tempo-sdk 0.0.93 → 0.0.99

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 (48) 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 +2 -2
  4. package/dist/canvas/astro.js +3 -3
  5. package/dist/canvas/index.js +36 -7
  6. package/dist/canvas/index.js.map +1 -1
  7. package/dist/canvas/interact-projection.js +4 -4
  8. package/dist/canvas/svelte.js +3 -3
  9. package/dist/canvas/vue.js +3 -3
  10. package/dist/{chunk-Y7EHQREO.js → chunk-27WT3XUG.js} +2 -2
  11. package/dist/{chunk-Y7EHQREO.js.map → chunk-27WT3XUG.js.map} +1 -1
  12. package/dist/{chunk-M7OOVEAR.js → chunk-6HYKKP5N.js} +3 -2
  13. package/dist/{chunk-M7OOVEAR.js.map → chunk-6HYKKP5N.js.map} +1 -1
  14. package/dist/{chunk-N5MWY4H6.js → chunk-CYDF4LYJ.js} +2 -2
  15. package/dist/{chunk-N5MWY4H6.js.map → chunk-CYDF4LYJ.js.map} +1 -1
  16. package/dist/{chunk-XB6GU4CE.js → chunk-I7VF4ZOV.js} +48 -37
  17. package/dist/chunk-I7VF4ZOV.js.map +1 -0
  18. package/dist/{chunk-HNNZM2XM.js → chunk-MIXQVPDH.js} +461 -185
  19. package/dist/chunk-MIXQVPDH.js.map +1 -0
  20. package/dist/{chunk-GHNHPVEI.js → chunk-SGTGDLOX.js} +2 -2
  21. package/dist/{chunk-GHNHPVEI.js.map → chunk-SGTGDLOX.js.map} +1 -1
  22. package/dist/chunk-T364NBR3.js +1440 -0
  23. package/dist/chunk-T364NBR3.js.map +1 -0
  24. package/dist/{chunk-FZVJVL3T.js → chunk-X5DJKVBT.js} +10 -17
  25. package/dist/chunk-X5DJKVBT.js.map +1 -0
  26. package/dist/{chunk-CVUNZBRV.js → chunk-ZT7HJ6YU.js} +3 -3
  27. package/dist/{chunk-3L4RRKC3.js → chunk-ZW26VZHX.js} +42 -3
  28. package/dist/chunk-ZW26VZHX.js.map +1 -0
  29. package/dist/index.js +2 -2
  30. package/dist/nextjs/plugin.cjs +1 -1
  31. package/dist/nextjs/plugin.cjs.map +1 -1
  32. package/dist/nextjs/plugin.js +1 -1
  33. package/dist/nextjs-loader.cjs +1 -1
  34. package/dist/nextjs-loader.cjs.map +1 -1
  35. package/dist/nextjs.cjs +1 -1
  36. package/dist/nextjs.cjs.map +1 -1
  37. package/dist/nextjs.js +1 -1
  38. package/dist/nuxt/runtime/identity.js +1 -1
  39. package/dist/nuxt.js +1 -1
  40. package/dist/vue.js +1 -1
  41. package/package.json +1 -1
  42. package/dist/chunk-3L4RRKC3.js.map +0 -1
  43. package/dist/chunk-FZVJVL3T.js.map +0 -1
  44. package/dist/chunk-HNNZM2XM.js.map +0 -1
  45. package/dist/chunk-LEBVQBDH.js +0 -643
  46. package/dist/chunk-LEBVQBDH.js.map +0 -1
  47. package/dist/chunk-XB6GU4CE.js.map +0 -1
  48. /package/dist/{chunk-CVUNZBRV.js.map → chunk-ZT7HJ6YU.js.map} +0 -0
@@ -11,9 +11,10 @@ import {
11
11
  finishHeadCapture,
12
12
  getHeadTracker,
13
13
  isDisabledStylesheet,
14
+ resolveReference,
14
15
  resolveUrls,
15
16
  shouldIncludeLink
16
- } from "./chunk-XB6GU4CE.js";
17
+ } from "./chunk-I7VF4ZOV.js";
17
18
  import {
18
19
  isTempoInteractFrameName
19
20
  } from "./chunk-65B52AR7.js";
@@ -80,24 +81,27 @@ import {
80
81
  syncProjectionDomIdsToClone,
81
82
  trackAstroSources,
82
83
  underForeignProjectionRoot,
84
+ wantsLegacyInteractSourceCoordinates,
83
85
  watchDom,
84
86
  watchPortal,
85
87
  watchState
86
- } from "./chunk-3L4RRKC3.js";
88
+ } from "./chunk-ZW26VZHX.js";
87
89
  import {
88
90
  captureAttributes,
89
91
  captureWithSupplementalRoots,
90
92
  collectElementStates,
91
93
  countCaptureStyleRead,
92
94
  countIdentityNodeVisited,
95
+ cssSourcesFor,
93
96
  findLowestCommonAncestor,
97
+ observeCssInputs,
94
98
  readCaptureFlushCounters,
95
99
  readCaptureProducerCardinality,
96
100
  registerCaptureRootObserver,
97
101
  registerDocumentCaptureProducer,
98
102
  removeScriptTags,
99
103
  resetCaptureFlushCounters
100
- } from "./chunk-LEBVQBDH.js";
104
+ } from "./chunk-T364NBR3.js";
101
105
 
102
106
  // ../../modules/iframe-projection/combined/projection-repair-paths.ts
103
107
  function isProjectionRepairPaths(value) {
@@ -106,6 +110,66 @@ function isProjectionRepairPaths(value) {
106
110
  );
107
111
  }
108
112
 
113
+ // ../../modules/iframe-projection/html/document-assets.ts
114
+ var observers = /* @__PURE__ */ new WeakMap();
115
+ function observeDocumentAssets(doc, listener) {
116
+ let observer = observers.get(doc);
117
+ if (!observer) {
118
+ const listeners = /* @__PURE__ */ new Set();
119
+ let active = true;
120
+ const notify = (target, kind) => {
121
+ if (active)
122
+ for (const callback of listeners) {
123
+ if (kind) callback(target, kind);
124
+ else callback(target);
125
+ }
126
+ };
127
+ const onResource = (event) => {
128
+ const target = event.target;
129
+ if (target?.localName === "img" || target?.localName === "image")
130
+ notify(target);
131
+ else if (target?.localName === "link" && target.relList.contains("stylesheet"))
132
+ notify(null);
133
+ };
134
+ const onFonts = () => notify(null, "font");
135
+ doc.addEventListener("load", onResource, true);
136
+ doc.addEventListener("error", onResource, true);
137
+ for (const type of ["loading", "loadingdone", "loadingerror"])
138
+ doc.fonts?.addEventListener(type, onFonts);
139
+ const PerformanceObserver = doc.defaultView?.PerformanceObserver;
140
+ const performanceObserver = PerformanceObserver ? new PerformanceObserver((list) => {
141
+ if (list.getEntries().some(
142
+ (entry) => entry.initiatorType === "css"
143
+ ))
144
+ notify(null);
145
+ }) : null;
146
+ performanceObserver?.observe({ type: "resource", buffered: false });
147
+ observer = {
148
+ listeners,
149
+ stop() {
150
+ active = false;
151
+ performanceObserver?.disconnect();
152
+ doc.removeEventListener("load", onResource, true);
153
+ doc.removeEventListener("error", onResource, true);
154
+ for (const type of ["loading", "loadingdone", "loadingerror"])
155
+ doc.fonts?.removeEventListener(type, onFonts);
156
+ }
157
+ };
158
+ observers.set(doc, observer);
159
+ }
160
+ observer.listeners.add(listener);
161
+ let subscribed = true;
162
+ return () => {
163
+ if (!subscribed) return;
164
+ subscribed = false;
165
+ observer.listeners.delete(listener);
166
+ if (observer.listeners.size === 0) {
167
+ observer.stop();
168
+ observers.delete(doc);
169
+ }
170
+ };
171
+ }
172
+
109
173
  // ../../modules/rate-limiter/browser-frame-clock.ts
