tempo-sdk 0.0.87 → 0.0.92

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.
Files changed (70) hide show
  1. package/dist/astro.js +7 -7
  2. package/dist/canvas/astro.js +1 -1
  3. package/dist/canvas/editor.js +1 -1
  4. package/dist/canvas/index.js +2 -2
  5. package/dist/canvas/interact-projection.js +1 -1
  6. package/dist/canvas/parser.js +1 -1
  7. package/dist/canvas/svelte.js +10 -2
  8. package/dist/canvas/svelte.js.map +1 -1
  9. package/dist/canvas/vue.js +1 -1
  10. package/dist/{chunk-RQ54RXOY.js → chunk-3XEEVCM3.js} +36 -12
  11. package/dist/chunk-3XEEVCM3.js.map +1 -0
  12. package/dist/{chunk-2ZQMVAFM.js → chunk-6SOP4XU6.js} +98 -33
  13. package/dist/chunk-6SOP4XU6.js.map +1 -0
  14. package/dist/{chunk-Y72PIE3I.js → chunk-AFXE462X.js} +5 -4
  15. package/dist/{chunk-Y72PIE3I.js.map → chunk-AFXE462X.js.map} +1 -1
  16. package/dist/{chunk-DMT5MRMS.js → chunk-BQPKOVI5.js} +4 -3
  17. package/dist/{chunk-DMT5MRMS.js.map → chunk-BQPKOVI5.js.map} +1 -1
  18. package/dist/{chunk-PTL3UFIF.js → chunk-FENUT2N2.js} +2 -2
  19. package/dist/{chunk-PTL3UFIF.js.map → chunk-FENUT2N2.js.map} +1 -1
  20. package/dist/{chunk-H6OZIX2U.js → chunk-FGWGY3G3.js} +27 -3
  21. package/dist/chunk-FGWGY3G3.js.map +1 -0
  22. package/dist/{chunk-CXGAJRK7.js → chunk-KQSOE4KZ.js} +7 -7
  23. package/dist/chunk-MU7S7NU7.js +183 -0
  24. package/dist/chunk-MU7S7NU7.js.map +1 -0
  25. package/dist/{chunk-PPIIUCX5.js → chunk-NXPP3CSM.js} +5 -4
  26. package/dist/chunk-NXPP3CSM.js.map +1 -0
  27. package/dist/{chunk-GVH7HUMT.js → chunk-RZ3TG6MV.js} +2 -2
  28. package/dist/{chunk-GVH7HUMT.js.map → chunk-RZ3TG6MV.js.map} +1 -1
  29. package/dist/{chunk-AUG3ZWTR.js → chunk-TWW2DL7E.js} +2 -2
  30. package/dist/{chunk-AUG3ZWTR.js.map → chunk-TWW2DL7E.js.map} +1 -1
  31. package/dist/{chunk-5VIBKVFO.js → chunk-U66QI3EN.js} +28 -18
  32. package/dist/chunk-U66QI3EN.js.map +1 -0
  33. package/dist/{controls-reader-Z7OQWYWQ.js → controls-reader-5MFHYBZZ.js} +4 -4
  34. package/dist/expo/plugin.cjs +97 -32
  35. package/dist/expo/plugin.cjs.map +1 -1
  36. package/dist/expo/plugin.js +1 -1
  37. package/dist/expo-babel-plugin.cjs +97 -32
  38. package/dist/expo-babel-plugin.cjs.map +1 -1
  39. package/dist/expo-babel-plugin.d.cts +2 -0
  40. package/dist/expo-babel-plugin.d.ts +2 -0
  41. package/dist/expo-babel-plugin.js +1 -1
  42. package/dist/index.d.ts +2 -0
  43. package/dist/index.js +6 -6
  44. package/dist/nextjs/plugin.cjs +1 -1
  45. package/dist/nextjs/plugin.cjs.map +1 -1
  46. package/dist/nextjs/plugin.js +1 -1
  47. package/dist/nextjs-loader.cjs +126 -37
  48. package/dist/nextjs-loader.cjs.map +1 -1
  49. package/dist/nextjs.cjs +1 -1
  50. package/dist/nextjs.cjs.map +1 -1
  51. package/dist/nextjs.d.cts +2 -0
  52. package/dist/nextjs.d.ts +2 -0
  53. package/dist/nextjs.js +1 -1
  54. package/dist/nuxt/runtime/identity.js +1 -1
  55. package/dist/nuxt.js +230 -53
  56. package/dist/nuxt.js.map +1 -1
  57. package/dist/svelte.js +99 -24
  58. package/dist/svelte.js.map +1 -1
  59. package/dist/vue.js +120 -22
  60. package/dist/vue.js.map +1 -1
  61. package/package.json +1 -1
  62. package/dist/chunk-2ZQMVAFM.js.map +0 -1
  63. package/dist/chunk-5VIBKVFO.js.map +0 -1
  64. package/dist/chunk-H6BQZOAW.js +0 -121
  65. package/dist/chunk-H6BQZOAW.js.map +0 -1
  66. package/dist/chunk-H6OZIX2U.js.map +0 -1
  67. package/dist/chunk-PPIIUCX5.js.map +0 -1
  68. package/dist/chunk-RQ54RXOY.js.map +0 -1
  69. /package/dist/{chunk-CXGAJRK7.js.map → chunk-KQSOE4KZ.js.map} +0 -0
  70. /package/dist/{controls-reader-Z7OQWYWQ.js.map → controls-reader-5MFHYBZZ.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../svelte.ts","../../../modules/svelte-editor/compiler.ts","../../../modules/svelte-editor/escape.ts","../../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js","../../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js","../../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js","../../../modules/svelte-editor/parse.ts","../../../modules/svelte-editor/annotate.ts","../../../modules/svelte-editor/markup-transfer.ts"],"sourcesContent":["/**\n * Svelte-specific Tempo source annotation.\n *\n * Keep this adapter first in `svelte({ preprocess: [...] })`. It only supplies\n * filesystem/project identity; parsing and annotation remain isolated in the\n * framework-focused @modules/svelte-editor package.\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { createSvelteAnnotationPreprocessor } from \"@modules/svelte-editor\";\nimport type { PreprocessorGroup } from \"svelte/compiler\";\nimport { sourceVersionHash } from \"../../modules/annotation/source-version.ts\";\nimport {\n defaultSourceRoot,\n readModifiedTs,\n resolveAnnotationIdentity,\n} from \"./annotation-identity.ts\";\nimport { appendModuleVersionRecord } from \"./annotation-strategy.ts\";\n\nexport interface TempoSveltePreprocessOptions {\n /** Annotation identity root. Defaults to the process working directory. */\n root?: string;\n /** Allowed source boundary. Defaults to the package-manager workspace\n * around `root`, else `root` (see defaultSourceRoot); host sidecars set\n * this to the project root while annotations remain relative to the host\n * root. */\n sourceRoot?: string;\n /** Override the normal TEMPO environment gate, primarily for tests. */\n enabled?: boolean;\n}\n\n/** A top-level module script, Svelte 5 (`module`) or 4 (`context=\"module\"`). */\nconst MODULE_SCRIPT =\n /<script\\b[^>]*\\b(?:module\\b|context\\s*=\\s*[\"']module[\"'])[^>]*>/;\n\nexport function tempoSveltePreprocess(\n options: TempoSveltePreprocessOptions = {},\n): PreprocessorGroup {\n const root = resolve(options.root ?? process.cwd());\n const sourceRoot = resolve(options.sourceRoot ?? defaultSourceRoot(root));\n const enabled = options.enabled ?? Boolean(process.env.TEMPO);\n\n const metadata = ({ filename }: { filename?: string }) => {\n if (!enabled || !filename) return null;\n const identity = resolveAnnotationIdentity(filename, { root, sourceRoot });\n if (!identity?.absoluteFilename.endsWith(\".svelte\")) return null;\n return {\n filepath: identity.filepath,\n modifiedTs: readModifiedTs(identity.absoluteFilename),\n };\n };\n const annotation = createSvelteAnnotationPreprocessor({ metadata });\n\n return {\n name: \"svelte-source-annotation\",\n // The annotation, plus an empty module script when the file has none:\n // the module version record must run once per module evaluation, which\n // is what a module script's top level does (V2-498).\n markup(input) {\n const result = annotation.markup?.(input);\n if (!result || !(\"code\" in result)) return result;\n if (MODULE_SCRIPT.test(result.code)) return result;\n return {\n ...result,\n code: `${result.code}\\n<script module></script>\\n`,\n };\n },\n // The module version record ends the module script, as it ends every\n // annotated JSX module. The file's own bytes name its version, the same\n // raw-source hash the element stamps carry.\n script({ content, attributes, filename }) {\n const moduleScript =\n attributes.module === true || attributes.context === \"module\";\n if (!moduleScript) return undefined;\n const identity = metadata({ filename });\n if (!identity || !filename) return undefined;\n const sourceVersion = sourceVersionHash(readFileSync(filename, \"utf8\"));\n return {\n code: appendModuleVersionRecord(\n content,\n identity.filepath,\n identity.modifiedTs,\n sourceVersion,\n ),\n };\n },\n };\n}\n","/**\n * The Svelte compiler functions the editor calls. Every value import of the\n * compiler goes through here, as `#svelte-compiler` (package.json\n * \"imports\"), so a bundler can swap in `compiler-deferred.ts`; the other\n * modules import only its types.\n */\nexport { compile, parse } from \"svelte/compiler\";\n","export function escapeSvelteAttributeValue(\n value: string,\n quote: '\"' | \"'\",\n): string {\n let escaped = value\n .split(\"&\")\n .join(\"&amp;\")\n .split(\"<\")\n .join(\"&lt;\")\n .split(\">\")\n .join(\"&gt;\")\n .split(\"{\")\n .join(\"&#123;\")\n .split(\"}\")\n .join(\"&#125;\");\n escaped =\n quote === '\"'\n ? escaped.split('\"').join(\"&quot;\")\n : escaped.split(\"'\").join(\"&#39;\");\n return escaped;\n}\n","/**\n * @typedef { import('estree').Node} Node\n * @typedef {{\n * skip: () => void;\n * remove: () => void;\n * replace: (node: Node) => void;\n * }} WalkerContext\n */\n\nexport class WalkerBase {\n\tconstructor() {\n\t\t/** @type {boolean} */\n\t\tthis.should_skip = false;\n\n\t\t/** @type {boolean} */\n\t\tthis.should_remove = false;\n\n\t\t/** @type {Node | null} */\n\t\tthis.replacement = null;\n\n\t\t/** @type {WalkerContext} */\n\t\tthis.context = {\n\t\t\tskip: () => (this.should_skip = true),\n\t\t\tremove: () => (this.should_remove = true),\n\t\t\treplace: (node) => (this.replacement = node)\n\t\t};\n\t}\n\n\t/**\n\t * @template {Node} Parent\n\t * @param {Parent | null | undefined} parent\n\t * @param {keyof Parent | null | undefined} prop\n\t * @param {number | null | undefined} index\n\t * @param {Node} node\n\t */\n\treplace(parent, prop, index, node) {\n\t\tif (parent && prop) {\n\t\t\tif (index != null) {\n\t\t\t\t/** @type {Array<Node>} */ (parent[prop])[index] = node;\n\t\t\t} else {\n\t\t\t\t/** @type {Node} */ (parent[prop]) = node;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * @template {Node} Parent\n\t * @param {Parent | null | undefined} parent\n\t * @param {keyof Parent | null | undefined} prop\n\t * @param {number | null | undefined} index\n\t */\n\tremove(parent, prop, index) {\n\t\tif (parent && prop) {\n\t\t\tif (index !== null && index !== undefined) {\n\t\t\t\t/** @type {Array<Node>} */ (parent[prop]).splice(index, 1);\n\t\t\t} else {\n\t\t\t\tdelete parent[prop];\n\t\t\t}\n\t\t}\n\t}\n}\n","import { WalkerBase } from './walker.js';\n\n/**\n * @typedef { import('estree').Node} Node\n * @typedef { import('./walker.js').WalkerContext} WalkerContext\n * @typedef {(\n * this: WalkerContext,\n * node: Node,\n * parent: Node | null,\n * key: string | number | symbol | null | undefined,\n * index: number | null | undefined\n * ) => void} SyncHandler\n */\n\nexport class SyncWalker extends WalkerBase {\n\t/**\n\t *\n\t * @param {SyncHandler} [enter]\n\t * @param {SyncHandler} [leave]\n\t */\n\tconstructor(enter, leave) {\n\t\tsuper();\n\n\t\t/** @type {boolean} */\n\t\tthis.should_skip = false;\n\n\t\t/** @type {boolean} */\n\t\tthis.should_remove = false;\n\n\t\t/** @type {Node | null} */\n\t\tthis.replacement = null;\n\n\t\t/** @type {WalkerContext} */\n\t\tthis.context = {\n\t\t\tskip: () => (this.should_skip = true),\n\t\t\tremove: () => (this.should_remove = true),\n\t\t\treplace: (node) => (this.replacement = node)\n\t\t};\n\n\t\t/** @type {SyncHandler | undefined} */\n\t\tthis.enter = enter;\n\n\t\t/** @type {SyncHandler | undefined} */\n\t\tthis.leave = leave;\n\t}\n\n\t/**\n\t * @template {Node} Parent\n\t * @param {Node} node\n\t * @param {Parent | null} parent\n\t * @param {keyof Parent} [prop]\n\t * @param {number | null} [index]\n\t * @returns {Node | null}\n\t */\n\tvisit(node, parent, prop, index) {\n\t\tif (node) {\n\t\t\tif (this.enter) {\n\t\t\t\tconst _should_skip = this.should_skip;\n\t\t\t\tconst _should_remove = this.should_remove;\n\t\t\t\tconst _replacement = this.replacement;\n\t\t\t\tthis.should_skip = false;\n\t\t\t\tthis.should_remove = false;\n\t\t\t\tthis.replacement = null;\n\n\t\t\t\tthis.enter.call(this.context, node, parent, prop, index);\n\n\t\t\t\tif (this.replacement) {\n\t\t\t\t\tnode = this.replacement;\n\t\t\t\t\tthis.replace(parent, prop, index, node);\n\t\t\t\t}\n\n\t\t\t\tif (this.should_remove) {\n\t\t\t\t\tthis.remove(parent, prop, index);\n\t\t\t\t}\n\n\t\t\t\tconst skipped = this.should_skip;\n\t\t\t\tconst removed = this.should_remove;\n\n\t\t\t\tthis.should_skip = _should_skip;\n\t\t\t\tthis.should_remove = _should_remove;\n\t\t\t\tthis.replacement = _replacement;\n\n\t\t\t\tif (skipped) return node;\n\t\t\t\tif (removed) return null;\n\t\t\t}\n\n\t\t\t/** @type {keyof Node} */\n\t\t\tlet key;\n\n\t\t\tfor (key in node) {\n\t\t\t\t/** @type {unknown} */\n\t\t\t\tconst value = node[key];\n\n\t\t\t\tif (value && typeof value === 'object') {\n\t\t\t\t\tif (Array.isArray(value)) {\n\t\t\t\t\t\tconst nodes = /** @type {Array<unknown>} */ (value);\n\t\t\t\t\t\tfor (let i = 0; i < nodes.length; i += 1) {\n\t\t\t\t\t\t\tconst item = nodes[i];\n\t\t\t\t\t\t\tif (isNode(item)) {\n\t\t\t\t\t\t\t\tif (!this.visit(item, node, key, i)) {\n\t\t\t\t\t\t\t\t\t// removed\n\t\t\t\t\t\t\t\t\ti--;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (isNode(value)) {\n\t\t\t\t\t\tthis.visit(value, node, key, null);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.leave) {\n\t\t\t\tconst _replacement = this.replacement;\n\t\t\t\tconst _should_remove = this.should_remove;\n\t\t\t\tthis.replacement = null;\n\t\t\t\tthis.should_remove = false;\n\n\t\t\t\tthis.leave.call(this.context, node, parent, prop, index);\n\n\t\t\t\tif (this.replacement) {\n\t\t\t\t\tnode = this.replacement;\n\t\t\t\t\tthis.replace(parent, prop, index, node);\n\t\t\t\t}\n\n\t\t\t\tif (this.should_remove) {\n\t\t\t\t\tthis.remove(parent, prop, index);\n\t\t\t\t}\n\n\t\t\t\tconst removed = this.should_remove;\n\n\t\t\t\tthis.replacement = _replacement;\n\t\t\t\tthis.should_remove = _should_remove;\n\n\t\t\t\tif (removed) return null;\n\t\t\t}\n\t\t}\n\n\t\treturn node;\n\t}\n}\n\n/**\n * Ducktype a node.\n *\n * @param {unknown} value\n * @returns {value is Node}\n */\nfunction isNode(value) {\n\treturn (\n\t\tvalue !== null && typeof value === 'object' && 'type' in value && typeof value.type === 'string'\n\t);\n}\n","import { SyncWalker } from './sync.js';\nimport { AsyncWalker } from './async.js';\n\n/**\n * @typedef {import('estree').Node} Node\n * @typedef {import('./sync.js').SyncHandler} SyncHandler\n * @typedef {import('./async.js').AsyncHandler} AsyncHandler\n */\n\n/**\n * @param {Node} ast\n * @param {{\n * enter?: SyncHandler\n * leave?: SyncHandler\n * }} walker\n * @returns {Node | null}\n */\nexport function walk(ast, { enter, leave }) {\n\tconst instance = new SyncWalker(enter, leave);\n\treturn instance.visit(ast, null);\n}\n\n/**\n * @param {Node} ast\n * @param {{\n * enter?: AsyncHandler\n * leave?: AsyncHandler\n * }} walker\n * @returns {Promise<Node | null>}\n */\nexport async function asyncWalk(ast, { enter, leave }) {\n\tconst instance = new AsyncWalker(enter, leave);\n\treturn await instance.visit(ast, null);\n}\n","import { walk } from \"estree-walker\";\nimport type { AST } from \"svelte/compiler\";\nimport { compile, parse } from \"#svelte-compiler\";\nimport type {\n SvelteElementInfo,\n SvelteParseResult,\n SvelteTargetInfo,\n} from \"./types\";\n\ninterface InternalElementInfo extends SvelteElementInfo {\n node: AST.RegularElement;\n parentFragment: AST.Fragment;\n /** Owner of the exact Fragment that directly contains this element. */\n parentFragmentOwnerType: string | null;\n containsDynamicTemplateSyntax: boolean;\n}\n\nexport type InternalParseResult =\n | {\n kind: \"ok\";\n elements: ReadonlyMap<number, InternalElementInfo>;\n /** Native DOM wrappers preserve this scope; blocks and local declarations do not. */\n templateScopes: WeakMap<AST.Fragment, AST.Fragment>;\n targets: ReadonlyMap<number, SvelteTargetInfo>;\n targetNodes: ReadonlyMap<\n number,\n AST.BaseNode & { name?: string; attributes?: AST.AttributeLike[] }\n >;\n }\n | Extract<SvelteParseResult, { kind: \"invalid\" }>;\n\nexport function parseSvelteSource(\n source: string,\n filename = \"Component.svelte\",\n): SvelteParseResult {\n const result = parseSvelteSourceInternal(source, filename);\n if (result.kind === \"invalid\") return result;\n\n return toPublicParseResult(result);\n}\n\nfunction toPublicParseResult(\n result: Extract<InternalParseResult, { kind: \"ok\" }>,\n): Extract<SvelteParseResult, { kind: \"ok\" }> {\n return {\n kind: \"ok\",\n elements: new Map(\n [...result.elements].map(([offset, element]) => [\n offset,\n toPublicElementInfo(element),\n ]),\n ),\n targets: new Map(result.targets),\n };\n}\n\nexport function findSvelteElementAtOffset(\n parsed: SvelteParseResult,\n offset: number,\n): SvelteElementInfo | null {\n if (parsed.kind !== \"ok\" || !Number.isInteger(offset)) return null;\n return parsed.elements.get(offset) ?? null;\n}\n\nexport function parseSvelteSourceInternal(\n source: string,\n filename: string,\n validation: \"compiler\" | \"syntax\" = \"compiler\",\n): InternalParseResult {\n const cacheKey = `${validation}\\0${filename}\\0${source}`;\n const cached = parseCache.get(cacheKey);\n if (cached) {\n parseCache.delete(cacheKey);\n parseCache.set(cacheKey, cached);\n return cached;\n }\n try {\n // `parse` intentionally accepts some compiler-invalid semantic forms.\n // Establish compiler validity before exposing offsets as editable anchors.\n if (validation === \"compiler\") {\n compile(source, { filename, generate: false });\n }\n const ast = parse(source, { filename, modern: true });\n const elements = new Map<number, InternalElementInfo>();\n const targets = new Map<number, SvelteTargetInfo>();\n const targetNodes = new Map<\n number,\n AST.BaseNode & { name?: string; attributes?: AST.AttributeLike[] }\n >();\n const elementStack: AST.RegularElement[] = [];\n const fragmentOwnerTypes = new WeakMap<object, string | null>();\n const templateScopes = new WeakMap<AST.Fragment, AST.Fragment>();\n const scopeStack: AST.Fragment[] = [];\n\n walk(ast as unknown as Parameters<typeof walk>[0], {\n enter(node, parent) {\n const svelteNode = node as unknown as AST.BaseNode;\n if (svelteNode.type === \"Fragment\") {\n const fragment = node as unknown as AST.Fragment;\n const owner = parent as unknown as AST.BaseNode | null;\n const inherits =\n owner?.type === \"RegularElement\" &&\n !(owner as AST.RegularElement).attributes.some(\n (attribute) => attribute.type === \"LetDirective\",\n ) &&\n !fragment.nodes.some(\n (child) =>\n child.type === \"ConstTag\" || child.type === \"SnippetBlock\",\n );\n const scope = inherits\n ? (scopeStack[scopeStack.length - 1] ?? fragment)\n : fragment;\n templateScopes.set(fragment, scope);\n scopeStack.push(scope);\n fragmentOwnerTypes.set(\n node as object,\n (parent as unknown as AST.BaseNode | null)?.type ?? null,\n );\n }\n const target = toTargetInfo(\n node as unknown as AST.BaseNode & {\n name?: string;\n },\n );\n if (target) {\n const fragment = parent as unknown as AST.BaseNode | null;\n target.parentFragmentOwnerType =\n fragment?.type === \"Fragment\"\n ? (fragmentOwnerTypes.get(fragment as object) ?? null)\n : null;\n targets.set(target.start, target);\n targetNodes.set(\n target.start,\n node as unknown as AST.BaseNode & {\n name?: string;\n attributes?: AST.AttributeLike[];\n },\n );\n }\n if (svelteNode.type !== \"RegularElement\") return;\n const element = node as unknown as AST.RegularElement;\n const parentFragment = parent as unknown as AST.Fragment;\n /* v8 ignore next 4 -- Svelte's modern AST schema parents every RegularElement with Fragment */\n if (parentFragment.type !== \"Fragment\") {\n throw new Error(\n `native element at offset ${element.start} has no exact template fragment parent`,\n );\n }\n const opening = locateOpeningTagEnd(source, element);\n /* v8 ignore next 3 -- a compiler-parsed RegularElement always has an authored opening terminator */\n if (opening.kind === \"invalid\") {\n throw new Error(opening.message);\n }\n /* v8 ignore next 4 -- modern AST source ranges cannot assign one start to two nodes */\n if (elements.has(element.start)) {\n throw new Error(\n `multiple native elements start at UTF-16 offset ${element.start}`,\n );\n }\n elements.set(element.start, {\n node: element,\n tagName: element.name,\n start: element.start,\n end: element.end,\n openingEnd: opening.openingEnd,\n selfClosing: opening.selfClosing,\n childrenStart: opening.selfClosing ? null : opening.openingEnd,\n childrenEnd: opening.selfClosing\n ? null\n : locateClosingTagStart(source, element, opening.openingEnd),\n parentElementStart:\n elementStack[elementStack.length - 1]?.start ?? null,\n parentFragment,\n parentFragmentOwnerType:\n fragmentOwnerTypes.get(parentFragment as object) ?? null,\n containsDynamicTemplateSyntax: containsDynamicSyntax(element),\n attributeNames: element.attributes\n .filter(\n (attribute): attribute is AST.Attribute =>\n attribute.type === \"Attribute\",\n )\n .map((attribute) => attribute.name),\n hasSpreadAttributes: element.attributes.some(\n (attribute) => attribute.type === \"SpreadAttribute\",\n ),\n directiveTypes: element.attributes\n .filter(\n (attribute) =>\n attribute.type !== \"Attribute\" &&\n attribute.type !== \"SpreadAttribute\",\n )\n .map((attribute) => attribute.type),\n });\n elementStack.push(element);\n },\n leave(node) {\n const svelteNode = node as unknown as AST.BaseNode;\n if (svelteNode.type === \"RegularElement\") elementStack.pop();\n if (svelteNode.type === \"Fragment\") scopeStack.pop();\n },\n });\n\n const result = {\n kind: \"ok\",\n elements,\n templateScopes,\n targets,\n targetNodes,\n } as const;\n rememberParse(cacheKey, result);\n return result;\n } catch (error) {\n const result = compilerError(error);\n rememberParse(cacheKey, result);\n return result;\n }\n}\n\nfunction toTargetInfo(\n node: AST.BaseNode & {\n name?: string;\n attributes?: AST.AttributeLike[];\n },\n): SvelteTargetInfo | null {\n if (node.type === \"RegularElement\") {\n return {\n kind: \"native-element\",\n tagName: node.name ?? \"\",\n start: node.start,\n end: node.end,\n ...targetAttributeFacts(node.attributes ?? []),\n };\n }\n if (node.type === \"Component\") {\n return {\n kind: \"component\",\n tagName: node.name ?? \"\",\n start: node.start,\n end: node.end,\n ...targetAttributeFacts(node.attributes ?? []),\n };\n }\n if (node.type === \"SvelteComponent\") {\n return {\n kind: \"component\",\n tagName: node.name ?? node.type,\n start: node.start,\n end: node.end,\n ...targetAttributeFacts(node.attributes ?? []),\n };\n }\n if (node.type === \"SvelteElement\") {\n return {\n kind: \"dynamic-element\",\n tagName: node.name ?? node.type,\n start: node.start,\n end: node.end,\n ...targetAttributeFacts(node.attributes ?? []),\n };\n }\n if (\n node.type === \"SlotElement\" ||\n node.type === \"TitleElement\" ||\n node.type === \"SvelteBody\" ||\n node.type === \"SvelteBoundary\" ||\n node.type === \"SvelteDocument\" ||\n node.type === \"SvelteFragment\" ||\n node.type === \"SvelteHead\" ||\n node.type === \"SvelteSelf\" ||\n node.type === \"SvelteWindow\"\n ) {\n return {\n kind: \"special-element\",\n tagName: node.name ?? node.type,\n start: node.start,\n end: node.end,\n };\n }\n return null;\n}\n\nfunction targetAttributeFacts(\n attributes: readonly AST.AttributeLike[],\n): Pick<\n SvelteTargetInfo,\n | \"attributeNames\"\n | \"hasSpreadAttributes\"\n | \"directiveTypes\"\n | \"staticAttributes\"\n> {\n const staticAttributes: Record<string, string | true> = {};\n for (const attribute of attributes) {\n if (attribute.type !== \"Attribute\") continue;\n if (attribute.value === true) {\n staticAttributes[attribute.name] = true;\n continue;\n }\n if (\n Array.isArray(attribute.value) &&\n attribute.value.every((part) => part.type === \"Text\")\n ) {\n staticAttributes[attribute.name] = attribute.value\n .map((part) => (part as AST.Text).data)\n .join(\"\");\n }\n }\n return {\n attributeNames: attributes\n .filter(\n (attribute): attribute is AST.Attribute =>\n attribute.type === \"Attribute\",\n )\n .map((attribute) => attribute.name),\n hasSpreadAttributes: attributes.some(\n (attribute) => attribute.type === \"SpreadAttribute\",\n ),\n directiveTypes: attributes\n .filter(\n (attribute) =>\n attribute.type !== \"Attribute\" &&\n attribute.type !== \"SpreadAttribute\",\n )\n .map((attribute) => attribute.type),\n staticAttributes,\n };\n}\n\nconst PARSE_CACHE_LIMIT = 16;\nconst parseCache = new Map<string, InternalParseResult>();\n\nfunction rememberParse(key: string, result: InternalParseResult): void {\n parseCache.set(key, result);\n while (parseCache.size > PARSE_CACHE_LIMIT) {\n const oldest = parseCache.keys().next().value;\n if (oldest === undefined) break;\n parseCache.delete(oldest);\n }\n}\n\nexport function clearSvelteParseCacheForTests(): void {\n parseCache.clear();\n}\n\nfunction locateOpeningTagEnd(\n source: string,\n element: AST.RegularElement,\n):\n | { kind: \"ok\"; openingEnd: number; selfClosing: boolean }\n | { kind: \"invalid\"; message: string } {\n const lastAttribute = element.attributes[element.attributes.length - 1];\n const afterName = element.start + 1 + element.name.length;\n const cursor = lastAttribute?.end ?? afterName;\n const tail = source.slice(cursor, element.end);\n const closing = /^(\\s*)(\\/?)>/.exec(tail);\n /* v8 ignore next 6 -- invoked only for compiler-parsed RegularElements */\n if (!closing) {\n return {\n kind: \"invalid\",\n message: `could not locate the opening-tag terminator for <${element.name}> at UTF-16 offset ${element.start}`,\n };\n }\n return {\n kind: \"ok\",\n openingEnd: cursor + closing[0].length,\n selfClosing: closing[2] === \"/\",\n };\n}\n\nfunction locateClosingTagStart(\n source: string,\n element: AST.RegularElement,\n openingEnd: number,\n): number | null {\n const escapedName = element.name.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n const match = new RegExp(`</${escapedName}\\\\s*>$`).exec(\n source.slice(openingEnd, element.end),\n );\n return match ? openingEnd + match.index : null;\n}\n\nfunction containsDynamicSyntax(element: AST.RegularElement): boolean {\n let dynamic = false;\n walk(element as unknown as Parameters<typeof walk>[0], {\n enter(node) {\n const type = (node as { type?: unknown }).type;\n if (\n type === \"ExpressionTag\" ||\n type === \"HtmlTag\" ||\n type === \"RenderTag\" ||\n type === \"AttachTag\" ||\n type === \"ConstTag\" ||\n type === \"DeclarationTag\" ||\n type === \"DebugTag\" ||\n type === \"SpreadAttribute\" ||\n (typeof type === \"string\" && type.endsWith(\"Directive\")) ||\n type === \"Component\" ||\n type === \"SvelteComponent\" ||\n type === \"SvelteElement\" ||\n type === \"EachBlock\" ||\n type === \"IfBlock\" ||\n type === \"AwaitBlock\" ||\n type === \"KeyBlock\" ||\n type === \"SnippetBlock\"\n ) {\n dynamic = true;\n this.skip();\n }\n },\n });\n return dynamic;\n}\n\nfunction compilerError(\n error: unknown,\n): Extract<SvelteParseResult, { kind: \"invalid\" }> {\n if (error && typeof error === \"object\") {\n const value = error as { code?: unknown; message?: unknown };\n return {\n kind: \"invalid\",\n code: typeof value.code === \"string\" ? value.code : \"invalid_svelte\",\n message:\n typeof value.message === \"string\"\n ? value.message\n : /* v8 ignore next -- Svelte compiler diagnostics always carry messages */\n \"Svelte source could not be parsed\",\n };\n }\n /* v8 ignore next 5 -- Svelte compiler and parser throw diagnostic objects */\n return {\n kind: \"invalid\",\n code: \"invalid_svelte\",\n message: String(error),\n };\n}\n\nfunction toPublicElementInfo(element: InternalElementInfo): SvelteElementInfo {\n return {\n tagName: element.tagName,\n start: element.start,\n end: element.end,\n openingEnd: element.openingEnd,\n selfClosing: element.selfClosing,\n childrenStart: element.childrenStart,\n childrenEnd: element.childrenEnd,\n parentElementStart: element.parentElementStart,\n attributeNames: element.attributeNames,\n hasSpreadAttributes: element.hasSpreadAttributes,\n directiveTypes: element.directiveTypes,\n };\n}\n","import { sourceVersionHash } from \"@modules/annotation/source-version\";\nimport MagicString, { type SourceMap } from \"magic-string\";\nimport type { AST, PreprocessorGroup } from \"svelte/compiler\";\nimport { compile } from \"#svelte-compiler\";\nimport {\n applyStringEdits,\n mapOffsetThroughStringEdits,\n} from \"@modules/template-edits\";\nimport { escapeSvelteAttributeValue } from \"./escape\";\nimport { parseSvelteSourceInternal } from \"./parse\";\nimport type { StringEdit } from \"./types\";\n\nconst TEMPO_ATTRIBUTE_NAMES = [\n \"data-tempo-filepath\",\n \"data-tempo-position\",\n \"data-tempo-modifiedts\",\n \"data-tempo-source-version\",\n] as const;\nconst TEMPO_ATTRIBUTE_NAME_SET = new Set<string>(TEMPO_ATTRIBUTE_NAMES);\nexport const TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE =\n \"data-tempo-svelte-source-registry\";\n\nexport interface TempoSvelteComponentSourceRecord {\n readonly kind: \"component\";\n readonly name: string;\n /** Svelte dev metadata uses one-based lines and zero-based columns. */\n readonly line: number;\n readonly column: number;\n /** Exact UTF-16 offset in the annotation-free authored source. */\n readonly position: number;\n readonly className?: string;\n readonly style?: string;\n /** Literal author metadata on a component invocation, even when the\n * component does not forward it to a DOM host. */\n readonly locked?: boolean;\n /** Attributes written as expressions (`class={x}`, `class=\"a {b}\"`),\n * space separated as the canvas names them (`class` is `className`),\n * directives in their own spelling (`class:on`, `bind:value`),\n * `@attach`, and `#slot` when the element is a block's child (`{#each}`,\n * `{#if}`); the Svelte form of the JSX `data-tempo-expr` stamp. Empty\n * when a spread is the only one, absent when there is none. */\n readonly expressions?: string;\n readonly supportsClassName: boolean;\n readonly supportsStyle: boolean;\n}\n\nexport interface TempoSvelteHostSourceRecord {\n readonly kind: \"host\";\n readonly name: string;\n readonly line: number;\n readonly column: number;\n readonly position: number;\n readonly className?: string;\n readonly style?: string;\n /** Attributes written as expressions (`class={x}`, `class=\"a {b}\"`),\n * space separated as the canvas names them (`class` is `className`),\n * directives in their own spelling (`class:on`, `bind:value`),\n * `@attach`, and `#slot` when the element is a block's child (`{#each}`,\n * `{#if}`); the Svelte form of the JSX `data-tempo-expr` stamp. Empty\n * when a spread is the only one, absent when there is none. */\n readonly expressions?: string;\n readonly supportsClassName: boolean;\n readonly supportsStyle: boolean;\n}\n\nexport interface TempoSvelteSourceRegistryRecord {\n readonly filename: string;\n readonly filepath: string;\n readonly modifiedTs: number;\n readonly sourceVersion: string;\n readonly components: readonly TempoSvelteComponentSourceRecord[];\n readonly hosts: readonly TempoSvelteHostSourceRecord[];\n}\n\nexport interface AnnotateSvelteSourceOptions {\n source: string;\n filename: string;\n filepath: string;\n modifiedTs: number;\n sourceVersion?: string;\n /** `syntax` is for a first-in-chain preprocessor whose later stages validate. */\n validation?: \"compiler\" | \"syntax\";\n}\n\nexport type AnnotateSvelteSourceResult =\n | {\n kind: \"ok\";\n code: string;\n map: SourceMap;\n /** Insertion offsets in the annotated input passed to this call. */\n edits: readonly StringEdit[];\n elementsAnnotated: number;\n /** Recovered base-source offsets after existing annotations are removed. */\n skippedExistingAnnotations: readonly number[];\n sourceVersion: string;\n }\n | {\n kind: \"refused\";\n code:\n | \"invalid_source\"\n | \"invalid_output\"\n | \"invalid_metadata\"\n | \"annotation_conflict\";\n message: string;\n };\n\n/** Pure Svelte source annotation transform with exact original UTF-16 anchors. */\nexport function annotateSvelteSource(\n options: AnnotateSvelteSourceOptions,\n): AnnotateSvelteSourceResult {\n if (\n !options.filepath ||\n !options.filename ||\n !Number.isFinite(options.modifiedTs) ||\n !Number.isInteger(options.modifiedTs) ||\n options.modifiedTs < 0 ||\n options.sourceVersion === \"\"\n ) {\n return {\n kind: \"refused\",\n code: \"invalid_metadata\",\n message:\n \"filename, filepath, a non-negative integer modifiedTs, and a non-empty sourceVersion are required\",\n };\n }\n const inputSource = removeGeneratedSourceRegistries(options.source);\n const validation = options.validation ?? \"compiler\";\n const parsed = parseSvelteSourceInternal(\n inputSource,\n options.filename,\n validation,\n );\n if (parsed.kind === \"invalid\") {\n return { kind: \"refused\", code: \"invalid_source\", message: parsed.message };\n }\n\n const removalEdits: StringEdit[] = [];\n const existing = new Map<\n number,\n {\n filepath: string;\n position: number;\n modifiedTs: number;\n sourceVersion: string;\n }\n >();\n for (const element of parsed.elements.values()) {\n const tempoAttributes = element.node.attributes.filter(\n (attribute): attribute is AST.Attribute =>\n attribute.type === \"Attribute\" &&\n TEMPO_ATTRIBUTE_NAME_SET.has(attribute.name),\n );\n if (tempoAttributes.length === 0) continue;\n const conflict = readExistingAnnotation(inputSource, element.node);\n if (conflict.kind === \"refused\") return conflict;\n existing.set(element.start, conflict.metadata);\n removalEdits.push(conflict.removalEdit);\n }\n\n const baseSource = applyStringEdits(inputSource, removalEdits);\n const baseParsed = parseSvelteSourceInternal(\n baseSource,\n options.filename,\n validation,\n );\n /* v8 ignore next 6 -- exact generated-annotation removal from parsed input cannot invalidate syntax */\n if (baseParsed.kind === \"invalid\") {\n return {\n kind: \"refused\",\n code: \"annotation_conflict\",\n message:\n \"removing existing Tempo annotations did not recover valid source\",\n };\n }\n const version = options.sourceVersion ?? sourceVersionHash(baseSource);\n for (const [currentOffset, metadata] of existing) {\n const baseOffset = mapOffsetThroughStringEdits(currentOffset, removalEdits);\n if (\n baseOffset === null ||\n !baseParsed.elements.has(baseOffset) ||\n metadata.filepath !== options.filepath ||\n metadata.position !== baseOffset ||\n metadata.modifiedTs !== options.modifiedTs ||\n metadata.sourceVersion !== version\n ) {\n return {\n kind: \"refused\",\n code: \"annotation_conflict\",\n message: `existing Tempo annotations at UTF-16 offset ${currentOffset} do not exactly match the recovered source identity`,\n };\n }\n }\n\n const edits: StringEdit[] = [];\n const skippedExistingAnnotations: number[] = [];\n for (const element of parsed.elements.values()) {\n const baseOffset = mapOffsetThroughStringEdits(element.start, removalEdits);\n /* v8 ignore next 6 -- validated non-overlapping annotation removals preserve opening anchors */\n if (baseOffset === null || !baseParsed.elements.has(baseOffset)) {\n return {\n kind: \"refused\",\n code: \"annotation_conflict\",\n message: `could not map element at UTF-16 offset ${element.start} to recovered source`,\n };\n }\n if (existing.has(element.start)) {\n skippedExistingAnnotations.push(baseOffset);\n continue;\n }\n const insertionOffset =\n element.node.attributes[element.node.attributes.length - 1]?.end ??\n element.start + 1 + element.tagName.length;\n edits.push({\n start: insertionOffset,\n end: insertionOffset,\n replacement: serializeAnnotations({\n filepath: options.filepath,\n position: baseOffset,\n modifiedTs: options.modifiedTs,\n sourceVersion: version,\n }),\n });\n }\n\n // A comment marks the start of this invocation's roots without affecting\n // element selectors. @html keeps it present even with preserveComments off.\n const startEdit: StringEdit = {\n start: 0,\n end: 0,\n replacement: `{@html '<!--${TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE}-->'}`,\n };\n const annotationEdits = [startEdit, ...edits];\n const annotatedCode = applyStringEdits(inputSource, annotationEdits);\n const sourceRecords = buildSourceRecords({\n source: inputSource,\n parsed,\n removalEdits,\n annotationEdits,\n annotatedCode,\n });\n const registry: TempoSvelteSourceRegistryRecord = {\n filename: options.filename,\n filepath: options.filepath,\n modifiedTs: options.modifiedTs,\n sourceVersion: version,\n components: sourceRecords.components,\n hosts: sourceRecords.hosts,\n };\n const registryEdit: StringEdit = {\n start: inputSource.length,\n end: inputSource.length,\n replacement: `\\n<template ${TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE}=\"${escapeSvelteAttributeValue(JSON.stringify(registry), '\"')}\"></template>\\n`,\n };\n const transformEdits = [...annotationEdits, registryEdit];\n const code = applyStringEdits(inputSource, transformEdits);\n try {\n if (validation === \"compiler\") {\n compile(code, { filename: options.filename, generate: false });\n } else {\n const parsedOutput = parseSvelteSourceInternal(\n code,\n options.filename,\n \"syntax\",\n );\n if (parsedOutput.kind === \"invalid\")\n throw new Error(parsedOutput.message);\n }\n /* v8 ignore next 6 -- static attributes inserted into compiler-validated RegularElements are syntax-preserving */\n } catch (error) {\n return {\n kind: \"refused\",\n code: \"invalid_output\",\n message: error instanceof Error ? error.message : String(error),\n };\n }\n\n const magic = new MagicString(inputSource);\n for (const edit of transformEdits) {\n magic.appendLeft(edit.start, edit.replacement);\n }\n /* v8 ignore next 6 -- both outputs consume the same insertion-only edit list */\n if (magic.toString() !== code) {\n return {\n kind: \"refused\",\n code: \"invalid_output\",\n message: \"annotation code and source-map transform outputs diverged\",\n };\n }\n return {\n kind: \"ok\",\n code,\n map: magic.generateMap({\n source: options.filename,\n includeContent: true,\n hires: true,\n }),\n edits,\n elementsAnnotated: edits.length,\n skippedExistingAnnotations,\n sourceVersion: version,\n };\n}\n\nfunction removeGeneratedSourceRegistries(source: string): string {\n const escaped = TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE.replace(\n /[.*+?^${}()|[\\]\\\\]/g,\n \"\\\\$&\",\n );\n return source\n .replace(`{@html '<!--${TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE}-->'}`, \"\")\n .replace(\n new RegExp(\n `\\\\n?<template\\\\s+${escaped}=(?:\"[^\"]*\"|'[^']*')\\\\s*><\\\\/template>\\\\n?`,\n \"g\",\n ),\n \"\",\n );\n}\n\nfunction buildSourceRecords(options: {\n source: string;\n parsed: Extract<ReturnType<typeof parseSvelteSourceInternal>, { kind: \"ok\" }>;\n removalEdits: readonly StringEdit[];\n annotationEdits: readonly StringEdit[];\n annotatedCode: string;\n}): {\n components: TempoSvelteComponentSourceRecord[];\n hosts: TempoSvelteHostSourceRecord[];\n} {\n const components: TempoSvelteComponentSourceRecord[] = [];\n const hosts: TempoSvelteHostSourceRecord[] = [];\n for (const target of options.parsed.targets.values()) {\n if (\n target.kind !== \"component\" &&\n target.kind !== \"native-element\" &&\n target.kind !== \"dynamic-element\"\n ) {\n continue;\n }\n const position = mapOffsetThroughStringEdits(\n target.start,\n options.removalEdits,\n );\n if (position === null) continue;\n const compiledOffset = mapOffsetForward(\n target.start,\n options.annotationEdits,\n );\n const location = sourceLocationAt(options.annotatedCode, compiledOffset);\n const classValue = target.staticAttributes?.class;\n const styleValue = target.staticAttributes?.style;\n const lockValue = target.staticAttributes?.[\"data-tempo-locked\"];\n const hasSpread = target.hasSpreadAttributes === true;\n const directives = new Set(target.directiveTypes ?? []);\n const attributes = new Set(target.attributeNames ?? []);\n // A block child's own slot is dynamic, as a JSX `.map` root or\n // conditional branch is (`#slot`, user decision 2026-09-25: Svelte\n // follows the JSX rule). A written attribute with no literal value is\n // an expression.\n const blockChild = /Block$/.test(target.parentFragmentOwnerType ?? \"\");\n const node = options.parsed.targetNodes.get(target.start);\n // A directive or an attachment is written in the source and may show\n // nothing on the page (`class:on` while off): the canvas cannot learn\n // it from the DOM, so it is a fact here, in its own spelling.\n const directiveFacts = (node?.attributes ?? []).flatMap((attribute) => {\n if (\n attribute.type === \"Attribute\" ||\n attribute.type === \"SpreadAttribute\"\n )\n return [];\n // Svelte's AttributeLike type leaves out `{@attach}`, which the parser\n // still lists among the attributes.\n if ((attribute.type as string) === \"AttachTag\") return [\"@attach\"];\n const written = options.source.slice(attribute.start, attribute.end);\n return [written.split(\"=\")[0]!.trim()];\n });\n const expressions = [\n ...(blockChild ? [\"#slot\"] : []),\n ...[...attributes]\n .filter((name) => target.staticAttributes?.[name] === undefined)\n .map((name) => (name === \"class\" ? \"className\" : name)),\n ...directiveFacts,\n ].join(\" \");\n const common = {\n name: target.tagName,\n line: location.line,\n column: location.column,\n position,\n ...(typeof classValue === \"string\" ? { className: classValue } : {}),\n ...(typeof styleValue === \"string\" ? { style: styleValue } : {}),\n ...(lockValue === true || lockValue === \"true\" || lockValue === \"\"\n ? { locked: true }\n : lockValue === \"false\"\n ? { locked: false }\n : {}),\n // A spread gets a stamp even with no fact, as JSX's does.\n ...(expressions || hasSpread ? { expressions } : {}),\n supportsClassName:\n !hasSpread &&\n !directives.has(\"ClassDirective\") &&\n (!attributes.has(\"class\") || typeof classValue === \"string\"),\n supportsStyle:\n !hasSpread &&\n !directives.has(\"StyleDirective\") &&\n (!attributes.has(\"style\") || typeof styleValue === \"string\"),\n } as const;\n if (target.kind === \"component\") {\n components.push({ kind: \"component\", ...common });\n } else {\n hosts.push({ kind: \"host\", ...common });\n }\n }\n return { components, hosts };\n}\n\nfunction mapOffsetForward(\n offset: number,\n edits: readonly StringEdit[],\n): number {\n let mapped = offset;\n for (const edit of edits) {\n if (edit.start > offset) continue;\n mapped += edit.replacement.length - (edit.end - edit.start);\n }\n return mapped;\n}\n\nfunction sourceLocationAt(\n source: string,\n offset: number,\n): { line: number; column: number } {\n const before = source.slice(0, offset);\n const lines = before.split(\"\\n\");\n return {\n line: lines.length,\n column: lines[lines.length - 1]?.length ?? 0,\n };\n}\n\nexport interface CreateSvelteAnnotationPreprocessorOptions {\n metadata(input: { filename: string | undefined; source: string }): {\n filepath: string;\n modifiedTs: number;\n sourceVersion?: string;\n } | null;\n}\n\n/**\n * Create a Svelte markup preprocessor for raw-source annotations. It must be\n * first in the caller's preprocessor array so stored offsets identify the\n * authored file rather than another preprocessor's generated source.\n */\nexport function createSvelteAnnotationPreprocessor(\n options: CreateSvelteAnnotationPreprocessorOptions,\n): PreprocessorGroup {\n return {\n name: \"svelte-source-annotation\",\n markup: ({ content, filename }) => {\n const metadata = options.metadata({ filename, source: content });\n if (metadata === null) return undefined;\n const result = annotateSvelteSource({\n source: content,\n filename: filename ?? metadata.filepath,\n ...metadata,\n validation: \"syntax\",\n });\n if (result.kind === \"refused\") {\n throw new Error(`${result.code}: ${result.message}`);\n }\n return { code: result.code, map: result.map };\n },\n };\n}\n\ntype ExistingAnnotationRead =\n | {\n kind: \"ok\";\n metadata: {\n filepath: string;\n position: number;\n modifiedTs: number;\n sourceVersion: string;\n };\n removalEdit: StringEdit;\n }\n | Extract<AnnotateSvelteSourceResult, { kind: \"refused\" }>;\n\nfunction readExistingAnnotation(\n source: string,\n element: AST.RegularElement,\n): ExistingAnnotationRead {\n const attributes = element.attributes.filter(\n (attribute): attribute is AST.Attribute => attribute.type === \"Attribute\",\n );\n const tempo = attributes.filter((attribute) =>\n TEMPO_ATTRIBUTE_NAME_SET.has(attribute.name),\n );\n const names = tempo.map((attribute) => attribute.name);\n if (\n tempo.length !== TEMPO_ATTRIBUTE_NAMES.length ||\n TEMPO_ATTRIBUTE_NAMES.some((name, index) => names[index] !== name) ||\n attributes\n .slice(-TEMPO_ATTRIBUTE_NAMES.length)\n .some((attribute, index) => attribute !== tempo[index]) ||\n tempo.some((attribute) => !isStaticLiteralAttribute(attribute))\n ) {\n return annotationConflict(element.start);\n }\n const [\n filepathAttribute,\n positionAttribute,\n modifiedAttribute,\n versionAttribute,\n ] = tempo;\n /* v8 ignore next 7 -- the length and ordered-name checks above prove all tuple members exist */\n if (\n !filepathAttribute ||\n !positionAttribute ||\n !modifiedAttribute ||\n !versionAttribute\n ) {\n return annotationConflict(element.start);\n }\n const filepath = staticLiteralAttributeValue(filepathAttribute);\n const positionText = staticLiteralAttributeValue(positionAttribute);\n const modifiedText = staticLiteralAttributeValue(modifiedAttribute);\n const sourceVersion = staticLiteralAttributeValue(versionAttribute);\n const position = Number(positionText);\n const modifiedTs = Number(modifiedText);\n const first = tempo[0];\n const last = tempo[tempo.length - 1];\n if (\n !first ||\n !last ||\n source[first.start - 1] !== \" \" ||\n !Number.isSafeInteger(position) ||\n position < 0 ||\n !Number.isSafeInteger(modifiedTs) ||\n modifiedTs < 0 ||\n !filepath ||\n !sourceVersion\n ) {\n return annotationConflict(element.start);\n }\n const expected = serializeAnnotations({\n filepath,\n position,\n modifiedTs,\n sourceVersion,\n }).slice(1);\n if (source.slice(first.start, last.end) !== expected) {\n return annotationConflict(element.start);\n }\n return {\n kind: \"ok\",\n metadata: { filepath, position, modifiedTs, sourceVersion },\n removalEdit: {\n start: first.start - 1,\n end: last.end,\n replacement: \"\",\n },\n };\n}\n\nfunction annotationConflict(\n offset: number,\n): Extract<AnnotateSvelteSourceResult, { kind: \"refused\" }> {\n return {\n kind: \"refused\",\n code: \"annotation_conflict\",\n message: `element at UTF-16 offset ${offset} has partial, dynamic, reordered, or conflicting Tempo annotations`,\n };\n}\n\nfunction isStaticLiteralAttribute(attribute: AST.Attribute): boolean {\n return (\n Array.isArray(attribute.value) &&\n attribute.value.every((part) => part.type === \"Text\")\n );\n}\n\nfunction staticLiteralAttributeValue(attribute: AST.Attribute): string {\n /* v8 ignore next -- callers first prove the attribute is a static Text array */\n return Array.isArray(attribute.value)\n ? attribute.value\n .map((part) => (part.type === \"Text\" ? part.data : \"\"))\n .join(\"\")\n : \"\";\n}\n\nfunction serializeAnnotations(metadata: {\n filepath: string;\n position: number;\n modifiedTs: number;\n sourceVersion: string;\n}): string {\n const values = {\n \"data-tempo-filepath\": metadata.filepath,\n \"data-tempo-position\": String(metadata.position),\n \"data-tempo-modifiedts\": String(metadata.modifiedTs),\n \"data-tempo-source-version\": metadata.sourceVersion,\n };\n return Object.entries(values)\n .map(\n ([name, value]) => ` ${name}=\"${escapeSvelteAttributeValue(value, '\"')}\"`,\n )\n .join(\"\");\n}\n","import { CssUrlError, rebaseCssUrls } from \"@modules/template-edits/css-urls\";\nimport { type AST, parse } from \"svelte/compiler\";\nimport type {\n SvelteImportUse,\n PlanSvelteMarkupTransferOptions,\n StringEdit,\n SvelteEditRefusalCode,\n SvelteMarkupTransferPlan,\n} from \"./types\";\n\n/** An ESTree node as the Svelte parser gives it (acorn, with positions). */\ntype Node = {\n type: string;\n start: number;\n end: number;\n [key: string]: unknown;\n};\n\nclass TransferRefusal extends Error {\n readonly code: SvelteEditRefusalCode;\n constructor(code: SvelteEditRefusalCode, message: string) {\n super(message);\n this.code = code;\n }\n}\n\nconst refuse = (code: SvelteEditRefusalCode, message: string): never => {\n throw new TransferRefusal(code, message);\n};\n\n/** Instance values Svelte gives every component: moved into another one\n * they read that one's. */\nconst INSTANCE_NAMES = new Set([\n \"$$props\",\n \"$$restProps\",\n \"$$slots\",\n \"$$events\",\n]);\n\n/**\n * Plan carrying one authored element of a Svelte component into another\n * component file, refusal-first: the markup unchanged, plus the\n * destination edits that give it what it reads. An instance- or\n * module-script import the markup reads (a component, an action, a\n * transition, a store behind `$name`) is carried, rebased; a literal\n * `const` is carried as written; the source's `<style>` comes along,\n * because its selectors may match the moved elements. Anything the markup\n * reads from its component's own state (props, `let` state, functions, an\n * enclosing block's bindings, a snippet, `<slot>`) refuses: moved, it\n * would read another component's. Where the destination's enclosing block,\n * snippet or `let:` binds a name the markup reads, a carried declaration\n * takes a fresh name and anything else refuses. Removing the element from\n * the source is the caller's.\n *\n * Unlike `planSvelteTransfer`, which places scope-free markup through the\n * target's own planner, this plans dependencies and leaves placement to the\n * caller. Svelte markup URLs are page-relative, so none is rebased.\n */\nexport function planSvelteMarkupTransfer(\n options: PlanSvelteMarkupTransferOptions,\n): SvelteMarkupTransferPlan {\n try {\n return transfer(options);\n } catch (error) {\n if (error instanceof TransferRefusal)\n return { kind: \"refused\", code: error.code, message: error.message };\n throw error;\n }\n}\n\nfunction transfer(\n options: PlanSvelteMarkupTransferOptions,\n): SvelteMarkupTransferPlan {\n const from = readComponent(options.source, options.sourceFile);\n const into = readComponent(options.destination, options.destinationFile);\n const element = elementAt(from.root.fragment, options.start);\n if (!element)\n return refuse(\n \"invalid_anchor\",\n `no Svelte element starts at UTF-16 offset ${options.start}`,\n );\n if (element.type === \"SvelteSelf\")\n refuse(\n \"scope_change\",\n \"<svelte:self> renders its own component; moving it requires AI\",\n );\n\n const uses = emptyUses(options.source);\n visitTemplate(element, new Set(), uses);\n const enclosing = new Set<string>();\n declaredInTemplate(from.root.fragment as unknown as Node, element, enclosing);\n for (const name of uses.names.keys())\n if (enclosing.has(name))\n refuse(\n \"scope_change\",\n `The markup reads ${name} from its template's blocks or snippets; moving it requires AI`,\n );\n if (uses.slots)\n refuse(\n \"scope_change\",\n \"The markup renders its component's <slot>; moving it requires AI\",\n );\n\n const declarations = resolveDependencies(from, uses, options);\n const shadowing = destinationScope(into, options);\n const carried = new Set(declarations.map((declaration) => declaration.local));\n for (const used of uses.names.keys()) {\n // `$name` reads the store `name` holds.\n const name = used.startsWith(\"$\") && used.length > 1 ? used.slice(1) : used;\n if (\n !carried.has(name) &&\n into.scripts.some((script) => script.declared.has(name))\n )\n refuse(\n \"scope_change\",\n `The destination's script defines ${name}, which the markup reads globally; moving it requires AI`,\n );\n if (shadowing.has(name) && !carried.has(name))\n refuse(\n \"scope_change\",\n `A block, snippet or let: directive at the destination binds ${name}, which the markup reads; moving it requires AI`,\n );\n }\n const declared = declareInDestination(\n from,\n into,\n declarations,\n shadowing,\n new Set(uses.names.keys()),\n );\n const markupEdits = respell(declarations, declared.renames, element.start);\n const authored = options.source.slice(element.start, element.end);\n return {\n kind: \"planned\",\n markup: applyEdits(authored, markupEdits),\n markupEdits,\n end: element.end,\n destinationEdits: joinInsertions([\n ...declared.edits,\n ...carryStyle(from, into, options),\n ]),\n };\n}\n\n/** The names the destination's template binds where the markup lands,\n * which would shadow a name the markup reads: moved under\n * `{#each labels as label}`, markup that read a carried `label` const\n * would read the loop variable. A new board's content slot has no parent\n * and no enclosing scope. */\nfunction destinationScope(\n into: ComponentRead,\n options: PlanSvelteMarkupTransferOptions,\n): Set<string> {\n const offset = options.destinationParentOffset;\n if (offset === undefined) return new Set();\n const scope = scopeAt(into.root.fragment, offset);\n if (!scope)\n return refuse(\n \"invalid_anchor\",\n `no Svelte element starts at UTF-16 offset ${offset} of ${options.destinationFile}`,\n );\n return scope;\n}\n\n/** Edits, in the moved element's coordinates, that spell each renamed\n * declaration's new name where the markup wrote the old one. */\nfunction respell(\n declarations: readonly Declaration[],\n renames: ReadonlyMap<string, string>,\n base: number,\n): StringEdit[] {\n return declarations.flatMap((declaration) => {\n const local = renames.get(declaration.local);\n if (local === undefined) return [];\n return declaration.occurrences.map(({ start, end, written, as }) => {\n // `$store` subscribes to the renamed store.\n const read = written.startsWith(\"$\") ? `$${local}` : local;\n const replacement =\n as === \"shorthand\"\n ? `${written}: ${read}`\n : as === \"attribute\"\n ? `${written.slice(1, -1).trim()}={${read}}`\n : as === \"directive-shorthand\"\n ? `${written}={${read}}`\n : read;\n return { start: start - base, end: end - base, replacement };\n });\n });\n}\n\n/** Simultaneous edits applied tail first. */\nfunction applyEdits(text: string, edits: readonly StringEdit[]): string {\n let result = text;\n for (const edit of [...edits].sort((a, b) => b.start - a.start))\n result =\n result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);\n return result;\n}\n\n/** Simultaneous insertions at one offset have no order of their own; an\n * empty destination gains its script and its style at offset 0, so they\n * are joined into one edit in the order listed. */\nfunction joinInsertions(edits: readonly StringEdit[]): StringEdit[] {\n const joined: StringEdit[] = [];\n for (const edit of edits) {\n const same = joined.find(\n (other) =>\n other.start === other.end &&\n edit.start === edit.end &&\n other.start === edit.start,\n );\n if (same) same.replacement += edit.replacement;\n else joined.push({ ...edit });\n }\n return joined;\n}\n\n// ---------------------------------------------------------------------------\n// Reading a component\n\ninterface ScriptRead {\n imports: { local: string; source: string; imported: string }[];\n /** Top-level `const name = <literal>`, the literal as written. */\n literals: Map<string, string>;\n /** Every name the block declares at its top level. */\n declared: Set<string>;\n}\n\ninterface ComponentRead {\n source: string;\n root: AST.Root;\n scripts: ScriptRead[];\n}\n\nfunction readComponent(source: string, filename: string): ComponentRead {\n let root: AST.Root;\n try {\n root = parse(source, { filename, modern: true });\n } catch (error) {\n return refuse(\n \"invalid_source\",\n error instanceof Error ? error.message : String(error),\n );\n }\n const scripts = [root.instance, root.module].flatMap((script) =>\n script ? [readScript(script.content as unknown as Node, source)] : [],\n );\n return { source, root, scripts };\n}\n\nfunction readScript(program: Node, source: string): ScriptRead {\n const read: ScriptRead = {\n imports: [],\n literals: new Map(),\n declared: new Set(),\n };\n for (const statement of program.body as Node[]) {\n if (statement.type === \"ImportDeclaration\") {\n const typeOnly = statement.importKind === \"type\";\n for (const specifier of statement.specifiers as Node[]) {\n const local = (specifier.local as Node).name as string;\n read.declared.add(local);\n if (typeOnly || specifier.importKind === \"type\") continue;\n const imported = specifier.imported as Node | undefined;\n read.imports.push({\n local,\n source: (statement.source as Node).value as string,\n imported:\n specifier.type === \"ImportDefaultSpecifier\"\n ? \"default\"\n : specifier.type === \"ImportNamespaceSpecifier\"\n ? \"*\"\n : ((imported?.name ?? imported?.value) as string),\n });\n }\n continue;\n }\n // `$: name = …` declares `name` (Svelte 4 reactive declarations).\n if (statement.type === \"LabeledStatement\") {\n const body = statement.body as Node;\n const assignment = body.expression as Node | undefined;\n const left = assignment?.left as Node | undefined;\n if (assignment?.type === \"AssignmentExpression\" && left)\n for (const name of patternNames(left)) read.declared.add(name);\n continue;\n }\n const declaration =\n statement.type === \"ExportNamedDeclaration\" ||\n statement.type === \"ExportDefaultDeclaration\"\n ? (statement.declaration as Node | null)\n : statement;\n if (!declaration) continue;\n if (declaration.type === \"VariableDeclaration\") {\n for (const declarator of declaration.declarations as Node[]) {\n const id = declarator.id as Node;\n for (const name of patternNames(id)) read.declared.add(name);\n const init = declarator.init as Node | null;\n if (\n declaration.kind === \"const\" &&\n id.type === \"Identifier\" &&\n init &&\n isLiteral(init)\n )\n read.literals.set(\n id.name as string,\n source.slice(init.start, init.end),\n );\n }\n continue;\n }\n const id = declaration.id as Node | undefined;\n if (id?.type === \"Identifier\") read.declared.add(id.name as string);\n }\n return read;\n}\n\n/** A value that means the same written anywhere: no name it reads. */\nfunction isLiteral(node: Node): boolean {\n switch (node.type) {\n case \"Literal\":\n return node.regex === undefined && node.bigint === undefined;\n case \"TemplateLiteral\":\n return (node.expressions as Node[]).length === 0;\n case \"UnaryExpression\":\n return (\n node.operator === \"-\" &&\n (node.argument as Node).type === \"Literal\" &&\n typeof (node.argument as Node).value === \"number\"\n );\n case \"ArrayExpression\":\n return (node.elements as (Node | null)[]).every(\n (element) => element !== null && isLiteral(element),\n );\n case \"ObjectExpression\":\n return (node.properties as Node[]).every(\n (property) =>\n property.type === \"Property\" &&\n property.kind === \"init\" &&\n !property.computed &&\n !property.method &&\n isLiteral(property.value as Node),\n );\n default:\n return false;\n }\n}\n\n/** The names a binding pattern declares. A `let:` directive's pattern\n * arrives parsed as an expression, so the expression spellings of each\n * pattern bind too. */\nfunction patternNames(pattern: Node | null | undefined): string[] {\n if (!pattern) return [];\n switch (pattern.type) {\n case \"Identifier\":\n return [pattern.name as string];\n case \"ObjectPattern\":\n case \"ObjectExpression\":\n return (pattern.properties as Node[]).flatMap((property) =>\n patternNames(\n property.type === \"RestElement\" || property.type === \"SpreadElement\"\n ? (property.argument as Node)\n : (property.value as Node),\n ),\n );\n case \"ArrayPattern\":\n case \"ArrayExpression\":\n return (pattern.elements as (Node | null)[]).flatMap(patternNames);\n case \"AssignmentPattern\":\n case \"AssignmentExpression\":\n return patternNames(pattern.left as Node);\n case \"RestElement\":\n case \"SpreadElement\":\n return patternNames(pattern.argument as Node);\n default:\n return [];\n }\n}\n\n/** The element-like template node whose `<` is at `start`. */\nfunction elementAt(fragment: AST.Fragment, start: number): Node | null {\n let found: Node | null = null;\n const visit = (value: unknown) => {\n if (found || !value || typeof value !== \"object\") return;\n if (Array.isArray(value)) {\n for (const item of value) visit(item);\n return;\n }\n const node = value as Node;\n const elementLike =\n typeof node.type === \"string\" &&\n \"attributes\" in node &&\n \"fragment\" in node;\n if (elementLike && node.start === start) {\n found = node;\n return;\n }\n for (const [key, child] of Object.entries(node))\n if (key !== \"metadata\" && key !== \"parent\") visit(child);\n };\n visit(fragment);\n return found;\n}\n\n// ---------------------------------------------------------------------------\n// What the markup reads\n\n/** Where the markup writes a name it reads, and how, so a renamed\n * declaration can be spelled there exactly: `written` is the text at\n * `[start, end)` for identifiers (`fmt`, `$store`) and shorthand properties\n * (`{ fmt }`); a shorthand attribute (`{icon}`) or directive (`class:on`,\n * `bind:value`, `style:color`) covers the whole attribute, `written` its\n * text; a tag or directive name covers the name alone. */\ninterface Occurrence {\n start: number;\n end: number;\n written: string;\n as:\n | \"identifier\"\n | \"shorthand\"\n | \"attribute\"\n | \"directive-shorthand\"\n | \"tag\"\n | \"directive\";\n}\n\ninterface TemplateUses {\n /** The source the occurrences index. */\n source: string;\n /** Names its expressions, tags and directives read from outside. */\n names: Map<string, Occurrence[]>;\n slots: boolean;\n}\n\nconst emptyUses = (source: string): TemplateUses => ({\n source,\n names: new Map(),\n slots: false,\n});\n\nfunction note(uses: TemplateUses, name: string, occurrence: Occurrence) {\n uses.names.set(name, [...(uses.names.get(name) ?? []), occurrence]);\n}\n\n/** Every name a template node and its subtree read from the component, in\n * `scope` (names the moved markup binds itself: block contexts, `let:`,\n * snippet parameters, `{@const}`, snippets). */\nfunction visitTemplate(\n node: Node,\n scope: ReadonlySet<string>,\n uses: TemplateUses,\n): void {\n const read = (expression: unknown, inner = scope) => {\n if (expression && typeof expression === \"object\")\n readExpression(expression as Node, inner, uses);\n };\n const fragment = (value: unknown, inner: ReadonlySet<string>) => {\n if (!value) return;\n // Snippets and `{@const}` are visible across their whole fragment.\n const nodes = (value as { nodes: Node[] }).nodes;\n const local = new Set(inner);\n for (const child of nodes) {\n if (child.type === \"SnippetBlock\")\n local.add((child.expression as Node).name as string);\n if (child.type === \"ConstTag\")\n for (const declarator of (child.declaration as Node)\n .declarations as Node[])\n for (const name of patternNames(declarator.id as Node))\n local.add(name);\n }\n for (const child of nodes) visitTemplate(child, local, uses);\n };\n switch (node.type) {\n case \"Text\":\n case \"Comment\":\n return;\n case \"ExpressionTag\":\n case \"HtmlTag\":\n case \"RenderTag\":\n case \"AttachTag\":\n read(node.expression);\n return;\n case \"DebugTag\":\n for (const identifier of node.identifiers as Node[]) read(identifier);\n return;\n case \"ConstTag\":\n for (const declarator of (node.declaration as Node)\n .declarations as Node[])\n read(declarator.init);\n return;\n case \"IfBlock\":\n read(node.test);\n fragment(node.consequent, scope);\n fragment(node.alternate, scope);\n return;\n case \"EachBlock\": {\n read(node.expression);\n const inner = new Set([\n ...scope,\n ...patternNames(node.context as Node | null),\n ...(typeof node.index === \"string\" ? [node.index] : []),\n ]);\n read(node.key, inner);\n fragment(node.body, inner);\n fragment(node.fallback, scope);\n return;\n }\n case \"AwaitBlock\":\n read(node.expression);\n fragment(node.pending, scope);\n fragment(\n node.then,\n new Set([...scope, ...patternNames(node.value as Node | null)]),\n );\n fragment(\n node.catch,\n new Set([...scope, ...patternNames(node.error as Node | null)]),\n );\n return;\n case \"KeyBlock\":\n read(node.expression);\n fragment(node.fragment, scope);\n return;\n case \"SnippetBlock\": {\n const parameters = node.parameters as Node[];\n const inner = new Set([...scope, ...parameters.flatMap(patternNames)]);\n for (const parameter of parameters) read(parameter, inner);\n fragment(node.body, inner);\n return;\n }\n }\n if (!(\"attributes\" in node)) return;\n // An element-like node: its tag, its attributes, its content.\n if (node.type === \"SlotElement\") uses.slots = true;\n if (node.type === \"Component\") {\n const name = (node.name as string).split(\".\")[0]!;\n const tag = { written: name, as: \"tag\" as const };\n note(uses, name, {\n ...tag,\n start: node.start + 1,\n end: node.start + 1 + name.length,\n });\n const own = uses.source.slice(node.start, node.end);\n const closing = own.lastIndexOf(\"</\");\n if (closing > 0 && own.startsWith(name, closing + 2))\n note(uses, name, {\n ...tag,\n start: node.start + closing + 2,\n end: node.start + closing + 2 + name.length,\n });\n }\n if (node.type === \"SvelteElement\") read(node.tag);\n if (node.type === \"SvelteComponent\") read(node.expression);\n let inner = scope;\n for (const attribute of node.attributes as Node[]) {\n if (attribute.type === \"LetDirective\") {\n const names = attribute.expression\n ? patternNames(attribute.expression as Node)\n : [attribute.name as string];\n inner = new Set([...inner, ...names]);\n }\n }\n for (const attribute of node.attributes as Node[]) {\n const text = uses.source.slice(attribute.start, attribute.end);\n const whole = { start: attribute.start, end: attribute.end, written: text };\n const expression = attribute.expression as Node | null | undefined;\n switch (attribute.type) {\n case \"LetDirective\":\n continue;\n case \"StyleDirective\":\n // `style:color` alone reads `color`.\n if (attribute.value === true) {\n const name = attribute.name as string;\n if (!inner.has(name))\n note(uses, name, { ...whole, as: \"directive-shorthand\" });\n continue;\n }\n // falls through: a valued style directive reads its value's parts.\n case \"Attribute\": {\n const value = attribute.value;\n // `{icon}` is `icon={icon}`.\n const shorthand =\n text.startsWith(\"{\") &&\n !Array.isArray(value) &&\n (value as Node | null)?.type === \"ExpressionTag\" &&\n ((value as Node).expression as Node).type === \"Identifier\";\n if (shorthand) {\n const name = ((value as Node).expression as Node).name as string;\n if (!inner.has(name)) note(uses, name, { ...whole, as: \"attribute\" });\n continue;\n }\n for (const part of Array.isArray(value) ? value : [value])\n if (part && typeof part === \"object\" && part.type === \"ExpressionTag\")\n read(part.expression, inner);\n continue;\n }\n case \"UseDirective\":\n case \"TransitionDirective\":\n case \"AnimateDirective\": {\n const name = (attribute.name as string).split(\".\")[0]!;\n const start = attribute.start + text.indexOf(\":\") + 1;\n note(uses, name, {\n start,\n end: start + name.length,\n written: name,\n as: \"directive\",\n });\n read(expression, inner);\n continue;\n }\n default: {\n // `class:on` and `bind:value` alone read their own name.\n const shorthand =\n expression?.type === \"Identifier\" && !text.includes(\"=\");\n if (shorthand) {\n const name = expression.name as string;\n if (!inner.has(name))\n note(uses, name, { ...whole, as: \"directive-shorthand\" });\n continue;\n }\n read(expression, inner);\n }\n }\n }\n fragment(node.fragment, inner);\n}\n\n/** The free names of a JavaScript expression: every identifier it reads\n * that neither `scope` nor a function, block or catch clause inside it\n * binds. */\nfunction readExpression(\n root: Node,\n scope: ReadonlySet<string>,\n uses: TemplateUses,\n): void {\n const visit = (node: Node, bound: ReadonlySet<string>): void => {\n switch (node.type) {\n case \"Identifier\": {\n const name = node.name as string;\n if (!bound.has(name))\n note(uses, name, {\n start: node.start,\n end: node.end,\n written: name,\n as: \"identifier\",\n });\n return;\n }\n case \"MemberExpression\":\n visit(node.object as Node, bound);\n if (node.computed) visit(node.property as Node, bound);\n return;\n case \"Property\": {\n // `{ fmt }` is `{ fmt: fmt }`: a rename keeps the key.\n const value = node.value as Node;\n if (node.shorthand && value.type === \"Identifier\") {\n const name = value.name as string;\n if (!bound.has(name))\n note(uses, name, {\n start: value.start,\n end: value.end,\n written: name,\n as: \"shorthand\",\n });\n return;\n }\n if (node.computed) visit(node.key as Node, bound);\n visit(value, bound);\n return;\n }\n case \"PropertyDefinition\":\n case \"MethodDefinition\":\n if (node.computed) visit(node.key as Node, bound);\n if (node.value) visit(node.value as Node, bound);\n return;\n case \"LabeledStatement\":\n visit(node.body as Node, bound);\n return;\n case \"BreakStatement\":\n case \"ContinueStatement\":\n case \"MetaProperty\":\n return;\n case \"FunctionExpression\":\n case \"FunctionDeclaration\":\n case \"ArrowFunctionExpression\": {\n const params = node.params as Node[];\n const inner = new Set([\n ...bound,\n ...params.flatMap(patternNames),\n ...(node.id ? patternNames(node.id as Node) : []),\n ]);\n for (const param of params) visitPatternDefaults(param, inner);\n visit(node.body as Node, inner);\n return;\n }\n case \"BlockStatement\":\n case \"Program\": {\n const inner = new Set(bound);\n for (const statement of node.body as Node[]) {\n if (statement.type === \"VariableDeclaration\")\n for (const declarator of statement.declarations as Node[])\n for (const name of patternNames(declarator.id as Node))\n inner.add(name);\n if (\n (statement.type === \"FunctionDeclaration\" ||\n statement.type === \"ClassDeclaration\") &&\n statement.id\n )\n inner.add((statement.id as Node).name as string);\n }\n for (const statement of node.body as Node[]) visit(statement, inner);\n return;\n }\n // A loop's own declarations bind inside the loop alone.\n case \"ForStatement\":\n case \"ForInStatement\":\n case \"ForOfStatement\": {\n const head = (node.init ?? node.left) as Node | null;\n const inner = new Set(bound);\n if (head?.type === \"VariableDeclaration\")\n for (const declarator of head.declarations as Node[])\n for (const name of patternNames(declarator.id as Node))\n inner.add(name);\n for (const key of [\"init\", \"left\", \"right\", \"test\", \"update\", \"body\"])\n if (node[key]) visit(node[key] as Node, inner);\n return;\n }\n case \"VariableDeclarator\":\n visitPatternDefaults(node.id as Node, bound);\n if (node.init) visit(node.init as Node, bound);\n return;\n case \"CatchClause\": {\n const inner = new Set([\n ...bound,\n ...patternNames(node.param as Node | null),\n ]);\n visit(node.body as Node, inner);\n return;\n }\n }\n for (const [key, value] of Object.entries(node)) {\n if (key === \"type\" || key === \"loc\" || key === \"metadata\") continue;\n for (const child of Array.isArray(value) ? value : [value])\n if (\n child &&\n typeof child === \"object\" &&\n typeof child.type === \"string\"\n )\n visit(child as Node, bound);\n }\n };\n /** A pattern's default values and computed keys are read; its names\n * are bound. */\n const visitPatternDefaults = (pattern: Node, bound: ReadonlySet<string>) => {\n if (pattern.type === \"AssignmentPattern\") {\n visit(pattern.right as Node, bound);\n visitPatternDefaults(pattern.left as Node, bound);\n } else if (pattern.type === \"ObjectPattern\") {\n for (const property of pattern.properties as Node[]) {\n if (property.computed) visit(property.key as Node, bound);\n visitPatternDefaults(\n (property.type === \"RestElement\"\n ? property.argument\n : property.value) as Node,\n bound,\n );\n }\n } else if (pattern.type === \"ArrayPattern\") {\n for (const element of pattern.elements as (Node | null)[])\n if (element) visitPatternDefaults(element, bound);\n } else if (pattern.type === \"RestElement\") {\n visitPatternDefaults(pattern.argument as Node, bound);\n }\n };\n // A binding pattern (a snippet parameter) reads only its defaults.\n if (root.type.endsWith(\"Pattern\") || root.type === \"RestElement\")\n visitPatternDefaults(root, scope);\n else visit(root, scope);\n}\n\n/** Every name a template construct outside `skip` binds for markup\n * inside it. Over-approximate on purpose: a name bound anywhere else in\n * the template is never taken for a script or global binding. */\nfunction declaredInTemplate(value: unknown, skip: Node, out: Set<string>) {\n if (!value || typeof value !== \"object\" || value === skip) return;\n if (Array.isArray(value)) {\n for (const item of value) declaredInTemplate(item, skip, out);\n return;\n }\n const node = value as Node;\n for (const name of bindingsOf(node)) out.add(name);\n for (const [key, child] of Object.entries(node))\n if (key !== \"metadata\" && key !== \"parent\")\n declaredInTemplate(child, skip, out);\n}\n\n/** The names one template construct binds: a block's context or index, a\n * snippet's name and parameters, a `{@const}`, a `let:` directive. */\nfunction bindingsOf(node: Node): string[] {\n switch (node.type) {\n case \"EachBlock\":\n return [\n ...patternNames(node.context as Node | null),\n ...(typeof node.index === \"string\" ? [node.index] : []),\n ];\n case \"AwaitBlock\":\n return [\n ...patternNames(node.value as Node | null),\n ...patternNames(node.error as Node | null),\n ];\n case \"SnippetBlock\":\n return [\n (node.expression as Node).name as string,\n ...(node.parameters as Node[]).flatMap(patternNames),\n ];\n case \"ConstTag\":\n return ((node.declaration as Node).declarations as Node[]).flatMap(\n (declarator) => patternNames(declarator.id as Node),\n );\n case \"LetDirective\":\n return node.expression\n ? patternNames(node.expression as Node)\n : [node.name as string];\n default:\n return [];\n }\n}\n\n/** The names the template binds for markup landing as the last child of\n * the element at `start`: each enclosing block's context, an enclosing\n * snippet's parameters, a `let:` directive on the element or an ancestor,\n * and the `{@const}` and snippet names of every fragment on the way down,\n * which bind for their whole fragment. Null when no element starts there. */\nfunction scopeAt(fragment: AST.Fragment, start: number): Set<string> | null {\n const fragmentBindings = (nodes: readonly Node[]) =>\n nodes.flatMap((node) =>\n node.type === \"ConstTag\"\n ? bindingsOf(node)\n : node.type === \"SnippetBlock\"\n ? [(node.expression as Node).name as string]\n : [],\n );\n const visit = (value: unknown, bound: readonly string[]): string[] | null => {\n if (!value || typeof value !== \"object\") return null;\n if (Array.isArray(value)) {\n for (const item of value) {\n const found = visit(item, bound);\n if (found) return found;\n }\n return null;\n }\n const node = value as Node;\n const outside =\n typeof node.start === \"number\" &&\n typeof node.end === \"number\" &&\n (start < node.start || start >= node.end);\n if (outside) return null;\n const elementLike =\n typeof node.type === \"string\" &&\n \"attributes\" in node &&\n \"fragment\" in node;\n const binds =\n node.type === \"Fragment\"\n ? fragmentBindings(node.nodes as Node[])\n : elementLike\n ? (node.attributes as Node[]).flatMap(bindingsOf)\n : bindingsOf(node);\n const inside = [...bound, ...binds];\n if (elementLike && node.start === start)\n return [\n ...inside,\n ...fragmentBindings((node.fragment as Node).nodes as Node[]),\n ];\n for (const [key, child] of Object.entries(node))\n if (key !== \"metadata\" && key !== \"parent\") {\n const found = visit(child, inside);\n if (found) return found;\n }\n return null;\n };\n const found = visit(fragment, []);\n return found && new Set(found);\n}\n\n// ---------------------------------------------------------------------------\n// Resolving what the markup reads\n\n/** A declaration the destination must hold, under the source's local\n * name, and where the markup writes that name. */\ntype Declaration = (\n | { kind: \"import\"; local: string; source: string; imported: string }\n | { kind: \"const\"; local: string; literal: string }\n) & { occurrences: Occurrence[] };\n\nfunction resolveDependencies(\n from: ComponentRead,\n uses: TemplateUses,\n options: PlanSvelteMarkupTransferOptions,\n): Declaration[] {\n const declarations = new Map<string, Declaration>();\n for (const [used, occurrences] of uses.names) {\n if (INSTANCE_NAMES.has(used))\n refuse(\n \"scope_change\",\n `The markup reads its component's ${used}; moving it requires AI`,\n );\n // `$name` subscribes to the store `name` holds.\n const store = used.startsWith(\"$\") && used.length > 1;\n const name = store ? used.slice(1) : used;\n const known = declarations.get(name);\n if (known) {\n known.occurrences.push(...occurrences);\n continue;\n }\n for (const script of from.scripts) {\n const imported = script.imports.find((entry) => entry.local === name);\n if (imported) {\n declarations.set(name, {\n kind: \"import\",\n local: name,\n source: options.rebase(imported.source, \"import\"),\n imported: imported.imported,\n occurrences: [...occurrences],\n });\n break;\n }\n const literal = script.literals.get(name);\n if (literal !== undefined) {\n declarations.set(name, {\n kind: \"const\",\n local: name,\n literal,\n occurrences: [...occurrences],\n });\n break;\n }\n if (script.declared.has(name))\n refuse(\n \"scope_change\",\n `The markup reads ${used}, which its component's script defines; moving it requires AI`,\n );\n }\n // A name no script declares is a global, the same anywhere.\n }\n return [...declarations.values()];\n}\n\n// ---------------------------------------------------------------------------\n// Writing the destination\n\nfunction statementOf(declaration: Declaration, local: string): string {\n if (declaration.kind === \"const\")\n return `const ${local} = ${declaration.literal};`;\n const from = JSON.stringify(declaration.source);\n if (declaration.imported === \"default\")\n return `import ${local} from ${from};`;\n if (declaration.imported === \"*\") return `import * as ${local} from ${from};`;\n const imported = /^[$A-Z_a-z][$\\w]*$/.test(declaration.imported)\n ? declaration.imported\n : JSON.stringify(declaration.imported);\n return imported === local\n ? `import { ${imported} } from ${from};`\n : `import { ${imported} as ${local} } from ${from};`;\n}\n\n/** The edit that declares each dependency in the destination's instance\n * script (creating it when there is none), and the name each one takes\n * there. One the destination already holds, the same import or literal, is\n * reused under the destination's name for it. A name the destination\n * already uses for something else, or reads without declaring, takes the\n * next free spelling instead (`Icon2`), as Astro's transfer does; the\n * caller re-spells the markup. */\nfunction declareInDestination(\n from: ComponentRead,\n into: ComponentRead,\n declarations: readonly Declaration[],\n /** Names the template binds where the markup lands, which a\n * declaration's name must not be: the binding would shadow it. */\n shadowing: ReadonlySet<string>,\n /** Names the moved markup itself writes, which a new name must not be. */\n markupNames: ReadonlySet<string>,\n): { edits: StringEdit[]; renames: Map<string, string> } {\n const destinationUses = emptyUses(into.source);\n for (const child of into.root.fragment.nodes as unknown as Node[])\n visitTemplate(child, new Set(), destinationUses);\n const spoken = new Set([\n ...(into.source.match(/[$A-Z_a-z][$\\w]*/g) ?? []),\n ...markupNames,\n ]);\n const allocate = (name: string) => {\n let fresh = name;\n for (let count = 2; spoken.has(fresh); count++) fresh = `${name}${count}`;\n spoken.add(fresh);\n return fresh;\n };\n const statements: string[] = [];\n const renames = new Map<string, string>();\n for (const declaration of declarations) {\n const held = into.scripts.flatMap((script) =>\n declaration.kind === \"import\"\n ? script.imports\n .filter(\n (entry) =>\n entry.source === declaration.source &&\n entry.imported === declaration.imported,\n )\n .map((entry) => entry.local)\n : script.literals.get(declaration.local) === declaration.literal\n ? [declaration.local]\n : [],\n )[0];\n // Reusing the destination's declaration keeps one, unless the landing\n // spot's block or snippet shadows its name.\n if (held !== undefined && !shadowing.has(held)) {\n if (held !== declaration.local) renames.set(declaration.local, held);\n continue;\n }\n const taken =\n into.scripts.some((script) => script.declared.has(declaration.local)) ||\n destinationUses.names.has(declaration.local) ||\n destinationUses.names.has(`$${declaration.local}`) ||\n shadowing.has(declaration.local);\n const local = taken ? allocate(declaration.local) : declaration.local;\n if (local !== declaration.local) renames.set(declaration.local, local);\n statements.push(statementOf(declaration, local));\n }\n if (statements.length === 0) return { edits: [], renames };\n\n const source = into.source;\n const newline = source.includes(\"\\r\\n\") ? \"\\r\\n\" : \"\\n\";\n const instance = into.root.instance;\n if (instance) {\n const body = (instance.content as unknown as Node).body as Node[];\n const imports = body.filter(\n (statement) => statement.type === \"ImportDeclaration\",\n );\n const lastImport = imports[imports.length - 1];\n if (lastImport) {\n const lineStart = source.lastIndexOf(\"\\n\", lastImport.start - 1) + 1;\n const indent = /^[ \\t]*/.exec(\n source.slice(lineStart, lastImport.start),\n )![0];\n return {\n renames,\n edits: [\n {\n start: lastImport.end,\n end: lastImport.end,\n replacement: statements\n .map((statement) => `${newline}${indent}${statement}`)\n .join(\"\"),\n },\n ],\n };\n }\n const openingEnd = source.indexOf(\">\", instance.start) + 1;\n const insertion = body[0]?.start ?? openingEnd;\n const lineStart = source.lastIndexOf(\"\\n\", insertion - 1) + 1;\n const before = source.slice(lineStart, insertion);\n const indent = /^[ \\t]*$/.test(before) ? before : \"\";\n return {\n renames,\n edits: [\n {\n start: insertion,\n end: insertion,\n replacement: body[0]\n ? `${statements.join(`${newline}${indent}`)}${newline}${indent}`\n : `${newline}${statements.map((statement) => ` ${statement}`).join(newline)}${newline}`,\n },\n ],\n };\n }\n // A TypeScript component's new script is TypeScript too.\n const lang = from.root.instance?.attributes.find(\n (attribute) => attribute.name === \"lang\",\n );\n const opening =\n lang && Array.isArray(lang.value) && lang.value[0]?.type === \"Text\"\n ? `<script lang=\"${lang.value[0].data}\">`\n : \"<script>\";\n return {\n renames,\n edits: [\n {\n start: 0,\n end: 0,\n replacement: `${opening}${newline}${statements.map((statement) => ` ${statement}`).join(newline)}${newline}</script>${newline}${newline}`,\n },\n ],\n };\n}\n\n/** The source's `<style>`, carried: Svelte scopes it to the component, so\n * in the destination its selectors match the moved elements as they did\n * in the source. A component holds one `<style>`: an existing one with the\n * same attributes gains the source's rules, one with others refuses. Its\n * relative `url()` and `@import` references are re-spelled for the\n * destination's directory. */\nfunction carryStyle(\n from: ComponentRead,\n into: ComponentRead,\n options: PlanSvelteMarkupTransferOptions,\n): StringEdit[] {\n const style = from.root.css;\n if (!style) return [];\n // Vite resolves the style's relative references from the component's\n // directory: they are re-spelled for the destination's.\n let content: string;\n try {\n content = rebaseCssUrls(style.content.styles, options.rebase);\n } catch (error) {\n if (!(error instanceof CssUrlError)) throw error;\n return refuse(\"scoped_css\", error.message);\n }\n const block =\n from.source.slice(style.start, style.content.start) +\n content +\n from.source.slice(style.content.end, style.end);\n const destination = into.source;\n const existing = into.root.css;\n if (!existing) {\n const newline = destination.includes(\"\\r\\n\") ? \"\\r\\n\" : \"\\n\";\n const separator =\n destination.endsWith(\"\\n\") || destination === \"\" ? \"\" : newline;\n return [\n {\n start: destination.length,\n end: destination.length,\n replacement: `${separator}${block}${newline}`,\n },\n ];\n }\n const opening = (read: ComponentRead, css: AST.CSS.StyleSheet) =>\n read.source.slice(css.start, css.content.start);\n if (destination.includes(content)) return [];\n if (opening(into, existing) !== opening(from, style))\n refuse(\n \"scoped_css\",\n `${options.destinationFile} already has a <style> written differently; merging the moved markup's styles requires AI`,\n );\n return [\n {\n start: existing.content.end,\n end: existing.content.end,\n replacement: content,\n },\n ];\n}\n\n/**\n * The file's value imports and every name it reads outside them, so a\n * caller can drop an import an edit left unread. Over-approximate on\n * purpose: any identifier a script spells counts as read. Null when the\n * file does not parse.\n */\nexport function readSvelteImportUse(\n source: string,\n file: string,\n): SvelteImportUse | null {\n let root: AST.Root;\n try {\n root = parse(source, { filename: file, modern: true });\n } catch {\n return null;\n }\n const uses = emptyUses(source);\n for (const child of root.fragment.nodes as unknown as Node[])\n visitTemplate(child, new Set(), uses);\n const referenced = new Set<string>();\n for (const name of uses.names.keys()) {\n referenced.add(name);\n if (name.startsWith(\"$\")) referenced.add(name.slice(1));\n }\n const imports: SvelteImportUse[\"imports\"] = [];\n for (const script of [root.instance, root.module]) {\n if (!script) continue;\n for (const statement of (script.content as unknown as Node)\n .body as Node[]) {\n if (statement.type !== \"ImportDeclaration\") {\n identifierNames(statement, referenced);\n continue;\n }\n const specifiers = statement.specifiers as Node[];\n if (statement.importKind === \"type\" || !specifiers.length) continue;\n const from = statement.source as Node;\n imports.push({\n start: statement.start,\n end: statement.end,\n sourceText: source.slice(from.start, from.end),\n rewritable: !(statement.attributes as Node[] | undefined)?.length,\n specifiers: specifiers.map((specifier) => ({\n local: (specifier.local as Node).name as string,\n kind:\n specifier.type === \"ImportDefaultSpecifier\"\n ? \"default\"\n : specifier.type === \"ImportNamespaceSpecifier\"\n ? \"namespace\"\n : \"named\",\n text: source.slice(specifier.start, specifier.end),\n })),\n });\n }\n }\n return { imports, referenced };\n}\n\n/** Every identifier name under `node`. */\nfunction identifierNames(node: unknown, out: Set<string>): void {\n if (!node || typeof node !== \"object\") return;\n if (Array.isArray(node)) {\n for (const item of node) identifierNames(item, out);\n return;\n }\n const value = node as { type?: unknown; name?: unknown };\n if (value.type === \"Identifier\" && typeof value.name === \"string\")\n out.add(value.name);\n for (const [key, child] of Object.entries(node))\n if (key !== \"loc\" && key !== \"metadata\" && key !== \"leadingComments\")\n identifierNames(child, out);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAQA,SAAS,oBAAoB;AAC7B,SAAS,eAAe;;;ACHxB,SAAS,SAAS,aAAa;;;ACNxB,SAAS,2BACd,OACA,OACQ;AACR,MAAI,UAAU,MACX,MAAM,GAAG,EACT,KAAK,OAAO,EACZ,MAAM,GAAG,EACT,KAAK,MAAM,EACX,MAAM,GAAG,EACT,KAAK,MAAM,EACX,MAAM,GAAG,EAC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;AAAA,QACL,MAAM;AAAA,UACJ;AAAA,UACA,SAAS;AAAA,UACT,SAAS;AAAA,UACT;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["parse"]}
1
+ {"version":3,"sources":["../svelte.ts","../../../modules/svelte-editor/compiler.ts","../../../modules/svelte-editor/byte-order-mark.ts","../../../modules/svelte-editor/escape.ts","../../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js","../../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js","../../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js","../../../modules/svelte-editor/literal-attributes.ts","../../../modules/svelte-editor/style-directives.ts","../../../modules/svelte-editor/parse.ts","../../../modules/svelte-editor/annotate.ts"],"sourcesContent":["/**\n * Svelte-specific Tempo source annotation.\n *\n * Keep this adapter first in `svelte({ preprocess: [...] })`. It only supplies\n * filesystem/project identity; parsing and annotation remain isolated in the\n * framework-focused @modules/svelte-editor package.\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { createSvelteAnnotationPreprocessor } from \"@modules/svelte-editor\";\nimport type { PreprocessorGroup } from \"svelte/compiler\";\nimport { sourceVersionHash } from \"../../modules/annotation/source-version.ts\";\nimport {\n defaultSourceRoot,\n readModifiedTs,\n resolveAnnotationIdentity,\n} from \"./annotation-identity.ts\";\nimport { appendModuleVersionRecord } from \"./annotation-strategy.ts\";\n\nexport interface TempoSveltePreprocessOptions {\n /** Annotation identity root. Defaults to the process working directory. */\n root?: string;\n /** Allowed source boundary. Defaults to the package-manager workspace\n * around `root`, else `root` (see defaultSourceRoot); host sidecars set\n * this to the project root while annotations remain relative to the host\n * root. */\n sourceRoot?: string;\n /** Override the normal TEMPO environment gate, primarily for tests. */\n enabled?: boolean;\n}\n\n/** A top-level module script, Svelte 5 (`module`) or 4 (`context=\"module\"`). */\nconst MODULE_SCRIPT =\n /<script\\b[^>]*\\b(?:module\\b|context\\s*=\\s*[\"']module[\"'])[^>]*>/;\n\nexport function tempoSveltePreprocess(\n options: TempoSveltePreprocessOptions = {},\n): PreprocessorGroup {\n const root = resolve(options.root ?? process.cwd());\n const sourceRoot = resolve(options.sourceRoot ?? defaultSourceRoot(root));\n const enabled = options.enabled ?? Boolean(process.env.TEMPO);\n\n const metadata = ({ filename }: { filename?: string }) => {\n if (!enabled || !filename) return null;\n const identity = resolveAnnotationIdentity(filename, { root, sourceRoot });\n if (!identity?.absoluteFilename.endsWith(\".svelte\")) return null;\n return {\n filepath: identity.filepath,\n modifiedTs: readModifiedTs(identity.absoluteFilename),\n };\n };\n const annotation = createSvelteAnnotationPreprocessor({ metadata });\n\n return {\n name: \"svelte-source-annotation\",\n // The annotation, plus an empty module script when the file has none:\n // the module version record must run once per module evaluation, which\n // is what a module script's top level does (V2-498).\n markup(input) {\n const result = annotation.markup?.(input);\n if (!result || !(\"code\" in result)) return result;\n if (MODULE_SCRIPT.test(result.code)) return result;\n return {\n ...result,\n code: `${result.code}\\n<script module></script>\\n`,\n };\n },\n // The module version record ends the module script, as it ends every\n // annotated JSX module. The file's own bytes name its version, the same\n // raw-source hash the element stamps carry.\n script({ content, attributes, filename }) {\n const moduleScript =\n attributes.module === true || attributes.context === \"module\";\n if (!moduleScript) return undefined;\n const identity = metadata({ filename });\n if (!identity || !filename) return undefined;\n const sourceVersion = sourceVersionHash(readFileSync(filename, \"utf8\"));\n return {\n code: appendModuleVersionRecord(\n content,\n identity.filepath,\n identity.modifiedTs,\n sourceVersion,\n ),\n };\n },\n };\n}\n","/**\n * The Svelte compiler functions the editor calls. Every value import of the\n * compiler goes through here, as `#svelte-compiler` (package.json\n * \"imports\"), so a bundler can swap in `compiler-deferred.ts`; the other\n * modules import only its types. Both read the source in the caller's\n * offsets (see byte-order-mark.ts).\n */\nimport * as SvelteCompiler from \"svelte/compiler\";\nimport { withoutByteOrderMark } from \"./byte-order-mark\";\n\nexport const compile: typeof SvelteCompiler.compile = (source, options) =>\n SvelteCompiler.compile(withoutByteOrderMark(source), options);\n// Svelte overloads `parse` on `modern`, which a forwarding arrow cannot\n// declare; the cast restores the overloads.\nexport const parse = ((\n source: string,\n options?: Parameters<typeof SvelteCompiler.parse>[1],\n) =>\n SvelteCompiler.parse(\n withoutByteOrderMark(source),\n options,\n )) as typeof SvelteCompiler.parse;\n","/**\n * Svelte's `parse` and `compile` drop a leading byte-order mark before they\n * read the source, so every syntax offset they report is one short of the\n * text a caller holds. The editor's offsets index that text, so its compiler\n * entry hands Svelte the source with the mark replaced by a space instead:\n * the length is unchanged, and leading whitespace in a component's markup\n * renders nothing.\n */\nexport function withoutByteOrderMark(source: string): string {\n return source.charCodeAt(0) === 0xfeff ? ` ${source.slice(1)}` : source;\n}\n","export function escapeSvelteAttributeValue(\n value: string,\n quote: '\"' | \"'\",\n): string {\n let escaped = value\n .split(\"&\")\n .join(\"&amp;\")\n .split(\"<\")\n .join(\"&lt;\")\n .split(\">\")\n .join(\"&gt;\")\n .split(\"{\")\n .join(\"&#123;\")\n .split(\"}\")\n .join(\"&#125;\");\n escaped =\n quote === '\"'\n ? escaped.split('\"').join(\"&quot;\")\n : escaped.split(\"'\").join(\"&#39;\");\n return escaped;\n}\n","/**\n * @typedef { import('estree').Node} Node\n * @typedef {{\n * skip: () => void;\n * remove: () => void;\n * replace: (node: Node) => void;\n * }} WalkerContext\n */\n\nexport class WalkerBase {\n\tconstructor() {\n\t\t/** @type {boolean} */\n\t\tthis.should_skip = false;\n\n\t\t/** @type {boolean} */\n\t\tthis.should_remove = false;\n\n\t\t/** @type {Node | null} */\n\t\tthis.replacement = null;\n\n\t\t/** @type {WalkerContext} */\n\t\tthis.context = {\n\t\t\tskip: () => (this.should_skip = true),\n\t\t\tremove: () => (this.should_remove = true),\n\t\t\treplace: (node) => (this.replacement = node)\n\t\t};\n\t}\n\n\t/**\n\t * @template {Node} Parent\n\t * @param {Parent | null | undefined} parent\n\t * @param {keyof Parent | null | undefined} prop\n\t * @param {number | null | undefined} index\n\t * @param {Node} node\n\t */\n\treplace(parent, prop, index, node) {\n\t\tif (parent && prop) {\n\t\t\tif (index != null) {\n\t\t\t\t/** @type {Array<Node>} */ (parent[prop])[index] = node;\n\t\t\t} else {\n\t\t\t\t/** @type {Node} */ (parent[prop]) = node;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * @template {Node} Parent\n\t * @param {Parent | null | undefined} parent\n\t * @param {keyof Parent | null | undefined} prop\n\t * @param {number | null | undefined} index\n\t */\n\tremove(parent, prop, index) {\n\t\tif (parent && prop) {\n\t\t\tif (index !== null && index !== undefined) {\n\t\t\t\t/** @type {Array<Node>} */ (parent[prop]).splice(index, 1);\n\t\t\t} else {\n\t\t\t\tdelete parent[prop];\n\t\t\t}\n\t\t}\n\t}\n}\n","import { WalkerBase } from './walker.js';\n\n/**\n * @typedef { import('estree').Node} Node\n * @typedef { import('./walker.js').WalkerContext} WalkerContext\n * @typedef {(\n * this: WalkerContext,\n * node: Node,\n * parent: Node | null,\n * key: string | number | symbol | null | undefined,\n * index: number | null | undefined\n * ) => void} SyncHandler\n */\n\nexport class SyncWalker extends WalkerBase {\n\t/**\n\t *\n\t * @param {SyncHandler} [enter]\n\t * @param {SyncHandler} [leave]\n\t */\n\tconstructor(enter, leave) {\n\t\tsuper();\n\n\t\t/** @type {boolean} */\n\t\tthis.should_skip = false;\n\n\t\t/** @type {boolean} */\n\t\tthis.should_remove = false;\n\n\t\t/** @type {Node | null} */\n\t\tthis.replacement = null;\n\n\t\t/** @type {WalkerContext} */\n\t\tthis.context = {\n\t\t\tskip: () => (this.should_skip = true),\n\t\t\tremove: () => (this.should_remove = true),\n\t\t\treplace: (node) => (this.replacement = node)\n\t\t};\n\n\t\t/** @type {SyncHandler | undefined} */\n\t\tthis.enter = enter;\n\n\t\t/** @type {SyncHandler | undefined} */\n\t\tthis.leave = leave;\n\t}\n\n\t/**\n\t * @template {Node} Parent\n\t * @param {Node} node\n\t * @param {Parent | null} parent\n\t * @param {keyof Parent} [prop]\n\t * @param {number | null} [index]\n\t * @returns {Node | null}\n\t */\n\tvisit(node, parent, prop, index) {\n\t\tif (node) {\n\t\t\tif (this.enter) {\n\t\t\t\tconst _should_skip = this.should_skip;\n\t\t\t\tconst _should_remove = this.should_remove;\n\t\t\t\tconst _replacement = this.replacement;\n\t\t\t\tthis.should_skip = false;\n\t\t\t\tthis.should_remove = false;\n\t\t\t\tthis.replacement = null;\n\n\t\t\t\tthis.enter.call(this.context, node, parent, prop, index);\n\n\t\t\t\tif (this.replacement) {\n\t\t\t\t\tnode = this.replacement;\n\t\t\t\t\tthis.replace(parent, prop, index, node);\n\t\t\t\t}\n\n\t\t\t\tif (this.should_remove) {\n\t\t\t\t\tthis.remove(parent, prop, index);\n\t\t\t\t}\n\n\t\t\t\tconst skipped = this.should_skip;\n\t\t\t\tconst removed = this.should_remove;\n\n\t\t\t\tthis.should_skip = _should_skip;\n\t\t\t\tthis.should_remove = _should_remove;\n\t\t\t\tthis.replacement = _replacement;\n\n\t\t\t\tif (skipped) return node;\n\t\t\t\tif (removed) return null;\n\t\t\t}\n\n\t\t\t/** @type {keyof Node} */\n\t\t\tlet key;\n\n\t\t\tfor (key in node) {\n\t\t\t\t/** @type {unknown} */\n\t\t\t\tconst value = node[key];\n\n\t\t\t\tif (value && typeof value === 'object') {\n\t\t\t\t\tif (Array.isArray(value)) {\n\t\t\t\t\t\tconst nodes = /** @type {Array<unknown>} */ (value);\n\t\t\t\t\t\tfor (let i = 0; i < nodes.length; i += 1) {\n\t\t\t\t\t\t\tconst item = nodes[i];\n\t\t\t\t\t\t\tif (isNode(item)) {\n\t\t\t\t\t\t\t\tif (!this.visit(item, node, key, i)) {\n\t\t\t\t\t\t\t\t\t// removed\n\t\t\t\t\t\t\t\t\ti--;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (isNode(value)) {\n\t\t\t\t\t\tthis.visit(value, node, key, null);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.leave) {\n\t\t\t\tconst _replacement = this.replacement;\n\t\t\t\tconst _should_remove = this.should_remove;\n\t\t\t\tthis.replacement = null;\n\t\t\t\tthis.should_remove = false;\n\n\t\t\t\tthis.leave.call(this.context, node, parent, prop, index);\n\n\t\t\t\tif (this.replacement) {\n\t\t\t\t\tnode = this.replacement;\n\t\t\t\t\tthis.replace(parent, prop, index, node);\n\t\t\t\t}\n\n\t\t\t\tif (this.should_remove) {\n\t\t\t\t\tthis.remove(parent, prop, index);\n\t\t\t\t}\n\n\t\t\t\tconst removed = this.should_remove;\n\n\t\t\t\tthis.replacement = _replacement;\n\t\t\t\tthis.should_remove = _should_remove;\n\n\t\t\t\tif (removed) return null;\n\t\t\t}\n\t\t}\n\n\t\treturn node;\n\t}\n}\n\n/**\n * Ducktype a node.\n *\n * @param {unknown} value\n * @returns {value is Node}\n */\nfunction isNode(value) {\n\treturn (\n\t\tvalue !== null && typeof value === 'object' && 'type' in value && typeof value.type === 'string'\n\t);\n}\n","import { SyncWalker } from './sync.js';\nimport { AsyncWalker } from './async.js';\n\n/**\n * @typedef {import('estree').Node} Node\n * @typedef {import('./sync.js').SyncHandler} SyncHandler\n * @typedef {import('./async.js').AsyncHandler} AsyncHandler\n */\n\n/**\n * @param {Node} ast\n * @param {{\n * enter?: SyncHandler\n * leave?: SyncHandler\n * }} walker\n * @returns {Node | null}\n */\nexport function walk(ast, { enter, leave }) {\n\tconst instance = new SyncWalker(enter, leave);\n\treturn instance.visit(ast, null);\n}\n\n/**\n * @param {Node} ast\n * @param {{\n * enter?: AsyncHandler\n * leave?: AsyncHandler\n * }} walker\n * @returns {Promise<Node | null>}\n */\nexport async function asyncWalk(ast, { enter, leave }) {\n\tconst instance = new AsyncWalker(enter, leave);\n\treturn await instance.visit(ast, null);\n}\n","import { readLiteralExpression } from \"@modules/annotation/expression-facts\";\nimport type { AST } from \"svelte/compiler\";\nimport type { StringEdit } from \"./types\";\n\n/**\n * A native element attribute written as one mustache that holds only a\n * literal (`x={2}`, `x={\"2\"}`, `x=\"{2}\"`), the way Svelte icons write SVG\n * geometry. Svelte renders it as the literal's string, so it is as static\n * as `x=\"2\"`. Null, undefined and booleans are not: Svelte omits or\n * coerces those. `class`, `style` and event handlers have their own\n * readers and are never read here.\n */\nexport function literalMustacheAttribute(attribute: AST.Attribute): {\n value: string | number;\n rendered: string;\n expression: { start: number; end: number };\n quoted: boolean;\n} | null {\n const name = attribute.name.toLowerCase();\n if (name === \"class\" || name === \"style\" || name.startsWith(\"on\"))\n return null;\n const tag = Array.isArray(attribute.value)\n ? attribute.value.length === 1\n ? attribute.value[0]\n : undefined\n : attribute.value === true\n ? undefined\n : attribute.value;\n if (tag?.type !== \"ExpressionTag\") return null;\n const expression = tag.expression as unknown as {\n type: string;\n start: number;\n end: number;\n [key: string]: unknown;\n };\n const value = readLiteralExpression(expression);\n if (typeof value !== \"string\" && typeof value !== \"number\") return null;\n return {\n value,\n rendered: String(value),\n expression: { start: expression.start, end: expression.end },\n quoted: Array.isArray(attribute.value),\n };\n}\n\n/** The edit that writes `value` into a literal mustache attribute, in the\n * author's form: a number stays a number when the new value is one, and\n * any other value is a string literal. Null when the quoted form\n * (`x=\"{2}\"`) would need a quote inside its quotes. */\nexport function planLiteralMustacheUpdate(\n literal: NonNullable<ReturnType<typeof literalMustacheAttribute>>,\n value: string,\n): StringEdit | null {\n const numeric = Number(value);\n const replacement =\n typeof literal.value === \"number\" &&\n value.trim() !== \"\" &&\n Number.isFinite(numeric) &&\n String(numeric) === value\n ? value\n : literal.quoted\n ? null\n : JSON.stringify(value);\n if (replacement === null) return null;\n return {\n start: literal.expression.start,\n end: literal.expression.end,\n replacement,\n };\n}\n","import { cssPropertiesOverlap } from \"@modules/inline-style-value\";\nimport type { AST } from \"svelte/compiler\";\nimport type { StringEdit } from \"./types\";\nimport { escapeSvelteAttributeValue } from \"./escape\";\n\n/**\n * A `style:` directive sets one CSS property at runtime, and Svelte gives it\n * precedence over the static style attribute one property at a time\n * (`set_style`): a static declaration of any other property renders as\n * written. These helpers decide which properties a directive owns, and\n * rewrite a directive whose value is one quoted literal.\n */\n\n/** Shorthands the shared table leaves out whose longhands do not share\n * their name as a prefix. */\nconst EXTRA_COVERAGE: Readonly<Record<string, readonly string[]>> = {\n \"place-content\": [\"align-content\", \"justify-content\"],\n \"place-items\": [\"align-items\", \"justify-items\"],\n \"place-self\": [\"align-self\", \"justify-self\"],\n \"grid-area\": [\n \"grid-row-start\",\n \"grid-row-end\",\n \"grid-column-start\",\n \"grid-column-end\",\n ],\n};\n\nfunction normalizeProperty(property: string): string {\n const trimmed = property.trim();\n return trimmed.startsWith(\"--\") ? trimmed : trimmed.toLowerCase();\n}\n\n/**\n * Whether a directive named `directive` can set `property` at runtime: the\n * same property, two properties the shared shorthand table relates, or a\n * property named after the other (`grid-template` and\n * `grid-template-columns`), which also covers shorthands the table does not\n * list. A custom property overlaps only itself.\n */\nexport function styleDirectiveOverlaps(\n directive: string,\n property: string,\n): boolean {\n const left = normalizeProperty(directive);\n const right = normalizeProperty(property);\n if (left === right) return true;\n if (left.startsWith(\"--\") || right.startsWith(\"--\")) return false;\n if (left === \"all\" || right === \"all\") return true;\n if (left.startsWith(`${right}-`) || right.startsWith(`${left}-`)) return true;\n if (\n EXTRA_COVERAGE[left]?.includes(right) ||\n EXTRA_COVERAGE[right]?.includes(left)\n )\n return true;\n return cssPropertiesOverlap(left, right);\n}\n\n/** The element's style directives. */\nexport function styleDirectives(\n attributes: readonly { type: string }[],\n): AST.StyleDirective[] {\n return attributes.filter(\n (attribute) => attribute.type === \"StyleDirective\",\n ) as AST.StyleDirective[];\n}\n\n/** A directive whose value is one quoted text chunk with no modifier, its\n * name written once on the element: its decoded value and where the quoted\n * text sits. Null for any other directive. */\nexport function literalStyleDirective(\n source: string,\n directive: AST.StyleDirective,\n siblings: readonly AST.StyleDirective[],\n): { value: string; start: number; end: number; quote: '\"' | \"'\" } | null {\n if (directive.modifiers.length > 0) return null;\n if (\n siblings.some(\n (other) =>\n other !== directive &&\n normalizeProperty(other.name) === normalizeProperty(directive.name),\n )\n )\n return null;\n const value = directive.value;\n if (!Array.isArray(value) || value.length !== 1) return null;\n const text = value[0]!;\n if (text.type !== \"Text\") return null;\n const quote = source[text.start - 1];\n if (\n (quote !== '\"' && quote !== \"'\") ||\n source[text.end] !== quote ||\n text.end + 1 !== directive.end\n )\n return null;\n return { value: text.data, start: text.start, end: text.end, quote };\n}\n\n/**\n * The edits that write `styles` into the element's literal directives of\n * the same property (a null value removes the directive with the\n * whitespace before it), and the styles left for the static attribute.\n * Null when a property left over is one a directive owns: a static\n * declaration of it would never render. `owned` is a directive the caller\n * rewrites itself. `cleared` names each property whose directive a removal\n * deletes: a static declaration of it, hidden while the directive stood,\n * renders once it is gone, so the caller clears that too.\n */\nexport function planStyleDirectives(\n source: string,\n attributes: readonly { type: string }[],\n styles: Readonly<Record<string, string | null>>,\n owned?: string,\n):\n | {\n kind: \"ok\";\n edits: StringEdit[];\n remaining: Record<string, string | null>;\n cleared: string[];\n }\n | { kind: \"conflict\"; directive: string; property: string } {\n const directives = styleDirectives(attributes).filter(\n (directive) => directive.name !== owned,\n );\n const edits: StringEdit[] = [];\n const remaining: Record<string, string | null> = {};\n const cleared: string[] = [];\n for (const [property, value] of Object.entries(styles)) {\n const own = directives.find(\n (directive) =>\n normalizeProperty(directive.name) === normalizeProperty(property),\n );\n const literal =\n owned === undefined && own\n ? literalStyleDirective(source, own, directives)\n : null;\n // Another directive that sets the property too leaves which one renders\n // to Svelte's order of application.\n const conflict = directives.find(\n (directive) =>\n !(literal && directive === own) &&\n styleDirectiveOverlaps(directive.name, property),\n );\n if (conflict)\n return { kind: \"conflict\", directive: conflict.name, property };\n if (!own || !literal) {\n remaining[property] = value;\n continue;\n }\n let start = own.start;\n while (start > 0 && /\\s/.test(source[start - 1]!)) start -= 1;\n if (value === null) cleared.push(property);\n edits.push(\n value === null\n ? { start, end: own.end, replacement: \"\" }\n : {\n start: literal.start,\n end: literal.end,\n replacement: escapeSvelteAttributeValue(value, literal.quote),\n },\n );\n }\n return { kind: \"ok\", edits, remaining, cleared };\n}\n","import { walk } from \"estree-walker\";\nimport type { AST } from \"svelte/compiler\";\nimport { compile, parse } from \"#svelte-compiler\";\nimport { literalMustacheAttribute } from \"./literal-attributes\";\nimport { literalStyleDirective, styleDirectives } from \"./style-directives\";\nimport type {\n SvelteElementInfo,\n SvelteParseResult,\n SvelteTargetInfo,\n} from \"./types\";\n\ninterface InternalElementInfo extends SvelteElementInfo {\n node: AST.RegularElement;\n parentFragment: AST.Fragment;\n /** Owner of the exact Fragment that directly contains this element. */\n parentFragmentOwnerType: string | null;\n containsDynamicTemplateSyntax: boolean;\n}\n\nexport type InternalParseResult =\n | {\n kind: \"ok\";\n elements: ReadonlyMap<number, InternalElementInfo>;\n /** Component invocations (`Component` nodes) as move subjects, read\n * like elements; `<svelte:component>` is not one. */\n invocations: ReadonlyMap<number, InternalElementInfo>;\n /** Native DOM wrappers and plain component slots preserve this scope; blocks, `let:` slots and local declarations do not. */\n templateScopes: WeakMap<AST.Fragment, AST.Fragment>;\n targets: ReadonlyMap<number, SvelteTargetInfo>;\n targetNodes: ReadonlyMap<\n number,\n AST.BaseNode & { name?: string; attributes?: AST.AttributeLike[] }\n >;\n }\n | Extract<SvelteParseResult, { kind: \"invalid\" }>;\n\nexport function parseSvelteSource(\n source: string,\n filename = \"Component.svelte\",\n): SvelteParseResult {\n const result = parseSvelteSourceInternal(source, filename);\n if (result.kind === \"invalid\") return result;\n\n return toPublicParseResult(result);\n}\n\nfunction toPublicParseResult(\n result: Extract<InternalParseResult, { kind: \"ok\" }>,\n): Extract<SvelteParseResult, { kind: \"ok\" }> {\n return {\n kind: \"ok\",\n elements: new Map(\n [...result.elements].map(([offset, element]) => [\n offset,\n toPublicElementInfo(element),\n ]),\n ),\n targets: new Map(result.targets),\n };\n}\n\nexport function findSvelteElementAtOffset(\n parsed: SvelteParseResult,\n offset: number,\n): SvelteElementInfo | null {\n if (parsed.kind !== \"ok\" || !Number.isInteger(offset)) return null;\n return parsed.elements.get(offset) ?? null;\n}\n\nexport function parseSvelteSourceInternal(\n source: string,\n filename: string,\n validation: \"compiler\" | \"syntax\" = \"compiler\",\n): InternalParseResult {\n const cacheKey = `${validation}\\0${filename}\\0${source}`;\n const cached = parseCache.get(cacheKey);\n if (cached) {\n parseCache.delete(cacheKey);\n parseCache.set(cacheKey, cached);\n return cached;\n }\n try {\n // `parse` intentionally accepts some compiler-invalid semantic forms.\n // Establish compiler validity before exposing offsets as editable anchors.\n if (validation === \"compiler\") {\n compile(source, { filename, generate: false });\n }\n const ast = parse(source, { filename, modern: true });\n const elements = new Map<number, InternalElementInfo>();\n const invocations = new Map<number, InternalElementInfo>();\n const targets = new Map<number, SvelteTargetInfo>();\n const targetNodes = new Map<\n number,\n AST.BaseNode & { name?: string; attributes?: AST.AttributeLike[] }\n >();\n const elementStack: AST.RegularElement[] = [];\n const fragmentOwnerTypes = new WeakMap<object, string | null>();\n const templateScopes = new WeakMap<AST.Fragment, AST.Fragment>();\n const scopeStack: AST.Fragment[] = [];\n\n walk(ast as unknown as Parameters<typeof walk>[0], {\n enter(node, parent) {\n const svelteNode = node as unknown as AST.BaseNode;\n if (svelteNode.type === \"Fragment\") {\n const fragment = node as unknown as AST.Fragment;\n const owner = parent as unknown as AST.BaseNode | null;\n // A DOM wrapper adds no names, and neither does a component's\n // default slot unless it binds `let:` slot props: the content is\n // a closure over this file's scope.\n const inherits =\n (owner?.type === \"RegularElement\" ||\n owner?.type === \"Component\" ||\n owner?.type === \"SvelteComponent\") &&\n !(owner as AST.RegularElement).attributes.some(\n (attribute) => attribute.type === \"LetDirective\",\n ) &&\n !fragment.nodes.some(\n (child) =>\n child.type === \"ConstTag\" || child.type === \"SnippetBlock\",\n );\n const scope = inherits\n ? (scopeStack[scopeStack.length - 1] ?? fragment)\n : fragment;\n templateScopes.set(fragment, scope);\n scopeStack.push(scope);\n fragmentOwnerTypes.set(\n node as object,\n (parent as unknown as AST.BaseNode | null)?.type ?? null,\n );\n }\n const target = toTargetInfo(\n source,\n node as unknown as AST.BaseNode & {\n name?: string;\n },\n );\n if (target) {\n const fragment = parent as unknown as AST.BaseNode | null;\n target.parentFragmentOwnerType =\n fragment?.type === \"Fragment\"\n ? (fragmentOwnerTypes.get(fragment as object) ?? null)\n : null;\n targets.set(target.start, target);\n targetNodes.set(\n target.start,\n node as unknown as AST.BaseNode & {\n name?: string;\n attributes?: AST.AttributeLike[];\n },\n );\n }\n if (\n svelteNode.type !== \"RegularElement\" &&\n svelteNode.type !== \"Component\"\n )\n return;\n const element = node as unknown as AST.RegularElement;\n const parentFragment = parent as unknown as AST.Fragment;\n /* v8 ignore next 4 -- Svelte's modern AST schema parents every RegularElement with Fragment */\n if (parentFragment.type !== \"Fragment\") {\n throw new Error(\n `native element at offset ${element.start} has no exact template fragment parent`,\n );\n }\n const opening = locateOpeningTagEnd(source, element);\n /* v8 ignore next 3 -- a compiler-parsed RegularElement always has an authored opening terminator */\n if (opening.kind === \"invalid\") {\n throw new Error(opening.message);\n }\n const into = svelteNode.type === \"Component\" ? invocations : elements;\n /* v8 ignore next 4 -- modern AST source ranges cannot assign one start to two nodes */\n if (into.has(element.start)) {\n throw new Error(\n `multiple native elements start at UTF-16 offset ${element.start}`,\n );\n }\n into.set(element.start, {\n node: element,\n tagName: element.name,\n start: element.start,\n end: element.end,\n openingEnd: opening.openingEnd,\n selfClosing: opening.selfClosing,\n childrenStart: opening.selfClosing ? null : opening.openingEnd,\n childrenEnd: opening.selfClosing\n ? null\n : locateClosingTagStart(source, element, opening.openingEnd),\n parentElementStart:\n elementStack[elementStack.length - 1]?.start ?? null,\n parentFragment,\n parentFragmentOwnerType:\n fragmentOwnerTypes.get(parentFragment as object) ?? null,\n // An invocation runs another component's code with its props.\n containsDynamicTemplateSyntax:\n svelteNode.type === \"Component\" || containsDynamicSyntax(element),\n attributeNames: element.attributes\n .filter(\n (attribute): attribute is AST.Attribute =>\n attribute.type === \"Attribute\",\n )\n .map((attribute) => attribute.name),\n hasSpreadAttributes: element.attributes.some(\n (attribute) => attribute.type === \"SpreadAttribute\",\n ),\n directiveTypes: element.attributes\n .filter(\n (attribute) =>\n attribute.type !== \"Attribute\" &&\n attribute.type !== \"SpreadAttribute\",\n )\n .map((attribute) => attribute.type),\n });\n if (svelteNode.type === \"RegularElement\") elementStack.push(element);\n },\n leave(node) {\n const svelteNode = node as unknown as AST.BaseNode;\n if (svelteNode.type === \"RegularElement\") elementStack.pop();\n if (svelteNode.type === \"Fragment\") scopeStack.pop();\n },\n });\n\n const result = {\n kind: \"ok\",\n elements,\n invocations,\n templateScopes,\n targets,\n targetNodes,\n } as const;\n rememberParse(cacheKey, result);\n return result;\n } catch (error) {\n const result = compilerError(error);\n rememberParse(cacheKey, result);\n return result;\n }\n}\n\nfunction toTargetInfo(\n source: string,\n node: AST.BaseNode & {\n name?: string;\n attributes?: AST.AttributeLike[];\n },\n): SvelteTargetInfo | null {\n if (node.type === \"RegularElement\") {\n return {\n kind: \"native-element\",\n tagName: node.name ?? \"\",\n start: node.start,\n end: node.end,\n ...targetAttributeFacts(source, node.attributes ?? [], true),\n };\n }\n if (node.type === \"Component\") {\n return {\n kind: \"component\",\n tagName: node.name ?? \"\",\n start: node.start,\n end: node.end,\n ...targetAttributeFacts(source, node.attributes ?? []),\n };\n }\n if (node.type === \"SvelteComponent\") {\n return {\n kind: \"component\",\n tagName: node.name ?? node.type,\n start: node.start,\n end: node.end,\n ...targetAttributeFacts(source, node.attributes ?? []),\n };\n }\n if (node.type === \"SvelteElement\") {\n return {\n kind: \"dynamic-element\",\n tagName: node.name ?? node.type,\n start: node.start,\n end: node.end,\n ...targetAttributeFacts(source, node.attributes ?? []),\n };\n }\n if (\n node.type === \"SlotElement\" ||\n node.type === \"TitleElement\" ||\n node.type === \"SvelteBody\" ||\n node.type === \"SvelteBoundary\" ||\n node.type === \"SvelteDocument\" ||\n node.type === \"SvelteFragment\" ||\n node.type === \"SvelteHead\" ||\n node.type === \"SvelteSelf\" ||\n node.type === \"SvelteWindow\"\n ) {\n return {\n kind: \"special-element\",\n tagName: node.name ?? node.type,\n start: node.start,\n end: node.end,\n };\n }\n return null;\n}\n\nfunction targetAttributeFacts(\n source: string,\n attributes: readonly AST.AttributeLike[],\n native = false,\n): Pick<\n SvelteTargetInfo,\n | \"attributeNames\"\n | \"hasSpreadAttributes\"\n | \"directiveTypes\"\n | \"staticAttributes\"\n | \"styleDirectives\"\n> {\n const directives = styleDirectives(attributes);\n // A spread may override any attribute, so only an element without one\n // reads a literal mustache as its value (a component's is a typed prop).\n const literalMustaches =\n native &&\n !attributes.some((attribute) => attribute.type === \"SpreadAttribute\");\n const staticAttributes: Record<string, string | true> = {};\n for (const attribute of attributes) {\n if (attribute.type !== \"Attribute\") continue;\n const literal = literalMustaches\n ? literalMustacheAttribute(attribute)\n : null;\n if (literal) {\n staticAttributes[attribute.name] = literal.rendered;\n continue;\n }\n if (attribute.value === true) {\n staticAttributes[attribute.name] = true;\n continue;\n }\n if (\n Array.isArray(attribute.value) &&\n attribute.value.every((part) => part.type === \"Text\")\n ) {\n staticAttributes[attribute.name] = attribute.value\n .map((part) => (part as AST.Text).data)\n .join(\"\");\n }\n }\n return {\n attributeNames: attributes\n .filter(\n (attribute): attribute is AST.Attribute =>\n attribute.type === \"Attribute\",\n )\n .map((attribute) => attribute.name),\n hasSpreadAttributes: attributes.some(\n (attribute) => attribute.type === \"SpreadAttribute\",\n ),\n directiveTypes: attributes\n .filter(\n (attribute) =>\n attribute.type !== \"Attribute\" &&\n attribute.type !== \"SpreadAttribute\",\n )\n .map((attribute) => attribute.type),\n staticAttributes,\n styleDirectives: directives.map((directive) => {\n const literal = literalStyleDirective(source, directive, directives);\n return {\n name: directive.name,\n ...(literal ? { literal: literal.value } : {}),\n };\n }),\n };\n}\n\nconst PARSE_CACHE_LIMIT = 16;\nconst parseCache = new Map<string, InternalParseResult>();\n\nfunction rememberParse(key: string, result: InternalParseResult): void {\n parseCache.set(key, result);\n while (parseCache.size > PARSE_CACHE_LIMIT) {\n const oldest = parseCache.keys().next().value;\n if (oldest === undefined) break;\n parseCache.delete(oldest);\n }\n}\n\nexport function clearSvelteParseCacheForTests(): void {\n parseCache.clear();\n}\n\nfunction locateOpeningTagEnd(\n source: string,\n element: AST.RegularElement,\n):\n | { kind: \"ok\"; openingEnd: number; selfClosing: boolean }\n | { kind: \"invalid\"; message: string } {\n const lastAttribute = element.attributes[element.attributes.length - 1];\n const afterName = element.start + 1 + element.name.length;\n const cursor = lastAttribute?.end ?? afterName;\n const tail = source.slice(cursor, element.end);\n const closing = /^(\\s*)(\\/?)>/.exec(tail);\n /* v8 ignore next 6 -- invoked only for compiler-parsed RegularElements */\n if (!closing) {\n return {\n kind: \"invalid\",\n message: `could not locate the opening-tag terminator for <${element.name}> at UTF-16 offset ${element.start}`,\n };\n }\n return {\n kind: \"ok\",\n openingEnd: cursor + closing[0].length,\n selfClosing: closing[2] === \"/\",\n };\n}\n\nfunction locateClosingTagStart(\n source: string,\n element: AST.RegularElement,\n openingEnd: number,\n): number | null {\n const escapedName = element.name.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n const match = new RegExp(`</${escapedName}\\\\s*>$`).exec(\n source.slice(openingEnd, element.end),\n );\n return match ? openingEnd + match.index : null;\n}\n\nfunction containsDynamicSyntax(element: AST.RegularElement): boolean {\n let dynamic = false;\n walk(element as unknown as Parameters<typeof walk>[0], {\n enter(node) {\n const type = (node as { type?: unknown }).type;\n if (\n type === \"ExpressionTag\" ||\n type === \"HtmlTag\" ||\n type === \"RenderTag\" ||\n type === \"AttachTag\" ||\n type === \"ConstTag\" ||\n type === \"DeclarationTag\" ||\n type === \"DebugTag\" ||\n type === \"SpreadAttribute\" ||\n (typeof type === \"string\" && type.endsWith(\"Directive\")) ||\n type === \"Component\" ||\n type === \"SvelteComponent\" ||\n type === \"SvelteElement\" ||\n type === \"EachBlock\" ||\n type === \"IfBlock\" ||\n type === \"AwaitBlock\" ||\n type === \"KeyBlock\" ||\n type === \"SnippetBlock\"\n ) {\n dynamic = true;\n this.skip();\n }\n },\n });\n return dynamic;\n}\n\nfunction compilerError(\n error: unknown,\n): Extract<SvelteParseResult, { kind: \"invalid\" }> {\n if (error && typeof error === \"object\") {\n const value = error as { code?: unknown; message?: unknown };\n return {\n kind: \"invalid\",\n code: typeof value.code === \"string\" ? value.code : \"invalid_svelte\",\n message:\n typeof value.message === \"string\"\n ? value.message\n : /* v8 ignore next -- Svelte compiler diagnostics always carry messages */\n \"Svelte source could not be parsed\",\n };\n }\n /* v8 ignore next 5 -- Svelte compiler and parser throw diagnostic objects */\n return {\n kind: \"invalid\",\n code: \"invalid_svelte\",\n message: String(error),\n };\n}\n\nfunction toPublicElementInfo(element: InternalElementInfo): SvelteElementInfo {\n return {\n tagName: element.tagName,\n start: element.start,\n end: element.end,\n openingEnd: element.openingEnd,\n selfClosing: element.selfClosing,\n childrenStart: element.childrenStart,\n childrenEnd: element.childrenEnd,\n parentElementStart: element.parentElementStart,\n attributeNames: element.attributeNames,\n hasSpreadAttributes: element.hasSpreadAttributes,\n directiveTypes: element.directiveTypes,\n };\n}\n","import { sourceVersionHash } from \"@modules/annotation/source-version\";\nimport MagicString, { type SourceMap } from \"magic-string\";\nimport type { AST, PreprocessorGroup } from \"svelte/compiler\";\nimport { compile } from \"#svelte-compiler\";\nimport {\n applyStringEdits,\n mapOffsetThroughStringEdits,\n} from \"@modules/template-edits\";\nimport { escapeSvelteAttributeValue } from \"./escape\";\nimport { parseSvelteSourceInternal } from \"./parse\";\nimport type { StringEdit } from \"./types\";\n\nconst TEMPO_ATTRIBUTE_NAMES = [\n \"data-tempo-filepath\",\n \"data-tempo-position\",\n \"data-tempo-modifiedts\",\n \"data-tempo-source-version\",\n] as const;\nconst TEMPO_ATTRIBUTE_NAME_SET = new Set<string>(TEMPO_ATTRIBUTE_NAMES);\nexport const TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE =\n \"data-tempo-svelte-source-registry\";\n\nexport interface TempoSvelteComponentSourceRecord {\n readonly kind: \"component\";\n readonly name: string;\n /** Svelte dev metadata uses one-based lines and zero-based columns. */\n readonly line: number;\n readonly column: number;\n /** Exact UTF-16 offset in the annotation-free authored source. */\n readonly position: number;\n readonly className?: string;\n readonly style?: string;\n /** Literal author metadata on a component invocation, even when the\n * component does not forward it to a DOM host. */\n readonly locked?: boolean;\n /** Attributes written as expressions (`class={x}`, `class=\"a {b}\"`),\n * space separated as the canvas names them (`class` is `className`),\n * directives in their own spelling (`class:on`, `bind:value`),\n * `@attach`, and `#slot` when the element is a block's child (`{#each}`,\n * `{#if}`); the Svelte form of the JSX `data-tempo-expr` stamp. Empty\n * when a spread is the only one, absent when there is none. */\n readonly expressions?: string;\n readonly supportsClassName: boolean;\n readonly supportsStyle: boolean;\n}\n\nexport interface TempoSvelteHostSourceRecord {\n readonly kind: \"host\";\n readonly name: string;\n readonly line: number;\n readonly column: number;\n readonly position: number;\n readonly className?: string;\n readonly style?: string;\n /** Attributes written as expressions (`class={x}`, `class=\"a {b}\"`),\n * space separated as the canvas names them (`class` is `className`),\n * directives in their own spelling (`class:on`, `bind:value`),\n * `@attach`, and `#slot` when the element is a block's child (`{#each}`,\n * `{#if}`); the Svelte form of the JSX `data-tempo-expr` stamp. Empty\n * when a spread is the only one, absent when there is none. */\n readonly expressions?: string;\n readonly supportsClassName: boolean;\n readonly supportsStyle: boolean;\n}\n\nexport interface TempoSvelteSourceRegistryRecord {\n readonly filename: string;\n readonly filepath: string;\n readonly modifiedTs: number;\n readonly sourceVersion: string;\n readonly components: readonly TempoSvelteComponentSourceRecord[];\n readonly hosts: readonly TempoSvelteHostSourceRecord[];\n}\n\nexport interface AnnotateSvelteSourceOptions {\n source: string;\n filename: string;\n filepath: string;\n modifiedTs: number;\n sourceVersion?: string;\n /** `syntax` is for a first-in-chain preprocessor whose later stages validate. */\n validation?: \"compiler\" | \"syntax\";\n}\n\nexport type AnnotateSvelteSourceResult =\n | {\n kind: \"ok\";\n code: string;\n map: SourceMap;\n /** Insertion offsets in the annotated input passed to this call. */\n edits: readonly StringEdit[];\n elementsAnnotated: number;\n /** Recovered base-source offsets after existing annotations are removed. */\n skippedExistingAnnotations: readonly number[];\n sourceVersion: string;\n }\n | {\n kind: \"refused\";\n code:\n | \"invalid_source\"\n | \"invalid_output\"\n | \"invalid_metadata\"\n | \"annotation_conflict\";\n message: string;\n };\n\n/** Pure Svelte source annotation transform with exact original UTF-16 anchors. */\nexport function annotateSvelteSource(\n options: AnnotateSvelteSourceOptions,\n): AnnotateSvelteSourceResult {\n if (\n !options.filepath ||\n !options.filename ||\n !Number.isFinite(options.modifiedTs) ||\n !Number.isInteger(options.modifiedTs) ||\n options.modifiedTs < 0 ||\n options.sourceVersion === \"\"\n ) {\n return {\n kind: \"refused\",\n code: \"invalid_metadata\",\n message:\n \"filename, filepath, a non-negative integer modifiedTs, and a non-empty sourceVersion are required\",\n };\n }\n const inputSource = removeGeneratedSourceRegistries(options.source);\n const validation = options.validation ?? \"compiler\";\n const parsed = parseSvelteSourceInternal(\n inputSource,\n options.filename,\n validation,\n );\n if (parsed.kind === \"invalid\") {\n return { kind: \"refused\", code: \"invalid_source\", message: parsed.message };\n }\n\n const removalEdits: StringEdit[] = [];\n const existing = new Map<\n number,\n {\n filepath: string;\n position: number;\n modifiedTs: number;\n sourceVersion: string;\n }\n >();\n for (const element of parsed.elements.values()) {\n const tempoAttributes = element.node.attributes.filter(\n (attribute): attribute is AST.Attribute =>\n attribute.type === \"Attribute\" &&\n TEMPO_ATTRIBUTE_NAME_SET.has(attribute.name),\n );\n if (tempoAttributes.length === 0) continue;\n const conflict = readExistingAnnotation(inputSource, element.node);\n if (conflict.kind === \"refused\") return conflict;\n existing.set(element.start, conflict.metadata);\n removalEdits.push(conflict.removalEdit);\n }\n\n const baseSource = applyStringEdits(inputSource, removalEdits);\n const baseParsed = parseSvelteSourceInternal(\n baseSource,\n options.filename,\n validation,\n );\n /* v8 ignore next 6 -- exact generated-annotation removal from parsed input cannot invalidate syntax */\n if (baseParsed.kind === \"invalid\") {\n return {\n kind: \"refused\",\n code: \"annotation_conflict\",\n message:\n \"removing existing Tempo annotations did not recover valid source\",\n };\n }\n const version = options.sourceVersion ?? sourceVersionHash(baseSource);\n for (const [currentOffset, metadata] of existing) {\n const baseOffset = mapOffsetThroughStringEdits(currentOffset, removalEdits);\n if (\n baseOffset === null ||\n !baseParsed.elements.has(baseOffset) ||\n metadata.filepath !== options.filepath ||\n metadata.position !== baseOffset ||\n metadata.modifiedTs !== options.modifiedTs ||\n metadata.sourceVersion !== version\n ) {\n return {\n kind: \"refused\",\n code: \"annotation_conflict\",\n message: `existing Tempo annotations at UTF-16 offset ${currentOffset} do not exactly match the recovered source identity`,\n };\n }\n }\n\n const edits: StringEdit[] = [];\n const skippedExistingAnnotations: number[] = [];\n for (const element of parsed.elements.values()) {\n const baseOffset = mapOffsetThroughStringEdits(element.start, removalEdits);\n /* v8 ignore next 6 -- validated non-overlapping annotation removals preserve opening anchors */\n if (baseOffset === null || !baseParsed.elements.has(baseOffset)) {\n return {\n kind: \"refused\",\n code: \"annotation_conflict\",\n message: `could not map element at UTF-16 offset ${element.start} to recovered source`,\n };\n }\n if (existing.has(element.start)) {\n skippedExistingAnnotations.push(baseOffset);\n continue;\n }\n const insertionOffset =\n element.node.attributes[element.node.attributes.length - 1]?.end ??\n element.start + 1 + element.tagName.length;\n edits.push({\n start: insertionOffset,\n end: insertionOffset,\n replacement: serializeAnnotations({\n filepath: options.filepath,\n position: baseOffset,\n modifiedTs: options.modifiedTs,\n sourceVersion: version,\n }),\n });\n }\n\n // A comment marks the start of this invocation's roots without affecting\n // element selectors. @html keeps it present even with preserveComments off.\n // It follows a byte-order mark, which Svelte drops only as the file's\n // first character.\n const markupStart = inputSource.charCodeAt(0) === 0xfeff ? 1 : 0;\n const startEdit: StringEdit = {\n start: markupStart,\n end: markupStart,\n replacement: `{@html '<!--${TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE}-->'}`,\n };\n const annotationEdits = [startEdit, ...edits];\n const annotatedCode = applyStringEdits(inputSource, annotationEdits);\n const sourceRecords = buildSourceRecords({\n source: inputSource,\n parsed,\n removalEdits,\n annotationEdits,\n annotatedCode,\n });\n const registry: TempoSvelteSourceRegistryRecord = {\n filename: options.filename,\n filepath: options.filepath,\n modifiedTs: options.modifiedTs,\n sourceVersion: version,\n components: sourceRecords.components,\n hosts: sourceRecords.hosts,\n };\n const registryEdit: StringEdit = {\n start: inputSource.length,\n end: inputSource.length,\n replacement: `\\n<template ${TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE}=\"${escapeSvelteAttributeValue(JSON.stringify(registry), '\"')}\"></template>\\n`,\n };\n const transformEdits = [...annotationEdits, registryEdit];\n const code = applyStringEdits(inputSource, transformEdits);\n try {\n if (validation === \"compiler\") {\n compile(code, { filename: options.filename, generate: false });\n } else {\n const parsedOutput = parseSvelteSourceInternal(\n code,\n options.filename,\n \"syntax\",\n );\n if (parsedOutput.kind === \"invalid\")\n throw new Error(parsedOutput.message);\n }\n /* v8 ignore next 6 -- static attributes inserted into compiler-validated RegularElements are syntax-preserving */\n } catch (error) {\n return {\n kind: \"refused\",\n code: \"invalid_output\",\n message: error instanceof Error ? error.message : String(error),\n };\n }\n\n const magic = new MagicString(inputSource);\n for (const edit of transformEdits) {\n magic.appendLeft(edit.start, edit.replacement);\n }\n /* v8 ignore next 6 -- both outputs consume the same insertion-only edit list */\n if (magic.toString() !== code) {\n return {\n kind: \"refused\",\n code: \"invalid_output\",\n message: \"annotation code and source-map transform outputs diverged\",\n };\n }\n return {\n kind: \"ok\",\n code,\n map: magic.generateMap({\n source: options.filename,\n includeContent: true,\n hires: true,\n }),\n edits,\n elementsAnnotated: edits.length,\n skippedExistingAnnotations,\n sourceVersion: version,\n };\n}\n\nfunction removeGeneratedSourceRegistries(source: string): string {\n const escaped = TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE.replace(\n /[.*+?^${}()|[\\]\\\\]/g,\n \"\\\\$&\",\n );\n return source\n .replace(`{@html '<!--${TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE}-->'}`, \"\")\n .replace(\n new RegExp(\n `\\\\n?<template\\\\s+${escaped}=(?:\"[^\"]*\"|'[^']*')\\\\s*><\\\\/template>\\\\n?`,\n \"g\",\n ),\n \"\",\n );\n}\n\nfunction buildSourceRecords(options: {\n source: string;\n parsed: Extract<ReturnType<typeof parseSvelteSourceInternal>, { kind: \"ok\" }>;\n removalEdits: readonly StringEdit[];\n annotationEdits: readonly StringEdit[];\n annotatedCode: string;\n}): {\n components: TempoSvelteComponentSourceRecord[];\n hosts: TempoSvelteHostSourceRecord[];\n} {\n const components: TempoSvelteComponentSourceRecord[] = [];\n const hosts: TempoSvelteHostSourceRecord[] = [];\n for (const target of options.parsed.targets.values()) {\n if (\n target.kind !== \"component\" &&\n target.kind !== \"native-element\" &&\n target.kind !== \"dynamic-element\"\n ) {\n continue;\n }\n const position = mapOffsetThroughStringEdits(\n target.start,\n options.removalEdits,\n );\n if (position === null) continue;\n const compiledOffset = mapOffsetForward(\n target.start,\n options.annotationEdits,\n );\n const location = sourceLocationAt(options.annotatedCode, compiledOffset);\n const classValue = target.staticAttributes?.class;\n const styleValue = target.staticAttributes?.style;\n const lockValue = target.staticAttributes?.[\"data-tempo-locked\"];\n const hasSpread = target.hasSpreadAttributes === true;\n const directives = new Set(target.directiveTypes ?? []);\n const attributes = new Set(target.attributeNames ?? []);\n // A block child's own slot is dynamic, as a JSX `.map` root or\n // conditional branch is (`#slot`, user decision 2026-09-25: Svelte\n // follows the JSX rule). A written attribute with no literal value is\n // an expression.\n const blockChild = /Block$/.test(target.parentFragmentOwnerType ?? \"\");\n const node = options.parsed.targetNodes.get(target.start);\n // A directive or an attachment is written in the source and may show\n // nothing on the page (`class:on` while off): the canvas cannot learn\n // it from the DOM, so it is a fact here, in its own spelling.\n const directiveFacts = (node?.attributes ?? []).flatMap((attribute) => {\n if (\n attribute.type === \"Attribute\" ||\n attribute.type === \"SpreadAttribute\"\n )\n return [];\n // Svelte's AttributeLike type leaves out `{@attach}`, which the parser\n // still lists among the attributes.\n if ((attribute.type as string) === \"AttachTag\") return [\"@attach\"];\n const written = options.source.slice(attribute.start, attribute.end);\n return [written.split(\"=\")[0]!.trim()];\n });\n const expressions = [\n ...(blockChild ? [\"#slot\"] : []),\n ...[...attributes]\n .filter((name) => target.staticAttributes?.[name] === undefined)\n .map((name) => (name === \"class\" ? \"className\" : name)),\n ...directiveFacts,\n ].join(\" \");\n const common = {\n name: target.tagName,\n line: location.line,\n column: location.column,\n position,\n ...(typeof classValue === \"string\" ? { className: classValue } : {}),\n ...(typeof styleValue === \"string\" ? { style: styleValue } : {}),\n ...(lockValue === true || lockValue === \"true\" || lockValue === \"\"\n ? { locked: true }\n : lockValue === \"false\"\n ? { locked: false }\n : {}),\n // A spread gets a stamp even with no fact, as JSX's does.\n ...(expressions || hasSpread ? { expressions } : {}),\n supportsClassName:\n !hasSpread &&\n !directives.has(\"ClassDirective\") &&\n (!attributes.has(\"class\") || typeof classValue === \"string\"),\n supportsStyle:\n !hasSpread &&\n !directives.has(\"StyleDirective\") &&\n (!attributes.has(\"style\") || typeof styleValue === \"string\"),\n } as const;\n if (target.kind === \"component\") {\n components.push({ kind: \"component\", ...common });\n } else {\n hosts.push({ kind: \"host\", ...common });\n }\n }\n return { components, hosts };\n}\n\nfunction mapOffsetForward(\n offset: number,\n edits: readonly StringEdit[],\n): number {\n let mapped = offset;\n for (const edit of edits) {\n if (edit.start > offset) continue;\n mapped += edit.replacement.length - (edit.end - edit.start);\n }\n return mapped;\n}\n\nfunction sourceLocationAt(\n source: string,\n offset: number,\n): { line: number; column: number } {\n const before = source.slice(0, offset);\n const lines = before.split(\"\\n\");\n return {\n line: lines.length,\n column: lines[lines.length - 1]?.length ?? 0,\n };\n}\n\nexport interface CreateSvelteAnnotationPreprocessorOptions {\n metadata(input: { filename: string | undefined; source: string }): {\n filepath: string;\n modifiedTs: number;\n sourceVersion?: string;\n } | null;\n}\n\n/**\n * Create a Svelte markup preprocessor for raw-source annotations. It must be\n * first in the caller's preprocessor array so stored offsets identify the\n * authored file rather than another preprocessor's generated source.\n */\nexport function createSvelteAnnotationPreprocessor(\n options: CreateSvelteAnnotationPreprocessorOptions,\n): PreprocessorGroup {\n return {\n name: \"svelte-source-annotation\",\n markup: ({ content, filename }) => {\n const metadata = options.metadata({ filename, source: content });\n if (metadata === null) return undefined;\n const result = annotateSvelteSource({\n source: content,\n filename: filename ?? metadata.filepath,\n ...metadata,\n validation: \"syntax\",\n });\n if (result.kind === \"refused\") {\n throw new Error(`${result.code}: ${result.message}`);\n }\n return { code: result.code, map: result.map };\n },\n };\n}\n\ntype ExistingAnnotationRead =\n | {\n kind: \"ok\";\n metadata: {\n filepath: string;\n position: number;\n modifiedTs: number;\n sourceVersion: string;\n };\n removalEdit: StringEdit;\n }\n | Extract<AnnotateSvelteSourceResult, { kind: \"refused\" }>;\n\nfunction readExistingAnnotation(\n source: string,\n element: AST.RegularElement,\n): ExistingAnnotationRead {\n const attributes = element.attributes.filter(\n (attribute): attribute is AST.Attribute => attribute.type === \"Attribute\",\n );\n const tempo = attributes.filter((attribute) =>\n TEMPO_ATTRIBUTE_NAME_SET.has(attribute.name),\n );\n const names = tempo.map((attribute) => attribute.name);\n if (\n tempo.length !== TEMPO_ATTRIBUTE_NAMES.length ||\n TEMPO_ATTRIBUTE_NAMES.some((name, index) => names[index] !== name) ||\n attributes\n .slice(-TEMPO_ATTRIBUTE_NAMES.length)\n .some((attribute, index) => attribute !== tempo[index]) ||\n tempo.some((attribute) => !isStaticLiteralAttribute(attribute))\n ) {\n return annotationConflict(element.start);\n }\n const [\n filepathAttribute,\n positionAttribute,\n modifiedAttribute,\n versionAttribute,\n ] = tempo;\n /* v8 ignore next 7 -- the length and ordered-name checks above prove all tuple members exist */\n if (\n !filepathAttribute ||\n !positionAttribute ||\n !modifiedAttribute ||\n !versionAttribute\n ) {\n return annotationConflict(element.start);\n }\n const filepath = staticLiteralAttributeValue(filepathAttribute);\n const positionText = staticLiteralAttributeValue(positionAttribute);\n const modifiedText = staticLiteralAttributeValue(modifiedAttribute);\n const sourceVersion = staticLiteralAttributeValue(versionAttribute);\n const position = Number(positionText);\n const modifiedTs = Number(modifiedText);\n const first = tempo[0];\n const last = tempo[tempo.length - 1];\n if (\n !first ||\n !last ||\n source[first.start - 1] !== \" \" ||\n !Number.isSafeInteger(position) ||\n position < 0 ||\n !Number.isSafeInteger(modifiedTs) ||\n modifiedTs < 0 ||\n !filepath ||\n !sourceVersion\n ) {\n return annotationConflict(element.start);\n }\n const expected = serializeAnnotations({\n filepath,\n position,\n modifiedTs,\n sourceVersion,\n }).slice(1);\n if (source.slice(first.start, last.end) !== expected) {\n return annotationConflict(element.start);\n }\n return {\n kind: \"ok\",\n metadata: { filepath, position, modifiedTs, sourceVersion },\n removalEdit: {\n start: first.start - 1,\n end: last.end,\n replacement: \"\",\n },\n };\n}\n\nfunction annotationConflict(\n offset: number,\n): Extract<AnnotateSvelteSourceResult, { kind: \"refused\" }> {\n return {\n kind: \"refused\",\n code: \"annotation_conflict\",\n message: `element at UTF-16 offset ${offset} has partial, dynamic, reordered, or conflicting Tempo annotations`,\n };\n}\n\nfunction isStaticLiteralAttribute(attribute: AST.Attribute): boolean {\n return (\n Array.isArray(attribute.value) &&\n attribute.value.every((part) => part.type === \"Text\")\n );\n}\n\nfunction staticLiteralAttributeValue(attribute: AST.Attribute): string {\n /* v8 ignore next -- callers first prove the attribute is a static Text array */\n return Array.isArray(attribute.value)\n ? attribute.value\n .map((part) => (part.type === \"Text\" ? part.data : \"\"))\n .join(\"\")\n : \"\";\n}\n\nfunction serializeAnnotations(metadata: {\n filepath: string;\n position: number;\n modifiedTs: number;\n sourceVersion: string;\n}): string {\n const values = {\n \"data-tempo-filepath\": metadata.filepath,\n \"data-tempo-position\": String(metadata.position),\n \"data-tempo-modifiedts\": String(metadata.modifiedTs),\n \"data-tempo-source-version\": metadata.sourceVersion,\n };\n return Object.entries(values)\n .map(\n ([name, value]) => ` ${name}=\"${escapeSvelteAttributeValue(value, '\"')}\"`,\n )\n .join(\"\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAQA,SAAS,oBAAoB;AAC7B,SAAS,eAAe;;;ACFxB,YAAY,oBAAoB;;;ACCzB,SAAS,qBAAqB,QAAwB;AAC3D,SAAO,OAAO,WAAW,CAAC,MAAM,QAAS,IAAI,OAAO,MAAM,CAAC,CAAC,KAAK;AACnE;;;ADAO,IAAMA,WAAyC,CAAC,QAAQ,YAC9C,uBAAQ,qBAAqB,MAAM,GAAG,OAAO;AAGvD,IAAMC,UAAS,CACpB,QACA,YAEe;AAAA,EACb,qBAAqB,MAAM;AAAA,EAC3B;AACF;;;AErBK,SAAS,2BACd,OACA,OACQ;AACR,MAAI,UAAU,MACX,MAAM,GAAG,EACT,KAAK,OAAO,EACZ,MAAM,GAAG,EACT,KAAK,MAAM,EACX,MAAM,GAAG,EACT,KAAK,MAAM,EACX,MAAM,GAAG,EACT,KAAK,QAAQ,EACb,MAAM,GAAG,EACT,KAAK,QAAQ;AAChB,YACE,UAAU,MACN,QAAQ,MAAM,GAAG,EAAE,KAAK,QAAQ,IAChC,QAAQ,MAAM,GAAG,EAAE,KAAK,OAAO;AACrC,SAAO;AACT;;;ACXO,IAAM,aAAN,MAAiB;AAAA,EACvB,cAAc;AAEb,SAAK,cAAc;AAGnB,SAAK,gBAAgB;AAGrB,SAAK,cAAc;AAGnB,SAAK,UAAU;AAAA,MACd,MAAM,MAAO,KAAK,cAAc;AAAA,MAChC,QAAQ,MAAO,KAAK,gBAAgB;AAAA,MACpC,SAAS,CAAC,SAAU,KAAK,cAAc;AAAA,IACxC;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,QAAQ,QAAQ,MAAM,OAAO,MAAM;AAClC,QAAI,UAAU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