tempo-sdk 0.0.89 → 0.0.93

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 (82) hide show
  1. package/dist/assets/index.js +3 -3
  2. package/dist/astro/asset-preview-client.js +3 -3
  3. package/dist/astro.js +7 -7
  4. package/dist/canvas/astro.js +3 -3
  5. package/dist/canvas/editor.js +1 -1
  6. package/dist/canvas/index.js +157 -7
  7. package/dist/canvas/index.js.map +1 -1
  8. package/dist/canvas/interact-projection.js +4 -4
  9. package/dist/canvas/parser.js +1 -1
  10. package/dist/canvas/svelte.js +12 -4
  11. package/dist/canvas/svelte.js.map +1 -1
  12. package/dist/canvas/vue.js +3 -3
  13. package/dist/{chunk-DNERBE7A.js → chunk-3L4RRKC3.js} +17 -11
  14. package/dist/chunk-3L4RRKC3.js.map +1 -0
  15. package/dist/{chunk-2ZQMVAFM.js → chunk-6SOP4XU6.js} +98 -33
  16. package/dist/chunk-6SOP4XU6.js.map +1 -0
  17. package/dist/{chunk-Y72PIE3I.js → chunk-AFXE462X.js} +5 -4
  18. package/dist/{chunk-Y72PIE3I.js.map → chunk-AFXE462X.js.map} +1 -1
  19. package/dist/{chunk-DMT5MRMS.js → chunk-BQPKOVI5.js} +4 -3
  20. package/dist/{chunk-DMT5MRMS.js.map → chunk-BQPKOVI5.js.map} +1 -1
  21. package/dist/{chunk-I5MJ342V.js → chunk-CVUNZBRV.js} +3 -3
  22. package/dist/{chunk-H6OZIX2U.js → chunk-FGWGY3G3.js} +27 -3
  23. package/dist/chunk-FGWGY3G3.js.map +1 -0
  24. package/dist/{chunk-NXPP3CSM.js → chunk-FZVJVL3T.js} +2 -2
  25. package/dist/{chunk-GZ6KY7ZF.js → chunk-GHNHPVEI.js} +2 -2
  26. package/dist/{chunk-GZ6KY7ZF.js.map → chunk-GHNHPVEI.js.map} +1 -1
  27. package/dist/{chunk-3XEEVCM3.js → chunk-HNNZM2XM.js} +127 -66
  28. package/dist/chunk-HNNZM2XM.js.map +1 -0
  29. package/dist/{chunk-5M45Z7K6.js → chunk-LEBVQBDH.js} +83 -51
  30. package/dist/chunk-LEBVQBDH.js.map +1 -0
  31. package/dist/{chunk-X5ORR3FI.js → chunk-M7OOVEAR.js} +7 -7
  32. package/dist/chunk-MU7S7NU7.js +183 -0
  33. package/dist/chunk-MU7S7NU7.js.map +1 -0
  34. package/dist/{chunk-3JR2JRSV.js → chunk-N5MWY4H6.js} +2 -2
  35. package/dist/{chunk-3JR2JRSV.js.map → chunk-N5MWY4H6.js.map} +1 -1
  36. package/dist/{chunk-5VIBKVFO.js → chunk-U66QI3EN.js} +28 -18
  37. package/dist/chunk-U66QI3EN.js.map +1 -0
  38. package/dist/{chunk-XN2K7GED.js → chunk-XB6GU4CE.js} +32 -8
  39. package/dist/{chunk-XN2K7GED.js.map → chunk-XB6GU4CE.js.map} +1 -1
  40. package/dist/{chunk-SLAZCXFE.js → chunk-Y7EHQREO.js} +2 -2
  41. package/dist/{chunk-SLAZCXFE.js.map → chunk-Y7EHQREO.js.map} +1 -1
  42. package/dist/{controls-reader-Z7OQWYWQ.js → controls-reader-5MFHYBZZ.js} +4 -4
  43. package/dist/expo/plugin.cjs +97 -32
  44. package/dist/expo/plugin.cjs.map +1 -1
  45. package/dist/expo/plugin.js +1 -1
  46. package/dist/expo-babel-plugin.cjs +97 -32
  47. package/dist/expo-babel-plugin.cjs.map +1 -1
  48. package/dist/expo-babel-plugin.d.cts +2 -0
  49. package/dist/expo-babel-plugin.d.ts +2 -0
  50. package/dist/expo-babel-plugin.js +1 -1
  51. package/dist/index.d.ts +2 -0
  52. package/dist/index.js +6 -6
  53. package/dist/nextjs/plugin.cjs +1 -1
  54. package/dist/nextjs/plugin.cjs.map +1 -1
  55. package/dist/nextjs/plugin.js +1 -1
  56. package/dist/nextjs-loader.cjs +126 -37
  57. package/dist/nextjs-loader.cjs.map +1 -1
  58. package/dist/nextjs.cjs +1 -1
  59. package/dist/nextjs.cjs.map +1 -1
  60. package/dist/nextjs.d.cts +2 -0
  61. package/dist/nextjs.d.ts +2 -0
  62. package/dist/nextjs.js +1 -1
  63. package/dist/nuxt/runtime/identity.js +1 -1
  64. package/dist/nuxt.js +230 -53
  65. package/dist/nuxt.js.map +1 -1
  66. package/dist/svelte.js +99 -24
  67. package/dist/svelte.js.map +1 -1
  68. package/dist/vue.js +120 -22
  69. package/dist/vue.js.map +1 -1
  70. package/package.json +1 -1
  71. package/dist/chunk-2ZQMVAFM.js.map +0 -1
  72. package/dist/chunk-3XEEVCM3.js.map +0 -1
  73. package/dist/chunk-5M45Z7K6.js.map +0 -1
  74. package/dist/chunk-5VIBKVFO.js.map +0 -1
  75. package/dist/chunk-DNERBE7A.js.map +0 -1
  76. package/dist/chunk-H6BQZOAW.js +0 -121
  77. package/dist/chunk-H6BQZOAW.js.map +0 -1
  78. package/dist/chunk-H6OZIX2U.js.map +0 -1
  79. /package/dist/{chunk-I5MJ342V.js.map → chunk-CVUNZBRV.js.map} +0 -0
  80. /package/dist/{chunk-NXPP3CSM.js.map → chunk-FZVJVL3T.js.map} +0 -0
  81. /package/dist/{chunk-X5ORR3FI.js.map → chunk-M7OOVEAR.js.map} +0 -0
  82. /package/dist/{controls-reader-Z7OQWYWQ.js.map → controls-reader-5MFHYBZZ.js.map} +0 -0
@@ -468,26 +468,31 @@ function collectElementStates(root, options = {}) {
468
468
  return states;
469
469
  }
470
470
 
