@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,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":"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"}
|
|
@@ -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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/server/escape.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Converts any value a JSX child may hold to escaped HTML: the helper compiled server output calls
|
|
4
|
+
* for every dynamic child, and what the renderers call on the app's result.
|
|
5
|
+
*
|
|
6
|
+
* - Strings are escaped (`& < > " '`); numbers and bigints are written as they are; `null`,
|
|
7
|
+
* `undefined` and booleans render nothing.
|
|
8
|
+
* - `SsrNode` values (from `ssr`, `ssrRaw` and the other helpers) pass through unchanged: they were
|
|
9
|
+
* escaped when they were built.
|
|
10
|
+
* - Accessors are called (untracked) and their result is rendered; a chain of more than 1000
|
|
11
|
+
* accessors returning accessors throws.
|
|
12
|
+
* - Arrays are flattened in order, with an explicit stack, so nesting depth is not limited by the
|
|
13
|
+
* call stack.
|
|
14
|
+
* - Plain objects throw in development builds and render nothing in production builds.
|
|
15
|
+
*
|
|
16
|
+
* @param value The value to render.
|
|
17
|
+
* @returns The escaped markup.
|
|
18
|
+
* @throws TypeError when an array contains itself, for a symbol (`UNRECOGNIZED_INSERT_VALUE`), for an
|
|
19
|
+
* object that is not an `SsrNode` (`UNRECOGNIZED_INSERT_VALUE`, development builds only), and for an
|
|
20
|
+
* accessor chain deeper than 1000.
|
|
21
|
+
* @example
|
|
22
|
+
* import { escape } from "@shadow-js/web/server";
|
|
23
|
+
*
|
|
24
|
+
* const name = () => "<Ada>";
|
|
25
|
+
* escape(["Hello, ", name, null, 3]); // "Hello, <Ada>3"
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
*/
|
|
28
|
+
export declare function escape(value: unknown): string;
|
|
29
|
+
//#endregion
|
|
30
|
+
//# sourceMappingURL=escape.d.ts.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { invalid } from "./errors.js";
|
|
2
|
+
import { isSsrNode } from "./node.js";
|
|
3
|
+
import { untrack } from "@shadow-js/core";
|
|
4
|
+
//#region src/server/escape.ts
|
|
5
|
+
const HTML_ESCAPES = {
|
|
6
|
+
"&": "&",
|
|
7
|
+
"<": "<",
|
|
8
|
+
">": ">",
|
|
9
|
+
"\"": """,
|
|
10
|
+
"'": "'"
|
|
11
|
+
};
|
|
12
|
+
const HTML_SPECIAL = /[&<>"']/g;
|
|
13
|
+
/** Longest chain of accessors that returns accessors; longer chains are a bug in user code. */
|
|
14
|
+
const MAX_ACCESSOR_LAYERS = 1e3;
|
|
15
|
+
/**
|
|
16
|
+
* Escapes the five HTML-significant characters. Escaping `&` too means entity-looking text is
|
|
17
|
+
* written literally, and the result is safe in text and in quoted attribute values alike.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
function escapeHtml(text) {
|
|
21
|
+
return text.replace(HTML_SPECIAL, (char) => HTML_ESCAPES[char] ?? char);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Calls accessors until a plain value remains. Accessors run untracked; a chain longer than
|
|
25
|
+
* {@link MAX_ACCESSOR_LAYERS} throws instead of looping.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
function resolveValue(value) {
|
|
29
|
+
let current = value;
|
|
30
|
+
for (let layer = 0; typeof current === "function"; layer += 1) {
|
|
31
|
+
if (layer >= MAX_ACCESSOR_LAYERS) throw new TypeError("An accessor returns accessors more than 1000 levels deep.");
|
|
32
|
+
current = untrack(current);
|
|
33
|
+
}
|
|
34
|
+
return current;
|
|
35
|
+
}
|
|
36
|
+
/** Writes the markup for one resolved value that is not an array. */
|
|
37
|
+
function appendLeaf(value, out) {
|
|
38
|
+
if (value === null || value === void 0 || typeof value === "boolean") return;
|
|
39
|
+
if (typeof value === "string") {
|
|
40
|
+
out.push(escapeHtml(value));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (typeof value === "number" || typeof value === "bigint") {
|
|
44
|
+
out.push(String(value));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (typeof value === "symbol") throw invalid("UNRECOGNIZED_INSERT_VALUE", "A symbol cannot be rendered.");
|
|
48
|
+
if (isSsrNode(value)) {
|
|
49
|
+
out.push(value.t);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (typeof value === "object") throw invalid("UNRECOGNIZED_INSERT_VALUE", "A plain object cannot be rendered. Use a string, a number, an array or an SsrNode.");
|
|
53
|
+
out.push(escapeHtml(String(value)));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Converts any value a JSX child may hold to escaped HTML: the helper compiled server output calls
|
|
57
|
+
* for every dynamic child, and what the renderers call on the app's result.
|
|
58
|
+
*
|
|
59
|
+
* - Strings are escaped (`& < > " '`); numbers and bigints are written as they are; `null`,
|
|
60
|
+
* `undefined` and booleans render nothing.
|
|
61
|
+
* - `SsrNode` values (from `ssr`, `ssrRaw` and the other helpers) pass through unchanged: they were
|
|
62
|
+
* escaped when they were built.
|
|
63
|
+
* - Accessors are called (untracked) and their result is rendered; a chain of more than 1000
|
|
64
|
+
* accessors returning accessors throws.
|
|
65
|
+
* - Arrays are flattened in order, with an explicit stack, so nesting depth is not limited by the
|
|
66
|
+
* call stack.
|
|
67
|
+
* - Plain objects throw in development builds and render nothing in production builds.
|
|
68
|
+
*
|
|
69
|
+
* @param value The value to render.
|
|
70
|
+
* @returns The escaped markup.
|
|
71
|
+
* @throws TypeError when an array contains itself, for a symbol (`UNRECOGNIZED_INSERT_VALUE`), for an
|
|
72
|
+
* object that is not an `SsrNode` (`UNRECOGNIZED_INSERT_VALUE`, development builds only), and for an
|
|
73
|
+
* accessor chain deeper than 1000.
|
|
74
|
+
* @example
|
|
75
|
+
* import { escape } from "@shadow-js/web/server";
|
|
76
|
+
*
|
|
77
|
+
* const name = () => "<Ada>";
|
|
78
|
+
* escape(["Hello, ", name, null, 3]); // "Hello, <Ada>3"
|
|
79
|
+
* @since 1.0.0
|
|
80
|
+
*/
|
|
81
|
+
function escape(value) {
|
|
82
|
+
const out = [];
|
|
83
|
+
const frames = [];
|
|
84
|
+
const cursors = [];
|
|
85
|
+
const open = /* @__PURE__ */ new Set();
|
|
86
|
+
let item = value;
|
|
87
|
+
for (;;) {
|
|
88
|
+
const resolved = resolveValue(item);
|
|
89
|
+
if (Array.isArray(resolved)) {
|
|
90
|
+
if (open.has(resolved)) throw new TypeError("escape(): an array contains itself.");
|
|
91
|
+
open.add(resolved);
|
|
92
|
+
frames.push(resolved);
|
|
93
|
+
cursors.push(0);
|
|
94
|
+
} else appendLeaf(resolved, out);
|
|
95
|
+
let next;
|
|
96
|
+
let found = false;
|
|
97
|
+
while (!found && frames.length > 0) {
|
|
98
|
+
const top = frames.length - 1;
|
|
99
|
+
const frame = frames[top];
|
|
100
|
+
const cursor = cursors[top] ?? 0;
|
|
101
|
+
if (frame === void 0) break;
|
|
102
|
+
if (cursor < frame.length) {
|
|
103
|
+
cursors[top] = cursor + 1;
|
|
104
|
+
next = frame[cursor];
|
|
105
|
+
found = true;
|
|
106
|
+
} else {
|
|
107
|
+
frames.pop();
|
|
108
|
+
cursors.pop();
|
|
109
|
+
open.delete(frame);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!found) return out.join("");
|
|
113
|
+
item = next;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { escape, escapeHtml, resolveValue };
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=escape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.js","names":["accessor"],"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":";;;;AAIA,MAAM,eAAiD;CACrD,KAAK;CACL,KAAK;CACL,KAAK;CACL,MAAK;CACL,KAAK;AACP;AAEA,MAAM,eAAe;;AAGrB,MAAM,sBAAsB;;;;;;AAO5B,SAAgB,WAAW,MAAsB;CAC/C,OAAO,KAAK,QAAQ,eAAe,SAAS,aAAa,SAAS,IAAI;AACxE;;;;;;AAOA,SAAgB,aAAa,OAAyB;CACpD,IAAI,UAAU;CACd,KAAK,IAAI,QAAQ,GAAG,OAAO,YAAY,YAAY,SAAS,GAAG;EAC7D,IAAI,SAAS,qBACX,MAAM,IAAI,UAAU,2DAA2D;EAGjF,UAAU,QAAQA,OAAQ;CAC5B;CACA,OAAO;AACT;;AAGA,SAAS,WAAW,OAAgB,KAAqB;CACvD,IAAI,UAAU,QAAQ,UAAU,KAAA,KAAa,OAAO,UAAU,WAAW;CACzE,IAAI,OAAO,UAAU,UAAU;EAC7B,IAAI,KAAK,WAAW,KAAK,CAAC;EAC1B;CACF;CAEA,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAAU;EAC1D,IAAI,KAAK,OAAO,KAAK,CAAC;EACtB;CACF;CACA,IAAI,OAAO,UAAU,UACnB,MAAM,QAAQ,6BAA6B,8BAA8B;CAE3E,IAAI,UAAU,KAAK,GAAG;EACpB,IAAI,KAAK,MAAM,CAAC;EAChB;CACF;CAEA,IAAI,OAAO,UAAU,UAEjB,MAAM,QACJ,6BACA,oFACF;CAIJ,IAAI,KAAK,WAAW,OAAO,KAAK,CAAC,CAAC;AACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,OAAO,OAAwB;CAC7C,MAAM,MAAgB,CAAC;CACvB,MAAM,SAAsB,CAAC;CAC7B,MAAM,UAAoB,CAAC;CAC3B,MAAM,uBAAO,IAAI,IAAe;CAChC,IAAI,OAAgB;CACpB,SAAS;EACP,MAAM,WAAW,aAAa,IAAI;EAClC,IAAI,MAAM,QAAQ,QAAQ,GAAG;GAC3B,IAAI,KAAK,IAAI,QAAQ,GAAG,MAAM,IAAI,UAAU,qCAAqC;GACjF,KAAK,IAAI,QAAQ;GACjB,OAAO,KAAK,QAAQ;GACpB,QAAQ,KAAK,CAAC;EAChB,OACE,WAAW,UAAU,GAAG;EAG1B,IAAI;EACJ,IAAI,QAAQ;EACZ,OAAO,CAAC,SAAS,OAAO,SAAS,GAAG;GAClC,MAAM,MAAM,OAAO,SAAS;GAC5B,MAAM,QAAQ,OAAO;GACrB,MAAM,SAAS,QAAQ,QAAQ;GAC/B,IAAI,UAAU,KAAA,GAAW;GACzB,IAAI,SAAS,MAAM,QAAQ;IACzB,QAAQ,OAAO,SAAS;IACxB,OAAO,MAAM;IACb,QAAQ;GACV,OAAO;IACL,OAAO,IAAI;IACX,QAAQ,IAAI;IACZ,KAAK,OAAO,KAAK;GACnB;EACF;EACA,IAAI,CAAC,OAAO,OAAO,IAAI,KAAK,EAAE;EAC9B,OAAO;CACT;AACF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { SsrNode } from "./node.js";
|
|
2
|
+
//#region src/server/form-controls.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Renders the content of a `<textarea>` from its value: the helper compiled server output calls for
|
|
5
|
+
* `<textarea value={...}>` and `defaultValue`, since a browser ignores a `value` attribute on a
|
|
6
|
+
* textarea. The text is escaped, and a value that starts with a line break gets one more, because
|
|
7
|
+
* the HTML parser drops the first one.
|
|
8
|
+
*
|
|
9
|
+
* @param value The value, or an accessor of it. `null` and `undefined` give an empty textarea;
|
|
10
|
+
* anything else is written as `String(value)`.
|
|
11
|
+
* @returns The escaped content as a trusted `SsrNode`.
|
|
12
|
+
* @throws TypeError `UNRECOGNIZED_INSERT_VALUE` when the value is a symbol.
|
|
13
|
+
* @example
|
|
14
|
+
* import { renderToString, ssr, ssrTextArea } from "@shadow-js/web/server";
|
|
15
|
+
*
|
|
16
|
+
* const bio = "Loves <b>tags</b>";
|
|
17
|
+
* const html = renderToString(() => ssr(["<textarea>", "</textarea>"], ssrTextArea(bio)));
|
|
18
|
+
* // "<textarea>Loves <b>tags</b></textarea>"
|
|
19
|
+
* @see ssrSelectValue
|
|
20
|
+
* @since 1.0.0
|
|
21
|
+
*/
|
|
22
|
+
export declare function ssrTextArea(value: unknown): SsrNode;
|
|
23
|
+
/**
|
|
24
|
+
* The options of a `<select>` with the ones its value stands for marked `selected`. A browser
|
|
25
|
+
* ignores a `value` attribute on `<select>`, so the server flags the options instead: the option
|
|
26
|
+
* whose `value` attribute equals the value (or, with no such attribute, whose text does) is
|
|
27
|
+
* selected, and every other option loses `selected`. An array selects every listed option, for
|
|
28
|
+
* `<select multiple>`; a single value selects the first match, like `select.value = x`. `null`
|
|
29
|
+
* and `undefined` stand for the empty string. Options inside `<optgroup>`, control flow and
|
|
30
|
+
* components are found because the search runs on the serialized children. Values are compared,
|
|
31
|
+
* never written, so they cannot add markup.
|
|
32
|
+
*
|
|
33
|
+
* @param value The select's `value`, or an accessor of it. Entries of an array are compared as
|
|
34
|
+
* strings; `null` and `undefined` entries are skipped.
|
|
35
|
+
* @param children The select's children (an `SsrNode`, or anything `escape` accepts).
|
|
36
|
+
* @returns The children with the `selected` flags set, as a trusted `SsrNode`.
|
|
37
|
+
* @throws TypeError `UNRECOGNIZED_INSERT_VALUE` when the value is a symbol, and the errors of
|
|
38
|
+
* {@link escape} for the children.
|
|
39
|
+
* @example
|
|
40
|
+
* import { renderToString, ssr, ssrRaw, ssrSelectValue } from "@shadow-js/web/server";
|
|
41
|
+
*
|
|
42
|
+
* const options = ssrRaw(`<option value="red">Red</option><option value="blue">Blue</option>`);
|
|
43
|
+
* const html = renderToString(() => ssr(["<select>", "</select>"], ssrSelectValue("blue", options)));
|
|
44
|
+
* // '<select><option value="red">Red</option><option value="blue" selected>Blue</option></select>'
|
|
45
|
+
* @see setSelectValue
|
|
46
|
+
* @since 1.0.0
|
|
47
|
+
*/
|
|
48
|
+
export declare function ssrSelectValue(value: unknown, children: unknown): SsrNode;
|
|
49
|
+
//#endregion
|
|
50
|
+
//# sourceMappingURL=form-controls.d.ts.map
|