tempo-sdk 0.0.52 → 0.0.57

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 +10 -6
  7. package/dist/canvas/index.js +130 -47
  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-EMYYTS6D.js +1585 -0
  20. package/dist/chunk-EMYYTS6D.js.map +1 -0
  21. package/dist/{chunk-DX6XAXCK.js → chunk-N2TYN3RB.js} +189 -420
  22. package/dist/chunk-N2TYN3RB.js.map +1 -0
  23. package/dist/{chunk-7Y7XNHUM.js → chunk-QXL6GL2P.js} +18 -3
  24. package/dist/chunk-QXL6GL2P.js.map +1 -0
  25. package/dist/{chunk-QP2NTODB.js → chunk-RHHVVWAC.js} +115 -25
  26. package/dist/chunk-RHHVVWAC.js.map +1 -0
  27. package/dist/chunk-TL4MGN7E.js +2570 -0
  28. package/dist/chunk-TL4MGN7E.js.map +1 -0
  29. package/dist/{chunk-PULSTDX2.js → chunk-U3SLJNRS.js} +284 -46
  30. package/dist/chunk-U3SLJNRS.js.map +1 -0
  31. package/dist/{chunk-ZZYNOX24.js → chunk-U64AHDHZ.js} +1708 -2461
  32. package/dist/chunk-U64AHDHZ.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 +463 -153
  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-BtQuVGpl.d.ts} +33 -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
