a11y-elements 1.0.2 → 1.0.3

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 (52) hide show
  1. package/README.md +32 -6
  2. package/dist/a11y.css +42 -9
  3. package/dist/browser/all.js +9 -9
  4. package/dist/browser/{chunk-K7JWBING.js → chunk-2X4DBANG.js} +2 -2
  5. package/dist/browser/{chunk-MB2GJCKB.js → chunk-3AHPI6C5.js} +2 -2
  6. package/dist/browser/{chunk-GOYSEJKF.js → chunk-B6V4HID2.js} +2 -2
  7. package/dist/browser/{chunk-UKFZ7AT5.js → chunk-F4KVDZS3.js} +12 -1
  8. package/dist/browser/chunk-F4KVDZS3.js.map +1 -0
  9. package/dist/browser/{chunk-OMZFF2KR.js → chunk-GYM3EIL3.js} +46 -21
  10. package/dist/browser/chunk-GYM3EIL3.js.map +1 -0
  11. package/dist/browser/{chunk-PO7RAUEO.js → chunk-HJUKOWFZ.js} +5 -3
  12. package/dist/browser/chunk-HJUKOWFZ.js.map +1 -0
  13. package/dist/browser/{chunk-J5T2K5NR.js → chunk-RGO5EYGG.js} +2 -2
  14. package/dist/browser/chunk-WKWX3MMT.js +233 -0
  15. package/dist/browser/chunk-WKWX3MMT.js.map +1 -0
  16. package/dist/browser/{chunk-YQ2VLQAY.js → chunk-YYYJ6D77.js} +15 -1
  17. package/dist/browser/chunk-YYYJ6D77.js.map +1 -0
  18. package/dist/browser/overlays/context-menu/define.js +3 -3
  19. package/dist/browser/overlays/dropdown/define.js +3 -3
  20. package/dist/browser/overlays/notification-banner/define.js +2 -2
  21. package/dist/browser/overlays/popover/define.js +2 -2
  22. package/dist/browser/overlays/snackbar/define.js +2 -2
  23. package/dist/browser/overlays/tooltip/define.js +2 -2
  24. package/dist/core/input-modality.d.ts +21 -0
  25. package/dist/core/input-modality.js +56 -0
  26. package/dist/core/input-modality.js.map +1 -0
  27. package/dist/overlays/core/a11y-anchored-overlay-element.d.ts +4 -0
  28. package/dist/overlays/core/a11y-anchored-overlay-element.js +14 -0
  29. package/dist/overlays/core/a11y-anchored-overlay-element.js.map +1 -1
  30. package/dist/overlays/core/a11y-passive-overlay-element.d.ts +9 -0
  31. package/dist/overlays/core/a11y-passive-overlay-element.js +14 -0
  32. package/dist/overlays/core/a11y-passive-overlay-element.js.map +1 -1
  33. package/dist/overlays/notification-banner/notification-banner.element.d.ts +7 -1
  34. package/dist/overlays/notification-banner/notification-banner.element.js +9 -1
  35. package/dist/overlays/notification-banner/notification-banner.element.js.map +1 -1
  36. package/dist/overlays/snackbar/snackbar.element.d.ts +20 -7
  37. package/dist/overlays/snackbar/snackbar.element.js +55 -20
  38. package/dist/overlays/snackbar/snackbar.element.js.map +1 -1
  39. package/dist/overlays/tooltip/tooltip.element.d.ts +32 -8
  40. package/dist/overlays/tooltip/tooltip.element.js +112 -18
  41. package/dist/overlays/tooltip/tooltip.element.js.map +1 -1
  42. package/package.json +1 -1
  43. package/dist/browser/chunk-OMZFF2KR.js.map +0 -1
  44. package/dist/browser/chunk-PMGHD553.js +0 -124
  45. package/dist/browser/chunk-PMGHD553.js.map +0 -1
  46. package/dist/browser/chunk-PO7RAUEO.js.map +0 -1
  47. package/dist/browser/chunk-UKFZ7AT5.js.map +0 -1
  48. package/dist/browser/chunk-YQ2VLQAY.js.map +0 -1
  49. /package/dist/browser/{chunk-K7JWBING.js.map → chunk-2X4DBANG.js.map} +0 -0
  50. /package/dist/browser/{chunk-MB2GJCKB.js.map → chunk-3AHPI6C5.js.map} +0 -0
  51. /package/dist/browser/{chunk-GOYSEJKF.js.map → chunk-B6V4HID2.js.map} +0 -0
  52. /package/dist/browser/{chunk-J5T2K5NR.js.map → chunk-RGO5EYGG.js.map} +0 -0
package/README.md CHANGED
@@ -1546,11 +1546,21 @@ It's a page region, not an open/close overlay: it fires no open/close events and
1546
1546
  | Option | Default | Description |
1547
1547
  | --- | --- | --- |
1548
1548
  | `type` | `info` | `info`, `success`, `warning` or `error` (`error` uses `role="alert"`). |
1549
- | `position` | `top` | `top` or `bottom`. |
1549
+ | `position` | `--a11y-notification-banner-position`, else `top` | `top` or `bottom`. |
1550
1550
  | `actionText` / `onAction` | — | Adds an action button; clicking it runs `onAction` and dismisses the banner. |
1551
1551
  | `onClose` | — | Called when the banner is dismissed. |
1552
1552
  | `maxStack` | — | Sets `max-stack` on the region (sticky for later banners). |
1553
1553
 
1554
+ To set the default position for every banner, use CSS, like any other style property:
1555
+
1556
+ ```css
1557
+ :root {
1558
+ --a11y-notification-banner-position: bottom;
1559
+ }
1560
+ ```
1561
+
1562
+ It's read each time a banner is shown, so a change applies to the next banners, not to those already on screen. A `position` passed to `show()` wins. Other values, corners included, are ignored.
1563
+
1554
1564
  Classes: `.a11y-notification-banner--info` / `--success` / `--warning` / `--error`, `__message`, `__action`, `__close`.
1555
1565
 
1556
1566
  <details>
