@shadow-js/web 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +190 -2
- package/dist/dev/attributes.d.ts +88 -0
- package/dist/dev/attributes.js +195 -0
- package/dist/dev/attributes.js.map +1 -0
- package/dist/dev/autofocus.d.ts +30 -0
- package/dist/dev/autofocus.js +44 -0
- package/dist/dev/autofocus.js.map +1 -0
- package/dist/dev/class-style.d.ts +87 -0
- package/dist/dev/class-style.js +196 -0
- package/dist/dev/class-style.js.map +1 -0
- package/dist/dev/component.d.ts +21 -0
- package/dist/dev/component.js +41 -0
- package/dist/dev/component.js.map +1 -0
- package/dist/dev/control-flow/activity.d.ts +56 -0
- package/dist/dev/control-flow/activity.js +135 -0
- package/dist/dev/control-flow/activity.js.map +1 -0
- package/dist/dev/control-flow/branch.js +103 -0
- package/dist/dev/control-flow/branch.js.map +1 -0
- package/dist/dev/control-flow/client-only.d.ts +46 -0
- package/dist/dev/control-flow/client-only.js +49 -0
- package/dist/dev/control-flow/client-only.js.map +1 -0
- package/dist/dev/control-flow/dynamic.d.ts +80 -0
- package/dist/dev/control-flow/dynamic.js +133 -0
- package/dist/dev/control-flow/dynamic.js.map +1 -0
- package/dist/dev/control-flow/error-boundary.d.ts +70 -0
- package/dist/dev/control-flow/error-boundary.js +114 -0
- package/dist/dev/control-flow/error-boundary.js.map +1 -0
- package/dist/dev/control-flow/for.d.ts +78 -0
- package/dist/dev/control-flow/for.js +22 -0
- package/dist/dev/control-flow/for.js.map +1 -0
- package/dist/dev/control-flow/fragment.d.ts +36 -0
- package/dist/dev/control-flow/fragment.js +30 -0
- package/dist/dev/control-flow/fragment.js.map +1 -0
- package/dist/dev/control-flow/hot-link.js +63 -0
- package/dist/dev/control-flow/hot-link.js.map +1 -0
- package/dist/dev/control-flow/index-list.d.ts +46 -0
- package/dist/dev/control-flow/index-list.js +30 -0
- package/dist/dev/control-flow/index-list.js.map +1 -0
- package/dist/dev/control-flow/index.d.ts +15 -0
- package/dist/dev/control-flow/lazy.d.ts +56 -0
- package/dist/dev/control-flow/lazy.js +63 -0
- package/dist/dev/control-flow/lazy.js.map +1 -0
- package/dist/dev/control-flow/no-hydration.d.ts +37 -0
- package/dist/dev/control-flow/no-hydration.js +57 -0
- package/dist/dev/control-flow/no-hydration.js.map +1 -0
- package/dist/dev/control-flow/portal.d.ts +67 -0
- package/dist/dev/control-flow/portal.js +133 -0
- package/dist/dev/control-flow/portal.js.map +1 -0
- package/dist/dev/control-flow/root-errors.d.ts +23 -0
- package/dist/dev/control-flow/root-errors.js +32 -0
- package/dist/dev/control-flow/root-errors.js.map +1 -0
- package/dist/dev/control-flow/show.d.ts +99 -0
- package/dist/dev/control-flow/show.js +17 -0
- package/dist/dev/control-flow/show.js.map +1 -0
- package/dist/dev/control-flow/suspense-list.d.ts +63 -0
- package/dist/dev/control-flow/suspense-list.js +104 -0
- package/dist/dev/control-flow/suspense-list.js.map +1 -0
- package/dist/dev/control-flow/suspense.d.ts +51 -0
- package/dist/dev/control-flow/suspense.js +101 -0
- package/dist/dev/control-flow/suspense.js.map +1 -0
- package/dist/dev/control-flow/switch.d.ts +83 -0
- package/dist/dev/control-flow/switch.js +89 -0
- package/dist/dev/control-flow/switch.js.map +1 -0
- package/dist/dev/derived.d.ts +50 -0
- package/dist/dev/derived.js +33 -0
- package/dist/dev/derived.js.map +1 -0
- package/dist/dev/element.d.ts +38 -0
- package/dist/dev/element.js +104 -0
- package/dist/dev/element.js.map +1 -0
- package/dist/dev/events.d.ts +85 -0
- package/dist/dev/events.js +264 -0
- package/dist/dev/events.js.map +1 -0
- package/dist/dev/extend.d.ts +12 -0
- package/dist/dev/extend.js +12 -0
- package/dist/dev/head/components.d.ts +135 -0
- package/dist/dev/head/components.js +169 -0
- package/dist/dev/head/components.js.map +1 -0
- package/dist/dev/head/registry.js +67 -0
- package/dist/dev/head/registry.js.map +1 -0
- package/dist/dev/head/server-head.d.ts +52 -0
- package/dist/dev/head/server-head.js +75 -0
- package/dist/dev/head/server-head.js.map +1 -0
- package/dist/dev/head/sink.js +95 -0
- package/dist/dev/head/sink.js.map +1 -0
- package/dist/dev/head/use-head.d.ts +33 -0
- package/dist/dev/head/use-head.js +83 -0
- package/dist/dev/head/use-head.js.map +1 -0
- package/dist/dev/head/validate.d.ts +83 -0
- package/dist/dev/head/validate.js +267 -0
- package/dist/dev/head/validate.js.map +1 -0
- package/dist/dev/hmr.d.ts +80 -0
- package/dist/dev/hmr.js +123 -0
- package/dist/dev/hmr.js.map +1 -0
- package/dist/dev/hydration.d.ts +59 -0
- package/dist/dev/hydration.js +119 -0
- package/dist/dev/hydration.js.map +1 -0
- package/dist/dev/index.d.ts +45 -0
- package/dist/dev/index.js +34 -0
- package/dist/dev/insert.d.ts +95 -0
- package/dist/dev/insert.js +356 -0
- package/dist/dev/insert.js.map +1 -0
- package/dist/dev/internal/claim.d.ts +104 -0
- package/dist/dev/internal/claim.js +356 -0
- package/dist/dev/internal/claim.js.map +1 -0
- package/dist/dev/internal/css-units.js +25 -0
- package/dist/dev/internal/css-units.js.map +1 -0
- package/dist/dev/internal/diagnostics.d.ts +28 -0
- package/dist/dev/internal/diagnostics.js +37 -0
- package/dist/dev/internal/diagnostics.js.map +1 -0
- package/dist/dev/internal/early-events.js +75 -0
- package/dist/dev/internal/early-events.js.map +1 -0
- package/dist/dev/internal/hydration-hooks.d.ts +41 -0
- package/dist/dev/internal/hydration-hooks.js +26 -0
- package/dist/dev/internal/hydration-hooks.js.map +1 -0
- package/dist/dev/internal/hydration-scope.d.ts +129 -0
- package/dist/dev/internal/hydration-scope.js +155 -0
- package/dist/dev/internal/hydration-scope.js.map +1 -0
- package/dist/dev/internal/names.d.ts +31 -0
- package/dist/dev/internal/names.js +34 -0
- package/dist/dev/internal/names.js.map +1 -0
- package/dist/dev/internal/portal-context.d.ts +37 -0
- package/dist/dev/internal/portal-context.js +27 -0
- package/dist/dev/internal/portal-context.js.map +1 -0
- package/dist/dev/internal/react-names.js +115 -0
- package/dist/dev/internal/react-names.js.map +1 -0
- package/dist/dev/internal/reconcile.d.ts +38 -0
- package/dist/dev/internal/reconcile.js +121 -0
- package/dist/dev/internal/reconcile.js.map +1 -0
- package/dist/dev/internal/stream-context.d.ts +45 -0
- package/dist/dev/internal/stream-context.js +22 -0
- package/dist/dev/internal/stream-context.js.map +1 -0
- package/dist/dev/jsx/aria.d.ts +70 -0
- package/dist/dev/jsx/component.d.ts +87 -0
- package/dist/dev/jsx/events.d.ts +362 -0
- package/dist/dev/jsx/global.d.ts +209 -0
- package/dist/dev/jsx/html.d.ts +877 -0
- package/dist/dev/jsx/intrinsic.d.ts +57 -0
- package/dist/dev/jsx/mathml.d.ts +184 -0
- package/dist/dev/jsx/svg.d.ts +605 -0
- package/dist/dev/jsx/types.d.ts +174 -0
- package/dist/dev/jsx-dev-runtime.d.ts +10 -0
- package/dist/dev/jsx-dev-runtime.js +0 -0
- package/dist/dev/jsx-runtime.d.ts +92 -0
- package/dist/dev/jsx-runtime.js +0 -0
- package/dist/dev/reactive.d.ts +108 -0
- package/dist/dev/reactive.js +84 -0
- package/dist/dev/reactive.js.map +1 -0
- package/dist/dev/render.d.ts +34 -0
- package/dist/dev/render.js +51 -0
- package/dist/dev/render.js.map +1 -0
- package/dist/dev/resource-hints.d.ts +143 -0
- package/dist/dev/resource-hints.js +199 -0
- package/dist/dev/resource-hints.js.map +1 -0
- package/dist/dev/select-value.d.ts +22 -0
- package/dist/dev/select-value.js +50 -0
- package/dist/dev/select-value.js.map +1 -0
- package/dist/dev/server/attributes.d.ts +31 -0
- package/dist/dev/server/attributes.js +154 -0
- package/dist/dev/server/attributes.js.map +1 -0
- package/dist/dev/server/class-style.d.ts +44 -0
- package/dist/dev/server/class-style.js +172 -0
- package/dist/dev/server/class-style.js.map +1 -0
- package/dist/dev/server/component.d.ts +40 -0
- package/dist/dev/server/component.js +71 -0
- package/dist/dev/server/component.js.map +1 -0
- package/dist/dev/server/derived.d.ts +39 -0
- package/dist/dev/server/derived.js +25 -0
- package/dist/dev/server/derived.js.map +1 -0
- package/dist/dev/server/element.d.ts +87 -0
- package/dist/dev/server/element.js +215 -0
- package/dist/dev/server/element.js.map +1 -0
- package/dist/dev/server/errors.js +25 -0
- package/dist/dev/server/errors.js.map +1 -0
- package/dist/dev/server/escape.d.ts +28 -0
- package/dist/dev/server/escape.js +118 -0
- package/dist/dev/server/escape.js.map +1 -0
- package/dist/dev/server/form-controls.d.ts +48 -0
- package/dist/dev/server/form-controls.js +192 -0
- package/dist/dev/server/form-controls.js.map +1 -0
- package/dist/dev/server/hydration-script.d.ts +63 -0
- package/dist/dev/server/hydration-script.js +58 -0
- package/dist/dev/server/hydration-script.js.map +1 -0
- package/dist/dev/server/index.d.ts +16 -0
- package/dist/dev/server/index.js +16 -0
- package/dist/dev/server/node.d.ts +11 -0
- package/dist/dev/server/node.js +20 -0
- package/dist/dev/server/node.js.map +1 -0
- package/dist/dev/server/portals.d.ts +44 -0
- package/dist/dev/server/portals.js +98 -0
- package/dist/dev/server/portals.js.map +1 -0
- package/dist/dev/server/render.d.ts +127 -0
- package/dist/dev/server/render.js +255 -0
- package/dist/dev/server/render.js.map +1 -0
- package/dist/dev/server/serialize.d.ts +43 -0
- package/dist/dev/server/serialize.js +314 -0
- package/dist/dev/server/serialize.js.map +1 -0
- package/dist/dev/server/stream.d.ts +92 -0
- package/dist/dev/server/stream.js +234 -0
- package/dist/dev/server/stream.js.map +1 -0
- package/dist/dev/server.d.ts +16 -0
- package/dist/dev/server.js +16 -0
- package/dist/dev/spread.d.ts +47 -0
- package/dist/dev/spread.js +295 -0
- package/dist/dev/spread.js.map +1 -0
- package/dist/dev/template.d.ts +24 -0
- package/dist/dev/template.js +119 -0
- package/dist/dev/template.js.map +1 -0
- package/dist/dev/view-transition.d.ts +95 -0
- package/dist/dev/view-transition.js +120 -0
- package/dist/dev/view-transition.js.map +1 -0
- package/dist/prod/attributes.js +2 -0
- package/dist/prod/attributes.js.map +1 -0
- package/dist/prod/autofocus.js +2 -0
- package/dist/prod/autofocus.js.map +1 -0
- package/dist/prod/class-style.js +2 -0
- package/dist/prod/class-style.js.map +1 -0
- package/dist/prod/component.js +2 -0
- package/dist/prod/component.js.map +1 -0
- package/dist/prod/control-flow/activity.js +2 -0
- package/dist/prod/control-flow/activity.js.map +1 -0
- package/dist/prod/control-flow/branch.js +2 -0
- package/dist/prod/control-flow/branch.js.map +1 -0
- package/dist/prod/control-flow/client-only.js +2 -0
- package/dist/prod/control-flow/client-only.js.map +1 -0
- package/dist/prod/control-flow/dynamic.js +2 -0
- package/dist/prod/control-flow/dynamic.js.map +1 -0
- package/dist/prod/control-flow/error-boundary.js +2 -0
- package/dist/prod/control-flow/error-boundary.js.map +1 -0
- package/dist/prod/control-flow/for.js +2 -0
- package/dist/prod/control-flow/for.js.map +1 -0
- package/dist/prod/control-flow/fragment.js +2 -0
- package/dist/prod/control-flow/fragment.js.map +1 -0
- package/dist/prod/control-flow/hot-link.js +2 -0
- package/dist/prod/control-flow/hot-link.js.map +1 -0
- package/dist/prod/control-flow/index-list.js +2 -0
- package/dist/prod/control-flow/index-list.js.map +1 -0
- package/dist/prod/control-flow/lazy.js +2 -0
- package/dist/prod/control-flow/lazy.js.map +1 -0
- package/dist/prod/control-flow/no-hydration.js +2 -0
- package/dist/prod/control-flow/no-hydration.js.map +1 -0
- package/dist/prod/control-flow/portal.js +2 -0
- package/dist/prod/control-flow/portal.js.map +1 -0
- package/dist/prod/control-flow/root-errors.js +2 -0
- package/dist/prod/control-flow/root-errors.js.map +1 -0
- package/dist/prod/control-flow/show.js +2 -0
- package/dist/prod/control-flow/show.js.map +1 -0
- package/dist/prod/control-flow/suspense-list.js +2 -0
- package/dist/prod/control-flow/suspense-list.js.map +1 -0
- package/dist/prod/control-flow/suspense.js +2 -0
- package/dist/prod/control-flow/suspense.js.map +1 -0
- package/dist/prod/control-flow/switch.js +2 -0
- package/dist/prod/control-flow/switch.js.map +1 -0
- package/dist/prod/derived.js +2 -0
- package/dist/prod/derived.js.map +1 -0
- package/dist/prod/element.js +2 -0
- package/dist/prod/element.js.map +1 -0
- package/dist/prod/events.js +2 -0
- package/dist/prod/events.js.map +1 -0
- package/dist/prod/extend.js +1 -0
- package/dist/prod/head/components.js +2 -0
- package/dist/prod/head/components.js.map +1 -0
- package/dist/prod/head/registry.js +2 -0
- package/dist/prod/head/registry.js.map +1 -0
- package/dist/prod/head/server-head.js +2 -0
- package/dist/prod/head/server-head.js.map +1 -0
- package/dist/prod/head/sink.js +2 -0
- package/dist/prod/head/sink.js.map +1 -0
- package/dist/prod/head/use-head.js +2 -0
- package/dist/prod/head/use-head.js.map +1 -0
- package/dist/prod/head/validate.js +2 -0
- package/dist/prod/head/validate.js.map +1 -0
- package/dist/prod/hmr.js +2 -0
- package/dist/prod/hmr.js.map +1 -0
- package/dist/prod/hydration.js +2 -0
- package/dist/prod/hydration.js.map +1 -0
- package/dist/prod/index.js +1 -0
- package/dist/prod/insert.js +2 -0
- package/dist/prod/insert.js.map +1 -0
- package/dist/prod/internal/claim.js +2 -0
- package/dist/prod/internal/claim.js.map +1 -0
- package/dist/prod/internal/css-units.js +2 -0
- package/dist/prod/internal/css-units.js.map +1 -0
- package/dist/prod/internal/diagnostics.js +2 -0
- package/dist/prod/internal/diagnostics.js.map +1 -0
- package/dist/prod/internal/early-events.js +2 -0
- package/dist/prod/internal/early-events.js.map +1 -0
- package/dist/prod/internal/hydration-hooks.js +2 -0
- package/dist/prod/internal/hydration-hooks.js.map +1 -0
- package/dist/prod/internal/hydration-scope.js +2 -0
- package/dist/prod/internal/hydration-scope.js.map +1 -0
- package/dist/prod/internal/names.js +2 -0
- package/dist/prod/internal/names.js.map +1 -0
- package/dist/prod/internal/portal-context.js +2 -0
- package/dist/prod/internal/portal-context.js.map +1 -0
- package/dist/prod/internal/react-names.js +2 -0
- package/dist/prod/internal/react-names.js.map +1 -0
- package/dist/prod/internal/reconcile.js +2 -0
- package/dist/prod/internal/reconcile.js.map +1 -0
- package/dist/prod/internal/stream-context.js +2 -0
- package/dist/prod/internal/stream-context.js.map +1 -0
- package/dist/prod/jsx-dev-runtime.js +0 -0
- package/dist/prod/jsx-runtime.js +0 -0
- package/dist/prod/reactive.js +2 -0
- package/dist/prod/reactive.js.map +1 -0
- package/dist/prod/render.js +2 -0
- package/dist/prod/render.js.map +1 -0
- package/dist/prod/resource-hints.js +2 -0
- package/dist/prod/resource-hints.js.map +1 -0
- package/dist/prod/select-value.js +2 -0
- package/dist/prod/select-value.js.map +1 -0
- package/dist/prod/server/attributes.js +2 -0
- package/dist/prod/server/attributes.js.map +1 -0
- package/dist/prod/server/class-style.js +2 -0
- package/dist/prod/server/class-style.js.map +1 -0
- package/dist/prod/server/component.js +2 -0
- package/dist/prod/server/component.js.map +1 -0
- package/dist/prod/server/derived.js +2 -0
- package/dist/prod/server/derived.js.map +1 -0
- package/dist/prod/server/element.js +2 -0
- package/dist/prod/server/element.js.map +1 -0
- package/dist/prod/server/errors.js +2 -0
- package/dist/prod/server/errors.js.map +1 -0
- package/dist/prod/server/escape.js +2 -0
- package/dist/prod/server/escape.js.map +1 -0
- package/dist/prod/server/form-controls.js +3 -0
- package/dist/prod/server/form-controls.js.map +1 -0
- package/dist/prod/server/hydration-script.js +2 -0
- package/dist/prod/server/hydration-script.js.map +1 -0
- package/dist/prod/server/index.js +1 -0
- package/dist/prod/server/node.js +2 -0
- package/dist/prod/server/node.js.map +1 -0
- package/dist/prod/server/portals.js +2 -0
- package/dist/prod/server/portals.js.map +1 -0
- package/dist/prod/server/render.js +2 -0
- package/dist/prod/server/render.js.map +1 -0
- package/dist/prod/server/serialize.js +2 -0
- package/dist/prod/server/serialize.js.map +1 -0
- package/dist/prod/server/stream.js +2 -0
- package/dist/prod/server/stream.js.map +1 -0
- package/dist/prod/server.js +1 -0
- package/dist/prod/spread.js +2 -0
- package/dist/prod/spread.js.map +1 -0
- package/dist/prod/template.js +2 -0
- package/dist/prod/template.js.map +1 -0
- package/dist/prod/view-transition.js +2 -0
- package/dist/prod/view-transition.js.map +1 -0
- package/dist/server/attributes.js +2 -0
- package/dist/server/attributes.js.map +1 -0
- package/dist/server/autofocus.js +2 -0
- package/dist/server/autofocus.js.map +1 -0
- package/dist/server/class-style.js +2 -0
- package/dist/server/class-style.js.map +1 -0
- package/dist/server/component.js +2 -0
- package/dist/server/component.js.map +1 -0
- package/dist/server/control-flow/activity.js +2 -0
- package/dist/server/control-flow/activity.js.map +1 -0
- package/dist/server/control-flow/branch.js +2 -0
- package/dist/server/control-flow/branch.js.map +1 -0
- package/dist/server/control-flow/client-only.js +2 -0
- package/dist/server/control-flow/client-only.js.map +1 -0
- package/dist/server/control-flow/dynamic.js +2 -0
- package/dist/server/control-flow/dynamic.js.map +1 -0
- package/dist/server/control-flow/error-boundary.js +2 -0
- package/dist/server/control-flow/error-boundary.js.map +1 -0
- package/dist/server/control-flow/for.js +2 -0
- package/dist/server/control-flow/for.js.map +1 -0
- package/dist/server/control-flow/fragment.js +2 -0
- package/dist/server/control-flow/fragment.js.map +1 -0
- package/dist/server/control-flow/index-list.js +2 -0
- package/dist/server/control-flow/index-list.js.map +1 -0
- package/dist/server/control-flow/lazy.js +2 -0
- package/dist/server/control-flow/lazy.js.map +1 -0
- package/dist/server/control-flow/no-hydration.js +2 -0
- package/dist/server/control-flow/no-hydration.js.map +1 -0
- package/dist/server/control-flow/portal.js +2 -0
- package/dist/server/control-flow/portal.js.map +1 -0
- package/dist/server/control-flow/root-errors.js +2 -0
- package/dist/server/control-flow/root-errors.js.map +1 -0
- package/dist/server/control-flow/show.js +2 -0
- package/dist/server/control-flow/show.js.map +1 -0
- package/dist/server/control-flow/suspense-list.js +2 -0
- package/dist/server/control-flow/suspense-list.js.map +1 -0
- package/dist/server/control-flow/suspense.js +2 -0
- package/dist/server/control-flow/suspense.js.map +1 -0
- package/dist/server/control-flow/switch.js +2 -0
- package/dist/server/control-flow/switch.js.map +1 -0
- package/dist/server/derived.js +2 -0
- package/dist/server/derived.js.map +1 -0
- package/dist/server/element.js +2 -0
- package/dist/server/element.js.map +1 -0
- package/dist/server/events.js +2 -0
- package/dist/server/events.js.map +1 -0
- package/dist/server/extend.js +1 -0
- package/dist/server/head/components.js +2 -0
- package/dist/server/head/components.js.map +1 -0
- package/dist/server/head/registry.js +2 -0
- package/dist/server/head/registry.js.map +1 -0
- package/dist/server/head/server-head.js +2 -0
- package/dist/server/head/server-head.js.map +1 -0
- package/dist/server/head/sink.js +2 -0
- package/dist/server/head/sink.js.map +1 -0
- package/dist/server/head/use-head.js +2 -0
- package/dist/server/head/use-head.js.map +1 -0
- package/dist/server/head/validate.js +2 -0
- package/dist/server/head/validate.js.map +1 -0
- package/dist/server/hydration.js +2 -0
- package/dist/server/hydration.js.map +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/insert.js +2 -0
- package/dist/server/insert.js.map +1 -0
- package/dist/server/internal/claim.js +2 -0
- package/dist/server/internal/claim.js.map +1 -0
- package/dist/server/internal/css-units.js +2 -0
- package/dist/server/internal/css-units.js.map +1 -0
- package/dist/server/internal/diagnostics.js +2 -0
- package/dist/server/internal/diagnostics.js.map +1 -0
- package/dist/server/internal/early-events.js +2 -0
- package/dist/server/internal/early-events.js.map +1 -0
- package/dist/server/internal/hydration-hooks.js +2 -0
- package/dist/server/internal/hydration-hooks.js.map +1 -0
- package/dist/server/internal/hydration-scope.js +2 -0
- package/dist/server/internal/hydration-scope.js.map +1 -0
- package/dist/server/internal/names.js +2 -0
- package/dist/server/internal/names.js.map +1 -0
- package/dist/server/internal/portal-context.js +2 -0
- package/dist/server/internal/portal-context.js.map +1 -0
- package/dist/server/internal/react-names.js +2 -0
- package/dist/server/internal/react-names.js.map +1 -0
- package/dist/server/internal/reconcile.js +2 -0
- package/dist/server/internal/reconcile.js.map +1 -0
- package/dist/server/internal/stream-context.js +2 -0
- package/dist/server/internal/stream-context.js.map +1 -0
- package/dist/server/reactive.js +2 -0
- package/dist/server/reactive.js.map +1 -0
- package/dist/server/render.js +2 -0
- package/dist/server/render.js.map +1 -0
- package/dist/server/resource-hints.js +2 -0
- package/dist/server/resource-hints.js.map +1 -0
- package/dist/server/select-value.js +2 -0
- package/dist/server/select-value.js.map +1 -0
- package/dist/server/server/attributes.js +2 -0
- package/dist/server/server/attributes.js.map +1 -0
- package/dist/server/server/class-style.js +2 -0
- package/dist/server/server/class-style.js.map +1 -0
- package/dist/server/server/component.js +2 -0
- package/dist/server/server/component.js.map +1 -0
- package/dist/server/server/derived.js +2 -0
- package/dist/server/server/derived.js.map +1 -0
- package/dist/server/server/element.js +2 -0
- package/dist/server/server/element.js.map +1 -0
- package/dist/server/server/errors.js +2 -0
- package/dist/server/server/errors.js.map +1 -0
- package/dist/server/server/escape.js +2 -0
- package/dist/server/server/escape.js.map +1 -0
- package/dist/server/server/form-controls.js +3 -0
- package/dist/server/server/form-controls.js.map +1 -0
- package/dist/server/server/hydration-script.js +2 -0
- package/dist/server/server/hydration-script.js.map +1 -0
- package/dist/server/server/index.js +1 -0
- package/dist/server/server/node.js +2 -0
- package/dist/server/server/node.js.map +1 -0
- package/dist/server/server/portals.js +2 -0
- package/dist/server/server/portals.js.map +1 -0
- package/dist/server/server/render.js +2 -0
- package/dist/server/server/render.js.map +1 -0
- package/dist/server/server/serialize.js +2 -0
- package/dist/server/server/serialize.js.map +1 -0
- package/dist/server/server/stream.js +2 -0
- package/dist/server/server/stream.js.map +1 -0
- package/dist/server/server.js +1 -0
- package/dist/server/spread.js +2 -0
- package/dist/server/spread.js.map +1 -0
- package/dist/server/template.js +2 -0
- package/dist/server/template.js.map +1 -0
- package/dist/server/view-transition.js +2 -0
- package/dist/server/view-transition.js.map +1 -0
- package/dist/server-dev/attributes.js +195 -0
- package/dist/server-dev/attributes.js.map +1 -0
- package/dist/server-dev/autofocus.js +44 -0
- package/dist/server-dev/autofocus.js.map +1 -0
- package/dist/server-dev/class-style.js +196 -0
- package/dist/server-dev/class-style.js.map +1 -0
- package/dist/server-dev/component.js +41 -0
- package/dist/server-dev/component.js.map +1 -0
- package/dist/server-dev/control-flow/activity.js +40 -0
- package/dist/server-dev/control-flow/activity.js.map +1 -0
- package/dist/server-dev/control-flow/branch.js +103 -0
- package/dist/server-dev/control-flow/branch.js.map +1 -0
- package/dist/server-dev/control-flow/client-only.js +49 -0
- package/dist/server-dev/control-flow/client-only.js.map +1 -0
- package/dist/server-dev/control-flow/dynamic.js +105 -0
- package/dist/server-dev/control-flow/dynamic.js.map +1 -0
- package/dist/server-dev/control-flow/error-boundary.js +114 -0
- package/dist/server-dev/control-flow/error-boundary.js.map +1 -0
- package/dist/server-dev/control-flow/for.js +22 -0
- package/dist/server-dev/control-flow/for.js.map +1 -0
- package/dist/server-dev/control-flow/fragment.js +30 -0
- package/dist/server-dev/control-flow/fragment.js.map +1 -0
- package/dist/server-dev/control-flow/hot-link.js +56 -0
- package/dist/server-dev/control-flow/hot-link.js.map +1 -0
- package/dist/server-dev/control-flow/index-list.js +30 -0
- package/dist/server-dev/control-flow/index-list.js.map +1 -0
- package/dist/server-dev/control-flow/lazy.js +63 -0
- package/dist/server-dev/control-flow/lazy.js.map +1 -0
- package/dist/server-dev/control-flow/no-hydration.js +39 -0
- package/dist/server-dev/control-flow/no-hydration.js.map +1 -0
- package/dist/server-dev/control-flow/portal.js +133 -0
- package/dist/server-dev/control-flow/portal.js.map +1 -0
- package/dist/server-dev/control-flow/root-errors.js +32 -0
- package/dist/server-dev/control-flow/root-errors.js.map +1 -0
- package/dist/server-dev/control-flow/show.js +17 -0
- package/dist/server-dev/control-flow/show.js.map +1 -0
- package/dist/server-dev/control-flow/suspense-list.js +99 -0
- package/dist/server-dev/control-flow/suspense-list.js.map +1 -0
- package/dist/server-dev/control-flow/suspense.js +118 -0
- package/dist/server-dev/control-flow/suspense.js.map +1 -0
- package/dist/server-dev/control-flow/switch.js +89 -0
- package/dist/server-dev/control-flow/switch.js.map +1 -0
- package/dist/server-dev/derived.js +33 -0
- package/dist/server-dev/derived.js.map +1 -0
- package/dist/server-dev/element.js +65 -0
- package/dist/server-dev/element.js.map +1 -0
- package/dist/server-dev/events.js +264 -0
- package/dist/server-dev/events.js.map +1 -0
- package/dist/server-dev/extend.js +12 -0
- package/dist/server-dev/head/components.js +169 -0
- package/dist/server-dev/head/components.js.map +1 -0
- package/dist/server-dev/head/registry.js +67 -0
- package/dist/server-dev/head/registry.js.map +1 -0
- package/dist/server-dev/head/server-head.js +75 -0
- package/dist/server-dev/head/server-head.js.map +1 -0
- package/dist/server-dev/head/sink.js +95 -0
- package/dist/server-dev/head/sink.js.map +1 -0
- package/dist/server-dev/head/use-head.js +83 -0
- package/dist/server-dev/head/use-head.js.map +1 -0
- package/dist/server-dev/head/validate.js +267 -0
- package/dist/server-dev/head/validate.js.map +1 -0
- package/dist/server-dev/hydration.js +119 -0
- package/dist/server-dev/hydration.js.map +1 -0
- package/dist/server-dev/index.js +34 -0
- package/dist/server-dev/insert.js +356 -0
- package/dist/server-dev/insert.js.map +1 -0
- package/dist/server-dev/internal/claim.js +356 -0
- package/dist/server-dev/internal/claim.js.map +1 -0
- package/dist/server-dev/internal/css-units.js +25 -0
- package/dist/server-dev/internal/css-units.js.map +1 -0
- package/dist/server-dev/internal/diagnostics.js +37 -0
- package/dist/server-dev/internal/diagnostics.js.map +1 -0
- package/dist/server-dev/internal/early-events.js +75 -0
- package/dist/server-dev/internal/early-events.js.map +1 -0
- package/dist/server-dev/internal/hydration-hooks.js +26 -0
- package/dist/server-dev/internal/hydration-hooks.js.map +1 -0
- package/dist/server-dev/internal/hydration-scope.js +155 -0
- package/dist/server-dev/internal/hydration-scope.js.map +1 -0
- package/dist/server-dev/internal/names.js +34 -0
- package/dist/server-dev/internal/names.js.map +1 -0
- package/dist/server-dev/internal/portal-context.js +27 -0
- package/dist/server-dev/internal/portal-context.js.map +1 -0
- package/dist/server-dev/internal/react-names.js +115 -0
- package/dist/server-dev/internal/react-names.js.map +1 -0
- package/dist/server-dev/internal/reconcile.js +121 -0
- package/dist/server-dev/internal/reconcile.js.map +1 -0
- package/dist/server-dev/internal/stream-context.js +22 -0
- package/dist/server-dev/internal/stream-context.js.map +1 -0
- package/dist/server-dev/reactive.js +84 -0
- package/dist/server-dev/reactive.js.map +1 -0
- package/dist/server-dev/render.js +51 -0
- package/dist/server-dev/render.js.map +1 -0
- package/dist/server-dev/resource-hints.js +199 -0
- package/dist/server-dev/resource-hints.js.map +1 -0
- package/dist/server-dev/select-value.js +50 -0
- package/dist/server-dev/select-value.js.map +1 -0
- package/dist/server-dev/server/attributes.js +154 -0
- package/dist/server-dev/server/attributes.js.map +1 -0
- package/dist/server-dev/server/class-style.js +172 -0
- package/dist/server-dev/server/class-style.js.map +1 -0
- package/dist/server-dev/server/component.js +71 -0
- package/dist/server-dev/server/component.js.map +1 -0
- package/dist/server-dev/server/derived.js +25 -0
- package/dist/server-dev/server/derived.js.map +1 -0
- package/dist/server-dev/server/element.js +215 -0
- package/dist/server-dev/server/element.js.map +1 -0
- package/dist/server-dev/server/errors.js +25 -0
- package/dist/server-dev/server/errors.js.map +1 -0
- package/dist/server-dev/server/escape.js +118 -0
- package/dist/server-dev/server/escape.js.map +1 -0
- package/dist/server-dev/server/form-controls.js +192 -0
- package/dist/server-dev/server/form-controls.js.map +1 -0
- package/dist/server-dev/server/hydration-script.js +58 -0
- package/dist/server-dev/server/hydration-script.js.map +1 -0
- package/dist/server-dev/server/index.js +16 -0
- package/dist/server-dev/server/node.js +20 -0
- package/dist/server-dev/server/node.js.map +1 -0
- package/dist/server-dev/server/portals.js +98 -0
- package/dist/server-dev/server/portals.js.map +1 -0
- package/dist/server-dev/server/render.js +255 -0
- package/dist/server-dev/server/render.js.map +1 -0
- package/dist/server-dev/server/serialize.js +314 -0
- package/dist/server-dev/server/serialize.js.map +1 -0
- package/dist/server-dev/server/stream.js +234 -0
- package/dist/server-dev/server/stream.js.map +1 -0
- package/dist/server-dev/server.js +16 -0
- package/dist/server-dev/spread.js +295 -0
- package/dist/server-dev/spread.js.map +1 -0
- package/dist/server-dev/template.js +119 -0
- package/dist/server-dev/template.js.map +1 -0
- package/dist/server-dev/view-transition.js +89 -0
- package/dist/server-dev/view-transition.js.map +1 -0
- package/package.json +136 -4
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { createRootScope, resourceKey, withScope } from "./internal/hydration-scope.js";
|
|
2
|
+
import { beginClaiming, claimElement, claimPortal, endClaiming, isClaiming, liftedRegions, releaseUnclaimedPortals, takeRegion, withoutClaiming } from "./internal/claim.js";
|
|
3
|
+
import { claims } from "./internal/hydration-hooks.js";
|
|
4
|
+
import { bindRegion, createRegion, removeRegion } from "./insert.js";
|
|
5
|
+
import { attachRootErrors } from "./control-flow/root-errors.js";
|
|
6
|
+
import { replayEarlyEvents } from "./internal/early-events.js";
|
|
7
|
+
import { ResourceCacheContext, batch, createRoot, flushSync, runWithOwner, untrack } from "@shadow-js/core";
|
|
8
|
+
import { withHydration } from "@shadow-js/core/extend";
|
|
9
|
+
// src/hydration.ts
|
|
10
|
+
function dataCache(data) {
|
|
11
|
+
const used = /* @__PURE__ */ new Set();
|
|
12
|
+
return {
|
|
13
|
+
key: resourceKey,
|
|
14
|
+
read(key) {
|
|
15
|
+
if (used.has(key) || !Object.hasOwn(data, key)) return void 0;
|
|
16
|
+
used.add(key);
|
|
17
|
+
return { value: data[key] };
|
|
18
|
+
},
|
|
19
|
+
track() {}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Removes marker comments the pass did not claim, so the live DOM never keeps any, and the server
|
|
24
|
+
* blocks of portals the client did not render (they would show content the client does not have).
|
|
25
|
+
*/
|
|
26
|
+
function stripLeftovers(container) {
|
|
27
|
+
const doc = container instanceof Document ? container : container.ownerDocument;
|
|
28
|
+
if (doc === null) return;
|
|
29
|
+
if (doc.body !== null) releaseUnclaimedPortals(doc.body);
|
|
30
|
+
const walker = doc.createTreeWalker(container, NodeFilter.SHOW_COMMENT);
|
|
31
|
+
const stale = [];
|
|
32
|
+
while (walker.nextNode()) {
|
|
33
|
+
const comment = walker.currentNode;
|
|
34
|
+
if (comment.data === "[" || comment.data === "]") stale.push(comment);
|
|
35
|
+
}
|
|
36
|
+
for (const comment of stale) comment.remove();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Attaches the application to HTML the server already rendered into `container`. Elements are
|
|
40
|
+
* claimed by their `data-hk` keys instead of created, so the DOM is not rebuilt and nodes keep
|
|
41
|
+
* their identity. Event handlers and reactive bindings are attached; markers are removed. Parts the
|
|
42
|
+
* server and client disagree on are repaired by reconciliation, never left half hydrated.
|
|
43
|
+
*
|
|
44
|
+
* @param code Runs once, untracked, and builds the same component tree the server rendered.
|
|
45
|
+
* @param container Element or Document that holds the server markup.
|
|
46
|
+
* @param options `renderId` (must match the server), the server's resource `data`, an `owner`, and
|
|
47
|
+
* the error reporters. Undefined uses the defaults.
|
|
48
|
+
* @returns A dispose function that stops the hydrated root and removes its nodes. Safe to call more
|
|
49
|
+
* than once.
|
|
50
|
+
* @throws Error (production message `SHADOW_HYDRATE_RUNNING`) when called while another hydration
|
|
51
|
+
* pass is in progress.
|
|
52
|
+
* @example
|
|
53
|
+
* import { createComponent, hydrate } from "@shadow-js/web";
|
|
54
|
+
*
|
|
55
|
+
* function App() {
|
|
56
|
+
* return "Hello";
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* const container = document.getElementById("app") as Element;
|
|
60
|
+
* const data = JSON.parse(document.getElementById("data")?.textContent ?? "{}") as Record<
|
|
61
|
+
* string,
|
|
62
|
+
* unknown
|
|
63
|
+
* >;
|
|
64
|
+
* const dispose = hydrate(() => createComponent(App, {}), container, { data });
|
|
65
|
+
* @see render
|
|
66
|
+
* @since 1.0.0
|
|
67
|
+
*/
|
|
68
|
+
function hydrate(code, container, options = {}) {
|
|
69
|
+
if (isClaiming()) throw new Error("hydrate(): a hydration pass is already running.");
|
|
70
|
+
const registry = /* @__PURE__ */ new Map();
|
|
71
|
+
const roots = container instanceof Element ? [container] : [];
|
|
72
|
+
for (const element of [...roots, ...Array.from(container.querySelectorAll("[data-hk]"))]) {
|
|
73
|
+
const key = element.getAttribute("data-hk");
|
|
74
|
+
if (key !== null) registry.set(key, element);
|
|
75
|
+
}
|
|
76
|
+
beginClaiming(registry, options.onRecoverableError);
|
|
77
|
+
const passClaims = {
|
|
78
|
+
claimElement,
|
|
79
|
+
takeRegion,
|
|
80
|
+
liftedRegions,
|
|
81
|
+
claimPortal,
|
|
82
|
+
isClaiming,
|
|
83
|
+
withoutClaiming
|
|
84
|
+
};
|
|
85
|
+
const previousClaims = claims.current;
|
|
86
|
+
claims.current = passClaims;
|
|
87
|
+
const cache = dataCache(options.data ?? {});
|
|
88
|
+
const region = createRegion(container, null, Array.from(container.childNodes));
|
|
89
|
+
let stop;
|
|
90
|
+
try {
|
|
91
|
+
stop = withHydration(() => batch(() => withScope(createRootScope(options.renderId), () => runWithOwner(options.owner ?? null, () => createRoot((dispose) => {
|
|
92
|
+
attachRootErrors(options);
|
|
93
|
+
ResourceCacheContext({
|
|
94
|
+
value: cache,
|
|
95
|
+
get children() {
|
|
96
|
+
bindRegion(region, untrack(code));
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return dispose;
|
|
101
|
+
})))));
|
|
102
|
+
flushSync();
|
|
103
|
+
} finally {
|
|
104
|
+
endClaiming();
|
|
105
|
+
claims.current = previousClaims;
|
|
106
|
+
}
|
|
107
|
+
replayEarlyEvents();
|
|
108
|
+
stripLeftovers(container);
|
|
109
|
+
let disposed = false;
|
|
110
|
+
return () => {
|
|
111
|
+
if (disposed) return;
|
|
112
|
+
disposed = true;
|
|
113
|
+
stop();
|
|
114
|
+
removeRegion(region);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export { hydrate };
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=hydration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration.js","names":[],"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":";;;;;;;;;AAsDA,SAAS,UAAU,MAA8C;CAC/D,MAAM,uBAAO,IAAI,IAAY;CAC7B,OAAO;EACL,KAAK;EACL,KAAK,KAAK;GACR,IAAI,KAAK,IAAI,GAAG,KAAK,CAAC,OAAO,OAAO,MAAM,GAAG,GAAG,OAAO,KAAA;GACvD,KAAK,IAAI,GAAG;GACZ,OAAO,EAAE,OAAO,KAAK,KAAK;EAC5B;EACA,QAAQ,CAER;CACF;AACF;;;;;AAMA,SAAS,eAAe,WAAuB;CAC7C,MAAM,MAAM,qBAAqB,WAAW,YAAY,UAAU;CAClE,IAAI,QAAQ,MAAM;CAClB,IAAI,IAAI,SAAS,MAAM,wBAAwB,IAAI,IAAI;CACvD,MAAM,SAAS,IAAI,iBAAiB,WAAW,WAAW,YAAY;CACtE,MAAM,QAAmB,CAAC;CAC1B,OAAO,OAAO,SAAS,GAAG;EACxB,MAAM,UAAU,OAAO;EACvB,IAAI,QAAQ,SAAS,OAAO,QAAQ,SAAS,KAAK,MAAM,KAAK,OAAO;CACtE;CACA,KAAK,MAAM,WAAW,OAAO,QAAQ,OAAO;AAC9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,QACd,MACA,WACA,UAA0B,CAAC,GACf;CACZ,IAAI,WAAW,GACb,MAAM,IAAI,MACE,iDACZ;CACF,MAAM,2BAAW,IAAI,IAAqB;CAC1C,MAAM,QAAmB,qBAAqB,UAAU,CAAC,SAAS,IAAI,CAAC;CACvE,KAAK,MAAM,WAAW,CAAC,GAAG,OAAO,GAAG,MAAM,KAAK,UAAU,iBAAiB,WAAW,CAAC,CAAC,GAAG;EACxF,MAAM,MAAM,QAAQ,aAAa,SAAS;EAC1C,IAAI,QAAQ,MAAM,SAAS,IAAI,KAAK,OAAO;CAC7C;CACA,cAAc,UAAU,QAAQ,kBAAkB;CAElD,MAAM,aAAqB;EACzB;EACA;EACA;EACA;EACA;EACA;CACF;CACA,MAAM,iBAAiB,OAAO;CAC9B,OAAO,UAAU;CACjB,MAAM,QAAQ,UAAU,QAAQ,QAAQ,CAAC,CAAC;CAC1C,MAAM,SAAS,aAAa,WAAW,MAAM,MAAM,KAAK,UAAU,UAAU,CAAC;CAC7E,IAAI;CACJ,IAAI;EAMF,OAAO,oBACL,YACE,UAAU,gBAAgB,QAAQ,QAAQ,SACxC,aAAa,QAAQ,SAAS,YAC5B,YAAY,YAAY;GACtB,iBAAiB,OAAO;GACxB,qBAAqB;IACnB,OAAO;IACP,IAAI,WAAW;KACb,WAAW,QAAQ,QAAQ,IAAI,CAAC;KAChC,OAAO;IACT;GACF,CAAC;GACD,OAAO;EACT,CAAC,CACH,CACF,CACF,CACF;EACA,UAAU;CACZ,UAAU;EACR,YAAY;EACZ,OAAO,UAAU;CACnB;CACA,kBAAkB;CAClB,eAAe,SAAS;CACxB,IAAI,WAAW;CACf,aAAa;EACX,IAAI,UAAU;EACd,WAAW;EACX,KAAK;EACL,aAAa,MAAM;CACrB;AACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { setAttribute, setAttributeNS, setBoolAttribute } from "./attributes.js";
|
|
2
|
+
import { element } from "./element.js";
|
|
3
|
+
import { anchor, insert } from "./insert.js";
|
|
4
|
+
import { autoFocus } from "./autofocus.js";
|
|
5
|
+
import { classList, className, setStyleProperty, style } from "./class-style.js";
|
|
6
|
+
import { createComponent } from "./component.js";
|
|
7
|
+
import { Activity, ActivityMode, ActivityProps } from "./control-flow/activity.js";
|
|
8
|
+
import { Booleanish, CSSProperties, ClassValue, JsxChild, Maybe, MaybeAccessor, Ref, TextChild } from "./jsx/types.js";
|
|
9
|
+
import { ClientOnly, ClientOnlyProps } from "./control-flow/client-only.js";
|
|
10
|
+
import { Dynamic, DynamicProps, createDynamic } from "./control-flow/dynamic.js";
|
|
11
|
+
import { ErrorBoundary, ErrorBoundaryLooseProps, ErrorBoundaryProps } from "./control-flow/error-boundary.js";
|
|
12
|
+
import { For, ForKeyedProps, ForProps, ForUnkeyedProps } from "./control-flow/for.js";
|
|
13
|
+
import { Fragment, FragmentProps } from "./control-flow/fragment.js";
|
|
14
|
+
import { Index, IndexProps } from "./control-flow/index-list.js";
|
|
15
|
+
import { LazyComponent, lazy } from "./control-flow/lazy.js";
|
|
16
|
+
import { NoHydration, NoHydrationProps } from "./control-flow/no-hydration.js";
|
|
17
|
+
import { Portal, PortalProps } from "./control-flow/portal.js";
|
|
18
|
+
import { Show, ShowLooseProps, ShowProps } from "./control-flow/show.js";
|
|
19
|
+
import { Suspense, SuspenseProps } from "./control-flow/suspense.js";
|
|
20
|
+
import { SuspenseList, SuspenseListProps } from "./control-flow/suspense-list.js";
|
|
21
|
+
import { Match, MatchProps, Switch, SwitchProps } from "./control-flow/switch.js";
|
|
22
|
+
import "./control-flow/index.js";
|
|
23
|
+
import { Derived, derived } from "./derived.js";
|
|
24
|
+
import { addEventListener, chainEvents, clearDelegatedEvents, delegateEvents } from "./events.js";
|
|
25
|
+
import { Base, HeadAttributeProps, Link, Meta, Style, StyleProps, Title, TitleProps } from "./head/components.js";
|
|
26
|
+
import { HeadAttributeValue, HeadInput, HeadTag, HeadTagName } from "./head/validate.js";
|
|
27
|
+
import { useHead } from "./head/use-head.js";
|
|
28
|
+
import { HydrateOptions, hydrate } from "./hydration.js";
|
|
29
|
+
import { Component, FlowComponent, ParentComponent, ParentProps, VoidComponent, VoidProps } from "./jsx/component.js";
|
|
30
|
+
import { BoundEventHandler, EventHandler, EventHandlerProp, ListenerObject } from "./jsx/events.js";
|
|
31
|
+
import { AriaAttributes, AriaRole } from "./jsx/aria.js";
|
|
32
|
+
import { HTMLIntrinsicElements } from "./jsx/html.js";
|
|
33
|
+
import { MathMLIntrinsicElements } from "./jsx/mathml.js";
|
|
34
|
+
import { SVGIntrinsicElements } from "./jsx/svg.js";
|
|
35
|
+
import { CustomElementProps, IntrinsicElementMap } from "./jsx/intrinsic.js";
|
|
36
|
+
import { ComponentProps, CustomEvents, Directives, JSX, ValidComponent } from "./jsx-runtime.js";
|
|
37
|
+
import { effect, memo, refTo, use } from "./reactive.js";
|
|
38
|
+
import { render } from "./render.js";
|
|
39
|
+
import { CrossOriginOptions, PreinitOptions, PreloadOptions, preconnect, prefetchDNS, preinit, preinitModule, preload, preloadModule } from "./resource-hints.js";
|
|
40
|
+
import { setSelectValue } from "./select-value.js";
|
|
41
|
+
import { spread } from "./spread.js";
|
|
42
|
+
import { template } from "./template.js";
|
|
43
|
+
import { ViewTransition, ViewTransitionOptions, ViewTransitionProps, startViewTransition } from "./view-transition.js";
|
|
44
|
+
import { isDev, isServer, mergeProps } from "@shadow-js/core";
|
|
45
|
+
export { Activity, type ActivityMode, type ActivityProps, type AriaAttributes, type AriaRole, Base, type Booleanish, type BoundEventHandler, type CSSProperties, type ClassValue, ClientOnly, type ClientOnlyProps, type Component, type ComponentProps, type CrossOriginOptions, type CustomElementProps, type CustomEvents, type Derived, type Directives, Dynamic, type DynamicProps, ErrorBoundary, type ErrorBoundaryLooseProps, type ErrorBoundaryProps, type EventHandler, type EventHandlerProp, type FlowComponent, For, type ForKeyedProps, type ForProps, type ForUnkeyedProps, Fragment, type FragmentProps, type HTMLIntrinsicElements, type HeadAttributeProps, type HeadAttributeValue, type HeadInput, type HeadTag, type HeadTagName, type HydrateOptions, Index, type IndexProps, type IntrinsicElementMap, type JSX, type JsxChild, type LazyComponent, Link, type ListenerObject, Match, type MatchProps, type MathMLIntrinsicElements, type Maybe, type MaybeAccessor, Meta, NoHydration, type NoHydrationProps, type ParentComponent, type ParentProps, Portal, type PortalProps, type PreinitOptions, type PreloadOptions, type Ref, type SVGIntrinsicElements, Show, type ShowLooseProps, type ShowProps, Style, type StyleProps, Suspense, SuspenseList, type SuspenseListProps, type SuspenseProps, Switch, type SwitchProps, type TextChild, Title, type TitleProps, type ValidComponent, ViewTransition, type ViewTransitionOptions, type ViewTransitionProps, type VoidComponent, type VoidProps, addEventListener, anchor, autoFocus, chainEvents, classList, className, clearDelegatedEvents, createComponent, createDynamic, delegateEvents, derived, effect, element, hydrate, insert, isDev, isServer, lazy, memo, mergeProps, preconnect, prefetchDNS, preinit, preinitModule, preload, preloadModule, refTo, render, setAttribute, setAttributeNS, setBoolAttribute, setSelectValue, setStyleProperty, spread, startViewTransition, style, template, use, useHead };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { setAttribute, setAttributeNS, setBoolAttribute } from "./attributes.js";
|
|
2
|
+
import { autoFocus } from "./autofocus.js";
|
|
3
|
+
import { classList, className, setStyleProperty, style } from "./class-style.js";
|
|
4
|
+
import { createComponent } from "./component.js";
|
|
5
|
+
import { Activity } from "./control-flow/activity.js";
|
|
6
|
+
import { Show } from "./control-flow/show.js";
|
|
7
|
+
import { ClientOnly } from "./control-flow/client-only.js";
|
|
8
|
+
import { anchor, insert } from "./insert.js";
|
|
9
|
+
import { element } from "./element.js";
|
|
10
|
+
import { addEventListener, chainEvents, clearDelegatedEvents, delegateEvents } from "./events.js";
|
|
11
|
+
import { setSelectValue } from "./select-value.js";
|
|
12
|
+
import { spread } from "./spread.js";
|
|
13
|
+
import { Dynamic, createDynamic } from "./control-flow/dynamic.js";
|
|
14
|
+
import { ErrorBoundary } from "./control-flow/error-boundary.js";
|
|
15
|
+
import { For } from "./control-flow/for.js";
|
|
16
|
+
import { Fragment } from "./control-flow/fragment.js";
|
|
17
|
+
import { Index } from "./control-flow/index-list.js";
|
|
18
|
+
import { lazy } from "./control-flow/lazy.js";
|
|
19
|
+
import { NoHydration } from "./control-flow/no-hydration.js";
|
|
20
|
+
import { Portal } from "./control-flow/portal.js";
|
|
21
|
+
import { SuspenseList } from "./control-flow/suspense-list.js";
|
|
22
|
+
import { Suspense } from "./control-flow/suspense.js";
|
|
23
|
+
import { Match, Switch } from "./control-flow/switch.js";
|
|
24
|
+
import { derived } from "./derived.js";
|
|
25
|
+
import { useHead } from "./head/use-head.js";
|
|
26
|
+
import { Base, Link, Meta, Style, Title } from "./head/components.js";
|
|
27
|
+
import { hydrate } from "./hydration.js";
|
|
28
|
+
import { effect, memo, refTo, use } from "./reactive.js";
|
|
29
|
+
import { render } from "./render.js";
|
|
30
|
+
import { preconnect, prefetchDNS, preinit, preinitModule, preload, preloadModule } from "./resource-hints.js";
|
|
31
|
+
import { template } from "./template.js";
|
|
32
|
+
import { ViewTransition, startViewTransition } from "./view-transition.js";
|
|
33
|
+
import { isDev, isServer, mergeProps } from "@shadow-js/core";
|
|
34
|
+
export { Activity, Base, ClientOnly, Dynamic, ErrorBoundary, For, Fragment, Index, Link, Match, Meta, NoHydration, Portal, Show, Style, Suspense, SuspenseList, Switch, Title, ViewTransition, addEventListener, anchor, autoFocus, chainEvents, classList, className, clearDelegatedEvents, createComponent, createDynamic, delegateEvents, derived, effect, element, hydrate, insert, isDev, isServer, lazy, memo, mergeProps, preconnect, prefetchDNS, preinit, preinitModule, preload, preloadModule, refTo, render, setAttribute, setAttributeNS, setBoolAttribute, setSelectValue, setStyleProperty, spread, startViewTransition, style, template, use, useHead };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State of one dynamic child region. `nodes` are the DOM nodes the region owns, in order. When
|
|
3
|
+
* `anchor` is set, content goes before it. Without one, an empty region is placed after `marker`
|
|
4
|
+
* (the node that preceded it), so it keeps its position while it is empty.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export interface Region {
|
|
8
|
+
readonly parent: Node;
|
|
9
|
+
readonly anchor: Node | null;
|
|
10
|
+
marker: Node | null;
|
|
11
|
+
nodes: Node[];
|
|
12
|
+
/**
|
|
13
|
+
* Text nodes this region created or adopted; only these may be reused by string updates. Null for none, the node
|
|
14
|
+
* itself for one (the usual region: a single dynamic text), a Set for more, so most regions allocate no Set.
|
|
15
|
+
*/
|
|
16
|
+
texts: Text | Set<Text> | null;
|
|
17
|
+
/**
|
|
18
|
+
* Development only: the server nodes a hydration pass handed this region, kept until its first
|
|
19
|
+
* commit compares their text with the value (`checkClaimedText`).
|
|
20
|
+
*/
|
|
21
|
+
claimed?: readonly Node[] | undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates the state of a region in `parent`. `anchorNode` (null to append) and `initial` (nodes
|
|
25
|
+
* already in the DOM, from hydration or splitText) are both optional.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export declare function createRegion(parent: Node, anchorNode: Node | null, initial: unknown): Region;
|
|
29
|
+
/**
|
|
30
|
+
* Keeps a region in sync with `value`. A value that is or contains a function (an accessor, or an
|
|
31
|
+
* array with accessor members) runs inside a render effect, so its reads are tracked. Anything
|
|
32
|
+
* else is inserted once.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export declare function bindRegion(region: Region, value: unknown): unknown;
|
|
36
|
+
/**
|
|
37
|
+
* Removes a region's nodes from its parent. Anchors and nodes that were moved elsewhere are not
|
|
38
|
+
* touched.
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export declare function removeRegion(region: Region): void;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a text anchor: an empty Text node placed before `before` (appended when null). Use it as
|
|
44
|
+
* the stable insertion point between two dynamic regions; it is never removed by the runtime.
|
|
45
|
+
*
|
|
46
|
+
* @param parent Node that receives the anchor.
|
|
47
|
+
* @param before Node the anchor goes before, or null to append.
|
|
48
|
+
* @returns The new empty Text node.
|
|
49
|
+
* @example
|
|
50
|
+
* import { anchor, insert } from "@shadow-js/web";
|
|
51
|
+
*
|
|
52
|
+
* const list = document.createElement("ul");
|
|
53
|
+
* const slot = anchor(list, null);
|
|
54
|
+
* insert(list, "first", slot); // goes before the anchor
|
|
55
|
+
* @see insert
|
|
56
|
+
* @since 1.0.0
|
|
57
|
+
*/
|
|
58
|
+
export declare function anchor(parent: Node, before: Node | null): Text;
|
|
59
|
+
/**
|
|
60
|
+
* Reactive child insertion: keeps the content of a region in sync with `value`.
|
|
61
|
+
*
|
|
62
|
+
* - A function is an accessor, wrapped in a render effect; it re-runs when its dependencies change.
|
|
63
|
+
* - `null`, `undefined`, booleans render nothing. Strings and numbers become one Text node, reused
|
|
64
|
+
* when the region already holds one. A Node is inserted itself. A DocumentFragment inserts a
|
|
65
|
+
* snapshot of its children. Arrays are flattened, nested arrays included.
|
|
66
|
+
* - Content goes before `anchorNode`, or at the end when it is null or omitted.
|
|
67
|
+
* - Arrays are reconciled in place: nodes that remain are never removed and re-added.
|
|
68
|
+
* - `initial` lists nodes already in the DOM (from hydration or splitText) so nothing is recreated.
|
|
69
|
+
* - During `hydrate()`, a region that adopted server text is compared with its first commit: in
|
|
70
|
+
* development, different text warns `HYDRATION_TEXT_MISMATCH` (on the console and in devtools) and
|
|
71
|
+
* the region shows the value computed by the client.
|
|
72
|
+
*
|
|
73
|
+
* @param parent Node that holds the region.
|
|
74
|
+
* @param value The value or an accessor returning it.
|
|
75
|
+
* @param anchorNode Node the content goes before; null or omitted appends.
|
|
76
|
+
* @param initial Nodes already in place for this region. Undefined adopts the server's nodes while
|
|
77
|
+
* hydrating and starts empty otherwise.
|
|
78
|
+
* @returns The value as accepted (a fragment yields the array of its nodes).
|
|
79
|
+
* @throws TypeError (production message `SHADOW_INSERT_CYCLE`) when an array contains itself, and
|
|
80
|
+
* (`SHADOW_INSERT_DEPTH`) when an accessor returns accessors more than 10,000 levels deep. When the
|
|
81
|
+
* value is reactive, the error is raised inside its render effect and goes to the owner's error
|
|
82
|
+
* handler, like any effect error.
|
|
83
|
+
* @example
|
|
84
|
+
* import { useSignal } from "@shadow-js/core";
|
|
85
|
+
* import { anchor, insert } from "@shadow-js/web";
|
|
86
|
+
*
|
|
87
|
+
* const list = document.createElement("ul");
|
|
88
|
+
* const end = anchor(list, null);
|
|
89
|
+
* const [items] = useSignal(["a", "b"]);
|
|
90
|
+
* insert(list, () => items().map((name) => document.createTextNode(name)), end);
|
|
91
|
+
* @see anchor
|
|
92
|
+
* @since 1.0.0
|
|
93
|
+
*/
|
|
94
|
+
export declare function insert(parent: Node, value: unknown, anchorNode?: Node | null, initial?: unknown): unknown;
|
|
95
|
+
//# sourceMappingURL=insert.d.ts.map
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { checkClaimedText } from "./internal/claim.js";
|
|
2
|
+
import { claims } from "./internal/hydration-hooks.js";
|
|
3
|
+
import { reconcileNodes } from "./internal/reconcile.js";
|
|
4
|
+
import { useRenderEffect } from "@shadow-js/core";
|
|
5
|
+
import { createComputation, currentOwner, disposeOwner, readComputation } from "@shadow-js/core/extend";
|
|
6
|
+
// src/insert.ts
|
|
7
|
+
/** Longest chain of accessors a single value may hold (a function returning a function ...). */
|
|
8
|
+
const MAX_ACCESSOR_DEPTH = 1e4;
|
|
9
|
+
/** The document a node belongs to (a Document is its own document). */
|
|
10
|
+
function documentOf(node) {
|
|
11
|
+
return node instanceof Document ? node : node.ownerDocument ?? document;
|
|
12
|
+
}
|
|
13
|
+
/** True when the region created or adopted `node`. */
|
|
14
|
+
function ownsText(region, node) {
|
|
15
|
+
const texts = region.texts;
|
|
16
|
+
return texts === node || texts instanceof Set && texts.has(node);
|
|
17
|
+
}
|
|
18
|
+
/** Records that the region owns `text`. */
|
|
19
|
+
function addText(region, text) {
|
|
20
|
+
const texts = region.texts;
|
|
21
|
+
if (texts === null) region.texts = text;
|
|
22
|
+
else if (texts instanceof Set) texts.add(text);
|
|
23
|
+
else if (texts !== text) region.texts = /* @__PURE__ */ new Set([texts, text]);
|
|
24
|
+
}
|
|
25
|
+
/** Forgets the Text nodes of the region that are not in `keep`. */
|
|
26
|
+
function pruneTexts(region, keep) {
|
|
27
|
+
const texts = region.texts;
|
|
28
|
+
if (texts === null) return;
|
|
29
|
+
if (texts instanceof Set) {
|
|
30
|
+
const kept = new Set(keep);
|
|
31
|
+
for (const text of texts) if (!kept.has(text)) texts.delete(text);
|
|
32
|
+
} else if (!keep.includes(texts)) region.texts = null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Flattens a value into parts without recursion. Functions are called (and their results unwrapped)
|
|
36
|
+
* through `call`, which runs inside the render effect that owns the value, so reads are tracked.
|
|
37
|
+
*/
|
|
38
|
+
function flatten(root, call = (fn) => fn()) {
|
|
39
|
+
const parts = [];
|
|
40
|
+
const frames = [[root]];
|
|
41
|
+
const cursors = [0];
|
|
42
|
+
const active = /* @__PURE__ */ new Set();
|
|
43
|
+
while (frames.length > 0) {
|
|
44
|
+
const top = frames.length - 1;
|
|
45
|
+
const frame = frames[top];
|
|
46
|
+
const cursor = cursors[top] ?? 0;
|
|
47
|
+
if (frame === void 0 || cursor >= frame.length) {
|
|
48
|
+
const done = frames.pop();
|
|
49
|
+
if (done !== void 0) active.delete(done);
|
|
50
|
+
cursors.pop();
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
cursors[top] = cursor + 1;
|
|
54
|
+
let item = frame[cursor];
|
|
55
|
+
for (let depth = 0; typeof item === "function"; depth += 1) {
|
|
56
|
+
if (depth >= MAX_ACCESSOR_DEPTH) throw new TypeError("insert(): accessor chain is too deep.");
|
|
57
|
+
item = call(item);
|
|
58
|
+
}
|
|
59
|
+
if (item === null || item === void 0 || typeof item === "boolean") continue;
|
|
60
|
+
if (typeof item === "string") parts.push(item);
|
|
61
|
+
else if (typeof item === "number") parts.push(String(item));
|
|
62
|
+
else if (item instanceof DocumentFragment) for (const child of item.childNodes) parts.push(child);
|
|
63
|
+
else if (item instanceof Node) parts.push(item);
|
|
64
|
+
else if (Array.isArray(item)) {
|
|
65
|
+
if (active.has(item)) throw new TypeError("insert(): a value contains itself.");
|
|
66
|
+
active.add(item);
|
|
67
|
+
frames.push(item);
|
|
68
|
+
cursors.push(0);
|
|
69
|
+
} else parts.push(String(item));
|
|
70
|
+
}
|
|
71
|
+
return parts;
|
|
72
|
+
}
|
|
73
|
+
/** Text nodes the region currently owns, keyed by their data, for reuse by equal strings. */
|
|
74
|
+
function reusablePool(region) {
|
|
75
|
+
const pool = /* @__PURE__ */ new Map();
|
|
76
|
+
for (const node of region.nodes) {
|
|
77
|
+
if (!(node instanceof Text) || !ownsText(region, node)) continue;
|
|
78
|
+
const list = pool.get(node.data);
|
|
79
|
+
if (list === void 0) pool.set(node.data, [node]);
|
|
80
|
+
else list.push(node);
|
|
81
|
+
}
|
|
82
|
+
return pool;
|
|
83
|
+
}
|
|
84
|
+
/** Turns parts into the nodes the region should hold, reusing its own Text nodes where possible. */
|
|
85
|
+
function materialize(region, parts) {
|
|
86
|
+
const only = parts.length === 1 ? parts[0] : void 0;
|
|
87
|
+
if (typeof only === "string") {
|
|
88
|
+
const current = region.nodes.length === 1 ? region.nodes[0] : void 0;
|
|
89
|
+
if (current instanceof Text && ownsText(region, current)) {
|
|
90
|
+
if (current.data !== only) current.data = only;
|
|
91
|
+
return [current];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const nodes = new Array(parts.length);
|
|
95
|
+
let count = 0;
|
|
96
|
+
const seen = /* @__PURE__ */ new Set();
|
|
97
|
+
let pool;
|
|
98
|
+
for (const part of parts) if (typeof part === "string") {
|
|
99
|
+
pool ??= reusablePool(region);
|
|
100
|
+
let text = pool.get(part)?.pop();
|
|
101
|
+
if (text === void 0) {
|
|
102
|
+
text = documentOf(region.parent).createTextNode(part);
|
|
103
|
+
addText(region, text);
|
|
104
|
+
}
|
|
105
|
+
seen.add(text);
|
|
106
|
+
nodes[count] = text;
|
|
107
|
+
count += 1;
|
|
108
|
+
} else if (!seen.has(part)) {
|
|
109
|
+
seen.add(part);
|
|
110
|
+
nodes[count] = part;
|
|
111
|
+
count += 1;
|
|
112
|
+
}
|
|
113
|
+
nodes.length = count;
|
|
114
|
+
return nodes;
|
|
115
|
+
}
|
|
116
|
+
/** The node after the region: its anchor, or the node after its last attached child, or its marker. */
|
|
117
|
+
function endOf(region, attached) {
|
|
118
|
+
if (region.anchor !== null) return region.anchor;
|
|
119
|
+
const last = attached.at(-1);
|
|
120
|
+
if (last !== void 0) return last.nextSibling;
|
|
121
|
+
const marker = region.marker;
|
|
122
|
+
if (marker === null) return region.parent.firstChild;
|
|
123
|
+
if (marker.parentNode !== region.parent) return null;
|
|
124
|
+
return marker.nextSibling;
|
|
125
|
+
}
|
|
126
|
+
/** Makes the DOM show `next` for this region. */
|
|
127
|
+
function reconcileRegion(region, next) {
|
|
128
|
+
const parent = region.parent;
|
|
129
|
+
const attached = region.nodes.filter((node) => node.parentNode === parent);
|
|
130
|
+
const end = endOf(region, attached);
|
|
131
|
+
const first = attached[0];
|
|
132
|
+
if (next.length === 0 && first !== void 0) region.marker = first.previousSibling;
|
|
133
|
+
reconcileNodes(parent, attached, next, end);
|
|
134
|
+
region.nodes = next;
|
|
135
|
+
pruneTexts(region, next);
|
|
136
|
+
}
|
|
137
|
+
/** Applies a flattened value to a region. */
|
|
138
|
+
function commit(region, parts) {
|
|
139
|
+
if (region.claimed !== void 0) {
|
|
140
|
+
checkClaimedText(region.claimed, parts);
|
|
141
|
+
region.claimed = void 0;
|
|
142
|
+
}
|
|
143
|
+
reconcileRegion(region, materialize(region, parts));
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Applies a resolved value to a region. A string or number is the common case (a dynamic text): when the region
|
|
147
|
+
* already shows its own Text node only the data is rewritten, and an empty region gets one new Text node, with none of
|
|
148
|
+
* the flattening and reconciling a general value needs.
|
|
149
|
+
*/
|
|
150
|
+
function commitValue(region, raw) {
|
|
151
|
+
if ((typeof raw === "string" || typeof raw === "number") && !region.claimed) {
|
|
152
|
+
const nodes = region.nodes;
|
|
153
|
+
const text = typeof raw === "string" ? raw : String(raw);
|
|
154
|
+
if (nodes.length === 1) {
|
|
155
|
+
const current = nodes[0];
|
|
156
|
+
if (current instanceof Text && current.parentNode === region.parent && ownsText(region, current)) {
|
|
157
|
+
if (current.data !== text) current.data = text;
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
} else if (nodes.length === 0) {
|
|
161
|
+
const created = documentOf(region.parent).createTextNode(text);
|
|
162
|
+
addText(region, created);
|
|
163
|
+
region.parent.insertBefore(created, endOf(region, nodes));
|
|
164
|
+
region.nodes = [created];
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
commit(region, flatten(raw));
|
|
169
|
+
}
|
|
170
|
+
/** Nodes of `initial` (already in the parent) that the region adopts as its current content. */
|
|
171
|
+
function adoptInitial(parent, initial) {
|
|
172
|
+
const adopted = [];
|
|
173
|
+
const seen = /* @__PURE__ */ new Set();
|
|
174
|
+
for (const part of flatten(initial)) {
|
|
175
|
+
if (typeof part === "string" || seen.has(part) || part.parentNode !== parent) continue;
|
|
176
|
+
seen.add(part);
|
|
177
|
+
adopted.push(part);
|
|
178
|
+
}
|
|
179
|
+
return adopted;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Creates the state of a region in `parent`. `anchorNode` (null to append) and `initial` (nodes
|
|
183
|
+
* already in the DOM, from hydration or splitText) are both optional.
|
|
184
|
+
* @internal
|
|
185
|
+
*/
|
|
186
|
+
function createRegion(parent, anchorNode, initial) {
|
|
187
|
+
const nodes = initial === void 0 ? [] : adoptInitial(parent, initial);
|
|
188
|
+
const region = {
|
|
189
|
+
parent,
|
|
190
|
+
anchor: anchorNode,
|
|
191
|
+
marker: nodes.length > 0 ? nodes[0]?.previousSibling ?? null : parent.lastChild,
|
|
192
|
+
nodes,
|
|
193
|
+
texts: null
|
|
194
|
+
};
|
|
195
|
+
for (const node of nodes) if (node instanceof Text) addText(region, node);
|
|
196
|
+
if (initial !== void 0 && claims.current.isClaiming()) region.claimed = nodes;
|
|
197
|
+
return region;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* True when a function appears anywhere in `root`, at any array depth. Scans without calling
|
|
201
|
+
* anything; `seen` stops it from looping on cyclic arrays (flatten reports those).
|
|
202
|
+
*/
|
|
203
|
+
function containsFunction(root) {
|
|
204
|
+
if (typeof root === "function") return true;
|
|
205
|
+
if (!Array.isArray(root)) return false;
|
|
206
|
+
const stack = [root];
|
|
207
|
+
const seen = /* @__PURE__ */ new Set([root]);
|
|
208
|
+
while (stack.length > 0) {
|
|
209
|
+
const frame = stack.pop() ?? [];
|
|
210
|
+
for (const item of frame) {
|
|
211
|
+
if (typeof item === "function") return true;
|
|
212
|
+
if (Array.isArray(item) && !seen.has(item)) {
|
|
213
|
+
seen.add(item);
|
|
214
|
+
stack.push(item);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* One memo per accessor function, owned by `owner` (the effect that evaluates the region's expression,
|
|
222
|
+
* so a new result drops them all; the effect that resolves the result runs many times and must not
|
|
223
|
+
* own them). `prune` disposes the memos of accessors the last
|
|
224
|
+
* run did not meet, which bounds the cache by what the region currently shows.
|
|
225
|
+
*/
|
|
226
|
+
function createCallCache(owner) {
|
|
227
|
+
const memos = /* @__PURE__ */ new Map();
|
|
228
|
+
let touched = /* @__PURE__ */ new Set();
|
|
229
|
+
return {
|
|
230
|
+
begin() {
|
|
231
|
+
touched = /* @__PURE__ */ new Set();
|
|
232
|
+
},
|
|
233
|
+
call(fn) {
|
|
234
|
+
touched.add(fn);
|
|
235
|
+
let node = memos.get(fn);
|
|
236
|
+
if (node === void 0) {
|
|
237
|
+
node = createComputation({
|
|
238
|
+
kind: "memo",
|
|
239
|
+
fn: () => fn(),
|
|
240
|
+
allowWrites: true,
|
|
241
|
+
owner
|
|
242
|
+
});
|
|
243
|
+
memos.set(fn, node);
|
|
244
|
+
}
|
|
245
|
+
return readComputation(node);
|
|
246
|
+
},
|
|
247
|
+
prune() {
|
|
248
|
+
for (const [fn, node] of memos) {
|
|
249
|
+
if (touched.has(fn)) continue;
|
|
250
|
+
memos.delete(fn);
|
|
251
|
+
disposeOwner(node);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Keeps a region in sync with `value`. A value that is or contains a function (an accessor, or an
|
|
258
|
+
* array with accessor members) runs inside a render effect, so its reads are tracked. Anything
|
|
259
|
+
* else is inserted once.
|
|
260
|
+
* @internal
|
|
261
|
+
*/
|
|
262
|
+
function bindRegion(region, value) {
|
|
263
|
+
if (!containsFunction(value)) {
|
|
264
|
+
commitValue(region, value);
|
|
265
|
+
return value instanceof DocumentFragment ? [...region.nodes] : value;
|
|
266
|
+
}
|
|
267
|
+
let latest;
|
|
268
|
+
useRenderEffect(typeof value === "function" ? value : () => value, (raw) => {
|
|
269
|
+
latest = raw;
|
|
270
|
+
if (containsFunction(raw)) {
|
|
271
|
+
const cache = createCallCache(currentOwner());
|
|
272
|
+
useRenderEffect(() => {
|
|
273
|
+
cache.begin();
|
|
274
|
+
const parts = flatten(raw, cache.call);
|
|
275
|
+
cache.prune();
|
|
276
|
+
return parts;
|
|
277
|
+
}, (parts) => {
|
|
278
|
+
commit(region, parts);
|
|
279
|
+
});
|
|
280
|
+
} else commitValue(region, raw);
|
|
281
|
+
});
|
|
282
|
+
return latest;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Removes a region's nodes from its parent. Anchors and nodes that were moved elsewhere are not
|
|
286
|
+
* touched.
|
|
287
|
+
* @internal
|
|
288
|
+
*/
|
|
289
|
+
function removeRegion(region) {
|
|
290
|
+
for (const node of region.nodes) if (node.parentNode === region.parent) region.parent.removeChild(node);
|
|
291
|
+
region.nodes = [];
|
|
292
|
+
region.texts = null;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Creates a text anchor: an empty Text node placed before `before` (appended when null). Use it as
|
|
296
|
+
* the stable insertion point between two dynamic regions; it is never removed by the runtime.
|
|
297
|
+
*
|
|
298
|
+
* @param parent Node that receives the anchor.
|
|
299
|
+
* @param before Node the anchor goes before, or null to append.
|
|
300
|
+
* @returns The new empty Text node.
|
|
301
|
+
* @example
|
|
302
|
+
* import { anchor, insert } from "@shadow-js/web";
|
|
303
|
+
*
|
|
304
|
+
* const list = document.createElement("ul");
|
|
305
|
+
* const slot = anchor(list, null);
|
|
306
|
+
* insert(list, "first", slot); // goes before the anchor
|
|
307
|
+
* @see insert
|
|
308
|
+
* @since 1.0.0
|
|
309
|
+
*/
|
|
310
|
+
function anchor(parent, before) {
|
|
311
|
+
const text = documentOf(parent).createTextNode("");
|
|
312
|
+
parent.insertBefore(text, before);
|
|
313
|
+
return text;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Reactive child insertion: keeps the content of a region in sync with `value`.
|
|
317
|
+
*
|
|
318
|
+
* - A function is an accessor, wrapped in a render effect; it re-runs when its dependencies change.
|
|
319
|
+
* - `null`, `undefined`, booleans render nothing. Strings and numbers become one Text node, reused
|
|
320
|
+
* when the region already holds one. A Node is inserted itself. A DocumentFragment inserts a
|
|
321
|
+
* snapshot of its children. Arrays are flattened, nested arrays included.
|
|
322
|
+
* - Content goes before `anchorNode`, or at the end when it is null or omitted.
|
|
323
|
+
* - Arrays are reconciled in place: nodes that remain are never removed and re-added.
|
|
324
|
+
* - `initial` lists nodes already in the DOM (from hydration or splitText) so nothing is recreated.
|
|
325
|
+
* - During `hydrate()`, a region that adopted server text is compared with its first commit: in
|
|
326
|
+
* development, different text warns `HYDRATION_TEXT_MISMATCH` (on the console and in devtools) and
|
|
327
|
+
* the region shows the value computed by the client.
|
|
328
|
+
*
|
|
329
|
+
* @param parent Node that holds the region.
|
|
330
|
+
* @param value The value or an accessor returning it.
|
|
331
|
+
* @param anchorNode Node the content goes before; null or omitted appends.
|
|
332
|
+
* @param initial Nodes already in place for this region. Undefined adopts the server's nodes while
|
|
333
|
+
* hydrating and starts empty otherwise.
|
|
334
|
+
* @returns The value as accepted (a fragment yields the array of its nodes).
|
|
335
|
+
* @throws TypeError (production message `SHADOW_INSERT_CYCLE`) when an array contains itself, and
|
|
336
|
+
* (`SHADOW_INSERT_DEPTH`) when an accessor returns accessors more than 10,000 levels deep. When the
|
|
337
|
+
* value is reactive, the error is raised inside its render effect and goes to the owner's error
|
|
338
|
+
* handler, like any effect error.
|
|
339
|
+
* @example
|
|
340
|
+
* import { useSignal } from "@shadow-js/core";
|
|
341
|
+
* import { anchor, insert } from "@shadow-js/web";
|
|
342
|
+
*
|
|
343
|
+
* const list = document.createElement("ul");
|
|
344
|
+
* const end = anchor(list, null);
|
|
345
|
+
* const [items] = useSignal(["a", "b"]);
|
|
346
|
+
* insert(list, () => items().map((name) => document.createTextNode(name)), end);
|
|
347
|
+
* @see anchor
|
|
348
|
+
* @since 1.0.0
|
|
349
|
+
*/
|
|
350
|
+
function insert(parent, value, anchorNode, initial) {
|
|
351
|
+
const resolvedAnchor = anchorNode ?? null;
|
|
352
|
+
return bindRegion(createRegion(parent, resolvedAnchor, initial === void 0 ? claims.current.takeRegion(parent, resolvedAnchor) : initial), value);
|
|
353
|
+
}
|
|
354
|
+
export { anchor, bindRegion, createRegion, insert, removeRegion };
|
|
355
|
+
|
|
356
|
+
//# sourceMappingURL=insert.js.map
|