{"version":3,"sources":["../src/index.ts","../src/font.ts","../src/wrap.ts","../src/cache.ts","../src/layout.ts","../src/draw.ts","../src/measure.ts"],"sourcesContent":["export { drawText, drawTextLayout } from './draw'\nexport type { DrawLayoutOptions } from './draw'\nexport { layoutText } from './layout'\nexport { clearMeasurementCache } from './cache'\nexport { measureText, splitText, getTextHeight } from './measure'\nexport type { MeasureTextConfig, SplitTextProps } from './measure'\nexport type {\n  TextContext,\n  TextMetricsLike,\n  TextStyle,\n  LayoutConfig,\n  DrawTextConfig,\n  DrawStyle,\n  TextLayout,\n  LayoutLine,\n  LayoutWord,\n} from './types'\n\n// v4 name kept as an alias\nexport type { DrawTextConfig as CanvasTextConfig } from './types'\n","interface FontParts {\n  fontStyle: string\n  fontVariant: string\n  fontWeight: string | number\n  fontSize: number\n  font: string\n}\n\nexport function buildFont({\n  fontStyle,\n  fontVariant,\n  fontWeight,\n  fontSize,\n  font,\n}: FontParts): string {\n  // Families containing spaces must be quoted in the CSS font shorthand;\n  // skip families that are already quoted or are a comma-separated list.\n  const family = font.includes(' ') && !/['\",]/.test(font) ? `\"${font}\"` : font\n  let out = ''\n  if (fontStyle) out += fontStyle + ' '\n  if (fontVariant) out += fontVariant + ' '\n  if (fontWeight) out += fontWeight + ' '\n  return out + fontSize + 'px ' + family\n}\n","export type Measure = (text: string) => number\n\nexport interface WrappedLine {\n  text: string\n  width: number\n}\n\nexport interface WrapOptions {\n  width: number\n  /** Width of a single segment (word, whitespace run, or grapheme). */\n  measureSeg: Measure\n  /**\n   * Exact whole-line measuring. When provided, fit tests measure the\n   * assembled candidate line instead of summing segment widths — slower,\n   * but includes kerning across segment boundaries.\n   */\n  measureLine?: Measure\n}\n\nlet wordSegmenter: Intl.Segmenter | undefined\nlet graphemeSegmenter: Intl.Segmenter | undefined\n\nfunction segmentWords(text: string): string[] {\n  if (typeof Intl !== 'undefined' && 'Segmenter' in Intl) {\n    wordSegmenter ??= new Intl.Segmenter(undefined, { granularity: 'word' })\n    return Array.from(wordSegmenter.segment(text), (s) => s.segment)\n  }\n  // Fallback: split on whitespace runs, keeping them as segments\n  return text.split(/(\\s+)/).filter((s) => s !== '')\n}\n\nexport function segmentGraphemes(text: string): string[] {\n  if (typeof Intl !== 'undefined' && 'Segmenter' in Intl) {\n    graphemeSegmenter ??= new Intl.Segmenter(undefined, {\n      granularity: 'grapheme',\n    })\n    return Array.from(graphemeSegmenter.segment(text), (s) => s.segment)\n  }\n  // Fallback: code points (still safe for surrogate pairs)\n  return Array.from(text)\n}\n\n/**\n * Whitespace test for word-granularity segments without allocating.\n * UAX-29 never mixes whitespace and non-whitespace in one segment, so the\n * first char is decisive; anything that could be whitespace falls back to\n * the exact trim() check.\n */\nfunction isWhitespaceSegment(segment: string): boolean {\n  if (segment === ' ') return true\n  const c = segment.charCodeAt(0)\n  // 0x21..0x167F excluding NBSP (0xA0) is guaranteed non-whitespace\n  if (c > 0x20 && c !== 0xa0 && c < 0x1680) return false\n  return segment.trim() === ''\n}\n\n/** Break a single token that is wider than the box, at grapheme boundaries. */\nfunction breakToken(token: string, opts: WrapOptions): WrappedLine[] {\n  const { width, measureSeg, measureLine } = opts\n  const parts: WrappedLine[] = []\n  let current = ''\n  let currentWidth = 0\n  for (const grapheme of segmentGraphemes(token)) {\n    const candidateWidth = measureLine\n      ? measureLine(current + grapheme)\n      : currentWidth + measureSeg(grapheme)\n    if (current !== '' && candidateWidth > width) {\n      parts.push({ text: current, width: currentWidth })\n      current = grapheme\n      currentWidth = measureLine ? measureLine(grapheme) : measureSeg(grapheme)\n    } else {\n      current += grapheme\n      currentWidth = candidateWidth\n    }\n  }\n  parts.push({ text: current, width: currentWidth })\n  return parts\n}\n\nfunction wrapParagraph(paragraph: string, opts: WrapOptions): WrappedLine[] {\n  const { width, measureSeg, measureLine } = opts\n\n  const whole = paragraph.trim()\n  if (whole === '') return [{ text: '', width: 0 }]\n  if (measureLine) {\n    // Exact mode can answer \"does the whole paragraph fit?\" with one measure\n    const wholeWidth = measureLine(whole)\n    if (wholeWidth <= width) return [{ text: whole, width: wholeWidth }]\n  }\n\n  const lines: WrappedLine[] = []\n  let lineText = ''\n  let lineWidth = 0\n  // Whitespace runs are held back until the next word commits to this line,\n  // so trailing spaces are dropped at breaks and never measured into a line.\n  let pendingText = ''\n  let pendingWidth = 0\n\n  const flush = () => {\n    if (lineText !== '') lines.push({ text: lineText, width: lineWidth })\n    lineText = ''\n    lineWidth = 0\n    pendingText = ''\n    pendingWidth = 0\n  }\n\n  const startLine = (segment: string, segmentWidth: number) => {\n    if (segmentWidth > width) {\n      const parts = breakToken(segment, opts)\n      for (const part of parts.slice(0, -1)) lines.push(part)\n      const last = parts[parts.length - 1]\n      lineText = last.text\n      lineWidth = last.width\n    } else {\n      lineText = segment\n      lineWidth = segmentWidth\n    }\n  }\n\n  for (const segment of segmentWords(paragraph)) {\n    if (isWhitespaceSegment(segment)) {\n      if (lineText === '') continue // never start a line with whitespace\n      pendingText += segment\n      if (!measureLine) pendingWidth += measureSeg(segment)\n      continue\n    }\n\n    const segmentWidth = measureSeg(segment)\n    if (lineText === '') {\n      startLine(segment, segmentWidth)\n      continue\n    }\n\n    const candidateWidth = measureLine\n      ? measureLine(lineText + pendingText + segment)\n      : lineWidth + pendingWidth + segmentWidth\n    if (candidateWidth <= width) {\n      lineText += pendingText + segment\n      lineWidth = candidateWidth\n      pendingText = ''\n      pendingWidth = 0\n    } else {\n      flush()\n      startLine(segment, segmentWidth)\n    }\n  }\n  flush()\n\n  if (lines.length === 0) lines.push({ text: '', width: 0 })\n  return lines\n}\n\n/**\n * Wrap text into measured lines. Returns one WrappedLine[] per paragraph\n * (text split on `\\n`), so callers can tell soft-wrapped lines from hard\n * breaks — the last line of each paragraph is a hard break.\n */\nexport function wrapText(text: string, opts: WrapOptions): WrappedLine[][] {\n  return text.split('\\n').map((p) => wrapParagraph(p, opts))\n}\n","/**\n * Module-level width caches, shared across calls and keyed by font (plus\n * letterSpacing/direction, which change glyph advances). This is what makes\n * steady-state wrapping cheap: each unique segment is shaped once per font,\n * afterwards line widths are computed by summing cached numbers.\n *\n * Call `clearMeasurementCache()` after loading web fonts — a font file\n * arriving changes the metrics behind already-cached widths.\n */\n\nconst MAX_SEGMENTS_PER_FONT = 10_000\n\nconst segmentCaches = new Map<string, Map<string, number>>()\n\ninterface CachedFontMetrics {\n  ascent: number\n  descent: number\n  height: number\n}\n\nconst metricsCache = new Map<string, CachedFontMetrics>()\n\nexport function getSegmentCache(cacheKey: string): Map<string, number> {\n  let cache = segmentCaches.get(cacheKey)\n  if (!cache) {\n    cache = new Map()\n    segmentCaches.set(cacheKey, cache)\n  }\n  return cache\n}\n\n/** FIFO-evicting insert so a pathological corpus can't grow unbounded. */\nexport function cacheSegmentWidth(\n  cache: Map<string, number>,\n  segment: string,\n  width: number\n): void {\n  if (cache.size >= MAX_SEGMENTS_PER_FONT) {\n    const oldest = cache.keys().next()\n    if (!oldest.done) cache.delete(oldest.value)\n  }\n  cache.set(segment, width)\n}\n\nexport function getCachedFontMetrics(\n  cacheKey: string\n): CachedFontMetrics | undefined {\n  return metricsCache.get(cacheKey)\n}\n\nexport function setCachedFontMetrics(\n  cacheKey: string,\n  metrics: CachedFontMetrics\n): void {\n  metricsCache.set(cacheKey, metrics)\n}\n\nconst MAX_RESULTS = 500\n\nconst layoutResults = new Map<string, unknown>()\nconst splitResults = new Map<string, readonly string[]>()\n\nfunction setWithEviction<V>(map: Map<string, V>, key: string, value: V): void {\n  if (map.size >= MAX_RESULTS) {\n    const oldest = map.keys().next()\n    if (!oldest.done) map.delete(oldest.value)\n  }\n  map.set(key, value)\n}\n\nexport function getCachedLayout(key: string): unknown {\n  return layoutResults.get(key)\n}\n\nexport function setCachedLayout(key: string, layout: unknown): void {\n  setWithEviction(layoutResults, key, layout)\n}\n\nexport function getCachedSplit(key: string): readonly string[] | undefined {\n  return splitResults.get(key)\n}\n\nexport function setCachedSplit(key: string, lines: readonly string[]): void {\n  setWithEviction(splitResults, key, lines)\n}\n\n/**\n * Drop every cached measurement and memoized result. Call this after\n * `document.fonts` finishes loading (or any time a font file arrives) so\n * widths are re-measured with the real font instead of its fallback.\n */\nexport function clearMeasurementCache(): void {\n  segmentCaches.clear()\n  metricsCache.clear()\n  layoutResults.clear()\n  splitResults.clear()\n}\n","import { buildFont } from './font'\nimport { wrapText, segmentGraphemes, type Measure } from './wrap'\nimport {\n  getSegmentCache,\n  cacheSegmentWidth,\n  getCachedFontMetrics,\n  setCachedFontMetrics,\n  getCachedLayout,\n  setCachedLayout,\n} from './cache'\nimport type {\n  LayoutConfig,\n  LayoutLine,\n  LayoutWord,\n  TextContext,\n  TextLayout,\n} from './types'\n\nconst ELLIPSIS = '…'\n\n/** Resolve defaults field by field — `??` also neutralizes explicitly-passed\n * `undefined` values, and this stays off the allocation-heavy\n * spread/Object.entries path since it runs on every layout call. */\nfunction resolveConfig(config: LayoutConfig) {\n  return {\n    width: config.width,\n    height: config.height,\n    font: config.font ?? 'Arial',\n    fontSize: config.fontSize ?? 14,\n    fontWeight: config.fontWeight ?? '',\n    fontStyle: config.fontStyle ?? '',\n    fontVariant: config.fontVariant ?? '',\n    lineHeight: config.lineHeight,\n    letterSpacing: config.letterSpacing,\n    direction: config.direction,\n    align: config.align ?? 'center',\n    vAlign: config.vAlign ?? 'middle',\n    justify: config.justify ?? false,\n    overflow: config.overflow ?? 'visible',\n    maxLines: config.maxLines,\n    cache: config.cache ?? true,\n  }\n}\n\ntype ResolvedConfig = ReturnType<typeof resolveConfig>\n\ninterface FontMetrics {\n  ascent: number\n  descent: number\n  height: number\n}\n\n/** Font metrics from the context's *current* font. */\nfunction fontMetrics(ctx: TextContext): FontMetrics {\n  // 'Mg' samples both an ascender and a descender for the actualBoundingBox\n  // fallback; fontBoundingBox (when available) ignores the sample anyway.\n  const m = ctx.measureText('Mg')\n  const ascent = m.fontBoundingBoxAscent ?? m.actualBoundingBoxAscent\n  const descent = m.fontBoundingBoxDescent ?? m.actualBoundingBoxDescent\n  return { ascent, descent, height: ascent + descent }\n}\n\nfunction ellipsize(line: string, measure: Measure, width: number): string {\n  if (measure(line + ELLIPSIS) <= width) return line + ELLIPSIS\n  const graphemes = segmentGraphemes(line)\n  while (graphemes.length > 0) {\n    graphemes.pop()\n    const candidate = graphemes.join('').trimEnd() + ELLIPSIS\n    if (measure(candidate) <= width) return candidate\n  }\n  return ELLIPSIS\n}\n\n/** Word positions stretching a line to the full box width, or null when\n * the line has fewer than two words or already fills the box. */\nfunction justifyWords(\n  line: string,\n  measure: Measure,\n  width: number\n): LayoutWord[] | null {\n  const chunks = line.split(/\\s+/).filter(Boolean)\n  if (chunks.length < 2) return null\n\n  const wordWidths = chunks.map(measure)\n  const totalWordWidth = wordWidths.reduce((sum, w) => sum + w, 0)\n  const gap = (width - totalWordWidth) / (chunks.length - 1)\n  if (gap <= 0) return null\n\n  const words: LayoutWord[] = []\n  let x = 0\n  for (let i = 0; i < chunks.length; i++) {\n    words.push({ text: chunks[i], x })\n    x += wordWidths[i] + gap\n  }\n  return words\n}\n\nfunction freezeLayout(layout: TextLayout): TextLayout {\n  for (const line of layout.lines) {\n    if (line.words) {\n      for (const word of line.words) Object.freeze(word)\n      Object.freeze(line.words)\n    }\n    Object.freeze(line)\n  }\n  Object.freeze(layout.lines)\n  return Object.freeze(layout)\n}\n\nconst KEY_SEP = '\u001f'\n\nfunction layoutMemoKey(\n  text: string,\n  cfg: ResolvedConfig,\n  font: string,\n  letterSpacing: string,\n  direction: string\n): string {\n  return (\n    text +\n    KEY_SEP +\n    cfg.width +\n    KEY_SEP +\n    (cfg.height ?? '') +\n    KEY_SEP +\n    font +\n    KEY_SEP +\n    (cfg.lineHeight ?? '') +\n    KEY_SEP +\n    letterSpacing +\n    KEY_SEP +\n    direction +\n    KEY_SEP +\n    cfg.align +\n    KEY_SEP +\n    cfg.vAlign +\n    KEY_SEP +\n    (cfg.justify ? 1 : 0) +\n    KEY_SEP +\n    cfg.overflow +\n    KEY_SEP +\n    (cfg.maxLines ?? '')\n  )\n}\n\n/**\n * Lay text out inside a box without drawing anything. Pure with respect to\n * the context: every context property it touches is restored before\n * returning. The result can be painted any number of times with\n * `drawTextLayout`, cached across frames, hit-tested, or inspected.\n *\n * Layouts and segment widths are memoized in module-level caches by default\n * (see `clearMeasurementCache`); returned layouts are frozen. Pass\n * `cache: false` to measure exactly, per call, with no shared state — those\n * results are not frozen.\n */\nexport function layoutText(\n  ctx: TextContext,\n  text: string,\n  config: LayoutConfig\n): TextLayout {\n  const cfg = resolveConfig(config)\n  const font = buildFont(cfg)\n  const useCache = cfg.cache !== false\n\n  // Widths depend on the context's effective letterSpacing/direction: the\n  // config's value when set, whatever the context carries otherwise.\n  const effLetterSpacing = cfg.letterSpacing ?? ctx.letterSpacing ?? ''\n  const effDirection = cfg.direction ?? ctx.direction ?? ''\n\n  let memoKey: string | undefined\n  if (useCache) {\n    memoKey = layoutMemoKey(text, cfg, font, effLetterSpacing, effDirection)\n    const memoized = getCachedLayout(memoKey)\n    if (memoized !== undefined) return memoized as TextLayout\n  }\n\n  const prevFont = ctx.font\n  const prevLetterSpacing = ctx.letterSpacing\n  const prevDirection = ctx.direction\n  ctx.font = font\n  if (cfg.letterSpacing !== undefined && 'letterSpacing' in ctx) {\n    ctx.letterSpacing = cfg.letterSpacing\n  }\n  if (cfg.direction !== undefined && 'direction' in ctx) {\n    ctx.direction = cfg.direction\n  }\n\n  try {\n    const cacheKey = `${font}|${effLetterSpacing}|${effDirection}`\n    const segmentCache = useCache\n      ? getSegmentCache(cacheKey)\n      : new Map<string, number>()\n\n    const measureSeg: Measure = (s) => {\n      let w = segmentCache.get(s)\n      if (w === undefined) {\n        w = ctx.measureText(s).width\n        cacheSegmentWidth(segmentCache, s, w)\n      }\n      return w\n    }\n\n    // Exact mode measures assembled candidate lines; dedupe within the call.\n    let measureLine: Measure | undefined\n    const lineCache = new Map<string, number>()\n    const measureLineExact: Measure = (s) => {\n      let w = lineCache.get(s)\n      if (w === undefined) {\n        w = ctx.measureText(s).width\n        lineCache.set(s, w)\n      }\n      return w\n    }\n    if (!useCache) measureLine = measureLineExact\n\n    const paragraphs = wrapText(text, {\n      width: cfg.width,\n      measureSeg,\n      measureLine,\n    })\n\n    // Flatten, remembering which lines are soft-wrapped (candidates for\n    // justification — the last line of each paragraph is a hard break).\n    let flat = paragraphs.flatMap((para) =>\n      para.map((line, i) => ({\n        text: line.text,\n        width: line.width,\n        justified: cfg.justify && i < para.length - 1,\n      }))\n    )\n\n    let metrics = useCache ? getCachedFontMetrics(cacheKey) : undefined\n    if (!metrics) {\n      metrics = fontMetrics(ctx)\n      if (useCache) setCachedFontMetrics(cacheKey, metrics)\n    }\n    const lineHeight = cfg.lineHeight ?? metrics.height\n\n    let limit = cfg.maxLines ?? Infinity\n    if (cfg.overflow !== 'visible' && cfg.height !== undefined) {\n      limit = Math.min(limit, Math.floor(cfg.height / lineHeight))\n    }\n\n    let clipped = false\n    if (flat.length > limit) {\n      flat = flat.slice(0, Math.max(limit, 0))\n      clipped = true\n      if (cfg.overflow === 'ellipsis' && flat.length > 0) {\n        const last = flat[flat.length - 1]\n        // Precision matters right at the edge — always measure the real line\n        last.text = ellipsize(last.text, measureLineExact, cfg.width)\n        last.width = measureLineExact(last.text)\n        last.justified = false\n      }\n    }\n\n    const textHeight = flat.length * lineHeight\n    const boxHeight = cfg.height ?? textHeight\n    let offsetTop = 0\n    if (cfg.vAlign === 'middle') offsetTop = (boxHeight - textHeight) / 2\n    else if (cfg.vAlign === 'bottom') offsetTop = boxHeight - textHeight\n\n    // Half-leading, like CSS: extra line height is split above and below.\n    const leading = lineHeight - metrics.height\n\n    let maxWidth = 0\n    const lines: LayoutLine[] = flat.map((line, i) => {\n      const words = line.justified\n        ? justifyWords(line.text, measureSeg, cfg.width)\n        : null\n      const width = words ? cfg.width : line.width\n      maxWidth = Math.max(maxWidth, width)\n\n      let x = 0\n      if (cfg.align === 'center') x = (cfg.width - width) / 2\n      else if (cfg.align === 'right') x = cfg.width - width\n\n      const y = offsetTop + i * lineHeight + leading / 2 + metrics.ascent\n      return { text: line.text, x, y, width, words }\n    })\n\n    const layout: TextLayout = {\n      lines,\n      width: maxWidth,\n      height: textHeight,\n      lineHeight,\n      font,\n      letterSpacing: cfg.letterSpacing,\n      direction: cfg.direction,\n      clipped,\n    }\n\n    if (memoKey !== undefined) {\n      // Memoized layouts are shared between callers — freeze so an\n      // accidental mutation throws instead of corrupting the cache.\n      freezeLayout(layout)\n      setCachedLayout(memoKey, layout)\n    }\n    return layout\n  } finally {\n    ctx.font = prevFont\n    if (prevLetterSpacing !== undefined && 'letterSpacing' in ctx) {\n      ctx.letterSpacing = prevLetterSpacing\n    }\n    if (prevDirection !== undefined && 'direction' in ctx) {\n      ctx.direction = prevDirection\n    }\n  }\n}\n","import { layoutText } from './layout'\nimport type {\n  DrawStyle,\n  DrawTextConfig,\n  TextContext,\n  TextLayout,\n} from './types'\n\nexport interface DrawLayoutOptions {\n  /** Left edge of the text box on the canvas */\n  x: number\n  /** Top edge of the text box on the canvas */\n  y: number\n  style?: DrawStyle\n}\n\n/**\n * Paint a layout produced by `layoutText` at (x, y). The layout can be\n * painted repeatedly (animation frames, fill + stroke passes) without\n * re-measuring. Context state is restored afterwards.\n */\nexport function drawTextLayout(\n  ctx: TextContext,\n  layout: TextLayout,\n  { x, y, style }: DrawLayoutOptions\n): void {\n  const prevFont = ctx.font\n  const prevAlign = ctx.textAlign\n  const prevBaseline = ctx.textBaseline\n  const prevLetterSpacing = ctx.letterSpacing\n  const prevDirection = ctx.direction\n  const prevFill = ctx.fillStyle\n  const prevStroke = ctx.strokeStyle\n  const prevLineWidth = ctx.lineWidth\n\n  ctx.font = layout.font\n  ctx.textAlign = 'left'\n  ctx.textBaseline = 'alphabetic'\n  if (layout.letterSpacing !== undefined && 'letterSpacing' in ctx) {\n    ctx.letterSpacing = layout.letterSpacing\n  }\n  if (layout.direction !== undefined && 'direction' in ctx) {\n    ctx.direction = layout.direction\n  }\n  if (style?.fill !== undefined) ctx.fillStyle = style.fill\n  const stroke = style?.stroke !== undefined && typeof ctx.strokeText === 'function'\n  if (stroke) {\n    ctx.strokeStyle = style!.stroke\n    ctx.lineWidth = style!.strokeWidth ?? 1\n  }\n\n  try {\n    for (const line of layout.lines) {\n      if (line.words) {\n        for (const word of line.words) {\n          ctx.fillText(word.text, x + line.x + word.x, y + line.y)\n          if (stroke) ctx.strokeText!(word.text, x + line.x + word.x, y + line.y)\n        }\n      } else {\n        ctx.fillText(line.text, x + line.x, y + line.y)\n        if (stroke) ctx.strokeText!(line.text, x + line.x, y + line.y)\n      }\n    }\n  } finally {\n    ctx.font = prevFont\n    ctx.textAlign = prevAlign\n    ctx.textBaseline = prevBaseline\n    if (prevLetterSpacing !== undefined && 'letterSpacing' in ctx) {\n      ctx.letterSpacing = prevLetterSpacing\n    }\n    if (prevDirection !== undefined && 'direction' in ctx) {\n      ctx.direction = prevDirection\n    }\n    if (prevFill !== undefined) ctx.fillStyle = prevFill\n    if (prevStroke !== undefined) ctx.strokeStyle = prevStroke\n    if (prevLineWidth !== undefined) ctx.lineWidth = prevLineWidth\n  }\n}\n\nconst DEBUG_COLOR = '#0C8CE9'\n\nfunction drawDebug(ctx: TextContext, config: DrawTextConfig): void {\n  if (\n    !ctx.strokeRect ||\n    !ctx.beginPath ||\n    !ctx.moveTo ||\n    !ctx.lineTo ||\n    !ctx.stroke\n  ) {\n    return\n  }\n  const { x, y, width, height } = config\n  const prevStroke = ctx.strokeStyle\n  const prevLineWidth = ctx.lineWidth\n  const prevAlpha = ctx.globalAlpha\n  ctx.strokeStyle = DEBUG_COLOR\n  ctx.lineWidth = 1\n\n  // Text box — the 0.5 offsets keep 1px strokes on the pixel grid so they\n  // render as one crisp row instead of blurring across two\n  ctx.strokeRect(x + 0.5, y + 0.5, width, height)\n\n  // Alignment guides, dashed and dimmed where the context supports it\n  const anchorX =\n    config.align === 'left'\n      ? x\n      : config.align === 'right'\n        ? x + width\n        : x + width / 2\n  const anchorY =\n    config.vAlign === 'top'\n      ? y\n      : config.vAlign === 'bottom'\n        ? y + height\n        : y + height / 2\n  ctx.setLineDash?.([4, 4])\n  if (prevAlpha !== undefined) ctx.globalAlpha = 0.5\n  ctx.beginPath()\n  ctx.moveTo(anchorX + 0.5, y)\n  ctx.lineTo(anchorX + 0.5, y + height)\n  ctx.moveTo(x, anchorY + 0.5)\n  ctx.lineTo(x + width, anchorY + 0.5)\n  ctx.stroke()\n  ctx.setLineDash?.([])\n  if (prevAlpha !== undefined) ctx.globalAlpha = prevAlpha\n\n  if (prevStroke !== undefined) ctx.strokeStyle = prevStroke\n  if (prevLineWidth !== undefined) ctx.lineWidth = prevLineWidth\n}\n\n/**\n * Lay out and draw text inside the box described by config. Convenience\n * wrapper around `layoutText` + `drawTextLayout` — for repeated drawing of\n * the same text, lay out once and paint the layout instead.\n */\nexport function drawText(\n  ctx: TextContext,\n  text: string,\n  config: DrawTextConfig\n): { height: number; width: number; lines: string[] } {\n  const fontSize = config.fontSize ?? 14\n  if (config.width <= 0 || config.height <= 0 || fontSize <= 0) {\n    return { height: 0, width: 0, lines: [] }\n  }\n\n  const layout = layoutText(ctx, text, config)\n  drawTextLayout(ctx, layout, { x: config.x, y: config.y, style: config.style })\n  if (config.debug) drawDebug(ctx, config)\n\n  return {\n    height: layout.height,\n    width: layout.width,\n    lines: layout.lines.map((line) => line.text),\n  }\n}\n","import { layoutText } from './layout'\nimport { wrapText } from './wrap'\nimport {\n  getSegmentCache,\n  cacheSegmentWidth,\n  getCachedSplit,\n  setCachedSplit,\n} from './cache'\nimport type { LayoutConfig, TextContext } from './types'\n\nexport type MeasureTextConfig = Omit<\n  LayoutConfig,\n  'height' | 'overflow' | 'align' | 'vAlign'\n>\n\n/**\n * Lays out the text exactly like drawText would — same wrapping, same line\n * height — without drawing anything. Useful for sizing a canvas before\n * rendering.\n */\nexport function measureText(\n  ctx: TextContext,\n  text: string,\n  config: MeasureTextConfig\n): { lines: string[]; width: number; height: number } {\n  const layout = layoutText(ctx, text, config)\n  return {\n    lines: layout.lines.map((line) => line.text),\n    width: layout.width,\n    height: layout.height,\n  }\n}\n\nexport interface SplitTextProps {\n  ctx: TextContext\n  text: string\n  width: number\n  /** @deprecated v5 justifies at paint time; this flag is ignored */\n  justify?: boolean\n  /** Set `false` to bypass the module-level width cache. Default `true` */\n  cache?: boolean\n}\n\n/**\n * Split text into wrapped lines using the context's current font.\n * Kept for v4 compatibility — prefer `layoutText`, which also gives you\n * positions and metrics.\n */\nexport function splitText({\n  ctx,\n  text,\n  width,\n  cache = true,\n}: SplitTextProps): string[] {\n  // splitText measures with the context's current state, so effective\n  // letterSpacing/direction must key the caches too\n  const stateKey = `${ctx.font}|${ctx.letterSpacing ?? ''}|${\n    ctx.direction ?? ''\n  }`\n\n  let memoKey: string | undefined\n  if (cache) {\n    memoKey = `${stateKey}\u001f${width}\u001f${text}`\n    const memoized = getCachedSplit(memoKey)\n    if (memoized !== undefined) return memoized as string[]\n  }\n\n  const segmentCache = cache\n    ? getSegmentCache(stateKey)\n    : new Map<string, number>()\n  const measureSeg = (s: string) => {\n    let w = segmentCache.get(s)\n    if (w === undefined) {\n      w = ctx.measureText(s).width\n      cacheSegmentWidth(segmentCache, s, w)\n    }\n    return w\n  }\n\n  let measureLine: ((s: string) => number) | undefined\n  if (!cache) {\n    const lineCache = new Map<string, number>()\n    measureLine = (s: string) => {\n      let w = lineCache.get(s)\n      if (w === undefined) {\n        w = ctx.measureText(s).width\n        lineCache.set(s, w)\n      }\n      return w\n    }\n  }\n\n  const lines = wrapText(text, { width, measureSeg, measureLine })\n    .flat()\n    .map((line) => line.text)\n  if (memoKey !== undefined) {\n    setCachedSplit(memoKey, Object.freeze(lines))\n  }\n  return lines\n}\n\ninterface GetTextHeightProps {\n  ctx: TextContext\n  text: string\n  style: string\n}\n\n/**\n * Height of `text` rendered with the given CSS font string. Uses the font's\n * real line box where the environment exposes it, falling back to the inked\n * bounding box of `text`.\n */\nexport function getTextHeight({ ctx, text, style }: GetTextHeightProps): number {\n  const prevBaseline = ctx.textBaseline\n  const prevFont = ctx.font\n  ctx.textBaseline = 'bottom'\n  ctx.font = style\n  const metrics = ctx.measureText(text)\n  const height =\n    metrics.fontBoundingBoxAscent !== undefined &&\n    metrics.fontBoundingBoxDescent !== undefined\n      ? metrics.fontBoundingBoxAscent + metrics.fontBoundingBoxDescent\n      : metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent\n  ctx.textBaseline = prevBaseline\n  ctx.font = prevFont\n  return height\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAsB;AAGpB,QAAM,SAAS,KAAK,SAAS,GAAG,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,IAAI,IAAI,MAAM;AACzE,MAAI,MAAM;AACV,MAAI,UAAW,QAAO,YAAY;AAClC,MAAI,YAAa,QAAO,cAAc;AACtC,MAAI,WAAY,QAAO,aAAa;AACpC,SAAO,MAAM,WAAW,QAAQ;AAClC;;;ACJA,IAAI;AACJ,IAAI;AAEJ,SAAS,aAAa,MAAwB;AAC5C,MAAI,OAAO,SAAS,eAAe,eAAe,MAAM;AACtD,sBAAkB,IAAI,KAAK,UAAU,QAAW,EAAE,aAAa,OAAO,CAAC;AACvE,WAAO,MAAM,KAAK,cAAc,QAAQ,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO;AAAA,EACjE;AAEA,SAAO,KAAK,MAAM,OAAO,EAAE,OAAO,CAAC,MAAM,MAAM,EAAE;AACnD;AAEO,SAAS,iBAAiB,MAAwB;AACvD,MAAI,OAAO,SAAS,eAAe,eAAe,MAAM;AACtD,0BAAsB,IAAI,KAAK,UAAU,QAAW;AAAA,MAClD,aAAa;AAAA,IACf,CAAC;AACD,WAAO,MAAM,KAAK,kBAAkB,QAAQ,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO;AA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