@@ -1565,6 +1575,7 @@ Colors come from the shared `--a11y-color-*` tokens (see [Shared tokens](#shared
1565
1575
  | `--a11y-notification-banner-close-font-size` | `1.25rem` |
1566
1576
  | `--a11y-notification-banner-gap` | `1rem` |
1567
1577
  | `--a11y-notification-banner-padding` | `0.75rem 1.5rem` |
1578
+ | `--a11y-notification-banner-position` | `top` |
1568
1579
 
1569
1580
  </details>
1570
1581
 
@@ -1624,7 +1635,8 @@ import { h, raw } from 'a11y-elements/core';
1624
1635
 
1625
1636
  notify('Saved');
1626
1637
  notify('Upload failed', { type: 'error', actionText: 'Retry', onAction: retryUpload });
1627
- notify('Copied to clipboard', { position: 'top', duration: 1500 });
1638
+ notify('Copied to clipboard', { position: 'top-right', duration: 1500 });
1639
+ notify('Draft deleted', { actionText: 'Undo', onAction: restoreDraft, onClose: () => console.log('toast gone') });
1628
1640
  notify(raw('Saved. <a href="/files">View files</a>')); // markup: sanitized, see below
1629
1641
  notify(h('span', null, 'Saved. ', h('a', { href: '/files' }, 'View files'))); // nodes, no parsing at all
1630
1642
  ```
@@ -1635,7 +1647,7 @@ notify(h('span', null, 'Saved. ', h('a', { href: '/files' }, 'View files'))); //
1635
1647
  | `max-stack` | attribute | `3` | How many toasts show at once; the rest wait in a queue and show as earlier ones are dismissed. |
1636
1648
  | `maxStack` | property | `3` | Same as `max-stack`. `setMaxStack(n)` is an alias. |
1637
1649
  | `notify(message, options)` | method | — | Shows a toast (or queues it). |
1638
- | `dismissAll()` | method | — | Removes every showing toast and drops queued ones, without running `onAction`. |
1650
+ | `dismissAll()` | method | — | Removes every showing toast (calling its `onClose`) and drops queued ones silently, without running `onAction`. |
1639
1651
 
1640
1652
  It's a page region, not an open/close overlay: it fires no open/close events and `dismissAllOverlays()` leaves it alone, so toasts outlive a SPA navigation while the region stays in the page. Call `dismissAll()` to clear them. Removing the region from the document (e.g. with `removeOverlaysWithin()`) drops its toasts, queued ones included, and cancels their timers; re-adding it starts empty. A toast enqueued while the region is detached waits until it's back in the page. Like every overlay it moves itself to `<body>`; see [Overlays in a framework](#overlays-in-a-framework) for `removeOverlaysWithin()`.
1641
1653
 
@@ -1646,11 +1658,22 @@ A `message` is text: a string is inserted as text, never parsed. A DOM node (e.g
1646
1658
  | Option | Default | Description |
1647
1659
  | --- | --- | --- |
1648
1660
  | `type` | `info` | `info`, `success`, `warning` or `error` (`error` uses `role="alert"`). |
1649
- | `position` | `bottom` | `bottom` or `top`. |
1661
+ | `position` | `--a11y-snackbar-position`, else `bottom` | `top`, `bottom`, `top-left`, `top-right`, `bottom-left` or `bottom-right`. |
1650
1662
  | `duration` | `3000` (`10000` with an action) | Time on screen, in ms, not counting hover/focus. `Infinity` keeps the toast until it's dismissed. |
1651
1663
  | `actionText` / `onAction` | — | Adds an action button; clicking it dismisses the toast and runs `onAction`. |
1664
+ | `onClose` | — | Called once the toast is gone: × button, action button (after `onAction`), timeout, or `dismissAll()`. Not called for a queued toast that never showed. |
1652
1665
  | `maxStack` | — | Sets `max-stack` on the region (sticky for later toasts). |
1653
1666
 
1667
+ To set the default position for every toast, use CSS, like any other style property:
1668
+
1669
+ ```css
1670
+ :root {
1671
+ --a11y-snackbar-position: top-right;
1672
+ }
1673
+ ```
1674
+
1675
+ It's read each time a toast is shown, so a change applies to the next toasts, not to those already on screen. A `position` passed to `notify()` wins. Toasts in the same position stack; each position has its own stack. Each stack is up to 90% of the viewport wide, so on a narrow screen toasts in different positions can overlap.
1676
+
1654
1677
  Classes: `.a11y-snackbar--info` / `--success` / `--warning` / `--error`.
1655
1678
 
1656
1679
  <details>
@@ -1669,6 +1692,7 @@ Colors come from the shared `--a11y-color-*` tokens (see [Shared tokens](#shared
1669
1692
  | `--a11y-snackbar-gap` | `1rem` |
1670
1693
  | `--a11y-snackbar-offset` | `1rem` |
1671
1694
  | `--a11y-snackbar-padding` | `0.75rem 1.5rem` |
1695
+ | `--a11y-snackbar-position` | `bottom` |
1672
1696
  | `--a11y-snackbar-shadow-blur` | `6px` |
1673
1697
  | `--a11y-snackbar-shadow-color` | `rgba(0, 0, 0, 0.3)` |
1674
1698
  | `--a11y-snackbar-shadow-offset-y` | `2px` |
@@ -1678,7 +1702,9 @@ Colors come from the shared `--a11y-color-*` tokens (see [Shared tokens](#shared
1678
1702
 
1679
1703
  ### `a11y-tooltip`
1680
1704
 
1681
- A short description shown on hover or focus of its anchor, which gets `aria-describedby`. It stays open while the pointer is over it, and Escape hides it. Never traps focus. See [Anchored overlays](#anchored-overlays).
1705
+ A short description shown on mouse hover or keyboard focus of its anchor, which gets `aria-describedby`. It stays open while the pointer is over it, and Escape hides it. Never traps focus. See [Anchored overlays](#anchored-overlays).
1706
+
1707
+ Pressing the anchor hides it, and hover doesn't bring it back until the pointer leaves and returns. On a touch screen a tap doesn't show it, since the tap is the action. Instead, a long press (500 ms) shows it, until the next tap elsewhere or on the anchor. Screen readers still announce the text through `aria-describedby`. Focus shows it only when the keyboard was used last (Tab, or Escape closing a modal that hands focus back), not after a click or tap. Before any input, it follows `:focus-visible`.
1682
1708
 
1683
1709
  ```html
1684
1710
  <button id="save-btn">Save</button>
@@ -1890,4 +1916,4 @@ MIT — see [`LICENSE.txt`](./LICENSE.txt).
1890
1916
 
1891
1917
  ## Support
1892
1918
 
1893
- If you find a11y-elements useful, consider supporting its development via [Ko-fi](https://ko-fi.com/loiskouninef)
1919
+ If you find a11y-elements useful, consider supporting its development on [Ko-fi](https://ko-fi.com/loiskouninef)
package/dist/a11y.css CHANGED
@@ -1461,11 +1461,8 @@ a11y-floating.a11y-floating--scrolled-away {
1461
1461
  }
1462
1462
 
1463
1463
  /* src/overlays/snackbar/snackbar.css */
1464
- .a11y-snackbar-region__bottom,
1465
- .a11y-snackbar-region__top {
1464
+ .a11y-snackbar-region__stack {
1466
1465
  position: fixed;
1467
- left: 50%;
1468
- transform: translateX(-50%);
1469
1466
  display: flex;
1470
1467
  flex-direction: column;
1471
1468
  align-items: stretch;
@@ -1475,16 +1472,26 @@ a11y-floating.a11y-floating--scrolled-away {
1475
1472
  pointer-events: none;
1476
1473
  z-index: var(--a11y-z-snackbar, 400);
1477
1474
  }
1478
- .a11y-snackbar-region__bottom .a11y-snackbar,
1479
- .a11y-snackbar-region__top .a11y-snackbar {
1475
+ .a11y-snackbar-region__stack .a11y-snackbar {
1480
1476
  pointer-events: auto;
1481
1477
  }
1482
- .a11y-snackbar-region__bottom {
1478
+ .a11y-snackbar-region__stack[data-position^=top] {
1479
+ top: var(--a11y-snackbar-offset, 1rem);
1480
+ }
1481
+ .a11y-snackbar-region__stack[data-position^=bottom] {
1483
1482
  bottom: var(--a11y-snackbar-offset, 1rem);
1484
1483
  flex-direction: column-reverse;
1485
1484
  }
1486
- .a11y-snackbar-region__top {
1487
- top: var(--a11y-snackbar-offset, 1rem);
1485
+ .a11y-snackbar-region__stack[data-position$=left] {
1486
+ left: var(--a11y-snackbar-offset, 1rem);
1487
+ }
1488
+ .a11y-snackbar-region__stack[data-position$=right] {
1489
+ right: var(--a11y-snackbar-offset, 1rem);
1490
+ }
1491
+ .a11y-snackbar-region__stack[data-position=top],
1492
+ .a11y-snackbar-region__stack[data-position=bottom] {
1493
+ left: 50%;
1494
+ transform: translateX(-50%);
1488
1495
  }
1489
1496
  .a11y-snackbar {
1490
1497
  position: relative;
@@ -1500,6 +1507,9 @@ a11y-floating.a11y-floating--scrolled-away {
1500
1507
  width: 100%;
1501
1508
  animation: a11y-snackbar-fade-in var(--a11y-snackbar-animation-duration, 0.3s) ease;
1502
1509
  }
1510
+ .a11y-snackbar-region__stack[data-position^=top] .a11y-snackbar {
1511
+ animation-name: a11y-snackbar-fade-in-down;
1512
+ }
1503
1513
  .a11y-snackbar--success {
1504
1514
  background: var(--a11y-color-success, #2e7d32);
1505
1515
  color: var(--a11y-color-text-on-success, var(--a11y-color-text, white));
@@ -1559,6 +1569,16 @@ a11y-floating.a11y-floating--scrolled-away {
1559
1569
  transform: translateY(0);
1560
1570
  }
1561
1571
  }
1572
+ @keyframes a11y-snackbar-fade-in-down {
1573
+ from {
1574
+ opacity: 0;
1575
+ transform: translateY(-8px);
1576
+ }
1577
+ to {
1578
+ opacity: 1;
1579
+ transform: translateY(0);
1580
+ }
1581
+ }
1562
1582
  @media (prefers-reduced-motion: reduce) {
1563
1583
  .a11y-snackbar {
1564
1584
  animation: none;
@@ -1633,6 +1653,19 @@ html.a11y-modal-layer-open .a11y-snackbar-region {
1633
1653
  font-size: var(--a11y-notification-banner-close-font-size, 1.25rem);
1634
1654
  line-height: 1;
1635
1655
  }
1656
+ .a11y-notification-banner-region__bottom .a11y-notification-banner {
1657
+ animation-name: a11y-notification-banner-fade-in-up;
1658
+ }
1659
+ @keyframes a11y-notification-banner-fade-in-up {
1660
+ from {
1661
+ opacity: 0;
1662
+ transform: translateY(8px);
1663
+ }
1664
+ to {
1665
+ opacity: 1;
1666
+ transform: translateY(0);
1667
+ }
1668
+ }
1636
1669
  @keyframes a11y-notification-banner-fade-in {
1637
1670
  from {
1638
1671
  opacity: 0;
@@ -8,18 +8,18 @@ import {
8
8
  import {
9
9
  NotificationBannerElement,
10
10
  showNotificationBanner
11
- } from "./chunk-PO7RAUEO.js";
11
+ } from "./chunk-HJUKOWFZ.js";
12
12
  import {
13
13
  PopoverElement
14
- } from "./chunk-MB2GJCKB.js";
14
+ } from "./chunk-3AHPI6C5.js";
15
15
  import {
16
16
  SnackbarElement,
17
17
  notify
18
- } from "./chunk-OMZFF2KR.js";
19
- import "./chunk-YQ2VLQAY.js";
18
+ } from "./chunk-GYM3EIL3.js";
19
+ import "./chunk-YYYJ6D77.js";
20
20
  import {
21
21
  TooltipElement
22
- } from "./chunk-PMGHD553.js";
22
+ } from "./chunk-WKWX3MMT.js";
23
23
  import {
24
24
  TabsElement
25
25
  } from "./chunk-4V5TTMP4.js";
@@ -34,15 +34,15 @@ import {
34
34
  } from "./chunk-OB2NQV77.js";
35
35
  import {
36
36
  ContextMenuElement
37
- } from "./chunk-GOYSEJKF.js";
37
+ } from "./chunk-B6V4HID2.js";
38
38
  import {
39
39
  DrawerElement
40
40
  } from "./chunk-6BEWDDER.js";
41
41
  import {
42
42
  DropdownElement
43
- } from "./chunk-K7JWBING.js";
44
- import "./chunk-J5T2K5NR.js";
45
- import "./chunk-UKFZ7AT5.js";
43
+ } from "./chunk-2X4DBANG.js";
44
+ import "./chunk-RGO5EYGG.js";
45
+ import "./chunk-F4KVDZS3.js";
46
46
  import {
47
47
  EmergencyDialogElement
48
48
  } from "./chunk-2TPJ5MVQ.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  A11yMenuOverlayElement
3
- } from "./chunk-J5T2K5NR.js";
3
+ } from "./chunk-RGO5EYGG.js";
4
4
  import {
5
5
  nextId
6
6
  } from "./chunk-Q4TMA3P7.js";
@@ -89,4 +89,4 @@ defineElement("a11y-dropdown", DropdownElement);
89
89
  export {
90
90
  DropdownElement
91
91
  };
92
- //# sourceMappingURL=chunk-K7JWBING.js.map
92
+ //# sourceMappingURL=chunk-2X4DBANG.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  A11yAnchoredOverlayElement
3
- } from "./chunk-UKFZ7AT5.js";
3
+ } from "./chunk-F4KVDZS3.js";
4
4
  import {
5
5
  nextId
6
6
  } from "./chunk-Q4TMA3P7.js";
@@ -62,4 +62,4 @@ defineElement("a11y-popover", PopoverElement);
62
62
  export {
63
63
  PopoverElement
64
64
  };
65
- //# sourceMappingURL=chunk-MB2GJCKB.js.map
65
+ //# sourceMappingURL=chunk-3AHPI6C5.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  A11yMenuOverlayElement
3
- } from "./chunk-J5T2K5NR.js";
3
+ } from "./chunk-RGO5EYGG.js";
4
4
  import {
5
5
  defineElement,
6
6
  doc
@@ -78,4 +78,4 @@ defineElement("a11y-context-menu", ContextMenuElement);
78
78
  export {
79
79
  ContextMenuElement
80
80
  };
81
- //# sourceMappingURL=chunk-GOYSEJKF.js.map
81
+ //# sourceMappingURL=chunk-B6V4HID2.js.map
@@ -29,6 +29,11 @@ var A11yAnchoredOverlayElement = class extends A11yOverlayElement {
29
29
  _focusTrap = null;
30
30
  _boundOutsideClick = null;
31
31
  _outsideClickTimer = null;
32
+ /** The `<html>` given the no-op click listener, kept to remove it from the same element. */
33
+ _tapTargetRoot = null;
34
+ /** Per instance: a shared function would be added once, and the first overlay to close would remove it for all. */
35
+ _noopClick = () => {
36
+ };
32
37
  _boundKeyDown = null;
33
38
  _boundReposition = null;
34
39
  _resizeObserver = null;
@@ -237,6 +242,8 @@ var A11yAnchoredOverlayElement = class extends A11yOverlayElement {
237
242
  this._outsideClickTimer = setTimeout(() => {
238
243
  doc.addEventListener("click", this._boundOutsideClick, true);
239
244
  }, 0);
245
+ this._tapTargetRoot = doc.documentElement;
246
+ this._tapTargetRoot.addEventListener("click", this._noopClick);
240
247
  if (!this.wantsFocusTrap()) {
241
248
  this._boundKeyDown = (e) => {
242
249
  if (e.key !== "Escape" || e.defaultPrevented) return;
@@ -256,6 +263,10 @@ var A11yAnchoredOverlayElement = class extends A11yOverlayElement {
256
263
  doc.removeEventListener("click", this._boundOutsideClick, true);
257
264
  this._boundOutsideClick = null;
258
265
  }
266
+ if (this._tapTargetRoot) {
267
+ this._tapTargetRoot.removeEventListener("click", this._noopClick);
268
+ this._tapTargetRoot = null;
269
+ }
259
270
  if (this._boundKeyDown) {
260
271
  doc.removeEventListener("keydown", this._boundKeyDown, true);
261
272
  this._boundKeyDown = null;
@@ -285,4 +296,4 @@ var A11yAnchoredOverlayElement = class extends A11yOverlayElement {
285
296
  export {
286
297
  A11yAnchoredOverlayElement
287
298
  };
288
- //# sourceMappingURL=chunk-UKFZ7AT5.js.map
299
+ //# sourceMappingURL=chunk-F4KVDZS3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/overlays/core/a11y-anchored-overlay-element.ts"],"sourcesContent":["import { A11yOverlayElement } from '../../core/a11y-overlay-element.js';\nimport {\n computedZIndex,\n findOverlayChromeRoot,\n getPortalOrigin,\n hasOverlayOpenedAfter,\n isInsideOverlayOpenedAfter,\n} from '../../core/overlay-registry.js';\nimport { FocusTrapHelper, type IFocusTrapOptions } from '../../core/focus-trap.js';\nimport { whenTransitionDone } from '../../core/transition.js';\nimport { doc } from '../../core/safe-dom.js';\n\nexport type AnchoredSide = 'top' | 'bottom' | 'left' | 'right';\nexport type AnchoredAlign = 'start' | 'end';\nexport type AnchoredPlacement = AnchoredSide | `${AnchoredSide}-${AnchoredAlign}`;\n\n/**\n * Base for overlays positioned relative to an anchor element or point\n * (popover, tooltip, dropdown, and — via `A11yMenuOverlayElement` —\n * dropdown-menu/context-menu). `this` (the custom element, holding the\n * consumer's own light-DOM content) is moved into a `wrapper` div appended\n * to `document.body` on show, and moved back out before the wrapper is torn\n * down on hide — the same portal dance `A11yOverlayElement` documents,\n * scoped to this overlay family's extra positioning chrome.\n *\n * The flip/clamp positioning math and the deferred-outside-click dismissal\n * are ported near-verbatim from the old framework version — both were\n * already framework-free hand-rolled DOM/geometry code with nothing to do\n * with the old base classes.\n */\nexport abstract class A11yAnchoredOverlayElement extends A11yOverlayElement {\n static override get observedAttributes(): string[] {\n return ['open', 'anchor', 'placement', 'offset'];\n }\n\n protected _wrapper: HTMLElement | null = null;\n private _anchorEl: HTMLElement | null = null;\n private _anchorRect: DOMRect | null = null;\n private _focusTrap: FocusTrapHelper | null = null;\n private _boundOutsideClick: ((e: MouseEvent) => void) | null = null;\n private _outsideClickTimer: ReturnType<typeof setTimeout> | null = null;\n /** The `<html>` given the no-op click listener, kept to remove it from the same element. */\n private _tapTargetRoot: HTMLElement | null = null;\n /** Per instance: a shared function would be added once, and the first overlay to close would remove it for all. */\n private _noopClick = (): void => {};\n private _boundKeyDown: ((e: KeyboardEvent) => void) | null = null;\n private _boundReposition: (() => void) | null = null;\n private _resizeObserver: ResizeObserver | null = null;\n private _pendingHide: (() => void) | null = null;\n private _cancelHideWait: (() => void) | null = null;\n\n /** The element to anchor to: an explicit `.anchorElement` property, or the `anchor=\"<id>\"` attribute. */\n get anchorElement(): HTMLElement | null {\n if (this._anchorEl) return this._anchorEl;\n const id = this.getAttribute('anchor');\n return id ? doc.getElementById(id) : null;\n }\n\n set anchorElement(el: HTMLElement | null) {\n this._anchorEl = el;\n this._anchorRect = null;\n this.onAnchorChanged();\n }\n\n /**\n * Called whenever the anchor may have changed (`anchor` attribute,\n * `.anchorElement` property). Subclasses that wire listeners/ARIA onto the\n * anchor re-bind here — call `super.onAnchorChanged()`.\n */\n protected onAnchorChanged(): void {\n if (this._wrapper) this.updatePosition();\n }\n\n protected override onAttributeChanged(name: string): void {\n if (name === 'anchor') this.onAnchorChanged();\n else if (this._wrapper) this.updatePosition(); // placement / offset\n }\n\n /** Anchors to a fixed viewport point instead of an element (used by context menus). */\n protected setAnchorPoint(x: number, y: number): void {\n this._anchorEl = null;\n this._anchorRect = new DOMRect(x, y, 0, 0);\n }\n\n get placement(): AnchoredPlacement {\n return (this.getAttribute('placement') as AnchoredPlacement | null) ?? 'bottom';\n }\n\n get offset(): number {\n return this.numberAttr('offset', 8);\n }\n\n /** Override to force focus-trapping on/off/conditional (menus always force it off; popovers derive it from `interactive`). */\n protected wantsFocusTrap(): boolean {\n return this.boolAttr('trap-focus');\n }\n\n protected createWrapper(): HTMLElement {\n const el = doc.createElement('div');\n el.className = 'a11y-anchored-overlay-wrapper';\n return el;\n }\n\n protected getContentClass(): string {\n return 'a11y-anchored-overlay-content';\n }\n\n /**\n * What this overlay was opened from, to tell whether it's nested in another\n * overlay (a tooltip in a modal): the anchor, else where it was authored.\n */\n protected nestingTarget(): Node | null {\n return this.anchorElement ?? getPortalOrigin(this);\n }\n\n /**\n * It lives on `<body>`, so its own z-index (tooltip 320…) would put it\n * behind the overlay it was opened from (modal 510…). Nested, it records\n * that overlay's z-index as `--a11y-z-parent`, and its CSS stacks it\n * `--a11y-z-nested-<name>` above that.\n */\n private _markNesting(wrapper: HTMLElement): void {\n const root = findOverlayChromeRoot(this.nestingTarget(), this);\n const z = root && root !== wrapper ? computedZIndex(root) : null;\n if (z === null) return;\n wrapper.classList.add('a11y-is-nested');\n wrapper.style.setProperty('--a11y-z-parent', String(z));\n }\n\n protected override _show(): void {\n // Reopened mid-close: complete that close first (see A11yModalOverlayElement).\n this._flushPendingHide();\n // Re-shown while already open (e.g. a context menu re-right-clicked\n // elsewhere): drop the current chrome and its listeners, then rebuild.\n if (this._wrapper) this._teardownChrome();\n\n const wrapper = this.createWrapper();\n this._markNesting(wrapper);\n doc.body.appendChild(wrapper);\n this.classList.add(this.getContentClass());\n this._moveSelfTo(wrapper); // see A11yOverlayElement's class doc on why this isn't a raw appendChild\n this._wrapper = wrapper;\n\n this.updatePosition();\n this._bindDismissListeners(wrapper);\n this._bindRepositionListeners(wrapper);\n\n if (this.wantsFocusTrap()) {\n this._focusTrap = new FocusTrapHelper({ container: wrapper, options: this._focusTrapOptions() });\n this._focusTrap.activate();\n }\n\n // Skipped if closed before the frame: adding it then would animate a closing overlay back in.\n requestAnimationFrame(() => {\n if (this._wrapper === wrapper) wrapper.classList.add('a11y-is-open');\n });\n if (!this._isShowing) this._onShown();\n }\n\n protected override _hide(opts?: { immediate?: boolean }): void {\n // Focus already moved elsewhere on the page (e.g. the outside click that closes this landed\n // on a text field): leave it there rather than pulling it back to the trigger.\n const active = doc.activeElement;\n const focusMovedAway = !!this._wrapper && !!active && active !== doc.body && !this._wrapper.contains(active);\n this._unbindActiveListeners({ returnFocus: !focusMovedAway });\n\n const wrapper = this._wrapper;\n if (!wrapper) {\n if (this._pendingHide) {\n if (opts?.immediate) this._flushPendingHide();\n } else if (this._isShowing) {\n this._onHidden();\n }\n return;\n }\n this._wrapper = null;\n\n const finish = (): void => {\n this._pendingHide = null;\n this._cancelHideWait = null;\n this.classList.remove(this.getContentClass());\n // Detach from the wrapper before it's removed — unless the consumer is\n // removing this element from the document, which must stay removed.\n if (!this._detaching) this._moveSelfTo(doc.body);\n wrapper.remove();\n this._onHidden();\n };\n this._pendingHide = finish;\n\n if (opts?.immediate) {\n finish();\n return;\n }\n wrapper.classList.remove('a11y-is-open');\n this._cancelHideWait = whenTransitionDone(wrapper, finish);\n }\n\n private _flushPendingHide(): void {\n const finish = this._pendingHide;\n if (!finish) return;\n this._cancelHideWait?.();\n finish();\n }\n\n private _unbindActiveListeners(opts?: { returnFocus?: boolean }): void {\n this._focusTrap?.deactivate(opts);\n this._focusTrap = null;\n this._unbindDismissListeners();\n this._unbindRepositionListeners();\n }\n\n private _teardownChrome(): void {\n this._unbindActiveListeners();\n this._moveSelfTo(doc.body);\n this._wrapper?.remove();\n this._wrapper = null;\n }\n\n protected _focusTrapOptions(): IFocusTrapOptions {\n return { onDeactivate: () => this.close('escape') };\n }\n\n updatePosition(): void {\n const anchorRect = this._getAnchorRect();\n if (!anchorRect || !this._wrapper) return;\n\n const wrapperRect = this._wrapper.getBoundingClientRect();\n const viewportWidth = doc.documentElement.clientWidth;\n const viewportHeight = doc.documentElement.clientHeight;\n\n const { placement, top, left } = this._computePosition(anchorRect, wrapperRect, viewportWidth, viewportHeight);\n\n this._wrapper.setAttribute('data-placement', placement);\n this._wrapper.style.top = `${top}px`;\n this._wrapper.style.left = `${left}px`;\n }\n\n private _getAnchorRect(): DOMRect | null {\n if (this.anchorElement) return this.anchorElement.getBoundingClientRect();\n return this._anchorRect;\n }\n\n private _computePosition(\n anchorRect: DOMRect,\n wrapperRect: DOMRect,\n viewportWidth: number,\n viewportHeight: number,\n ): { placement: string; top: number; left: number } {\n const offset = this.offset;\n const [side, align] = this.placement.split('-') as [AnchoredSide, AnchoredAlign | undefined];\n\n const opposite: Record<AnchoredSide, AnchoredSide> = { top: 'bottom', bottom: 'top', left: 'right', right: 'left' };\n\n const fits = (s: AnchoredSide): boolean => {\n switch (s) {\n case 'top':\n return anchorRect.top - offset - wrapperRect.height >= 0;\n case 'bottom':\n return anchorRect.bottom + offset + wrapperRect.height <= viewportHeight;\n case 'left':\n return anchorRect.left - offset - wrapperRect.width >= 0;\n case 'right':\n return anchorRect.right + offset + wrapperRect.width <= viewportWidth;\n }\n };\n\n const resolvedSide = !fits(side) && fits(opposite[side]) ? opposite[side] : side;\n\n let top: number;\n let left: number;\n\n if (resolvedSide === 'top' || resolvedSide === 'bottom') {\n top = resolvedSide === 'top' ? anchorRect.top - offset - wrapperRect.height : anchorRect.bottom + offset;\n left = this._alignCrossAxis(align, anchorRect.left, anchorRect.right, wrapperRect.width);\n left = this._clamp(left, offset, viewportWidth - wrapperRect.width - offset);\n } else {\n left = resolvedSide === 'left' ? anchorRect.left - offset - wrapperRect.width : anchorRect.right + offset;\n top = this._alignCrossAxis(align, anchorRect.top, anchorRect.bottom, wrapperRect.height);\n top = this._clamp(top, offset, viewportHeight - wrapperRect.height - offset);\n }\n\n const placement = align ? `${resolvedSide}-${align}` : resolvedSide;\n return { placement, top, left };\n }\n\n private _alignCrossAxis(align: AnchoredAlign | undefined, anchorStart: number, anchorEnd: number, wrapperSize: number): number {\n if (align === 'start') return anchorStart;\n if (align === 'end') return anchorEnd - wrapperSize;\n return anchorStart + (anchorEnd - anchorStart) / 2 - wrapperSize / 2;\n }\n\n private _clamp(value: number, min: number, max: number): number {\n if (max < min) return min;\n return Math.min(Math.max(value, min), max);\n }\n\n private _bindDismissListeners(wrapper: HTMLElement): void {\n this._boundOutsideClick = (e: MouseEvent): void => {\n const target = e.target as Node;\n if (wrapper.contains(target) || this.anchorElement?.contains(target)) return;\n if (isInsideOverlayOpenedAfter(this, target)) return; // e.g. a dropdown opened from inside this popover\n this.close('outside-click');\n };\n // Deferred so the same click/tap that opened the overlay doesn't immediately close it.\n // Capture phase: decided before the click's own handlers run — a menu item's handler closes\n // its dropdown, and once closed the dropdown no longer counts as \"opened on top of this one\".\n this._outsideClickTimer = setTimeout(() => {\n doc.addEventListener('click', this._boundOutsideClick!, true);\n }, 0);\n // WebKit with a touch screen (iOS Safari, Linux WebKit) fires no `click` for a tap\n // unless the element tapped or one of its parents has a click listener: one on\n // `document` doesn't count. On <html>, not <body>: a tap below a short <body> lands on <html>.\n // Without this, a tap on empty page space wouldn't close the overlay.\n this._tapTargetRoot = doc.documentElement;\n this._tapTargetRoot.addEventListener('click', this._noopClick);\n\n if (!this.wantsFocusTrap()) {\n // Capture phase, before a focus trap's own document listener: Escape\n // dismisses this overlay only (e.g. a tooltip on a button inside a\n // modal), and `preventDefault()` tells every other handler it's taken.\n this._boundKeyDown = (e: KeyboardEvent): void => {\n if (e.key !== 'Escape' || e.defaultPrevented) return;\n // Capture listeners run in the order they were added, i.e. oldest overlay first:\n // leave Escape to whatever was opened on top of this one.\n if (hasOverlayOpenedAfter(this)) return;\n e.preventDefault();\n this.close('escape');\n };\n doc.addEventListener('keydown', this._boundKeyDown, true);\n }\n }\n\n private _unbindDismissListeners(): void {\n if (this._outsideClickTimer) {\n clearTimeout(this._outsideClickTimer);\n this._outsideClickTimer = null;\n }\n if (this._boundOutsideClick) {\n doc.removeEventListener('click', this._boundOutsideClick, true);\n this._boundOutsideClick = null;\n }\n if (this._tapTargetRoot) {\n this._tapTargetRoot.removeEventListener('click', this._noopClick);\n this._tapTargetRoot = null;\n }\n if (this._boundKeyDown) {\n doc.removeEventListener('keydown', this._boundKeyDown, true);\n this._boundKeyDown = null;\n }\n }\n\n private _bindRepositionListeners(wrapper: HTMLElement): void {\n this._boundReposition = () => this.updatePosition();\n window.addEventListener('scroll', this._boundReposition, true);\n window.addEventListener('resize', this._boundReposition);\n\n if (typeof ResizeObserver !== 'undefined') {\n this._resizeObserver = new ResizeObserver(this._boundReposition);\n if (this.anchorElement) this._resizeObserver.observe(this.anchorElement);\n this._resizeObserver.observe(wrapper);\n }\n }\n\n private _unbindRepositionListeners(): void {\n if (this._boundReposition) {\n window.removeEventListener('scroll', this._boundReposition, true);\n window.removeEventListener('resize', this._boundReposition);\n this._boundReposition = null;\n }\n this._resizeObserver?.disconnect();\n this._resizeObserver = null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8BO,IAAe,6BAAf,cAAkD,mBAAmB;AAAA,EAC1E,WAAoB,qBAA+B;AACjD,WAAO,CAAC,QAAQ,UAAU,aAAa,QAAQ;AAAA,EACjD;AAAA,EAEU,WAA+B;AAAA,EACjC,YAAgC;AAAA,EAChC,cAA8B;AAAA,EAC9B,aAAqC;AAAA,EACrC,qBAAuD;AAAA,EACvD,qBAA2D;AAAA;AAAA,EAE3D,iBAAqC;AAAA;AAAA,EAErC,aAAa,MAAY;AAAA,EAAC;AAAA,EAC1B,gBAAqD;AAAA,EACrD,mBAAwC;AAAA,EACxC,kBAAyC;AAAA,EACzC,eAAoC;AAAA,EACpC,kBAAuC;AAAA;AAAA,EAG/C,IAAI,gBAAoC;AACtC,QAAI,KAAK,UAAW,QAAO,KAAK;AAChC,UAAM,KAAK,KAAK,aAAa,QAAQ;AACrC,WAAO,KAAK,IAAI,eAAe,EAAE,IAAI;AAAA,EACvC;AAAA,EAEA,IAAI,cAAc,IAAwB;AACxC,SAAK,YAAY;AACjB,SAAK,cAAc;AACnB,SAAK,gBAAgB;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,kBAAwB;AAChC,QAAI,KAAK,SAAU,MAAK,eAAe;AAAA,EACzC;AAAA,EAEmB,m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,UAAU,KAAK,gBAAgB;AAEvD,QAAI,OAAO,mBAAmB,aAAa;AACzC,WAAK,kBAAkB,IAAI,eAAe,KAAK,gBAAgB;AAC/D,UAAI,KAAK,cAAe,MAAK,gBAAgB,QAAQ,KAAK,aAAa;AACvE,WAAK,gBAAgB,QAAQ,OAAO;AAAA,IACtC;AAAA,EACF;AAAA,EAEQ,6BAAmC;AACzC,QAAI,KAAK,kBAAkB;AACzB,aAAO,oBAAoB,UAAU,KAAK,kBAAkB,IAAI;AAChE,aAAO,oBAAoB,UAAU,KAAK,gBAAgB;AAC1D,WAAK,mBAAmB;AAAA,IAC1B;AACA,SAAK,iBAAiB,WAAW;AACjC,SAAK,kBAAkB;AAAA,EACzB;AACF;","names":[]}
@@ -1,6 +1,7 @@
1
1
  import {
2
- A11yPassiveOverlayElement
3
- } from "./chunk-YQ2VLQAY.js";
2
+ A11yPassiveOverlayElement,
3
+ PASSIVE_OVERLAY_POSITIONS
4
+ } from "./chunk-YYYJ6D77.js";
4
5
  import {
5
6
  h
6
7
  } from "./chunk-KVUJT6BC.js";
@@ -12,8 +13,9 @@ import {
12
13
 
13
14
  // src/overlays/snackbar/snackbar.element.ts
14
15
  var SnackbarElement = class extends A11yPassiveOverlayElement {
15
- _bottomContainer;
16
- _topContainer;
16
+ /** One container per position, created on first use. */
17
+ _containers = /* @__PURE__ */ new Map();
18
+ _active = [];
17
19
  static get observedAttributes() {
18
20
  return [...super.observedAttributes, "dismiss-label"];
19
21
  }
@@ -34,21 +36,33 @@ var SnackbarElement = class extends A11yPassiveOverlayElement {
34
36
  connectedCallback() {
35
37
  super.connectedCallback();
36
38
  this.classList.add("a11y-snackbar-region");
37
- if (!this._bottomContainer) {
38
- this._bottomContainer = doc.createElement("div");
39
- this._bottomContainer.className = "a11y-snackbar-region__bottom";
40
- this._topContainer = doc.createElement("div");
41
- this._topContainer.className = "a11y-snackbar-region__top";
42
- this.append(this._bottomContainer, this._topContainer);
43
- }
44
39
  this._drainQueue();
45
40
  }
46
- /** Removes every showing toast and drops queued ones, without calling `onAction`. */
41
+ _container(position) {
42
+ let container = this._containers.get(position);
43
+ if (!container) {
44
+ container = doc.createElement("div");
45
+ container.className = `a11y-snackbar-region__stack${position === "top" || position === "bottom" ? ` a11y-snackbar-region__${position}` : ""}`;
46
+ container.dataset.position = position;
47
+ this._containers.set(position, container);
48
+ this.append(container);
49
+ }
50
+ return container;
51
+ }
52
+ /**
53
+ * Removes every showing toast (calling its `onClose`) and drops queued
54
+ * ones silently, without calling `onAction`.
55
+ */
47
56
  dismissAll() {
48
57
  this._queue = [];
49
58
  this._cancelAutoDismissTimers();
50
- this.querySelectorAll(".a11y-snackbar").forEach((toast) => toast.remove());
59
+ const toClose = this._active;
60
+ this._active = [];
51
61
  this._activeCount = 0;
62
+ toClose.forEach(({ el, onClose }) => {
63
+ el.remove();
64
+ onClose?.();
65
+ });
52
66
  }
53
67
  _onRemoved() {
54
68
  this.dismissAll();
@@ -61,14 +75,15 @@ var SnackbarElement = class extends A11yPassiveOverlayElement {
61
75
  position: options.position,
62
76
  duration: options.duration,
63
77
  actionText: options.actionText,
64
- onAction: options.onAction
78
+ onAction: options.onAction,
79
+ onClose: options.onClose
65
80
  });
66
81
  }
67
82
  _showItem(item) {
68
83
  const type = item.type ?? "info";
69
- const position = item.position ?? "bottom";
84
+ const position = (item.position && PASSIVE_OVERLAY_POSITIONS.includes(item.position) ? item.position : void 0) ?? this._cssPosition("--a11y-snackbar-position", PASSIVE_OVERLAY_POSITIONS) ?? "bottom";
70
85
  const duration = item.duration ?? (item.actionText ? 1e4 : 3e3);
71
- const container = position === "bottom" ? this._bottomContainer : this._topContainer;
86
+ const container = this._container(position);
72
87
  const el = doc.createElement("div");
73
88
  el.className = `a11y-snackbar a11y-snackbar--${type}`;
74
89
  el.setAttribute("role", type === "error" ? "alert" : "status");
@@ -78,15 +93,25 @@ var SnackbarElement = class extends A11yPassiveOverlayElement {
78
93
  if (item.actionText) el.append(h("button", { type: "button", class: "a11y-snackbar__action" }, item.actionText));
79
94
  el.append(h("button", { type: "button", class: "a11y-snackbar__close", "aria-label": this.dismissLabel }, "\xD7"));
80
95
  container.appendChild(el);
81
- const cancelAutoDismiss = this._autoDismiss(el, duration, () => this._onItemDismissed());
82
- const dismiss = () => {
83
- cancelAutoDismiss();
96
+ const entry = { el, onClose: item.onClose, cancelAutoDismiss: () => {
97
+ } };
98
+ this._active.push(entry);
99
+ const remove = () => {
100
+ if (!this._active.includes(entry)) return false;
101
+ entry.cancelAutoDismiss();
84
102
  el.remove();
103
+ this._active = this._active.filter((a) => a !== entry);
85
104
  this._onItemDismissed();
105
+ return true;
106
+ };
107
+ const dismiss = () => {
108
+ if (remove()) item.onClose?.();
86
109
  };
110
+ entry.cancelAutoDismiss = this._autoDismiss(el, duration, dismiss);
87
111
  el.querySelector(".a11y-snackbar__action")?.addEventListener("click", () => {
88
- dismiss();
112
+ if (!remove()) return;
89
113
  item.onAction?.();
114
+ item.onClose?.();
90
115
  });
91
116
  el.querySelector(".a11y-snackbar__close")?.addEventListener("click", dismiss);
92
117
  }
@@ -112,4 +137,4 @@ export {
112
137
  SnackbarElement,
113
138
  notify
114
139
  };
115
- //# sourceMappingURL=chunk-OMZFF2KR.js.map
140
+ //# sourceMappingURL=chunk-GYM3EIL3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/overlays/snackbar/snackbar.element.ts","../../src/overlays/snackbar/define.ts"],"sourcesContent":["import {\n A11yPassiveOverlayElement,\n PASSIVE_OVERLAY_POSITIONS,\n type PassiveOverlayItem,\n type PassiveOverlayPosition,\n} from '../core/a11y-passive-overlay-element.js';\nimport { getString } from '../../core/strings.js';\nimport { h, type Content } from '../../core/dom.js';\nimport { doc } from '../../core/safe-dom.js';\n\nexport type SnackbarType = 'info' | 'success' | 'error' | 'warning';\n\nexport interface NotifyOptions {\n type?: SnackbarType;\n /** Defaults to `--a11y-snackbar-position` from CSS, else `bottom`. */\n position?: PassiveOverlayPosition;\n duration?: number;\n actionText?: string;\n onAction?: () => void;\n /** Called once the toast is gone: × button, action button (after `onAction`), timeout or `dismissAll()`. */\n onClose?: () => void;\n /** Sets the concurrency limit for this and all future items — sticky on the shared region, same as the `max-stack` attribute. */\n maxStack?: number;\n}\n\ninterface SnackbarItem extends PassiveOverlayItem {\n type?: SnackbarType;\n onClose?: () => void;\n}\n\ninterface ActiveToast {\n el: HTMLElement;\n onClose?: () => void;\n cancelAutoDismiss: () => void;\n}\n\n/**\n * A toast notification region. Auto-dismisses after `duration`ms — default\n * 3000, or 10000 when the toast has an action button (time to reach it) —\n * paused while the toast is hovered or focused. Place one `<a11y-snackbar></a11y-snackbar>` anywhere in your page\n * (it portals itself to `document.body`), then call `.notify(message, options)`\n * on it — or skip placing one entirely and use the `notify()` convenience\n * export from this module, which finds-or-creates one automatically.\n *\n * Each toast shows at its `position` option, else at the position set in CSS\n * with `--a11y-snackbar-position` (`top`, `bottom`, `top-left`, `top-right`,\n * `bottom-left` or `bottom-right`; read when the toast is shown), else at the\n * bottom. Every toast has a round × close button in its top-right corner that\n * dismisses it early (without calling `onAction`). It's named by\n * `dismiss-label=\"…\"`, else `setStrings({ dismiss })`. `onClose` runs\n * whenever a toast that was shown goes away, timeout included.\n *\n * While the region stays in the page, toasts finish their own timers\n * regardless of navigation (call `dismissAll()` to clear them). Removing the\n * region from the document drops its toasts, queued ones included, and\n * cancels their timers; re-adding it starts empty.\n */\nexport class SnackbarElement extends A11yPassiveOverlayElement<SnackbarItem> {\n /** One container per position, created on first use. */\n private _containers = new Map<PassiveOverlayPosition, HTMLElement>();\n private _active: ActiveToast[] = [];\n\n static override get observedAttributes(): string[] {\n return [...super.observedAttributes, 'dismiss-label'];\n }\n\n /** The accessible name of each toast's close button. */\n get dismissLabel(): string {\n return this.stringAttr('dismiss-label', getString('dismiss'));\n }\n\n override attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void {\n super.attributeChangedCallback(name, oldValue, newValue);\n if (name === 'dismiss-label' && oldValue !== newValue) this._relabelDismissButtons();\n }\n\n protected override onStringsChange(): void {\n this._relabelDismissButtons();\n }\n\n private _relabelDismissButtons(): void {\n for (const btn of this.querySelectorAll('.a11y-snackbar__close')) btn.setAttribute('aria-label', this.dismissLabel);\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.classList.add('a11y-snackbar-region');\n this._drainQueue();\n }\n\n private _container(position: PassiveOverlayPosition): HTMLElement {\n let container = this._containers.get(position);\n if (!container) {\n container = doc.createElement('div');\n // `__top` / `__bottom`: the class names of the two containers before corners existed.\n container.className = `a11y-snackbar-region__stack${position === 'top' || position === 'bottom' ? ` a11y-snackbar-region__${position}` : ''}`;\n container.dataset.position = position;\n this._containers.set(position, container);\n this.append(container);\n }\n return container;\n }\n\n /**\n * Removes every showing toast (calling its `onClose`) and drops queued\n * ones silently, without calling `onAction`.\n */\n dismissAll(): void {\n this._queue = [];\n this._cancelAutoDismissTimers();\n const toClose = this._active;\n this._active = [];\n this._activeCount = 0;\n toClose.forEach(({ el, onClose }) => {\n el.remove();\n onClose?.();\n });\n }\n\n protected override _onRemoved(): void {\n this.dismissAll();\n }\n\n notify(message: Content, options: NotifyOptions = {}): void {\n if (options.maxStack) this.setMaxStack(options.maxStack);\n this.enqueue({\n message,\n type: options.type,\n position: options.position,\n duration: options.duration,\n actionText: options.actionText,\n onAction: options.onAction,\n onClose: options.onClose,\n });\n }\n\n protected _showItem(item: SnackbarItem): void {\n const type = item.type ?? 'info';\n const position =\n (item.position && PASSIVE_OVERLAY_POSITIONS.includes(item.position) ? item.position : undefined) ??\n this._cssPosition('--a11y-snackbar-position', PASSIVE_OVERLAY_POSITIONS) ??\n 'bottom';\n const duration = item.duration ?? (item.actionText ? 10_000 : 3000);\n const container = this._container(position);\n\n const el = doc.createElement('div');\n el.className = `a11y-snackbar a11y-snackbar--${type}`;\n el.setAttribute('role', type === 'error' ? 'alert' : 'status');\n el.setAttribute('aria-live', type === 'error' ? 'assertive' : 'polite');\n el.setAttribute('aria-atomic', 'true');\n el.append(h('span', { class: 'a11y-snackbar__message' }, item.message));\n if (item.actionText) el.append(h('button', { type: 'button', class: 'a11y-snackbar__action' }, item.actionText));\n el.append(h('button', { type: 'button', class: 'a11y-snackbar__close', 'aria-label': this.dismissLabel }, '\\u00d7'));\n\n container.appendChild(el);\n\n const entry: ActiveToast = { el, onClose: item.onClose, cancelAutoDismiss: () => {} };\n this._active.push(entry);\n\n /** Takes the toast off screen and counts it out; false if it was already gone (e.g. `dismissAll()` ran). */\n const remove = (): boolean => {\n if (!this._active.includes(entry)) return false;\n entry.cancelAutoDismiss();\n el.remove();\n this._active = this._active.filter((a) => a !== entry);\n // Counted out before the callbacks run: a `dismissAll()` from there resets the count itself.\n this._onItemDismissed();\n return true;\n };\n const dismiss = (): void => {\n if (remove()) item.onClose?.();\n };\n\n entry.cancelAutoDismiss = this._autoDismiss(el, duration, dismiss);\n\n el.querySelector<HTMLButtonElement>('.a11y-snackbar__action')?.addEventListener('click', () => {\n if (!remove()) return;\n item.onAction?.();\n item.onClose?.();\n });\n el.querySelector<HTMLButtonElement>('.a11y-snackbar__close')?.addEventListener('click', dismiss);\n }\n}\n","import { defineElement } from '../../core/define-element.js';\nimport type { Content } from '../../core/dom.js';\nimport { SnackbarElement, type NotifyOptions } from './snackbar.element.js';\nimport { doc } from '../../core/safe-dom.js';\n\ndefineElement('a11y-snackbar', SnackbarElement);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'a11y-snackbar': SnackbarElement;\n }\n}\n\nexport { SnackbarElement, type NotifyOptions };\n\nlet cachedRegion: SnackbarElement | null = null;\n\nfunction getRegion(): SnackbarElement {\n const existing = doc.querySelector<SnackbarElement>('a11y-snackbar');\n if (existing) return existing;\n if (!cachedRegion || !cachedRegion.isConnected) {\n cachedRegion = doc.createElement('a11y-snackbar') as SnackbarElement;\n doc.body.appendChild(cachedRegion);\n }\n return cachedRegion;\n}\n\n/**\n * Convenience: finds (or creates) an `<a11y-snackbar>` region and shows a\n * toast in it. Skip this entirely and call `.notify()` on your own\n * `<a11y-snackbar>` element directly if you want explicit control over\n * where it lives in the DOM.\n */\nexport function notify(message: Content, options: NotifyOptions = {}): void {\n getRegion().notify(message, options);\n}\n\nexport * from '../core/zero-build-exports.js';\n"],"mappings":";;;;;;;;;;;;;;AAyDO,IAAM,kBAAN,cAA8B,0BAAwC;AAAA;AAAA,EAEnE,cAAc,oBAAI,IAAyC;AAAA,EAC3D,UAAyB,CAAC;AAAA,EAElC,WAAoB,qBAA+B;AACjD,WAAO,CAAC,GAAG,MAAM,oBAAoB,eAAe;AAAA,EACtD;AAAA;AAAA,EAGA,IAAI,eAAuB;AACzB,WAAO,KAAK,WAAW,iBAAiB,UAAU,SAAS,CAAC;AAAA,EAC9D;AAAA,EAES,yBAAyB,MAAc,UAAyB,UAA+B;AACtG,UAAM,yBAAyB,MAAM,UAAU,QAAQ;AACvD,QAAI,SAAS,mBAAmB,aAAa,SAAU,MAAK,uBAAuB;AAAA,EACrF;AAAA,EAEmB,kBAAwB;AACzC,SAAK,uBAAuB;AAAA,EAC9B;AAAA,EAEQ,yBAA+B;AACrC,eAAW,OAAO,KAAK,iBAAiB,uBAAuB,EAAG,KAAI,aAAa,cAAc,KAAK,YAAY;AAAA,EACpH;AAAA,EAES,oBAA0B;AACjC,UAAM,kBAAkB;AACxB,SAAK,UAAU,IAAI,sBAAsB;AACzC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEQ,WAAW,UAA+C;AAChE,QAAI,YAAY,KAAK,YAAY,IAAI,QAAQ;AAC7C,QAAI,CAAC,WAAW;AACd,kBAAY,IAAI,cAAc,KAAK;AAEnC,gBAAU,YAAY,8BAA8B,aAAa,SAAS,aAAa,WAAW,0BAA0B,QAAQ,KAAK,EAAE;AAC3I,gBAAU,QAAQ,WAAW;AAC7B,WAAK,YAAY,IAAI,UAAU,SAAS;AACxC,WAAK,OAAO,SAAS;AAAA,IACvB;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,a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";
3
+ } from "./chunk-YYYJ6D77.js";
4
4
  import {
5
5
  h
6
6
  } from "./chunk-KVUJT6BC.js";
@@ -11,6 +11,7 @@ import {
11
11
  } from "./chunk-ED3UMYMY.js";
12
12
 
13
13
  // src/overlays/notification-banner/notification-banner.element.ts
14
+ var POSITIONS = ["top", "bottom"];
14
15
  var NotificationBannerElement = class extends A11yPassiveOverlayElement {
15
16
  _topContainer;
16
17
  _bottomContainer;
@@ -70,7 +71,8 @@ var NotificationBannerElement = class extends A11yPassiveOverlayElement {
70
71
  }
71
72
  _showItem(item) {
72
73
  const type = item.type ?? "info";
73
- const position = item.position ?? "top";
74
+ const option = item.position;
75
+ const position = (option && POSITIONS.includes(option) ? option : void 0) ?? this._cssPosition("--a11y-notification-banner-position", POSITIONS) ?? "top";
74
76
  const container = position === "top" ? this._topContainer : this._bottomContainer;
75
77
  const el = doc.createElement("div");
76
78
  el.className = `a11y-notification-banner a11y-notification-banner--${type}`;
@@ -126,4 +128,4 @@ export {
126
128
  NotificationBannerElement,
127
129
  showNotificationBanner
128
130
  };
129
- //# sourceMappingURL=chunk-PO7RAUEO.js.map
131
+ //# sourceMappingURL=chunk-HJUKOWFZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/overlays/notification-banner/notification-banner.element.ts","../../src/overlays/notification-banner/define.ts"],"sourcesContent":["import { A11yPassiveOverlayElement, type PassiveOverlayItem } from '../core/a11y-passive-overlay-element.js';\nimport { getString } from '../../core/strings.js';\nimport { h, type Content } from '../../core/dom.js';\nimport { doc } from '../../core/safe-dom.js';\n\nexport type NotificationBannerType = 'info' | 'success' | 'error' | 'warning';\n\nexport type NotificationBannerPosition = 'top' | 'bottom';\n\nconst POSITIONS: readonly NotificationBannerPosition[] = ['top', 'bottom'];\n\nexport interface NotificationBannerOptions {\n type?: NotificationBannerType;\n /** Defaults to `--a11y-notification-banner-position` from CSS, else `top`. */\n position?: NotificationBannerPosition;\n actionText?: string;\n onAction?: () => void;\n onClose?: () => void;\n /** Sets the concurrency limit for this and all future items — sticky on the shared region, same as the `max-stack` attribute. */\n maxStack?: number;\n}\n\ninterface NotificationBannerItem extends PassiveOverlayItem {\n type?: NotificationBannerType;\n onClose?: () => void;\n}\n\n/**\n * A persistent banner region (unlike `<a11y-snackbar>`, items never\n * auto-dismiss — they stay until the user dismisses them or `dismissAll()`\n * is called). Place one `<a11y-notification-banner>` in your page, then\n * call `.show(message, options)` on it — or use the `showNotificationBanner()`\n * convenience export, which finds-or-creates one automatically.\n *\n * `dismissAll()` is the framework-agnostic replacement for the old\n * `Lifecycle.onViewUnmount` auto-wiring (which assumed a specific SPA-router\n * service) — if you want banners cleared on navigation, call it yourself\n * from your own router's navigation hook. Unlike `<a11y-snackbar>` (whose\n * toasts finish their own timers regardless of navigation while the region\n * stays in the page), this asymmetry is intentional, not an oversight — a\n * banner is scoped to the page that raised it, a toast isn't.\n *\n * Each item's close button is named by `dismiss-label=\"…\"`, else\n * `setStrings({ dismiss })`.\n *\n * Each banner shows at its `position` option, else at the position set in\n * CSS with `--a11y-notification-banner-position` (`top` or `bottom`; read\n * when the banner is shown), else at the top.\n */\nexport class NotificationBannerElement extends A11yPassiveOverlayElement<NotificationBannerItem> {\n private _topContainer!: HTMLElement;\n private _bottomContainer!: HTMLElement;\n private _active: Array<{ el: HTMLElement; onClose?: () => void }> = [];\n\n static override get observedAttributes(): string[] {\n return [...super.observedAttributes, 'dismiss-label'];\n }\n\n /** The accessible name of each item's close button. */\n get dismissLabel(): string {\n return this.stringAttr('dismiss-label', getString('dismiss'));\n }\n\n override attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void {\n super.attributeChangedCallback(name, oldValue, newValue);\n if (name === 'dismiss-label' && oldValue !== newValue) this._relabelDismissButtons();\n }\n\n protected override onStringsChange(): void {\n this._relabelDismissButtons();\n }\n\n private _relabelDismissButtons(): void {\n for (const { el } of this._active) {\n el.querySelector('.a11y-notification-banner__close')?.setAttribute('aria-label', this.dismissLabel);\n }\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.classList.add('a11y-notification-banner-region');\n if (!this._topContainer) {\n this._topContainer = doc.createElement('div');\n this._topContainer.className = 'a11y-notification-banner-region__top';\n this._bottomContainer = doc.createElement('div');\n this._bottomContainer.className = 'a11y-notification-banner-region__bottom';\n this.append(this._topContainer, this._bottomContainer);\n }\n this._drainQueue();\n }\n\n show(message: Content, options: NotificationBannerOptions = {}): void {\n if (options.maxStack) this.setMaxStack(options.maxStack);\n this.enqueue({\n message,\n type: options.type,\n position: options.position,\n actionText: options.actionText,\n onAction: options.onAction,\n onClose: options.onClose,\n });\n }\n\n /** Force-dismisses every showing/queued item. Queued items never shown are dropped silently (no onClose); active ones get their onClose called. */\n dismissAll(): void {\n this._queue = [];\n const toClose = this._active;\n this._active = [];\n this._activeCount = 0;\n toClose.forEach(({ el, onClose }) => {\n el.remove();\n onClose?.();\n });\n }\n\n protected _showItem(item: NotificationBannerItem): void {\n const type = item.type ?? 'info';\n const option = item.position as NotificationBannerPosition | undefined;\n const position =\n (option && POSITIONS.includes(option) ? option : undefined) ??\n this._cssPosition('--a11y-notification-banner-position', POSITIONS) ??\n 'top';\n const container = position === 'top' ? this._topContainer : this._bottomContainer;\n\n const el = doc.createElement('div');\n el.className = `a11y-notification-banner a11y-notification-banner--${type}`;\n el.setAttribute('role', type === 'error' ? 'alert' : 'status');\n el.setAttribute('aria-live', type === 'error' ? 'assertive' : 'polite');\n el.append(\n h('span', { class: 'a11y-notification-banner__message' }, item.message),\n h(\n 'span',\n { class: 'a11y-notification-banner__actions' },\n item.actionText ? h('button', { type: 'button', class: 'a11y-notification-banner__action' }, item.actionText) : null,\n h('button', { type: 'button', class: 'a11y-notification-banner__close', 'aria-label': this.dismissLabel }, '\\u00d7'),\n ),\n );\n\n container.appendChild(el);\n\n const entry = { el, onClose: item.onClose };\n this._active.push(entry);\n\n const dismiss = (): void => {\n // Already gone: e.g. `onAction` called `dismissAll()`, which closed it and reset the count.\n if (!this._active.includes(entry)) return;\n el.remove();\n this._active = this._active.filter((a) => a !== entry);\n // Count it out before `onClose` runs: a `dismissAll()` from there resets the count itself.\n this._onItemDismissed();\n item.onClose?.();\n };\n\n if (item.actionText && item.onAction) {\n const actionBtn = el.querySelector<HTMLButtonElement>('.a11y-notification-banner__action');\n actionBtn?.addEventListener('click', () => {\n item.onAction?.();\n dismiss();\n });\n }\n\n el.querySelector<HTMLButtonElement>('.a11y-notification-banner__close')?.addEventListener('click', dismiss);\n }\n}\n","import { defineElement } from '../../core/define-element.js';\nimport type { Content } from '../../core/dom.js';\nimport { NotificationBannerElement, type NotificationBannerOptions } from './notification-banner.element.js';\nimport { doc } from '../../core/safe-dom.js';\n\ndefineElement('a11y-notification-banner', NotificationBannerElement);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'a11y-notification-banner': NotificationBannerElement;\n }\n}\n\nexport { NotificationBannerElement, type NotificationBannerOptions };\n\nlet cachedRegion: NotificationBannerElement | null = null;\n\nfunction getRegion(): NotificationBannerElement {\n const existing = doc.querySelector<NotificationBannerElement>('a11y-notification-banner');\n if (existing) return existing;\n if (!cachedRegion || !cachedRegion.isConnected) {\n cachedRegion = doc.createElement('a11y-notification-banner') as NotificationBannerElement;\n doc.body.appendChild(cachedRegion);\n }\n return cachedRegion;\n}\n\n/**\n * Convenience: finds (or creates) an `<a11y-notification-banner>` region and\n * shows a banner in it. Skip this entirely and call `.show()` on your own\n * `<a11y-notification-banner>` element directly if you want explicit control\n * over where it lives in the DOM.\n */\nexport function showNotificationBanner(message: Content, options: NotificationBannerOptions = {}): void {\n getRegion().show(message, options);\n}\n\nexport * from '../core/zero-build-exports.js';\n"],"mappings":";;;;;;;;;;;;;AASA,IAAM,YAAmD,CAAC,OAAO,QAAQ;AAwClE,IAAM,4BAAN,cAAwC,0BAAkD;AAAA,EACvF;AAAA,EACA;AAAA,EACA,UAA4D,CAAC;AAAA,EAErE,WAAoB,qBAA+B;AACjD,WAAO,CAAC,GAAG,MAAM,oBAAoB,eA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MACV,CAAC;AAAA,IACH;AAEA,OAAG,cAAiC,kCAAkC,GAAG,iBAAiB,SAAS,OAAO;AAAA,EAC5G;AACF;;;AC9JA,cAAc,4BAA4B,yBAAyB;AAUnE,IAAI,eAAiD;AAErD,SAAS,YAAuC;AAC9C,QAAM,WAAW,IAAI,cAAyC,0BAA0B;AACxF,MAAI,SAAU,QAAO;AACrB,MAAI,CAAC,gBAAgB,CAAC,aAAa,aAAa;AAC9C,mBAAe,IAAI,cAAc,0BAA0B;AAC3D,QAAI,KAAK,YAAY,YAAY;AAAA,EACnC;AACA,SAAO;AACT;AAQO,SAAS,uBAAuB,SAAkB,UAAqC,CAAC,GAAS;AACtG,YAAU,EAAE,KAAK,SAAS,OAAO;AACnC;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  A11yAnchoredOverlayElement
3
- } from "./chunk-UKFZ7AT5.js";
3
+ } from "./chunk-F4KVDZS3.js";
4
4
  import {
5
5
  focusFromKeyboard,
6
6
  focusReturnTarget,
@@ -150,4 +150,4 @@ var A11yMenuOverlayElement = class extends A11yAnchoredOverlayElement {
150
150
  export {
151
151
  A11yMenuOverlayElement
152
152
  };
153
- //# sourceMappingURL=chunk-J5T2K5NR.js.map
153
+ //# sourceMappingURL=chunk-RGO5EYGG.js.map