@ngrok/mantle-server-syntax-highlighter 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { FoldLine, FoldableRange, Indentation, LineRange, SupportedLanguage } from "@ngrok/mantle/highlight-utils";
2
- import * as _$shiki from "shiki";
2
+ import { createHighlighter } from "shiki";
3
3
  //#region src/engine.d.ts
4
4
  /**
5
5
  * Shiki grammar IDs preloaded by Mantle's highlighting engine.
@@ -11,7 +11,7 @@ declare const mantleShikiLanguageGrammarIds: ["bash", "csharp", "css", "go", "ht
11
11
  */
12
12
  declare const mantleShikiThemeName: "mantle-css-variables";
13
13
  declare const mantleHighlightCacheMaxEntries = 1000;
14
- type ShikiHighlighter = Awaited<ReturnType<(typeof _$shiki)["createHighlighter"]>>;
14
+ type ShikiHighlighter = Awaited<ReturnType<typeof createHighlighter>>;
15
15
  type MantleHighlightInput = {
16
16
  /**
17
17
  * Raw code string to highlight.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/lru-cache.ts","../src/compute-css-fold-ranges.ts","../src/compute-html-fold-ranges.ts","../src/line-offsets.ts","../src/compute-jsx-fold-ranges.ts","../src/compute-keyword-fold-ranges.ts","../src/server-fold-ranges.ts","../src/engine.ts"],"sourcesContent":["/** A simple least-recently-used cache backed by insertion-order `Map` semantics. */\ntype LruCache<K, V> = {\n\tdelete: (key: K) => boolean;\n\tget: (key: K) => V | undefined;\n\tset: (key: K, value: V) => void;\n\tsize: () => number;\n};\n\n/** Creates an LRU cache that evicts the least-recently-used entry when `maxEntries` is exceeded. */\nfunction createLruCache<K, V>(maxEntries: number): LruCache<K, V> {\n\tif (!Number.isInteger(maxEntries) || maxEntries <= 0) {\n\t\tthrow new Error(\"LRU cache maxEntries must be a positive integer.\");\n\t}\n\n\tconst map = new Map<K, V>();\n\n\treturn {\n\t\tdelete(key) {\n\t\t\treturn map.delete(key);\n\t\t},\n\t\tget(key) {\n\t\t\tif (!map.has(key)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst value = map.get(key) as V;\n\t\t\tmap.delete(key);\n\t\t\tmap.set(key, value);\n\t\t\treturn value;\n\t\t},\n\t\tset(key, value) {\n\t\t\tif (map.has(key)) {\n\t\t\t\tmap.delete(key);\n\t\t\t}\n\n\t\t\tmap.set(key, value);\n\t\t\tif (map.size <= maxEntries) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst oldestKey = map.keys().next().value as K | undefined;\n\t\t\tif (oldestKey != null) {\n\t\t\t\tmap.delete(oldestKey);\n\t\t\t}\n\t\t},\n\t\tsize() {\n\t\t\treturn map.size;\n\t\t},\n\t};\n}\n\nexport { createLruCache };\nexport type { LruCache };\n","import { finalizeFoldRanges, type FoldableRange } from \"@ngrok/mantle/highlight-utils\";\n\n/**\n * Raw-source fold computer for CSS — single-pass, parser-quality without a\n * parser dependency.\n *\n * Mirrors `computeJsonFoldRanges` but adds CSS-specific lexical features:\n *\n * - `/* … *​/` block comments are skipped wholesale.\n * - `\"…\"` and `'…'` string literals (including `\\\\` and `\\` escapes) are\n * skipped so braces inside `content: \"{ }\"` don't open folds.\n * - Backslash escapes outside of strings (CSS identifiers can use them) are\n * transparent — we just consume the next character.\n *\n * lightningcss is the project's preferred CSS parser, but its public visitor\n * API only surfaces *start* locations (`Location { line, column }`), not end\n * locations, which is what `FoldableRange.endLine` requires. Until upstream\n * exposes end spans we get the same correctness from a single-pass brace\n * matcher with a tiny CSS lexer — and skip the ~5MB native dep.\n *\n * @see https://github.com/parcel-bundler/lightningcss/issues/512\n */\n\n/**\n * Computes foldable ranges for a CSS source string. Each multi-line `{ … }`\n * (style rule, at-rule body, nested rule, keyframe selector) emits one range\n * with the opener and closer lines staying visible.\n *\n * Tolerant of malformed CSS — unmatched braces are dropped silently rather\n * than throwing, so a partial snippet still gets every fold it can. This\n * matches the behavior of `computeJsonFoldRanges` for JSON.\n *\n * @example\n * computeCssFoldRanges({ code: \".a {\\n color: red;\\n}\" });\n * // => [{ id: \"1\", startLine: 1, endLine: 3 }]\n */\nfunction computeCssFoldRanges({\n\tcode,\n}: {\n\t/** Raw CSS source code to scan. */\n\tcode: string;\n}): FoldableRange[] {\n\tconst length = code.length;\n\tif (length === 0) {\n\t\treturn [];\n\t}\n\n\tconst stack: number[] = [];\n\tconst ranges: FoldableRange[] = [];\n\n\tlet line = 1;\n\tlet index = 0;\n\n\twhile (index < length) {\n\t\tconst character = code.charCodeAt(index);\n\n\t\tif (character === 10) {\n\t\t\tline += 1;\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === 13) {\n\t\t\tline += 1;\n\t\t\tindex += 1;\n\t\t\tif (index < length && code.charCodeAt(index) === 10) {\n\t\t\t\tindex += 1;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\t// `/* … */` block comment — CSS has no line comments in standard CSS.\n\t\tif (character === 47 && index + 1 < length && code.charCodeAt(index + 1) === 42) {\n\t\t\tindex += 2;\n\t\t\twhile (index < length) {\n\t\t\t\tconst commentChar = code.charCodeAt(index);\n\t\t\t\tif (commentChar === 10) {\n\t\t\t\t\tline += 1;\n\t\t\t\t\tindex += 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (commentChar === 13) {\n\t\t\t\t\tline += 1;\n\t\t\t\t\tindex += 1;\n\t\t\t\t\tif (index < length && code.charCodeAt(index) === 10) {\n\t\t\t\t\t\tindex += 1;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (commentChar === 42 && index + 1 < length && code.charCodeAt(index + 1) === 47) {\n\t\t\t\t\tindex += 2;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tindex += 1;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\t// `\"…\"` or `'…'` string literal. CSS allows escaped newlines (`\\` followed\n\t\t// by a newline) which continue the string; treat any backslash as\n\t\t// \"skip the next char\" without bumping the line counter past it.\n\t\tif (character === 34 || character === 39) {\n\t\t\tconst quote = character;\n\t\t\tindex += 1;\n\t\t\twhile (index < length) {\n\t\t\t\tconst stringChar = code.charCodeAt(index);\n\t\t\t\tif (stringChar === 92) {\n\t\t\t\t\tindex += 1;\n\t\t\t\t\tif (index >= length) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst escaped = code.charCodeAt(index);\n\t\t\t\t\tif (escaped === 10) {\n\t\t\t\t\t\tline += 1;\n\t\t\t\t\t} else if (escaped === 13) {\n\t\t\t\t\t\tline += 1;\n\t\t\t\t\t\tif (index + 1 < length && code.charCodeAt(index + 1) === 10) {\n\t\t\t\t\t\t\tindex += 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tindex += 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (stringChar === quote) {\n\t\t\t\t\tindex += 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (stringChar === 10) {\n\t\t\t\t\t// CSS strings normally can't span unescaped newlines; bail to\n\t\t\t\t\t// avoid swallowing the rest of the file when the quote is\n\t\t\t\t\t// stranded.\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tindex += 1;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (character === 123) {\n\t\t\tstack.push(line);\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (character === 125) {\n\t\t\tconst startLine = stack.pop();\n\t\t\tif (startLine != null && startLine !== line) {\n\t\t\t\tranges.push({ id: String(startLine), startLine, endLine: line });\n\t\t\t}\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tindex += 1;\n\t}\n\n\treturn finalizeFoldRanges(ranges);\n}\n\nexport { computeCssFoldRanges };\n","import { finalizeFoldRanges, type FoldableRange } from \"@ngrok/mantle/highlight-utils\";\nimport { html, parse, parseFragment } from \"parse5\";\nimport type { DefaultTreeAdapterMap } from \"parse5\";\n\n/**\n * AST-based fold computer for HTML and XML.\n *\n * Uses `parse5` with `sourceCodeLocationInfo: true` so each element node carries\n * the line numbers of its open and close tags. Walking the tree gives us:\n *\n * - One fold per multi-line element (`<div>…</div>`).\n * - One fold per multi-line opening tag (`<div\\n class=\"x\"\\n>` — the\n * attribute list collapses).\n * - Correct void-element handling — parse5 already knows that `<br>`, `<img>`,\n * etc. don't open folds.\n * - Template content traversal — parse5 stores `<template>` descendants on a\n * separate `content` fragment, not on `childNodes`.\n * - String/comment scope filtering — angle brackets in `<!-- … -->` or\n * inside `\"…\"` attribute values aren't mistaken for tag openings.\n *\n * @see https://parse5.js.org/\n */\n\ntype HtmlFoldLanguage = \"html\" | \"xml\";\n\ntype Element = DefaultTreeAdapterMap[\"element\"];\ntype Node = DefaultTreeAdapterMap[\"node\"];\n\n/**\n * SVG-namespace URI used as a fragment context when parsing XML.\n *\n * In SVG context, `parse5` switches its tokenizer into \"foreign content\"\n * mode, which is much closer to XML semantics:\n *\n * - Self-closing `<foo/>` is honored.\n * - Element names are case-preserved.\n * - HTML-only void elements (`<br>`, `<img>`) are not auto-closed.\n *\n * That makes it acceptable as a stand-in XML parser for code blocks. The\n * caveat is that a few SVG-recognized names (`<title>`, `<desc>`, `<script>`,\n * `<style>`, `<foreignObject>`) revert to HTML rules inside their bodies; in\n * practice that's rare in user XML and yields conservative folding (still\n * correct, just sometimes more flat than VS Code's XML folder).\n */\nconst SVG_NAMESPACE = html.NS.SVG;\n\n/**\n * Synthetic SVG fragment context shared across XML parses. Only the namespace\n * matters for the foreign-content tokenizer mode; the rest of the fields\n * satisfy parse5's tree-adapter shape.\n */\nconst xmlFragmentContext = {\n\tnodeName: \"svg\",\n\ttagName: \"svg\",\n\tnamespaceURI: SVG_NAMESPACE,\n\tattrs: [],\n\tchildNodes: [],\n\tparentNode: null,\n} as unknown as DefaultTreeAdapterMap[\"parentNode\"];\n\n/**\n * Returns true when a parse5 tree node has element-style `tagName` and child\n * nodes — i.e. it's an `Element` we should consider folding. Comments,\n * doctypes, text nodes, and the document root all fail this check.\n */\nfunction isElement(node: Node): node is Element {\n\treturn (\n\t\t\"tagName\" in node &&\n\t\ttypeof (node as { tagName?: unknown }).tagName === \"string\" &&\n\t\t\"childNodes\" in node\n\t);\n}\n\n/**\n * Traverses `root` depth-first and pushes a {@link FoldableRange} for every\n * element whose source span covers more than one line.\n *\n * Multi-line *elements* fold from the opening tag's start line to the closing\n * tag's end line (or to the element end when `endTag` info is unavailable —\n * parse5 sometimes synthesizes elements without a real closer when handling\n * malformed input).\n *\n * Multi-line *opening tags* (e.g. `<div\\n class=\"x\">`) fold from the start\n * of the tag to its `>` so the attribute list collapses into the tag name.\n * VS Code emits this as a separate \"tag\" fold marker; we mirror that.\n */\nfunction collectRanges(root: Node, ranges: FoldableRange[]): void {\n\tconst stack: Node[] = [root];\n\twhile (stack.length > 0) {\n\t\tconst node = stack.pop();\n\t\tif (node == null) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (isElement(node)) {\n\t\t\tpushRangesForElement(node, ranges);\n\t\t}\n\t\tpushChildNodes(node, stack);\n\n\t\t// parse5 models `<template>` descendants inside `node.content`, a\n\t\t// DocumentFragment, while `node.childNodes` stays empty. Include that\n\t\t// fragment so nested HTML in templates gets the same folds as normal\n\t\t// element children without recursing or re-walking the tree.\n\t\tif (\"content\" in node && typeof node.content === \"object\" && node.content != null) {\n\t\t\tpushChildNodes(node.content, stack);\n\t\t}\n\t}\n}\n\n/** Pushes parse5 child nodes onto the DFS stack in source order. */\nfunction pushChildNodes(parent: unknown, stack: Node[]): void {\n\tif (typeof parent !== \"object\" || parent == null || !(\"childNodes\" in parent)) {\n\t\treturn;\n\t}\n\tconst childNodes = parent.childNodes;\n\tif (!Array.isArray(childNodes)) {\n\t\treturn;\n\t}\n\tfor (let index = childNodes.length - 1; index >= 0; index -= 1) {\n\t\tconst child = childNodes[index];\n\t\tif (child != null) {\n\t\t\tstack.push(child as Node);\n\t\t}\n\t}\n}\n\n/**\n * Emits up to two fold ranges for a single element: one for the element's\n * full body and one for its multi-line opening tag.\n */\nfunction pushRangesForElement(element: Element, ranges: FoldableRange[]): void {\n\tconst location = element.sourceCodeLocation;\n\tif (location == null) {\n\t\t// Implicit/synthetic elements (e.g. `<html>`/`<body>` parse5 fabricates\n\t\t// for fragment input) don't appear in the source. Skip them so we\n\t\t// don't emit folds without a real opener.\n\t\treturn;\n\t}\n\n\tconst startTag = location.startTag;\n\tconst endTag = location.endTag;\n\n\t// The element is a self-closing or void tag (no close tag in the source).\n\t// `<br>` HTML void elements and `<foo/>` XML self-closing tags both land\n\t// here; neither opens a fold.\n\tif (endTag == null) {\n\t\t// A multi-line single-tag element (`<input\\n type=\"text\"\\n/>`) still\n\t\t// gets the attribute-list fold below.\n\t\tpushTagFoldIfMultiline(startTag, ranges);\n\t\treturn;\n\t}\n\n\tconst startLine = location.startLine;\n\tconst endLine = location.endLine;\n\tif (endLine > startLine) {\n\t\tranges.push({ id: String(startLine), startLine, endLine });\n\t}\n\tpushTagFoldIfMultiline(startTag, ranges);\n}\n\n/**\n * Pushes a fold range for an opening tag (`startTag`) when its `<` and `>`\n * sit on different lines. Conservative: contributes nothing for single-line\n * tags so we don't fight `pushRangesForElement` for the same opener.\n */\nfunction pushTagFoldIfMultiline(\n\tstartTag: { startLine: number; endLine: number } | undefined,\n\tranges: FoldableRange[],\n): void {\n\tif (startTag == null) {\n\t\treturn;\n\t}\n\tif (startTag.endLine > startTag.startLine) {\n\t\tranges.push({\n\t\t\tid: String(startTag.startLine),\n\t\t\tstartLine: startTag.startLine,\n\t\t\tendLine: startTag.endLine,\n\t\t});\n\t}\n}\n\n/**\n * Computes foldable ranges for an HTML or XML source string.\n *\n * - HTML: uses `parse5.parse` so explicit `<html>`/`<head>`/`<body>` are\n * honored as foldable openers. Implicit wrappers parse5 fabricates for\n * fragment input have no `sourceCodeLocation` and are skipped.\n * - XML: uses `parse5.parseFragment` rooted in an SVG fragment context so the\n * tokenizer applies foreign-content (XML-like) rules — self-closing `<foo/>`\n * is respected, void HTML elements aren't special-cased.\n *\n * @example\n * computeHtmlFoldRanges({ code: \"<div>\\n <p>hi</p>\\n</div>\", language: \"html\" });\n * // => [{ id: \"1\", startLine: 1, endLine: 3 }]\n */\nfunction computeHtmlFoldRanges({\n\tcode,\n\tlanguage,\n}: {\n\t/** Raw source code to parse. */\n\tcode: string;\n\t/** Resolved Mantle language; selects HTML vs. XML parsing rules. */\n\tlanguage: HtmlFoldLanguage;\n}): FoldableRange[] {\n\tif (code.length === 0) {\n\t\treturn [];\n\t}\n\n\tconst document =\n\t\tlanguage === \"xml\"\n\t\t\t? parseFragment(xmlFragmentContext, code, { sourceCodeLocationInfo: true })\n\t\t\t: parse(code, { sourceCodeLocationInfo: true });\n\n\tconst ranges: FoldableRange[] = [];\n\tcollectRanges(document, ranges);\n\treturn finalizeFoldRanges(ranges);\n}\n\nexport { computeHtmlFoldRanges };\nexport type { HtmlFoldLanguage };\n","/**\n * Helpers for converting parser byte offsets into 1-indexed line numbers.\n *\n * Every AST-based fold strategy in this package speaks line numbers (because\n * `FoldableRange.startLine` / `endLine` are line-anchored), but parsers like\n * `oxc-parser` and `postcss` report offsets / line+col tuples derived from\n * byte positions. Building a single sorted `lineOffsets` array up front keeps\n * the per-node lookup `O(log n)` instead of rescanning the source each call.\n */\n\n/**\n * Returns an array where index `i` holds the byte offset of the start of\n * the `i + 1`-th line of `source`. The first entry is always `0`.\n *\n * Treats `\\n`, `\\r\\n`, and bare `\\r` as line breaks so it agrees with how\n * Shiki, oxc, parse5, and postcss split lines (they all match the JS\n * runtime's `String.prototype.split(/\\r\\n|\\r|\\n/)` behavior in practice).\n */\nfunction buildLineOffsets(source: string): number[] {\n\tconst offsets: number[] = [0];\n\tconst length = source.length;\n\tfor (let index = 0; index < length; index += 1) {\n\t\tconst character = source.charCodeAt(index);\n\t\tif (character === 10) {\n\t\t\toffsets.push(index + 1);\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === 13) {\n\t\t\t// `\\r\\n` and bare `\\r` both start a new line at index + 1 (or + 2 when\n\t\t\t// followed by `\\n`); skip the `\\n` to avoid pushing a duplicate offset.\n\t\t\tconst isCrLf = index + 1 < length && source.charCodeAt(index + 1) === 10;\n\t\t\toffsets.push(isCrLf ? index + 2 : index + 1);\n\t\t\tif (isCrLf) {\n\t\t\t\tindex += 1;\n\t\t\t}\n\t\t}\n\t}\n\treturn offsets;\n}\n\n/**\n * Returns the 1-indexed line number that contains `offset` in the source\n * scanned by {@link buildLineOffsets}. Out-of-range offsets clamp to the\n * first or last line.\n */\nfunction offsetToLine(lineOffsets: readonly number[], offset: number): number {\n\tif (lineOffsets.length === 0) {\n\t\treturn 1;\n\t}\n\tif (offset <= 0) {\n\t\treturn 1;\n\t}\n\tlet low = 0;\n\tlet high = lineOffsets.length - 1;\n\twhile (low < high) {\n\t\t// Bias the midpoint toward `high` so the loop terminates when\n\t\t// `lineOffsets[mid] <= offset` repeatedly succeeds with `low === mid`.\n\t\tconst mid = (low + high + 1) >>> 1;\n\t\tconst start = lineOffsets[mid] ?? 0;\n\t\tif (start <= offset) {\n\t\t\tlow = mid;\n\t\t} else {\n\t\t\thigh = mid - 1;\n\t\t}\n\t}\n\treturn low + 1;\n}\n\nexport { buildLineOffsets, offsetToLine };\n","import { finalizeFoldRanges, type FoldableRange } from \"@ngrok/mantle/highlight-utils\";\nimport { createRequire } from \"node:module\";\nimport type { ParserOptions } from \"oxc-parser\";\nimport { buildLineOffsets, offsetToLine } from \"./line-offsets.js\";\n\n/**\n * Loads `oxc-parser` lazily on first use. Eager `import` of oxc-parser runs\n * its napi-rs bootstrap (`bindings.js`), which `throw`s synchronously when the\n * platform-specific native binding (`@oxc-parser/binding-*`) isn't resolvable\n * — common on serverless hosts that ship the bundled JS without the binding\n * package alongside it. A throw at module-eval time would propagate through\n * the entire server bundle's import graph and 500 every route, not just\n * JSX/TSX folding. Deferring the load until folding runs lets this strategy\n * convert the failure into a cached \"no folds\" fallback while keeping every\n * other strategy working.\n */\ntype OxcParser = typeof import(\"oxc-parser\");\nconst requireOxc = createRequire(import.meta.url);\n\n/** Creates a memoized parser loader that caches both success and load failure. */\nfunction createOxcParserLoader(load: () => OxcParser): () => OxcParser | undefined {\n\tlet cachedOxcParser: OxcParser | undefined;\n\tlet didFailToLoadOxcParser = false;\n\n\treturn () => {\n\t\tif (cachedOxcParser != null) {\n\t\t\treturn cachedOxcParser;\n\t\t}\n\t\tif (didFailToLoadOxcParser) {\n\t\t\treturn undefined;\n\t\t}\n\t\tlet oxcParser: OxcParser;\n\t\ttry {\n\t\t\toxcParser = load();\n\t\t} catch {\n\t\t\tdidFailToLoadOxcParser = true;\n\t\t\treturn undefined;\n\t\t}\n\t\tcachedOxcParser = oxcParser;\n\t\treturn oxcParser;\n\t};\n}\n\n/** Returns the lazily-resolved `oxc-parser` module, or undefined after a cached load failure. */\nconst loadOxcParser = createOxcParserLoader(() => requireOxc(\"oxc-parser\") as OxcParser);\n\n/**\n * AST-based fold computer for the JS/TS/JSX/TSX language family.\n *\n * Mirrors VS Code's TypeScript language service folder by walking the parsed\n * AST instead of pairing brackets in the token stream. This lets us fold\n * constructs that bracket-pairing can't see:\n *\n * - JSX elements (`<Foo>…</Foo>`, fragments, members like `<obj.Foo>`).\n * - Template literals that span multiple lines (including tagged templates).\n *\n * It also keeps every fold the bracket strategy used to give us — block\n * statements, object literals, array literals, class/interface bodies, switch\n * statements — without the per-character scope-walk cost.\n *\n * @see https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/languageFeatures/folding.ts\n */\n\n/** Subset of supported languages handled by this computer. */\ntype JsxFoldLanguage = \"javascript\" | \"js\" | \"typescript\" | \"ts\" | \"jsx\" | \"tsx\";\n\n/**\n * Maps a Mantle language to the oxc-parser `lang` option. JavaScript keeps\n * JSX enabled so JSX-in-JS examples still fold, but TypeScript must stay in\n * plain `ts` mode: TSX parses generic arrow functions (`<T>(x: T) => ...`) as\n * JSX and drops the AST folds for otherwise-valid TypeScript snippets.\n */\nfunction oxcLangFor(language: JsxFoldLanguage): \"jsx\" | \"ts\" | \"tsx\" {\n\tswitch (language) {\n\t\tcase \"tsx\":\n\t\t\treturn \"tsx\";\n\t\tcase \"typescript\":\n\t\tcase \"ts\":\n\t\t\treturn \"ts\";\n\t\tcase \"jsx\":\n\t\tcase \"javascript\":\n\t\tcase \"js\":\n\t\t\treturn \"jsx\";\n\t}\n}\n\n/** Minimal AST node shape — every oxc node carries `type`, `start`, `end`. */\ntype AstNode = {\n\ttype: string;\n\tstart: number;\n\tend: number;\n\t[key: string]: unknown;\n};\n\n/** Type guard for an arbitrary value being an AST node. */\nfunction isAstNode(value: unknown): value is AstNode {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue != null &&\n\t\t\"type\" in value &&\n\t\ttypeof (value as { type?: unknown }).type === \"string\" &&\n\t\t\"start\" in value &&\n\t\ttypeof (value as { start?: unknown }).start === \"number\" &&\n\t\t\"end\" in value &&\n\t\ttypeof (value as { end?: unknown }).end === \"number\"\n\t);\n}\n\n/**\n * AST node types whose `start`/`end` positions delimit a foldable region\n * when they span multiple lines.\n *\n * Curated to match VS Code's TypeScript folder:\n * - Block-like statement bodies — covers function/method bodies, class bodies,\n * `if`/`for`/`while` blocks, modules, namespaces.\n * - Object & array literals — covers JSON-shaped data and JSX style props.\n * - JSX elements & fragments — open/close tags fold like HTML.\n * - Template literals — fold multi-line backtick strings (including tagged).\n * - Switch statements — VS Code folds the whole `switch (…) { … }`, not each case.\n */\nconst FOLDABLE_NODE_TYPES = new Set<string>([\n\t\"BlockStatement\",\n\t\"ClassBody\",\n\t\"ObjectExpression\",\n\t\"ObjectPattern\",\n\t\"ArrayExpression\",\n\t\"ArrayPattern\",\n\t\"JSXElement\",\n\t\"JSXFragment\",\n\t\"TemplateLiteral\",\n\t\"SwitchStatement\",\n\t// TypeScript-only:\n\t\"TSInterfaceBody\",\n\t\"TSTypeLiteral\",\n\t\"TSEnumBody\",\n\t\"TSEnumDeclaration\",\n\t\"TSModuleBlock\",\n\t\"TSMappedType\",\n]);\n\n/** Returns the `openingElement` of a `JSXElement` if present (the `<Foo …>` span). */\nfunction jsxOpeningElement(node: AstNode): AstNode | undefined {\n\tif (node.type !== \"JSXElement\") {\n\t\treturn undefined;\n\t}\n\tconst opening = (node as { openingElement?: unknown }).openingElement;\n\treturn isAstNode(opening) ? opening : undefined;\n}\n\n/** Returns true when a `JSXOpeningElement` is self-closing (`<Foo/>`). */\nfunction isSelfClosingOpening(opening: AstNode): boolean {\n\tconst selfClosing = (opening as { selfClosing?: unknown }).selfClosing;\n\treturn selfClosing === true;\n}\n\n/**\n * Recursively walks every AST node reachable from `root`, calling `visit`\n * with each one. Mirrors the helper used in the Vite plugin but stays local\n * so this module has no extra cross-package dependency.\n */\nfunction walk(root: unknown, visit: (node: AstNode) => void): void {\n\tif (Array.isArray(root)) {\n\t\tfor (const item of root) {\n\t\t\twalk(item, visit);\n\t\t}\n\t\treturn;\n\t}\n\tif (!isAstNode(root)) {\n\t\treturn;\n\t}\n\tvisit(root);\n\tfor (const value of Object.values(root)) {\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (const item of value) {\n\t\t\t\twalk(item, visit);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (isAstNode(value)) {\n\t\t\twalk(value, visit);\n\t\t}\n\t}\n}\n\n/**\n * Filename passed to `oxc-parser` purely for diagnostic strings; the actual\n * grammar comes from the `lang` option on the parser options object.\n */\nconst SYNTHETIC_FILENAME = \"__mantle_fold__\";\n\n/**\n * Pushes a {@link FoldableRange} for the source span `[startOffset, endOffset]`\n * (inclusive) when it crosses a line boundary. Single-line spans contribute\n * nothing — there's nothing to fold.\n */\nfunction pushRange(\n\tranges: FoldableRange[],\n\tlineOffsets: readonly number[],\n\tstartOffset: number,\n\tendOffset: number,\n): void {\n\tconst startLine = offsetToLine(lineOffsets, startOffset);\n\tconst endLine = offsetToLine(lineOffsets, endOffset);\n\tif (endLine > startLine) {\n\t\tranges.push({ id: String(startLine), startLine, endLine });\n\t}\n}\n\n/**\n * Computes foldable ranges for a JS/TS/JSX/TSX source string by parsing it\n * with `oxc-parser` and walking the AST. Errors are tolerated — a partial AST\n * still produces useful folds.\n *\n * @example\n * computeJsxFoldRanges({ code: \"<Foo>\\n <Bar/>\\n</Foo>\", language: \"tsx\" });\n * // => [{ id: \"1\", startLine: 1, endLine: 3 }]\n */\nfunction computeJsxFoldRanges({\n\tcode,\n\tlanguage,\n}: {\n\t/** Raw source code to parse and fold. */\n\tcode: string;\n\t/** Resolved Mantle language; controls grammar selection (TS vs JS, JSX vs plain). */\n\tlanguage: JsxFoldLanguage;\n}): FoldableRange[] {\n\tif (code.length === 0) {\n\t\treturn [];\n\t}\n\n\tconst options: ParserOptions = {\n\t\t// `unambiguous` lets the parser accept both `script` and `module` code,\n\t\t// matching how a code block is rendered without `import`/`export` context.\n\t\tsourceType: \"unambiguous\",\n\t\tlang: oxcLangFor(language),\n\t};\n\tconst oxcParser = loadOxcParser();\n\tif (oxcParser == null) {\n\t\treturn [];\n\t}\n\tconst { parseSync } = oxcParser;\n\tconst parsed = parseSync(SYNTHETIC_FILENAME, code, options);\n\tconst lineOffsets = buildLineOffsets(code);\n\tconst ranges: FoldableRange[] = [];\n\n\twalk(parsed.program, (node) => {\n\t\t// JSX elements get split treatment so multi-line attribute lists fold\n\t\t// even on self-closing tags (which have no separate body to fold).\n\t\tif (node.type === \"JSXElement\") {\n\t\t\tconst opening = jsxOpeningElement(node);\n\t\t\tconst isSelfClosing = opening != null && isSelfClosingOpening(opening);\n\t\t\tif (isSelfClosing) {\n\t\t\t\t// Self-closing tags fold the open-tag span only — there's no\n\t\t\t\t// body. Diverges from VS Code's stock TS folder, which doesn't\n\t\t\t\t// fold these at all, but matches what JSX authors actually want\n\t\t\t\t// for long attribute lists across multiple lines.\n\t\t\t\tif (opening != null) {\n\t\t\t\t\tpushRange(ranges, lineOffsets, opening.start, opening.end - 1);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Non-self-closing: fold the whole element AND any multi-line\n\t\t\t// opening tag's attribute list. After dedup, when both share an\n\t\t\t// opener line, the larger element fold wins — but the open-tag\n\t\t\t// fold survives when it has its own opener line offset.\n\t\t\tpushRange(ranges, lineOffsets, node.start, node.end - 1);\n\t\t\tif (opening != null) {\n\t\t\t\tpushRange(ranges, lineOffsets, opening.start, opening.end - 1);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (!FOLDABLE_NODE_TYPES.has(node.type)) {\n\t\t\treturn;\n\t\t}\n\t\tpushRange(ranges, lineOffsets, node.start, node.end - 1);\n\t});\n\n\treturn finalizeFoldRanges(ranges);\n}\n\nexport { computeJsxFoldRanges, createOxcParserLoader };\nexport type { JsxFoldLanguage };\n","import {\n\tfinalizeFoldRanges,\n\ttype FoldableRange,\n\ttype FoldLine,\n} from \"@ngrok/mantle/highlight-utils\";\n\n/**\n * Keyword-pair fold computer for languages whose blocks are delimited by\n * keywords rather than punctuation.\n *\n * VS Code models this with `foldingStartMarker` / `foldingStopMarker`\n * declarations in each language's `language-configuration.json`. We mirror\n * that behavior with linear marker predicates, evaluated against the\n * *visible* (non-string, non-comment) portion of each line — the Shiki tokens\n * carry scope information that lets us strip those out reliably.\n *\n * The stack is untyped — every closer pops the most recent opener, regardless\n * of which keyword opened it. Real source code nests properly, so this stays\n * correct without per-keyword tracking, and matches VS Code's marker-based\n * behavior.\n *\n * @see https://github.com/microsoft/vscode/blob/main/extensions/ruby/language-configuration.json\n * @see https://github.com/microsoft/vscode/blob/main/extensions/shellscript/language-configuration.json\n */\n\n/** Languages this computer knows how to fold. */\ntype KeywordFoldLanguage = \"ruby\" | \"rb\" | \"bash\" | \"sh\" | \"shell\";\n\n/**\n * Per-line opener/closer marker pair. The predicates intentionally match the\n * *visible* line content (after string and comment scopes are filtered out)\n * — interpolated `do … end` markers inside a string don't trigger folds.\n */\ntype KeywordPattern = {\n\t/** Returns true when this line opens a foldable block. */\n\tstartsFold: (visible: string) => boolean;\n\t/** Returns true when this line closes a foldable block. */\n\tendsFold: (visible: string) => boolean;\n};\n\nconst RUBY_START_KEYWORDS: readonly string[] = [\n\t\"def\",\n\t\"class\",\n\t\"module\",\n\t\"begin\",\n\t\"if\",\n\t\"unless\",\n\t\"while\",\n\t\"until\",\n\t\"for\",\n\t\"case\",\n];\nconst BASH_START_KEYWORDS: readonly string[] = [\"if\", \"while\", \"for\", \"case\", \"until\", \"select\"];\nconst BASH_END_KEYWORDS: readonly string[] = [\"fi\", \"esac\", \"done\"];\n\n/**\n * Ruby keyword folds modeled after VS Code's grammar. Covers:\n *\n * - Definition keywords at the start of a line: `def`, `class`, `module`, `begin`.\n * - Control-flow openers at the start of a line: `if`, `unless`, `while`,\n * `until`, `for`, `case` — Ruby's flagship multi-line constructs.\n * - Trailing `do` / `do |args|` for blocks attached to a method call.\n *\n * `end` always closes; mid-block keywords (`else`, `elsif`, `when`, `rescue`,\n * `ensure`) deliberately don't, so a single `if … else … end` becomes one\n * fold, not three.\n */\nconst RUBY_PATTERN: KeywordPattern = {\n\tstartsFold: rubyStartsFold,\n\tendsFold: (visible) => startsWithAnyWordAfterWhitespace(visible, [\"end\"]),\n};\n\n/**\n * Bash / Shell keyword folds modeled after VS Code's grammar.\n *\n * - Opener keywords at the start of a line — `if`, `while`, `for`, `case`,\n * `until`, `select` — that aren't closed by a same-line command marker.\n * - Lines ending with an unmatched `{` (function bodies, brace groups).\n * - Lines ending with `do` (the `for x in y; do` / `while cond; do` form).\n *\n * The end predicate matches `}` only when it leads its line — that lets us\n * close brace groups while ignoring `${VAR}` parameter expansions, which\n * are never line-leading.\n */\nconst BASH_PATTERN: KeywordPattern = {\n\tstartsFold: bashStartsFold,\n\tendsFold: bashEndsFold,\n};\n\n/** Returns true for ASCII identifier characters used by shell/Ruby keywords. */\nfunction isWordChar(character: number): boolean {\n\treturn (\n\t\t(character >= 48 && character <= 57) ||\n\t\t(character >= 65 && character <= 90) ||\n\t\t(character >= 97 && character <= 122) ||\n\t\tcharacter === 95\n\t);\n}\n\n/** Returns true for whitespace characters accepted around language markers. */\nfunction isWhitespaceChar(character: number): boolean {\n\treturn (\n\t\tcharacter === 9 ||\n\t\tcharacter === 10 ||\n\t\tcharacter === 11 ||\n\t\tcharacter === 12 ||\n\t\tcharacter === 13 ||\n\t\tcharacter === 32\n\t);\n}\n\n/** Returns the index of the first non-whitespace character in `text`. */\nfunction firstNonWhitespaceIndex(text: string): number {\n\tlet index = 0;\n\twhile (index < text.length && isWhitespaceChar(text.charCodeAt(index))) {\n\t\tindex += 1;\n\t}\n\treturn index;\n}\n\n/** Returns the exclusive index after the last non-whitespace character. */\nfunction endTrimmedIndex(text: string): number {\n\tlet index = text.length;\n\twhile (index > 0 && isWhitespaceChar(text.charCodeAt(index - 1))) {\n\t\tindex -= 1;\n\t}\n\treturn index;\n}\n\n/** Returns true if `word` appears at `index` with word boundaries. */\nfunction isWordAt(text: string, index: number, word: string, end = text.length): boolean {\n\tif (index < 0 || index + word.length > end) {\n\t\treturn false;\n\t}\n\tif (text.slice(index, index + word.length) !== word) {\n\t\treturn false;\n\t}\n\tconst beforeIsBoundary = index === 0 || !isWordChar(text.charCodeAt(index - 1));\n\tconst afterIndex = index + word.length;\n\tconst afterIsBoundary = afterIndex >= end || !isWordChar(text.charCodeAt(afterIndex));\n\treturn beforeIsBoundary && afterIsBoundary;\n}\n\n/** Returns true when a line begins with one of the given keywords. */\nfunction startsWithAnyWordAfterWhitespace(text: string, words: readonly string[]): boolean {\n\tconst index = firstNonWhitespaceIndex(text);\n\tfor (const word of words) {\n\t\tif (isWordAt(text, index, word)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Returns true when `index` is positioned where the shell can begin another\n * command word on the same physical line. This intentionally ignores ordinary\n * arguments and variables like `$done`, so `case $done in` still opens a fold.\n */\nfunction isShellCommandBoundary(text: string, index: number): boolean {\n\tlet cursor = index - 1;\n\twhile (cursor >= 0 && isWhitespaceChar(text.charCodeAt(cursor))) {\n\t\tcursor -= 1;\n\t}\n\tif (cursor < 0) {\n\t\treturn true;\n\t}\n\tconst previous = text.charCodeAt(cursor);\n\treturn previous === 38 || previous === 40 || previous === 59 || previous === 124;\n}\n\n/**\n * Returns true when a Bash closer appears as a same-line command marker, e.g.\n * `if ok; then echo hi; fi`. A single linear scan is cheaper than running one\n * regex per marker and keeps shell variables / arguments named `done`, `fi`,\n * or `esac` from suppressing valid opener folds.\n */\nfunction hasShellSameLineEndKeyword(text: string): boolean {\n\tfor (let index = 0; index < text.length; index += 1) {\n\t\tconst character = text.charCodeAt(index);\n\t\tif (!isWordChar(character)) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const word of BASH_END_KEYWORDS) {\n\t\t\tif (isWordAt(text, index, word) && isShellCommandBoundary(text, index)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\twhile (index + 1 < text.length && isWordChar(text.charCodeAt(index + 1))) {\n\t\t\tindex += 1;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Returns true when a line starts with a shell closer command. `done)` and\n * similar case labels are deliberately excluded; `)` is not a command\n * separator, so those labels should not pop the fold stack.\n */\nfunction startsWithShellEndKeyword(text: string): boolean {\n\tconst index = firstNonWhitespaceIndex(text);\n\tfor (const word of BASH_END_KEYWORDS) {\n\t\tif (!isWordAt(text, index, word)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst next = text.charCodeAt(index + word.length);\n\t\treturn (\n\t\t\tNumber.isNaN(next) || isWhitespaceChar(next) || next === 38 || next === 59 || next === 124\n\t\t);\n\t}\n\treturn false;\n}\n\n/** Returns true when a line ends with `word`, ignoring trailing whitespace. */\nfunction endsWithWord(text: string, word: string): boolean {\n\tconst end = endTrimmedIndex(text);\n\treturn isWordAt(text, end - word.length, word, end);\n}\n\n/** Returns true for trailing Ruby `do` / `do |args|` block openers. */\nfunction endsWithRubyDoBlock(text: string): boolean {\n\tlet end = endTrimmedIndex(text);\n\tif (end <= 0) {\n\t\treturn false;\n\t}\n\tif (text.charCodeAt(end - 1) === 124) {\n\t\tconst paramsStart = text.lastIndexOf(\"|\", end - 2);\n\t\tif (paramsStart === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tend = paramsStart;\n\t\twhile (end > 0 && isWhitespaceChar(text.charCodeAt(end - 1))) {\n\t\t\tend -= 1;\n\t\t}\n\t}\n\treturn isWordAt(text, end - 2, \"do\", end);\n}\n\n/** Returns true when a Ruby line opens a keyword-paired block. */\nfunction rubyStartsFold(visible: string): boolean {\n\treturn (\n\t\tstartsWithAnyWordAfterWhitespace(visible, RUBY_START_KEYWORDS) || endsWithRubyDoBlock(visible)\n\t);\n}\n\n/** Returns true when a shell line has a `{` with no later `}` on the same line. */\nfunction endsWithOpenBrace(visible: string): boolean {\n\treturn visible.lastIndexOf(\"{\") > visible.lastIndexOf(\"}\");\n}\n\n/** Returns true when a Bash/Shell line opens a keyword-paired block. */\nfunction bashStartsFold(visible: string): boolean {\n\tif (\n\t\tstartsWithAnyWordAfterWhitespace(visible, BASH_START_KEYWORDS) &&\n\t\t!hasShellSameLineEndKeyword(visible)\n\t) {\n\t\treturn true;\n\t}\n\treturn endsWithOpenBrace(visible) || endsWithWord(visible, \"do\");\n}\n\n/** Returns true when a Bash/Shell line closes a keyword-paired block. */\nfunction bashEndsFold(visible: string): boolean {\n\tconst firstContent = firstNonWhitespaceIndex(visible);\n\treturn visible.charCodeAt(firstContent) === 125 || startsWithShellEndKeyword(visible);\n}\n\n/** Resolves the keyword pattern for a given language. */\nfunction patternFor(language: KeywordFoldLanguage): KeywordPattern {\n\tswitch (language) {\n\t\tcase \"ruby\":\n\t\tcase \"rb\":\n\t\t\treturn RUBY_PATTERN;\n\t\tcase \"bash\":\n\t\tcase \"sh\":\n\t\tcase \"shell\":\n\t\t\treturn BASH_PATTERN;\n\t}\n}\n\n/**\n * TextMate scope prefixes that mark a token as inert content (string body,\n * comment body, character escape). Mirrors the filter used by\n * `computeFoldRanges` for the bracket strategy so behaviors stay consistent.\n */\nconst INERT_SCOPE_PREFIXES: readonly string[] = [\n\t\"string.\",\n\t\"comment.\",\n\t\"constant.character.escape\",\n];\n\n/** Returns true when the innermost scope of a token marks it inert. */\nfunction isInertScope(scopes: readonly { scopeName: string }[]): boolean {\n\tif (scopes.length === 0) {\n\t\treturn false;\n\t}\n\tconst innermost = scopes[scopes.length - 1]?.scopeName ?? \"\";\n\tif (innermost === \"string\" || innermost === \"comment\") {\n\t\treturn true;\n\t}\n\tfor (const prefix of INERT_SCOPE_PREFIXES) {\n\t\tif (innermost.startsWith(prefix)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Reconstructs the visible (non-string, non-comment) text of a single\n * tokenized line.\n *\n * Subtlety: Shiki keeps leading whitespace inside `token.content` but strips\n * it from every `explanation.content` piece — so `\" HttpListener\"` (token)\n * decomposes into `[{ content: \"HttpListener\", scopes: […] }]`. Iterating\n * explanations alone collapses adjacent identifiers (`class HttpListener`\n * becomes `classHttpListener`), which breaks every word-boundary keyword\n * regex. We use `token.content` whenever no explanation piece is inert and\n * only fall back to per-explanation iteration for mixed-scope tokens.\n */\nfunction visibleTextForLine(line: FoldLine): string {\n\tlet visible = \"\";\n\tfor (const token of line) {\n\t\tconst explanations = token.explanation;\n\t\tif (explanations == null || explanations.length === 0) {\n\t\t\tvisible += token.content;\n\t\t\tcontinue;\n\t\t}\n\t\tlet hasInert = false;\n\t\tfor (const explanation of explanations) {\n\t\t\tif (isInertScope(explanation.scopes)) {\n\t\t\t\thasInert = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!hasInert) {\n\t\t\tvisible += token.content;\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const explanation of explanations) {\n\t\t\tif (isInertScope(explanation.scopes)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvisible += explanation.content;\n\t\t}\n\t}\n\treturn visible;\n}\n\n/**\n * Computes foldable ranges from tokenized source lines using the language's\n * keyword opener/closer regex pair.\n *\n * The same line can both open and close a block (`if foo; end` in Ruby).\n * Such lines push and pop on the stack but their start/end coincide, so the\n * range gets discarded by the `endLine > startLine` filter — matching how\n * the bracket strategy treats single-line `{}` constructs.\n *\n * @example\n * // tokens: [[\"def f\"], [\" pass\"], [\"end\"]]\n * computeKeywordFoldRanges({ language: \"ruby\", tokens });\n * // => [{ id: \"1\", startLine: 1, endLine: 3 }]\n */\nfunction computeKeywordFoldRanges({\n\tlanguage,\n\ttokens,\n}: {\n\t/** Resolved Mantle language; controls which keyword pattern to use. */\n\tlanguage: KeywordFoldLanguage;\n\t/** Shiki-tokenized lines, with scope explanations populated. */\n\ttokens: FoldLine[];\n}): FoldableRange[] {\n\tconst pattern = patternFor(language);\n\tconst stack: number[] = [];\n\tconst ranges: FoldableRange[] = [];\n\n\tfor (let lineIndex = 0; lineIndex < tokens.length; lineIndex += 1) {\n\t\tconst line = tokens[lineIndex];\n\t\tif (line == null) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst visible = visibleTextForLine(line);\n\t\tif (visible.length === 0) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst lineNumber = lineIndex + 1;\n\n\t\t// Closers come first: `end` on the same line as a `do` (e.g. `loop do\n\t\t// end` written across two lines but both `do` and `end` are on different\n\t\t// lines) shouldn't first push then pop on the same iteration.\n\t\tif (pattern.endsFold(visible)) {\n\t\t\tconst startLine = stack.pop();\n\t\t\tif (startLine != null && startLine < lineNumber) {\n\t\t\t\tranges.push({ id: String(startLine), startLine, endLine: lineNumber });\n\t\t\t}\n\t\t}\n\t\tif (pattern.startsFold(visible)) {\n\t\t\tstack.push(lineNumber);\n\t\t}\n\t}\n\n\treturn finalizeFoldRanges(ranges);\n}\n\nexport { computeKeywordFoldRanges };\nexport type { KeywordFoldLanguage };\n","import {\n\tcomputeFoldRanges,\n\tcomputeJsonFoldRanges,\n\tfinalizeFoldRanges,\n\ttype FoldableRange,\n\ttype FoldLine,\n\ttype SupportedLanguage,\n} from \"@ngrok/mantle/highlight-utils\";\nimport { computeCssFoldRanges } from \"./compute-css-fold-ranges.js\";\nimport { computeHtmlFoldRanges, type HtmlFoldLanguage } from \"./compute-html-fold-ranges.js\";\nimport { computeJsxFoldRanges, type JsxFoldLanguage } from \"./compute-jsx-fold-ranges.js\";\nimport {\n\tcomputeKeywordFoldRanges,\n\ttype KeywordFoldLanguage,\n} from \"./compute-keyword-fold-ranges.js\";\n\n/**\n * Server-side folding strategy applied to a language. This is a richer\n * dispatch than `@ngrok/mantle/highlight-utils`'s `foldStrategyFor`:\n *\n * - `jsx-ast` parses JS / TS / JSX / TSX with `oxc-parser`.\n * - `html-ast` parses HTML / XML with `parse5`.\n * - `css-raw` runs a CSS-aware single-pass brace matcher.\n * - `json-raw` reuses the existing `computeJsonFoldRanges` (raw, scope-free).\n * - `token-bracket` / `token-indentation` are the existing token-based\n * strategies for languages without a heavier parser (Go, Rust, Java, C#,\n * Python, YAML).\n * - `token-keyword` matches keyword openers / closers against tokenized line\n * text (Bash / Shell).\n * - `token-bracket-and-keyword` runs the bracket pass *and* the keyword pass\n * and merges them — Ruby uses brace-style blocks (`{ |x| … }`) plus\n * keyword blocks (`def … end`).\n * - `none` opts out for plain text and unknown languages.\n *\n * Strategies suffixed `-ast` or `-raw` need only the raw source string;\n * `token-*` strategies need Shiki-tokenized lines with scope explanations.\n */\ntype ServerFoldStrategy =\n\t| \"jsx-ast\"\n\t| \"html-ast\"\n\t| \"css-raw\"\n\t| \"json-raw\"\n\t| \"token-bracket\"\n\t| \"token-indentation\"\n\t| \"token-keyword\"\n\t| \"token-bracket-and-keyword\"\n\t| \"none\";\n\n/** Returns the server fold strategy for the given supported language. */\nfunction serverFoldStrategyFor(language: SupportedLanguage): ServerFoldStrategy {\n\tswitch (language) {\n\t\tcase \"javascript\":\n\t\tcase \"js\":\n\t\tcase \"typescript\":\n\t\tcase \"ts\":\n\t\tcase \"jsx\":\n\t\tcase \"tsx\":\n\t\t\treturn \"jsx-ast\";\n\t\tcase \"html\":\n\t\tcase \"xml\":\n\t\t\treturn \"html-ast\";\n\t\tcase \"css\":\n\t\t\treturn \"css-raw\";\n\t\tcase \"json\":\n\t\t\treturn \"json-raw\";\n\t\tcase \"python\":\n\t\tcase \"py\":\n\t\tcase \"yaml\":\n\t\tcase \"yml\":\n\t\t\treturn \"token-indentation\";\n\t\tcase \"ruby\":\n\t\tcase \"rb\":\n\t\t\treturn \"token-bracket-and-keyword\";\n\t\tcase \"bash\":\n\t\tcase \"sh\":\n\t\tcase \"shell\":\n\t\t\treturn \"token-keyword\";\n\t\tcase \"plain\":\n\t\tcase \"plaintext\":\n\t\tcase \"text\":\n\t\tcase \"txt\":\n\t\t\treturn \"none\";\n\t\tdefault:\n\t\t\treturn \"token-bracket\";\n\t}\n}\n\n/**\n * Returns true when the strategy needs Shiki-tokenized lines (with scope\n * explanations) to run. AST and raw-source strategies operate on the source\n * string directly and let us skip the `includeExplanation: 'scopeName'`\n * Shiki option, saving meaningful work on JS/TS/HTML/CSS hot paths.\n */\nfunction serverFoldNeedsTokens(strategy: ServerFoldStrategy): boolean {\n\tswitch (strategy) {\n\t\tcase \"token-bracket\":\n\t\tcase \"token-indentation\":\n\t\tcase \"token-keyword\":\n\t\tcase \"token-bracket-and-keyword\":\n\t\t\treturn true;\n\t\tcase \"jsx-ast\":\n\t\tcase \"html-ast\":\n\t\tcase \"css-raw\":\n\t\tcase \"json-raw\":\n\t\tcase \"none\":\n\t\t\treturn false;\n\t}\n}\n\n/** Type guard: narrows `SupportedLanguage` to languages handled by the JSX strategy. */\nfunction isJsxFoldLanguage(language: SupportedLanguage): language is JsxFoldLanguage {\n\treturn (\n\t\tlanguage === \"javascript\" ||\n\t\tlanguage === \"js\" ||\n\t\tlanguage === \"typescript\" ||\n\t\tlanguage === \"ts\" ||\n\t\tlanguage === \"jsx\" ||\n\t\tlanguage === \"tsx\"\n\t);\n}\n\n/** Type guard: narrows `SupportedLanguage` to languages handled by the HTML strategy. */\nfunction isHtmlFoldLanguage(language: SupportedLanguage): language is HtmlFoldLanguage {\n\treturn language === \"html\" || language === \"xml\";\n}\n\n/** Type guard: narrows `SupportedLanguage` to languages handled by the keyword strategy. */\nfunction isKeywordFoldLanguage(language: SupportedLanguage): language is KeywordFoldLanguage {\n\treturn (\n\t\tlanguage === \"ruby\" ||\n\t\tlanguage === \"rb\" ||\n\t\tlanguage === \"bash\" ||\n\t\tlanguage === \"sh\" ||\n\t\tlanguage === \"shell\"\n\t);\n}\n\n/**\n * Computes foldable ranges for a single highlighted code block, dispatching\n * to the appropriate strategy. Every supported language flows through here,\n * including the legacy token-based ones, so the engine has a single decision\n * point.\n *\n * Caller contract:\n * - For token-needing strategies, `tokens` must be the lines produced by\n * Shiki with `includeExplanation: 'scopeName'`. Pass `undefined` and the\n * strategy returns `[]`.\n * - For raw / AST strategies, `tokens` is ignored; only `code` matters.\n *\n * Errors raised by underlying parsers are caught and converted into \"no\n * folds\" — Shiki still gets to render the highlighted code, the gutter just\n * skips the toggle. We log nothing here because the engine is the wrong\n * layer to surface diagnostics.\n */\nfunction computeServerFoldRanges({\n\tcode,\n\tlanguage,\n\ttokens,\n}: {\n\t/** Normalized source code (post-`normalizeIndentation`). */\n\tcode: string;\n\t/** Resolved Mantle supported language. */\n\tlanguage: SupportedLanguage;\n\t/** Shiki-tokenized lines, when the strategy needs them. */\n\ttokens: FoldLine[] | undefined;\n}): FoldableRange[] {\n\tconst strategy = serverFoldStrategyFor(language);\n\ttry {\n\t\tswitch (strategy) {\n\t\t\tcase \"jsx-ast\":\n\t\t\t\tif (!isJsxFoldLanguage(language)) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\treturn computeJsxFoldRanges({ code, language });\n\t\t\tcase \"html-ast\":\n\t\t\t\tif (!isHtmlFoldLanguage(language)) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\treturn computeHtmlFoldRanges({ code, language });\n\t\t\tcase \"css-raw\":\n\t\t\t\treturn computeCssFoldRanges({ code });\n\t\t\tcase \"json-raw\":\n\t\t\t\treturn computeJsonFoldRanges(code);\n\t\t\tcase \"token-bracket\":\n\t\t\tcase \"token-indentation\":\n\t\t\t\tif (tokens == null) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\treturn computeFoldRanges({ language, tokens });\n\t\t\tcase \"token-keyword\":\n\t\t\t\tif (tokens == null || !isKeywordFoldLanguage(language)) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\treturn computeKeywordFoldRanges({ language, tokens });\n\t\t\tcase \"token-bracket-and-keyword\":\n\t\t\t\tif (tokens == null || !isKeywordFoldLanguage(language)) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\treturn finalizeFoldRanges([\n\t\t\t\t\t...computeFoldRanges({ language, tokens }),\n\t\t\t\t\t...computeKeywordFoldRanges({ language, tokens }),\n\t\t\t\t]);\n\t\t\tcase \"none\":\n\t\t\t\treturn [];\n\t\t}\n\t} catch {\n\t\t// AST parsers throw on malformed input; falling back to no folds keeps\n\t\t// the rest of the highlight pipeline alive.\n\t\treturn [];\n\t}\n}\n\nexport {\n\t//,\n\tcomputeServerFoldRanges,\n\tserverFoldNeedsTokens,\n\tserverFoldStrategyFor,\n};\nexport type { ServerFoldStrategy };\n","import { createHash } from \"node:crypto\";\nimport {\n\tdecorateHighlightedHtml,\n\tinferIndentation,\n\tisSupportedLanguage,\n\tnormalizeIndentation,\n\tparseLanguage,\n\ttype FoldLine,\n\ttype Indentation,\n\ttype LineRange,\n\ttype SupportedLanguage,\n} from \"@ngrok/mantle/highlight-utils\";\nimport { createLruCache } from \"./lru-cache.js\";\nimport {\n\tcomputeServerFoldRanges,\n\tserverFoldNeedsTokens,\n\tserverFoldStrategyFor,\n} from \"./server-fold-ranges.js\";\n\n/**\n * Shiki grammar IDs preloaded by Mantle's highlighting engine.\n * This list is shared by both Vite plugins and server-side highlighting routes.\n */\nconst mantleShikiLanguageGrammarIds = [\n\t\"bash\",\n\t\"csharp\",\n\t\"css\",\n\t\"go\",\n\t\"html\",\n\t\"java\",\n\t\"javascript\",\n\t\"json\",\n\t\"jsx\",\n\t\"python\",\n\t\"ruby\",\n\t\"rust\",\n\t\"shell\",\n\t\"tsx\",\n\t\"typescript\",\n\t\"xml\",\n\t\"yaml\",\n] as const satisfies SupportedLanguage[];\n\n/**\n * Shared Shiki theme name used across Mantle highlighting.\n */\nconst mantleShikiThemeName = \"mantle-css-variables\" as const;\nconst mantleHighlightCacheMaxEntries = 1000;\n\ntype ShikiHighlighter = Awaited<ReturnType<(typeof import(\"shiki\"))[\"createHighlighter\"]>>;\n\ntype MantleHighlightInput = {\n\t/**\n\t * Raw code string to highlight.\n\t */\n\tcode: string;\n\t/**\n\t * Language hint. Accepts supported language aliases and markdown-style values.\n\t */\n\tlanguage: SupportedLanguage | (string & {});\n\t/**\n\t * Optional indentation preference. Defaults to language-inferred indentation.\n\t */\n\tindentation?: Indentation;\n\t/**\n\t * Whether to render line numbers into the returned HTML.\n\t * @default true\n\t */\n\tshowLineNumbers?: boolean;\n\t/**\n\t * Optional list of highlighted line numbers/ranges to render into the returned HTML.\n\t * @default []\n\t */\n\thighlightLines?: (LineRange | number)[];\n\t/**\n\t * Start line number for rendered line numbers.\n\t * @default 1\n\t */\n\tlineNumberStart?: number;\n};\n\ntype MantleHighlightResult = {\n\t/**\n\t * Normalized source code used as the highlight input.\n\t */\n\tcode: string;\n\t/**\n\t * Highlighted HTML extracted from Shiki's `<code>...</code>`.\n\t */\n\thtml: string;\n\t/**\n\t * Resolved supported language used for highlighting.\n\t */\n\tlanguage: SupportedLanguage;\n\t/**\n\t * Whether returned HTML includes line numbers.\n\t */\n\tshowLineNumbers: boolean;\n\t/**\n\t * Highlighted line numbers/ranges applied to the returned HTML.\n\t */\n\thighlightLines: (LineRange | number)[];\n\t/**\n\t * Start line number used for rendered line numbers.\n\t */\n\tlineNumberStart: number;\n};\n\ntype MantleServerHighlighter = {\n\t/**\n\t * Highlight a code snippet and return normalized code + highlighted HTML.\n\t */\n\thighlight: (input: MantleHighlightInput) => Promise<MantleHighlightResult>;\n};\n\nlet highlighterPromise: Promise<ShikiHighlighter> | undefined;\nconst mantleHighlightCache = createLruCache<string, Promise<MantleHighlightResult>>(\n\tmantleHighlightCacheMaxEntries,\n);\n\n/**\n * Creates (and caches) Mantle's shared Shiki highlighter instance.\n */\nfunction getMantleShikiHighlighter(): Promise<ShikiHighlighter> {\n\tif (highlighterPromise != null) {\n\t\treturn highlighterPromise;\n\t}\n\n\thighlighterPromise = (async () => {\n\t\tconst { createCssVariablesTheme, createHighlighter } = await import(\"shiki\");\n\t\tconst cssVarsTheme = createCssVariablesTheme({ name: mantleShikiThemeName });\n\n\t\t// Append more granular token scope → CSS variable mappings.\n\t\t// More specific scopes override the defaults from createCssVariablesTheme.\n\t\t// Each uses a fallback to the original grouping variable for backwards compat.\n\t\tcssVarsTheme.tokenColors = [\n\t\t\t...(cssVarsTheme.tokenColors ?? []),\n\t\t\t{\n\t\t\t\tscope: [\"entity.name.type\", \"entity.name.class\", \"support.type\", \"support.class\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-type, var(--shiki-token-function))\" },\n\t\t\t},\n\t\t\t{\n\t\t\t\tscope: [\"variable\", \"variable.parameter\", \"variable.other\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-variable, var(--shiki-foreground))\" },\n\t\t\t},\n\t\t\t{\n\t\t\t\tscope: [\"keyword.operator\", \"keyword.operator.assignment\", \"keyword.operator.comparison\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-operator, var(--shiki-token-keyword))\" },\n\t\t\t},\n\t\t\t{\n\t\t\t\tscope: [\"entity.other.attribute-name\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-attribute, var(--shiki-token-constant))\" },\n\t\t\t},\n\t\t\t{\n\t\t\t\tscope: [\"meta.object-literal.key\", \"support.type.property-name\", \"entity.name.tag.yaml\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-property, var(--shiki-token-function))\" },\n\t\t\t},\n\t\t\t{\n\t\t\t\tscope: [\"constant.character.escape\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-escape, var(--shiki-token-constant))\" },\n\t\t\t},\n\t\t\t{\n\t\t\t\tscope: [\"string.unquoted.plain.out.yaml\", \"string.unquoted.plain.in.yaml\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-variable, var(--shiki-foreground))\" },\n\t\t\t},\n\t\t\t{\n\t\t\t\tscope: [\"punctuation.definition.block.sequence.item.yaml\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-variable, var(--shiki-foreground))\" },\n\t\t\t},\n\t\t];\n\n\t\treturn createHighlighter({\n\t\t\tthemes: [cssVarsTheme],\n\t\t\tlangs: [...mantleShikiLanguageGrammarIds],\n\t\t});\n\t})().catch((error) => {\n\t\thighlighterPromise = undefined;\n\t\tthrow error;\n\t});\n\n\treturn highlighterPromise;\n}\n\n/**\n * Extracts the inner HTML from a Shiki `<code>...</code>` wrapper.\n */\nfunction extractHighlightedCodeInnerHtml(fullHtml: string): string | undefined {\n\treturn fullHtml.match(/<code[^>]*>([\\s\\S]*?)<\\/code>/)?.[1];\n}\n\n/**\n * Highlights code with Mantle's shared Shiki engine and normalization defaults.\n */\nasync function highlightWithMantleShiki(\n\tinput: MantleHighlightInput,\n): Promise<MantleHighlightResult> {\n\tconst resolvedLanguage = isSupportedLanguage(input.language)\n\t\t? input.language\n\t\t: parseLanguage(input.language);\n\tconst indentation = input.indentation ?? inferIndentation(resolvedLanguage, undefined);\n\tconst normalizedCode = normalizeIndentation(input.code, {\n\t\tindentation,\n\t});\n\tconst showLineNumbers = input.showLineNumbers ?? true;\n\tconst highlightLines = input.highlightLines ?? [];\n\tconst lineNumberStart = input.lineNumberStart ?? 1;\n\tconst cacheKey = createHash(\"sha1\")\n\t\t.update(normalizedCode)\n\t\t.update(\n\t\t\t`\\0${resolvedLanguage}\\0${showLineNumbers}\\0${lineNumberStart}\\0${JSON.stringify(highlightLines)}`,\n\t\t)\n\t\t.digest(\"hex\");\n\tconst cached = mantleHighlightCache.get(cacheKey);\n\tif (cached != null) {\n\t\treturn cached;\n\t}\n\n\tconst promise = (async () => {\n\t\tconst highlighter = await getMantleShikiHighlighter();\n\t\t// AST and raw-source fold strategies don't need token explanations, so\n\t\t// we skip the `includeExplanation` cost on the JS/TS/HTML/CSS hot path.\n\t\t// Token-based strategies (Python, Ruby, Go, …) still pay for it.\n\t\tconst foldStrategy = serverFoldStrategyFor(resolvedLanguage);\n\t\tconst wantsTokens = serverFoldNeedsTokens(foldStrategy);\n\t\tlet capturedTokens: FoldLine[] | undefined;\n\t\tconst fullHtml = highlighter.codeToHtml(normalizedCode, {\n\t\t\tlang: resolvedLanguage,\n\t\t\ttheme: mantleShikiThemeName,\n\t\t\tincludeExplanation: wantsTokens ? \"scopeName\" : false,\n\t\t\ttransformers: wantsTokens\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"mantle:capture-tokens\",\n\t\t\t\t\t\t\ttokens(tokens) {\n\t\t\t\t\t\t\t\tcapturedTokens = tokens;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: undefined,\n\t\t});\n\t\tconst baseHtml = extractHighlightedCodeInnerHtml(fullHtml);\n\n\t\tif (baseHtml == null) {\n\t\t\tthrow new Error(\"Failed to extract highlighted HTML from Shiki output\");\n\t\t}\n\t\tconst foldableRanges =\n\t\t\tfoldStrategy === \"none\"\n\t\t\t\t? undefined\n\t\t\t\t: computeServerFoldRanges({\n\t\t\t\t\t\tcode: normalizedCode,\n\t\t\t\t\t\tlanguage: resolvedLanguage,\n\t\t\t\t\t\ttokens: capturedTokens,\n\t\t\t\t\t});\n\t\tconst html = decorateHighlightedHtml({\n\t\t\tfoldableRanges,\n\t\t\thighlightLines,\n\t\t\thtml: baseHtml,\n\t\t\tlineNumberStart,\n\t\t\tshowLineNumbers,\n\t\t});\n\n\t\treturn {\n\t\t\tcode: normalizedCode,\n\t\t\thtml,\n\t\t\tlanguage: resolvedLanguage,\n\t\t\tshowLineNumbers,\n\t\t\thighlightLines,\n\t\t\tlineNumberStart,\n\t\t};\n\t})().catch((error) => {\n\t\tmantleHighlightCache.delete(cacheKey);\n\t\tthrow error;\n\t});\n\n\tmantleHighlightCache.set(cacheKey, promise);\n\treturn promise;\n}\n\n/**\n * Creates a reusable Mantle server highlighter facade for API routes.\n */\nfunction createMantleServerSyntaxHighlighter(): MantleServerHighlighter {\n\treturn {\n\t\thighlight: highlightWithMantleShiki,\n\t};\n}\n\nexport {\n\tcreateMantleServerSyntaxHighlighter,\n\textractHighlightedCodeInnerHtml,\n\tgetMantleShikiHighlighter,\n\thighlightWithMantleShiki,\n\tmantleHighlightCacheMaxEntries,\n\tmantleShikiLanguageGrammarIds,\n\tmantleShikiThemeName,\n};\nexport type { MantleHighlightInput, MantleHighlightResult, MantleServerHighlighter };\n"],"mappings":";;;;;;;AASA,SAAS,eAAqB,YAAoC;CACjE,IAAI,CAAC,OAAO,UAAU,WAAW,IAAI,cAAc,GAClD,MAAM,IAAI,MAAM,mDAAmD;CAGpE,MAAM,sBAAM,IAAI,KAAW;CAE3B,OAAO;EACN,OAAO,KAAK;GACX,OAAO,IAAI,OAAO,IAAI;;EAEvB,IAAI,KAAK;GACR,IAAI,CAAC,IAAI,IAAI,IAAI,EAChB;GAGD,MAAM,QAAQ,IAAI,IAAI,IAAI;GAC1B,IAAI,OAAO,IAAI;GACf,IAAI,IAAI,KAAK,MAAM;GACnB,OAAO;;EAER,IAAI,KAAK,OAAO;GACf,IAAI,IAAI,IAAI,IAAI,EACf,IAAI,OAAO,IAAI;GAGhB,IAAI,IAAI,KAAK,MAAM;GACnB,IAAI,IAAI,QAAQ,YACf;GAGD,MAAM,YAAY,IAAI,MAAM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,UAAU,eAAe,GAChG,CACA,OAAO,MAAM;CACf,MAAM,SAAS,qBAAqB,IAAI,SAAS;CACjD,IAAI,UAAU,MACb,OAAO;CAGR,MAAM,WAAW,YAAY;EAC5B,MAAM,cAAc,MAAM,2BAA2B;EAIrD,MAAM,eAAe,sBAAsB,iBAAiB;EAC5D,MAAM,cAAc,sBAAsB,aAAa;EACvD,IAAI;EAgBJ,MAAM,WAAW,gCAfA,YAAY,WAAW,gBAAgB;GACvD,MAAM;GACN,OAAO;GACP,oBAAoB,cAAc,cAAc;GAChD,cAAc,cACX,CACA;IACC,MAAM;IACN,OAAO,QAAQ;KACd,iBAAiB;;IAElB,CACD,GACA;GACH,CACwD,CAAC;EAE1D,IAAI,YAAY,MACf,MAAM,IAAI,MAAM,uDAAuD;EAkBxE,OAAO;GACN,MAAM;GACN,MAVY,wBAAwB;IACpC,gBARA,iBAAiB,SACd,SACA,wBAAwB;KACxB,MAAM;KACN,UAAU;KACV,QAAQ;KACR,CAAC;IAGJ;IACA,MAAM;IACN;IACA;IACA,CAII;GACJ,UAAU;GACV;GACA;GACA;GACA;KACE,CAAC,OAAO,UAAU;EACrB,qBAAqB,OAAO,SAAS;EACrC,MAAM;GACL;CAEF,qBAAqB,IAAI,UAAU,QAAQ;CAC3C,OAAO;;;;;AAMR,SAAS,sCAA+D;CACvE,OAAO,EACN,WAAW,0BACX"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/lru-cache.ts","../src/compute-css-fold-ranges.ts","../src/compute-html-fold-ranges.ts","../src/line-offsets.ts","../src/compute-jsx-fold-ranges.ts","../src/compute-keyword-fold-ranges.ts","../src/server-fold-ranges.ts","../src/engine.ts"],"sourcesContent":["/** A simple least-recently-used cache backed by insertion-order `Map` semantics. */\ntype LruCache<K, V> = {\n\tdelete: (key: K) => boolean;\n\tget: (key: K) => V | undefined;\n\tset: (key: K, value: V) => void;\n\tsize: () => number;\n};\n\n/** Creates an LRU cache that evicts the least-recently-used entry when `maxEntries` is exceeded. */\nfunction createLruCache<K, V>(maxEntries: number): LruCache<K, V> {\n\tif (!Number.isInteger(maxEntries) || maxEntries <= 0) {\n\t\tthrow new Error(\"LRU cache maxEntries must be a positive integer.\");\n\t}\n\n\tconst map = new Map<K, V>();\n\n\treturn {\n\t\tdelete(key) {\n\t\t\treturn map.delete(key);\n\t\t},\n\t\tget(key) {\n\t\t\tif (!map.has(key)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst value = map.get(key) as V;\n\t\t\tmap.delete(key);\n\t\t\tmap.set(key, value);\n\t\t\treturn value;\n\t\t},\n\t\tset(key, value) {\n\t\t\tif (map.has(key)) {\n\t\t\t\tmap.delete(key);\n\t\t\t}\n\n\t\t\tmap.set(key, value);\n\t\t\tif (map.size <= maxEntries) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst oldestKey = map.keys().next().value as K | undefined;\n\t\t\tif (oldestKey != null) {\n\t\t\t\tmap.delete(oldestKey);\n\t\t\t}\n\t\t},\n\t\tsize() {\n\t\t\treturn map.size;\n\t\t},\n\t};\n}\n\nexport { createLruCache };\nexport type { LruCache };\n","import { finalizeFoldRanges, type FoldableRange } from \"@ngrok/mantle/highlight-utils\";\n\n/**\n * Raw-source fold computer for CSS — single-pass, parser-quality without a\n * parser dependency.\n *\n * Mirrors `computeJsonFoldRanges` but adds CSS-specific lexical features:\n *\n * - `/* … *​/` block comments are skipped wholesale.\n * - `\"…\"` and `'…'` string literals (including `\\\\` and `\\` escapes) are\n * skipped so braces inside `content: \"{ }\"` don't open folds.\n * - Backslash escapes outside of strings (CSS identifiers can use them) are\n * transparent — we just consume the next character.\n *\n * lightningcss is the project's preferred CSS parser, but its public visitor\n * API only surfaces *start* locations (`Location { line, column }`), not end\n * locations, which is what `FoldableRange.endLine` requires. Until upstream\n * exposes end spans we get the same correctness from a single-pass brace\n * matcher with a tiny CSS lexer — and skip the ~5MB native dep.\n *\n * @see https://github.com/parcel-bundler/lightningcss/issues/512\n */\n\n/**\n * Computes foldable ranges for a CSS source string. Each multi-line `{ … }`\n * (style rule, at-rule body, nested rule, keyframe selector) emits one range\n * with the opener and closer lines staying visible.\n *\n * Tolerant of malformed CSS — unmatched braces are dropped silently rather\n * than throwing, so a partial snippet still gets every fold it can. This\n * matches the behavior of `computeJsonFoldRanges` for JSON.\n *\n * @example\n * computeCssFoldRanges({ code: \".a {\\n color: red;\\n}\" });\n * // => [{ id: \"1\", startLine: 1, endLine: 3 }]\n */\nfunction computeCssFoldRanges({\n\tcode,\n}: {\n\t/** Raw CSS source code to scan. */\n\tcode: string;\n}): FoldableRange[] {\n\tconst length = code.length;\n\tif (length === 0) {\n\t\treturn [];\n\t}\n\n\tconst stack: number[] = [];\n\tconst ranges: FoldableRange[] = [];\n\n\tlet line = 1;\n\tlet index = 0;\n\n\twhile (index < length) {\n\t\tconst character = code.charCodeAt(index);\n\n\t\tif (character === 10) {\n\t\t\tline += 1;\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === 13) {\n\t\t\tline += 1;\n\t\t\tindex += 1;\n\t\t\tif (index < length && code.charCodeAt(index) === 10) {\n\t\t\t\tindex += 1;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\t// `/* … */` block comment — CSS has no line comments in standard CSS.\n\t\tif (character === 47 && index + 1 < length && code.charCodeAt(index + 1) === 42) {\n\t\t\tindex += 2;\n\t\t\twhile (index < length) {\n\t\t\t\tconst commentChar = code.charCodeAt(index);\n\t\t\t\tif (commentChar === 10) {\n\t\t\t\t\tline += 1;\n\t\t\t\t\tindex += 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (commentChar === 13) {\n\t\t\t\t\tline += 1;\n\t\t\t\t\tindex += 1;\n\t\t\t\t\tif (index < length && code.charCodeAt(index) === 10) {\n\t\t\t\t\t\tindex += 1;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (commentChar === 42 && index + 1 < length && code.charCodeAt(index + 1) === 47) {\n\t\t\t\t\tindex += 2;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tindex += 1;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\t// `\"…\"` or `'…'` string literal. CSS allows escaped newlines (`\\` followed\n\t\t// by a newline) which continue the string; treat any backslash as\n\t\t// \"skip the next char\" without bumping the line counter past it.\n\t\tif (character === 34 || character === 39) {\n\t\t\tconst quote = character;\n\t\t\tindex += 1;\n\t\t\twhile (index < length) {\n\t\t\t\tconst stringChar = code.charCodeAt(index);\n\t\t\t\tif (stringChar === 92) {\n\t\t\t\t\tindex += 1;\n\t\t\t\t\tif (index >= length) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst escaped = code.charCodeAt(index);\n\t\t\t\t\tif (escaped === 10) {\n\t\t\t\t\t\tline += 1;\n\t\t\t\t\t} else if (escaped === 13) {\n\t\t\t\t\t\tline += 1;\n\t\t\t\t\t\tif (index + 1 < length && code.charCodeAt(index + 1) === 10) {\n\t\t\t\t\t\t\tindex += 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tindex += 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (stringChar === quote) {\n\t\t\t\t\tindex += 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (stringChar === 10) {\n\t\t\t\t\t// CSS strings normally can't span unescaped newlines; bail to\n\t\t\t\t\t// avoid swallowing the rest of the file when the quote is\n\t\t\t\t\t// stranded.\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tindex += 1;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (character === 123) {\n\t\t\tstack.push(line);\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (character === 125) {\n\t\t\tconst startLine = stack.pop();\n\t\t\tif (startLine != null && startLine !== line) {\n\t\t\t\tranges.push({ id: String(startLine), startLine, endLine: line });\n\t\t\t}\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tindex += 1;\n\t}\n\n\treturn finalizeFoldRanges(ranges);\n}\n\nexport { computeCssFoldRanges };\n","import { finalizeFoldRanges, type FoldableRange } from \"@ngrok/mantle/highlight-utils\";\nimport { html, parse, parseFragment } from \"parse5\";\nimport type { DefaultTreeAdapterMap } from \"parse5\";\n\n/**\n * AST-based fold computer for HTML and XML.\n *\n * Uses `parse5` with `sourceCodeLocationInfo: true` so each element node carries\n * the line numbers of its open and close tags. Walking the tree gives us:\n *\n * - One fold per multi-line element (`<div>…</div>`).\n * - One fold per multi-line opening tag (`<div\\n class=\"x\"\\n>` — the\n * attribute list collapses).\n * - Correct void-element handling — parse5 already knows that `<br>`, `<img>`,\n * etc. don't open folds.\n * - Template content traversal — parse5 stores `<template>` descendants on a\n * separate `content` fragment, not on `childNodes`.\n * - String/comment scope filtering — angle brackets in `<!-- … -->` or\n * inside `\"…\"` attribute values aren't mistaken for tag openings.\n *\n * @see https://parse5.js.org/\n */\n\ntype HtmlFoldLanguage = \"html\" | \"xml\";\n\ntype Element = DefaultTreeAdapterMap[\"element\"];\ntype Node = DefaultTreeAdapterMap[\"node\"];\n\n/**\n * SVG-namespace URI used as a fragment context when parsing XML.\n *\n * In SVG context, `parse5` switches its tokenizer into \"foreign content\"\n * mode, which is much closer to XML semantics:\n *\n * - Self-closing `<foo/>` is honored.\n * - Element names are case-preserved.\n * - HTML-only void elements (`<br>`, `<img>`) are not auto-closed.\n *\n * That makes it acceptable as a stand-in XML parser for code blocks. The\n * caveat is that a few SVG-recognized names (`<title>`, `<desc>`, `<script>`,\n * `<style>`, `<foreignObject>`) revert to HTML rules inside their bodies; in\n * practice that's rare in user XML and yields conservative folding (still\n * correct, just sometimes more flat than VS Code's XML folder).\n */\nconst SVG_NAMESPACE = html.NS.SVG;\n\n/**\n * Synthetic SVG fragment context shared across XML parses. Only the namespace\n * matters for the foreign-content tokenizer mode; the rest of the fields\n * satisfy parse5's tree-adapter shape.\n */\nconst xmlFragmentContext = {\n\tnodeName: \"svg\",\n\ttagName: \"svg\",\n\tnamespaceURI: SVG_NAMESPACE,\n\tattrs: [],\n\tchildNodes: [],\n\tparentNode: null,\n} as unknown as DefaultTreeAdapterMap[\"parentNode\"];\n\n/**\n * Returns true when a parse5 tree node has element-style `tagName` and child\n * nodes — i.e. it's an `Element` we should consider folding. Comments,\n * doctypes, text nodes, and the document root all fail this check.\n */\nfunction isElement(node: Node): node is Element {\n\treturn (\n\t\t\"tagName\" in node &&\n\t\ttypeof (node as { tagName?: unknown }).tagName === \"string\" &&\n\t\t\"childNodes\" in node\n\t);\n}\n\n/**\n * Traverses `root` depth-first and pushes a {@link FoldableRange} for every\n * element whose source span covers more than one line.\n *\n * Multi-line *elements* fold from the opening tag's start line to the closing\n * tag's end line (or to the element end when `endTag` info is unavailable —\n * parse5 sometimes synthesizes elements without a real closer when handling\n * malformed input).\n *\n * Multi-line *opening tags* (e.g. `<div\\n class=\"x\">`) fold from the start\n * of the tag to its `>` so the attribute list collapses into the tag name.\n * VS Code emits this as a separate \"tag\" fold marker; we mirror that.\n */\nfunction collectRanges(root: Node, ranges: FoldableRange[]): void {\n\tconst stack: Node[] = [root];\n\twhile (stack.length > 0) {\n\t\tconst node = stack.pop();\n\t\tif (node == null) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (isElement(node)) {\n\t\t\tpushRangesForElement(node, ranges);\n\t\t}\n\t\tpushChildNodes(node, stack);\n\n\t\t// parse5 models `<template>` descendants inside `node.content`, a\n\t\t// DocumentFragment, while `node.childNodes` stays empty. Include that\n\t\t// fragment so nested HTML in templates gets the same folds as normal\n\t\t// element children without recursing or re-walking the tree.\n\t\tif (\"content\" in node && typeof node.content === \"object\" && node.content != null) {\n\t\t\tpushChildNodes(node.content, stack);\n\t\t}\n\t}\n}\n\n/** Pushes parse5 child nodes onto the DFS stack in source order. */\nfunction pushChildNodes(parent: unknown, stack: Node[]): void {\n\tif (typeof parent !== \"object\" || parent == null || !(\"childNodes\" in parent)) {\n\t\treturn;\n\t}\n\tconst childNodes = parent.childNodes;\n\tif (!Array.isArray(childNodes)) {\n\t\treturn;\n\t}\n\tfor (let index = childNodes.length - 1; index >= 0; index -= 1) {\n\t\tconst child = childNodes[index];\n\t\tif (child != null) {\n\t\t\tstack.push(child as Node);\n\t\t}\n\t}\n}\n\n/**\n * Emits up to two fold ranges for a single element: one for the element's\n * full body and one for its multi-line opening tag.\n */\nfunction pushRangesForElement(element: Element, ranges: FoldableRange[]): void {\n\tconst location = element.sourceCodeLocation;\n\tif (location == null) {\n\t\t// Implicit/synthetic elements (e.g. `<html>`/`<body>` parse5 fabricates\n\t\t// for fragment input) don't appear in the source. Skip them so we\n\t\t// don't emit folds without a real opener.\n\t\treturn;\n\t}\n\n\tconst startTag = location.startTag;\n\tconst endTag = location.endTag;\n\n\t// The element is a self-closing or void tag (no close tag in the source).\n\t// `<br>` HTML void elements and `<foo/>` XML self-closing tags both land\n\t// here; neither opens a fold.\n\tif (endTag == null) {\n\t\t// A multi-line single-tag element (`<input\\n type=\"text\"\\n/>`) still\n\t\t// gets the attribute-list fold below.\n\t\tpushTagFoldIfMultiline(startTag, ranges);\n\t\treturn;\n\t}\n\n\tconst startLine = location.startLine;\n\tconst endLine = location.endLine;\n\tif (endLine > startLine) {\n\t\tranges.push({ id: String(startLine), startLine, endLine });\n\t}\n\tpushTagFoldIfMultiline(startTag, ranges);\n}\n\n/**\n * Pushes a fold range for an opening tag (`startTag`) when its `<` and `>`\n * sit on different lines. Conservative: contributes nothing for single-line\n * tags so we don't fight `pushRangesForElement` for the same opener.\n */\nfunction pushTagFoldIfMultiline(\n\tstartTag: { startLine: number; endLine: number } | undefined,\n\tranges: FoldableRange[],\n): void {\n\tif (startTag == null) {\n\t\treturn;\n\t}\n\tif (startTag.endLine > startTag.startLine) {\n\t\tranges.push({\n\t\t\tid: String(startTag.startLine),\n\t\t\tstartLine: startTag.startLine,\n\t\t\tendLine: startTag.endLine,\n\t\t});\n\t}\n}\n\n/**\n * Computes foldable ranges for an HTML or XML source string.\n *\n * - HTML: uses `parse5.parse` so explicit `<html>`/`<head>`/`<body>` are\n * honored as foldable openers. Implicit wrappers parse5 fabricates for\n * fragment input have no `sourceCodeLocation` and are skipped.\n * - XML: uses `parse5.parseFragment` rooted in an SVG fragment context so the\n * tokenizer applies foreign-content (XML-like) rules — self-closing `<foo/>`\n * is respected, void HTML elements aren't special-cased.\n *\n * @example\n * computeHtmlFoldRanges({ code: \"<div>\\n <p>hi</p>\\n</div>\", language: \"html\" });\n * // => [{ id: \"1\", startLine: 1, endLine: 3 }]\n */\nfunction computeHtmlFoldRanges({\n\tcode,\n\tlanguage,\n}: {\n\t/** Raw source code to parse. */\n\tcode: string;\n\t/** Resolved Mantle language; selects HTML vs. XML parsing rules. */\n\tlanguage: HtmlFoldLanguage;\n}): FoldableRange[] {\n\tif (code.length === 0) {\n\t\treturn [];\n\t}\n\n\tconst document =\n\t\tlanguage === \"xml\"\n\t\t\t? parseFragment(xmlFragmentContext, code, { sourceCodeLocationInfo: true })\n\t\t\t: parse(code, { sourceCodeLocationInfo: true });\n\n\tconst ranges: FoldableRange[] = [];\n\tcollectRanges(document, ranges);\n\treturn finalizeFoldRanges(ranges);\n}\n\nexport { computeHtmlFoldRanges };\nexport type { HtmlFoldLanguage };\n","/**\n * Helpers for converting parser byte offsets into 1-indexed line numbers.\n *\n * Every AST-based fold strategy in this package speaks line numbers (because\n * `FoldableRange.startLine` / `endLine` are line-anchored), but parsers like\n * `oxc-parser` and `postcss` report offsets / line+col tuples derived from\n * byte positions. Building a single sorted `lineOffsets` array up front keeps\n * the per-node lookup `O(log n)` instead of rescanning the source each call.\n */\n\n/**\n * Returns an array where index `i` holds the byte offset of the start of\n * the `i + 1`-th line of `source`. The first entry is always `0`.\n *\n * Treats `\\n`, `\\r\\n`, and bare `\\r` as line breaks so it agrees with how\n * Shiki, oxc, parse5, and postcss split lines (they all match the JS\n * runtime's `String.prototype.split(/\\r\\n|\\r|\\n/)` behavior in practice).\n */\nfunction buildLineOffsets(source: string): number[] {\n\tconst offsets: number[] = [0];\n\tconst length = source.length;\n\tfor (let index = 0; index < length; index += 1) {\n\t\tconst character = source.charCodeAt(index);\n\t\tif (character === 10) {\n\t\t\toffsets.push(index + 1);\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === 13) {\n\t\t\t// `\\r\\n` and bare `\\r` both start a new line at index + 1 (or + 2 when\n\t\t\t// followed by `\\n`); skip the `\\n` to avoid pushing a duplicate offset.\n\t\t\tconst isCrLf = index + 1 < length && source.charCodeAt(index + 1) === 10;\n\t\t\toffsets.push(isCrLf ? index + 2 : index + 1);\n\t\t\tif (isCrLf) {\n\t\t\t\tindex += 1;\n\t\t\t}\n\t\t}\n\t}\n\treturn offsets;\n}\n\n/**\n * Returns the 1-indexed line number that contains `offset` in the source\n * scanned by {@link buildLineOffsets}. Out-of-range offsets clamp to the\n * first or last line.\n */\nfunction offsetToLine(lineOffsets: readonly number[], offset: number): number {\n\tif (lineOffsets.length === 0) {\n\t\treturn 1;\n\t}\n\tif (offset <= 0) {\n\t\treturn 1;\n\t}\n\tlet low = 0;\n\tlet high = lineOffsets.length - 1;\n\twhile (low < high) {\n\t\t// Bias the midpoint toward `high` so the loop terminates when\n\t\t// `lineOffsets[mid] <= offset` repeatedly succeeds with `low === mid`.\n\t\tconst mid = (low + high + 1) >>> 1;\n\t\tconst start = lineOffsets[mid] ?? 0;\n\t\tif (start <= offset) {\n\t\t\tlow = mid;\n\t\t} else {\n\t\t\thigh = mid - 1;\n\t\t}\n\t}\n\treturn low + 1;\n}\n\nexport { buildLineOffsets, offsetToLine };\n","import { finalizeFoldRanges, type FoldableRange } from \"@ngrok/mantle/highlight-utils\";\nimport { createRequire } from \"node:module\";\nimport type * as OxcParserModule from \"oxc-parser\";\nimport type { ParserOptions } from \"oxc-parser\";\nimport { buildLineOffsets, offsetToLine } from \"./line-offsets.js\";\n\n/**\n * Loads `oxc-parser` lazily on first use. Eager `import` of oxc-parser runs\n * its napi-rs bootstrap (`bindings.js`), which `throw`s synchronously when the\n * platform-specific native binding (`@oxc-parser/binding-*`) isn't resolvable\n * — common on serverless hosts that ship the bundled JS without the binding\n * package alongside it. A throw at module-eval time would propagate through\n * the entire server bundle's import graph and 500 every route, not just\n * JSX/TSX folding. Deferring the load until folding runs lets this strategy\n * convert the failure into a cached \"no folds\" fallback while keeping every\n * other strategy working.\n */\ntype OxcParser = typeof OxcParserModule;\nconst requireOxc = createRequire(import.meta.url);\n\n/** Creates a memoized parser loader that caches both success and load failure. */\nfunction createOxcParserLoader(load: () => OxcParser): () => OxcParser | undefined {\n\tlet cachedOxcParser: OxcParser | undefined;\n\tlet didFailToLoadOxcParser = false;\n\n\treturn () => {\n\t\tif (cachedOxcParser != null) {\n\t\t\treturn cachedOxcParser;\n\t\t}\n\t\tif (didFailToLoadOxcParser) {\n\t\t\treturn undefined;\n\t\t}\n\t\tlet oxcParser: OxcParser;\n\t\ttry {\n\t\t\toxcParser = load();\n\t\t} catch {\n\t\t\tdidFailToLoadOxcParser = true;\n\t\t\treturn undefined;\n\t\t}\n\t\tcachedOxcParser = oxcParser;\n\t\treturn oxcParser;\n\t};\n}\n\n/** Returns the lazily-resolved `oxc-parser` module, or undefined after a cached load failure. */\nconst loadOxcParser = createOxcParserLoader(() => requireOxc(\"oxc-parser\") as OxcParser);\n\n/**\n * AST-based fold computer for the JS/TS/JSX/TSX language family.\n *\n * Mirrors VS Code's TypeScript language service folder by walking the parsed\n * AST instead of pairing brackets in the token stream. This lets us fold\n * constructs that bracket-pairing can't see:\n *\n * - JSX elements (`<Foo>…</Foo>`, fragments, members like `<obj.Foo>`).\n * - Template literals that span multiple lines (including tagged templates).\n *\n * It also keeps every fold the bracket strategy used to give us — block\n * statements, object literals, array literals, class/interface bodies, switch\n * statements — without the per-character scope-walk cost.\n *\n * @see https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/languageFeatures/folding.ts\n */\n\n/** Subset of supported languages handled by this computer. */\ntype JsxFoldLanguage = \"javascript\" | \"js\" | \"typescript\" | \"ts\" | \"jsx\" | \"tsx\";\n\n/**\n * Maps a Mantle language to the oxc-parser `lang` option. JavaScript keeps\n * JSX enabled so JSX-in-JS examples still fold, but TypeScript must stay in\n * plain `ts` mode: TSX parses generic arrow functions (`<T>(x: T) => ...`) as\n * JSX and drops the AST folds for otherwise-valid TypeScript snippets.\n */\nfunction oxcLangFor(language: JsxFoldLanguage): \"jsx\" | \"ts\" | \"tsx\" {\n\tswitch (language) {\n\t\tcase \"tsx\":\n\t\t\treturn \"tsx\";\n\t\tcase \"typescript\":\n\t\tcase \"ts\":\n\t\t\treturn \"ts\";\n\t\tcase \"jsx\":\n\t\tcase \"javascript\":\n\t\tcase \"js\":\n\t\t\treturn \"jsx\";\n\t}\n}\n\n/** Minimal AST node shape — every oxc node carries `type`, `start`, `end`. */\ntype AstNode = {\n\ttype: string;\n\tstart: number;\n\tend: number;\n\t[key: string]: unknown;\n};\n\n/** Type guard for an arbitrary value being an AST node. */\nfunction isAstNode(value: unknown): value is AstNode {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue != null &&\n\t\t\"type\" in value &&\n\t\ttypeof (value as { type?: unknown }).type === \"string\" &&\n\t\t\"start\" in value &&\n\t\ttypeof (value as { start?: unknown }).start === \"number\" &&\n\t\t\"end\" in value &&\n\t\ttypeof (value as { end?: unknown }).end === \"number\"\n\t);\n}\n\n/**\n * AST node types whose `start`/`end` positions delimit a foldable region\n * when they span multiple lines.\n *\n * Curated to match VS Code's TypeScript folder:\n * - Block-like statement bodies — covers function/method bodies, class bodies,\n * `if`/`for`/`while` blocks, modules, namespaces.\n * - Object & array literals — covers JSON-shaped data and JSX style props.\n * - JSX elements & fragments — open/close tags fold like HTML.\n * - Template literals — fold multi-line backtick strings (including tagged).\n * - Switch statements — VS Code folds the whole `switch (…) { … }`, not each case.\n */\nconst FOLDABLE_NODE_TYPES = new Set<string>([\n\t\"BlockStatement\",\n\t\"ClassBody\",\n\t\"ObjectExpression\",\n\t\"ObjectPattern\",\n\t\"ArrayExpression\",\n\t\"ArrayPattern\",\n\t\"JSXElement\",\n\t\"JSXFragment\",\n\t\"TemplateLiteral\",\n\t\"SwitchStatement\",\n\t// TypeScript-only:\n\t\"TSInterfaceBody\",\n\t\"TSTypeLiteral\",\n\t\"TSEnumBody\",\n\t\"TSEnumDeclaration\",\n\t\"TSModuleBlock\",\n\t\"TSMappedType\",\n]);\n\n/** Returns the `openingElement` of a `JSXElement` if present (the `<Foo …>` span). */\nfunction jsxOpeningElement(node: AstNode): AstNode | undefined {\n\tif (node.type !== \"JSXElement\") {\n\t\treturn undefined;\n\t}\n\tconst opening = (node as { openingElement?: unknown }).openingElement;\n\treturn isAstNode(opening) ? opening : undefined;\n}\n\n/** Returns true when a `JSXOpeningElement` is self-closing (`<Foo/>`). */\nfunction isSelfClosingOpening(opening: AstNode): boolean {\n\tconst selfClosing = (opening as { selfClosing?: unknown }).selfClosing;\n\treturn selfClosing === true;\n}\n\n/**\n * Recursively walks every AST node reachable from `root`, calling `visit`\n * with each one. Mirrors the helper used in the Vite plugin but stays local\n * so this module has no extra cross-package dependency.\n */\nfunction walk(root: unknown, visit: (node: AstNode) => void): void {\n\tif (Array.isArray(root)) {\n\t\tfor (const item of root) {\n\t\t\twalk(item, visit);\n\t\t}\n\t\treturn;\n\t}\n\tif (!isAstNode(root)) {\n\t\treturn;\n\t}\n\tvisit(root);\n\tfor (const value of Object.values(root)) {\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (const item of value) {\n\t\t\t\twalk(item, visit);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (isAstNode(value)) {\n\t\t\twalk(value, visit);\n\t\t}\n\t}\n}\n\n/**\n * Filename passed to `oxc-parser` purely for diagnostic strings; the actual\n * grammar comes from the `lang` option on the parser options object.\n */\nconst SYNTHETIC_FILENAME = \"__mantle_fold__\";\n\n/**\n * Pushes a {@link FoldableRange} for the source span `[startOffset, endOffset]`\n * (inclusive) when it crosses a line boundary. Single-line spans contribute\n * nothing — there's nothing to fold.\n */\nfunction pushRange(\n\tranges: FoldableRange[],\n\tlineOffsets: readonly number[],\n\tstartOffset: number,\n\tendOffset: number,\n): void {\n\tconst startLine = offsetToLine(lineOffsets, startOffset);\n\tconst endLine = offsetToLine(lineOffsets, endOffset);\n\tif (endLine > startLine) {\n\t\tranges.push({ id: String(startLine), startLine, endLine });\n\t}\n}\n\n/**\n * Computes foldable ranges for a JS/TS/JSX/TSX source string by parsing it\n * with `oxc-parser` and walking the AST. Errors are tolerated — a partial AST\n * still produces useful folds.\n *\n * @example\n * computeJsxFoldRanges({ code: \"<Foo>\\n <Bar/>\\n</Foo>\", language: \"tsx\" });\n * // => [{ id: \"1\", startLine: 1, endLine: 3 }]\n */\nfunction computeJsxFoldRanges({\n\tcode,\n\tlanguage,\n}: {\n\t/** Raw source code to parse and fold. */\n\tcode: string;\n\t/** Resolved Mantle language; controls grammar selection (TS vs JS, JSX vs plain). */\n\tlanguage: JsxFoldLanguage;\n}): FoldableRange[] {\n\tif (code.length === 0) {\n\t\treturn [];\n\t}\n\n\tconst options: ParserOptions = {\n\t\t// `unambiguous` lets the parser accept both `script` and `module` code,\n\t\t// matching how a code block is rendered without `import`/`export` context.\n\t\tsourceType: \"unambiguous\",\n\t\tlang: oxcLangFor(language),\n\t};\n\tconst oxcParser = loadOxcParser();\n\tif (oxcParser == null) {\n\t\treturn [];\n\t}\n\tconst { parseSync } = oxcParser;\n\tconst parsed = parseSync(SYNTHETIC_FILENAME, code, options);\n\tconst lineOffsets = buildLineOffsets(code);\n\tconst ranges: FoldableRange[] = [];\n\n\twalk(parsed.program, (node) => {\n\t\t// JSX elements get split treatment so multi-line attribute lists fold\n\t\t// even on self-closing tags (which have no separate body to fold).\n\t\tif (node.type === \"JSXElement\") {\n\t\t\tconst opening = jsxOpeningElement(node);\n\t\t\tconst isSelfClosing = opening != null && isSelfClosingOpening(opening);\n\t\t\tif (isSelfClosing) {\n\t\t\t\t// Self-closing tags fold the open-tag span only — there's no\n\t\t\t\t// body. Diverges from VS Code's stock TS folder, which doesn't\n\t\t\t\t// fold these at all, but matches what JSX authors actually want\n\t\t\t\t// for long attribute lists across multiple lines.\n\t\t\t\tif (opening != null) {\n\t\t\t\t\tpushRange(ranges, lineOffsets, opening.start, opening.end - 1);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Non-self-closing: fold the whole element AND any multi-line\n\t\t\t// opening tag's attribute list. After dedup, when both share an\n\t\t\t// opener line, the larger element fold wins — but the open-tag\n\t\t\t// fold survives when it has its own opener line offset.\n\t\t\tpushRange(ranges, lineOffsets, node.start, node.end - 1);\n\t\t\tif (opening != null) {\n\t\t\t\tpushRange(ranges, lineOffsets, opening.start, opening.end - 1);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (!FOLDABLE_NODE_TYPES.has(node.type)) {\n\t\t\treturn;\n\t\t}\n\t\tpushRange(ranges, lineOffsets, node.start, node.end - 1);\n\t});\n\n\treturn finalizeFoldRanges(ranges);\n}\n\nexport { computeJsxFoldRanges, createOxcParserLoader };\nexport type { JsxFoldLanguage };\n","import {\n\tfinalizeFoldRanges,\n\ttype FoldableRange,\n\ttype FoldLine,\n} from \"@ngrok/mantle/highlight-utils\";\n\n/**\n * Keyword-pair fold computer for languages whose blocks are delimited by\n * keywords rather than punctuation.\n *\n * VS Code models this with `foldingStartMarker` / `foldingStopMarker`\n * declarations in each language's `language-configuration.json`. We mirror\n * that behavior with linear marker predicates, evaluated against the\n * *visible* (non-string, non-comment) portion of each line — the Shiki tokens\n * carry scope information that lets us strip those out reliably.\n *\n * The stack is untyped — every closer pops the most recent opener, regardless\n * of which keyword opened it. Real source code nests properly, so this stays\n * correct without per-keyword tracking, and matches VS Code's marker-based\n * behavior.\n *\n * @see https://github.com/microsoft/vscode/blob/main/extensions/ruby/language-configuration.json\n * @see https://github.com/microsoft/vscode/blob/main/extensions/shellscript/language-configuration.json\n */\n\n/** Languages this computer knows how to fold. */\ntype KeywordFoldLanguage = \"ruby\" | \"rb\" | \"bash\" | \"sh\" | \"shell\";\n\n/**\n * Per-line opener/closer marker pair. The predicates intentionally match the\n * *visible* line content (after string and comment scopes are filtered out)\n * — interpolated `do … end` markers inside a string don't trigger folds.\n */\ntype KeywordPattern = {\n\t/** Returns true when this line opens a foldable block. */\n\tstartsFold: (visible: string) => boolean;\n\t/** Returns true when this line closes a foldable block. */\n\tendsFold: (visible: string) => boolean;\n};\n\nconst RUBY_START_KEYWORDS: readonly string[] = [\n\t\"def\",\n\t\"class\",\n\t\"module\",\n\t\"begin\",\n\t\"if\",\n\t\"unless\",\n\t\"while\",\n\t\"until\",\n\t\"for\",\n\t\"case\",\n];\nconst BASH_START_KEYWORDS: readonly string[] = [\"if\", \"while\", \"for\", \"case\", \"until\", \"select\"];\nconst BASH_END_KEYWORDS: readonly string[] = [\"fi\", \"esac\", \"done\"];\n\n/**\n * Ruby keyword folds modeled after VS Code's grammar. Covers:\n *\n * - Definition keywords at the start of a line: `def`, `class`, `module`, `begin`.\n * - Control-flow openers at the start of a line: `if`, `unless`, `while`,\n * `until`, `for`, `case` — Ruby's flagship multi-line constructs.\n * - Trailing `do` / `do |args|` for blocks attached to a method call.\n *\n * `end` always closes; mid-block keywords (`else`, `elsif`, `when`, `rescue`,\n * `ensure`) deliberately don't, so a single `if … else … end` becomes one\n * fold, not three.\n */\nconst RUBY_PATTERN: KeywordPattern = {\n\tstartsFold: rubyStartsFold,\n\tendsFold: (visible) => startsWithAnyWordAfterWhitespace(visible, [\"end\"]),\n};\n\n/**\n * Bash / Shell keyword folds modeled after VS Code's grammar.\n *\n * - Opener keywords at the start of a line — `if`, `while`, `for`, `case`,\n * `until`, `select` — that aren't closed by a same-line command marker.\n * - Lines ending with an unmatched `{` (function bodies, brace groups).\n * - Lines ending with `do` (the `for x in y; do` / `while cond; do` form).\n *\n * The end predicate matches `}` only when it leads its line — that lets us\n * close brace groups while ignoring `${VAR}` parameter expansions, which\n * are never line-leading.\n */\nconst BASH_PATTERN: KeywordPattern = {\n\tstartsFold: bashStartsFold,\n\tendsFold: bashEndsFold,\n};\n\n/** Returns true for ASCII identifier characters used by shell/Ruby keywords. */\nfunction isWordChar(character: number): boolean {\n\treturn (\n\t\t(character >= 48 && character <= 57) ||\n\t\t(character >= 65 && character <= 90) ||\n\t\t(character >= 97 && character <= 122) ||\n\t\tcharacter === 95\n\t);\n}\n\n/** Returns true for whitespace characters accepted around language markers. */\nfunction isWhitespaceChar(character: number): boolean {\n\treturn (\n\t\tcharacter === 9 ||\n\t\tcharacter === 10 ||\n\t\tcharacter === 11 ||\n\t\tcharacter === 12 ||\n\t\tcharacter === 13 ||\n\t\tcharacter === 32\n\t);\n}\n\n/** Returns the index of the first non-whitespace character in `text`. */\nfunction firstNonWhitespaceIndex(text: string): number {\n\tlet index = 0;\n\twhile (index < text.length && isWhitespaceChar(text.charCodeAt(index))) {\n\t\tindex += 1;\n\t}\n\treturn index;\n}\n\n/** Returns the exclusive index after the last non-whitespace character. */\nfunction endTrimmedIndex(text: string): number {\n\tlet index = text.length;\n\twhile (index > 0 && isWhitespaceChar(text.charCodeAt(index - 1))) {\n\t\tindex -= 1;\n\t}\n\treturn index;\n}\n\n/** Returns true if `word` appears at `index` with word boundaries. */\nfunction isWordAt(text: string, index: number, word: string, end = text.length): boolean {\n\tif (index < 0 || index + word.length > end) {\n\t\treturn false;\n\t}\n\tif (text.slice(index, index + word.length) !== word) {\n\t\treturn false;\n\t}\n\tconst beforeIsBoundary = index === 0 || !isWordChar(text.charCodeAt(index - 1));\n\tconst afterIndex = index + word.length;\n\tconst afterIsBoundary = afterIndex >= end || !isWordChar(text.charCodeAt(afterIndex));\n\treturn beforeIsBoundary && afterIsBoundary;\n}\n\n/** Returns true when a line begins with one of the given keywords. */\nfunction startsWithAnyWordAfterWhitespace(text: string, words: readonly string[]): boolean {\n\tconst index = firstNonWhitespaceIndex(text);\n\tfor (const word of words) {\n\t\tif (isWordAt(text, index, word)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Returns true when `index` is positioned where the shell can begin another\n * command word on the same physical line. This intentionally ignores ordinary\n * arguments and variables like `$done`, so `case $done in` still opens a fold.\n */\nfunction isShellCommandBoundary(text: string, index: number): boolean {\n\tlet cursor = index - 1;\n\twhile (cursor >= 0 && isWhitespaceChar(text.charCodeAt(cursor))) {\n\t\tcursor -= 1;\n\t}\n\tif (cursor < 0) {\n\t\treturn true;\n\t}\n\tconst previous = text.charCodeAt(cursor);\n\treturn previous === 38 || previous === 40 || previous === 59 || previous === 124;\n}\n\n/**\n * Returns true when a Bash closer appears as a same-line command marker, e.g.\n * `if ok; then echo hi; fi`. A single linear scan is cheaper than running one\n * regex per marker and keeps shell variables / arguments named `done`, `fi`,\n * or `esac` from suppressing valid opener folds.\n */\nfunction hasShellSameLineEndKeyword(text: string): boolean {\n\tfor (let index = 0; index < text.length; index += 1) {\n\t\tconst character = text.charCodeAt(index);\n\t\tif (!isWordChar(character)) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const word of BASH_END_KEYWORDS) {\n\t\t\tif (isWordAt(text, index, word) && isShellCommandBoundary(text, index)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\twhile (index + 1 < text.length && isWordChar(text.charCodeAt(index + 1))) {\n\t\t\tindex += 1;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Returns true when a line starts with a shell closer command. `done)` and\n * similar case labels are deliberately excluded; `)` is not a command\n * separator, so those labels should not pop the fold stack.\n */\nfunction startsWithShellEndKeyword(text: string): boolean {\n\tconst index = firstNonWhitespaceIndex(text);\n\tfor (const word of BASH_END_KEYWORDS) {\n\t\tif (!isWordAt(text, index, word)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst next = text.charCodeAt(index + word.length);\n\t\treturn (\n\t\t\tNumber.isNaN(next) || isWhitespaceChar(next) || next === 38 || next === 59 || next === 124\n\t\t);\n\t}\n\treturn false;\n}\n\n/** Returns true when a line ends with `word`, ignoring trailing whitespace. */\nfunction endsWithWord(text: string, word: string): boolean {\n\tconst end = endTrimmedIndex(text);\n\treturn isWordAt(text, end - word.length, word, end);\n}\n\n/** Returns true for trailing Ruby `do` / `do |args|` block openers. */\nfunction endsWithRubyDoBlock(text: string): boolean {\n\tlet end = endTrimmedIndex(text);\n\tif (end <= 0) {\n\t\treturn false;\n\t}\n\tif (text.charCodeAt(end - 1) === 124) {\n\t\tconst paramsStart = text.lastIndexOf(\"|\", end - 2);\n\t\tif (paramsStart === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tend = paramsStart;\n\t\twhile (end > 0 && isWhitespaceChar(text.charCodeAt(end - 1))) {\n\t\t\tend -= 1;\n\t\t}\n\t}\n\treturn isWordAt(text, end - 2, \"do\", end);\n}\n\n/** Returns true when a Ruby line opens a keyword-paired block. */\nfunction rubyStartsFold(visible: string): boolean {\n\treturn (\n\t\tstartsWithAnyWordAfterWhitespace(visible, RUBY_START_KEYWORDS) || endsWithRubyDoBlock(visible)\n\t);\n}\n\n/** Returns true when a shell line has a `{` with no later `}` on the same line. */\nfunction endsWithOpenBrace(visible: string): boolean {\n\treturn visible.lastIndexOf(\"{\") > visible.lastIndexOf(\"}\");\n}\n\n/** Returns true when a Bash/Shell line opens a keyword-paired block. */\nfunction bashStartsFold(visible: string): boolean {\n\tif (\n\t\tstartsWithAnyWordAfterWhitespace(visible, BASH_START_KEYWORDS) &&\n\t\t!hasShellSameLineEndKeyword(visible)\n\t) {\n\t\treturn true;\n\t}\n\treturn endsWithOpenBrace(visible) || endsWithWord(visible, \"do\");\n}\n\n/** Returns true when a Bash/Shell line closes a keyword-paired block. */\nfunction bashEndsFold(visible: string): boolean {\n\tconst firstContent = firstNonWhitespaceIndex(visible);\n\treturn visible.charCodeAt(firstContent) === 125 || startsWithShellEndKeyword(visible);\n}\n\n/** Resolves the keyword pattern for a given language. */\nfunction patternFor(language: KeywordFoldLanguage): KeywordPattern {\n\tswitch (language) {\n\t\tcase \"ruby\":\n\t\tcase \"rb\":\n\t\t\treturn RUBY_PATTERN;\n\t\tcase \"bash\":\n\t\tcase \"sh\":\n\t\tcase \"shell\":\n\t\t\treturn BASH_PATTERN;\n\t}\n}\n\n/**\n * TextMate scope prefixes that mark a token as inert content (string body,\n * comment body, character escape). Mirrors the filter used by\n * `computeFoldRanges` for the bracket strategy so behaviors stay consistent.\n */\nconst INERT_SCOPE_PREFIXES: readonly string[] = [\n\t\"string.\",\n\t\"comment.\",\n\t\"constant.character.escape\",\n];\n\n/** Returns true when the innermost scope of a token marks it inert. */\nfunction isInertScope(scopes: readonly { scopeName: string }[]): boolean {\n\tif (scopes.length === 0) {\n\t\treturn false;\n\t}\n\tconst innermost = scopes[scopes.length - 1]?.scopeName ?? \"\";\n\tif (innermost === \"string\" || innermost === \"comment\") {\n\t\treturn true;\n\t}\n\tfor (const prefix of INERT_SCOPE_PREFIXES) {\n\t\tif (innermost.startsWith(prefix)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Reconstructs the visible (non-string, non-comment) text of a single\n * tokenized line.\n *\n * Subtlety: Shiki keeps leading whitespace inside `token.content` but strips\n * it from every `explanation.content` piece — so `\" HttpListener\"` (token)\n * decomposes into `[{ content: \"HttpListener\", scopes: […] }]`. Iterating\n * explanations alone collapses adjacent identifiers (`class HttpListener`\n * becomes `classHttpListener`), which breaks every word-boundary keyword\n * regex. We use `token.content` whenever no explanation piece is inert and\n * only fall back to per-explanation iteration for mixed-scope tokens.\n */\nfunction visibleTextForLine(line: FoldLine): string {\n\tlet visible = \"\";\n\tfor (const token of line) {\n\t\tconst explanations = token.explanation;\n\t\tif (explanations == null || explanations.length === 0) {\n\t\t\tvisible += token.content;\n\t\t\tcontinue;\n\t\t}\n\t\tlet hasInert = false;\n\t\tfor (const explanation of explanations) {\n\t\t\tif (isInertScope(explanation.scopes)) {\n\t\t\t\thasInert = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!hasInert) {\n\t\t\tvisible += token.content;\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const explanation of explanations) {\n\t\t\tif (isInertScope(explanation.scopes)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvisible += explanation.content;\n\t\t}\n\t}\n\treturn visible;\n}\n\n/**\n * Computes foldable ranges from tokenized source lines using the language's\n * keyword opener/closer regex pair.\n *\n * The same line can both open and close a block (`if foo; end` in Ruby).\n * Such lines push and pop on the stack but their start/end coincide, so the\n * range gets discarded by the `endLine > startLine` filter — matching how\n * the bracket strategy treats single-line `{}` constructs.\n *\n * @example\n * // tokens: [[\"def f\"], [\" pass\"], [\"end\"]]\n * computeKeywordFoldRanges({ language: \"ruby\", tokens });\n * // => [{ id: \"1\", startLine: 1, endLine: 3 }]\n */\nfunction computeKeywordFoldRanges({\n\tlanguage,\n\ttokens,\n}: {\n\t/** Resolved Mantle language; controls which keyword pattern to use. */\n\tlanguage: KeywordFoldLanguage;\n\t/** Shiki-tokenized lines, with scope explanations populated. */\n\ttokens: FoldLine[];\n}): FoldableRange[] {\n\tconst pattern = patternFor(language);\n\tconst stack: number[] = [];\n\tconst ranges: FoldableRange[] = [];\n\n\tfor (let lineIndex = 0; lineIndex < tokens.length; lineIndex += 1) {\n\t\tconst line = tokens[lineIndex];\n\t\tif (line == null) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst visible = visibleTextForLine(line);\n\t\tif (visible.length === 0) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst lineNumber = lineIndex + 1;\n\n\t\t// Closers come first: `end` on the same line as a `do` (e.g. `loop do\n\t\t// end` written across two lines but both `do` and `end` are on different\n\t\t// lines) shouldn't first push then pop on the same iteration.\n\t\tif (pattern.endsFold(visible)) {\n\t\t\tconst startLine = stack.pop();\n\t\t\tif (startLine != null && startLine < lineNumber) {\n\t\t\t\tranges.push({ id: String(startLine), startLine, endLine: lineNumber });\n\t\t\t}\n\t\t}\n\t\tif (pattern.startsFold(visible)) {\n\t\t\tstack.push(lineNumber);\n\t\t}\n\t}\n\n\treturn finalizeFoldRanges(ranges);\n}\n\nexport { computeKeywordFoldRanges };\nexport type { KeywordFoldLanguage };\n","import {\n\tcomputeFoldRanges,\n\tcomputeJsonFoldRanges,\n\tfinalizeFoldRanges,\n\ttype FoldableRange,\n\ttype FoldLine,\n\ttype SupportedLanguage,\n} from \"@ngrok/mantle/highlight-utils\";\nimport { computeCssFoldRanges } from \"./compute-css-fold-ranges.js\";\nimport { computeHtmlFoldRanges, type HtmlFoldLanguage } from \"./compute-html-fold-ranges.js\";\nimport { computeJsxFoldRanges, type JsxFoldLanguage } from \"./compute-jsx-fold-ranges.js\";\nimport {\n\tcomputeKeywordFoldRanges,\n\ttype KeywordFoldLanguage,\n} from \"./compute-keyword-fold-ranges.js\";\n\n/**\n * Server-side folding strategy applied to a language. This is a richer\n * dispatch than `@ngrok/mantle/highlight-utils`'s `foldStrategyFor`:\n *\n * - `jsx-ast` parses JS / TS / JSX / TSX with `oxc-parser`.\n * - `html-ast` parses HTML / XML with `parse5`.\n * - `css-raw` runs a CSS-aware single-pass brace matcher.\n * - `json-raw` reuses the existing `computeJsonFoldRanges` (raw, scope-free).\n * - `token-bracket` / `token-indentation` are the existing token-based\n * strategies for languages without a heavier parser (Go, Rust, Java, C#,\n * Python, YAML).\n * - `token-keyword` matches keyword openers / closers against tokenized line\n * text (Bash / Shell).\n * - `token-bracket-and-keyword` runs the bracket pass *and* the keyword pass\n * and merges them — Ruby uses brace-style blocks (`{ |x| … }`) plus\n * keyword blocks (`def … end`).\n * - `none` opts out for plain text and unknown languages.\n *\n * Strategies suffixed `-ast` or `-raw` need only the raw source string;\n * `token-*` strategies need Shiki-tokenized lines with scope explanations.\n */\ntype ServerFoldStrategy =\n\t| \"jsx-ast\"\n\t| \"html-ast\"\n\t| \"css-raw\"\n\t| \"json-raw\"\n\t| \"token-bracket\"\n\t| \"token-indentation\"\n\t| \"token-keyword\"\n\t| \"token-bracket-and-keyword\"\n\t| \"none\";\n\n/** Returns the server fold strategy for the given supported language. */\nfunction serverFoldStrategyFor(language: SupportedLanguage): ServerFoldStrategy {\n\tswitch (language) {\n\t\tcase \"javascript\":\n\t\tcase \"js\":\n\t\tcase \"typescript\":\n\t\tcase \"ts\":\n\t\tcase \"jsx\":\n\t\tcase \"tsx\":\n\t\t\treturn \"jsx-ast\";\n\t\tcase \"html\":\n\t\tcase \"xml\":\n\t\t\treturn \"html-ast\";\n\t\tcase \"css\":\n\t\t\treturn \"css-raw\";\n\t\tcase \"json\":\n\t\t\treturn \"json-raw\";\n\t\tcase \"python\":\n\t\tcase \"py\":\n\t\tcase \"yaml\":\n\t\tcase \"yml\":\n\t\t\treturn \"token-indentation\";\n\t\tcase \"ruby\":\n\t\tcase \"rb\":\n\t\t\treturn \"token-bracket-and-keyword\";\n\t\tcase \"bash\":\n\t\tcase \"sh\":\n\t\tcase \"shell\":\n\t\t\treturn \"token-keyword\";\n\t\tcase \"plain\":\n\t\tcase \"plaintext\":\n\t\tcase \"text\":\n\t\tcase \"txt\":\n\t\t\treturn \"none\";\n\t\tdefault:\n\t\t\treturn \"token-bracket\";\n\t}\n}\n\n/**\n * Returns true when the strategy needs Shiki-tokenized lines (with scope\n * explanations) to run. AST and raw-source strategies operate on the source\n * string directly and let us skip the `includeExplanation: 'scopeName'`\n * Shiki option, saving meaningful work on JS/TS/HTML/CSS hot paths.\n */\nfunction serverFoldNeedsTokens(strategy: ServerFoldStrategy): boolean {\n\tswitch (strategy) {\n\t\tcase \"token-bracket\":\n\t\tcase \"token-indentation\":\n\t\tcase \"token-keyword\":\n\t\tcase \"token-bracket-and-keyword\":\n\t\t\treturn true;\n\t\tcase \"jsx-ast\":\n\t\tcase \"html-ast\":\n\t\tcase \"css-raw\":\n\t\tcase \"json-raw\":\n\t\tcase \"none\":\n\t\t\treturn false;\n\t}\n}\n\n/** Type guard: narrows `SupportedLanguage` to languages handled by the JSX strategy. */\nfunction isJsxFoldLanguage(language: SupportedLanguage): language is JsxFoldLanguage {\n\treturn (\n\t\tlanguage === \"javascript\" ||\n\t\tlanguage === \"js\" ||\n\t\tlanguage === \"typescript\" ||\n\t\tlanguage === \"ts\" ||\n\t\tlanguage === \"jsx\" ||\n\t\tlanguage === \"tsx\"\n\t);\n}\n\n/** Type guard: narrows `SupportedLanguage` to languages handled by the HTML strategy. */\nfunction isHtmlFoldLanguage(language: SupportedLanguage): language is HtmlFoldLanguage {\n\treturn language === \"html\" || language === \"xml\";\n}\n\n/** Type guard: narrows `SupportedLanguage` to languages handled by the keyword strategy. */\nfunction isKeywordFoldLanguage(language: SupportedLanguage): language is KeywordFoldLanguage {\n\treturn (\n\t\tlanguage === \"ruby\" ||\n\t\tlanguage === \"rb\" ||\n\t\tlanguage === \"bash\" ||\n\t\tlanguage === \"sh\" ||\n\t\tlanguage === \"shell\"\n\t);\n}\n\n/**\n * Computes foldable ranges for a single highlighted code block, dispatching\n * to the appropriate strategy. Every supported language flows through here,\n * including the legacy token-based ones, so the engine has a single decision\n * point.\n *\n * Caller contract:\n * - For token-needing strategies, `tokens` must be the lines produced by\n * Shiki with `includeExplanation: 'scopeName'`. Pass `undefined` and the\n * strategy returns `[]`.\n * - For raw / AST strategies, `tokens` is ignored; only `code` matters.\n *\n * Errors raised by underlying parsers are caught and converted into \"no\n * folds\" — Shiki still gets to render the highlighted code, the gutter just\n * skips the toggle. We log nothing here because the engine is the wrong\n * layer to surface diagnostics.\n */\nfunction computeServerFoldRanges({\n\tcode,\n\tlanguage,\n\ttokens,\n}: {\n\t/** Normalized source code (post-`normalizeIndentation`). */\n\tcode: string;\n\t/** Resolved Mantle supported language. */\n\tlanguage: SupportedLanguage;\n\t/** Shiki-tokenized lines, when the strategy needs them. */\n\ttokens: FoldLine[] | undefined;\n}): FoldableRange[] {\n\tconst strategy = serverFoldStrategyFor(language);\n\ttry {\n\t\tswitch (strategy) {\n\t\t\tcase \"jsx-ast\":\n\t\t\t\tif (!isJsxFoldLanguage(language)) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\treturn computeJsxFoldRanges({ code, language });\n\t\t\tcase \"html-ast\":\n\t\t\t\tif (!isHtmlFoldLanguage(language)) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\treturn computeHtmlFoldRanges({ code, language });\n\t\t\tcase \"css-raw\":\n\t\t\t\treturn computeCssFoldRanges({ code });\n\t\t\tcase \"json-raw\":\n\t\t\t\treturn computeJsonFoldRanges(code);\n\t\t\tcase \"token-bracket\":\n\t\t\tcase \"token-indentation\":\n\t\t\t\tif (tokens == null) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\treturn computeFoldRanges({ language, tokens });\n\t\t\tcase \"token-keyword\":\n\t\t\t\tif (tokens == null || !isKeywordFoldLanguage(language)) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\treturn computeKeywordFoldRanges({ language, tokens });\n\t\t\tcase \"token-bracket-and-keyword\":\n\t\t\t\tif (tokens == null || !isKeywordFoldLanguage(language)) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\treturn finalizeFoldRanges([\n\t\t\t\t\t...computeFoldRanges({ language, tokens }),\n\t\t\t\t\t...computeKeywordFoldRanges({ language, tokens }),\n\t\t\t\t]);\n\t\t\tcase \"none\":\n\t\t\t\treturn [];\n\t\t}\n\t} catch {\n\t\t// AST parsers throw on malformed input; falling back to no folds keeps\n\t\t// the rest of the highlight pipeline alive.\n\t\treturn [];\n\t}\n}\n\nexport {\n\t//,\n\tcomputeServerFoldRanges,\n\tserverFoldNeedsTokens,\n\tserverFoldStrategyFor,\n};\nexport type { ServerFoldStrategy };\n","import { createHash } from \"node:crypto\";\nimport type { createHighlighter } from \"shiki\";\nimport {\n\tdecorateHighlightedHtml,\n\tinferIndentation,\n\tisSupportedLanguage,\n\tnormalizeIndentation,\n\tparseLanguage,\n\ttype FoldLine,\n\ttype Indentation,\n\ttype LineRange,\n\ttype SupportedLanguage,\n} from \"@ngrok/mantle/highlight-utils\";\nimport { createLruCache } from \"./lru-cache.js\";\nimport {\n\tcomputeServerFoldRanges,\n\tserverFoldNeedsTokens,\n\tserverFoldStrategyFor,\n} from \"./server-fold-ranges.js\";\n\n/**\n * Shiki grammar IDs preloaded by Mantle's highlighting engine.\n * This list is shared by both Vite plugins and server-side highlighting routes.\n */\nconst mantleShikiLanguageGrammarIds = [\n\t\"bash\",\n\t\"csharp\",\n\t\"css\",\n\t\"go\",\n\t\"html\",\n\t\"java\",\n\t\"javascript\",\n\t\"json\",\n\t\"jsx\",\n\t\"python\",\n\t\"ruby\",\n\t\"rust\",\n\t\"shell\",\n\t\"tsx\",\n\t\"typescript\",\n\t\"xml\",\n\t\"yaml\",\n] as const satisfies SupportedLanguage[];\n\n/**\n * Shared Shiki theme name used across Mantle highlighting.\n */\nconst mantleShikiThemeName = \"mantle-css-variables\" as const;\nconst mantleHighlightCacheMaxEntries = 1000;\n\ntype ShikiHighlighter = Awaited<ReturnType<typeof createHighlighter>>;\n\ntype MantleHighlightInput = {\n\t/**\n\t * Raw code string to highlight.\n\t */\n\tcode: string;\n\t/**\n\t * Language hint. Accepts supported language aliases and markdown-style values.\n\t */\n\tlanguage: SupportedLanguage | (string & {});\n\t/**\n\t * Optional indentation preference. Defaults to language-inferred indentation.\n\t */\n\tindentation?: Indentation;\n\t/**\n\t * Whether to render line numbers into the returned HTML.\n\t * @default true\n\t */\n\tshowLineNumbers?: boolean;\n\t/**\n\t * Optional list of highlighted line numbers/ranges to render into the returned HTML.\n\t * @default []\n\t */\n\thighlightLines?: (LineRange | number)[];\n\t/**\n\t * Start line number for rendered line numbers.\n\t * @default 1\n\t */\n\tlineNumberStart?: number;\n};\n\ntype MantleHighlightResult = {\n\t/**\n\t * Normalized source code used as the highlight input.\n\t */\n\tcode: string;\n\t/**\n\t * Highlighted HTML extracted from Shiki's `<code>...</code>`.\n\t */\n\thtml: string;\n\t/**\n\t * Resolved supported language used for highlighting.\n\t */\n\tlanguage: SupportedLanguage;\n\t/**\n\t * Whether returned HTML includes line numbers.\n\t */\n\tshowLineNumbers: boolean;\n\t/**\n\t * Highlighted line numbers/ranges applied to the returned HTML.\n\t */\n\thighlightLines: (LineRange | number)[];\n\t/**\n\t * Start line number used for rendered line numbers.\n\t */\n\tlineNumberStart: number;\n};\n\ntype MantleServerHighlighter = {\n\t/**\n\t * Highlight a code snippet and return normalized code + highlighted HTML.\n\t */\n\thighlight: (input: MantleHighlightInput) => Promise<MantleHighlightResult>;\n};\n\nlet highlighterPromise: Promise<ShikiHighlighter> | undefined;\nconst mantleHighlightCache = createLruCache<string, Promise<MantleHighlightResult>>(\n\tmantleHighlightCacheMaxEntries,\n);\n\n/**\n * Creates (and caches) Mantle's shared Shiki highlighter instance.\n */\nfunction getMantleShikiHighlighter(): Promise<ShikiHighlighter> {\n\tif (highlighterPromise != null) {\n\t\treturn highlighterPromise;\n\t}\n\n\thighlighterPromise = (async () => {\n\t\tconst { createCssVariablesTheme, createHighlighter } = await import(\"shiki\");\n\t\tconst cssVarsTheme = createCssVariablesTheme({ name: mantleShikiThemeName });\n\n\t\t// Append more granular token scope → CSS variable mappings.\n\t\t// More specific scopes override the defaults from createCssVariablesTheme.\n\t\t// Each uses a fallback to the original grouping variable for backwards compat.\n\t\tcssVarsTheme.tokenColors = [\n\t\t\t...(cssVarsTheme.tokenColors ?? []),\n\t\t\t{\n\t\t\t\tscope: [\"entity.name.type\", \"entity.name.class\", \"support.type\", \"support.class\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-type, var(--shiki-token-function))\" },\n\t\t\t},\n\t\t\t{\n\t\t\t\tscope: [\"variable\", \"variable.parameter\", \"variable.other\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-variable, var(--shiki-foreground))\" },\n\t\t\t},\n\t\t\t{\n\t\t\t\tscope: [\"keyword.operator\", \"keyword.operator.assignment\", \"keyword.operator.comparison\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-operator, var(--shiki-token-keyword))\" },\n\t\t\t},\n\t\t\t{\n\t\t\t\tscope: [\"entity.other.attribute-name\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-attribute, var(--shiki-token-constant))\" },\n\t\t\t},\n\t\t\t{\n\t\t\t\tscope: [\"meta.object-literal.key\", \"support.type.property-name\", \"entity.name.tag.yaml\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-property, var(--shiki-token-function))\" },\n\t\t\t},\n\t\t\t{\n\t\t\t\tscope: [\"constant.character.escape\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-escape, var(--shiki-token-constant))\" },\n\t\t\t},\n\t\t\t{\n\t\t\t\tscope: [\"string.unquoted.plain.out.yaml\", \"string.unquoted.plain.in.yaml\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-variable, var(--shiki-foreground))\" },\n\t\t\t},\n\t\t\t{\n\t\t\t\tscope: [\"punctuation.definition.block.sequence.item.yaml\"],\n\t\t\t\tsettings: { foreground: \"var(--shiki-token-variable, var(--shiki-foreground))\" },\n\t\t\t},\n\t\t];\n\n\t\treturn createHighlighter({\n\t\t\tthemes: [cssVarsTheme],\n\t\t\tlangs: [...mantleShikiLanguageGrammarIds],\n\t\t});\n\t})().catch((error) => {\n\t\thighlighterPromise = undefined;\n\t\tthrow error;\n\t});\n\n\treturn highlighterPromise;\n}\n\n/**\n * Extracts the inner HTML from a Shiki `<code>...</code>` wrapper.\n */\nfunction extractHighlightedCodeInnerHtml(fullHtml: string): string | undefined {\n\treturn fullHtml.match(/<code[^>]*>([\\s\\S]*?)<\\/code>/)?.[1];\n}\n\n/**\n * Highlights code with Mantle's shared Shiki engine and normalization defaults.\n */\nasync function highlightWithMantleShiki(\n\tinput: MantleHighlightInput,\n): Promise<MantleHighlightResult> {\n\tconst resolvedLanguage = isSupportedLanguage(input.language)\n\t\t? input.language\n\t\t: parseLanguage(input.language);\n\tconst indentation = input.indentation ?? inferIndentation(resolvedLanguage, undefined);\n\tconst normalizedCode = normalizeIndentation(input.code, {\n\t\tindentation,\n\t});\n\tconst showLineNumbers = input.showLineNumbers ?? true;\n\tconst highlightLines = input.highlightLines ?? [];\n\tconst lineNumberStart = input.lineNumberStart ?? 1;\n\tconst cacheKey = createHash(\"sha1\")\n\t\t.update(normalizedCode)\n\t\t.update(\n\t\t\t`\\0${resolvedLanguage}\\0${showLineNumbers}\\0${lineNumberStart}\\0${JSON.stringify(highlightLines)}`,\n\t\t)\n\t\t.digest(\"hex\");\n\tconst cached = mantleHighlightCache.get(cacheKey);\n\tif (cached != null) {\n\t\treturn cached;\n\t}\n\n\tconst promise = (async () => {\n\t\tconst highlighter = await getMantleShikiHighlighter();\n\t\t// AST and raw-source fold strategies don't need token explanations, so\n\t\t// we skip the `includeExplanation` cost on the JS/TS/HTML/CSS hot path.\n\t\t// Token-based strategies (Python, Ruby, Go, …) still pay for it.\n\t\tconst foldStrategy = serverFoldStrategyFor(resolvedLanguage);\n\t\tconst wantsTokens = serverFoldNeedsTokens(foldStrategy);\n\t\tlet capturedTokens: FoldLine[] | undefined;\n\t\tconst fullHtml = highlighter.codeToHtml(normalizedCode, {\n\t\t\tlang: resolvedLanguage,\n\t\t\ttheme: mantleShikiThemeName,\n\t\t\tincludeExplanation: wantsTokens ? \"scopeName\" : false,\n\t\t\ttransformers: wantsTokens\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"mantle:capture-tokens\",\n\t\t\t\t\t\t\ttokens(tokens) {\n\t\t\t\t\t\t\t\tcapturedTokens = tokens;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: undefined,\n\t\t});\n\t\tconst baseHtml = extractHighlightedCodeInnerHtml(fullHtml);\n\n\t\tif (baseHtml == null) {\n\t\t\tthrow new Error(\"Failed to extract highlighted HTML from Shiki output\");\n\t\t}\n\t\tconst foldableRanges =\n\t\t\tfoldStrategy === \"none\"\n\t\t\t\t? undefined\n\t\t\t\t: computeServerFoldRanges({\n\t\t\t\t\t\tcode: normalizedCode,\n\t\t\t\t\t\tlanguage: resolvedLanguage,\n\t\t\t\t\t\ttokens: capturedTokens,\n\t\t\t\t\t});\n\t\tconst html = decorateHighlightedHtml({\n\t\t\tfoldableRanges,\n\t\t\thighlightLines,\n\t\t\thtml: baseHtml,\n\t\t\tlineNumberStart,\n\t\t\tshowLineNumbers,\n\t\t});\n\n\t\treturn {\n\t\t\tcode: normalizedCode,\n\t\t\thtml,\n\t\t\tlanguage: resolvedLanguage,\n\t\t\tshowLineNumbers,\n\t\t\thighlightLines,\n\t\t\tlineNumberStart,\n\t\t};\n\t})().catch((error) => {\n\t\tmantleHighlightCache.delete(cacheKey);\n\t\tthrow error;\n\t});\n\n\tmantleHighlightCache.set(cacheKey, promise);\n\treturn promise;\n}\n\n/**\n * Creates a reusable Mantle server highlighter facade for API routes.\n */\nfunction createMantleServerSyntaxHighlighter(): MantleServerHighlighter {\n\treturn {\n\t\thighlight: highlightWithMantleShiki,\n\t};\n}\n\nexport {\n\tcreateMantleServerSyntaxHighlighter,\n\textractHighlightedCodeInnerHtml,\n\tgetMantleShikiHighlighter,\n\thighlightWithMantleShiki,\n\tmantleHighlightCacheMaxEntries,\n\tmantleShikiLanguageGrammarIds,\n\tmantleShikiThemeName,\n};\nexport type { MantleHighlightInput, MantleHighlightResult, MantleServerHighlighter };\n"],"mappings":";;;;;;;AASA,SAAS,eAAqB,YAAoC;CACjE,IAAI,CAAC,OAAO,UAAU,UAAU,KAAK,cAAc,GAClD,MAAM,IAAI,MAAM,kDAAkD;CAGnE,MAAM,sBAAM,IAAI,IAAU;CAE1B,OAAO;EACN,OAAO,KAAK;GACX,OAAO,IAAI,OAAO,GAAG;EACtB;EACA,IAAI,KAAK;GACR,IAAI,CAAC,IAAI,IAAI,GAAG,GACf;GAGD,MAAM,QAAQ,IAAI,IAAI,GAAG;GACzB,IAAI,OAAO,GAAG;GACd,IAAI,IAA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IAGH;IACA,MAAM;IACN;IACA;GACD,CAII;GACH,UAAU;GACV;GACA;GACA;EACD;CACD,EAAC,CAAE,CAAC,CAAC,OAAO,UAAU;EACrB,qBAAqB,OAAO,QAAQ;EACpC,MAAM;CACP,CAAC;CAED,qBAAqB,IAAI,UAAU,OAAO;CAC1C,OAAO;AACR;;;;AAKA,SAAS,sCAA+D;CACvE,OAAO,EACN,WAAW,yBACZ;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngrok/mantle-server-syntax-highlighter",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Server-side syntax highlighting for @ngrok/mantle, powered by Shiki.",
5
5
  "homepage": "https://mantle.ngrok.com",
6
6
  "license": "MIT",
@@ -23,17 +23,17 @@
23
23
  "./package.json": "./package.json"
24
24
  },
25
25
  "dependencies": {
26
- "oxc-parser": "0.130.0",
26
+ "oxc-parser": "0.135.0",
27
27
  "parse5": "8.0.1",
28
- "shiki": "4.0.2"
28
+ "shiki": "4.2.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@testing-library/jest-dom": "6.9.1",
32
- "@types/node": "24.12.4",
33
- "tsdown": "0.22.0",
32
+ "@types/node": "24.13.1",
33
+ "tsdown": "0.22.2",
34
34
  "typescript": "6.0.3",
35
- "@cfg/tsconfig": "1.0.0",
36
- "@ngrok/mantle": "0.73.0"
35
+ "@ngrok/mantle": "0.74.0",
36
+ "@cfg/tsconfig": "1.0.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@ngrok/mantle": "*"