@shadow-js/web 0.0.0-stage → 1.0.0
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 +12 -0
- package/LICENSE +21 -0
- package/README.md +190 -2
- package/dist/dev/attributes.d.ts +90 -0
- package/dist/dev/attributes.js +196 -0
- package/dist/dev/attributes.js.map +1 -0
- package/dist/dev/autofocus.d.ts +32 -0
- package/dist/dev/autofocus.js +45 -0
- package/dist/dev/autofocus.js.map +1 -0
- package/dist/dev/class-style.d.ts +89 -0
- package/dist/dev/class-style.js +197 -0
- package/dist/dev/class-style.js.map +1 -0
- package/dist/dev/component.d.ts +23 -0
- package/dist/dev/component.js +42 -0
- package/dist/dev/component.js.map +1 -0
- package/dist/dev/control-flow/activity.d.ts +58 -0
- package/dist/dev/control-flow/activity.js +136 -0
- package/dist/dev/control-flow/activity.js.map +1 -0
- package/dist/dev/control-flow/branch.js +104 -0
- package/dist/dev/control-flow/branch.js.map +1 -0
- package/dist/dev/control-flow/client-only.d.ts +48 -0
- package/dist/dev/control-flow/client-only.js +50 -0
- package/dist/dev/control-flow/client-only.js.map +1 -0
- package/dist/dev/control-flow/dynamic.d.ts +82 -0
- package/dist/dev/control-flow/dynamic.js +134 -0
- package/dist/dev/control-flow/dynamic.js.map +1 -0
- package/dist/dev/control-flow/error-boundary.d.ts +72 -0
- package/dist/dev/control-flow/error-boundary.js +115 -0
- package/dist/dev/control-flow/error-boundary.js.map +1 -0
- package/dist/dev/control-flow/for.d.ts +80 -0
- package/dist/dev/control-flow/for.js +23 -0
- package/dist/dev/control-flow/for.js.map +1 -0
- package/dist/dev/control-flow/fragment.d.ts +38 -0
- package/dist/dev/control-flow/fragment.js +31 -0
- package/dist/dev/control-flow/fragment.js.map +1 -0
- package/dist/dev/control-flow/hot-link.js +64 -0
- package/dist/dev/control-flow/hot-link.js.map +1 -0
- package/dist/dev/control-flow/index-list.d.ts +48 -0
- package/dist/dev/control-flow/index-list.js +31 -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 +58 -0
- package/dist/dev/control-flow/lazy.js +64 -0
- package/dist/dev/control-flow/lazy.js.map +1 -0
- package/dist/dev/control-flow/no-hydration.d.ts +39 -0
- package/dist/dev/control-flow/no-hydration.js +58 -0
- package/dist/dev/control-flow/no-hydration.js.map +1 -0
- package/dist/dev/control-flow/portal.d.ts +69 -0
- package/dist/dev/control-flow/portal.js +134 -0
- package/dist/dev/control-flow/portal.js.map +1 -0
- package/dist/dev/control-flow/root-errors.d.ts +25 -0
- package/dist/dev/control-flow/root-errors.js +33 -0
- package/dist/dev/control-flow/root-errors.js.map +1 -0
- package/dist/dev/control-flow/show.d.ts +101 -0
- package/dist/dev/control-flow/show.js +18 -0
- package/dist/dev/control-flow/show.js.map +1 -0
- package/dist/dev/control-flow/suspense-list.d.ts +65 -0
- package/dist/dev/control-flow/suspense-list.js +105 -0
- package/dist/dev/control-flow/suspense-list.js.map +1 -0
- package/dist/dev/control-flow/suspense.d.ts +53 -0
- package/dist/dev/control-flow/suspense.js +102 -0
- package/dist/dev/control-flow/suspense.js.map +1 -0
- package/dist/dev/control-flow/switch.d.ts +85 -0
- package/dist/dev/control-flow/switch.js +90 -0
- package/dist/dev/control-flow/switch.js.map +1 -0
- package/dist/dev/derived.d.ts +52 -0
- package/dist/dev/derived.js +34 -0
- package/dist/dev/derived.js.map +1 -0
- package/dist/dev/element.d.ts +40 -0
- package/dist/dev/element.js +105 -0
- package/dist/dev/element.js.map +1 -0
- package/dist/dev/events.d.ts +87 -0
- package/dist/dev/events.js +265 -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 +137 -0
- package/dist/dev/head/components.js +170 -0
- package/dist/dev/head/components.js.map +1 -0
- package/dist/dev/head/registry.js +68 -0
- package/dist/dev/head/registry.js.map +1 -0
- package/dist/dev/head/server-head.d.ts +54 -0
- package/dist/dev/head/server-head.js +76 -0
- package/dist/dev/head/server-head.js.map +1 -0
- package/dist/dev/head/sink.js +96 -0
- package/dist/dev/head/sink.js.map +1 -0
- package/dist/dev/head/use-head.d.ts +35 -0
- package/dist/dev/head/use-head.js +84 -0
- package/dist/dev/head/use-head.js.map +1 -0
- package/dist/dev/head/validate.d.ts +85 -0
- package/dist/dev/head/validate.js +268 -0
- package/dist/dev/head/validate.js.map +1 -0
- package/dist/dev/hmr.d.ts +82 -0
- package/dist/dev/hmr.js +124 -0
- package/dist/dev/hmr.js.map +1 -0
- package/dist/dev/hydration.d.ts +61 -0
- package/dist/dev/hydration.js +120 -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 +97 -0
- package/dist/dev/insert.js +357 -0
- package/dist/dev/insert.js.map +1 -0
- package/dist/dev/internal/claim.d.ts +106 -0
- package/dist/dev/internal/claim.js +357 -0
- package/dist/dev/internal/claim.js.map +1 -0
- package/dist/dev/internal/css-units.js +26 -0
- package/dist/dev/internal/css-units.js.map +1 -0
- package/dist/dev/internal/diagnostics.d.ts +30 -0
- package/dist/dev/internal/diagnostics.js +38 -0
- package/dist/dev/internal/diagnostics.js.map +1 -0
- package/dist/dev/internal/early-events.js +76 -0
- package/dist/dev/internal/early-events.js.map +1 -0
- package/dist/dev/internal/hydration-hooks.d.ts +43 -0
- package/dist/dev/internal/hydration-hooks.js +27 -0
- package/dist/dev/internal/hydration-hooks.js.map +1 -0
- package/dist/dev/internal/hydration-scope.d.ts +131 -0
- package/dist/dev/internal/hydration-scope.js +156 -0
- package/dist/dev/internal/hydration-scope.js.map +1 -0
- package/dist/dev/internal/names.d.ts +33 -0
- package/dist/dev/internal/names.js +35 -0
- package/dist/dev/internal/names.js.map +1 -0
- package/dist/dev/internal/portal-context.d.ts +39 -0
- package/dist/dev/internal/portal-context.js +28 -0
- package/dist/dev/internal/portal-context.js.map +1 -0
- package/dist/dev/internal/react-names.js +116 -0
- package/dist/dev/internal/react-names.js.map +1 -0
- package/dist/dev/internal/reconcile.d.ts +40 -0
- package/dist/dev/internal/reconcile.js +122 -0
- package/dist/dev/internal/reconcile.js.map +1 -0
- package/dist/dev/internal/stream-context.d.ts +47 -0
- package/dist/dev/internal/stream-context.js +23 -0
- package/dist/dev/internal/stream-context.js.map +1 -0
- package/dist/dev/jsx/aria.d.ts +72 -0
- package/dist/dev/jsx/component.d.ts +89 -0
- package/dist/dev/jsx/events.d.ts +364 -0
- package/dist/dev/jsx/global.d.ts +211 -0
- package/dist/dev/jsx/html.d.ts +879 -0
- package/dist/dev/jsx/intrinsic.d.ts +59 -0
- package/dist/dev/jsx/mathml.d.ts +186 -0
- package/dist/dev/jsx/svg.d.ts +607 -0
- package/dist/dev/jsx/types.d.ts +176 -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 +94 -0
- package/dist/dev/jsx-runtime.js +0 -0
- package/dist/dev/reactive.d.ts +110 -0
- package/dist/dev/reactive.js +85 -0
- package/dist/dev/reactive.js.map +1 -0
- package/dist/dev/render.d.ts +36 -0
- package/dist/dev/render.js +52 -0
- package/dist/dev/render.js.map +1 -0
- package/dist/dev/resource-hints.d.ts +145 -0
- package/dist/dev/resource-hints.js +200 -0
- package/dist/dev/resource-hints.js.map +1 -0
- package/dist/dev/select-value.d.ts +24 -0
- package/dist/dev/select-value.js +51 -0
- package/dist/dev/select-value.js.map +1 -0
- package/dist/dev/server/attributes.d.ts +33 -0
- package/dist/dev/server/attributes.js +155 -0
- package/dist/dev/server/attributes.js.map +1 -0
- package/dist/dev/server/class-style.d.ts +46 -0
- package/dist/dev/server/class-style.js +173 -0
- package/dist/dev/server/class-style.js.map +1 -0
- package/dist/dev/server/component.d.ts +42 -0
- package/dist/dev/server/component.js +72 -0
- package/dist/dev/server/component.js.map +1 -0
- package/dist/dev/server/derived.d.ts +41 -0
- package/dist/dev/server/derived.js +26 -0
- package/dist/dev/server/derived.js.map +1 -0
- package/dist/dev/server/element.d.ts +89 -0
- package/dist/dev/server/element.js +216 -0
- package/dist/dev/server/element.js.map +1 -0
- package/dist/dev/server/errors.js +26 -0
- package/dist/dev/server/errors.js.map +1 -0
- package/dist/dev/server/escape.d.ts +30 -0
- package/dist/dev/server/escape.js +119 -0
- package/dist/dev/server/escape.js.map +1 -0
- package/dist/dev/server/form-controls.d.ts +50 -0
- package/dist/dev/server/form-controls.js +193 -0
- package/dist/dev/server/form-controls.js.map +1 -0
- package/dist/dev/server/hydration-script.d.ts +65 -0
- package/dist/dev/server/hydration-script.js +59 -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 +13 -0
- package/dist/dev/server/node.js +21 -0
- package/dist/dev/server/node.js.map +1 -0
- package/dist/dev/server/portals.d.ts +46 -0
- package/dist/dev/server/portals.js +99 -0
- package/dist/dev/server/portals.js.map +1 -0
- package/dist/dev/server/render.d.ts +129 -0
- package/dist/dev/server/render.js +256 -0
- package/dist/dev/server/render.js.map +1 -0
- package/dist/dev/server/serialize.d.ts +45 -0
- package/dist/dev/server/serialize.js +315 -0
- package/dist/dev/server/serialize.js.map +1 -0
- package/dist/dev/server/stream.d.ts +94 -0
- package/dist/dev/server/stream.js +235 -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 +49 -0
- package/dist/dev/spread.js +296 -0
- package/dist/dev/spread.js.map +1 -0
- package/dist/dev/template.d.ts +26 -0
- package/dist/dev/template.js +120 -0
- package/dist/dev/template.js.map +1 -0
- package/dist/dev/view-transition.d.ts +97 -0
- package/dist/dev/view-transition.js +121 -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 +196 -0
- package/dist/server-dev/attributes.js.map +1 -0
- package/dist/server-dev/autofocus.js +45 -0
- package/dist/server-dev/autofocus.js.map +1 -0
- package/dist/server-dev/class-style.js +197 -0
- package/dist/server-dev/class-style.js.map +1 -0
- package/dist/server-dev/component.js +42 -0
- package/dist/server-dev/component.js.map +1 -0
- package/dist/server-dev/control-flow/activity.js +41 -0
- package/dist/server-dev/control-flow/activity.js.map +1 -0
- package/dist/server-dev/control-flow/branch.js +104 -0
- package/dist/server-dev/control-flow/branch.js.map +1 -0
- package/dist/server-dev/control-flow/client-only.js +50 -0
- package/dist/server-dev/control-flow/client-only.js.map +1 -0
- package/dist/server-dev/control-flow/dynamic.js +106 -0
- package/dist/server-dev/control-flow/dynamic.js.map +1 -0
- package/dist/server-dev/control-flow/error-boundary.js +115 -0
- package/dist/server-dev/control-flow/error-boundary.js.map +1 -0
- package/dist/server-dev/control-flow/for.js +23 -0
- package/dist/server-dev/control-flow/for.js.map +1 -0
- package/dist/server-dev/control-flow/fragment.js +31 -0
- package/dist/server-dev/control-flow/fragment.js.map +1 -0
- package/dist/server-dev/control-flow/hot-link.js +57 -0
- package/dist/server-dev/control-flow/hot-link.js.map +1 -0
- package/dist/server-dev/control-flow/index-list.js +31 -0
- package/dist/server-dev/control-flow/index-list.js.map +1 -0
- package/dist/server-dev/control-flow/lazy.js +64 -0
- package/dist/server-dev/control-flow/lazy.js.map +1 -0
- package/dist/server-dev/control-flow/no-hydration.js +40 -0
- package/dist/server-dev/control-flow/no-hydration.js.map +1 -0
- package/dist/server-dev/control-flow/portal.js +134 -0
- package/dist/server-dev/control-flow/portal.js.map +1 -0
- package/dist/server-dev/control-flow/root-errors.js +33 -0
- package/dist/server-dev/control-flow/root-errors.js.map +1 -0
- package/dist/server-dev/control-flow/show.js +18 -0
- package/dist/server-dev/control-flow/show.js.map +1 -0
- package/dist/server-dev/control-flow/suspense-list.js +100 -0
- package/dist/server-dev/control-flow/suspense-list.js.map +1 -0
- package/dist/server-dev/control-flow/suspense.js +119 -0
- package/dist/server-dev/control-flow/suspense.js.map +1 -0
- package/dist/server-dev/control-flow/switch.js +90 -0
- package/dist/server-dev/control-flow/switch.js.map +1 -0
- package/dist/server-dev/derived.js +34 -0
- package/dist/server-dev/derived.js.map +1 -0
- package/dist/server-dev/element.js +66 -0
- package/dist/server-dev/element.js.map +1 -0
- package/dist/server-dev/events.js +265 -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 +170 -0
- package/dist/server-dev/head/components.js.map +1 -0
- package/dist/server-dev/head/registry.js +68 -0
- package/dist/server-dev/head/registry.js.map +1 -0
- package/dist/server-dev/head/server-head.js +76 -0
- package/dist/server-dev/head/server-head.js.map +1 -0
- package/dist/server-dev/head/sink.js +96 -0
- package/dist/server-dev/head/sink.js.map +1 -0
- package/dist/server-dev/head/use-head.js +84 -0
- package/dist/server-dev/head/use-head.js.map +1 -0
- package/dist/server-dev/head/validate.js +268 -0
- package/dist/server-dev/head/validate.js.map +1 -0
- package/dist/server-dev/hydration.js +120 -0
- package/dist/server-dev/hydration.js.map +1 -0
- package/dist/server-dev/index.js +34 -0
- package/dist/server-dev/insert.js +357 -0
- package/dist/server-dev/insert.js.map +1 -0
- package/dist/server-dev/internal/claim.js +357 -0
- package/dist/server-dev/internal/claim.js.map +1 -0
- package/dist/server-dev/internal/css-units.js +26 -0
- package/dist/server-dev/internal/css-units.js.map +1 -0
- package/dist/server-dev/internal/diagnostics.js +38 -0
- package/dist/server-dev/internal/diagnostics.js.map +1 -0
- package/dist/server-dev/internal/early-events.js +76 -0
- package/dist/server-dev/internal/early-events.js.map +1 -0
- package/dist/server-dev/internal/hydration-hooks.js +27 -0
- package/dist/server-dev/internal/hydration-hooks.js.map +1 -0
- package/dist/server-dev/internal/hydration-scope.js +156 -0
- package/dist/server-dev/internal/hydration-scope.js.map +1 -0
- package/dist/server-dev/internal/names.js +35 -0
- package/dist/server-dev/internal/names.js.map +1 -0
- package/dist/server-dev/internal/portal-context.js +28 -0
- package/dist/server-dev/internal/portal-context.js.map +1 -0
- package/dist/server-dev/internal/react-names.js +116 -0
- package/dist/server-dev/internal/react-names.js.map +1 -0
- package/dist/server-dev/internal/reconcile.js +122 -0
- package/dist/server-dev/internal/reconcile.js.map +1 -0
- package/dist/server-dev/internal/stream-context.js +23 -0
- package/dist/server-dev/internal/stream-context.js.map +1 -0
- package/dist/server-dev/reactive.js +85 -0
- package/dist/server-dev/reactive.js.map +1 -0
- package/dist/server-dev/render.js +52 -0
- package/dist/server-dev/render.js.map +1 -0
- package/dist/server-dev/resource-hints.js +200 -0
- package/dist/server-dev/resource-hints.js.map +1 -0
- package/dist/server-dev/select-value.js +51 -0
- package/dist/server-dev/select-value.js.map +1 -0
- package/dist/server-dev/server/attributes.js +155 -0
- package/dist/server-dev/server/attributes.js.map +1 -0
- package/dist/server-dev/server/class-style.js +173 -0
- package/dist/server-dev/server/class-style.js.map +1 -0
- package/dist/server-dev/server/component.js +72 -0
- package/dist/server-dev/server/component.js.map +1 -0
- package/dist/server-dev/server/derived.js +26 -0
- package/dist/server-dev/server/derived.js.map +1 -0
- package/dist/server-dev/server/element.js +216 -0
- package/dist/server-dev/server/element.js.map +1 -0
- package/dist/server-dev/server/errors.js +26 -0
- package/dist/server-dev/server/errors.js.map +1 -0
- package/dist/server-dev/server/escape.js +119 -0
- package/dist/server-dev/server/escape.js.map +1 -0
- package/dist/server-dev/server/form-controls.js +193 -0
- package/dist/server-dev/server/form-controls.js.map +1 -0
- package/dist/server-dev/server/hydration-script.js +59 -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 +21 -0
- package/dist/server-dev/server/node.js.map +1 -0
- package/dist/server-dev/server/portals.js +99 -0
- package/dist/server-dev/server/portals.js.map +1 -0
- package/dist/server-dev/server/render.js +256 -0
- package/dist/server-dev/server/render.js.map +1 -0
- package/dist/server-dev/server/serialize.js +315 -0
- package/dist/server-dev/server/serialize.js.map +1 -0
- package/dist/server-dev/server/stream.js +235 -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 +296 -0
- package/dist/server-dev/spread.js.map +1 -0
- package/dist/server-dev/template.js +120 -0
- package/dist/server-dev/template.js.map +1 -0
- package/dist/server-dev/view-transition.js +90 -0
- package/dist/server-dev/view-transition.js.map +1 -0
- package/package.json +136 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-head.js","names":["registries","createRegistryFor","createRoot","version","bump","useSignal","registry","createHeadRegistry","count","apply","createDomHeadSink","doc","useEffect","winners","registryFor","known","useHead","isServer","collector","getOwner","useContext","ServerHeadContext","normalizeTags","untrack","input","useRenderEffect","tags"],"sources":["../../../src/head/use-head.ts"],"sourcesContent":["import {\n createRoot,\n getOwner,\n isServer,\n untrack,\n useContext,\n useEffect,\n useRenderEffect,\n useSignal,\n} from \"@shadow-js/core\";\nimport { createHeadRegistry, type HeadRegistry } from \"./registry\";\nimport { ServerHeadContext } from \"./server-head\";\nimport { createDomHeadSink } from \"./sink\";\nimport { type HeadInput, normalizeTags } from \"./validate\";\n\n/** One registry per document, shared by every `useHead` call on it. */\nconst registries = new WeakMap<Document, HeadRegistry>();\n\n/**\n * Creates the registry for a document and the deferred effect that writes it to the head. The\n * effect is detached: it lives as long as the document, not as long as the first caller. It runs\n * in the user-effect queue, so every registration made in one flush produces one DOM pass.\n */\nfunction createRegistryFor(doc: Document): HeadRegistry {\n return createRoot(\n (): HeadRegistry => {\n const [version, bump] = useSignal(0);\n const registry = createHeadRegistry(() => {\n bump((count) => count + 1);\n });\n const apply = createDomHeadSink(doc);\n useEffect(\n () => {\n version();\n return registry.winners();\n },\n (winners) => {\n apply(winners);\n },\n );\n return registry;\n },\n { detached: true },\n );\n}\n\n/** The registry of a document, created on first use. */\nfunction registryFor(doc: Document): HeadRegistry {\n const known = registries.get(doc);\n if (known !== undefined) return known;\n const registry = createRegistryFor(doc);\n registries.set(doc, registry);\n return registry;\n}\n\n/**\n * Registers head tags for the lifetime of the current owner. Each registration joins the stack of\n * its identity: `title` and `base` are singletons, `meta` is keyed by its name, property,\n * http-equiv or charset (and media), icons by rel, sizes and type, resource links by rel, href and\n * as, and styles by key. The last registration of an identity wins; disposing it restores the one\n * below. Append-only tags (no identity) all stay. Passing a function re-registers when its\n * dependencies change. On the client the registrations are written to `document.head` after the\n * render phase of a flush, in one pass per flush. On the server the tags go to the render's `head`\n * collector (see `createServerHead`), read once; without one, or outside an owner, nothing is\n * registered.\n *\n * @param input One tag, several tags, or a function returning them. `null`, `undefined` and `false`\n * register nothing.\n * @throws TypeError for an invalid tag description (see {@link normalizeTags}); on the client the\n * error is raised in the registration's render effect and goes to the owner's error handler.\n * In development builds, calling it on the client with no owner does not throw: it warns\n * `HEAD_OUTSIDE_OWNER` and registers nothing.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { useHead } from \"@shadow-js/web\";\n *\n * function Post() {\n * const [post] = useSignal({ title: \"Hello\" });\n * useHead(() => ({ tag: \"title\", children: `${post().title} | Blog` }));\n * return null;\n * }\n * @see Title\n * @see Meta\n * @since 1.0.0\n */\nexport function useHead(input: HeadInput | (() => HeadInput)): void {\n if (isServer) {\n const collector = getOwner() === null ? null : useContext(ServerHeadContext);\n if (collector !== null) {\n collector.add(normalizeTags(untrack(() => (typeof input === \"function\" ? input() : input))));\n }\n return;\n }\n if (getOwner() === null) {\n if (__DEV__) {\n console.warn(\"[shadow HEAD_OUTSIDE_OWNER] useHead() needs an owner; nothing was registered.\");\n }\n return;\n }\n const registry = registryFor(document);\n useRenderEffect(\n () => normalizeTags(typeof input === \"function\" ? input() : input),\n (tags) => registry.add(tags),\n );\n}\n"],"mappings":"A,6VAgBA,MAAMA,kBAAa,IAAI,QAOvB,SAASC,EAAkB,EAA6B,CACtD,OAAOC,MACe,CAClB,GAAM,CAACC,EAASC,GAAQC,EAAU,CAAC,EAC7BC,EAAWC,MAAyB,CACxCH,EAAM,GAAUI,EAAQ,CAAC,CAC3B,CAAC,EACKC,EAAQC,EAAkBC,CAAG,EAUnC,OATAC,OAEIT,EAAQ,EACDG,EAAS,QAAQ,GAEzB,GAAY,CACXG,EAAMI,CAAO,CACf,CACF,EACOP,CACT,EACA,CAAE,SAAU,EAAK,CACnB,CACF,CAGA,SAASQ,EAAY,EAA6B,CAChD,IAAMC,EAAQf,EAAW,IAAIW,CAAG,EAChC,GAAII,IAAU,IAAA,GAAW,OAAOA,EAChC,IAAMT,EAAWL,EAAkBU,CAAG,EAEtC,OADAX,EAAW,IAAIW,EAAKL,CAAQ,EACrBA,CACT,CAgCA,SAAgBU,EAAQ,EAA4C,CAClE,GAAIC,EAAU,CACZ,IAAMC,EAAYC,EAAS,IAAM,KAAO,KAAOC,EAAWC,CAAiB,EACvEH,IAAc,MAChBA,EAAU,IAAII,EAAcC,MAAe,OAAOC,GAAU,WAAaA,EAAM,EAAIA,CAAM,CAAC,CAAC,EAE7F,MACF,CACA,GAAIL,EAAS,IAAM,KAIjB,OAEF,IAAMb,EAAWQ,EAAY,QAAQ,EACrCW,MACQH,EAAc,OAAOE,GAAU,WAAaA,EAAM,EAAIA,CAAK,EAChE,GAASlB,EAAS,IAAIoB,CAAI,CAC7B,CACF,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import"../internal/diagnostics.js";import{isUnsafeUrlAttribute as e}from"../attributes.js";const t=`data-shadow-head`,n=`data-shadow-key`,r=/* @__PURE__ */ new Set([`title`,`meta`,`link`,`style`,`base`]),i=/^[a-zA-Z_][a-zA-Z0-9_:.-]*$/,a=/* @__PURE__ */ new Set([t,n]),o=/* @__PURE__ */ new Set([`__proto__`,`constructor`,`prototype`]),s=[`name`,`property`,`http-equiv`,`charset`],c=/* @__PURE__ */ new Set([`og:image`,`og:video`,`og:audio`,`og:locale:alternate`,`og:email`,`og:phone_number`,`og:fax_number`,`article:tag`,`article:author`,`book:author`,`book:tag`,`music:album`,`music:song`,`music:musician`,`music:creator`,`video:actor`,`video:director`,`video:writer`,`video:tag`,`fb:admins`,`twitter:image`]),l=/* @__PURE__ */ new Set([`alternate`,`author`,`archives`,`assets`,`bookmarks`,`me`,`apple-touch-startup-image`]),u=/* @__PURE__ */ new Set([`preload`,`modulepreload`,`prefetch`,`preconnect`,`dns-prefetch`,`stylesheet`]);function d(e){return r.has(e)}function f(e){return e.map(e=>`${e.length}:${e}`).join(``)}function p(e){if(e!=null&&e!==!1){if(e===!0)return``;if(typeof e==`string`)return e;if(typeof e==`number`)return String(e);throw TypeError(`SHADOW_HEAD_ATTRIBUTE_VALUE`)}}function m(t,n){if(n==null)return/* @__PURE__ */ new Map;if(typeof n!=`object`||Array.isArray(n))throw TypeError(`SHADOW_HEAD_PROPS`);let r=/* @__PURE__ */ new Map;for(let s of Object.keys(n)){if(!i.test(s))throw TypeError(`SHADOW_HEAD_ATTRIBUTE_NAME`);let c=s.toLowerCase();if(c.startsWith(`on`))throw TypeError(`SHADOW_HEAD_EVENT_ATTRIBUTE`);if(a.has(c))throw TypeError(`SHADOW_HEAD_RESERVED`);if(o.has(c))continue;let l=p(Reflect.get(n,s));l!==void 0&&(e(c,l)?`${c}${t}`:r.set(c,l))}return r}function h(e,t){if(t!=null){if(e!==`title`&&e!==`style`)throw TypeError(`SHADOW_HEAD_NO_CHILDREN`);if(typeof t!=`string`)throw TypeError(`SHADOW_HEAD_TEXT`);return t}}function g(e,t){if(t!=null){if(e!==`style`)throw TypeError(`SHADOW_HEAD_STYLE_KEY`);if(typeof t!=`string`||t===``)throw TypeError(`SHADOW_HEAD_KEY`);return t}}function _(e){if(e===void 0)return;let t=e.toLowerCase().split(/\s+/).filter(e=>e!==``);if(t.length!==0)return t.sort().join(` `)}function v(e){let t=e.get(`media`)??``;for(let n of s){let r=e.get(n);if(r!==void 0)return n===`charset`?f([`meta`,n]):c.has(r)?f([`meta`,n,r,t,e.get(`content`)??``]):f([`meta`,n,r,t])}}function y(e){let t=_(e.get(`rel`));if(t!==void 0){if(t.split(` `).some(e=>e===`icon`||e.endsWith(`-icon`)))return f([`link`,`icon`,t,e.get(`sizes`)??``,e.get(`type`)??``]);if(t===`canonical`)return f([`link`,`canonical`]);if(u.has(t))return f([`link`,`resource`,t,e.get(`href`)??``,e.get(`as`)??``]);if(l.has(t))return f([`link`,`multi`,t,e.get(`href`)??``,e.get(`hreflang`)??``,e.get(`media`)??``,e.get(`type`)??``])}}function b(e,t,n){return e===`title`?f([`title`]):e===`base`?f([`base`]):e===`style`?n===void 0?void 0:f([`style`,n]):e===`meta`?v(t):y(t)}function x(e){if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(`SHADOW_HEAD_TAG`);let t=Reflect.get(e,`tag`);if(typeof t!=`string`||!d(t))throw TypeError(`SHADOW_HEAD_TAG_NAME`);let n=m(t,Reflect.get(e,`props`)),r=h(t,Reflect.get(e,`children`)),i=g(t,Reflect.get(e,`key`));return{tag:t,attributes:[...n],text:r,key:i,identity:b(t,n,i)}}function S(e){return e==null||e===!1?[]:Array.isArray(e)?e.map(e=>x(e)):[x(e)]}function C(e){let t=e.localName;if(!d(t))return;let n=/* @__PURE__ */ new Map;for(let t of Array.from(e.attributes))t.name!==`data-shadow-head`&&t.name!==`data-shadow-key`&&n.set(t.name.toLowerCase(),t.value);return b(t,n,e.getAttribute(`data-shadow-key`)??void 0)}export{n as HEAD_KEY,t as HEAD_MARKER,b as identityOf,C as identityOfElement,d as isHeadTagName,x as normalizeTag,S as normalizeTags};
|
|
2
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","names":["HEAD_MARKER","HEAD_KEY","TAG_NAMES","ATTRIBUTE_NAME","RESERVED_ATTRIBUTES","FORBIDDEN_NAMES","META_IDENTITY_FIELDS","MULTI_VALUED_META","MULTI_LINK_RELS","RESOURCE_RELS","isHeadTagName","value","frame","parts","part","attributeText","attributesFrom","props","values","key","name","text","isUnsafeUrlAttribute","tag","textFrom","children","keyFrom","normalizeRel","raw","tokens","token","metaIdentity","media","lookup","field","linkIdentity","rel","identityOf","normalizeTag","input","normalizeTags","item","identityOfElement","element","attribute"],"sources":["../../../src/head/validate.ts"],"sourcesContent":["import { isUnsafeUrlAttribute, warnOnce } from \"../extend\";\n\n/**\n * Head elements the registry manages. `script` and `noscript` are refused: a head-registered\n * script would bypass CSP nonces and Trusted Types, so scripts come only from the asset pipeline.\n * @since 1.0.0\n */\nexport type HeadTagName = \"title\" | \"meta\" | \"link\" | \"style\" | \"base\";\n\n/**\n * One attribute value: a string is written as is, `true` as an empty attribute, `false` and\n * `undefined` omit it, and a number is written as text.\n * @since 1.0.0\n */\nexport type HeadAttributeValue = string | number | boolean | undefined;\n\n/**\n * Describes one head element. `key` identifies a `style` for replacement; other tags use their\n * own identity (see {@link useHead}).\n *\n * @example\n * import type { HeadTag } from \"@shadow-js/web\";\n *\n * const description: HeadTag = { tag: \"meta\", props: { name: \"description\", content: \"Docs\" } };\n * @since 1.0.0\n */\nexport interface HeadTag {\n /** The element to register: `title`, `meta`, `link`, `style` or `base`. Any other name throws. */\n readonly tag: HeadTagName;\n /**\n * The attributes of the element. Names are case-insensitive, must be valid attribute names, and\n * may not start with `on`.\n * @default undefined (the element has no attributes)\n */\n readonly props?: Readonly<Record<string, HeadAttributeValue>>;\n /**\n * The text of a `title` or `style`. Other tags take no text and throw when it is given.\n * @default undefined (no text)\n */\n readonly children?: string;\n /**\n * Identity of a `style`: a later style with the same key replaces an earlier one. Only `style`\n * takes a key.\n * @default undefined (the style has no identity and always stays)\n */\n readonly key?: string;\n}\n\n/**\n * What {@link useHead} accepts: one tag, several tags, or nothing (which registers nothing).\n * @since 1.0.0\n */\nexport type HeadInput = HeadTag | readonly HeadTag[] | null | undefined | false;\n\n/**\n * A validated tag: lower-case attribute names, the text it carries, and its identity. Produced\n * only by {@link normalizeTag}, so the registry and the DOM sink never see unchecked input.\n * @internal\n */\nexport interface NormalizedTag {\n readonly tag: HeadTagName;\n readonly attributes: ReadonlyArray<readonly [string, string]>;\n readonly text: string | undefined;\n readonly key: string | undefined;\n /** Identity that replaces earlier registrations; undefined for append-only tags. */\n readonly identity: string | undefined;\n}\n\n/** Marks every element the sink created or adopted. Callers may not supply it. @internal */\nexport const HEAD_MARKER = \"data-shadow-head\";\n/** Carries a style's key so a server-rendered style can be adopted. @internal */\nexport const HEAD_KEY = \"data-shadow-key\";\n\nconst TAG_NAMES: ReadonlySet<string> = new Set([\"title\", \"meta\", \"link\", \"style\", \"base\"]);\nconst ATTRIBUTE_NAME = /^[a-zA-Z_][a-zA-Z0-9_:.-]*$/;\nconst RESERVED_ATTRIBUTES: ReadonlySet<string> = new Set([HEAD_MARKER, HEAD_KEY]);\n/** Names skipped silently, as spread does: they would reach a prototype if written as keys. */\nconst FORBIDDEN_NAMES: ReadonlySet<string> = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\nconst META_IDENTITY_FIELDS = [\"name\", \"property\", \"http-equiv\", \"charset\"] as const;\n/**\n * Properties that repeat by design (one tag per image, per tag, per locale). Their identity includes the content,\n * so every value stays; the others are last-wins. Sub-properties of an image (`og:image:width`) are single.\n * @since 1.0.0\n */\nconst MULTI_VALUED_META: ReadonlySet<string> = new Set([\n \"og:image\",\n \"og:video\",\n \"og:audio\",\n \"og:locale:alternate\",\n \"og:email\",\n \"og:phone_number\",\n \"og:fax_number\",\n \"article:tag\",\n \"article:author\",\n \"book:author\",\n \"book:tag\",\n \"music:album\",\n \"music:song\",\n \"music:musician\",\n \"music:creator\",\n \"video:actor\",\n \"video:director\",\n \"video:writer\",\n \"video:tag\",\n \"fb:admins\",\n \"twitter:image\",\n]);\n/** Links that repeat (alternates per language, authors, archives): their identity is every attribute. */\nconst MULTI_LINK_RELS: ReadonlySet<string> = new Set([\n \"alternate\",\n \"author\",\n \"archives\",\n \"assets\",\n \"bookmarks\",\n \"me\",\n \"apple-touch-startup-image\",\n]);\nconst RESOURCE_RELS: ReadonlySet<string> = new Set([\n \"preload\",\n \"modulepreload\",\n \"prefetch\",\n \"preconnect\",\n \"dns-prefetch\",\n \"stylesheet\",\n]);\n\n/** True for the tag names the registry manages. @internal */\nexport function isHeadTagName(value: string): value is HeadTagName {\n return TAG_NAMES.has(value);\n}\n\n/**\n * Length-prefixed identity: `[\"a|b\"]` and `[\"a\", \"b\"]` can never collide because every part\n * carries its own length.\n */\nfunction frame(parts: readonly string[]): string {\n return parts.map((part) => `${part.length}:${part}`).join(\"\");\n}\n\n/** Text of an attribute value, or undefined when the attribute is omitted. */\nfunction attributeText(value: unknown): string | undefined {\n if (value === undefined || value === null || value === false) return undefined;\n if (value === true) return \"\";\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\") return String(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 * Validates the props of one tag and returns its lower-case, de-duplicated attributes, in order. The\n * map is the lookup that the identity is built from, so it is built once per tag.\n */\nfunction attributesFrom(tag: HeadTagName, props: unknown): ReadonlyMap<string, string> {\n if (props === undefined || props === null) return new Map();\n if (typeof props !== \"object\" || Array.isArray(props)) {\n throw new TypeError(__DEV__ ? \"ShadowJS head: props must be an object.\" : \"SHADOW_HEAD_PROPS\");\n }\n const values = new Map<string, string>();\n for (const key of Object.keys(props)) {\n if (!ATTRIBUTE_NAME.test(key)) {\n throw new TypeError(\n __DEV__\n ? `ShadowJS head: \"${key}\" is not a valid attribute name.`\n : \"SHADOW_HEAD_ATTRIBUTE_NAME\",\n );\n }\n const name = key.toLowerCase();\n if (name.startsWith(\"on\")) {\n throw new TypeError(\n __DEV__\n ? `ShadowJS head: event attribute \"${key}\" is not allowed.`\n : \"SHADOW_HEAD_EVENT_ATTRIBUTE\",\n );\n }\n if (RESERVED_ATTRIBUTES.has(name)) {\n throw new TypeError(\n __DEV__ ? `ShadowJS head: \"${key}\" is reserved for the runtime.` : \"SHADOW_HEAD_RESERVED\",\n );\n }\n if (FORBIDDEN_NAMES.has(name)) continue;\n const text = attributeText(Reflect.get(props, key));\n if (text === undefined) continue;\n if (isUnsafeUrlAttribute(name, text)) {\n warnOnce(\"UNSAFE_URL_BLOCKED\", `Dropped the unsafe \"${name}\" value of a <${tag}> head tag.`);\n continue;\n }\n values.set(name, text);\n }\n return values;\n}\n\n/** Children text: title and style only, and only as a string. */\nfunction textFrom(tag: HeadTagName, children: unknown): string | undefined {\n if (children === undefined || children === null) return undefined;\n if (tag !== \"title\" && tag !== \"style\") {\n throw new TypeError(\n __DEV__ ? `ShadowJS head: <${tag}> takes no children.` : \"SHADOW_HEAD_NO_CHILDREN\",\n );\n }\n if (typeof children !== \"string\")\n throw new TypeError(__DEV__ ? \"ShadowJS head: children must be text.\" : \"SHADOW_HEAD_TEXT\");\n return children;\n}\n\n/** The key of a style. Only style takes one. */\nfunction keyFrom(tag: HeadTagName, key: unknown): string | undefined {\n if (key === undefined || key === null) return undefined;\n if (tag !== \"style\")\n throw new TypeError(\n __DEV__ ? \"ShadowJS head: only <style> takes a key.\" : \"SHADOW_HEAD_STYLE_KEY\",\n );\n if (typeof key !== \"string\" || key === \"\") {\n throw new TypeError(\n __DEV__ ? \"ShadowJS head: a key must be a non-empty string.\" : \"SHADOW_HEAD_KEY\",\n );\n }\n return key;\n}\n\n/** Rel tokens, lower-cased and sorted, so `\"ICON apple\"` and `\"apple icon\"` compare equal. */\nfunction normalizeRel(raw: string | undefined): string | undefined {\n if (raw === undefined) return undefined;\n const tokens = raw\n .toLowerCase()\n .split(/\\s+/)\n .filter((token) => token !== \"\");\n if (tokens.length === 0) return undefined;\n return tokens.sort().join(\" \");\n}\n\n/** Identity of a meta: its first identifying field and the media query. */\nfunction metaIdentity(lookup: ReadonlyMap<string, string>): string | undefined {\n const media = lookup.get(\"media\") ?? \"\";\n for (const field of META_IDENTITY_FIELDS) {\n const value = lookup.get(field);\n if (value === undefined) continue;\n // A document has one charset, whatever its value: that meta is a singleton.\n if (field === \"charset\") return frame([\"meta\", field]);\n if (MULTI_VALUED_META.has(value))\n return frame([\"meta\", field, value, media, lookup.get(\"content\") ?? \"\"]);\n return frame([\"meta\", field, value, media]);\n }\n return undefined;\n}\n\n/** Identity of a link: icons by rel, sizes and type; preloads and stylesheets by rel, href and as. */\nfunction linkIdentity(lookup: ReadonlyMap<string, string>): string | undefined {\n const rel = normalizeRel(lookup.get(\"rel\"));\n if (rel === undefined) return undefined;\n const isIcon = rel.split(\" \").some((token) => token === \"icon\" || token.endsWith(\"-icon\"));\n if (isIcon) {\n return frame([\"link\", \"icon\", rel, lookup.get(\"sizes\") ?? \"\", lookup.get(\"type\") ?? \"\"]);\n }\n // A document has one canonical URL: a singleton, so a new value replaces the old element (and a server's\n // copy is adopted) instead of a second `<link rel=\"canonical\">` being appended.\n if (rel === \"canonical\") return frame([\"link\", \"canonical\"]);\n if (RESOURCE_RELS.has(rel)) {\n return frame([\"link\", \"resource\", rel, lookup.get(\"href\") ?? \"\", lookup.get(\"as\") ?? \"\"]);\n }\n if (MULTI_LINK_RELS.has(rel)) {\n return frame([\n \"link\",\n \"multi\",\n rel,\n lookup.get(\"href\") ?? \"\",\n lookup.get(\"hreflang\") ?? \"\",\n lookup.get(\"media\") ?? \"\",\n lookup.get(\"type\") ?? \"\",\n ]);\n }\n return undefined;\n}\n\n/** Identity of a validated tag, or undefined when the tag is append-only. @internal */\nexport function identityOf(\n tag: HeadTagName,\n lookup: ReadonlyMap<string, string>,\n key: string | undefined,\n): string | undefined {\n if (tag === \"title\") return frame([\"title\"]);\n if (tag === \"base\") return frame([\"base\"]);\n if (tag === \"style\") return key === undefined ? undefined : frame([\"style\", key]);\n return tag === \"meta\" ? metaIdentity(lookup) : linkIdentity(lookup);\n}\n\n/**\n * Validates one head tag description and computes its identity. Hostile input throws a\n * TypeError: an unknown tag (including `script`), a bad attribute name, an event attribute, a\n * reserved marker, children on a void tag, or a key on anything but a style. An unsafe URL\n * attribute is dropped with a dev warning, the same way `setAttribute` treats it.\n *\n * @param input The description, usually a {@link HeadTag}; any value is checked.\n * @returns The normalized tag.\n * @throws TypeError for every invalid input listed above.\n * @internal\n * @since 1.0.0\n */\nexport function normalizeTag(input: unknown): NormalizedTag {\n if (input === null || typeof input !== \"object\" || Array.isArray(input)) {\n throw new TypeError(\n __DEV__ ? \"ShadowJS head: a head tag must be an object.\" : \"SHADOW_HEAD_TAG\",\n );\n }\n const name = Reflect.get(input, \"tag\");\n if (typeof name !== \"string\" || !isHeadTagName(name)) {\n const shown = typeof name === \"string\" ? name : typeof name;\n throw new TypeError(\n __DEV__ ? `ShadowJS head: unsupported tag \"${shown}\".` : \"SHADOW_HEAD_TAG_NAME\",\n );\n }\n const lookup = attributesFrom(name, Reflect.get(input, \"props\"));\n const text = textFrom(name, Reflect.get(input, \"children\"));\n const key = keyFrom(name, Reflect.get(input, \"key\"));\n return {\n tag: name,\n attributes: [...lookup],\n text,\n key,\n identity: identityOf(name, lookup, key),\n };\n}\n\n/**\n * Normalizes what {@link useHead} receives: one description, a list, or nothing.\n *\n * @param input A description, a list of them, or null, undefined or false for none.\n * @returns The normalized tags, in order.\n * @throws TypeError when any description is invalid: an unknown tag (including `script`), an\n * attribute name that is not valid or starts with `on`, a reserved marker attribute, an attribute\n * value that is not a string, number or boolean, children on a tag other than `title` and `style`,\n * or a key on anything but a `style`. The production messages start with `SHADOW_HEAD_`.\n * @example\n * import { normalizeTags } from \"@shadow-js/web/server\";\n *\n * const tags = normalizeTags([\n * { tag: \"title\", children: \"A\" },\n * { tag: \"base\", props: { href: \"/\" } },\n * ]);\n * console.log(tags.length); // 2\n * @see useHead\n * @since 1.0.0\n */\nexport function normalizeTags(input: unknown): NormalizedTag[] {\n if (input === null || input === undefined || input === false) return [];\n if (Array.isArray(input)) return input.map((item: unknown) => normalizeTag(item));\n return [normalizeTag(input)];\n}\n\n/**\n * The identity of an element already in the document, computed the same way as for a\n * registration, so the sink can adopt a server-rendered element. Undefined for elements that are\n * not head tags or that are append-only.\n * @internal\n */\nexport function identityOfElement(element: Element): string | undefined {\n const name = element.localName;\n if (!isHeadTagName(name)) return undefined;\n const lookup = new Map<string, string>();\n for (const attribute of Array.from(element.attributes)) {\n if (attribute.name === HEAD_MARKER || attribute.name === HEAD_KEY) continue;\n lookup.set(attribute.name.toLowerCase(), attribute.value);\n }\n const key = element.getAttribute(HEAD_KEY) ?? undefined;\n return identityOf(name, lookup, key);\n}\n"],"mappings":"A,2FAqEA,MAAaA,EAAc,mBAEdC,EAAW,kBAElBC,kBAAiC,IAAI,IAAI,CAAC,QAAS,OAAQ,OAAQ,QAAS,MAAM,CAAC,EACnFC,EAAiB,8BACjBC,kBAA2C,IAAI,IAAI,CAACJ,EAAaC,CAAQ,CAAC,EAE1EI,kBAAuC,IAAI,IAAI,CAAC,YAAa,cAAe,WAAW,CAAC,EACxFC,EAAuB,CAAC,OAAQ,WAAY,aAAc,SAAS,EAMnEC,kBAAyC,IAAI,IAAI,CACrD,WACA,WACA,WACA,sBACA,WACA,kBACA,gBACA,cACA,iBACA,cACA,WACA,cACA,aACA,iBACA,gBACA,cACA,iBACA,eACA,YACA,YACA,eACF,CAAC,EAEKC,kBAAuC,IAAI,IAAI,CACnD,YACA,SACA,WACA,SACA,YACA,KACA,2BACF,CAAC,EACKC,kBAAqC,IAAI,IAAI,CACjD,UACA,gBACA,WACA,aACA,eACA,YACF,CAAC,EAGD,SAAgBC,EAAc,EAAqC,CACjE,OAAOR,EAAU,IAAIS,CAAK,CAC5B,CAMA,SAASC,EAAM,EAAkC,CAC/C,OAAOC,EAAM,IAAK,GAAS,GAAGC,EAAK,OAAO,GAAGA,GAAM,CAAC,CAAC,KAAK,EAAE,CAC9D,CAGA,SAASC,EAAc,EAAoC,CACzD,GAAIJ,GAAiC,MAAQA,IAAU,GACvD,IAAIA,IAAU,GAAM,MAAO,GAC3B,GAAI,OAAOA,GAAU,SAAU,OAAOA,EACtC,GAAI,OAAOA,GAAU,SAAU,OAAO,OAAOA,CAAK,EAClD,MAAU,UAGJ,6BACN,CAP2B,CAQ7B,CAMA,SAASK,EAAe,EAAkB,EAA6C,CACrF,GAAIC,GAAiC,KAAM,sBAAO,IAAI,IACtD,GAAI,OAAOA,GAAU,UAA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,OAAOP,EAAWjB,EAAMa,EADZU,EAAQ,aAAA,iBAAqB,GAAK,IAAA,EACX,CACrC,C"}
|
package/dist/prod/hmr.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{hotModulesOf as e}from"./control-flow/hot-link.js";import{batch as t,getOwner as n,untrack as r,useSignal as i}from"@shadow-js/core";import{createComputation as a,readComputation as o}from"@shadow-js/core/extend";const s=`shadowjs:hmr-registry`;var c=class{entries=/* @__PURE__ */ new Map;managed;listeners=/* @__PURE__ */ new Set;constructor(e){this.managed=e}commit(){let e=[...this.listeners];t(()=>{for(let e of this.entries.values())e.dirty&&(e.dirty=!1,e.bump())});for(let t of e)t()}};function l(e,t){if(e===void 0||typeof e.data!=`object`||e.data===null)return new c(!1);let n=e.data[s];if(n instanceof c)return n;let r=new c(!0);return e.dispose(e=>{e[s]=r}),r}function u(t,s,c){if(!t.managed)return c;let l=t.entries.get(s);if(l!==void 0)return l.implementation=c,l.dirty=!0,l.proxy;let[u,d]=i(0),f={implementation:c,version:u,bump:()=>{d(e=>e+1)},proxy:void 0,dirty:!1},p=i=>{e(n())?.add(t);let s=a({kind:`memo`,allowWrites:!0,fn:()=>(f.version(),r(()=>f.implementation(i)))});return()=>o(s)};return Object.defineProperty(p,"name",{value:s}),f.proxy=p,t.entries.set(s,f),p}function d(e,t){e!==void 0&&t.managed&&(e.accept(),t.commit())}export{c as ModuleRegistry,d as accept,u as component,l as registry};
|
|
2
|
+
//# sourceMappingURL=hmr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmr.js","names":["REGISTRY_KEY","ModuleRegistry","managed","listening","batch","entry","listener","registry","hot","previous","created","component","reg","implementation","existing","name","version","setVersion","useSignal","n","proxy","hotModulesOf","getOwner","node","createComputation","untrack","props","readComputation","accept"],"sources":["../../src/hmr.ts"],"sourcesContent":["import { batch, getOwner, untrack, useSignal } from \"@shadow-js/core\";\nimport { createComputation, readComputation } from \"@shadow-js/core/extend\";\nimport { hotModulesOf } from \"./control-flow/hot-link\";\n\n/**\n * The subset of Vite's `import.meta.hot` the runtime uses. The compiled output passes\n * `import.meta.hot` to `registry`, so any object with these three members works (a test runner can\n * supply its own).\n * @since 1.0.0\n */\nexport interface HotContext {\n /** Data kept across hot updates of the module: values stored in a `dispose` callback arrive here. */\n readonly data: Record<string, unknown>;\n /** Declares that the module accepts its own update, so the page is not reloaded. */\n accept(): void;\n /** Registers a callback that runs before the module is replaced and may store values in `data`. */\n dispose(callback: (data: Record<string, unknown>) => void): void;\n}\n\ntype ComponentFunction = (props: never) => unknown;\n\ninterface Entry {\n implementation: ComponentFunction;\n readonly version: () => number;\n readonly bump: () => void;\n readonly proxy: ComponentFunction;\n dirty: boolean;\n}\n\nconst REGISTRY_KEY = \"shadowjs:hmr-registry\";\n\n/**\n * The components of one module, kept across hot updates. Instances are created through a stable\n * proxy that follows the current implementation, so an edit re-renders only the edited component's\n * instances; parents and siblings keep their state. Produced by `registry`; the compiled output\n * of a development build is its only user.\n *\n * @example\n * import { type HotContext, registry } from \"@shadow-js/web/hmr\";\n *\n * declare const hot: HotContext | undefined;\n * const modules = registry(hot, \"src/app.tsx\");\n * console.log(modules.managed); // false when there is no hot context (production, server)\n * @see registry\n * @since 1.0.0\n */\nexport class ModuleRegistry {\n /** The components of the module by name, each with the proxy instances are created through. */\n readonly entries: Map<string, Entry> = new Map<string, Entry>();\n /** True when the module can hot update (a hot context was given); false makes the registry inert. */\n readonly managed: boolean;\n /**\n * Told after each update of this module, once its components are re-rendered. An error boundary\n * that shows its fallback listens here, so the edit that fixes its error rebuilds its children.\n */\n readonly listeners: Set<() => void> = new Set<() => void>();\n\n /**\n * Creates an empty registry.\n *\n * @param managed Whether the module can hot update. When false, `component` returns each\n * implementation unchanged.\n */\n constructor(managed: boolean) {\n this.managed = managed;\n }\n\n /**\n * Re-renders every instance of the components replaced during the last module evaluation, then tells\n * the listeners. The listeners are read before the re-render: a boundary that starts listening because\n * this very update failed is not reset by it.\n */\n commit(): void {\n const listening = [...this.listeners];\n batch(() => {\n for (const entry of this.entries.values()) {\n if (!entry.dirty) continue;\n entry.dirty = false;\n entry.bump();\n }\n });\n for (const listener of listening) listener();\n }\n}\n\n/**\n * Returns the registry of the module identified by `hot`, reusing the one from the previous\n * evaluation of the same module. Without `hot` (production, server) the registry is inert.\n * @internal\n */\nexport function registry(hot: HotContext | undefined, _id: string): ModuleRegistry {\n // A test runner may define `import.meta.hot` without a `data` bag: nothing can hot update there.\n if (hot === undefined || typeof hot.data !== \"object\" || hot.data === null) {\n return new ModuleRegistry(false);\n }\n const previous = hot.data[REGISTRY_KEY];\n if (previous instanceof ModuleRegistry) return previous;\n const created = new ModuleRegistry(true);\n hot.dispose((data) => {\n data[REGISTRY_KEY] = created;\n });\n return created;\n}\n\n/**\n * Registers a component implementation and returns the function to use in its place. On the first\n * evaluation that is a proxy; on later evaluations the same proxy, now backed by the new code.\n * @internal\n */\nexport function component<P>(\n reg: ModuleRegistry,\n name: string,\n implementation: (props: P) => unknown,\n): (props: P) => unknown {\n if (!reg.managed) return implementation;\n const existing = reg.entries.get(name);\n if (existing !== undefined) {\n existing.implementation = implementation as ComponentFunction;\n existing.dirty = true;\n return existing.proxy as (props: P) => unknown;\n }\n const [version, setVersion] = useSignal(0);\n const entry: Entry = {\n implementation: implementation as ComponentFunction,\n version,\n bump: () => {\n setVersion((n) => n + 1);\n },\n proxy: undefined as unknown as ComponentFunction,\n dirty: false,\n };\n const proxy = (props: P): (() => unknown) => {\n // The error boundary above this instance (if any) learns that its children come from this module.\n hotModulesOf(getOwner())?.add(reg);\n // A memo per instance: an update re-renders this component only, not the arrays or regions\n // that merely contain it. It runs component setup, which may write state it owns.\n const node = createComputation({\n kind: \"memo\",\n allowWrites: true,\n fn: () => {\n entry.version();\n return untrack(() => (entry.implementation as (props: P) => unknown)(props));\n },\n });\n return () => readComputation<unknown>(node);\n };\n Object.defineProperty(proxy, \"name\", { value: name });\n (entry as { proxy: ComponentFunction }).proxy = proxy as unknown as ComponentFunction;\n reg.entries.set(name, entry);\n return proxy;\n}\n\n/**\n * Marks the module as able to update itself and applies the replaced components.\n * @internal\n */\nexport function accept(hot: HotContext | undefined, reg: ModuleRegistry): void {\n if (hot === undefined || !reg.managed) return;\n hot.accept();\n reg.commit();\n}\n"],"mappings":"A,4NA6BA,MAAMA,EAAe,wBAiBrB,IAAaC,EAAb,KAA4B,CAE1B,wBAAuC,IAAI,IAE3C,QAKA,0BAAsC,IAAI,IAQ1C,YAAY,EAAkB,CAC5B,KAAK,QAAUC,CACjB,CAOA,QAAe,CACb,IAAMC,EAAY,CAAC,GAAG,KAAK,SAAS,EACpCC,MAAY,CACV,IAAK,IAAMC,KAAS,KAAK,QAAQ,OAAO,EACjCA,EAAM,QACX,EAAM,MAAQ,GACdA,EAAM,KAAK,EAEf,CAAC,EACD,IAAK,IAAMC,KAAYH,EAAWG,EAAS,CAC7C,CACF,EAOA,SAAgBC,EAAS,EAA6B,EAA6B,CAEjF,GAAIC,IAAQ,IAAA,IAAa,OAAOA,EAAI,MAAS,UAAYA,EAAI,OAAS,KACpE,OAAO,IAAIP,EAAe,EAAK,EAEjC,IAAMQ,EAAWD,EAAI,KAAKR,GAC1B,GAAIS,aAAoBR,EAAgB,OAAOQ,EAC/C,IAAMC,EAAU,IAAIT,EAAe,EAAI,EAIvC,OAHAO,EAAI,QAAS,GAAS,CACpB,EAAKR,GAAgBU,CACvB,CAAC,EACMA,CACT,CAOA,SAAgBC,EACd,EACA,EACA,EACuB,CACvB,GAAI,CAACC,EAAI,QAAS,OAAOC,EACzB,IAAMC,EAAWF,EAAI,QAAQ,IAAIG,CAAI,EACrC,GAAID,IAAa,IAAA,GAGf,MAFA,GAAS,eAAiBD,EAC1B,EAAS,MAAQ,GACVC,EAAS,MAElB,GAAM,CAACE,EAASC,GAAcC,EAAU,CAAC,EACnCb,EAAe,CACH,iBAChB,UACA,SAAY,CACVY,EAAY,GAAME,EAAI,CAAC,CACzB,EACA,MAAO,IAAA,GACP,MAAO,EACT,EACMC,EAAS,GAA8B,CAE3CC,EAAaC,EAAS,CAAC,CAAC,EAAE,IAAIV,CAAG,EAGjC,IAAMW,EAAOC,EAAkB,CAC7B,KAAM,OACN,YAAa,GACb,QACEnB,EAAM,QAAQ,EACPoB,MAAepB,EAAM,eAAyCqB,CAAK,CAAC,EAE/E,CAAC,EACD,UAAaC,EAAyBJ,CAAI,CAC5C,EAIA,OAHA,OAAO,eAAeH,EAAO,OAAQ,CAAE,MAAOL,CAAK,CAAC,EACpD,EAAwC,MAAQK,EAChDR,EAAI,QAAQ,IAAIG,EAAMV,CAAK,EACpBe,CACT,CAMA,SAAgBQ,EAAO,EAA6B,EAA2B,CACzEpB,IAAQ,IAAA,IAAcI,EAAI,UAC9BJ,EAAI,OAAO,EACXI,EAAI,OAAO,EACb,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createRootScope as e,resourceKey as t,withScope as n}from"./internal/hydration-scope.js";import{beginClaiming as r,claimElement as i,claimPortal as a,endClaiming as o,isClaiming as s,liftedRegions as c,releaseUnclaimedPortals as l,takeRegion as u,withoutClaiming as d}from"./internal/claim.js";import{claims as f}from"./internal/hydration-hooks.js";import{bindRegion as p,createRegion as m,removeRegion as h}from"./insert.js";import{attachRootErrors as g}from"./control-flow/root-errors.js";import{replayEarlyEvents as _}from"./internal/early-events.js";import{ResourceCacheContext as v,batch as y,createRoot as b,flushSync as x,runWithOwner as S,untrack as C}from"@shadow-js/core";import{withHydration as w}from"@shadow-js/core/extend";function T(e){let n=/* @__PURE__ */ new Set;return{key:t,read(t){if(!n.has(t)&&Object.hasOwn(e,t))return n.add(t),{value:e[t]}},track(){}}}function E(e){let t=e instanceof Document?e:e.ownerDocument;if(t===null)return;t.body!==null&&l(t.body);let n=t.createTreeWalker(e,NodeFilter.SHOW_COMMENT),r=[];for(;n.nextNode();){let e=n.currentNode;(e.data===`[`||e.data===`]`)&&r.push(e)}for(let e of r)e.remove()}function D(t,l,D={}){if(s())throw Error(`SHADOW_HYDRATE_RUNNING`);let O=/* @__PURE__ */ new Map,k=l instanceof Element?[l]:[];for(let e of[...k,...Array.from(l.querySelectorAll(`[data-hk]`))]){let t=e.getAttribute(`data-hk`);t!==null&&O.set(t,e)}r(O,D.onRecoverableError);let A={claimElement:i,takeRegion:u,liftedRegions:c,claimPortal:a,isClaiming:s,withoutClaiming:d},j=f.current;f.current=A;let M=T(D.data??{}),N=m(l,null,Array.from(l.childNodes)),P;try{P=w(()=>y(()=>n(e(D.renderId),()=>S(D.owner??null,()=>b(e=>(g(D),v({value:M,get children(){return p(N,C(t)),null}}),e)))))),x()}finally{o(),f.current=j}_(),E(l);let F=!1;return()=>{F||(F=!0,P(),h(N))}}export{D as hydrate};
|
|
2
|
+
//# sourceMappingURL=hydration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration.js","names":["dataCache","used","resourceKey","key","data","stripLeftovers","doc","container","releaseUnclaimedPortals","walker","stale","comment","hydrate","isClaiming","registry","roots","element","beginClaiming","options","passClaims","previousClaims","claims","cache","region","createRegion","stop","withHydration","batch","withScope","createRootScope","runWithOwner","createRoot","attachRootErrors","ResourceCacheContext","bindRegion","untrack","code","dispose","flushSync","endClaiming","replayEarlyEvents","disposed","removeRegion"],"sources":["../../src/hydration.ts"],"sourcesContent":["import {\n batch,\n createRoot,\n flushSync,\n type Owner,\n type ResourceCache,\n ResourceCacheContext,\n runWithOwner,\n untrack,\n} from \"@shadow-js/core\";\nimport { withHydration } from \"@shadow-js/core/extend\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport {\n beginClaiming,\n claimElement,\n claimPortal,\n endClaiming,\n isClaiming,\n liftedRegions,\n releaseUnclaimedPortals,\n takeRegion,\n withoutClaiming,\n} from \"./internal/claim\";\nimport { replayEarlyEvents } from \"./internal/early-events\";\nimport { type Claims, claims } from \"./internal/hydration-hooks\";\nimport { createRootScope, resourceKey, withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link hydrate}: the server render it continues, the root's owner, and the error\n * reporters it inherits from `RootErrorOptions` (`onUncaughtError`, `onCaughtError`,\n * `onRecoverableError`).\n * @since 1.0.0\n */\nexport interface HydrateOptions extends RootErrorOptions {\n /**\n * The id the server render used, so the client numbers its elements with the same keys. Must\n * equal the `renderId` given to the server render.\n * @default \"0\"\n */\n renderId?: string;\n /**\n * The resource values the server fetched: the `data` of `renderToStringAsync`. A resource whose\n * key is found here starts with that value instead of fetching it again. Each value is used once.\n * @default {} (no resource value is preloaded; resources fetch on the client)\n */\n data?: Record<string, unknown>;\n /**\n * The owner the hydrated root is created under, so its context (providers) is visible to the app.\n * @default null (the root has no parent owner)\n */\n owner?: Owner;\n}\n\nfunction dataCache(data: Record<string, unknown>): ResourceCache {\n const used = new Set<string>();\n return {\n key: resourceKey,\n read(key) {\n if (used.has(key) || !Object.hasOwn(data, key)) return undefined;\n used.add(key);\n return { value: data[key] };\n },\n track() {\n // Client fetches are not tracked: nothing waits for them.\n },\n };\n}\n\n/**\n * Removes marker comments the pass did not claim, so the live DOM never keeps any, and the server\n * blocks of portals the client did not render (they would show content the client does not have).\n */\nfunction stripLeftovers(container: Node): void {\n const doc = container instanceof Document ? container : container.ownerDocument;\n if (doc === null) return;\n if (doc.body !== null) releaseUnclaimedPortals(doc.body);\n const walker = doc.createTreeWalker(container, NodeFilter.SHOW_COMMENT);\n const stale: Comment[] = [];\n while (walker.nextNode()) {\n const comment = walker.currentNode as Comment;\n if (comment.data === \"[\" || comment.data === \"]\") stale.push(comment);\n }\n for (const comment of stale) comment.remove();\n}\n\n/**\n * Attaches the application to HTML the server already rendered into `container`. Elements are\n * claimed by their `data-hk` keys instead of created, so the DOM is not rebuilt and nodes keep\n * their identity. Event handlers and reactive bindings are attached; markers are removed. Parts the\n * server and client disagree on are repaired by reconciliation, never left half hydrated.\n *\n * @param code Runs once, untracked, and builds the same component tree the server rendered.\n * @param container Element or Document that holds the server markup.\n * @param options `renderId` (must match the server), the server's resource `data`, an `owner`, and\n * the error reporters. Undefined uses the defaults.\n * @returns A dispose function that stops the hydrated root and removes its nodes. Safe to call more\n * than once.\n * @throws Error (production message `SHADOW_HYDRATE_RUNNING`) when called while another hydration\n * pass is in progress.\n * @example\n * import { createComponent, hydrate } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const container = document.getElementById(\"app\") as Element;\n * const data = JSON.parse(document.getElementById(\"data\")?.textContent ?? \"{}\") as Record<\n * string,\n * unknown\n * >;\n * const dispose = hydrate(() => createComponent(App, {}), container, { data });\n * @see render\n * @since 1.0.0\n */\nexport function hydrate(\n code: () => unknown,\n container: Element | Document,\n options: HydrateOptions = {},\n): () => void {\n if (isClaiming())\n throw new Error(\n __DEV__ ? \"hydrate(): a hydration pass is already running.\" : \"SHADOW_HYDRATE_RUNNING\",\n );\n const registry = new Map<string, Element>();\n const roots: Element[] = container instanceof Element ? [container] : [];\n for (const element of [...roots, ...Array.from(container.querySelectorAll(\"[data-hk]\"))]) {\n const key = element.getAttribute(\"data-hk\");\n if (key !== null) registry.set(key, element);\n }\n beginClaiming(registry, options.onRecoverableError);\n // The renderer reaches the claiming code only through this hook, installed for this pass alone.\n const passClaims: Claims = {\n claimElement,\n takeRegion,\n liftedRegions,\n claimPortal,\n isClaiming,\n withoutClaiming,\n };\n const previousClaims = claims.current;\n claims.current = passClaims;\n const cache = dataCache(options.data ?? {});\n const region = createRegion(container, null, Array.from(container.childNodes));\n let stop: () => void;\n try {\n // The batch wraps the scope, not the other way round: its exit flushes the queued effects\n // (onMount, and the re-renders they cause) after the scope is restored. The scope numbers only\n // the templates the server rendered; an effect that builds new DOM must not draw keys from it\n // (that shifts the keys of later siblings and misses the ones the server never sent). Boundaries\n // rebuild from their own captured scope, so a reset inside the pass still claims its elements.\n stop = withHydration(() =>\n batch(() =>\n withScope(createRootScope(options.renderId), () =>\n runWithOwner(options.owner ?? null, () =>\n createRoot((dispose) => {\n attachRootErrors(options);\n ResourceCacheContext({\n value: cache,\n get children() {\n bindRegion(region, untrack(code));\n return null;\n },\n });\n return dispose;\n }),\n ),\n ),\n ),\n );\n flushSync();\n } finally {\n endClaiming();\n claims.current = previousClaims;\n }\n replayEarlyEvents();\n stripLeftovers(container);\n let disposed = false;\n return () => {\n if (disposed) return;\n disposed = true;\n stop();\n removeRegion(region);\n };\n}\n"],"mappings":"A,wuBAsDA,SAASA,EAAU,EAA8C,CAC/D,IAAMC,kBAAO,IAAI,IACjB,MAAO,CACL,IAAKC,EACL,KAAK,EAAK,CACR,GAAI,GAAK,IAAIC,CAAG,GAAM,OAAO,OAAOC,EAAMD,CAAG,EAE7C,OADAF,EAAK,IAAIE,CAAG,EACL,CAAE,MAAOC,EAAKD,EAAK,CAC5B,EACA,OAAQ,CAER,CACF,CACF,CAMA,SAASE,EAAe,EAAuB,CAC7C,IAAMC,EAAMC,aAAqB,SAAWA,EAAYA,EAAU,cAClE,GAAID,IAAQ,KAAM,OACdA,EAAI,OAAS,MAAME,EAAwBF,EAAI,IAAI,EACvD,IAAMG,EAASH,EAAI,iBAAiBC,EAAW,WAAW,YAAY,EAChEG,EAAmB,CAAC,EAC1B,KAAOD,EAAO,SAAS,GAAG,CACxB,IAAME,EAAUF,EAAO,aACnBE,EAAQ,OAAS,KAAOA,EAAQ,OAAS,MAAKD,EAAM,KAAKC,CAAO,CACtE,CACA,IAAK,IAAMA,KAAWD,EAAOC,EAAQ,OAAO,CAC9C,CAgCA,SAAgBC,EACd,EACA,EACA,EAA0B,CAAC,EACf,CACZ,GAAIC,EAAW,EACb,MAAU,MACsD,wBAChE,EACF,IAAMC,kBAAW,IAAI,IACfC,EAAmBR,aAAqB,QAAU,CAACA,CAAS,EAAI,CAAC,EACvE,IAAK,IAAMS,IAAW,CAAC,GAAGD,EAAO,GAAG,MAAM,KAAKR,EAAU,iBAAiB,WAAW,CAAC,CAAC,EAAG,CACxF,IAAMJ,EAAMa,EAAQ,aAAa,SAAS,EACtCb,IAAQ,MAAMW,EAAS,IAAIX,EAAKa,CAAO,CAC7C,CACAC,EAAcH,EAAUI,EAAQ,kBAAkB,EAElD,IAAMC,EAAqB,CACzB,eACA,aACA,gBACA,cACA,aACA,iBACF,EACMC,EAAiBC,EAAO,QAC9B,EAAO,QAAUF,EACjB,IAAMG,EAAQtB,EAAUkB,EAAQ,MAAQ,CAAC,CAAC,EACpCK,EAASC,EAAajB,EAAW,KAAM,MAAM,KAAKA,EAAU,UAAU,CAAC,EACzEkB,EACJ,GAAI,CAMF,EAAOC,MACLC,MACEC,EAAUC,EAAgBX,EAAQ,QAAQ,MACxCY,EAAaZ,EAAQ,OAAS,SAC5Ba,EAAY,IACVC,EAAiBd,CAAO,EACxBe,EAAqB,CACnB,MAAOX,EACP,IAAI,UAAW,CAEb,OADAY,EAAWX,EAAQY,EAAQC,CAAI,CAAC,EACzB,IACT,CACF,CAAC,EACMC,EACR,CACH,CACF,CACF,CACF,EACAC,EAAU,CACZ,QAAU,CACRC,EAAY,EACZ,EAAO,QAAUnB,CACnB,CACAoB,EAAkB,EAClBnC,EAAeE,CAAS,EACxB,IAAIkC,EAAW,GACf,UAAa,CACPA,IACJ,EAAW,GACXhB,EAAK,EACLiB,EAAanB,CAAM,EACrB,CACF,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{setAttribute as e,setAttributeNS as t,setBoolAttribute as n}from"./attributes.js";import{autoFocus as r}from"./autofocus.js";import{classList as i,className as a,setStyleProperty as o,style as s}from"./class-style.js";import{createComponent as c}from"./component.js";import{Activity as l}from"./control-flow/activity.js";import{Show as u}from"./control-flow/show.js";import{ClientOnly as d}from"./control-flow/client-only.js";import{anchor as f,insert as p}from"./insert.js";import{element as m}from"./element.js";import{addEventListener as h,chainEvents as g,clearDelegatedEvents as _,delegateEvents as v}from"./events.js";import{setSelectValue as y}from"./select-value.js";import{spread as b}from"./spread.js";import{Dynamic as x,createDynamic as S}from"./control-flow/dynamic.js";import{ErrorBoundary as C}from"./control-flow/error-boundary.js";import{For as w}from"./control-flow/for.js";import{Fragment as T}from"./control-flow/fragment.js";import{Index as E}from"./control-flow/index-list.js";import{lazy as D}from"./control-flow/lazy.js";import{NoHydration as O}from"./control-flow/no-hydration.js";import{Portal as k}from"./control-flow/portal.js";import{SuspenseList as A}from"./control-flow/suspense-list.js";import{Suspense as j}from"./control-flow/suspense.js";import{Match as M,Switch as N}from"./control-flow/switch.js";import{derived as P}from"./derived.js";import{useHead as F}from"./head/use-head.js";import{Base as I,Link as L,Meta as R,Style as z,Title as B}from"./head/components.js";import{hydrate as V}from"./hydration.js";import{effect as H,memo as U,refTo as W,use as G}from"./reactive.js";import{render as K}from"./render.js";import{preconnect as q,prefetchDNS as J,preinit as Y,preinitModule as X,preload as Z,preloadModule as Q}from"./resource-hints.js";import{template as $}from"./template.js";import{ViewTransition as ee,startViewTransition as te}from"./view-transition.js";import{isDev as ne,isServer as re,mergeProps as ie}from"@shadow-js/core";export{l as Activity,I as Base,d as ClientOnly,x as Dynamic,C as ErrorBoundary,w as For,T as Fragment,E as Index,L as Link,M as Match,R as Meta,O as NoHydration,k as Portal,u as Show,z as Style,j as Suspense,A as SuspenseList,N as Switch,B as Title,ee as ViewTransition,h as addEventListener,f as anchor,r as autoFocus,g as chainEvents,i as classList,a as className,_ as clearDelegatedEvents,c as createComponent,S as createDynamic,v as delegateEvents,P as derived,H as effect,m as element,V as hydrate,p as insert,ne as isDev,re as isServer,D as lazy,U as memo,ie as mergeProps,q as preconnect,J as prefetchDNS,Y as preinit,X as preinitModule,Z as preload,Q as preloadModule,W as refTo,K as render,e as setAttribute,t as setAttributeNS,n as setBoolAttribute,y as setSelectValue,o as setStyleProperty,b as spread,te as startViewTransition,s as style,$ as template,G as use,F as useHead};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{claims as e}from"./internal/hydration-hooks.js";import{reconcileNodes as t}from"./internal/reconcile.js";import{useRenderEffect as n}from"@shadow-js/core";import{createComputation as r,currentOwner as i,disposeOwner as a,readComputation as o}from"@shadow-js/core/extend";function s(e){return e instanceof Document?e:e.ownerDocument??document}function c(e,t){let n=e.texts;return n===t||n instanceof Set&&n.has(t)}function l(e,t){let n=e.texts;n===null?e.texts=t:n instanceof Set?n.add(t):n!==t&&(e.texts=/* @__PURE__ */ new Set([n,t]))}function u(e,t){let n=e.texts;if(n!==null){if(n instanceof Set){let e=new Set(t);for(let t of n)e.has(t)||n.delete(t)}else t.includes(n)||(e.texts=null)}}function d(e,t=e=>e()){let n=[],r=[[e]],i=[0],a=/* @__PURE__ */ new Set;for(;r.length>0;){let e=r.length-1,o=r[e],s=i[e]??0;if(o===void 0||s>=o.length){let e=r.pop();e!==void 0&&a.delete(e),i.pop();continue}i[e]=s+1;let c=o[s];for(let e=0;typeof c==`function`;e+=1){if(e>=1e4)throw TypeError(`SHADOW_INSERT_DEPTH`);c=t(c)}if(c!=null&&typeof c!=`boolean`){if(typeof c==`string`)n.push(c);else if(typeof c==`number`)n.push(String(c));else if(c instanceof DocumentFragment)for(let e of c.childNodes)n.push(e);else if(c instanceof Node)n.push(c);else if(Array.isArray(c)){if(a.has(c))throw TypeError(`SHADOW_INSERT_CYCLE`);a.add(c),r.push(c),i.push(0)}else n.push(String(c))}}return n}function f(e){let t=/* @__PURE__ */ new Map;for(let n of e.nodes){if(!(n instanceof Text)||!c(e,n))continue;let r=t.get(n.data);r===void 0?t.set(n.data,[n]):r.push(n)}return t}function p(e,t){let n=t.length===1?t[0]:void 0;if(typeof n==`string`){let t=e.nodes.length===1?e.nodes[0]:void 0;if(t instanceof Text&&c(e,t))return t.data!==n&&(t.data=n),[t]}let r=Array(t.length),i=0,a=/* @__PURE__ */ new Set,o;for(let n of t)if(typeof n==`string`){o??=f(e);let t=o.get(n)?.pop();t===void 0&&(t=s(e.parent).createTextNode(n),l(e,t)),a.add(t),r[i]=t,i+=1}else a.has(n)||(a.add(n),r[i]=n,i+=1);return r.length=i,r}function m(e,t){if(e.anchor!==null)return e.anchor;let n=t.at(-1);if(n!==void 0)return n.nextSibling;let r=e.marker;return r===null?e.parent.firstChild:r.parentNode===e.parent?r.nextSibling:null}function h(e,n){let r=e.parent,i=e.nodes.filter(e=>e.parentNode===r),a=m(e,i),o=i[0];n.length===0&&o!==void 0&&(e.marker=o.previousSibling),t(r,i,n,a),e.nodes=n,u(e,n)}function g(e,t){h(e,p(e,t))}function _(e,t){if(typeof t==`string`||typeof t==`number`){let n=e.nodes,r=typeof t==`string`?t:String(t);if(n.length===1){let t=n[0];if(t instanceof Text&&t.parentNode===e.parent&&c(e,t)){t.data!==r&&(t.data=r);return}}else if(n.length===0){let t=s(e.parent).createTextNode(r);l(e,t),e.parent.insertBefore(t,m(e,n)),e.nodes=[t];return}}g(e,d(t))}function v(e,t){let n=[],r=/* @__PURE__ */ new Set;for(let i of d(t))typeof i==`string`||r.has(i)||i.parentNode!==e||(r.add(i),n.push(i));return n}function y(e,t,n){let r=n===void 0?[]:v(e,n),i={parent:e,anchor:t,marker:r.length>0?r[0]?.previousSibling??null:e.lastChild,nodes:r,texts:null};for(let e of r)e instanceof Text&&l(i,e);return i}function b(e){if(typeof e==`function`)return!0;if(!Array.isArray(e))return!1;let t=[e],n=/* @__PURE__ */ new Set([e]);for(;t.length>0;){let e=t.pop()??[];for(let r of e){if(typeof r==`function`)return!0;Array.isArray(r)&&!n.has(r)&&(n.add(r),t.push(r))}}return!1}function x(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Set;return{begin(){n=/* @__PURE__ */ new Set},call(i){n.add(i);let a=t.get(i);return a===void 0&&(a=r({kind:`memo`,fn:()=>i(),allowWrites:!0,owner:e}),t.set(i,a)),o(a)},prune(){for(let[e,r]of t)n.has(e)||(t.delete(e),a(r))}}}function S(e,t){if(!b(t))return _(e,t),t instanceof DocumentFragment?[...e.nodes]:t;let r;return n(typeof t==`function`?t:()=>t,t=>{if(r=t,b(t)){let r=x(i());n(()=>{r.begin();let e=d(t,r.call);return r.prune(),e},t=>{g(e,t)})}else _(e,t)}),r}function C(e){for(let t of e.nodes)t.parentNode===e.parent&&e.parent.removeChild(t);e.nodes=[],e.texts=null}function w(e,t){let n=s(e).createTextNode(``);return e.insertBefore(n,t),n}function T(t,n,r,i){let a=r??null;return S(y(t,a,i===void 0?e.current.takeRegion(t,a):i),n)}export{w as anchor,S as bindRegion,y as createRegion,T as insert,C as removeRegion};
|
|
2
|
+
//# sourceMappingURL=insert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insert.js","names":["documentOf","node","ownsText","texts","region","addText","text","pruneTexts","kept","keep","flatten","fn","parts","frames","root","cursors","active","top","frame","cursor","done","item","depth","call","child","reusablePool","pool","list","materialize","only","current","nodes","count","seen","part","endOf","last","attached","marker","reconcileRegion","parent","end","first","next","reconcileNodes","commit","commitValue","raw","created","adoptInitial","adopted","initial","createRegion","anchorNode","containsFunction","stack","createCallCache","memos","touched","createComputation","readComputation","disposeOwner","bindRegion","value","latest","useRenderEffect","cache","currentOwner","removeRegion","anchor","before","insert","resolvedAnchor","claims"],"sources":["../../src/insert.ts"],"sourcesContent":["import { useRenderEffect } from \"@shadow-js/core\";\nimport {\n type ComputationNode,\n createComputation,\n currentOwner,\n disposeOwner,\n readComputation,\n} from \"@shadow-js/core/extend\";\nimport { checkClaimedText } from \"./internal/claim\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { reconcileNodes } from \"./internal/reconcile\";\n\n/** One piece of a value after flattening: a DOM node, or text to be turned into a Text node. */\ntype Part = Node | string;\n\n/** Longest chain of accessors a single value may hold (a function returning a function ...). */\nconst MAX_ACCESSOR_DEPTH = 10_000;\n\n/**\n * State of one dynamic child region. `nodes` are the DOM nodes the region owns, in order. When\n * `anchor` is set, content goes before it. Without one, an empty region is placed after `marker`\n * (the node that preceded it), so it keeps its position while it is empty.\n * @internal\n */\nexport interface Region {\n readonly parent: Node;\n readonly anchor: Node | null;\n marker: Node | null;\n nodes: Node[];\n /**\n * Text nodes this region created or adopted; only these may be reused by string updates. Null for none, the node\n * itself for one (the usual region: a single dynamic text), a Set for more, so most regions allocate no Set.\n */\n texts: Text | Set<Text> | null;\n /**\n * Development only: the server nodes a hydration pass handed this region, kept until its first\n * commit compares their text with the value (`checkClaimedText`).\n */\n claimed?: readonly Node[] | undefined;\n}\n\n/** The document a node belongs to (a Document is its own document). */\nfunction documentOf(node: Node): Document {\n return node instanceof Document ? node : (node.ownerDocument ?? document);\n}\n\n/** True when the region created or adopted `node`. */\nfunction ownsText(region: Region, node: Node): boolean {\n const texts = region.texts;\n return texts === node || (texts instanceof Set && texts.has(node as Text));\n}\n\n/** Records that the region owns `text`. */\nfunction addText(region: Region, text: Text): void {\n const texts = region.texts;\n if (texts === null) region.texts = text;\n else if (texts instanceof Set) texts.add(text);\n else if (texts !== text) region.texts = new Set([texts, text]);\n}\n\n/** Forgets the Text nodes of the region that are not in `keep`. */\nfunction pruneTexts(region: Region, keep: readonly Node[]): void {\n const texts = region.texts;\n if (texts === null) return;\n if (texts instanceof Set) {\n const kept = new Set<Node>(keep);\n for (const text of texts) {\n if (!kept.has(text)) texts.delete(text);\n }\n } else if (!keep.includes(texts)) region.texts = null;\n}\n\n/**\n * Flattens a value into parts without recursion. Functions are called (and their results unwrapped)\n * through `call`, which runs inside the render effect that owns the value, so reads are tracked.\n */\nfunction flatten(root: unknown, call: (fn: () => unknown) => unknown = (fn) => fn()): Part[] {\n const parts: Part[] = [];\n const frames: unknown[][] = [[root]];\n const cursors: number[] = [0];\n const active = new Set<unknown[]>();\n while (frames.length > 0) {\n const top = frames.length - 1;\n const frame = frames[top];\n const cursor = cursors[top] ?? 0;\n if (frame === undefined || cursor >= frame.length) {\n const done = frames.pop();\n if (done !== undefined) active.delete(done);\n cursors.pop();\n continue;\n }\n cursors[top] = cursor + 1;\n let item: unknown = frame[cursor];\n for (let depth = 0; typeof item === \"function\"; depth += 1) {\n if (depth >= MAX_ACCESSOR_DEPTH)\n throw new TypeError(\n __DEV__ ? \"insert(): accessor chain is too deep.\" : \"SHADOW_INSERT_DEPTH\",\n );\n item = call(item as () => unknown);\n }\n if (item === null || item === undefined || typeof item === \"boolean\") continue;\n if (typeof item === \"string\") parts.push(item);\n else if (typeof item === \"number\") parts.push(String(item));\n else if (item instanceof DocumentFragment) {\n for (const child of item.childNodes) parts.push(child);\n } else if (item instanceof Node) parts.push(item);\n else if (Array.isArray(item)) {\n if (active.has(item))\n throw new TypeError(__DEV__ ? \"insert(): a value contains itself.\" : \"SHADOW_INSERT_CYCLE\");\n active.add(item);\n frames.push(item);\n cursors.push(0);\n } else parts.push(String(item));\n }\n return parts;\n}\n\n/** Text nodes the region currently owns, keyed by their data, for reuse by equal strings. */\nfunction reusablePool(region: Region): Map<string, Text[]> {\n const pool = new Map<string, Text[]>();\n for (const node of region.nodes) {\n if (!(node instanceof Text) || !ownsText(region, node)) continue;\n const list = pool.get(node.data);\n if (list === undefined) pool.set(node.data, [node]);\n else list.push(node);\n }\n return pool;\n}\n\n/** Turns parts into the nodes the region should hold, reusing its own Text nodes where possible. */\nfunction materialize(region: Region, parts: readonly Part[]): Node[] {\n const only = parts.length === 1 ? parts[0] : undefined;\n if (typeof only === \"string\") {\n const current = region.nodes.length === 1 ? region.nodes[0] : undefined;\n if (current instanceof Text && ownsText(region, current)) {\n if (current.data !== only) current.data = only;\n return [current];\n }\n }\n // Sized to the parts: `[]` and `push` would reserve room for sixteen nodes in every dynamic child (a row has two).\n const nodes: Node[] = new Array<Node>(parts.length);\n let count = 0;\n const seen = new Set<Node>();\n let pool: Map<string, Text[]> | undefined;\n for (const part of parts) {\n if (typeof part === \"string\") {\n pool ??= reusablePool(region);\n const reused = pool.get(part)?.pop();\n let text = reused;\n if (text === undefined) {\n text = documentOf(region.parent).createTextNode(part);\n addText(region, text);\n }\n seen.add(text);\n nodes[count] = text;\n count += 1;\n } else if (!seen.has(part)) {\n seen.add(part);\n nodes[count] = part;\n count += 1;\n }\n }\n nodes.length = count;\n return nodes;\n}\n\n/** The node after the region: its anchor, or the node after its last attached child, or its marker. */\nfunction endOf(region: Region, attached: readonly Node[]): Node | null {\n if (region.anchor !== null) return region.anchor;\n const last = attached.at(-1);\n if (last !== undefined) return last.nextSibling;\n const marker = region.marker;\n if (marker === null) return region.parent.firstChild;\n if (marker.parentNode !== region.parent) return null;\n return marker.nextSibling;\n}\n\n/** Makes the DOM show `next` for this region. */\nfunction reconcileRegion(region: Region, next: Node[]): void {\n const parent = region.parent;\n const attached = region.nodes.filter((node) => node.parentNode === parent);\n const end = endOf(region, attached);\n const first = attached[0];\n if (next.length === 0 && first !== undefined) region.marker = first.previousSibling;\n reconcileNodes(parent, attached, next, end);\n region.nodes = next;\n pruneTexts(region, next);\n}\n\n/** Applies a flattened value to a region. */\nfunction commit(region: Region, parts: readonly Part[]): void {\n if (__DEV__ && region.claimed !== undefined) {\n // Only the first commit of a claimed region is compared; later changes are ordinary updates.\n checkClaimedText(region.claimed, parts);\n region.claimed = undefined;\n }\n reconcileRegion(region, materialize(region, parts));\n}\n\n/**\n * Applies a resolved value to a region. A string or number is the common case (a dynamic text): when the region\n * already shows its own Text node only the data is rewritten, and an empty region gets one new Text node, with none of\n * the flattening and reconciling a general value needs.\n */\nfunction commitValue(region: Region, raw: unknown): void {\n if ((typeof raw === \"string\" || typeof raw === \"number\") && !(__DEV__ && region.claimed)) {\n const nodes = region.nodes;\n const text = typeof raw === \"string\" ? raw : String(raw);\n if (nodes.length === 1) {\n const current = nodes[0];\n if (\n current instanceof Text &&\n current.parentNode === region.parent &&\n ownsText(region, current)\n ) {\n if (current.data !== text) current.data = text;\n return;\n }\n } else if (nodes.length === 0) {\n const created = documentOf(region.parent).createTextNode(text);\n addText(region, created);\n region.parent.insertBefore(created, endOf(region, nodes));\n region.nodes = [created];\n return;\n }\n }\n commit(region, flatten(raw));\n}\n\n/** Nodes of `initial` (already in the parent) that the region adopts as its current content. */\nfunction adoptInitial(parent: Node, initial: unknown): Node[] {\n const adopted: Node[] = [];\n const seen = new Set<Node>();\n for (const part of flatten(initial)) {\n if (typeof part === \"string\" || seen.has(part) || part.parentNode !== parent) continue;\n seen.add(part);\n adopted.push(part);\n }\n return adopted;\n}\n\n/**\n * Creates the state of a region in `parent`. `anchorNode` (null to append) and `initial` (nodes\n * already in the DOM, from hydration or splitText) are both optional.\n * @internal\n */\nexport function createRegion(parent: Node, anchorNode: Node | null, initial: unknown): Region {\n const nodes = initial === undefined ? [] : adoptInitial(parent, initial);\n const marker = nodes.length > 0 ? (nodes[0]?.previousSibling ?? null) : parent.lastChild;\n const region: Region = { parent, anchor: anchorNode, marker, nodes, texts: null };\n for (const node of nodes) if (node instanceof Text) addText(region, node);\n // A region that adopts server nodes during a hydration pass is checked against its first commit.\n if (__DEV__ && initial !== undefined && claims.current.isClaiming()) region.claimed = nodes;\n return region;\n}\n\n/**\n * True when a function appears anywhere in `root`, at any array depth. Scans without calling\n * anything; `seen` stops it from looping on cyclic arrays (flatten reports those).\n */\nfunction containsFunction(root: unknown): boolean {\n if (typeof root === \"function\") return true;\n if (!Array.isArray(root)) return false;\n const stack: unknown[][] = [root];\n const seen = new Set<unknown[]>([root]);\n while (stack.length > 0) {\n const frame = stack.pop() ?? [];\n for (const item of frame) {\n if (typeof item === \"function\") return true;\n if (Array.isArray(item) && !seen.has(item)) {\n seen.add(item);\n stack.push(item);\n }\n }\n }\n return false;\n}\n\n/**\n * One memo per accessor function, owned by `owner` (the effect that evaluates the region's expression,\n * so a new result drops them all; the effect that resolves the result runs many times and must not\n * own them). `prune` disposes the memos of accessors the last\n * run did not meet, which bounds the cache by what the region currently shows.\n */\nfunction createCallCache(owner: ReturnType<typeof currentOwner>): {\n begin(): void;\n call(fn: () => unknown): unknown;\n prune(): void;\n} {\n const memos = new Map<() => unknown, ComputationNode>();\n let touched = new Set<() => unknown>();\n return {\n begin(): void {\n touched = new Set();\n },\n call(fn: () => unknown): unknown {\n touched.add(fn);\n let node = memos.get(fn);\n if (node === undefined) {\n // Component setup runs inside these memos, which may write the state it owns.\n node = createComputation({ kind: \"memo\", fn: () => fn(), allowWrites: true, owner });\n memos.set(fn, node);\n }\n return readComputation(node);\n },\n prune(): void {\n for (const [fn, node] of memos) {\n if (touched.has(fn)) continue;\n memos.delete(fn);\n disposeOwner(node);\n }\n },\n };\n}\n\n/**\n * Keeps a region in sync with `value`. A value that is or contains a function (an accessor, or an\n * array with accessor members) runs inside a render effect, so its reads are tracked. Anything\n * else is inserted once.\n * @internal\n */\nexport function bindRegion(region: Region, value: unknown): unknown {\n if (!containsFunction(value)) {\n commitValue(region, value);\n return value instanceof DocumentFragment ? [...region.nodes] : value;\n }\n let latest: unknown;\n const accessor = typeof value === \"function\" ? (value as () => unknown) : () => value;\n // Every accessor met while resolving the result is evaluated by a memo of its own, kept between\n // runs. An accessor that builds components (`() => show() ? <Late /> : null`) then runs again\n // only when what it reads changes, not whenever something it returned (the component's own\n // accessor, reading its own data) does.\n // Two stages. The outer effect runs the expression and tracks only what the expression itself\n // reads. When the result holds accessors (a component returned one, or `props.children` did),\n // a nested effect resolves them, so a change inside the result re-renders the result but never\n // re-runs the expression: re-running `() => props.children` would build the child components\n // again, discarding their state.\n useRenderEffect(accessor, (raw) => {\n latest = raw;\n if (containsFunction(raw)) {\n const cache = createCallCache(currentOwner());\n useRenderEffect(\n () => {\n cache.begin();\n const parts = flatten(raw, cache.call);\n cache.prune();\n return parts;\n },\n (parts) => {\n commit(region, parts);\n },\n );\n } else {\n commitValue(region, raw);\n }\n });\n return latest;\n}\n\n/**\n * Removes a region's nodes from its parent. Anchors and nodes that were moved elsewhere are not\n * touched.\n * @internal\n */\nexport function removeRegion(region: Region): void {\n for (const node of region.nodes) {\n if (node.parentNode === region.parent) region.parent.removeChild(node);\n }\n region.nodes = [];\n region.texts = null;\n}\n\n/**\n * Creates a text anchor: an empty Text node placed before `before` (appended when null). Use it as\n * the stable insertion point between two dynamic regions; it is never removed by the runtime.\n *\n * @param parent Node that receives the anchor.\n * @param before Node the anchor goes before, or null to append.\n * @returns The new empty Text node.\n * @example\n * import { anchor, insert } from \"@shadow-js/web\";\n *\n * const list = document.createElement(\"ul\");\n * const slot = anchor(list, null);\n * insert(list, \"first\", slot); // goes before the anchor\n * @see insert\n * @since 1.0.0\n */\nexport function anchor(parent: Node, before: Node | null): Text {\n const text = documentOf(parent).createTextNode(\"\");\n parent.insertBefore(text, before);\n return text;\n}\n\n/**\n * Reactive child insertion: keeps the content of a region in sync with `value`.\n *\n * - A function is an accessor, wrapped in a render effect; it re-runs when its dependencies change.\n * - `null`, `undefined`, booleans render nothing. Strings and numbers become one Text node, reused\n * when the region already holds one. A Node is inserted itself. A DocumentFragment inserts a\n * snapshot of its children. Arrays are flattened, nested arrays included.\n * - Content goes before `anchorNode`, or at the end when it is null or omitted.\n * - Arrays are reconciled in place: nodes that remain are never removed and re-added.\n * - `initial` lists nodes already in the DOM (from hydration or splitText) so nothing is recreated.\n * - During `hydrate()`, a region that adopted server text is compared with its first commit: in\n * development, different text warns `HYDRATION_TEXT_MISMATCH` (on the console and in devtools) and\n * the region shows the value computed by the client.\n *\n * @param parent Node that holds the region.\n * @param value The value or an accessor returning it.\n * @param anchorNode Node the content goes before; null or omitted appends.\n * @param initial Nodes already in place for this region. Undefined adopts the server's nodes while\n * hydrating and starts empty otherwise.\n * @returns The value as accepted (a fragment yields the array of its nodes).\n * @throws TypeError (production message `SHADOW_INSERT_CYCLE`) when an array contains itself, and\n * (`SHADOW_INSERT_DEPTH`) when an accessor returns accessors more than 10,000 levels deep. When the\n * value is reactive, the error is raised inside its render effect and goes to the owner's error\n * handler, like any effect error.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { anchor, insert } from \"@shadow-js/web\";\n *\n * const list = document.createElement(\"ul\");\n * const end = anchor(list, null);\n * const [items] = useSignal([\"a\", \"b\"]);\n * insert(list, () => items().map((name) => document.createTextNode(name)), end);\n * @see anchor\n * @since 1.0.0\n */\nexport function insert(\n parent: Node,\n value: unknown,\n anchorNode?: Node | null,\n initial?: unknown,\n): unknown {\n const resolvedAnchor = anchorNode ?? null;\n const adopted =\n initial === undefined ? claims.current.takeRegion(parent, resolvedAnchor) : initial;\n const region = createRegion(parent, resolvedAnchor, adopted);\n return bindRegion(region, value);\n}\n"],"mappings":"A,sRA0CA,SAASA,EAAW,EAAsB,CACxC,OAAOC,aAAgB,SAAWA,EAAQA,EAAK,eAAiB,QAClE,CAGA,SAASC,EAAS,EAAgB,EAAqB,CACrD,IAAMC,EAAQC,EAAO,MACrB,OAAOD,IAAUF,GAASE,aAAiB,KAAOA,EAAM,IAAIF,CAAY,CAC1E,CAGA,SAASI,EAAQ,EAAgB,EAAkB,CACjD,IAAMF,EAAQC,EAAO,MACjBD,IAAU,KAAM,EAAO,MAAQG,EAC1BH,aAAiB,IAAKA,EAAM,IAAIG,CAAI,EACpCH,IAAUG,IAAM,EAAO,sBAAQ,IAAI,IAAI,CAACH,EAAOG,CAAI,CAAC,EAC/D,CAGA,SAASC,EAAW,EAAgB,EAA6B,CAC/D,IAAMJ,EAAQC,EAAO,MACrB,GAAID,IAAU,KACd,IAAIA,aAAiB,IAAK,CACxB,IAAMK,EAAO,IAAI,IAAUC,CAAI,EAC/B,IAAK,IAAMH,KAAQH,EACZK,EAAK,IAAIF,CAAI,GAAGH,EAAM,OAAOG,CAAI,CAE1C,MAAYG,EAAK,SAASN,CAAK,IAAG,EAAO,MAAQ,KAAA,CACnD,CAMA,SAASO,EAAQ,EAAe,EAAwC,GAAOC,EAAG,EAAW,CAC3F,IAAMC,EAAgB,CAAC,EACjBC,EAAsB,CAAC,CAACC,CAAI,CAAC,EAC7BC,EAAoB,CAAC,CAAC,EACtBC,kBAAS,IAAI,IACnB,KAAOH,EAAO,OAAS,GAAG,CACxB,IAAMI,EAAMJ,EAAO,OAAS,EACtBK,EAAQL,EAAOI,GACfE,EAASJ,EAAQE,IAAQ,EAC/B,GAAIC,IAAU,IAAA,IAAaC,GAAUD,EAAM,OAAQ,CACjD,IAAME,EAAOP,EAAO,IAAI,EACpBO,I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end";let e=null;function t(t,n){e={registry:t,recoverable:n,pending:/* @__PURE__ */ new WeakMap,lifted:[]}}function n(){e=null}function r(){return e!==null}function i(e,t){if(e.nodeType!==8)return!1;let n=e.data;return n===t||t===`[`&&n.startsWith(`[b:`)}function a(e,t,n){let r=[e];for(;r.length>0;){let e=r.pop();if(e===void 0)break;let a=e.firstChild;for(;a!==null;){let o=a.nextSibling;if(i(a,`[`)){let r=[],o=1,s=a.nextSibling;for(;s!==null;){if(i(s,`[`))o+=1;else if(i(s,`]`)&&(--o,o===0))break;r.push(s),s=s.nextSibling}let c=s===null?null:s.nextSibling;n.push(r);for(let t of r)e.removeChild(t);e.removeChild(a),s!==null&&e.removeChild(s);let l=t.get(e);l===void 0?t.set(e,[r]):l.push(r),a=c}else a.nodeType===1&&r.push(a),a=o}}e.normalize()}function o(t){let n=e;if(n===null||t===void 0)return null;let r=n.registry.get(t);return r===void 0?(n.recoverable?.(/* @__PURE__ */ Error(`SHADOW_HYDRATION_KEY_MISS`)),null):(n.registry.delete(t),r.removeAttribute(`data-hk`),a(r,n.pending,n.lifted),r)}function s(t,n){let r=e;if(r===null)return;let i=r.pending.get(t)?.shift();if(i!==void 0){for(let e of i)t.insertBefore(e,n);return i}}function c(){return e?.lifted}function l(t){let n=e;e=null;try{return t()}finally{e=n}}const u=`portal:`,d=`/portal:`;function f(t){let n=e;if(n===null||t===void 0||typeof document>`u`)return;let r=document.body;if(r===null)return;let i=Array.from(r.childNodes),a=i.findIndex(e=>m(e,u+t));if(a===-1)return;let o=i.findIndex((e,n)=>n>a&&m(e,d+t));if(o===-1)return;let s=[];for(let e of i.slice(a+1,o))e.nodeType===8&&h(e)?r.removeChild(e):s.push(e);for(let e of[i[a],i[o]])e!==void 0&&r.removeChild(e);for(let e of s){if(e.nodeType!==1)continue;let t=e,r=t.getAttribute(`data-hk`);r!==null&&n.registry.set(r,t);for(let e of Array.from(t.querySelectorAll(`[data-hk]`))){let t=e.getAttribute(`data-hk`);t!==null&&n.registry.set(t,e)}}return s}function p(e){let t=Array.from(e.childNodes);for(let n=0;n<t.length;n+=1){let r=t[n];if(r===void 0||r.nodeType!==8)continue;let i=r.data;if(!i.startsWith(u))continue;let a=t.findIndex((e,t)=>t>n&&m(e,d+i.slice(7))),o=a===-1?n:a;for(let r of t.slice(n,o+1))r.parentNode===e&&e.removeChild(r);n=o}}function m(e,t){return e.nodeType===8&&e.data===t}function h(e){return e.data===`[`||e.data===`]`}export{t as beginClaiming,o as claimElement,f as claimPortal,n as endClaiming,r as isClaiming,c as liftedRegions,p as releaseUnclaimedPortals,s as takeRegion,l as withoutClaiming};
|
|
2
|
+
//# sourceMappingURL=claim.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claim.js","names":["state","beginClaiming","endClaiming","isClaiming","isMarker","node","text","data","prepare","stack","root","parent","child","following","content","depth","cursor","after","lifted","queue","pending","claimElement","current","key","element","takeRegion","anchorNode","liftedRegions","withoutClaiming","saved","fn","PORTAL_OPEN","PORTAL_CLOSE","claimPortal","body","nodes","open","isComment","close","index","isRegionMarker","own","keyed","hk","releaseUnclaimedPortals","opening","last","comment"],"sources":["../../../src/internal/claim.ts"],"sourcesContent":["import { DEVTOOLS_EVENT, devtoolsReport } from \"@shadow-js/core/extend\";\n\n/** What a hydration pass in progress knows. Exists only while `hydrate()` runs its synchronous pass. */\ninterface HydrationState {\n /** Server elements by `data-hk` key; entries are consumed when claimed. */\n readonly registry: Map<string, Element>;\n /** Told about each mismatch the pass repaired (the `onRecoverableError` option). */\n readonly recoverable: ((error: unknown) => void) | undefined;\n /** Region contents taken out of each claimed parent, in document order. */\n readonly pending: WeakMap<Node, Node[][]>;\n /** The content of every region lifted out of a claimed element, in document order (read by `NoHydration`). */\n readonly lifted: Node[][];\n}\n\nlet state: HydrationState | null = null;\n\n/** Starts a claiming pass over the given server elements. @internal */\nexport function beginClaiming(\n registry: Map<string, Element>,\n recoverable?: (error: unknown) => void,\n): void {\n state = { registry, recoverable, pending: new WeakMap(), lifted: [] };\n}\n\n/** Ends the claiming pass. @internal */\nexport function endClaiming(): void {\n state = null;\n}\n\n/**\n * Reports whether a `hydrate()` pass is claiming server DOM right now: a custom renderer reads it to\n * decide between adopting server nodes and building fresh ones. The pass is synchronous, so this is\n * `false` again once `hydrate()` returns, and in every later update.\n *\n * @returns `true` during the synchronous pass of `hydrate()` (outside {@link withoutClaiming}),\n * `false` otherwise.\n * @example\n * import { isClaiming } from \"@shadow-js/web/extend\";\n *\n * function describe(): string {\n * return isClaiming() ? \"adopting server markup\" : \"building fresh DOM\";\n * }\n * @see claims\n * @since 1.0.0\n */\nexport function isClaiming(): boolean {\n return state !== null;\n}\n\nfunction isMarker(node: Node, data: string): boolean {\n if (node.nodeType !== 8) return false;\n const text = (node as Comment).data;\n // `[b:ID` opens a Suspense boundary region (streaming); it hydrates like a plain region.\n return text === data || (data === \"[\" && text.startsWith(\"[b:\"));\n}\n\n/**\n * Turns server markup for one template into the shape a freshly cloned template has: region\n * contents are lifted out (to be re-inserted by `insert`), marker comments are removed and text\n * nodes are merged again. Iterative; static elements below the root are walked, regions are not\n * (their contents belong to other templates, claimed later through the registry).\n */\nfunction prepare(root: Element, pending: WeakMap<Node, Node[][]>, lifted: Node[][]): void {\n const stack: Element[] = [root];\n while (stack.length > 0) {\n const parent = stack.pop();\n if (parent === undefined) break;\n let child: ChildNode | null = parent.firstChild;\n while (child !== null) {\n const following: ChildNode | null = child.nextSibling;\n if (isMarker(child, \"[\")) {\n const content: Node[] = [];\n let depth = 1;\n let cursor: ChildNode | null = child.nextSibling;\n while (cursor !== null) {\n if (isMarker(cursor, \"[\")) depth += 1;\n else if (isMarker(cursor, \"]\")) {\n depth -= 1;\n if (depth === 0) break;\n }\n content.push(cursor);\n cursor = cursor.nextSibling;\n }\n const after: ChildNode | null = cursor === null ? null : cursor.nextSibling;\n lifted.push(content);\n for (const node of content) parent.removeChild(node);\n parent.removeChild(child);\n if (cursor !== null) parent.removeChild(cursor);\n const queue = pending.get(parent);\n if (queue === undefined) pending.set(parent, [content]);\n else queue.push(content);\n child = after;\n continue;\n }\n if (child.nodeType === 1) stack.push(child as Element);\n child = following;\n }\n }\n root.normalize();\n}\n\n/**\n * Adopts the server's element for a hydration key while `hydrate()` runs: the step that lets a custom\n * template reuse server markup instead of creating new nodes. The element loses its `data-hk`\n * attribute, and the content of its regions is lifted out, to be adopted by {@link takeRegion} when\n * the regions bind. Prefer `claims.current.claimElement`, which links this code only into apps that\n * call `hydrate()`.\n *\n * @param key The key from `nextKey()`, drawn where the server drew it. Undefined claims nothing.\n * @returns The server element; `null` when no hydration pass is running, when `key` is undefined, or\n * when the server sent no element for the key (the caller then creates the node itself). A missing\n * key is a recoverable mismatch: development builds warn `HYDRATION_KEY_MISS`, and the pass's\n * `onRecoverableError` receives an `Error`.\n * @example\n * import { claimElement, nextKey } from \"@shadow-js/web/extend\";\n *\n * function createPanel(): Element {\n * // During hydrate(): the server's <section>. Otherwise: a new one.\n * return claimElement(nextKey()) ?? document.createElement(\"section\");\n * }\n * @see claims\n * @since 1.0.0\n */\nexport function claimElement(key: string | undefined): Element | null {\n const current = state;\n if (current === null || key === undefined) return null;\n const element = current.registry.get(key);\n if (element === undefined) {\n // Production keeps only the code (the same split as core's messages): the text stays out of the bundle.\n if (__DEV__) {\n const message = `No server element for key \"${key}\".`;\n console.warn(`[shadow HYDRATION_KEY_MISS] ${message}`);\n devtoolsReport(DEVTOOLS_EVENT.HYDRATION_MISMATCH, message, key, undefined);\n }\n current.recoverable?.(\n new Error(__DEV__ ? `No server element for key \"${key}\".` : \"SHADOW_HYDRATION_KEY_MISS\"),\n );\n return null;\n }\n current.registry.delete(key);\n element.removeAttribute(\"data-hk\");\n prepare(element, current.pending, current.lifted);\n return element;\n}\n\n/** Characters that stay readable as escapes in a diagnostic snippet: markup, quotes and ampersands. */\nconst SNIPPET_ESCAPES: ReadonlyMap<string, string> = new Map([\n [\"<\", \"\\\\u003c\"],\n [\">\", \"\\\\u003e\"],\n [\"&\", \"\\\\u0026\"],\n ['\"', \"\\\\u0022\"],\n [\"'\", \"\\\\u0027\"],\n]);\n\n/**\n * Escapes text for a diagnostic snippet and cuts it to `limit` output characters, with `...` when cut.\n * Escapes are never split, so the output is at most `limit + 3` characters.\n * @internal\n */\nfunction snippet(text: string, limit: number): string {\n let out = \"\";\n for (const char of text) {\n const code = char.codePointAt(0) ?? 0;\n const controlled = code < 0x20 || (code >= 0x7f && code <= 0x9f);\n const escaped =\n SNIPPET_ESCAPES.get(char) ?? (controlled ? `\\\\u${code.toString(16).padStart(4, \"0\")}` : char);\n if (out.length + escaped.length > limit) return `${out}...`;\n out += escaped;\n }\n return out;\n}\n\n/** The opening tag of a server element as the server wrote it (attribute values as they are). */\nfunction openingMarkup(element: Element): string {\n let markup = `<${element.localName}`;\n for (const attr of Array.from(element.attributes)) markup += ` ${attr.name}=\"${attr.value}\"`;\n return `${markup}>`;\n}\n\n/**\n * Development check of a claimed element against the tag its template or `element()` call expects.\n * A different tag warns `HYDRATION_MISMATCH` on the console and in devtools, with an escaped snippet of\n * the server element (its opening tag and the start of its text, bounded). Recovery is unchanged: the\n * element is still adopted, nothing is thrown or replaced, and the caller gets the same value.\n *\n * Call it under `if (__DEV__)`. Text is not compared here: the expected text is inserted later, by\n * `insert`, and {@link checkClaimedText} compares it with the server text at that point.\n *\n * @param element The server element `claimElement` returned.\n * @param expectedTag The tag the client expects (any case).\n * @internal\n */\nexport function checkClaimedTag(element: Element, expectedTag: string): void {\n if (!__DEV__) return;\n const expected = expectedTag.toLowerCase();\n const actual = element.localName.toLowerCase();\n if (actual === expected) return;\n const text = element.textContent ?? \"\";\n let detail = `expected <${expected}> but the server sent <${snippet(actual, 80)}>; server markup: \"${snippet(openingMarkup(element), 80)}\"`;\n if (text !== \"\") detail += `; text: \"${snippet(text, 40)}\"`;\n console.warn(`[shadow HYDRATION_MISMATCH] ${detail}`);\n devtoolsReport(DEVTOOLS_EVENT.HYDRATION_MISMATCH, detail, undefined, undefined);\n}\n\n/**\n * Development check of the first commit of a region that claimed server text. The server text is the\n * DOM text of the claimed nodes (already decoded, so an escaped `<` compares as `<`); the expected\n * text is the strings of the first commit, joined (a number is already its string, `null` and booleans\n * render nothing, so they expect `\"\"`). Equal text is silent. Different text warns\n * `HYDRATION_TEXT_MISMATCH` on the console and in devtools, with both texts escaped and bounded to 40\n * characters. Recovery is unchanged: the region shows the value the client computed.\n *\n * Not compared, so silent: a region that claimed no nodes (an empty server region has no server text),\n * a region whose server nodes are not all text (an element, or the markers of a nested region), and a\n * commit that holds a node (an element is shown in place of the server's content, as before).\n *\n * Call it under `if (__DEV__)`, once per claimed region, at its first commit.\n *\n * @param claimed The server nodes the region adopted, in document order.\n * @param parts What the first commit shows: strings, or nodes.\n * @internal\n * @since 1.0.0\n */\nexport function checkClaimedText(\n claimed: readonly Node[],\n parts: readonly (Node | string)[],\n): void {\n if (!__DEV__) return;\n if (claimed.length === 0) return;\n let server = \"\";\n for (const node of claimed) {\n if (node.nodeType !== 3) return;\n server += node.textContent ?? \"\";\n }\n let expected = \"\";\n for (const part of parts) {\n if (typeof part !== \"string\") return;\n expected += part;\n }\n if (expected === server) return;\n const detail = `expected text \"${snippet(expected, 40)}\" but the server sent text \"${snippet(server, 40)}\"`;\n console.warn(`[shadow HYDRATION_TEXT_MISMATCH] ${detail}`);\n devtoolsReport(DEVTOOLS_EVENT.HYDRATION_MISMATCH, detail, undefined, undefined);\n}\n\n/**\n * Adopts the server content of the next region of a claimed parent while `hydrate()` runs: the nodes\n * that sat between the region's markers are put back before `anchorNode` and returned, so a custom\n * region can bind to them instead of inserting new nodes. Regions are taken in document order.\n *\n * @param parent An element returned by {@link claimElement} (or one of its descendants).\n * @param anchorNode The node the content goes before; `null` appends it at the end of `parent`.\n * @returns The adopted nodes; undefined when no hydration pass is running or `parent` has no region\n * left to adopt (the caller then inserts fresh nodes).\n * @example\n * import { takeRegion } from \"@shadow-js/web/extend\";\n *\n * function fillRegion(parent: Element): Node[] {\n * const adopted = takeRegion(parent, null);\n * if (adopted !== undefined) return adopted;\n * const text = document.createTextNode(\"fresh\");\n * parent.append(text);\n * return [text];\n * }\n * @see claimElement\n * @since 1.0.0\n */\nexport function takeRegion(parent: Node, anchorNode: Node | null): Node[] | undefined {\n const current = state;\n if (current === null) return undefined;\n const content = current.pending.get(parent)?.shift();\n if (content === undefined) return undefined;\n for (const node of content) parent.insertBefore(node, anchorNode);\n return content;\n}\n\n/**\n * The content of every region the pass lifted out of the server elements it claimed, in document order. `NoHydration` finds\n * its own markers in them. Undefined outside a hydration pass.\n * @internal\n */\nexport function liftedRegions(): readonly (readonly Node[])[] | undefined {\n return state?.lifted;\n}\n\n/**\n * Runs `fn` with claiming switched off, so the templates it builds are created fresh instead of\n * claimed from the server markup. Use it for content the server did not render (a portal the server\n * sent nothing for), so its keys are not reported as missing. The previous state is restored when\n * `fn` returns or throws.\n *\n * @param fn The code to run. It runs synchronously, once.\n * @returns What `fn` returns. An error `fn` throws propagates.\n * @example\n * import { template } from \"@shadow-js/web\";\n * import { withoutClaiming } from \"@shadow-js/web/extend\";\n *\n * const makeTip = template(`<div class=\"tip\"></div>`);\n * const tip = withoutClaiming(() => makeTip()); // a fresh clone, even during hydrate()\n * @see claims\n * @since 1.0.0\n */\nexport function withoutClaiming<T>(fn: () => T): T {\n const saved = state;\n state = null;\n try {\n return fn();\n } finally {\n state = saved;\n }\n}\n\n/** Comment that opens the server block of a portal (`<!--portal:KEY-->`). */\nconst PORTAL_OPEN = \"portal:\";\n/** Comment that closes it (`<!--/portal:KEY-->`). */\nconst PORTAL_CLOSE = \"/portal:\";\n\n/**\n * Adopts the server block of a portal while `hydrate()` runs. The server writes each portal's markup\n * at the end of `<body>` between `<!--portal:KEY-->` and `<!--/portal:KEY-->` comments (see\n * `createServerPortals`); this removes the comments, leaves the content in place, and registers its\n * keyed elements so the portal's templates claim them.\n *\n * @param key The portal's key from `nextKey()`. Undefined claims nothing.\n * @returns The nodes of the block, in place in the body; undefined when no hydration pass is running,\n * `key` is undefined, there is no document body, or the server sent no complete block for the key.\n * @example\n * import { claimPortal, nextKey } from \"@shadow-js/web/extend\";\n *\n * function mountOverlay(build: () => Node): Node[] {\n * const adopted = claimPortal(nextKey());\n * if (adopted !== undefined) return adopted;\n * const node = build();\n * document.body.append(node);\n * return [node];\n * }\n * @since 1.0.0\n */\nexport function claimPortal(key: string | undefined): Node[] | undefined {\n const current = state;\n if (current === null || key === undefined || typeof document === \"undefined\") return undefined;\n const body = document.body;\n if (body === null) return undefined;\n const nodes = Array.from(body.childNodes);\n const open = nodes.findIndex((node) => isComment(node, PORTAL_OPEN + key));\n if (open === -1) return undefined;\n const close = nodes.findIndex(\n (node, index) => index > open && isComment(node, PORTAL_CLOSE + key),\n );\n if (close === -1) return undefined;\n // The content stays where the server put it (the region adopts it in place); only the markers go.\n const content: Node[] = [];\n for (const node of nodes.slice(open + 1, close)) {\n if (node.nodeType === 8 && isRegionMarker(node as Comment)) body.removeChild(node);\n else content.push(node);\n }\n for (const node of [nodes[open], nodes[close]]) {\n if (node !== undefined) body.removeChild(node);\n }\n for (const node of content) {\n if (node.nodeType !== 1) continue;\n const element = node as Element;\n const own = element.getAttribute(\"data-hk\");\n if (own !== null) current.registry.set(own, element);\n for (const keyed of Array.from(element.querySelectorAll(\"[data-hk]\"))) {\n const hk = keyed.getAttribute(\"data-hk\");\n if (hk !== null) current.registry.set(hk, keyed);\n }\n }\n return content;\n}\n\n/**\n * Removes the server blocks of portals that were not claimed during the pass: the client did not render\n * those portals, so their markup must not stay in the page. Each block goes with its comments. A block\n * without its closing comment loses only its opening one.\n * @internal\n */\nexport function releaseUnclaimedPortals(body: Node): void {\n const nodes = Array.from(body.childNodes);\n for (let open = 0; open < nodes.length; open += 1) {\n const opening = nodes[open];\n if (opening === undefined || opening.nodeType !== 8) continue;\n const data = (opening as Comment).data;\n if (!data.startsWith(PORTAL_OPEN)) continue;\n const close = nodes.findIndex(\n (node, index) =>\n index > open && isComment(node, PORTAL_CLOSE + data.slice(PORTAL_OPEN.length)),\n );\n const last = close === -1 ? open : close;\n for (const node of nodes.slice(open, last + 1)) {\n if (node.parentNode === body) body.removeChild(node);\n }\n open = last;\n }\n}\n\nfunction isComment(node: Node, data: string): boolean {\n return node.nodeType === 8 && (node as Comment).data === data;\n}\n\nfunction isRegionMarker(comment: Comment): boolean {\n return comment.data === \"[\" || comment.data === \"]\";\n}\n"],"mappings":"A,+BAcA,IAAIA,EAA+B,KAGnC,SAAgBC,EACd,EACA,EACM,CACN,EAAQ,CAAE,WAAU,cAAa,wBAAS,IAAI,QAAW,OAAQ,CAAC,CAAE,CACtE,CAGA,SAAgBC,GAAoB,CAClC,EAAQ,IACV,CAkBA,SAAgBC,GAAsB,CACpC,OAAOH,IAAU,IACnB,CAEA,SAASI,EAAS,EAAY,EAAuB,CACnD,GAAIC,EAAK,WAAa,EAAG,MAAO,GAChC,IAAMC,EAAQD,EAAiB,KAE/B,OAAOC,IAASC,GAASA,IAAS,KAAOD,EAAK,WAAW,KAAK,CAChE,CAQA,SAASE,EAAQ,EAAe,EAAkC,EAAwB,CACxF,IAAMC,EAAmB,CAACC,CAAI,EAC9B,KAAOD,EAAM,OAAS,GAAG,CACvB,IAAME,EAASF,EAAM,IAAI,EACzB,GAAIE,IAAW,IAAA,GAAW,MAC1B,IAAIC,EAA0BD,EAAO,WACrC,KAAOC,IAAU,MAAM,CACrB,IAAMC,EAA8BD,EAAM,YAC1C,GAAIR,EAASQ,EAAO,GAAG,EAAG,CACxB,IAAME,EAAkB,CAAC,EACrBC,EAAQ,EACRC,EAA2BJ,EAAM,YACrC,KAAOI,IAAW,MAAM,CACtB,GAAIZ,EAASY,EAAQ,GAAG,EAAG,GAAS,OAC/B,GAAIZ,EAASY,EAAQ,GAAG,IAC3B,IACID,IAAU,GAAG,MAEnBD,EAAQ,KAAKE,CAAM,EACnB,EAASA,EAAO,WAClB,CACA,IAAMC,EAA0BD,IAAW,KAAO,KAAOA,EAAO,YAChEE,EAAO,KAAKJ,CAAO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EAAMC,GACtB,GAAIS,IAAY,IAAA,IAAaA,EAAQ,WAAa,EAAG,SACrD,IAAMtC,EAAQsC,EAAoB,KAClC,GAAI,CAACtC,EAAK,WAAWwB,CAAW,EAAG,SACnC,IAAMO,EAAQH,EAAM,WACjB,EAAM,IACLI,EAAQH,GAAQC,EAAUhC,EAAM2B,EAAezB,EAAK,MAAM,CAAkB,CAAC,CACjF,EACMuC,EAAOR,IAAU,GAAKF,EAAOE,EACnC,IAAK,IAAMjC,KAAQ8B,EAAM,MAAMC,EAAMU,EAAO,CAAC,EACvCzC,EAAK,aAAe6B,GAAMA,EAAK,YAAY7B,CAAI,EAErD,EAAOyC,CACT,CACF,CAEA,SAAST,EAAU,EAAY,EAAuB,CACpD,OAAOhC,EAAK,WAAa,GAAMA,EAAiB,OAASE,CAC3D,CAEA,SAASiC,EAAe,EAA2B,CACjD,OAAOO,EAAQ,OAAS,KAAOA,EAAQ,OAAS,GAClD,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=new Set(`animation-iteration-count aspect-ratio border-image-outset border-image-slice border-image-width box-flex box-flex-group box-ordinal-group column-count columns flex flex-grow flex-positive flex-shrink flex-negative flex-order grid-area grid-row grid-row-end grid-row-span grid-row-start grid-column grid-column-end grid-column-span grid-column-start font-weight line-clamp line-height opacity order orphans scale tab-size widows z-index zoom fill-opacity flood-opacity stop-opacity stroke-dasharray stroke-dashoffset stroke-miterlimit stroke-opacity stroke-width`.split(` `));function t(t,n){if(typeof n!=`number`||n===0||t.startsWith(`--`))return String(n);let r=t.replace(/^-(?:webkit|moz|ms|o)-/,``);return e.has(r)?String(n):`${n}px`}export{t as cssValueText};
|
|
2
|
+
//# sourceMappingURL=css-units.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-units.js","names":["UNITLESS","cssValueText","value","property","bare"],"sources":["../../../src/internal/css-units.ts"],"sourcesContent":["/**\n * React's unitless style properties. A number given to any other property is in pixels (`0` stays\n * `0`); these properties take the bare number. Vendor prefixes do not change the answer.\n *\n * The compiler never needs this table for static values, and `class-style.ts` and the server\n * stylesheet writer are the only importers, so it is linked only where a style is written.\n * @internal\n */\nconst UNITLESS: ReadonlySet<string> = new Set(\n (\n \"animation-iteration-count aspect-ratio border-image-outset border-image-slice \" +\n \"border-image-width box-flex box-flex-group box-ordinal-group column-count columns flex \" +\n \"flex-grow flex-positive flex-shrink flex-negative flex-order grid-area grid-row grid-row-end \" +\n \"grid-row-span grid-row-start grid-column grid-column-end grid-column-span grid-column-start \" +\n \"font-weight line-clamp line-height opacity order orphans scale tab-size widows z-index zoom \" +\n \"fill-opacity flood-opacity stop-opacity stroke-dasharray stroke-dashoffset stroke-miterlimit \" +\n \"stroke-opacity stroke-width\"\n ).split(\" \"),\n);\n\n/**\n * The CSS text of one style value. A finite or non-finite number gets `px` unless it is zero, a\n * custom property (`--x`) or unitless; every other value is `String(value)`.\n * @param property The CSS property in kebab-case (`toCssProperty` output).\n * @param value The style value.\n * @internal\n */\nexport function cssValueText(property: string, value: unknown): string {\n if (typeof value !== \"number\" || value === 0 || property.startsWith(\"--\")) return String(value);\n const bare = property.replace(/^-(?:webkit|moz|ms|o)-/, \"\");\n return UNITLESS.has(bare) ? String(value) : `${value}px`;\n}\n"],"mappings":"AAQA,MAAMA,EAAgC,IAAI,IAEtC,qjBAOA,MAAM,GAAG,CACb,EASA,SAAgBC,EAAa,EAAkB,EAAwB,CACrE,GAAI,OAAOC,GAAU,UAAYA,IAAU,GAAKC,EAAS,WAAW,IAAI,EAAG,OAAO,OAAOD,CAAK,EAC9F,IAAME,EAAOD,EAAS,QAAQ,yBAA0B,EAAE,EAC1D,OAAOH,EAAS,IAAII,CAAI,EAAI,OAAOF,CAAK,EAAI,GAAGA,EAAM,GACvD,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","names":["warnOnce","invalidAttributeName","name"],"sources":["../../../src/internal/diagnostics.ts"],"sourcesContent":["/**\n * The diagnostic codes of the DOM runtime: `UNSAFE_URL_BLOCKED` (a URL attribute that would run\n * script was not written), `INVALID_ATTRIBUTE_NAME` (a name that cannot appear in markup) and\n * `DUPLICATE_CLASS_ATTRIBUTE` (one element carries `class` and `className`, so the parser drops one).\n * @since 1.0.0\n */\nexport type WebWarningCode =\n | \"UNSAFE_URL_BLOCKED\"\n | \"INVALID_ATTRIBUTE_NAME\"\n | \"DUPLICATE_CLASS_ATTRIBUTE\";\n\nconst seen = new Set<WebWarningCode>();\n\n/**\n * Prints a development warning as `[shadow CODE] detail`, at most once per code for the life of the\n * page or process (the same pattern as core's `warn`): for a custom renderer that refuses a value the\n * way the built-in ones do. Production builds print nothing.\n *\n * @param code The diagnostic code. A code that was already reported is ignored, whatever the detail.\n * @param detail The text after the code.\n * @example\n * import { isUnsafeUrlAttribute, warnOnce } from \"@shadow-js/web/extend\";\n *\n * function setLink(el: Element, url: string): void {\n * if (isUnsafeUrlAttribute(\"href\", url)) {\n * warnOnce(\"UNSAFE_URL_BLOCKED\", `Blocked a script URL: ${url}`);\n * return;\n * }\n * el.setAttribute(\"href\", url);\n * }\n * @since 1.0.0\n */\nexport function warnOnce(code: WebWarningCode, detail: string): void {\n if (!__DEV__) return;\n if (seen.has(code)) return;\n seen.add(code);\n console.warn(`[shadow ${code}] ${detail}`);\n}\n\n/** Forgets which codes were already reported. Used by tests; not part of the public surface. @internal */\nexport function resetWebWarningDedupe(): void {\n seen.clear();\n}\n\n/**\n * Error thrown for attribute names that cannot appear in markup. Dev builds carry the full text;\n * production keeps the code and the name (the same split as core's messages).\n * @internal\n */\nexport function invalidAttributeName(name: string): TypeError {\n if (!__DEV__) return new TypeError(`SHADOW_INVALID_ATTRIBUTE_NAME: \"${name}\"`);\n return new TypeError(`[shadow INVALID_ATTRIBUTE_NAME] \"${name}\" is not a valid attribute name.`);\n}\n"],"mappings":"AAgCA,SAAgBA,EAAS,EAAsB,EAAsB,CAKrE,CAYA,SAAgBC,EAAqB,EAAyB,CAC9C,MAAO,gBAAI,UAAU,mCAAmCC,EAAK,EAAE,CAE/E,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=[`click`,`input`],t=`__SHADOWJS_EARLY__`,n=/^[a-z]+$/;function r(e){return`(function(){var d=document,n=`+JSON.stringify(e.filter(e=>n.test(e)))+`,q=[];function c(e){q.push(e)}for(var i=0;i<n.length;i++)d.addEventListener(n[i],c,true);window.${t}={queue:q,names:n,listener:c};})();`}function i(){let e=Reflect.get(globalThis,t);if(typeof e!=`object`||!e)return;let n=Reflect.get(e,`queue`),r=Reflect.get(e,`names`),i=Reflect.get(e,`listener`);if(Array.isArray(n)&&Array.isArray(r)&&typeof i==`function`)return{queue:n.filter(e=>e instanceof Event),names:r.filter(e=>typeof e==`string`),listener:i}}function a(e){let t={bubbles:!0,cancelable:e.cancelable,composed:!0};return e instanceof MouseEvent?new MouseEvent(e.type,{...t,clientX:e.clientX,clientY:e.clientY,button:e.button,buttons:e.buttons,altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey}):new Event(e.type,t)}function o(){let e=i();if(e!==void 0){Reflect.deleteProperty(globalThis,t);for(let t of e.names)document.removeEventListener(t,e.listener,!0);for(let t of e.queue){let e=t.target;e instanceof Node&&e.dispatchEvent(a(t))}}}export{e as DEFAULT_EARLY_EVENTS,t as EARLY_CAPTURE_KEY,r as captureScriptBody,o as replayEarlyEvents};
|
|
2
|
+
//# sourceMappingURL=early-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"early-events.js","names":["DEFAULT_EARLY_EVENTS","EARLY_CAPTURE_KEY","EVENT_NAME","captureScriptBody","names","name","readCapture","value","queue","listener","item","reissue","init","event","replayEarlyEvents","capture","target"],"sources":["../../../src/internal/early-events.ts"],"sourcesContent":["/**\n * Early event capture (ADR-016): a tiny inline script, placed before the bundle, records the events a\n * user makes before the application has hydrated. `hydrate()` then replays them once its handlers are\n * attached, so a click made while the page was still loading is not lost. The script is generated by\n * `generateHydrationScript` on the server; the replay is the client half, and it does nothing when the\n * page has no captured events.\n */\n\n/** The event types recorded when a page does not name its own. @internal */\nexport const DEFAULT_EARLY_EVENTS: readonly string[] = [\"click\", \"input\"];\n\n/** The window property the capture script writes. Its shape is checked before use. @internal */\nexport const EARLY_CAPTURE_KEY = \"__SHADOWJS_EARLY__\";\n\n/** Event names are plain lower-case words: anything else would end up inside the script text. */\nconst EVENT_NAME = /^[a-z]+$/;\n\n/**\n * The inline script body. A capture listener on the document (capture phase, so it sees events even\n * when a page stops their propagation) queues each event; the queue and the listener are kept on\n * `window` for the replay.\n * @internal\n */\nexport function captureScriptBody(names: readonly string[]): string {\n const list = JSON.stringify(names.filter((name) => EVENT_NAME.test(name)));\n return (\n \"(function(){var d=document,n=\" +\n list +\n \",q=[];function c(e){q.push(e)}\" +\n \"for(var i=0;i<n.length;i++)d.addEventListener(n[i],c,true);\" +\n `window.${EARLY_CAPTURE_KEY}={queue:q,names:n,listener:c};})();`\n );\n}\n\ninterface Capture {\n readonly queue: Event[];\n readonly names: string[];\n readonly listener: (event: Event) => void;\n}\n\n/** The capture the script left on the window, validated, or undefined. */\nfunction readCapture(): Capture | undefined {\n const value: unknown = Reflect.get(globalThis, EARLY_CAPTURE_KEY);\n if (typeof value !== \"object\" || value === null) return undefined;\n const queue: unknown = Reflect.get(value, \"queue\");\n const names: unknown = Reflect.get(value, \"names\");\n const listener: unknown = Reflect.get(value, \"listener\");\n if (!Array.isArray(queue) || !Array.isArray(names) || typeof listener !== \"function\") {\n return undefined;\n }\n const events = queue.filter((item): item is Event => item instanceof Event);\n const kinds = names.filter((name): name is string => typeof name === \"string\");\n return { queue: events, names: kinds, listener: listener as (event: Event) => void };\n}\n\n/** A new event of the same type that bubbles like the original and carries its pointer position. */\nfunction reissue(event: Event): Event {\n const init: EventInit = { bubbles: true, cancelable: event.cancelable, composed: true };\n if (event instanceof MouseEvent) {\n return new MouseEvent(event.type, {\n ...init,\n clientX: event.clientX,\n clientY: event.clientY,\n button: event.button,\n buttons: event.buttons,\n altKey: event.altKey,\n ctrlKey: event.ctrlKey,\n metaKey: event.metaKey,\n shiftKey: event.shiftKey,\n });\n }\n return new Event(event.type, init);\n}\n\n/**\n * Stops the capture and replays what it recorded, in order, on the elements they were made on. Called\n * by `hydrate()` after the handlers are attached. Does nothing when no capture ran.\n * @internal\n */\nexport function replayEarlyEvents(): void {\n const capture = readCapture();\n if (capture === undefined) return;\n Reflect.deleteProperty(globalThis, EARLY_CAPTURE_KEY);\n for (const name of capture.names) document.removeEventListener(name, capture.listener, true);\n for (const event of capture.queue) {\n const target = event.target;\n if (target instanceof Node) target.dispatchEvent(reissue(event));\n }\n}\n"],"mappings":"AASA,MAAaA,EAA0C,CAAC,QAAS,OAAO,EAG3DC,EAAoB,qBAG3BC,EAAa,WAQnB,SAAgBC,EAAkB,EAAkC,CAElE,MACE,gCAFW,KAAK,UAAUC,EAAM,OAAQ,GAASF,EAAW,KAAKG,CAAI,CAAC,CAGnE,EACH,mGAEUJ,EAAkB,oCAEhC,CASA,SAASK,GAAmC,CAC1C,IAAMC,EAAiB,QAAQ,IAAI,WAAYN,CAAiB,EAChE,GAAI,OAAOM,GAAU,WAAYA,EAAgB,OACjD,IAAMC,EAAiB,QAAQ,IAAID,EAAO,OAAO,EAC3CH,EAAiB,QAAQ,IAAIG,EAAO,OAAO,EAC3CE,EAAoB,QAAQ,IAAIF,EAAO,UAAU,EACvD,GAAK,MAAM,QAAQC,CAAK,GAAM,MAAM,QAAQJ,CAAK,GAAK,OAAOK,GAAa,WAK1E,MAAO,CAAE,MAFMD,EAAM,OAAQ,GAAwBE,aAAgB,KAEhD,EAAG,MADVN,EAAM,OAAQ,GAAyB,OAAOC,GAAS,QAClC,EAAa,UAAmC,CACrF,CAGA,SAASM,EAAQ,EAAqB,CACpC,IAAMC,EAAkB,CAAE,QAAS,GAAM,WAAYC,EAAM,WAAY,SAAU,EAAK,EActF,OAbIA,aAAiB,WACZ,IAAI,WAAWA,EAAM,KAAM,CAChC,GAAGD,EACH,QAASC,EAAM,QACf,QAASA,EAAM,QACf,OAAQA,EAAM,OACd,QAASA,EAAM,QACf,OAAQA,EAAM,OACd,QAASA,EAAM,QACf,QAASA,EAAM,QACf,SAAUA,EAAM,QAClB,CAAC,EAEI,IAAI,MAAMA,EAAM,KAAMD,CAAI,CACnC,CAOA,SAAgBE,GAA0B,CACxC,IAAMC,EAAUT,EAAY,EAC5B,GAAIS,IAAY,IAAA,GAChB,SAAQ,eAAe,WAAYd,CAAiB,EACpD,IAAK,IAAMI,KAAQU,EAAQ,MAAO,SAAS,oBAAoBV,EAAMU,EAAQ,SAAU,EAAI,EAC3F,IAAK,IAAMF,KAASE,EAAQ,MAAO,CACjC,IAAMC,EAASH,EAAM,OACjBG,aAAkB,MAAMA,EAAO,cAAcL,EAAQE,CAAK,CAAC,CACjE,CALoD,CAMtD,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration-hooks.js","names":["claims","fn"],"sources":["../../../src/internal/hydration-hooks.ts"],"sourcesContent":["/**\n * The claiming half of hydration, as a hook. `hydrate()` installs the real implementation for the\n * length of its pass; outside a pass the hooks are idle: nothing is claimed, and the renderer builds\n * the same DOM it builds on a fresh page. Templates, regions, `Dynamic`, `Portal` and `NoHydration`\n * call through {@link claims}, so only code that reaches `hydrate()` carries the claiming code (the\n * registry, the server-block lifting and the portal scan). A custom renderer reads the same hook.\n * @since 1.0.0\n */\nexport interface Claims {\n /** Claims the server element for `key` (see `claimElement`). */\n claimElement(key: string | undefined): Element | null;\n /** Adopts the next server region of `parent` (see `takeRegion`). */\n takeRegion(parent: Node, anchorNode: Node | null): Node[] | undefined;\n /** The content of every region lifted out of a claimed element (see `liftedRegions`). */\n liftedRegions(): readonly (readonly Node[])[] | undefined;\n /** Adopts the server block of a portal (see `claimPortal`). */\n claimPortal(key: string | undefined): Node[] | undefined;\n /** True while a hydration pass claims server DOM (see `isClaiming`). */\n isClaiming(): boolean;\n /** Runs `fn` with claiming off (see `withoutClaiming`). */\n withoutClaiming<T>(fn: () => T): T;\n}\n\nconst idle: Claims = {\n claimElement: () => null,\n takeRegion: () => undefined,\n liftedRegions: () => undefined,\n claimPortal: () => undefined,\n isClaiming: () => false,\n withoutClaiming: (fn) => fn(),\n};\n\n/**\n * The claims in effect. Read at each call (never captured), so a region that is updated after its\n * hydration pass ended builds fresh DOM. Only `hydrate()` replaces it, and restores it in `finally`.\n * Outside a hydration pass every method is a no-op.\n *\n * @example\n * import { claims, nextKey } from \"@shadow-js/web/extend\";\n *\n * function createCard(): Element {\n * // Adopts the server's element during hydrate(); builds a new one otherwise.\n * return claims.current.claimElement(nextKey()) ?? document.createElement(\"article\");\n * }\n * @see Claims\n * @since 1.0.0\n */\nexport const claims: { current: Claims } = { current: idle };\n"],"mappings":"AA+CA,MAAaA,EAA8B,CAAE,QAAS,CAvBpD,iBAAoB,KACpB,eAAkB,IAAA,GAClB,kBAAqB,IAAA,GACrB,gBAAmB,IAAA,GACnB,eAAkB,GAClB,gBAAkB,GAAOC,EAAG,CAkBwB,CAAK,E"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
let e=null;function t(e=`0`){return{id:`${e}-`,count:0,resources:0}}function n(){return e}function r(t,n){let r=e;e=t;try{return n()}finally{e=r}}function i(t){let n=e;return n===null?t():r({id:`${n.id}${n.count++}-`,count:0,resources:0},t)}function a(){let t=e;if(t!==null)return`${t.id}${t.count++}`}function o(t){if(t!==void 0)return`k:${t}`;let n=e;return n===null?`r`:`${n.id}r${n.resources++}`}function s(e){return e===void 0?null:{id:`${e}-`,count:0,resources:0}}export{s as childScope,t as createRootScope,n as currentScope,i as enterComponent,a as nextKey,o as resourceKey,r as withScope};
|
|
2
|
+
//# sourceMappingURL=hydration-scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration-scope.js","names":["current","createRootScope","renderId","currentScope","withScope","previous","scope","fn","enterComponent","parent","nextKey","resourceKey","explicit","childScope","key"],"sources":["../../../src/internal/hydration-scope.ts"],"sourcesContent":["/**\n * A hydration scope: the deterministic source of hydration keys shared by the server renderer and\n * the client hydrator. Keys depend only on the nesting and order of component calls, never on owners,\n * effects or memos, so server and client agree as long as they run the same components. Scopes are\n * created by {@link createRootScope}, {@link enterComponent} and {@link childScope}; treat their\n * fields as read-only.\n *\n * @since 1.0.0\n */\nexport interface HydrationScope {\n /** Prefix of every key allocated in this scope, ending with `-` (`\"0-\"` for a root, `\"0-3-\"` below). */\n readonly id: string;\n /** Next number handed out by this scope: component scopes and template root keys share it. */\n count: number;\n /** Number of auto-keyed resources created directly in this scope so far. */\n resources: number;\n}\n\nlet current: HydrationScope | null = null;\n\n/**\n * Creates the scope a render or a hydration starts from: what `renderToString` and `hydrate()` put in\n * effect around the app. A custom renderer that hands out hydration keys does the same.\n *\n * @param renderId The prefix of every key of this render. Default: `\"0\"`, the default `renderId` of\n * the renderers.\n * @returns A fresh scope whose `id` is `` `${renderId}-` ``.\n * @example\n * import { createRootScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * const keys = withScope(createRootScope(\"app\"), () => [nextKey(), nextKey()]);\n * // [\"app-0\", \"app-1\"]\n * @see withScope\n * @since 1.0.0\n */\nexport function createRootScope(renderId = \"0\"): HydrationScope {\n return { id: `${renderId}-`, count: 0, resources: 0 };\n}\n\n/**\n * Returns the hydration scope in effect.\n *\n * @returns The current scope; `null` outside a server render, a hydration, or a {@link withScope}\n * call.\n * @example\n * import { currentScope } from \"@shadow-js/web/extend\";\n *\n * function scopeLabel(): string {\n * return currentScope()?.id ?? \"no scope\";\n * }\n * @since 1.0.0\n */\nexport function currentScope(): HydrationScope | null {\n return current;\n}\n\n/**\n * Runs `fn` with `scope` in effect, so the keys `fn` draws come from it. The previous scope is\n * restored when `fn` returns or throws.\n *\n * @param scope The scope to put in effect; `null` runs `fn` with no scope (no keys are drawn).\n * @param fn The code to run, synchronously, once.\n * @returns What `fn` returns. An error `fn` throws propagates.\n * @example\n * import { childScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * // The keys of an isolated subtree, independent of its siblings.\n * const first = withScope(childScope(\"0-4\"), () => nextKey()); // \"0-4-0\"\n * @see createRootScope\n * @since 1.0.0\n */\nexport function withScope<T>(scope: HydrationScope | null, fn: () => T): T {\n const previous = current;\n current = scope;\n try {\n return fn();\n } finally {\n current = previous;\n }\n}\n\n/**\n * Runs a component call in a scope of its own, so the keys it draws depend only on its position\n * among its parent's calls: what `createComponent` does on the client and on the server. The\n * component's scope takes the next number of the parent scope.\n *\n * @param fn The component call, run synchronously, once.\n * @returns What `fn` returns. Without a scope in effect, `fn` simply runs.\n * @example\n * import { createRootScope, enterComponent, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * withScope(createRootScope(), () => {\n * nextKey(); // \"0-0\"\n * return enterComponent(() => nextKey()); // \"0-1-0\": the component's first key\n * });\n * @since 1.0.0\n */\nexport function enterComponent<T>(fn: () => T): T {\n const parent = current;\n if (parent === null) return fn();\n return withScope({ id: `${parent.id}${parent.count++}-`, count: 0, resources: 0 }, fn);\n}\n\n/**\n * Draws the key of the next template root in the current scope: what `template()` and\n * `ssrHydrationKey()` call, in the same order on the server and the client. Each call advances the\n * scope.\n *\n * @returns The key (`\"0-0\"`, `\"0-1\"`, ...); undefined outside a scope.\n * @example\n * import { claimElement, nextKey } from \"@shadow-js/web/extend\";\n *\n * function createBadge(): Element {\n * return claimElement(nextKey()) ?? document.createElement(\"span\");\n * }\n * @see claimElement\n * @since 1.0.0\n */\nexport function nextKey(): string | undefined {\n const scope = current;\n if (scope === null) return undefined;\n return `${scope.id}${scope.count++}`;\n}\n\n/**\n * Returns the key a resource's value is stored under in the server data, the same on the server and\n * the client: the explicit key when there is one, else one drawn from the current scope.\n *\n * @param explicit The resource's own key. When given, the result is `` `k:${explicit}` ``, a prefix\n * no generated key has. Undefined draws the next resource key of the scope.\n * @returns `` `k:${explicit}` ``; otherwise the scope id, `r` and the creation index (`\"0-1-r0\"`);\n * `\"r\"` outside a scope.\n * @example\n * import { createRootScope, resourceKey, withScope } from \"@shadow-js/web/extend\";\n *\n * withScope(createRootScope(), () => [resourceKey(undefined), resourceKey(\"user\")]);\n * // [\"0-r0\", \"k:user\"]\n * @since 1.0.0\n */\nexport function resourceKey(explicit: string | undefined): string {\n if (explicit !== undefined) return `k:${explicit}`;\n const scope = current;\n if (scope === null) return \"r\";\n return `${scope.id}r${scope.resources++}`;\n}\n\n/**\n * Creates a fresh scope for an isolated part of the tree, such as a Suspense boundary's content or\n * fallback, or a portal's content: its keys depend only on `key`, not on the siblings around it.\n *\n * @param key The key of the boundary (from `nextKey()`); undefined means no scope.\n * @returns A scope whose `id` is `` `${key}-` ``; `null` when `key` is undefined.\n * @example\n * import { childScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * function renderIsolated<T>(build: () => T): T {\n * return withScope(childScope(nextKey()), build);\n * }\n * @see withScope\n * @since 1.0.0\n */\nexport function childScope(key: string | undefined): HydrationScope | null {\n return key === undefined ? null : { id: `${key}-`, count: 0, resources: 0 };\n}\n"],"mappings":"AAkBA,IAAIA,EAAiC,KAiBrC,SAAgBC,EAAgB,EAAW,IAAqB,CAC9D,MAAO,CAAE,GAAI,GAAGC,EAAS,GAAI,MAAO,EAAG,UAAW,CAAE,CACtD,CAeA,SAAgBC,GAAsC,CACpD,OAAOH,CACT,CAiBA,SAAgBI,EAAa,EAA8B,EAAgB,CACzE,IAAMC,EAAWL,EACjB,EAAUM,EACV,GAAI,CACF,OAAOC,EAAG,CACZ,QAAU,CACR,EAAUF,CACZ,CACF,CAkBA,SAAgBG,EAAkB,EAAgB,CAChD,IAAMC,EAAST,EAEf,OADIS,IAAW,KAAaF,EAAG,EACxBH,EAAU,CAAE,GAAI,GAAGK,EAAO,KAAK,EAAO,QAAQ,GAAI,MAAO,EAAG,UAAW,CAAE,EAAGF,CAAE,CACvF,CAiBA,SAAgBG,GAA8B,CAC5C,IAAMJ,EAAQN,EACd,GAAIM,IAAU,KACd,MAAO,GAAGA,EAAM,KAAK,EAAM,SAC7B,CAiBA,SAAgBK,EAAY,EAAsC,CAChE,GAAIC,IAAa,IAAA,GAAW,MAAO,KAAKA,IACxC,IAAMN,EAAQN,EAEd,OADIM,IAAU,KAAa,IACpB,GAAGA,EAAM,GAAG,GAAG,EAAM,aAC9B,CAiBA,SAAgBO,EAAW,EAAgD,CACzE,OAAOC,IAAQ,IAAA,GAAY,KAAO,CAAE,GAAI,GAAGA,EAAI,GAAI,MAAO,EAAG,UAAW,CAAE,CAC5E,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.js","names":["HTML_NS","SVG_NS","MATHML_NS"],"sources":["../../../src/internal/names.ts"],"sourcesContent":["/**\n * The XHTML namespace URI: the `namespaceURI` of ordinary HTML elements.\n *\n * @example\n * import { HTML_NS } from \"@shadow-js/web/extend\";\n *\n * const isHtml = (el: Element): boolean => el.namespaceURI === HTML_NS;\n * @since 1.0.0\n */\nexport const HTML_NS = \"http://www.w3.org/1999/xhtml\";\n/**\n * The SVG namespace URI, for `createElementNS` and `namespaceURI` checks.\n *\n * @example\n * import { SVG_NS } from \"@shadow-js/web/extend\";\n *\n * const circle = document.createElementNS(SVG_NS, \"circle\");\n * @since 1.0.0\n */\nexport const SVG_NS = \"http://www.w3.org/2000/svg\";\n/**\n * The MathML namespace URI, for `createElementNS` and `namespaceURI` checks.\n *\n * @example\n * import { MATHML_NS } from \"@shadow-js/web/extend\";\n *\n * const fraction = document.createElementNS(MATHML_NS, \"mfrac\");\n * @since 1.0.0\n */\nexport const MATHML_NS = \"http://www.w3.org/1998/Math/MathML\";\n\n/** `template()` flag: the markup is SVG. @internal */\nexport const TEMPLATE_SVG = 1;\n/** `template()` flag: the markup is MathML. @internal */\nexport const TEMPLATE_MATHML = 2;\n/** `template()` flag: clone with `document.importNode` (custom elements). @internal */\nexport const TEMPLATE_IMPORT_NODE = 4;\n"],"mappings":"AASA,MAAaA,EAAU,+BAUVC,EAAS,6BAUTC,EAAY,qC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal-context.js","names":["PortalContext"],"sources":["../../../src/internal/portal-context.ts"],"sourcesContent":["import { type Context, createContext } from \"@shadow-js/core\";\n\n/**\n * Receives the markup of the portals a server render produces: what {@link PortalContext} provides\n * when the render was given a `portals` collector.\n * @since 1.0.0\n */\nexport interface PortalSink {\n /**\n * Records the markup of the portal with hydration key `key`. A key recorded again replaces the\n * earlier markup. Throws an `SsrError` whose `code` is `SSR_PORTAL_LIMIT` past 256 portals in one\n * render.\n */\n add(key: string, html: string): void;\n}\n\n/**\n * The context through which a server render hands portals their collector: the renderers provide it\n * when they are given a `portals` option (see `createServerPortals`). A custom portal reads it on the\n * server and records its markup under its hydration key, so the client's `claimPortal` adopts it.\n * Its value is `null` for every other render, and in the browser, where a portal writes nothing on\n * the server.\n *\n * @example\n * import { useContext } from \"@shadow-js/core\";\n * import { nextKey, PortalContext } from \"@shadow-js/web/extend\";\n * import { escape } from \"@shadow-js/web/server\";\n *\n * function ServerToast(props: { text: string }): null {\n * const key = nextKey();\n * const sink = useContext(PortalContext);\n * if (sink !== null && key !== undefined) sink.add(key, `<div role=\"status\">${escape(props.text)}</div>`);\n * return null;\n * }\n * @see claimPortal\n * @since 1.0.0\n */\nexport const PortalContext: Context<PortalSink | null> =\n /* @__PURE__ */ createContext<PortalSink | null>(null, {\n name: \"Portal\",\n });\n"],"mappings":"A,gDAqCA,MAAaA,EACK,kBAAiC,KAAM,CACrD,KAAM,QACR,CAAC,E"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=/^(?:alignment|baseline|clip|color|dominant|enable|fill|flood|font|glyph|image|letter|lighting|marker|mask|mix|paint|pointer|shape|stop|stroke|text|transform|unicode|vector|white|word|writing)(?=[A-Z])/,t=/* @__PURE__ */ new Set([`clipPathUnits`,`glyphRef`,`markerHeight`,`markerUnits`,`markerWidth`,`maskContentUnits`,`maskUnits`,`textLength`]);function n(n,i){if(n===`className`)return`class`;if(n===`htmlFor`)return`for`;if(n===`httpEquiv`)return`http-equiv`;if(n===`acceptCharset`)return`accept-charset`;if(!i)return n.toLowerCase();if(n.includes(`:`))return n;let a=/^xlink([A-Z].*)$/.exec(n);if(a!==null)return`xlink:${r(a[1]??``)}`;let o=/^xml([A-Z].*)$/.exec(n);return o===null?t.has(n)||!e.test(n)?n:n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`):`xml:${r(o[1]??``)}`}function r(e){return e.replace(/^[A-Z]/,e=>e.toLowerCase())}const i=/* @__PURE__ */ new Set([`key`,`suppressHydrationWarning`,`suppressContentEditableWarning`]),a=/* @__PURE__ */ new Set([`checkbox`,`radio`,`file`]);function o(e,t,n){let r=/^on[A-Z]/.test(e),i=r&&e.endsWith(`Capture`),o=e.slice(2,i?-7:void 0);if(!r)return{type:o.toLowerCase(),capture:!1,passive:!1};let s=o.toLowerCase();return s===`change`?{type:t===`textarea`||t===`input`&&(n===null||!a.has(n))?`input`:`change`,capture:i,passive:!1}:s===`focus`?{type:`focusin`,capture:i,passive:!1}:s===`blur`?{type:`focusout`,capture:i,passive:!1}:s===`doubleclick`?{type:`dblclick`,capture:i,passive:!1}:s===`wheel`?{type:`wheel`,capture:i,passive:!i}:{type:s,capture:i,passive:!1}}export{i as IGNORED_KEYS,n as attributeName,o as eventPlan};
|
|
2
|
+
//# sourceMappingURL=react-names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-names.js","names":["SVG_PROPERTY_FAMILY","SVG_CAMEL_ATTRIBUTES","attributeName","name","svg","xlink","lowerFirst","xml","letter","text","IGNORED_KEYS","CHANGE_ON_TYPES","eventPlan","reactSpelling","attribute","capture","base","lower","tag","type"],"sources":["../../../src/internal/react-names.ts"],"sourcesContent":["/**\n * React spellings at run time: the attribute and event names that a props object (a spread) passes\n * through. The compiler resolves the same names at build time (`packages/compiler/src/internal/\n * react-names.ts`); a test keeps the two presentation lists equal, so keep them in step.\n *\n * @internal\n */\n\n/**\n * SVG presentation attributes are CSS properties, and React spells them in camelCase (`strokeWidth` is\n * `stroke-width`). A camelCase name whose first word is one of these families is hyphenated. The\n * families are the first words of the CSS properties SVG takes as attributes, so one rule covers the\n * presentation list. The compiler's table (`packages/compiler/src/internal/react-names.ts`) lists the\n * same names, and a test checks each one.\n */\nconst SVG_PROPERTY_FAMILY =\n /^(?:alignment|baseline|clip|color|dominant|enable|fill|flood|font|glyph|image|letter|lighting|marker|mask|mix|paint|pointer|shape|stop|stroke|text|transform|unicode|vector|white|word|writing)(?=[A-Z])/;\n\n/**\n * SVG attributes that start with a property family but are not CSS properties (`clipPathUnits`,\n * `markerWidth`): they are camelCase in SVG, so they keep their case.\n */\nconst SVG_CAMEL_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"clipPathUnits\",\n \"glyphRef\",\n \"markerHeight\",\n \"markerUnits\",\n \"markerWidth\",\n \"maskContentUnits\",\n \"maskUnits\",\n \"textLength\",\n]);\n\n/**\n * The attribute name for a props key on an element: HTML names are lower case (what the parser and\n * `setAttribute` write anyway, and what server markup needs); SVG presentation names are hyphenated,\n * `xlinkHref` and `xmlLang` take their prefix, and other SVG names keep their case (`viewBox`).\n * @internal\n */\nexport function attributeName(name: string, svg: boolean): string {\n if (name === \"className\") return \"class\";\n if (name === \"htmlFor\") return \"for\";\n if (name === \"httpEquiv\") return \"http-equiv\";\n if (name === \"acceptCharset\") return \"accept-charset\";\n if (!svg) return name.toLowerCase();\n if (name.includes(\":\")) return name;\n const xlink = /^xlink([A-Z].*)$/.exec(name);\n if (xlink !== null) return `xlink:${lowerFirst(xlink[1] ?? \"\")}`;\n const xml = /^xml([A-Z].*)$/.exec(name);\n if (xml !== null) return `xml:${lowerFirst(xml[1] ?? \"\")}`;\n if (SVG_CAMEL_ATTRIBUTES.has(name) || !SVG_PROPERTY_FAMILY.test(name)) return name;\n return name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n}\n\nfunction lowerFirst(text: string): string {\n return text.replace(/^[A-Z]/, (letter) => letter.toLowerCase());\n}\n\n/** Props that have no DOM form: a spread ignores them (React's `key` and hydration flags). @internal */\nexport const IGNORED_KEYS: ReadonlySet<string> = new Set([\n \"key\",\n \"suppressHydrationWarning\",\n \"suppressContentEditableWarning\",\n]);\n\n/** The DOM event for a React-spelled prop (see the compiler's `eventPlan`). @internal */\nexport interface EventPlan {\n readonly type: string;\n readonly capture: boolean;\n readonly passive: boolean;\n}\n\nconst CHANGE_ON_TYPES: ReadonlySet<string> = new Set([\"checkbox\", \"radio\", \"file\"]);\n\n/**\n * Plans the DOM event for an `on*` prop. React's spellings follow React: `onChange` is the per-edit\n * `input` event on text inputs and textareas and the `change` event on other controls; `onFocus` and\n * `onBlur` bubble as `focusin` and `focusout`; a `...Capture` suffix binds the capture phase; `onWheel`\n * is passive. A lower-case `on` spelling is the native event.\n * @internal\n */\nexport function eventPlan(attribute: string, tag: string, type: string | null): EventPlan {\n const reactSpelling = /^on[A-Z]/.test(attribute);\n const capture = reactSpelling && attribute.endsWith(\"Capture\");\n const base = attribute.slice(2, capture ? -\"Capture\".length : undefined);\n if (!reactSpelling) return { type: base.toLowerCase(), capture: false, passive: false };\n const lower = base.toLowerCase();\n if (lower === \"change\") {\n const perEdit =\n tag === \"textarea\" || (tag === \"input\" && (type === null || !CHANGE_ON_TYPES.has(type)));\n return { type: perEdit ? \"input\" : \"change\", capture, passive: false };\n }\n if (lower === \"focus\") return { type: \"focusin\", capture, passive: false };\n if (lower === \"blur\") return { type: \"focusout\", capture, passive: false };\n if (lower === \"doubleclick\") return { type: \"dblclick\", capture, passive: false };\n if (lower === \"wheel\") return { type: \"wheel\", capture, passive: !capture };\n return { type: lower, capture, passive: false };\n}\n"],"mappings":"AAeA,MAAMA,EACJ,2MAMIC,kBAA4C,IAAI,IAAI,CACxD,gBACA,WACA,eACA,cACA,cACA,mBACA,YACA,YACF,CAAC,EAQD,SAAg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AEnEF,IAAU,QAAgB,CAAE,KAAM,UAAW,UAAS,QAAS,EAAM,EACrEA,IAAU,OAAe,CAAE,KAAM,WAAY,UAAS,QAAS,EAAM,EACrEA,IAAU,cAAsB,CAAE,KAAM,WAAY,UAAS,QAAS,EAAM,EAC5EA,IAAU,QAAgB,CAAE,KAAM,QAAS,UAAS,QAAS,CAACF,CAAQ,EACnE,CAAE,KAAME,EAAO,UAAS,QAAS,EAAM,CAChD,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e,t){t!==void 0&&t.parentNode===e&&e.removeChild(t)}function t(e,t,n){let r=[],i=e.map(()=>-1);for(let t=0;t<e.length;t+=1){let n=e[t]??0,a=0,o=r.length;for(;a<o;){let t=a+o>>1;(e[r[t]??0]??0)<n?a=t+1:o=t}i[t]=a>0?r[a-1]??-1:-1,r[a]=t}let a=r.length>0?r[r.length-1]??-1:-1;for(;a!==-1;)n[(e[a]??0)-t]=1,a=i[a]??-1}function n(n,r,i,a){let o=r.length,s=i.length,c=0;for(;c<o&&c<s&&r[c]===i[c];)c+=1;let l=o,u=s;for(;l>c&&u>c&&r[l-1]===i[u-1];)--l,--u;if(l===c&&u===c)return;let d=u<s?i[u]??null:a;if(u===c){for(let t=c;t<l;t+=1)e(n,r[t]);return}let f=/* @__PURE__ */ new Map;for(let e=c;e<u;e+=1){let t=i[e];t!==void 0&&f.set(t,e)}let p=[];for(let t=c;t<l;t+=1){let i=r[t];if(i===void 0)continue;let a=f.get(i);a===void 0?e(n,i):p.push(a)}if(p.length===0){for(let e=c;e<u;e+=1){let t=i[e];t!==void 0&&n.insertBefore(t,d)}return}let m=new Uint8Array(u-c);t(p,c,m);let h=typeof n.moveBefore==`function`,g=d;for(let e=u-1;e>=c;--e){let t=i[e];t!==void 0&&(m[e-c]!==1&&(h&&t.parentNode===n?n.moveBefore(t,g):n.insertBefore(t,g)),g=t)}}export{n as reconcileNodes};
|
|
2
|
+
//# sourceMappingURL=reconcile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile.js","names":["removeNode","node","parent","markLongestIncreasing","tails","previous","values","index","value","low","high","middle","cursor","offset","reconcileNodes","prevLength","prev","nextLength","next","head","prevTail","nextTail","before","end","target","survivors","position","stable","movable","anchorNode"],"sources":["../../../src/internal/reconcile.ts"],"sourcesContent":["/** A parent that can move a child in place (Element.prototype.moveBefore, where implemented). */\ninterface MovableParent extends Node {\n moveBefore(node: Node, child: Node | null): void;\n}\n\n/** Removes `node` only when it is still a child of `parent`, so detached nodes are ignored. */\nfunction removeNode(parent: Node, node: Node | undefined): void {\n if (node !== undefined && node.parentNode === parent) parent.removeChild(node);\n}\n\n/**\n * Marks the members of one longest strictly increasing subsequence of `values` in `marks`, where\n * `values[k]` is the target position of the k-th surviving node and `marks[v - offset]` is set for\n * target position `v`. Patience sorting: O(n log n).\n */\nfunction markLongestIncreasing(values: readonly number[], offset: number, marks: Uint8Array): void {\n // tails[k]: index into `values` of the smallest tail of an increasing run of length k + 1.\n const tails: number[] = [];\n const previous: number[] = values.map(() => -1);\n for (let index = 0; index < values.length; index += 1) {\n const value = values[index] ?? 0;\n let low = 0;\n let high = tails.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n const probe = values[tails[middle] ?? 0] ?? 0;\n if (probe < value) low = middle + 1;\n else high = middle;\n }\n previous[index] = low > 0 ? (tails[low - 1] ?? -1) : -1;\n tails[low] = index;\n }\n let cursor = tails.length > 0 ? (tails[tails.length - 1] ?? -1) : -1;\n while (cursor !== -1) {\n marks[(values[cursor] ?? 0) - offset] = 1;\n cursor = previous[cursor] ?? -1;\n }\n}\n\n/**\n * Updates one region of `parent`'s children from the nodes `prev` to the nodes `next`, keeping every\n * node that stays and moving as few as possible: the list reconciliation `insert` performs for arrays\n * (and so for `For`). Use it in a custom list renderer.\n *\n * Preconditions: `prev` are the nodes this region owns, in DOM order and all children of `parent`;\n * `next` holds no duplicates; `end` is the node after the region (null for the end of `parent`).\n *\n * Strategy, in three steps:\n * 1. Trim the common prefix and suffix: appends, prepends, and removals at either end touch\n * only the nodes that changed (no move at all).\n * 2. Remove the nodes that left the value. A node that is still present is never removed.\n * 3. Place the rest from the end of `next` backwards. Nodes on a longest increasing subsequence of\n * surviving positions stay where they are; every other node is moved (or inserted) directly\n * before the node that follows it in `next`. Moves use `moveBefore` when the parent has it,\n * which keeps focus and iframe state, and `insertBefore` otherwise. Each node moves at most once,\n * and the number of moves is minimal for the surviving order.\n *\n * @param parent The parent of the region.\n * @param prev The nodes the region holds now, in DOM order, all children of `parent`.\n * @param next The nodes the region must hold, in order, without duplicates. A node of `prev` that is\n * not in `next` is removed; a node of `next` that is not in `prev` is inserted.\n * @param end The node right after the region; `null` when the region runs to the end of `parent`.\n * @example\n * import { reconcileNodes } from \"@shadow-js/web/extend\";\n *\n * const item = (text: string): HTMLLIElement =>\n * Object.assign(document.createElement(\"li\"), { textContent: text });\n * const list = document.createElement(\"ul\");\n * const a = item(\"a\");\n * const b = item(\"b\");\n * const c = item(\"c\");\n * list.append(a, b, c);\n * reconcileNodes(list, [a, b, c], [c, a], null); // removes b, moves c before a\n * @since 1.0.0\n */\nexport function reconcileNodes(\n parent: Node,\n prev: readonly Node[],\n next: readonly Node[],\n end: Node | null,\n): void {\n const prevLength = prev.length;\n const nextLength = next.length;\n\n let head = 0;\n while (head < prevLength && head < nextLength && prev[head] === next[head]) head += 1;\n let prevTail = prevLength;\n let nextTail = nextLength;\n while (prevTail > head && nextTail > head && prev[prevTail - 1] === next[nextTail - 1]) {\n prevTail -= 1;\n nextTail -= 1;\n }\n if (prevTail === head && nextTail === head) return;\n\n // Everything in the common suffix is already in place, so the middle goes before its first node.\n const before = nextTail < nextLength ? (next[nextTail] ?? null) : end;\n\n if (nextTail === head) {\n for (let index = head; index < prevTail; index += 1) removeNode(parent, prev[index]);\n return;\n }\n\n const target = new Map<Node, number>();\n for (let index = head; index < nextTail; index += 1) {\n const node = next[index];\n if (node !== undefined) target.set(node, index);\n }\n\n const survivors: number[] = [];\n for (let index = head; index < prevTail; index += 1) {\n const node = prev[index];\n if (node === undefined) continue;\n const position = target.get(node);\n if (position === undefined) removeNode(parent, node);\n else survivors.push(position);\n }\n\n if (survivors.length === 0) {\n for (let index = head; index < nextTail; index += 1) {\n const node = next[index];\n if (node !== undefined) parent.insertBefore(node, before);\n }\n return;\n }\n\n const stable = new Uint8Array(nextTail - head);\n markLongestIncreasing(survivors, head, stable);\n const movable = typeof (parent as Partial<MovableParent>).moveBefore === \"function\";\n\n let anchorNode = before;\n for (let index = nextTail - 1; index >= head; index -= 1) {\n const node = next[index];\n if (node === undefined) continue;\n if (stable[index - head] !== 1) {\n if (movable && node.parentNode === parent)\n (parent as MovableParent).moveBefore(node, anchorNode);\n else parent.insertBefore(node, anchorNode);\n }\n anchorNode = node;\n }\n}\n"],"mappings":"AAMA,SAASA,EAAW,EAAc,EAA8B,CAC1DC,IAAS,IAAA,IAAaA,EAAK,aAAeC,GAAQA,EAAO,YAAYD,CAAI,CAC/E,CAOA,SAASE,EAAsB,EAA2B,EAAgB,EAAyB,CAEjG,IAAMC,EAAkB,CAAC,EACnBC,EAAqBC,EAAO,QAAU,EAAE,EAC9C,IAAK,IAAIC,EAAQ,EAAGA,EAAQD,EAAO,OAAQ,GAAS,EAAG,CACrD,IAAME,EAAQF,EAAOC,IAAU,EAC3BE,EAAM,EACNC,EAAON,EAAM,OACjB,KAAOK,EAAMC,GAAM,CACjB,IAAMC,EAAUF,EAAMC,GAAS,GACjBJ,EAAOF,EAAMO,IAAW,IAAM,GAChCH,EAAO,EAAMG,EAAS,EAC7B,EAAOA,CACd,CACA,EAASJ,GAASE,EAAM,EAAKL,EAAMK,EAAM,IAAM,GAAM,GACrD,EAAMA,GAAOF,CACf,CACA,IAAIK,EAASR,EAAM,OAAS,EAAKA,EAAMA,EAAM,OAAS,IAAM,GAAM,GAClE,KAAOQ,IAAW,IAChB,GAAON,EAAOM,IAAW,GAAKC,GAAU,EACxC,EAASR,EAASO,IAAW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7ChB,EAAsBsB,EAAWN,EAAMQ,CAAM,EAC7C,IAAMC,EAAU,OAAQ1B,EAAkC,YAAe,WAErE2B,EAAaP,EACjB,IAAK,IAAIf,EAAQc,EAAW,EAAGd,GAASY,EAAM,IAAY,CACxD,IAAMlB,EAAOiB,EAAKX,GACdN,IAAS,IAAA,KACT0B,EAAOpB,EAAQY,KAAU,IACvBS,GAAW3B,EAAK,aAAeC,EACjCA,EAA0B,WAAWD,EAAM4B,CAAU,EAClD3B,EAAO,aAAaD,EAAM4B,CAAU,GAE3C,EAAa5B,EACf,CACF,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-context.js","names":["StreamContext"],"sources":["../../../src/internal/stream-context.ts"],"sourcesContent":["import { type Context, createContext } from \"@shadow-js/core\";\n\n/**\n * A Suspense boundary whose content was not ready when the shell rendered: `renderToStream` calls\n * `rebuild` again each time a resource settles, and streams the markup once it is complete.\n * @since 1.0.0\n */\nexport interface StreamBoundary {\n /**\n * The boundary's hydration key. The shell must wrap the fallback in `<!--[b:ID-->` and `<!--]-->`\n * comments so the streamed chunk can replace it.\n */\n readonly id: string;\n /**\n * Renders the content again. Returns its final markup, or `null` when it is still pending, in which\n * case it has deferred itself again with {@link StreamSink.defer}.\n */\n rebuild(): string | null;\n}\n\n/**\n * Receives the boundaries that are still pending during a streaming render: what\n * {@link StreamContext} provides.\n * @since 1.0.0\n */\nexport interface StreamSink {\n /** Queues `boundary` to be rebuilt when the next resource settles. */\n defer(boundary: StreamBoundary): void;\n}\n\n/**\n * The context through which `renderToStream` lets a Suspense-like boundary defer its content: a\n * boundary that is pending in the shell renders its fallback between `<!--[b:ID-->` and `<!--]-->`\n * and defers a {@link StreamBoundary} to the sink. Its value is `null` for every other render (the\n * boundary then keeps its fallback).\n *\n * @example\n * import { useContext } from \"@shadow-js/core\";\n * import { StreamContext } from \"@shadow-js/web/extend\";\n *\n * function canStream(): boolean {\n * // Inside a component rendered by renderToStream.\n * return useContext(StreamContext) !== null;\n * }\n * @since 1.0.0\n */\nexport const StreamContext: Context<StreamSink | null> =\n /* @__PURE__ */ createContext<StreamSink | null>(null, {\n name: \"Stream\",\n });\n"],"mappings":"A,gDA8CA,MAAaA,EACK,kBAAiC,KAAM,CACrD,KAAM,QACR,CAAC,E"}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{getOwner as e,onCleanup as t,untrack as n,useMemo as r,useRenderEffect as i}from"@shadow-js/core";function a(e,t){t===void 0?i(e):i(e,t)}function o(e){return r(e)}function s(e,r,i){let a=n(()=>e(r,i));typeof a==`function`&&t(a)}function c(n,r){if(typeof n==`function`){s(n,r);return}if(typeof n!=`object`||!n||!(`current`in n))return;let i=n;i.current=r,e()!==null&&t(()=>{i.current=null})}export{a as effect,o as memo,c as refTo,s as use};
|
|
2
|
+
//# sourceMappingURL=reactive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactive.js","names":["effect","apply","useRenderEffect","compute","memo","useMemo","fn","use","cleanup","untrack","el","arg","onCleanup","refTo","target","holder","getOwner"],"sources":["../../src/reactive.ts"],"sourcesContent":["import {\n type Cleanup,\n getOwner,\n onCleanup,\n untrack,\n useMemo,\n useRenderEffect,\n} from \"@shadow-js/core\";\n\n/**\n * Runs `fn` as a render effect: synchronously when created, and again when the signals it reads\n * change. It is the effect the compiler emits for DOM bindings; application code usually prefers\n * `useEffect`. A function returned by `fn` is its cleanup, run before the next run and when the\n * owner disposes. It never runs on the server, and in development an effect created outside an\n * owner warns `NO_OWNER_EFFECT`.\n *\n * @param fn Tracked body. Returns an optional cleanup function.\n * @example\n * import { createRoot, useSignal } from \"@shadow-js/core\";\n * import { effect } from \"@shadow-js/web\";\n *\n * const label = document.createElement(\"span\");\n * createRoot(() => {\n * const [name] = useSignal(\"Ada\");\n * effect(() => {\n * label.textContent = name(); // runs now, and again when name changes\n * });\n * });\n * @see memo\n * @since 1.0.0\n */\nexport function effect(fn: () => void | Cleanup): void;\n/**\n * Two-form render effect: `compute` is tracked and `apply` runs untracked with the new and the\n * previous value. A function returned by `apply` is its cleanup. Use it to keep the tracked reads\n * apart from the code that writes the DOM.\n *\n * @param compute Tracked. Its result is passed to `apply`.\n * @param apply Untracked. Receives the value and the previous value (`undefined` on the first run)\n * and returns an optional cleanup function.\n * @example\n * import { createRoot, useSignal } from \"@shadow-js/core\";\n * import { effect } from \"@shadow-js/web\";\n *\n * const title = document.createElement(\"h1\");\n * createRoot(() => {\n * const [text] = useSignal(\"Hello\");\n * effect(text, (value, previous) => {\n * title.textContent = value;\n * console.log(previous); // undefined on the first run\n * });\n * });\n * @see memo\n * @since 1.0.0\n */\nexport function effect<T>(\n compute: () => T,\n apply: (value: T, previous: T | undefined) => void | Cleanup,\n): void;\nexport function effect<T>(\n compute: () => T,\n apply?: (value: T, previous: T | undefined) => void | Cleanup,\n): void {\n if (apply === undefined) useRenderEffect(compute);\n else useRenderEffect(compute, apply);\n}\n\n/**\n * Creates a cached derivation that recomputes only when the signals it reads change. It is core's\n * `useMemo` under the short name the compiler emits.\n *\n * @param fn The computation. Tracked; its result is cached until a dependency changes.\n * @returns An accessor for the current value.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { memo } from \"@shadow-js/web\";\n *\n * function setup() {\n * const [count, setCount] = useSignal(2);\n * const doubled = memo(() => count() * 2);\n * setCount(4);\n * console.log(doubled()); // 8\n * }\n * @see effect\n * @since 1.0.0\n */\nexport function memo<T>(fn: () => T): () => T {\n return useMemo<T>(fn);\n}\n\n/**\n * Applies a directive: calls `fn(el, arg)` untracked, so a directive or a ref never subscribes the\n * surrounding effect to what it reads. A function returned by `fn` is a cleanup, run when the owner\n * disposes.\n *\n * @param fn The directive. Receives the element and the accessor of its argument.\n * @param el The element the directive applies to.\n * @param arg Accessor for the directive's argument. Undefined passes `undefined` through; the\n * directive reads the accessor where it wants to track it.\n * @example\n * import { use } from \"@shadow-js/web\";\n *\n * function tooltip(el: Element, text: () => string) {\n * el.setAttribute(\"title\", text());\n * }\n * const button = document.createElement(\"button\");\n * use(tooltip, button, () => \"Save the draft\");\n * @see refTo\n * @since 1.0.0\n */\nexport function use<T>(\n fn: (el: Element, arg: () => T) => unknown,\n el: Element,\n arg?: () => T,\n): void {\n const cleanup = untrack(() => fn(el, arg as () => T));\n // A ref callback may return a cleanup (React 19): it runs when the owner of the element is disposed.\n if (typeof cleanup === \"function\") onCleanup(cleanup as Cleanup);\n}\n\n/**\n * Fills a ref of any form the compiler accepts. A callback is called with the element (its returned\n * cleanup runs when the owner disposes). A `{ current }` object gets the element as `current`, and\n * `null` once the owner is disposed, as React's `useRef` objects do. Any other value is ignored.\n *\n * @param target The ref value: a callback, a `{ current }` object, or anything else (ignored).\n * @param el The element the ref receives.\n * @example\n * import { refTo } from \"@shadow-js/web\";\n *\n * const box = { current: null as HTMLDivElement | null };\n * const div = document.createElement(\"div\");\n * refTo(box, div);\n * console.log(box.current === div); // true\n * @see use\n * @since 1.0.0\n */\nexport function refTo(target: unknown, el: Element): void {\n if (typeof target === \"function\") {\n use(target as (node: Element, arg: () => unknown) => unknown, el);\n return;\n }\n if (target === null || typeof target !== \"object\" || !(\"current\" in target)) return;\n const holder = target as { current: unknown };\n holder.current = el;\n if (getOwner() !== null) {\n onCleanup(() => {\n holder.current = null;\n });\n }\n}\n"],"mappings":"A,yGA2DA,SAAgBA,EACd,EACA,EACM,CACFC,IAAU,IAAA,GAAWC,EAAgBC,CAAO,EAC3CD,EAAgBC,EAASF,CAAK,CACrC,CAqBA,SAAgBG,EAAQ,EAAsB,CAC5C,OAAOC,EAAWC,CAAE,CACtB,CAsBA,SAAgBC,EACd,EACA,EACA,EACM,CACN,IAAMC,EAAUC,MAAcH,EAAGI,EAAIC,CAAc,CAAC,EAEhD,OAAOH,GAAY,YAAYI,EAAUJ,CAAkB,CACjE,CAmBA,SAAgBK,EAAM,EAAiB,EAAmB,CACxD,GAAI,OAAOC,GAAW,WAAY,CAChCP,EAAIO,EAA0DJ,CAAE,EAChE,MACF,CACA,GAAuB,OAAOI,GAAW,WAArCA,GAAiD,EAAE,YAAaA,GAAS,OAC7E,IAAMC,EAASD,EACf,EAAO,QAAUJ,EACbM,EAAS,IAAM,MACjBJ,MAAgB,CACd,EAAO,QAAU,IACnB,CAAC,CAEL,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{withScope as e}from"./internal/hydration-scope.js";import{claims as t}from"./internal/hydration-hooks.js";import{bindRegion as n,createRegion as r,removeRegion as i}from"./insert.js";import{attachRootErrors as a}from"./control-flow/root-errors.js";import{batch as o,createRoot as s,flushSync as c,untrack as l}from"@shadow-js/core";function u(u,d,f){let p=r(d,null,void 0),m=t.current.withoutClaiming(()=>e(null,()=>o(()=>s(e=>(f!==void 0&&a(f),n(p,l(u)),e)))));c();let h=!1;return()=>{h||(h=!0,m(),i(p))}}export{u as render};
|
|
2
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","names":["render","region","createRegion","container","stop","claims","withScope","batch","createRoot","options","attachRootErrors","bindRegion","untrack","code","dispose","flushSync","disposed","removeRegion"],"sources":["../../src/render.ts"],"sourcesContent":["import { batch, createRoot, flushSync, untrack } from \"@shadow-js/core\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link render}: the error reporters of the root.\n * @since 1.0.0\n */\nexport type RenderOptions = RootErrorOptions;\n\n/**\n * Mounts `code` into `container`. Creates an owner, inserts the output, flushes the effects, and\n * returns a dispose function that stops the owner and removes the nodes this call inserted. A\n * second render into the same container appends after the first.\n *\n * @param code Runs once, untracked, to build the tree (a component call, a node, text or an array).\n * Return an accessor (for example `() => count`) from it to make the root content reactive.\n * @param container Element, Document or DocumentFragment that receives the output.\n * @param options The root's error reporters (`onUncaughtError`, `onCaughtError`). Undefined sets\n * no reporter.\n * @returns A dispose function, safe to call more than once.\n * @example\n * import { createComponent, render } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const dispose = render(\n * () => createComponent(App, {}),\n * document.getElementById(\"root\") as Element,\n * );\n * dispose(); // stops the root and removes the text it inserted\n * @see hydrate\n * @since 1.0.0\n */\nexport function render(\n code: () => unknown,\n container: Element | Document | DocumentFragment,\n options?: RenderOptions,\n): () => void {\n const region = createRegion(container, null, undefined);\n // One batch around the build: effects (and anything a resource's batch would flush mid-build)\n // wait until the whole tree exists, so a Suspense boundary knows what is pending before its\n // content's effects are considered.\n // A fresh root never consumes the enclosing hydration pass's nodes or key sequence.\n const stop = claims.current.withoutClaiming(() =>\n withScope(null, () =>\n batch(() =>\n createRoot((dispose) => {\n // An error nothing else took ends here; with onUncaughtError it is reported instead of thrown.\n if (options !== undefined) attachRootErrors(options);\n // The component tree is built once; only accessors inside the result stay reactive.\n bindRegion(region, untrack(code));\n return dispose;\n }),\n ),\n ),\n );\n flushSync();\n let disposed = false;\n return () => {\n if (disposed) return;\n disposed = true;\n stop();\n removeRegion(region);\n };\n}\n"],"mappings":"A,mVAsCA,SAAgBA,EACd,EACA,EACA,EACY,CACZ,IAAMC,EAASC,EAAaC,EAAW,KAAM,IAAA,EAAS,EAKhDC,EAAOC,EAAO,QAAQ,oBAC1BC,EAAU,SACRC,MACEC,EAAY,IAENC,IAAY,IAAA,IAAWC,EAAiBD,CAAO,EAEnDE,EAAWV,EAAQW,EAAQC,CAAI,CAAC,EACzBC,EACR,CACH,CACF,CACF,EACAC,EAAU,EACV,IAAIC,EAAW,GACf,UAAa,CACPA,IACJ,EAAW,GACXZ,EAAK,EACLa,EAAahB,CAAM,EACrB,CACF,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{useHead as e}from"./head/use-head.js";import{isServer as t}from"@shadow-js/core";function n(e){let t=new URL(e,`https://base.invalid`);if(t.protocol!==`https:`&&t.protocol!==`http:`)throw TypeError(`SHADOW_RESOURCE_HINT_URL`)}function r(e,t){for(let[n,r]of Object.entries(t))if(e.getAttribute(n)!==r)return!1;return!0}function i(e,n,i=()=>void 0){if(t){i();return}if(typeof document>`u`)return;for(let t of document.head.querySelectorAll(e))if(r(t,n))return;let a=document.createElement(e);for(let[e,t]of Object.entries(n))a.setAttribute(e,t);document.head.append(a)}function a(t){return()=>e({tag:`link`,props:t})}function o(e,t){n(e);let r={rel:`preconnect`,href:e,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,r,a(r))}function s(e){n(e);let t={rel:`dns-prefetch`,href:e};i(`link`,t,a(t))}function c(e,t){n(e);let r={rel:`preload`,href:e,as:t.as,...t.type===void 0?{}:{type:t.type},...t.media===void 0?{}:{media:t.media},...t.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,r,a(r))}function l(e,t){n(e);let r={rel:`modulepreload`,href:e,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,r,a(r))}function u(e,t){if(n(e),t.as===`style`){let n={rel:`stylesheet`,href:e,...t.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,n,a(n))}else i(`script`,{src:e,async:``,...t.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}},a({rel:`preload`,href:e,as:`script`}))}function d(e,t){n(e),i(`script`,{src:e,type:`module`,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}},a({rel:`modulepreload`,href:e,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}}))}export{o as preconnect,s as prefetchDNS,u as preinit,d as preinitModule,c as preload,l as preloadModule};
|
|
2
|
+
//# sourceMappingURL=resource-hints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-hints.js","names":["checkUrl","url","href","carries","name","value","attributes","element","hint","isServer","serverTag","existing","tag","serverLink","useHead","preconnect","options","prefetchDNS","preload","preloadModule","preinit","preinitModule"],"sources":["../../src/resource-hints.ts"],"sourcesContent":["import { isServer } from \"@shadow-js/core\";\nimport { useHead } from \"./head/use-head\";\nimport type { HeadAttributeValue } from \"./head/validate\";\n\n/**\n * Options of {@link preconnect}, {@link preloadModule} and {@link preinitModule}.\n * @since 1.0.0\n */\nexport interface CrossOriginOptions {\n /**\n * CORS mode of the connection or request: `\"anonymous\"` sends no credentials, `\"use-credentials\"`\n * sends cookies and client certificates. Fonts and `fetch` preloads need one of them.\n * @default undefined (no `crossorigin` attribute; the browser's default for the resource applies)\n */\n readonly crossOrigin?: \"anonymous\" | \"use-credentials\";\n}\n\n/**\n * Options of {@link preload}: the destination is required, as the browser needs it to pick the\n * right request.\n * @since 1.0.0\n */\nexport interface PreloadOptions extends CrossOriginOptions {\n /**\n * The destination of the request, which the browser uses to pick its priority and headers. It\n * must match how the resource is used later, or the preloaded copy is not reused.\n */\n readonly as:\n | \"audio\"\n | \"document\"\n | \"embed\"\n | \"fetch\"\n | \"font\"\n | \"image\"\n | \"object\"\n | \"script\"\n | \"style\"\n | \"track\"\n | \"video\"\n | \"worker\";\n /**\n * MIME type, so the browser can skip unsupported formats (for example `font/woff2`).\n * @default undefined (no `type` attribute)\n */\n readonly type?: string;\n /**\n * Media query the hint applies to (for example `(min-width: 800px)`); the browser skips the\n * preload when it does not match.\n * @default undefined (no `media` attribute; the hint always applies)\n */\n readonly media?: string;\n}\n\n/**\n * Options of {@link preinit}.\n * @since 1.0.0\n */\nexport interface PreinitOptions extends CrossOriginOptions {\n /**\n * What to load: `\"style\"` inserts a stylesheet, `\"script\"` inserts an async script. Required, as\n * the two produce different elements.\n */\n readonly as: \"style\" | \"script\";\n}\n\ntype Attributes = Readonly<Record<string, string>>;\n\n/** Hints are page-level and only ever use http(s) URLs; anything else throws, like head tags do. */\nfunction checkUrl(href: string): void {\n const url = new URL(href, \"https://base.invalid\");\n if (url.protocol !== \"https:\" && url.protocol !== \"http:\") {\n throw new TypeError(\n __DEV__\n ? `resource hint: \"${href}\" must be an http(s) or relative URL`\n : \"SHADOW_RESOURCE_HINT_URL\",\n );\n }\n}\n\n/** Whether an element already carries every attribute of a hint (so the hint is already there). */\nfunction carries(element: Element, attributes: Attributes): boolean {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) return false;\n }\n return true;\n}\n\n/**\n * Inserts a hint element once: an identical element already in the head (server-rendered or added\n * earlier) is kept. On the server the hint joins the render's head collector, when there is one.\n */\nfunction hint(\n tag: \"link\" | \"script\",\n attributes: Attributes,\n serverTag: () => void = () => undefined,\n): void {\n if (isServer) {\n serverTag();\n return;\n }\n if (typeof document === \"undefined\") return;\n for (const existing of document.head.querySelectorAll(tag)) {\n if (carries(existing, attributes)) return;\n }\n const element = document.createElement(tag);\n for (const [name, value] of Object.entries(attributes)) element.setAttribute(name, value);\n document.head.append(element);\n}\n\n/** Server form of a hint: a head link (scripts cannot be head tags, see {@link preinitModule}). */\nfunction serverLink(attributes: Readonly<Record<string, HeadAttributeValue>>): () => void {\n return () => useHead({ tag: \"link\", props: attributes });\n}\n\n/**\n * Tells the browser to open a connection (DNS, TCP, TLS) to an origin the page will use soon.\n * React's `preconnect`. Calling it again for the same origin adds nothing. Works in a component, in\n * an event handler, or at module scope on the client.\n *\n * @param href An http(s) origin or URL.\n * @param options CORS mode (needed for fonts and fetch with credentials). Undefined adds no\n * `crossorigin` attribute.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or\n * relative.\n * @example\n * import { preconnect } from \"@shadow-js/web\";\n *\n * preconnect(\"https://fonts.example.com\", { crossOrigin: \"anonymous\" });\n * @see prefetchDNS\n * @see preload\n * @since 1.0.0\n */\nexport function preconnect(href: string, options?: CrossOriginOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n rel: \"preconnect\",\n href,\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Resolves an origin's DNS ahead of use. Cheaper than {@link preconnect}; React's `prefetchDNS`.\n * @param href An http(s) origin or URL.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { prefetchDNS } from \"@shadow-js/web\";\n *\n * prefetchDNS(\"https://api.example.com\");\n * @see preconnect\n * @since 1.0.0\n */\nexport function prefetchDNS(href: string): void {\n checkUrl(href);\n const attributes: Attributes = { rel: \"dns-prefetch\", href };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Starts fetching a resource the page will need, at high priority. The browser stores it for the\n * later request with the same URL and destination (React's `preload`).\n *\n * @param href An http(s) or relative URL.\n * @param options The destination (`as`, required) and the optional type, media and CORS mode.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preload } from \"@shadow-js/web\";\n *\n * preload(\"/fonts/inter.woff2\", { as: \"font\", type: \"font/woff2\", crossOrigin: \"anonymous\" });\n * @see preloadModule\n * @see preinit\n * @since 1.0.0\n */\nexport function preload(href: string, options: PreloadOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n rel: \"preload\",\n href,\n as: options.as,\n ...(options.type === undefined ? {} : { type: options.type }),\n ...(options.media === undefined ? {} : { media: options.media }),\n ...(options.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Starts loading an ES module the page will import, so the import does not wait for the module\n * graph to be discovered. React's `preloadModule`.\n * @param href An http(s) or relative URL of the module.\n * @param options CORS mode. Undefined adds no `crossorigin` attribute.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preloadModule } from \"@shadow-js/web\";\n *\n * preloadModule(\"/chunks/editor.js\");\n * @see preinitModule\n * @see preload\n * @since 1.0.0\n */\nexport function preloadModule(href: string, options?: CrossOriginOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n rel: \"modulepreload\",\n href,\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Loads a stylesheet or script now, and keeps it applied or executed (React's `preinit`). A\n * stylesheet becomes a `<link rel=\"stylesheet\">`; a script becomes an async `<script>` in the head.\n * On the server a script can only be hinted as a preload, because head tags cannot be scripts.\n *\n * @param href An http(s) or relative URL.\n * @param options What to load (`style` or `script`, required) and the CORS mode.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preinit } from \"@shadow-js/web\";\n *\n * preinit(\"/theme.css\", { as: \"style\" });\n * @see preload\n * @see preinitModule\n * @since 1.0.0\n */\nexport function preinit(href: string, options: PreinitOptions): void {\n checkUrl(href);\n if (options.as === \"style\") {\n const attributes: Attributes = {\n rel: \"stylesheet\",\n href,\n ...(options.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n return;\n }\n const attributes: Attributes = {\n src: href,\n async: \"\",\n ...(options.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"script\", attributes, serverLink({ rel: \"preload\", href, as: \"script\" }));\n}\n\n/**\n * Loads and runs an ES module now (React's `preinitModule`). On the client it inserts a\n * `<script type=\"module\">`; on the server it hints the module with `modulepreload`, since the\n * script itself is loaded by the page.\n *\n * @param href An http(s) or relative URL of the module.\n * @param options CORS mode. Undefined adds no `crossorigin` attribute.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preinitModule } from \"@shadow-js/web\";\n *\n * preinitModule(\"/chunks/app.js\");\n * @see preloadModule\n * @see preinit\n * @since 1.0.0\n */\nexport function preinitModule(href: string, options?: CrossOriginOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n src: href,\n type: \"module\",\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\n \"script\",\n attributes,\n serverLink({\n rel: \"modulepreload\",\n href,\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n }),\n );\n}\n"],"mappings":"A,wFAoEA,SAASA,EAAS,EAAoB,CACpC,IAAMC,EAAM,IAAI,IAAIC,EAAM,sBAAsB,EAChD,GAAID,EAAI,WAAa,UAAYA,EAAI,WAAa,QAChD,MAAU,UAGJ,0BACN,CAEJ,CAGA,SAASE,EAAQ,EAAkB,EAAiC,CAClE,IAAK,GAAM,CAACC,EAAMC,KAAU,OAAO,QAAQC,CAAU,EACnD,GAAIC,EAAQ,aAAaH,CAAI,IAAMC,EAAO,MAAO,GAEnD,MAAO,EACT,CAMA,SAASG,EACP,EACA,EACA,MAA8B,IAAA,GACxB,CACN,GAAIC,EAAU,CACZC,EAAU,EACV,MACF,CACA,GAAI,OAAO,SAAa,IAAa,OACrC,IAAK,IAAMC,KAAY,SAAS,KAAK,iBAAiBC,CAAG,EACvD,GAAIT,EAAQQ,EAAUL,CAAU,EAAG,OAErC,IAAMC,EAAU,SAAS,cAAcK,CAAG,EAC1C,IAAK,GAAM,CAACR,EAAMC,KAAU,OAAO,QAAQC,CAAU,EAAGC,EAAQ,aAAaH,EAAMC,CAAK,EACxF,SAAS,KAAK,OAAOE,CAAO,CAC9B,CAGA,SAASM,EAAW,EAAsE,CACxF,UAAaC,EAAQ,CAAE,IAAK,OAAQ,MAAOR,CAAW,CAAC,CACzD,CAoBA,SAAgBS,EAAW,EAAc,EAAoC,CAC3Ef,EAASE,CAAI,EACb,IAAMI,EAAyB,CAC7B,IAAK,aACL,OACA,GAAIU,GAAS,cAAgB,IAAA,GAAY,CAAC,EAAI,CAAE,YAAaA,EAAQ,WAAY,CACnF,EACAR,EAAK,OAAQF,EAAYO,EAAWP,CAAU,CAAC,CACjD,CAaA,SAAgBW,EAAY,EAAoB,CAC9CjB,EAASE,CAAI,EACb,IAAMI,EA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,EAMbM,EACE,SACA,CANA,IAAKN,EACL,KAAM,SACN,GAAIc,GAAS,cAAgB,IAAA,GAAY,CAAC,EAAI,CAAE,YAAaA,EAAQ,WAAY,CAIxE,EACTH,EAAW,CACT,IAAK,gBACL,OACA,GAAIG,GAAS,cAAgB,IAAA,GAAY,CAAC,EAAI,CAAE,YAAaA,EAAQ,WAAY,CACnF,CAAC,CACH,CACF,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e){let t=/* @__PURE__ */ new Set;for(let n of e)n!=null&&t.add(String(n));return t}function t(e){return e==null?``:String(e)}function n(n,r){if(n.multiple&&Array.isArray(r)){let t=e(r);for(let e of Array.from(n.options))e.selected=t.has(e.value)}else n.value=t(r)}function r(n,r){if(n.multiple&&Array.isArray(r)){let t=e(r);return Array.from(n.options).every(e=>e.selected===t.has(e.value))}return n.value===t(r)}export{r as selectShows,n as setSelectValue};
|
|
2
|
+
//# sourceMappingURL=select-value.js.map
|