tempo-sdk 0.0.60 → 0.0.66

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 (108) hide show
  1. package/astro/client.d.ts +4 -0
  2. package/dist/assets/editor.js +1 -1
  3. package/dist/assets/index.d.ts +10 -63
  4. package/dist/assets/index.js +12 -32
  5. package/dist/assets/index.js.map +1 -1
  6. package/dist/assets/parser.js +1 -1
  7. package/dist/astro/asset-preview-client.d.ts +4 -0
  8. package/dist/astro/asset-preview-client.js +93 -0
  9. package/dist/astro/asset-preview-client.js.map +1 -0
  10. package/dist/astro/controls.d.ts +7 -0
  11. package/dist/astro/controls.js +7 -0
  12. package/dist/astro/controls.js.map +1 -0
  13. package/dist/astro/document-client.d.ts +10 -0
  14. package/dist/astro/document-client.js +78 -0
  15. package/dist/astro/document-client.js.map +1 -0
  16. package/dist/astro/runtime.d.ts +15 -0
  17. package/dist/astro/runtime.js +86 -0
  18. package/dist/astro/runtime.js.map +1 -0
  19. package/dist/astro.d.ts +21 -0
  20. package/dist/astro.js +749 -0
  21. package/dist/astro.js.map +1 -0
  22. package/dist/canvas/astro-contract.d.ts +21 -0
  23. package/dist/canvas/astro-contract.js +9 -0
  24. package/dist/canvas/astro-contract.js.map +1 -0
  25. package/dist/canvas/astro.d.ts +18 -0
  26. package/dist/canvas/astro.js +42 -0
  27. package/dist/canvas/astro.js.map +1 -0
  28. package/dist/canvas/editor.d.ts +1 -1
  29. package/dist/canvas/editor.js +3 -2
  30. package/dist/canvas/editor.js.map +1 -1
  31. package/dist/canvas/index.d.ts +1 -1
  32. package/dist/canvas/index.js +40 -16
  33. package/dist/canvas/index.js.map +1 -1
  34. package/dist/canvas/interact-projection.js +4 -4
  35. package/dist/canvas/parser.d.ts +3 -1
  36. package/dist/canvas/parser.js +1 -1
  37. package/dist/canvas/svelte.d.ts +1 -1
  38. package/dist/canvas/svelte.js +3 -3
  39. package/dist/{chunk-5BHIHP25.js → chunk-2JRAG36X.js} +37 -11
  40. package/dist/chunk-2JRAG36X.js.map +1 -0
  41. package/dist/{chunk-N2TYN3RB.js → chunk-6AAE4LYV.js} +123 -123
  42. package/dist/chunk-6AAE4LYV.js.map +1 -0
  43. package/dist/{chunk-7DT5DDSH.js → chunk-6IR5JY6W.js} +106 -7
  44. package/dist/chunk-6IR5JY6W.js.map +1 -0
  45. package/dist/{chunk-FQSZRVSL.js → chunk-6W6UKDSY.js} +45 -4
  46. package/dist/chunk-6W6UKDSY.js.map +1 -0
  47. package/dist/chunk-77DZCV5Z.js +38 -0
  48. package/dist/chunk-77DZCV5Z.js.map +1 -0
  49. package/dist/chunk-DELFOKU3.js +2495 -0
  50. package/dist/chunk-DELFOKU3.js.map +1 -0
  51. package/dist/{chunk-MXKZZOLM.js → chunk-EYKOOLPL.js} +368 -32
  52. package/dist/chunk-EYKOOLPL.js.map +1 -0
  53. package/dist/chunk-F23JGM4U.js +107 -0
  54. package/dist/chunk-F23JGM4U.js.map +1 -0
  55. package/dist/chunk-FE6TYCLF.js +1514 -0
  56. package/dist/chunk-FE6TYCLF.js.map +1 -0
  57. package/dist/chunk-H6OZIX2U.js +133 -0
  58. package/dist/chunk-H6OZIX2U.js.map +1 -0
  59. package/dist/chunk-JVVHU3A7.js +1077 -0
  60. package/dist/chunk-JVVHU3A7.js.map +1 -0
  61. package/dist/{chunk-2IQD2KPS.js → chunk-KOSJXE4G.js} +3 -102
  62. package/dist/chunk-KOSJXE4G.js.map +1 -0
  63. package/dist/{chunk-TL4MGN7E.js → chunk-NSKYOKG5.js} +254 -10
  64. package/dist/chunk-NSKYOKG5.js.map +1 -0
  65. package/dist/chunk-OX2YKYSL.js +13 -0
  66. package/dist/chunk-OX2YKYSL.js.map +1 -0
  67. package/dist/{chunk-VMTQDG4U.js → chunk-PXDTH36X.js} +12 -10
  68. package/dist/chunk-PXDTH36X.js.map +1 -0
  69. package/dist/{chunk-XLEKCOB7.js → chunk-PYAJHLXO.js} +56 -1
  70. package/dist/chunk-PYAJHLXO.js.map +1 -0
  71. package/dist/{chunk-OTVBSF7U.js → chunk-Q2A46HHW.js} +17 -12
  72. package/dist/chunk-Q2A46HHW.js.map +1 -0
  73. package/dist/controls-reader-SNMI2UY7.js +191 -0
  74. package/dist/controls-reader-SNMI2UY7.js.map +1 -0
  75. package/dist/controls-uCaQ3CNX.d.ts +61 -0
  76. package/dist/expo/plugin.cjs +16 -11
  77. package/dist/expo/plugin.cjs.map +1 -1
  78. package/dist/expo/plugin.js +1 -1
  79. package/dist/expo-babel-plugin.cjs +16 -11
  80. package/dist/expo-babel-plugin.cjs.map +1 -1
  81. package/dist/expo-babel-plugin.js +1 -1
  82. package/dist/index.d.ts +4 -0
  83. package/dist/index.js +10 -2465
  84. package/dist/index.js.map +1 -1
  85. package/dist/nextjs/plugin.cjs +44 -3
  86. package/dist/nextjs/plugin.cjs.map +1 -1
  87. package/dist/nextjs/plugin.js +1 -1
  88. package/dist/nextjs-loader.cjs +60 -14
  89. package/dist/nextjs-loader.cjs.map +1 -1
  90. package/dist/nextjs.cjs +44 -3
  91. package/dist/nextjs.cjs.map +1 -1
  92. package/dist/nextjs.d.cts +4 -4
  93. package/dist/nextjs.d.ts +4 -4
  94. package/dist/nextjs.js +1 -1
  95. package/dist/{storyboard-DjOF61B_.d.ts → storyboard-4YdTYq_e.d.ts} +1 -1
  96. package/dist/svelte.js +7 -1075
  97. package/dist/svelte.js.map +1 -1
  98. package/package.json +44 -3
  99. package/dist/chunk-2IQD2KPS.js.map +0 -1
  100. package/dist/chunk-5BHIHP25.js.map +0 -1
  101. package/dist/chunk-7DT5DDSH.js.map +0 -1
  102. package/dist/chunk-FQSZRVSL.js.map +0 -1
  103. package/dist/chunk-MXKZZOLM.js.map +0 -1
  104. package/dist/chunk-N2TYN3RB.js.map +0 -1
  105. package/dist/chunk-OTVBSF7U.js.map +0 -1
  106. package/dist/chunk-TL4MGN7E.js.map +0 -1
  107. package/dist/chunk-VMTQDG4U.js.map +0 -1
  108. package/dist/chunk-XLEKCOB7.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../canvas/editor.ts","../../canvas/v1-file-compat.ts"],"sourcesContent":["import { parseSync } from \"oxc-parser\";\n\nimport {\n parseCanvasFile,\n type CanvasSourceSpan,\n type ParsedCanvasFile,\n type ParsedCanvasImport,\n type ParsedCanvasStoryboard,\n} from \"./parser\";\nimport type { V1LayoutCompat } from \"./v1-client-compat\";\nimport { v1LayoutHint, v1ReadableLayout } from \"./v1-file-compat\";\n\nexport type CanvasSourceEdit = {\n start: number;\n end: number;\n value: string;\n};\n\nexport type CanvasEditResult = {\n source: string;\n edits: CanvasSourceEdit[];\n parsed: ParsedCanvasFile;\n};\n\nexport type CanvasEditorLayout = {\n x: number;\n y: number;\n width?: number;\n height?: number;\n zIndex?: number;\n};\n\nexport type AddCanvasStoryboardInput =\n | {\n kind: \"component\";\n /** The component's authored framework, as the declaration and the\n * parser spell it: a Svelte component is written as\n * `<SvelteStoryboard>` from \"tempo-sdk/canvas/svelte\". */\n uiFramework?: \"svelte\";\n id: string;\n /** Migration passes a legacy responsive layout in its V1-readable\n * spelling (see v1-file-compat.ts). */\n layout: CanvasEditorLayout & V1LayoutCompat;\n name?: string;\n componentExpression?: string;\n // Pre-formatted object-literal expression (e.g. `{ a: \"s\", b: expr }`)\n // emitted as `props={<value>}` after `component=`. Used by migration to\n // render `render: () => <C a={b} />` as `component={C} props={{ a: b }}`.\n props?: string;\n componentImport?: {\n localName: string;\n source: string;\n importedName?: string;\n };\n }\n | {\n // Per-storyboard fallback for legacy object shapes migration cannot\n // convert natively: emits `<LegacyStoryboardV1 id storyboard={Expr} />`.\n // The wrapper reads name/layout off the referenced object, so no\n // name/layout attributes are emitted here.\n kind: \"legacy-v1\";\n id: string;\n storyboardExpression: string;\n }\n | {\n kind: \"route\";\n id: string;\n route: string;\n layout: CanvasEditorLayout;\n name?: string;\n }\n | {\n kind: \"html\";\n id: string;\n layout: CanvasEditorLayout;\n name?: string;\n filepath?: string;\n src?: string;\n };\n\ntype SdkComponent =\n | \"Storyboard\"\n | \"SvelteStoryboard\"\n | \"LegacyStoryboardV1\"\n | \"RouteStoryboard\"\n | \"HtmlStoryboard\";\n\nexport function applyCanvasSourceEdits(\n source: string,\n edits: readonly CanvasSourceEdit[],\n): string {\n const sorted = [...edits].sort((left, right) => right.start - left.start);\n let previousStart = source.length + 1;\n let nextSource = source;\n\n for (const edit of sorted) {\n if (\n edit.start < 0 ||\n edit.end < edit.start ||\n edit.end > source.length ||\n edit.end > previousStart\n ) {\n throw new Error(\n `Invalid overlapping canvas source edit ${edit.start}:${edit.end}`,\n );\n }\n nextSource =\n nextSource.slice(0, edit.start) + edit.value + nextSource.slice(edit.end);\n previousStart = edit.start;\n }\n\n return nextSource;\n}\n\nexport function updateCanvasName(options: {\n filePath: string;\n source: string;\n name: string;\n}): CanvasEditResult {\n return editCanvasStringAttribute(\n options,\n \"name\",\n requireNonEmpty(options.name, \"Canvas name\"),\n (parsed) => ({\n valueSpan: parsed.nameSpan,\n attributeSpan: parsed.nameAttributeSpan,\n }),\n );\n}\n\nexport function updateCanvasPath(options: {\n filePath: string;\n source: string;\n path: string;\n}): CanvasEditResult {\n return editCanvasStringAttribute(\n options,\n \"path\",\n requireNonEmpty(options.path, \"Canvas path\"),\n (parsed) => ({\n valueSpan: parsed.pathSpan,\n attributeSpan: parsed.pathAttributeSpan,\n }),\n );\n}\n\nexport function updateCanvasBackgroundColor(options: {\n filePath: string;\n source: string;\n backgroundColor?: string;\n}): CanvasEditResult {\n return editCanvasStringAttribute(\n options,\n \"backgroundColor\",\n options.backgroundColor && options.backgroundColor.trim() !== \"\"\n ? options.backgroundColor\n : undefined,\n (parsed) => ({\n valueSpan: parsed.backgroundColorSpan,\n attributeSpan: parsed.backgroundColorAttributeSpan,\n }),\n );\n}\n\nfunction editCanvasStringAttribute(\n options: { filePath: string; source: string },\n attributeName: string,\n value: string | undefined,\n selectSpans: (parsed: ParsedCanvasFile) => {\n valueSpan?: CanvasSourceSpan;\n attributeSpan?: CanvasSourceSpan;\n },\n): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const spans = selectSpans(parsed);\n const edit = upsertJsxStringAttribute({\n source: options.source,\n openingElementSpan: requiredSpan(\n parsed.canvasOpeningElementSpan,\n \"Canvas opening element not found\",\n ),\n valueSpan: spans.valueSpan,\n attributeSpan: spans.attributeSpan,\n name: attributeName,\n value,\n });\n return applyResult(options.source, parsed, edit ? [edit] : []);\n}\n\nexport function updateStoryboardName(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n name?: string;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n if (storyboard.legacyV1) {\n const edit = upsertObjectStringProperty({\n source: options.source,\n objectClose: storyboard.legacyV1.objectClose,\n valueSpan: storyboard.nameSpan,\n propertySpan: storyboard.legacyV1.namePropertySpan,\n name: \"name\",\n value:\n options.name && options.name.trim() !== \"\" ? options.name : undefined,\n });\n return applyResult(options.source, parsed, edit ? [edit] : []);\n }\n\n const edit = upsertJsxStringAttribute({\n source: options.source,\n openingElementSpan: requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n ),\n valueSpan: storyboard.nameSpan,\n attributeSpan: storyboard.nameAttributeSpan,\n name: \"name\",\n value:\n options.name && options.name.trim() !== \"\" ? options.name : undefined,\n });\n return applyResult(options.source, parsed, edit ? [edit] : []);\n}\n\nexport function updateStoryboardId(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n nextId: string;\n}): CanvasEditResult {\n const nextId = requireNonEmpty(options.nextId, \"Storyboard id\");\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n const duplicate = parsed.storyboards.find(\n (item) =>\n item.storyboardKey === nextId &&\n item.storyboardKey !== storyboard.storyboardKey,\n );\n if (duplicate) {\n throw new Error(`Storyboard id \"${nextId}\" already exists`);\n }\n const edit = upsertJsxStringAttribute({\n source: options.source,\n openingElementSpan: requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n ),\n valueSpan: storyboard.idSpan,\n attributeSpan: storyboard.idAttributeSpan,\n name: \"id\",\n value: nextId,\n });\n return applyResult(options.source, parsed, [edit]);\n}\n\nexport function updateStoryboardLayout(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n layout: Partial<CanvasEditorLayout>;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n const spans = storyboard.layoutSpans;\n if (!spans) {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" has no editable layout`,\n );\n }\n\n const span =\n storyboard.legacyV1?.layoutPropertySpan ?? storyboard.layoutAttributeSpan;\n if (!span || spans.layoutClose === undefined) {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" has no editable layout`,\n );\n }\n for (const key of [\"x\", \"y\", \"width\", \"height\", \"zIndex\"] as const) {\n if (\n parsed.errors.some(\n (error) =>\n error.span &&\n error.span.start >= span.start &&\n error.span.end <= span.end &&\n error.message.includes(`layout.${key} must be a number literal`),\n )\n ) {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" layout.${key} is not editable`,\n );\n }\n }\n const layout = { ...storyboard.layout, ...options.layout };\n if (\n storyboard.kind === \"component\" &&\n storyboard.layout.width === undefined &&\n storyboard.layout.height === undefined\n ) {\n delete layout.width;\n delete layout.height;\n }\n if ((layout.width === undefined) !== (layout.height === undefined)) {\n throw new Error(\"layout.width and layout.height must be set together\");\n }\n if (storyboard.kind !== \"component\" && layout.width === undefined) {\n throw new Error(\"Route and HTML layouts require width and height\");\n }\n for (const key of [\"x\", \"y\"] as const) {\n if (options.layout[key] !== undefined && !spans[key]) {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" layout.${key} is not editable`,\n );\n }\n }\n // A responsive board keeps the first-paint hint its literal already\n // carries, so the rewritten literal stays readable to a V1 client.\n const written = v1ReadableLayout(\n layout,\n v1LayoutHint(options.source.slice(span.start, span.end)),\n );\n return applyResult(options.source, parsed, [\n {\n start: span.start,\n end: span.end,\n value: storyboard.legacyV1\n ? `layout: { ${formatLayout(written)} }`\n : `layout={{ ${formatLayout(written)} }}`,\n },\n ]);\n}\n\nexport function updateStoryboardComponent(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n componentExpression: string;\n componentImport?: {\n localName: string;\n source: string;\n importedName?: string;\n };\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n if (storyboard.kind !== \"component\") {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" is not a component storyboard`,\n );\n }\n\n const imports: string[] = [];\n if (options.componentImport) {\n const importLine = buildMissingComponentImportLine(\n parsed,\n options.source,\n options.componentImport,\n );\n if (importLine) imports.push(importLine);\n }\n\n const importEdit = buildImportInsertionEdit(options.source, parsed, imports);\n const componentEdit = upsertJsxExpressionAttribute({\n source: options.source,\n openingElementSpan: requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n ),\n expressionSpan: storyboard.component?.span,\n attributeSpan: storyboard.component?.attributeSpan,\n name: \"component\",\n value: requireNonEmpty(\n options.componentExpression,\n \"Storyboard component expression\",\n ),\n });\n\n return applyResult(options.source, parsed, [\n ...(importEdit ? [importEdit] : []),\n componentEdit,\n ]);\n}\n\nexport function updateStoryboardProps(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n propsExpression?: string;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n const edit = upsertJsxExpressionAttribute({\n source: options.source,\n openingElementSpan: requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n ),\n expressionSpan: storyboard.props?.span,\n attributeSpan: storyboard.props?.attributeSpan,\n name: \"props\",\n value:\n options.propsExpression && options.propsExpression.trim() !== \"\"\n ? options.propsExpression.trim()\n : undefined,\n });\n return applyResult(options.source, parsed, edit ? [edit] : []);\n}\n\n/** Literal `vrt` options an editor may write (TEM-1775). Mirrors the parsed\n * shape: `threshold` 0..0.5, `skip` pauses without losing config, `ignore`\n * regions are storyboard-local CSS px. */\nexport type StoryboardVrtConfigInput = {\n threshold?: number;\n skip?: boolean;\n ignore?: Array<{ x: number; y: number; w: number; h: number }>;\n};\n\n/**\n * Sets or clears the opt-in visual-regression tracking mark (TEM-1775) on a\n * component storyboard. `tracked: true` writes the bare `vrt` attribute\n * (tracked with defaults), replacing an existing untracked declaration\n * (`vrt={false}`, dynamic forms) in place; an already-tracked declaration —\n * including the object form with threshold/ignore overrides — is left\n * untouched. `tracked: false` removes the whole `vrt` attribute, object\n * config included: the in-app toggle is a full untrack, not the\n * `skip: true` pause. An OBJECT `tracked` writes that exact literal config\n * (`vrt={{ threshold, skip, ignore }}`), replacing whatever declaration\n * exists — the agent-facing `canvas_set_vrt` path for thresholds, masks and\n * pauses; an empty object is the bare mark.\n */\nexport function updateStoryboardVrt(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n tracked: boolean | StoryboardVrtConfigInput;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n if (storyboard.kind === \"route\") {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" is a route storyboard; VRT supports component and local HTML storyboards`,\n );\n }\n\n if (typeof options.tracked === \"object\") {\n const literal = formatStoryboardVrtConfig(options.tracked);\n const attributeText = literal === null ? \"vrt\" : `vrt={${literal}}`;\n if (storyboard.vrtAttributeSpan) {\n return applyResult(options.source, parsed, [\n {\n start: storyboard.vrtAttributeSpan.start,\n end: storyboard.vrtAttributeSpan.end,\n value: attributeText,\n },\n ]);\n }\n return applyResult(options.source, parsed, [\n insertBareJsxAttributeLine({\n source: options.source,\n openingElementSpan: requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n ),\n name: attributeText,\n }),\n ]);\n }\n\n if (!options.tracked) {\n if (!storyboard.vrtAttributeSpan) {\n return applyResult(options.source, parsed, []);\n }\n return applyResult(options.source, parsed, [\n {\n ...expandJsxAttributeRemoval(\n options.source,\n storyboard.vrtAttributeSpan,\n ),\n value: \"\",\n },\n ]);\n }\n\n if (storyboard.vrt) {\n return applyResult(options.source, parsed, []);\n }\n const openingElementSpan = requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n );\n if (storyboard.vrtAttributeSpan) {\n return applyResult(options.source, parsed, [\n {\n ...expandJsxAttributeRemoval(\n options.source,\n storyboard.vrtAttributeSpan,\n ),\n value: \"\",\n },\n insertBareJsxAttributeLine({\n source: options.source,\n openingElementSpan,\n name: \"vrt\",\n }),\n ]);\n }\n return applyResult(options.source, parsed, [\n insertBareJsxAttributeLine({\n source: options.source,\n openingElementSpan,\n name: \"vrt\",\n }),\n ]);\n}\n\n/**\n * Renders a literal `vrt` object the parser accepts back (`readVrt`: number\n * literal threshold in 0..0.5, boolean `skip`, `{ x, y, w, h }` number\n * literal regions), validating the same rules up front so an editor never\n * writes a declaration the parser would then degrade. Returns `null` for an\n * empty config — the bare `vrt` mark says the same thing.\n */\nfunction formatStoryboardVrtConfig(\n config: StoryboardVrtConfigInput,\n): string | null {\n const parts: string[] = [];\n if (config.threshold !== undefined) {\n if (\n typeof config.threshold !== \"number\" ||\n !Number.isFinite(config.threshold) ||\n config.threshold < 0 ||\n config.threshold > 0.5\n ) {\n throw new Error(\"vrt.threshold must be a number between 0 and 0.5\");\n }\n parts.push(`threshold: ${config.threshold}`);\n }\n if (config.skip !== undefined) {\n if (typeof config.skip !== \"boolean\") {\n throw new Error(\"vrt.skip must be a boolean\");\n }\n parts.push(`skip: ${config.skip}`);\n }\n if (config.ignore !== undefined) {\n if (!Array.isArray(config.ignore)) {\n throw new Error(\"vrt.ignore must be an array of { x, y, w, h } regions\");\n }\n const regions = config.ignore.map((region) => {\n for (const key of [\"x\", \"y\", \"w\", \"h\"] as const) {\n const value = region?.[key];\n if (typeof value !== \"number\" || !Number.isFinite(value) || value < 0) {\n throw new Error(\n `vrt.ignore regions must be { x, y, w, h } non-negative numbers (bad ${key})`,\n );\n }\n }\n return `{ x: ${region.x}, y: ${region.y}, w: ${region.w}, h: ${region.h} }`;\n });\n if (regions.length > 0) {\n parts.push(`ignore: [${regions.join(\", \")}]`);\n }\n }\n return parts.length === 0 ? null : `{ ${parts.join(\", \")} }`;\n}\n\nexport function updateRouteStoryboardRoute(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n route: string;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n if (storyboard.kind !== \"route\") {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" is not a route storyboard`,\n );\n }\n const edit = upsertJsxStringAttribute({\n source: options.source,\n openingElementSpan: requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n ),\n valueSpan: storyboard.routeSpan,\n attributeSpan: storyboard.routeAttributeSpan,\n name: \"route\",\n value: requireNonEmpty(options.route, \"Route storyboard route\"),\n });\n return applyResult(options.source, parsed, [edit]);\n}\n\nexport function updateHtmlStoryboardSource(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n filepath?: string;\n src?: string;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n if (storyboard.kind !== \"html\") {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" is not an html storyboard`,\n );\n }\n const filepath =\n options.filepath && options.filepath.trim() !== \"\"\n ? options.filepath.trim()\n : undefined;\n const src =\n options.src && options.src.trim() !== \"\" ? options.src : undefined;\n if (!filepath && !src) {\n throw new Error(\"HTML storyboard source requires filepath or src\");\n }\n\n const openingElementSpan = requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n );\n const filepathEdit = upsertJsxStringAttribute({\n source: options.source,\n openingElementSpan,\n valueSpan: storyboard.filepathSpan,\n attributeSpan: storyboard.filepathAttributeSpan,\n name: \"filepath\",\n value: filepath,\n });\n const srcEdit = upsertJsxStringAttribute({\n source: options.source,\n openingElementSpan,\n valueSpan: storyboard.srcSpan,\n attributeSpan: storyboard.srcAttributeSpan,\n name: \"src\",\n value: src,\n });\n\n return applyResult(options.source, parsed, [filepathEdit, srcEdit]);\n}\n\nexport function addCanvasStoryboard(options: {\n filePath: string;\n source: string;\n storyboard: AddCanvasStoryboardInput;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n if (\n parsed.storyboards.some(\n (item) => item.storyboardKey === options.storyboard.id,\n )\n ) {\n throw new Error(`Storyboard id \"${options.storyboard.id}\" already exists`);\n }\n\n const imports: string[] = [];\n const sdkComponent = sdkComponentForStoryboard(options.storyboard);\n const sdkTag = resolveSdkTag(parsed, sdkComponent);\n let storyboardTag = sdkTag.tag;\n if (sdkTag.importLine) {\n imports.push(sdkTag.importLine);\n storyboardTag = sdkTag.tag;\n }\n\n let componentExpression: string | undefined;\n if (options.storyboard.kind === \"component\") {\n componentExpression =\n options.storyboard.componentExpression ??\n options.storyboard.componentImport?.localName;\n if (!componentExpression) {\n throw new Error(\n \"Component storyboard requires componentExpression or componentImport\",\n );\n }\n if (options.storyboard.componentImport) {\n const importLine = buildMissingComponentImportLine(\n parsed,\n options.source,\n options.storyboard.componentImport,\n );\n if (importLine) imports.push(importLine);\n }\n }\n\n const importEdit = buildImportInsertionEdit(options.source, parsed, imports);\n const insertionEdit = buildCanvasChildInsertionEdit({\n source: options.source,\n parsed,\n tag: storyboardTag,\n storyboard: options.storyboard,\n componentExpression,\n });\n\n const edits = [...(importEdit ? [importEdit] : []), insertionEdit];\n return applyResult(options.source, parsed, edits);\n}\n\nexport function removeCanvasStoryboard(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n removeUnusedComponentImport?: boolean;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n const edits: CanvasSourceEdit[] = [\n {\n ...expandToFullLines(options.source, storyboard.jsxElementSpan),\n value: \"\",\n },\n ];\n\n if (options.removeUnusedComponentImport ?? true) {\n const importEdit = buildUnusedComponentImportRemoval({\n source: options.source,\n parsed,\n deletedStoryboard: storyboard,\n deletionEdit: edits[0],\n });\n if (importEdit) edits.push(importEdit);\n }\n\n const result = applyResult(options.source, parsed, edits);\n return {\n ...result,\n source: collapseBlankLines(result.source, detectNewline(options.source)),\n };\n}\n\nfunction applyResult(\n source: string,\n parsed: ParsedCanvasFile,\n edits: readonly (CanvasSourceEdit | null | undefined)[],\n): CanvasEditResult {\n const compactEdits = edits.filter((edit): edit is CanvasSourceEdit => {\n if (!edit) return false;\n return source.slice(edit.start, edit.end) !== edit.value;\n });\n return {\n source: applyCanvasSourceEdits(source, compactEdits),\n edits: compactEdits,\n parsed,\n };\n}\n\nfunction findStoryboard(\n parsed: ParsedCanvasFile,\n storyboardId: string,\n): ParsedCanvasStoryboard {\n const storyboard = parsed.storyboards.find(\n (item) => item.storyboardKey === storyboardId,\n );\n if (!storyboard) {\n throw new Error(`Storyboard \"${storyboardId}\" not found`);\n }\n return storyboard;\n}\n\nfunction requireStoryboardOpeningSpan(\n storyboard: ParsedCanvasStoryboard,\n storyboardId: string,\n): CanvasSourceSpan {\n return requiredSpan(\n storyboard.openingElementSpan,\n `Storyboard \"${storyboardId}\" opening element not found`,\n );\n}\n\nfunction upsertJsxStringAttribute(options: {\n source: string;\n openingElementSpan: CanvasSourceSpan;\n valueSpan?: CanvasSourceSpan;\n attributeSpan?: CanvasSourceSpan;\n name: string;\n value?: string;\n}): CanvasSourceEdit | null {\n if (options.value === undefined) {\n if (!options.attributeSpan) return null;\n return {\n ...expandJsxAttributeRemoval(options.source, options.attributeSpan),\n value: \"\",\n };\n }\n\n const value = JSON.stringify(options.value);\n if (options.valueSpan) {\n return {\n start: options.valueSpan.start,\n end: options.valueSpan.end,\n value,\n };\n }\n\n const offset = findOpeningElementAttributeInsertionOffset(\n options.source,\n options.openingElementSpan,\n );\n return {\n start: offset,\n end: offset,\n value: ` ${options.name}={${value}}`,\n };\n}\n\nfunction upsertObjectStringProperty(options: {\n source: string;\n objectClose?: number;\n valueSpan?: CanvasSourceSpan;\n propertySpan?: CanvasSourceSpan;\n name: string;\n value?: string;\n}): CanvasSourceEdit | null {\n if (options.value === undefined) {\n if (!options.propertySpan) return null;\n return {\n ...expandObjectPropertyRemoval(options.source, options.propertySpan),\n value: \"\",\n };\n }\n\n const value = JSON.stringify(options.value);\n if (options.valueSpan) {\n return {\n start: options.valueSpan.start,\n end: options.valueSpan.end,\n value,\n };\n }\n\n if (typeof options.objectClose !== \"number\") {\n throw new Error(`Object close not found for \"${options.name}\" property`);\n }\n\n return insertObjectProperty(\n options.source,\n options.objectClose,\n `${options.name}: ${value}`,\n );\n}\n\nfunction upsertJsxExpressionAttribute(options: {\n source: string;\n openingElementSpan: CanvasSourceSpan;\n expressionSpan?: CanvasSourceSpan;\n attributeSpan?: CanvasSourceSpan;\n name: string;\n value?: string;\n}): CanvasSourceEdit | null {\n if (options.value === undefined) {\n if (!options.attributeSpan) return null;\n return {\n ...expandJsxAttributeRemoval(options.source, options.attributeSpan),\n value: \"\",\n };\n }\n\n if (options.expressionSpan) {\n return {\n start: options.expressionSpan.start,\n end: options.expressionSpan.end,\n value: options.value,\n };\n }\n\n const offset = findOpeningElementAttributeInsertionOffset(\n options.source,\n options.openingElementSpan,\n );\n return {\n start: offset,\n end: offset,\n value: ` ${options.name}={${options.value}}`,\n };\n}\n\nfunction insertObjectProperty(\n source: string,\n objectClose: number,\n propertySource: string,\n): CanvasSourceEdit {\n const offset = trimWhitespaceBeforeOffset(source, objectClose);\n const previous = previousMeaningfulCharacter(source, offset);\n return {\n start: offset,\n end: offset,\n value: `${previous === \"{\" || previous === \",\" ? \" \" : \", \"}${propertySource}`,\n };\n}\n\nfunction formatStoryboardElement(options: {\n source: string;\n insertionOffset: number;\n tag: string;\n storyboard: AddCanvasStoryboardInput;\n componentExpression?: string;\n}): string {\n const newline = detectNewline(options.source);\n const closingIndent = lineIndentAt(options.source, options.insertionOffset);\n const indent = `${closingIndent} `;\n const firstLineIndent = \" \";\n const propIndent = `${indent} `;\n const props = storyboardElementProps(\n options.storyboard,\n options.componentExpression,\n );\n\n return `${firstLineIndent}<${options.tag}${newline}${props\n .map((prop) => `${propIndent}${prop}`)\n .join(newline)}${newline}${indent}/>${newline}${closingIndent}`;\n}\n\nfunction buildCanvasChildInsertionEdit(options: {\n source: string;\n parsed: ParsedCanvasFile;\n tag: string;\n storyboard: AddCanvasStoryboardInput;\n componentExpression?: string;\n}): CanvasSourceEdit {\n const insertionOffset = options.parsed.canvasChildrenInsertionOffset;\n if (typeof insertionOffset === \"number\") {\n return {\n start: insertionOffset,\n end: insertionOffset,\n value: formatStoryboardElement({\n source: options.source,\n insertionOffset,\n tag: options.tag,\n storyboard: options.storyboard,\n componentExpression: options.componentExpression,\n }),\n };\n }\n\n const openingSpan = options.parsed.canvasOpeningElementSpan;\n if (!openingSpan) {\n throw new Error(\"Canvas closing element not found\");\n }\n\n const openingSource = options.source.slice(\n openingSpan.start,\n openingSpan.end,\n );\n const selfClosingMatch = openingSource.match(/\\s*\\/\\s*>$/);\n const canvasName = openingSource.match(\n /^<\\s*([A-Za-z_$][\\w$]*(?:\\.[A-Za-z_$][\\w$]*)*)/,\n )?.[1];\n if (!selfClosingMatch || !canvasName) {\n throw new Error(\"Canvas closing element not found\");\n }\n\n const newline = detectNewline(options.source);\n const replacementStart = openingSpan.end - selfClosingMatch[0].length;\n const closingIndent = lineIndentAt(options.source, openingSpan.start);\n const childIndent = `${closingIndent} `;\n const propIndent = `${childIndent} `;\n const props = storyboardElementProps(\n options.storyboard,\n options.componentExpression,\n );\n\n return {\n start: replacementStart,\n end: openingSpan.end,\n value: `>${newline}${childIndent}<${options.tag}${newline}${props\n .map((prop) => `${propIndent}${prop}`)\n .join(\n newline,\n )}${newline}${childIndent}/>${newline}${closingIndent}</${canvasName}>`,\n };\n}\n\nfunction storyboardElementProps(\n storyboard: AddCanvasStoryboardInput,\n componentExpression?: string,\n): string[] {\n const idProp = formatJsxStringAttribute(\n \"id\",\n requireNonEmpty(storyboard.id, \"Storyboard id\"),\n );\n\n // LegacyStoryboardV1 carries only `id` + `storyboard={Expr}`; name and\n // layout live on the referenced object, so they are never emitted here.\n if (storyboard.kind === \"legacy-v1\") {\n return [idProp, `storyboard={${storyboard.storyboardExpression}}`];\n }\n\n if (\n (storyboard.kind === \"route\" || storyboard.kind === \"html\") &&\n (storyboard.layout.width === undefined ||\n storyboard.layout.height === undefined)\n ) {\n throw new Error(\"Route and HTML layouts require width and height\");\n }\n return [\n idProp,\n ...(storyboard.name && storyboard.name.trim() !== \"\"\n ? [formatJsxStringAttribute(\"name\", storyboard.name)]\n : []),\n ...storyboardKindProps(storyboard, componentExpression),\n `layout={{ ${formatLayout(storyboard.layout)} }}`,\n ];\n}\n\n/**\n * Format a JSX string attribute. Prefers the idiomatic plain form\n * (`name=\"value\"`) and falls back to the expression form (`name={\"value\"}`)\n * when the plain form can't represent the value faithfully: JSX string\n * attributes don't process backslash escapes but DO decode HTML entities, so\n * any value that JSON-escapes (quotes, backslashes, control characters) or\n * contains `&` must go through a braced string literal.\n */\nexport function formatJsxStringAttribute(name: string, value: string): string {\n const encoded = JSON.stringify(value);\n const plainSafe = encoded === `\"${value}\"` && !value.includes(\"&\");\n return plainSafe ? `${name}=${encoded}` : `${name}={${encoded}}`;\n}\n\nfunction storyboardKindProps(\n // legacy-v1 never reaches here: `storyboardElementProps` emits its\n // `storyboard={…}` prop directly (it has no name/layout attributes).\n storyboard: Exclude<AddCanvasStoryboardInput, { kind: \"legacy-v1\" }>,\n componentExpression?: string,\n): string[] {\n if (storyboard.kind === \"component\") {\n return [\n `component={${componentExpression}}`,\n ...(storyboard.props && storyboard.props.trim() !== \"\"\n ? [`props={${storyboard.props.trim()}}`]\n : []),\n ];\n }\n if (storyboard.kind === \"route\") {\n return [formatJsxStringAttribute(\"route\", storyboard.route)];\n }\n return [\n ...(storyboard.filepath\n ? [formatJsxStringAttribute(\"filepath\", storyboard.filepath)]\n : []),\n ...(storyboard.src\n ? [formatJsxStringAttribute(\"src\", storyboard.src)]\n : []),\n ];\n}\n\nfunction formatLayout(layout: CanvasEditorLayout & V1LayoutCompat): string {\n return [\n `x: ${roundLayoutNumber(layout.x)}`,\n `y: ${roundLayoutNumber(layout.y)}`,\n ...(layout.width === undefined\n ? []\n : [`width: ${roundLayoutNumber(layout.width)}`]),\n ...(layout.height === undefined\n ? []\n : [`height: ${roundLayoutNumber(layout.height)}`]),\n ...(layout.zIndex === undefined\n ? []\n : [`zIndex: ${roundLayoutNumber(layout.zIndex)}`]),\n ...(layout.intrinsicSizing === undefined\n ? []\n : [`intrinsicSizing: ${JSON.stringify(layout.intrinsicSizing)}`]),\n ].join(\", \");\n}\n\nfunction sdkComponentForStoryboard(\n storyboard: AddCanvasStoryboardInput,\n): SdkComponent {\n if (storyboard.kind === \"route\") return \"RouteStoryboard\";\n if (storyboard.kind === \"html\") return \"HtmlStoryboard\";\n if (storyboard.kind === \"legacy-v1\") return \"LegacyStoryboardV1\";\n if (storyboard.uiFramework === \"svelte\") return \"SvelteStoryboard\";\n return \"Storyboard\";\n}\n\nfunction resolveSdkTag(\n parsed: ParsedCanvasFile,\n component: SdkComponent,\n): { tag: string; importLine?: string } {\n const sdkSource =\n component === \"SvelteStoryboard\"\n ? \"tempo-sdk/canvas/svelte\"\n : \"tempo-sdk/canvas\";\n for (const item of parsed.imports) {\n if (item.source !== sdkSource) continue;\n if (item.kind === \"namespace\")\n return { tag: `${item.localName}.${component}` };\n if (item.importedName === component) return { tag: item.localName };\n }\n\n const localName = pickAvailableIdentifier(parsed, `TempoCanvas${component}`);\n return {\n tag: localName,\n importLine: `import { ${component} as ${localName} } from \"${sdkSource}\";`,\n };\n}\n\nfunction buildMissingComponentImportLine(\n parsed: ParsedCanvasFile,\n source: string,\n componentImport: {\n localName: string;\n source: string;\n importedName?: string;\n },\n): string | null {\n const existing = parsed.imports.find(\n (item) => item.localName === componentImport.localName,\n );\n if (existing) {\n if (existing.source !== componentImport.source) {\n throw new Error(\n `Import binding \"${componentImport.localName}\" already exists`,\n );\n }\n return null;\n }\n // Collision check that THROWS — must not fire on the name merely appearing\n // inside a string literal (e.g. `<Canvas name=\"Card Demo\">` blocking a `Card`\n // import), so use the AST-based node scan, never the textual `hasIdentifier`.\n if (\n sourceContainsIdentifierNode(\n parsed.filePath,\n source,\n componentImport.localName,\n )\n ) {\n throw new Error(`Identifier \"${componentImport.localName}\" already exists`);\n }\n\n if (\n !componentImport.importedName ||\n componentImport.importedName === \"default\"\n ) {\n return `import ${componentImport.localName} from ${JSON.stringify(\n componentImport.source,\n )};`;\n }\n\n const specifier =\n componentImport.importedName === componentImport.localName\n ? componentImport.localName\n : `${componentImport.importedName} as ${componentImport.localName}`;\n return `import { ${specifier} } from ${JSON.stringify(componentImport.source)};`;\n}\n\nfunction buildImportInsertionEdit(\n source: string,\n parsed: ParsedCanvasFile,\n importLines: readonly string[],\n): CanvasSourceEdit | null {\n if (importLines.length === 0) return null;\n const newline = detectNewline(source);\n const uniqueLines = Array.from(new Set(importLines));\n const lastImport = parsed.imports.reduce<ParsedCanvasImport | null>(\n (latest, item) =>\n !latest || item.declarationSpan.end > latest.declarationSpan.end\n ? item\n : latest,\n null,\n );\n\n if (lastImport) {\n return {\n start: lastImport.declarationSpan.end,\n end: lastImport.declarationSpan.end,\n value: `${newline}${uniqueLines.join(newline)}`,\n };\n }\n\n const offset = topLevelInsertionOffset(source);\n return {\n start: offset,\n end: offset,\n value: `${uniqueLines.join(newline)}${newline}`,\n };\n}\n\nfunction buildUnusedComponentImportRemoval(options: {\n source: string;\n parsed: ParsedCanvasFile;\n deletedStoryboard: ParsedCanvasStoryboard;\n deletionEdit: CanvasSourceEdit;\n}): CanvasSourceEdit | null {\n const componentImport = options.deletedStoryboard.component?.import;\n if (!componentImport || componentImport.importKind === \"type\") return null;\n\n const usedByRemainingStoryboard = options.parsed.storyboards.some(\n (storyboard) =>\n storyboard.storyboardKey !== options.deletedStoryboard.storyboardKey &&\n storyboard.component?.import?.localName === componentImport.localName,\n );\n if (usedByRemainingStoryboard) return null;\n\n const sourceAfterStoryboardDelete = applyCanvasSourceEdits(options.source, [\n options.deletionEdit,\n ]);\n\n if (componentImport.specifierCount === 1) {\n const sourceWithoutImport = removeSpanText(\n sourceAfterStoryboardDelete,\n componentImport.declarationSpan,\n );\n if (hasIdentifier(sourceWithoutImport, componentImport.localName))\n return null;\n\n return {\n ...expandToFullLines(options.source, componentImport.declarationSpan),\n value: \"\",\n };\n }\n\n if (\n componentImport.kind !== \"named\" ||\n componentImport.hasDefaultSpecifier ||\n componentImport.hasNamespaceSpecifier ||\n componentImport.namedSpecifierCount <= 1\n ) {\n return null;\n }\n\n const specifierRange = expandImportSpecifierRemovalRange(\n options.source,\n componentImport.span,\n );\n const sourceWithoutImport = removeSpanText(\n sourceAfterStoryboardDelete,\n specifierRange,\n );\n if (hasIdentifier(sourceWithoutImport, componentImport.localName))\n return null;\n\n return {\n ...specifierRange,\n value: \"\",\n };\n}\n\nfunction expandImportSpecifierRemovalRange(\n source: string,\n span: CanvasSourceSpan,\n): CanvasSourceSpan {\n const lineStart = Math.max(source.lastIndexOf(\"\\n\", span.start - 1) + 1, 0);\n const nextNewline = source.indexOf(\"\\n\", span.end);\n const lineEnd = nextNewline >= 0 ? nextNewline + 1 : source.length;\n const before = source.slice(lineStart, span.start);\n const after = source.slice(span.end, lineEnd);\n if (/^[ \\t]*$/.test(before) && /^[ \\t]*(,)?[ \\t]*(\\r?\\n)?$/.test(after)) {\n return { start: lineStart, end: lineEnd };\n }\n\n let start = span.start;\n let end = span.end;\n while (end < source.length && /\\s/.test(source[end] ?? \"\")) end++;\n if (source[end] === \",\") {\n end++;\n while (\n end < source.length &&\n (source[end] === \" \" || source[end] === \"\\t\")\n ) {\n end++;\n }\n return { start, end };\n }\n\n while (\n start > 0 &&\n (source[start - 1] === \" \" || source[start - 1] === \"\\t\")\n ) {\n start--;\n }\n if (source[start - 1] === \",\") {\n start--;\n while (\n start > 0 &&\n (source[start - 1] === \" \" || source[start - 1] === \"\\t\")\n ) {\n start--;\n }\n }\n return { start, end };\n}\n\nfunction removeSpanText(source: string, span: CanvasSourceSpan): string {\n return source.slice(0, span.start) + source.slice(span.end);\n}\n\nfunction findOpeningElementAttributeInsertionOffset(\n source: string,\n span: CanvasSourceSpan,\n): number {\n const close = source.lastIndexOf(\">\", span.end - 1);\n if (close < span.start) {\n throw new Error(\"JSX opening element close not found\");\n }\n return source[close - 1] === \"/\" ? close - 1 : close;\n}\n\nfunction insertBareJsxAttributeLine(options: {\n source: string;\n openingElementSpan: CanvasSourceSpan;\n name: string;\n}): CanvasSourceEdit {\n const offset = findOpeningElementAttributeInsertionOffset(\n options.source,\n options.openingElementSpan,\n );\n const newline = detectNewline(options.source);\n const openingIndent = lineIndentAt(\n options.source,\n options.openingElementSpan.start,\n );\n const openingLineEnd = options.source.indexOf(\n \"\\n\",\n options.openingElementSpan.start,\n );\n const existingAttributeIndent =\n openingLineEnd >= 0 && openingLineEnd < offset\n ? options.source\n .slice(openingLineEnd + 1, offset)\n .split(/\\r?\\n/)\n .find((line) => line.trim() !== \"\")\n ?.match(/^[ \\t]*/)?.[0]\n : undefined;\n const attributeIndent =\n existingAttributeIndent &&\n existingAttributeIndent.length > openingIndent.length\n ? existingAttributeIndent\n : `${openingIndent}${openingIndent.includes(\"\\t\") ? \"\\t\" : \" \"}`;\n const closingLineStart = Math.max(\n options.source.lastIndexOf(\"\\n\", offset - 1) + 1,\n 0,\n );\n\n if (/^[ \\t]*$/.test(options.source.slice(closingLineStart, offset))) {\n return {\n start: closingLineStart,\n end: closingLineStart,\n value: `${attributeIndent}${options.name}${newline}`,\n };\n }\n\n let start = offset;\n while (\n start > options.openingElementSpan.start &&\n (options.source[start - 1] === \" \" || options.source[start - 1] === \"\\t\")\n ) {\n start--;\n }\n return {\n start,\n end: offset,\n value: `${newline}${attributeIndent}${options.name}${newline}${openingIndent}`,\n };\n}\n\nfunction expandJsxAttributeRemoval(\n source: string,\n span: CanvasSourceSpan,\n): CanvasSourceSpan {\n const lineStart = Math.max(source.lastIndexOf(\"\\n\", span.start - 1) + 1, 0);\n const nextNewline = source.indexOf(\"\\n\", span.end);\n const lineEnd = nextNewline >= 0 ? nextNewline : source.length;\n if (\n /^[ \\t]*$/.test(source.slice(lineStart, span.start)) &&\n /^[ \\t]*$/.test(source.slice(span.end, lineEnd))\n ) {\n return {\n start: lineStart,\n end: nextNewline >= 0 ? nextNewline + 1 : lineEnd,\n };\n }\n\n let start = span.start;\n let end = span.end;\n\n while (\n start > 0 &&\n (source[start - 1] === \" \" || source[start - 1] === \"\\t\")\n ) {\n start--;\n }\n while (end < source.length && (source[end] === \" \" || source[end] === \"\\t\")) {\n end++;\n }\n return { start, end };\n}\n\nfunction expandObjectPropertyRemoval(\n source: string,\n span: CanvasSourceSpan,\n): CanvasSourceSpan {\n let start = span.start;\n let end = span.end;\n\n while (start > 0 && /\\s/.test(source[start - 1] ?? \"\")) start--;\n while (end < source.length && /\\s/.test(source[end] ?? \"\")) end++;\n\n if (source[end] === \",\") {\n end++;\n while (\n end < source.length &&\n (source[end] === \" \" || source[end] === \"\\t\")\n ) {\n end++;\n }\n return { start, end };\n }\n\n let comma = start - 1;\n while (comma >= 0 && /\\s/.test(source[comma] ?? \"\")) comma--;\n if (source[comma] === \",\") {\n start = comma;\n }\n return { start, end };\n}\n\nexport function expandToFullLines(\n source: string,\n span: CanvasSourceSpan,\n): CanvasSourceSpan {\n let start = span.start;\n let end = span.end;\n while (\n start > 0 &&\n source[start - 1] !== \"\\n\" &&\n source[start - 1] !== \"\\r\"\n ) {\n start--;\n }\n if (start > 0) {\n if (source[start - 1] === \"\\n\") start--;\n if (start > 0 && source[start - 1] === \"\\r\") start--;\n }\n while (end < source.length && (source[end] === \" \" || source[end] === \"\\t\")) {\n end++;\n }\n if (source.slice(end, end + 2) === \"\\r\\n\") {\n end += 2;\n } else if (source[end] === \"\\n\" || source[end] === \"\\r\") {\n end++;\n }\n return { start, end };\n}\n\nexport function expandStatementForward(\n source: string,\n span: CanvasSourceSpan,\n): CanvasSourceSpan {\n let end = span.end;\n while (end < source.length && (source[end] === \" \" || source[end] === \"\\t\")) {\n end++;\n }\n if (source.slice(end, end + 2) === \"\\r\\n\") {\n end += 2;\n } else if (source[end] === \"\\n\" || source[end] === \"\\r\") {\n end++;\n }\n return { start: span.start, end };\n}\n\nfunction lineIndentAt(source: string, offset: number): string {\n const lineStart = Math.max(source.lastIndexOf(\"\\n\", offset - 1) + 1, 0);\n const linePrefix = source.slice(lineStart, offset);\n const match = linePrefix.match(/^[ \\t]*/);\n return match?.[0] ?? \"\";\n}\n\nfunction previousMeaningfulCharacter(source: string, offset: number): string {\n for (let index = offset - 1; index >= 0; index -= 1) {\n const character = source[index] ?? \"\";\n if (!/\\s/.test(character)) return character;\n }\n return \"\";\n}\n\nfunction trimWhitespaceBeforeOffset(source: string, offset: number): number {\n let nextOffset = offset;\n while (nextOffset > 0 && /\\s/.test(source[nextOffset - 1] ?? \"\")) {\n nextOffset--;\n }\n return nextOffset;\n}\n\nexport function collapseBlankLines(source: string, newline: string): string {\n return newline === \"\\r\\n\"\n ? source.replace(/(\\r\\n){3,}/g, \"\\r\\n\\r\\n\")\n : source.replace(/\\n{3,}/g, \"\\n\\n\");\n}\n\nexport function detectNewline(source: string): \"\\n\" | \"\\r\\n\" {\n return source.includes(\"\\r\\n\") ? \"\\r\\n\" : \"\\n\";\n}\n\nexport function topLevelInsertionOffset(source: string): number {\n let offset = 0;\n if (source.startsWith(\"#!\")) {\n const newline = source.indexOf(\"\\n\");\n offset = newline >= 0 ? newline + 1 : source.length;\n }\n\n while (true) {\n const nextLineEnd = source.indexOf(\"\\n\", offset);\n const end = nextLineEnd >= 0 ? nextLineEnd + 1 : source.length;\n const line = source.slice(offset, end).trim();\n if (!/^[\"']use [^\"']+[\"'];?$/.test(line)) break;\n offset = end;\n }\n\n return offset;\n}\n\nfunction pickAvailableIdentifier(\n parsed: ParsedCanvasFile,\n base: string,\n): string {\n const usedImports = new Set(parsed.imports.map((item) => item.localName));\n if (!usedImports.has(base)) return base;\n for (let index = 2; index < 10_000; index += 1) {\n const candidate = `${base}${index}`;\n if (!usedImports.has(candidate)) return candidate;\n }\n throw new Error(`Unable to find available identifier for ${base}`);\n}\n\n/**\n * Cheap word-boundary text scan. It matches occurrences inside string literals\n * and comments too, so it is SAFE-DIRECTION ONLY: use it where a false positive\n * is harmless (conservatively keeping an import that might still be used), NEVER\n * for a collision check that throws or blocks an edit — those must use\n * {@link sourceContainsIdentifierNode}, which counts real identifier nodes only.\n */\nexport function hasIdentifier(source: string, identifier: string): boolean {\n return new RegExp(`\\\\b${escapeRegExp(identifier)}\\\\b`).test(source);\n}\n\n/**\n * True when `name` appears as a real identifier node (`Identifier` /\n * `JSXIdentifier`) anywhere in `source` — a binding or reference, never a\n * string-literal or comment occurrence. Use this for collision checks that\n * throw or block an edit, so a name appearing only inside a string (e.g.\n * `<Canvas name=\"Card Demo\">` vs a `Card` import) can't masquerade as a\n * declared identifier.\n */\nexport function sourceContainsIdentifierNode(\n filePath: string,\n source: string,\n name: string,\n): boolean {\n const program = (parseSync(filePath, source) as any).program;\n let found = false;\n walkWithParent(program, (node) => {\n if (found) return;\n if (\n (node.type === \"Identifier\" || node.type === \"JSXIdentifier\") &&\n node.name === name\n ) {\n found = true;\n }\n });\n return found;\n}\n\n/**\n * Depth-first walk that hands each AST node to `visit` along with its parent and\n * the parent field it was reached through — the context callers need to tell a\n * value reference from a property key or member access.\n */\nexport function walkWithParent(\n node: any,\n visit: (node: any, parent: any, key: string | null) => void,\n parent: any = null,\n key: string | null = null,\n seen = new Set<any>(),\n): void {\n if (!node || typeof node !== \"object\" || seen.has(node)) return;\n seen.add(node);\n if (typeof node.type === \"string\") visit(node, parent, key);\n for (const [childKey, value] of Object.entries(node)) {\n if (!value || typeof value !== \"object\") continue;\n if (Array.isArray(value)) {\n for (const item of value)\n walkWithParent(item, visit, node, childKey, seen);\n } else {\n walkWithParent(value, visit, node, childKey, seen);\n }\n }\n}\n\nfunction escapeRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nfunction roundLayoutNumber(value: number): number {\n if (typeof value !== \"number\" || !Number.isFinite(value)) {\n throw new Error(\"Layout values must be finite numbers\");\n }\n return Math.round(value);\n}\n\nfunction requireNonEmpty(value: string, label: string): string {\n const trimmed = value.trim();\n if (!trimmed) {\n throw new Error(`${label} must be non-empty`);\n }\n return trimmed;\n}\n\nfunction requiredSpan<T>(value: T | undefined, message: string): T {\n if (value === undefined) {\n throw new Error(message);\n }\n return value;\n}\n","/**\n * @deprecated V1 client compat (file spelling).\n *\n * A released V1 Tempo client (app 0.0.114) parses the canvas files this SDK\n * writes. Its parser reads a component layout without width and height as\n * degraded and falls back to 600x400, so a responsive component board is\n * written in the legacy spelling `{ x, y, width, height, intrinsicSizing:\n * \"root-element\" }`, where width and height are a first-paint hint. The V2\n * parser and shell already read that spelling as responsive, so V2 behavior\n * does not change. Delete with v1-client-compat.ts once no protocol-1 client\n * is supported; the compiler then lists every call site.\n */\nimport type { CanvasEditorLayout } from \"./editor\";\nimport type { V1LayoutCompat } from \"./v1-client-compat\";\n\n/** How a component layout is spelled on disk so a V1 parser reads it. A\n * layout with a size is written as is. A responsive layout is written in the\n * legacy spelling with `hint` as its width and height: the hint the file\n * already carries, or the size the writer knows. Without a hint there is\n * nothing V1-readable to write and the layout is returned as is. */\nexport function v1ReadableLayout(\n layout: CanvasEditorLayout,\n hint: { width: number; height: number } | undefined,\n): CanvasEditorLayout & V1LayoutCompat {\n const fixed = layout.width !== undefined && layout.height !== undefined;\n if (fixed || !hint) return layout;\n return {\n ...layout,\n width: hint.width,\n height: hint.height,\n intrinsicSizing: \"root-element\",\n };\n}\n\n/** The first-paint hint a legacy responsive layout literal carries, read\n * from the literal's source text (the parser keeps no value or span for it).\n * The literal is machine-written with number literals, which the parser has\n * already required, so a plain property scan is enough. */\nexport function v1LayoutHint(\n layoutSource: string,\n): { width: number; height: number } | undefined {\n const width = readNumberProperty(layoutSource, \"width\");\n const height = readNumberProperty(layoutSource, \"height\");\n return width === undefined || height === undefined\n ? undefined\n : { width, height };\n}\n\nfunction readNumberProperty(source: string, key: string): number | undefined {\n const match = source.match(\n new RegExp(`(?:^|[{,\\\\s])${key}\\\\s*:\\\\s*(-?[0-9]*\\\\.?[0-9]+)`),\n );\n return match ? Number(match[1]) : undefined;\n}\n"],"mappings":";;;;;AAAA,SAAS,iBAAiB;;;ACoBnB,SAAS,iBACd,QACA,MACqC;AACrC,QAAM,QAAQ,OAAO,UAAU,UAAa,OAAO,WAAW;AAC9D,MAAI,SAAS,CAAC,KAAM,QAAO;AAC3B,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,KAAK;AAAA,IACZ,QAAQ,KAAK;AAAA,IACb,iBAAiB;AAAA,EACnB;AACF;AAMO,SAAS,aACd,cAC+C;AAC/C,QAAM,QAAQ,mBAAmB,cAAc,OAAO;AACtD,QAAM,SAAS,mBAAmB,cAAc,QAAQ;AACxD,SAAO,UAAU,UAAa,WAAW,SACrC,SACA,EAAE,OAAO,OAAO;AACtB;AAEA,SAAS,mBAAmB,QAAgB,KAAiC;AAC3E,QAAM,QAAQ,OAAO;AAAA,IACnB,IAAI,OAAO,gBAAgB,GAAG,+BAA+B;AAAA,EAC/D;AACA,SAAO,QAAQ,OAAO,MAAM,CAAC,CAAC,IAAI;AACpC;;;ADkCO,SAAS,uBACd,QACA,OACQ;AACR,QAAM,SAAS,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC,MAAM,UAAU,MAAM,QAAQ,KAAK,KAAK;AACxE,MAAI,gBAAgB,OAAO,SAAS;AACpC,MAAI,aAAa;AAEjB,aAAW,QAAQ,QAAQ;AACzB,QACE,KAAK,QAAQ,KACb,KAAK,MAAM,KAAK,SAChB,KAAK,MAAM,OAAO,UAClB,KAAK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OAAe,OAAuB;AAC7D,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,GAAG,KAAK,oBAAoB;AAAA,EAC9C;AACA,SAAO;AACT;AAEA,SAAS,aAAgB,OAAsB,SAAoB;AACjE,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,OAAO;AAAA,EACzB;AACA,SAAO;AACT;","names":["edit","sourceWithoutImport"]}
