75000
      Ÿˆ¾‘äÇò 8à
PHQ8ËäþÈƒh¹ÍÂÊ      Ÿ75000
  K   ¡ˆl–Ü4ý('ÜZÔâ€vã,ÜÅ£�þB6™YÆÈÜ’<ÓÀ•ÇŸÉƒqÑ3Î_“I|¥ŽõHºl=$¤�zTÖ™	ÄÌ C    ¡const ROMAN_NUMERALS: [number, string][] = [
  [1000, 'm'],
  [900, 'cm'],
  [500, 'd'],
  [400, 'cd'],
  [100, 'c'],
  [90, 'xc'],
  [50, 'l'],
  [40, 'xl'],
  [10, 'x'],
  [9, 'ix'],
  [5, 'v'],
  [4, 'iv'],
  [1, 'i'],
]

const ALPHA_NUMERALS = 'abcdefghijklmnopqrstuvwxyz'

/** Alpha list markers support at most 2 letters (aâ€“z, aaâ€“zz), matching {@link fromAlpha}. */
export const ORDERED_LIST_ALPHA_MARKER_PATTERN = '[a-zA-Z]{1,2}'

/**
 * Marker segment for ordered list lines: numeric, roman, or 1â€“2 letter alpha.
 * Roman is matched before alpha so "iii" is roman; invalid romans like "aa" fall through to alpha.
 */
export const ORDERED_LIST_MARKER_PATTERN = String.raw`\d+|[ivxlcdmIVXLCDM]+|${ORDERED_LIST_ALPHA_MARKER_PATTERN}`

/**
 * Convert a number to lowercase roman numerals.
 * @example toRoman(1) // 'i'
 * @example toRoman(4) // 'iv'
 */
export function toRoman(num: number): string {
  let remaining = num
  let result = ''

  for (const [value, numeral] of ROMAN_NUMERALS) {
    while (remaining >= value) {
      result += numeral
      remaining -= value
    }
  }

  return result
}

/**
 * Convert a number to uppercase roman numerals.
 * @example toRomanUpper(1) // 'I'
 * @example toRomanUpper(4) // 'IV'
 */
export function toRomanUpper(num: number): string {
  return toRoman(num).toUpperCase()
}

function fromRoman(roman: string): number {
  const lower = roman.toLowerCase()
  let index = 0
  let result = 0

  while (index < lower.length) {
    let matched = false

    for (const [value, numeral] of ROMAN_NUMERALS) {
      if (lower.startsWith(numeral, index)) {
        result += value
        index += numeral.length
        matched = true
        break
      }
    }

    if (!matched) {
      return 0
    }
  }

  return result
}

function isValidRoman(marker: string): boolean {
  if (!/^[ivxlcdmIVXLCDM]+$/.test(marker)) {
    return false
  }

  const value = fromRoman(marker)

  if (value <= 0) {
    return false
  }

  const expected = marker === marker.toLowerCase() ? toRoman(value) : toRomanUpper(value)

  return expected === marker
}

function fromAlpha(marker: string): number {
  const lower = marker.toLowerCase()

  if (lower.length === 1) {
    return lower.charCodeAt(0) - 'a'.charCodeAt(0) + 1
  }

  if (lower.length === 2) {
    const first = lower.charCodeAt(0) - 'a'.charCodeAt(0)
    const second = lower.charCodeAt(1) - 'a'.charCodeAt(0)

    return (first + 1) * 26 + second + 1
  }

  return 0
}

function toRomanAlpha(num: number): string {
  if (num <= 26) {
    return ALPHA_NUMERALS[num - 1]
  }

  const first = Math.floor((num - 1) / 26) - 1
  const second = (num - 1) % 26

  if (first < 0) {
    return ALPHA_NUMERALS[second]
  }

  return ALPHA_NUMERALS[first] + ALPHA_NUMERALS[second]
}

/**
 * Extract the list marker type from a marker string.
 * Supports "1", "a", "A", "i", "I" marker styles.
 *
 * @param marker The text content of the list marker (e.g. "a", "1", "iii", "b")
 * @returns The normalized type string, or undefined for default numeric type
 */
export function detectMarkerType(marker: string): string | undefined {
  if (!marker || /^\d+$/.test(marker)) {
    return undefined
  }

  if (isValidRoman(marker)) {
    return marker === marker.toLowerCase() ? 'i' : 'I'
  }

  if (/^[a-z]{1,2}$/.test(marker)) {
    return 'a'
  }

  if (/^[A-Z]{1,2}$/.test(marker)) {
    return 'A'
  }

  return undefined
}

/**
 * Convert a list marker string to its numeric start position.
 *
 * @param marker The text content of the list marker (e.g. "3", "b", "II")
 * @returns The 1-based start value for the ordered list
 */
export function markerToStart(marker: string): number {
  if (/^\d+$/.test(marker)) {
    return parseInt(marker, 10)
  }

  const type = detectMarkerType(marker)

  if (type === 'i' || type === 'I') {
    return fromRoman(marker)
  }

  if (type === 'a' || type === 'A') {
    const start = fromAlpha(marker)

    return st