@shadow-js/web 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/README.md +190 -2
- package/dist/dev/attributes.d.ts +90 -0
- package/dist/dev/attributes.js +196 -0
- package/dist/dev/attributes.js.map +1 -0
- package/dist/dev/autofocus.d.ts +32 -0
- package/dist/dev/autofocus.js +45 -0
- package/dist/dev/autofocus.js.map +1 -0
- package/dist/dev/class-style.d.ts +89 -0
- package/dist/dev/class-style.js +197 -0
- package/dist/dev/class-style.js.map +1 -0
- package/dist/dev/component.d.ts +23 -0
- package/dist/dev/component.js +42 -0
- package/dist/dev/component.js.map +1 -0
- package/dist/dev/control-flow/activity.d.ts +58 -0
- package/dist/dev/control-flow/activity.js +136 -0
- package/dist/dev/control-flow/activity.js.map +1 -0
- package/dist/dev/control-flow/branch.js +104 -0
- package/dist/dev/control-flow/branch.js.map +1 -0
- package/dist/dev/control-flow/client-only.d.ts +48 -0
- package/dist/dev/control-flow/client-only.js +50 -0
- package/dist/dev/control-flow/client-only.js.map +1 -0
- package/dist/dev/control-flow/dynamic.d.ts +82 -0
- package/dist/dev/control-flow/dynamic.js +134 -0
- package/dist/dev/control-flow/dynamic.js.map +1 -0
- package/dist/dev/control-flow/error-boundary.d.ts +72 -0
- package/dist/dev/control-flow/error-boundary.js +115 -0
- package/dist/dev/control-flow/error-boundary.js.map +1 -0
- package/dist/dev/control-flow/for.d.ts +80 -0
- package/dist/dev/control-flow/for.js +23 -0
- package/dist/dev/control-flow/for.js.map +1 -0
- package/dist/dev/control-flow/fragment.d.ts +38 -0
- package/dist/dev/control-flow/fragment.js +31 -0
- package/dist/dev/control-flow/fragment.js.map +1 -0
- package/dist/dev/control-flow/hot-link.js +64 -0
- package/dist/dev/control-flow/hot-link.js.map +1 -0
- package/dist/dev/control-flow/index-list.d.ts +48 -0
- package/dist/dev/control-flow/index-list.js +31 -0
- package/dist/dev/control-flow/index-list.js.map +1 -0
- package/dist/dev/control-flow/index.d.ts +15 -0
- package/dist/dev/control-flow/lazy.d.ts +58 -0
- package/dist/dev/control-flow/lazy.js +64 -0
- package/dist/dev/control-flow/lazy.js.map +1 -0
- package/dist/dev/control-flow/no-hydration.d.ts +39 -0
- package/dist/dev/control-flow/no-hydration.js +58 -0
- package/dist/dev/control-flow/no-hydration.js.map +1 -0
- package/dist/dev/control-flow/portal.d.ts +69 -0
- package/dist/dev/control-flow/portal.js +134 -0
- package/dist/dev/control-flow/portal.js.map +1 -0
- package/dist/dev/control-flow/root-errors.d.ts +25 -0
- package/dist/dev/control-flow/root-errors.js +33 -0
- package/dist/dev/control-flow/root-errors.js.map +1 -0
- package/dist/dev/control-flow/show.d.ts +101 -0
- package/dist/dev/control-flow/show.js +18 -0
- package/dist/dev/control-flow/show.js.map +1 -0
- package/dist/dev/control-flow/suspense-list.d.ts +65 -0
- package/dist/dev/control-flow/suspense-list.js +105 -0
- package/dist/dev/control-flow/suspense-list.js.map +1 -0
- package/dist/dev/control-flow/suspense.d.ts +53 -0
- package/dist/dev/control-flow/suspense.js +102 -0
- package/dist/dev/control-flow/suspense.js.map +1 -0
- package/dist/dev/control-flow/switch.d.ts +85 -0
- package/dist/dev/control-flow/switch.js +90 -0
- package/dist/dev/control-flow/switch.js.map +1 -0
- package/dist/dev/derived.d.ts +52 -0
- package/dist/dev/derived.js +34 -0
- package/dist/dev/derived.js.map +1 -0
- package/dist/dev/element.d.ts +40 -0
- package/dist/dev/element.js +105 -0
- package/dist/dev/element.js.map +1 -0
- package/dist/dev/events.d.ts +87 -0
- package/dist/dev/events.js +265 -0
- package/dist/dev/events.js.map +1 -0
- package/dist/dev/extend.d.ts +12 -0
- package/dist/dev/extend.js +12 -0
- package/dist/dev/head/components.d.ts +137 -0
- package/dist/dev/head/components.js +170 -0
- package/dist/dev/head/components.js.map +1 -0
- package/dist/dev/head/registry.js +68 -0
- package/dist/dev/head/registry.js.map +1 -0
- package/dist/dev/head/server-head.d.ts +54 -0
- package/dist/dev/head/server-head.js +76 -0
- package/dist/dev/head/server-head.js.map +1 -0
- package/dist/dev/head/sink.js +96 -0
- package/dist/dev/head/sink.js.map +1 -0
- package/dist/dev/head/use-head.d.ts +35 -0
- package/dist/dev/head/use-head.js +84 -0
- package/dist/dev/head/use-head.js.map +1 -0
- package/dist/dev/head/validate.d.ts +85 -0
- package/dist/dev/head/validate.js +268 -0
- package/dist/dev/head/validate.js.map +1 -0
- package/dist/dev/hmr.d.ts +82 -0
- package/dist/dev/hmr.js +124 -0
- package/dist/dev/hmr.js.map +1 -0
- package/dist/dev/hydration.d.ts +61 -0
- package/dist/dev/hydration.js +120 -0
- package/dist/dev/hydration.js.map +1 -0
- package/dist/dev/index.d.ts +45 -0
- package/dist/dev/index.js +34 -0
- package/dist/dev/insert.d.ts +97 -0
- package/dist/dev/insert.js +357 -0
- package/dist/dev/insert.js.map +1 -0
- package/dist/dev/internal/claim.d.ts +106 -0
- package/dist/dev/internal/claim.js +357 -0
- package/dist/dev/internal/claim.js.map +1 -0
- package/dist/dev/internal/css-units.js +26 -0
- package/dist/dev/internal/css-units.js.map +1 -0
- package/dist/dev/internal/diagnostics.d.ts +30 -0
- package/dist/dev/internal/diagnostics.js +38 -0
- package/dist/dev/internal/diagnostics.js.map +1 -0
- package/dist/dev/internal/early-events.js +76 -0
- package/dist/dev/internal/early-events.js.map +1 -0
- package/dist/dev/internal/hydration-hooks.d.ts +43 -0
- package/dist/dev/internal/hydration-hooks.js +27 -0
- package/dist/dev/internal/hydration-hooks.js.map +1 -0
- package/dist/dev/internal/hydration-scope.d.ts +131 -0
- package/dist/dev/internal/hydration-scope.js +156 -0
- package/dist/dev/internal/hydration-scope.js.map +1 -0
- package/dist/dev/internal/names.d.ts +33 -0
- package/dist/dev/internal/names.js +35 -0
- package/dist/dev/internal/names.js.map +1 -0
- package/dist/dev/internal/portal-context.d.ts +39 -0
- package/dist/dev/internal/portal-context.js +28 -0
- package/dist/dev/internal/portal-context.js.map +1 -0
- package/dist/dev/internal/react-names.js +116 -0
- package/dist/dev/internal/react-names.js.map +1 -0
- package/dist/dev/internal/reconcile.d.ts +40 -0
- package/dist/dev/internal/reconcile.js +122 -0
- package/dist/dev/internal/reconcile.js.map +1 -0
- package/dist/dev/internal/stream-context.d.ts +47 -0
- package/dist/dev/internal/stream-context.js +23 -0
- package/dist/dev/internal/stream-context.js.map +1 -0
- package/dist/dev/jsx/aria.d.ts +72 -0
- package/dist/dev/jsx/component.d.ts +89 -0
- package/dist/dev/jsx/events.d.ts +364 -0
- package/dist/dev/jsx/global.d.ts +211 -0
- package/dist/dev/jsx/html.d.ts +879 -0
- package/dist/dev/jsx/intrinsic.d.ts +59 -0
- package/dist/dev/jsx/mathml.d.ts +186 -0
- package/dist/dev/jsx/svg.d.ts +607 -0
- package/dist/dev/jsx/types.d.ts +176 -0
- package/dist/dev/jsx-dev-runtime.d.ts +10 -0
- package/dist/dev/jsx-dev-runtime.js +0 -0
- package/dist/dev/jsx-runtime.d.ts +94 -0
- package/dist/dev/jsx-runtime.js +0 -0
- package/dist/dev/reactive.d.ts +110 -0
- package/dist/dev/reactive.js +85 -0
- package/dist/dev/reactive.js.map +1 -0
- package/dist/dev/render.d.ts +36 -0
- package/dist/dev/render.js +52 -0
- package/dist/dev/render.js.map +1 -0
- package/dist/dev/resource-hints.d.ts +145 -0
- package/dist/dev/resource-hints.js +200 -0
- package/dist/dev/resource-hints.js.map +1 -0
- package/dist/dev/select-value.d.ts +24 -0
- package/dist/dev/select-value.js +51 -0
- package/dist/dev/select-value.js.map +1 -0
- package/dist/dev/server/attributes.d.ts +33 -0
- package/dist/dev/server/attributes.js +155 -0
- package/dist/dev/server/attributes.js.map +1 -0
- package/dist/dev/server/class-style.d.ts +46 -0
- package/dist/dev/server/class-style.js +173 -0
- package/dist/dev/server/class-style.js.map +1 -0
- package/dist/dev/server/component.d.ts +42 -0
- package/dist/dev/server/component.js +72 -0
- package/dist/dev/server/component.js.map +1 -0
- package/dist/dev/server/derived.d.ts +41 -0
- package/dist/dev/server/derived.js +26 -0
- package/dist/dev/server/derived.js.map +1 -0
- package/dist/dev/server/element.d.ts +89 -0
- package/dist/dev/server/element.js +216 -0
- package/dist/dev/server/element.js.map +1 -0
- package/dist/dev/server/errors.js +26 -0
- package/dist/dev/server/errors.js.map +1 -0
- package/dist/dev/server/escape.d.ts +30 -0
- package/dist/dev/server/escape.js +119 -0
- package/dist/dev/server/escape.js.map +1 -0
- package/dist/dev/server/form-controls.d.ts +50 -0
- package/dist/dev/server/form-controls.js +193 -0
- package/dist/dev/server/form-controls.js.map +1 -0
- package/dist/dev/server/hydration-script.d.ts +65 -0
- package/dist/dev/server/hydration-script.js +59 -0
- package/dist/dev/server/hydration-script.js.map +1 -0
- package/dist/dev/server/index.d.ts +16 -0
- package/dist/dev/server/index.js +16 -0
- package/dist/dev/server/node.d.ts +13 -0
- package/dist/dev/server/node.js +21 -0
- package/dist/dev/server/node.js.map +1 -0
- package/dist/dev/server/portals.d.ts +46 -0
- package/dist/dev/server/portals.js +99 -0
- package/dist/dev/server/portals.js.map +1 -0
- package/dist/dev/server/render.d.ts +129 -0
- package/dist/dev/server/render.js +256 -0
- package/dist/dev/server/render.js.map +1 -0
- package/dist/dev/server/serialize.d.ts +45 -0
- package/dist/dev/server/serialize.js +315 -0
- package/dist/dev/server/serialize.js.map +1 -0
- package/dist/dev/server/stream.d.ts +94 -0
- package/dist/dev/server/stream.js +235 -0
- package/dist/dev/server/stream.js.map +1 -0
- package/dist/dev/server.d.ts +16 -0
- package/dist/dev/server.js +16 -0
- package/dist/dev/spread.d.ts +49 -0
- package/dist/dev/spread.js +296 -0
- package/dist/dev/spread.js.map +1 -0
- package/dist/dev/template.d.ts +26 -0
- package/dist/dev/template.js +120 -0
- package/dist/dev/template.js.map +1 -0
- package/dist/dev/view-transition.d.ts +97 -0
- package/dist/dev/view-transition.js +121 -0
- package/dist/dev/view-transition.js.map +1 -0
- package/dist/prod/attributes.js +2 -0
- package/dist/prod/attributes.js.map +1 -0
- package/dist/prod/autofocus.js +2 -0
- package/dist/prod/autofocus.js.map +1 -0
- package/dist/prod/class-style.js +2 -0
- package/dist/prod/class-style.js.map +1 -0
- package/dist/prod/component.js +2 -0
- package/dist/prod/component.js.map +1 -0
- package/dist/prod/control-flow/activity.js +2 -0
- package/dist/prod/control-flow/activity.js.map +1 -0
- package/dist/prod/control-flow/branch.js +2 -0
- package/dist/prod/control-flow/branch.js.map +1 -0
- package/dist/prod/control-flow/client-only.js +2 -0
- package/dist/prod/control-flow/client-only.js.map +1 -0
- package/dist/prod/control-flow/dynamic.js +2 -0
- package/dist/prod/control-flow/dynamic.js.map +1 -0
- package/dist/prod/control-flow/error-boundary.js +2 -0
- package/dist/prod/control-flow/error-boundary.js.map +1 -0
- package/dist/prod/control-flow/for.js +2 -0
- package/dist/prod/control-flow/for.js.map +1 -0
- package/dist/prod/control-flow/fragment.js +2 -0
- package/dist/prod/control-flow/fragment.js.map +1 -0
- package/dist/prod/control-flow/hot-link.js +2 -0
- package/dist/prod/control-flow/hot-link.js.map +1 -0
- package/dist/prod/control-flow/index-list.js +2 -0
- package/dist/prod/control-flow/index-list.js.map +1 -0
- package/dist/prod/control-flow/lazy.js +2 -0
- package/dist/prod/control-flow/lazy.js.map +1 -0
- package/dist/prod/control-flow/no-hydration.js +2 -0
- package/dist/prod/control-flow/no-hydration.js.map +1 -0
- package/dist/prod/control-flow/portal.js +2 -0
- package/dist/prod/control-flow/portal.js.map +1 -0
- package/dist/prod/control-flow/root-errors.js +2 -0
- package/dist/prod/control-flow/root-errors.js.map +1 -0
- package/dist/prod/control-flow/show.js +2 -0
- package/dist/prod/control-flow/show.js.map +1 -0
- package/dist/prod/control-flow/suspense-list.js +2 -0
- package/dist/prod/control-flow/suspense-list.js.map +1 -0
- package/dist/prod/control-flow/suspense.js +2 -0
- package/dist/prod/control-flow/suspense.js.map +1 -0
- package/dist/prod/control-flow/switch.js +2 -0
- package/dist/prod/control-flow/switch.js.map +1 -0
- package/dist/prod/derived.js +2 -0
- package/dist/prod/derived.js.map +1 -0
- package/dist/prod/element.js +2 -0
- package/dist/prod/element.js.map +1 -0
- package/dist/prod/events.js +2 -0
- package/dist/prod/events.js.map +1 -0
- package/dist/prod/extend.js +1 -0
- package/dist/prod/head/components.js +2 -0
- package/dist/prod/head/components.js.map +1 -0
- package/dist/prod/head/registry.js +2 -0
- package/dist/prod/head/registry.js.map +1 -0
- package/dist/prod/head/server-head.js +2 -0
- package/dist/prod/head/server-head.js.map +1 -0
- package/dist/prod/head/sink.js +2 -0
- package/dist/prod/head/sink.js.map +1 -0
- package/dist/prod/head/use-head.js +2 -0
- package/dist/prod/head/use-head.js.map +1 -0
- package/dist/prod/head/validate.js +2 -0
- package/dist/prod/head/validate.js.map +1 -0
- package/dist/prod/hmr.js +2 -0
- package/dist/prod/hmr.js.map +1 -0
- package/dist/prod/hydration.js +2 -0
- package/dist/prod/hydration.js.map +1 -0
- package/dist/prod/index.js +1 -0
- package/dist/prod/insert.js +2 -0
- package/dist/prod/insert.js.map +1 -0
- package/dist/prod/internal/claim.js +2 -0
- package/dist/prod/internal/claim.js.map +1 -0
- package/dist/prod/internal/css-units.js +2 -0
- package/dist/prod/internal/css-units.js.map +1 -0
- package/dist/prod/internal/diagnostics.js +2 -0
- package/dist/prod/internal/diagnostics.js.map +1 -0
- package/dist/prod/internal/early-events.js +2 -0
- package/dist/prod/internal/early-events.js.map +1 -0
- package/dist/prod/internal/hydration-hooks.js +2 -0
- package/dist/prod/internal/hydration-hooks.js.map +1 -0
- package/dist/prod/internal/hydration-scope.js +2 -0
- package/dist/prod/internal/hydration-scope.js.map +1 -0
- package/dist/prod/internal/names.js +2 -0
- package/dist/prod/internal/names.js.map +1 -0
- package/dist/prod/internal/portal-context.js +2 -0
- package/dist/prod/internal/portal-context.js.map +1 -0
- package/dist/prod/internal/react-names.js +2 -0
- package/dist/prod/internal/react-names.js.map +1 -0
- package/dist/prod/internal/reconcile.js +2 -0
- package/dist/prod/internal/reconcile.js.map +1 -0
- package/dist/prod/internal/stream-context.js +2 -0
- package/dist/prod/internal/stream-context.js.map +1 -0
- package/dist/prod/jsx-dev-runtime.js +0 -0
- package/dist/prod/jsx-runtime.js +0 -0
- package/dist/prod/reactive.js +2 -0
- package/dist/prod/reactive.js.map +1 -0
- package/dist/prod/render.js +2 -0
- package/dist/prod/render.js.map +1 -0
- package/dist/prod/resource-hints.js +2 -0
- package/dist/prod/resource-hints.js.map +1 -0
- package/dist/prod/select-value.js +2 -0
- package/dist/prod/select-value.js.map +1 -0
- package/dist/prod/server/attributes.js +2 -0
- package/dist/prod/server/attributes.js.map +1 -0
- package/dist/prod/server/class-style.js +2 -0
- package/dist/prod/server/class-style.js.map +1 -0
- package/dist/prod/server/component.js +2 -0
- package/dist/prod/server/component.js.map +1 -0
- package/dist/prod/server/derived.js +2 -0
- package/dist/prod/server/derived.js.map +1 -0
- package/dist/prod/server/element.js +2 -0
- package/dist/prod/server/element.js.map +1 -0
- package/dist/prod/server/errors.js +2 -0
- package/dist/prod/server/errors.js.map +1 -0
- package/dist/prod/server/escape.js +2 -0
- package/dist/prod/server/escape.js.map +1 -0
- package/dist/prod/server/form-controls.js +3 -0
- package/dist/prod/server/form-controls.js.map +1 -0
- package/dist/prod/server/hydration-script.js +2 -0
- package/dist/prod/server/hydration-script.js.map +1 -0
- package/dist/prod/server/index.js +1 -0
- package/dist/prod/server/node.js +2 -0
- package/dist/prod/server/node.js.map +1 -0
- package/dist/prod/server/portals.js +2 -0
- package/dist/prod/server/portals.js.map +1 -0
- package/dist/prod/server/render.js +2 -0
- package/dist/prod/server/render.js.map +1 -0
- package/dist/prod/server/serialize.js +2 -0
- package/dist/prod/server/serialize.js.map +1 -0
- package/dist/prod/server/stream.js +2 -0
- package/dist/prod/server/stream.js.map +1 -0
- package/dist/prod/server.js +1 -0
- package/dist/prod/spread.js +2 -0
- package/dist/prod/spread.js.map +1 -0
- package/dist/prod/template.js +2 -0
- package/dist/prod/template.js.map +1 -0
- package/dist/prod/view-transition.js +2 -0
- package/dist/prod/view-transition.js.map +1 -0
- package/dist/server/attributes.js +2 -0
- package/dist/server/attributes.js.map +1 -0
- package/dist/server/autofocus.js +2 -0
- package/dist/server/autofocus.js.map +1 -0
- package/dist/server/class-style.js +2 -0
- package/dist/server/class-style.js.map +1 -0
- package/dist/server/component.js +2 -0
- package/dist/server/component.js.map +1 -0
- package/dist/server/control-flow/activity.js +2 -0
- package/dist/server/control-flow/activity.js.map +1 -0
- package/dist/server/control-flow/branch.js +2 -0
- package/dist/server/control-flow/branch.js.map +1 -0
- package/dist/server/control-flow/client-only.js +2 -0
- package/dist/server/control-flow/client-only.js.map +1 -0
- package/dist/server/control-flow/dynamic.js +2 -0
- package/dist/server/control-flow/dynamic.js.map +1 -0
- package/dist/server/control-flow/error-boundary.js +2 -0
- package/dist/server/control-flow/error-boundary.js.map +1 -0
- package/dist/server/control-flow/for.js +2 -0
- package/dist/server/control-flow/for.js.map +1 -0
- package/dist/server/control-flow/fragment.js +2 -0
- package/dist/server/control-flow/fragment.js.map +1 -0
- package/dist/server/control-flow/index-list.js +2 -0
- package/dist/server/control-flow/index-list.js.map +1 -0
- package/dist/server/control-flow/lazy.js +2 -0
- package/dist/server/control-flow/lazy.js.map +1 -0
- package/dist/server/control-flow/no-hydration.js +2 -0
- package/dist/server/control-flow/no-hydration.js.map +1 -0
- package/dist/server/control-flow/portal.js +2 -0
- package/dist/server/control-flow/portal.js.map +1 -0
- package/dist/server/control-flow/root-errors.js +2 -0
- package/dist/server/control-flow/root-errors.js.map +1 -0
- package/dist/server/control-flow/show.js +2 -0
- package/dist/server/control-flow/show.js.map +1 -0
- package/dist/server/control-flow/suspense-list.js +2 -0
- package/dist/server/control-flow/suspense-list.js.map +1 -0
- package/dist/server/control-flow/suspense.js +2 -0
- package/dist/server/control-flow/suspense.js.map +1 -0
- package/dist/server/control-flow/switch.js +2 -0
- package/dist/server/control-flow/switch.js.map +1 -0
- package/dist/server/derived.js +2 -0
- package/dist/server/derived.js.map +1 -0
- package/dist/server/element.js +2 -0
- package/dist/server/element.js.map +1 -0
- package/dist/server/events.js +2 -0
- package/dist/server/events.js.map +1 -0
- package/dist/server/extend.js +1 -0
- package/dist/server/head/components.js +2 -0
- package/dist/server/head/components.js.map +1 -0
- package/dist/server/head/registry.js +2 -0
- package/dist/server/head/registry.js.map +1 -0
- package/dist/server/head/server-head.js +2 -0
- package/dist/server/head/server-head.js.map +1 -0
- package/dist/server/head/sink.js +2 -0
- package/dist/server/head/sink.js.map +1 -0
- package/dist/server/head/use-head.js +2 -0
- package/dist/server/head/use-head.js.map +1 -0
- package/dist/server/head/validate.js +2 -0
- package/dist/server/head/validate.js.map +1 -0
- package/dist/server/hydration.js +2 -0
- package/dist/server/hydration.js.map +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/insert.js +2 -0
- package/dist/server/insert.js.map +1 -0
- package/dist/server/internal/claim.js +2 -0
- package/dist/server/internal/claim.js.map +1 -0
- package/dist/server/internal/css-units.js +2 -0
- package/dist/server/internal/css-units.js.map +1 -0
- package/dist/server/internal/diagnostics.js +2 -0
- package/dist/server/internal/diagnostics.js.map +1 -0
- package/dist/server/internal/early-events.js +2 -0
- package/dist/server/internal/early-events.js.map +1 -0
- package/dist/server/internal/hydration-hooks.js +2 -0
- package/dist/server/internal/hydration-hooks.js.map +1 -0
- package/dist/server/internal/hydration-scope.js +2 -0
- package/dist/server/internal/hydration-scope.js.map +1 -0
- package/dist/server/internal/names.js +2 -0
- package/dist/server/internal/names.js.map +1 -0
- package/dist/server/internal/portal-context.js +2 -0
- package/dist/server/internal/portal-context.js.map +1 -0
- package/dist/server/internal/react-names.js +2 -0
- package/dist/server/internal/react-names.js.map +1 -0
- package/dist/server/internal/reconcile.js +2 -0
- package/dist/server/internal/reconcile.js.map +1 -0
- package/dist/server/internal/stream-context.js +2 -0
- package/dist/server/internal/stream-context.js.map +1 -0
- package/dist/server/reactive.js +2 -0
- package/dist/server/reactive.js.map +1 -0
- package/dist/server/render.js +2 -0
- package/dist/server/render.js.map +1 -0
- package/dist/server/resource-hints.js +2 -0
- package/dist/server/resource-hints.js.map +1 -0
- package/dist/server/select-value.js +2 -0
- package/dist/server/select-value.js.map +1 -0
- package/dist/server/server/attributes.js +2 -0
- package/dist/server/server/attributes.js.map +1 -0
- package/dist/server/server/class-style.js +2 -0
- package/dist/server/server/class-style.js.map +1 -0
- package/dist/server/server/component.js +2 -0
- package/dist/server/server/component.js.map +1 -0
- package/dist/server/server/derived.js +2 -0
- package/dist/server/server/derived.js.map +1 -0
- package/dist/server/server/element.js +2 -0
- package/dist/server/server/element.js.map +1 -0
- package/dist/server/server/errors.js +2 -0
- package/dist/server/server/errors.js.map +1 -0
- package/dist/server/server/escape.js +2 -0
- package/dist/server/server/escape.js.map +1 -0
- package/dist/server/server/form-controls.js +3 -0
- package/dist/server/server/form-controls.js.map +1 -0
- package/dist/server/server/hydration-script.js +2 -0
- package/dist/server/server/hydration-script.js.map +1 -0
- package/dist/server/server/index.js +1 -0
- package/dist/server/server/node.js +2 -0
- package/dist/server/server/node.js.map +1 -0
- package/dist/server/server/portals.js +2 -0
- package/dist/server/server/portals.js.map +1 -0
- package/dist/server/server/render.js +2 -0
- package/dist/server/server/render.js.map +1 -0
- package/dist/server/server/serialize.js +2 -0
- package/dist/server/server/serialize.js.map +1 -0
- package/dist/server/server/stream.js +2 -0
- package/dist/server/server/stream.js.map +1 -0
- package/dist/server/server.js +1 -0
- package/dist/server/spread.js +2 -0
- package/dist/server/spread.js.map +1 -0
- package/dist/server/template.js +2 -0
- package/dist/server/template.js.map +1 -0
- package/dist/server/view-transition.js +2 -0
- package/dist/server/view-transition.js.map +1 -0
- package/dist/server-dev/attributes.js +196 -0
- package/dist/server-dev/attributes.js.map +1 -0
- package/dist/server-dev/autofocus.js +45 -0
- package/dist/server-dev/autofocus.js.map +1 -0
- package/dist/server-dev/class-style.js +197 -0
- package/dist/server-dev/class-style.js.map +1 -0
- package/dist/server-dev/component.js +42 -0
- package/dist/server-dev/component.js.map +1 -0
- package/dist/server-dev/control-flow/activity.js +41 -0
- package/dist/server-dev/control-flow/activity.js.map +1 -0
- package/dist/server-dev/control-flow/branch.js +104 -0
- package/dist/server-dev/control-flow/branch.js.map +1 -0
- package/dist/server-dev/control-flow/client-only.js +50 -0
- package/dist/server-dev/control-flow/client-only.js.map +1 -0
- package/dist/server-dev/control-flow/dynamic.js +106 -0
- package/dist/server-dev/control-flow/dynamic.js.map +1 -0
- package/dist/server-dev/control-flow/error-boundary.js +115 -0
- package/dist/server-dev/control-flow/error-boundary.js.map +1 -0
- package/dist/server-dev/control-flow/for.js +23 -0
- package/dist/server-dev/control-flow/for.js.map +1 -0
- package/dist/server-dev/control-flow/fragment.js +31 -0
- package/dist/server-dev/control-flow/fragment.js.map +1 -0
- package/dist/server-dev/control-flow/hot-link.js +57 -0
- package/dist/server-dev/control-flow/hot-link.js.map +1 -0
- package/dist/server-dev/control-flow/index-list.js +31 -0
- package/dist/server-dev/control-flow/index-list.js.map +1 -0
- package/dist/server-dev/control-flow/lazy.js +64 -0
- package/dist/server-dev/control-flow/lazy.js.map +1 -0
- package/dist/server-dev/control-flow/no-hydration.js +40 -0
- package/dist/server-dev/control-flow/no-hydration.js.map +1 -0
- package/dist/server-dev/control-flow/portal.js +134 -0
- package/dist/server-dev/control-flow/portal.js.map +1 -0
- package/dist/server-dev/control-flow/root-errors.js +33 -0
- package/dist/server-dev/control-flow/root-errors.js.map +1 -0
- package/dist/server-dev/control-flow/show.js +18 -0
- package/dist/server-dev/control-flow/show.js.map +1 -0
- package/dist/server-dev/control-flow/suspense-list.js +100 -0
- package/dist/server-dev/control-flow/suspense-list.js.map +1 -0
- package/dist/server-dev/control-flow/suspense.js +119 -0
- package/dist/server-dev/control-flow/suspense.js.map +1 -0
- package/dist/server-dev/control-flow/switch.js +90 -0
- package/dist/server-dev/control-flow/switch.js.map +1 -0
- package/dist/server-dev/derived.js +34 -0
- package/dist/server-dev/derived.js.map +1 -0
- package/dist/server-dev/element.js +66 -0
- package/dist/server-dev/element.js.map +1 -0
- package/dist/server-dev/events.js +265 -0
- package/dist/server-dev/events.js.map +1 -0
- package/dist/server-dev/extend.js +12 -0
- package/dist/server-dev/head/components.js +170 -0
- package/dist/server-dev/head/components.js.map +1 -0
- package/dist/server-dev/head/registry.js +68 -0
- package/dist/server-dev/head/registry.js.map +1 -0
- package/dist/server-dev/head/server-head.js +76 -0
- package/dist/server-dev/head/server-head.js.map +1 -0
- package/dist/server-dev/head/sink.js +96 -0
- package/dist/server-dev/head/sink.js.map +1 -0
- package/dist/server-dev/head/use-head.js +84 -0
- package/dist/server-dev/head/use-head.js.map +1 -0
- package/dist/server-dev/head/validate.js +268 -0
- package/dist/server-dev/head/validate.js.map +1 -0
- package/dist/server-dev/hydration.js +120 -0
- package/dist/server-dev/hydration.js.map +1 -0
- package/dist/server-dev/index.js +34 -0
- package/dist/server-dev/insert.js +357 -0
- package/dist/server-dev/insert.js.map +1 -0
- package/dist/server-dev/internal/claim.js +357 -0
- package/dist/server-dev/internal/claim.js.map +1 -0
- package/dist/server-dev/internal/css-units.js +26 -0
- package/dist/server-dev/internal/css-units.js.map +1 -0
- package/dist/server-dev/internal/diagnostics.js +38 -0
- package/dist/server-dev/internal/diagnostics.js.map +1 -0
- package/dist/server-dev/internal/early-events.js +76 -0
- package/dist/server-dev/internal/early-events.js.map +1 -0
- package/dist/server-dev/internal/hydration-hooks.js +27 -0
- package/dist/server-dev/internal/hydration-hooks.js.map +1 -0
- package/dist/server-dev/internal/hydration-scope.js +156 -0
- package/dist/server-dev/internal/hydration-scope.js.map +1 -0
- package/dist/server-dev/internal/names.js +35 -0
- package/dist/server-dev/internal/names.js.map +1 -0
- package/dist/server-dev/internal/portal-context.js +28 -0
- package/dist/server-dev/internal/portal-context.js.map +1 -0
- package/dist/server-dev/internal/react-names.js +116 -0
- package/dist/server-dev/internal/react-names.js.map +1 -0
- package/dist/server-dev/internal/reconcile.js +122 -0
- package/dist/server-dev/internal/reconcile.js.map +1 -0
- package/dist/server-dev/internal/stream-context.js +23 -0
- package/dist/server-dev/internal/stream-context.js.map +1 -0
- package/dist/server-dev/reactive.js +85 -0
- package/dist/server-dev/reactive.js.map +1 -0
- package/dist/server-dev/render.js +52 -0
- package/dist/server-dev/render.js.map +1 -0
- package/dist/server-dev/resource-hints.js +200 -0
- package/dist/server-dev/resource-hints.js.map +1 -0
- package/dist/server-dev/select-value.js +51 -0
- package/dist/server-dev/select-value.js.map +1 -0
- package/dist/server-dev/server/attributes.js +155 -0
- package/dist/server-dev/server/attributes.js.map +1 -0
- package/dist/server-dev/server/class-style.js +173 -0
- package/dist/server-dev/server/class-style.js.map +1 -0
- package/dist/server-dev/server/component.js +72 -0
- package/dist/server-dev/server/component.js.map +1 -0
- package/dist/server-dev/server/derived.js +26 -0
- package/dist/server-dev/server/derived.js.map +1 -0
- package/dist/server-dev/server/element.js +216 -0
- package/dist/server-dev/server/element.js.map +1 -0
- package/dist/server-dev/server/errors.js +26 -0
- package/dist/server-dev/server/errors.js.map +1 -0
- package/dist/server-dev/server/escape.js +119 -0
- package/dist/server-dev/server/escape.js.map +1 -0
- package/dist/server-dev/server/form-controls.js +193 -0
- package/dist/server-dev/server/form-controls.js.map +1 -0
- package/dist/server-dev/server/hydration-script.js +59 -0
- package/dist/server-dev/server/hydration-script.js.map +1 -0
- package/dist/server-dev/server/index.js +16 -0
- package/dist/server-dev/server/node.js +21 -0
- package/dist/server-dev/server/node.js.map +1 -0
- package/dist/server-dev/server/portals.js +99 -0
- package/dist/server-dev/server/portals.js.map +1 -0
- package/dist/server-dev/server/render.js +256 -0
- package/dist/server-dev/server/render.js.map +1 -0
- package/dist/server-dev/server/serialize.js +315 -0
- package/dist/server-dev/server/serialize.js.map +1 -0
- package/dist/server-dev/server/stream.js +235 -0
- package/dist/server-dev/server/stream.js.map +1 -0
- package/dist/server-dev/server.js +16 -0
- package/dist/server-dev/spread.js +296 -0
- package/dist/server-dev/spread.js.map +1 -0
- package/dist/server-dev/template.js +120 -0
- package/dist/server-dev/template.js.map +1 -0
- package/dist/server-dev/view-transition.js +90 -0
- package/dist/server-dev/view-transition.js.map +1 -0
- package/package.json +136 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration-scope.js","names":["current","createRootScope","renderId","currentScope","withScope","previous","scope","fn","enterComponent","parent","nextKey","resourceKey","explicit","childScope","key"],"sources":["../../../src/internal/hydration-scope.ts"],"sourcesContent":["/**\n * A hydration scope: the deterministic source of hydration keys shared by the server renderer and\n * the client hydrator. Keys depend only on the nesting and order of component calls, never on owners,\n * effects or memos, so server and client agree as long as they run the same components. Scopes are\n * created by {@link createRootScope}, {@link enterComponent} and {@link childScope}; treat their\n * fields as read-only.\n *\n * @since 1.0.0\n */\nexport interface HydrationScope {\n /** Prefix of every key allocated in this scope, ending with `-` (`\"0-\"` for a root, `\"0-3-\"` below). */\n readonly id: string;\n /** Next number handed out by this scope: component scopes and template root keys share it. */\n count: number;\n /** Number of auto-keyed resources created directly in this scope so far. */\n resources: number;\n}\n\nlet current: HydrationScope | null = null;\n\n/**\n * Creates the scope a render or a hydration starts from: what `renderToString` and `hydrate()` put in\n * effect around the app. A custom renderer that hands out hydration keys does the same.\n *\n * @param renderId The prefix of every key of this render. Default: `\"0\"`, the default `renderId` of\n * the renderers.\n * @returns A fresh scope whose `id` is `` `${renderId}-` ``.\n * @example\n * import { createRootScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * const keys = withScope(createRootScope(\"app\"), () => [nextKey(), nextKey()]);\n * // [\"app-0\", \"app-1\"]\n * @see withScope\n * @since 1.0.0\n */\nexport function createRootScope(renderId = \"0\"): HydrationScope {\n return { id: `${renderId}-`, count: 0, resources: 0 };\n}\n\n/**\n * Returns the hydration scope in effect.\n *\n * @returns The current scope; `null` outside a server render, a hydration, or a {@link withScope}\n * call.\n * @example\n * import { currentScope } from \"@shadow-js/web/extend\";\n *\n * function scopeLabel(): string {\n * return currentScope()?.id ?? \"no scope\";\n * }\n * @since 1.0.0\n */\nexport function currentScope(): HydrationScope | null {\n return current;\n}\n\n/**\n * Runs `fn` with `scope` in effect, so the keys `fn` draws come from it. The previous scope is\n * restored when `fn` returns or throws.\n *\n * @param scope The scope to put in effect; `null` runs `fn` with no scope (no keys are drawn).\n * @param fn The code to run, synchronously, once.\n * @returns What `fn` returns. An error `fn` throws propagates.\n * @example\n * import { childScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * // The keys of an isolated subtree, independent of its siblings.\n * const first = withScope(childScope(\"0-4\"), () => nextKey()); // \"0-4-0\"\n * @see createRootScope\n * @since 1.0.0\n */\nexport function withScope<T>(scope: HydrationScope | null, fn: () => T): T {\n const previous = current;\n current = scope;\n try {\n return fn();\n } finally {\n current = previous;\n }\n}\n\n/**\n * Runs a component call in a scope of its own, so the keys it draws depend only on its position\n * among its parent's calls: what `createComponent` does on the client and on the server. The\n * component's scope takes the next number of the parent scope.\n *\n * @param fn The component call, run synchronously, once.\n * @returns What `fn` returns. Without a scope in effect, `fn` simply runs.\n * @example\n * import { createRootScope, enterComponent, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * withScope(createRootScope(), () => {\n * nextKey(); // \"0-0\"\n * return enterComponent(() => nextKey()); // \"0-1-0\": the component's first key\n * });\n * @since 1.0.0\n */\nexport function enterComponent<T>(fn: () => T): T {\n const parent = current;\n if (parent === null) return fn();\n return withScope({ id: `${parent.id}${parent.count++}-`, count: 0, resources: 0 }, fn);\n}\n\n/**\n * Draws the key of the next template root in the current scope: what `template()` and\n * `ssrHydrationKey()` call, in the same order on the server and the client. Each call advances the\n * scope.\n *\n * @returns The key (`\"0-0\"`, `\"0-1\"`, ...); undefined outside a scope.\n * @example\n * import { claimElement, nextKey } from \"@shadow-js/web/extend\";\n *\n * function createBadge(): Element {\n * return claimElement(nextKey()) ?? document.createElement(\"span\");\n * }\n * @see claimElement\n * @since 1.0.0\n */\nexport function nextKey(): string | undefined {\n const scope = current;\n if (scope === null) return undefined;\n return `${scope.id}${scope.count++}`;\n}\n\n/**\n * Returns the key a resource's value is stored under in the server data, the same on the server and\n * the client: the explicit key when there is one, else one drawn from the current scope.\n *\n * @param explicit The resource's own key. When given, the result is `` `k:${explicit}` ``, a prefix\n * no generated key has. Undefined draws the next resource key of the scope.\n * @returns `` `k:${explicit}` ``; otherwise the scope id, `r` and the creation index (`\"0-1-r0\"`);\n * `\"r\"` outside a scope.\n * @example\n * import { createRootScope, resourceKey, withScope } from \"@shadow-js/web/extend\";\n *\n * withScope(createRootScope(), () => [resourceKey(undefined), resourceKey(\"user\")]);\n * // [\"0-r0\", \"k:user\"]\n * @since 1.0.0\n */\nexport function resourceKey(explicit: string | undefined): string {\n if (explicit !== undefined) return `k:${explicit}`;\n const scope = current;\n if (scope === null) return \"r\";\n return `${scope.id}r${scope.resources++}`;\n}\n\n/**\n * Creates a fresh scope for an isolated part of the tree, such as a Suspense boundary's content or\n * fallback, or a portal's content: its keys depend only on `key`, not on the siblings around it.\n *\n * @param key The key of the boundary (from `nextKey()`); undefined means no scope.\n * @returns A scope whose `id` is `` `${key}-` ``; `null` when `key` is undefined.\n * @example\n * import { childScope, nextKey, withScope } from \"@shadow-js/web/extend\";\n *\n * function renderIsolated<T>(build: () => T): T {\n * return withScope(childScope(nextKey()), build);\n * }\n * @see withScope\n * @since 1.0.0\n */\nexport function childScope(key: string | undefined): HydrationScope | null {\n return key === undefined ? null : { id: `${key}-`, count: 0, resources: 0 };\n}\n"],"mappings":"AAkBA,IAAIA,EAAiC,KAiBrC,SAAgBC,EAAgB,EAAW,IAAqB,CAC9D,MAAO,CAAE,GAAI,GAAGC,EAAS,GAAI,MAAO,EAAG,UAAW,CAAE,CACtD,CAeA,SAAgBC,GAAsC,CACpD,OAAOH,CACT,CAiBA,SAAgBI,EAAa,EAA8B,EAAgB,CACzE,IAAMC,EAAWL,EACjB,EAAUM,EACV,GAAI,CACF,OAAOC,EAAG,CACZ,QAAU,CACR,EAAUF,CACZ,CACF,CAkBA,SAAgBG,EAAkB,EAAgB,CAChD,IAAMC,EAAST,EAEf,OADIS,IAAW,KAAaF,EAAG,EACxBH,EAAU,CAAE,GAAI,GAAGK,EAAO,KAAK,EAAO,QAAQ,GAAI,MAAO,EAAG,UAAW,CAAE,EAAGF,CAAE,CACvF,CAiBA,SAAgBG,GAA8B,CAC5C,IAAMJ,EAAQN,EACd,GAAIM,IAAU,KACd,MAAO,GAAGA,EAAM,KAAK,EAAM,SAC7B,CAiBA,SAAgBK,EAAY,EAAsC,CAChE,GAAIC,IAAa,IAAA,GAAW,MAAO,KAAKA,IACxC,IAAMN,EAAQN,EAEd,OADIM,IAAU,KAAa,IACpB,GAAGA,EAAM,GAAG,GAAG,EAAM,aAC9B,CAiBA,SAAgBO,EAAW,EAAgD,CACzE,OAAOC,IAAQ,IAAA,GAAY,KAAO,CAAE,GAAI,GAAGA,EAAI,GAAI,MAAO,EAAG,UAAW,CAAE,CAC5E,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.js","names":["HTML_NS","SVG_NS","MATHML_NS"],"sources":["../../../src/internal/names.ts"],"sourcesContent":["/**\n * The XHTML namespace URI: the `namespaceURI` of ordinary HTML elements.\n *\n * @example\n * import { HTML_NS } from \"@shadow-js/web/extend\";\n *\n * const isHtml = (el: Element): boolean => el.namespaceURI === HTML_NS;\n * @since 1.0.0\n */\nexport const HTML_NS = \"http://www.w3.org/1999/xhtml\";\n/**\n * The SVG namespace URI, for `createElementNS` and `namespaceURI` checks.\n *\n * @example\n * import { SVG_NS } from \"@shadow-js/web/extend\";\n *\n * const circle = document.createElementNS(SVG_NS, \"circle\");\n * @since 1.0.0\n */\nexport const SVG_NS = \"http://www.w3.org/2000/svg\";\n/**\n * The MathML namespace URI, for `createElementNS` and `namespaceURI` checks.\n *\n * @example\n * import { MATHML_NS } from \"@shadow-js/web/extend\";\n *\n * const fraction = document.createElementNS(MATHML_NS, \"mfrac\");\n * @since 1.0.0\n */\nexport const MATHML_NS = \"http://www.w3.org/1998/Math/MathML\";\n\n/** `template()` flag: the markup is SVG. @internal */\nexport const TEMPLATE_SVG = 1;\n/** `template()` flag: the markup is MathML. @internal */\nexport const TEMPLATE_MATHML = 2;\n/** `template()` flag: clone with `document.importNode` (custom elements). @internal */\nexport const TEMPLATE_IMPORT_NODE = 4;\n"],"mappings":"AASA,MAAaA,EAAU,+BAUVC,EAAS,6BAUTC,EAAY,qC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal-context.js","names":["PortalContext"],"sources":["../../../src/internal/portal-context.ts"],"sourcesContent":["import { type Context, createContext } from \"@shadow-js/core\";\n\n/**\n * Receives the markup of the portals a server render produces: what {@link PortalContext} provides\n * when the render was given a `portals` collector.\n * @since 1.0.0\n */\nexport interface PortalSink {\n /**\n * Records the markup of the portal with hydration key `key`. A key recorded again replaces the\n * earlier markup. Throws an `SsrError` whose `code` is `SSR_PORTAL_LIMIT` past 256 portals in one\n * render.\n */\n add(key: string, html: string): void;\n}\n\n/**\n * The context through which a server render hands portals their collector: the renderers provide it\n * when they are given a `portals` option (see `createServerPortals`). A custom portal reads it on the\n * server and records its markup under its hydration key, so the client's `claimPortal` adopts it.\n * Its value is `null` for every other render, and in the browser, where a portal writes nothing on\n * the server.\n *\n * @example\n * import { useContext } from \"@shadow-js/core\";\n * import { nextKey, PortalContext } from \"@shadow-js/web/extend\";\n * import { escape } from \"@shadow-js/web/server\";\n *\n * function ServerToast(props: { text: string }): null {\n * const key = nextKey();\n * const sink = useContext(PortalContext);\n * if (sink !== null && key !== undefined) sink.add(key, `<div role=\"status\">${escape(props.text)}</div>`);\n * return null;\n * }\n * @see claimPortal\n * @since 1.0.0\n */\nexport const PortalContext: Context<PortalSink | null> =\n /* @__PURE__ */ createContext<PortalSink | null>(null, {\n name: \"Portal\",\n });\n"],"mappings":"A,gDAqCA,MAAaA,EACK,kBAAiC,KAAM,CACrD,KAAM,QACR,CAAC,E"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=/^(?:alignment|baseline|clip|color|dominant|enable|fill|flood|font|glyph|image|letter|lighting|marker|mask|mix|paint|pointer|shape|stop|stroke|text|transform|unicode|vector|white|word|writing)(?=[A-Z])/,t=/* @__PURE__ */ new Set([`clipPathUnits`,`glyphRef`,`markerHeight`,`markerUnits`,`markerWidth`,`maskContentUnits`,`maskUnits`,`textLength`]);function n(n,i){if(n===`className`)return`class`;if(n===`htmlFor`)return`for`;if(n===`httpEquiv`)return`http-equiv`;if(n===`acceptCharset`)return`accept-charset`;if(!i)return n.toLowerCase();if(n.includes(`:`))return n;let a=/^xlink([A-Z].*)$/.exec(n);if(a!==null)return`xlink:${r(a[1]??``)}`;let o=/^xml([A-Z].*)$/.exec(n);return o===null?t.has(n)||!e.test(n)?n:n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`):`xml:${r(o[1]??``)}`}function r(e){return e.replace(/^[A-Z]/,e=>e.toLowerCase())}const i=/* @__PURE__ */ new Set([`key`,`suppressHydrationWarning`,`suppressContentEditableWarning`]),a=/* @__PURE__ */ new Set([`checkbox`,`radio`,`file`]);function o(e,t,n){let r=/^on[A-Z]/.test(e),i=r&&e.endsWith(`Capture`),o=e.slice(2,i?-7:void 0);if(!r)return{type:o.toLowerCase(),capture:!1,passive:!1};let s=o.toLowerCase();return s===`change`?{type:t===`textarea`||t===`input`&&(n===null||!a.has(n))?`input`:`change`,capture:i,passive:!1}:s===`focus`?{type:`focusin`,capture:i,passive:!1}:s===`blur`?{type:`focusout`,capture:i,passive:!1}:s===`doubleclick`?{type:`dblclick`,capture:i,passive:!1}:s===`wheel`?{type:`wheel`,capture:i,passive:!i}:{type:s,capture:i,passive:!1}}export{i as IGNORED_KEYS,n as attributeName,o as eventPlan};
|
|
2
|
+
//# sourceMappingURL=react-names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-names.js","names":["SVG_PROPERTY_FAMILY","SVG_CAMEL_ATTRIBUTES","attributeName","name","svg","xlink","lowerFirst","xml","letter","text","IGNORED_KEYS","CHANGE_ON_TYPES","eventPlan","reactSpelling","attribute","capture","base","lower","tag","type"],"sources":["../../../src/internal/react-names.ts"],"sourcesContent":["/**\n * React spellings at run time: the attribute and event names that a props object (a spread) passes\n * through. The compiler resolves the same names at build time (`packages/compiler/src/internal/\n * react-names.ts`); a test keeps the two presentation lists equal, so keep them in step.\n *\n * @internal\n */\n\n/**\n * SVG presentation attributes are CSS properties, and React spells them in camelCase (`strokeWidth` is\n * `stroke-width`). A camelCase name whose first word is one of these families is hyphenated. The\n * families are the first words of the CSS properties SVG takes as attributes, so one rule covers the\n * presentation list. The compiler's table (`packages/compiler/src/internal/react-names.ts`) lists the\n * same names, and a test checks each one.\n */\nconst SVG_PROPERTY_FAMILY =\n /^(?:alignment|baseline|clip|color|dominant|enable|fill|flood|font|glyph|image|letter|lighting|marker|mask|mix|paint|pointer|shape|stop|stroke|text|transform|unicode|vector|white|word|writing)(?=[A-Z])/;\n\n/**\n * SVG attributes that start with a property family but are not CSS properties (`clipPathUnits`,\n * `markerWidth`): they are camelCase in SVG, so they keep their case.\n */\nconst SVG_CAMEL_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"clipPathUnits\",\n \"glyphRef\",\n \"markerHeight\",\n \"markerUnits\",\n \"markerWidth\",\n \"maskContentUnits\",\n \"maskUnits\",\n \"textLength\",\n]);\n\n/**\n * The attribute name for a props key on an element: HTML names are lower case (what the parser and\n * `setAttribute` write anyway, and what server markup needs); SVG presentation names are hyphenated,\n * `xlinkHref` and `xmlLang` take their prefix, and other SVG names keep their case (`viewBox`).\n * @internal\n */\nexport function attributeName(name: string, svg: boolean): string {\n if (name === \"className\") return \"class\";\n if (name === \"htmlFor\") return \"for\";\n if (name === \"httpEquiv\") return \"http-equiv\";\n if (name === \"acceptCharset\") return \"accept-charset\";\n if (!svg) return name.toLowerCase();\n if (name.includes(\":\")) return name;\n const xlink = /^xlink([A-Z].*)$/.exec(name);\n if (xlink !== null) return `xlink:${lowerFirst(xlink[1] ?? \"\")}`;\n const xml = /^xml([A-Z].*)$/.exec(name);\n if (xml !== null) return `xml:${lowerFirst(xml[1] ?? \"\")}`;\n if (SVG_CAMEL_ATTRIBUTES.has(name) || !SVG_PROPERTY_FAMILY.test(name)) return name;\n return name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n}\n\nfunction lowerFirst(text: string): string {\n return text.replace(/^[A-Z]/, (letter) => letter.toLowerCase());\n}\n\n/** Props that have no DOM form: a spread ignores them (React's `key` and hydration flags). @internal */\nexport const IGNORED_KEYS: ReadonlySet<string> = new Set([\n \"key\",\n \"suppressHydrationWarning\",\n \"suppressContentEditableWarning\",\n]);\n\n/** The DOM event for a React-spelled prop (see the compiler's `eventPlan`). @internal */\nexport interface EventPlan {\n readonly type: string;\n readonly capture: boolean;\n readonly passive: boolean;\n}\n\nconst CHANGE_ON_TYPES: ReadonlySet<string> = new Set([\"checkbox\", \"radio\", \"file\"]);\n\n/**\n * Plans the DOM event for an `on*` prop. React's spellings follow React: `onChange` is the per-edit\n * `input` event on text inputs and textareas and the `change` event on other controls; `onFocus` and\n * `onBlur` bubble as `focusin` and `focusout`; a `...Capture` suffix binds the capture phase; `onWheel`\n * is passive. A lower-case `on` spelling is the native event.\n * @internal\n */\nexport function eventPlan(attribute: string, tag: string, type: string | null): EventPlan {\n const reactSpelling = /^on[A-Z]/.test(attribute);\n const capture = reactSpelling && attribute.endsWith(\"Capture\");\n const base = attribute.slice(2, capture ? -\"Capture\".length : undefined);\n if (!reactSpelling) return { type: base.toLowerCase(), capture: false, passive: false };\n const lower = base.toLowerCase();\n if (lower === \"change\") {\n const perEdit =\n tag === \"textarea\" || (tag === \"input\" && (type === null || !CHANGE_ON_TYPES.has(type)));\n return { type: perEdit ? \"input\" : \"change\", capture, passive: false };\n }\n if (lower === \"focus\") return { type: \"focusin\", capture, passive: false };\n if (lower === \"blur\") return { type: \"focusout\", capture, passive: false };\n if (lower === \"doubleclick\") return { type: \"dblclick\", capture, passive: false };\n if (lower === \"wheel\") return { type: \"wheel\", capture, passive: !capture };\n return { type: lower, capture, passive: false };\n}\n"],"mappings":"AAeA,MAAMA,EACJ,2MAMIC,kBAA4C,IAAI,IAAI,CACxD,gBACA,WACA,eACA,cACA,cACA,mBACA,YACA,YACF,CAAC,EAQD,SAAgBC,EAAc,EAAc,EAAsB,CAChE,GAAIC,IAAS,YAAa,MAAO,QACjC,GAAIA,IAAS,UAAW,MAAO,MAC/B,GAAIA,IAAS,YAAa,MAAO,aACjC,GAAIA,IAAS,gBAAiB,MAAO,iBACrC,GAAI,CAACC,EAAK,OAAOD,EAAK,YAAY,EAClC,GAAIA,EAAK,SAAS,GAAG,EAAG,OAAOA,EAC/B,IAAME,EAAQ,mBAAmB,KAAKF,CAAI,EAC1C,GAAIE,IAAU,KAAM,MAAO,SAASC,EAAWD,EAAM,IAAM,EAAE,IAC7D,IAAME,EAAM,iBAAiB,KAAKJ,CAAI,EAGtC,OAFII,IAAQ,KACRN,EAAqB,IAAIE,CAAI,GAAK,CAACH,EAAoB,KAAKG,CAAI,EAAUA,EACvEA,EAAK,QAAQ,SAAW,GAAW,IAAIK,EAAO,YAAY,GAAG,EAF3C,OAAOF,EAAWC,EAAI,IAAM,EAAE,GAGzD,CAEA,SAASD,EAAW,EAAsB,CACxC,OAAOG,EAAK,QAAQ,SAAW,GAAWD,EAAO,YAAY,CAAC,CAChE,CAGA,MAAaE,kBAAoC,IAAI,IAAI,CACvD,MACA,2BACA,gCACF,CAAC,EASKC,kBAAuC,IAAI,IAAI,CAAC,WAAY,QAAS,MAAM,CAAC,EASlF,SAAgBC,EAAU,EAAmB,EAAa,EAAgC,CACxF,IAAMC,EAAgB,WAAW,KAAKC,CAAS,EACzCC,EAAUF,GAAiBC,EAAU,SAAS,SAAS,EACvDE,EAAOF,EAAU,MAAM,EAAGC,EAAU,GAAoB,IAAA,EAAS,EACvE,GAAI,CAACF,EAAe,MAAO,CAAE,KAAMG,EAAK,YAAY,EAAG,QAAS,GAAO,QAAS,EAAM,EACtF,IAAMC,EAAQD,EAAK,YAAY,EAU/B,OATIC,IAAU,SAGL,CAAE,KADPC,IAAQ,YAAeA,IAAQ,UAAYC,IAAS,MAAQ,CAACR,EAAgB,IAAIQ,CAAI,GAC9D,QAAU,SAAU,UAAS,QAAS,EAAM,EAEnEF,IAAU,QAAgB,CAAE,KAAM,UAAW,UAAS,QAAS,EAAM,EACrEA,IAAU,OAAe,CAAE,KAAM,WAAY,UAAS,QAAS,EAAM,EACrEA,IAAU,cAAsB,CAAE,KAAM,WAAY,UAAS,QAAS,EAAM,EAC5EA,IAAU,QAAgB,CAAE,KAAM,QAAS,UAAS,QAAS,CAACF,CAAQ,EACnE,CAAE,KAAME,EAAO,UAAS,QAAS,EAAM,CAChD,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e,t){t!==void 0&&t.parentNode===e&&e.removeChild(t)}function t(e,t,n){let r=[],i=e.map(()=>-1);for(let t=0;t<e.length;t+=1){let n=e[t]??0,a=0,o=r.length;for(;a<o;){let t=a+o>>1;(e[r[t]??0]??0)<n?a=t+1:o=t}i[t]=a>0?r[a-1]??-1:-1,r[a]=t}let a=r.length>0?r[r.length-1]??-1:-1;for(;a!==-1;)n[(e[a]??0)-t]=1,a=i[a]??-1}function n(n,r,i,a){let o=r.length,s=i.length,c=0;for(;c<o&&c<s&&r[c]===i[c];)c+=1;let l=o,u=s;for(;l>c&&u>c&&r[l-1]===i[u-1];)--l,--u;if(l===c&&u===c)return;let d=u<s?i[u]??null:a;if(u===c){for(let t=c;t<l;t+=1)e(n,r[t]);return}let f=/* @__PURE__ */ new Map;for(let e=c;e<u;e+=1){let t=i[e];t!==void 0&&f.set(t,e)}let p=[];for(let t=c;t<l;t+=1){let i=r[t];if(i===void 0)continue;let a=f.get(i);a===void 0?e(n,i):p.push(a)}if(p.length===0){for(let e=c;e<u;e+=1){let t=i[e];t!==void 0&&n.insertBefore(t,d)}return}let m=new Uint8Array(u-c);t(p,c,m);let h=typeof n.moveBefore==`function`,g=d;for(let e=u-1;e>=c;--e){let t=i[e];t!==void 0&&(m[e-c]!==1&&(h&&t.parentNode===n?n.moveBefore(t,g):n.insertBefore(t,g)),g=t)}}export{n as reconcileNodes};
|
|
2
|
+
//# sourceMappingURL=reconcile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile.js","names":["removeNode","node","parent","markLongestIncreasing","tails","previous","values","index","value","low","high","middle","cursor","offset","reconcileNodes","prevLength","prev","nextLength","next","head","prevTail","nextTail","before","end","target","survivors","position","stable","movable","anchorNode"],"sources":["../../../src/internal/reconcile.ts"],"sourcesContent":["/** A parent that can move a child in place (Element.prototype.moveBefore, where implemented). */\ninterface MovableParent extends Node {\n moveBefore(node: Node, child: Node | null): void;\n}\n\n/** Removes `node` only when it is still a child of `parent`, so detached nodes are ignored. */\nfunction removeNode(parent: Node, node: Node | undefined): void {\n if (node !== undefined && node.parentNode === parent) parent.removeChild(node);\n}\n\n/**\n * Marks the members of one longest strictly increasing subsequence of `values` in `marks`, where\n * `values[k]` is the target position of the k-th surviving node and `marks[v - offset]` is set for\n * target position `v`. Patience sorting: O(n log n).\n */\nfunction markLongestIncreasing(values: readonly number[], offset: number, marks: Uint8Array): void {\n // tails[k]: index into `values` of the smallest tail of an increasing run of length k + 1.\n const tails: number[] = [];\n const previous: number[] = values.map(() => -1);\n for (let index = 0; index < values.length; index += 1) {\n const value = values[index] ?? 0;\n let low = 0;\n let high = tails.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n const probe = values[tails[middle] ?? 0] ?? 0;\n if (probe < value) low = middle + 1;\n else high = middle;\n }\n previous[index] = low > 0 ? (tails[low - 1] ?? -1) : -1;\n tails[low] = index;\n }\n let cursor = tails.length > 0 ? (tails[tails.length - 1] ?? -1) : -1;\n while (cursor !== -1) {\n marks[(values[cursor] ?? 0) - offset] = 1;\n cursor = previous[cursor] ?? -1;\n }\n}\n\n/**\n * Updates one region of `parent`'s children from the nodes `prev` to the nodes `next`, keeping every\n * node that stays and moving as few as possible: the list reconciliation `insert` performs for arrays\n * (and so for `For`). Use it in a custom list renderer.\n *\n * Preconditions: `prev` are the nodes this region owns, in DOM order and all children of `parent`;\n * `next` holds no duplicates; `end` is the node after the region (null for the end of `parent`).\n *\n * Strategy, in three steps:\n * 1. Trim the common prefix and suffix: appends, prepends, and removals at either end touch\n * only the nodes that changed (no move at all).\n * 2. Remove the nodes that left the value. A node that is still present is never removed.\n * 3. Place the rest from the end of `next` backwards. Nodes on a longest increasing subsequence of\n * surviving positions stay where they are; every other node is moved (or inserted) directly\n * before the node that follows it in `next`. Moves use `moveBefore` when the parent has it,\n * which keeps focus and iframe state, and `insertBefore` otherwise. Each node moves at most once,\n * and the number of moves is minimal for the surviving order.\n *\n * @param parent The parent of the region.\n * @param prev The nodes the region holds now, in DOM order, all children of `parent`.\n * @param next The nodes the region must hold, in order, without duplicates. A node of `prev` that is\n * not in `next` is removed; a node of `next` that is not in `prev` is inserted.\n * @param end The node right after the region; `null` when the region runs to the end of `parent`.\n * @example\n * import { reconcileNodes } from \"@shadow-js/web/extend\";\n *\n * const item = (text: string): HTMLLIElement =>\n * Object.assign(document.createElement(\"li\"), { textContent: text });\n * const list = document.createElement(\"ul\");\n * const a = item(\"a\");\n * const b = item(\"b\");\n * const c = item(\"c\");\n * list.append(a, b, c);\n * reconcileNodes(list, [a, b, c], [c, a], null); // removes b, moves c before a\n * @since 1.0.0\n */\nexport function reconcileNodes(\n parent: Node,\n prev: readonly Node[],\n next: readonly Node[],\n end: Node | null,\n): void {\n const prevLength = prev.length;\n const nextLength = next.length;\n\n let head = 0;\n while (head < prevLength && head < nextLength && prev[head] === next[head]) head += 1;\n let prevTail = prevLength;\n let nextTail = nextLength;\n while (prevTail > head && nextTail > head && prev[prevTail - 1] === next[nextTail - 1]) {\n prevTail -= 1;\n nextTail -= 1;\n }\n if (prevTail === head && nextTail === head) return;\n\n // Everything in the common suffix is already in place, so the middle goes before its first node.\n const before = nextTail < nextLength ? (next[nextTail] ?? null) : end;\n\n if (nextTail === head) {\n for (let index = head; index < prevTail; index += 1) removeNode(parent, prev[index]);\n return;\n }\n\n const target = new Map<Node, number>();\n for (let index = head; index < nextTail; index += 1) {\n const node = next[index];\n if (node !== undefined) target.set(node, index);\n }\n\n const survivors: number[] = [];\n for (let index = head; index < prevTail; index += 1) {\n const node = prev[index];\n if (node === undefined) continue;\n const position = target.get(node);\n if (position === undefined) removeNode(parent, node);\n else survivors.push(position);\n }\n\n if (survivors.length === 0) {\n for (let index = head; index < nextTail; index += 1) {\n const node = next[index];\n if (node !== undefined) parent.insertBefore(node, before);\n }\n return;\n }\n\n const stable = new Uint8Array(nextTail - head);\n markLongestIncreasing(survivors, head, stable);\n const movable = typeof (parent as Partial<MovableParent>).moveBefore === \"function\";\n\n let anchorNode = before;\n for (let index = nextTail - 1; index >= head; index -= 1) {\n const node = next[index];\n if (node === undefined) continue;\n if (stable[index - head] !== 1) {\n if (movable && node.parentNode === parent)\n (parent as MovableParent).moveBefore(node, anchorNode);\n else parent.insertBefore(node, anchorNode);\n }\n anchorNode = node;\n }\n}\n"],"mappings":"AAMA,SAASA,EAAW,EAAc,EAA8B,CAC1DC,IAAS,IAAA,IAAaA,EAAK,aAAeC,GAAQA,EAAO,YAAYD,CAAI,CAC/E,CAOA,SAASE,EAAsB,EAA2B,EAAgB,EAAyB,CAEjG,IAAMC,EAAkB,CAAC,EACnBC,EAAqBC,EAAO,QAAU,EAAE,EAC9C,IAAK,IAAIC,EAAQ,EAAGA,EAAQD,EAAO,OAAQ,GAAS,EAAG,CACrD,IAAME,EAAQF,EAAOC,IAAU,EAC3BE,EAAM,EACNC,EAAON,EAAM,OACjB,KAAOK,EAAMC,GAAM,CACjB,IAAMC,EAAUF,EAAMC,GAAS,GACjBJ,EAAOF,EAAMO,IAAW,IAAM,GAChCH,EAAO,EAAMG,EAAS,EAC7B,EAAOA,CACd,CACA,EAASJ,GAASE,EAAM,EAAKL,EAAMK,EAAM,IAAM,GAAM,GACrD,EAAMA,GAAOF,CACf,CACA,IAAIK,EAASR,EAAM,OAAS,EAAKA,EAAMA,EAAM,OAAS,IAAM,GAAM,GAClE,KAAOQ,IAAW,IAChB,GAAON,EAAOM,IAAW,GAAKC,GAAU,EACxC,EAASR,EAASO,IAAW,EAEjC,CAsCA,SAAgBE,EACd,EACA,EACA,EACA,EACM,CACN,IAAMC,EAAaC,EAAK,OAClBC,EAAaC,EAAK,OAEpBC,EAAO,EACX,KAAOA,EAAOJ,GAAcI,EAAOF,GAAcD,EAAKG,KAAUD,EAAKC,IAAO,GAAQ,EACpF,IAAIC,EAAWL,EACXM,EAAWJ,EACf,KAAOG,EAAWD,GAAQE,EAAWF,GAAQH,EAAKI,EAAW,KAAOF,EAAKG,EAAW,IAClF,IACA,IAEF,GAAID,IAAaD,GAAQE,IAAaF,EAAM,OAG5C,IAAMG,EAASD,EAAWJ,EAAcC,EAAKG,IAAa,KAAQE,EAElE,GAAIF,IAAaF,EAAM,CACrB,IAAK,IAAIZ,EAAQY,EAAMZ,EAAQa,EAAU,GAAS,EAAGpB,EAAWE,EAAQc,EAAKT,EAAM,EACnF,MACF,CAEA,IAAMiB,kBAAS,IAAI,IACnB,IAAK,IAAIjB,EAAQY,EAAMZ,EAAQc,EAAU,GAAS,EAAG,CACnD,IAAMpB,EAAOiB,EAAKX,GACdN,IAAS,IAAA,IAAWuB,EAAO,IAAIvB,EAAMM,CAAK,CAChD,CAEA,IAAMkB,EAAsB,CAAC,EAC7B,IAAK,IAAIlB,EAAQY,EAAMZ,EAAQa,EAAU,GAAS,EAAG,CACnD,IAAMnB,EAAOe,EAAKT,GAClB,GAAIN,IAAS,IAAA,GAAW,SACxB,IAAMyB,EAAWF,EAAO,IAAIvB,CAAI,EAC5ByB,IAAa,IAAA,GAAW1B,EAAWE,EAAQD,CAAI,EAC9CwB,EAAU,KAAKC,CAAQ,CAC9B,CAEA,GAAID,EAAU,SAAW,EAAG,CAC1B,IAAK,IAAIlB,EAAQY,EAAMZ,EAAQc,EAAU,GAAS,EAAG,CACnD,IAAMpB,EAAOiB,EAAKX,GACdN,IAAS,IAAA,IAAWC,EAAO,aAAaD,EAAMqB,CAAM,CAC1D,CACA,MACF,CAEA,IAAMK,EAAS,IAAI,WAAWN,EAAWF,CAAI,EAC7ChB,EAAsBsB,EAAWN,EAAMQ,CAAM,EAC7C,IAAMC,EAAU,OAAQ1B,EAAkC,YAAe,WAErE2B,EAAaP,EACjB,IAAK,IAAIf,EAAQc,EAAW,EAAGd,GAASY,EAAM,IAAY,CACxD,IAAMlB,EAAOiB,EAAKX,GACdN,IAAS,IAAA,KACT0B,EAAOpB,EAAQY,KAAU,IACvBS,GAAW3B,EAAK,aAAeC,EACjCA,EAA0B,WAAWD,EAAM4B,CAAU,EAClD3B,EAAO,aAAaD,EAAM4B,CAAU,GAE3C,EAAa5B,EACf,CACF,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-context.js","names":["StreamContext"],"sources":["../../../src/internal/stream-context.ts"],"sourcesContent":["import { type Context, createContext } from \"@shadow-js/core\";\n\n/**\n * A Suspense boundary whose content was not ready when the shell rendered: `renderToStream` calls\n * `rebuild` again each time a resource settles, and streams the markup once it is complete.\n * @since 1.0.0\n */\nexport interface StreamBoundary {\n /**\n * The boundary's hydration key. The shell must wrap the fallback in `<!--[b:ID-->` and `<!--]-->`\n * comments so the streamed chunk can replace it.\n */\n readonly id: string;\n /**\n * Renders the content again. Returns its final markup, or `null` when it is still pending, in which\n * case it has deferred itself again with {@link StreamSink.defer}.\n */\n rebuild(): string | null;\n}\n\n/**\n * Receives the boundaries that are still pending during a streaming render: what\n * {@link StreamContext} provides.\n * @since 1.0.0\n */\nexport interface StreamSink {\n /** Queues `boundary` to be rebuilt when the next resource settles. */\n defer(boundary: StreamBoundary): void;\n}\n\n/**\n * The context through which `renderToStream` lets a Suspense-like boundary defer its content: a\n * boundary that is pending in the shell renders its fallback between `<!--[b:ID-->` and `<!--]-->`\n * and defers a {@link StreamBoundary} to the sink. Its value is `null` for every other render (the\n * boundary then keeps its fallback).\n *\n * @example\n * import { useContext } from \"@shadow-js/core\";\n * import { StreamContext } from \"@shadow-js/web/extend\";\n *\n * function canStream(): boolean {\n * // Inside a component rendered by renderToStream.\n * return useContext(StreamContext) !== null;\n * }\n * @since 1.0.0\n */\nexport const StreamContext: Context<StreamSink | null> =\n /* @__PURE__ */ createContext<StreamSink | null>(null, {\n name: \"Stream\",\n });\n"],"mappings":"A,gDA8CA,MAAaA,EACK,kBAAiC,KAAM,CACrD,KAAM,QACR,CAAC,E"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{getOwner as e,onCleanup as t,untrack as n,useMemo as r,useRenderEffect as i}from"@shadow-js/core";function a(e,t){t===void 0?i(e):i(e,t)}function o(e){return r(e)}function s(e,r,i){let a=n(()=>e(r,i));typeof a==`function`&&t(a)}function c(n,r){if(typeof n==`function`){s(n,r);return}if(typeof n!=`object`||!n||!(`current`in n))return;let i=n;i.current=r,e()!==null&&t(()=>{i.current=null})}export{a as effect,o as memo,c as refTo,s as use};
|
|
2
|
+
//# sourceMappingURL=reactive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactive.js","names":["effect","apply","useRenderEffect","compute","memo","useMemo","fn","use","cleanup","untrack","el","arg","onCleanup","refTo","target","holder","getOwner"],"sources":["../../src/reactive.ts"],"sourcesContent":["import {\n type Cleanup,\n getOwner,\n onCleanup,\n untrack,\n useMemo,\n useRenderEffect,\n} from \"@shadow-js/core\";\n\n/**\n * Runs `fn` as a render effect: synchronously when created, and again when the signals it reads\n * change. It is the effect the compiler emits for DOM bindings; application code usually prefers\n * `useEffect`. A function returned by `fn` is its cleanup, run before the next run and when the\n * owner disposes. It never runs on the server, and in development an effect created outside an\n * owner warns `NO_OWNER_EFFECT`.\n *\n * @param fn Tracked body. Returns an optional cleanup function.\n * @example\n * import { createRoot, useSignal } from \"@shadow-js/core\";\n * import { effect } from \"@shadow-js/web\";\n *\n * const label = document.createElement(\"span\");\n * createRoot(() => {\n * const [name] = useSignal(\"Ada\");\n * effect(() => {\n * label.textContent = name(); // runs now, and again when name changes\n * });\n * });\n * @see memo\n * @since 1.0.0\n */\nexport function effect(fn: () => void | Cleanup): void;\n/**\n * Two-form render effect: `compute` is tracked and `apply` runs untracked with the new and the\n * previous value. A function returned by `apply` is its cleanup. Use it to keep the tracked reads\n * apart from the code that writes the DOM.\n *\n * @param compute Tracked. Its result is passed to `apply`.\n * @param apply Untracked. Receives the value and the previous value (`undefined` on the first run)\n * and returns an optional cleanup function.\n * @example\n * import { createRoot, useSignal } from \"@shadow-js/core\";\n * import { effect } from \"@shadow-js/web\";\n *\n * const title = document.createElement(\"h1\");\n * createRoot(() => {\n * const [text] = useSignal(\"Hello\");\n * effect(text, (value, previous) => {\n * title.textContent = value;\n * console.log(previous); // undefined on the first run\n * });\n * });\n * @see memo\n * @since 1.0.0\n */\nexport function effect<T>(\n compute: () => T,\n apply: (value: T, previous: T | undefined) => void | Cleanup,\n): void;\nexport function effect<T>(\n compute: () => T,\n apply?: (value: T, previous: T | undefined) => void | Cleanup,\n): void {\n if (apply === undefined) useRenderEffect(compute);\n else useRenderEffect(compute, apply);\n}\n\n/**\n * Creates a cached derivation that recomputes only when the signals it reads change. It is core's\n * `useMemo` under the short name the compiler emits.\n *\n * @param fn The computation. Tracked; its result is cached until a dependency changes.\n * @returns An accessor for the current value.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { memo } from \"@shadow-js/web\";\n *\n * function setup() {\n * const [count, setCount] = useSignal(2);\n * const doubled = memo(() => count() * 2);\n * setCount(4);\n * console.log(doubled()); // 8\n * }\n * @see effect\n * @since 1.0.0\n */\nexport function memo<T>(fn: () => T): () => T {\n return useMemo<T>(fn);\n}\n\n/**\n * Applies a directive: calls `fn(el, arg)` untracked, so a directive or a ref never subscribes the\n * surrounding effect to what it reads. A function returned by `fn` is a cleanup, run when the owner\n * disposes.\n *\n * @param fn The directive. Receives the element and the accessor of its argument.\n * @param el The element the directive applies to.\n * @param arg Accessor for the directive's argument. Undefined passes `undefined` through; the\n * directive reads the accessor where it wants to track it.\n * @example\n * import { use } from \"@shadow-js/web\";\n *\n * function tooltip(el: Element, text: () => string) {\n * el.setAttribute(\"title\", text());\n * }\n * const button = document.createElement(\"button\");\n * use(tooltip, button, () => \"Save the draft\");\n * @see refTo\n * @since 1.0.0\n */\nexport function use<T>(\n fn: (el: Element, arg: () => T) => unknown,\n el: Element,\n arg?: () => T,\n): void {\n const cleanup = untrack(() => fn(el, arg as () => T));\n // A ref callback may return a cleanup (React 19): it runs when the owner of the element is disposed.\n if (typeof cleanup === \"function\") onCleanup(cleanup as Cleanup);\n}\n\n/**\n * Fills a ref of any form the compiler accepts. A callback is called with the element (its returned\n * cleanup runs when the owner disposes). A `{ current }` object gets the element as `current`, and\n * `null` once the owner is disposed, as React's `useRef` objects do. Any other value is ignored.\n *\n * @param target The ref value: a callback, a `{ current }` object, or anything else (ignored).\n * @param el The element the ref receives.\n * @example\n * import { refTo } from \"@shadow-js/web\";\n *\n * const box = { current: null as HTMLDivElement | null };\n * const div = document.createElement(\"div\");\n * refTo(box, div);\n * console.log(box.current === div); // true\n * @see use\n * @since 1.0.0\n */\nexport function refTo(target: unknown, el: Element): void {\n if (typeof target === \"function\") {\n use(target as (node: Element, arg: () => unknown) => unknown, el);\n return;\n }\n if (target === null || typeof target !== \"object\" || !(\"current\" in target)) return;\n const holder = target as { current: unknown };\n holder.current = el;\n if (getOwner() !== null) {\n onCleanup(() => {\n holder.current = null;\n });\n }\n}\n"],"mappings":"A,yGA2DA,SAAgBA,EACd,EACA,EACM,CACFC,IAAU,IAAA,GAAWC,EAAgBC,CAAO,EAC3CD,EAAgBC,EAASF,CAAK,CACrC,CAqBA,SAAgBG,EAAQ,EAAsB,CAC5C,OAAOC,EAAWC,CAAE,CACtB,CAsBA,SAAgBC,EACd,EACA,EACA,EACM,CACN,IAAMC,EAAUC,MAAcH,EAAGI,EAAIC,CAAc,CAAC,EAEhD,OAAOH,GAAY,YAAYI,EAAUJ,CAAkB,CACjE,CAmBA,SAAgBK,EAAM,EAAiB,EAAmB,CACxD,GAAI,OAAOC,GAAW,WAAY,CAChCP,EAAIO,EAA0DJ,CAAE,EAChE,MACF,CACA,GAAuB,OAAOI,GAAW,WAArCA,GAAiD,EAAE,YAAaA,GAAS,OAC7E,IAAMC,EAASD,EACf,EAAO,QAAUJ,EACbM,EAAS,IAAM,MACjBJ,MAAgB,CACd,EAAO,QAAU,IACnB,CAAC,CAEL,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{withScope as e}from"./internal/hydration-scope.js";import{claims as t}from"./internal/hydration-hooks.js";import{bindRegion as n,createRegion as r,removeRegion as i}from"./insert.js";import{attachRootErrors as a}from"./control-flow/root-errors.js";import{batch as o,createRoot as s,flushSync as c,untrack as l}from"@shadow-js/core";function u(u,d,f){let p=r(d,null,void 0),m=t.current.withoutClaiming(()=>e(null,()=>o(()=>s(e=>(f!==void 0&&a(f),n(p,l(u)),e)))));c();let h=!1;return()=>{h||(h=!0,m(),i(p))}}export{u as render};
|
|
2
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","names":["render","region","createRegion","container","stop","claims","withScope","batch","createRoot","options","attachRootErrors","bindRegion","untrack","code","dispose","flushSync","disposed","removeRegion"],"sources":["../../src/render.ts"],"sourcesContent":["import { batch, createRoot, flushSync, untrack } from \"@shadow-js/core\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link render}: the error reporters of the root.\n * @since 1.0.0\n */\nexport type RenderOptions = RootErrorOptions;\n\n/**\n * Mounts `code` into `container`. Creates an owner, inserts the output, flushes the effects, and\n * returns a dispose function that stops the owner and removes the nodes this call inserted. A\n * second render into the same container appends after the first.\n *\n * @param code Runs once, untracked, to build the tree (a component call, a node, text or an array).\n * Return an accessor (for example `() => count`) from it to make the root content reactive.\n * @param container Element, Document or DocumentFragment that receives the output.\n * @param options The root's error reporters (`onUncaughtError`, `onCaughtError`). Undefined sets\n * no reporter.\n * @returns A dispose function, safe to call more than once.\n * @example\n * import { createComponent, render } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const dispose = render(\n * () => createComponent(App, {}),\n * document.getElementById(\"root\") as Element,\n * );\n * dispose(); // stops the root and removes the text it inserted\n * @see hydrate\n * @since 1.0.0\n */\nexport function render(\n code: () => unknown,\n container: Element | Document | DocumentFragment,\n options?: RenderOptions,\n): () => void {\n const region = createRegion(container, null, undefined);\n // One batch around the build: effects (and anything a resource's batch would flush mid-build)\n // wait until the whole tree exists, so a Suspense boundary knows what is pending before its\n // content's effects are considered.\n // A fresh root never consumes the enclosing hydration pass's nodes or key sequence.\n const stop = claims.current.withoutClaiming(() =>\n withScope(null, () =>\n batch(() =>\n createRoot((dispose) => {\n // An error nothing else took ends here; with onUncaughtError it is reported instead of thrown.\n if (options !== undefined) attachRootErrors(options);\n // The component tree is built once; only accessors inside the result stay reactive.\n bindRegion(region, untrack(code));\n return dispose;\n }),\n ),\n ),\n );\n flushSync();\n let disposed = false;\n return () => {\n if (disposed) return;\n disposed = true;\n stop();\n removeRegion(region);\n };\n}\n"],"mappings":"A,mVAsCA,SAAgBA,EACd,EACA,EACA,EACY,CACZ,IAAMC,EAASC,EAAaC,EAAW,KAAM,IAAA,EAAS,EAKhDC,EAAOC,EAAO,QAAQ,oBAC1BC,EAAU,SACRC,MACEC,EAAY,IAENC,IAAY,IAAA,IAAWC,EAAiBD,CAAO,EAEnDE,EAAWV,EAAQW,EAAQC,CAAI,CAAC,EACzBC,EACR,CACH,CACF,CACF,EACAC,EAAU,EACV,IAAIC,EAAW,GACf,UAAa,CACPA,IACJ,EAAW,GACXZ,EAAK,EACLa,EAAahB,CAAM,EACrB,CACF,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{useHead as e}from"./head/use-head.js";import{isServer as t}from"@shadow-js/core";function n(e){let t=new URL(e,`https://base.invalid`);if(t.protocol!==`https:`&&t.protocol!==`http:`)throw TypeError(`SHADOW_RESOURCE_HINT_URL`)}function r(e,t){for(let[n,r]of Object.entries(t))if(e.getAttribute(n)!==r)return!1;return!0}function i(e,n,i=()=>void 0){if(t){i();return}if(typeof document>`u`)return;for(let t of document.head.querySelectorAll(e))if(r(t,n))return;let a=document.createElement(e);for(let[e,t]of Object.entries(n))a.setAttribute(e,t);document.head.append(a)}function a(t){return()=>e({tag:`link`,props:t})}function o(e,t){n(e);let r={rel:`preconnect`,href:e,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,r,a(r))}function s(e){n(e);let t={rel:`dns-prefetch`,href:e};i(`link`,t,a(t))}function c(e,t){n(e);let r={rel:`preload`,href:e,as:t.as,...t.type===void 0?{}:{type:t.type},...t.media===void 0?{}:{media:t.media},...t.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,r,a(r))}function l(e,t){n(e);let r={rel:`modulepreload`,href:e,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,r,a(r))}function u(e,t){if(n(e),t.as===`style`){let n={rel:`stylesheet`,href:e,...t.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}};i(`link`,n,a(n))}else i(`script`,{src:e,async:``,...t.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}},a({rel:`preload`,href:e,as:`script`}))}function d(e,t){n(e),i(`script`,{src:e,type:`module`,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}},a({rel:`modulepreload`,href:e,...t?.crossOrigin===void 0?{}:{crossorigin:t.crossOrigin}}))}export{o as preconnect,s as prefetchDNS,u as preinit,d as preinitModule,c as preload,l as preloadModule};
|
|
2
|
+
//# sourceMappingURL=resource-hints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-hints.js","names":["checkUrl","url","href","carries","name","value","attributes","element","hint","isServer","serverTag","existing","tag","serverLink","useHead","preconnect","options","prefetchDNS","preload","preloadModule","preinit","preinitModule"],"sources":["../../src/resource-hints.ts"],"sourcesContent":["import { isServer } from \"@shadow-js/core\";\nimport { useHead } from \"./head/use-head\";\nimport type { HeadAttributeValue } from \"./head/validate\";\n\n/**\n * Options of {@link preconnect}, {@link preloadModule} and {@link preinitModule}.\n * @since 1.0.0\n */\nexport interface CrossOriginOptions {\n /**\n * CORS mode of the connection or request: `\"anonymous\"` sends no credentials, `\"use-credentials\"`\n * sends cookies and client certificates. Fonts and `fetch` preloads need one of them.\n * @default undefined (no `crossorigin` attribute; the browser's default for the resource applies)\n */\n readonly crossOrigin?: \"anonymous\" | \"use-credentials\";\n}\n\n/**\n * Options of {@link preload}: the destination is required, as the browser needs it to pick the\n * right request.\n * @since 1.0.0\n */\nexport interface PreloadOptions extends CrossOriginOptions {\n /**\n * The destination of the request, which the browser uses to pick its priority and headers. It\n * must match how the resource is used later, or the preloaded copy is not reused.\n */\n readonly as:\n | \"audio\"\n | \"document\"\n | \"embed\"\n | \"fetch\"\n | \"font\"\n | \"image\"\n | \"object\"\n | \"script\"\n | \"style\"\n | \"track\"\n | \"video\"\n | \"worker\";\n /**\n * MIME type, so the browser can skip unsupported formats (for example `font/woff2`).\n * @default undefined (no `type` attribute)\n */\n readonly type?: string;\n /**\n * Media query the hint applies to (for example `(min-width: 800px)`); the browser skips the\n * preload when it does not match.\n * @default undefined (no `media` attribute; the hint always applies)\n */\n readonly media?: string;\n}\n\n/**\n * Options of {@link preinit}.\n * @since 1.0.0\n */\nexport interface PreinitOptions extends CrossOriginOptions {\n /**\n * What to load: `\"style\"` inserts a stylesheet, `\"script\"` inserts an async script. Required, as\n * the two produce different elements.\n */\n readonly as: \"style\" | \"script\";\n}\n\ntype Attributes = Readonly<Record<string, string>>;\n\n/** Hints are page-level and only ever use http(s) URLs; anything else throws, like head tags do. */\nfunction checkUrl(href: string): void {\n const url = new URL(href, \"https://base.invalid\");\n if (url.protocol !== \"https:\" && url.protocol !== \"http:\") {\n throw new TypeError(\n __DEV__\n ? `resource hint: \"${href}\" must be an http(s) or relative URL`\n : \"SHADOW_RESOURCE_HINT_URL\",\n );\n }\n}\n\n/** Whether an element already carries every attribute of a hint (so the hint is already there). */\nfunction carries(element: Element, attributes: Attributes): boolean {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) return false;\n }\n return true;\n}\n\n/**\n * Inserts a hint element once: an identical element already in the head (server-rendered or added\n * earlier) is kept. On the server the hint joins the render's head collector, when there is one.\n */\nfunction hint(\n tag: \"link\" | \"script\",\n attributes: Attributes,\n serverTag: () => void = () => undefined,\n): void {\n if (isServer) {\n serverTag();\n return;\n }\n if (typeof document === \"undefined\") return;\n for (const existing of document.head.querySelectorAll(tag)) {\n if (carries(existing, attributes)) return;\n }\n const element = document.createElement(tag);\n for (const [name, value] of Object.entries(attributes)) element.setAttribute(name, value);\n document.head.append(element);\n}\n\n/** Server form of a hint: a head link (scripts cannot be head tags, see {@link preinitModule}). */\nfunction serverLink(attributes: Readonly<Record<string, HeadAttributeValue>>): () => void {\n return () => useHead({ tag: \"link\", props: attributes });\n}\n\n/**\n * Tells the browser to open a connection (DNS, TCP, TLS) to an origin the page will use soon.\n * React's `preconnect`. Calling it again for the same origin adds nothing. Works in a component, in\n * an event handler, or at module scope on the client.\n *\n * @param href An http(s) origin or URL.\n * @param options CORS mode (needed for fonts and fetch with credentials). Undefined adds no\n * `crossorigin` attribute.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or\n * relative.\n * @example\n * import { preconnect } from \"@shadow-js/web\";\n *\n * preconnect(\"https://fonts.example.com\", { crossOrigin: \"anonymous\" });\n * @see prefetchDNS\n * @see preload\n * @since 1.0.0\n */\nexport function preconnect(href: string, options?: CrossOriginOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n rel: \"preconnect\",\n href,\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Resolves an origin's DNS ahead of use. Cheaper than {@link preconnect}; React's `prefetchDNS`.\n * @param href An http(s) origin or URL.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { prefetchDNS } from \"@shadow-js/web\";\n *\n * prefetchDNS(\"https://api.example.com\");\n * @see preconnect\n * @since 1.0.0\n */\nexport function prefetchDNS(href: string): void {\n checkUrl(href);\n const attributes: Attributes = { rel: \"dns-prefetch\", href };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Starts fetching a resource the page will need, at high priority. The browser stores it for the\n * later request with the same URL and destination (React's `preload`).\n *\n * @param href An http(s) or relative URL.\n * @param options The destination (`as`, required) and the optional type, media and CORS mode.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preload } from \"@shadow-js/web\";\n *\n * preload(\"/fonts/inter.woff2\", { as: \"font\", type: \"font/woff2\", crossOrigin: \"anonymous\" });\n * @see preloadModule\n * @see preinit\n * @since 1.0.0\n */\nexport function preload(href: string, options: PreloadOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n rel: \"preload\",\n href,\n as: options.as,\n ...(options.type === undefined ? {} : { type: options.type }),\n ...(options.media === undefined ? {} : { media: options.media }),\n ...(options.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Starts loading an ES module the page will import, so the import does not wait for the module\n * graph to be discovered. React's `preloadModule`.\n * @param href An http(s) or relative URL of the module.\n * @param options CORS mode. Undefined adds no `crossorigin` attribute.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preloadModule } from \"@shadow-js/web\";\n *\n * preloadModule(\"/chunks/editor.js\");\n * @see preinitModule\n * @see preload\n * @since 1.0.0\n */\nexport function preloadModule(href: string, options?: CrossOriginOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n rel: \"modulepreload\",\n href,\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n}\n\n/**\n * Loads a stylesheet or script now, and keeps it applied or executed (React's `preinit`). A\n * stylesheet becomes a `<link rel=\"stylesheet\">`; a script becomes an async `<script>` in the head.\n * On the server a script can only be hinted as a preload, because head tags cannot be scripts.\n *\n * @param href An http(s) or relative URL.\n * @param options What to load (`style` or `script`, required) and the CORS mode.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preinit } from \"@shadow-js/web\";\n *\n * preinit(\"/theme.css\", { as: \"style\" });\n * @see preload\n * @see preinitModule\n * @since 1.0.0\n */\nexport function preinit(href: string, options: PreinitOptions): void {\n checkUrl(href);\n if (options.as === \"style\") {\n const attributes: Attributes = {\n rel: \"stylesheet\",\n href,\n ...(options.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"link\", attributes, serverLink(attributes));\n return;\n }\n const attributes: Attributes = {\n src: href,\n async: \"\",\n ...(options.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\"script\", attributes, serverLink({ rel: \"preload\", href, as: \"script\" }));\n}\n\n/**\n * Loads and runs an ES module now (React's `preinitModule`). On the client it inserts a\n * `<script type=\"module\">`; on the server it hints the module with `modulepreload`, since the\n * script itself is loaded by the page.\n *\n * @param href An http(s) or relative URL of the module.\n * @param options CORS mode. Undefined adds no `crossorigin` attribute.\n * @throws TypeError (production message `SHADOW_RESOURCE_HINT_URL`) for a URL that is not http(s) or relative.\n * @example\n * import { preinitModule } from \"@shadow-js/web\";\n *\n * preinitModule(\"/chunks/app.js\");\n * @see preloadModule\n * @see preinit\n * @since 1.0.0\n */\nexport function preinitModule(href: string, options?: CrossOriginOptions): void {\n checkUrl(href);\n const attributes: Attributes = {\n src: href,\n type: \"module\",\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n };\n hint(\n \"script\",\n attributes,\n serverLink({\n rel: \"modulepreload\",\n href,\n ...(options?.crossOrigin === undefined ? {} : { crossorigin: options.crossOrigin }),\n }),\n );\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e){let t=/* @__PURE__ */ new Set;for(let n of e)n!=null&&t.add(String(n));return t}function t(e){return e==null?``:String(e)}function n(n,r){if(n.multiple&&Array.isArray(r)){let t=e(r);for(let e of Array.from(n.options))e.selected=t.has(e.value)}else n.value=t(r)}function r(n,r){if(n.multiple&&Array.isArray(r)){let t=e(r);return Array.from(n.options).every(e=>e.selected===t.has(e.value))}return n.value===t(r)}export{r as selectShows,n as setSelectValue};
|
|
2
|
+
//# sourceMappingURL=select-value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-value.js","names":["listed","values","item","value","single","setSelectValue","select","wanted","option","selectShows"],"sources":["../../src/select-value.ts"],"sourcesContent":["/** The values an array stands for, as strings; null and undefined entries are skipped. */\nfunction listed(value: readonly unknown[]): Set<string> {\n const values = new Set<string>();\n for (const item of value) {\n if (item !== null && item !== undefined) values.add(String(item));\n }\n return values;\n}\n\n/** The string a single value assigns to `select.value`; null and undefined clear the choice. */\nfunction single(value: unknown): string {\n return value === null || value === undefined ? \"\" : String(value);\n}\n\n/**\n * Selects the options a `value` stands for. The compiler calls it for `<select value={...}>`. A\n * single value behaves like `select.value = value` (`null` and `undefined` are the empty string).\n * On a `<select multiple>` an array selects exactly the options whose value it lists and clears\n * the others. The server writes the same state as `selected` on the options (`ssrSelectValue`).\n *\n * @param select The select element; its options must already be in it.\n * @param value A string or number (written as `String(value)`), or `null`/`undefined` (written as\n * `\"\"`: an option with an empty value is selected, otherwise none). For a `multiple` select, an array of them: `null` and `undefined`\n * entries are skipped. An array on a single select is written as `String(array)`.\n * @example\n * import { setSelectValue } from \"@shadow-js/web\";\n *\n * const select = document.createElement(\"select\");\n * select.multiple = true;\n * select.append(new Option(\"A\", \"a\"), new Option(\"B\", \"b\"), new Option(\"C\", \"c\"));\n * setSelectValue(select, [\"a\", \"c\"]); // A and C selected, B cleared\n * @see ssrSelectValue\n * @since 1.0.0\n */\nexport function setSelectValue(select: HTMLSelectElement, value: unknown): void {\n if (select.multiple && Array.isArray(value)) {\n const wanted = listed(value);\n for (const option of Array.from(select.options)) option.selected = wanted.has(option.value);\n return;\n }\n select.value = single(value);\n}\n\n/** True when the select already shows `value` the way {@link setSelectValue} would leave it. @internal */\nexport function selectShows(select: HTMLSelectElement, value: unknown): boolean {\n if (select.multiple && Array.isArray(value)) {\n const wanted = listed(value);\n return Array.from(select.options).every(\n (option) => option.selected === wanted.has(option.value),\n );\n }\n return select.value === single(value);\n}\n"],"mappings":"AACA,SAASA,EAAO,EAAwC,CACtD,IAAMC,kBAAS,IAAI,IACnB,IAAK,IAAMC,KAAQC,EACbD,GAAS,MAA4BD,EAAO,IAAI,OAAOC,CAAI,CAAC,EAElE,OAAOD,CACT,CAGA,SAASG,EAAO,EAAwB,CACtC,OAAOD,GAAU,KAA8B,GAAK,OAAOA,CAAK,CAClE,CAsBA,SAAgBE,EAAe,EAA2B,EAAsB,CAC9E,GAAIC,EAAO,UAAY,MAAM,QAAQH,CAAK,EAAG,CAC3C,IAAMI,EAASP,EAAOG,CAAK,EAC3B,IAAK,IAAMK,KAAU,MAAM,KAAKF,EAAO,OAAO,EAAG,EAAO,SAAWC,EAAO,IAAIC,EAAO,KAAK,CAE5F,KACA,GAAO,MAAQJ,EAAOD,CAAK,CAC7B,CAGA,SAAgBM,EAAY,EAA2B,EAAyB,CAC9E,GAAIH,EAAO,UAAY,MAAM,QAAQH,CAAK,EAAG,CAC3C,IAAMI,EAASP,EAAOG,CAAK,EAC3B,OAAO,MAAM,KAAKG,EAAO,OAAO,CAAC,CAAC,MAC/B,GAAWE,EAAO,WAAaD,EAAO,IAAIC,EAAO,KAAK,CACzD,CACF,CACA,OAAOF,EAAO,QAAUF,EAAOD,CAAK,CACtC,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{invalid as e}from"./errors.js";import{escapeHtml as t,resolveValue as n}from"./escape.js";const r=/^[A-Za-z_:][A-Za-z0-9_:.-]*$/,i=/* @__PURE__ */ new Set([`href`,`src`,`action`,`formaction`,`xlink:href`,`srcdoc`,`poster`,`data`]),a=/* @__PURE__ */ new Set([`values`,`from`,`to`,`by`]),o=/* @__PURE__ */ new Set([`draggable`,`spellcheck`,`contenteditable`]),s=/* @__PURE__ */ new Set([`async`,`autofocus`,`autoplay`,`checked`,`controls`,`default`,`defer`,`disabled`,`formnovalidate`,`hidden`,`inert`,`ismap`,`loop`,`multiple`,`muted`,`nomodule`,`novalidate`,`open`,`playsinline`,`readonly`,`required`,`reversed`,`selected`]),c=[`javascript:`,`data:text/html`,`vbscript:`];function l(t){if(!r.test(t))throw e(`INVALID_ATTRIBUTE_NAME`,`"${t}" is not a valid attribute name.`)}function u(e){return e.length>2&&e.startsWith(`on`)}function d(e){return e.startsWith(`aria-`)||e.startsWith(`data-`)||o.has(e)}function f(e){let t=``;for(let n of e){let e=n.charCodeAt(0);e>31&&(e<127||e>159)&&(t+=n)}return t}function p(e){let t=f(e).trim().toLowerCase();return c.some(e=>t.startsWith(e))}function m(e,t){return i.has(e)?p(t):a.has(e)&&t.split(`;`).some(p)}function h(e,t){return t==null?null:t===!1?d(e)?`false`:null:t===!0?d(e)?`true`:``:String(t)}function g(t){if(typeof t==`symbol`)throw e(`UNRECOGNIZED_INSERT_VALUE`,`A symbol cannot be an attribute value.`)}function _(e,r,i=!1){l(e);let a=e.toLowerCase();if(u(a))return``;let o=n(r);if(g(o),i)return o?` ${e}`:``;let s=h(a,o);return s===null||m(a,s)?``:` ${e}="${t(s)}"`}export{s as BOOLEAN_ATTRIBUTES,l as assertAttributeName,h as attributeText,u as isEventName,p as isUnsafeUrl,_ as ssrAttribute};
|
|
2
|
+
//# sourceMappingURL=attributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attributes.js","names":["ATTRIBUTE_NAME","URL_ATTRIBUTES","ANIMATION_VALUE_ATTRIBUTES","ENUMERATED_ATTRIBUTES","BOOLEAN_ATTRIBUTES","UNSAFE_URL_PREFIXES","assertAttributeName","name","invalid","isEventName","lowerName","isStringValued","stripControls","kept","char","text","code","isUnsafeUrl","normalized","value","prefix","isUnsafeAttributeValue","attributeText","assertNotSymbol","ssrAttribute","resolved","resolveValue","isBoolean","escapeHtml"],"sources":["../../../src/server/attributes.ts"],"sourcesContent":["import { invalid } from \"./errors\";\nimport { escapeHtml, resolveValue } from \"./escape\";\n\n/** Names that can appear in markup: an XML-name subset without `@` or whitespace. Same as the client. */\nconst ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_:.-]*$/;\n\n/** Attributes whose value is a URL and is therefore checked for script schemes. Same as the client. */\nconst URL_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"href\",\n \"src\",\n \"action\",\n \"formaction\",\n \"xlink:href\",\n \"srcdoc\",\n \"poster\",\n \"data\",\n]);\n\n/**\n * SVG animation attributes (`animate`, `set`): with `attributeName=\"href\"` they write an `href` by animation, so their value\n * is checked like one. `values` is a `;` list and every entry is checked. Same as the client.\n */\nconst ANIMATION_VALUE_ATTRIBUTES: ReadonlySet<string> = new Set([\"values\", \"from\", \"to\", \"by\"]);\n\n/** Enumerated attributes where `false` is a real value (\"false\") rather than an absence. */\nconst ENUMERATED_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"draggable\",\n \"spellcheck\",\n \"contenteditable\",\n]);\n\n/**\n * Boolean attributes that a props object writes as presence flags (`disabled: true` gives a bare\n * `disabled`). Lower-case names only.\n * @internal\n */\nexport const BOOLEAN_ATTRIBUTES: ReadonlySet<string> = new Set([\n \"async\",\n \"autofocus\",\n \"autoplay\",\n \"checked\",\n \"controls\",\n \"default\",\n \"defer\",\n \"disabled\",\n \"formnovalidate\",\n \"hidden\",\n \"inert\",\n \"ismap\",\n \"loop\",\n \"multiple\",\n \"muted\",\n \"nomodule\",\n \"novalidate\",\n \"open\",\n \"playsinline\",\n \"readonly\",\n \"required\",\n \"reversed\",\n \"selected\",\n]);\n\n/** URL prefixes (after normalization) that are never written. Same as the client. */\nconst UNSAFE_URL_PREFIXES: readonly string[] = [\"javascript:\", \"data:text/html\", \"vbscript:\"];\n\n/** Throws a TypeError unless `name` can be written as an attribute name. @internal */\nexport function assertAttributeName(name: string): void {\n if (!ATTRIBUTE_NAME.test(name)) {\n throw invalid(\"INVALID_ATTRIBUTE_NAME\", `\"${name}\" is not a valid attribute name.`);\n }\n}\n\n/** True for `on*` names, which never reach markup. Length matches the client's event test. @internal */\nexport function isEventName(lowerName: string): boolean {\n return lowerName.length > 2 && lowerName.startsWith(\"on\");\n}\n\n/** True for `aria-*`, `data-*` and the enumerated attributes: their booleans are strings. */\nfunction isStringValued(lowerName: string): boolean {\n return (\n lowerName.startsWith(\"aria-\") ||\n lowerName.startsWith(\"data-\") ||\n ENUMERATED_ATTRIBUTES.has(lowerName)\n );\n}\n\n/** Removes C0 and C1 control characters, which browsers ignore inside a URL scheme. */\nfunction stripControls(text: string): string {\n let kept = \"\";\n for (const char of text) {\n const code = char.charCodeAt(0);\n if (code > 0x1f && (code < 0x7f || code > 0x9f)) kept += char;\n }\n return kept;\n}\n\n/** True when the URL would run script, after the normalization browsers apply. @internal */\nexport function isUnsafeUrl(value: string): boolean {\n const normalized = stripControls(value).trim().toLowerCase();\n return UNSAFE_URL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n\n/** True when `lowerName` carries a URL (or an animated one) and `value` would run script. */\nfunction isUnsafeAttributeValue(lowerName: string, value: string): boolean {\n if (URL_ATTRIBUTES.has(lowerName)) return isUnsafeUrl(value);\n return ANIMATION_VALUE_ATTRIBUTES.has(lowerName) && value.split(\";\").some(isUnsafeUrl);\n}\n\n/** Text to write for `value`, or null when the attribute is removed. Same rules as the client. @internal */\nexport function attributeText(lowerName: string, value: unknown): string | null {\n if (value === null || value === undefined) return null;\n if (value === false) return isStringValued(lowerName) ? \"false\" : null;\n if (value === true) return isStringValued(lowerName) ? \"true\" : \"\";\n return String(value);\n}\n\n/** Refuses symbols, which have no markup form and would otherwise be coerced silently. */\nfunction assertNotSymbol(value: unknown): void {\n if (typeof value === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be an attribute value.\");\n }\n}\n\n/**\n * Renders one attribute as markup with a leading space, or `\"\"` when the attribute is absent: the\n * helper the compiler's server output calls for a dynamic attribute. It applies the client's value\n * rules and URL check, so server and client agree on what is written.\n *\n * - `null`, `undefined` and `false` give `\"\"` (except `false` on `aria-*`, `data-*`, `draggable`,\n * `spellcheck` and `contenteditable`, which is written as `\"false\"`); `true` writes `=\"\"` (or\n * `\"true\"` for those same names). Other values are written as `String(value)`, HTML-escaped.\n * - URL attributes whose value would run script are dropped, with the check of\n * `isUnsafeUrlAttribute` (including the SVG animation attributes `values`, `from`, `to`, `by`).\n * - `on*` names are dropped: event handlers never reach markup.\n * - Accessors are called (untracked) until a plain value remains.\n *\n * @param name Attribute name, matching `[A-Za-z_:][A-Za-z0-9_:.-]*`. It is validated before\n * anything else, so an invalid name always throws.\n * @param value The value, or an accessor of it.\n * @param isBoolean `true` for a presence attribute such as `disabled`: a truthy value writes the bare\n * name, a falsy one writes nothing. Default: `false`.\n * @returns Markup such as `' title=\"a&b\"'`, or `\"\"`.\n * @throws TypeError `INVALID_ATTRIBUTE_NAME` for an invalid name, and `UNRECOGNIZED_INSERT_VALUE`\n * when the value is a symbol.\n * @example\n * import { ssrAttribute } from \"@shadow-js/web/server\";\n *\n * ssrAttribute(\"title\", \"Tom & Jerry\"); // ' title=\"Tom & Jerry\"'\n * ssrAttribute(\"disabled\", true, true); // \" disabled\"\n * ssrAttribute(\"href\", \"javascript:alert(1)\"); // \"\"\n * @since 1.0.0\n */\nexport function ssrAttribute(name: string, value: unknown, isBoolean = false): string {\n assertAttributeName(name);\n const lowerName = name.toLowerCase();\n if (isEventName(lowerName)) return \"\";\n const resolved = resolveValue(value);\n assertNotSymbol(resolved);\n if (isBoolean) return resolved ? ` ${name}` : \"\";\n const text = attributeText(lowerName, resolved);\n if (text === null) return \"\";\n if (isUnsafeAttributeValue(lowerName, text)) return \"\";\n return ` ${name}=\"${escapeHtml(text)}\"`;\n}\n"],"mappings":"A,iGAIA,MAAMA,EAAiB,+BAGjBC,kBAAsC,IAAI,IAAI,CAClD,OACA,MACA,SACA,aACA,aACA,SACA,SACA,MACF,CAAC,EAMKC,kBAAkD,IAAI,IAAI,CAAC,SAAU,OAAQ,KAAM,IAAI,CAAC,EAGxFC,kBAA6C,IAAI,IAAI,CACzD,YACA,aACA,iBACF,CAAC,EAOYC,kBAA0C,IAAI,IAAI,CAC7D,QACA,YACA,WACA,UACA,WACA,UACA,QACA,WACA,iBACA,SACA,QACA,QACA,OACA,WACA,QACA,WACA,aACA,OACA,cACA,WACA,WACA,WACA,UACF,CAAC,EAGKC,EAAyC,CAAC,cAAe,iBAAkB,WAAW,EAG5F,SAAgBC,EAAoB,EAAoB,CACtD,GAAI,CAACN,EAAe,KAAKO,CAAI,EAC3B,MAAMC,EAAQ,yBAA0B,IAAID,EAAK,iCAAiC,CAEtF,CAGA,SAAgBE,EAAY,EAA4B,CACtD,OAAOC,EAAU,OAAS,GAAKA,EAAU,WAAW,IAAI,CAC1D,CAGA,SAASC,EAAe,EAA4B,CAClD,OACED,EAAU,WAAW,OAAO,GAC5BA,EAAU,WAAW,OAAO,GAC5BP,EAAsB,IAAIO,CAAS,CAEvC,CAGA,SAASE,EAAc,EAAsB,CAC3C,IAAIC,EAAO,GACX,IAAK,IAAMC,KAAQC,EAAM,CACvB,IAAMC,EAAOF,EAAK,WAAW,CAAC,EAC1BE,EAAO,KAASA,EAAO,KAAQA,EAAO,OAAO,GAAQF,EAC3D,CACA,OAAOD,CACT,CAGA,SAAgBI,EAAY,EAAwB,CAClD,IAAMC,EAAaN,EAAcO,CAAK,CAAC,CAAC,KAAK,CAAC,CAAC,YAAY,EAC3D,OAAOd,EAAoB,KAAM,GAAWa,EAAW,WAAWE,CAAM,CAAC,CAC3E,CAGA,SAASC,EAAuB,EAAmB,EAAwB,CAEzE,OADIpB,EAAe,IAAIS,CAAS,EAAUO,EAAYE,CAAK,EACpDjB,EAA2B,IAAIQ,CAAS,GAAKS,EAAM,MAAM,GAAG,CAAC,CAAC,KAAKF,CAAW,CACvF,CAGA,SAAgBK,EAAc,EAAmB,EAA+B,CAI9E,OAHIH,GAAU,KAAoC,KAC9CA,IAAU,GAAcR,EAAeD,CAAS,EAAI,QAAU,KAC9DS,IAAU,GAAaR,EAAeD,CAAS,EAAI,OAAS,GACzD,OAAOS,CAAK,CACrB,CAGA,SAASI,EAAgB,EAAsB,CAC7C,GAAI,OAAOJ,GAAU,SACnB,MAAMX,EAAQ,4BAA6B,wCAAwC,CAEvF,CA+BA,SAAgBgB,EAAa,EAAc,EAAgB,EAAY,GAAe,CACpFlB,EAAoBC,CAAI,EACxB,IAAMG,EAAYH,EAAK,YAAY,EACnC,GAAIE,EAAYC,CAAS,EAAG,MAAO,GACnC,IAAMe,EAAWC,EAAaP,CAAK,EAEnC,GADAI,EAAgBE,CAAQ,EACpBE,EAAW,OAAOF,EAAW,IAAIlB,IAAS,GAC9C,IAAMQ,EAAOO,EAAcZ,EAAWe,CAAQ,EAG9C,OAFIV,IAAS,MACTM,EAAuBX,EAAWK,CAAI,EAAU,GAC7C,IAAIR,EAAK,IAAIqB,EAAWb,CAAI,EAAE,EACvC,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{cssValueText as e}from"../internal/css-units.js";import{invalid as t}from"./errors.js";import{isSsrNode as n}from"./node.js";import{escapeHtml as r,resolveValue as i}from"./escape.js";const a=/^(--[A-Za-z0-9_-]+|-?[a-z][a-z0-9-]*)$/;function o(e,n){let r=[[e]],a=[0],o=/* @__PURE__ */ new Set;for(;r.length>0;){let e=r.length-1,s=r[e],c=a[e]??0;if(s===void 0||c>=s.length){let e=r.pop();e!==void 0&&o.delete(e),a.pop();continue}a[e]=c+1;let l=i(s[c]);if(Array.isArray(l)){if(o.has(l))throw TypeError(`A class array contains itself.`);o.add(l),r.push(l),a.push(0)}else if(typeof l==`string`)l!==``&&n.push(l);else if(typeof l==`number`)l!==0&&!Number.isNaN(l)&&n.push(String(l));else if(typeof l==`symbol`)throw t(`UNRECOGNIZED_INSERT_VALUE`,`A symbol cannot be a class name.`);else if(typeof l==`object`&&l){let e=l;for(let t of Object.keys(e))t!==``&&i(e[t])&&n.push(t)}}}function s(e){let t=i(e);if(typeof t==`string`)return t;if(t==null||t===!1)return``;let n=[];return o(t,n),n.join(` `)}function c(e){let t=s(e);return t===``?``:` class="${r(t)}"`}function l(e){if(e.startsWith(`--`))return e;let t=e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);return t.startsWith(`ms-`)?`-${t}`:t}function u(e){let t=``,n=0,r=!1;for(let i of e)if(r)r=!1;else if(i===`\\`)r=!0;else if(t!==``)i===t&&(t=``);else if(i===`"`||i===`'`)t=i;else if(i===`(`)n+=1;else if(i===`)`)n=Math.max(0,n-1);else if((i===`;`||i===`{`||i===`}`)&&n===0)return!1;return t===``&&n===0&&!r}function d(r,o){let s=i(r);if(s!=null&&s!==!1){if(typeof s==`string`)s!==``&&o.push(s);else{if(typeof s!=`object`||n(s))throw t(`UNRECOGNIZED_INSERT_VALUE`,`A style must be a string, an object or an array of them.`);if(Array.isArray(s))for(let e of s){let t=i(e);if(Array.isArray(t))throw TypeError(`ssrStyle(): a style array may not contain another array.`);d(t,o)}else for(let n of Object.keys(s)){let r=l(n);if(!a.test(r))throw t(`INVALID_STYLE_PROPERTY`,`"${n}" is not a valid CSS property name.`);let c=i(Reflect.get(s,n));if(c==null||c===!1)continue;if(typeof c==`symbol`)throw t(`UNRECOGNIZED_INSERT_VALUE`,`A symbol cannot be a style value.`);let d=e(r,c);u(d)&&o.push(`${r}:${d}`)}}}}function f(e){let t=[];return d(e,t),t.join(`;`)}function p(e){let t=f(e);return t===``?``:` style="${r(t)}"`}export{s as classText,o as collectClasses,u as isSafeCssValue,c as ssrClass,p as ssrStyle,f as styleText,l as toCssProperty};
|
|
2
|
+
//# sourceMappingURL=class-style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-style.js","names":["CSS_PROPERTY","collectClasses","frames","root","cursors","open","top","frame","cursor","done","item","resolveValue","parts","invalid","record","key","classText","resolved","value","ssrClass","text","escapeHtml","toCssProperty","name","kebab","letter","isSafeCssValue","quote","depth","escaped","char","collectDeclarations","source","out","isSsrNode","property","cssValueText","styleText","declarations","ssrStyle"],"sources":["../../../src/server/class-style.ts"],"sourcesContent":["import { cssValueText } from \"../internal/css-units\";\nimport { invalid } from \"./errors\";\nimport { escapeHtml, resolveValue } from \"./escape\";\nimport { isSsrNode } from \"./node\";\n\n/** A CSS property name: a custom property, or a lower-case name with an optional vendor dash. */\nconst CSS_PROPERTY = /^(--[A-Za-z0-9_-]+|-?[a-z][a-z0-9-]*)$/;\n\n/**\n * Appends the class names found in `root` to `parts`, clsx-style. Iterative: array nesting depth\n * is controlled by the caller, so it must not reach the call stack.\n * @internal\n */\nexport function collectClasses(root: unknown, parts: string[]): void {\n const frames: unknown[][] = [[root]];\n const cursors: number[] = [0];\n const open = new Set<unknown[]>();\n while (frames.length > 0) {\n const top = frames.length - 1;\n const frame = frames[top];\n const cursor = cursors[top] ?? 0;\n if (frame === undefined || cursor >= frame.length) {\n const done = frames.pop();\n if (done !== undefined) open.delete(done);\n cursors.pop();\n continue;\n }\n cursors[top] = cursor + 1;\n const item = resolveValue(frame[cursor]);\n if (Array.isArray(item)) {\n if (open.has(item)) throw new TypeError(\"A class array contains itself.\");\n open.add(item);\n frames.push(item);\n cursors.push(0);\n } else if (typeof item === \"string\") {\n if (item !== \"\") parts.push(item);\n } else if (typeof item === \"number\") {\n if (item !== 0 && !Number.isNaN(item)) parts.push(String(item));\n } else if (typeof item === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be a class name.\");\n } else if (item !== null && typeof item === \"object\") {\n const record = item as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n if (key !== \"\" && resolveValue(record[key])) parts.push(key);\n }\n }\n }\n}\n\n/**\n * The class text for a class value, or \"\" when there is none. A string is used as it is.\n * @internal\n */\nexport function classText(value: unknown): string {\n const resolved = resolveValue(value);\n if (typeof resolved === \"string\") return resolved;\n if (resolved === null || resolved === undefined || resolved === false) return \"\";\n const parts: string[] = [];\n collectClasses(resolved, parts);\n return parts.join(\" \");\n}\n\n/**\n * Renders a `class` attribute from a class value: the helper the compiler's server output calls for\n * `class`, `className` and `classList`, with the same clsx rules as the client's `className`.\n *\n * @param value A string (used as is), or an array or object: non-empty strings, numbers other than\n * `0` and `NaN`, nested arrays, and the keys of objects whose value is truthy. Accessors, also\n * inside arrays and as object values, are called. `null`, `undefined` and `false` give no class.\n * @returns Markup such as `' class=\"a b\"'` (HTML-escaped), or `\"\"` when there are no classes.\n * @throws TypeError when an array contains itself, and `UNRECOGNIZED_INSERT_VALUE` for a symbol.\n * @example\n * import { ssrClass } from \"@shadow-js/web/server\";\n *\n * ssrClass([\"card\", { \"card--active\": true, hidden: false }]); // ' class=\"card card--active\"'\n * ssrClass(null); // \"\"\n * @see ssrStyle\n * @since 1.0.0\n */\nexport function ssrClass(value: unknown): string {\n const text = classText(value);\n return text === \"\" ? \"\" : ` class=\"${escapeHtml(text)}\"`;\n}\n\n/** Converts a camelCase style name to CSS, keeping custom properties; `ms` gets its dash. @internal */\nexport function toCssProperty(name: string): string {\n if (name.startsWith(\"--\")) return name;\n const kebab = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n return kebab.startsWith(\"ms-\") ? `-${kebab}` : kebab;\n}\n\n/**\n * True when a value cannot end its own declaration. A `;`, `{` or `}` outside quotes and\n * parentheses would start another declaration or rule, so such a value is dropped. Unbalanced\n * quotes or parentheses are dropped too, because they would swallow the declarations after them.\n * @internal\n */\nexport function isSafeCssValue(text: string): boolean {\n let quote = \"\";\n let depth = 0;\n let escaped = false;\n for (const char of text) {\n if (escaped) {\n escaped = false;\n } else if (char === \"\\\\\") {\n escaped = true;\n } else if (quote !== \"\") {\n if (char === quote) quote = \"\";\n } else if (char === '\"' || char === \"'\") {\n quote = char;\n } else if (char === \"(\") {\n depth += 1;\n } else if (char === \")\") {\n depth = Math.max(0, depth - 1);\n } else if ((char === \";\" || char === \"{\" || char === \"}\") && depth === 0) {\n return false;\n }\n }\n return quote === \"\" && depth === 0 && !escaped;\n}\n\n/** Declarations for one style source, appended to `out` as raw (unescaped) CSS text. */\nfunction collectDeclarations(source: unknown, out: string[]): void {\n const value = resolveValue(source);\n if (value === null || value === undefined || value === false) return;\n if (typeof value === \"string\") {\n if (value !== \"\") out.push(value);\n return;\n }\n if (typeof value !== \"object\" || isSsrNode(value)) {\n throw invalid(\n \"UNRECOGNIZED_INSERT_VALUE\",\n \"A style must be a string, an object or an array of them.\",\n );\n }\n if (Array.isArray(value)) {\n for (const item of value) {\n const resolved = resolveValue(item);\n if (Array.isArray(resolved)) {\n throw new TypeError(\"ssrStyle(): a style array may not contain another array.\");\n }\n collectDeclarations(resolved, out);\n }\n return;\n }\n for (const key of Object.keys(value)) {\n const property = toCssProperty(key);\n if (!CSS_PROPERTY.test(property)) {\n throw invalid(\"INVALID_STYLE_PROPERTY\", `\"${key}\" is not a valid CSS property name.`);\n }\n const resolved = resolveValue(Reflect.get(value, key));\n if (resolved === null || resolved === undefined || resolved === false) continue;\n if (typeof resolved === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be a style value.\");\n }\n const text = cssValueText(property, resolved);\n if (!isSafeCssValue(text)) continue;\n out.push(`${property}:${text}`);\n }\n}\n\n/**\n * The declarations of a style value, joined with `;`, or \"\" when there are none. Later\n * declarations win in CSS, so earlier and later sources can be combined in order.\n * @internal\n */\nexport function styleText(value: unknown): string {\n const declarations: string[] = [];\n collectDeclarations(value, declarations);\n return declarations.join(\";\");\n}\n\n/**\n * Renders a `style` attribute from a style value: the helper the compiler's server output calls for\n * `style` and `style:` attributes. Sources in an array are written in order, so a later declaration\n * wins in CSS.\n *\n * @param value A string (written as is), an object of properties, or an array of strings and\n * objects (not nested). Object keys are camelCase (converted to kebab-case, `msTransform` gives\n * `-ms-transform`), kebab-case, or custom properties (`--gap`, kept). `null`, `undefined` and `false`\n * values are skipped; a number is in pixels unless it is `0`, the property is unitless (`opacity`,\n * `zIndex`, ...) or a custom property, as in React. A value that could end its own declaration (a\n * `;`, `{` or `}` outside quotes and parentheses, or an unbalanced quote or parenthesis) is dropped.\n * @returns Markup such as `' style=\"color:red\"'` (HTML-escaped), or `\"\"` when there is nothing to\n * write.\n * @throws TypeError `INVALID_STYLE_PROPERTY` for an invalid property name, `UNRECOGNIZED_INSERT_VALUE`\n * for a symbol or a value that is not a string, object or array, and a TypeError for a nested array.\n * @example\n * import { ssrStyle } from \"@shadow-js/web/server\";\n *\n * ssrStyle({ backgroundColor: \"red\", width: 10, \"--gap\": \"4px\" });\n * // ' style=\"background-color:red;width:10px;--gap:4px\"'\n * ssrStyle([{ color: \"red\" }, \"color: blue\"]); // the later declaration wins\n * @see ssrClass\n * @since 1.0.0\n */\nexport function ssrStyle(value: unknown): string {\n const text = styleText(value);\n return text === \"\" ? \"\" : ` style=\"${escapeHtml(text)}\"`;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{currentScope as e,enterComponent as t}from"../internal/hydration-scope.js";import{untrack as n}from"@shadow-js/core";import{createOwner as r,runInScope as i}from"@shadow-js/core/extend";function a(n,a){if(typeof n!=`function`)throw TypeError(`createComponent(): the component must be a function.`);return t(()=>{let t=r();return t.idPrefix=e()?.id,i({owner:t,listener:null},()=>n(a))})}function o(e){let t,r=!1;return()=>{if(t!==void 0)return t.value;if(r)throw TypeError(`memo(): the computation read itself.`);r=!0;try{let r=n(e);return t={value:r},r}finally{r=!1}}}export{a as createComponent,o as memo};
|
|
2
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","names":["createComponent","component","enterComponent","owner","createOwner","currentScope","runInScope","props","memo","slot","running","value","untrack","fn"],"sources":["../../../src/server/component.ts"],"sourcesContent":["import { untrack } from \"@shadow-js/core\";\nimport { createOwner, runInScope } from \"@shadow-js/core/extend\";\nimport { currentScope, enterComponent } from \"../internal/hydration-scope\";\n\n/**\n * Calls a component on the server, untracked, with its own owner and hydration scope, so the\n * hydration keys it hands out depend only on where it sits in the tree. The server twin of the client\n * `createComponent`: compiled server output calls it for `<Component />`, and a hand-written render\n * entry calls it for the root component.\n *\n * @param component The component function.\n * @param props The props object; reactive props are getters.\n * @returns Whatever the component returns.\n * @throws TypeError when `component` is not a function. An error the component throws propagates.\n * @example\n * import { createComponent, renderToString } from \"@shadow-js/web/server\";\n *\n * function Card(props: { title: string }) {\n * return <h2>{props.title}</h2>;\n * }\n * const html = renderToString(() => createComponent(Card, { title: \"Hello\" }));\n * @since 1.0.0\n */\nexport function createComponent<P>(component: (props: P) => unknown, props: P): unknown {\n if (typeof component !== \"function\") {\n throw new TypeError(\"createComponent(): the component must be a function.\");\n }\n return enterComponent(() => {\n // The same owner structure as the browser, so `useId` prefixes agree (see the DOM createComponent).\n const owner = createOwner();\n owner.idPrefix = currentScope()?.id;\n // One scope switch (owner in, listener off): deep component trees are bounded by the call stack.\n return runInScope({ owner, listener: null }, () => component(props));\n });\n}\n\n/**\n * The server twin of `memo`: nothing is reactive during a server render, so it computes once, on the\n * first read, and returns the cached value on every later read. A call that throws is not cached\n * (the next read runs `fn` again).\n *\n * @param fn The computation; runs untracked, on the first read.\n * @returns An accessor of the cached value.\n * @throws TypeError from the accessor when `fn` reads the accessor itself while it runs, instead of\n * recursing. An error `fn` throws propagates from the read.\n * @example\n * import { memo } from \"@shadow-js/web/server\";\n *\n * const items = [3, 1, 2];\n * const sorted = memo(() => [...items].sort());\n * sorted(); // [1, 2, 3], computed now\n * sorted(); // the same array, cached\n * @since 1.0.0\n */\nexport function memo<T>(fn: () => T): () => T {\n let slot: { readonly value: T } | undefined;\n let running = false;\n return () => {\n if (slot !== undefined) return slot.value;\n if (running) throw new TypeError(\"memo(): the computation read itself.\");\n running = true;\n try {\n const value = untrack(fn);\n slot = { value };\n return value;\n } finally {\n running = false;\n }\n };\n}\n"],"mappings":"A,iMAuBA,SAAgBA,EAAmB,EAAkC,EAAmB,CACtF,GAAI,OAAOC,GAAc,WACvB,MAAU,UAAU,sDAAsD,EAE5E,OAAOC,MAAqB,CAE1B,IAAMC,EAAQC,EAAY,EAG1B,MAFA,GAAM,SAAWC,EAAa,CAAC,EAAE,GAE1BC,EAAW,CAAE,QAAO,SAAU,IAAK,MAASL,EAAUM,CAAK,CAAC,CACrE,CAAC,CACH,CAoBA,SAAgBC,EAAQ,EAAsB,CAC5C,IAAIC,EACAC,EAAU,GACd,UAAa,CACX,GAAID,IAAS,IAAA,GAAW,OAAOA,EAAK,MACpC,GAAIC,EAAS,MAAU,UAAU,sCAAsC,EACvE,EAAU,GACV,GAAI,CACF,IAAMC,EAAQC,EAAQC,CAAE,EAExB,MADA,GAAO,CAAE,OAAM,EACRF,CACT,QAAU,CACR,EAAU,EACZ,CACF,CACF,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derived.js","names":["derived","current","compute","read","args"],"sources":["../../../src/server/derived.ts"],"sourcesContent":["/**\n * The server twin of the client `Derived`: what {@link derived} returns. Nothing is reactive on the\n * server, so it holds the value computed once. Read it as `x.value` or call it as `x()`.\n *\n * @example\n * import { derived } from \"@shadow-js/web/server\";\n *\n * const total = derived(() => 20 * 3);\n * total.value; // 60\n * total(); // 60\n * @see derived\n * @since 1.0.0\n */\nexport interface Derived<T> {\n /**\n * Returns the value. When the value is a function, calls it with `args` and returns its result\n * instead, so a derived function stays callable.\n */\n (...args: unknown[]): unknown;\n /** The value `compute` returned. */\n readonly value: T;\n}\n\n/**\n * The server twin of the client `derived`, which the compiler emits for `const x = <expression\n * reading signals>` inside a component. On the server it calls `compute` once, immediately, and\n * returns a constant {@link Derived}.\n *\n * @param compute The computation. Runs once, when `derived` is called; an error it throws propagates.\n * @returns A {@link Derived} holding the result.\n * @example\n * import { derived } from \"@shadow-js/web/server\";\n *\n * const greeting = derived(() => (name: string) => `Hello, ${name}`);\n * greeting(\"Ada\"); // \"Hello, Ada\": a derived function stays callable\n * @see Derived\n * @since 1.0.0\n */\nexport function derived<T>(compute: () => T): Derived<T> {\n const current = compute();\n const read = ((...args: unknown[]): unknown =>\n typeof current === \"function\"\n ? (current as (...a: unknown[]) => unknown)(...args)\n : current) as {\n (...args: unknown[]): unknown;\n value: T;\n };\n Object.defineProperty(read, \"value\", { value: current });\n return read as Derived<T>;\n}\n"],"mappings":"AAsCA,SAAgBA,EAAW,EAA8B,CACvD,IAAMC,EAAUC,EAAQ,EAClBC,IAAS,GAAGC,IAChB,OAAOH,GAAY,WACdA,EAAyC,GAAGG,CAAI,EACjDH,GAKN,OADA,OAAO,eAAeE,EAAM,QAAS,CAAE,MAAOF,CAAQ,CAAC,EAChDE,CACT,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{nextKey as e}from"../internal/hydration-scope.js";import{IGNORED_KEYS as t,attributeName as n}from"../internal/react-names.js";import{invalid as r}from"./errors.js";import{SsrNode as i,isSsrNode as a}from"./node.js";import{escape as o,escapeHtml as s,resolveValue as c}from"./escape.js";import{BOOLEAN_ATTRIBUTES as l,isEventName as u,ssrAttribute as d}from"./attributes.js";import{classText as f,ssrStyle as p,styleText as m}from"./class-style.js";import{markSelectedOptions as h,textareaContent as g}from"./form-controls.js";const _=/^[A-Za-z][A-Za-z0-9-]*$/,v=/* @__PURE__ */ new Set([`area`,`base`,`br`,`col`,`command`,`embed`,`hr`,`img`,`input`,`keygen`,`link`,`meta`,`param`,`source`,`track`,`wbr`]),y=/* @__PURE__ */ new Set([`__proto__`,`constructor`,`prototype`,`children`,`ref`]);function b(e){if(typeof e==`object`&&e)return Reflect.get(e,`__html`)}function x(e,...t){if(!Array.isArray(e)||e.length!==t.length+1)throw TypeError(`ssr(): parts must have one more entry than there are holes.`);let n=e[0]??``;for(let r=0;r<t.length;r+=1){let i=t[r];if(typeof i==`string`)n+=i;else if(a(i))n+=i.t;else throw TypeError(`ssr(): a hole must be an escaped string or an SsrNode.`);n+=e[r+1]??``}return new i(n)}function S(e){if(typeof e!=`string`)throw TypeError(`ssrRaw(): the markup must be a string.`);return new i(e)}function C(){let t=e();return t===void 0?``:` data-hk="${s(t)}"`}function w(e,a,x=void 0,S=!1,w=!1){if(typeof e!=`string`||!_.test(e))throw r(`INVALID_TAG_NAME`,`"${String(e)}" is not a valid tag name.`);let O=e.toLowerCase(),k=O===`select`,A=O===`textarea`,j={},M=!1,N=!1,P=S?C():``,F=[],I=``,L;if(typeof a==`object`&&a)for(let e of Object.keys(a)){if(y.has(e)||t.has(e)||e===`ref`||e.startsWith(`on:`)||e.startsWith(`use:`)||e.startsWith(`prop:`)||u(e)||S&&e===`data-hk`)continue;let r=c(Reflect.get(a,e));if(e===`class`||e===`className`){let e=f(r);e!==``&&F.push(e)}else if(e===`classList`)E(r,F);else if(e===`style`)I=m(r);else if(e===`innerHTML`)L=D(r);else if(e===`dangerouslySetInnerHTML`)L=D(c(b(r)));else if((k||A)&&e===`value`)j.value=r,M=!0;else if((k||A)&&e===`defaultValue`)j.fallback=r,N=!0;else if(e.startsWith(`attr:`))P+=d(e.slice(5),r);else if(e.startsWith(`bool:`))P+=d(e.slice(5),r,!0);else if(e===`defaultValue`||e===`defaultChecked`){let t=e===`defaultValue`?`value`:`checked`;Object.hasOwn(a,t)||(P+=d(t,r,t===`checked`))}else{let t=n(e,w);P+=d(t,r,l.has(t))}}if(F.length>0&&(P+=` class="${s(F.join(` `))}"`),I!==``&&(P+=p(I)),v.has(O))return new i(`<${e}${P}>`);let R=L===void 0?o(x===void 0?T(a):x):L;if(L===void 0&&(M||N)){let e=M?j.value:j.fallback;R=A?g(e):h(e,R)}return new i(`<${e}${P}>${R}</${e}>`)}function T(e){if(typeof e==`object`&&e)return Reflect.get(e,`children`)}function E(e,t){if(typeof e==`object`&&e&&!Array.isArray(e))for(let n of Object.keys(e))n!==``&&c(Reflect.get(e,n))&&t.push(n)}function D(e){if(e==null)return``;if(a(e))return e.t;if(typeof e==`symbol`)throw r(`UNRECOGNIZED_INSERT_VALUE`,`A symbol cannot be innerHTML.`);return String(e)}export{x as ssr,w as ssrElement,C as ssrHydrationKey,S as ssrRaw};
|
|
2
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.js","names":["TAG_NAME","VOID_ELEMENTS","SKIPPED_KEYS","innerHtmlOfValue","value","ssr","holes","parts","html","index","hole","isSsrNode","SsrNode","ssrRaw","ssrHydrationKey","key","nextKey","escapeHtml","ssrElement","tag","invalid","lowerTag","isSelect","isTextarea","control","hasValue","hasFallback","attributes","needsKey","classes","style","innerHtml","props","IGNORED_KEYS","isEventName","resolveValue","text","classText","collectTruthyKeys","styleText","plainHtml","ssrAttribute","name","attributeName","svg","BOOLEAN_ATTRIBUTES","ssrStyle","content","escape","children","propsChildren","textareaContent","markSelectedOptions","out"],"sources":["../../../src/server/element.ts"],"sourcesContent":["import { nextKey } from \"../internal/hydration-scope\";\nimport { attributeName, IGNORED_KEYS } from \"../internal/react-names\";\nimport { BOOLEAN_ATTRIBUTES, isEventName, ssrAttribute } from \"./attributes\";\nimport { classText, ssrStyle, styleText } from \"./class-style\";\nimport { invalid } from \"./errors\";\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name \"escape\" is part of the compiler contract (SSR output).\nimport { escape, escapeHtml, resolveValue } from \"./escape\";\nimport { markSelectedOptions, textareaContent } from \"./form-controls\";\nimport { isSsrNode, SsrNode } from \"./node\";\n\n/** A tag name: letters, digits and dashes, starting with a letter. Anything else could break out. */\nconst TAG_NAME = /^[A-Za-z][A-Za-z0-9-]*$/;\n\n/** Elements that never have children or a closing tag. */\nconst VOID_ELEMENTS: ReadonlySet<string> = new Set([\n \"area\",\n \"base\",\n \"br\",\n \"col\",\n \"command\",\n \"embed\",\n \"hr\",\n \"img\",\n \"input\",\n \"keygen\",\n \"link\",\n \"meta\",\n \"param\",\n \"source\",\n \"track\",\n \"wbr\",\n]);\n\n/** Keys that never become attributes: they are handled elsewhere or would reach a prototype. */\nconst SKIPPED_KEYS: ReadonlySet<string> = new Set([\n \"__proto__\",\n \"constructor\",\n \"prototype\",\n \"children\",\n \"ref\",\n]);\n\n/** The HTML of a `dangerouslySetInnerHTML` value (`{ __html }`): null and undefined are empty. */\nfunction innerHtmlOfValue(value: unknown): unknown {\n if (value === null || typeof value !== \"object\") return undefined;\n return Reflect.get(value, \"__html\");\n}\n\n/**\n * Joins the static parts of a server template with its dynamic holes into trusted markup: the\n * function compiled server output calls for each element tree. Holes are inserted unchanged, so each\n * must already be escaped (the output of `escape`, `ssrAttribute`, `ssrClass`, ...) or an `SsrNode`;\n * any other value throws, so a raw user value cannot reach the markup.\n *\n * @param parts The static markup, one more entry than there are holes.\n * @param holes The dynamic parts: strings produced by the escaping helpers, or `SsrNode` values.\n * @returns The markup as a trusted `SsrNode`, which `escape` writes without encoding.\n * @throws TypeError when `parts` is not an array of `holes.length + 1` entries, or when a hole is not\n * a string or an `SsrNode`.\n * @example\n * import { escape, renderToString, ssr } from \"@shadow-js/web/server\";\n *\n * const name = \"<Ada>\";\n * const html = renderToString(() => ssr([\"<p>Hello, \", \"</p>\"], escape(name)));\n * // \"<p>Hello, <Ada></p>\"\n * @see ssrRaw\n * @since 1.0.0\n */\nexport function ssr(parts: readonly string[], ...holes: unknown[]): SsrNode {\n if (!Array.isArray(parts) || parts.length !== holes.length + 1) {\n throw new TypeError(\"ssr(): parts must have one more entry than there are holes.\");\n }\n let html = parts[0] ?? \"\";\n for (let index = 0; index < holes.length; index += 1) {\n const hole = holes[index];\n if (typeof hole === \"string\") html += hole;\n else if (isSsrNode(hole)) html += hole.t;\n else throw new TypeError(\"ssr(): a hole must be an escaped string or an SsrNode.\");\n html += parts[index + 1] ?? \"\";\n }\n return new SsrNode(html);\n}\n\n/**\n * Marks a string as trusted markup that `escape` and `ssr` insert unchanged. Only use it for markup\n * the application wrote itself, never for user input.\n *\n * @param html The markup, inserted unchanged.\n * @returns The markup as a trusted `SsrNode`.\n * @throws TypeError when `html` is not a string.\n * @example\n * import { renderToString, ssrRaw } from \"@shadow-js/web/server\";\n *\n * const html = renderToString(() => [\"<b>escaped</b>\", ssrRaw(\"<!-- build 42 -->\")]);\n * // \"<b>escaped</b><!-- build 42 -->\"\n * @see ssr\n * @since 1.0.0\n */\nexport function ssrRaw(html: string): SsrNode {\n if (typeof html !== \"string\") throw new TypeError(\"ssrRaw(): the markup must be a string.\");\n return new SsrNode(html);\n}\n\n/**\n * Draws the next hydration key of the current scope and returns it as a `data-hk` attribute, such as\n * `' data-hk=\"0-0\"'`: compiled server output calls it for the root element of each template, and\n * the client's `hydrate()` claims the element by that key. Calls must happen in the same order as on\n * the client, so call it only where the compiler would.\n *\n * @returns Markup for the `data-hk` attribute, or `\"\"` outside a server render (no key is drawn).\n * @example\n * import { renderToString, ssr, ssrHydrationKey } from \"@shadow-js/web/server\";\n *\n * const html = renderToString(() => ssr([\"<div\", \">x</div>\"], ssrHydrationKey()));\n * // '<div data-hk=\"0-0\">x</div>'\n * @since 1.0.0\n */\nexport function ssrHydrationKey(): string {\n const key = nextKey();\n return key === undefined ? \"\" : ` data-hk=\"${escapeHtml(key)}\"`;\n}\n\n/**\n * Renders an element from a props object: what compiled server output calls for an element with a\n * spread (`<div {...props} />`), and the server half of `Dynamic` and `element`. It writes the same\n * markup the client's `spread` produces.\n *\n * `class`, `className`, `classList` and `style` are combined into one `class` and one `style`\n * attribute; other keys are attributes, with React names mapped (`htmlFor` is `for`) and HTML boolean\n * attributes (`disabled`, `checked`, ...) written as bare names. `ref`, `children`, `on*` keys and the\n * `on:`, `use:` and `prop:` prefixes are skipped; `attr:` and `bool:` select the attribute and presence\n * forms. `innerHTML` and `dangerouslySetInnerHTML` are written unescaped as the content. On a\n * `textarea` the `value` (or `defaultValue`) is the content; on a `select` it marks the matching\n * `<option selected>` (an array for `multiple`); on other elements `defaultValue` and `defaultChecked`\n * are the `value` and `checked` attributes. Void elements (`img`, `input`, ...) get no content.\n *\n * @param tag Element name: letters, digits and dashes, starting with a letter.\n * @param props The props object (each getter is read once), or `null`.\n * @param children The content, escaped unless it is an `SsrNode`. Undefined (the default) uses the\n * `children` prop.\n * @param needsKey `true` writes the hydration key of this template root first. Default: `false`.\n * @param svg `true` for an SVG element: SVG presentation names are hyphenated (`strokeWidth` is\n * `stroke-width`), other names keep their case. Default: `false`.\n * @returns The element as a trusted `SsrNode`.\n * @throws TypeError `INVALID_TAG_NAME` for an invalid tag, `INVALID_ATTRIBUTE_NAME` for an invalid\n * attribute name, and the errors of {@link ssrAttribute}, `ssrClass` and `ssrStyle` for invalid values.\n * @example\n * import { renderToString, ssrElement } from \"@shadow-js/web/server\";\n *\n * const props = { id: \"save\", disabled: true, class: [\"btn\", { primary: true }], children: \"Save\" };\n * const html = renderToString(() => ssrElement(\"button\", props));\n * // '<button id=\"save\" disabled class=\"btn primary\">Save</button>'\n * @since 1.0.0\n */\nexport function ssrElement(\n tag: string,\n props: unknown,\n children: unknown = undefined,\n needsKey = false,\n svg = false,\n): SsrNode {\n if (typeof tag !== \"string\" || !TAG_NAME.test(tag)) {\n throw invalid(\"INVALID_TAG_NAME\", `\"${String(tag)}\" is not a valid tag name.`);\n }\n const lowerTag = tag.toLowerCase();\n // A browser ignores `value` on these: a textarea's value is its content, a select's value is the\n // `selected` flag of its options. The props are read once and applied to the content below.\n const isSelect = lowerTag === \"select\";\n const isTextarea = lowerTag === \"textarea\";\n const control: { value?: unknown; fallback?: unknown } = {};\n let hasValue = false;\n let hasFallback = false;\n let attributes = needsKey ? ssrHydrationKey() : \"\";\n const classes: string[] = [];\n let style = \"\";\n let innerHtml: string | undefined;\n if (props !== null && typeof props === \"object\") {\n for (const key of Object.keys(props)) {\n if (SKIPPED_KEYS.has(key) || IGNORED_KEYS.has(key)) continue;\n if (\n key === \"ref\" ||\n key.startsWith(\"on:\") ||\n key.startsWith(\"use:\") ||\n key.startsWith(\"prop:\")\n )\n continue;\n if (isEventName(key)) continue;\n if (needsKey && key === \"data-hk\") continue;\n const value = resolveValue(Reflect.get(props, key));\n if (key === \"class\" || key === \"className\") {\n const text = classText(value);\n if (text !== \"\") classes.push(text);\n } else if (key === \"classList\") {\n collectTruthyKeys(value, classes);\n } else if (key === \"style\") {\n style = styleText(value);\n } else if (key === \"innerHTML\") {\n innerHtml = plainHtml(value);\n } else if (key === \"dangerouslySetInnerHTML\") {\n innerHtml = plainHtml(resolveValue(innerHtmlOfValue(value)));\n } else if ((isSelect || isTextarea) && key === \"value\") {\n control.value = value;\n hasValue = true;\n } else if ((isSelect || isTextarea) && key === \"defaultValue\") {\n control.fallback = value;\n hasFallback = true;\n } else if (key.startsWith(\"attr:\")) {\n attributes += ssrAttribute(key.slice(5), value);\n } else if (key.startsWith(\"bool:\")) {\n attributes += ssrAttribute(key.slice(5), value, true);\n } else if (key === \"defaultValue\" || key === \"defaultChecked\") {\n // The attributes of the same name in HTML are the defaults: `value` and `checked`.\n const name = key === \"defaultValue\" ? \"value\" : \"checked\";\n if (!Object.hasOwn(props, name))\n attributes += ssrAttribute(name, value, name === \"checked\");\n } else {\n const name = attributeName(key, svg);\n attributes += ssrAttribute(name, value, BOOLEAN_ATTRIBUTES.has(name));\n }\n }\n }\n if (classes.length > 0) attributes += ` class=\"${escapeHtml(classes.join(\" \"))}\"`;\n if (style !== \"\") attributes += ssrStyle(style);\n if (VOID_ELEMENTS.has(lowerTag)) return new SsrNode(`<${tag}${attributes}>`);\n // Like the DOM `spread`: a `children` prop supplies the content unless the element wrote its own.\n let content =\n innerHtml !== undefined\n ? innerHtml\n : escape(children === undefined ? propsChildren(props) : children);\n if (innerHtml === undefined && (hasValue || hasFallback)) {\n const value = hasValue ? control.value : control.fallback;\n content = isTextarea ? textareaContent(value) : markSelectedOptions(value, content);\n }\n return new SsrNode(`<${tag}${attributes}>${content}</${tag}>`);\n}\n\n/** The `children` of a spread props object (read once, so a getter runs once), or undefined. */\nfunction propsChildren(props: unknown): unknown {\n if (props === null || typeof props !== \"object\") return undefined;\n return Reflect.get(props, \"children\");\n}\n\n/** Class names whose key is truthy, from a `classList` object. */\nfunction collectTruthyKeys(value: unknown, out: string[]): void {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return;\n for (const key of Object.keys(value)) {\n if (key !== \"\" && resolveValue(Reflect.get(value, key))) out.push(key);\n }\n}\n\n/** Raw HTML text for `innerHTML`: null and undefined become \"\", an SsrNode its markup. */\nfunction plainHtml(value: unknown): string {\n if (value === null || value === undefined) return \"\";\n if (isSsrNode(value)) return value.t;\n if (typeof value === \"symbol\")\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be innerHTML.\");\n return String(value);\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","names":["SsrError","code","invalid"],"sources":["../../../src/server/errors.ts"],"sourcesContent":["/** Diagnostic codes raised by the server renderer. @internal */\nexport type SsrErrorCode = \"SSR_BOUNDARY_WATERFALL\" | \"SSR_PORTAL_LIMIT\" | \"SSR_TIMEOUT\";\n\n/**\n * Error thrown by the server renderer, carrying a stable code. Dev builds carry the full text;\n * production builds keep only the code (the same split as core's diagnostics).\n * @internal\n */\nexport class SsrError extends Error {\n readonly code: SsrErrorCode;\n constructor(code: SsrErrorCode, detail: string) {\n super(__DEV__ ? `[shadow ${code}] ${detail}` : `SHADOW_${code}`);\n this.name = \"SsrError\";\n this.code = code;\n }\n}\n\n/**\n * A TypeError for input the renderer refuses: a value that could become unsafe markup, or a\n * malformed argument. Dev builds carry the detail; production builds keep the code.\n * @internal\n */\nexport function invalid(code: string, detail: string): TypeError {\n return new TypeError(__DEV__ ? `[shadow ${code}] ${detail}` : `SHADOW_${code}`);\n}\n"],"mappings":"AAQA,IAAaA,EAAb,cAA8B,KAAM,CAClC,KACA,YAAY,EAAoB,EAAgB,CAC9C,MAA+C,UAAUC,GAAM,EAC/D,KAAK,KAAO,WACZ,KAAK,KAAOA,CACd,CACF,EAOA,SAAgBC,EAAQ,EAAc,EAA2B,CAC/D,MAAO,gBAAI,UAAmD,UAAUD,GAAM,CAChF,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{invalid as e}from"./errors.js";import{isSsrNode as t}from"./node.js";import{untrack as n}from"@shadow-js/core";const r={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},i=/[&<>"']/g;function a(e){return e.replace(i,e=>r[e]??e)}function o(e){let t=e;for(let e=0;typeof t==`function`;e+=1){if(e>=1e3)throw TypeError(`An accessor returns accessors more than 1000 levels deep.`);t=n(t)}return t}function s(n,r){if(n!=null&&typeof n!=`boolean`){if(typeof n==`string`)r.push(a(n));else if(typeof n==`number`||typeof n==`bigint`)r.push(String(n));else{if(typeof n==`symbol`)throw e(`UNRECOGNIZED_INSERT_VALUE`,`A symbol cannot be rendered.`);t(n)?r.push(n.t):typeof n!=`object`&&r.push(a(String(n)))}}}function c(e){let t=[],n=[],r=[],i=/* @__PURE__ */ new Set,a=e;for(;;){let e=o(a);if(Array.isArray(e)){if(i.has(e))throw TypeError(`escape(): an array contains itself.`);i.add(e),n.push(e),r.push(0)}else s(e,t);let c,l=!1;for(;!l&&n.length>0;){let e=n.length-1,t=n[e],a=r[e]??0;if(t===void 0)break;a<t.length?(r[e]=a+1,c=t[a],l=!0):(n.pop(),r.pop(),i.delete(t))}if(!l)return t.join(``);a=c}}export{c as escape,a as escapeHtml,o as resolveValue};
|
|
2
|
+
//# sourceMappingURL=escape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.js","names":["accessor","HTML_ESCAPES","HTML_SPECIAL","escapeHtml","text","char","resolveValue","current","value","layer","untrack","appendLeaf","out","invalid","isSsrNode","escape","frames","cursors","open","item","resolved","next","found","top","frame","cursor"],"sources":["../../../src/server/escape.ts"],"sourcesContent":["import { untrack } from \"@shadow-js/core\";\nimport { invalid } from \"./errors\";\nimport { isSsrNode } from \"./node\";\n\nconst HTML_ESCAPES: Readonly<Record<string, string>> = {\n \"&\": \"&\",\n \"<\": \"<\",\n \">\": \">\",\n '\"': \""\",\n \"'\": \"'\",\n};\n\nconst HTML_SPECIAL = /[&<>\"']/g;\n\n/** Longest chain of accessors that returns accessors; longer chains are a bug in user code. */\nconst MAX_ACCESSOR_LAYERS = 1000;\n\n/**\n * Escapes the five HTML-significant characters. Escaping `&` too means entity-looking text is\n * written literally, and the result is safe in text and in quoted attribute values alike.\n * @internal\n */\nexport function escapeHtml(text: string): string {\n return text.replace(HTML_SPECIAL, (char) => HTML_ESCAPES[char] ?? char);\n}\n\n/**\n * Calls accessors until a plain value remains. Accessors run untracked; a chain longer than\n * {@link MAX_ACCESSOR_LAYERS} throws instead of looping.\n * @internal\n */\nexport function resolveValue(value: unknown): unknown {\n let current = value;\n for (let layer = 0; typeof current === \"function\"; layer += 1) {\n if (layer >= MAX_ACCESSOR_LAYERS) {\n throw new TypeError(\"An accessor returns accessors more than 1000 levels deep.\");\n }\n const accessor = current as () => unknown;\n current = untrack(accessor);\n }\n return current;\n}\n\n/** Writes the markup for one resolved value that is not an array. */\nfunction appendLeaf(value: unknown, out: string[]): void {\n if (value === null || value === undefined || typeof value === \"boolean\") return;\n if (typeof value === \"string\") {\n out.push(escapeHtml(value));\n return;\n }\n // Numbers and bigints never contain markup characters.\n if (typeof value === \"number\" || typeof value === \"bigint\") {\n out.push(String(value));\n return;\n }\n if (typeof value === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be rendered.\");\n }\n if (isSsrNode(value)) {\n out.push(value.t);\n return;\n }\n // Any other object is not trusted markup. Dev fails loudly; production renders nothing.\n if (typeof value === \"object\") {\n if (__DEV__) {\n throw invalid(\n \"UNRECOGNIZED_INSERT_VALUE\",\n \"A plain object cannot be rendered. Use a string, a number, an array or an SsrNode.\",\n );\n }\n return;\n }\n out.push(escapeHtml(String(value)));\n}\n\n/**\n * Converts any value a JSX child may hold to escaped HTML: the helper compiled server output calls\n * for every dynamic child, and what the renderers call on the app's result.\n *\n * - Strings are escaped (`& < > \" '`); numbers and bigints are written as they are; `null`,\n * `undefined` and booleans render nothing.\n * - `SsrNode` values (from `ssr`, `ssrRaw` and the other helpers) pass through unchanged: they were\n * escaped when they were built.\n * - Accessors are called (untracked) and their result is rendered; a chain of more than 1000\n * accessors returning accessors throws.\n * - Arrays are flattened in order, with an explicit stack, so nesting depth is not limited by the\n * call stack.\n * - Plain objects throw in development builds and render nothing in production builds.\n *\n * @param value The value to render.\n * @returns The escaped markup.\n * @throws TypeError when an array contains itself, for a symbol (`UNRECOGNIZED_INSERT_VALUE`), for an\n * object that is not an `SsrNode` (`UNRECOGNIZED_INSERT_VALUE`, development builds only), and for an\n * accessor chain deeper than 1000.\n * @example\n * import { escape } from \"@shadow-js/web/server\";\n *\n * const name = () => \"<Ada>\";\n * escape([\"Hello, \", name, null, 3]); // \"Hello, <Ada>3\"\n * @since 1.0.0\n */\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name \"escape\" is part of the compiler contract (SSR output).\nexport function escape(value: unknown): string {\n const out: string[] = [];\n const frames: unknown[][] = [];\n const cursors: number[] = [];\n const open = new Set<unknown[]>();\n let item: unknown = value;\n for (;;) {\n const resolved = resolveValue(item);\n if (Array.isArray(resolved)) {\n if (open.has(resolved)) throw new TypeError(\"escape(): an array contains itself.\");\n open.add(resolved);\n frames.push(resolved);\n cursors.push(0);\n } else {\n appendLeaf(resolved, out);\n }\n // Find the next item, closing every array that has no items left.\n let next: unknown;\n let found = false;\n while (!found && frames.length > 0) {\n const top = frames.length - 1;\n const frame = frames[top];\n const cursor = cursors[top] ?? 0;\n if (frame === undefined) break;\n if (cursor < frame.length) {\n cursors[top] = cursor + 1;\n next = frame[cursor];\n found = true;\n } else {\n frames.pop();\n cursors.pop();\n open.delete(frame);\n }\n }\n if (!found) return out.join(\"\");\n item = next;\n }\n}\n"],"mappings":"A,sHAIA,MAAMC,EAAiD,CACrD,IAAK,QACL,IAAK,OACL,IAAK,OACL,IAAK,SACL,IAAK,OACP,EAEMC,EAAe,WAUrB,SAAgBC,EAAW,EAAsB,CAC/C,OAAOC,EAAK,QAAQF,EAAe,GAASD,EAAaI,IAASA,CAAI,CACxE,CAOA,SAAgBC,EAAa,EAAyB,CACpD,IAAIC,EAAUC,EACd,IAAK,IAAIC,EAAQ,EAAG,OAAOF,GAAY,WAAY,GAAS,EAAG,CAC7D,GAAIE,GAAS,IACX,MAAU,UAAU,2DAA2D,EAGjF,EAAUC,EAAQV,CAAQ,CAC5B,CACA,OAAOO,CACT,CAGA,SAASI,EAAW,EAAgB,EAAqB,CACvD,GAAIH,GAAU,MAA+B,OAAOA,GAAU,UAC9D,IAAI,OAAOA,GAAU,SACnBI,EAAI,KAAKT,EAAWK,CAAK,CAAC,OAI5B,GAAI,OAAOA,GAAU,UAAY,OAAOA,GAAU,SAChDI,EAAI,KAAK,OAAOJ,CAAK,CAAC,MAGxB,IAAI,OAAOA,GAAU,SACnB,MAAMK,EAAQ,4BAA6B,8BAA8B,EAEvEC,EAAUN,CAAK,EACjBI,EAAI,KAAKJ,EAAM,CAAC,EAId,OAAOA,GAAU,UASrBI,EAAI,KAAKT,EAAW,OAAOK,CAAK,CAAC,CAAC,CAhByC,CAP3E,CAwBF,CA6BA,SAAgBO,EAAO,EAAwB,CAC7C,IAAMH,EAAgB,CAAC,EACjBI,EAAsB,CAAC,EACvBC,EAAoB,CAAC,EACrBC,kBAAO,IAAI,IACbC,EAAgBX,EACpB,OAAS,CACP,IAAMY,EAAWd,EAAaa,CAAI,EAClC,GAAI,MAAM,QAAQC,CAAQ,EAAG,CAC3B,GAAIF,EAAK,IAAIE,CAAQ,EAAG,MAAU,UAAU,qCAAqC,EACjFF,EAAK,IAAIE,CAAQ,EACjBJ,EAAO,KAAKI,CAAQ,EACpBH,EAAQ,KAAK,CAAC,CAChB,MACEN,EAAWS,EAAUR,CAAG,EAG1B,IAAIS,EACAC,EAAQ,GACZ,KAAO,CAACA,GAASN,EAAO,OAAS,GAAG,CAClC,IAAMO,EAAMP,EAAO,OAAS,EACtBQ,EAAQR,EAAOO,GACfE,EAASR,EAAQM,IAAQ,EAC/B,GAAIC,IAAU,IAAA,GAAW,MACrBC,EAASD,EAAM,QACjB,EAAQD,GAAOE,EAAS,EACxB,EAAOD,EAAMC,GACb,EAAQ,KAERT,EAAO,IAAI,EACXC,EAAQ,IAAI,EACZC,EAAK,OAAOM,CAAK,EAErB,CACA,GAAI,CAACF,EAAO,OAAOV,EAAI,KAAK,EAAE,EAC9B,EAAOS,CACT,CACF,C"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{invalid as e}from"./errors.js";import{SsrNode as t}from"./node.js";import{escape as n,escapeHtml as r,resolveValue as i}from"./escape.js";function a(t){if(typeof t==`symbol`)throw e(`UNRECOGNIZED_INSERT_VALUE`,`A symbol cannot be a form control value.`);return t==null?``:String(t)}function o(e){let t=r(a(i(e))),n=t.charAt(0);return n===`
|
|
2
|
+
`||n===`\r`?`\n${t}`:t}function s(e){return new t(o(e))}function c(e){let t=i(e);if(!Array.isArray(t))return{values:/* @__PURE__ */ new Set([a(t)]),many:!1};let n=/* @__PURE__ */ new Set;for(let e of t){let t=i(e);t!=null&&n.add(a(t))}return{values:n,many:!0}}const l=/[ \t\n\f\r]+/g,u=/&(?:#(\d+)|#x([0-9a-f]+)|(amp|lt|gt|quot|apos|nbsp));/gi,d={amp:`&`,lt:`<`,gt:`>`,quot:`"`,apos:`'`,nbsp:`\xA0`},f=/<!--[\s\S]*?-->|<[^>]*>/g;function p(e){return e.replace(u,(e,t,n,r)=>{if(r!==void 0)return d[r.toLowerCase()]??e;let i=t===void 0?Number.parseInt(n??``,16):Number(t);return Number.isInteger(i)&&i>=0&&i<=1114111&&!(i>=55296&&i<=57343)?String.fromCodePoint(i):e})}function m(e,t){let n=``;for(let r=t;r<e.length;r+=1){let t=e.charAt(r);if(n!==``)t===n&&(n=``);else if(t===`"`||t===`'`)n=t;else if(t===`>`)return r}return-1}function h(e,t,n){n.lastIndex=t;let r=n.exec(e);return p(e.slice(t,r===null?e.length:r.index).replace(f,``)).replace(l,` `).trim()}function g(e,t){let n=``,r=0,i=0,a=!1,o=/* @__PURE__ */ RegExp(`\\s+([^\\s"'<>/=]+)(?:\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s"'=<>\`]+)))?`,`g`),s=/* @__PURE__ */ RegExp(`<\\/?(?:option|optgroup)(?=[\\s/>])`,`gi`);for(;;){let c=e.indexOf(`<option`,i);if(c===-1)break;let l=c+7;if(i=l,!/[\s/>]/.test(e.charAt(l)))continue;let u=m(e,l);if(u===-1)break;let d=e.slice(l,u),f,g=-1,_=-1;o.lastIndex=0;for(let e=o.exec(d);e!==null;e=o.exec(d)){let t=(e[1]??``).toLowerCase();t===`selected`?(g=e.index,_=e.index+e[0].length):t===`value`&&f===void 0&&(f=p(e[2]??e[3]??e[4]??``))}let v=(t.many||!a)&&t.values.has(f??h(e,u+1,s));if(v&&(a=!0),v&&g===-1){let t=d.endsWith(`/`)?d.length-1:d.length;n+=`${e.slice(r,l+t)} selected`,r=l+t}else!v&&g!==-1&&(n+=e.slice(r,l+g),r=l+_);i=u}return r===0?e:n+e.slice(r)}function _(e,r){return new t(v(e,n(r)))}function v(e,t){return g(t,c(e))}export{v as markSelectedOptions,_ as ssrSelectValue,s as ssrTextArea,o as textareaContent};
|
|
3
|
+
//# sourceMappingURL=form-controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-controls.js","names":["valueText","value","invalid","textareaContent","html","escapeHtml","resolveValue","first","ssrTextArea","SsrNode","wantedValues","resolved","values","item","one","WHITESPACE","ENTITY","NAMED_ENTITIES","TAGS","decodeEntities","text","named","whole","code","decimal","hex","tagEnd","quote","index","from","char","optionText","boundary","boundaries","markOptions","out","copied","at","found","attribute","start","attributesFrom","end","source","selectedAt","selectedEnd","match","name","matches","wanted","slash","ssrSelectValue","markSelectedOptions","escape","children"],"sources":["../../../src/server/form-controls.ts"],"sourcesContent":["import { invalid } from \"./errors\";\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name \"escape\" is part of the compiler contract (SSR output).\nimport { escape, escapeHtml, resolveValue } from \"./escape\";\nimport { SsrNode } from \"./node\";\n\n/**\n * Server markup for the controls whose state is not an attribute. A browser ignores `value` on a\n * `<textarea>` and on a `<select>`: the textarea's text is its content, and the select's value is\n * the `selected` flag of its options. These helpers write that markup, so the server HTML shows the\n * same state the client sets and a form posted without JavaScript sends it.\n */\n\n/** Text of a value for a textarea: null and undefined are empty, everything else is its string. */\nfunction valueText(value: unknown): string {\n if (typeof value === \"symbol\") {\n throw invalid(\"UNRECOGNIZED_INSERT_VALUE\", \"A symbol cannot be a form control value.\");\n }\n return value === null || value === undefined ? \"\" : String(value);\n}\n\n/**\n * Markup of a textarea's content. The HTML parser drops one newline directly after `<textarea>`,\n * so a value that starts with a line break gets one more; its content is then exactly the value.\n * @internal\n */\nexport function textareaContent(value: unknown): string {\n const html = escapeHtml(valueText(resolveValue(value)));\n const first = html.charAt(0);\n return first === \"\\n\" || first === \"\\r\" ? `\\n${html}` : html;\n}\n\n/**\n * Renders the content of a `<textarea>` from its value: the helper compiled server output calls for\n * `<textarea value={...}>` and `defaultValue`, since a browser ignores a `value` attribute on a\n * textarea. The text is escaped, and a value that starts with a line break gets one more, because\n * the HTML parser drops the first one.\n *\n * @param value The value, or an accessor of it. `null` and `undefined` give an empty textarea;\n * anything else is written as `String(value)`.\n * @returns The escaped content as a trusted `SsrNode`.\n * @throws TypeError `UNRECOGNIZED_INSERT_VALUE` when the value is a symbol.\n * @example\n * import { renderToString, ssr, ssrTextArea } from \"@shadow-js/web/server\";\n *\n * const bio = \"Loves <b>tags</b>\";\n * const html = renderToString(() => ssr([\"<textarea>\", \"</textarea>\"], ssrTextArea(bio)));\n * // \"<textarea>Loves <b>tags</b></textarea>\"\n * @see ssrSelectValue\n * @since 1.0.0\n */\nexport function ssrTextArea(value: unknown): SsrNode {\n return new SsrNode(textareaContent(value));\n}\n\n/** The values a select value stands for: an array lists them (`multiple`), anything else is one. */\nfunction wantedValues(value: unknown): { values: Set<string>; many: boolean } {\n const resolved = resolveValue(value);\n if (!Array.isArray(resolved)) return { values: new Set([valueText(resolved)]), many: false };\n const values = new Set<string>();\n for (const item of resolved) {\n const one = resolveValue(item);\n if (one !== null && one !== undefined) values.add(valueText(one));\n }\n return { values, many: true };\n}\n\n/** Characters of the HTML spec's \"ASCII whitespace\". */\nconst WHITESPACE = /[ \\t\\n\\f\\r]+/g;\n/** Entities our own escaping writes, plus numeric references and ` ` from trusted raw markup. */\nconst ENTITY = /&(?:#(\\d+)|#x([0-9a-f]+)|(amp|lt|gt|quot|apos|nbsp));/gi;\nconst NAMED_ENTITIES: Readonly<Record<string, string>> = {\n amp: \"&\",\n lt: \"<\",\n gt: \">\",\n quot: '\"',\n apos: \"'\",\n nbsp: \" \",\n};\n/** Comments and tags inside an option's text (the region markers the compiler writes). */\nconst TAGS = /<!--[\\s\\S]*?-->|<[^>]*>/g;\n/**\n * The next option or optgroup tag, start or end: where an option's text ends. Sources of global\n * expressions, built per call so no `lastIndex` outlives it.\n */\nconst OPTION_BOUNDARY = \"<\\\\/?(?:option|optgroup)(?=[\\\\s/>])\";\n/** One attribute of a start tag: name, then an optional quoted or bare value. */\nconst ATTRIBUTE = \"\\\\s+([^\\\\s\\\"'<>/=]+)(?:\\\\s*=\\\\s*(?:\\\"([^\\\"]*)\\\"|'([^']*)'|([^\\\\s\\\"'=<>`]+)))?\";\n\nfunction decodeEntities(text: string): string {\n return text.replace(ENTITY, (whole, decimal?: string, hex?: string, named?: string) => {\n if (named !== undefined) return NAMED_ENTITIES[named.toLowerCase()] ?? whole;\n const code = decimal !== undefined ? Number(decimal) : Number.parseInt(hex ?? \"\", 16);\n return Number.isInteger(code) &&\n code >= 0 &&\n code <= 0x10ffff &&\n !(code >= 0xd800 && code <= 0xdfff)\n ? String.fromCodePoint(code)\n : whole;\n });\n}\n\n/** Index of the `>` that ends the start tag whose attributes begin at `from`, or -1. Quotes are skipped. */\nfunction tagEnd(html: string, from: number): number {\n let quote = \"\";\n for (let index = from; index < html.length; index += 1) {\n const char = html.charAt(index);\n if (quote !== \"\") {\n if (char === quote) quote = \"\";\n } else if (char === '\"' || char === \"'\") {\n quote = char;\n } else if (char === \">\") {\n return index;\n }\n }\n return -1;\n}\n\n/** The text an option without a `value` attribute stands for: its text content, whitespace collapsed. */\nfunction optionText(html: string, from: number, boundaries: RegExp): string {\n boundaries.lastIndex = from;\n const boundary = boundaries.exec(html);\n const raw = html.slice(from, boundary === null ? html.length : boundary.index);\n return decodeEntities(raw.replace(TAGS, \"\")).replace(WHITESPACE, \" \").trim();\n}\n\n/**\n * Rewrites the option start tags of `html` so that exactly the wanted ones carry `selected`. The\n * input is markup this runtime produced (text and attribute values are escaped, so `<option` is\n * always a tag); only the `selected` attribute is added or removed, and nothing from the wanted\n * values is ever written.\n */\nfunction markOptions(html: string, wanted: { values: Set<string>; many: boolean }): string {\n let out = \"\";\n let copied = 0;\n let at = 0;\n let found = false;\n const attribute = new RegExp(ATTRIBUTE, \"g\");\n const boundaries = new RegExp(OPTION_BOUNDARY, \"gi\");\n for (;;) {\n const start = html.indexOf(\"<option\", at);\n if (start === -1) break;\n const attributesFrom = start + 7;\n at = attributesFrom;\n if (!/[\\s/>]/.test(html.charAt(attributesFrom))) continue;\n const end = tagEnd(html, attributesFrom);\n if (end === -1) break;\n const source = html.slice(attributesFrom, end);\n let value: string | undefined;\n let selectedAt = -1;\n let selectedEnd = -1;\n attribute.lastIndex = 0;\n for (let match = attribute.exec(source); match !== null; match = attribute.exec(source)) {\n const name = (match[1] ?? \"\").toLowerCase();\n if (name === \"selected\") {\n selectedAt = match.index;\n selectedEnd = match.index + match[0].length;\n } else if (name === \"value\" && value === undefined) {\n value = decodeEntities(match[2] ?? match[3] ?? match[4] ?? \"\");\n }\n }\n // A scalar behaves like `select.value = x`: the first option with that value wins.\n const matches =\n (wanted.many || !found) && wanted.values.has(value ?? optionText(html, end + 1, boundaries));\n if (matches) found = true;\n if (matches && selectedAt === -1) {\n const slash = source.endsWith(\"/\") ? source.length - 1 : source.length;\n out += `${html.slice(copied, attributesFrom + slash)} selected`;\n copied = attributesFrom + slash;\n } else if (!matches && selectedAt !== -1) {\n out += html.slice(copied, attributesFrom + selectedAt);\n copied = attributesFrom + selectedEnd;\n }\n at = end;\n }\n return copied === 0 ? html : out + html.slice(copied);\n}\n\n/**\n * The options of a `<select>` with the ones its value stands for marked `selected`. A browser\n * ignores a `value` attribute on `<select>`, so the server flags the options instead: the option\n * whose `value` attribute equals the value (or, with no such attribute, whose text does) is\n * selected, and every other option loses `selected`. An array selects every listed option, for\n * `<select multiple>`; a single value selects the first match, like `select.value = x`. `null`\n * and `undefined` stand for the empty string. Options inside `<optgroup>`, control flow and\n * components are found because the search runs on the serialized children. Values are compared,\n * never written, so they cannot add markup.\n *\n * @param value The select's `value`, or an accessor of it. Entries of an array are compared as\n * strings; `null` and `undefined` entries are skipped.\n * @param children The select's children (an `SsrNode`, or anything `escape` accepts).\n * @returns The children with the `selected` flags set, as a trusted `SsrNode`.\n * @throws TypeError `UNRECOGNIZED_INSERT_VALUE` when the value is a symbol, and the errors of\n * {@link escape} for the children.\n * @example\n * import { renderToString, ssr, ssrRaw, ssrSelectValue } from \"@shadow-js/web/server\";\n *\n * const options = ssrRaw(`<option value=\"red\">Red</option><option value=\"blue\">Blue</option>`);\n * const html = renderToString(() => ssr([\"<select>\", \"</select>\"], ssrSelectValue(\"blue\", options)));\n * // '<select><option value=\"red\">Red</option><option value=\"blue\" selected>Blue</option></select>'\n * @see setSelectValue\n * @since 1.0.0\n */\nexport function ssrSelectValue(value: unknown, children: unknown): SsrNode {\n return new SsrNode(markSelectedOptions(value, escape(children)));\n}\n\n/** {@link ssrSelectValue} on markup that is already escaped. @internal */\nexport function markSelectedOptions(value: unknown, html: string): string {\n return markOptions(html, wantedValues(value));\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{ssrRaw as e}from"./element.js";import{DEFAULT_EARLY_EVENTS as t,captureScriptBody as n}from"../internal/early-events.js";const r=/^[A-Za-z0-9+/=_-]+$/;function i(e={}){let i=e.nonce,a=i!==void 0&&r.test(i)?` nonce="${i}"`:``,o=e.eventNames??t;return`<script${a}>${n(o)}<\/script>`}function a(t={}){return e(i(t))}export{a as HydrationScript,i as generateHydrationScript};
|
|
2
|
+
//# sourceMappingURL=hydration-script.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration-script.js","names":["NONCE","generateHydrationScript","nonce","options","attribute","names","DEFAULT_EARLY_EVENTS","captureScriptBody","HydrationScript","ssrRaw","props"],"sources":["../../../src/server/hydration-script.ts"],"sourcesContent":["import { captureScriptBody, DEFAULT_EARLY_EVENTS } from \"../internal/early-events\";\nimport { ssrRaw } from \"./element\";\n\n/**\n * Options of {@link generateHydrationScript} and {@link HydrationScript}.\n * @since 1.0.0\n */\nexport interface HydrationScriptOptions {\n /**\n * CSP nonce for the script. It is written only when it is a plain token (letters, digits, `+`, `/`,\n * `=`, `_`, `-`); any other value is ignored and the script gets no nonce.\n * @default undefined (no nonce attribute)\n */\n readonly nonce?: string;\n /**\n * Event types to capture before hydration. Only plain lower-case names (`[a-z]+`) are kept; others\n * are skipped.\n * @default [\"click\", \"input\"]\n */\n readonly eventNames?: readonly string[];\n}\n\nconst NONCE = /^[A-Za-z0-9+/=_-]+$/;\n\n/**\n * Returns the inline `<script>` that records the events a user makes before the app has hydrated, so\n * `hydrate()` can replay them once its handlers are attached (a click made while the bundle loads is\n * not lost). Put it in the `<head>` of the server-rendered page, before the bundle.\n *\n * @param options The CSP nonce and the event types to capture. Undefined uses the defaults of\n * {@link HydrationScriptOptions}.\n * @returns The script element as a string of markup.\n * @example\n * import { generateHydrationScript, renderToString } from \"@shadow-js/web/server\";\n *\n * function page(app: () => unknown, nonce: string): string {\n * const body = renderToString(app);\n * return `<html><head>${generateHydrationScript({ nonce })}</head><body>${body}</body></html>`;\n * }\n * @see HydrationScript\n * @since 1.0.0\n */\nexport function generateHydrationScript(options: HydrationScriptOptions = {}): string {\n const nonce = options.nonce;\n const attribute = nonce !== undefined && NONCE.test(nonce) ? ` nonce=\"${nonce}\"` : \"\";\n const names = options.eventNames ?? DEFAULT_EARLY_EVENTS;\n return `<script${attribute}>${captureScriptBody(names)}</script>`;\n}\n\n/**\n * {@link generateHydrationScript} as a component, for a document rendered with server JSX:\n * `<HydrationScript nonce={nonce} />` in the `<head>`.\n *\n * @param props The CSP nonce and the event types to capture. Undefined uses the defaults of\n * {@link HydrationScriptOptions}.\n * @returns The script as trusted raw markup.\n * @example\n * import { createComponent, HydrationScript, renderToString } from \"@shadow-js/web/server\";\n *\n * function Document() {\n * return (\n * <html>\n * <head>\n * <HydrationScript nonce=\"r4nd0m\" />\n * </head>\n * <body>Hello</body>\n * </html>\n * );\n * }\n * const html = renderToString(() => createComponent(Document, {}));\n * @see generateHydrationScript\n * @since 1.0.0\n */\nexport function HydrationScript(props: HydrationScriptOptions = {}): unknown {\n return ssrRaw(generateHydrationScript(props));\n}\n"],"mappings":"A,gIAsBA,MAAMA,EAAQ,sBAoBd,SAAgBC,EAAwB,EAAkC,CAAC,EAAW,CACpF,IAAMC,EAAQC,EAAQ,MAChBC,EAAYF,IAAU,IAAA,IAAaF,EAAM,KAAKE,CAAK,EAAI,WAAWA,EAAM,GAAK,GAC7EG,EAAQF,EAAQ,YAAcG,EACpC,MAAO,UAAUF,EAAU,GAAGG,EAAkBF,CAAK,EAAE,WACzD,CA0BA,SAAgBG,EAAgB,EAAgC,CAAC,EAAY,CAC3E,OAAOC,EAAOR,EAAwBS,CAAK,CAAC,CAC9C,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{escape as e}from"./escape.js";import{ssrAttribute as t}from"./attributes.js";import{ssrClass as n,ssrStyle as r}from"./class-style.js";import{ssrSelectValue as i,ssrTextArea as a}from"./form-controls.js";import{ssr as o,ssrElement as s,ssrHydrationKey as c,ssrRaw as l}from"./element.js";import{createServerPortals as u}from"./portals.js";import{normalizeTags as d}from"../head/validate.js";import{createServerHead as f}from"../head/server-head.js";import{createComponent as p,memo as m}from"./component.js";import{derived as h}from"./derived.js";import{HydrationScript as g,generateHydrationScript as _}from"./hydration-script.js";import{renderToString as v,renderToStringAsync as y}from"./render.js";import{deserialize as b,serialize as x}from"./serialize.js";import{renderToStream as S}from"./stream.js";import{mergeProps as C}from"@shadow-js/core";export{g as HydrationScript,p as createComponent,f as createServerHead,u as createServerPortals,h as derived,b as deserialize,e as escape,_ as generateHydrationScript,m as memo,C as mergeProps,d as normalizeTags,S as renderToStream,v as renderToString,y as renderToStringAsync,x as serialize,o as ssr,t as ssrAttribute,n as ssrClass,s as ssrElement,c as ssrHydrationKey,l as ssrRaw,i as ssrSelectValue,r as ssrStyle,a as ssrTextArea};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","names":["SsrNode","t","isSsrNode","value"],"sources":["../../../src/server/node.ts"],"sourcesContent":["/**\n * Markup that is already safe to insert: the only value `escape` writes without encoding.\n * A class instance, not a `{ t }` shape, so a plain object parsed from user input can never be\n * mistaken for trusted markup.\n * @internal\n */\nexport class SsrNode {\n readonly t: string;\n constructor(t: string) {\n this.t = t;\n }\n}\n\n/** True for values created by the server helpers. @internal */\nexport function isSsrNode(value: unknown): value is SsrNode {\n return value instanceof SsrNode;\n}\n"],"mappings":"AAMA,IAAaA,EAAb,KAAqB,CACnB,EACA,YAAY,EAAW,CACrB,KAAK,EAAIC,CACX,CACF,EAGA,SAAgBC,EAAU,EAAkC,CAC1D,OAAOC,aAAiBH,CAC1B,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{childScope as e,withScope as t}from"../internal/hydration-scope.js";import{SsrError as n}from"./errors.js";import{escape as r}from"./escape.js";import{PortalContext as i}from"../internal/portal-context.js";var a=class{entries=/* @__PURE__ */ new Map;add(e,t){if(!this.entries.has(e)&&this.entries.size>=256)throw new n(`SSR_PORTAL_LIMIT`,`A render produced more than 256 portals; close some overlays or raise the limit.`);this.entries.set(e,t)}clear(){this.entries.clear()}html(){let e=``;for(let[t,n]of this.entries)e+=`<!--portal:${t}-->${n}<!--/portal:${t}-->`;return e}};const o=/* @__PURE__ */ new WeakMap;function s(){let e=new a,t={html:()=>e.html()};return o.set(t,e),t}function c(e){let t=o.get(e);if(t===void 0)throw TypeError(`portals must be created with createServerPortals().`);return t}function l(n,i,a){if(a===null||n===void 0)return;let o=t(e(n),()=>r(i()));a.add(n,o)}function u(e,t){return i({value:e,get children(){return t()}})()}function d(e){if(e===void 0)return null;let t=c(e);return t.clear(),t}export{a as PortalCollector,c as collectorOf,s as createServerPortals,d as portalCollectorFor,l as renderServerPortal,u as withPortalSink};
|
|
2
|
+
//# sourceMappingURL=portals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portals.js","names":["PortalCollector","key","SsrError","html","out","collectors","createServerPortals","collector","portals","collectorOf","renderServerPortal","sink","withScope","childScope","escape","children","withPortalSink","PortalContext","build","portalCollectorFor"],"sources":["../../../src/server/portals.ts"],"sourcesContent":["import { childScope, withScope } from \"../internal/hydration-scope\";\nimport { PortalContext, type PortalSink } from \"../internal/portal-context\";\nimport { SsrError } from \"./errors\";\n// biome-ignore lint/suspicious/noShadowRestrictedNames: the name \"escape\" is part of the compiler contract (SSR output).\nimport { escape } from \"./escape\";\n\n/**\n * The most portals one render may produce. A page with more open overlays than this is a bug, and the\n * collector refuses to grow without a bound.\n * @internal\n */\nexport const MAX_SERVER_PORTALS = 256;\n\n/**\n * The markup of the portals a server render produced (see {@link createServerPortals}). Pass it to\n * the render as its `portals` option, then emit `html()` at the end of `<body>`, after the app markup.\n * The client adopts each block when it hydrates the portal that wrote it.\n *\n * @example\n * import { createComponent, createServerPortals, renderToString } from \"@shadow-js/web/server\";\n *\n * function App() {\n * return <main>Hello</main>;\n * }\n * const portals = createServerPortals();\n * const app = renderToString(() => createComponent(App, {}), { portals });\n * const page = `<!doctype html><html><body><div id=\"app\">${app}</div>${portals.html()}</body></html>`;\n * @since 1.0.0\n */\nexport interface ServerPortals {\n /**\n * The collected blocks, in the order the render produced them: each is `<!--portal:KEY-->` markup\n * `<!--/portal:KEY-->`. Emit it once, at the end of `<body>`.\n * @returns The markup; empty when no portal was rendered.\n */\n html(): string;\n}\n\n/** The collector behind a {@link ServerPortals}: what a renderer writes into while it renders. @internal */\nexport class PortalCollector implements PortalSink {\n private readonly entries = new Map<string, string>();\n\n add(key: string, html: string): void {\n if (!this.entries.has(key) && this.entries.size >= MAX_SERVER_PORTALS) {\n throw new SsrError(\n \"SSR_PORTAL_LIMIT\",\n `A render produced more than ${MAX_SERVER_PORTALS} portals; close some overlays or raise the limit.`,\n );\n }\n this.entries.set(key, html);\n }\n\n /** Forgets what an earlier pass of the same render wrote. */\n clear(): void {\n this.entries.clear();\n }\n\n html(): string {\n let out = \"\";\n for (const [key, html] of this.entries) {\n out += `<!--portal:${key}-->${html}<!--/portal:${key}-->`;\n }\n return out;\n }\n}\n\nconst collectors = new WeakMap<ServerPortals, PortalCollector>();\n\n/**\n * Creates the collector a server render writes its portals into. Without one, a `Portal` renders\n * nothing on the server. Create one per request: a render clears it before it starts, and one render\n * may produce at most 256 portals (more throw an `SsrError` whose `code` is `SSR_PORTAL_LIMIT`).\n *\n * @returns A new, empty {@link ServerPortals}.\n * @example\n * import { createComponent, createServerPortals, renderToString } from \"@shadow-js/web/server\";\n *\n * function App() {\n * return <main>Hello</main>;\n * }\n * const portals = createServerPortals();\n * const app = renderToString(() => createComponent(App, {}), { portals });\n * const page = `<body><div id=\"app\">${app}</div>${portals.html()}</body>`;\n * @since 1.0.0\n */\nexport function createServerPortals(): ServerPortals {\n const collector = new PortalCollector();\n const portals: ServerPortals = { html: () => collector.html() };\n collectors.set(portals, collector);\n return portals;\n}\n\n/**\n * The collector behind a `portals` option.\n * @throws TypeError when the value did not come from {@link createServerPortals}.\n * @internal\n */\nexport function collectorOf(portals: ServerPortals): PortalCollector {\n const collector = collectors.get(portals);\n if (collector === undefined) {\n throw new TypeError(\"portals must be created with createServerPortals().\");\n }\n return collector;\n}\n\n/**\n * The server half of a `Portal`: renders its content into the render's collector. The content gets its\n * own hydration scope, so the keys of the siblings do not depend on whether the portal rendered. Writes\n * nothing when the render has no collector or the portal has no key (no render scope).\n *\n * @param key The portal's key, from `nextKey()` at the call site.\n * @param children Reads the portal's content. A thunk, because reading a JSX child builds it, and the\n * content must be built inside its own scope.\n * @param sink The collector the portal context provides (null for a render without one).\n * @internal\n */\nexport function renderServerPortal(\n key: string | undefined,\n children: () => unknown,\n sink: PortalSink | null,\n): void {\n if (sink === null || key === undefined) return;\n const html = withScope(childScope(key), () => escape(children()));\n sink.add(key, html);\n}\n\n/**\n * Runs `build` with the portal sink provided, and returns what `build` returns (the render's accessor).\n * A null sink provides nothing, so the portals of that render write nothing.\n * @internal\n */\nexport function withPortalSink<T>(sink: PortalSink | null, build: () => T): T {\n const view = PortalContext({\n value: sink,\n get children() {\n return build();\n },\n });\n return (view as () => T)();\n}\n\n/**\n * The collector a renderer writes into for one call: null without a `portals` option, else the cleared\n * collector.\n * @internal\n */\nexport function portalCollectorFor(portals: ServerPortals | undefined): PortalCollector | null {\n if (portals === undefined) return null;\n const collector = collectorOf(portals);\n collector.clear();\n return collector;\n}\n"],"mappings":"A,qNAuCA,IAAaA,EAAb,KAAmD,CACjD,wBAA2B,IAAI,IAE/B,IAAI,EAAa,EAAoB,CACnC,GAAI,CAAC,KAAK,QAAQ,IAAIC,CAAG,GAAK,KAAK,QAAQ,MAAA,IACzC,MAAM,IAAIC,EACR,mBACA,kFACF,EAEF,KAAK,QAAQ,IAAID,EAAKE,CAAI,CAC5B,CAGA,OAAc,CACZ,KAAK,QAAQ,MAAM,CACrB,CAEA,MAAe,CACb,IAAIC,EAAM,GACV,IAAK,GAAM,CAACH,EAAKE,KAAS,KAAK,QAC7B,GAAO,cAAcF,EAAI,KAAKE,EAAK,cAAcF,EAAI,KAEvD,OAAOG,CACT,CACF,EAEA,MAAMC,kBAAa,IAAI,QAmBvB,SAAgBC,GAAqC,CACnD,IAAMC,EAAY,IAAIP,EAChBQ,EAAyB,CAAE,SAAYD,EAAU,KAAK,CAAE,EAE9D,OADAF,EAAW,IAAIG,EAASD,CAAS,EAC1BC,CACT,CAOA,SAAgBC,EAAY,EAAyC,CACnE,IAAMF,EAAYF,EAAW,IAAIG,CAAO,EACxC,GAAID,IAAc,IAAA,GAChB,MAAU,UAAU,qDAAqD,EAE3E,OAAOA,CACT,CAaA,SAAgBG,EACd,EACA,EACA,EACM,CACN,GAAIC,IAAS,MAAQV,IAAQ,IAAA,GAAW,OACxC,IAAME,EAAOS,EAAUC,EAAWZ,CAAG,MAASa,EAAOC,EAAS,CAAC,CAAC,EAChEJ,EAAK,IAAIV,EAAKE,CAAI,CACpB,CAOA,SAAgBa,EAAkB,EAAyB,EAAmB,CAO5E,OANaC,EAAc,CACzB,MAAON,EACP,IAAI,UAAW,CACb,OAAOO,EAAM,CACf,CACF,CACW,CAAC,CAAa,CAC3B,CAOA,SAAgBC,EAAmB,EAA4D,CAC7F,GAAIX,IAAY,IAAA,GAAW,OAAO,KAClC,IAAMD,EAAYE,EAAYD,CAAO,EAErC,OADAD,EAAU,MAAM,EACTA,CACT,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createRootScope as e,resourceKey as t,withScope as n}from"../internal/hydration-scope.js";import{SsrError as r}from"./errors.js";import{escape as i}from"./escape.js";import{attachRootErrors as a}from"../control-flow/root-errors.js";import{portalCollectorFor as o,withPortalSink as s}from"./portals.js";import{runWithServerHead as c}from"../head/server-head.js";import{ResourceCacheContext as l,createRoot as u}from"@shadow-js/core";const d=/^[A-Za-z0-9_-]+$/;function f(e){if(typeof e!=`string`||!d.test(e))throw TypeError(`render options: renderId must be made of letters, digits, _ and -.`);return e}function p(e){return{...e?.onCaughtError===void 0?{}:{onCaughtError:e.onCaughtError},...e?.onUncaughtError===void 0?{}:{onUncaughtError:e.onUncaughtError}}}function m(t,r,o,u,d,f){return a(f),s(d,()=>l({value:o,get children(){return c(u,()=>n(e(r),()=>i(t())))}}))()}function h(e,t){let n=f(t?.renderId??`0`),r=o(t?.portals),i=p(t);return u(a=>{try{return m(e,n,null,t?.head,r,i)}finally{a()}})}function g(e,n,r,i,a,o){let s=/* @__PURE__ */ new Set,c=[],l={caught:[],uncaught:[]},d={onCaughtError:e=>{l.caught.push(e)},...o.onUncaughtError===void 0?{}:{onUncaughtError:e=>{l.uncaught.push(e)}}},f=/* @__PURE__ */ new Set,p={key:e=>{let n=t(e);return s.add(n),n},read:e=>r.has(e)?{value:r.get(e)}:void 0,track:(e,t)=>{f.has(e)||(f.add(e),c.push({key:e,promise:t}))}};return u(t=>(i?.clear(),a?.clear(),{html:m(e,n,p,i,a,d),requested:s,tracked:c,errors:l,dispose:t}))}function _(e,t){for(let n of e.caught)t.onCaughtError?.(n);for(let n of e.uncaught)t.onUncaughtError?.(n)}function v(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function y(e,t){let n={};for(let r of e)t.has(r)&&v(n,r,t.get(r));return n}function b(e){if(e.canceled)throw new r(`SSR_TIMEOUT`,`The render was canceled after its time budget.`)}async function x(e,t,n,i,a,o,s){let c=/* @__PURE__ */ new Map;for(let l=1;;l+=1){b(i);let u=g(e,t,c,a,o,s);if(i.roots.push(u.dispose),u.tracked.length===0)return u.dispose(),_(u.errors,s),{html:u.html,data:y(u.requested,c)};let d=await Promise.allSettled(u.tracked.map(e=>e.promise));b(i);let f=!1;if(d.forEach((e,t)=>{let n=u.tracked[t];n!==void 0&&e.status===`fulfilled`&&(c.has(n.key)||(f=!0),c.set(n.key,e.value))}),u.dispose(),!f)return _(u.errors,s),{html:u.html,data:y(u.requested,c)};if(l>=n)throw new r(`SSR_BOUNDARY_WATERFALL`,`Resources kept loading new resources after ${n} passes; raise maxPasses or flatten the data flow.`)}}function S(e){let t=e?.timeoutMs??1e4,n=e?.maxPasses??10;if(typeof t!=`number`||!(t>0)||!Number.isFinite(t))throw TypeError(`render options: timeoutMs must be a positive finite number.`);if(!Number.isInteger(n)||n<1)throw TypeError(`render options: maxPasses must be an integer of at least 1.`);return{timeoutMs:t,maxPasses:n}}async function C(e,t){let n=f(t?.renderId??`0`),{timeoutMs:i,maxPasses:a}=S(t),s={canceled:!1,roots:[]},c,l=new Promise((e,t)=>{c=setTimeout(()=>{s.canceled=!0,t(new r(`SSR_TIMEOUT`,`The render did not finish within ${i} ms.`))},i)});try{let r=o(t?.portals);return await Promise.race([x(e,n,a,s,t?.head,r,p(t)),l])}finally{clearTimeout(c),s.canceled=!0;for(let e of s.roots.splice(0))e()}}export{h as renderToString,C as renderToStringAsync};
|
|
2
|
+
//# sourceMappingURL=render.js.map
|