1
+ {"version":3,"sources":["../../canvas/editor.ts","../../canvas/v1-file-compat.ts"],"sourcesContent":["import { parseSync } from \"oxc-parser\";\n\nimport {\n parseCanvasFile,\n type CanvasSourceSpan,\n type ParsedCanvasFile,\n type ParsedCanvasImport,\n type ParsedCanvasStoryboard,\n} from \"./parser\";\nimport type { V1LayoutCompat } from \"./v1-client-compat\";\nimport { v1LayoutHint, v1ReadableLayout } from \"./v1-file-compat\";\n\nexport type CanvasSourceEdit = {\n start: number;\n end: number;\n value: string;\n};\n\nexport type CanvasEditResult = {\n source: string;\n edits: CanvasSourceEdit[];\n parsed: ParsedCanvasFile;\n};\n\nexport type CanvasEditorLayout = {\n x: number;\n y: number;\n width?: number;\n height?: number;\n zIndex?: number;\n};\n\nexport type AddCanvasStoryboardInput =\n | {\n kind: \"component\";\n /** The component's authored framework, as the declaration and the\n * parser spell it: a Svelte component is written as\n * `<SvelteStoryboard>` from \"tempo-sdk/canvas/svelte\". */\n uiFramework?: \"svelte\" | \"astro\";\n id: string;\n /** Migration passes a legacy responsive layout in its V1-readable\n * spelling (see v1-file-compat.ts). */\n layout: CanvasEditorLayout & V1LayoutCompat;\n name?: string;\n componentExpression?: string;\n // Pre-formatted object-literal expression (e.g. `{ a: \"s\", b: expr }`)\n // emitted as `props={<value>}` after `component=`. Used by migration to\n // render `render: () => <C a={b} />` as `component={C} props={{ a: b }}`.\n props?: string;\n componentImport?: {\n localName: string;\n source: string;\n importedName?: string;\n };\n }\n | {\n // Per-storyboard fallback for legacy object shapes migration cannot\n // convert natively: emits `<LegacyStoryboardV1 id storyboard={Expr} />`.\n // The wrapper reads name/layout off the referenced object, so no\n // name/layout attributes are emitted here.\n kind: \"legacy-v1\";\n id: string;\n storyboardExpression: string;\n }\n | {\n kind: \"route\";\n id: string;\n route: string;\n layout: CanvasEditorLayout;\n name?: string;\n }\n | {\n kind: \"html\";\n id: string;\n layout: CanvasEditorLayout;\n name?: string;\n filepath?: string;\n src?: string;\n };\n\ntype SdkComponent =\n | \"Storyboard\"\n | \"SvelteStoryboard\"\n | \"AstroStoryboard\"\n | \"LegacyStoryboardV1\"\n | \"RouteStoryboard\"\n | \"HtmlStoryboard\";\n\nexport function applyCanvasSourceEdits(\n source: string,\n edits: readonly CanvasSourceEdit[],\n): string {\n const sorted = [...edits].sort((left, right) => right.start - left.start);\n let previousStart = source.length + 1;\n let nextSource = source;\n\n for (const edit of sorted) {\n if (\n edit.start < 0 ||\n edit.end < edit.start ||\n edit.end > source.length ||\n edit.end > previousStart\n ) {\n throw new Error(\n `Invalid overlapping canvas source edit ${edit.start}:${edit.end}`,\n );\n }\n nextSource =\n nextSource.slice(0, edit.start) + edit.value + nextSource.slice(edit.end);\n previousStart = edit.start;\n }\n\n return nextSource;\n}\n\nexport function updateCanvasName(options: {\n filePath: string;\n source: string;\n name: string;\n}): CanvasEditResult {\n return editCanvasStringAttribute(\n options,\n \"name\",\n requireNonEmpty(options.name, \"Canvas name\"),\n (parsed) => ({\n valueSpan: parsed.nameSpan,\n attributeSpan: parsed.nameAttributeSpan,\n }),\n );\n}\n\nexport function updateCanvasPath(options: {\n filePath: string;\n source: string;\n path: string;\n}): CanvasEditResult {\n return editCanvasStringAttribute(\n options,\n \"path\",\n requireNonEmpty(options.path, \"Canvas path\"),\n (parsed) => ({\n valueSpan: parsed.pathSpan,\n attributeSpan: parsed.pathAttributeSpan,\n }),\n );\n}\n\nexport function updateCanvasBackgroundColor(options: {\n filePath: string;\n source: string;\n backgroundColor?: string;\n}): CanvasEditResult {\n return editCanvasStringAttribute(\n options,\n \"backgroundColor\",\n options.backgroundColor && options.backgroundColor.trim() !== \"\"\n ? options.backgroundColor\n : undefined,\n (parsed) => ({\n valueSpan: parsed.backgroundColorSpan,\n attributeSpan: parsed.backgroundColorAttributeSpan,\n }),\n );\n}\n\nfunction editCanvasStringAttribute(\n options: { filePath: string; source: string },\n attributeName: string,\n value: string | undefined,\n selectSpans: (parsed: ParsedCanvasFile) => {\n valueSpan?: CanvasSourceSpan;\n attributeSpan?: CanvasSourceSpan;\n },\n): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const spans = selectSpans(parsed);\n const edit = upsertJsxStringAttribute({\n source: options.source,\n openingElementSpan: requiredSpan(\n parsed.canvasOpeningElementSpan,\n \"Canvas opening element not found\",\n ),\n valueSpan: spans.valueSpan,\n attributeSpan: spans.attributeSpan,\n name: attributeName,\n value,\n });\n return applyResult(options.source, parsed, edit ? [edit] : []);\n}\n\nexport function updateStoryboardName(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n name?: string;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n if (storyboard.legacyV1) {\n const edit = upsertObjectStringProperty({\n source: options.source,\n objectClose: storyboard.legacyV1.objectClose,\n valueSpan: storyboard.nameSpan,\n propertySpan: storyboard.legacyV1.namePropertySpan,\n name: \"name\",\n value:\n options.name && options.name.trim() !== \"\" ? options.name : undefined,\n });\n return applyResult(options.source, parsed, edit ? [edit] : []);\n }\n\n const edit = upsertJsxStringAttribute({\n source: options.source,\n openingElementSpan: requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n ),\n valueSpan: storyboard.nameSpan,\n attributeSpan: storyboard.nameAttributeSpan,\n name: \"name\",\n value:\n options.name && options.name.trim() !== \"\" ? options.name : undefined,\n });\n return applyResult(options.source, parsed, edit ? [edit] : []);\n}\n\nexport function updateStoryboardId(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n nextId: string;\n}): CanvasEditResult {\n const nextId = requireNonEmpty(options.nextId, \"Storyboard id\");\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n const duplicate = parsed.storyboards.find(\n (item) =>\n item.storyboardKey === nextId &&\n item.storyboardKey !== storyboard.storyboardKey,\n );\n if (duplicate) {\n throw new Error(`Storyboard id \"${nextId}\" already exists`);\n }\n const edit = upsertJsxStringAttribute({\n source: options.source,\n openingElementSpan: requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n ),\n valueSpan: storyboard.idSpan,\n attributeSpan: storyboard.idAttributeSpan,\n name: \"id\",\n value: nextId,\n });\n return applyResult(options.source, parsed, [edit]);\n}\n\nexport function updateStoryboardLayout(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n layout: Partial<CanvasEditorLayout>;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n const spans = storyboard.layoutSpans;\n if (!spans) {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" has no editable layout`,\n );\n }\n\n const span =\n storyboard.legacyV1?.layoutPropertySpan ?? storyboard.layoutAttributeSpan;\n if (!span || spans.layoutClose === undefined) {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" has no editable layout`,\n );\n }\n for (const key of [\"x\", \"y\", \"width\", \"height\", \"zIndex\"] as const) {\n if (\n parsed.errors.some(\n (error) =>\n error.span &&\n error.span.start >= span.start &&\n error.span.end <= span.end &&\n error.message.includes(`layout.${key} must be a number literal`),\n )\n ) {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" layout.${key} is not editable`,\n );\n }\n }\n const layout = { ...storyboard.layout, ...options.layout };\n if (\n storyboard.kind === \"component\" &&\n storyboard.layout.width === undefined &&\n storyboard.layout.height === undefined\n ) {\n delete layout.width;\n delete layout.height;\n }\n if ((layout.width === undefined) !== (layout.height === undefined)) {\n throw new Error(\"layout.width and layout.height must be set together\");\n }\n if (storyboard.kind !== \"component\" && layout.width === undefined) {\n throw new Error(\"Route and HTML layouts require width and height\");\n }\n for (const key of [\"x\", \"y\"] as const) {\n if (options.layout[key] !== undefined && !spans[key]) {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" layout.${key} is not editable`,\n );\n }\n }\n // A responsive board keeps the first-paint hint its literal already\n // carries, so the rewritten literal stays readable to a V1 client.\n const written = v1ReadableLayout(\n layout,\n v1LayoutHint(options.source.slice(span.start, span.end)),\n );\n return applyResult(options.source, parsed, [\n {\n start: span.start,\n end: span.end,\n value: storyboard.legacyV1\n ? `layout: { ${formatLayout(written)} }`\n : `layout={{ ${formatLayout(written)} }}`,\n },\n ]);\n}\n\nexport function updateStoryboardComponent(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n componentExpression: string;\n componentImport?: {\n localName: string;\n source: string;\n importedName?: string;\n };\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n if (storyboard.kind !== \"component\") {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" is not a component storyboard`,\n );\n }\n\n const imports: string[] = [];\n if (options.componentImport) {\n const importLine = buildMissingComponentImportLine(\n parsed,\n options.source,\n options.componentImport,\n );\n if (importLine) imports.push(importLine);\n }\n\n const importEdit = buildImportInsertionEdit(options.source, parsed, imports);\n const componentEdit = upsertJsxExpressionAttribute({\n source: options.source,\n openingElementSpan: requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n ),\n expressionSpan: storyboard.component?.span,\n attributeSpan: storyboard.component?.attributeSpan,\n name: \"component\",\n value: requireNonEmpty(\n options.componentExpression,\n \"Storyboard component expression\",\n ),\n });\n\n return applyResult(options.source, parsed, [\n ...(importEdit ? [importEdit] : []),\n componentEdit,\n ]);\n}\n\nexport function updateStoryboardProps(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n propsExpression?: string;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n const edit = upsertJsxExpressionAttribute({\n source: options.source,\n openingElementSpan: requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n ),\n expressionSpan: storyboard.props?.span,\n attributeSpan: storyboard.props?.attributeSpan,\n name: \"props\",\n value:\n options.propsExpression && options.propsExpression.trim() !== \"\"\n ? options.propsExpression.trim()\n : undefined,\n });\n return applyResult(options.source, parsed, edit ? [edit] : []);\n}\n\n/** Literal `vrt` options an editor may write (TEM-1775). Mirrors the parsed\n * shape: `threshold` 0..0.5, `skip` pauses without losing config, `ignore`\n * regions are storyboard-local CSS px. */\nexport type StoryboardVrtConfigInput = {\n threshold?: number;\n skip?: boolean;\n ignore?: Array<{ x: number; y: number; w: number; h: number }>;\n};\n\n/**\n * Sets or clears the opt-in visual-regression tracking mark (TEM-1775) on a\n * component storyboard. `tracked: true` writes the bare `vrt` attribute\n * (tracked with defaults), replacing an existing untracked declaration\n * (`vrt={false}`, dynamic forms) in place; an already-tracked declaration —\n * including the object form with threshold/ignore overrides — is left\n * untouched. `tracked: false` removes the whole `vrt` attribute, object\n * config included: the in-app toggle is a full untrack, not the\n * `skip: true` pause. An OBJECT `tracked` writes that exact literal config\n * (`vrt={{ threshold, skip, ignore }}`), replacing whatever declaration\n * exists — the agent-facing `canvas_set_vrt` path for thresholds, masks and\n * pauses; an empty object is the bare mark.\n */\nexport function updateStoryboardVrt(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n tracked: boolean | StoryboardVrtConfigInput;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n if (storyboard.kind === \"route\") {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" is a route storyboard; VRT supports component and local HTML storyboards`,\n );\n }\n\n if (typeof options.tracked === \"object\") {\n const literal = formatStoryboardVrtConfig(options.tracked);\n const attributeText = literal === null ? \"vrt\" : `vrt={${literal}}`;\n if (storyboard.vrtAttributeSpan) {\n return applyResult(options.source, parsed, [\n {\n start: storyboard.vrtAttributeSpan.start,\n end: storyboard.vrtAttributeSpan.end,\n value: attributeText,\n },\n ]);\n }\n return applyResult(options.source, parsed, [\n insertBareJsxAttributeLine({\n source: options.source,\n openingElementSpan: requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n ),\n name: attributeText,\n }),\n ]);\n }\n\n if (!options.tracked) {\n if (!storyboard.vrtAttributeSpan) {\n return applyResult(options.source, parsed, []);\n }\n return applyResult(options.source, parsed, [\n {\n ...expandJsxAttributeRemoval(\n options.source,\n storyboard.vrtAttributeSpan,\n ),\n value: \"\",\n },\n ]);\n }\n\n if (storyboard.vrt) {\n return applyResult(options.source, parsed, []);\n }\n const openingElementSpan = requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n );\n if (storyboard.vrtAttributeSpan) {\n return applyResult(options.source, parsed, [\n {\n ...expandJsxAttributeRemoval(\n options.source,\n storyboard.vrtAttributeSpan,\n ),\n value: \"\",\n },\n insertBareJsxAttributeLine({\n source: options.source,\n openingElementSpan,\n name: \"vrt\",\n }),\n ]);\n }\n return applyResult(options.source, parsed, [\n insertBareJsxAttributeLine({\n source: options.source,\n openingElementSpan,\n name: \"vrt\",\n }),\n ]);\n}\n\n/**\n * Renders a literal `vrt` object the parser accepts back (`readVrt`: number\n * literal threshold in 0..0.5, boolean `skip`, `{ x, y, w, h }` number\n * literal regions), validating the same rules up front so an editor never\n * writes a declaration the parser would then degrade. Returns `null` for an\n * empty config — the bare `vrt` mark says the same thing.\n */\nfunction formatStoryboardVrtConfig(\n config: StoryboardVrtConfigInput,\n): string | null {\n const parts: string[] = [];\n if (config.threshold !== undefined) {\n if (\n typeof config.threshold !== \"number\" ||\n !Number.isFinite(config.threshold) ||\n config.threshold < 0 ||\n config.threshold > 0.5\n ) {\n throw new Error(\"vrt.threshold must be a number between 0 and 0.5\");\n }\n parts.push(`threshold: ${config.threshold}`);\n }\n if (config.skip !== undefined) {\n if (typeof config.skip !== \"boolean\") {\n throw new Error(\"vrt.skip must be a boolean\");\n }\n parts.push(`skip: ${config.skip}`);\n }\n if (config.ignore !== undefined) {\n if (!Array.isArray(config.ignore)) {\n throw new Error(\"vrt.ignore must be an array of { x, y, w, h } regions\");\n }\n const regions = config.ignore.map((region) => {\n for (const key of [\"x\", \"y\", \"w\", \"h\"] as const) {\n const value = region?.[key];\n if (typeof value !== \"number\" || !Number.isFinite(value) || value < 0) {\n throw new Error(\n `vrt.ignore regions must be { x, y, w, h } non-negative numbers (bad ${key})`,\n );\n }\n }\n return `{ x: ${region.x}, y: ${region.y}, w: ${region.w}, h: ${region.h} }`;\n });\n if (regions.length > 0) {\n parts.push(`ignore: [${regions.join(\", \")}]`);\n }\n }\n return parts.length === 0 ? null : `{ ${parts.join(\", \")} }`;\n}\n\nexport function updateRouteStoryboardRoute(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n route: string;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n if (storyboard.kind !== \"route\") {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" is not a route storyboard`,\n );\n }\n const edit = upsertJsxStringAttribute({\n source: options.source,\n openingElementSpan: requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n ),\n valueSpan: storyboard.routeSpan,\n attributeSpan: storyboard.routeAttributeSpan,\n name: \"route\",\n value: requireNonEmpty(options.route, \"Route storyboard route\"),\n });\n return applyResult(options.source, parsed, [edit]);\n}\n\nexport function updateHtmlStoryboardSource(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n filepath?: string;\n src?: string;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n if (storyboard.kind !== \"html\") {\n throw new Error(\n `Storyboard \"${options.storyboardId}\" is not an html storyboard`,\n );\n }\n const filepath =\n options.filepath && options.filepath.trim() !== \"\"\n ? options.filepath.trim()\n : undefined;\n const src =\n options.src && options.src.trim() !== \"\" ? options.src : undefined;\n if (!filepath && !src) {\n throw new Error(\"HTML storyboard source requires filepath or src\");\n }\n\n const openingElementSpan = requireStoryboardOpeningSpan(\n storyboard,\n options.storyboardId,\n );\n const filepathEdit = upsertJsxStringAttribute({\n source: options.source,\n openingElementSpan,\n valueSpan: storyboard.filepathSpan,\n attributeSpan: storyboard.filepathAttributeSpan,\n name: \"filepath\",\n value: filepath,\n });\n const srcEdit = upsertJsxStringAttribute({\n source: options.source,\n openingElementSpan,\n valueSpan: storyboard.srcSpan,\n attributeSpan: storyboard.srcAttributeSpan,\n name: \"src\",\n value: src,\n });\n\n return applyResult(options.source, parsed, [filepathEdit, srcEdit]);\n}\n\nexport function addCanvasStoryboard(options: {\n filePath: string;\n source: string;\n storyboard: AddCanvasStoryboardInput;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n if (\n parsed.storyboards.some(\n (item) => item.storyboardKey === options.storyboard.id,\n )\n ) {\n throw new Error(`Storyboard id \"${options.storyboard.id}\" already exists`);\n }\n\n const imports: string[] = [];\n const sdkComponent = sdkComponentForStoryboard(options.storyboard);\n const sdkTag = resolveSdkTag(parsed, sdkComponent);\n let storyboardTag = sdkTag.tag;\n if (sdkTag.importLine) {\n imports.push(sdkTag.importLine);\n storyboardTag = sdkTag.tag;\n }\n\n let componentExpression: string | undefined;\n if (options.storyboard.kind === \"component\") {\n componentExpression =\n options.storyboard.componentExpression ??\n options.storyboard.componentImport?.localName;\n if (!componentExpression) {\n throw new Error(\n \"Component storyboard requires componentExpression or componentImport\",\n );\n }\n if (options.storyboard.componentImport) {\n const importLine = buildMissingComponentImportLine(\n parsed,\n options.source,\n options.storyboard.componentImport,\n );\n if (importLine) imports.push(importLine);\n }\n }\n\n const importEdit = buildImportInsertionEdit(options.source, parsed, imports);\n const insertionEdit = buildCanvasChildInsertionEdit({\n source: options.source,\n parsed,\n tag: storyboardTag,\n storyboard: options.storyboard,\n componentExpression,\n });\n\n const edits = [...(importEdit ? [importEdit] : []), insertionEdit];\n return applyResult(options.source, parsed, edits);\n}\n\nexport function removeCanvasStoryboard(options: {\n filePath: string;\n source: string;\n storyboardId: string;\n removeUnusedComponentImport?: boolean;\n}): CanvasEditResult {\n const parsed = parseCanvasFile(options.filePath, options.source);\n const storyboard = findStoryboard(parsed, options.storyboardId);\n const edits: CanvasSourceEdit[] = [\n {\n ...expandToFullLines(options.source, storyboard.jsxElementSpan),\n value: \"\",\n },\n ];\n\n if (options.removeUnusedComponentImport ?? true) {\n const importEdit = buildUnusedComponentImportRemoval({\n source: options.source,\n parsed,\n deletedStoryboard: storyboard,\n deletionEdit: edits[0],\n });\n if (importEdit) edits.push(importEdit);\n }\n\n const result = applyResult(options.source, parsed, edits);\n return {\n ...result,\n source: collapseBlankLines(result.source, detectNewline(options.source)),\n };\n}\n\nfunction applyResult(\n source: string,\n parsed: ParsedCanvasFile,\n edits: readonly (CanvasSourceEdit | null | undefined)[],\n): CanvasEditResult {\n const compactEdits = edits.filter((edit): edit is CanvasSourceEdit => {\n if (!edit) return false;\n return source.slice(edit.start, edit.end) !== edit.value;\n });\n return {\n source: applyCanvasSourceEdits(source, compactEdits),\n edits: compactEdits,\n parsed,\n };\n}\n\nfunction findStoryboard(\n parsed: ParsedCanvasFile,\n storyboardId: string,\n): ParsedCanvasStoryboard {\n const storyboard = parsed.storyboards.find(\n (item) => item.storyboardKey === storyboardId,\n );\n if (!storyboard) {\n throw new Error(`Storyboard \"${storyboardId}\" not found`);\n }\n return storyboard;\n}\n\nfunction requireStoryboardOpeningSpan(\n storyboard: ParsedCanvasStoryboard,\n storyboardId: string,\n): CanvasSourceSpan {\n return requiredSpan(\n storyboard.openingElementSpan,\n `Storyboard \"${storyboardId}\" opening element not found`,\n );\n}\n\nfunction upsertJsxStringAttribute(options: {\n source: string;\n openingElementSpan: CanvasSourceSpan;\n valueSpan?: CanvasSourceSpan;\n attributeSpan?: CanvasSourceSpan;\n name: string;\n value?: string;\n}): CanvasSourceEdit | null {\n if (options.value === undefined) {\n if (!options.attributeSpan) return null;\n return {\n ...expandJsxAttributeRemoval(options.source, options.attributeSpan),\n value: \"\",\n };\n }\n\n const value = JSON.stringify(options.value);\n if (options.valueSpan) {\n return {\n start: options.valueSpan.start,\n end: options.valueSpan.end,\n value,\n };\n }\n\n const offset = findOpeningElementAttributeInsertionOffset(\n options.source,\n options.openingElementSpan,\n );\n return {\n start: offset,\n end: offset,\n value: ` ${options.name}={${value}}`,\n };\n}\n\nfunction upsertObjectStringProperty(options: {\n source: string;\n objectClose?: number;\n valueSpan?: CanvasSourceSpan;\n propertySpan?: CanvasSourceSpan;\n name: string;\n value?: string;\n}): CanvasSourceEdit | null {\n if (options.value === undefined) {\n if (!options.propertySpan) return null;\n return {\n ...expandObjectPropertyRemoval(options.source, options.propertySpan),\n value: \"\",\n };\n }\n\n const value = JSON.stringify(options.value);\n if (options.valueSpan) {\n return {\n start: options.valueSpan.start,\n end: options.valueSpan.end,\n value,\n };\n }\n\n if (typeof options.objectClose !== \"number\") {\n throw new Error(`Object close not found for \"${options.name}\" property`);\n }\n\n return insertObjectProperty(\n options.source,\n options.objectClose,\n `${options.name}: ${value}`,\n );\n}\n\nfunction upsertJsxExpressionAttribute(options: {\n source: string;\n openingElementSpan: CanvasSourceSpan;\n expressionSpan?: CanvasSourceSpan;\n attributeSpan?: CanvasSourceSpan;\n name: string;\n value?: string;\n}): CanvasSourceEdit | null {\n if (options.value === undefined) {\n if (!options.attributeSpan) return null;\n return {\n ...expandJsxAttributeRemoval(options.source, options.attributeSpan),\n value: \"\",\n };\n }\n\n if (options.expressionSpan) {\n return {\n start: options.expressionSpan.start,\n end: options.expressionSpan.end,\n value: options.value,\n };\n }\n\n const offset = findOpeningElementAttributeInsertionOffset(\n options.source,\n options.openingElementSpan,\n );\n return {\n start: offset,\n end: offset,\n value: ` ${options.name}={${options.value}}`,\n };\n}\n\nfunction insertObjectProperty(\n source: string,\n objectClose: number,\n propertySource: string,\n): CanvasSourceEdit {\n const offset = trimWhitespaceBeforeOffset(source, objectClose);\n const previous = previousMeaningfulCharacter(source, offset);\n return {\n start: offset,\n end: offset,\n value: `${previous === \"{\" || previous === \",\" ? \" \" : \", \"}${propertySource}`,\n };\n}\n\nfunction formatStoryboardElement(options: {\n source: string;\n insertionOffset: number;\n tag: string;\n storyboard: AddCanvasStoryboardInput;\n componentExpression?: string;\n}): string {\n const newline = detectNewline(options.source);\n const closingIndent = lineIndentAt(options.source, options.insertionOffset);\n const indent = `${closingIndent} `;\n const firstLineIndent = \" \";\n const propIndent = `${indent} `;\n const props = storyboardElementProps(\n options.storyboard,\n options.componentExpression,\n );\n\n return `${firstLineIndent}<${options.tag}${newline}${props\n .map((prop) => `${propIndent}${prop}`)\n .join(newline)}${newline}${indent}/>${newline}${closingIndent}`;\n}\n\nfunction buildCanvasChildInsertionEdit(options: {\n source: string;\n parsed: ParsedCanvasFile;\n tag: string;\n storyboard: AddCanvasStoryboardInput;\n componentExpression?: string;\n}): CanvasSourceEdit {\n const insertionOffset = options.parsed.canvasChildrenInsertionOffset;\n if (typeof insertionOffset === \"number\") {\n return {\n start: insertionOffset,\n end: insertionOffset,\n value: formatStoryboardElement({\n source: options.source,\n insertionOffset,\n tag: options.tag,\n storyboard: options.storyboard,\n componentExpression: options.componentExpression,\n }),\n };\n }\n\n const openingSpan = options.parsed.canvasOpeningElementSpan;\n if (!openingSpan) {\n throw new Error(\"Canvas closing element not found\");\n }\n\n const openingSource = options.source.slice(\n openingSpan.start,\n openingSpan.end,\n );\n const selfClosingMatch = openingSource.match(/\\s*\\/\\s*>$/);\n const canvasName = openingSource.match(\n /^<\\s*([A-Za-z_$][\\w$]*(?:\\.[A-Za-z_$][\\w$]*)*)/,\n )?.[1];\n if (!selfClosingMatch || !canvasName) {\n throw new Error(\"Canvas closing element not found\");\n }\n\n const newline = detectNewline(options.source);\n const replacementStart = openingSpan.end - selfClosingMatch[0].length;\n const closingIndent = lineIndentAt(options.source, openingSpan.start);\n const childIndent = `${closingIndent} `;\n const propIndent = `${childIndent} `;\n const props = storyboardElementProps(\n options.storyboard,\n options.componentExpression,\n );\n\n return {\n start: replacementStart,\n end: openingSpan.end,\n value: `>${newline}${childIndent}<${options.tag}${newline}${props\n .map((prop) => `${propIndent}${prop}`)\n .join(\n newline,\n )}${newline}${childIndent}/>${newline}${closingIndent}</${canvasName}>`,\n };\n}\n\nfunction storyboardElementProps(\n storyboard: AddCanvasStoryboardInput,\n componentExpression?: string,\n): string[] {\n const idProp = formatJsxStringAttribute(\n \"id\",\n requireNonEmpty(storyboard.id, \"Storyboard id\"),\n );\n\n // LegacyStoryboardV1 carries only `id` + `storyboard={Expr}`; name and\n // layout live on the referenced object, so they are never emitted here.\n if (storyboard.kind === \"legacy-v1\") {\n return [idProp, `storyboard={${storyboard.storyboardExpression}}`];\n }\n\n if (\n (storyboard.kind === \"route\" || storyboard.kind === \"html\") &&\n (storyboard.layout.width === undefined ||\n storyboard.layout.height === undefined)\n ) {\n throw new Error(\"Route and HTML layouts require width and height\");\n }\n return [\n idProp,\n ...(storyboard.name && storyboard.name.trim() !== \"\"\n ? [formatJsxStringAttribute(\"name\", storyboard.name)]\n : []),\n ...storyboardKindProps(storyboard, componentExpression),\n `layout={{ ${formatLayout(storyboard.layout)} }}`,\n ];\n}\n\n/**\n * Format a JSX string attribute. Prefers the idiomatic plain form\n * (`name=\"value\"`) and falls back to the expression form (`name={\"value\"}`)\n * when the plain form can't represent the value faithfully: JSX string\n * attributes don't process backslash escapes but DO decode HTML entities, so\n * any value that JSON-escapes (quotes, backslashes, control characters) or\n * contains `&` must go through a braced string literal.\n */\nexport function formatJsxStringAttribute(name: string, value: string): string {\n const encoded = JSON.stringify(value);\n const plainSafe = encoded === `\"${value}\"` && !value.includes(\"&\");\n return plainSafe ? `${name}=${encoded}` : `${name}={${encoded}}`;\n}\n\nfunction storyboardKindProps(\n // legacy-v1 never reaches here: `storyboardElementProps` emits its\n // `storyboard={…}` prop directly (it has no name/layout attributes).\n storyboard: Exclude<AddCanvasStoryboardInput, { kind: \"legacy-v1\" }>,\n componentExpression?: string,\n): string[] {\n if (storyboard.kind === \"component\") {\n return [\n `component={${componentExpression}}`,\n ...(storyboard.props && storyboard.props.trim() !== \"\"\n ? [`props={${storyboard.props.trim()}}`]\n : []),\n ];\n }\n if (storyboard.kind === \"route\") {\n return [formatJsxStringAttribute(\"route\", storyboard.route)];\n }\n return [\n ...(storyboard.filepath\n ? [formatJsxStringAttribute(\"filepath\", storyboard.filepath)]\n : []),\n ...(storyboard.src\n ? [formatJsxStringAttribute(\"src\", storyboard.src)]\n : []),\n ];\n}\n\nfunction formatLayout(layout: CanvasEditorLayout & V1LayoutCompat): string {\n return [\n `x: ${roundLayoutNumber(layout.x)}`,\n `y: ${roundLayoutNumber(layout.y)}`,\n ...(layout.width === undefined\n ? []\n : [`width: ${roundLayoutNumber(layout.width)}`]),\n ...(layout.height === undefined\n ? []\n : [`height: ${roundLayoutNumber(layout.height)}`]),\n ...(layout.zIndex === undefined\n ? []\n : [`zIndex: ${roundLayoutNumber(layout.zIndex)}`]),\n ...(layout.intrinsicSizing === undefined\n ? []\n : [`intrinsicSizing: ${JSON.stringify(layout.intrinsicSizing)}`]),\n ].join(\", \");\n}\n\nfunction sdkComponentForStoryboard(\n storyboard: AddCanvasStoryboardInput,\n): SdkComponent {\n if (storyboard.kind === \"route\") return \"RouteStoryboard\";\n if (storyboard.kind === \"html\") return \"HtmlStoryboard\";\n if (storyboard.kind === \"legacy-v1\") return \"LegacyStoryboardV1\";\n if (storyboard.uiFramework === \"svelte\") return \"SvelteStoryboard\";\n if (storyboard.uiFramework === \"astro\") return \"AstroStoryboard\";\n return \"Storyboard\";\n}\n\nfunction resolveSdkTag(\n parsed: ParsedCanvasFile,\n component: SdkComponent,\n): { tag: string; importLine?: string } {\n const sdkSource =\n component === \"SvelteStoryboard\"\n ? \"tempo-sdk/canvas/svelte\"\n : component === \"AstroStoryboard\"\n ? \"tempo-sdk/canvas/astro\"\n : \"tempo-sdk/canvas\";\n for (const item of parsed.imports) {\n if (item.source !== sdkSource) continue;\n if (item.kind === \"namespace\")\n return { tag: `${item.localName}.${component}` };\n if (item.importedName === component) return { tag: item.localName };\n }\n\n const localName = pickAvailableIdentifier(parsed, `TempoCanvas${component}`);\n return {\n tag: localName,\n importLine: `import { ${component} as ${localName} } from \"${sdkSource}\";`,\n };\n}\n\nfunction buildMissingComponentImportLine(\n parsed: ParsedCanvasFile,\n source: string,\n componentImport: {\n localName: string;\n source: string;\n importedName?: string;\n },\n): string | null {\n const existing = parsed.imports.find(\n (item) => item.localName === componentImport.localName,\n );\n if (existing) {\n if (existing.source !== componentImport.source) {\n throw new Error(\n `Import binding \"${componentImport.localName}\" already exists`,\n );\n }\n return null;\n }\n // Collision check that THROWS — must not fire on the name merely appearing\n // inside a string literal (e.g. `<Canvas name=\"Card Demo\">` blocking a `Card`\n // import), so use the AST-based node scan, never the textual `hasIdentifier`.\n if (\n sourceContainsIdentifierNode(\n parsed.filePath,\n source,\n componentImport.localName,\n )\n ) {\n throw new Error(`Identifier \"${componentImport.localName}\" already exists`);\n }\n\n if (\n !componentImport.importedName ||\n componentImport.importedName === \"default\"\n ) {\n return `import ${componentImport.localName} from ${JSON.stringify(\n componentImport.source,\n )};`;\n }\n\n const specifier =\n componentImport.importedName === componentImport.localName\n ? componentImport.localName\n : `${componentImport.importedName} as ${componentImport.localName}`;\n return `import { ${specifier} } from ${JSON.stringify(componentImport.source)};`;\n}\n\nfunction buildImportInsertionEdit(\n source: string,\n parsed: ParsedCanvasFile,\n importLines: readonly string[],\n): CanvasSourceEdit | null {\n if (importLines.length === 0) return null;\n const newline = detectNewline(source);\n const uniqueLines = Array.from(new Set(importLines));\n const lastImport = parsed.imports.reduce<ParsedCanvasImport | null>(\n (latest, item) =>\n !latest || item.declarationSpan.end > latest.declarationSpan.end\n ? item\n : latest,\n null,\n );\n\n if (lastImport) {\n return {\n start: lastImport.declarationSpan.end,\n end: lastImport.declarationSpan.end,\n value: `${newline}${uniqueLines.join(newline)}`,\n };\n }\n\n const offset = topLevelInsertionOffset(source);\n return {\n start: offset,\n end: offset,\n value: `${uniqueLines.join(newline)}${newline}`,\n };\n}\n\nfunction buildUnusedComponentImportRemoval(options: {\n source: string;\n parsed: ParsedCanvasFile;\n deletedStoryboard: ParsedCanvasStoryboard;\n deletionEdit: CanvasSourceEdit;\n}): CanvasSourceEdit | null {\n const componentImport = options.deletedStoryboard.component?.import;\n if (!componentImport || componentImport.importKind === \"type\") return null;\n\n const usedByRemainingStoryboard = options.parsed.storyboards.some(\n (storyboard) =>\n storyboard.storyboardKey !== options.deletedStoryboard.storyboardKey &&\n storyboard.component?.import?.localName === componentImport.localName,\n );\n if (usedByRemainingStoryboard) return null;\n\n const sourceAfterStoryboardDelete = applyCanvasSourceEdits(options.source, [\n options.deletionEdit,\n ]);\n\n if (componentImport.specifierCount === 1) {\n const sourceWithoutImport = removeSpanText(\n sourceAfterStoryboardDelete,\n componentImport.declarationSpan,\n );\n if (hasIdentifier(sourceWithoutImport, componentImport.localName))\n return null;\n\n return {\n ...expandToFullLines(options.source, componentImport.declarationSpan),\n value: \"\",\n };\n }\n\n if (\n componentImport.kind !== \"named\" ||\n componentImport.hasDefaultSpecifier ||\n componentImport.hasNamespaceSpecifier ||\n componentImport.namedSpecifierCount <= 1\n ) {\n return null;\n }\n\n const specifierRange = expandImportSpecifierRemovalRange(\n options.source,\n componentImport.span,\n );\n const sourceWithoutImport = removeSpanText(\n sourceAfterStoryboardDelete,\n specifierRange,\n );\n if (hasIdentifier(sourceWithoutImport, componentImport.localName))\n return null;\n\n return {\n ...specifierRange,\n value: \"\",\n };\n}\n\nfunction expandImportSpecifierRemovalRange(\n source: string,\n span: CanvasSourceSpan,\n): CanvasSourceSpan {\n const lineStart = Math.max(source.lastIndexOf(\"\\n\", span.start - 1) + 1, 0);\n const nextNewline = source.indexOf(\"\\n\", span.end);\n const lineEnd = nextNewline >= 0 ? nextNewline + 1 : source.length;\n const before = source.slice(lineStart, span.start);\n const after = source.slice(span.end, lineEnd);\n if (/^[ \\t]*$/.test(before) && /^[ \\t]*(,)?[ \\t]*(\\r?\\n)?$/.test(after)) {\n return { start: lineStart, end: lineEnd };\n }\n\n let start = span.start;\n let end = span.end;\n while (end < source.length && /\\s/.test(source[end] ?? \"\")) end++;\n if (source[end] === \",\") {\n end++;\n while (\n end < source.length &&\n (source[end] === \" \" || source[end] === \"\\t\")\n ) {\n end++;\n }\n return { start, end };\n }\n\n while (\n start > 0 &&\n (source[start - 1] === \" \" || source[start - 1] === \"\\t\")\n ) {\n start--;\n }\n if (source[start - 1] === \",\") {\n start--;\n while (\n start > 0 &&\n (source[start - 1] === \" \" || source[start - 1] === \"\\t\")\n ) {\n start--;\n }\n }\n return { start, end };\n}\n\nfunction removeSpanText(source: string, span: CanvasSourceSpan): string {\n return source.slice(0, span.start) + source.slice(span.end);\n}\n\nfunction findOpeningElementAttributeInsertionOffset(\n source: string,\n span: CanvasSourceSpan,\n): number {\n const close = source.lastIndexOf(\">\", span.end - 1);\n if (close < span.start) {\n throw new Error(\"JSX opening element close not found\");\n }\n return source[close - 1] === \"/\" ? close - 1 : close;\n}\n\nfunction insertBareJsxAttributeLine(options: {\n source: string;\n openingElementSpan: CanvasSourceSpan;\n name: string;\n}): CanvasSourceEdit {\n const offset = findOpeningElementAttributeInsertionOffset(\n options.source,\n options.openingElementSpan,\n );\n const newline = detectNewline(options.source);\n const openingIndent = lineIndentAt(\n options.source,\n options.openingElementSpan.start,\n );\n const openingLineEnd = options.source.indexOf(\n \"\\n\",\n options.openingElementSpan.start,\n );\n const existingAttributeIndent =\n openingLineEnd >= 0 && openingLineEnd < offset\n ? options.source\n .slice(openingLineEnd + 1, offset)\n .split(/\\r?\\n/)\n .find((line) => line.trim() !== \"\")\n ?.match(/^[ \\t]*/)?.[0]\n : undefined;\n const attributeIndent =\n existingAttributeIndent &&\n existingAttributeIndent.length > openingIndent.length\n ? existingAttributeIndent\n : `${openingIndent}${openingIndent.includes(\"\\t\") ? \"\\t\" : \" \"}`;\n const closingLineStart = Math.max(\n options.source.lastIndexOf(\"\\n\", offset - 1) + 1,\n 0,\n );\n\n if (/^[ \\t]*$/.test(options.source.slice(closingLineStart, offset))) {\n return {\n start: closingLineStart,\n end: closingLineStart,\n value: `${attributeIndent}${options.name}${newline}`,\n };\n }\n\n let start = offset;\n while (\n start > options.openingElementSpan.start &&\n (options.source[start - 1] === \" \" || options.source[start - 1] === \"\\t\")\n ) {\n start--;\n }\n return {\n start,\n end: offset,\n value: `${newline}${attributeIndent}${options.name}${newline}${openingIndent}`,\n };\n}\n\nfunction expandJsxAttributeRemoval(\n source: string,\n span: CanvasSourceSpan,\n): CanvasSourceSpan {\n const lineStart = Math.max(source.lastIndexOf(\"\\n\", span.start - 1) + 1, 0);\n const nextNewline = source.indexOf(\"\\n\", span.end);\n const lineEnd = nextNewline >= 0 ? nextNewline : source.length;\n if (\n /^[ \\t]*$/.test(source.slice(lineStart, span.start)) &&\n /^[ \\t]*$/.test(source.slice(span.end, lineEnd))\n ) {\n return {\n start: lineStart,\n end: nextNewline >= 0 ? nextNewline + 1 : lineEnd,\n };\n }\n\n let start = span.start;\n let end = span.end;\n\n while (\n start > 0 &&\n (source[start - 1] === \" \" || source[start - 1] === \"\\t\")\n ) {\n start--;\n }\n while (end < source.length && (source[end] === \" \" || source[end] === \"\\t\")) {\n end++;\n }\n return { start, end };\n}\n\nfunction expandObjectPropertyRemoval(\n source: string,\n span: CanvasSourceSpan,\n): CanvasSourceSpan {\n let start = span.start;\n let end = span.end;\n\n while (start > 0 && /\\s/.test(source[start - 1] ?? \"\")) start--;\n while (end < source.length && /\\s/.test(source[end] ?? \"\")) end++;\n\n if (source[end] === \",\") {\n end++;\n while (\n end < source.length &&\n (source[end] === \" \" || source[end] === \"\\t\")\n ) {\n end++;\n }\n return { start, end };\n }\n\n let comma = start - 1;\n while (comma >= 0 && /\\s/.test(source[comma] ?? \"\")) comma--;\n if (source[comma] === \",\") {\n start = comma;\n }\n return { start, end };\n}\n\nexport function expandToFullLines(\n source: string,\n span: CanvasSourceSpan,\n): CanvasSourceSpan {\n let start = span.start;\n let end = span.end;\n while (\n start > 0 &&\n source[start - 1] !== \"\\n\" &&\n source[start - 1] !== \"\\r\"\n ) {\n start--;\n }\n if (start > 0) {\n if (source[start - 1] === \"\\n\") start--;\n if (start > 0 && source[start - 1] === \"\\r\") start--;\n }\n while (end < source.length && (source[end] === \" \" || source[end] === \"\\t\")) {\n end++;\n }\n if (source.slice(end, end + 2) === \"\\r\\n\") {\n end += 2;\n } else if (source[end] === \"\\n\" || source[end] === \"\\r\") {\n end++;\n }\n return { start, end };\n}\n\nexport function expandStatementForward(\n source: string,\n span: CanvasSourceSpan,\n): CanvasSourceSpan {\n let end = span.end;\n while (end < source.length && (source[end] === \" \" || source[end] === \"\\t\")) {\n end++;\n }\n if (source.slice(end, end + 2) === \"\\r\\n\") {\n end += 2;\n } else if (source[end] === \"\\n\" || source[end] === \"\\r\") {\n end++;\n }\n return { start: span.start, end };\n}\n\nfunction lineIndentAt(source: string, offset: number): string {\n const lineStart = Math.max(source.lastIndexOf(\"\\n\", offset - 1) + 1, 0);\n const linePrefix = source.slice(lineStart, offset);\n const match = linePrefix.match(/^[ \\t]*/);\n return match?.[0] ?? \"\";\n}\n\nfunction previousMeaningfulCharacter(source: string, offset: number): string {\n for (let index = offset - 1; index >= 0; index -= 1) {\n const character = source[index] ?? \"\";\n if (!/\\s/.test(character)) return character;\n }\n return \"\";\n}\n\nfunction trimWhitespaceBeforeOffset(source: string, offset: number): number {\n let nextOffset = offset;\n while (nextOffset > 0 && /\\s/.test(source[nextOffset - 1] ?? \"\")) {\n nextOffset--;\n }\n return nextOffset;\n}\n\nexport function collapseBlankLines(source: string, newline: string): string {\n return newline === \"\\r\\n\"\n ? source.replace(/(\\r\\n){3,}/g, \"\\r\\n\\r\\n\")\n : source.replace(/\\n{3,}/g, \"\\n\\n\");\n}\n\nexport function detectNewline(source: string): \"\\n\" | \"\\r\\n\" {\n return source.includes(\"\\r\\n\") ? \"\\r\\n\" : \"\\n\";\n}\n\nexport function topLevelInsertionOffset(source: string): number {\n let offset = 0;\n if (source.startsWith(\"#!\")) {\n const newline = source.indexOf(\"\\n\");\n offset = newline >= 0 ? newline + 1 : source.length;\n }\n\n while (true) {\n const nextLineEnd = source.indexOf(\"\\n\", offset);\n const end = nextLineEnd >= 0 ? nextLineEnd + 1 : source.length;\n const line = source.slice(offset, end).trim();\n if (!/^[\"']use [^\"']+[\"'];?$/.test(line)) break;\n offset = end;\n }\n\n return offset;\n}\n\nfunction pickAvailableIdentifier(\n parsed: ParsedCanvasFile,\n base: string,\n): string {\n const usedImports = new Set(parsed.imports.map((item) => item.localName));\n if (!usedImports.has(base)) return base;\n for (let index = 2; index < 10_000; index += 1) {\n const candidate = `${base}${index}`;\n if (!usedImports.has(candidate)) return candidate;\n }\n throw new Error(`Unable to find available identifier for ${base}`);\n}\n\n/**\n * Cheap word-boundary text scan. It matches occurrences inside string literals\n * and comments too, so it is SAFE-DIRECTION ONLY: use it where a false positive\n * is harmless (conservatively keeping an import that might still be used), NEVER\n * for a collision check that throws or blocks an edit — those must use\n * {@link sourceContainsIdentifierNode}, which counts real identifier nodes only.\n */\nexport function hasIdentifier(source: string, identifier: string): boolean {\n return new RegExp(`\\\\b${escapeRegExp(identifier)}\\\\b`).test(source);\n}\n\n/**\n * True when `name` appears as a real identifier node (`Identifier` /\n * `JSXIdentifier`) anywhere in `source` — a binding or reference, never a\n * string-literal or comment occurrence. Use this for collision checks that\n * throw or block an edit, so a name appearing only inside a string (e.g.\n * `<Canvas name=\"Card Demo\">` vs a `Card` import) can't masquerade as a\n * declared identifier.\n */\nexport function sourceContainsIdentifierNode(\n filePath: string,\n source: string,\n name: string,\n): boolean {\n const program = (parseSync(filePath, source) as any).program;\n let found = false;\n walkWithParent(program, (node) => {\n if (found) return;\n if (\n (node.type === \"Identifier\" || node.type === \"JSXIdentifier\") &&\n node.name === name\n ) {\n found = true;\n }\n });\n return found;\n}\n\n/**\n * Depth-first walk that hands each AST node to `visit` along with its parent and\n * the parent field it was reached through — the context callers need to tell a\n * value reference from a property key or member access.\n */\nexport function walkWithParent(\n node: any,\n visit: (node: any, parent: any, key: string | null) => void,\n parent: any = null,\n key: string | null = null,\n seen = new Set<any>(),\n): void {\n if (!node || typeof node !== \"object\" || seen.has(node)) return;\n seen.add(node);\n if (typeof node.type === \"string\") visit(node, parent, key);\n for (const [childKey, value] of Object.entries(node)) {\n if (!value || typeof value !== \"object\") continue;\n if (Array.isArray(value)) {\n for (const item of value)\n walkWithParent(item, visit, node, childKey, seen);\n } else {\n walkWithParent(value, visit, node, childKey, seen);\n }\n }\n}\n\nfunction escapeRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nfunction roundLayoutNumber(value: number): number {\n if (typeof value !== \"number\" || !Number.isFinite(value)) {\n throw new Error(\"Layout values must be finite numbers\");\n }\n return Math.round(value);\n}\n\nfunction requireNonEmpty(value: string, label: string): string {\n const trimmed = value.trim();\n if (!trimmed) {\n throw new Error(`${label} must be non-empty`);\n }\n return trimmed;\n}\n\nfunction requiredSpan<T>(value: T | undefined, message: string): T {\n if (value === undefined) {\n throw new Error(message);\n }\n return value;\n}\n","/**\n * @deprecated V1 client compat (file spelling).\n *\n * A released V1 Tempo client (app 0.0.114) parses the canvas files this SDK\n * writes. Its parser reads a component layout without width and height as\n * degraded and falls back to 600x400, so a responsive component board is\n * written in the legacy spelling `{ x, y, width, height, intrinsicSizing:\n * \"root-element\" }`, where width and height are a first-paint hint. The V2\n * parser and shell already read that spelling as responsive, so V2 behavior\n * does not change. Delete with v1-client-compat.ts once no protocol-1 client\n * is supported; the compiler then lists every call site.\n */\nimport type { CanvasEditorLayout } from \"./editor\";\nimport type { V1LayoutCompat } from \"./v1-client-compat\";\n\n/** How a component layout is spelled on disk so a V1 parser reads it. A\n * layout with a size is written as is. A responsive layout is written in the\n * legacy spelling with `hint` as its width and height: the hint the file\n * already carries, or the size the writer knows. Without a hint there is\n * nothing V1-readable to write and the layout is returned as is. */\nexport function v1ReadableLayout(\n layout: CanvasEditorLayout,\n hint: { width: number; height: number } | undefined,\n): CanvasEditorLayout & V1LayoutCompat {\n const fixed = layout.width !== undefined && layout.height !== undefined;\n if (fixed || !hint) return layout;\n return {\n ...layout,\n width: hint.width,\n height: hint.height,\n intrinsicSizing: \"root-element\",\n };\n}\n\n/** The first-paint hint a legacy responsive layout literal carries, read\n * from the literal's source text (the parser keeps no value or span for it).\n * The literal is machine-written with number literals, which the parser has\n * already required, so a plain property scan is enough. */\nexport function v1LayoutHint(\n layoutSource: string,\n): { width: number; height: number } | undefined {\n const width = readNumberProperty(layoutSource, \"width\");\n const height = readNumberProperty(layoutSource, \"height\");\n return width === undefined || height === undefined\n ? undefined\n : { width, height };\n}\n\nfunction readNumberProperty(source: string, key: string): number | undefined {\n const match = source.match(\n new RegExp(`(?:^|[{,\\\\s])${key}\\\\s*:\\\\s*(-?[0-9]*\\\\.?[0-9]+)`),\n );\n return match ? Number(match[1]) : undefined;\n}\n"],"mappings":";;;;;AAAA,SAAS,iBAAiB;;;ACoBnB,SAAS,iBACd,QACA,MACqC;AACrC,QAAM,QAAQ,OAAO,UAAU,UAAa,OAAO,WAAW;AAC9D,MAAI,SAAS,CAAC,KAAM,QAAO;AAC3B,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,KAAK;AAAA,IACZ,QAAQ,KAAK;AAAA,IACb,iBAAiB;AAAA,EACnB;AACF;AAMO,SAAS,aACd,cAC+C;AAC/C,QAAM,QAAQ,mBAAmB,cAAc,OAAO;AACtD,QAAM,SAAS,mBAAmB,cAAc,QAAQ;AACxD,SAAO,UAAU,UAAa,WAAW,SACrC,SACA,EAAE,OAAO,OAAO;AACtB;AAEA,SAAS,mBAAmB,QAAgB,KAAiC;AAC3E,QAAM,QAAQ,OAAO;AAAA,IACnB,IAAI,OAAO,gBAAgB,GAAG,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GAAG;AACxB,iBAAW,QAAQ;AACjB,uBAAe,MAAM,OAAO,MAAM,UAAU,IAAI;AAAA,IACpD,OAAO;AACL,qBAAe,OAAO,OAAO,MAAM,UAAU,IAAI;AAAA,IACnD;AAAA,EACF;AACF;AAEA,SAAS,aAAa,OAAuB;AAC3C,SAAO,MAAM,QAAQ,uBAAuB,MAAM;AACpD;AAEA,SAAS,kBAAkB,OAAuB;AAChD,MAAI,OAAO,UAAU,YAAY,CAAC,OAAO,SAAS,KAAK,GAAG;AACxD,UAAM,IAAI,MAAM,sCAAsC;AAAA,EACxD;AACA,SAAO,KAAK,MAAM,KAAK;AACzB;AAEA,SAAS,gBAAgB,OAAe,OAAuB;AAC7D,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,GAAG,KAAK,oBAAoB;AAAA,EAC9C;AACA,SAAO;AACT;AAEA,SAAS,aAAgB,OAAsB,SAAoB;AACjE,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,OAAO;AAAA,EACzB;AACA,SAAO;AACT;","names":["edit","sourceWithoutImport"]}
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode, ComponentType } from 'react';
3
- export { H as HtmlStoryboard, L as LegacyStoryboardV1, R as RouteStoryboard, S as Storyboard, a as StoryboardLayout, b as StoryboardSlot, c as StoryboardVrtConfig, d as StoryboardVrtIgnoreRegion } from '../storyboard-DjOF61B_.js';
3
+ export { H as HtmlStoryboard, L as LegacyStoryboardV1, R as RouteStoryboard, S as Storyboard, a as StoryboardLayout, b as StoryboardSlot, c as StoryboardVrtConfig, d as StoryboardVrtIgnoreRegion } from '../storyboard-4YdTYq_e.js';
4
4
  import '../page-DwLnOM5d.js';
