tempo-sdk 0.0.52 → 0.0.60

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 (75) hide show
  1. package/dist/assets/index.js +4 -2
  2. package/dist/assets/index.js.map +1 -1
  3. package/dist/canvas/editor.d.ts +11 -16
  4. package/dist/canvas/editor.js +79 -49
  5. package/dist/canvas/editor.js.map +1 -1
  6. package/dist/canvas/index.d.ts +13 -7
  7. package/dist/canvas/index.js +227 -64
  8. package/dist/canvas/index.js.map +1 -1
  9. package/dist/canvas/interact-projection.js +4 -3
  10. package/dist/canvas/parser.d.ts +10 -5
  11. package/dist/canvas/parser.js +3 -1
  12. package/dist/canvas/svelte.d.ts +8 -5
  13. package/dist/canvas/svelte.js +20 -5
  14. package/dist/canvas/svelte.js.map +1 -1
  15. package/dist/chunk-2IQD2KPS.js +219 -0
  16. package/dist/chunk-2IQD2KPS.js.map +1 -0
  17. package/dist/chunk-5BHIHP25.js +410 -0
  18. package/dist/chunk-5BHIHP25.js.map +1 -0
  19. package/dist/{chunk-PULSTDX2.js → chunk-7DT5DDSH.js} +284 -46
  20. package/dist/chunk-7DT5DDSH.js.map +1 -0
  21. package/dist/{chunk-7Y7XNHUM.js → chunk-FQSZRVSL.js} +18 -3
  22. package/dist/chunk-FQSZRVSL.js.map +1 -0
  23. package/dist/{chunk-ZZYNOX24.js → chunk-MXKZZOLM.js} +1717 -2460
  24. package/dist/chunk-MXKZZOLM.js.map +1 -0
  25. package/dist/{chunk-DX6XAXCK.js → chunk-N2TYN3RB.js} +189 -420
  26. package/dist/chunk-N2TYN3RB.js.map +1 -0
  27. package/dist/chunk-OTVBSF7U.js +1585 -0
  28. package/dist/chunk-OTVBSF7U.js.map +1 -0
  29. package/dist/chunk-TL4MGN7E.js +2570 -0
  30. package/dist/chunk-TL4MGN7E.js.map +1 -0
  31. package/dist/{chunk-QP2NTODB.js → chunk-VMTQDG4U.js} +117 -27
  32. package/dist/chunk-VMTQDG4U.js.map +1 -0
  33. package/dist/expo/plugin.cjs +1256 -16
  34. package/dist/expo/plugin.cjs.map +1 -1
  35. package/dist/expo/plugin.d.cts +0 -1
  36. package/dist/expo/plugin.d.ts +0 -1
  37. package/dist/expo/plugin.js +1 -1
  38. package/dist/expo-babel-plugin.cjs +1258 -16
  39. package/dist/expo-babel-plugin.cjs.map +1 -1
  40. package/dist/expo-babel-plugin.d.cts +8 -5
  41. package/dist/expo-babel-plugin.d.ts +8 -5
  42. package/dist/expo-babel-plugin.js +1 -1
  43. package/dist/index.d.ts +5 -1
  44. package/dist/index.js +647 -166
  45. package/dist/index.js.map +1 -1
  46. package/dist/nextjs/plugin.cjs +151 -0
  47. package/dist/nextjs/plugin.cjs.map +1 -1
  48. package/dist/nextjs/plugin.d.cts +1 -1
  49. package/dist/nextjs/plugin.d.ts +1 -1
  50. package/dist/nextjs/plugin.js +1 -1
  51. package/dist/nextjs-loader.cjs +1432 -35
  52. package/dist/nextjs-loader.cjs.map +1 -1
  53. package/dist/nextjs.cjs +17 -2
  54. package/dist/nextjs.cjs.map +1 -1
  55. package/dist/nextjs.d.cts +14 -3
  56. package/dist/nextjs.d.ts +14 -3
  57. package/dist/nextjs.js +1 -1
  58. package/dist/{page-xi1aI5a7.d.ts → page-DwLnOM5d.d.ts} +12 -6
  59. package/dist/{storyboard-DbtzTPvI.d.ts → storyboard-DjOF61B_.d.ts} +35 -15
  60. package/dist/svelte.d.ts +3 -2
  61. package/dist/svelte.js +103 -29
  62. package/dist/svelte.js.map +1 -1
  63. package/dist/v1-client-compat-qxaXEDm_.d.ts +23 -0
  64. package/package.json +5 -2
  65. package/dist/chunk-57KAYXHF.js +0 -19
  66. package/dist/chunk-57KAYXHF.js.map +0 -1
  67. package/dist/chunk-7Y7XNHUM.js.map +0 -1
  68. package/dist/chunk-CB5NJJJT.js +0 -345
  69. package/dist/chunk-CB5NJJJT.js.map +0 -1
  70. package/dist/chunk-DX6XAXCK.js.map +0 -1
  71. package/dist/chunk-F3KJDCMU.js +0 -19
  72. package/dist/chunk-F3KJDCMU.js.map +0 -1
  73. package/dist/chunk-PULSTDX2.js.map +0 -1
  74. package/dist/chunk-QP2NTODB.js.map +0 -1
  75. package/dist/chunk-ZZYNOX24.js.map +0 -1
