tempo-sdk 0.0.15 → 0.0.16
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/dist/canvas/editor.d.ts +129 -0
- package/dist/canvas/editor.js +1198 -0
- package/dist/canvas/editor.js.map +1 -0
- package/dist/canvas/index.d.ts +173 -0
- package/dist/canvas/index.js +2193 -0
- package/dist/canvas/index.js.map +1 -0
- package/dist/canvas/parser.d.ts +109 -0
- package/dist/canvas/parser.js +13 -0
- package/dist/canvas/parser.js.map +1 -0
- package/dist/chunk-B3PHU7XX.js +571 -0
- package/dist/chunk-B3PHU7XX.js.map +1 -0
- package/dist/chunk-EJBWZCEE.js +434 -0
- package/dist/chunk-EJBWZCEE.js.map +1 -0
- package/dist/chunk-ICP7LCPJ.js +615 -0
- package/dist/chunk-ICP7LCPJ.js.map +1 -0
- package/dist/chunk-MBTLXFNP.js +605 -0
- package/dist/chunk-MBTLXFNP.js.map +1 -0
- package/dist/chunk-MD3HJ7L3.js +457 -0
- package/dist/chunk-MD3HJ7L3.js.map +1 -0
- package/dist/chunk-O3HYJ6BU.js +433 -0
- package/dist/chunk-O3HYJ6BU.js.map +1 -0
- package/dist/index.d.ts +3 -34
- package/dist/page-BokkL6FZ.d.ts +35 -0
- package/dist/page-xi1aI5a7.d.ts +36 -0
- package/package.json +15 -1
|
@@ -0,0 +1,2193 @@
|
|
|
1
|
+
// canvas/canvas.tsx
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
useContext,
|
|
5
|
+
useMemo
|
|
6
|
+
} from "react";
|
|
7
|
+
|
|
8
|
+
// canvas/ids.ts
|
|
9
|
+
function normalizeId(value, label) {
|
|
10
|
+
const normalized = value?.trim();
|
|
11
|
+
if (!normalized) {
|
|
12
|
+
throw new Error(`${label} is required.`);
|
|
13
|
+
}
|
|
14
|
+
return normalized;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// canvas/canvas.tsx
|
|
18
|
+
import { jsx } from "react/jsx-runtime";
|
|
19
|
+
var CanvasIdentityContext = createContext(null);
|
|
20
|
+
function getCanvasStoryboardRenderId(canvasPath, storyboardId) {
|
|
21
|
+
return `canvas:${encodeURIComponent(
|
|
22
|
+
normalizeId(canvasPath, "Canvas path")
|
|
23
|
+
)}#storyboard:${encodeURIComponent(
|
|
24
|
+
normalizeId(storyboardId, "Storyboard id")
|
|
25
|
+
)}`;
|
|
26
|
+
}
|
|
27
|
+
function useCanvasIdentity() {
|
|
28
|
+
return useContext(CanvasIdentityContext);
|
|
29
|
+
}
|
|
30
|
+
function useCanvasStoryboardRenderId(storyboardId) {
|
|
31
|
+
const canvas = useCanvasIdentity();
|
|
32
|
+
const normalizedId = normalizeId(storyboardId, "Storyboard id");
|
|
33
|
+
return canvas ? getCanvasStoryboardRenderId(canvas.path, normalizedId) : normalizedId;
|
|
34
|
+
}
|
|
35
|
+
function Canvas({
|
|
36
|
+
children,
|
|
37
|
+
name,
|
|
38
|
+
path,
|
|
39
|
+
backgroundColor,
|
|
40
|
+
defaultViewport
|
|
41
|
+
}) {
|
|
42
|
+
const contextIdentity = useCanvasIdentity();
|
|
43
|
+
const canvasName = normalizeId(name, "Canvas name");
|
|
44
|
+
const canvasPath = path === void 0 ? contextIdentity?.path : normalizeId(path, "Canvas path");
|
|
45
|
+
if (!canvasPath) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
'<Canvas> must be rendered inside <CanvasContext path="..."> or receive a path prop.'
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const identity = useMemo(() => ({ path: canvasPath }), [canvasPath]);
|
|
51
|
+
return /* @__PURE__ */ jsx(CanvasIdentityContext.Provider, { value: identity, children: /* @__PURE__ */ jsx(
|
|
52
|
+
"div",
|
|
53
|
+
{
|
|
54
|
+
"data-tempo-canvas": canvasName,
|
|
55
|
+
"data-tempo-canvas-path": canvasPath,
|
|
56
|
+
"data-tempo-canvas-background": backgroundColor,
|
|
57
|
+
"data-tempo-canvas-viewport": defaultViewport ? JSON.stringify(defaultViewport) : void 0,
|
|
58
|
+
children
|
|
59
|
+
}
|
|
60
|
+
) });
|
|
61
|
+
}
|
|
62
|
+
function CanvasContext({
|
|
63
|
+
children,
|
|
64
|
+
path
|
|
65
|
+
}) {
|
|
66
|
+
const canvasPath = normalizeId(path, "Canvas path");
|
|
67
|
+
const identity = useMemo(() => ({ path: canvasPath }), [canvasPath]);
|
|
68
|
+
return /* @__PURE__ */ jsx(CanvasIdentityContext.Provider, { value: identity, children });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// canvas/canvas-host.tsx
|
|
72
|
+
import {
|
|
73
|
+
useMemo as useMemo3
|
|
74
|
+
} from "react";
|
|
75
|
+
|
|
76
|
+
// canvas/runtime-context.ts
|
|
77
|
+
import { createContext as createContext2, useCallback, useContext as useContext2 } from "react";
|
|
78
|
+
var CanvasHostContext = createContext2(null);
|
|
79
|
+
function useRequiredCanvasHost() {
|
|
80
|
+
const host = useContext2(CanvasHostContext);
|
|
81
|
+
if (!host) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
"Tempo canvas components must be rendered inside <CanvasHost>."
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
return host;
|
|
87
|
+
}
|
|
88
|
+
function useActiveState(storyboardId) {
|
|
89
|
+
const renderId = useCanvasStoryboardRenderId(storyboardId);
|
|
90
|
+
const host = useRequiredCanvasHost();
|
|
91
|
+
return host.getStoryboardStatus(renderId) !== "unmounted";
|
|
92
|
+
}
|
|
93
|
+
function useStoryboardStatus(storyboardId) {
|
|
94
|
+
const renderId = useCanvasStoryboardRenderId(storyboardId);
|
|
95
|
+
const host = useRequiredCanvasHost();
|
|
96
|
+
return host.getStoryboardStatus(renderId);
|
|
97
|
+
}
|
|
98
|
+
function useStoryboardRendered(storyboardId) {
|
|
99
|
+
const renderId = useCanvasStoryboardRenderId(storyboardId);
|
|
100
|
+
const host = useRequiredCanvasHost();
|
|
101
|
+
return useCallback(() => {
|
|
102
|
+
host.markStoryboardRendered(renderId);
|
|
103
|
+
}, [host, renderId]);
|
|
104
|
+
}
|
|
105
|
+
function useStoryboardErrorReporter(storyboardId) {
|
|
106
|
+
const renderId = useCanvasStoryboardRenderId(storyboardId);
|
|
107
|
+
const host = useRequiredCanvasHost();
|
|
108
|
+
const reportError = useCallback(
|
|
109
|
+
(error) => {
|
|
110
|
+
host.reportStoryboardError(renderId, error);
|
|
111
|
+
},
|
|
112
|
+
[host, renderId]
|
|
113
|
+
);
|
|
114
|
+
const clearError = useCallback(() => {
|
|
115
|
+
host.clearStoryboardError(renderId);
|
|
116
|
+
}, [host, renderId]);
|
|
117
|
+
return { reportError, clearError };
|
|
118
|
+
}
|
|
119
|
+
function useStoryboardSize(storyboardId) {
|
|
120
|
+
const renderId = useCanvasStoryboardRenderId(storyboardId);
|
|
121
|
+
const host = useRequiredCanvasHost();
|
|
122
|
+
return host.getStoryboardSize(renderId);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// canvas/use-canvas-host-postmessage.ts
|
|
126
|
+
import { useCallback as useCallback2, useEffect, useMemo as useMemo2, useRef, useState } from "react";
|
|
127
|
+
|
|
128
|
+
// canvas/canvas-host-runtime.ts
|
|
129
|
+
function getCanvasHostRuntime() {
|
|
130
|
+
const runtime = window.__tempoCanvasHostRuntime;
|
|
131
|
+
if (!runtime) {
|
|
132
|
+
throw new Error("window.__tempoCanvasHostRuntime is not installed.");
|
|
133
|
+
}
|
|
134
|
+
return runtime;
|
|
135
|
+
}
|
|
136
|
+
function getOptionalCanvasHostRuntime() {
|
|
137
|
+
return typeof window === "undefined" ? void 0 : window.__tempoCanvasHostRuntime;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// canvas/portal-tracking.ts
|
|
141
|
+
var PORTAL_MANAGED_PROPERTIES = [
|
|
142
|
+
{ key: "visibility", cssName: "visibility", hiddenValue: "hidden" },
|
|
143
|
+
{ key: "pointerEvents", cssName: "pointer-events", hiddenValue: "none" },
|
|
144
|
+
{
|
|
145
|
+
key: "contentVisibility",
|
|
146
|
+
cssName: "content-visibility",
|
|
147
|
+
hiddenValue: "hidden"
|
|
148
|
+
},
|
|
149
|
+
{ key: "transition", cssName: "transition", hiddenValue: "none" },
|
|
150
|
+
{ key: "animation", cssName: "animation", hiddenValue: "none" }
|
|
151
|
+
];
|
|
152
|
+
var portalElementsByRenderId = /* @__PURE__ */ new Map();
|
|
153
|
+
var portalOwnerRenderIdsByElement = /* @__PURE__ */ new Map();
|
|
154
|
+
var portalInlineStyleByElement = /* @__PURE__ */ new Map();
|
|
155
|
+
var renderStatusById = /* @__PURE__ */ new Map();
|
|
156
|
+
var projectionPortalIdAttribute = "data-projection-portal-id";
|
|
157
|
+
var nextSdkPortalId = 1;
|
|
158
|
+
function escapeAttributeValue(value) {
|
|
159
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
160
|
+
}
|
|
161
|
+
function ensureProjectionPortalId(portalRoot) {
|
|
162
|
+
const existingId = portalRoot.getAttribute(projectionPortalIdAttribute);
|
|
163
|
+
if (existingId) return existingId;
|
|
164
|
+
const id = `tempo-sdk-portal-${nextSdkPortalId++}`;
|
|
165
|
+
portalRoot.setAttribute(projectionPortalIdAttribute, id);
|
|
166
|
+
return id;
|
|
167
|
+
}
|
|
168
|
+
function buildProjectionPortalSelector(portalRoot) {
|
|
169
|
+
return `[${projectionPortalIdAttribute}="${escapeAttributeValue(
|
|
170
|
+
ensureProjectionPortalId(portalRoot)
|
|
171
|
+
)}"]`;
|
|
172
|
+
}
|
|
173
|
+
function findFiberKey(element) {
|
|
174
|
+
return Object.keys(element).find(
|
|
175
|
+
(key) => key.startsWith("__reactFiber$") || key.startsWith("__reactInternalInstance$")
|
|
176
|
+
) ?? null;
|
|
177
|
+
}
|
|
178
|
+
function findContainerKey(element) {
|
|
179
|
+
return Object.keys(element).find((key) => key.startsWith("__reactContainer$")) ?? null;
|
|
180
|
+
}
|
|
181
|
+
function getFiberFromElement(element) {
|
|
182
|
+
const fiberKey = findFiberKey(element);
|
|
183
|
+
if (fiberKey) {
|
|
184
|
+
return element[fiberKey] ?? null;
|
|
185
|
+
}
|
|
186
|
+
const containerKey = findContainerKey(element);
|
|
187
|
+
if (containerKey) {
|
|
188
|
+
return element[containerKey] ?? null;
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
var PortalTracker = class {
|
|
193
|
+
constructor() {
|
|
194
|
+
this.watchers = /* @__PURE__ */ new Set();
|
|
195
|
+
this.ownerWatchersByPortalRoot = /* @__PURE__ */ new Map();
|
|
196
|
+
this.observer = null;
|
|
197
|
+
this.handleMutations = (mutations) => {
|
|
198
|
+
for (const mutation of mutations) {
|
|
199
|
+
for (const node of mutation.addedNodes) {
|
|
200
|
+
if (node instanceof Element) {
|
|
201
|
+
queueMicrotask(() => this.checkElement(node));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
for (const node of mutation.removedNodes) {
|
|
205
|
+
if (!(node instanceof Element)) continue;
|
|
206
|
+
const owners = this.ownerWatchersByPortalRoot.get(node);
|
|
207
|
+
if (!owners) continue;
|
|
208
|
+
for (const owner of owners) {
|
|
209
|
+
owner.onPortalRemoved(node);
|
|
210
|
+
}
|
|
211
|
+
this.ownerWatchersByPortalRoot.delete(node);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
register(watcher) {
|
|
217
|
+
this.watchers.add(watcher);
|
|
218
|
+
if (this.watchers.size === 1) {
|
|
219
|
+
this.startObserving();
|
|
220
|
+
}
|
|
221
|
+
if (typeof document !== "undefined" && document.body) {
|
|
222
|
+
this.checkExistingElements();
|
|
223
|
+
queueMicrotask(() => this.checkExistingElements());
|
|
224
|
+
}
|
|
225
|
+
return () => this.unregister(watcher);
|
|
226
|
+
}
|
|
227
|
+
checkExistingElements() {
|
|
228
|
+
if (typeof document === "undefined" || !document.body) return;
|
|
229
|
+
for (const child of Array.from(document.body.children)) {
|
|
230
|
+
this.checkElement(child);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
unregister(watcher) {
|
|
234
|
+
this.watchers.delete(watcher);
|
|
235
|
+
for (const [portalRoot, owners] of this.ownerWatchersByPortalRoot) {
|
|
236
|
+
owners.delete(watcher);
|
|
237
|
+
if (owners.size === 0) {
|
|
238
|
+
this.ownerWatchersByPortalRoot.delete(portalRoot);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (this.watchers.size === 0) {
|
|
242
|
+
this.stopObserving();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
startObserving() {
|
|
246
|
+
if (this.observer || typeof document === "undefined" || !document.body || typeof MutationObserver === "undefined") {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
this.observer = new MutationObserver(this.handleMutations);
|
|
250
|
+
this.observer.observe(document.body, { childList: true });
|
|
251
|
+
}
|
|
252
|
+
stopObserving() {
|
|
253
|
+
this.observer?.disconnect();
|
|
254
|
+
this.observer = null;
|
|
255
|
+
}
|
|
256
|
+
checkElement(element) {
|
|
257
|
+
const ancestorDomNodes = this.getDomAncestorsViaFiber(element);
|
|
258
|
+
if (ancestorDomNodes.length === 0) return;
|
|
259
|
+
let owners = this.ownerWatchersByPortalRoot.get(element);
|
|
260
|
+
for (const watcher of this.watchers) {
|
|
261
|
+
const belongsToWatcher = ancestorDomNodes.some(
|
|
262
|
+
(node) => watcher.element.contains(node) || watcher.element === node
|
|
263
|
+
);
|
|
264
|
+
if (!belongsToWatcher) continue;
|
|
265
|
+
if (!owners) {
|
|
266
|
+
owners = /* @__PURE__ */ new Set();
|
|
267
|
+
this.ownerWatchersByPortalRoot.set(element, owners);
|
|
268
|
+
}
|
|
269
|
+
if (owners.has(watcher)) continue;
|
|
270
|
+
owners.add(watcher);
|
|
271
|
+
watcher.onPortalFound(element);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
getDomAncestorsViaFiber(element) {
|
|
275
|
+
const fiber = getFiberFromElement(element);
|
|
276
|
+
if (!fiber) return [];
|
|
277
|
+
const domNodes = [];
|
|
278
|
+
let current = fiber.return;
|
|
279
|
+
while (current) {
|
|
280
|
+
if (current.stateNode instanceof Element) {
|
|
281
|
+
domNodes.push(current.stateNode);
|
|
282
|
+
}
|
|
283
|
+
current = current.return;
|
|
284
|
+
}
|
|
285
|
+
return domNodes;
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
var portalTracker = null;
|
|
289
|
+
function getPortalTracker() {
|
|
290
|
+
if (!portalTracker) {
|
|
291
|
+
portalTracker = new PortalTracker();
|
|
292
|
+
}
|
|
293
|
+
return portalTracker;
|
|
294
|
+
}
|
|
295
|
+
function getStylablePortalElement(portalRoot) {
|
|
296
|
+
if (portalRoot instanceof HTMLElement || portalRoot instanceof SVGElement) {
|
|
297
|
+
return portalRoot;
|
|
298
|
+
}
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
function ensurePortalInlineStyle(portalRoot) {
|
|
302
|
+
const existing = portalInlineStyleByElement.get(portalRoot);
|
|
303
|
+
if (existing) return existing;
|
|
304
|
+
const stylableElement = getStylablePortalElement(portalRoot);
|
|
305
|
+
const baseline = {
|
|
306
|
+
visibility: readInlineStyleValue(stylableElement, "visibility"),
|
|
307
|
+
pointerEvents: readInlineStyleValue(stylableElement, "pointer-events"),
|
|
308
|
+
contentVisibility: readInlineStyleValue(
|
|
309
|
+
stylableElement,
|
|
310
|
+
"content-visibility"
|
|
311
|
+
),
|
|
312
|
+
transition: readInlineStyleValue(stylableElement, "transition"),
|
|
313
|
+
animation: readInlineStyleValue(stylableElement, "animation")
|
|
314
|
+
};
|
|
315
|
+
portalInlineStyleByElement.set(portalRoot, baseline);
|
|
316
|
+
return baseline;
|
|
317
|
+
}
|
|
318
|
+
function readInlineStyleValue(element, propertyName) {
|
|
319
|
+
return {
|
|
320
|
+
value: element?.style.getPropertyValue(propertyName) ?? "",
|
|
321
|
+
priority: element?.style.getPropertyPriority(propertyName) ?? ""
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
function restoreInlineStyleValue(style, propertyName, baseline) {
|
|
325
|
+
if (baseline.value) {
|
|
326
|
+
style.setProperty(propertyName, baseline.value, baseline.priority);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
style.removeProperty(propertyName);
|
|
330
|
+
}
|
|
331
|
+
function restorePortalInlineStyle(portalRoot) {
|
|
332
|
+
const stylableElement = getStylablePortalElement(portalRoot);
|
|
333
|
+
const baseline = portalInlineStyleByElement.get(portalRoot);
|
|
334
|
+
if (!stylableElement || !baseline) return;
|
|
335
|
+
for (const property of PORTAL_MANAGED_PROPERTIES) {
|
|
336
|
+
restoreInlineStyleValue(
|
|
337
|
+
stylableElement.style,
|
|
338
|
+
property.cssName,
|
|
339
|
+
baseline[property.key]
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
function syncPortalVisibility(portalRoot) {
|
|
344
|
+
const owners = portalOwnerRenderIdsByElement.get(portalRoot);
|
|
345
|
+
if (!owners || owners.size === 0) {
|
|
346
|
+
restorePortalInlineStyle(portalRoot);
|
|
347
|
+
portalInlineStyleByElement.delete(portalRoot);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const stylableElement = getStylablePortalElement(portalRoot);
|
|
351
|
+
if (!stylableElement) return;
|
|
352
|
+
const shouldBeVisible = [...owners].some(
|
|
353
|
+
(renderId) => renderStatusById.get(renderId) === "active"
|
|
354
|
+
);
|
|
355
|
+
if (shouldBeVisible) {
|
|
356
|
+
restorePortalInlineStyle(portalRoot);
|
|
357
|
+
portalInlineStyleByElement.delete(portalRoot);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
ensurePortalInlineStyle(portalRoot);
|
|
361
|
+
for (const property of PORTAL_MANAGED_PROPERTIES) {
|
|
362
|
+
stylableElement.style.setProperty(
|
|
363
|
+
property.cssName,
|
|
364
|
+
property.hiddenValue,
|
|
365
|
+
"important"
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
function trackPortal(renderId, portalRoot) {
|
|
370
|
+
ensureProjectionPortalId(portalRoot);
|
|
371
|
+
const portals = portalElementsByRenderId.get(renderId) ?? /* @__PURE__ */ new Set();
|
|
372
|
+
portals.add(portalRoot);
|
|
373
|
+
portalElementsByRenderId.set(renderId, portals);
|
|
374
|
+
const owners = portalOwnerRenderIdsByElement.get(portalRoot) ?? /* @__PURE__ */ new Set();
|
|
375
|
+
owners.add(renderId);
|
|
376
|
+
portalOwnerRenderIdsByElement.set(portalRoot, owners);
|
|
377
|
+
syncPortalVisibility(portalRoot);
|
|
378
|
+
}
|
|
379
|
+
function untrackPortal(renderId, portalRoot) {
|
|
380
|
+
const portals = portalElementsByRenderId.get(renderId);
|
|
381
|
+
if (!portals) return;
|
|
382
|
+
portals.delete(portalRoot);
|
|
383
|
+
if (portals.size === 0) {
|
|
384
|
+
portalElementsByRenderId.delete(renderId);
|
|
385
|
+
}
|
|
386
|
+
const owners = portalOwnerRenderIdsByElement.get(portalRoot);
|
|
387
|
+
if (owners) {
|
|
388
|
+
owners.delete(renderId);
|
|
389
|
+
if (owners.size === 0) {
|
|
390
|
+
portalOwnerRenderIdsByElement.delete(portalRoot);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
syncPortalVisibility(portalRoot);
|
|
394
|
+
}
|
|
395
|
+
function releaseStoryboardPortals(renderId) {
|
|
396
|
+
const portals = portalElementsByRenderId.get(renderId);
|
|
397
|
+
if (!portals) {
|
|
398
|
+
renderStatusById.delete(renderId);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
for (const portalRoot of [...portals]) {
|
|
402
|
+
untrackPortal(renderId, portalRoot);
|
|
403
|
+
}
|
|
404
|
+
renderStatusById.delete(renderId);
|
|
405
|
+
}
|
|
406
|
+
function getStoryboardPortalSelectors(renderId) {
|
|
407
|
+
const portals = portalElementsByRenderId.get(renderId);
|
|
408
|
+
if (!portals) return [];
|
|
409
|
+
return [...portals].filter((portalRoot) => portalRoot.isConnected).map(buildProjectionPortalSelector);
|
|
410
|
+
}
|
|
411
|
+
function syncStoryboardPortals(renderId, status) {
|
|
412
|
+
renderStatusById.set(renderId, status);
|
|
413
|
+
const portals = portalElementsByRenderId.get(renderId);
|
|
414
|
+
if (!portals) return;
|
|
415
|
+
for (const portalRoot of portals) {
|
|
416
|
+
syncPortalVisibility(portalRoot);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
function trackStoryboardPortals(renderId, element, status) {
|
|
420
|
+
syncStoryboardPortals(renderId, status);
|
|
421
|
+
const unregister = getPortalTracker().register({
|
|
422
|
+
element,
|
|
423
|
+
onPortalFound(portalRoot) {
|
|
424
|
+
trackPortal(renderId, portalRoot);
|
|
425
|
+
},
|
|
426
|
+
onPortalRemoved(portalRoot) {
|
|
427
|
+
untrackPortal(renderId, portalRoot);
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
return () => {
|
|
431
|
+
unregister();
|
|
432
|
+
releaseStoryboardPortals(renderId);
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// canvas/canvas-host-operations.ts
|
|
437
|
+
var escapeRenderId = (renderId) => renderId.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
438
|
+
var buildRenderSelector = (renderId) => `[data-render-id="${escapeRenderId(renderId)}"]`;
|
|
439
|
+
var buildRenderContentSelector = (renderId) => `[data-render-content="${escapeRenderId(renderId)}"]`;
|
|
440
|
+
var buildRenderContentFiberSelector = (renderId) => `${buildRenderContentSelector(renderId)} > :not([data-tempo-hide-fiber="true"])`;
|
|
441
|
+
function stripRenderContentWrapperAttributes(capture, renderId) {
|
|
442
|
+
if (!capture || typeof capture !== "object") return capture;
|
|
443
|
+
const dom = capture.dom;
|
|
444
|
+
if (!dom) return capture;
|
|
445
|
+
const shouldStripAttributes = dom.selector === "" && dom.attributes?.["data-render-content"] === renderId;
|
|
446
|
+
const shouldStripRootAttributes = dom.rootAttributes?.["data-render-content"] === renderId;
|
|
447
|
+
if (!shouldStripAttributes && !shouldStripRootAttributes) return capture;
|
|
448
|
+
return {
|
|
449
|
+
...capture,
|
|
450
|
+
dom: {
|
|
451
|
+
...dom,
|
|
452
|
+
attributes: shouldStripAttributes ? void 0 : dom.attributes,
|
|
453
|
+
rootAttributes: shouldStripRootAttributes ? void 0 : dom.rootAttributes
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
function stripRenderContentWrapperFromCombinedCapture(capture, renderId) {
|
|
458
|
+
if (!capture || typeof capture !== "object" || !("html" in capture)) {
|
|
459
|
+
return capture;
|
|
460
|
+
}
|
|
461
|
+
const html = capture.html;
|
|
462
|
+
if (!html) return capture;
|
|
463
|
+
return {
|
|
464
|
+
...capture,
|
|
465
|
+
html: stripRenderContentWrapperAttributes(html, renderId)
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
function captureStoryboardImage(renderId, options) {
|
|
469
|
+
const portalSelectors = [
|
|
470
|
+
...options?.portalSelectors ?? [],
|
|
471
|
+
...getStoryboardPortalSelectors(renderId)
|
|
472
|
+
];
|
|
473
|
+
return getCanvasHostRuntime().captureSelector(
|
|
474
|
+
buildRenderSelector(renderId),
|
|
475
|
+
portalSelectors.length > 0 ? { ...options, portalSelectors: [...new Set(portalSelectors)] } : options
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
async function captureStoryboardHtml(renderId, options) {
|
|
479
|
+
const capture = await getCanvasHostRuntime().captureHtml?.({
|
|
480
|
+
selector: buildRenderContentSelector(renderId),
|
|
481
|
+
timeout: options?.timeout
|
|
482
|
+
});
|
|
483
|
+
return capture ? stripRenderContentWrapperAttributes(capture, renderId) : null;
|
|
484
|
+
}
|
|
485
|
+
function captureStoryboardStaticHtml(renderId, options) {
|
|
486
|
+
return getCanvasHostRuntime().captureStaticHtml?.({
|
|
487
|
+
selector: buildRenderContentSelector(renderId),
|
|
488
|
+
timeout: options?.timeout
|
|
489
|
+
}) ?? Promise.resolve(null);
|
|
490
|
+
}
|
|
491
|
+
async function captureStoryboardCombined(renderId, options) {
|
|
492
|
+
const capture = await getCanvasHostRuntime().captureCombined?.({
|
|
493
|
+
selector: buildRenderContentSelector(renderId),
|
|
494
|
+
fiberSelector: options?.fiberSelector ?? buildRenderContentFiberSelector(renderId),
|
|
495
|
+
fiberTags: options?.fiberTags,
|
|
496
|
+
timeout: options?.timeout
|
|
497
|
+
});
|
|
498
|
+
return capture ? stripRenderContentWrapperFromCombinedCapture(capture, renderId) : null;
|
|
499
|
+
}
|
|
500
|
+
function watchStoryboardHtml(renderId, options) {
|
|
501
|
+
const runtime = getCanvasHostRuntime();
|
|
502
|
+
if (!runtime.watchHtml) {
|
|
503
|
+
return Promise.reject(new Error("watchHtml is not available."));
|
|
504
|
+
}
|
|
505
|
+
return runtime.watchHtml({
|
|
506
|
+
selector: buildRenderContentSelector(renderId),
|
|
507
|
+
onUpdate(capture) {
|
|
508
|
+
options.onUpdate(stripRenderContentWrapperAttributes(capture, renderId));
|
|
509
|
+
},
|
|
510
|
+
onError: options.onError,
|
|
511
|
+
debounceDelay: options.debounceDelay,
|
|
512
|
+
maxWait: options.maxWait,
|
|
513
|
+
timeout: options.timeout
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
function watchStoryboardCombined(renderId, options) {
|
|
517
|
+
const runtime = getCanvasHostRuntime();
|
|
518
|
+
if (!runtime.watchCombined) {
|
|
519
|
+
return Promise.reject(new Error("watchCombined is not available."));
|
|
520
|
+
}
|
|
521
|
+
return runtime.watchCombined({
|
|
522
|
+
selector: buildRenderContentSelector(renderId),
|
|
523
|
+
fiberSelector: options.fiberSelector ?? buildRenderContentFiberSelector(renderId),
|
|
524
|
+
fiberTags: options.fiberTags,
|
|
525
|
+
onUpdate(capture) {
|
|
526
|
+
options.onUpdate(
|
|
527
|
+
stripRenderContentWrapperFromCombinedCapture(capture, renderId)
|
|
528
|
+
);
|
|
529
|
+
},
|
|
530
|
+
onError: options.onError,
|
|
531
|
+
debounceDelay: options.debounceDelay,
|
|
532
|
+
maxWait: options.maxWait,
|
|
533
|
+
timeout: options.timeout,
|
|
534
|
+
knownSourceVersion: options.knownSourceVersion
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// canvas/canvas-host-protocol.ts
|
|
539
|
+
function isRecord(value) {
|
|
540
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
541
|
+
}
|
|
542
|
+
function readCanvasHostCommand(message) {
|
|
543
|
+
if (!isRecord(message) || typeof message.type !== "string") return null;
|
|
544
|
+
return {
|
|
545
|
+
type: message.type,
|
|
546
|
+
requestId: message.requestId,
|
|
547
|
+
payload: isRecord(message.payload) ? message.payload : {}
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
var readTrimmedString = (value) => {
|
|
551
|
+
if (typeof value !== "string") return void 0;
|
|
552
|
+
const normalized = value.trim();
|
|
553
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
554
|
+
};
|
|
555
|
+
function resolveRenderTarget(payload) {
|
|
556
|
+
const explicitRenderId = readTrimmedString(payload.renderId);
|
|
557
|
+
const canvasPath = readTrimmedString(payload.canvasPath);
|
|
558
|
+
const storyboardId = readTrimmedString(payload.storyboardId);
|
|
559
|
+
const renderId = explicitRenderId || (canvasPath && storyboardId ? getCanvasStoryboardRenderId(canvasPath, storyboardId) : storyboardId);
|
|
560
|
+
return renderId ? {
|
|
561
|
+
renderId,
|
|
562
|
+
...canvasPath ? { canvasPath } : {},
|
|
563
|
+
...storyboardId ? { storyboardId } : {}
|
|
564
|
+
} : null;
|
|
565
|
+
}
|
|
566
|
+
function requireRenderTarget(commandType, payload) {
|
|
567
|
+
const target = resolveRenderTarget(payload);
|
|
568
|
+
if (!target) {
|
|
569
|
+
throw new Error(
|
|
570
|
+
`${commandType} requires payload.renderId or payload.canvasPath + payload.storyboardId`
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
return target;
|
|
574
|
+
}
|
|
575
|
+
var readPositiveFiniteNumber = (value, fieldName) => {
|
|
576
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
577
|
+
throw new Error(`${fieldName} must be a positive finite number`);
|
|
578
|
+
}
|
|
579
|
+
return value;
|
|
580
|
+
};
|
|
581
|
+
function readOptionalNumber(payload, fieldName) {
|
|
582
|
+
return typeof payload[fieldName] === "number" ? payload[fieldName] : void 0;
|
|
583
|
+
}
|
|
584
|
+
function readOptionalSize(payload) {
|
|
585
|
+
const hasWidth = payload.width != null;
|
|
586
|
+
const hasHeight = payload.height != null;
|
|
587
|
+
if (!hasWidth && !hasHeight) return {};
|
|
588
|
+
if (!hasWidth || !hasHeight) {
|
|
589
|
+
throw new Error("width and height must be provided together");
|
|
590
|
+
}
|
|
591
|
+
return {
|
|
592
|
+
width: readPositiveFiniteNumber(payload.width, "width"),
|
|
593
|
+
height: readPositiveFiniteNumber(payload.height, "height")
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function readRenderRequest(commandType, payload) {
|
|
597
|
+
const target = requireRenderTarget(commandType, payload);
|
|
598
|
+
const importPath = readTrimmedString(payload.importPath);
|
|
599
|
+
const importName = readTrimmedString(payload.importName);
|
|
600
|
+
const props = isRecord(payload.props) ? payload.props : void 0;
|
|
601
|
+
return {
|
|
602
|
+
...target,
|
|
603
|
+
importPath: importPath ?? target.canvasPath ?? target.renderId,
|
|
604
|
+
importName: importName ?? target.storyboardId ?? target.renderId,
|
|
605
|
+
...props ? { props } : {},
|
|
606
|
+
...readOptionalSize(payload),
|
|
607
|
+
intrinsicSize: payload.intrinsicSize === true ? true : void 0
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
function readWatchId(commandType, payload) {
|
|
611
|
+
const watchId = readTrimmedString(payload.watchId);
|
|
612
|
+
if (!watchId) {
|
|
613
|
+
throw new Error(`${commandType} requires payload.watchId`);
|
|
614
|
+
}
|
|
615
|
+
return watchId;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// canvas/canvas-host-render-state.ts
|
|
619
|
+
var propsMatch = (a, b) => JSON.stringify(a ?? {}) === JSON.stringify(b ?? {});
|
|
620
|
+
function renderRequestMatchesEntry(entry, request) {
|
|
621
|
+
return entry?.importPath === request.importPath && entry.importName === request.importName && entry.width === request.width && entry.height === request.height && entry.intrinsicSize === request.intrinsicSize && propsMatch(entry.props, request.props);
|
|
622
|
+
}
|
|
623
|
+
function acquireRender(entries, request) {
|
|
624
|
+
const next = new Map(entries);
|
|
625
|
+
const current = next.get(request.renderId);
|
|
626
|
+
const changed = !renderRequestMatchesEntry(current, request);
|
|
627
|
+
next.set(request.renderId, {
|
|
628
|
+
...request,
|
|
629
|
+
status: "active",
|
|
630
|
+
activeCount: (current?.activeCount ?? 0) + 1,
|
|
631
|
+
revision: changed ? (current?.revision ?? 0) + 1 : current?.revision ?? 1
|
|
632
|
+
});
|
|
633
|
+
return next;
|
|
634
|
+
}
|
|
635
|
+
function releaseRender(entries, renderId, maxCached, now = Date.now()) {
|
|
636
|
+
const current = entries.get(renderId);
|
|
637
|
+
if (!current) return new Map(entries);
|
|
638
|
+
const next = new Map(entries);
|
|
639
|
+
const activeCount = Math.max(0, current.activeCount - 1);
|
|
640
|
+
if (activeCount > 0) {
|
|
641
|
+
next.set(renderId, { ...current, activeCount, status: "active" });
|
|
642
|
+
return next;
|
|
643
|
+
}
|
|
644
|
+
next.set(renderId, {
|
|
645
|
+
...current,
|
|
646
|
+
activeCount: 0,
|
|
647
|
+
status: "cached",
|
|
648
|
+
lastInactiveAt: now
|
|
649
|
+
});
|
|
650
|
+
return evictCachedRenders(next, maxCached);
|
|
651
|
+
}
|
|
652
|
+
function evictCachedRenders(entries, maxCached) {
|
|
653
|
+
const next = new Map(entries);
|
|
654
|
+
const cached = [...next.values()].filter((entry) => entry.status === "cached").sort((a, b) => (a.lastInactiveAt ?? 0) - (b.lastInactiveAt ?? 0));
|
|
655
|
+
for (const entry of cached.slice(0, Math.max(0, cached.length - maxCached))) {
|
|
656
|
+
next.delete(entry.renderId);
|
|
657
|
+
}
|
|
658
|
+
return next;
|
|
659
|
+
}
|
|
660
|
+
function buildRenderStatePayload(entries, maxCached) {
|
|
661
|
+
return {
|
|
662
|
+
renders: [...entries.values()].map(
|
|
663
|
+
({
|
|
664
|
+
activeCount: _activeCount,
|
|
665
|
+
lastInactiveAt: _lastInactiveAt,
|
|
666
|
+
revision: _revision,
|
|
667
|
+
...entry
|
|
668
|
+
}) => entry
|
|
669
|
+
),
|
|
670
|
+
maxCached
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
function buildRenderStatusMap(entries) {
|
|
674
|
+
return new Map([...entries].map(([id, entry]) => [id, entry.status]));
|
|
675
|
+
}
|
|
676
|
+
function buildRenderSizeMap(entries) {
|
|
677
|
+
return new Map(
|
|
678
|
+
[...entries].map(([id, entry]) => [
|
|
679
|
+
id,
|
|
680
|
+
{
|
|
681
|
+
width: entry.width,
|
|
682
|
+
height: entry.height,
|
|
683
|
+
intrinsicSize: entry.intrinsicSize,
|
|
684
|
+
revision: entry.revision
|
|
685
|
+
}
|
|
686
|
+
])
|
|
687
|
+
);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// canvas/runtime-problems.ts
|
|
691
|
+
var CanvasHostProblemTracker = class {
|
|
692
|
+
constructor() {
|
|
693
|
+
this.hostProblemHmrGeneration = 0;
|
|
694
|
+
this.componentProblems = /* @__PURE__ */ new Map();
|
|
695
|
+
this.componentProblemHmrGenerations = /* @__PURE__ */ new Map();
|
|
696
|
+
this.watchers = /* @__PURE__ */ new Set();
|
|
697
|
+
this.hostProblemClearedWatchers = /* @__PURE__ */ new Set();
|
|
698
|
+
this.hmrGeneration = 0;
|
|
699
|
+
}
|
|
700
|
+
snapshot() {
|
|
701
|
+
const currentViteOverlay = readCurrentViteOverlay();
|
|
702
|
+
const hostProblem = currentViteOverlay ?? (this.hostProblem?.sourceKind === "vite-overlay" ? void 0 : this.hostProblem);
|
|
703
|
+
return {
|
|
704
|
+
hostProblem,
|
|
705
|
+
componentProblems: [...this.componentProblems].map(
|
|
706
|
+
([renderId, problem]) => ({ renderId, problem })
|
|
707
|
+
)
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
watch(callback) {
|
|
711
|
+
this.watchers.add(callback);
|
|
712
|
+
return () => {
|
|
713
|
+
this.watchers.delete(callback);
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
watchHostProblemCleared(callback) {
|
|
717
|
+
this.hostProblemClearedWatchers.add(callback);
|
|
718
|
+
return () => {
|
|
719
|
+
this.hostProblemClearedWatchers.delete(callback);
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
reportHostProblem(sourceKind, error, details = {}) {
|
|
723
|
+
this.hostProblem = createProblem(sourceKind, error, details);
|
|
724
|
+
this.hostProblemHmrGeneration = this.hmrGeneration;
|
|
725
|
+
this.publish();
|
|
726
|
+
}
|
|
727
|
+
reportProblemNearRender(sourceKind, error, details = {}) {
|
|
728
|
+
const problem = createProblem(sourceKind, error, details);
|
|
729
|
+
const renderId = findRenderIdForProblem(problem);
|
|
730
|
+
if (renderId) {
|
|
731
|
+
this.componentProblems.set(renderId, problem);
|
|
732
|
+
this.componentProblemHmrGenerations.set(renderId, this.hmrGeneration);
|
|
733
|
+
} else {
|
|
734
|
+
this.hostProblem = problem;
|
|
735
|
+
this.hostProblemHmrGeneration = this.hmrGeneration;
|
|
736
|
+
}
|
|
737
|
+
this.publish();
|
|
738
|
+
}
|
|
739
|
+
clearHostProblem(sourceKinds) {
|
|
740
|
+
if (!this.hostProblem) return;
|
|
741
|
+
if (sourceKinds && !sourceKinds.includes(this.hostProblem.sourceKind)) return;
|
|
742
|
+
const clearedProblem = this.hostProblem;
|
|
743
|
+
this.hostProblem = void 0;
|
|
744
|
+
this.hostProblemHmrGeneration = 0;
|
|
745
|
+
this.publish();
|
|
746
|
+
this.publishHostProblemCleared(clearedProblem);
|
|
747
|
+
}
|
|
748
|
+
reportComponentProblem(renderId, sourceKind, error, details = {}) {
|
|
749
|
+
this.componentProblems.set(
|
|
750
|
+
renderId,
|
|
751
|
+
createProblem(sourceKind, error, details)
|
|
752
|
+
);
|
|
753
|
+
this.componentProblemHmrGenerations.set(renderId, this.hmrGeneration);
|
|
754
|
+
this.publish();
|
|
755
|
+
}
|
|
756
|
+
clearComponentProblem(renderId, sourceKinds) {
|
|
757
|
+
const problem = this.componentProblems.get(renderId);
|
|
758
|
+
if (!problem) return;
|
|
759
|
+
if (sourceKinds && !sourceKinds.includes(problem.sourceKind)) return;
|
|
760
|
+
this.componentProblems.delete(renderId);
|
|
761
|
+
this.componentProblemHmrGenerations.delete(renderId);
|
|
762
|
+
this.publish();
|
|
763
|
+
}
|
|
764
|
+
hasComponentProblem(renderId) {
|
|
765
|
+
return this.componentProblems.has(renderId);
|
|
766
|
+
}
|
|
767
|
+
clearRecoveredComponentProblemsAfterRender(renderId) {
|
|
768
|
+
let changed = false;
|
|
769
|
+
const problem = this.componentProblems.get(renderId);
|
|
770
|
+
if (problem && problem.sourceKind !== "render-error-boundary" && this.hmrGeneration > (this.componentProblemHmrGenerations.get(renderId) ?? this.hmrGeneration)) {
|
|
771
|
+
this.componentProblems.delete(renderId);
|
|
772
|
+
this.componentProblemHmrGenerations.delete(renderId);
|
|
773
|
+
changed = true;
|
|
774
|
+
}
|
|
775
|
+
if (this.clearRecoveredHostProblemAfterRender(renderId)) changed = true;
|
|
776
|
+
if (changed) this.publish();
|
|
777
|
+
}
|
|
778
|
+
noteHmrUpdateStarted() {
|
|
779
|
+
this.hmrGeneration += 1;
|
|
780
|
+
}
|
|
781
|
+
dispose() {
|
|
782
|
+
this.watchers.clear();
|
|
783
|
+
this.hostProblemClearedWatchers.clear();
|
|
784
|
+
}
|
|
785
|
+
inspectCurrentProblems(options = {}) {
|
|
786
|
+
const renderIdFilter = options.renderId ?? void 0;
|
|
787
|
+
const currentRenderFailures = [];
|
|
788
|
+
for (const [renderId, failure] of this.componentProblems) {
|
|
789
|
+
if (renderIdFilter != null && renderId !== renderIdFilter) continue;
|
|
790
|
+
currentRenderFailures.push({ renderId, failure });
|
|
791
|
+
}
|
|
792
|
+
const currentHostFailure = readCurrentViteOverlay() ?? this.hostProblem;
|
|
793
|
+
return {
|
|
794
|
+
...currentHostFailure ? { currentHostFailure } : {},
|
|
795
|
+
currentRenderFailures,
|
|
796
|
+
observedAt: Date.now()
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
publish() {
|
|
800
|
+
for (const watcher of this.watchers) {
|
|
801
|
+
watcher();
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
publishHostProblemCleared(problem) {
|
|
805
|
+
for (const watcher of this.hostProblemClearedWatchers) {
|
|
806
|
+
watcher(problem);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
clearRecoveredHostProblemAfterRender(renderId) {
|
|
810
|
+
if (!this.hostProblem || !renderRecoveredHostProblemSourceKinds.includes(this.hostProblem.sourceKind)) {
|
|
811
|
+
return false;
|
|
812
|
+
}
|
|
813
|
+
if (this.hmrGeneration <= this.hostProblemHmrGeneration) return false;
|
|
814
|
+
if (this.hostProblem.sourceKind === "vite-hmr-error" && findRenderIdForProblem(this.hostProblem) !== renderId) {
|
|
815
|
+
return false;
|
|
816
|
+
}
|
|
817
|
+
const clearedProblem = this.hostProblem;
|
|
818
|
+
this.hostProblem = void 0;
|
|
819
|
+
this.hostProblemHmrGeneration = 0;
|
|
820
|
+
this.publishHostProblemCleared(clearedProblem);
|
|
821
|
+
return true;
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
function createCanvasHostProblemTracker() {
|
|
825
|
+
return new CanvasHostProblemTracker();
|
|
826
|
+
}
|
|
827
|
+
function installCanvasHostRuntimeProblemTracking(tracker) {
|
|
828
|
+
if (typeof window === "undefined") return () => {
|
|
829
|
+
};
|
|
830
|
+
const cleanupHostCapture = installHostProblemCapture(tracker);
|
|
831
|
+
const cleanupViteCapture = installViteProblemCapture(tracker);
|
|
832
|
+
const cleanupInspector = installCurrentProblemInspector(tracker);
|
|
833
|
+
return () => {
|
|
834
|
+
cleanupHostCapture();
|
|
835
|
+
cleanupViteCapture();
|
|
836
|
+
cleanupInspector();
|
|
837
|
+
tracker.dispose();
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
var renderRecoveredHostProblemSourceKinds = ["page-error", "unhandled-rejection", "console-vite-error", "vite-hmr-error"];
|
|
841
|
+
function createProblem(sourceKind, error, details = {}) {
|
|
842
|
+
return {
|
|
843
|
+
sourceKind,
|
|
844
|
+
message: error instanceof Error ? error.message : String(error),
|
|
845
|
+
stack: error instanceof Error ? error.stack : void 0,
|
|
846
|
+
frameUrl: typeof window === "undefined" ? void 0 : window.location.href,
|
|
847
|
+
timestamp: Date.now(),
|
|
848
|
+
...details
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
function findRenderIdForProblem(problem) {
|
|
852
|
+
if (typeof document === "undefined") return void 0;
|
|
853
|
+
const haystack = [
|
|
854
|
+
problem.message,
|
|
855
|
+
problem.stack,
|
|
856
|
+
problem.componentStack,
|
|
857
|
+
problem.filename
|
|
858
|
+
].filter(Boolean).join("\n");
|
|
859
|
+
if (!haystack) return void 0;
|
|
860
|
+
for (const slot of document.querySelectorAll("[data-render-id]")) {
|
|
861
|
+
const renderId = slot.getAttribute("data-render-id");
|
|
862
|
+
if (!renderId) continue;
|
|
863
|
+
const sourceFiles = getObservedSourceFiles(slot);
|
|
864
|
+
if (sourceFiles.some((sourceFile) => problemTextMentionsSource(haystack, sourceFile))) {
|
|
865
|
+
return renderId;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
return void 0;
|
|
869
|
+
}
|
|
870
|
+
var sourceAnnotationSelector = "[data-tempo-source-file], [data-tempo-source-loc], [data-tempo-filepath], [data-tempo-html-filepath]";
|
|
871
|
+
function getObservedSourceFiles(slot) {
|
|
872
|
+
const sourceFiles = /* @__PURE__ */ new Set();
|
|
873
|
+
for (const element of slot.querySelectorAll(sourceAnnotationSelector)) {
|
|
874
|
+
for (const attribute of [
|
|
875
|
+
"data-tempo-source-file",
|
|
876
|
+
"data-tempo-filepath",
|
|
877
|
+
"data-tempo-html-filepath"
|
|
878
|
+
]) {
|
|
879
|
+
const value = element.getAttribute(attribute);
|
|
880
|
+
if (value) sourceFiles.add(value);
|
|
881
|
+
}
|
|
882
|
+
const sourceLoc = element.getAttribute("data-tempo-source-loc");
|
|
883
|
+
const sourceFile = sourceLoc?.split(":")[0];
|
|
884
|
+
if (sourceFile) sourceFiles.add(sourceFile);
|
|
885
|
+
}
|
|
886
|
+
return [...sourceFiles];
|
|
887
|
+
}
|
|
888
|
+
function problemTextMentionsSource(text, sourceFile) {
|
|
889
|
+
const normalizedSource = sourceFile.replace(/\\/g, "/");
|
|
890
|
+
const basename = normalizedSource.split("/").pop() ?? normalizedSource;
|
|
891
|
+
return text.includes(normalizedSource) || basename !== "" && text.includes(basename);
|
|
892
|
+
}
|
|
893
|
+
function installHostProblemCapture(tracker) {
|
|
894
|
+
const onError = (event) => {
|
|
895
|
+
if (event.target instanceof Element) return;
|
|
896
|
+
tracker.reportProblemNearRender("page-error", event.error ?? event.message, {
|
|
897
|
+
filename: event.filename || void 0,
|
|
898
|
+
line: typeof event.lineno === "number" ? event.lineno : void 0,
|
|
899
|
+
column: typeof event.colno === "number" ? event.colno : void 0
|
|
900
|
+
});
|
|
901
|
+
};
|
|
902
|
+
const onUnhandledRejection = (event) => {
|
|
903
|
+
tracker.reportProblemNearRender("unhandled-rejection", event.reason);
|
|
904
|
+
};
|
|
905
|
+
const resourceTags = /* @__PURE__ */ new Set([
|
|
906
|
+
"IMG",
|
|
907
|
+
"SCRIPT",
|
|
908
|
+
"LINK",
|
|
909
|
+
"AUDIO",
|
|
910
|
+
"VIDEO",
|
|
911
|
+
"SOURCE"
|
|
912
|
+
]);
|
|
913
|
+
const onResourceError = (event) => {
|
|
914
|
+
const target = event.target;
|
|
915
|
+
if (!(target instanceof Element) || !resourceTags.has(target.tagName)) {
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
const url = target.getAttribute("src") || target.getAttribute("href") || "";
|
|
919
|
+
const message = "Failed to load " + target.tagName.toLowerCase() + (url ? ": " + url : "");
|
|
920
|
+
const renderId = target.closest("[data-render-id]")?.getAttribute("data-render-id");
|
|
921
|
+
if (renderId) {
|
|
922
|
+
tracker.reportComponentProblem(renderId, "resource-load", message);
|
|
923
|
+
} else {
|
|
924
|
+
tracker.reportHostProblem("resource-load", message, {
|
|
925
|
+
filename: url || void 0
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
const onFontLoadingError = (event) => {
|
|
930
|
+
const faces = event.fontfaces ?? [];
|
|
931
|
+
const families = faces.map((face) => face.family).filter(Boolean).join(", ");
|
|
932
|
+
tracker.reportHostProblem(
|
|
933
|
+
"resource-load",
|
|
934
|
+
"Failed to load font" + (families ? ": " + families : "")
|
|
935
|
+
);
|
|
936
|
+
};
|
|
937
|
+
const fontFaceSet = typeof document.fonts?.addEventListener === "function" ? document.fonts : void 0;
|
|
938
|
+
window.addEventListener("error", onError);
|
|
939
|
+
window.addEventListener("unhandledrejection", onUnhandledRejection);
|
|
940
|
+
window.addEventListener("error", onResourceError, { capture: true });
|
|
941
|
+
document.addEventListener("error", onResourceError, { capture: true });
|
|
942
|
+
fontFaceSet?.addEventListener("loadingerror", onFontLoadingError);
|
|
943
|
+
return () => {
|
|
944
|
+
window.removeEventListener("error", onError);
|
|
945
|
+
window.removeEventListener("unhandledrejection", onUnhandledRejection);
|
|
946
|
+
window.removeEventListener("error", onResourceError, { capture: true });
|
|
947
|
+
document.removeEventListener("error", onResourceError, { capture: true });
|
|
948
|
+
fontFaceSet?.removeEventListener("loadingerror", onFontLoadingError);
|
|
949
|
+
};
|
|
950
|
+
}
|
|
951
|
+
function installViteProblemCapture(tracker) {
|
|
952
|
+
const reconcileViteOverlay = () => {
|
|
953
|
+
const problem = readCurrentViteOverlay();
|
|
954
|
+
if (problem) {
|
|
955
|
+
tracker.reportHostProblem("vite-overlay", problem.message, {
|
|
956
|
+
stack: problem.stack,
|
|
957
|
+
filename: problem.filename
|
|
958
|
+
});
|
|
959
|
+
} else {
|
|
960
|
+
tracker.clearHostProblem(["vite-overlay"]);
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
const observer = new MutationObserver(reconcileViteOverlay);
|
|
964
|
+
if (document.body) {
|
|
965
|
+
observer.observe(document.body, { childList: true });
|
|
966
|
+
reconcileViteOverlay();
|
|
967
|
+
void Promise.resolve().then(reconcileViteOverlay);
|
|
968
|
+
}
|
|
969
|
+
const viteHmrFailedModules = /* @__PURE__ */ new Map();
|
|
970
|
+
const latestViteHmrFailure = () => {
|
|
971
|
+
let latest;
|
|
972
|
+
for (const problem of viteHmrFailedModules.values()) {
|
|
973
|
+
if (!latest || problem.timestamp >= latest.timestamp) latest = problem;
|
|
974
|
+
}
|
|
975
|
+
return latest;
|
|
976
|
+
};
|
|
977
|
+
const reconcileViteHmrHostProblem = () => {
|
|
978
|
+
const latest = latestViteHmrFailure();
|
|
979
|
+
if (latest) {
|
|
980
|
+
tracker.reportHostProblem("vite-hmr-error", latest.message, latest);
|
|
981
|
+
} else {
|
|
982
|
+
tracker.clearHostProblem(["vite-hmr-error"]);
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
const failedReloadPattern = /^Failed to reload (.+?)\. This could be due to/;
|
|
986
|
+
const pathlessViteErrorKey = "__tempo:pathless-vite-error";
|
|
987
|
+
let viteHmrCycleActive = false;
|
|
988
|
+
let cycleFailedPaths = /* @__PURE__ */ new Map();
|
|
989
|
+
let lastCycleViteErrorDetail;
|
|
990
|
+
const onViteBeforeUpdate = () => {
|
|
991
|
+
viteHmrCycleActive = true;
|
|
992
|
+
cycleFailedPaths = /* @__PURE__ */ new Map();
|
|
993
|
+
lastCycleViteErrorDetail = void 0;
|
|
994
|
+
tracker.noteHmrUpdateStarted();
|
|
995
|
+
};
|
|
996
|
+
const onViteAfterUpdate = (payload) => {
|
|
997
|
+
const updatedPaths = readUpdatePaths(payload);
|
|
998
|
+
let shouldReconcile = false;
|
|
999
|
+
if (updatedPaths.length > 0 && !cycleFailedPaths.has(pathlessViteErrorKey)) {
|
|
1000
|
+
shouldReconcile = viteHmrFailedModules.delete(pathlessViteErrorKey);
|
|
1001
|
+
}
|
|
1002
|
+
for (const [path, problem] of cycleFailedPaths) {
|
|
1003
|
+
viteHmrFailedModules.set(path, problem);
|
|
1004
|
+
shouldReconcile = true;
|
|
1005
|
+
}
|
|
1006
|
+
viteHmrCycleActive = false;
|
|
1007
|
+
cycleFailedPaths = /* @__PURE__ */ new Map();
|
|
1008
|
+
if (shouldReconcile) reconcileViteHmrHostProblem();
|
|
1009
|
+
};
|
|
1010
|
+
const onViteError = (payload) => {
|
|
1011
|
+
const error = readViteError(payload);
|
|
1012
|
+
if (!error) return;
|
|
1013
|
+
lastCycleViteErrorDetail = error;
|
|
1014
|
+
const path = error.filename ?? pathlessViteErrorKey;
|
|
1015
|
+
const problem = createProblem("vite-hmr-error", error.message, {
|
|
1016
|
+
stack: error.stack,
|
|
1017
|
+
filename: error.filename
|
|
1018
|
+
});
|
|
1019
|
+
if (viteHmrCycleActive) {
|
|
1020
|
+
cycleFailedPaths.set(path, problem);
|
|
1021
|
+
} else {
|
|
1022
|
+
viteHmrFailedModules.set(path, problem);
|
|
1023
|
+
}
|
|
1024
|
+
reconcileViteHmrHostProblem();
|
|
1025
|
+
};
|
|
1026
|
+
let hotEventsCancelled = false;
|
|
1027
|
+
let subscribedHot;
|
|
1028
|
+
const subscribeHotEvents = (hot2) => {
|
|
1029
|
+
subscribedHot = hot2;
|
|
1030
|
+
hot2.on?.("vite:beforeUpdate", onViteBeforeUpdate);
|
|
1031
|
+
hot2.on?.("vite:afterUpdate", onViteAfterUpdate);
|
|
1032
|
+
hot2.on?.("vite:error", onViteError);
|
|
1033
|
+
};
|
|
1034
|
+
const hot = readViteHot();
|
|
1035
|
+
if (hot?.on) {
|
|
1036
|
+
subscribeHotEvents(hot);
|
|
1037
|
+
} else {
|
|
1038
|
+
void import(
|
|
1039
|
+
/* @vite-ignore */
|
|
1040
|
+
/* webpackIgnore: true */
|
|
1041
|
+
/* turbopackIgnore: true */
|
|
1042
|
+
"/@vite/client"
|
|
1043
|
+
).then((client) => {
|
|
1044
|
+
const createHotContext = client.createHotContext;
|
|
1045
|
+
const context = createHotContext?.("/__tempo-canvas-host__");
|
|
1046
|
+
if (!context || hotEventsCancelled) return;
|
|
1047
|
+
subscribeHotEvents(context);
|
|
1048
|
+
}).catch(() => {
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
const stopClearedWatch = tracker.watchHostProblemCleared((problem) => {
|
|
1052
|
+
if (problem.sourceKind !== "vite-hmr-error") return;
|
|
1053
|
+
const key = problem.filename ?? pathlessViteErrorKey;
|
|
1054
|
+
if (!viteHmrFailedModules.has(key)) return;
|
|
1055
|
+
viteHmrFailedModules.delete(key);
|
|
1056
|
+
void Promise.resolve().then(reconcileViteHmrHostProblem);
|
|
1057
|
+
});
|
|
1058
|
+
const originalConsoleError = console.error;
|
|
1059
|
+
const patchedConsoleError = (...args) => {
|
|
1060
|
+
originalConsoleError(...args);
|
|
1061
|
+
const error = readViteConsoleError(args[0], args[1]);
|
|
1062
|
+
if (!error) return;
|
|
1063
|
+
const failedReload = failedReloadPattern.exec(error.message);
|
|
1064
|
+
if (failedReload) {
|
|
1065
|
+
const path = failedReload[1];
|
|
1066
|
+
const detail = lastCycleViteErrorDetail;
|
|
1067
|
+
const problem = createProblem(
|
|
1068
|
+
"vite-hmr-error",
|
|
1069
|
+
detail?.message ?? "Failed to reload " + path,
|
|
1070
|
+
{
|
|
1071
|
+
stack: detail?.stack ?? error.stack,
|
|
1072
|
+
filename: detail?.filename ?? path
|
|
1073
|
+
}
|
|
1074
|
+
);
|
|
1075
|
+
if (detail) {
|
|
1076
|
+
cycleFailedPaths.set(path, problem);
|
|
1077
|
+
viteHmrFailedModules.set(path, problem);
|
|
1078
|
+
reconcileViteHmrHostProblem();
|
|
1079
|
+
} else {
|
|
1080
|
+
void verifyModuleStillExists(path).then((exists) => {
|
|
1081
|
+
if (exists) viteHmrFailedModules.set(path, problem);
|
|
1082
|
+
else viteHmrFailedModules.delete(path);
|
|
1083
|
+
reconcileViteHmrHostProblem();
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
if (viteHmrCycleActive) {
|
|
1089
|
+
lastCycleViteErrorDetail = error;
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
tracker.reportProblemNearRender("console-vite-error", error.message, {
|
|
1093
|
+
stack: error.stack,
|
|
1094
|
+
filename: error.filename
|
|
1095
|
+
});
|
|
1096
|
+
};
|
|
1097
|
+
console.error = patchedConsoleError;
|
|
1098
|
+
return () => {
|
|
1099
|
+
observer.disconnect();
|
|
1100
|
+
stopClearedWatch();
|
|
1101
|
+
hotEventsCancelled = true;
|
|
1102
|
+
subscribedHot?.off?.("vite:beforeUpdate", onViteBeforeUpdate);
|
|
1103
|
+
subscribedHot?.off?.("vite:afterUpdate", onViteAfterUpdate);
|
|
1104
|
+
subscribedHot?.off?.("vite:error", onViteError);
|
|
1105
|
+
if (console.error === patchedConsoleError) {
|
|
1106
|
+
console.error = originalConsoleError;
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
function installCurrentProblemInspector(tracker) {
|
|
1111
|
+
const maybeWindow = window;
|
|
1112
|
+
const previous = maybeWindow.__tempoErrorTrackingInspectCurrentProblems;
|
|
1113
|
+
const inspect = (options = {}) => mergeCurrentProblemSnapshots(
|
|
1114
|
+
tracker.inspectCurrentProblems(options),
|
|
1115
|
+
previous?.(options) ?? null
|
|
1116
|
+
);
|
|
1117
|
+
maybeWindow.__tempoErrorTrackingInspectCurrentProblems = inspect;
|
|
1118
|
+
return () => {
|
|
1119
|
+
if (maybeWindow.__tempoErrorTrackingInspectCurrentProblems === inspect) {
|
|
1120
|
+
maybeWindow.__tempoErrorTrackingInspectCurrentProblems = previous;
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
function readViteHot() {
|
|
1125
|
+
const explicitHot = window.__tempoCanvasHostViteHot;
|
|
1126
|
+
if (explicitHot) return explicitHot;
|
|
1127
|
+
try {
|
|
1128
|
+
return eval("import.meta && import.meta.hot");
|
|
1129
|
+
} catch {
|
|
1130
|
+
return void 0;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
function readCurrentViteOverlay() {
|
|
1134
|
+
if (typeof document === "undefined") return void 0;
|
|
1135
|
+
const overlay = document.querySelector("vite-error-overlay");
|
|
1136
|
+
if (!overlay) return void 0;
|
|
1137
|
+
const { message, stack, filename } = readViteOverlayContent(overlay);
|
|
1138
|
+
return createProblem("vite-overlay", message, { stack, filename });
|
|
1139
|
+
}
|
|
1140
|
+
function readViteOverlayContent(overlay) {
|
|
1141
|
+
const root = overlay.shadowRoot ?? overlay;
|
|
1142
|
+
const text = (selector) => {
|
|
1143
|
+
const value = root.querySelector(selector)?.textContent?.trim();
|
|
1144
|
+
return value ? value : void 0;
|
|
1145
|
+
};
|
|
1146
|
+
const message = text(".message-body") ?? text(".message") ?? overlay.textContent?.trim() ?? "Unknown Vite error";
|
|
1147
|
+
const stack = [text(".stack"), text(".plugin"), text(".frame")].filter(Boolean).join("\n");
|
|
1148
|
+
return {
|
|
1149
|
+
message,
|
|
1150
|
+
stack: stack || void 0,
|
|
1151
|
+
filename: text(".file")
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
function readViteError(value) {
|
|
1155
|
+
if (value instanceof Error) {
|
|
1156
|
+
return {
|
|
1157
|
+
message: value.message,
|
|
1158
|
+
stack: value.stack,
|
|
1159
|
+
filename: typeof value.id === "string" ? value.id : void 0
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
if (typeof value === "string") return { message: value };
|
|
1163
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
1164
|
+
const record = value;
|
|
1165
|
+
const nested = typeof record.err === "object" && record.err !== null ? record.err : record;
|
|
1166
|
+
const message = typeof nested.message === "string" ? nested.message : typeof record.message === "string" ? record.message : void 0;
|
|
1167
|
+
if (!message) return void 0;
|
|
1168
|
+
return {
|
|
1169
|
+
message,
|
|
1170
|
+
stack: typeof nested.stack === "string" ? nested.stack : typeof record.stack === "string" ? record.stack : void 0,
|
|
1171
|
+
filename: typeof nested.filename === "string" ? nested.filename : typeof nested.file === "string" ? nested.file : typeof nested.id === "string" ? nested.id : typeof record.id === "string" ? record.id : void 0
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
1174
|
+
function readViteConsoleError(first, second) {
|
|
1175
|
+
if (first === "[vite]") return readViteError(second);
|
|
1176
|
+
if (typeof first !== "string" || !first.startsWith("[vite]")) {
|
|
1177
|
+
return void 0;
|
|
1178
|
+
}
|
|
1179
|
+
const detail = readViteError(second);
|
|
1180
|
+
const message = first.replace(/^\[vite\]\s*/, "") || detail?.message;
|
|
1181
|
+
return message ? {
|
|
1182
|
+
message,
|
|
1183
|
+
stack: detail?.stack,
|
|
1184
|
+
filename: detail?.filename
|
|
1185
|
+
} : void 0;
|
|
1186
|
+
}
|
|
1187
|
+
function readUpdatePaths(payload) {
|
|
1188
|
+
const updates = typeof payload === "object" && payload !== null && Array.isArray(payload.updates) ? payload.updates : [];
|
|
1189
|
+
const paths = /* @__PURE__ */ new Set();
|
|
1190
|
+
const collectPath = (value) => {
|
|
1191
|
+
if (typeof value === "string") paths.add(value);
|
|
1192
|
+
};
|
|
1193
|
+
for (const update of updates) {
|
|
1194
|
+
collectPath(update.path);
|
|
1195
|
+
collectPath(update.acceptedPath);
|
|
1196
|
+
collectPath(update.id);
|
|
1197
|
+
}
|
|
1198
|
+
return [...paths];
|
|
1199
|
+
}
|
|
1200
|
+
async function verifyModuleStillExists(path) {
|
|
1201
|
+
if (typeof fetch !== "function") return true;
|
|
1202
|
+
try {
|
|
1203
|
+
const response = await fetch(path, { cache: "no-store" });
|
|
1204
|
+
const contentType = response.headers.get("content-type") || "";
|
|
1205
|
+
return !contentType.includes("text/html");
|
|
1206
|
+
} catch {
|
|
1207
|
+
return true;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
function mergeCurrentProblemSnapshots(primary, fallback) {
|
|
1211
|
+
if (!fallback) return primary;
|
|
1212
|
+
const currentRenderFailures = [...primary.currentRenderFailures];
|
|
1213
|
+
const seen = new Set(
|
|
1214
|
+
currentRenderFailures.map(
|
|
1215
|
+
(entry) => `${entry.renderId ?? ""}:${entry.failure.sourceKind}:${entry.failure.message}`
|
|
1216
|
+
)
|
|
1217
|
+
);
|
|
1218
|
+
for (const entry of fallback.currentRenderFailures) {
|
|
1219
|
+
const key = `${entry.renderId ?? ""}:${entry.failure.sourceKind}:${entry.failure.message}`;
|
|
1220
|
+
if (seen.has(key)) continue;
|
|
1221
|
+
seen.add(key);
|
|
1222
|
+
currentRenderFailures.push(entry);
|
|
1223
|
+
}
|
|
1224
|
+
return {
|
|
1225
|
+
currentHostFailure: primary.currentHostFailure ?? fallback.currentHostFailure,
|
|
1226
|
+
currentRenderFailures,
|
|
1227
|
+
observedAt: Math.max(primary.observedAt, fallback.observedAt)
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
// canvas/use-canvas-host-postmessage.ts
|
|
1232
|
+
function postToMessageSource(source, response) {
|
|
1233
|
+
if (source && "postMessage" in source && source !== window) {
|
|
1234
|
+
source.postMessage(response, "*");
|
|
1235
|
+
} else {
|
|
1236
|
+
window.postMessage(response, "*");
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
function useCanvasHostPostMessage() {
|
|
1240
|
+
const [renderEntriesById, setRenderEntriesById] = useState(
|
|
1241
|
+
() => /* @__PURE__ */ new Map()
|
|
1242
|
+
);
|
|
1243
|
+
const [watchRequestsById, setWatchRequestsById] = useState(
|
|
1244
|
+
() => /* @__PURE__ */ new Map()
|
|
1245
|
+
);
|
|
1246
|
+
const [renderCommitVersionById, setRenderCommitVersionById] = useState(
|
|
1247
|
+
() => /* @__PURE__ */ new Map()
|
|
1248
|
+
);
|
|
1249
|
+
const renderEntriesRef = useRef(renderEntriesById);
|
|
1250
|
+
const watchRequestsRef = useRef(watchRequestsById);
|
|
1251
|
+
const maxCachedRef = useRef(20);
|
|
1252
|
+
const renderedRenderIdsRef = useRef(/* @__PURE__ */ new Set());
|
|
1253
|
+
const pendingRenderAcksRef = useRef(/* @__PURE__ */ new Map());
|
|
1254
|
+
const watchesRef = useRef(/* @__PURE__ */ new Map());
|
|
1255
|
+
const problemWatchersRef = useRef(/* @__PURE__ */ new Map());
|
|
1256
|
+
const problemTrackerRef = useRef(createCanvasHostProblemTracker());
|
|
1257
|
+
const renderCommitTimesRef = useRef(/* @__PURE__ */ new Map());
|
|
1258
|
+
const sourceAnnotatedCommitTimesRef = useRef(/* @__PURE__ */ new Map());
|
|
1259
|
+
const buildProblemSnapshot = useCallback2(
|
|
1260
|
+
() => problemTrackerRef.current.snapshot(),
|
|
1261
|
+
[]
|
|
1262
|
+
);
|
|
1263
|
+
const recordSourceAnnotatedCommit = useCallback2(
|
|
1264
|
+
(renderId, observedAt = Date.now()) => {
|
|
1265
|
+
if (renderSlotHasSourceAnnotations(renderId)) {
|
|
1266
|
+
sourceAnnotatedCommitTimesRef.current.set(renderId, observedAt);
|
|
1267
|
+
}
|
|
1268
|
+
},
|
|
1269
|
+
[]
|
|
1270
|
+
);
|
|
1271
|
+
const publishProblemSnapshot = useCallback2(() => {
|
|
1272
|
+
const payload = buildProblemSnapshot();
|
|
1273
|
+
for (const watcher of problemWatchersRef.current.values()) {
|
|
1274
|
+
postToMessageSource(watcher.source, {
|
|
1275
|
+
type: "render-pool:problem-snapshot",
|
|
1276
|
+
requestId: watcher.requestId,
|
|
1277
|
+
watchId: watcher.watchId,
|
|
1278
|
+
payload
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
}, [buildProblemSnapshot]);
|
|
1282
|
+
const setEntries = useCallback2(
|
|
1283
|
+
(update) => {
|
|
1284
|
+
setRenderEntriesById((entries) => {
|
|
1285
|
+
const next = update(entries);
|
|
1286
|
+
renderEntriesRef.current = next;
|
|
1287
|
+
for (const renderId of [...renderedRenderIdsRef.current]) {
|
|
1288
|
+
if (!next.has(renderId)) {
|
|
1289
|
+
renderedRenderIdsRef.current.delete(renderId);
|
|
1290
|
+
renderCommitTimesRef.current.delete(renderId);
|
|
1291
|
+
sourceAnnotatedCommitTimesRef.current.delete(renderId);
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
return next;
|
|
1295
|
+
});
|
|
1296
|
+
},
|
|
1297
|
+
[]
|
|
1298
|
+
);
|
|
1299
|
+
const waitForRender = useCallback2(
|
|
1300
|
+
(request) => {
|
|
1301
|
+
const current = renderEntriesRef.current.get(request.renderId);
|
|
1302
|
+
const alreadyRendered = current?.status === "active" && renderedRenderIdsRef.current.has(request.renderId) && renderRequestMatchesEntry(current, request);
|
|
1303
|
+
setEntries((entries) => acquireRender(entries, request));
|
|
1304
|
+
if (alreadyRendered) {
|
|
1305
|
+
return Promise.resolve();
|
|
1306
|
+
}
|
|
1307
|
+
return new Promise((resolve, reject) => {
|
|
1308
|
+
const pendingAcks = pendingRenderAcksRef.current.get(request.renderId) ?? [];
|
|
1309
|
+
pendingAcks.push({ resolve, reject });
|
|
1310
|
+
pendingRenderAcksRef.current.set(request.renderId, pendingAcks);
|
|
1311
|
+
});
|
|
1312
|
+
},
|
|
1313
|
+
[setEntries]
|
|
1314
|
+
);
|
|
1315
|
+
const releaseRenderLease = useCallback2(
|
|
1316
|
+
(renderId) => {
|
|
1317
|
+
setEntries(
|
|
1318
|
+
(entries) => releaseRender(entries, renderId, maxCachedRef.current)
|
|
1319
|
+
);
|
|
1320
|
+
},
|
|
1321
|
+
[setEntries]
|
|
1322
|
+
);
|
|
1323
|
+
const stopRuntimeWatch = useCallback2(async (watchId) => {
|
|
1324
|
+
const existingWatch = watchesRef.current.get(watchId);
|
|
1325
|
+
if (!existingWatch) return;
|
|
1326
|
+
watchesRef.current.delete(watchId);
|
|
1327
|
+
await existingWatch.watch.stop();
|
|
1328
|
+
}, []);
|
|
1329
|
+
const removeWatchRequest = useCallback2(
|
|
1330
|
+
async (watchId) => {
|
|
1331
|
+
const existingRequest = watchRequestsRef.current.get(watchId);
|
|
1332
|
+
try {
|
|
1333
|
+
await stopRuntimeWatch(watchId);
|
|
1334
|
+
} finally {
|
|
1335
|
+
if (!existingRequest) return;
|
|
1336
|
+
setWatchRequestsById((requests) => {
|
|
1337
|
+
const next = new Map(requests);
|
|
1338
|
+
next.delete(watchId);
|
|
1339
|
+
watchRequestsRef.current = next;
|
|
1340
|
+
return next;
|
|
1341
|
+
});
|
|
1342
|
+
releaseRenderLease(existingRequest.request.renderId);
|
|
1343
|
+
}
|
|
1344
|
+
},
|
|
1345
|
+
[releaseRenderLease, stopRuntimeWatch]
|
|
1346
|
+
);
|
|
1347
|
+
const buildState = useCallback2(
|
|
1348
|
+
() => buildRenderStatePayload(renderEntriesRef.current, maxCachedRef.current),
|
|
1349
|
+
[]
|
|
1350
|
+
);
|
|
1351
|
+
const buildHealthSnapshot = useCallback2((renderId) => {
|
|
1352
|
+
const slot = renderId ? document.querySelector(buildRenderContentSelector(renderId)) : null;
|
|
1353
|
+
const observedSourceFiles = getObservedSourceFiles2(slot);
|
|
1354
|
+
return {
|
|
1355
|
+
alive: true,
|
|
1356
|
+
reactConnected: isReactConnected() || renderCommitTimesRef.current.size > 0 || renderEntriesRef.current.size > 0,
|
|
1357
|
+
documentReadyState: document.readyState,
|
|
1358
|
+
hasViteOverlayElement: document.querySelector("vite-error-overlay") !== null,
|
|
1359
|
+
lastHostRenderCommitAt: latestTimestamp(renderCommitTimesRef.current),
|
|
1360
|
+
lastClaimRenderCommitAt: renderCommitTimesRef.current.get(renderId) ?? null,
|
|
1361
|
+
lastHostSourceAnnotatedCommitAt: latestTimestamp(
|
|
1362
|
+
sourceAnnotatedCommitTimesRef.current
|
|
1363
|
+
),
|
|
1364
|
+
lastClaimSourceAnnotatedCommitAt: sourceAnnotatedCommitTimesRef.current.get(renderId) ?? null,
|
|
1365
|
+
renderSlotExists: slot !== null,
|
|
1366
|
+
renderSlotHasSourceAnnotatedContent: observedSourceFiles.length > 0,
|
|
1367
|
+
renderSlotObservedSourceFiles: observedSourceFiles,
|
|
1368
|
+
claimErrorBoundaryTripped: problemTrackerRef.current.hasComponentProblem(renderId),
|
|
1369
|
+
observedAt: Date.now()
|
|
1370
|
+
};
|
|
1371
|
+
}, []);
|
|
1372
|
+
const markStoryboardRendered = useCallback2(
|
|
1373
|
+
(storyboardId) => {
|
|
1374
|
+
const committedAt = Date.now();
|
|
1375
|
+
renderedRenderIdsRef.current.add(storyboardId);
|
|
1376
|
+
renderCommitTimesRef.current.set(storyboardId, committedAt);
|
|
1377
|
+
recordSourceAnnotatedCommit(storyboardId, committedAt);
|
|
1378
|
+
setRenderCommitVersionById((versions) => {
|
|
1379
|
+
const next = new Map(versions);
|
|
1380
|
+
next.set(storyboardId, (next.get(storyboardId) ?? 0) + 1);
|
|
1381
|
+
return next;
|
|
1382
|
+
});
|
|
1383
|
+
problemTrackerRef.current.clearRecoveredComponentProblemsAfterRender(
|
|
1384
|
+
storyboardId
|
|
1385
|
+
);
|
|
1386
|
+
const pendingAcks = pendingRenderAcksRef.current.get(storyboardId);
|
|
1387
|
+
if (!pendingAcks) return;
|
|
1388
|
+
pendingRenderAcksRef.current.delete(storyboardId);
|
|
1389
|
+
for (const ack of pendingAcks) {
|
|
1390
|
+
ack.resolve();
|
|
1391
|
+
}
|
|
1392
|
+
},
|
|
1393
|
+
[recordSourceAnnotatedCommit]
|
|
1394
|
+
);
|
|
1395
|
+
const reportStoryboardError = useCallback2(
|
|
1396
|
+
(storyboardId, error) => {
|
|
1397
|
+
renderedRenderIdsRef.current.delete(storyboardId);
|
|
1398
|
+
problemTrackerRef.current.reportComponentProblem(
|
|
1399
|
+
storyboardId,
|
|
1400
|
+
"render-error-boundary",
|
|
1401
|
+
error.message,
|
|
1402
|
+
{
|
|
1403
|
+
stack: error.stack,
|
|
1404
|
+
componentStack: error.componentStack
|
|
1405
|
+
}
|
|
1406
|
+
);
|
|
1407
|
+
const pendingAcks = pendingRenderAcksRef.current.get(storyboardId);
|
|
1408
|
+
if (pendingAcks) {
|
|
1409
|
+
pendingRenderAcksRef.current.delete(storyboardId);
|
|
1410
|
+
const renderError = new Error(error.message);
|
|
1411
|
+
for (const ack of pendingAcks) {
|
|
1412
|
+
ack.reject(renderError);
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
},
|
|
1416
|
+
[]
|
|
1417
|
+
);
|
|
1418
|
+
const clearStoryboardError = useCallback2(
|
|
1419
|
+
(storyboardId) => {
|
|
1420
|
+
problemTrackerRef.current.clearComponentProblem(storyboardId, [
|
|
1421
|
+
"render-error-boundary"
|
|
1422
|
+
]);
|
|
1423
|
+
},
|
|
1424
|
+
[]
|
|
1425
|
+
);
|
|
1426
|
+
useEffect(() => {
|
|
1427
|
+
if (typeof window === "undefined") return;
|
|
1428
|
+
let cancelled = false;
|
|
1429
|
+
const activeWatchIds = new Set(watchRequestsById.keys());
|
|
1430
|
+
for (const watchId of watchesRef.current.keys()) {
|
|
1431
|
+
if (!activeWatchIds.has(watchId)) {
|
|
1432
|
+
void stopRuntimeWatch(watchId);
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
for (const request of watchRequestsById.values()) {
|
|
1436
|
+
const renderEntry = renderEntriesById.get(request.request.renderId);
|
|
1437
|
+
const renderReady = renderEntry?.status === "active" && renderedRenderIdsRef.current.has(request.request.renderId) && renderRequestMatchesEntry(renderEntry, request.request);
|
|
1438
|
+
if (!renderReady) continue;
|
|
1439
|
+
const existing = watchesRef.current.get(request.watchId);
|
|
1440
|
+
if (existing?.bindingKey === request.bindingKey) continue;
|
|
1441
|
+
void (async () => {
|
|
1442
|
+
if (existing) {
|
|
1443
|
+
await stopRuntimeWatch(request.watchId);
|
|
1444
|
+
}
|
|
1445
|
+
if (cancelled) return;
|
|
1446
|
+
const onUpdate = (capture) => {
|
|
1447
|
+
recordSourceAnnotatedCommit(request.request.renderId);
|
|
1448
|
+
postToMessageSource(request.source, {
|
|
1449
|
+
type: "render-pool:watch-update",
|
|
1450
|
+
requestId: request.requestId,
|
|
1451
|
+
watchId: request.watchId,
|
|
1452
|
+
command: request.commandType,
|
|
1453
|
+
payload: { capture }
|
|
1454
|
+
});
|
|
1455
|
+
};
|
|
1456
|
+
const onError = (error) => {
|
|
1457
|
+
postToMessageSource(request.source, {
|
|
1458
|
+
type: "render-pool:error",
|
|
1459
|
+
requestId: request.requestId,
|
|
1460
|
+
watchId: request.watchId,
|
|
1461
|
+
command: request.commandType,
|
|
1462
|
+
error: error.message
|
|
1463
|
+
});
|
|
1464
|
+
};
|
|
1465
|
+
const common = {
|
|
1466
|
+
onUpdate,
|
|
1467
|
+
onError,
|
|
1468
|
+
debounceDelay: readOptionalNumber(request.payload, "debounceDelay"),
|
|
1469
|
+
maxWait: readOptionalNumber(request.payload, "maxWait"),
|
|
1470
|
+
timeout: readOptionalNumber(request.payload, "timeout")
|
|
1471
|
+
};
|
|
1472
|
+
const watch = request.commandType === "render-pool:watch-html" ? await watchStoryboardHtml(request.request.renderId, common) : await watchStoryboardCombined(request.request.renderId, {
|
|
1473
|
+
...common,
|
|
1474
|
+
fiberSelector: typeof request.payload.fiberSelector === "string" ? request.payload.fiberSelector : void 0,
|
|
1475
|
+
fiberTags: Array.isArray(request.payload.fiberTags) ? request.payload.fiberTags : void 0,
|
|
1476
|
+
knownSourceVersion: typeof request.payload.knownSourceVersion === "object" && request.payload.knownSourceVersion !== null ? request.payload.knownSourceVersion : void 0
|
|
1477
|
+
});
|
|
1478
|
+
if (cancelled || !watchRequestsRef.current.has(request.watchId)) {
|
|
1479
|
+
await watch.stop();
|
|
1480
|
+
return;
|
|
1481
|
+
}
|
|
1482
|
+
watchesRef.current.set(request.watchId, {
|
|
1483
|
+
renderId: request.request.renderId,
|
|
1484
|
+
bindingKey: request.bindingKey,
|
|
1485
|
+
watch
|
|
1486
|
+
});
|
|
1487
|
+
if (request.paused) {
|
|
1488
|
+
if (watch.setPaused) watch.setPaused(true);
|
|
1489
|
+
else watch.pause?.();
|
|
1490
|
+
}
|
|
1491
|
+
})().catch((caught) => {
|
|
1492
|
+
postToMessageSource(request.source, {
|
|
1493
|
+
type: "render-pool:error",
|
|
1494
|
+
requestId: request.requestId,
|
|
1495
|
+
watchId: request.watchId,
|
|
1496
|
+
command: request.commandType,
|
|
1497
|
+
error: caught instanceof Error ? caught.message : String(caught)
|
|
1498
|
+
});
|
|
1499
|
+
});
|
|
1500
|
+
}
|
|
1501
|
+
return () => {
|
|
1502
|
+
cancelled = true;
|
|
1503
|
+
};
|
|
1504
|
+
}, [
|
|
1505
|
+
recordSourceAnnotatedCommit,
|
|
1506
|
+
renderCommitVersionById,
|
|
1507
|
+
renderEntriesById,
|
|
1508
|
+
stopRuntimeWatch,
|
|
1509
|
+
watchRequestsById
|
|
1510
|
+
]);
|
|
1511
|
+
useEffect(() => {
|
|
1512
|
+
if (typeof window === "undefined") return;
|
|
1513
|
+
const withRenderLease = async (request, run) => {
|
|
1514
|
+
await waitForRender(request);
|
|
1515
|
+
try {
|
|
1516
|
+
return await run();
|
|
1517
|
+
} finally {
|
|
1518
|
+
releaseRenderLease(request.renderId);
|
|
1519
|
+
}
|
|
1520
|
+
};
|
|
1521
|
+
const handleCommand = (message, source) => {
|
|
1522
|
+
const command = readCanvasHostCommand(message);
|
|
1523
|
+
if (!command) return;
|
|
1524
|
+
const payload = command.payload;
|
|
1525
|
+
const post = (response) => postToMessageSource(source, response);
|
|
1526
|
+
const ack = () => post({
|
|
1527
|
+
type: "render-pool:ack",
|
|
1528
|
+
requestId: command.requestId,
|
|
1529
|
+
command: command.type
|
|
1530
|
+
});
|
|
1531
|
+
const error = (message2) => post({
|
|
1532
|
+
type: "render-pool:error",
|
|
1533
|
+
requestId: command.requestId,
|
|
1534
|
+
command: command.type,
|
|
1535
|
+
error: message2
|
|
1536
|
+
});
|
|
1537
|
+
const postAsyncError = (caught) => {
|
|
1538
|
+
error(caught instanceof Error ? caught.message : String(caught));
|
|
1539
|
+
};
|
|
1540
|
+
const postCaptureResult = (capture) => post({
|
|
1541
|
+
type: "render-pool:capture-result",
|
|
1542
|
+
requestId: command.requestId,
|
|
1543
|
+
command: command.type,
|
|
1544
|
+
payload: { capture }
|
|
1545
|
+
});
|
|
1546
|
+
try {
|
|
1547
|
+
if (command.type === "render-pool:render") {
|
|
1548
|
+
const request = readRenderRequest(command.type, payload);
|
|
1549
|
+
void waitForRender(request).then(ack).catch(postAsyncError);
|
|
1550
|
+
return;
|
|
1551
|
+
}
|
|
1552
|
+
if (command.type === "render-pool:capture-image") {
|
|
1553
|
+
const request = readRenderRequest(command.type, payload);
|
|
1554
|
+
void withRenderLease(
|
|
1555
|
+
request,
|
|
1556
|
+
() => captureStoryboardImage(request.renderId, {
|
|
1557
|
+
overlaySelector: typeof payload.overlaySelector === "string" ? payload.overlaySelector : void 0,
|
|
1558
|
+
format: payload.format === "jpeg" || payload.format === "png" ? payload.format : void 0,
|
|
1559
|
+
quality: readOptionalNumber(payload, "quality"),
|
|
1560
|
+
scale: readOptionalNumber(payload, "scale"),
|
|
1561
|
+
outputPath: typeof payload.outputPath === "string" ? payload.outputPath : void 0,
|
|
1562
|
+
forceRefresh: payload.forceRefresh === true,
|
|
1563
|
+
portalSelectors: Array.isArray(payload.portalSelectors) ? payload.portalSelectors.filter(
|
|
1564
|
+
(selector) => typeof selector === "string"
|
|
1565
|
+
) : void 0
|
|
1566
|
+
})
|
|
1567
|
+
).then((capture) => {
|
|
1568
|
+
recordSourceAnnotatedCommit(request.renderId);
|
|
1569
|
+
postCaptureResult(capture);
|
|
1570
|
+
}).catch(postAsyncError);
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1573
|
+
if (command.type === "render-pool:capture-html") {
|
|
1574
|
+
const request = readRenderRequest(command.type, payload);
|
|
1575
|
+
void withRenderLease(
|
|
1576
|
+
request,
|
|
1577
|
+
() => captureStoryboardHtml(request.renderId, {
|
|
1578
|
+
timeout: readOptionalNumber(payload, "timeout")
|
|
1579
|
+
})
|
|
1580
|
+
).then((capture) => {
|
|
1581
|
+
recordSourceAnnotatedCommit(request.renderId);
|
|
1582
|
+
postCaptureResult(capture);
|
|
1583
|
+
}).catch(postAsyncError);
|
|
1584
|
+
return;
|
|
1585
|
+
}
|
|
1586
|
+
if (command.type === "render-pool:capture-static-html") {
|
|
1587
|
+
const request = readRenderRequest(command.type, payload);
|
|
1588
|
+
void withRenderLease(
|
|
1589
|
+
request,
|
|
1590
|
+
() => captureStoryboardStaticHtml(request.renderId, {
|
|
1591
|
+
timeout: readOptionalNumber(payload, "timeout")
|
|
1592
|
+
})
|
|
1593
|
+
).then((capture) => {
|
|
1594
|
+
recordSourceAnnotatedCommit(request.renderId);
|
|
1595
|
+
postCaptureResult(capture);
|
|
1596
|
+
}).catch(postAsyncError);
|
|
1597
|
+
return;
|
|
1598
|
+
}
|
|
1599
|
+
if (command.type === "render-pool:capture-combined") {
|
|
1600
|
+
const request = readRenderRequest(command.type, payload);
|
|
1601
|
+
void withRenderLease(
|
|
1602
|
+
request,
|
|
1603
|
+
() => captureStoryboardCombined(request.renderId, {
|
|
1604
|
+
fiberSelector: typeof payload.fiberSelector === "string" ? payload.fiberSelector : void 0,
|
|
1605
|
+
fiberTags: Array.isArray(payload.fiberTags) ? payload.fiberTags : void 0,
|
|
1606
|
+
timeout: readOptionalNumber(payload, "timeout")
|
|
1607
|
+
})
|
|
1608
|
+
).then((capture) => {
|
|
1609
|
+
recordSourceAnnotatedCommit(request.renderId);
|
|
1610
|
+
postCaptureResult(capture);
|
|
1611
|
+
}).catch(postAsyncError);
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
if (command.type === "render-pool:watch-html" || command.type === "render-pool:watch-combined") {
|
|
1615
|
+
const request = readRenderRequest(command.type, payload);
|
|
1616
|
+
const watchId = readWatchId(command.type, payload);
|
|
1617
|
+
void removeWatchRequest(watchId).then(() => {
|
|
1618
|
+
setEntries((entries) => acquireRender(entries, request));
|
|
1619
|
+
setWatchRequestsById((requests) => {
|
|
1620
|
+
const next = new Map(requests);
|
|
1621
|
+
next.set(watchId, {
|
|
1622
|
+
commandType: command.type,
|
|
1623
|
+
requestId: command.requestId,
|
|
1624
|
+
watchId,
|
|
1625
|
+
source,
|
|
1626
|
+
request,
|
|
1627
|
+
payload,
|
|
1628
|
+
paused: false,
|
|
1629
|
+
bindingKey: buildWatchBindingKey(command.type, payload)
|
|
1630
|
+
});
|
|
1631
|
+
watchRequestsRef.current = next;
|
|
1632
|
+
return next;
|
|
1633
|
+
});
|
|
1634
|
+
ack();
|
|
1635
|
+
}).catch(postAsyncError);
|
|
1636
|
+
return;
|
|
1637
|
+
}
|
|
1638
|
+
if (command.type === "render-pool:unwatch") {
|
|
1639
|
+
const watchId = readWatchId(command.type, payload);
|
|
1640
|
+
void removeWatchRequest(watchId).then(ack).catch(postAsyncError);
|
|
1641
|
+
return;
|
|
1642
|
+
}
|
|
1643
|
+
if (command.type === "render-pool:set-watch-paused") {
|
|
1644
|
+
const watchId = readWatchId(command.type, payload);
|
|
1645
|
+
const paused = payload.paused === true;
|
|
1646
|
+
const watch = watchesRef.current.get(watchId)?.watch;
|
|
1647
|
+
watch?.setPaused?.(paused);
|
|
1648
|
+
if (!watch?.setPaused) {
|
|
1649
|
+
if (paused) watch?.pause?.();
|
|
1650
|
+
else watch?.resume?.();
|
|
1651
|
+
}
|
|
1652
|
+
setWatchRequestsById((requests) => {
|
|
1653
|
+
const current = requests.get(watchId);
|
|
1654
|
+
if (!current || current.paused === paused) return requests;
|
|
1655
|
+
const next = new Map(requests);
|
|
1656
|
+
next.set(watchId, { ...current, paused });
|
|
1657
|
+
watchRequestsRef.current = next;
|
|
1658
|
+
return next;
|
|
1659
|
+
});
|
|
1660
|
+
ack();
|
|
1661
|
+
return;
|
|
1662
|
+
}
|
|
1663
|
+
if (command.type === "render-pool:unrender") {
|
|
1664
|
+
const target = requireRenderTarget(command.type, payload);
|
|
1665
|
+
releaseRenderLease(target.renderId);
|
|
1666
|
+
ack();
|
|
1667
|
+
return;
|
|
1668
|
+
}
|
|
1669
|
+
if (command.type === "render-pool:list") {
|
|
1670
|
+
post({
|
|
1671
|
+
type: "render-pool:state",
|
|
1672
|
+
requestId: command.requestId,
|
|
1673
|
+
payload: buildState()
|
|
1674
|
+
});
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
if (command.type === "render-pool:set-cache-limit") {
|
|
1678
|
+
const maxCached = typeof payload.maxCached === "number" && Number.isInteger(payload.maxCached) ? Math.max(0, payload.maxCached) : maxCachedRef.current;
|
|
1679
|
+
maxCachedRef.current = maxCached;
|
|
1680
|
+
setEntries((entries) => evictCachedRenders(entries, maxCached));
|
|
1681
|
+
ack();
|
|
1682
|
+
return;
|
|
1683
|
+
}
|
|
1684
|
+
if (command.type === "render-pool:isolate") {
|
|
1685
|
+
const target = resolveRenderTarget(payload);
|
|
1686
|
+
document.querySelector("[data-render-isolation]")?.remove();
|
|
1687
|
+
if (target?.renderId) {
|
|
1688
|
+
const style = document.createElement("style");
|
|
1689
|
+
style.setAttribute("data-render-isolation", "");
|
|
1690
|
+
const escapedId = typeof CSS !== "undefined" && typeof CSS.escape === "function" ? CSS.escape(target.renderId) : target.renderId;
|
|
1691
|
+
style.textContent = '[data-render-id]:not([data-render-id="' + escapedId + '"]) { opacity: 0 !important; pointer-events: none !important; }';
|
|
1692
|
+
document.head.appendChild(style);
|
|
1693
|
+
}
|
|
1694
|
+
ack();
|
|
1695
|
+
return;
|
|
1696
|
+
}
|
|
1697
|
+
if (command.type === "render-pool:query-health") {
|
|
1698
|
+
const target = resolveRenderTarget(payload);
|
|
1699
|
+
post({
|
|
1700
|
+
type: "render-pool:health-snapshot",
|
|
1701
|
+
requestId: command.requestId,
|
|
1702
|
+
snapshot: buildHealthSnapshot(target?.renderId ?? "")
|
|
1703
|
+
});
|
|
1704
|
+
return;
|
|
1705
|
+
}
|
|
1706
|
+
if (command.type === "render-pool:query-problems") {
|
|
1707
|
+
post({
|
|
1708
|
+
type: "render-pool:problem-snapshot",
|
|
1709
|
+
requestId: command.requestId,
|
|
1710
|
+
payload: buildProblemSnapshot()
|
|
1711
|
+
});
|
|
1712
|
+
return;
|
|
1713
|
+
}
|
|
1714
|
+
if (command.type === "render-pool:watch-problems") {
|
|
1715
|
+
const watchId = typeof payload.watchId === "string" && payload.watchId.trim() ? payload.watchId : String(command.requestId ?? "default");
|
|
1716
|
+
problemWatchersRef.current.set(watchId, {
|
|
1717
|
+
requestId: command.requestId,
|
|
1718
|
+
watchId,
|
|
1719
|
+
source
|
|
1720
|
+
});
|
|
1721
|
+
ack();
|
|
1722
|
+
post({
|
|
1723
|
+
type: "render-pool:problem-snapshot",
|
|
1724
|
+
requestId: command.requestId,
|
|
1725
|
+
watchId,
|
|
1726
|
+
payload: buildProblemSnapshot()
|
|
1727
|
+
});
|
|
1728
|
+
return;
|
|
1729
|
+
}
|
|
1730
|
+
if (command.type === "render-pool:unwatch-problems") {
|
|
1731
|
+
const watchId = typeof payload.watchId === "string" && payload.watchId.trim() ? payload.watchId : String(command.requestId ?? "default");
|
|
1732
|
+
problemWatchersRef.current.delete(watchId);
|
|
1733
|
+
ack();
|
|
1734
|
+
}
|
|
1735
|
+
} catch (caught) {
|
|
1736
|
+
postAsyncError(caught);
|
|
1737
|
+
}
|
|
1738
|
+
};
|
|
1739
|
+
const onMessage = (event) => handleCommand(event.data, event.source);
|
|
1740
|
+
const onBridgeCommand = (event) => handleCommand(event instanceof CustomEvent ? event.detail : void 0);
|
|
1741
|
+
window.addEventListener("message", onMessage);
|
|
1742
|
+
window.addEventListener("__render-pool:command", onBridgeCommand);
|
|
1743
|
+
const stopProblemPublisher = problemTrackerRef.current.watch(
|
|
1744
|
+
publishProblemSnapshot
|
|
1745
|
+
);
|
|
1746
|
+
const stopRuntimeProblemTracking = installCanvasHostRuntimeProblemTracking(
|
|
1747
|
+
problemTrackerRef.current
|
|
1748
|
+
);
|
|
1749
|
+
window.postMessage({ type: "render-pool:ready" }, "*");
|
|
1750
|
+
return () => {
|
|
1751
|
+
window.removeEventListener("message", onMessage);
|
|
1752
|
+
window.removeEventListener("__render-pool:command", onBridgeCommand);
|
|
1753
|
+
stopRuntimeProblemTracking();
|
|
1754
|
+
stopProblemPublisher();
|
|
1755
|
+
for (const { watch } of watchesRef.current.values()) {
|
|
1756
|
+
void watch.stop();
|
|
1757
|
+
}
|
|
1758
|
+
watchesRef.current.clear();
|
|
1759
|
+
problemWatchersRef.current.clear();
|
|
1760
|
+
};
|
|
1761
|
+
}, [
|
|
1762
|
+
buildHealthSnapshot,
|
|
1763
|
+
buildProblemSnapshot,
|
|
1764
|
+
buildState,
|
|
1765
|
+
publishProblemSnapshot,
|
|
1766
|
+
recordSourceAnnotatedCommit,
|
|
1767
|
+
releaseRenderLease,
|
|
1768
|
+
removeWatchRequest,
|
|
1769
|
+
setEntries,
|
|
1770
|
+
waitForRender
|
|
1771
|
+
]);
|
|
1772
|
+
return {
|
|
1773
|
+
renderStatusById: useMemo2(
|
|
1774
|
+
() => buildRenderStatusMap(renderEntriesById),
|
|
1775
|
+
[renderEntriesById]
|
|
1776
|
+
),
|
|
1777
|
+
renderSizeById: useMemo2(
|
|
1778
|
+
() => buildRenderSizeMap(renderEntriesById),
|
|
1779
|
+
[renderEntriesById]
|
|
1780
|
+
),
|
|
1781
|
+
markStoryboardRendered,
|
|
1782
|
+
reportStoryboardError,
|
|
1783
|
+
clearStoryboardError
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1786
|
+
function latestTimestamp(values) {
|
|
1787
|
+
let latest = null;
|
|
1788
|
+
for (const value of values.values()) {
|
|
1789
|
+
latest = latest === null ? value : Math.max(latest, value);
|
|
1790
|
+
}
|
|
1791
|
+
return latest;
|
|
1792
|
+
}
|
|
1793
|
+
function isReactConnected() {
|
|
1794
|
+
const hook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
1795
|
+
return (hook?.renderers?.size ?? 0) > 0;
|
|
1796
|
+
}
|
|
1797
|
+
function buildWatchBindingKey(commandType, payload) {
|
|
1798
|
+
try {
|
|
1799
|
+
return JSON.stringify({ commandType, payload });
|
|
1800
|
+
} catch {
|
|
1801
|
+
return `${commandType}:${Date.now()}`;
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
var sourceAnnotationSelector2 = "[data-tempo-source-file], [data-tempo-source-loc], [data-tempo-filepath], [data-tempo-html-filepath]";
|
|
1805
|
+
function renderSlotHasSourceAnnotations(renderId) {
|
|
1806
|
+
const slot = typeof document === "undefined" ? null : document.querySelector(buildRenderContentSelector(renderId));
|
|
1807
|
+
return getObservedSourceFiles2(slot).length > 0;
|
|
1808
|
+
}
|
|
1809
|
+
function getObservedSourceFiles2(slot) {
|
|
1810
|
+
if (!slot) return [];
|
|
1811
|
+
return [
|
|
1812
|
+
...new Set(
|
|
1813
|
+
[...slot.querySelectorAll(sourceAnnotationSelector2)].flatMap((element) => [
|
|
1814
|
+
element.getAttribute("data-tempo-source-file"),
|
|
1815
|
+
element.getAttribute("data-tempo-filepath"),
|
|
1816
|
+
element.getAttribute("data-tempo-html-filepath"),
|
|
1817
|
+
element.getAttribute("data-tempo-source-loc")
|
|
1818
|
+
]).filter((file) => Boolean(file))
|
|
1819
|
+
)
|
|
1820
|
+
];
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
// canvas/canvas-host.tsx
|
|
1824
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
1825
|
+
function readDirectUrlDimension(value) {
|
|
1826
|
+
const match = value.trim().match(/^([0-9]*\.?[0-9]+)(px|vw|vh)?$/);
|
|
1827
|
+
if (!match) {
|
|
1828
|
+
throw new Error(
|
|
1829
|
+
"Direct URL dimensions must be positive finite numbers, optionally with px, vw, or vh units"
|
|
1830
|
+
);
|
|
1831
|
+
}
|
|
1832
|
+
const numberPart = match[1] ?? "";
|
|
1833
|
+
const unit = match[2] ?? "";
|
|
1834
|
+
const numberValue = Number(numberPart);
|
|
1835
|
+
if (!numberPart || !Number.isFinite(numberValue) || numberValue <= 0) {
|
|
1836
|
+
throw new Error(
|
|
1837
|
+
"Direct URL dimensions must be positive finite numbers, optionally with px, vw, or vh units"
|
|
1838
|
+
);
|
|
1839
|
+
}
|
|
1840
|
+
return unit && unit !== "px" ? `${numberValue}${unit}` : numberValue;
|
|
1841
|
+
}
|
|
1842
|
+
function readDirectUrlSize(params) {
|
|
1843
|
+
const width = params.get("width")?.trim();
|
|
1844
|
+
const height = params.get("height")?.trim();
|
|
1845
|
+
if (!width && !height) return void 0;
|
|
1846
|
+
if (!width || !height) {
|
|
1847
|
+
throw new Error("Direct URL width and height must be provided together");
|
|
1848
|
+
}
|
|
1849
|
+
return {
|
|
1850
|
+
width: readDirectUrlDimension(width),
|
|
1851
|
+
height: readDirectUrlDimension(height),
|
|
1852
|
+
revision: 1
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
function readDirectUrlRender() {
|
|
1856
|
+
if (typeof window === "undefined") return null;
|
|
1857
|
+
const params = new URLSearchParams(window.location.search);
|
|
1858
|
+
const canvasPath = params.get("pageFile")?.trim() ?? params.get("importPath")?.trim() ?? "";
|
|
1859
|
+
const storyboardId = params.get("exportName")?.trim() ?? params.get("importName")?.trim() ?? "";
|
|
1860
|
+
if (!canvasPath || !storyboardId) return null;
|
|
1861
|
+
return {
|
|
1862
|
+
renderId: getCanvasStoryboardRenderId(canvasPath, storyboardId),
|
|
1863
|
+
size: readDirectUrlSize(params)
|
|
1864
|
+
};
|
|
1865
|
+
}
|
|
1866
|
+
function CanvasHost({
|
|
1867
|
+
children,
|
|
1868
|
+
activeStoryboardIds,
|
|
1869
|
+
isStoryboardActive
|
|
1870
|
+
}) {
|
|
1871
|
+
const {
|
|
1872
|
+
renderStatusById: renderStatusById2,
|
|
1873
|
+
renderSizeById,
|
|
1874
|
+
markStoryboardRendered,
|
|
1875
|
+
reportStoryboardError,
|
|
1876
|
+
clearStoryboardError
|
|
1877
|
+
} = useCanvasHostPostMessage();
|
|
1878
|
+
const directUrlSearch = typeof window === "undefined" ? "" : window.location.search;
|
|
1879
|
+
const directUrlRender = useMemo3(readDirectUrlRender, [directUrlSearch]);
|
|
1880
|
+
const propActiveIds = useMemo3(
|
|
1881
|
+
() => new Set(activeStoryboardIds ?? []),
|
|
1882
|
+
[activeStoryboardIds]
|
|
1883
|
+
);
|
|
1884
|
+
const runtime = useMemo3(
|
|
1885
|
+
() => ({
|
|
1886
|
+
getStoryboardStatus(storyboardId) {
|
|
1887
|
+
const normalizedId = normalizeId(storyboardId, "Storyboard id");
|
|
1888
|
+
if (propActiveIds.has(normalizedId) || directUrlRender?.renderId === normalizedId || (isStoryboardActive ? isStoryboardActive(normalizedId) : false)) {
|
|
1889
|
+
return "active";
|
|
1890
|
+
}
|
|
1891
|
+
return renderStatusById2.get(normalizedId) ?? "unmounted";
|
|
1892
|
+
},
|
|
1893
|
+
getStoryboardSize(storyboardId) {
|
|
1894
|
+
const normalizedId = normalizeId(storyboardId, "Storyboard id");
|
|
1895
|
+
if (directUrlRender?.renderId === normalizedId) {
|
|
1896
|
+
return directUrlRender.size;
|
|
1897
|
+
}
|
|
1898
|
+
return renderSizeById.get(normalizedId);
|
|
1899
|
+
},
|
|
1900
|
+
markStoryboardRendered,
|
|
1901
|
+
reportStoryboardError,
|
|
1902
|
+
clearStoryboardError
|
|
1903
|
+
}),
|
|
1904
|
+
[
|
|
1905
|
+
clearStoryboardError,
|
|
1906
|
+
directUrlRender,
|
|
1907
|
+
isStoryboardActive,
|
|
1908
|
+
markStoryboardRendered,
|
|
1909
|
+
propActiveIds,
|
|
1910
|
+
reportStoryboardError,
|
|
1911
|
+
renderSizeById,
|
|
1912
|
+
renderStatusById2
|
|
1913
|
+
]
|
|
1914
|
+
);
|
|
1915
|
+
return /* @__PURE__ */ jsx2(CanvasHostContext.Provider, { value: runtime, children });
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
// canvas/storyboard.tsx
|
|
1919
|
+
import {
|
|
1920
|
+
Component,
|
|
1921
|
+
Suspense,
|
|
1922
|
+
useEffect as useEffect2,
|
|
1923
|
+
useRef as useRef2
|
|
1924
|
+
} from "react";
|
|
1925
|
+
import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
1926
|
+
function Storyboard({
|
|
1927
|
+
id,
|
|
1928
|
+
name,
|
|
1929
|
+
component,
|
|
1930
|
+
layout,
|
|
1931
|
+
props
|
|
1932
|
+
}) {
|
|
1933
|
+
const Component2 = component;
|
|
1934
|
+
return /* @__PURE__ */ jsx3(StoryboardSlot, { id, name, layout, kind: "component", children: /* @__PURE__ */ jsx3(Component2, { ...props ?? {} }) });
|
|
1935
|
+
}
|
|
1936
|
+
function LegacyStoryboardV1({
|
|
1937
|
+
id,
|
|
1938
|
+
storyboard
|
|
1939
|
+
}) {
|
|
1940
|
+
return /* @__PURE__ */ jsx3(
|
|
1941
|
+
StoryboardSlot,
|
|
1942
|
+
{
|
|
1943
|
+
id,
|
|
1944
|
+
name: storyboard.name,
|
|
1945
|
+
layout: storyboard.layout,
|
|
1946
|
+
kind: "component",
|
|
1947
|
+
children: /* @__PURE__ */ jsx3(LegacyStoryboardV1Render, { render: storyboard.render })
|
|
1948
|
+
}
|
|
1949
|
+
);
|
|
1950
|
+
}
|
|
1951
|
+
function LegacyStoryboardV1Render({
|
|
1952
|
+
render
|
|
1953
|
+
}) {
|
|
1954
|
+
return /* @__PURE__ */ jsx3(Fragment, { children: render() });
|
|
1955
|
+
}
|
|
1956
|
+
function RouteStoryboard({
|
|
1957
|
+
id,
|
|
1958
|
+
name,
|
|
1959
|
+
route,
|
|
1960
|
+
layout
|
|
1961
|
+
}) {
|
|
1962
|
+
return /* @__PURE__ */ jsx3(
|
|
1963
|
+
StoryboardSlot,
|
|
1964
|
+
{
|
|
1965
|
+
id,
|
|
1966
|
+
name,
|
|
1967
|
+
layout,
|
|
1968
|
+
kind: "route",
|
|
1969
|
+
route
|
|
1970
|
+
}
|
|
1971
|
+
);
|
|
1972
|
+
}
|
|
1973
|
+
function HtmlStoryboard({
|
|
1974
|
+
id,
|
|
1975
|
+
name,
|
|
1976
|
+
filepath,
|
|
1977
|
+
src,
|
|
1978
|
+
layout
|
|
1979
|
+
}) {
|
|
1980
|
+
return /* @__PURE__ */ jsx3(
|
|
1981
|
+
StoryboardSlot,
|
|
1982
|
+
{
|
|
1983
|
+
id,
|
|
1984
|
+
name,
|
|
1985
|
+
layout,
|
|
1986
|
+
kind: "html",
|
|
1987
|
+
filepath,
|
|
1988
|
+
src
|
|
1989
|
+
}
|
|
1990
|
+
);
|
|
1991
|
+
}
|
|
1992
|
+
function StoryboardSlot({
|
|
1993
|
+
children,
|
|
1994
|
+
id,
|
|
1995
|
+
kind,
|
|
1996
|
+
layout,
|
|
1997
|
+
name,
|
|
1998
|
+
route,
|
|
1999
|
+
filepath,
|
|
2000
|
+
src
|
|
2001
|
+
}) {
|
|
2002
|
+
const renderId = useCanvasStoryboardRenderId(id);
|
|
2003
|
+
const canvas = useCanvasIdentity();
|
|
2004
|
+
const status = useStoryboardStatus(id);
|
|
2005
|
+
const renderSize = useStoryboardSize(id);
|
|
2006
|
+
const markRendered = useStoryboardRendered(id);
|
|
2007
|
+
const { reportError, clearError } = useStoryboardErrorReporter(id);
|
|
2008
|
+
const renderWidth = renderSize?.width;
|
|
2009
|
+
const renderHeight = renderSize?.height;
|
|
2010
|
+
const intrinsicSize = renderSize?.intrinsicSize;
|
|
2011
|
+
const resetKey = `${renderId}:${renderSize?.revision ?? 0}`;
|
|
2012
|
+
const contentRef = useRef2(null);
|
|
2013
|
+
useEffect2(() => {
|
|
2014
|
+
if (!contentRef.current || status === "unmounted") return;
|
|
2015
|
+
return trackStoryboardPortals(renderId, contentRef.current, status);
|
|
2016
|
+
}, [renderId]);
|
|
2017
|
+
useEffect2(() => {
|
|
2018
|
+
if (status === "unmounted") return;
|
|
2019
|
+
syncStoryboardPortals(renderId, status);
|
|
2020
|
+
}, [renderId, status]);
|
|
2021
|
+
if (status === "unmounted") return null;
|
|
2022
|
+
return /* @__PURE__ */ jsx3(
|
|
2023
|
+
"div",
|
|
2024
|
+
{
|
|
2025
|
+
"data-render-id": renderId,
|
|
2026
|
+
"data-render-status": status,
|
|
2027
|
+
"data-tempo-storyboard-render-id": renderId,
|
|
2028
|
+
"data-tempo-storyboard-id": id,
|
|
2029
|
+
"data-tempo-canvas-path": canvas?.path,
|
|
2030
|
+
"data-tempo-storyboard-name": name,
|
|
2031
|
+
"data-tempo-storyboard-kind": kind,
|
|
2032
|
+
"data-tempo-storyboard-route": route,
|
|
2033
|
+
"data-tempo-storyboard-filepath": filepath,
|
|
2034
|
+
"data-tempo-storyboard-src": src,
|
|
2035
|
+
style: {
|
|
2036
|
+
position: "absolute",
|
|
2037
|
+
left: layout.x,
|
|
2038
|
+
top: layout.y,
|
|
2039
|
+
width: intrinsicSize ? "max-content" : renderWidth ?? layout.width,
|
|
2040
|
+
height: intrinsicSize ? "max-content" : renderHeight ?? layout.height,
|
|
2041
|
+
minWidth: intrinsicSize ? renderWidth : void 0,
|
|
2042
|
+
minHeight: intrinsicSize ? renderHeight : void 0,
|
|
2043
|
+
zIndex: layout.zIndex,
|
|
2044
|
+
visibility: status === "active" ? "visible" : "hidden",
|
|
2045
|
+
pointerEvents: status === "active" ? "auto" : "none"
|
|
2046
|
+
},
|
|
2047
|
+
children: /* @__PURE__ */ jsx3(
|
|
2048
|
+
"div",
|
|
2049
|
+
{
|
|
2050
|
+
"data-render-content": renderId,
|
|
2051
|
+
ref: contentRef,
|
|
2052
|
+
style: { width: "100%", height: "100%" },
|
|
2053
|
+
children: /* @__PURE__ */ jsx3(
|
|
2054
|
+
StoryboardErrorBoundary,
|
|
2055
|
+
{
|
|
2056
|
+
onError: reportError,
|
|
2057
|
+
onRecover: clearError,
|
|
2058
|
+
resetKey,
|
|
2059
|
+
children: /* @__PURE__ */ jsxs(Suspense, { fallback: null, children: [
|
|
2060
|
+
children,
|
|
2061
|
+
/* @__PURE__ */ jsx3(
|
|
2062
|
+
StoryboardReadySentinel,
|
|
2063
|
+
{
|
|
2064
|
+
active: status === "active",
|
|
2065
|
+
clearError,
|
|
2066
|
+
markRendered
|
|
2067
|
+
}
|
|
2068
|
+
)
|
|
2069
|
+
] })
|
|
2070
|
+
}
|
|
2071
|
+
)
|
|
2072
|
+
}
|
|
2073
|
+
)
|
|
2074
|
+
}
|
|
2075
|
+
);
|
|
2076
|
+
}
|
|
2077
|
+
var renderErrorRetryDelayMs = 1e3;
|
|
2078
|
+
var StoryboardErrorBoundary = class extends Component {
|
|
2079
|
+
constructor() {
|
|
2080
|
+
super(...arguments);
|
|
2081
|
+
this.retryTimer = null;
|
|
2082
|
+
this.state = {
|
|
2083
|
+
error: null,
|
|
2084
|
+
componentStack: void 0,
|
|
2085
|
+
resetKey: this.props.resetKey
|
|
2086
|
+
};
|
|
2087
|
+
}
|
|
2088
|
+
static getDerivedStateFromError(error) {
|
|
2089
|
+
return { error };
|
|
2090
|
+
}
|
|
2091
|
+
static getDerivedStateFromProps(props, state) {
|
|
2092
|
+
if (props.resetKey !== state.resetKey) {
|
|
2093
|
+
return { error: null, componentStack: void 0, resetKey: props.resetKey };
|
|
2094
|
+
}
|
|
2095
|
+
return null;
|
|
2096
|
+
}
|
|
2097
|
+
componentDidCatch(error, info) {
|
|
2098
|
+
this.setState({ componentStack: info.componentStack ?? void 0 });
|
|
2099
|
+
this.props.onError({
|
|
2100
|
+
message: error.message,
|
|
2101
|
+
stack: error.stack,
|
|
2102
|
+
componentStack: info.componentStack ?? void 0
|
|
2103
|
+
});
|
|
2104
|
+
this.scheduleRetry();
|
|
2105
|
+
}
|
|
2106
|
+
componentDidUpdate(_prevProps, prevState) {
|
|
2107
|
+
if (this.state.error) {
|
|
2108
|
+
if (!this.retryTimer) this.scheduleRetry();
|
|
2109
|
+
return;
|
|
2110
|
+
}
|
|
2111
|
+
this.clearRetryTimer();
|
|
2112
|
+
if (prevState.error && !this.state.error) {
|
|
2113
|
+
this.props.onRecover();
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
componentWillUnmount() {
|
|
2117
|
+
this.clearRetryTimer();
|
|
2118
|
+
}
|
|
2119
|
+
scheduleRetry() {
|
|
2120
|
+
this.clearRetryTimer();
|
|
2121
|
+
this.retryTimer = setTimeout(() => {
|
|
2122
|
+
this.retryTimer = null;
|
|
2123
|
+
this.setState(
|
|
2124
|
+
(state) => state.error ? { error: null, componentStack: void 0, resetKey: state.resetKey } : null
|
|
2125
|
+
);
|
|
2126
|
+
}, renderErrorRetryDelayMs);
|
|
2127
|
+
}
|
|
2128
|
+
clearRetryTimer() {
|
|
2129
|
+
if (!this.retryTimer) return;
|
|
2130
|
+
clearTimeout(this.retryTimer);
|
|
2131
|
+
this.retryTimer = null;
|
|
2132
|
+
}
|
|
2133
|
+
render() {
|
|
2134
|
+
if (this.state.error) {
|
|
2135
|
+
return /* @__PURE__ */ jsx3(
|
|
2136
|
+
"div",
|
|
2137
|
+
{
|
|
2138
|
+
"data-render-error": "true",
|
|
2139
|
+
"data-render-error-message": this.state.error.message,
|
|
2140
|
+
style: { width: "100%", height: "100%" }
|
|
2141
|
+
}
|
|
2142
|
+
);
|
|
2143
|
+
}
|
|
2144
|
+
return this.props.children;
|
|
2145
|
+
}
|
|
2146
|
+
};
|
|
2147
|
+
function StoryboardReadySentinel({
|
|
2148
|
+
active,
|
|
2149
|
+
clearError,
|
|
2150
|
+
markRendered
|
|
2151
|
+
}) {
|
|
2152
|
+
useEffect2(() => {
|
|
2153
|
+
if (!active) return;
|
|
2154
|
+
let paintFrame = 0;
|
|
2155
|
+
const commitFrame = requestAnimationFrame(() => {
|
|
2156
|
+
paintFrame = requestAnimationFrame(() => {
|
|
2157
|
+
clearError();
|
|
2158
|
+
markRendered();
|
|
2159
|
+
});
|
|
2160
|
+
});
|
|
2161
|
+
return () => {
|
|
2162
|
+
cancelAnimationFrame(commitFrame);
|
|
2163
|
+
cancelAnimationFrame(paintFrame);
|
|
2164
|
+
};
|
|
2165
|
+
}, [active, clearError, markRendered]);
|
|
2166
|
+
return null;
|
|
2167
|
+
}
|
|
2168
|
+
export {
|
|
2169
|
+
Canvas,
|
|
2170
|
+
CanvasContext,
|
|
2171
|
+
CanvasHost,
|
|
2172
|
+
HtmlStoryboard,
|
|
2173
|
+
LegacyStoryboardV1,
|
|
2174
|
+
RouteStoryboard,
|
|
2175
|
+
Storyboard,
|
|
2176
|
+
StoryboardSlot,
|
|
2177
|
+
buildRenderContentFiberSelector,
|
|
2178
|
+
buildRenderContentSelector,
|
|
2179
|
+
buildRenderSelector,
|
|
2180
|
+
captureStoryboardCombined,
|
|
2181
|
+
captureStoryboardHtml,
|
|
2182
|
+
captureStoryboardImage,
|
|
2183
|
+
captureStoryboardStaticHtml,
|
|
2184
|
+
getCanvasHostRuntime,
|
|
2185
|
+
getCanvasStoryboardRenderId,
|
|
2186
|
+
getOptionalCanvasHostRuntime,
|
|
2187
|
+
stripRenderContentWrapperAttributes,
|
|
2188
|
+
stripRenderContentWrapperFromCombinedCapture,
|
|
2189
|
+
useActiveState,
|
|
2190
|
+
watchStoryboardCombined,
|
|
2191
|
+
watchStoryboardHtml
|
|
2192
|
+
};
|
|
2193
|
+
//# sourceMappingURL=index.js.map
|