5
5
  import '../v1-client-compat-qxaXEDm_.js';
6
6
 
@@ -1,6 +1,7 @@
1
1
  import {
2
- VITE_ERROR_FEED_KEY
3
- } from "../chunk-K3EYTZLL.js";
2
+ installTempoInteractProjectionSource
3
+ } from "../chunk-EYKOOLPL.js";
4
+ import "../chunk-2JRAG36X.js";
4
5
  import {
5
6
  AdmissionBudgetError,
6
7
  Canvas,
@@ -22,17 +23,16 @@ import {
22
23
  useRequiredCanvasHost,
23
24
  v1DirectUrlSize,
24
25
  v1RenderRequestSize
25
- } from "../chunk-7DT5DDSH.js";
26
+ } from "../chunk-6IR5JY6W.js";
27
+ import "../chunk-NSKYOKG5.js";
28
+ import "../chunk-6AAE4LYV.js";
26
29
  import {
27
- installTempoInteractProjectionSource
28
- } from "../chunk-MXKZZOLM.js";
30
+ VITE_ERROR_FEED_KEY
31
+ } from "../chunk-K3EYTZLL.js";
29
32
  import {
30
33
  TEMPO_INTERACT_FRAME_NAME,
31
34
  isTempoInteractFrameName
32
35
  } from "../chunk-65B52AR7.js";
