@sdxc/ui 2026.10.9 → 2026.10.10

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/README.md CHANGED
@@ -362,6 +362,7 @@ script never runs, so the cost of every behavior stays visible before you apply
362
362
  | `validate(schema)` | a native form control | Applies a `remix/data-schema` schema through `setCustomValidity()`, mirrored into a `FieldError`. |
363
363
  | `viewTransition()` | a `SharedElement` island | Bridges a same-document reload to the View Transition API. |
364
364
  | `trackHostNode(handle)` | inside a mixin | Caches a mixin's live host node across insert and remove, for the mixins above that read the DOM outside render. |
365
+ | `whileLive(handle, subscribe)` | inside a mixin | Subscribes a mixin or island to a model, session or frame only while it is live in a document. |
365
366
 
366
367
  ### Behavior Classes
367
368
 
@@ -461,13 +462,16 @@ import { clientEntry } from "remix/component";
461
462
 
462
463
  import { Toast } from "@sdxc/ui";
463
464
  import { Toaster } from "@sdxc/ui/behaviors";
465
+ import { whileLive } from "@sdxc/ui/mixins";
464
466
 
465
467
  export const AppToaster = clientEntry(
466
468
  "/app/components/app-toaster.tsx#AppToaster",
467
469
  function AppToaster(handle: Handle) {
468
470
  let toaster = new Toaster<{ title: string; color?: Toast.Color }>();
469
471
 
470
- toaster.addEventListener("change", () => handle.update(), { signal: handle.signal });
472
+ whileLive(handle, (model: Toaster, signal) =>
473
+ model.addEventListener("change", () => handle.update(), { signal }),
474
+ )(toaster);
471
475
  handle.context.set({ toaster });
472
476
 
473
477
  return () => (
@@ -502,7 +506,7 @@ import type { Handle } from "remix/component";
502
506
  import { visuallyHidden } from "@sdxc/u/a11y";
503
507
  import { Button, Modal, ShortcutList } from "@sdxc/ui";
504
508
  import { Announcer } from "@sdxc/ui/behaviors";
505
- import { keymap } from "@sdxc/ui/mixins";
509
+ import { keymap, whileLive } from "@sdxc/ui/mixins";
506
510
  import { keyComboGlyphs } from "@sdxc/ui/utils";
507
511
  import { clientEntry } from "remix/component";
508
512
 
@@ -512,7 +516,9 @@ export default clientEntry(
512
516
  "/app/components/shortcuts.tsx#default",
513
517
  function Shortcuts(handle: Handle<Props>) {
514
518
  let announcer = new Announcer({ hold: 1200 });
515
- announcer.addEventListener("change", () => handle.update(), { signal: handle.signal });
519
+ whileLive(handle, (model: Announcer, signal) =>
520
+ model.addEventListener("change", () => handle.update(), { signal }),
521
+ )(announcer);
516
522
 
517
523
  let openHelp = () =>
518
524
  document.querySelector<HTMLButtonElement>('[commandfor="shortcuts"]')?.click();
@@ -56,7 +56,7 @@ export declare namespace Announcer {
56
56
  * `aria-live` element, and calls {@link Announcer.next} once it has been read.
57
57
  *
58
58
  * @example
59
- * announcer.addEventListener("change", () => handle.update(), { signal: handle.signal });
59
+ * whileLive(handle, (model: Announcer, signal) => model.addEventListener("change", () => handle.update(), { signal }))(announcer);
60
60
  */
61
61
  export declare class Announcer extends TypedEventTarget<Announcer.Events> {
62
62
  #private;
@@ -15,7 +15,7 @@ const DEFAULT_PRIORITY = "polite";
15
15
  * `aria-live` element, and calls {@link Announcer.next} once it has been read.
16
16
  *
17
17
  * @example
18
- * announcer.addEventListener("change", () => handle.update(), { signal: handle.signal });
18
+ * whileLive(handle, (model: Announcer, signal) => model.addEventListener("change", () => handle.update(), { signal }))(announcer);
19
19
  */
20
20
  export class Announcer extends TypedEventTarget {
21
21
  #queue = [];
@@ -68,7 +68,7 @@ export declare namespace Toaster {
68
68
  * {@link Toaster.resume} so a toast under the cursor stays readable.
69
69
  *
70
70
  * @example
71
- * toaster.addEventListener("change", () => handle.update(), { signal: handle.signal });
71
+ * whileLive(handle, (model: Toaster, signal) => model.addEventListener("change", () => handle.update(), { signal }))(toaster);
72
72
  */
73
73
  export declare class Toaster<Data = unknown> extends TypedEventTarget<Toaster.Events> {
74
74
  #private;
@@ -26,7 +26,7 @@ function toPublicToast(entry) {
26
26
  * {@link Toaster.resume} so a toast under the cursor stays readable.
27
27
  *
28
28
  * @example
29
- * toaster.addEventListener("change", () => handle.update(), { signal: handle.signal });
29
+ * whileLive(handle, (model: Toaster, signal) => model.addEventListener("change", () => handle.update(), { signal }))(toaster);
30
30
  */
31
31
  export class Toaster extends TypedEventTarget {
32
32
  #toasts = new Map();
@@ -16,7 +16,7 @@ const DEFAULT_SIZE = "md";
16
16
  /**
17
17
  * Applied through {@link attrs} so the host is hidden from assistive
18
18
  * technology by default, since composed uses supply their own accessible
19
- * name; pass `aria-hidden={false}` and `aria-label` to render standalone.
19
+ * name; pass `aria-hidden="false"` and `aria-label` to render standalone.
20
20
  */
21
21
  const DEFAULT_ARIA_HIDDEN = "true";
22
22
  /**
@@ -125,7 +125,7 @@ export function Marker(handle) {
125
125
  * @example
126
126
  * <Marker.Icon><CheckIcon /></Marker.Icon>
127
127
  * @example
128
- * <Marker.Icon aria-hidden={false}>
128
+ * <Marker.Icon aria-hidden="false">
129
129
  * <Spinner size="sm" aria-label={t("status.generating")} />
130
130
  * </Marker.Icon>
131
131
  */
@@ -31,6 +31,6 @@ export declare namespace Skeleton {
31
31
  * @example
32
32
  * <Skeleton style={{ blockSize: "2.5rem", inlineSize: "2.5rem", borderRadius: "9999px" }} />
33
33
  * @example
34
- * <Skeleton aria-hidden={false} aria-label={t("status.loadingProfile")} />
34
+ * <Skeleton aria-hidden="false" aria-label={t("status.loadingProfile")} />
35
35
  */
36
36
  export declare function Skeleton(handle: Handle<Skeleton.Props>): () => import("remix/component").RemixElement;
@@ -6,7 +6,7 @@ import { attrs } from "remix/component";
6
6
  /**
7
7
  * Default `aria-hidden` value applied through {@link attrs}, keeping a
8
8
  * placeholder out of the accessibility tree unless a consumer sets
9
- * `aria-hidden={false}` to expose a loading label to assistive tech.
9
+ * `aria-hidden="false"` to expose a loading label to assistive tech.
10
10
  */
11
11
  const DEFAULT_ARIA_HIDDEN = "true";
12
12
  /**
@@ -21,7 +21,7 @@ const DEFAULT_ARIA_HIDDEN = "true";
21
21
  * @example
22
22
  * <Skeleton style={{ blockSize: "2.5rem", inlineSize: "2.5rem", borderRadius: "9999px" }} />
23
23
  * @example
24
- * <Skeleton aria-hidden={false} aria-label={t("status.loadingProfile")} />
24
+ * <Skeleton aria-hidden="false" aria-label={t("status.loadingProfile")} />
25
25
  */
26
26
  export function Skeleton(handle) {
27
27
  return () => {
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import { createElement, createMixin, on } from "remix/component";
10
10
  import { DISABLED_SELECTOR } from "../utils/disabled-selector.js";
11
+ import { whileLive } from "./while-live.js";
11
12
  /**
12
13
  * Attribute every calendar day cell exposes its date on, in local
13
14
  * `YYYY-MM-DD` form, that `calendarKeys()` matches against a
@@ -58,7 +59,9 @@ function fromDateKey(key) {
58
59
  */
59
60
  export const calendarKeys = createMixin((handle) => {
60
61
  let hostNode;
61
- let boundModel;
62
+ let follow = whileLive(handle, (model, signal) => {
63
+ model.addEventListener("change", () => syncFocusedCell(model), { signal });
64
+ });
62
65
  handle.addEventListener("insert", (event) => {
63
66
  hostNode = event.node;
64
67
  });
@@ -81,12 +84,7 @@ export const calendarKeys = createMixin((handle) => {
81
84
  }
82
85
  }
83
86
  return (model) => {
84
- if (boundModel !== model) {
85
- boundModel = model;
86
- model.addEventListener("change", () => syncFocusedCell(model), {
87
- signal: handle.signal,
88
- });
89
- }
87
+ follow(model);
90
88
  return createElement(handle.element, {
91
89
  mix: [
92
90
  on("click", (event) => {
@@ -9,6 +9,7 @@
9
9
  * @copyright Sergio Xalambrí 2026
10
10
  */
11
11
  import { createElement, createMixin, on } from "remix/component";
12
+ import { whileLive } from "./while-live.js";
12
13
  /**
13
14
  * Attribute the search input exposes itself on — `Command.Input`'s own
14
15
  * `<input>` carries this automatically, and `commandFilter()` forwards its
@@ -91,6 +92,12 @@ function syncMatches(root, model) {
91
92
  export const commandFilter = createMixin((handle) => {
92
93
  let hostNode;
93
94
  let boundModel;
95
+ let follow = whileLive(handle, (model, signal) => {
96
+ model.addEventListener("change", () => {
97
+ if (hostNode !== undefined)
98
+ syncMatches(hostNode, model);
99
+ }, { signal });
100
+ });
94
101
  handle.addEventListener("insert", (event) => {
95
102
  hostNode = event.node;
96
103
  boundModel?.setOptions(collectOptions(hostNode));
@@ -99,13 +106,8 @@ export const commandFilter = createMixin((handle) => {
99
106
  hostNode = undefined;
100
107
  });
101
108
  return (model) => {
102
- if (boundModel !== model) {
103
- boundModel = model;
104
- model.addEventListener("change", () => {
105
- if (hostNode !== undefined)
106
- syncMatches(hostNode, model);
107
- }, { signal: handle.signal });
108
- }
109
+ boundModel = model;
110
+ follow(model);
109
111
  return createElement(handle.element, {
110
112
  mix: [
111
113
  on("input", (event) => {
@@ -10,6 +10,7 @@
10
10
  */
11
11
  import { createElement, createMixin, on } from "remix/component";
12
12
  import { COMMAND_INPUT_ATTRIBUTE, COMMAND_ITEM_ATTRIBUTE, getCommandItemId, } from "./command-filter.js";
13
+ import { whileLive } from "./while-live.js";
13
14
  /** `KeyboardEvent.key` value that moves the active match to the previous visible option. */
14
15
  const ARROW_UP_KEY = "ArrowUp";
15
16
  /** `KeyboardEvent.key` value that moves the active match to the next visible option. */
@@ -78,27 +79,14 @@ function activateCurrent(root, model) {
78
79
  export const commandKeys = createMixin((handle) => {
79
80
  let hostNode;
80
81
  let boundModel;
81
- /** The most recent model the mixin was given, which insertion subscribes to. */
82
- let pendingModel;
83
- /**
84
- * The subscription belongs to the inserted host: it exists to write the active item
85
- * onto a live node, and `handle.signal` is the lifetime of that node. Binding it while
86
- * the host is only being rendered — on a server, say — subscribes on behalf of nothing
87
- * and hands `addEventListener` a signal that does not exist yet.
88
- */
89
- function follow(model) {
90
- if (boundModel === model)
91
- return;
92
- boundModel = model;
82
+ let follow = whileLive(handle, (model, signal) => {
93
83
  model.addEventListener("change", () => {
94
84
  if (hostNode !== undefined)
95
85
  syncActive(hostNode, model);
96
- }, { signal: handle.signal });
97
- }
86
+ }, { signal });
87
+ });
98
88
  handle.addEventListener("insert", (event) => {
99
89
  hostNode = event.node;
100
- if (pendingModel !== undefined)
101
- follow(pendingModel);
102
90
  if (boundModel !== undefined)
103
91
  syncActive(hostNode, boundModel);
104
92
  });
@@ -106,9 +94,8 @@ export const commandKeys = createMixin((handle) => {
106
94
  hostNode = undefined;
107
95
  });
108
96
  return (model) => {
109
- pendingModel = model;
110
- if (hostNode !== undefined)
111
- follow(model);
97
+ boundModel = model;
98
+ follow(model);
112
99
  return createElement(handle.element, {
113
100
  mix: [
114
101
  on("keydown", (event) => {
@@ -8,6 +8,7 @@
8
8
  * @copyright Sergio Xalambrí 2026
9
9
  */
10
10
  import { createElement, createMixin, on } from "remix/component";
11
+ import { whileLive } from "./while-live.js";
11
12
  /**
12
13
  * Attribute every reorderable row carries its stable identity on, read by
13
14
  * {@link dragReorder} to resolve the row under the pointer and shared by
@@ -118,8 +119,11 @@ function resolveDropPosition(row, clientY) {
118
119
  */
119
120
  export const dragReorder = createMixin((handle) => {
120
121
  let hostNode;
121
- let boundSession;
122
122
  let activePointerId;
123
+ let follow = whileLive(handle, (session, signal) => {
124
+ session.addEventListener("change", () => syncRows(session), { signal });
125
+ signal.addEventListener("abort", () => session.cancel());
126
+ });
123
127
  handle.addEventListener("insert", (event) => {
124
128
  hostNode = event.node;
125
129
  });
@@ -148,11 +152,7 @@ export const dragReorder = createMixin((handle) => {
148
152
  }
149
153
  }
150
154
  return (session) => {
151
- if (boundSession !== session) {
152
- boundSession = session;
153
- session.addEventListener("change", () => syncRows(session), { signal: handle.signal });
154
- handle.signal.addEventListener("abort", () => session.cancel());
155
- }
155
+ follow(session);
156
156
  return createElement(handle.element, {
157
157
  mix: [
158
158
  on("pointerdown", (event) => {
@@ -8,6 +8,7 @@
8
8
  * @copyright Sergio Xalambrí 2026
9
9
  */
10
10
  import { createElement, createMixin, on } from "remix/component";
11
+ import { whileLive } from "./while-live.js";
11
12
  /**
12
13
  * `data-*` attribute {@link dropZone} toggles on its host while a file
13
14
  * drag from outside the page hovers over it, so a DropZone's styling can
@@ -65,7 +66,10 @@ function isFileDrag(dataTransfer) {
65
66
  */
66
67
  export const dropZone = createMixin((handle) => {
67
68
  let hostNode;
68
- let boundSession;
69
+ let follow = whileLive(handle, (session, signal) => {
70
+ session.addEventListener("change", () => syncDropTarget(session), { signal });
71
+ signal.addEventListener("abort", () => session.cancel());
72
+ });
69
73
  handle.addEventListener("insert", (event) => {
70
74
  hostNode = event.node;
71
75
  });
@@ -82,13 +86,7 @@ export const dropZone = createMixin((handle) => {
82
86
  hostNode.removeAttribute(DROP_TARGET_ATTRIBUTE);
83
87
  }
84
88
  return (session) => {
85
- if (boundSession !== session) {
86
- boundSession = session;
87
- session.addEventListener("change", () => syncDropTarget(session), {
88
- signal: handle.signal,
89
- });
90
- handle.signal.addEventListener("abort", () => session.cancel());
91
- }
89
+ follow(session);
92
90
  return createElement(handle.element, {
93
91
  mix: [
94
92
  on("dragenter", (event) => {
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import { createElement, createMixin, on } from "remix/component";
11
11
  import { DISABLED_SELECTOR } from "../utils/disabled-selector.js";
12
+ import { whileLive } from "./while-live.js";
12
13
  /**
13
14
  * Attribute every GridList row exposes its {@link SelectionModel.Key} on;
14
15
  * `gridListKeys()` correlates a row with the key `SelectionModel` tracks its
@@ -151,7 +152,12 @@ function syncSelection(host, model) {
151
152
  */
152
153
  export const gridListKeys = createMixin((handle) => {
153
154
  let hostNode;
154
- let boundModel;
155
+ let follow = whileLive(handle, (model, signal) => {
156
+ model.addEventListener("change", () => {
157
+ if (hostNode !== undefined)
158
+ syncSelection(hostNode, model);
159
+ }, { signal });
160
+ });
155
161
  handle.addEventListener("insert", (event) => {
156
162
  hostNode = event.node;
157
163
  let rows = queryRows(hostNode);
@@ -162,13 +168,7 @@ export const gridListKeys = createMixin((handle) => {
162
168
  hostNode = undefined;
163
169
  });
164
170
  return (model) => {
165
- if (boundModel !== model) {
166
- boundModel = model;
167
- model.addEventListener("change", () => {
168
- if (hostNode !== undefined)
169
- syncSelection(hostNode, model);
170
- }, { signal: handle.signal });
171
- }
171
+ follow(model);
172
172
  return createElement(handle.element, {
173
173
  mix: [
174
174
  on("focusin", (event) => {
@@ -48,3 +48,4 @@ export * from "./track-host-node.js";
48
48
  export * from "./treeKeys.js";
49
49
  export * from "./validate.js";
50
50
  export * from "./view-transition.js";
51
+ export * from "./while-live.js";
@@ -48,3 +48,4 @@ export * from "./track-host-node.js";
48
48
  export * from "./treeKeys.js";
49
49
  export * from "./validate.js";
50
50
  export * from "./view-transition.js";
51
+ export * from "./while-live.js";
@@ -13,6 +13,7 @@
13
13
  */
14
14
  import { createElement, createMixin, on } from "remix/component";
15
15
  import { prefersReducedMotion } from "../utils/prefers-reduced-motion.js";
16
+ import { whileLive } from "./while-live.js";
16
17
  /**
17
18
  * Attribute every conversational turn exposes itself on, its value the
18
19
  * turn's stable id; `messageFollow()` reads it to find the anchor turn and
@@ -257,6 +258,16 @@ export const messageFollow = createMixin((handle) => {
257
258
  let userScrollIntent = false;
258
259
  let itemsObserver;
259
260
  let observedItems = new Set();
261
+ let follow = whileLive(handle, (model, signal) => {
262
+ model.addEventListener("change", () => {
263
+ if (!hostNode)
264
+ return;
265
+ syncAttributesFromModel(hostNode, model);
266
+ let request = model.consumeScrollRequest();
267
+ if (request)
268
+ fulfillScrollRequest(hostNode, request);
269
+ }, { signal });
270
+ });
260
271
  /**
261
272
  * Lazily creates the visibility observer the first time a turn exists
262
273
  * beneath `host`, then keeps it watching exactly the turns currently
@@ -373,17 +384,8 @@ export const messageFollow = createMixin((handle) => {
373
384
  hostNode = undefined;
374
385
  });
375
386
  return (model) => {
376
- if (boundModel !== model) {
377
- boundModel = model;
378
- model.addEventListener("change", () => {
379
- if (!hostNode)
380
- return;
381
- syncAttributesFromModel(hostNode, model);
382
- let request = model.consumeScrollRequest();
383
- if (request)
384
- fulfillScrollRequest(hostNode, request);
385
- }, { signal: handle.signal });
386
- }
387
+ boundModel = model;
388
+ follow(model);
387
389
  return createElement(handle.element, {
388
390
  mix: [
389
391
  on("scroll", (event) => {
@@ -14,6 +14,7 @@
14
14
  import { createElement, createMixin, on } from "remix/component";
15
15
  import { CALENDAR_DAY_DATE_ATTRIBUTE } from "./calendar-keys.js";
16
16
  import { trackHostNode } from "./track-host-node.js";
17
+ import { whileLive } from "./while-live.js";
17
18
  /**
18
19
  * Parses a day cell's {@link CALENDAR_DAY_DATE_ATTRIBUTE} value into a
19
20
  * `Date` built from its numeric year/month/day components, keeping the
@@ -66,7 +67,9 @@ function classifyRangePosition(date, range) {
66
67
  */
67
68
  export const rangePreview = createMixin((handle) => {
68
69
  let getHostNode = trackHostNode(handle);
69
- let boundModel;
70
+ let follow = whileLive(handle, (model, signal) => {
71
+ model.addEventListener("change", () => syncRangePreview(model), { signal });
72
+ });
70
73
  /** Mirrors `model`'s anchor day and preview range onto the grid's day cells. */
71
74
  function syncRangePreview(model) {
72
75
  let hostNode = getHostNode();
@@ -100,12 +103,7 @@ export const rangePreview = createMixin((handle) => {
100
103
  model.updateRangePreview(date);
101
104
  }
102
105
  return (model) => {
103
- if (boundModel !== model) {
104
- boundModel = model;
105
- model.addEventListener("change", () => syncRangePreview(model), {
106
- signal: handle.signal,
107
- });
108
- }
106
+ follow(model);
109
107
  return createElement(handle.element, {
110
108
  mix: [
111
109
  on("pointerover", (event) => {
@@ -15,6 +15,7 @@
15
15
  import { createElement, createMixin, on } from "remix/component";
16
16
  import { isNewPrimaryPress } from "../utils/is-new-primary-press.js";
17
17
  import { trackHostNode } from "./track-host-node.js";
18
+ import { whileLive } from "./while-live.js";
18
19
  /**
19
20
  * Attribute a Resizable panel group's own host element carries.
20
21
  * `resizeHandle()` walks up to the nearest ancestor carrying it to find the
@@ -195,8 +196,14 @@ function roundPercent(value) {
195
196
  */
196
197
  export const resizeHandle = createMixin((handle) => {
197
198
  let getHostNode = trackHostNode(handle);
198
- let boundSession;
199
199
  let activePointerId;
200
+ let follow = whileLive(handle, (session, signal) => {
201
+ session.addEventListener("change", () => syncLayout(session), { signal });
202
+ signal.addEventListener("abort", () => {
203
+ if (activePointerId !== undefined)
204
+ session.cancel();
205
+ });
206
+ });
200
207
  /** Mirrors `session`'s resolved sizes onto their panel elements, and this handle's adjacent panel onto its own ARIA value attributes. */
201
208
  function syncLayout(session) {
202
209
  let hostNode = getHostNode();
@@ -224,14 +231,7 @@ export const resizeHandle = createMixin((handle) => {
224
231
  hostNode.setAttribute("aria-valuemax", String(Math.round(adjacentPanel.max)));
225
232
  }
226
233
  return (axis, session) => {
227
- if (boundSession !== session) {
228
- boundSession = session;
229
- session.addEventListener("change", () => syncLayout(session), { signal: handle.signal });
230
- handle.signal.addEventListener("abort", () => {
231
- if (activePointerId !== undefined)
232
- session.cancel();
233
- });
234
- }
234
+ follow(session);
235
235
  return createElement(handle.element, {
236
236
  mix: [
237
237
  on("pointerdown", (event) => {
@@ -20,12 +20,14 @@ import type { MixinHandle } from "remix/component";
20
20
  * export const example = createMixin<HTMLElement>((handle) => {
21
21
  * let hostNode = trackHostNode(handle);
22
22
  *
23
- * addEventListeners(document, handle.signal, {
24
- * keydown() {
25
- * let node = hostNode();
26
- * if (node === undefined) return;
27
- * // ...
28
- * },
23
+ * handle.queueTask(() => {
24
+ * addEventListeners(document, handle.signal, {
25
+ * keydown() {
26
+ * let node = hostNode();
27
+ * if (node === undefined) return;
28
+ * // ...
29
+ * },
30
+ * });
29
31
  * });
30
32
  *
31
33
  * return () => {};
@@ -19,12 +19,14 @@
19
19
  * export const example = createMixin<HTMLElement>((handle) => {
20
20
  * let hostNode = trackHostNode(handle);
21
21
  *
22
- * addEventListeners(document, handle.signal, {
23
- * keydown() {
24
- * let node = hostNode();
25
- * if (node === undefined) return;
26
- * // ...
27
- * },
22
+ * handle.queueTask(() => {
23
+ * addEventListeners(document, handle.signal, {
24
+ * keydown() {
25
+ * let node = hostNode();
26
+ * if (node === undefined) return;
27
+ * // ...
28
+ * },
29
+ * });
28
30
  * });
29
31
  *
30
32
  * return () => {};
@@ -11,6 +11,7 @@
11
11
  */
12
12
  import { createElement, createMixin, on } from "remix/component";
13
13
  import { isPrintableKey, labelFor, setRovingTabindex } from "../utils/keyboard-nav.js";
14
+ import { whileLive } from "./while-live.js";
14
15
  /**
15
16
  * Attribute every Tree row exposes itself on; its value doubles as the
16
17
  * `SelectionModel.Key` {@link treeKeys} toggles, ranges over, and mirrors
@@ -155,6 +156,14 @@ export const treeKeys = createMixin((handle) => {
155
156
  let boundModel;
156
157
  let buffer = "";
157
158
  let resetBufferId;
159
+ let follow = whileLive(handle, (model, signal) => {
160
+ model.addEventListener("change", () => {
161
+ if (hostNode === undefined)
162
+ return;
163
+ syncSelection(hostNode, model);
164
+ dispatchTreeChange(hostNode, model);
165
+ }, { signal });
166
+ });
158
167
  handle.addEventListener("insert", (event) => {
159
168
  hostNode = event.node;
160
169
  let rows = collectRows(hostNode);
@@ -172,15 +181,8 @@ export const treeKeys = createMixin((handle) => {
172
181
  });
173
182
  handle.signal.addEventListener("abort", () => clearTimeout(resetBufferId));
174
183
  return (model) => {
175
- if (boundModel !== model) {
176
- boundModel = model;
177
- model.addEventListener("change", () => {
178
- if (hostNode === undefined)
179
- return;
180
- syncSelection(hostNode, model);
181
- dispatchTreeChange(hostNode, model);
182
- }, { signal: handle.signal });
183
- }
184
+ boundModel = model;
185
+ follow(model);
184
186
  return createElement(handle.element, {
185
187
  mix: [
186
188
  on("focusin", (event) => {
@@ -11,6 +11,7 @@
11
11
  import { createElement, createMixin } from "remix/component";
12
12
  import { prefersReducedMotion } from "../utils/prefers-reduced-motion.js";
13
13
  import { trackHostNode } from "./track-host-node.js";
14
+ import { whileLive } from "./while-live.js";
14
15
  /**
15
16
  * `data-*` attribute {@link viewTransition} sets on a SharedElement's host
16
17
  * while its Frame's transition is in flight, so styling can suppress hover
@@ -93,19 +94,19 @@ function settleFrameTransition(frame) {
93
94
  */
94
95
  export const viewTransition = createMixin((handle) => {
95
96
  let getHostNode = trackHostNode(handle);
96
- let frame = handle.frame;
97
- frame.addEventListener("reloadStart", () => {
98
- let state = ensureFrameTransition(frame);
99
- let hostNode = getHostNode();
100
- hostNode?.dispatchEvent(new ViewTransitionEvent(state.transition));
101
- if (!state.transition)
102
- return;
103
- let stopTransitioning = () => getHostNode()?.removeAttribute(TRANSITIONING_ATTRIBUTE);
104
- hostNode?.toggleAttribute(TRANSITIONING_ATTRIBUTE, true);
105
- void state.transition.finished.then(stopTransitioning, stopTransitioning);
106
- }, { signal: handle.signal });
107
- frame.addEventListener("reloadComplete", () => settleFrameTransition(frame), {
108
- signal: handle.signal,
97
+ let follow = whileLive(handle, (frame, signal) => {
98
+ frame.addEventListener("reloadStart", () => {
99
+ let state = ensureFrameTransition(frame);
100
+ let hostNode = getHostNode();
101
+ hostNode?.dispatchEvent(new ViewTransitionEvent(state.transition));
102
+ if (!state.transition)
103
+ return;
104
+ let stopTransitioning = () => getHostNode()?.removeAttribute(TRANSITIONING_ATTRIBUTE);
105
+ hostNode?.toggleAttribute(TRANSITIONING_ATTRIBUTE, true);
106
+ void state.transition.finished.then(stopTransitioning, stopTransitioning);
107
+ }, { signal });
108
+ frame.addEventListener("reloadComplete", () => settleFrameTransition(frame), { signal });
109
109
  });
110
+ follow(handle.frame);
110
111
  return () => createElement(handle.element, {});
111
112
  });
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Ties a subscription to a model, session, frame or global to the time a mixin's host or an
3
+ * island component is live in a document, so code that renders on a server as well as in a
4
+ * browser subscribes only in the browser, with a real signal that detaches the listeners.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { Handle, MixinHandle } from "remix/component";
10
+ /**
11
+ * Keeps `subscribe` bound to the latest target handed to the returned function while the host
12
+ * is inserted, or once an island component's first render commits: server rendering never
13
+ * subscribes, and a new target detaches the previous one's listeners. Call it during setup.
14
+ *
15
+ * @param handle Handle of the mixin or island component whose lifetime bounds every subscription.
16
+ * @param subscribe Registers listeners on `target` with `signal`, which aborts once that target
17
+ * is replaced or the mixin slot or component is disposed.
18
+ * @returns A function to call with the current target, from render or straight after setup.
19
+ * @template target The model, session, frame or global being listened to.
20
+ * @template node The host element a mixin is applied to.
21
+ * @example let follow = whileLive(handle, (model, signal) => model.addEventListener("change", sync, { signal }));
22
+ * @example whileLive(handle, (model: Toaster, signal) => model.addEventListener("change", () => void handle.update(), { signal }))(toaster);
23
+ */
24
+ export declare function whileLive<target extends object, node extends EventTarget = Element>(handle: MixinHandle<node> | Pick<Handle, "signal" | "queueTask">, subscribe: (target: target, signal: AbortSignal) => void): (target: target) => void;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Ties a subscription to a model, session, frame or global to the time a mixin's host or an
3
+ * island component is live in a document, so code that renders on a server as well as in a
4
+ * browser subscribes only in the browser, with a real signal that detaches the listeners.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ /**
10
+ * Keeps `subscribe` bound to the latest target handed to the returned function while the host
11
+ * is inserted, or once an island component's first render commits: server rendering never
12
+ * subscribes, and a new target detaches the previous one's listeners. Call it during setup.
13
+ *
14
+ * @param handle Handle of the mixin or island component whose lifetime bounds every subscription.
15
+ * @param subscribe Registers listeners on `target` with `signal`, which aborts once that target
16
+ * is replaced or the mixin slot or component is disposed.
17
+ * @returns A function to call with the current target, from render or straight after setup.
18
+ * @template target The model, session, frame or global being listened to.
19
+ * @template node The host element a mixin is applied to.
20
+ * @example let follow = whileLive(handle, (model, signal) => model.addEventListener("change", sync, { signal }));
21
+ * @example whileLive(handle, (model: Toaster, signal) => model.addEventListener("change", () => void handle.update(), { signal }))(toaster);
22
+ */
23
+ export function whileLive(handle, subscribe) {
24
+ let lifetime = handle.signal;
25
+ let live = false;
26
+ let latest;
27
+ let bound;
28
+ let binding;
29
+ /** Subscribes to the latest target once the host is live and that target is not yet bound. */
30
+ function bind() {
31
+ if (!live || latest === undefined || latest === bound)
32
+ return;
33
+ binding?.abort();
34
+ binding = new AbortController();
35
+ bound = latest;
36
+ subscribe(latest, AbortSignal.any([lifetime, binding.signal]));
37
+ }
38
+ /** Marks the host or component live and binds whatever target arrived before it was. */
39
+ function goLive() {
40
+ live = true;
41
+ bind();
42
+ }
43
+ if ("addEventListener" in handle) {
44
+ handle.addEventListener("insert", goLive);
45
+ handle.addEventListener("remove", () => {
46
+ live = false;
47
+ });
48
+ }
49
+ else {
50
+ handle.queueTask(goLive);
51
+ }
52
+ return (target) => {
53
+ latest = target;
54
+ bind();
55
+ };
56
+ }
@@ -220,7 +220,7 @@ function parseAlphaToken(token) {
220
220
  }
221
221
  /** Parses an `hsl()`/`hsla()` hue token — a plain number optionally suffixed with `deg` — to its numeric degree value, or `null` when `token` matches neither shape. */
222
222
  function parseHueToken(token) {
223
- let match = /^(-?\d*\.?\d+)(deg)?$/i.exec(token);
223
+ let match = /^(-?(?:\d+(?:\.\d+)?|\.\d+))(deg)?$/i.exec(token);
224
224
  if (match === null)
225
225
  return null;
226
226
  let value = Number(match[1]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdxc/ui",
3
- "version": "2026.10.9",
3
+ "version": "2026.10.10",
4
4
  "description": "Styled, accessible remix/component components rendered as server HTML",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  "@sdxc/u": "2026.10.2",
22
22
  "remix": "3.0.0"
23
23
  },
24
- "gitHead": "64fa732ed0a8ca8693a35aeef6345ae5be2534ef",
24
+ "gitHead": "b61f19c59866708a2d89a5a8f4655ebbc16941b0",
25
25
  "publishConfig": {
26
26
  "access": "public"
27
27
  },
package/src/reset.css CHANGED
@@ -2,19 +2,21 @@
2
2
  * Base reset: border-box sizing, zeroed margins/padding,
3
3
  * borders reset to "0 solid" so bare border-widths work later, the theme's
4
4
  * sans font stack applied once at the document root for every element to
5
- * inherit, form controls that inherit font/color/line-height, transparent
6
- * button/input backgrounds with a sensible cursor, block-level media, the theme's
7
- * focus ring for keyboard focus, and the rest of the usual list/table/[hidden]
8
- * normalizations.
5
+ * inherit, MathML drawn in the system's math font, form controls that inherit
6
+ * font/color/line-height, transparent button/input backgrounds with a sensible
7
+ * cursor, block-level media, the theme's focus ring for keyboard focus, and the
8
+ * rest of the usual list/table/[hidden] normalizations.
9
9
  *
10
10
  * Every selector is wrapped in :where(...) so the whole file carries zero
11
11
  * specificity and can never beat a component's own css() rules.
12
12
  *
13
13
  * Deliberate exemption: this reset does NOT touch the user-agent styles that
14
- * <dialog> and [popover] depend on. ::backdrop is left alone entirely, and
14
+ * <dialog>, [popover] and MathML depend on. ::backdrop is left alone entirely,
15
15
  * dialog/[popover] are excluded from the margin reset so their default
16
- * `margin: auto` centering survives untouched. Overlay components own the
17
- * rest of their presentation explicitly instead of fighting the reset.
16
+ * `margin: auto` centering survives untouched, and everything inside <math>
17
+ * keeps the padding that spaces matrix cells and fraction bars. Overlay
18
+ * components own the rest of their presentation explicitly instead of
19
+ * fighting the reset.
18
20
  */
19
21
 
20
22
  @layer base, rmx;
@@ -27,7 +29,7 @@
27
29
  border: 0 solid;
28
30
  }
29
31
 
30
- :where(:not(dialog, [popover])),
32
+ :where(:not(dialog, [popover], math *)),
31
33
  :where(*)::before,
32
34
  :where(*)::after {
33
35
  margin: 0;
@@ -42,6 +44,14 @@
42
44
  -webkit-tap-highlight-color: transparent;
43
45
  }
44
46
 
47
+ /*
48
+ * Stretchy fences and big operators need a font with an OpenType MATH table;
49
+ * the operating systems ship one each, named ahead of the generic family.
50
+ */
51
+ :where(math) {
52
+ font-family: "STIX Two Math", "Cambria Math", math;
53
+ }
54
+
45
55
  :where(hr) {
46
56
  height: 0;
47
57
  color: inherit;