@c9up/nebula 0.2.3 → 0.2.5

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.
Files changed (99) hide show
  1. package/README.md +9 -8
  2. package/dist/atoms/AspectRatio.d.ts +10 -4
  3. package/dist/atoms/AspectRatio.js +21 -6
  4. package/dist/atoms/Avatar.d.ts +14 -0
  5. package/dist/atoms/Avatar.js +46 -8
  6. package/dist/atoms/NativeSelect.d.ts +10 -0
  7. package/dist/atoms/NativeSelect.js +4 -1
  8. package/dist/atoms/Progress.d.ts +9 -1
  9. package/dist/atoms/Progress.js +21 -5
  10. package/dist/atoms/Switch.d.ts +7 -1
  11. package/dist/atoms/Switch.js +7 -1
  12. package/dist/cli/add.d.ts +2 -0
  13. package/dist/cli/add.js +4 -1
  14. package/dist/cli/diff.d.ts +48 -0
  15. package/dist/cli/diff.js +77 -3
  16. package/dist/cli/projectConfig.d.ts +16 -0
  17. package/dist/cli/projectConfig.js +61 -0
  18. package/dist/console/AddCommand.js +6 -1
  19. package/dist/console/DiffCommand.js +12 -12
  20. package/dist/lib/icons.d.ts +8 -0
  21. package/dist/lib/icons.js +8 -0
  22. package/dist/lib/image.js +12 -1
  23. package/dist/molecules/Accordion.js +1 -2
  24. package/dist/molecules/Collapsible.js +1 -2
  25. package/dist/molecules/InputOTP.d.ts +12 -0
  26. package/dist/molecules/InputOTP.js +68 -27
  27. package/dist/molecules/Resizable.d.ts +6 -0
  28. package/dist/molecules/Resizable.js +8 -2
  29. package/dist/molecules/index.d.ts +1 -1
  30. package/dist/molecules/index.js +1 -1
  31. package/dist/organisms/AlertDialog.js +4 -5
  32. package/dist/organisms/Chart.d.ts +103 -15
  33. package/dist/organisms/Chart.js +518 -99
  34. package/dist/organisms/Combobox.d.ts +13 -0
  35. package/dist/organisms/Combobox.js +5 -2
  36. package/dist/organisms/Command.js +56 -8
  37. package/dist/organisms/Dialog.js +7 -7
  38. package/dist/organisms/Form.d.ts +15 -0
  39. package/dist/organisms/Form.js +10 -0
  40. package/dist/organisms/Select.d.ts +6 -4
  41. package/dist/organisms/Select.js +1 -0
  42. package/dist/organisms/Sidebar.d.ts +9 -9
  43. package/dist/organisms/Sidebar.js +77 -32
  44. package/dist/organisms/Sonner.d.ts +243 -0
  45. package/dist/organisms/Sonner.js +916 -0
  46. package/dist/organisms/Toaster.d.ts +9 -0
  47. package/dist/organisms/Toaster.js +28 -5
  48. package/dist/organisms/Tooltip.d.ts +4 -0
  49. package/dist/organisms/index.d.ts +7 -1
  50. package/dist/organisms/index.js +7 -1
  51. package/dist/primitives/dismissable.d.ts +11 -4
  52. package/dist/primitives/dismissable.js +8 -6
  53. package/dist/primitives/floating.d.ts +5 -1
  54. package/dist/primitives/floating.js +8 -1
  55. package/dist/primitives/menu.js +2 -1
  56. package/dist/primitives/menuParts.js +3 -3
  57. package/dist/primitives/modalSurface.js +70 -36
  58. package/dist/primitives/portal.d.ts +15 -0
  59. package/dist/primitives/portal.js +18 -1
  60. package/dist/primitives/presence.js +8 -5
  61. package/nebula.css +2 -2
  62. package/package.json +1 -1
  63. package/registry.json +13 -0
  64. package/src/atoms/AspectRatio.ts +21 -6
  65. package/src/atoms/Avatar.ts +54 -7
  66. package/src/atoms/NativeSelect.ts +14 -1
  67. package/src/atoms/Progress.ts +21 -5
  68. package/src/atoms/Switch.ts +7 -1
  69. package/src/cli/add.ts +7 -1
  70. package/src/cli/diff.ts +130 -3
  71. package/src/cli/projectConfig.ts +71 -0
  72. package/src/console/AddCommand.ts +6 -1
  73. package/src/console/DiffCommand.ts +18 -16
  74. package/src/lib/icons.ts +28 -0
  75. package/src/lib/image.ts +13 -1
  76. package/src/molecules/Accordion.ts +1 -2
  77. package/src/molecules/Collapsible.ts +1 -3
  78. package/src/molecules/InputOTP.ts +81 -27
  79. package/src/molecules/Resizable.ts +8 -2
  80. package/src/molecules/index.ts +3 -0
  81. package/src/organisms/AlertDialog.ts +3 -5
  82. package/src/organisms/Chart.ts +633 -125
  83. package/src/organisms/Combobox.ts +18 -2
  84. package/src/organisms/Command.ts +66 -7
  85. package/src/organisms/Dialog.ts +6 -7
  86. package/src/organisms/Form.ts +21 -0
  87. package/src/organisms/Select.ts +7 -4
  88. package/src/organisms/Sidebar.ts +75 -25
  89. package/src/organisms/Sonner.ts +1373 -0
  90. package/src/organisms/Toaster.ts +30 -6
  91. package/src/organisms/Tooltip.ts +4 -0
  92. package/src/organisms/index.ts +29 -0
  93. package/src/primitives/dismissable.ts +16 -8
  94. package/src/primitives/floating.ts +13 -2
  95. package/src/primitives/menu.ts +2 -1
  96. package/src/primitives/menuParts.ts +3 -3
  97. package/src/primitives/modalSurface.ts +77 -40
  98. package/src/primitives/portal.ts +27 -1
  99. package/src/primitives/presence.ts +12 -9