@@ -0,0 +1,2570 @@
1
+ import {
2
+ FORM_RUNTIME_MUTATION,
3
+ findLowestCommonAncestor,
4
+ generateSelector,
5
+ observeRuntimeMutations,
6
+ removeScriptTags
7
+ } from "./chunk-N2TYN3RB.js";
8
+
9
+ // ../../modules/iframe-projection/fiber/react-types.ts
10
+ var FiberTag = {
11
+ /** Function component: `function MyComponent(props) { ... }` */
12
+ FunctionComponent: 0,
13
+ /** Class component: `class MyComponent extends React.Component` */
14
+ ClassComponent: 1,
15
+ /**
16
+ * Component not yet determined to be function or class.
17
+ * React resolves this on first render, then updates the tag.
18
+ */
19
+ IndeterminateComponent: 2,
20
+ /** Root of a React tree (created by createRoot/render) */
21
+ HostRoot: 3,
22
+ /** React Portal: renders children into a different DOM container */
23
+ HostPortal: 4,
24
+ /** DOM element: div, span, button, etc. */
25
+ HostComponent: 5,
26
+ /** Text node: string/number children */
27
+ HostText: 6,
28
+ /** React.Fragment or <>...</> */
29
+ Fragment: 7,
30
+ /** StrictMode, ConcurrentMode, etc. */
31
+ Mode: 8,
32
+ /** Context.Consumer (legacy pattern) */
33
+ ContextConsumer: 9,
34
+ /** Context.Provider */
35
+ ContextProvider: 10,
36
+ /** React.forwardRef wrapper */
37
+ ForwardRef: 11,
38
+ /** React.Profiler for performance measurements */
39
+ Profiler: 12,
40
+ /** React.Suspense boundary */
41
+ SuspenseComponent: 13,
42
+ /** React.memo() wrapper */
43
+ MemoComponent: 14,
44
+ /** Simplified memo (internal optimization) */
45
+ SimpleMemoComponent: 15,
46
+ /** React.lazy() wrapper for code splitting */
47
+ LazyComponent: 16,
48
+ /** Incomplete class component (errored during render) */
49
+ IncompleteClassComponent: 17,
50
+ /** Dehydrated Suspense boundary (server-rendered) */
51
+ DehydratedFragment: 18,
52
+ /** SuspenseList for coordinating reveal order */
53
+ SuspenseListComponent: 19,
54
+ /** Scope component (experimental) */
55
+ ScopeComponent: 21,
56
+ /** Offscreen component (experimental, powers Activity) */
57
+ OffscreenComponent: 22,
58
+ /** Legacy hidden component (deprecated) */
59
+ LegacyHiddenComponent: 23,
60
+ /** Cache component (experimental) */
61
+ CacheComponent: 24,
62
+ /** Tracing marker (experimental) */
63
+ TracingMarkerComponent: 25,
64
+ /** Hoistable elements like <title>, <meta> (React 18.3+) */
65
+ HostHoistable: 26,
66
+ /** Singleton elements like <html>, <head>, <body> (React 18.3+) */
67
+ HostSingleton: 27
68
+ };
69
+
70
+ // ../../modules/iframe-projection/fiber/serialize.ts
71
+ function getDisplayName(fiber) {
72
+ const { type, tag } = fiber;
73
+ if (typeof type === "string") {
74
+ return type;
75
+ }
76
+ if (tag === FiberTag.HostText) {
77
+ return "#text";
78
+ }
79
+ if (typeof type === "function") {
80
+ const fn = type;
81
+ return fn.displayName || fn.name || "Anonymous";
82
+ }
83
+ if (type && typeof type === "object") {
84
+ if ("type" in type && type.type) {
85
+ const inner = type.type;
86
+ if (typeof inner === "function") {
87
+ return inner.displayName || inner.name || "Memo";
88
+ }
89
+ }
90
+ if ("render" in type && type.render) {
91
+ const render = type.render;
92
+ return type.displayName || render.displayName || render.name || "ForwardRef";
93
+ }
94
+ if ("_context" in type) {
95
+ const ctx = type._context;
96
+ return ctx.displayName ? `${ctx.displayName}.Provider` : "Context.Provider";
97
+ }
98
+ }
99
+ const tagNames = {
100
+ [FiberTag.HostRoot]: "HostRoot",
101
+ [FiberTag.Fragment]: "Fragment",
102
+ [FiberTag.Mode]: "Mode",
103
+ [FiberTag.ContextConsumer]: "Context.Consumer",
104
+ [FiberTag.ContextProvider]: "Context.Provider",
105
+ [FiberTag.Profiler]: "Profiler",
106
+ [FiberTag.SuspenseComponent]: "Suspense",
107
+ [FiberTag.SuspenseListComponent]: "SuspenseList",
108
+ [FiberTag.OffscreenComponent]: "Offscreen"
109
+ };
110
+ return tagNames[tag] || `Unknown(${tag})`;
111
+ }
112
+ function getTag(fiber) {
113
+ return fiber.tag;
114
+ }
115
+ function getProps(fiber) {
116
+ return fiber.memoizedProps;
117
+ }
118
+ function sanitizeProps(props) {
119
+ if (!props) return void 0;
120
+ const result = {};
121
+ let hasProps = false;
122
+ for (const [key, value] of Object.entries(props)) {
123
+ if (key === "children") continue;
124
+ hasProps = true;
125
+ result[key] = sanitizeValue(value);
126
+ }
127
+ return hasProps ? result : void 0;
128
+ }
129
+ function sanitizeValue(value) {
130
+ if (value === null || value === void 0) {
131
+ return value;
132
+ }
133
+ if (typeof value === "function") {
134
+ return "[Function]";
135
+ }
136
+ if (typeof value === "symbol") {
137
+ return `[Symbol:${value.description ?? ""}]`;
138
+ }
139
+ if (value instanceof Element) {
140
+ return `[Element:${value.tagName.toLowerCase()}${value.id ? `#${value.id}` : ""}]`;
141
+ }
142
+ if (value instanceof Node) {
143
+ return `[Node:${value.nodeName}]`;
144
+ }
145
+ if (Array.isArray(value)) {
146
+ if (value.length <= 10) {
147
+ return value.map(sanitizeValue);
148
+ }
149
+ return `[Array(${value.length})]`;
150
+ }
151
+ if (typeof value === "object") {
152
+ if ("$$typeof" in value) {
153
+ return "[ReactElement]";
154
+ }
155
+ try {
156
+ return JSON.parse(JSON.stringify(value));
157
+ } catch {
158
+ return "[Object]";
159
+ }
160
+ }
161
+ return value;
162
+ }
163
+ function getDomElement(fiber) {
164
+ if (fiber.tag !== FiberTag.HostComponent) {
165
+ return null;
166
+ }
167
+ return fiber.stateNode instanceof Element ? fiber.stateNode : null;
168
+ }
169
+ function* iterateChildren(fiber) {
170
+ let child = fiber.child;
171
+ while (child) {
172
+ yield child;
173
+ child = child.sibling;
174
+ }
175
+ }
176
+ function resolveCommittedFiber(fiber) {
177
+ const alternate = fiber.alternate;
178
+ if (!alternate) {
179
+ return fiber;
180
+ }
181
+ let a = fiber;
182
+ let b = alternate;
183
+ for (; ; ) {
184
+ const parentA = a.return;
185
+ if (!parentA) break;
186
+ const parentB = parentA.alternate;
187
+ if (!parentB) {
188
+ const nextParent = parentA.return;
189
+ if (nextParent) {
190
+ a = nextParent;
191
+ b = nextParent;
192
+ continue;
193
+ }
194
+ break;
195
+ }
196
+ if (parentA.child === parentB.child) {
197
+ for (let child = parentA.child; child; child = child.sibling) {
198
+ if (child === a) return fiber;
199
+ if (child === b) return alternate;
200
+ }
201
+ throw new Error("Unable to resolve a mounted React fiber");
202
+ }
203
+ if (a.return !== b.return) {
204
+ a = parentA;
205
+ b = parentB;
206
+ } else {
207
+ let found = false;
208
+ for (let child = parentA.child; child; child = child.sibling) {
209
+ if (child === a) {
210
+ found = true;
211
+ a = parentA;
212
+ b = parentB;
213
+ break;
214
+ }
215
+ if (child === b) {
216
+ found = true;
217
+ a = parentB;
218
+ b = parentA;
219
+ break;
220
+ }
221
+ }
222
+ if (!found) {
223
+ for (let child = parentB.child; child; child = child.sibling) {
224
+ if (child === a) {
225
+ found = true;
226
+ a = parentB;
227
+ b = parentA;
228
+ break;
229
+ }
230
+ if (child === b) {
231
+ found = true;
232
+ a = parentA;
233
+ b = parentB;
234
+ break;
235
+ }
236
+ }
237
+ }
238
+ if (!found) {
239
+ throw new Error("React fiber is absent from both parent generations");
240
+ }
241
+ }
242
+ if (a.alternate !== b) {
243
+ throw new Error("React return fibers are not paired alternates");
244
+ }
245
+ }
246
+ if (a.tag !== FiberTag.HostRoot) {
247
+ throw new Error("Unable to resolve an unmounted React fiber");
248
+ }
249
+ const fiberRoot = a.stateNode;
250
+ return fiberRoot?.current === a ? fiber : alternate;
251
+ }
252
+ var TRANSIENT_FIBER_RESOLUTION_ERRORS = /* @__PURE__ */ new Set([
253
+ "Unable to resolve a mounted React fiber",
254
+ "React fiber is absent from both parent generations",
255
+ "React return fibers are not paired alternates",
256
+ "Unable to resolve an unmounted React fiber"
257
+ ]);
258
+ function isTransientFiberResolutionError(error) {
259
+ return error instanceof Error && TRANSIENT_FIBER_RESOLUTION_ERRORS.has(error.message);
260
+ }
261
+ var defaultSerialize = (fiber) => ({
262
+ name: getDisplayName(fiber),
263
+ tag: getTag(fiber)
264
+ });
265
+ function serializeTree(fiber, serialize, options = {}) {
266
+ const { maxDepth = Infinity, skipText = true } = options;
267
+ function serializeNode(f, depth) {
268
+ if (depth > maxDepth) return null;
269
+ if (skipText && f.tag === FiberTag.HostText) {
270
+ return null;
271
+ }
272
+ const nodeData = serialize(f);
273
+ const children = [];
274
+ for (const child of iterateChildren(f)) {
275
+ const serialized = serializeNode(child, depth + 1);
276
+ if (serialized) {
277
+ children.push(serialized);
278
+ }
279
+ }
280
+ return { ...nodeData, children };
281
+ }
282
+ return serializeNode(fiber, 0);
283
+ }
284
+
285
+ // ../../modules/iframe-projection/fiber/capture.ts
286
+ function findFiberKey(element) {
287
+ return Object.keys(element).find(
288
+ (k) => k.startsWith("__reactFiber$") || k.startsWith("__reactInternalInstance$")
289
+ ) ?? null;
290
+ }
291
+ function findContainerKey(element) {
292
+ return Object.keys(element).find((k) => k.startsWith("__reactContainer$")) ?? null;
293
+ }
294
+ function getFiberFromElement(element) {
295
+ const fiberKey = findFiberKey(element);
296
+ if (fiberKey) {
297
+ return element[fiberKey] ?? null;
298
+ }
299
+ const containerKey = findContainerKey(element);
300
+ if (containerKey) {
301
+ return element[containerKey] ?? null;
302
+ }
303
+ return null;
304
+ }
305
+
306
+ // ../../modules/iframe-projection/fiber/utils.ts
307
+ function filterTreeInclude(tree, includeTags) {
308
+ if (tree === null) return null;
309
+ if (!includeTags.has(tree.tag)) {
310
+ const filteredChildren = filterChildrenInclude(tree.children, includeTags);
311
+ return filteredChildren.length > 0 ? filteredChildren[0] : null;
312
+ }
313
+ return {
314
+ ...tree,
315
+ children: filterChildrenInclude(tree.children, includeTags)
316
+ };
317
+ }
318
+ function filterChildrenInclude(children, includeTags) {
319
+ const result = [];
320
+ for (const child of children) {
321
+ if (!includeTags.has(child.tag)) {
322
+ const grandchildren = filterChildrenInclude(child.children, includeTags);
323
+ result.push(...grandchildren);
324
+ } else {
325
+ result.push({
326
+ ...child,
327
+ children: filterChildrenInclude(child.children, includeTags)
328
+ });
329
+ }
330
+ }
331
+ return result;
332
+ }
333
+
334
+ // ../../modules/iframe-projection/fiber/watch.ts
335
+ function captureTree(options = {}) {
336
+ const { selector, serialize, tags, ...serializeOptions } = options;
337
+ const serializeFn = serialize ?? defaultSerialize;
338
+ const tagSet = tags && tags.length > 0 ? new Set(tags) : null;
339
+ let startFiber = null;
340
+ if (selector) {
341
+ const element = document.querySelector(selector);
342
+ if (element) {
343
+ const rawFiber = getFiberFromElement(element);
344
+ startFiber = rawFiber ? resolveCommittedFiber(rawFiber) : null;
345
+ }
346
+ } else {
347
+ const hook = getHook();
348
+ if (!hook) return null;
349
+ let fiberRoot = null;
350
+ for (const roots of lastCommittedRoots.values()) {
351
+ for (const root of roots) {
352
+ if (root.current) {
353
+ fiberRoot = root;
354
+ break;
355
+ }
356
+ }
357
+ if (fiberRoot) break;
358
+ }
359
+ if (!fiberRoot) {
360
+ for (const [_id, renderer] of hook.renderers ?? []) {
361
+ const roots = renderer.getFiberRoots?.();
362
+ if (roots) {
363
+ for (const root of roots) {
364
+ if (root?.current) {
365
+ fiberRoot = root;
366
+ break;
367
+ }
368
+ }
369
+ }
370
+ if (fiberRoot) break;
371
+ }
372
+ }
373
+ if (!fiberRoot) return null;
374
+ const rootFiber = fiberRoot.current;
375
+ if (rootFiber && rootFiber.tag === FiberTag.HostRoot && rootFiber.child) {
376
+ startFiber = rootFiber.child;
377
+ } else if (rootFiber) {
378
+ startFiber = rootFiber;
379
+ }
380
+ }
381
+ if (!startFiber) return null;
382
+ let tree = serializeTree(startFiber, serializeFn, serializeOptions);
383
+ if (tree && tagSet && "tag" in tree) {
384
+ const filtered = filterTreeInclude(
385
+ tree,
386
+ tagSet
387
+ );
388
+ tree = filtered;
389
+ }
390
+ return tree;
391
+ }
392
+ var HOOK_MARKER = /* @__PURE__ */ Symbol.for("iframe-projection-fiber-hook");
393
+ var cachedInterface = null;
394
+ var lastCommittedRoots = /* @__PURE__ */ new Map();
395
+ function rememberCommittedRoot(rendererId, root) {
396
+ const roots = lastCommittedRoots.get(rendererId) ?? /* @__PURE__ */ new Set();
397
+ for (const previous of roots) {
398
+ if (previous !== root && previous.containerInfo === root.containerInfo) {
399
+ roots.delete(previous);
400
+ }
401
+ }
402
+ roots.add(root);
403
+ lastCommittedRoots.set(rendererId, roots);
404
+ }
405
+ function getCommittedFiberRoots() {
406
+ return [...lastCommittedRoots.values()].flatMap((roots) => [...roots]);
407
+ }
408
+ function initHook() {
409
+ if (cachedInterface) {
410
+ return cachedInterface;
411
+ }
412
+ const existing = typeof window !== "undefined" ? window.__REACT_DEVTOOLS_GLOBAL_HOOK__ : void 0;
413
+ if (existing && HOOK_MARKER in existing) {
414
+ cachedInterface = existing[HOOK_MARKER];
415
+ return cachedInterface;
416
+ }
417
+ const commitHandlers = /* @__PURE__ */ new Set();
418
+ const injectHandlers = /* @__PURE__ */ new Set();
419
+ const unmountHandlers = /* @__PURE__ */ new Set();
420
+ const createRegistrar = (set) => (handler) => {
421
+ set.add(handler);
422
+ return () => set.delete(handler);
423
+ };
424
+ const callbacks = {
425
+ onCommit: (root, id2, didError) => {
426
+ rememberCommittedRoot(id2, root);
427
+ commitHandlers.forEach((h) => h(root, id2, didError));
428
+ },
429
+ onInject: (renderer, id2) => injectHandlers.forEach((h) => h(renderer, id2)),
430
+ onUnmount: (fiber, id2) => unmountHandlers.forEach((h) => h(fiber, id2))
431
+ };
432
+ let hook;
433
+ if (existing) {
434
+ wrapDevToolsHook(existing, callbacks);
435
+ hook = existing;
436
+ } else {
437
+ hook = createDevToolsHook(callbacks);
438
+ if (typeof window !== "undefined") {
439
+ window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook;
440
+ }
441
+ }
442
+ const hookInterface = {
443
+ onCommit: createRegistrar(commitHandlers),
444
+ onInject: createRegistrar(injectHandlers),
445
+ onUnmount: createRegistrar(unmountHandlers),
446
+ hook,
447
+ seedCommittedRoots(roots) {
448
+ for (const [rendererId, root] of roots) {
449
+ rememberCommittedRoot(rendererId, root);
450
+ }
451
+ }
452
+ };
453
+ hook[HOOK_MARKER] = hookInterface;
454
+ cachedInterface = hookInterface;
455
+ return hookInterface;
456
+ }
457
+ function createDevToolsHook(callbacks) {
458
+ const hook = {
459
+ supportsFiber: true,
460
+ renderers: /* @__PURE__ */ new Map(),
461
+ inject(renderer) {
462
+ const id2 = this.renderers.size + 1;
463
+ this.renderers.set(id2, renderer);
464
+ callbacks?.onInject?.(renderer, id2);
465
+ return id2;
466
+ },
467
+ onCommitFiberRoot(rendererId, fiberRoot, _priority, didError) {
468
+ callbacks?.onCommit?.(fiberRoot, rendererId, didError === true);
469
+ },
470
+ onCommitFiberUnmount(rendererId, fiber) {
471
+ callbacks?.onUnmount?.(fiber, rendererId);
472
+ },
473
+ // Required stubs for React compatibility
474
+ checkDCE(_fn) {
475
+ },
476
+ onScheduleFiberRoot() {
477
+ }
478
+ };
479
+ return hook;
480
+ }
481
+ function wrapDevToolsHook(hook, callbacks) {
482
+ if (callbacks.onInject && typeof hook.inject === "function") {
483
+ const original = hook.inject.bind(hook);
484
+ hook.inject = function(renderer) {
485
+ const id2 = original(renderer);
486
+ callbacks.onInject(renderer, id2);
487
+ return id2;
488
+ };
489
+ }
490
+ if (callbacks.onCommit) {
491
+ const original = hook.onCommitFiberRoot?.bind(hook);
492
+ hook.onCommitFiberRoot = function(rendererId, fiberRoot, priority, didError) {
493
+ callbacks.onCommit(fiberRoot, rendererId, didError === true);
494
+ original?.(rendererId, fiberRoot, priority, didError);
495
+ };
496
+ }
497
+ if (callbacks.onUnmount) {
498
+ const original = hook.onCommitFiberUnmount?.bind(hook);
499
+ hook.onCommitFiberUnmount = function(rendererId, fiber) {
500
+ callbacks.onUnmount(fiber, rendererId);
501
+ original?.(rendererId, fiber);
502
+ };
503
+ }
504
+ }
505
+ function getHook() {
506
+ if (typeof window === "undefined") return null;
507
+ return window.__REACT_DEVTOOLS_GLOBAL_HOOK__ ?? null;
508
+ }
509
+
510
+ // ../../modules/iframe-projection/fiber/projection-scope.ts
511
+ var PROJECTION_SCOPE_ROLE = "__tempoProjectionScopeRole";
512
+ function role(fiber) {
513
+ const type = fiber?.type;
514
+ return type?.[PROJECTION_SCOPE_ROLE];
515
+ }
516
+ function isOutputInvocation(fiber) {
517
+ const parent = fiber.return;
518
+ return role(parent) === "output" || parent?.tag === FiberTag.MemoComponent && isOutputInvocation(parent);
519
+ }
520
+ function isProjectionScopePlumbing(fiber) {
521
+ return role(fiber) !== void 0 || isOutputInvocation(fiber);
522
+ }
523
+
524
+ // ../../modules/iframe-projection/combined/realm-epoch.ts
525
+ var REALM_DOCUMENT_EPOCH = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
526
+ var nextCaptureSequence = 0;
527
+ function nextRealmCaptureSequence() {
528
+ return nextCaptureSequence++;
529
+ }
530
+
531
+ // ../../modules/iframe-projection/html/watch-dom.ts
532
+ var DOM_ID_ATTR = "data-dom-id";
533
+ var HOST_LAYER_ID_ATTR = "data-host-layer-id";
534
+ var PROJECTION_ROOT_ATTRIBUTE = "data-tempo-projection-root";
535
+ var idPrefix = REALM_DOCUMENT_EPOCH;
536
+ var idCounter = 0;
537
+ var liveElementIds = /* @__PURE__ */ new WeakMap();
538
+ function nextProjectionId() {
539
+ return `${idPrefix}-${idCounter++}`;
540
+ }
541
+ function seedProjectionIds(sessionId) {
542
+ idPrefix = sessionId;
543
+ }
544
+ function underForeignProjectionRoot(element, root) {
545
+ for (let current = element; current && current !== root; current = current.parentElement) {
546
+ if (current.hasAttribute(PROJECTION_ROOT_ATTRIBUTE)) return true;
547
+ }
548
+ return false;
549
+ }
550
+ function projectedElements(scope) {
551
+ const elements = [];
552
+ const stack = [scope];
553
+ while (stack.length > 0) {
554
+ const element = stack.pop();
555
+ if (element.tagName.toLowerCase() === "script") continue;
556
+ elements.push(element);
557
+ if (element !== scope && element.hasAttribute(PROJECTION_ROOT_ATTRIBUTE))
558
+ continue;
559
+ for (let index = element.children.length - 1; index >= 0; index -= 1) {
560
+ stack.push(element.children[index]);
561
+ }
562
+ }
563
+ return elements;
564
+ }
565
+ function assignDomId(element) {
566
+ let id2 = liveElementIds.get(element);
567
+ if (!id2) {
568
+ id2 = nextProjectionId();
569
+ liveElementIds.set(element, id2);
570
+ }
571
+ if (element.getAttribute(DOM_ID_ATTR) !== id2) {
572
+ element.setAttribute(DOM_ID_ATTR, id2);
573
+ }
574
+ if (element.getAttribute(HOST_LAYER_ID_ATTR) !== id2) {
575
+ element.setAttribute(HOST_LAYER_ID_ATTR, id2);
576
+ }
577
+ return id2;
578
+ }
579
+ function ensureProjectionDomId(element, root) {
580
+ if (element.nodeType === 3 || element.nodeType === 8) {
581
+ let parent = element.parentElement;
582
+ if (!parent) return readProjectionDomId(element);
583
+ const position = [
584
+ Array.from(parent.childNodes).filter(
585
+ (child) => !(child instanceof Element) || child.localName !== "script" && !child.hasAttribute("data-tempo-svelte-source-registry")
586
+ ).indexOf(element)
587
+ ];
588
+ const rootDomId = root ? ensureProjectionDomId(root) : null;
589
+ const rootParentId = rootDomId && `$projection-root:${rootDomId}`;
590
+ let parentId = parent === root ? rootParentId : ensureProjectionDomId(parent);
591
+ while (!parentId && parent !== root && parent.parentElement) {
592
+ position.unshift(
593
+ Array.from(parent.parentElement.childNodes).filter(
594
+ (child) => !(child instanceof Element) || child.localName !== "script" && !child.hasAttribute("data-tempo-svelte-source-registry")
595
+ ).indexOf(parent)
596
+ );
597
+ parent = parent.parentElement;
598
+ parentId = parent === root ? rootParentId : ensureProjectionDomId(parent);
599
+ }
600
+ if (!parentId) return null;
601
+ const kind = element.nodeType === 3 ? "text" : "comment";
602
+ const id2 = `${parentId}/${kind}/${position.join("/")}`;
603
+ liveElementIds.set(element, id2);
604
+ return id2;
605
+ }
606
+ if (!(element instanceof Element)) return null;
607
+ if (hasContentEditableAncestor(element)) return null;
608
+ return assignDomId(element);
609
+ }
610
+ function readProjectionDomId(element) {
611
+ return liveElementIds.get(element) ?? null;
612
+ }
613
+ function syncProjectionDomIdsToClone(liveRoot, cloneRoot, includeRoot = true) {
614
+ const pending = includeRoot ? [[liveRoot, cloneRoot]] : Array.from(
615
+ liveRoot.children,
616
+ (liveChild, index) => [liveChild, cloneRoot.children[index]]
617
+ );
618
+ while (pending.length > 0) {
619
+ const [live, clone] = pending.pop();
620
+ const id2 = live.tagName.toLowerCase() === "script" ? null : ensureProjectionDomId(live);
621
+ if (id2) {
622
+ clone.setAttribute(DOM_ID_ATTR, id2);
623
+ clone.setAttribute(HOST_LAYER_ID_ATTR, id2);
624
+ } else {
625
+ clone.removeAttribute(DOM_ID_ATTR);
626
+ clone.removeAttribute(HOST_LAYER_ID_ATTR);
627
+ }
628
+ if (live !== liveRoot && live.hasAttribute(PROJECTION_ROOT_ATTRIBUTE)) {
629
+ clone.replaceChildren();
630
+ continue;
631
+ }
632
+ for (let index = 0; index < live.children.length; index += 1) {
633
+ const liveChild = live.children[index];
634
+ const cloneChild = clone.children[index];
635
+ if (liveChild && cloneChild) pending.push([liveChild, cloneChild]);
636
+ }
637
+ }
638
+ }
639
+ function isContentEditableRoot(element) {
640
+ return element.getAttribute("contenteditable") !== null;
641
+ }
642
+ function hasContentEditableAncestor(element) {
643
+ let current = element.parentElement;
644
+ while (current) {
645
+ if (current.getAttribute("contenteditable") !== null) {
646
+ return true;
647
+ }
648
+ current = current.parentElement;
649
+ }
650
+ return false;
651
+ }
652
+ function assignDomIdToTree(root, watchedRoot) {
653
+ if (hasContentEditableAncestor(root)) {
654
+ return;
655
+ }
656
+ ensureProjectionDomId(root);
657
+ if (isContentEditableRoot(root)) {
658
+ return;
659
+ }
660
+ if (root !== watchedRoot && root.hasAttribute(PROJECTION_ROOT_ATTRIBUTE)) {
661
+ return;
662
+ }
663
+ const stack = [];
664
+ for (let i = root.children.length - 1; i >= 0; i--) {
665
+ stack.push(root.children[i]);
666
+ }
667
+ while (stack.length > 0) {
668
+ const element = stack.pop();
669
+ ensureProjectionDomId(element);
670
+ if (isContentEditableRoot(element)) {
671
+ continue;
672
+ }
673
+ if (element.hasAttribute(PROJECTION_ROOT_ATTRIBUTE)) {
674
+ continue;
675
+ }
676
+ for (let i = element.children.length - 1; i >= 0; i--) {
677
+ stack.push(element.children[i]);
678
+ }
679
+ }
680
+ }
681
+ function watchDom(root, onMutation) {
682
+ const mutatedElements = /* @__PURE__ */ new Set();
683
+ assignDomIdToTree(root, root);
684
+ const retainMutations = (mutations) => {
685
+ const scalarMutations = [];
686
+ const firstAttributeByTarget = /* @__PURE__ */ new WeakMap();
687
+ const firstCharacterDataByTarget = /* @__PURE__ */ new WeakMap();
688
+ for (const mutation of mutations) {
689
+ const concernedParent = mutation.type === "attributes" ? mutation.target.parentElement : mutation.target instanceof Element ? mutation.target : mutation.target.parentElement;
690
+ if (concernedParent && underForeignProjectionRoot(concernedParent, root))
691
+ continue;
692
+ if (mutation.type === "attributes" && mutation.attributeName !== null) {
693
+ const isProjectionId = mutation.attributeName === DOM_ID_ATTR || mutation.attributeName === HOST_LAYER_ID_ATTR;
694
+ if (isProjectionId) continue;
695
+ const target = mutation.target;
696
+ const byName = firstAttributeByTarget.get(target) ?? /* @__PURE__ */ new Map();
697
+ if (!byName.has(mutation.attributeName)) {
698
+ byName.set(mutation.attributeName, mutation);
699
+ firstAttributeByTarget.set(target, byName);
700
+ scalarMutations.push(mutation);
701
+ }
702
+ } else if (mutation.type === "characterData") {
703
+ if (!firstCharacterDataByTarget.has(mutation.target)) {
704
+ firstCharacterDataByTarget.set(mutation.target, mutation);
705
+ scalarMutations.push(mutation);
706
+ }
707
+ } else {
708
+ scalarMutations.push(mutation);
709
+ }
710
+ }
711
+ let retained = 0;
712
+ for (const mutation of scalarMutations) {
713
+ if (mutation.type === "attributes" && mutation.attributeName !== null && mutation.oldValue === mutation.target.getAttribute(mutation.attributeName)) {
714
+ continue;
715
+ }
716
+ if (mutation.type === "characterData" && mutation.oldValue === mutation.target.textContent) {
717
+ continue;
718
+ }
719
+ retained += 1;
720
+ watcher.mutationRecordCount += 1;
721
+ watcher.projectionMutations.push({
722
+ type: mutation.type,
723
+ target: mutation.target,
724
+ ...mutation.type === "attributes" || mutation.type === "characterData" ? { oldValue: mutation.oldValue } : {},
725
+ ...mutation.type === "attributes" ? { attributeName: mutation.attributeName } : {},
726
+ ...mutation.type === "childList" ? {
727
+ addedNodes: Array.from(mutation.addedNodes),
728
+ removedNodes: Array.from(mutation.removedNodes),
729
+ previousSibling: mutation.previousSibling,
730
+ nextSibling: mutation.nextSibling
731
+ } : {}
732
+ });
733
+ const target = mutation.target instanceof Element ? mutation.target : mutation.target.parentElement;
734
+ if (target && root.contains(target)) {
735
+ mutatedElements.add(target);
736
+ }
737
+ if (mutation.type === "childList") {
738
+ for (const node of mutation.addedNodes) {
739
+ if (node instanceof Element && root.contains(node)) {
740
+ assignDomIdToTree(node, root);
741
+ watcher.addedElementCount += 1;
742
+ }
743
+ }
744
+ if (mutation.target instanceof Element && root.contains(mutation.target)) {
745
+ mutatedElements.add(mutation.target);
746
+ }
747
+ }
748
+ }
749
+ return retained;
750
+ };
751
+ const observer = new MutationObserver((mutations) => {
752
+ if (retainMutations(mutations) > 0 && mutatedElements.size > 0)
753
+ onMutation();
754
+ });
755
+ observer.observe(root, {
756
+ childList: true,
757
+ subtree: true,
758
+ attributes: true,
759
+ attributeOldValue: true,
760
+ characterData: true,
761
+ characterDataOldValue: true
762
+ });
763
+ const watcher = {
764
+ root,
765
+ mutatedElements,
766
+ addedElementCount: 0,
767
+ mutationRecordCount: 0,
768
+ projectionMutations: [],
769
+ takePendingRecords: () => retainMutations(observer.takeRecords()),
770
+ stop: () => {
771
+ observer.disconnect();
772
+ mutatedElements.clear();
773
+ watcher.mutationRecordCount = 0;
774
+ watcher.projectionMutations.length = 0;
775
+ }
776
+ };
777
+ return watcher;
778
+ }
779
+ function flushDomWatcher(watcher) {
780
+ watcher.addedElementCount = 0;
781
+ watcher.mutationRecordCount = 0;
782
+ watcher.projectionMutations.length = 0;
783
+ if (watcher.mutatedElements.size === 0) {
784
+ return null;
785
+ }
786
+ const lca = findLowestCommonAncestor(watcher.mutatedElements);
787
+ watcher.mutatedElements.clear();
788
+ if (lca && !watcher.root.contains(lca) && lca !== watcher.root) {
789
+ return watcher.root;
790
+ }
791
+ return lca;
792
+ }
793
+ function drainProjectionDomMutations(watcher) {
794
+ const retained = watcher.projectionMutations.splice(0);
795
+ const mutations = [];
796
+ const firstAttributeByTarget = /* @__PURE__ */ new WeakMap();
797
+ const firstCharacterDataTargets = /* @__PURE__ */ new WeakSet();
798
+ for (const mutation of retained) {
799
+ const attributeName = mutation.attributeName;
800
+ if (mutation.type === "attributes" && attributeName != null) {
801
+ const target = mutation.target;
802
+ const names = firstAttributeByTarget.get(target) ?? /* @__PURE__ */ new Set();
803
+ if (names.has(attributeName)) continue;
804
+ names.add(attributeName);
805
+ firstAttributeByTarget.set(target, names);
806
+ if (mutation.oldValue === target.getAttribute(attributeName)) {
807
+ continue;
808
+ }
809
+ mutations.push({
810
+ type: "attributes",
811
+ target,
812
+ attributeName
813
+ });
814
+ continue;
815
+ }
816
+ if (mutation.type === "characterData") {
817
+ if (firstCharacterDataTargets.has(mutation.target)) continue;
818
+ firstCharacterDataTargets.add(mutation.target);
819
+ if (mutation.oldValue === mutation.target.textContent) continue;
820
+ mutations.push({ type: "characterData", target: mutation.target });
821
+ continue;
822
+ }
823
+ mutations.push(mutation);
824
+ }
825
+ watcher.mutatedElements.clear();
826
+ watcher.addedElementCount = 0;
827
+ watcher.mutationRecordCount = 0;
828
+ return mutations;
829
+ }
830
+ function hasPendingMutations(watcher) {
831
+ return watcher.mutatedElements.size > 0;
832
+ }
833
+
834
+ // ../../modules/iframe-projection/combined/projection-observed-files.ts
835
+ var ProjectionObservedFileAccumulator = class {
836
+ constructor() {
837
+ this.files = /* @__PURE__ */ new Map();
838
+ }
839
+ add(filepath, modifiedTsRaw, sourceVersionRaw) {
840
+ if (typeof filepath !== "string" || filepath.length === 0) return;
841
+ const modifiedTs = typeof modifiedTsRaw === "number" ? modifiedTsRaw : typeof modifiedTsRaw === "string" ? Number(modifiedTsRaw) : Number.NaN;
842
+ if (!Number.isFinite(modifiedTs)) return;
843
+ const sourceVersion = typeof sourceVersionRaw === "string" && sourceVersionRaw.length > 0 ? sourceVersionRaw : void 0;
844
+ const current = this.files.get(filepath);
845
+ if (!current) {
846
+ this.files.set(filepath, {
847
+ modifiedTs,
848
+ sourceVersion
849
+ });
850
+ return;
851
+ }
852
+ if (modifiedTs > current.modifiedTs) return;
853
+ if (modifiedTs < current.modifiedTs) {
854
+ current.modifiedTs = modifiedTs;
855
+ current.sourceVersion = sourceVersion;
856
+ return;
857
+ }
858
+ if (current.sourceVersion !== sourceVersion)
859
+ current.sourceVersion = void 0;
860
+ }
861
+ merge(files) {
862
+ if (!files) return;
863
+ for (const [filepath, fact] of Object.entries(files)) {
864
+ this.add(filepath, fact.modifiedTs, fact.sourceVersion);
865
+ }
866
+ }
867
+ addLayerProps(props) {
868
+ if (!props) return;
869
+ this.add(
870
+ props["data-tempo-filepath"],
871
+ props["data-tempo-modifiedts"],
872
+ props["data-tempo-source-version"]
873
+ );
874
+ }
875
+ addElement(element) {
876
+ this.add(
877
+ element.getAttribute("data-tempo-filepath"),
878
+ element.getAttribute("data-tempo-modifiedts"),
879
+ element.getAttribute("data-tempo-source-version")
880
+ );
881
+ }
882
+ snapshot() {
883
+ return Object.fromEntries(
884
+ Array.from(this.files, ([filepath, fact]) => [
885
+ filepath,
886
+ {
887
+ modifiedTs: fact.modifiedTs,
888
+ ...fact.sourceVersion !== void 0 ? { sourceVersion: fact.sourceVersion } : {}
889
+ }
890
+ ])
891
+ );
892
+ }
893
+ };
894
+
895
+ // ../../modules/iframe-projection/html/watch-state.ts
896
+ function watchState(root, onStateChange) {
897
+ const scrolledElements = /* @__PURE__ */ new Set();
898
+ const changedFormElements = /* @__PURE__ */ new Set();
899
+ const stopRuntimeMutations = observeRuntimeMutations(root.ownerDocument);
900
+ const handleScroll = (event) => {
901
+ const target = event.target;
902
+ if (target instanceof Element && root.contains(target)) {
903
+ scrolledElements.add(target);
904
+ watcher.stateRecordCount += 1;
905
+ onStateChange();
906
+ } else if (target === document) {
907
+ const scrollTarget = document.scrollingElement || document.documentElement;
908
+ if (scrollTarget) {
909
+ scrolledElements.add(scrollTarget);
910
+ watcher.stateRecordCount += 1;
911
+ onStateChange();
912
+ }
913
+ }
914
+ };
915
+ const handleFormChange = (event) => {
916
+ if (event.target instanceof Element && root.contains(event.target)) {
917
+ changedFormElements.add(event.target);
918
+ watcher.projectionFormEvents.set(
919
+ event.target,
920
+ event.type === "change" ? "change" : "input"
921
+ );
922
+ watcher.stateRecordCount += 1;
923
+ onStateChange();
924
+ }
925
+ };
926
+ document.addEventListener("scroll", handleScroll, true);
927
+ document.addEventListener("input", handleFormChange, true);
928
+ document.addEventListener("change", handleFormChange, true);
929
+ document.addEventListener(FORM_RUNTIME_MUTATION, handleFormChange, true);
930
+ const watcher = {
931
+ root,
932
+ scrolledElements,
933
+ changedFormElements,
934
+ stateRecordCount: 0,
935
+ projectionFormEvents: /* @__PURE__ */ new Map(),
936
+ stop: () => {
937
+ document.removeEventListener("scroll", handleScroll, true);
938
+ document.removeEventListener("input", handleFormChange, true);
939
+ document.removeEventListener("change", handleFormChange, true);
940
+ document.removeEventListener(
941
+ FORM_RUNTIME_MUTATION,
942
+ handleFormChange,
943
+ true
944
+ );
945
+ stopRuntimeMutations();
946
+ scrolledElements.clear();
947
+ changedFormElements.clear();
948
+ watcher.stateRecordCount = 0;
949
+ watcher.projectionFormEvents.clear();
950
+ }
951
+ };
952
+ return watcher;
953
+ }
954
+ function flushStateWatcher(watcher) {
955
+ const { root, scrolledElements, changedFormElements } = watcher;
956
+ watcher.stateRecordCount = 0;
957
+ watcher.projectionFormEvents.clear();
958
+ const states = [];
959
+ const scrolled = new Set(scrolledElements);
960
+ const changed = new Set(changedFormElements);
961
+ scrolledElements.clear();
962
+ changedFormElements.clear();
963
+ for (const el of scrolled) {
964
+ const isDocumentScroll = el === document.scrollingElement || el === document.documentElement;
965
+ if (!isDocumentScroll && !root.contains(el)) continue;
966
+ const selector = isDocumentScroll ? ":root" : generateSelector(el, root);
967
+ states.push({
968
+ selector,
969
+ scrollTop: el.scrollTop,
970
+ scrollLeft: el.scrollLeft
971
+ });
972
+ }
973
+ for (const el of changed) {
974
+ if (!root.contains(el)) continue;
975
+ if (el instanceof HTMLInputElement) {
976
+ const isCheckable = el.type === "checkbox" || el.type === "radio";
977
+ const hasNonDefault = isCheckable ? el.checked !== el.defaultChecked : el.value !== el.defaultValue;
978
+ if (hasNonDefault) {
979
+ const selector = generateSelector(el, root);
980
+ if (isCheckable) {
981
+ states.push({ selector, checked: el.checked });
982
+ } else {
983
+ states.push({ selector, value: el.value });
984
+ }
985
+ changedFormElements.add(el);
986
+ }
987
+ } else if (el instanceof HTMLTextAreaElement) {
988
+ if (el.value !== el.defaultValue) {
989
+ const selector = generateSelector(el, root);
990
+ states.push({ selector, value: el.value });
991
+ changedFormElements.add(el);
992
+ }
993
+ } else if (el instanceof HTMLSelectElement) {
994
+ let hasNonDefault = false;
995
+ for (const option of el.options) {
996
+ if (option.selected !== option.defaultSelected) {
997
+ const selector = generateSelector(option, root);
998
+ states.push({ selector, selected: option.selected });
999
+ hasNonDefault = true;
1000
+ }
1001
+ }
1002
+ if (hasNonDefault) {
1003
+ changedFormElements.add(el);
1004
+ }
1005
+ }
1006
+ }
1007
+ return states;
1008
+ }
1009
+ function drainProjectionStateEvents(watcher) {
1010
+ const events = [];
1011
+ for (const element of watcher.scrolledElements) {
1012
+ const isDocumentScroll = element === watcher.root.ownerDocument.scrollingElement || element === watcher.root.ownerDocument.documentElement;
1013
+ events.push({
1014
+ element: isDocumentScroll ? watcher.root : element,
1015
+ eventKind: "scroll"
1016
+ });
1017
+ }
1018
+ for (const [element, eventKind] of watcher.projectionFormEvents) {
1019
+ events.push({ element, eventKind });
1020
+ }
1021
+ watcher.scrolledElements.clear();
1022
+ watcher.changedFormElements.clear();
1023
+ watcher.projectionFormEvents.clear();
1024
+ watcher.stateRecordCount = 0;
1025
+ return events;
1026
+ }
1027
+ function hasPendingStateChanges(watcher) {
1028
+ return watcher.scrolledElements.size > 0 || watcher.changedFormElements.size > 0;
1029
+ }
1030
+
1031
+ // ../../modules/iframe-projection/html/watch-portal.ts
1032
+ var portalIdCounter = 0;
1033
+ var PORTAL_ID_ATTR = "data-projection-portal-id";
1034
+ function getOrAssignPortalId(element) {
1035
+ const existing = element.getAttribute(PORTAL_ID_ATTR);
1036
+ if (existing) return existing;
1037
+ const id2 = `portal-${++portalIdCounter}`;
1038
+ element.setAttribute(PORTAL_ID_ATTR, id2);
1039
+ return id2;
1040
+ }
1041
+ function watchPortal(element, onTrigger, coordinateRoot) {
1042
+ const id2 = getOrAssignPortalId(element);
1043
+ const domWatcher = watchDom(element, onTrigger);
1044
+ const stateWatcher = watchState(element, onTrigger);
1045
+ return {
1046
+ id: id2,
1047
+ element,
1048
+ hasPendingChanges() {
1049
+ return hasPendingMutations(domWatcher) || hasPendingStateChanges(stateWatcher);
1050
+ },
1051
+ pendingRecordCount() {
1052
+ return domWatcher.mutationRecordCount + stateWatcher.stateRecordCount;
1053
+ },
1054
+ takePendingDomRecords: () => domWatcher.takePendingRecords(),
1055
+ clearPendingChanges() {
1056
+ return {
1057
+ dom: drainProjectionDomMutations(domWatcher),
1058
+ state: drainProjectionStateEvents(stateWatcher)
1059
+ };
1060
+ },
1061
+ flush(isInitial = false) {
1062
+ const hasDomChanges = hasPendingMutations(domWatcher);
1063
+ const hasStateChanges = hasPendingStateChanges(stateWatcher);
1064
+ if (!isInitial && !hasDomChanges && !hasStateChanges) {
1065
+ return null;
1066
+ }
1067
+ let targetElement = element;
1068
+ if (!isInitial && hasDomChanges) {
1069
+ const lca = flushDomWatcher(domWatcher);
1070
+ if (lca && element.contains(lca)) {
1071
+ targetElement = lca;
1072
+ }
1073
+ } else {
1074
+ flushDomWatcher(domWatcher);
1075
+ }
1076
+ const states = flushStateWatcher(stateWatcher);
1077
+ const selector = generateSelector(targetElement, element);
1078
+ const html = removeScriptTags(targetElement.outerHTML);
1079
+ const coordinateSpace = coordinateRoot ? capturePortalCoordinateSpace(coordinateRoot, element) : void 0;
1080
+ return {
1081
+ id: id2,
1082
+ selector,
1083
+ html,
1084
+ states,
1085
+ ...coordinateSpace && { coordinateSpace }
1086
+ };
1087
+ },
1088
+ resampleCoordinates() {
1089
+ const coordinateSpace = coordinateRoot ? capturePortalCoordinateSpace(coordinateRoot, element) : void 0;
1090
+ if (!coordinateSpace) return null;
1091
+ return {
1092
+ id: id2,
1093
+ selector: "",
1094
+ html: "",
1095
+ states: [],
1096
+ coordinateSpace,
1097
+ coordinatesOnly: true
1098
+ };
1099
+ },
1100
+ stop() {
1101
+ domWatcher.stop();
1102
+ stateWatcher.stop();
1103
+ }
1104
+ };
1105
+ }
1106
+ function capturePortalCoordinateSpace(root, portal) {
1107
+ const viewport = root.ownerDocument?.defaultView;
1108
+ if (!viewport) return void 0;
1109
+ const rect = root.getBoundingClientRect();
1110
+ return {
1111
+ origin: portal ? choosePortalCoordinateOrigin(rect, portal) : "root",
1112
+ rootViewportLeft: rect.left,
1113
+ rootViewportTop: rect.top,
1114
+ viewportWidth: viewport.innerWidth,
1115
+ viewportHeight: viewport.innerHeight
1116
+ };
1117
+ }
1118
+ function choosePortalCoordinateOrigin(rootRect, portal) {
1119
+ const portalRect = measurePortalBounds(portal);
1120
+ const localViewport = {
1121
+ left: 0,
1122
+ top: 0,
1123
+ right: rootRect.width,
1124
+ bottom: rootRect.height
1125
+ };
1126
+ const coversSourceViewport = portalRect.left <= 0 && portalRect.top <= 0 && portalRect.right >= (portal.ownerDocument.defaultView?.innerWidth ?? 0) && portalRect.bottom >= (portal.ownerDocument.defaultView?.innerHeight ?? 0);
1127
+ if (coversSourceViewport) return "viewport";
1128
+ if (rectanglesOverlap(rootRect, portalRect)) return "root";
1129
+ const directScore = visibleArea(portalRect, localViewport);
1130
+ const rebasedScore = visibleArea(
1131
+ {
1132
+ left: portalRect.left - rootRect.left,
1133
+ top: portalRect.top - rootRect.top,
1134
+ right: portalRect.right - rootRect.left,
1135
+ bottom: portalRect.bottom - rootRect.top
1136
+ },
1137
+ localViewport
1138
+ );
1139
+ if (rebasedScore > directScore) return "root";
1140
+ if (directScore > rebasedScore) return "viewport";
1141
+ return "viewport";
1142
+ }
1143
+ function measurePortalBounds(portal) {
1144
+ const ownRect = portal.getBoundingClientRect();
1145
+ if (hasArea(ownRect)) return ownRect;
1146
+ let left = Number.POSITIVE_INFINITY;
1147
+ let top = Number.POSITIVE_INFINITY;
1148
+ let right = Number.NEGATIVE_INFINITY;
1149
+ let bottom = Number.NEGATIVE_INFINITY;
1150
+ for (const descendant of Array.from(portal.querySelectorAll("*"))) {
1151
+ const rect = descendant.getBoundingClientRect();
1152
+ if (!hasArea(rect)) continue;
1153
+ left = Math.min(left, rect.left);
1154
+ top = Math.min(top, rect.top);
1155
+ right = Math.max(right, rect.right);
1156
+ bottom = Math.max(bottom, rect.bottom);
1157
+ }
1158
+ return Number.isFinite(left) ? { left, top, right, bottom } : ownRect;
1159
+ }
1160
+ function hasArea(rect) {
1161
+ return rect.right > rect.left && rect.bottom > rect.top;
1162
+ }
1163
+ function visibleArea(rect, viewport) {
1164
+ const width = Math.max(
1165
+ 0,
1166
+ Math.min(rect.right, viewport.right) - Math.max(rect.left, viewport.left)
1167
+ );
1168
+ const height = Math.max(
1169
+ 0,
1170
+ Math.min(rect.bottom, viewport.bottom) - Math.max(rect.top, viewport.top)
1171
+ );
1172
+ return width * height;
1173
+ }
1174
+ function rectanglesOverlap(a, b) {
1175
+ return a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top;
1176
+ }
1177
+
1178
+ // ../../modules/iframe-projection/combined/css-escape.ts
1179
+ function cssEscape(value) {
1180
+ return globalThis.CSS?.escape ? globalThis.CSS.escape(value) : value.replace(/["\\]/g, "\\$&");
1181
+ }
1182
+
1183
+ // ../../modules/iframe-projection/combined/projection-patch.ts
1184
+ var SOURCE_ANNOTATION_ATTRIBUTES = /* @__PURE__ */ new Set([
1185
+ "data-tempo-filepath",
1186
+ "data-tempo-position",
1187
+ "data-tempo-modifiedts",
1188
+ "data-tempo-source-version",
1189
+ // Expression facts describe the same callsite, so they travel, update and
1190
+ // are distrusted exactly like the location stamps.
1191
+ "data-tempo-expr"
1192
+ ]);
1193
+ var PROJECTION_ROOT_TARGET_ID = "$projection-root";
1194
+ function captureProjectionMutationPatch(root, mutations, options = {}) {
1195
+ const observedFiles = new ProjectionObservedFileAccumulator();
1196
+ const fallbackRegions = /* @__PURE__ */ new Set();
1197
+ const childListMutations = [];
1198
+ const characterDataTargets = [];
1199
+ const attributes = /* @__PURE__ */ new Map();
1200
+ const metadataTargets = /* @__PURE__ */ new Set();
1201
+ for (const mutation of mutations) {
1202
+ const element = mutationTargetElement(mutation.target);
1203
+ if (!element || element !== root && !root.contains(element)) continue;
1204
+ if (mutation.type === "attributes" && mutation.attributeName) {
1205
+ const isSourceMetadata = SOURCE_ANNOTATION_ATTRIBUTES.has(
1206
+ mutation.attributeName
1207
+ );
1208
+ if (isSourceMetadata) {
1209
+ metadataTargets.add(element);
1210
+ continue;
1211
+ }
1212
+ const names = attributes.get(element) ?? /* @__PURE__ */ new Set();
1213
+ names.add(mutation.attributeName);
1214
+ attributes.set(element, names);
1215
+ continue;
1216
+ }
1217
+ if (mutation.type === "characterData") {
1218
+ characterDataTargets.push(mutation.target);
1219
+ } else {
1220
+ const carriesNoChildDetail = mutation.addedNodes === void 0 && mutation.removedNodes === void 0;
1221
+ if (options.regionalChildLists || carriesNoChildDetail) {
1222
+ fallbackRegions.add(element);
1223
+ } else {
1224
+ childListMutations.push(mutation);
1225
+ }
1226
+ }
1227
+ }
1228
+ const addedElements = coalesceElements(
1229
+ childListMutations.flatMap(
1230
+ (mutation) => Array.from(mutation.addedNodes ?? []).filter(
1231
+ (node) => node instanceof Element && root.contains(node)
1232
+ )
1233
+ )
1234
+ );
1235
+ const removedElements = coalesceElements(
1236
+ childListMutations.flatMap(
1237
+ (mutation) => Array.from(mutation.removedNodes ?? []).filter(
1238
+ (node) => node instanceof Element && !root.contains(node)
1239
+ )
1240
+ )
1241
+ );
1242
+ const coveredByAddedElement = (element) => addedElements.some((added) => added === element || added.contains(element));
1243
+ const placements = [];
1244
+ const removals = [];
1245
+ const metadata = [];
1246
+ for (const removed of removedElements) {
1247
+ const targetId = readProjectionDomId(removed);
1248
+ if (targetId) removals.push({ kind: "remove", targetId });
1249
+ }
1250
+ addedElements.sort(reverseDocumentOrder);
1251
+ for (const added of addedElements) {
1252
+ if (added.tagName.toLowerCase() === "script") continue;
1253
+ const parent = added.parentElement;
1254
+ if (!parent || parent !== root && !root.contains(parent)) continue;
1255
+ const parentId = projectionTargetId(root, parent);
1256
+ const targetId = ensureProjectionDomId(added);
1257
+ if (!parentId || !targetId) {
1258
+ fallbackRegions.add(parent);
1259
+ continue;
1260
+ }
1261
+ const before = added.nextElementSibling;
1262
+ const beforeId = before ? ensureProjectionDomId(before) : null;
1263
+ if (before && !beforeId) {
1264
+ fallbackRegions.add(parent);
1265
+ continue;
1266
+ }
1267
+ const captured = capturePlacedElementWithoutAnnotations(
1268
+ added,
1269
+ observedFiles
1270
+ );
1271
+ placements.push({
1272
+ kind: "place",
1273
+ parentId,
1274
+ targetId,
1275
+ beforeId,
1276
+ html: captured.html,
1277
+ ancestorIds: captureProjectionAncestorIds(root, added)
1278
+ });
1279
+ }
1280
+ for (const target of characterDataTargets) {
1281
+ const parent = target.parentElement;
1282
+ if (!parent || coveredByAddedElement(parent)) continue;
1283
+ const targetId = ensureProjectionDomId(target, root);
1284
+ if (targetId)
1285
+ metadata.push({
1286
+ targetId,
1287
+ targetFiberId: targetId,
1288
+ content: target.textContent ?? "",
1289
+ ancestorIds: [
1290
+ ensureProjectionDomId(parent, root),
1291
+ ...captureProjectionAncestorIds(root, parent)
1292
+ ]
1293
+ });
1294
+ }
1295
+ for (const mutation of childListMutations) {
1296
+ const nodes = [
1297
+ ...mutation.addedNodes ?? [],
1298
+ ...mutation.removedNodes ?? []
1299
+ ];
1300
+ if (nodes.some((node) => !(node instanceof Element))) {
1301
+ const parent = mutation.target instanceof Element ? mutation.target : mutation.target.parentElement;
1302
+ if (parent && !coveredByAddedElement(parent)) fallbackRegions.add(parent);
1303
+ }
1304
+ }
1305
+ for (const element of [...attributes.keys()]) {
1306
+ if (projectionTargetId(root, element)) continue;
1307
+ attributes.delete(element);
1308
+ fallbackRegions.add(widenToIdentifiableRegion(root, element));
1309
+ }
1310
+ for (const region of [...fallbackRegions]) {
1311
+ if (projectionTargetId(root, region)) continue;
1312
+ fallbackRegions.delete(region);
1313
+ fallbackRegions.add(widenToIdentifiableRegion(root, region));
1314
+ }
1315
+ const survivingRegions = coalesceRegions(fallbackRegions);
1316
+ const isInsideRegion = (element) => survivingRegions.some(
1317
+ (region) => region !== element && region.contains(element)
1318
+ );
1319
+ for (const element of attributes.keys()) {
1320
+ if (isInsideRegion(element) || coveredByAddedElement(element)) {
1321
+ attributes.delete(element);
1322
+ }
1323
+ }
1324
+ const regionCaptures = /* @__PURE__ */ new Map();
1325
+ for (const region of survivingRegions) {
1326
+ const captured = captureRegionWithoutAnnotations(region, observedFiles);
1327
+ regionCaptures.set(region, captured);
1328
+ }
1329
+ const allTargets = /* @__PURE__ */ new Set([
1330
+ ...survivingRegions,
1331
+ ...attributes.keys()
1332
+ ]);
1333
+ const ids = /* @__PURE__ */ new Map();
1334
+ for (const element of allTargets) {
1335
+ const id2 = projectionTargetId(root, element);
1336
+ if (id2) ids.set(element, id2);
1337
+ }
1338
+ const pointerEventsNone = /* @__PURE__ */ new Set();
1339
+ for (const element of addedElements) {
1340
+ if (element.tagName.toLowerCase() === "script" || survivingRegions.some(
1341
+ (region) => region === element || region.contains(element)
1342
+ ))
1343
+ continue;
1344
+ for (const target of projectedElements(element)) {
1345
+ const id2 = target.getAttribute(DOM_ID_ATTR);
1346
+ if (id2 && target.ownerDocument.defaultView?.getComputedStyle(target).pointerEvents === "none") {
1347
+ pointerEventsNone.add(id2);
1348
+ }
1349
+ }
1350
+ }
1351
+ for (const element of attributes.keys()) {
1352
+ const id2 = ids.get(element);
1353
+ if (id2 && element.ownerDocument.defaultView?.getComputedStyle(element).pointerEvents === "none") {
1354
+ pointerEventsNone.add(id2);
1355
+ }
1356
+ }
1357
+ return {
1358
+ ...metadata.length ? { layers: { metadata } } : {},
1359
+ ...pointerEventsNone.size > 0 ? { pointerEventsNone: [...pointerEventsNone] } : {},
1360
+ dom: [
1361
+ ...removals.filter(
1362
+ (change) => !survivingRegions.some(
1363
+ (region) => region.querySelector(
1364
+ `[${DOM_ID_ATTR}="${cssEscape(change.targetId)}"]`
1365
+ )
1366
+ )
1367
+ ),
1368
+ ...placements.filter(
1369
+ (change) => !isCoveredTargetId(root, survivingRegions, change.targetId)
1370
+ ),
1371
+ ...survivingRegions.map(
1372
+ (element) => ({
1373
+ kind: "children",
1374
+ targetId: ids.get(element),
1375
+ html: regionCaptures.get(element).html,
1376
+ ancestorIds: captureProjectionAncestorIds(root, element)
1377
+ })
1378
+ ),
1379
+ ...Array.from(
1380
+ attributes,
1381
+ ([element, names]) => ({
1382
+ kind: "attributes",
1383
+ targetId: ids.get(element),
1384
+ attributes: captureFinalAttributes(element, names),
1385
+ ancestorIds: captureProjectionAncestorIds(root, element)
1386
+ })
1387
+ )
1388
+ ],
1389
+ localMetadataTargets: Array.from(metadataTargets),
1390
+ observedFiles: observedFiles.snapshot()
1391
+ };
1392
+ }
1393
+ function captureProjectionStatePatch(root, element, eventKind) {
1394
+ const targetId = ensureProjectionDomId(element);
1395
+ if (!targetId) return null;
1396
+ const ancestorIds = captureProjectionAncestorIds(root, element);
1397
+ if (eventKind === "scroll") {
1398
+ return {
1399
+ targetId,
1400
+ kind: "scroll",
1401
+ scrollTop: element.scrollTop,
1402
+ scrollLeft: element.scrollLeft,
1403
+ ancestorIds
1404
+ };
1405
+ }
1406
+ if (element instanceof HTMLInputElement) {
1407
+ if (element.type === "checkbox" || element.type === "radio") {
1408
+ return {
1409
+ targetId,
1410
+ kind: "checked",
1411
+ checked: element.checked,
1412
+ ancestorIds
1413
+ };
1414
+ }
1415
+ return {
1416
+ targetId,
1417
+ kind: "value",
1418
+ value: element.value,
1419
+ selectionStart: element.selectionStart,
1420
+ selectionEnd: element.selectionEnd,
1421
+ ancestorIds
1422
+ };
1423
+ }
1424
+ if (element instanceof HTMLTextAreaElement) {
1425
+ return {
1426
+ targetId,
1427
+ kind: "value",
1428
+ value: element.value,
1429
+ selectionStart: element.selectionStart,
1430
+ selectionEnd: element.selectionEnd,
1431
+ ancestorIds
1432
+ };
1433
+ }
1434
+ if (element instanceof HTMLSelectElement) {
1435
+ const selectedIndices = [];
1436
+ for (let index = 0; index < element.options.length; index += 1) {
1437
+ if (element.options[index]?.selected) selectedIndices.push(index);
1438
+ }
1439
+ return { targetId, kind: "selected", selectedIndices, ancestorIds };
1440
+ }
1441
+ return null;
1442
+ }
1443
+ function captureProjectionPortalRegion(element, removed = false, coordinateRoot) {
1444
+ const portalId = element.getAttribute(PORTAL_ID_ATTR);
1445
+ if (!portalId) return null;
1446
+ if (removed) {
1447
+ return {
1448
+ portal: { kind: "remove", portalId },
1449
+ observedFiles: {}
1450
+ };
1451
+ }
1452
+ for (const live of projectedElements(element)) ensureProjectionDomId(live);
1453
+ const clone = element.cloneNode(true);
1454
+ syncProjectionDomIdsToClone(element, clone);
1455
+ for (const script of clone.querySelectorAll("script")) script.remove();
1456
+ const observedFiles = new ProjectionObservedFileAccumulator();
1457
+ stripSourceAnnotations(clone, observedFiles, true);
1458
+ const coordinateSpace = coordinateRoot ? capturePortalCoordinateSpace(coordinateRoot, element) : void 0;
1459
+ return {
1460
+ portal: {
1461
+ kind: "replace",
1462
+ portalId,
1463
+ html: removeScriptTags(clone.outerHTML),
1464
+ ...coordinateSpace && { coordinateSpace }
1465
+ },
1466
+ observedFiles: observedFiles.snapshot()
1467
+ };
1468
+ }
1469
+ function captureProjectionPortalCoordinates(root, element) {
1470
+ const portalId = element.getAttribute(PORTAL_ID_ATTR);
1471
+ const coordinateSpace = capturePortalCoordinateSpace(root, element);
1472
+ if (!portalId || !coordinateSpace) return null;
1473
+ return {
1474
+ kind: "replace",
1475
+ portalId,
1476
+ html: "",
1477
+ coordinateSpace,
1478
+ coordinatesOnly: true
1479
+ };
1480
+ }
1481
+ function mutationTargetElement(target) {
1482
+ return target instanceof Element ? target : target.parentElement;
1483
+ }
1484
+ function projectionTargetId(root, element) {
1485
+ return element === root ? PROJECTION_ROOT_TARGET_ID : ensureProjectionDomId(element);
1486
+ }
1487
+ function coalesceElements(elements) {
1488
+ const unique = Array.from(new Set(elements));
1489
+ return unique.filter(
1490
+ (candidate) => !unique.some((other) => other !== candidate && other.contains(candidate))
1491
+ );
1492
+ }
1493
+ function reverseDocumentOrder(left, right) {
1494
+ if (left === right) return 0;
1495
+ const position = left.compareDocumentPosition(right);
1496
+ if (position & 4) return 1;
1497
+ if (position & 2) return -1;
1498
+ return 0;
1499
+ }
1500
+ function capturePlacedElementWithoutAnnotations(element, observedFiles) {
1501
+ for (const live of projectedElements(element)) ensureProjectionDomId(live);
1502
+ const clone = element.cloneNode(true);
1503
+ syncProjectionDomIdsToClone(element, clone);
1504
+ if (clone.tagName.toLowerCase() === "script") {
1505
+ return { html: "" };
1506
+ }
1507
+ for (const script of clone.querySelectorAll("script")) script.remove();
1508
+ stripSourceAnnotations(clone, observedFiles, true);
1509
+ return { html: clone.outerHTML };
1510
+ }
1511
+ function isCoveredTargetId(root, regions, targetId) {
1512
+ const target = targetId === PROJECTION_ROOT_TARGET_ID ? root : root.querySelector(`[${DOM_ID_ATTR}="${cssEscape(targetId)}"]`);
1513
+ return target ? regions.some((region) => region === target || region.contains(target)) : false;
1514
+ }
1515
+ function coalesceRegions(regions) {
1516
+ const candidates = Array.from(regions);
1517
+ return candidates.filter(
1518
+ (candidate) => !candidates.some(
1519
+ (other) => other !== candidate && other.contains(candidate)
1520
+ )
1521
+ );
1522
+ }
1523
+ function captureFinalAttributes(element, names) {
1524
+ return Object.fromEntries(
1525
+ Array.from(names, (name) => [name, element.getAttribute(name)])
1526
+ );
1527
+ }
1528
+ function stripSourceAnnotations(cloneRoot, observedFiles, includeRoot) {
1529
+ for (const registry of cloneRoot.querySelectorAll(
1530
+ "template[data-tempo-svelte-source-registry]"
1531
+ ))
1532
+ registry.remove();
1533
+ const hostDomIds = /* @__PURE__ */ new Set();
1534
+ const walker = cloneRoot.ownerDocument.createTreeWalker(
1535
+ cloneRoot,
1536
+ NodeFilter.SHOW_ELEMENT
1537
+ );
1538
+ let copy = includeRoot ? cloneRoot : walker.nextNode();
1539
+ while (copy) {
1540
+ observedFiles.add(
1541
+ copy.getAttribute("data-tempo-filepath"),
1542
+ copy.getAttribute("data-tempo-modifiedts"),
1543
+ copy.getAttribute("data-tempo-source-version")
1544
+ );
1545
+ const domId = copy.getAttribute(DOM_ID_ATTR);
1546
+ if (domId) hostDomIds.add(domId);
1547
+ for (const name of SOURCE_ANNOTATION_ATTRIBUTES) copy.removeAttribute(name);
1548
+ copy = walker.nextNode();
1549
+ }
1550
+ return hostDomIds;
1551
+ }
1552
+ function captureRegionWithoutAnnotations(element, observedFiles) {
1553
+ for (const live of projectedElements(element)) ensureProjectionDomId(live);
1554
+ const clone = element.cloneNode(true);
1555
+ syncProjectionDomIdsToClone(element, clone, false);
1556
+ for (const script of clone.querySelectorAll("script")) script.remove();
1557
+ stripSourceAnnotations(clone, observedFiles, false);
1558
+ return { html: clone.innerHTML };
1559
+ }
1560
+ function widenToIdentifiableRegion(root, element) {
1561
+ for (let current = element; current && current !== root; current = current.parentElement) {
1562
+ if (readProjectionDomId(current)) return current;
1563
+ }
1564
+ return root;
1565
+ }
1566
+ function captureProjectionAncestorIds(root, element) {
1567
+ if (element === root) return [];
1568
+ const ids = [];
1569
+ for (let current = element.parentElement; current && current !== root; current = current.parentElement) {
1570
+ const id2 = readProjectionDomId(current);
1571
+ if (id2) {
1572
+ ensureProjectionDomId(current);
1573
+ ids.push(id2);
1574
+ }
1575
+ }
1576
+ return ids;
1577
+ }
1578
+
1579
+ // ../../modules/iframe-projection/combined/projection-dom-layers.ts
1580
+ var DOM_LAYER_ROOT_ID = "dom:$projection-root";
1581
+ var DOM_LAYER_FIBER_PREFIX = "dom:";
1582
+ function createProjectionDomLayerSerializer() {
1583
+ let nextElementId = 1;
1584
+ const elementIds = /* @__PURE__ */ new WeakMap();
1585
+ const domIdOwners = /* @__PURE__ */ new Map();
1586
+ const identity = {
1587
+ id: /* @__PURE__ */ new WeakMap(),
1588
+ layerIdForElement(_root, element) {
1589
+ const existing = elementIds.get(element);
1590
+ if (existing) return existing;
1591
+ const id2 = `${DOM_LAYER_FIBER_PREFIX}element:${nextElementId++}`;
1592
+ elementIds.set(element, id2);
1593
+ return id2;
1594
+ },
1595
+ bindableDomIdForElement(root, element) {
1596
+ const domId = ensureProjectionDomId(element);
1597
+ if (!domId) return null;
1598
+ const owner = domIdOwners.get(domId);
1599
+ if (owner === element) return domId;
1600
+ if (!owner || !root.contains(owner)) {
1601
+ domIdOwners.set(domId, element);
1602
+ return domId;
1603
+ }
1604
+ return null;
1605
+ }
1606
+ };
1607
+ return {
1608
+ serializeRoot(root, observedFiles = {}) {
1609
+ return serializeProjectionDomLayerRootWithIdentity(
1610
+ root,
1611
+ observedFiles,
1612
+ identity
1613
+ );
1614
+ },
1615
+ capturePatch(root, targets, observedFiles = {}) {
1616
+ return captureProjectionDomLayerPatchFromTargets(
1617
+ root,
1618
+ targets,
1619
+ observedFiles,
1620
+ identity
1621
+ );
1622
+ }
1623
+ };
1624
+ }
1625
+ var dataDomLayerIdentity = {
1626
+ id: /* @__PURE__ */ new WeakMap(),
1627
+ layerIdForElement: domLayerIdForElement,
1628
+ bindableDomIdForElement: (_root, element) => ensureProjectionDomId(element)
1629
+ };
1630
+ function serializeProjectionDomLayerRootWithIdentity(root, observedFiles, identity) {
1631
+ const observed = new ProjectionObservedFileAccumulator();
1632
+ observed.merge(observedFiles);
1633
+ const tree = serializeDomLayerRootNode(root, identity, observed);
1634
+ return {
1635
+ semantic: { kind: "layers", tree },
1636
+ observedFiles: observed.snapshot()
1637
+ };
1638
+ }
1639
+ function captureProjectionDomLayerPatchFromTargets(root, targets, observedFiles, identity) {
1640
+ const structuralTargets = new Set(
1641
+ targets.structural.filter(
1642
+ (target) => target === root || root.contains(target)
1643
+ )
1644
+ );
1645
+ const metadataTargets = new Set(
1646
+ targets.metadata.filter(
1647
+ (target) => target === root || root.contains(target)
1648
+ )
1649
+ );
1650
+ const regions = Array.from(structuralTargets).filter(
1651
+ (candidate) => !Array.from(structuralTargets).some(
1652
+ (other) => other !== candidate && other.contains(candidate)
1653
+ )
1654
+ );
1655
+ const regionSnapshots = regions.map(
1656
+ (target) => {
1657
+ const observed = new ProjectionObservedFileAccumulator();
1658
+ observed.merge(observedFiles);
1659
+ const tree = target === root ? serializeDomLayerRootNode(root, identity, observed) : serializeDomLayerNode(root, target, identity, observed);
1660
+ return {
1661
+ targetFiberId: layerIdForTarget(root, target, identity),
1662
+ targetId: id(root, target, identity),
1663
+ tree,
1664
+ observedFiles: observed.snapshot()
1665
+ };
1666
+ }
1667
+ );
1668
+ const metadataSnapshots = [];
1669
+ for (const target of metadataTargets) {
1670
+ if (target !== root && regions.some((region) => region === root || region.contains(target))) {
1671
+ continue;
1672
+ }
1673
+ metadataSnapshots.push({
1674
+ targetFiberId: layerIdForTarget(root, target, identity),
1675
+ targetId: id(root, target, identity),
1676
+ props: captureProjectionDomLayerProps(target)
1677
+ });
1678
+ }
1679
+ if (regionSnapshots.length === 0 && metadataSnapshots.length === 0) {
1680
+ return void 0;
1681
+ }
1682
+ return {
1683
+ ...regionSnapshots.length > 0 ? { regions: regionSnapshots } : {},
1684
+ ...metadataSnapshots.length > 0 ? { metadata: metadataSnapshots } : {}
1685
+ };
1686
+ }
1687
+ function serializeDomLayerRootNode(root, identity, observedFiles, children) {
1688
+ const name = root.tagName.toLowerCase();
1689
+ const stamps = rootSourceStamps(root);
1690
+ observedFiles?.addLayerProps(stamps);
1691
+ return {
1692
+ kind: "fragment",
1693
+ runtime: "dom",
1694
+ id: id(root, root, identity),
1695
+ key: null,
1696
+ name,
1697
+ domId: null,
1698
+ elementTag: null,
1699
+ ...stamps ? { props: stamps } : {},
1700
+ source: {
1701
+ kind: "react-fiber",
1702
+ fiber: {
1703
+ tag: FiberTag.HostRoot,
1704
+ name,
1705
+ id: DOM_LAYER_ROOT_ID
1706
+ }
1707
+ },
1708
+ children: Array.from(root.childNodes).filter(
1709
+ (child) => !(child instanceof Element) || child.localName !== "script" && !child.hasAttribute(PROJECTION_ROOT_ATTRIBUTE)
1710
+ ).flatMap(
1711
+ (child) => serializeDomLayerNode(root, child, identity, observedFiles) ?? []
1712
+ )
1713
+ };
1714
+ }
1715
+ function withoutSourceStamps(props) {
1716
+ return Object.fromEntries(
1717
+ Object.entries(props ?? {}).filter(
1718
+ ([key]) => !SOURCE_ANNOTATION_ATTRIBUTES.has(key)
1719
+ )
1720
+ );
1721
+ }
1722
+ function firstStampCarrier(root, element) {
1723
+ const filepath = element.getAttribute("data-tempo-filepath");
1724
+ const position = element.getAttribute("data-tempo-position");
1725
+ if (filepath === null || position === null) return true;
1726
+ const quote = (value) => `"${value.replace(/["\\]/g, "\\$&")}"`;
1727
+ const selector = `[data-tempo-filepath=${quote(filepath)}][data-tempo-position=${quote(position)}]`;
1728
+ return root.querySelector(selector) === element;
1729
+ }
1730
+ function rootSourceStamps(root) {
1731
+ const stamps = {};
1732
+ for (const name of SOURCE_ANNOTATION_ATTRIBUTES) {
1733
+ const value = root.getAttribute(name);
1734
+ if (value === null) continue;
1735
+ if (name === "data-tempo-position" || name === "data-tempo-modifiedts") {
1736
+ const numeric = Number(value);
1737
+ if (Number.isFinite(numeric)) stamps[name] = numeric;
1738
+ } else stamps[name] = value;
1739
+ }
1740
+ return Object.keys(stamps).length ? stamps : void 0;
1741
+ }
1742
+ function serializeDomLayerNode(root, element, identity = dataDomLayerIdentity, observedFiles, children) {
1743
+ if (element.nodeType === 3 || element.nodeType === 8) {
1744
+ const kind = element.nodeType === 3 ? "text" : "comment";
1745
+ const domId2 = ensureProjectionDomId(element, root ?? void 0);
1746
+ if (domId2 === null) return null;
1747
+ return {
1748
+ kind,
1749
+ id: domId2,
1750
+ content: element.textContent ?? ""
1751
+ };
1752
+ }
1753
+ if (!(element instanceof Element))
1754
+ throw new Error("Invalid projection child");
1755
+ const domId = identity.bindableDomIdForElement(root ?? element, element);
1756
+ const name = element.tagName.toLowerCase();
1757
+ const props = captureProjectionDomLayerProps(element, observedFiles);
1758
+ const hostProps = root && firstStampCarrier(root, element) ? props : withoutSourceStamps(props);
1759
+ return {
1760
+ kind: "host",
1761
+ runtime: "dom",
1762
+ id: domId ?? id(root ?? element, element, identity),
1763
+ key: null,
1764
+ name,
1765
+ domId,
1766
+ elementTag: name,
1767
+ props: hostProps && Object.keys(hostProps).length ? hostProps : void 0,
1768
+ source: {
1769
+ kind: "react-fiber",
1770
+ fiber: {
1771
+ tag: FiberTag.HostComponent,
1772
+ name,
1773
+ id: identity.layerIdForElement(root ?? element, element)
1774
+ }
1775
+ },
1776
+ // Another root's element ends this root's tree, as the React lane's
1777
+ // serializer does: what it holds is that root's to publish.
1778
+ children: children ?? Array.from(element.childNodes).filter(
1779
+ (child) => !(child instanceof Element) || child.localName !== "script" && !child.hasAttribute(PROJECTION_ROOT_ATTRIBUTE)
1780
+ ).flatMap(
1781
+ (child) => serializeDomLayerNode(root, child, identity, observedFiles) ?? []
1782
+ )
1783
+ };
1784
+ }
1785
+ function id(root, element, identity) {
1786
+ const domId = element === root ? null : identity.bindableDomIdForElement(root, element);
1787
+ if (domId !== null) return domId;
1788
+ const existing = identity.id.get(element);
1789
+ if (existing) return existing;
1790
+ const value = nextProjectionId();
1791
+ identity.id.set(element, value);
1792
+ return value;
1793
+ }
1794
+ function layerIdForTarget(root, target, identity) {
1795
+ if (target === root) return DOM_LAYER_ROOT_ID;
1796
+ return identity.layerIdForElement(root, target);
1797
+ }
1798
+ function projectionDomLayerId(domId) {
1799
+ return `${DOM_LAYER_FIBER_PREFIX}${domId}`;
1800
+ }
1801
+ function domLayerIdForElement(root, element) {
1802
+ const domId = ensureProjectionDomId(element);
1803
+ if (domId) return projectionDomLayerId(domId);
1804
+ const path = [];
1805
+ let current = element;
1806
+ while (current && current !== root) {
1807
+ const parent = current.parentElement;
1808
+ if (!parent) break;
1809
+ path.push(Array.from(parent.children).indexOf(current));
1810
+ current = parent;
1811
+ }
1812
+ return `${DOM_LAYER_FIBER_PREFIX}path:${path.reverse().join(".")}`;
1813
+ }
1814
+ function captureProjectionDomLayerProps(element, observedFiles) {
1815
+ const props = {};
1816
+ const locked = element.getAttribute("data-tempo-locked");
1817
+ if (locked === "true" || locked === "") props["data-tempo-locked"] = true;
1818
+ else if (locked === "false") props["data-tempo-locked"] = false;
1819
+ const layoutMode = layoutModeOf(getComputedStyle(element));
1820
+ if (layoutMode) props.layoutMode = layoutMode;
1821
+ const className = element.getAttribute("class");
1822
+ if (className) props.className = className;
1823
+ const style = parseInlineStyle(element.getAttribute("style"));
1824
+ if (style) props.style = style;
1825
+ for (const name of SOURCE_ANNOTATION_ATTRIBUTES) {
1826
+ const value = element.getAttribute(name);
1827
+ if (value === null) continue;
1828
+ if (name === "data-tempo-position" || name === "data-tempo-modifiedts") {
1829
+ const numeric = Number(value);
1830
+ if (Number.isFinite(numeric)) props[name] = numeric;
1831
+ } else {
1832
+ props[name] = value;
1833
+ }
1834
+ }
1835
+ for (const name of [
1836
+ "data-tempo-supports-style",
1837
+ "data-tempo-supports-classname",
1838
+ "data-tempo-supports-children"
1839
+ ]) {
1840
+ const value = element.getAttribute(name);
1841
+ if (value === "true" || value === "false") props[name] = value === "true";
1842
+ }
1843
+ for (const name of ["data-tempo-storyboard-root", "data-tempo-hide-fiber"]) {
1844
+ const value = element.getAttribute(name);
1845
+ if (value !== null) props[name] = value !== "false";
1846
+ }
1847
+ observedFiles?.addLayerProps(props);
1848
+ return Object.keys(props).length > 0 ? props : void 0;
1849
+ }
1850
+ function parseInlineStyle(value) {
1851
+ if (!value) return void 0;
1852
+ const style = {};
1853
+ for (const declaration of value.split(";")) {
1854
+ const separator = declaration.indexOf(":");
1855
+ if (separator < 0) continue;
1856
+ const property = declaration.slice(0, separator).trim();
1857
+ const propertyValue = declaration.slice(separator + 1).trim();
1858
+ if (property && propertyValue) style[property] = propertyValue;
1859
+ }
1860
+ return Object.keys(style).length > 0 ? style : void 0;
1861
+ }
1862
+
1863
+ // ../../modules/iframe-projection/combined/projection-layer-snapshot.ts
1864
+ function layoutModeOf(style) {
1865
+ if (/grid/.test(style.display)) return "grid";
1866
+ if (!/flex/.test(style.display)) return void 0;
1867
+ return /^column/.test(style.flexDirection) ? "flex-column" : "flex-row";
1868
+ }
1869
+ var PROJECTION_SCOPE_TARGET = "$projection-scope";
1870
+ function projectionLayerRoots(snapshot) {
1871
+ const semantic = snapshot.semantic;
1872
+ return semantic.kind === "scope" ? semantic.fragment.children : semantic.kind === "layers" && semantic.tree ? [semantic.tree] : [];
1873
+ }
1874
+ var COMPONENT_TAGS = /* @__PURE__ */ new Set([
1875
+ FiberTag.FunctionComponent,
1876
+ FiberTag.ClassComponent,
1877
+ FiberTag.ForwardRef,
1878
+ FiberTag.MemoComponent,
1879
+ FiberTag.SimpleMemoComponent,
1880
+ FiberTag.LazyComponent
1881
+ ]);
1882
+ function createProjectionLayerSerializer(watchedRoot, contentsScope = false, includeRoot = false) {
1883
+ const fiberIds = /* @__PURE__ */ new WeakMap();
1884
+ const portalNodeIds = /* @__PURE__ */ new WeakMap();
1885
+ let publishedPortalAncestors = /* @__PURE__ */ new WeakSet();
1886
+ let publishedTargetAncestors = /* @__PURE__ */ new Set();
1887
+ let observedRoot = null;
1888
+ const physicalAggregations = /* @__PURE__ */ new WeakSet();
1889
+ const aggregatesPhysicalTargets = (fiber) => physicalAggregations.has(fiber) || fiber.alternate !== null && physicalAggregations.has(fiber.alternate);
1890
+ const portalNodeId = (node) => {
1891
+ const known = portalNodeIds.get(node);
1892
+ if (known) return known;
1893
+ const value = nextProjectionId();
1894
+ portalNodeIds.set(node, value);
1895
+ return value;
1896
+ };
1897
+ const ids = /* @__PURE__ */ new WeakMap();
1898
+ function id2(fiber) {
1899
+ const node = fiber.tag === FiberTag.HostText && fiber.stateNode instanceof Node ? fiber.stateNode : fiber.tag === FiberTag.HostComponent ? getDomElement(fiber) : null;
1900
+ const domId = node ? ensureProjectionDomId(node, watchedRoot) : null;
1901
+ if (domId !== null) return domId;
1902
+ const direct = ids.get(fiber);
1903
+ if (direct) return direct;
1904
+ const alternate = fiber.alternate ? ids.get(fiber.alternate) : null;
1905
+ if (alternate) {
1906
+ ids.set(fiber, alternate);
1907
+ return alternate;
1908
+ }
1909
+ const value = nextProjectionId();
1910
+ ids.set(fiber, value);
1911
+ if (fiber.alternate) ids.set(fiber.alternate, value);
1912
+ return value;
1913
+ }
1914
+ const fiberId = (fiber) => {
1915
+ const direct = fiberIds.get(fiber);
1916
+ if (direct) return direct;
1917
+ const alternate = fiber.alternate ? fiberIds.get(fiber.alternate) : null;
1918
+ if (alternate) {
1919
+ fiberIds.set(fiber, alternate);
1920
+ return alternate;
1921
+ }
1922
+ const id3 = nextProjectionId();
1923
+ fiberIds.set(fiber, id3);
1924
+ if (fiber.alternate) fiberIds.set(fiber.alternate, id3);
1925
+ return id3;
1926
+ };
1927
+ const knownFiberId = (fiber) => fiberIds.get(fiber) ?? (fiber.alternate ? fiberIds.get(fiber.alternate) : void 0) ?? null;
1928
+ const serialize = (root, observation = false) => {
1929
+ const observedFiles = new ProjectionObservedFileAccumulator();
1930
+ let fiberNodesVisited = 0;
1931
+ let semanticNodesSerialized = 0;
1932
+ const portalOwners = /* @__PURE__ */ new Map();
1933
+ const portalTargets = /* @__PURE__ */ new Map();
1934
+ const emittedNodes = /* @__PURE__ */ new Set();
1935
+ const collectOwnership = (fiber, portal) => {
1936
+ if (fiber !== root && isProjectionRootFiber(fiber)) return;
1937
+ fiberNodesVisited += 1;
1938
+ if (fiber.tag === FiberTag.HostPortal) {
1939
+ portal = fiber;
1940
+ const target = fiber.stateNode?.containerInfo;
1941
+ if (target instanceof Element) {
1942
+ const entries = portalTargets.get(target) ?? [];
1943
+ entries.push(fiber);
1944
+ portalTargets.set(target, entries);
1945
+ }
1946
+ }
1947
+ if (portal) portalOwners.set(fiber, portal);
1948
+ for (let child = fiber.child; child; child = child.sibling)
1949
+ collectOwnership(child, portal);
1950
+ };
1951
+ if (root) collectOwnership(root);
1952
+ else if (watchedRoot) {
1953
+ for (const committed of getCommittedFiberRoots()) {
1954
+ const container = committed.containerInfo;
1955
+ if (!(container instanceof Element) || !watchedRoot.contains(container))
1956
+ continue;
1957
+ let boundary = container;
1958
+ while (boundary && boundary !== watchedRoot && !boundary.hasAttribute(PROJECTION_ROOT_ATTRIBUTE))
1959
+ boundary = boundary.parentElement;
1960
+ if (boundary === watchedRoot) collectOwnership(committed.current);
1961
+ }
1962
+ }
1963
+ if (observation) observedRoot = root;
1964
+ if (root === observedRoot || root?.alternate === observedRoot || observedRoot?.alternate === root) {
1965
+ publishedPortalAncestors = /* @__PURE__ */ new WeakSet();
1966
+ for (const portals of portalTargets.values())
1967
+ for (const portal of portals)
1968
+ for (let ancestor = portal; ancestor; ancestor = ancestor.return)
1969
+ publishedPortalAncestors.add(ancestor);
1970
+ publishedTargetAncestors = /* @__PURE__ */ new Set();
1971
+ for (const target of portalTargets.keys())
1972
+ for (let node = target; node; node = node.parentNode)
1973
+ publishedTargetAncestors.add(node);
1974
+ }
1975
+ const portalOf = (fiber) => {
1976
+ const known = portalOwners.get(fiber);
1977
+ if (known) return known;
1978
+ for (let owner = fiber.return; owner; owner = owner.return) {
1979
+ if (owner.tag === FiberTag.HostPortal) return owner;
1980
+ if (isProjectionRootFiber(owner)) break;
1981
+ }
1982
+ };
1983
+ const portalRuntime = (fiber, node) => {
1984
+ const portal = portalOf(fiber);
1985
+ return portal ? {
1986
+ ...node ? { nodeId: portalNodeId(node) } : {},
1987
+ fiberId: fiberId(fiber),
1988
+ ownerFiberId: fiberId(portal.return ?? portal)
1989
+ } : void 0;
1990
+ };
1991
+ const domChildren = (element, parent, allowed, inheritedPortal) => {
1992
+ const physicalPortal = (parent && portalOf(parent)) ?? inheritedPortal;
1993
+ const annotations = /* @__PURE__ */ new Map();
1994
+ const extras = [];
1995
+ const pending = [];
1996
+ const collect = (fiber, chain) => {
1997
+ if (isProjectionRootFiber(fiber)) return false;
1998
+ if (fiber.tag === FiberTag.HostPortal) {
1999
+ return false;
2000
+ }
2001
+ const node = fiber.tag === FiberTag.HostText ? fiber.stateNode : fiber.tag === FiberTag.HostComponent ? getDomElement(fiber) : null;
2002
+ if (node instanceof Node) {
2003
+ annotations.set(node, { fiber, chain });
2004
+ for (const extra of pending.splice(0)) extra.before = node;
2005
+ return true;
2006
+ }
2007
+ fiberNodesVisited += 1;
2008
+ const included = isProjectionLayerFiber(fiber);
2009
+ const next = included ? [...chain, fiber] : chain;
2010
+ let hasChildren = false;
2011
+ for (let child = fiber.child; child; child = child.sibling)
2012
+ hasChildren = collect(child, next) || hasChildren;
2013
+ if (!hasChildren && included) {
2014
+ const extra = { fiber, chain };
2015
+ extras.push(extra);
2016
+ pending.push(extra);
2017
+ return true;
2018
+ }
2019
+ return hasChildren;
2020
+ };
2021
+ if (parent)
2022
+ for (let child = parent.child; child; child = child.sibling)
2023
+ collect(child, []);
2024
+ for (const portal of portalTargets.get(element) ?? [])
2025
+ for (let child = portal.child; child; child = child.sibling)
2026
+ collect(child, []);
2027
+ const extrasByNode = /* @__PURE__ */ new Map();
2028
+ const trailing = [];
2029
+ for (const extra of extras) {
2030
+ if (!extra.before || extra.before.parentNode !== element)
2031
+ trailing.push(extra);
2032
+ else {
2033
+ const group = extrasByNode.get(extra.before) ?? [];
2034
+ group.push(extra);
2035
+ extrasByNode.set(extra.before, group);
2036
+ }
2037
+ }
2038
+ const children = [];
2039
+ const components = /* @__PURE__ */ new Map();
2040
+ const seen = /* @__PURE__ */ new Set();
2041
+ const destinationOf = (chain, node) => {
2042
+ for (const component of components.keys()) {
2043
+ if (!chain.includes(component)) components.delete(component);
2044
+ }
2045
+ let destination = children;
2046
+ for (const component of chain) {
2047
+ let nested = components.get(component);
2048
+ if (!nested) {
2049
+ nested = [];
2050
+ components.set(component, nested);
2051
+ const branches2 = visit(component, nested);
2052
+ if (seen.has(component)) {
2053
+ const suffix = node && ensureProjectionDomId(node, watchedRoot) || nextProjectionId();
2054
+ for (const branch of branches2) {
2055
+ destination.push({ ...branch, id: `${branch.id}/${suffix}` });
2056
+ }
2057
+ } else destination.push(...branches2);
2058
+ seen.add(component);
2059
+ }
2060
+ destination = nested;
2061
+ }
2062
+ return destination;
2063
+ };
2064
+ const appendExtra = (extra) => {
2065
+ destinationOf(extra.chain, extra.before).push(
2066
+ ...visit(
2067
+ extra.fiber,
2068
+ extra.fiber.tag === FiberTag.HostPortal ? void 0 : []
2069
+ )
2070
+ );
2071
+ };
2072
+ for (const child of Array.from(element.childNodes)) {
2073
+ if (allowed && !allowed.has(child)) continue;
2074
+ if (child instanceof Element && (child.localName === "script" || child.hasAttribute(PROJECTION_ROOT_ATTRIBUTE)))
2075
+ continue;
2076
+ for (const extra of extrasByNode.get(child) ?? []) appendExtra(extra);
2077
+ const annotation = annotations.get(child);
2078
+ const destination = destinationOf(annotation?.chain ?? [], child);
2079
+ let fiber = annotation?.fiber;
2080
+ if (!fiber && child instanceof Element) {
2081
+ const candidate = getFiberFromElement(child);
2082
+ if (candidate) fiber = resolveCommittedFiber(candidate) ?? void 0;
2083
+ }
2084
+ if (fiber?.tag === FiberTag.HostRoot && child instanceof Element) {
2085
+ const serialized = serializeDomLayerNode(
2086
+ null,
2087
+ child,
2088
+ void 0,
2089
+ void 0,
2090
+ domChildren(child, fiber)
2091
+ );
2092
+ if (serialized) destination.push(serialized);
2093
+ } else if (fiber) destination.push(...visit(fiber));
2094
+ else {
2095
+ const isElement = child instanceof Element;
2096
+ if (emittedNodes.has(child)) continue;
2097
+ emittedNodes.add(child);
2098
+ const serialized = serializeDomLayerNode(
2099
+ isElement ? null : watchedRoot ?? null,
2100
+ child,
2101
+ void 0,
2102
+ void 0,
2103
+ isElement ? domChildren(child, void 0, void 0, physicalPortal) : void 0
2104
+ );
2105
+ if (serialized) {
2106
+ const portal = physicalPortal;
2107
+ destination.push(
2108
+ portal ? {
2109
+ ...serialized,
2110
+ portal: {
2111
+ nodeId: portalNodeId(child),
2112
+ ownerFiberId: fiberId(portal.return ?? portal)
2113
+ }
2114
+ } : serialized
2115
+ );
2116
+ semanticNodesSerialized += 1;
2117
+ }
2118
+ }
2119
+ }
2120
+ for (const extra of trailing) appendExtra(extra);
2121
+ return children;
2122
+ };
2123
+ const visit = (fiber, suppliedChildren) => {
2124
+ if (!suppliedChildren) fiberNodesVisited += 1;
2125
+ if (fiber !== root && isProjectionRootFiber(fiber)) return [];
2126
+ if (fiber.tag === FiberTag.HostPortal) return [];
2127
+ if (fiber.tag === FiberTag.HostText && fiber.stateNode instanceof Node && fiber.stateNode.parentElement) {
2128
+ if (emittedNodes.has(fiber.stateNode)) return [];
2129
+ emittedNodes.add(fiber.stateNode);
2130
+ const text = serializeDomLayerNode(
2131
+ watchedRoot ?? null,
2132
+ fiber.stateNode
2133
+ );
2134
+ if (!text) return [];
2135
+ semanticNodesSerialized += 1;
2136
+ const portal2 = portalRuntime(fiber, fiber.stateNode);
2137
+ return [portal2 ? { ...text, portal: portal2 } : text];
2138
+ }
2139
+ const name = getDisplayName(fiber);
2140
+ const kind = projectionKindForTag(fiber.tag);
2141
+ const included = isProjectionLayerFiber(fiber) && !(contentsScope && !includeRoot && fiber === root && getDomElement(fiber) === watchedRoot);
2142
+ const element = kind === "host" ? getDomElement(fiber) : null;
2143
+ if (element?.localName === "script") return [];
2144
+ if (element) {
2145
+ if (emittedNodes.has(element)) return [];
2146
+ emittedNodes.add(element);
2147
+ }
2148
+ const domId = element ? ensureProjectionDomId(element) : null;
2149
+ const props = included ? captureProjectionLayerProps(fiber, element) : void 0;
2150
+ observedFiles.addLayerProps(props);
2151
+ if (element) {
2152
+ observedFiles.addLayerProps(
2153
+ captureProjectionLayerProps(
2154
+ fiber,
2155
+ element,
2156
+ "live-host",
2157
+ props?.layoutMode ?? null
2158
+ )
2159
+ );
2160
+ }
2161
+ const children = suppliedChildren ?? (element ? domChildren(element, fiber) : []);
2162
+ if (!suppliedChildren && !element)
2163
+ for (let child = fiber.child; child; child = child.sibling)
2164
+ children.push(...visit(child));
2165
+ if (!included) return children;
2166
+ if (kind === null || kind === "text" || kind === "comment")
2167
+ return children;
2168
+ const source = {
2169
+ kind: "react-fiber",
2170
+ fiber: { tag: fiber.tag, name, id: fiberId(fiber) }
2171
+ };
2172
+ const portal = portalRuntime(fiber, element ?? void 0);
2173
+ let node;
2174
+ if (kind === "host") {
2175
+ node = {
2176
+ runtime: "react",
2177
+ kind,
2178
+ id: domId ?? id2(fiber),
2179
+ key: fiber.key == null ? null : String(fiber.key),
2180
+ name,
2181
+ domId,
2182
+ elementTag: name,
2183
+ props,
2184
+ source,
2185
+ ...portal ? { portal } : {},
2186
+ children
2187
+ };
2188
+ } else {
2189
+ node = {
2190
+ runtime: "react",
2191
+ kind,
2192
+ id: id2(fiber),
2193
+ key: fiber.key == null ? null : String(fiber.key),
2194
+ name,
2195
+ domId: null,
2196
+ elementTag: null,
2197
+ props,
2198
+ source,
2199
+ ...portal ? { portal } : {},
2200
+ children
2201
+ };
2202
+ }
2203
+ semanticNodesSerialized += 1;
2204
+ return [node];
2205
+ };
2206
+ const isScope = contentsScope && (!root || root === observedRoot || root?.alternate === observedRoot || observation);
2207
+ const branches = isScope && (!root || root.tag === FiberTag.HostRoot) && watchedRoot ? domChildren(watchedRoot, root ?? void 0) : root ? visit(root) : [];
2208
+ if (isScope && includeRoot && (!root || root.tag === FiberTag.HostRoot) && watchedRoot) {
2209
+ const node = serializeDomLayerNode(
2210
+ null,
2211
+ watchedRoot,
2212
+ void 0,
2213
+ observedFiles,
2214
+ [...branches]
2215
+ );
2216
+ branches.splice(0, branches.length, ...node ? [node] : []);
2217
+ }
2218
+ for (const [target, portals] of portalTargets) {
2219
+ if (emittedNodes.has(target) || !target.isConnected || target.ownerDocument !== watchedRoot?.ownerDocument)
2220
+ continue;
2221
+ const allowed = /* @__PURE__ */ new Set();
2222
+ for (const [fiber, portal2] of portalOwners) {
2223
+ if (!portals.includes(portal2)) continue;
2224
+ const node = fiber.tag === FiberTag.HostText ? fiber.stateNode : fiber.tag === FiberTag.HostComponent ? getDomElement(fiber) : null;
2225
+ if (node instanceof Node && node.parentNode === target)
2226
+ allowed.add(node);
2227
+ }
2228
+ const portal = portals[0];
2229
+ branches.push({
2230
+ runtime: "dom",
2231
+ kind: "host",
2232
+ id: portalNodeId(target),
2233
+ name: target.localName,
2234
+ key: null,
2235
+ domId: null,
2236
+ elementTag: target.localName,
2237
+ props: {
2238
+ "data-tempo-hide-fiber": true,
2239
+ "data-tempo-supports-style": false,
2240
+ "data-tempo-supports-classname": false,
2241
+ "data-tempo-supports-children": false,
2242
+ layoutMode: target.ownerDocument.defaultView ? layoutModeOf(
2243
+ target.ownerDocument.defaultView.getComputedStyle(target)
2244
+ ) : void 0
2245
+ },
2246
+ source: {
2247
+ kind: "react-fiber",
2248
+ fiber: {
2249
+ tag: FiberTag.HostPortal,
2250
+ name: "",
2251
+ id: fiberId(portal)
2252
+ }
2253
+ },
2254
+ portal: {
2255
+ target: true,
2256
+ nodeId: portalNodeId(target),
2257
+ ownerFiberId: fiberId(portal.return ?? portal)
2258
+ },
2259
+ children: domChildren(target, void 0, allowed)
2260
+ });
2261
+ semanticNodesSerialized += 1;
2262
+ emittedNodes.add(target);
2263
+ }
2264
+ let tree;
2265
+ const hiddenWatchedSlot = root !== null && isTempoHiddenFiber(root) && getDomElement(root) === watchedRoot;
2266
+ if (root && branches.some((branch) => branch.portal?.target))
2267
+ physicalAggregations.add(root);
2268
+ if (isScope || !root) {
2269
+ tree = null;
2270
+ } else if (branches.length === 1 && !aggregatesPhysicalTargets(root)) {
2271
+ tree = branches[0] ?? null;
2272
+ } else if (root.tag === FiberTag.HostRoot || branches.length > 1 || aggregatesPhysicalTargets(root)) {
2273
+ const name = getDisplayName(root);
2274
+ tree = {
2275
+ runtime: "react",
2276
+ kind: "fragment",
2277
+ // A nonhidden root already contributes its own physical branch.
2278
+ // This transparent aggregation belongs to the watched observation,
2279
+ // and must not alias that branch's host address.
2280
+ id: root.tag === FiberTag.HostRoot || hiddenWatchedSlot || !aggregatesPhysicalTargets(root) ? id2(root) : `${fiberId(root)}/physical`,
2281
+ key: root.key == null ? null : String(root.key),
2282
+ name,
2283
+ domId: null,
2284
+ elementTag: null,
2285
+ source: {
2286
+ kind: "react-fiber",
2287
+ fiber: { tag: root.tag, name, id: fiberId(root) }
2288
+ },
2289
+ children: branches
2290
+ };
2291
+ semanticNodesSerialized += 1;
2292
+ } else {
2293
+ tree = null;
2294
+ }
2295
+ return {
2296
+ snapshot: {
2297
+ semantic: isScope ? {
2298
+ kind: "scope",
2299
+ fragment: { kind: "fragment", children: branches }
2300
+ } : { kind: "layers", tree },
2301
+ observedFiles: observedFiles.snapshot()
2302
+ },
2303
+ fiberNodesVisited,
2304
+ semanticNodesSerialized
2305
+ };
2306
+ };
2307
+ return {
2308
+ portalClosure(candidate) {
2309
+ if (publishedPortalAncestors.has(candidate) || candidate.alternate && publishedPortalAncestors.has(candidate.alternate))
2310
+ return { required: true, nodesVisited: 0 };
2311
+ const element = getDomElement(candidate);
2312
+ if (element && publishedTargetAncestors.has(element))
2313
+ return { required: true, nodesVisited: 0 };
2314
+ let nodesVisited = 0;
2315
+ const pending = [candidate];
2316
+ while (pending.length) {
2317
+ const fiber = pending.pop();
2318
+ nodesVisited += 1;
2319
+ if (fiber !== candidate && isProjectionRootFiber(fiber)) continue;
2320
+ if (fiber.tag === FiberTag.HostPortal)
2321
+ return { required: true, nodesVisited };
2322
+ for (let child = fiber.child; child; child = child.sibling)
2323
+ pending.push(child);
2324
+ }
2325
+ return { required: false, nodesVisited };
2326
+ },
2327
+ serialize: (root) => serialize(root, true),
2328
+ serializeContents: () => serialize(null, true),
2329
+ fiberId,
2330
+ knownFiberId,
2331
+ serializeRegion(root) {
2332
+ const targetFiberId = fiberId(root);
2333
+ const serialized = serialize(root);
2334
+ const semantic = serialized.snapshot.semantic;
2335
+ return {
2336
+ region: {
2337
+ targetFiberId,
2338
+ ...semantic.kind === "scope" ? { scope: semantic.fragment } : {},
2339
+ targetId: semantic.kind === "scope" ? PROJECTION_SCOPE_TARGET : aggregatesPhysicalTargets(root) && root.tag !== FiberTag.HostRoot && !(isTempoHiddenFiber(root) && getDomElement(root) === watchedRoot) ? `${fiberId(root)}/physical` : id2(root),
2340
+ tree: serialized.snapshot.semantic.kind === "layers" ? serialized.snapshot.semantic.tree : null,
2341
+ observedFiles: serialized.snapshot.observedFiles
2342
+ },
2343
+ fiberNodesVisited: serialized.fiberNodesVisited,
2344
+ semanticNodesSerialized: serialized.semanticNodesSerialized
2345
+ };
2346
+ },
2347
+ captureMetadata(root, options) {
2348
+ return {
2349
+ targetFiberId: fiberId(root),
2350
+ targetId: id2(root),
2351
+ props: captureProjectionLayerProps(
2352
+ root,
2353
+ root.tag === FiberTag.HostComponent ? getDomElement(root) : null,
2354
+ options?.sourceAnnotations ?? "fiber",
2355
+ options?.layoutMode
2356
+ )
2357
+ };
2358
+ }
2359
+ };
2360
+ }
2361
+ function isProjectionLayerFiber(fiber) {
2362
+ if (isTempoHiddenFiber(fiber)) return false;
2363
+ const kind = projectionKindForTag(fiber.tag);
2364
+ if (kind === null) return false;
2365
+ if (kind === "host") return true;
2366
+ const sourceKey = projectionFiberSourceKey(fiber);
2367
+ if (!sourceKey) return true;
2368
+ for (let parent = fiber.return; parent; parent = parent.return) {
2369
+ if (isTempoHiddenFiber(parent)) continue;
2370
+ const parentKind = projectionKindForTag(parent.tag);
2371
+ if (parentKind === null) continue;
2372
+ if (parentKind === "host") return true;
2373
+ return projectionFiberSourceKey(parent) !== sourceKey;
2374
+ }
2375
+ return true;
2376
+ }
2377
+ function projectionKindForTag(tag) {
2378
+ if (tag === FiberTag.HostComponent) return "host";
2379
+ if (tag === FiberTag.HostText) return "text";
2380
+ if (COMPONENT_TAGS.has(tag)) return "component";
2381
+ return null;
2382
+ }
2383
+ function ascendToAnnotatedComponentRoot(fiber) {
2384
+ let topmost = fiber;
2385
+ for (let parent = fiber.return; parent; parent = parent.return) {
2386
+ if (parent.tag === FiberTag.HostRoot || parent.tag === FiberTag.HostPortal) {
2387
+ break;
2388
+ }
2389
+ const kind = projectionKindForTag(parent.tag);
2390
+ if (kind === "host") break;
2391
+ if (isTempoHiddenFiber(parent)) break;
2392
+ if (kind === "component") {
2393
+ if (projectionFiberSourceKey(parent) === null) break;
2394
+ topmost = parent;
2395
+ }
2396
+ }
2397
+ return topmost;
2398
+ }
2399
+ function isProjectionRootFiber(fiber) {
2400
+ const props = getProps(fiber);
2401
+ const dataSet = props?.dataSet;
2402
+ const native = dataSet && typeof dataSet === "object" ? dataSet.tempoProjectionRoot : void 0;
2403
+ const value = native ?? props?.[PROJECTION_ROOT_ATTRIBUTE];
2404
+ return value === true || value === "true";
2405
+ }
2406
+ function isTempoHiddenFiber(fiber) {
2407
+ if (isProjectionScopePlumbing(fiber)) return true;
2408
+ const props = getProps(fiber);
2409
+ const direct = props?.["data-tempo-hide-fiber"];
2410
+ const dataSet = props?.dataSet;
2411
+ const native = dataSet && typeof dataSet === "object" ? dataSet.tempoHideFiber : void 0;
2412
+ const value = native ?? direct;
2413
+ return value === true || value === "true";
2414
+ }
2415
+ function captureProjectionLayerProps(fiber, element, sourceAnnotations = "fiber", layoutMode) {
2416
+ const raw = getProps(fiber);
2417
+ const dataSet = raw?.dataSet && typeof raw.dataSet === "object" ? raw.dataSet : void 0;
2418
+ const read = (flatKey, dataSetKey, authority = "source") => {
2419
+ if (authority === "source" && element && sourceAnnotations === "live-host") {
2420
+ return element.getAttribute(flatKey);
2421
+ }
2422
+ return dataSet && Object.hasOwn(dataSet, dataSetKey) ? dataSet[dataSetKey] : raw?.[flatKey];
2423
+ };
2424
+ const props = {};
2425
+ const putString = (flatKey, dataSetKey) => {
2426
+ const value = read(flatKey, dataSetKey);
2427
+ if (typeof value === "string") props[flatKey] = value;
2428
+ };
2429
+ const putFiniteNumber = (flatKey, dataSetKey) => {
2430
+ const value = read(flatKey, dataSetKey);
2431
+ const numeric = typeof value === "number" ? value : typeof value === "string" ? Number(value) : Number.NaN;
2432
+ if (Number.isFinite(numeric)) props[flatKey] = numeric;
2433
+ };
2434
+ const putBoolean = (flatKey, dataSetKey) => {
2435
+ const value = read(flatKey, dataSetKey, "fiber");
2436
+ if (value === true || value === "true") props[flatKey] = true;
2437
+ if (value === false || value === "false") props[flatKey] = false;
2438
+ };
2439
+ const putPresence = (flatKey, dataSetKey) => {
2440
+ const present = dataSet != null && Object.hasOwn(dataSet, dataSetKey) || raw != null && Object.hasOwn(raw, flatKey);
2441
+ if (present)
2442
+ props[flatKey] = read(flatKey, dataSetKey, "fiber") !== "false";
2443
+ };
2444
+ putString("data-tempo-filepath", "tempoFilepath");
2445
+ const locked = read("data-tempo-locked", "tempoLocked");
2446
+ if (locked === true || locked === "true" || locked === "")
2447
+ props["data-tempo-locked"] = true;
2448
+ else if (locked === false || locked === "false")
2449
+ props["data-tempo-locked"] = false;
2450
+ putFiniteNumber("data-tempo-position", "tempoPosition");
2451
+ putFiniteNumber("data-tempo-modifiedts", "tempoModifiedts");
2452
+ putString("data-tempo-source-version", "tempoSourceVersion");
2453
+ putBoolean("data-tempo-supports-style", "tempoSupportsStyle");
2454
+ putBoolean("data-tempo-supports-classname", "tempoSupportsClassname");
2455
+ putBoolean("data-tempo-supports-children", "tempoSupportsChildren");
2456
+ putString("data-tempo-expr", "tempoExpr");
2457
+ putPresence("data-tempo-storyboard-root", "tempoStoryboardRoot");
2458
+ putString("data-tempo-component-reference", "tempoComponentReference");
2459
+ putString("data-tempo-external-component", "tempoExternalComponent");
2460
+ putString("data-tempo-canvas-declaration", "tempoCanvasDeclaration");
2461
+ putString("data-tempo-storyboard-declaration", "tempoStoryboardDeclaration");
2462
+ putString("data-tempo-storyboard-id", "tempoStoryboardId");
2463
+ if (fiber.tag === FiberTag.HostComponent && fiber.type === "polygon" && typeof raw?.points === "string") {
2464
+ props.points = raw.points;
2465
+ }
2466
+ if (element) {
2467
+ if (layoutMode === void 0) {
2468
+ layoutMode = layoutModeOf(getComputedStyle(element));
2469
+ }
2470
+ if (layoutMode) props.layoutMode = layoutMode;
2471
+ const className = element.getAttribute("class");
2472
+ if (className !== null && className !== "") props.className = className;
2473
+ const style = parseInlineStyle2(element.getAttribute("style"));
2474
+ if (style) props.style = style;
2475
+ } else if (typeof raw?.className === "string") {
2476
+ props.className = raw.className;
2477
+ }
2478
+ return Object.keys(props).length > 0 ? props : void 0;
2479
+ }
2480
+ function parseInlineStyle2(value) {
2481
+ if (!value) return void 0;
2482
+ const style = {};
2483
+ for (const declaration of value.split(";")) {
2484
+ const colon = declaration.indexOf(":");
2485
+ if (colon < 0) continue;
2486
+ const property = declaration.slice(0, colon).trim();
2487
+ const propertyValue = declaration.slice(colon + 1).trim();
2488
+ if (property) style[property] = propertyValue;
2489
+ }
2490
+ return Object.keys(style).length > 0 ? style : void 0;
2491
+ }
2492
+ function projectionFiberSourceKey(fiber) {
2493
+ const props = captureProjectionLayerProps(fiber, null);
2494
+ const filepath = props?.["data-tempo-filepath"];
2495
+ const position = props?.["data-tempo-position"];
2496
+ return filepath && position !== void 0 ? `${filepath}:${position}` : null;
2497
+ }
2498
+
2499
+ // ../../modules/iframe-projection/combined/projection-pending.ts
2500
+ var PROJECTION_PENDING_ATTRIBUTE = "data-tempo-projection-pending";
2501
+ function isProjectionPendingOnly(rootElement) {
2502
+ const children = rootElement.children;
2503
+ if (children.length === 0) return false;
2504
+ for (let index = 0; index < children.length; index += 1) {
2505
+ const child = children[index];
2506
+ if (!child || !child.hasAttribute(PROJECTION_PENDING_ATTRIBUTE)) {
2507
+ return false;
2508
+ }
2509
+ }
2510
+ return true;
2511
+ }
2512
+
2513
+ export {
2514
+ FiberTag,
2515
+ PROJECTION_SCOPE_ROLE,
2516
+ PROJECTION_PENDING_ATTRIBUTE,
2517
+ isProjectionPendingOnly,
2518
+ getDisplayName,
2519
+ getTag,
2520
+ getProps,
2521
+ sanitizeProps,
2522
+ getDomElement,
2523
+ resolveCommittedFiber,
2524
+ isTransientFiberResolutionError,
2525
+ serializeTree,
2526
+ getFiberFromElement,
2527
+ captureTree,
2528
+ getCommittedFiberRoots,
2529
+ initHook,
2530
+ REALM_DOCUMENT_EPOCH,
2531
+ nextRealmCaptureSequence,
2532
+ DOM_ID_ATTR,
2533
+ PROJECTION_ROOT_ATTRIBUTE,
2534
+ nextProjectionId,
2535
+ seedProjectionIds,
2536
+ underForeignProjectionRoot,
2537
+ projectedElements,
2538
+ ensureProjectionDomId,
2539
+ readProjectionDomId,
2540
+ syncProjectionDomIdsToClone,
2541
+ watchDom,
2542
+ drainProjectionDomMutations,
2543
+ watchState,
2544
+ drainProjectionStateEvents,
2545
+ PORTAL_ID_ATTR,
2546
+ getOrAssignPortalId,
2547
+ watchPortal,
2548
+ capturePortalCoordinateSpace,
2549
+ cssEscape,
2550
+ ProjectionObservedFileAccumulator,
2551
+ PROJECTION_ROOT_TARGET_ID,
2552
+ captureProjectionMutationPatch,
2553
+ captureProjectionStatePatch,
2554
+ captureProjectionPortalRegion,
2555
+ captureProjectionPortalCoordinates,
2556
+ stripSourceAnnotations,
2557
+ captureRegionWithoutAnnotations,
2558
+ captureProjectionAncestorIds,
2559
+ PROJECTION_SCOPE_TARGET,
2560
+ projectionLayerRoots,
2561
+ createProjectionLayerSerializer,
2562
+ isProjectionLayerFiber,
2563
+ ascendToAnnotatedComponentRoot,
2564
+ isProjectionRootFiber,
2565
+ DOM_LAYER_ROOT_ID,
2566
+ createProjectionDomLayerSerializer,
2567
+ serializeDomLayerNode,
2568
+ captureProjectionDomLayerProps
2569
+ };
2570
+ //# sourceMappingURL=chunk-TL4MGN7E.js.map