@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":"portal.js","names":["appendMoved","target","node","shadowRootOf","host","resolveMount","mount","Portal","key","nextKey","sink","useContext","PortalContext","isServer","props","owner","getOwner","mounted","adopted","claims","unmount","current","removeRegion","mountInto","region","createRegion","initial","runWithOwner","createRoot","bind","bindRegion","mode","withScope","childScope","dispose","moveTo","previous","moveRegion","useRenderEffect","shadow","onCleanup"],"sources":["../../../src/control-flow/portal.ts"],"sourcesContent":["import {\n createRoot,\n getOwner,\n isServer,\n onCleanup,\n runWithOwner,\n useContext,\n useRenderEffect,\n} from \"@shadow-js/core\";\nimport {\n bindRegion,\n childScope,\n claims,\n createRegion,\n moveRegion,\n nextKey,\n PortalContext,\n type Region,\n removeRegion,\n withScope,\n} from \"../extend\";\n\n/**\n * Props of {@link Portal}.\n * @since 1.0.0\n */\nexport interface PortalProps {\n /**\n * The element that receives the content, or a function returning it (read reactively). A null\n * target, or a function that returns null or undefined, renders nothing and warns once in\n * development (`PORTAL_TARGET_MISSING`).\n * @default document.body (when the prop is omitted)\n */\n readonly mount?: Element | null | (() => Element | null | undefined);\n /**\n * Put the content in a shadow root of the mount, created once and reused. A portal with a shadow\n * root is not server-rendered; the browser creates it.\n * @default false\n */\n readonly useShadow?: boolean;\n /**\n * Reserved for namespace handling. Nodes are inserted as they were created, so the flag does not\n * change the output yet.\n * @default false\n */\n readonly isSVG?: boolean;\n /**\n * The content: a node, text, an array, or an accessor returning them.\n * @default undefined (nothing is rendered)\n */\n readonly children?: unknown;\n}\n\n/** What the portal holds while content is mounted: where it is, its region, and its effects. */\ninterface Mounted {\n readonly host: Node;\n readonly region: Region;\n /** Stops the content's effects. The nodes stay where they are. */\n readonly stopEffects: () => void;\n}\n\n/**\n * How the content of a mount is built. `claimed`: the server markup is adopted (the templates claim\n * it). `unclaimed`: hydrating, but the server sent nothing for this portal, so it is built fresh.\n */\ntype MountMode = \"plain\" | \"claimed\" | \"unclaimed\";\n\n/** A node that can be moved in place (`Element.prototype.moveBefore`, where implemented). */\ninterface MovableNode extends Node {\n moveBefore(node: Node, child: Node | null): void;\n}\n\n/** Appends `node` to `target`, moving it in place when the target supports `moveBefore`. */\nfunction appendMoved(target: Node, node: Node): void {\n if (typeof (target as Partial<MovableNode>).moveBefore === \"function\") {\n (target as MovableNode).moveBefore(node, null);\n } else {\n target.appendChild(node);\n }\n}\n\n/** The shadow root of an element, attached once when the element has none. */\nfunction shadowRootOf(host: Element): ShadowRoot {\n return host.shadowRoot ?? host.attachShadow({ mode: \"open\" });\n}\n\n/** The mount target of a `mount` prop: the default body, the element, or the function's result. */\nfunction resolveMount(mount: PortalProps[\"mount\"]): Element | null {\n if (mount === undefined) return document.body;\n const value = typeof mount === \"function\" ? mount() : mount;\n return value ?? null;\n}\n\n/**\n * Renders `children` into another part of the document, without a wrapper: the content nodes are\n * inserted directly into the mount element (or its shadow root). Nothing is left at the call site.\n * Disposing the owner removes exactly the nodes the portal inserted; nodes that were already in the\n * mount stay. A reactive `mount` moves the content: the children are built once, and\n * their nodes and effects keep their identity while they move.\n *\n * On the server the content is rendered into the render's `portals` collector (see\n * `createServerPortals`), and the document emits it at the end of `<body>`. When the browser hydrates\n * the portal it adopts that markup instead of creating it again, moving it into the mount if the mount\n * is not `body`. A portal with `useShadow` is not server-rendered; the browser creates it.\n *\n * Events follow the DOM tree. Delegated handlers inside the content fire when the mount is in the\n * document, because the document listener sees the event bubble past the mount. Handlers on\n * elements that wrap the call site do not fire.\n *\n * @param props See {@link PortalProps}.\n * @returns Always null: the portal renders nothing in place.\n * @example\n * import { Portal } from \"@shadow-js/web\";\n *\n * function Modal() {\n * return <div role=\"dialog\">Hello</div>;\n * }\n *\n * function App() {\n * return (\n * <Portal mount={document.getElementById(\"modal-root\")}>\n * <Modal />\n * </Portal>\n * );\n * }\n * @see Dynamic\n * @since 1.0.0\n */\nexport function Portal(props: PortalProps): null {\n // The key of this portal's server block, taken at the call site on the server and in the browser\n // alike. The content renders in a scope of its own (`childScope`), so the keys of the siblings do\n // not depend on whether the content rendered.\n const key = nextKey();\n // A server render provides the portal collector (`renderToString` and friends), so it is recognized\n // by the collector as well as by the build's `isServer` flag: the same server code runs in both.\n const sink = useContext(PortalContext);\n if (isServer || sink !== null) {\n if (props.useShadow !== true) sink?.render?.(key, () => props.children);\n return null;\n }\n // The content is built under the portal's own owner, not under the effect that picks the mount:\n // that effect runs again for each new mount and would dispose what it owns.\n const owner = getOwner();\n let mounted: Mounted | undefined;\n let warned = false;\n // The server block of this portal, taken out of the markers while hydrating; used by the first mount.\n let adopted: Node[] | undefined = claims.current.claimPortal(key);\n\n /** Stops the content's effects, then removes its nodes. Safe to call when nothing is mounted. */\n const unmount = (): void => {\n const current = mounted;\n if (current === undefined) return;\n mounted = undefined;\n current.stopEffects();\n removeRegion(current.region);\n };\n\n /** Creates the content region in `host`, adopting the nodes that are already there. */\n const mountInto = (host: Node, initial: Node[], mode: MountMode): Mounted => {\n const region = createRegion(host, null, initial);\n const stopEffects = runWithOwner(owner, () =>\n createRoot((dispose) => {\n const bind = (): void => {\n bindRegion(region, () => props.children);\n };\n if (mode === \"plain\") bind();\n else if (mode === \"claimed\") withScope(childScope(key), bind);\n else claims.current.withoutClaiming(() => withScope(childScope(key), bind));\n return dispose;\n }),\n );\n return { host, region, stopEffects };\n };\n\n /** Mounts the content in `target` the first time, and moves it there afterward. */\n const moveTo = (target: Node): void => {\n const previous = mounted;\n if (previous === undefined) {\n const initial = adopted ?? [];\n let mode: MountMode = \"plain\";\n if (adopted !== undefined) mode = \"claimed\";\n else if (key !== undefined && claims.current.isClaiming()) mode = \"unclaimed\";\n adopted = undefined;\n for (const node of initial) {\n if (node.parentNode !== target) appendMoved(target, node);\n }\n mounted = mountInto(target, initial, mode);\n return;\n }\n // The children were built once, under an owner that stays: the nodes and their effects move, so\n // an input keeps what was typed and a component is neither disposed nor set up again.\n moveRegion(previous.region, target, (node) => appendMoved(target, node));\n mounted = { host: target, region: previous.region, stopEffects: previous.stopEffects };\n };\n\n useRenderEffect(\n () => {\n const host = resolveMount(props.mount);\n const shadow = props.useShadow === true;\n return { host, shadow };\n },\n ({ host, shadow }) => {\n if (host === null) {\n unmount();\n // The server block was adopted at the call site but has nowhere to live: leaving it would show\n // content the client does not render (stripLeftovers removes the blocks nobody claimed).\n for (const node of adopted ?? []) node.parentNode?.removeChild(node);\n adopted = undefined;\n if (__DEV__ && !warned) {\n warned = true;\n console.warn(\n \"[shadow PORTAL_TARGET_MISSING] Portal has no mount element; nothing is rendered.\",\n );\n }\n return;\n }\n const target: Node = shadow ? shadowRootOf(host) : host;\n if (mounted !== undefined && mounted.host === target) return;\n moveTo(target);\n },\n );\n onCleanup(unmount);\n return null;\n}\n"],"mappings":"A,2bAyEA,SAASA,EAAY,EAAc,EAAkB,CAC/C,OAAQC,EAAgC,YAAe,WACzDA,EAAwB,WAAWC,EAAM,IAAI,EAE7CD,EAAO,YAAYC,CAAI,CAE3B,CAGA,SAASC,EAAa,EAA2B,CAC/C,OAAOC,EAAK,YAAcA,EAAK,aAAa,CAAE,KAAM,MAAO,CAAC,CAC9D,CAGA,SAASC,EAAa,EAA6C,CAGjE,OAFIC,IAAU,IAAA,GAAkB,SAAS,MAC3B,OAAOA,GAAU,WAAaA,EAAM,EAAIA,IACtC,IAClB,CAqCA,SAAgBC,EAAO,EAA0B,CAI/C,IAAMC,EAAMC,EA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AAS,WAAY,CACvF,EA6BA,OA3BAE,OAIW,CAAE,KAFIjC,EAAaS,EAAM,KAEpB,EAAG,OADAA,EAAM,YAAc,EACb,IAEvB,CAAE,OAAM,YAAa,CACpB,GAAIV,IAAS,KAAM,CACjBgB,EAAQ,EAGR,IAAK,IAAMlB,KAAQgB,GAAW,CAAC,EAAGhB,EAAK,YAAY,YAAYA,CAAI,EACnE,EAAU,IAAA,GAOV,MACF,CACA,IAAMD,EAAesC,EAASpC,EAAaC,CAAI,EAAIA,GAC/Ca,IAAY,IAAA,IAAaA,EAAQ,OAAShB,IAC9CkC,EAAOlC,CAAM,CACf,CACF,EACAuC,EAAUpB,CAAO,EACV,IACT,C"}
|
|
1
|
+
{"version":3,"file":"portal.js","names":["bindRegion","createRegion","moveRegion","removeRegion","childScope","nextKey","withScope","claims","PortalContext","createRoot","getOwner","isServer","onCleanup","runWithOwner","useContext","useRenderEffect","appendMoved","target","node","shadowRootOf","host","resolveMount","mount","Portal","props","key","sink","owner","mounted","adopted","unmount","current","mountInto","initial","mode","region","dispose","bind","moveTo","previous","shadow"],"sources":["../../../src/control-flow/portal.ts"],"sourcesContent":["import {\n createRoot,\n getOwner,\n isServer,\n onCleanup,\n runWithOwner,\n useContext,\n useRenderEffect,\n} from \"@shadow-js/core\";\nimport {\n bindRegion,\n childScope,\n claims,\n createRegion,\n moveRegion,\n nextKey,\n PortalContext,\n type Region,\n removeRegion,\n withScope,\n} from \"../extend\";\n\n/**\n * Props of {@link Portal}.\n * @since 1.0.0\n */\nexport interface PortalProps {\n /**\n * The element that receives the content, or a function returning it (read reactively). A null\n * target, or a function that returns null or undefined, renders nothing and warns once in\n * development (`PORTAL_TARGET_MISSING`).\n * @default document.body (when the prop is omitted)\n */\n readonly mount?: Element | null | (() => Element | null | undefined);\n /**\n * Put the content in a shadow root of the mount, created once and reused. A portal with a shadow\n * root is not server-rendered; the browser creates it.\n * @default false\n */\n readonly useShadow?: boolean;\n /**\n * Reserved for namespace handling. Nodes are inserted as they were created, so the flag does not\n * change the output yet.\n * @default false\n */\n readonly isSVG?: boolean;\n /**\n * The content: a node, text, an array, or an accessor returning them.\n * @default undefined (nothing is rendered)\n */\n readonly children?: unknown;\n}\n\n/** What the portal holds while content is mounted: where it is, its region, and its effects. */\ninterface Mounted {\n readonly host: Node;\n readonly region: Region;\n /** Stops the content's effects. The nodes stay where they are. */\n readonly stopEffects: () => void;\n}\n\n/**\n * How the content of a mount is built. `claimed`: the server markup is adopted (the templates claim\n * it). `unclaimed`: hydrating, but the server sent nothing for this portal, so it is built fresh.\n */\ntype MountMode = \"plain\" | \"claimed\" | \"unclaimed\";\n\n/** A node that can be moved in place (`Element.prototype.moveBefore`, where implemented). */\ninterface MovableNode extends Node {\n moveBefore(node: Node, child: Node | null): void;\n}\n\n/** Appends `node` to `target`, moving it in place when the target supports `moveBefore`. */\nfunction appendMoved(target: Node, node: Node): void {\n if (typeof (target as Partial<MovableNode>).moveBefore === \"function\") {\n (target as MovableNode).moveBefore(node, null);\n } else {\n target.appendChild(node);\n }\n}\n\n/** The shadow root of an element, attached once when the element has none. */\nfunction shadowRootOf(host: Element): ShadowRoot {\n return host.shadowRoot ?? host.attachShadow({ mode: \"open\" });\n}\n\n/** The mount target of a `mount` prop: the default body, the element, or the function's result. */\nfunction resolveMount(mount: PortalProps[\"mount\"]): Element | null {\n if (mount === undefined) return document.body;\n const value = typeof mount === \"function\" ? mount() : mount;\n return value ?? null;\n}\n\n/**\n * Renders `children` into another part of the document, without a wrapper: the content nodes are\n * inserted directly into the mount element (or its shadow root). Nothing is left at the call site.\n * Disposing the owner removes exactly the nodes the portal inserted; nodes that were already in the\n * mount stay. A reactive `mount` moves the content: the children are built once, and\n * their nodes and effects keep their identity while they move.\n *\n * On the server the content is rendered into the render's `portals` collector (see\n * `createServerPortals`), and the document emits it at the end of `<body>`. When the browser hydrates\n * the portal it adopts that markup instead of creating it again, moving it into the mount if the mount\n * is not `body`. A portal with `useShadow` is not server-rendered; the browser creates it.\n *\n * Events follow the DOM tree. Delegated handlers inside the content fire when the mount is in the\n * document, because the document listener sees the event bubble past the mount. Handlers on\n * elements that wrap the call site do not fire.\n *\n * @param props See {@link PortalProps}.\n * @returns Always null: the portal renders nothing in place.\n * @example\n * import { Portal } from \"@shadow-js/web\";\n *\n * function Modal() {\n * return <div role=\"dialog\">Hello</div>;\n * }\n *\n * function App() {\n * return (\n * <Portal mount={document.getElementById(\"modal-root\")}>\n * <Modal />\n * </Portal>\n * );\n * }\n * @see Dynamic\n * @since 1.0.0\n */\nexport function Portal(props: PortalProps): null {\n // The key of this portal's server block, taken at the call site on the server and in the browser\n // alike. The content renders in a scope of its own (`childScope`), so the keys of the siblings do\n // not depend on whether the content rendered.\n const key = nextKey();\n // A server render provides the portal collector (`renderToString` and friends), so it is recognized\n // by the collector as well as by the build's `isServer` flag: the same server code runs in both.\n const sink = useContext(PortalContext);\n if (isServer || sink !== null) {\n if (props.useShadow !== true) sink?.render?.(key, () => props.children);\n return null;\n }\n // The content is built under the portal's own owner, not under the effect that picks the mount:\n // that effect runs again for each new mount and would dispose what it owns.\n const owner = getOwner();\n let mounted: Mounted | undefined;\n let warned = false;\n // The server block of this portal, taken out of the markers while hydrating; used by the first mount.\n let adopted: Node[] | undefined = claims.current.claimPortal(key);\n\n /** Stops the content's effects, then removes its nodes. Safe to call when nothing is mounted. */\n const unmount = (): void => {\n const current = mounted;\n if (current === undefined) return;\n mounted = undefined;\n current.stopEffects();\n removeRegion(current.region);\n };\n\n /** Creates the content region in `host`, adopting the nodes that are already there. */\n const mountInto = (host: Node, initial: Node[], mode: MountMode): Mounted => {\n const region = createRegion(host, null, initial);\n const stopEffects = runWithOwner(owner, () =>\n createRoot((dispose) => {\n const bind = (): void => {\n bindRegion(region, () => props.children);\n };\n if (mode === \"plain\") bind();\n else if (mode === \"claimed\") withScope(childScope(key), bind);\n else claims.current.withoutClaiming(() => withScope(childScope(key), bind));\n return dispose;\n }),\n );\n return { host, region, stopEffects };\n };\n\n /** Mounts the content in `target` the first time, and moves it there afterward. */\n const moveTo = (target: Node): void => {\n const previous = mounted;\n if (previous === undefined) {\n const initial = adopted ?? [];\n let mode: MountMode = \"plain\";\n if (adopted !== undefined) mode = \"claimed\";\n else if (key !== undefined && claims.current.isClaiming()) mode = \"unclaimed\";\n adopted = undefined;\n for (const node of initial) {\n if (node.parentNode !== target) appendMoved(target, node);\n }\n mounted = mountInto(target, initial, mode);\n return;\n }\n // The children were built once, under an owner that stays: the nodes and their effects move, so\n // an input keeps what was typed and a component is neither disposed nor set up again.\n moveRegion(previous.region, target, (node) => appendMoved(target, node));\n mounted = { host: target, region: previous.region, stopEffects: previous.stopEffects };\n };\n\n useRenderEffect(\n () => {\n const host = resolveMount(props.mount);\n const shadow = props.useShadow === true;\n return { host, shadow };\n },\n ({ host, shadow }) => {\n if (host === null) {\n unmount();\n // The server block was adopted at the call site but has nowhere to live: leaving it would show\n // content the client does not render (stripLeftovers removes the blocks nobody claimed).\n for (const node of adopted ?? []) node.parentNode?.removeChild(node);\n adopted = undefined;\n if (__DEV__ && !warned) {\n warned = true;\n console.warn(\n \"[shadow PORTAL_TARGET_MISSING] Portal has no mount element; nothing is rendered.\",\n );\n }\n return;\n }\n const target: Node = shadow ? shadowRootOf(host) : host;\n if (mounted !== undefined && mounted.host === target) return;\n moveTo(target);\n },\n );\n onCleanup(unmount);\n return null;\n}\n"],"mappings":"A,2bAyEA,SAASgB,EAAYC,EAAcC,EAAkB,CAC/C,OAAQD,EAAgC,YAAe,WACxDA,EAAuB,WAAWC,EAAM,IAAI,EAE7CD,EAAO,YAAYC,CAAI,CAE3B,CAGA,SAASC,EAAaC,EAA2B,CAC/C,OAAOA,EAAK,YAAcA,EAAK,aAAa,CAAE,KAAM,MAAO,CAAC,CAC9D,CAGA,SAASC,EAAaC,EAA6C,CAGjE,OAFIA,IAAU,IAAA,GAAkB,SAAS,MAC3B,OAAOA,GAAU,WAAaA,EAAM,EAAIA,IACtC,IAClB,CAqCA,SAAgBC,EAAOC,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,EAAU,CAAE,KAAMX,EAAQ,OAAQsB,EAAS,OAAQ,YAAaA,EAAS,WAAY,CACvF,EA6BA,OA3BAxB,OAIW,CAAE,KAFIM,EAAaG,EAAM,KAEpB,EAAG,OADAA,EAAM,YAAc,EACb,IAEvB,CAAEJ,OAAMoB,YAAa,CACpB,GAAIpB,IAAS,KAAM,CACjBU,EAAQ,EAGR,IAAK,IAAMZ,KAAQW,GAAW,CAAC,EAAGX,EAAK,YAAY,YAAYA,CAAI,EACnEW,EAAU,IAAA,GAOV,MACF,CACA,IAAMZ,EAAeuB,EAASrB,EAAaC,CAAI,EAAIA,GAC/CQ,IAAY,IAAA,IAAaA,EAAQ,OAASX,IAC9CqB,EAAOrB,CAAM,CACf,CACF,EACAL,EAAUkB,CAAO,EACV,IACT,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root-errors.js","names":["ROOT_ERRORS","attachRootErrors","
|
|
1
|
+
{"version":3,"file":"root-errors.js","names":["getOwner","ROOT_ERRORS","attachRootErrors","options","root","map","rootErrorsOf","owner"],"sources":["../../../src/control-flow/root-errors.ts"],"sourcesContent":["import { getOwner, type Owner } from \"@shadow-js/core\";\n\n/**\n * The error reporters a root was rendered or hydrated with (see `RenderOptions` and `HydrateOptions`).\n * @since 1.0.0\n */\nexport interface RootErrorOptions {\n /**\n * Receives an error that no error boundary took. The root then does not rethrow it.\n * @default undefined (no reporter; an error no boundary takes follows the default handling)\n */\n readonly onUncaughtError?: (error: unknown) => void;\n /**\n * Receives an error an `ErrorBoundary` caught (its fallback is shown).\n * @default undefined (no reporter)\n */\n readonly onCaughtError?: (error: unknown) => void;\n /**\n * Receives a hydration mismatch that was repaired on the client. Only `hydrate` reports these.\n * @default undefined (no reporter)\n */\n readonly onRecoverableError?: (error: unknown) => void;\n}\n\n/**\n * The key the reporters are stored under in an owner's context map. A symbol the context map inherits\n * (as a Provider's value is inherited), so every node below the root sees it, detached roots included.\n * A plain value rather than a context: a context would bring its Provider into every bundle.\n */\nconst ROOT_ERRORS: symbol = /* @__PURE__ */ Symbol(\"RootErrors\");\n\n/**\n * Attaches the options to the root that is being created (called inside its `createRoot`). The reporters\n * go into the root's context map, and an `onUncaughtError` becomes the root's error handler (a fresh root\n * has none, so it is the only one).\n * @internal\n */\nexport function attachRootErrors(options: RootErrorOptions): void {\n const root = getOwner();\n if (root === null) return;\n const map = Object.create(root.context) as Record<symbol, unknown>;\n map[ROOT_ERRORS] = options;\n root.context = map;\n if (options.onUncaughtError !== undefined) root.errorHandlers = [options.onUncaughtError];\n}\n\n/**\n * The reporters of the nearest root above `owner`, or undefined when no root was given options.\n * @internal\n */\nexport function rootErrorsOf(owner: Owner | null): RootErrorOptions | undefined {\n return owner?.context?.[ROOT_ERRORS] as RootErrorOptions | undefined;\n}\n"],"mappings":"A,2CA6BA,MAAMC,EAAsC,uBAAO,YAAY,EAQ/D,SAAgBC,EAAiBC,EAAiC,CAChE,IAAMC,EAAOJ,EAAS,EACtB,GAAII,IAAS,KAAM,OACnB,IAAMC,EAAM,OAAO,OAAOD,EAAK,OAAO,EACtCC,EAAIJ,GAAeE,EACnBC,EAAK,QAAUC,EACXF,EAAQ,kBAAoB,IAAA,KAAWC,EAAK,cAAgB,CAACD,EAAQ,eAAe,EAC1F,CAMA,SAAgBG,EAAaC,EAAmD,CAC9E,OAAOA,GAAO,UAAUN,EAC1B,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"show.js","names":["
|
|
1
|
+
{"version":3,"file":"show.js","names":["createBranches","Show","props","when"],"sources":["../../../src/control-flow/show.ts"],"sourcesContent":["import type { Accessor } from \"@shadow-js/core\";\nimport type { JsxChild } from \"../jsx/types\";\nimport { createBranches, FALLBACK } from \"./branch\";\n\n/** What `when` accepts: the value, or any falsy stand-in (`0` and `\"\"` count as falsy). */\ntype ShowCondition<T> = T | undefined | null | false | 0 | \"\";\n\n/** Props shared by both forms of {@link Show}. */\ninterface ShowBaseProps<T> {\n /** The condition. The children are shown while it is truthy. */\n readonly when: ShowCondition<T>;\n /**\n * Shown while `when` is falsy. Read lazily, only when it is needed.\n * @default undefined (a falsy `when` renders nothing)\n */\n readonly fallback?: unknown;\n}\n\n/**\n * Keyed form: the children are rebuilt whenever the identity of `when` changes and a callback\n * child receives the value itself.\n * @since 1.0.0\n */\nexport interface ShowKeyedProps<T> extends ShowBaseProps<T> {\n /** Must be `true` in this form: a change of the identity of `when` rebuilds the children. */\n readonly keyed: true;\n /**\n * Plain content, an accessor, or a callback `(item) => content` called untracked in the branch.\n * @default undefined (a truthy `when` renders nothing)\n */\n readonly children?: JsxChild | (() => unknown) | ((item: NonNullable<T>) => unknown);\n}\n\n/**\n * Default form: the branch is rebuilt only when the truthiness of `when` changes. A callback child\n * receives an accessor of the latest truthy value; reading it after `when` became falsy throws a\n * TypeError, except while the branch is being torn down.\n * @since 1.0.0\n */\nexport interface ShowAccessorProps<T> extends ShowBaseProps<T> {\n /**\n * Absent or `false` in this form: the children are rebuilt only when the truthiness of `when`\n * changes.\n * @default false\n */\n readonly keyed?: false;\n /**\n * Plain content, an accessor, or a callback `(item) => content` called untracked in the branch.\n * @default undefined (a truthy `when` renders nothing)\n */\n readonly children?: JsxChild | (() => unknown) | ((item: Accessor<NonNullable<T>>) => unknown);\n}\n\n/**\n * Props of {@link Show}.\n * @since 1.0.0\n */\nexport type ShowProps<T> = ShowKeyedProps<T> | ShowAccessorProps<T>;\n\n/**\n * The same props with untyped `children`, for code that forwards children it does not know the\n * shape of (a wrapper component's own `props.children`).\n * @since 1.0.0\n */\nexport interface ShowLooseProps<T> extends ShowBaseProps<T> {\n /**\n * Same meaning as in {@link ShowKeyedProps}: `true` rebuilds the children when the identity of\n * `when` changes.\n * @default false\n */\n readonly keyed?: boolean;\n /**\n * Plain content, an accessor, or a callback, as in {@link ShowProps}.\n * @default undefined (a truthy `when` renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * Shows `children` while `when` is truthy, and `fallback` otherwise. The branch is rebuilt only\n * when the truthiness of `when` changes (or, with `keyed`, when its identity changes).\n *\n * `when` follows JavaScript truthiness: `0`, `\"\"`, `null`, `undefined` and `false` show the\n * fallback. While `fallback` is not given, a falsy `when` renders nothing.\n *\n * @param props See {@link ShowProps}.\n * @returns An accessor of the current branch's content. The DOM runtime's `insert` consumes it.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { Show } from \"@shadow-js/web\";\n *\n * function Greeting() {\n * const [user] = useSignal<{ name: string } | null>(null);\n * return (\n * <Show when={user()} fallback={<p>Sign in</p>}>\n * {(u) => <p>Hello {u().name}</p>}\n * </Show>\n * );\n * }\n * @see Switch\n * @see ErrorBoundary\n * @since 1.0.0\n */\nexport function Show<T>(props: ShowProps<T>): Accessor<unknown>;\nexport function Show<T>(props: ShowLooseProps<T>): Accessor<unknown>;\nexport function Show<T>(props: ShowLooseProps<T>): Accessor<unknown> {\n return createBranches(\n \"Show\",\n () => {\n const when = props.when;\n return {\n index: when ? 0 : FALLBACK,\n keyed: props.keyed === true,\n when,\n read: () => props.when,\n body: () => props.children,\n };\n },\n () => props.fallback,\n );\n}\n"],"mappings":"A,6CAyGA,SAAgBC,EAAQC,EAA6C,CACnE,OAAOF,EACL,WACM,CACJ,IAAMG,EAAOD,EAAM,KACnB,MAAO,CACL,MAAOC,EAAO,EAAA,GACd,MAAOD,EAAM,QAAU,GACvBC,OACA,SAAYD,EAAM,KAClB,SAAYA,EAAM,QACpB,CACF,MACMA,EAAM,QACd,CACF,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suspense-list.js","names":["
|
|
1
|
+
{"version":3,"file":"suspense-list.js","names":["createContext","onCleanup","useContext","SignalNode","readSignal","writeSignal","SuspenseListContext","SuspenseList","props","changes","slots","touch","ready","entry","index","position","reveal","slot","order","ordered","wanted","i","candidate","registerInList","list"],"sources":["../../../src/control-flow/suspense-list.ts"],"sourcesContent":["import { type Accessor, type Context, createContext, onCleanup, useContext } from \"@shadow-js/core\";\nimport { readSignal, SignalNode, writeSignal } from \"@shadow-js/core/extend\";\n\n/** What a `<Suspense>` inside a list learns about its place: when to show content and a fallback. @internal */\nexport interface SuspenseListSlot {\n /** True when this boundary may show its content now (it is ready and the order allows it). */\n reveal(): boolean;\n /** True when this boundary should show its fallback while it waits. */\n showFallback(): boolean;\n}\n\n/** Provided by `<SuspenseList>` to the boundaries below it. @internal */\nexport interface SuspenseListState {\n /** Registers a boundary, in creation order; `ready` reports that its own data has loaded. */\n register(ready: () => boolean): SuspenseListSlot;\n}\n\n/** The enclosing list, or null. @internal */\nexport const SuspenseListContext: Context<SuspenseListState | null> =\n /* @__PURE__ */ createContext<SuspenseListState | null>(null, { name: \"SuspenseList\" });\n\n/**\n * Props of {@link SuspenseList}.\n * @since 1.0.0\n */\nexport interface SuspenseListProps {\n /**\n * `\"forwards\"`: boundaries reveal in order, each after the ones before it. `\"backwards\"`: the\n * same from the last one. `\"together\"`: all at once, when the last one is ready. Without it each\n * boundary reveals on its own. Read reactively.\n * @default undefined (each boundary reveals as soon as its own data is ready)\n */\n readonly revealOrder?: \"forwards\" | \"backwards\" | \"together\" | undefined;\n /**\n * What the boundaries that are still waiting show: `\"collapsed\"` only the next fallback in\n * order, `\"hidden\"` none. Applies to `forwards` and `backwards`; the default shows every fallback.\n * @default undefined (every waiting boundary shows its fallback)\n */\n readonly tail?: \"collapsed\" | \"hidden\" | undefined;\n /**\n * The content, with the `<Suspense>` boundaries to coordinate anywhere below it.\n * @default undefined (renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * Coordinates the `<Suspense>` boundaries below it so a page of independent loads reveals in a\n * calm order instead of popping in at random.\n *\n * @param props See {@link SuspenseListProps}.\n * @returns An accessor of the children, rendered with the list's coordination in context.\n * @example\n * import { Suspense, SuspenseList } from \"@shadow-js/web\";\n *\n * function Skeleton() {\n * return <p>Loading...</p>;\n * }\n *\n * function Profile() {\n * return <p>Profile</p>;\n * }\n *\n * function Feed() {\n * return <p>Feed</p>;\n * }\n *\n * function Page() {\n * return (\n * <SuspenseList revealOrder=\"forwards\" tail=\"collapsed\">\n * <Suspense fallback={<Skeleton />}>\n * <Profile />\n * </Suspense>\n * <Suspense fallback={<Skeleton />}>\n * <Feed />\n * </Suspense>\n * </SuspenseList>\n * );\n * }\n * @see Suspense\n * @since 1.0.0\n */\nexport function SuspenseList(props: SuspenseListProps): Accessor<unknown> {\n // The set of boundaries changes as they are created and disposed; `changes` tells readers.\n const changes = new SignalNode<number>(0, false);\n const slots: Array<{ readonly ready: () => boolean }> = [];\n const touch = (): void => {\n writeSignal(changes, 0, { allowInMemo: true });\n };\n\n const state: SuspenseListState = {\n register(ready) {\n const entry = { ready };\n slots.push(entry);\n touch();\n onCleanup(() => {\n const index = slots.indexOf(entry);\n if (index !== -1) slots.splice(index, 1);\n touch();\n });\n const position = (): number => {\n readSignal(changes);\n return slots.indexOf(entry);\n };\n const reveal = (): boolean => {\n const index = position();\n if (index === -1) return false;\n switch (props.revealOrder) {\n case \"together\":\n return slots.every((slot) => slot.ready());\n case \"forwards\":\n return slots.slice(0, index + 1).every((slot) => slot.ready());\n case \"backwards\":\n return slots.slice(index).every((slot) => slot.ready());\n default:\n return ready();\n }\n };\n const showFallback = (): boolean => {\n if (reveal()) return false;\n const order = props.revealOrder;\n const sequential = order === \"forwards\" || order === \"backwards\";\n if (!sequential) return true;\n if (props.tail === \"hidden\") return false;\n if (props.tail !== \"collapsed\") return true;\n // Only the next boundary in order that is not revealed yet shows its fallback.\n const index = position();\n const ordered = order === \"backwards\" ? [...slots].reverse() : slots;\n const wanted = order === \"backwards\" ? slots.length - 1 - index : index;\n for (let i = 0; i < ordered.length; i += 1) {\n const candidate = ordered[i];\n if (candidate !== undefined && !candidate.ready()) return i === wanted;\n }\n return false;\n };\n return { reveal, showFallback };\n },\n };\n\n return SuspenseListContext({\n value: state,\n get children() {\n return props.children;\n },\n }) as Accessor<unknown>;\n}\n\n/** The slot of the nearest list for a boundary created now, or null outside a list. @internal */\nexport function registerInList(ready: () => boolean): SuspenseListSlot | null {\n const list = useContext(SuspenseListContext);\n return list === null ? null : list.register(ready);\n}\n"],"mappings":"A,oKAkBA,MAAaM,EACKN,kBAAwC,KAAM,CAAE,KAAM,cAAe,CAAC,EA+DxF,SAAgBO,EAAaC,EAA6C,CAExE,IAAMC,EAAU,IAAIN,EAAmB,EAAG,EAAK,EACzCO,EAAkD,CAAC,EACnDC,MAAoB,CACxBN,EAAYI,EAAS,EAAG,CAAE,YAAa,EAAK,CAAC,CAC/C,EAmDA,OAAOH,EAAoB,CACzB,MAAO,CAjDP,SAASM,EAAO,CACd,IAAMC,EAAQ,CAAED,OAAM,EACtBF,EAAM,KAAKG,CAAK,EAChBF,EAAM,EACNV,MAAgB,CACd,IAAMa,EAAQJ,EAAM,QAAQG,CAAK,EAC7BC,IAAU,IAAIJ,EAAM,OAAOI,EAAO,CAAC,EACvCH,EAAM,CACR,CAAC,EACD,IAAMI,OACJX,EAAWK,CAAO,EACXC,EAAM,QAAQG,CAAK,GAEtBG,MAAwB,CAC5B,IAAMF,EAAQC,EAAS,EACvB,GAAID,IAAU,GAAI,MAAO,GACzB,OAAQN,EAAM,YAAd,CACE,IAAK,WACH,OAAOE,EAAM,MAAOO,GAASA,EAAK,MAAM,CAAC,EAC3C,IAAK,WACH,OAAOP,EAAM,MAAM,EAAGI,EAAQ,CAAC,CAAC,CAAC,MAAOG,GAASA,EAAK,MAAM,CAAC,EAC/D,IAAK,YACH,OAAOP,EAAM,MAAMI,CAAK,CAAC,CAAC,MAAOG,GAASA,EAAK,MAAM,CAAC,EACxD,QACE,OAAOL,EAAM,CACjB,CACF,EAkBA,MAAO,CAAEI,SAAQ,iBAjBmB,CAClC,GAAIA,EAAO,EAAG,MAAO,GACrB,IAAME,EAAQV,EAAM,YAEpB,GADmBU,IAAU,YAAcA,IAAU,YACpC,MAAO,GACxB,GAAIV,EAAM,OAAS,SAAU,MAAO,GACpC,GAAIA,EAAM,OAAS,YAAa,MAAO,GAEvC,IAAMM,EAAQC,EAAS,EACjBI,EAAUD,IAAU,YAAc,CAAC,GAAGR,CAAK,CAAC,CAAC,QAAQ,EAAIA,EACzDU,EAASF,IAAU,YAAcR,EAAM,OAAS,EAAII,EAAQA,EAClE,IAAK,IAAIO,EAAI,EAAGA,EAAIF,EAAQ,OAAQE,GAAK,EAAG,CAC1C,IAAMC,EAAYH,EAAQE,GAC1B,GAAIC,IAAc,IAAA,IAAa,CAACA,EAAU,MAAM,EAAG,OAAOD,IAAMD,CAClE,CACA,MAAO,EACT,CAC8B,CAChC,CAIW,EACX,IAAI,UAAW,CACb,OAAOZ,EAAM,QACf,CACF,CAAC,CACH,CAGA,SAAgBe,EAAeX,EAA+C,CAC5E,IAAMY,EAAOtB,EAAWI,CAAmB,EAC3C,OAAOkB,IAAS,KAAO,KAAOA,EAAK,SAASZ,CAAK,CACnD,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suspense.js","names":["
|
|
1
|
+
{"version":3,"file":"suspense.js","names":["childScope","nextKey","withScope","registerInList","SuspenseContext","runWithOwner","useMemo","SignalNode","createOwner","readSignal","transitionHooks","writeSignal","createTracker","pending","hold","shown","adjust","by","Suspense","props","key","tracker","count","holding","revealed","slot","boundary","content","fallbackScope","previous"],"sources":["../../../src/control-flow/suspense.ts"],"sourcesContent":["import {\n type Accessor,\n getOwner,\n runWithOwner,\n SuspenseContext,\n type SuspenseTracker,\n useContext,\n useMemo,\n} from \"@shadow-js/core\";\nimport {\n type BoundaryHold,\n createOwner,\n readSignal,\n SignalNode,\n transitionHooks,\n writeSignal,\n} from \"@shadow-js/core/extend\";\nimport { childScope, nextKey, StreamContext, withScope } from \"../extend\";\nimport { ssrRaw } from \"../server/element\";\n// biome-ignore lint/suspicious/noShadowRestrictedNames: `escape` is the compiler's SSR helper name.\nimport { escape } from \"../server/escape\";\nimport { registerInList } from \"./suspense-list\";\n\n/**\n * Props of {@link Suspense}.\n * @since 1.0.0\n */\nexport interface SuspenseProps {\n /**\n * Shown while any resource read inside the boundary is loading for the first time.\n * @default undefined (a pending boundary renders nothing)\n */\n fallback?: unknown;\n /**\n * The content. Created once, under the boundary, and kept alive while the fallback is visible.\n * @default undefined (renders nothing)\n */\n children?: unknown;\n}\n\n/** What a boundary tracks: its pending reads, and whether a transition holds its content. */\ninterface Tracking {\n readonly tracker: SuspenseTracker;\n readonly count: () => number;\n /** True while a transition waits for data and the boundary keeps showing its content. */\n readonly holding: () => boolean;\n /** Called when the boundary first shows its content: only then can a transition hold it. */\n readonly revealed: () => void;\n}\n\n/**\n * A counter the resources of one boundary report to (see {@link SuspenseTracker}), and the hold a\n * transition takes on the boundary. A transition that reads pending data while the boundary shows\n * content does not bring the fallback back: its readers keep their previous values, the boundary\n * keeps its content, and the readers run again when the count returns to zero.\n */\nfunction createTracker(): Tracking {\n // Counted with an extension-API cell: a resource may be read (and so hold this boundary) while a\n // memo computes, where a plain write would be rejected.\n const pending = new SignalNode<number>(0, Object.is);\n // The hold a transition takes on this boundary. Only a transition read creates it (core keeps the\n // machinery of holds behind its transition hooks); the boundary's memo reads the count before it\n // reads the hold, so it runs again when the count reaches zero (the release).\n let hold: BoundaryHold | undefined;\n let shown = false;\n const adjust = (by: number): void => {\n writeSignal(pending, pending.value + by, { allowInMemo: true });\n };\n const tracker: SuspenseTracker = {\n increment: () => adjust(1),\n decrement: () => {\n adjust(-1);\n if (pending.value === 0) hold?.release();\n },\n hold: (): boolean => {\n if (!shown) return false;\n hold ??= transitionHooks()?.boundaryHold();\n return hold?.engage() === true;\n },\n };\n return {\n tracker,\n count: () => readSignal(pending),\n holding: () => hold?.holding() === true,\n revealed: () => {\n shown = true;\n },\n };\n}\n\n/**\n * Shows `fallback` while resources read inside it are loading for the first time. The children\n * are created once and stay alive (with their state) while the fallback is visible; the boundary\n * only switches what is displayed. Nested boundaries each track their own resources.\n *\n * On the server a boundary renders its fallback when its data is not ready (`renderToString`), or\n * streams the content later (`renderToStream`). Content and fallback get their own hydration key\n * space, so what a boundary renders never shifts the keys of its siblings.\n *\n * @param props See {@link SuspenseProps}.\n * @returns An accessor of what the boundary shows: the fallback while a resource is pending, the\n * children otherwise.\n * @example\n * import { useResource } from \"@shadow-js/core\";\n * import { Suspense } from \"@shadow-js/web\";\n *\n * function Profile() {\n * const name = useResource(() => Promise.resolve(\"Ada\"));\n * return <p>{name()}</p>;\n * }\n *\n * function Page() {\n * return (\n * <Suspense fallback={<p>Loading...</p>}>\n * <Profile />\n * </Suspense>\n * );\n * }\n * @see SuspenseList\n * @see ErrorBoundary\n * @since 1.0.0\n */\nexport function Suspense(props: SuspenseProps): Accessor<unknown> {\n const key = nextKey();\n const { tracker, count, holding, revealed } = createTracker();\n // The content lives under its own owner, whose gate holds back user effects and `onMount` until\n // the boundary has resolved once. Render effects (DOM bindings) are never held.\n // Inside a <SuspenseList> the boundary also waits for its turn to be revealed.\n const slot = __SERVER__ ? null : registerInList(() => count() === 0);\n const boundary = createOwner();\n boundary.gate = () => count() > 0 || (slot !== null && !slot.reveal());\n const content = runWithOwner(boundary, () =>\n withScope(childScope(key), () =>\n SuspenseContext({\n value: tracker,\n get children() {\n return props.children;\n },\n }),\n ),\n );\n if (__SERVER__) return suspenseOnServer(props, key, count, content as () => unknown);\n const fallbackScope = childScope(key === undefined ? undefined : `${key}f`);\n return useMemo<unknown>(\n (previous) => {\n // Read first: the memo depends on the count even while held, so it runs again when the hold ends.\n count();\n // A transition holds the boundary: the content stays as it was (the same value, so no DOM change).\n if (holding() && previous !== undefined) return previous;\n if (slot === null) {\n if (count() > 0) return withScope(fallbackScope, () => props.fallback);\n revealed();\n return (content as () => unknown)();\n }\n if (count() === 0 && slot.reveal()) {\n revealed();\n return (content as () => unknown)();\n }\n return slot.showFallback() ? withScope(fallbackScope, () => props.fallback) : null;\n },\n { allowWrites: true },\n );\n}\n\n/** Server behavior: ready content, a fallback, or a fallback plus a deferred stream chunk. */\nfunction suspenseOnServer(\n props: SuspenseProps,\n key: string | undefined,\n count: () => number,\n content: () => unknown,\n): Accessor<unknown> {\n const fallbackScope = childScope(key === undefined ? undefined : `${key}f`);\n if (count() === 0) return content;\n const sink = useContext(StreamContext);\n if (sink === null || key === undefined) {\n return () => withScope(fallbackScope, () => props.fallback);\n }\n const owner = getOwner();\n const boundary = {\n id: key,\n rebuild: (): string | null => {\n const next = createTracker();\n const rebuilt = runWithOwner(owner, () =>\n withScope(childScope(key), () =>\n SuspenseContext({\n value: next.tracker,\n get children() {\n return props.children;\n },\n }),\n ),\n );\n if (next.count() > 0) {\n sink.defer(boundary);\n return null;\n }\n return escape((rebuilt as () => unknown)());\n },\n };\n sink.defer(boundary);\n // The markers delimit the region the stream later replaces; hydration strips them.\n return () => [\n ssrRaw(`<!--[b:${key}-->`),\n withScope(fallbackScope, () => props.fallback),\n ssrRaw(\"<!--]-->\"),\n ];\n}\n"],"mappings":"A,wVAwDA,SAASY,GAA0B,CAGjC,IAAMC,EAAU,IAAIN,EAAmB,EAAG,OAAO,EAAE,EAI/CO,EACAC,EAAQ,GACNC,EAAUC,GAAqB,CACnCN,EAAYE,EAASA,EAAQ,MAAQI,EAAI,CAAE,YAAa,EAAK,CAAC,CAChE,EAaA,MAAO,CACL,QAAA,CAZA,cAAiBD,EAAO,CAAC,EACzB,cAAiB,CACfA,EAAO,EAAE,EACLH,EAAQ,QAAU,GAAGC,GAAM,QAAQ,CACzC,EACA,SACOC,GACLD,IAASJ,EAAgB,CAAC,EAAE,aAAa,EAClCI,GAAM,OAAO,IAAM,IAFP,EAMf,EACN,UAAaL,EAAWI,CAAO,EAC/B,YAAeC,GAAM,QAAQ,IAAM,GACnC,aAAgB,CACdC,EAAQ,EACV,CACF,CACF,CAkCA,SAAgBG,EAASC,EAAyC,CAChE,IAAMC,EAAMnB,EAAQ,EACd,CAAEoB,UAASC,QAAOC,UAASC,YAAaZ,EAAc,EAItDa,EAA2BtB,MAAqBmB,EAAM,IAAM,CAAC,EAC7DI,EAAWlB,EAAY,EAC7BkB,EAAS,SAAaJ,EAAM,EAAI,GAAMG,IAAS,MAAQ,CAACA,EAAK,OAAO,EACpE,IAAME,EAAUtB,EAAaqB,MAC3BxB,EAAUF,EAAWoB,CAAG,MACtBhB,EAAgB,CACd,MAAOiB,EACP,IAAI,UAAW,CACb,OAAOF,EAAM,QACf,CACF,CAAC,CACH,CACF,EAEMS,EAAgB5B,EAAWoB,IAAQ,IAAA,GAAY,IAAA,GAAY,GAAGA,EAAI,EAAE,EAC1E,OAAOd,EACJuB,IAECP,EAAM,EAEFC,EAAQ,GAAKM,IAAa,IAAA,GAAkBA,EAC5CJ,IAAS,KACPH,EAAM,EAAI,EAAUpB,EAAU0B,MAAqBT,EAAM,QAAQ,GACrEK,EAAS,EACDG,EAA0B,GAEhCL,EAAM,IAAM,GAAKG,EAAK,OAAO,GAC/BD,EAAS,EACDG,EAA0B,GAE7BF,EAAK,aAAa,EAAIvB,EAAU0B,MAAqBT,EAAM,QAAQ,EAAI,MAEhF,CAAE,YAAa,EAAK,CACtB,CACF,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.js","names":["resolveChildren","Match","props","isMatch","item","matchesOf","
|
|
1
|
+
{"version":3,"file":"switch.js","names":["resolveChildren","createBranches","children","Match","props","isMatch","item","matchesOf","resolved","matches","Switch","list","index","match","when"],"sources":["../../../src/control-flow/switch.ts"],"sourcesContent":["import { type Accessor, type ResolvedChildren, children as resolveChildren } from \"@shadow-js/core\";\nimport { createBranches, FALLBACK } from \"./branch\";\n\n/**\n * Props of {@link Match}. A Match descriptor is the props object itself.\n * @since 1.0.0\n */\nexport interface MatchProps<T> {\n /** The condition. The first Match whose `when` is truthy is shown. */\n readonly when: T | undefined | null | false | 0 | \"\";\n /**\n * Same meaning as in {@link ShowLooseProps}: `true` rebuilds the branch when the identity of\n * `when` changes.\n * @default false\n */\n readonly keyed?: boolean;\n /**\n * The branch content: plain content, an accessor, or a callback, as the children of\n * {@link ShowProps}.\n * @default undefined (the selected Match renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * Describes one branch of a {@link Switch}. It returns its props unchanged.\n *\n * @param props The condition and the branch content.\n * @returns The same props object, which `Switch` reads.\n * @example\n * import { Match } from \"@shadow-js/web\";\n *\n * const branch = Match({ when: \"ready\", children: \"Loaded\" });\n * console.log(branch.when); // \"ready\"\n * @see Switch\n * @since 1.0.0\n */\nexport function Match<T>(props: MatchProps<T>): MatchProps<T> {\n return props;\n}\n\n/**\n * Props of {@link Switch}.\n * @since 1.0.0\n */\nexport interface SwitchProps {\n /**\n * Shown when no Match is truthy. Read lazily.\n * @default undefined (nothing is rendered when no Match is truthy)\n */\n readonly fallback?: unknown;\n /**\n * One or more {@link Match} descriptors. `null`, `undefined` and booleans are ignored.\n * @default undefined (no branches; the fallback is shown)\n */\n readonly children?: unknown;\n}\n\n/** A Match descriptor is any object with a `when` key. Anything else is not a Match. */\nfunction isMatch(item: unknown): item is MatchProps<unknown> {\n return typeof item === \"object\" && item !== null && \"when\" in item;\n}\n\n/** Resolves the children into Match descriptors. Throws for any other kind of child. */\nfunction matchesOf(resolved: ResolvedChildren): MatchProps<unknown>[] {\n const matches: MatchProps<unknown>[] = [];\n for (const item of resolved.toArray()) {\n if (!isMatch(item))\n throw new TypeError(\n __DEV__ ? \"ShadowJS Switch: children must be <Match>\" : \"SHADOW_SWITCH_CHILDREN\",\n );\n matches.push(item);\n }\n return matches;\n}\n\n/**\n * Shows the first {@link Match} whose `when` is truthy, or the fallback when none is.\n * Re-selecting the same branch with the same truthiness (or, when keyed, the same value) does not\n * rebuild it.\n *\n * @param props See {@link SwitchProps}.\n * @returns An accessor of the selected branch's content.\n * @throws TypeError (production message `SHADOW_SWITCH_CHILDREN`) when a child is neither a Match\n * nor `null`, `undefined` or a boolean.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { Match, Switch } from \"@shadow-js/web\";\n *\n * function Status() {\n * const [error] = useSignal<string | null>(null);\n * const [data] = useSignal<string | null>(\"ready\");\n * return (\n * <Switch fallback={<p>Loading...</p>}>\n * <Match when={error()}>\n * <p>Failed</p>\n * </Match>\n * <Match when={data()}>\n * <p>Ready</p>\n * </Match>\n * </Switch>\n * );\n * }\n * @see Show\n * @since 1.0.0\n */\nexport function Switch(props: SwitchProps): Accessor<unknown> {\n const matches = resolveChildren(() => props.children);\n // Validate now, so that a wrong child is reported where the Switch is written.\n matchesOf(matches);\n return createBranches(\n \"Switch\",\n () => {\n const list = matchesOf(matches);\n for (const [index, match] of list.entries()) {\n const when = match.when;\n if (when) {\n return {\n index,\n keyed: match.keyed === true,\n when,\n read: () => match.when,\n body: () => match.children,\n };\n }\n }\n return {\n index: FALLBACK,\n keyed: false,\n when: undefined,\n read: () => undefined,\n body: () => undefined,\n };\n },\n () => props.fallback,\n );\n}\n"],"mappings":"A,wFAqCA,SAAgBG,EAASC,EAAqC,CAC5D,OAAOA,CACT,CAoBA,SAASC,EAAQC,EAA4C,CAC3D,OAAO,OAAOA,GAAS,YAAYA,GAAiB,SAAUA,CAChE,CAGA,SAASC,EAAUC,EAAmD,CACpE,IAAMC,EAAiC,CAAC,EACxC,IAAK,IAAMH,KAAQE,EAAS,QAAQ,EAAG,CACrC,GAAI,CAACH,EAAQC,CAAI,EACf,MAAU,UACgD,wBAC1D,EACFG,EAAQ,KAAKH,CAAI,CACnB,CACA,OAAOG,CACT,CAgCA,SAAgBC,EAAON,EAAuC,CAC5D,IAAMK,EAAUT,MAAsBI,EAAM,QAAQ,EAGpD,OADAG,EAAUE,CAAO,EACVR,EACL,aACM,CACJ,IAAMU,EAAOJ,EAAUE,CAAO,EAC9B,IAAK,GAAM,CAACG,EAAOC,KAAUF,EAAK,QAAQ,EAAG,CAC3C,IAAMG,EAAOD,EAAM,KACnB,GAAIC,EACF,MAAO,CACLF,QACA,MAAOC,EAAM,QAAU,GACvBC,OACA,SAAYD,EAAM,KAClB,SAAYA,EAAM,QACpB,CAEJ,CACA,MAAO,CACL,MAAA,GACA,MAAO,GACP,KAAM,IAAA,GACN,SAAY,IAAA,GACZ,SAAY,IAAA,EACd,CACF,MACMT,EAAM,QACd,CACF,C"}
|
package/dist/prod/derived.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derived.js","names":["
|
|
1
|
+
{"version":3,"file":"derived.js","names":["useMemo","derived","compute","memo","read","args","current"],"sources":["../../src/derived.ts"],"sourcesContent":["import { useMemo } from \"@shadow-js/core\";\n\n/**\n * A value the compiler keeps live: the result of `const x = <expression reading signals>` inside a\n * component. Read it as `x.value` or call it as `x()`, so `{double}` and `{double()}` both work in\n * JSX. When the value is itself a function, calling the derived calls that function with the\n * arguments, so a derived function stays callable.\n *\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { derived } from \"@shadow-js/web\";\n *\n * function setup() {\n * const [count, setCount] = useSignal(2);\n * const double = derived(() => count() * 2);\n * console.log(double.value); // 4\n * setCount(5);\n * console.log(double()); // 10\n * }\n * @see derived\n * @since 1.0.0\n */\nexport interface Derived<T> {\n /**\n * Returns the current value, tracked. When the value is a function, calls it with `args` and\n * returns its result instead.\n */\n (...args: unknown[]): unknown;\n /** The current value, tracked: reading it inside an effect or binding subscribes that reader. */\n readonly value: T;\n}\n\n/**\n * Wraps a computation as a {@link Derived} value that recomputes only when the signals it reads\n * change. The compiler emits it for `const x = <expression reading signals>` inside components; it\n * is not meant to be written by hand.\n *\n * @param compute The computation. Runs in a memo, so it is tracked and cached between reads.\n * @returns A {@link Derived} whose `value` (and call result) follows `compute`.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { derived } from \"@shadow-js/web\";\n *\n * function setup() {\n * const [price] = useSignal(20);\n * const total = derived(() => price() * 3);\n * console.log(total.value); // 60\n * }\n * @see Derived\n * @since 1.0.0\n */\nexport function derived<T>(compute: () => T): Derived<T> {\n const memo = useMemo(compute);\n const read = ((...args: unknown[]): unknown => {\n const current = memo();\n return typeof current === \"function\"\n ? (current as (...a: unknown[]) => unknown)(...args)\n : current;\n }) as { (...args: unknown[]): unknown; value: T };\n Object.defineProperty(read, \"value\", { get: memo });\n return read as Derived<T>;\n}\n"],"mappings":"A,0CAmDA,SAAgBC,EAAWC,EAA8B,CACvD,IAAMC,EAAOH,EAAQE,CAAO,EACtBE,IAAS,GAAGC,IAA6B,CAC7C,IAAMC,EAAUH,EAAK,EACrB,OAAO,OAAOG,GAAY,WACrBA,EAAyC,GAAGD,CAAI,EACjDC,CACN,GAEA,OADA,OAAO,eAAeF,EAAM,QAAS,CAAE,IAAKD,CAAK,CAAC,EAC3CC,CACT,C"}
|
package/dist/prod/element.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.js","names":["
|
|
1
|
+
{"version":3,"file":"element.js","names":["setAttribute","setBoolAttribute","style","insert","claims","nextKey","isFlagAttribute","batch","untrack","useRenderEffect","TAG_PATTERN","element","tag","props","read","el","key","handler","tuple","fn","data","event","applied","value","name","ref","\"ref\"","\"children\""],"sources":["../../src/element.ts"],"sourcesContent":["import { batch, untrack, useRenderEffect } from \"@shadow-js/core\";\nimport { setAttribute, setBoolAttribute } from \"./attributes\";\nimport { style } from \"./class-style\";\nimport { insert } from \"./insert\";\nimport { checkClaimedTag } from \"./internal/claim\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { nextKey } from \"./internal/hydration-scope\";\nimport { isFlagAttribute } from \"./internal/react-names\";\nimport { ssrElement, ssrRaw } from \"./server/element\";\nimport { isTextOnlyElement } from \"./server/raw-text\";\n\n/**\n * The slim element primitive: one HTML element with attributes, event listeners, `ref` and children,\n * and no generic prop runtime. `Dynamic` and `spread` cover every prop shape; this covers the common\n * ones, so a library that renders one fixed element (a link, a button) pays for what it binds.\n *\n * It keeps the renderer's contracts: the hydration key is drawn when the element is created, so it\n * claims the server's element and adopts its children; on the server it writes the same markup `Dynamic`\n * writes for the tag.\n */\n\n/** Tag shape that `Dynamic` accepts. `script` is refused for the same reason. */\nconst TAG_PATTERN = /^[a-z][a-z0-9-]*$/i;\n\n/**\n * Creates one HTML element from a tag name and a props object, without the generic prop runtime of\n * `spread` and `Dynamic`: for a library that renders one fixed element (a link, a button) and wants\n * to pay only for what it binds. It draws a hydration key, so during `hydrate()` it adopts the\n * server's element and its children; on the server it returns the markup `Dynamic` writes for the tag.\n *\n * Each prop other than `children`, `ref` and `onX` is read in a render effect, so a getter prop\n * updates the element in place. `class` and the other attributes follow {@link setAttribute} (URL\n * attributes that would run script are refused); `style` follows {@link style}. Use `Dynamic` when the\n * tag is not known in advance, or for SVG, `classList`, delegated events or React prop names.\n *\n * @param tag An HTML tag name matching `[a-z][a-z0-9-]*` (any case), such as `\"a\"`. `script` is\n * refused.\n * @param props The element's props. `onX` keys whose third letter is uppercase are native listeners,\n * read once: the rest of the key lowercased is the event (`onClick` is `click`), and the value is a\n * function (called with the element as `this`) or a `[fn, data]` tuple (called as `fn(data, event)`);\n * handlers run batched and untracked. `ref` is called once with the element. `children` is inserted\n * (a getter keeps it reactive). `class` takes a string; `style` a string or an object.\n * @returns The element on the client; its server markup when rendering on the server.\n * @throws TypeError `SHADOW_ELEMENT_TAG` when `tag` is not an allowed tag name.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { element } from \"@shadow-js/web\";\n *\n * function HomeLink() {\n * const [active] = useSignal(true);\n * return element(\"a\", {\n * href: \"/\",\n * get \"aria-current\"() { return active() ? \"page\" : undefined; },\n * onClick: (event: MouseEvent) => console.log(event.type),\n * children: \"Home\",\n * });\n * }\n * @see spread\n * @since 1.0.0\n */\nexport function element(tag: string, props: object): unknown {\n if (!TAG_PATTERN.test(tag) || tag.toLowerCase() === \"script\") {\n throw new TypeError(__DEV__ ? \"ShadowJS element: invalid tag\" : \"SHADOW_ELEMENT_TAG\");\n }\n const read = props as Readonly<Record<string, unknown>>;\n if (__SERVER__) {\n // The children are read after the hydration key is drawn, in the order the client claims them.\n return ssrElement(\n tag,\n props,\n () => {\n const children = read[\"children\"];\n // The content of a style or a title is text the parser reads whole: no markers can go in it.\n if (children === undefined || isTextOnlyElement(tag)) return children;\n return [ssrRaw(\"<!--[-->\"), children, ssrRaw(\"<!--]-->\")];\n },\n true,\n );\n }\n const claimed = claims.current.claimElement(nextKey());\n if (claimed !== null && __DEV__) checkClaimedTag(claimed, tag);\n const el = claimed ?? document.createElement(tag);\n for (const key of Object.keys(props)) {\n if (key === \"children\" || key === \"ref\") continue;\n if (/^on[A-Z]/.test(key)) {\n // Binds one listener, read once. A function runs with the element as `this`; a `[fn, data]` tuple\n // receives `data` first. `null`, `undefined` and `false` bind nothing. Handlers run in a batch and\n // untracked, as the event binding of `Dynamic` runs them.\n const handler = read[key];\n const tuple = Array.isArray(handler);\n // The tuple's data is read once, at bind time, like the handler.\n const [fn, data]: readonly unknown[] = tuple ? handler : [handler];\n if (typeof fn === \"function\") {\n el.addEventListener(key.slice(2).toLowerCase(), (event: Event): void => {\n batch(() => untrack(() => (tuple ? fn.call(el, data, event) : fn.call(el, event))));\n });\n }\n } else if (key === \"style\") {\n // The last value written, so a property that leaves the style object is removed (as spread does).\n let applied: unknown;\n useRenderEffect(\n () => read[key],\n (value) => {\n applied = style(el as HTMLElement, value, applied);\n },\n );\n } else {\n useRenderEffect(\n () => read[key],\n (value) => {\n // The server writes a boolean attribute by truthiness; the client does the same. A name\n // that is a flag has no React spelling, so lower case is its attribute name.\n const name = key.toLowerCase();\n if (isFlagAttribute(name, value)) setBoolAttribute(el, name, value);\n else setAttribute(el, key, value);\n },\n );\n }\n }\n const ref = read[\"ref\"];\n if (typeof ref === \"function\") untrack(() => ref(el));\n insert(el, () => read[\"children\"]);\n return el;\n}\n"],"mappings":"A,wYAsBA,MAAMU,EAAc,qBAsCpB,SAAgBC,EAAQC,EAAaC,EAAwB,CAC3D,GAAI,CAACH,EAAY,KAAKE,CAAG,GAAKA,EAAI,YAAY,IAAM,SAClD,MAAU,UAAsD,oBAAoB,EAEtF,IAAME,EAAOD,EAiBPE,EAFUX,EAAO,QAAQ,aAAaC,EAAQ,CAEnC,GAAK,SAAS,cAAcO,CAAG,EAChD,IAAK,IAAMI,KAAO,OAAO,KAAKH,CAAK,EACjC,GAAIG,IAAQ,YAAcA,IAAQ,MAClC,IAAI,WAAW,KAAKA,CAAG,EAAG,CAIxB,IAAMC,EAAUH,EAAKE,GACfE,EAAQ,MAAM,QAAQD,CAAO,EAE7B,CAACE,EAAIC,GAA4BF,EAAQD,EAAU,CAACA,CAAO,EAC7D,OAAOE,GAAO,YAChBJ,EAAG,iBAAiBC,EAAI,MAAM,CAAC,CAAC,CAAC,YAAY,EAAIK,GAAuB,CACtEd,MAAYC,MAAeU,EAAQC,EAAG,KAAKJ,EAAIK,EAAMC,CAAK,EAAIF,EAAG,KAAKJ,EAAIM,CAAK,CAAE,CAAC,CACpF,CAAC,CAEL,MAAO,GAAIL,IAAQ,QAAS,CAE1B,IAAIM,EACJb,MACQK,EAAKE,GACVO,GAAU,CACTD,EAAUpB,EAAMa,EAAmBQ,EAAOD,CAAO,CACnD,CACF,CACF,MACEb,MACQK,EAAKE,GACVO,GAAU,CAGT,IAAMC,EAAOR,EAAI,YAAY,EACzBV,EAAgBkB,EAAMD,CAAK,EAAGtB,EAAiBc,EAAIS,EAAMD,CAAK,EAC7DvB,EAAae,EAAIC,EAAKO,CAAK,CAClC,CACF,CAAA,CAGJ,IAAME,EAAMX,EAAKY,IAGjB,OAFI,OAAOD,GAAQ,YAAYjB,MAAciB,EAAIV,CAAE,CAAC,EACpDZ,EAAOY,MAAUD,EAAKa,QAAW,EAC1BZ,CACT,C"}
|
package/dist/prod/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","names":["DELEGATED_EVENTS","installed","dispatchDelegated","batch","key","event","dataKey","errors","node","fn","data","untrack","error","first","isListenerObject","handler","listen","listener","run","el","name","options","bindListenerObject","object","capture","chainEvents","handlers","installDelegate","known","target","delegateEvents","names","clearDelegatedEvents","delegationDocument","owner","bindEvent","tuple","slot","delegate","addEventListener","unbind","getOwner","onCleanup"],"sources":["../../src/events.ts"],"sourcesContent":["import { batch, getOwner, onCleanup, untrack } from \"@shadow-js/core\";\n\n/**\n * Events that may be delegated: composed events, which leave a shadow root and reach the document.\n * `change` is not composed, so it is bound on its element (see the note on `bindEvent`).\n */\nconst DELEGATED_EVENTS =\n /^(?:click|dblclick|input|beforeinput|contextmenu|key(?:down|up|press)|(?:pointer|mouse)(?:down|up|move|over|out)|focus(?:in|out)|touch(?:start|end|move))$/;\n\n/** Documents that already carry the delegated listener for a given event name. */\nconst installed = new WeakMap<Document, Set<string>>();\n\n/** A bound handler: called with `this` = the node. */\ntype Handler = (this: EventTarget, ...args: unknown[]) => unknown;\n\n/**\n * The one listener per (document, event). It walks `composedPath()` from the target outward,\n * calling `node.$$<type>` with `this = node` and `currentTarget` retargeted to the node for the\n * duration of the call. Stops when a handler stops propagation.\n */\nfunction dispatchDelegated(event: Event): void {\n // One batch per event: every handler on the path runs first, then the effects, so the DOM is\n // current when the event finishes (ADR-007).\n batch(() => {\n const key = `$$${event.type}`;\n const dataKey = `${key}Data`;\n const errors: unknown[] = [];\n for (const node of event.composedPath()) {\n if (event.cancelBubble) break;\n const fn = Reflect.get(node, key);\n if (typeof fn !== \"function\") continue;\n const data = Reflect.get(node, dataKey);\n try {\n Object.defineProperty(event, \"currentTarget\", { configurable: true, get: () => node });\n untrack(() =>\n (fn as Handler).call(node, ...(data === undefined ? [event] : [data, event])),\n );\n } catch (error) {\n errors.push(error);\n } finally {\n Reflect.deleteProperty(event, \"currentTarget\");\n }\n }\n const [first] = errors;\n if (errors.length === 1) throw first;\n if (errors.length > 1)\n throw new AggregateError(\n errors,\n __DEV__ ? \"Several event handlers threw.\" : \"SHADOW_EVENT_ERRORS\",\n );\n });\n}\n\n/** A DOM-style listener object: `handleEvent` plus the `addEventListener` options. */\ninterface ListenerObject {\n handleEvent(event: Event): unknown;\n once?: boolean;\n passive?: boolean;\n capture?: boolean;\n signal?: AbortSignal;\n}\n\nfunction isListenerObject(handler: unknown): handler is ListenerObject {\n return (\n typeof handler === \"object\" &&\n handler !== null &&\n typeof (handler as { handleEvent?: unknown }).handleEvent === \"function\"\n );\n}\n\n/** Adds a native listener that runs `run` untracked in one batch; returns the function that removes it. */\nfunction listen(\n el: Element,\n name: string,\n run: (event: Event) => unknown,\n options: AddEventListenerOptions | boolean,\n): () => void {\n const listener = (event: Event): void => {\n batch(() => untrack(() => run(event)));\n };\n el.addEventListener(name, listener, options);\n return () => {\n el.removeEventListener(name, listener, options);\n };\n}\n\n/** Binds a listener object natively (never delegated), honoring its options. */\nfunction bindListenerObject(\n el: Element,\n name: string,\n object: ListenerObject,\n capture: boolean,\n): () => void {\n const { once, passive, signal } = object;\n // A member that is `undefined` counts as absent to the DOM, so none of them needs a check.\n return listen(el, name, (event) => object.handleEvent(event), {\n capture: object.capture === true || capture,\n once,\n passive,\n signal,\n } as AddEventListenerOptions);\n}\n\n/**\n * Combines several handlers for one event name on one element into one handler that calls them in\n * order with the same event. The compiler uses it when an element has, for example, both `onInput`\n * and a text input's `onChange`: the delegated slot holds one function.\n *\n * @param handlers The handlers, in source order. None gives a handler that does nothing.\n * @returns A handler that calls each of them with the same `this` and event. An error thrown by one\n * handler propagates and the later handlers do not run.\n * @example\n * import { addEventListener, chainEvents } from \"@shadow-js/web\";\n *\n * const input = document.createElement(\"input\");\n * const onInput = chainEvents(\n * (event) => console.log(\"validate\", event.type),\n * (event) => console.log(\"save\", event.type),\n * );\n * addEventListener(input, \"input\", onInput);\n * @since 1.0.0\n */\nexport function chainEvents(\n ...handlers: Array<(this: EventTarget, event: Event) => unknown>\n): (this: EventTarget, event: Event) => void {\n return function chained(this: EventTarget, event: Event): void {\n for (const handler of handlers) handler.call(this, event);\n };\n}\n\n/** Installs the delegated listener for one event name on `target`, unless it is there already. */\nfunction installDelegate(name: string, target: Document): void {\n let known = installed.get(target);\n if (known === undefined) {\n known = new Set<string>();\n installed.set(target, known);\n }\n if (known.has(name)) return;\n known.add(name);\n target.addEventListener(name, dispatchDelegated);\n}\n\n/**\n * Installs the document listener that runs delegated handlers for each event name, once per\n * document and name; repeated calls do nothing. Compiled modules call it for the events they\n * delegate, so application code rarely needs it. The listener walks `composedPath()` from the target\n * outward and runs each element's delegated handler in one batch, stopping when a handler stops\n * propagation. A non-composed event raised inside a shadow root never reaches the document, so bind\n * such events natively.\n *\n * @param names Event names to delegate, such as `[\"click\", \"input\"]`.\n * @param target Document that receives the listeners. Default: the global `document`.\n * @example\n * import { delegateEvents } from \"@shadow-js/web\";\n *\n * delegateEvents([\"click\", \"input\"]);\n * @see clearDelegatedEvents\n * @since 1.0.0\n */\nexport function delegateEvents(names: string[], target: Document = globalThis.document): void {\n for (const name of names) installDelegate(name, target);\n}\n\n/**\n * Removes the delegated listeners {@link delegateEvents} installed on `target`. Delegated handlers stop\n * running until `delegateEvents` is called again (Solid's `clearDelegatedEvents`). Use it when a page\n * unmounts ShadowJS entirely, for example a micro-frontend that hands the document back. A document\n * without delegated listeners is left as is.\n *\n * @param target Document whose listeners are removed. Default: the global `document`.\n * @example\n * import { clearDelegatedEvents } from \"@shadow-js/web\";\n *\n * export function unmountApp(dispose: () => void): void {\n * dispose();\n * clearDelegatedEvents();\n * }\n * @see delegateEvents\n * @since 1.0.0\n */\nexport function clearDelegatedEvents(target: Document = globalThis.document): void {\n const known = installed.get(target);\n if (known === undefined) return;\n for (const name of known) target.removeEventListener(name, dispatchDelegated);\n installed.delete(target);\n}\n\n/**\n * The document that must carry the delegated listener for `el`. A template clone is owned by the\n * template's inert document (no window, never receives an event) until it is inserted, and handlers\n * are bound before that: use the page's document then, which is where the element will live.\n */\nfunction delegationDocument(el: Element): Document {\n const owner = el.ownerDocument;\n return owner !== null && owner.defaultView !== null ? owner : globalThis.document;\n}\n\n/**\n * Binds one handler and returns the function that undoes it. A delegated event is stored on the\n * element as an expando; the document listener picks it up. Other events get a native listener.\n * Non-composed events (`change`, `select`, `load`, ...) never leave a shadow root, so they always get\n * a native listener, whatever the caller asked for.\n * @internal\n */\nexport function bindEvent(\n el: Element,\n name: string,\n handler: unknown,\n delegate: boolean,\n capture = false,\n): (() => void) | undefined {\n if (handler === null || handler === undefined || handler === false) return undefined;\n if (isListenerObject(handler)) return bindListenerObject(el, name, handler, capture);\n let fn = handler as Handler;\n let data: unknown;\n let tuple = false;\n if (Array.isArray(handler) && typeof handler[0] === \"function\") {\n fn = handler[0] as Handler;\n data = handler[1];\n tuple = true;\n } else if (typeof handler !== \"function\") {\n throw new TypeError(\n __DEV__\n ? \"addEventListener(): the handler must be a function, [function, data] or an object with handleEvent.\"\n : \"SHADOW_EVENT_HANDLER\",\n );\n }\n // One delegated slot per event name: a second handler for the same name on this element (React's\n // onInput and onChange on one text input) binds natively, so both run.\n const slot = `$$${name}`;\n // The delegated slot tells a tuple from a plain handler by its data being defined, so a tuple whose\n // data is undefined is bound natively, where it still receives `(undefined, event)`.\n if (\n delegate &&\n (!tuple || data !== undefined) &&\n !capture &&\n DELEGATED_EVENTS.test(name) &&\n Reflect.get(el, slot) === undefined\n ) {\n installDelegate(name, delegationDocument(el));\n const dataKey = `${slot}Data`;\n Reflect.set(el, slot, fn);\n if (tuple) Reflect.set(el, dataKey, data);\n else Reflect.deleteProperty(el, dataKey);\n return () => {\n if (Reflect.get(el, slot) === fn) {\n Reflect.deleteProperty(el, slot);\n Reflect.deleteProperty(el, dataKey);\n }\n };\n }\n return listen(el, name, (event) => fn.call(el, ...(tuple ? [data, event] : [event])), capture);\n}\n\n/**\n * Binds an event handler to an element: the helper compiled templates call for `onX` and the `on:`\n * and `oncapture:` prefixes. Handlers run batched and untracked, with `this` set to the element.\n * Inside an owner, the listener is removed when the owner is disposed, even if the element outlives\n * it.\n *\n * @param el Target element.\n * @param name Event name, lowercase, such as `click`.\n * @param handler A function (called with the event), a `[fn, data]` tuple (called as\n * `fn(data, event)`), or a listener object `{ handleEvent, once, passive, capture, signal }`, which\n * is always bound natively with those options. `null`, `undefined` and `false` bind nothing.\n * @param delegate `true` stores the handler on the element for the document listener of\n * {@link delegateEvents} (installed on demand) when `name` is a delegated event (`click`, `input`,\n * `keydown`, pointer, mouse, touch and focus events, ...) and the element has no delegated handler\n * for it yet. Otherwise, and when undefined, the handler gets a native listener.\n * @param capture `true` listens in the capture phase, never delegated. Undefined means the bubble phase.\n * @throws TypeError `SHADOW_EVENT_HANDLER` when `handler` is not a function, a tuple whose first item\n * is a function, or a listener object.\n * @example\n * import { addEventListener } from \"@shadow-js/web\";\n *\n * const button = document.createElement(\"button\");\n * addEventListener(button, \"click\", () => console.log(\"pressed\"), true);\n * addEventListener(button, \"focus\", [(id: string, event: Event) => console.log(id, event.type), \"save\"]);\n * @see delegateEvents\n * @since 1.0.0\n */\nexport function addEventListener(\n el: Element,\n name: string,\n handler: unknown,\n delegate?: boolean,\n capture?: boolean,\n): void {\n const unbind = bindEvent(el, name, handler, delegate === true, capture === true);\n // The listener goes when the owner does, even if the element outlives it (moved, portaled, reused).\n if (unbind !== undefined && getOwner() !== null) onCleanup(unbind);\n}\n"],"mappings":"A,kFAMA,MAAMA,EACJ,6JAGIC,kBAAY,IAAI,QAUtB,SAASC,EAAkB,EAAoB,CAG7CC,MAAY,CACV,IAAMC,EAAM,KAAKC,EAAM,OACjBC,EAAU,GAAGF,EAAI,MACjBG,EAAoB,CAAC,EAC3B,IAAK,IAAMC,KAAQH,EAAM,aAAa,EAAG,CACvC,GAAIA,EAAM,aAAc,MACxB,IAAMI,EAAK,QAAQ,IAAID,EAAMJ,CAAG,EAChC,GAAI,OAAOK,GAAO,WAAY,SAC9B,IAAMC,EAAO,QAAQ,IAAIF,EAAMF,CAAO,EACtC,GAAI,CACF,OAAO,eAAeD,EAAO,gBAAiB,CAAE,aAAc,GAAM,QAAWG,CAAK,CAAC,EACrFG,MACGF,EAAe,KAAKD,EAAM,GAAIE,IAAS,IAAA,GAAY,CAACL,CAAK,EAAI,CAACK,EAAML,CAAK,CAAE,CAC9E,CACF,OAASO,EAAO,CACdL,EAAO,KAAKK,CAAK,CACnB,QAAU,CACR,QAAQ,eAAeP,EAAO,eAAe,CAC/C,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,CAAC1B,EAAML,CAAK,EAAI,CAACA,CAAK,CAAE,EAAGmB,CAAO,CAC/F,CA6BA,SAAgBe,EACd,EACA,EACA,EACA,EACA,EACM,CACN,IAAMC,EAASL,EAAUhB,EAAIC,EAAML,EAASuB,IAAa,GAAMd,IAAY,EAAI,EAE3EgB,IAAW,IAAA,IAAaC,EAAS,IAAM,MAAMC,EAAUF,CAAM,CACnE,C"}
|
|
1
|
+
{"version":3,"file":"events.js","names":["batch","getOwner","onCleanup","untrack","DELEGATED_EVENTS","installed","dispatchDelegated","event","key","dataKey","errors","node","fn","data","error","first","isListenerObject","handler","listen","el","name","run","options","listener","bindListenerObject","object","capture","once","passive","signal","chainEvents","handlers","installDelegate","target","known","delegateEvents","names","clearDelegatedEvents","delegationDocument","owner","bindEvent","delegate","tuple","slot","addEventListener","unbind"],"sources":["../../src/events.ts"],"sourcesContent":["import { batch, getOwner, onCleanup, untrack } from \"@shadow-js/core\";\n\n/**\n * Events that may be delegated: composed events, which leave a shadow root and reach the document.\n * `change` is not composed, so it is bound on its element (see the note on `bindEvent`).\n */\nconst DELEGATED_EVENTS =\n /^(?:click|dblclick|input|beforeinput|contextmenu|key(?:down|up|press)|(?:pointer|mouse)(?:down|up|move|over|out)|focus(?:in|out)|touch(?:start|end|move))$/;\n\n/** Documents that already carry the delegated listener for a given event name. */\nconst installed = new WeakMap<Document, Set<string>>();\n\n/** A bound handler: called with `this` = the node. */\ntype Handler = (this: EventTarget, ...args: unknown[]) => unknown;\n\n/**\n * The one listener per (document, event). It walks `composedPath()` from the target outward,\n * calling `node.$$<type>` with `this = node` and `currentTarget` retargeted to the node for the\n * duration of the call. Stops when a handler stops propagation.\n */\nfunction dispatchDelegated(event: Event): void {\n // One batch per event: every handler on the path runs first, then the effects, so the DOM is\n // current when the event finishes (ADR-007).\n batch(() => {\n const key = `$$${event.type}`;\n const dataKey = `${key}Data`;\n const errors: unknown[] = [];\n for (const node of event.composedPath()) {\n if (event.cancelBubble) break;\n const fn = Reflect.get(node, key);\n if (typeof fn !== \"function\") continue;\n const data = Reflect.get(node, dataKey);\n try {\n Object.defineProperty(event, \"currentTarget\", { configurable: true, get: () => node });\n untrack(() =>\n (fn as Handler).call(node, ...(data === undefined ? [event] : [data, event])),\n );\n } catch (error) {\n errors.push(error);\n } finally {\n Reflect.deleteProperty(event, \"currentTarget\");\n }\n }\n const [first] = errors;\n if (errors.length === 1) throw first;\n if (errors.length > 1)\n throw new AggregateError(\n errors,\n __DEV__ ? \"Several event handlers threw.\" : \"SHADOW_EVENT_ERRORS\",\n );\n });\n}\n\n/** A DOM-style listener object: `handleEvent` plus the `addEventListener` options. */\ninterface ListenerObject {\n handleEvent(event: Event): unknown;\n once?: boolean;\n passive?: boolean;\n capture?: boolean;\n signal?: AbortSignal;\n}\n\nfunction isListenerObject(handler: unknown): handler is ListenerObject {\n return (\n typeof handler === \"object\" &&\n handler !== null &&\n typeof (handler as { handleEvent?: unknown }).handleEvent === \"function\"\n );\n}\n\n/** Adds a native listener that runs `run` untracked in one batch; returns the function that removes it. */\nfunction listen(\n el: Element,\n name: string,\n run: (event: Event) => unknown,\n options: AddEventListenerOptions | boolean,\n): () => void {\n const listener = (event: Event): void => {\n batch(() => untrack(() => run(event)));\n };\n el.addEventListener(name, listener, options);\n return () => {\n el.removeEventListener(name, listener, options);\n };\n}\n\n/** Binds a listener object natively (never delegated), honoring its options. */\nfunction bindListenerObject(\n el: Element,\n name: string,\n object: ListenerObject,\n capture: boolean,\n): () => void {\n const { once, passive, signal } = object;\n // A member that is `undefined` counts as absent to the DOM, so none of them needs a check.\n return listen(el, name, (event) => object.handleEvent(event), {\n capture: object.capture === true || capture,\n once,\n passive,\n signal,\n } as AddEventListenerOptions);\n}\n\n/**\n * Combines several handlers for one event name on one element into one handler that calls them in\n * order with the same event. The compiler uses it when an element has, for example, both `onInput`\n * and a text input's `onChange`: the delegated slot holds one function.\n *\n * @param handlers The handlers, in source order. None gives a handler that does nothing.\n * @returns A handler that calls each of them with the same `this` and event. An error thrown by one\n * handler propagates and the later handlers do not run.\n * @example\n * import { addEventListener, chainEvents } from \"@shadow-js/web\";\n *\n * const input = document.createElement(\"input\");\n * const onInput = chainEvents(\n * (event) => console.log(\"validate\", event.type),\n * (event) => console.log(\"save\", event.type),\n * );\n * addEventListener(input, \"input\", onInput);\n * @since 1.0.0\n */\nexport function chainEvents(\n ...handlers: Array<(this: EventTarget, event: Event) => unknown>\n): (this: EventTarget, event: Event) => void {\n return function chained(this: EventTarget, event: Event): void {\n for (const handler of handlers) handler.call(this, event);\n };\n}\n\n/** Installs the delegated listener for one event name on `target`, unless it is there already. */\nfunction installDelegate(name: string, target: Document): void {\n let known = installed.get(target);\n if (known === undefined) {\n known = new Set<string>();\n installed.set(target, known);\n }\n if (known.has(name)) return;\n known.add(name);\n target.addEventListener(name, dispatchDelegated);\n}\n\n/**\n * Installs the document listener that runs delegated handlers for each event name, once per\n * document and name; repeated calls do nothing. Compiled modules call it for the events they\n * delegate, so application code rarely needs it. The listener walks `composedPath()` from the target\n * outward and runs each element's delegated handler in one batch, stopping when a handler stops\n * propagation. A non-composed event raised inside a shadow root never reaches the document, so bind\n * such events natively.\n *\n * @param names Event names to delegate, such as `[\"click\", \"input\"]`.\n * @param target Document that receives the listeners. Default: the global `document`.\n * @example\n * import { delegateEvents } from \"@shadow-js/web\";\n *\n * delegateEvents([\"click\", \"input\"]);\n * @see clearDelegatedEvents\n * @since 1.0.0\n */\nexport function delegateEvents(names: string[], target: Document = globalThis.document): void {\n for (const name of names) installDelegate(name, target);\n}\n\n/**\n * Removes the delegated listeners {@link delegateEvents} installed on `target`. Delegated handlers stop\n * running until `delegateEvents` is called again (Solid's `clearDelegatedEvents`). Use it when a page\n * unmounts ShadowJS entirely, for example a micro-frontend that hands the document back. A document\n * without delegated listeners is left as is.\n *\n * @param target Document whose listeners are removed. Default: the global `document`.\n * @example\n * import { clearDelegatedEvents } from \"@shadow-js/web\";\n *\n * export function unmountApp(dispose: () => void): void {\n * dispose();\n * clearDelegatedEvents();\n * }\n * @see delegateEvents\n * @since 1.0.0\n */\nexport function clearDelegatedEvents(target: Document = globalThis.document): void {\n const known = installed.get(target);\n if (known === undefined) return;\n for (const name of known) target.removeEventListener(name, dispatchDelegated);\n installed.delete(target);\n}\n\n/**\n * The document that must carry the delegated listener for `el`. A template clone is owned by the\n * template's inert document (no window, never receives an event) until it is inserted, and handlers\n * are bound before that: use the page's document then, which is where the element will live.\n */\nfunction delegationDocument(el: Element): Document {\n const owner = el.ownerDocument;\n return owner !== null && owner.defaultView !== null ? owner : globalThis.document;\n}\n\n/**\n * Binds one handler and returns the function that undoes it. A delegated event is stored on the\n * element as an expando; the document listener picks it up. Other events get a native listener.\n * Non-composed events (`change`, `select`, `load`, ...) never leave a shadow root, so they always get\n * a native listener, whatever the caller asked for.\n * @internal\n */\nexport function bindEvent(\n el: Element,\n name: string,\n handler: unknown,\n delegate: boolean,\n capture = false,\n): (() => void) | undefined {\n if (handler === null || handler === undefined || handler === false) return undefined;\n if (isListenerObject(handler)) return bindListenerObject(el, name, handler, capture);\n let fn = handler as Handler;\n let data: unknown;\n let tuple = false;\n if (Array.isArray(handler) && typeof handler[0] === \"function\") {\n fn = handler[0] as Handler;\n data = handler[1];\n tuple = true;\n } else if (typeof handler !== \"function\") {\n throw new TypeError(\n __DEV__\n ? \"addEventListener(): the handler must be a function, [function, data] or an object with handleEvent.\"\n : \"SHADOW_EVENT_HANDLER\",\n );\n }\n // One delegated slot per event name: a second handler for the same name on this element (React's\n // onInput and onChange on one text input) binds natively, so both run.\n const slot = `$$${name}`;\n // The delegated slot tells a tuple from a plain handler by its data being defined, so a tuple whose\n // data is undefined is bound natively, where it still receives `(undefined, event)`.\n if (\n delegate &&\n (!tuple || data !== undefined) &&\n !capture &&\n DELEGATED_EVENTS.test(name) &&\n Reflect.get(el, slot) === undefined\n ) {\n installDelegate(name, delegationDocument(el));\n const dataKey = `${slot}Data`;\n Reflect.set(el, slot, fn);\n if (tuple) Reflect.set(el, dataKey, data);\n else Reflect.deleteProperty(el, dataKey);\n return () => {\n if (Reflect.get(el, slot) === fn) {\n Reflect.deleteProperty(el, slot);\n Reflect.deleteProperty(el, dataKey);\n }\n };\n }\n return listen(el, name, (event) => fn.call(el, ...(tuple ? [data, event] : [event])), capture);\n}\n\n/**\n * Binds an event handler to an element: the helper compiled templates call for `onX` and the `on:`\n * and `oncapture:` prefixes. Handlers run batched and untracked, with `this` set to the element.\n * Inside an owner, the listener is removed when the owner is disposed, even if the element outlives\n * it.\n *\n * @param el Target element.\n * @param name Event name, lowercase, such as `click`.\n * @param handler A function (called with the event), a `[fn, data]` tuple (called as\n * `fn(data, event)`), or a listener object `{ handleEvent, once, passive, capture, signal }`, which\n * is always bound natively with those options. `null`, `undefined` and `false` bind nothing.\n * @param delegate `true` stores the handler on the element for the document listener of\n * {@link delegateEvents} (installed on demand) when `name` is a delegated event (`click`, `input`,\n * `keydown`, pointer, mouse, touch and focus events, ...) and the element has no delegated handler\n * for it yet. Otherwise, and when undefined, the handler gets a native listener.\n * @param capture `true` listens in the capture phase, never delegated. Undefined means the bubble phase.\n * @throws TypeError `SHADOW_EVENT_HANDLER` when `handler` is not a function, a tuple whose first item\n * is a function, or a listener object.\n * @example\n * import { addEventListener } from \"@shadow-js/web\";\n *\n * const button = document.createElement(\"button\");\n * addEventListener(button, \"click\", () => console.log(\"pressed\"), true);\n * addEventListener(button, \"focus\", [(id: string, event: Event) => console.log(id, event.type), \"save\"]);\n * @see delegateEvents\n * @since 1.0.0\n */\nexport function addEventListener(\n el: Element,\n name: string,\n handler: unknown,\n delegate?: boolean,\n capture?: boolean,\n): void {\n const unbind = bindEvent(el, name, handler, delegate === true, capture === true);\n // The listener goes when the owner does, even if the element outlives it (moved, portaled, reused).\n if (unbind !== undefined && getOwner() !== null) onCleanup(unbind);\n}\n"],"mappings":"A,kFAMA,MAAMI,EACJ,6JAGIC,kBAAY,IAAI,QAUtB,SAASC,EAAkBC,EAAoB,CAG7CP,MAAY,CACV,IAA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AGJ,sBACN,EAIF,IAAM0B,EAAO,KAAKvB,IAGlB,GACEqB,IACC,CAACC,GAAS7B,IAAS,IAAA,KACpB,CAACa,GACDtB,EAAiB,KAAKgB,CAAI,GAC1B,QAAQ,IAAID,EAAIwB,CAAI,IAAM,IAAA,GAC1B,CACAX,EAAgBZ,EAAMkB,EAAmBnB,CAAE,CAAC,EAC5C,IAAMV,EAAU,GAAGkC,EAAK,MAIxB,OAHA,QAAQ,IAAIxB,EAAIwB,EAAM/B,CAAE,EACpB8B,EAAO,QAAQ,IAAIvB,EAAIV,EAASI,CAAI,EACnC,QAAQ,eAAeM,EAAIV,CAAO,MAC1B,CACP,QAAQ,IAAIU,EAAIwB,CAAI,IAAM/B,IAC5B,QAAQ,eAAeO,EAAIwB,CAAI,EAC/B,QAAQ,eAAexB,EAAIV,CAAO,EAEtC,CACF,CACA,OAAOS,EAAOC,EAAIC,EAAOb,GAAUK,EAAG,KAAKO,EAAI,GAAIuB,EAAQ,CAAC7B,EAAMN,CAAK,EAAI,CAACA,CAAK,CAAE,EAAGmB,CAAO,CAC/F,CA6BA,SAAgBkB,EACdzB,EACAC,EACAH,EACAwB,EACAf,EACM,CACN,IAAMmB,EAASL,EAAUrB,EAAIC,EAAMH,EAASwB,IAAa,GAAMf,IAAY,EAAI,EAE3EmB,IAAW,IAAA,IAAa5C,EAAS,IAAM,MAAMC,EAAU2C,CAAM,CACnE,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","names":["partText","value","textOf","resolved","keyOf","attributeValue","attributesOf","entries","key","props","skip","attributeTag","Title","useHead","Meta","Link","Style","attributes","text","Base"],"sources":["../../../src/head/components.ts"],"sourcesContent":["import { useHead } from \"./use-head\";\nimport type { HeadAttributeValue, HeadTag, HeadTagName } from \"./validate\";\n\n/**\n * Props of {@link Title}.\n * @since 1.0.0\n */\nexport interface TitleProps {\n /**\n * The title text: a string, a number, an array of those, or an accessor returning them. `null`,\n * `undefined` and `false` count as empty text; anything else throws a TypeError.\n * @default undefined (the title is the empty string)\n */\n readonly children?: unknown;\n}\n\n/**\n * Props of {@link Meta}, {@link Link} and {@link Base}: every prop is an attribute, and a function\n * value is read reactively.\n * @since 1.0.0\n */\nexport interface HeadAttributeProps {\n /**\n * One attribute of the tag. A string or number is written as text, `true` as an empty attribute,\n * and `false`, `null` or `undefined` omit it. Any other value throws a TypeError.\n */\n readonly [attribute: string]: unknown;\n}\n\n/**\n * Props of {@link Style}: the CSS text and an optional key that replaces an earlier style with the\n * same key.\n * @since 1.0.0\n */\nexport interface StyleProps {\n /**\n * The CSS text: a string, a number, an array of those, or an accessor returning them.\n * @default undefined (the style has no text)\n */\n readonly children?: unknown;\n /**\n * Identity of the style: a later style with the same key replaces an earlier one. Must be a\n * non-empty string.\n * @default undefined (the style has no identity and always stays)\n */\n readonly key?: unknown;\n /** One attribute of the `<style>` element, such as `media`, with the same rules as {@link HeadAttributeProps}. */\n readonly [attribute: string]: unknown;\n}\n\n/** Text of a value that may be an accessor. Anything but text or an array of text throws. */\nfunction partText(value: unknown): string {\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\") return String(value);\n if (value === undefined || value === null || value === false) return \"\";\n throw new TypeError(\n __DEV__ ? \"ShadowJS head: Title children must be text.\" : \"SHADOW_HEAD_TITLE_TEXT\",\n );\n}\n\n/** The text a Title shows. An accessor is called once, so its reads are tracked by the caller. */\nfunction textOf(value: unknown): string {\n const resolved = typeof value === \"function\" ? (value as () => unknown)() : value;\n if (Array.isArray(resolved)) return (resolved as unknown[]).map(partText).join(\"\");\n return partText(resolved);\n}\n\n/** The style key of a prop: absent stays absent, a non-empty string is kept, anything else throws. */\nfunction keyOf(value: unknown): string | undefined {\n if (value === undefined || value === null) return undefined;\n if (typeof value === \"string\" && value !== \"\") return value;\n throw new TypeError(\n __DEV__ ? \"ShadowJS head: a key must be a non-empty string.\" : \"SHADOW_HEAD_KEY\",\n );\n}\n\n/** One attribute value from a prop: strings, numbers and booleans are kept, the rest is an error. */\nfunction attributeValue(value: unknown): HeadAttributeValue {\n if (value === undefined || value === null || value === false) return undefined;\n if (value === true) return true;\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\") return value;\n throw new TypeError(\n __DEV__\n ? \"ShadowJS head: attribute values must be strings, numbers or booleans.\"\n : \"SHADOW_HEAD_ATTRIBUTE_VALUE\",\n );\n}\n\n/**\n * The attributes of a component's props, reading each prop (so a getter is tracked by the\n * caller). `skip` lists props that are not attributes.\n */\nfunction attributesOf(props: object, skip: readonly string[]): Record<string, HeadAttributeValue> {\n const entries: Array<[string, HeadAttributeValue]> = [];\n for (const key of Object.keys(props)) {\n if (skip.includes(key)) continue;\n entries.push([key, attributeValue(Reflect.get(props, key))]);\n }\n return Object.fromEntries(entries);\n}\n\n/** A tag with attributes and no text, of the given name. */\nfunction attributeTag(tag: HeadTagName, props: object, skip: readonly string[]): HeadTag {\n return { tag, props: attributesOf(props, skip) };\n}\n\n/**\n * Sets the document title. The last registered Title wins; removing it restores the one below, or\n * the original title when none is left.\n *\n * @param props The title text.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_TITLE_TEXT`) when the children are not text.\n * @example\n * import { Title } from \"@shadow-js/web\";\n *\n * function Home() {\n * return <Title>Home | Blog</Title>;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Title(props: TitleProps): null {\n useHead((): HeadTag => ({ tag: \"title\", children: textOf(props.children) }));\n return null;\n}\n\n/**\n * Registers a `<meta>`. Identity follows name, property, http-equiv or charset, so the last\n * description wins. Children are ignored: a meta carries no text.\n *\n * @param props Attributes, such as `name` and `content`.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_ATTRIBUTE_VALUE`) for an attribute value that\n * is not a string, number or boolean, and for an invalid attribute name or an event attribute\n * (see {@link normalizeTags}).\n * @example\n * import { Meta } from \"@shadow-js/web\";\n *\n * function About() {\n * return <Meta name=\"description\" content=\"About us\" />;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Meta(props: HeadAttributeProps): null {\n useHead(() => attributeTag(\"meta\", props, [\"children\"]));\n return null;\n}\n\n/**\n * Registers a `<link>`. Icons are keyed by rel, sizes and type; preloads and stylesheets by rel,\n * href and as; other links are append-only.\n *\n * @param props Attributes, such as `rel` and `href`.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_ATTRIBUTE_VALUE`) for an attribute value that\n * is not a string, number or boolean, and for an invalid attribute name or an event attribute\n * (see {@link normalizeTags}).\n * @example\n * import { Link } from \"@shadow-js/web\";\n *\n * function Page() {\n * return <Link rel=\"stylesheet\" href=\"/site.css\" />;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Link(props: HeadAttributeProps): null {\n useHead(() => attributeTag(\"link\", props, [\"children\"]));\n return null;\n}\n\n/**\n * Registers a `<style>` with the given CSS text. A `key` makes it replace an earlier style with the\n * same key; without one, every style stays.\n *\n * @param props The CSS as `children`, an optional `key`, and attributes such as `media`.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_KEY`) when `key` is not a non-empty string.\n * @example\n * import { Style } from \"@shadow-js/web\";\n *\n * function Theme() {\n * return <Style key=\"theme\">{\"body { margin: 0 }\"}</Style>;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Style(props: StyleProps): null {\n useHead((): HeadTag => {\n const attributes = attributesOf(props, [\"children\", \"key\"]);\n const text = props.children === undefined ? undefined : textOf(props.children);\n const key = keyOf(props.key);\n return {\n tag: \"style\",\n props: attributes,\n ...(text === undefined ? {} : { children: text }),\n ...(key === undefined ? {} : { key }),\n };\n });\n return null;\n}\n\n/**\n * Registers the document `<base>`. There is one; the last registration wins. Base is placed first\n * in the head, as browsers expect.\n *\n * @param props Attributes, such as `href`.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_ATTRIBUTE_VALUE`) for an attribute value that\n * is not a string, number or boolean.\n * @example\n * import { Base } from \"@shadow-js/web\";\n *\n * function Shell() {\n * return <Base href=\"/app/\" />;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Base(props: HeadAttributeProps): null {\n useHead(() => attributeTag(\"base\", props, [\"children\"]));\n return null;\n}\n"],"mappings":"A,wCAmDA,SAASA,EAAS,EAAwB,CACxC,GAAI,OAAOC,GAAU,SAAU,OAAOA,EACtC,GAAI,OAAOA,GAAU,SAAU,OAAO,OAAOA,CAAK,EAClD,GAAIA,GAAiC,MAAQA,IAAU,GAAO,MAAO,GACrE,MAAU,UACkD,wBAC5D,CACF,CAGA,SAASC,EAAO,EAAwB,CACtC,IAAMC,EAAW,OAAOF,GAAU,WAAcA,EAAwB,EAAIA,EAE5E,OADI,MAAM,QAAQE,CAAQ,EAAWA,EAAuB,IAAIH,CAAQ,CAAC,CAAC,KAAK,EAAE,EAC1EA,EAASG,CAAQ,CAC1B,CAGA,SAASC,EAAM,EAAoC,CACjD,GAAIH,GAAiC,KACrC,IAAI,OAAOA,GAAU,UAAYA,IAAU,GAAI,OAAOA,EACtD,MAAU,UACuD,iBACjE,CAHsD,CAIxD,CAGA,SAASI,EAAe,EAAoC,CAC1D,GAAIJ,GAAiC,MAAQA,IAAU,GACvD,IAAIA,IAAU,GAAM,MAAO,GAE3B,GADI,OAAOA,GAAU,UACjB,OAAOA,GAAU,SAAU,OAAOA,EACtC,MAAU,UAGJ,6BACN,CAP2B,CAQ7B,CAMA,SAASK,EAAa,EAAe,EAA6D,CAChG,IAAMC,EAA+C,CAAC,EACtD,IAAK,IAAMC,KAAO,OAAO,KAAKC,CAAK,EAC7BC,EAAK,SAASF,CAAG,GACrBD,EAAQ,KAAK,CAACC,EAAKH,EAAe,QAAQ,IAAII,EAAOD,CAAG,CAAC,CAAC,CAAC,EAE7D,OAAO,OAAO,YAAYD,CAAO,CACnC,CAGA,SAASI,EAAa,EAAkB,EAAe,EAAkC,CACvF,MAAO,CAAE,MAAK,MAAOL,EAAaG,EAAOC,CAAI,CAAE,CACjD,CAkBA,SAAgBE,EAAM,EAAyB,CAE7C,OADAC,OAAwB,CAAE,IAAK,QAAS,SAAUX,EAAOO,EAAM,QAAQ,CAAE,EAAE,EACpE,IACT,CAoBA,SAAgBK,EAAK,EAAiC,CAEpD,OADAD,MAAcF,EAAa,OAAQF,EAAO,CAAC,UAAU,CAAC,CAAC,EAChD,IACT,CAoBA,SAAgBM,EAAK,EAAiC,CAEpD,OADAF,MAAcF,EAAa,OAAQF,EAAO,CAAC,UAAU,CAAC,CAAC,EAChD,IACT,CAkBA,SAAgBO,EAAM,EAAyB,CAY7C,OAXAH,MAAuB,CACrB,IAAMI,EAAaX,EAAaG,EAAO,CAAC,WAAY,KAAK,CAAC,EACpDS,EAAOT,EAAM,WAAa,IAAA,GAAY,IAAA,GAAYP,EAAOO,EAAM,QAAQ,EACvED,EAAMJ,EAAMK,EAAM,GAAG,EAC3B,MAAO,CACL,IAAK,QACL,MAAOQ,EACP,GAAIC,IAAS,IAAA,GAAY,CAAC,EAAI,CAAE,SAAUA,CAAK,EAC/C,GAAIV,IAAQ,IAAA,GAAY,CAAC,EAAI,CAAE,KAAI,CACrC,CACF,CAAC,EACM,IACT,CAmBA,SAAgBW,EAAK,EAAiC,CAEpD,OADAN,MAAcF,EAAa,OAAQF,EAAO,CAAC,UAAU,CAAC,CAAC,EAChD,IACT,C"}
|
|
1
|
+
{"version":3,"file":"components.js","names":["useHead","partText","value","textOf","resolved","keyOf","attributeValue","attributesOf","props","skip","entries","key","attributeTag","tag","Title","Meta","Link","Style","attributes","text","Base"],"sources":["../../../src/head/components.ts"],"sourcesContent":["import { useHead } from \"./use-head\";\nimport type { HeadAttributeValue, HeadTag, HeadTagName } from \"./validate\";\n\n/**\n * Props of {@link Title}.\n * @since 1.0.0\n */\nexport interface TitleProps {\n /**\n * The title text: a string, a number, an array of those, or an accessor returning them. `null`,\n * `undefined` and `false` count as empty text; anything else throws a TypeError.\n * @default undefined (the title is the empty string)\n */\n readonly children?: unknown;\n}\n\n/**\n * Props of {@link Meta}, {@link Link} and {@link Base}: every prop is an attribute, and a function\n * value is read reactively.\n * @since 1.0.0\n */\nexport interface HeadAttributeProps {\n /**\n * One attribute of the tag. A string or number is written as text, `true` as an empty attribute,\n * and `false`, `null` or `undefined` omit it. Any other value throws a TypeError.\n */\n readonly [attribute: string]: unknown;\n}\n\n/**\n * Props of {@link Style}: the CSS text and an optional key that replaces an earlier style with the\n * same key.\n * @since 1.0.0\n */\nexport interface StyleProps {\n /**\n * The CSS text: a string, a number, an array of those, or an accessor returning them.\n * @default undefined (the style has no text)\n */\n readonly children?: unknown;\n /**\n * Identity of the style: a later style with the same key replaces an earlier one. Must be a\n * non-empty string.\n * @default undefined (the style has no identity and always stays)\n */\n readonly key?: unknown;\n /** One attribute of the `<style>` element, such as `media`, with the same rules as {@link HeadAttributeProps}. */\n readonly [attribute: string]: unknown;\n}\n\n/** Text of a value that may be an accessor. Anything but text or an array of text throws. */\nfunction partText(value: unknown): string {\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\") return String(value);\n if (value === undefined || value === null || value === false) return \"\";\n throw new TypeError(\n __DEV__ ? \"ShadowJS head: Title children must be text.\" : \"SHADOW_HEAD_TITLE_TEXT\",\n );\n}\n\n/** The text a Title shows. An accessor is called once, so its reads are tracked by the caller. */\nfunction textOf(value: unknown): string {\n const resolved = typeof value === \"function\" ? (value as () => unknown)() : value;\n if (Array.isArray(resolved)) return (resolved as unknown[]).map(partText).join(\"\");\n return partText(resolved);\n}\n\n/** The style key of a prop: absent stays absent, a non-empty string is kept, anything else throws. */\nfunction keyOf(value: unknown): string | undefined {\n if (value === undefined || value === null) return undefined;\n if (typeof value === \"string\" && value !== \"\") return value;\n throw new TypeError(\n __DEV__ ? \"ShadowJS head: a key must be a non-empty string.\" : \"SHADOW_HEAD_KEY\",\n );\n}\n\n/** One attribute value from a prop: strings, numbers and booleans are kept, the rest is an error. */\nfunction attributeValue(value: unknown): HeadAttributeValue {\n if (value === undefined || value === null || value === false) return undefined;\n if (value === true) return true;\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\") return value;\n throw new TypeError(\n __DEV__\n ? \"ShadowJS head: attribute values must be strings, numbers or booleans.\"\n : \"SHADOW_HEAD_ATTRIBUTE_VALUE\",\n );\n}\n\n/**\n * The attributes of a component's props, reading each prop (so a getter is tracked by the\n * caller). `skip` lists props that are not attributes.\n */\nfunction attributesOf(props: object, skip: readonly string[]): Record<string, HeadAttributeValue> {\n const entries: Array<[string, HeadAttributeValue]> = [];\n for (const key of Object.keys(props)) {\n if (skip.includes(key)) continue;\n entries.push([key, attributeValue(Reflect.get(props, key))]);\n }\n return Object.fromEntries(entries);\n}\n\n/** A tag with attributes and no text, of the given name. */\nfunction attributeTag(tag: HeadTagName, props: object, skip: readonly string[]): HeadTag {\n return { tag, props: attributesOf(props, skip) };\n}\n\n/**\n * Sets the document title. The last registered Title wins; removing it restores the one below, or\n * the original title when none is left.\n *\n * @param props The title text.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_TITLE_TEXT`) when the children are not text.\n * @example\n * import { Title } from \"@shadow-js/web\";\n *\n * function Home() {\n * return <Title>Home | Blog</Title>;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Title(props: TitleProps): null {\n useHead((): HeadTag => ({ tag: \"title\", children: textOf(props.children) }));\n return null;\n}\n\n/**\n * Registers a `<meta>`. Identity follows name, property, http-equiv or charset, so the last\n * description wins. Children are ignored: a meta carries no text.\n *\n * @param props Attributes, such as `name` and `content`.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_ATTRIBUTE_VALUE`) for an attribute value that\n * is not a string, number or boolean, and for an invalid attribute name or an event attribute\n * (see {@link normalizeTags}).\n * @example\n * import { Meta } from \"@shadow-js/web\";\n *\n * function About() {\n * return <Meta name=\"description\" content=\"About us\" />;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Meta(props: HeadAttributeProps): null {\n useHead(() => attributeTag(\"meta\", props, [\"children\"]));\n return null;\n}\n\n/**\n * Registers a `<link>`. Icons are keyed by rel, sizes and type; preloads and stylesheets by rel,\n * href and as; other links are append-only.\n *\n * @param props Attributes, such as `rel` and `href`.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_ATTRIBUTE_VALUE`) for an attribute value that\n * is not a string, number or boolean, and for an invalid attribute name or an event attribute\n * (see {@link normalizeTags}).\n * @example\n * import { Link } from \"@shadow-js/web\";\n *\n * function Page() {\n * return <Link rel=\"stylesheet\" href=\"/site.css\" />;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Link(props: HeadAttributeProps): null {\n useHead(() => attributeTag(\"link\", props, [\"children\"]));\n return null;\n}\n\n/**\n * Registers a `<style>` with the given CSS text. A `key` makes it replace an earlier style with the\n * same key; without one, every style stays.\n *\n * @param props The CSS as `children`, an optional `key`, and attributes such as `media`.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_KEY`) when `key` is not a non-empty string.\n * @example\n * import { Style } from \"@shadow-js/web\";\n *\n * function Theme() {\n * return <Style key=\"theme\">{\"body { margin: 0 }\"}</Style>;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Style(props: StyleProps): null {\n useHead((): HeadTag => {\n const attributes = attributesOf(props, [\"children\", \"key\"]);\n const text = props.children === undefined ? undefined : textOf(props.children);\n const key = keyOf(props.key);\n return {\n tag: \"style\",\n props: attributes,\n ...(text === undefined ? {} : { children: text }),\n ...(key === undefined ? {} : { key }),\n };\n });\n return null;\n}\n\n/**\n * Registers the document `<base>`. There is one; the last registration wins. Base is placed first\n * in the head, as browsers expect.\n *\n * @param props Attributes, such as `href`.\n * @returns Always null: nothing is rendered in place.\n * @throws TypeError (production message `SHADOW_HEAD_ATTRIBUTE_VALUE`) for an attribute value that\n * is not a string, number or boolean.\n * @example\n * import { Base } from \"@shadow-js/web\";\n *\n * function Shell() {\n * return <Base href=\"/app/\" />;\n * }\n * @see useHead\n * @since 1.0.0\n */\nexport function Base(props: HeadAttributeProps): null {\n useHead(() => attributeTag(\"base\", props, [\"children\"]));\n return null;\n}\n"],"mappings":"A,wCAmDA,SAASC,EAASC,EAAwB,CACxC,GAAI,OAAOA,GAAU,SAAU,OAAOA,EACtC,GAAI,OAAOA,GAAU,SAAU,OAAO,OAAOA,CAAK,EAClD,GAAIA,GAAiC,MAAQA,IAAU,GAAO,MAAO,GACrE,MAAU,UACkD,wBAC5D,CACF,CAGA,SAASC,EAAOD,EAAwB,CACtC,IAAME,EAAW,OAAOF,GAAU,WAAcA,EAAwB,EAAIA,EAE5E,OADI,MAAM,QAAQE,CAAQ,EAAWA,EAAuB,IAAIH,CAAQ,CAAC,CAAC,KAAK,EAAE,EAC1EA,EAASG,CAAQ,CAC1B,CAGA,SAASC,EAAMH,EAAoC,CACjD,GAAIA,GAAiC,KACrC,IAAI,OAAOA,GAAU,UAAYA,IAAU,GAAI,OAAOA,EACtD,MAAU,UACuD,iBACjE,CAHsD,CAIxD,CAGA,SAASI,EAAeJ,EAAoC,CAC1D,GAAIA,GAAiC,MAAQA,IAAU,GACvD,IAAIA,IAAU,GAAM,MAAO,GAE3B,GADI,OAAOA,GAAU,UACjB,OAAOA,GAAU,SAAU,OAAOA,EACtC,MAAU,UAGJ,6BACN,CAP2B,CAQ7B,CAMA,SAASK,EAAaC,EAAeC,EAA6D,CAChG,IAAMC,EAA+C,CAAC,EACtD,IAAK,IAAMC,KAAO,OAAO,KAAKH,CAAK,EAC7BC,EAAK,SAASE,CAAG,GACrBD,EAAQ,KAAK,CAACC,EAAKL,EAAe,QAAQ,IAAIE,EAAOG,CAAG,CAAC,CAAC,CAAC,EAE7D,OAAO,OAAO,YAAYD,CAAO,CACnC,CAGA,SAASE,EAAaC,EAAkBL,EAAeC,EAAkC,CACvF,MAAO,CAAEI,MAAK,MAAON,EAAaC,EAAOC,CAAI,CAAE,CACjD,CAkBA,SAAgBK,EAAMN,EAAyB,CAE7C,OADAR,OAAwB,CAAE,IAAK,QAAS,SAAUG,EAAOK,EAAM,QAAQ,CAAE,EAAE,EACpE,IACT,CAoBA,SAAgBO,EAAKP,EAAiC,CAEpD,OADAR,MAAcY,EAAa,OAAQJ,EAAO,CAAC,UAAU,CAAC,CAAC,EAChD,IACT,CAoBA,SAAgBQ,EAAKR,EAAiC,CAEpD,OADAR,MAAcY,EAAa,OAAQJ,EAAO,CAAC,UAAU,CAAC,CAAC,EAChD,IACT,CAkBA,SAAgBS,EAAMT,EAAyB,CAY7C,OAXAR,MAAuB,CACrB,IAAMkB,EAAaX,EAAaC,EAAO,CAAC,WAAY,KAAK,CAAC,EACpDW,EAAOX,EAAM,WAAa,IAAA,GAAY,IAAA,GAAYL,EAAOK,EAAM,QAAQ,EACvEG,EAAMN,EAAMG,EAAM,GAAG,EAC3B,MAAO,CACL,IAAK,QACL,MAAOU,EACP,GAAIC,IAAS,IAAA,GAAY,CAAC,EAAI,CAAE,SAAUA,CAAK,EAC/C,GAAIR,IAAQ,IAAA,GAAY,CAAC,EAAI,CAAEA,KAAI,CACrC,CACF,CAAC,EACM,IACT,CAmBA,SAAgBS,EAAKZ,EAAiC,CAEpD,OADAR,MAAcY,EAAa,OAAQJ,EAAO,CAAC,UAAU,CAAC,CAAC,EAChD,IACT,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","names":["noop","createHeadRegistry","stacks","appendOnly","tags","entries","tag","slot","stack","entry","
|
|
1
|
+
{"version":3,"file":"registry.js","names":["noop","createHeadRegistry","onChange","stacks","appendOnly","tags","entries","tag","slot","stack","entry","removed","index","winners","top"],"sources":["../../../src/head/registry.ts"],"sourcesContent":["import type { NormalizedTag } from \"./validate\";\n\n/**\n * One rendered head element: the slot it occupies (its identity, or a unique key for an\n * append-only tag) and the tag that currently wins that slot.\n * @internal\n */\nexport interface HeadWinner {\n readonly slot: string;\n readonly tag: NormalizedTag;\n}\n\n/**\n * The pure head registry: no DOM, no signals. Every registration joins the stack of its identity;\n * the top of each stack is the winner. Removing a registration takes it out of its stack, so the\n * one below it wins again.\n * @internal\n */\nexport interface HeadRegistry {\n /**\n * Registers a group of tags. The returned function removes them again; calling it twice is a\n * no-op.\n */\n add(tags: readonly NormalizedTag[]): () => void;\n /** The winning tag of every slot, in the order each slot first appeared. */\n winners(): HeadWinner[];\n}\n\ninterface Entry {\n readonly slot: string;\n readonly tag: NormalizedTag;\n}\n\nconst noop = (): void => undefined;\n\n/**\n * Creates an empty head registry. `onChange` runs after every effective add or removal, so the\n * owner of the DOM can schedule one update for a whole batch.\n *\n * @param onChange Called after the registry changes.\n * @returns A registry with no winners.\n * @internal\n * @since 1.0.0\n */\nexport function createHeadRegistry(onChange: () => void): HeadRegistry {\n const stacks = new Map<string, Entry[]>();\n let appendOnly = 0;\n return {\n add(tags: readonly NormalizedTag[]): () => void {\n if (tags.length === 0) return noop;\n const entries: Entry[] = [];\n for (const tag of tags) {\n let slot = tag.identity;\n if (slot === undefined) {\n slot = `#${appendOnly}`;\n appendOnly += 1;\n }\n let stack = stacks.get(slot);\n if (stack === undefined) {\n stack = [];\n stacks.set(slot, stack);\n }\n const entry: Entry = { slot, tag };\n stack.push(entry);\n entries.push(entry);\n }\n onChange();\n let removed = false;\n return (): void => {\n if (removed) return;\n removed = true;\n for (const entry of entries) {\n const stack = stacks.get(entry.slot);\n if (stack === undefined) continue;\n const index = stack.indexOf(entry);\n if (index !== -1) stack.splice(index, 1);\n if (stack.length === 0) stacks.delete(entry.slot);\n }\n onChange();\n };\n },\n winners(): HeadWinner[] {\n const winners: HeadWinner[] = [];\n for (const [slot, stack] of stacks) {\n const top = stack[stack.length - 1];\n if (top !== undefined) winners.push({ slot, tag: top.tag });\n }\n return winners;\n },\n };\n}\n"],"mappings":"AAiCA,MAAMA,MAAmB,IAAA,GAWzB,SAAgBC,EAAmBC,EAAoC,CACrE,IAAMC,kBAAS,IAAI,IACfC,EAAa,EACjB,MAAO,CACL,IAAIC,EAA4C,CAC9C,GAAIA,EAAK,SAAW,EAAG,OAAOL,EAC9B,IAAMM,EAAmB,CAAC,EAC1B,IAAK,IAAMC,KAAOF,EAAM,CACtB,IAAIG,EAAOD,EAAI,SACXC,IAAS,IAAA,KACXA,EAAO,IAAIJ,IACXA,GAAc,GAEhB,IAAIK,EAAQN,EAAO,IAAIK,CAAI,EACvBC,IAAU,IAAA,KACZA,EAAQ,CAAC,EACTN,EAAO,IAAIK,EAAMC,CAAK,GAExB,IAAMC,EAAe,CAAEF,OAAMD,KAAI,EACjCE,EAAM,KAAKC,CAAK,EAChBJ,EAAQ,KAAKI,CAAK,CACpB,CACAR,EAAS,EACT,IAAIS,EAAU,GACd,UAAmB,CACjB,GAAIA,GACJA,GAAU,GACV,IAAK,IAAMD,KAASJ,EAAS,CAC3B,IAAMG,EAAQN,EAAO,IAAIO,EAAM,IAAI,EACnC,GAAID,IAAU,IAAA,GAAW,SACzB,IAAMG,EAAQH,EAAM,QAAQC,CAAK,EAC7BE,IAAU,IAAIH,EAAM,OAAOG,EAAO,CAAC,EACnCH,EAAM,SAAW,GAAGN,EAAO,OAAOO,EAAM,IAAI,CAClD,CACAR,EAAS,CARC,CASZ,CACF,EACA,SAAwB,CACtB,IAAMW,EAAwB,CAAC,EAC/B,IAAK,GAAM,CAACL,EAAMC,KAAUN,EAAQ,CAClC,IAAMW,EAAML,EAAMA,EAAM,OAAS,GAC7BK,IAAQ,IAAA,IAAWD,EAAQ,KAAK,CAAEL,OAAM,IAAKM,EAAI,GAAI,CAAC,CAC5D,CACA,OAAOD,CACT,CACF,CACF,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-head.js","names":["
|
|
1
|
+
{"version":3,"file":"server-head.js","names":["escapeHtml","createHeadRegistry","HEAD_KEY","HEAD_MARKER","createContext","VOID_TAGS","ServerHeadContext","tagHtml","tag","nonce","attributes","name","value","text","createServerHead","registry","tags","options","winner","runWithServerHead","head","fn","holder"],"sources":["../../../src/head/server-head.ts"],"sourcesContent":["import { type Context, createContext } from \"@shadow-js/core\";\nimport { escapeHtml } from \"../server/escape\";\nimport { createHeadRegistry, type HeadRegistry } from \"./registry\";\nimport { HEAD_KEY, HEAD_MARKER, type NormalizedTag } from \"./validate\";\n\n/** Elements that never have content or a closing tag. */\nconst VOID_TAGS: ReadonlySet<string> = new Set([\"meta\", \"link\", \"base\"]);\n\n/**\n * The head of one server render: what `useHead`, `<Title>`, `<Meta>`, `<Link>`, `<Style>` and\n * `<Base>` registered while the app rendered. Pass it to a render function through its `head`\n * option, then write {@link ServerHead.html} into the document's `<head>`.\n *\n * Tags follow the same rules as in the browser: the last registration of an identity wins\n * (`title`, `meta` by name, ...), append-only tags all stay. Every tag carries the marker the\n * browser's head sink looks for, so the client adopts the server's elements instead of adding\n * duplicates.\n * @since 1.0.0\n */\nexport interface ServerHead {\n /** Registers tags. Used by `useHead`; the returned function removes them again. */\n add(tags: readonly NormalizedTag[]): () => void;\n /** Forgets every registration. Multi-pass renders call this before each pass. */\n clear(): void;\n /**\n * The markup of the winning tags, in registration order. With a `nonce`, every `<style>` carries\n * it, so the page's Content-Security-Policy (`style-src 'nonce-...'`) accepts the styles. Throws a\n * TypeError when the text of a style contains a closing style tag.\n *\n * @param options `nonce` is added to every `<style>`. Default: no options, so no nonce.\n */\n html(options?: { readonly nonce?: string }): string;\n /** The winning tags, for hosts that build the head themselves. */\n tags(): readonly NormalizedTag[];\n}\n\n/** The collector `useHead` writes to while a render is running; null outside a render with `head`. @internal */\nexport const ServerHeadContext: Context<ServerHead | null> =\n /* @__PURE__ */ createContext<ServerHead | null>(null, { name: \"ServerHead\" });\n\n/** Markup of one tag. Text and attribute values are escaped; `</style` cannot appear in a style. */\nfunction tagHtml(tag: NormalizedTag, nonce: string | undefined): string {\n let attributes = ` ${HEAD_MARKER}`;\n if (tag.key !== undefined) attributes += ` ${HEAD_KEY}=\"${escapeHtml(tag.key)}\"`;\n for (const [name, value] of tag.attributes) {\n attributes += value === \"\" ? ` ${name}` : ` ${name}=\"${escapeHtml(value)}\"`;\n }\n if (VOID_TAGS.has(tag.tag)) return `<${tag.tag}${attributes}>`;\n const text = tag.text ?? \"\";\n if (tag.tag === \"style\") {\n if (/<\\/style/i.test(text)) {\n throw new TypeError(\"ShadowJS head: style text may not contain a closing style tag.\");\n }\n const withNonce =\n nonce === undefined ? attributes : `${attributes} nonce=\"${escapeHtml(nonce)}\"`;\n return `<style${withNonce}>${text}</style>`;\n }\n return `<${tag.tag}${attributes}>${escapeHtml(text)}</${tag.tag}>`;\n}\n\n/**\n * Creates an empty server head collector.\n *\n * @returns A collector to pass as the `head` option of `renderToString`, `renderToStringAsync` or\n * `renderToStream`.\n * @example\n * import { createComponent, Title } from \"@shadow-js/web\";\n * import { createServerHead, renderToString } from \"@shadow-js/web/server\";\n *\n * function App() {\n * return Title({ children: \"Home\" });\n * }\n *\n * const head = createServerHead();\n * const html = renderToString(() => createComponent(App, {}), { head });\n * const page = `<!doctype html><head>${head.html()}</head><body>${html}</body>`;\n * @see useHead\n * @since 1.0.0\n */\nexport function createServerHead(): ServerHead {\n let registry: HeadRegistry = createHeadRegistry(() => undefined);\n return {\n add: (tags) => registry.add(tags),\n clear() {\n registry = createHeadRegistry(() => undefined);\n },\n html: (options) =>\n registry\n .winners()\n .map((winner) => tagHtml(winner.tag, options?.nonce))\n .join(\"\"),\n tags: () => registry.winners().map((winner) => winner.tag),\n };\n}\n\n/**\n * Runs `fn` with `head` as the collector `useHead` writes to. Server renderers call it around the\n * app; with no collector `fn` runs as is. @internal\n */\nexport function runWithServerHead<T>(head: ServerHead | undefined, fn: () => T): T {\n if (head === undefined) return fn();\n const holder: { value?: T } = {};\n ServerHeadContext({\n value: head,\n get children() {\n holder.value = fn();\n return null;\n },\n });\n return holder.value as T;\n}\n"],"mappings":"A,8MAMA,MAAMK,kBAAiC,IAAI,IAAI,CAAC,OAAQ,OAAQ,MAAM,CAAC,EA+B1DC,EACKF,kBAAiC,KAAM,CAAE,KAAM,YAAa,CAAC,EAG/E,SAASG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F,CAAC,EACMC,EAAO,KAChB,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sink.js","names":["
|
|
1
|
+
{"version":3,"file":"sink.js","names":["HEAD_KEY","HEAD_MARKER","identityOfElement","release","head","record","el","adoptable","slot","tag","claimed","candidate","acquire","doc","existing","sync","wanted","name","value","text","createDomHeadSink","owned","winners","winner"],"sources":["../../../src/head/sink.ts"],"sourcesContent":["import type { HeadWinner } from \"./registry\";\nimport { HEAD_KEY, HEAD_MARKER, identityOfElement, type NormalizedTag } from \"./validate\";\n\n/**\n * What the sink knows about one element it writes. `created` elements are removed on release;\n * adopted ones are removed too unless they are titles, where the original text comes back.\n */\ninterface Owned {\n readonly el: Element;\n readonly created: boolean;\n /** Text an adopted title had before the sink took it over. */\n readonly restoreText: string | undefined;\n /** Attributes last written, so the next write can remove the ones that disappeared. */\n attributes: ReadonlyArray<readonly [string, string]>;\n}\n\n/** Removes or restores one element the sink owned. Elements already gone are ignored. */\nfunction release(head: HTMLHeadElement, record: Owned): void {\n const el = record.el;\n if (el.parentNode !== head) return;\n if (el.localName === \"title\" && !record.created) {\n if (record.restoreText !== undefined && el.textContent !== record.restoreText) {\n el.textContent = record.restoreText;\n }\n return;\n }\n el.remove();\n}\n\n/**\n * Finds an element to adopt for a slot, or returns undefined. Only identity-keyed slots adopt. A\n * server-rendered element carries the marker, and a page title or base is adopted even without it,\n * because the browser shows that one, so it must be the one that changes.\n */\nfunction adoptable(\n head: HTMLHeadElement,\n slot: string,\n tag: NormalizedTag,\n claimed: Set<Element>,\n): Element | undefined {\n if (tag.identity === undefined) return undefined;\n for (const candidate of Array.from(head.querySelectorAll(tag.tag))) {\n if (claimed.has(candidate)) continue;\n if (identityOfElement(candidate) !== slot) continue;\n if (candidate.hasAttribute(HEAD_MARKER) || tag.tag === \"title\") return candidate;\n }\n return undefined;\n}\n\n/** Takes over an existing element for a slot, or creates and marks a new one. */\nfunction acquire(doc: Document, slot: string, tag: NormalizedTag, claimed: Set<Element>): Owned {\n const head = doc.head;\n const existing = adoptable(head, slot, tag, claimed);\n if (existing !== undefined) {\n const restoreText = tag.tag === \"title\" ? existing.textContent : undefined;\n return { el: existing, created: false, restoreText, attributes: [] };\n }\n const el = doc.createElement(tag.tag);\n el.setAttribute(HEAD_MARKER, \"\");\n if (tag.key !== undefined) el.setAttribute(HEAD_KEY, tag.key);\n if (tag.tag === \"base\") head.insertBefore(el, head.firstChild);\n else head.appendChild(el);\n return { el, created: true, restoreText: undefined, attributes: [] };\n}\n\n/** Writes the attributes and text of `tag` to its element, touching only what changed. */\nfunction sync(record: Owned, tag: NormalizedTag): void {\n const el = record.el;\n const wanted = new Map<string, string>(tag.attributes);\n for (const [name] of record.attributes) {\n if (!wanted.has(name)) el.removeAttribute(name);\n }\n for (const [name, value] of tag.attributes) {\n if (el.getAttribute(name) !== value) el.setAttribute(name, value);\n }\n record.attributes = tag.attributes;\n if (tag.tag === \"title\" || tag.tag === \"style\") {\n const text = tag.text ?? \"\";\n if (el.textContent !== text) el.textContent = text;\n }\n}\n\n/**\n * Creates the DOM sink for one document. The returned function makes `document.head` show the\n * given winners: it releases elements whose slot is gone, adopts or creates the rest and updates\n * them in place. It is called once per batch of registrations, so one call is one DOM pass.\n *\n * @param doc The document whose head is written.\n * @returns A function that applies a list of winners.\n * @internal\n * @since 1.0.0\n */\nexport function createDomHeadSink(doc: Document): (winners: readonly HeadWinner[]) => void {\n const owned = new Map<string, Owned>();\n return (winners: readonly HeadWinner[]): void => {\n const head = doc.head;\n const wanted = new Set(winners.map((winner) => winner.slot));\n for (const [slot, record] of owned) {\n if (wanted.has(slot) && record.el.parentNode === head) continue;\n owned.delete(slot);\n release(head, record);\n }\n const claimed = new Set<Element>();\n for (const record of owned.values()) claimed.add(record.el);\n for (const winner of winners) {\n let record = owned.get(winner.slot);\n if (record === undefined) {\n record = acquire(doc, winner.slot, winner.tag, claimed);\n owned.set(winner.slot, record);\n claimed.add(record.el);\n }\n sync(record, winner.tag);\n }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AASZ,EAAO,WACrBW,EAAO,IAAIC,CAAI,GAAGX,EAAG,gBAAgBW,CAAI,EAEhD,IAAK,GAAM,CAACA,EAAMC,KAAUT,EAAI,WAC1BH,EAAG,aAAaW,CAAI,IAAMC,GAAOZ,EAAG,aAAaW,EAAMC,CAAK,EAGlE,GADAb,EAAO,WAAaI,EAAI,WACpBA,EAAI,MAAQ,SAAWA,EAAI,MAAQ,QAAS,CAC9C,IAAMU,EAAOV,EAAI,MAAQ,GACrBH,EAAG,cAAgBa,IAAMb,EAAG,YAAca,EAChD,CACF,CAYA,SAAgBC,EAAkBP,EAAyD,CACzF,IAAMQ,kBAAQ,IAAI,IAClB,MAAQC,IAAyC,CAC/C,IAAMlB,EAAOS,EAAI,KACXG,EAAS,IAAI,IAAIM,EAAQ,IAAKC,GAAWA,EAAO,IAAI,CAAC,EAC3D,IAAK,GAAM,CAACf,EAAMH,KAAWgB,EACvBL,EAAO,IAAIR,CAAI,GAAKH,EAAO,GAAG,aAAeD,IACjDiB,EAAM,OAAOb,CAAI,EACjBL,EAAQC,EAAMC,CAAM,GAEtB,IAAMK,kBAAU,IAAI,IACpB,IAAK,IAAML,KAAUgB,EAAM,OAAO,EAAGX,EAAQ,IAAIL,EAAO,EAAE,EAC1D,IAAK,IAAMkB,KAAUD,EAAS,CAC5B,IAAIjB,EAASgB,EAAM,IAAIE,EAAO,IAAI,EAC9BlB,IAAW,IAAA,KACbA,EAASO,EAAQC,EAAKU,EAAO,KAAMA,EAAO,IAAKb,CAAO,EACtDW,EAAM,IAAIE,EAAO,KAAMlB,CAAM,EAC7BK,EAAQ,IAAIL,EAAO,EAAE,GAEvBU,EAAKV,EAAQkB,EAAO,GAAG,CACzB,CACF,CACF,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-head.js","names":["
|
|
1
|
+
{"version":3,"file":"use-head.js","names":["createHeadRegistry","ServerHeadContext","createDomHeadSink","normalizeTags","createRoot","getOwner","isServer","untrack","useContext","useEffect","useRenderEffect","useSignal","registries","createRegistryFor","doc","version","bump","registry","count","apply","winners","registryFor","known","useHead","input","collector","tags"],"sources":["../../../src/head/use-head.ts"],"sourcesContent":["import {\n createRoot,\n getOwner,\n isServer,\n untrack,\n useContext,\n useEffect,\n useRenderEffect,\n useSignal,\n} from \"@shadow-js/core\";\nimport { createHeadRegistry, type HeadRegistry } from \"./registry\";\nimport { ServerHeadContext } from \"./server-head\";\nimport { createDomHeadSink } from \"./sink\";\nimport { type HeadInput, normalizeTags } from \"./validate\";\n\n/** One registry per document, shared by every `useHead` call on it. */\nconst registries = new WeakMap<Document, HeadRegistry>();\n\n/**\n * Creates the registry for a document and the deferred effect that writes it to the head. The\n * effect is detached: it lives as long as the document, not as long as the first caller. It runs\n * in the user-effect queue, so every registration made in one flush produces one DOM pass.\n */\nfunction createRegistryFor(doc: Document): HeadRegistry {\n return createRoot(\n (): HeadRegistry => {\n const [version, bump] = useSignal(0);\n const registry = createHeadRegistry(() => {\n bump((count) => count + 1);\n });\n const apply = createDomHeadSink(doc);\n useEffect(\n () => {\n version();\n return registry.winners();\n },\n (winners) => {\n apply(winners);\n },\n );\n return registry;\n },\n { detached: true },\n );\n}\n\n/** The registry of a document, created on first use. */\nfunction registryFor(doc: Document): HeadRegistry {\n const known = registries.get(doc);\n if (known !== undefined) return known;\n const registry = createRegistryFor(doc);\n registries.set(doc, registry);\n return registry;\n}\n\n/**\n * Registers head tags for the lifetime of the current owner. Each registration joins the stack of\n * its identity: `title` and `base` are singletons, `meta` is keyed by its name, property,\n * http-equiv or charset (and media), icons by rel, sizes and type, resource links by rel, href and\n * as, and styles by key. The last registration of an identity wins; disposing it restores the one\n * below. Append-only tags (no identity) all stay. Passing a function re-registers when its\n * dependencies change. On the client the registrations are written to `document.head` after the\n * render phase of a flush, in one pass per flush. On the server the tags go to the render's `head`\n * collector (see `createServerHead`), read once; without one, or outside an owner, nothing is\n * registered.\n *\n * @param input One tag, several tags, or a function returning them. `null`, `undefined` and `false`\n * register nothing.\n * @throws TypeError for an invalid tag description (see {@link normalizeTags}); on the client the\n * error is raised in the registration's render effect and goes to the owner's error handler.\n * In development builds, calling it on the client with no owner does not throw: it warns\n * `HEAD_OUTSIDE_OWNER` and registers nothing.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { useHead } from \"@shadow-js/web\";\n *\n * function Post() {\n * const [post] = useSignal({ title: \"Hello\" });\n * useHead(() => ({ tag: \"title\", children: `${post().title} | Blog` }));\n * return null;\n * }\n * @see Title\n * @see Meta\n * @since 1.0.0\n */\nexport function useHead(input: HeadInput | (() => HeadInput)): void {\n if (isServer) {\n const collector = getOwner() === null ? null : useContext(ServerHeadContext);\n if (collector !== null) {\n collector.add(normalizeTags(untrack(() => (typeof input === \"function\" ? input() : input))));\n }\n return;\n }\n if (getOwner() === null) {\n if (__DEV__) {\n console.warn(\"[shadow HEAD_OUTSIDE_OWNER] useHead() needs an owner; nothing was registered.\");\n }\n return;\n }\n const registry = registryFor(document);\n useRenderEffect(\n () => normalizeTags(typeof input === \"function\" ? input() : input),\n (tags) => registry.add(tags),\n );\n}\n"],"mappings":"A,6VAgBA,MAAMY,kBAAa,IAAI,QAOvB,SAASC,EAAkBC,EAA6B,CACtD,OAAOV,MACe,CAClB,GAAM,CAACW,EAASC,GAAQL,EAAU,CAAC,EAC7BM,EAAWjB,MAAyB,CACxCgB,EAAME,GAAUA,EAAQ,CAAC,CAC3B,CAAC,EACKC,EAAQjB,EAAkBY,CAAG,EAUnC,OATAL,OAEIM,EAAQ,EACDE,EAAS,QAAQ,GAEzBG,GAAY,CACXD,EAAMC,CAAO,CACf,CACF,EACOH,CACT,EACA,CAAE,SAAU,EAAK,CACnB,CACF,CAGA,SAASI,EAAYP,EAA6B,CAChD,IAAMQ,EAAQV,EAAW,IAAIE,CAAG,EAChC,GAAIQ,IAAU,IAAA,GAAW,OAAOA,EAChC,IAAML,EAAWJ,EAAkBC,CAAG,EAEtC,OADAF,EAAW,IAAIE,EAAKG,CAAQ,EACrBA,CACT,CAgCA,SAAgBM,EAAQC,EAA4C,CAClE,GAAIlB,EAAU,CACZ,IAAMmB,EAAYpB,EAAS,IAAM,KAAO,KAAOG,EAAWP,CAAiB,EACvEwB,IAAc,MAChBA,EAAU,IAAItB,EAAcI,MAAe,OAAOiB,GAAU,WAAaA,EAAM,EAAIA,CAAM,CAAC,CAAC,EAE7F,MACF,CACA,GAAInB,EAAS,IAAM,KAIjB,OAEF,IAAMY,EAAWI,EAAY,QAAQ,EACrCX,MACQP,EAAc,OAAOqB,GAAU,WAAaA,EAAM,EAAIA,CAAK,EAChEE,GAAST,EAAS,IAAIS,CAAI,CAC7B,CACF,C"}
|