110
174
  function browserFrameClock() {
111
175
  let next = 0;
@@ -524,7 +588,7 @@ async function processHeadText(input) {
524
588
  const rawCss = measure("joinRules", () => input.rules.join("\n"));
525
589
  const css = measure(
526
590
  "resolveUrls",
527
- () => absolutifyCssReferences(rawCss, input.base)
591
+ () => absolutifyCssReferences(rawCss, input.base, input.rootRelativeOrigin)
528
592
  );
529
593
  const start = input.measure ? performance.now() : 0;
530
594
  const digest = await crypto.subtle.digest(
@@ -540,7 +604,7 @@ async function processHeadText(input) {
540
604
  }
541
605
 
542
606
  // ../../modules/iframe-projection/html/head-worker-source.ts
543
- var HEAD_WORKER_SOURCE = '(function() {\n "use strict";\n function extractStyleSourceEvidence(text) {\n const attributes = {};\n const clone = {\n setAttribute: (key, value) => {\n attributes[key] = value;\n }\n };\n const reference = [\n ...text.matchAll(/\\/\\*[#@]\\s*sourceMappingURL\\s*=\\s*(\\S+?)\\s*\\*\\//g)\n ].slice(-1)[0]?.[1];\n if (!reference || reference.length > 1024 * 1024) return attributes;\n const inline = /^data:application\\/json(?:;charset=[\\w-]+)?(;base64)?,(.*)$/is.exec(\n reference\n );\n if (!inline) {\n try {\n const url = new URL(reference);\n if (/^https?:$/.test(url.protocol))\n clone.setAttribute("data-projection-css-source-map-url", url.href);\n } catch {\n }\n return attributes;\n }\n function compact(raw, depth) {\n if (!raw || typeof raw !== "object" || depth > 16) return null;\n const map = raw;\n if (map.version !== 3) return null;\n const sources = Array.isArray(map.sources) && map.sources.length <= 4096 && map.sources.every((source) => typeof source === "string") ? map.sources : void 0;\n const sections = Array.isArray(map.sections) && map.sections.length <= 256 ? map.sections.flatMap((section) => {\n const nested = section && typeof section === "object" ? compact(section.map, depth + 1) : null;\n return nested ? [{ map: nested }] : [];\n }) : void 0;\n return {\n version: 3,\n ...typeof map.file === "string" ? { file: map.file } : {},\n ...typeof map.sourceRoot === "string" ? { sourceRoot: map.sourceRoot } : {},\n ...sources ? { sources } : {},\n ...sections ? { sections } : {}\n };\n }\n try {\n const json = inline[1] ? new TextDecoder().decode(\n Uint8Array.from(\n atob(inline[2]),\n (character) => character.charCodeAt(0)\n )\n ) : decodeURIComponent(inline[2]);\n const metadata = compact(JSON.parse(json), 0);\n if (!metadata) return attributes;\n const serialized = JSON.stringify(metadata);\n if (serialized.length <= 64 * 1024)\n clone.setAttribute("data-projection-css-source-map", serialized);\n } catch {\n }\n return attributes;\n }\n function absolutifyCssReferences(cssText, baseHref) {\n const resolve = (value) => {\n const trimmed = value.trim();\n if (!trimmed || trimmed.startsWith("#") || /^(?:data|blob|javascript):/i.test(trimmed)) {\n return /^javascript:/i.test(trimmed) ? "" : trimmed;\n }\n try {\n return new URL(trimmed, baseHref).href;\n } catch {\n return trimmed;\n }\n };\n return cssText.replace(\n /url\\(\\s*(["\']?)([^"\')]+)\\1\\s*\\)/gi,\n (_match, quote, value) => `url(${quote}${resolve(value)}${quote})`\n ).replace(\n /@import\\s+(["\'])([^"\']+)\\1/gi,\n (_match, quote, value) => `@import ${quote}${resolve(value)}${quote}`\n );\n }\n async function processHeadText(input) {\n const stages = {};\n const measure = (name, work) => {\n if (!input.measure) return work();\n const start2 = performance.now();\n const value = work();\n stages[name] = performance.now() - start2;\n return value;\n };\n const metadata = input.metadata ?? measure(\n "sourceMetadata",\n () => extractStyleSourceEvidence(input.authored ?? "")\n );\n const rawCss = measure("joinRules", () => input.rules.join("\\n"));\n const css = measure(\n "resolveUrls",\n () => absolutifyCssReferences(rawCss, input.base)\n );\n const start = input.measure ? performance.now() : 0;\n const digest = await crypto.subtle.digest(\n "SHA-256",\n new TextEncoder().encode(css)\n );\n const hash = Array.from(\n new Uint8Array(digest),\n (byte) => byte.toString(16).padStart(2, "0")\n ).join("");\n if (input.measure) stages.resourceHash = performance.now() - start;\n return { css, hash, metadata, stages };\n }\n const scope = globalThis;\n scope.onmessage = async ({ data }) => {\n try {\n scope.postMessage({ id: data.id, result: await processHeadText(data) });\n } catch (error) {\n scope.postMessage({ id: data.id, error: String(error) });\n }\n };\n})();\n';
607
+ var HEAD_WORKER_SOURCE = '(function() {\n "use strict";\n function extractStyleSourceEvidence(text) {\n const attributes = {};\n const clone = {\n setAttribute: (key, value) => {\n attributes[key] = value;\n }\n };\n const reference = [\n ...text.matchAll(/\\/\\*[#@]\\s*sourceMappingURL\\s*=\\s*(\\S+?)\\s*\\*\\//g)\n ].slice(-1)[0]?.[1];\n if (!reference || reference.length > 1024 * 1024) return attributes;\n const inline = /^data:application\\/json(?:;charset=[\\w-]+)?(;base64)?,(.*)$/is.exec(\n reference\n );\n if (!inline) {\n try {\n const url = new URL(reference);\n if (/^https?:$/.test(url.protocol))\n clone.setAttribute("data-projection-css-source-map-url", url.href);\n } catch {\n }\n return attributes;\n }\n function compact(raw, depth) {\n if (!raw || typeof raw !== "object" || depth > 16) return null;\n const map = raw;\n if (map.version !== 3) return null;\n const sources = Array.isArray(map.sources) && map.sources.length <= 4096 && map.sources.every((source) => typeof source === "string") ? map.sources : void 0;\n const sections = Array.isArray(map.sections) && map.sections.length <= 256 ? map.sections.flatMap((section) => {\n const nested = section && typeof section === "object" ? compact(section.map, depth + 1) : null;\n return nested ? [{ map: nested }] : [];\n }) : void 0;\n return {\n version: 3,\n ...typeof map.file === "string" ? { file: map.file } : {},\n ...typeof map.sourceRoot === "string" ? { sourceRoot: map.sourceRoot } : {},\n ...sources ? { sources } : {},\n ...sections ? { sections } : {}\n };\n }\n try {\n const json = inline[1] ? new TextDecoder().decode(\n Uint8Array.from(\n atob(inline[2]),\n (character) => character.charCodeAt(0)\n )\n ) : decodeURIComponent(inline[2]);\n const metadata = compact(JSON.parse(json), 0);\n if (!metadata) return attributes;\n const serialized = JSON.stringify(metadata);\n if (serialized.length <= 64 * 1024)\n clone.setAttribute("data-projection-css-source-map", serialized);\n } catch {\n }\n return attributes;\n }\n function resolveReference(value, baseHref, rootRelativeOrigin) {\n const url = new URL(value, baseHref);\n const sameOrigin = rootRelativeOrigin !== void 0 && rootRelativeOrigin !== "null" && url.origin === rootRelativeOrigin;\n return sameOrigin ? url.pathname + url.search + url.hash : url.href;\n }\n function absolutifyCssReferences(cssText, baseHref, rootRelativeOrigin) {\n const resolve = (value) => {\n const trimmed = value.trim();\n if (!trimmed || trimmed.startsWith("#") || /^(?:data|blob|javascript):/i.test(trimmed)) {\n return /^javascript:/i.test(trimmed) ? "" : trimmed;\n }\n try {\n return resolveReference(trimmed, baseHref, rootRelativeOrigin);\n } catch {\n return trimmed;\n }\n };\n return cssText.replace(\n /url\\(\\s*(["\']?)([^"\')]+)\\1\\s*\\)/gi,\n (_match, quote, value) => `url(${quote}${resolve(value)}${quote})`\n ).replace(\n /@import\\s+(["\'])([^"\']+)\\1/gi,\n (_match, quote, value) => `@import ${quote}${resolve(value)}${quote}`\n );\n }\n async function processHeadText(input) {\n const stages = {};\n const measure = (name, work) => {\n if (!input.measure) return work();\n const start2 = performance.now();\n const value = work();\n stages[name] = performance.now() - start2;\n return value;\n };\n const metadata = input.metadata ?? measure(\n "sourceMetadata",\n () => extractStyleSourceEvidence(input.authored ?? "")\n );\n const rawCss = measure("joinRules", () => input.rules.join("\\n"));\n const css = measure(\n "resolveUrls",\n () => absolutifyCssReferences(rawCss, input.base, input.rootRelativeOrigin)\n );\n const start = input.measure ? performance.now() : 0;\n const digest = await crypto.subtle.digest(\n "SHA-256",\n new TextEncoder().encode(css)\n );\n const hash = Array.from(\n new Uint8Array(digest),\n (byte) => byte.toString(16).padStart(2, "0")\n ).join("");\n if (input.measure) stages.resourceHash = performance.now() - start;\n return { css, hash, metadata, stages };\n }\n const scope = globalThis;\n scope.onmessage = async ({ data }) => {\n try {\n scope.postMessage({ id: data.id, result: await processHeadText(data) });\n } catch (error) {\n scope.postMessage({ id: data.id, error: String(error) });\n }\n };\n})();\n';
544
608
 
545
609
  // ../../modules/iframe-projection/html/head-worker.ts
546
610
  var WORKER_TIMEOUT_MS = 3e4;
@@ -626,14 +690,21 @@ function createHeadWorker() {
626
690
 
627
691
  // ../../modules/iframe-projection/html/prepared-head.ts
628
692
  var documents = /* @__PURE__ */ new WeakMap();
629
- function createPreparedHead(doc, clock) {
630
- let shared = documents.get(doc);
693
+ function createPreparedHead(doc, clock, options = {}) {
694
+ const mode = options.rootRelativeOrigin ?? "";
695
+ let modes = documents.get(doc);
696
+ if (!modes) documents.set(doc, modes = /* @__PURE__ */ new Map());
697
+ let shared = modes.get(mode);
631
698
  if (!shared) {
632
- shared = { head: buildPreparedHead(doc, clock), owners: 0 };
633
- documents.set(doc, shared);
699
+ shared = {
700
+ head: buildPreparedHead(doc, clock, options.rootRelativeOrigin),
701
+ owners: 0
702
+ };
703
+ modes.set(mode, shared);
634
704
  }
635
705
  shared.owners++;
636
706
  const owner = shared;
707
+ const ownerModes = modes;
637
708
  let disposed = false;
638
709
  return {
639
710
  ...owner.head,
@@ -642,14 +713,16 @@ function createPreparedHead(doc, clock) {
642
713
  disposed = true;
643
714
  if (--owner.owners === 0) {
644
715
  owner.head.dispose();
645
- documents.delete(doc);
716
+ ownerModes.delete(mode);
717
+ if (ownerModes.size === 0) documents.delete(doc);
646
718
  }
647
719
  }
648
720
  };
649
721
  }
650
- function buildPreparedHead(doc, clock) {
722
+ function buildPreparedHead(doc, clock, origin) {
651
723
  const work = createWorkScheduler({ clock });
652
724
  const worker = createHeadWorker();
725
+ const cssSources = cssSourcesFor(doc);
653
726
  const abort = new AbortController();
654
727
  const cache = /* @__PURE__ */ new Map();
655
728
  const versions = /* @__PURE__ */ new Map();
@@ -735,7 +808,8 @@ function buildPreparedHead(doc, clock) {
735
808
  for (let offset = 0; offset < list.length; ) {
736
809
  const start = timing ? performance.now() : 0;
737
810
  const end = Math.min(offset + 32, list.length);
738
- for (; offset < end; offset++) rules.push(list[offset].cssText);
811
+ for (; offset < end; offset++)
812
+ rules.push(cssSources.ruleText(list[offset]));
739
813
  if (timing) {
740
814
  const elapsed = performance.now() - start;
741
815
  timing.report.stages.readCssRules = (timing.report.stages.readCssRules ?? 0) + elapsed;
@@ -756,13 +830,14 @@ function buildPreparedHead(doc, clock) {
756
830
  ...Array.from(doc.head?.children ?? []).filter((node) => {
757
831
  if (node.tagName === "LINK")
758
832
  return shouldIncludeLink(node) && !isDisabledStylesheet(node);
833
+ if (node.tagName === "STYLE") return !isDisabledStylesheet(node);
759
834
  if (node.tagName === "META") {
760
835
  const name = node.getAttribute("name")?.toLowerCase();
761
836
  return node.getAttribute("http-equiv")?.toLowerCase() !== "content-security-policy" && name !== "content-security-policy" && name !== "theme-color";
762
837
  }
763
- return node.tagName === "STYLE" || node.tagName === "BASE";
838
+ return node.tagName === "BASE";
764
839
  }),
765
- ...adopted
840
+ ...adopted.filter((sheet) => !sheet.disabled)
766
841
  ];
767
842
  const next = [];
768
843
  for (const source of sources) {
@@ -783,7 +858,7 @@ function buildPreparedHead(doc, clock) {
783
858
  let prepared;
784
859
  if (kind === "META" || kind === "BASE") {
785
860
  const node = source.cloneNode(true);
786
- resolveUrls(node, base);
861
+ resolveUrls(node, base, origin);
787
862
  prepared = { node, rules: 0 };
788
863
  } else {
789
864
  const queued = timing ? performance.now() : 0;
@@ -795,7 +870,7 @@ function buildPreparedHead(doc, clock) {
795
870
  let node = input.node;
796
871
  if (input.rules === null) {
797
872
  node.removeAttribute("crossorigin");
798
- resolveUrls(node, base);
873
+ resolveUrls(node, base, origin);
799
874
  prepared = { node, rules: 0 };
800
875
  } else {
801
876
  if (kind === "LINK") {
@@ -824,6 +899,7 @@ function buildPreparedHead(doc, clock) {
824
899
  rules: input.rules,
825
900
  authored: authored && authored.length <= 5 * 1024 * 1024 ? authored : "",
826
901
  base: input.cssBase,
902
+ rootRelativeOrigin: origin,
827
903
  metadata: previous?.authored === authored ? previous?.value : void 0,
828
904
  measure: !!timing
829
905
  });
@@ -841,7 +917,7 @@ function buildPreparedHead(doc, clock) {
841
917
  node.setAttribute(key, value);
842
918
  if ("tagName" in source && authored !== void 0)
843
919
  metadata.set(source, { authored, value: text.metadata });
844
- resolveUrls(node, base);
920
+ resolveUrls(node, base, origin);
845
921
  prepared = { node, text, rules: input.count };
846
922
  if (sheetTiming?.sheet) {
847
923
  sheetTiming.sheet.rules = input.count;
@@ -957,66 +1033,6 @@ function buildPreparedHead(doc, clock) {
957
1033
  };
958
1034
  }
959
1035
 
960
- // ../../modules/iframe-projection/html/document-assets.ts
961
- var observers = /* @__PURE__ */ new WeakMap();
962
- function observeDocumentAssets(doc, listener) {
963
- let observer = observers.get(doc);
964
- if (!observer) {
965
- const listeners = /* @__PURE__ */ new Set();
966
- let active = true;
967
- const notify = (target, kind) => {
968
- if (active)
969
- for (const callback of listeners) {
970
- if (kind) callback(target, kind);
971
- else callback(target);
972
- }
973
- };
974
- const onResource = (event) => {
975
- const target = event.target;
976
- if (target?.localName === "img" || target?.localName === "image")
977
- notify(target);
978
- else if (target?.localName === "link" && target.relList.contains("stylesheet"))
979
- notify(null);
980
- };
981
- const onFonts = () => notify(null, "font");
982
- doc.addEventListener("load", onResource, true);
983
- doc.addEventListener("error", onResource, true);
984
- for (const type of ["loading", "loadingdone", "loadingerror"])
985
- doc.fonts?.addEventListener(type, onFonts);
986
- const PerformanceObserver = doc.defaultView?.PerformanceObserver;
987
- const performanceObserver = PerformanceObserver ? new PerformanceObserver((list) => {
988
- if (list.getEntries().some(
989
- (entry) => entry.initiatorType === "css"
990
- ))
991
- notify(null);
992
- }) : null;
993
- performanceObserver?.observe({ type: "resource", buffered: false });
994
- observer = {
995
- listeners,
996
- stop() {
997
- active = false;
998
- performanceObserver?.disconnect();
999
- doc.removeEventListener("load", onResource, true);
1000
- doc.removeEventListener("error", onResource, true);
1001
- for (const type of ["loading", "loadingdone", "loadingerror"])
1002
- doc.fonts?.removeEventListener(type, onFonts);
1003
- }
1004
- };
1005
- observers.set(doc, observer);
1006
- }
1007
- observer.listeners.add(listener);
1008
- let subscribed = true;
1009
- return () => {
1010
- if (!subscribed) return;
1011
- subscribed = false;
1012
- observer.listeners.delete(listener);
1013
- if (observer.listeners.size === 0) {
1014
- observer.stop();
1015
- observers.delete(doc);
1016
- }
1017
- };
1018
- }
1019
-
1020
1036
  // ../../modules/iframe-projection/combined/projection-capture-perf.ts
1021
1037
  function buildProjectionCapturePerf(input) {
1022
1038
  const flushCounters = readCaptureFlushCounters();
@@ -1071,8 +1087,17 @@ function buildProjectionCapturePerf(input) {
1071
1087
  };
1072
1088
  }
1073
1089
 
1090
+ // ../../modules/iframe-projection/root-color.ts
1091
+ var PROJECTION_ROOT_COLOR_ATTR = "data-tempo-root-color";
1092
+ function captureProjectionRootColor(documentElement) {
1093
+ const color = documentElement.ownerDocument.defaultView?.getComputedStyle(documentElement).color.trim();
1094
+ return color ? { [PROJECTION_ROOT_COLOR_ATTR]: color } : {};
1095
+ }
1096
+
1074
1097
  // ../../modules/iframe-projection/html/root-coordinates.ts
1075
1098
  var ROOT_COORDINATES_ATTRIBUTE = "data-projection-root-coordinates";
1099
+
1100
+ // ../../modules/iframe-projection/combined/legacy-source-coordinates.ts
1076
1101
  function changesFixedCoordinates(css) {
1077
1102
  const active = (value) => Boolean(value && value !== "none");
1078
1103
  return active(css.transform) || active(css.translate) || active(css.rotate) || active(css.scale) || active(css.perspective) || active(css.filter) || active(css.backdropFilter) || /layout|paint|strict|content/.test(css.contain) || /transform|perspective|filter/.test(css.willChange);
@@ -1115,12 +1140,111 @@ function captureRootCoordinates(root, portals = []) {
1115
1140
  ...layout
1116
1141
  };
1117
1142
  }
1118
-
1119
- // ../../modules/iframe-projection/root-color.ts
1120
- var PROJECTION_ROOT_COLOR_ATTR = "data-tempo-root-color";
1121
- function captureProjectionRootColor(documentElement) {
1122
- const color = documentElement.ownerDocument.defaultView?.getComputedStyle(documentElement).color.trim();
1123
- return color ? { [PROJECTION_ROOT_COLOR_ATTR]: color } : {};
1143
+ function createLegacySourceCoordinateTracker(options) {
1144
+ const sentPortalCoordinates = /* @__PURE__ */ new Map();
1145
+ let stopped = false;
1146
+ let sentCoordinates;
1147
+ const hasCoordinateFrame = () => sentCoordinates !== void 0;
1148
+ const ancestorsOf = (element) => {
1149
+ const chain = [];
1150
+ for (let ancestor = element.parentElement; ancestor; ancestor = ancestor.parentElement) {
1151
+ chain.push(ancestor);
1152
+ }
1153
+ return chain;
1154
+ };
1155
+ const sameChain = (chain, other) => chain.length === other.length && chain.every((element, index) => element === other[index]);
1156
+ let observedAncestors = [];
1157
+ const frameWatcher = new MutationObserver((records) => {
1158
+ if (stopped) return;
1159
+ let reparented = false;
1160
+ if (records.some((record) => record.type === "childList")) {
1161
+ const chain = ancestorsOf(options.root);
1162
+ reparented = !sameChain(chain, observedAncestors);
1163
+ if (reparented) observeAncestors(chain);
1164
+ }
1165
+ const restyled = records.some((record) => record.type === "attributes");
1166
+ if (!reparented && !restyled) return;
1167
+ if (!options.hasPortals() && !hasCoordinateFrame()) return;
1168
+ options.onChange();
1169
+ });
1170
+ function observeAncestors(chain) {
1171
+ frameWatcher.disconnect();
1172
+ observedAncestors = chain;
1173
+ for (const ancestor of chain) {
1174
+ frameWatcher.observe(ancestor, {
1175
+ attributes: true,
1176
+ attributeFilter: ["style", "class"],
1177
+ childList: true
1178
+ });
1179
+ }
1180
+ }
1181
+ observeAncestors(ancestorsOf(options.root));
1182
+ const view = options.root.ownerDocument.defaultView;
1183
+ const invalidateCoordinates = () => {
1184
+ if (!stopped && (hasCoordinateFrame() || options.hasPortals()))
1185
+ options.onChange();
1186
+ };
1187
+ const onScroll = (event) => {
1188
+ const target = event.target;
1189
+ if (target?.contains?.(options.root)) invalidateCoordinates();
1190
+ };
1191
+ view?.addEventListener("resize", invalidateCoordinates);
1192
+ view?.addEventListener("scroll", onScroll, true);
1193
+ return {
1194
+ hasCoordinateFrame,
1195
+ rememberCoordinates(coordinates) {
1196
+ sentCoordinates = coordinates ? JSON.stringify(coordinates) : void 0;
1197
+ },
1198
+ portalSent(portal, patch) {
1199
+ if (patch.kind === "replace" && patch.coordinateSpace) {
1200
+ sentPortalCoordinates.set(
1201
+ portal,
1202
+ JSON.stringify(patch.coordinateSpace)
1203
+ );
1204
+ }
1205
+ },
1206
+ portalRemoved(portal) {
1207
+ sentPortalCoordinates.delete(portal);
1208
+ },
1209
+ portalRefreshes(livePortals, resent) {
1210
+ const patches = [];
1211
+ for (const portal of livePortals) {
1212
+ if (resent.has(portal)) continue;
1213
+ const coordinates = captureProjectionPortalCoordinates(
1214
+ options.root,
1215
+ portal
1216
+ );
1217
+ if (!coordinates) continue;
1218
+ const measured = JSON.stringify(coordinates.coordinateSpace);
1219
+ if (sentPortalCoordinates.get(portal) === measured) continue;
1220
+ sentPortalCoordinates.set(portal, measured);
1221
+ patches.push(coordinates);
1222
+ }
1223
+ return patches;
1224
+ },
1225
+ rootPatch(livePortals) {
1226
+ const coordinates = captureRootCoordinates(options.root, livePortals);
1227
+ const measuredCoordinates = coordinates ? JSON.stringify(coordinates) : void 0;
1228
+ const coordinatesChanged = measuredCoordinates !== sentCoordinates;
1229
+ sentCoordinates = measuredCoordinates;
1230
+ if (!coordinatesChanged) return null;
1231
+ return {
1232
+ kind: "attributes",
1233
+ targetId: PROJECTION_ROOT_TARGET_ID,
1234
+ attributes: {
1235
+ [ROOT_COORDINATES_ATTRIBUTE]: measuredCoordinates ?? null
1236
+ }
1237
+ };
1238
+ },
1239
+ stop() {
1240
+ if (stopped) return;
1241
+ stopped = true;
1242
+ frameWatcher.disconnect();
1243
+ view?.removeEventListener("resize", invalidateCoordinates);
1244
+ view?.removeEventListener("scroll", onScroll, true);
1245
+ sentPortalCoordinates.clear();
1246
+ }
1247
+ };
1124
1248
  }
1125
1249
 
1126
1250
  // ../../modules/iframe-projection/combined/projection-full-snapshot.ts
@@ -1130,7 +1254,9 @@ function captureProjectionFullSnapshot(options) {
1130
1254
  const { dom, hostDomIdCount } = captureFullDom(
1131
1255
  options.root,
1132
1256
  options.portals ?? [],
1133
- observedFiles
1257
+ observedFiles,
1258
+ void 0,
1259
+ options.legacySourceCoordinates === true
1134
1260
  );
1135
1261
  const pointerEventsNone = [];
1136
1262
  for (const element of projectedElements(options.root)) {
@@ -1162,7 +1288,7 @@ function captureProjectionFullSnapshot(options) {
1162
1288
  function captureFullDom(root, portals, observedFiles, identity = {
1163
1289
  readId: (element) => ensureProjectionDomId(element),
1164
1290
  syncClone: syncProjectionDomIdsToClone
1165
- }) {
1291
+ }, legacySourceCoordinates = false) {
1166
1292
  for (const scope of [root, ...portals]) {
1167
1293
  for (const element of projectedElements(scope)) {
1168
1294
  identity.readId(element);
@@ -1188,7 +1314,7 @@ function captureFullDom(root, portals, observedFiles, identity = {
1188
1314
  )) {
1189
1315
  hostDomIds.add(domId);
1190
1316
  }
1191
- const coordinateSpace = capturePortalCoordinateSpace(root, portal);
1317
+ const coordinateSpace = legacySourceCoordinates ? capturePortalCoordinateSpace(root, portal) : void 0;
1192
1318
  portalPatches.push({
1193
1319
  kind: "replace",
1194
1320
  portalId,
@@ -1198,7 +1324,7 @@ function captureFullDom(root, portals, observedFiles, identity = {
1198
1324
  }
1199
1325
  const body = root.ownerDocument.body;
1200
1326
  const rootDomId = identity.readId(root);
1201
- const coordinates = captureRootCoordinates(root, portals);
1327
+ const coordinates = legacySourceCoordinates ? captureRootCoordinates(root, portals) : void 0;
1202
1328
  const dom = {
1203
1329
  ...coordinates ? { coordinates } : {},
1204
1330
  html: removeScriptTags(clone.innerHTML),
@@ -4374,55 +4500,12 @@ function createProjectionRootAccumulator(options) {
4374
4500
  const portals = /* @__PURE__ */ new Map();
4375
4501
  const dirtyPortals = /* @__PURE__ */ new Set();
4376
4502
  const removedPortals = /* @__PURE__ */ new Map();
4377
- const sentPortalCoordinates = /* @__PURE__ */ new Map();
4378
4503
  let stopped = false;
4379
- let sentCoordinates;
4380
- const hasCoordinateFrame = () => sentCoordinates !== void 0;
4381
- const ancestorsOf = (element) => {
4382
- const chain = [];
4383
- for (let ancestor = element.parentElement; ancestor; ancestor = ancestor.parentElement) {
4384
- chain.push(ancestor);
4385
- }
4386
- return chain;
4387
- };
4388
- const sameChain = (chain, other) => chain.length === other.length && chain.every((element, index) => element === other[index]);
4389
- let observedAncestors = [];
4390
- const frameWatcher = new MutationObserver((records) => {
4391
- if (stopped) return;
4392
- let reparented = false;
4393
- if (records.some((record) => record.type === "childList")) {
4394
- const chain = ancestorsOf(options.root);
4395
- reparented = !sameChain(chain, observedAncestors);
4396
- if (reparented) observeAncestors(chain);
4397
- }
4398
- const restyled = records.some((record) => record.type === "attributes");
4399
- if (!reparented && !restyled) return;
4400
- if (portals.size === 0 && !hasCoordinateFrame()) return;
4401
- options.onChange("portal-coordinate-change");
4402
- });
4403
- function observeAncestors(chain) {
4404
- frameWatcher.disconnect();
4405
- observedAncestors = chain;
4406
- for (const ancestor of chain) {
4407
- frameWatcher.observe(ancestor, {
4408
- attributes: true,
4409
- attributeFilter: ["style", "class"],
4410
- childList: true
4411
- });
4412
- }
4413
- }
4414
- observeAncestors(ancestorsOf(options.root));
4415
- const view = options.root.ownerDocument.defaultView;
4416
- const invalidateCoordinates = () => {
4417
- if (!stopped && (hasCoordinateFrame() || portals.size > 0))
4418
- options.onChange("portal-coordinate-change");
4419
- };
4420
- const onScroll = (event) => {
4421
- const target = event.target;
4422
- if (target?.contains?.(options.root)) invalidateCoordinates();
4423
- };
4424
- view?.addEventListener("resize", invalidateCoordinates);
4425
- view?.addEventListener("scroll", onScroll, true);
4504
+ const legacyCoordinates = options.legacySourceCoordinates ? createLegacySourceCoordinateTracker({
4505
+ root: options.root,
4506
+ hasPortals: () => portals.size > 0,
4507
+ onChange: () => options.onChange("portal-coordinate-change")
4508
+ }) : null;
4426
4509
  const registerPortals = options.registerPortals ?? ((registration) => getPortalTracker().register({
4427
4510
  element: options.root,
4428
4511
  ...registration
@@ -4447,7 +4530,7 @@ function createProjectionRootAccumulator(options) {
4447
4530
  });
4448
4531
  dirtyPortals.delete(portal);
4449
4532
  portals.delete(portal);
4450
- sentPortalCoordinates.delete(portal);
4533
+ legacyCoordinates?.portalRemoved(portal);
4451
4534
  handle.stop();
4452
4535
  options.onChange("portal-mutation");
4453
4536
  }
@@ -4457,9 +4540,9 @@ function createProjectionRootAccumulator(options) {
4457
4540
  if (stopped) return 0;
4458
4541
  return dom.takePendingRecords();
4459
4542
  },
4460
- hasCoordinateFrame,
4543
+ hasCoordinateFrame: () => legacyCoordinates?.hasCoordinateFrame() ?? false,
4461
4544
  rememberCoordinates(coordinates) {
4462
- sentCoordinates = coordinates ? JSON.stringify(coordinates) : void 0;
4545
+ legacyCoordinates?.rememberCoordinates(coordinates);
4463
4546
  },
4464
4547
  hasPortals() {
4465
4548
  return !stopped && portals.size > 0;
@@ -4525,16 +4608,11 @@ function createProjectionRootAccumulator(options) {
4525
4608
  const captured = captureProjectionPortalRegion(
4526
4609
  portal,
4527
4610
  false,
4528
- options.root
4611
+ legacyCoordinates ? options.root : void 0
4529
4612
  );
4530
4613
  if (!captured) continue;
4531
4614
  resentPortals.add(portal);
4532
- if (captured.portal.kind === "replace" && captured.portal.coordinateSpace) {
4533
- sentPortalCoordinates.set(
4534
- portal,
4535
- JSON.stringify(captured.portal.coordinateSpace)
4536
- );
4537
- }
4615
+ legacyCoordinates?.portalSent(portal, captured.portal);
4538
4616
  portalPatches.push(captured.portal);
4539
4617
  observedFiles.merge(captured.observedFiles);
4540
4618
  layerObservedFiles.merge(captured.observedFiles);
@@ -4549,18 +4627,10 @@ function createProjectionRootAccumulator(options) {
4549
4627
  }
4550
4628
  }
4551
4629
  dirtyPortals.clear();
4552
- for (const portal of portals.keys()) {
4553
- if (resentPortals.has(portal)) continue;
4554
- const coordinates2 = captureProjectionPortalCoordinates(
4555
- options.root,
4556
- portal
4630
+ if (legacyCoordinates)
4631
+ portalPatches.push(
4632
+ ...legacyCoordinates.portalRefreshes(portals.keys(), resentPortals)
4557
4633
  );
4558
- if (!coordinates2) continue;
4559
- const measured = JSON.stringify(coordinates2.coordinateSpace);
4560
- if (sentPortalCoordinates.get(portal) === measured) continue;
4561
- sentPortalCoordinates.set(portal, measured);
4562
- portalPatches.push(coordinates2);
4563
- }
4564
4634
  const observedSnapshot = observedFiles.snapshot();
4565
4635
  for (const snapshot of metadata)
4566
4636
  layerObservedFiles.addLayerProps(snapshot.props);
@@ -4569,19 +4639,9 @@ function createProjectionRootAccumulator(options) {
4569
4639
  ...metadata.length > 0 ? { metadata } : {},
4570
4640
  ...Object.keys(layerObservedSnapshot).length > 0 ? { observedFiles: layerObservedSnapshot } : {}
4571
4641
  };
4572
- const coordinates = captureRootCoordinates(options.root, portals.keys());
4573
- const measuredCoordinates = coordinates ? JSON.stringify(coordinates) : void 0;
4574
- const coordinatesChanged = measuredCoordinates !== sentCoordinates;
4575
- sentCoordinates = measuredCoordinates;
4576
4642
  const domPatches = [...mutationPatch.dom];
4577
- if (coordinatesChanged)
4578
- domPatches.push({
4579
- kind: "attributes",
4580
- targetId: PROJECTION_ROOT_TARGET_ID,
4581
- attributes: {
4582
- [ROOT_COORDINATES_ATTRIBUTE]: measuredCoordinates ?? null
4583
- }
4584
- });
4643
+ const rootCoordinatesPatch = legacyCoordinates?.rootPatch(portals.keys());
4644
+ if (rootCoordinatesPatch) domPatches.push(rootCoordinatesPatch);
4585
4645
  const patch = {
4586
4646
  ...Object.keys(layers).length > 0 ? { layers } : {},
4587
4647
  ...domPatches.length > 0 ? { dom: domPatches } : {},
@@ -4617,16 +4677,13 @@ function createProjectionRootAccumulator(options) {
4617
4677
  if (stopped) return;
4618
4678
  stopped = true;
4619
4679
  unregisterPortals();
4620
- frameWatcher.disconnect();
4621
- view?.removeEventListener("resize", invalidateCoordinates);
4622
- view?.removeEventListener("scroll", onScroll, true);
4680
+ legacyCoordinates?.stop();
4623
4681
  dom.stop();
4624
4682
  state.stop();
4625
4683
  for (const portal of portals.values()) portal.stop();
4626
4684
  portals.clear();
4627
4685
  dirtyPortals.clear();
4628
4686
  removedPortals.clear();
4629
- sentPortalCoordinates.clear();
4630
4687
  }
4631
4688
  };
4632
4689
  }
@@ -4655,7 +4712,9 @@ function collectDomLayerTargets(root, mutations) {
4655
4712
  var MODULE_EVALUATED_GRACE_MS = 3e3;
4656
4713
  function createCombinedDocumentProducer(options) {
4657
4714
  const reactHook = initHook();
4658
- const preparedHead = options.prepareHead ? createPreparedHead(options.document, options.headWorkClock) : void 0;
4715
+ const preparedHead = options.prepareHead ? createPreparedHead(options.document, options.headWorkClock, {
4716
+ rootRelativeOrigin: options.rootRelativeOrigin
4717
+ }) : void 0;
4659
4718
  const roots = /* @__PURE__ */ new Map();
4660
4719
  const captureStats = /* @__PURE__ */ new WeakMap();
4661
4720
  let stopped = false;
@@ -4945,10 +5004,15 @@ function createCombinedDocumentProducer(options) {
4945
5004
  root: runtime.options.element,
4946
5005
  fiberTarget,
4947
5006
  portals: accumulator.portalElements(),
4948
- layerAdapter: runtime.layerAdapter
5007
+ layerAdapter: runtime.layerAdapter,
5008
+ legacySourceCoordinates: options.legacySourceCoordinates === true
4949
5009
  });
4950
- const { snapshot } = captured;
4951
- accumulator.rememberCoordinates(snapshot.dom.coordinates);
5010
+ accumulator.rememberCoordinates(captured.snapshot.dom.coordinates);
5011
+ const snapshot = options.rootRelativeOrigin === void 0 ? captured.snapshot : rootRelativeSnapshot(
5012
+ captured.snapshot,
5013
+ runtime.options.element,
5014
+ options.rootRelativeOrigin
5015
+ );
4952
5016
  const documentContext = JSON.stringify([
4953
5017
  snapshot.dom.documentElementAttributes,
4954
5018
  snapshot.dom.bodyAttributes,
@@ -5141,7 +5205,7 @@ function createCombinedDocumentProducer(options) {
5141
5205
  }
5142
5206
  const observedSnapshot = observedFiles.snapshot();
5143
5207
  const layerObservedSnapshot = layerObservedFiles.snapshot();
5144
- const patch = {
5208
+ let patch = {
5145
5209
  ...basePatch,
5146
5210
  ...adapterLayerPatch ? { layers: adapterLayerPatch } : regions.snapshots.length > 0 || metadata.length > 0 ? {
5147
5211
  layers: {
@@ -5169,6 +5233,14 @@ function createCombinedDocumentProducer(options) {
5169
5233
  layers: { ...patch.layers, observedFiles: layerObservedSnapshot }
5170
5234
  });
5171
5235
  }
5236
+ if (options.rootRelativeOrigin !== void 0) {
5237
+ patch = rootRelativePatch(
5238
+ patch,
5239
+ runtime.options.element,
5240
+ accumulator.portalElements(),
5241
+ options.rootRelativeOrigin
5242
+ );
5243
+ }
5172
5244
  const absentFiles = captureAbsentFiles(runtime, observedSnapshot, false);
5173
5245
  if (absentFiles) Object.assign(patch, { absentFiles });
5174
5246
  if (Object.keys(patch).length === 0) {
@@ -5199,7 +5271,9 @@ function createCombinedDocumentProducer(options) {
5199
5271
  captureHead(flushContext) {
5200
5272
  if (flushContext.candidateRootCount === 0) resetCaptureFlushCounters();
5201
5273
  const startedAt = Date.now();
5202
- const head = preparedHead ? preparedHead.capture(options.styleResource) : captureHead(options.document, options.styleResource);
5274
+ const head = preparedHead ? preparedHead.capture(options.styleResource) : captureHead(options.document, options.styleResource, {
5275
+ rootRelativeOrigin: options.rootRelativeOrigin
5276
+ });
5203
5277
  headSnapshotMs = Date.now() - startedAt;
5204
5278
  headPerfContext = flushContext;
5205
5279
  return head;
@@ -5263,6 +5337,7 @@ function createCombinedDocumentProducer(options) {
5263
5337
  try {
5264
5338
  const accumulator = createProjectionRootAccumulator({
5265
5339
  root: runtime.options.element,
5340
+ legacySourceCoordinates: options.legacySourceCoordinates === true,
5266
5341
  onChange(trigger) {
5267
5342
  if (!runtime.options.element.isConnected) {
5268
5343
  makeRootDormant(runtime);
@@ -5581,11 +5656,22 @@ function createCombinedDocumentProducer(options) {
5581
5656
  if (!runtime || runtime.dormant || !runtime.options.element.isConnected) {
5582
5657
  return null;
5583
5658
  }
5584
- return captureProjectionRegion(
5659
+ const portals = runtime.accumulator?.portalElements() ?? [];
5660
+ const capture = captureProjectionRegion(
5585
5661
  runtime.options.element,
5586
5662
  targetId,
5587
- runtime.accumulator?.portalElements() ?? []
5663
+ portals
5588
5664
  );
5665
+ if (!capture || options.rootRelativeOrigin === void 0) return capture;
5666
+ return {
5667
+ ...capture,
5668
+ html: rootRelativeBodyHtml(
5669
+ capture.html,
5670
+ options.document,
5671
+ options.rootRelativeOrigin,
5672
+ resolveRegionElement(runtime.options.element, targetId, portals)
5673
+ )
5674
+ };
5589
5675
  },
5590
5676
  stop() {
5591
5677
  if (stopped) return;
@@ -6075,6 +6161,177 @@ function aggregateBatchPerf(roots, head, context, capturedHeadMs, rootsPerBatch,
6075
6161
  sourceViewportSamples
6076
6162
  };
6077
6163
  }
6164
+ function rootRelativeSnapshot(snapshot, root, origin) {
6165
+ const { baseUrl: _, ...dom } = snapshot.dom;
6166
+ const rewriteAttributes = (attributes, element) => Object.fromEntries(
6167
+ Object.entries(attributes).map(([name, value]) => [
6168
+ name,
6169
+ rootRelativeBodyAttribute(element, name, value, origin)
6170
+ ])
6171
+ );
6172
+ return {
6173
+ ...snapshot,
6174
+ dom: {
6175
+ ...dom,
6176
+ html: rootRelativeBodyHtml(dom.html, root.ownerDocument, origin, root),
6177
+ documentElementAttributes: rewriteAttributes(
6178
+ dom.documentElementAttributes,
6179
+ root.ownerDocument.documentElement
6180
+ ),
6181
+ ...dom.bodyAttributes && root.ownerDocument.body ? {
6182
+ bodyAttributes: rewriteAttributes(
6183
+ dom.bodyAttributes,
6184
+ root.ownerDocument.body
6185
+ )
6186
+ } : {},
6187
+ ...dom.rootAttributes ? { rootAttributes: rewriteAttributes(dom.rootAttributes, root) } : {},
6188
+ portals: dom.portals.map(
6189
+ (portal) => portal.kind === "replace" ? {
6190
+ ...portal,
6191
+ html: rootRelativeBodyHtml(
6192
+ portal.html,
6193
+ root.ownerDocument,
6194
+ origin
6195
+ )
6196
+ } : portal
6197
+ )
6198
+ }
6199
+ };
6200
+ }
6201
+ function rootRelativePatch(patch, root, portals, origin) {
6202
+ const resolve = (id) => resolveRegionElement(root, id, portals);
6203
+ return {
6204
+ ...patch,
6205
+ ...patch.dom ? {
6206
+ dom: patch.dom.map((change) => {
6207
+ if (change.kind === "remove") return change;
6208
+ const element = resolve(change.targetId);
6209
+ if (change.kind === "attributes") {
6210
+ if (!element) return change;
6211
+ return {
6212
+ ...change,
6213
+ attributes: Object.fromEntries(
6214
+ Object.entries(change.attributes).map(([name, value]) => [
6215
+ name,
6216
+ value === null ? null : rootRelativeBodyAttribute(element, name, value, origin)
6217
+ ])
6218
+ )
6219
+ };
6220
+ }
6221
+ return {
6222
+ ...change,
6223
+ html: rootRelativeBodyHtml(
6224
+ change.html,
6225
+ root.ownerDocument,
6226
+ origin,
6227
+ change.kind === "children" ? element : resolve(change.parentId)
6228
+ )
6229
+ };
6230
+ })
6231
+ } : {},
6232
+ ...patch.portals ? {
6233
+ portals: patch.portals.map(
6234
+ (portal) => portal.kind === "replace" ? {
6235
+ ...portal,
6236
+ html: rootRelativeBodyHtml(
6237
+ portal.html,
6238
+ root.ownerDocument,
6239
+ origin
6240
+ )
6241
+ } : portal
6242
+ )
6243
+ } : {},
6244
+ ...patch.layers?.metadata ? {
6245
+ layers: {
6246
+ ...patch.layers,
6247
+ metadata: patch.layers.metadata.map((entry) => {
6248
+ const parent = entry.ancestorIds?.[0];
6249
+ if (entry.content === void 0 || !parent || resolve(parent)?.localName !== "style")
6250
+ return entry;
6251
+ return {
6252
+ ...entry,
6253
+ content: rootRelativeBodyCss(entry.content, origin)
6254
+ };
6255
+ })
6256
+ }
6257
+ } : {}
6258
+ };
6259
+ }
6260
+ function rootRelativeBodyHtml(html, doc, origin, context) {
6261
+ if (context?.localName === "style") return rootRelativeBodyCss(html, origin);
6262
+ if (!html.includes(origin.replace(/^[a-z]+:/i, ""))) return html;
6263
+ const template = doc.createElement("template");
6264
+ const svgContext = context?.namespaceURI === "http://www.w3.org/2000/svg";
6265
+ const container = svgContext ? template.content.ownerDocument.createElementNS(
6266
+ context.namespaceURI,
6267
+ context.localName
6268
+ ) : template;
6269
+ container.innerHTML = html;
6270
+ const content = container === template ? template.content : container;
6271
+ let changed = false;
6272
+ for (const element of content.querySelectorAll("*")) {
6273
+ for (const attribute of [...element.attributes]) {
6274
+ const value = rootRelativeBodyAttribute(
6275
+ element,
6276
+ attribute.name,
6277
+ attribute.value,
6278
+ origin
6279
+ );
6280
+ if (value === attribute.value) continue;
6281
+ attribute.value = value;
6282
+ changed = true;
6283
+ }
6284
+ if (element.localName !== "style") continue;
6285
+ const css = element.textContent ?? "";
6286
+ const rewritten = rootRelativeBodyCss(css, origin);
6287
+ if (rewritten === css) continue;
6288
+ element.textContent = rewritten;
6289
+ changed = true;
6290
+ }
6291
+ return changed ? container.innerHTML : html;
6292
+ }
6293
+ function rootRelativeBodyAttribute(element, name, value, origin) {
6294
+ if (name === "style") return rootRelativeBodyCss(value, origin);
6295
+ if (name === "srcset") {
6296
+ let cursor = 0;
6297
+ let copied = 0;
6298
+ let rewritten = "";
6299
+ while (cursor < value.length) {
6300
+ while (cursor < value.length && /[\s,]/.test(value[cursor])) cursor++;
6301
+ const start = cursor;
6302
+ while (cursor < value.length && !/\s/.test(value[cursor])) cursor++;
6303
+ const token = value.slice(start, cursor);
6304
+ const url = token.replace(/,+$/, "");
6305
+ rewritten += value.slice(copied, start) + rootRelativeBodyUrl(url, origin);
6306
+ copied = start + url.length;
6307
+ if (token.endsWith(",")) continue;
6308
+ while (cursor < value.length && value[cursor] !== ",") cursor++;
6309
+ }
6310
+ return rewritten + value.slice(copied);
6311
+ }
6312
+ const svgResource = element.namespaceURI === "http://www.w3.org/2000/svg" && element.localName !== "a";
6313
+ const stylesheet = element.localName === "link" && /(?:^|\s)stylesheet(?:\s|$)/i.test(element.getAttribute("rel") ?? "");
6314
+ const resourceAttribute = name === "src" || name === "poster" || (name === "href" || name === "xlink:href") && (svgResource || stylesheet);
6315
+ return resourceAttribute ? rootRelativeBodyUrl(value, origin) : value;
6316
+ }
6317
+ function rootRelativeBodyCss(css, origin) {
6318
+ return css.replace(
6319
+ /url\(\s*(["']?)([^"')]+)\1\s*\)/gi,
6320
+ (match, _quote, value) => {
6321
+ const rewritten = rootRelativeBodyUrl(value, origin);
6322
+ return rewritten === value ? match : match.replace(value, rewritten);
6323
+ }
6324
+ );
6325
+ }
6326
+ function rootRelativeBodyUrl(value, origin) {
6327
+ if (!/^(?:https?:)?\/\//i.test(value.trim())) return value;
6328
+ try {
6329
+ const resolved = resolveReference(value, origin, origin);
6330
+ return resolved.startsWith("/") ? resolved : value;
6331
+ } catch {
6332
+ return value;
6333
+ }
6334
+ }
6078
6335
 
6079
6336
  // ../../modules/iframe-projection/combined/layer-framework.ts
6080
6337
  var LAYER_FRAMEWORKS = [
@@ -6644,6 +6901,9 @@ function watchCombined(element, onChange, options = {}) {
6644
6901
  const producer = createCombinedDocumentProducer({
6645
6902
  document: element.ownerDocument,
6646
6903
  flushWindowMs: options.debounceDelay ?? LEGACY_FLUSH_WINDOW_MS,
6904
+ // Only clients older than canvas protocol 3 send this command, and they
6905
+ // rebase the envelope's portals from the coordinate refreshes it drives.
6906
+ legacySourceCoordinates: true,
6647
6907
  emit(batch) {
6648
6908
  if (stopped) return;
6649
6909
  if (paused) {
@@ -6892,6 +7152,7 @@ function createProjectionSourceController(options) {
6892
7152
  }
6893
7153
  producer ?? (producer = createCombinedDocumentProducer({
6894
7154
  document: options.document,
7155
+ legacySourceCoordinates: options.legacySourceCoordinates === true,
6895
7156
  emit: publishBatch,
6896
7157
  onError: (error) => sendError(error)
6897
7158
  }));
@@ -7121,7 +7382,12 @@ function createProjectionSourceController(options) {
7121
7382
  }
7122
7383
  function startCombinedSourceInterface(options = {}) {
7123
7384
  if (typeof document !== "undefined") trackAstroSources(document);
7124
- const { targetOrigin = "*", serialize, hideFiberProp } = options;
7385
+ const {
7386
+ targetOrigin = "*",
7387
+ serialize,
7388
+ hideFiberProp,
7389
+ legacySourceCoordinates = false
7390
+ } = options;
7125
7391
  if (combinedSourceInitialized) {
7126
7392
  console.warn("[combined-postmessage:source] Already initialized");
7127
7393
  return combinedSourceCleanup || (() => {
@@ -7147,13 +7413,18 @@ function startCombinedSourceInterface(options = {}) {
7147
7413
  };
7148
7414
  combinedSourceCleanup = cleanup;
7149
7415
  const deferredInstall = installWhenDocumentBodyReady(
7150
- () => initCombinedSourceInterface(targetOrigin, serialize, hideFiberProp)
7416
+ () => initCombinedSourceInterface(
7417
+ targetOrigin,
7418
+ serialize,
7419
+ hideFiberProp,
7420
+ legacySourceCoordinates
7421
+ )
7151
7422
  );
7152
7423
  if (disposed) deferredInstall();
7153
7424
  else disposeDeferredInstall = deferredInstall;
7154
7425
  return cleanup;
7155
7426
  }
7156
- function initCombinedSourceInterface(targetOrigin, serialize, hideFiberProp) {
7427
+ function initCombinedSourceInterface(targetOrigin, serialize, hideFiberProp, legacySourceCoordinates = false) {
7157
7428
  window.__IFRAME_PROJECTION_COMBINED_INTERFACE_ACTIVE__ = true;
7158
7429
  const send = (msg) => {
7159
7430
  if ("batch" in msg && msg.batch instanceof ArrayBuffer) {
@@ -7171,6 +7442,7 @@ function initCombinedSourceInterface(targetOrigin, serialize, hideFiberProp) {
7171
7442
  watcherIdPrefix: "iframe-projection-watcher",
7172
7443
  serialize,
7173
7444
  hideFiberProp,
7445
+ legacySourceCoordinates,
7174
7446
  send(type, payload) {
7175
7447
  if (type === "error") {
7176
7448
  send({
@@ -8317,9 +8589,13 @@ function installTempoInteractProjectionSource() {
8317
8589
  delete hook[PENDING_ROOTS_KEY];
8318
8590
  }
8319
8591
  const disposeCanvasFrames = installTempoInteractCanvasFrameLane();
8320
- const disposeProjection = startCombinedSourceInterface();
8592
+ const stopCssInputs = observeCssInputs(document);
8593
+ const disposeProjection = startCombinedSourceInterface({
8594
+ legacySourceCoordinates: wantsLegacyInteractSourceCoordinates()
8595
+ });
8321
8596
  return () => {
8322
8597
  disposeProjection();
8598
+ stopCssInputs();
8323
8599
  disposeCanvasFrames();
8324
8600
  };
8325
8601
  }
@@ -8327,4 +8603,4 @@ function installTempoInteractProjectionSource() {
8327
8603
  export {
8328
8604
  installTempoInteractProjectionSource
8329
8605
  };
8330
- //# sourceMappingURL=chunk-HNNZM2XM.js.map
8606
+ //# sourceMappingURL=chunk-MIXQVPDH.js.map