33
- import "../chunk-TL4MGN7E.js";
34
- import "../chunk-5BHIHP25.js";
35
- import "../chunk-N2TYN3RB.js";
36
36
 
37
37
  // canvas/canvas-host.tsx
38
38
  import {
@@ -225,8 +225,12 @@ function CanvasImportBoundary({
225
225
  () => registerCanvasProblemScope(canvasPath),
226
226
  [canvasPath, registerCanvasProblemScope]
227
227
  );
228
+ const canvasElement = useMemo(
229
+ () => /* @__PURE__ */ jsx(LazyCanvas, { replacement }),
230
+ [LazyCanvas, replacement]
231
+ );
228
232
  return /* @__PURE__ */ jsx(CanvasImportErrorBoundary, { reportError, children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(CanvasPendingMarker, {}), children: /* @__PURE__ */ jsxs(CanvasContext, { path: canvasPath, children: [
229
- /* @__PURE__ */ jsx(LazyCanvas, { replacement }),
233
+ canvasElement,
230
234
  /* @__PURE__ */ jsx(CanvasCommitSignal, { onCommit: markCommitted })
231
235
  ] }) }) }, retryRevision);
232
236
  }
@@ -538,6 +542,7 @@ function readRenderRequest(commandType, payload) {
538
542
  importPath: importPath ?? target.canvasPath ?? target.renderId,
539
543
  importName: importName ?? target.storyboardId ?? target.renderId,
540
544
  ...props ? { props } : {},
545
+ ...payload.userInitiated === true ? { userInitiated: true } : {},
541
546
  ...readOptionalSize(payload),
542
547
  ...isV1CanvasClient() ? v1RenderRequestSize(payload) : {}
543
548
  };