471
- // ../../modules/iframe-projection/html/runtime-mutations.ts
472
- var FORM_RUNTIME_MUTATION = "tempo:form-runtime-mutation";
473
- var CSS_RUNTIME_MUTATION = "tempo:css-runtime-mutation";
474
- var RUNTIME_MUTATION_SOURCE = String.raw`(scope => {
471
+ // ../../modules/iframe-projection/html/runtime-mutations-runtime.js
472
+ function installRuntimeMutations(scope) {
475
473
  const doc = scope.document;
476
474
  const undo = [];
477
475
  let active = true;
478
476
  const emit = (target, kind, detail) => {
479
- if (active) target.dispatchEvent(detail
480
- ? new scope.CustomEvent(kind, { bubbles: true, detail })
481
- : new scope.Event(kind, { bubbles: true }));
477
+ if (active)
478
+ target.dispatchEvent(
479
+ detail ? new scope.CustomEvent(kind, { bubbles: true, detail }) : new scope.Event(kind, { bubbles: true })
480
+ );
482
481
  };
483
- const form = target => {
484
- if (target instanceof scope.HTMLOptionElement) target = target.closest('select');
485
- if (target && target.isConnected) emit(target, 'tempo:form-runtime-mutation');
482
+ const form = (target) => {
483
+ if (target instanceof scope.HTMLOptionElement)
484
+ target = target.closest("select");
485
+ if (target && target.isConnected)
486
+ emit(target, "tempo:form-runtime-mutation");
486
487
  };
487
488
  const css = (target, mutable = false) => {
488
489
  const sheet = target instanceof scope.CSSStyleSheet ? target : target.parentStyleSheet;
489
490
  if (target === doc || sheet && (sheet.ownerNode?.isConnected || doc.adoptedStyleSheets.includes(sheet)))
490
- emit(doc, 'tempo:css-runtime-mutation', { ownerNode: sheet?.ownerNode ?? null, sheet: sheet ?? null, mutable });
491
+ emit(doc, "tempo:css-runtime-mutation", {
492
+ ownerNode: sheet?.ownerNode ?? null,
493
+ sheet: sheet ?? null,
494
+ mutable
495
+ });
491
496
  };
492
497
  const setter = (proto, key, changed) => {
493
498
  if (!proto) return;
@@ -496,7 +501,8 @@ var RUNTIME_MUTATION_SOURCE = String.raw`(scope => {
496
501
  const set = function(value) {
497
502
  const before = original.get?.call(this);
498
503
  original.set.call(this, value);
499
- if (key === 'adoptedStyleSheets' || before !== original.get?.call(this)) changed(this);
504
+ if (key === "adoptedStyleSheets" || before !== original.get?.call(this))
505
+ changed(this);
500
506
  };
501
507
  Object.defineProperty(proto, key, { ...original, set });
502
508
  undo.push(() => {
@@ -507,10 +513,15 @@ var RUNTIME_MUTATION_SOURCE = String.raw`(scope => {
507
513
  const method = (proto, key, changed) => {
508
514
  if (!proto) return;
509
515
  const original = Object.getOwnPropertyDescriptor(proto, key);
510
- if (typeof original?.value !== 'function' || !original.configurable) return;
516
+ if (typeof original?.value !== "function" || !original.configurable) return;
511
517
  const value = function(...args) {
512
518
  const result = original.value.apply(this, args);
513
- if (result instanceof scope.Promise) result.then(() => changed(this), () => {});
519
+ if (result instanceof scope.Promise)
520
+ result.then(
521
+ () => changed(this),
522
+ () => {
523
+ }
524
+ );
514
525
  else changed(this);
515
526
  return result;
516
527
  };
@@ -521,40 +532,61 @@ var RUNTIME_MUTATION_SOURCE = String.raw`(scope => {
521
532
  });
522
533
  };
523
534
  for (const [type, keys] of [
524
- ['HTMLInputElement', ['value', 'checked', 'valueAsNumber', 'valueAsDate']],
525
- ['HTMLTextAreaElement', ['value']],
526
- ['HTMLSelectElement', ['value', 'selectedIndex']],
527
- ['HTMLOptionElement', ['selected']],
528
- ]) for (const key of keys) setter(scope[type]?.prototype, key, form);
529
- for (const type of ['HTMLInputElement', 'HTMLTextAreaElement'])
530
- method(scope[type]?.prototype, 'setRangeText', form);
531
- for (const key of ['stepUp', 'stepDown']) method(scope.HTMLInputElement?.prototype, key, form);
532
- // CSSOM edits do not create MutationRecords, including declaration setters.
533
- for (const key of ['insertRule', 'deleteRule', 'addRule', 'removeRule', 'replace', 'replaceSync'])
535
+ ["HTMLInputElement", ["value", "checked", "valueAsNumber", "valueAsDate"]],
536
+ ["HTMLTextAreaElement", ["value"]],
537
+ ["HTMLSelectElement", ["value", "selectedIndex"]],
538
+ ["HTMLOptionElement", ["selected"]]
539
+ ])
540
+ for (const key of keys) setter(scope[type]?.prototype, key, form);
541
+ for (const type of ["HTMLInputElement", "HTMLTextAreaElement"])
542
+ method(scope[type]?.prototype, "setRangeText", form);
543
+ for (const key of ["stepUp", "stepDown"])
544
+ method(scope.HTMLInputElement?.prototype, key, form);
545
+ for (const key of [
546
+ "insertRule",
547
+ "deleteRule",
548
+ "addRule",
549
+ "removeRule",
550
+ "replace",
551
+ "replaceSync"
552
+ ])
534
553
  method(scope.CSSStyleSheet?.prototype, key, css);
535
- for (const key of ['insertRule', 'deleteRule']) method(scope.CSSGroupingRule?.prototype, key, css);
554
+ for (const key of ["insertRule", "deleteRule"])
555
+ method(scope.CSSGroupingRule?.prototype, key, css);
536
556
  const declarations = scope.CSSStyleDeclaration?.prototype;
537
- setter(declarations, 'cssText', target => { if (target.parentRule) css(target.parentRule); });
538
- for (const key of ['setProperty', 'removeProperty'])
539
- method(declarations, key, target => { if (target.parentRule) css(target.parentRule); });
540
- // Chromium's named declaration properties are own data properties, not
541
- // prototype setters. Observe exposure without proxying/changing native identity.
542
- // Receivers conservatively reread exposed sheets on the next head request.
543
- for (const proto of [scope.CSSStyleRule?.prototype, scope.CSSKeyframeRule?.prototype]) {
544
- const original = proto && Object.getOwnPropertyDescriptor(proto, 'style');
557
+ setter(declarations, "cssText", (target) => {
558
+ if (target.parentRule) css(target.parentRule);
559
+ });
560
+ for (const key of ["setProperty", "removeProperty"])
561
+ method(declarations, key, (target) => {
562
+ if (target.parentRule) css(target.parentRule);
563
+ });
564
+ for (const proto of [
565
+ scope.CSSStyleRule?.prototype,
566
+ scope.CSSKeyframeRule?.prototype
567
+ ]) {
568
+ const original = proto && Object.getOwnPropertyDescriptor(proto, "style");
545
569
  if (!original?.get || !original.configurable) continue;
546
- const get = function() { css(this, true); return original.get.call(this); };
547
- Object.defineProperty(proto, 'style', { ...original, get });
548
- undo.push(() => { if (Object.getOwnPropertyDescriptor(proto, 'style')?.get === get) Object.defineProperty(proto, 'style', original); });
570
+ const get = function() {
571
+ css(this, true);
572
+ return original.get.call(this);
573
+ };
574
+ Object.defineProperty(proto, "style", { ...original, get });
575
+ undo.push(() => {
576
+ if (Object.getOwnPropertyDescriptor(proto, "style")?.get === get)
577
+ Object.defineProperty(proto, "style", original);
578
+ });
549
579
  }
550
- setter(scope.CSSStyleRule?.prototype, 'selectorText', css);
551
- setter(scope.CSSKeyframeRule?.prototype, 'keyText', css);
552
- for (const key of ['appendRule', 'deleteRule']) method(scope.CSSKeyframesRule?.prototype, key, css);
553
- setter(scope.MediaList?.prototype, 'mediaText', () => css(doc));
554
- for (const key of ['appendMedium', 'deleteMedium']) method(scope.MediaList?.prototype, key, () => css(doc));
555
- setter(scope.Document?.prototype, 'adoptedStyleSheets', css);
556
- setter(scope.StyleSheet?.prototype, 'disabled', css);
557
- method(scope.HTMLFormElement?.prototype, 'reset', target => {
580
+ setter(scope.CSSStyleRule?.prototype, "selectorText", css);
581
+ setter(scope.CSSKeyframeRule?.prototype, "keyText", css);
582
+ for (const key of ["appendRule", "deleteRule"])
583
+ method(scope.CSSKeyframesRule?.prototype, key, css);
584
+ setter(scope.MediaList?.prototype, "mediaText", () => css(doc));
585
+ for (const key of ["appendMedium", "deleteMedium"])
586
+ method(scope.MediaList?.prototype, key, () => css(doc));
587
+ setter(scope.Document?.prototype, "adoptedStyleSheets", css);
588
+ setter(scope.StyleSheet?.prototype, "disabled", css);
589
+ method(scope.HTMLFormElement?.prototype, "reset", (target) => {
558
590
  for (const element of target.elements) form(element);
559
591
  });
560
592
  const dispose = () => {
@@ -563,18 +595,18 @@ var RUNTIME_MUTATION_SOURCE = String.raw`(scope => {
563
595
  for (const restore of undo.reverse()) restore();
564
596
  };
565
597
  return dispose;
566
- })`;
567
- var install;
598
+ }
599
+
600
+ // ../../modules/iframe-projection/html/runtime-mutations.ts
601
+ var FORM_RUNTIME_MUTATION = "tempo:form-runtime-mutation";
602
+ var CSS_RUNTIME_MUTATION = "tempo:css-runtime-mutation";
568
603
  var owners = /* @__PURE__ */ new WeakMap();
569
604
  function observeRuntimeMutations(doc) {
570
605
  if (!doc.defaultView) return () => {
571
606
  };
572
607
  let owner = owners.get(doc);
573
608
  if (!owner) {
574
- install ?? (install = new Function(
575
- `return ${RUNTIME_MUTATION_SOURCE}`
576
- )());
577
- owner = { count: 0, stop: install(doc.defaultView) };
609
+ owner = { count: 0, stop: installRuntimeMutations(doc.defaultView) };
578
610
  owners.set(doc, owner);
579
611
  }
580
612
  owner.count++;
@@ -608,4 +640,4 @@ export {
608
640
  captureAttributes,
609
641
  collectElementStates
610
642
  };
611
- //# sourceMappingURL=chunk-5M45Z7K6.js.map
643
+ //# sourceMappingURL=chunk-LEBVQBDH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../modules/iframe-projection/html/declared-facts.ts","../../../modules/iframe-projection/shared/capture-perf.ts","../../../modules/iframe-projection/html/displayability.ts","../../../modules/iframe-projection/html/selectors.ts","../../../modules/iframe-projection/html/capture.ts","../../../modules/iframe-projection/html/runtime-mutations-runtime.js","../../../modules/iframe-projection/html/runtime-mutations.ts"],"sourcesContent":["/**\n * Declared Capture Facts (producer-side)\n *\n * Computes the `DeclaredCaptureFacts` a capture producer attaches to its\n * `DomCapture`. Everything here reads the LIVE DOM the producer already\n * holds — never the serialized HTML string — so the facts are ground truth\n * rather than a re-parse of the payload. See specs/canvas-determinism.md §4.\n */\n\nimport type { DeclaredCaptureFacts } from \"./types\";\n\n/** Every source kind uses character offsets in the same annotation contract. */\nconst SOURCE_ANNOTATED_SELECTOR = \"[data-tempo-filepath]\";\n\n/**\n * Compute the declared facts for a capture.\n *\n * @param targetElement - The element whose subtree is serialized into\n * `dom.html` (the mutation LCA for scoped captures, or the capture root\n * for whole-surface ones).\n * @param captureRoot - The watched root. `complete` is `targetElement ===\n * captureRoot`. The render-error probe searches the WHOLE root (the error\n * overlay is a surface-level fact, not necessarily inside the scoped LCA).\n * @param scopeSelector - The selector the producer already computed for\n * `targetElement` relative to `captureRoot` (\"\" for whole-surface).\n * Surfaced as `scopeSelector` only when the capture is not complete.\n * @param portalElements - Live portal root elements whose content the\n * producer also serializes into `portals`. Their annotations count toward\n * `observedVersions`/`containedAnchors` exactly as the DOM subtree's do.\n */\nexport function computeDeclaredFacts(\n targetElement: Element,\n captureRoot: Element,\n scopeSelector: string,\n portalElements: readonly Element[],\n): DeclaredCaptureFacts {\n const observedVersions: Record<string, number> = {};\n const observedSourceVersions: Record<string, string> = {};\n const anchorSet = new Set<string>();\n\n const visit = (element: Element): void => {\n const filepath = element.getAttribute(\"data-tempo-filepath\");\n if (filepath == null || filepath.length === 0) return;\n\n const modifiedTsRaw = element.getAttribute(\"data-tempo-modifiedts\");\n if (modifiedTsRaw != null) {\n const modifiedTs = Number(modifiedTsRaw);\n if (!Number.isNaN(modifiedTs)) {\n const existing = observedVersions[filepath];\n if (existing === undefined || modifiedTs > existing) {\n observedVersions[filepath] = modifiedTs;\n // Co-locate the content-version token with the newest render: it\n // rides the same element that just set the file's MAX modifiedts.\n // Clear a stale token from an older render when the newest element\n // carries none (a mid-HMR mixed tree, or an old-SDK element).\n const version = element.getAttribute(\"data-tempo-source-version\");\n if (version != null && version.length > 0) {\n observedSourceVersions[filepath] = version;\n } else {\n delete observedSourceVersions[filepath];\n }\n }\n }\n }\n\n const position = element.getAttribute(\"data-tempo-position\");\n if (position != null && position.length > 0) {\n anchorSet.add(`${filepath} ${position}`);\n }\n };\n\n // The serialized population: the target subtree (including the target\n // element itself, whose annotations travel in `dom.attributes`) plus every\n // portal root and its descendants.\n const walkRoots: readonly Element[] = [targetElement, ...portalElements];\n for (const root of walkRoots) {\n if (root.matches(SOURCE_ANNOTATED_SELECTOR)) visit(root);\n for (const annotated of root.querySelectorAll(SOURCE_ANNOTATED_SELECTOR)) {\n visit(annotated);\n }\n }\n\n const complete = targetElement === captureRoot;\n\n return {\n complete,\n scopeSelector: complete ? null : scopeSelector,\n observedVersions,\n observedSourceVersions,\n containedAnchors: Array.from(anchorSet),\n renderError: computeRenderError(captureRoot),\n };\n}\n\n/**\n * Render-error boundary state for a capture root. Non-null iff a\n * `[data-render-error=\"true\"]` element exists anywhere in the live root\n * subtree (or is the root itself); its `data-render-error-message` becomes\n * `message` when present.\n */\nfunction computeRenderError(\n captureRoot: Element,\n): DeclaredCaptureFacts[\"renderError\"] {\n const errorElement = captureRoot.matches('[data-render-error=\"true\"]')\n ? captureRoot\n : captureRoot.querySelector('[data-render-error=\"true\"]');\n if (!errorElement) return null;\n return {\n message: errorElement.getAttribute(\"data-render-error-message\"),\n };\n}\n","/**\n * Capture-flush perf counters.\n *\n * Module-local mutable counters incremented by the hot paths that run inside\n * a combined-watch flush: the displayability walk's getComputedStyle reads,\n * the layout-kind style read during fiber serialization, and the\n * render-identity declaration walks. The flush resets them before capturing\n * and reads them after, shipping the totals on the emitted capture's `perf`\n * field — so the paths themselves never thread perf parameters through their\n * signatures. Increment-only: no DOM reads, no allocation.\n *\n * The same functions also run outside a flush (one-shot capture APIs); those\n * increments are simply discarded by the next flush's reset.\n */\n\ninterface CaptureFlushCounters {\n styleReadCount: number;\n identityNodesVisited: number;\n sourceVersionDomScanNodes: number;\n sourceVersionFiberSerializeNodes: number;\n sourceVersionFiberReductionNodes: number;\n sourceVersionFallbackScanNodes: number;\n}\n\nconst counters: CaptureFlushCounters = {\n styleReadCount: 0,\n identityNodesVisited: 0,\n sourceVersionDomScanNodes: 0,\n sourceVersionFiberSerializeNodes: 0,\n sourceVersionFiberReductionNodes: 0,\n sourceVersionFallbackScanNodes: 0,\n};\n\nconst producerReferencesByDocument = new Map<Document, number>();\nlet activeDocumentProducers = 0;\nlet activeRootObservers = 0;\nlet activeReactCommitSubscriptions = 0;\n\n/** Register one document producer and its one React commit subscription. */\nexport function registerDocumentCaptureProducer(\n document: Document,\n): () => void {\n const references = producerReferencesByDocument.get(document) ?? 0;\n if (references === 0) activeDocumentProducers += 1;\n producerReferencesByDocument.set(document, references + 1);\n activeReactCommitSubscriptions += 1;\n let active = true;\n return () => {\n if (!active) return;\n active = false;\n const current = producerReferencesByDocument.get(document) ?? 0;\n if (current <= 1) {\n producerReferencesByDocument.delete(document);\n activeDocumentProducers = Math.max(0, activeDocumentProducers - 1);\n } else {\n producerReferencesByDocument.set(document, current - 1);\n }\n activeReactCommitSubscriptions = Math.max(\n 0,\n activeReactCommitSubscriptions - 1,\n );\n };\n}\n\n/** Register one independently observed projection root. */\nexport function registerCaptureRootObserver(): () => void {\n activeRootObservers += 1;\n let active = true;\n return () => {\n if (!active) return;\n active = false;\n activeRootObservers = Math.max(0, activeRootObservers - 1);\n };\n}\n\nexport function readCaptureProducerCardinality(): {\n activeDocumentProducers: number;\n activeRootObservers: number;\n reactCommitSubscriptions: number;\n} {\n return {\n activeDocumentProducers,\n activeRootObservers,\n reactCommitSubscriptions: activeReactCommitSubscriptions,\n };\n}\n\n/** @internal Test isolation for producer ownership counters. */\nexport function _resetCaptureProducerCardinalityForTesting(): void {\n producerReferencesByDocument.clear();\n activeDocumentProducers = 0;\n activeRootObservers = 0;\n activeReactCommitSubscriptions = 0;\n}\n\n/** One getComputedStyle call on the capture path. */\nexport function countCaptureStyleRead(): void {\n counters.styleReadCount += 1;\n}\n\n/** One element/node visited by a render-identity declaration walk. */\nexport function countIdentityNodeVisited(): void {\n counters.identityNodesVisited += 1;\n}\n\nexport function countSourceVersionDomScanNode(): void {\n counters.sourceVersionDomScanNodes += 1;\n}\n\nexport function countSourceVersionFiberSerializeNode(): void {\n counters.sourceVersionFiberSerializeNodes += 1;\n}\n\nexport function countSourceVersionFiberReductionNode(): void {\n counters.sourceVersionFiberReductionNodes += 1;\n}\n\nexport function countSourceVersionFallbackScanNode(): void {\n counters.sourceVersionFallbackScanNodes += 1;\n}\n\nexport function resetCaptureFlushCounters(): void {\n counters.styleReadCount = 0;\n counters.identityNodesVisited = 0;\n counters.sourceVersionDomScanNodes = 0;\n counters.sourceVersionFiberSerializeNodes = 0;\n counters.sourceVersionFiberReductionNodes = 0;\n counters.sourceVersionFallbackScanNodes = 0;\n}\n\nexport function readCaptureFlushCounters(): Readonly<CaptureFlushCounters> {\n return { ...counters };\n}\n","import { countCaptureStyleRead } from \"../shared/capture-perf\";\nimport type { CaptureDisplayability } from \"./types\";\n\n/** Elements whose descendants do not contribute projected pixels/content. */\nconst IGNORED_CONTENT_TAGS = new Set([\n \"DATALIST\",\n \"LINK\",\n \"META\",\n \"NOSCRIPT\",\n \"SCRIPT\",\n \"STYLE\",\n \"TEMPLATE\",\n]);\n\nconst VISUAL_ASSET_TAGS = new Set([\n \"AUDIO\",\n \"CANVAS\",\n \"EMBED\",\n \"IFRAME\",\n \"IMG\",\n \"INPUT\",\n \"OBJECT\",\n \"SELECT\",\n \"SVG\",\n \"TEXTAREA\",\n \"VIDEO\",\n]);\n\n/**\n * Measures displayable structure in a live, styled document.\n *\n * The capture root itself is excluded because `DomCapture.dom.html` contains\n * its children. Supplemental roots are included because portal updates carry\n * each portal root's `outerHTML`. A null result means no browsing context was\n * available, so callers must omit the proof rather than infer it from markup.\n */\nexport function measureComputedDisplayability(\n captureRoot: Element,\n supplementalRoots: readonly Element[] = [],\n): CaptureDisplayability | null {\n const doc = captureRoot.ownerDocument;\n const view = doc.defaultView;\n if (\n !view ||\n !captureRoot.isConnected ||\n supplementalRoots.some(\n (root) => root.ownerDocument !== doc || !root.isConnected,\n )\n ) {\n return null;\n }\n\n const result: CaptureDisplayability = {\n version: 1,\n elementCount: 0,\n paintedElementCount: 0,\n nonEmptyTextNodeCount: 0,\n visualAssetCount: 0,\n };\n\n try {\n const rootBlocked = hasBlockingElementInChain(captureRoot, view);\n const rootTextVisible =\n !rootBlocked && elementHasVisibleComputedVisibility(captureRoot, view);\n for (const child of Array.from(captureRoot.childNodes)) {\n visitNode(child, rootBlocked, rootTextVisible, view, result);\n }\n\n for (const supplementalRoot of supplementalRoots) {\n visitNode(\n supplementalRoot,\n hasBlockingElementInChain(supplementalRoot.parentElement, view),\n true,\n view,\n result,\n );\n }\n } catch {\n // A producer declaration is proof. If style inspection is unavailable for\n // any part of the render domain, omit the whole profile conservatively.\n return null;\n }\n\n return result;\n}\n\nfunction visitNode(\n node: Node,\n blockedByAncestor: boolean,\n parentTextVisible: boolean,\n view: Window,\n result: CaptureDisplayability,\n): void {\n if (node.nodeType === 3) {\n if (\n !blockedByAncestor &&\n parentTextVisible &&\n (node.textContent?.trim().length ?? 0) > 0\n ) {\n result.nonEmptyTextNodeCount += 1;\n }\n return;\n }\n if (node.nodeType !== 1) return;\n\n const element = node as Element;\n const blocked = blockedByAncestor || elementBlocksSubtree(element, view);\n if (blocked) return;\n\n const visible = elementHasVisibleComputedVisibility(element, view);\n if (visible) {\n result.elementCount += 1;\n if (elementPaintsOwnPixels(element, view)) {\n result.paintedElementCount = (result.paintedElementCount ?? 0) + 1;\n }\n if (VISUAL_ASSET_TAGS.has(element.tagName)) {\n result.visualAssetCount += 1;\n }\n }\n\n for (const child of Array.from(element.childNodes)) {\n visitNode(child, false, visible, view, result);\n }\n}\n\nfunction elementPaintsOwnPixels(element: Element, view: Window): boolean {\n countCaptureStyleRead();\n const style = view.getComputedStyle(element);\n if (colorCanPaint(style.backgroundColor)) return true;\n if (style.backgroundImage && style.backgroundImage !== \"none\") return true;\n if (style.boxShadow && style.boxShadow !== \"none\") return true;\n if (\n style.outlineStyle !== \"none\" &&\n parseFloat(style.outlineWidth) > 0 &&\n colorCanPaint(style.outlineColor)\n ) {\n return true;\n }\n for (const side of [\"Top\", \"Right\", \"Bottom\", \"Left\"] as const) {\n if (\n style[`border${side}Style`] !== \"none\" &&\n parseFloat(style[`border${side}Width`]) > 0 &&\n colorCanPaint(style[`border${side}Color`])\n ) {\n return true;\n }\n }\n return false;\n}\n\nfunction colorCanPaint(value: string): boolean {\n const normalized = value.trim().toLowerCase().replace(/ /g, \"\");\n if (!normalized || normalized === \"transparent\") return false;\n return !(\n /^rgba\\([^)]*,0(?:\\.0+)?\\)$/.test(normalized) ||\n /^rgb\\([^)]*\\/0(?:\\.0+)?\\)$/.test(normalized)\n );\n}\n\nfunction hasBlockingElementInChain(\n start: Element | null,\n view: Window,\n): boolean {\n for (let element = start; element; element = element.parentElement) {\n if (elementBlocksSubtree(element, view)) return true;\n }\n return false;\n}\n\nfunction elementBlocksSubtree(element: Element, view: Window): boolean {\n if (IGNORED_CONTENT_TAGS.has(element.tagName)) return true;\n if (element.hasAttribute(\"hidden\")) return true;\n if (element.tagName === \"DIALOG\" && !element.hasAttribute(\"open\")) {\n return true;\n }\n if (\n element.tagName === \"INPUT\" &&\n element.getAttribute(\"type\")?.trim().toLowerCase() === \"hidden\"\n ) {\n return true;\n }\n\n countCaptureStyleRead();\n const style = view.getComputedStyle(element);\n const opacity = style.opacity.trim();\n return (\n style.display === \"none\" ||\n (opacity.length > 0 && Number(opacity) <= 0) ||\n style.getPropertyValue(\"content-visibility\") === \"hidden\"\n );\n}\n\nfunction elementHasVisibleComputedVisibility(\n element: Element,\n view: Window,\n): boolean {\n countCaptureStyleRead();\n const visibility = view.getComputedStyle(element).visibility;\n return visibility !== \"hidden\" && visibility !== \"collapse\";\n}\n","/**\n * CSS Selector Utilities\n *\n * Pure functions for generating CSS selectors.\n */\n\n/**\n * Generates a unique CSS selector path for an element.\n *\n * Uses nth-of-type notation when needed for uniqueness among siblings.\n *\n * @param element - Element to generate selector for\n * @param root - Optional root element to stop at (selector will be relative to this)\n * @returns CSS selector path (e.g., \"body > div > button:nth-of-type(2)\")\n *\n * @example\n * ```ts\n * generateSelector(document.querySelector('button'));\n * // \"body > div > button\"\n *\n * generateSelector(button, container);\n * // \"div > button\" (relative to container)\n * ```\n */\nexport function generateSelector(element: Element, root?: Element): string {\n // Special cases for well-known elements\n if (!root) {\n if (element === document.documentElement) return \":root\";\n if (element === document.head) return \"head\";\n if (element === document.body) return \"body\";\n }\n\n // If element is the root, return empty string\n if (root && element === root) return \"\";\n\n const parts: string[] = [];\n let current: Element | null = element;\n const stopAt = root ?? document.documentElement;\n\n while (current && current !== stopAt) {\n const parent: Element | null = current.parentElement;\n if (!parent) break;\n\n const tagName = current.tagName.toLowerCase();\n\n // Count same-type siblings to determine if :nth-of-type is needed\n let index = 1;\n let sibling = current.previousElementSibling;\n while (sibling) {\n if (sibling.tagName === current.tagName) index++;\n sibling = sibling.previousElementSibling;\n }\n\n let sameTypeSiblings = 0;\n for (const child of parent.children) {\n if (child.tagName === current.tagName) sameTypeSiblings++;\n }\n\n if (sameTypeSiblings > 1) {\n parts.unshift(`${tagName}:nth-of-type(${index})`);\n } else {\n parts.unshift(tagName);\n }\n\n current = parent;\n }\n\n // Handle edge cases\n if (parts.length === 0) {\n if (element === document.body) return \"body\";\n if (element === document.head) return \"head\";\n return \"\";\n }\n\n const path = parts.join(\" > \");\n\n // Anchor to root with :scope so querySelector matches at the correct depth.\n // Without this, \"div > div > div:nth-of-type(2)\" is ambiguous — it can match\n // any ancestor chain of divs at any depth within the subtree, not just the\n // specific depth from the root. :scope pins the first segment to a direct\n // child of the querySelector target.\n if (root) return `:scope > ${path}`;\n\n return path;\n}\n\n/**\n * Finds the Lowest Common Ancestor (LCA) of a set of nodes.\n *\n * The LCA is the deepest element that is an ancestor of all provided nodes.\n * Useful for determining the minimal subtree that contains all mutations.\n *\n * @param nodes - Set of DOM nodes to find common ancestor for\n * @returns The LCA element, or null if no common ancestor found\n */\nexport function findLowestCommonAncestor(nodes: Set<Node>): Element | null {\n if (nodes.size === 0) return null;\n\n // Build ancestor chains for each node (from root to node)\n const ancestorChains: Element[][] = [];\n\n for (const node of nodes) {\n const chain: Element[] = [];\n let current: Node | null =\n node instanceof Element ? node : node.parentElement;\n\n while (current && current !== document) {\n if (current instanceof Element) {\n chain.unshift(current);\n }\n current = current.parentNode;\n }\n\n if (chain.length > 0) {\n ancestorChains.push(chain);\n }\n }\n\n if (ancestorChains.length === 0) {\n return document.documentElement;\n }\n\n // Find the deepest common ancestor by comparing chains\n let lca: Element = document.documentElement;\n const firstChain = ancestorChains[0]!;\n const minLength = Math.min(...ancestorChains.map((c) => c.length));\n\n for (let i = 0; i < minLength; i++) {\n const candidate = firstChain[i];\n if (candidate && ancestorChains.every((chain) => chain[i] === candidate)) {\n lca = candidate;\n } else {\n break;\n }\n }\n\n return lca;\n}\n","/**\n * DOM Capture\n *\n * One-shot capture of DOM content and element states.\n */\n\nimport { computeDeclaredFacts } from \"./declared-facts\";\nimport { measureComputedDisplayability } from \"./displayability\";\nimport { generateSelector } from \"./selectors\";\nimport type { DomCapture, ElementState } from \"./types\";\n\nexport interface CollectElementStatesOptions {\n /** Whether to include document-level scroll via the :root selector. */\n includeDocumentScroll?: boolean;\n}\n\n/**\n * Captures the current state of an element as a DomCapture.\n *\n * @param element - Element to capture\n * @returns DomCapture containing HTML and element states\n *\n * @example\n * ```ts\n * const snapshot = capture(document.body);\n * // { dom: { selector: \"body\", html: \"...\" }, states: [...] }\n * ```\n */\nexport function capture(element: Element): DomCapture {\n return captureWithSupplementalRoots(element, []);\n}\n\n/** Internal complete-capture primitive used when a higher-level producer also\n * serializes supplemental roots such as owned React portals. */\nexport function captureWithSupplementalRoots(\n element: Element,\n supplementalRoots: readonly Element[],\n): DomCapture {\n // Sync form state to attributes before serializing\n syncFormStateToAttributes(element);\n\n // Selector relative to itself = \"\" (this IS the container)\n const selector = generateSelector(element, element);\n // Use innerHTML - we capture the children, not the container itself\n const html = removeScriptTags(element.innerHTML);\n const attributes = captureAttributes(element);\n const documentElementAttributes = element.ownerDocument\n ? captureAttributes(element.ownerDocument.documentElement)\n : undefined;\n const bodyAttributes = element.ownerDocument?.body\n ? captureAttributes(element.ownerDocument.body)\n : undefined;\n const baseUrl = element.ownerDocument?.baseURI;\n const states = collectElementStates(element);\n const displayability = measureComputedDisplayability(\n element,\n supplementalRoots,\n );\n\n return {\n // Whole-surface one-shot: the element is both the capture root and the\n // serialized scope, so `complete` is true and there is no scope selector.\n declared: computeDeclaredFacts(element, element, \"\", supplementalRoots),\n ...(displayability && { displayability }),\n dom: {\n selector,\n html,\n attributes,\n documentElementAttributes,\n bodyAttributes,\n },\n states,\n baseUrl,\n };\n}\n\n/**\n * Syncs form element state (DOM properties) to HTML attributes.\n *\n * Form elements like checkboxes, selects, and inputs have runtime state\n * that isn't reflected in their HTML attributes. This syncs that state\n * to attributes so it survives serialization.\n */\nfunction syncFormStateToAttributes(root: Element): void {\n // Checkboxes and radios\n for (const input of root.querySelectorAll(\n 'input[type=\"checkbox\"], input[type=\"radio\"]',\n )) {\n const el = input as HTMLInputElement;\n if (el.checked) {\n el.setAttribute(\"checked\", \"\");\n } else {\n el.removeAttribute(\"checked\");\n }\n }\n\n // Text inputs\n for (const input of root.querySelectorAll(\n 'input:not([type=\"checkbox\"]):not([type=\"radio\"])',\n )) {\n const el = input as HTMLInputElement;\n if (el.value !== el.getAttribute(\"value\")) {\n el.setAttribute(\"value\", el.value);\n }\n }\n\n // Textareas\n for (const textarea of root.querySelectorAll(\"textarea\")) {\n const el = textarea as HTMLTextAreaElement;\n if (el.value !== el.textContent) {\n el.textContent = el.value;\n }\n if (el.hasAttribute(\"value\")) {\n el.removeAttribute(\"value\");\n }\n }\n\n // Selects\n for (const select of root.querySelectorAll(\"select\")) {\n const el = select as HTMLSelectElement;\n for (const option of el.options) {\n if (option.selected) {\n option.setAttribute(\"selected\", \"\");\n } else {\n option.removeAttribute(\"selected\");\n }\n }\n }\n}\n\n/**\n * Removes all script tags from HTML string.\n */\nexport function removeScriptTags(html: string): string {\n return html.replace(/<script\\b[^>]*>[\\s\\S]*?<\\/script>/gi, \"\");\n}\n\n/**\n * Captures attributes from an element into a serializable map.\n */\nexport function captureAttributes(element: Element): Record<string, string> {\n const attrs: Record<string, string> = {};\n for (const attr of Array.from(element.attributes)) {\n attrs[attr.name] = attr.value;\n }\n return attrs;\n}\n\n/**\n * Collects current element states from a root element.\n *\n * Walks form elements and scrollable containers to collect their runtime state.\n */\nexport function collectElementStates(\n root: Element,\n options: CollectElementStatesOptions = {},\n): ElementState[] {\n const { includeDocumentScroll = true } = options;\n const states: ElementState[] = [];\n\n // Collect form states\n for (const input of root.querySelectorAll(\"input\")) {\n const el = input as HTMLInputElement;\n const isCheckable = el.type === \"checkbox\" || el.type === \"radio\";\n const hasNonDefault = isCheckable\n ? el.checked !== el.defaultChecked\n : el.value !== el.defaultValue;\n\n if (hasNonDefault) {\n const selector = generateSelector(el, root);\n if (isCheckable) {\n states.push({ selector, checked: el.checked });\n } else {\n states.push({ selector, value: el.value });\n }\n }\n }\n\n for (const textarea of root.querySelectorAll(\"textarea\")) {\n const el = textarea as HTMLTextAreaElement;\n if (el.value !== el.defaultValue) {\n const selector = generateSelector(el, root);\n states.push({ selector, value: el.value });\n }\n }\n\n for (const select of root.querySelectorAll(\"select\")) {\n const el = select as HTMLSelectElement;\n for (const option of el.options) {\n if (option.selected !== option.defaultSelected) {\n const selector = generateSelector(option, root);\n states.push({ selector, selected: option.selected });\n }\n }\n }\n\n // Collect scroll states - always include root and document-level scroll\n // so that scrolling back to 0 is properly communicated.\n states.push({\n selector: \"\",\n scrollTop: root.scrollTop,\n scrollLeft: root.scrollLeft,\n });\n\n // Check document-level scroll (scrollingElement, usually <html>)\n // This handles the common case where scroll is on documentElement, not body\n if (includeDocumentScroll) {\n const scrollingEl = root.ownerDocument?.scrollingElement;\n if (scrollingEl && scrollingEl !== root) {\n states.push({\n selector: \":root\",\n scrollTop: scrollingEl.scrollTop,\n scrollLeft: scrollingEl.scrollLeft,\n });\n }\n }\n\n for (const el of root.querySelectorAll(\"*\")) {\n if (el.scrollTop > 0 || el.scrollLeft > 0) {\n const selector = generateSelector(el, root);\n states.push({\n selector,\n scrollTop: el.scrollTop,\n scrollLeft: el.scrollLeft,\n });\n }\n }\n\n return states;\n}\n","/** Primary browser runtime; also emitted for isolated page injection. It must\n * stay self-contained. Ordinary producers call it without dynamic evaluation. */\nexport function installRuntimeMutations(scope) {\n const doc = scope.document;\n const undo = [];\n let active = true;\n const emit = (target, kind, detail) => {\n if (active)\n target.dispatchEvent(\n detail\n ? new scope.CustomEvent(kind, { bubbles: true, detail })\n : new scope.Event(kind, { bubbles: true }),\n );\n };\n const form = (target) => {\n if (target instanceof scope.HTMLOptionElement)\n target = target.closest(\"select\");\n if (target && target.isConnected)\n emit(target, \"tempo:form-runtime-mutation\");\n };\n const css = (target, mutable = false) => {\n const sheet =\n target instanceof scope.CSSStyleSheet ? target : target.parentStyleSheet;\n if (\n target === doc ||\n (sheet &&\n (sheet.ownerNode?.isConnected ||\n doc.adoptedStyleSheets.includes(sheet)))\n )\n emit(doc, \"tempo:css-runtime-mutation\", {\n ownerNode: sheet?.ownerNode ?? null,\n sheet: sheet ?? null,\n mutable,\n });\n };\n const setter = (proto, key, changed) => {\n if (!proto) return;\n const original = Object.getOwnPropertyDescriptor(proto, key);\n if (!original?.set || !original.configurable) return;\n const set = function (value) {\n const before = original.get?.call(this);\n original.set.call(this, value);\n if (key === \"adoptedStyleSheets\" || before !== original.get?.call(this))\n changed(this);\n };\n Object.defineProperty(proto, key, { ...original, set });\n undo.push(() => {\n if (Object.getOwnPropertyDescriptor(proto, key)?.set === set)\n Object.defineProperty(proto, key, original);\n });\n };\n const method = (proto, key, changed) => {\n if (!proto) return;\n const original = Object.getOwnPropertyDescriptor(proto, key);\n if (typeof original?.value !== \"function\" || !original.configurable) return;\n const value = function (...args) {\n const result = original.value.apply(this, args);\n if (result instanceof scope.Promise)\n result.then(\n () => changed(this),\n () => {},\n );\n else changed(this);\n return result;\n };\n Object.defineProperty(proto, key, { ...original, value });\n undo.push(() => {\n if (Object.getOwnPropertyDescriptor(proto, key)?.value === value)\n Object.defineProperty(proto, key, original);\n });\n };\n for (const [type, keys] of [\n [\"HTMLInputElement\", [\"value\", \"checked\", \"valueAsNumber\", \"valueAsDate\"]],\n [\"HTMLTextAreaElement\", [\"value\"]],\n [\"HTMLSelectElement\", [\"value\", \"selectedIndex\"]],\n [\"HTMLOptionElement\", [\"selected\"]],\n ])\n for (const key of keys) setter(scope[type]?.prototype, key, form);\n for (const type of [\"HTMLInputElement\", \"HTMLTextAreaElement\"])\n method(scope[type]?.prototype, \"setRangeText\", form);\n for (const key of [\"stepUp\", \"stepDown\"])\n method(scope.HTMLInputElement?.prototype, key, form);\n // CSSOM edits do not create MutationRecords, including declaration setters.\n for (const key of [\n \"insertRule\",\n \"deleteRule\",\n \"addRule\",\n \"removeRule\",\n \"replace\",\n \"replaceSync\",\n ])\n method(scope.CSSStyleSheet?.prototype, key, css);\n for (const key of [\"insertRule\", \"deleteRule\"])\n method(scope.CSSGroupingRule?.prototype, key, css);\n const declarations = scope.CSSStyleDeclaration?.prototype;\n setter(declarations, \"cssText\", (target) => {\n if (target.parentRule) css(target.parentRule);\n });\n for (const key of [\"setProperty\", \"removeProperty\"])\n method(declarations, key, (target) => {\n if (target.parentRule) css(target.parentRule);\n });\n // Chromium's named declaration properties are own data properties, not\n // prototype setters. Observe exposure without proxying/changing native identity.\n // Receivers conservatively reread exposed sheets on the next head request.\n for (const proto of [\n scope.CSSStyleRule?.prototype,\n scope.CSSKeyframeRule?.prototype,\n ]) {\n const original = proto && Object.getOwnPropertyDescriptor(proto, \"style\");\n if (!original?.get || !original.configurable) continue;\n const get = function () {\n css(this, true);\n return original.get.call(this);\n };\n Object.defineProperty(proto, \"style\", { ...original, get });\n undo.push(() => {\n if (Object.getOwnPropertyDescriptor(proto, \"style\")?.get === get)\n Object.defineProperty(proto, \"style\", original);\n });\n }\n setter(scope.CSSStyleRule?.prototype, \"selectorText\", css);\n setter(scope.CSSKeyframeRule?.prototype, \"keyText\", css);\n for (const key of [\"appendRule\", \"deleteRule\"])\n method(scope.CSSKeyframesRule?.prototype, key, css);\n setter(scope.MediaList?.prototype, \"mediaText\", () => css(doc));\n for (const key of [\"appendMedium\", \"deleteMedium\"])\n method(scope.MediaList?.prototype, key, () => css(doc));\n setter(scope.Document?.prototype, \"adoptedStyleSheets\", css);\n setter(scope.StyleSheet?.prototype, \"disabled\", css);\n method(scope.HTMLFormElement?.prototype, \"reset\", (target) => {\n for (const element of target.elements) form(element);\n });\n const dispose = () => {\n if (!active) return;\n active = false;\n for (const restore of undo.reverse()) restore();\n };\n return dispose;\n}\n","import { installRuntimeMutations } from \"./runtime-mutations-runtime.js\";\nexport { RUNTIME_MUTATION_SOURCE } from \"./runtime-mutations-source\";\n\n/** Browser-only mutation hooks shared by ordinary and isolated producers.\n * Notifications carry no values or authority: receivers read the actual DOM.\n * Private events avoid firing application input/change handlers. No polling.\n * The fixed source also installs in an isolated guest's page realm before JS.\n */\nexport const FORM_RUNTIME_MUTATION = \"tempo:form-runtime-mutation\";\nexport const CSS_RUNTIME_MUTATION = \"tempo:css-runtime-mutation\";\n\nconst owners = new WeakMap<Document, { count: number; stop(): void }>();\n\n/** Multiple root/head watchers share one set of hooks in their browser realm. */\nexport function observeRuntimeMutations(doc: Document): () => void {\n if (!doc.defaultView) return () => {};\n let owner = owners.get(doc);\n if (!owner) {\n owner = { count: 0, stop: installRuntimeMutations(doc.defaultView) };\n owners.set(doc, owner);\n }\n owner.count++;\n let released = false;\n return () => {\n if (released) return;\n released = true;\n if (--owner.count === 0) {\n owner.stop();\n owners.delete(doc);\n }\n };\n}\n"],"mappings":";AAYA,IAAM,4BAA4B;AAkB3B,SAAS,qBACd,eACA,aACA,eACA,gBACsB;AACtB,QAAM,mBAA2C,CAAC;AAClD,QAAM,yBAAiD,CAAC;AACxD,QAAM,YAAY,oBAAI,IAAY;AAElC,QAAM,QAAQ,CAAC,YAA2B;AACxC,UAAM,WAAW,QAAQ,aAAa,qBAAqB;AAC3D,QAAI,YAAY,QAAQ,SAAS,WAAW,EAAG;AAE/C,UAAM,gBAAgB,QAAQ,aAAa,uBAAuB;AAClE,QAAI,iBAAiB,MAAM;AACzB,YAAM,aAAa,OAAO,aAAa;AACvC,UAAI,CAAC,OAAO,MAAM,UAAU,GAAG;AAC7B,cAAM,WAAW,iBAAiB,QAAQ;AAC1C,YAAI,aAAa,UAAa,aAAa,UAAU;AACnD,2BAAiB,QAAQ,IAAI;AAK7B,gBAAM,UAAU,QAAQ,aAAa,2BAA2B;AAChE,cAAI,WAAW,QAAQ,QAAQ,SAAS,GAAG;AACzC,mCAAuB,QAAQ,IAAI;AAAA,UACrC,OAAO;AACL,mBAAO,uBAAuB,QAAQ;AAAA,UACxC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,WAAW,QAAQ,aAAa,qBAAqB;AAC3D,QAAI,YAAY,QAAQ,SAAS,SAAS,GAAG;AAC3C,gBAAU,IAAI,GAAG,QAAQ,IAAI,QAAQ,EAAE;AAAA,IACzC;AAAA,EACF;AAKA,QAAM,YAAgC,CAAC,eAAe,GAAG,cAAc;AACvE,aAAW,QAAQ,WAAW;AAC5B,QAAI,KAAK,QAAQ,yBAAyB,EAAG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MAAM;AACX,QAAI,SAAU;AACd,eAAW;AACX,QAAI,EAAE,MAAM,UAAU,GAAG;AACvB,YAAM,KAAK;AACX,aAAO,OAAO,GAAG;AAAA,IACnB;AAAA,EACF;AACF;","names":["document"]}
@@ -8,21 +8,21 @@ import {
8
8
  TEMPO_WORKSPACE_NONCE_META_NAME,
9
9
  createSdkFileMatcher,
10
10
  createTempoHostIdentity
11
- } from "./chunk-3JR2JRSV.js";
11
+ } from "./chunk-N5MWY4H6.js";
12
12
  import {
13
13
  appendModuleVersionRecord,
14
14
  cleanModuleId,
15
15
  computeTempoAnnotatedProps
16
- } from "./chunk-DMT5MRMS.js";
16
+ } from "./chunk-BQPKOVI5.js";
17
17
  import {
18
18
  annotateFile
19
- } from "./chunk-H6OZIX2U.js";
19
+ } from "./chunk-FGWGY3G3.js";
20
20
  import {
21
21
  sourceVersionHash
22
- } from "./chunk-H6BQZOAW.js";
22
+ } from "./chunk-MU7S7NU7.js";
23
23
  import {
24
24
  parseCanvasFile
25
- } from "./chunk-Y72PIE3I.js";
25
+ } from "./chunk-AFXE462X.js";
26
26
  import {
27
27
  canonicalPathAllowMissing,
28
28
  flutterPreviewKey
@@ -2265,7 +2265,7 @@ function tempoVitePlugin(options = {}) {
2265
2265
  const file = decodeURIComponent(
2266
2266
  id.slice("\0tempo:astro-component:".length, -3)
2267
2267
  );
2268
- const { readAstroControlsMetadata } = await import("./controls-reader-Z7OQWYWQ.js");
2268
+ const { readAstroControlsMetadata } = await import("./controls-reader-5MFHYBZZ.js");
2269
2269
  const controls = await readAstroControlsMetadata(
2270
2270
  file,
2271
2271
  async (specifier, importer) => (await this.resolve(specifier, importer, { skipSelf: true }))?.id ?? null,
@@ -2654,4 +2654,4 @@ export {
2654
2654
  tempoVitePlugin,
2655
2655
  tempoAnnotate
2656
2656
  };
2657
- //# sourceMappingURL=chunk-X5ORR3FI.js.map
2657
+ //# sourceMappingURL=chunk-M7OOVEAR.js.map
@@ -0,0 +1,183 @@
1
+ // ../../modules/annotation/source-version.ts
2
+ function sourceVersionHash(content) {
3
+ let djb2 = 5381;
4
+ let sdbm = 0;
5
+ for (let i = 0; i < content.length; i++) {
6
+ const c = content.charCodeAt(i);
7
+ djb2 = (djb2 << 5) + djb2 ^ c;
8
+ sdbm = c + (sdbm << 6) + (sdbm << 16) - sdbm | 0;
9
+ }
10
+ return toHex8(djb2) + toHex8(sdbm);
11
+ }
12
+ function toHex8(n) {
13
+ return (n >>> 0).toString(16).padStart(8, "0");
14
+ }
15
+
16
+ // ../../modules/annotation/literal-expression.ts
17
+ function unwrapLiteralExpression(node) {
18
+ let current = node;
19
+ while ([
20
+ "ParenthesizedExpression",
21
+ "TSAsExpression",
22
+ "TSSatisfiesExpression",
23
+ "TSTypeAssertion",
24
+ "TSNonNullExpression",
25
+ "TSInstantiationExpression"
26
+ ].includes(current.type)) {
27
+ const expression = current.expression;
28
+ if (!expression) break;
29
+ current = expression;
30
+ }
31
+ return current;
32
+ }
33
+ function readLiteralExpression(node) {
34
+ const value = unwrapLiteralExpression(node);
35
+ if (["Literal", "StringLiteral", "NumericLiteral", "BooleanLiteral"].includes(
36
+ value.type
37
+ )) {
38
+ if (typeof value.value === "string" || typeof value.value === "boolean")
39
+ return value.value;
40
+ if (typeof value.value === "number" && Number.isFinite(value.value))
41
+ return value.value;
42
+ }
43
+ if (value.type === "TemplateLiteral") {
44
+ const expressions = value.expressions;
45
+ const quasis = value.quasis;
46
+ if (expressions.length === 0 && quasis.length === 1 && typeof quasis[0]?.value.cooked === "string")
47
+ return quasis[0].value.cooked;
48
+ }
49
+ if (value.type === "UnaryExpression" && (value.operator === "-" || value.operator === "+")) {
50
+ const argument = readLiteralExpression(value.argument);
51
+ if (typeof argument === "number")
52
+ return value.operator === "-" ? -argument : argument;
53
+ }
54
+ if (value.type === "BinaryExpression" && ["+", "-", "*", "/"].includes(value.operator)) {
55
+ const left = readLiteralExpression(value.left);
56
+ const right = readLiteralExpression(value.right);
57
+ if (typeof left !== "number" || typeof right !== "number") return null;
58
+ const result = value.operator === "+" ? left + right : value.operator === "-" ? left - right : value.operator === "*" ? left * right : left / right;
59
+ return Number.isFinite(result) ? result : null;
60
+ }
61
+ return null;
62
+ }
63
+ function literalJsxChild(node) {
64
+ if (node.type !== "JSXExpressionContainer") return null;
65
+ const root = unwrapLiteralExpression(
66
+ node.expression
67
+ );
68
+ return root.type === "JSXElement" ? root : null;
69
+ }
70
+ function literalPropertyName(key, computed = false) {
71
+ if (!computed && key.type === "Identifier")
72
+ return typeof key.name === "string" ? key.name : null;
73
+ const value = readLiteralExpression(key);
74
+ return typeof value === "string" || typeof value === "number" ? String(value) : null;
75
+ }
76
+
77
+ // ../../modules/annotation/expression-facts.ts
78
+ var EXPRESSION_FACTS_ATTRIBUTE = "data-tempo-expr";
79
+ var DYNAMIC_SLOT_FACT = "#slot";
80
+ function expressionFacts(element, parentType, isStaticJsxChild = false) {
81
+ const opening = element.openingElement;
82
+ const attributes = opening.attributes;
83
+ const facts = [];
84
+ if (!isStaticJsxChild && parentType !== "JSXElement" && parentType !== "JSXFragment")
85
+ facts.push(DYNAMIC_SLOT_FACT);
86
+ const last = /* @__PURE__ */ new Map();
87
+ attributes.forEach((attribute, index) => {
88
+ const name = attributeName(attribute);
89
+ if (name !== null) last.set(name, index);
90
+ });
91
+ let lastSpread = -1;
92
+ attributes.forEach((attribute, index) => {
93
+ if (attribute.type === "JSXSpreadAttribute") lastSpread = index;
94
+ });
95
+ for (const [name, index] of last) {
96
+ if (unstamped(name)) continue;
97
+ const overridden = index < lastSpread;
98
+ const value = attributes[index].value;
99
+ if (value === null) continue;
100
+ if (name === "style" && !overridden) {
101
+ facts.push(...styleFacts(value));
102
+ continue;
103
+ }
104
+ if (overridden) facts.push(name);
105
+ else if (name === "className" && isClassHelperCall(value)) continue;
106
+ else if (!isLiteralValue(value)) facts.push(name);
107
+ }
108
+ if (facts.length > 0) return facts.join(" ");
109
+ return lastSpread >= 0 ? "" : void 0;
110
+ }
111
+ function attributeName(attribute) {
112
+ if (attribute.type !== "JSXAttribute") return null;
113
+ const name = attribute.name;
114
+ if (name.type === "JSXIdentifier") return name.name;
115
+ if (name.type === "JSXNamespacedName") {
116
+ const namespace = name.namespace.name;
117
+ return `${namespace}:${name.name.name}`;
118
+ }
119
+ return null;
120
+ }
121
+ function unstamped(name) {
122
+ return name === "key" || name.startsWith("data-tempo-");
123
+ }
124
+ function styleFacts(value) {
125
+ const expression = value.type === "JSXExpressionContainer" ? unwrap(value.expression) : value;
126
+ if (expression.type !== "ObjectExpression") return ["style"];
127
+ const properties = expression.properties;
128
+ const last = /* @__PURE__ */ new Map();
129
+ properties.forEach((property, index) => {
130
+ const key = styleKey(property);
131
+ if (key !== null) last.set(key, index);
132
+ });
133
+ const facts = [];
134
+ for (const [key, index] of last) {
135
+ const property = properties[index];
136
+ const overridden = properties.slice(index + 1).some(
137
+ (later) => later.type === "SpreadElement" || later.computed && styleKey(later) === null
138
+ );
139
+ const literal = property.type !== "ObjectMethod" && !property.shorthand && isLiteral(property.value);
140
+ if (overridden || !literal) facts.push(`style.${key}`);
141
+ }
142
+ return facts;
143
+ }
144
+ function styleKey(property) {
145
+ const isProperty = property.type === "Property" || property.type === "ObjectProperty" || property.type === "ObjectMethod";
146
+ if (!isProperty) return null;
147
+ return literalPropertyName(property.key, Boolean(property.computed));
148
+ }
149
+ function isLiteralValue(value) {
150
+ if (value.type === "Literal" || value.type === "StringLiteral") return true;
151
+ if (value.type !== "JSXExpressionContainer") return false;
152
+ return isLiteral(value.expression);
153
+ }
154
+ var CLASS_HELPERS = /* @__PURE__ */ new Set(["cn", "clsx", "twMerge", "cx", "classNames"]);
155
+ function isClassHelperCall(value) {
156
+ if (value.type !== "JSXExpressionContainer") return false;
157
+ const call = value.expression;
158
+ if (call.type !== "CallExpression") return false;
159
+ const callee = call.callee;
160
+ if (callee.type !== "Identifier" || !CLASS_HELPERS.has(callee.name))
161
+ return false;
162
+ return call.arguments.every(
163
+ (argument) => (argument.type === "Literal" || argument.type === "StringLiteral") && typeof argument.value === "string" || argument.type === "TemplateLiteral" && argument.expressions.length === 0
164
+ );
165
+ }
166
+ function isLiteral(node) {
167
+ return readLiteralExpression(node) !== null;
168
+ }
169
+ function unwrap(node) {
170
+ return unwrapLiteralExpression(node);
171
+ }
172
+
173
+ export {
174
+ unwrapLiteralExpression,
175
+ readLiteralExpression,
176
+ literalJsxChild,
177
+ literalPropertyName,
178
+ EXPRESSION_FACTS_ATTRIBUTE,
179
+ DYNAMIC_SLOT_FACT,
180
+ expressionFacts,
181
+ sourceVersionHash
182
+ };
183
+ //# sourceMappingURL=chunk-MU7S7NU7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../modules/annotation/source-version.ts","../../../modules/annotation/literal-expression.ts","../../../modules/annotation/expression-facts.ts"],"sourcesContent":["/**\n * Canvas source-version identity.\n *\n * `sourceVersionHash` maps the exact text of a source file to a 16-hex-character\n * token identifying that content. It is the version stamp the canvas edit/\n * reconcile loop uses to answer \"has the host caught up to write W?\": the SDK\n * JSX transforms stamp `data-tempo-source-version` with the hash of the source\n * they annotate, and the write pipeline (`applyWrites` → `sourceVersionsByFile`)\n * reports the hash of the exact bytes it wrote. A captured element's stamp is\n * compared for EQUALITY against a write's version — never ordered, never\n * subtracted, never used as a high-water mark. Two identical contents MUST\n * produce the same token; two different contents MUST (for identity purposes)\n * produce different tokens.\n *\n * Because coverage is an equality test across independently-computed hashes,\n * every producer of a version — this function's callers in the vite/next/expo\n * transforms and in `applyWrites` — MUST route through THIS function so the\n * tokens are bit-identical. Changing the algorithm requires changing it for all\n * producers in lockstep, or old stamps and new write-versions stop matching.\n *\n * The token concatenates two independent 32-bit rolling hashes over the string's\n * UTF-16 code units — djb2 and sdbm — each rendered as unsigned 8-char hex. Two\n * independent hash families make an accidental collision between distinct source\n * contents vanishingly unlikely for version-identity use, while the function\n * stays dependency-free and single-pass (fast enough to run once per file per\n * transform on the devserver hot path).\n */\nexport function sourceVersionHash(content: string): string {\n let djb2 = 5381;\n let sdbm = 0;\n for (let i = 0; i < content.length; i++) {\n const c = content.charCodeAt(i);\n // djb2: hash * 33 ^ c. The trailing `^ c` keeps the value inside 32-bit\n // signed range every iteration, so no explicit coercion is needed.\n djb2 = ((djb2 << 5) + djb2) ^ c;\n // sdbm: c + hash*65599. The final term is an arithmetic subtraction, so\n // coerce back to a 32-bit int each step to prevent float drift.\n sdbm = (c + (sdbm << 6) + (sdbm << 16) - sdbm) | 0;\n }\n return toHex8(djb2) + toHex8(sdbm);\n}\n\n/** Render a 32-bit value as unsigned, zero-padded 8-char lowercase hex. */\nfunction toHex8(n: number): string {\n return (n >>> 0).toString(16).padStart(8, \"0\");\n}\n","/** Syntax-only reading shared by source annotations and checked writers. */\nexport function unwrapLiteralExpression<T extends { type: string }>(\n node: T,\n): T {\n let current = node;\n while (\n [\n \"ParenthesizedExpression\",\n \"TSAsExpression\",\n \"TSSatisfiesExpression\",\n \"TSTypeAssertion\",\n \"TSNonNullExpression\",\n \"TSInstantiationExpression\",\n ].includes(current.type)\n ) {\n const expression = (current as T & { expression?: T }).expression;\n if (!expression) break;\n current = expression;\n }\n return current;\n}\n\n/** No names, calls or interpolation: only authored scalar values, with numeric literal arithmetic folded. */\nexport function readLiteralExpression(node: {\n type: string;\n [key: string]: unknown;\n}): string | number | boolean | null {\n const value = unwrapLiteralExpression(node);\n if (\n [\"Literal\", \"StringLiteral\", \"NumericLiteral\", \"BooleanLiteral\"].includes(\n value.type,\n )\n ) {\n if (typeof value.value === \"string\" || typeof value.value === \"boolean\")\n return value.value;\n if (typeof value.value === \"number\" && Number.isFinite(value.value))\n return value.value;\n }\n if (value.type === \"TemplateLiteral\") {\n const expressions = value.expressions as unknown[];\n const quasis = value.quasis as { value: { cooked?: string | null } }[];\n if (\n expressions.length === 0 &&\n quasis.length === 1 &&\n typeof quasis[0]?.value.cooked === \"string\"\n )\n return quasis[0].value.cooked;\n }\n if (\n value.type === \"UnaryExpression\" &&\n (value.operator === \"-\" || value.operator === \"+\")\n ) {\n const argument = readLiteralExpression(value.argument as typeof node);\n if (typeof argument === \"number\")\n return value.operator === \"-\" ? -argument : argument;\n }\n // `16 / 9` names nothing: arithmetic on numeric literals is as fixed as\n // `-10`. Numbers only, so `\"16\" + \"/9\"` stays an expression, and a\n // non-finite result (`16 / 0`) is not a value a writer could spell.\n if (\n value.type === \"BinaryExpression\" &&\n [\"+\", \"-\", \"*\", \"/\"].includes(value.operator as string)\n ) {\n const left = readLiteralExpression(value.left as typeof node);\n const right = readLiteralExpression(value.right as typeof node);\n if (typeof left !== \"number\" || typeof right !== \"number\") return null;\n const result =\n value.operator === \"+\"\n ? left + right\n : value.operator === \"-\"\n ? left - right\n : value.operator === \"*\"\n ? left * right\n : left / right;\n return Number.isFinite(result) ? result : null;\n }\n return null;\n}\n\n/** A braced, unconditional JSX element is still exactly one authored child. */\nexport function literalJsxChild<T extends { type: string }>(node: T): T | null {\n if (node.type !== \"JSXExpressionContainer\") return null;\n const root = unwrapLiteralExpression(\n (node as T & { expression: T }).expression,\n );\n return root.type === \"JSXElement\" ? root : null;\n}\n\n/** A property name that the written syntax determines without evaluating code. */\nexport function literalPropertyName(\n key: { type: string; [key: string]: unknown },\n computed = false,\n): string | null {\n if (!computed && key.type === \"Identifier\")\n return typeof key.name === \"string\" ? key.name : null;\n const value = readLiteralExpression(key);\n return typeof value === \"string\" || typeof value === \"number\"\n ? String(value)\n : null;\n}\n","/**\n * Expression facts: which parts of one JSX element's source are runtime\n * expressions, stamped as `data-tempo-expr` so the canvas can know before an\n * edit that the edit's operand is not literal source.\n *\n * The value is a space-separated token list. Each token is a fact, never a\n * decision:\n * - `#slot`: the element is not an unconditional JSX child, for example a\n * `.map` callback, conditional, return or prop value. A braced element with\n * only parentheses/type wrappers is a literal child. The `#` keeps this\n * fact apart from attribute names.\n * - `<name>`: the attribute is written at the callsite and its value is an\n * expression, or a later spread may override it.\n * - `style` alone: the style value is not an object literal, or a later\n * spread may override it. Every style key is then an expression.\n * - `style.<key>`: that key of a style object literal is an expression, a\n * shorthand, or a later spread or computed key may override it.\n *\n * A fact is written only when the file proves it, and exactly where the\n * checked writer refuses (`main/literal-writes.ts` planAttribute and\n * planInlineStyles, `astParentKind` for the slot; pinned cell by cell in\n * `literal-writes.expression-facts.test.ts`). Both read JSX in order:\n * - a spread (or a computed key in a style object) overrides only what comes\n * before it, so an attribute or key before one is a fact and one after it\n * is not;\n * - of repeated occurrences the last renders, so only the last is judged\n * and the writer edits that one.\n * What the file leaves open, such as an attribute absent at a callsite with\n * a spread, gets no token.\n *\n * Works on oxc (ESTree) and Babel JSX trees alike.\n */\n\nimport {\n readLiteralExpression,\n unwrapLiteralExpression,\n literalPropertyName,\n} from \"./literal-expression\";\nexport {\n readLiteralExpression,\n unwrapLiteralExpression,\n literalJsxChild,\n literalPropertyName,\n} from \"./literal-expression\";\n\nexport const EXPRESSION_FACTS_ATTRIBUTE = \"data-tempo-expr\";\nexport const DYNAMIC_SLOT_FACT = \"#slot\";\n\ntype Node = { type: string; [key: string]: unknown };\n\n/**\n * The stamp for one element, or undefined when there is nothing to write.\n * An element with a spread attribute always gets a stamp, empty when it has\n * no fact: annotations land after every spread, so its own value replaces\n * one a caller's props would otherwise carry onto it.\n */\nexport function expressionFacts(\n element: unknown,\n parentType: string | null,\n isStaticJsxChild = false,\n): string | undefined {\n const opening = (element as { openingElement: { attributes: Node[] } })\n .openingElement;\n const attributes = opening.attributes;\n const facts: string[] = [];\n if (\n !isStaticJsxChild &&\n parentType !== \"JSXElement\" &&\n parentType !== \"JSXFragment\"\n )\n facts.push(DYNAMIC_SLOT_FACT);\n\n // The writer reads an attribute's last occurrence, so only that one counts.\n const last = new Map<string, number>();\n attributes.forEach((attribute, index) => {\n const name = attributeName(attribute);\n if (name !== null) last.set(name, index);\n });\n let lastSpread = -1;\n attributes.forEach((attribute, index) => {\n if (attribute.type === \"JSXSpreadAttribute\") lastSpread = index;\n });\n for (const [name, index] of last) {\n if (unstamped(name)) continue;\n const overridden = index < lastSpread;\n const value = attributes[index]!.value as Node | null;\n // A bare attribute is `true`, not an expression.\n if (value === null) continue;\n if (name === \"style\" && !overridden) {\n facts.push(...styleFacts(value));\n continue;\n }\n if (overridden) facts.push(name);\n else if (name === \"className\" && isClassHelperCall(value)) continue;\n else if (!isLiteralValue(value)) facts.push(name);\n }\n\n if (facts.length > 0) return facts.join(\" \");\n return lastSpread >= 0 ? \"\" : undefined;\n}\n\n/** The facts one stamp holds, the inverse of `expressionFacts`. No stamp\n * holds none. */\nexport function stampedFacts(stamp: string | undefined): ReadonlySet<string> {\n return new Set((stamp ?? \"\").split(\" \").filter(Boolean));\n}\n\nfunction attributeName(attribute: Node): string | null {\n if (attribute.type !== \"JSXAttribute\") return null;\n const name = attribute.name as Node;\n if (name.type === \"JSXIdentifier\") return name.name as string;\n if (name.type === \"JSXNamespacedName\") {\n const namespace = (name.namespace as Node).name as string;\n return `${namespace}:${(name.name as Node).name as string}`;\n }\n return null;\n}\n\n/** Props the stamp leaves out: Tempo's own annotations, and `key`, which\n * the canvas reads from the layer. A handler, `ref` or `children` is\n * stamped although no canvas edit writes it: it renders no DOM attribute,\n * so this is where the canvas learns that an element is not plain rich\n * text (review2 r2 R3-A: un-bold of `<b onClick={f}>` deleted the handler). */\nfunction unstamped(name: string): boolean {\n return name === \"key\" || name.startsWith(\"data-tempo-\");\n}\n\nfunction styleFacts(value: Node): string[] {\n const expression =\n value.type === \"JSXExpressionContainer\"\n ? unwrap(value.expression as Node)\n : value;\n if (expression.type !== \"ObjectExpression\") return [\"style\"];\n const properties = expression.properties as Node[];\n const last = new Map<string, number>();\n properties.forEach((property, index) => {\n const key = styleKey(property);\n if (key !== null) last.set(key, index);\n });\n const facts: string[] = [];\n for (const [key, index] of last) {\n const property = properties[index]!;\n const overridden = properties\n .slice(index + 1)\n .some(\n (later) =>\n later.type === \"SpreadElement\" ||\n (later.computed && styleKey(later) === null),\n );\n const literal =\n property.type !== \"ObjectMethod\" &&\n !property.shorthand &&\n isLiteral(property.value as Node);\n if (overridden || !literal) facts.push(`style.${key}`);\n }\n return facts;\n}\n\n/** A fixed property name, including a literal written inside brackets. */\nfunction styleKey(property: Node): string | null {\n const isProperty =\n property.type === \"Property\" ||\n property.type === \"ObjectProperty\" ||\n property.type === \"ObjectMethod\";\n if (!isProperty) return null;\n return literalPropertyName(property.key as Node, Boolean(property.computed));\n}\n\n/** An attribute value the writer can rewrite in place: a JSX string, or a\n * container holding one literal. */\nfunction isLiteralValue(value: Node): boolean {\n if (value.type === \"Literal\" || value.type === \"StringLiteral\") return true;\n if (value.type !== \"JSXExpressionContainer\") return false;\n return isLiteral(value.expression as Node);\n}\n\n/** The class-list helpers whose literal arguments are the className. */\nconst CLASS_HELPERS = new Set([\"cn\", \"clsx\", \"twMerge\", \"cx\", \"classNames\"]);\n\n/** `className={cn(\"a\", \"b\")}`: a class helper called with only string\n * literals and templates without `${}`, the call the writer edits argument\n * by argument. The stamp cannot see imports or scope, so it leaves those to\n * the checked writer, which refuses a helper the file does not import. */\nfunction isClassHelperCall(value: Node): boolean {\n if (value.type !== \"JSXExpressionContainer\") return false;\n const call = value.expression as Node;\n if (call.type !== \"CallExpression\") return false;\n const callee = call.callee as Node;\n if (callee.type !== \"Identifier\" || !CLASS_HELPERS.has(callee.name as string))\n return false;\n return (call.arguments as Node[]).every(\n (argument) =>\n ((argument.type === \"Literal\" || argument.type === \"StringLiteral\") &&\n typeof argument.value === \"string\") ||\n (argument.type === \"TemplateLiteral\" &&\n (argument.expressions as unknown[]).length === 0),\n );\n}\n\n/** The writer's scalar literal, including constant templates and type wrappers. */\nfunction isLiteral(node: Node): boolean {\n return readLiteralExpression(node) !== null;\n}\n\nfunction unwrap(node: Node): Node {\n return unwrapLiteralExpression(node);\n}\n"],"mappings":";AA2BO,SAAS,kBAAkB,SAAyB;AACzD,MAAI,OAAO;AACX,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM,IAAI,QAAQ,WAAW,CAAC;A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MAAM;AACzC;AAEA,SAAS,OAAO,MAAkB;AAChC,SAAO,wBAAwB,IAAI;AACrC;","names":[]}
@@ -5,7 +5,7 @@ import { resolve } from "path";
5
5
  // package.json
6
6
  var package_default = {
7
7
  name: "tempo-sdk",
8
- version: "0.0.89",
8
+ version: "0.0.93",
9
9
  publishConfig: {
10
10
  tag: "sdk-v2-latest"
11
11
  },
@@ -339,4 +339,4 @@ export {
339
339
  createTempoHostIdentity,
340
340
  createSdkFileMatcher
341
341
  };
342
- //# sourceMappingURL=chunk-3JR2JRSV.js.map
342
+ //# sourceMappingURL=chunk-N5MWY4H6.js.map