@shadow-js/web 1.1.0 → 1.1.1
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 +6 -0
- package/README.md +1 -1
- package/dist/dev/attributes.d.ts +1 -2
- package/dist/dev/autofocus.d.ts +1 -2
- package/dist/dev/class-style.d.ts +1 -2
- package/dist/dev/component.d.ts +1 -2
- package/dist/dev/control-flow/activity.d.ts +1 -2
- package/dist/dev/control-flow/client-only.d.ts +1 -2
- package/dist/dev/control-flow/dynamic.d.ts +1 -2
- package/dist/dev/control-flow/error-boundary.d.ts +1 -2
- package/dist/dev/control-flow/for.d.ts +1 -2
- package/dist/dev/control-flow/fragment.d.ts +1 -2
- package/dist/dev/control-flow/index-list.d.ts +1 -2
- package/dist/dev/control-flow/lazy.d.ts +1 -2
- package/dist/dev/control-flow/no-hydration.d.ts +1 -2
- package/dist/dev/control-flow/portal.d.ts +1 -2
- package/dist/dev/control-flow/portal.js.map +1 -1
- package/dist/dev/control-flow/root-errors.d.ts +2 -3
- package/dist/dev/control-flow/show.d.ts +1 -2
- package/dist/dev/control-flow/suspense-list.d.ts +2 -3
- package/dist/dev/control-flow/suspense.d.ts +1 -2
- package/dist/dev/control-flow/switch.d.ts +1 -2
- package/dist/dev/derived.d.ts +1 -2
- package/dist/dev/element.d.ts +1 -2
- package/dist/dev/events.d.ts +1 -2
- package/dist/dev/extend.d.ts +9 -0
- package/dist/dev/head/components.d.ts +1 -2
- package/dist/dev/head/server-head.d.ts +2 -3
- package/dist/dev/head/use-head.d.ts +1 -2
- package/dist/dev/head/validate.d.ts +1 -2
- package/dist/dev/hmr.d.ts +1 -2
- package/dist/dev/hmr.js.map +1 -1
- package/dist/dev/hydration.d.ts +1 -2
- package/dist/dev/insert.d.ts +1 -2
- package/dist/dev/insert.js.map +1 -1
- package/dist/dev/internal/claim.d.ts +1 -2
- package/dist/dev/internal/diagnostics.d.ts +1 -2
- package/dist/dev/internal/hydration-hooks.d.ts +1 -2
- package/dist/dev/internal/hydration-scope.d.ts +1 -2
- package/dist/dev/internal/names.d.ts +1 -2
- package/dist/dev/internal/portal-context.d.ts +1 -2
- package/dist/dev/internal/reconcile.d.ts +1 -2
- package/dist/dev/internal/reconcile.js.map +1 -1
- package/dist/dev/internal/stream-context.d.ts +1 -2
- package/dist/dev/jsx/aria.d.ts +7 -2
- package/dist/dev/jsx/component.d.ts +7 -2
- package/dist/dev/jsx/events.d.ts +1 -2
- package/dist/dev/jsx/global.d.ts +11 -2
- package/dist/dev/jsx/html.d.ts +8 -2
- package/dist/dev/jsx/intrinsic.d.ts +10 -2
- package/dist/dev/jsx/mathml.d.ts +8 -2
- package/dist/dev/jsx/svg.d.ts +13 -2
- package/dist/dev/jsx/types.d.ts +1 -2
- package/dist/dev/jsx-dev-runtime.d.ts +6 -0
- package/dist/dev/jsx-runtime.d.ts +13 -2
- package/dist/dev/reactive.d.ts +1 -2
- package/dist/dev/render.d.ts +1 -2
- package/dist/dev/resource-hints.d.ts +1 -2
- package/dist/dev/select-value.d.ts +1 -2
- package/dist/dev/server/attributes.d.ts +1 -2
- package/dist/dev/server/class-style.d.ts +1 -2
- package/dist/dev/server/component.d.ts +1 -2
- package/dist/dev/server/derived.d.ts +1 -2
- package/dist/dev/server/element.d.ts +1 -2
- package/dist/dev/server/errors.js.map +1 -1
- package/dist/dev/server/escape.d.ts +1 -2
- package/dist/dev/server/form-controls.d.ts +1 -2
- package/dist/dev/server/hydration-script.d.ts +1 -2
- package/dist/dev/server/index.d.ts +7 -2
- package/dist/dev/server/index.js +2 -2
- package/dist/dev/server/node.d.ts +1 -2
- package/dist/dev/server/node.js.map +1 -1
- package/dist/dev/server/portals.d.ts +1 -2
- package/dist/dev/server/portals.js.map +1 -1
- package/dist/dev/server/raw-text.d.ts +1 -2
- package/dist/dev/server/render.d.ts +1 -2
- package/dist/dev/server/serialize.d.ts +1 -2
- package/dist/dev/server/stream.d.ts +1 -2
- package/dist/dev/server/stream.js.map +1 -1
- package/dist/dev/server.d.ts +1 -0
- package/dist/dev/spread.d.ts +1 -2
- package/dist/dev/template.d.ts +1 -2
- package/dist/dev/view-transition.d.ts +1 -2
- package/dist/prod/attributes.js.map +1 -1
- package/dist/prod/autofocus.js.map +1 -1
- package/dist/prod/class-style.js.map +1 -1
- package/dist/prod/component.js.map +1 -1
- package/dist/prod/control-flow/activity.js.map +1 -1
- package/dist/prod/control-flow/branch.js.map +1 -1
- package/dist/prod/control-flow/client-only.js.map +1 -1
- package/dist/prod/control-flow/dynamic.js.map +1 -1
- package/dist/prod/control-flow/error-boundary.js.map +1 -1
- package/dist/prod/control-flow/for.js.map +1 -1
- package/dist/prod/control-flow/fragment.js.map +1 -1
- package/dist/prod/control-flow/hot-link.js.map +1 -1
- package/dist/prod/control-flow/index-list.js.map +1 -1
- package/dist/prod/control-flow/lazy.js.map +1 -1
- package/dist/prod/control-flow/no-hydration.js.map +1 -1
- package/dist/prod/control-flow/portal.js.map +1 -1
- package/dist/prod/control-flow/root-errors.js.map +1 -1
- package/dist/prod/control-flow/show.js.map +1 -1
- package/dist/prod/control-flow/suspense-list.js.map +1 -1
- package/dist/prod/control-flow/suspense.js.map +1 -1
- package/dist/prod/control-flow/switch.js.map +1 -1
- package/dist/prod/derived.js.map +1 -1
- package/dist/prod/element.js.map +1 -1
- package/dist/prod/events.js.map +1 -1
- package/dist/prod/head/components.js.map +1 -1
- package/dist/prod/head/registry.js.map +1 -1
- package/dist/prod/head/server-head.js.map +1 -1
- package/dist/prod/head/sink.js.map +1 -1
- package/dist/prod/head/use-head.js.map +1 -1
- package/dist/prod/head/validate.js.map +1 -1
- package/dist/prod/hmr.js.map +1 -1
- package/dist/prod/hydration.js.map +1 -1
- package/dist/prod/insert.js.map +1 -1
- package/dist/prod/internal/accessor.js.map +1 -1
- package/dist/prod/internal/claim.js.map +1 -1
- package/dist/prod/internal/css-units.js.map +1 -1
- package/dist/prod/internal/diagnostics.js.map +1 -1
- package/dist/prod/internal/early-events.js.map +1 -1
- package/dist/prod/internal/hydration-hooks.js.map +1 -1
- package/dist/prod/internal/hydration-scope.js.map +1 -1
- package/dist/prod/internal/portal-context.js.map +1 -1
- package/dist/prod/internal/react-names.js.map +1 -1
- package/dist/prod/internal/reconcile.js.map +1 -1
- package/dist/prod/internal/stream-context.js.map +1 -1
- package/dist/prod/reactive.js.map +1 -1
- package/dist/prod/render.js.map +1 -1
- package/dist/prod/resource-hints.js.map +1 -1
- package/dist/prod/select-value.js.map +1 -1
- package/dist/prod/server/attributes.js.map +1 -1
- package/dist/prod/server/class-style.js.map +1 -1
- package/dist/prod/server/component.js.map +1 -1
- package/dist/prod/server/derived.js.map +1 -1
- package/dist/prod/server/element.js.map +1 -1
- package/dist/prod/server/errors.js.map +1 -1
- package/dist/prod/server/escape.js.map +1 -1
- package/dist/prod/server/form-controls.js.map +1 -1
- package/dist/prod/server/hydration-script.js.map +1 -1
- package/dist/prod/server/node.js.map +1 -1
- package/dist/prod/server/portals.js.map +1 -1
- package/dist/prod/server/raw-text.js.map +1 -1
- package/dist/prod/server/render.js.map +1 -1
- package/dist/prod/server/serialize.js.map +1 -1
- package/dist/prod/server/stream.js.map +1 -1
- package/dist/prod/spread.js.map +1 -1
- package/dist/prod/template.js.map +1 -1
- package/dist/prod/view-transition.js.map +1 -1
- package/dist/server/attributes.js.map +1 -1
- package/dist/server/autofocus.js.map +1 -1
- package/dist/server/class-style.js.map +1 -1
- package/dist/server/component.js.map +1 -1
- package/dist/server/control-flow/activity.js.map +1 -1
- package/dist/server/control-flow/branch.js.map +1 -1
- package/dist/server/control-flow/client-only.js.map +1 -1
- package/dist/server/control-flow/dynamic.js.map +1 -1
- package/dist/server/control-flow/error-boundary.js.map +1 -1
- package/dist/server/control-flow/for.js.map +1 -1
- package/dist/server/control-flow/fragment.js.map +1 -1
- package/dist/server/control-flow/index-list.js.map +1 -1
- package/dist/server/control-flow/lazy.js.map +1 -1
- package/dist/server/control-flow/no-hydration.js.map +1 -1
- package/dist/server/control-flow/portal.js.map +1 -1
- package/dist/server/control-flow/root-errors.js.map +1 -1
- package/dist/server/control-flow/show.js.map +1 -1
- package/dist/server/control-flow/suspense-list.js.map +1 -1
- package/dist/server/control-flow/suspense.js.map +1 -1
- package/dist/server/control-flow/switch.js.map +1 -1
- package/dist/server/derived.js.map +1 -1
- package/dist/server/element.js.map +1 -1
- package/dist/server/events.js.map +1 -1
- package/dist/server/head/components.js.map +1 -1
- package/dist/server/head/registry.js.map +1 -1
- package/dist/server/head/server-head.js.map +1 -1
- package/dist/server/head/sink.js.map +1 -1
- package/dist/server/head/use-head.js.map +1 -1
- package/dist/server/head/validate.js.map +1 -1
- package/dist/server/hydration.js.map +1 -1
- package/dist/server/insert.js.map +1 -1
- package/dist/server/internal/accessor.js.map +1 -1
- package/dist/server/internal/claim.js.map +1 -1
- package/dist/server/internal/css-units.js.map +1 -1
- package/dist/server/internal/diagnostics.js.map +1 -1
- package/dist/server/internal/early-events.js.map +1 -1
- package/dist/server/internal/hydration-hooks.js.map +1 -1
- package/dist/server/internal/hydration-scope.js.map +1 -1
- package/dist/server/internal/portal-context.js.map +1 -1
- package/dist/server/internal/react-names.js.map +1 -1
- package/dist/server/internal/reconcile.js.map +1 -1
- package/dist/server/internal/stream-context.js.map +1 -1
- package/dist/server/reactive.js.map +1 -1
- package/dist/server/render.js.map +1 -1
- package/dist/server/resource-hints.js.map +1 -1
- package/dist/server/select-value.js.map +1 -1
- package/dist/server/server/attributes.js.map +1 -1
- package/dist/server/server/class-style.js.map +1 -1
- package/dist/server/server/component.js.map +1 -1
- package/dist/server/server/derived.js.map +1 -1
- package/dist/server/server/element.js.map +1 -1
- package/dist/server/server/errors.js.map +1 -1
- package/dist/server/server/escape.js.map +1 -1
- package/dist/server/server/form-controls.js.map +1 -1
- package/dist/server/server/hydration-script.js.map +1 -1
- package/dist/server/server/node.js.map +1 -1
- package/dist/server/server/portals.js.map +1 -1
- package/dist/server/server/raw-text.js.map +1 -1
- package/dist/server/server/render.js.map +1 -1
- package/dist/server/server/serialize.js.map +1 -1
- package/dist/server/server/stream.js.map +1 -1
- package/dist/server/spread.js.map +1 -1
- package/dist/server/template.js.map +1 -1
- package/dist/server/view-transition.js.map +1 -1
- package/dist/server-dev/control-flow/portal.js.map +1 -1
- package/dist/server-dev/insert.js.map +1 -1
- package/dist/server-dev/internal/reconcile.js.map +1 -1
- package/dist/server-dev/server/errors.js.map +1 -1
- package/dist/server-dev/server/index.js +2 -2
- package/dist/server-dev/server/node.js.map +1 -1
- package/dist/server-dev/server/portals.js.map +1 -1
- package/dist/server-dev/server/stream.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.js","names":["ATTRIBUTE_NAME","URL_ATTRIBUTES","ANIMATION_VALUE_ATTRIBUTES","ENUMERATED_ATTRIBUTES","UNSAFE_URL_PREFIXES","assertAttributeName","name","
|
|
1
|
+
{"version":3,"file":"attributes.js","names":["invalid","escapeHtml","resolveValue","ATTRIBUTE_NAME","URL_ATTRIBUTES","ANIMATION_VALUE_ATTRIBUTES","ENUMERATED_ATTRIBUTES","UNSAFE_URL_PREFIXES","assertAttributeName","name","isEventName","lowerName","isStringValued","stripControls","text","kept","char","code","isUnsafeUrl","value","normalized","prefix","isUnsafeAttributeValue","attributeText","assertNotSymbol","ssrAttribute","isBoolean","resolved"],"sources":["../../../src/server/attributes.ts"],"sourcesContent":["import { SRCDOC_DYNAMIC_DETAIL, warnOnce } from \"../internal/diagnostics\";\nimport { invalid } from \"./errors\";\nimport { escapeHtml, resolveValue } from \"./escape\";\n\n/** Names that can appear in markup: an XML-name subset without `@` or whitespace. Same as the client. */\nconst ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_:.-]*$/;\n\n/** Attributes whose value is a URL and is therefore checked for script schemes. Same as the client. */\nconst URL_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"href\",\n \"src\",\n \"action\",\n \"formaction\",\n \"xlink:href\",\n \"poster\",\n \"data\",\n]);\n\n/**\n * SVG animation attributes (`animate`, `set`): with `attributeName=\"href\"` they write an `href` by animation, so their value\n * is checked like one. `values` is a `;` list and every entry is checked. Same as the client.\n */\nconst ANIMATION_VALUE_ATTRIBUTES: ReadonlySet<string> = new Set([\"values\", \"from\", \"to\", \"by\"]);\n\n/** Enumerated attributes where `false` is a real value (\"false\") rather than an absence. */\nconst ENUMERATED_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"draggable\",\n \"spellcheck\",\n \"contenteditable\",\n]);\n\n/** URL prefixes (after normalization) that are never written. Same as the client. */\nconst UNSAFE_URL_PREFIXES: readonly string[] = [\"javascript:\", \"data:text/html\", \"vbscript:\"];\n\n/** Throws a TypeError unless `name` can be written as an attribute name. @internal */\nexport function assertAttributeName(name: string): void {\n if (!ATTRIBUTE_NAME.test(name)) {\n throw invalid(\"INVALID_ATTRIBUTE_NAME\", `\"${name}\" is not a valid attribute name.`);\n }\n}\n\n/** True for `on*` names, which never reach markup. Length matches the client's event test. @internal */\nexport function isEventName(lowerName: string): boolean {\n return lowerName.length > 2 && lowerName.startsWith(\"on\");\n}\n\n/** True for `aria-*`, `data-*` and the enumerated attributes: their booleans are strings. */\nfunction isStringValued(lowerName: string): boolean {\n return (\n lowerName.startsWith(\"aria-\") ||\n lowerName.startsWith(\"data-\") ||\n ENUMERATED_ATTRIBUTES.has(lowerName)\n );\n}\n\n/** Removes C0 and C1 control characters, which browsers ignore inside a URL scheme. */\nfunction stripControls(text: string): string {\n let kept = \"\";\n for (const char of text) {\n const code = char.charCodeAt(0);\n if (code > 0x1f && (code < 0x7f || code > 0x9f)) kept += char;\n }\n return kept;\n}\n\n/** True when the URL would run script, after the normalization browsers apply. @internal */\nexport function isUnsafeUrl(value: string): boolean {\n const normalized = stripControls(value).trim().toLowerCase();\n return UNSAFE_URL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n\n/** True when `lowerName` carries a URL (or an animated one) and `value` would run script. */\nfunction isUnsafeAttributeValue(lowerName: string, value: string): boolean {\n if (URL_ATTRIBUTES.has(lowerName)) return isUnsafeUrl(value);\n return ANIMATION_VALUE_ATTRIBUTES.has(lowerName) && value.split(\";\").some(isUnsafeUrl);\n}\n\n/** Text to write for `value`, or null when the attribute is removed. Same rules as the client. @internal */\nexport function attributeText(lowerName: string, value: unknown): string | null {\n if (value === null || value === undefined) return null;\n if (value === false) return isStringValued(lowerName) ? \"false\" : null;\n if (value === true) return isStringValued(lowerName) ? \"true\" : \"\";\n return String(value);\n}\n\n/** Refuses symbols, which have no markup form and would otherwise be coerced silently. */\nfunction assertNotSymbol(value: unknown): void {\n if (typeof value === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be an attribute value.\");\n }\n}\n\n/**\n * Renders one attribute as markup with a leading space, or `\"\"` when the attribute is absent: the\n * helper the compiler's server output calls for a dynamic attribute. It applies the client's value\n * rules and URL check, so server and client agree on what is written.\n *\n * - `null`, `undefined` and `false` give `\"\"` (except `false` on `aria-*`, `data-*`, `draggable`,\n * `spellcheck` and `contenteditable`, which is written as `\"false\"`); `true` writes `=\"\"` (or\n * `\"true\"` for those same names). Other values are written as `String(value)`, HTML-escaped.\n * - URL attributes whose value would run script are dropped, with the check of\n * `isUnsafeUrlAttribute` (including the SVG animation attributes `values`, `from`, `to`, `by`).\n * - `srcdoc` is an HTML sink, not a URL: its value is a document the frame runs, escaped for the attribute\n * and otherwise written as it is, with the trust of `innerHTML`. Sanitize it and give the frame a `sandbox`\n * attribute. Development builds warn once with `SRCDOC_DYNAMIC`.\n * - `on*` names are dropped: event handlers never reach markup.\n * - Accessors are called (untracked) until a plain value remains.\n *\n * @param name Attribute name, matching `[A-Za-z_:][A-Za-z0-9_:.-]*`. It is validated before\n * anything else, so an invalid name always throws.\n * @param value The value, or an accessor of it.\n * @param isBoolean `true` for a presence attribute such as `disabled`: a truthy value writes the bare\n * name, a falsy one writes nothing. Default: `false`.\n * @returns Markup such as `' title=\"a&b\"'`, or `\"\"`.\n * @throws TypeError `INVALID_ATTRIBUTE_NAME` for an invalid name, and `UNRECOGNIZED_INSERT_VALUE`\n * when the value is a symbol.\n * @example\n * import { ssrAttribute } from \"@shadow-js/web/server\";\n *\n * ssrAttribute(\"title\", \"Tom & Jerry\"); // ' title=\"Tom & Jerry\"'\n * ssrAttribute(\"disabled\", true, true); // \" disabled\"\n * ssrAttribute(\"href\", \"javascript:alert(1)\"); // \"\"\n * @since 1.0.0\n */\nexport function ssrAttribute(name: string, value: unknown, isBoolean = false): string {\n assertAttributeName(name);\n const lowerName = name.toLowerCase();\n if (isEventName(lowerName)) return \"\";\n const resolved = resolveValue(value);\n assertNotSymbol(resolved);\n if (isBoolean) return resolved ? ` ${name}` : \"\";\n const text = attributeText(lowerName, resolved);\n if (text === null) return \"\";\n if (__DEV__ && lowerName === \"srcdoc\") warnOnce(\"SRCDOC_DYNAMIC\", SRCDOC_DYNAMIC_DETAIL);\n if (isUnsafeAttributeValue(lowerName, text)) return \"\";\n return ` ${name}=\"${escapeHtml(text)}\"`;\n}\n"],"mappings":"A,iGAKA,MAAMG,EAAiB,+BAGjBC,kBAAsC,IAAI,IAAI,CAClD,OACA,MACA,SACA,aACA,aACA,SACA,MACF,CAAC,EAMKC,kBAAkD,IAAI,IAAI,CAAC,SAAU,OAAQ,KAAM,IAAI,CAAC,EAGxFC,kBAA6C,IAAI,IAAI,CACzD,YACA,aACA,iBACF,CAAC,EAGKC,EAAyC,CAAC,cAAe,iBAAkB,WAAW,EAG5F,SAAgBC,EAAoBC,EAAoB,CACtD,GAAI,CAACN,EAAe,KAAKM,CAAI,EAC3B,MAAMT,EAAQ,yBAA0B,IAAIS,EAAK,iCAAiC,CAEtF,CAGA,SAAgBC,EAAYC,EAA4B,CACtD,OAAOA,EAAU,OAAS,GAAKA,EAAU,WAAW,IAAI,CAC1D,CAGA,SAASC,EAAeD,EAA4B,CAClD,OACEA,EAAU,WAAW,OAAO,GAC5BA,EAAU,WAAW,OAAO,GAC5BL,E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,EAAWa,CAAI,EAAE,EACvC,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-style.js","names":["CSS_PROPERTY","collectClasses","frames","root","cursors","open","top","frame","cursor","done","item","resolveValue","parts","invalid","record","key","classText","resolved","value","ssrClass","text","escapeHtml","toCssProperty","name","kebab","letter","isSafeCssValue","quote","depth","escaped","char","collectDeclarations","source","out","isSsrNode","property","cssValueText","styleText","declarations","ssrStyle"],"sources":["../../../src/server/class-style.ts"],"sourcesContent":["import { cssValueText } from \"../internal/css-units\";\nimport { invalid } from \"./errors\";\nimport { escapeHtml, resolveValue } from \"./escape\";\nimport { isSsrNode } from \"./node\";\n\n/** A CSS property name: a custom property, or a lower-case name with an optional vendor dash. */\nconst CSS_PROPERTY = /^(--[A-Za-z0-9_-]+|-?[a-z][a-z0-9-]*)$/;\n\n/**\n * Appends the class names found in `root` to `parts`, clsx-style. Iterative: array nesting depth\n * is controlled by the caller, so it must not reach the call stack.\n * @internal\n */\nexport function collectClasses(root: unknown, parts: string[]): void {\n const frames: unknown[][] = [[root]];\n const cursors: number[] = [0];\n const open = new Set<unknown[]>();\n while (frames.length > 0) {\n const top = frames.length - 1;\n const frame = frames[top];\n const cursor = cursors[top] ?? 0;\n if (frame === undefined || cursor >= frame.length) {\n const done = frames.pop();\n if (done !== undefined) open.delete(done);\n cursors.pop();\n continue;\n }\n cursors[top] = cursor + 1;\n const item = resolveValue(frame[cursor]);\n if (Array.isArray(item)) {\n if (open.has(item)) throw new TypeError(\"A class array contains itself.\");\n open.add(item);\n frames.push(item);\n cursors.push(0);\n } else 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 (typeof item === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be a class name.\");\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 (key !== \"\" && resolveValue(record[key])) parts.push(key);\n }\n }\n }\n}\n\n/**\n * The class text for a class value, or \"\" when there is none. A string is used as it is.\n * @internal\n */\nexport function classText(value: unknown): string {\n const resolved = resolveValue(value);\n if (typeof resolved === \"string\") return resolved;\n if (resolved === null || resolved === undefined || resolved === false) return \"\";\n const parts: string[] = [];\n collectClasses(resolved, parts);\n return parts.join(\" \");\n}\n\n/**\n * Renders a `class` attribute from a class value: the helper the compiler's server output calls for\n * `class`, `className` and `classList`, with the same clsx rules as the client's `className`.\n *\n * @param value A string (used as is), or an array or object: non-empty strings, numbers other than\n * `0` and `NaN`, nested arrays, and the keys of objects whose value is truthy. Accessors, also\n * inside arrays and as object values, are called. `null`, `undefined` and `false` give no class.\n * @returns Markup such as `' class=\"a b\"'` (HTML-escaped), or `\"\"` when there are no classes.\n * @throws TypeError when an array contains itself, and `UNRECOGNIZED_INSERT_VALUE` for a symbol.\n * @example\n * import { ssrClass } from \"@shadow-js/web/server\";\n *\n * ssrClass([\"card\", { \"card--active\": true, hidden: false }]); // ' class=\"card card--active\"'\n * ssrClass(null); // \"\"\n * @see ssrStyle\n * @since 1.0.0\n */\nexport function ssrClass(value: unknown): string {\n const text = classText(value);\n return text === \"\" ? \"\" : ` class=\"${escapeHtml(text)}\"`;\n}\n\n/** Converts a camelCase style name to CSS, keeping custom properties; `ms` gets its dash. @internal */\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 * True when a value cannot end its own declaration. A `;`, `{` or `}` outside quotes and\n * parentheses would start another declaration or rule, so such a value is dropped. Unbalanced\n * quotes or parentheses are dropped too, because they would swallow the declarations after them.\n * @internal\n */\nexport function isSafeCssValue(text: string): boolean {\n let quote = \"\";\n let depth = 0;\n let escaped = false;\n for (const char of text) {\n if (escaped) {\n escaped = false;\n } else if (char === \"\\\\\") {\n escaped = true;\n } else if (quote !== \"\") {\n if (char === quote) quote = \"\";\n } else if (char === '\"' || char === \"'\") {\n quote = char;\n } else if (char === \"(\") {\n depth += 1;\n } else if (char === \")\") {\n depth = Math.max(0, depth - 1);\n } else if ((char === \";\" || char === \"{\" || char === \"}\") && depth === 0) {\n return false;\n }\n }\n return quote === \"\" && depth === 0 && !escaped;\n}\n\n/** Declarations for one style source, appended to `out` as raw (unescaped) CSS text. */\nfunction collectDeclarations(source: unknown, out: string[]): void {\n const value = resolveValue(source);\n if (value === null || value === undefined || value === false) return;\n if (typeof value === \"string\") {\n if (value !== \"\") out.push(value);\n return;\n }\n if (typeof value !== \"object\" || isSsrNode(value)) {\n throw invalid(\n \"UNRECOGNIZED_INSERT_VALUE\",\n \"A style must be a string, an object or an array of them.\",\n );\n }\n if (Array.isArray(value)) {\n for (const item of value) {\n const resolved = resolveValue(item);\n if (Array.isArray(resolved)) {\n throw new TypeError(\"ssrStyle(): a style array may not contain another array.\");\n }\n collectDeclarations(resolved, out);\n }\n return;\n }\n for (const key of Object.keys(value)) {\n const property = toCssProperty(key);\n if (!CSS_PROPERTY.test(property)) {\n throw invalid(\"INVALID_STYLE_PROPERTY\", `\"${key}\" is not a valid CSS property name.`);\n }\n const resolved = resolveValue(Reflect.get(value, key));\n if (resolved === null || resolved === undefined || resolved === false) continue;\n if (typeof resolved === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be a style value.\");\n }\n const text = cssValueText(property, resolved);\n if (!isSafeCssValue(text)) continue;\n out.push(`${property}:${text}`);\n }\n}\n\n/**\n * The declarations of a style value, joined with `;`, or \"\" when there are none. Later\n * declarations win in CSS, so earlier and later sources can be combined in order.\n * @internal\n */\nexport function styleText(value: unknown): string {\n const declarations: string[] = [];\n collectDeclarations(value, declarations);\n return declarations.join(\";\");\n}\n\n/**\n * Renders a `style` attribute from a style value: the helper the compiler's server output calls for\n * `style` and `style:` attributes. Sources in an array are written in order, so a later declaration\n * wins in CSS.\n *\n * @param value A string (written as is), an object of properties, or an array of strings and\n * objects (not nested). Object keys are camelCase (converted to kebab-case, `msTransform` gives\n * `-ms-transform`), kebab-case, or custom properties (`--gap`, kept). `null`, `undefined` and `false`\n * values are skipped; a number is in pixels unless it is `0`, the property is unitless (`opacity`,\n * `zIndex`, ...) or a custom property, as in React. A value that could end its own declaration (a\n * `;`, `{` or `}` outside quotes and parentheses, or an unbalanced quote or parenthesis) is dropped.\n * @returns Markup such as `' style=\"color:red\"'` (HTML-escaped), or `\"\"` when there is nothing to\n * write.\n * @throws TypeError `INVALID_STYLE_PROPERTY` for an invalid property name, `UNRECOGNIZED_INSERT_VALUE`\n * for a symbol or a value that is not a string, object or array, and a TypeError for a nested array.\n * @example\n * import { ssrStyle } from \"@shadow-js/web/server\";\n *\n * ssrStyle({ backgroundColor: \"red\", width: 10, \"--gap\": \"4px\" });\n * // ' style=\"background-color:red;width:10px;--gap:4px\"'\n * ssrStyle([{ color: \"red\" }, \"color: blue\"]); // the later declaration wins\n * @see ssrClass\n * @since 1.0.0\n */\nexport function ssrStyle(value: unknown): string {\n const text = styleText(value);\n return text === \"\" ? \"\" : ` style=\"${escapeHtml(text)}\"`;\n}\n"],"mappings":"A,+LAMA,MAAMA,EAAe,yCAOrB,SAAgBC,EAAe,EAAe,EAAuB,CACnE,IAAMC,EAAsB,CAAC,CAACC,CAAI,CAAC,EAC7BC,EAAoB,CAAC,CAAC,EACtBC,kBAAO,IAAI,IACjB,KAAOH,EAAO,OAAS,GAAG,CACxB,IAAMI,EAAMJ,EAAO,OAAS,EACtBK,EAAQL,EAAOI,GACfE,EAASJ,EAAQE,IAAQ,EAC/B,GAAIC,IAAU,IAAA,IAAaC,GAAUD,EAAM,OAAQ,CACjD,IAAME,EAAOP,EAAO,IAAI,EACpBO,IAAS,IAAA,IAAWJ,EAAK,OAAOI,CAAI,EACxCL,EAAQ,IAAI,EACZ,QACF,CACA,EAAQE,GAAOE,EAAS,E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AEhF,IAAMO,EAAOgB,EAAaD,EAAUlB,CAAQ,EACvCS,EAAeN,CAAI,GACxBa,EAAI,KAAK,GAAGE,EAAS,GAAGf,GAAM,CAChC,CAzBE,CALF,CA+BF,CAOA,SAAgBiB,EAAU,EAAwB,CAChD,IAAMC,EAAyB,CAAC,EAEhC,OADAP,EAAoBb,EAAOoB,CAAY,EAChCA,EAAa,KAAK,GAAG,CAC9B,CA0BA,SAAgBC,EAAS,EAAwB,CAC/C,IAAMnB,EAAOiB,EAAUnB,CAAK,EAC5B,OAAOE,IAAS,GAAK,GAAK,WAAWC,EAAWD,CAAI,EAAE,EACxD,C"}
|
|
1
|
+
{"version":3,"file":"class-style.js","names":["cssValueText","invalid","escapeHtml","resolveValue","isSsrNode","CSS_PROPERTY","collectClasses","root","parts","frames","cursors","open","top","frame","cursor","done","item","record","key","classText","value","resolved","ssrClass","text","toCssProperty","name","kebab","letter","isSafeCssValue","quote","depth","escaped","char","collectDeclarations","source","out","property","styleText","declarations","ssrStyle"],"sources":["../../../src/server/class-style.ts"],"sourcesContent":["import { cssValueText } from \"../internal/css-units\";\nimport { invalid } from \"./errors\";\nimport { escapeHtml, resolveValue } from \"./escape\";\nimport { isSsrNode } from \"./node\";\n\n/** A CSS property name: a custom property, or a lower-case name with an optional vendor dash. */\nconst CSS_PROPERTY = /^(--[A-Za-z0-9_-]+|-?[a-z][a-z0-9-]*)$/;\n\n/**\n * Appends the class names found in `root` to `parts`, clsx-style. Iterative: array nesting depth\n * is controlled by the caller, so it must not reach the call stack.\n * @internal\n */\nexport function collectClasses(root: unknown, parts: string[]): void {\n const frames: unknown[][] = [[root]];\n const cursors: number[] = [0];\n const open = new Set<unknown[]>();\n while (frames.length > 0) {\n const top = frames.length - 1;\n const frame = frames[top];\n const cursor = cursors[top] ?? 0;\n if (frame === undefined || cursor >= frame.length) {\n const done = frames.pop();\n if (done !== undefined) open.delete(done);\n cursors.pop();\n continue;\n }\n cursors[top] = cursor + 1;\n const item = resolveValue(frame[cursor]);\n if (Array.isArray(item)) {\n if (open.has(item)) throw new TypeError(\"A class array contains itself.\");\n open.add(item);\n frames.push(item);\n cursors.push(0);\n } else 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 (typeof item === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be a class name.\");\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 (key !== \"\" && resolveValue(record[key])) parts.push(key);\n }\n }\n }\n}\n\n/**\n * The class text for a class value, or \"\" when there is none. A string is used as it is.\n * @internal\n */\nexport function classText(value: unknown): string {\n const resolved = resolveValue(value);\n if (typeof resolved === \"string\") return resolved;\n if (resolved === null || resolved === undefined || resolved === false) return \"\";\n const parts: string[] = [];\n collectClasses(resolved, parts);\n return parts.join(\" \");\n}\n\n/**\n * Renders a `class` attribute from a class value: the helper the compiler's server output calls for\n * `class`, `className` and `classList`, with the same clsx rules as the client's `className`.\n *\n * @param value A string (used as is), or an array or object: non-empty strings, numbers other than\n * `0` and `NaN`, nested arrays, and the keys of objects whose value is truthy. Accessors, also\n * inside arrays and as object values, are called. `null`, `undefined` and `false` give no class.\n * @returns Markup such as `' class=\"a b\"'` (HTML-escaped), or `\"\"` when there are no classes.\n * @throws TypeError when an array contains itself, and `UNRECOGNIZED_INSERT_VALUE` for a symbol.\n * @example\n * import { ssrClass } from \"@shadow-js/web/server\";\n *\n * ssrClass([\"card\", { \"card--active\": true, hidden: false }]); // ' class=\"card card--active\"'\n * ssrClass(null); // \"\"\n * @see ssrStyle\n * @since 1.0.0\n */\nexport function ssrClass(value: unknown): string {\n const text = classText(value);\n return text === \"\" ? \"\" : ` class=\"${escapeHtml(text)}\"`;\n}\n\n/** Converts a camelCase style name to CSS, keeping custom properties; `ms` gets its dash. @internal */\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 * True when a value cannot end its own declaration. A `;`, `{` or `}` outside quotes and\n * parentheses would start another declaration or rule, so such a value is dropped. Unbalanced\n * quotes or parentheses are dropped too, because they would swallow the declarations after them.\n * @internal\n */\nexport function isSafeCssValue(text: string): boolean {\n let quote = \"\";\n let depth = 0;\n let escaped = false;\n for (const char of text) {\n if (escaped) {\n escaped = false;\n } else if (char === \"\\\\\") {\n escaped = true;\n } else if (quote !== \"\") {\n if (char === quote) quote = \"\";\n } else if (char === '\"' || char === \"'\") {\n quote = char;\n } else if (char === \"(\") {\n depth += 1;\n } else if (char === \")\") {\n depth = Math.max(0, depth - 1);\n } else if ((char === \";\" || char === \"{\" || char === \"}\") && depth === 0) {\n return false;\n }\n }\n return quote === \"\" && depth === 0 && !escaped;\n}\n\n/** Declarations for one style source, appended to `out` as raw (unescaped) CSS text. */\nfunction collectDeclarations(source: unknown, out: string[]): void {\n const value = resolveValue(source);\n if (value === null || value === undefined || value === false) return;\n if (typeof value === \"string\") {\n if (value !== \"\") out.push(value);\n return;\n }\n if (typeof value !== \"object\" || isSsrNode(value)) {\n throw invalid(\n \"UNRECOGNIZED_INSERT_VALUE\",\n \"A style must be a string, an object or an array of them.\",\n );\n }\n if (Array.isArray(value)) {\n for (const item of value) {\n const resolved = resolveValue(item);\n if (Array.isArray(resolved)) {\n throw new TypeError(\"ssrStyle(): a style array may not contain another array.\");\n }\n collectDeclarations(resolved, out);\n }\n return;\n }\n for (const key of Object.keys(value)) {\n const property = toCssProperty(key);\n if (!CSS_PROPERTY.test(property)) {\n throw invalid(\"INVALID_STYLE_PROPERTY\", `\"${key}\" is not a valid CSS property name.`);\n }\n const resolved = resolveValue(Reflect.get(value, key));\n if (resolved === null || resolved === undefined || resolved === false) continue;\n if (typeof resolved === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be a style value.\");\n }\n const text = cssValueText(property, resolved);\n if (!isSafeCssValue(text)) continue;\n out.push(`${property}:${text}`);\n }\n}\n\n/**\n * The declarations of a style value, joined with `;`, or \"\" when there are none. Later\n * declarations win in CSS, so earlier and later sources can be combined in order.\n * @internal\n */\nexport function styleText(value: unknown): string {\n const declarations: string[] = [];\n collectDeclarations(value, declarations);\n return declarations.join(\";\");\n}\n\n/**\n * Renders a `style` attribute from a style value: the helper the compiler's server output calls for\n * `style` and `style:` attributes. Sources in an array are written in order, so a later declaration\n * wins in CSS.\n *\n * @param value A string (written as is), an object of properties, or an array of strings and\n * objects (not nested). Object keys are camelCase (converted to kebab-case, `msTransform` gives\n * `-ms-transform`), kebab-case, or custom properties (`--gap`, kept). `null`, `undefined` and `false`\n * values are skipped; a number is in pixels unless it is `0`, the property is unitless (`opacity`,\n * `zIndex`, ...) or a custom property, as in React. A value that could end its own declaration (a\n * `;`, `{` or `}` outside quotes and parentheses, or an unbalanced quote or parenthesis) is dropped.\n * @returns Markup such as `' style=\"color:red\"'` (HTML-escaped), or `\"\"` when there is nothing to\n * write.\n * @throws TypeError `INVALID_STYLE_PROPERTY` for an invalid property name, `UNRECOGNIZED_INSERT_VALUE`\n * for a symbol or a value that is not a string, object or array, and a TypeError for a nested array.\n * @example\n * import { ssrStyle } from \"@shadow-js/web/server\";\n *\n * ssrStyle({ backgroundColor: \"red\", width: 10, \"--gap\": \"4px\" });\n * // ' style=\"background-color:red;width:10px;--gap:4px\"'\n * ssrStyle([{ color: \"red\" }, \"color: blue\"]); // the later declaration wins\n * @see ssrClass\n * @since 1.0.0\n */\nexport function ssrStyle(value: unknown): string {\n const text = styleText(value);\n return text === \"\" ? \"\" : ` style=\"${escapeHtml(text)}\"`;\n}\n"],"mappings":"A,+LAMA,MAAMK,EAAe,yCAOrB,SAAgBC,EAAeC,EAAeC,EAAuB,CACnE,IAAMC,EAAsB,CAAC,CAACF,CAAI,CAAC,EAC7B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BZ,EAAUc,CAAG,CACnC,MAGF,IAAK,IAAMjB,KAAO,OAAO,KAAKE,CAAK,EAAG,CACpC,IAAMgB,EAAWZ,EAAcN,CAAG,EAClC,GAAI,CAACb,EAAa,KAAK+B,CAAQ,EAC7B,MAAMnC,EAAQ,yBAA0B,IAAIiB,EAAI,oCAAoC,EAEtF,IAAMG,EAAWlB,EAAa,QAAQ,IAAIiB,EAAOF,CAAG,CAAC,EACrD,GAAIG,GAAa,MAAkCA,IAAa,GAAO,SACvE,GAAI,OAAOA,GAAa,SACtB,MAAMpB,EAAQ,4BAA6B,mCAAmC,EAEhF,IAAMsB,EAAOvB,EAAaoC,EAAUf,CAAQ,EACvCO,EAAeL,CAAI,GACxBY,EAAI,KAAK,GAAGC,EAAS,GAAGb,GAAM,CAChC,CAzBE,CALF,CA+BF,CAOA,SAAgBc,EAAUjB,EAAwB,CAChD,IAAMkB,EAAyB,CAAC,EAEhC,OADAL,EAAoBb,EAAOkB,CAAY,EAChCA,EAAa,KAAK,GAAG,CAC9B,CA0BA,SAAgBC,EAASnB,EAAwB,CAC/C,IAAMG,EAAOc,EAAUjB,CAAK,EAC5B,OAAOG,IAAS,GAAK,GAAK,WAAWrB,EAAWqB,CAAI,EAAE,EACxD,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","names":["
|
|
1
|
+
{"version":3,"file":"component.js","names":["currentScope","enterComponent","untrack","createOwner","runInScope","createComponent","component","props","owner","memo","fn","slot","running","value"],"sources":["../../../src/server/component.ts"],"sourcesContent":["import { untrack } from \"@shadow-js/core\";\nimport { createOwner, runInScope } from \"@shadow-js/core/extend\";\nimport { currentScope, enterComponent } from \"../internal/hydration-scope\";\n\n/**\n * Calls a component on the server, untracked, with its own owner and hydration scope, so the\n * hydration keys it hands out depend only on where it sits in the tree. The server twin of the client\n * `createComponent`: compiled server output calls it for `<Component />`, and a hand-written render\n * entry calls it for the root component.\n *\n * @param component The component function.\n * @param props The props object; reactive props are getters.\n * @returns Whatever the component returns.\n * @throws TypeError when `component` is not a function. An error the component throws propagates.\n * @example\n * import { createComponent, renderToString } from \"@shadow-js/web/server\";\n *\n * function Card(props: { title: string }) {\n * return <h2>{props.title}</h2>;\n * }\n * const html = renderToString(() => createComponent(Card, { title: \"Hello\" }));\n * @since 1.0.0\n */\nexport function createComponent<P>(component: (props: P) => unknown, props: P): unknown {\n if (typeof component !== \"function\") {\n throw new TypeError(\"createComponent(): the component must be a function.\");\n }\n return enterComponent(() => {\n // The same owner structure as the browser, so `useId` prefixes agree (see the DOM createComponent).\n const owner = createOwner();\n owner.idPrefix = currentScope()?.id;\n // One scope switch (owner in, listener off): deep component trees are bounded by the call stack.\n return runInScope({ owner, listener: null }, () => component(props));\n });\n}\n\n/**\n * The server twin of `memo`: nothing is reactive during a server render, so it computes once, on the\n * first read, and returns the cached value on every later read. A call that throws is not cached\n * (the next read runs `fn` again).\n *\n * @param fn The computation; runs untracked, on the first read.\n * @returns An accessor of the cached value.\n * @throws TypeError from the accessor when `fn` reads the accessor itself while it runs, instead of\n * recursing. An error `fn` throws propagates from the read.\n * @example\n * import { memo } from \"@shadow-js/web/server\";\n *\n * const items = [3, 1, 2];\n * const sorted = memo(() => [...items].sort());\n * sorted(); // [1, 2, 3], computed now\n * sorted(); // the same array, cached\n * @since 1.0.0\n */\nexport function memo<T>(fn: () => T): () => T {\n let slot: { readonly value: T } | undefined;\n let running = false;\n return () => {\n if (slot !== undefined) return slot.value;\n if (running) throw new TypeError(\"memo(): the computation read itself.\");\n running = true;\n try {\n const value = untrack(fn);\n slot = { value };\n return value;\n } finally {\n running = false;\n }\n };\n}\n"],"mappings":"A,iMAuBA,SAAgBK,EAAmBC,EAAkCC,EAAmB,CACtF,GAAI,OAAOD,GAAc,WACvB,MAAU,UAAU,sDAAsD,EAE5E,OAAOL,MAAqB,CAE1B,IAAMO,EAAQL,EAAY,EAG1B,MAFAK,GAAM,SAAWR,EAAa,CAAC,EAAE,GAE1BI,EAAW,CAAEI,QAAO,SAAU,IAAK,MAASF,EAAUC,CAAK,CAAC,CACrE,CAAC,CACH,CAoBA,SAAgBE,EAAQC,EAAsB,CAC5C,IAAIC,EACAC,EAAU,GACd,UAAa,CACX,GAAID,IAAS,IAAA,GAAW,OAAOA,EAAK,MACpC,GAAIC,EAAS,MAAU,UAAU,sCAAsC,EACvEA,EAAU,GACV,GAAI,CACF,IAAMC,EAAQX,EAAQQ,CAAE,EAExB,MADAC,GAAO,CAAEE,OAAM,EACRA,CACT,QAAU,CACRD,EAAU,EACZ,CACF,CACF,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derived.js","names":["derived","
|
|
1
|
+
{"version":3,"file":"derived.js","names":["derived","compute","current","read","args"],"sources":["../../../src/server/derived.ts"],"sourcesContent":["/**\n * The server twin of the client `Derived`: what {@link derived} returns. Nothing is reactive on the\n * server, so it holds the value computed once. Read it as `x.value` or call it as `x()`.\n *\n * @example\n * import { derived } from \"@shadow-js/web/server\";\n *\n * const total = derived(() => 20 * 3);\n * total.value; // 60\n * total(); // 60\n * @see derived\n * @since 1.0.0\n */\nexport interface Derived<T> {\n /**\n * Returns the value. When the value is a function, calls it with `args` and returns its result\n * instead, so a derived function stays callable.\n */\n (...args: unknown[]): unknown;\n /** The value `compute` returned. */\n readonly value: T;\n}\n\n/**\n * The server twin of the client `derived`, which the compiler emits for `const x = <expression\n * reading signals>` inside a component. On the server it calls `compute` once, immediately, and\n * returns a constant {@link Derived}.\n *\n * @param compute The computation. Runs once, when `derived` is called; an error it throws propagates.\n * @returns A {@link Derived} holding the result.\n * @example\n * import { derived } from \"@shadow-js/web/server\";\n *\n * const greeting = derived(() => (name: string) => `Hello, ${name}`);\n * greeting(\"Ada\"); // \"Hello, Ada\": a derived function stays callable\n * @see Derived\n * @since 1.0.0\n */\nexport function derived<T>(compute: () => T): Derived<T> {\n const current = compute();\n const read = ((...args: unknown[]): unknown =>\n typeof current === \"function\"\n ? (current as (...a: unknown[]) => unknown)(...args)\n : current) as {\n (...args: unknown[]): unknown;\n value: T;\n };\n Object.defineProperty(read, \"value\", { value: current });\n return read as Derived<T>;\n}\n"],"mappings":"AAsCA,SAAgBA,EAAWC,EAA8B,CACvD,IAAMC,EAAUD,EAAQ,EAClBE,IAAS,GAAGC,IAChB,OAAOF,GAAY,WACdA,EAAyC,GAAGE,CAAI,EACjDF,GAKN,OADA,OAAO,eAAeC,EAAM,QAAS,CAAE,MAAOD,CAAQ,CAAC,EAChDC,CACT,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.js","names":["TAG_NAME","VOID_ELEMENTS","SKIPPED_KEYS","innerHtmlOfValue","value","ssr","holes","parts","html","index","hole","isSsrNode","SsrNode","ssrRaw","ssrHydrationKey","key","nextKey","escapeHtml","ssrElement","tag","invalid","lowerTag","isSelect","isTextarea","control","hasValue","hasFallback","attributes","needsKey","classes","style","innerHtml","props","IGNORED_KEYS","isEventName","resolveValue","text","classText","collectTruthyKeys","styleText","plainHtml","ssrAttribute","name","attributeName","svg","isFlagAttribute","ssrStyle","raw","given","children","propsChildren","content","rawElementContent","escape","textareaContent","markSelectedOptions","keepLeadingNewline","out"],"sources":["../../../src/server/element.ts"],"sourcesContent":["import { nextKey } from \"../internal/hydration-scope\";\nimport { attributeName, IGNORED_KEYS, isFlagAttribute } from \"../internal/react-names\";\nimport { isEventName, ssrAttribute } from \"./attributes\";\nimport { classText, ssrStyle, styleText } from \"./class-style\";\nimport { invalid } from \"./errors\";\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name \"escape\" is part of the compiler contract (SSR output).\nimport { escape, escapeHtml, resolveValue } from \"./escape\";\nimport { keepLeadingNewline, markSelectedOptions, textareaContent } from \"./form-controls\";\nimport { isSsrNode, SsrNode } from \"./node\";\nimport { rawElementContent } from \"./raw-text\";\n\n/** A tag name: letters, digits and dashes, starting with a letter. Anything else could break out. */\nconst TAG_NAME = /^[A-Za-z][A-Za-z0-9-]*$/;\n\n/** Elements that never have children or a closing tag. */\nconst VOID_ELEMENTS: ReadonlySet<string> = new Set([\n \"area\",\n \"base\",\n \"br\",\n \"col\",\n \"command\",\n \"embed\",\n \"hr\",\n \"img\",\n \"input\",\n \"keygen\",\n \"link\",\n \"meta\",\n \"param\",\n \"source\",\n \"track\",\n \"wbr\",\n]);\n\n/** Keys that never become attributes: they are handled elsewhere or would reach a prototype. */\nconst SKIPPED_KEYS: ReadonlySet<string> = new Set([\n \"__proto__\",\n \"constructor\",\n \"prototype\",\n \"children\",\n \"ref\",\n]);\n\n/** The HTML of a `dangerouslySetInnerHTML` value (`{ __html }`): null and undefined are empty. */\nfunction innerHtmlOfValue(value: unknown): unknown {\n if (value === null || typeof value !== \"object\") return undefined;\n return Reflect.get(value, \"__html\");\n}\n\n/**\n * Joins the static parts of a server template with its dynamic holes into trusted markup: the\n * function compiled server output calls for each element tree. Holes are inserted unchanged, so each\n * must already be escaped (the output of `escape`, `ssrAttribute`, `ssrClass`, ...) or an `SsrNode`;\n * any other value throws, so a raw user value cannot reach the markup.\n *\n * @param parts The static markup, one more entry than there are holes.\n * @param holes The dynamic parts: strings produced by the escaping helpers, or `SsrNode` values.\n * @returns The markup as a trusted `SsrNode`, which `escape` writes without encoding.\n * @throws TypeError when `parts` is not an array of `holes.length + 1` entries, or when a hole is not\n * a string or an `SsrNode`.\n * @example\n * import { escape, renderToString, ssr } from \"@shadow-js/web/server\";\n *\n * const name = \"<Ada>\";\n * const html = renderToString(() => ssr([\"<p>Hello, \", \"</p>\"], escape(name)));\n * // \"<p>Hello, <Ada></p>\"\n * @see ssrRaw\n * @since 1.0.0\n */\nexport function ssr(parts: readonly string[], ...holes: unknown[]): SsrNode {\n if (!Array.isArray(parts) || parts.length !== holes.length + 1) {\n throw new TypeError(\"ssr(): parts must have one more entry than there are holes.\");\n }\n let html = parts[0] ?? \"\";\n for (let index = 0; index < holes.length; index += 1) {\n const hole = holes[index];\n if (typeof hole === \"string\") html += hole;\n else if (isSsrNode(hole)) html += hole.t;\n else throw new TypeError(\"ssr(): a hole must be an escaped string or an SsrNode.\");\n html += parts[index + 1] ?? \"\";\n }\n return new SsrNode(html);\n}\n\n/**\n * Marks a string as trusted markup that `escape` and `ssr` insert unchanged. Only use it for markup\n * the application wrote itself, never for user input.\n *\n * @param html The markup, inserted unchanged.\n * @returns The markup as a trusted `SsrNode`.\n * @throws TypeError when `html` is not a string.\n * @example\n * import { renderToString, ssrRaw } from \"@shadow-js/web/server\";\n *\n * const html = renderToString(() => [\"<b>escaped</b>\", ssrRaw(\"<!-- build 42 -->\")]);\n * // \"<b>escaped</b><!-- build 42 -->\"\n * @see ssr\n * @since 1.0.0\n */\nexport function ssrRaw(html: string): SsrNode {\n if (typeof html !== \"string\") throw new TypeError(\"ssrRaw(): the markup must be a string.\");\n return new SsrNode(html);\n}\n\n/**\n * Draws the next hydration key of the current scope and returns it as a `data-hk` attribute, such as\n * `' data-hk=\"0-0\"'`: compiled server output calls it for the root element of each template, and\n * the client's `hydrate()` claims the element by that key. Calls must happen in the same order as on\n * the client, so call it only where the compiler would.\n *\n * @returns Markup for the `data-hk` attribute, or `\"\"` outside a server render (no key is drawn).\n * @example\n * import { renderToString, ssr, ssrHydrationKey } from \"@shadow-js/web/server\";\n *\n * const html = renderToString(() => ssr([\"<div\", \">x</div>\"], ssrHydrationKey()));\n * // '<div data-hk=\"0-0\">x</div>'\n * @since 1.0.0\n */\nexport function ssrHydrationKey(): string {\n const key = nextKey();\n return key === undefined ? \"\" : ` data-hk=\"${escapeHtml(key)}\"`;\n}\n\n/**\n * Renders an element from a props object: what compiled server output calls for an element with a\n * spread (`<div {...props} />`), and the server half of `Dynamic` and `element`. It writes the same\n * markup the client's `spread` produces.\n *\n * `class`, `className`, `classList` and `style` are combined into one `class` and one `style`\n * attribute; other keys are attributes, with React names mapped (`htmlFor` is `for`) and HTML boolean\n * attributes (`disabled`, `checked`, ...) written as bare names. `ref`, `children`, `on*` keys and the\n * `on:`, `use:` and `prop:` prefixes are skipped; `attr:` and `bool:` select the attribute and presence\n * forms. `innerHTML` and `dangerouslySetInnerHTML` are written unescaped as the content. On a\n * `textarea` the `value` (or `defaultValue`) is the content; on a `select` it marks the matching\n * `<option selected>` (an array for `multiple`); on other elements `defaultValue` and `defaultChecked`\n * are the `value` and `checked` attributes. Void elements (`img`, `input`, ...) get no content.\n *\n * @param tag Element name: letters, digits and dashes, starting with a letter.\n * @param props The props object (each getter is read once), or `null`.\n * @param children The content, escaped unless it is an `SsrNode`. Undefined (the default) uses the\n * `children` prop.\n * @param needsKey `true` writes the hydration key of this template root first. Default: `false`.\n * @param svg `true` for an SVG element: SVG presentation names are hyphenated (`strokeWidth` is\n * `stroke-width`), other names keep their case. Default: `false`.\n * @returns The element as a trusted `SsrNode`.\n * @throws TypeError `INVALID_TAG_NAME` for an invalid tag, `INVALID_ATTRIBUTE_NAME` for an invalid\n * attribute name, and the errors of {@link ssrAttribute}, `ssrClass` and `ssrStyle` for invalid values.\n * @example\n * import { renderToString, ssrElement } from \"@shadow-js/web/server\";\n *\n * const props = { id: \"save\", disabled: true, class: [\"btn\", { primary: true }], children: \"Save\" };\n * const html = renderToString(() => ssrElement(\"button\", props));\n * // '<button id=\"save\" disabled class=\"btn primary\">Save</button>'\n * @since 1.0.0\n */\nexport function ssrElement(\n tag: string,\n props: unknown,\n children: unknown = undefined,\n needsKey = false,\n svg = false,\n): SsrNode {\n if (typeof tag !== \"string\" || !TAG_NAME.test(tag)) {\n throw invalid(\"INVALID_TAG_NAME\", `\"${String(tag)}\" is not a valid tag name.`);\n }\n const lowerTag = tag.toLowerCase();\n // A browser ignores `value` on these: a textarea's value is its content, a select's value is the\n // `selected` flag of its options. The props are read once and applied to the content below.\n const isSelect = lowerTag === \"select\";\n const isTextarea = lowerTag === \"textarea\";\n const control: { value?: unknown; fallback?: unknown } = {};\n let hasValue = false;\n let hasFallback = false;\n let attributes = needsKey ? ssrHydrationKey() : \"\";\n const classes: string[] = [];\n let style = \"\";\n let innerHtml: string | undefined;\n if (props !== null && typeof props === \"object\") {\n for (const key of Object.keys(props)) {\n if (SKIPPED_KEYS.has(key) || IGNORED_KEYS.test(key)) continue;\n if (\n key === \"ref\" ||\n key.startsWith(\"on:\") ||\n key.startsWith(\"use:\") ||\n key.startsWith(\"prop:\")\n )\n continue;\n if (isEventName(key)) continue;\n if (needsKey && key === \"data-hk\") continue;\n const value = resolveValue(Reflect.get(props, key));\n if (key === \"class\" || key === \"className\") {\n const text = classText(value);\n if (text !== \"\") classes.push(text);\n } else if (key === \"classList\") {\n collectTruthyKeys(value, classes);\n } else if (key === \"style\") {\n style = styleText(value);\n } else if (key === \"innerHTML\") {\n innerHtml = plainHtml(value);\n } else if (key === \"dangerouslySetInnerHTML\") {\n innerHtml = plainHtml(resolveValue(innerHtmlOfValue(value)));\n } else if ((isSelect || isTextarea) && key === \"value\") {\n control.value = value;\n hasValue = true;\n } else if ((isSelect || isTextarea) && key === \"defaultValue\") {\n control.fallback = value;\n hasFallback = true;\n } else if (key.startsWith(\"attr:\")) {\n attributes += ssrAttribute(key.slice(5), value);\n } else if (key.startsWith(\"bool:\")) {\n attributes += ssrAttribute(key.slice(5), value, true);\n } else if (key === \"defaultValue\" || key === \"defaultChecked\") {\n // The attributes of the same name in HTML are the defaults: `value` and `checked`.\n const name = key === \"defaultValue\" ? \"value\" : \"checked\";\n if (!Object.hasOwn(props, name))\n attributes += ssrAttribute(name, value, name === \"checked\");\n } else {\n const name = attributeName(key, svg);\n attributes += ssrAttribute(name, value, isFlagAttribute(name, value));\n }\n }\n }\n if (classes.length > 0) attributes += ` class=\"${escapeHtml(classes.join(\" \"))}\"`;\n if (style !== \"\") attributes += ssrStyle(style);\n if (VOID_ELEMENTS.has(lowerTag)) return new SsrNode(`<${tag}${attributes}>`);\n // Like the DOM `spread`: a `children` prop supplies the content unless the element wrote its own.\n // The text of a script or a style is raw (no entities), so it is written as it is and checked instead.\n const raw = !svg && (lowerTag === \"script\" || lowerTag === \"style\");\n const given = children === undefined ? propsChildren(props) : children;\n let content =\n innerHtml !== undefined ? innerHtml : raw ? rawElementContent(lowerTag, given) : escape(given);\n if (innerHtml === undefined && (hasValue || hasFallback)) {\n const value = hasValue ? control.value : control.fallback;\n content = isTextarea ? textareaContent(value) : markSelectedOptions(value, content);\n } else if (\n (isTextarea || lowerTag === \"pre\" || lowerTag === \"listing\") &&\n innerHtml === undefined\n ) {\n // The parser drops one line break right after these start tags (a textarea's children are its\n // value, as on the client): write one more so the content is read as it was given.\n content = keepLeadingNewline(content);\n }\n return new SsrNode(`<${tag}${attributes}>${content}</${tag}>`);\n}\n\n/** The `children` of a spread props object (read once, so a getter runs once), or undefined. */\nfunction propsChildren(props: unknown): unknown {\n if (props === null || typeof props !== \"object\") return undefined;\n return Reflect.get(props, \"children\");\n}\n\n/** Class names whose key is truthy, from a `classList` object. */\nfunction collectTruthyKeys(value: unknown, out: string[]): void {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return;\n for (const key of Object.keys(value)) {\n if (key !== \"\" && resolveValue(Reflect.get(value, key))) out.push(key);\n }\n}\n\n/** Raw HTML text for `innerHTML`: null and undefined become \"\", an SsrNode its markup. */\nfunction plainHtml(value: unknown): string {\n if (value === null || value === undefined) return \"\";\n if (isSsrNode(value)) return value.t;\n if (typeof value === \"symbol\")\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be innerHTML.\");\n return String(value);\n}\n"],"mappings":"A,6lBAYA,MAAMA,EAAW,0BAGXC,kBAAqC,IAAI,IAAI,CACjD,OACA,OACA,KACA,MACA,UACA,QACA,KACA,MACA,QACA,SACA,OACA,OACA,QACA,SACA,QACA,KACF,CAAC,EAGKC,kBAAoC,IAAI,IAAI,CAChD,YACA,cACA,YACA,WACA,KACF,CAAC,EAGD,SAASC,EAAiB,EAAyB,CACjD,GAAsB,OAAOC,GAAU,UAAnCA,EACJ,OAAO,QAAQ,IAAIA,EAAO,QAAQ,CACpC,CAsBA,SAAgBC,EAAI,EAA0B,GAAGC,EAA2B,CAC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hB,CAAK,CACrB,C"}
|
|
1
|
+
{"version":3,"file":"element.js","names":["nextKey","IGNORED_KEYS","attributeName","isFlagAttribute","isEventName","ssrAttribute","classText","ssrStyle","styleText","invalid","escape","escapeHtml","resolveValue","keepLeadingNewline","markSelectedOptions","textareaContent","SsrNode","isSsrNode","rawElementContent","TAG_NAME","VOID_ELEMENTS","SKIPPED_KEYS","innerHtmlOfValue","value","ssr","parts","holes","html","index","hole","ssrRaw","ssrHydrationKey","key","ssrElement","tag","props","children","needsKey","svg","lowerTag","isSelect","isTextarea","control","hasValue","hasFallback","attributes","classes","style","innerHtml","text","collectTruthyKeys","plainHtml","name","raw","given","propsChildren","content","out"],"sources":["../../../src/server/element.ts"],"sourcesContent":["import { nextKey } from \"../internal/hydration-scope\";\nimport { attributeName, IGNORED_KEYS, isFlagAttribute } from \"../internal/react-names\";\nimport { isEventName, ssrAttribute } from \"./attributes\";\nimport { classText, ssrStyle, styleText } from \"./class-style\";\nimport { invalid } from \"./errors\";\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name \"escape\" is part of the compiler contract (SSR output).\nimport { escape, escapeHtml, resolveValue } from \"./escape\";\nimport { keepLeadingNewline, markSelectedOptions, textareaContent } from \"./form-controls\";\nimport { isSsrNode, SsrNode } from \"./node\";\nimport { rawElementContent } from \"./raw-text\";\n\n/** A tag name: letters, digits and dashes, starting with a letter. Anything else could break out. */\nconst TAG_NAME = /^[A-Za-z][A-Za-z0-9-]*$/;\n\n/** Elements that never have children or a closing tag. */\nconst VOID_ELEMENTS: ReadonlySet<string> = new Set([\n \"area\",\n \"base\",\n \"br\",\n \"col\",\n \"command\",\n \"embed\",\n \"hr\",\n \"img\",\n \"input\",\n \"keygen\",\n \"link\",\n \"meta\",\n \"param\",\n \"source\",\n \"track\",\n \"wbr\",\n]);\n\n/** Keys that never become attributes: they are handled elsewhere or would reach a prototype. */\nconst SKIPPED_KEYS: ReadonlySet<string> = new Set([\n \"__proto__\",\n \"constructor\",\n \"prototype\",\n \"children\",\n \"ref\",\n]);\n\n/** The HTML of a `dangerouslySetInnerHTML` value (`{ __html }`): null and undefined are empty. */\nfunction innerHtmlOfValue(value: unknown): unknown {\n if (value === null || typeof value !== \"object\") return undefined;\n return Reflect.get(value, \"__html\");\n}\n\n/**\n * Joins the static parts of a server template with its dynamic holes into trusted markup: the\n * function compiled server output calls for each element tree. Holes are inserted unchanged, so each\n * must already be escaped (the output of `escape`, `ssrAttribute`, `ssrClass`, ...) or an `SsrNode`;\n * any other value throws, so a raw user value cannot reach the markup.\n *\n * @param parts The static markup, one more entry than there are holes.\n * @param holes The dynamic parts: strings produced by the escaping helpers, or `SsrNode` values.\n * @returns The markup as a trusted `SsrNode`, which `escape` writes without encoding.\n * @throws TypeError when `parts` is not an array of `holes.length + 1` entries, or when a hole is not\n * a string or an `SsrNode`.\n * @example\n * import { escape, renderToString, ssr } from \"@shadow-js/web/server\";\n *\n * const name = \"<Ada>\";\n * const html = renderToString(() => ssr([\"<p>Hello, \", \"</p>\"], escape(name)));\n * // \"<p>Hello, <Ada></p>\"\n * @see ssrRaw\n * @since 1.0.0\n */\nexport function ssr(parts: readonly string[], ...holes: unknown[]): SsrNode {\n if (!Array.isArray(parts) || parts.length !== holes.length + 1) {\n throw new TypeError(\"ssr(): parts must have one more entry than there are holes.\");\n }\n let html = parts[0] ?? \"\";\n for (let index = 0; index < holes.length; index += 1) {\n const hole = holes[index];\n if (typeof hole === \"string\") html += hole;\n else if (isSsrNode(hole)) html += hole.t;\n else throw new TypeError(\"ssr(): a hole must be an escaped string or an SsrNode.\");\n html += parts[index + 1] ?? \"\";\n }\n return new SsrNode(html);\n}\n\n/**\n * Marks a string as trusted markup that `escape` and `ssr` insert unchanged. Only use it for markup\n * the application wrote itself, never for user input.\n *\n * @param html The markup, inserted unchanged.\n * @returns The markup as a trusted `SsrNode`.\n * @throws TypeError when `html` is not a string.\n * @example\n * import { renderToString, ssrRaw } from \"@shadow-js/web/server\";\n *\n * const html = renderToString(() => [\"<b>escaped</b>\", ssrRaw(\"<!-- build 42 -->\")]);\n * // \"<b>escaped</b><!-- build 42 -->\"\n * @see ssr\n * @since 1.0.0\n */\nexport function ssrRaw(html: string): SsrNode {\n if (typeof html !== \"string\") throw new TypeError(\"ssrRaw(): the markup must be a string.\");\n return new SsrNode(html);\n}\n\n/**\n * Draws the next hydration key of the current scope and returns it as a `data-hk` attribute, such as\n * `' data-hk=\"0-0\"'`: compiled server output calls it for the root element of each template, and\n * the client's `hydrate()` claims the element by that key. Calls must happen in the same order as on\n * the client, so call it only where the compiler would.\n *\n * @returns Markup for the `data-hk` attribute, or `\"\"` outside a server render (no key is drawn).\n * @example\n * import { renderToString, ssr, ssrHydrationKey } from \"@shadow-js/web/server\";\n *\n * const html = renderToString(() => ssr([\"<div\", \">x</div>\"], ssrHydrationKey()));\n * // '<div data-hk=\"0-0\">x</div>'\n * @since 1.0.0\n */\nexport function ssrHydrationKey(): string {\n const key = nextKey();\n return key === undefined ? \"\" : ` data-hk=\"${escapeHtml(key)}\"`;\n}\n\n/**\n * Renders an element from a props object: what compiled server output calls for an element with a\n * spread (`<div {...props} />`), and the server half of `Dynamic` and `element`. It writes the same\n * markup the client's `spread` produces.\n *\n * `class`, `className`, `classList` and `style` are combined into one `class` and one `style`\n * attribute; other keys are attributes, with React names mapped (`htmlFor` is `for`) and HTML boolean\n * attributes (`disabled`, `checked`, ...) written as bare names. `ref`, `children`, `on*` keys and the\n * `on:`, `use:` and `prop:` prefixes are skipped; `attr:` and `bool:` select the attribute and presence\n * forms. `innerHTML` and `dangerouslySetInnerHTML` are written unescaped as the content. On a\n * `textarea` the `value` (or `defaultValue`) is the content; on a `select` it marks the matching\n * `<option selected>` (an array for `multiple`); on other elements `defaultValue` and `defaultChecked`\n * are the `value` and `checked` attributes. Void elements (`img`, `input`, ...) get no content.\n *\n * @param tag Element name: letters, digits and dashes, starting with a letter.\n * @param props The props object (each getter is read once), or `null`.\n * @param children The content, escaped unless it is an `SsrNode`. Undefined (the default) uses the\n * `children` prop.\n * @param needsKey `true` writes the hydration key of this template root first. Default: `false`.\n * @param svg `true` for an SVG element: SVG presentation names are hyphenated (`strokeWidth` is\n * `stroke-width`), other names keep their case. Default: `false`.\n * @returns The element as a trusted `SsrNode`.\n * @throws TypeError `INVALID_TAG_NAME` for an invalid tag, `INVALID_ATTRIBUTE_NAME` for an invalid\n * attribute name, and the errors of {@link ssrAttribute}, `ssrClass` and `ssrStyle` for invalid values.\n * @example\n * import { renderToString, ssrElement } from \"@shadow-js/web/server\";\n *\n * const props = { id: \"save\", disabled: true, class: [\"btn\", { primary: true }], children: \"Save\" };\n * const html = renderToString(() => ssrElement(\"button\", props));\n * // '<button id=\"save\" disabled class=\"btn primary\">Save</button>'\n * @since 1.0.0\n */\nexport function ssrElement(\n tag: string,\n props: unknown,\n children: unknown = undefined,\n needsKey = false,\n svg = false,\n): SsrNode {\n if (typeof tag !== \"string\" || !TAG_NAME.test(tag)) {\n throw invalid(\"INVALID_TAG_NAME\", `\"${String(tag)}\" is not a valid tag name.`);\n }\n const lowerTag = tag.toLowerCase();\n // A browser ignores `value` on these: a textarea's value is its content, a select's value is the\n // `selected` flag of its options. The props are read once and applied to the content below.\n const isSelect = lowerTag === \"select\";\n const isTextarea = lowerTag === \"textarea\";\n const control: { value?: unknown; fallback?: unknown } = {};\n let hasValue = false;\n let hasFallback = false;\n let attributes = needsKey ? ssrHydrationKey() : \"\";\n const classes: string[] = [];\n let style = \"\";\n let innerHtml: string | undefined;\n if (props !== null && typeof props === \"object\") {\n for (const key of Object.keys(props)) {\n if (SKIPPED_KEYS.has(key) || IGNORED_KEYS.test(key)) continue;\n if (\n key === \"ref\" ||\n key.startsWith(\"on:\") ||\n key.startsWith(\"use:\") ||\n key.startsWith(\"prop:\")\n )\n continue;\n if (isEventName(key)) continue;\n if (needsKey && key === \"data-hk\") continue;\n const value = resolveValue(Reflect.get(props, key));\n if (key === \"class\" || key === \"className\") {\n const text = classText(value);\n if (text !== \"\") classes.push(text);\n } else if (key === \"classList\") {\n collectTruthyKeys(value, classes);\n } else if (key === \"style\") {\n style = styleText(value);\n } else if (key === \"innerHTML\") {\n innerHtml = plainHtml(value);\n } else if (key === \"dangerouslySetInnerHTML\") {\n innerHtml = plainHtml(resolveValue(innerHtmlOfValue(value)));\n } else if ((isSelect || isTextarea) && key === \"value\") {\n control.value = value;\n hasValue = true;\n } else if ((isSelect || isTextarea) && key === \"defaultValue\") {\n control.fallback = value;\n hasFallback = true;\n } else if (key.startsWith(\"attr:\")) {\n attributes += ssrAttribute(key.slice(5), value);\n } else if (key.startsWith(\"bool:\")) {\n attributes += ssrAttribute(key.slice(5), value, true);\n } else if (key === \"defaultValue\" || key === \"defaultChecked\") {\n // The attributes of the same name in HTML are the defaults: `value` and `checked`.\n const name = key === \"defaultValue\" ? \"value\" : \"checked\";\n if (!Object.hasOwn(props, name))\n attributes += ssrAttribute(name, value, name === \"checked\");\n } else {\n const name = attributeName(key, svg);\n attributes += ssrAttribute(name, value, isFlagAttribute(name, value));\n }\n }\n }\n if (classes.length > 0) attributes += ` class=\"${escapeHtml(classes.join(\" \"))}\"`;\n if (style !== \"\") attributes += ssrStyle(style);\n if (VOID_ELEMENTS.has(lowerTag)) return new SsrNode(`<${tag}${attributes}>`);\n // Like the DOM `spread`: a `children` prop supplies the content unless the element wrote its own.\n // The text of a script or a style is raw (no entities), so it is written as it is and checked instead.\n const raw = !svg && (lowerTag === \"script\" || lowerTag === \"style\");\n const given = children === undefined ? propsChildren(props) : children;\n let content =\n innerHtml !== undefined ? innerHtml : raw ? rawElementContent(lowerTag, given) : escape(given);\n if (innerHtml === undefined && (hasValue || hasFallback)) {\n const value = hasValue ? control.value : control.fallback;\n content = isTextarea ? textareaContent(value) : markSelectedOptions(value, content);\n } else if (\n (isTextarea || lowerTag === \"pre\" || lowerTag === \"listing\") &&\n innerHtml === undefined\n ) {\n // The parser drops one line break right after these start tags (a textarea's children are its\n // value, as on the client): write one more so the content is read as it was given.\n content = keepLeadingNewline(content);\n }\n return new SsrNode(`<${tag}${attributes}>${content}</${tag}>`);\n}\n\n/** The `children` of a spread props object (read once, so a getter runs once), or undefined. */\nfunction propsChildren(props: unknown): unknown {\n if (props === null || typeof props !== \"object\") return undefined;\n return Reflect.get(props, \"children\");\n}\n\n/** Class names whose key is truthy, from a `classList` object. */\nfunction collectTruthyKeys(value: unknown, out: string[]): void {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return;\n for (const key of Object.keys(value)) {\n if (key !== \"\" && resolveValue(Reflect.get(value, key))) out.push(key);\n }\n}\n\n/** Raw HTML text for `innerHTML`: null and undefined become \"\", an SsrNode its markup. */\nfunction plainHtml(value: unknown): string {\n if (value === null || value === undefined) return \"\";\n if (isSsrNode(value)) return value.t;\n if (typeof value === \"symbol\")\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be innerHTML.\");\n return String(value);\n}\n"],"mappings":"A,6lBAYA,MAAMmB,EAAW,0BAGXC,kBAAqC,IAAI,IAAI,CACjD,OACA,OACA,KACA,MACA,UACA,QACA,KACA,MACA,QACA,SACA,OACA,OACA,QACA,SACA,QACA,KACF,CAAC,EAGKC,kBAAoC,IAAI,IAAI,CAChD,YACA,cACA,YACA,WACA,KACF,CAAC,EAGD,SAASC,EAAiBC,EAAyB,CACjD,GAAsB,OAAOA,GAAU,UAAnCA,EACJ,OAAO,QAAQ,IAAIA,EAAO,QAAQ,CACpC,CAsBA,SAAgBC,EAAIC,EAA0B,GAAGC,EAA2B,CAC1E,GAAI,CAAC,MAAM,QAAQD,CAAK,GAAKA,EAAM,SAAWC,EAAM,OAAS,EAC3D,MAAU,UAAU,6DAA6D,EAEnF,IAAIC,EAAOF,EAAM,IAAM,GACvB,IAAK,IAAIG,EAAQ,EAAGA,EAAQF,EAAM,OAAQE,GAAS,EAAG,CACpD,IAAMC,EAAOH,EAAME,GACnB,GAAI,OAAOC,GAAS,SAAUF,GAAQE,OACjC,GAAIZ,EAAUY,CAAI,EAAGF,GAAQE,EA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,IAAA,GAAwBK,EAAMnC,EAAkBqB,EAAUe,CAAK,EAAI5C,EAAO4C,CAAK,EAAnEN,EAC5B,GAAIA,IAAc,IAAA,KAAcL,GAAYC,GAAc,CACxD,IAAMrB,EAAQoB,EAAWD,EAAQ,MAAQA,EAAQ,SACjDc,EAAUf,EAAa1B,EAAgBQ,CAAK,EAAIT,EAAoBS,EAAOiC,CAAO,CACpF,MACGf,GAAcF,IAAa,OAASA,IAAa,YAClDS,IAAc,IAAA,KAIdQ,EAAU3C,EAAmB2C,CAAO,GAEtC,OAAO,IAAIxC,EAAQ,IAAIkB,IAAMW,EAAW,GAAGW,EAAQ,IAAItB,EAAI,EAAE,CAC/D,CAGA,SAASqB,EAAcpB,EAAyB,CAC9C,GAAsB,OAAOA,GAAU,UAAnCA,EACJ,OAAO,QAAQ,IAAIA,EAAO,UAAU,CACtC,CAGA,SAASe,EAAkB3B,EAAgBkC,EAAqB,CAC9D,GAAsB,OAAOlC,GAAU,UAAnCA,GAA+C,OAAM,QAAQA,CAAK,EACtE,IAAK,IAAMS,KAAO,OAAO,KAAKT,CAAK,EAC7BS,IAAQ,IAAMpB,EAAa,QAAQ,IAAIW,EAAOS,CAAG,CAAC,GAAGyB,EAAI,KAAKzB,CAAG,CAEzE,CAGA,SAASmB,EAAU5B,EAAwB,CACzC,GAAIA,GAAU,KAA6B,MAAO,GAClD,GAAIN,EAAUM,CAAK,EAAG,OAAOA,EAAM,EACnC,GAAI,OAAOA,GAAU,SACnB,MAAMd,EAAQ,4BAA6B,+BAA+B,EAC5E,OAAO,OAAOc,CAAK,CACrB,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":["SsrError","code","invalid","MAX_TIMER_MS"],"sources":["../../../src/server/errors.ts"],"sourcesContent":["/** Diagnostic codes raised by the server renderer. @internal */\nexport type SsrErrorCode = \"SSR_BOUNDARY_WATERFALL\" | \"SSR_PORTAL_LIMIT\" | \"SSR_TIMEOUT\";\n\n/**\n * Error thrown by the server renderer, carrying a stable code. Dev builds carry the full text;\n * production builds keep only the code (the same split as core's diagnostics).\n * @internal\n */\nexport class SsrError extends Error {\n readonly code: SsrErrorCode;\n constructor(code: SsrErrorCode, detail: string) {\n super(__DEV__ ? `[shadow ${code}] ${detail}` : `SHADOW_${code}`);\n this.name = \"SsrError\";\n this.code = code;\n }\n}\n\n/**\n * A TypeError for input the renderer refuses: a value that could become unsafe markup, or a\n * malformed argument. Dev builds carry the detail; production builds keep the code.\n * @internal\n */\nexport function invalid(code: string, detail: string): TypeError {\n return new TypeError(__DEV__ ? `[shadow ${code}] ${detail}` : `SHADOW_${code}`);\n}\n\n/**\n * The longest delay `setTimeout` honors: larger values fire after one millisecond. A budget above it\n * (`Number.MAX_SAFE_INTEGER` for \"no limit\") is clamped here instead of ending every render at once.\n * @internal\n */\nexport const MAX_TIMER_MS = 2_147_483_647;\n"],"mappings":"AAQA,IAAaA,EAAb,cAA8B,KAAM,
|
|
1
|
+
{"version":3,"file":"errors.js","names":["SsrError","code","detail","invalid","MAX_TIMER_MS"],"sources":["../../../src/server/errors.ts"],"sourcesContent":["/** Diagnostic codes raised by the server renderer. @internal */\nexport type SsrErrorCode = \"SSR_BOUNDARY_WATERFALL\" | \"SSR_PORTAL_LIMIT\" | \"SSR_TIMEOUT\";\n\n/**\n * Error thrown by the server renderer, carrying a stable code. Dev builds carry the full text;\n * production builds keep only the code (the same split as core's diagnostics).\n * @internal\n */\nexport class SsrError extends Error {\n readonly code: SsrErrorCode;\n constructor(code: SsrErrorCode, detail: string) {\n super(__DEV__ ? `[shadow ${code}] ${detail}` : `SHADOW_${code}`);\n this.name = \"SsrError\";\n this.code = code;\n }\n}\n\n/**\n * A TypeError for input the renderer refuses: a value that could become unsafe markup, or a\n * malformed argument. Dev builds carry the detail; production builds keep the code.\n * @internal\n */\nexport function invalid(code: string, detail: string): TypeError {\n return new TypeError(__DEV__ ? `[shadow ${code}] ${detail}` : `SHADOW_${code}`);\n}\n\n/**\n * The longest delay `setTimeout` honors: larger values fire after one millisecond. A budget above it\n * (`Number.MAX_SAFE_INTEGER` for \"no limit\") is clamped here instead of ending every render at once.\n * @internal\n */\nexport const MAX_TIMER_MS = 2_147_483_647;\n"],"mappings":"AAQA,IAAaA,EAAb,cAA8B,KAAM,CACzB,KACT,YAAYC,EAAoBC,EAAgB,CAC9C,MAA+C,UAAUD,GAAM,EAC/D,KAAK,KAAO,WACZ,KAAK,KAAOA,CACd,CACF,EAOA,SAAgBE,EAAQF,EAAcC,EAA2B,CAC/D,MAAO,gBAAI,UAAmD,UAAUD,GAAM,CAChF,CAOA,MAAaG,EAAe,W"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"escape.js","names":["accessor","HTML_ESCAPES","HTML_SPECIAL","escapeHtml","text","char","resolveValue","
|
|
1
|
+
{"version":3,"file":"escape.js","names":["accessor","invalid","isSsrNode","untrack","HTML_ESCAPES","HTML_SPECIAL","escapeHtml","text","char","resolveValue","value","current","layer","appendLeaf","out","escape","render","frames","cursors","open","item","resolved","next","found","top","frame","cursor"],"sources":["../../../src/server/escape.ts"],"sourcesContent":["import { untrack } from \"@shadow-js/core\";\nimport { invalid } from \"./errors\";\nimport { isSsrNode } from \"./node\";\n\nconst HTML_ESCAPES: Readonly<Record<string, string>> = {\n \"&\": \"&\",\n \"<\": \"<\",\n \">\": \">\",\n '\"': \""\",\n \"'\": \"'\",\n};\n\nconst HTML_SPECIAL = /[&<>\"']/g;\n\n/** Longest chain of accessors that returns accessors; longer chains are a bug in user code. */\nconst MAX_ACCESSOR_LAYERS = 1000;\n\n/**\n * Escapes the five HTML-significant characters. Escaping `&` too means entity-looking text is\n * written literally, and the result is safe in text and in quoted attribute values alike.\n * @internal\n */\nexport function escapeHtml(text: string): string {\n return text.replace(HTML_SPECIAL, (char) => HTML_ESCAPES[char] ?? char);\n}\n\n/**\n * Calls accessors until a plain value remains. Accessors run untracked; a chain longer than\n * {@link MAX_ACCESSOR_LAYERS} throws instead of looping.\n * @internal\n */\nexport function resolveValue(value: unknown): unknown {\n let current = value;\n for (let layer = 0; typeof current === \"function\"; layer += 1) {\n if (layer >= MAX_ACCESSOR_LAYERS) {\n throw new TypeError(\"An accessor returns accessors more than 1000 levels deep.\");\n }\n const accessor = current as () => unknown;\n current = untrack(accessor);\n }\n return current;\n}\n\n/** Writes the markup for one resolved value that is not an array; `text` encodes the text of a string. */\nfunction appendLeaf(value: unknown, out: string[], text: (value: string) => string): void {\n if (value === null || value === undefined || typeof value === \"boolean\") return;\n if (typeof value === \"string\") {\n out.push(text(value));\n return;\n }\n // Numbers and bigints never contain markup characters.\n if (typeof value === \"number\" || typeof value === \"bigint\") {\n out.push(String(value));\n return;\n }\n if (typeof value === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be rendered.\");\n }\n if (isSsrNode(value)) {\n out.push(value.t);\n return;\n }\n // Any other object is not trusted markup. Dev fails loudly; production renders nothing.\n if (typeof value === \"object\") {\n if (__DEV__) {\n throw invalid(\n \"UNRECOGNIZED_INSERT_VALUE\",\n \"A plain object cannot be rendered. Use a string, a number, an array or an SsrNode.\",\n );\n }\n return;\n }\n out.push(text(String(value)));\n}\n\n/**\n * Converts any value a JSX child may hold to escaped HTML: the helper compiled server output calls\n * for every dynamic child, and what the renderers call on the app's result.\n *\n * - Strings are escaped (`& < > \" '`); numbers and bigints are written as they are; `null`,\n * `undefined` and booleans render nothing.\n * - `SsrNode` values (from `ssr`, `ssrRaw` and the other helpers) pass through unchanged: they were\n * escaped when they were built.\n * - Accessors are called (untracked) and their result is rendered; a chain of more than 1000\n * accessors returning accessors throws.\n * - Arrays are flattened in order, with an explicit stack, so nesting depth is not limited by the\n * call stack.\n * - Plain objects throw in development builds and render nothing in production builds.\n *\n * @param value The value to render.\n * @returns The escaped markup.\n * @throws TypeError when an array contains itself, for a symbol (`UNRECOGNIZED_INSERT_VALUE`), for an\n * object that is not an `SsrNode` (`UNRECOGNIZED_INSERT_VALUE`, development builds only), and for an\n * accessor chain deeper than 1000.\n * @example\n * import { escape } from \"@shadow-js/web/server\";\n *\n * const name = () => \"<Ada>\";\n * escape([\"Hello, \", name, null, 3]); // \"Hello, <Ada>3\"\n * @since 1.0.0\n */\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name \"escape\" is part of the compiler contract (SSR output).\nexport function escape(value: unknown): string {\n return render(value, escapeHtml);\n}\n\n/**\n * {@link escape} with the encoding of strings left to the caller: the walk over accessors, arrays and\n * trusted nodes that every kind of text shares (an element's text is encoded one way, a script's another).\n * @internal\n */\nexport function render(value: unknown, text: (value: string) => string): string {\n const out: string[] = [];\n const frames: unknown[][] = [];\n const cursors: number[] = [];\n const open = new Set<unknown[]>();\n let item: unknown = value;\n for (;;) {\n const resolved = resolveValue(item);\n if (Array.isArray(resolved)) {\n if (open.has(resolved)) throw new TypeError(\"escape(): an array contains itself.\");\n open.add(resolved);\n frames.push(resolved);\n cursors.push(0);\n } else {\n appendLeaf(resolved, out, text);\n }\n // Find the next item, closing every array that has no items left.\n let next: unknown;\n let found = false;\n while (!found && frames.length > 0) {\n const top = frames.length - 1;\n const frame = frames[top];\n const cursor = cursors[top] ?? 0;\n if (frame === undefined) break;\n if (cursor < frame.length) {\n cursors[top] = cursor + 1;\n next = frame[cursor];\n found = true;\n } else {\n frames.pop();\n cursors.pop();\n open.delete(frame);\n }\n }\n if (!found) return out.join(\"\");\n item = next;\n }\n}\n"],"mappings":"A,sHAIA,MAAMI,EAAiD,CACrD,IAAK,QACL,IAAK,OACL,IAAK,OACL,IAAK,SACL,IAAK,OACP,EAEMC,EAAe,WAUrB,SAAgBC,EAAWC,EAAsB,CAC/C,OAAOA,EAAK,QAAQF,EAAeG,GAASJ,EAAaI,IAASA,CAAI,CACxE,CAOA,SAAgBC,EAAaC,EAAyB,CACpD,IAAIC,EAAUD,EACd,IAAK,IAAIE,EAAQ,EAAG,OAAOD,GAAY,WAAYC,GAAS,EAAG,CAC7D,GAAIA,GAAS,IACX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EACxBJ,EAAOG,EAAMC,GACbH,EAAQ,KAERN,EAAO,IAAI,EACXC,EAAQ,IAAI,EACZC,EAAK,OAAOM,CAAK,EAErB,CACA,GAAI,CAACF,EAAO,OAAOT,EAAI,KAAK,EAAE,EAC9BM,EAAOE,CACT,CACF,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-controls.js","names":["valueText","value","invalid","textareaContent","keepLeadingNewline","escapeHtml","resolveValue","first","html","ssrTextArea","SsrNode","wantedValues","resolved","values","item","one","WHITESPACE","ENTITY","NAMED_ENTITIES","TAGS","decodeEntities","text","named","whole","code","decimal","hex","tagEnd","quote","index","from","char","optionText","boundary","boundaries","markOptions","out","copied","at","found","attribute","start","attributesFrom","end","source","selectedAt","selectedEnd","match","name","matches","wanted","slash","ssrSelectValue","markSelectedOptions","escape","children"],"sources":["../../../src/server/form-controls.ts"],"sourcesContent":["import { invalid } from \"./errors\";\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name \"escape\" is part of the compiler contract (SSR output).\nimport { escape, escapeHtml, resolveValue } from \"./escape\";\nimport { SsrNode } from \"./node\";\n\n/**\n * Server markup for the controls whose state is not an attribute. A browser ignores `value` on a\n * `<textarea>` and on a `<select>`: the textarea's text is its content, and the select's value is\n * the `selected` flag of its options. These helpers write that markup, so the server HTML shows the\n * same state the client sets and a form posted without JavaScript sends it.\n */\n\n/** Text of a value for a textarea: null and undefined are empty, everything else is its string. */\nfunction valueText(value: unknown): string {\n if (typeof value === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be a form control value.\");\n }\n return value === null || value === undefined ? \"\" : String(value);\n}\n\n/**\n * Markup of a textarea's content. The HTML parser drops one newline directly after `<textarea>`,\n * so a value that starts with a line break gets one more; its content is then exactly the value.\n * @internal\n */\nexport function textareaContent(value: unknown): string {\n return keepLeadingNewline(escapeHtml(valueText(resolveValue(value))));\n}\n\n/** Content markup of a textarea with the line break its parser would drop kept. @internal */\nexport function keepLeadingNewline(html: string): string {\n const first = html.charAt(0);\n return first === \"\\n\" || first === \"\\r\" ? `\\n${html}` : html;\n}\n\n/**\n * Renders the content of a `<textarea>` from its value: the helper compiled server output calls for\n * `<textarea value={...}>` and `defaultValue`, since a browser ignores a `value` attribute on a\n * textarea. The text is escaped, and a value that starts with a line break gets one more, because\n * the HTML parser drops the first one.\n *\n * @param value The value, or an accessor of it. `null` and `undefined` give an empty textarea;\n * anything else is written as `String(value)`.\n * @returns The escaped content as a trusted `SsrNode`.\n * @throws TypeError `UNRECOGNIZED_INSERT_VALUE` when the value is a symbol.\n * @example\n * import { renderToString, ssr, ssrTextArea } from \"@shadow-js/web/server\";\n *\n * const bio = \"Loves <b>tags</b>\";\n * const html = renderToString(() => ssr([\"<textarea>\", \"</textarea>\"], ssrTextArea(bio)));\n * // \"<textarea>Loves <b>tags</b></textarea>\"\n * @see ssrSelectValue\n * @since 1.0.0\n */\nexport function ssrTextArea(value: unknown): SsrNode {\n return new SsrNode(textareaContent(value));\n}\n\n/** The values a select value stands for: an array lists them (`multiple`), anything else is one. */\nfunction wantedValues(value: unknown): { values: Set<string>; many: boolean } {\n const resolved = resolveValue(value);\n if (!Array.isArray(resolved)) return { values: new Set([valueText(resolved)]), many: false };\n const values = new Set<string>();\n for (const item of resolved) {\n const one = resolveValue(item);\n if (one !== null && one !== undefined) values.add(valueText(one));\n }\n return { values, many: true };\n}\n\n/** Characters of the HTML spec's \"ASCII whitespace\". */\nconst WHITESPACE = /[ \\t\\n\\f\\r]+/g;\n/** Entities our own escaping writes, plus numeric references and ` ` from trusted raw markup. */\nconst ENTITY = /&(?:#(\\d+)|#x([0-9a-f]+)|(amp|lt|gt|quot|apos|nbsp));/gi;\nconst NAMED_ENTITIES: Readonly<Record<string, string>> = {\n amp: \"&\",\n lt: \"<\",\n gt: \">\",\n quot: '\"',\n apos: \"'\",\n nbsp: \" \",\n};\n/** Comments and tags inside an option's text (the region markers the compiler writes). */\nconst TAGS = /<!--[\\s\\S]*?-->|<[^>]*>/g;\n/**\n * The next option or optgroup tag, start or end: where an option's text ends. Sources of global\n * expressions, built per call so no `lastIndex` outlives it.\n */\nconst OPTION_BOUNDARY = \"<\\\\/?(?:option|optgroup)(?=[\\\\s/>])\";\n/** One attribute of a start tag: name, then an optional quoted or bare value. */\nconst ATTRIBUTE = \"\\\\s+([^\\\\s\\\"'<>/=]+)(?:\\\\s*=\\\\s*(?:\\\"([^\\\"]*)\\\"|'([^']*)'|([^\\\\s\\\"'=<>`]+)))?\";\n\nfunction decodeEntities(text: string): string {\n return text.replace(ENTITY, (whole, decimal?: string, hex?: string, named?: string) => {\n if (named !== undefined) return NAMED_ENTITIES[named.toLowerCase()] ?? whole;\n const code = decimal !== undefined ? Number(decimal) : Number.parseInt(hex ?? \"\", 16);\n return Number.isInteger(code) &&\n code >= 0 &&\n code <= 0x10ffff &&\n !(code >= 0xd800 && code <= 0xdfff)\n ? String.fromCodePoint(code)\n : whole;\n });\n}\n\n/** Index of the `>` that ends the start tag whose attributes begin at `from`, or -1. Quotes are skipped. */\nfunction tagEnd(html: string, from: number): number {\n let quote = \"\";\n for (let index = from; index < html.length; index += 1) {\n const char = html.charAt(index);\n if (quote !== \"\") {\n if (char === quote) quote = \"\";\n } else if (char === '\"' || char === \"'\") {\n quote = char;\n } else if (char === \">\") {\n return index;\n }\n }\n return -1;\n}\n\n/** The text an option without a `value` attribute stands for: its text content, whitespace collapsed. */\nfunction optionText(html: string, from: number, boundaries: RegExp): string {\n boundaries.lastIndex = from;\n const boundary = boundaries.exec(html);\n const raw = html.slice(from, boundary === null ? html.length : boundary.index);\n return decodeEntities(raw.replace(TAGS, \"\")).replace(WHITESPACE, \" \").trim();\n}\n\n/**\n * Rewrites the option start tags of `html` so that exactly the wanted ones carry `selected`. The\n * input is markup this runtime produced (text and attribute values are escaped, so `<option` is\n * always a tag); only the `selected` attribute is added or removed, and nothing from the wanted\n * values is ever written.\n */\nfunction markOptions(html: string, wanted: { values: Set<string>; many: boolean }): string {\n let out = \"\";\n let copied = 0;\n let at = 0;\n let found = false;\n const attribute = new RegExp(ATTRIBUTE, \"g\");\n const boundaries = new RegExp(OPTION_BOUNDARY, \"gi\");\n for (;;) {\n const start = html.indexOf(\"<option\", at);\n if (start === -1) break;\n const attributesFrom = start + 7;\n at = attributesFrom;\n if (!/[\\s/>]/.test(html.charAt(attributesFrom))) continue;\n const end = tagEnd(html, attributesFrom);\n if (end === -1) break;\n const source = html.slice(attributesFrom, end);\n let value: string | undefined;\n let selectedAt = -1;\n let selectedEnd = -1;\n attribute.lastIndex = 0;\n for (let match = attribute.exec(source); match !== null; match = attribute.exec(source)) {\n const name = (match[1] ?? \"\").toLowerCase();\n if (name === \"selected\") {\n selectedAt = match.index;\n selectedEnd = match.index + match[0].length;\n } else if (name === \"value\" && value === undefined) {\n value = decodeEntities(match[2] ?? match[3] ?? match[4] ?? \"\");\n }\n }\n // A scalar behaves like `select.value = x`: the first option with that value wins.\n const matches =\n (wanted.many || !found) && wanted.values.has(value ?? optionText(html, end + 1, boundaries));\n if (matches) found = true;\n if (matches && selectedAt === -1) {\n const slash = source.endsWith(\"/\") ? source.length - 1 : source.length;\n out += `${html.slice(copied, attributesFrom + slash)} selected`;\n copied = attributesFrom + slash;\n } else if (!matches && selectedAt !== -1) {\n out += html.slice(copied, attributesFrom + selectedAt);\n copied = attributesFrom + selectedEnd;\n }\n at = end;\n }\n return copied === 0 ? html : out + html.slice(copied);\n}\n\n/**\n * The options of a `<select>` with the ones its value stands for marked `selected`. A browser\n * ignores a `value` attribute on `<select>`, so the server flags the options instead: the option\n * whose `value` attribute equals the value (or, with no such attribute, whose text does) is\n * selected, and every other option loses `selected`. An array selects every listed option, for\n * `<select multiple>`; a single value selects the first match, like `select.value = x`. `null`\n * and `undefined` stand for the empty string. Options inside `<optgroup>`, control flow and\n * components are found because the search runs on the serialized children. Values are compared,\n * never written, so they cannot add markup.\n *\n * @param value The select's `value`, or an accessor of it. Entries of an array are compared as\n * strings; `null` and `undefined` entries are skipped.\n * @param children The select's children (an `SsrNode`, or anything `escape` accepts).\n * @returns The children with the `selected` flags set, as a trusted `SsrNode`.\n * @throws TypeError `UNRECOGNIZED_INSERT_VALUE` when the value is a symbol, and the errors of\n * {@link escape} for the children.\n * @example\n * import { renderToString, ssr, ssrRaw, ssrSelectValue } from \"@shadow-js/web/server\";\n *\n * const options = ssrRaw(`<option value=\"red\">Red</option><option value=\"blue\">Blue</option>`);\n * const html = renderToString(() => ssr([\"<select>\", \"</select>\"], ssrSelectValue(\"blue\", options)));\n * // '<select><option value=\"red\">Red</option><option value=\"blue\" selected>Blue</option></select>'\n * @see setSelectValue\n * @since 1.0.0\n */\nexport function ssrSelectValue(value: unknown, children: unknown): SsrNode {\n return new SsrNode(markSelectedOptions(value, escape(children)));\n}\n\n/** {@link ssrSelectValue} on markup that is already escaped. @internal */\nexport function markSelectedOptions(value: unknown, html: string): string {\n return markOptions(html, wantedValues(value));\n}\n"],"mappings":"A,iJAaA,SAASA,EAAU,EAAwB,CACzC,GAAI,OAAOC,GAAU,SACnB,MAAMC,EAAQ,4BAA6B,0CAA0C,EAEvF,OAAOD,GAAU,KAA8B,GAAK,OAAOA,CAAK,CAClE,CAOA,SAAgBE,EAAgB,EAAwB,CACtD,OAAOC,EAAmBC,EAAWL,EAAUM,EAAaL,CAAK,CAAC,CAAC,CAAC,CACtE,CAGA,SAAgBG,EAAmB,EAAsB,CACvD,IAAMG,EAAQC,EAAK,OAAO,CAAC,EAC3B,OAAOD,IAAU;GAAQA,IAAU,KAAO,KAAKC,IAASA,CAC1D,CAqBA,SAAgBC,EAAY,EAAyB,CACnD,OAAO,IAAIC,EAAQP,EAAgBF,CAAK,CAAC,CAC3C,CAGA,SAASU,EAAa,EAAwD,CAC5E,IAAMC,EAAWN,EAAaL,CAAK,EACnC,GAAI,CAAC,MAAM,QAAQW,CAAQ,EAAG,MAAO,CAAE,uBAAQ,IAAI,IAAI,CAACZ,EAAUY,CAAQ,CAAC,CAAC,EA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,EAAiBS,CAAK,EAAE,WACrD,EAAST,EAAiBS,CAC5B,KAAW,CAACF,GAAWJ,IAAe,KACpC,GAAOrC,EAAK,MAAM6B,EAAQK,EAAiBG,CAAU,EACrD,EAASH,EAAiBI,GAE5B,EAAKH,CACP,CACA,OAAON,IAAW,EAAI7B,EAAO4B,EAAM5B,EAAK,MAAM6B,CAAM,CACtD,CA2BA,SAAgBe,EAAe,EAAgB,EAA4B,CACzE,OAAO,IAAI1C,EAAQ2C,EAAoBpD,EAAOqD,EAAOC,CAAQ,CAAC,CAAC,CACjE,CAGA,SAAgBF,EAAoB,EAAgB,EAAsB,CACxE,OAAOlB,EAAY3B,EAAMG,EAAaV,CAAK,CAAC,CAC9C,C"}
|
|
1
|
+
{"version":3,"file":"form-controls.js","names":["invalid","escape","escapeHtml","resolveValue","SsrNode","valueText","value","textareaContent","keepLeadingNewline","html","first","ssrTextArea","wantedValues","resolved","values","item","one","WHITESPACE","ENTITY","NAMED_ENTITIES","TAGS","decodeEntities","text","whole","decimal","hex","named","code","tagEnd","from","quote","index","char","optionText","boundaries","boundary","markOptions","wanted","out","copied","at","found","attribute","start","attributesFrom","end","source","selectedAt","selectedEnd","match","name","matches","slash","ssrSelectValue","children","markSelectedOptions"],"sources":["../../../src/server/form-controls.ts"],"sourcesContent":["import { invalid } from \"./errors\";\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name \"escape\" is part of the compiler contract (SSR output).\nimport { escape, escapeHtml, resolveValue } from \"./escape\";\nimport { SsrNode } from \"./node\";\n\n/**\n * Server markup for the controls whose state is not an attribute. A browser ignores `value` on a\n * `<textarea>` and on a `<select>`: the textarea's text is its content, and the select's value is\n * the `selected` flag of its options. These helpers write that markup, so the server HTML shows the\n * same state the client sets and a form posted without JavaScript sends it.\n */\n\n/** Text of a value for a textarea: null and undefined are empty, everything else is its string. */\nfunction valueText(value: unknown): string {\n if (typeof value === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be a form control value.\");\n }\n return value === null || value === undefined ? \"\" : String(value);\n}\n\n/**\n * Markup of a textarea's content. The HTML parser drops one newline directly after `<textarea>`,\n * so a value that starts with a line break gets one more; its content is then exactly the value.\n * @internal\n */\nexport function textareaContent(value: unknown): string {\n return keepLeadingNewline(escapeHtml(valueText(resolveValue(value))));\n}\n\n/** Content markup of a textarea with the line break its parser would drop kept. @internal */\nexport function keepLeadingNewline(html: string): string {\n const first = html.charAt(0);\n return first === \"\\n\" || first === \"\\r\" ? `\\n${html}` : html;\n}\n\n/**\n * Renders the content of a `<textarea>` from its value: the helper compiled server output calls for\n * `<textarea value={...}>` and `defaultValue`, since a browser ignores a `value` attribute on a\n * textarea. The text is escaped, and a value that starts with a line break gets one more, because\n * the HTML parser drops the first one.\n *\n * @param value The value, or an accessor of it. `null` and `undefined` give an empty textarea;\n * anything else is written as `String(value)`.\n * @returns The escaped content as a trusted `SsrNode`.\n * @throws TypeError `UNRECOGNIZED_INSERT_VALUE` when the value is a symbol.\n * @example\n * import { renderToString, ssr, ssrTextArea } from \"@shadow-js/web/server\";\n *\n * const bio = \"Loves <b>tags</b>\";\n * const html = renderToString(() => ssr([\"<textarea>\", \"</textarea>\"], ssrTextArea(bio)));\n * // \"<textarea>Loves <b>tags</b></textarea>\"\n * @see ssrSelectValue\n * @since 1.0.0\n */\nexport function ssrTextArea(value: unknown): SsrNode {\n return new SsrNode(textareaContent(value));\n}\n\n/** The values a select value stands for: an array lists them (`multiple`), anything else is one. */\nfunction wantedValues(value: unknown): { values: Set<string>; many: boolean } {\n const resolved = resolveValue(value);\n if (!Array.isArray(resolved)) return { values: new Set([valueText(resolved)]), many: false };\n const values = new Set<string>();\n for (const item of resolved) {\n const one = resolveValue(item);\n if (one !== null && one !== undefined) values.add(valueText(one));\n }\n return { values, many: true };\n}\n\n/** Characters of the HTML spec's \"ASCII whitespace\". */\nconst WHITESPACE = /[ \\t\\n\\f\\r]+/g;\n/** Entities our own escaping writes, plus numeric references and ` ` from trusted raw markup. */\nconst ENTITY = /&(?:#(\\d+)|#x([0-9a-f]+)|(amp|lt|gt|quot|apos|nbsp));/gi;\nconst NAMED_ENTITIES: Readonly<Record<string, string>> = {\n amp: \"&\",\n lt: \"<\",\n gt: \">\",\n quot: '\"',\n apos: \"'\",\n nbsp: \" \",\n};\n/** Comments and tags inside an option's text (the region markers the compiler writes). */\nconst TAGS = /<!--[\\s\\S]*?-->|<[^>]*>/g;\n/**\n * The next option or optgroup tag, start or end: where an option's text ends. Sources of global\n * expressions, built per call so no `lastIndex` outlives it.\n */\nconst OPTION_BOUNDARY = \"<\\\\/?(?:option|optgroup)(?=[\\\\s/>])\";\n/** One attribute of a start tag: name, then an optional quoted or bare value. */\nconst ATTRIBUTE = \"\\\\s+([^\\\\s\\\"'<>/=]+)(?:\\\\s*=\\\\s*(?:\\\"([^\\\"]*)\\\"|'([^']*)'|([^\\\\s\\\"'=<>`]+)))?\";\n\nfunction decodeEntities(text: string): string {\n return text.replace(ENTITY, (whole, decimal?: string, hex?: string, named?: string) => {\n if (named !== undefined) return NAMED_ENTITIES[named.toLowerCase()] ?? whole;\n const code = decimal !== undefined ? Number(decimal) : Number.parseInt(hex ?? \"\", 16);\n return Number.isInteger(code) &&\n code >= 0 &&\n code <= 0x10ffff &&\n !(code >= 0xd800 && code <= 0xdfff)\n ? String.fromCodePoint(code)\n : whole;\n });\n}\n\n/** Index of the `>` that ends the start tag whose attributes begin at `from`, or -1. Quotes are skipped. */\nfunction tagEnd(html: string, from: number): number {\n let quote = \"\";\n for (let index = from; index < html.length; index += 1) {\n const char = html.charAt(index);\n if (quote !== \"\") {\n if (char === quote) quote = \"\";\n } else if (char === '\"' || char === \"'\") {\n quote = char;\n } else if (char === \">\") {\n return index;\n }\n }\n return -1;\n}\n\n/** The text an option without a `value` attribute stands for: its text content, whitespace collapsed. */\nfunction optionText(html: string, from: number, boundaries: RegExp): string {\n boundaries.lastIndex = from;\n const boundary = boundaries.exec(html);\n const raw = html.slice(from, boundary === null ? html.length : boundary.index);\n return decodeEntities(raw.replace(TAGS, \"\")).replace(WHITESPACE, \" \").trim();\n}\n\n/**\n * Rewrites the option start tags of `html` so that exactly the wanted ones carry `selected`. The\n * input is markup this runtime produced (text and attribute values are escaped, so `<option` is\n * always a tag); only the `selected` attribute is added or removed, and nothing from the wanted\n * values is ever written.\n */\nfunction markOptions(html: string, wanted: { values: Set<string>; many: boolean }): string {\n let out = \"\";\n let copied = 0;\n let at = 0;\n let found = false;\n const attribute = new RegExp(ATTRIBUTE, \"g\");\n const boundaries = new RegExp(OPTION_BOUNDARY, \"gi\");\n for (;;) {\n const start = html.indexOf(\"<option\", at);\n if (start === -1) break;\n const attributesFrom = start + 7;\n at = attributesFrom;\n if (!/[\\s/>]/.test(html.charAt(attributesFrom))) continue;\n const end = tagEnd(html, attributesFrom);\n if (end === -1) break;\n const source = html.slice(attributesFrom, end);\n let value: string | undefined;\n let selectedAt = -1;\n let selectedEnd = -1;\n attribute.lastIndex = 0;\n for (let match = attribute.exec(source); match !== null; match = attribute.exec(source)) {\n const name = (match[1] ?? \"\").toLowerCase();\n if (name === \"selected\") {\n selectedAt = match.index;\n selectedEnd = match.index + match[0].length;\n } else if (name === \"value\" && value === undefined) {\n value = decodeEntities(match[2] ?? match[3] ?? match[4] ?? \"\");\n }\n }\n // A scalar behaves like `select.value = x`: the first option with that value wins.\n const matches =\n (wanted.many || !found) && wanted.values.has(value ?? optionText(html, end + 1, boundaries));\n if (matches) found = true;\n if (matches && selectedAt === -1) {\n const slash = source.endsWith(\"/\") ? source.length - 1 : source.length;\n out += `${html.slice(copied, attributesFrom + slash)} selected`;\n copied = attributesFrom + slash;\n } else if (!matches && selectedAt !== -1) {\n out += html.slice(copied, attributesFrom + selectedAt);\n copied = attributesFrom + selectedEnd;\n }\n at = end;\n }\n return copied === 0 ? html : out + html.slice(copied);\n}\n\n/**\n * The options of a `<select>` with the ones its value stands for marked `selected`. A browser\n * ignores a `value` attribute on `<select>`, so the server flags the options instead: the option\n * whose `value` attribute equals the value (or, with no such attribute, whose text does) is\n * selected, and every other option loses `selected`. An array selects every listed option, for\n * `<select multiple>`; a single value selects the first match, like `select.value = x`. `null`\n * and `undefined` stand for the empty string. Options inside `<optgroup>`, control flow and\n * components are found because the search runs on the serialized children. Values are compared,\n * never written, so they cannot add markup.\n *\n * @param value The select's `value`, or an accessor of it. Entries of an array are compared as\n * strings; `null` and `undefined` entries are skipped.\n * @param children The select's children (an `SsrNode`, or anything `escape` accepts).\n * @returns The children with the `selected` flags set, as a trusted `SsrNode`.\n * @throws TypeError `UNRECOGNIZED_INSERT_VALUE` when the value is a symbol, and the errors of\n * {@link escape} for the children.\n * @example\n * import { renderToString, ssr, ssrRaw, ssrSelectValue } from \"@shadow-js/web/server\";\n *\n * const options = ssrRaw(`<option value=\"red\">Red</option><option value=\"blue\">Blue</option>`);\n * const html = renderToString(() => ssr([\"<select>\", \"</select>\"], ssrSelectValue(\"blue\", options)));\n * // '<select><option value=\"red\">Red</option><option value=\"blue\" selected>Blue</option></select>'\n * @see setSelectValue\n * @since 1.0.0\n */\nexport function ssrSelectValue(value: unknown, children: unknown): SsrNode {\n return new SsrNode(markSelectedOptions(value, escape(children)));\n}\n\n/** {@link ssrSelectValue} on markup that is already escaped. @internal */\nexport function markSelectedOptions(value: unknown, html: string): string {\n return markOptions(html, wantedValues(value));\n}\n"],"mappings":"A,iJAaA,SAASK,EAAUC,EAAwB,CACzC,GAAI,OAAOA,GAAU,SACnB,MAAMN,EAAQ,4BAA6B,0CAA0C,EAEvF,OAAOM,GAAU,KAA8B,GAAK,OAAOA,CAAK,CAClE,CAOA,SAAgBC,EAAgBD,EAAwB,CACtD,OAAOE,EAAmBN,EAAWG,EAAUF,EAAaG,CAAK,CAAC,CAAC,CAAC,CACtE,CAGA,SAAgBE,EAAmBC,EAAsB,CACvD,IAAMC,EAAQD,EAAK,OAAO,CAAC,EAC3B,OAAOC,IAAU;GAAQA,IAAU,KAAO,KAAKD,IAASA,CAC1D,CAqBA,S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AEA,IAAME,GACHd,EAAO,MAAQ,CAACI,IAAUJ,EAAO,OAAO,IAAI/B,GAAS2B,EAAWxB,EAAMoC,EAAM,EAAGX,CAAU,CAAC,EAE7F,GADIiB,IAASV,EAAQ,IACjBU,GAAWJ,IAAe,GAAI,CAChC,IAAMK,EAAQN,EAAO,SAAS,GAAG,EAAIA,EAAO,OAAS,EAAIA,EAAO,OAChER,GAAO,GAAG7B,EAAK,MAAM8B,EAAQK,EAAiBQ,CAAK,EAAE,WACrDb,EAASK,EAAiBQ,CAC5B,KAAW,CAACD,GAAWJ,IAAe,KACpCT,GAAO7B,EAAK,MAAM8B,EAAQK,EAAiBG,CAAU,EACrDR,EAASK,EAAiBI,GAE5BR,EAAKK,CACP,CACA,OAAON,IAAW,EAAI9B,EAAO6B,EAAM7B,EAAK,MAAM8B,CAAM,CACtD,CA2BA,SAAgBc,EAAe/C,EAAgBgD,EAA4B,CACzE,OAAO,IAAIlD,EAAQmD,EAAoBjD,EAAOL,EAAOqD,CAAQ,CAAC,CAAC,CACjE,CAGA,SAAgBC,EAAoBjD,EAAgBG,EAAsB,CACxE,OAAO2B,EAAY3B,EAAMG,EAAaN,CAAK,CAAC,CAC9C,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydration-script.js","names":["
|
|
1
|
+
{"version":3,"file":"hydration-script.js","names":["DEFAULT_EARLY_EVENTS","captureScriptBody","ssrRaw","NONCE","generateHydrationScript","options","nonce","attribute","names","HydrationScript","props"],"sources":["../../../src/server/hydration-script.ts"],"sourcesContent":["import { captureScriptBody, DEFAULT_EARLY_EVENTS } from \"../internal/early-events\";\nimport { ssrRaw } from \"./element\";\n\n/**\n * Options of {@link generateHydrationScript} and {@link HydrationScript}.\n * @since 1.0.0\n */\nexport interface HydrationScriptOptions {\n /**\n * CSP nonce for the script. It is written only when it is a plain token (letters, digits, `+`, `/`,\n * `=`, `_`, `-`); any other value is ignored and the script gets no nonce.\n * @default undefined (no nonce attribute)\n */\n readonly nonce?: string;\n /**\n * Event types to capture before hydration. Only plain lower-case names (`[a-z]+`) are kept; others\n * are skipped.\n * @default [\"click\", \"input\"]\n */\n readonly eventNames?: readonly string[];\n}\n\nconst NONCE = /^[A-Za-z0-9+/=_-]+$/;\n\n/**\n * Returns the inline `<script>` that records the events a user makes before the app has hydrated, so\n * `hydrate()` can replay them once its handlers are attached (a click made while the bundle loads is\n * not lost). Put it in the `<head>` of the server-rendered page, before the bundle.\n *\n * @param options The CSP nonce and the event types to capture. Undefined uses the defaults of\n * {@link HydrationScriptOptions}.\n * @returns The script element as a string of markup.\n * @example\n * import { generateHydrationScript, renderToString } from \"@shadow-js/web/server\";\n *\n * function page(app: () => unknown, nonce: string): string {\n * const body = renderToString(app);\n * return `<html><head>${generateHydrationScript({ nonce })}</head><body>${body}</body></html>`;\n * }\n * @see HydrationScript\n * @since 1.0.0\n */\nexport function generateHydrationScript(options: HydrationScriptOptions = {}): string {\n const nonce = options.nonce;\n const attribute = nonce !== undefined && NONCE.test(nonce) ? ` nonce=\"${nonce}\"` : \"\";\n const names = options.eventNames ?? DEFAULT_EARLY_EVENTS;\n return `<script${attribute}>${captureScriptBody(names)}</script>`;\n}\n\n/**\n * {@link generateHydrationScript} as a component, for a document rendered with server JSX:\n * `<HydrationScript nonce={nonce} />` in the `<head>`.\n *\n * @param props The CSP nonce and the event types to capture. Undefined uses the defaults of\n * {@link HydrationScriptOptions}.\n * @returns The script as trusted raw markup.\n * @example\n * import { createComponent, HydrationScript, renderToString } from \"@shadow-js/web/server\";\n *\n * function Document() {\n * return (\n * <html>\n * <head>\n * <HydrationScript nonce=\"r4nd0m\" />\n * </head>\n * <body>Hello</body>\n * </html>\n * );\n * }\n * const html = renderToString(() => createComponent(Document, {}));\n * @see generateHydrationScript\n * @since 1.0.0\n */\nexport function HydrationScript(props: HydrationScriptOptions = {}): unknown {\n return ssrRaw(generateHydrationScript(props));\n}\n"],"mappings":"A,gIAsBA,MAAMG,EAAQ,sBAoBd,SAAgBC,EAAwBC,EAAkC,CAAC,EAAW,CACpF,IAAMC,EAAQD,EAAQ,MAChBE,EAAYD,IAAU,IAAA,IAAaH,EAAM,KAAKG,CAAK,EAAI,WAAWA,EAAM,GAAK,GAC7EE,EAAQH,EAAQ,YAAcL,EACpC,MAAO,UAAUO,EAAU,GAAGN,EAAkBO,CAAK,EAAE,WACzD,CA0BA,SAAgBC,EAAgBC,EAAgC,CAAC,EAAY,CAC3E,OAAOR,EAAOE,EAAwBM,CAAK,CAAC,CAC9C,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","names":["SsrNode","t","isSsrNode","value"],"sources":["../../../src/server/node.ts"],"sourcesContent":["/**\n * Markup that is already safe to insert: the only value `escape` writes without encoding.\n * A class instance, not a `{ t }` shape, so a plain object parsed from user input can never be\n * mistaken for trusted markup.\n * @internal\n */\nexport class SsrNode {\n readonly t: string;\n constructor(t: string) {\n this.t = t;\n }\n}\n\n/** True for values created by the server helpers. @internal */\nexport function isSsrNode(value: unknown): value is SsrNode {\n return value instanceof SsrNode;\n}\n"],"mappings":"AAMA,IAAaA,EAAb,KAAqB,
|
|
1
|
+
{"version":3,"file":"node.js","names":["SsrNode","t","isSsrNode","value"],"sources":["../../../src/server/node.ts"],"sourcesContent":["/**\n * Markup that is already safe to insert: the only value `escape` writes without encoding.\n * A class instance, not a `{ t }` shape, so a plain object parsed from user input can never be\n * mistaken for trusted markup.\n * @internal\n */\nexport class SsrNode {\n readonly t: string;\n constructor(t: string) {\n this.t = t;\n }\n}\n\n/** True for values created by the server helpers. @internal */\nexport function isSsrNode(value: unknown): value is SsrNode {\n return value instanceof SsrNode;\n}\n"],"mappings":"AAMA,IAAaA,EAAb,KAAqB,CACV,EACT,YAAYC,EAAW,CACrB,KAAK,EAAIA,CACX,CACF,EAGA,SAAgBC,EAAUC,EAAkC,CAC1D,OAAOA,aAAiBH,CAC1B,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portals.js","names":["
|
|
1
|
+
{"version":3,"file":"portals.js","names":["childScope","withScope","PortalContext","SsrError","escape","PortalCollector","key","html","children","renderServerPortal","out","collectors","createServerPortals","collector","portals","collectorOf","sink","withPortalSink","build","portalCollectorFor"],"sources":["../../../src/server/portals.ts"],"sourcesContent":["import { childScope, withScope } from \"../internal/hydration-scope\";\nimport { PortalContext, type PortalSink } from \"../internal/portal-context\";\nimport { SsrError } from \"./errors\";\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name \"escape\" is part of the compiler contract (SSR output).\nimport { escape } from \"./escape\";\n\n/**\n * The most portals one render may produce. A page with more open overlays than this is a bug, and the\n * collector refuses to grow without a bound.\n * @internal\n */\nexport const MAX_SERVER_PORTALS = 256;\n\n/**\n * The markup of the portals a server render produced (see {@link createServerPortals}). Pass it to\n * the render as its `portals` option, then emit `html()` at the end of `<body>`, after the app markup.\n * The client adopts each block when it hydrates the portal that wrote it.\n *\n * @example\n * import { createComponent, createServerPortals, renderToString } from \"@shadow-js/web/server\";\n *\n * function App() {\n * return <main>Hello</main>;\n * }\n * const portals = createServerPortals();\n * const app = renderToString(() => createComponent(App, {}), { portals });\n * const page = `<!doctype html><html><body><div id=\"app\">${app}</div>${portals.html()}</body></html>`;\n * @since 1.0.0\n */\nexport interface ServerPortals {\n /**\n * The collected blocks, in the order the render produced them: each is `<!--portal:KEY-->` markup\n * `<!--/portal:KEY-->`. Emit it once, at the end of `<body>`.\n * @returns The markup; empty when no portal was rendered.\n */\n html(): string;\n}\n\n/** The collector behind a {@link ServerPortals}: what a renderer writes into while it renders. @internal */\nexport class PortalCollector implements PortalSink {\n private readonly entries = new Map<string, string>();\n\n add(key: string, html: string): void {\n if (!this.entries.has(key) && this.entries.size >= MAX_SERVER_PORTALS) {\n throw new SsrError(\n \"SSR_PORTAL_LIMIT\",\n `A render produced more than ${MAX_SERVER_PORTALS} portals; close some overlays or raise the limit.`,\n );\n }\n this.entries.set(key, html);\n }\n\n /** Forgets what an earlier pass of the same render wrote. */\n clear(): void {\n this.entries.clear();\n }\n\n render(key: string | undefined, children: () => unknown): void {\n renderServerPortal(key, children, this);\n }\n\n html(): string {\n let out = \"\";\n for (const [key, html] of this.entries) {\n out += `<!--portal:${key}-->${html}<!--/portal:${key}-->`;\n }\n return out;\n }\n}\n\nconst collectors = new WeakMap<ServerPortals, PortalCollector>();\n\n/**\n * Creates the collector a server render writes its portals into. Without one, a `Portal` renders\n * nothing on the server. Create one per request: a render clears it before it starts, and one render\n * may produce at most 256 portals (more throw an `SsrError` whose `code` is `SSR_PORTAL_LIMIT`).\n *\n * @returns A new, empty {@link ServerPortals}.\n * @example\n * import { createComponent, createServerPortals, renderToString } from \"@shadow-js/web/server\";\n *\n * function App() {\n * return <main>Hello</main>;\n * }\n * const portals = createServerPortals();\n * const app = renderToString(() => createComponent(App, {}), { portals });\n * const page = `<body><div id=\"app\">${app}</div>${portals.html()}</body>`;\n * @since 1.0.0\n */\nexport function createServerPortals(): ServerPortals {\n const collector = new PortalCollector();\n const portals: ServerPortals = { html: () => collector.html() };\n collectors.set(portals, collector);\n return portals;\n}\n\n/**\n * The collector behind a `portals` option.\n * @throws TypeError when the value did not come from {@link createServerPortals}.\n * @internal\n */\nexport function collectorOf(portals: ServerPortals): PortalCollector {\n const collector = collectors.get(portals);\n if (collector === undefined) {\n throw new TypeError(\"portals must be created with createServerPortals().\");\n }\n return collector;\n}\n\n/**\n * The server half of a `Portal`: renders its content into the render's collector. The content gets its\n * own hydration scope, so the keys of the siblings do not depend on whether the portal rendered. Writes\n * nothing when the render has no collector or the portal has no key (no render scope).\n *\n * @param key The portal's key, from `nextKey()` at the call site.\n * @param children Reads the portal's content. A thunk, because reading a JSX child builds it, and the\n * content must be built inside its own scope.\n * @param sink The collector the portal context provides (null for a render without one).\n * @internal\n */\nexport function renderServerPortal(\n key: string | undefined,\n children: () => unknown,\n sink: PortalSink | null,\n): void {\n if (sink === null || key === undefined) return;\n const html = withScope(childScope(key), () => escape(children()));\n sink.add(key, html);\n}\n\n/**\n * Runs `build` with the portal sink provided, and returns what `build` returns (the render's accessor).\n * A null sink provides nothing, so the portals of that render write nothing.\n * @internal\n */\nexport function withPortalSink<T>(sink: PortalSink | null, build: () => T): T {\n const view = PortalContext({\n value: sink,\n get children() {\n return build();\n },\n });\n return (view as () => T)();\n}\n\n/**\n * The collector a renderer writes into for one call: null without a `portals` option, else the cleared\n * collector.\n * @internal\n */\nexport function portalCollectorFor(portals: ServerPortals | undefined): PortalCollector | null {\n if (portals === undefined) return null;\n const collector = collectorOf(portals);\n collector.clear();\n return collector;\n}\n"],"mappings":"A,qNAuCA,IAAaK,EAAb,KAAmD,CAChC,wBAAU,IAAI,IAE/B,IAAIC,EAAaC,EAAoB,CACnC,GAAI,CAAC,KAAK,QAAQ,IAAID,CAAG,GAAK,KAAK,QAAQ,MAAA,IACzC,MAAM,IAAIH,EACR,mBACA,kFACF,EAEF,KAAK,QAAQ,IAAIG,EAAKC,CAAI,CAC5B,CAGA,OAAc,CACZ,KAAK,QAAQ,MAAM,CACrB,CAEA,OAAOD,EAAyBE,EAA+B,CAC7DC,EAAmBH,EAAKE,EAAU,IAAI,CACxC,CAEA,MAAe,CACb,IAAIE,EAAM,GACV,IAAK,GAAM,CAACJ,EAAKC,KAAS,KAAK,QAC7BG,GAAO,cAAcJ,EAAI,KAAKC,EAAK,cAAcD,EAAI,KAEvD,OAAOI,CACT,CACF,EAEA,MAAMC,kBAAa,IAAI,QAmBvB,SAAgBC,GAAqC,CACnD,IAAMC,EAAY,IAAIR,EAChBS,EAAyB,CAAE,SAAYD,EAAU,KAAK,CAAE,EAE9D,OADAF,EAAW,IAAIG,EAASD,CAAS,EAC1BC,CACT,CAOA,SAAgBC,EAAYD,EAAyC,CACnE,IAAMD,EAAYF,EAAW,IAAIG,CAAO,EACxC,GAAID,IAAc,IAAA,GAChB,MAAU,UAAU,qDAAqD,EAE3E,OAAOA,CACT,CAaA,SAAgBJ,EACdH,EACAE,EACAQ,EACM,CACN,GAAIA,IAAS,MAAQV,IAAQ,IAAA,GAAW,OACxC,IAAMC,EAAON,EAAUD,EAAWM,CAAG,MAASF,EAAOI,EAAS,CAAC,CAAC,EAChEQ,EAAK,IAAIV,EAAKC,CAAI,CACpB,CAOA,SAAgBU,EAAkBD,EAAyBE,EAAmB,CAO5E,OANahB,EAAc,CACzB,MAAOc,EACP,IAAI,UAAW,CACb,OAAOE,EAAM,CACf,CACF,CACW,CAAC,CAAa,CAC3B,CAOA,SAAgBC,EAAmBL,EAA4D,CAC7F,GAAIA,IAAY,IAAA,GAAW,OAAO,KAClC,IAAMD,EAAYE,EAAYD,CAAO,EAErC,OADAD,EAAU,MAAM,EACTA,CACT,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw-text.js","names":["
|
|
1
|
+
{"version":3,"file":"raw-text.js","names":["invalid","render","resolveValue","SsrNode","isSsrNode","TEXT_ONLY_ELEMENTS","isTextOnlyElement","tag","RAW_TEXT_ELEMENTS","CLOSING_TAG","neutralize","text","match","rawTextContent","value","rawElementContent","resolved","ssrRawText"],"sources":["../../../src/server/raw-text.ts"],"sourcesContent":["import { invalid } from \"./errors\";\nimport { render, resolveValue } from \"./escape\";\nimport { isSsrNode, SsrNode } from \"./node\";\n\n/**\n * Elements whose content the HTML parser reads as text and nothing else: `script` and `style` (raw text, no\n * entities) and `title` and `textarea` (entities only). Neither kind can hold a comment, so the region markers\n * that delimit a dynamic child elsewhere would show up as literal text inside them.\n */\nconst TEXT_ONLY_ELEMENTS: ReadonlySet<string> = new Set([\"script\", \"style\", \"title\", \"textarea\"]);\n\n/**\n * True for an HTML element whose content is text only, so its children are written without region markers\n * and the client adopts the text as it is. Pass the tag in any letter case; SVG elements of the same names\n * are ordinary elements and are not text only.\n * @internal\n */\nexport function isTextOnlyElement(tag: string): boolean {\n return TEXT_ONLY_ELEMENTS.has(tag.toLowerCase());\n}\n\n/** The elements whose text the parser reads raw. */\nconst RAW_TEXT_ELEMENTS: ReadonlySet<string> = new Set([\"script\", \"style\"]);\n\n/** The closing tag of a script or style in any case, and the `<!--` that opens a script's double-escaped state. */\nconst CLOSING_TAG = {\n script: /<\\/(script)|<!--/gi,\n style: /<\\/(style)/gi,\n} as const;\n\n/**\n * Keeps raw text from ending its element or the script data state. `</script` and `</style` get a backslash that\n * CSS, JavaScript and JSON all read as the character itself (`<\\/style` is `</style` in a string, a comment or a\n * selector escape), and `<!--` in a script becomes `<\\u0021--`: `\\!` is no JSON escape, and a script that holds\n * JSON data (`application/json`, `ld+json`) must still parse. The text means what it meant and the parser does\n * not see a tag. Entities would instead change the text: raw text has none.\n */\nfunction neutralize(tag: \"script\" | \"style\", text: string): string {\n return text.replace(CLOSING_TAG[tag], (match: string) =>\n match === \"<!--\" ? \"<\\\\u0021--\" : `<\\\\/${match.slice(2)}`,\n );\n}\n\n/** The text of a child value for a `script` or `style`: strings unescaped, the whole checked by {@link neutralize}. @internal */\nexport function rawTextContent(tag: string, value: unknown): string {\n return neutralize(\n tag.toLowerCase() === \"script\" ? \"script\" : \"style\",\n render(value, (text) => text),\n );\n}\n\n/**\n * The content of a `script` or `style` element made by `ssrElement`. A node the compiler built (`ssr`, `ssrRaw`)\n * is the application's own markup and is left as it is; any other value is raw text and is checked.\n * @internal\n */\nexport function rawElementContent(tag: string, value: unknown): string {\n const resolved = resolveValue(value);\n return isSsrNode(resolved) ? resolved.t : rawTextContent(tag, resolved);\n}\n\n/**\n * Writes the children of a `<script>` or `<style>` element: the helper compiled server output calls for a\n * dynamic child of one. The browser reads these elements' content as raw text, so the value is written\n * as it is (`a > b` stays `a > b`; HTML entities would corrupt the stylesheet or the code) with no region\n * markers around it, and the client adopts the text when it hydrates. Only one thing is changed: a closing tag of\n * the element, in any letter case (`</style`, `</SCRIPT`), and `<!--` in a script, would end the element\n * early or hide its end, so each is rewritten (`<\\/style`, `<\\u0021--`) to text that CSS, JavaScript and JSON read as the same characters.\n *\n * Accessors are called untracked, arrays are flattened, `null`, `undefined` and booleans write nothing, and\n * a symbol throws, as in {@link escape}.\n *\n * @param tag The element, `\"script\"` or `\"style\"` (any letter case).\n * @param value The child value: a string, a number, an array, an accessor or `null`.\n * @returns The text as a trusted `SsrNode`.\n * @throws TypeError `INVALID_RAW_TEXT_TAG` when `tag` is not `script` or `style`, and the errors of\n * {@link escape} for the value.\n * @example\n * import { renderToString, ssr, ssrRawText } from \"@shadow-js/web/server\";\n *\n * const css = \"a > b { color: red } </style><script>alert(1)</script>\";\n * const html = renderToString(() => ssr([\"<style>\", \"</style>\"], ssrRawText(\"style\", css)));\n * // \"<style>a > b { color: red } <\\/style><script>alert(1)</script></style>\"\n * @see escape\n * @since 1.0.2\n */\nexport function ssrRawText(tag: \"script\" | \"style\", value: unknown): SsrNode {\n if (typeof tag !== \"string\" || !RAW_TEXT_ELEMENTS.has(tag.toLowerCase())) {\n throw invalid(\"INVALID_RAW_TEXT_TAG\", \"ssrRawText(): the tag must be script or style.\");\n }\n return new SsrNode(rawTextContent(tag, value));\n}\n"],"mappings":"A,gJASA,MAAMK,kBAA0C,IAAI,IAAI,CAAC,SAAU,QAAS,QAAS,UAAU,CAAC,EAQhG,SAAgBC,EAAkBC,EAAsB,CACtD,OAAOF,EAAmB,IAAIE,EAAI,YAAY,CAAC,CACjD,CAGA,MAAMC,kBAAyC,IAAI,IAAI,CAAC,SAAU,OAAO,CAAC,EAGpEC,EAAc,CAClB,OAAQ,qBACR,MAAO,cACT,EASA,SAASC,EAAWH,EAAyBI,EAAsB,CACjE,OAAOA,EAAK,QAAQF,EAAYF,GAAOK,GACrCA,IAAU,OAAS,aAAe,OAAOA,EAAM,MAAM,CAAC,GACxD,CACF,CAGA,SAAgBC,EAAeN,EAAaO,EAAwB,CAClE,OAAOJ,EACLH,EAAI,YAAY,IAAM,SAAW,SAAW,QAC5CN,EAAOa,EAAQH,GAASA,CAAI,CAC9B,CACF,CAOA,SAAgBI,EAAkBR,EAAaO,EAAwB,CACrE,IAAME,EAAWd,EAAaY,CAAK,EACnC,OAAOV,EAAUY,CAAQ,EAAIA,EAAS,EAAIH,EAAeN,EAAKS,CAAQ,CACxE,CA2BA,SAAgBC,EAAWV,EAAyBO,EAAyB,CAC3E,GAAI,OAAOP,GAAQ,UAAY,CAACC,EAAkB,IAAID,EAAI,YAAY,CAAC,EACrE,MAAMP,EAAQ,uBAAwB,gDAAgD,EAExF,OAAO,IAAIG,EAAQU,EAAeN,EAAKO,CAAK,CAAC,CAC/C,C"}
|