@shadow-js/web 1.0.4 → 1.0.5
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 +8 -0
- package/README.md +1 -1
- package/dist/dev/class-style.js +6 -1
- package/dist/dev/class-style.js.map +1 -1
- package/dist/dev/control-flow/dynamic.js +4 -4
- package/dist/dev/control-flow/no-hydration.js +1 -1
- package/dist/dev/control-flow/portal.js +1 -1
- package/dist/dev/element.js +2 -2
- package/dist/dev/extend.js +6 -6
- package/dist/dev/head/use-head.js +1 -1
- package/dist/dev/head/validate.js +1 -1
- package/dist/dev/hydration.js +21 -13
- package/dist/dev/hydration.js.map +1 -1
- package/dist/dev/index.d.ts +5 -5
- package/dist/dev/index.js +6 -6
- package/dist/dev/jsx/global.d.ts +2 -2
- package/dist/dev/jsx/html.d.ts +1 -1
- package/dist/dev/jsx/intrinsic.d.ts +1 -1
- package/dist/dev/jsx/mathml.d.ts +1 -1
- package/dist/dev/jsx/svg.d.ts +1 -1
- package/dist/dev/jsx-runtime.d.ts +3 -3
- package/dist/dev/render.js +22 -11
- package/dist/dev/render.js.map +1 -1
- package/dist/dev/server/class-style.js +1 -1
- package/dist/dev/server/element.js +3 -3
- package/dist/dev/server/form-controls.js +1 -1
- package/dist/dev/server/hydration-script.js +1 -1
- package/dist/dev/server/portals.js +1 -1
- package/dist/dev/server/raw-text.js +1 -1
- package/dist/dev/server/render.js +2 -2
- package/dist/dev/server/stream.js +3 -3
- package/dist/dev/spread.js +12 -4
- package/dist/dev/spread.js.map +1 -1
- package/dist/dev/template.js +3 -3
- 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/no-hydration.js +1 -1
- package/dist/prod/control-flow/portal.js +1 -1
- package/dist/prod/element.js +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/head/use-head.js +1 -1
- package/dist/prod/head/validate.js +1 -1
- package/dist/prod/hydration.js +1 -1
- package/dist/prod/hydration.js.map +1 -1
- package/dist/prod/index.js +1 -1
- package/dist/prod/render.js +1 -1
- package/dist/prod/render.js.map +1 -1
- package/dist/prod/server/class-style.js +1 -1
- package/dist/prod/server/element.js +1 -1
- package/dist/prod/server/form-controls.js +2 -2
- package/dist/prod/server/hydration-script.js +1 -1
- package/dist/prod/server/portals.js +1 -1
- package/dist/prod/server/raw-text.js +1 -1
- package/dist/prod/server/render.js +1 -1
- package/dist/prod/server/stream.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/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/portal.js +1 -1
- package/dist/server/control-flow/suspense.js +1 -1
- package/dist/server/element.js +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/head/use-head.js +1 -1
- package/dist/server/head/validate.js +1 -1
- package/dist/server/hydration.js +1 -1
- package/dist/server/hydration.js.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/render.js +1 -1
- package/dist/server/render.js.map +1 -1
- package/dist/server/server/class-style.js +1 -1
- package/dist/server/server/element.js +1 -1
- package/dist/server/server/form-controls.js +2 -2
- package/dist/server/server/hydration-script.js +1 -1
- package/dist/server/server/portals.js +1 -1
- package/dist/server/server/raw-text.js +1 -1
- package/dist/server/server/render.js +1 -1
- package/dist/server/server/stream.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-dev/class-style.js +6 -1
- package/dist/server-dev/class-style.js.map +1 -1
- package/dist/server-dev/control-flow/dynamic.js +1 -1
- package/dist/server-dev/control-flow/portal.js +1 -1
- package/dist/server-dev/control-flow/suspense.js +2 -2
- package/dist/server-dev/element.js +1 -1
- package/dist/server-dev/extend.js +6 -6
- package/dist/server-dev/head/use-head.js +1 -1
- package/dist/server-dev/head/validate.js +1 -1
- package/dist/server-dev/hydration.js +21 -13
- package/dist/server-dev/hydration.js.map +1 -1
- package/dist/server-dev/index.js +6 -6
- package/dist/server-dev/render.js +22 -11
- package/dist/server-dev/render.js.map +1 -1
- package/dist/server-dev/server/class-style.js +1 -1
- package/dist/server-dev/server/element.js +3 -3
- package/dist/server-dev/server/form-controls.js +1 -1
- package/dist/server-dev/server/hydration-script.js +1 -1
- package/dist/server-dev/server/portals.js +1 -1
- package/dist/server-dev/server/raw-text.js +1 -1
- package/dist/server-dev/server/render.js +2 -2
- package/dist/server-dev/server/stream.js +3 -3
- package/dist/server-dev/spread.js +12 -4
- package/dist/server-dev/spread.js.map +1 -1
- package/dist/server-dev/template.js +3 -3
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- A style array skips `null`, `undefined` and `false` values like the server does, so an earlier entry's property is no longer removed on the client.
|
|
8
|
+
- When `render()` or `hydrate()` throws during its first flush, the root, its effects and (for `render`) its partial DOM are torn down and the error is rethrown; `hydrate` keeps the server markup.
|
|
9
|
+
- `value` on `progress`, `meter` and `li` is written as an attribute through `spread`, so `undefined` leaves no `value="0"` and matches the server.
|
|
10
|
+
|
|
3
11
|
## 1.0.4
|
|
4
12
|
|
|
5
13
|
### Fixed
|
package/README.md
CHANGED
|
@@ -175,7 +175,7 @@ type tests are in `packages/web/test-types`.
|
|
|
175
175
|
## Dependencies
|
|
176
176
|
|
|
177
177
|
- Runtime: none.
|
|
178
|
-
- Peers: `@shadow-js/core` `^1.0.
|
|
178
|
+
- Peers: `@shadow-js/core` `^1.0.5`: the reactive primitives the renderer is built on.
|
|
179
179
|
|
|
180
180
|
## Types
|
|
181
181
|
|
package/dist/dev/class-style.js
CHANGED
|
@@ -189,7 +189,12 @@ function style(el, value, prev) {
|
|
|
189
189
|
if (typeof item === "string") el.style.cssText += `;${item}`;
|
|
190
190
|
else if (item !== null && item !== void 0 && item !== false) {
|
|
191
191
|
if (typeof item !== "object" || Array.isArray(item)) throw new TypeError("style(): an array holds only strings and objects.");
|
|
192
|
-
|
|
192
|
+
const declared = {};
|
|
193
|
+
for (const key of Object.keys(item)) {
|
|
194
|
+
const part = unwrap(item[key]);
|
|
195
|
+
if (part !== null && part !== void 0 && part !== false) declared[key] = part;
|
|
196
|
+
}
|
|
197
|
+
style(el, declared, {});
|
|
193
198
|
}
|
|
194
199
|
}
|
|
195
200
|
return resolved;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-style.js","names":[],"sources":["../../src/class-style.ts"],"sourcesContent":["import { leaves, unwrap } from \"./internal/accessor\";\nimport { cssValueText } from \"./internal/css-units\";\nimport { HTML_NS } from \"./internal/names\";\n\n/** Appends the truthy class names of `value` (strings, numbers, nested arrays, objects) to `parts`. */\nfunction collectClasses(root: unknown, parts: string[]): void {\n const cycle = __DEV__ ? \"className(): a class array contains itself.\" : \"SHADOW_CLASS_CYCLE\";\n for (const item of leaves(root, cycle)) {\n if (typeof item === \"string\") {\n if (item !== \"\") parts.push(item);\n } else if (typeof item === \"number\") {\n if (item !== 0 && !Number.isNaN(item)) parts.push(String(item));\n } else if (item !== null && typeof item === \"object\") {\n const record = item as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n if (unwrap(record[key]) && key !== \"\") parts.push(key);\n }\n }\n }\n}\n\n/** Class text for `value`, or null when the class attribute must be removed. */\nfunction classText(input: unknown): string | null {\n const value = unwrap(input);\n if (typeof value === \"string\") return value;\n if (value === null || value === undefined || value === false) return null;\n const parts: string[] = [];\n collectClasses(value, parts);\n return parts.join(\" \");\n}\n\n/**\n * Writes a class value. `svg` selects the attribute path, which SVG and MathML need because their\n * `className` is not a plain string.\n * @internal\n */\nexport function applyClass(el: Element, value: unknown, svg: boolean): void {\n const text = classText(value);\n if (text === null) {\n el.removeAttribute(\"class\");\n return;\n }\n if (svg) {\n if (el.getAttribute(\"class\") !== text) el.setAttribute(\"class\", text);\n } else if (el.className !== text) {\n el.className = text;\n }\n}\n\n/**\n * Replaces the whole `class` of an element: the helper compiled templates call for `class` and\n * `className`. HTML elements are written through `className`; SVG and MathML elements (whose\n * `className` is not a plain string) through the `class` attribute. The DOM is touched only when\n * the text changes.\n *\n * @param el Target element.\n * @param value A string is used as is. Arrays and objects are clsx-style: non-empty strings,\n * numbers other than `0` and `NaN`, nested arrays, and the keys of objects whose value is truthy,\n * joined with spaces. `null`, `undefined` and `false` remove the attribute. Accessors, also inside\n * arrays and as object values, are called (as on the server); the signals they read are tracked by\n * the effect that applies the class.\n * @throws TypeError `SHADOW_CLASS_CYCLE` when an array contains itself (directly or through a nested\n * array), and `SHADOW_INSERT_DEPTH` when an accessor returns accessors more than 10,000 levels deep.\n * @example\n * import { className } from \"@shadow-js/web\";\n *\n * const card = document.createElement(\"div\");\n * className(card, [\"card\", { \"card--active\": true, \"card--muted\": false }]);\n * card.className; // \"card card--active\"\n * @see classList\n * @since 1.0.0\n */\nexport function className(el: Element, value: unknown): void {\n applyClass(el, value, el.namespaceURI !== HTML_NS);\n}\n\n/** Narrows an object value to a record of keys; arrays and primitives are not class maps. @internal */\nexport function asRecord(value: unknown): Record<string, unknown> | undefined {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n return value as Record<string, unknown>;\n}\n\n/** Whether `key` is switched on in `map`: own properties only, so a key named `constructor` reads as it was written. */\nfunction enabled(map: Record<string, unknown>, key: string): boolean {\n return Object.hasOwn(map, key) && Boolean(map[key]);\n}\n\n/**\n * Toggles individual classes from an object: the helper compiled templates call for `classList`.\n * Unlike {@link className}, it leaves classes it did not set alone: only keys whose truthiness\n * changed relative to `prev` are touched. A key may hold several space-separated names. Keys that\n * disappeared from `value` are switched off.\n *\n * @param el Target element.\n * @param value Map from class names to truthiness; a value that is an accessor is called. `undefined`\n * switches off every class `prev` had on.\n * @param prev The map returned by the previous call. Undefined (the first call) means no class was\n * on yet.\n * @returns The map now in effect (`value`, or `{}` for undefined; a copy with the accessors resolved\n * when `value` has any), to pass back as `prev` next time.\n * @example\n * import { classList } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"li\");\n * let prev = classList(el, { active: true, \"is-new pulse\": true });\n * prev = classList(el, { active: false }, prev); // removes active, is-new and pulse\n * @see className\n * @since 1.0.0\n */\nexport function classList(\n el: Element,\n value: Record<string, unknown> | undefined,\n prev?: Record<string, unknown>,\n): Record<string, unknown> {\n // `value` itself, or a copy in which accessor values are resolved, so a later diff compares what was applied.\n const source = value ?? {};\n let next = source;\n for (const key of Object.keys(source)) {\n if (typeof source[key] !== \"function\") continue;\n if (next === source) next = { ...source };\n next[key] = unwrap(source[key]);\n }\n const before: Record<string, unknown> = prev ?? {};\n const keys = new Set([...Object.keys(before), ...Object.keys(next)]);\n for (const key of keys) {\n // Own properties only: `next[\"constructor\"]` would otherwise read Object.prototype's function\n // and a class with that name could never be switched on.\n const now = enabled(next, key);\n const was = enabled(before, key);\n if (now === was) continue;\n for (const token of key.split(/\\s+/)) {\n if (token !== \"\") el.classList.toggle(token, now);\n }\n }\n return next;\n}\n\n/**\n * Converts a camelCase style name to a CSS property name. Custom properties are kept as they are,\n * and vendor prefixes map to `-webkit-` and `-ms-`.\n * @internal\n */\nexport function toCssProperty(name: string): string {\n if (name.startsWith(\"--\")) return name;\n const kebab = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n return kebab.startsWith(\"ms-\") ? `-${kebab}` : kebab;\n}\n\n/**\n * Sets or removes one inline style property: the helper compiled templates call for the `style:`\n * prefix. Other inline properties are left alone.\n *\n * @param el HTML or SVG element.\n * @param name CSS property in camelCase (`backgroundColor`, `msTransform` gives `-ms-transform`) or\n * kebab-case, or a custom property (`--accent`, kept as is).\n * @param value `null`, `undefined` and `false` remove the property. A number is in pixels, as in\n * React, unless it is `0`, the property is unitless (`opacity`, `zIndex`, `flexGrow`, `lineHeight`,\n * ...) or a custom property. Any other value is written as `String(value)`.\n * @example\n * import { setStyleProperty } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"div\");\n * setStyleProperty(el, \"marginTop\", 8); // margin-top: 8px\n * setStyleProperty(el, \"--accent\", \"rebeccapurple\");\n * setStyleProperty(el, \"opacity\", 0.5); // unitless\n * @see style\n * @since 1.0.0\n */\nexport function setStyleProperty(el: HTMLElement | SVGElement, name: string, value: unknown): void {\n const property = toCssProperty(name);\n if (value === null || value === undefined || value === false) {\n el.style.removeProperty(property);\n } else {\n el.style.setProperty(property, cssValueText(property, value));\n }\n}\n\n/**\n * Sets the inline style of an element: the helper compiled templates call for a `style` attribute.\n * An object is diffed against `prev` so that only changed properties are written, each with the\n * rules of {@link setStyleProperty}; properties that disappeared are removed.\n *\n * @param el HTML or SVG element.\n * @param value An object of properties (camelCase, kebab-case or custom names). A string replaces\n * `cssText`. An array of strings and objects (not nested; `null`, `undefined`, `false` and `\"\"`\n * items are skipped) is written in order, so a later declaration wins, exactly as `ssrStyle` writes it\n * on the server. `null`, `undefined` and `false` remove the `style` attribute. Accessors (the value,\n * array items and property values) are called, as on the server.\n * @param prev The value returned by the previous call. Undefined (the first call) diffs against an\n * empty style. When it is a string or an array, `cssText` is cleared before the object is written.\n * @returns What to pass back as `prev` next time: a shallow copy of an object value, otherwise\n * `value` itself.\n * @throws TypeError (production message `SHADOW_STYLE_ITEM`) when an array holds a nested array or a\n * value that is not a string or an object.\n * @example\n * import { style } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"div\");\n * let prev = style(el, { color: \"red\", width: 120 }); // width: 120px\n * prev = style(el, { color: \"blue\" }, prev); // writes color, removes width\n * @see setStyleProperty\n * @since 1.0.0\n */\nexport function style(el: HTMLElement | SVGElement, value: unknown, prev?: unknown): unknown {\n const resolved = unwrap(value);\n if (resolved === null || resolved === undefined || resolved === false) {\n el.removeAttribute(\"style\");\n return resolved;\n }\n if (typeof resolved !== \"object\") {\n el.style.cssText = String(resolved);\n return resolved;\n }\n if (Array.isArray(resolved)) {\n // Not diffed: a string in the array can set any property, so the whole style is written again, in\n // order (a later declaration wins, as on the server).\n el.style.cssText = \"\";\n for (const source of resolved) {\n const item = unwrap(source);\n if (typeof item === \"string\") {\n el.style.cssText += `;${item}`;\n } else if (item !== null && item !== undefined && item !== false) {\n if (typeof item !== \"object\" || Array.isArray(item)) {\n throw new TypeError(\n __DEV__ ? \"style(): an array holds only strings and objects.\" : \"SHADOW_STYLE_ITEM\",\n );\n }\n style(el, item, {});\n }\n }\n return resolved;\n }\n const next: Record<string, unknown> = { ...(resolved as Record<string, unknown>) };\n for (const key of Object.keys(next)) next[key] = unwrap(next[key]);\n const before = asRecord(prev) ?? {};\n // What a string or an array wrote is unknown, so it is cleared before the object is written.\n if (typeof prev === \"string\" || Array.isArray(prev)) el.style.cssText = \"\";\n const keys = new Set([...Object.keys(before), ...Object.keys(next)]);\n for (const key of keys) {\n if (Object.is(before[key], next[key])) continue;\n setStyleProperty(el, key, next[key]);\n }\n return next;\n}\n"],"mappings":";;;;;AAKA,SAAS,eAAe,MAAe,OAAuB;CAE5D,KAAK,MAAM,QAAQ,OAAO,MAAM,6CAAK,GACnC,IAAI,OAAO,SAAS,UACd;MAAA,SAAS,IAAI,MAAM,KAAK,IAAI;CAAA,OAC3B,IAAI,OAAO,SAAS,UACrB;MAAA,SAAS,KAAK,CAAC,OAAO,MAAM,IAAI,GAAG,MAAM,KAAK,OAAO,IAAI,CAAC;CAAA,OACzD,IAAI,SAAS,QAAQ,OAAO,SAAS,UAAU;EACpD,MAAM,SAAS;EACf,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,GAClC,IAAI,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,KAAK,GAAG;CAEzD;AAEJ;;AAGA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AO;IAChE,IAAI,OAAO,SAAS,YAAY,MAAM,QAAQ,IAAI,GAChD,MAAM,IAAI,UACE,mDACZ;IAEF,MAAM,IAAI,MAAM,CAAC,CAAC;GACpB;EACF;EACA,OAAO;CACT;CACA,MAAM,OAAgC,EAAE,GAAI,SAAqC;CACjF,KAAK,MAAM,OAAO,OAAO,KAAK,IAAI,GAAG,KAAK,OAAO,OAAO,KAAK,IAAI;CACjE,MAAM,SAAS,SAAS,IAAI,KAAK,CAAC;CAElC,IAAI,OAAO,SAAS,YAAY,MAAM,QAAQ,IAAI,GAAG,GAAG,MAAM,UAAU;CACxE,MAAM,uBAAO,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,MAAM,GAAG,GAAG,OAAO,KAAK,IAAI,CAAC,CAAC;CACnE,KAAK,MAAM,OAAO,MAAM;EACtB,IAAI,OAAO,GAAG,OAAO,MAAM,KAAK,IAAI,GAAG;EACvC,iBAAiB,IAAI,KAAK,KAAK,IAAI;CACrC;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"class-style.js","names":[],"sources":["../../src/class-style.ts"],"sourcesContent":["import { leaves, unwrap } from \"./internal/accessor\";\nimport { cssValueText } from \"./internal/css-units\";\nimport { HTML_NS } from \"./internal/names\";\n\n/** Appends the truthy class names of `value` (strings, numbers, nested arrays, objects) to `parts`. */\nfunction collectClasses(root: unknown, parts: string[]): void {\n const cycle = __DEV__ ? \"className(): a class array contains itself.\" : \"SHADOW_CLASS_CYCLE\";\n for (const item of leaves(root, cycle)) {\n if (typeof item === \"string\") {\n if (item !== \"\") parts.push(item);\n } else if (typeof item === \"number\") {\n if (item !== 0 && !Number.isNaN(item)) parts.push(String(item));\n } else if (item !== null && typeof item === \"object\") {\n const record = item as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n if (unwrap(record[key]) && key !== \"\") parts.push(key);\n }\n }\n }\n}\n\n/** Class text for `value`, or null when the class attribute must be removed. */\nfunction classText(input: unknown): string | null {\n const value = unwrap(input);\n if (typeof value === \"string\") return value;\n if (value === null || value === undefined || value === false) return null;\n const parts: string[] = [];\n collectClasses(value, parts);\n return parts.join(\" \");\n}\n\n/**\n * Writes a class value. `svg` selects the attribute path, which SVG and MathML need because their\n * `className` is not a plain string.\n * @internal\n */\nexport function applyClass(el: Element, value: unknown, svg: boolean): void {\n const text = classText(value);\n if (text === null) {\n el.removeAttribute(\"class\");\n return;\n }\n if (svg) {\n if (el.getAttribute(\"class\") !== text) el.setAttribute(\"class\", text);\n } else if (el.className !== text) {\n el.className = text;\n }\n}\n\n/**\n * Replaces the whole `class` of an element: the helper compiled templates call for `class` and\n * `className`. HTML elements are written through `className`; SVG and MathML elements (whose\n * `className` is not a plain string) through the `class` attribute. The DOM is touched only when\n * the text changes.\n *\n * @param el Target element.\n * @param value A string is used as is. Arrays and objects are clsx-style: non-empty strings,\n * numbers other than `0` and `NaN`, nested arrays, and the keys of objects whose value is truthy,\n * joined with spaces. `null`, `undefined` and `false` remove the attribute. Accessors, also inside\n * arrays and as object values, are called (as on the server); the signals they read are tracked by\n * the effect that applies the class.\n * @throws TypeError `SHADOW_CLASS_CYCLE` when an array contains itself (directly or through a nested\n * array), and `SHADOW_INSERT_DEPTH` when an accessor returns accessors more than 10,000 levels deep.\n * @example\n * import { className } from \"@shadow-js/web\";\n *\n * const card = document.createElement(\"div\");\n * className(card, [\"card\", { \"card--active\": true, \"card--muted\": false }]);\n * card.className; // \"card card--active\"\n * @see classList\n * @since 1.0.0\n */\nexport function className(el: Element, value: unknown): void {\n applyClass(el, value, el.namespaceURI !== HTML_NS);\n}\n\n/** Narrows an object value to a record of keys; arrays and primitives are not class maps. @internal */\nexport function asRecord(value: unknown): Record<string, unknown> | undefined {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n return value as Record<string, unknown>;\n}\n\n/** Whether `key` is switched on in `map`: own properties only, so a key named `constructor` reads as it was written. */\nfunction enabled(map: Record<string, unknown>, key: string): boolean {\n return Object.hasOwn(map, key) && Boolean(map[key]);\n}\n\n/**\n * Toggles individual classes from an object: the helper compiled templates call for `classList`.\n * Unlike {@link className}, it leaves classes it did not set alone: only keys whose truthiness\n * changed relative to `prev` are touched. A key may hold several space-separated names. Keys that\n * disappeared from `value` are switched off.\n *\n * @param el Target element.\n * @param value Map from class names to truthiness; a value that is an accessor is called. `undefined`\n * switches off every class `prev` had on.\n * @param prev The map returned by the previous call. Undefined (the first call) means no class was\n * on yet.\n * @returns The map now in effect (`value`, or `{}` for undefined; a copy with the accessors resolved\n * when `value` has any), to pass back as `prev` next time.\n * @example\n * import { classList } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"li\");\n * let prev = classList(el, { active: true, \"is-new pulse\": true });\n * prev = classList(el, { active: false }, prev); // removes active, is-new and pulse\n * @see className\n * @since 1.0.0\n */\nexport function classList(\n el: Element,\n value: Record<string, unknown> | undefined,\n prev?: Record<string, unknown>,\n): Record<string, unknown> {\n // `value` itself, or a copy in which accessor values are resolved, so a later diff compares what was applied.\n const source = value ?? {};\n let next = source;\n for (const key of Object.keys(source)) {\n if (typeof source[key] !== \"function\") continue;\n if (next === source) next = { ...source };\n next[key] = unwrap(source[key]);\n }\n const before: Record<string, unknown> = prev ?? {};\n const keys = new Set([...Object.keys(before), ...Object.keys(next)]);\n for (const key of keys) {\n // Own properties only: `next[\"constructor\"]` would otherwise read Object.prototype's function\n // and a class with that name could never be switched on.\n const now = enabled(next, key);\n const was = enabled(before, key);\n if (now === was) continue;\n for (const token of key.split(/\\s+/)) {\n if (token !== \"\") el.classList.toggle(token, now);\n }\n }\n return next;\n}\n\n/**\n * Converts a camelCase style name to a CSS property name. Custom properties are kept as they are,\n * and vendor prefixes map to `-webkit-` and `-ms-`.\n * @internal\n */\nexport function toCssProperty(name: string): string {\n if (name.startsWith(\"--\")) return name;\n const kebab = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n return kebab.startsWith(\"ms-\") ? `-${kebab}` : kebab;\n}\n\n/**\n * Sets or removes one inline style property: the helper compiled templates call for the `style:`\n * prefix. Other inline properties are left alone.\n *\n * @param el HTML or SVG element.\n * @param name CSS property in camelCase (`backgroundColor`, `msTransform` gives `-ms-transform`) or\n * kebab-case, or a custom property (`--accent`, kept as is).\n * @param value `null`, `undefined` and `false` remove the property. A number is in pixels, as in\n * React, unless it is `0`, the property is unitless (`opacity`, `zIndex`, `flexGrow`, `lineHeight`,\n * ...) or a custom property. Any other value is written as `String(value)`.\n * @example\n * import { setStyleProperty } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"div\");\n * setStyleProperty(el, \"marginTop\", 8); // margin-top: 8px\n * setStyleProperty(el, \"--accent\", \"rebeccapurple\");\n * setStyleProperty(el, \"opacity\", 0.5); // unitless\n * @see style\n * @since 1.0.0\n */\nexport function setStyleProperty(el: HTMLElement | SVGElement, name: string, value: unknown): void {\n const property = toCssProperty(name);\n if (value === null || value === undefined || value === false) {\n el.style.removeProperty(property);\n } else {\n el.style.setProperty(property, cssValueText(property, value));\n }\n}\n\n/**\n * Sets the inline style of an element: the helper compiled templates call for a `style` attribute.\n * An object is diffed against `prev` so that only changed properties are written, each with the\n * rules of {@link setStyleProperty}; properties that disappeared are removed.\n *\n * @param el HTML or SVG element.\n * @param value An object of properties (camelCase, kebab-case or custom names). A string replaces\n * `cssText`. An array of strings and objects (not nested; `null`, `undefined`, `false` and `\"\"`\n * items are skipped) is written in order, so a later declaration wins, exactly as `ssrStyle` writes it\n * on the server. `null`, `undefined` and `false` remove the `style` attribute. Accessors (the value,\n * array items and property values) are called, as on the server.\n * @param prev The value returned by the previous call. Undefined (the first call) diffs against an\n * empty style. When it is a string or an array, `cssText` is cleared before the object is written.\n * @returns What to pass back as `prev` next time: a shallow copy of an object value, otherwise\n * `value` itself.\n * @throws TypeError (production message `SHADOW_STYLE_ITEM`) when an array holds a nested array or a\n * value that is not a string or an object.\n * @example\n * import { style } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"div\");\n * let prev = style(el, { color: \"red\", width: 120 }); // width: 120px\n * prev = style(el, { color: \"blue\" }, prev); // writes color, removes width\n * @see setStyleProperty\n * @since 1.0.0\n */\nexport function style(el: HTMLElement | SVGElement, value: unknown, prev?: unknown): unknown {\n const resolved = unwrap(value);\n if (resolved === null || resolved === undefined || resolved === false) {\n el.removeAttribute(\"style\");\n return resolved;\n }\n if (typeof resolved !== \"object\") {\n el.style.cssText = String(resolved);\n return resolved;\n }\n if (Array.isArray(resolved)) {\n // Not diffed: a string in the array can set any property, so the whole style is written again, in\n // order (a later declaration wins, as on the server).\n el.style.cssText = \"\";\n for (const source of resolved) {\n const item = unwrap(source);\n if (typeof item === \"string\") {\n el.style.cssText += `;${item}`;\n } else if (item !== null && item !== undefined && item !== false) {\n if (typeof item !== \"object\" || Array.isArray(item)) {\n throw new TypeError(\n __DEV__ ? \"style(): an array holds only strings and objects.\" : \"SHADOW_STYLE_ITEM\",\n );\n }\n // A null, undefined or false value declares nothing here, as on the server: `style` would remove\n // the property, which erases what an earlier source of the array wrote.\n const declared: Record<string, unknown> = {};\n for (const key of Object.keys(item)) {\n const part = unwrap((item as Record<string, unknown>)[key]);\n if (part !== null && part !== undefined && part !== false) declared[key] = part;\n }\n style(el, declared, {});\n }\n }\n return resolved;\n }\n const next: Record<string, unknown> = { ...(resolved as Record<string, unknown>) };\n for (const key of Object.keys(next)) next[key] = unwrap(next[key]);\n const before = asRecord(prev) ?? {};\n // What a string or an array wrote is unknown, so it is cleared before the object is written.\n if (typeof prev === \"string\" || Array.isArray(prev)) el.style.cssText = \"\";\n const keys = new Set([...Object.keys(before), ...Object.keys(next)]);\n for (const key of keys) {\n if (Object.is(before[key], next[key])) continue;\n setStyleProperty(el, key, next[key]);\n }\n return next;\n}\n"],"mappings":";;;;;AAKA,SAAS,eAAe,MAAe,OAAuB;CAE5D,KAAK,MAAM,QAAQ,OAAO,MAAM,6CAAK,GACnC,IAAI,OAAO,SAAS,UACd;MAAA,SAAS,IAAI,MAAM,KAAK,IAAI;CAAA,OAC3B,IA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-
import { nextKey } from "../internal/hydration-scope.js";
|
|
4
1
|
import { createComponent } from "../component.js";
|
|
5
|
-
import { claims } from "../internal/hydration-hooks.js";
|
|
6
2
|
import { bindRegion, createRegion } from "../insert.js";
|
|
3
|
+
import { claims } from "../internal/hydration-hooks.js";
|
|
4
|
+
import { MATHML_NS, SVG_NS } from "../internal/names.js";
|
|
5
|
+
import { nextKey } from "../internal/hydration-scope.js";
|
|
6
|
+
import { warnOnce } from "../internal/diagnostics.js";
|
|
7
7
|
import { spreadProps } from "../spread.js";
|
|
8
8
|
import { mergeProps, splitProps, untrack, useMemo } from "@shadow-js/core";
|
|
9
9
|
// src/control-flow/dynamic.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { nextKey } from "../internal/hydration-scope.js";
|
|
2
1
|
import { claims } from "../internal/hydration-hooks.js";
|
|
2
|
+
import { nextKey } from "../internal/hydration-scope.js";
|
|
3
3
|
// src/control-flow/no-hydration.ts
|
|
4
4
|
/** The nodes between `<!--nh:KEY-->` and its `<!--/nh-->` in the lifted regions, or undefined when the server sent none. */
|
|
5
5
|
function findStatic(key, regions) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { bindRegion, createRegion, moveRegion, removeRegion } from "../insert.js";
|
|
1
2
|
import { childScope, nextKey, withScope } from "../internal/hydration-scope.js";
|
|
2
3
|
import { claims } from "../internal/hydration-hooks.js";
|
|
3
|
-
import { bindRegion, createRegion, moveRegion, removeRegion } from "../insert.js";
|
|
4
4
|
import { PortalContext } from "../internal/portal-context.js";
|
|
5
5
|
import { createRoot, getOwner, isServer, onCleanup, runWithOwner, useContext, useRenderEffect } from "@shadow-js/core";
|
|
6
6
|
// src/control-flow/portal.ts
|
package/dist/dev/element.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { setAttribute, setBoolAttribute } from "./attributes.js";
|
|
2
2
|
import { style } from "./class-style.js";
|
|
3
|
-
import {
|
|
3
|
+
import { insert } from "./insert.js";
|
|
4
4
|
import { checkClaimedTag } from "./internal/claim.js";
|
|
5
5
|
import { claims } from "./internal/hydration-hooks.js";
|
|
6
|
-
import {
|
|
6
|
+
import { nextKey } from "./internal/hydration-scope.js";
|
|
7
7
|
import { isFlagAttribute } from "./internal/react-names.js";
|
|
8
8
|
import { batch, untrack, useRenderEffect } from "@shadow-js/core";
|
|
9
9
|
// src/element.ts
|
package/dist/dev/extend.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { warnOnce } from "./internal/diagnostics.js";
|
|
2
1
|
import { isUnsafeUrlAttribute } from "./attributes.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { element } from "./element.js";
|
|
3
|
+
import { bindRegion, createRegion, moveRegion, removeRegion } from "./insert.js";
|
|
5
4
|
import { claimElement, claimPortal, isClaiming, takeRegion, withoutClaiming } from "./internal/claim.js";
|
|
5
|
+
import { warnOnce } from "./internal/diagnostics.js";
|
|
6
6
|
import { claims } from "./internal/hydration-hooks.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { element } from "./element.js";
|
|
7
|
+
import { childScope, createRootScope, currentScope, enterComponent, nextKey, resourceKey, withScope } from "./internal/hydration-scope.js";
|
|
8
|
+
import { HTML_NS, MATHML_NS, SVG_NS } from "./internal/names.js";
|
|
10
9
|
import { PortalContext } from "./internal/portal-context.js";
|
|
10
|
+
import { reconcileNodes } from "./internal/reconcile.js";
|
|
11
11
|
import { StreamContext } from "./internal/stream-context.js";
|
|
12
12
|
export { HTML_NS, MATHML_NS, PortalContext, SVG_NS, StreamContext, bindRegion, childScope, claimElement, claimPortal, claims, createRegion, createRootScope, currentScope, element, enterComponent, isClaiming, isUnsafeUrlAttribute, moveRegion, nextKey, reconcileNodes, removeRegion, resourceKey, takeRegion, warnOnce, withScope, withoutClaiming };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHeadRegistry } from "./registry.js";
|
|
2
|
-
import { normalizeTags } from "./validate.js";
|
|
3
2
|
import { ServerHeadContext } from "./server-head.js";
|
|
4
3
|
import { createDomHeadSink } from "./sink.js";
|
|
4
|
+
import { normalizeTags } from "./validate.js";
|
|
5
5
|
import { createRoot, getOwner, isServer, untrack, useContext, useEffect, useRenderEffect, useSignal } from "@shadow-js/core";
|
|
6
6
|
// src/head/use-head.ts
|
|
7
7
|
/** One registry per document, shared by every `useHead` call on it. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { warnOnce } from "../internal/diagnostics.js";
|
|
2
1
|
import { isUnsafeUrlAttribute } from "../attributes.js";
|
|
2
|
+
import { warnOnce } from "../internal/diagnostics.js";
|
|
3
3
|
// src/head/validate.ts
|
|
4
4
|
/** Marks every element the sink created or adopted. Callers may not supply it. @internal */
|
|
5
5
|
const HEAD_MARKER = "data-shadow-head";
|
package/dist/dev/hydration.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createRootScope, resourceKey, withScope } from "./internal/hydration-scope.js";
|
|
2
|
-
import { beginClaiming, claimElement, claimPortal, endClaiming, isClaiming, liftedRegions, releaseUnclaimedPortals, takeRegion, withoutClaiming } from "./internal/claim.js";
|
|
3
|
-
import { claims } from "./internal/hydration-hooks.js";
|
|
4
|
-
import { bindRegion, createRegion, removeRegion } from "./insert.js";
|
|
5
1
|
import { attachRootErrors } from "./control-flow/root-errors.js";
|
|
2
|
+
import { bindRegion, createRegion, removeRegion } from "./insert.js";
|
|
3
|
+
import { beginClaiming, claimElement, claimPortal, endClaiming, isClaiming, liftedRegions, releaseUnclaimedPortals, takeRegion, withoutClaiming } from "./internal/claim.js";
|
|
6
4
|
import { replayEarlyEvents } from "./internal/early-events.js";
|
|
5
|
+
import { claims } from "./internal/hydration-hooks.js";
|
|
6
|
+
import { createRootScope, resourceKey, withScope } from "./internal/hydration-scope.js";
|
|
7
7
|
import { ResourceCacheContext, batch, createRoot, flushSync, runWithOwner, untrack } from "@shadow-js/core";
|
|
8
8
|
import { withHydration } from "@shadow-js/core/extend";
|
|
9
9
|
// src/hydration.ts
|
|
@@ -87,8 +87,16 @@ function hydrate(code, container, options = {}) {
|
|
|
87
87
|
const cache = dataCache(options.data ?? {});
|
|
88
88
|
const region = createRegion(container, null, Array.from(container.childNodes));
|
|
89
89
|
let stop;
|
|
90
|
+
let disposed = false;
|
|
91
|
+
const teardown = () => {
|
|
92
|
+
if (disposed) return;
|
|
93
|
+
disposed = true;
|
|
94
|
+
stop?.();
|
|
95
|
+
removeRegion(region);
|
|
96
|
+
};
|
|
90
97
|
try {
|
|
91
|
-
|
|
98
|
+
withHydration(() => batch(() => withScope(createRootScope(options.renderId), () => runWithOwner(options.owner ?? null, () => createRoot((dispose) => {
|
|
99
|
+
stop = dispose;
|
|
92
100
|
attachRootErrors(options);
|
|
93
101
|
ResourceCacheContext({
|
|
94
102
|
value: cache,
|
|
@@ -97,22 +105,22 @@ function hydrate(code, container, options = {}) {
|
|
|
97
105
|
return null;
|
|
98
106
|
}
|
|
99
107
|
});
|
|
100
|
-
return dispose;
|
|
101
108
|
})))));
|
|
102
109
|
flushSync();
|
|
110
|
+
} catch (error) {
|
|
111
|
+
try {
|
|
112
|
+
stop?.();
|
|
113
|
+
} catch (cleanupError) {
|
|
114
|
+
throw new AggregateError([error, cleanupError], "hydrate() failed and so did its teardown.");
|
|
115
|
+
}
|
|
116
|
+
throw error;
|
|
103
117
|
} finally {
|
|
104
118
|
endClaiming();
|
|
105
119
|
claims.current = previousClaims;
|
|
106
120
|
}
|
|
107
121
|
replayEarlyEvents();
|
|
108
122
|
stripLeftovers(container);
|
|
109
|
-
|
|
110
|
-
return () => {
|
|
111
|
-
if (disposed) return;
|
|
112
|
-
disposed = true;
|
|
113
|
-
stop();
|
|
114
|
-
removeRegion(region);
|
|
115
|
-
};
|
|
123
|
+
return teardown;
|
|
116
124
|
}
|
|
117
125
|
export { hydrate };
|
|
118
126
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydration.js","names":[],"sources":["../../src/hydration.ts"],"sourcesContent":["import {\n batch,\n createRoot,\n flushSync,\n type Owner,\n type ResourceCache,\n ResourceCacheContext,\n runWithOwner,\n untrack,\n} from \"@shadow-js/core\";\nimport { withHydration } from \"@shadow-js/core/extend\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport {\n beginClaiming,\n claimElement,\n claimPortal,\n endClaiming,\n isClaiming,\n liftedRegions,\n releaseUnclaimedPortals,\n takeRegion,\n withoutClaiming,\n} from \"./internal/claim\";\nimport { replayEarlyEvents } from \"./internal/early-events\";\nimport { type Claims, claims } from \"./internal/hydration-hooks\";\nimport { createRootScope, resourceKey, withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link hydrate}: the server render it continues, the root's owner, and the error\n * reporters it inherits from `RootErrorOptions` (`onUncaughtError`, `onCaughtError`,\n * `onRecoverableError`).\n * @since 1.0.0\n */\nexport interface HydrateOptions extends RootErrorOptions {\n /**\n * The id the server render used, so the client numbers its elements with the same keys. Must\n * equal the `renderId` given to the server render.\n * @default \"0\"\n */\n renderId?: string;\n /**\n * The resource values the server fetched: the `data` of `renderToStringAsync`. A resource whose\n * key is found here starts with that value instead of fetching it again. Each value is used once.\n * @default {} (no resource value is preloaded; resources fetch on the client)\n */\n data?: Record<string, unknown>;\n /**\n * The owner the hydrated root is created under, so its context (providers) is visible to the app.\n * @default null (the root has no parent owner)\n */\n owner?: Owner;\n}\n\nfunction dataCache(data: Record<string, unknown>): ResourceCache {\n const used = new Set<string>();\n return {\n key: resourceKey,\n read(key) {\n if (used.has(key) || !Object.hasOwn(data, key)) return undefined;\n used.add(key);\n return { value: data[key] };\n },\n track() {\n // Client fetches are not tracked: nothing waits for them.\n },\n };\n}\n\n/**\n * Removes marker comments the pass did not claim, so the live DOM never keeps any, and the server\n * blocks of portals the client did not render (they would show content the client does not have).\n */\nfunction stripLeftovers(container: Node): void {\n const doc = container instanceof Document ? container : container.ownerDocument;\n if (doc === null) return;\n if (doc.body !== null) releaseUnclaimedPortals(doc.body);\n const walker = doc.createTreeWalker(container, NodeFilter.SHOW_COMMENT);\n const stale: Comment[] = [];\n while (walker.nextNode()) {\n const comment = walker.currentNode as Comment;\n if (comment.data === \"[\" || comment.data === \"]\") stale.push(comment);\n }\n for (const comment of stale) comment.remove();\n}\n\n/**\n * Attaches the application to HTML the server already rendered into `container`. Elements are\n * claimed by their `data-hk` keys instead of created, so the DOM is not rebuilt and nodes keep\n * their identity. Event handlers and reactive bindings are attached; markers are removed. Parts the\n * server and client disagree on are repaired by reconciliation, never left half hydrated.\n *\n * @param code Runs once, untracked, and builds the same component tree the server rendered.\n * @param container Element or Document that holds the server markup.\n * @param options `renderId` (must match the server), the server's resource `data`, an `owner`, and\n * the error reporters. Undefined uses the defaults.\n * @returns A dispose function that stops the hydrated root and removes its nodes. Safe to call more\n * than once.\n * @throws Error (production message `SHADOW_HYDRATE_RUNNING`) when called while another hydration\n * pass is in progress.\n * @example\n * import { createComponent, hydrate } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const container = document.getElementById(\"app\") as Element;\n * const data = JSON.parse(document.getElementById(\"data\")?.textContent ?? \"{}\") as Record<\n * string,\n * unknown\n * >;\n * const dispose = hydrate(() => createComponent(App, {}), container, { data });\n * @see render\n * @since 1.0.0\n */\nexport function hydrate(\n code: () => unknown,\n container: Element | Document,\n options: HydrateOptions = {},\n): () => void {\n if (isClaiming())\n throw new Error(\n __DEV__ ? \"hydrate(): a hydration pass is already running.\" : \"SHADOW_HYDRATE_RUNNING\",\n );\n const registry = new Map<string, Element>();\n const roots: Element[] = container instanceof Element ? [container] : [];\n for (const element of [...roots, ...Array.from(container.querySelectorAll(\"[data-hk]\"))]) {\n const key = element.getAttribute(\"data-hk\");\n if (key !== null) registry.set(key, element);\n }\n beginClaiming(registry, options.onRecoverableError);\n // The renderer reaches the claiming code only through this hook, installed for this pass alone.\n const passClaims: Claims = {\n claimElement,\n takeRegion,\n liftedRegions,\n claimPortal,\n isClaiming,\n withoutClaiming,\n };\n const previousClaims = claims.current;\n claims.current = passClaims;\n const cache = dataCache(options.data ?? {});\n const region = createRegion(container, null, Array.from(container.childNodes));\n let stop: () => void;\n try {\n // The batch wraps the scope, not the other way round: its exit flushes the queued effects\n // (onMount, and the re-renders they cause) after the scope is restored. The scope numbers only\n // the templates the server rendered; an effect that builds new DOM must not draw keys from it\n // (that shifts the keys of later siblings and misses the ones the server never sent). Boundaries\n // rebuild from their own captured scope, so a reset inside the pass still claims its elements.\n
|
|
1
|
+
{"version":3,"file":"hydration.js","names":[],"sources":["../../src/hydration.ts"],"sourcesContent":["import {\n batch,\n createRoot,\n flushSync,\n type Owner,\n type ResourceCache,\n ResourceCacheContext,\n runWithOwner,\n untrack,\n} from \"@shadow-js/core\";\nimport { withHydration } from \"@shadow-js/core/extend\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport {\n beginClaiming,\n claimElement,\n claimPortal,\n endClaiming,\n isClaiming,\n liftedRegions,\n releaseUnclaimedPortals,\n takeRegion,\n withoutClaiming,\n} from \"./internal/claim\";\nimport { replayEarlyEvents } from \"./internal/early-events\";\nimport { type Claims, claims } from \"./internal/hydration-hooks\";\nimport { createRootScope, resourceKey, withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link hydrate}: the server render it continues, the root's owner, and the error\n * reporters it inherits from `RootErrorOptions` (`onUncaughtError`, `onCaughtError`,\n * `onRecoverableError`).\n * @since 1.0.0\n */\nexport interface HydrateOptions extends RootErrorOptions {\n /**\n * The id the server render used, so the client numbers its elements with the same keys. Must\n * equal the `renderId` given to the server render.\n * @default \"0\"\n */\n renderId?: string;\n /**\n * The resource values the server fetched: the `data` of `renderToStringAsync`. A resource whose\n * key is found here starts with that value instead of fetching it again. Each value is used once.\n * @default {} (no resource value is preloaded; resources fetch on the client)\n */\n data?: Record<string, unknown>;\n /**\n * The owner the hydrated root is created under, so its context (providers) is visible to the app.\n * @default null (the root has no parent owner)\n */\n owner?: Owner;\n}\n\nfunction dataCache(data: Record<string, unknown>): ResourceCache {\n const used = new Set<string>();\n return {\n key: resourceKey,\n read(key) {\n if (used.has(key) || !Object.hasOwn(data, key)) return undefined;\n used.add(key);\n return { value: data[key] };\n },\n track() {\n // Client fetches are not tracked: nothing waits for them.\n },\n };\n}\n\n/**\n * Removes marker comments the pass did not claim, so the live DOM never keeps any, and the server\n * blocks of portals the client did not render (they would show content the client does not have).\n */\nfunction stripLeftovers(container: Node): void {\n const doc = container instanceof Document ? container : container.ownerDocument;\n if (doc === null) return;\n if (doc.body !== null) releaseUnclaimedPortals(doc.body);\n const walker = doc.createTreeWalker(container, NodeFilter.SHOW_COMMENT);\n const stale: Comment[] = [];\n while (walker.nextNode()) {\n const comment = walker.currentNode as Comment;\n if (comment.data === \"[\" || comment.data === \"]\") stale.push(comment);\n }\n for (const comment of stale) comment.remove();\n}\n\n/**\n * Attaches the application to HTML the server already rendered into `container`. Elements are\n * claimed by their `data-hk` keys instead of created, so the DOM is not rebuilt and nodes keep\n * their identity. Event handlers and reactive bindings are attached; markers are removed. Parts the\n * server and client disagree on are repaired by reconciliation, never left half hydrated.\n *\n * @param code Runs once, untracked, and builds the same component tree the server rendered.\n * @param container Element or Document that holds the server markup.\n * @param options `renderId` (must match the server), the server's resource `data`, an `owner`, and\n * the error reporters. Undefined uses the defaults.\n * @returns A dispose function that stops the hydrated root and removes its nodes. Safe to call more\n * than once.\n * @throws Error (production message `SHADOW_HYDRATE_RUNNING`) when called while another hydration\n * pass is in progress.\n * @example\n * import { createComponent, hydrate } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const container = document.getElementById(\"app\") as Element;\n * const data = JSON.parse(document.getElementById(\"data\")?.textContent ?? \"{}\") as Record<\n * string,\n * unknown\n * >;\n * const dispose = hydrate(() => createComponent(App, {}), container, { data });\n * @see render\n * @since 1.0.0\n */\nexport function hydrate(\n code: () => unknown,\n container: Element | Document,\n options: HydrateOptions = {},\n): () => void {\n if (isClaiming())\n throw new Error(\n __DEV__ ? \"hydrate(): a hydration pass is already running.\" : \"SHADOW_HYDRATE_RUNNING\",\n );\n const registry = new Map<string, Element>();\n const roots: Element[] = container instanceof Element ? [container] : [];\n for (const element of [...roots, ...Array.from(container.querySelectorAll(\"[data-hk]\"))]) {\n const key = element.getAttribute(\"data-hk\");\n if (key !== null) registry.set(key, element);\n }\n beginClaiming(registry, options.onRecoverableError);\n // The renderer reaches the claiming code only through this hook, installed for this pass alone.\n const passClaims: Claims = {\n claimElement,\n takeRegion,\n liftedRegions,\n claimPortal,\n isClaiming,\n withoutClaiming,\n };\n const previousClaims = claims.current;\n claims.current = passClaims;\n const cache = dataCache(options.data ?? {});\n const region = createRegion(container, null, Array.from(container.childNodes));\n let stop: (() => void) | undefined;\n let disposed = false;\n const teardown = (): void => {\n if (disposed) return;\n disposed = true;\n stop?.();\n removeRegion(region);\n };\n try {\n // The batch wraps the scope, not the other way round: its exit flushes the queued effects\n // (onMount, and the re-renders they cause) after the scope is restored. The scope numbers only\n // the templates the server rendered; an effect that builds new DOM must not draw keys from it\n // (that shifts the keys of later siblings and misses the ones the server never sent). Boundaries\n // rebuild from their own captured scope, so a reset inside the pass still claims its elements.\n withHydration(() =>\n batch(() =>\n withScope(createRootScope(options.renderId), () =>\n runWithOwner(options.owner ?? null, () =>\n createRoot((dispose) => {\n stop = dispose;\n attachRootErrors(options);\n ResourceCacheContext({\n value: cache,\n get children() {\n bindRegion(region, untrack(code));\n return null;\n },\n });\n }),\n ),\n ),\n ),\n );\n flushSync();\n } catch (error) {\n // The caller gets no dispose function from a hydration that throws, so the root must not stay alive. Its\n // effects and listeners go; the server's markup stays, so the page keeps what the server rendered.\n try {\n stop?.();\n } catch (cleanupError) {\n throw new AggregateError(\n [error, cleanupError],\n __DEV__ ? \"hydrate() failed and so did its teardown.\" : \"SHADOW_HYDRATE_ERRORS\",\n );\n }\n throw error;\n } finally {\n endClaiming();\n claims.current = previousClaims;\n }\n replayEarlyEvents();\n stripLeftovers(container);\n return teardown;\n}\n"],"mappings":";;;;;;;;;AAsDA,SAAS,UAAU,MAA8C;CAC/D,MAAM,uBAAO,IAAI,IAAY;CAC7B,OAAO;EACL,KAAK;EACL,KAAK,KAAK;GACR,IAAI,KAAK,IAAI,GAAG,KAAK,CAAC,OAAO,OAAO,MAAM,GAAG,GAAG,OAAO,KAAA;GACvD,KAAK,IAAI,GAAG;GACZ,OAAO,EAAE,OAAO,KAAK,KAAK;EAC5B;EACA,QAAQ,CAER;CACF;AACF;;;;;AAMA,SAAS,eAAe,WAAuB;CAC7C,MAAM,MAAM,qBAAqB,WAAW,YAAY,UAAU;CAClE,IAAI,QAAQ,MAAM;CAClB,IAAI,IAAI,SAAS,MAAM,wBAAwB,IAAI,IAAI;CACvD,MAAM,SAAS,IAAI,iBAAiB,WAAW,WAAW,YAAY;CACtE,MAAM,QAAmB,CAAC;CAC1B,OAAO,OAAO,SAAS,GAAG;EACxB,MAAM,UAAU,OAAO;EACvB,IAAI,QAAQ,SAAS,OAAO,QAAQ,SAAS,KAAK,MAAM,KAAK,OAAO;CACtE;CACA,KAAK,MAAM,WAAW,OAAO,QAAQ,OAAO;AAC9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,QACd,MACA,WACA,UAA0B,CAAC,GACf;CACZ,IAAI,WAAW,GACb,MAAM,IAAI,MACE,iDACZ;CACF,MAAM,2BAAW,IAAI,IAAqB;CAC1C,MAAM,QAAmB,qBAAqB,UAAU,CAAC,SAAS,IAAI,CAAC;CACvE,KAAK,MAAM,WAAW,CAAC,GAAG,OAAO,GAAG,MAAM,KAAK,UAAU,iBAAiB,WAAW,CAAC,CAAC,GAAG;EACxF,MAAM,MAAM,QAAQ,aAAa,SAAS;EAC1C,IAAI,QAAQ,MAAM,SAAS,IAAI,KAAK,OAAO;CAC7C;CACA,cAAc,UAAU,QAAQ,kBAAkB;CAElD,MAAM,aAAqB;EACzB;EACA;EACA;EACA;EACA;EACA;CACF;CACA,MAAM,iBAAiB,OAAO;CAC9B,OAAO,UAAU;CACjB,MAAM,QAAQ,UAAU,QAAQ,QAAQ,CAAC,CAAC;CAC1C,MAAM,SAAS,aAAa,WAAW,MAAM,MAAM,KAAK,UAAU,UAAU,CAAC;CAC7E,IAAI;CACJ,IAAI,WAAW;CACf,MAAM,iBAAuB;EAC3B,IAAI,UAAU;EACd,WAAW;EACX,OAAO;EACP,aAAa,MAAM;CACrB;CACA,IAAI;EAMF,oBACE,YACE,UAAU,gBAAgB,QAAQ,QAAQ,SACxC,aAAa,QAAQ,SAAS,YAC5B,YAAY,YAAY;GACtB,OAAO;GACP,iBAAiB,OAAO;GACxB,qBAAqB;IACnB,OAAO;IACP,IAAI,WAAW;KACb,WAAW,QAAQ,QAAQ,IAAI,CAAC;KAChC,OAAO;IACT;GACF,CAAC;EACH,CAAC,CACH,CACF,CACF,CACF;EACA,UAAU;CACZ,SAAS,OAAO;EAGd,IAAI;GACF,OAAO;EACT,SAAS,cAAc;GACrB,MAAM,IAAI,eACR,CAAC,OAAO,YAAY,GACV,2CACZ;EACF;EACA,MAAM;CACR,UAAU;EACR,YAAY;EACZ,OAAO,UAAU;CACnB;CACA,kBAAkB;CAClB,eAAe,SAAS;CACxB,OAAO;AACT"}
|
package/dist/dev/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { setAttribute, setAttributeNS, setBoolAttribute } from "./attributes.js";
|
|
2
|
-
import { element } from "./element.js";
|
|
3
|
-
import { anchor, insert } from "./insert.js";
|
|
4
2
|
import { autoFocus } from "./autofocus.js";
|
|
5
3
|
import { classList, className, setStyleProperty, style } from "./class-style.js";
|
|
6
4
|
import { createComponent } from "./component.js";
|
|
5
|
+
import "./control-flow/index.js";
|
|
6
|
+
import { Derived, derived } from "./derived.js";
|
|
7
7
|
import { Activity, ActivityMode, ActivityProps } from "./control-flow/activity.js";
|
|
8
8
|
import { Booleanish, CSSProperties, ClassValue, JsxChild, Maybe, MaybeAccessor, Ref, TextChild } from "./jsx/types.js";
|
|
9
9
|
import { ClientOnly, ClientOnlyProps } from "./control-flow/client-only.js";
|
|
@@ -19,13 +19,13 @@ import { Show, ShowLooseProps, ShowProps } from "./control-flow/show.js";
|
|
|
19
19
|
import { Suspense, SuspenseProps } from "./control-flow/suspense.js";
|
|
20
20
|
import { SuspenseList, SuspenseListProps } from "./control-flow/suspense-list.js";
|
|
21
21
|
import { Match, MatchProps, Switch, SwitchProps } from "./control-flow/switch.js";
|
|
22
|
-
import "./
|
|
23
|
-
import { Derived, derived } from "./derived.js";
|
|
22
|
+
import { element } from "./element.js";
|
|
24
23
|
import { addEventListener, chainEvents, clearDelegatedEvents, delegateEvents } from "./events.js";
|
|
24
|
+
import { HydrateOptions, hydrate } from "./hydration.js";
|
|
25
25
|
import { Base, HeadAttributeProps, Link, Meta, Style, StyleProps, Title, TitleProps } from "./head/components.js";
|
|
26
26
|
import { HeadAttributeValue, HeadInput, HeadTag, HeadTagName } from "./head/validate.js";
|
|
27
27
|
import { useHead } from "./head/use-head.js";
|
|
28
|
-
import {
|
|
28
|
+
import { anchor, insert } from "./insert.js";
|
|
29
29
|
import { Component, FlowComponent, ParentComponent, ParentProps, VoidComponent, VoidProps } from "./jsx/component.js";
|
|
30
30
|
import { BoundEventHandler, EventHandler, EventHandlerProp, ListenerObject } from "./jsx/events.js";
|
|
31
31
|
import { AriaAttributes, AriaRole } from "./jsx/aria.js";
|
package/dist/dev/index.js
CHANGED
|
@@ -5,11 +5,11 @@ import { createComponent } from "./component.js";
|
|
|
5
5
|
import { Activity } from "./control-flow/activity.js";
|
|
6
6
|
import { Show } from "./control-flow/show.js";
|
|
7
7
|
import { ClientOnly } from "./control-flow/client-only.js";
|
|
8
|
-
import {
|
|
8
|
+
import { derived } from "./derived.js";
|
|
9
9
|
import { element } from "./element.js";
|
|
10
10
|
import { addEventListener, chainEvents, clearDelegatedEvents, delegateEvents } from "./events.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { hydrate } from "./hydration.js";
|
|
12
|
+
import { anchor, insert } from "./insert.js";
|
|
13
13
|
import { Dynamic, createDynamic } from "./control-flow/dynamic.js";
|
|
14
14
|
import { ErrorBoundary } from "./control-flow/error-boundary.js";
|
|
15
15
|
import { For } from "./control-flow/for.js";
|
|
@@ -21,13 +21,13 @@ import { Portal } from "./control-flow/portal.js";
|
|
|
21
21
|
import { SuspenseList } from "./control-flow/suspense-list.js";
|
|
22
22
|
import { Suspense } from "./control-flow/suspense.js";
|
|
23
23
|
import { Match, Switch } from "./control-flow/switch.js";
|
|
24
|
-
import {
|
|
24
|
+
import { effect, memo, refTo, use } from "./reactive.js";
|
|
25
25
|
import { useHead } from "./head/use-head.js";
|
|
26
26
|
import { Base, Link, Meta, Style, Title } from "./head/components.js";
|
|
27
|
-
import { hydrate } from "./hydration.js";
|
|
28
|
-
import { effect, memo, refTo, use } from "./reactive.js";
|
|
29
27
|
import { render } from "./render.js";
|
|
30
28
|
import { preconnect, prefetchDNS, preinit, preinitModule, preload, preloadModule } from "./resource-hints.js";
|
|
29
|
+
import { setSelectValue } from "./select-value.js";
|
|
30
|
+
import { spread } from "./spread.js";
|
|
31
31
|
import { template } from "./template.js";
|
|
32
32
|
import { ViewTransition, startViewTransition } from "./view-transition.js";
|
|
33
33
|
import { isDev, isServer, mergeProps } from "@shadow-js/core";
|
package/dist/dev/jsx/global.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Booleanish, CSSProperties, CSSPropertyValue, ClassValue, JsxChild, Maybe, Ref, TextChild } from "./types.js";
|
|
2
|
-
import { EventAttributes, MediaEventAttributes, VideoEventAttributes, WindowEventAttributes } from "./events.js";
|
|
3
1
|
import { AriaAttributes } from "./aria.js";
|
|
2
|
+
import { EventAttributes, MediaEventAttributes, VideoEventAttributes, WindowEventAttributes } from "./events.js";
|
|
3
|
+
import { Booleanish, CSSProperties, CSSPropertyValue, ClassValue, JsxChild, Maybe, Ref, TextChild } from "./types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Values accepted by `data-*` attributes. `true` and `false` are written as the strings "true" and
|
|
6
6
|
* "false", so they are not presence flags.
|
package/dist/dev/jsx/html.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LooseString, Maybe } from "./types.js";
|
|
2
1
|
import { Aliases, ElementProps, MediaElementProps, TextElementProps, VideoElementProps, VoidElementProps, WindowElementProps } from "./global.js";
|
|
2
|
+
import { LooseString, Maybe } from "./types.js";
|
|
3
3
|
/** Targets of links and forms. Any other browsing-context name is also accepted. @since 1.0.0 */
|
|
4
4
|
export type LinkTarget = LooseString<"_self" | "_blank" | "_parent" | "_top">;
|
|
5
5
|
/** Referrer policies, as in the HTML standard. @since 1.0.0 */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { JsxChild, MathMLTagElement, Maybe } from "./types.js";
|
|
2
1
|
import { Aliases, ElementProps, GlobalAttributes, TextElementProps } from "./global.js";
|
|
3
2
|
import { AnchorAttributes, HTMLIntrinsicElements, ScriptAttributes, StyleElementAttributes } from "./html.js";
|
|
4
3
|
import { MathMLGlobalAttributes, MathMLIntrinsicElements } from "./mathml.js";
|
|
5
4
|
import { SVGAnchorAttributes, SVGCoreAttributes, SVGHrefAttributes, SVGIntrinsicElements, SVGPresentationAttributes, SVGReactPresentationAttributes } from "./svg.js";
|
|
5
|
+
import { JsxChild, MathMLTagElement, Maybe } from "./types.js";
|
|
6
6
|
/** The DOM element a shared `a` may be. @internal */
|
|
7
7
|
type AnchorElement = HTMLElementTagNameMap["a"] | SVGElementTagNameMap["a"] | MathMLTagElement<"a">;
|
|
8
8
|
/** The DOM element a shared `script` may be. @internal */
|
package/dist/dev/jsx/mathml.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Booleanish, MathMLTagElement, Maybe } from "./types.js";
|
|
2
1
|
import { ElementProps, VoidElementProps } from "./global.js";
|
|
2
|
+
import { Booleanish, MathMLTagElement, Maybe } from "./types.js";
|
|
3
3
|
/** A MathML length or unitless number, e.g. `"2em"`, `"thin"`, `3`. @since 1.0.0 */
|
|
4
4
|
export type MathValue = Maybe<number | string>;
|
|
5
5
|
/** The `mathvariant` presentation values. @since 1.0.0 */
|
package/dist/dev/jsx/svg.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LooseString, Maybe } from "./types.js";
|
|
2
1
|
import { ElementProps, TextElementProps, VoidElementProps, WindowElementProps } from "./global.js";
|
|
2
|
+
import { LooseString, Maybe } from "./types.js";
|
|
3
3
|
/** A length, coordinate, or other SVG number. Plain numbers are user units. @since 1.0.0 */
|
|
4
4
|
export type SvgValue = Maybe<number | string>;
|
|
5
5
|
/** Coordinate-system units of gradients, patterns, clip paths and masks. @since 1.0.0 */
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Booleanish, CSSProperties, ClassValue, JsxChild, Maybe, MaybeAccessor, Ref, RefOf, TextChild } from "./jsx/types.js";
|
|
2
1
|
import { Component, FlowComponent, ParentComponent, ParentProps, VoidComponent, VoidProps } from "./jsx/component.js";
|
|
3
2
|
import { BoundEventHandler, CustomEventProps, EventHandler, EventHandlerProp, ListenerObject } from "./jsx/events.js";
|
|
4
|
-
import { AriaAttributes, AriaRole } from "./jsx/aria.js";
|
|
5
3
|
import { DirectiveProps } from "./jsx/global.js";
|
|
4
|
+
import { AriaAttributes, AriaRole } from "./jsx/aria.js";
|
|
5
|
+
import { CustomElementProps, IntrinsicElementMap } from "./jsx/intrinsic.js";
|
|
6
6
|
import { HTMLIntrinsicElements } from "./jsx/html.js";
|
|
7
7
|
import { MathMLIntrinsicElements } from "./jsx/mathml.js";
|
|
8
8
|
import { SVGIntrinsicElements } from "./jsx/svg.js";
|
|
9
|
-
import {
|
|
9
|
+
import { Booleanish, CSSProperties, ClassValue, JsxChild, Maybe, MaybeAccessor, Ref, RefOf, TextChild } from "./jsx/types.js";
|
|
10
10
|
/**
|
|
11
11
|
* The app's custom events, by name, for the `on:` and `oncapture:` prefixes: declaration-merge it so
|
|
12
12
|
* `on:toast={...}` receives a typed event. Empty by default; a name without an entry is not accepted
|
package/dist/dev/render.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { withScope } from "./internal/hydration-scope.js";
|
|
2
|
-
import { claims } from "./internal/hydration-hooks.js";
|
|
3
|
-
import { bindRegion, createRegion, removeRegion } from "./insert.js";
|
|
4
1
|
import { attachRootErrors } from "./control-flow/root-errors.js";
|
|
2
|
+
import { bindRegion, createRegion, removeRegion } from "./insert.js";
|
|
3
|
+
import { claims } from "./internal/hydration-hooks.js";
|
|
4
|
+
import { withScope } from "./internal/hydration-scope.js";
|
|
5
5
|
import { batch, createRoot, flushSync, untrack } from "@shadow-js/core";
|
|
6
6
|
// src/render.ts
|
|
7
7
|
/**
|
|
@@ -32,19 +32,30 @@ import { batch, createRoot, flushSync, untrack } from "@shadow-js/core";
|
|
|
32
32
|
*/
|
|
33
33
|
function render(code, container, options) {
|
|
34
34
|
const region = createRegion(container, null, void 0);
|
|
35
|
-
|
|
36
|
-
if (options !== void 0) attachRootErrors(options);
|
|
37
|
-
bindRegion(region, untrack(code));
|
|
38
|
-
return dispose;
|
|
39
|
-
}))));
|
|
40
|
-
flushSync();
|
|
35
|
+
let stop;
|
|
41
36
|
let disposed = false;
|
|
42
|
-
|
|
37
|
+
const teardown = () => {
|
|
43
38
|
if (disposed) return;
|
|
44
39
|
disposed = true;
|
|
45
|
-
stop();
|
|
40
|
+
stop?.();
|
|
46
41
|
removeRegion(region);
|
|
47
42
|
};
|
|
43
|
+
try {
|
|
44
|
+
claims.current.withoutClaiming(() => withScope(null, () => batch(() => createRoot((dispose) => {
|
|
45
|
+
stop = dispose;
|
|
46
|
+
if (options !== void 0) attachRootErrors(options);
|
|
47
|
+
bindRegion(region, untrack(code));
|
|
48
|
+
}))));
|
|
49
|
+
flushSync();
|
|
50
|
+
} catch (error) {
|
|
51
|
+
try {
|
|
52
|
+
teardown();
|
|
53
|
+
} catch (cleanupError) {
|
|
54
|
+
throw new AggregateError([error, cleanupError], "render() failed and so did its teardown.");
|
|
55
|
+
}
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
return teardown;
|
|
48
59
|
}
|
|
49
60
|
export { render };
|
|
50
61
|
|
package/dist/dev/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","names":[],"sources":["../../src/render.ts"],"sourcesContent":["import { batch, createRoot, flushSync, untrack } from \"@shadow-js/core\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link render}: the error reporters of the root.\n * @since 1.0.0\n */\nexport type RenderOptions = RootErrorOptions;\n\n/**\n * Mounts `code` into `container`. Creates an owner, inserts the output, flushes the effects, and\n * returns a dispose function that stops the owner and removes the nodes this call inserted. A\n * second render into the same container appends after the first.\n *\n * @param code Runs once, untracked, to build the tree (a component call, a node, text or an array).\n * Return an accessor (for example `() => count`) from it to make the root content reactive.\n * @param container Element, Document or DocumentFragment that receives the output.\n * @param options The root's error reporters (`onUncaughtError`, `onCaughtError`). Undefined sets\n * no reporter.\n * @returns A dispose function, safe to call more than once.\n * @example\n * import { createComponent, render } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const dispose = render(\n * () => createComponent(App, {}),\n * document.getElementById(\"root\") as Element,\n * );\n * dispose(); // stops the root and removes the text it inserted\n * @see hydrate\n * @since 1.0.0\n */\nexport function render(\n code: () => unknown,\n container: Element | Document | DocumentFragment,\n options?: RenderOptions,\n): () => void {\n const region = createRegion(container, null, undefined);\n // One batch around the build: effects (and anything a resource's batch would flush mid-build)\n // wait until the whole tree exists, so a Suspense boundary knows what is pending before its\n // content's effects are considered.\n // A fresh root never consumes the enclosing hydration pass's nodes or key sequence.\n
|
|
1
|
+
{"version":3,"file":"render.js","names":[],"sources":["../../src/render.ts"],"sourcesContent":["import { batch, createRoot, flushSync, untrack } from \"@shadow-js/core\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link render}: the error reporters of the root.\n * @since 1.0.0\n */\nexport type RenderOptions = RootErrorOptions;\n\n/**\n * Mounts `code` into `container`. Creates an owner, inserts the output, flushes the effects, and\n * returns a dispose function that stops the owner and removes the nodes this call inserted. A\n * second render into the same container appends after the first.\n *\n * @param code Runs once, untracked, to build the tree (a component call, a node, text or an array).\n * Return an accessor (for example `() => count`) from it to make the root content reactive.\n * @param container Element, Document or DocumentFragment that receives the output.\n * @param options The root's error reporters (`onUncaughtError`, `onCaughtError`). Undefined sets\n * no reporter.\n * @returns A dispose function, safe to call more than once.\n * @example\n * import { createComponent, render } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const dispose = render(\n * () => createComponent(App, {}),\n * document.getElementById(\"root\") as Element,\n * );\n * dispose(); // stops the root and removes the text it inserted\n * @see hydrate\n * @since 1.0.0\n */\nexport function render(\n code: () => unknown,\n container: Element | Document | DocumentFragment,\n options?: RenderOptions,\n): () => void {\n const region = createRegion(container, null, undefined);\n let stop: (() => void) | undefined;\n let disposed = false;\n const teardown = (): void => {\n if (disposed) return;\n disposed = true;\n stop?.();\n removeRegion(region);\n };\n // One batch around the build: effects (and anything a resource's batch would flush mid-build)\n // wait until the whole tree exists, so a Suspense boundary knows what is pending before its\n // content's effects are considered.\n // A fresh root never consumes the enclosing hydration pass's nodes or key sequence.\n try {\n claims.current.withoutClaiming(() =>\n withScope(null, () =>\n batch(() =>\n createRoot((dispose) => {\n stop = dispose;\n // An error nothing else took ends here; with onUncaughtError it is reported instead of thrown.\n if (options !== undefined) attachRootErrors(options);\n // The component tree is built once; only accessors inside the result stay reactive.\n bindRegion(region, untrack(code));\n }),\n ),\n ),\n );\n flushSync();\n } catch (error) {\n // The caller gets no dispose function from a render that throws (an effect of the first flush failed),\n // so the root must not stay alive with its DOM and effects.\n try {\n teardown();\n } catch (cleanupError) {\n throw new AggregateError(\n [error, cleanupError],\n __DEV__ ? \"render() failed and so did its teardown.\" : \"SHADOW_RENDER_ERRORS\",\n );\n }\n throw error;\n }\n return teardown;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,OACd,MACA,WACA,SACY;CACZ,MAAM,SAAS,aAAa,WAAW,MAAM,KAAA,CAAS;CACtD,IAAI;CACJ,IAAI,WAAW;CACf,MAAM,iBAAuB;EAC3B,IAAI,UAAU;EACd,WAAW;EACX,OAAO;EACP,aAAa,MAAM;CACrB;CAKA,IAAI;EACF,OAAO,QAAQ,sBACb,UAAU,YACR,YACE,YAAY,YAAY;GACtB,OAAO;GAEP,IAAI,YAAY,KAAA,GAAW,iBAAiB,OAAO;GAEnD,WAAW,QAAQ,QAAQ,IAAI,CAAC;EAClC,CAAC,CACH,CACF,CACF;EACA,UAAU;CACZ,SAAS,OAAO;EAGd,IAAI;GACF,SAAS;EACX,SAAS,cAAc;GACrB,MAAM,IAAI,eACR,CAAC,OAAO,YAAY,GACV,0CACZ;EACF;EACA,MAAM;CACR;CACA,OAAO;AACT"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cssValueText } from "../internal/css-units.js";
|
|
2
2
|
import { invalid } from "./errors.js";
|
|
3
|
-
import { isSsrNode } from "./node.js";
|
|
4
3
|
import { escapeHtml, resolveValue } from "./escape.js";
|
|
4
|
+
import { isSsrNode } from "./node.js";
|
|
5
5
|
// src/server/class-style.ts
|
|
6
6
|
/** A CSS property name: a custom property, or a lower-case name with an optional vendor dash. */
|
|
7
7
|
const CSS_PROPERTY = /^(--[A-Za-z0-9_-]+|-?[a-z][a-z0-9-]*)$/;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { nextKey } from "../internal/hydration-scope.js";
|
|
2
2
|
import { IGNORED_KEYS, attributeName, isFlagAttribute } from "../internal/react-names.js";
|
|
3
|
-
import { invalid } from "./errors.js";
|
|
4
|
-
import { SsrNode, isSsrNode } from "./node.js";
|
|
5
|
-
import { escape, escapeHtml, resolveValue } from "./escape.js";
|
|
6
3
|
import { isEventName, ssrAttribute } from "./attributes.js";
|
|
7
4
|
import { classText, ssrStyle, styleText } from "./class-style.js";
|
|
5
|
+
import { invalid } from "./errors.js";
|
|
6
|
+
import { escape, escapeHtml, resolveValue } from "./escape.js";
|
|
8
7
|
import { keepLeadingNewline, markSelectedOptions, textareaContent } from "./form-controls.js";
|
|
8
|
+
import { SsrNode, isSsrNode } from "./node.js";
|
|
9
9
|
import { rawElementContent } from "./raw-text.js";
|
|
10
10
|
// src/server/element.ts
|
|
11
11
|
/** A tag name: letters, digits and dashes, starting with a letter. Anything else could break out. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { invalid } from "./errors.js";
|
|
2
|
-
import { SsrNode } from "./node.js";
|
|
3
2
|
import { escape, escapeHtml, resolveValue } from "./escape.js";
|
|
3
|
+
import { SsrNode } from "./node.js";
|
|
4
4
|
// src/server/form-controls.ts
|
|
5
5
|
/**
|
|
6
6
|
* Server markup for the controls whose state is not an attribute. A browser ignores `value` on a
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { childScope, withScope } from "../internal/hydration-scope.js";
|
|
2
|
+
import { PortalContext } from "../internal/portal-context.js";
|
|
2
3
|
import { SsrError } from "./errors.js";
|
|
3
4
|
import { escape } from "./escape.js";
|
|
4
|
-
import { PortalContext } from "../internal/portal-context.js";
|
|
5
5
|
/** The collector behind a {@link ServerPortals}: what a renderer writes into while it renders. @internal */
|
|
6
6
|
var PortalCollector = class {
|
|
7
7
|
entries = /* @__PURE__ */ new Map();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { invalid } from "./errors.js";
|
|
2
|
-
import { SsrNode, isSsrNode } from "./node.js";
|
|
3
2
|
import { render, resolveValue } from "./escape.js";
|
|
3
|
+
import { SsrNode, isSsrNode } from "./node.js";
|
|
4
4
|
// src/server/raw-text.ts
|
|
5
5
|
/** The elements whose text the parser reads raw. */
|
|
6
6
|
const RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set(["script", "style"]);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { attachRootErrors } from "../control-flow/root-errors.js";
|
|
2
|
+
import { runWithServerHead } from "../head/server-head.js";
|
|
1
3
|
import { createRootScope, resourceKey, withScope } from "../internal/hydration-scope.js";
|
|
2
4
|
import { MAX_TIMER_MS, SsrError } from "./errors.js";
|
|
3
5
|
import { escape } from "./escape.js";
|
|
4
|
-
import { attachRootErrors } from "../control-flow/root-errors.js";
|
|
5
|
-
import { runWithServerHead } from "../head/server-head.js";
|
|
6
6
|
import { portalCollectorFor, withPortalSink } from "./portals.js";
|
|
7
7
|
import { ResourceCacheContext, createRoot } from "@shadow-js/core";
|
|
8
8
|
// src/server/render.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { attachRootErrors } from "../control-flow/root-errors.js";
|
|
2
|
+
import { runWithServerHead } from "../head/server-head.js";
|
|
1
3
|
import { createRootScope, resourceKey, withScope } from "../internal/hydration-scope.js";
|
|
4
|
+
import { StreamContext } from "../internal/stream-context.js";
|
|
2
5
|
import { MAX_TIMER_MS, SsrError } from "./errors.js";
|
|
3
6
|
import { escape } from "./escape.js";
|
|
4
|
-
import { StreamContext } from "../internal/stream-context.js";
|
|
5
|
-
import { attachRootErrors } from "../control-flow/root-errors.js";
|
|
6
|
-
import { runWithServerHead } from "../head/server-head.js";
|
|
7
7
|
import { portalCollectorFor, withPortalSink } from "./portals.js";
|
|
8
8
|
import { serialize } from "./serialize.js";
|
|
9
9
|
import { ResourceCacheContext, createRoot, untrack } from "@shadow-js/core";
|