@@ -564,21 +569,27 @@ function acquireRender(entries, request) {
564
569
  const changed = !renderRequestMatchesEntry(current, request);
565
570
  next.set(request.renderId, {
566
571
  ...request,
572
+ lastUsedAt: request.userInitiated ? Date.now() : current?.lastUsedAt,
567
573
  status: "active",
568
574
  activeCount: (current?.activeCount ?? 0) + 1,
569
575
  revision: changed ? (current?.revision ?? 0) + 1 : current?.revision ?? 1
570
576
  });
571
577
  return next;
572
578
  }
573
- function releaseRender(entries, renderId, maxCached, now = Date.now()) {
574
- const current = entries.get(renderId);
575
- if (!current) return entries;
579
+ function releaseRender(entries, renderId, maxCached, now = Date.now(), cacheWhenIdle) {
580
+ const previous = entries.get(renderId);
581
+ if (!previous) return entries;
582
+ const current = cacheWhenIdle === true ? { ...previous, lastUsedAt: now } : previous;
576
583
  const next = new Map(entries);
577
584
  const activeCount = Math.max(0, current.activeCount - 1);
578
585
  if (activeCount > 0) {
579
586
  next.set(renderId, { ...current, activeCount, status: "active" });
580
587
  return next;
581
588
  }
589
+ if (cacheWhenIdle === false && current.lastUsedAt === void 0) {
590
+ next.delete(renderId);
591
+ return next;
592
+ }
582
593
  next.set(renderId, {
583
594
  ...current,
584
595
  activeCount: 0,
@@ -588,7 +599,9 @@ function releaseRender(entries, renderId, maxCached, now = Date.now()) {
588
599
  return evictCachedRenders(next, maxCached);
589
600
  }
590
601
  function evictCachedRenders(entries, maxCached) {
591
- const cached = [...entries.values()].filter((entry) => entry.status === "cached").sort((a, b) => (a.lastInactiveAt ?? 0) - (b.lastInactiveAt ?? 0));
602
+ const cached = [...entries.values()].filter((entry) => entry.status === "cached").sort(
603
+ (a, b) => (a.lastUsedAt ?? 0) - (b.lastUsedAt ?? 0) || (a.lastInactiveAt ?? 0) - (b.lastInactiveAt ?? 0)
604
+ );
592
605
  const evicted = cached.slice(0, Math.max(0, cached.length - maxCached));
593
606
  if (evicted.length === 0) return entries;
594
607
  const next = new Map(entries);
@@ -602,6 +615,8 @@ function buildRenderStatePayload(entries, maxCached, canvasPaths = []) {
602
615
  ({
603
616
  activeCount: _activeCount,
604
617
  lastInactiveAt: _lastInactiveAt,
618
+ lastUsedAt: _lastUsedAt,
619
+ userInitiated: _userInitiated,
605
620
  revision: _revision,
606
621
  ...entry
607
622
  }) => entry
@@ -1689,9 +1704,15 @@ function useCanvasHostPostMessage(registeredCanvasPaths = [], urlPinnedRenderId
1689
1704
  [setEntries]
1690
1705
  );
1691
1706
  const releaseRenderLease = useCallback2(
1692
- (renderId) => {
1707
+ (renderId, cacheWhenIdle) => {
1693
1708
  setEntries(
1694
- (entries) => releaseRender(entries, renderId, maxCachedRef.current)
1709
+ (entries) => releaseRender(
1710
+ entries,
1711
+ renderId,
1712
+ maxCachedRef.current,
1713
+ Date.now(),
1714
+ cacheWhenIdle
1715
+ )
1695
1716
  );
1696
1717
  },
1697
1718
  [setEntries]
@@ -2197,7 +2218,10 @@ function useCanvasHostPostMessage(registeredCanvasPaths = [], urlPinnedRenderId
2197
2218
  }
2198
2219
  if (command.type === "render-pool:unrender") {
2199
2220
  const target = requireRenderTarget(command.type, payload);
2200
- releaseRenderLease(target.renderId);
2221
+ releaseRenderLease(
2222
+ target.renderId,
2223
+ typeof payload.cacheWhenIdle === "boolean" ? payload.cacheWhenIdle : void 0
2224
+ );
2201
2225
  ack();
2202
2226
  return;
2203
2227
  }