@@ -1,323 +1,75 @@
1
- // ../../modules/iframe-projection/html/watch-head.ts
2
- var INCLUDE_TAGS = /* @__PURE__ */ new Set(["STYLE", "META", "BASE", "LINK"]);
3
- var INCLUDE_LINK_RELS = /* @__PURE__ */ new Set(["stylesheet"]);
4
- var instance = null;
5
- function getHeadTracker() {
6
- if (!instance) {
7
- instance = new HeadTrackerImpl();
8
- }
9
- return instance;
10
- }
11
- var HeadSubscriptionImpl = class {
12
- constructor(doc, callback, onUnsubscribe) {
13
- this.hasMutations = false;
14
- this.doc = doc;
15
- this.callback = callback;
16
- this.onUnsubscribe = onUnsubscribe;
17
- }
18
- flush(isInitial) {
19
- if (!isInitial && !this.hasMutations) {
20
- return void 0;
21
- }
22
- this.hasMutations = false;
23
- return captureHead(this.doc);
24
- }
25
- unsubscribe() {
26
- this.onUnsubscribe();
27
- }
28
- /** Called by tracker when relevant mutation detected */
29
- notifyMutation(details) {
30
- this.hasMutations = true;
31
- this.callback(details);
32
- }
33
- };
34
- var HeadTrackerImpl = class {
35
- constructor() {
36
- this.docObservers = /* @__PURE__ */ new Map();
37
- this.activeSubscriptions = 0;
38
- }
39
- subscribe(doc, onMutation) {
40
- let docState = this.docObservers.get(doc);
41
- if (!docState) {
42
- docState = this.createDocObserver(doc);
43
- this.docObservers.set(doc, docState);
44
- }
45
- const subscription = new HeadSubscriptionImpl(doc, onMutation, () => {
46
- this.unsubscribe(doc, subscription);
47
- });
48
- docState.subscriptions.add(subscription);
49
- this.activeSubscriptions += 1;
50
- return subscription;
51
- }
52
- createDocObserver(doc) {
53
- const subscriptions = /* @__PURE__ */ new Set();
54
- const notify = (details) => {
55
- for (const sub of subscriptions) {
56
- sub.notifyMutation(details);
57
- }
58
- };
59
- const observeHead = (head) => {
60
- const observer = new MutationObserver((mutations) => {
61
- const details = this.readRelevantMutations(mutations, head);
62
- if (!details) return;
63
- notify(details);
64
- });
65
- observer.observe(head, {
66
- childList: true,
67
- subtree: true,
68
- attributes: true,
69
- characterData: true
70
- });
71
- return observer;
72
- };
73
- if (doc.head) {
74
- return { observer: observeHead(doc.head), subscriptions };
75
- }
76
- const bootstrap = new MutationObserver(() => {
77
- const head = doc.head;
78
- if (!head) return;
79
- bootstrap.disconnect();
80
- state.observer = observeHead(head);
81
- notify({ stylesheetPaths: [] });
82
- });
83
- bootstrap.observe(doc, { childList: true, subtree: true });
84
- const state = { observer: bootstrap, subscriptions };
85
- return state;
86
- }
87
- unsubscribe(doc, sub) {
88
- const docState = this.docObservers.get(doc);
89
- if (!docState) return;
90
- if (!docState.subscriptions.delete(sub)) return;
91
- this.activeSubscriptions = Math.max(0, this.activeSubscriptions - 1);
92
- if (docState.subscriptions.size === 0) {
93
- docState.observer.disconnect();
94
- this.docObservers.delete(doc);
95
- }
96
- }
97
- /**
98
- * Check if mutations contain changes to elements we care about.
99
- * This filtering runs once per mutation batch (not once per subscription).
100
- */
101
- readRelevantMutations(mutations, head) {
102
- let relevant = false;
103
- const stylesheetPaths = /* @__PURE__ */ new Set();
104
- const collectStylesheetPath = (node) => {
105
- const element = node instanceof Element ? node : node?.parentElement ?? null;
106
- if (!element) return;
107
- const candidates = [
108
- element,
109
- ...element.querySelectorAll(
110
- "style[data-vite-dev-id], link[rel~='stylesheet']"
111
- )
112
- ];
113
- for (const candidate of candidates) {
114
- if (candidate instanceof HTMLStyleElement) {
115
- const id = candidate.getAttribute("data-vite-dev-id")?.trim();
116
- if (id) stylesheetPaths.add(id);
117
- } else if (candidate instanceof HTMLLinkElement && shouldIncludeLink(candidate)) {
118
- const href = candidate.getAttribute("href")?.trim() || candidate.href;
119
- if (href) stylesheetPaths.add(href);
120
- }
121
- }
122
- };
123
- for (const mutation of mutations) {
124
- const target = mutation.target;
125
- const element = target instanceof Element ? target : target.parentElement;
126
- if (!element || !head.contains(element) && target !== head) continue;
127
- const tagName = element.tagName;
128
- if (INCLUDE_TAGS.has(tagName)) {
129
- if (tagName === "LINK") {
130
- if (!shouldIncludeLink(element)) continue;
131
- }
132
- relevant = true;
133
- collectStylesheetPath(element);
134
- }
135
- if (mutation.type === "childList" && target === head) {
136
- relevant = true;
137
- }
138
- if (mutation.type === "childList") {
139
- for (const node of mutation.addedNodes) collectStylesheetPath(node);
140
- for (const node of mutation.removedNodes) collectStylesheetPath(node);
141
- }
142
- }
143
- return relevant ? { stylesheetPaths: [...stylesheetPaths] } : null;
144
- }
145
- destroy() {
146
- for (const docState of this.docObservers.values()) {
147
- docState.observer.disconnect();
148
- docState.subscriptions.clear();
149
- }
150
- this.docObservers.clear();
151
- this.activeSubscriptions = 0;
152
- }
153
- readPerfSnapshot() {
154
- return {
155
- observers: this.docObservers.size,
156
- subscriptions: this.activeSubscriptions
157
- };
1
+ // ../../modules/iframe-projection/html/selectors.ts
2
+ function generateSelector(element, root) {
3
+ if (!root) {
4
+ if (element === document.documentElement) return ":root";
5
+ if (element === document.head) return "head";
6
+ if (element === document.body) return "body";
158
7
  }
159
- };
160
- function captureHead(doc) {
161
- const head = doc.head;
162
- if (!head) return "";
163
- const baseURI = doc.baseURI;
164
- const fragments = [];
165
- for (const child of Array.from(head.children)) {
166
- const tagName = child.tagName;
167
- if (!INCLUDE_TAGS.has(tagName)) continue;
168
- if (tagName === "LINK") {
169
- if (!shouldIncludeLink(child)) continue;
170
- if (isDisabledStylesheet(child)) continue;
171
- }
172
- if (tagName === "META") {
173
- const httpEquiv = child.getAttribute("http-equiv")?.toLowerCase();
174
- const name = child.getAttribute("name")?.toLowerCase();
175
- if (httpEquiv === "content-security-policy" || name === "content-security-policy") {
176
- continue;
177
- }
178
- }
179
- let clone = child.cloneNode(true);
180
- materializeStyleElementCssom(child, clone);
181
- if (tagName === "LINK") {
182
- clone = materializeStylesheetLinkCssom(child, clone);
183
- }
184
- resolveUrls(clone, baseURI);
185
- if (clone.tagName === "LINK") {
186
- clone.removeAttribute("crossorigin");
187
- } else if (clone.tagName === "STYLE") {
188
- escapeStyleForHtmlSerialization(clone);
8
+ if (root && element === root) return "";
9
+ const parts = [];
10
+ let current = element;
11
+ const stopAt = root ?? document.documentElement;
12
+ while (current && current !== stopAt) {
13
+ const parent = current.parentElement;
14
+ if (!parent) break;
15
+ const tagName = current.tagName.toLowerCase();
16
+ let index = 1;
17
+ let sibling = current.previousElementSibling;
18
+ while (sibling) {
19
+ if (sibling.tagName === current.tagName) index++;
20
+ sibling = sibling.previousElementSibling;
189
21
  }
190
- fragments.push(clone.outerHTML);
191
- }
192
- fragments.push(...captureAdoptedStyleSheets(doc));
193
- return fragments.join("\n");
194
- }
195
- function materializeStylesheetLinkCssom(source, clone) {
196
- const link = source;
197
- const cssText = serializeCssRules(link.sheet);
198
- if (!cssText) {
199
- return clone;
200
- }
201
- const style = source.ownerDocument.createElement("style");
202
- for (const attribute of Array.from(source.attributes)) {
203
- if ([
204
- "as",
205
- "crossorigin",
206
- "fetchpriority",
207
- "href",
208
- "integrity",
209
- "referrerpolicy",
210
- "rel"
211
- ].includes(attribute.name.toLowerCase())) {
212
- continue;
22
+ let sameTypeSiblings = 0;
23
+ for (const child of parent.children) {
24
+ if (child.tagName === current.tagName) sameTypeSiblings++;
213
25
  }
214
- style.setAttribute(attribute.name, attribute.value);
215
- }
216
- style.setAttribute("data-projection-stylesheet-href", link.href);
217
- style.textContent = absolutifyCssReferences(cssText, link.href);
218
- return style;
219
- }
220
- function materializeStyleElementCssom(source, clone) {
221
- if (source.tagName !== "STYLE" || clone.tagName !== "STYLE") {
222
- return;
223
- }
224
- const style = source;
225
- const text = style.textContent ?? "";
226
- if (text.trim().length > 0) {
227
- return;
228
- }
229
- const cssText = serializeCssRules(style.sheet);
230
- if (cssText) {
231
- clone.textContent = cssText;
232
- }
233
- }
234
- function captureAdoptedStyleSheets(doc) {
235
- const sheets = Array.from(doc.adoptedStyleSheets ?? []);
236
- if (sheets.length === 0) {
237
- return [];
238
- }
239
- const fragments = [];
240
- for (const sheet of sheets) {
241
- const cssText = serializeCssRules(sheet);
242
- if (!cssText) {
243
- continue;
26
+ if (sameTypeSiblings > 1) {
27
+ parts.unshift(`${tagName}:nth-of-type(${index})`);
28
+ } else {
29
+ parts.unshift(tagName);
244
30
  }
245
- const style = doc.createElement("style");
246
- style.setAttribute("data-projection-adopted-stylesheet", "true");
247
- style.textContent = cssText;
248
- escapeStyleForHtmlSerialization(style);
249
- fragments.push(style.outerHTML);
250
- }
251
- return fragments;
252
- }
253
- function escapeStyleForHtmlSerialization(style) {
254
- style.textContent = (style.textContent ?? "").replace(/<\//gi, "<\\/");
255
- }
256
- function serializeCssRules(sheet) {
257
- if (!sheet) {
258
- return "";
31
+ current = parent;
259
32
  }
260
- try {
261
- return Array.from(sheet.cssRules).map((rule) => rule.cssText).join("\n");
262
- } catch {
33
+ if (parts.length === 0) {
34
+ if (element === document.body) return "body";
35
+ if (element === document.head) return "head";
263
36
  return "";
264
37
  }
38
+ const path = parts.join(" > ");
39
+ if (root) return `:scope > ${path}`;
40
+ return path;
265
41
  }
266
- function absolutifyCssReferences(cssText, baseHref) {
267
- if (!/^https?:/i.test(baseHref)) {
268
- return cssText;
269
- }
270
- const resolve = (value) => {
271
- const trimmed = value.trim();
272
- if (!trimmed || trimmed.startsWith("#") || /^(?:data|blob|javascript):/i.test(trimmed)) {
273
- return /^javascript:/i.test(trimmed) ? "" : trimmed;
42
+ function findLowestCommonAncestor(nodes) {
43
+ if (nodes.size === 0) return null;
44
+ const ancestorChains = [];
45
+ for (const node of nodes) {
46
+ const chain = [];
47
+ let current = node instanceof Element ? node : node.parentElement;
48
+ while (current && current !== document) {
49
+ if (current instanceof Element) {
50
+ chain.unshift(current);
51
+ }
52
+ current = current.parentNode;
274
53
  }
275
- try {
276
- return new URL(trimmed, baseHref).href;
277
- } catch {
278
- return trimmed;
54
+ if (chain.length > 0) {
55
+ ancestorChains.push(chain);
279
56
  }
280
- };
281
- return cssText.replace(
282
- /url\(\s*(["']?)([^"')]+)\1\s*\)/gi,
283
- (_match, quote, value) => `url(${quote}${resolve(value)}${quote})`
284
- ).replace(
285
- /@import\s+(["'])([^"']+)\1/gi,
286
- (_match, quote, value) => `@import ${quote}${resolve(value)}${quote}`
287
- );
288
- }
289
- function shouldIncludeLink(element) {
290
- const rel = element.getAttribute("rel");
291
- if (!rel) {
292
- return false;
293
57
  }
294
- return rel.toLowerCase().split(/\s+/).some((token) => INCLUDE_LINK_RELS.has(token));
295
- }
296
- function isDisabledStylesheet(element) {
297
- const link = element;
298
- return link.disabled || link.sheet?.disabled === true;
299
- }
300
- function resolveUrls(element, baseURI) {
301
- if (!baseURI || !baseURI.startsWith("http")) {
302
- return;
303
- }
304
- const href = element.getAttribute("href");
305
- if (href && !isAbsoluteUrl(href)) {
306
- try {
307
- element.setAttribute("href", new URL(href, baseURI).href);
308
- } catch {
309
- }
58
+ if (ancestorChains.length === 0) {
59
+ return document.documentElement;
310
60
  }
311
- const src = element.getAttribute("src");
312
- if (src && !isAbsoluteUrl(src)) {
313
- try {
314
- element.setAttribute("src", new URL(src, baseURI).href);
315
- } catch {
61
+ let lca = document.documentElement;
62
+ const firstChain = ancestorChains[0];
63
+ const minLength = Math.min(...ancestorChains.map((c) => c.length));
64
+ for (let i = 0; i < minLength; i++) {
65
+ const candidate = firstChain[i];
66
+ if (candidate && ancestorChains.every((chain) => chain[i] === candidate)) {
67
+ lca = candidate;
68
+ } else {
69
+ break;
316
70
  }
317
71
  }
318
- }
319
- function isAbsoluteUrl(url) {
320
- return /^(https?:)?\/\//i.test(url) || url.startsWith("data:");
72
+ return lca;
321
73
  }
322
74
 
323
75
  // ../../modules/iframe-projection/shared/capture-perf.ts
@@ -390,49 +142,33 @@ function readCaptureFlushCounters() {
390
142
  }
391
143
 
392
144
  // ../../modules/iframe-projection/html/declared-facts.ts
393
- var SOURCE_ANNOTATED_SELECTOR = "[data-tempo-filepath], [data-tempo-html-filepath]";
394
- var NAMESPACES = [
395
- {
396
- filepathAttr: "data-tempo-filepath",
397
- positionAttr: "data-tempo-position",
398
- modifiedTsAttr: "data-tempo-modifiedts",
399
- sourceVersionAttr: "data-tempo-source-version"
400
- },
401
- {
402
- filepathAttr: "data-tempo-html-filepath",
403
- positionAttr: "data-tempo-html-offset",
404
- modifiedTsAttr: "data-tempo-html-modifiedts",
405
- sourceVersionAttr: "data-tempo-html-source-version"
406
- }
407
- ];
145
+ var SOURCE_ANNOTATED_SELECTOR = "[data-tempo-filepath]";
408
146
  function computeDeclaredFacts(targetElement, captureRoot, scopeSelector, portalElements) {
409
147
  const observedVersions = {};
410
148
  const observedSourceVersions = {};
411
149
  const anchorSet = /* @__PURE__ */ new Set();
412
150
  const visit = (element) => {
413
- for (const ns of NAMESPACES) {
414
- const filepath = element.getAttribute(ns.filepathAttr);
415
- if (filepath == null || filepath.length === 0) continue;
416
- const modifiedTsRaw = element.getAttribute(ns.modifiedTsAttr);
417
- if (modifiedTsRaw != null) {
418
- const modifiedTs = Number(modifiedTsRaw);
419
- if (!Number.isNaN(modifiedTs)) {
420
- const existing = observedVersions[filepath];
421
- if (existing === void 0 || modifiedTs > existing) {
422
- observedVersions[filepath] = modifiedTs;
423
- const version = element.getAttribute(ns.sourceVersionAttr);
424
- if (version != null && version.length > 0) {
425
- observedSourceVersions[filepath] = version;
426
- } else {
427
- delete observedSourceVersions[filepath];
428
- }
151
+ const filepath = element.getAttribute("data-tempo-filepath");
152
+ if (filepath == null || filepath.length === 0) return;
153
+ const modifiedTsRaw = element.getAttribute("data-tempo-modifiedts");
154
+ if (modifiedTsRaw != null) {
155
+ const modifiedTs = Number(modifiedTsRaw);
156
+ if (!Number.isNaN(modifiedTs)) {
157
+ const existing = observedVersions[filepath];
158
+ if (existing === void 0 || modifiedTs > existing) {
159
+ observedVersions[filepath] = modifiedTs;
160
+ const version = element.getAttribute("data-tempo-source-version");
161
+ if (version != null && version.length > 0) {
162
+ observedSourceVersions[filepath] = version;
163
+ } else {
164
+ delete observedSourceVersions[filepath];
429
165
  }
430
166
  }
431
167
  }
432
- const position = element.getAttribute(ns.positionAttr);
433
- if (position != null && position.length > 0) {
434
- anchorSet.add(`${filepath} ${position}`);
435
- }
168
+ }
169
+ const position = element.getAttribute("data-tempo-position");
170
+ if (position != null && position.length > 0) {
171
+ anchorSet.add(`${filepath} ${position}`);
436
172
  }
437
173
  };
438
174
  const walkRoots = [targetElement, ...portalElements];
@@ -590,80 +326,6 @@ function elementHasVisibleComputedVisibility(element, view) {
590
326
  return visibility !== "hidden" && visibility !== "collapse";
591
327
  }
592
328
 
593
- // ../../modules/iframe-projection/html/selectors.ts
594
- function generateSelector(element, root) {
595
- if (!root) {
596
- if (element === document.documentElement) return ":root";
597
- if (element === document.head) return "head";
598
- if (element === document.body) return "body";
599
- }
600
- if (root && element === root) return "";
601
- const parts = [];
602
- let current = element;
603
- const stopAt = root ?? document.documentElement;
604
- while (current && current !== stopAt) {
605
- const parent = current.parentElement;
606
- if (!parent) break;
607
- const tagName = current.tagName.toLowerCase();
608
- let index = 1;
609
- let sibling = current.previousElementSibling;
610
- while (sibling) {
611
- if (sibling.tagName === current.tagName) index++;
612
- sibling = sibling.previousElementSibling;
613
- }
614
- let sameTypeSiblings = 0;
615
- for (const child of parent.children) {
616
- if (child.tagName === current.tagName) sameTypeSiblings++;
617
- }
618
- if (sameTypeSiblings > 1) {
619
- parts.unshift(`${tagName}:nth-of-type(${index})`);
620
- } else {
621
- parts.unshift(tagName);
622
- }
623
- current = parent;
624
- }
625
- if (parts.length === 0) {
626
- if (element === document.body) return "body";
627
- if (element === document.head) return "head";
628
- return "";
629
- }
630
- const path = parts.join(" > ");
631
- if (root) return `:scope > ${path}`;
632
- return path;
633
- }
634
- function findLowestCommonAncestor(nodes) {
635
- if (nodes.size === 0) return null;
636
- const ancestorChains = [];
637
- for (const node of nodes) {
638
- const chain = [];
639
- let current = node instanceof Element ? node : node.parentElement;
640
- while (current && current !== document) {
641
- if (current instanceof Element) {
642
- chain.unshift(current);
643
- }
644
- current = current.parentNode;
645
- }
646
- if (chain.length > 0) {
647
- ancestorChains.push(chain);
648
- }
649
- }
650
- if (ancestorChains.length === 0) {
651
- return document.documentElement;
652
- }
653
- let lca = document.documentElement;
654
- const firstChain = ancestorChains[0];
655
- const minLength = Math.min(...ancestorChains.map((c) => c.length));
656
- for (let i = 0; i < minLength; i++) {
657
- const candidate = firstChain[i];
658
- if (candidate && ancestorChains.every((chain) => chain[i] === candidate)) {
659
- lca = candidate;
660
- } else {
661
- break;
662
- }
663
- }
664
- return lca;
665
- }
666
-
667
329
  // ../../modules/iframe-projection/html/capture.ts
668
330
  function capture(element) {
669
331
  return captureWithSupplementalRoots(element, []);
@@ -806,9 +468,118 @@ function collectElementStates(root, options = {}) {
806
468
  return states;
807
469
  }
808
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 => {
475
+ const doc = scope.document;
476
+ const undo = [];
477
+ let active = true;
478
+ 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 }));
482
+ };
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');
486
+ };
487
+ const css = target => {
488
+ const sheet = target instanceof scope.CSSStyleSheet ? target : target.parentStyleSheet;
489
+ if (target === doc || sheet && (sheet.ownerNode?.isConnected || doc.adoptedStyleSheets.includes(sheet)))
490
+ emit(doc, 'tempo:css-runtime-mutation', { ownerNode: sheet?.ownerNode ?? null });
491
+ };
492
+ const setter = (proto, key, changed) => {
493
+ if (!proto) return;
494
+ const original = Object.getOwnPropertyDescriptor(proto, key);
495
+ if (!original?.set || !original.configurable) return;
496
+ const set = function(value) {
497
+ const before = original.get?.call(this);
498
+ original.set.call(this, value);
499
+ if (key === 'adoptedStyleSheets' || before !== original.get?.call(this)) changed(this);
500
+ };
501
+ Object.defineProperty(proto, key, { ...original, set });
502
+ undo.push(() => {
503
+ if (Object.getOwnPropertyDescriptor(proto, key)?.set === set)
504
+ Object.defineProperty(proto, key, original);
505
+ });
506
+ };
507
+ const method = (proto, key, changed) => {
508
+ if (!proto) return;
509
+ const original = Object.getOwnPropertyDescriptor(proto, key);
510
+ if (typeof original?.value !== 'function' || !original.configurable) return;
511
+ const value = function(...args) {
512
+ const result = original.value.apply(this, args);
513
+ if (result instanceof scope.Promise) result.then(() => changed(this), () => {});
514
+ else changed(this);
515
+ return result;
516
+ };
517
+ Object.defineProperty(proto, key, { ...original, value });
518
+ undo.push(() => {
519
+ if (Object.getOwnPropertyDescriptor(proto, key)?.value === value)
520
+ Object.defineProperty(proto, key, original);
521
+ });
522
+ };
523
+ 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'])
534
+ method(scope.CSSStyleSheet?.prototype, key, css);
535
+ for (const key of ['insertRule', 'deleteRule']) method(scope.CSSGroupingRule?.prototype, key, css);
536
+ 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
+ setter(scope.Document?.prototype, 'adoptedStyleSheets', css);
541
+ setter(scope.StyleSheet?.prototype, 'disabled', css);
542
+ method(scope.HTMLFormElement?.prototype, 'reset', target => {
543
+ for (const element of target.elements) form(element);
544
+ });
545
+ const dispose = () => {
546
+ if (!active) return;
547
+ active = false;
548
+ for (const restore of undo.reverse()) restore();
549
+ };
550
+ return dispose;
551
+ })`;
552
+ var install;
553
+ var owners = /* @__PURE__ */ new WeakMap();
554
+ function observeRuntimeMutations(doc) {
555
+ if (!doc.defaultView) return () => {
556
+ };
557
+ let owner = owners.get(doc);
558
+ if (!owner) {
559
+ install ?? (install = new Function(
560
+ `return ${RUNTIME_MUTATION_SOURCE}`
561
+ )());
562
+ owner = { count: 0, stop: install(doc.defaultView) };
563
+ owners.set(doc, owner);
564
+ }
565
+ owner.count++;
566
+ let released = false;
567
+ return () => {
568
+ if (released) return;
569
+ released = true;
570
+ if (--owner.count === 0) {
571
+ owner.stop();
572
+ owners.delete(doc);
573
+ }
574
+ };
575
+ }
576
+
809
577
  export {
810
- getHeadTracker,
811
- captureHead,
578
+ generateSelector,
579
+ findLowestCommonAncestor,
580
+ FORM_RUNTIME_MUTATION,
581
+ CSS_RUNTIME_MUTATION,
582
+ observeRuntimeMutations,
812
583
  registerDocumentCaptureProducer,
813
584
  registerCaptureRootObserver,
814
585
  readCaptureProducerCardinality,
@@ -816,12 +587,10 @@ export {
816
587
  countIdentityNodeVisited,
817
588
  resetCaptureFlushCounters,
818
589
  readCaptureFlushCounters,
819
- generateSelector,
820
- findLowestCommonAncestor,
821
590
  capture,
822
591
  captureWithSupplementalRoots,
823
592
  removeScriptTags,
824
593
  captureAttributes,
825
594
  collectElementStates
826
595
  };
827
- //# sourceMappingURL=chunk-DX6XAXCK.js.map
596
+ //# sourceMappingURL=chunk-N2TYN3RB.js.map