tempo-sdk 0.0.18 → 0.0.20
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.
- package/README.md +32 -2
- package/dist/assets/editor.d.ts +79 -0
- package/dist/assets/editor.js +571 -0
- package/dist/assets/editor.js.map +1 -0
- package/dist/assets/index.d.ts +83 -0
- package/dist/assets/index.js +26 -0
- package/dist/assets/index.js.map +1 -0
- package/dist/assets/parser.d.ts +78 -0
- package/dist/assets/parser.js +29 -0
- package/dist/assets/parser.js.map +1 -0
- package/dist/canvas/editor.js +1 -1
- package/dist/canvas/index.d.ts +99 -16
- package/dist/canvas/index.js +1427 -661
- package/dist/canvas/index.js.map +1 -1
- package/dist/canvas/interact-projection.d.ts +8 -0
- package/dist/canvas/interact-projection.js +2848 -0
- package/dist/canvas/interact-projection.js.map +1 -0
- package/dist/canvas/parser.d.ts +25 -1
- package/dist/canvas/parser.js +3 -1
- package/dist/{chunk-6Q4I3RFN.js → chunk-GBKYTBEE.js} +242 -33
- package/dist/chunk-GBKYTBEE.js.map +1 -0
- package/dist/chunk-IWULHYPW.js +650 -0
- package/dist/chunk-IWULHYPW.js.map +1 -0
- package/dist/chunk-QXB32HG4.js +11 -0
- package/dist/chunk-QXB32HG4.js.map +1 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.js +601 -20
- package/dist/index.js.map +1 -1
- package/dist/types-B-dRoF2T.d.ts +102 -0
- package/package.json +19 -2
- package/dist/chunk-6Q4I3RFN.js.map +0 -1
|
@@ -0,0 +1,2848 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isTempoInteractFrameName
|
|
3
|
+
} from "../chunk-QXB32HG4.js";
|
|
4
|
+
|
|
5
|
+
// ../../modules/iframe-projection/fiber/react-types.ts
|
|
6
|
+
var FiberTag = {
|
|
7
|
+
/** Function component: `function MyComponent(props) { ... }` */
|
|
8
|
+
FunctionComponent: 0,
|
|
9
|
+
/** Class component: `class MyComponent extends React.Component` */
|
|
10
|
+
ClassComponent: 1,
|
|
11
|
+
/**
|
|
12
|
+
* Component not yet determined to be function or class.
|
|
13
|
+
* React resolves this on first render, then updates the tag.
|
|
14
|
+
*/
|
|
15
|
+
IndeterminateComponent: 2,
|
|
16
|
+
/** Root of a React tree (created by createRoot/render) */
|
|
17
|
+
HostRoot: 3,
|
|
18
|
+
/** React Portal: renders children into a different DOM container */
|
|
19
|
+
HostPortal: 4,
|
|
20
|
+
/** DOM element: div, span, button, etc. */
|
|
21
|
+
HostComponent: 5,
|
|
22
|
+
/** Text node: string/number children */
|
|
23
|
+
HostText: 6,
|
|
24
|
+
/** React.Fragment or <>...</> */
|
|
25
|
+
Fragment: 7,
|
|
26
|
+
/** StrictMode, ConcurrentMode, etc. */
|
|
27
|
+
Mode: 8,
|
|
28
|
+
/** Context.Consumer (legacy pattern) */
|
|
29
|
+
ContextConsumer: 9,
|
|
30
|
+
/** Context.Provider */
|
|
31
|
+
ContextProvider: 10,
|
|
32
|
+
/** React.forwardRef wrapper */
|
|
33
|
+
ForwardRef: 11,
|
|
34
|
+
/** React.Profiler for performance measurements */
|
|
35
|
+
Profiler: 12,
|
|
36
|
+
/** React.Suspense boundary */
|
|
37
|
+
SuspenseComponent: 13,
|
|
38
|
+
/** React.memo() wrapper */
|
|
39
|
+
MemoComponent: 14,
|
|
40
|
+
/** Simplified memo (internal optimization) */
|
|
41
|
+
SimpleMemoComponent: 15,
|
|
42
|
+
/** React.lazy() wrapper for code splitting */
|
|
43
|
+
LazyComponent: 16,
|
|
44
|
+
/** Incomplete class component (errored during render) */
|
|
45
|
+
IncompleteClassComponent: 17,
|
|
46
|
+
/** Dehydrated Suspense boundary (server-rendered) */
|
|
47
|
+
DehydratedFragment: 18,
|
|
48
|
+
/** SuspenseList for coordinating reveal order */
|
|
49
|
+
SuspenseListComponent: 19,
|
|
50
|
+
/** Scope component (experimental) */
|
|
51
|
+
ScopeComponent: 21,
|
|
52
|
+
/** Offscreen component (experimental, powers Activity) */
|
|
53
|
+
OffscreenComponent: 22,
|
|
54
|
+
/** Legacy hidden component (deprecated) */
|
|
55
|
+
LegacyHiddenComponent: 23,
|
|
56
|
+
/** Cache component (experimental) */
|
|
57
|
+
CacheComponent: 24,
|
|
58
|
+
/** Tracing marker (experimental) */
|
|
59
|
+
TracingMarkerComponent: 25,
|
|
60
|
+
/** Hoistable elements like <title>, <meta> (React 18.3+) */
|
|
61
|
+
HostHoistable: 26,
|
|
62
|
+
/** Singleton elements like <html>, <head>, <body> (React 18.3+) */
|
|
63
|
+
HostSingleton: 27
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// ../../modules/iframe-projection/fiber/serialize.ts
|
|
67
|
+
function getDisplayName(fiber) {
|
|
68
|
+
const { type, tag } = fiber;
|
|
69
|
+
if (typeof type === "string") {
|
|
70
|
+
return type;
|
|
71
|
+
}
|
|
72
|
+
if (tag === FiberTag.HostText) {
|
|
73
|
+
return "#text";
|
|
74
|
+
}
|
|
75
|
+
if (typeof type === "function") {
|
|
76
|
+
const fn = type;
|
|
77
|
+
return fn.displayName || fn.name || "Anonymous";
|
|
78
|
+
}
|
|
79
|
+
if (type && typeof type === "object") {
|
|
80
|
+
if ("type" in type && type.type) {
|
|
81
|
+
const inner = type.type;
|
|
82
|
+
if (typeof inner === "function") {
|
|
83
|
+
return inner.displayName || inner.name || "Memo";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if ("render" in type && type.render) {
|
|
87
|
+
const render = type.render;
|
|
88
|
+
return type.displayName || render.displayName || render.name || "ForwardRef";
|
|
89
|
+
}
|
|
90
|
+
if ("_context" in type) {
|
|
91
|
+
const ctx = type._context;
|
|
92
|
+
return ctx.displayName ? `${ctx.displayName}.Provider` : "Context.Provider";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const tagNames = {
|
|
96
|
+
[FiberTag.HostRoot]: "HostRoot",
|
|
97
|
+
[FiberTag.Fragment]: "Fragment",
|
|
98
|
+
[FiberTag.Mode]: "Mode",
|
|
99
|
+
[FiberTag.ContextConsumer]: "Context.Consumer",
|
|
100
|
+
[FiberTag.ContextProvider]: "Context.Provider",
|
|
101
|
+
[FiberTag.Profiler]: "Profiler",
|
|
102
|
+
[FiberTag.SuspenseComponent]: "Suspense",
|
|
103
|
+
[FiberTag.SuspenseListComponent]: "SuspenseList",
|
|
104
|
+
[FiberTag.OffscreenComponent]: "Offscreen"
|
|
105
|
+
};
|
|
106
|
+
return tagNames[tag] || `Unknown(${tag})`;
|
|
107
|
+
}
|
|
108
|
+
function getTag(fiber) {
|
|
109
|
+
return fiber.tag;
|
|
110
|
+
}
|
|
111
|
+
function getProps(fiber) {
|
|
112
|
+
return fiber.memoizedProps;
|
|
113
|
+
}
|
|
114
|
+
function sanitizeProps(props) {
|
|
115
|
+
if (!props) return void 0;
|
|
116
|
+
const result = {};
|
|
117
|
+
let hasProps = false;
|
|
118
|
+
for (const [key, value] of Object.entries(props)) {
|
|
119
|
+
if (key === "children") continue;
|
|
120
|
+
hasProps = true;
|
|
121
|
+
result[key] = sanitizeValue(value);
|
|
122
|
+
}
|
|
123
|
+
return hasProps ? result : void 0;
|
|
124
|
+
}
|
|
125
|
+
function sanitizeValue(value) {
|
|
126
|
+
if (value === null || value === void 0) {
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
if (typeof value === "function") {
|
|
130
|
+
return "[Function]";
|
|
131
|
+
}
|
|
132
|
+
if (typeof value === "symbol") {
|
|
133
|
+
return `[Symbol:${value.description ?? ""}]`;
|
|
134
|
+
}
|
|
135
|
+
if (value instanceof Element) {
|
|
136
|
+
return `[Element:${value.tagName.toLowerCase()}${value.id ? `#${value.id}` : ""}]`;
|
|
137
|
+
}
|
|
138
|
+
if (value instanceof Node) {
|
|
139
|
+
return `[Node:${value.nodeName}]`;
|
|
140
|
+
}
|
|
141
|
+
if (Array.isArray(value)) {
|
|
142
|
+
if (value.length <= 10) {
|
|
143
|
+
return value.map(sanitizeValue);
|
|
144
|
+
}
|
|
145
|
+
return `[Array(${value.length})]`;
|
|
146
|
+
}
|
|
147
|
+
if (typeof value === "object") {
|
|
148
|
+
if ("$$typeof" in value) {
|
|
149
|
+
return "[ReactElement]";
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
return JSON.parse(JSON.stringify(value));
|
|
153
|
+
} catch {
|
|
154
|
+
return "[Object]";
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
function getDomElement(fiber) {
|
|
160
|
+
if (fiber.tag !== FiberTag.HostComponent) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
return fiber.stateNode instanceof Element ? fiber.stateNode : null;
|
|
164
|
+
}
|
|
165
|
+
function* iterateChildren(fiber) {
|
|
166
|
+
let child = fiber.child;
|
|
167
|
+
while (child) {
|
|
168
|
+
yield child;
|
|
169
|
+
child = child.sibling;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function resolveCommittedFiber(fiber) {
|
|
173
|
+
const alternate = fiber.alternate;
|
|
174
|
+
if (!alternate) {
|
|
175
|
+
return fiber;
|
|
176
|
+
}
|
|
177
|
+
let a = fiber;
|
|
178
|
+
let b = alternate;
|
|
179
|
+
for (; ; ) {
|
|
180
|
+
const parentA = a.return;
|
|
181
|
+
if (!parentA) break;
|
|
182
|
+
const parentB = parentA.alternate;
|
|
183
|
+
if (!parentB) {
|
|
184
|
+
const nextParent = parentA.return;
|
|
185
|
+
if (nextParent) {
|
|
186
|
+
a = nextParent;
|
|
187
|
+
b = nextParent;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
if (parentA.child === parentB.child) {
|
|
193
|
+
for (let child = parentA.child; child; child = child.sibling) {
|
|
194
|
+
if (child === a) return fiber;
|
|
195
|
+
if (child === b) return alternate;
|
|
196
|
+
}
|
|
197
|
+
throw new Error("Unable to resolve a mounted React fiber");
|
|
198
|
+
}
|
|
199
|
+
if (a.return !== b.return) {
|
|
200
|
+
a = parentA;
|
|
201
|
+
b = parentB;
|
|
202
|
+
} else {
|
|
203
|
+
let found = false;
|
|
204
|
+
for (let child = parentA.child; child; child = child.sibling) {
|
|
205
|
+
if (child === a) {
|
|
206
|
+
found = true;
|
|
207
|
+
a = parentA;
|
|
208
|
+
b = parentB;
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
if (child === b) {
|
|
212
|
+
found = true;
|
|
213
|
+
a = parentB;
|
|
214
|
+
b = parentA;
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (!found) {
|
|
219
|
+
for (let child = parentB.child; child; child = child.sibling) {
|
|
220
|
+
if (child === a) {
|
|
221
|
+
found = true;
|
|
222
|
+
a = parentB;
|
|
223
|
+
b = parentA;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
if (child === b) {
|
|
227
|
+
found = true;
|
|
228
|
+
a = parentA;
|
|
229
|
+
b = parentB;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (!found) {
|
|
235
|
+
throw new Error("React fiber is absent from both parent generations");
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (a.alternate !== b) {
|
|
239
|
+
throw new Error("React return fibers are not paired alternates");
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (a.tag !== FiberTag.HostRoot) {
|
|
243
|
+
throw new Error("Unable to resolve an unmounted React fiber");
|
|
244
|
+
}
|
|
245
|
+
const fiberRoot = a.stateNode;
|
|
246
|
+
return fiberRoot?.current === a ? fiber : alternate;
|
|
247
|
+
}
|
|
248
|
+
var defaultSerialize = (fiber) => ({
|
|
249
|
+
name: getDisplayName(fiber),
|
|
250
|
+
tag: getTag(fiber)
|
|
251
|
+
});
|
|
252
|
+
function serializeTree(fiber, serialize, options = {}) {
|
|
253
|
+
const { maxDepth = Infinity, skipText = true } = options;
|
|
254
|
+
function serializeNode(f, depth) {
|
|
255
|
+
if (depth > maxDepth) return null;
|
|
256
|
+
if (skipText && f.tag === FiberTag.HostText) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
const nodeData = serialize(f);
|
|
260
|
+
const children = [];
|
|
261
|
+
for (const child of iterateChildren(f)) {
|
|
262
|
+
const serialized = serializeNode(child, depth + 1);
|
|
263
|
+
if (serialized) {
|
|
264
|
+
children.push(serialized);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return { ...nodeData, children };
|
|
268
|
+
}
|
|
269
|
+
return serializeNode(fiber, 0);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ../../modules/iframe-projection/fiber/capture.ts
|
|
273
|
+
function findFiberKey(element) {
|
|
274
|
+
return Object.keys(element).find(
|
|
275
|
+
(k) => k.startsWith("__reactFiber$") || k.startsWith("__reactInternalInstance$")
|
|
276
|
+
) ?? null;
|
|
277
|
+
}
|
|
278
|
+
function findContainerKey(element) {
|
|
279
|
+
return Object.keys(element).find((k) => k.startsWith("__reactContainer$")) ?? null;
|
|
280
|
+
}
|
|
281
|
+
function getFiberFromElement(element) {
|
|
282
|
+
const fiberKey = findFiberKey(element);
|
|
283
|
+
if (fiberKey) {
|
|
284
|
+
return element[fiberKey] ?? null;
|
|
285
|
+
}
|
|
286
|
+
const containerKey = findContainerKey(element);
|
|
287
|
+
if (containerKey) {
|
|
288
|
+
return element[containerKey] ?? null;
|
|
289
|
+
}
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// ../../modules/iframe-projection/fiber/utils.ts
|
|
294
|
+
function filterTreeInclude(tree, includeTags) {
|
|
295
|
+
if (tree === null) return null;
|
|
296
|
+
if (!includeTags.has(tree.tag)) {
|
|
297
|
+
const filteredChildren = filterChildrenInclude(tree.children, includeTags);
|
|
298
|
+
return filteredChildren.length > 0 ? filteredChildren[0] : null;
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
...tree,
|
|
302
|
+
children: filterChildrenInclude(tree.children, includeTags)
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function filterChildrenInclude(children, includeTags) {
|
|
306
|
+
const result = [];
|
|
307
|
+
for (const child of children) {
|
|
308
|
+
if (!includeTags.has(child.tag)) {
|
|
309
|
+
const grandchildren = filterChildrenInclude(child.children, includeTags);
|
|
310
|
+
result.push(...grandchildren);
|
|
311
|
+
} else {
|
|
312
|
+
result.push({
|
|
313
|
+
...child,
|
|
314
|
+
children: filterChildrenInclude(child.children, includeTags)
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return result;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// ../../modules/iframe-projection/fiber/watch.ts
|
|
322
|
+
function captureTree(options = {}) {
|
|
323
|
+
const { selector, serialize, tags, ...serializeOptions } = options;
|
|
324
|
+
const serializeFn = serialize ?? defaultSerialize;
|
|
325
|
+
const tagSet = tags && tags.length > 0 ? new Set(tags) : null;
|
|
326
|
+
const hook = getHook();
|
|
327
|
+
if (!hook) return null;
|
|
328
|
+
let fiberRoot = null;
|
|
329
|
+
for (const roots of lastCommittedRoots.values()) {
|
|
330
|
+
for (const root of roots) {
|
|
331
|
+
if (root.current) {
|
|
332
|
+
fiberRoot = root;
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (fiberRoot) break;
|
|
337
|
+
}
|
|
338
|
+
if (!fiberRoot) {
|
|
339
|
+
for (const [_id, renderer] of hook.renderers) {
|
|
340
|
+
const roots = renderer.getFiberRoots?.();
|
|
341
|
+
if (roots) {
|
|
342
|
+
for (const root of roots) {
|
|
343
|
+
if (root?.current) {
|
|
344
|
+
fiberRoot = root;
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (fiberRoot) break;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
if (!fiberRoot) return null;
|
|
353
|
+
let startFiber = null;
|
|
354
|
+
if (selector) {
|
|
355
|
+
const element = document.querySelector(selector);
|
|
356
|
+
if (element) {
|
|
357
|
+
const rawFiber = getFiberFromElement(element);
|
|
358
|
+
startFiber = rawFiber ? resolveCommittedFiber(rawFiber) : null;
|
|
359
|
+
}
|
|
360
|
+
} else {
|
|
361
|
+
const rootFiber = fiberRoot.current;
|
|
362
|
+
if (rootFiber && rootFiber.tag === FiberTag.HostRoot && rootFiber.child) {
|
|
363
|
+
startFiber = rootFiber.child;
|
|
364
|
+
} else if (rootFiber) {
|
|
365
|
+
startFiber = rootFiber;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (!startFiber) return null;
|
|
369
|
+
let tree = serializeTree(startFiber, serializeFn, serializeOptions);
|
|
370
|
+
if (tree && tagSet && "tag" in tree) {
|
|
371
|
+
const filtered = filterTreeInclude(
|
|
372
|
+
tree,
|
|
373
|
+
tagSet
|
|
374
|
+
);
|
|
375
|
+
tree = filtered;
|
|
376
|
+
}
|
|
377
|
+
return tree;
|
|
378
|
+
}
|
|
379
|
+
var HOOK_MARKER = /* @__PURE__ */ Symbol.for("iframe-projection-fiber-hook");
|
|
380
|
+
var cachedInterface = null;
|
|
381
|
+
var lastCommittedRoots = /* @__PURE__ */ new Map();
|
|
382
|
+
function rememberCommittedRoot(rendererId, root) {
|
|
383
|
+
const roots = lastCommittedRoots.get(rendererId) ?? /* @__PURE__ */ new Set();
|
|
384
|
+
for (const previous of roots) {
|
|
385
|
+
if (previous !== root && previous.containerInfo === root.containerInfo) {
|
|
386
|
+
roots.delete(previous);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
roots.add(root);
|
|
390
|
+
lastCommittedRoots.set(rendererId, roots);
|
|
391
|
+
}
|
|
392
|
+
function getCommittedFiberRoots() {
|
|
393
|
+
return [...lastCommittedRoots.values()].flatMap((roots) => [...roots]);
|
|
394
|
+
}
|
|
395
|
+
function initHook() {
|
|
396
|
+
if (cachedInterface) {
|
|
397
|
+
return cachedInterface;
|
|
398
|
+
}
|
|
399
|
+
const existing = typeof window !== "undefined" ? window.__REACT_DEVTOOLS_GLOBAL_HOOK__ : void 0;
|
|
400
|
+
if (existing && HOOK_MARKER in existing) {
|
|
401
|
+
cachedInterface = existing[HOOK_MARKER];
|
|
402
|
+
return cachedInterface;
|
|
403
|
+
}
|
|
404
|
+
const commitHandlers = /* @__PURE__ */ new Set();
|
|
405
|
+
const injectHandlers = /* @__PURE__ */ new Set();
|
|
406
|
+
const unmountHandlers = /* @__PURE__ */ new Set();
|
|
407
|
+
const createRegistrar = (set) => (handler) => {
|
|
408
|
+
set.add(handler);
|
|
409
|
+
return () => set.delete(handler);
|
|
410
|
+
};
|
|
411
|
+
const callbacks = {
|
|
412
|
+
onCommit: (root, id, didError) => {
|
|
413
|
+
rememberCommittedRoot(id, root);
|
|
414
|
+
commitHandlers.forEach((h) => h(root, id, didError));
|
|
415
|
+
},
|
|
416
|
+
onInject: (renderer, id) => injectHandlers.forEach((h) => h(renderer, id)),
|
|
417
|
+
onUnmount: (fiber, id) => unmountHandlers.forEach((h) => h(fiber, id))
|
|
418
|
+
};
|
|
419
|
+
let hook;
|
|
420
|
+
if (existing) {
|
|
421
|
+
wrapDevToolsHook(existing, callbacks);
|
|
422
|
+
hook = existing;
|
|
423
|
+
} else {
|
|
424
|
+
hook = createDevToolsHook(callbacks);
|
|
425
|
+
if (typeof window !== "undefined") {
|
|
426
|
+
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
const hookInterface = {
|
|
430
|
+
onCommit: createRegistrar(commitHandlers),
|
|
431
|
+
onInject: createRegistrar(injectHandlers),
|
|
432
|
+
onUnmount: createRegistrar(unmountHandlers),
|
|
433
|
+
hook,
|
|
434
|
+
seedCommittedRoots(roots) {
|
|
435
|
+
for (const [rendererId, root] of roots) {
|
|
436
|
+
rememberCommittedRoot(rendererId, root);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
hook[HOOK_MARKER] = hookInterface;
|
|
441
|
+
cachedInterface = hookInterface;
|
|
442
|
+
return hookInterface;
|
|
443
|
+
}
|
|
444
|
+
function createDevToolsHook(callbacks) {
|
|
445
|
+
const hook = {
|
|
446
|
+
supportsFiber: true,
|
|
447
|
+
renderers: /* @__PURE__ */ new Map(),
|
|
448
|
+
inject(renderer) {
|
|
449
|
+
const id = this.renderers.size + 1;
|
|
450
|
+
this.renderers.set(id, renderer);
|
|
451
|
+
callbacks?.onInject?.(renderer, id);
|
|
452
|
+
return id;
|
|
453
|
+
},
|
|
454
|
+
onCommitFiberRoot(rendererId, fiberRoot, _priority, didError) {
|
|
455
|
+
callbacks?.onCommit?.(fiberRoot, rendererId, didError === true);
|
|
456
|
+
},
|
|
457
|
+
onCommitFiberUnmount(rendererId, fiber) {
|
|
458
|
+
callbacks?.onUnmount?.(fiber, rendererId);
|
|
459
|
+
},
|
|
460
|
+
// Required stubs for React compatibility
|
|
461
|
+
checkDCE(_fn) {
|
|
462
|
+
},
|
|
463
|
+
onScheduleFiberRoot() {
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
return hook;
|
|
467
|
+
}
|
|
468
|
+
function wrapDevToolsHook(hook, callbacks) {
|
|
469
|
+
if (callbacks.onInject) {
|
|
470
|
+
const original = hook.inject.bind(hook);
|
|
471
|
+
hook.inject = function(renderer) {
|
|
472
|
+
const id = original(renderer);
|
|
473
|
+
callbacks.onInject(renderer, id);
|
|
474
|
+
return id;
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
if (callbacks.onCommit) {
|
|
478
|
+
const original = hook.onCommitFiberRoot?.bind(hook);
|
|
479
|
+
hook.onCommitFiberRoot = function(rendererId, fiberRoot, priority, didError) {
|
|
480
|
+
callbacks.onCommit(fiberRoot, rendererId, didError === true);
|
|
481
|
+
original?.(rendererId, fiberRoot, priority, didError);
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
if (callbacks.onUnmount) {
|
|
485
|
+
const original = hook.onCommitFiberUnmount?.bind(hook);
|
|
486
|
+
hook.onCommitFiberUnmount = function(rendererId, fiber) {
|
|
487
|
+
callbacks.onUnmount(fiber, rendererId);
|
|
488
|
+
original?.(rendererId, fiber);
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function getHook() {
|
|
493
|
+
if (typeof window === "undefined") return null;
|
|
494
|
+
return window.__REACT_DEVTOOLS_GLOBAL_HOOK__ ?? null;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// ../../modules/iframe-projection/combined/realm-epoch.ts
|
|
498
|
+
var REALM_DOCUMENT_EPOCH = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
499
|
+
var nextCaptureSequence = 0;
|
|
500
|
+
function nextRealmCaptureSequence() {
|
|
501
|
+
return nextCaptureSequence++;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// ../../modules/iframe-projection/html/declared-facts.ts
|
|
505
|
+
var SOURCE_ANNOTATED_SELECTOR = "[data-tempo-filepath], [data-tempo-html-filepath]";
|
|
506
|
+
var NAMESPACES = [
|
|
507
|
+
{
|
|
508
|
+
filepathAttr: "data-tempo-filepath",
|
|
509
|
+
positionAttr: "data-tempo-position",
|
|
510
|
+
modifiedTsAttr: "data-tempo-modifiedts",
|
|
511
|
+
sourceVersionAttr: "data-tempo-source-version"
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
filepathAttr: "data-tempo-html-filepath",
|
|
515
|
+
positionAttr: "data-tempo-html-offset",
|
|
516
|
+
modifiedTsAttr: "data-tempo-html-modifiedts",
|
|
517
|
+
sourceVersionAttr: "data-tempo-html-source-version"
|
|
518
|
+
}
|
|
519
|
+
];
|
|
520
|
+
function computeDeclaredFacts(targetElement, captureRoot, scopeSelector, portalElements) {
|
|
521
|
+
const observedVersions = {};
|
|
522
|
+
const observedSourceVersions = {};
|
|
523
|
+
const anchorSet = /* @__PURE__ */ new Set();
|
|
524
|
+
const visit = (element) => {
|
|
525
|
+
for (const ns of NAMESPACES) {
|
|
526
|
+
const filepath = element.getAttribute(ns.filepathAttr);
|
|
527
|
+
if (filepath == null || filepath.length === 0) continue;
|
|
528
|
+
const modifiedTsRaw = element.getAttribute(ns.modifiedTsAttr);
|
|
529
|
+
if (modifiedTsRaw != null) {
|
|
530
|
+
const modifiedTs = Number(modifiedTsRaw);
|
|
531
|
+
if (!Number.isNaN(modifiedTs)) {
|
|
532
|
+
const existing = observedVersions[filepath];
|
|
533
|
+
if (existing === void 0 || modifiedTs > existing) {
|
|
534
|
+
observedVersions[filepath] = modifiedTs;
|
|
535
|
+
const version = element.getAttribute(ns.sourceVersionAttr);
|
|
536
|
+
if (version != null && version.length > 0) {
|
|
537
|
+
observedSourceVersions[filepath] = version;
|
|
538
|
+
} else {
|
|
539
|
+
delete observedSourceVersions[filepath];
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
const position = element.getAttribute(ns.positionAttr);
|
|
545
|
+
if (position != null && position.length > 0) {
|
|
546
|
+
anchorSet.add(`${filepath} ${position}`);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
const walkRoots = [targetElement, ...portalElements];
|
|
551
|
+
for (const root of walkRoots) {
|
|
552
|
+
if (root.matches(SOURCE_ANNOTATED_SELECTOR)) visit(root);
|
|
553
|
+
for (const annotated of root.querySelectorAll(SOURCE_ANNOTATED_SELECTOR)) {
|
|
554
|
+
visit(annotated);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
const complete = targetElement === captureRoot;
|
|
558
|
+
return {
|
|
559
|
+
complete,
|
|
560
|
+
scopeSelector: complete ? null : scopeSelector,
|
|
561
|
+
observedVersions,
|
|
562
|
+
observedSourceVersions,
|
|
563
|
+
containedAnchors: Array.from(anchorSet),
|
|
564
|
+
renderError: computeRenderError(captureRoot)
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
function computeRenderError(captureRoot) {
|
|
568
|
+
const errorElement = captureRoot.matches('[data-render-error="true"]') ? captureRoot : captureRoot.querySelector('[data-render-error="true"]');
|
|
569
|
+
if (!errorElement) return null;
|
|
570
|
+
return {
|
|
571
|
+
message: errorElement.getAttribute("data-render-error-message")
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// ../../modules/iframe-projection/html/displayability.ts
|
|
576
|
+
var IGNORED_CONTENT_TAGS = /* @__PURE__ */ new Set([
|
|
577
|
+
"DATALIST",
|
|
578
|
+
"LINK",
|
|
579
|
+
"META",
|
|
580
|
+
"NOSCRIPT",
|
|
581
|
+
"SCRIPT",
|
|
582
|
+
"STYLE",
|
|
583
|
+
"TEMPLATE"
|
|
584
|
+
]);
|
|
585
|
+
var VISUAL_ASSET_TAGS = /* @__PURE__ */ new Set([
|
|
586
|
+
"AUDIO",
|
|
587
|
+
"CANVAS",
|
|
588
|
+
"EMBED",
|
|
589
|
+
"IFRAME",
|
|
590
|
+
"IMG",
|
|
591
|
+
"INPUT",
|
|
592
|
+
"OBJECT",
|
|
593
|
+
"SELECT",
|
|
594
|
+
"SVG",
|
|
595
|
+
"TEXTAREA",
|
|
596
|
+
"VIDEO"
|
|
597
|
+
]);
|
|
598
|
+
function measureComputedDisplayability(captureRoot, supplementalRoots = []) {
|
|
599
|
+
const doc = captureRoot.ownerDocument;
|
|
600
|
+
const view = doc.defaultView;
|
|
601
|
+
if (!view || !captureRoot.isConnected || supplementalRoots.some(
|
|
602
|
+
(root) => root.ownerDocument !== doc || !root.isConnected
|
|
603
|
+
)) {
|
|
604
|
+
return null;
|
|
605
|
+
}
|
|
606
|
+
const result = {
|
|
607
|
+
version: 1,
|
|
608
|
+
elementCount: 0,
|
|
609
|
+
paintedElementCount: 0,
|
|
610
|
+
nonEmptyTextNodeCount: 0,
|
|
611
|
+
visualAssetCount: 0
|
|
612
|
+
};
|
|
613
|
+
try {
|
|
614
|
+
const rootBlocked = hasBlockingElementInChain(captureRoot, view);
|
|
615
|
+
const rootTextVisible = !rootBlocked && elementHasVisibleComputedVisibility(captureRoot, view);
|
|
616
|
+
for (const child of Array.from(captureRoot.childNodes)) {
|
|
617
|
+
visitNode(child, rootBlocked, rootTextVisible, view, result);
|
|
618
|
+
}
|
|
619
|
+
for (const supplementalRoot of supplementalRoots) {
|
|
620
|
+
visitNode(
|
|
621
|
+
supplementalRoot,
|
|
622
|
+
hasBlockingElementInChain(supplementalRoot.parentElement, view),
|
|
623
|
+
true,
|
|
624
|
+
view,
|
|
625
|
+
result
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
} catch {
|
|
629
|
+
return null;
|
|
630
|
+
}
|
|
631
|
+
return result;
|
|
632
|
+
}
|
|
633
|
+
function visitNode(node, blockedByAncestor, parentTextVisible, view, result) {
|
|
634
|
+
if (node.nodeType === 3) {
|
|
635
|
+
if (!blockedByAncestor && parentTextVisible && (node.textContent?.trim().length ?? 0) > 0) {
|
|
636
|
+
result.nonEmptyTextNodeCount += 1;
|
|
637
|
+
}
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
if (node.nodeType !== 1) return;
|
|
641
|
+
const element = node;
|
|
642
|
+
const blocked = blockedByAncestor || elementBlocksSubtree(element, view);
|
|
643
|
+
if (blocked) return;
|
|
644
|
+
const visible = elementHasVisibleComputedVisibility(element, view);
|
|
645
|
+
if (visible) {
|
|
646
|
+
result.elementCount += 1;
|
|
647
|
+
if (elementPaintsOwnPixels(element, view)) {
|
|
648
|
+
result.paintedElementCount = (result.paintedElementCount ?? 0) + 1;
|
|
649
|
+
}
|
|
650
|
+
if (VISUAL_ASSET_TAGS.has(element.tagName)) {
|
|
651
|
+
result.visualAssetCount += 1;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
for (const child of Array.from(element.childNodes)) {
|
|
655
|
+
visitNode(child, false, visible, view, result);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
function elementPaintsOwnPixels(element, view) {
|
|
659
|
+
const style = view.getComputedStyle(element);
|
|
660
|
+
if (colorCanPaint(style.backgroundColor)) return true;
|
|
661
|
+
if (style.backgroundImage && style.backgroundImage !== "none") return true;
|
|
662
|
+
if (style.boxShadow && style.boxShadow !== "none") return true;
|
|
663
|
+
if (style.outlineStyle !== "none" && parseFloat(style.outlineWidth) > 0 && colorCanPaint(style.outlineColor)) {
|
|
664
|
+
return true;
|
|
665
|
+
}
|
|
666
|
+
for (const side of ["Top", "Right", "Bottom", "Left"]) {
|
|
667
|
+
if (style[`border${side}Style`] !== "none" && parseFloat(style[`border${side}Width`]) > 0 && colorCanPaint(style[`border${side}Color`])) {
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
function colorCanPaint(value) {
|
|
674
|
+
const normalized = value.trim().toLowerCase().replace(/ /g, "");
|
|
675
|
+
if (!normalized || normalized === "transparent") return false;
|
|
676
|
+
return !(/^rgba\([^)]*,0(?:\.0+)?\)$/.test(normalized) || /^rgb\([^)]*\/0(?:\.0+)?\)$/.test(normalized));
|
|
677
|
+
}
|
|
678
|
+
function hasBlockingElementInChain(start, view) {
|
|
679
|
+
for (let element = start; element; element = element.parentElement) {
|
|
680
|
+
if (elementBlocksSubtree(element, view)) return true;
|
|
681
|
+
}
|
|
682
|
+
return false;
|
|
683
|
+
}
|
|
684
|
+
function elementBlocksSubtree(element, view) {
|
|
685
|
+
if (IGNORED_CONTENT_TAGS.has(element.tagName)) return true;
|
|
686
|
+
if (element.hasAttribute("hidden")) return true;
|
|
687
|
+
if (element.tagName === "DIALOG" && !element.hasAttribute("open")) {
|
|
688
|
+
return true;
|
|
689
|
+
}
|
|
690
|
+
if (element.tagName === "INPUT" && element.getAttribute("type")?.trim().toLowerCase() === "hidden") {
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
693
|
+
const style = view.getComputedStyle(element);
|
|
694
|
+
const opacity = style.opacity.trim();
|
|
695
|
+
return style.display === "none" || opacity.length > 0 && Number(opacity) <= 0 || style.getPropertyValue("content-visibility") === "hidden";
|
|
696
|
+
}
|
|
697
|
+
function elementHasVisibleComputedVisibility(element, view) {
|
|
698
|
+
const visibility = view.getComputedStyle(element).visibility;
|
|
699
|
+
return visibility !== "hidden" && visibility !== "collapse";
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// ../../modules/iframe-projection/html/selectors.ts
|
|
703
|
+
function generateSelector(element, root) {
|
|
704
|
+
if (!root) {
|
|
705
|
+
if (element === document.documentElement) return ":root";
|
|
706
|
+
if (element === document.head) return "head";
|
|
707
|
+
if (element === document.body) return "body";
|
|
708
|
+
}
|
|
709
|
+
if (root && element === root) return "";
|
|
710
|
+
const parts = [];
|
|
711
|
+
let current = element;
|
|
712
|
+
const stopAt = root ?? document.documentElement;
|
|
713
|
+
while (current && current !== stopAt) {
|
|
714
|
+
const parent = current.parentElement;
|
|
715
|
+
if (!parent) break;
|
|
716
|
+
const tagName = current.tagName.toLowerCase();
|
|
717
|
+
let index = 1;
|
|
718
|
+
let sibling = current.previousElementSibling;
|
|
719
|
+
while (sibling) {
|
|
720
|
+
if (sibling.tagName === current.tagName) index++;
|
|
721
|
+
sibling = sibling.previousElementSibling;
|
|
722
|
+
}
|
|
723
|
+
let sameTypeSiblings = 0;
|
|
724
|
+
for (const child of parent.children) {
|
|
725
|
+
if (child.tagName === current.tagName) sameTypeSiblings++;
|
|
726
|
+
}
|
|
727
|
+
if (sameTypeSiblings > 1) {
|
|
728
|
+
parts.unshift(`${tagName}:nth-of-type(${index})`);
|
|
729
|
+
} else {
|
|
730
|
+
parts.unshift(tagName);
|
|
731
|
+
}
|
|
732
|
+
current = parent;
|
|
733
|
+
}
|
|
734
|
+
if (parts.length === 0) {
|
|
735
|
+
if (element === document.body) return "body";
|
|
736
|
+
if (element === document.head) return "head";
|
|
737
|
+
return "";
|
|
738
|
+
}
|
|
739
|
+
const path = parts.join(" > ");
|
|
740
|
+
if (root) return `:scope > ${path}`;
|
|
741
|
+
return path;
|
|
742
|
+
}
|
|
743
|
+
function findLowestCommonAncestor(nodes) {
|
|
744
|
+
if (nodes.size === 0) return null;
|
|
745
|
+
const ancestorChains = [];
|
|
746
|
+
for (const node of nodes) {
|
|
747
|
+
const chain = [];
|
|
748
|
+
let current = node instanceof Element ? node : node.parentElement;
|
|
749
|
+
while (current && current !== document) {
|
|
750
|
+
if (current instanceof Element) {
|
|
751
|
+
chain.unshift(current);
|
|
752
|
+
}
|
|
753
|
+
current = current.parentNode;
|
|
754
|
+
}
|
|
755
|
+
if (chain.length > 0) {
|
|
756
|
+
ancestorChains.push(chain);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
if (ancestorChains.length === 0) {
|
|
760
|
+
return document.documentElement;
|
|
761
|
+
}
|
|
762
|
+
let lca = document.documentElement;
|
|
763
|
+
const firstChain = ancestorChains[0];
|
|
764
|
+
const minLength = Math.min(...ancestorChains.map((c) => c.length));
|
|
765
|
+
for (let i = 0; i < minLength; i++) {
|
|
766
|
+
const candidate = firstChain[i];
|
|
767
|
+
if (candidate && ancestorChains.every((chain) => chain[i] === candidate)) {
|
|
768
|
+
lca = candidate;
|
|
769
|
+
} else {
|
|
770
|
+
break;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
return lca;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// ../../modules/iframe-projection/html/capture.ts
|
|
777
|
+
function captureWithSupplementalRoots(element, supplementalRoots) {
|
|
778
|
+
syncFormStateToAttributes(element);
|
|
779
|
+
const selector = generateSelector(element, element);
|
|
780
|
+
const html = removeScriptTags(element.innerHTML);
|
|
781
|
+
const attributes = captureAttributes(element);
|
|
782
|
+
const documentElementAttributes = element.ownerDocument ? captureAttributes(element.ownerDocument.documentElement) : void 0;
|
|
783
|
+
const baseUrl = element.ownerDocument?.baseURI;
|
|
784
|
+
const states = collectElementStates(element);
|
|
785
|
+
const displayability = measureComputedDisplayability(
|
|
786
|
+
element,
|
|
787
|
+
supplementalRoots
|
|
788
|
+
);
|
|
789
|
+
return {
|
|
790
|
+
// Whole-surface one-shot: the element is both the capture root and the
|
|
791
|
+
// serialized scope, so `complete` is true and there is no scope selector.
|
|
792
|
+
declared: computeDeclaredFacts(element, element, "", supplementalRoots),
|
|
793
|
+
...displayability && { displayability },
|
|
794
|
+
dom: { selector, html, attributes, documentElementAttributes },
|
|
795
|
+
states,
|
|
796
|
+
baseUrl
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
function syncFormStateToAttributes(root) {
|
|
800
|
+
for (const input of root.querySelectorAll(
|
|
801
|
+
'input[type="checkbox"], input[type="radio"]'
|
|
802
|
+
)) {
|
|
803
|
+
const el = input;
|
|
804
|
+
if (el.checked) {
|
|
805
|
+
el.setAttribute("checked", "");
|
|
806
|
+
} else {
|
|
807
|
+
el.removeAttribute("checked");
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
for (const input of root.querySelectorAll(
|
|
811
|
+
'input:not([type="checkbox"]):not([type="radio"])'
|
|
812
|
+
)) {
|
|
813
|
+
const el = input;
|
|
814
|
+
if (el.value !== el.getAttribute("value")) {
|
|
815
|
+
el.setAttribute("value", el.value);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
for (const textarea of root.querySelectorAll("textarea")) {
|
|
819
|
+
const el = textarea;
|
|
820
|
+
if (el.value !== el.textContent) {
|
|
821
|
+
el.textContent = el.value;
|
|
822
|
+
}
|
|
823
|
+
if (el.hasAttribute("value")) {
|
|
824
|
+
el.removeAttribute("value");
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
for (const select of root.querySelectorAll("select")) {
|
|
828
|
+
const el = select;
|
|
829
|
+
for (const option of el.options) {
|
|
830
|
+
if (option.selected) {
|
|
831
|
+
option.setAttribute("selected", "");
|
|
832
|
+
} else {
|
|
833
|
+
option.removeAttribute("selected");
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
function removeScriptTags(html) {
|
|
839
|
+
return html.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "");
|
|
840
|
+
}
|
|
841
|
+
function captureAttributes(element) {
|
|
842
|
+
const attrs = {};
|
|
843
|
+
for (const attr of Array.from(element.attributes)) {
|
|
844
|
+
attrs[attr.name] = attr.value;
|
|
845
|
+
}
|
|
846
|
+
return attrs;
|
|
847
|
+
}
|
|
848
|
+
function collectElementStates(root, options = {}) {
|
|
849
|
+
const { includeDocumentScroll = true } = options;
|
|
850
|
+
const states = [];
|
|
851
|
+
for (const input of root.querySelectorAll("input")) {
|
|
852
|
+
const el = input;
|
|
853
|
+
const isCheckable = el.type === "checkbox" || el.type === "radio";
|
|
854
|
+
const hasNonDefault = isCheckable ? el.checked !== el.defaultChecked : el.value !== el.defaultValue;
|
|
855
|
+
if (hasNonDefault) {
|
|
856
|
+
const selector = generateSelector(el, root);
|
|
857
|
+
if (isCheckable) {
|
|
858
|
+
states.push({ selector, checked: el.checked });
|
|
859
|
+
} else {
|
|
860
|
+
states.push({ selector, value: el.value });
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
for (const textarea of root.querySelectorAll("textarea")) {
|
|
865
|
+
const el = textarea;
|
|
866
|
+
if (el.value !== el.defaultValue) {
|
|
867
|
+
const selector = generateSelector(el, root);
|
|
868
|
+
states.push({ selector, value: el.value });
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
for (const select of root.querySelectorAll("select")) {
|
|
872
|
+
const el = select;
|
|
873
|
+
for (const option of el.options) {
|
|
874
|
+
if (option.selected !== option.defaultSelected) {
|
|
875
|
+
const selector = generateSelector(option, root);
|
|
876
|
+
states.push({ selector, selected: option.selected });
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
states.push({
|
|
881
|
+
selector: "",
|
|
882
|
+
scrollTop: root.scrollTop,
|
|
883
|
+
scrollLeft: root.scrollLeft
|
|
884
|
+
});
|
|
885
|
+
if (includeDocumentScroll) {
|
|
886
|
+
const scrollingEl = root.ownerDocument?.scrollingElement;
|
|
887
|
+
if (scrollingEl && scrollingEl !== root) {
|
|
888
|
+
states.push({
|
|
889
|
+
selector: ":root",
|
|
890
|
+
scrollTop: scrollingEl.scrollTop,
|
|
891
|
+
scrollLeft: scrollingEl.scrollLeft
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
for (const el of root.querySelectorAll("*")) {
|
|
896
|
+
if (el.scrollTop > 0 || el.scrollLeft > 0) {
|
|
897
|
+
const selector = generateSelector(el, root);
|
|
898
|
+
states.push({
|
|
899
|
+
selector,
|
|
900
|
+
scrollTop: el.scrollTop,
|
|
901
|
+
scrollLeft: el.scrollLeft
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
return states;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// ../../modules/iframe-projection/html/watch-head.ts
|
|
909
|
+
var INCLUDE_TAGS = /* @__PURE__ */ new Set(["STYLE", "META", "BASE", "LINK"]);
|
|
910
|
+
var INCLUDE_LINK_RELS = /* @__PURE__ */ new Set(["stylesheet"]);
|
|
911
|
+
var instance = null;
|
|
912
|
+
function getHeadTracker() {
|
|
913
|
+
if (!instance) {
|
|
914
|
+
instance = new HeadTrackerImpl();
|
|
915
|
+
}
|
|
916
|
+
return instance;
|
|
917
|
+
}
|
|
918
|
+
var HeadSubscriptionImpl = class {
|
|
919
|
+
constructor(doc, callback, onUnsubscribe) {
|
|
920
|
+
this.hasMutations = false;
|
|
921
|
+
this.doc = doc;
|
|
922
|
+
this.callback = callback;
|
|
923
|
+
this.onUnsubscribe = onUnsubscribe;
|
|
924
|
+
}
|
|
925
|
+
flush(isInitial) {
|
|
926
|
+
if (!isInitial && !this.hasMutations) {
|
|
927
|
+
return void 0;
|
|
928
|
+
}
|
|
929
|
+
this.hasMutations = false;
|
|
930
|
+
return captureHead(this.doc);
|
|
931
|
+
}
|
|
932
|
+
unsubscribe() {
|
|
933
|
+
this.onUnsubscribe();
|
|
934
|
+
}
|
|
935
|
+
/** Called by tracker when relevant mutation detected */
|
|
936
|
+
notifyMutation(details) {
|
|
937
|
+
this.hasMutations = true;
|
|
938
|
+
this.callback(details);
|
|
939
|
+
}
|
|
940
|
+
};
|
|
941
|
+
var HeadTrackerImpl = class {
|
|
942
|
+
constructor() {
|
|
943
|
+
this.docObservers = /* @__PURE__ */ new Map();
|
|
944
|
+
}
|
|
945
|
+
subscribe(doc, onMutation) {
|
|
946
|
+
let docState = this.docObservers.get(doc);
|
|
947
|
+
if (!docState) {
|
|
948
|
+
docState = this.createDocObserver(doc);
|
|
949
|
+
this.docObservers.set(doc, docState);
|
|
950
|
+
}
|
|
951
|
+
const subscription = new HeadSubscriptionImpl(doc, onMutation, () => {
|
|
952
|
+
this.unsubscribe(doc, subscription);
|
|
953
|
+
});
|
|
954
|
+
docState.subscriptions.add(subscription);
|
|
955
|
+
return subscription;
|
|
956
|
+
}
|
|
957
|
+
createDocObserver(doc) {
|
|
958
|
+
const subscriptions = /* @__PURE__ */ new Set();
|
|
959
|
+
const head = doc.head;
|
|
960
|
+
const observer = new MutationObserver((mutations) => {
|
|
961
|
+
if (!head) {
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
const details = this.readRelevantMutations(mutations, head);
|
|
965
|
+
if (!details) return;
|
|
966
|
+
for (const sub of subscriptions) {
|
|
967
|
+
sub.notifyMutation(details);
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
if (head) {
|
|
971
|
+
observer.observe(head, {
|
|
972
|
+
childList: true,
|
|
973
|
+
subtree: true,
|
|
974
|
+
attributes: true,
|
|
975
|
+
characterData: true
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
return { observer, subscriptions };
|
|
979
|
+
}
|
|
980
|
+
unsubscribe(doc, sub) {
|
|
981
|
+
const docState = this.docObservers.get(doc);
|
|
982
|
+
if (!docState) return;
|
|
983
|
+
docState.subscriptions.delete(sub);
|
|
984
|
+
if (docState.subscriptions.size === 0) {
|
|
985
|
+
docState.observer.disconnect();
|
|
986
|
+
this.docObservers.delete(doc);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Check if mutations contain changes to elements we care about.
|
|
991
|
+
* This filtering runs once per mutation batch (not once per subscription).
|
|
992
|
+
*/
|
|
993
|
+
readRelevantMutations(mutations, head) {
|
|
994
|
+
let relevant = false;
|
|
995
|
+
const stylesheetPaths = /* @__PURE__ */ new Set();
|
|
996
|
+
const collectStylesheetPath = (node) => {
|
|
997
|
+
const element = node instanceof Element ? node : node?.parentElement ?? null;
|
|
998
|
+
if (!element) return;
|
|
999
|
+
const candidates = [
|
|
1000
|
+
element,
|
|
1001
|
+
...element.querySelectorAll(
|
|
1002
|
+
"style[data-vite-dev-id], link[rel~='stylesheet']"
|
|
1003
|
+
)
|
|
1004
|
+
];
|
|
1005
|
+
for (const candidate of candidates) {
|
|
1006
|
+
if (candidate instanceof HTMLStyleElement) {
|
|
1007
|
+
const id = candidate.getAttribute("data-vite-dev-id")?.trim();
|
|
1008
|
+
if (id) stylesheetPaths.add(id);
|
|
1009
|
+
} else if (candidate instanceof HTMLLinkElement && shouldIncludeLink(candidate)) {
|
|
1010
|
+
const href = candidate.getAttribute("href")?.trim() || candidate.href;
|
|
1011
|
+
if (href) stylesheetPaths.add(href);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
for (const mutation of mutations) {
|
|
1016
|
+
const target = mutation.target;
|
|
1017
|
+
const element = target instanceof Element ? target : target.parentElement;
|
|
1018
|
+
if (!element || !head.contains(element) && target !== head) continue;
|
|
1019
|
+
const tagName = element.tagName;
|
|
1020
|
+
if (INCLUDE_TAGS.has(tagName)) {
|
|
1021
|
+
if (tagName === "LINK") {
|
|
1022
|
+
if (!shouldIncludeLink(element)) continue;
|
|
1023
|
+
}
|
|
1024
|
+
relevant = true;
|
|
1025
|
+
collectStylesheetPath(element);
|
|
1026
|
+
}
|
|
1027
|
+
if (mutation.type === "childList" && target === head) {
|
|
1028
|
+
relevant = true;
|
|
1029
|
+
}
|
|
1030
|
+
if (mutation.type === "childList") {
|
|
1031
|
+
for (const node of mutation.addedNodes) collectStylesheetPath(node);
|
|
1032
|
+
for (const node of mutation.removedNodes) collectStylesheetPath(node);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
return relevant ? { stylesheetPaths: [...stylesheetPaths] } : null;
|
|
1036
|
+
}
|
|
1037
|
+
destroy() {
|
|
1038
|
+
for (const docState of this.docObservers.values()) {
|
|
1039
|
+
docState.observer.disconnect();
|
|
1040
|
+
docState.subscriptions.clear();
|
|
1041
|
+
}
|
|
1042
|
+
this.docObservers.clear();
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
function captureHead(doc) {
|
|
1046
|
+
const head = doc.head;
|
|
1047
|
+
if (!head) return "";
|
|
1048
|
+
const baseURI = doc.baseURI;
|
|
1049
|
+
const fragments = [];
|
|
1050
|
+
for (const child of Array.from(head.children)) {
|
|
1051
|
+
const tagName = child.tagName;
|
|
1052
|
+
if (!INCLUDE_TAGS.has(tagName)) continue;
|
|
1053
|
+
if (tagName === "LINK") {
|
|
1054
|
+
if (!shouldIncludeLink(child)) continue;
|
|
1055
|
+
}
|
|
1056
|
+
if (tagName === "META") {
|
|
1057
|
+
const httpEquiv = child.getAttribute("http-equiv")?.toLowerCase();
|
|
1058
|
+
const name = child.getAttribute("name")?.toLowerCase();
|
|
1059
|
+
if (httpEquiv === "content-security-policy" || name === "content-security-policy") {
|
|
1060
|
+
continue;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
const clone = child.cloneNode(true);
|
|
1064
|
+
materializeStyleElementCssom(child, clone);
|
|
1065
|
+
resolveUrls(clone, baseURI);
|
|
1066
|
+
if (tagName === "LINK") {
|
|
1067
|
+
clone.removeAttribute("crossorigin");
|
|
1068
|
+
}
|
|
1069
|
+
fragments.push(clone.outerHTML);
|
|
1070
|
+
}
|
|
1071
|
+
fragments.push(...captureAdoptedStyleSheets(doc));
|
|
1072
|
+
return fragments.join("\n");
|
|
1073
|
+
}
|
|
1074
|
+
function materializeStyleElementCssom(source, clone) {
|
|
1075
|
+
if (source.tagName !== "STYLE" || clone.tagName !== "STYLE") {
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
const style = source;
|
|
1079
|
+
const text = style.textContent ?? "";
|
|
1080
|
+
if (text.trim().length > 0) {
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
const cssText = serializeCssRules(style.sheet);
|
|
1084
|
+
if (cssText) {
|
|
1085
|
+
clone.textContent = cssText;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
function captureAdoptedStyleSheets(doc) {
|
|
1089
|
+
const sheets = Array.from(doc.adoptedStyleSheets ?? []);
|
|
1090
|
+
if (sheets.length === 0) {
|
|
1091
|
+
return [];
|
|
1092
|
+
}
|
|
1093
|
+
const fragments = [];
|
|
1094
|
+
for (const sheet of sheets) {
|
|
1095
|
+
const cssText = serializeCssRules(sheet);
|
|
1096
|
+
if (!cssText) {
|
|
1097
|
+
continue;
|
|
1098
|
+
}
|
|
1099
|
+
const style = doc.createElement("style");
|
|
1100
|
+
style.setAttribute("data-projection-adopted-stylesheet", "true");
|
|
1101
|
+
style.textContent = cssText;
|
|
1102
|
+
fragments.push(style.outerHTML);
|
|
1103
|
+
}
|
|
1104
|
+
return fragments;
|
|
1105
|
+
}
|
|
1106
|
+
function serializeCssRules(sheet) {
|
|
1107
|
+
if (!sheet) {
|
|
1108
|
+
return "";
|
|
1109
|
+
}
|
|
1110
|
+
try {
|
|
1111
|
+
return Array.from(sheet.cssRules).map((rule) => rule.cssText).join("\n");
|
|
1112
|
+
} catch {
|
|
1113
|
+
return "";
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
function shouldIncludeLink(element) {
|
|
1117
|
+
const rel = element.getAttribute("rel");
|
|
1118
|
+
if (!rel) {
|
|
1119
|
+
return false;
|
|
1120
|
+
}
|
|
1121
|
+
return rel.toLowerCase().split(/\s+/).some((token) => INCLUDE_LINK_RELS.has(token));
|
|
1122
|
+
}
|
|
1123
|
+
function resolveUrls(element, baseURI) {
|
|
1124
|
+
if (!baseURI || !baseURI.startsWith("http")) {
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
const href = element.getAttribute("href");
|
|
1128
|
+
if (href && !isAbsoluteUrl(href)) {
|
|
1129
|
+
try {
|
|
1130
|
+
element.setAttribute("href", new URL(href, baseURI).href);
|
|
1131
|
+
} catch {
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
const src = element.getAttribute("src");
|
|
1135
|
+
if (src && !isAbsoluteUrl(src)) {
|
|
1136
|
+
try {
|
|
1137
|
+
element.setAttribute("src", new URL(src, baseURI).href);
|
|
1138
|
+
} catch {
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
function isAbsoluteUrl(url) {
|
|
1143
|
+
return /^(https?:)?\/\//i.test(url) || url.startsWith("data:");
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
// ../../modules/iframe-projection/html/watch-dom.ts
|
|
1147
|
+
var DOM_ID_ATTR = "data-dom-id";
|
|
1148
|
+
var sessionHash = null;
|
|
1149
|
+
var idCounter = 0;
|
|
1150
|
+
function getOrCreateSessionHash() {
|
|
1151
|
+
if (sessionHash === null) {
|
|
1152
|
+
sessionHash = Math.random().toString(36).substring(2, 6);
|
|
1153
|
+
}
|
|
1154
|
+
return sessionHash;
|
|
1155
|
+
}
|
|
1156
|
+
function assignDomId(element) {
|
|
1157
|
+
const existing = element.getAttribute(DOM_ID_ATTR);
|
|
1158
|
+
if (existing !== null) {
|
|
1159
|
+
return existing;
|
|
1160
|
+
}
|
|
1161
|
+
const id = `${getOrCreateSessionHash()}-${idCounter++}`;
|
|
1162
|
+
element.setAttribute(DOM_ID_ATTR, id);
|
|
1163
|
+
return id;
|
|
1164
|
+
}
|
|
1165
|
+
function isContentEditableRoot(element) {
|
|
1166
|
+
return element.getAttribute("contenteditable") !== null;
|
|
1167
|
+
}
|
|
1168
|
+
function hasContentEditableAncestor(element) {
|
|
1169
|
+
let current = element.parentElement;
|
|
1170
|
+
while (current) {
|
|
1171
|
+
if (current.getAttribute("contenteditable") !== null) {
|
|
1172
|
+
return true;
|
|
1173
|
+
}
|
|
1174
|
+
current = current.parentElement;
|
|
1175
|
+
}
|
|
1176
|
+
return false;
|
|
1177
|
+
}
|
|
1178
|
+
function assignDomIdToTree(root) {
|
|
1179
|
+
if (hasContentEditableAncestor(root)) {
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
assignDomId(root);
|
|
1183
|
+
if (isContentEditableRoot(root)) {
|
|
1184
|
+
return;
|
|
1185
|
+
}
|
|
1186
|
+
const stack = [];
|
|
1187
|
+
for (let i = root.children.length - 1; i >= 0; i--) {
|
|
1188
|
+
stack.push(root.children[i]);
|
|
1189
|
+
}
|
|
1190
|
+
while (stack.length > 0) {
|
|
1191
|
+
const element = stack.pop();
|
|
1192
|
+
assignDomId(element);
|
|
1193
|
+
if (isContentEditableRoot(element)) {
|
|
1194
|
+
continue;
|
|
1195
|
+
}
|
|
1196
|
+
for (let i = element.children.length - 1; i >= 0; i--) {
|
|
1197
|
+
stack.push(element.children[i]);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
function watchDom(root, onMutation) {
|
|
1202
|
+
const mutatedElements = /* @__PURE__ */ new Set();
|
|
1203
|
+
assignDomIdToTree(root);
|
|
1204
|
+
const observer = new MutationObserver((mutations) => {
|
|
1205
|
+
for (const mutation of mutations) {
|
|
1206
|
+
const target = mutation.target instanceof Element ? mutation.target : mutation.target.parentElement;
|
|
1207
|
+
if (target && root.contains(target)) {
|
|
1208
|
+
mutatedElements.add(target);
|
|
1209
|
+
}
|
|
1210
|
+
if (mutation.type === "childList") {
|
|
1211
|
+
for (const node of mutation.addedNodes) {
|
|
1212
|
+
if (node instanceof Element && root.contains(node)) {
|
|
1213
|
+
assignDomIdToTree(node);
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
if (mutation.target instanceof Element && root.contains(mutation.target)) {
|
|
1217
|
+
mutatedElements.add(mutation.target);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
if (mutatedElements.size > 0) {
|
|
1222
|
+
onMutation();
|
|
1223
|
+
}
|
|
1224
|
+
});
|
|
1225
|
+
observer.observe(root, {
|
|
1226
|
+
childList: true,
|
|
1227
|
+
subtree: true,
|
|
1228
|
+
attributes: true,
|
|
1229
|
+
characterData: true
|
|
1230
|
+
});
|
|
1231
|
+
return {
|
|
1232
|
+
root,
|
|
1233
|
+
mutatedElements,
|
|
1234
|
+
stop: () => {
|
|
1235
|
+
observer.disconnect();
|
|
1236
|
+
mutatedElements.clear();
|
|
1237
|
+
}
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
function flushDomWatcher(watcher) {
|
|
1241
|
+
if (watcher.mutatedElements.size === 0) {
|
|
1242
|
+
return null;
|
|
1243
|
+
}
|
|
1244
|
+
const lca = findLowestCommonAncestor(watcher.mutatedElements);
|
|
1245
|
+
watcher.mutatedElements.clear();
|
|
1246
|
+
if (lca && !watcher.root.contains(lca) && lca !== watcher.root) {
|
|
1247
|
+
return watcher.root;
|
|
1248
|
+
}
|
|
1249
|
+
return lca;
|
|
1250
|
+
}
|
|
1251
|
+
function hasPendingMutations(watcher) {
|
|
1252
|
+
return watcher.mutatedElements.size > 0;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
// ../../modules/iframe-projection/html/watch-state.ts
|
|
1256
|
+
function watchState(root, onStateChange) {
|
|
1257
|
+
const scrolledElements = /* @__PURE__ */ new Set();
|
|
1258
|
+
const changedFormElements = /* @__PURE__ */ new Set();
|
|
1259
|
+
const handleScroll = (event) => {
|
|
1260
|
+
const target = event.target;
|
|
1261
|
+
if (target instanceof Element && root.contains(target)) {
|
|
1262
|
+
scrolledElements.add(target);
|
|
1263
|
+
onStateChange();
|
|
1264
|
+
} else if (target === document) {
|
|
1265
|
+
const scrollTarget = document.scrollingElement || document.documentElement;
|
|
1266
|
+
if (scrollTarget) {
|
|
1267
|
+
scrolledElements.add(scrollTarget);
|
|
1268
|
+
onStateChange();
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
};
|
|
1272
|
+
const handleFormChange = (event) => {
|
|
1273
|
+
if (event.target instanceof Element && root.contains(event.target)) {
|
|
1274
|
+
changedFormElements.add(event.target);
|
|
1275
|
+
onStateChange();
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
document.addEventListener("scroll", handleScroll, true);
|
|
1279
|
+
document.addEventListener("input", handleFormChange, true);
|
|
1280
|
+
document.addEventListener("change", handleFormChange, true);
|
|
1281
|
+
return {
|
|
1282
|
+
root,
|
|
1283
|
+
scrolledElements,
|
|
1284
|
+
changedFormElements,
|
|
1285
|
+
stop: () => {
|
|
1286
|
+
document.removeEventListener("scroll", handleScroll, true);
|
|
1287
|
+
document.removeEventListener("input", handleFormChange, true);
|
|
1288
|
+
document.removeEventListener("change", handleFormChange, true);
|
|
1289
|
+
scrolledElements.clear();
|
|
1290
|
+
changedFormElements.clear();
|
|
1291
|
+
}
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
1294
|
+
function flushStateWatcher(watcher) {
|
|
1295
|
+
const { root, scrolledElements, changedFormElements } = watcher;
|
|
1296
|
+
const states = [];
|
|
1297
|
+
const scrolled = new Set(scrolledElements);
|
|
1298
|
+
const changed = new Set(changedFormElements);
|
|
1299
|
+
scrolledElements.clear();
|
|
1300
|
+
changedFormElements.clear();
|
|
1301
|
+
for (const el of scrolled) {
|
|
1302
|
+
const isDocumentScroll = el === document.scrollingElement || el === document.documentElement;
|
|
1303
|
+
if (!isDocumentScroll && !root.contains(el)) continue;
|
|
1304
|
+
const selector = isDocumentScroll ? ":root" : generateSelector(el, root);
|
|
1305
|
+
states.push({
|
|
1306
|
+
selector,
|
|
1307
|
+
scrollTop: el.scrollTop,
|
|
1308
|
+
scrollLeft: el.scrollLeft
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
for (const el of changed) {
|
|
1312
|
+
if (!root.contains(el)) continue;
|
|
1313
|
+
if (el instanceof HTMLInputElement) {
|
|
1314
|
+
const isCheckable = el.type === "checkbox" || el.type === "radio";
|
|
1315
|
+
const hasNonDefault = isCheckable ? el.checked !== el.defaultChecked : el.value !== el.defaultValue;
|
|
1316
|
+
if (hasNonDefault) {
|
|
1317
|
+
const selector = generateSelector(el, root);
|
|
1318
|
+
if (isCheckable) {
|
|
1319
|
+
states.push({ selector, checked: el.checked });
|
|
1320
|
+
} else {
|
|
1321
|
+
states.push({ selector, value: el.value });
|
|
1322
|
+
}
|
|
1323
|
+
changedFormElements.add(el);
|
|
1324
|
+
}
|
|
1325
|
+
} else if (el instanceof HTMLTextAreaElement) {
|
|
1326
|
+
if (el.value !== el.defaultValue) {
|
|
1327
|
+
const selector = generateSelector(el, root);
|
|
1328
|
+
states.push({ selector, value: el.value });
|
|
1329
|
+
changedFormElements.add(el);
|
|
1330
|
+
}
|
|
1331
|
+
} else if (el instanceof HTMLSelectElement) {
|
|
1332
|
+
let hasNonDefault = false;
|
|
1333
|
+
for (const option of el.options) {
|
|
1334
|
+
if (option.selected !== option.defaultSelected) {
|
|
1335
|
+
const selector = generateSelector(option, root);
|
|
1336
|
+
states.push({ selector, selected: option.selected });
|
|
1337
|
+
hasNonDefault = true;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
if (hasNonDefault) {
|
|
1341
|
+
changedFormElements.add(el);
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
return states;
|
|
1346
|
+
}
|
|
1347
|
+
function hasPendingStateChanges(watcher) {
|
|
1348
|
+
return watcher.scrolledElements.size > 0 || watcher.changedFormElements.size > 0;
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
// ../../modules/iframe-projection/html/watch-portal.ts
|
|
1352
|
+
var portalIdCounter = 0;
|
|
1353
|
+
var PORTAL_ID_ATTR = "data-projection-portal-id";
|
|
1354
|
+
function watchPortal(element, onTrigger) {
|
|
1355
|
+
let id = element.getAttribute(PORTAL_ID_ATTR);
|
|
1356
|
+
if (!id) {
|
|
1357
|
+
id = `portal-${++portalIdCounter}`;
|
|
1358
|
+
element.setAttribute(PORTAL_ID_ATTR, id);
|
|
1359
|
+
}
|
|
1360
|
+
const domWatcher = watchDom(element, onTrigger);
|
|
1361
|
+
const stateWatcher = watchState(element, onTrigger);
|
|
1362
|
+
return {
|
|
1363
|
+
id,
|
|
1364
|
+
element,
|
|
1365
|
+
hasPendingChanges() {
|
|
1366
|
+
return hasPendingMutations(domWatcher) || hasPendingStateChanges(stateWatcher);
|
|
1367
|
+
},
|
|
1368
|
+
flush(isInitial = false) {
|
|
1369
|
+
const hasDomChanges = hasPendingMutations(domWatcher);
|
|
1370
|
+
const hasStateChanges = hasPendingStateChanges(stateWatcher);
|
|
1371
|
+
if (!isInitial && !hasDomChanges && !hasStateChanges) {
|
|
1372
|
+
return null;
|
|
1373
|
+
}
|
|
1374
|
+
let targetElement = element;
|
|
1375
|
+
if (!isInitial && hasDomChanges) {
|
|
1376
|
+
const lca = flushDomWatcher(domWatcher);
|
|
1377
|
+
if (lca && element.contains(lca)) {
|
|
1378
|
+
targetElement = lca;
|
|
1379
|
+
}
|
|
1380
|
+
} else {
|
|
1381
|
+
flushDomWatcher(domWatcher);
|
|
1382
|
+
}
|
|
1383
|
+
const states = flushStateWatcher(stateWatcher);
|
|
1384
|
+
const selector = generateSelector(targetElement, element);
|
|
1385
|
+
const html = removeScriptTags(targetElement.outerHTML);
|
|
1386
|
+
return { id, selector, html, states };
|
|
1387
|
+
},
|
|
1388
|
+
stop() {
|
|
1389
|
+
domWatcher.stop();
|
|
1390
|
+
stateWatcher.stop();
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
function createPortalRemovedUpdate(id) {
|
|
1395
|
+
return {
|
|
1396
|
+
id,
|
|
1397
|
+
selector: "",
|
|
1398
|
+
html: "",
|
|
1399
|
+
states: [],
|
|
1400
|
+
removed: true
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
// ../../modules/iframe-projection/html/snapshot.ts
|
|
1405
|
+
var nextPortalId = 1;
|
|
1406
|
+
function captureProjectionSnapshot(element, supplementalRoots) {
|
|
1407
|
+
const head = captureHead(element.ownerDocument ?? document);
|
|
1408
|
+
const { updates: portals, elements: portalElements } = supplementalRoots ? captureKnownPortals(supplementalRoots) : capturePortals(element);
|
|
1409
|
+
const baseCapture = captureWithSupplementalRoots(element, portalElements);
|
|
1410
|
+
return {
|
|
1411
|
+
...baseCapture,
|
|
1412
|
+
portalsComplete: true,
|
|
1413
|
+
head,
|
|
1414
|
+
...portals.length > 0 ? { portals } : {}
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
function captureKnownPortals(roots) {
|
|
1418
|
+
const updates = [];
|
|
1419
|
+
const elements = [];
|
|
1420
|
+
for (const root of roots) {
|
|
1421
|
+
if (!root.isConnected) continue;
|
|
1422
|
+
const id = getOrAssignPortalId(root);
|
|
1423
|
+
updates.push({
|
|
1424
|
+
id,
|
|
1425
|
+
selector: "",
|
|
1426
|
+
html: removeScriptTags(root.outerHTML),
|
|
1427
|
+
states: collectElementStates(root, { includeDocumentScroll: false })
|
|
1428
|
+
});
|
|
1429
|
+
elements.push(root);
|
|
1430
|
+
}
|
|
1431
|
+
return { updates, elements };
|
|
1432
|
+
}
|
|
1433
|
+
function capturePortals(root) {
|
|
1434
|
+
const doc = root.ownerDocument;
|
|
1435
|
+
const body = doc?.body;
|
|
1436
|
+
if (!body) return { updates: [], elements: [] };
|
|
1437
|
+
const updates = [];
|
|
1438
|
+
const elements = [];
|
|
1439
|
+
for (const child of Array.from(body.children)) {
|
|
1440
|
+
if (child === root || root.contains(child)) {
|
|
1441
|
+
continue;
|
|
1442
|
+
}
|
|
1443
|
+
if (!isPortalForRoot(child, root)) {
|
|
1444
|
+
continue;
|
|
1445
|
+
}
|
|
1446
|
+
const id = getOrAssignPortalId(child);
|
|
1447
|
+
updates.push({
|
|
1448
|
+
id,
|
|
1449
|
+
selector: "",
|
|
1450
|
+
html: removeScriptTags(child.outerHTML),
|
|
1451
|
+
states: collectElementStates(child, { includeDocumentScroll: false })
|
|
1452
|
+
});
|
|
1453
|
+
elements.push(child);
|
|
1454
|
+
}
|
|
1455
|
+
return { updates, elements };
|
|
1456
|
+
}
|
|
1457
|
+
function isPortalForRoot(candidate, root) {
|
|
1458
|
+
const fiber = getFiberFromElement(candidate);
|
|
1459
|
+
if (!fiber) {
|
|
1460
|
+
return false;
|
|
1461
|
+
}
|
|
1462
|
+
let current = fiber.return;
|
|
1463
|
+
while (current) {
|
|
1464
|
+
if (current.stateNode instanceof Element) {
|
|
1465
|
+
const ancestor = current.stateNode;
|
|
1466
|
+
if (ancestor === root || root.contains(ancestor)) {
|
|
1467
|
+
return true;
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
current = current.return;
|
|
1471
|
+
}
|
|
1472
|
+
return false;
|
|
1473
|
+
}
|
|
1474
|
+
function getOrAssignPortalId(element) {
|
|
1475
|
+
const existing = element.getAttribute(PORTAL_ID_ATTR);
|
|
1476
|
+
if (existing) {
|
|
1477
|
+
return existing;
|
|
1478
|
+
}
|
|
1479
|
+
const id = `portal-${nextPortalId++}`;
|
|
1480
|
+
element.setAttribute(PORTAL_ID_ATTR, id);
|
|
1481
|
+
return id;
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
// ../../modules/iframe-projection/shared/portal-tracker.ts
|
|
1485
|
+
var instance2 = null;
|
|
1486
|
+
function getPortalTracker() {
|
|
1487
|
+
if (!instance2) {
|
|
1488
|
+
instance2 = new PortalTrackerImpl();
|
|
1489
|
+
}
|
|
1490
|
+
return instance2;
|
|
1491
|
+
}
|
|
1492
|
+
var PortalTrackerImpl = class {
|
|
1493
|
+
constructor() {
|
|
1494
|
+
this.watchers = /* @__PURE__ */ new Set();
|
|
1495
|
+
this.trackedPortals = /* @__PURE__ */ new Map();
|
|
1496
|
+
// portal element -> subscribed watchers
|
|
1497
|
+
this.observer = null;
|
|
1498
|
+
this.handleMutations = (mutations) => {
|
|
1499
|
+
for (const mutation of mutations) {
|
|
1500
|
+
for (const node of mutation.addedNodes) {
|
|
1501
|
+
if (node instanceof Element) {
|
|
1502
|
+
queueMicrotask(() => this.checkElement(node));
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
for (const node of mutation.removedNodes) {
|
|
1506
|
+
if (node instanceof Element) {
|
|
1507
|
+
const owners = this.trackedPortals.get(node);
|
|
1508
|
+
if (owners) {
|
|
1509
|
+
for (const owner of owners) {
|
|
1510
|
+
owner.onPortalRemoved(node);
|
|
1511
|
+
}
|
|
1512
|
+
this.trackedPortals.delete(node);
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
register(watcher) {
|
|
1520
|
+
this.watchers.add(watcher);
|
|
1521
|
+
if (this.watchers.size === 1) {
|
|
1522
|
+
this.startObserving();
|
|
1523
|
+
}
|
|
1524
|
+
for (const child of Array.from(document.body.children)) {
|
|
1525
|
+
this.checkElement(child);
|
|
1526
|
+
}
|
|
1527
|
+
return () => this.unregister(watcher);
|
|
1528
|
+
}
|
|
1529
|
+
unregister(watcher) {
|
|
1530
|
+
this.watchers.delete(watcher);
|
|
1531
|
+
for (const [portal, owners] of this.trackedPortals) {
|
|
1532
|
+
owners.delete(watcher);
|
|
1533
|
+
if (owners.size === 0) {
|
|
1534
|
+
this.trackedPortals.delete(portal);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
if (this.watchers.size === 0) {
|
|
1538
|
+
this.stopObserving();
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
destroy() {
|
|
1542
|
+
this.stopObserving();
|
|
1543
|
+
this.watchers.clear();
|
|
1544
|
+
this.trackedPortals.clear();
|
|
1545
|
+
}
|
|
1546
|
+
startObserving() {
|
|
1547
|
+
if (this.observer) return;
|
|
1548
|
+
this.observer = new MutationObserver(this.handleMutations);
|
|
1549
|
+
this.observer.observe(document.body, { childList: true });
|
|
1550
|
+
}
|
|
1551
|
+
stopObserving() {
|
|
1552
|
+
this.observer?.disconnect();
|
|
1553
|
+
this.observer = null;
|
|
1554
|
+
}
|
|
1555
|
+
/**
|
|
1556
|
+
* Check if an element is a portal belonging to any registered watcher.
|
|
1557
|
+
*/
|
|
1558
|
+
checkElement(element) {
|
|
1559
|
+
const ancestorDomNodes = this.getDomAncestorsViaFiber(element);
|
|
1560
|
+
if (ancestorDomNodes.length === 0) return;
|
|
1561
|
+
let owners = this.trackedPortals.get(element);
|
|
1562
|
+
for (const watcher of this.watchers) {
|
|
1563
|
+
const belongsToWatcher = ancestorDomNodes.some(
|
|
1564
|
+
(node) => watcher.element.contains(node) || watcher.element === node
|
|
1565
|
+
);
|
|
1566
|
+
if (belongsToWatcher) {
|
|
1567
|
+
if (!owners) {
|
|
1568
|
+
owners = /* @__PURE__ */ new Set();
|
|
1569
|
+
this.trackedPortals.set(element, owners);
|
|
1570
|
+
}
|
|
1571
|
+
if (owners.has(watcher)) {
|
|
1572
|
+
continue;
|
|
1573
|
+
}
|
|
1574
|
+
owners.add(watcher);
|
|
1575
|
+
watcher.onPortalFound(element);
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
/**
|
|
1580
|
+
* Walk up the fiber tree from an element and collect all DOM nodes encountered.
|
|
1581
|
+
*
|
|
1582
|
+
* React fibers form a tree where fiber.return points to the parent.
|
|
1583
|
+
* For HostComponent fibers (DOM elements), stateNode is the DOM Element.
|
|
1584
|
+
* By collecting these, we get the "DOM ancestry" through React's logical tree,
|
|
1585
|
+
* which differs from actual DOM ancestry for portals.
|
|
1586
|
+
*/
|
|
1587
|
+
getDomAncestorsViaFiber(element) {
|
|
1588
|
+
const fiber = getFiberFromElement(element);
|
|
1589
|
+
if (!fiber) return [];
|
|
1590
|
+
const domNodes = [];
|
|
1591
|
+
let current = fiber.return;
|
|
1592
|
+
while (current) {
|
|
1593
|
+
if (current.stateNode instanceof Element) {
|
|
1594
|
+
domNodes.push(current.stateNode);
|
|
1595
|
+
}
|
|
1596
|
+
current = current.return;
|
|
1597
|
+
}
|
|
1598
|
+
return domNodes;
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1601
|
+
|
|
1602
|
+
// ../../modules/iframe-projection/combined/render-identity.ts
|
|
1603
|
+
var SOURCE_IDENTITY_KEYS = [
|
|
1604
|
+
"data-tempo-filepath",
|
|
1605
|
+
"data-tempo-position",
|
|
1606
|
+
"data-tempo-modifiedts",
|
|
1607
|
+
"data-tempo-source-version",
|
|
1608
|
+
"data-tempo-html-filepath",
|
|
1609
|
+
"data-tempo-html-offset",
|
|
1610
|
+
"data-tempo-html-modifiedts",
|
|
1611
|
+
"data-tempo-html-source-version"
|
|
1612
|
+
];
|
|
1613
|
+
var TRANSIENT_FIBER_RESOLUTION_ERRORS = /* @__PURE__ */ new Set([
|
|
1614
|
+
"Unable to resolve a mounted React fiber",
|
|
1615
|
+
"React fiber is absent from both parent generations",
|
|
1616
|
+
"React return fibers are not paired alternates",
|
|
1617
|
+
"Unable to resolve an unmounted React fiber"
|
|
1618
|
+
]);
|
|
1619
|
+
function normalizeIdentityValue(value) {
|
|
1620
|
+
if (typeof value === "string") return value;
|
|
1621
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
1622
|
+
return String(value);
|
|
1623
|
+
}
|
|
1624
|
+
return void 0;
|
|
1625
|
+
}
|
|
1626
|
+
function sourceIdentityFromProps(props) {
|
|
1627
|
+
if (!props) return void 0;
|
|
1628
|
+
const source = {};
|
|
1629
|
+
for (const key of SOURCE_IDENTITY_KEYS) {
|
|
1630
|
+
const value = normalizeIdentityValue(props[key]);
|
|
1631
|
+
if (value !== void 0) source[key] = value;
|
|
1632
|
+
}
|
|
1633
|
+
return Object.keys(source).length > 0 ? source : void 0;
|
|
1634
|
+
}
|
|
1635
|
+
function sourceIdentityFromElement(element) {
|
|
1636
|
+
const source = {};
|
|
1637
|
+
for (const key of SOURCE_IDENTITY_KEYS) {
|
|
1638
|
+
const value = element.getAttribute(key);
|
|
1639
|
+
if (value !== null) source[key] = value;
|
|
1640
|
+
}
|
|
1641
|
+
return Object.keys(source).length > 0 ? source : void 0;
|
|
1642
|
+
}
|
|
1643
|
+
function isContentEditableBoundary(props) {
|
|
1644
|
+
if (!props) return false;
|
|
1645
|
+
return props.contentEditable !== null && props.contentEditable !== void 0 || props.contenteditable !== null && props.contenteditable !== void 0;
|
|
1646
|
+
}
|
|
1647
|
+
function finalizeDeclaration(hosts, missingDomIdCount) {
|
|
1648
|
+
const counts = /* @__PURE__ */ new Map();
|
|
1649
|
+
for (const host of hosts) {
|
|
1650
|
+
counts.set(host.domId, (counts.get(host.domId) ?? 0) + 1);
|
|
1651
|
+
}
|
|
1652
|
+
const duplicateDomIds = [...counts].filter(([, count]) => count > 1).map(([domId]) => domId).sort();
|
|
1653
|
+
hosts.sort((left, right) => left.domId.localeCompare(right.domId));
|
|
1654
|
+
return { hosts, missingDomIdCount, duplicateDomIds };
|
|
1655
|
+
}
|
|
1656
|
+
function declareFiberHostIdentity(tree) {
|
|
1657
|
+
const hosts = [];
|
|
1658
|
+
let missingDomIdCount = 0;
|
|
1659
|
+
const visit = (node) => {
|
|
1660
|
+
if (node.insideContentEditable) return;
|
|
1661
|
+
const renderNode = node;
|
|
1662
|
+
if (renderNode.tag === FiberTag.HostComponent) {
|
|
1663
|
+
if (!node.domId) {
|
|
1664
|
+
missingDomIdCount += 1;
|
|
1665
|
+
} else {
|
|
1666
|
+
hosts.push({
|
|
1667
|
+
domId: node.domId,
|
|
1668
|
+
tag: renderNode.name?.toLowerCase() ?? "",
|
|
1669
|
+
source: sourceIdentityFromProps(node.props)
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1672
|
+
if (isContentEditableBoundary(node.props)) return;
|
|
1673
|
+
}
|
|
1674
|
+
for (const child of node.children) {
|
|
1675
|
+
visit(child);
|
|
1676
|
+
}
|
|
1677
|
+
};
|
|
1678
|
+
visit(tree);
|
|
1679
|
+
return finalizeDeclaration(hosts, missingDomIdCount);
|
|
1680
|
+
}
|
|
1681
|
+
function declareDomHostIdentity(captureRoot, supplementalRoots) {
|
|
1682
|
+
const hosts = [];
|
|
1683
|
+
let missingDomIdCount = 0;
|
|
1684
|
+
const seenElements = /* @__PURE__ */ new Set();
|
|
1685
|
+
const visit = (element) => {
|
|
1686
|
+
if (seenElements.has(element)) return;
|
|
1687
|
+
seenElements.add(element);
|
|
1688
|
+
const rawFiber = getFiberFromElement(element);
|
|
1689
|
+
if (rawFiber) {
|
|
1690
|
+
try {
|
|
1691
|
+
const fiber = resolveCommittedFiber(rawFiber);
|
|
1692
|
+
if (fiber.tag === FiberTag.HostComponent && fiber.stateNode === element) {
|
|
1693
|
+
const domId = element.getAttribute("data-dom-id");
|
|
1694
|
+
if (!domId) {
|
|
1695
|
+
missingDomIdCount += 1;
|
|
1696
|
+
} else {
|
|
1697
|
+
hosts.push({
|
|
1698
|
+
domId,
|
|
1699
|
+
tag: element.localName.toLowerCase(),
|
|
1700
|
+
source: sourceIdentityFromElement(element)
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
} catch (error) {
|
|
1705
|
+
if (!(error instanceof Error) || !TRANSIENT_FIBER_RESOLUTION_ERRORS.has(error.message)) {
|
|
1706
|
+
throw error;
|
|
1707
|
+
}
|
|
1708
|
+
missingDomIdCount += 1;
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
if (element.getAttribute("contenteditable") !== null) return;
|
|
1712
|
+
for (const child of element.children) visit(child);
|
|
1713
|
+
};
|
|
1714
|
+
for (const child of captureRoot.children) visit(child);
|
|
1715
|
+
for (const root of supplementalRoots) visit(root);
|
|
1716
|
+
return finalizeDeclaration(hosts, missingDomIdCount);
|
|
1717
|
+
}
|
|
1718
|
+
function hostIdentityDeclarationsMatch(left, right) {
|
|
1719
|
+
if (left.missingDomIdCount !== 0 || right.missingDomIdCount !== 0 || left.duplicateDomIds.length !== 0 || right.duplicateDomIds.length !== 0 || left.hosts.length !== right.hosts.length) {
|
|
1720
|
+
return false;
|
|
1721
|
+
}
|
|
1722
|
+
for (let index = 0; index < left.hosts.length; index += 1) {
|
|
1723
|
+
const leftHost = left.hosts[index];
|
|
1724
|
+
const rightHost = right.hosts[index];
|
|
1725
|
+
if (!leftHost || !rightHost || leftHost.domId !== rightHost.domId || leftHost.tag !== rightHost.tag || JSON.stringify(leftHost.source ?? {}) !== JSON.stringify(rightHost.source ?? {})) {
|
|
1726
|
+
return false;
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
return true;
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
// ../../modules/iframe-projection/combined/declared-facts.ts
|
|
1733
|
+
function createRenderDeclarationScope(captureRoot, supplementalRoots) {
|
|
1734
|
+
return {
|
|
1735
|
+
captureRoot,
|
|
1736
|
+
supplementalRoots,
|
|
1737
|
+
...captureRoot.getAttribute("data-tempo-render-mode") === "static-dom" && {
|
|
1738
|
+
renderMode: "static-dom"
|
|
1739
|
+
}
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
function computeObservedVersionsFromFiber(tree) {
|
|
1743
|
+
const observedVersions = {};
|
|
1744
|
+
const observedSourceVersions = {};
|
|
1745
|
+
const record = (filepath, modifiedTsRaw, sourceVersionRaw) => {
|
|
1746
|
+
if (typeof filepath !== "string" || filepath.length === 0) return;
|
|
1747
|
+
const modifiedTs = typeof modifiedTsRaw === "number" ? modifiedTsRaw : typeof modifiedTsRaw === "string" ? Number(modifiedTsRaw) : NaN;
|
|
1748
|
+
if (Number.isNaN(modifiedTs)) return;
|
|
1749
|
+
const existing = observedVersions[filepath];
|
|
1750
|
+
if (existing === void 0 || modifiedTs > existing) {
|
|
1751
|
+
observedVersions[filepath] = modifiedTs;
|
|
1752
|
+
if (typeof sourceVersionRaw === "string" && sourceVersionRaw.length > 0) {
|
|
1753
|
+
observedSourceVersions[filepath] = sourceVersionRaw;
|
|
1754
|
+
} else {
|
|
1755
|
+
delete observedSourceVersions[filepath];
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
};
|
|
1759
|
+
const visit = (node) => {
|
|
1760
|
+
const props = node.props;
|
|
1761
|
+
record(
|
|
1762
|
+
props?.["data-tempo-filepath"],
|
|
1763
|
+
props?.["data-tempo-modifiedts"],
|
|
1764
|
+
props?.["data-tempo-source-version"]
|
|
1765
|
+
);
|
|
1766
|
+
record(
|
|
1767
|
+
props?.["data-tempo-html-filepath"],
|
|
1768
|
+
props?.["data-tempo-html-modifiedts"],
|
|
1769
|
+
props?.["data-tempo-html-source-version"]
|
|
1770
|
+
);
|
|
1771
|
+
for (const child of node.children) {
|
|
1772
|
+
visit(child);
|
|
1773
|
+
}
|
|
1774
|
+
};
|
|
1775
|
+
visit(tree);
|
|
1776
|
+
return { observedVersions, observedSourceVersions };
|
|
1777
|
+
}
|
|
1778
|
+
function computeRenderDeclarations(fiber, html, hasReactRenderer, document2, identityScope) {
|
|
1779
|
+
const domIdentity = identityScope ? declareDomHostIdentity(
|
|
1780
|
+
identityScope.captureRoot,
|
|
1781
|
+
identityScope.supplementalRoots
|
|
1782
|
+
) : void 0;
|
|
1783
|
+
const fiberIdentity = fiber ? declareFiberHostIdentity(fiber) : void 0;
|
|
1784
|
+
const identityMatching = domIdentity && fiberIdentity ? hostIdentityDeclarationsMatch(domIdentity, fiberIdentity) : void 0;
|
|
1785
|
+
return {
|
|
1786
|
+
...fiber !== void 0 && {
|
|
1787
|
+
fiberDeclared: fiber ? {
|
|
1788
|
+
complete: true,
|
|
1789
|
+
...document2 && {
|
|
1790
|
+
domConsistent: identityMatching ?? fiberHostIdentitiesAreLive(fiber, document2)
|
|
1791
|
+
},
|
|
1792
|
+
...fiberIdentity && { hostIdentity: fiberIdentity },
|
|
1793
|
+
...computeObservedVersionsFromFiber(fiber)
|
|
1794
|
+
} : null
|
|
1795
|
+
},
|
|
1796
|
+
...fiber ? { renderDeclared: { complete: true, kind: "fiber" } } : (identityScope?.renderMode === "static-dom" || !hasReactRenderer) && html?.declared.complete === true ? {
|
|
1797
|
+
renderDeclared: {
|
|
1798
|
+
complete: true,
|
|
1799
|
+
kind: "static-dom"
|
|
1800
|
+
}
|
|
1801
|
+
} : {},
|
|
1802
|
+
...domIdentity && {
|
|
1803
|
+
renderIdentity: {
|
|
1804
|
+
dom: domIdentity,
|
|
1805
|
+
...fiberIdentity && { fiber: fiberIdentity },
|
|
1806
|
+
...identityMatching !== void 0 && {
|
|
1807
|
+
matching: identityMatching
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
function fiberHostIdentitiesAreLive(fiber, document2) {
|
|
1814
|
+
const liveDomIds = new Set(
|
|
1815
|
+
Array.from(document2.querySelectorAll("[data-dom-id]")).filter((element) => element.isConnected).map((element) => element.getAttribute("data-dom-id")).filter((domId) => domId !== null)
|
|
1816
|
+
);
|
|
1817
|
+
const seenFiberDomIds = /* @__PURE__ */ new Set();
|
|
1818
|
+
const visit = (node) => {
|
|
1819
|
+
if (node.domId) {
|
|
1820
|
+
if (seenFiberDomIds.has(node.domId) || !liveDomIds.has(node.domId)) {
|
|
1821
|
+
return false;
|
|
1822
|
+
}
|
|
1823
|
+
seenFiberDomIds.add(node.domId);
|
|
1824
|
+
}
|
|
1825
|
+
return node.children.every(
|
|
1826
|
+
(child) => visit(child)
|
|
1827
|
+
);
|
|
1828
|
+
};
|
|
1829
|
+
return visit(fiber);
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
// ../../modules/element-overlay/render/layout-kind.ts
|
|
1833
|
+
function getElementLayoutKind(el, style = getComputedStyle(el)) {
|
|
1834
|
+
if (/grid/.test(style.display)) return "grid";
|
|
1835
|
+
if (/flex/.test(style.display)) {
|
|
1836
|
+
return /^column/.test(style.flexDirection) ? "row" : "column";
|
|
1837
|
+
}
|
|
1838
|
+
if (style.position === "relative" || style.position === "sticky" || style.position === "absolute") {
|
|
1839
|
+
return "div";
|
|
1840
|
+
}
|
|
1841
|
+
return null;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
// ../../modules/iframe-projection/combined/enriched-serialize.ts
|
|
1845
|
+
var nextFiberId = 1;
|
|
1846
|
+
var fiberIdMap = /* @__PURE__ */ new WeakMap();
|
|
1847
|
+
function getFiberId(fiber) {
|
|
1848
|
+
let id = fiberIdMap.get(fiber);
|
|
1849
|
+
if (id) return id;
|
|
1850
|
+
if (fiber.alternate) {
|
|
1851
|
+
id = fiberIdMap.get(fiber.alternate);
|
|
1852
|
+
if (id) {
|
|
1853
|
+
fiberIdMap.set(fiber, id);
|
|
1854
|
+
return id;
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
id = String(nextFiberId++);
|
|
1858
|
+
fiberIdMap.set(fiber, id);
|
|
1859
|
+
if (fiber.alternate) {
|
|
1860
|
+
fiberIdMap.set(fiber.alternate, id);
|
|
1861
|
+
}
|
|
1862
|
+
return id;
|
|
1863
|
+
}
|
|
1864
|
+
function normalizeTempoDataSet(props) {
|
|
1865
|
+
const dataSet = props?.dataSet;
|
|
1866
|
+
if (!props || !dataSet || typeof dataSet !== "object") return props;
|
|
1867
|
+
let extracted = null;
|
|
1868
|
+
let remaining = null;
|
|
1869
|
+
for (const [key, value] of Object.entries(
|
|
1870
|
+
dataSet
|
|
1871
|
+
)) {
|
|
1872
|
+
if (key.startsWith("tempo")) {
|
|
1873
|
+
(extracted ?? (extracted = {}))[`data-${key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}`] = value;
|
|
1874
|
+
} else {
|
|
1875
|
+
(remaining ?? (remaining = {}))[key] = value;
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
if (!extracted) return props;
|
|
1879
|
+
const out = { ...props, ...extracted };
|
|
1880
|
+
if (remaining) out.dataSet = remaining;
|
|
1881
|
+
else delete out.dataSet;
|
|
1882
|
+
return out;
|
|
1883
|
+
}
|
|
1884
|
+
var enrichedSerialize = (fiber) => {
|
|
1885
|
+
const domElement = getDomElement(fiber);
|
|
1886
|
+
return {
|
|
1887
|
+
fiberId: getFiberId(fiber),
|
|
1888
|
+
name: getDisplayName(fiber),
|
|
1889
|
+
tag: getTag(fiber),
|
|
1890
|
+
...hasContextDependencies(fiber) && { hasContextDependencies: true },
|
|
1891
|
+
...domElement && {
|
|
1892
|
+
domId: domElement.getAttribute(DOM_ID_ATTR) ?? void 0,
|
|
1893
|
+
...hasContentEditableAncestor2(domElement) && {
|
|
1894
|
+
insideContentEditable: true
|
|
1895
|
+
},
|
|
1896
|
+
layoutKind: getElementLayoutKind(domElement) ?? void 0
|
|
1897
|
+
},
|
|
1898
|
+
props: normalizeTempoDataSet(sanitizeProps(getProps(fiber)))
|
|
1899
|
+
};
|
|
1900
|
+
};
|
|
1901
|
+
function hasContentEditableAncestor2(element) {
|
|
1902
|
+
let current = element.parentElement;
|
|
1903
|
+
while (current) {
|
|
1904
|
+
if (current.getAttribute("contenteditable") !== null) return true;
|
|
1905
|
+
current = current.parentElement;
|
|
1906
|
+
}
|
|
1907
|
+
return false;
|
|
1908
|
+
}
|
|
1909
|
+
function hasContextDependencies(fiber) {
|
|
1910
|
+
const dependencies = fiber.dependencies;
|
|
1911
|
+
if (!dependencies || typeof dependencies !== "object") {
|
|
1912
|
+
return false;
|
|
1913
|
+
}
|
|
1914
|
+
return Boolean(
|
|
1915
|
+
dependencies.firstContext
|
|
1916
|
+
);
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
// ../../modules/iframe-projection/combined/hide-fiber-tree.ts
|
|
1920
|
+
var shouldHideFiberNode = (node, hideFiberProp) => {
|
|
1921
|
+
if (!hideFiberProp) {
|
|
1922
|
+
return false;
|
|
1923
|
+
}
|
|
1924
|
+
const value = node.props?.[hideFiberProp];
|
|
1925
|
+
return value === true || value === "true";
|
|
1926
|
+
};
|
|
1927
|
+
var filterHiddenFiberNode = (node, hideFiberProp) => {
|
|
1928
|
+
const children = node.children.flatMap(
|
|
1929
|
+
(child) => filterHiddenFiberNode(child, hideFiberProp)
|
|
1930
|
+
);
|
|
1931
|
+
return shouldHideFiberNode(node, hideFiberProp) ? children : [{ ...node, children }];
|
|
1932
|
+
};
|
|
1933
|
+
var filterHiddenFiberTree = (tree, hideFiberProp) => {
|
|
1934
|
+
if (!tree || !hideFiberProp) {
|
|
1935
|
+
return tree;
|
|
1936
|
+
}
|
|
1937
|
+
return filterHiddenFiberNode(tree, hideFiberProp)[0] ?? null;
|
|
1938
|
+
};
|
|
1939
|
+
var captureCombinedFiberTree = (options) => {
|
|
1940
|
+
const rootElement = options.rootElement;
|
|
1941
|
+
if (options.selector || !rootElement) {
|
|
1942
|
+
const tree = captureTree({
|
|
1943
|
+
serialize: options.serialize,
|
|
1944
|
+
selector: options.selector,
|
|
1945
|
+
tags: options.tags
|
|
1946
|
+
});
|
|
1947
|
+
return filterHiddenFiberTree(tree, options.hideFiberProp);
|
|
1948
|
+
}
|
|
1949
|
+
const roots = getCommittedFiberRoots().filter(
|
|
1950
|
+
(root) => rootBelongsToElement(root, rootElement)
|
|
1951
|
+
);
|
|
1952
|
+
const firstRoot = roots[0];
|
|
1953
|
+
if (!firstRoot) return null;
|
|
1954
|
+
const trees = roots.flatMap(
|
|
1955
|
+
(root) => serializeRootBranches(root, options.serialize, options.tags)
|
|
1956
|
+
).flatMap(
|
|
1957
|
+
(tree) => options.hideFiberProp ? filterHiddenFiberNode(tree, options.hideFiberProp) : [tree]
|
|
1958
|
+
);
|
|
1959
|
+
if (trees.length === 0) {
|
|
1960
|
+
return {
|
|
1961
|
+
...options.serialize(firstRoot.current),
|
|
1962
|
+
domId: void 0,
|
|
1963
|
+
props: void 0,
|
|
1964
|
+
children: []
|
|
1965
|
+
};
|
|
1966
|
+
}
|
|
1967
|
+
if (trees.length === 1) return trees[0] ?? null;
|
|
1968
|
+
return {
|
|
1969
|
+
...options.serialize(firstRoot.current),
|
|
1970
|
+
fiberId: "__tempo_document_fiber_roots__",
|
|
1971
|
+
domId: void 0,
|
|
1972
|
+
props: void 0,
|
|
1973
|
+
children: trees
|
|
1974
|
+
};
|
|
1975
|
+
};
|
|
1976
|
+
function rootBelongsToElement(root, element) {
|
|
1977
|
+
const container = root.containerInfo;
|
|
1978
|
+
return container === element || element.contains(container);
|
|
1979
|
+
}
|
|
1980
|
+
function serializeRootBranches(root, serialize, tags) {
|
|
1981
|
+
const tagSet = tags && tags.length > 0 ? new Set(tags) : null;
|
|
1982
|
+
const branches = [];
|
|
1983
|
+
for (let fiber = root.current.child; fiber; fiber = fiber.sibling) {
|
|
1984
|
+
const tree = serializeTree(fiber, serialize);
|
|
1985
|
+
if (!tree) continue;
|
|
1986
|
+
branches.push(...filterTreeBranches(tree, tagSet));
|
|
1987
|
+
}
|
|
1988
|
+
return branches;
|
|
1989
|
+
}
|
|
1990
|
+
function filterTreeBranches(tree, tags) {
|
|
1991
|
+
if (!tags || !("tag" in tree)) return [tree];
|
|
1992
|
+
const children = tree.children.flatMap(
|
|
1993
|
+
(child) => filterTreeBranches(child, tags)
|
|
1994
|
+
);
|
|
1995
|
+
return tags.has(tree.tag) ? [{ ...tree, children }] : children;
|
|
1996
|
+
}
|
|
1997
|
+
var sourceVersionSerialize = (fiber) => ({
|
|
1998
|
+
fiberId: "",
|
|
1999
|
+
props: getProps(fiber)
|
|
2000
|
+
});
|
|
2001
|
+
var captureCombinedFiberSourceVersion = (options) => {
|
|
2002
|
+
const tree = captureCombinedFiberTree({
|
|
2003
|
+
serialize: sourceVersionSerialize,
|
|
2004
|
+
selector: options.selector,
|
|
2005
|
+
rootElement: options.rootElement,
|
|
2006
|
+
tags: options.tags,
|
|
2007
|
+
hideFiberProp: options.hideFiberProp
|
|
2008
|
+
});
|
|
2009
|
+
if (!tree) return null;
|
|
2010
|
+
let max = null;
|
|
2011
|
+
const updateMax = (mtimeRaw) => {
|
|
2012
|
+
const value = typeof mtimeRaw === "number" ? mtimeRaw : typeof mtimeRaw === "string" ? parseInt(mtimeRaw, 10) : NaN;
|
|
2013
|
+
if (!Number.isNaN(value) && (max === null || value > max)) {
|
|
2014
|
+
max = value;
|
|
2015
|
+
}
|
|
2016
|
+
};
|
|
2017
|
+
const visit = (node) => {
|
|
2018
|
+
updateMax(node.props?.["data-tempo-modifiedts"]);
|
|
2019
|
+
updateMax(node.props?.["data-tempo-html-modifiedts"]);
|
|
2020
|
+
for (const child of node.children) visit(child);
|
|
2021
|
+
};
|
|
2022
|
+
visit(tree);
|
|
2023
|
+
return max;
|
|
2024
|
+
};
|
|
2025
|
+
|
|
2026
|
+
// ../../modules/iframe-projection/combined/watch.ts
|
|
2027
|
+
var DEBOUNCE_DELAY = 50;
|
|
2028
|
+
var MAX_WAIT = 250;
|
|
2029
|
+
var RENDER_CHANGE_FLAGS = 2 | // Placement
|
|
2030
|
+
4 | // Update
|
|
2031
|
+
16 | // ChildDeletion
|
|
2032
|
+
32 | // ContentReset
|
|
2033
|
+
128 | // DidCapture
|
|
2034
|
+
256;
|
|
2035
|
+
function realmHasReactRenderer(element, localHook) {
|
|
2036
|
+
const view = element.ownerDocument?.defaultView;
|
|
2037
|
+
if (view && view !== window) {
|
|
2038
|
+
return (view.__REACT_DEVTOOLS_GLOBAL_HOOK__?.renderers?.size ?? 0) > 0;
|
|
2039
|
+
}
|
|
2040
|
+
return localHook.hook.renderers.size > 0;
|
|
2041
|
+
}
|
|
2042
|
+
function watchCombined(element, onChange, options = {}) {
|
|
2043
|
+
const {
|
|
2044
|
+
debounceDelay = DEBOUNCE_DELAY,
|
|
2045
|
+
maxWait = MAX_WAIT,
|
|
2046
|
+
serialize,
|
|
2047
|
+
fiberSelector,
|
|
2048
|
+
fiberTags,
|
|
2049
|
+
hideFiberProp
|
|
2050
|
+
} = options;
|
|
2051
|
+
const serializeFn = serialize ?? enrichedSerialize;
|
|
2052
|
+
const reactHook = initHook();
|
|
2053
|
+
let debounceTimer = null;
|
|
2054
|
+
let maxWaitTimer = null;
|
|
2055
|
+
let fiberDirty = false;
|
|
2056
|
+
let paused = false;
|
|
2057
|
+
let stopped = false;
|
|
2058
|
+
let dirtyWhilePaused = false;
|
|
2059
|
+
const portalWatchers = /* @__PURE__ */ new Map();
|
|
2060
|
+
const pendingPortalRemovals = [];
|
|
2061
|
+
const portalWatchersNeedingInitialFlush = /* @__PURE__ */ new Set();
|
|
2062
|
+
const clearFlushTimers = () => {
|
|
2063
|
+
if (debounceTimer) {
|
|
2064
|
+
clearTimeout(debounceTimer);
|
|
2065
|
+
debounceTimer = null;
|
|
2066
|
+
}
|
|
2067
|
+
if (maxWaitTimer) {
|
|
2068
|
+
clearTimeout(maxWaitTimer);
|
|
2069
|
+
maxWaitTimer = null;
|
|
2070
|
+
}
|
|
2071
|
+
};
|
|
2072
|
+
const scheduleFlush = () => {
|
|
2073
|
+
if (stopped) {
|
|
2074
|
+
return;
|
|
2075
|
+
}
|
|
2076
|
+
if (paused) {
|
|
2077
|
+
dirtyWhilePaused = true;
|
|
2078
|
+
clearFlushTimers();
|
|
2079
|
+
return;
|
|
2080
|
+
}
|
|
2081
|
+
if (debounceTimer) {
|
|
2082
|
+
clearTimeout(debounceTimer);
|
|
2083
|
+
debounceTimer = null;
|
|
2084
|
+
}
|
|
2085
|
+
debounceTimer = setTimeout(flush, debounceDelay);
|
|
2086
|
+
if (!maxWaitTimer) {
|
|
2087
|
+
maxWaitTimer = setTimeout(flush, maxWait);
|
|
2088
|
+
}
|
|
2089
|
+
};
|
|
2090
|
+
const triggerFlush = (_trigger) => scheduleFlush();
|
|
2091
|
+
const captureFiberTree = () => captureCombinedFiberTree({
|
|
2092
|
+
serialize: serializeFn,
|
|
2093
|
+
selector: fiberSelector,
|
|
2094
|
+
rootElement: element,
|
|
2095
|
+
tags: fiberTags,
|
|
2096
|
+
hideFiberProp
|
|
2097
|
+
});
|
|
2098
|
+
const watchedFiberForCommit = (fiberRoot) => {
|
|
2099
|
+
const target = fiberSelector ? element.ownerDocument?.querySelector(fiberSelector) : element;
|
|
2100
|
+
if (!target) return null;
|
|
2101
|
+
if (fiberRoot.containerInfo === target || target.contains(fiberRoot.containerInfo)) {
|
|
2102
|
+
return fiberRoot.current;
|
|
2103
|
+
}
|
|
2104
|
+
const rawFiber = getFiberFromElement(target);
|
|
2105
|
+
if (!rawFiber) return null;
|
|
2106
|
+
const committed = resolveCommittedFiber(rawFiber);
|
|
2107
|
+
let root = committed;
|
|
2108
|
+
while (root.return) root = root.return;
|
|
2109
|
+
return root === fiberRoot.current ? committed : null;
|
|
2110
|
+
};
|
|
2111
|
+
const fiberHasRenderChanges = (fiber) => (((fiber.flags ?? 0) | (fiber.subtreeFlags ?? 0)) & RENDER_CHANGE_FLAGS) !== 0;
|
|
2112
|
+
const getCurrentSourceVersion = (options2) => ({
|
|
2113
|
+
...options2.html && {
|
|
2114
|
+
htmlModifiedTs: getMaxModifiedTsFromElements([
|
|
2115
|
+
element,
|
|
2116
|
+
...Array.from(portalWatchers.keys())
|
|
2117
|
+
]) ?? void 0
|
|
2118
|
+
},
|
|
2119
|
+
...options2.fiber && {
|
|
2120
|
+
fiberModifiedTs: captureCombinedFiberSourceVersion({
|
|
2121
|
+
selector: fiberSelector,
|
|
2122
|
+
rootElement: element,
|
|
2123
|
+
tags: fiberTags,
|
|
2124
|
+
hideFiberProp
|
|
2125
|
+
}) ?? void 0
|
|
2126
|
+
}
|
|
2127
|
+
});
|
|
2128
|
+
const emitCapture = (capture, provenance) => {
|
|
2129
|
+
onChange({
|
|
2130
|
+
...capture,
|
|
2131
|
+
provenance,
|
|
2132
|
+
documentEpoch: REALM_DOCUMENT_EPOCH,
|
|
2133
|
+
sequence: nextRealmCaptureSequence()
|
|
2134
|
+
});
|
|
2135
|
+
};
|
|
2136
|
+
const hasDirtySources = () => hasPendingMutations(domWatcher) || hasPendingStateChanges(stateWatcher) || pendingPortalRemovals.length > 0 || portalWatchersNeedingInitialFlush.size > 0 || Array.from(portalWatchers.values()).some((w) => w.hasPendingChanges()) || headSubscription.hasMutations || fiberDirty;
|
|
2137
|
+
const flush = (isFirstFlush = false, additionalTriggers = []) => {
|
|
2138
|
+
if (stopped) {
|
|
2139
|
+
return;
|
|
2140
|
+
}
|
|
2141
|
+
if (paused) {
|
|
2142
|
+
dirtyWhilePaused = true;
|
|
2143
|
+
clearFlushTimers();
|
|
2144
|
+
return;
|
|
2145
|
+
}
|
|
2146
|
+
clearFlushTimers();
|
|
2147
|
+
if (isFirstFlush) {
|
|
2148
|
+
flushDomWatcher(domWatcher);
|
|
2149
|
+
flushStateWatcher(stateWatcher);
|
|
2150
|
+
for (const handle of portalWatchers.values()) {
|
|
2151
|
+
handle.flush(true);
|
|
2152
|
+
}
|
|
2153
|
+
pendingPortalRemovals.length = 0;
|
|
2154
|
+
portalWatchersNeedingInitialFlush.clear();
|
|
2155
|
+
fiberDirty = false;
|
|
2156
|
+
const sourceVersion2 = getCurrentSourceVersion({
|
|
2157
|
+
html: true,
|
|
2158
|
+
fiber: true
|
|
2159
|
+
});
|
|
2160
|
+
const html = captureProjectionSnapshot(
|
|
2161
|
+
element,
|
|
2162
|
+
Array.from(portalWatchers.keys())
|
|
2163
|
+
);
|
|
2164
|
+
const fiber = captureFiberTree();
|
|
2165
|
+
const captureSourceVersion = {
|
|
2166
|
+
htmlModifiedTs: sourceVersion2.htmlModifiedTs ?? getMaxModifiedTsFromHtml(html) ?? void 0,
|
|
2167
|
+
fiberModifiedTs: sourceVersion2.fiberModifiedTs ?? getMaxModifiedTsFromFiber(fiber) ?? void 0
|
|
2168
|
+
};
|
|
2169
|
+
emitCapture(
|
|
2170
|
+
{
|
|
2171
|
+
html,
|
|
2172
|
+
fiber: fiber ?? null,
|
|
2173
|
+
...computeRenderDeclarations(
|
|
2174
|
+
fiber,
|
|
2175
|
+
html,
|
|
2176
|
+
realmHasReactRenderer(element, reactHook),
|
|
2177
|
+
element.ownerDocument,
|
|
2178
|
+
createRenderDeclarationScope(
|
|
2179
|
+
element,
|
|
2180
|
+
Array.from(portalWatchers.keys())
|
|
2181
|
+
)
|
|
2182
|
+
),
|
|
2183
|
+
sourceVersion: captureSourceVersion
|
|
2184
|
+
},
|
|
2185
|
+
{ kind: "initial" }
|
|
2186
|
+
);
|
|
2187
|
+
return;
|
|
2188
|
+
}
|
|
2189
|
+
const hasDomChanges = hasPendingMutations(domWatcher);
|
|
2190
|
+
const hasStateChanges = hasPendingStateChanges(stateWatcher);
|
|
2191
|
+
const hasPortalChanges = pendingPortalRemovals.length > 0 || portalWatchersNeedingInitialFlush.size > 0 || Array.from(portalWatchers.values()).some((w) => w.hasPendingChanges());
|
|
2192
|
+
const hasHeadChanges = headSubscription.hasMutations;
|
|
2193
|
+
const hasFiberChanges = fiberDirty;
|
|
2194
|
+
if (!hasDomChanges && !hasStateChanges && !hasPortalChanges && !hasHeadChanges && !hasFiberChanges) {
|
|
2195
|
+
return;
|
|
2196
|
+
}
|
|
2197
|
+
const sourceVersion = hasDomChanges || hasFiberChanges ? getCurrentSourceVersion({
|
|
2198
|
+
html: hasDomChanges,
|
|
2199
|
+
fiber: hasFiberChanges
|
|
2200
|
+
}) : void 0;
|
|
2201
|
+
let htmlCapture;
|
|
2202
|
+
if (hasFiberChanges) {
|
|
2203
|
+
htmlCapture = captureProjectionSnapshot(
|
|
2204
|
+
element,
|
|
2205
|
+
Array.from(portalWatchers.keys())
|
|
2206
|
+
);
|
|
2207
|
+
flushDomWatcher(domWatcher);
|
|
2208
|
+
flushStateWatcher(stateWatcher);
|
|
2209
|
+
pendingPortalRemovals.length = 0;
|
|
2210
|
+
portalWatchersNeedingInitialFlush.clear();
|
|
2211
|
+
for (const handle of portalWatchers.values()) handle.flush(false);
|
|
2212
|
+
headSubscription.flush(false);
|
|
2213
|
+
} else if (hasDomChanges || hasStateChanges || hasPortalChanges || hasHeadChanges) {
|
|
2214
|
+
let targetElement = element;
|
|
2215
|
+
if (hasDomChanges) {
|
|
2216
|
+
const lca = flushDomWatcher(domWatcher);
|
|
2217
|
+
if (lca && element.contains(lca)) {
|
|
2218
|
+
targetElement = lca;
|
|
2219
|
+
}
|
|
2220
|
+
} else {
|
|
2221
|
+
flushDomWatcher(domWatcher);
|
|
2222
|
+
}
|
|
2223
|
+
const states = flushStateWatcher(stateWatcher);
|
|
2224
|
+
const selector = generateSelector(targetElement, element);
|
|
2225
|
+
const html = removeScriptTags(targetElement.innerHTML);
|
|
2226
|
+
const attributes = captureAttributes(targetElement);
|
|
2227
|
+
const rootAttributes = element === targetElement ? void 0 : captureAttributes(element);
|
|
2228
|
+
const documentElementAttributes = element.ownerDocument ? captureAttributes(element.ownerDocument.documentElement) : void 0;
|
|
2229
|
+
const baseUrl = element.ownerDocument?.baseURI;
|
|
2230
|
+
const portals = [];
|
|
2231
|
+
for (const id of pendingPortalRemovals) {
|
|
2232
|
+
portals.push(createPortalRemovedUpdate(id));
|
|
2233
|
+
}
|
|
2234
|
+
pendingPortalRemovals.length = 0;
|
|
2235
|
+
for (const handle of portalWatchers.values()) {
|
|
2236
|
+
const needsInitialFlush = portalWatchersNeedingInitialFlush.has(handle);
|
|
2237
|
+
const update = handle.flush(needsInitialFlush);
|
|
2238
|
+
if (update) portals.push(update);
|
|
2239
|
+
portalWatchersNeedingInitialFlush.delete(handle);
|
|
2240
|
+
}
|
|
2241
|
+
const head = headSubscription.flush(false);
|
|
2242
|
+
const portalElements = Array.from(portalWatchers.keys());
|
|
2243
|
+
const declared = computeDeclaredFacts(
|
|
2244
|
+
targetElement,
|
|
2245
|
+
element,
|
|
2246
|
+
selector,
|
|
2247
|
+
portalElements
|
|
2248
|
+
);
|
|
2249
|
+
const displayability = declared.complete ? measureComputedDisplayability(element, portalElements) : null;
|
|
2250
|
+
htmlCapture = {
|
|
2251
|
+
declared,
|
|
2252
|
+
...displayability && { displayability },
|
|
2253
|
+
dom: {
|
|
2254
|
+
selector,
|
|
2255
|
+
html,
|
|
2256
|
+
attributes,
|
|
2257
|
+
rootAttributes,
|
|
2258
|
+
documentElementAttributes
|
|
2259
|
+
},
|
|
2260
|
+
states,
|
|
2261
|
+
baseUrl,
|
|
2262
|
+
...portals.length > 0 && { portals },
|
|
2263
|
+
...head !== void 0 && { head }
|
|
2264
|
+
};
|
|
2265
|
+
} else {
|
|
2266
|
+
flushDomWatcher(domWatcher);
|
|
2267
|
+
flushStateWatcher(stateWatcher);
|
|
2268
|
+
}
|
|
2269
|
+
let fiberCapture;
|
|
2270
|
+
if (hasFiberChanges) {
|
|
2271
|
+
fiberDirty = false;
|
|
2272
|
+
const tree = captureFiberTree();
|
|
2273
|
+
fiberCapture = tree ?? null;
|
|
2274
|
+
}
|
|
2275
|
+
const triggers = /* @__PURE__ */ new Set([
|
|
2276
|
+
...hasDomChanges ? ["dom"] : [],
|
|
2277
|
+
...hasStateChanges ? ["state"] : [],
|
|
2278
|
+
...hasHeadChanges ? ["head"] : [],
|
|
2279
|
+
...hasPortalChanges ? ["portal"] : [],
|
|
2280
|
+
...hasFiberChanges ? ["fiber"] : [],
|
|
2281
|
+
...additionalTriggers
|
|
2282
|
+
]);
|
|
2283
|
+
emitCapture(
|
|
2284
|
+
{
|
|
2285
|
+
...htmlCapture !== void 0 && { html: htmlCapture },
|
|
2286
|
+
...fiberCapture !== void 0 && {
|
|
2287
|
+
fiber: fiberCapture
|
|
2288
|
+
},
|
|
2289
|
+
...computeRenderDeclarations(
|
|
2290
|
+
fiberCapture,
|
|
2291
|
+
htmlCapture,
|
|
2292
|
+
realmHasReactRenderer(element, reactHook),
|
|
2293
|
+
element.ownerDocument,
|
|
2294
|
+
createRenderDeclarationScope(
|
|
2295
|
+
element,
|
|
2296
|
+
Array.from(portalWatchers.keys())
|
|
2297
|
+
)
|
|
2298
|
+
),
|
|
2299
|
+
...sourceVersion && { sourceVersion }
|
|
2300
|
+
},
|
|
2301
|
+
{ kind: "watch", triggers: [...triggers] }
|
|
2302
|
+
);
|
|
2303
|
+
};
|
|
2304
|
+
const domWatcher = watchDom(element, () => triggerFlush("dom"));
|
|
2305
|
+
const stateWatcher = watchState(element, () => triggerFlush("state"));
|
|
2306
|
+
const headSubscription = getHeadTracker().subscribe(
|
|
2307
|
+
element.ownerDocument,
|
|
2308
|
+
() => triggerFlush("head")
|
|
2309
|
+
);
|
|
2310
|
+
const watchedDocument = element.ownerDocument;
|
|
2311
|
+
const watchedWindow = watchedDocument?.defaultView;
|
|
2312
|
+
const crossRealmHeadObserver = watchedWindow && watchedWindow !== window && watchedDocument.head ? new watchedWindow.MutationObserver(() => {
|
|
2313
|
+
headSubscription.hasMutations = true;
|
|
2314
|
+
triggerFlush("head");
|
|
2315
|
+
}) : null;
|
|
2316
|
+
crossRealmHeadObserver?.observe(watchedDocument.head, {
|
|
2317
|
+
childList: true,
|
|
2318
|
+
subtree: true,
|
|
2319
|
+
attributes: true,
|
|
2320
|
+
characterData: true
|
|
2321
|
+
});
|
|
2322
|
+
const portalTracker = getPortalTracker();
|
|
2323
|
+
const unregisterPortalWatcher = portalTracker.register({
|
|
2324
|
+
element,
|
|
2325
|
+
onPortalFound: (portalRoot) => {
|
|
2326
|
+
const handle = watchPortal(portalRoot, () => triggerFlush("portal"));
|
|
2327
|
+
portalWatchers.set(portalRoot, handle);
|
|
2328
|
+
portalWatchersNeedingInitialFlush.add(handle);
|
|
2329
|
+
triggerFlush("portal");
|
|
2330
|
+
},
|
|
2331
|
+
onPortalRemoved: (portalRoot) => {
|
|
2332
|
+
const handle = portalWatchers.get(portalRoot);
|
|
2333
|
+
if (handle) {
|
|
2334
|
+
handle.stop();
|
|
2335
|
+
pendingPortalRemovals.push(handle.id);
|
|
2336
|
+
portalWatchers.delete(portalRoot);
|
|
2337
|
+
triggerFlush("portal");
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
});
|
|
2341
|
+
const { onCommit } = reactHook;
|
|
2342
|
+
const unsubFiber = onCommit((fiberRoot) => {
|
|
2343
|
+
const watchedFiber = watchedFiberForCommit(fiberRoot);
|
|
2344
|
+
if (!watchedFiber) return;
|
|
2345
|
+
const hasRenderChanges = fiberHasRenderChanges(watchedFiber);
|
|
2346
|
+
if (!hasRenderChanges) return;
|
|
2347
|
+
fiberDirty = true;
|
|
2348
|
+
scheduleFlush();
|
|
2349
|
+
});
|
|
2350
|
+
flush(true);
|
|
2351
|
+
const stop = () => {
|
|
2352
|
+
if (stopped) {
|
|
2353
|
+
return;
|
|
2354
|
+
}
|
|
2355
|
+
stopped = true;
|
|
2356
|
+
clearFlushTimers();
|
|
2357
|
+
domWatcher.stop();
|
|
2358
|
+
stateWatcher.stop();
|
|
2359
|
+
crossRealmHeadObserver?.disconnect();
|
|
2360
|
+
headSubscription.unsubscribe();
|
|
2361
|
+
unregisterPortalWatcher();
|
|
2362
|
+
unsubFiber();
|
|
2363
|
+
for (const handle of portalWatchers.values()) {
|
|
2364
|
+
handle.stop();
|
|
2365
|
+
}
|
|
2366
|
+
portalWatchers.clear();
|
|
2367
|
+
};
|
|
2368
|
+
const pause = () => {
|
|
2369
|
+
if (stopped || paused) {
|
|
2370
|
+
return;
|
|
2371
|
+
}
|
|
2372
|
+
dirtyWhilePaused = dirtyWhilePaused || debounceTimer !== null || maxWaitTimer !== null || hasDirtySources();
|
|
2373
|
+
paused = true;
|
|
2374
|
+
clearFlushTimers();
|
|
2375
|
+
};
|
|
2376
|
+
const resume = (resumeOptions) => {
|
|
2377
|
+
if (stopped) {
|
|
2378
|
+
return;
|
|
2379
|
+
}
|
|
2380
|
+
const flushPolicy = resumeOptions?.flush ?? "if-dirty";
|
|
2381
|
+
const shouldFlush = flushPolicy === "always" || flushPolicy === "if-dirty" && (dirtyWhilePaused || hasDirtySources());
|
|
2382
|
+
dirtyWhilePaused = false;
|
|
2383
|
+
paused = false;
|
|
2384
|
+
if (shouldFlush) {
|
|
2385
|
+
flush(false, resumeOptions?.triggers);
|
|
2386
|
+
}
|
|
2387
|
+
};
|
|
2388
|
+
return Object.assign(stop, {
|
|
2389
|
+
stop,
|
|
2390
|
+
pause,
|
|
2391
|
+
resume,
|
|
2392
|
+
setPaused: (nextPaused, setPausedOptions) => {
|
|
2393
|
+
if (nextPaused) {
|
|
2394
|
+
pause();
|
|
2395
|
+
} else {
|
|
2396
|
+
resume(setPausedOptions);
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
});
|
|
2400
|
+
}
|
|
2401
|
+
function watchCombinedSelector(root, selector, onChange, options = {}) {
|
|
2402
|
+
const isDocumentRoot = root.nodeType === 9;
|
|
2403
|
+
let activeElement = null;
|
|
2404
|
+
let activeWatcher = null;
|
|
2405
|
+
let stopped = false;
|
|
2406
|
+
let paused = false;
|
|
2407
|
+
let dirtyWhilePaused = false;
|
|
2408
|
+
let activeParentObserver = null;
|
|
2409
|
+
let missingTargetObserver = null;
|
|
2410
|
+
let hasBoundOnce = false;
|
|
2411
|
+
const getTarget = () => {
|
|
2412
|
+
if (selector) {
|
|
2413
|
+
return root.querySelector(selector);
|
|
2414
|
+
}
|
|
2415
|
+
if (isDocumentRoot) {
|
|
2416
|
+
return root.body;
|
|
2417
|
+
}
|
|
2418
|
+
return root;
|
|
2419
|
+
};
|
|
2420
|
+
const stopActiveWatcher = () => {
|
|
2421
|
+
activeParentObserver?.disconnect();
|
|
2422
|
+
activeParentObserver = null;
|
|
2423
|
+
activeWatcher?.stop();
|
|
2424
|
+
activeWatcher = null;
|
|
2425
|
+
activeElement = null;
|
|
2426
|
+
};
|
|
2427
|
+
const stopMissingTargetObserver = () => {
|
|
2428
|
+
missingTargetObserver?.disconnect();
|
|
2429
|
+
missingTargetObserver = null;
|
|
2430
|
+
};
|
|
2431
|
+
const observeMissingTarget = () => {
|
|
2432
|
+
if (stopped || paused || !selector || missingTargetObserver) {
|
|
2433
|
+
return;
|
|
2434
|
+
}
|
|
2435
|
+
missingTargetObserver = new MutationObserver(reconcileTarget);
|
|
2436
|
+
missingTargetObserver.observe(root, {
|
|
2437
|
+
attributes: true,
|
|
2438
|
+
childList: true,
|
|
2439
|
+
subtree: true
|
|
2440
|
+
});
|
|
2441
|
+
};
|
|
2442
|
+
const observeActiveParent = (element) => {
|
|
2443
|
+
activeParentObserver?.disconnect();
|
|
2444
|
+
activeParentObserver = null;
|
|
2445
|
+
const parent = element.parentElement;
|
|
2446
|
+
if (!parent || !selector) {
|
|
2447
|
+
return;
|
|
2448
|
+
}
|
|
2449
|
+
activeParentObserver = new MutationObserver(reconcileTarget);
|
|
2450
|
+
activeParentObserver.observe(parent, { childList: true });
|
|
2451
|
+
};
|
|
2452
|
+
const bindTarget = (element) => {
|
|
2453
|
+
stopMissingTargetObserver();
|
|
2454
|
+
activeElement = element;
|
|
2455
|
+
observeActiveParent(element);
|
|
2456
|
+
const isRebind = hasBoundOnce;
|
|
2457
|
+
hasBoundOnce = true;
|
|
2458
|
+
activeWatcher = watchCombined(
|
|
2459
|
+
element,
|
|
2460
|
+
(capture) => {
|
|
2461
|
+
if (!element.isConnected || element !== getTarget()) {
|
|
2462
|
+
reconcileTarget();
|
|
2463
|
+
return;
|
|
2464
|
+
}
|
|
2465
|
+
onChange({
|
|
2466
|
+
...capture,
|
|
2467
|
+
...isRebind && capture.provenance?.kind === "initial" ? {
|
|
2468
|
+
provenance: {
|
|
2469
|
+
kind: "watch",
|
|
2470
|
+
triggers: ["selector-rebind"]
|
|
2471
|
+
}
|
|
2472
|
+
} : {}
|
|
2473
|
+
});
|
|
2474
|
+
},
|
|
2475
|
+
options
|
|
2476
|
+
);
|
|
2477
|
+
if (paused) {
|
|
2478
|
+
activeWatcher.pause();
|
|
2479
|
+
dirtyWhilePaused = true;
|
|
2480
|
+
}
|
|
2481
|
+
};
|
|
2482
|
+
const reconcileTarget = () => {
|
|
2483
|
+
if (stopped) {
|
|
2484
|
+
return;
|
|
2485
|
+
}
|
|
2486
|
+
const nextElement = getTarget();
|
|
2487
|
+
const activeDetached = activeElement !== null && !activeElement.isConnected;
|
|
2488
|
+
const activeChanged = activeElement !== null && activeElement !== nextElement;
|
|
2489
|
+
if (activeDetached || activeChanged) {
|
|
2490
|
+
stopActiveWatcher();
|
|
2491
|
+
dirtyWhilePaused = true;
|
|
2492
|
+
}
|
|
2493
|
+
if (!nextElement) {
|
|
2494
|
+
observeMissingTarget();
|
|
2495
|
+
return;
|
|
2496
|
+
}
|
|
2497
|
+
stopMissingTargetObserver();
|
|
2498
|
+
if (!activeWatcher) {
|
|
2499
|
+
if (paused) {
|
|
2500
|
+
dirtyWhilePaused = true;
|
|
2501
|
+
return;
|
|
2502
|
+
}
|
|
2503
|
+
bindTarget(nextElement);
|
|
2504
|
+
}
|
|
2505
|
+
};
|
|
2506
|
+
reconcileTarget();
|
|
2507
|
+
const stop = () => {
|
|
2508
|
+
if (stopped) {
|
|
2509
|
+
return;
|
|
2510
|
+
}
|
|
2511
|
+
stopped = true;
|
|
2512
|
+
stopMissingTargetObserver();
|
|
2513
|
+
stopActiveWatcher();
|
|
2514
|
+
};
|
|
2515
|
+
const pause = () => {
|
|
2516
|
+
if (stopped || paused) {
|
|
2517
|
+
return;
|
|
2518
|
+
}
|
|
2519
|
+
paused = true;
|
|
2520
|
+
dirtyWhilePaused = true;
|
|
2521
|
+
stopMissingTargetObserver();
|
|
2522
|
+
activeWatcher?.pause();
|
|
2523
|
+
};
|
|
2524
|
+
const resume = (resumeOptions) => {
|
|
2525
|
+
if (stopped) {
|
|
2526
|
+
return;
|
|
2527
|
+
}
|
|
2528
|
+
paused = false;
|
|
2529
|
+
if (activeWatcher) {
|
|
2530
|
+
activeWatcher.resume(resumeOptions);
|
|
2531
|
+
dirtyWhilePaused = false;
|
|
2532
|
+
reconcileTarget();
|
|
2533
|
+
return;
|
|
2534
|
+
}
|
|
2535
|
+
const flushPolicy = resumeOptions?.flush ?? "if-dirty";
|
|
2536
|
+
const shouldFlush = flushPolicy === "always" || flushPolicy === "if-dirty" && dirtyWhilePaused;
|
|
2537
|
+
dirtyWhilePaused = false;
|
|
2538
|
+
if (shouldFlush) {
|
|
2539
|
+
reconcileTarget();
|
|
2540
|
+
} else {
|
|
2541
|
+
observeMissingTarget();
|
|
2542
|
+
}
|
|
2543
|
+
};
|
|
2544
|
+
return Object.assign(stop, {
|
|
2545
|
+
stop,
|
|
2546
|
+
pause,
|
|
2547
|
+
resume,
|
|
2548
|
+
setPaused: (nextPaused, setPausedOptions) => {
|
|
2549
|
+
if (nextPaused) {
|
|
2550
|
+
pause();
|
|
2551
|
+
} else {
|
|
2552
|
+
resume(setPausedOptions);
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
});
|
|
2556
|
+
}
|
|
2557
|
+
function getMaxModifiedTsFromElements(elements) {
|
|
2558
|
+
let max = null;
|
|
2559
|
+
const updateMax = (mtimeRaw) => {
|
|
2560
|
+
if (mtimeRaw == null) return;
|
|
2561
|
+
const value = parseInt(mtimeRaw, 10);
|
|
2562
|
+
if (!Number.isNaN(value) && (max === null || value > max)) {
|
|
2563
|
+
max = value;
|
|
2564
|
+
}
|
|
2565
|
+
};
|
|
2566
|
+
const visit = (element) => {
|
|
2567
|
+
updateMax(element.getAttribute("data-tempo-modifiedts"));
|
|
2568
|
+
updateMax(element.getAttribute("data-tempo-html-modifiedts"));
|
|
2569
|
+
};
|
|
2570
|
+
for (const element of elements) {
|
|
2571
|
+
visit(element);
|
|
2572
|
+
for (const child of element.querySelectorAll(
|
|
2573
|
+
"[data-tempo-modifiedts], [data-tempo-html-modifiedts]"
|
|
2574
|
+
)) {
|
|
2575
|
+
visit(child);
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
return max;
|
|
2579
|
+
}
|
|
2580
|
+
function getMaxModifiedTsFromHtml(capture) {
|
|
2581
|
+
let max = null;
|
|
2582
|
+
const visitHtml = (html) => {
|
|
2583
|
+
const tagRe = /<[^>]*data-tempo-(?:html-)?modifiedts="(\d+)"[^>]*>/g;
|
|
2584
|
+
for (let match = tagRe.exec(html); match !== null; match = tagRe.exec(html)) {
|
|
2585
|
+
const modifiedTs = match[1];
|
|
2586
|
+
if (modifiedTs) {
|
|
2587
|
+
updateMax(parseInt(modifiedTs, 10));
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2590
|
+
};
|
|
2591
|
+
const updateMax = (value) => {
|
|
2592
|
+
if (!Number.isNaN(value) && (max === null || value > max)) {
|
|
2593
|
+
max = value;
|
|
2594
|
+
}
|
|
2595
|
+
};
|
|
2596
|
+
visitHtml(capture.dom.html);
|
|
2597
|
+
for (const portal of capture.portals ?? []) {
|
|
2598
|
+
visitHtml(portal.html);
|
|
2599
|
+
}
|
|
2600
|
+
return max;
|
|
2601
|
+
}
|
|
2602
|
+
function getMaxModifiedTsFromFiber(tree) {
|
|
2603
|
+
if (!tree) return null;
|
|
2604
|
+
let max = null;
|
|
2605
|
+
const updateMax = (mtimeRaw) => {
|
|
2606
|
+
const value = typeof mtimeRaw === "number" ? mtimeRaw : typeof mtimeRaw === "string" ? parseInt(mtimeRaw, 10) : NaN;
|
|
2607
|
+
if (!Number.isNaN(value) && (max === null || value > max)) {
|
|
2608
|
+
max = value;
|
|
2609
|
+
}
|
|
2610
|
+
};
|
|
2611
|
+
const visit = (node) => {
|
|
2612
|
+
const props = node.props;
|
|
2613
|
+
updateMax(props?.["data-tempo-modifiedts"]);
|
|
2614
|
+
updateMax(props?.["data-tempo-html-modifiedts"]);
|
|
2615
|
+
for (const child of node.children) {
|
|
2616
|
+
visit(child);
|
|
2617
|
+
}
|
|
2618
|
+
};
|
|
2619
|
+
visit(tree);
|
|
2620
|
+
return max;
|
|
2621
|
+
}
|
|
2622
|
+
|
|
2623
|
+
// ../../modules/iframe-projection/combined/postmessage.ts
|
|
2624
|
+
var MESSAGE_MARKER = "__iframeProjection";
|
|
2625
|
+
function isMessage(data) {
|
|
2626
|
+
return typeof data === "object" && data !== null && MESSAGE_MARKER in data && data[MESSAGE_MARKER] === true;
|
|
2627
|
+
}
|
|
2628
|
+
var combinedWatchers = /* @__PURE__ */ new Map();
|
|
2629
|
+
var nextCombinedWatcherId = 1;
|
|
2630
|
+
var combinedSourceInitialized = false;
|
|
2631
|
+
var combinedSourceCleanup = null;
|
|
2632
|
+
function installWhenDocumentBodyReady(install) {
|
|
2633
|
+
let cancelled = false;
|
|
2634
|
+
let installedCleanup = null;
|
|
2635
|
+
let animationFrameId = null;
|
|
2636
|
+
let listeningForDomReady = false;
|
|
2637
|
+
const init = () => {
|
|
2638
|
+
listeningForDomReady = false;
|
|
2639
|
+
animationFrameId = null;
|
|
2640
|
+
if (cancelled) return;
|
|
2641
|
+
if (document.body) {
|
|
2642
|
+
installedCleanup = install();
|
|
2643
|
+
return;
|
|
2644
|
+
}
|
|
2645
|
+
animationFrameId = requestAnimationFrame(init);
|
|
2646
|
+
};
|
|
2647
|
+
if (document.readyState === "loading") {
|
|
2648
|
+
listeningForDomReady = true;
|
|
2649
|
+
document.addEventListener("DOMContentLoaded", init);
|
|
2650
|
+
} else {
|
|
2651
|
+
init();
|
|
2652
|
+
}
|
|
2653
|
+
return () => {
|
|
2654
|
+
if (cancelled) return;
|
|
2655
|
+
cancelled = true;
|
|
2656
|
+
if (listeningForDomReady) {
|
|
2657
|
+
document.removeEventListener("DOMContentLoaded", init);
|
|
2658
|
+
listeningForDomReady = false;
|
|
2659
|
+
}
|
|
2660
|
+
if (animationFrameId !== null) {
|
|
2661
|
+
cancelAnimationFrame(animationFrameId);
|
|
2662
|
+
animationFrameId = null;
|
|
2663
|
+
}
|
|
2664
|
+
installedCleanup?.();
|
|
2665
|
+
installedCleanup = null;
|
|
2666
|
+
};
|
|
2667
|
+
}
|
|
2668
|
+
function startCombinedSourceInterface(options = {}) {
|
|
2669
|
+
const {
|
|
2670
|
+
targetOrigin = "*",
|
|
2671
|
+
serialize,
|
|
2672
|
+
hideFiberProp
|
|
2673
|
+
} = options;
|
|
2674
|
+
if (combinedSourceInitialized) {
|
|
2675
|
+
console.warn("[combined-postmessage:source] Already initialized");
|
|
2676
|
+
return combinedSourceCleanup || (() => {
|
|
2677
|
+
});
|
|
2678
|
+
}
|
|
2679
|
+
if (typeof window === "undefined" || window.parent === window) {
|
|
2680
|
+
console.log("[combined-postmessage:source] Not in iframe, skipping");
|
|
2681
|
+
return () => {
|
|
2682
|
+
};
|
|
2683
|
+
}
|
|
2684
|
+
combinedSourceInitialized = true;
|
|
2685
|
+
let disposeDeferredInstall = () => {
|
|
2686
|
+
};
|
|
2687
|
+
let disposed = false;
|
|
2688
|
+
const cleanup = () => {
|
|
2689
|
+
if (disposed) return;
|
|
2690
|
+
disposed = true;
|
|
2691
|
+
disposeDeferredInstall();
|
|
2692
|
+
if (combinedSourceCleanup === cleanup) {
|
|
2693
|
+
combinedSourceCleanup = null;
|
|
2694
|
+
combinedSourceInitialized = false;
|
|
2695
|
+
}
|
|
2696
|
+
};
|
|
2697
|
+
combinedSourceCleanup = cleanup;
|
|
2698
|
+
const deferredInstall = installWhenDocumentBodyReady(
|
|
2699
|
+
() => initCombinedSourceInterface(
|
|
2700
|
+
targetOrigin,
|
|
2701
|
+
serialize,
|
|
2702
|
+
hideFiberProp
|
|
2703
|
+
)
|
|
2704
|
+
);
|
|
2705
|
+
if (disposed) deferredInstall();
|
|
2706
|
+
else disposeDeferredInstall = deferredInstall;
|
|
2707
|
+
return cleanup;
|
|
2708
|
+
}
|
|
2709
|
+
function initCombinedSourceInterface(targetOrigin, serialize, hideFiberProp) {
|
|
2710
|
+
window.__IFRAME_PROJECTION_COMBINED_INTERFACE_ACTIVE__ = true;
|
|
2711
|
+
const send = (msg) => {
|
|
2712
|
+
window.parent.postMessage({ ...msg, [MESSAGE_MARKER]: true }, targetOrigin);
|
|
2713
|
+
};
|
|
2714
|
+
const handleMessage = (event) => {
|
|
2715
|
+
const data = event.data;
|
|
2716
|
+
if (!isMessage(data)) return;
|
|
2717
|
+
switch (data.type) {
|
|
2718
|
+
case "combined-ping":
|
|
2719
|
+
send({ type: "combined-pong", [MESSAGE_MARKER]: true });
|
|
2720
|
+
break;
|
|
2721
|
+
case "start-combined-watcher": {
|
|
2722
|
+
const {
|
|
2723
|
+
requestId,
|
|
2724
|
+
selector,
|
|
2725
|
+
fiberSelector,
|
|
2726
|
+
fiberTags,
|
|
2727
|
+
debounceDelay,
|
|
2728
|
+
maxWait
|
|
2729
|
+
} = data;
|
|
2730
|
+
const watcherId = `combined-watcher-${nextCombinedWatcherId++}`;
|
|
2731
|
+
try {
|
|
2732
|
+
const pendingCaptures = [];
|
|
2733
|
+
let established = false;
|
|
2734
|
+
const watcher = watchCombinedSelector(
|
|
2735
|
+
document,
|
|
2736
|
+
selector,
|
|
2737
|
+
(capture) => {
|
|
2738
|
+
if (!established) {
|
|
2739
|
+
pendingCaptures.push(capture);
|
|
2740
|
+
return;
|
|
2741
|
+
}
|
|
2742
|
+
send({
|
|
2743
|
+
type: "combined-update",
|
|
2744
|
+
[MESSAGE_MARKER]: true,
|
|
2745
|
+
watcherId,
|
|
2746
|
+
capture
|
|
2747
|
+
});
|
|
2748
|
+
},
|
|
2749
|
+
{
|
|
2750
|
+
debounceDelay,
|
|
2751
|
+
maxWait,
|
|
2752
|
+
...serialize && {
|
|
2753
|
+
serialize
|
|
2754
|
+
},
|
|
2755
|
+
fiberSelector,
|
|
2756
|
+
fiberTags,
|
|
2757
|
+
hideFiberProp
|
|
2758
|
+
}
|
|
2759
|
+
);
|
|
2760
|
+
combinedWatchers.set(watcherId, watcher);
|
|
2761
|
+
send({
|
|
2762
|
+
type: "combined-watcher-started",
|
|
2763
|
+
[MESSAGE_MARKER]: true,
|
|
2764
|
+
requestId,
|
|
2765
|
+
watcherId
|
|
2766
|
+
});
|
|
2767
|
+
established = true;
|
|
2768
|
+
for (const capture of pendingCaptures) {
|
|
2769
|
+
send({
|
|
2770
|
+
type: "combined-update",
|
|
2771
|
+
[MESSAGE_MARKER]: true,
|
|
2772
|
+
watcherId,
|
|
2773
|
+
capture
|
|
2774
|
+
});
|
|
2775
|
+
}
|
|
2776
|
+
console.log(
|
|
2777
|
+
`[combined-postmessage:source] Started ${watcherId} on ${selector || "body"}`
|
|
2778
|
+
);
|
|
2779
|
+
} catch (err) {
|
|
2780
|
+
send({
|
|
2781
|
+
type: "combined-error",
|
|
2782
|
+
[MESSAGE_MARKER]: true,
|
|
2783
|
+
requestId,
|
|
2784
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2785
|
+
});
|
|
2786
|
+
}
|
|
2787
|
+
break;
|
|
2788
|
+
}
|
|
2789
|
+
case "stop-combined-watcher": {
|
|
2790
|
+
const { watcherId } = data;
|
|
2791
|
+
const watcher = combinedWatchers.get(watcherId);
|
|
2792
|
+
if (watcher) {
|
|
2793
|
+
watcher.stop();
|
|
2794
|
+
combinedWatchers.delete(watcherId);
|
|
2795
|
+
send({
|
|
2796
|
+
type: "combined-watcher-stopped",
|
|
2797
|
+
[MESSAGE_MARKER]: true,
|
|
2798
|
+
watcherId
|
|
2799
|
+
});
|
|
2800
|
+
console.log(`[combined-postmessage:source] Stopped ${watcherId}`);
|
|
2801
|
+
}
|
|
2802
|
+
break;
|
|
2803
|
+
}
|
|
2804
|
+
case "set-combined-watcher-paused": {
|
|
2805
|
+
const watcher = combinedWatchers.get(data.watcherId);
|
|
2806
|
+
watcher?.setPaused(data.paused);
|
|
2807
|
+
break;
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2810
|
+
};
|
|
2811
|
+
window.addEventListener("message", handleMessage);
|
|
2812
|
+
send({ type: "combined-source-ready", [MESSAGE_MARKER]: true });
|
|
2813
|
+
console.log(
|
|
2814
|
+
"[combined-postmessage:source] Ready, sent combined-source-ready"
|
|
2815
|
+
);
|
|
2816
|
+
return () => {
|
|
2817
|
+
window.removeEventListener("message", handleMessage);
|
|
2818
|
+
for (const [id, watcher] of combinedWatchers) {
|
|
2819
|
+
watcher.stop();
|
|
2820
|
+
console.log(`[combined-postmessage:source] Stopped ${id}`);
|
|
2821
|
+
}
|
|
2822
|
+
combinedWatchers.clear();
|
|
2823
|
+
delete window.__IFRAME_PROJECTION_COMBINED_INTERFACE_ACTIVE__;
|
|
2824
|
+
console.log("[combined-postmessage:source] Cleaned up");
|
|
2825
|
+
};
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
// canvas/interact-projection.ts
|
|
2829
|
+
var PENDING_ROOTS_KEY = "__tempoPendingFiberRoots";
|
|
2830
|
+
function installTempoInteractProjectionSource() {
|
|
2831
|
+
if (typeof window === "undefined" || window.parent === window || !isTempoInteractFrameName(window.name)) {
|
|
2832
|
+
return () => {
|
|
2833
|
+
};
|
|
2834
|
+
}
|
|
2835
|
+
const hookInterface = initHook();
|
|
2836
|
+
const hook = hookInterface.hook;
|
|
2837
|
+
const pendingRoots = hook[PENDING_ROOTS_KEY];
|
|
2838
|
+
if (pendingRoots) {
|
|
2839
|
+
hookInterface.seedCommittedRoots(pendingRoots);
|
|
2840
|
+
pendingRoots.clear();
|
|
2841
|
+
delete hook[PENDING_ROOTS_KEY];
|
|
2842
|
+
}
|
|
2843
|
+
return startCombinedSourceInterface();
|
|
2844
|
+
}
|
|
2845
|
+
export {
|
|
2846
|
+
installTempoInteractProjectionSource
|
|
2847
|
+
};
|
|
2848
|
+
//# sourceMappingURL=interact-projection.js.map
|