@@ -1,6 +1,11 @@
1
1
  /**
2
2
  * Toaster — transient notifications.
3
3
  *
4
+ * @deprecated shadcn has deprecated its `toast` component in favour of
5
+ * `sonner`, and so does nebula: use `organisms/Sonner.ts` (`nebula add
6
+ * sonner`), whose `Toaster` and `toast` follow sonner's API. This one stays
7
+ * until apps have moved.
8
+ *
4
9
  * shadcn ships two: `sonner`, which wraps a third-party library, and `toast`,
5
10
  * its own, built on Base UI. nebula keeps it in-house with zero dependencies
6
11
  * and follows the SECOND — the shape is the same: one region mounted once near
@@ -36,7 +41,7 @@
36
41
  * single most common complaint about the pattern.
37
42
  */
38
43
 
39
- import { component, html, signal } from "@c9up/aurora";
44
+ import { component, html, onMount, signal } from "@c9up/aurora";
40
45
  import type { Child } from "../lib/children.js";
41
46
  import { cn } from "../lib/cn.js";
42
47
  import { LoaderIcon, XIcon } from "../lib/icons.js";
@@ -180,6 +185,9 @@ function show(options: ToastOptions): ToastId {
180
185
  } else {
181
186
  id = options.id;
182
187
  }
188
+ // No document: the server, rendering one request in a process shared by
189
+ // every user. Kept here, the toast would reach the next user's markup.
190
+ if (typeof document === "undefined") return id;
183
191
  const variant = options.variant ?? "default";
184
192
  const entry: ActiveToast = { ...options, id, variant };
185
193
  queue([...queue(), entry]);
@@ -230,13 +238,18 @@ function optionsOf(message: ToastMessage): Omit<ToastOptions, "id"> {
230
238
  return { title: message };
231
239
  }
232
240
 
241
+ /** A stage given as a function of the outcome, rather than as the message. */
242
+ function isMessageOf<T>(
243
+ message: ToastMessage | ((value: T) => ToastMessage),
244
+ ): message is (value: T) => ToastMessage {
245
+ return typeof message === "function";
246
+ }
247
+
233
248
  function resolveMessage<T>(
234
249
  message: ToastMessage | ((value: T) => ToastMessage),
235
250
  value: T,
236
251
  ): Omit<ToastOptions, "id"> {
237
- if (typeof message === "function") {
238
- return optionsOf((message as (v: T) => ToastMessage)(value));
239
- }
252
+ if (isMessageOf(message)) return optionsOf(message(value));
240
253
  return optionsOf(message);
241
254
  }
242
255
 
