@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,173 @@
|
|
|
1
|
+
import { cssValueText } from "../internal/css-units.js";
|
|
2
|
+
import { invalid } from "./errors.js";
|
|
3
|
+
import { isSsrNode } from "./node.js";
|
|
4
|
+
import { escapeHtml, resolveValue } from "./escape.js";
|
|
5
|
+
//#region src/server/class-style.ts
|
|
6
|
+
/** A CSS property name: a custom property, or a lower-case name with an optional vendor dash. */
|
|
7
|
+
const CSS_PROPERTY = /^(--[A-Za-z0-9_-]+|-?[a-z][a-z0-9-]*)$/;
|
|
8
|
+
/**
|
|
9
|
+
* Appends the class names found in `root` to `parts`, clsx-style. Iterative: array nesting depth
|
|
10
|
+
* is controlled by the caller, so it must not reach the call stack.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
function collectClasses(root, parts) {
|
|
14
|
+
const frames = [[root]];
|
|
15
|
+
const cursors = [0];
|
|
16
|
+
const open = /* @__PURE__ */ new Set();
|
|
17
|
+
while (frames.length > 0) {
|
|
18
|
+
const top = frames.length - 1;
|
|
19
|
+
const frame = frames[top];
|
|
20
|
+
const cursor = cursors[top] ?? 0;
|
|
21
|
+
if (frame === void 0 || cursor >= frame.length) {
|
|
22
|
+
const done = frames.pop();
|
|
23
|
+
if (done !== void 0) open.delete(done);
|
|
24
|
+
cursors.pop();
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
cursors[top] = cursor + 1;
|
|
28
|
+
const item = resolveValue(frame[cursor]);
|
|
29
|
+
if (Array.isArray(item)) {
|
|
30
|
+
if (open.has(item)) throw new TypeError("A class array contains itself.");
|
|
31
|
+
open.add(item);
|
|
32
|
+
frames.push(item);
|
|
33
|
+
cursors.push(0);
|
|
34
|
+
} else if (typeof item === "string") {
|
|
35
|
+
if (item !== "") parts.push(item);
|
|
36
|
+
} else if (typeof item === "number") {
|
|
37
|
+
if (item !== 0 && !Number.isNaN(item)) parts.push(String(item));
|
|
38
|
+
} else if (typeof item === "symbol") throw invalid("UNRECOGNIZED_INSERT_VALUE", "A symbol cannot be a class name.");
|
|
39
|
+
else if (item !== null && typeof item === "object") {
|
|
40
|
+
const record = item;
|
|
41
|
+
for (const key of Object.keys(record)) if (key !== "" && resolveValue(record[key])) parts.push(key);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The class text for a class value, or "" when there is none. A string is used as it is.
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
function classText(value) {
|
|
50
|
+
const resolved = resolveValue(value);
|
|
51
|
+
if (typeof resolved === "string") return resolved;
|
|
52
|
+
if (resolved === null || resolved === void 0 || resolved === false) return "";
|
|
53
|
+
const parts = [];
|
|
54
|
+
collectClasses(resolved, parts);
|
|
55
|
+
return parts.join(" ");
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Renders a `class` attribute from a class value: the helper the compiler's server output calls for
|
|
59
|
+
* `class`, `className` and `classList`, with the same clsx rules as the client's `className`.
|
|
60
|
+
*
|
|
61
|
+
* @param value A string (used as is), or an array or object: non-empty strings, numbers other than
|
|
62
|
+
* `0` and `NaN`, nested arrays, and the keys of objects whose value is truthy. Accessors, also
|
|
63
|
+
* inside arrays and as object values, are called. `null`, `undefined` and `false` give no class.
|
|
64
|
+
* @returns Markup such as `' class="a b"'` (HTML-escaped), or `""` when there are no classes.
|
|
65
|
+
* @throws TypeError when an array contains itself, and `UNRECOGNIZED_INSERT_VALUE` for a symbol.
|
|
66
|
+
* @example
|
|
67
|
+
* import { ssrClass } from "@shadow-js/web/server";
|
|
68
|
+
*
|
|
69
|
+
* ssrClass(["card", { "card--active": true, hidden: false }]); // ' class="card card--active"'
|
|
70
|
+
* ssrClass(null); // ""
|
|
71
|
+
* @see ssrStyle
|
|
72
|
+
* @since 1.0.0
|
|
73
|
+
*/
|
|
74
|
+
function ssrClass(value) {
|
|
75
|
+
const text = classText(value);
|
|
76
|
+
return text === "" ? "" : ` class="${escapeHtml(text)}"`;
|
|
77
|
+
}
|
|
78
|
+
/** Converts a camelCase style name to CSS, keeping custom properties; `ms` gets its dash. @internal */
|
|
79
|
+
function toCssProperty(name) {
|
|
80
|
+
if (name.startsWith("--")) return name;
|
|
81
|
+
const kebab = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
82
|
+
return kebab.startsWith("ms-") ? `-${kebab}` : kebab;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* True when a value cannot end its own declaration. A `;`, `{` or `}` outside quotes and
|
|
86
|
+
* parentheses would start another declaration or rule, so such a value is dropped. Unbalanced
|
|
87
|
+
* quotes or parentheses are dropped too, because they would swallow the declarations after them.
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
function isSafeCssValue(text) {
|
|
91
|
+
let quote = "";
|
|
92
|
+
let depth = 0;
|
|
93
|
+
let escaped = false;
|
|
94
|
+
for (const char of text) if (escaped) escaped = false;
|
|
95
|
+
else if (char === "\\") escaped = true;
|
|
96
|
+
else if (quote !== "") {
|
|
97
|
+
if (char === quote) quote = "";
|
|
98
|
+
} else if (char === "\"" || char === "'") quote = char;
|
|
99
|
+
else if (char === "(") depth += 1;
|
|
100
|
+
else if (char === ")") depth = Math.max(0, depth - 1);
|
|
101
|
+
else if ((char === ";" || char === "{" || char === "}") && depth === 0) return false;
|
|
102
|
+
return quote === "" && depth === 0 && !escaped;
|
|
103
|
+
}
|
|
104
|
+
/** Declarations for one style source, appended to `out` as raw (unescaped) CSS text. */
|
|
105
|
+
function collectDeclarations(source, out) {
|
|
106
|
+
const value = resolveValue(source);
|
|
107
|
+
if (value === null || value === void 0 || value === false) return;
|
|
108
|
+
if (typeof value === "string") {
|
|
109
|
+
if (value !== "") out.push(value);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (typeof value !== "object" || isSsrNode(value)) throw invalid("UNRECOGNIZED_INSERT_VALUE", "A style must be a string, an object or an array of them.");
|
|
113
|
+
if (Array.isArray(value)) {
|
|
114
|
+
for (const item of value) {
|
|
115
|
+
const resolved = resolveValue(item);
|
|
116
|
+
if (Array.isArray(resolved)) throw new TypeError("ssrStyle(): a style array may not contain another array.");
|
|
117
|
+
collectDeclarations(resolved, out);
|
|
118
|
+
}
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
for (const key of Object.keys(value)) {
|
|
122
|
+
const property = toCssProperty(key);
|
|
123
|
+
if (!CSS_PROPERTY.test(property)) throw invalid("INVALID_STYLE_PROPERTY", `"${key}" is not a valid CSS property name.`);
|
|
124
|
+
const resolved = resolveValue(Reflect.get(value, key));
|
|
125
|
+
if (resolved === null || resolved === void 0 || resolved === false) continue;
|
|
126
|
+
if (typeof resolved === "symbol") throw invalid("UNRECOGNIZED_INSERT_VALUE", "A symbol cannot be a style value.");
|
|
127
|
+
const text = cssValueText(property, resolved);
|
|
128
|
+
if (!isSafeCssValue(text)) continue;
|
|
129
|
+
out.push(`${property}:${text}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The declarations of a style value, joined with `;`, or "" when there are none. Later
|
|
134
|
+
* declarations win in CSS, so earlier and later sources can be combined in order.
|
|
135
|
+
* @internal
|
|
136
|
+
*/
|
|
137
|
+
function styleText(value) {
|
|
138
|
+
const declarations = [];
|
|
139
|
+
collectDeclarations(value, declarations);
|
|
140
|
+
return declarations.join(";");
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Renders a `style` attribute from a style value: the helper the compiler's server output calls for
|
|
144
|
+
* `style` and `style:` attributes. Sources in an array are written in order, so a later declaration
|
|
145
|
+
* wins in CSS.
|
|
146
|
+
*
|
|
147
|
+
* @param value A string (written as is), an object of properties, or an array of strings and
|
|
148
|
+
* objects (not nested). Object keys are camelCase (converted to kebab-case, `msTransform` gives
|
|
149
|
+
* `-ms-transform`), kebab-case, or custom properties (`--gap`, kept). `null`, `undefined` and `false`
|
|
150
|
+
* values are skipped; a number is in pixels unless it is `0`, the property is unitless (`opacity`,
|
|
151
|
+
* `zIndex`, ...) or a custom property, as in React. A value that could end its own declaration (a
|
|
152
|
+
* `;`, `{` or `}` outside quotes and parentheses, or an unbalanced quote or parenthesis) is dropped.
|
|
153
|
+
* @returns Markup such as `' style="color:red"'` (HTML-escaped), or `""` when there is nothing to
|
|
154
|
+
* write.
|
|
155
|
+
* @throws TypeError `INVALID_STYLE_PROPERTY` for an invalid property name, `UNRECOGNIZED_INSERT_VALUE`
|
|
156
|
+
* for a symbol or a value that is not a string, object or array, and a TypeError for a nested array.
|
|
157
|
+
* @example
|
|
158
|
+
* import { ssrStyle } from "@shadow-js/web/server";
|
|
159
|
+
*
|
|
160
|
+
* ssrStyle({ backgroundColor: "red", width: 10, "--gap": "4px" });
|
|
161
|
+
* // ' style="background-color:red;width:10px;--gap:4px"'
|
|
162
|
+
* ssrStyle([{ color: "red" }, "color: blue"]); // the later declaration wins
|
|
163
|
+
* @see ssrClass
|
|
164
|
+
* @since 1.0.0
|
|
165
|
+
*/
|
|
166
|
+
function ssrStyle(value) {
|
|
167
|
+
const text = styleText(value);
|
|
168
|
+
return text === "" ? "" : ` style="${escapeHtml(text)}"`;
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
export { classText, collectClasses, isSafeCssValue, ssrClass, ssrStyle, styleText, toCssProperty };
|
|
172
|
+
|
|
173
|
+
//# sourceMappingURL=class-style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-style.js","names":[],"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":";;;;;;AAMA,MAAM,eAAe;;;;;;AAOrB,SAAgB,eAAe,MAAe,OAAuB;CACnE,MAAM,SAAsB,CAAC,CAAC,IAAI,CAAC;CACnC,MAAM,UAAoB,CAAC,CAAC;CAC5B,MAAM,uBAAO,IAAI,IAAe;CAChC,OAAO,OAAO,SAAS,GAAG;EACxB,MAAM,MAAM,OAAO,SAAS;EAC5B,MAAM,QAAQ,OAAO;EACrB,MAAM,SAAS,QAAQ,QAAQ;EAC/B,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM,QAAQ;GACjD,MAAM,OAAO,OAAO,IAAI;GACxB,IAAI,SAAS,KAAA,GAAW,KAAK,OAAO,IAAI;GACxC,QAAQ,IAAI;GACZ;EACF;EACA,QAAQ,OAAO,SAAS;EACxB,MAAM,OAAO,aAAa,MAAM,OAAO;EACvC,IAAI,MAAM,QAAQ,IAAI,GAAG;GACvB,IAAI,KAAK,IAAI,IAAI,GAAG,MAAM,IAAI,UAAU,gCAAgC;GACxE,KAAK,IAAI,IAAI;GACb,OAAO,KAAK,IAAI;GAChB,QAAQ,KAAK,CAAC;EAChB,OAAO,IAAI,OAAO,SAAS,UACrB;OAAA,SAAS,IAAI,MAAM,KAAK,IAAI;EAAA,OAC3B,IAAI,OAAO,SAAS,UACrB;OAAA,SAAS,KAAK,CAAC,OAAO,MAAM,IAAI,GAAG,MAAM,KAAK,OAAO,IAAI,CAAC;EAAA,OACzD,IAAI,OAAO,SAAS,UACzB,MAAM,QAAQ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I,EAAE;AACxD"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { currentScope, enterComponent } from "../internal/hydration-scope.js";
|
|
2
|
+
import { untrack } from "@shadow-js/core";
|
|
3
|
+
import { createOwner, runInScope } from "@shadow-js/core/extend";
|
|
4
|
+
//#region src/server/component.ts
|
|
5
|
+
/**
|
|
6
|
+
* Calls a component on the server, untracked, with its own owner and hydration scope, so the
|
|
7
|
+
* hydration keys it hands out depend only on where it sits in the tree. The server twin of the client
|
|
8
|
+
* `createComponent`: compiled server output calls it for `<Component />`, and a hand-written render
|
|
9
|
+
* entry calls it for the root component.
|
|
10
|
+
*
|
|
11
|
+
* @param component The component function.
|
|
12
|
+
* @param props The props object; reactive props are getters.
|
|
13
|
+
* @returns Whatever the component returns.
|
|
14
|
+
* @throws TypeError when `component` is not a function. An error the component throws propagates.
|
|
15
|
+
* @example
|
|
16
|
+
* import { createComponent, renderToString } from "@shadow-js/web/server";
|
|
17
|
+
*
|
|
18
|
+
* function Card(props: { title: string }) {
|
|
19
|
+
* return <h2>{props.title}</h2>;
|
|
20
|
+
* }
|
|
21
|
+
* const html = renderToString(() => createComponent(Card, { title: "Hello" }));
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
*/
|
|
24
|
+
function createComponent(component, props) {
|
|
25
|
+
if (typeof component !== "function") throw new TypeError("createComponent(): the component must be a function.");
|
|
26
|
+
return enterComponent(() => {
|
|
27
|
+
const owner = createOwner();
|
|
28
|
+
owner.idPrefix = currentScope()?.id;
|
|
29
|
+
return runInScope({
|
|
30
|
+
owner,
|
|
31
|
+
listener: null
|
|
32
|
+
}, () => component(props));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The server twin of `memo`: nothing is reactive during a server render, so it computes once, on the
|
|
37
|
+
* first read, and returns the cached value on every later read. A call that throws is not cached
|
|
38
|
+
* (the next read runs `fn` again).
|
|
39
|
+
*
|
|
40
|
+
* @param fn The computation; runs untracked, on the first read.
|
|
41
|
+
* @returns An accessor of the cached value.
|
|
42
|
+
* @throws TypeError from the accessor when `fn` reads the accessor itself while it runs, instead of
|
|
43
|
+
* recursing. An error `fn` throws propagates from the read.
|
|
44
|
+
* @example
|
|
45
|
+
* import { memo } from "@shadow-js/web/server";
|
|
46
|
+
*
|
|
47
|
+
* const items = [3, 1, 2];
|
|
48
|
+
* const sorted = memo(() => [...items].sort());
|
|
49
|
+
* sorted(); // [1, 2, 3], computed now
|
|
50
|
+
* sorted(); // the same array, cached
|
|
51
|
+
* @since 1.0.0
|
|
52
|
+
*/
|
|
53
|
+
function memo(fn) {
|
|
54
|
+
let slot;
|
|
55
|
+
let running = false;
|
|
56
|
+
return () => {
|
|
57
|
+
if (slot !== void 0) return slot.value;
|
|
58
|
+
if (running) throw new TypeError("memo(): the computation read itself.");
|
|
59
|
+
running = true;
|
|
60
|
+
try {
|
|
61
|
+
const value = untrack(fn);
|
|
62
|
+
slot = { value };
|
|
63
|
+
return value;
|
|
64
|
+
} finally {
|
|
65
|
+
running = false;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { createComponent, memo };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","names":[],"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":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,gBAAmB,WAAkC,OAAmB;CACtF,IAAI,OAAO,cAAc,YACvB,MAAM,IAAI,UAAU,sDAAsD;CAE5E,OAAO,qBAAqB;EAE1B,MAAM,QAAQ,YAAY;EAC1B,MAAM,WAAW,aAAa,CAAC,EAAE;EAEjC,OAAO,WAAW;GAAE;GAAO,UAAU;EAAK,SAAS,UAAU,KAAK,CAAC;CACrE,CAAC;AACH;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,KAAQ,IAAsB;CAC5C,IAAI;CACJ,IAAI,UAAU;CACd,aAAa;EACX,IAAI,SAAS,KAAA,GAAW,OAAO,KAAK;EACpC,IAAI,SAAS,MAAM,IAAI,UAAU,sCAAsC;EACvE,UAAU;EACV,IAAI;GACF,MAAM,QAAQ,QAAQ,EAAE;GACxB,OAAO,EAAE,MAAM;GACf,OAAO;EACT,UAAU;GACR,UAAU;EACZ;CACF;AACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/server/derived.ts
|
|
2
|
+
/**
|
|
3
|
+
* The server twin of the client `derived`, which the compiler emits for `const x = <expression
|
|
4
|
+
* reading signals>` inside a component. On the server it calls `compute` once, immediately, and
|
|
5
|
+
* returns a constant {@link Derived}.
|
|
6
|
+
*
|
|
7
|
+
* @param compute The computation. Runs once, when `derived` is called; an error it throws propagates.
|
|
8
|
+
* @returns A {@link Derived} holding the result.
|
|
9
|
+
* @example
|
|
10
|
+
* import { derived } from "@shadow-js/web/server";
|
|
11
|
+
*
|
|
12
|
+
* const greeting = derived(() => (name: string) => `Hello, ${name}`);
|
|
13
|
+
* greeting("Ada"); // "Hello, Ada": a derived function stays callable
|
|
14
|
+
* @see Derived
|
|
15
|
+
* @since 1.0.0
|
|
16
|
+
*/
|
|
17
|
+
function derived(compute) {
|
|
18
|
+
const current = compute();
|
|
19
|
+
const read = ((...args) => typeof current === "function" ? current(...args) : current);
|
|
20
|
+
Object.defineProperty(read, "value", { value: current });
|
|
21
|
+
return read;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { derived };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=derived.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derived.js","names":[],"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,SAAgB,QAAW,SAA8B;CACvD,MAAM,UAAU,QAAQ;CACxB,MAAM,SAAS,GAAG,SAChB,OAAO,YAAY,aACd,QAAyC,GAAG,IAAI,IACjD;CAIN,OAAO,eAAe,MAAM,SAAS,EAAE,OAAO,QAAQ,CAAC;CACvD,OAAO;AACT"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { nextKey } from "../internal/hydration-scope.js";
|
|
2
|
+
import { IGNORED_KEYS, attributeName } from "../internal/react-names.js";
|
|
3
|
+
import { invalid } from "./errors.js";
|
|
4
|
+
import { SsrNode, isSsrNode } from "./node.js";
|
|
5
|
+
import { escape, escapeHtml, resolveValue } from "./escape.js";
|
|
6
|
+
import { BOOLEAN_ATTRIBUTES, isEventName, ssrAttribute } from "./attributes.js";
|
|
7
|
+
import { classText, ssrStyle, styleText } from "./class-style.js";
|
|
8
|
+
import { markSelectedOptions, textareaContent } from "./form-controls.js";
|
|
9
|
+
//#region src/server/element.ts
|
|
10
|
+
/** A tag name: letters, digits and dashes, starting with a letter. Anything else could break out. */
|
|
11
|
+
const TAG_NAME = /^[A-Za-z][A-Za-z0-9-]*$/;
|
|
12
|
+
/** Elements that never have children or a closing tag. */
|
|
13
|
+
const VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
14
|
+
"area",
|
|
15
|
+
"base",
|
|
16
|
+
"br",
|
|
17
|
+
"col",
|
|
18
|
+
"command",
|
|
19
|
+
"embed",
|
|
20
|
+
"hr",
|
|
21
|
+
"img",
|
|
22
|
+
"input",
|
|
23
|
+
"keygen",
|
|
24
|
+
"link",
|
|
25
|
+
"meta",
|
|
26
|
+
"param",
|
|
27
|
+
"source",
|
|
28
|
+
"track",
|
|
29
|
+
"wbr"
|
|
30
|
+
]);
|
|
31
|
+
/** Keys that never become attributes: they are handled elsewhere or would reach a prototype. */
|
|
32
|
+
const SKIPPED_KEYS = /* @__PURE__ */ new Set([
|
|
33
|
+
"__proto__",
|
|
34
|
+
"constructor",
|
|
35
|
+
"prototype",
|
|
36
|
+
"children",
|
|
37
|
+
"ref"
|
|
38
|
+
]);
|
|
39
|
+
/** The HTML of a `dangerouslySetInnerHTML` value (`{ __html }`): null and undefined are empty. */
|
|
40
|
+
function innerHtmlOfValue(value) {
|
|
41
|
+
if (value === null || typeof value !== "object") return void 0;
|
|
42
|
+
return Reflect.get(value, "__html");
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Joins the static parts of a server template with its dynamic holes into trusted markup: the
|
|
46
|
+
* function compiled server output calls for each element tree. Holes are inserted unchanged, so each
|
|
47
|
+
* must already be escaped (the output of `escape`, `ssrAttribute`, `ssrClass`, ...) or an `SsrNode`;
|
|
48
|
+
* any other value throws, so a raw user value cannot reach the markup.
|
|
49
|
+
*
|
|
50
|
+
* @param parts The static markup, one more entry than there are holes.
|
|
51
|
+
* @param holes The dynamic parts: strings produced by the escaping helpers, or `SsrNode` values.
|
|
52
|
+
* @returns The markup as a trusted `SsrNode`, which `escape` writes without encoding.
|
|
53
|
+
* @throws TypeError when `parts` is not an array of `holes.length + 1` entries, or when a hole is not
|
|
54
|
+
* a string or an `SsrNode`.
|
|
55
|
+
* @example
|
|
56
|
+
* import { escape, renderToString, ssr } from "@shadow-js/web/server";
|
|
57
|
+
*
|
|
58
|
+
* const name = "<Ada>";
|
|
59
|
+
* const html = renderToString(() => ssr(["<p>Hello, ", "</p>"], escape(name)));
|
|
60
|
+
* // "<p>Hello, <Ada></p>"
|
|
61
|
+
* @see ssrRaw
|
|
62
|
+
* @since 1.0.0
|
|
63
|
+
*/
|
|
64
|
+
function ssr(parts, ...holes) {
|
|
65
|
+
if (!Array.isArray(parts) || parts.length !== holes.length + 1) throw new TypeError("ssr(): parts must have one more entry than there are holes.");
|
|
66
|
+
let html = parts[0] ?? "";
|
|
67
|
+
for (let index = 0; index < holes.length; index += 1) {
|
|
68
|
+
const hole = holes[index];
|
|
69
|
+
if (typeof hole === "string") html += hole;
|
|
70
|
+
else if (isSsrNode(hole)) html += hole.t;
|
|
71
|
+
else throw new TypeError("ssr(): a hole must be an escaped string or an SsrNode.");
|
|
72
|
+
html += parts[index + 1] ?? "";
|
|
73
|
+
}
|
|
74
|
+
return new SsrNode(html);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Marks a string as trusted markup that `escape` and `ssr` insert unchanged. Only use it for markup
|
|
78
|
+
* the application wrote itself, never for user input.
|
|
79
|
+
*
|
|
80
|
+
* @param html The markup, inserted unchanged.
|
|
81
|
+
* @returns The markup as a trusted `SsrNode`.
|
|
82
|
+
* @throws TypeError when `html` is not a string.
|
|
83
|
+
* @example
|
|
84
|
+
* import { renderToString, ssrRaw } from "@shadow-js/web/server";
|
|
85
|
+
*
|
|
86
|
+
* const html = renderToString(() => ["<b>escaped</b>", ssrRaw("<!-- build 42 -->")]);
|
|
87
|
+
* // "<b>escaped</b><!-- build 42 -->"
|
|
88
|
+
* @see ssr
|
|
89
|
+
* @since 1.0.0
|
|
90
|
+
*/
|
|
91
|
+
function ssrRaw(html) {
|
|
92
|
+
if (typeof html !== "string") throw new TypeError("ssrRaw(): the markup must be a string.");
|
|
93
|
+
return new SsrNode(html);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Draws the next hydration key of the current scope and returns it as a `data-hk` attribute, such as
|
|
97
|
+
* `' data-hk="0-0"'`: compiled server output calls it for the root element of each template, and
|
|
98
|
+
* the client's `hydrate()` claims the element by that key. Calls must happen in the same order as on
|
|
99
|
+
* the client, so call it only where the compiler would.
|
|
100
|
+
*
|
|
101
|
+
* @returns Markup for the `data-hk` attribute, or `""` outside a server render (no key is drawn).
|
|
102
|
+
* @example
|
|
103
|
+
* import { renderToString, ssr, ssrHydrationKey } from "@shadow-js/web/server";
|
|
104
|
+
*
|
|
105
|
+
* const html = renderToString(() => ssr(["<div", ">x</div>"], ssrHydrationKey()));
|
|
106
|
+
* // '<div data-hk="0-0">x</div>'
|
|
107
|
+
* @since 1.0.0
|
|
108
|
+
*/
|
|
109
|
+
function ssrHydrationKey() {
|
|
110
|
+
const key = nextKey();
|
|
111
|
+
return key === void 0 ? "" : ` data-hk="${escapeHtml(key)}"`;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Renders an element from a props object: what compiled server output calls for an element with a
|
|
115
|
+
* spread (`<div {...props} />`), and the server half of `Dynamic` and `element`. It writes the same
|
|
116
|
+
* markup the client's `spread` produces.
|
|
117
|
+
*
|
|
118
|
+
* `class`, `className`, `classList` and `style` are combined into one `class` and one `style`
|
|
119
|
+
* attribute; other keys are attributes, with React names mapped (`htmlFor` is `for`) and HTML boolean
|
|
120
|
+
* attributes (`disabled`, `checked`, ...) written as bare names. `ref`, `children`, `on*` keys and the
|
|
121
|
+
* `on:`, `use:` and `prop:` prefixes are skipped; `attr:` and `bool:` select the attribute and presence
|
|
122
|
+
* forms. `innerHTML` and `dangerouslySetInnerHTML` are written unescaped as the content. On a
|
|
123
|
+
* `textarea` the `value` (or `defaultValue`) is the content; on a `select` it marks the matching
|
|
124
|
+
* `<option selected>` (an array for `multiple`); on other elements `defaultValue` and `defaultChecked`
|
|
125
|
+
* are the `value` and `checked` attributes. Void elements (`img`, `input`, ...) get no content.
|
|
126
|
+
*
|
|
127
|
+
* @param tag Element name: letters, digits and dashes, starting with a letter.
|
|
128
|
+
* @param props The props object (each getter is read once), or `null`.
|
|
129
|
+
* @param children The content, escaped unless it is an `SsrNode`. Undefined (the default) uses the
|
|
130
|
+
* `children` prop.
|
|
131
|
+
* @param needsKey `true` writes the hydration key of this template root first. Default: `false`.
|
|
132
|
+
* @param svg `true` for an SVG element: SVG presentation names are hyphenated (`strokeWidth` is
|
|
133
|
+
* `stroke-width`), other names keep their case. Default: `false`.
|
|
134
|
+
* @returns The element as a trusted `SsrNode`.
|
|
135
|
+
* @throws TypeError `INVALID_TAG_NAME` for an invalid tag, `INVALID_ATTRIBUTE_NAME` for an invalid
|
|
136
|
+
* attribute name, and the errors of {@link ssrAttribute}, `ssrClass` and `ssrStyle` for invalid values.
|
|
137
|
+
* @example
|
|
138
|
+
* import { renderToString, ssrElement } from "@shadow-js/web/server";
|
|
139
|
+
*
|
|
140
|
+
* const props = { id: "save", disabled: true, class: ["btn", { primary: true }], children: "Save" };
|
|
141
|
+
* const html = renderToString(() => ssrElement("button", props));
|
|
142
|
+
* // '<button id="save" disabled class="btn primary">Save</button>'
|
|
143
|
+
* @since 1.0.0
|
|
144
|
+
*/
|
|
145
|
+
function ssrElement(tag, props, children = void 0, needsKey = false, svg = false) {
|
|
146
|
+
if (typeof tag !== "string" || !TAG_NAME.test(tag)) throw invalid("INVALID_TAG_NAME", `"${String(tag)}" is not a valid tag name.`);
|
|
147
|
+
const lowerTag = tag.toLowerCase();
|
|
148
|
+
const isSelect = lowerTag === "select";
|
|
149
|
+
const isTextarea = lowerTag === "textarea";
|
|
150
|
+
const control = {};
|
|
151
|
+
let hasValue = false;
|
|
152
|
+
let hasFallback = false;
|
|
153
|
+
let attributes = needsKey ? ssrHydrationKey() : "";
|
|
154
|
+
const classes = [];
|
|
155
|
+
let style = "";
|
|
156
|
+
let innerHtml;
|
|
157
|
+
if (props !== null && typeof props === "object") for (const key of Object.keys(props)) {
|
|
158
|
+
if (SKIPPED_KEYS.has(key) || IGNORED_KEYS.has(key)) continue;
|
|
159
|
+
if (key === "ref" || key.startsWith("on:") || key.startsWith("use:") || key.startsWith("prop:")) continue;
|
|
160
|
+
if (isEventName(key)) continue;
|
|
161
|
+
if (needsKey && key === "data-hk") continue;
|
|
162
|
+
const value = resolveValue(Reflect.get(props, key));
|
|
163
|
+
if (key === "class" || key === "className") {
|
|
164
|
+
const text = classText(value);
|
|
165
|
+
if (text !== "") classes.push(text);
|
|
166
|
+
} else if (key === "classList") collectTruthyKeys(value, classes);
|
|
167
|
+
else if (key === "style") style = styleText(value);
|
|
168
|
+
else if (key === "innerHTML") innerHtml = plainHtml(value);
|
|
169
|
+
else if (key === "dangerouslySetInnerHTML") innerHtml = plainHtml(resolveValue(innerHtmlOfValue(value)));
|
|
170
|
+
else if ((isSelect || isTextarea) && key === "value") {
|
|
171
|
+
control.value = value;
|
|
172
|
+
hasValue = true;
|
|
173
|
+
} else if ((isSelect || isTextarea) && key === "defaultValue") {
|
|
174
|
+
control.fallback = value;
|
|
175
|
+
hasFallback = true;
|
|
176
|
+
} else if (key.startsWith("attr:")) attributes += ssrAttribute(key.slice(5), value);
|
|
177
|
+
else if (key.startsWith("bool:")) attributes += ssrAttribute(key.slice(5), value, true);
|
|
178
|
+
else if (key === "defaultValue" || key === "defaultChecked") {
|
|
179
|
+
const name = key === "defaultValue" ? "value" : "checked";
|
|
180
|
+
if (!Object.hasOwn(props, name)) attributes += ssrAttribute(name, value, name === "checked");
|
|
181
|
+
} else {
|
|
182
|
+
const name = attributeName(key, svg);
|
|
183
|
+
attributes += ssrAttribute(name, value, BOOLEAN_ATTRIBUTES.has(name));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (classes.length > 0) attributes += ` class="${escapeHtml(classes.join(" "))}"`;
|
|
187
|
+
if (style !== "") attributes += ssrStyle(style);
|
|
188
|
+
if (VOID_ELEMENTS.has(lowerTag)) return new SsrNode(`<${tag}${attributes}>`);
|
|
189
|
+
let content = innerHtml !== void 0 ? innerHtml : escape(children === void 0 ? propsChildren(props) : children);
|
|
190
|
+
if (innerHtml === void 0 && (hasValue || hasFallback)) {
|
|
191
|
+
const value = hasValue ? control.value : control.fallback;
|
|
192
|
+
content = isTextarea ? textareaContent(value) : markSelectedOptions(value, content);
|
|
193
|
+
}
|
|
194
|
+
return new SsrNode(`<${tag}${attributes}>${content}</${tag}>`);
|
|
195
|
+
}
|
|
196
|
+
/** The `children` of a spread props object (read once, so a getter runs once), or undefined. */
|
|
197
|
+
function propsChildren(props) {
|
|
198
|
+
if (props === null || typeof props !== "object") return void 0;
|
|
199
|
+
return Reflect.get(props, "children");
|
|
200
|
+
}
|
|
201
|
+
/** Class names whose key is truthy, from a `classList` object. */
|
|
202
|
+
function collectTruthyKeys(value, out) {
|
|
203
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return;
|
|
204
|
+
for (const key of Object.keys(value)) if (key !== "" && resolveValue(Reflect.get(value, key))) out.push(key);
|
|
205
|
+
}
|
|
206
|
+
/** Raw HTML text for `innerHTML`: null and undefined become "", an SsrNode its markup. */
|
|
207
|
+
function plainHtml(value) {
|
|
208
|
+
if (value === null || value === void 0) return "";
|
|
209
|
+
if (isSsrNode(value)) return value.t;
|
|
210
|
+
if (typeof value === "symbol") throw invalid("UNRECOGNIZED_INSERT_VALUE", "A symbol cannot be innerHTML.");
|
|
211
|
+
return String(value);
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
export { ssr, ssrElement, ssrHydrationKey, ssrRaw };
|
|
215
|
+
|
|
216
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.js","names":[],"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":";;;;;;;;;;AAWA,MAA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AC,GAAG,IAAI,KAAK,GAAG;AAEzE;;AAGA,SAAS,UAAU,OAAwB;CACzC,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;CAClD,IAAI,UAAU,KAAK,GAAG,OAAO,MAAM;CACnC,IAAI,OAAO,UAAU,UACnB,MAAM,QAAQ,6BAA6B,+BAA+B;CAC5E,OAAO,OAAO,KAAK;AACrB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/server/errors.ts
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown by the server renderer, carrying a stable code. Dev builds carry the full text;
|
|
4
|
+
* production builds keep only the code (the same split as core's diagnostics).
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
var SsrError = class extends Error {
|
|
8
|
+
code;
|
|
9
|
+
constructor(code, detail) {
|
|
10
|
+
super(`[shadow ${code}] ${detail}`);
|
|
11
|
+
this.name = "SsrError";
|
|
12
|
+
this.code = code;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A TypeError for input the renderer refuses: a value that could become unsafe markup, or a
|
|
17
|
+
* malformed argument. Dev builds carry the detail; production builds keep the code.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
function invalid(code, detail) {
|
|
21
|
+
return /* @__PURE__ */ new TypeError(`[shadow ${code}] ${detail}`);
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { SsrError, invalid };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"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,IAAa,WAAb,cAA8B,MAAM;CAClC;CACA,YAAY,MAAoB,QAAgB;EAC9C,MAAgB,WAAW,KAAK,IAAI,QAA2B;EAC/D,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;;;;;AAOA,SAAgB,QAAQ,MAAc,QAA2B;CAC/D,uBAAO,IAAI,UAAoB,WAAW,KAAK,IAAI,QAA2B;AAChF"}
|