@vidact/runtime 0.2.0-beta.0
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/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/README.md +50 -0
- package/dist/actions.d.ts +37 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +295 -0
- package/dist/actions.js.map +1 -0
- package/dist/async.d.ts +22 -0
- package/dist/async.d.ts.map +1 -0
- package/dist/async.js +24 -0
- package/dist/async.js.map +1 -0
- package/dist/compiled/async-resource.d.ts +7 -0
- package/dist/compiled/async-resource.d.ts.map +1 -0
- package/dist/compiled/async-resource.js +89 -0
- package/dist/compiled/async-resource.js.map +1 -0
- package/dist/compiled/core.d.ts +183 -0
- package/dist/compiled/core.d.ts.map +1 -0
- package/dist/compiled/core.js +3170 -0
- package/dist/compiled/core.js.map +1 -0
- package/dist/compiled/types.d.ts +63 -0
- package/dist/compiled/types.d.ts.map +1 -0
- package/dist/compiled/types.js +7 -0
- package/dist/compiled/types.js.map +1 -0
- package/dist/compiled/validation.d.ts +2 -0
- package/dist/compiled/validation.d.ts.map +1 -0
- package/dist/compiled/validation.js +22 -0
- package/dist/compiled/validation.js.map +1 -0
- package/dist/component-spread.d.ts +6 -0
- package/dist/component-spread.d.ts.map +1 -0
- package/dist/component-spread.js +71 -0
- package/dist/component-spread.js.map +1 -0
- package/dist/concurrent.d.ts +26 -0
- package/dist/concurrent.d.ts.map +1 -0
- package/dist/concurrent.js +244 -0
- package/dist/concurrent.js.map +1 -0
- package/dist/direct-dom.d.ts +14 -0
- package/dist/direct-dom.d.ts.map +1 -0
- package/dist/direct-dom.js +239 -0
- package/dist/direct-dom.js.map +1 -0
- package/dist/dom/attributes.d.ts +7 -0
- package/dist/dom/attributes.d.ts.map +1 -0
- package/dist/dom/attributes.js +52 -0
- package/dist/dom/attributes.js.map +1 -0
- package/dist/dom/events.d.ts +3 -0
- package/dist/dom/events.d.ts.map +1 -0
- package/dist/dom/events.js +78 -0
- package/dist/dom/events.js.map +1 -0
- package/dist/dom/forms.d.ts +7 -0
- package/dist/dom/forms.d.ts.map +1 -0
- package/dist/dom/forms.js +217 -0
- package/dist/dom/forms.js.map +1 -0
- package/dist/dom/intrinsic.d.ts +19 -0
- package/dist/dom/intrinsic.d.ts.map +1 -0
- package/dist/dom/intrinsic.js +53 -0
- package/dist/dom/intrinsic.js.map +1 -0
- package/dist/dom/namespace.d.ts +3 -0
- package/dist/dom/namespace.d.ts.map +1 -0
- package/dist/dom/namespace.js +34 -0
- package/dist/dom/namespace.js.map +1 -0
- package/dist/dom/namespaces.d.ts +9 -0
- package/dist/dom/namespaces.d.ts.map +1 -0
- package/dist/dom/namespaces.js +14 -0
- package/dist/dom/namespaces.js.map +1 -0
- package/dist/dom/properties.d.ts +27 -0
- package/dist/dom/properties.d.ts.map +1 -0
- package/dist/dom/properties.js +333 -0
- package/dist/dom/properties.js.map +1 -0
- package/dist/dom/style-properties.d.ts +2 -0
- package/dist/dom/style-properties.d.ts.map +1 -0
- package/dist/dom/style-properties.js +47 -0
- package/dist/dom/style-properties.js.map +1 -0
- package/dist/dom/styles.d.ts +4 -0
- package/dist/dom/styles.d.ts.map +1 -0
- package/dist/dom/styles.js +77 -0
- package/dist/dom/styles.js.map +1 -0
- package/dist/dom-forms.d.ts +3 -0
- package/dist/dom-forms.d.ts.map +1 -0
- package/dist/dom-forms.js +17 -0
- package/dist/dom-forms.js.map +1 -0
- package/dist/dom-styles.d.ts +3 -0
- package/dist/dom-styles.d.ts.map +1 -0
- package/dist/dom-styles.js +11 -0
- package/dist/dom-styles.js.map +1 -0
- package/dist/env.d.ts +6 -0
- package/dist/framework-hydrate.d.ts +21 -0
- package/dist/framework-hydrate.d.ts.map +1 -0
- package/dist/framework-hydrate.js +165 -0
- package/dist/framework-hydrate.js.map +1 -0
- package/dist/framework-protocol.d.ts +33 -0
- package/dist/framework-protocol.d.ts.map +1 -0
- package/dist/framework-protocol.js +235 -0
- package/dist/framework-protocol.js.map +1 -0
- package/dist/framework.d.ts +39 -0
- package/dist/framework.d.ts.map +1 -0
- package/dist/framework.js +111 -0
- package/dist/framework.js.map +1 -0
- package/dist/hydrate.d.ts +9 -0
- package/dist/hydrate.d.ts.map +1 -0
- package/dist/hydrate.js +14 -0
- package/dist/hydrate.js.map +1 -0
- package/dist/hydration-bridge.d.ts +62 -0
- package/dist/hydration-bridge.d.ts.map +1 -0
- package/dist/hydration-bridge.js +95 -0
- package/dist/hydration-bridge.js.map +1 -0
- package/dist/hydration.d.ts +29 -0
- package/dist/hydration.d.ts.map +1 -0
- package/dist/hydration.js +489 -0
- package/dist/hydration.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/indexed-list.d.ts +12 -0
- package/dist/indexed-list.d.ts.map +1 -0
- package/dist/indexed-list.js +10 -0
- package/dist/indexed-list.js.map +1 -0
- package/dist/jsx-runtime.d.ts +12 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +27 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/keyed-list.d.ts +17 -0
- package/dist/keyed-list.d.ts.map +1 -0
- package/dist/keyed-list.js +180 -0
- package/dist/keyed-list.js.map +1 -0
- package/dist/metadata.d.ts +4 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +187 -0
- package/dist/metadata.js.map +1 -0
- package/dist/nested-prop.d.ts +4 -0
- package/dist/nested-prop.d.ts.map +1 -0
- package/dist/nested-prop.js +18 -0
- package/dist/nested-prop.js.map +1 -0
- package/dist/profiling.d.ts +10 -0
- package/dist/profiling.d.ts.map +1 -0
- package/dist/profiling.js +21 -0
- package/dist/profiling.js.map +1 -0
- package/dist/protocol.d.ts +3 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +7 -0
- package/dist/protocol.js.map +1 -0
- package/dist/raw-html.d.ts +3 -0
- package/dist/raw-html.d.ts.map +1 -0
- package/dist/raw-html.js +172 -0
- package/dist/raw-html.js.map +1 -0
- package/dist/ref.d.ts +6 -0
- package/dist/ref.d.ts.map +1 -0
- package/dist/ref.js +5 -0
- package/dist/ref.js.map +1 -0
- package/dist/renderable-protocol.d.ts +10 -0
- package/dist/renderable-protocol.d.ts.map +1 -0
- package/dist/renderable-protocol.js +12 -0
- package/dist/renderable-protocol.js.map +1 -0
- package/dist/renderable.d.ts +27 -0
- package/dist/renderable.d.ts.map +1 -0
- package/dist/renderable.js +147 -0
- package/dist/renderable.js.map +1 -0
- package/dist/retained-ui.d.ts +8 -0
- package/dist/retained-ui.d.ts.map +1 -0
- package/dist/retained-ui.js +12 -0
- package/dist/retained-ui.js.map +1 -0
- package/dist/root.d.ts +18 -0
- package/dist/root.d.ts.map +1 -0
- package/dist/root.js +94 -0
- package/dist/root.js.map +1 -0
- package/dist/scheduler.d.ts +10 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +124 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/server-framework.d.ts +52 -0
- package/dist/server-framework.d.ts.map +1 -0
- package/dist/server-framework.js +247 -0
- package/dist/server-framework.js.map +1 -0
- package/dist/server.d.ts +159 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +793 -0
- package/dist/server.js.map +1 -0
- package/dist/shared/promise.d.ts +4 -0
- package/dist/shared/promise.d.ts.map +1 -0
- package/dist/shared/promise.js +23 -0
- package/dist/shared/promise.js.map +1 -0
- package/dist/source-mask.d.ts +7 -0
- package/dist/source-mask.d.ts.map +1 -0
- package/dist/source-mask.js +74 -0
- package/dist/source-mask.js.map +1 -0
- package/dist/spread.d.ts +3 -0
- package/dist/spread.d.ts.map +1 -0
- package/dist/spread.js +103 -0
- package/dist/spread.js.map +1 -0
- package/dist/state-slot.d.ts +18 -0
- package/dist/state-slot.d.ts.map +1 -0
- package/dist/state-slot.js +46 -0
- package/dist/state-slot.js.map +1 -0
- package/dist/testing.d.ts +7 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +18 -0
- package/dist/testing.js.map +1 -0
- package/package.json +151 -0
|
@@ -0,0 +1,3170 @@
|
|
|
1
|
+
import { currentIntrinsicNamespace, withIntrinsicNamespace, } from '../dom/intrinsic.js';
|
|
2
|
+
import { HydrationMismatch, beginHydration, borrowHydrationSlotRange, claimHydrationArrayRange, claimHydrationComponentMount, claimHydrationComponentRange, claimHydrationNode, claimHydrationSlotRange, claimHydrationSuspenseFallback, claimHydrationText, claimHydrationTextRange, hydrationRangeParent, hydrationRootMarkers, finishHydration, finishHydrationArrayRange, hydrationCursor, hydrationFragmentChildren, hydrationInsertionPoint, isHydrating, isHydrationMismatch, noteHydrationStructuralParent, withoutHydration, withHydrationComponentRange, withHydrationInsertion, withHydrationCursor, } from '../hydration-bridge.js';
|
|
3
|
+
import { createIndexedList } from '../indexed-list.js';
|
|
4
|
+
import { createKeyedList } from '../keyed-list.js';
|
|
5
|
+
import { isRenderableProtocol, materializeRenderable } from '../renderable-protocol.js';
|
|
6
|
+
import { scheduleDeferredTask, scheduleTask } from '../scheduler.js';
|
|
7
|
+
import { intersectsSources, isEmptySources, unionSources } from '../source-mask.js';
|
|
8
|
+
import { createStateSlot } from '../state-slot.js';
|
|
9
|
+
import { isSuspension, subscribeResource, useAsync } from './async-resource.js';
|
|
10
|
+
import { BINDING, COMPONENT_SPREAD_SOURCE as componentSpreadSourceSymbol, CONTEXT, STRUCTURAL, } from './types.js';
|
|
11
|
+
import { hasInvalidChild } from './validation.js';
|
|
12
|
+
export const COMPONENT_SPREAD_SOURCE = componentSpreadSourceSymbol;
|
|
13
|
+
const MAX_FLUSH_PASSES = 100;
|
|
14
|
+
export const DEV = typeof __VIDACT_DEV__ === 'undefined' || __VIDACT_DEV__;
|
|
15
|
+
let retainedUiEnabled = typeof __VIDACT_RETAINED_UI__ !== 'undefined' && __VIDACT_RETAINED_UI__;
|
|
16
|
+
let profilingEnabled = false;
|
|
17
|
+
let activeOwnerCount = 0;
|
|
18
|
+
let createdOwnerCount = 0;
|
|
19
|
+
const noop = () => { };
|
|
20
|
+
const wideSourceOperations = [isEmptySources, intersectsSources, unionSources];
|
|
21
|
+
const narrowSourceOperations = [
|
|
22
|
+
(mask) => mask === 0,
|
|
23
|
+
(left, right) => (left & right) !== 0,
|
|
24
|
+
(left, right) => (left | right) >>> 0,
|
|
25
|
+
];
|
|
26
|
+
export function deferred(render) {
|
|
27
|
+
noteHydrationStructuralParent();
|
|
28
|
+
return [
|
|
29
|
+
STRUCTURAL,
|
|
30
|
+
(parent, before) => {
|
|
31
|
+
const hydrated = claimHydrationSlotRange(parent);
|
|
32
|
+
if (hydrated === undefined)
|
|
33
|
+
insertValue(parent, render(), before);
|
|
34
|
+
else
|
|
35
|
+
insertValue(parent, render(), hydrated[1]);
|
|
36
|
+
},
|
|
37
|
+
'slot',
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
/** @internal */
|
|
41
|
+
export function retainedActivity(modeInput, render) {
|
|
42
|
+
noteHydrationStructuralParent();
|
|
43
|
+
const context = activeContextFrame ?? activeOwner?.[2] ?? null;
|
|
44
|
+
const rootIdentity = activeOwner?.[3] ?? activeRootIdentity;
|
|
45
|
+
if (rootIdentity === null) {
|
|
46
|
+
throw new Error(DEV ? 'Activity must run during compiled root construction' : 'V033');
|
|
47
|
+
}
|
|
48
|
+
const parentErrorBoundary = activeOwner?.[4] ?? null;
|
|
49
|
+
const parentConnection = activeOwner?.[5] ?? null;
|
|
50
|
+
let mounted = false;
|
|
51
|
+
return [
|
|
52
|
+
STRUCTURAL,
|
|
53
|
+
(parent, before) => {
|
|
54
|
+
if (mounted)
|
|
55
|
+
throw new Error(DEV ? 'compiled Activity is already mounted' : 'V008');
|
|
56
|
+
mounted = true;
|
|
57
|
+
const lifetimeOwner = activeOwner;
|
|
58
|
+
if (lifetimeOwner === null) {
|
|
59
|
+
throw new Error(DEV ? 'Activity must mount inside an owned compiled root' : 'V033');
|
|
60
|
+
}
|
|
61
|
+
const readMode = () => validateActivityMode(isCompiledBinding(modeInput) ? modeInput[1]() : modeInput);
|
|
62
|
+
let currentMode = readMode();
|
|
63
|
+
const connection = createRetainedConnection(parentConnection, currentMode === 'visible');
|
|
64
|
+
const childOwner = createOwner(context, rootIdentity, parentErrorBoundary, connection);
|
|
65
|
+
const hydratedRange = claimHydrationSlotRange(parent);
|
|
66
|
+
const start = hydratedRange?.[0] ?? document.createComment(DEV ? 'vidact:activity' : '');
|
|
67
|
+
const end = hydratedRange?.[1] ?? document.createComment(DEV ? '/vidact:activity' : '');
|
|
68
|
+
if (hydratedRange === undefined) {
|
|
69
|
+
parent.insertBefore(start, before);
|
|
70
|
+
parent.insertBefore(end, before);
|
|
71
|
+
}
|
|
72
|
+
const currentParent = rangeParent(start, end, 'Activity boundary');
|
|
73
|
+
const hiddenDisplays = new Map();
|
|
74
|
+
const hiddenTexts = new Map();
|
|
75
|
+
const heldText = document.createDocumentFragment();
|
|
76
|
+
let restoreHydratedDisplays = hydratedRange !== undefined && currentMode === 'hidden';
|
|
77
|
+
const conceal = () => {
|
|
78
|
+
for (const node of nodesBetween(start, end)) {
|
|
79
|
+
if (node instanceof Element && 'style' in node) {
|
|
80
|
+
const styled = node;
|
|
81
|
+
const previous = hiddenDisplays.get(node);
|
|
82
|
+
const hydratedDisplay = restoreHydratedDisplays
|
|
83
|
+
? readServerHiddenDisplay(node)
|
|
84
|
+
: undefined;
|
|
85
|
+
if (previous === undefined && hydratedDisplay !== undefined) {
|
|
86
|
+
hiddenDisplays.set(node, hydratedDisplay);
|
|
87
|
+
}
|
|
88
|
+
else if (previous === undefined ||
|
|
89
|
+
styled.style.display !== 'none' ||
|
|
90
|
+
styled.style.getPropertyPriority('display') !== 'important') {
|
|
91
|
+
hiddenDisplays.set(node, [
|
|
92
|
+
styled.style.display,
|
|
93
|
+
styled.style.getPropertyPriority('display'),
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
styled.style.setProperty('display', 'none', 'important');
|
|
97
|
+
}
|
|
98
|
+
else if (node instanceof Text && !hiddenTexts.has(node)) {
|
|
99
|
+
const placeholder = document.createComment(DEV ? 'vidact:activity-text' : '');
|
|
100
|
+
node.replaceWith(placeholder);
|
|
101
|
+
heldText.append(node);
|
|
102
|
+
hiddenTexts.set(node, placeholder);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
restoreHydratedDisplays = false;
|
|
106
|
+
};
|
|
107
|
+
const reveal = () => {
|
|
108
|
+
for (const [element, [display, priority]] of hiddenDisplays) {
|
|
109
|
+
const styled = element;
|
|
110
|
+
if (display === '')
|
|
111
|
+
styled.style.removeProperty('display');
|
|
112
|
+
else
|
|
113
|
+
styled.style.setProperty('display', display, priority);
|
|
114
|
+
}
|
|
115
|
+
hiddenDisplays.clear();
|
|
116
|
+
for (const [text, placeholder] of hiddenTexts) {
|
|
117
|
+
if (placeholder.parentNode !== null)
|
|
118
|
+
placeholder.replaceWith(text);
|
|
119
|
+
}
|
|
120
|
+
hiddenTexts.clear();
|
|
121
|
+
};
|
|
122
|
+
const setMode = (nextMode) => {
|
|
123
|
+
if (nextMode === currentMode)
|
|
124
|
+
return;
|
|
125
|
+
currentMode = nextMode;
|
|
126
|
+
if (nextMode === 'hidden') {
|
|
127
|
+
connection.visible = false;
|
|
128
|
+
updateRetainedConnection(connection);
|
|
129
|
+
conceal();
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
reveal();
|
|
133
|
+
connection.visible = true;
|
|
134
|
+
updateRetainedConnection(connection);
|
|
135
|
+
concealDisconnectedDescendants(connection);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
connection.afterFlush.add(conceal);
|
|
139
|
+
let stagedNodes = [];
|
|
140
|
+
try {
|
|
141
|
+
const [fragment, nodes] = hydratedRange === undefined
|
|
142
|
+
? stageRender(render, childOwner)
|
|
143
|
+
: withHydrationInsertion(currentParent, end, () => stageRender(render, childOwner));
|
|
144
|
+
stagedNodes = nodes;
|
|
145
|
+
currentParent.insertBefore(fragment, end);
|
|
146
|
+
if (currentMode === 'hidden')
|
|
147
|
+
conceal();
|
|
148
|
+
commitPublishedNodes(nodes);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
disposePublished(childOwner, stagedNodes);
|
|
152
|
+
disposeRetainedConnection(connection);
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
const removeModeUpdater = isCompiledBinding(modeInput)
|
|
156
|
+
? subscribeBinding(modeInput, () => setMode(readMode()))
|
|
157
|
+
: noop;
|
|
158
|
+
onCleanup(() => {
|
|
159
|
+
removeModeUpdater();
|
|
160
|
+
reveal();
|
|
161
|
+
try {
|
|
162
|
+
disposeRange(childOwner, start, end);
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
disposeRetainedConnection(connection);
|
|
166
|
+
start.remove();
|
|
167
|
+
end.remove();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
'slot',
|
|
172
|
+
];
|
|
173
|
+
}
|
|
174
|
+
/** @internal */
|
|
175
|
+
export function enableRetainedUi() {
|
|
176
|
+
retainedUiEnabled = true;
|
|
177
|
+
}
|
|
178
|
+
/** @internal */
|
|
179
|
+
export function enableProfiling() {
|
|
180
|
+
profilingEnabled = DEV;
|
|
181
|
+
}
|
|
182
|
+
/** @internal */
|
|
183
|
+
export function profiled(idInput, onRenderInput, render) {
|
|
184
|
+
if (!DEV)
|
|
185
|
+
return deferred(render);
|
|
186
|
+
noteHydrationStructuralParent();
|
|
187
|
+
const context = activeContextFrame ?? activeOwner?.[2] ?? null;
|
|
188
|
+
const rootIdentity = activeOwner?.[3] ?? activeRootIdentity;
|
|
189
|
+
if (rootIdentity === null) {
|
|
190
|
+
throw new Error(DEV ? 'Profiler must run during compiled root construction' : 'V035');
|
|
191
|
+
}
|
|
192
|
+
const parentErrorBoundary = activeOwner?.[4] ?? null;
|
|
193
|
+
const parentConnection = activeOwner?.[5] ?? null;
|
|
194
|
+
const parentProfile = activeOwner?.[6] ?? null;
|
|
195
|
+
let mounted = false;
|
|
196
|
+
return [
|
|
197
|
+
STRUCTURAL,
|
|
198
|
+
(parent, before) => {
|
|
199
|
+
if (mounted)
|
|
200
|
+
throw new Error(DEV ? 'compiled Profiler is already mounted' : 'V008');
|
|
201
|
+
mounted = true;
|
|
202
|
+
const readId = () => {
|
|
203
|
+
const id = isCompiledBinding(idInput) ? idInput[1]() : idInput;
|
|
204
|
+
if (typeof id !== 'string')
|
|
205
|
+
throw new TypeError('Profiler id must be a string');
|
|
206
|
+
return id;
|
|
207
|
+
};
|
|
208
|
+
const readOnRender = () => {
|
|
209
|
+
const onRender = isCompiledBinding(onRenderInput) ? onRenderInput[1]() : onRenderInput;
|
|
210
|
+
if (typeof onRender !== 'function') {
|
|
211
|
+
throw new TypeError('Profiler onRender must be a function');
|
|
212
|
+
}
|
|
213
|
+
return onRender;
|
|
214
|
+
};
|
|
215
|
+
const boundary = {
|
|
216
|
+
parent: parentProfile?.boundary ?? null,
|
|
217
|
+
id: readId(),
|
|
218
|
+
onRender: readOnRender(),
|
|
219
|
+
baseDuration: 0,
|
|
220
|
+
mounted: false,
|
|
221
|
+
pendingDuration: 0,
|
|
222
|
+
pendingStart: 0,
|
|
223
|
+
scheduled: false,
|
|
224
|
+
};
|
|
225
|
+
const childOwner = createOwner(context, rootIdentity, parentErrorBoundary, parentConnection, {
|
|
226
|
+
frame: parentProfile?.frame ?? null,
|
|
227
|
+
boundary,
|
|
228
|
+
});
|
|
229
|
+
const hydratedRange = claimHydrationSlotRange(parent);
|
|
230
|
+
const start = hydratedRange?.[0] ?? document.createComment(DEV ? 'vidact:profiler' : '');
|
|
231
|
+
const end = hydratedRange?.[1] ?? document.createComment(DEV ? '/vidact:profiler' : '');
|
|
232
|
+
if (hydratedRange === undefined) {
|
|
233
|
+
parent.insertBefore(start, before);
|
|
234
|
+
parent.insertBefore(end, before);
|
|
235
|
+
}
|
|
236
|
+
const currentParent = rangeParent(start, end, 'Profiler boundary');
|
|
237
|
+
let stagedNodes = [];
|
|
238
|
+
const started = profileNow();
|
|
239
|
+
try {
|
|
240
|
+
const [fragment, nodes] = hydratedRange === undefined
|
|
241
|
+
? stageRender(render, childOwner)
|
|
242
|
+
: withHydrationInsertion(currentParent, end, () => stageRender(render, childOwner));
|
|
243
|
+
stagedNodes = nodes;
|
|
244
|
+
currentParent.insertBefore(fragment, end);
|
|
245
|
+
commitPublishedNodes(nodes);
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
disposePublished(childOwner, stagedNodes);
|
|
249
|
+
throw error;
|
|
250
|
+
}
|
|
251
|
+
const finished = profileNow();
|
|
252
|
+
boundary.baseDuration = finished - started;
|
|
253
|
+
boundary.mounted = true;
|
|
254
|
+
emitProfileMeasure(childOwner, 'range', started, finished);
|
|
255
|
+
runOwnerTask(childOwner, () => boundary.onRender(boundary.id, 'mount', boundary.baseDuration, boundary.baseDuration, started, finished));
|
|
256
|
+
const removeIdUpdater = isCompiledBinding(idInput)
|
|
257
|
+
? subscribeBinding(idInput, () => {
|
|
258
|
+
boundary.id = readId();
|
|
259
|
+
})
|
|
260
|
+
: noop;
|
|
261
|
+
const removeCallbackUpdater = isCompiledBinding(onRenderInput)
|
|
262
|
+
? subscribeBinding(onRenderInput, () => {
|
|
263
|
+
boundary.onRender = readOnRender();
|
|
264
|
+
})
|
|
265
|
+
: noop;
|
|
266
|
+
onCleanup(() => {
|
|
267
|
+
removeCallbackUpdater();
|
|
268
|
+
removeIdUpdater();
|
|
269
|
+
disposeRange(childOwner, start, end);
|
|
270
|
+
});
|
|
271
|
+
},
|
|
272
|
+
'slot',
|
|
273
|
+
];
|
|
274
|
+
}
|
|
275
|
+
/** @internal */
|
|
276
|
+
export function recordCompiledDebugValue(valueInput, format) {
|
|
277
|
+
if (!profilingEnabled)
|
|
278
|
+
return;
|
|
279
|
+
const owner = activeConstructionOwner ?? activeOwner;
|
|
280
|
+
if (owner === null) {
|
|
281
|
+
throw new Error(DEV ? 'useDebugValue must run inside a compiled component' : 'V036');
|
|
282
|
+
}
|
|
283
|
+
const frame = ensureProfileContext(owner).frame;
|
|
284
|
+
if (frame === null) {
|
|
285
|
+
throw new Error(DEV ? 'useDebugValue must run inside a compiled component' : 'V036');
|
|
286
|
+
}
|
|
287
|
+
const read = () => {
|
|
288
|
+
const value = isCompiledBinding(valueInput) ? valueInput[1]() : valueInput;
|
|
289
|
+
return format === undefined ? value : format(value);
|
|
290
|
+
};
|
|
291
|
+
const index = frame.values.length;
|
|
292
|
+
frame.values.push(read());
|
|
293
|
+
if (isCompiledBinding(valueInput)) {
|
|
294
|
+
const remove = subscribeBinding(valueInput, () => {
|
|
295
|
+
frame.values[index] = read();
|
|
296
|
+
});
|
|
297
|
+
owner[1].add(remove);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/** @internal */
|
|
301
|
+
export function captureCompiledOwnerStack() {
|
|
302
|
+
if (!profilingEnabled)
|
|
303
|
+
return null;
|
|
304
|
+
const owner = activeConstructionOwner ?? activeOwner;
|
|
305
|
+
let frame = owner === null ? null : ensureProfileContext(owner).frame;
|
|
306
|
+
if (frame === null)
|
|
307
|
+
return null;
|
|
308
|
+
const lines = [];
|
|
309
|
+
while (frame !== null) {
|
|
310
|
+
const values = frame.values.length === 0 ? '' : ` [${frame.values.map(String).join(', ')}]`;
|
|
311
|
+
lines.push(`\n at ${frame.name}${values}`);
|
|
312
|
+
frame = frame.parent;
|
|
313
|
+
}
|
|
314
|
+
return lines.join('');
|
|
315
|
+
}
|
|
316
|
+
function validateActivityMode(mode) {
|
|
317
|
+
if (mode === 'visible' || mode === 'hidden')
|
|
318
|
+
return mode;
|
|
319
|
+
throw new TypeError(DEV ? 'Activity mode must be "visible" or "hidden"' : 'V034');
|
|
320
|
+
}
|
|
321
|
+
function readServerHiddenDisplay(element) {
|
|
322
|
+
const cssText = element.getAttribute('style');
|
|
323
|
+
const hiddenDeclaration = 'display:none!important';
|
|
324
|
+
if (cssText === null || !cssText.endsWith(hiddenDeclaration))
|
|
325
|
+
return undefined;
|
|
326
|
+
let authoredCssText = cssText.slice(0, -hiddenDeclaration.length);
|
|
327
|
+
if (authoredCssText.endsWith(';'))
|
|
328
|
+
authoredCssText = authoredCssText.slice(0, -1);
|
|
329
|
+
const style = document.createElement('div').style;
|
|
330
|
+
style.cssText = authoredCssText;
|
|
331
|
+
return [style.display, style.getPropertyPriority('display')];
|
|
332
|
+
}
|
|
333
|
+
export function errorBoundary(render, fallback, onError) {
|
|
334
|
+
noteHydrationStructuralParent();
|
|
335
|
+
const context = activeContextFrame ?? activeOwner?.[2] ?? null;
|
|
336
|
+
const rootIdentity = activeOwner?.[3] ?? activeRootIdentity;
|
|
337
|
+
if (rootIdentity === null) {
|
|
338
|
+
throw new Error(DEV ? 'errorBoundary must run during compiled root construction' : 'V028');
|
|
339
|
+
}
|
|
340
|
+
const parentBoundary = activeOwner?.[4] ?? null;
|
|
341
|
+
let mounted = false;
|
|
342
|
+
return [
|
|
343
|
+
STRUCTURAL,
|
|
344
|
+
(parent, before) => {
|
|
345
|
+
if (mounted)
|
|
346
|
+
throw new Error(DEV ? 'compiled error boundary is already mounted' : 'V008');
|
|
347
|
+
mounted = true;
|
|
348
|
+
const hydratedRange = claimHydrationSlotRange(parent);
|
|
349
|
+
const start = hydratedRange?.[0] ?? document.createComment(DEV ? 'vidact:error' : '');
|
|
350
|
+
const end = hydratedRange?.[1] ?? document.createComment(DEV ? '/vidact:error' : '');
|
|
351
|
+
if (hydratedRange === undefined) {
|
|
352
|
+
parent.insertBefore(start, before);
|
|
353
|
+
parent.insertBefore(end, before);
|
|
354
|
+
}
|
|
355
|
+
let currentOwner = null;
|
|
356
|
+
let currentNodes = [];
|
|
357
|
+
let failed = false;
|
|
358
|
+
const publish = (read, boundary) => {
|
|
359
|
+
const currentParent = rangeParent(start, end, 'error boundary');
|
|
360
|
+
const nextOwner = createOwner(context, rootIdentity, boundary);
|
|
361
|
+
const [fragment, nodes] = hydratedRange === undefined
|
|
362
|
+
? stageRender(read, nextOwner)
|
|
363
|
+
: withHydrationInsertion(currentParent, end, () => stageRender(read, nextOwner));
|
|
364
|
+
try {
|
|
365
|
+
currentParent.insertBefore(fragment, end);
|
|
366
|
+
commitPublishedNodes(nodes);
|
|
367
|
+
}
|
|
368
|
+
catch (error) {
|
|
369
|
+
disposePublished(nextOwner, nodes);
|
|
370
|
+
throw error;
|
|
371
|
+
}
|
|
372
|
+
const previousOwner = currentOwner;
|
|
373
|
+
const previousNodes = currentNodes;
|
|
374
|
+
currentOwner = nextOwner;
|
|
375
|
+
currentNodes = nodes;
|
|
376
|
+
disposePublished(previousOwner, previousNodes);
|
|
377
|
+
};
|
|
378
|
+
const reset = () => {
|
|
379
|
+
if (!failed)
|
|
380
|
+
return;
|
|
381
|
+
try {
|
|
382
|
+
failed = false;
|
|
383
|
+
publish(render, boundary);
|
|
384
|
+
}
|
|
385
|
+
catch (error) {
|
|
386
|
+
recover(error);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
const recover = (error) => {
|
|
390
|
+
failed = true;
|
|
391
|
+
publish(() => fallback(error, reset), parentBoundary);
|
|
392
|
+
onError?.(error);
|
|
393
|
+
rootIdentity.onCaughtError?.(error);
|
|
394
|
+
};
|
|
395
|
+
const boundary = { handle: recover, parent: parentBoundary };
|
|
396
|
+
try {
|
|
397
|
+
publish(render, boundary);
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
recover(error);
|
|
401
|
+
}
|
|
402
|
+
onCleanup(() => {
|
|
403
|
+
try {
|
|
404
|
+
disposePublished(currentOwner, currentNodes);
|
|
405
|
+
}
|
|
406
|
+
finally {
|
|
407
|
+
start.remove();
|
|
408
|
+
end.remove();
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
},
|
|
412
|
+
'slot',
|
|
413
|
+
];
|
|
414
|
+
}
|
|
415
|
+
export function suspense(render, fallback) {
|
|
416
|
+
noteHydrationStructuralParent();
|
|
417
|
+
const context = activeContextFrame ?? activeOwner?.[2] ?? null;
|
|
418
|
+
const rootIdentity = activeOwner?.[3] ?? activeRootIdentity;
|
|
419
|
+
if (rootIdentity === null) {
|
|
420
|
+
throw new Error(DEV ? 'Suspense must run during compiled root construction' : 'V032');
|
|
421
|
+
}
|
|
422
|
+
const parentErrorBoundary = activeOwner?.[4] ?? null;
|
|
423
|
+
let mounted = false;
|
|
424
|
+
return [
|
|
425
|
+
STRUCTURAL,
|
|
426
|
+
(parent, before) => {
|
|
427
|
+
if (mounted)
|
|
428
|
+
throw new Error(DEV ? 'compiled Suspense boundary is already mounted' : 'V008');
|
|
429
|
+
mounted = true;
|
|
430
|
+
const lifetimeOwner = activeOwner;
|
|
431
|
+
if (lifetimeOwner === null) {
|
|
432
|
+
throw new Error(DEV ? 'Suspense must mount inside an owned compiled root' : 'V032');
|
|
433
|
+
}
|
|
434
|
+
const hydratedRange = claimHydrationSlotRange(parent);
|
|
435
|
+
const start = hydratedRange?.[0] ?? document.createComment(DEV ? 'vidact:suspense' : '');
|
|
436
|
+
const end = hydratedRange?.[1] ?? document.createComment(DEV ? '/vidact:suspense' : '');
|
|
437
|
+
if (hydratedRange === undefined) {
|
|
438
|
+
parent.insertBefore(start, before);
|
|
439
|
+
parent.insertBefore(end, before);
|
|
440
|
+
}
|
|
441
|
+
const pendingMarker = hydratedRange === undefined ? undefined : claimHydrationSuspenseFallback(parent);
|
|
442
|
+
let currentOwner = null;
|
|
443
|
+
let currentNodes = [];
|
|
444
|
+
let currentKind = null;
|
|
445
|
+
let removeResourceListener = noop;
|
|
446
|
+
let generation = 0;
|
|
447
|
+
let boundary;
|
|
448
|
+
const publish = (read, kind, detachedHydrationProbe = false) => {
|
|
449
|
+
const currentParent = rangeParent(start, end, 'Suspense boundary');
|
|
450
|
+
const nextOwner = createOwner(context, rootIdentity, kind === 'content' ? boundary : parentErrorBoundary);
|
|
451
|
+
const serverNodes = detachedHydrationProbe ? nodesBetween(start, end) : [];
|
|
452
|
+
const [fragment, nodes] = detachedHydrationProbe
|
|
453
|
+
? withoutHydration(() => stageRender(read, nextOwner))
|
|
454
|
+
: hydratedRange === undefined || currentKind !== null
|
|
455
|
+
? stageRender(read, nextOwner)
|
|
456
|
+
: withHydrationInsertion(currentParent, end, () => stageRender(read, nextOwner));
|
|
457
|
+
try {
|
|
458
|
+
currentParent.insertBefore(fragment, end);
|
|
459
|
+
commitPublishedNodes(nodes);
|
|
460
|
+
}
|
|
461
|
+
catch (error) {
|
|
462
|
+
disposePublished(nextOwner, nodes);
|
|
463
|
+
throw error;
|
|
464
|
+
}
|
|
465
|
+
const previousOwner = currentOwner;
|
|
466
|
+
const previousNodes = currentNodes;
|
|
467
|
+
currentOwner = nextOwner;
|
|
468
|
+
currentNodes = nodes;
|
|
469
|
+
currentKind = kind;
|
|
470
|
+
disposePublished(previousOwner, previousNodes);
|
|
471
|
+
for (const node of serverNodes)
|
|
472
|
+
node.parentNode?.removeChild(node);
|
|
473
|
+
};
|
|
474
|
+
const beginAttempt = () => {
|
|
475
|
+
const attemptGeneration = ++generation;
|
|
476
|
+
removeResourceListener();
|
|
477
|
+
removeResourceListener = noop;
|
|
478
|
+
return attemptGeneration;
|
|
479
|
+
};
|
|
480
|
+
const suspend = (failure, attemptGeneration) => {
|
|
481
|
+
if (!isSuspension(failure))
|
|
482
|
+
throw failure;
|
|
483
|
+
const retry = () => {
|
|
484
|
+
if (lifetimeOwner[0] || attemptGeneration !== generation)
|
|
485
|
+
return;
|
|
486
|
+
runOwnerTask(lifetimeOwner, () => attempt(false));
|
|
487
|
+
};
|
|
488
|
+
removeResourceListener = subscribeResource(failure.resource, retry);
|
|
489
|
+
if (currentKind !== 'fallback') {
|
|
490
|
+
try {
|
|
491
|
+
publish(fallback, 'fallback');
|
|
492
|
+
if (pendingMarker !== undefined) {
|
|
493
|
+
currentNodes = [pendingMarker, ...currentNodes];
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
catch (fallbackError) {
|
|
497
|
+
removeResourceListener();
|
|
498
|
+
removeResourceListener = noop;
|
|
499
|
+
throw fallbackError;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
const attempt = (initial) => {
|
|
504
|
+
const attemptGeneration = beginAttempt();
|
|
505
|
+
try {
|
|
506
|
+
publish(render, 'content', initial && pendingMarker !== undefined);
|
|
507
|
+
}
|
|
508
|
+
catch (error) {
|
|
509
|
+
if (!isSuspension(error)) {
|
|
510
|
+
if (initial || !routeOwnerError(lifetimeOwner, error))
|
|
511
|
+
throw error;
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
suspend(error, attemptGeneration);
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
boundary = {
|
|
518
|
+
handle: (error) => suspend(error, beginAttempt()),
|
|
519
|
+
parent: parentErrorBoundary,
|
|
520
|
+
};
|
|
521
|
+
attempt(true);
|
|
522
|
+
onCleanup(() => {
|
|
523
|
+
generation += 1;
|
|
524
|
+
removeResourceListener();
|
|
525
|
+
try {
|
|
526
|
+
disposePublished(currentOwner, currentNodes);
|
|
527
|
+
}
|
|
528
|
+
finally {
|
|
529
|
+
start.remove();
|
|
530
|
+
end.remove();
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
},
|
|
534
|
+
'slot',
|
|
535
|
+
];
|
|
536
|
+
}
|
|
537
|
+
export function createPortal(children, container, _key) {
|
|
538
|
+
if (!(container instanceof Node) || typeof container.insertBefore !== 'function') {
|
|
539
|
+
throw new TypeError(DEV ? 'createPortal requires a DOM container' : 'V026');
|
|
540
|
+
}
|
|
541
|
+
const context = activeContextFrame ?? activeOwner?.[2] ?? null;
|
|
542
|
+
const rootIdentity = activeOwner?.[3] ?? activeRootIdentity;
|
|
543
|
+
if (rootIdentity === null) {
|
|
544
|
+
throw new Error(DEV ? 'createPortal must run during compiled root construction' : 'V027');
|
|
545
|
+
}
|
|
546
|
+
let mounted = false;
|
|
547
|
+
return [
|
|
548
|
+
STRUCTURAL,
|
|
549
|
+
(logicalParent, before) => {
|
|
550
|
+
if (mounted)
|
|
551
|
+
throw new Error(DEV ? 'compiled portal is already mounted' : 'V008');
|
|
552
|
+
mounted = true;
|
|
553
|
+
const logicalMarker = document.createComment(DEV ? 'vidact:portal' : '');
|
|
554
|
+
logicalParent.insertBefore(logicalMarker, before);
|
|
555
|
+
const start = document.createComment(DEV ? 'vidact:portal:start' : '');
|
|
556
|
+
const end = document.createComment(DEV ? 'vidact:portal:end' : '');
|
|
557
|
+
const fragment = document.createDocumentFragment();
|
|
558
|
+
fragment.append(start, end);
|
|
559
|
+
const portalOwner = withRootIdentity(rootIdentity, () => withContextFrame(context, createOwner));
|
|
560
|
+
try {
|
|
561
|
+
withOwner(portalOwner, () => insertValue(fragment, children, end));
|
|
562
|
+
}
|
|
563
|
+
catch (error) {
|
|
564
|
+
disposeOwner(portalOwner);
|
|
565
|
+
logicalMarker.remove();
|
|
566
|
+
throw error;
|
|
567
|
+
}
|
|
568
|
+
const rollback = () => {
|
|
569
|
+
removeBetween(start, end);
|
|
570
|
+
start.remove();
|
|
571
|
+
end.remove();
|
|
572
|
+
};
|
|
573
|
+
const publication = [
|
|
574
|
+
() => {
|
|
575
|
+
container.insertBefore(fragment, null);
|
|
576
|
+
try {
|
|
577
|
+
commitRangeRefs(start, end);
|
|
578
|
+
}
|
|
579
|
+
catch (error) {
|
|
580
|
+
rollback();
|
|
581
|
+
throw error;
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
rollback,
|
|
585
|
+
];
|
|
586
|
+
if (rootIdentity.mounted) {
|
|
587
|
+
stagePublication([publication[0], publication[1], () => disposeOwner(portalOwner)]);
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
let pending = pendingRootPortals.get(rootIdentity);
|
|
591
|
+
if (pending === undefined) {
|
|
592
|
+
pending = new Set();
|
|
593
|
+
pendingRootPortals.set(rootIdentity, pending);
|
|
594
|
+
}
|
|
595
|
+
pending.add(publication);
|
|
596
|
+
}
|
|
597
|
+
onCleanup(() => {
|
|
598
|
+
pendingRootPortals.get(rootIdentity)?.delete(publication);
|
|
599
|
+
try {
|
|
600
|
+
disposeOwner(portalOwner);
|
|
601
|
+
}
|
|
602
|
+
finally {
|
|
603
|
+
publication[1]();
|
|
604
|
+
logicalMarker.remove();
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
},
|
|
608
|
+
];
|
|
609
|
+
}
|
|
610
|
+
let activeOwner = null;
|
|
611
|
+
let activeContextFrame = null;
|
|
612
|
+
let activeRootIdentity = null;
|
|
613
|
+
let nextClientRoot = 0;
|
|
614
|
+
let activeScopeCollector = null;
|
|
615
|
+
let activeConstructionOwner = null;
|
|
616
|
+
let activeProfileName = null;
|
|
617
|
+
let activeErrorOwner = null;
|
|
618
|
+
let failedOwner = null;
|
|
619
|
+
let transactionDepth = 0;
|
|
620
|
+
let drainingFlushes = false;
|
|
621
|
+
let activePublication = null;
|
|
622
|
+
const scheduledFlushes = new Set();
|
|
623
|
+
const scopeOwners = new WeakMap();
|
|
624
|
+
const scopeNamespaces = new WeakMap();
|
|
625
|
+
const componentRanges = new WeakMap();
|
|
626
|
+
const pendingRefs = new WeakMap();
|
|
627
|
+
const componentCommitOwners = new WeakMap();
|
|
628
|
+
const pendingInsertionCommits = new WeakMap();
|
|
629
|
+
const pendingOwnerCommits = new WeakMap();
|
|
630
|
+
const pendingRootPortals = new WeakMap();
|
|
631
|
+
export function createCompiledScope() {
|
|
632
|
+
return createScope(wideSourceOperations);
|
|
633
|
+
}
|
|
634
|
+
export function createNarrowCompiledScope() {
|
|
635
|
+
return createScope(narrowSourceOperations);
|
|
636
|
+
}
|
|
637
|
+
export function runCompiledTransaction(operation) {
|
|
638
|
+
transactionDepth += 1;
|
|
639
|
+
try {
|
|
640
|
+
return operation();
|
|
641
|
+
}
|
|
642
|
+
finally {
|
|
643
|
+
transactionDepth -= 1;
|
|
644
|
+
if (transactionDepth === 0)
|
|
645
|
+
drainFlushes();
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function createScope(operations) {
|
|
649
|
+
const namespace = currentIntrinsicNamespace();
|
|
650
|
+
const owner = createOwner();
|
|
651
|
+
const updaters = [];
|
|
652
|
+
const freeUpdaterIndexes = [];
|
|
653
|
+
const addedDuringFlush = new Set();
|
|
654
|
+
let batchDepth = 0;
|
|
655
|
+
let flushing = false;
|
|
656
|
+
let pending = 0;
|
|
657
|
+
const flush = () => {
|
|
658
|
+
if (owner[0] || flushing)
|
|
659
|
+
return;
|
|
660
|
+
const operation = () => {
|
|
661
|
+
flushing = true;
|
|
662
|
+
try {
|
|
663
|
+
let pass = 0;
|
|
664
|
+
while (!operations[0](pending)) {
|
|
665
|
+
pass += 1;
|
|
666
|
+
if (pass > MAX_FLUSH_PASSES) {
|
|
667
|
+
pending = 0;
|
|
668
|
+
throw new Error(DEV ? 'Vidact compiled scope did not stabilize' : 'V001');
|
|
669
|
+
}
|
|
670
|
+
let active = pending;
|
|
671
|
+
pending = 0;
|
|
672
|
+
const updaterCount = updaters.length;
|
|
673
|
+
for (let index = 0; index < updaterCount; index += 1) {
|
|
674
|
+
const updater = updaters[index];
|
|
675
|
+
if (updater === undefined ||
|
|
676
|
+
addedDuringFlush.has(updater) ||
|
|
677
|
+
!updater[3] ||
|
|
678
|
+
!operations[1](active, updater[0])) {
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
if (profilingEnabled) {
|
|
682
|
+
measureProfileWork(owner, 'updater', () => updater[2](active));
|
|
683
|
+
}
|
|
684
|
+
else {
|
|
685
|
+
updater[2](active);
|
|
686
|
+
}
|
|
687
|
+
if (updater[1] !== undefined)
|
|
688
|
+
active = operations[2](active, updater[1]);
|
|
689
|
+
}
|
|
690
|
+
addedDuringFlush.clear();
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
finally {
|
|
694
|
+
addedDuringFlush.clear();
|
|
695
|
+
flushing = false;
|
|
696
|
+
}
|
|
697
|
+
if (retainedUiEnabled)
|
|
698
|
+
notifyRetainedFlush(owner[5] ?? null);
|
|
699
|
+
};
|
|
700
|
+
if (profilingEnabled)
|
|
701
|
+
measureProfileWork(owner, 'scheduler', operation, true);
|
|
702
|
+
else
|
|
703
|
+
operation();
|
|
704
|
+
};
|
|
705
|
+
const scope = [
|
|
706
|
+
(reads, run, writes) => {
|
|
707
|
+
if (owner[0]) {
|
|
708
|
+
throw new Error(DEV ? 'cannot add an updater to a disposed scope' : 'V002');
|
|
709
|
+
}
|
|
710
|
+
const errorOwner = activeOwner ?? owner;
|
|
711
|
+
const context = activeContextFrame ?? errorOwner[2];
|
|
712
|
+
const entry = [
|
|
713
|
+
reads,
|
|
714
|
+
writes,
|
|
715
|
+
(active) => {
|
|
716
|
+
try {
|
|
717
|
+
withOwner(errorOwner, () => withContextFrame(context, () => withScopeNamespace(scope, () => run(active))));
|
|
718
|
+
}
|
|
719
|
+
catch (error) {
|
|
720
|
+
if (!routeOwnerError(errorOwner, error)) {
|
|
721
|
+
failedOwner = errorOwner;
|
|
722
|
+
throw error;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
},
|
|
726
|
+
true,
|
|
727
|
+
];
|
|
728
|
+
const reusableIndex = freeUpdaterIndexes.pop();
|
|
729
|
+
const index = reusableIndex ?? updaters.length;
|
|
730
|
+
updaters[index] = entry;
|
|
731
|
+
if (flushing)
|
|
732
|
+
addedDuringFlush.add(entry);
|
|
733
|
+
const remove = () => {
|
|
734
|
+
if (updaters[index] !== entry)
|
|
735
|
+
return;
|
|
736
|
+
entry[3] = false;
|
|
737
|
+
updaters[index] = undefined;
|
|
738
|
+
freeUpdaterIndexes.push(index);
|
|
739
|
+
};
|
|
740
|
+
if (activeOwner !== null && activeOwner !== owner)
|
|
741
|
+
activeOwner[1].add(remove);
|
|
742
|
+
return remove;
|
|
743
|
+
},
|
|
744
|
+
(sources) => {
|
|
745
|
+
if (owner[0] || operations[0](sources))
|
|
746
|
+
return;
|
|
747
|
+
pending = operations[2](pending, sources);
|
|
748
|
+
if (batchDepth === 0) {
|
|
749
|
+
if (retainedUiEnabled)
|
|
750
|
+
scheduleOwnerFlush(owner, flush);
|
|
751
|
+
else
|
|
752
|
+
scheduleFlush(flush);
|
|
753
|
+
}
|
|
754
|
+
},
|
|
755
|
+
(operation) => {
|
|
756
|
+
batchDepth += 1;
|
|
757
|
+
transactionDepth += 1;
|
|
758
|
+
try {
|
|
759
|
+
return operation();
|
|
760
|
+
}
|
|
761
|
+
finally {
|
|
762
|
+
batchDepth -= 1;
|
|
763
|
+
if (batchDepth === 0 && !operations[0](pending)) {
|
|
764
|
+
if (retainedUiEnabled)
|
|
765
|
+
scheduleOwnerFlush(owner, flush);
|
|
766
|
+
else
|
|
767
|
+
scheduleFlush(flush);
|
|
768
|
+
}
|
|
769
|
+
transactionDepth -= 1;
|
|
770
|
+
if (transactionDepth === 0)
|
|
771
|
+
drainFlushes();
|
|
772
|
+
}
|
|
773
|
+
},
|
|
774
|
+
() => {
|
|
775
|
+
if (owner[0])
|
|
776
|
+
return;
|
|
777
|
+
try {
|
|
778
|
+
disposeOwner(owner);
|
|
779
|
+
}
|
|
780
|
+
finally {
|
|
781
|
+
pending = 0;
|
|
782
|
+
for (const updater of updaters) {
|
|
783
|
+
if (updater !== undefined)
|
|
784
|
+
updater[3] = false;
|
|
785
|
+
}
|
|
786
|
+
updaters.length = 0;
|
|
787
|
+
freeUpdaterIndexes.length = 0;
|
|
788
|
+
addedDuringFlush.clear();
|
|
789
|
+
}
|
|
790
|
+
},
|
|
791
|
+
];
|
|
792
|
+
scopeOwners.set(scope, owner);
|
|
793
|
+
scopeNamespaces.set(scope, namespace);
|
|
794
|
+
activeScopeCollector?.add(scope);
|
|
795
|
+
if (activeScopeCollector !== null)
|
|
796
|
+
activeConstructionOwner = owner;
|
|
797
|
+
return scope;
|
|
798
|
+
}
|
|
799
|
+
export function createCompiledState(scope, sourceMask, initialValue) {
|
|
800
|
+
const assertWritable = stateWriteGuard(scope);
|
|
801
|
+
const value = typeof initialValue === 'function' ? initialValue() : initialValue;
|
|
802
|
+
return createStateSlot(scope[1], sourceMask, value, assertWritable);
|
|
803
|
+
}
|
|
804
|
+
export function createCompiledReducer(scope, sourceMask, reducer, initialArg, initialize) {
|
|
805
|
+
const state = createStateSlot(scope[1], sourceMask, initialize === undefined ? initialArg : initialize(initialArg), stateWriteGuard(scope));
|
|
806
|
+
return {
|
|
807
|
+
get: state.get,
|
|
808
|
+
set: (action) => state.set((previous) => reducer(previous, action)),
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
export function createCompiledMemo(scope, reads, writes, evaluate, readDependencies) {
|
|
812
|
+
let currentDependencies = readDependencies();
|
|
813
|
+
const slot = createStateSlot(scope[1], writes, evaluate(), stateWriteGuard(scope));
|
|
814
|
+
const removeUpdater = scope[0](reads, () => {
|
|
815
|
+
const nextDependencies = readDependencies();
|
|
816
|
+
if (equalDependencies(nextDependencies, currentDependencies))
|
|
817
|
+
return;
|
|
818
|
+
slot.replace(evaluate());
|
|
819
|
+
currentDependencies = nextDependencies;
|
|
820
|
+
});
|
|
821
|
+
const owner = scopeOwners.get(scope);
|
|
822
|
+
if (owner === undefined) {
|
|
823
|
+
removeUpdater();
|
|
824
|
+
throw new Error(DEV ? 'createCompiledMemo received an unknown scope' : 'V003');
|
|
825
|
+
}
|
|
826
|
+
owner[1].add(removeUpdater);
|
|
827
|
+
return slot;
|
|
828
|
+
}
|
|
829
|
+
export function createContext(defaultValue) {
|
|
830
|
+
let context;
|
|
831
|
+
const provider = ((props) => provideContext(context, props.value, props.children));
|
|
832
|
+
context = provider;
|
|
833
|
+
context.Provider = provider;
|
|
834
|
+
Object.defineProperty(context, CONTEXT, { value: defaultValue });
|
|
835
|
+
return context;
|
|
836
|
+
}
|
|
837
|
+
/** @internal */
|
|
838
|
+
export function runWithCompiledContext(context, value, operation) {
|
|
839
|
+
const parent = activeContextFrame ?? activeOwner?.[2] ?? null;
|
|
840
|
+
return withContextFrame({ context: context, input: value, parent }, operation);
|
|
841
|
+
}
|
|
842
|
+
export function createCompiledContext(scope, sourceMask, context) {
|
|
843
|
+
const input = contextInput(scope, context);
|
|
844
|
+
return createCompiledProp(scope, sourceMask, input);
|
|
845
|
+
}
|
|
846
|
+
export function createCompiledExternalStore(scope, sourceMask, storeSubscribe, getSnapshot, _getServerSnapshot) {
|
|
847
|
+
const owner = scopeOwners.get(scope);
|
|
848
|
+
if (owner === undefined) {
|
|
849
|
+
throw new Error(DEV ? 'createCompiledExternalStore received an unknown scope' : 'V003');
|
|
850
|
+
}
|
|
851
|
+
const slot = createStateSlot(scope[1], sourceMask, getSnapshot(), stateWriteGuard(scope));
|
|
852
|
+
if (!retainedUiEnabled) {
|
|
853
|
+
let active = true;
|
|
854
|
+
const checkSnapshot = () => {
|
|
855
|
+
if (!active)
|
|
856
|
+
return;
|
|
857
|
+
scope[2](() => slot.replace(getSnapshot()));
|
|
858
|
+
};
|
|
859
|
+
const unsubscribe = storeSubscribe(() => runOwnerTask(owner, checkSnapshot));
|
|
860
|
+
if (typeof unsubscribe !== 'function') {
|
|
861
|
+
active = false;
|
|
862
|
+
throw new TypeError(DEV ? 'external store subscribe must return an unsubscribe function' : 'V020');
|
|
863
|
+
}
|
|
864
|
+
try {
|
|
865
|
+
checkSnapshot();
|
|
866
|
+
}
|
|
867
|
+
catch (error) {
|
|
868
|
+
active = false;
|
|
869
|
+
unsubscribe();
|
|
870
|
+
throw error;
|
|
871
|
+
}
|
|
872
|
+
owner[1].add(() => {
|
|
873
|
+
active = false;
|
|
874
|
+
unsubscribe();
|
|
875
|
+
});
|
|
876
|
+
return slot;
|
|
877
|
+
}
|
|
878
|
+
let active = false;
|
|
879
|
+
let unsubscribe = noop;
|
|
880
|
+
const checkSnapshot = () => {
|
|
881
|
+
if (!active)
|
|
882
|
+
return;
|
|
883
|
+
scope[2](() => slot.replace(getSnapshot()));
|
|
884
|
+
};
|
|
885
|
+
const [activate, disposeResource] = createRetainedResource(owner, () => {
|
|
886
|
+
active = true;
|
|
887
|
+
try {
|
|
888
|
+
const remove = storeSubscribe(() => runOwnerTask(owner, checkSnapshot));
|
|
889
|
+
if (typeof remove !== 'function') {
|
|
890
|
+
throw new TypeError(DEV ? 'external store subscribe must return an unsubscribe function' : 'V020');
|
|
891
|
+
}
|
|
892
|
+
unsubscribe = remove;
|
|
893
|
+
checkSnapshot();
|
|
894
|
+
}
|
|
895
|
+
catch (error) {
|
|
896
|
+
active = false;
|
|
897
|
+
unsubscribe();
|
|
898
|
+
unsubscribe = noop;
|
|
899
|
+
throw error;
|
|
900
|
+
}
|
|
901
|
+
}, () => {
|
|
902
|
+
active = false;
|
|
903
|
+
unsubscribe();
|
|
904
|
+
unsubscribe = noop;
|
|
905
|
+
}, 0);
|
|
906
|
+
try {
|
|
907
|
+
activate();
|
|
908
|
+
}
|
|
909
|
+
catch (error) {
|
|
910
|
+
disposeResource();
|
|
911
|
+
throw error;
|
|
912
|
+
}
|
|
913
|
+
owner[1].add(() => {
|
|
914
|
+
disposeResource();
|
|
915
|
+
});
|
|
916
|
+
return slot;
|
|
917
|
+
}
|
|
918
|
+
export function createCompiledEffectEvent(scope, callback) {
|
|
919
|
+
const owner = scopeOwners.get(scope);
|
|
920
|
+
if (owner === undefined) {
|
|
921
|
+
throw new Error(DEV ? 'createCompiledEffectEvent received an unknown scope' : 'V003');
|
|
922
|
+
}
|
|
923
|
+
return (...arguments_) => {
|
|
924
|
+
if (owner[0])
|
|
925
|
+
throw new Error(DEV ? 'cannot call an effect event after disposal' : 'V022');
|
|
926
|
+
return callback(...arguments_);
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
export function createCompiledId(scope) {
|
|
930
|
+
const owner = scopeOwners.get(scope);
|
|
931
|
+
if (owner === undefined) {
|
|
932
|
+
throw new Error(DEV ? 'createCompiledId received an unknown scope' : 'V003');
|
|
933
|
+
}
|
|
934
|
+
const id = `:${owner[3].prefix}r${owner[3].nextId}:`;
|
|
935
|
+
owner[3].nextId += 1;
|
|
936
|
+
return id;
|
|
937
|
+
}
|
|
938
|
+
export function useContext(context) {
|
|
939
|
+
if (activeConstructionOwner === null) {
|
|
940
|
+
throw new Error(DEV ? 'useContext must run during compiled component construction' : 'V019');
|
|
941
|
+
}
|
|
942
|
+
const input = contextInputFromFrame(activeConstructionOwner[2], context);
|
|
943
|
+
return isCompiledBinding(input) ? input[1]() : input;
|
|
944
|
+
}
|
|
945
|
+
export function use(context) {
|
|
946
|
+
return useContext(context);
|
|
947
|
+
}
|
|
948
|
+
export function createCompiledAsync(scope, reads, writes, evaluate) {
|
|
949
|
+
const input = evaluate();
|
|
950
|
+
if (isCompiledContext(input))
|
|
951
|
+
return createCompiledContext(scope, writes, input);
|
|
952
|
+
const slot = createCompiledState(scope, writes, useAsync(input));
|
|
953
|
+
scope[0](reads, () => slot.replace(useAsync(evaluate())));
|
|
954
|
+
return slot;
|
|
955
|
+
}
|
|
956
|
+
export function Suspense(props) {
|
|
957
|
+
const render = Array.isArray(props.children) ? props.children[0] : props.children;
|
|
958
|
+
if (typeof render !== 'function' || typeof props.fallback !== 'function') {
|
|
959
|
+
throw new TypeError(DEV
|
|
960
|
+
? `Suspense children and fallback must be compiler-generated render functions; received ${typeof render} and ${typeof props.fallback}`
|
|
961
|
+
: 'V031');
|
|
962
|
+
}
|
|
963
|
+
return suspense(render, props.fallback);
|
|
964
|
+
}
|
|
965
|
+
export function useSyncExternalStore(_subscribe, _getSnapshot, _getServerSnapshot) {
|
|
966
|
+
throw new Error(DEV ? 'useSyncExternalStore requires compiler lowering' : 'V021');
|
|
967
|
+
}
|
|
968
|
+
export function useEffectEvent(callback) {
|
|
969
|
+
return callback;
|
|
970
|
+
}
|
|
971
|
+
export function useId() {
|
|
972
|
+
if (activeConstructionOwner === null) {
|
|
973
|
+
throw new Error(DEV ? 'useId must run during compiled component construction' : 'V023');
|
|
974
|
+
}
|
|
975
|
+
const id = `:${activeConstructionOwner[3].prefix}r${activeConstructionOwner[3].nextId}:`;
|
|
976
|
+
activeConstructionOwner[3].nextId += 1;
|
|
977
|
+
return id;
|
|
978
|
+
}
|
|
979
|
+
export function useMemo(factory, _dependencies) {
|
|
980
|
+
return factory();
|
|
981
|
+
}
|
|
982
|
+
export function useCallback(callback, _dependencies) {
|
|
983
|
+
return callback;
|
|
984
|
+
}
|
|
985
|
+
export function createCompiledProp(scope, sourceMask, input, fallback) {
|
|
986
|
+
const assertWritable = stateWriteGuard(scope);
|
|
987
|
+
const upstream = isCompiledBinding(input) ? input : undefined;
|
|
988
|
+
const read = () => {
|
|
989
|
+
const value = upstream === undefined ? input : upstream[1]();
|
|
990
|
+
return value === undefined && fallback !== undefined ? fallback() : value;
|
|
991
|
+
};
|
|
992
|
+
const slot = createStateSlot(scope[1], sourceMask, read(), assertWritable);
|
|
993
|
+
if (upstream !== undefined) {
|
|
994
|
+
const remove = subscribeBinding(upstream, () => slot.replace(read()));
|
|
995
|
+
const owner = scopeOwners.get(scope);
|
|
996
|
+
if (owner === undefined) {
|
|
997
|
+
throw new Error(DEV ? 'createCompiledProp received an unknown scope' : 'V003');
|
|
998
|
+
}
|
|
999
|
+
owner[1].add(remove);
|
|
1000
|
+
}
|
|
1001
|
+
return slot;
|
|
1002
|
+
}
|
|
1003
|
+
export function createCompiledRestProp(scope, sourceMask, input, excludedNames) {
|
|
1004
|
+
const excluded = new Set(excludedNames);
|
|
1005
|
+
const entries = () => Object.entries(input).filter(([name]) => !excluded.has(name));
|
|
1006
|
+
const read = () => Object.fromEntries(entries().map(([name, value]) => [name, isCompiledBinding(value) ? value[1]() : value]));
|
|
1007
|
+
const slot = createStateSlot(scope[1], sourceMask, read(), stateWriteGuard(scope));
|
|
1008
|
+
const componentSpreadSource = input[COMPONENT_SPREAD_SOURCE];
|
|
1009
|
+
const upstreams = new Set(entries()
|
|
1010
|
+
.map(([, value]) => value)
|
|
1011
|
+
.filter(isCompiledBinding));
|
|
1012
|
+
if (isCompiledBinding(componentSpreadSource))
|
|
1013
|
+
upstreams.add(componentSpreadSource);
|
|
1014
|
+
const removers = [...upstreams].map((upstream) => subscribeBinding(upstream, () => slot.replace(read())));
|
|
1015
|
+
const owner = scopeOwners.get(scope);
|
|
1016
|
+
if (owner === undefined) {
|
|
1017
|
+
throw new Error(DEV ? 'createCompiledRestProp received an unknown scope' : 'V003');
|
|
1018
|
+
}
|
|
1019
|
+
owner[1].add(() => {
|
|
1020
|
+
for (const remove of removers)
|
|
1021
|
+
remove();
|
|
1022
|
+
});
|
|
1023
|
+
return slot;
|
|
1024
|
+
}
|
|
1025
|
+
function stateWriteGuard(scope) {
|
|
1026
|
+
const owner = scopeOwners.get(scope);
|
|
1027
|
+
if (owner === undefined) {
|
|
1028
|
+
throw new Error(DEV ? 'compiled state received an unknown scope' : 'V003');
|
|
1029
|
+
}
|
|
1030
|
+
return () => {
|
|
1031
|
+
if (owner[0])
|
|
1032
|
+
throw new Error(DEV ? 'cannot update state after disposal' : 'V012');
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
export function binding(scope, reads, evaluate, additionalScope, additionalReads) {
|
|
1036
|
+
return [BINDING, evaluate, scope, reads, additionalScope, additionalReads];
|
|
1037
|
+
}
|
|
1038
|
+
export function compiledEvent(scope, handler) {
|
|
1039
|
+
const owner = scopeOwners.get(scope);
|
|
1040
|
+
if (owner === undefined) {
|
|
1041
|
+
throw new Error(DEV ? 'compiledEvent received an unknown scope' : 'V003');
|
|
1042
|
+
}
|
|
1043
|
+
const errorOwner = activeOwner ?? owner;
|
|
1044
|
+
return (...arguments_) => runOwnerTask(errorOwner, () => withOwner(errorOwner, () => scope[2](() => handler(...arguments_))));
|
|
1045
|
+
}
|
|
1046
|
+
export function captureCompiledTask(scope) {
|
|
1047
|
+
const owner = scope === undefined ? activeOwner : scopeOwners.get(scope);
|
|
1048
|
+
if (owner === null || owner === undefined) {
|
|
1049
|
+
throw new Error(DEV ? 'compiled task must be captured during owned construction' : 'V034');
|
|
1050
|
+
}
|
|
1051
|
+
return {
|
|
1052
|
+
disposed: () => owner[0],
|
|
1053
|
+
report: (error) => runOwnerTask(owner, () => {
|
|
1054
|
+
throw error;
|
|
1055
|
+
}),
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
export function when(scope, reads, condition, render, additionalScope, additionalReads) {
|
|
1059
|
+
return structural(scope, (parent, before) => {
|
|
1060
|
+
const [start, end, hydrated] = structuralRange(parent, before, 'when');
|
|
1061
|
+
let branchOwner = null;
|
|
1062
|
+
let mounted = false;
|
|
1063
|
+
let hydrationPending = hydrated;
|
|
1064
|
+
const update = () => {
|
|
1065
|
+
const next = Boolean(condition());
|
|
1066
|
+
if (hydrationPending && !next) {
|
|
1067
|
+
claimHydrationText(parent, '');
|
|
1068
|
+
hydrationPending = false;
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
if (next === mounted)
|
|
1072
|
+
return;
|
|
1073
|
+
const currentParent = rangeParent(start, end, 'conditional block');
|
|
1074
|
+
if (!next) {
|
|
1075
|
+
const owner = branchOwner;
|
|
1076
|
+
branchOwner = null;
|
|
1077
|
+
mounted = false;
|
|
1078
|
+
disposeRange(owner, start, end);
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
const nextOwner = createOwner();
|
|
1082
|
+
const [fragment, staged] = hydrationPending
|
|
1083
|
+
? withHydrationInsertion(currentParent, end, () => stageRender(render, nextOwner))
|
|
1084
|
+
: stageRender(render, nextOwner);
|
|
1085
|
+
hydrationPending = false;
|
|
1086
|
+
currentParent.insertBefore(fragment, end);
|
|
1087
|
+
commitPublishedNodes(staged);
|
|
1088
|
+
branchOwner = nextOwner;
|
|
1089
|
+
mounted = true;
|
|
1090
|
+
};
|
|
1091
|
+
const removeUpdater = subscribe(scope, reads, update, additionalScope, additionalReads);
|
|
1092
|
+
try {
|
|
1093
|
+
update();
|
|
1094
|
+
}
|
|
1095
|
+
catch (error) {
|
|
1096
|
+
removeUpdater();
|
|
1097
|
+
throw error;
|
|
1098
|
+
}
|
|
1099
|
+
onCleanup(() => {
|
|
1100
|
+
removeUpdater();
|
|
1101
|
+
try {
|
|
1102
|
+
disposeRange(branchOwner, start, end);
|
|
1103
|
+
}
|
|
1104
|
+
finally {
|
|
1105
|
+
start.remove();
|
|
1106
|
+
end.remove();
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1109
|
+
}, 'slot');
|
|
1110
|
+
}
|
|
1111
|
+
export function choose(scope, reads, mode, select, consequent, alternate, additionalScope, additionalReads) {
|
|
1112
|
+
return structural(scope, (parent, before) => {
|
|
1113
|
+
const [start, end, hydrated] = structuralRange(parent, before, 'choice');
|
|
1114
|
+
let selected = -1;
|
|
1115
|
+
let branchOwner = null;
|
|
1116
|
+
let branchNodes = [];
|
|
1117
|
+
const update = () => {
|
|
1118
|
+
const value = select();
|
|
1119
|
+
const next = mode === 'not-nullish' ? (value === null || value === undefined ? 1 : 0) : value ? 0 : 1;
|
|
1120
|
+
if (next === selected)
|
|
1121
|
+
return;
|
|
1122
|
+
const currentParent = rangeParent(start, end, 'choice block');
|
|
1123
|
+
const nextOwner = createOwner();
|
|
1124
|
+
const [fragment, nodes] = hydrated && selected === -1
|
|
1125
|
+
? withHydrationInsertion(currentParent, end, () => stageRender(next === 0 ? consequent : alternate, nextOwner))
|
|
1126
|
+
: stageRender(next === 0 ? consequent : alternate, nextOwner);
|
|
1127
|
+
currentParent.insertBefore(fragment, end);
|
|
1128
|
+
try {
|
|
1129
|
+
commitPublishedNodes(nodes);
|
|
1130
|
+
}
|
|
1131
|
+
catch (error) {
|
|
1132
|
+
disposePublished(nextOwner, nodes);
|
|
1133
|
+
throw error;
|
|
1134
|
+
}
|
|
1135
|
+
const previousOwner = branchOwner;
|
|
1136
|
+
const previousNodes = branchNodes;
|
|
1137
|
+
branchOwner = nextOwner;
|
|
1138
|
+
branchNodes = nodes;
|
|
1139
|
+
selected = next;
|
|
1140
|
+
disposePublished(previousOwner, previousNodes);
|
|
1141
|
+
};
|
|
1142
|
+
const removeUpdater = subscribe(scope, reads, update, additionalScope, additionalReads);
|
|
1143
|
+
try {
|
|
1144
|
+
update();
|
|
1145
|
+
}
|
|
1146
|
+
catch (error) {
|
|
1147
|
+
removeUpdater();
|
|
1148
|
+
throw error;
|
|
1149
|
+
}
|
|
1150
|
+
onCleanup(() => {
|
|
1151
|
+
removeUpdater();
|
|
1152
|
+
try {
|
|
1153
|
+
disposePublished(branchOwner, branchNodes);
|
|
1154
|
+
}
|
|
1155
|
+
finally {
|
|
1156
|
+
start.remove();
|
|
1157
|
+
end.remove();
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1160
|
+
}, 'slot');
|
|
1161
|
+
}
|
|
1162
|
+
export function dispatch(scope, reads, type, key, render, additionalScope, additionalReads) {
|
|
1163
|
+
return structural(scope, (parent, before) => {
|
|
1164
|
+
const [start, end, hydrated] = structuralRange(parent, before, 'dispatch');
|
|
1165
|
+
const unset = Symbol('Vidact.UnsetIdentity');
|
|
1166
|
+
let currentType = unset;
|
|
1167
|
+
let currentKey = unset;
|
|
1168
|
+
let currentOwner = null;
|
|
1169
|
+
let currentNodes = [];
|
|
1170
|
+
const update = () => {
|
|
1171
|
+
const nextType = type();
|
|
1172
|
+
const nextKey = key();
|
|
1173
|
+
if (currentType !== unset &&
|
|
1174
|
+
Object.is(nextType, currentType) &&
|
|
1175
|
+
Object.is(nextKey, currentKey)) {
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1178
|
+
const currentParent = rangeParent(start, end, 'dispatch block');
|
|
1179
|
+
const nextOwner = createOwner();
|
|
1180
|
+
const [fragment, nodes] = hydrated && currentType === unset
|
|
1181
|
+
? withHydrationInsertion(currentParent, end, () => stageRender(render, nextOwner))
|
|
1182
|
+
: stageRender(render, nextOwner);
|
|
1183
|
+
currentParent.insertBefore(fragment, end);
|
|
1184
|
+
try {
|
|
1185
|
+
commitPublishedNodes(nodes);
|
|
1186
|
+
}
|
|
1187
|
+
catch (error) {
|
|
1188
|
+
disposePublished(nextOwner, nodes);
|
|
1189
|
+
throw error;
|
|
1190
|
+
}
|
|
1191
|
+
const previousOwner = currentOwner;
|
|
1192
|
+
const previousNodes = currentNodes;
|
|
1193
|
+
currentType = nextType;
|
|
1194
|
+
currentKey = nextKey;
|
|
1195
|
+
currentOwner = nextOwner;
|
|
1196
|
+
currentNodes = nodes;
|
|
1197
|
+
disposePublished(previousOwner, previousNodes);
|
|
1198
|
+
};
|
|
1199
|
+
const removeUpdater = subscribe(scope, reads, update, additionalScope, additionalReads);
|
|
1200
|
+
try {
|
|
1201
|
+
update();
|
|
1202
|
+
}
|
|
1203
|
+
catch (error) {
|
|
1204
|
+
removeUpdater();
|
|
1205
|
+
throw error;
|
|
1206
|
+
}
|
|
1207
|
+
onCleanup(() => {
|
|
1208
|
+
removeUpdater();
|
|
1209
|
+
try {
|
|
1210
|
+
disposePublished(currentOwner, currentNodes);
|
|
1211
|
+
}
|
|
1212
|
+
finally {
|
|
1213
|
+
start.remove();
|
|
1214
|
+
end.remove();
|
|
1215
|
+
}
|
|
1216
|
+
});
|
|
1217
|
+
}, 'slot');
|
|
1218
|
+
}
|
|
1219
|
+
export function keyed(scope, reads, values, key, render, additionalScope, additionalReads) {
|
|
1220
|
+
return structural(scope, (parent, before) => {
|
|
1221
|
+
const itemSource = 1;
|
|
1222
|
+
const indexSource = 2;
|
|
1223
|
+
const list = createKeyedList(parent, {
|
|
1224
|
+
key,
|
|
1225
|
+
render(value, index) {
|
|
1226
|
+
const owner = createOwner();
|
|
1227
|
+
const itemScope = createNarrowCompiledScope();
|
|
1228
|
+
const valueSlot = createCompiledState(itemScope, itemSource, value);
|
|
1229
|
+
const indexSlot = createCompiledState(itemScope, indexSource, index);
|
|
1230
|
+
try {
|
|
1231
|
+
const nodes = withOwner(owner, () => {
|
|
1232
|
+
onCleanup(itemScope[3]);
|
|
1233
|
+
return materialize(render(valueSlot, indexSlot, itemScope));
|
|
1234
|
+
});
|
|
1235
|
+
return [
|
|
1236
|
+
nodes,
|
|
1237
|
+
(nextValue, nextIndex) => {
|
|
1238
|
+
itemScope[2](() => {
|
|
1239
|
+
valueSlot.set(nextValue);
|
|
1240
|
+
indexSlot.set(nextIndex);
|
|
1241
|
+
});
|
|
1242
|
+
},
|
|
1243
|
+
() => disposeOwner(owner),
|
|
1244
|
+
];
|
|
1245
|
+
}
|
|
1246
|
+
catch (error) {
|
|
1247
|
+
disposeOwner(owner);
|
|
1248
|
+
throw error;
|
|
1249
|
+
}
|
|
1250
|
+
},
|
|
1251
|
+
}, before);
|
|
1252
|
+
const update = () => {
|
|
1253
|
+
try {
|
|
1254
|
+
commitPublishedNodes(list.update(values()));
|
|
1255
|
+
}
|
|
1256
|
+
catch (error) {
|
|
1257
|
+
const currentParent = list.parent();
|
|
1258
|
+
if (currentParent !== null)
|
|
1259
|
+
commitPendingRefs(currentParent);
|
|
1260
|
+
throw error;
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
1263
|
+
update();
|
|
1264
|
+
const removeUpdater = subscribe(scope, reads, update, additionalScope, additionalReads);
|
|
1265
|
+
onCleanup(() => {
|
|
1266
|
+
removeUpdater();
|
|
1267
|
+
list.dispose();
|
|
1268
|
+
});
|
|
1269
|
+
}, 'array');
|
|
1270
|
+
}
|
|
1271
|
+
export function indexed(scope, reads, values, render, additionalScope, additionalReads) {
|
|
1272
|
+
return structural(scope, (parent, before) => {
|
|
1273
|
+
const itemSource = 1;
|
|
1274
|
+
const indexSource = 2;
|
|
1275
|
+
const list = createIndexedList(parent, {
|
|
1276
|
+
render(value, index) {
|
|
1277
|
+
const owner = createOwner();
|
|
1278
|
+
const itemScope = createNarrowCompiledScope();
|
|
1279
|
+
const valueSlot = createCompiledState(itemScope, itemSource, value);
|
|
1280
|
+
const indexSlot = createCompiledState(itemScope, indexSource, index);
|
|
1281
|
+
try {
|
|
1282
|
+
const nodes = withOwner(owner, () => {
|
|
1283
|
+
onCleanup(itemScope[3]);
|
|
1284
|
+
return materialize(render(valueSlot, indexSlot, itemScope));
|
|
1285
|
+
});
|
|
1286
|
+
return [
|
|
1287
|
+
nodes,
|
|
1288
|
+
(nextValue, nextIndex) => {
|
|
1289
|
+
itemScope[2](() => {
|
|
1290
|
+
valueSlot.set(nextValue);
|
|
1291
|
+
indexSlot.set(nextIndex);
|
|
1292
|
+
});
|
|
1293
|
+
},
|
|
1294
|
+
() => disposeOwner(owner),
|
|
1295
|
+
];
|
|
1296
|
+
}
|
|
1297
|
+
catch (error) {
|
|
1298
|
+
disposeOwner(owner);
|
|
1299
|
+
throw error;
|
|
1300
|
+
}
|
|
1301
|
+
},
|
|
1302
|
+
}, before);
|
|
1303
|
+
const update = () => {
|
|
1304
|
+
try {
|
|
1305
|
+
commitPublishedNodes(list.update(values()));
|
|
1306
|
+
}
|
|
1307
|
+
catch (error) {
|
|
1308
|
+
const currentParent = list.parent();
|
|
1309
|
+
if (currentParent !== null)
|
|
1310
|
+
commitPendingRefs(currentParent);
|
|
1311
|
+
throw error;
|
|
1312
|
+
}
|
|
1313
|
+
};
|
|
1314
|
+
update();
|
|
1315
|
+
const removeUpdater = subscribe(scope, reads, update, additionalScope, additionalReads);
|
|
1316
|
+
onCleanup(() => {
|
|
1317
|
+
removeUpdater();
|
|
1318
|
+
list.dispose();
|
|
1319
|
+
});
|
|
1320
|
+
}, 'array');
|
|
1321
|
+
}
|
|
1322
|
+
export function compiledRoot(scope, render) {
|
|
1323
|
+
const owner = scopeOwners.get(scope);
|
|
1324
|
+
if (owner === undefined) {
|
|
1325
|
+
throw new Error(DEV ? 'compiledRoot received an unknown scope' : 'V004');
|
|
1326
|
+
}
|
|
1327
|
+
const hydratedRange = claimHydrationComponentRange();
|
|
1328
|
+
const start = hydratedRange?.[0] ?? document.createComment(DEV ? 'vidact:component' : '');
|
|
1329
|
+
const end = hydratedRange?.[1] ?? document.createComment(DEV ? '/vidact:component' : '');
|
|
1330
|
+
componentCommitOwners.set(end, owner);
|
|
1331
|
+
const fragment = document.createDocumentFragment();
|
|
1332
|
+
if (hydratedRange === undefined)
|
|
1333
|
+
fragment.append(start, end);
|
|
1334
|
+
owner[1].add(() => {
|
|
1335
|
+
try {
|
|
1336
|
+
removeBetween(start, end);
|
|
1337
|
+
}
|
|
1338
|
+
finally {
|
|
1339
|
+
start.remove();
|
|
1340
|
+
end.remove();
|
|
1341
|
+
}
|
|
1342
|
+
});
|
|
1343
|
+
try {
|
|
1344
|
+
const renderParent = hydrationRangeParent(start, end) ?? fragment;
|
|
1345
|
+
const insertRender = () => withOwner(owner, () => withScopeNamespace(scope, () => insertValue(renderParent, render(), end)));
|
|
1346
|
+
const insert = () => {
|
|
1347
|
+
if (hydratedRange === undefined)
|
|
1348
|
+
insertRender();
|
|
1349
|
+
else
|
|
1350
|
+
withHydrationComponentRange(hydratedRange, () => withHydrationCursor(renderParent, start.nextSibling, insertRender));
|
|
1351
|
+
};
|
|
1352
|
+
if (profilingEnabled)
|
|
1353
|
+
measureProfileWork(owner, 'range', insert);
|
|
1354
|
+
else
|
|
1355
|
+
insert();
|
|
1356
|
+
}
|
|
1357
|
+
catch (error) {
|
|
1358
|
+
try {
|
|
1359
|
+
scope[3]();
|
|
1360
|
+
}
|
|
1361
|
+
catch {
|
|
1362
|
+
// Preserve the render error that made this component unmountable.
|
|
1363
|
+
}
|
|
1364
|
+
throw error;
|
|
1365
|
+
}
|
|
1366
|
+
let mounted = false;
|
|
1367
|
+
const component = [
|
|
1368
|
+
STRUCTURAL,
|
|
1369
|
+
(parent, before) => {
|
|
1370
|
+
if (mounted)
|
|
1371
|
+
throw new Error(DEV ? 'compiled component is already mounted' : 'V005');
|
|
1372
|
+
mounted = true;
|
|
1373
|
+
adoptCompiledRoot(component);
|
|
1374
|
+
try {
|
|
1375
|
+
if (!claimHydrationComponentMount(parent, start, end)) {
|
|
1376
|
+
parent.insertBefore(fragment, before);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
catch (error) {
|
|
1380
|
+
try {
|
|
1381
|
+
scope[3]();
|
|
1382
|
+
}
|
|
1383
|
+
catch {
|
|
1384
|
+
// Preserve the insertion error that made this component unmountable.
|
|
1385
|
+
}
|
|
1386
|
+
throw error;
|
|
1387
|
+
}
|
|
1388
|
+
},
|
|
1389
|
+
];
|
|
1390
|
+
componentRanges.set(component, [start, end, scope]);
|
|
1391
|
+
return component;
|
|
1392
|
+
}
|
|
1393
|
+
export function adoptCompiledRoot(root) {
|
|
1394
|
+
if (!isCompiledComponentResult(root))
|
|
1395
|
+
return;
|
|
1396
|
+
const range = componentRanges.get(root);
|
|
1397
|
+
if (range === undefined)
|
|
1398
|
+
return;
|
|
1399
|
+
const owner = scopeOwners.get(range[2]);
|
|
1400
|
+
if (activeOwner !== null && owner !== undefined && activeOwner !== owner) {
|
|
1401
|
+
activeOwner[1].add(range[2][3]);
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
export function constructCompiledComponent(component, componentType) {
|
|
1405
|
+
const previousCollector = activeScopeCollector;
|
|
1406
|
+
const previousConstructionOwner = activeConstructionOwner;
|
|
1407
|
+
const previousProfileName = activeProfileName;
|
|
1408
|
+
const scopes = new Set();
|
|
1409
|
+
activeScopeCollector = scopes;
|
|
1410
|
+
activeConstructionOwner = null;
|
|
1411
|
+
const profileType = componentType;
|
|
1412
|
+
if (DEV)
|
|
1413
|
+
activeProfileName = profileType?.displayName ?? profileType?.name ?? 'Anonymous';
|
|
1414
|
+
try {
|
|
1415
|
+
return component();
|
|
1416
|
+
}
|
|
1417
|
+
catch (error) {
|
|
1418
|
+
// oxlint-disable-next-line unicorn/no-array-reverse - scopes is already copied to avoid mutation during iteration
|
|
1419
|
+
for (const scope of [...scopes].reverse()) {
|
|
1420
|
+
try {
|
|
1421
|
+
scope[3]();
|
|
1422
|
+
}
|
|
1423
|
+
catch {
|
|
1424
|
+
// Preserve the construction error that made this component unmountable.
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
throw error;
|
|
1428
|
+
}
|
|
1429
|
+
finally {
|
|
1430
|
+
activeScopeCollector = previousCollector;
|
|
1431
|
+
activeConstructionOwner = previousConstructionOwner;
|
|
1432
|
+
if (DEV)
|
|
1433
|
+
activeProfileName = previousProfileName;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
export function queueElementRef(element, value) {
|
|
1437
|
+
if (!isRefValue(value)) {
|
|
1438
|
+
throw new TypeError(DEV ? 'ref must be a callback or an object with current' : 'V006');
|
|
1439
|
+
}
|
|
1440
|
+
pendingRefs.set(element, [activeOwner, value]);
|
|
1441
|
+
}
|
|
1442
|
+
export function useImperativeHandle(ref, create, dependencies) {
|
|
1443
|
+
const owner = activeConstructionOwner;
|
|
1444
|
+
if (owner === null) {
|
|
1445
|
+
throw new Error(DEV ? 'useImperativeHandle must run during compiled component construction' : 'V013');
|
|
1446
|
+
}
|
|
1447
|
+
if (!isRefValue(ref)) {
|
|
1448
|
+
throw new TypeError(DEV ? 'imperative ref must be null, a callback, or an object with current' : 'V006');
|
|
1449
|
+
}
|
|
1450
|
+
if (dependencies !== undefined && dependencies.length !== 0) {
|
|
1451
|
+
throw new Error(DEV ? 'reactive useImperativeHandle dependencies are not supported yet' : 'V014');
|
|
1452
|
+
}
|
|
1453
|
+
queueOwnerCommit(owner, () => owner[1].add(attachRef(ref, create())));
|
|
1454
|
+
}
|
|
1455
|
+
export function useLayoutEffect(create, dependencies) {
|
|
1456
|
+
registerEffect(create, dependencies, false);
|
|
1457
|
+
}
|
|
1458
|
+
export function useInsertionEffect(create, dependencies) {
|
|
1459
|
+
const owner = activeConstructionOwner;
|
|
1460
|
+
if (owner === null) {
|
|
1461
|
+
throw new Error(DEV ? 'insertion effects must run during compiled component construction' : 'V016');
|
|
1462
|
+
}
|
|
1463
|
+
if (dependencies !== undefined && dependencies.length !== 0) {
|
|
1464
|
+
throw new Error(DEV ? 'reactive insertion effect dependencies require compiler lowering' : 'V017');
|
|
1465
|
+
}
|
|
1466
|
+
const lifetimeOwner = activeOwner ?? owner;
|
|
1467
|
+
if (!retainedUiEnabled) {
|
|
1468
|
+
let cleanup = noop;
|
|
1469
|
+
queueInsertionCommit(owner, () => {
|
|
1470
|
+
if (lifetimeOwner[0])
|
|
1471
|
+
return;
|
|
1472
|
+
cleanup();
|
|
1473
|
+
cleanup = profilingEnabled
|
|
1474
|
+
? readProfiledEffectCleanup(owner, create)
|
|
1475
|
+
: readEffectCleanup(create());
|
|
1476
|
+
});
|
|
1477
|
+
lifetimeOwner[1].add(() => cleanup());
|
|
1478
|
+
return;
|
|
1479
|
+
}
|
|
1480
|
+
let cleanup = noop;
|
|
1481
|
+
const [activate, disposeResource] = createRetainedResource(lifetimeOwner, () => {
|
|
1482
|
+
stagePublication([
|
|
1483
|
+
noop,
|
|
1484
|
+
noop,
|
|
1485
|
+
undefined,
|
|
1486
|
+
() => {
|
|
1487
|
+
cleanup = profilingEnabled
|
|
1488
|
+
? readProfiledEffectCleanup(owner, create)
|
|
1489
|
+
: readEffectCleanup(create());
|
|
1490
|
+
},
|
|
1491
|
+
-20,
|
|
1492
|
+
]);
|
|
1493
|
+
}, () => {
|
|
1494
|
+
cleanup();
|
|
1495
|
+
cleanup = noop;
|
|
1496
|
+
});
|
|
1497
|
+
queueInsertionCommit(owner, () => {
|
|
1498
|
+
if (!lifetimeOwner[0])
|
|
1499
|
+
activate();
|
|
1500
|
+
});
|
|
1501
|
+
lifetimeOwner[1].add(disposeResource);
|
|
1502
|
+
}
|
|
1503
|
+
export function useEffect(create, dependencies) {
|
|
1504
|
+
registerEffect(create, dependencies, true);
|
|
1505
|
+
}
|
|
1506
|
+
function registerEffect(create, dependencies, passive) {
|
|
1507
|
+
const owner = activeConstructionOwner;
|
|
1508
|
+
if (owner === null) {
|
|
1509
|
+
throw new Error(DEV ? 'effects must run during compiled component construction' : 'V016');
|
|
1510
|
+
}
|
|
1511
|
+
if (dependencies !== undefined && dependencies.length !== 0) {
|
|
1512
|
+
throw new Error(DEV ? 'reactive effect dependencies require compiler lowering' : 'V017');
|
|
1513
|
+
}
|
|
1514
|
+
const lifetimeOwner = activeOwner ?? owner;
|
|
1515
|
+
if (!retainedUiEnabled) {
|
|
1516
|
+
let cleanup = noop;
|
|
1517
|
+
let generation = 0;
|
|
1518
|
+
const run = () => {
|
|
1519
|
+
cleanup();
|
|
1520
|
+
cleanup = profilingEnabled
|
|
1521
|
+
? readProfiledEffectCleanup(owner, create)
|
|
1522
|
+
: readEffectCleanup(create());
|
|
1523
|
+
};
|
|
1524
|
+
queueOwnerCommit(owner, () => {
|
|
1525
|
+
if (lifetimeOwner[0])
|
|
1526
|
+
return;
|
|
1527
|
+
if (passive) {
|
|
1528
|
+
const scheduled = ++generation;
|
|
1529
|
+
(DEV ? scheduleTask : queueMicrotask)(() => {
|
|
1530
|
+
if (!lifetimeOwner[0] && scheduled === generation)
|
|
1531
|
+
runOwnerTask(lifetimeOwner, run);
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
else {
|
|
1535
|
+
run();
|
|
1536
|
+
}
|
|
1537
|
+
});
|
|
1538
|
+
lifetimeOwner[1].add(() => {
|
|
1539
|
+
generation += 1;
|
|
1540
|
+
if (passive)
|
|
1541
|
+
(DEV ? scheduleTask : queueMicrotask)(() => runOwnerTask(lifetimeOwner, cleanup));
|
|
1542
|
+
else
|
|
1543
|
+
cleanup();
|
|
1544
|
+
});
|
|
1545
|
+
return;
|
|
1546
|
+
}
|
|
1547
|
+
let cleanup = noop;
|
|
1548
|
+
let generation = 0;
|
|
1549
|
+
const [activate, disposeResource] = createRetainedResource(lifetimeOwner, () => {
|
|
1550
|
+
stagePublication([
|
|
1551
|
+
noop,
|
|
1552
|
+
noop,
|
|
1553
|
+
undefined,
|
|
1554
|
+
() => {
|
|
1555
|
+
if (passive) {
|
|
1556
|
+
const scheduled = ++generation;
|
|
1557
|
+
(DEV ? scheduleTask : queueMicrotask)(() => {
|
|
1558
|
+
if (!lifetimeOwner[0] && scheduled === generation) {
|
|
1559
|
+
runOwnerTask(lifetimeOwner, () => {
|
|
1560
|
+
cleanup = profilingEnabled
|
|
1561
|
+
? readProfiledEffectCleanup(owner, create)
|
|
1562
|
+
: readEffectCleanup(create());
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
else {
|
|
1568
|
+
cleanup = profilingEnabled
|
|
1569
|
+
? readProfiledEffectCleanup(owner, create)
|
|
1570
|
+
: readEffectCleanup(create());
|
|
1571
|
+
}
|
|
1572
|
+
},
|
|
1573
|
+
passive ? 40 : 20,
|
|
1574
|
+
]);
|
|
1575
|
+
}, () => {
|
|
1576
|
+
generation += 1;
|
|
1577
|
+
const previousCleanup = cleanup;
|
|
1578
|
+
cleanup = noop;
|
|
1579
|
+
if (passive)
|
|
1580
|
+
(DEV ? scheduleTask : queueMicrotask)(() => runOwnerTask(lifetimeOwner, previousCleanup));
|
|
1581
|
+
else
|
|
1582
|
+
previousCleanup();
|
|
1583
|
+
});
|
|
1584
|
+
queueOwnerCommit(owner, () => {
|
|
1585
|
+
if (!lifetimeOwner[0])
|
|
1586
|
+
activate();
|
|
1587
|
+
});
|
|
1588
|
+
lifetimeOwner[1].add(disposeResource);
|
|
1589
|
+
}
|
|
1590
|
+
export function compiledLayoutEffect(scope, reads, readCreate, readDependencies) {
|
|
1591
|
+
compiledEffect(scope, reads, readCreate, readDependencies, false);
|
|
1592
|
+
}
|
|
1593
|
+
export function compiledInsertionEffect(scope, reads, readCreate, readDependencies) {
|
|
1594
|
+
const owner = activeConstructionOwner;
|
|
1595
|
+
if (owner === null || scopeOwners.get(scope) !== owner) {
|
|
1596
|
+
throw new Error(DEV ? 'compiled insertion effects must run in their component scope' : 'V016');
|
|
1597
|
+
}
|
|
1598
|
+
const lifetimeOwner = activeOwner ?? owner;
|
|
1599
|
+
if (!retainedUiEnabled) {
|
|
1600
|
+
let mounted = false;
|
|
1601
|
+
let currentDependencies;
|
|
1602
|
+
let cleanup = noop;
|
|
1603
|
+
const run = () => {
|
|
1604
|
+
const nextDependencies = readDependencies?.();
|
|
1605
|
+
if (mounted &&
|
|
1606
|
+
readDependencies !== undefined &&
|
|
1607
|
+
equalDependencies(nextDependencies, currentDependencies)) {
|
|
1608
|
+
return;
|
|
1609
|
+
}
|
|
1610
|
+
cleanup();
|
|
1611
|
+
cleanup = profilingEnabled
|
|
1612
|
+
? readProfiledEffectCleanup(owner, () => readCreate()())
|
|
1613
|
+
: readEffectCleanup(readCreate()());
|
|
1614
|
+
currentDependencies = nextDependencies;
|
|
1615
|
+
mounted = true;
|
|
1616
|
+
};
|
|
1617
|
+
queueInsertionCommit(owner, () => {
|
|
1618
|
+
if (!lifetimeOwner[0])
|
|
1619
|
+
run();
|
|
1620
|
+
});
|
|
1621
|
+
const removeUpdater = subscribe(scope, reads, () => stagePublication([noop, noop, undefined, run, -20]));
|
|
1622
|
+
lifetimeOwner[1].add(() => {
|
|
1623
|
+
removeUpdater();
|
|
1624
|
+
cleanup();
|
|
1625
|
+
});
|
|
1626
|
+
return;
|
|
1627
|
+
}
|
|
1628
|
+
let mounted = false;
|
|
1629
|
+
let connected = false;
|
|
1630
|
+
let currentDependencies;
|
|
1631
|
+
let cleanup = noop;
|
|
1632
|
+
const run = () => {
|
|
1633
|
+
const nextDependencies = readDependencies?.();
|
|
1634
|
+
if (mounted &&
|
|
1635
|
+
readDependencies !== undefined &&
|
|
1636
|
+
equalDependencies(nextDependencies, currentDependencies)) {
|
|
1637
|
+
return;
|
|
1638
|
+
}
|
|
1639
|
+
cleanup();
|
|
1640
|
+
cleanup = profilingEnabled
|
|
1641
|
+
? readProfiledEffectCleanup(owner, () => readCreate()())
|
|
1642
|
+
: readEffectCleanup(readCreate()());
|
|
1643
|
+
currentDependencies = nextDependencies;
|
|
1644
|
+
mounted = true;
|
|
1645
|
+
};
|
|
1646
|
+
const [activate, disposeResource] = createRetainedResource(lifetimeOwner, () => {
|
|
1647
|
+
stagePublication([
|
|
1648
|
+
noop,
|
|
1649
|
+
noop,
|
|
1650
|
+
undefined,
|
|
1651
|
+
() => {
|
|
1652
|
+
connected = true;
|
|
1653
|
+
run();
|
|
1654
|
+
},
|
|
1655
|
+
-20,
|
|
1656
|
+
]);
|
|
1657
|
+
}, () => {
|
|
1658
|
+
connected = false;
|
|
1659
|
+
cleanup();
|
|
1660
|
+
cleanup = noop;
|
|
1661
|
+
mounted = false;
|
|
1662
|
+
});
|
|
1663
|
+
queueInsertionCommit(owner, () => {
|
|
1664
|
+
if (!lifetimeOwner[0])
|
|
1665
|
+
activate();
|
|
1666
|
+
});
|
|
1667
|
+
const removeUpdater = subscribe(scope, reads, () => {
|
|
1668
|
+
if (connected)
|
|
1669
|
+
stagePublication([noop, noop, undefined, run, -20]);
|
|
1670
|
+
});
|
|
1671
|
+
lifetimeOwner[1].add(() => {
|
|
1672
|
+
removeUpdater();
|
|
1673
|
+
disposeResource();
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
export function compiledEffect(scope, reads, readCreate, readDependencies, passive = true) {
|
|
1677
|
+
const owner = activeConstructionOwner;
|
|
1678
|
+
if (owner === null || scopeOwners.get(scope) !== owner) {
|
|
1679
|
+
throw new Error(DEV ? 'compiled effects must run in their component scope' : 'V016');
|
|
1680
|
+
}
|
|
1681
|
+
const lifetimeOwner = activeOwner ?? owner;
|
|
1682
|
+
if (!retainedUiEnabled) {
|
|
1683
|
+
let mounted = false;
|
|
1684
|
+
let generation = 0;
|
|
1685
|
+
let currentDependencies;
|
|
1686
|
+
let cleanup = noop;
|
|
1687
|
+
const run = () => {
|
|
1688
|
+
const nextDependencies = readDependencies?.();
|
|
1689
|
+
if (mounted &&
|
|
1690
|
+
readDependencies !== undefined &&
|
|
1691
|
+
equalDependencies(nextDependencies, currentDependencies)) {
|
|
1692
|
+
return;
|
|
1693
|
+
}
|
|
1694
|
+
cleanup();
|
|
1695
|
+
cleanup = profilingEnabled
|
|
1696
|
+
? readProfiledEffectCleanup(owner, () => readCreate()())
|
|
1697
|
+
: readEffectCleanup(readCreate()());
|
|
1698
|
+
currentDependencies = nextDependencies;
|
|
1699
|
+
mounted = true;
|
|
1700
|
+
};
|
|
1701
|
+
const schedule = () => {
|
|
1702
|
+
if (!passive) {
|
|
1703
|
+
run();
|
|
1704
|
+
return;
|
|
1705
|
+
}
|
|
1706
|
+
const scheduled = ++generation;
|
|
1707
|
+
(DEV ? scheduleTask : queueMicrotask)(() => {
|
|
1708
|
+
if (!lifetimeOwner[0] && scheduled === generation)
|
|
1709
|
+
runOwnerTask(lifetimeOwner, run);
|
|
1710
|
+
});
|
|
1711
|
+
};
|
|
1712
|
+
queueOwnerCommit(owner, () => {
|
|
1713
|
+
if (!lifetimeOwner[0])
|
|
1714
|
+
schedule();
|
|
1715
|
+
});
|
|
1716
|
+
const removeUpdater = subscribe(scope, reads, () => {
|
|
1717
|
+
if (passive)
|
|
1718
|
+
schedule();
|
|
1719
|
+
else
|
|
1720
|
+
stagePublication([noop, noop, undefined, run, 20]);
|
|
1721
|
+
});
|
|
1722
|
+
lifetimeOwner[1].add(() => {
|
|
1723
|
+
generation += 1;
|
|
1724
|
+
removeUpdater();
|
|
1725
|
+
if (passive)
|
|
1726
|
+
(DEV ? scheduleTask : queueMicrotask)(() => runOwnerTask(lifetimeOwner, cleanup));
|
|
1727
|
+
else
|
|
1728
|
+
cleanup();
|
|
1729
|
+
});
|
|
1730
|
+
return;
|
|
1731
|
+
}
|
|
1732
|
+
let mounted = false;
|
|
1733
|
+
let connected = false;
|
|
1734
|
+
let generation = 0;
|
|
1735
|
+
let currentDependencies;
|
|
1736
|
+
let cleanup = noop;
|
|
1737
|
+
const run = () => {
|
|
1738
|
+
const nextDependencies = readDependencies?.();
|
|
1739
|
+
if (mounted &&
|
|
1740
|
+
readDependencies !== undefined &&
|
|
1741
|
+
equalDependencies(nextDependencies, currentDependencies)) {
|
|
1742
|
+
return;
|
|
1743
|
+
}
|
|
1744
|
+
cleanup();
|
|
1745
|
+
cleanup = profilingEnabled
|
|
1746
|
+
? readProfiledEffectCleanup(owner, () => readCreate()())
|
|
1747
|
+
: readEffectCleanup(readCreate()());
|
|
1748
|
+
currentDependencies = nextDependencies;
|
|
1749
|
+
mounted = true;
|
|
1750
|
+
};
|
|
1751
|
+
const schedule = () => {
|
|
1752
|
+
if (!connected)
|
|
1753
|
+
return;
|
|
1754
|
+
if (!passive) {
|
|
1755
|
+
run();
|
|
1756
|
+
return;
|
|
1757
|
+
}
|
|
1758
|
+
const scheduled = ++generation;
|
|
1759
|
+
(DEV ? scheduleTask : queueMicrotask)(() => {
|
|
1760
|
+
if (!lifetimeOwner[0] && scheduled === generation)
|
|
1761
|
+
runOwnerTask(lifetimeOwner, run);
|
|
1762
|
+
});
|
|
1763
|
+
};
|
|
1764
|
+
const [activate, disposeResource] = createRetainedResource(lifetimeOwner, () => {
|
|
1765
|
+
stagePublication([
|
|
1766
|
+
noop,
|
|
1767
|
+
noop,
|
|
1768
|
+
undefined,
|
|
1769
|
+
() => {
|
|
1770
|
+
connected = true;
|
|
1771
|
+
schedule();
|
|
1772
|
+
},
|
|
1773
|
+
passive ? 40 : 20,
|
|
1774
|
+
]);
|
|
1775
|
+
}, () => {
|
|
1776
|
+
connected = false;
|
|
1777
|
+
generation += 1;
|
|
1778
|
+
const previousCleanup = cleanup;
|
|
1779
|
+
cleanup = noop;
|
|
1780
|
+
mounted = false;
|
|
1781
|
+
if (passive)
|
|
1782
|
+
(DEV ? scheduleTask : queueMicrotask)(() => runOwnerTask(lifetimeOwner, previousCleanup));
|
|
1783
|
+
else
|
|
1784
|
+
previousCleanup();
|
|
1785
|
+
});
|
|
1786
|
+
queueOwnerCommit(owner, () => {
|
|
1787
|
+
if (!lifetimeOwner[0])
|
|
1788
|
+
activate();
|
|
1789
|
+
});
|
|
1790
|
+
const removeUpdater = subscribe(scope, reads, () => {
|
|
1791
|
+
if (!connected)
|
|
1792
|
+
return;
|
|
1793
|
+
if (passive)
|
|
1794
|
+
schedule();
|
|
1795
|
+
else
|
|
1796
|
+
stagePublication([noop, noop, undefined, run, 20]);
|
|
1797
|
+
});
|
|
1798
|
+
lifetimeOwner[1].add(() => {
|
|
1799
|
+
removeUpdater();
|
|
1800
|
+
disposeResource();
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
function readEffectCleanup(result) {
|
|
1804
|
+
if (result === undefined)
|
|
1805
|
+
return noop;
|
|
1806
|
+
if (typeof result === 'function')
|
|
1807
|
+
return result;
|
|
1808
|
+
throw new TypeError(DEV ? 'an effect must return a cleanup function or undefined' : 'V018');
|
|
1809
|
+
}
|
|
1810
|
+
export function compiledImperativeHandle(scope, reads, readRef, create, readDependencies) {
|
|
1811
|
+
const owner = activeConstructionOwner;
|
|
1812
|
+
if (owner === null || scopeOwners.get(scope) !== owner) {
|
|
1813
|
+
throw new Error(DEV ? 'compiledImperativeHandle must run in its compiled component scope' : 'V013');
|
|
1814
|
+
}
|
|
1815
|
+
let mounted = false;
|
|
1816
|
+
let currentRef;
|
|
1817
|
+
let currentHandle;
|
|
1818
|
+
let currentDependencies;
|
|
1819
|
+
// oxlint-disable-next-line unicorn/consistent-function-scoping -- This placeholder is replaced by the committed resource cleanup.
|
|
1820
|
+
let cleanup = noop;
|
|
1821
|
+
const commitInitial = () => {
|
|
1822
|
+
currentRef = readImperativeRef(readRef());
|
|
1823
|
+
currentDependencies = readDependencies?.();
|
|
1824
|
+
currentHandle = create();
|
|
1825
|
+
cleanup = attachRef(currentRef, currentHandle);
|
|
1826
|
+
mounted = true;
|
|
1827
|
+
};
|
|
1828
|
+
queueOwnerCommit(owner, commitInitial);
|
|
1829
|
+
const update = () => {
|
|
1830
|
+
if (!mounted)
|
|
1831
|
+
return;
|
|
1832
|
+
const nextRef = readImperativeRef(readRef());
|
|
1833
|
+
const nextDependencies = readDependencies?.();
|
|
1834
|
+
if (Object.is(nextRef, currentRef) &&
|
|
1835
|
+
readDependencies !== undefined &&
|
|
1836
|
+
equalDependencies(nextDependencies, currentDependencies)) {
|
|
1837
|
+
return;
|
|
1838
|
+
}
|
|
1839
|
+
const previousRef = currentRef;
|
|
1840
|
+
const previousHandle = currentHandle;
|
|
1841
|
+
const previousDependencies = currentDependencies;
|
|
1842
|
+
const previousCleanup = cleanup;
|
|
1843
|
+
let nextCleanup;
|
|
1844
|
+
let finalized = false;
|
|
1845
|
+
stagePublication([
|
|
1846
|
+
noop,
|
|
1847
|
+
() => {
|
|
1848
|
+
if (!finalized)
|
|
1849
|
+
return;
|
|
1850
|
+
nextCleanup?.();
|
|
1851
|
+
cleanup = attachRef(previousRef, previousHandle);
|
|
1852
|
+
currentRef = previousRef;
|
|
1853
|
+
currentHandle = previousHandle;
|
|
1854
|
+
currentDependencies = previousDependencies;
|
|
1855
|
+
finalized = false;
|
|
1856
|
+
},
|
|
1857
|
+
undefined,
|
|
1858
|
+
() => {
|
|
1859
|
+
const nextHandle = create();
|
|
1860
|
+
if (Object.is(nextRef, previousRef)) {
|
|
1861
|
+
try {
|
|
1862
|
+
previousCleanup();
|
|
1863
|
+
}
|
|
1864
|
+
catch (error) {
|
|
1865
|
+
try {
|
|
1866
|
+
cleanup = attachRef(previousRef, previousHandle);
|
|
1867
|
+
}
|
|
1868
|
+
catch {
|
|
1869
|
+
// Preserve the cleanup error that aborted publication.
|
|
1870
|
+
}
|
|
1871
|
+
throw error;
|
|
1872
|
+
}
|
|
1873
|
+
try {
|
|
1874
|
+
nextCleanup = attachRef(nextRef, nextHandle);
|
|
1875
|
+
}
|
|
1876
|
+
catch (error) {
|
|
1877
|
+
try {
|
|
1878
|
+
cleanup = attachRef(previousRef, previousHandle);
|
|
1879
|
+
}
|
|
1880
|
+
catch {
|
|
1881
|
+
// Preserve the next-ref attachment error.
|
|
1882
|
+
}
|
|
1883
|
+
throw error;
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
else {
|
|
1887
|
+
nextCleanup = attachRef(nextRef, nextHandle);
|
|
1888
|
+
try {
|
|
1889
|
+
previousCleanup();
|
|
1890
|
+
}
|
|
1891
|
+
catch (error) {
|
|
1892
|
+
nextCleanup();
|
|
1893
|
+
try {
|
|
1894
|
+
cleanup = attachRef(previousRef, previousHandle);
|
|
1895
|
+
}
|
|
1896
|
+
catch {
|
|
1897
|
+
// Preserve the previous-ref cleanup error.
|
|
1898
|
+
}
|
|
1899
|
+
throw error;
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
cleanup = nextCleanup;
|
|
1903
|
+
currentRef = nextRef;
|
|
1904
|
+
currentHandle = nextHandle;
|
|
1905
|
+
currentDependencies = nextDependencies;
|
|
1906
|
+
finalized = true;
|
|
1907
|
+
},
|
|
1908
|
+
10,
|
|
1909
|
+
]);
|
|
1910
|
+
};
|
|
1911
|
+
const removeUpdater = subscribe(scope, reads, update);
|
|
1912
|
+
owner[1].add(() => {
|
|
1913
|
+
removeUpdater();
|
|
1914
|
+
cleanup();
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1917
|
+
function queueOwnerCommit(owner, commit) {
|
|
1918
|
+
let commits = pendingOwnerCommits.get(owner);
|
|
1919
|
+
if (commits === undefined) {
|
|
1920
|
+
commits = new Set();
|
|
1921
|
+
pendingOwnerCommits.set(owner, commits);
|
|
1922
|
+
}
|
|
1923
|
+
commits.add(commit);
|
|
1924
|
+
}
|
|
1925
|
+
function queueInsertionCommit(owner, commit) {
|
|
1926
|
+
let commits = pendingInsertionCommits.get(owner);
|
|
1927
|
+
if (commits === undefined) {
|
|
1928
|
+
commits = new Set();
|
|
1929
|
+
pendingInsertionCommits.set(owner, commits);
|
|
1930
|
+
}
|
|
1931
|
+
commits.add(commit);
|
|
1932
|
+
}
|
|
1933
|
+
function readImperativeRef(ref) {
|
|
1934
|
+
if (!isRefValue(ref)) {
|
|
1935
|
+
throw new TypeError(DEV ? 'imperative ref must be null, a callback, or an object with current' : 'V006');
|
|
1936
|
+
}
|
|
1937
|
+
return ref;
|
|
1938
|
+
}
|
|
1939
|
+
function equalDependencies(next, previous) {
|
|
1940
|
+
if (next === undefined || previous === undefined || next.length !== previous.length)
|
|
1941
|
+
return false;
|
|
1942
|
+
return next.every((value, index) => Object.is(value, previous[index]));
|
|
1943
|
+
}
|
|
1944
|
+
export function mountCompiledRef(element, value) {
|
|
1945
|
+
const initial = value[1]();
|
|
1946
|
+
if (!isRefValue(initial)) {
|
|
1947
|
+
throw new TypeError(DEV ? 'ref must be null, a callback, or an object with current' : 'V006');
|
|
1948
|
+
}
|
|
1949
|
+
let current = initial;
|
|
1950
|
+
// oxlint-disable-next-line unicorn/consistent-function-scoping -- This placeholder is replaced when the ref attaches.
|
|
1951
|
+
let cleanup = noop;
|
|
1952
|
+
const pending = [activeOwner, current, (attached) => (cleanup = attached)];
|
|
1953
|
+
pendingRefs.set(element, pending);
|
|
1954
|
+
const removeUpdater = subscribeBinding(value, () => {
|
|
1955
|
+
const next = value[1]();
|
|
1956
|
+
if (Object.is(next, current))
|
|
1957
|
+
return;
|
|
1958
|
+
if (!isRefValue(next)) {
|
|
1959
|
+
throw new TypeError(DEV ? 'ref must be null, a callback, or an object with current' : 'V006');
|
|
1960
|
+
}
|
|
1961
|
+
const previous = current;
|
|
1962
|
+
let nextCleanup;
|
|
1963
|
+
let committed = false;
|
|
1964
|
+
stagePublication([
|
|
1965
|
+
() => {
|
|
1966
|
+
nextCleanup = attachRef(next, element);
|
|
1967
|
+
cleanup();
|
|
1968
|
+
cleanup = nextCleanup;
|
|
1969
|
+
current = next;
|
|
1970
|
+
committed = true;
|
|
1971
|
+
},
|
|
1972
|
+
() => {
|
|
1973
|
+
if (!committed) {
|
|
1974
|
+
nextCleanup?.();
|
|
1975
|
+
return;
|
|
1976
|
+
}
|
|
1977
|
+
cleanup();
|
|
1978
|
+
cleanup = attachRef(previous, element);
|
|
1979
|
+
current = previous;
|
|
1980
|
+
committed = false;
|
|
1981
|
+
},
|
|
1982
|
+
]);
|
|
1983
|
+
});
|
|
1984
|
+
onCleanup(() => {
|
|
1985
|
+
removeUpdater();
|
|
1986
|
+
if (pendingRefs.get(element) === pending)
|
|
1987
|
+
pendingRefs.delete(element);
|
|
1988
|
+
cleanup();
|
|
1989
|
+
});
|
|
1990
|
+
}
|
|
1991
|
+
export function registerCompiledCleanup(cleanup) {
|
|
1992
|
+
onCleanup(cleanup);
|
|
1993
|
+
}
|
|
1994
|
+
export function hydrateCompiled(component, host, options) {
|
|
1995
|
+
let endHydration;
|
|
1996
|
+
let hydratedMount;
|
|
1997
|
+
try {
|
|
1998
|
+
endHydration = beginHydration(host);
|
|
1999
|
+
hydratedMount = mountCompiled(component, host, options);
|
|
2000
|
+
finishHydration();
|
|
2001
|
+
const rootMarkers = hydrationRootMarkers();
|
|
2002
|
+
return {
|
|
2003
|
+
dispose: () => {
|
|
2004
|
+
try {
|
|
2005
|
+
hydratedMount?.dispose();
|
|
2006
|
+
}
|
|
2007
|
+
finally {
|
|
2008
|
+
removeBetween(rootMarkers[0], rootMarkers[1]);
|
|
2009
|
+
rootMarkers[0].remove();
|
|
2010
|
+
rootMarkers[1].remove();
|
|
2011
|
+
}
|
|
2012
|
+
},
|
|
2013
|
+
};
|
|
2014
|
+
}
|
|
2015
|
+
catch (error) {
|
|
2016
|
+
if (!isHydrationMismatch(error))
|
|
2017
|
+
throw error;
|
|
2018
|
+
try {
|
|
2019
|
+
hydratedMount?.dispose();
|
|
2020
|
+
}
|
|
2021
|
+
catch {
|
|
2022
|
+
// Preserve and report the mismatch that forced recovery.
|
|
2023
|
+
}
|
|
2024
|
+
hydratedMount = undefined;
|
|
2025
|
+
endHydration?.();
|
|
2026
|
+
endHydration = undefined;
|
|
2027
|
+
options?.onRecoverableError?.(error);
|
|
2028
|
+
return mountCompiled(component, host, options);
|
|
2029
|
+
}
|
|
2030
|
+
finally {
|
|
2031
|
+
endHydration?.();
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
export function mountCompiled(component, host, options) {
|
|
2035
|
+
const hydrating = isHydrating();
|
|
2036
|
+
const previousRootIdentity = activeRootIdentity;
|
|
2037
|
+
const rootIdentity = createRootIdentity(options?.identifierPrefix, options?.onCaughtError, options?.onUncaughtError);
|
|
2038
|
+
activeRootIdentity = rootIdentity;
|
|
2039
|
+
let root;
|
|
2040
|
+
try {
|
|
2041
|
+
root = constructCompiledComponent(component);
|
|
2042
|
+
}
|
|
2043
|
+
catch (error) {
|
|
2044
|
+
if (isHydrationMismatch(error))
|
|
2045
|
+
throw error;
|
|
2046
|
+
if (rootIdentity.onUncaughtError === undefined)
|
|
2047
|
+
throw error;
|
|
2048
|
+
rootIdentity.onUncaughtError(error);
|
|
2049
|
+
return { dispose: noop };
|
|
2050
|
+
}
|
|
2051
|
+
finally {
|
|
2052
|
+
activeRootIdentity = previousRootIdentity;
|
|
2053
|
+
}
|
|
2054
|
+
const range = componentRanges.get(root);
|
|
2055
|
+
if (range === undefined) {
|
|
2056
|
+
throw new Error(DEV ? 'mountCompiled received an unknown component result' : 'V007');
|
|
2057
|
+
}
|
|
2058
|
+
const previous = [...host.childNodes];
|
|
2059
|
+
try {
|
|
2060
|
+
root[1](host, previous[0] ?? null);
|
|
2061
|
+
const rootOwner = scopeOwners.get(range[2]);
|
|
2062
|
+
const mountedRootIdentity = rootOwner?.[3];
|
|
2063
|
+
if (mountedRootIdentity !== undefined) {
|
|
2064
|
+
mountedRootIdentity.mounted = true;
|
|
2065
|
+
commitRootPortals(mountedRootIdentity);
|
|
2066
|
+
}
|
|
2067
|
+
commitOwnerInsertions(rootOwner);
|
|
2068
|
+
commitRangeRefs(range[0], range[1]);
|
|
2069
|
+
commitOwnerResources(rootOwner);
|
|
2070
|
+
if (!hydrating) {
|
|
2071
|
+
for (const node of previous)
|
|
2072
|
+
host.removeChild(node);
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
catch (error) {
|
|
2076
|
+
try {
|
|
2077
|
+
range[2][3]();
|
|
2078
|
+
}
|
|
2079
|
+
catch {
|
|
2080
|
+
// Preserve the mount error while still running every component cleanup.
|
|
2081
|
+
}
|
|
2082
|
+
if (isHydrationMismatch(error) || rootIdentity.onUncaughtError === undefined)
|
|
2083
|
+
throw error;
|
|
2084
|
+
rootIdentity.onUncaughtError(error);
|
|
2085
|
+
return { dispose: noop };
|
|
2086
|
+
}
|
|
2087
|
+
return {
|
|
2088
|
+
dispose: range[2][3],
|
|
2089
|
+
};
|
|
2090
|
+
}
|
|
2091
|
+
export function isCompiledBinding(value) {
|
|
2092
|
+
return Array.isArray(value) && value[0] === BINDING;
|
|
2093
|
+
}
|
|
2094
|
+
export function isStructuralBinding(value) {
|
|
2095
|
+
return Array.isArray(value) && value[0] === STRUCTURAL;
|
|
2096
|
+
}
|
|
2097
|
+
export function isCompiledComponentResult(value) {
|
|
2098
|
+
return isStructuralBinding(value) && componentRanges.has(value);
|
|
2099
|
+
}
|
|
2100
|
+
export function mountCompiledBinding(parent, value) {
|
|
2101
|
+
mountCompiledBindingBefore(parent, value, null);
|
|
2102
|
+
}
|
|
2103
|
+
export function mountCompiledProp(value, apply) {
|
|
2104
|
+
let current = value[1]();
|
|
2105
|
+
let cleanup = apply(current);
|
|
2106
|
+
const removeUpdater = subscribeBinding(value, () => {
|
|
2107
|
+
const next = value[1]();
|
|
2108
|
+
if (Object.is(next, current))
|
|
2109
|
+
return;
|
|
2110
|
+
const previous = current;
|
|
2111
|
+
let nextCleanup;
|
|
2112
|
+
let committedNext = false;
|
|
2113
|
+
stagePublication([
|
|
2114
|
+
() => {
|
|
2115
|
+
try {
|
|
2116
|
+
nextCleanup = apply(next);
|
|
2117
|
+
}
|
|
2118
|
+
catch (error) {
|
|
2119
|
+
try {
|
|
2120
|
+
apply(previous);
|
|
2121
|
+
}
|
|
2122
|
+
catch {
|
|
2123
|
+
// Preserve the setter error that aborted publication.
|
|
2124
|
+
}
|
|
2125
|
+
throw error;
|
|
2126
|
+
}
|
|
2127
|
+
committedNext = true;
|
|
2128
|
+
cleanup?.();
|
|
2129
|
+
cleanup = nextCleanup;
|
|
2130
|
+
current = next;
|
|
2131
|
+
},
|
|
2132
|
+
() => {
|
|
2133
|
+
if (!committedNext)
|
|
2134
|
+
return;
|
|
2135
|
+
nextCleanup?.();
|
|
2136
|
+
cleanup = apply(previous);
|
|
2137
|
+
current = previous;
|
|
2138
|
+
committedNext = false;
|
|
2139
|
+
},
|
|
2140
|
+
]);
|
|
2141
|
+
});
|
|
2142
|
+
onCleanup(() => {
|
|
2143
|
+
removeUpdater();
|
|
2144
|
+
cleanup?.();
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
2147
|
+
export function mountCompiledPropTransition(value, initialize, prepare) {
|
|
2148
|
+
let current = value[1]();
|
|
2149
|
+
initialize(current);
|
|
2150
|
+
const removeUpdater = subscribeBinding(value, () => {
|
|
2151
|
+
const next = value[1]();
|
|
2152
|
+
if (Object.is(next, current))
|
|
2153
|
+
return;
|
|
2154
|
+
const previous = current;
|
|
2155
|
+
const transition = prepare(next, previous);
|
|
2156
|
+
let attempted = false;
|
|
2157
|
+
stagePublication([
|
|
2158
|
+
() => {
|
|
2159
|
+
attempted = true;
|
|
2160
|
+
transition?.[0]();
|
|
2161
|
+
current = next;
|
|
2162
|
+
},
|
|
2163
|
+
() => {
|
|
2164
|
+
if (!attempted)
|
|
2165
|
+
return;
|
|
2166
|
+
try {
|
|
2167
|
+
transition?.[1]();
|
|
2168
|
+
}
|
|
2169
|
+
finally {
|
|
2170
|
+
current = previous;
|
|
2171
|
+
attempted = false;
|
|
2172
|
+
}
|
|
2173
|
+
},
|
|
2174
|
+
transition?.[2],
|
|
2175
|
+
transition?.[3],
|
|
2176
|
+
transition?.[4],
|
|
2177
|
+
]);
|
|
2178
|
+
});
|
|
2179
|
+
onCleanup(removeUpdater);
|
|
2180
|
+
}
|
|
2181
|
+
function structural(scope, mount, hydrationKind) {
|
|
2182
|
+
if (hydrationKind !== undefined)
|
|
2183
|
+
noteHydrationStructuralParent();
|
|
2184
|
+
let mounted = false;
|
|
2185
|
+
const owner = activeOwner ?? scopeOwners.get(scope);
|
|
2186
|
+
const context = activeContextFrame ?? owner[2];
|
|
2187
|
+
const mountOnce = (parent, before) => {
|
|
2188
|
+
if (mounted)
|
|
2189
|
+
throw new Error(DEV ? 'compiled block is already mounted' : 'V008');
|
|
2190
|
+
mounted = true;
|
|
2191
|
+
const operation = () => withOwner(owner, () => withContextFrame(context, () => withScopeNamespace(scope, () => mount(parent, before))));
|
|
2192
|
+
if (profilingEnabled)
|
|
2193
|
+
measureProfileWork(owner, 'range', operation);
|
|
2194
|
+
else
|
|
2195
|
+
operation();
|
|
2196
|
+
};
|
|
2197
|
+
return hydrationKind === undefined
|
|
2198
|
+
? [STRUCTURAL, mountOnce]
|
|
2199
|
+
: [STRUCTURAL, mountOnce, hydrationKind];
|
|
2200
|
+
}
|
|
2201
|
+
function structuralRange(parent, before, label) {
|
|
2202
|
+
const hydrated = claimHydrationSlotRange(parent);
|
|
2203
|
+
if (hydrated !== undefined)
|
|
2204
|
+
return [hydrated[0], hydrated[1], true];
|
|
2205
|
+
const start = document.createComment(DEV ? `vidact:${label}` : '');
|
|
2206
|
+
const end = document.createComment(DEV ? `/vidact:${label}` : '');
|
|
2207
|
+
parent.insertBefore(start, before);
|
|
2208
|
+
parent.insertBefore(end, before);
|
|
2209
|
+
return [start, end, false];
|
|
2210
|
+
}
|
|
2211
|
+
function subscribe(scope, reads, run, additionalScope, additionalReads) {
|
|
2212
|
+
const removers = [scope[0](reads, run)];
|
|
2213
|
+
if (additionalScope !== undefined && additionalReads !== undefined) {
|
|
2214
|
+
removers.push(additionalScope[0](additionalReads, () => withScopeNamespace(scope, run)));
|
|
2215
|
+
}
|
|
2216
|
+
return () => {
|
|
2217
|
+
for (const remove of removers)
|
|
2218
|
+
remove();
|
|
2219
|
+
};
|
|
2220
|
+
}
|
|
2221
|
+
function subscribeBinding(compiledBinding, run) {
|
|
2222
|
+
return subscribe(compiledBinding[2], compiledBinding[3], run, compiledBinding[4], compiledBinding[5]);
|
|
2223
|
+
}
|
|
2224
|
+
function withScopeNamespace(scope, operation) {
|
|
2225
|
+
return withIntrinsicNamespace(scopeNamespaces.get(scope), operation);
|
|
2226
|
+
}
|
|
2227
|
+
function createOwner(context = activeContextFrame ?? activeOwner?.[2] ?? null, rootIdentity = activeOwner?.[3] ?? activeRootIdentity ?? createRootIdentity(), boundary = activeOwner?.[4] ?? null, retainedConnection = activeOwner?.[5] ?? null, profileContext = activeOwner?.[6] ?? activeConstructionOwner?.[6] ?? null) {
|
|
2228
|
+
if (DEV) {
|
|
2229
|
+
activeOwnerCount += 1;
|
|
2230
|
+
createdOwnerCount += 1;
|
|
2231
|
+
}
|
|
2232
|
+
let nextProfile = profileContext;
|
|
2233
|
+
if (profilingEnabled && activeProfileName !== null && activeConstructionOwner === null) {
|
|
2234
|
+
nextProfile = {
|
|
2235
|
+
frame: {
|
|
2236
|
+
name: activeProfileName,
|
|
2237
|
+
parent: profileContext?.frame ?? null,
|
|
2238
|
+
values: [],
|
|
2239
|
+
},
|
|
2240
|
+
boundary: profileContext?.boundary ?? null,
|
|
2241
|
+
};
|
|
2242
|
+
}
|
|
2243
|
+
if (profilingEnabled) {
|
|
2244
|
+
const owner = [
|
|
2245
|
+
false,
|
|
2246
|
+
new Set(),
|
|
2247
|
+
context,
|
|
2248
|
+
rootIdentity,
|
|
2249
|
+
boundary,
|
|
2250
|
+
retainedUiEnabled ? retainedConnection : null,
|
|
2251
|
+
nextProfile,
|
|
2252
|
+
];
|
|
2253
|
+
if (DEV)
|
|
2254
|
+
owner[7] = activeConstructionOwner?.[7] ?? activeProfileName;
|
|
2255
|
+
return owner;
|
|
2256
|
+
}
|
|
2257
|
+
const owner = retainedUiEnabled
|
|
2258
|
+
? [false, new Set(), context, rootIdentity, boundary, retainedConnection]
|
|
2259
|
+
: [false, new Set(), context, rootIdentity, boundary];
|
|
2260
|
+
if (DEV)
|
|
2261
|
+
owner[7] = activeConstructionOwner?.[7] ?? activeProfileName;
|
|
2262
|
+
return owner;
|
|
2263
|
+
}
|
|
2264
|
+
function ensureProfileContext(owner) {
|
|
2265
|
+
const current = owner[6];
|
|
2266
|
+
if (current?.frame !== null && current?.frame !== undefined)
|
|
2267
|
+
return current;
|
|
2268
|
+
const parent = current ?? (activeOwner !== null && activeOwner !== owner ? (activeOwner[6] ?? null) : null);
|
|
2269
|
+
const next = {
|
|
2270
|
+
frame: {
|
|
2271
|
+
name: owner[7] ?? activeProfileName ?? 'Anonymous',
|
|
2272
|
+
parent: parent?.frame ?? null,
|
|
2273
|
+
values: [],
|
|
2274
|
+
},
|
|
2275
|
+
boundary: parent?.boundary ?? null,
|
|
2276
|
+
};
|
|
2277
|
+
owner[6] = next;
|
|
2278
|
+
return next;
|
|
2279
|
+
}
|
|
2280
|
+
function profileNow() {
|
|
2281
|
+
return typeof performance === 'undefined' ? Date.now() : performance.now();
|
|
2282
|
+
}
|
|
2283
|
+
function measureProfileWork(owner, kind, operation, contribute = false) {
|
|
2284
|
+
const started = profileNow();
|
|
2285
|
+
try {
|
|
2286
|
+
return operation();
|
|
2287
|
+
}
|
|
2288
|
+
finally {
|
|
2289
|
+
const finished = profileNow();
|
|
2290
|
+
emitProfileMeasure(owner, kind, started, finished);
|
|
2291
|
+
if (contribute)
|
|
2292
|
+
recordProfileCommit(owner, started, finished);
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
function emitProfileMeasure(owner, kind, started, finished) {
|
|
2296
|
+
if (typeof performance === 'undefined' || typeof performance.measure !== 'function')
|
|
2297
|
+
return;
|
|
2298
|
+
const component = owner[6]?.frame?.name ?? 'Anonymous';
|
|
2299
|
+
performance.measure(`vidact.${kind}:${component}`, { start: started, end: finished });
|
|
2300
|
+
}
|
|
2301
|
+
function recordProfileCommit(owner, started, finished) {
|
|
2302
|
+
let boundary = owner[6]?.boundary ?? null;
|
|
2303
|
+
while (boundary !== null) {
|
|
2304
|
+
queueProfileBoundaryCommit(boundary, owner, started, finished);
|
|
2305
|
+
boundary = boundary.parent;
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
function queueProfileBoundaryCommit(boundary, owner, started, finished) {
|
|
2309
|
+
if (!boundary.mounted)
|
|
2310
|
+
return;
|
|
2311
|
+
boundary.pendingDuration += finished - started;
|
|
2312
|
+
boundary.pendingStart =
|
|
2313
|
+
boundary.pendingStart === 0 ? started : Math.min(boundary.pendingStart, started);
|
|
2314
|
+
if (boundary.scheduled)
|
|
2315
|
+
return;
|
|
2316
|
+
boundary.scheduled = true;
|
|
2317
|
+
stagePublication([
|
|
2318
|
+
noop,
|
|
2319
|
+
noop,
|
|
2320
|
+
undefined,
|
|
2321
|
+
() => {
|
|
2322
|
+
const actualDuration = boundary.pendingDuration;
|
|
2323
|
+
const startTime = boundary.pendingStart;
|
|
2324
|
+
boundary.pendingDuration = 0;
|
|
2325
|
+
boundary.pendingStart = 0;
|
|
2326
|
+
boundary.scheduled = false;
|
|
2327
|
+
boundary.onRender(boundary.id, 'update', actualDuration, boundary.baseDuration, startTime, profileNow());
|
|
2328
|
+
},
|
|
2329
|
+
100,
|
|
2330
|
+
owner,
|
|
2331
|
+
]);
|
|
2332
|
+
}
|
|
2333
|
+
function readProfiledEffectCleanup(owner, evaluate) {
|
|
2334
|
+
const cleanup = measureProfileWork(owner, 'effect', () => readEffectCleanup(evaluate()));
|
|
2335
|
+
if (cleanup === noop)
|
|
2336
|
+
return cleanup;
|
|
2337
|
+
return () => measureProfileWork(owner, 'effect', cleanup);
|
|
2338
|
+
}
|
|
2339
|
+
function createRetainedConnection(parent, visible) {
|
|
2340
|
+
const connection = {
|
|
2341
|
+
parent,
|
|
2342
|
+
children: new Set(),
|
|
2343
|
+
resources: new Set(),
|
|
2344
|
+
deferredFlushes: new Map(),
|
|
2345
|
+
afterFlush: new Set(),
|
|
2346
|
+
visible,
|
|
2347
|
+
connected: visible && (parent?.connected ?? true),
|
|
2348
|
+
disposed: false,
|
|
2349
|
+
};
|
|
2350
|
+
parent?.children.add(connection);
|
|
2351
|
+
return connection;
|
|
2352
|
+
}
|
|
2353
|
+
function createRetainedResource(owner, connect, disconnect, phase = 1) {
|
|
2354
|
+
const connection = owner[5];
|
|
2355
|
+
const resource = {
|
|
2356
|
+
owner,
|
|
2357
|
+
connect,
|
|
2358
|
+
disconnect,
|
|
2359
|
+
active: false,
|
|
2360
|
+
connected: false,
|
|
2361
|
+
disposed: false,
|
|
2362
|
+
phase,
|
|
2363
|
+
};
|
|
2364
|
+
connection?.resources.add(resource);
|
|
2365
|
+
const activate = () => {
|
|
2366
|
+
if (resource.disposed)
|
|
2367
|
+
return;
|
|
2368
|
+
resource.active = true;
|
|
2369
|
+
reconcileRetainedResource(resource, connection?.connected ?? true);
|
|
2370
|
+
};
|
|
2371
|
+
const dispose = () => {
|
|
2372
|
+
if (resource.disposed)
|
|
2373
|
+
return;
|
|
2374
|
+
resource.disposed = true;
|
|
2375
|
+
resource.active = false;
|
|
2376
|
+
connection?.resources.delete(resource);
|
|
2377
|
+
reconcileRetainedResource(resource, false);
|
|
2378
|
+
};
|
|
2379
|
+
return [activate, dispose];
|
|
2380
|
+
}
|
|
2381
|
+
function reconcileRetainedResource(resource, connected) {
|
|
2382
|
+
const nextConnected = !resource.disposed && resource.active && connected;
|
|
2383
|
+
if (resource.connected === nextConnected)
|
|
2384
|
+
return;
|
|
2385
|
+
resource.connected = nextConnected;
|
|
2386
|
+
try {
|
|
2387
|
+
runOwnerTask(resource.owner, nextConnected ? resource.connect : resource.disconnect);
|
|
2388
|
+
}
|
|
2389
|
+
catch (error) {
|
|
2390
|
+
resource.connected = false;
|
|
2391
|
+
throw error;
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
function updateRetainedConnection(connection) {
|
|
2395
|
+
if (connection.disposed)
|
|
2396
|
+
return;
|
|
2397
|
+
const nextConnected = connection.visible && (connection.parent?.connected ?? true);
|
|
2398
|
+
if (connection.connected === nextConnected)
|
|
2399
|
+
return;
|
|
2400
|
+
connection.connected = nextConnected;
|
|
2401
|
+
if (nextConnected) {
|
|
2402
|
+
for (const [flush, cancel] of connection.deferredFlushes) {
|
|
2403
|
+
cancel();
|
|
2404
|
+
scheduleFlush(flush);
|
|
2405
|
+
}
|
|
2406
|
+
connection.deferredFlushes.clear();
|
|
2407
|
+
for (const resource of [...connection.resources].toSorted((left, right) => left.phase - right.phase)) {
|
|
2408
|
+
reconcileRetainedResource(resource, true);
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
else {
|
|
2412
|
+
for (const resource of [...connection.resources].toReversed()) {
|
|
2413
|
+
reconcileRetainedResource(resource, false);
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
for (const child of connection.children)
|
|
2417
|
+
updateRetainedConnection(child);
|
|
2418
|
+
}
|
|
2419
|
+
function concealDisconnectedDescendants(connection) {
|
|
2420
|
+
for (const child of connection.children) {
|
|
2421
|
+
if (!child.connected) {
|
|
2422
|
+
for (const conceal of child.afterFlush)
|
|
2423
|
+
conceal();
|
|
2424
|
+
}
|
|
2425
|
+
concealDisconnectedDescendants(child);
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
function disposeRetainedConnection(connection) {
|
|
2429
|
+
if (connection.disposed)
|
|
2430
|
+
return;
|
|
2431
|
+
connection.disposed = true;
|
|
2432
|
+
connection.parent?.children.delete(connection);
|
|
2433
|
+
for (const cancel of connection.deferredFlushes.values())
|
|
2434
|
+
cancel();
|
|
2435
|
+
connection.deferredFlushes.clear();
|
|
2436
|
+
connection.afterFlush.clear();
|
|
2437
|
+
for (const child of connection.children)
|
|
2438
|
+
disposeRetainedConnection(child);
|
|
2439
|
+
connection.children.clear();
|
|
2440
|
+
for (const resource of [...connection.resources].toReversed()) {
|
|
2441
|
+
resource.disposed = true;
|
|
2442
|
+
resource.active = false;
|
|
2443
|
+
reconcileRetainedResource(resource, false);
|
|
2444
|
+
}
|
|
2445
|
+
connection.resources.clear();
|
|
2446
|
+
}
|
|
2447
|
+
function notifyRetainedFlush(connection) {
|
|
2448
|
+
for (let current = connection; current !== null; current = current.parent) {
|
|
2449
|
+
if (!current.connected) {
|
|
2450
|
+
for (const notify of current.afterFlush)
|
|
2451
|
+
notify();
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
function createRootIdentity(identifierPrefix, onCaughtError, onUncaughtError) {
|
|
2456
|
+
return {
|
|
2457
|
+
mounted: false,
|
|
2458
|
+
nextId: 0,
|
|
2459
|
+
prefix: identifierPrefix ?? `v${nextClientRoot++}-`,
|
|
2460
|
+
onCaughtError,
|
|
2461
|
+
onUncaughtError,
|
|
2462
|
+
};
|
|
2463
|
+
}
|
|
2464
|
+
function commitRootPortals(rootIdentity) {
|
|
2465
|
+
const pending = pendingRootPortals.get(rootIdentity);
|
|
2466
|
+
if (pending === undefined)
|
|
2467
|
+
return;
|
|
2468
|
+
pendingRootPortals.delete(rootIdentity);
|
|
2469
|
+
const committed = [];
|
|
2470
|
+
try {
|
|
2471
|
+
for (const publication of pending) {
|
|
2472
|
+
publication[0]();
|
|
2473
|
+
committed.push(publication);
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
catch (error) {
|
|
2477
|
+
for (const publication of committed.toReversed())
|
|
2478
|
+
publication[1]();
|
|
2479
|
+
throw error;
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
function provideContext(context, input, children) {
|
|
2483
|
+
const parentContext = activeContextFrame ?? activeOwner?.[2] ?? null;
|
|
2484
|
+
let mounted = false;
|
|
2485
|
+
return [
|
|
2486
|
+
STRUCTURAL,
|
|
2487
|
+
(parent, before) => {
|
|
2488
|
+
if (mounted)
|
|
2489
|
+
throw new Error(DEV ? 'context provider is already mounted' : 'V008');
|
|
2490
|
+
mounted = true;
|
|
2491
|
+
withContextFrame({ context: context, input, parent: parentContext }, () => insertValue(parent, children, before));
|
|
2492
|
+
},
|
|
2493
|
+
'transparent',
|
|
2494
|
+
];
|
|
2495
|
+
}
|
|
2496
|
+
function contextInput(scope, context) {
|
|
2497
|
+
const owner = scopeOwners.get(scope);
|
|
2498
|
+
if (owner === undefined) {
|
|
2499
|
+
throw new Error(DEV ? 'createCompiledContext received an unknown scope' : 'V003');
|
|
2500
|
+
}
|
|
2501
|
+
return contextInputFromFrame(owner[2], context);
|
|
2502
|
+
}
|
|
2503
|
+
function contextInputFromFrame(frame, context) {
|
|
2504
|
+
if (typeof context !== 'function' || !(CONTEXT in context)) {
|
|
2505
|
+
throw new TypeError(DEV ? 'useContext requires a context created by createContext' : 'V018');
|
|
2506
|
+
}
|
|
2507
|
+
for (let current = frame; current !== null; current = current.parent) {
|
|
2508
|
+
if (current.context === context)
|
|
2509
|
+
return current.input;
|
|
2510
|
+
}
|
|
2511
|
+
return context[CONTEXT];
|
|
2512
|
+
}
|
|
2513
|
+
function withOwner(owner, operation) {
|
|
2514
|
+
const previous = activeOwner;
|
|
2515
|
+
const previousContext = activeContextFrame;
|
|
2516
|
+
const previousRootIdentity = activeRootIdentity;
|
|
2517
|
+
const previousErrorOwner = activeErrorOwner;
|
|
2518
|
+
activeOwner = owner;
|
|
2519
|
+
activeContextFrame = owner[2];
|
|
2520
|
+
activeRootIdentity = owner[3];
|
|
2521
|
+
activeErrorOwner = owner;
|
|
2522
|
+
try {
|
|
2523
|
+
return operation();
|
|
2524
|
+
}
|
|
2525
|
+
finally {
|
|
2526
|
+
activeOwner = previous;
|
|
2527
|
+
activeContextFrame = previousContext;
|
|
2528
|
+
activeRootIdentity = previousRootIdentity;
|
|
2529
|
+
activeErrorOwner = previousErrorOwner;
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
function withContextFrame(frame, operation) {
|
|
2533
|
+
const previous = activeContextFrame;
|
|
2534
|
+
activeContextFrame = frame;
|
|
2535
|
+
try {
|
|
2536
|
+
return operation();
|
|
2537
|
+
}
|
|
2538
|
+
finally {
|
|
2539
|
+
activeContextFrame = previous;
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
function withRootIdentity(rootIdentity, operation) {
|
|
2543
|
+
const previous = activeRootIdentity;
|
|
2544
|
+
activeRootIdentity = rootIdentity;
|
|
2545
|
+
try {
|
|
2546
|
+
return operation();
|
|
2547
|
+
}
|
|
2548
|
+
finally {
|
|
2549
|
+
activeRootIdentity = previous;
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
function onCleanup(cleanup) {
|
|
2553
|
+
activeOwner?.[1].add(cleanup);
|
|
2554
|
+
}
|
|
2555
|
+
function disposeOwner(owner) {
|
|
2556
|
+
if (owner[0])
|
|
2557
|
+
return;
|
|
2558
|
+
owner[0] = true;
|
|
2559
|
+
if (DEV)
|
|
2560
|
+
activeOwnerCount -= 1;
|
|
2561
|
+
pendingInsertionCommits.delete(owner);
|
|
2562
|
+
pendingOwnerCommits.delete(owner);
|
|
2563
|
+
const cleanups = [...owner[1]];
|
|
2564
|
+
owner[1].clear();
|
|
2565
|
+
let firstError;
|
|
2566
|
+
let hasError = false;
|
|
2567
|
+
for (let index = cleanups.length - 1; index >= 0; index -= 1) {
|
|
2568
|
+
try {
|
|
2569
|
+
cleanups[index]?.();
|
|
2570
|
+
}
|
|
2571
|
+
catch (error) {
|
|
2572
|
+
if (!hasError)
|
|
2573
|
+
firstError = error;
|
|
2574
|
+
hasError = true;
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
if (hasError)
|
|
2578
|
+
throw firstError;
|
|
2579
|
+
}
|
|
2580
|
+
/** @internal Test-only allocation and retention evidence. */
|
|
2581
|
+
export function readCompiledOwnerMetrics() {
|
|
2582
|
+
return { active: activeOwnerCount, created: createdOwnerCount };
|
|
2583
|
+
}
|
|
2584
|
+
function mountCompiledBindingBefore(parent, value, before) {
|
|
2585
|
+
const unset = Symbol(DEV ? 'Vidact.UnsetBinding' : undefined);
|
|
2586
|
+
const initial = value[1]();
|
|
2587
|
+
const scalarInitial = isScalarRenderValue(initial);
|
|
2588
|
+
const hydratedTextRange = scalarInitial
|
|
2589
|
+
? claimHydrationTextRange(parent, toText(initial))
|
|
2590
|
+
: undefined;
|
|
2591
|
+
const borrowedHydrationRange = isHydrating() && !scalarInitial
|
|
2592
|
+
? borrowHydrationSlotRange(parent, isStructuralBinding(initial) && initial[2] === 'slot')
|
|
2593
|
+
: undefined;
|
|
2594
|
+
const hydratedStructuralRange = isHydrating() && !scalarInitial
|
|
2595
|
+
? (borrowedHydrationRange ?? claimHydrationSlotRange(parent))
|
|
2596
|
+
: undefined;
|
|
2597
|
+
const hydratedRange = hydratedTextRange ?? hydratedStructuralRange;
|
|
2598
|
+
const start = hydratedRange?.[0] ?? document.createComment(DEV ? 'vidact:binding' : '');
|
|
2599
|
+
const end = hydratedRange?.[1] ?? document.createComment(DEV ? '/vidact:binding' : '');
|
|
2600
|
+
if (hydratedRange === undefined) {
|
|
2601
|
+
parent.insertBefore(start, before);
|
|
2602
|
+
parent.insertBefore(end, before);
|
|
2603
|
+
}
|
|
2604
|
+
let current = hydratedTextRange === undefined ? unset : initial;
|
|
2605
|
+
let currentOwner = null;
|
|
2606
|
+
let text = hydratedTextRange?.[2] ?? null;
|
|
2607
|
+
const clear = () => {
|
|
2608
|
+
const owner = currentOwner;
|
|
2609
|
+
currentOwner = null;
|
|
2610
|
+
text = null;
|
|
2611
|
+
disposeRange(owner, start, end);
|
|
2612
|
+
};
|
|
2613
|
+
const update = () => {
|
|
2614
|
+
const next = value[1]();
|
|
2615
|
+
if (current !== unset && Object.is(next, current))
|
|
2616
|
+
return;
|
|
2617
|
+
const currentParent = rangeParent(start, end, 'binding range');
|
|
2618
|
+
if (isScalarRenderValue(next)) {
|
|
2619
|
+
const content = toText(next);
|
|
2620
|
+
if (text !== null) {
|
|
2621
|
+
const target = text;
|
|
2622
|
+
const previousContent = target.data;
|
|
2623
|
+
const previous = current;
|
|
2624
|
+
stagePublication([
|
|
2625
|
+
() => {
|
|
2626
|
+
if (target.data !== content)
|
|
2627
|
+
target.data = content;
|
|
2628
|
+
current = next;
|
|
2629
|
+
},
|
|
2630
|
+
() => {
|
|
2631
|
+
if (target.data !== previousContent)
|
|
2632
|
+
target.data = previousContent;
|
|
2633
|
+
current = previous;
|
|
2634
|
+
},
|
|
2635
|
+
]);
|
|
2636
|
+
return;
|
|
2637
|
+
}
|
|
2638
|
+
clear();
|
|
2639
|
+
text = document.createTextNode(content);
|
|
2640
|
+
currentParent.insertBefore(text, end);
|
|
2641
|
+
current = next;
|
|
2642
|
+
return;
|
|
2643
|
+
}
|
|
2644
|
+
const nextOwner = createOwner();
|
|
2645
|
+
const [fragment, staged] = stageValue(next, nextOwner);
|
|
2646
|
+
try {
|
|
2647
|
+
clear();
|
|
2648
|
+
}
|
|
2649
|
+
catch (error) {
|
|
2650
|
+
disposeOwner(nextOwner);
|
|
2651
|
+
throw error;
|
|
2652
|
+
}
|
|
2653
|
+
currentOwner = nextOwner;
|
|
2654
|
+
currentParent.insertBefore(fragment, end);
|
|
2655
|
+
commitPublishedNodes(staged);
|
|
2656
|
+
current = next;
|
|
2657
|
+
};
|
|
2658
|
+
if (hydratedStructuralRange !== undefined) {
|
|
2659
|
+
const nextOwner = createOwner();
|
|
2660
|
+
const [fragment, staged] = withHydrationInsertion(parent, end, () => stageRender(() => initial, nextOwner));
|
|
2661
|
+
parent.insertBefore(fragment, end);
|
|
2662
|
+
commitPublishedNodes(staged);
|
|
2663
|
+
currentOwner = nextOwner;
|
|
2664
|
+
current = initial;
|
|
2665
|
+
}
|
|
2666
|
+
else if (hydratedRange === undefined) {
|
|
2667
|
+
update();
|
|
2668
|
+
}
|
|
2669
|
+
const removeUpdater = subscribeBinding(value, update);
|
|
2670
|
+
onCleanup(() => {
|
|
2671
|
+
removeUpdater();
|
|
2672
|
+
clear();
|
|
2673
|
+
if (borrowedHydrationRange === undefined) {
|
|
2674
|
+
start.remove();
|
|
2675
|
+
end.remove();
|
|
2676
|
+
}
|
|
2677
|
+
});
|
|
2678
|
+
}
|
|
2679
|
+
function materialize(value) {
|
|
2680
|
+
const insertionPoint = hydrationInsertionPoint();
|
|
2681
|
+
if (insertionPoint !== undefined) {
|
|
2682
|
+
const [parent, before] = insertionPoint;
|
|
2683
|
+
const first = hydrationCursor(parent);
|
|
2684
|
+
if (first === undefined)
|
|
2685
|
+
throw new Error('hydration insertion point requires active hydration');
|
|
2686
|
+
insertValue(parent, value, before);
|
|
2687
|
+
const after = hydrationCursor(parent);
|
|
2688
|
+
const nodes = [];
|
|
2689
|
+
for (let node = first; node !== null && node !== after; node = node.nextSibling) {
|
|
2690
|
+
nodes.push(node);
|
|
2691
|
+
}
|
|
2692
|
+
return nodes;
|
|
2693
|
+
}
|
|
2694
|
+
const fragment = document.createDocumentFragment();
|
|
2695
|
+
const moves = [];
|
|
2696
|
+
try {
|
|
2697
|
+
insertValue(fragment, value, null, moves);
|
|
2698
|
+
}
|
|
2699
|
+
catch (error) {
|
|
2700
|
+
restoreNodePositions(moves);
|
|
2701
|
+
throw error;
|
|
2702
|
+
}
|
|
2703
|
+
return [...fragment.childNodes];
|
|
2704
|
+
}
|
|
2705
|
+
function stageValue(value, owner) {
|
|
2706
|
+
const insertionPoint = hydrationInsertionPoint();
|
|
2707
|
+
if (insertionPoint !== undefined) {
|
|
2708
|
+
const [parent, before] = insertionPoint;
|
|
2709
|
+
const first = hydrationCursor(parent);
|
|
2710
|
+
if (first === undefined)
|
|
2711
|
+
throw new Error('hydration insertion point requires active hydration');
|
|
2712
|
+
withOwner(owner, () => insertValue(parent, value, before));
|
|
2713
|
+
const nodes = [];
|
|
2714
|
+
for (let node = first; node !== null && node !== before; node = node.nextSibling) {
|
|
2715
|
+
nodes.push(node);
|
|
2716
|
+
}
|
|
2717
|
+
return [document.createDocumentFragment(), nodes];
|
|
2718
|
+
}
|
|
2719
|
+
const fragment = document.createDocumentFragment();
|
|
2720
|
+
const moves = [];
|
|
2721
|
+
try {
|
|
2722
|
+
withOwner(owner, () => insertValue(fragment, value, null, moves));
|
|
2723
|
+
}
|
|
2724
|
+
catch (error) {
|
|
2725
|
+
restoreNodePositions(moves);
|
|
2726
|
+
try {
|
|
2727
|
+
disposeOwner(owner);
|
|
2728
|
+
}
|
|
2729
|
+
catch {
|
|
2730
|
+
// Preserve the staging error; cleanup still ran every registered disposer.
|
|
2731
|
+
}
|
|
2732
|
+
throw error;
|
|
2733
|
+
}
|
|
2734
|
+
return [fragment, [...fragment.childNodes]];
|
|
2735
|
+
}
|
|
2736
|
+
function stageRender(render, owner) {
|
|
2737
|
+
try {
|
|
2738
|
+
return stageValue(withOwner(owner, render), owner);
|
|
2739
|
+
}
|
|
2740
|
+
catch (error) {
|
|
2741
|
+
try {
|
|
2742
|
+
disposeOwner(owner);
|
|
2743
|
+
}
|
|
2744
|
+
catch {
|
|
2745
|
+
// Preserve the render or staging error after every registered cleanup ran.
|
|
2746
|
+
}
|
|
2747
|
+
throw error;
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
2750
|
+
function insertValue(parent, value, before, moves) {
|
|
2751
|
+
if (value === null || value === undefined || typeof value === 'boolean') {
|
|
2752
|
+
claimHydrationText(parent, '');
|
|
2753
|
+
return;
|
|
2754
|
+
}
|
|
2755
|
+
if (isStructuralBinding(value)) {
|
|
2756
|
+
if (isHydrating() && !isCompiledComponentResult(value) && value[2] === undefined) {
|
|
2757
|
+
throw new HydrationMismatch('structural binding hydration markers are not available');
|
|
2758
|
+
}
|
|
2759
|
+
adoptCompiledRoot(value);
|
|
2760
|
+
value[1](parent, before);
|
|
2761
|
+
return;
|
|
2762
|
+
}
|
|
2763
|
+
if (isCompiledBinding(value)) {
|
|
2764
|
+
mountCompiledBindingBefore(parent, value, before);
|
|
2765
|
+
return;
|
|
2766
|
+
}
|
|
2767
|
+
if (isRenderableProtocol(value)) {
|
|
2768
|
+
insertValue(parent, materializeRenderable(value), before, moves);
|
|
2769
|
+
return;
|
|
2770
|
+
}
|
|
2771
|
+
if (Array.isArray(value)) {
|
|
2772
|
+
if (hasInvalidChild(value)) {
|
|
2773
|
+
throw new TypeError(DEV ? 'unsupported compiled child value; expected a DOM node or owned block' : 'V009');
|
|
2774
|
+
}
|
|
2775
|
+
const hydratedRange = claimHydrationArrayRange(parent);
|
|
2776
|
+
for (const item of value)
|
|
2777
|
+
insertValue(parent, item, before, moves);
|
|
2778
|
+
if (hydratedRange !== undefined)
|
|
2779
|
+
finishHydrationArrayRange(parent, hydratedRange[1]);
|
|
2780
|
+
return;
|
|
2781
|
+
}
|
|
2782
|
+
if (value instanceof DocumentFragment) {
|
|
2783
|
+
const hydrationChildren = hydrationFragmentChildren(value);
|
|
2784
|
+
if (hydrationChildren !== undefined) {
|
|
2785
|
+
for (const child of hydrationChildren) {
|
|
2786
|
+
insertValue(parent, child, before, moves);
|
|
2787
|
+
}
|
|
2788
|
+
return;
|
|
2789
|
+
}
|
|
2790
|
+
// oxlint-disable-next-line unicorn/no-useless-spread -- Snapshot the live NodeList before moving nodes.
|
|
2791
|
+
for (const child of [...value.childNodes])
|
|
2792
|
+
insertValue(parent, child, before, moves);
|
|
2793
|
+
return;
|
|
2794
|
+
}
|
|
2795
|
+
if (value instanceof Node) {
|
|
2796
|
+
moves?.push([value, value.parentNode, value.nextSibling]);
|
|
2797
|
+
adoptCompiledRoot(value);
|
|
2798
|
+
claimPendingRefOwners(value);
|
|
2799
|
+
if (!claimHydrationNode(parent, value))
|
|
2800
|
+
parent.insertBefore(value, before);
|
|
2801
|
+
if (!(parent instanceof DocumentFragment))
|
|
2802
|
+
commitPendingRefs(value);
|
|
2803
|
+
return;
|
|
2804
|
+
}
|
|
2805
|
+
if (typeof value === 'object' || typeof value === 'function' || typeof value === 'symbol') {
|
|
2806
|
+
throw new TypeError(DEV ? 'unsupported compiled child value; expected a DOM node or owned block' : 'V009');
|
|
2807
|
+
}
|
|
2808
|
+
const content = String(value);
|
|
2809
|
+
if (claimHydrationText(parent, content) === undefined) {
|
|
2810
|
+
parent.insertBefore(document.createTextNode(content), before);
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
function restoreNodePositions(positions) {
|
|
2814
|
+
for (let index = positions.length - 1; index >= 0; index -= 1) {
|
|
2815
|
+
const position = positions[index];
|
|
2816
|
+
if (position === undefined)
|
|
2817
|
+
continue;
|
|
2818
|
+
if (position[1] === null) {
|
|
2819
|
+
position[0].parentNode?.removeChild(position[0]);
|
|
2820
|
+
continue;
|
|
2821
|
+
}
|
|
2822
|
+
const before = position[2]?.parentNode === position[1] ? position[2] : null;
|
|
2823
|
+
position[1].insertBefore(position[0], before);
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
function removeBetween(start, end) {
|
|
2827
|
+
let node = start.nextSibling;
|
|
2828
|
+
while (node !== null && node !== end) {
|
|
2829
|
+
const next = node.nextSibling;
|
|
2830
|
+
node.parentNode?.removeChild(node);
|
|
2831
|
+
node = next;
|
|
2832
|
+
}
|
|
2833
|
+
}
|
|
2834
|
+
function nodesBetween(start, end) {
|
|
2835
|
+
const nodes = [];
|
|
2836
|
+
for (let node = start.nextSibling; node !== null && node !== end; node = node.nextSibling) {
|
|
2837
|
+
nodes.push(node);
|
|
2838
|
+
}
|
|
2839
|
+
return nodes;
|
|
2840
|
+
}
|
|
2841
|
+
function rangeParent(start, end, description) {
|
|
2842
|
+
const parent = end.parentNode;
|
|
2843
|
+
if (parent === null || start.parentNode !== parent) {
|
|
2844
|
+
throw new Error(DEV ? `cannot update a detached ${description}` : 'V010');
|
|
2845
|
+
}
|
|
2846
|
+
return parent;
|
|
2847
|
+
}
|
|
2848
|
+
function disposeRange(owner, start, end) {
|
|
2849
|
+
try {
|
|
2850
|
+
if (owner !== null)
|
|
2851
|
+
disposeOwner(owner);
|
|
2852
|
+
}
|
|
2853
|
+
finally {
|
|
2854
|
+
removeBetween(start, end);
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
2857
|
+
function disposePublished(owner, nodes) {
|
|
2858
|
+
try {
|
|
2859
|
+
if (owner !== null)
|
|
2860
|
+
disposeOwner(owner);
|
|
2861
|
+
}
|
|
2862
|
+
finally {
|
|
2863
|
+
for (const node of nodes)
|
|
2864
|
+
node.parentNode?.removeChild(node);
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
function toText(value) {
|
|
2868
|
+
return value === null || value === undefined || typeof value === 'boolean' ? '' : String(value);
|
|
2869
|
+
}
|
|
2870
|
+
function isScalarRenderValue(value) {
|
|
2871
|
+
return (value === null ||
|
|
2872
|
+
value === undefined ||
|
|
2873
|
+
typeof value === 'string' ||
|
|
2874
|
+
typeof value === 'number' ||
|
|
2875
|
+
typeof value === 'bigint' ||
|
|
2876
|
+
typeof value === 'boolean');
|
|
2877
|
+
}
|
|
2878
|
+
function isRefValue(value) {
|
|
2879
|
+
return (value === null ||
|
|
2880
|
+
value === undefined ||
|
|
2881
|
+
typeof value === 'function' ||
|
|
2882
|
+
(typeof value === 'object' && value !== null && 'current' in value));
|
|
2883
|
+
}
|
|
2884
|
+
function claimPendingRefOwners(root) {
|
|
2885
|
+
visitNodes(root, (node) => {
|
|
2886
|
+
if (!(node instanceof Element))
|
|
2887
|
+
return;
|
|
2888
|
+
const pending = pendingRefs.get(node);
|
|
2889
|
+
if (pending !== undefined && pending[0] === null)
|
|
2890
|
+
pending[0] = activeOwner;
|
|
2891
|
+
});
|
|
2892
|
+
}
|
|
2893
|
+
function commitPendingRefs(root) {
|
|
2894
|
+
if (!isHydrating())
|
|
2895
|
+
commitPublishedNodesNow([root]);
|
|
2896
|
+
}
|
|
2897
|
+
function commitPublishedNodes(nodes) {
|
|
2898
|
+
if (isHydrating())
|
|
2899
|
+
return;
|
|
2900
|
+
commitPublishedNodesNow(nodes);
|
|
2901
|
+
}
|
|
2902
|
+
function commitPublishedNodesNow(nodes) {
|
|
2903
|
+
const publicationRoot = nodes[0]?.getRootNode();
|
|
2904
|
+
if (publicationRoot instanceof DocumentFragment && !(publicationRoot instanceof ShadowRoot)) {
|
|
2905
|
+
return;
|
|
2906
|
+
}
|
|
2907
|
+
for (const node of nodes)
|
|
2908
|
+
commitNodeInsertions(node);
|
|
2909
|
+
for (const node of nodes)
|
|
2910
|
+
commitNodeRefs(node);
|
|
2911
|
+
for (const node of nodes)
|
|
2912
|
+
commitNodeResources(node);
|
|
2913
|
+
}
|
|
2914
|
+
function commitNodeInsertions(root) {
|
|
2915
|
+
visitNodes(root, (node) => {
|
|
2916
|
+
if (node instanceof Comment)
|
|
2917
|
+
commitOwnerInsertions(componentCommitOwners.get(node));
|
|
2918
|
+
});
|
|
2919
|
+
}
|
|
2920
|
+
function commitNodeRefs(root) {
|
|
2921
|
+
visitNodes(root, (node) => {
|
|
2922
|
+
if (node instanceof Element) {
|
|
2923
|
+
const pending = pendingRefs.get(node);
|
|
2924
|
+
if (pending !== undefined) {
|
|
2925
|
+
pendingRefs.delete(node);
|
|
2926
|
+
const owner = pending[0] ?? activeOwner;
|
|
2927
|
+
const cleanup = attachRef(pending[1], node);
|
|
2928
|
+
if (pending[2] === undefined)
|
|
2929
|
+
owner?.[1].add(cleanup);
|
|
2930
|
+
else
|
|
2931
|
+
pending[2](cleanup);
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
});
|
|
2935
|
+
}
|
|
2936
|
+
function commitNodeResources(root) {
|
|
2937
|
+
visitNodes(root, (node) => {
|
|
2938
|
+
if (node instanceof Comment)
|
|
2939
|
+
commitOwnerResources(componentCommitOwners.get(node));
|
|
2940
|
+
});
|
|
2941
|
+
}
|
|
2942
|
+
function commitOwnerInsertions(owner) {
|
|
2943
|
+
if (owner === undefined || owner[0])
|
|
2944
|
+
return;
|
|
2945
|
+
const commits = pendingInsertionCommits.get(owner);
|
|
2946
|
+
if (commits === undefined)
|
|
2947
|
+
return;
|
|
2948
|
+
pendingInsertionCommits.delete(owner);
|
|
2949
|
+
for (const commit of commits)
|
|
2950
|
+
commit();
|
|
2951
|
+
}
|
|
2952
|
+
function commitOwnerResources(owner) {
|
|
2953
|
+
if (owner === undefined || owner[0])
|
|
2954
|
+
return;
|
|
2955
|
+
const commits = pendingOwnerCommits.get(owner);
|
|
2956
|
+
if (commits === undefined)
|
|
2957
|
+
return;
|
|
2958
|
+
pendingOwnerCommits.delete(owner);
|
|
2959
|
+
for (const commit of commits)
|
|
2960
|
+
commit();
|
|
2961
|
+
}
|
|
2962
|
+
function commitRangeRefs(start, end) {
|
|
2963
|
+
const nodes = [];
|
|
2964
|
+
let node = start.nextSibling;
|
|
2965
|
+
while (node !== null && node !== end) {
|
|
2966
|
+
nodes.push(node);
|
|
2967
|
+
node = node.nextSibling;
|
|
2968
|
+
}
|
|
2969
|
+
commitPublishedNodesNow(nodes);
|
|
2970
|
+
}
|
|
2971
|
+
function visitNodes(root, visit) {
|
|
2972
|
+
visit(root);
|
|
2973
|
+
for (const child of root.childNodes)
|
|
2974
|
+
visitNodes(child, visit);
|
|
2975
|
+
}
|
|
2976
|
+
function attachRef(value, target) {
|
|
2977
|
+
if (value === null || value === undefined)
|
|
2978
|
+
return noop;
|
|
2979
|
+
if (typeof value === 'function') {
|
|
2980
|
+
const cleanup = value(target);
|
|
2981
|
+
return typeof cleanup === 'function' ? cleanup : () => value(null);
|
|
2982
|
+
}
|
|
2983
|
+
value.current = target;
|
|
2984
|
+
return () => {
|
|
2985
|
+
if (value.current === target)
|
|
2986
|
+
value.current = null;
|
|
2987
|
+
};
|
|
2988
|
+
}
|
|
2989
|
+
function scheduleFlush(flush) {
|
|
2990
|
+
scheduledFlushes.add(flush);
|
|
2991
|
+
if (transactionDepth === 0)
|
|
2992
|
+
drainFlushes();
|
|
2993
|
+
}
|
|
2994
|
+
function scheduleOwnerFlush(owner, flush) {
|
|
2995
|
+
const connection = owner[5];
|
|
2996
|
+
if (connection === null || connection === undefined || connection.connected) {
|
|
2997
|
+
scheduleFlush(flush);
|
|
2998
|
+
return;
|
|
2999
|
+
}
|
|
3000
|
+
if (connection.deferredFlushes.has(flush))
|
|
3001
|
+
return;
|
|
3002
|
+
const cancel = scheduleDeferredTask(() => {
|
|
3003
|
+
connection.deferredFlushes.delete(flush);
|
|
3004
|
+
scheduleFlush(flush);
|
|
3005
|
+
});
|
|
3006
|
+
connection.deferredFlushes.set(flush, cancel);
|
|
3007
|
+
}
|
|
3008
|
+
function drainFlushes() {
|
|
3009
|
+
if (drainingFlushes || transactionDepth > 0)
|
|
3010
|
+
return;
|
|
3011
|
+
drainingFlushes = true;
|
|
3012
|
+
const publication = [];
|
|
3013
|
+
activePublication = publication;
|
|
3014
|
+
const runs = new Map();
|
|
3015
|
+
let committing = false;
|
|
3016
|
+
let failure;
|
|
3017
|
+
let failed = false;
|
|
3018
|
+
try {
|
|
3019
|
+
while (scheduledFlushes.size > 0) {
|
|
3020
|
+
const flush = scheduledFlushes.values().next().value;
|
|
3021
|
+
if (flush === undefined)
|
|
3022
|
+
break;
|
|
3023
|
+
scheduledFlushes.delete(flush);
|
|
3024
|
+
const runCount = (runs.get(flush) ?? 0) + 1;
|
|
3025
|
+
if (runCount > MAX_FLUSH_PASSES) {
|
|
3026
|
+
scheduledFlushes.clear();
|
|
3027
|
+
throw new Error(DEV ? 'Vidact compiled scopes did not stabilize' : 'V011');
|
|
3028
|
+
}
|
|
3029
|
+
runs.set(flush, runCount);
|
|
3030
|
+
flush();
|
|
3031
|
+
}
|
|
3032
|
+
activePublication = null;
|
|
3033
|
+
committing = true;
|
|
3034
|
+
commitPublication(publication);
|
|
3035
|
+
}
|
|
3036
|
+
catch (error) {
|
|
3037
|
+
activePublication = null;
|
|
3038
|
+
if (!committing)
|
|
3039
|
+
abortPublication(publication);
|
|
3040
|
+
failure = error;
|
|
3041
|
+
failed = true;
|
|
3042
|
+
}
|
|
3043
|
+
finally {
|
|
3044
|
+
activePublication = null;
|
|
3045
|
+
drainingFlushes = false;
|
|
3046
|
+
}
|
|
3047
|
+
if (failed) {
|
|
3048
|
+
const owner = failedOwner;
|
|
3049
|
+
failedOwner = null;
|
|
3050
|
+
if (!routeOwnerError(owner, failure))
|
|
3051
|
+
throw failure;
|
|
3052
|
+
}
|
|
3053
|
+
if (scheduledFlushes.size > 0)
|
|
3054
|
+
drainFlushes();
|
|
3055
|
+
}
|
|
3056
|
+
function stagePublication(operation) {
|
|
3057
|
+
if (activePublication === null) {
|
|
3058
|
+
operation[0]();
|
|
3059
|
+
try {
|
|
3060
|
+
operation[3]?.();
|
|
3061
|
+
}
|
|
3062
|
+
catch (error) {
|
|
3063
|
+
operation[1]();
|
|
3064
|
+
throw error;
|
|
3065
|
+
}
|
|
3066
|
+
return;
|
|
3067
|
+
}
|
|
3068
|
+
activePublication.push([
|
|
3069
|
+
operation[0],
|
|
3070
|
+
operation[1],
|
|
3071
|
+
operation[2],
|
|
3072
|
+
operation[3],
|
|
3073
|
+
operation[4],
|
|
3074
|
+
operation[5] ?? activeErrorOwner,
|
|
3075
|
+
]);
|
|
3076
|
+
}
|
|
3077
|
+
function commitPublication(operations) {
|
|
3078
|
+
const ordered = operations.some((operation) => operation[4] !== undefined)
|
|
3079
|
+
? operations.toSorted((left, right) => (left[4] ?? 0) - (right[4] ?? 0))
|
|
3080
|
+
: operations;
|
|
3081
|
+
const applied = [];
|
|
3082
|
+
let current;
|
|
3083
|
+
try {
|
|
3084
|
+
for (const operation of ordered) {
|
|
3085
|
+
current = operation;
|
|
3086
|
+
applied.push(operation);
|
|
3087
|
+
operation[0]();
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
catch (error) {
|
|
3091
|
+
for (let index = applied.length - 1; index >= 0; index -= 1) {
|
|
3092
|
+
try {
|
|
3093
|
+
applied[index]?.[1]();
|
|
3094
|
+
}
|
|
3095
|
+
catch {
|
|
3096
|
+
// Preserve the publication error while attempting every inverse.
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
for (const operation of ordered.slice(applied.length)) {
|
|
3100
|
+
try {
|
|
3101
|
+
operation[2]?.();
|
|
3102
|
+
}
|
|
3103
|
+
catch {
|
|
3104
|
+
// Preserve the publication error while disposing every staged value.
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
failedOwner = current?.[5] ?? null;
|
|
3108
|
+
throw error;
|
|
3109
|
+
}
|
|
3110
|
+
try {
|
|
3111
|
+
for (const operation of ordered) {
|
|
3112
|
+
current = operation;
|
|
3113
|
+
operation[3]?.();
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
catch (error) {
|
|
3117
|
+
for (let index = applied.length - 1; index >= 0; index -= 1) {
|
|
3118
|
+
try {
|
|
3119
|
+
applied[index]?.[1]();
|
|
3120
|
+
}
|
|
3121
|
+
catch {
|
|
3122
|
+
// Preserve the finalization error while attempting every inverse.
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
failedOwner = current?.[5] ?? null;
|
|
3126
|
+
throw error;
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
function runOwnerTask(owner, operation) {
|
|
3130
|
+
try {
|
|
3131
|
+
operation();
|
|
3132
|
+
}
|
|
3133
|
+
catch (error) {
|
|
3134
|
+
if (!routeOwnerError(owner, error))
|
|
3135
|
+
throw error;
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
function routeOwnerError(owner, failure) {
|
|
3139
|
+
let error = failure;
|
|
3140
|
+
let boundary = owner?.[4] ?? null;
|
|
3141
|
+
while (boundary !== null) {
|
|
3142
|
+
try {
|
|
3143
|
+
boundary.handle(error);
|
|
3144
|
+
return true;
|
|
3145
|
+
}
|
|
3146
|
+
catch (nextError) {
|
|
3147
|
+
error = nextError;
|
|
3148
|
+
boundary = boundary.parent;
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
const onUncaughtError = owner?.[3].onUncaughtError;
|
|
3152
|
+
if (onUncaughtError === undefined)
|
|
3153
|
+
return false;
|
|
3154
|
+
onUncaughtError(error);
|
|
3155
|
+
return true;
|
|
3156
|
+
}
|
|
3157
|
+
export function isCompiledContext(value) {
|
|
3158
|
+
return typeof value === 'function' && CONTEXT in value;
|
|
3159
|
+
}
|
|
3160
|
+
function abortPublication(operations) {
|
|
3161
|
+
for (let index = operations.length - 1; index >= 0; index -= 1) {
|
|
3162
|
+
try {
|
|
3163
|
+
operations[index]?.[2]?.();
|
|
3164
|
+
}
|
|
3165
|
+
catch {
|
|
3166
|
+
// Preserve the computation error while disposing every staged value.
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3170
|
+
//# sourceMappingURL=core.js.map
|