@@ -244,6 +257,8 @@ function resolveMessage<T>(
244
257
  * Raise a toast. Returns its id, which `dismiss` accepts.
245
258
  *
246
259
  * Callable from anywhere — no component, no context, no handle.
260
+ *
261
+ * @deprecated Use `toast` from `organisms/Sonner.ts`, shadcn's current toaster.
247
262
  */
248
263
  export const toast = {
249
264
  show,
@@ -345,11 +360,20 @@ const positionClasses: Record<NonNullable<ToasterProps["position"]>, string> = {
345
360
  * `data-nebula-live` marks it as exempt from the `aria-hidden` sweep a modal
346
361
  * performs over its siblings — a toast raised while a dialog is open still has
347
362
  * to be announced.
363
+ *
364
+ * @deprecated Use `Toaster` from `organisms/Sonner.ts`, shadcn's current toaster.
348
365
  */
349
366
  export const Toaster = component<ToasterProps>((props) => {
350
367
  const position = props.position ?? "bottom-right";
351
368
  const closeLabel = props.closeButtonAriaLabel ?? "Dismiss notification";
352
369
  const render = (entry: ActiveToast): Child => renderToast(entry, closeLabel);
370
+ // Empty until mounted, so the server's markup carries no toast and the
371
+ // browser adopts the same empty region before filling it.
372
+ const adopted = signal(false);
373
+ onMount(() => {
374
+ adopted(true);
375
+ });
376
+ const shown = (): readonly ActiveToast[] => (adopted() ? queue() : []);
353
377
 
354
378
  return html`<div
355
379
  data-slot="toaster"
@@ -365,13 +389,13 @@ export const Toaster = component<ToasterProps>((props) => {
365
389
  >
366
390
  <div role="status" aria-live="polite" aria-atomic="false" class="contents">
367
391
  ${() =>
368
- queue()
392
+ shown()
369
393
  .filter((entry) => entry.variant !== "error")
370
394
  .map(render)}
371
395
  </div>
372
396
  <div role="alert" aria-live="assertive" aria-atomic="false" class="contents">
373
397
  ${() =>
374
- queue()
398
+ shown()
375
399
  .filter((entry) => entry.variant === "error")
376
400
  .map(render)}
377
401
  </div>
@@ -294,6 +294,10 @@ export interface TooltipContentProps {
294
294
  /** Which edge of the trigger to sit on. Flips when there is no room. */
295
295
  side?: Side;
296
296
  align?: Align;
297
+ /**
298
+ * Gap past the arrow, in px. `0`, as upstream: the arrow's own length is
299
+ * added by the positioner, the way Radix's popper adds it.
300
+ */
297
301
  sideOffset?: number;
298
302
  class?: Reactive<string>;
299
303
  }
@@ -57,10 +57,16 @@ export {
57
57
  } from "./Carousel.js";
58
58
  export {
59
59
  Chart,
60
+ type ChartBound,
61
+ type ChartCategory,
60
62
  type ChartDatum,
61
63
  type ChartProps,
62
64
  type ChartSeries,
65
+ niceTicks,
66
+ type ValueAxisOptions,
67
+ valueAxis,
63
68
  valueRange,
69
+ visibleCategories,
64
70
  } from "./Chart.js";
65
71
  export {
66
72
  Combobox,
@@ -391,6 +397,29 @@ export {
391
397
  sidebarState,
392
398
  useSidebar,
393
399
  } from "./Sidebar.js";
400
+ /**
401
+ * shadcn's `sonner`. Its file exports `Toaster` and `toast`, as upstream; the
402
+ * barrel renames them because the deprecated `Toaster` below still owns those
403
+ * names until apps have moved — `nebula add sonner` gives the file itself.
404
+ */
405
+ export {
406
+ type Action as SonnerAction,
407
+ type ExternalToast,
408
+ type Offset as SonnerOffset,
409
+ type Position as SonnerPosition,
410
+ type PromiseData as SonnerPromiseData,
411
+ type PromiseExtendedResult as SonnerPromiseExtendedResult,
412
+ type PromiseResult as SonnerPromiseResult,
413
+ type ToastClassnames,
414
+ Toaster as Sonner,
415
+ type ToasterProps as SonnerProps,
416
+ type ToastIcons,
417
+ type ToastId as SonnerToastId,
418
+ type ToastOptions as SonnerToastOptions,
419
+ type ToastT,
420
+ type ToastType,
421
+ toast as sonnerToast,
422
+ } from "./Sonner.js";
394
423
  export {
395
424
  Toaster,
396
425
  type ToasterProps,
@@ -9,8 +9,8 @@
9
9
  *
10
10
  * So layers live in one stack and the rules are applied once, globally:
11
11
  *
12
- * - **Escape** reaches only the topmost layer that accepts it. That is what
13
- * makes Escape close a submenu first and its parent menu second.
12
+ * - **Escape** reaches only the topmost layer, skipping those that pass it
13
+ * through. One that refuses it dismisses nothing below.
14
14
  * - **Pointer outside** walks the stack top-down and stops at the first layer
15
15
  * the event landed inside. Layers above it close, layers below it stay. A
16
16
  * click in a parent menu therefore closes the submenu and nothing else.
@@ -35,8 +35,15 @@ export interface DismissableOptions {
35
35
  * immediately reopen on click.
36
36
  */
37
37
  exclude?: () => ReadonlyArray<HTMLElement | null | undefined>;
38
- /** Escape dismisses this layer when it is topmost. Default `true`. */
39
- escapeKey?: boolean;
38
+ /**
39
+ * Escape dismisses this layer when it is topmost. Default `true`.
40
+ *
41
+ * `false` refuses it: while this layer is on top, Escape dismisses nothing,
42
+ * as a Radix layer that prevents its `onEscapeKeyDown`. `"passthrough"`
43
+ * hands it to the layer below, for a surface that is part of the one under
44
+ * it — a submenu, whose Escape closes the whole menu.
45
+ */
46
+ escapeKey?: boolean | "passthrough";
40
47
  /** A pointer press outside dismisses. Default `true`. */
41
48
  outsidePointer?: boolean;
42
49
  /** Focus moving outside dismisses. Default `false`. */
@@ -110,13 +117,14 @@ function stopListeningIfIdle(): void {
110
117
  function onKeyDown(event: KeyboardEvent): void {
111
118
  if (event.key !== "Escape") return;
112
119
 
113
- // Topmost layer that accepts Escape — not simply the topmost layer. A
114
- // Tooltip stacked over a Popover opts out, and Escape must then reach the
115
- // Popover rather than being swallowed.
120
+ // The topmost layer decides, past the ones that pass Escape through. One
121
+ // that refuses it stops here: falling through would close the sheet behind
122
+ // a dialog that has to be answered.
116
123
  for (let i = stack.length - 1; i >= 0; i -= 1) {
117
124
  const layer = stack[i];
118
125
  if (layer === undefined) continue;
119
- if (layer.escapeKey === false) continue;
126
+ if (layer.escapeKey === "passthrough") continue;
127
+ if (layer.escapeKey === false) return;
120
128
  event.stopPropagation();
121
129
  layer.onDismiss("escape");
122
130
  return;
@@ -55,7 +55,11 @@ export interface PositionOptions {
55
55
  flip?: boolean;
56
56
  /** Slide along the cross axis to stay on screen. Default `true`. */
57
57
  shift?: boolean;
58
- /** Arrow size in px; centres the arrow and keeps it off the corners. */
58
+ /**
59
+ * Arrow size in px; centres the arrow and keeps it off the corners. It is
60
+ * also added to `offset`, so the surface stands an arrow's length away
61
+ * from the anchor (the arrow is square, so its width is its height).
62
+ */
59
63
  arrowSize?: number;
60
64
  /**
61
65
  * Mirror the placement for a right-to-left writing direction.
@@ -105,7 +109,10 @@ export function resolvePosition(
105
109
  viewport: Viewport,
106
110
  options: PositionOptions = {},
107
111
  ): Position {
108
- const offset = options.offset ?? DEFAULT_OFFSET;
112
+ // The arrow stands in the gap, so the gap starts past it — Radix's popper
113
+ // offsets by `sideOffset + arrowHeight` for the same reason. That is why
114
+ // shadcn's `sideOffset = 0` still leaves the arrow clear of the trigger.
115
+ const offset = (options.offset ?? DEFAULT_OFFSET) + (options.arrowSize ?? 0);
109
116
  const padding = options.padding ?? DEFAULT_PADDING;
110
117
  const requested = options.placement ?? "bottom";
111
118
  const [physicalSide, physicalAlign] = splitPlacement(requested);
@@ -453,6 +460,10 @@ export function autoPosition(
453
460
  floating.setAttribute("data-align", position.align);
454
461
 
455
462
  const arrowEl = options.arrow?.();
463
+ // The arrow's `data-[side=…]` classes read the arrow's OWN attribute, so it
464
+ // is written here on every placement: without it none of them applied and
465
+ // the arrow sat in the text, and a flip has to turn it around.
466
+ arrowEl?.setAttribute("data-side", position.side);
456
467
  if (arrowEl && position.arrow) {
457
468
  const { x, y } = position.arrow;
458
469
  arrowEl.style.position = "absolute";
@@ -403,7 +403,8 @@ export function wireMenu(
403
403
  element: () => element,
404
404
  exclude: () => [trigger, panel],
405
405
  onDismiss: () => closeSubmenusFrom(0),
406
- escapeKey: false,
406
+ // Escape in a submenu closes the whole menu, as Radix's does.
407
+ escapeKey: "passthrough",
407
408
  });
408
409
 
409
410
  const inner = wireMenu(element, {
@@ -49,7 +49,7 @@ import {
49
49
  menuSubTriggerClasses,
50
50
  registerSubmenu,
51
51
  } from "./menu.js";
52
- import { portal } from "./portal.js";
52
+ import { portalOnMount } from "./portal.js";
53
53
 
54
54
  /** What a row needs from the menu it is in. */
55
55
  export interface MenuOwner {
@@ -347,10 +347,10 @@ export function createMenuParts(
347
347
  });
348
348
 
349
349
  const Portal = component<MenuPortalProps>((props) => {
350
- const mounted = portal(html`${slot(props.children)}`, {
350
+ portalOnMount(html`${slot(props.children)}`, {
351
351
  container: props.container,
352
+ slot: `${prefix}-portal`,
352
353
  });
353
- mounted.host.setAttribute("data-slot", `${prefix}-portal`);
354
354
  return html``;
355
355
  });
356
356
 
@@ -63,25 +63,59 @@ export interface ModalSurfaceOptions {
63
63
  onClosed?: () => void;
64
64
  }
65
65
 
66
+ interface Armed {
67
+ readonly layer: DismissableLayer;
68
+ readonly trap: FocusTrap;
69
+ readonly restoreSiblings: () => void;
70
+ }
71
+
66
72
  interface Live {
67
73
  readonly mount: Portal;
68
74
  /** Carries `data-state`; the exit animation is watched here. */
69
75
  readonly element: HTMLElement;
70
- readonly layer: DismissableLayer;
71
- readonly trap: FocusTrap;
76
+ readonly panel: HTMLElement;
72
77
  readonly unlock: () => void;
73
- readonly restoreSiblings: () => void;
78
+ /** What makes it modal: `null` once closed, through its exit. */
79
+ armed: Armed | null;
74
80
  cancelExit: (() => void) | null;
75
81
  }
76
82
 
77
83
  export function modalSurface(options: ModalSurfaceOptions): void {
78
84
  let live: Live | null = null;
79
85
 
86
+ function arm(host: HTMLElement, panel: HTMLElement): Armed {
87
+ const restoreSiblings = hideSiblingsFrom(host);
88
+ const trap = focusTrap(panel, {
89
+ initialFocus: () => options.initialFocus?.(panel) ?? null,
90
+ returnFocus: options.returnFocus,
91
+ });
92
+ const layer = dismissable({
93
+ element: () => panel,
94
+ onDismiss: options.onClose,
95
+ escapeKey: options.dismissOnEscape !== false,
96
+ outsidePointer: options.dismissOnOutside !== false,
97
+ outsideFocus: false,
98
+ });
99
+ return { layer, trap, restoreSiblings };
100
+ }
101
+
102
+ function disarm(current: Live): void {
103
+ const armed = current.armed;
104
+ if (armed === null) return;
105
+ current.armed = null;
106
+ armed.layer.remove();
107
+ armed.trap.release();
108
+ armed.restoreSiblings();
109
+ }
110
+
80
111
  function show(): void {
81
112
  if (live !== null) {
113
+ // Reopened while its exit was still playing: the same node comes
114
+ // back, and it is a modal again, not a panel the page reads through.
82
115
  live.cancelExit?.();
83
116
  live.cancelExit = null;
84
117
  live.element.setAttribute("data-state", "open");
118
+ if (live.armed === null) live.armed = arm(live.mount.host, live.panel);
85
119
  return;
86
120
  }
87
121
 
@@ -95,28 +129,13 @@ export function modalSurface(options: ModalSurfaceOptions): void {
95
129
 
96
130
  const panel = options.panel?.(element) ?? element;
97
131
  const unlock = options.lockScroll === false ? () => {} : lockScroll();
98
- const restoreSiblings = hideSiblingsFrom(mount.host);
99
-
100
- const trap = focusTrap(panel, {
101
- initialFocus: () => options.initialFocus?.(panel) ?? null,
102
- returnFocus: options.returnFocus,
103
- });
104
-
105
- const layer = dismissable({
106
- element: () => panel,
107
- onDismiss: options.onClose,
108
- escapeKey: options.dismissOnEscape !== false,
109
- outsidePointer: options.dismissOnOutside !== false,
110
- outsideFocus: false,
111
- });
112
132
 
113
133
  live = {
114
134
  mount,
115
135
  element,
116
- layer,
117
- trap,
136
+ panel,
118
137
  unlock,
119
- restoreSiblings,
138
+ armed: arm(mount.host, panel),
120
139
  cancelExit: null,
121
140
  };
122
141
  options.onOpened?.(panel);
@@ -124,11 +143,9 @@ export function modalSurface(options: ModalSurfaceOptions): void {
124
143
 
125
144
  function hide(): void {
126
145
  const current = live;
127
- if (current === null) return;
146
+ if (current === null || current.armed === null) return;
128
147
 
129
- current.layer.remove();
130
- current.trap.release();
131
- current.restoreSiblings();
148
+ disarm(current);
132
149
  current.element.setAttribute("data-state", "closed");
133
150
  options.onClosed?.();
134
151
 
@@ -146,9 +163,7 @@ export function modalSurface(options: ModalSurfaceOptions): void {
146
163
  if (current === null) return;
147
164
  live = null;
148
165
  current.cancelExit?.();
149
- current.layer.remove();
150
- current.trap.release();
151
- current.restoreSiblings();
166
+ disarm(current);
152
167
  current.unlock();
153
168
  current.mount.close();
154
169
  }
@@ -165,35 +180,57 @@ export function modalSurface(options: ModalSurfaceOptions): void {
165
180
  });
166
181
  }
167
182
 
183
+ /** How many open modals hide each node; it is shown again at zero. */
184
+ const hiddenBy = new WeakMap<Element, number>();
185
+ /** Nodes that were already `aria-hidden` when the first modal reached them. */
186
+ const hiddenBefore = new WeakSet<Element>();
187
+
168
188
  /**
169
189
  * Hide everything except the overlay from assistive technology.
170
190
  *
171
- * Marks each sibling of the portal host, and restores exactly what was there
172
- * before — an element that was *already* `aria-hidden` for its own reasons
173
- * must stay that way after the dialog closes, so the previous value is saved
174
- * rather than the attribute simply removed.
191
+ * Marks each sibling of the portal host. Counted per node, as the
192
+ * `aria-hidden` package Radix modals use does: stacked modals hide the same
193
+ * page, and they close in any order — a confirm that closes its parent sheet
194
+ * before itself is enough — so a node is shown again only when the last
195
+ * modal hiding it lets go. A node the application had hidden itself is never
196
+ * touched.
197
+ *
198
+ * Only siblings of the host, not the whole page: a second modal hides the
199
+ * first one's host along with the page, and shows it again when it closes.
175
200
  *
176
- * Only siblings of the host, not the whole page: a second modal opening over
177
- * the first must not hide it, and it will not, because it appends its own host
178
- * after the first one and only touches what is beside it.
201
+ * The returned release runs once, however many paths reach it.
179
202
  */
180
203
  function hideSiblingsFrom(host: HTMLElement): () => void {
181
204
  const parent = host.parentElement;
182
205
  if (parent === null) return () => {};
183
206
 
184
- const saved: Array<[Element, string | null]> = [];
207
+ const hidden: Element[] = [];
185
208
  for (const sibling of parent.children) {
186
209
  if (sibling === host) continue;
187
210
  // A live region announcing outside the dialog (a toast) is deliberate.
188
211
  if (sibling.hasAttribute("data-nebula-live")) continue;
189
- saved.push([sibling, sibling.getAttribute("aria-hidden")]);
190
- sibling.setAttribute("aria-hidden", "true");
212
+ const count = (hiddenBy.get(sibling) ?? 0) + 1;
213
+ hiddenBy.set(sibling, count);
214
+ hidden.push(sibling);
215
+ const attribute = sibling.getAttribute("aria-hidden");
216
+ const alreadyHidden = attribute !== null && attribute !== "false";
217
+ if (count === 1 && alreadyHidden) hiddenBefore.add(sibling);
218
+ if (!alreadyHidden) sibling.setAttribute("aria-hidden", "true");
191
219
  }
192
220
 
221
+ let released = false;
193
222
  return (): void => {
194
- for (const [element, previous] of saved) {
195
- if (previous === null) element.removeAttribute("aria-hidden");
196
- else element.setAttribute("aria-hidden", previous);
223
+ if (released) return;
224
+ released = true;
225
+ for (const element of hidden) {
226
+ const count = (hiddenBy.get(element) ?? 1) - 1;
227
+ if (count > 0) {
228
+ hiddenBy.set(element, count);
229
+ continue;
230
+ }
231
+ hiddenBy.delete(element);
232
+ if (!hiddenBefore.has(element)) element.removeAttribute("aria-hidden");
233
+ hiddenBefore.delete(element);
197
234
  }
198
235
  };
199
236
  }
@@ -12,7 +12,7 @@
12
12
  * content and the discipline to tear both down together.
13
13
  */
14
14
 
15
- import { render, type TemplateResult } from "@c9up/aurora";
15
+ import { onMount, render, type TemplateResult } from "@c9up/aurora";
16
16
 
17
17
  export interface PortalOptions {
18
18
  /** Where to mount. Defaults to `document.body`. */
@@ -59,3 +59,29 @@ export function portal(
59
59
  },
60
60
  };
61
61
  }
62
+
63
+ export interface PortalPartOptions extends PortalOptions {
64
+ /** The host's `data-slot`, naming the part that put it there. */
65
+ slot: string;
66
+ }
67
+
68
+ /**
69
+ * Portal `content` once the calling component is mounted, and close it when
70
+ * the component unmounts. Call it from a component's setup.
71
+ *
72
+ * Setup also runs inside `renderToString`, where there is no document to
73
+ * append a host to, so the portal waits for the mount: the server renders
74
+ * nothing in place and the content is client-only, as a portal that renders
75
+ * only after its mount effect is. The close rides on the same hook, so a part
76
+ * cannot open a portal without also taking it away.
77
+ */
78
+ export function portalOnMount(
79
+ content: TemplateResult,
80
+ options: PortalPartOptions,
81
+ ): void {
82
+ onMount(() => {
83
+ const mounted = portal(content, options);
84
+ mounted.host.setAttribute("data-slot", options.slot);
85
+ return () => mounted.close();
86
+ });
87
+ }
@@ -408,19 +408,22 @@ function containsKeyframes(rules: CSSRuleList, name: string): boolean {
408
408
  for (const rule of Array.from(rules)) {
409
409
  if (isKeyframesNamed(rule, name)) return true;
410
410
  // `cssRules` on a group rule (media, supports, layer); absent on others.
411
- const nested = Reflect.get(rule, "cssRules");
412
- if (
413
- nested !== null &&
414
- typeof nested === "object" &&
415
- typeof Reflect.get(nested, "length") === "number" &&
416
- containsKeyframes(nested as CSSRuleList, name)
417
- ) {
418
- return true;
419
- }
411
+ const nested: unknown = Reflect.get(rule, "cssRules");
412
+ if (isRuleList(nested) && containsKeyframes(nested, name)) return true;
420
413
  }
421
414
  return false;
422
415
  }
423
416
 
417
+ /** A `CSSRuleList`, read structurally: not every DOM exposes the class. */
418
+ function isRuleList(value: unknown): value is CSSRuleList {
419
+ return (
420
+ typeof value === "object" &&
421
+ value !== null &&
422
+ typeof Reflect.get(value, "length") === "number" &&
423
+ typeof Reflect.get(value, "item") === "function"
424
+ );
425
+ }
426
+
424
427
  /**
425
428
  * Are all the animations this element declares actually defined?
426
429
  *