@shadow-js/web 0.0.0-stage → 1.0.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 +18 -0
- package/LICENSE +21 -0
- package/README.md +190 -2
- package/dist/dev/attributes.d.ts +88 -0
- package/dist/dev/attributes.js +195 -0
- package/dist/dev/attributes.js.map +1 -0
- package/dist/dev/autofocus.d.ts +30 -0
- package/dist/dev/autofocus.js +44 -0
- package/dist/dev/autofocus.js.map +1 -0
- package/dist/dev/class-style.d.ts +87 -0
- package/dist/dev/class-style.js +196 -0
- package/dist/dev/class-style.js.map +1 -0
- package/dist/dev/component.d.ts +21 -0
- package/dist/dev/component.js +41 -0
- package/dist/dev/component.js.map +1 -0
- package/dist/dev/control-flow/activity.d.ts +56 -0
- package/dist/dev/control-flow/activity.js +135 -0
- package/dist/dev/control-flow/activity.js.map +1 -0
- package/dist/dev/control-flow/branch.js +103 -0
- package/dist/dev/control-flow/branch.js.map +1 -0
- package/dist/dev/control-flow/client-only.d.ts +46 -0
- package/dist/dev/control-flow/client-only.js +49 -0
- package/dist/dev/control-flow/client-only.js.map +1 -0
- package/dist/dev/control-flow/dynamic.d.ts +80 -0
- package/dist/dev/control-flow/dynamic.js +133 -0
- package/dist/dev/control-flow/dynamic.js.map +1 -0
- package/dist/dev/control-flow/error-boundary.d.ts +70 -0
- package/dist/dev/control-flow/error-boundary.js +114 -0
- package/dist/dev/control-flow/error-boundary.js.map +1 -0
- package/dist/dev/control-flow/for.d.ts +78 -0
- package/dist/dev/control-flow/for.js +22 -0
- package/dist/dev/control-flow/for.js.map +1 -0
- package/dist/dev/control-flow/fragment.d.ts +36 -0
- package/dist/dev/control-flow/fragment.js +30 -0
- package/dist/dev/control-flow/fragment.js.map +1 -0
- package/dist/dev/control-flow/hot-link.js +63 -0
- package/dist/dev/control-flow/hot-link.js.map +1 -0
- package/dist/dev/control-flow/index-list.d.ts +46 -0
- package/dist/dev/control-flow/index-list.js +30 -0
- package/dist/dev/control-flow/index-list.js.map +1 -0
- package/dist/dev/control-flow/index.d.ts +15 -0
- package/dist/dev/control-flow/lazy.d.ts +56 -0
- package/dist/dev/control-flow/lazy.js +63 -0
- package/dist/dev/control-flow/lazy.js.map +1 -0
- package/dist/dev/control-flow/no-hydration.d.ts +37 -0
- package/dist/dev/control-flow/no-hydration.js +57 -0
- package/dist/dev/control-flow/no-hydration.js.map +1 -0
- package/dist/dev/control-flow/portal.d.ts +67 -0
- package/dist/dev/control-flow/portal.js +133 -0
- package/dist/dev/control-flow/portal.js.map +1 -0
- package/dist/dev/control-flow/root-errors.d.ts +23 -0
- package/dist/dev/control-flow/root-errors.js +32 -0
- package/dist/dev/control-flow/root-errors.js.map +1 -0
- package/dist/dev/control-flow/show.d.ts +99 -0
- package/dist/dev/control-flow/show.js +17 -0
- package/dist/dev/control-flow/show.js.map +1 -0
- package/dist/dev/control-flow/suspense-list.d.ts +63 -0
- package/dist/dev/control-flow/suspense-list.js +104 -0
- package/dist/dev/control-flow/suspense-list.js.map +1 -0
- package/dist/dev/control-flow/suspense.d.ts +51 -0
- package/dist/dev/control-flow/suspense.js +101 -0
- package/dist/dev/control-flow/suspense.js.map +1 -0
- package/dist/dev/control-flow/switch.d.ts +83 -0
- package/dist/dev/control-flow/switch.js +89 -0
- package/dist/dev/control-flow/switch.js.map +1 -0
- package/dist/dev/derived.d.ts +50 -0
- package/dist/dev/derived.js +33 -0
- package/dist/dev/derived.js.map +1 -0
- package/dist/dev/element.d.ts +38 -0
- package/dist/dev/element.js +104 -0
- package/dist/dev/element.js.map +1 -0
- package/dist/dev/events.d.ts +85 -0
- package/dist/dev/events.js +264 -0
- package/dist/dev/events.js.map +1 -0
- package/dist/dev/extend.d.ts +12 -0
- package/dist/dev/extend.js +12 -0
- package/dist/dev/head/components.d.ts +135 -0
- package/dist/dev/head/components.js +169 -0
- package/dist/dev/head/components.js.map +1 -0
- package/dist/dev/head/registry.js +67 -0
- package/dist/dev/head/registry.js.map +1 -0
- package/dist/dev/head/server-head.d.ts +52 -0
- package/dist/dev/head/server-head.js +75 -0
- package/dist/dev/head/server-head.js.map +1 -0
- package/dist/dev/head/sink.js +95 -0
- package/dist/dev/head/sink.js.map +1 -0
- package/dist/dev/head/use-head.d.ts +33 -0
- package/dist/dev/head/use-head.js +83 -0
- package/dist/dev/head/use-head.js.map +1 -0
- package/dist/dev/head/validate.d.ts +83 -0
- package/dist/dev/head/validate.js +267 -0
- package/dist/dev/head/validate.js.map +1 -0
- package/dist/dev/hmr.d.ts +80 -0
- package/dist/dev/hmr.js +123 -0
- package/dist/dev/hmr.js.map +1 -0
- package/dist/dev/hydration.d.ts +59 -0
- package/dist/dev/hydration.js +119 -0
- package/dist/dev/hydration.js.map +1 -0
- package/dist/dev/index.d.ts +45 -0
- package/dist/dev/index.js +34 -0
- package/dist/dev/insert.d.ts +95 -0
- package/dist/dev/insert.js +356 -0
- package/dist/dev/insert.js.map +1 -0
- package/dist/dev/internal/claim.d.ts +104 -0
- package/dist/dev/internal/claim.js +356 -0
- package/dist/dev/internal/claim.js.map +1 -0
- package/dist/dev/internal/css-units.js +25 -0
- package/dist/dev/internal/css-units.js.map +1 -0
- package/dist/dev/internal/diagnostics.d.ts +28 -0
- package/dist/dev/internal/diagnostics.js +37 -0
- package/dist/dev/internal/diagnostics.js.map +1 -0
- package/dist/dev/internal/early-events.js +75 -0
- package/dist/dev/internal/early-events.js.map +1 -0
- package/dist/dev/internal/hydration-hooks.d.ts +41 -0
- package/dist/dev/internal/hydration-hooks.js +26 -0
- package/dist/dev/internal/hydration-hooks.js.map +1 -0
- package/dist/dev/internal/hydration-scope.d.ts +129 -0
- package/dist/dev/internal/hydration-scope.js +155 -0
- package/dist/dev/internal/hydration-scope.js.map +1 -0
- package/dist/dev/internal/names.d.ts +31 -0
- package/dist/dev/internal/names.js +34 -0
- package/dist/dev/internal/names.js.map +1 -0
- package/dist/dev/internal/portal-context.d.ts +37 -0
- package/dist/dev/internal/portal-context.js +27 -0
- package/dist/dev/internal/portal-context.js.map +1 -0
- package/dist/dev/internal/react-names.js +115 -0
- package/dist/dev/internal/react-names.js.map +1 -0
- package/dist/dev/internal/reconcile.d.ts +38 -0
- package/dist/dev/internal/reconcile.js +121 -0
- package/dist/dev/internal/reconcile.js.map +1 -0
- package/dist/dev/internal/stream-context.d.ts +45 -0
- package/dist/dev/internal/stream-context.js +22 -0
- package/dist/dev/internal/stream-context.js.map +1 -0
- package/dist/dev/jsx/aria.d.ts +70 -0
- package/dist/dev/jsx/component.d.ts +87 -0
- package/dist/dev/jsx/events.d.ts +362 -0
- package/dist/dev/jsx/global.d.ts +209 -0
- package/dist/dev/jsx/html.d.ts +877 -0
- package/dist/dev/jsx/intrinsic.d.ts +57 -0
- package/dist/dev/jsx/mathml.d.ts +184 -0
- package/dist/dev/jsx/svg.d.ts +605 -0
- package/dist/dev/jsx/types.d.ts +174 -0
- package/dist/dev/jsx-dev-runtime.d.ts +10 -0
- package/dist/dev/jsx-dev-runtime.js +0 -0
- package/dist/dev/jsx-runtime.d.ts +92 -0
- package/dist/dev/jsx-runtime.js +0 -0
- package/dist/dev/reactive.d.ts +108 -0
- package/dist/dev/reactive.js +84 -0
- package/dist/dev/reactive.js.map +1 -0
- package/dist/dev/render.d.ts +34 -0
- package/dist/dev/render.js +51 -0
- package/dist/dev/render.js.map +1 -0
- package/dist/dev/resource-hints.d.ts +143 -0
- package/dist/dev/resource-hints.js +199 -0
- package/dist/dev/resource-hints.js.map +1 -0
- package/dist/dev/select-value.d.ts +22 -0
- package/dist/dev/select-value.js +50 -0
- package/dist/dev/select-value.js.map +1 -0
- package/dist/dev/server/attributes.d.ts +31 -0
- package/dist/dev/server/attributes.js +154 -0
- package/dist/dev/server/attributes.js.map +1 -0
- package/dist/dev/server/class-style.d.ts +44 -0
- package/dist/dev/server/class-style.js +172 -0
- package/dist/dev/server/class-style.js.map +1 -0
- package/dist/dev/server/component.d.ts +40 -0
- package/dist/dev/server/component.js +71 -0
- package/dist/dev/server/component.js.map +1 -0
- package/dist/dev/server/derived.d.ts +39 -0
- package/dist/dev/server/derived.js +25 -0
- package/dist/dev/server/derived.js.map +1 -0
- package/dist/dev/server/element.d.ts +87 -0
- package/dist/dev/server/element.js +215 -0
- package/dist/dev/server/element.js.map +1 -0
- package/dist/dev/server/errors.js +25 -0
- package/dist/dev/server/errors.js.map +1 -0
- package/dist/dev/server/escape.d.ts +28 -0
- package/dist/dev/server/escape.js +118 -0
- package/dist/dev/server/escape.js.map +1 -0
- package/dist/dev/server/form-controls.d.ts +48 -0
- package/dist/dev/server/form-controls.js +192 -0
- package/dist/dev/server/form-controls.js.map +1 -0
- package/dist/dev/server/hydration-script.d.ts +63 -0
- package/dist/dev/server/hydration-script.js +58 -0
- package/dist/dev/server/hydration-script.js.map +1 -0
- package/dist/dev/server/index.d.ts +16 -0
- package/dist/dev/server/index.js +16 -0
- package/dist/dev/server/node.d.ts +11 -0
- package/dist/dev/server/node.js +20 -0
- package/dist/dev/server/node.js.map +1 -0
- package/dist/dev/server/portals.d.ts +44 -0
- package/dist/dev/server/portals.js +98 -0
- package/dist/dev/server/portals.js.map +1 -0
- package/dist/dev/server/render.d.ts +127 -0
- package/dist/dev/server/render.js +255 -0
- package/dist/dev/server/render.js.map +1 -0
- package/dist/dev/server/serialize.d.ts +43 -0
- package/dist/dev/server/serialize.js +314 -0
- package/dist/dev/server/serialize.js.map +1 -0
- package/dist/dev/server/stream.d.ts +92 -0
- package/dist/dev/server/stream.js +234 -0
- package/dist/dev/server/stream.js.map +1 -0
- package/dist/dev/server.d.ts +16 -0
- package/dist/dev/server.js +16 -0
- package/dist/dev/spread.d.ts +47 -0
- package/dist/dev/spread.js +295 -0
- package/dist/dev/spread.js.map +1 -0
- package/dist/dev/template.d.ts +24 -0
- package/dist/dev/template.js +119 -0
- package/dist/dev/template.js.map +1 -0
- package/dist/dev/view-transition.d.ts +95 -0
- package/dist/dev/view-transition.js +120 -0
- package/dist/dev/view-transition.js.map +1 -0
- package/dist/prod/attributes.js +2 -0
- package/dist/prod/attributes.js.map +1 -0
- package/dist/prod/autofocus.js +2 -0
- package/dist/prod/autofocus.js.map +1 -0
- package/dist/prod/class-style.js +2 -0
- package/dist/prod/class-style.js.map +1 -0
- package/dist/prod/component.js +2 -0
- package/dist/prod/component.js.map +1 -0
- package/dist/prod/control-flow/activity.js +2 -0
- package/dist/prod/control-flow/activity.js.map +1 -0
- package/dist/prod/control-flow/branch.js +2 -0
- package/dist/prod/control-flow/branch.js.map +1 -0
- package/dist/prod/control-flow/client-only.js +2 -0
- package/dist/prod/control-flow/client-only.js.map +1 -0
- package/dist/prod/control-flow/dynamic.js +2 -0
- package/dist/prod/control-flow/dynamic.js.map +1 -0
- package/dist/prod/control-flow/error-boundary.js +2 -0
- package/dist/prod/control-flow/error-boundary.js.map +1 -0
- package/dist/prod/control-flow/for.js +2 -0
- package/dist/prod/control-flow/for.js.map +1 -0
- package/dist/prod/control-flow/fragment.js +2 -0
- package/dist/prod/control-flow/fragment.js.map +1 -0
- package/dist/prod/control-flow/hot-link.js +2 -0
- package/dist/prod/control-flow/hot-link.js.map +1 -0
- package/dist/prod/control-flow/index-list.js +2 -0
- package/dist/prod/control-flow/index-list.js.map +1 -0
- package/dist/prod/control-flow/lazy.js +2 -0
- package/dist/prod/control-flow/lazy.js.map +1 -0
- package/dist/prod/control-flow/no-hydration.js +2 -0
- package/dist/prod/control-flow/no-hydration.js.map +1 -0
- package/dist/prod/control-flow/portal.js +2 -0
- package/dist/prod/control-flow/portal.js.map +1 -0
- package/dist/prod/control-flow/root-errors.js +2 -0
- package/dist/prod/control-flow/root-errors.js.map +1 -0
- package/dist/prod/control-flow/show.js +2 -0
- package/dist/prod/control-flow/show.js.map +1 -0
- package/dist/prod/control-flow/suspense-list.js +2 -0
- package/dist/prod/control-flow/suspense-list.js.map +1 -0
- package/dist/prod/control-flow/suspense.js +2 -0
- package/dist/prod/control-flow/suspense.js.map +1 -0
- package/dist/prod/control-flow/switch.js +2 -0
- package/dist/prod/control-flow/switch.js.map +1 -0
- package/dist/prod/derived.js +2 -0
- package/dist/prod/derived.js.map +1 -0
- package/dist/prod/element.js +2 -0
- package/dist/prod/element.js.map +1 -0
- package/dist/prod/events.js +2 -0
- package/dist/prod/events.js.map +1 -0
- package/dist/prod/extend.js +1 -0
- package/dist/prod/head/components.js +2 -0
- package/dist/prod/head/components.js.map +1 -0
- package/dist/prod/head/registry.js +2 -0
- package/dist/prod/head/registry.js.map +1 -0
- package/dist/prod/head/server-head.js +2 -0
- package/dist/prod/head/server-head.js.map +1 -0
- package/dist/prod/head/sink.js +2 -0
- package/dist/prod/head/sink.js.map +1 -0
- package/dist/prod/head/use-head.js +2 -0
- package/dist/prod/head/use-head.js.map +1 -0
- package/dist/prod/head/validate.js +2 -0
- package/dist/prod/head/validate.js.map +1 -0
- package/dist/prod/hmr.js +2 -0
- package/dist/prod/hmr.js.map +1 -0
- package/dist/prod/hydration.js +2 -0
- package/dist/prod/hydration.js.map +1 -0
- package/dist/prod/index.js +1 -0
- package/dist/prod/insert.js +2 -0
- package/dist/prod/insert.js.map +1 -0
- package/dist/prod/internal/claim.js +2 -0
- package/dist/prod/internal/claim.js.map +1 -0
- package/dist/prod/internal/css-units.js +2 -0
- package/dist/prod/internal/css-units.js.map +1 -0
- package/dist/prod/internal/diagnostics.js +2 -0
- package/dist/prod/internal/diagnostics.js.map +1 -0
- package/dist/prod/internal/early-events.js +2 -0
- package/dist/prod/internal/early-events.js.map +1 -0
- package/dist/prod/internal/hydration-hooks.js +2 -0
- package/dist/prod/internal/hydration-hooks.js.map +1 -0
- package/dist/prod/internal/hydration-scope.js +2 -0
- package/dist/prod/internal/hydration-scope.js.map +1 -0
- package/dist/prod/internal/names.js +2 -0
- package/dist/prod/internal/names.js.map +1 -0
- package/dist/prod/internal/portal-context.js +2 -0
- package/dist/prod/internal/portal-context.js.map +1 -0
- package/dist/prod/internal/react-names.js +2 -0
- package/dist/prod/internal/react-names.js.map +1 -0
- package/dist/prod/internal/reconcile.js +2 -0
- package/dist/prod/internal/reconcile.js.map +1 -0
- package/dist/prod/internal/stream-context.js +2 -0
- package/dist/prod/internal/stream-context.js.map +1 -0
- package/dist/prod/jsx-dev-runtime.js +0 -0
- package/dist/prod/jsx-runtime.js +0 -0
- package/dist/prod/reactive.js +2 -0
- package/dist/prod/reactive.js.map +1 -0
- package/dist/prod/render.js +2 -0
- package/dist/prod/render.js.map +1 -0
- package/dist/prod/resource-hints.js +2 -0
- package/dist/prod/resource-hints.js.map +1 -0
- package/dist/prod/select-value.js +2 -0
- package/dist/prod/select-value.js.map +1 -0
- package/dist/prod/server/attributes.js +2 -0
- package/dist/prod/server/attributes.js.map +1 -0
- package/dist/prod/server/class-style.js +2 -0
- package/dist/prod/server/class-style.js.map +1 -0
- package/dist/prod/server/component.js +2 -0
- package/dist/prod/server/component.js.map +1 -0
- package/dist/prod/server/derived.js +2 -0
- package/dist/prod/server/derived.js.map +1 -0
- package/dist/prod/server/element.js +2 -0
- package/dist/prod/server/element.js.map +1 -0
- package/dist/prod/server/errors.js +2 -0
- package/dist/prod/server/errors.js.map +1 -0
- package/dist/prod/server/escape.js +2 -0
- package/dist/prod/server/escape.js.map +1 -0
- package/dist/prod/server/form-controls.js +3 -0
- package/dist/prod/server/form-controls.js.map +1 -0
- package/dist/prod/server/hydration-script.js +2 -0
- package/dist/prod/server/hydration-script.js.map +1 -0
- package/dist/prod/server/index.js +1 -0
- package/dist/prod/server/node.js +2 -0
- package/dist/prod/server/node.js.map +1 -0
- package/dist/prod/server/portals.js +2 -0
- package/dist/prod/server/portals.js.map +1 -0
- package/dist/prod/server/render.js +2 -0
- package/dist/prod/server/render.js.map +1 -0
- package/dist/prod/server/serialize.js +2 -0
- package/dist/prod/server/serialize.js.map +1 -0
- package/dist/prod/server/stream.js +2 -0
- package/dist/prod/server/stream.js.map +1 -0
- package/dist/prod/server.js +1 -0
- package/dist/prod/spread.js +2 -0
- package/dist/prod/spread.js.map +1 -0
- package/dist/prod/template.js +2 -0
- package/dist/prod/template.js.map +1 -0
- package/dist/prod/view-transition.js +2 -0
- package/dist/prod/view-transition.js.map +1 -0
- package/dist/server/attributes.js +2 -0
- package/dist/server/attributes.js.map +1 -0
- package/dist/server/autofocus.js +2 -0
- package/dist/server/autofocus.js.map +1 -0
- package/dist/server/class-style.js +2 -0
- package/dist/server/class-style.js.map +1 -0
- package/dist/server/component.js +2 -0
- package/dist/server/component.js.map +1 -0
- package/dist/server/control-flow/activity.js +2 -0
- package/dist/server/control-flow/activity.js.map +1 -0
- package/dist/server/control-flow/branch.js +2 -0
- package/dist/server/control-flow/branch.js.map +1 -0
- package/dist/server/control-flow/client-only.js +2 -0
- package/dist/server/control-flow/client-only.js.map +1 -0
- package/dist/server/control-flow/dynamic.js +2 -0
- package/dist/server/control-flow/dynamic.js.map +1 -0
- package/dist/server/control-flow/error-boundary.js +2 -0
- package/dist/server/control-flow/error-boundary.js.map +1 -0
- package/dist/server/control-flow/for.js +2 -0
- package/dist/server/control-flow/for.js.map +1 -0
- package/dist/server/control-flow/fragment.js +2 -0
- package/dist/server/control-flow/fragment.js.map +1 -0
- package/dist/server/control-flow/index-list.js +2 -0
- package/dist/server/control-flow/index-list.js.map +1 -0
- package/dist/server/control-flow/lazy.js +2 -0
- package/dist/server/control-flow/lazy.js.map +1 -0
- package/dist/server/control-flow/no-hydration.js +2 -0
- package/dist/server/control-flow/no-hydration.js.map +1 -0
- package/dist/server/control-flow/portal.js +2 -0
- package/dist/server/control-flow/portal.js.map +1 -0
- package/dist/server/control-flow/root-errors.js +2 -0
- package/dist/server/control-flow/root-errors.js.map +1 -0
- package/dist/server/control-flow/show.js +2 -0
- package/dist/server/control-flow/show.js.map +1 -0
- package/dist/server/control-flow/suspense-list.js +2 -0
- package/dist/server/control-flow/suspense-list.js.map +1 -0
- package/dist/server/control-flow/suspense.js +2 -0
- package/dist/server/control-flow/suspense.js.map +1 -0
- package/dist/server/control-flow/switch.js +2 -0
- package/dist/server/control-flow/switch.js.map +1 -0
- package/dist/server/derived.js +2 -0
- package/dist/server/derived.js.map +1 -0
- package/dist/server/element.js +2 -0
- package/dist/server/element.js.map +1 -0
- package/dist/server/events.js +2 -0
- package/dist/server/events.js.map +1 -0
- package/dist/server/extend.js +1 -0
- package/dist/server/head/components.js +2 -0
- package/dist/server/head/components.js.map +1 -0
- package/dist/server/head/registry.js +2 -0
- package/dist/server/head/registry.js.map +1 -0
- package/dist/server/head/server-head.js +2 -0
- package/dist/server/head/server-head.js.map +1 -0
- package/dist/server/head/sink.js +2 -0
- package/dist/server/head/sink.js.map +1 -0
- package/dist/server/head/use-head.js +2 -0
- package/dist/server/head/use-head.js.map +1 -0
- package/dist/server/head/validate.js +2 -0
- package/dist/server/head/validate.js.map +1 -0
- package/dist/server/hydration.js +2 -0
- package/dist/server/hydration.js.map +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/insert.js +2 -0
- package/dist/server/insert.js.map +1 -0
- package/dist/server/internal/claim.js +2 -0
- package/dist/server/internal/claim.js.map +1 -0
- package/dist/server/internal/css-units.js +2 -0
- package/dist/server/internal/css-units.js.map +1 -0
- package/dist/server/internal/diagnostics.js +2 -0
- package/dist/server/internal/diagnostics.js.map +1 -0
- package/dist/server/internal/early-events.js +2 -0
- package/dist/server/internal/early-events.js.map +1 -0
- package/dist/server/internal/hydration-hooks.js +2 -0
- package/dist/server/internal/hydration-hooks.js.map +1 -0
- package/dist/server/internal/hydration-scope.js +2 -0
- package/dist/server/internal/hydration-scope.js.map +1 -0
- package/dist/server/internal/names.js +2 -0
- package/dist/server/internal/names.js.map +1 -0
- package/dist/server/internal/portal-context.js +2 -0
- package/dist/server/internal/portal-context.js.map +1 -0
- package/dist/server/internal/react-names.js +2 -0
- package/dist/server/internal/react-names.js.map +1 -0
- package/dist/server/internal/reconcile.js +2 -0
- package/dist/server/internal/reconcile.js.map +1 -0
- package/dist/server/internal/stream-context.js +2 -0
- package/dist/server/internal/stream-context.js.map +1 -0
- package/dist/server/reactive.js +2 -0
- package/dist/server/reactive.js.map +1 -0
- package/dist/server/render.js +2 -0
- package/dist/server/render.js.map +1 -0
- package/dist/server/resource-hints.js +2 -0
- package/dist/server/resource-hints.js.map +1 -0
- package/dist/server/select-value.js +2 -0
- package/dist/server/select-value.js.map +1 -0
- package/dist/server/server/attributes.js +2 -0
- package/dist/server/server/attributes.js.map +1 -0
- package/dist/server/server/class-style.js +2 -0
- package/dist/server/server/class-style.js.map +1 -0
- package/dist/server/server/component.js +2 -0
- package/dist/server/server/component.js.map +1 -0
- package/dist/server/server/derived.js +2 -0
- package/dist/server/server/derived.js.map +1 -0
- package/dist/server/server/element.js +2 -0
- package/dist/server/server/element.js.map +1 -0
- package/dist/server/server/errors.js +2 -0
- package/dist/server/server/errors.js.map +1 -0
- package/dist/server/server/escape.js +2 -0
- package/dist/server/server/escape.js.map +1 -0
- package/dist/server/server/form-controls.js +3 -0
- package/dist/server/server/form-controls.js.map +1 -0
- package/dist/server/server/hydration-script.js +2 -0
- package/dist/server/server/hydration-script.js.map +1 -0
- package/dist/server/server/index.js +1 -0
- package/dist/server/server/node.js +2 -0
- package/dist/server/server/node.js.map +1 -0
- package/dist/server/server/portals.js +2 -0
- package/dist/server/server/portals.js.map +1 -0
- package/dist/server/server/render.js +2 -0
- package/dist/server/server/render.js.map +1 -0
- package/dist/server/server/serialize.js +2 -0
- package/dist/server/server/serialize.js.map +1 -0
- package/dist/server/server/stream.js +2 -0
- package/dist/server/server/stream.js.map +1 -0
- package/dist/server/server.js +1 -0
- package/dist/server/spread.js +2 -0
- package/dist/server/spread.js.map +1 -0
- package/dist/server/template.js +2 -0
- package/dist/server/template.js.map +1 -0
- package/dist/server/view-transition.js +2 -0
- package/dist/server/view-transition.js.map +1 -0
- package/dist/server-dev/attributes.js +195 -0
- package/dist/server-dev/attributes.js.map +1 -0
- package/dist/server-dev/autofocus.js +44 -0
- package/dist/server-dev/autofocus.js.map +1 -0
- package/dist/server-dev/class-style.js +196 -0
- package/dist/server-dev/class-style.js.map +1 -0
- package/dist/server-dev/component.js +41 -0
- package/dist/server-dev/component.js.map +1 -0
- package/dist/server-dev/control-flow/activity.js +40 -0
- package/dist/server-dev/control-flow/activity.js.map +1 -0
- package/dist/server-dev/control-flow/branch.js +103 -0
- package/dist/server-dev/control-flow/branch.js.map +1 -0
- package/dist/server-dev/control-flow/client-only.js +49 -0
- package/dist/server-dev/control-flow/client-only.js.map +1 -0
- package/dist/server-dev/control-flow/dynamic.js +105 -0
- package/dist/server-dev/control-flow/dynamic.js.map +1 -0
- package/dist/server-dev/control-flow/error-boundary.js +114 -0
- package/dist/server-dev/control-flow/error-boundary.js.map +1 -0
- package/dist/server-dev/control-flow/for.js +22 -0
- package/dist/server-dev/control-flow/for.js.map +1 -0
- package/dist/server-dev/control-flow/fragment.js +30 -0
- package/dist/server-dev/control-flow/fragment.js.map +1 -0
- package/dist/server-dev/control-flow/hot-link.js +56 -0
- package/dist/server-dev/control-flow/hot-link.js.map +1 -0
- package/dist/server-dev/control-flow/index-list.js +30 -0
- package/dist/server-dev/control-flow/index-list.js.map +1 -0
- package/dist/server-dev/control-flow/lazy.js +63 -0
- package/dist/server-dev/control-flow/lazy.js.map +1 -0
- package/dist/server-dev/control-flow/no-hydration.js +39 -0
- package/dist/server-dev/control-flow/no-hydration.js.map +1 -0
- package/dist/server-dev/control-flow/portal.js +133 -0
- package/dist/server-dev/control-flow/portal.js.map +1 -0
- package/dist/server-dev/control-flow/root-errors.js +32 -0
- package/dist/server-dev/control-flow/root-errors.js.map +1 -0
- package/dist/server-dev/control-flow/show.js +17 -0
- package/dist/server-dev/control-flow/show.js.map +1 -0
- package/dist/server-dev/control-flow/suspense-list.js +99 -0
- package/dist/server-dev/control-flow/suspense-list.js.map +1 -0
- package/dist/server-dev/control-flow/suspense.js +118 -0
- package/dist/server-dev/control-flow/suspense.js.map +1 -0
- package/dist/server-dev/control-flow/switch.js +89 -0
- package/dist/server-dev/control-flow/switch.js.map +1 -0
- package/dist/server-dev/derived.js +33 -0
- package/dist/server-dev/derived.js.map +1 -0
- package/dist/server-dev/element.js +65 -0
- package/dist/server-dev/element.js.map +1 -0
- package/dist/server-dev/events.js +264 -0
- package/dist/server-dev/events.js.map +1 -0
- package/dist/server-dev/extend.js +12 -0
- package/dist/server-dev/head/components.js +169 -0
- package/dist/server-dev/head/components.js.map +1 -0
- package/dist/server-dev/head/registry.js +67 -0
- package/dist/server-dev/head/registry.js.map +1 -0
- package/dist/server-dev/head/server-head.js +75 -0
- package/dist/server-dev/head/server-head.js.map +1 -0
- package/dist/server-dev/head/sink.js +95 -0
- package/dist/server-dev/head/sink.js.map +1 -0
- package/dist/server-dev/head/use-head.js +83 -0
- package/dist/server-dev/head/use-head.js.map +1 -0
- package/dist/server-dev/head/validate.js +267 -0
- package/dist/server-dev/head/validate.js.map +1 -0
- package/dist/server-dev/hydration.js +119 -0
- package/dist/server-dev/hydration.js.map +1 -0
- package/dist/server-dev/index.js +34 -0
- package/dist/server-dev/insert.js +356 -0
- package/dist/server-dev/insert.js.map +1 -0
- package/dist/server-dev/internal/claim.js +356 -0
- package/dist/server-dev/internal/claim.js.map +1 -0
- package/dist/server-dev/internal/css-units.js +25 -0
- package/dist/server-dev/internal/css-units.js.map +1 -0
- package/dist/server-dev/internal/diagnostics.js +37 -0
- package/dist/server-dev/internal/diagnostics.js.map +1 -0
- package/dist/server-dev/internal/early-events.js +75 -0
- package/dist/server-dev/internal/early-events.js.map +1 -0
- package/dist/server-dev/internal/hydration-hooks.js +26 -0
- package/dist/server-dev/internal/hydration-hooks.js.map +1 -0
- package/dist/server-dev/internal/hydration-scope.js +155 -0
- package/dist/server-dev/internal/hydration-scope.js.map +1 -0
- package/dist/server-dev/internal/names.js +34 -0
- package/dist/server-dev/internal/names.js.map +1 -0
- package/dist/server-dev/internal/portal-context.js +27 -0
- package/dist/server-dev/internal/portal-context.js.map +1 -0
- package/dist/server-dev/internal/react-names.js +115 -0
- package/dist/server-dev/internal/react-names.js.map +1 -0
- package/dist/server-dev/internal/reconcile.js +121 -0
- package/dist/server-dev/internal/reconcile.js.map +1 -0
- package/dist/server-dev/internal/stream-context.js +22 -0
- package/dist/server-dev/internal/stream-context.js.map +1 -0
- package/dist/server-dev/reactive.js +84 -0
- package/dist/server-dev/reactive.js.map +1 -0
- package/dist/server-dev/render.js +51 -0
- package/dist/server-dev/render.js.map +1 -0
- package/dist/server-dev/resource-hints.js +199 -0
- package/dist/server-dev/resource-hints.js.map +1 -0
- package/dist/server-dev/select-value.js +50 -0
- package/dist/server-dev/select-value.js.map +1 -0
- package/dist/server-dev/server/attributes.js +154 -0
- package/dist/server-dev/server/attributes.js.map +1 -0
- package/dist/server-dev/server/class-style.js +172 -0
- package/dist/server-dev/server/class-style.js.map +1 -0
- package/dist/server-dev/server/component.js +71 -0
- package/dist/server-dev/server/component.js.map +1 -0
- package/dist/server-dev/server/derived.js +25 -0
- package/dist/server-dev/server/derived.js.map +1 -0
- package/dist/server-dev/server/element.js +215 -0
- package/dist/server-dev/server/element.js.map +1 -0
- package/dist/server-dev/server/errors.js +25 -0
- package/dist/server-dev/server/errors.js.map +1 -0
- package/dist/server-dev/server/escape.js +118 -0
- package/dist/server-dev/server/escape.js.map +1 -0
- package/dist/server-dev/server/form-controls.js +192 -0
- package/dist/server-dev/server/form-controls.js.map +1 -0
- package/dist/server-dev/server/hydration-script.js +58 -0
- package/dist/server-dev/server/hydration-script.js.map +1 -0
- package/dist/server-dev/server/index.js +16 -0
- package/dist/server-dev/server/node.js +20 -0
- package/dist/server-dev/server/node.js.map +1 -0
- package/dist/server-dev/server/portals.js +98 -0
- package/dist/server-dev/server/portals.js.map +1 -0
- package/dist/server-dev/server/render.js +255 -0
- package/dist/server-dev/server/render.js.map +1 -0
- package/dist/server-dev/server/serialize.js +314 -0
- package/dist/server-dev/server/serialize.js.map +1 -0
- package/dist/server-dev/server/stream.js +234 -0
- package/dist/server-dev/server/stream.js.map +1 -0
- package/dist/server-dev/server.js +16 -0
- package/dist/server-dev/spread.js +295 -0
- package/dist/server-dev/spread.js.map +1 -0
- package/dist/server-dev/template.js +119 -0
- package/dist/server-dev/template.js.map +1 -0
- package/dist/server-dev/view-transition.js +89 -0
- package/dist/server-dev/view-transition.js.map +1 -0
- package/package.json +136 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branch.js","names":["sameChoice","a","b","createBranches","latest","state","swap","owner","getOwner","selection","useMemo","next","select","live","accessorFor","owned","current","untrack","produce","choice","fallback","body","eager","callback","transitionHooks","result","createRoot","onCleanup"],"sources":["../../../src/control-flow/branch.ts"],"sourcesContent":["import { type Accessor, createRoot, getOwner, onCleanup, untrack, useMemo } from \"@shadow-js/core\";\nimport {\n type SlotBranch,\n type SlotOwned,\n type SlotState,\n type SlotSwap,\n transitionHooks,\n} from \"@shadow-js/core/extend\";\n\n/**\n * Branch index meaning \"no branch is selected\": the fallback is shown.\n * @internal\n */\nexport const FALLBACK = -1;\n\n/**\n * One selection made by a control-flow component.\n *\n * - `index` names the chosen branch, or {@link FALLBACK}.\n * - `keyed` and `when` decide whether a change of selection rebuilds the branch.\n * - `read` reads the condition reactively; the callback child's accessor argument uses it.\n * - `body` reads the branch's children getter. It is read tracked: a compiled `children` getter\n * that is a plain reactive expression (`{count()}`) must update the output. Creating child JSX\n * reads nothing here, because components and bindings track inside their own computations.\n *\n * @internal\n * @since 1.0.0\n */\nexport interface Choice {\n /** The chosen branch: a zero-based position, or {@link FALLBACK} when no branch is chosen. */\n readonly index: number;\n /** True when a change of `when` (by identity) rebuilds the branch even if `index` is the same. */\n readonly keyed: boolean;\n /** The value of the condition at selection time; a keyed callback child receives it. */\n readonly when: unknown;\n /** Reads the current value of the condition, tracked; backs the callback child's accessor. */\n readonly read: () => unknown;\n /** Reads the chosen branch's children (content, an accessor, or a callback), tracked. */\n readonly body: () => unknown;\n}\n\n/** Bookkeeping for the branch that is on screen. */\ntype Rendered = SlotOwned;\n\n/** A branch on screen, or one a transition builds (see the transition layer in core's concurrency.ts). */\ntype Live = SlotBranch<Choice>;\n\n/**\n * Whether two selections describe the same rendered output. Non-keyed branches only care about\n * which branch is chosen, which is the same as comparing truthiness of the condition. Keyed\n * branches also rebuild when the condition's identity changes. The fallback never rebuilds.\n */\nfunction sameChoice(a: Choice, b: Choice): boolean {\n if (a.index !== b.index) return false;\n return a.index === FALLBACK || !a.keyed || a.when === b.when;\n}\n\n/**\n * Builds the accessor behind `Show` and `Switch`. The selection memo decides which branch is chosen;\n * the output memo commits it.\n *\n * Ordinary changes build the branch inside the output memo: the memo's teardown removes the previous\n * branch first. A change made during a transition, while a branch is on screen, is handled by the\n * transition layer (core's `slotSwap`, reached through `transitionHooks`), created by the first such change: it builds the\n * new branch under a hold and commits it once its reads have settled. Until then the shown branch stays\n * on screen, its DOM untouched, and nothing is built twice. Apps that never change a shown branch in a\n * transition never create that layer.\n *\n * Teardown ordering: the owner of a branch is marked `disposing` before it is torn down, so a cleanup\n * that reads the callback's accessor learns that the branch is going away and gets the last truthy\n * value instead of a stale-accessor error.\n *\n * @param name Component name used in diagnostics.\n * @param select Tracked selection; runs inside the selection memo.\n * @param fallback Reads the fallback lazily, untracked, only when it is shown.\n * @returns The output accessor.\n * @throws TypeError (production message `SHADOW_STALE_ACCESSOR`) from the accessor handed to a\n * callback child, when it is read after its branch was replaced.\n * @internal\n * @since 1.0.0\n */\nexport function createBranches(\n name: string,\n select: () => Choice,\n fallback: () => unknown,\n): Accessor<unknown> {\n /** Selection computed most recently; its `read` is always current, unlike the held value. */\n let latest: Choice | undefined;\n /** The branch on screen, and what the output last returned. The transition layer reads and writes it. */\n const state: SlotState<Choice> = { live: undefined };\n /** The transition layer, created by the first transition that replaces the branch on screen. */\n let swap: SlotSwap<Choice> | undefined;\n /** The slot's owner: the transition layer's holder for the branches it builds lives under it. */\n const owner = getOwner();\n\n const pick = (): Choice => {\n const next = select();\n latest = next;\n const live: Live | undefined = state.live;\n if (live !== undefined && next.index === live.owned.index) live.owned.value = next.when;\n return next;\n };\n const selection = useMemo<Choice>(pick, { equals: sameChoice });\n\n const accessorFor = (owned: Rendered): (() => unknown) => {\n return () => {\n if (owned.disposing) return owned.value;\n const current = untrack(selection);\n if (current.index !== owned.index) {\n throw new TypeError(\n __DEV__\n ? `ShadowJS ${name}: stale accessor. The branch was replaced; read the accessor only while its condition is truthy.`\n : \"SHADOW_STALE_ACCESSOR\",\n );\n }\n return (latest ?? current).read();\n };\n };\n\n /**\n * The value a branch (or the fallback) produces. `eager` evaluates a zero-argument accessor now (a\n * transition build needs to see whether a read was held); otherwise it is evaluated when rendered.\n */\n const produce = (choice: Choice, owned: Rendered, eager: boolean): unknown => {\n if (choice.index === FALLBACK) return untrack(fallback);\n const body = choice.body();\n if (typeof body !== \"function\") return body;\n // A zero-argument function is an accessor. Returned as it is, the renderer would call it in an\n // effect outside this branch, so an error it throws would escape the boundary around the Show\n // (STATUS: ErrorBoundary does not catch a Show function child). A memo owned here evaluates it\n // inside the branch, where the nearest error handler applies.\n if (body.length === 0) {\n // Lazy outside a transition: the parent evaluates it when it renders, so a deep chain of\n // branches is built in that render rather than inside this one.\n return useMemo<unknown>(() => (body as () => unknown)(), {\n allowWrites: true,\n lazy: !eager,\n });\n }\n const callback = body as (value: unknown) => unknown;\n return untrack(() => callback(choice.keyed ? choice.when : accessorFor(owned)));\n };\n\n return useMemo<unknown>(\n () => {\n const choice = selection();\n if (swap === undefined && state.live !== undefined) {\n swap = transitionHooks()?.slotSwap(state, produce, sameChoice, owner);\n }\n if (swap?.step(choice)) return state.live?.result;\n\n // The usual path: the previous branch was torn down by this memo (its teardown marked it disposing;\n // the flag is cleared again, so a stale accessor throws). Build the next one here.\n if (state.live !== undefined) state.live.owned.disposing = false;\n state.live = undefined;\n const owned: Rendered = { index: choice.index, value: choice.when, disposing: false };\n const result = produce(choice, owned, false);\n // Created last, so it is the newest child: the memo's teardown marks the branch first.\n createRoot(() => {\n onCleanup(() => {\n owned.disposing = true;\n });\n });\n state.live = { choice, owned, result };\n return result;\n },\n { allowWrites: true },\n );\n}\n"],"mappings":"A,6JAoDA,SAASA,EAAW,EAAW,EAAoB,CAEjD,OADIC,EAAE,QAAUC,EAAE,MACXD,EAAE,QAAA,IAAsB,CAACA,EAAE,OAASA,EAAE,OAASC,EAAE,KADxB,EAElC,CA0BA,SAAgBC,EACd,EACA,EACA,EACmB,CAEnB,IAAIC,EAEEC,EAA2B,CAAE,KAAM,IAAA,EAAU,EAE/CC,EAEEC,EAAQC,EAAS,EASjBC,EAAYC,MAPS,CACzB,IAAMC,EAAOC,EAAO,EACpB,EAASD,EACT,IAAME,EAAyBR,EAAM,KAErC,OADIQ,IAAS,IAAA,IAAaF,EAAK,QAAUE,EAAK,MAAM,QAAO,EAAK,MAAM,MAAQF,EAAK,MAC5EA,CACT,EACwC,CAAE,OAAQX,CAAW,CAAC,EAExDc,EAAe,OACN,CACX,GAAIC,EAAM,UAAW,OAAOA,EAAM,MAClC,IAAMC,EAAUC,EAAQR,CAAS,EACjC,GAAIO,EAAQ,QAAUD,EAAM,MAC1B,MAAU,UAGJ,uBACN,EAEF,OAAQX,GAAUY,EAAA,CAAS,KAAK,CAClC,EAOIE,GAAW,EAAgB,EAAiB,IAA4B,CAC5E,GAAIC,EAAO,QAAA,GAAoB,OAAOF,EAAQG,CAAQ,EACtD,IAAMC,EAAOF,EAAO,KAAK,EACzB,GAAI,OAAOE,GAAS,WAAY,OAAOA,EAKvC,GAAIA,EAAK,SAAW,EAGlB,OAAOX,MAAwBW,EAAuB,EAAG,CACvD,YAAa,GACb,KAAM,CAACC,CACT,CAAC,EAEH,IAAMC,EAAWF,EACjB,OAAOJ,MAAcM,EAASJ,EAAO,MAAQA,EAAO,KAAOL,EAAYC,CAAK,CAAC,CAAC,CAChF,EAEA,OAAOL,MACC,CACJ,IAAMS,EAASV,EAAU,EAIzB,GAHIH,IAAS,IAAA,IAAaD,EAAM,OAAS,IAAA,KACvC,EAAOmB,EAAgB,CAAC,EAAE,SAASnB,EAAOa,EAASlB,EAAYO,CAAK,GAElED,GAAM,KAAKa,CAAM,EAAG,OAAOd,EAAM,MAAM,OAIvCA,EAAM,OAAS,IAAA,KAAW,EAAM,KAAK,MAAM,UAAY,IAC3D,EAAM,KAAO,IAAA,GACb,IAAMU,EAAkB,CAAE,MAAOI,EAAO,MAAO,MAAOA,EAAO,KAAM,UAAW,EAAM,EAC9EM,EAASP,EAAQC,EAAQJ,EAAO,EAAK,EAQ3C,OANAW,MAAiB,CACfC,MAAgB,CACd,EAAM,UAAY,EACpB,CAAC,CACH,CAAC,EACD,EAAM,KAAO,CAAE,SAAQ,QAAO,QAAO,EAC9BF,CACT,EACA,CAAE,YAAa,EAAK,CACtB,CACF,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Show as e}from"./show.js";import{onMount as t,useSignal as n}from"@shadow-js/core";function r(r){let[i,a]=n(!1);return t(()=>{a(!0)}),e({get when(){return i()},get fallback(){return r.fallback},get children(){return r.children}})}export{r as ClientOnly};
|
|
2
|
+
//# sourceMappingURL=client-only.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-only.js","names":["ClientOnly","mounted","setMounted","useSignal","onMount","Show","props"],"sources":["../../../src/control-flow/client-only.ts"],"sourcesContent":["import { type Accessor, onMount, useSignal } from \"@shadow-js/core\";\nimport type { JsxChild } from \"../jsx/types\";\nimport { Show } from \"./show\";\n\n/**\n * Props of {@link ClientOnly}.\n * @since 1.0.0\n */\nexport interface ClientOnlyProps {\n /**\n * Rendered on the server and while the page hydrates, until the browser has mounted.\n * @default undefined (nothing is rendered until mount)\n */\n readonly fallback?: JsxChild;\n /**\n * Rendered in the browser only, after mount.\n * @default undefined (nothing is rendered after mount either)\n */\n readonly children?: JsxChild | (() => unknown);\n}\n\n/**\n * Renders `children` in the browser only. The server (and the first client pass, which must match\n * the server's markup) renders `fallback`; once mounted, the children replace it. Use it for\n * content that depends on browser state: `window`, `localStorage`, media queries, charts.\n *\n * @param props See {@link ClientOnlyProps}.\n * @returns An accessor of the current content: the fallback until mount, then the children.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { ClientOnly } from \"@shadow-js/web\";\n *\n * function Chart(props: { data: number[] }) {\n * return <canvas data-points={props.data.length} />;\n * }\n *\n * function Report() {\n * const [rows] = useSignal([1, 2, 3]);\n * return (\n * <ClientOnly fallback={<p>Loading chart...</p>}>\n * <Chart data={rows()} />\n * </ClientOnly>\n * );\n * }\n * @see Show\n * @since 1.0.0\n */\nexport function ClientOnly(props: ClientOnlyProps): Accessor<unknown> {\n const [mounted, setMounted] = useSignal(false);\n // Never runs on the server, so the server always renders the fallback.\n onMount(() => {\n setMounted(true);\n });\n return Show({\n get when() {\n return mounted();\n },\n get fallback() {\n return props.fallback;\n },\n get children() {\n return props.children;\n },\n });\n}\n"],"mappings":"A,0FA+CA,SAAgBA,EAAW,EAA2C,CACpE,GAAM,CAACC,EAASC,GAAcC,EAAU,EAAK,EAK7C,OAHAC,MAAc,CACZF,EAAW,EAAI,CACjB,CAAC,EACMG,EAAK,CACV,IAAI,MAAO,CACT,OAAOJ,EAAQ,CACjB,EACA,IAAI,UAAW,CACb,OAAOK,EAAM,QACf,EACA,IAAI,UAAW,CACb,OAAOA,EAAM,QACf,CACF,CAAC,CACH,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import"../internal/names.js";import{nextKey as e}from"../internal/hydration-scope.js";import{createComponent as t}from"../component.js";import{claims as n}from"../internal/hydration-hooks.js";import{bindRegion as r,createRegion as i}from"../insert.js";import{spread as a}from"../spread.js";import{mergeProps as o,splitProps as s,untrack as c,useMemo as l}from"@shadow-js/core";const u=/* @__PURE__ */ new Set([`svg`,`g`,`path`,`circle`,`ellipse`,`line`,`polygon`,`polyline`,`rect`,`text`,`tspan`,`textpath`,`defs`,`use`,`symbol`,`marker`,`clippath`,`mask`,`pattern`,`lineargradient`,`radialgradient`,`stop`,`filter`]),d=/^[a-z][a-z0-9-]*$/i,f=/* @__PURE__ */ new Set([`script`]);function p(t,o){let s=t.toLowerCase();if(!d.test(t)||f.has(s))throw TypeError(`SHADOW_DYNAMIC_TAG`);let c=u.has(s),l=n.current.claimElement(e())??(c?document.createElementNS(`http://www.w3.org/2000/svg`,t):document.createElement(t));a(l,o,c,!0);let p=i(l,null,n.current.takeRegion(l,null));return r(p,()=>o.children),l}function m(e,n){if(!e)return null;if(typeof e==`string`)return p(e,n);if(typeof e==`function`)return t(e,n);throw TypeError(`SHADOW_DYNAMIC_COMPONENT`)}function h(e){let[,t]=s(e,[`component`]);return l(()=>{let n=e.component;return c(()=>m(n,t))},{allowWrites:!0})}function g(e,t={}){return h(o({get component(){return e()}},t))}export{h as Dynamic,g as createDynamic};
|
|
2
|
+
//# sourceMappingURL=dynamic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic.js","names":["SVG_TAGS","TAG_PATTERN","DENIED_TAGS","buildElement","lower","tag","svg","el","claims","nextKey","spread","props","region","createRegion","bindRegion","buildTarget","target","createComponent","Dynamic","rest","splitProps","useMemo","untrack","createDynamic","mergeProps","component"],"sources":["../../../src/control-flow/dynamic.ts"],"sourcesContent":["import { mergeProps, splitProps, untrack, useMemo } from \"@shadow-js/core\";\nimport { createComponent } from \"../component\";\nimport { bindRegion, claims, createRegion, nextKey, SVG_NS } from \"../extend\";\nimport { ssrElement, ssrRaw } from \"../server/element\";\nimport { spread } from \"../spread\";\n\n/**\n * A component function or a tag name, as {@link Dynamic} accepts it. The props of a function are\n * checked by the caller.\n * @since 1.0.0\n */\nexport type DynamicComponent = string | ((props: never) => unknown);\n\n/**\n * Everything `component` may be: a component, a tag name, or `undefined`, `null` or `false`, which\n * render nothing.\n * @since 1.0.0\n */\nexport type DynamicTarget = DynamicComponent | undefined | null | false;\n\n/**\n * Props of {@link Dynamic}: `component` plus the props of whatever it renders. Every other prop\n * passes through, reactive getters included.\n * @since 1.0.0\n */\nexport interface DynamicProps<C extends DynamicTarget = DynamicTarget> {\n /** The component to render, a tag name, or a falsy value for nothing. */\n readonly component: C;\n /** Any other prop is passed to the rendered component or set on the element, still reactive. */\n readonly [prop: string]: unknown;\n}\n\n/** Tag names that take the SVG namespace. Anything else is HTML. */\nconst SVG_TAGS: ReadonlySet<string> = new Set([\n \"svg\",\n \"g\",\n \"path\",\n \"circle\",\n \"ellipse\",\n \"line\",\n \"polygon\",\n \"polyline\",\n \"rect\",\n \"text\",\n \"tspan\",\n \"textpath\",\n \"defs\",\n \"use\",\n \"symbol\",\n \"marker\",\n \"clippath\",\n \"mask\",\n \"pattern\",\n \"lineargradient\",\n \"radialgradient\",\n \"stop\",\n \"filter\",\n]);\n\n/** Shape of a tag name: a letter, then letters, digits or dashes. Anything else is refused. */\nconst TAG_PATTERN = /^[a-z][a-z0-9-]*$/i;\n\n/** Tags refused in any letter case: a script would bypass CSP nonces and Trusted Types. */\nconst DENIED_TAGS: ReadonlySet<string> = new Set([\"script\"]);\n\n/**\n * Creates an element for a validated tag name and applies the props to it, children included.\n * The namespace comes from the tag: SVG-only names get the SVG namespace, the rest are HTML.\n * On the server it renders the element as markup (with the hydration key and the children region\n * the client adopts); while hydrating it claims that element instead of creating one.\n */\nfunction buildElement(tag: string, props: object): unknown {\n const lower = tag.toLowerCase();\n if (!TAG_PATTERN.test(tag) || DENIED_TAGS.has(lower)) {\n throw new TypeError(__DEV__ ? \"ShadowJS Dynamic: invalid tag\" : \"SHADOW_DYNAMIC_TAG\");\n }\n if (__SERVER__) {\n // The children are read lazily, after `ssrElement` took the element's hydration key: the client\n // claims the element first and builds its children second, so the keys must be drawn in that\n // order here too, or a component inside the element and every sibling after it would miss.\n return ssrElement(\n tag,\n props,\n () => {\n const { children } = props as { children?: unknown };\n return children === undefined\n ? undefined\n : [ssrRaw(\"<!--[-->\"), children, ssrRaw(\"<!--]-->\")];\n },\n true,\n );\n }\n const svg = SVG_TAGS.has(lower);\n const claimed = claims.current.claimElement(nextKey());\n const el = claimed ?? (svg ? document.createElementNS(SVG_NS, tag) : document.createElement(tag));\n // Attributes through spread; children through insert, which adopts the server's children region.\n spread(el, props, svg, true);\n const region = createRegion(el, null, claims.current.takeRegion(el, null));\n bindRegion(region, () => (props as { children?: unknown }).children);\n return el;\n}\n\n/**\n * Renders one value of `component`: nothing for a falsy value, an element for a tag name, the\n * component's result for a function. Anything else is a TypeError.\n */\nfunction buildTarget(target: unknown, props: object): unknown {\n if (!target) return null;\n if (typeof target === \"string\") return buildElement(target, props);\n if (typeof target === \"function\") {\n return createComponent(target as (props: object) => unknown, props);\n }\n throw new TypeError(\n __DEV__\n ? \"ShadowJS Dynamic: component must be a string, a function, or a falsy value.\"\n : \"SHADOW_DYNAMIC_COMPONENT\",\n );\n}\n\n/**\n * Renders a component function or an element chosen by a tag name, and re-renders when\n * `component` changes. Only `component` is tracked: the rest of the props are passed through\n * reactive, so changing them updates the rendered output without rebuilding it. Swapping\n * `component` disposes the old subtree, cleanups included, and builds the new one once. A falsy\n * `component` renders nothing.\n *\n * Tag names are checked against `^[a-z][a-z0-9-]*$` (case-insensitive) and `script` is refused, so\n * data-driven tags cannot inject markup. SVG-only names (`circle`, `path`, `svg`, ...) are created\n * in the SVG namespace.\n *\n * @param props `component` and the props of what it renders.\n * @returns An accessor of the rendered output, to be inserted by the caller.\n * @throws TypeError for an invalid tag name or a component that is neither a string nor a function\n * (at read time, which is when the caller inserts it).\n * @example\n * import { createRoot, useSignal } from \"@shadow-js/core\";\n * import { Dynamic, insert } from \"@shadow-js/web\";\n *\n * const parent = document.createElement(\"div\");\n * createRoot(() => {\n * const [level] = useSignal(1);\n * insert(\n * parent,\n * Dynamic({\n * get component() {\n * return level() === 1 ? \"h1\" : \"h2\";\n * },\n * children: \"Title\",\n * }),\n * );\n * });\n * @see createDynamic\n * @since 1.0.0\n */\nexport function Dynamic<C extends DynamicTarget>(props: DynamicProps<C>): () => unknown {\n const [, rest] = splitProps(props, [\"component\"]);\n // The component is built inside this memo, so its setup (or a ref, or a directive) may write signals.\n return useMemo(\n (): unknown => {\n const target: unknown = props.component;\n return untrack(() => buildTarget(target, rest));\n },\n { allowWrites: true },\n );\n}\n\n/**\n * Function form of {@link Dynamic}, for code that is not JSX: renders what `component()` returns (a\n * component, a tag name or a falsy value) with `props`, and follows it when it changes.\n *\n * @param component Accessor of the target.\n * @param props The props of what it renders (reactive getters stay reactive).\n * @returns An accessor of the rendered output.\n * @example\n * import { createRoot, useSignal } from \"@shadow-js/core\";\n * import { createDynamic, insert } from \"@shadow-js/web\";\n *\n * const parent = document.createElement(\"div\");\n * createRoot(() => {\n * const [level] = useSignal(1);\n * insert(parent, createDynamic(() => (level() === 1 ? \"h1\" : \"h2\"), { children: \"Title\" }));\n * });\n * @see Dynamic\n * @since 1.0.0\n */\nexport function createDynamic<C extends DynamicTarget>(\n component: () => C,\n props: object = {},\n): () => unknown {\n return Dynamic(\n mergeProps(\n {\n get component(): C {\n return component();\n },\n },\n props,\n ) as DynamicProps<C>,\n );\n}\n"],"mappings":"A,yXAiCA,MAAMA,kBAAgC,IAAI,IAAI,CAC5C,MACA,IACA,OACA,SACA,UACA,OACA,UACA,WACA,OACA,OACA,QACA,WACA,OACA,MACA,SACA,SACA,WACA,OACA,UACA,iBACA,iBACA,OACA,QACF,CAAC,EAGKC,EAAc,qBAGdC,kBAAmC,IAAI,IAAI,CAAC,QAAQ,CAAC,EAQ3D,SAASC,EAAa,EAAa,EAAwB,CACzD,IAAMC,EAAQC,EAAI,YAAY,EAC9B,GAAI,CAACJ,EAAY,KAAKI,CAAG,GAAKH,EAAY,IAAIE,CAAK,EACjD,MAAU,UAAsD,oBAAoB,EAkBtF,IAAME,EAAMN,EAAS,IAAII,CAAK,EAExBG,EADUC,EAAO,QAAQ,aAAaC,EAAQ,CACnC,IAAMH,EAAM,SAAS,gBAAA,6BAAwBD,CAAG,EAAI,SAAS,cAAcA,CAAG,GAE/FK,EAAOH,EAAII,EAAOL,EAAK,EAAI,EAC3B,IAAMM,EAASC,EAAaN,EAAI,KAAMC,EAAO,QAAQ,WAAWD,EAAI,IAAI,CAAC,EAEzE,OADAO,EAAWF,MAAeD,EAAiC,QAAQ,EAC5DJ,CACT,CAMA,SAASQ,EAAY,EAAiB,EAAwB,CAC5D,GAAI,CAACC,EAAQ,OAAO,KACpB,GAAI,OAAOA,GAAW,SAAU,OAAOb,EAAaa,EAAQL,CAAK,EACjE,GAAI,OAAOK,GAAW,WACpB,OAAOC,EAAgBD,EAAsCL,CAAK,EAEpE,MAAU,UAGJ,0BACN,CACF,CAqCA,SAAgBO,EAAiC,EAAuC,CACtF,GAAM,EAAGC,GAAQC,EAAWT,EAAO,CAAC,WAAW,CAAC,EAEhD,OAAOU,MACU,CACb,IAAML,EAAkBL,EAAM,UAC9B,OAAOW,MAAcP,EAAYC,EAAQG,CAAI,CAAC,CAChD,EACA,CAAE,YAAa,EAAK,CACtB,CACF,CAqBA,SAAgBI,EACd,EACA,EAAgB,CAAC,EACF,CACf,OAAOL,EACLM,EACE,CACE,IAAI,WAAe,CACjB,OAAOC,EAAU,CACnB,CACF,EACAd,CACF,CACF,CACF,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{currentScope as e,withScope as t}from"../internal/hydration-scope.js";import{rootErrorsOf as n}from"./root-errors.js";import{catchError as r,createRoot as i,getOwner as a,onCleanup as o,untrack as s,useMemo as c,useSignal as l}from"@shadow-js/core";import{createSignalNode as u,handleError as d,readSignal as f,writeSignal as p}from"@shadow-js/core/extend";function m(m){let h=u(void 0,Object.is),g=a(),_=n(g),v=e(),y=v===null?null:{id:v.id,count:v.count,resources:v.resources},b=()=>f(h),x=e=>{p(h,e,{allowInMemo:!0})},[S,C]=l(0,{equals:!1}),w=!0,T=!1,E,D=()=>{w&&(x(void 0),C(e=>e+1))},O=e=>{w&&(_?.onCaughtError?.(e),T?E===void 0&&(E={error:e}):x({error:e}))},k=()=>{let e=E;return E=void 0,e},A=e=>{let t=m.fallback;if(typeof t!=`function`)return t;try{return s(()=>t(e,D))}catch(e){d(e,g);return}},j=()=>{T=!0;try{S();let e=b()??k();if(e!==void 0)return A(e.error);let t=i(e=>({dispose:e,value:r(()=>s(()=>m.children),O)})),n=k();return n===void 0?t.value:(t.dispose(),A(n.error))}finally{i(()=>{o(()=>{T=!0})}),T=!1}},M=c(()=>y===null?j():t({...y},j),{allowWrites:!0});return i(()=>{o(()=>{w=!1})}),M}export{m as ErrorBoundary};
|
|
2
|
+
//# sourceMappingURL=error-boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-boundary.js","names":["ErrorBoundary","failureCell","createSignalNode","parentOwner","getOwner","roots","rootErrorsOf","live","currentScope","origin","failure","readSignal","setFailure","writeSignal","next","version","setVersion","useSignal","alive","busy","pending","reset","count","report","error","takePending","captured","fallbackFor","fallback","props","untrack","thrown","handleError","build","current","scope","createRoot","catchError","creation","onCleanup","body","useMemo","withScope"],"sources":["../../../src/control-flow/error-boundary.ts"],"sourcesContent":["import {\n type Accessor,\n catchError,\n createRoot,\n getOwner,\n onCleanup,\n untrack,\n useMemo,\n useSignal,\n} from \"@shadow-js/core\";\nimport { createSignalNode, handleError, readSignal, writeSignal } from \"@shadow-js/core/extend\";\nimport { currentScope, type HydrationScope, withScope } from \"../extend\";\nimport type { JsxChild } from \"../jsx/types\";\nimport { attachHotModules, createHotLink, type HotLink } from \"./hot-link\";\nimport { rootErrorsOf } from \"./root-errors\";\n\n/**\n * Props of {@link ErrorBoundary}.\n * @since 1.0.0\n */\nexport interface ErrorBoundaryProps {\n /**\n * Shown after an error. A function is called untracked as `(error, reset)`; any other value is\n * shown as is.\n */\n readonly fallback: JsxChild | ((error: unknown, reset: () => void) => unknown);\n /**\n * The protected content, read untracked when the children are built.\n * @default undefined (nothing is protected; the boundary renders nothing)\n */\n readonly children?: JsxChild | (() => unknown);\n}\n\n/**\n * {@link ErrorBoundaryProps} with untyped members, for code that forwards a fallback or children it\n * does not know the shape of.\n * @since 1.0.0\n */\nexport interface ErrorBoundaryLooseProps {\n /** Shown after an error; the same contract as {@link ErrorBoundaryProps.fallback}. */\n readonly fallback: unknown;\n /**\n * The protected content; the same contract as {@link ErrorBoundaryProps.children}.\n * @default undefined (nothing is protected; the boundary renders nothing)\n */\n readonly children?: unknown;\n}\n\n/** A caught error, wrapped so that any thrown value (including `undefined`) is representable. */\ninterface Failure {\n readonly error: unknown;\n}\n\n/**\n * Renders `children`. If they throw while being created, or any effect, memo or cleanup inside\n * them throws later, the children are disposed and `fallback` is rendered instead. A function\n * fallback receives the error and a `reset` that rebuilds the children from scratch.\n *\n * Errors raised while the boundary is building or tearing down its children are captured and\n * never write a signal, because writing inside a memo is an error. Late errors write the failure\n * signal, which re-runs the boundary. After the boundary is disposed, late errors are dropped.\n * Errors thrown by the fallback are not caught by this boundary; they reach the parent.\n *\n * @param props See {@link ErrorBoundaryProps}.\n * @returns An accessor of the current content (children or fallback).\n * @throws Nothing itself. An error from the children is shown through `fallback`, and an error\n * thrown by a function `fallback` goes to the enclosing boundary or the root's error handler.\n * @example\n * import { ErrorBoundary } from \"@shadow-js/web\";\n *\n * function Dashboard() {\n * return <p>Dashboard</p>;\n * }\n *\n * function Page() {\n * return (\n * <ErrorBoundary\n * fallback={(error, reset) => (\n * <button onClick={reset}>Retry after: {String(error)}</button>\n * )}\n * >\n * <Dashboard />\n * </ErrorBoundary>\n * );\n * }\n * @see Suspense\n * @since 1.0.0\n */\nexport function ErrorBoundary(props: ErrorBoundaryProps): Accessor<unknown>;\nexport function ErrorBoundary(props: ErrorBoundaryLooseProps): Accessor<unknown>;\nexport function ErrorBoundary(props: ErrorBoundaryLooseProps): Accessor<unknown> {\n // An extension-API cell: a failure is boundary state, written from places a plain write refuses\n // (a sibling boundary's fallback throwing while its memo computes).\n const failureCell = createSignalNode<Failure | undefined>(undefined, Object.is);\n /** Where an error of this boundary's own fallback goes: the boundary that encloses it. */\n const parentOwner = getOwner();\n // The root's reporters (render/hydrate options): an error this boundary takes is reported to them.\n const roots = rootErrorsOf(parentOwner);\n /** The hydration scope at creation (a copy of its counts), or null outside a hydration or server render. */\n const live = currentScope();\n const origin: HydrationScope | null =\n live === null ? null : { id: live.id, count: live.count, resources: live.resources };\n const failure = (): Failure | undefined => readSignal(failureCell);\n const setFailure = (next: Failure | undefined): void => {\n writeSignal(failureCell, next, { allowInMemo: true });\n };\n /** Bumped by reset(): forces a rebuild even when no failure was recorded. */\n const [version, setVersion] = useSignal(0, { equals: false });\n /** False once the boundary's owner is disposed. */\n let alive = true;\n /** True while the body memo is building or tearing down children; errors are captured then. */\n let busy = false;\n /** An error captured while busy, consumed by the next body computation. */\n let pending: Failure | undefined;\n\n const reset = (): void => {\n if (!alive) return;\n setFailure(undefined);\n setVersion((count) => count + 1);\n };\n\n /**\n * Dev only: the modules the children were built from. While the fallback is shown, a hot update of one of\n * them resets the boundary, so the edit that fixes the error shows the children without a retry.\n */\n const hot: HotLink | undefined = __DEV__\n ? createHotLink(() => {\n reset();\n })\n : undefined;\n\n const report = (error: unknown): void => {\n if (!alive) return;\n roots?.onCaughtError?.(error);\n if (busy) {\n if (pending === undefined) pending = { error };\n return;\n }\n setFailure({ error });\n };\n\n /** Returns the captured error and clears it. A function, so TypeScript does not narrow the variable. */\n const takePending = (): Failure | undefined => {\n const captured = pending;\n pending = undefined;\n return captured;\n };\n\n const fallbackFor = (error: unknown): unknown => {\n const fallback = props.fallback;\n if (typeof fallback !== \"function\") return fallback;\n try {\n return untrack(() =>\n (fallback as (error: unknown, reset: () => void) => unknown)(error, reset),\n );\n } catch (thrown) {\n // A failing fallback is not this boundary's business: hand it to the enclosing boundary now.\n // Left to the memo it would only surface when a consumer outside that boundary reads it.\n handleError(thrown, parentOwner);\n return undefined;\n }\n };\n\n /** Builds the children or the fallback, as the current failure state says. */\n const build = (): unknown => {\n busy = true;\n try {\n version();\n const current = failure() ?? takePending();\n if (current !== undefined) {\n hot?.arm();\n return fallbackFor(current.error);\n }\n\n hot?.modules.clear();\n const scope = createRoot((dispose) => {\n if (hot !== undefined) attachHotModules(hot.modules);\n return {\n dispose,\n value: catchError(() => untrack(() => props.children), report),\n };\n });\n const creation = takePending();\n if (creation !== undefined) {\n scope.dispose();\n hot?.arm();\n return fallbackFor(creation.error);\n }\n hot?.disarm();\n return scope.value;\n } finally {\n // Newest child of the body memo: its cleanup marks the teardown before any child cleanup runs.\n createRoot(() => {\n onCleanup(() => {\n busy = true;\n });\n });\n busy = false;\n }\n // Children and the fallback are built here; their setup may write signals.\n };\n // Every build starts from the hydration scope the boundary was created in (a copy, so the count\n // is the same each time). A rebuild during a hydration pass then numbers its templates as the\n // first build did, so it claims the server's elements instead of missing keys.\n const body = useMemo<unknown>(\n () => (origin === null ? build() : withScope({ ...origin }, build)),\n { allowWrites: true },\n );\n\n // Created after the body memo, so it is the newest child of the owner and is disposed first.\n createRoot(() => {\n onCleanup(() => {\n alive = false;\n hot?.disarm();\n });\n });\n return body;\n}\n"],"mappings":"A,4WA0FA,SAAgBA,EAAc,EAAmD,CAG/E,IAAMC,EAAcC,EAAsC,IAAA,GAAW,OAAO,EAAE,EAExEC,EAAcC,EAAS,EAEvBC,EAAQC,EAAaH,CAAW,EAEhCI,EAAOC,EAAa,EACpBC,EACJF,IAAS,KAAO,KAAO,CAAE,GAAIA,EAAK,GAAI,MAAOA,EAAK,MAAO,UAAWA,EAAK,SAAU,EAC/EG,MAAqCC,EAAWV,CAAW,EAC3DW,EAAc,GAAoC,CACtDC,EAAYZ,EAAaa,EAAM,CAAE,YAAa,EAAK,CAAC,CACtD,EAEM,CAACC,EAASC,GAAcC,EAAU,EAAG,CAAE,OAAQ,EAAM,CAAC,EAExDC,EAAQ,GAERC,EAAO,GAEPC,EAEEC,MAAoB,CACnBH,IACLN,EAAW,IAAA,EAAS,EACpBI,EAAY,GAAUM,EAAQ,CAAC,EACjC,EAYMC,EAAU,GAAyB,CAClCL,IACLb,GAAO,gBAAgBmB,CAAK,EACxBL,EACEC,IAAY,IAAA,KAAW,EAAU,CAAE,OAAM,GAG/CR,EAAW,CAAE,OAAM,CAAC,EACtB,EAGMa,MAAyC,CAC7C,IAAMC,EAAWN,EAEjB,MADA,GAAU,IAAA,GACHM,CACT,EAEMC,EAAe,GAA4B,CAC/C,IAAMC,EAAWC,EAAM,SACvB,GAAI,OAAOD,GAAa,WAAY,OAAOA,EAC3C,GAAI,CACF,OAAOE,MACJF,EAA4DJ,EAAOH,CAAK,CAC3E,CACF,OAASU,EAAQ,CAGfC,EAAYD,EAAQ5B,CAAW,EAC/B,MACF,CACF,EAGM8B,MAAuB,CAC3B,EAAO,GACP,GAAI,CACFlB,EAAQ,EACR,IAAMmB,EAAUxB,EAAQ,GAAKe,EAAY,EACzC,GAAIS,IAAY,IAAA,GAEd,OAAOP,EAAYO,EAAQ,KAAK,EAIlC,IAAMC,EAAQC,EAAY,IAEjB,CACL,UACA,MAAOC,MAAiBP,MAAcD,EAAM,QAAQ,EAAGN,CAAM,CAC/D,EACD,EACKe,EAAWb,EAAY,EAO7B,OANIa,IAAa,IAAA,GAMVH,EAAM,OALXA,EAAM,QAAQ,EAEPR,EAAYW,EAAS,KAAK,EAIrC,QAAU,CAERF,MAAiB,CACfG,MAAgB,CACd,EAAO,EACT,CAAC,CACH,CAAC,EACD,EAAO,EACT,CAEF,EAIMC,EAAOC,MACJhC,IAAW,KAAOwB,EAAM,EAAIS,EAAU,CAAE,GAAGjC,CAAO,EAAGwB,CAAK,EACjE,CAAE,YAAa,EAAK,CACtB,EASA,OANAG,MAAiB,CACfG,MAAgB,CACd,EAAQ,EAEV,CAAC,CACH,CAAC,EACMC,CACT,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{mapArray as e,untrack as t}from"@shadow-js/core";function n(e,n,r){return t(()=>e.children)(n,r)}function r(t){let r=()=>t.each,i=()=>t.fallback,a=t.key;return a===void 0?e(r,(e,r)=>n(t,e,r),{fallback:i}):e(r,(e,r)=>n(t,e,r),{key:a,fallback:i})}export{r as For};
|
|
2
|
+
//# sourceMappingURL=for.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"for.js","names":["renderRow","untrack","props","item","index","For","list","fallback","keyOf","mapArray"],"sources":["../../../src/control-flow/for.ts"],"sourcesContent":["import { type Accessor, mapArray, untrack } from \"@shadow-js/core\";\n\n/**\n * Props of {@link For} without `key`: rows are matched by item reference.\n * @since 1.0.0\n */\nexport interface ForUnkeyedProps<T> {\n /**\n * The list to render. `null`, `undefined` and `false` count as an empty list. Read lazily, inside\n * the list memo, so it is tracked.\n */\n readonly each: readonly T[] | null | undefined | false;\n /**\n * Shown while the list is empty. Read lazily.\n * @default undefined (an empty list renders nothing)\n */\n readonly fallback?: unknown;\n /**\n * Absent in this form: rows are matched by item reference. Pass `key` to match by key.\n * No default: omit it for reference matching.\n */\n readonly key?: undefined;\n /** Called once per row, untracked. The callback receives the item value. */\n readonly children: (item: T, index: () => number) => unknown;\n}\n\n/**\n * Props of {@link For} with `key`: rows are matched by `key(item)`.\n * @since 1.0.0\n */\nexport interface ForKeyedProps<T> {\n /**\n * The list to render. `null`, `undefined` and `false` count as an empty list. Read lazily, inside\n * the list memo, so it is tracked.\n */\n readonly each: readonly T[] | null | undefined | false;\n /**\n * Shown while the list is empty. Read lazily.\n * @default undefined (an empty list renders nothing)\n */\n readonly fallback?: unknown;\n /** Identifies each item. A new object under the same key updates the row's `item()`. */\n readonly key: (item: T) => unknown;\n /** Called once per row, untracked. The callback receives an accessor of the item. */\n readonly children: (item: () => T, index: () => number) => unknown;\n}\n\n/**\n * Props of {@link For}.\n * @since 1.0.0\n */\nexport type ForProps<T> = ForUnkeyedProps<T> | ForKeyedProps<T>;\n\n/**\n * Calls the row callback. `props.children` is read untracked, once per row.\n * @internal\n */\nfunction renderRow(props: { readonly children: unknown }, item: unknown, index: () => number) {\n const render = untrack(() => props.children) as (item: unknown, index: () => number) => unknown;\n return render(item, index);\n}\n\n/**\n * Renders one row per item. Rows whose key survives an update keep their DOM and state; only\n * changed items create or dispose rows. The list is read lazily, inside the list memo.\n *\n * Whether rows are keyed is decided when `For` is created: it reads `key` once. When the list\n * is empty and `fallback` is not given, the result is `[undefined]`, which renders nothing.\n *\n * @param props See {@link ForUnkeyedProps} and {@link ForKeyedProps}.\n * @returns An accessor of the row values, in input order.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { For } from \"@shadow-js/web\";\n *\n * function TodoList() {\n * const [todos] = useSignal([{ id: 1, title: \"Write docs\" }]);\n * return (\n * <ul>\n * <For each={todos()} key={(todo) => todo.id} fallback={<li>Nothing to do</li>}>\n * {(todo) => <li>{todo().title}</li>}\n * </For>\n * </ul>\n * );\n * }\n * @see Index\n * @since 1.0.0\n */\nexport function For<T>(props: ForKeyedProps<T>): Accessor<unknown[]>;\nexport function For<T>(props: ForUnkeyedProps<T>): Accessor<unknown[]>;\nexport function For<T>(props: ForProps<T>): Accessor<unknown[]> {\n const list = (): readonly T[] | null | undefined | false => props.each;\n const fallback = (): unknown => props.fallback;\n const keyOf = props.key;\n if (keyOf === undefined) {\n return mapArray(list, (item: T, index: () => number) => renderRow(props, item, index), {\n fallback,\n });\n }\n return mapArray(list, (item: () => T, index: () => number) => renderRow(props, item, index), {\n key: keyOf,\n fallback,\n });\n}\n"],"mappings":"A,wDAyDA,SAASA,EAAU,EAAuC,EAAe,EAAqB,CAE5F,OADeC,MAAcC,EAAM,QACvB,CAAC,CAACC,EAAMC,CAAK,CAC3B,CA8BA,SAAgBC,EAAO,EAAyC,CAC9D,IAAMC,MAAsDJ,EAAM,KAC5DK,MAA0BL,EAAM,SAChCM,EAAQN,EAAM,IAMpB,OALIM,IAAU,IAAA,GACLC,EAASH,GAAO,EAAS,IAAwBN,EAAUE,EAAOC,EAAMC,CAAK,EAAG,CACrF,UACF,CAAC,EAEIK,EAASH,GAAO,EAAe,IAAwBN,EAAUE,EAAOC,EAAMC,CAAK,EAAG,CAC3F,IAAKI,EACL,UACF,CAAC,CACH,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fragment.js","names":["Fragment","props"],"sources":["../../../src/control-flow/fragment.ts"],"sourcesContent":["/**\n * Props of {@link Fragment}.\n * @since 1.0.0\n */\nexport interface FragmentProps {\n /**\n * The children to group.\n * @default undefined (the Fragment renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * A no-op wrapper: returns `props.children` untouched, so the children are created by the caller's\n * getter exactly as if no wrapper existed. Use it to group several children under one element.\n *\n * @param props The children to group.\n * @returns `props.children`, unchanged.\n * @example\n * import { Fragment } from \"@shadow-js/web\";\n *\n * function Header() {\n * return <h1>Title</h1>;\n * }\n *\n * function Page() {\n * return (\n * <Fragment>\n * <Header />\n * <p>Body</p>\n * </Fragment>\n * );\n * }\n * @since 1.0.0\n */\nexport function Fragment(props: FragmentProps): unknown {\n return props.children;\n}\n"],"mappings":"AAmCA,SAAgBA,EAAS,EAA+B,CACtD,OAAOC,EAAM,QACf,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hot-link.js","names":["HOT_MODULES","hotModulesOf","owner"],"sources":["../../../src/control-flow/hot-link.ts"],"sourcesContent":["import { getOwner, type Owner } from \"@shadow-js/core\";\nimport type { ModuleRegistry } from \"../hmr\";\n\n/**\n * The hot-update link between an error boundary and the modules its children were built from. Dev\n * only: the callers reach this code behind `__DEV__`, so production bundles never include it.\n *\n * A boundary that shows its fallback listens to those modules. When one of them is hot-replaced (the\n * edit is usually the fix), the boundary resets and builds its children again, so the user does not\n * have to press retry. The same module set is kept while the children are built: each component instance\n * adds its module to it when it is created (`hotModulesOf` in the proxy of `component()`).\n */\n\n/** The key the module set is stored under in the owner context of a boundary's children. */\nconst HOT_MODULES: symbol = /* @__PURE__ */ Symbol(\"HotModules\");\n\n/**\n * Makes `modules` the set of the root that is being created (called inside its `createRoot`): every\n * component created below that root adds its module to it.\n * @internal\n */\nexport function attachHotModules(modules: Set<ModuleRegistry>): void {\n const root = getOwner();\n if (root === null) return;\n const map = Object.create(root.context) as Record<symbol, unknown>;\n map[HOT_MODULES] = modules;\n root.context = map;\n}\n\n/**\n * The module set of the nearest boundary above `owner`, or undefined when there is none.\n * @internal\n */\nexport function hotModulesOf(owner: Owner | null): Set<ModuleRegistry> | undefined {\n return owner?.context?.[HOT_MODULES] as Set<ModuleRegistry> | undefined;\n}\n\n/**\n * The link of one boundary: the modules its children were last built from, and the listener armed on\n * them while the boundary shows its fallback.\n * @internal\n */\nexport interface HotLink {\n /** The modules of the last children build. Cleared by the boundary before each build. */\n readonly modules: Set<ModuleRegistry>;\n /** Listens to every module in `modules`: a hot update of one of them calls the boundary's `onUpdate`. */\n arm(): void;\n /** Stops listening (the children built, or the boundary was disposed). */\n disarm(): void;\n}\n\n/**\n * Creates the link of a boundary. `onUpdate` runs after a hot update of a module the boundary listens to,\n * once the update is applied.\n * @internal\n */\nexport function createHotLink(onUpdate: () => void): HotLink {\n const modules = new Set<ModuleRegistry>();\n let armed: ModuleRegistry[] = [];\n const listener = (): void => {\n onUpdate();\n };\n const disarm = (): void => {\n for (const registry of armed) registry.listeners.delete(listener);\n armed = [];\n };\n const arm = (): void => {\n disarm();\n for (const registry of modules) {\n registry.listeners.add(listener);\n armed.push(registry);\n }\n };\n return { modules, arm, disarm };\n}\n"],"mappings":"A,wBAcA,MAAMA,EAAsC,uBAAO,YAAY,EAmB/D,SAAgBC,EAAa,EAAsD,CACjF,OAAOC,GAAO,UAAUF,EAC1B,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-list.js","names":["Index","indexArray","props","untrack","item","index"],"sources":["../../../src/control-flow/index-list.ts"],"sourcesContent":["import { type Accessor, indexArray, untrack } from \"@shadow-js/core\";\n\n/**\n * Props of {@link Index}.\n * @since 1.0.0\n */\nexport interface IndexProps<T> {\n /**\n * The list to render. `null`, `undefined` and `false` count as an empty list. Read lazily, so it\n * is tracked.\n */\n readonly each: readonly T[] | null | undefined | false;\n /**\n * Shown while the list is empty. Read lazily.\n * @default undefined (an empty list renders nothing)\n */\n readonly fallback?: unknown;\n /**\n * Called once per position, untracked. The item is an accessor that follows the value at this\n * position; the index is a plain number, because a position never changes.\n */\n readonly children: (item: () => T, index: number) => unknown;\n}\n\n/**\n * Renders one row per position. Rows are created and removed only when the length changes; the\n * row at position `i` stays, and its item accessor follows the value at `i`. Use it for\n * primitive lists where identity does not matter.\n *\n * @param props See {@link IndexProps}.\n * @returns An accessor of the row values, in input order.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { Index } from \"@shadow-js/web\";\n *\n * function Cells() {\n * const [values] = useSignal([10, 20, 30]);\n * return (\n * <ul>\n * <Index each={values()}>{(value, index) => <li>{`${index}: ${value()}`}</li>}</Index>\n * </ul>\n * );\n * }\n * @see For\n * @since 1.0.0\n */\nexport function Index<T>(props: IndexProps<T>): Accessor<unknown[]> {\n return indexArray(\n () => props.each,\n (item: () => T, index: number) => untrack(() => props.children)(item, index),\n { fallback: () => props.fallback },\n );\n}\n"],"mappings":"A,0DA8CA,SAAgBA,EAAS,EAA2C,CAClE,OAAOC,MACCC,EAAM,MACX,EAAe,IAAkBC,MAAcD,EAAM,QAAQ,CAAC,CAACE,EAAMC,CAAK,EAC3E,CAAE,aAAgBH,EAAM,QAAS,CACnC,CACF,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{untrack as e,useMemo as t,useResource as n}from"@shadow-js/core";function r(r){let i,a,o=()=>(i===void 0&&(i=r().then(e=>(a=e.default,e.default),e=>{throw i=void 0,e})),i),s=(r=>{if(a!==void 0){let n=a;return t(()=>e(()=>n(r)),{allowWrites:!0})}let i=n(()=>o());return t(()=>{let t=i();return t===void 0?void 0:e(()=>t(r))},{allowWrites:!0})});return s.preload=o,s}export{r as lazy};
|
|
2
|
+
//# sourceMappingURL=lazy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy.js","names":["lazy","pending","loaded","load","loader","module","error","Lazy","component","useMemo","untrack","props","resource","useResource"],"sources":["../../../src/control-flow/lazy.ts"],"sourcesContent":["import { type Accessor, untrack, useMemo, useResource } from \"@shadow-js/core\";\n\ntype ComponentFunction<P> = (props: P) => unknown;\n\n/**\n * A component made by {@link lazy}: call it (or write it in JSX) like any component, and use\n * `preload` to start the load early.\n * @since 1.0.0\n */\nexport interface LazyComponent<P> {\n /**\n * Renders the loaded component with `props`. While the code is loading the result is empty and the\n * nearest `<Suspense>` shows its fallback; without a boundary nothing is rendered until the load\n * resolves.\n */\n (props: P): Accessor<unknown>;\n /**\n * Starts loading without rendering and resolves to the component. Calls share one load, so the\n * loader runs once. A failed load is not cached: the next call or render loads again.\n */\n preload(): Promise<ComponentFunction<P>>;\n}\n\n/**\n * Defines a component whose code is loaded on first render. While loading, the nearest\n * `<Suspense>` shows its fallback; a failed load throws to the nearest `<ErrorBoundary>` and the\n * next render retries.\n *\n * @param loader Returns a promise of a module whose `default` export is the component, such as\n * `() => import(\"./chart\")`. Called at most once while its load succeeds.\n * @returns A {@link LazyComponent}.\n * @throws Nothing synchronously. A rejected load surfaces as an error when the component's output\n * is read, so the nearest `<ErrorBoundary>` takes it; `preload()` rejects with the same error.\n * @example\n * import { lazy, Suspense } from \"@shadow-js/web\";\n *\n * function Chart(props: { title: string }) {\n * return <h2>{props.title}</h2>;\n * }\n *\n * // In an app the loader is `() => import(\"./chart\")`.\n * const LazyChart = lazy(() => Promise.resolve({ default: Chart }));\n *\n * function Page() {\n * return (\n * <Suspense fallback={<p>Loading...</p>}>\n * <LazyChart title=\"Sales\" />\n * </Suspense>\n * );\n * }\n * @see Suspense\n * @see ErrorBoundary\n * @since 1.0.0\n */\nexport function lazy<P>(\n loader: () => Promise<{ default: ComponentFunction<P> }>,\n): LazyComponent<P> {\n let pending: Promise<ComponentFunction<P>> | undefined;\n let loaded: ComponentFunction<P> | undefined;\n\n const load = (): Promise<ComponentFunction<P>> => {\n if (pending === undefined) {\n pending = loader().then(\n (module) => {\n loaded = module.default;\n return module.default;\n },\n (error: unknown) => {\n pending = undefined;\n throw error;\n },\n );\n }\n return pending;\n };\n\n const Lazy = ((props: P): Accessor<unknown> => {\n if (loaded !== undefined) {\n const component = loaded;\n return useMemo(() => untrack(() => component(props)), { allowWrites: true });\n }\n const resource = useResource(() => load());\n return useMemo(\n () => {\n const component = resource();\n return component === undefined ? undefined : untrack(() => component(props));\n },\n { allowWrites: true },\n );\n }) as LazyComponent<P>;\n Lazy.preload = load;\n return Lazy;\n}\n"],"mappings":"A,wEAsDA,SAAgBA,EACd,EACkB,CAClB,IAAIC,EACAC,EAEEC,OACAF,IAAY,IAAA,KACd,EAAUG,EAAO,CAAC,CAAC,KAChB,IACC,EAASC,EAAO,QACTA,EAAO,SAEf,GAAmB,CAElB,KADA,GAAU,IAAA,GACJC,CACR,CACF,GAEKL,GAGHM,GAAS,GAAgC,CAC7C,GAAIL,IAAW,IAAA,GAAW,CACxB,IAAMM,EAAYN,EAClB,OAAOO,MAAcC,MAAcF,EAAUG,CAAK,CAAC,EAAG,CAAE,YAAa,EAAK,CAAC,CAC7E,CACA,IAAMC,EAAWC,MAAkBV,EAAK,CAAC,EACzC,OAAOM,MACC,CACJ,IAAMD,EAAYI,EAAS,EAC3B,OAAOJ,IAAc,IAAA,GAAY,IAAA,GAAYE,MAAcF,EAAUG,CAAK,CAAC,CAC7E,EACA,CAAE,YAAa,EAAK,CACtB,CACF,GAEA,MADA,GAAK,QAAUR,EACRI,CACT,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{nextKey as e}from"../internal/hydration-scope.js";import{claims as t}from"../internal/hydration-hooks.js";function n(e,t){if(e!==void 0&&t!==void 0)for(let n of t){let t=n.findIndex(t=>t.nodeType===8&&t.data===`nh:${e}`);if(t===-1)continue;let r=[],i=1;for(let e=t+1;e<n.length;e+=1){let t=n[e];if(t.nodeType===8){let e=t.data;if(e.startsWith(`nh:`))i+=1;else if(e===`/nh`&&--i===0)break}r.push(t)}return r}}function r(r){let i=e();if(t.current.isClaiming()){let e=n(i,t.current.liftedRegions());return e===void 0?()=>t.current.withoutClaiming(()=>r.children):()=>e}return()=>r.children}export{r as NoHydration};
|
|
2
|
+
//# sourceMappingURL=no-hydration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-hydration.js","names":["findStatic","key","regions","region","open","node","nodes","depth","i","data","NoHydration","nextKey","claims","kept","props"],"sources":["../../../src/control-flow/no-hydration.ts"],"sourcesContent":["import type { Accessor } from \"@shadow-js/core\";\nimport { claims, nextKey, withScope } from \"../extend\";\nimport { ssrRaw } from \"../server/element\";\n\n/** The nodes between `<!--nh:KEY-->` and its `<!--/nh-->` in the lifted regions, or undefined when the server sent none. */\nfunction findStatic(\n key: string | undefined,\n regions: readonly (readonly Node[])[] | undefined,\n): Node[] | undefined {\n if (key === undefined || regions === undefined) return undefined;\n for (const region of regions) {\n const open = region.findIndex(\n (node) => node.nodeType === 8 && (node as Comment).data === `nh:${key}`,\n );\n if (open === -1) continue;\n const nodes: Node[] = [];\n let depth = 1;\n for (let i = open + 1; i < region.length; i += 1) {\n const node = region[i] as Node;\n if (node.nodeType === 8) {\n const data = (node as Comment).data;\n if (data.startsWith(\"nh:\")) depth += 1;\n else if (data === \"/nh\" && --depth === 0) break;\n }\n nodes.push(node);\n }\n return nodes;\n }\n return undefined;\n}\n\n/**\n * Props of {@link NoHydration}.\n * @since 1.0.0\n */\nexport interface NoHydrationProps {\n /**\n * The static content. Rendered by the server without hydration keys and left untouched by the\n * browser's hydration pass.\n * @default undefined (renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * Content the browser never hydrates: the server renders it without hydration keys, and while the\n * page hydrates the browser leaves that markup exactly as it is (no code runs for it, no event\n * handlers or reactivity are attached). Use it for static, heavy markup such as rendered\n * documentation or a long article. Rendered by the browser alone (a client-side navigation), its\n * children render normally.\n *\n * @param props See {@link NoHydrationProps}.\n * @returns An accessor of the content: the children, or the server's own nodes while the browser hydrates.\n * @example\n * import { NoHydration } from \"@shadow-js/web\";\n *\n * function Docs(props: { html: string }) {\n * return (\n * <NoHydration>\n * <article innerHTML={props.html} />\n * </NoHydration>\n * );\n * }\n * @see ClientOnly\n * @since 1.0.0\n */\nexport function NoHydration(props: NoHydrationProps): Accessor<unknown> {\n // The component has its own scope, so this key does not move the keys of its siblings.\n const key = nextKey();\n if (__SERVER__) {\n // No scope for the content: the keys of what is rendered inside are not handed out.\n const built = withScope(null, () => props.children);\n return () => [ssrRaw(`<!--nh:${key ?? \"\"}-->`), built, ssrRaw(\"<!--/nh-->\")];\n }\n if (claims.current.isClaiming()) {\n // Hydrating: the server's nodes between the markers are handed to the region as they are.\n const kept = findStatic(key, claims.current.liftedRegions());\n if (kept !== undefined) return () => kept;\n // No markers from the server (the root of the container): render on the client, claiming nothing.\n return () => claims.current.withoutClaiming(() => props.children);\n }\n return () => props.children;\n}\n"],"mappings":"A,iHAKA,SAASA,EACP,EACA,EACoB,CACpB,GAAIC,IAAQ,IAAA,IAAaC,IAAY,IAAA,GACrC,IAAK,IAAMC,KAAUD,EAAS,CAC5B,IAAME,EAAOD,EAAO,UACjB,GAASE,EAAK,WAAa,GAAMA,EAAiB,OAAS,MAAMJ,GACpE,EACA,GAAIG,IAAS,GAAI,SACjB,IAAME,EAAgB,CAAC,EACnBC,EAAQ,EACZ,IAAK,IAAIC,EAAIJ,EAAO,EAAGI,EAAIL,EAAO,OAAQ,GAAK,EAAG,CAChD,IAAME,EAAOF,EAAOK,GACpB,GAAIH,EAAK,WAAa,EAAG,CACvB,IAAMI,EAAQJ,EAAiB,KAC/B,GAAII,EAAK,WAAW,KAAK,EAAG,GAAS,OAChC,GAAIA,IAAS,OAAS,EAAEF,IAAU,EAAG,KAC5C,CACAD,EAAM,KAAKD,CAAI,CACjB,CACA,OAAOC,CACT,CAEF,CAqCA,SAAgBI,EAAY,EAA4C,CAEtE,IAAMT,EAAMU,EAAQ,EAMpB,GAAIC,EAAO,QAAQ,WAAW,EAAG,CAE/B,IAAMC,EAAOb,EAAWC,EAAKW,EAAO,QAAQ,cAAc,CAAC,EAG3D,OAFIC,IAAS,IAAA,OAEAD,EAAO,QAAQ,oBAAsBE,EAAM,QAAQ,MAF3BD,CAGvC,CACA,UAAaC,EAAM,QACrB,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{childScope as e,nextKey as t,withScope as n}from"../internal/hydration-scope.js";import{claims as r}from"../internal/hydration-hooks.js";import{bindRegion as i,createRegion as a,removeRegion as o}from"../insert.js";import{PortalContext as s}from"../internal/portal-context.js";import{renderServerPortal as c}from"../server/portals.js";import{createRoot as l,isServer as u,onCleanup as d,useContext as f,useRenderEffect as p}from"@shadow-js/core";function m(e,t){typeof e.moveBefore==`function`?e.moveBefore(t,null):e.appendChild(t)}function h(e){return e.shadowRoot??e.attachShadow({mode:`open`})}function g(e){return e===void 0?document.body:(typeof e==`function`?e():e)??null}function _(_){let v=t(),y=f(s);if(u||y!==null)return _.useShadow!==!0&&c(v,()=>_.children,y),null;let b,x=r.current.claimPortal(v),S=()=>{let e=b;e!==void 0&&(b=void 0,e.stopEffects(),o(e.region))},C=(t,o,s)=>{let c=a(t,null,o);return{host:t,region:c,stopEffects:l(t=>{let a=()=>{i(c,()=>_.children)};return s===`plain`?a():s===`claimed`?n(e(v),a):r.current.withoutClaiming(()=>n(e(v),a)),t})}},w=e=>{let t=b;if(t===void 0){let t=x??[],n=`plain`;x===void 0?v!==void 0&&r.current.isClaiming()&&(n=`unclaimed`):n=`claimed`,x=void 0;for(let n of t)n.parentNode!==e&&m(e,n);b=C(e,t,n);return}let n=t.region.nodes.filter(e=>e.parentNode===t.host);t.stopEffects();for(let t of n)m(e,t);b=C(e,n,`plain`)};return p(()=>({host:g(_.mount),shadow:_.useShadow===!0}),({host:e,shadow:t})=>{if(e===null){S();return}let n=t?h(e):e;(b===void 0||b.host!==n)&&w(n)}),d(S),null}export{_ as Portal};
|
|
2
|
+
//# sourceMappingURL=portal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal.js","names":["appendMoved","target","node","shadowRootOf","host","resolveMount","mount","Portal","key","nextKey","sink","useContext","PortalContext","isServer","props","renderServerPortal","mounted","adopted","claims","unmount","current","removeRegion","mountInto","region","createRegion","initial","createRoot","bind","bindRegion","mode","withScope","childScope","dispose","moveTo","previous","nodes","useRenderEffect","shadow","onCleanup"],"sources":["../../../src/control-flow/portal.ts"],"sourcesContent":["import { createRoot, isServer, onCleanup, useContext, useRenderEffect } from \"@shadow-js/core\";\nimport {\n bindRegion,\n childScope,\n claims,\n createRegion,\n nextKey,\n PortalContext,\n type Region,\n removeRegion,\n withScope,\n} from \"../extend\";\nimport { renderServerPortal } from \"../server/portals\";\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, and static nodes keep their identity while they\n * 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) renderServerPortal(key, () => props.children, sink);\n return null;\n }\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 = 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 return { host, region, stopEffects };\n };\n\n /** Moves the content to `target`. The nodes move first, then the children are bound again. */\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 const nodes = previous.region.nodes.filter((node) => node.parentNode === previous.host);\n previous.stopEffects();\n for (const node of nodes) appendMoved(target, node);\n mounted = mountInto(target, nodes, \"plain\");\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 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,qcAiEA,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,EAAQ,EAGdC,EAAOC,EAAWC,CAAa,EACrC,GAAIC,GAAYH,IAAS,KAEvB,OADII,EAAM,YAAc,IAAMC,EAAmBP,MAAWM,EAAM,SAAUJ,CAAI,EACzE,KAET,IAAIM,EAGAC,EAA8BC,EAAO,QAAQ,YAAYV,CAAG,EAG1DW,MAAsB,CAC1B,IAAMC,EAAUJ,EACZI,IAAY,IAAA,KAChB,EAAU,IAAA,GACVA,EAAQ,YAAY,EACpBC,EAAaD,EAAQ,MAAM,EAC7B,EAGME,GAAa,EAAY,EAAiB,IAA6B,CAC3E,IAAMC,EAASC,EAAapB,EAAM,KAAMqB,CAAO,EAU/C,MAAO,CAAE,OAAM,SAAQ,YATHC,EAAY,GAAY,CAC1C,IAAMC,MAAmB,CACvBC,EAAWL,MAAcT,EAAM,QAAQ,CACzC,EAIA,OAHIe,IAAS,QAASF,EAAK,EAClBE,IAAS,UAAWC,EAAUC,EAAWvB,CAAG,EAAGmB,CAAI,EACvDT,EAAO,QAAQ,oBAAsBY,EAAUC,EAAWvB,CAAG,EAAGmB,CAAI,CAAC,EACnEK,CACT,CACiC,CAAE,CACrC,EAGMC,EAAU,GAAuB,CACrC,IAAMC,EAAWlB,EACjB,GAAIkB,IAAa,IAAA,GAAW,CAC1B,IAAMT,EAAUR,GAAW,CAAC,EACxBY,EAAkB,QAClBZ,IAAY,IAAA,GACPT,IAAQ,IAAA,IAAaU,EAAO,QAAQ,WAAW,IAAG,EAAO,aADvC,EAAO,UAElC,EAAU,IAAA,GACV,IAAK,IAAMhB,KAAQuB,EACbvB,EAAK,aAAeD,GAAQD,EAAYC,EAAQC,CAAI,EAE1D,EAAUoB,EAAUrB,EAAQwB,EAASI,CAAI,EACzC,MACF,CACA,IAAMM,EAAQD,EAAS,OAAO,MAAM,OAAQ,GAAShC,EAAK,aAAegC,EAAS,IAAI,EACtFA,EAAS,YAAY,EACrB,IAAK,IAAMhC,KAAQiC,EAAOnC,EAAYC,EAAQC,CAAI,EAClD,EAAUoB,EAAUrB,EAAQkC,EAAO,OAAO,CAC5C,EAyBA,OAvBAC,OAIW,CAAE,KAFI/B,EAAaS,EAAM,KAEpB,EAAG,OADAA,EAAM,YAAc,EACb,IAEvB,CAAE,OAAM,YAAa,CACpB,GAAIV,IAAS,KAAM,CACjBe,EAAQ,EAOR,MACF,CACA,IAAMlB,EAAeoC,EAASlC,EAAaC,CAAI,EAAIA,GAC/CY,IAAY,IAAA,IAAaA,EAAQ,OAASf,IAC9CgC,EAAOhC,CAAM,CACf,CACF,EACAqC,EAAUnB,CAAO,EACV,IACT,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{getOwner as e}from"@shadow-js/core";const t=/* @__PURE__ */ Symbol(`RootErrors`);function n(n){let r=e();if(r===null)return;let i=Object.create(r.context);i[t]=n,r.context=i,n.onUncaughtError!==void 0&&(r.errorHandlers=[n.onUncaughtError])}function r(e){return e?.context?.[t]}export{n as attachRootErrors,r as rootErrorsOf};
|
|
2
|
+
//# sourceMappingURL=root-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"root-errors.js","names":["ROOT_ERRORS","attachRootErrors","root","getOwner","map","options","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,MAAMA,EAAsC,uBAAO,YAAY,EAQ/D,SAAgBC,EAAiB,EAAiC,CAChE,IAAMC,EAAOC,EAAS,EACtB,GAAID,IAAS,KAAM,OACnB,IAAME,EAAM,OAAO,OAAOF,EAAK,OAAO,EACtC,EAAIF,GAAeK,EACnB,EAAK,QAAUD,EACXC,EAAQ,kBAAoB,IAAA,KAAW,EAAK,cAAgB,CAACA,EAAQ,eAAe,EAC1F,CAMA,SAAgBC,EAAa,EAAmD,CAC9E,OAAOC,GAAO,UAAUP,EAC1B,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"show.js","names":["Show","createBranches","when","props"],"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,SAAgBA,EAAQ,EAA6C,CACnE,OAAOC,EACL,WACM,CACJ,IAAMC,EAAOC,EAAM,KACnB,MAAO,CACL,MAAOD,EAAO,EAAA,GACd,MAAOC,EAAM,QAAU,GACvB,OACA,SAAYA,EAAM,KAClB,SAAYA,EAAM,QACpB,CACF,MACMA,EAAM,QACd,CACF,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createContext as e,onCleanup as t,useContext as n}from"@shadow-js/core";import{createSignalNode as r,readSignal as i,writeSignal as a}from"@shadow-js/core/extend";const o=/* @__PURE__ */ e(null,{name:`SuspenseList`});function s(e){let n=r(0,!1),s=[],c=()=>{a(n,0,{allowInMemo:!0})};return o({value:{register(r){let a={ready:r};s.push(a),c(),t(()=>{let e=s.indexOf(a);e!==-1&&s.splice(e,1),c()});let o=()=>(i(n),s.indexOf(a)),l=()=>{let t=o();if(t===-1)return!1;switch(e.revealOrder){case`together`:return s.every(e=>e.ready());case`forwards`:return s.slice(0,t+1).every(e=>e.ready());case`backwards`:return s.slice(t).every(e=>e.ready());default:return r()}};return{reveal:l,showFallback:()=>{if(l())return!1;let t=e.revealOrder;if(t!==`forwards`&&t!==`backwards`)return!0;if(e.tail===`hidden`)return!1;if(e.tail!==`collapsed`)return!0;let n=o(),r=t===`backwards`?[...s].reverse():s,i=t===`backwards`?s.length-1-n:n;for(let e=0;e<r.length;e+=1){let t=r[e];if(t!==void 0&&!t.ready())return e===i}return!1}}}},get children(){return e.children}})}function c(e){let t=n(o);return t===null?null:t.register(e)}export{s as SuspenseList,o as SuspenseListContext,c as registerInList};
|
|
2
|
+
//# sourceMappingURL=suspense-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suspense-list.js","names":["SuspenseListContext","SuspenseList","changes","createSignalNode","slots","touch","writeSignal","entry","onCleanup","index","position","readSignal","reveal","props","slot","ready","order","ordered","wanted","i","candidate","registerInList","list","useContext"],"sources":["../../../src/control-flow/suspense-list.ts"],"sourcesContent":["import { type Accessor, type Context, createContext, onCleanup, useContext } from \"@shadow-js/core\";\nimport { createSignalNode, readSignal, 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 = createSignalNode<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,0KAkBA,MAAaA,EACK,kBAAwC,KAAM,CAAE,KAAM,cAAe,CAAC,EA+DxF,SAAgBC,EAAa,EAA6C,CAExE,IAAMC,EAAUC,EAAyB,EAAG,EAAK,EAC3CC,EAAkD,CAAC,EACnDC,MAAoB,CACxBC,EAAYJ,EAAS,EAAG,CAAE,YAAa,EAAK,CAAC,CAC/C,EAmDA,OAAOF,EAAoB,CACzB,MAAO,CAjDP,SAAS,EAAO,CACd,IAAMO,EAAQ,CAAE,OAAM,EACtBH,EAAM,KAAKG,CAAK,EAChBF,EAAM,EACNG,MAAgB,CACd,IAAMC,EAAQL,EAAM,QAAQG,CAAK,EAC7BE,IAAU,IAAIL,EAAM,OAAOK,EAAO,CAAC,EACvCJ,EAAM,CACR,CAAC,EACD,IAAMK,OACJC,EAAWT,CAAO,EACXE,EAAM,QAAQG,CAAK,GAEtBK,MAAwB,CAC5B,IAAMH,EAAQC,EAAS,EACvB,GAAID,IAAU,GAAI,MAAO,GACzB,OAAQI,EAAM,YAAd,CACE,IAAK,WACH,OAAOT,EAAM,MAAO,GAASU,EAAK,MAAM,CAAC,EAC3C,IAAK,WACH,OAAOV,EAAM,MAAM,EAAGK,EAAQ,CAAC,CAAC,CAAC,MAAO,GAASK,EAAK,MAAM,CAAC,EAC/D,IAAK,YACH,OAAOV,EAAM,MAAMK,CAAK,CAAC,CAAC,MAAO,GAASK,EAAK,MAAM,CAAC,EACxD,QACE,OAAOC,EAAM,CACjB,CACF,EAkBA,MAAO,CAAE,SAAQ,iBAjBmB,CAClC,GAAIH,EAAO,EAAG,MAAO,GACrB,IAAMI,EAAQH,EAAM,YAEpB,GADmBG,IAAU,YAAcA,IAAU,YACpC,MAAO,GACxB,GAAIH,EAAM,OAAS,SAAU,MAAO,GACpC,GAAIA,EAAM,OAAS,YAAa,MAAO,GAEvC,IAAMJ,EAAQC,EAAS,EACjBO,EAAUD,IAAU,YAAc,CAAC,GAAGZ,CAAK,CAAC,CAAC,QAAQ,EAAIA,EACzDc,EAASF,IAAU,YAAcZ,EAAM,OAAS,EAAIK,EAAQA,EAClE,IAAK,IAAIU,EAAI,EAAGA,EAAIF,EAAQ,OAAQ,GAAK,EAAG,CAC1C,IAAMG,EAAYH,EAAQE,GAC1B,GAAIC,IAAc,IAAA,IAAa,CAACA,EAAU,MAAM,EAAG,OAAOD,IAAMD,CAClE,CACA,MAAO,EACT,CAC8B,CAChC,CAIW,EACX,IAAI,UAAW,CACb,OAAOL,EAAM,QACf,CACF,CAAC,CACH,CAGA,SAAgBQ,EAAe,EAA+C,CAC5E,IAAMC,EAAOC,EAAWvB,CAAmB,EAC3C,OAAOsB,IAAS,KAAO,KAAOA,EAAK,SAASP,CAAK,CACnD,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{childScope as e,nextKey as t,withScope as n}from"../internal/hydration-scope.js";import{registerInList as r}from"./suspense-list.js";import{SuspenseContext as i,runWithOwner as a,useMemo as o}from"@shadow-js/core";import{createOwner as s,createSignalNode as c,readSignal as l,transitionHooks as u,writeSignal as d}from"@shadow-js/core/extend";function f(){let e=c(0,Object.is),t,n=!1,r=t=>{d(e,e.value+t,{allowInMemo:!0})};return{tracker:{increment:()=>r(1),decrement:()=>{r(-1),e.value===0&&t?.release()},hold:()=>n?(t??=u()?.boundaryHold(),t?.engage()===!0):!1},count:()=>l(e),holding:()=>t?.holding()===!0,revealed:()=>{n=!0}}}function p(c){let l=t(),{tracker:u,count:d,holding:p,revealed:m}=f(),h=r(()=>d()===0),g=s();g.gate=()=>d()>0||h!==null&&!h.reveal();let _=a(g,()=>n(e(l),()=>i({value:u,get children(){return c.children}}))),v=e(l===void 0?void 0:`${l}f`);return o(e=>(d(),p()&&e!==void 0?e:h===null?d()>0?n(v,()=>c.fallback):(m(),_()):d()===0&&h.reveal()?(m(),_()):h.showFallback()?n(v,()=>c.fallback):null),{allowWrites:!0})}export{p as Suspense};
|
|
2
|
+
//# sourceMappingURL=suspense.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suspense.js","names":["createTracker","pending","createSignalNode","hold","shown","adjust","writeSignal","by","transitionHooks","readSignal","Suspense","key","nextKey","slot","registerInList","count","boundary","createOwner","content","runWithOwner","withScope","childScope","SuspenseContext","tracker","props","fallbackScope","useMemo","holding","previous","revealed"],"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 createSignalNode,\n readSignal,\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 = createSignalNode<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,8VAwDA,SAASA,GAA0B,CAGjC,IAAMC,EAAUC,EAAyB,EAAG,OAAO,EAAE,EAIjDC,EACAC,EAAQ,GACNC,EAAU,GAAqB,CACnCC,EAAYL,EAASA,EAAQ,MAAQM,EAAI,CAAE,YAAa,EAAK,CAAC,CAChE,EAaA,MAAO,CACL,QAAA,CAZA,cAAiBF,EAAO,CAAC,EACzB,cAAiB,CACfA,EAAO,EAAE,EACLJ,EAAQ,QAAU,GAAGE,GAAM,QAAQ,CACzC,EACA,SACOC,GACL,IAASI,EAAgB,CAAC,EAAE,aAAa,EAClCL,GAAM,OAAO,IAAM,IAFP,EAMf,EACN,UAAaM,EAAWR,CAAO,EAC/B,YAAeE,GAAM,QAAQ,IAAM,GACnC,aAAgB,CACd,EAAQ,EACV,CACF,CACF,CAkCA,SAAgBO,EAAS,EAAyC,CAChE,IAAMC,EAAMC,EAAQ,EACd,CAAE,UAAS,QAAO,UAAS,YAAaZ,EAAc,EAItDa,EAA2BC,MAAqBC,EAAM,IAAM,CAAC,EAC7DC,EAAWC,EAAY,EAC7B,EAAS,SAAaF,EAAM,EAAI,GAAMF,IAAS,MAAQ,CAACA,EAAK,OAAO,EACpE,IAAMK,EAAUC,EAAaH,MAC3BI,EAAUC,EAAWV,CAAG,MACtBW,EAAgB,CACd,MAAOC,EACP,IAAI,UAAW,CACb,OAAOC,EAAM,QACf,CACF,CAAC,CACH,CACF,EAEMC,EAAgBJ,EAAWV,IAAQ,IAAA,GAAY,IAAA,GAAY,GAAGA,EAAI,EAAE,EAC1E,OAAOe,EACJ,IAECX,EAAM,EAEFY,EAAQ,GAAKC,IAAa,IAAA,GAAkBA,EAC5Cf,IAAS,KACPE,EAAM,EAAI,EAAUK,EAAUK,MAAqBD,EAAM,QAAQ,GACrEK,EAAS,EACDX,EAA0B,GAEhCH,EAAM,IAAM,GAAKF,EAAK,OAAO,GAC/BgB,EAAS,EACDX,EAA0B,GAE7BL,EAAK,aAAa,EAAIO,EAAUK,MAAqBD,EAAM,QAAQ,EAAI,MAEhF,CAAE,YAAa,EAAK,CACtB,CACF,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createBranches as e}from"./branch.js";import{children as t}from"@shadow-js/core";function n(e){return e}function r(e){return typeof e==`object`&&!!e&&`when`in e}function i(e){let t=[];for(let n of e.toArray()){if(!r(n))throw TypeError(`SHADOW_SWITCH_CHILDREN`);t.push(n)}return t}function a(n){let r=t(()=>n.children);return i(r),e(`Switch`,()=>{let e=i(r);for(let[t,n]of e.entries()){let e=n.when;if(e)return{index:t,keyed:n.keyed===!0,when:e,read:()=>n.when,body:()=>n.children}}return{index:-1,keyed:!1,when:void 0,read:()=>void 0,body:()=>void 0}},()=>n.fallback)}export{n as Match,a as Switch};
|
|
2
|
+
//# sourceMappingURL=switch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.js","names":["resolveChildren","Match","props","isMatch","item","matchesOf","matches","resolved","Switch","children","createBranches","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,SAAgBC,EAAS,EAAqC,CAC5D,OAAOC,CACT,CAoBA,SAASC,EAAQ,EAA4C,CAC3D,OAAO,OAAOC,GAAS,YAAYA,GAAiB,SAAUA,CAChE,CAGA,SAASC,EAAU,EAAmD,CACpE,IAAMC,EAAiC,CAAC,EACxC,IAAK,IAAMF,KAAQG,EAAS,QAAQ,EAAG,CACrC,GAAI,CAACJ,EAAQC,CAAI,EACf,MAAU,UACgD,wBAC1D,EACFE,EAAQ,KAAKF,CAAI,CACnB,CACA,OAAOE,CACT,CAgCA,SAAgBE,EAAO,EAAuC,CAC5D,IAAMF,EAAUN,MAAsBE,EAAM,QAAQ,EAGpD,OADAG,EAAUC,CAAO,EACVI,EACL,aACM,CACJ,IAAMC,EAAON,EAAUC,CAAO,EAC9B,IAAK,GAAM,CAACM,EAAOC,KAAUF,EAAK,QAAQ,EAAG,CAC3C,IAAMG,EAAOD,EAAM,KACnB,GAAIC,EACF,MAAO,CACL,QACA,MAAOD,EAAM,QAAU,GACvB,OACA,SAAYA,EAAM,KAClB,SAAYA,EAAM,QACpB,CAEJ,CACA,MAAO,CACL,MAAA,GACA,MAAO,GACP,KAAM,IAAA,GACN,SAAY,IAAA,GACZ,SAAY,IAAA,EACd,CACF,MACMX,EAAM,QACd,CACF,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derived.js","names":["derived","memo","useMemo","compute","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,SAAgBA,EAAW,EAA8B,CACvD,IAAMC,EAAOC,EAAQC,CAAO,EACtBC,IAAS,GAAGC,IAA6B,CAC7C,IAAMC,EAAUL,EAAK,EACrB,OAAO,OAAOK,GAAY,WACrBA,EAAyC,GAAGD,CAAI,EACjDC,CACN,GAEA,OADA,OAAO,eAAeF,EAAM,QAAS,CAAE,IAAKH,CAAK,CAAC,EAC3CG,CACT,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{setAttribute as e}from"./attributes.js";import{style as t}from"./class-style.js";import{nextKey as n}from"./internal/hydration-scope.js";import{claims as r}from"./internal/hydration-hooks.js";import{insert as i}from"./insert.js";import{batch as a,untrack as o,useRenderEffect as s}from"@shadow-js/core";const c=/^[a-z][a-z0-9-]*$/i;function l(e){return e.length>2&&e.startsWith(`on`)&&/^[A-Z]/.test(e.charAt(2))?e.slice(2).toLowerCase():void 0}function u(e,t,n){let r;if(typeof n==`function`)r=t=>n.call(e,t);else if(Array.isArray(n)){let[t,i]=n;typeof t==`function`&&(r=n=>t.call(e,i,n))}if(r===void 0)return;let i=r;e.addEventListener(t,e=>{a(()=>o(()=>i(e)))})}function d(a,o){if(!c.test(a)||a.toLowerCase()===`script`)throw TypeError(`SHADOW_ELEMENT_TAG`);let d=o,f=r.current.claimElement(n())??document.createElement(a);for(let n of Object.keys(o)){if(n===`children`||n===`ref`)continue;let r=l(n);if(r!==void 0)u(f,r,d[n]);else if(n===`style`){let e;s(()=>d[n],n=>{e=t(f,n,e)})}else s(()=>d[n],t=>{e(f,n,t)})}let p=d.ref;return typeof p==`function`&&p(f),i(f,()=>d.children),f}export{d as element};
|
|
2
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.js","names":["TAG_PATTERN","eventNameOf","key","bindListener","call","handler","el","event","fn","data","run","name","batch","untrack","element","tag","read","props","claims","nextKey","applied","useRenderEffect","style","value","setAttribute","ref","\"ref\"","insert","\"children\""],"sources":["../../src/element.ts"],"sourcesContent":["import { batch, untrack, useRenderEffect } from \"@shadow-js/core\";\nimport { setAttribute } 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 { ssrElement, ssrRaw } from \"./server/element\";\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/** `onClick` to `click`, when the key is an event handler name. */\nfunction eventNameOf(key: string): string | undefined {\n return key.length > 2 && key.startsWith(\"on\") && /^[A-Z]/.test(key.charAt(2))\n ? key.slice(2).toLowerCase()\n : undefined;\n}\n\n/**\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 */\nfunction bindListener(el: Element, name: string, handler: unknown): void {\n let call: ((event: Event) => unknown) | undefined;\n if (typeof handler === \"function\") {\n call = (event: Event): unknown => handler.call(el, event);\n } else if (Array.isArray(handler)) {\n const [fn, data] = handler as [unknown, unknown];\n if (typeof fn === \"function\") call = (event: Event): unknown => fn.call(el, data, event);\n }\n if (call === undefined) return;\n const run = call;\n el.addEventListener(name, (event: Event): void => {\n batch(() => untrack(() => run(event)));\n });\n}\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 return children === undefined\n ? undefined\n : [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 const event = eventNameOf(key);\n if (event !== undefined) {\n bindListener(el, event, read[key]);\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 setAttribute(el, key, value);\n },\n );\n }\n }\n const ref = read[\"ref\"];\n if (typeof ref === \"function\") ref(el);\n insert(el, () => read[\"children\"]);\n return el;\n}\n"],"mappings":"A,sTAoBA,MAAMA,EAAc,qBAGpB,SAASC,EAAY,EAAiC,CACpD,OAAOC,EAAI,OAAS,GAAKA,EAAI,WAAW,IAAI,GAAK,SAAS,KAAKA,EAAI,OAAO,CAAC,CAAC,EACxEA,EAAI,MAAM,CAAC,CAAC,CAAC,YAAY,EACzB,IAAA,EACN,CAOA,SAASC,EAAa,EAAa,EAAc,EAAwB,CACvE,IAAIC,EACJ,GAAI,OAAOC,GAAY,WACrB,EAAQ,GAA0BA,EAAQ,KAAKC,EAAIC,CAAK,OACnD,GAAI,MAAM,QAAQF,CAAO,EAAG,CACjC,GAAM,CAACG,EAAIC,GAAQJ,EACf,OAAOG,GAAO,aAAY,EAAQ,GAA0BA,EAAG,KAAKF,EAAIG,EAAMF,CAAK,EACzF,CACA,GAAIH,IAAS,IAAA,GAAW,OACxB,IAAMM,EAAMN,EACZE,EAAG,iBAAiBK,EAAO,GAAuB,CAChDC,MAAYC,MAAcH,EAAIH,CAAK,CAAC,CAAC,CACvC,CAAC,CACH,CAsCA,SAAgBO,EAAQ,EAAa,EAAwB,CAC3D,GAAI,CAACd,EAAY,KAAKe,CAAG,GAAKA,EAAI,YAAY,IAAM,SAClD,MAAU,UAAsD,oBAAoB,EAEtF,IAAMC,EAAOC,EAiBPX,EAFUY,EAAO,QAAQ,aAAaC,EAAQ,CAEnC,GAAK,SAAS,cAAcJ,CAAG,EAChD,IAAK,IAAMb,KAAO,OAAO,KAAKe,CAAK,EAAG,CACpC,GAAIf,IAAQ,YAAcA,IAAQ,MAAO,SACzC,IAAMK,EAAQN,EAAYC,CAAG,EAC7B,GAAIK,IAAU,IAAA,GACZJ,EAAaG,EAAIC,EAAOS,EAAKd,EAAI,OAC5B,GAAIA,IAAQ,QAAS,CAE1B,IAAIkB,EACJC,MACQL,EAAKd,GACV,GAAU,CACT,EAAUoB,EAAMhB,EAAmBiB,EAAOH,CAAO,CACnD,CACF,CACF,MACEC,MACQL,EAAKd,GACV,GAAU,CACTsB,EAAalB,EAAIJ,EAAKqB,CAAK,CAC7B,CACF,CAEJ,CACA,IAAME,EAAMT,EAAKU,IAGjB,OAFI,OAAOD,GAAQ,YAAYA,EAAInB,CAAE,EACrCqB,EAAOrB,MAAUU,EAAKY,QAAW,EAC1BtB,CACT,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{batch as e,getOwner as t,onCleanup as n,untrack as r}from"@shadow-js/core";const i=/* @__PURE__ */ new Set([`click`,`dblclick`,`input`,`keydown`,`keyup`,`keypress`,`pointerdown`,`pointerup`,`pointermove`,`mousedown`,`mouseup`,`mousemove`,`focusin`,`focusout`,`beforeinput`,`touchstart`,`touchend`,`touchmove`,`contextmenu`,`mouseover`,`mouseout`,`pointerover`,`pointerout`]),a=/* @__PURE__ */ new WeakMap;function o(e,t,n,i){Object.defineProperty(n,"currentTarget",{configurable:!0,get:()=>t});try{r(()=>e.fn.call(t,...i))}finally{Reflect.deleteProperty(n,`currentTarget`)}}function s(e,t){return Reflect.get(e,t)}function c(t){e(()=>l(t))}function l(e){let t=`$$${e.type}`,n=`${t}Data`,r=[];for(let i of e.composedPath()){if(e.cancelBubble)break;let a=s(i,t);if(typeof a!=`function`)continue;let c=s(i,n),l={fn:a,data:c,tuple:c!==void 0};try{o(l,i,e,l.tuple?[c,e]:[e])}catch(e){r.push(e)}}let[i]=r;if(r.length===1)throw i;if(r.length>1)throw AggregateError(r,`SHADOW_EVENT_ERRORS`)}function u(e){return typeof e==`object`&&!!e&&typeof e.handleEvent==`function`}function d(t,n,i,a){let o={capture:i.capture===!0||a};i.once!==void 0&&(o.once=i.once),i.passive!==void 0&&(o.passive=i.passive),i.signal!==void 0&&(o.signal=i.signal);let s=t=>{e(()=>r(()=>i.handleEvent(t)))};return t.addEventListener(n,s,o),()=>{t.removeEventListener(n,s,o)}}function f(e){if(typeof e==`function`)return{fn:e,data:void 0,tuple:!1};if(Array.isArray(e)&&typeof e[0]==`function`)return{fn:e[0],data:e[1],tuple:!0};throw TypeError(`SHADOW_EVENT_HANDLER`)}function p(...e){return function(t){for(let n of e)n.call(this,t)}}function m(e,t=globalThis.document){let n=a.get(t);n===void 0&&(n=/* @__PURE__ */ new Set,a.set(t,n));for(let r of e)n.has(r)||(n.add(r),t.addEventListener(r,c))}function h(e=globalThis.document){let t=a.get(e);if(t!==void 0){for(let n of t)e.removeEventListener(n,c);a.delete(e)}}function g(e){let t=e.ownerDocument;return t!==null&&t.defaultView!==null?t:globalThis.document}function _(t,n,a,o,s=!1){if(a==null||a===!1)return;if(u(a))return d(t,n,a,s);let c=f(a),l=`$$${n}`;if(o&&!s&&i.has(n)&&Reflect.get(t,l)===void 0){m([n],g(t));let e=`${l}Data`;return Reflect.set(t,l,c.fn),c.tuple?Reflect.set(t,e,c.data):Reflect.deleteProperty(t,e),()=>{Reflect.get(t,l)===c.fn&&(Reflect.deleteProperty(t,l),Reflect.deleteProperty(t,e))}}let p=n=>{let i=c.tuple?[c.data,n]:[n];e(()=>r(()=>c.fn.call(t,...i)))};return t.addEventListener(n,p,s),()=>{t.removeEventListener(n,p,s)}}function v(e,r,i,a,o){let s=_(e,r,i,a===!0,o===!0);s!==void 0&&t()!==null&&n(s)}export{v as addEventListener,_ as bindEvent,p as chainEvents,h as clearDelegatedEvents,m as delegateEvents};
|
|
2
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","names":["holder","DELEGATED_EVENTS","installed","invoke","event","node","untrack","binding","args","expando","key","dispatchDelegated","batch","dispatchPath","dataKey","errors","fn","data","error","first","isListenerObject","handler","bindListenerObject","options","object","capture","listener","el","name","toBinding","chainEvents","handlers","delegateEvents","known","target","names","clearDelegatedEvents","delegationDocument","owner","bindEvent","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 = new Set([\n \"click\",\n \"dblclick\",\n \"input\",\n \"keydown\",\n \"keyup\",\n \"keypress\",\n \"pointerdown\",\n \"pointerup\",\n \"pointermove\",\n \"mousedown\",\n \"mouseup\",\n \"mousemove\",\n \"focusin\",\n \"focusout\",\n \"beforeinput\",\n \"touchstart\",\n \"touchend\",\n \"touchmove\",\n \"contextmenu\",\n \"mouseover\",\n \"mouseout\",\n \"pointerover\",\n \"pointerout\",\n]);\n\n/** Documents that already carry the delegated listener for a given event name. */\nconst installed = new WeakMap<Document, Set<string>>();\n\n/** A handler together with its optional data; `tuple` records the `[fn, data]` form. */\ninterface Binding {\n readonly fn: (this: EventTarget, ...args: unknown[]) => unknown;\n readonly data: unknown;\n readonly tuple: boolean;\n}\n\n/** Calls `fn` with `this` = node, retargeting `currentTarget` for the duration of the call. */\nfunction invoke(binding: Binding, node: EventTarget, event: Event, args: unknown[]): void {\n Object.defineProperty(event, \"currentTarget\", { configurable: true, get: () => node });\n try {\n untrack(() => binding.fn.call(node, ...args));\n } finally {\n Reflect.deleteProperty(event, \"currentTarget\");\n }\n}\n\n/** Reads a compiler-style expando (`node.$$click`), if present. */\nfunction expando(node: EventTarget, key: string): unknown {\n const holder: object = node;\n return Reflect.get(holder, key);\n}\n\n/**\n * The one listener per (document, event). It walks `composedPath()` from the target outward,\n * calling `node.$$<type>` with `this = node`. 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(() => dispatchPath(event));\n}\n\nfunction dispatchPath(event: Event): void {\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 = expando(node, key);\n if (typeof fn !== \"function\") continue;\n const data = expando(node, dataKey);\n const binding: Binding = {\n fn: fn as (this: EventTarget, ...args: unknown[]) => unknown,\n data,\n tuple: data !== undefined,\n };\n try {\n invoke(binding, node, event, binding.tuple ? [data, event] : [event]);\n } catch (error) {\n errors.push(error);\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/** 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/** 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 options: AddEventListenerOptions = { capture: object.capture === true || capture };\n if (object.once !== undefined) options.once = object.once;\n if (object.passive !== undefined) options.passive = object.passive;\n if (object.signal !== undefined) options.signal = object.signal;\n const listener = (event: Event): void => {\n batch(() => untrack(() => object.handleEvent(event)));\n };\n el.addEventListener(name, listener, options);\n return () => {\n el.removeEventListener(name, listener, options);\n };\n}\n\n/** Normalizes a handler value into a binding; throws for values that are neither. */\nfunction toBinding(handler: unknown): Binding {\n if (typeof handler === \"function\") {\n return { fn: handler as Binding[\"fn\"], data: undefined, tuple: false };\n }\n if (Array.isArray(handler) && typeof handler[0] === \"function\") {\n return { fn: handler[0] as Binding[\"fn\"], data: handler[1], tuple: true };\n }\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\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/**\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 let known = installed.get(target);\n if (known === undefined) {\n known = new Set<string>();\n installed.set(target, known);\n }\n for (const name of names) {\n if (known.has(name)) continue;\n known.add(name);\n target.addEventListener(name, dispatchDelegated);\n }\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 const binding = toBinding(handler);\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 if (delegate && !capture && DELEGATED_EVENTS.has(name) && Reflect.get(el, slot) === undefined) {\n delegateEvents([name], delegationDocument(el));\n const dataKey = `${slot}Data`;\n Reflect.set(el, slot, binding.fn);\n if (binding.tuple) Reflect.set(el, dataKey, binding.data);\n else Reflect.deleteProperty(el, dataKey);\n return () => {\n if (Reflect.get(el, slot) === binding.fn) {\n Reflect.deleteProperty(el, slot);\n Reflect.deleteProperty(el, dataKey);\n }\n };\n }\n const listener = (event: Event): void => {\n const args: unknown[] = binding.tuple ? [binding.data, event] : [event];\n batch(() => untrack(() => binding.fn.call(el, ...args)));\n };\n el.addEventListener(name, listener, capture);\n return () => {\n el.removeEventListener(name, listener, capture);\n };\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,MAAMC,kBAAmB,IAAI,IAAI,CAC/B,QACA,WACA,QACA,UACA,QACA,WACA,cACA,YACA,cACA,YACA,UACA,YACA,UACA,WACA,cACA,aACA,WACA,YACA,cACA,YACA,WACA,cACA,YACF,CAAC,EAGKC,kBAAY,IAAI,QAUtB,SAASC,EAAO,EAAkB,EAAmB,EAAc,EAAuB,CACxF,OAAO,eAAeC,EAAO,gBAAiB,CAAE,aAAc,GAAM,QAAWC,CAAK,CAAC,EACrF,GAAI,CACFC,MAAcC,EAAQ,GAAG,KAAKF,EAAM,GAAGG,CAAI,CAAC,CAC9C,QAAU,CACR,QAAQ,eAAeJ,EAAO,eAAe,CAC/C,CACF,CAGA,SAASK,EAAQ,EAAmB,EAAsB,CAExD,OAAO,QAAQ,IAAIT,EAAQU,CAAG,CAChC,CAMA,SAASC,EAAkB,EAAoB,CAG7CC,MAAYC,EAAaT,CAAK,CAAC,CACjC,CAEA,SAASS,EAAa,EAAoB,CACxC,IAAMH,EAAM,KAAKN,EAAM,OACjBU,EAAU,GAAGJ,EAAI,MACjBK,EAAoB,CAAC,EAC3B,IAAK,IAAMV,KAAQD,EAAM,aAAa,EAAG,CACvC,GAAIA,EAAM,aAAc,MACxB,IAAMY,EAAKP,EAAQJ,EAAMK,CAAG,EAC5B,GAAI,OAAOM,GAAO,WAAY,SAC9B,IAAMC,EAAOR,EAAQJ,EAAMS,CAAO,EAC5BP,EAAmB,CACnB,KACJ,OACA,MAAOU,IAAS,IAAA,EAClB,EACA,GAAI,CACFd,EAAOI,EAASF,EAAMD,EAAOG,EAAQ,MAAQ,CAACU,EAAMb,CAAK,EAAI,CAACA,CAAK,CAAC,CACtE,OAASc,EAAO,CACdH,EAAO,KAAKG,CAAK,CACnB,CACF,CACA,GAAM,CAACC,GAASJ,EAChB,GAAIA,EAAO,SAAW,EAAG,MAAMI,EAC/B,GAAIJ,EAAO,OAAS,EAClB,MAAU,eACRA,EAC4C,qBAC9C,CACJ,CAWA,SAASK,EAAiB,EAA6C,CACrE,OACE,OAAOC,GAAY,YACnBA,GACA,OAAQA,EAAsC,aAAgB,UAElE,CAGA,SAASC,EACP,EACA,EACA,EACA,EACY,CACZ,IAAMC,EAAmC,CAAE,QAASC,EAAO,UAAY,IAAQC,CAAQ,EACnFD,EAAO,OAAS,IAAA,KAAW,EAAQ,KAAOA,EAAO,MACjDA,EAAO,UAAY,IAAA,KAAW,EAAQ,QAAUA,EAAO,SACvDA,EAAO,SAAW,IAAA,KAAW,EAAQ,OAASA,EAAO,QACzD,IAAME,EAAY,GAAuB,CACvCd,MAAYN,MAAckB,EAAO,YAAYpB,CAAK,CAAC,CAAC,CACtD,EAEA,OADAuB,EAAG,iBAAiBC,EAAMF,EAAUH,CAAO,MAC9B,CACXI,EAAG,oBAAoBC,EAAMF,EAAUH,CAAO,CAChD,CACF,CAGA,SAASM,EAAU,EAA2B,CAC5C,GAAI,OAAOR,GAAY,WACrB,MAAO,CAAE,GAAIA,EAA0B,KAAM,IAAA,GAAW,MAAO,EAAM,EAEvE,GAAI,MAAM,QAAQA,CAAO,GAAK,OAAOA,EAAQ,IAAO,WAClD,MAAO,CAAE,GAAIA,EAAQ,GAAqB,KAAMA,EAAQ,GAAI,MAAO,EAAK,EAE1E,MAAU,UAGJ,sBACN,CACF,CAqBA,SAAgBS,EACd,GAAGC,EACwC,CAC3C,OAAO,SAAoC,EAAoB,CAC7D,IAAK,IAAMV,KAAWU,EAAUV,EAAQ,KAAK,KAAMjB,CAAK,CAC1D,CACF,CAmBA,SAAgB4B,EAAe,EAAiB,EAAmB,WAAW,SAAgB,CAC5F,IAAIC,EAAQ/B,EAAU,IAAIgC,CAAM,EAC5BD,IAAU,IAAA,KACZ,kBAAQ,IAAI,IACZ/B,EAAU,IAAIgC,EAAQD,CAAK,GAE7B,IAAK,IAAML,KAAQO,EACbF,EAAM,IAAIL,CAAI,IAClBK,EAAM,IAAIL,CAAI,EACdM,EAAO,iBAAiBN,EAAMjB,CAAiB,EAEnD,CAmBA,SAAgByB,EAAqB,EAAmB,WAAW,SAAgB,CACjF,IAAMH,EAAQ/B,EAAU,IAAIgC,CAAM,EAClC,GAAID,IAAU,IAAA,GACd,KAAK,IAAML,KAAQK,EAAOC,EAAO,oBAAoBN,EAAMjB,CAAiB,EAC5ET,EAAU,OAAOgC,CAAM,CADqD,CAE9E,CAOA,SAASG,EAAmB,EAAuB,CACjD,IAAMC,EAAQX,EAAG,cACjB,OAAOW,IAAU,MAAQA,EAAM,cAAgB,KAAOA,EAAQ,WAAW,QAC3E,CASA,SAAgBC,EACd,EACA,EACA,EACA,EACA,EAAU,GACgB,CAC1B,GAAIlB,GAAY,MAAiCA,IAAY,GAAO,OACpE,GAAID,EAAiBC,CAAO,EAAG,OAAOC,EAAmBK,EAAIC,EAAMP,EAASI,CAAO,EACnF,IAAMlB,EAAUsB,EAAUR,CAAO,EAG3BmB,EAAO,KAAKZ,IAClB,GAAIa,GAAY,CAAChB,GAAWxB,EAAiB,IAAI2B,CAAI,GAAK,QAAQ,IAAID,EAAIa,CAAI,IAAM,IAAA,GAAW,CAC7FR,EAAe,CAACJ,CAAI,EAAGS,EAAmBV,CAAE,CAAC,EAC7C,IAAMb,EAAU,GAAG0B,EAAK,MAIxB,OAHA,QAAQ,IAAIb,EAAIa,EAAMjC,EAAQ,EAAE,EAC5BA,EAAQ,MAAO,QAAQ,IAAIoB,EAAIb,EAASP,EAAQ,IAAI,EACnD,QAAQ,eAAeoB,EAAIb,CAAO,MAC1B,CACP,QAAQ,IAAIa,EAAIa,CAAI,IAAMjC,EAAQ,KACpC,QAAQ,eAAeoB,EAAIa,CAAI,EAC/B,QAAQ,eAAeb,EAAIb,CAAO,EAEtC,CACF,CACA,IAAMY,EAAY,GAAuB,CACvC,IAAMlB,EAAkBD,EAAQ,MAAQ,CAACA,EAAQ,KAAMH,CAAK,EAAI,CAACA,CAAK,EACtEQ,MAAYN,MAAcC,EAAQ,GAAG,KAAKoB,EAAI,GAAGnB,CAAI,CAAC,CAAC,CACzD,EAEA,OADAmB,EAAG,iBAAiBC,EAAMF,EAAUD,CAAO,MAC9B,CACXE,EAAG,oBAAoBC,EAAMF,EAAUD,CAAO,CAChD,CACF,CA6BA,SAAgBiB,EACd,EACA,EACA,EACA,EACA,EACM,CACN,IAAMC,EAASJ,EAAUZ,EAAIC,EAAMP,EAASoB,IAAa,GAAMhB,IAAY,EAAI,EAE3EkB,IAAW,IAAA,IAAaC,EAAS,IAAM,MAAMC,EAAUF,CAAM,CACnE,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{warnOnce as e}from"./internal/diagnostics.js";import{isUnsafeUrlAttribute as t}from"./attributes.js";import{HTML_NS as n,MATHML_NS as r,SVG_NS as i}from"./internal/names.js";import{childScope as a,createRootScope as o,currentScope as s,enterComponent as c,nextKey as l,resourceKey as u,withScope as d}from"./internal/hydration-scope.js";import{claimElement as f,claimPortal as p,isClaiming as m,takeRegion as h,withoutClaiming as g}from"./internal/claim.js";import{claims as _}from"./internal/hydration-hooks.js";import{reconcileNodes as v}from"./internal/reconcile.js";import{bindRegion as y,createRegion as b,removeRegion as x}from"./insert.js";import{element as S}from"./element.js";import{PortalContext as C}from"./internal/portal-context.js";import{StreamContext as w}from"./internal/stream-context.js";export{n as HTML_NS,r as MATHML_NS,C as PortalContext,i as SVG_NS,w as StreamContext,y as bindRegion,a as childScope,f as claimElement,p as claimPortal,_ as claims,b as createRegion,o as createRootScope,s as currentScope,S as element,c as enterComponent,m as isClaiming,t as isUnsafeUrlAttribute,l as nextKey,v as reconcileNodes,x as removeRegion,u as resourceKey,h as takeRegion,e as warnOnce,d as withScope,g as withoutClaiming};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{useHead as e}from"./use-head.js";function t(e){if(typeof e==`string`)return e;if(typeof e==`number`)return String(e);if(e==null||e===!1)return``;throw TypeError(`SHADOW_HEAD_TITLE_TEXT`)}function n(e){let n=typeof e==`function`?e():e;return Array.isArray(n)?n.map(t).join(``):t(n)}function r(e){if(e!=null){if(typeof e==`string`&&e!==``)return e;throw TypeError(`SHADOW_HEAD_KEY`)}}function i(e){if(e!=null&&e!==!1){if(e===!0)return!0;if(typeof e==`string`||typeof e==`number`)return e;throw TypeError(`SHADOW_HEAD_ATTRIBUTE_VALUE`)}}function a(e,t){let n=[];for(let r of Object.keys(e))t.includes(r)||n.push([r,i(Reflect.get(e,r))]);return Object.fromEntries(n)}function o(e,t,n){return{tag:e,props:a(t,n)}}function s(t){return e(()=>({tag:`title`,children:n(t.children)})),null}function c(t){return e(()=>o(`meta`,t,[`children`])),null}function l(t){return e(()=>o(`link`,t,[`children`])),null}function u(t){return e(()=>{let e=a(t,[`children`,`key`]),i=t.children===void 0?void 0:n(t.children),o=r(t.key);return{tag:`style`,props:e,...i===void 0?{}:{children:i},...o===void 0?{}:{key:o}}}),null}function d(t){return e(()=>o(`base`,t,[`children`])),null}export{d as Base,l as Link,c as Meta,u as Style,s as Title};
|
|
2
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=()=>void 0;function t(t){let n=/* @__PURE__ */ new Map,r=0;return{add(i){if(i.length===0)return e;let a=[];for(let e of i){let t=e.identity;t===void 0&&(t=`#${r}`,r+=1);let i=n.get(t);i===void 0&&(i=[],n.set(t,i));let o={slot:t,tag:e};i.push(o),a.push(o)}t();let o=!1;return()=>{if(!o){o=!0;for(let e of a){let t=n.get(e.slot);if(t===void 0)continue;let r=t.indexOf(e);r!==-1&&t.splice(r,1),t.length===0&&n.delete(e.slot)}t()}}},winners(){let e=[];for(let[t,r]of n){let n=r[r.length-1];n!==void 0&&e.push({slot:t,tag:n.tag})}return e}}}export{t as createHeadRegistry};
|
|
2
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","names":["noop","createHeadRegistry","stacks","appendOnly","tags","entries","tag","slot","stack","entry","onChange","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,EAAmB,EAAoC,CACrE,IAAMC,kBAAS,IAAI,IACfC,EAAa,EACjB,MAAO,CACL,IAAI,EAA4C,CAC9C,GAAIC,EAAK,SAAW,EAAG,OAAOJ,EAC9B,IAAMK,EAAmB,CAAC,EAC1B,IAAK,IAAMC,KAAOF,EAAM,CACtB,IAAIG,EAAOD,EAAI,SACXC,IAAS,IAAA,KACX,EAAO,IAAIJ,IACX,GAAc,GAEhB,IAAIK,EAAQN,EAAO,IAAIK,CAAI,EACvBC,IAAU,IAAA,KACZ,EAAQ,CAAC,EACTN,EAAO,IAAIK,EAAMC,CAAK,GAExB,IAAMC,EAAe,CAAE,OAAM,KAAI,EACjCD,EAAM,KAAKC,CAAK,EAChBJ,EAAQ,KAAKI,CAAK,CACpB,CACAC,EAAS,EACT,IAAIC,EAAU,GACd,UAAmB,CACjB,GAAI,GACJ,GAAU,GACV,IAAK,IAAMF,KAASJ,EAAS,CAC3B,IAAMG,EAAQN,EAAO,IAAIO,EAAM,IAAI,EACnC,GAAID,IAAU,IAAA,GAAW,SACzB,IAAMI,EAAQJ,EAAM,QAAQC,CAAK,EAC7BG,IAAU,IAAIJ,EAAM,OAAOI,EAAO,CAAC,EACnCJ,EAAM,SAAW,GAAGN,EAAO,OAAOO,EAAM,IAAI,CAClD,CACAC,EAAS,CARC,CASZ,CACF,EACA,SAAwB,CACtB,IAAMG,EAAwB,CAAC,EAC/B,IAAK,GAAM,CAACN,EAAMC,KAAUN,EAAQ,CAClC,IAAMY,EAAMN,EAAMA,EAAM,OAAS,GAC7BM,IAAQ,IAAA,IAAWD,EAAQ,KAAK,CAAE,OAAM,IAAKC,EAAI,GAAI,CAAC,CAC5D,CACA,OAAOD,CACT,CACF,CACF,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{escapeHtml as e}from"../server/escape.js";import{createHeadRegistry as t}from"./registry.js";import{HEAD_KEY as n,HEAD_MARKER as r}from"./validate.js";import{createContext as i}from"@shadow-js/core";const a=/* @__PURE__ */ new Set([`meta`,`link`,`base`]),o=/* @__PURE__ */ i(null,{name:`ServerHead`});function s(t,i){let o=` ${r}`;t.key!==void 0&&(o+=` ${n}="${e(t.key)}"`);for(let[n,r]of t.attributes)o+=r===``?` ${n}`:` ${n}="${e(r)}"`;if(a.has(t.tag))return`<${t.tag}${o}>`;let s=t.text??``;if(t.tag===`style`){if(/<\/style/i.test(s))throw TypeError(`ShadowJS head: style text may not contain a closing style tag.`);return`<style${i===void 0?o:`${o} nonce="${e(i)}"`}>${s}</style>`}return`<${t.tag}${o}>${e(s)}</${t.tag}>`}function c(){let e=t(()=>void 0);return{add:t=>e.add(t),clear(){e=t(()=>void 0)},html:t=>e.winners().map(e=>s(e.tag,t?.nonce)).join(``),tags:()=>e.winners().map(e=>e.tag)}}function l(e,t){if(e===void 0)return t();let n={};return o({value:e,get children(){return n.value=t(),null}}),n.value}export{o as ServerHeadContext,c as createServerHead,l as runWithServerHead};
|
|
2
|
+
//# sourceMappingURL=server-head.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-head.js","names":["VOID_TAGS","ServerHeadContext","tagHtml","attributes","HEAD_MARKER","tag","HEAD_KEY","escapeHtml","name","value","text","nonce","createServerHead","registry","createHeadRegistry","tags","winner","options","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,MAAMA,kBAAiC,IAAI,IAAI,CAAC,OAAQ,OAAQ,MAAM,CAAC,EA+B1DC,EACK,kBAAiC,KAAM,CAAE,KAAM,YAAa,CAAC,EAG/E,SAASC,EAAQ,EAAoB,EAAmC,CACtE,IAAIC,EAAa,IAAIC,IACjBC,EAAI,MAAQ,IAAA,KAAW,GAAc,IAAIC,EAAS,IAAIC,EAAWF,EAAI,GAAG,EAAE,IAC9E,IAAK,GAAM,CAACG,EAAMC,KAAUJ,EAAI,WAC9B,GAAcI,IAAU,GAAK,IAAID,IAAS,IAAIA,EAAK,IAAID,EAAWE,CAAK,EAAE,GAE3E,GAAIT,EAAU,IAAIK,EAAI,GAAG,EAAG,MAAO,IAAIA,EAAI,MAAMF,EAAW,GAC5D,IAAMO,EAAOL,EAAI,MAAQ,GACzB,GAAIA,EAAI,MAAQ,QAAS,CACvB,GAAI,YAAY,KAAKK,CAAI,EACvB,MAAU,UAAU,gEAAgE,EAItF,MAAO,SADLC,IAAU,IAAA,GAAYR,EAAa,GAAGA,EAAW,UAAUI,EAAWI,CAAK,EAAE,GACrD,GAAGD,EAAK,SACpC,CACA,MAAO,IAAIL,EAAI,MAAMF,EAAW,GAAGI,EAAWG,CAAI,EAAE,IAAIL,EAAI,IAAI,EAClE,CAqBA,SAAgBO,GAA+B,CAC7C,IAAIC,EAAyBC,MAAyB,IAAA,EAAS,EAC/D,MAAO,CACL,IAAM,GAASD,EAAS,IAAIE,CAAI,EAChC,OAAQ,CACN,EAAWD,MAAyB,IAAA,EAAS,CAC/C,EACA,KAAO,GACLD,EACG,QAAQ,CAAC,CACT,IAAK,GAAWX,EAAQc,EAAO,IAAKC,GAAS,KAAK,CAAC,CAAC,CACpD,KAAK,EAAE,EACZ,SAAYJ,EAAS,QAAQ,CAAC,CAAC,IAAK,GAAWG,EAAO,GAAG,CAC3D,CACF,CAMA,SAAgBE,EAAqB,EAA8B,EAAgB,CACjF,GAAIC,IAAS,IAAA,GAAW,OAAOC,EAAG,EAClC,IAAMC,EAAwB,CAAC,EAQ/B,OAPApB,EAAkB,CAChB,MAAOkB,EACP,IAAI,UAAW,CAEb,MADA,GAAO,MAAQC,EAAG,EACX,IACT,CACF,CAAC,EACMC,EAAO,KAChB,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{HEAD_KEY as e,HEAD_MARKER as t,identityOfElement as n}from"./validate.js";function r(e,t){let n=t.el;n.parentNode===e&&(n.localName===`title`&&!t.created?t.restoreText!==void 0&&n.textContent!==t.restoreText&&(n.textContent=t.restoreText):n.remove())}function i(e,t,r,i){if(r.identity!==void 0){for(let a of Array.from(e.querySelectorAll(r.tag)))if(!i.has(a)&&n(a)===t&&(a.hasAttribute(`data-shadow-head`)||r.tag===`title`))return a}}function a(n,r,a,o){let s=n.head,c=i(s,r,a,o);if(c!==void 0)return{el:c,created:!1,restoreText:a.tag===`title`?c.textContent:void 0,attributes:[]};let l=n.createElement(a.tag);return l.setAttribute(t,``),a.key!==void 0&&l.setAttribute(e,a.key),a.tag===`base`?s.insertBefore(l,s.firstChild):s.appendChild(l),{el:l,created:!0,restoreText:void 0,attributes:[]}}function o(e,t){let n=e.el,r=new Map(t.attributes);for(let[t]of e.attributes)r.has(t)||n.removeAttribute(t);for(let[e,r]of t.attributes)n.getAttribute(e)!==r&&n.setAttribute(e,r);if(e.attributes=t.attributes,t.tag===`title`||t.tag===`style`){let e=t.text??``;n.textContent!==e&&(n.textContent=e)}}function s(e){let t=/* @__PURE__ */ new Map;return n=>{let i=e.head,s=new Set(n.map(e=>e.slot));for(let[e,n]of t)s.has(e)&&n.el.parentNode===i||(t.delete(e),r(i,n));let c=/* @__PURE__ */ new Set;for(let e of t.values())c.add(e.el);for(let r of n){let n=t.get(r.slot);n===void 0&&(n=a(e,r.slot,r.tag,c),t.set(r.slot,n),c.add(n.el)),o(n,r.tag)}}}export{s as createDomHeadSink};
|
|
2
|
+
//# sourceMappingURL=sink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sink.js","names":["release","el","record","head","adoptable","tag","candidate","identityOfElement","slot","acquire","doc","existing","claimed","HEAD_MARKER","HEAD_KEY","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 }\n };\n}\n"],"mappings":"A,iFAiBA,SAASA,EAAQ,EAAuB,EAAqB,CAC3D,IAAMC,EAAKC,EAAO,GACdD,EAAG,aAAeE,IAClBF,EAAG,YAAc,SAAW,CAACC,EAAO,QAClCA,EAAO,cAAgB,IAAA,IAAaD,EAAG,cAAgBC,EAAO,cAChE,EAAG,YAAcA,EAAO,aAI5BD,EAAG,OAAO,EACZ,CAOA,SAASG,EACP,EACA,EACA,EACA,EACqB,CACrB,GAAIC,EAAI,WAAa,IAAA,GACrB,KAAK,IAAMC,KAAa,MAAM,KAAKH,EAAK,iBAAiBE,EAAI,GAAG,CAAC,EAC/D,GAAI,GAAQ,IAAIC,CAAS,GACrBC,EAAkBD,CAAS,IAAME,IACjCF,EAAU,aAAA,kBAAwB,GAAKD,EAAI,MAAQ,SAAS,OAAOC,CACzE,CAEF,CAGA,SAASG,EAAQ,EAAe,EAAc,EAAoB,EAA8B,CAC9F,IAAMN,EAAOO,EAAI,KACXC,EAAWP,EAAUD,EAAMK,EAAMH,EAAKO,CAAO,EACnD,GAAID,IAAa,IAAA,GAEf,MAAO,CAAE,GAAIA,EAAU,QAAS,GAAO,YADnBN,EAAI,MAAQ,QAAUM,EAAS,YAAc,IAAA,GACb,WAAY,CAAC,CAAE,EAErE,IAAMV,EAAKS,EAAI,cAAcL,EAAI,GAAG,EAKpC,OAJAJ,EAAG,aAAaY,EAAa,EAAE,EAC3BR,EAAI,MAAQ,IAAA,IAAWJ,EAAG,aAAaa,EAAUT,EAAI,GAAG,EACxDA,EAAI,MAAQ,OAAQF,EAAK,aAAaF,EAAIE,EAAK,UAAU,EACxDA,EAAK,YAAYF,CAAE,EACjB,CAAE,KAAI,QAAS,GAAM,YAAa,IAAA,GAAW,WAAY,CAAC,CAAE,CACrE,CAGA,SAASc,EAAK,EAAe,EAA0B,CACrD,IAAMd,EAAKC,EAAO,GACZc,EAAS,IAAI,IAAoBX,EAAI,UAAU,EACrD,IAAK,GAAM,CAACY,KAASf,EAAO,WACrBc,EAAO,IAAIC,CAAI,GAAGhB,EAAG,gBAAgBgB,CAAI,EAEhD,IAAK,GAAM,CAACA,EAAMC,KAAUb,EAAI,WAC1BJ,EAAG,aAAagB,CAAI,IAAMC,GAAOjB,EAAG,aAAagB,EAAMC,CAAK,EAGlE,GADA,EAAO,WAAab,EAAI,WACpBA,EAAI,MAAQ,SAAWA,EAAI,MAAQ,QAAS,CAC9C,IAAMc,EAAOd,EAAI,MAAQ,GACrBJ,EAAG,cAAgBkB,IAAM,EAAG,YAAcA,EAChD,CACF,CAYA,SAAgBC,EAAkB,EAAyD,CACzF,IAAMC,kBAAQ,IAAI,IAClB,MAAQ,IAAyC,CAC/C,IAAMlB,EAAOO,EAAI,KACXM,EAAS,IAAI,IAAIM,EAAQ,IAAK,GAAWC,EAAO,IAAI,CAAC,EAC3D,IAAK,GAAM,CAACf,EAAMN,KAAWmB,EACvBL,EAAO,IAAIR,CAAI,GAAKN,EAAO,GAAG,aAAeC,IACjDkB,EAAM,OAAOb,CAAI,EACjBR,EAAQG,EAAMD,CAAM,GAEtB,IAAMU,kBAAU,IAAI,IACpB,IAAK,IAAMV,KAAUmB,EAAM,OAAO,EAAGT,EAAQ,IAAIV,EAAO,EAAE,EAC1D,IAAK,IAAMqB,KAAUD,EAAS,CAC5B,IAAIpB,EAASmB,EAAM,IAAIE,EAAO,IAAI,EAC9BrB,IAAW,IAAA,KACb,EAASO,EAAQC,EAAKa,EAAO,KAAMA,EAAO,IAAKX,CAAO,EACtDS,EAAM,IAAIE,EAAO,KAAMrB,CAAM,EAC7BU,EAAQ,IAAIV,EAAO,EAAE,GAEvBa,EAAKb,EAAQqB,EAAO,GAAG,CACzB,CACF,CACF,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createHeadRegistry as e}from"./registry.js";import{normalizeTags as t}from"./validate.js";import{ServerHeadContext as n}from"./server-head.js";import{createDomHeadSink as r}from"./sink.js";import{createRoot as i,getOwner as a,isServer as o,untrack as s,useContext as c,useEffect as l,useRenderEffect as u,useSignal as d}from"@shadow-js/core";const f=/* @__PURE__ */ new WeakMap;function p(t){return i(()=>{let[n,i]=d(0),a=e(()=>{i(e=>e+1)}),o=r(t);return l(()=>(n(),a.winners()),e=>{o(e)}),a},{detached:!0})}function m(e){let t=f.get(e);if(t!==void 0)return t;let n=p(e);return f.set(e,n),n}function h(e){if(o){let r=a()===null?null:c(n);r!==null&&r.add(t(s(()=>typeof e==`function`?e():e)));return}if(a()===null)return;let r=m(document);u(()=>t(typeof e==`function`?e():e),e=>r.add(e))}export{h as useHead};
|
|
2
|
+
//# sourceMappingURL=use-head.js.map
|