@shadow-js/web 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +190 -2
- package/dist/dev/attributes.d.ts +88 -0
- package/dist/dev/attributes.js +195 -0
- package/dist/dev/attributes.js.map +1 -0
- package/dist/dev/autofocus.d.ts +30 -0
- package/dist/dev/autofocus.js +44 -0
- package/dist/dev/autofocus.js.map +1 -0
- package/dist/dev/class-style.d.ts +87 -0
- package/dist/dev/class-style.js +196 -0
- package/dist/dev/class-style.js.map +1 -0
- package/dist/dev/component.d.ts +21 -0
- package/dist/dev/component.js +41 -0
- package/dist/dev/component.js.map +1 -0
- package/dist/dev/control-flow/activity.d.ts +56 -0
- package/dist/dev/control-flow/activity.js +135 -0
- package/dist/dev/control-flow/activity.js.map +1 -0
- package/dist/dev/control-flow/branch.js +103 -0
- package/dist/dev/control-flow/branch.js.map +1 -0
- package/dist/dev/control-flow/client-only.d.ts +46 -0
- package/dist/dev/control-flow/client-only.js +49 -0
- package/dist/dev/control-flow/client-only.js.map +1 -0
- package/dist/dev/control-flow/dynamic.d.ts +80 -0
- package/dist/dev/control-flow/dynamic.js +133 -0
- package/dist/dev/control-flow/dynamic.js.map +1 -0
- package/dist/dev/control-flow/error-boundary.d.ts +70 -0
- package/dist/dev/control-flow/error-boundary.js +114 -0
- package/dist/dev/control-flow/error-boundary.js.map +1 -0
- package/dist/dev/control-flow/for.d.ts +78 -0
- package/dist/dev/control-flow/for.js +22 -0
- package/dist/dev/control-flow/for.js.map +1 -0
- package/dist/dev/control-flow/fragment.d.ts +36 -0
- package/dist/dev/control-flow/fragment.js +30 -0
- package/dist/dev/control-flow/fragment.js.map +1 -0
- package/dist/dev/control-flow/hot-link.js +63 -0
- package/dist/dev/control-flow/hot-link.js.map +1 -0
- package/dist/dev/control-flow/index-list.d.ts +46 -0
- package/dist/dev/control-flow/index-list.js +30 -0
- package/dist/dev/control-flow/index-list.js.map +1 -0
- package/dist/dev/control-flow/index.d.ts +15 -0
- package/dist/dev/control-flow/lazy.d.ts +56 -0
- package/dist/dev/control-flow/lazy.js +63 -0
- package/dist/dev/control-flow/lazy.js.map +1 -0
- package/dist/dev/control-flow/no-hydration.d.ts +37 -0
- package/dist/dev/control-flow/no-hydration.js +57 -0
- package/dist/dev/control-flow/no-hydration.js.map +1 -0
- package/dist/dev/control-flow/portal.d.ts +67 -0
- package/dist/dev/control-flow/portal.js +133 -0
- package/dist/dev/control-flow/portal.js.map +1 -0
- package/dist/dev/control-flow/root-errors.d.ts +23 -0
- package/dist/dev/control-flow/root-errors.js +32 -0
- package/dist/dev/control-flow/root-errors.js.map +1 -0
- package/dist/dev/control-flow/show.d.ts +99 -0
- package/dist/dev/control-flow/show.js +17 -0
- package/dist/dev/control-flow/show.js.map +1 -0
- package/dist/dev/control-flow/suspense-list.d.ts +63 -0
- package/dist/dev/control-flow/suspense-list.js +104 -0
- package/dist/dev/control-flow/suspense-list.js.map +1 -0
- package/dist/dev/control-flow/suspense.d.ts +51 -0
- package/dist/dev/control-flow/suspense.js +101 -0
- package/dist/dev/control-flow/suspense.js.map +1 -0
- package/dist/dev/control-flow/switch.d.ts +83 -0
- package/dist/dev/control-flow/switch.js +89 -0
- package/dist/dev/control-flow/switch.js.map +1 -0
- package/dist/dev/derived.d.ts +50 -0
- package/dist/dev/derived.js +33 -0
- package/dist/dev/derived.js.map +1 -0
- package/dist/dev/element.d.ts +38 -0
- package/dist/dev/element.js +104 -0
- package/dist/dev/element.js.map +1 -0
- package/dist/dev/events.d.ts +85 -0
- package/dist/dev/events.js +264 -0
- package/dist/dev/events.js.map +1 -0
- package/dist/dev/extend.d.ts +12 -0
- package/dist/dev/extend.js +12 -0
- package/dist/dev/head/components.d.ts +135 -0
- package/dist/dev/head/components.js +169 -0
- package/dist/dev/head/components.js.map +1 -0
- package/dist/dev/head/registry.js +67 -0
- package/dist/dev/head/registry.js.map +1 -0
- package/dist/dev/head/server-head.d.ts +52 -0
- package/dist/dev/head/server-head.js +75 -0
- package/dist/dev/head/server-head.js.map +1 -0
- package/dist/dev/head/sink.js +95 -0
- package/dist/dev/head/sink.js.map +1 -0
- package/dist/dev/head/use-head.d.ts +33 -0
- package/dist/dev/head/use-head.js +83 -0
- package/dist/dev/head/use-head.js.map +1 -0
- package/dist/dev/head/validate.d.ts +83 -0
- package/dist/dev/head/validate.js +267 -0
- package/dist/dev/head/validate.js.map +1 -0
- package/dist/dev/hmr.d.ts +80 -0
- package/dist/dev/hmr.js +123 -0
- package/dist/dev/hmr.js.map +1 -0
- package/dist/dev/hydration.d.ts +59 -0
- package/dist/dev/hydration.js +119 -0
- package/dist/dev/hydration.js.map +1 -0
- package/dist/dev/index.d.ts +45 -0
- package/dist/dev/index.js +34 -0
- package/dist/dev/insert.d.ts +95 -0
- package/dist/dev/insert.js +356 -0
- package/dist/dev/insert.js.map +1 -0
- package/dist/dev/internal/claim.d.ts +104 -0
- package/dist/dev/internal/claim.js +356 -0
- package/dist/dev/internal/claim.js.map +1 -0
- package/dist/dev/internal/css-units.js +25 -0
- package/dist/dev/internal/css-units.js.map +1 -0
- package/dist/dev/internal/diagnostics.d.ts +28 -0
- package/dist/dev/internal/diagnostics.js +37 -0
- package/dist/dev/internal/diagnostics.js.map +1 -0
- package/dist/dev/internal/early-events.js +75 -0
- package/dist/dev/internal/early-events.js.map +1 -0
- package/dist/dev/internal/hydration-hooks.d.ts +41 -0
- package/dist/dev/internal/hydration-hooks.js +26 -0
- package/dist/dev/internal/hydration-hooks.js.map +1 -0
- package/dist/dev/internal/hydration-scope.d.ts +129 -0
- package/dist/dev/internal/hydration-scope.js +155 -0
- package/dist/dev/internal/hydration-scope.js.map +1 -0
- package/dist/dev/internal/names.d.ts +31 -0
- package/dist/dev/internal/names.js +34 -0
- package/dist/dev/internal/names.js.map +1 -0
- package/dist/dev/internal/portal-context.d.ts +37 -0
- package/dist/dev/internal/portal-context.js +27 -0
- package/dist/dev/internal/portal-context.js.map +1 -0
- package/dist/dev/internal/react-names.js +115 -0
- package/dist/dev/internal/react-names.js.map +1 -0
- package/dist/dev/internal/reconcile.d.ts +38 -0
- package/dist/dev/internal/reconcile.js +121 -0
- package/dist/dev/internal/reconcile.js.map +1 -0
- package/dist/dev/internal/stream-context.d.ts +45 -0
- package/dist/dev/internal/stream-context.js +22 -0
- package/dist/dev/internal/stream-context.js.map +1 -0
- package/dist/dev/jsx/aria.d.ts +70 -0
- package/dist/dev/jsx/component.d.ts +87 -0
- package/dist/dev/jsx/events.d.ts +362 -0
- package/dist/dev/jsx/global.d.ts +209 -0
- package/dist/dev/jsx/html.d.ts +877 -0
- package/dist/dev/jsx/intrinsic.d.ts +57 -0
- package/dist/dev/jsx/mathml.d.ts +184 -0
- package/dist/dev/jsx/svg.d.ts +605 -0
- package/dist/dev/jsx/types.d.ts +174 -0
- package/dist/dev/jsx-dev-runtime.d.ts +10 -0
- package/dist/dev/jsx-dev-runtime.js +0 -0
- package/dist/dev/jsx-runtime.d.ts +92 -0
- package/dist/dev/jsx-runtime.js +0 -0
- package/dist/dev/reactive.d.ts +108 -0
- package/dist/dev/reactive.js +84 -0
- package/dist/dev/reactive.js.map +1 -0
- package/dist/dev/render.d.ts +34 -0
- package/dist/dev/render.js +51 -0
- package/dist/dev/render.js.map +1 -0
- package/dist/dev/resource-hints.d.ts +143 -0
- package/dist/dev/resource-hints.js +199 -0
- package/dist/dev/resource-hints.js.map +1 -0
- package/dist/dev/select-value.d.ts +22 -0
- package/dist/dev/select-value.js +50 -0
- package/dist/dev/select-value.js.map +1 -0
- package/dist/dev/server/attributes.d.ts +31 -0
- package/dist/dev/server/attributes.js +154 -0
- package/dist/dev/server/attributes.js.map +1 -0
- package/dist/dev/server/class-style.d.ts +44 -0
- package/dist/dev/server/class-style.js +172 -0
- package/dist/dev/server/class-style.js.map +1 -0
- package/dist/dev/server/component.d.ts +40 -0
- package/dist/dev/server/component.js +71 -0
- package/dist/dev/server/component.js.map +1 -0
- package/dist/dev/server/derived.d.ts +39 -0
- package/dist/dev/server/derived.js +25 -0
- package/dist/dev/server/derived.js.map +1 -0
- package/dist/dev/server/element.d.ts +87 -0
- package/dist/dev/server/element.js +215 -0
- package/dist/dev/server/element.js.map +1 -0
- package/dist/dev/server/errors.js +25 -0
- package/dist/dev/server/errors.js.map +1 -0
- package/dist/dev/server/escape.d.ts +28 -0
- package/dist/dev/server/escape.js +118 -0
- package/dist/dev/server/escape.js.map +1 -0
- package/dist/dev/server/form-controls.d.ts +48 -0
- package/dist/dev/server/form-controls.js +192 -0
- package/dist/dev/server/form-controls.js.map +1 -0
- package/dist/dev/server/hydration-script.d.ts +63 -0
- package/dist/dev/server/hydration-script.js +58 -0
- package/dist/dev/server/hydration-script.js.map +1 -0
- package/dist/dev/server/index.d.ts +16 -0
- package/dist/dev/server/index.js +16 -0
- package/dist/dev/server/node.d.ts +11 -0
- package/dist/dev/server/node.js +20 -0
- package/dist/dev/server/node.js.map +1 -0
- package/dist/dev/server/portals.d.ts +44 -0
- package/dist/dev/server/portals.js +98 -0
- package/dist/dev/server/portals.js.map +1 -0
- package/dist/dev/server/render.d.ts +127 -0
- package/dist/dev/server/render.js +255 -0
- package/dist/dev/server/render.js.map +1 -0
- package/dist/dev/server/serialize.d.ts +43 -0
- package/dist/dev/server/serialize.js +314 -0
- package/dist/dev/server/serialize.js.map +1 -0
- package/dist/dev/server/stream.d.ts +92 -0
- package/dist/dev/server/stream.js +234 -0
- package/dist/dev/server/stream.js.map +1 -0
- package/dist/dev/server.d.ts +16 -0
- package/dist/dev/server.js +16 -0
- package/dist/dev/spread.d.ts +47 -0
- package/dist/dev/spread.js +295 -0
- package/dist/dev/spread.js.map +1 -0
- package/dist/dev/template.d.ts +24 -0
- package/dist/dev/template.js +119 -0
- package/dist/dev/template.js.map +1 -0
- package/dist/dev/view-transition.d.ts +95 -0
- package/dist/dev/view-transition.js +120 -0
- package/dist/dev/view-transition.js.map +1 -0
- package/dist/prod/attributes.js +2 -0
- package/dist/prod/attributes.js.map +1 -0
- package/dist/prod/autofocus.js +2 -0
- package/dist/prod/autofocus.js.map +1 -0
- package/dist/prod/class-style.js +2 -0
- package/dist/prod/class-style.js.map +1 -0
- package/dist/prod/component.js +2 -0
- package/dist/prod/component.js.map +1 -0
- package/dist/prod/control-flow/activity.js +2 -0
- package/dist/prod/control-flow/activity.js.map +1 -0
- package/dist/prod/control-flow/branch.js +2 -0
- package/dist/prod/control-flow/branch.js.map +1 -0
- package/dist/prod/control-flow/client-only.js +2 -0
- package/dist/prod/control-flow/client-only.js.map +1 -0
- package/dist/prod/control-flow/dynamic.js +2 -0
- package/dist/prod/control-flow/dynamic.js.map +1 -0
- package/dist/prod/control-flow/error-boundary.js +2 -0
- package/dist/prod/control-flow/error-boundary.js.map +1 -0
- package/dist/prod/control-flow/for.js +2 -0
- package/dist/prod/control-flow/for.js.map +1 -0
- package/dist/prod/control-flow/fragment.js +2 -0
- package/dist/prod/control-flow/fragment.js.map +1 -0
- package/dist/prod/control-flow/hot-link.js +2 -0
- package/dist/prod/control-flow/hot-link.js.map +1 -0
- package/dist/prod/control-flow/index-list.js +2 -0
- package/dist/prod/control-flow/index-list.js.map +1 -0
- package/dist/prod/control-flow/lazy.js +2 -0
- package/dist/prod/control-flow/lazy.js.map +1 -0
- package/dist/prod/control-flow/no-hydration.js +2 -0
- package/dist/prod/control-flow/no-hydration.js.map +1 -0
- package/dist/prod/control-flow/portal.js +2 -0
- package/dist/prod/control-flow/portal.js.map +1 -0
- package/dist/prod/control-flow/root-errors.js +2 -0
- package/dist/prod/control-flow/root-errors.js.map +1 -0
- package/dist/prod/control-flow/show.js +2 -0
- package/dist/prod/control-flow/show.js.map +1 -0
- package/dist/prod/control-flow/suspense-list.js +2 -0
- package/dist/prod/control-flow/suspense-list.js.map +1 -0
- package/dist/prod/control-flow/suspense.js +2 -0
- package/dist/prod/control-flow/suspense.js.map +1 -0
- package/dist/prod/control-flow/switch.js +2 -0
- package/dist/prod/control-flow/switch.js.map +1 -0
- package/dist/prod/derived.js +2 -0
- package/dist/prod/derived.js.map +1 -0
- package/dist/prod/element.js +2 -0
- package/dist/prod/element.js.map +1 -0
- package/dist/prod/events.js +2 -0
- package/dist/prod/events.js.map +1 -0
- package/dist/prod/extend.js +1 -0
- package/dist/prod/head/components.js +2 -0
- package/dist/prod/head/components.js.map +1 -0
- package/dist/prod/head/registry.js +2 -0
- package/dist/prod/head/registry.js.map +1 -0
- package/dist/prod/head/server-head.js +2 -0
- package/dist/prod/head/server-head.js.map +1 -0
- package/dist/prod/head/sink.js +2 -0
- package/dist/prod/head/sink.js.map +1 -0
- package/dist/prod/head/use-head.js +2 -0
- package/dist/prod/head/use-head.js.map +1 -0
- package/dist/prod/head/validate.js +2 -0
- package/dist/prod/head/validate.js.map +1 -0
- package/dist/prod/hmr.js +2 -0
- package/dist/prod/hmr.js.map +1 -0
- package/dist/prod/hydration.js +2 -0
- package/dist/prod/hydration.js.map +1 -0
- package/dist/prod/index.js +1 -0
- package/dist/prod/insert.js +2 -0
- package/dist/prod/insert.js.map +1 -0
- package/dist/prod/internal/claim.js +2 -0
- package/dist/prod/internal/claim.js.map +1 -0
- package/dist/prod/internal/css-units.js +2 -0
- package/dist/prod/internal/css-units.js.map +1 -0
- package/dist/prod/internal/diagnostics.js +2 -0
- package/dist/prod/internal/diagnostics.js.map +1 -0
- package/dist/prod/internal/early-events.js +2 -0
- package/dist/prod/internal/early-events.js.map +1 -0
- package/dist/prod/internal/hydration-hooks.js +2 -0
- package/dist/prod/internal/hydration-hooks.js.map +1 -0
- package/dist/prod/internal/hydration-scope.js +2 -0
- package/dist/prod/internal/hydration-scope.js.map +1 -0
- package/dist/prod/internal/names.js +2 -0
- package/dist/prod/internal/names.js.map +1 -0
- package/dist/prod/internal/portal-context.js +2 -0
- package/dist/prod/internal/portal-context.js.map +1 -0
- package/dist/prod/internal/react-names.js +2 -0
- package/dist/prod/internal/react-names.js.map +1 -0
- package/dist/prod/internal/reconcile.js +2 -0
- package/dist/prod/internal/reconcile.js.map +1 -0
- package/dist/prod/internal/stream-context.js +2 -0
- package/dist/prod/internal/stream-context.js.map +1 -0
- package/dist/prod/jsx-dev-runtime.js +0 -0
- package/dist/prod/jsx-runtime.js +0 -0
- package/dist/prod/reactive.js +2 -0
- package/dist/prod/reactive.js.map +1 -0
- package/dist/prod/render.js +2 -0
- package/dist/prod/render.js.map +1 -0
- package/dist/prod/resource-hints.js +2 -0
- package/dist/prod/resource-hints.js.map +1 -0
- package/dist/prod/select-value.js +2 -0
- package/dist/prod/select-value.js.map +1 -0
- package/dist/prod/server/attributes.js +2 -0
- package/dist/prod/server/attributes.js.map +1 -0
- package/dist/prod/server/class-style.js +2 -0
- package/dist/prod/server/class-style.js.map +1 -0
- package/dist/prod/server/component.js +2 -0
- package/dist/prod/server/component.js.map +1 -0
- package/dist/prod/server/derived.js +2 -0
- package/dist/prod/server/derived.js.map +1 -0
- package/dist/prod/server/element.js +2 -0
- package/dist/prod/server/element.js.map +1 -0
- package/dist/prod/server/errors.js +2 -0
- package/dist/prod/server/errors.js.map +1 -0
- package/dist/prod/server/escape.js +2 -0
- package/dist/prod/server/escape.js.map +1 -0
- package/dist/prod/server/form-controls.js +3 -0
- package/dist/prod/server/form-controls.js.map +1 -0
- package/dist/prod/server/hydration-script.js +2 -0
- package/dist/prod/server/hydration-script.js.map +1 -0
- package/dist/prod/server/index.js +1 -0
- package/dist/prod/server/node.js +2 -0
- package/dist/prod/server/node.js.map +1 -0
- package/dist/prod/server/portals.js +2 -0
- package/dist/prod/server/portals.js.map +1 -0
- package/dist/prod/server/render.js +2 -0
- package/dist/prod/server/render.js.map +1 -0
- package/dist/prod/server/serialize.js +2 -0
- package/dist/prod/server/serialize.js.map +1 -0
- package/dist/prod/server/stream.js +2 -0
- package/dist/prod/server/stream.js.map +1 -0
- package/dist/prod/server.js +1 -0
- package/dist/prod/spread.js +2 -0
- package/dist/prod/spread.js.map +1 -0
- package/dist/prod/template.js +2 -0
- package/dist/prod/template.js.map +1 -0
- package/dist/prod/view-transition.js +2 -0
- package/dist/prod/view-transition.js.map +1 -0
- package/dist/server/attributes.js +2 -0
- package/dist/server/attributes.js.map +1 -0
- package/dist/server/autofocus.js +2 -0
- package/dist/server/autofocus.js.map +1 -0
- package/dist/server/class-style.js +2 -0
- package/dist/server/class-style.js.map +1 -0
- package/dist/server/component.js +2 -0
- package/dist/server/component.js.map +1 -0
- package/dist/server/control-flow/activity.js +2 -0
- package/dist/server/control-flow/activity.js.map +1 -0
- package/dist/server/control-flow/branch.js +2 -0
- package/dist/server/control-flow/branch.js.map +1 -0
- package/dist/server/control-flow/client-only.js +2 -0
- package/dist/server/control-flow/client-only.js.map +1 -0
- package/dist/server/control-flow/dynamic.js +2 -0
- package/dist/server/control-flow/dynamic.js.map +1 -0
- package/dist/server/control-flow/error-boundary.js +2 -0
- package/dist/server/control-flow/error-boundary.js.map +1 -0
- package/dist/server/control-flow/for.js +2 -0
- package/dist/server/control-flow/for.js.map +1 -0
- package/dist/server/control-flow/fragment.js +2 -0
- package/dist/server/control-flow/fragment.js.map +1 -0
- package/dist/server/control-flow/index-list.js +2 -0
- package/dist/server/control-flow/index-list.js.map +1 -0
- package/dist/server/control-flow/lazy.js +2 -0
- package/dist/server/control-flow/lazy.js.map +1 -0
- package/dist/server/control-flow/no-hydration.js +2 -0
- package/dist/server/control-flow/no-hydration.js.map +1 -0
- package/dist/server/control-flow/portal.js +2 -0
- package/dist/server/control-flow/portal.js.map +1 -0
- package/dist/server/control-flow/root-errors.js +2 -0
- package/dist/server/control-flow/root-errors.js.map +1 -0
- package/dist/server/control-flow/show.js +2 -0
- package/dist/server/control-flow/show.js.map +1 -0
- package/dist/server/control-flow/suspense-list.js +2 -0
- package/dist/server/control-flow/suspense-list.js.map +1 -0
- package/dist/server/control-flow/suspense.js +2 -0
- package/dist/server/control-flow/suspense.js.map +1 -0
- package/dist/server/control-flow/switch.js +2 -0
- package/dist/server/control-flow/switch.js.map +1 -0
- package/dist/server/derived.js +2 -0
- package/dist/server/derived.js.map +1 -0
- package/dist/server/element.js +2 -0
- package/dist/server/element.js.map +1 -0
- package/dist/server/events.js +2 -0
- package/dist/server/events.js.map +1 -0
- package/dist/server/extend.js +1 -0
- package/dist/server/head/components.js +2 -0
- package/dist/server/head/components.js.map +1 -0
- package/dist/server/head/registry.js +2 -0
- package/dist/server/head/registry.js.map +1 -0
- package/dist/server/head/server-head.js +2 -0
- package/dist/server/head/server-head.js.map +1 -0
- package/dist/server/head/sink.js +2 -0
- package/dist/server/head/sink.js.map +1 -0
- package/dist/server/head/use-head.js +2 -0
- package/dist/server/head/use-head.js.map +1 -0
- package/dist/server/head/validate.js +2 -0
- package/dist/server/head/validate.js.map +1 -0
- package/dist/server/hydration.js +2 -0
- package/dist/server/hydration.js.map +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/insert.js +2 -0
- package/dist/server/insert.js.map +1 -0
- package/dist/server/internal/claim.js +2 -0
- package/dist/server/internal/claim.js.map +1 -0
- package/dist/server/internal/css-units.js +2 -0
- package/dist/server/internal/css-units.js.map +1 -0
- package/dist/server/internal/diagnostics.js +2 -0
- package/dist/server/internal/diagnostics.js.map +1 -0
- package/dist/server/internal/early-events.js +2 -0
- package/dist/server/internal/early-events.js.map +1 -0
- package/dist/server/internal/hydration-hooks.js +2 -0
- package/dist/server/internal/hydration-hooks.js.map +1 -0
- package/dist/server/internal/hydration-scope.js +2 -0
- package/dist/server/internal/hydration-scope.js.map +1 -0
- package/dist/server/internal/names.js +2 -0
- package/dist/server/internal/names.js.map +1 -0
- package/dist/server/internal/portal-context.js +2 -0
- package/dist/server/internal/portal-context.js.map +1 -0
- package/dist/server/internal/react-names.js +2 -0
- package/dist/server/internal/react-names.js.map +1 -0
- package/dist/server/internal/reconcile.js +2 -0
- package/dist/server/internal/reconcile.js.map +1 -0
- package/dist/server/internal/stream-context.js +2 -0
- package/dist/server/internal/stream-context.js.map +1 -0
- package/dist/server/reactive.js +2 -0
- package/dist/server/reactive.js.map +1 -0
- package/dist/server/render.js +2 -0
- package/dist/server/render.js.map +1 -0
- package/dist/server/resource-hints.js +2 -0
- package/dist/server/resource-hints.js.map +1 -0
- package/dist/server/select-value.js +2 -0
- package/dist/server/select-value.js.map +1 -0
- package/dist/server/server/attributes.js +2 -0
- package/dist/server/server/attributes.js.map +1 -0
- package/dist/server/server/class-style.js +2 -0
- package/dist/server/server/class-style.js.map +1 -0
- package/dist/server/server/component.js +2 -0
- package/dist/server/server/component.js.map +1 -0
- package/dist/server/server/derived.js +2 -0
- package/dist/server/server/derived.js.map +1 -0
- package/dist/server/server/element.js +2 -0
- package/dist/server/server/element.js.map +1 -0
- package/dist/server/server/errors.js +2 -0
- package/dist/server/server/errors.js.map +1 -0
- package/dist/server/server/escape.js +2 -0
- package/dist/server/server/escape.js.map +1 -0
- package/dist/server/server/form-controls.js +3 -0
- package/dist/server/server/form-controls.js.map +1 -0
- package/dist/server/server/hydration-script.js +2 -0
- package/dist/server/server/hydration-script.js.map +1 -0
- package/dist/server/server/index.js +1 -0
- package/dist/server/server/node.js +2 -0
- package/dist/server/server/node.js.map +1 -0
- package/dist/server/server/portals.js +2 -0
- package/dist/server/server/portals.js.map +1 -0
- package/dist/server/server/render.js +2 -0
- package/dist/server/server/render.js.map +1 -0
- package/dist/server/server/serialize.js +2 -0
- package/dist/server/server/serialize.js.map +1 -0
- package/dist/server/server/stream.js +2 -0
- package/dist/server/server/stream.js.map +1 -0
- package/dist/server/server.js +1 -0
- package/dist/server/spread.js +2 -0
- package/dist/server/spread.js.map +1 -0
- package/dist/server/template.js +2 -0
- package/dist/server/template.js.map +1 -0
- package/dist/server/view-transition.js +2 -0
- package/dist/server/view-transition.js.map +1 -0
- package/dist/server-dev/attributes.js +195 -0
- package/dist/server-dev/attributes.js.map +1 -0
- package/dist/server-dev/autofocus.js +44 -0
- package/dist/server-dev/autofocus.js.map +1 -0
- package/dist/server-dev/class-style.js +196 -0
- package/dist/server-dev/class-style.js.map +1 -0
- package/dist/server-dev/component.js +41 -0
- package/dist/server-dev/component.js.map +1 -0
- package/dist/server-dev/control-flow/activity.js +40 -0
- package/dist/server-dev/control-flow/activity.js.map +1 -0
- package/dist/server-dev/control-flow/branch.js +103 -0
- package/dist/server-dev/control-flow/branch.js.map +1 -0
- package/dist/server-dev/control-flow/client-only.js +49 -0
- package/dist/server-dev/control-flow/client-only.js.map +1 -0
- package/dist/server-dev/control-flow/dynamic.js +105 -0
- package/dist/server-dev/control-flow/dynamic.js.map +1 -0
- package/dist/server-dev/control-flow/error-boundary.js +114 -0
- package/dist/server-dev/control-flow/error-boundary.js.map +1 -0
- package/dist/server-dev/control-flow/for.js +22 -0
- package/dist/server-dev/control-flow/for.js.map +1 -0
- package/dist/server-dev/control-flow/fragment.js +30 -0
- package/dist/server-dev/control-flow/fragment.js.map +1 -0
- package/dist/server-dev/control-flow/hot-link.js +56 -0
- package/dist/server-dev/control-flow/hot-link.js.map +1 -0
- package/dist/server-dev/control-flow/index-list.js +30 -0
- package/dist/server-dev/control-flow/index-list.js.map +1 -0
- package/dist/server-dev/control-flow/lazy.js +63 -0
- package/dist/server-dev/control-flow/lazy.js.map +1 -0
- package/dist/server-dev/control-flow/no-hydration.js +39 -0
- package/dist/server-dev/control-flow/no-hydration.js.map +1 -0
- package/dist/server-dev/control-flow/portal.js +133 -0
- package/dist/server-dev/control-flow/portal.js.map +1 -0
- package/dist/server-dev/control-flow/root-errors.js +32 -0
- package/dist/server-dev/control-flow/root-errors.js.map +1 -0
- package/dist/server-dev/control-flow/show.js +17 -0
- package/dist/server-dev/control-flow/show.js.map +1 -0
- package/dist/server-dev/control-flow/suspense-list.js +99 -0
- package/dist/server-dev/control-flow/suspense-list.js.map +1 -0
- package/dist/server-dev/control-flow/suspense.js +118 -0
- package/dist/server-dev/control-flow/suspense.js.map +1 -0
- package/dist/server-dev/control-flow/switch.js +89 -0
- package/dist/server-dev/control-flow/switch.js.map +1 -0
- package/dist/server-dev/derived.js +33 -0
- package/dist/server-dev/derived.js.map +1 -0
- package/dist/server-dev/element.js +65 -0
- package/dist/server-dev/element.js.map +1 -0
- package/dist/server-dev/events.js +264 -0
- package/dist/server-dev/events.js.map +1 -0
- package/dist/server-dev/extend.js +12 -0
- package/dist/server-dev/head/components.js +169 -0
- package/dist/server-dev/head/components.js.map +1 -0
- package/dist/server-dev/head/registry.js +67 -0
- package/dist/server-dev/head/registry.js.map +1 -0
- package/dist/server-dev/head/server-head.js +75 -0
- package/dist/server-dev/head/server-head.js.map +1 -0
- package/dist/server-dev/head/sink.js +95 -0
- package/dist/server-dev/head/sink.js.map +1 -0
- package/dist/server-dev/head/use-head.js +83 -0
- package/dist/server-dev/head/use-head.js.map +1 -0
- package/dist/server-dev/head/validate.js +267 -0
- package/dist/server-dev/head/validate.js.map +1 -0
- package/dist/server-dev/hydration.js +119 -0
- package/dist/server-dev/hydration.js.map +1 -0
- package/dist/server-dev/index.js +34 -0
- package/dist/server-dev/insert.js +356 -0
- package/dist/server-dev/insert.js.map +1 -0
- package/dist/server-dev/internal/claim.js +356 -0
- package/dist/server-dev/internal/claim.js.map +1 -0
- package/dist/server-dev/internal/css-units.js +25 -0
- package/dist/server-dev/internal/css-units.js.map +1 -0
- package/dist/server-dev/internal/diagnostics.js +37 -0
- package/dist/server-dev/internal/diagnostics.js.map +1 -0
- package/dist/server-dev/internal/early-events.js +75 -0
- package/dist/server-dev/internal/early-events.js.map +1 -0
- package/dist/server-dev/internal/hydration-hooks.js +26 -0
- package/dist/server-dev/internal/hydration-hooks.js.map +1 -0
- package/dist/server-dev/internal/hydration-scope.js +155 -0
- package/dist/server-dev/internal/hydration-scope.js.map +1 -0
- package/dist/server-dev/internal/names.js +34 -0
- package/dist/server-dev/internal/names.js.map +1 -0
- package/dist/server-dev/internal/portal-context.js +27 -0
- package/dist/server-dev/internal/portal-context.js.map +1 -0
- package/dist/server-dev/internal/react-names.js +115 -0
- package/dist/server-dev/internal/react-names.js.map +1 -0
- package/dist/server-dev/internal/reconcile.js +121 -0
- package/dist/server-dev/internal/reconcile.js.map +1 -0
- package/dist/server-dev/internal/stream-context.js +22 -0
- package/dist/server-dev/internal/stream-context.js.map +1 -0
- package/dist/server-dev/reactive.js +84 -0
- package/dist/server-dev/reactive.js.map +1 -0
- package/dist/server-dev/render.js +51 -0
- package/dist/server-dev/render.js.map +1 -0
- package/dist/server-dev/resource-hints.js +199 -0
- package/dist/server-dev/resource-hints.js.map +1 -0
- package/dist/server-dev/select-value.js +50 -0
- package/dist/server-dev/select-value.js.map +1 -0
- package/dist/server-dev/server/attributes.js +154 -0
- package/dist/server-dev/server/attributes.js.map +1 -0
- package/dist/server-dev/server/class-style.js +172 -0
- package/dist/server-dev/server/class-style.js.map +1 -0
- package/dist/server-dev/server/component.js +71 -0
- package/dist/server-dev/server/component.js.map +1 -0
- package/dist/server-dev/server/derived.js +25 -0
- package/dist/server-dev/server/derived.js.map +1 -0
- package/dist/server-dev/server/element.js +215 -0
- package/dist/server-dev/server/element.js.map +1 -0
- package/dist/server-dev/server/errors.js +25 -0
- package/dist/server-dev/server/errors.js.map +1 -0
- package/dist/server-dev/server/escape.js +118 -0
- package/dist/server-dev/server/escape.js.map +1 -0
- package/dist/server-dev/server/form-controls.js +192 -0
- package/dist/server-dev/server/form-controls.js.map +1 -0
- package/dist/server-dev/server/hydration-script.js +58 -0
- package/dist/server-dev/server/hydration-script.js.map +1 -0
- package/dist/server-dev/server/index.js +16 -0
- package/dist/server-dev/server/node.js +20 -0
- package/dist/server-dev/server/node.js.map +1 -0
- package/dist/server-dev/server/portals.js +98 -0
- package/dist/server-dev/server/portals.js.map +1 -0
- package/dist/server-dev/server/render.js +255 -0
- package/dist/server-dev/server/render.js.map +1 -0
- package/dist/server-dev/server/serialize.js +314 -0
- package/dist/server-dev/server/serialize.js.map +1 -0
- package/dist/server-dev/server/stream.js +234 -0
- package/dist/server-dev/server/stream.js.map +1 -0
- package/dist/server-dev/server.js +16 -0
- package/dist/server-dev/spread.js +295 -0
- package/dist/server-dev/spread.js.map +1 -0
- package/dist/server-dev/template.js +119 -0
- package/dist/server-dev/template.js.map +1 -0
- package/dist/server-dev/view-transition.js +89 -0
- package/dist/server-dev/view-transition.js.map +1 -0
- package/package.json +136 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.1
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Released at 1.0.1 with the other packages, which share one version. No change to this package.
|
|
8
|
+
|
|
9
|
+
## 1.0.0
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- DOM rendering, event bindings, reactive properties and composable control-flow components.
|
|
14
|
+
- Server rendering, streaming, hydration, serialization and document head management.
|
|
15
|
+
- Hydration preserves spread child nodes and static NoHydration regions.
|
|
16
|
+
- Fresh client roots mounted during hydration preserve the enclosing root's server nodes and key sequence.
|
|
17
|
+
- Streaming SSR releases abort listeners and timers, prevents rendering after cancellation, respects pre-aborted signals and keeps callbacks untracked.
|
|
18
|
+
- Held shells stop at exactly ten passes; every pass is disposed even when another pass's cleanup throws.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ShadowJS contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,191 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @shadow-js/web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The DOM renderer of ShadowJS: it mounts components, keeps text, attributes and child lists in sync
|
|
4
|
+
with signals, and provides control flow (`<Show>`, `<For>`, `<Suspense>` and more), document head
|
|
5
|
+
tags, server rendering and hydration. There is no virtual DOM: the compiler turns JSX into real DOM
|
|
6
|
+
operations (see [`@shadow-js/compiler`](../compiler/README.md)) and this package supplies the
|
|
7
|
+
runtime those operations call. The live DOM contains no comment nodes and no placeholder elements.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @shadow-js/core @shadow-js/web
|
|
13
|
+
npm install -D @shadow-js/vite
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`@shadow-js/core` is a peer dependency. JSX needs the compiler, which the Vite plugin runs for
|
|
17
|
+
you. In `tsconfig.json`, point JSX at this package:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"compilerOptions": {
|
|
22
|
+
"jsx": "preserve",
|
|
23
|
+
"jsxImportSource": "@shadow-js/web"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
ShadowJS 1.0.0 is not on npm yet. Until it is published, install it from a local checkout of this
|
|
29
|
+
repository.
|
|
30
|
+
|
|
31
|
+
## Example
|
|
32
|
+
|
|
33
|
+
A component is a function that runs once. `count()` inside JSX is a binding: when the signal
|
|
34
|
+
changes, only that text node is updated. `render` mounts a component into a container, flushes, and
|
|
35
|
+
returns a function that removes the output and disposes everything the component created.
|
|
36
|
+
|
|
37
|
+
```tsx title="counter.tsx" run mount="Counter" text="Count: 0"
|
|
38
|
+
import { useStore } from "@shadow-js/core";
|
|
39
|
+
|
|
40
|
+
export function Counter() {
|
|
41
|
+
const [count, setCount] = useStore(0);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<button type="button" onClick={() => setCount((n) => n + 1)}>
|
|
45
|
+
Count: {count()}
|
|
46
|
+
</button>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Test it with [`@shadow-js/testing`](https://testing.shadowjs.net). `fireEvent` dispatches the click and
|
|
52
|
+
flushes, so the assertion sees the updated text.
|
|
53
|
+
|
|
54
|
+
```tsx title="counter.test.tsx" test
|
|
55
|
+
import { fireEvent, render } from "@shadow-js/testing/dom";
|
|
56
|
+
import { describe, expect, it } from "vitest";
|
|
57
|
+
import { Counter } from "./counter";
|
|
58
|
+
|
|
59
|
+
describe("Counter", () => {
|
|
60
|
+
it("updates only its text when clicked", () => {
|
|
61
|
+
const view = render(() => <Counter />);
|
|
62
|
+
const button = view.getByRole("button");
|
|
63
|
+
const text = button.lastChild;
|
|
64
|
+
|
|
65
|
+
expect(button.textContent).toBe("Count: 0");
|
|
66
|
+
fireEvent.click(button);
|
|
67
|
+
|
|
68
|
+
expect(button.textContent).toBe("Count: 1");
|
|
69
|
+
expect(button.lastChild).toBe(text);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Server rendering and hydration
|
|
75
|
+
|
|
76
|
+
`@shadow-js/web/server` renders the same component to a string. The compiler emits a server variant
|
|
77
|
+
of your JSX (`generate: "ssr"`, which the Vite plugin selects for SSR builds). Hydration keys
|
|
78
|
+
(`data-hk`) and `<!--[-->` region markers in the string let the browser claim the existing nodes
|
|
79
|
+
instead of rebuilding them; the markers are removed during hydration.
|
|
80
|
+
|
|
81
|
+
```tsx title="server.tsx" run target="ssr" output='<button data-hk="0-0-0" type="button">Count: <!--[-->0<!--]--></button>'
|
|
82
|
+
import { renderToString } from "@shadow-js/web/server";
|
|
83
|
+
import { Counter } from "./counter";
|
|
84
|
+
|
|
85
|
+
console.log(renderToString(() => <Counter />));
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
On the client, `hydrate` takes the same component call and the container that holds the server
|
|
89
|
+
markup. It returns a dispose function.
|
|
90
|
+
|
|
91
|
+
```tsx title="entry-client.tsx" typecheck
|
|
92
|
+
import { hydrate } from "@shadow-js/web";
|
|
93
|
+
import { Counter } from "./counter";
|
|
94
|
+
|
|
95
|
+
const container = document.getElementById("app");
|
|
96
|
+
if (container === null) throw new Error("Missing #app element");
|
|
97
|
+
|
|
98
|
+
hydrate(() => <Counter />, container);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Resources that loaded on the server are passed through `renderToStringAsync` (which returns
|
|
102
|
+
`{ html, data }`) and `hydrate(..., { data })`; `renderToStream` streams Suspense boundaries.
|
|
103
|
+
An already-aborted signal prevents the application from rendering. Completion, failure, timeout and
|
|
104
|
+
consumer cancellation release abort listeners, timers and render owners. Cancellation also stops a
|
|
105
|
+
held shell from rendering again when its data arrives. Shell callbacks and error reporters run
|
|
106
|
+
untracked. Held shells are limited to ten passes; invalid time budgets are refused synchronously.
|
|
107
|
+
If cleanup fails, every pass is still disposed before the error is surfaced; multiple cleanup
|
|
108
|
+
failures are combined in an `AggregateError`.
|
|
109
|
+
|
|
110
|
+
## API
|
|
111
|
+
|
|
112
|
+
Entry `@shadow-js/web`. The exports are:
|
|
113
|
+
|
|
114
|
+
### Mounting and hydration
|
|
115
|
+
|
|
116
|
+
| Export | Description |
|
|
117
|
+
| --- | --- |
|
|
118
|
+
| `render` | Mounts a component into a container, flushes, and returns a dispose function. |
|
|
119
|
+
| `hydrate` | Attaches the application to HTML the server rendered, claiming nodes by key. |
|
|
120
|
+
|
|
121
|
+
### Control flow
|
|
122
|
+
|
|
123
|
+
| Export | Description |
|
|
124
|
+
| --- | --- |
|
|
125
|
+
| `Show` | Shows `children` while `when` is truthy, `fallback` otherwise. |
|
|
126
|
+
| `Switch`, `Match` | Shows the first `Match` whose `when` is truthy, or the fallback. |
|
|
127
|
+
| `For` | One row per item, matched by reference or by `key`; rows keep their identity when the list moves. |
|
|
128
|
+
| `Index` | One row per position. |
|
|
129
|
+
| `Dynamic` | Renders a component or a tag chosen at runtime. |
|
|
130
|
+
| `Portal` | Renders children into another part of the document, without a wrapper. |
|
|
131
|
+
| `Suspense` | Shows `fallback` while resources read inside it load for the first time. |
|
|
132
|
+
| `ErrorBoundary` | Renders `children`; shows a fallback when they throw, with a `reset`. |
|
|
133
|
+
| `lazy` | A component whose code is loaded on first render. |
|
|
134
|
+
| `Fragment` | A no-op wrapper that returns its children. |
|
|
135
|
+
|
|
136
|
+
### Document head
|
|
137
|
+
|
|
138
|
+
| Export | Description |
|
|
139
|
+
| --- | --- |
|
|
140
|
+
| `Title`, `Meta`, `Link`, `Base`, `Style` | Components that register head tags for their lifetime. |
|
|
141
|
+
| `useHead` | Registers head tags for the lifetime of the current owner. |
|
|
142
|
+
|
|
143
|
+
### Compiler targets and custom renderers
|
|
144
|
+
|
|
145
|
+
| Export | Description |
|
|
146
|
+
| --- | --- |
|
|
147
|
+
| `template`, `insert`, `anchor` | Clone static DOM once, insert reactive children, create text anchors. |
|
|
148
|
+
| `spread`, `use` | Apply a props object reactively; run refs and directives untracked. |
|
|
149
|
+
| `setAttribute`, `setAttributeNS`, `setBoolAttribute`, `className`, `classList`, `style`, `setStyleProperty` | Attribute, class and style writers with URL and name safety. |
|
|
150
|
+
| `addEventListener`, `delegateEvents` | Bind handlers; delegate common events to the document. |
|
|
151
|
+
| `createComponent`, `effect`, `memo`, `derived`, `mergeProps` | Helpers the compiled code imports. |
|
|
152
|
+
|
|
153
|
+
`isDev`, `isServer` and `mergeProps` are re-exported from `@shadow-js/core`. The package also
|
|
154
|
+
exports the `JSX` namespace and the component types `Component`, `ParentComponent`, `VoidComponent`,
|
|
155
|
+
`FlowComponent`, `ParentProps`, `ComponentProps`, `Ref`, `ClassValue` and `CSSProperties`.
|
|
156
|
+
|
|
157
|
+
### Subpath entries
|
|
158
|
+
|
|
159
|
+
| Entry | Contents |
|
|
160
|
+
| --- | --- |
|
|
161
|
+
| `@shadow-js/web/server` | `renderToString`, `renderToStringAsync`, `renderToStream`, `serialize`, `deserialize`, and the helpers the compiler's server output calls (`ssr`, `escape`, `ssrAttribute`, `ssrClass`, `ssrStyle`, `ssrElement`, `ssrHydrationKey`, `ssrRaw`, `ssrSelectValue`, `ssrTextArea`). |
|
|
162
|
+
| `@shadow-js/web/jsx-runtime`, `@shadow-js/web/jsx-dev-runtime` | The `JSX` namespace for `jsxImportSource`; augment `CustomEvents` and `Directives` here. |
|
|
163
|
+
| `@shadow-js/web/extend` | The building blocks the built-ins use: `createRegion`, `bindRegion`, `reconcileNodes`, hydration scopes (`withScope`, `nextKey`, `claimElement`), `isUnsafeUrlAttribute`. |
|
|
164
|
+
| `@shadow-js/web/hmr` | The runtime of component-level hot updates, imported by code the compiler generates when its `hmr` option is on. Not called by application code. |
|
|
165
|
+
|
|
166
|
+
## Status
|
|
167
|
+
|
|
168
|
+
The DOM runtime, control flow, the server renderer and hydration are tested, including the
|
|
169
|
+
server-to-client round trip. `Dynamic`, `Portal`, head tags and the JSX types are exported; the
|
|
170
|
+
type tests are in `packages/web/test-types`.
|
|
171
|
+
|
|
172
|
+
## Links
|
|
173
|
+
|
|
174
|
+
- [`@shadow-js/core`](../core/README.md), [`@shadow-js/compiler`](../compiler/README.md), [`@shadow-js/vite`](../vite/README.md), [`@shadow-js/testing`](https://testing.shadowjs.net)
|
|
175
|
+
|
|
176
|
+
## Dependencies
|
|
177
|
+
|
|
178
|
+
- Runtime: none.
|
|
179
|
+
- Peers: `@shadow-js/core` `^1.0.0`: the reactive primitives the renderer is built on.
|
|
180
|
+
|
|
181
|
+
## Types
|
|
182
|
+
|
|
183
|
+
- Names from the root: `ComponentProps`, `Derived`, `derived`, `HydrateOptions`.
|
|
184
|
+
- Type tests in `test-types/` run with `npx tsc -p tsconfig.test-types.json`.
|
|
185
|
+
|
|
186
|
+
## Support
|
|
187
|
+
|
|
188
|
+
- Node.js `>=22.12.0`. ESM only: use `import`; `require` is not supported.
|
|
189
|
+
- Browsers: current evergreen releases.
|
|
190
|
+
- Versioning: every `@shadow-js/*` package releases together at one version. Upgrade them as one set.
|
|
191
|
+
- Documentation: [ShadowJS documentation](https://shadowjs.net).
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reports whether writing `value` to the attribute `name` would run script: the URL check that
|
|
3
|
+
* {@link setAttribute}, the head registry and the server renderer share. Use it in a custom renderer
|
|
4
|
+
* before writing a URL that came from user data. URL attributes (`href`, `src`, `action`,
|
|
5
|
+
* `formaction`, `xlink:href`, `srcdoc`, `poster`, `data`) are unsafe when, after removing control
|
|
6
|
+
* characters, trimming and lowercasing, they start with `javascript:`, `data:text/html` or
|
|
7
|
+
* `vbscript:`. The SVG animation attributes `values`, `from`, `to` and `by` are checked the same way,
|
|
8
|
+
* each `;`-separated entry of `values` on its own.
|
|
9
|
+
*
|
|
10
|
+
* @param name Attribute name, in any case.
|
|
11
|
+
* @param value The text that would be written.
|
|
12
|
+
* @returns `true` when the value must not be written; `false` for every other attribute or value.
|
|
13
|
+
* @example
|
|
14
|
+
* import { isUnsafeUrlAttribute } from "@shadow-js/web/extend";
|
|
15
|
+
*
|
|
16
|
+
* isUnsafeUrlAttribute("href", " JavaScript:alert(1)"); // true
|
|
17
|
+
* isUnsafeUrlAttribute("href", "https://example.com"); // false
|
|
18
|
+
* isUnsafeUrlAttribute("title", "javascript:alert(1)"); // false: not a URL attribute
|
|
19
|
+
* @see setAttribute
|
|
20
|
+
* @since 1.0.0
|
|
21
|
+
*/
|
|
22
|
+
export declare function isUnsafeUrlAttribute(name: string, value: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Sets or removes one attribute with the JSX value rules: the helper compiled templates call for a
|
|
25
|
+
* dynamic attribute, also usable on elements you create yourself. The DOM is touched only when the
|
|
26
|
+
* text changes. A URL attribute whose value would run script (see {@link isUnsafeUrlAttribute}) is
|
|
27
|
+
* left unchanged, and development builds warn once with `UNSAFE_URL_BLOCKED`.
|
|
28
|
+
*
|
|
29
|
+
* @param el Target element.
|
|
30
|
+
* @param name Attribute name. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.
|
|
31
|
+
* @param value `null`, `undefined` and `false` remove the attribute, except that `false` writes
|
|
32
|
+
* `"false"` for `aria-*`, `data-*`, `draggable`, `spellcheck` and `contenteditable`. `true` writes
|
|
33
|
+
* `""` (or `"true"` for those same names). Any other value is written as `String(value)`.
|
|
34
|
+
* @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.
|
|
35
|
+
* @example
|
|
36
|
+
* import { setAttribute } from "@shadow-js/web";
|
|
37
|
+
*
|
|
38
|
+
* const link = document.createElement("a");
|
|
39
|
+
* setAttribute(link, "href", "https://example.com");
|
|
40
|
+
* setAttribute(link, "aria-hidden", false); // aria-hidden="false"
|
|
41
|
+
* setAttribute(link, "title", null); // removes title
|
|
42
|
+
* @see setBoolAttribute
|
|
43
|
+
* @see setAttributeNS
|
|
44
|
+
* @since 1.0.0
|
|
45
|
+
*/
|
|
46
|
+
export declare function setAttribute(el: Element, name: string, value: unknown): void;
|
|
47
|
+
/**
|
|
48
|
+
* Sets or removes a namespaced attribute such as `xlink:href` or `xml:lang`, with the value rules
|
|
49
|
+
* and the URL check of {@link setAttribute}. Removal uses the local part of the name (`href` for
|
|
50
|
+
* `xlink:href`).
|
|
51
|
+
*
|
|
52
|
+
* @param el Target element.
|
|
53
|
+
* @param namespace Namespace URI. `""` means no namespace, which behaves exactly like
|
|
54
|
+
* {@link setAttribute}.
|
|
55
|
+
* @param name Qualified name (`prefix:local`). It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.
|
|
56
|
+
* @param value The value, with the same rules as {@link setAttribute}.
|
|
57
|
+
* @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.
|
|
58
|
+
* @example
|
|
59
|
+
* import { setAttributeNS } from "@shadow-js/web";
|
|
60
|
+
*
|
|
61
|
+
* const XLINK = "http://www.w3.org/1999/xlink";
|
|
62
|
+
* const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
|
|
63
|
+
* setAttributeNS(use, XLINK, "xlink:href", "#icon-star");
|
|
64
|
+
* setAttributeNS(use, XLINK, "xlink:href", null); // removes it
|
|
65
|
+
* @see setAttribute
|
|
66
|
+
* @since 1.0.0
|
|
67
|
+
*/
|
|
68
|
+
export declare function setAttributeNS(el: Element, namespace: string, name: string, value: unknown): void;
|
|
69
|
+
/**
|
|
70
|
+
* Sets or removes a presence (boolean) attribute such as `disabled` or `hidden`: the helper compiled
|
|
71
|
+
* templates call for the `bool:` prefix. A truthy value sets the attribute to `""`, a falsy value
|
|
72
|
+
* removes it; the DOM is touched only when presence changes. No URL check applies.
|
|
73
|
+
*
|
|
74
|
+
* @param el Target element.
|
|
75
|
+
* @param name Attribute name, such as `disabled`. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.
|
|
76
|
+
* @param value Any value: only its truthiness is read.
|
|
77
|
+
* @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.
|
|
78
|
+
* @example
|
|
79
|
+
* import { setBoolAttribute } from "@shadow-js/web";
|
|
80
|
+
*
|
|
81
|
+
* const button = document.createElement("button");
|
|
82
|
+
* setBoolAttribute(button, "disabled", true); // disabled=""
|
|
83
|
+
* setBoolAttribute(button, "disabled", 0); // removed
|
|
84
|
+
* @see setAttribute
|
|
85
|
+
* @since 1.0.0
|
|
86
|
+
*/
|
|
87
|
+
export declare function setBoolAttribute(el: Element, name: string, value: unknown): void;
|
|
88
|
+
//# sourceMappingURL=attributes.d.ts.map
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { invalidAttributeName, warnOnce } from "./internal/diagnostics.js";
|
|
2
|
+
// src/attributes.ts
|
|
3
|
+
/** Names that can appear in markup: an XML-name subset without `@` or whitespace. */
|
|
4
|
+
const ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_:.-]*$/;
|
|
5
|
+
/**
|
|
6
|
+
* Attributes whose value is a URL and therefore checked for script schemes. The SVG animation values
|
|
7
|
+
* (`animate`, `set`) are checked too: with `attributeName="href"` they write an `href` by animation.
|
|
8
|
+
*/
|
|
9
|
+
const URL_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
10
|
+
"href",
|
|
11
|
+
"src",
|
|
12
|
+
"action",
|
|
13
|
+
"formaction",
|
|
14
|
+
"xlink:href",
|
|
15
|
+
"srcdoc",
|
|
16
|
+
"poster",
|
|
17
|
+
"data",
|
|
18
|
+
"values",
|
|
19
|
+
"from",
|
|
20
|
+
"to",
|
|
21
|
+
"by"
|
|
22
|
+
]);
|
|
23
|
+
/** Enumerated attributes where `false` is a real value ("false") rather than an absence. */
|
|
24
|
+
const ENUMERATED_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
25
|
+
"draggable",
|
|
26
|
+
"spellcheck",
|
|
27
|
+
"contenteditable"
|
|
28
|
+
]);
|
|
29
|
+
/** URL prefixes (after normalization) that are never written. */
|
|
30
|
+
const UNSAFE_URL_PREFIXES = [
|
|
31
|
+
"javascript:",
|
|
32
|
+
"data:text/html",
|
|
33
|
+
"vbscript:"
|
|
34
|
+
];
|
|
35
|
+
/**
|
|
36
|
+
* Throws a TypeError unless `name` is a valid attribute name. Runs for every name, including the
|
|
37
|
+
* ones that come from spread, so no unvalidated name reaches `setAttribute`.
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
function assertAttributeName(name) {
|
|
41
|
+
if (!ATTRIBUTE_NAME.test(name)) throw invalidAttributeName(name);
|
|
42
|
+
}
|
|
43
|
+
/** True for `aria-*`, `data-*` and the enumerated attributes: their boolean values are strings. */
|
|
44
|
+
function isStringValued(lowerName) {
|
|
45
|
+
return lowerName.startsWith("aria-") || lowerName.startsWith("data-") || ENUMERATED_ATTRIBUTES.has(lowerName);
|
|
46
|
+
}
|
|
47
|
+
/** Removes C0 and C1 control characters. Written as a loop so no control character appears in a regex. */
|
|
48
|
+
function stripControls(text) {
|
|
49
|
+
let kept = "";
|
|
50
|
+
for (const char of text) {
|
|
51
|
+
const code = char.charCodeAt(0);
|
|
52
|
+
if (code > 31 && (code < 127 || code > 159)) kept += char;
|
|
53
|
+
}
|
|
54
|
+
return kept;
|
|
55
|
+
}
|
|
56
|
+
/** True when the URL would run script: browsers ignore the controls and case that hide the scheme. */
|
|
57
|
+
function isUnsafeUrl(value) {
|
|
58
|
+
const normalized = stripControls(value).trim().toLowerCase();
|
|
59
|
+
return UNSAFE_URL_PREFIXES.some((prefix) => normalized.startsWith(prefix));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Reports whether writing `value` to the attribute `name` would run script: the URL check that
|
|
63
|
+
* {@link setAttribute}, the head registry and the server renderer share. Use it in a custom renderer
|
|
64
|
+
* before writing a URL that came from user data. URL attributes (`href`, `src`, `action`,
|
|
65
|
+
* `formaction`, `xlink:href`, `srcdoc`, `poster`, `data`) are unsafe when, after removing control
|
|
66
|
+
* characters, trimming and lowercasing, they start with `javascript:`, `data:text/html` or
|
|
67
|
+
* `vbscript:`. The SVG animation attributes `values`, `from`, `to` and `by` are checked the same way,
|
|
68
|
+
* each `;`-separated entry of `values` on its own.
|
|
69
|
+
*
|
|
70
|
+
* @param name Attribute name, in any case.
|
|
71
|
+
* @param value The text that would be written.
|
|
72
|
+
* @returns `true` when the value must not be written; `false` for every other attribute or value.
|
|
73
|
+
* @example
|
|
74
|
+
* import { isUnsafeUrlAttribute } from "@shadow-js/web/extend";
|
|
75
|
+
*
|
|
76
|
+
* isUnsafeUrlAttribute("href", " JavaScript:alert(1)"); // true
|
|
77
|
+
* isUnsafeUrlAttribute("href", "https://example.com"); // false
|
|
78
|
+
* isUnsafeUrlAttribute("title", "javascript:alert(1)"); // false: not a URL attribute
|
|
79
|
+
* @see setAttribute
|
|
80
|
+
* @since 1.0.0
|
|
81
|
+
*/
|
|
82
|
+
function isUnsafeUrlAttribute(name, value) {
|
|
83
|
+
const lowerName = name.toLowerCase();
|
|
84
|
+
if (!URL_ATTRIBUTES.has(lowerName)) return false;
|
|
85
|
+
return lowerName === "values" ? value.split(";").some(isUnsafeUrl) : isUnsafeUrl(value);
|
|
86
|
+
}
|
|
87
|
+
/** Text to write for `value`, or null when the attribute must be removed. */
|
|
88
|
+
function attributeText(lowerName, value) {
|
|
89
|
+
if (value === null || value === void 0) return null;
|
|
90
|
+
if (value === false) return isStringValued(lowerName) ? "false" : null;
|
|
91
|
+
if (value === true) return isStringValued(lowerName) ? "true" : "";
|
|
92
|
+
return String(value);
|
|
93
|
+
}
|
|
94
|
+
/** The part of a qualified name after the prefix (`xlink:href` gives `href`). */
|
|
95
|
+
function localPart(qualified) {
|
|
96
|
+
const colon = qualified.indexOf(":");
|
|
97
|
+
return colon === -1 ? qualified : qualified.slice(colon + 1);
|
|
98
|
+
}
|
|
99
|
+
/** Writes or removes one attribute, applying the value rules and the URL check. */
|
|
100
|
+
function commit(el, namespace, qualified, value) {
|
|
101
|
+
const lowerName = qualified.toLowerCase();
|
|
102
|
+
const text = attributeText(lowerName, value);
|
|
103
|
+
if (text === null) {
|
|
104
|
+
if (namespace === null) el.removeAttribute(qualified);
|
|
105
|
+
else el.removeAttributeNS(namespace, localPart(qualified));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (isUnsafeUrlAttribute(lowerName, text)) {
|
|
109
|
+
warnOnce("UNSAFE_URL_BLOCKED", `Blocked a script URL in the "${qualified}" attribute.`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (namespace === null) {
|
|
113
|
+
if (el.getAttribute(qualified) !== text) el.setAttribute(qualified, text);
|
|
114
|
+
} else if (el.getAttributeNS(namespace, localPart(qualified)) !== text) el.setAttributeNS(namespace, qualified, text);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Sets or removes one attribute with the JSX value rules: the helper compiled templates call for a
|
|
118
|
+
* dynamic attribute, also usable on elements you create yourself. The DOM is touched only when the
|
|
119
|
+
* text changes. A URL attribute whose value would run script (see {@link isUnsafeUrlAttribute}) is
|
|
120
|
+
* left unchanged, and development builds warn once with `UNSAFE_URL_BLOCKED`.
|
|
121
|
+
*
|
|
122
|
+
* @param el Target element.
|
|
123
|
+
* @param name Attribute name. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.
|
|
124
|
+
* @param value `null`, `undefined` and `false` remove the attribute, except that `false` writes
|
|
125
|
+
* `"false"` for `aria-*`, `data-*`, `draggable`, `spellcheck` and `contenteditable`. `true` writes
|
|
126
|
+
* `""` (or `"true"` for those same names). Any other value is written as `String(value)`.
|
|
127
|
+
* @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.
|
|
128
|
+
* @example
|
|
129
|
+
* import { setAttribute } from "@shadow-js/web";
|
|
130
|
+
*
|
|
131
|
+
* const link = document.createElement("a");
|
|
132
|
+
* setAttribute(link, "href", "https://example.com");
|
|
133
|
+
* setAttribute(link, "aria-hidden", false); // aria-hidden="false"
|
|
134
|
+
* setAttribute(link, "title", null); // removes title
|
|
135
|
+
* @see setBoolAttribute
|
|
136
|
+
* @see setAttributeNS
|
|
137
|
+
* @since 1.0.0
|
|
138
|
+
*/
|
|
139
|
+
function setAttribute(el, name, value) {
|
|
140
|
+
assertAttributeName(name);
|
|
141
|
+
commit(el, null, name, value);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Sets or removes a namespaced attribute such as `xlink:href` or `xml:lang`, with the value rules
|
|
145
|
+
* and the URL check of {@link setAttribute}. Removal uses the local part of the name (`href` for
|
|
146
|
+
* `xlink:href`).
|
|
147
|
+
*
|
|
148
|
+
* @param el Target element.
|
|
149
|
+
* @param namespace Namespace URI. `""` means no namespace, which behaves exactly like
|
|
150
|
+
* {@link setAttribute}.
|
|
151
|
+
* @param name Qualified name (`prefix:local`). It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.
|
|
152
|
+
* @param value The value, with the same rules as {@link setAttribute}.
|
|
153
|
+
* @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.
|
|
154
|
+
* @example
|
|
155
|
+
* import { setAttributeNS } from "@shadow-js/web";
|
|
156
|
+
*
|
|
157
|
+
* const XLINK = "http://www.w3.org/1999/xlink";
|
|
158
|
+
* const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
|
|
159
|
+
* setAttributeNS(use, XLINK, "xlink:href", "#icon-star");
|
|
160
|
+
* setAttributeNS(use, XLINK, "xlink:href", null); // removes it
|
|
161
|
+
* @see setAttribute
|
|
162
|
+
* @since 1.0.0
|
|
163
|
+
*/
|
|
164
|
+
function setAttributeNS(el, namespace, name, value) {
|
|
165
|
+
assertAttributeName(name);
|
|
166
|
+
commit(el, namespace === "" ? null : namespace, name, value);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Sets or removes a presence (boolean) attribute such as `disabled` or `hidden`: the helper compiled
|
|
170
|
+
* templates call for the `bool:` prefix. A truthy value sets the attribute to `""`, a falsy value
|
|
171
|
+
* removes it; the DOM is touched only when presence changes. No URL check applies.
|
|
172
|
+
*
|
|
173
|
+
* @param el Target element.
|
|
174
|
+
* @param name Attribute name, such as `disabled`. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.
|
|
175
|
+
* @param value Any value: only its truthiness is read.
|
|
176
|
+
* @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.
|
|
177
|
+
* @example
|
|
178
|
+
* import { setBoolAttribute } from "@shadow-js/web";
|
|
179
|
+
*
|
|
180
|
+
* const button = document.createElement("button");
|
|
181
|
+
* setBoolAttribute(button, "disabled", true); // disabled=""
|
|
182
|
+
* setBoolAttribute(button, "disabled", 0); // removed
|
|
183
|
+
* @see setAttribute
|
|
184
|
+
* @since 1.0.0
|
|
185
|
+
*/
|
|
186
|
+
function setBoolAttribute(el, name, value) {
|
|
187
|
+
assertAttributeName(name);
|
|
188
|
+
const present = el.hasAttribute(name);
|
|
189
|
+
if (value) {
|
|
190
|
+
if (!present) el.setAttribute(name, "");
|
|
191
|
+
} else if (present) el.removeAttribute(name);
|
|
192
|
+
}
|
|
193
|
+
export { assertAttributeName, isUnsafeUrlAttribute, setAttribute, setAttributeNS, setBoolAttribute };
|
|
194
|
+
|
|
195
|
+
//# sourceMappingURL=attributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attributes.js","names":[],"sources":["../../src/attributes.ts"],"sourcesContent":["import { invalidAttributeName, warnOnce } from \"./internal/diagnostics\";\n\n/** Names that can appear in markup: an XML-name subset without `@` or whitespace. */\nconst ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_:.-]*$/;\n\n/**\n * Attributes whose value is a URL and therefore checked for script schemes. The SVG animation values\n * (`animate`, `set`) are checked too: with `attributeName=\"href\"` they write an `href` by animation.\n */\nconst URL_ATTRIBUTES = new Set([\n \"href\",\n \"src\",\n \"action\",\n \"formaction\",\n \"xlink:href\",\n \"srcdoc\",\n \"poster\",\n \"data\",\n \"values\",\n \"from\",\n \"to\",\n \"by\",\n]);\n\n/** Enumerated attributes where `false` is a real value (\"false\") rather than an absence. */\nconst ENUMERATED_ATTRIBUTES = new Set([\"draggable\", \"spellcheck\", \"contenteditable\"]);\n\n/** URL prefixes (after normalization) that are never written. */\nconst UNSAFE_URL_PREFIXES = [\"javascript:\", \"data:text/html\", \"vbscript:\"];\n\n/**\n * Throws a TypeError unless `name` is a valid attribute name. Runs for every name, including the\n * ones that come from spread, so no unvalidated name reaches `setAttribute`.\n * @internal\n */\nexport function assertAttributeName(name: string): void {\n if (!ATTRIBUTE_NAME.test(name)) throw invalidAttributeName(name);\n}\n\n/** True for `aria-*`, `data-*` and the enumerated attributes: their boolean values are strings. */\nfunction isStringValued(lowerName: string): boolean {\n return (\n lowerName.startsWith(\"aria-\") ||\n lowerName.startsWith(\"data-\") ||\n ENUMERATED_ATTRIBUTES.has(lowerName)\n );\n}\n\n/** Removes C0 and C1 control characters. Written as a loop so no control character appears in a regex. */\nfunction stripControls(text: string): string {\n let kept = \"\";\n for (const char of text) {\n const code = char.charCodeAt(0);\n if (code > 0x1f && (code < 0x7f || code > 0x9f)) kept += char;\n }\n return kept;\n}\n\n/** True when the URL would run script: browsers ignore the controls and case that hide the scheme. */\nfunction isUnsafeUrl(value: string): boolean {\n const normalized = stripControls(value).trim().toLowerCase();\n return UNSAFE_URL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n\n/**\n * Reports whether writing `value` to the attribute `name` would run script: the URL check that\n * {@link setAttribute}, the head registry and the server renderer share. Use it in a custom renderer\n * before writing a URL that came from user data. URL attributes (`href`, `src`, `action`,\n * `formaction`, `xlink:href`, `srcdoc`, `poster`, `data`) are unsafe when, after removing control\n * characters, trimming and lowercasing, they start with `javascript:`, `data:text/html` or\n * `vbscript:`. The SVG animation attributes `values`, `from`, `to` and `by` are checked the same way,\n * each `;`-separated entry of `values` on its own.\n *\n * @param name Attribute name, in any case.\n * @param value The text that would be written.\n * @returns `true` when the value must not be written; `false` for every other attribute or value.\n * @example\n * import { isUnsafeUrlAttribute } from \"@shadow-js/web/extend\";\n *\n * isUnsafeUrlAttribute(\"href\", \" JavaScript:alert(1)\"); // true\n * isUnsafeUrlAttribute(\"href\", \"https://example.com\"); // false\n * isUnsafeUrlAttribute(\"title\", \"javascript:alert(1)\"); // false: not a URL attribute\n * @see setAttribute\n * @since 1.0.0\n */\nexport function isUnsafeUrlAttribute(name: string, value: string): boolean {\n const lowerName = name.toLowerCase();\n if (!URL_ATTRIBUTES.has(lowerName)) return false;\n // `values` is a `;` list: every entry is a URL of its own.\n return lowerName === \"values\" ? value.split(\";\").some(isUnsafeUrl) : isUnsafeUrl(value);\n}\n\n/** Text to write for `value`, or null when the attribute must be removed. */\nfunction attributeText(lowerName: string, value: unknown): string | null {\n if (value === null || value === undefined) return null;\n if (value === false) return isStringValued(lowerName) ? \"false\" : null;\n if (value === true) return isStringValued(lowerName) ? \"true\" : \"\";\n return String(value);\n}\n\n/** The part of a qualified name after the prefix (`xlink:href` gives `href`). */\nfunction localPart(qualified: string): string {\n const colon = qualified.indexOf(\":\");\n return colon === -1 ? qualified : qualified.slice(colon + 1);\n}\n\n/** Writes or removes one attribute, applying the value rules and the URL check. */\nfunction commit(el: Element, namespace: string | null, qualified: string, value: unknown): void {\n const lowerName = qualified.toLowerCase();\n const text = attributeText(lowerName, value);\n if (text === null) {\n if (namespace === null) el.removeAttribute(qualified);\n else el.removeAttributeNS(namespace, localPart(qualified));\n return;\n }\n if (isUnsafeUrlAttribute(lowerName, text)) {\n warnOnce(\"UNSAFE_URL_BLOCKED\", `Blocked a script URL in the \"${qualified}\" attribute.`);\n return;\n }\n if (namespace === null) {\n if (el.getAttribute(qualified) !== text) el.setAttribute(qualified, text);\n } else if (el.getAttributeNS(namespace, localPart(qualified)) !== text) {\n el.setAttributeNS(namespace, qualified, text);\n }\n}\n\n/**\n * Sets or removes one attribute with the JSX value rules: the helper compiled templates call for a\n * dynamic attribute, also usable on elements you create yourself. The DOM is touched only when the\n * text changes. A URL attribute whose value would run script (see {@link isUnsafeUrlAttribute}) is\n * left unchanged, and development builds warn once with `UNSAFE_URL_BLOCKED`.\n *\n * @param el Target element.\n * @param name Attribute name. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.\n * @param value `null`, `undefined` and `false` remove the attribute, except that `false` writes\n * `\"false\"` for `aria-*`, `data-*`, `draggable`, `spellcheck` and `contenteditable`. `true` writes\n * `\"\"` (or `\"true\"` for those same names). Any other value is written as `String(value)`.\n * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.\n * @example\n * import { setAttribute } from \"@shadow-js/web\";\n *\n * const link = document.createElement(\"a\");\n * setAttribute(link, \"href\", \"https://example.com\");\n * setAttribute(link, \"aria-hidden\", false); // aria-hidden=\"false\"\n * setAttribute(link, \"title\", null); // removes title\n * @see setBoolAttribute\n * @see setAttributeNS\n * @since 1.0.0\n */\nexport function setAttribute(el: Element, name: string, value: unknown): void {\n assertAttributeName(name);\n commit(el, null, name, value);\n}\n\n/**\n * Sets or removes a namespaced attribute such as `xlink:href` or `xml:lang`, with the value rules\n * and the URL check of {@link setAttribute}. Removal uses the local part of the name (`href` for\n * `xlink:href`).\n *\n * @param el Target element.\n * @param namespace Namespace URI. `\"\"` means no namespace, which behaves exactly like\n * {@link setAttribute}.\n * @param name Qualified name (`prefix:local`). It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.\n * @param value The value, with the same rules as {@link setAttribute}.\n * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.\n * @example\n * import { setAttributeNS } from \"@shadow-js/web\";\n *\n * const XLINK = \"http://www.w3.org/1999/xlink\";\n * const use = document.createElementNS(\"http://www.w3.org/2000/svg\", \"use\");\n * setAttributeNS(use, XLINK, \"xlink:href\", \"#icon-star\");\n * setAttributeNS(use, XLINK, \"xlink:href\", null); // removes it\n * @see setAttribute\n * @since 1.0.0\n */\nexport function setAttributeNS(el: Element, namespace: string, name: string, value: unknown): void {\n assertAttributeName(name);\n commit(el, namespace === \"\" ? null : namespace, name, value);\n}\n\n/**\n * Sets or removes a presence (boolean) attribute such as `disabled` or `hidden`: the helper compiled\n * templates call for the `bool:` prefix. A truthy value sets the attribute to `\"\"`, a falsy value\n * removes it; the DOM is touched only when presence changes. No URL check applies.\n *\n * @param el Target element.\n * @param name Attribute name, such as `disabled`. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.\n * @param value Any value: only its truthiness is read.\n * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.\n * @example\n * import { setBoolAttribute } from \"@shadow-js/web\";\n *\n * const button = document.createElement(\"button\");\n * setBoolAttribute(button, \"disabled\", true); // disabled=\"\"\n * setBoolAttribute(button, \"disabled\", 0); // removed\n * @see setAttribute\n * @since 1.0.0\n */\nexport function setBoolAttribute(el: Element, name: string, value: unknown): void {\n assertAttributeName(name);\n const present = el.hasAttribute(name);\n if (value) {\n if (!present) el.setAttribute(name, \"\");\n } else if (present) {\n el.removeAttribute(name);\n }\n}\n"],"mappings":";;;AAGA,MAAM,iBAAiB;;;;;AAMvB,MAAM,iCAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,MAAM,wCAAwB,IAAI,IAAI;CAAC;CAAa;CAAc;AAAiB,CAAC;;AAGpF,MAAM,sBAAsB;CAAC;CAAe;CAAkB;AAAW;;;;;;AAOzE,SAAgB,oBAAoB,MAAoB;CACtD,IAAI,CAAC,eAAe,KAAK,IAAI,GAAG,MAAM,qBAAqB,IAAI;AACjE;;AAGA,SAAS,eAAe,WAA4B;CAClD,OACE,UAAU,WAAW,OAAO,KAC5B,UAAU,WAAW,OAAO,KAC5B,sBAAsB,IAAI,SAAS;AAEvC;;AAGA,SAAS,cAAc,MAAsB;CAC3C,IAAI,OAAO;CACX,KAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,OAAO,KAAK,WAAW,CAAC;EAC9B,IAAI,OAAO,OAAS,OAAO,OAAQ,OAAO,MAAO,QAAQ;CAC3D;CACA,OAAO;AACT;;AAGA,SAAS,YAAY,OAAwB;CAC3C,MAAM,aAAa,cAAc,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,YAAY;CAC3D,OAAO,oBAAoB,MAAM,WAAW,WAAW,WAAW,MAAM,CAAC;AAC3E;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,qBAAqB,MAAc,OAAwB;CACzE,MAAM,YAAY,KAAK,YAAY;CACnC,IAAI,CAAC,eAAe,IAAI,SAAS,GAAG,OAAO;CAE3C,OAAO,cAAc,WAAW,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,WAAW,IAAI,YAAY,KAAK;AACxF;;AAGA,SAAS,cAAc,WAAmB,OAA+B;CACvE,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;CAClD,IAAI,UAAU,OAAO,OAAO,eAAe,SAAS,IAAI,UAAU;CAClE,IAAI,UAAU,MAAM,OAAO,eAAe,SAAS,IAAI,SAAS;CAChE,OAAO,OAAO,KAAK;AACrB;;AAGA,SAAS,UAAU,WAA2B;CAC5C,MAAM,QAAQ,UAAU,QAAQ,GAAG;CACnC,OAAO,UAAU,KAAK,YAAY,UAAU,MAAM,QAAQ,CAAC;AAC7D;;AAGA,SAAS,OAAO,IAAa,WAA0B,WAAmB,OAAsB;CAC9F,MAAM,YAAY,UAAU,YAAY;CACxC,MAAM,OAAO,cAAc,WAAW,KAAK;CAC3C,IAAI,SAAS,MAAM;EACjB,IAAI,cAAc,MAAM,GAAG,gBAAgB,SAAS;OAC/C,GAAG,kBAAkB,WAAW,UAAU,SAAS,CAAC;EACzD;CACF;CACA,IAAI,qBAAqB,WAAW,IAAI,GAAG;EACzC,SAAS,sBAAsB,gCAAgC,UAAU,aAAa;EACtF;CACF;CACA,IAAI,cAAc,MACZ;MAAA,GAAG,aAAa,SAAS,MAAM,MAAM,GAAG,aAAa,WAAW,IAAI;CAAA,OACnE,IAAI,GAAG,eAAe,WAAW,UAAU,SAAS,CAAC,MAAM,MAChE,GAAG,eAAe,WAAW,WAAW,IAAI;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,aAAa,IAAa,MAAc,OAAsB;CAC5E,oBAAoB,IAAI;CACxB,OAAO,IAAI,MAAM,MAAM,KAAK;AAC9B;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,eAAe,IAAa,WAAmB,MAAc,OAAsB;CACjG,oBAAoB,IAAI;CACxB,OAAO,IAAI,cAAc,KAAK,OAAO,WAAW,MAAM,KAAK;AAC7D;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,iBAAiB,IAAa,MAAc,OAAsB;CAChF,oBAAoB,IAAI;CACxB,MAAM,UAAU,GAAG,aAAa,IAAI;CACpC,IAAI,OACE;MAAA,CAAC,SAAS,GAAG,aAAa,MAAM,EAAE;CAAA,OACjC,IAAI,SACT,GAAG,gBAAgB,IAAI;AAE3B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Focuses an element written with `autoFocus` (React parity) once it is inserted into the document
|
|
3
|
+
* by a client render or update. The compiler calls this for an `autoFocus` attribute and for
|
|
4
|
+
* `autoFocus` keys of a spread, so an app that never uses `autoFocus` never reaches this code. Call it
|
|
5
|
+
* yourself only for elements you create by hand, inside an owner (a component or a root): the focus
|
|
6
|
+
* is requested with `onMount`, so development builds warn with `NO_OWNER_EFFECT` without one.
|
|
7
|
+
*
|
|
8
|
+
* The rules, which match React's for `autoFocus`:
|
|
9
|
+
* - Once per element: the focus is requested when the element is created, after the owner has been
|
|
10
|
+
* flushed. Moving the element later (a keyed reorder) does not focus it again.
|
|
11
|
+
* - An element that is not connected when its owner flushes (a detached root) is not focused.
|
|
12
|
+
* - During hydration the server markup already carries `autofocus`, so the element focuses only when
|
|
13
|
+
* nothing else has the focus (the document's active element is the body or null). A user's focus
|
|
14
|
+
* is never taken away by hydration.
|
|
15
|
+
*
|
|
16
|
+
* @param el The element. Only `HTMLElement` and `SVGElement` are focused; for any other element, and
|
|
17
|
+
* for one that cannot take focus, the call does nothing.
|
|
18
|
+
* @param enabled The `autoFocus` value: falsy values (`false`, `undefined`, `""`, `0`) do nothing.
|
|
19
|
+
* @example
|
|
20
|
+
* import { autoFocus, render } from "@shadow-js/web";
|
|
21
|
+
*
|
|
22
|
+
* render(() => {
|
|
23
|
+
* const input = document.createElement("input");
|
|
24
|
+
* autoFocus(input, true); // focused once the root has mounted it
|
|
25
|
+
* return input;
|
|
26
|
+
* }, document.body);
|
|
27
|
+
* @since 1.0.0
|
|
28
|
+
*/
|
|
29
|
+
export declare function autoFocus(el: Element, enabled: unknown): void;
|
|
30
|
+
//# sourceMappingURL=autofocus.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { onMount } from "@shadow-js/core";
|
|
2
|
+
import { isHydrating } from "@shadow-js/core/extend";
|
|
3
|
+
// src/autofocus.ts
|
|
4
|
+
/**
|
|
5
|
+
* Focuses an element written with `autoFocus` (React parity) once it is inserted into the document
|
|
6
|
+
* by a client render or update. The compiler calls this for an `autoFocus` attribute and for
|
|
7
|
+
* `autoFocus` keys of a spread, so an app that never uses `autoFocus` never reaches this code. Call it
|
|
8
|
+
* yourself only for elements you create by hand, inside an owner (a component or a root): the focus
|
|
9
|
+
* is requested with `onMount`, so development builds warn with `NO_OWNER_EFFECT` without one.
|
|
10
|
+
*
|
|
11
|
+
* The rules, which match React's for `autoFocus`:
|
|
12
|
+
* - Once per element: the focus is requested when the element is created, after the owner has been
|
|
13
|
+
* flushed. Moving the element later (a keyed reorder) does not focus it again.
|
|
14
|
+
* - An element that is not connected when its owner flushes (a detached root) is not focused.
|
|
15
|
+
* - During hydration the server markup already carries `autofocus`, so the element focuses only when
|
|
16
|
+
* nothing else has the focus (the document's active element is the body or null). A user's focus
|
|
17
|
+
* is never taken away by hydration.
|
|
18
|
+
*
|
|
19
|
+
* @param el The element. Only `HTMLElement` and `SVGElement` are focused; for any other element, and
|
|
20
|
+
* for one that cannot take focus, the call does nothing.
|
|
21
|
+
* @param enabled The `autoFocus` value: falsy values (`false`, `undefined`, `""`, `0`) do nothing.
|
|
22
|
+
* @example
|
|
23
|
+
* import { autoFocus, render } from "@shadow-js/web";
|
|
24
|
+
*
|
|
25
|
+
* render(() => {
|
|
26
|
+
* const input = document.createElement("input");
|
|
27
|
+
* autoFocus(input, true); // focused once the root has mounted it
|
|
28
|
+
* return input;
|
|
29
|
+
* }, document.body);
|
|
30
|
+
* @since 1.0.0
|
|
31
|
+
*/
|
|
32
|
+
function autoFocus(el, enabled) {
|
|
33
|
+
if (!enabled) return;
|
|
34
|
+
const hydrating = isHydrating();
|
|
35
|
+
onMount(() => {
|
|
36
|
+
const doc = el.ownerDocument;
|
|
37
|
+
const active = doc.activeElement;
|
|
38
|
+
const free = !hydrating || active === null || active === doc.body;
|
|
39
|
+
if (el.isConnected && free && (el instanceof HTMLElement || el instanceof SVGElement)) el.focus();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export { autoFocus };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=autofocus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autofocus.js","names":[],"sources":["../../src/autofocus.ts"],"sourcesContent":["import { onMount } from \"@shadow-js/core\";\nimport { isHydrating } from \"@shadow-js/core/extend\";\n\n/**\n * Focuses an element written with `autoFocus` (React parity) once it is inserted into the document\n * by a client render or update. The compiler calls this for an `autoFocus` attribute and for\n * `autoFocus` keys of a spread, so an app that never uses `autoFocus` never reaches this code. Call it\n * yourself only for elements you create by hand, inside an owner (a component or a root): the focus\n * is requested with `onMount`, so development builds warn with `NO_OWNER_EFFECT` without one.\n *\n * The rules, which match React's for `autoFocus`:\n * - Once per element: the focus is requested when the element is created, after the owner has been\n * flushed. Moving the element later (a keyed reorder) does not focus it again.\n * - An element that is not connected when its owner flushes (a detached root) is not focused.\n * - During hydration the server markup already carries `autofocus`, so the element focuses only when\n * nothing else has the focus (the document's active element is the body or null). A user's focus\n * is never taken away by hydration.\n *\n * @param el The element. Only `HTMLElement` and `SVGElement` are focused; for any other element, and\n * for one that cannot take focus, the call does nothing.\n * @param enabled The `autoFocus` value: falsy values (`false`, `undefined`, `\"\"`, `0`) do nothing.\n * @example\n * import { autoFocus, render } from \"@shadow-js/web\";\n *\n * render(() => {\n * const input = document.createElement(\"input\");\n * autoFocus(input, true); // focused once the root has mounted it\n * return input;\n * }, document.body);\n * @since 1.0.0\n */\nexport function autoFocus(el: Element, enabled: unknown): void {\n if (!enabled) return;\n const hydrating = isHydrating();\n onMount(() => {\n const doc = el.ownerDocument;\n const active = doc.activeElement;\n // Hydration focuses only when nothing has the focus: the body or no element.\n const free = !hydrating || active === null || active === doc.body;\n if (el.isConnected && free && (el instanceof HTMLElement || el instanceof SVGElement)) {\n el.focus();\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,UAAU,IAAa,SAAwB;CAC7D,IAAI,CAAC,SAAS;CACd,MAAM,YAAY,YAAY;CAC9B,cAAc;EACZ,MAAM,MAAM,GAAG;EACf,MAAM,SAAS,IAAI;EAEnB,MAAM,OAAO,CAAC,aAAa,WAAW,QAAQ,WAAW,IAAI;EAC7D,IAAI,GAAG,eAAe,SAAS,cAAc,eAAe,cAAc,aACxE,GAAG,MAAM;CAEb,CAAC;AACH"}
|