@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,357 @@
|
|
|
1
|
+
import { DEVTOOLS_EVENT, devtoolsReport } from "@shadow-js/core/extend";
|
|
2
|
+
//#region src/internal/claim.ts
|
|
3
|
+
let state = null;
|
|
4
|
+
/** Starts a claiming pass over the given server elements. @internal */
|
|
5
|
+
function beginClaiming(registry, recoverable) {
|
|
6
|
+
state = {
|
|
7
|
+
registry,
|
|
8
|
+
recoverable,
|
|
9
|
+
pending: /* @__PURE__ */ new WeakMap(),
|
|
10
|
+
lifted: []
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** Ends the claiming pass. @internal */
|
|
14
|
+
function endClaiming() {
|
|
15
|
+
state = null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Reports whether a `hydrate()` pass is claiming server DOM right now: a custom renderer reads it to
|
|
19
|
+
* decide between adopting server nodes and building fresh ones. The pass is synchronous, so this is
|
|
20
|
+
* `false` again once `hydrate()` returns, and in every later update.
|
|
21
|
+
*
|
|
22
|
+
* @returns `true` during the synchronous pass of `hydrate()` (outside {@link withoutClaiming}),
|
|
23
|
+
* `false` otherwise.
|
|
24
|
+
* @example
|
|
25
|
+
* import { isClaiming } from "@shadow-js/web/extend";
|
|
26
|
+
*
|
|
27
|
+
* function describe(): string {
|
|
28
|
+
* return isClaiming() ? "adopting server markup" : "building fresh DOM";
|
|
29
|
+
* }
|
|
30
|
+
* @see claims
|
|
31
|
+
* @since 1.0.0
|
|
32
|
+
*/
|
|
33
|
+
function isClaiming() {
|
|
34
|
+
return state !== null;
|
|
35
|
+
}
|
|
36
|
+
function isMarker(node, data) {
|
|
37
|
+
if (node.nodeType !== 8) return false;
|
|
38
|
+
const text = node.data;
|
|
39
|
+
return text === data || data === "[" && text.startsWith("[b:");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Turns server markup for one template into the shape a freshly cloned template has: region
|
|
43
|
+
* contents are lifted out (to be re-inserted by `insert`), marker comments are removed and text
|
|
44
|
+
* nodes are merged again. Iterative; static elements below the root are walked, regions are not
|
|
45
|
+
* (their contents belong to other templates, claimed later through the registry).
|
|
46
|
+
*/
|
|
47
|
+
function prepare(root, pending, lifted) {
|
|
48
|
+
const stack = [root];
|
|
49
|
+
while (stack.length > 0) {
|
|
50
|
+
const parent = stack.pop();
|
|
51
|
+
if (parent === void 0) break;
|
|
52
|
+
let child = parent.firstChild;
|
|
53
|
+
while (child !== null) {
|
|
54
|
+
const following = child.nextSibling;
|
|
55
|
+
if (isMarker(child, "[")) {
|
|
56
|
+
const content = [];
|
|
57
|
+
let depth = 1;
|
|
58
|
+
let cursor = child.nextSibling;
|
|
59
|
+
while (cursor !== null) {
|
|
60
|
+
if (isMarker(cursor, "[")) depth += 1;
|
|
61
|
+
else if (isMarker(cursor, "]")) {
|
|
62
|
+
depth -= 1;
|
|
63
|
+
if (depth === 0) break;
|
|
64
|
+
}
|
|
65
|
+
content.push(cursor);
|
|
66
|
+
cursor = cursor.nextSibling;
|
|
67
|
+
}
|
|
68
|
+
const after = cursor === null ? null : cursor.nextSibling;
|
|
69
|
+
lifted.push(content);
|
|
70
|
+
for (const node of content) parent.removeChild(node);
|
|
71
|
+
parent.removeChild(child);
|
|
72
|
+
if (cursor !== null) parent.removeChild(cursor);
|
|
73
|
+
const queue = pending.get(parent);
|
|
74
|
+
if (queue === void 0) pending.set(parent, [content]);
|
|
75
|
+
else queue.push(content);
|
|
76
|
+
child = after;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (child.nodeType === 1) stack.push(child);
|
|
80
|
+
child = following;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
root.normalize();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Adopts the server's element for a hydration key while `hydrate()` runs: the step that lets a custom
|
|
87
|
+
* template reuse server markup instead of creating new nodes. The element loses its `data-hk`
|
|
88
|
+
* attribute, and the content of its regions is lifted out, to be adopted by {@link takeRegion} when
|
|
89
|
+
* the regions bind. Prefer `claims.current.claimElement`, which links this code only into apps that
|
|
90
|
+
* call `hydrate()`.
|
|
91
|
+
*
|
|
92
|
+
* @param key The key from `nextKey()`, drawn where the server drew it. Undefined claims nothing.
|
|
93
|
+
* @returns The server element; `null` when no hydration pass is running, when `key` is undefined, or
|
|
94
|
+
* when the server sent no element for the key (the caller then creates the node itself). A missing
|
|
95
|
+
* key is a recoverable mismatch: development builds warn `HYDRATION_KEY_MISS`, and the pass's
|
|
96
|
+
* `onRecoverableError` receives an `Error`.
|
|
97
|
+
* @example
|
|
98
|
+
* import { claimElement, nextKey } from "@shadow-js/web/extend";
|
|
99
|
+
*
|
|
100
|
+
* function createPanel(): Element {
|
|
101
|
+
* // During hydrate(): the server's <section>. Otherwise: a new one.
|
|
102
|
+
* return claimElement(nextKey()) ?? document.createElement("section");
|
|
103
|
+
* }
|
|
104
|
+
* @see claims
|
|
105
|
+
* @since 1.0.0
|
|
106
|
+
*/
|
|
107
|
+
function claimElement(key) {
|
|
108
|
+
const current = state;
|
|
109
|
+
if (current === null || key === void 0) return null;
|
|
110
|
+
const element = current.registry.get(key);
|
|
111
|
+
if (element === void 0) {
|
|
112
|
+
{
|
|
113
|
+
const message = `No server element for key "${key}".`;
|
|
114
|
+
console.warn(`[shadow HYDRATION_KEY_MISS] ${message}`);
|
|
115
|
+
devtoolsReport(DEVTOOLS_EVENT.HYDRATION_MISMATCH, message, key, void 0);
|
|
116
|
+
}
|
|
117
|
+
current.recoverable?.(/* @__PURE__ */ new Error(`No server element for key "${key}".`));
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
current.registry.delete(key);
|
|
121
|
+
element.removeAttribute("data-hk");
|
|
122
|
+
prepare(element, current.pending, current.lifted);
|
|
123
|
+
return element;
|
|
124
|
+
}
|
|
125
|
+
/** Characters that stay readable as escapes in a diagnostic snippet: markup, quotes and ampersands. */
|
|
126
|
+
const SNIPPET_ESCAPES = /* @__PURE__ */ new Map([
|
|
127
|
+
["<", "\\u003c"],
|
|
128
|
+
[">", "\\u003e"],
|
|
129
|
+
["&", "\\u0026"],
|
|
130
|
+
["\"", "\\u0022"],
|
|
131
|
+
["'", "\\u0027"]
|
|
132
|
+
]);
|
|
133
|
+
/**
|
|
134
|
+
* Escapes text for a diagnostic snippet and cuts it to `limit` output characters, with `...` when cut.
|
|
135
|
+
* Escapes are never split, so the output is at most `limit + 3` characters.
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
function snippet(text, limit) {
|
|
139
|
+
let out = "";
|
|
140
|
+
for (const char of text) {
|
|
141
|
+
const code = char.codePointAt(0) ?? 0;
|
|
142
|
+
const controlled = code < 32 || code >= 127 && code <= 159;
|
|
143
|
+
const escaped = SNIPPET_ESCAPES.get(char) ?? (controlled ? `\\u${code.toString(16).padStart(4, "0")}` : char);
|
|
144
|
+
if (out.length + escaped.length > limit) return `${out}...`;
|
|
145
|
+
out += escaped;
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
/** The opening tag of a server element as the server wrote it (attribute values as they are). */
|
|
150
|
+
function openingMarkup(element) {
|
|
151
|
+
let markup = `<${element.localName}`;
|
|
152
|
+
for (const attr of Array.from(element.attributes)) markup += ` ${attr.name}="${attr.value}"`;
|
|
153
|
+
return `${markup}>`;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Development check of a claimed element against the tag its template or `element()` call expects.
|
|
157
|
+
* A different tag warns `HYDRATION_MISMATCH` on the console and in devtools, with an escaped snippet of
|
|
158
|
+
* the server element (its opening tag and the start of its text, bounded). Recovery is unchanged: the
|
|
159
|
+
* element is still adopted, nothing is thrown or replaced, and the caller gets the same value.
|
|
160
|
+
*
|
|
161
|
+
* Call it under `if (__DEV__)`. Text is not compared here: the expected text is inserted later, by
|
|
162
|
+
* `insert`, and {@link checkClaimedText} compares it with the server text at that point.
|
|
163
|
+
*
|
|
164
|
+
* @param element The server element `claimElement` returned.
|
|
165
|
+
* @param expectedTag The tag the client expects (any case).
|
|
166
|
+
* @internal
|
|
167
|
+
*/
|
|
168
|
+
function checkClaimedTag(element, expectedTag) {
|
|
169
|
+
const expected = expectedTag.toLowerCase();
|
|
170
|
+
const actual = element.localName.toLowerCase();
|
|
171
|
+
if (actual === expected) return;
|
|
172
|
+
const text = element.textContent ?? "";
|
|
173
|
+
let detail = `expected <${expected}> but the server sent <${snippet(actual, 80)}>; server markup: "${snippet(openingMarkup(element), 80)}"`;
|
|
174
|
+
if (text !== "") detail += `; text: "${snippet(text, 40)}"`;
|
|
175
|
+
console.warn(`[shadow HYDRATION_MISMATCH] ${detail}`);
|
|
176
|
+
devtoolsReport(DEVTOOLS_EVENT.HYDRATION_MISMATCH, detail, void 0, void 0);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Development check of the first commit of a region that claimed server text. The server text is the
|
|
180
|
+
* DOM text of the claimed nodes (already decoded, so an escaped `<` compares as `<`); the expected
|
|
181
|
+
* text is the strings of the first commit, joined (a number is already its string, `null` and booleans
|
|
182
|
+
* render nothing, so they expect `""`). Equal text is silent. Different text warns
|
|
183
|
+
* `HYDRATION_TEXT_MISMATCH` on the console and in devtools, with both texts escaped and bounded to 40
|
|
184
|
+
* characters. Recovery is unchanged: the region shows the value the client computed.
|
|
185
|
+
*
|
|
186
|
+
* Not compared, so silent: a region that claimed no nodes (an empty server region has no server text),
|
|
187
|
+
* a region whose server nodes are not all text (an element, or the markers of a nested region), and a
|
|
188
|
+
* commit that holds a node (an element is shown in place of the server's content, as before).
|
|
189
|
+
*
|
|
190
|
+
* Call it under `if (__DEV__)`, once per claimed region, at its first commit.
|
|
191
|
+
*
|
|
192
|
+
* @param claimed The server nodes the region adopted, in document order.
|
|
193
|
+
* @param parts What the first commit shows: strings, or nodes.
|
|
194
|
+
* @internal
|
|
195
|
+
* @since 1.0.0
|
|
196
|
+
*/
|
|
197
|
+
function checkClaimedText(claimed, parts) {
|
|
198
|
+
if (claimed.length === 0) return;
|
|
199
|
+
let server = "";
|
|
200
|
+
for (const node of claimed) {
|
|
201
|
+
if (node.nodeType !== 3) return;
|
|
202
|
+
server += node.textContent ?? "";
|
|
203
|
+
}
|
|
204
|
+
let expected = "";
|
|
205
|
+
for (const part of parts) {
|
|
206
|
+
if (typeof part !== "string") return;
|
|
207
|
+
expected += part;
|
|
208
|
+
}
|
|
209
|
+
if (expected === server) return;
|
|
210
|
+
const detail = `expected text "${snippet(expected, 40)}" but the server sent text "${snippet(server, 40)}"`;
|
|
211
|
+
console.warn(`[shadow HYDRATION_TEXT_MISMATCH] ${detail}`);
|
|
212
|
+
devtoolsReport(DEVTOOLS_EVENT.HYDRATION_MISMATCH, detail, void 0, void 0);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Adopts the server content of the next region of a claimed parent while `hydrate()` runs: the nodes
|
|
216
|
+
* that sat between the region's markers are put back before `anchorNode` and returned, so a custom
|
|
217
|
+
* region can bind to them instead of inserting new nodes. Regions are taken in document order.
|
|
218
|
+
*
|
|
219
|
+
* @param parent An element returned by {@link claimElement} (or one of its descendants).
|
|
220
|
+
* @param anchorNode The node the content goes before; `null` appends it at the end of `parent`.
|
|
221
|
+
* @returns The adopted nodes; undefined when no hydration pass is running or `parent` has no region
|
|
222
|
+
* left to adopt (the caller then inserts fresh nodes).
|
|
223
|
+
* @example
|
|
224
|
+
* import { takeRegion } from "@shadow-js/web/extend";
|
|
225
|
+
*
|
|
226
|
+
* function fillRegion(parent: Element): Node[] {
|
|
227
|
+
* const adopted = takeRegion(parent, null);
|
|
228
|
+
* if (adopted !== undefined) return adopted;
|
|
229
|
+
* const text = document.createTextNode("fresh");
|
|
230
|
+
* parent.append(text);
|
|
231
|
+
* return [text];
|
|
232
|
+
* }
|
|
233
|
+
* @see claimElement
|
|
234
|
+
* @since 1.0.0
|
|
235
|
+
*/
|
|
236
|
+
function takeRegion(parent, anchorNode) {
|
|
237
|
+
const current = state;
|
|
238
|
+
if (current === null) return void 0;
|
|
239
|
+
const content = current.pending.get(parent)?.shift();
|
|
240
|
+
if (content === void 0) return void 0;
|
|
241
|
+
for (const node of content) parent.insertBefore(node, anchorNode);
|
|
242
|
+
return content;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* The content of every region the pass lifted out of the server elements it claimed, in document order. `NoHydration` finds
|
|
246
|
+
* its own markers in them. Undefined outside a hydration pass.
|
|
247
|
+
* @internal
|
|
248
|
+
*/
|
|
249
|
+
function liftedRegions() {
|
|
250
|
+
return state?.lifted;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Runs `fn` with claiming switched off, so the templates it builds are created fresh instead of
|
|
254
|
+
* claimed from the server markup. Use it for content the server did not render (a portal the server
|
|
255
|
+
* sent nothing for), so its keys are not reported as missing. The previous state is restored when
|
|
256
|
+
* `fn` returns or throws.
|
|
257
|
+
*
|
|
258
|
+
* @param fn The code to run. It runs synchronously, once.
|
|
259
|
+
* @returns What `fn` returns. An error `fn` throws propagates.
|
|
260
|
+
* @example
|
|
261
|
+
* import { template } from "@shadow-js/web";
|
|
262
|
+
* import { withoutClaiming } from "@shadow-js/web/extend";
|
|
263
|
+
*
|
|
264
|
+
* const makeTip = template(`<div class="tip"></div>`);
|
|
265
|
+
* const tip = withoutClaiming(() => makeTip()); // a fresh clone, even during hydrate()
|
|
266
|
+
* @see claims
|
|
267
|
+
* @since 1.0.0
|
|
268
|
+
*/
|
|
269
|
+
function withoutClaiming(fn) {
|
|
270
|
+
const saved = state;
|
|
271
|
+
state = null;
|
|
272
|
+
try {
|
|
273
|
+
return fn();
|
|
274
|
+
} finally {
|
|
275
|
+
state = saved;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/** Comment that opens the server block of a portal (`<!--portal:KEY-->`). */
|
|
279
|
+
const PORTAL_OPEN = "portal:";
|
|
280
|
+
/** Comment that closes it (`<!--/portal:KEY-->`). */
|
|
281
|
+
const PORTAL_CLOSE = "/portal:";
|
|
282
|
+
/**
|
|
283
|
+
* Adopts the server block of a portal while `hydrate()` runs. The server writes each portal's markup
|
|
284
|
+
* at the end of `<body>` between `<!--portal:KEY-->` and `<!--/portal:KEY-->` comments (see
|
|
285
|
+
* `createServerPortals`); this removes the comments, leaves the content in place, and registers its
|
|
286
|
+
* keyed elements so the portal's templates claim them.
|
|
287
|
+
*
|
|
288
|
+
* @param key The portal's key from `nextKey()`. Undefined claims nothing.
|
|
289
|
+
* @returns The nodes of the block, in place in the body; undefined when no hydration pass is running,
|
|
290
|
+
* `key` is undefined, there is no document body, or the server sent no complete block for the key.
|
|
291
|
+
* @example
|
|
292
|
+
* import { claimPortal, nextKey } from "@shadow-js/web/extend";
|
|
293
|
+
*
|
|
294
|
+
* function mountOverlay(build: () => Node): Node[] {
|
|
295
|
+
* const adopted = claimPortal(nextKey());
|
|
296
|
+
* if (adopted !== undefined) return adopted;
|
|
297
|
+
* const node = build();
|
|
298
|
+
* document.body.append(node);
|
|
299
|
+
* return [node];
|
|
300
|
+
* }
|
|
301
|
+
* @since 1.0.0
|
|
302
|
+
*/
|
|
303
|
+
function claimPortal(key) {
|
|
304
|
+
const current = state;
|
|
305
|
+
if (current === null || key === void 0 || typeof document === "undefined") return void 0;
|
|
306
|
+
const body = document.body;
|
|
307
|
+
if (body === null) return void 0;
|
|
308
|
+
const nodes = Array.from(body.childNodes);
|
|
309
|
+
const open = nodes.findIndex((node) => isComment(node, PORTAL_OPEN + key));
|
|
310
|
+
if (open === -1) return void 0;
|
|
311
|
+
const close = nodes.findIndex((node, index) => index > open && isComment(node, PORTAL_CLOSE + key));
|
|
312
|
+
if (close === -1) return void 0;
|
|
313
|
+
const content = [];
|
|
314
|
+
for (const node of nodes.slice(open + 1, close)) if (node.nodeType === 8 && isRegionMarker(node)) body.removeChild(node);
|
|
315
|
+
else content.push(node);
|
|
316
|
+
for (const node of [nodes[open], nodes[close]]) if (node !== void 0) body.removeChild(node);
|
|
317
|
+
for (const node of content) {
|
|
318
|
+
if (node.nodeType !== 1) continue;
|
|
319
|
+
const element = node;
|
|
320
|
+
const own = element.getAttribute("data-hk");
|
|
321
|
+
if (own !== null) current.registry.set(own, element);
|
|
322
|
+
for (const keyed of Array.from(element.querySelectorAll("[data-hk]"))) {
|
|
323
|
+
const hk = keyed.getAttribute("data-hk");
|
|
324
|
+
if (hk !== null) current.registry.set(hk, keyed);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return content;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Removes the server blocks of portals that were not claimed during the pass: the client did not render
|
|
331
|
+
* those portals, so their markup must not stay in the page. Each block goes with its comments. A block
|
|
332
|
+
* without its closing comment loses only its opening one.
|
|
333
|
+
* @internal
|
|
334
|
+
*/
|
|
335
|
+
function releaseUnclaimedPortals(body) {
|
|
336
|
+
const nodes = Array.from(body.childNodes);
|
|
337
|
+
for (let open = 0; open < nodes.length; open += 1) {
|
|
338
|
+
const opening = nodes[open];
|
|
339
|
+
if (opening === void 0 || opening.nodeType !== 8) continue;
|
|
340
|
+
const data = opening.data;
|
|
341
|
+
if (!data.startsWith(PORTAL_OPEN)) continue;
|
|
342
|
+
const close = nodes.findIndex((node, index) => index > open && isComment(node, PORTAL_CLOSE + data.slice(7)));
|
|
343
|
+
const last = close === -1 ? open : close;
|
|
344
|
+
for (const node of nodes.slice(open, last + 1)) if (node.parentNode === body) body.removeChild(node);
|
|
345
|
+
open = last;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function isComment(node, data) {
|
|
349
|
+
return node.nodeType === 8 && node.data === data;
|
|
350
|
+
}
|
|
351
|
+
function isRegionMarker(comment) {
|
|
352
|
+
return comment.data === "[" || comment.data === "]";
|
|
353
|
+
}
|
|
354
|
+
//#endregion
|
|
355
|
+
export { beginClaiming, checkClaimedTag, checkClaimedText, claimElement, claimPortal, endClaiming, isClaiming, liftedRegions, releaseUnclaimedPortals, takeRegion, withoutClaiming };
|
|
356
|
+
|
|
357
|
+
//# sourceMappingURL=claim.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claim.js","names":[],"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":"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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/internal/css-units.ts
|
|
2
|
+
/**
|
|
3
|
+
* React's unitless style properties. A number given to any other property is in pixels (`0` stays
|
|
4
|
+
* `0`); these properties take the bare number. Vendor prefixes do not change the answer.
|
|
5
|
+
*
|
|
6
|
+
* The compiler never needs this table for static values, and `class-style.ts` and the server
|
|
7
|
+
* stylesheet writer are the only importers, so it is linked only where a style is written.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
const UNITLESS = 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(" "));
|
|
11
|
+
/**
|
|
12
|
+
* The CSS text of one style value. A finite or non-finite number gets `px` unless it is zero, a
|
|
13
|
+
* custom property (`--x`) or unitless; every other value is `String(value)`.
|
|
14
|
+
* @param property The CSS property in kebab-case (`toCssProperty` output).
|
|
15
|
+
* @param value The style value.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
function cssValueText(property, value) {
|
|
19
|
+
if (typeof value !== "number" || value === 0 || property.startsWith("--")) return String(value);
|
|
20
|
+
const bare = property.replace(/^-(?:webkit|moz|ms|o)-/, "");
|
|
21
|
+
return UNITLESS.has(bare) ? String(value) : `${value}px`;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { cssValueText };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=css-units.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-units.js","names":[],"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,MAAM,WAAgC,IAAI,IAEtC,qjBAOA,MAAM,GAAG,CACb;;;;;;;;AASA,SAAgB,aAAa,UAAkB,OAAwB;CACrE,IAAI,OAAO,UAAU,YAAY,UAAU,KAAK,SAAS,WAAW,IAAI,GAAG,OAAO,OAAO,KAAK;CAC9F,MAAM,OAAO,SAAS,QAAQ,0BAA0B,EAAE;CAC1D,OAAO,SAAS,IAAI,IAAI,IAAI,OAAO,KAAK,IAAI,GAAG,MAAM;AACvD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/internal/diagnostics.ts
|
|
2
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3
|
+
/**
|
|
4
|
+
* Prints a development warning as `[shadow CODE] detail`, at most once per code for the life of the
|
|
5
|
+
* page or process (the same pattern as core's `warn`): for a custom renderer that refuses a value the
|
|
6
|
+
* way the built-in ones do. Production builds print nothing.
|
|
7
|
+
*
|
|
8
|
+
* @param code The diagnostic code. A code that was already reported is ignored, whatever the detail.
|
|
9
|
+
* @param detail The text after the code.
|
|
10
|
+
* @example
|
|
11
|
+
* import { isUnsafeUrlAttribute, warnOnce } from "@shadow-js/web/extend";
|
|
12
|
+
*
|
|
13
|
+
* function setLink(el: Element, url: string): void {
|
|
14
|
+
* if (isUnsafeUrlAttribute("href", url)) {
|
|
15
|
+
* warnOnce("UNSAFE_URL_BLOCKED", `Blocked a script URL: ${url}`);
|
|
16
|
+
* return;
|
|
17
|
+
* }
|
|
18
|
+
* el.setAttribute("href", url);
|
|
19
|
+
* }
|
|
20
|
+
* @since 1.0.0
|
|
21
|
+
*/
|
|
22
|
+
function warnOnce(code, detail) {
|
|
23
|
+
if (seen.has(code)) return;
|
|
24
|
+
seen.add(code);
|
|
25
|
+
console.warn(`[shadow ${code}] ${detail}`);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Error thrown for attribute names that cannot appear in markup. Dev builds carry the full text;
|
|
29
|
+
* production keeps the code and the name (the same split as core's messages).
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
function invalidAttributeName(name) {
|
|
33
|
+
return /* @__PURE__ */ new TypeError(`[shadow INVALID_ATTRIBUTE_NAME] "${name}" is not a valid attribute name.`);
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { invalidAttributeName, warnOnce };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","names":[],"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":";AAWA,MAAM,uBAAO,IAAI,IAAoB;;;;;;;;;;;;;;;;;;;;AAqBrC,SAAgB,SAAS,MAAsB,QAAsB;CAEnE,IAAI,KAAK,IAAI,IAAI,GAAG;CACpB,KAAK,IAAI,IAAI;CACb,QAAQ,KAAK,WAAW,KAAK,IAAI,QAAQ;AAC3C;;;;;;AAYA,SAAgB,qBAAqB,MAAyB;CAE5D,uBAAO,IAAI,UAAU,oCAAoC,KAAK,iCAAiC;AACjG"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
//#region src/internal/early-events.ts
|
|
2
|
+
/**
|
|
3
|
+
* Early event capture (ADR-016): a tiny inline script, placed before the bundle, records the events a
|
|
4
|
+
* user makes before the application has hydrated. `hydrate()` then replays them once its handlers are
|
|
5
|
+
* attached, so a click made while the page was still loading is not lost. The script is generated by
|
|
6
|
+
* `generateHydrationScript` on the server; the replay is the client half, and it does nothing when the
|
|
7
|
+
* page has no captured events.
|
|
8
|
+
*/
|
|
9
|
+
/** The event types recorded when a page does not name its own. @internal */
|
|
10
|
+
const DEFAULT_EARLY_EVENTS = ["click", "input"];
|
|
11
|
+
/** The window property the capture script writes. Its shape is checked before use. @internal */
|
|
12
|
+
const EARLY_CAPTURE_KEY = "__SHADOWJS_EARLY__";
|
|
13
|
+
/** Event names are plain lower-case words: anything else would end up inside the script text. */
|
|
14
|
+
const EVENT_NAME = /^[a-z]+$/;
|
|
15
|
+
/**
|
|
16
|
+
* The inline script body. A capture listener on the document (capture phase, so it sees events even
|
|
17
|
+
* when a page stops their propagation) queues each event; the queue and the listener are kept on
|
|
18
|
+
* `window` for the replay.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
function captureScriptBody(names) {
|
|
22
|
+
return "(function(){var d=document,n=" + JSON.stringify(names.filter((name) => EVENT_NAME.test(name))) + `,q=[];function c(e){q.push(e)}for(var i=0;i<n.length;i++)d.addEventListener(n[i],c,true);window.${EARLY_CAPTURE_KEY}={queue:q,names:n,listener:c};})();`;
|
|
23
|
+
}
|
|
24
|
+
/** The capture the script left on the window, validated, or undefined. */
|
|
25
|
+
function readCapture() {
|
|
26
|
+
const value = Reflect.get(globalThis, EARLY_CAPTURE_KEY);
|
|
27
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
28
|
+
const queue = Reflect.get(value, "queue");
|
|
29
|
+
const names = Reflect.get(value, "names");
|
|
30
|
+
const listener = Reflect.get(value, "listener");
|
|
31
|
+
if (!Array.isArray(queue) || !Array.isArray(names) || typeof listener !== "function") return;
|
|
32
|
+
return {
|
|
33
|
+
queue: queue.filter((item) => item instanceof Event),
|
|
34
|
+
names: names.filter((name) => typeof name === "string"),
|
|
35
|
+
listener
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** A new event of the same type that bubbles like the original and carries its pointer position. */
|
|
39
|
+
function reissue(event) {
|
|
40
|
+
const init = {
|
|
41
|
+
bubbles: true,
|
|
42
|
+
cancelable: event.cancelable,
|
|
43
|
+
composed: true
|
|
44
|
+
};
|
|
45
|
+
if (event instanceof MouseEvent) return new MouseEvent(event.type, {
|
|
46
|
+
...init,
|
|
47
|
+
clientX: event.clientX,
|
|
48
|
+
clientY: event.clientY,
|
|
49
|
+
button: event.button,
|
|
50
|
+
buttons: event.buttons,
|
|
51
|
+
altKey: event.altKey,
|
|
52
|
+
ctrlKey: event.ctrlKey,
|
|
53
|
+
metaKey: event.metaKey,
|
|
54
|
+
shiftKey: event.shiftKey
|
|
55
|
+
});
|
|
56
|
+
return new Event(event.type, init);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Stops the capture and replays what it recorded, in order, on the elements they were made on. Called
|
|
60
|
+
* by `hydrate()` after the handlers are attached. Does nothing when no capture ran.
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
function replayEarlyEvents() {
|
|
64
|
+
const capture = readCapture();
|
|
65
|
+
if (capture === void 0) return;
|
|
66
|
+
Reflect.deleteProperty(globalThis, EARLY_CAPTURE_KEY);
|
|
67
|
+
for (const name of capture.names) document.removeEventListener(name, capture.listener, true);
|
|
68
|
+
for (const event of capture.queue) {
|
|
69
|
+
const target = event.target;
|
|
70
|
+
if (target instanceof Node) target.dispatchEvent(reissue(event));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { DEFAULT_EARLY_EVENTS, EARLY_CAPTURE_KEY, captureScriptBody, replayEarlyEvents };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=early-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"early-events.js","names":[],"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,MAAa,uBAA0C,CAAC,SAAS,OAAO;;AAGxE,MAAa,oBAAoB;;AAGjC,MAAM,aAAa;;;;;;;AAQnB,SAAgB,kBAAkB,OAAkC;CAElE,OACE,kCAFW,KAAK,UAAU,MAAM,QAAQ,SAAS,WAAW,KAAK,IAAI,CAAC,CAGnE,IACH,mGAEU,kBAAkB;AAEhC;;AASA,SAAS,cAAmC;CAC1C,MAAM,QAAiB,QAAQ,IAAI,YAAY,iBAAiB;CAChE,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,KAAA;CACxD,MAAM,QAAiB,QAAQ,IAAI,OAAO,OAAO;CACjD,MAAM,QAAiB,QAAQ,IAAI,OAAO,OAAO;CACjD,MAAM,WAAoB,QAAQ,IAAI,OAAO,UAAU;CACvD,IAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,CAAC,MAAM,QAAQ,KAAK,KAAK,OAAO,aAAa,YACxE;CAIF,OAAO;EAAE,OAFM,MAAM,QAAQ,SAAwB,gBAAgB,KAEhD;EAAG,OADV,MAAM,QAAQ,SAAyB,OAAO,SAAS,QAClC;EAAa;CAAmC;AACrF;;AAGA,SAAS,QAAQ,OAAqB;CACpC,MAAM,OAAkB;EAAE,SAAS;EAAM,YAAY,MAAM;EAAY,UAAU;CAAK;CACtF,IAAI,iBAAiB,YACnB,OAAO,IAAI,WAAW,MAAM,MAAM;EAChC,GAAG;EACH,SAAS,MAAM;EACf,SAAS,MAAM;EACf,QAAQ,MAAM;EACd,SAAS,MAAM;EACf,QAAQ,MAAM;EACd,SAAS,MAAM;EACf,SAAS,MAAM;EACf,UAAU,MAAM;CAClB,CAAC;CAEH,OAAO,IAAI,MAAM,MAAM,MAAM,IAAI;AACnC;;;;;;AAOA,SAAgB,oBAA0B;CACxC,MAAM,UAAU,YAAY;CAC5B,IAAI,YAAY,KAAA,GAAW;CAC3B,QAAQ,eAAe,YAAY,iBAAiB;CACpD,KAAK,MAAM,QAAQ,QAAQ,OAAO,SAAS,oBAAoB,MAAM,QAAQ,UAAU,IAAI;CAC3F,KAAK,MAAM,SAAS,QAAQ,OAAO;EACjC,MAAM,SAAS,MAAM;EACrB,IAAI,kBAAkB,MAAM,OAAO,cAAc,QAAQ,KAAK,CAAC;CACjE;AACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The claims in effect. Read at each call (never captured), so a region that is updated after its
|
|
3
|
+
* hydration pass ended builds fresh DOM. Only `hydrate()` replaces it, and restores it in `finally`.
|
|
4
|
+
* Outside a hydration pass every method is a no-op.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* import { claims, nextKey } from "@shadow-js/web/extend";
|
|
8
|
+
*
|
|
9
|
+
* function createCard(): Element {
|
|
10
|
+
* // Adopts the server's element during hydrate(); builds a new one otherwise.
|
|
11
|
+
* return claims.current.claimElement(nextKey()) ?? document.createElement("article");
|
|
12
|
+
* }
|
|
13
|
+
* @see Claims
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
*/
|
|
16
|
+
const claims = { current: {
|
|
17
|
+
claimElement: () => null,
|
|
18
|
+
takeRegion: () => void 0,
|
|
19
|
+
liftedRegions: () => void 0,
|
|
20
|
+
claimPortal: () => void 0,
|
|
21
|
+
isClaiming: () => false,
|
|
22
|
+
withoutClaiming: (fn) => fn()
|
|
23
|
+
} };
|
|
24
|
+
//#endregion
|
|
25
|
+
export { claims };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=hydration-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration-hooks.js","names":[],"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,MAAa,SAA8B,EAAE,SAAS;CAvBpD,oBAAoB;CACpB,kBAAkB,KAAA;CAClB,qBAAqB,KAAA;CACrB,mBAAmB,KAAA;CACnB,kBAAkB;CAClB,kBAAkB,OAAO,GAAG;AAkBwB,EAAK"}
|