@shadow-js/web 1.0.1 → 1.0.3
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 +37 -0
- package/dist/dev/attributes.d.ts +10 -3
- package/dist/dev/attributes.js +27 -49
- package/dist/dev/attributes.js.map +1 -1
- package/dist/dev/class-style.d.ts +15 -6
- package/dist/dev/class-style.js +64 -47
- package/dist/dev/class-style.js.map +1 -1
- package/dist/dev/control-flow/dynamic.d.ts +11 -2
- package/dist/dev/control-flow/dynamic.js +57 -40
- package/dist/dev/control-flow/dynamic.js.map +1 -1
- package/dist/dev/control-flow/error-boundary.js +2 -2
- package/dist/dev/control-flow/error-boundary.js.map +1 -1
- package/dist/dev/control-flow/portal.d.ts +2 -2
- package/dist/dev/control-flow/portal.js +17 -13
- package/dist/dev/control-flow/portal.js.map +1 -1
- package/dist/dev/control-flow/suspense-list.js +2 -2
- package/dist/dev/control-flow/suspense-list.js.map +1 -1
- package/dist/dev/control-flow/suspense.js +2 -2
- package/dist/dev/control-flow/suspense.js.map +1 -1
- package/dist/dev/element.js +6 -3
- package/dist/dev/element.js.map +1 -1
- package/dist/dev/events.js +15 -44
- package/dist/dev/events.js.map +1 -1
- package/dist/dev/extend.d.ts +2 -2
- package/dist/dev/extend.js +2 -2
- package/dist/dev/insert.d.ts +26 -5
- package/dist/dev/insert.js +84 -45
- package/dist/dev/insert.js.map +1 -1
- package/dist/dev/internal/accessor.js +56 -0
- package/dist/dev/internal/accessor.js.map +1 -0
- package/dist/dev/internal/claim.d.ts +2 -1
- package/dist/dev/internal/claim.js +18 -3
- package/dist/dev/internal/claim.js.map +1 -1
- package/dist/dev/internal/css-units.js +2 -2
- package/dist/dev/internal/css-units.js.map +1 -1
- package/dist/dev/internal/diagnostics.d.ts +7 -3
- package/dist/dev/internal/diagnostics.js +14 -4
- package/dist/dev/internal/diagnostics.js.map +1 -1
- package/dist/dev/internal/early-events.js +20 -2
- package/dist/dev/internal/early-events.js.map +1 -1
- package/dist/dev/internal/portal-context.d.ts +9 -0
- package/dist/dev/internal/portal-context.js.map +1 -1
- package/dist/dev/internal/react-names.js +45 -71
- package/dist/dev/internal/react-names.js.map +1 -1
- package/dist/dev/internal/reconcile.js +7 -12
- package/dist/dev/internal/reconcile.js.map +1 -1
- package/dist/dev/jsx/global.d.ts +5 -2
- package/dist/dev/jsx/html.d.ts +1 -0
- package/dist/dev/resource-hints.js +4 -2
- package/dist/dev/resource-hints.js.map +1 -1
- package/dist/dev/select-value.js +5 -15
- package/dist/dev/select-value.js.map +1 -1
- package/dist/dev/server/attributes.d.ts +3 -0
- package/dist/dev/server/attributes.js +6 -32
- package/dist/dev/server/attributes.js.map +1 -1
- package/dist/dev/server/element.js +10 -7
- package/dist/dev/server/element.js.map +1 -1
- package/dist/dev/server/errors.js +7 -1
- package/dist/dev/server/errors.js.map +1 -1
- package/dist/dev/server/escape.js +14 -6
- package/dist/dev/server/escape.js.map +1 -1
- package/dist/dev/server/form-controls.js +5 -2
- package/dist/dev/server/form-controls.js.map +1 -1
- package/dist/dev/server/index.d.ts +2 -1
- package/dist/dev/server/index.js +3 -2
- package/dist/dev/server/portals.js +3 -0
- package/dist/dev/server/portals.js.map +1 -1
- package/dist/dev/server/raw-text.d.ts +28 -0
- package/dist/dev/server/raw-text.js +66 -0
- package/dist/dev/server/raw-text.js.map +1 -0
- package/dist/dev/server/render.d.ts +2 -1
- package/dist/dev/server/render.js +3 -3
- package/dist/dev/server/render.js.map +1 -1
- package/dist/dev/server/stream.d.ts +1 -1
- package/dist/dev/server/stream.js +3 -3
- package/dist/dev/server/stream.js.map +1 -1
- package/dist/dev/server.d.ts +2 -1
- package/dist/dev/server.js +3 -2
- package/dist/dev/spread.js +56 -81
- package/dist/dev/spread.js.map +1 -1
- package/dist/dev/template.js +1 -3
- package/dist/dev/template.js.map +1 -1
- package/dist/dev/view-transition.js +12 -4
- package/dist/dev/view-transition.js.map +1 -1
- package/dist/prod/attributes.js +1 -1
- package/dist/prod/attributes.js.map +1 -1
- package/dist/prod/class-style.js +1 -1
- package/dist/prod/class-style.js.map +1 -1
- package/dist/prod/control-flow/dynamic.js +1 -1
- package/dist/prod/control-flow/dynamic.js.map +1 -1
- package/dist/prod/control-flow/error-boundary.js +1 -1
- package/dist/prod/control-flow/error-boundary.js.map +1 -1
- package/dist/prod/control-flow/portal.js +1 -1
- package/dist/prod/control-flow/portal.js.map +1 -1
- package/dist/prod/control-flow/suspense-list.js +1 -1
- package/dist/prod/control-flow/suspense-list.js.map +1 -1
- package/dist/prod/control-flow/suspense.js +1 -1
- package/dist/prod/control-flow/suspense.js.map +1 -1
- package/dist/prod/element.js +1 -1
- package/dist/prod/element.js.map +1 -1
- package/dist/prod/events.js +1 -1
- package/dist/prod/events.js.map +1 -1
- package/dist/prod/extend.js +1 -1
- package/dist/prod/insert.js +1 -1
- package/dist/prod/insert.js.map +1 -1
- package/dist/prod/internal/accessor.js +2 -0
- package/dist/prod/internal/accessor.js.map +1 -0
- package/dist/prod/internal/claim.js +1 -1
- package/dist/prod/internal/claim.js.map +1 -1
- package/dist/prod/internal/css-units.js +1 -1
- package/dist/prod/internal/css-units.js.map +1 -1
- package/dist/prod/internal/diagnostics.js +1 -1
- package/dist/prod/internal/diagnostics.js.map +1 -1
- package/dist/prod/internal/early-events.js +1 -1
- package/dist/prod/internal/early-events.js.map +1 -1
- package/dist/prod/internal/portal-context.js.map +1 -1
- package/dist/prod/internal/react-names.js +1 -1
- package/dist/prod/internal/react-names.js.map +1 -1
- package/dist/prod/internal/reconcile.js +1 -1
- package/dist/prod/internal/reconcile.js.map +1 -1
- package/dist/prod/resource-hints.js +1 -1
- package/dist/prod/resource-hints.js.map +1 -1
- package/dist/prod/select-value.js +1 -1
- package/dist/prod/select-value.js.map +1 -1
- package/dist/prod/server/attributes.js +1 -1
- package/dist/prod/server/attributes.js.map +1 -1
- package/dist/prod/server/element.js +1 -1
- package/dist/prod/server/element.js.map +1 -1
- package/dist/prod/server/errors.js +1 -1
- package/dist/prod/server/errors.js.map +1 -1
- package/dist/prod/server/escape.js +1 -1
- package/dist/prod/server/escape.js.map +1 -1
- package/dist/prod/server/form-controls.js +2 -2
- package/dist/prod/server/form-controls.js.map +1 -1
- package/dist/prod/server/index.js +1 -1
- package/dist/prod/server/portals.js +1 -1
- package/dist/prod/server/portals.js.map +1 -1
- package/dist/prod/server/raw-text.js +2 -0
- package/dist/prod/server/raw-text.js.map +1 -0
- package/dist/prod/server/render.js +1 -1
- package/dist/prod/server/render.js.map +1 -1
- package/dist/prod/server/stream.js +1 -1
- package/dist/prod/server/stream.js.map +1 -1
- package/dist/prod/server.js +1 -1
- package/dist/prod/spread.js +1 -1
- package/dist/prod/spread.js.map +1 -1
- package/dist/prod/template.js +1 -1
- package/dist/prod/template.js.map +1 -1
- package/dist/prod/view-transition.js +1 -1
- package/dist/prod/view-transition.js.map +1 -1
- package/dist/server/attributes.js +1 -1
- package/dist/server/attributes.js.map +1 -1
- package/dist/server/class-style.js +1 -1
- package/dist/server/class-style.js.map +1 -1
- package/dist/server/control-flow/dynamic.js +1 -1
- package/dist/server/control-flow/dynamic.js.map +1 -1
- package/dist/server/control-flow/error-boundary.js +1 -1
- package/dist/server/control-flow/error-boundary.js.map +1 -1
- package/dist/server/control-flow/portal.js +1 -1
- package/dist/server/control-flow/portal.js.map +1 -1
- package/dist/server/control-flow/suspense-list.js +1 -1
- package/dist/server/control-flow/suspense-list.js.map +1 -1
- package/dist/server/control-flow/suspense.js +1 -1
- package/dist/server/control-flow/suspense.js.map +1 -1
- package/dist/server/element.js +1 -1
- package/dist/server/element.js.map +1 -1
- package/dist/server/events.js +1 -1
- package/dist/server/events.js.map +1 -1
- package/dist/server/extend.js +1 -1
- package/dist/server/insert.js +1 -1
- package/dist/server/insert.js.map +1 -1
- package/dist/server/internal/accessor.js +2 -0
- package/dist/server/internal/accessor.js.map +1 -0
- package/dist/server/internal/claim.js +1 -1
- package/dist/server/internal/claim.js.map +1 -1
- package/dist/server/internal/css-units.js +1 -1
- package/dist/server/internal/css-units.js.map +1 -1
- package/dist/server/internal/diagnostics.js +1 -1
- package/dist/server/internal/diagnostics.js.map +1 -1
- package/dist/server/internal/early-events.js +1 -1
- package/dist/server/internal/early-events.js.map +1 -1
- package/dist/server/internal/portal-context.js.map +1 -1
- package/dist/server/internal/react-names.js +1 -1
- package/dist/server/internal/react-names.js.map +1 -1
- package/dist/server/internal/reconcile.js +1 -1
- package/dist/server/internal/reconcile.js.map +1 -1
- package/dist/server/resource-hints.js +1 -1
- package/dist/server/resource-hints.js.map +1 -1
- package/dist/server/select-value.js +1 -1
- package/dist/server/select-value.js.map +1 -1
- package/dist/server/server/attributes.js +1 -1
- package/dist/server/server/attributes.js.map +1 -1
- package/dist/server/server/element.js +1 -1
- package/dist/server/server/element.js.map +1 -1
- package/dist/server/server/errors.js +1 -1
- package/dist/server/server/errors.js.map +1 -1
- package/dist/server/server/escape.js +1 -1
- package/dist/server/server/escape.js.map +1 -1
- package/dist/server/server/form-controls.js +2 -2
- package/dist/server/server/form-controls.js.map +1 -1
- package/dist/server/server/index.js +1 -1
- package/dist/server/server/portals.js +1 -1
- package/dist/server/server/portals.js.map +1 -1
- package/dist/server/server/raw-text.js +2 -0
- package/dist/server/server/raw-text.js.map +1 -0
- package/dist/server/server/render.js +1 -1
- package/dist/server/server/render.js.map +1 -1
- package/dist/server/server/stream.js +1 -1
- package/dist/server/server/stream.js.map +1 -1
- package/dist/server/server.js +1 -1
- package/dist/server/spread.js +1 -1
- package/dist/server/spread.js.map +1 -1
- package/dist/server/template.js +1 -1
- package/dist/server/template.js.map +1 -1
- package/dist/server/view-transition.js.map +1 -1
- package/dist/server-dev/attributes.js +27 -49
- package/dist/server-dev/attributes.js.map +1 -1
- package/dist/server-dev/class-style.js +64 -47
- package/dist/server-dev/class-style.js.map +1 -1
- package/dist/server-dev/control-flow/dynamic.js +22 -10
- package/dist/server-dev/control-flow/dynamic.js.map +1 -1
- package/dist/server-dev/control-flow/error-boundary.js +2 -2
- package/dist/server-dev/control-flow/error-boundary.js.map +1 -1
- package/dist/server-dev/control-flow/portal.js +17 -13
- package/dist/server-dev/control-flow/portal.js.map +1 -1
- package/dist/server-dev/control-flow/suspense-list.js +2 -2
- package/dist/server-dev/control-flow/suspense-list.js.map +1 -1
- package/dist/server-dev/control-flow/suspense.js +2 -2
- package/dist/server-dev/control-flow/suspense.js.map +1 -1
- package/dist/server-dev/element.js +3 -1
- package/dist/server-dev/element.js.map +1 -1
- package/dist/server-dev/events.js +15 -44
- package/dist/server-dev/events.js.map +1 -1
- package/dist/server-dev/extend.js +2 -2
- package/dist/server-dev/insert.js +84 -45
- package/dist/server-dev/insert.js.map +1 -1
- package/dist/server-dev/internal/accessor.js +56 -0
- package/dist/server-dev/internal/accessor.js.map +1 -0
- package/dist/server-dev/internal/claim.js +18 -3
- package/dist/server-dev/internal/claim.js.map +1 -1
- package/dist/server-dev/internal/css-units.js +2 -2
- package/dist/server-dev/internal/css-units.js.map +1 -1
- package/dist/server-dev/internal/diagnostics.js +14 -4
- package/dist/server-dev/internal/diagnostics.js.map +1 -1
- package/dist/server-dev/internal/early-events.js +20 -2
- package/dist/server-dev/internal/early-events.js.map +1 -1
- package/dist/server-dev/internal/portal-context.js.map +1 -1
- package/dist/server-dev/internal/react-names.js +45 -71
- package/dist/server-dev/internal/react-names.js.map +1 -1
- package/dist/server-dev/internal/reconcile.js +7 -12
- package/dist/server-dev/internal/reconcile.js.map +1 -1
- package/dist/server-dev/resource-hints.js +4 -2
- package/dist/server-dev/resource-hints.js.map +1 -1
- package/dist/server-dev/select-value.js +5 -15
- package/dist/server-dev/select-value.js.map +1 -1
- package/dist/server-dev/server/attributes.js +6 -32
- package/dist/server-dev/server/attributes.js.map +1 -1
- package/dist/server-dev/server/element.js +10 -7
- package/dist/server-dev/server/element.js.map +1 -1
- package/dist/server-dev/server/errors.js +7 -1
- package/dist/server-dev/server/errors.js.map +1 -1
- package/dist/server-dev/server/escape.js +14 -6
- package/dist/server-dev/server/escape.js.map +1 -1
- package/dist/server-dev/server/form-controls.js +5 -2
- package/dist/server-dev/server/form-controls.js.map +1 -1
- package/dist/server-dev/server/index.js +3 -2
- package/dist/server-dev/server/portals.js +3 -0
- package/dist/server-dev/server/portals.js.map +1 -1
- package/dist/server-dev/server/raw-text.js +86 -0
- package/dist/server-dev/server/raw-text.js.map +1 -0
- package/dist/server-dev/server/render.js +3 -3
- package/dist/server-dev/server/render.js.map +1 -1
- package/dist/server-dev/server/stream.js +3 -3
- package/dist/server-dev/server/stream.js.map +1 -1
- package/dist/server-dev/server.js +3 -2
- package/dist/server-dev/spread.js +42 -80
- package/dist/server-dev/spread.js.map +1 -1
- package/dist/server-dev/template.js +1 -3
- package/dist/server-dev/template.js.map +1 -1
- package/dist/server-dev/view-transition.js.map +1 -1
- package/package.json +4 -3
|
@@ -48,7 +48,6 @@ function prepare(root, pending, lifted) {
|
|
|
48
48
|
const stack = [root];
|
|
49
49
|
while (stack.length > 0) {
|
|
50
50
|
const parent = stack.pop();
|
|
51
|
-
if (parent === void 0) break;
|
|
52
51
|
let child = parent.firstChild;
|
|
53
52
|
while (child !== null) {
|
|
54
53
|
const following = child.nextSibling;
|
|
@@ -211,6 +210,21 @@ function checkClaimedText(claimed, parts) {
|
|
|
211
210
|
console.warn(`[shadow HYDRATION_TEXT_MISMATCH] ${detail}`);
|
|
212
211
|
devtoolsReport(DEVTOOLS_EVENT.HYDRATION_MISMATCH, detail, void 0, void 0);
|
|
213
212
|
}
|
|
213
|
+
/** HTML elements whose content is text and nothing else: no comment can mark a region inside them. */
|
|
214
|
+
const TEXT_ONLY = /* @__PURE__ */ new Set([
|
|
215
|
+
"script",
|
|
216
|
+
"style",
|
|
217
|
+
"title",
|
|
218
|
+
"textarea"
|
|
219
|
+
]);
|
|
220
|
+
/**
|
|
221
|
+
* True for a `script`, `style`, `title` or `textarea`, in whichever namespace the parser put it: `Dynamic` knows no
|
|
222
|
+
* parent, so the server writes the children of such a tag without region markers even where the page parses it as
|
|
223
|
+
* an SVG `title` or `style`. Its whole content is then the one region.
|
|
224
|
+
*/
|
|
225
|
+
function isTextOnly(node) {
|
|
226
|
+
return node.nodeType === 1 && TEXT_ONLY.has(node.localName);
|
|
227
|
+
}
|
|
214
228
|
/**
|
|
215
229
|
* Adopts the server content of the next region of a claimed parent while `hydrate()` runs: the nodes
|
|
216
230
|
* that sat between the region's markers are put back before `anchorNode` and returned, so a custom
|
|
@@ -219,7 +233,8 @@ function checkClaimedText(claimed, parts) {
|
|
|
219
233
|
* @param parent An element returned by {@link claimElement} (or one of its descendants).
|
|
220
234
|
* @param anchorNode The node the content goes before; `null` appends it at the end of `parent`.
|
|
221
235
|
* @returns The adopted nodes; undefined when no hydration pass is running or `parent` has no region
|
|
222
|
-
* left to adopt (the caller then inserts fresh nodes).
|
|
236
|
+
* left to adopt (the caller then inserts fresh nodes). A `script`, `style`, `title` or `textarea` has no
|
|
237
|
+
* markers (the server writes its text as the parser reads it): its current children are the region.
|
|
223
238
|
* @example
|
|
224
239
|
* import { takeRegion } from "@shadow-js/web/extend";
|
|
225
240
|
*
|
|
@@ -237,7 +252,7 @@ function takeRegion(parent, anchorNode) {
|
|
|
237
252
|
const current = state;
|
|
238
253
|
if (current === null) return void 0;
|
|
239
254
|
const content = current.pending.get(parent)?.shift();
|
|
240
|
-
if (content === void 0) return void 0;
|
|
255
|
+
if (content === void 0) return isTextOnly(parent) ? Array.from(parent.childNodes) : void 0;
|
|
241
256
|
for (const node of content) parent.insertBefore(node, anchorNode);
|
|
242
257
|
return content;
|
|
243
258
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claim.js","names":[],"sources":["../../../src/internal/claim.ts"],"sourcesContent":["import { DEVTOOLS_EVENT, devtoolsReport } from \"@shadow-js/core/extend\";\n\n/** What a hydration pass in progress knows. Exists only while `hydrate()` runs its synchronous pass. */\ninterface HydrationState {\n /** Server elements by `data-hk` key; entries are consumed when claimed. */\n readonly registry: Map<string, Element>;\n /** Told about each mismatch the pass repaired (the `onRecoverableError` option). */\n readonly recoverable: ((error: unknown) => void) | undefined;\n /** Region contents taken out of each claimed parent, in document order. */\n readonly pending: WeakMap<Node, Node[][]>;\n /** The content of every region lifted out of a claimed element, in document order (read by `NoHydration`). */\n readonly lifted: Node[][];\n}\n\nlet state: HydrationState | null = null;\n\n/** Starts a claiming pass over the given server elements. @internal */\nexport function beginClaiming(\n registry: Map<string, Element>,\n recoverable?: (error: unknown) => void,\n): void {\n state = { registry, recoverable, pending: new WeakMap(), lifted: [] };\n}\n\n/** Ends the claiming pass. @internal */\nexport function endClaiming(): void {\n state = null;\n}\n\n/**\n * Reports whether a `hydrate()` pass is claiming server DOM right now: a custom renderer reads it to\n * decide between adopting server nodes and building fresh ones. The pass is synchronous, so this is\n * `false` again once `hydrate()` returns, and in every later update.\n *\n * @returns `true` during the synchronous pass of `hydrate()` (outside {@link withoutClaiming}),\n * `false` otherwise.\n * @example\n * import { isClaiming } from \"@shadow-js/web/extend\";\n *\n * function describe(): string {\n * return isClaiming() ? \"adopting server markup\" : \"building fresh DOM\";\n * }\n * @see claims\n * @since 1.0.0\n */\nexport function isClaiming(): boolean {\n return state !== null;\n}\n\nfunction isMarker(node: Node, data: string): boolean {\n if (node.nodeType !== 8) return false;\n const text = (node as Comment).data;\n // `[b:ID` opens a Suspense boundary region (streaming); it hydrates like a plain region.\n return text === data || (data === \"[\" && text.startsWith(\"[b:\"));\n}\n\n/**\n * Turns server markup for one template into the shape a freshly cloned template has: region\n * contents are lifted out (to be re-inserted by `insert`), marker comments are removed and text\n * nodes are merged again. Iterative; static elements below the root are walked, regions are not\n * (their contents belong to other templates, claimed later through the registry).\n */\nfunction prepare(root: Element, pending: WeakMap<Node, Node[][]>, lifted: Node[][]): void {\n const stack: Element[] = [root];\n while (stack.length > 0) {\n const parent = stack.pop();\n if (parent === undefined) break;\n let child: ChildNode | null = parent.firstChild;\n while (child !== null) {\n const following: ChildNode | null = child.nextSibling;\n if (isMarker(child, \"[\")) {\n const content: Node[] = [];\n let depth = 1;\n let cursor: ChildNode | null = child.nextSibling;\n while (cursor !== null) {\n if (isMarker(cursor, \"[\")) depth += 1;\n else if (isMarker(cursor, \"]\")) {\n depth -= 1;\n if (depth === 0) break;\n }\n content.push(cursor);\n cursor = cursor.nextSibling;\n }\n const after: ChildNode | null = cursor === null ? null : cursor.nextSibling;\n lifted.push(content);\n for (const node of content) parent.removeChild(node);\n parent.removeChild(child);\n if (cursor !== null) parent.removeChild(cursor);\n const queue = pending.get(parent);\n if (queue === undefined) pending.set(parent, [content]);\n else queue.push(content);\n child = after;\n continue;\n }\n if (child.nodeType === 1) stack.push(child as Element);\n child = following;\n }\n }\n root.normalize();\n}\n\n/**\n * Adopts the server's element for a hydration key while `hydrate()` runs: the step that lets a custom\n * template reuse server markup instead of creating new nodes. The element loses its `data-hk`\n * attribute, and the content of its regions is lifted out, to be adopted by {@link takeRegion} when\n * the regions bind. Prefer `claims.current.claimElement`, which links this code only into apps that\n * call `hydrate()`.\n *\n * @param key The key from `nextKey()`, drawn where the server drew it. Undefined claims nothing.\n * @returns The server element; `null` when no hydration pass is running, when `key` is undefined, or\n * when the server sent no element for the key (the caller then creates the node itself). A missing\n * key is a recoverable mismatch: development builds warn `HYDRATION_KEY_MISS`, and the pass's\n * `onRecoverableError` receives an `Error`.\n * @example\n * import { claimElement, nextKey } from \"@shadow-js/web/extend\";\n *\n * function createPanel(): Element {\n * // During hydrate(): the server's <section>. Otherwise: a new one.\n * return claimElement(nextKey()) ?? document.createElement(\"section\");\n * }\n * @see claims\n * @since 1.0.0\n */\nexport function claimElement(key: string | undefined): Element | null {\n const current = state;\n if (current === null || key === undefined) return null;\n const element = current.registry.get(key);\n if (element === undefined) {\n // Production keeps only the code (the same split as core's messages): the text stays out of the bundle.\n if (__DEV__) {\n const message = `No server element for key \"${key}\".`;\n console.warn(`[shadow HYDRATION_KEY_MISS] ${message}`);\n devtoolsReport(DEVTOOLS_EVENT.HYDRATION_MISMATCH, message, key, undefined);\n }\n current.recoverable?.(\n new Error(__DEV__ ? `No server element for key \"${key}\".` : \"SHADOW_HYDRATION_KEY_MISS\"),\n );\n return null;\n }\n current.registry.delete(key);\n element.removeAttribute(\"data-hk\");\n prepare(element, current.pending, current.lifted);\n return element;\n}\n\n/** Characters that stay readable as escapes in a diagnostic snippet: markup, quotes and ampersands. */\nconst SNIPPET_ESCAPES: ReadonlyMap<string, string> = new Map([\n [\"<\", \"\\\\u003c\"],\n [\">\", \"\\\\u003e\"],\n [\"&\", \"\\\\u0026\"],\n ['\"', \"\\\\u0022\"],\n [\"'\", \"\\\\u0027\"],\n]);\n\n/**\n * Escapes text for a diagnostic snippet and cuts it to `limit` output characters, with `...` when cut.\n * Escapes are never split, so the output is at most `limit + 3` characters.\n * @internal\n */\nfunction snippet(text: string, limit: number): string {\n let out = \"\";\n for (const char of text) {\n const code = char.codePointAt(0) ?? 0;\n const controlled = code < 0x20 || (code >= 0x7f && code <= 0x9f);\n const escaped =\n SNIPPET_ESCAPES.get(char) ?? (controlled ? `\\\\u${code.toString(16).padStart(4, \"0\")}` : char);\n if (out.length + escaped.length > limit) return `${out}...`;\n out += escaped;\n }\n return out;\n}\n\n/** The opening tag of a server element as the server wrote it (attribute values as they are). */\nfunction openingMarkup(element: Element): string {\n let markup = `<${element.localName}`;\n for (const attr of Array.from(element.attributes)) markup += ` ${attr.name}=\"${attr.value}\"`;\n return `${markup}>`;\n}\n\n/**\n * Development check of a claimed element against the tag its template or `element()` call expects.\n * A different tag warns `HYDRATION_MISMATCH` on the console and in devtools, with an escaped snippet of\n * the server element (its opening tag and the start of its text, bounded). Recovery is unchanged: the\n * element is still adopted, nothing is thrown or replaced, and the caller gets the same value.\n *\n * Call it under `if (__DEV__)`. Text is not compared here: the expected text is inserted later, by\n * `insert`, and {@link checkClaimedText} compares it with the server text at that point.\n *\n * @param element The server element `claimElement` returned.\n * @param expectedTag The tag the client expects (any case).\n * @internal\n */\nexport function checkClaimedTag(element: Element, expectedTag: string): void {\n if (!__DEV__) return;\n const expected = expectedTag.toLowerCase();\n const actual = element.localName.toLowerCase();\n if (actual === expected) return;\n const text = element.textContent ?? \"\";\n let detail = `expected <${expected}> but the server sent <${snippet(actual, 80)}>; server markup: \"${snippet(openingMarkup(element), 80)}\"`;\n if (text !== \"\") detail += `; text: \"${snippet(text, 40)}\"`;\n console.warn(`[shadow HYDRATION_MISMATCH] ${detail}`);\n devtoolsReport(DEVTOOLS_EVENT.HYDRATION_MISMATCH, detail, undefined, undefined);\n}\n\n/**\n * Development check of the first commit of a region that claimed server text. The server text is the\n * DOM text of the claimed nodes (already decoded, so an escaped `<` compares as `<`); the expected\n * text is the strings of the first commit, joined (a number is already its string, `null` and booleans\n * render nothing, so they expect `\"\"`). Equal text is silent. Different text warns\n * `HYDRATION_TEXT_MISMATCH` on the console and in devtools, with both texts escaped and bounded to 40\n * characters. Recovery is unchanged: the region shows the value the client computed.\n *\n * Not compared, so silent: a region that claimed no nodes (an empty server region has no server text),\n * a region whose server nodes are not all text (an element, or the markers of a nested region), and a\n * commit that holds a node (an element is shown in place of the server's content, as before).\n *\n * Call it under `if (__DEV__)`, once per claimed region, at its first commit.\n *\n * @param claimed The server nodes the region adopted, in document order.\n * @param parts What the first commit shows: strings, or nodes.\n * @internal\n * @since 1.0.0\n */\nexport function checkClaimedText(\n claimed: readonly Node[],\n parts: readonly (Node | string)[],\n): void {\n if (!__DEV__) return;\n if (claimed.length === 0) return;\n let server = \"\";\n for (const node of claimed) {\n if (node.nodeType !== 3) return;\n server += node.textContent ?? \"\";\n }\n let expected = \"\";\n for (const part of parts) {\n if (typeof part !== \"string\") return;\n expected += part;\n }\n if (expected === server) return;\n const detail = `expected text \"${snippet(expected, 40)}\" but the server sent text \"${snippet(server, 40)}\"`;\n console.warn(`[shadow HYDRATION_TEXT_MISMATCH] ${detail}`);\n devtoolsReport(DEVTOOLS_EVENT.HYDRATION_MISMATCH, detail, undefined, undefined);\n}\n\n/**\n * Adopts the server content of the next region of a claimed parent while `hydrate()` runs: the nodes\n * that sat between the region's markers are put back before `anchorNode` and returned, so a custom\n * region can bind to them instead of inserting new nodes. Regions are taken in document order.\n *\n * @param parent An element returned by {@link claimElement} (or one of its descendants).\n * @param anchorNode The node the content goes before; `null` appends it at the end of `parent`.\n * @returns The adopted nodes; undefined when no hydration pass is running or `parent` has no region\n * left to adopt (the caller then inserts fresh nodes).\n * @example\n * import { takeRegion } from \"@shadow-js/web/extend\";\n *\n * function fillRegion(parent: Element): Node[] {\n * const adopted = takeRegion(parent, null);\n * if (adopted !== undefined) return adopted;\n * const text = document.createTextNode(\"fresh\");\n * parent.append(text);\n * return [text];\n * }\n * @see claimElement\n * @since 1.0.0\n */\nexport function takeRegion(parent: Node, anchorNode: Node | null): Node[] | undefined {\n const current = state;\n if (current === null) return undefined;\n const content = current.pending.get(parent)?.shift();\n if (content === undefined) return undefined;\n for (const node of content) parent.insertBefore(node, anchorNode);\n return content;\n}\n\n/**\n * The content of every region the pass lifted out of the server elements it claimed, in document order. `NoHydration` finds\n * its own markers in them. Undefined outside a hydration pass.\n * @internal\n */\nexport function liftedRegions(): readonly (readonly Node[])[] | undefined {\n return state?.lifted;\n}\n\n/**\n * Runs `fn` with claiming switched off, so the templates it builds are created fresh instead of\n * claimed from the server markup. Use it for content the server did not render (a portal the server\n * sent nothing for), so its keys are not reported as missing. The previous state is restored when\n * `fn` returns or throws.\n *\n * @param fn The code to run. It runs synchronously, once.\n * @returns What `fn` returns. An error `fn` throws propagates.\n * @example\n * import { template } from \"@shadow-js/web\";\n * import { withoutClaiming } from \"@shadow-js/web/extend\";\n *\n * const makeTip = template(`<div class=\"tip\"></div>`);\n * const tip = withoutClaiming(() => makeTip()); // a fresh clone, even during hydrate()\n * @see claims\n * @since 1.0.0\n */\nexport function withoutClaiming<T>(fn: () => T): T {\n const saved = state;\n state = null;\n try {\n return fn();\n } finally {\n state = saved;\n }\n}\n\n/** Comment that opens the server block of a portal (`<!--portal:KEY-->`). */\nconst PORTAL_OPEN = \"portal:\";\n/** Comment that closes it (`<!--/portal:KEY-->`). */\nconst PORTAL_CLOSE = \"/portal:\";\n\n/**\n * Adopts the server block of a portal while `hydrate()` runs. The server writes each portal's markup\n * at the end of `<body>` between `<!--portal:KEY-->` and `<!--/portal:KEY-->` comments (see\n * `createServerPortals`); this removes the comments, leaves the content in place, and registers its\n * keyed elements so the portal's templates claim them.\n *\n * @param key The portal's key from `nextKey()`. Undefined claims nothing.\n * @returns The nodes of the block, in place in the body; undefined when no hydration pass is running,\n * `key` is undefined, there is no document body, or the server sent no complete block for the key.\n * @example\n * import { claimPortal, nextKey } from \"@shadow-js/web/extend\";\n *\n * function mountOverlay(build: () => Node): Node[] {\n * const adopted = claimPortal(nextKey());\n * if (adopted !== undefined) return adopted;\n * const node = build();\n * document.body.append(node);\n * return [node];\n * }\n * @since 1.0.0\n */\nexport function claimPortal(key: string | undefined): Node[] | undefined {\n const current = state;\n if (current === null || key === undefined || typeof document === \"undefined\") return undefined;\n const body = document.body;\n if (body === null) return undefined;\n const nodes = Array.from(body.childNodes);\n const open = nodes.findIndex((node) => isComment(node, PORTAL_OPEN + key));\n if (open === -1) return undefined;\n const close = nodes.findIndex(\n (node, index) => index > open && isComment(node, PORTAL_CLOSE + key),\n );\n if (close === -1) return undefined;\n // The content stays where the server put it (the region adopts it in place); only the markers go.\n const content: Node[] = [];\n for (const node of nodes.slice(open + 1, close)) {\n if (node.nodeType === 8 && isRegionMarker(node as Comment)) body.removeChild(node);\n else content.push(node);\n }\n for (const node of [nodes[open], nodes[close]]) {\n if (node !== undefined) body.removeChild(node);\n }\n for (const node of content) {\n if (node.nodeType !== 1) continue;\n const element = node as Element;\n const own = element.getAttribute(\"data-hk\");\n if (own !== null) current.registry.set(own, element);\n for (const keyed of Array.from(element.querySelectorAll(\"[data-hk]\"))) {\n const hk = keyed.getAttribute(\"data-hk\");\n if (hk !== null) current.registry.set(hk, keyed);\n }\n }\n return content;\n}\n\n/**\n * Removes the server blocks of portals that were not claimed during the pass: the client did not render\n * those portals, so their markup must not stay in the page. Each block goes with its comments. A block\n * without its closing comment loses only its opening one.\n * @internal\n */\nexport function releaseUnclaimedPortals(body: Node): void {\n const nodes = Array.from(body.childNodes);\n for (let open = 0; open < nodes.length; open += 1) {\n const opening = nodes[open];\n if (opening === undefined || opening.nodeType !== 8) continue;\n const data = (opening as Comment).data;\n if (!data.startsWith(PORTAL_OPEN)) continue;\n const close = nodes.findIndex(\n (node, index) =>\n index > open && isComment(node, PORTAL_CLOSE + data.slice(PORTAL_OPEN.length)),\n );\n const last = close === -1 ? open : close;\n for (const node of nodes.slice(open, last + 1)) {\n if (node.parentNode === body) body.removeChild(node);\n }\n open = last;\n }\n}\n\nfunction isComment(node: Node, data: string): boolean {\n return node.nodeType === 8 && (node as Comment).data === data;\n}\n\nfunction isRegionMarker(comment: Comment): boolean {\n return comment.data === \"[\" || comment.data === \"]\";\n}\n"],"mappings":";;AAcA,IAAI,QAA+B;;AAGnC,SAAgB,cACd,UACA,aACM;CACN,QAAQ;EAAE;EAAU;EAAa,yBAAS,IAAI,QAAQ;EAAG,QAAQ,CAAC;CAAE;AACtE;;AAGA,SAAgB,cAAoB;CAClC,QAAQ;AACV;;;;;;;;;;;;;;;;;AAkBA,SAAgB,aAAsB;CACpC,OAAO,UAAU;AACnB;AAEA,SAAS,SAAS,MAAY,MAAuB;CACnD,IAAI,KAAK,aAAa,GAAG,OAAO;CAChC,MAAM,OAAQ,KAAiB;CAE/B,OAAO,SAAS,QAAS,SAAS,OAAO,KAAK,WAAW,KAAK;AAChE;;;;;;;AAQA,SAAS,QAAQ,MAAe,SAAkC,QAAwB;CACxF,MAAM,QAAmB,CAAC,IAAI;CAC9B,OAAO,MAAM,SAAS,GAAG;EACvB,MAAM,SAAS,MAAM,IAAI;EACzB,IAAI,WAAW,KAAA,GAAW;EAC1B,IAAI,QAA0B,OAAO;EACrC,OAAO,UAAU,MAAM;GACrB,MAAM,YAA8B,MAAM;GAC1C,IAAI,SAAS,O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KAAK,MAAM,CAAkB,CAAC,CACjF;EACA,MAAM,OAAO,UAAU,KAAK,OAAO;EACnC,KAAK,MAAM,QAAQ,MAAM,MAAM,MAAM,OAAO,CAAC,GAC3C,IAAI,KAAK,eAAe,MAAM,KAAK,YAAY,IAAI;EAErD,OAAO;CACT;AACF;AAEA,SAAS,UAAU,MAAY,MAAuB;CACpD,OAAO,KAAK,aAAa,KAAM,KAAiB,SAAS;AAC3D;AAEA,SAAS,eAAe,SAA2B;CACjD,OAAO,QAAQ,SAAS,OAAO,QAAQ,SAAS;AAClD"}
|
|
1
|
+
{"version":3,"file":"claim.js","names":[],"sources":["../../../src/internal/claim.ts"],"sourcesContent":["import { DEVTOOLS_EVENT, devtoolsReport } from \"@shadow-js/core/extend\";\n\n/** What a hydration pass in progress knows. Exists only while `hydrate()` runs its synchronous pass. */\ninterface HydrationState {\n /** Server elements by `data-hk` key; entries are consumed when claimed. */\n readonly registry: Map<string, Element>;\n /** Told about each mismatch the pass repaired (the `onRecoverableError` option). */\n readonly recoverable: ((error: unknown) => void) | undefined;\n /** Region contents taken out of each claimed parent, in document order. */\n readonly pending: WeakMap<Node, Node[][]>;\n /** The content of every region lifted out of a claimed element, in document order (read by `NoHydration`). */\n readonly lifted: Node[][];\n}\n\nlet state: HydrationState | null = null;\n\n/** Starts a claiming pass over the given server elements. @internal */\nexport function beginClaiming(\n registry: Map<string, Element>,\n recoverable?: (error: unknown) => void,\n): void {\n state = { registry, recoverable, pending: new WeakMap(), lifted: [] };\n}\n\n/** Ends the claiming pass. @internal */\nexport function endClaiming(): void {\n state = null;\n}\n\n/**\n * Reports whether a `hydrate()` pass is claiming server DOM right now: a custom renderer reads it to\n * decide between adopting server nodes and building fresh ones. The pass is synchronous, so this is\n * `false` again once `hydrate()` returns, and in every later update.\n *\n * @returns `true` during the synchronous pass of `hydrate()` (outside {@link withoutClaiming}),\n * `false` otherwise.\n * @example\n * import { isClaiming } from \"@shadow-js/web/extend\";\n *\n * function describe(): string {\n * return isClaiming() ? \"adopting server markup\" : \"building fresh DOM\";\n * }\n * @see claims\n * @since 1.0.0\n */\nexport function isClaiming(): boolean {\n return state !== null;\n}\n\nfunction isMarker(node: Node, data: string): boolean {\n if (node.nodeType !== 8) return false;\n const text = (node as Comment).data;\n // `[b:ID` opens a Suspense boundary region (streaming); it hydrates like a plain region.\n return text === data || (data === \"[\" && text.startsWith(\"[b:\"));\n}\n\n/**\n * Turns server markup for one template into the shape a freshly cloned template has: region\n * contents are lifted out (to be re-inserted by `insert`), marker comments are removed and text\n * nodes are merged again. Iterative; static elements below the root are walked, regions are not\n * (their contents belong to other templates, claimed later through the registry).\n */\nfunction prepare(root: Element, pending: WeakMap<Node, Node[][]>, lifted: Node[][]): void {\n const stack: Element[] = [root];\n while (stack.length > 0) {\n const parent = stack.pop() as Element;\n let child: ChildNode | null = parent.firstChild;\n while (child !== null) {\n const following: ChildNode | null = child.nextSibling;\n if (isMarker(child, \"[\")) {\n const content: Node[] = [];\n let depth = 1;\n let cursor: ChildNode | null = child.nextSibling;\n while (cursor !== null) {\n if (isMarker(cursor, \"[\")) depth += 1;\n else if (isMarker(cursor, \"]\")) {\n depth -= 1;\n if (depth === 0) break;\n }\n content.push(cursor);\n cursor = cursor.nextSibling;\n }\n const after: ChildNode | null = cursor === null ? null : cursor.nextSibling;\n lifted.push(content);\n for (const node of content) parent.removeChild(node);\n parent.removeChild(child);\n if (cursor !== null) parent.removeChild(cursor);\n const queue = pending.get(parent);\n if (queue === undefined) pending.set(parent, [content]);\n else queue.push(content);\n child = after;\n continue;\n }\n if (child.nodeType === 1) stack.push(child as Element);\n child = following;\n }\n }\n root.normalize();\n}\n\n/**\n * Adopts the server's element for a hydration key while `hydrate()` runs: the step that lets a custom\n * template reuse server markup instead of creating new nodes. The element loses its `data-hk`\n * attribute, and the content of its regions is lifted out, to be adopted by {@link takeRegion} when\n * the regions bind. Prefer `claims.current.claimElement`, which links this code only into apps that\n * call `hydrate()`.\n *\n * @param key The key from `nextKey()`, drawn where the server drew it. Undefined claims nothing.\n * @returns The server element; `null` when no hydration pass is running, when `key` is undefined, or\n * when the server sent no element for the key (the caller then creates the node itself). A missing\n * key is a recoverable mismatch: development builds warn `HYDRATION_KEY_MISS`, and the pass's\n * `onRecoverableError` receives an `Error`.\n * @example\n * import { claimElement, nextKey } from \"@shadow-js/web/extend\";\n *\n * function createPanel(): Element {\n * // During hydrate(): the server's <section>. Otherwise: a new one.\n * return claimElement(nextKey()) ?? document.createElement(\"section\");\n * }\n * @see claims\n * @since 1.0.0\n */\nexport function claimElement(key: string | undefined): Element | null {\n const current = state;\n if (current === null || key === undefined) return null;\n const element = current.registry.get(key);\n if (element === undefined) {\n // Production keeps only the code (the same split as core's messages): the text stays out of the bundle.\n if (__DEV__) {\n const message = `No server element for key \"${key}\".`;\n console.warn(`[shadow HYDRATION_KEY_MISS] ${message}`);\n devtoolsReport(DEVTOOLS_EVENT.HYDRATION_MISMATCH, message, key, undefined);\n }\n current.recoverable?.(\n new Error(__DEV__ ? `No server element for key \"${key}\".` : \"SHADOW_HYDRATION_KEY_MISS\"),\n );\n return null;\n }\n current.registry.delete(key);\n element.removeAttribute(\"data-hk\");\n prepare(element, current.pending, current.lifted);\n return element;\n}\n\n/** Characters that stay readable as escapes in a diagnostic snippet: markup, quotes and ampersands. */\nconst SNIPPET_ESCAPES: ReadonlyMap<string, string> = new Map([\n [\"<\", \"\\\\u003c\"],\n [\">\", \"\\\\u003e\"],\n [\"&\", \"\\\\u0026\"],\n ['\"', \"\\\\u0022\"],\n [\"'\", \"\\\\u0027\"],\n]);\n\n/**\n * Escapes text for a diagnostic snippet and cuts it to `limit` output characters, with `...` when cut.\n * Escapes are never split, so the output is at most `limit + 3` characters.\n * @internal\n */\nfunction snippet(text: string, limit: number): string {\n let out = \"\";\n for (const char of text) {\n const code = char.codePointAt(0) ?? 0;\n const controlled = code < 0x20 || (code >= 0x7f && code <= 0x9f);\n const escaped =\n SNIPPET_ESCAPES.get(char) ?? (controlled ? `\\\\u${code.toString(16).padStart(4, \"0\")}` : char);\n if (out.length + escaped.length > limit) return `${out}...`;\n out += escaped;\n }\n return out;\n}\n\n/** The opening tag of a server element as the server wrote it (attribute values as they are). */\nfunction openingMarkup(element: Element): string {\n let markup = `<${element.localName}`;\n for (const attr of Array.from(element.attributes)) markup += ` ${attr.name}=\"${attr.value}\"`;\n return `${markup}>`;\n}\n\n/**\n * Development check of a claimed element against the tag its template or `element()` call expects.\n * A different tag warns `HYDRATION_MISMATCH` on the console and in devtools, with an escaped snippet of\n * the server element (its opening tag and the start of its text, bounded). Recovery is unchanged: the\n * element is still adopted, nothing is thrown or replaced, and the caller gets the same value.\n *\n * Call it under `if (__DEV__)`. Text is not compared here: the expected text is inserted later, by\n * `insert`, and {@link checkClaimedText} compares it with the server text at that point.\n *\n * @param element The server element `claimElement` returned.\n * @param expectedTag The tag the client expects (any case).\n * @internal\n */\nexport function checkClaimedTag(element: Element, expectedTag: string): void {\n if (!__DEV__) return;\n const expected = expectedTag.toLowerCase();\n const actual = element.localName.toLowerCase();\n if (actual === expected) return;\n const text = element.textContent ?? \"\";\n let detail = `expected <${expected}> but the server sent <${snippet(actual, 80)}>; server markup: \"${snippet(openingMarkup(element), 80)}\"`;\n if (text !== \"\") detail += `; text: \"${snippet(text, 40)}\"`;\n console.warn(`[shadow HYDRATION_MISMATCH] ${detail}`);\n devtoolsReport(DEVTOOLS_EVENT.HYDRATION_MISMATCH, detail, undefined, undefined);\n}\n\n/**\n * Development check of the first commit of a region that claimed server text. The server text is the\n * DOM text of the claimed nodes (already decoded, so an escaped `<` compares as `<`); the expected\n * text is the strings of the first commit, joined (a number is already its string, `null` and booleans\n * render nothing, so they expect `\"\"`). Equal text is silent. Different text warns\n * `HYDRATION_TEXT_MISMATCH` on the console and in devtools, with both texts escaped and bounded to 40\n * characters. Recovery is unchanged: the region shows the value the client computed.\n *\n * Not compared, so silent: a region that claimed no nodes (an empty server region has no server text),\n * a region whose server nodes are not all text (an element, or the markers of a nested region), and a\n * commit that holds a node (an element is shown in place of the server's content, as before).\n *\n * Call it under `if (__DEV__)`, once per claimed region, at its first commit.\n *\n * @param claimed The server nodes the region adopted, in document order.\n * @param parts What the first commit shows: strings, or nodes.\n * @internal\n * @since 1.0.0\n */\nexport function checkClaimedText(\n claimed: readonly Node[],\n parts: readonly (Node | string)[],\n): void {\n if (!__DEV__) return;\n if (claimed.length === 0) return;\n let server = \"\";\n for (const node of claimed) {\n if (node.nodeType !== 3) return;\n server += node.textContent ?? \"\";\n }\n let expected = \"\";\n for (const part of parts) {\n if (typeof part !== \"string\") return;\n expected += part;\n }\n if (expected === server) return;\n const detail = `expected text \"${snippet(expected, 40)}\" but the server sent text \"${snippet(server, 40)}\"`;\n console.warn(`[shadow HYDRATION_TEXT_MISMATCH] ${detail}`);\n devtoolsReport(DEVTOOLS_EVENT.HYDRATION_MISMATCH, detail, undefined, undefined);\n}\n\n/** HTML elements whose content is text and nothing else: no comment can mark a region inside them. */\nconst TEXT_ONLY = new Set([\"script\", \"style\", \"title\", \"textarea\"]);\n\n/**\n * True for a `script`, `style`, `title` or `textarea`, in whichever namespace the parser put it: `Dynamic` knows no\n * parent, so the server writes the children of such a tag without region markers even where the page parses it as\n * an SVG `title` or `style`. Its whole content is then the one region.\n */\nfunction isTextOnly(node: Node): boolean {\n return node.nodeType === 1 && TEXT_ONLY.has((node as Element).localName);\n}\n\n/**\n * Adopts the server content of the next region of a claimed parent while `hydrate()` runs: the nodes\n * that sat between the region's markers are put back before `anchorNode` and returned, so a custom\n * region can bind to them instead of inserting new nodes. Regions are taken in document order.\n *\n * @param parent An element returned by {@link claimElement} (or one of its descendants).\n * @param anchorNode The node the content goes before; `null` appends it at the end of `parent`.\n * @returns The adopted nodes; undefined when no hydration pass is running or `parent` has no region\n * left to adopt (the caller then inserts fresh nodes). A `script`, `style`, `title` or `textarea` has no\n * markers (the server writes its text as the parser reads it): its current children are the region.\n * @example\n * import { takeRegion } from \"@shadow-js/web/extend\";\n *\n * function fillRegion(parent: Element): Node[] {\n * const adopted = takeRegion(parent, null);\n * if (adopted !== undefined) return adopted;\n * const text = document.createTextNode(\"fresh\");\n * parent.append(text);\n * return [text];\n * }\n * @see claimElement\n * @since 1.0.0\n */\nexport function takeRegion(parent: Node, anchorNode: Node | null): Node[] | undefined {\n const current = state;\n if (current === null) return undefined;\n const content = current.pending.get(parent)?.shift();\n if (content === undefined) return isTextOnly(parent) ? Array.from(parent.childNodes) : undefined;\n for (const node of content) parent.insertBefore(node, anchorNode);\n return content;\n}\n\n/**\n * The content of every region the pass lifted out of the server elements it claimed, in document order. `NoHydration` finds\n * its own markers in them. Undefined outside a hydration pass.\n * @internal\n */\nexport function liftedRegions(): readonly (readonly Node[])[] | undefined {\n return state?.lifted;\n}\n\n/**\n * Runs `fn` with claiming switched off, so the templates it builds are created fresh instead of\n * claimed from the server markup. Use it for content the server did not render (a portal the server\n * sent nothing for), so its keys are not reported as missing. The previous state is restored when\n * `fn` returns or throws.\n *\n * @param fn The code to run. It runs synchronously, once.\n * @returns What `fn` returns. An error `fn` throws propagates.\n * @example\n * import { template } from \"@shadow-js/web\";\n * import { withoutClaiming } from \"@shadow-js/web/extend\";\n *\n * const makeTip = template(`<div class=\"tip\"></div>`);\n * const tip = withoutClaiming(() => makeTip()); // a fresh clone, even during hydrate()\n * @see claims\n * @since 1.0.0\n */\nexport function withoutClaiming<T>(fn: () => T): T {\n const saved = state;\n state = null;\n try {\n return fn();\n } finally {\n state = saved;\n }\n}\n\n/** Comment that opens the server block of a portal (`<!--portal:KEY-->`). */\nconst PORTAL_OPEN = \"portal:\";\n/** Comment that closes it (`<!--/portal:KEY-->`). */\nconst PORTAL_CLOSE = \"/portal:\";\n\n/**\n * Adopts the server block of a portal while `hydrate()` runs. The server writes each portal's markup\n * at the end of `<body>` between `<!--portal:KEY-->` and `<!--/portal:KEY-->` comments (see\n * `createServerPortals`); this removes the comments, leaves the content in place, and registers its\n * keyed elements so the portal's templates claim them.\n *\n * @param key The portal's key from `nextKey()`. Undefined claims nothing.\n * @returns The nodes of the block, in place in the body; undefined when no hydration pass is running,\n * `key` is undefined, there is no document body, or the server sent no complete block for the key.\n * @example\n * import { claimPortal, nextKey } from \"@shadow-js/web/extend\";\n *\n * function mountOverlay(build: () => Node): Node[] {\n * const adopted = claimPortal(nextKey());\n * if (adopted !== undefined) return adopted;\n * const node = build();\n * document.body.append(node);\n * return [node];\n * }\n * @since 1.0.0\n */\nexport function claimPortal(key: string | undefined): Node[] | undefined {\n const current = state;\n if (current === null || key === undefined || typeof document === \"undefined\") return undefined;\n const body = document.body;\n if (body === null) return undefined;\n const nodes = Array.from(body.childNodes);\n const open = nodes.findIndex((node) => isComment(node, PORTAL_OPEN + key));\n if (open === -1) return undefined;\n const close = nodes.findIndex(\n (node, index) => index > open && isComment(node, PORTAL_CLOSE + key),\n );\n if (close === -1) return undefined;\n // The content stays where the server put it (the region adopts it in place); only the markers go.\n const content: Node[] = [];\n for (const node of nodes.slice(open + 1, close)) {\n if (node.nodeType === 8 && isRegionMarker(node as Comment)) body.removeChild(node);\n else content.push(node);\n }\n for (const node of [nodes[open], nodes[close]]) {\n if (node !== undefined) body.removeChild(node);\n }\n for (const node of content) {\n if (node.nodeType !== 1) continue;\n const element = node as Element;\n const own = element.getAttribute(\"data-hk\");\n if (own !== null) current.registry.set(own, element);\n for (const keyed of Array.from(element.querySelectorAll(\"[data-hk]\"))) {\n const hk = keyed.getAttribute(\"data-hk\");\n if (hk !== null) current.registry.set(hk, keyed);\n }\n }\n return content;\n}\n\n/**\n * Removes the server blocks of portals that were not claimed during the pass: the client did not render\n * those portals, so their markup must not stay in the page. Each block goes with its comments. A block\n * without its closing comment loses only its opening one.\n * @internal\n */\nexport function releaseUnclaimedPortals(body: Node): void {\n const nodes = Array.from(body.childNodes);\n for (let open = 0; open < nodes.length; open += 1) {\n const opening = nodes[open];\n if (opening === undefined || opening.nodeType !== 8) continue;\n const data = (opening as Comment).data;\n if (!data.startsWith(PORTAL_OPEN)) continue;\n const close = nodes.findIndex(\n (node, index) =>\n index > open && isComment(node, PORTAL_CLOSE + data.slice(PORTAL_OPEN.length)),\n );\n const last = close === -1 ? open : close;\n for (const node of nodes.slice(open, last + 1)) {\n if (node.parentNode === body) body.removeChild(node);\n }\n open = last;\n }\n}\n\nfunction isComment(node: Node, data: string): boolean {\n return node.nodeType === 8 && (node as Comment).data === data;\n}\n\nfunction isRegionMarker(comment: Comment): boolean {\n return comment.data === \"[\" || comment.data === \"]\";\n}\n"],"mappings":";;AAcA,IAAI,QAA+B;;AAGnC,SAAgB,cACd,UACA,aACM;CACN,QAAQ;EAAE;EAAU;EAAa,yBAAS,IAAI,QAAQ;EAAG,QAAQ,CAAC;CAAE;AACtE;;AAGA,SAAgB,cAAoB;CAClC,QAAQ;AACV;;;;;;;;;;;;;;;;;AAkBA,SAAgB,aAAsB;CACpC,OAAO,UAAU;AACnB;AAEA,SAAS,SAAS,MAAY,MAAuB;CACnD,IAAI,KAAK,aAAa,GAAG,OAAO;CAChC,MAAM,OAAQ,KAAiB;CAE/B,OAAO,SAAS,QAAS,SAAS,OAAO,KAAK,WAAW,KAAK;AAChE;;;;;;;AAQA,SAAS,QAAQ,MAAe,SAAkC,QAAwB;CACxF,MAAM,QAAmB,CAAC,IAAI;CAC9B,OAAO,MAAM,SAAS,GAAG;EACvB,MAAM,SAAS,MAAM,IAAI;EACzB,IAAI,QAA0B,OAAO;EACrC,OAAO,UAAU,MAAM;GACrB,MAAM,YAA8B,MAAM;GAC1C,IAAI,SAAS,OAAO,GAAG,GAAG;IACxB,MAAM,UAAkB,CAAC;IACzB,IAAI,QAAQ;IACZ,IAAI,SAA2B,MAAM;IACrC,OAAO,WAAW,MAAM;KACtB,IAAI,SAAS,QAAQ,GAAG,GAAG,SAAS;UAC/B,IAAI,SAAS,QAAQ,GAAG,GAAG;MAC9B,SAAS;MACT,IAAI,UAAU,GAAG;KACnB;KACA,QAAQ,KAAK,MAAM;KACnB,SAAS,OAAO;IAClB;IACA,MAAM,QAA0B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Q,MAAM,MAAM,MAAM,OAAO,CAAC,GAC3C,IAAI,KAAK,eAAe,MAAM,KAAK,YAAY,IAAI;EAErD,OAAO;CACT;AACF;AAEA,SAAS,UAAU,MAAY,MAAuB;CACpD,OAAO,KAAK,aAAa,KAAM,KAAiB,SAAS;AAC3D;AAEA,SAAS,eAAe,SAA2B;CACjD,OAAO,QAAQ,SAAS,OAAO,QAAQ,SAAS;AAClD"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* stylesheet writer are the only importers, so it is linked only where a style is written.
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
|
-
const UNITLESS =
|
|
10
|
+
const UNITLESS = /^(?:animation-iteration-count|aspect-ratio|border-image-(?:outset|slice|width)|box-(?:flex(?:-group)?|ordinal-group)|column-count|columns|flex(?:-(?:grow|positive|shrink|negative|order))?|grid-(?:area|(?:row|column)(?:-(?:end|span|start))?)|font-weight|line-(?:clamp|height)|opacity|order|orphans|scale|tab-size|widows|z-index|zoom|(?:fill|flood|stop|stroke)-opacity|stroke-(?:dasharray|dashoffset|miterlimit|width))$/;
|
|
11
11
|
/**
|
|
12
12
|
* The CSS text of one style value. A finite or non-finite number gets `px` unless it is zero, a
|
|
13
13
|
* custom property (`--x`) or unitless; every other value is `String(value)`.
|
|
@@ -18,7 +18,7 @@ const UNITLESS = new Set("animation-iteration-count aspect-ratio border-image-ou
|
|
|
18
18
|
function cssValueText(property, value) {
|
|
19
19
|
if (typeof value !== "number" || value === 0 || property.startsWith("--")) return String(value);
|
|
20
20
|
const bare = property.replace(/^-(?:webkit|moz|ms|o)-/, "");
|
|
21
|
-
return UNITLESS.
|
|
21
|
+
return UNITLESS.test(bare) ? String(value) : `${value}px`;
|
|
22
22
|
}
|
|
23
23
|
export { cssValueText };
|
|
24
24
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css-units.js","names":[],"sources":["../../../src/internal/css-units.ts"],"sourcesContent":["/**\n * React's unitless style properties. A number given to any other property is in pixels (`0` stays\n * `0`); these properties take the bare number. Vendor prefixes do not change the answer.\n *\n * The compiler never needs this table for static values, and `class-style.ts` and the server\n * stylesheet writer are the only importers, so it is linked only where a style is written.\n * @internal\n */\nconst UNITLESS
|
|
1
|
+
{"version":3,"file":"css-units.js","names":[],"sources":["../../../src/internal/css-units.ts"],"sourcesContent":["/**\n * React's unitless style properties. A number given to any other property is in pixels (`0` stays\n * `0`); these properties take the bare number. Vendor prefixes do not change the answer.\n *\n * The compiler never needs this table for static values, and `class-style.ts` and the server\n * stylesheet writer are the only importers, so it is linked only where a style is written.\n * @internal\n */\nconst UNITLESS =\n /^(?:animation-iteration-count|aspect-ratio|border-image-(?:outset|slice|width)|box-(?:flex(?:-group)?|ordinal-group)|column-count|columns|flex(?:-(?:grow|positive|shrink|negative|order))?|grid-(?:area|(?:row|column)(?:-(?:end|span|start))?)|font-weight|line-(?:clamp|height)|opacity|order|orphans|scale|tab-size|widows|z-index|zoom|(?:fill|flood|stop|stroke)-opacity|stroke-(?:dasharray|dashoffset|miterlimit|width))$/;\n\n/**\n * The CSS text of one style value. A finite or non-finite number gets `px` unless it is zero, a\n * custom property (`--x`) or unitless; every other value is `String(value)`.\n * @param property The CSS property in kebab-case (`toCssProperty` output).\n * @param value The style value.\n * @internal\n */\nexport function cssValueText(property: string, value: unknown): string {\n if (typeof value !== \"number\" || value === 0 || property.startsWith(\"--\")) return String(value);\n const bare = property.replace(/^-(?:webkit|moz|ms|o)-/, \"\");\n return UNITLESS.test(bare) ? String(value) : `${value}px`;\n}\n"],"mappings":";;;;;;;;;AAQA,MAAM,WACJ;;;;;;;;AASF,SAAgB,aAAa,UAAkB,OAAwB;CACrE,IAAI,OAAO,UAAU,YAAY,UAAU,KAAK,SAAS,WAAW,IAAI,GAAG,OAAO,OAAO,KAAK;CAC9F,MAAM,OAAO,SAAS,QAAQ,0BAA0B,EAAE;CAC1D,OAAO,SAAS,KAAK,IAAI,IAAI,OAAO,KAAK,IAAI,GAAG,MAAM;AACxD"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/internal/diagnostics.ts
|
|
2
|
+
/** The codes reported, and the `code:key` pairs of the warnings that pass a key. */
|
|
2
3
|
const seen = /* @__PURE__ */ new Set();
|
|
3
4
|
/**
|
|
4
5
|
* Prints a development warning as `[shadow CODE] detail`, at most once per code for the life of the
|
|
@@ -7,6 +8,8 @@ const seen = /* @__PURE__ */ new Set();
|
|
|
7
8
|
*
|
|
8
9
|
* @param code The diagnostic code. A code that was already reported is ignored, whatever the detail.
|
|
9
10
|
* @param detail The text after the code.
|
|
11
|
+
* @param key Optional. With a key the warning is once per `code` and `key` instead of once per code, for a
|
|
12
|
+
* warning about a name where each name deserves a report. Pass a bounded set of keys: each is remembered.
|
|
10
13
|
* @example
|
|
11
14
|
* import { isUnsafeUrlAttribute, warnOnce } from "@shadow-js/web/extend";
|
|
12
15
|
*
|
|
@@ -19,12 +22,19 @@ const seen = /* @__PURE__ */ new Set();
|
|
|
19
22
|
* }
|
|
20
23
|
* @since 1.0.0
|
|
21
24
|
*/
|
|
22
|
-
function warnOnce(code, detail) {
|
|
23
|
-
|
|
24
|
-
seen.
|
|
25
|
+
function warnOnce(code, detail, key) {
|
|
26
|
+
const id = key === void 0 ? code : `${code}:${key}`;
|
|
27
|
+
if (seen.has(id)) return;
|
|
28
|
+
seen.add(id);
|
|
25
29
|
console.warn(`[shadow ${code}] ${detail}`);
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
32
|
+
* The text of the `SRCDOC_DYNAMIC` warning, shared by the client and the server writer. `srcdoc` is a whole HTML
|
|
33
|
+
* document the frame runs, so it has the trust of `innerHTML`, not of a URL: no scheme check applies to it.
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
const SRCDOC_DYNAMIC_DETAIL = "A computed value was written to \"srcdoc\". It is an HTML document the frame runs, with the trust of innerHTML: sanitize it, and add the sandbox attribute to the frame.";
|
|
37
|
+
/**
|
|
28
38
|
* Error thrown for attribute names that cannot appear in markup. Dev builds carry the full text;
|
|
29
39
|
* production keeps the code and the name (the same split as core's messages).
|
|
30
40
|
* @internal
|
|
@@ -32,6 +42,6 @@ function warnOnce(code, detail) {
|
|
|
32
42
|
function invalidAttributeName(name) {
|
|
33
43
|
return /* @__PURE__ */ new TypeError(`[shadow INVALID_ATTRIBUTE_NAME] "${name}" is not a valid attribute name.`);
|
|
34
44
|
}
|
|
35
|
-
export { invalidAttributeName, warnOnce };
|
|
45
|
+
export { SRCDOC_DYNAMIC_DETAIL, invalidAttributeName, warnOnce };
|
|
36
46
|
|
|
37
47
|
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.js","names":[],"sources":["../../../src/internal/diagnostics.ts"],"sourcesContent":["/**\n * The diagnostic codes of the DOM runtime: `UNSAFE_URL_BLOCKED` (a URL attribute that would run\n * script was not written), `INVALID_ATTRIBUTE_NAME` (a name that cannot appear in markup) and\n * `DUPLICATE_CLASS_ATTRIBUTE` (one element carries `class` and `className`, so the parser drops one).\n * @since 1.0.0\n */\nexport type WebWarningCode =\n | \"UNSAFE_URL_BLOCKED\"\n | \"INVALID_ATTRIBUTE_NAME\"\n | \"DUPLICATE_CLASS_ATTRIBUTE\";\n\nconst seen = new Set<
|
|
1
|
+
{"version":3,"file":"diagnostics.js","names":[],"sources":["../../../src/internal/diagnostics.ts"],"sourcesContent":["/**\n * The diagnostic codes of the DOM runtime: `UNSAFE_URL_BLOCKED` (a URL attribute that would run\n * script was not written), `INVALID_ATTRIBUTE_NAME` (a name that cannot appear in markup) and\n * `DUPLICATE_CLASS_ATTRIBUTE` (one element carries `class` and `className`, so the parser drops one)\n * `SRCDOC_DYNAMIC` (a value computed at run time was written to `srcdoc`, an HTML sink) and\n * `DYNAMIC_SVG_CASE` (`Dynamic` was given an SVG element name in a case SVG does not spell it in).\n * @since 1.0.0\n */\nexport type WebWarningCode =\n | \"UNSAFE_URL_BLOCKED\"\n | \"INVALID_ATTRIBUTE_NAME\"\n | \"DUPLICATE_CLASS_ATTRIBUTE\"\n | \"SRCDOC_DYNAMIC\"\n | \"DYNAMIC_SVG_CASE\";\n\n/** The codes reported, and the `code:key` pairs of the warnings that pass a key. */\nconst seen = new Set<string>();\n\n/**\n * Prints a development warning as `[shadow CODE] detail`, at most once per code for the life of the\n * page or process (the same pattern as core's `warn`): for a custom renderer that refuses a value the\n * way the built-in ones do. Production builds print nothing.\n *\n * @param code The diagnostic code. A code that was already reported is ignored, whatever the detail.\n * @param detail The text after the code.\n * @param key Optional. With a key the warning is once per `code` and `key` instead of once per code, for a\n * warning about a name where each name deserves a report. Pass a bounded set of keys: each is remembered.\n * @example\n * import { isUnsafeUrlAttribute, warnOnce } from \"@shadow-js/web/extend\";\n *\n * function setLink(el: Element, url: string): void {\n * if (isUnsafeUrlAttribute(\"href\", url)) {\n * warnOnce(\"UNSAFE_URL_BLOCKED\", `Blocked a script URL: ${url}`);\n * return;\n * }\n * el.setAttribute(\"href\", url);\n * }\n * @since 1.0.0\n */\nexport function warnOnce(code: WebWarningCode, detail: string, key?: string): void {\n if (!__DEV__) return;\n const id = key === undefined ? code : `${code}:${key}`;\n if (seen.has(id)) return;\n seen.add(id);\n console.warn(`[shadow ${code}] ${detail}`);\n}\n\n/**\n * The text of the `SRCDOC_DYNAMIC` warning, shared by the client and the server writer. `srcdoc` is a whole HTML\n * document the frame runs, so it has the trust of `innerHTML`, not of a URL: no scheme check applies to it.\n * @internal\n */\nexport const SRCDOC_DYNAMIC_DETAIL =\n 'A computed value was written to \"srcdoc\". It is an HTML document the frame runs, with the trust of innerHTML: sanitize it, and add the sandbox attribute to the frame.';\n\n/** Forgets which codes were already reported. Used by tests; not part of the public surface. @internal */\nexport function resetWebWarningDedupe(): void {\n seen.clear();\n}\n\n/**\n * Error thrown for attribute names that cannot appear in markup. Dev builds carry the full text;\n * production keeps the code and the name (the same split as core's messages).\n * @internal\n */\nexport function invalidAttributeName(name: string): TypeError {\n if (!__DEV__) return new TypeError(`SHADOW_INVALID_ATTRIBUTE_NAME: \"${name}\"`);\n return new TypeError(`[shadow INVALID_ATTRIBUTE_NAME] \"${name}\" is not a valid attribute name.`);\n}\n"],"mappings":";;AAgBA,MAAM,uBAAO,IAAI,IAAY;;;;;;;;;;;;;;;;;;;;;;AAuB7B,SAAgB,SAAS,MAAsB,QAAgB,KAAoB;CAEjF,MAAM,KAAK,QAAQ,KAAA,IAAY,OAAO,GAAG,KAAK,GAAG;CACjD,IAAI,KAAK,IAAI,EAAE,GAAG;CAClB,KAAK,IAAI,EAAE;CACX,QAAQ,KAAK,WAAW,KAAK,IAAI,QAAQ;AAC3C;;;;;;AAOA,MAAa,wBACX;;;;;;AAYF,SAAgB,qBAAqB,MAAyB;CAE5D,uBAAO,IAAI,UAAU,oCAAoC,KAAK,iCAAiC;AACjG"}
|
|
@@ -19,7 +19,7 @@ const EVENT_NAME = /^[a-z]+$/;
|
|
|
19
19
|
* @internal
|
|
20
20
|
*/
|
|
21
21
|
function captureScriptBody(names) {
|
|
22
|
-
return "(function(){var d=document,n=" + JSON.stringify(names.filter((name) => EVENT_NAME.test(name))) + `,q=[];function c(e){q.push(e)}for(var i=0;i<n.length;i++)d.addEventListener(n[i],c,true);window.${EARLY_CAPTURE_KEY}={queue:q,names:n,listener:c};})();`;
|
|
22
|
+
return "(function(){var d=document,n=" + JSON.stringify(names.filter((name) => EVENT_NAME.test(name))) + `,q=[];function c(e){if(q.length<100)q.push(e)}for(var i=0;i<n.length;i++)d.addEventListener(n[i],c,true);window.${EARLY_CAPTURE_KEY}={queue:q,names:n,listener:c};})();`;
|
|
23
23
|
}
|
|
24
24
|
/** The capture the script left on the window, validated, or undefined. */
|
|
25
25
|
function readCapture() {
|
|
@@ -67,9 +67,27 @@ function replayEarlyEvents() {
|
|
|
67
67
|
for (const name of capture.names) document.removeEventListener(name, capture.listener, true);
|
|
68
68
|
for (const event of capture.queue) {
|
|
69
69
|
const target = event.target;
|
|
70
|
-
if (target instanceof Node) target.dispatchEvent(reissue(event));
|
|
70
|
+
if (target instanceof Node) target.dispatchEvent(withoutDefaultAction(reissue(event)));
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* The replayed event runs the page's handlers, not the browser's default action: the real event
|
|
75
|
+
* already ran it when the user made it. A dispatched `click` on a link follows the link, so without
|
|
76
|
+
* this a link was followed twice. The native flag is set right away, which cancels the default action,
|
|
77
|
+
* and the handlers still see `defaultPrevented` as false (a router skips a click that is already
|
|
78
|
+
* prevented) until one of them prevents it itself.
|
|
79
|
+
*/
|
|
80
|
+
function withoutDefaultAction(event) {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
let prevented = false;
|
|
83
|
+
Object.defineProperties(event, {
|
|
84
|
+
defaultPrevented: { get: () => prevented },
|
|
85
|
+
preventDefault: { value: () => {
|
|
86
|
+
prevented = true;
|
|
87
|
+
} }
|
|
88
|
+
});
|
|
89
|
+
return event;
|
|
90
|
+
}
|
|
73
91
|
export { DEFAULT_EARLY_EVENTS, EARLY_CAPTURE_KEY, captureScriptBody, replayEarlyEvents };
|
|
74
92
|
|
|
75
93
|
//# sourceMappingURL=early-events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"early-events.js","names":[],"sources":["../../../src/internal/early-events.ts"],"sourcesContent":["/**\n * Early event capture (ADR-016): a tiny inline script, placed before the bundle, records the events a\n * user makes before the application has hydrated. `hydrate()` then replays them once its handlers are\n * attached, so a click made while the page was still loading is not lost. The script is generated by\n * `generateHydrationScript` on the server; the replay is the client half, and it does nothing when the\n * page has no captured events.\n */\n\n/** The event types recorded when a page does not name its own. @internal */\nexport const DEFAULT_EARLY_EVENTS: readonly string[] = [\"click\", \"input\"];\n\n/** The window property the capture script writes. Its shape is checked before use. @internal */\nexport const EARLY_CAPTURE_KEY = \"__SHADOWJS_EARLY__\";\n\n/** Event names are plain lower-case words: anything else would end up inside the script text. */\nconst EVENT_NAME = /^[a-z]+$/;\n\n/**\n * The inline script body. A capture listener on the document (capture phase, so it sees events even\n * when a page stops their propagation) queues each event; the queue and the listener are kept on\n * `window` for the replay.\n * @internal\n */\nexport function captureScriptBody(names: readonly string[]): string {\n const list = JSON.stringify(names.filter((name) => EVENT_NAME.test(name)));\n return (\n \"(function(){var d=document,n=\" +\n list +\n
|
|
1
|
+
{"version":3,"file":"early-events.js","names":[],"sources":["../../../src/internal/early-events.ts"],"sourcesContent":["/**\n * Early event capture (ADR-016): a tiny inline script, placed before the bundle, records the events a\n * user makes before the application has hydrated. `hydrate()` then replays them once its handlers are\n * attached, so a click made while the page was still loading is not lost. The script is generated by\n * `generateHydrationScript` on the server; the replay is the client half, and it does nothing when the\n * page has no captured events.\n */\n\n/** The event types recorded when a page does not name its own. @internal */\nexport const DEFAULT_EARLY_EVENTS: readonly string[] = [\"click\", \"input\"];\n\n/** The window property the capture script writes. Its shape is checked before use. @internal */\nexport const EARLY_CAPTURE_KEY = \"__SHADOWJS_EARLY__\";\n\n/**\n * The most events the capture script keeps. A page whose bundle never loads would otherwise hold every\n * click and keystroke of the visit; the first ones are the ones worth replaying. @internal\n */\nexport const MAX_EARLY_EVENTS = 100;\n\n/** Event names are plain lower-case words: anything else would end up inside the script text. */\nconst EVENT_NAME = /^[a-z]+$/;\n\n/**\n * The inline script body. A capture listener on the document (capture phase, so it sees events even\n * when a page stops their propagation) queues each event; the queue and the listener are kept on\n * `window` for the replay.\n * @internal\n */\nexport function captureScriptBody(names: readonly string[]): string {\n const list = JSON.stringify(names.filter((name) => EVENT_NAME.test(name)));\n return (\n \"(function(){var d=document,n=\" +\n list +\n `,q=[];function c(e){if(q.length<${MAX_EARLY_EVENTS})q.push(e)}` +\n \"for(var i=0;i<n.length;i++)d.addEventListener(n[i],c,true);\" +\n `window.${EARLY_CAPTURE_KEY}={queue:q,names:n,listener:c};})();`\n );\n}\n\ninterface Capture {\n readonly queue: Event[];\n readonly names: string[];\n readonly listener: (event: Event) => void;\n}\n\n/** The capture the script left on the window, validated, or undefined. */\nfunction readCapture(): Capture | undefined {\n const value: unknown = Reflect.get(globalThis, EARLY_CAPTURE_KEY);\n if (typeof value !== \"object\" || value === null) return undefined;\n const queue: unknown = Reflect.get(value, \"queue\");\n const names: unknown = Reflect.get(value, \"names\");\n const listener: unknown = Reflect.get(value, \"listener\");\n if (!Array.isArray(queue) || !Array.isArray(names) || typeof listener !== \"function\") {\n return undefined;\n }\n const events = queue.filter((item): item is Event => item instanceof Event);\n const kinds = names.filter((name): name is string => typeof name === \"string\");\n return { queue: events, names: kinds, listener: listener as (event: Event) => void };\n}\n\n/** A new event of the same type that bubbles like the original and carries its pointer position. */\nfunction reissue(event: Event): Event {\n const init: EventInit = { bubbles: true, cancelable: event.cancelable, composed: true };\n if (event instanceof MouseEvent) {\n return new MouseEvent(event.type, {\n ...init,\n clientX: event.clientX,\n clientY: event.clientY,\n button: event.button,\n buttons: event.buttons,\n altKey: event.altKey,\n ctrlKey: event.ctrlKey,\n metaKey: event.metaKey,\n shiftKey: event.shiftKey,\n });\n }\n return new Event(event.type, init);\n}\n\n/**\n * Stops the capture and replays what it recorded, in order, on the elements they were made on. Called\n * by `hydrate()` after the handlers are attached. Does nothing when no capture ran.\n * @internal\n */\nexport function replayEarlyEvents(): void {\n const capture = readCapture();\n if (capture === undefined) return;\n Reflect.deleteProperty(globalThis, EARLY_CAPTURE_KEY);\n for (const name of capture.names) document.removeEventListener(name, capture.listener, true);\n for (const event of capture.queue) {\n const target = event.target;\n if (target instanceof Node) target.dispatchEvent(withoutDefaultAction(reissue(event)));\n }\n}\n\n/**\n * The replayed event runs the page's handlers, not the browser's default action: the real event\n * already ran it when the user made it. A dispatched `click` on a link follows the link, so without\n * this a link was followed twice. The native flag is set right away, which cancels the default action,\n * and the handlers still see `defaultPrevented` as false (a router skips a click that is already\n * prevented) until one of them prevents it itself.\n */\nfunction withoutDefaultAction(event: Event): Event {\n event.preventDefault();\n let prevented = false;\n Object.defineProperties(event, {\n defaultPrevented: { get: () => prev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,eAAe,YAAY,iBAAiB;CACpD,KAAK,MAAM,QAAQ,QAAQ,OAAO,SAAS,oBAAoB,MAAM,QAAQ,UAAU,IAAI;CAC3F,KAAK,MAAM,SAAS,QAAQ,OAAO;EACjC,MAAM,SAAS,MAAM;EACrB,IAAI,kBAAkB,MAAM,OAAO,cAAc,qBAAqB,QAAQ,KAAK,CAAC,CAAC;CACvF;AACF;;;;;;;;AASA,SAAS,qBAAqB,OAAqB;CACjD,MAAM,eAAe;CACrB,IAAI,YAAY;CAChB,OAAO,iBAAiB,OAAO;EAC7B,kBAAkB,EAAE,WAAW,UAAU;EACzC,gBAAgB,EACd,aAAa;GACX,YAAY;EACd,EACF;CACF,CAAC;CACD,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portal-context.js","names":[],"sources":["../../../src/internal/portal-context.ts"],"sourcesContent":["import { type Context, createContext } from \"@shadow-js/core\";\n\n/**\n * Receives the markup of the portals a server render produces: what {@link PortalContext} provides\n * when the render was given a `portals` collector.\n * @since 1.0.0\n */\nexport interface PortalSink {\n /**\n * Records the markup of the portal with hydration key `key`. A key recorded again replaces the\n * earlier markup. Throws an `SsrError` whose `code` is `SSR_PORTAL_LIMIT` past 256 portals in one\n * render.\n */\n add(key: string, html: string): void;\n}\n\n/**\n * The context through which a server render hands portals their collector: the renderers provide it\n * when they are given a `portals` option (see `createServerPortals`). A custom portal reads it on the\n * server and records its markup under its hydration key, so the client's `claimPortal` adopts it.\n * Its value is `null` for every other render, and in the browser, where a portal writes nothing on\n * the server.\n *\n * @example\n * import { useContext } from \"@shadow-js/core\";\n * import { nextKey, PortalContext } from \"@shadow-js/web/extend\";\n * import { escape } from \"@shadow-js/web/server\";\n *\n * function ServerToast(props: { text: string }): null {\n * const key = nextKey();\n * const sink = useContext(PortalContext);\n * if (sink !== null && key !== undefined) sink.add(key, `<div role=\"status\">${escape(props.text)}</div>`);\n * return null;\n * }\n * @see claimPortal\n * @since 1.0.0\n */\nexport const PortalContext: Context<PortalSink | null> =\n /* @__PURE__ */ createContext<PortalSink | null>(null, {\n name: \"Portal\",\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"portal-context.js","names":[],"sources":["../../../src/internal/portal-context.ts"],"sourcesContent":["import { type Context, createContext } from \"@shadow-js/core\";\n\n/**\n * Receives the markup of the portals a server render produces: what {@link PortalContext} provides\n * when the render was given a `portals` collector.\n * @since 1.0.0\n */\nexport interface PortalSink {\n /**\n * Records the markup of the portal with hydration key `key`. A key recorded again replaces the\n * earlier markup. Throws an `SsrError` whose `code` is `SSR_PORTAL_LIMIT` past 256 portals in one\n * render.\n */\n add(key: string, html: string): void;\n /**\n * Renders a `Portal`'s content into this sink under hydration key `key`. The collectors the\n * renderers provide have it; `Portal` calls it instead of importing the markup writer, so the\n * browser bundle of an app that uses `Portal` does not carry server rendering code. A sink without\n * it receives nothing from `Portal`.\n * @param key The portal's key, `undefined` when the render has no scope (nothing is written).\n * @param children Reads the content: a thunk, because it must be built inside the portal's scope.\n */\n render?(key: string | undefined, children: () => unknown): void;\n}\n\n/**\n * The context through which a server render hands portals their collector: the renderers provide it\n * when they are given a `portals` option (see `createServerPortals`). A custom portal reads it on the\n * server and records its markup under its hydration key, so the client's `claimPortal` adopts it.\n * Its value is `null` for every other render, and in the browser, where a portal writes nothing on\n * the server.\n *\n * @example\n * import { useContext } from \"@shadow-js/core\";\n * import { nextKey, PortalContext } from \"@shadow-js/web/extend\";\n * import { escape } from \"@shadow-js/web/server\";\n *\n * function ServerToast(props: { text: string }): null {\n * const key = nextKey();\n * const sink = useContext(PortalContext);\n * if (sink !== null && key !== undefined) sink.add(key, `<div role=\"status\">${escape(props.text)}</div>`);\n * return null;\n * }\n * @see claimPortal\n * @since 1.0.0\n */\nexport const PortalContext: Context<PortalSink | null> =\n /* @__PURE__ */ createContext<PortalSink | null>(null, {\n name: \"Portal\",\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAa,gBACK,8BAAiC,MAAM,EACrD,MAAM,SACR,CAAC"}
|
|
@@ -11,22 +11,16 @@
|
|
|
11
11
|
* `stroke-width`). A camelCase name whose first word is one of these families is hyphenated. The
|
|
12
12
|
* families are the first words of the CSS properties SVG takes as attributes, so one rule covers the
|
|
13
13
|
* presentation list. The compiler's table (`packages/compiler/src/internal/react-names.ts`) lists the
|
|
14
|
-
* same names, and a test checks each one.
|
|
14
|
+
* same names, and a test checks each one. The exceptions are SVG attributes that start with a family but are
|
|
15
|
+
* not CSS properties (`clipPathUnits`, `markerWidth`): they are camelCase in SVG, so they keep their case.
|
|
15
16
|
*/
|
|
16
|
-
const SVG_PROPERTY_FAMILY = /^(?:alignment|baseline|clip|color|dominant|enable|fill|flood|font|glyph|image|letter|lighting|marker|mask|mix|paint|pointer|shape|stop|stroke|text|transform|unicode|vector|white|word|writing)(?=[A-Z])/;
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"glyphRef",
|
|
24
|
-
"markerHeight",
|
|
25
|
-
"markerUnits",
|
|
26
|
-
"markerWidth",
|
|
27
|
-
"maskContentUnits",
|
|
28
|
-
"maskUnits",
|
|
29
|
-
"textLength"
|
|
17
|
+
const SVG_PROPERTY_FAMILY = /^(?!clipPathUnits|glyphRef|marker(?:Height|Units|Width)|mask(?:Content)?Units|textLength)(?:alignment|baseline|clip|color|dominant|enable|fill|flood|font|glyph|image|letter|lighting|marker|mask|mix|paint|pointer|shape|stop|stroke|text|transform|unicode|vector|white|word|writing)(?=[A-Z])/;
|
|
18
|
+
/** React names whose attribute differs from the lower-cased key, in HTML and SVG alike. */
|
|
19
|
+
const RENAMED = /* @__PURE__ */ new Map([
|
|
20
|
+
["className", "class"],
|
|
21
|
+
["htmlFor", "for"],
|
|
22
|
+
["httpEquiv", "http-equiv"],
|
|
23
|
+
["acceptCharset", "accept-charset"]
|
|
30
24
|
]);
|
|
31
25
|
/**
|
|
32
26
|
* The attribute name for a props key on an element: HTML names are lower case (what the parser and
|
|
@@ -35,33 +29,24 @@ const SVG_CAMEL_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
|
35
29
|
* @internal
|
|
36
30
|
*/
|
|
37
31
|
function attributeName(name, svg) {
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
if (name === "httpEquiv") return "http-equiv";
|
|
41
|
-
if (name === "acceptCharset") return "accept-charset";
|
|
32
|
+
const renamed = RENAMED.get(name);
|
|
33
|
+
if (renamed !== void 0) return renamed;
|
|
42
34
|
if (!svg) return name.toLowerCase();
|
|
43
35
|
if (name.includes(":")) return name;
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
if (xml !== null) return `xml:${lowerFirst(xml[1] ?? "")}`;
|
|
48
|
-
if (SVG_CAMEL_ATTRIBUTES.has(name) || !SVG_PROPERTY_FAMILY.test(name)) return name;
|
|
36
|
+
const prefixed = /^(xlink|xml)([A-Z])(.*)$/.exec(name);
|
|
37
|
+
if (prefixed !== null) return `${prefixed[1]}:${prefixed[2]?.toLowerCase()}${prefixed[3]}`;
|
|
38
|
+
if (!SVG_PROPERTY_FAMILY.test(name)) return name;
|
|
49
39
|
return name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
50
40
|
}
|
|
51
|
-
function lowerFirst(text) {
|
|
52
|
-
return text.replace(/^[A-Z]/, (letter) => letter.toLowerCase());
|
|
53
|
-
}
|
|
54
41
|
/** Props that have no DOM form: a spread ignores them (React's `key` and hydration flags). @internal */
|
|
55
|
-
const IGNORED_KEYS =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
]
|
|
60
|
-
|
|
61
|
-
"checkbox",
|
|
62
|
-
"radio",
|
|
63
|
-
"file"
|
|
42
|
+
const IGNORED_KEYS = /^(?:key|suppress(?:Hydration|ContentEditable)Warning)$/;
|
|
43
|
+
/** React events that bubble under another name. */
|
|
44
|
+
const REACT_EVENTS = /* @__PURE__ */ new Map([
|
|
45
|
+
["focus", "focusin"],
|
|
46
|
+
["blur", "focusout"],
|
|
47
|
+
["doubleclick", "dblclick"]
|
|
64
48
|
]);
|
|
49
|
+
const CHANGE_ON_TYPES = /^(?:checkbox|radio|file)$/;
|
|
65
50
|
/**
|
|
66
51
|
* Plans the DOM event for an `on*` prop. React's spellings follow React: `onChange` is the per-edit
|
|
67
52
|
* `input` event on text inputs and textareas and the `change` event on other controls; `onFocus` and
|
|
@@ -72,44 +57,33 @@ const CHANGE_ON_TYPES = /* @__PURE__ */ new Set([
|
|
|
72
57
|
function eventPlan(attribute, tag, type) {
|
|
73
58
|
const reactSpelling = /^on[A-Z]/.test(attribute);
|
|
74
59
|
const capture = reactSpelling && attribute.endsWith("Capture");
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
capture: false,
|
|
79
|
-
passive: false
|
|
80
|
-
};
|
|
81
|
-
const lower = base.toLowerCase();
|
|
82
|
-
if (lower === "change") return {
|
|
83
|
-
type: tag === "textarea" || tag === "input" && (type === null || !CHANGE_ON_TYPES.has(type)) ? "input" : "change",
|
|
84
|
-
capture,
|
|
85
|
-
passive: false
|
|
86
|
-
};
|
|
87
|
-
if (lower === "focus") return {
|
|
88
|
-
type: "focusin",
|
|
89
|
-
capture,
|
|
90
|
-
passive: false
|
|
91
|
-
};
|
|
92
|
-
if (lower === "blur") return {
|
|
93
|
-
type: "focusout",
|
|
94
|
-
capture,
|
|
95
|
-
passive: false
|
|
96
|
-
};
|
|
97
|
-
if (lower === "doubleclick") return {
|
|
98
|
-
type: "dblclick",
|
|
99
|
-
capture,
|
|
100
|
-
passive: false
|
|
101
|
-
};
|
|
102
|
-
if (lower === "wheel") return {
|
|
103
|
-
type: "wheel",
|
|
104
|
-
capture,
|
|
105
|
-
passive: !capture
|
|
106
|
-
};
|
|
60
|
+
const lower = attribute.slice(2, capture ? -7 : void 0).toLowerCase();
|
|
61
|
+
let planned = lower;
|
|
62
|
+
if (reactSpelling) planned = lower === "change" ? tag === "textarea" || tag === "input" && (type === null || !CHANGE_ON_TYPES.test(type)) ? "input" : "change" : REACT_EVENTS.get(lower) ?? lower;
|
|
107
63
|
return {
|
|
108
|
-
type:
|
|
64
|
+
type: planned,
|
|
109
65
|
capture,
|
|
110
|
-
passive:
|
|
66
|
+
passive: reactSpelling && lower === "wheel" && !capture
|
|
111
67
|
};
|
|
112
68
|
}
|
|
113
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Boolean attributes that a props object writes as presence flags (`disabled: true` gives a bare
|
|
71
|
+
* `disabled`). Lower-case names only. The server and the client share this test, so a value that
|
|
72
|
+
* renders a flag on one side renders it on the other. One space-separated string, not a set of
|
|
73
|
+
* strings, because every bundle that spreads props carries it. A name with a space in it can match
|
|
74
|
+
* two neighbors, but such a name is not a valid attribute name and both renderers refuse it before
|
|
75
|
+
* they write anything.
|
|
76
|
+
*/
|
|
77
|
+
const BOOLEAN_ATTRIBUTES = " async autofocus autoplay checked controls default defer disabled formnovalidate hidden inert ismap loop multiple muted nomodule novalidate open playsinline readonly required reversed selected ";
|
|
78
|
+
/**
|
|
79
|
+
* True when a prop written under attribute name `name` is a presence flag for `value`: one of the
|
|
80
|
+
* boolean attributes, except `hidden="until-found"`, a keyword that only collapses the element
|
|
81
|
+
* (a bare `hidden` would hide it). The client writes the flag with truthiness, as the server does.
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
function isFlagAttribute(name, value) {
|
|
85
|
+
return BOOLEAN_ATTRIBUTES.includes(` ${name} `) && !(name === "hidden" && value === "until-found");
|
|
86
|
+
}
|
|
87
|
+
export { IGNORED_KEYS, attributeName, eventPlan, isFlagAttribute };
|
|
114
88
|
|
|
115
89
|
//# sourceMappingURL=react-names.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-names.js","names":[],"sources":["../../../src/internal/react-names.ts"],"sourcesContent":["/**\n * React spellings at run time: the attribute and event names that a props object (a spread) passes\n * through. The compiler resolves the same names at build time (`packages/compiler/src/internal/\n * react-names.ts`); a test keeps the two presentation lists equal, so keep them in step.\n *\n * @internal\n */\n\n/**\n * SVG presentation attributes are CSS properties, and React spells them in camelCase (`strokeWidth` is\n * `stroke-width`). A camelCase name whose first word is one of these families is hyphenated. The\n * families are the first words of the CSS properties SVG takes as attributes, so one rule covers the\n * presentation list. The compiler's table (`packages/compiler/src/internal/react-names.ts`) lists the\n * same names, and a test checks each one.\n */\nconst SVG_PROPERTY_FAMILY =\n /^(?:alignment|baseline|clip|color|dominant|enable|fill|flood|font|glyph|image|letter|lighting|marker|mask|mix|paint|pointer|shape|stop|stroke|text|transform|unicode|vector|white|word|writing)(?=[A-Z])/;\n\n
|
|
1
|
+
{"version":3,"file":"react-names.js","names":[],"sources":["../../../src/internal/react-names.ts"],"sourcesContent":["/**\n * React spellings at run time: the attribute and event names that a props object (a spread) passes\n * through. The compiler resolves the same names at build time (`packages/compiler/src/internal/\n * react-names.ts`); a test keeps the two presentation lists equal, so keep them in step.\n *\n * @internal\n */\n\n/**\n * SVG presentation attributes are CSS properties, and React spells them in camelCase (`strokeWidth` is\n * `stroke-width`). A camelCase name whose first word is one of these families is hyphenated. The\n * families are the first words of the CSS properties SVG takes as attributes, so one rule covers the\n * presentation list. The compiler's table (`packages/compiler/src/internal/react-names.ts`) lists the\n * same names, and a test checks each one. The exceptions are SVG attributes that start with a family but are\n * not CSS properties (`clipPathUnits`, `markerWidth`): they are camelCase in SVG, so they keep their case.\n */\nconst SVG_PROPERTY_FAMILY =\n /^(?!clipPathUnits|glyphRef|marker(?:Height|Units|Width)|mask(?:Content)?Units|textLength)(?:alignment|baseline|clip|color|dominant|enable|fill|flood|font|glyph|image|letter|lighting|marker|mask|mix|paint|pointer|shape|stop|stroke|text|transform|unicode|vector|white|word|writing)(?=[A-Z])/;\n\n/** React names whose attribute differs from the lower-cased key, in HTML and SVG alike. */\nconst RENAMED: ReadonlyMap<string, string> = new Map([\n [\"className\", \"class\"],\n [\"htmlFor\", \"for\"],\n [\"httpEquiv\", \"http-equiv\"],\n [\"acceptCharset\", \"accept-charset\"],\n]);\n\n/**\n * The attribute name for a props key on an element: HTML names are lower case (what the parser and\n * `setAttribute` write anyway, and what server markup needs); SVG presentation names are hyphenated,\n * `xlinkHref` and `xmlLang` take their prefix, and other SVG names keep their case (`viewBox`).\n * @internal\n */\nexport function attributeName(name: string, svg: boolean): string {\n const renamed = RENAMED.get(name);\n if (renamed !== undefined) return renamed;\n if (!svg) return name.toLowerCase();\n if (name.includes(\":\")) return name;\n const prefixed = /^(xlink|xml)([A-Z])(.*)$/.exec(name);\n if (prefixed !== null) return `${prefixed[1]}:${prefixed[2]?.toLowerCase()}${prefixed[3]}`;\n if (!SVG_PROPERTY_FAMILY.test(name)) return name;\n return name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n}\n\n/** Props that have no DOM form: a spread ignores them (React's `key` and hydration flags). @internal */\nexport const IGNORED_KEYS: RegExp = /^(?:key|suppress(?:Hydration|ContentEditable)Warning)$/;\n\n/** The DOM event for a React-spelled prop (see the compiler's `eventPlan`). @internal */\nexport interface EventPlan {\n readonly type: string;\n readonly capture: boolean;\n readonly passive: boolean;\n}\n\n/** React events that bubble under another name. */\nconst REACT_EVENTS: ReadonlyMap<string, string> = new Map([\n [\"focus\", \"focusin\"],\n [\"blur\", \"focusout\"],\n [\"doubleclick\", \"dblclick\"],\n]);\n\nconst CHANGE_ON_TYPES = /^(?:checkbox|radio|file)$/;\n\n/**\n * Plans the DOM event for an `on*` prop. React's spellings follow React: `onChange` is the per-edit\n * `input` event on text inputs and textareas and the `change` event on other controls; `onFocus` and\n * `onBlur` bubble as `focusin` and `focusout`; a `...Capture` suffix binds the capture phase; `onWheel`\n * is passive. A lower-case `on` spelling is the native event.\n * @internal\n */\nexport function eventPlan(attribute: string, tag: string, type: string | null): EventPlan {\n const reactSpelling = /^on[A-Z]/.test(attribute);\n const capture = reactSpelling && attribute.endsWith(\"Capture\");\n const lower = attribute.slice(2, capture ? -\"Capture\".length : undefined).toLowerCase();\n let planned = lower;\n if (reactSpelling) {\n planned =\n lower === \"change\"\n ? tag === \"textarea\" || (tag === \"input\" && (type === null || !CHANGE_ON_TYPES.test(type)))\n ? \"input\"\n : \"change\"\n : (REACT_EVENTS.get(lower) ?? lower);\n }\n return { type: planned, capture, passive: reactSpelling && lower === \"wheel\" && !capture };\n}\n\n/**\n * Boolean attributes that a props object writes as presence flags (`disabled: true` gives a bare\n * `disabled`). Lower-case names only. The server and the client share this test, so a value that\n * renders a flag on one side renders it on the other. One space-separated string, not a set of\n * strings, because every bundle that spreads props carries it. A name with a space in it can match\n * two neighbors, but such a name is not a valid attribute name and both renderers refuse it before\n * they write anything.\n */\nconst BOOLEAN_ATTRIBUTES =\n \" async autofocus autoplay checked controls default defer disabled formnovalidate hidden inert \" +\n \"ismap loop multiple muted nomodule novalidate open playsinline readonly required reversed selected \";\n\n/**\n * True when a prop written under attribute name `name` is a presence flag for `value`: one of the\n * boolean attributes, except `hidden=\"until-found\"`, a keyword that only collapses the element\n * (a bare `hidden` would hide it). The client writes the flag with truthiness, as the server does.\n * @internal\n */\nexport function isFlagAttribute(name: string, value: unknown): boolean {\n return (\n BOOLEAN_ATTRIBUTES.includes(` ${name} `) && !(name === \"hidden\" && value === \"until-found\")\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAM,sBACJ;;AAGF,MAAM,0BAAuC,IAAI,IAAI;CACnD,CAAC,aAAa,OAAO;CACrB,CAAC,WAAW,KAAK;CACjB,CAAC,aAAa,YAAY;CAC1B,CAAC,iBAAiB,gBAAgB;AACpC,CAAC;;;;;;;AAQD,SAAgB,cAAc,MAAc,KAAsB;CAChE,MAAM,UAAU,QAAQ,IAAI,IAAI;CAChC,IAAI,YAAY,KAAA,GAAW,OAAO;CAClC,IAAI,CAAC,KAAK,OAAO,KAAK,YAAY;CAClC,IAAI,KAAK,SAAS,GAAG,GAAG,OAAO;CAC/B,MAAM,WAAW,2BAA2B,KAAK,IAAI;CACrD,IAAI,aAAa,MAAM,OAAO,GAAG,SAAS,GAAG,GAAG,SAAS,EAAE,EAAE,YAAY,IAAI,SAAS;CACtF,IAAI,CAAC,oBAAoB,KAAK,IAAI,GAAG,OAAO;CAC5C,OAAO,KAAK,QAAQ,WAAW,WAAW,IAAI,OAAO,YAAY,GAAG;AACtE;;AAGA,MAAa,eAAuB;;AAUpC,MAAM,+BAA4C,IAAI,IAAI;CACxD,CAAC,SAAS,SAAS;CACnB,CAAC,QAAQ,UAAU;CACnB,CAAC,eAAe,UAAU;AAC5B,CAAC;AAED,MAAM,kBAAkB;;;;;;;;AASxB,SAAgB,UAAU,WAAmB,KAAa,MAAgC;CACxF,MAAM,gBAAgB,WAAW,KAAK,SAAS;CAC/C,MAAM,UAAU,iBAAiB,UAAU,SAAS,SAAS;CAC7D,MAAM,QAAQ,UAAU,MAAM,GAAG,UAAU,KAAoB,KAAA,CAAS,CAAC,CAAC,YAAY;CACtF,IAAI,UAAU;CACd,IAAI,eACF,UACE,UAAU,WACN,QAAQ,cAAe,QAAQ,YAAY,SAAS,QAAQ,CAAC,gBAAgB,KAAK,IAAI,KACpF,UACA,WACD,aAAa,IAAI,KAAK,KAAK;CAEpC,OAAO;EAAE,MAAM;EAAS;EAAS,SAAS,iBAAiB,UAAU,WAAW,CAAC;CAAQ;AAC3F;;;;;;;;;AAUA,MAAM,qBACJ;;;;;;;AASF,SAAgB,gBAAgB,MAAc,OAAyB;CACrE,OACE,mBAAmB,SAAS,IAAI,KAAK,EAAE,KAAK,EAAE,SAAS,YAAY,UAAU;AAEjF"}
|
|
@@ -12,21 +12,21 @@ function markLongestIncreasing(values, offset, marks) {
|
|
|
12
12
|
const tails = [];
|
|
13
13
|
const previous = values.map(() => -1);
|
|
14
14
|
for (let index = 0; index < values.length; index += 1) {
|
|
15
|
-
const value = values[index]
|
|
15
|
+
const value = values[index];
|
|
16
16
|
let low = 0;
|
|
17
17
|
let high = tails.length;
|
|
18
18
|
while (low < high) {
|
|
19
19
|
const middle = low + high >> 1;
|
|
20
|
-
if (
|
|
20
|
+
if (values[tails[middle]] < value) low = middle + 1;
|
|
21
21
|
else high = middle;
|
|
22
22
|
}
|
|
23
|
-
previous[index] =
|
|
23
|
+
previous[index] = tails[low - 1] ?? -1;
|
|
24
24
|
tails[low] = index;
|
|
25
25
|
}
|
|
26
|
-
let cursor = tails.
|
|
26
|
+
let cursor = tails.at(-1) ?? -1;
|
|
27
27
|
while (cursor !== -1) {
|
|
28
|
-
marks[
|
|
29
|
-
cursor = previous[cursor]
|
|
28
|
+
marks[values[cursor] - offset] = 1;
|
|
29
|
+
cursor = previous[cursor];
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -90,16 +90,12 @@ function reconcileNodes(parent, prev, next, end) {
|
|
|
90
90
|
const survivors = [];
|
|
91
91
|
for (let index = head; index < prevTail; index += 1) {
|
|
92
92
|
const node = prev[index];
|
|
93
|
-
if (node === void 0) continue;
|
|
94
93
|
const position = target.get(node);
|
|
95
94
|
if (position === void 0) removeNode(parent, node);
|
|
96
95
|
else survivors.push(position);
|
|
97
96
|
}
|
|
98
97
|
if (survivors.length === 0) {
|
|
99
|
-
for (
|
|
100
|
-
const node = next[index];
|
|
101
|
-
if (node !== void 0) parent.insertBefore(node, before);
|
|
102
|
-
}
|
|
98
|
+
for (const node of next.slice(head, nextTail)) parent.insertBefore(node, before);
|
|
103
99
|
return;
|
|
104
100
|
}
|
|
105
101
|
const stable = new Uint8Array(nextTail - head);
|
|
@@ -108,7 +104,6 @@ function reconcileNodes(parent, prev, next, end) {
|
|
|
108
104
|
let anchorNode = before;
|
|
109
105
|
for (let index = nextTail - 1; index >= head; index -= 1) {
|
|
110
106
|
const node = next[index];
|
|
111
|
-
if (node === void 0) continue;
|
|
112
107
|
if (stable[index - head] !== 1) {
|
|
113
108
|
if (movable && node.parentNode === parent) parent.moveBefore(node, anchorNode);
|
|
114
109
|
else parent.insertBefore(node, anchorNode);
|