@shadow-js/web 1.0.0 → 1.0.2
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 +29 -0
- package/dist/dev/attributes.d.ts +10 -5
- package/dist/dev/attributes.js +28 -51
- package/dist/dev/attributes.js.map +1 -1
- package/dist/dev/autofocus.d.ts +0 -2
- package/dist/dev/autofocus.js +1 -2
- package/dist/dev/class-style.d.ts +6 -4
- package/dist/dev/class-style.js +25 -9
- package/dist/dev/class-style.js.map +1 -1
- package/dist/dev/component.d.ts +0 -2
- package/dist/dev/component.js +1 -2
- package/dist/dev/control-flow/activity.d.ts +0 -2
- package/dist/dev/control-flow/activity.js +1 -2
- package/dist/dev/control-flow/branch.js +0 -1
- package/dist/dev/control-flow/client-only.d.ts +0 -2
- package/dist/dev/control-flow/client-only.js +1 -2
- package/dist/dev/control-flow/dynamic.d.ts +11 -4
- package/dist/dev/control-flow/dynamic.js +57 -41
- package/dist/dev/control-flow/dynamic.js.map +1 -1
- package/dist/dev/control-flow/error-boundary.d.ts +0 -2
- package/dist/dev/control-flow/error-boundary.js +1 -2
- package/dist/dev/control-flow/for.d.ts +0 -2
- package/dist/dev/control-flow/for.js +1 -2
- package/dist/dev/control-flow/fragment.d.ts +0 -2
- package/dist/dev/control-flow/fragment.js +1 -2
- package/dist/dev/control-flow/hot-link.js +1 -2
- package/dist/dev/control-flow/index-list.d.ts +0 -2
- package/dist/dev/control-flow/index-list.js +1 -2
- package/dist/dev/control-flow/lazy.d.ts +0 -2
- package/dist/dev/control-flow/lazy.js +1 -2
- package/dist/dev/control-flow/no-hydration.d.ts +0 -2
- package/dist/dev/control-flow/no-hydration.js +1 -2
- package/dist/dev/control-flow/portal.d.ts +0 -2
- package/dist/dev/control-flow/portal.js +3 -2
- package/dist/dev/control-flow/portal.js.map +1 -1
- package/dist/dev/control-flow/root-errors.d.ts +0 -2
- package/dist/dev/control-flow/root-errors.js +1 -2
- package/dist/dev/control-flow/show.d.ts +0 -2
- package/dist/dev/control-flow/show.js +1 -2
- package/dist/dev/control-flow/suspense-list.d.ts +0 -2
- package/dist/dev/control-flow/suspense-list.js +1 -2
- package/dist/dev/control-flow/suspense.d.ts +0 -2
- package/dist/dev/control-flow/suspense.js +1 -2
- package/dist/dev/control-flow/switch.d.ts +0 -2
- package/dist/dev/control-flow/switch.js +1 -2
- package/dist/dev/derived.d.ts +0 -2
- package/dist/dev/derived.js +1 -2
- package/dist/dev/element.d.ts +0 -2
- package/dist/dev/element.js +2 -3
- package/dist/dev/element.js.map +1 -1
- package/dist/dev/events.d.ts +0 -2
- package/dist/dev/events.js +16 -46
- package/dist/dev/events.js.map +1 -1
- package/dist/dev/head/components.d.ts +0 -2
- package/dist/dev/head/components.js +1 -2
- package/dist/dev/head/registry.js +1 -2
- package/dist/dev/head/server-head.d.ts +0 -2
- package/dist/dev/head/server-head.js +1 -2
- package/dist/dev/head/sink.js +1 -2
- package/dist/dev/head/use-head.d.ts +0 -2
- package/dist/dev/head/use-head.js +1 -2
- package/dist/dev/head/validate.d.ts +0 -2
- package/dist/dev/head/validate.js +1 -2
- package/dist/dev/hmr.d.ts +0 -2
- package/dist/dev/hmr.js +1 -2
- package/dist/dev/hydration.d.ts +0 -2
- package/dist/dev/hydration.js +1 -2
- package/dist/dev/insert.d.ts +15 -7
- package/dist/dev/insert.js +36 -15
- package/dist/dev/insert.js.map +1 -1
- package/dist/dev/internal/claim.d.ts +2 -3
- package/dist/dev/internal/claim.js +19 -4
- package/dist/dev/internal/claim.js.map +1 -1
- package/dist/dev/internal/css-units.js +1 -2
- package/dist/dev/internal/diagnostics.d.ts +7 -5
- package/dist/dev/internal/diagnostics.js +15 -6
- package/dist/dev/internal/diagnostics.js.map +1 -1
- package/dist/dev/internal/early-events.js +21 -4
- package/dist/dev/internal/early-events.js.map +1 -1
- package/dist/dev/internal/hydration-hooks.d.ts +0 -2
- package/dist/dev/internal/hydration-hooks.js +0 -1
- package/dist/dev/internal/hydration-scope.d.ts +0 -2
- package/dist/dev/internal/hydration-scope.js +1 -2
- package/dist/dev/internal/names.d.ts +0 -2
- package/dist/dev/internal/names.js +1 -2
- package/dist/dev/internal/portal-context.d.ts +0 -2
- package/dist/dev/internal/portal-context.js +1 -2
- package/dist/dev/internal/react-names.js +26 -63
- package/dist/dev/internal/react-names.js.map +1 -1
- package/dist/dev/internal/reconcile.d.ts +0 -2
- package/dist/dev/internal/reconcile.js +4 -8
- package/dist/dev/internal/reconcile.js.map +1 -1
- package/dist/dev/internal/stream-context.d.ts +0 -2
- package/dist/dev/internal/stream-context.js +1 -2
- package/dist/dev/jsx/aria.d.ts +0 -2
- package/dist/dev/jsx/component.d.ts +0 -2
- package/dist/dev/jsx/events.d.ts +0 -2
- package/dist/dev/jsx/global.d.ts +5 -4
- package/dist/dev/jsx/html.d.ts +1 -2
- package/dist/dev/jsx/intrinsic.d.ts +0 -2
- package/dist/dev/jsx/mathml.d.ts +0 -2
- package/dist/dev/jsx/svg.d.ts +0 -2
- package/dist/dev/jsx/types.d.ts +0 -2
- package/dist/dev/jsx-runtime.d.ts +0 -2
- package/dist/dev/reactive.d.ts +0 -2
- package/dist/dev/reactive.js +1 -2
- package/dist/dev/render.d.ts +0 -2
- package/dist/dev/render.js +1 -2
- package/dist/dev/resource-hints.d.ts +0 -2
- package/dist/dev/resource-hints.js +5 -4
- package/dist/dev/resource-hints.js.map +1 -1
- package/dist/dev/select-value.d.ts +0 -2
- package/dist/dev/select-value.js +6 -17
- package/dist/dev/select-value.js.map +1 -1
- package/dist/dev/server/attributes.d.ts +3 -2
- package/dist/dev/server/attributes.js +6 -3
- package/dist/dev/server/attributes.js.map +1 -1
- package/dist/dev/server/class-style.d.ts +0 -2
- package/dist/dev/server/class-style.js +1 -2
- package/dist/dev/server/component.d.ts +0 -2
- package/dist/dev/server/component.js +1 -2
- package/dist/dev/server/derived.d.ts +0 -2
- package/dist/dev/server/derived.js +1 -2
- package/dist/dev/server/element.d.ts +0 -2
- package/dist/dev/server/element.js +9 -6
- package/dist/dev/server/element.js.map +1 -1
- package/dist/dev/server/errors.js +8 -3
- package/dist/dev/server/errors.js.map +1 -1
- package/dist/dev/server/escape.d.ts +0 -2
- package/dist/dev/server/escape.js +15 -8
- package/dist/dev/server/escape.js.map +1 -1
- package/dist/dev/server/form-controls.d.ts +0 -2
- package/dist/dev/server/form-controls.js +6 -4
- package/dist/dev/server/form-controls.js.map +1 -1
- package/dist/dev/server/hydration-script.d.ts +0 -2
- package/dist/dev/server/hydration-script.js +1 -2
- package/dist/dev/server/index.d.ts +2 -1
- package/dist/dev/server/index.js +2 -1
- package/dist/dev/server/node.d.ts +0 -2
- package/dist/dev/server/node.js +1 -2
- package/dist/dev/server/portals.d.ts +0 -2
- package/dist/dev/server/portals.js +0 -1
- package/dist/dev/server/raw-text.d.ts +28 -0
- package/dist/dev/server/raw-text.js +66 -0
- package/dist/dev/server/raw-text.js.map +1 -0
- package/dist/dev/server/render.d.ts +2 -3
- package/dist/dev/server/render.js +3 -4
- package/dist/dev/server/render.js.map +1 -1
- package/dist/dev/server/serialize.d.ts +0 -2
- package/dist/dev/server/serialize.js +1 -2
- package/dist/dev/server/stream.d.ts +1 -3
- package/dist/dev/server/stream.js +3 -4
- package/dist/dev/server/stream.js.map +1 -1
- package/dist/dev/server.d.ts +2 -1
- package/dist/dev/server.js +2 -1
- package/dist/dev/spread.d.ts +0 -2
- package/dist/dev/spread.js +8 -56
- package/dist/dev/spread.js.map +1 -1
- package/dist/dev/template.d.ts +0 -2
- package/dist/dev/template.js +1 -2
- package/dist/dev/view-transition.d.ts +0 -2
- package/dist/dev/view-transition.js +1 -2
- package/dist/prod/attributes.js +1 -1
- package/dist/prod/attributes.js.map +1 -1
- package/dist/prod/class-style.js +1 -1
- package/dist/prod/class-style.js.map +1 -1
- package/dist/prod/control-flow/dynamic.js +1 -1
- package/dist/prod/control-flow/dynamic.js.map +1 -1
- package/dist/prod/control-flow/portal.js +1 -1
- package/dist/prod/control-flow/portal.js.map +1 -1
- package/dist/prod/element.js +1 -1
- package/dist/prod/element.js.map +1 -1
- package/dist/prod/events.js +1 -1
- package/dist/prod/events.js.map +1 -1
- package/dist/prod/insert.js +1 -1
- package/dist/prod/insert.js.map +1 -1
- package/dist/prod/internal/claim.js +1 -1
- package/dist/prod/internal/claim.js.map +1 -1
- package/dist/prod/internal/diagnostics.js +1 -1
- package/dist/prod/internal/diagnostics.js.map +1 -1
- package/dist/prod/internal/early-events.js +1 -1
- package/dist/prod/internal/early-events.js.map +1 -1
- package/dist/prod/internal/react-names.js +1 -1
- package/dist/prod/internal/react-names.js.map +1 -1
- package/dist/prod/internal/reconcile.js +1 -1
- package/dist/prod/internal/reconcile.js.map +1 -1
- package/dist/prod/resource-hints.js +1 -1
- package/dist/prod/resource-hints.js.map +1 -1
- package/dist/prod/select-value.js +1 -1
- package/dist/prod/select-value.js.map +1 -1
- package/dist/prod/server/attributes.js +1 -1
- package/dist/prod/server/attributes.js.map +1 -1
- package/dist/prod/server/element.js +1 -1
- package/dist/prod/server/element.js.map +1 -1
- package/dist/prod/server/errors.js +1 -1
- package/dist/prod/server/errors.js.map +1 -1
- package/dist/prod/server/escape.js +1 -1
- package/dist/prod/server/escape.js.map +1 -1
- package/dist/prod/server/form-controls.js +2 -2
- package/dist/prod/server/form-controls.js.map +1 -1
- package/dist/prod/server/index.js +1 -1
- package/dist/prod/server/raw-text.js +2 -0
- package/dist/prod/server/raw-text.js.map +1 -0
- package/dist/prod/server/render.js +1 -1
- package/dist/prod/server/render.js.map +1 -1
- package/dist/prod/server/stream.js +1 -1
- package/dist/prod/server/stream.js.map +1 -1
- package/dist/prod/server.js +1 -1
- package/dist/prod/spread.js +1 -1
- package/dist/prod/spread.js.map +1 -1
- package/dist/server/attributes.js +1 -1
- package/dist/server/attributes.js.map +1 -1
- package/dist/server/class-style.js +1 -1
- package/dist/server/class-style.js.map +1 -1
- package/dist/server/control-flow/dynamic.js +1 -1
- package/dist/server/control-flow/dynamic.js.map +1 -1
- package/dist/server/control-flow/portal.js +1 -1
- package/dist/server/control-flow/portal.js.map +1 -1
- package/dist/server/element.js +1 -1
- package/dist/server/element.js.map +1 -1
- package/dist/server/events.js +1 -1
- package/dist/server/events.js.map +1 -1
- package/dist/server/insert.js +1 -1
- package/dist/server/insert.js.map +1 -1
- package/dist/server/internal/claim.js +1 -1
- package/dist/server/internal/claim.js.map +1 -1
- package/dist/server/internal/diagnostics.js +1 -1
- package/dist/server/internal/diagnostics.js.map +1 -1
- package/dist/server/internal/early-events.js +1 -1
- package/dist/server/internal/early-events.js.map +1 -1
- package/dist/server/internal/react-names.js +1 -1
- package/dist/server/internal/react-names.js.map +1 -1
- package/dist/server/internal/reconcile.js +1 -1
- package/dist/server/internal/reconcile.js.map +1 -1
- package/dist/server/resource-hints.js +1 -1
- package/dist/server/resource-hints.js.map +1 -1
- package/dist/server/select-value.js +1 -1
- package/dist/server/select-value.js.map +1 -1
- package/dist/server/server/attributes.js +1 -1
- package/dist/server/server/attributes.js.map +1 -1
- package/dist/server/server/element.js +1 -1
- package/dist/server/server/element.js.map +1 -1
- package/dist/server/server/errors.js +1 -1
- package/dist/server/server/errors.js.map +1 -1
- package/dist/server/server/escape.js +1 -1
- package/dist/server/server/escape.js.map +1 -1
- package/dist/server/server/form-controls.js +2 -2
- package/dist/server/server/form-controls.js.map +1 -1
- package/dist/server/server/index.js +1 -1
- package/dist/server/server/raw-text.js +2 -0
- package/dist/server/server/raw-text.js.map +1 -0
- package/dist/server/server/render.js +1 -1
- package/dist/server/server/render.js.map +1 -1
- package/dist/server/server/stream.js +1 -1
- package/dist/server/server/stream.js.map +1 -1
- package/dist/server/server.js +1 -1
- package/dist/server/spread.js +1 -1
- package/dist/server/spread.js.map +1 -1
- package/dist/server-dev/attributes.js +28 -51
- package/dist/server-dev/attributes.js.map +1 -1
- package/dist/server-dev/autofocus.js +1 -2
- package/dist/server-dev/class-style.js +25 -9
- package/dist/server-dev/class-style.js.map +1 -1
- package/dist/server-dev/component.js +1 -2
- package/dist/server-dev/control-flow/activity.js +1 -2
- package/dist/server-dev/control-flow/branch.js +0 -1
- package/dist/server-dev/control-flow/client-only.js +1 -2
- package/dist/server-dev/control-flow/dynamic.js +23 -12
- package/dist/server-dev/control-flow/dynamic.js.map +1 -1
- package/dist/server-dev/control-flow/error-boundary.js +1 -2
- package/dist/server-dev/control-flow/for.js +1 -2
- package/dist/server-dev/control-flow/fragment.js +1 -2
- package/dist/server-dev/control-flow/hot-link.js +1 -2
- package/dist/server-dev/control-flow/index-list.js +1 -2
- package/dist/server-dev/control-flow/lazy.js +1 -2
- package/dist/server-dev/control-flow/no-hydration.js +1 -2
- package/dist/server-dev/control-flow/portal.js +3 -2
- package/dist/server-dev/control-flow/portal.js.map +1 -1
- package/dist/server-dev/control-flow/root-errors.js +1 -2
- package/dist/server-dev/control-flow/show.js +1 -2
- package/dist/server-dev/control-flow/suspense-list.js +1 -2
- package/dist/server-dev/control-flow/suspense.js +1 -2
- package/dist/server-dev/control-flow/switch.js +1 -2
- package/dist/server-dev/derived.js +1 -2
- package/dist/server-dev/element.js +4 -3
- package/dist/server-dev/element.js.map +1 -1
- package/dist/server-dev/events.js +16 -46
- package/dist/server-dev/events.js.map +1 -1
- package/dist/server-dev/head/components.js +1 -2
- package/dist/server-dev/head/registry.js +1 -2
- package/dist/server-dev/head/server-head.js +1 -2
- package/dist/server-dev/head/sink.js +1 -2
- package/dist/server-dev/head/use-head.js +1 -2
- package/dist/server-dev/head/validate.js +1 -2
- package/dist/server-dev/hydration.js +1 -2
- package/dist/server-dev/insert.js +36 -15
- package/dist/server-dev/insert.js.map +1 -1
- package/dist/server-dev/internal/claim.js +19 -4
- package/dist/server-dev/internal/claim.js.map +1 -1
- package/dist/server-dev/internal/css-units.js +1 -2
- package/dist/server-dev/internal/diagnostics.js +15 -6
- package/dist/server-dev/internal/diagnostics.js.map +1 -1
- package/dist/server-dev/internal/early-events.js +21 -4
- package/dist/server-dev/internal/early-events.js.map +1 -1
- package/dist/server-dev/internal/hydration-hooks.js +0 -1
- package/dist/server-dev/internal/hydration-scope.js +1 -2
- package/dist/server-dev/internal/names.js +1 -2
- package/dist/server-dev/internal/portal-context.js +1 -2
- package/dist/server-dev/internal/react-names.js +26 -63
- package/dist/server-dev/internal/react-names.js.map +1 -1
- package/dist/server-dev/internal/reconcile.js +4 -8
- package/dist/server-dev/internal/reconcile.js.map +1 -1
- package/dist/server-dev/internal/stream-context.js +1 -2
- package/dist/server-dev/reactive.js +1 -2
- package/dist/server-dev/render.js +1 -2
- package/dist/server-dev/resource-hints.js +5 -4
- package/dist/server-dev/resource-hints.js.map +1 -1
- package/dist/server-dev/select-value.js +6 -17
- package/dist/server-dev/select-value.js.map +1 -1
- package/dist/server-dev/server/attributes.js +6 -3
- package/dist/server-dev/server/attributes.js.map +1 -1
- package/dist/server-dev/server/class-style.js +1 -2
- package/dist/server-dev/server/component.js +1 -2
- package/dist/server-dev/server/derived.js +1 -2
- package/dist/server-dev/server/element.js +9 -6
- package/dist/server-dev/server/element.js.map +1 -1
- package/dist/server-dev/server/errors.js +8 -3
- package/dist/server-dev/server/errors.js.map +1 -1
- package/dist/server-dev/server/escape.js +15 -8
- package/dist/server-dev/server/escape.js.map +1 -1
- package/dist/server-dev/server/form-controls.js +6 -4
- package/dist/server-dev/server/form-controls.js.map +1 -1
- package/dist/server-dev/server/hydration-script.js +1 -2
- package/dist/server-dev/server/index.js +2 -1
- package/dist/server-dev/server/node.js +1 -2
- package/dist/server-dev/server/portals.js +0 -1
- package/dist/server-dev/server/raw-text.js +86 -0
- package/dist/server-dev/server/raw-text.js.map +1 -0
- package/dist/server-dev/server/render.js +3 -4
- package/dist/server-dev/server/render.js.map +1 -1
- package/dist/server-dev/server/serialize.js +1 -2
- package/dist/server-dev/server/stream.js +3 -4
- package/dist/server-dev/server/stream.js.map +1 -1
- package/dist/server-dev/server.js +2 -1
- package/dist/server-dev/spread.js +8 -56
- package/dist/server-dev/spread.js.map +1 -1
- package/dist/server-dev/template.js +1 -2
- package/dist/server-dev/view-transition.js +1 -2
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Dynamic children of `<style>` and `<script>` are written as text on the server, not entity-escaped (`a > b` stays `a > b`), and a closing tag of the element in the text (`</style`, `</script`, and `<!--` in a script) is made harmless as `<\/style`. `<style>`, `<script>`, `<title>` and `<textarea>` get no `<!--[-->` markers inside them, from compiled code, `element()` and `Dynamic` alike, and hydration adopts their text. `@shadow-js/web/server` exports `ssrRawText` for the compiled output.
|
|
8
|
+
- `classList` switches on class names that `Object.prototype` also has (`constructor`, `toString`), which were skipped before.
|
|
9
|
+
- `element()` calls its `ref` untracked, so a signal read in the ref no longer re-runs the code that created the element.
|
|
10
|
+
- A delegated `[handler, undefined]` tuple receives `(undefined, event)`, as the native binding does.
|
|
11
|
+
- A `Portal` whose mount is missing while the page hydrates removes the server block it adopted instead of leaving it in the body.
|
|
12
|
+
- `setAttribute`, `setAttributeNS` and `spread` no longer write `on*` attributes from strings (a spread of untrusted keys could add `onclick="..."`); the server already dropped them.
|
|
13
|
+
- Server `hidden="until-found"` is written as the keyword instead of a bare `hidden`.
|
|
14
|
+
- A `<textarea>` given its text as children keeps a leading line break on the server.
|
|
15
|
+
- `timeoutMs` of `renderToStream` and `renderToStringAsync` is clamped to the timer range, so `Number.MAX_SAFE_INTEGER` no longer expires after one millisecond.
|
|
16
|
+
- `preinit` and `preinitModule` skip a script with the same `src` and `type` that is already anywhere in the document, not only in the head with the same attributes.
|
|
17
|
+
- The early event capture script keeps at most 100 events.
|
|
18
|
+
- `Dynamic` creates every SVG-only tag the compiler knows (`image`, `foreignObject`, `animate*`, the `fe*` filter primitives, `clipPath`, `mask`, `pattern`, `marker`, `symbol`, `use`, `textPath`, `tspan`, the gradients, `stop`, `filter`, `desc`, `metadata`, `view`, `switch`, ...) in the SVG namespace, in any letter case.
|
|
19
|
+
- The client `style()` accepts an array of strings and objects, written in order with a later declaration winning, as `ssrStyle` does; the `style` JSX prop type accepts it too.
|
|
20
|
+
- Replaying a click captured before hydration runs the page's handlers without the browser's default action, so a link is no longer followed a second time.
|
|
21
|
+
- Several `insert()` regions without an anchor on one parent keep the order of the calls: a reactive region created right where the previous one ends gives that one an empty Text node as its anchor (removed when that region is disposed), so a sibling that replaces its nodes no longer sends the content of an empty region after it to the end of the parent.
|
|
22
|
+
- `Dynamic` creates MathML names (`math`, `mi`, `mfrac`, `semantics`, `annotation-xml`, ...) in the MathML namespace, and any SVG-only name in the SVG namespace exactly as the caller wrote it: it no longer derives the canonical case of a name written in the wrong case (`clippath` makes an element named `clippath`, not a `clipPath`). The namespace comes from a name pattern that answers the same in every DOM and parses no HTML. Development builds warn once per name with the new code `DYNAMIC_SVG_CASE`, which names the canonical spelling; `warnOnce` takes an optional `key` for a warning that is once per key instead of once per code.
|
|
23
|
+
- `srcdoc` is no longer treated as a URL: it is an HTML document, an HTML sink with the trust of `innerHTML`, written as it is (client and server) with no scheme check. Development builds warn once with the new code `SRCDOC_DYNAMIC` (see the `sandbox` attribute) when a computed value is written to it.
|
|
24
|
+
- Hydrating a `Dynamic` `title` or `style` inside an `<svg>` adopts the server text instead of adding it a second time (`<title>HiHi</title>`): the server writes such a tag without region markers because `Dynamic` does not know its parent, so `takeRegion` adopts the content of a `title`, `style`, `script` or `textarea` in whichever namespace the page parsed it. `Dynamic` also creates the SVG 2 `discard` element in the SVG namespace.
|
|
25
|
+
|
|
26
|
+
## 1.0.1
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- Released at 1.0.1 with the other packages, which share one version. No change to this package.
|
|
31
|
+
|
|
3
32
|
## 1.0.0
|
|
4
33
|
|
|
5
34
|
### Added
|
package/dist/dev/attributes.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
//#region src/attributes.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Reports whether writing `value` to the attribute `name` would run script: the URL check that
|
|
4
3
|
* {@link setAttribute}, the head registry and the server renderer share. Use it in a custom renderer
|
|
5
4
|
* before writing a URL that came from user data. URL attributes (`href`, `src`, `action`,
|
|
6
|
-
* `formaction`, `xlink:href`, `
|
|
5
|
+
* `formaction`, `xlink:href`, `poster`, `data`) are unsafe when, after removing control
|
|
7
6
|
* characters, trimming and lowercasing, they start with `javascript:`, `data:text/html` or
|
|
8
7
|
* `vbscript:`. The SVG animation attributes `values`, `from`, `to` and `by` are checked the same way,
|
|
9
|
-
* each `;`-separated entry of `values` on its own.
|
|
8
|
+
* each `;`-separated entry of `values` on its own. `srcdoc` is not a URL but an HTML document, with the
|
|
9
|
+
* trust of `innerHTML`: no scheme check applies to it, so this returns `false` for it (see {@link setAttribute}).
|
|
10
10
|
*
|
|
11
11
|
* @param name Attribute name, in any case.
|
|
12
12
|
* @param value The text that would be written.
|
|
@@ -25,7 +25,13 @@ export declare function isUnsafeUrlAttribute(name: string, value: string): boole
|
|
|
25
25
|
* Sets or removes one attribute with the JSX value rules: the helper compiled templates call for a
|
|
26
26
|
* dynamic attribute, also usable on elements you create yourself. The DOM is touched only when the
|
|
27
27
|
* text changes. A URL attribute whose value would run script (see {@link isUnsafeUrlAttribute}) is
|
|
28
|
-
* left unchanged, and development builds warn once with `UNSAFE_URL_BLOCKED`.
|
|
28
|
+
* left unchanged, and development builds warn once with `UNSAFE_URL_BLOCKED`. Names that start with
|
|
29
|
+
* `on` (`onclick`, ...) are never written, only removed: handlers are bound with `addEventListener`.
|
|
30
|
+
*
|
|
31
|
+
* `srcdoc` is an HTML sink: the value is a document the frame runs, written as it is and trusted like
|
|
32
|
+
* `innerHTML`. Sanitize it, and give the frame a `sandbox` attribute. Compiled templates call this for a
|
|
33
|
+
* computed value only (a literal `srcdoc` is part of the template), so development builds warn once with
|
|
34
|
+
* `SRCDOC_DYNAMIC` for every value written here.
|
|
29
35
|
*
|
|
30
36
|
* @param el Target element.
|
|
31
37
|
* @param name Attribute name. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.
|
|
@@ -86,5 +92,4 @@ export declare function setAttributeNS(el: Element, namespace: string, name: str
|
|
|
86
92
|
* @since 1.0.0
|
|
87
93
|
*/
|
|
88
94
|
export declare function setBoolAttribute(el: Element, name: string, value: unknown): void;
|
|
89
|
-
//#endregion
|
|
90
95
|
//# sourceMappingURL=attributes.d.ts.map
|
package/dist/dev/attributes.js
CHANGED
|
@@ -1,37 +1,19 @@
|
|
|
1
|
-
import { invalidAttributeName, warnOnce } from "./internal/diagnostics.js";
|
|
2
|
-
|
|
1
|
+
import { SRCDOC_DYNAMIC_DETAIL, invalidAttributeName, warnOnce } from "./internal/diagnostics.js";
|
|
2
|
+
// src/attributes.ts
|
|
3
3
|
/** Names that can appear in markup: an XML-name subset without `@` or whitespace. */
|
|
4
4
|
const ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_:.-]*$/;
|
|
5
5
|
/**
|
|
6
6
|
* Attributes whose value is a URL and therefore checked for script schemes. The SVG animation values
|
|
7
7
|
* (`animate`, `set`) are checked too: with `attributeName="href"` they write an `href` by animation.
|
|
8
8
|
*/
|
|
9
|
-
const URL_ATTRIBUTES =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
]);
|
|
9
|
+
const URL_ATTRIBUTES = /^(?:href|src|action|formaction|xlink:href|poster|data|values|from|to|by)$/;
|
|
10
|
+
/**
|
|
11
|
+
* `aria-*`, `data-*` and the enumerated attributes: their boolean values are the strings "true" and "false"
|
|
12
|
+
* rather than a present or absent attribute.
|
|
13
|
+
*/
|
|
14
|
+
const STRING_VALUED = /^(?:aria-|data-|draggable$|spellcheck$|contenteditable$)/;
|
|
29
15
|
/** URL prefixes (after normalization) that are never written. */
|
|
30
|
-
const UNSAFE_URL_PREFIXES =
|
|
31
|
-
"javascript:",
|
|
32
|
-
"data:text/html",
|
|
33
|
-
"vbscript:"
|
|
34
|
-
];
|
|
16
|
+
const UNSAFE_URL_PREFIXES = /^(?:javascript:|data:text\/html|vbscript:)/;
|
|
35
17
|
/**
|
|
36
18
|
* Throws a TypeError unless `name` is a valid attribute name. Runs for every name, including the
|
|
37
19
|
* ones that come from spread, so no unvalidated name reaches `setAttribute`.
|
|
@@ -40,32 +22,23 @@ const UNSAFE_URL_PREFIXES = [
|
|
|
40
22
|
function assertAttributeName(name) {
|
|
41
23
|
if (!ATTRIBUTE_NAME.test(name)) throw invalidAttributeName(name);
|
|
42
24
|
}
|
|
43
|
-
/**
|
|
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. */
|
|
25
|
+
/** Removes C0 and C1 control characters (`\p{Cc}`), which browsers ignore inside a URL scheme. */
|
|
48
26
|
function stripControls(text) {
|
|
49
|
-
|
|
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;
|
|
27
|
+
return text.replace(/\p{Cc}/gu, "");
|
|
55
28
|
}
|
|
56
29
|
/** True when the URL would run script: browsers ignore the controls and case that hide the scheme. */
|
|
57
30
|
function isUnsafeUrl(value) {
|
|
58
|
-
|
|
59
|
-
return UNSAFE_URL_PREFIXES.some((prefix) => normalized.startsWith(prefix));
|
|
31
|
+
return UNSAFE_URL_PREFIXES.test(stripControls(value).trim().toLowerCase());
|
|
60
32
|
}
|
|
61
33
|
/**
|
|
62
34
|
* Reports whether writing `value` to the attribute `name` would run script: the URL check that
|
|
63
35
|
* {@link setAttribute}, the head registry and the server renderer share. Use it in a custom renderer
|
|
64
36
|
* before writing a URL that came from user data. URL attributes (`href`, `src`, `action`,
|
|
65
|
-
* `formaction`, `xlink:href`, `
|
|
37
|
+
* `formaction`, `xlink:href`, `poster`, `data`) are unsafe when, after removing control
|
|
66
38
|
* characters, trimming and lowercasing, they start with `javascript:`, `data:text/html` or
|
|
67
39
|
* `vbscript:`. The SVG animation attributes `values`, `from`, `to` and `by` are checked the same way,
|
|
68
|
-
* each `;`-separated entry of `values` on its own.
|
|
40
|
+
* each `;`-separated entry of `values` on its own. `srcdoc` is not a URL but an HTML document, with the
|
|
41
|
+
* trust of `innerHTML`: no scheme check applies to it, so this returns `false` for it (see {@link setAttribute}).
|
|
69
42
|
*
|
|
70
43
|
* @param name Attribute name, in any case.
|
|
71
44
|
* @param value The text that would be written.
|
|
@@ -81,14 +54,14 @@ function isUnsafeUrl(value) {
|
|
|
81
54
|
*/
|
|
82
55
|
function isUnsafeUrlAttribute(name, value) {
|
|
83
56
|
const lowerName = name.toLowerCase();
|
|
84
|
-
if (!URL_ATTRIBUTES.
|
|
57
|
+
if (!URL_ATTRIBUTES.test(lowerName)) return false;
|
|
85
58
|
return lowerName === "values" ? value.split(";").some(isUnsafeUrl) : isUnsafeUrl(value);
|
|
86
59
|
}
|
|
87
60
|
/** Text to write for `value`, or null when the attribute must be removed. */
|
|
88
61
|
function attributeText(lowerName, value) {
|
|
89
62
|
if (value === null || value === void 0) return null;
|
|
90
|
-
if (value === false) return
|
|
91
|
-
if (value === true) return
|
|
63
|
+
if (value === false) return STRING_VALUED.test(lowerName) ? "false" : null;
|
|
64
|
+
if (value === true) return STRING_VALUED.test(lowerName) ? "true" : "";
|
|
92
65
|
return String(value);
|
|
93
66
|
}
|
|
94
67
|
/** The part of a qualified name after the prefix (`xlink:href` gives `href`). */
|
|
@@ -105,6 +78,8 @@ function commit(el, namespace, qualified, value) {
|
|
|
105
78
|
else el.removeAttributeNS(namespace, localPart(qualified));
|
|
106
79
|
return;
|
|
107
80
|
}
|
|
81
|
+
if (/^on./.test(lowerName)) return;
|
|
82
|
+
if (lowerName === "srcdoc") warnOnce("SRCDOC_DYNAMIC", SRCDOC_DYNAMIC_DETAIL);
|
|
108
83
|
if (isUnsafeUrlAttribute(lowerName, text)) {
|
|
109
84
|
warnOnce("UNSAFE_URL_BLOCKED", `Blocked a script URL in the "${qualified}" attribute.`);
|
|
110
85
|
return;
|
|
@@ -117,7 +92,13 @@ function commit(el, namespace, qualified, value) {
|
|
|
117
92
|
* Sets or removes one attribute with the JSX value rules: the helper compiled templates call for a
|
|
118
93
|
* dynamic attribute, also usable on elements you create yourself. The DOM is touched only when the
|
|
119
94
|
* 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`.
|
|
95
|
+
* left unchanged, and development builds warn once with `UNSAFE_URL_BLOCKED`. Names that start with
|
|
96
|
+
* `on` (`onclick`, ...) are never written, only removed: handlers are bound with `addEventListener`.
|
|
97
|
+
*
|
|
98
|
+
* `srcdoc` is an HTML sink: the value is a document the frame runs, written as it is and trusted like
|
|
99
|
+
* `innerHTML`. Sanitize it, and give the frame a `sandbox` attribute. Compiled templates call this for a
|
|
100
|
+
* computed value only (a literal `srcdoc` is part of the template), so development builds warn once with
|
|
101
|
+
* `SRCDOC_DYNAMIC` for every value written here.
|
|
121
102
|
*
|
|
122
103
|
* @param el Target element.
|
|
123
104
|
* @param name Attribute name. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.
|
|
@@ -185,12 +166,8 @@ function setAttributeNS(el, namespace, name, value) {
|
|
|
185
166
|
*/
|
|
186
167
|
function setBoolAttribute(el, name, value) {
|
|
187
168
|
assertAttributeName(name);
|
|
188
|
-
|
|
189
|
-
if (value) {
|
|
190
|
-
if (!present) el.setAttribute(name, "");
|
|
191
|
-
} else if (present) el.removeAttribute(name);
|
|
169
|
+
el.toggleAttribute(name, Boolean(value));
|
|
192
170
|
}
|
|
193
|
-
//#endregion
|
|
194
171
|
export { assertAttributeName, isUnsafeUrlAttribute, setAttribute, setAttributeNS, setBoolAttribute };
|
|
195
172
|
|
|
196
173
|
//# sourceMappingURL=attributes.js.map
|
|
@@ -1 +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,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;;;;;;;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"}
|
|
1
|
+
{"version":3,"file":"attributes.js","names":[],"sources":["../../src/attributes.ts"],"sourcesContent":["import { invalidAttributeName, SRCDOC_DYNAMIC_DETAIL, 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 = /^(?:href|src|action|formaction|xlink:href|poster|data|values|from|to|by)$/;\n\n/**\n * `aria-*`, `data-*` and the enumerated attributes: their boolean values are the strings \"true\" and \"false\"\n * rather than a present or absent attribute.\n */\nconst STRING_VALUED = /^(?:aria-|data-|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/** Removes C0 and C1 control characters (`\\p{Cc}`), which browsers ignore inside a URL scheme. */\nfunction stripControls(text: string): string {\n return text.replace(/\\p{Cc}/gu, \"\");\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 return UNSAFE_URL_PREFIXES.test(stripControls(value).trim().toLowerCase());\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`, `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. `srcdoc` is not a URL but an HTML document, with the\n * trust of `innerHTML`: no scheme check applies to it, so this returns `false` for it (see {@link setAttribute}).\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.test(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 STRING_VALUED.test(lowerName) ? \"false\" : null;\n if (value === true) return STRING_VALUED.test(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 // Event handlers are bound as functions, never written as attributes: a string there is script the\n // page would run. The server drops the same names, so both renders agree.\n if (/^on./.test(lowerName)) return;\n if (__DEV__ && lowerName === \"srcdoc\") warnOnce(\"SRCDOC_DYNAMIC\", SRCDOC_DYNAMIC_DETAIL);\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`. Names that start with\n * `on` (`onclick`, ...) are never written, only removed: handlers are bound with `addEventListener`.\n *\n * `srcdoc` is an HTML sink: the value is a document the frame runs, written as it is and trusted like\n * `innerHTML`. Sanitize it, and give the frame a `sandbox` attribute. Compiled templates call this for a\n * computed value only (a literal `srcdoc` is part of the template), so development builds warn once with\n * `SRCDOC_DYNAMIC` for every value written here.\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 el.toggleAttribute(name, Boolean(value));\n}\n"],"mappings":";;;AAGA,MAAM,iBAAiB;;;;;AAMvB,MAAM,iBAAiB;;;;;AAMvB,MAAM,gBAAgB;;AAGtB,MAAM,sBAAsB;;;;;;AAO5B,SAAgB,oBAAoB,MAAoB;CACtD,IAAI,CAAC,eAAe,KAAK,IAAI,GAAG,MAAM,qBAAqB,IAAI;AACjE;;AAGA,SAAS,cAAc,MAAsB;CAC3C,OAAO,KAAK,QAAQ,YAAY,EAAE;AACpC;;AAGA,SAAS,YAAY,OAAwB;CAC3C,OAAO,oBAAoB,KAAK,cAAc,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC;AAC3E;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,qBAAqB,MAAc,OAAwB;CACzE,MAAM,YAAY,KAAK,YAAY;CACnC,IAAI,CAAC,eAAe,KAAK,SAAS,GAAG,OAAO;CAE5C,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,cAAc,KAAK,SAAS,IAAI,UAAU;CACtE,IAAI,UAAU,MAAM,OAAO,cAAc,KAAK,SAAS,IAAI,SAAS;CACpE,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;CAGA,IAAI,OAAO,KAAK,SAAS,GAAG;CAC5B,IAAe,cAAc,UAAU,SAAS,kBAAkB,qBAAqB;CACvF,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,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,GAAG,gBAAgB,MAAM,QAAQ,KAAK,CAAC;AACzC"}
|
package/dist/dev/autofocus.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/autofocus.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Focuses an element written with `autoFocus` (React parity) once it is inserted into the document
|
|
4
3
|
* by a client render or update. The compiler calls this for an `autoFocus` attribute and for
|
|
@@ -28,5 +27,4 @@
|
|
|
28
27
|
* @since 1.0.0
|
|
29
28
|
*/
|
|
30
29
|
export declare function autoFocus(el: Element, enabled: unknown): void;
|
|
31
|
-
//#endregion
|
|
32
30
|
//# sourceMappingURL=autofocus.d.ts.map
|
package/dist/dev/autofocus.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { onMount } from "@shadow-js/core";
|
|
2
2
|
import { isHydrating } from "@shadow-js/core/extend";
|
|
3
|
-
|
|
3
|
+
// src/autofocus.ts
|
|
4
4
|
/**
|
|
5
5
|
* Focuses an element written with `autoFocus` (React parity) once it is inserted into the document
|
|
6
6
|
* by a client render or update. The compiler calls this for an `autoFocus` attribute and for
|
|
@@ -39,7 +39,6 @@ function autoFocus(el, enabled) {
|
|
|
39
39
|
if (el.isConnected && free && (el instanceof HTMLElement || el instanceof SVGElement)) el.focus();
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
//#endregion
|
|
43
42
|
export { autoFocus };
|
|
44
43
|
|
|
45
44
|
//# sourceMappingURL=autofocus.js.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/class-style.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Replaces the whole `class` of an element: the helper compiled templates call for `class` and
|
|
4
3
|
* `className`. HTML elements are written through `className`; SVG and MathML elements (whose
|
|
@@ -70,11 +69,15 @@ export declare function setStyleProperty(el: HTMLElement | SVGElement, name: str
|
|
|
70
69
|
*
|
|
71
70
|
* @param el HTML or SVG element.
|
|
72
71
|
* @param value An object of properties (camelCase, kebab-case or custom names). A string replaces
|
|
73
|
-
* `cssText`. `null`, `undefined
|
|
72
|
+
* `cssText`. An array of strings and objects (not nested; `null`, `undefined`, `false` and `""`
|
|
73
|
+
* items are skipped) is written in order, so a later declaration wins, exactly as `ssrStyle` writes it
|
|
74
|
+
* on the server. `null`, `undefined` and `false` remove the `style` attribute.
|
|
74
75
|
* @param prev The value returned by the previous call. Undefined (the first call) diffs against an
|
|
75
|
-
* empty style. When it is a string, `cssText` is cleared before the object is written.
|
|
76
|
+
* empty style. When it is a string or an array, `cssText` is cleared before the object is written.
|
|
76
77
|
* @returns What to pass back as `prev` next time: a shallow copy of an object value, otherwise
|
|
77
78
|
* `value` itself.
|
|
79
|
+
* @throws TypeError (production message `SHADOW_STYLE_ITEM`) when an array holds a nested array or a
|
|
80
|
+
* value that is not a string or an object.
|
|
78
81
|
* @example
|
|
79
82
|
* import { style } from "@shadow-js/web";
|
|
80
83
|
*
|
|
@@ -85,5 +88,4 @@ export declare function setStyleProperty(el: HTMLElement | SVGElement, name: str
|
|
|
85
88
|
* @since 1.0.0
|
|
86
89
|
*/
|
|
87
90
|
export declare function style(el: HTMLElement | SVGElement, value: unknown, prev?: unknown): unknown;
|
|
88
|
-
//#endregion
|
|
89
91
|
//# sourceMappingURL=class-style.d.ts.map
|
package/dist/dev/class-style.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cssValueText } from "./internal/css-units.js";
|
|
2
2
|
import { HTML_NS } from "./internal/names.js";
|
|
3
|
-
|
|
3
|
+
// src/class-style.ts
|
|
4
4
|
/** Appends the truthy class names of `value` (strings, numbers, nested arrays, objects) to `parts`. */
|
|
5
5
|
function collectClasses(root, parts) {
|
|
6
6
|
const frames = [[root]];
|
|
@@ -80,11 +80,15 @@ function applyClass(el, value, svg) {
|
|
|
80
80
|
function className(el, value) {
|
|
81
81
|
applyClass(el, value, el.namespaceURI !== HTML_NS);
|
|
82
82
|
}
|
|
83
|
-
/** Narrows an object value to a record of keys; arrays and primitives are not class maps. */
|
|
83
|
+
/** Narrows an object value to a record of keys; arrays and primitives are not class maps. @internal */
|
|
84
84
|
function asRecord(value) {
|
|
85
85
|
if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
86
86
|
return value;
|
|
87
87
|
}
|
|
88
|
+
/** Whether `key` is switched on in `map`: own properties only, so a key named `constructor` reads as it was written. */
|
|
89
|
+
function enabled(map, key) {
|
|
90
|
+
return Object.hasOwn(map, key) && Boolean(map[key]);
|
|
91
|
+
}
|
|
88
92
|
/**
|
|
89
93
|
* Toggles individual classes from an object: the helper compiled templates call for `classList`.
|
|
90
94
|
* Unlike {@link className}, it leaves classes it did not set alone: only keys whose truthiness
|
|
@@ -110,8 +114,8 @@ function classList(el, value, prev) {
|
|
|
110
114
|
const before = prev ?? {};
|
|
111
115
|
const keys = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(next)]);
|
|
112
116
|
for (const key of keys) {
|
|
113
|
-
const now =
|
|
114
|
-
if (now ===
|
|
117
|
+
const now = enabled(next, key);
|
|
118
|
+
if (now === enabled(before, key)) continue;
|
|
115
119
|
for (const token of key.split(/\s+/)) if (token !== "") el.classList.toggle(token, now);
|
|
116
120
|
}
|
|
117
121
|
return next;
|
|
@@ -158,11 +162,15 @@ function setStyleProperty(el, name, value) {
|
|
|
158
162
|
*
|
|
159
163
|
* @param el HTML or SVG element.
|
|
160
164
|
* @param value An object of properties (camelCase, kebab-case or custom names). A string replaces
|
|
161
|
-
* `cssText`. `null`, `undefined
|
|
165
|
+
* `cssText`. An array of strings and objects (not nested; `null`, `undefined`, `false` and `""`
|
|
166
|
+
* items are skipped) is written in order, so a later declaration wins, exactly as `ssrStyle` writes it
|
|
167
|
+
* on the server. `null`, `undefined` and `false` remove the `style` attribute.
|
|
162
168
|
* @param prev The value returned by the previous call. Undefined (the first call) diffs against an
|
|
163
|
-
* empty style. When it is a string, `cssText` is cleared before the object is written.
|
|
169
|
+
* empty style. When it is a string or an array, `cssText` is cleared before the object is written.
|
|
164
170
|
* @returns What to pass back as `prev` next time: a shallow copy of an object value, otherwise
|
|
165
171
|
* `value` itself.
|
|
172
|
+
* @throws TypeError (production message `SHADOW_STYLE_ITEM`) when an array holds a nested array or a
|
|
173
|
+
* value that is not a string or an object.
|
|
166
174
|
* @example
|
|
167
175
|
* import { style } from "@shadow-js/web";
|
|
168
176
|
*
|
|
@@ -181,9 +189,18 @@ function style(el, value, prev) {
|
|
|
181
189
|
el.style.cssText = String(value);
|
|
182
190
|
return value;
|
|
183
191
|
}
|
|
192
|
+
if (Array.isArray(value)) {
|
|
193
|
+
el.style.cssText = "";
|
|
194
|
+
for (const item of value) if (typeof item === "string") el.style.cssText += `;${item}`;
|
|
195
|
+
else if (item !== null && item !== void 0 && item !== false) {
|
|
196
|
+
if (typeof item !== "object" || Array.isArray(item)) throw new TypeError("style(): an array holds only strings and objects.");
|
|
197
|
+
style(el, item, {});
|
|
198
|
+
}
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
184
201
|
const next = { ...value };
|
|
185
202
|
const before = asRecord(prev) ?? {};
|
|
186
|
-
if (typeof prev === "string") el.style.cssText = "";
|
|
203
|
+
if (typeof prev === "string" || Array.isArray(prev)) el.style.cssText = "";
|
|
187
204
|
const keys = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(next)]);
|
|
188
205
|
for (const key of keys) {
|
|
189
206
|
if (Object.is(before[key], next[key])) continue;
|
|
@@ -191,7 +208,6 @@ function style(el, value, prev) {
|
|
|
191
208
|
}
|
|
192
209
|
return next;
|
|
193
210
|
}
|
|
194
|
-
|
|
195
|
-
export { applyClass, classList, className, setStyleProperty, style, toCssProperty };
|
|
211
|
+
export { applyClass, asRecord, classList, className, setStyleProperty, style, toCssProperty };
|
|
196
212
|
|
|
197
213
|
//# sourceMappingURL=class-style.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-style.js","names":[],"sources":["../../src/class-style.ts"],"sourcesContent":["import { cssValueText } from \"./internal/css-units\";\nimport { HTML_NS } from \"./internal/names\";\n\n/** Appends the truthy class names of `value` (strings, numbers, nested arrays, objects) to `parts`. */\nfunction collectClasses(root: unknown, parts: string[]): void {\n // Explicit frames instead of recursion: array nesting depth is controlled by the user.\n const frames: unknown[][] = [[root]];\n const cursors: number[] = [0];\n const active = new Set<unknown[]>();\n while (frames.length > 0) {\n const top = frames.length - 1;\n const frame = frames[top];\n const cursor = cursors[top] ?? 0;\n if (frame === undefined || cursor >= frame.length) {\n const done = frames.pop();\n if (done !== undefined) active.delete(done);\n cursors.pop();\n continue;\n }\n cursors[top] = cursor + 1;\n const item = frame[cursor];\n if (Array.isArray(item)) {\n if (active.has(item))\n throw new TypeError(\n __DEV__ ? \"className(): a class array contains itself.\" : \"SHADOW_CLASS_CYCLE\",\n );\n active.add(item);\n frames.push(item);\n cursors.push(0);\n } else if (typeof item === \"string\") {\n if (item !== \"\") parts.push(item);\n } else if (typeof item === \"number\") {\n if (item !== 0 && !Number.isNaN(item)) parts.push(String(item));\n } else if (item !== null && typeof item === \"object\") {\n const record = item as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n if (record[key] && key !== \"\") parts.push(key);\n }\n }\n }\n}\n\n/** Class text for `value`, or null when the class attribute must be removed. */\nfunction classText(value: unknown): string | null {\n if (typeof value === \"string\") return value;\n if (value === null || value === undefined || value === false) return null;\n const parts: string[] = [];\n collectClasses(value, parts);\n return parts.join(\" \");\n}\n\n/**\n * Writes a class value. `svg` selects the attribute path, which SVG and MathML need because their\n * `className` is not a plain string.\n * @internal\n */\nexport function applyClass(el: Element, value: unknown, svg: boolean): void {\n const text = classText(value);\n if (text === null) {\n el.removeAttribute(\"class\");\n return;\n }\n if (svg) {\n if (el.getAttribute(\"class\") !== text) el.setAttribute(\"class\", text);\n } else if (el.className !== text) {\n el.className = text;\n }\n}\n\n/**\n * Replaces the whole `class` of an element: the helper compiled templates call for `class` and\n * `className`. HTML elements are written through `className`; SVG and MathML elements (whose\n * `className` is not a plain string) through the `class` attribute. The DOM is touched only when\n * the text changes.\n *\n * @param el Target element.\n * @param value A string is used as is. Arrays and objects are clsx-style: non-empty strings,\n * numbers other than `0` and `NaN`, nested arrays, and the keys of objects whose value is truthy,\n * joined with spaces. `null`, `undefined` and `false` remove the attribute.\n * @throws TypeError `SHADOW_CLASS_CYCLE` when an array contains itself (directly or through a nested\n * array).\n * @example\n * import { className } from \"@shadow-js/web\";\n *\n * const card = document.createElement(\"div\");\n * className(card, [\"card\", { \"card--active\": true, \"card--muted\": false }]);\n * card.className; // \"card card--active\"\n * @see classList\n * @since 1.0.0\n */\nexport function className(el: Element, value: unknown): void {\n applyClass(el, value, el.namespaceURI !== HTML_NS);\n}\n\n/** Narrows an object value to a record of keys; arrays and primitives are not class maps. */\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n return value as Record<string, unknown>;\n}\n\n/**\n * Toggles individual classes from an object: the helper compiled templates call for `classList`.\n * Unlike {@link className}, it leaves classes it did not set alone: only keys whose truthiness\n * changed relative to `prev` are touched. A key may hold several space-separated names. Keys that\n * disappeared from `value` are switched off.\n *\n * @param el Target element.\n * @param value Map from class names to truthiness. `undefined` switches off every class `prev` had on.\n * @param prev The map returned by the previous call. Undefined (the first call) means no class was\n * on yet.\n * @returns The map now in effect (`value`, or `{}` for undefined), to pass back as `prev` next time.\n * @example\n * import { classList } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"li\");\n * let prev = classList(el, { active: true, \"is-new pulse\": true });\n * prev = classList(el, { active: false }, prev); // removes active, is-new and pulse\n * @see className\n * @since 1.0.0\n */\nexport function classList(\n el: Element,\n value: Record<string, unknown> | undefined,\n prev?: Record<string, unknown>,\n): Record<string, unknown> {\n const next: Record<string, unknown> = value ?? {};\n const before: Record<string, unknown> = prev ?? {};\n const keys = new Set([...Object.keys(before), ...Object.keys(next)]);\n for (const key of keys) {\n const now = Boolean(next[key]);\n const was = Boolean(before[key]);\n if (now === was) continue;\n for (const token of key.split(/\\s+/)) {\n if (token !== \"\") el.classList.toggle(token, now);\n }\n }\n return next;\n}\n\n/**\n * Converts a camelCase style name to a CSS property name. Custom properties are kept as they are,\n * and vendor prefixes map to `-webkit-` and `-ms-`.\n * @internal\n */\nexport function toCssProperty(name: string): string {\n if (name.startsWith(\"--\")) return name;\n const kebab = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n return kebab.startsWith(\"ms-\") ? `-${kebab}` : kebab;\n}\n\n/**\n * Sets or removes one inline style property: the helper compiled templates call for the `style:`\n * prefix. Other inline properties are left alone.\n *\n * @param el HTML or SVG element.\n * @param name CSS property in camelCase (`backgroundColor`, `msTransform` gives `-ms-transform`) or\n * kebab-case, or a custom property (`--accent`, kept as is).\n * @param value `null`, `undefined` and `false` remove the property. A number is in pixels, as in\n * React, unless it is `0`, the property is unitless (`opacity`, `zIndex`, `flexGrow`, `lineHeight`,\n * ...) or a custom property. Any other value is written as `String(value)`.\n * @example\n * import { setStyleProperty } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"div\");\n * setStyleProperty(el, \"marginTop\", 8); // margin-top: 8px\n * setStyleProperty(el, \"--accent\", \"rebeccapurple\");\n * setStyleProperty(el, \"opacity\", 0.5); // unitless\n * @see style\n * @since 1.0.0\n */\nexport function setStyleProperty(el: HTMLElement | SVGElement, name: string, value: unknown): void {\n const property = toCssProperty(name);\n if (value === null || value === undefined || value === false) {\n el.style.removeProperty(property);\n } else {\n el.style.setProperty(property, cssValueText(property, value));\n }\n}\n\n/**\n * Sets the inline style of an element: the helper compiled templates call for a `style` attribute.\n * An object is diffed against `prev` so that only changed properties are written, each with the\n * rules of {@link setStyleProperty}; properties that disappeared are removed.\n *\n * @param el HTML or SVG element.\n * @param value An object of properties (camelCase, kebab-case or custom names). A string replaces\n * `cssText`. `null`, `undefined` and `false` remove the `style` attribute.\n * @param prev The value returned by the previous call. Undefined (the first call) diffs against an\n * empty style. When it is a string, `cssText` is cleared before the object is written.\n * @returns What to pass back as `prev` next time: a shallow copy of an object value, otherwise\n * `value` itself.\n * @example\n * import { style } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"div\");\n * let prev = style(el, { color: \"red\", width: 120 }); // width: 120px\n * prev = style(el, { color: \"blue\" }, prev); // writes color, removes width\n * @see setStyleProperty\n * @since 1.0.0\n */\nexport function style(el: HTMLElement | SVGElement, value: unknown, prev?: unknown): unknown {\n if (value === null || value === undefined || value === false) {\n el.removeAttribute(\"style\");\n return value;\n }\n if (typeof value !== \"object\") {\n el.style.cssText = String(value);\n return value;\n }\n const next = { ...(value as Record<string, unknown>) };\n const before = asRecord(prev) ?? {};\n if (typeof prev === \"string\") el.style.cssText = \"\";\n const keys = new Set([...Object.keys(before), ...Object.keys(next)]);\n for (const key of keys) {\n if (Object.is(before[key], next[key])) continue;\n setStyleProperty(el, key, next[key]);\n }\n return next;\n}\n"],"mappings":";;;;AAIA,SAAS,eAAe,MAAe,OAAuB;CAE5D,MAAM,SAAsB,CAAC,CAAC,IAAI,CAAC;CACnC,MAAM,UAAoB,CAAC,CAAC;CAC5B,MAAM,yBAAS,IAAI,IAAe;CAClC,OAAO,OAAO,SAAS,GAAG;EACxB,MAAM,MAAM,OAAO,SAAS;EAC5B,MAAM,QAAQ,OAAO;EACrB,MAAM,SAAS,QAAQ,QAAQ;EAC/B,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM,QAAQ;GACjD,MAAM,OAAO,OAAO,IAAI;GACxB,IAAI,SAAS,KAAA,GAAW,OAAO,OAAO,IAAI;GAC1C,QAAQ,IAAI;GACZ;EACF;EACA,QAAQ,OAAO,SAAS;EACxB,MAAM,OAAO,MAAM;EACnB,IAAI,MAAM,QAAQ,IAAI,GAAG;GACvB,IAAI,OAAO,IAAI,IAAI,GACjB,MAAM,IAAI,UACE,6CACZ;GACF,OAAO,IAAI,IAAI;GACf,OAAO,KAAK,IAAI;GAChB,QAAQ,KAAK,CAAC;EAChB,OAAO,IAAI,OAAO,SAAS,UACrB;OAAA,SAAS,IAAI,MAAM,KAAK,IAAI;EAAA,OAC3B,IAAI,OAAO,SAAS,UACrB;OAAA,SAAS,KAAK,CAAC,OAAO,MAAM,IAAI,GAAG,MAAM,KAAK,OAAO,IAAI,CAAC;EAAA,OACzD,IAAI,SAAS,QAAQ,OAAO,SAAS,UAAU;GACpD,MAAM,SAAS;GACf,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,GAClC,IAAI,OAAO,QAAQ,Q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A,SAAgB,cAAc,MAAsB;CAClD,IAAI,KAAK,WAAW,IAAI,GAAG,OAAO;CAClC,MAAM,QAAQ,KAAK,QAAQ,WAAW,WAAW,IAAI,OAAO,YAAY,GAAG;CAC3E,OAAO,MAAM,WAAW,KAAK,IAAI,IAAI,UAAU;AACjD;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,iBAAiB,IAA8B,MAAc,OAAsB;CACjG,MAAM,WAAW,cAAc,IAAI;CACnC,IAAI,UAAU,QAAQ,UAAU,KAAA,KAAa,UAAU,OACrD,GAAG,MAAM,eAAe,QAAQ;MAEhC,GAAG,MAAM,YAAY,UAAU,aAAa,UAAU,KAAK,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,MAAM,IAA8B,OAAgB,MAAyB;CAC3F,IAAI,UAAU,QAAQ,UAAU,KAAA,KAAa,UAAU,OAAO;EAC5D,GAAG,gBAAgB,OAAO;EAC1B,OAAO;CACT;CACA,IAAI,OAAO,UAAU,UAAU;EAC7B,GAAG,MAAM,UAAU,OAAO,KAAK;EAC/B,OAAO;CACT;CACA,MAAM,OAAO,EAAE,GAAI,MAAkC;CACrD,MAAM,SAAS,SAAS,IAAI,KAAK,CAAC;CAClC,IAAI,OAAO,SAAS,UAAU,GAAG,MAAM,UAAU;CACjD,MAAM,uBAAO,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,MAAM,GAAG,GAAG,OAAO,KAAK,IAAI,CAAC,CAAC;CACnE,KAAK,MAAM,OAAO,MAAM;EACtB,IAAI,OAAO,GAAG,OAAO,MAAM,KAAK,IAAI,GAAG;EACvC,iBAAiB,IAAI,KAAK,KAAK,IAAI;CACrC;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"class-style.js","names":[],"sources":["../../src/class-style.ts"],"sourcesContent":["import { cssValueText } from \"./internal/css-units\";\nimport { HTML_NS } from \"./internal/names\";\n\n/** Appends the truthy class names of `value` (strings, numbers, nested arrays, objects) to `parts`. */\nfunction collectClasses(root: unknown, parts: string[]): void {\n // Explicit frames instead of recursion: array nesting depth is controlled by the user.\n const frames: unknown[][] = [[root]];\n const cursors: number[] = [0];\n const active = new Set<unknown[]>();\n while (frames.length > 0) {\n const top = frames.length - 1;\n const frame = frames[top];\n const cursor = cursors[top] ?? 0;\n if (frame === undefined || cursor >= frame.length) {\n const done = frames.pop();\n if (done !== undefined) active.delete(done);\n cursors.pop();\n continue;\n }\n cursors[top] = cursor + 1;\n const item = frame[cursor];\n if (Array.isArray(item)) {\n if (active.has(item))\n throw new TypeError(\n __DEV__ ? \"className(): a class array contains itself.\" : \"SHADOW_CLASS_CYCLE\",\n );\n active.add(item);\n frames.push(item);\n cursors.push(0);\n } else if (typeof item === \"string\") {\n if (item !== \"\") parts.push(item);\n } else if (typeof item === \"number\") {\n if (item !== 0 && !Number.isNaN(item)) parts.push(String(item));\n } else if (item !== null && typeof item === \"object\") {\n const record = item as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n if (record[key] && key !== \"\") parts.push(key);\n }\n }\n }\n}\n\n/** Class text for `value`, or null when the class attribute must be removed. */\nfunction classText(value: unknown): string | null {\n if (typeof value === \"string\") return value;\n if (value === null || value === undefined || value === false) return null;\n const parts: string[] = [];\n collectClasses(value, parts);\n return parts.join(\" \");\n}\n\n/**\n * Writes a class value. `svg` selects the attribute path, which SVG and MathML need because their\n * `className` is not a plain string.\n * @internal\n */\nexport function applyClass(el: Element, value: unknown, svg: boolean): void {\n const text = classText(value);\n if (text === null) {\n el.removeAttribute(\"class\");\n return;\n }\n if (svg) {\n if (el.getAttribute(\"class\") !== text) el.setAttribute(\"class\", text);\n } else if (el.className !== text) {\n el.className = text;\n }\n}\n\n/**\n * Replaces the whole `class` of an element: the helper compiled templates call for `class` and\n * `className`. HTML elements are written through `className`; SVG and MathML elements (whose\n * `className` is not a plain string) through the `class` attribute. The DOM is touched only when\n * the text changes.\n *\n * @param el Target element.\n * @param value A string is used as is. Arrays and objects are clsx-style: non-empty strings,\n * numbers other than `0` and `NaN`, nested arrays, and the keys of objects whose value is truthy,\n * joined with spaces. `null`, `undefined` and `false` remove the attribute.\n * @throws TypeError `SHADOW_CLASS_CYCLE` when an array contains itself (directly or through a nested\n * array).\n * @example\n * import { className } from \"@shadow-js/web\";\n *\n * const card = document.createElement(\"div\");\n * className(card, [\"card\", { \"card--active\": true, \"card--muted\": false }]);\n * card.className; // \"card card--active\"\n * @see classList\n * @since 1.0.0\n */\nexport function className(el: Element, value: unknown): void {\n applyClass(el, value, el.namespaceURI !== HTML_NS);\n}\n\n/** Narrows an object value to a record of keys; arrays and primitives are not class maps. @internal */\nexport function asRecord(value: unknown): Record<string, unknown> | undefined {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n return value as Record<string, unknown>;\n}\n\n/** Whether `key` is switched on in `map`: own properties only, so a key named `constructor` reads as it was written. */\nfunction enabled(map: Record<string, unknown>, key: string): boolean {\n return Object.hasOwn(map, key) && Boolean(map[key]);\n}\n\n/**\n * Toggles individual classes from an object: the helper compiled templates call for `classList`.\n * Unlike {@link className}, it leaves classes it did not set alone: only keys whose truthiness\n * changed relative to `prev` are touched. A key may hold several space-separated names. Keys that\n * disappeared from `value` are switched off.\n *\n * @param el Target element.\n * @param value Map from class names to truthiness. `undefined` switches off every class `prev` had on.\n * @param prev The map returned by the previous call. Undefined (the first call) means no class was\n * on yet.\n * @returns The map now in effect (`value`, or `{}` for undefined), to pass back as `prev` next time.\n * @example\n * import { classList } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"li\");\n * let prev = classList(el, { active: true, \"is-new pulse\": true });\n * prev = classList(el, { active: false }, prev); // removes active, is-new and pulse\n * @see className\n * @since 1.0.0\n */\nexport function classList(\n el: Element,\n value: Record<string, unknown> | undefined,\n prev?: Record<string, unknown>,\n): Record<string, unknown> {\n const next: Record<string, unknown> = value ?? {};\n const before: Record<string, unknown> = prev ?? {};\n const keys = new Set([...Object.keys(before), ...Object.keys(next)]);\n for (const key of keys) {\n // Own properties only: `next[\"constructor\"]` would otherwise read Object.prototype's function\n // and a class with that name could never be switched on.\n const now = enabled(next, key);\n const was = enabled(before, key);\n if (now === was) continue;\n for (const token of key.split(/\\s+/)) {\n if (token !== \"\") el.classList.toggle(token, now);\n }\n }\n return next;\n}\n\n/**\n * Converts a camelCase style name to a CSS property name. Custom properties are kept as they are,\n * and vendor prefixes map to `-webkit-` and `-ms-`.\n * @internal\n */\nexport function toCssProperty(name: string): string {\n if (name.startsWith(\"--\")) return name;\n const kebab = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n return kebab.startsWith(\"ms-\") ? `-${kebab}` : kebab;\n}\n\n/**\n * Sets or removes one inline style property: the helper compiled templates call for the `style:`\n * prefix. Other inline properties are left alone.\n *\n * @param el HTML or SVG element.\n * @param name CSS property in camelCase (`backgroundColor`, `msTransform` gives `-ms-transform`) or\n * kebab-case, or a custom property (`--accent`, kept as is).\n * @param value `null`, `undefined` and `false` remove the property. A number is in pixels, as in\n * React, unless it is `0`, the property is unitless (`opacity`, `zIndex`, `flexGrow`, `lineHeight`,\n * ...) or a custom property. Any other value is written as `String(value)`.\n * @example\n * import { setStyleProperty } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"div\");\n * setStyleProperty(el, \"marginTop\", 8); // margin-top: 8px\n * setStyleProperty(el, \"--accent\", \"rebeccapurple\");\n * setStyleProperty(el, \"opacity\", 0.5); // unitless\n * @see style\n * @since 1.0.0\n */\nexport function setStyleProperty(el: HTMLElement | SVGElement, name: string, value: unknown): void {\n const property = toCssProperty(name);\n if (value === null || value === undefined || value === false) {\n el.style.removeProperty(property);\n } else {\n el.style.setProperty(property, cssValueText(property, value));\n }\n}\n\n/**\n * Sets the inline style of an element: the helper compiled templates call for a `style` attribute.\n * An object is diffed against `prev` so that only changed properties are written, each with the\n * rules of {@link setStyleProperty}; properties that disappeared are removed.\n *\n * @param el HTML or SVG element.\n * @param value An object of properties (camelCase, kebab-case or custom names). A string replaces\n * `cssText`. An array of strings and objects (not nested; `null`, `undefined`, `false` and `\"\"`\n * items are skipped) is written in order, so a later declaration wins, exactly as `ssrStyle` writes it\n * on the server. `null`, `undefined` and `false` remove the `style` attribute.\n * @param prev The value returned by the previous call. Undefined (the first call) diffs against an\n * empty style. When it is a string or an array, `cssText` is cleared before the object is written.\n * @returns What to pass back as `prev` next time: a shallow copy of an object value, otherwise\n * `value` itself.\n * @throws TypeError (production message `SHADOW_STYLE_ITEM`) when an array holds a nested array or a\n * value that is not a string or an object.\n * @example\n * import { style } from \"@shadow-js/web\";\n *\n * const el = document.createElement(\"div\");\n * let prev = style(el, { color: \"red\", width: 120 }); // width: 120px\n * prev = style(el, { color: \"blue\" }, prev); // writes color, removes width\n * @see setStyleProperty\n * @since 1.0.0\n */\nexport function style(el: HTMLElement | SVGElement, value: unknown, prev?: unknown): unknown {\n if (value === null || value === undefined || value === false) {\n el.removeAttribute(\"style\");\n return value;\n }\n if (typeof value !== \"object\") {\n el.style.cssText = String(value);\n return value;\n }\n if (Array.isArray(value)) {\n // Not diffed: a string in the array can set any property, so the whole style is written again, in\n // order (a later declaration wins, as on the server).\n el.style.cssText = \"\";\n for (const item of value) {\n if (typeof item === \"string\") {\n el.style.cssText += `;${item}`;\n } else if (item !== null && item !== undefined && item !== false) {\n if (typeof item !== \"object\" || Array.isArray(item)) {\n throw new TypeError(\n __DEV__ ? \"style(): an array holds only strings and objects.\" : \"SHADOW_STYLE_ITEM\",\n );\n }\n style(el, item, {});\n }\n }\n return value;\n }\n const next = { ...(value as Record<string, unknown>) };\n const before = asRecord(prev) ?? {};\n // What a string or an array wrote is unknown, so it is cleared before the object is written.\n if (typeof prev === \"string\" || Array.isArray(prev)) el.style.cssText = \"\";\n const keys = new Set([...Object.keys(before), ...Object.keys(next)]);\n for (const key of keys) {\n if (Object.is(before[key], next[key])) continue;\n setStyleProperty(el, key, next[key]);\n }\n return next;\n}\n"],"mappings":";;;;AAIA,SAAS,eAAe,MAAe,OAAuB;CAE5D,MA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.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/component.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Calls a component untracked, under a new owner that is a child of the current one: cleanups and
|
|
4
3
|
* effects it creates are disposed with the enclosing scope. The name, given in development builds,
|
|
@@ -19,5 +18,4 @@
|
|
|
19
18
|
* @since 1.0.0
|
|
20
19
|
*/
|
|
21
20
|
export declare function createComponent<P>(component: (props: P) => unknown, props: P, name?: string): unknown;
|
|
22
|
-
//#endregion
|
|
23
21
|
//# sourceMappingURL=component.d.ts.map
|
package/dist/dev/component.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { currentScope, enterComponent } from "./internal/hydration-scope.js";
|
|
2
2
|
import { DEVTOOLS_EVENT, addCleanup, createOwner, devtoolsReport, runInScope } from "@shadow-js/core/extend";
|
|
3
|
-
|
|
3
|
+
// src/component.ts
|
|
4
4
|
/** Dev-only: the name each component was created with, for devtools. Weak, so components are not kept alive. */
|
|
5
5
|
const componentNames = /* @__PURE__ */ new WeakMap();
|
|
6
6
|
/**
|
|
@@ -36,7 +36,6 @@ function createComponent(component, props, name) {
|
|
|
36
36
|
return result;
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
//#endregion
|
|
40
39
|
export { createComponent };
|
|
41
40
|
|
|
42
41
|
//# sourceMappingURL=component.js.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Accessor } from "@shadow-js/core";
|
|
2
|
-
//#region src/control-flow/activity.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* `visible` shows the children; `hidden` keeps them alive (state, DOM and focus) but out of sight.
|
|
5
4
|
* @since 1.0.0
|
|
@@ -54,5 +53,4 @@ export interface ActivityProps {
|
|
|
54
53
|
* @since 1.0.0
|
|
55
54
|
*/
|
|
56
55
|
export declare function Activity(props: ActivityProps): Accessor<unknown>;
|
|
57
|
-
//#endregion
|
|
58
56
|
//# sourceMappingURL=activity.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { runWithOwner, untrack, useEffect, useRenderEffect, useSignal } from "@shadow-js/core";
|
|
2
2
|
import { createOwner, pauseOwner, resumeOwner } from "@shadow-js/core/extend";
|
|
3
|
-
|
|
3
|
+
// src/control-flow/activity.ts
|
|
4
4
|
/**
|
|
5
5
|
* Hides the nodes between two anchors without removing them. Top-level elements get
|
|
6
6
|
* `display: none` (their own state, subtree and listeners are untouched). Top-level text nodes are
|
|
@@ -130,7 +130,6 @@ function Activity(props) {
|
|
|
130
130
|
end
|
|
131
131
|
];
|
|
132
132
|
}
|
|
133
|
-
//#endregion
|
|
134
133
|
export { Activity };
|
|
135
134
|
|
|
136
135
|
//# sourceMappingURL=activity.js.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { JsxChild } from "../jsx/types.js";
|
|
2
2
|
import { Accessor } from "@shadow-js/core";
|
|
3
|
-
//#region src/control-flow/client-only.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Props of {@link ClientOnly}.
|
|
6
5
|
* @since 1.0.0
|
|
@@ -44,5 +43,4 @@ export interface ClientOnlyProps {
|
|
|
44
43
|
* @since 1.0.0
|
|
45
44
|
*/
|
|
46
45
|
export declare function ClientOnly(props: ClientOnlyProps): Accessor<unknown>;
|
|
47
|
-
//#endregion
|
|
48
46
|
//# sourceMappingURL=client-only.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Show } from "./show.js";
|
|
2
2
|
import { onMount, useSignal } from "@shadow-js/core";
|
|
3
|
-
|
|
3
|
+
// src/control-flow/client-only.ts
|
|
4
4
|
/**
|
|
5
5
|
* Renders `children` in the browser only. The server (and the first client pass, which must match
|
|
6
6
|
* the server's markup) renders `fallback`; once mounted, the children replace it. Use it for
|
|
@@ -44,7 +44,6 @@ function ClientOnly(props) {
|
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
-
//#endregion
|
|
48
47
|
export { ClientOnly };
|
|
49
48
|
|
|
50
49
|
//# sourceMappingURL=client-only.js.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/control-flow/dynamic.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* A component function or a tag name, as {@link Dynamic} accepts it. The props of a function are
|
|
4
3
|
* checked by the caller.
|
|
@@ -30,8 +29,17 @@ export interface DynamicProps<C extends DynamicTarget = DynamicTarget> {
|
|
|
30
29
|
* `component` renders nothing.
|
|
31
30
|
*
|
|
32
31
|
* Tag names are checked against `^[a-z][a-z0-9-]*$` (case-insensitive) and `script` is refused, so
|
|
33
|
-
* data-driven tags cannot inject markup.
|
|
34
|
-
* in
|
|
32
|
+
* data-driven tags cannot inject markup. The browser decides the namespace: a name HTML knows (`div`,
|
|
33
|
+
* `a`, `style`, `title`, a custom element) is an HTML element, in any letter case. A name HTML does not
|
|
34
|
+
* know and that SVG defines (`circle`, `path`, `svg`, `image`, `foreignObject`, `clipPath`, the `fe*` filter
|
|
35
|
+
* primitives, the gradients and animation elements, ...) is created in the SVG namespace, matched against a
|
|
36
|
+
* name pattern (no HTML is parsed, so Trusted Types is never involved); any other name stays an HTML element.
|
|
37
|
+
* The element keeps the name exactly as written: `Dynamic` does not derive the canonical case, which SVG
|
|
38
|
+
* needs (`clipPath`, `linearGradient`, `feGaussianBlur`, `foreignObject`, ...), so write those names as SVG
|
|
39
|
+
* spells them. Development builds warn once per name with `DYNAMIC_SVG_CASE` when they are not.
|
|
40
|
+
* MathML names (`math`, `mi`, `mfrac`, `semantics`, `annotation-xml`, ...) are created in the MathML
|
|
41
|
+
* namespace, in lowercase. `title`, `style` and `a` stay HTML elements: `Dynamic` does not know the parent
|
|
42
|
+
* the element will be inserted into.
|
|
35
43
|
*
|
|
36
44
|
* @param props `component` and the props of what it renders.
|
|
37
45
|
* @returns An accessor of the rendered output, to be inserted by the caller.
|
|
@@ -78,5 +86,4 @@ export declare function Dynamic<C extends DynamicTarget>(props: DynamicProps<C>)
|
|
|
78
86
|
* @since 1.0.0
|
|
79
87
|
*/
|
|
80
88
|
export declare function createDynamic<C extends DynamicTarget>(component: () => C, props?: object): () => unknown;
|
|
81
|
-
//#endregion
|
|
82
89
|
//# sourceMappingURL=dynamic.d.ts.map
|