pudui 0.0.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/README.md +161 -0
- package/dist/component-D3kwgmef.mjs +275 -0
- package/dist/core-Cypb6mR9.d.mts +434 -0
- package/dist/hmr-runtime.d.mts +99 -0
- package/dist/hmr-runtime.mjs +177 -0
- package/dist/hydration-markers-DdjOvH6g.mjs +218 -0
- package/dist/index.d.mts +109 -0
- package/dist/index.mjs +1505 -0
- package/dist/jsx-dev-runtime.d.mts +36 -0
- package/dist/jsx-dev-runtime.mjs +2 -0
- package/dist/jsx-runtime.d.mts +36 -0
- package/dist/jsx-runtime.mjs +2 -0
- package/dist/macros.d.mts +43 -0
- package/dist/macros.mjs +47 -0
- package/dist/server.d.mts +55 -0
- package/dist/server.mjs +223 -0
- package/dist/transforms-DUsCAPAL.mjs +707 -0
- package/dist/transforms.d.mts +150 -0
- package/dist/transforms.mjs +2 -0
- package/dist/vite-plugin.d.mts +224 -0
- package/dist/vite-plugin.mjs +748 -0
- package/dist/vite-runtime.d.mts +42 -0
- package/dist/vite-runtime.mjs +89 -0
- package/dist/vnode-Lr-Tpypk.mjs +182 -0
- package/package.json +99 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1505 @@
|
|
|
1
|
+
import { c as jsxDEV, d as normalizeChildren, f as readRawChildHtml, l as isEmptyChild, n as Raw, o as isVNode, r as createElement, s as jsx, t as Fragment, u as isRawChild } from "./vnode-Lr-Tpypk.mjs";
|
|
2
|
+
import { a as isRawStartCommentData, g as readDangerouslySetInnerHTML, h as isPrimitiveValue, i as isRawEndCommentData, m as isChildlessElement, n as isHydrateMetaCommentData, o as parseHydrateMetaCommentData, p as attributeName, r as isHydrateStartCommentData, s as parseHydrateStartCommentData, t as isHydrateEndCommentData, v as toKebabCase } from "./hydration-markers-DdjOvH6g.mjs";
|
|
3
|
+
import { a as isComponent, d as resolveComponent, f as setComponentProps, h as invariant, i as finishComponentRender, l as renderComponentErrorOutput, m as fail, n as beginComponentRender, o as queueComponentMount, p as subscribeComponent, r as createComponent, s as readComponentHydrateMeta, t as Component, u as renderComponentOutput } from "./component-D3kwgmef.mjs";
|
|
4
|
+
//#region src/core/hydration.ts
|
|
5
|
+
/**
|
|
6
|
+
* Checks whether a value is a hydrated child boundary wrapper.
|
|
7
|
+
*
|
|
8
|
+
* @param value Value to inspect.
|
|
9
|
+
* @returns `true` when the value stores hydration boundary state.
|
|
10
|
+
*/
|
|
11
|
+
function isHydratedChildren(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && "b" in value;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a hydrated child wrapper from boundary metadata.
|
|
16
|
+
*
|
|
17
|
+
* @param boundary Hydration boundary metadata.
|
|
18
|
+
* @returns Hydrated child wrapper.
|
|
19
|
+
*/
|
|
20
|
+
function createHydratedChildren(boundary) {
|
|
21
|
+
return { b: boundary };
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Replaces the boundary metadata stored by a hydrated child wrapper.
|
|
25
|
+
*
|
|
26
|
+
* @param children Hydrated child wrapper to update.
|
|
27
|
+
* @param boundary Next hydration boundary metadata.
|
|
28
|
+
*/
|
|
29
|
+
function updateHydratedChildrenBoundary(children, boundary) {
|
|
30
|
+
children.b = boundary;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/runtime/props.ts
|
|
34
|
+
/**
|
|
35
|
+
* Patches DOM attributes and selected properties from old props to new props.
|
|
36
|
+
*
|
|
37
|
+
* @param element Element to patch.
|
|
38
|
+
* @param oldProps Previous intrinsic props.
|
|
39
|
+
* @param newProps Next intrinsic props.
|
|
40
|
+
*/
|
|
41
|
+
function patchProps(element, oldProps, newProps) {
|
|
42
|
+
for (const [rawName, value] of Object.entries(newProps)) {
|
|
43
|
+
if (shouldSkipProp(rawName)) continue;
|
|
44
|
+
const name = attributeName(rawName);
|
|
45
|
+
if (rawName === "style") {
|
|
46
|
+
patchStyle(element, oldProps.style, value);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const oldAttributeValue = attributeValue(readPropValue(oldProps, rawName));
|
|
50
|
+
const newAttributeValue = attributeValue(value);
|
|
51
|
+
if (oldAttributeValue !== newAttributeValue) if (newAttributeValue === void 0) element.removeAttribute(name);
|
|
52
|
+
else element.setAttribute(name, newAttributeValue);
|
|
53
|
+
}
|
|
54
|
+
for (const rawName of Object.keys(oldProps)) {
|
|
55
|
+
if (shouldSkipProp(rawName) || readPropValue(newProps, rawName) !== void 0) continue;
|
|
56
|
+
if (rawName === "style") {
|
|
57
|
+
if (oldProps.style != null) element.removeAttribute("style");
|
|
58
|
+
} else if (attributeValue(oldProps[rawName]) !== void 0) element.removeAttribute(attributeName(rawName));
|
|
59
|
+
}
|
|
60
|
+
if (element instanceof HTMLInputElement) {
|
|
61
|
+
if ("checked" in newProps && (element.type === "checkbox" || element.type === "radio")) element.checked = newProps.checked === true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function shouldSkipProp(rawName) {
|
|
65
|
+
return " children dangerouslySetInnerHTML key ref ".includes(" " + rawName + " ") || rawName.startsWith("on");
|
|
66
|
+
}
|
|
67
|
+
function readPropValue(props, rawName) {
|
|
68
|
+
const value = props[rawName];
|
|
69
|
+
if (value !== void 0) return value;
|
|
70
|
+
if (rawName === "class") return props.className;
|
|
71
|
+
if (rawName === "className") return props.class;
|
|
72
|
+
if (rawName === "for") return props.htmlFor;
|
|
73
|
+
if (rawName === "htmlFor") return props.for;
|
|
74
|
+
}
|
|
75
|
+
function attributeValue(value) {
|
|
76
|
+
if (value === true) return "";
|
|
77
|
+
if (isPrimitiveValue(value)) return String(value);
|
|
78
|
+
}
|
|
79
|
+
function patchStyle(element, oldStyle, newStyle) {
|
|
80
|
+
if (newStyle == null) {
|
|
81
|
+
if (oldStyle != null) element.removeAttribute("style");
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const style = newStyle;
|
|
85
|
+
if (oldStyle) {
|
|
86
|
+
for (const [name, value] of Object.entries(oldStyle)) if (value != null && style[name] == null) element.style.removeProperty(toKebabCase(name));
|
|
87
|
+
}
|
|
88
|
+
const htmlElement = element;
|
|
89
|
+
for (const [name, value] of Object.entries(style)) {
|
|
90
|
+
if (value == null) continue;
|
|
91
|
+
const oldValue = oldStyle?.[name];
|
|
92
|
+
if (oldValue != null && oldValue == value) continue;
|
|
93
|
+
setStyle(htmlElement, name, value);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function setStyle(element, name, value) {
|
|
97
|
+
const propertyName = toKebabCase(name);
|
|
98
|
+
const propertyValue = String(value);
|
|
99
|
+
element.style.setProperty(propertyName, propertyValue);
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/runtime/refs.ts
|
|
103
|
+
/**
|
|
104
|
+
* Queues ref callbacks to run after an element is committed.
|
|
105
|
+
*
|
|
106
|
+
* @param element Element passed to the ref callbacks.
|
|
107
|
+
* @param ref Ref callback or nested ref callbacks.
|
|
108
|
+
* @param effects Commit effect queues.
|
|
109
|
+
* @param cleanups Cleanup list that receives returned ref cleanups.
|
|
110
|
+
*/
|
|
111
|
+
function collectRefEffects(element, ref, effects, cleanups) {
|
|
112
|
+
if (!ref) return;
|
|
113
|
+
effects.r.push(() => {
|
|
114
|
+
runRefValue(element, ref, cleanups);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function runRefValue(element, ref, cleanups) {
|
|
118
|
+
if (!Array.isArray(ref)) {
|
|
119
|
+
const cleanup = ref(element);
|
|
120
|
+
if (typeof cleanup === "function") cleanups.push(cleanup);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
for (const nestedRef of ref) runRefValue(element, nestedRef, cleanups);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Runs commit effects in order.
|
|
127
|
+
*
|
|
128
|
+
* @param effects Effects to run.
|
|
129
|
+
*/
|
|
130
|
+
function runEffects(effects) {
|
|
131
|
+
for (const effect of effects) effect();
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Runs ref cleanups in reverse registration order.
|
|
135
|
+
*
|
|
136
|
+
* @param cleanups Cleanup callbacks to run.
|
|
137
|
+
*/
|
|
138
|
+
function runCleanups(cleanups) {
|
|
139
|
+
for (let index = cleanups.length - 1; index >= 0; index--) cleanups[index]();
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/client.ts
|
|
143
|
+
const textRenderNodeKind = 0;
|
|
144
|
+
const arrayRenderNodeKind = 1;
|
|
145
|
+
const componentRenderNodeKind = 2;
|
|
146
|
+
const elementRenderNodeKind = 3;
|
|
147
|
+
const hydratedRenderNodeKind = 4;
|
|
148
|
+
const rawRenderNodeKind = 5;
|
|
149
|
+
const skippedHydrationRenderNodeKind = 6;
|
|
150
|
+
const activeHydrationBoundaries = /* @__PURE__ */ new WeakMap();
|
|
151
|
+
const stylesheetPromisesByDocument = /* @__PURE__ */ new WeakMap();
|
|
152
|
+
const loadedStylesheetsByDocument = /* @__PURE__ */ new WeakMap();
|
|
153
|
+
let pendingHydrationBoundaryRefreshes;
|
|
154
|
+
function renderContextWithOwner(context, owner) {
|
|
155
|
+
return context.owner === owner ? context : {
|
|
156
|
+
...context,
|
|
157
|
+
owner
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Creates a ref that wires a DOM event listener to an element.
|
|
162
|
+
*
|
|
163
|
+
* Each time the event fires, the previous handler invocation for that element
|
|
164
|
+
* is aborted and the new invocation receives a fresh `AbortSignal`. This makes
|
|
165
|
+
* async event handlers straightforward to cancel during rapid input.
|
|
166
|
+
*
|
|
167
|
+
* @param type DOM event name to listen for.
|
|
168
|
+
* @param handler Callback invoked for each event with a cancellation signal.
|
|
169
|
+
* @param options Options passed to `addEventListener`.
|
|
170
|
+
* @returns A ref callback that installs and removes the listener.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```tsx
|
|
174
|
+
* <button
|
|
175
|
+
* ref={event("click", async (_event, signal) => {
|
|
176
|
+
* await save({ signal });
|
|
177
|
+
* })}
|
|
178
|
+
* >
|
|
179
|
+
* Save
|
|
180
|
+
* </button>
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
function event(type, handler, options) {
|
|
184
|
+
return (element) => {
|
|
185
|
+
const listener = (event) => {
|
|
186
|
+
const newController = new AbortController();
|
|
187
|
+
const target = event.currentTarget ?? event.target ?? window;
|
|
188
|
+
target._puduiAbortController?.abort();
|
|
189
|
+
target._puduiAbortController = newController;
|
|
190
|
+
return handler(event, newController.signal);
|
|
191
|
+
};
|
|
192
|
+
element.addEventListener(type, listener, options);
|
|
193
|
+
return () => {
|
|
194
|
+
element.removeEventListener(type, listener, options);
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Mounts a child tree into a DOM container.
|
|
200
|
+
*
|
|
201
|
+
* The container's existing children are replaced on the initial render. Later
|
|
202
|
+
* calls to `rerender()` patch the DOM in place when possible.
|
|
203
|
+
*
|
|
204
|
+
* @param child Child tree to render.
|
|
205
|
+
* @param container DOM element or fragment to own.
|
|
206
|
+
* @returns A root controller for rerendering or unmounting.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```tsx
|
|
210
|
+
* import { render } from "pudui";
|
|
211
|
+
*
|
|
212
|
+
* const root = render(<main>Hello</main>, document.body);
|
|
213
|
+
* root.rerender(<main>Updated</main>);
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
function render(child, container) {
|
|
217
|
+
let currentChild = child;
|
|
218
|
+
let mounted = true;
|
|
219
|
+
let renderNode;
|
|
220
|
+
const root = new Component({ render() {
|
|
221
|
+
return currentChild;
|
|
222
|
+
} });
|
|
223
|
+
const commit = () => {
|
|
224
|
+
if (!mounted) return false;
|
|
225
|
+
if (renderNode !== void 0) {
|
|
226
|
+
const pendingStylesheets = waitForConnectedStylesheets(ownerDocumentFor(container));
|
|
227
|
+
if (pendingStylesheets !== void 0) return pendingStylesheets.then(commit);
|
|
228
|
+
}
|
|
229
|
+
const effects = {
|
|
230
|
+
m: [],
|
|
231
|
+
r: []
|
|
232
|
+
};
|
|
233
|
+
const context = {
|
|
234
|
+
document: ownerDocumentFor(container),
|
|
235
|
+
effects,
|
|
236
|
+
owner: void 0,
|
|
237
|
+
scheduleUpdate: commit
|
|
238
|
+
};
|
|
239
|
+
if (renderNode === void 0) {
|
|
240
|
+
renderNode = childToRenderNode(root, context);
|
|
241
|
+
container.replaceChildren(renderNodeToFragment(renderNode));
|
|
242
|
+
} else renderNode = patchRenderNode(renderNode, root, context);
|
|
243
|
+
runEffects(effects.r);
|
|
244
|
+
runEffects(effects.m);
|
|
245
|
+
return true;
|
|
246
|
+
};
|
|
247
|
+
commit();
|
|
248
|
+
return {
|
|
249
|
+
rerender(nextChild) {
|
|
250
|
+
currentChild = nextChild;
|
|
251
|
+
commit();
|
|
252
|
+
},
|
|
253
|
+
unmount() {
|
|
254
|
+
mounted = false;
|
|
255
|
+
if (renderNode !== void 0) {
|
|
256
|
+
cleanupRenderNode(renderNode);
|
|
257
|
+
renderNode = void 0;
|
|
258
|
+
}
|
|
259
|
+
container.replaceChildren();
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Hydrates server-rendered Pudui boundaries in a document or element.
|
|
265
|
+
*
|
|
266
|
+
* The root scans for hydration comments emitted by `renderToString()` and uses
|
|
267
|
+
* `options.load` to import component factories when a boundary becomes active.
|
|
268
|
+
*
|
|
269
|
+
* @param root Document, element, or fragment containing server-rendered markup.
|
|
270
|
+
* @param options Hydration loader options.
|
|
271
|
+
* @returns A root controller for rerendering or unmounting.
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* ```tsx
|
|
275
|
+
* import { hydrate } from "pudui";
|
|
276
|
+
* import { load } from "pudui/vite-runtime";
|
|
277
|
+
*
|
|
278
|
+
* hydrate(document, { load });
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
function hydrate(root, options) {
|
|
282
|
+
const hydrationRoot = createHydrationRoot(root, options);
|
|
283
|
+
hydrationRoot.hydrate();
|
|
284
|
+
return hydrationRoot.root;
|
|
285
|
+
}
|
|
286
|
+
function createHydrationRoot(container, options) {
|
|
287
|
+
let currentChild;
|
|
288
|
+
let mounted = true;
|
|
289
|
+
let renderNode;
|
|
290
|
+
let boundaryRoots = [];
|
|
291
|
+
let hydrationRequest = 0;
|
|
292
|
+
const document = ownerDocumentFor(container);
|
|
293
|
+
const commit = () => {
|
|
294
|
+
if (!mounted || renderNode === void 0 || currentChild === void 0) return false;
|
|
295
|
+
const pendingStylesheets = waitForConnectedStylesheets(document);
|
|
296
|
+
if (pendingStylesheets !== void 0) return pendingStylesheets.then(commit);
|
|
297
|
+
const effects = {
|
|
298
|
+
m: [],
|
|
299
|
+
r: []
|
|
300
|
+
};
|
|
301
|
+
renderNode = patchRenderNode(renderNode, currentChild, {
|
|
302
|
+
document,
|
|
303
|
+
effects,
|
|
304
|
+
hydrateOptions: options,
|
|
305
|
+
owner: void 0,
|
|
306
|
+
scheduleUpdate: commit
|
|
307
|
+
});
|
|
308
|
+
runEffects(effects.r);
|
|
309
|
+
runEffects(effects.m);
|
|
310
|
+
return true;
|
|
311
|
+
};
|
|
312
|
+
const hydrateBoundaries = () => {
|
|
313
|
+
const request = ++hydrationRequest;
|
|
314
|
+
boundaryRoots = hydrateRootBoundaries(container, options, (hydrationRoot) => {
|
|
315
|
+
if (!mounted || request !== hydrationRequest || renderNode !== void 0) {
|
|
316
|
+
hydrationRoot.u();
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
boundaryRoots.push(hydrationRoot);
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
return {
|
|
323
|
+
hydrate() {
|
|
324
|
+
hydrateBoundaries();
|
|
325
|
+
},
|
|
326
|
+
root: {
|
|
327
|
+
rerender(nextChild) {
|
|
328
|
+
currentChild = nextChild;
|
|
329
|
+
if (container instanceof Document && isRawChild(nextChild)) {
|
|
330
|
+
const request = ++hydrationRequest;
|
|
331
|
+
const html = readRawChildHtml(nextChild);
|
|
332
|
+
const pendingStylesheets = waitForHtmlStylesheets(container, html);
|
|
333
|
+
const replace = () => {
|
|
334
|
+
if (!mounted || request !== hydrationRequest) return;
|
|
335
|
+
cleanupBoundaryHydrationRoots(boundaryRoots, { removeContents: false });
|
|
336
|
+
boundaryRoots = [];
|
|
337
|
+
if (renderNode !== void 0) {
|
|
338
|
+
cleanupRenderNode(renderNode);
|
|
339
|
+
renderNode = void 0;
|
|
340
|
+
}
|
|
341
|
+
patchDocumentWithHtml(container, html);
|
|
342
|
+
hydrateBoundaries();
|
|
343
|
+
};
|
|
344
|
+
if (pendingStylesheets === void 0) replace();
|
|
345
|
+
else pendingStylesheets.then(replace);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
hydrationRequest++;
|
|
349
|
+
cleanupBoundaryHydrationRoots(boundaryRoots);
|
|
350
|
+
boundaryRoots = [];
|
|
351
|
+
if (renderNode === void 0) {
|
|
352
|
+
const effects = {
|
|
353
|
+
m: [],
|
|
354
|
+
r: []
|
|
355
|
+
};
|
|
356
|
+
renderNode = childToRenderNode(nextChild, {
|
|
357
|
+
document,
|
|
358
|
+
effects,
|
|
359
|
+
hydrateOptions: options,
|
|
360
|
+
owner: void 0,
|
|
361
|
+
scheduleUpdate: commit
|
|
362
|
+
});
|
|
363
|
+
container.replaceChildren(renderNodeToFragment(renderNode));
|
|
364
|
+
runEffects(effects.r);
|
|
365
|
+
runEffects(effects.m);
|
|
366
|
+
} else commit();
|
|
367
|
+
},
|
|
368
|
+
unmount() {
|
|
369
|
+
mounted = false;
|
|
370
|
+
hydrationRequest++;
|
|
371
|
+
cleanupBoundaryHydrationRoots(boundaryRoots);
|
|
372
|
+
boundaryRoots = [];
|
|
373
|
+
if (renderNode !== void 0) {
|
|
374
|
+
cleanupRenderNode(renderNode);
|
|
375
|
+
renderNode = void 0;
|
|
376
|
+
}
|
|
377
|
+
container.replaceChildren();
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function hydrateBoundary(initialBoundary, factory, options) {
|
|
383
|
+
let boundary = initialBoundary;
|
|
384
|
+
let hydratedChildren = createHydratedChildren(boundary);
|
|
385
|
+
let component = createHydratedComponent(boundary, factory, hydratedChildren);
|
|
386
|
+
const document = boundary.s.ownerDocument;
|
|
387
|
+
let mounted = true;
|
|
388
|
+
let renderNode;
|
|
389
|
+
const commit = () => {
|
|
390
|
+
if (!mounted || renderNode === void 0) return false;
|
|
391
|
+
const pendingStylesheets = waitForConnectedStylesheets(document);
|
|
392
|
+
if (pendingStylesheets !== void 0) return pendingStylesheets.then(commit);
|
|
393
|
+
const effects = {
|
|
394
|
+
m: [],
|
|
395
|
+
r: []
|
|
396
|
+
};
|
|
397
|
+
renderNode = patchRenderNode(renderNode, component, {
|
|
398
|
+
document,
|
|
399
|
+
effects,
|
|
400
|
+
hydrateOptions: options,
|
|
401
|
+
owner: void 0,
|
|
402
|
+
scheduleUpdate: commit
|
|
403
|
+
});
|
|
404
|
+
runEffects(effects.r);
|
|
405
|
+
runEffects(effects.m);
|
|
406
|
+
return true;
|
|
407
|
+
};
|
|
408
|
+
const hydrate = () => {
|
|
409
|
+
const parent = boundary.s.parentNode;
|
|
410
|
+
if (!parent) return;
|
|
411
|
+
const effects = {
|
|
412
|
+
m: [],
|
|
413
|
+
r: []
|
|
414
|
+
};
|
|
415
|
+
renderNode = hydrateComponentToDom(component, {
|
|
416
|
+
document,
|
|
417
|
+
effects,
|
|
418
|
+
hydrateOptions: options,
|
|
419
|
+
owner: void 0,
|
|
420
|
+
scheduleUpdate: commit
|
|
421
|
+
}, boundary.s.nextSibling, component, parent, boundary.s, boundary.e).r;
|
|
422
|
+
runEffects(effects.r);
|
|
423
|
+
runEffects(effects.m);
|
|
424
|
+
};
|
|
425
|
+
const hydrationRoot = {
|
|
426
|
+
r(index, props, key) {
|
|
427
|
+
const nextBoundary = {
|
|
428
|
+
...boundary,
|
|
429
|
+
i: index,
|
|
430
|
+
k: key,
|
|
431
|
+
p: props
|
|
432
|
+
};
|
|
433
|
+
if (boundary.k !== key) {
|
|
434
|
+
if (renderNode !== void 0) cleanupRenderNode(renderNode);
|
|
435
|
+
boundary = nextBoundary;
|
|
436
|
+
hydratedChildren = createHydratedChildren(boundary);
|
|
437
|
+
component = createHydratedComponent(boundary, factory, hydratedChildren);
|
|
438
|
+
hydrate();
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
boundary = nextBoundary;
|
|
442
|
+
updateHydratedChildrenBoundary(hydratedChildren, boundary);
|
|
443
|
+
setHydratedComponentProps(component, boundary, hydratedChildren);
|
|
444
|
+
if (renderNode !== void 0) cleanupRenderNode(renderNode);
|
|
445
|
+
hydrate();
|
|
446
|
+
},
|
|
447
|
+
s: boundary.s,
|
|
448
|
+
u(options) {
|
|
449
|
+
mounted = false;
|
|
450
|
+
activeHydrationBoundaries.delete(boundary.s);
|
|
451
|
+
if (renderNode !== void 0) {
|
|
452
|
+
cleanupRenderNode(renderNode);
|
|
453
|
+
renderNode = void 0;
|
|
454
|
+
}
|
|
455
|
+
if (options?.removeContents !== false) removeBoundaryContents(boundary);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
activeHydrationBoundaries.set(boundary.s, hydrationRoot);
|
|
459
|
+
hydrate();
|
|
460
|
+
return hydrationRoot;
|
|
461
|
+
}
|
|
462
|
+
function createHydratedComponent(boundary, factory, children) {
|
|
463
|
+
return createComponent(factory, hydratedComponentProps(boundary, children));
|
|
464
|
+
}
|
|
465
|
+
function setHydratedComponentProps(component, boundary, children) {
|
|
466
|
+
setComponentProps(component, hydratedComponentProps(boundary, children));
|
|
467
|
+
}
|
|
468
|
+
function hydratedComponentProps(boundary, children) {
|
|
469
|
+
return {
|
|
470
|
+
...boundary.p,
|
|
471
|
+
children
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
function hydrateRootBoundaries(root, options, onAsyncHydrationRoot) {
|
|
475
|
+
const [boundaries, hydrateMeta] = findHydrationBoundaries(root);
|
|
476
|
+
const hydrationRoots = [];
|
|
477
|
+
for (const boundary of boundaries) {
|
|
478
|
+
const meta = hydrateMeta.get(boundary.i);
|
|
479
|
+
if (meta === void 0) fail("hydrate metadata");
|
|
480
|
+
const loaded = options.load(meta);
|
|
481
|
+
if (isPromiseLike(loaded)) loaded.then((factory) => {
|
|
482
|
+
onAsyncHydrationRoot(hydrateBoundary(boundary, factory, options));
|
|
483
|
+
}, () => {});
|
|
484
|
+
else hydrationRoots.push(hydrateBoundary(boundary, loaded, options));
|
|
485
|
+
}
|
|
486
|
+
return hydrationRoots;
|
|
487
|
+
}
|
|
488
|
+
function isPromiseLike(value) {
|
|
489
|
+
return typeof value?.then === "function";
|
|
490
|
+
}
|
|
491
|
+
function cleanupBoundaryHydrationRoots(hydrationRoots, options) {
|
|
492
|
+
for (const hydrationRoot of hydrationRoots) hydrationRoot.u(options);
|
|
493
|
+
hydrationRoots.length = 0;
|
|
494
|
+
}
|
|
495
|
+
function childToRenderNode(child, context) {
|
|
496
|
+
if (isHydratedChildren(child)) return hydratedChildrenToRenderNode(child, context.document);
|
|
497
|
+
if (isEmptyChild(child) || isPrimitiveValue(child)) return textToRenderNode(child, context.document);
|
|
498
|
+
if (isRawChild(child)) return rawToRenderNode(child, context.document, context.hydrateOptions);
|
|
499
|
+
if (Array.isArray(child)) return arrayToRenderNode(child, context);
|
|
500
|
+
if (isComponent(child)) return componentToRenderNode(child, context);
|
|
501
|
+
if (isVNode(child)) {
|
|
502
|
+
if (typeof child.type === "function") return childToRenderNode(resolveComponent(child, context.owner), context);
|
|
503
|
+
return elementToRenderNode(child, context);
|
|
504
|
+
}
|
|
505
|
+
return textToRenderNode(null, context.document);
|
|
506
|
+
}
|
|
507
|
+
function hydrateChildToDom(child, context, currentNode, rootComponent, parent) {
|
|
508
|
+
if (isHydratedChildren(child)) return hydrateHydratedChildren(child, currentNode, parent);
|
|
509
|
+
if (isEmptyChild(child) || isPrimitiveValue(child)) return hydrateTextToDom(child, currentNode, parent);
|
|
510
|
+
if (isRawChild(child)) return hydrateRawToDom(child, context, currentNode, parent);
|
|
511
|
+
if (Array.isArray(child)) {
|
|
512
|
+
let nextNode = currentNode;
|
|
513
|
+
const start = insertMarker(parent, nextNode);
|
|
514
|
+
const children = [];
|
|
515
|
+
for (const nestedChild of normalizeHydratedChildren(child)) {
|
|
516
|
+
const result = hydrateChildToDom(nestedChild, context, nextNode, rootComponent, parent);
|
|
517
|
+
nextNode = result.n;
|
|
518
|
+
children.push(result.r);
|
|
519
|
+
}
|
|
520
|
+
const end = insertMarker(parent, nextNode);
|
|
521
|
+
return {
|
|
522
|
+
n: nextNode,
|
|
523
|
+
r: {
|
|
524
|
+
c: children,
|
|
525
|
+
e: end,
|
|
526
|
+
k: arrayRenderNodeKind,
|
|
527
|
+
s: start
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
if (isComponent(child)) {
|
|
532
|
+
if (child !== rootComponent && readComponentHydrateMeta(child) !== void 0) return hydrateSkippedBoundary(currentNode, parent);
|
|
533
|
+
return hydrateComponentToDom(child, context, currentNode, rootComponent, parent);
|
|
534
|
+
}
|
|
535
|
+
if (isVNode(child)) {
|
|
536
|
+
if (typeof child.type === "function") return hydrateChildToDom(resolveComponent(child, context.owner), context, currentNode, rootComponent, parent);
|
|
537
|
+
return hydrateElementToDom(child, context, currentNode, rootComponent, parent);
|
|
538
|
+
}
|
|
539
|
+
return hydrateTextToDom(null, currentNode, parent);
|
|
540
|
+
}
|
|
541
|
+
function hydrateElementToDom(vnode, context, currentNode, rootComponent, parent) {
|
|
542
|
+
const element = nextHydratableNode(currentNode);
|
|
543
|
+
if (!(element instanceof Element) || element.localName !== vnode.type) {
|
|
544
|
+
const node = elementToRenderNode(vnode, context);
|
|
545
|
+
insertRenderNode(parent, node, currentNode);
|
|
546
|
+
return {
|
|
547
|
+
n: currentNode,
|
|
548
|
+
r: node
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
let child;
|
|
552
|
+
if (!isChildlessElement(vnode.type) && readDangerouslySetInnerHTML(vnode.props) === void 0) child = hydrateChildToDom(vnode.props.children ?? null, context, element.firstChild, rootComponent, element).r;
|
|
553
|
+
const node = {
|
|
554
|
+
c: child,
|
|
555
|
+
k: elementRenderNodeKind,
|
|
556
|
+
n: element,
|
|
557
|
+
r: [],
|
|
558
|
+
v: snapshotHostVNode(vnode)
|
|
559
|
+
};
|
|
560
|
+
collectRefEffects(element, vnode.props.ref, context.effects, node.r);
|
|
561
|
+
return {
|
|
562
|
+
n: element.nextSibling,
|
|
563
|
+
r: node
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
function hydrateComponentToDom(component, context, currentNode, rootComponent, parent, start, end) {
|
|
567
|
+
const componentStart = start ?? insertMarker(parent, currentNode);
|
|
568
|
+
const unsubscribe = subscribeComponent(component, context.scheduleUpdate);
|
|
569
|
+
let result;
|
|
570
|
+
try {
|
|
571
|
+
renderComponentChild(component, context.effects, (renderedChild) => {
|
|
572
|
+
result = hydrateChildToDom(renderedChild, renderContextWithOwner(context, component), currentNode, rootComponent, parent);
|
|
573
|
+
return result;
|
|
574
|
+
});
|
|
575
|
+
} catch (reason) {
|
|
576
|
+
unsubscribe();
|
|
577
|
+
throw reason;
|
|
578
|
+
}
|
|
579
|
+
if (result === void 0) {
|
|
580
|
+
unsubscribe();
|
|
581
|
+
fail("hydrate result");
|
|
582
|
+
}
|
|
583
|
+
const componentEnd = end ?? insertMarker(parent, result.n);
|
|
584
|
+
return {
|
|
585
|
+
n: end ? end.nextSibling : result.n,
|
|
586
|
+
r: {
|
|
587
|
+
c: result.r,
|
|
588
|
+
e: componentEnd,
|
|
589
|
+
k: componentRenderNodeKind,
|
|
590
|
+
s: componentStart,
|
|
591
|
+
u: unsubscribe,
|
|
592
|
+
v: component
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function hydrateTextToDom(value, currentNode, parent) {
|
|
597
|
+
const textNode = nextHydratableNode(currentNode);
|
|
598
|
+
if (textNode?.nodeType === Node.TEXT_NODE) return {
|
|
599
|
+
n: textNode.nextSibling,
|
|
600
|
+
r: {
|
|
601
|
+
k: textRenderNodeKind,
|
|
602
|
+
n: textNode
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
const node = ownerDocumentFor(parent).createTextNode(textValue(value));
|
|
606
|
+
parent.insertBefore(node, currentNode);
|
|
607
|
+
return {
|
|
608
|
+
n: currentNode,
|
|
609
|
+
r: {
|
|
610
|
+
k: textRenderNodeKind,
|
|
611
|
+
n: node
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
function hydrateRawToDom(raw, context, currentNode, parent) {
|
|
616
|
+
const start = nextHydratableNode(currentNode);
|
|
617
|
+
if (isRawStartComment(start)) {
|
|
618
|
+
const end = findDelimitedEnd(start, isRawStartComment, isRawEndComment);
|
|
619
|
+
if (end) return {
|
|
620
|
+
n: end.nextSibling,
|
|
621
|
+
r: hydrateRawRenderNode({
|
|
622
|
+
e: end,
|
|
623
|
+
h: [],
|
|
624
|
+
k: rawRenderNodeKind,
|
|
625
|
+
r: raw,
|
|
626
|
+
s: start
|
|
627
|
+
}, context.hydrateOptions)
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
const node = rawToRenderNode(raw, context.document, context.hydrateOptions);
|
|
631
|
+
insertRenderNode(parent, node, currentNode);
|
|
632
|
+
return {
|
|
633
|
+
n: currentNode,
|
|
634
|
+
r: node
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
function hydrateHydratedChildren(children, currentNode, parent) {
|
|
638
|
+
const start = insertMarker(parent, currentNode);
|
|
639
|
+
children.n = currentNode;
|
|
640
|
+
let node = currentNode;
|
|
641
|
+
while (node && node !== children.b.e) node = node.nextSibling;
|
|
642
|
+
return {
|
|
643
|
+
n: node,
|
|
644
|
+
r: {
|
|
645
|
+
c: children,
|
|
646
|
+
e: insertMarker(parent, node),
|
|
647
|
+
k: hydratedRenderNodeKind,
|
|
648
|
+
s: start
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
function hydrateSkippedBoundary(currentNode, parent) {
|
|
653
|
+
const start = findNextHydrateStart(currentNode);
|
|
654
|
+
const end = start ? findDelimitedEnd(start, isHydrateStartComment, isHydrateEndComment) : void 0;
|
|
655
|
+
if (!start || !end) return hydrateTextToDom(null, currentNode, parent);
|
|
656
|
+
return {
|
|
657
|
+
n: end.nextSibling,
|
|
658
|
+
r: {
|
|
659
|
+
e: end,
|
|
660
|
+
k: skippedHydrationRenderNodeKind,
|
|
661
|
+
s: start
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
function normalizeHydratedChildren(children) {
|
|
666
|
+
const normalized = [];
|
|
667
|
+
let text = "";
|
|
668
|
+
for (const child of normalizeChildren(children)) {
|
|
669
|
+
if (isPrimitiveValue(child)) {
|
|
670
|
+
text += String(child);
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
if (text) {
|
|
674
|
+
normalized.push(text);
|
|
675
|
+
text = "";
|
|
676
|
+
}
|
|
677
|
+
normalized.push(child);
|
|
678
|
+
}
|
|
679
|
+
if (text) normalized.push(text);
|
|
680
|
+
return normalized;
|
|
681
|
+
}
|
|
682
|
+
function patchRenderNode(node, nextChild, context) {
|
|
683
|
+
const replace = () => replaceRenderNode(node, nextChild, context);
|
|
684
|
+
if (isHydratedChildren(nextChild)) {
|
|
685
|
+
if (node.k === hydratedRenderNodeKind && node.c === nextChild) return node;
|
|
686
|
+
return replace();
|
|
687
|
+
}
|
|
688
|
+
if (isEmptyChild(nextChild) || isPrimitiveValue(nextChild)) {
|
|
689
|
+
if (node.k === textRenderNodeKind) {
|
|
690
|
+
const nextValue = textValue(nextChild);
|
|
691
|
+
if (node.n.data !== nextValue) node.n.data = nextValue;
|
|
692
|
+
return node;
|
|
693
|
+
}
|
|
694
|
+
return replace();
|
|
695
|
+
}
|
|
696
|
+
if (isRawChild(nextChild)) {
|
|
697
|
+
if (node.k === rawRenderNodeKind) return patchRawRenderNode(node, nextChild, context);
|
|
698
|
+
return replace();
|
|
699
|
+
}
|
|
700
|
+
if (Array.isArray(nextChild)) {
|
|
701
|
+
if (node.k === arrayRenderNodeKind) return patchArrayRenderNode(node, nextChild, context);
|
|
702
|
+
return replace();
|
|
703
|
+
}
|
|
704
|
+
if (isComponent(nextChild)) {
|
|
705
|
+
if (node.k === componentRenderNodeKind && node.v === nextChild) return patchComponentRenderNode(node, nextChild, context);
|
|
706
|
+
return replace();
|
|
707
|
+
}
|
|
708
|
+
if (isVNode(nextChild)) {
|
|
709
|
+
if (typeof nextChild.type === "function") return patchRenderNode(node, resolveComponent(nextChild, context.owner), context);
|
|
710
|
+
const vnode = nextChild;
|
|
711
|
+
if (node.k === elementRenderNodeKind && node.v.type === vnode.type && node.v.key === vnode.key) return patchElementRenderNode(node, vnode, context);
|
|
712
|
+
return replace();
|
|
713
|
+
}
|
|
714
|
+
return patchRenderNode(node, null, context);
|
|
715
|
+
}
|
|
716
|
+
function patchArrayRenderNode(node, nextChildren, context) {
|
|
717
|
+
const normalizedChildren = normalizeChildren(nextChildren);
|
|
718
|
+
if (shouldPatchKeyedArray(node.c, normalizedChildren)) return patchKeyedArrayRenderNode(node, normalizedChildren, context);
|
|
719
|
+
const sharedLength = Math.min(node.c.length, normalizedChildren.length);
|
|
720
|
+
for (let index = 0; index < sharedLength; index++) node.c[index] = patchRenderNode(node.c[index], normalizedChildren[index], context);
|
|
721
|
+
const parent = node.e.parentNode;
|
|
722
|
+
const addedChildren = [];
|
|
723
|
+
for (let index = sharedLength; index < normalizedChildren.length; index++) {
|
|
724
|
+
if (!parent) break;
|
|
725
|
+
const child = childToRenderNode(normalizedChildren[index], context);
|
|
726
|
+
node.c.push(child);
|
|
727
|
+
addedChildren.push(child);
|
|
728
|
+
}
|
|
729
|
+
if (parent && addedChildren.length > 0) {
|
|
730
|
+
const fragment = context.document.createDocumentFragment();
|
|
731
|
+
for (const child of addedChildren) appendRenderNode(fragment, child);
|
|
732
|
+
parent.insertBefore(fragment, node.e);
|
|
733
|
+
}
|
|
734
|
+
const removedChildren = node.c.splice(normalizedChildren.length);
|
|
735
|
+
for (let index = removedChildren.length - 1; index >= 0; index--) {
|
|
736
|
+
const child = removedChildren[index];
|
|
737
|
+
cleanupRenderNode(child);
|
|
738
|
+
}
|
|
739
|
+
const firstRemovedChild = removedChildren[0];
|
|
740
|
+
const lastRemovedChild = removedChildren.at(-1);
|
|
741
|
+
if (firstRemovedChild && lastRemovedChild) removeNodeRange(renderNodeStart(firstRemovedChild), renderNodeEnd(lastRemovedChild));
|
|
742
|
+
return node;
|
|
743
|
+
}
|
|
744
|
+
function patchKeyedArrayRenderNode(node, normalizedChildren, context) {
|
|
745
|
+
const parent = node.e.parentNode;
|
|
746
|
+
const oldEntries = /* @__PURE__ */ new Map();
|
|
747
|
+
for (let index = 0; index < node.c.length; index++) oldEntries.set(readRenderNodeKey(node.c[index]), {
|
|
748
|
+
i: index,
|
|
749
|
+
n: node.c[index]
|
|
750
|
+
});
|
|
751
|
+
const nextNodes = [];
|
|
752
|
+
const oldIndexes = [];
|
|
753
|
+
for (const child of normalizedChildren) {
|
|
754
|
+
const key = readChildKey(child);
|
|
755
|
+
const oldEntry = oldEntries.get(key);
|
|
756
|
+
if (oldEntry) {
|
|
757
|
+
oldEntries.delete(key);
|
|
758
|
+
nextNodes.push(patchRenderNode(oldEntry.n, child, context));
|
|
759
|
+
oldIndexes.push(oldEntry.i + 1);
|
|
760
|
+
} else {
|
|
761
|
+
nextNodes.push(childToRenderNode(child, context));
|
|
762
|
+
oldIndexes.push(0);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
for (const { n: removedNode } of oldEntries.values()) {
|
|
766
|
+
cleanupRenderNode(removedNode);
|
|
767
|
+
removeRenderNode(removedNode);
|
|
768
|
+
}
|
|
769
|
+
if (parent) {
|
|
770
|
+
const stableIndexes = lis(oldIndexes);
|
|
771
|
+
let stableCursor = stableIndexes.length - 1;
|
|
772
|
+
let anchor = node.e;
|
|
773
|
+
for (let index = nextNodes.length - 1; index >= 0; index--) {
|
|
774
|
+
const child = nextNodes[index];
|
|
775
|
+
if (stableIndexes[stableCursor] === index) stableCursor--;
|
|
776
|
+
else insertRenderNode(parent, child, anchor);
|
|
777
|
+
anchor = renderNodeStart(child);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
node.c = nextNodes;
|
|
781
|
+
return node;
|
|
782
|
+
}
|
|
783
|
+
function shouldPatchKeyedArray(oldNodes, nextChildren) {
|
|
784
|
+
const firstOld = oldNodes[0];
|
|
785
|
+
const firstNext = nextChildren[0];
|
|
786
|
+
if (firstOld?.k !== elementRenderNodeKind || firstOld.v.key === void 0 || !isVNode(firstNext) || firstNext.key === void 0) return false;
|
|
787
|
+
if (oldNodes.length <= nextChildren.length) {
|
|
788
|
+
for (let index = 0; index < oldNodes.length; index++) if (readRenderNodeKey(oldNodes[index]) !== readChildKey(nextChildren[index])) return true;
|
|
789
|
+
return false;
|
|
790
|
+
}
|
|
791
|
+
return true;
|
|
792
|
+
}
|
|
793
|
+
function readChildKey(child) {
|
|
794
|
+
return isVNode(child) ? child.key : void 0;
|
|
795
|
+
}
|
|
796
|
+
function readRenderNodeKey(node) {
|
|
797
|
+
return node.k === elementRenderNodeKind ? node.v.key : void 0;
|
|
798
|
+
}
|
|
799
|
+
function lis(values) {
|
|
800
|
+
const p = Array.from({ length: values.length });
|
|
801
|
+
const t = [];
|
|
802
|
+
for (let index = 0; index < values.length; index++) {
|
|
803
|
+
const value = values[index];
|
|
804
|
+
if (value === 0) continue;
|
|
805
|
+
let low = 0;
|
|
806
|
+
let high = t.length;
|
|
807
|
+
while (low < high) {
|
|
808
|
+
const middle = low + high >> 1;
|
|
809
|
+
if (values[t[middle]] < value) low = middle + 1;
|
|
810
|
+
else high = middle;
|
|
811
|
+
}
|
|
812
|
+
p[index] = low > 0 ? t[low - 1] : -1;
|
|
813
|
+
t[low] = index;
|
|
814
|
+
}
|
|
815
|
+
let cursor = t.at(-1) ?? -1;
|
|
816
|
+
for (let index = t.length - 1; index >= 0; index--) {
|
|
817
|
+
t[index] = cursor;
|
|
818
|
+
cursor = p[cursor] ?? -1;
|
|
819
|
+
}
|
|
820
|
+
return t;
|
|
821
|
+
}
|
|
822
|
+
function patchComponentRenderNode(node, component, context) {
|
|
823
|
+
return renderComponentChild(component, context.effects, (renderedChild) => {
|
|
824
|
+
node.c = patchRenderNode(node.c, renderedChild, renderContextWithOwner(context, component));
|
|
825
|
+
return node;
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
function patchRawRenderNode(node, raw, context) {
|
|
829
|
+
if (readRawChildHtml(node.r) === readRawChildHtml(raw)) {
|
|
830
|
+
node.r = raw;
|
|
831
|
+
return node;
|
|
832
|
+
}
|
|
833
|
+
const parent = node.s.parentNode;
|
|
834
|
+
if (parent !== null && parent === node.e.parentNode) patchDomChildren(parent, node.s.nextSibling, htmlToFragment(parent, readRawChildHtml(raw)).childNodes, context.document, node.e);
|
|
835
|
+
node.h = node.h.filter((hydrationRoot) => {
|
|
836
|
+
if (hydrationRoot.s.parentNode !== null) return true;
|
|
837
|
+
hydrationRoot.u({ removeContents: false });
|
|
838
|
+
return false;
|
|
839
|
+
});
|
|
840
|
+
node.r = raw;
|
|
841
|
+
if (context.hydrateOptions !== void 0) hydrateRawRenderNode(node, context.hydrateOptions);
|
|
842
|
+
return node;
|
|
843
|
+
}
|
|
844
|
+
function patchElementRenderNode(node, vnode, context) {
|
|
845
|
+
const refChanged = node.v.props.ref !== vnode.props.ref;
|
|
846
|
+
if (refChanged) {
|
|
847
|
+
runCleanups(node.r);
|
|
848
|
+
node.r = [];
|
|
849
|
+
}
|
|
850
|
+
patchProps(node.n, node.v.props, vnode.props);
|
|
851
|
+
if (!isChildlessElement(vnode.type)) {
|
|
852
|
+
const nextInnerHTML = readDangerouslySetInnerHTML(vnode.props);
|
|
853
|
+
const previousInnerHTML = readDangerouslySetInnerHTML(node.v.props);
|
|
854
|
+
if (nextInnerHTML !== void 0) {
|
|
855
|
+
if (node.c !== void 0) {
|
|
856
|
+
cleanupRenderNode(node.c);
|
|
857
|
+
node.c = void 0;
|
|
858
|
+
}
|
|
859
|
+
if (previousInnerHTML !== nextInnerHTML) patchDomChildren(node.n, node.n.firstChild, htmlToFragment(node.n, nextInnerHTML).childNodes, context.document);
|
|
860
|
+
} else if (previousInnerHTML !== void 0) {
|
|
861
|
+
node.n.textContent = "";
|
|
862
|
+
node.c = childToRenderNode(vnode.props.children ?? null, context);
|
|
863
|
+
insertRenderNode(node.n, node.c, null);
|
|
864
|
+
} else if (node.c !== void 0) node.c = patchRenderNode(node.c, vnode.props.children ?? null, context);
|
|
865
|
+
else {
|
|
866
|
+
node.c = childToRenderNode(vnode.props.children ?? null, context);
|
|
867
|
+
insertRenderNode(node.n, node.c, null);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
node.v = snapshotHostVNode(vnode);
|
|
871
|
+
if (refChanged) collectRefEffects(node.n, vnode.props.ref, context.effects, node.r);
|
|
872
|
+
return node;
|
|
873
|
+
}
|
|
874
|
+
function replaceRenderNode(node, nextChild, context) {
|
|
875
|
+
const parent = renderNodeStart(node).parentNode;
|
|
876
|
+
const nextSibling = renderNodeEnd(node).nextSibling;
|
|
877
|
+
const replacement = childToRenderNode(nextChild, context);
|
|
878
|
+
cleanupRenderNode(node);
|
|
879
|
+
removeRenderNode(node);
|
|
880
|
+
if (parent) insertRenderNode(parent, replacement, nextSibling);
|
|
881
|
+
return replacement;
|
|
882
|
+
}
|
|
883
|
+
function textToRenderNode(value, document) {
|
|
884
|
+
return {
|
|
885
|
+
k: textRenderNodeKind,
|
|
886
|
+
n: document.createTextNode(textValue(value))
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
function rawToRenderNode(raw, document, hydrateOptions) {
|
|
890
|
+
const node = {
|
|
891
|
+
e: createMarker(document),
|
|
892
|
+
h: [],
|
|
893
|
+
k: rawRenderNodeKind,
|
|
894
|
+
r: raw,
|
|
895
|
+
s: createMarker(document)
|
|
896
|
+
};
|
|
897
|
+
if (hydrateOptions) queueRawHydration(node, hydrateOptions);
|
|
898
|
+
return node;
|
|
899
|
+
}
|
|
900
|
+
function queueRawHydration(node, hydrateOptions) {
|
|
901
|
+
Promise.resolve().then(() => {
|
|
902
|
+
if (isRawRenderNodeConnected(node)) hydrateRawRenderNode(node, hydrateOptions);
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
function hydrateRawRenderNode(node, hydrateOptions) {
|
|
906
|
+
hydrateRawBoundaries(node, hydrateOptions).then((hydrationRoots) => {
|
|
907
|
+
if (!isRawRenderNodeConnected(node)) {
|
|
908
|
+
for (const hydrationRoot of hydrationRoots) hydrationRoot.u();
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
node.h = hydrationRoots;
|
|
912
|
+
}, () => {});
|
|
913
|
+
return node;
|
|
914
|
+
}
|
|
915
|
+
async function hydrateRawBoundaries(node, hydrateOptions) {
|
|
916
|
+
const [boundaries, hydrateMeta] = findHydrationBoundariesBetween(node.s, node.e);
|
|
917
|
+
const hydrationRoots = [];
|
|
918
|
+
for (const boundary of boundaries) {
|
|
919
|
+
if (!isRawRenderNodeConnected(node)) break;
|
|
920
|
+
const activeRoot = activeHydrationBoundaries.get(boundary.s);
|
|
921
|
+
if (activeRoot !== void 0) {
|
|
922
|
+
hydrationRoots.push(activeRoot);
|
|
923
|
+
continue;
|
|
924
|
+
}
|
|
925
|
+
const meta = hydrateMeta.get(boundary.i);
|
|
926
|
+
if (meta === void 0) fail("raw metadata");
|
|
927
|
+
const factory = await hydrateOptions.load(meta);
|
|
928
|
+
if (!isRawRenderNodeConnected(node)) break;
|
|
929
|
+
hydrationRoots.push(hydrateBoundary(boundary, factory, hydrateOptions));
|
|
930
|
+
}
|
|
931
|
+
return hydrationRoots;
|
|
932
|
+
}
|
|
933
|
+
function isRawRenderNodeConnected(node) {
|
|
934
|
+
return !!node.s.parentNode && node.s.parentNode === node.e.parentNode;
|
|
935
|
+
}
|
|
936
|
+
function htmlToFragment(parent, html) {
|
|
937
|
+
const range = ownerDocumentFor(parent).createRange();
|
|
938
|
+
if (parent instanceof Element || parent instanceof DocumentFragment) range.selectNodeContents(parent);
|
|
939
|
+
else range.selectNode(parent);
|
|
940
|
+
return range.createContextualFragment(html);
|
|
941
|
+
}
|
|
942
|
+
function patchDocumentWithHtml(document, html) {
|
|
943
|
+
const parsed = new DOMParser().parseFromString(html, "text/html");
|
|
944
|
+
patchDocumentType(document, parsed);
|
|
945
|
+
patchElementAttributes(document.documentElement, parsed.documentElement);
|
|
946
|
+
patchDocumentSection(document, document.head, parsed.head);
|
|
947
|
+
patchDocumentSection(document, document.body, parsed.body);
|
|
948
|
+
}
|
|
949
|
+
function patchDocumentType(document, parsed) {
|
|
950
|
+
if (parsed.doctype === null) {
|
|
951
|
+
document.doctype?.remove();
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
const current = document.doctype;
|
|
955
|
+
if (current?.name === parsed.doctype.name && current.publicId === parsed.doctype.publicId && current.systemId === parsed.doctype.systemId) return;
|
|
956
|
+
const next = document.implementation.createDocumentType(parsed.doctype.name, parsed.doctype.publicId, parsed.doctype.systemId);
|
|
957
|
+
if (current) document.replaceChild(next, current);
|
|
958
|
+
else document.insertBefore(next, document.documentElement);
|
|
959
|
+
}
|
|
960
|
+
function patchDocumentSection(document, current, parsed) {
|
|
961
|
+
patchElementAttributes(current, parsed);
|
|
962
|
+
if (current === document.head) patchHeadChildren(document, parsed);
|
|
963
|
+
else patchDomChildren(current, current.firstChild, parsed.childNodes, document);
|
|
964
|
+
}
|
|
965
|
+
function patchHeadChildren(document, parsed) {
|
|
966
|
+
const reusedHeadNodes = /* @__PURE__ */ new Set();
|
|
967
|
+
patchDomChildren(document.head, document.head.firstChild, parsed.childNodes, document, void 0, (parsedNode) => {
|
|
968
|
+
const persistentNode = findPersistentHeadNode(document, parsedNode, reusedHeadNodes);
|
|
969
|
+
if (persistentNode !== void 0) reusedHeadNodes.add(persistentNode);
|
|
970
|
+
return persistentNode;
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
function findPersistentHeadNode(document, parsedNode, reusedHeadNodes) {
|
|
974
|
+
if (!(parsedNode instanceof Element)) return;
|
|
975
|
+
for (const child of document.head.children) {
|
|
976
|
+
if (reusedHeadNodes.has(child) || !isPersistentHeadNodeMatch(document, child, parsedNode)) continue;
|
|
977
|
+
return child;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
function isPersistentHeadNodeMatch(document, current, parsed) {
|
|
981
|
+
if (current instanceof HTMLLinkElement && parsed instanceof HTMLLinkElement && current.relList.contains("stylesheet") && parsed.relList.contains("stylesheet")) return stylesheetHref(document, stylesheetLinkHref(current)) === stylesheetHref(document, stylesheetLinkHref(parsed));
|
|
982
|
+
if (current instanceof HTMLScriptElement && parsed instanceof HTMLScriptElement && scriptSource(current) && scriptSource(parsed)) return scriptHref(document, scriptSource(current)) === scriptHref(document, scriptSource(parsed));
|
|
983
|
+
return false;
|
|
984
|
+
}
|
|
985
|
+
function scriptHref(document, src) {
|
|
986
|
+
try {
|
|
987
|
+
return new URL(src, document.baseURI).href;
|
|
988
|
+
} catch {
|
|
989
|
+
return new URL(src, location.href).href;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
function scriptSource(script) {
|
|
993
|
+
return script.getAttribute("src") ?? script.src;
|
|
994
|
+
}
|
|
995
|
+
function patchDomChildren(parent, anchor, parsedChildren, document, end, findReusableNode) {
|
|
996
|
+
const flushRefreshes = pendingHydrationBoundaryRefreshes === void 0;
|
|
997
|
+
if (flushRefreshes) pendingHydrationBoundaryRefreshes = [];
|
|
998
|
+
for (const parsedChild of parsedChildren) {
|
|
999
|
+
anchor = skipUnmatchedEmptyTextNodes(anchor, parsedChild, end);
|
|
1000
|
+
const reusableNode = findReusableNode?.(parsedChild);
|
|
1001
|
+
let child;
|
|
1002
|
+
if (reusableNode !== void 0) child = patchDomNode(reusableNode, parsedChild, document);
|
|
1003
|
+
else if (anchor && anchor !== end && canPatchDomNode(anchor, parsedChild)) child = patchDomNode(anchor, parsedChild, document);
|
|
1004
|
+
else child = document.importNode(parsedChild, true);
|
|
1005
|
+
if (child === anchor) {
|
|
1006
|
+
anchor = child.nextSibling;
|
|
1007
|
+
continue;
|
|
1008
|
+
}
|
|
1009
|
+
parent.insertBefore(child, anchor === end ? end : anchor);
|
|
1010
|
+
}
|
|
1011
|
+
removeSiblings(anchor, end);
|
|
1012
|
+
if (flushRefreshes) {
|
|
1013
|
+
const refreshes = pendingHydrationBoundaryRefreshes;
|
|
1014
|
+
pendingHydrationBoundaryRefreshes = void 0;
|
|
1015
|
+
for (const start of refreshes ?? []) refreshHydrationBoundary(start);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
function skipUnmatchedEmptyTextNodes(anchor, parsedChild, end) {
|
|
1019
|
+
while (anchor && anchor !== end && isEmptyTextNode(anchor) && !canPatchDomNode(anchor, parsedChild)) {
|
|
1020
|
+
const next = anchor.nextSibling;
|
|
1021
|
+
anchor.parentNode?.removeChild(anchor);
|
|
1022
|
+
anchor = next;
|
|
1023
|
+
}
|
|
1024
|
+
return anchor;
|
|
1025
|
+
}
|
|
1026
|
+
function removeSiblings(anchor, end) {
|
|
1027
|
+
while (anchor && anchor !== end) {
|
|
1028
|
+
const next = anchor.nextSibling;
|
|
1029
|
+
anchor.parentNode?.removeChild(anchor);
|
|
1030
|
+
anchor = next;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
function patchDomNode(current, parsed, document) {
|
|
1034
|
+
if (!canPatchDomNode(current, parsed)) {
|
|
1035
|
+
const replacement = document.importNode(parsed, true);
|
|
1036
|
+
current.parentNode?.replaceChild(replacement, current);
|
|
1037
|
+
return replacement;
|
|
1038
|
+
}
|
|
1039
|
+
if (current.nodeType === Node.TEXT_NODE || current.nodeType === Node.COMMENT_NODE) {
|
|
1040
|
+
if (current.nodeValue !== parsed.nodeValue) {
|
|
1041
|
+
current.nodeValue = parsed.nodeValue;
|
|
1042
|
+
if (current.nodeType === Node.COMMENT_NODE) refreshActiveHydrationBoundary(current);
|
|
1043
|
+
}
|
|
1044
|
+
return current;
|
|
1045
|
+
}
|
|
1046
|
+
if (current instanceof Element && parsed instanceof Element) {
|
|
1047
|
+
patchElementAttributes(current, parsed);
|
|
1048
|
+
if (!isChildlessElement(current.localName)) patchDomChildren(current, current.firstChild, parsed.childNodes, document);
|
|
1049
|
+
patchFormElementProperties(current, parsed);
|
|
1050
|
+
}
|
|
1051
|
+
return current;
|
|
1052
|
+
}
|
|
1053
|
+
function refreshActiveHydrationBoundary(start) {
|
|
1054
|
+
if (pendingHydrationBoundaryRefreshes) pendingHydrationBoundaryRefreshes.push(start);
|
|
1055
|
+
else refreshHydrationBoundary(start);
|
|
1056
|
+
}
|
|
1057
|
+
function refreshHydrationBoundary(start) {
|
|
1058
|
+
const hydrationRoot = activeHydrationBoundaries.get(start);
|
|
1059
|
+
if (hydrationRoot === void 0) return;
|
|
1060
|
+
const marker = parseHydrateStartComment(start);
|
|
1061
|
+
if (marker) hydrationRoot.r(marker.i, marker.p, marker.k);
|
|
1062
|
+
}
|
|
1063
|
+
function canPatchDomNode(current, parsed) {
|
|
1064
|
+
if (current.nodeType !== parsed.nodeType) return false;
|
|
1065
|
+
if (current instanceof Element && parsed instanceof Element) return current.namespaceURI === parsed.namespaceURI && current.localName === parsed.localName;
|
|
1066
|
+
return true;
|
|
1067
|
+
}
|
|
1068
|
+
function isEmptyTextNode(node) {
|
|
1069
|
+
return node.nodeType === Node.TEXT_NODE && node.nodeValue === "";
|
|
1070
|
+
}
|
|
1071
|
+
function patchElementAttributes(current, parsed) {
|
|
1072
|
+
for (const name of current.getAttributeNames()) if (!parsed.hasAttribute(name)) current.removeAttribute(name);
|
|
1073
|
+
for (const { name, value } of parsed.attributes) if (current.getAttribute(name) !== value) current.setAttribute(name, value);
|
|
1074
|
+
}
|
|
1075
|
+
function patchFormElementProperties(current, parsed) {
|
|
1076
|
+
if (current instanceof HTMLInputElement && parsed instanceof HTMLInputElement) {
|
|
1077
|
+
if (current.type === "checkbox" || current.type === "radio") {
|
|
1078
|
+
current.checked = parsed.hasAttribute("checked");
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
current.value = parsed.getAttribute("value") ?? "";
|
|
1082
|
+
} else if (current instanceof HTMLTextAreaElement && parsed instanceof HTMLTextAreaElement) current.value = parsed.value;
|
|
1083
|
+
else if (current instanceof HTMLOptionElement && parsed instanceof HTMLOptionElement) current.selected = parsed.hasAttribute("selected");
|
|
1084
|
+
}
|
|
1085
|
+
function waitForHtmlStylesheets(document, html) {
|
|
1086
|
+
const parsed = new DOMParser().parseFromString(html, "text/html");
|
|
1087
|
+
const hrefs = [];
|
|
1088
|
+
for (const link of parsed.querySelectorAll("link[href]")) if (isLoadBlockingStylesheet(link)) hrefs.push(stylesheetLinkHref(link));
|
|
1089
|
+
return waitForStylesheets(document, hrefs, true);
|
|
1090
|
+
}
|
|
1091
|
+
function waitForConnectedStylesheets(document) {
|
|
1092
|
+
const hrefs = [];
|
|
1093
|
+
for (const link of document.querySelectorAll("link[href]")) if (isLoadBlockingStylesheet(link)) hrefs.push(stylesheetLinkHref(link));
|
|
1094
|
+
return waitForStylesheets(document, hrefs, false);
|
|
1095
|
+
}
|
|
1096
|
+
function waitForStylesheets(document, hrefs, createMissingLinks) {
|
|
1097
|
+
const pendingStylesheets = [];
|
|
1098
|
+
for (const href of hrefs) {
|
|
1099
|
+
const pendingStylesheet = waitForStylesheet(document, href, createMissingLinks);
|
|
1100
|
+
if (pendingStylesheet !== void 0) pendingStylesheets.push(pendingStylesheet);
|
|
1101
|
+
}
|
|
1102
|
+
if (pendingStylesheets.length === 0) return;
|
|
1103
|
+
return Promise.all(pendingStylesheets).then(() => {});
|
|
1104
|
+
}
|
|
1105
|
+
function waitForStylesheet(document, href, createMissingLink) {
|
|
1106
|
+
const absoluteHref = stylesheetHref(document, href);
|
|
1107
|
+
const loadedStylesheets = ensureLoadedStylesheets(document);
|
|
1108
|
+
if (loadedStylesheets.has(absoluteHref)) return;
|
|
1109
|
+
let link = findStylesheetLink(document, absoluteHref);
|
|
1110
|
+
if (link?.sheet) {
|
|
1111
|
+
loadedStylesheets.add(absoluteHref);
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
const stylesheetPromises = ensureStylesheetPromises(document);
|
|
1115
|
+
const existingPromise = stylesheetPromises.get(absoluteHref);
|
|
1116
|
+
if (existingPromise !== void 0) return existingPromise;
|
|
1117
|
+
if (link === void 0) {
|
|
1118
|
+
if (!createMissingLink || document.head === null) return;
|
|
1119
|
+
link = document.createElement("link");
|
|
1120
|
+
link.rel = "stylesheet";
|
|
1121
|
+
link.href = absoluteHref;
|
|
1122
|
+
document.head.append(link);
|
|
1123
|
+
}
|
|
1124
|
+
const promise = new Promise((resolve) => {
|
|
1125
|
+
const finish = () => {
|
|
1126
|
+
link.removeEventListener("load", finish);
|
|
1127
|
+
link.removeEventListener("error", finish);
|
|
1128
|
+
loadedStylesheets.add(absoluteHref);
|
|
1129
|
+
stylesheetPromises.delete(absoluteHref);
|
|
1130
|
+
resolve();
|
|
1131
|
+
};
|
|
1132
|
+
link.addEventListener("load", finish);
|
|
1133
|
+
link.addEventListener("error", finish);
|
|
1134
|
+
if (link.sheet) finish();
|
|
1135
|
+
});
|
|
1136
|
+
stylesheetPromises.set(absoluteHref, promise);
|
|
1137
|
+
return promise;
|
|
1138
|
+
}
|
|
1139
|
+
function stylesheetHref(document, href) {
|
|
1140
|
+
try {
|
|
1141
|
+
return new URL(href, document.baseURI).href;
|
|
1142
|
+
} catch {
|
|
1143
|
+
return new URL(href, location.href).href;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
function stylesheetLinkHref(link) {
|
|
1147
|
+
return link.getAttribute("href") ?? link.href;
|
|
1148
|
+
}
|
|
1149
|
+
function isLoadBlockingStylesheet(link) {
|
|
1150
|
+
if (!link.relList.contains("stylesheet") || link.disabled) return false;
|
|
1151
|
+
const media = link.media.trim();
|
|
1152
|
+
if (!media || media === "all") return true;
|
|
1153
|
+
return typeof matchMedia === "undefined" || matchMedia(media).matches;
|
|
1154
|
+
}
|
|
1155
|
+
function findStylesheetLink(document, href, excluded = /* @__PURE__ */ new Set()) {
|
|
1156
|
+
for (const link of document.querySelectorAll("link[href]")) if (!excluded.has(link) && isLoadBlockingStylesheet(link) && stylesheetHref(document, stylesheetLinkHref(link)) === href) return link;
|
|
1157
|
+
}
|
|
1158
|
+
function ensureStylesheetPromises(document) {
|
|
1159
|
+
let stylesheetPromises = stylesheetPromisesByDocument.get(document);
|
|
1160
|
+
if (stylesheetPromises === void 0) {
|
|
1161
|
+
stylesheetPromises = /* @__PURE__ */ new Map();
|
|
1162
|
+
stylesheetPromisesByDocument.set(document, stylesheetPromises);
|
|
1163
|
+
}
|
|
1164
|
+
return stylesheetPromises;
|
|
1165
|
+
}
|
|
1166
|
+
function ensureLoadedStylesheets(document) {
|
|
1167
|
+
let loadedStylesheets = loadedStylesheetsByDocument.get(document);
|
|
1168
|
+
if (loadedStylesheets === void 0) {
|
|
1169
|
+
loadedStylesheets = /* @__PURE__ */ new Set();
|
|
1170
|
+
loadedStylesheetsByDocument.set(document, loadedStylesheets);
|
|
1171
|
+
}
|
|
1172
|
+
return loadedStylesheets;
|
|
1173
|
+
}
|
|
1174
|
+
function textValue(value) {
|
|
1175
|
+
return isPrimitiveValue(value) ? String(value) : "";
|
|
1176
|
+
}
|
|
1177
|
+
function arrayToRenderNode(children, context) {
|
|
1178
|
+
return {
|
|
1179
|
+
c: normalizeChildren(children).map((child) => childToRenderNode(child, context)),
|
|
1180
|
+
e: createMarker(context.document),
|
|
1181
|
+
k: arrayRenderNodeKind,
|
|
1182
|
+
s: createMarker(context.document)
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
function componentToRenderNode(component, context) {
|
|
1186
|
+
const unsubscribe = subscribeComponent(component, context.scheduleUpdate);
|
|
1187
|
+
let child;
|
|
1188
|
+
try {
|
|
1189
|
+
renderComponentChild(component, context.effects, (renderedChild) => {
|
|
1190
|
+
child = childToRenderNode(renderedChild, renderContextWithOwner(context, component));
|
|
1191
|
+
return child;
|
|
1192
|
+
});
|
|
1193
|
+
} catch (reason) {
|
|
1194
|
+
unsubscribe();
|
|
1195
|
+
throw reason;
|
|
1196
|
+
}
|
|
1197
|
+
if (child === void 0) {
|
|
1198
|
+
unsubscribe();
|
|
1199
|
+
fail("render node");
|
|
1200
|
+
}
|
|
1201
|
+
return {
|
|
1202
|
+
c: child,
|
|
1203
|
+
e: createMarker(context.document),
|
|
1204
|
+
k: componentRenderNodeKind,
|
|
1205
|
+
s: createMarker(context.document),
|
|
1206
|
+
u: unsubscribe,
|
|
1207
|
+
v: component
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
function elementToRenderNode(vnode, context) {
|
|
1211
|
+
const element = context.document.createElement(vnode.type);
|
|
1212
|
+
let child;
|
|
1213
|
+
patchProps(element, {}, vnode.props);
|
|
1214
|
+
if (!isChildlessElement(vnode.type)) {
|
|
1215
|
+
const innerHTML = readDangerouslySetInnerHTML(vnode.props);
|
|
1216
|
+
if (innerHTML !== void 0) element.innerHTML = innerHTML;
|
|
1217
|
+
else {
|
|
1218
|
+
child = childToRenderNode(vnode.props.children ?? null, context);
|
|
1219
|
+
insertRenderNode(element, child, null);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
const node = {
|
|
1223
|
+
c: child,
|
|
1224
|
+
k: elementRenderNodeKind,
|
|
1225
|
+
n: element,
|
|
1226
|
+
r: [],
|
|
1227
|
+
v: snapshotHostVNode(vnode)
|
|
1228
|
+
};
|
|
1229
|
+
collectRefEffects(element, vnode.props.ref, context.effects, node.r);
|
|
1230
|
+
return node;
|
|
1231
|
+
}
|
|
1232
|
+
function snapshotHostVNode(vnode) {
|
|
1233
|
+
const { style } = vnode.props;
|
|
1234
|
+
if (!style) return vnode;
|
|
1235
|
+
return {
|
|
1236
|
+
...vnode,
|
|
1237
|
+
props: {
|
|
1238
|
+
...vnode.props,
|
|
1239
|
+
style: { ...style }
|
|
1240
|
+
}
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
function hydratedChildrenToRenderNode(children, document) {
|
|
1244
|
+
const start = createMarker(document);
|
|
1245
|
+
const end = createMarker(document);
|
|
1246
|
+
const fragment = document.createDocumentFragment();
|
|
1247
|
+
fragment.append(start);
|
|
1248
|
+
appendHydratedChildren(fragment, children);
|
|
1249
|
+
fragment.append(end);
|
|
1250
|
+
return {
|
|
1251
|
+
c: children,
|
|
1252
|
+
e: end,
|
|
1253
|
+
k: hydratedRenderNodeKind,
|
|
1254
|
+
s: start
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
function nextHydratableNode(node) {
|
|
1258
|
+
let currentNode = node;
|
|
1259
|
+
while (isHydrateMetaComment(currentNode)) currentNode = currentNode.nextSibling;
|
|
1260
|
+
return currentNode;
|
|
1261
|
+
}
|
|
1262
|
+
function findNextHydrateStart(node) {
|
|
1263
|
+
let currentNode = node;
|
|
1264
|
+
while (currentNode) {
|
|
1265
|
+
if (isHydrateStartComment(currentNode)) return currentNode;
|
|
1266
|
+
if (!isHydrateMetaComment(currentNode)) return;
|
|
1267
|
+
currentNode = currentNode.nextSibling;
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
function findDelimitedEnd(start, isStart, isEnd) {
|
|
1271
|
+
let depth = 0;
|
|
1272
|
+
let currentNode = start;
|
|
1273
|
+
while (currentNode) {
|
|
1274
|
+
if (isStart(currentNode)) depth++;
|
|
1275
|
+
else if (isEnd(currentNode)) {
|
|
1276
|
+
depth--;
|
|
1277
|
+
if (depth === 0) return currentNode;
|
|
1278
|
+
}
|
|
1279
|
+
currentNode = currentNode.nextSibling;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
function removeBoundaryContents(boundary) {
|
|
1283
|
+
removeDelimitedContents(boundary.s, boundary.e);
|
|
1284
|
+
}
|
|
1285
|
+
function insertMarker(parent, before) {
|
|
1286
|
+
const marker = createMarker(ownerDocumentFor(parent));
|
|
1287
|
+
parent.insertBefore(marker, before?.parentNode === parent ? before : null);
|
|
1288
|
+
return marker;
|
|
1289
|
+
}
|
|
1290
|
+
function createMarker(document) {
|
|
1291
|
+
return document.createTextNode("");
|
|
1292
|
+
}
|
|
1293
|
+
function insertRenderNode(parent, node, before) {
|
|
1294
|
+
parent.insertBefore(renderNodeToFragment(node), before);
|
|
1295
|
+
}
|
|
1296
|
+
function renderNodeToFragment(node) {
|
|
1297
|
+
const fragment = ownerDocumentFor(renderNodeStart(node)).createDocumentFragment();
|
|
1298
|
+
appendRenderNode(fragment, node);
|
|
1299
|
+
return fragment;
|
|
1300
|
+
}
|
|
1301
|
+
function appendRenderNode(parent, node) {
|
|
1302
|
+
switch (node.k) {
|
|
1303
|
+
case arrayRenderNodeKind:
|
|
1304
|
+
parent.appendChild(node.s);
|
|
1305
|
+
for (const child of node.c) appendRenderNode(parent, child);
|
|
1306
|
+
parent.appendChild(node.e);
|
|
1307
|
+
return;
|
|
1308
|
+
case componentRenderNodeKind:
|
|
1309
|
+
parent.appendChild(node.s);
|
|
1310
|
+
appendRenderNode(parent, node.c);
|
|
1311
|
+
parent.appendChild(node.e);
|
|
1312
|
+
return;
|
|
1313
|
+
case elementRenderNodeKind:
|
|
1314
|
+
parent.appendChild(node.n);
|
|
1315
|
+
return;
|
|
1316
|
+
case hydratedRenderNodeKind:
|
|
1317
|
+
parent.appendChild(node.s);
|
|
1318
|
+
appendHydratedChildren(parent, node.c);
|
|
1319
|
+
parent.appendChild(node.e);
|
|
1320
|
+
return;
|
|
1321
|
+
case rawRenderNodeKind:
|
|
1322
|
+
if (node.s.parentNode && node.s.parentNode === node.e.parentNode) appendNodeRange(parent, node.s, node.e);
|
|
1323
|
+
else {
|
|
1324
|
+
parent.appendChild(node.s);
|
|
1325
|
+
parent.appendChild(htmlToFragment(parent, readRawChildHtml(node.r)));
|
|
1326
|
+
parent.appendChild(node.e);
|
|
1327
|
+
}
|
|
1328
|
+
return;
|
|
1329
|
+
case skippedHydrationRenderNodeKind:
|
|
1330
|
+
appendNodeRange(parent, node.s, node.e);
|
|
1331
|
+
return;
|
|
1332
|
+
case textRenderNodeKind:
|
|
1333
|
+
parent.appendChild(node.n);
|
|
1334
|
+
return;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
function appendHydratedChildren(parent, children) {
|
|
1338
|
+
let node = children.n;
|
|
1339
|
+
while (node && node !== children.b.e) {
|
|
1340
|
+
const nextNode = node.nextSibling;
|
|
1341
|
+
parent.appendChild(node);
|
|
1342
|
+
node = nextNode;
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
function appendNodeRange(parent, start, end) {
|
|
1346
|
+
let child = start;
|
|
1347
|
+
while (child) {
|
|
1348
|
+
const next = child === end ? null : child.nextSibling;
|
|
1349
|
+
parent.appendChild(child);
|
|
1350
|
+
if (child === end) return;
|
|
1351
|
+
child = next;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
function removeRenderNode(node) {
|
|
1355
|
+
removeNodeRange(renderNodeStart(node), renderNodeEnd(node));
|
|
1356
|
+
}
|
|
1357
|
+
function removeDelimitedContents(start, end) {
|
|
1358
|
+
const first = start.nextSibling;
|
|
1359
|
+
const last = end.previousSibling;
|
|
1360
|
+
if (first && last && first !== end && last !== start) removeNodeRange(first, last);
|
|
1361
|
+
}
|
|
1362
|
+
function removeNodeRange(start, end) {
|
|
1363
|
+
const parent = start.parentNode;
|
|
1364
|
+
if (!parent || parent !== end.parentNode) return;
|
|
1365
|
+
let node = start;
|
|
1366
|
+
while (node) {
|
|
1367
|
+
const next = node === end ? null : node.nextSibling;
|
|
1368
|
+
parent.removeChild(node);
|
|
1369
|
+
node = next;
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
function cleanupRenderNode(node) {
|
|
1373
|
+
switch (node.k) {
|
|
1374
|
+
case arrayRenderNodeKind:
|
|
1375
|
+
for (let index = node.c.length - 1; index >= 0; index--) cleanupRenderNode(node.c[index]);
|
|
1376
|
+
return;
|
|
1377
|
+
case componentRenderNodeKind:
|
|
1378
|
+
node.u();
|
|
1379
|
+
cleanupRenderNode(node.c);
|
|
1380
|
+
return;
|
|
1381
|
+
case elementRenderNodeKind:
|
|
1382
|
+
runCleanups(node.r);
|
|
1383
|
+
node.r = [];
|
|
1384
|
+
if (node.c !== void 0) cleanupRenderNode(node.c);
|
|
1385
|
+
return;
|
|
1386
|
+
case rawRenderNodeKind:
|
|
1387
|
+
for (const hydrationRoot of node.h) hydrationRoot.u();
|
|
1388
|
+
node.h = [];
|
|
1389
|
+
return;
|
|
1390
|
+
case hydratedRenderNodeKind:
|
|
1391
|
+
case skippedHydrationRenderNodeKind:
|
|
1392
|
+
case textRenderNodeKind: return;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
function renderNodeStart(node) {
|
|
1396
|
+
return node.k === elementRenderNodeKind || node.k === textRenderNodeKind ? node.n : node.s;
|
|
1397
|
+
}
|
|
1398
|
+
function renderNodeEnd(node) {
|
|
1399
|
+
return node.k === elementRenderNodeKind || node.k === textRenderNodeKind ? node.n : node.e;
|
|
1400
|
+
}
|
|
1401
|
+
function ownerDocumentFor(node) {
|
|
1402
|
+
if (node instanceof Document) return node;
|
|
1403
|
+
invariant(node.ownerDocument, "owner document");
|
|
1404
|
+
return node.ownerDocument;
|
|
1405
|
+
}
|
|
1406
|
+
function renderComponentChild(component, effects, renderChild) {
|
|
1407
|
+
beginComponentRender(component);
|
|
1408
|
+
try {
|
|
1409
|
+
const refEffectStart = effects.r.length;
|
|
1410
|
+
const mountEffectStart = effects.m.length;
|
|
1411
|
+
try {
|
|
1412
|
+
const result = renderChild(renderComponentOutput(component));
|
|
1413
|
+
queueComponentMount(component, effects.m);
|
|
1414
|
+
return result;
|
|
1415
|
+
} catch (reason) {
|
|
1416
|
+
effects.r.splice(refEffectStart);
|
|
1417
|
+
effects.m.splice(mountEffectStart);
|
|
1418
|
+
beginComponentRender(component);
|
|
1419
|
+
const result = renderChild(renderComponentErrorOutput(component, reason));
|
|
1420
|
+
queueComponentMount(component, effects.m);
|
|
1421
|
+
return result;
|
|
1422
|
+
}
|
|
1423
|
+
} finally {
|
|
1424
|
+
finishComponentRender(component);
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
function findHydrationBoundaries(root) {
|
|
1428
|
+
const walker = (root instanceof Document ? root : root.ownerDocument).createTreeWalker(root, NodeFilter.SHOW_COMMENT);
|
|
1429
|
+
const hydrateMeta = /* @__PURE__ */ new Map();
|
|
1430
|
+
const boundaries = [];
|
|
1431
|
+
const stack = [];
|
|
1432
|
+
let currentNode = walker.nextNode();
|
|
1433
|
+
while (currentNode) {
|
|
1434
|
+
collectHydrationBoundary(currentNode, hydrateMeta, boundaries, stack);
|
|
1435
|
+
currentNode = walker.nextNode();
|
|
1436
|
+
}
|
|
1437
|
+
return [boundaries, hydrateMeta];
|
|
1438
|
+
}
|
|
1439
|
+
function findHydrationBoundariesBetween(start, end) {
|
|
1440
|
+
const hydrateMeta = /* @__PURE__ */ new Map();
|
|
1441
|
+
const boundaries = [];
|
|
1442
|
+
const stack = [];
|
|
1443
|
+
let node = start.nextSibling;
|
|
1444
|
+
while (node && node !== end) {
|
|
1445
|
+
collectHydrationBoundariesIn(node, hydrateMeta, boundaries, stack);
|
|
1446
|
+
node = node.nextSibling;
|
|
1447
|
+
}
|
|
1448
|
+
return [boundaries, hydrateMeta];
|
|
1449
|
+
}
|
|
1450
|
+
function collectHydrationBoundary(comment, hydrateMeta, boundaries, stack) {
|
|
1451
|
+
const meta = parseHydrateMetaComment(comment);
|
|
1452
|
+
if (meta) {
|
|
1453
|
+
hydrateMeta.set(meta.i, meta.v);
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1456
|
+
const boundaryStart = parseHydrateStartComment(comment);
|
|
1457
|
+
if (boundaryStart) stack.push({
|
|
1458
|
+
i: boundaryStart.i,
|
|
1459
|
+
k: boundaryStart.k,
|
|
1460
|
+
p: boundaryStart.p,
|
|
1461
|
+
s: comment
|
|
1462
|
+
});
|
|
1463
|
+
else if (isHydrateEndComment(comment)) {
|
|
1464
|
+
const startedBoundary = stack.pop();
|
|
1465
|
+
if (startedBoundary) boundaries.push({
|
|
1466
|
+
...startedBoundary,
|
|
1467
|
+
e: comment
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
function collectHydrationBoundariesIn(root, hydrateMeta, boundaries, stack) {
|
|
1472
|
+
if (root.nodeType === Node.COMMENT_NODE) collectHydrationBoundary(root, hydrateMeta, boundaries, stack);
|
|
1473
|
+
const walker = ownerDocumentFor(root).createTreeWalker(root, NodeFilter.SHOW_COMMENT);
|
|
1474
|
+
let currentNode = walker.nextNode();
|
|
1475
|
+
while (currentNode) {
|
|
1476
|
+
collectHydrationBoundary(currentNode, hydrateMeta, boundaries, stack);
|
|
1477
|
+
currentNode = walker.nextNode();
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
function parseHydrateMetaComment(comment) {
|
|
1481
|
+
return parseHydrateMetaCommentData(comment.data);
|
|
1482
|
+
}
|
|
1483
|
+
function parseHydrateStartComment(comment) {
|
|
1484
|
+
return parseHydrateStartCommentData(comment.data);
|
|
1485
|
+
}
|
|
1486
|
+
function isHydrateMetaComment(node) {
|
|
1487
|
+
return isCommentData(node, isHydrateMetaCommentData);
|
|
1488
|
+
}
|
|
1489
|
+
function isHydrateStartComment(node) {
|
|
1490
|
+
return isCommentData(node, isHydrateStartCommentData);
|
|
1491
|
+
}
|
|
1492
|
+
function isHydrateEndComment(node) {
|
|
1493
|
+
return isCommentData(node, isHydrateEndCommentData);
|
|
1494
|
+
}
|
|
1495
|
+
function isRawStartComment(node) {
|
|
1496
|
+
return isCommentData(node, isRawStartCommentData);
|
|
1497
|
+
}
|
|
1498
|
+
function isRawEndComment(node) {
|
|
1499
|
+
return isCommentData(node, isRawEndCommentData);
|
|
1500
|
+
}
|
|
1501
|
+
function isCommentData(node, isMarkerCommentData) {
|
|
1502
|
+
return node?.nodeType === Node.COMMENT_NODE && isMarkerCommentData(node.data);
|
|
1503
|
+
}
|
|
1504
|
+
//#endregion
|
|
1505
|
+
export { Component, Fragment, Raw, createElement, event, hydrate, isComponent, isVNode, jsx, jsx as jsxs, jsxDEV, render };
|