@zazz-ui/core 0.4.1 → 0.5.0
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/AUTHORING.md +158 -0
- package/CHANGELOG.md +331 -0
- package/README.md +55 -23
- package/dist/scroll-state-C8mA5gq6.js +1 -0
- package/dist/sri.json +124 -72
- package/dist/zazz.css +1 -1
- package/dist/zazz.js +1 -1
- package/editor/zazz.css-data.json +116794 -0
- package/editor/zazz.html-data.json +1683 -0
- package/editor/zazz.language-data.json +5001 -0
- package/editor/zazz.lint-data.json +152 -0
- package/package.json +12 -5
- package/src/base/_breakpoints.css +12 -0
- package/src/base/_layers.css +8 -9
- package/src/base/_properties-2xl.css +171 -0
- package/src/base/_properties-active.css +107 -0
- package/src/base/_properties-checked.css +107 -0
- package/src/base/_properties-current.css +107 -0
- package/src/base/_properties-disabled.css +107 -0
- package/src/base/_properties-focus-visible.css +107 -0
- package/src/base/_properties-focus-within.css +107 -0
- package/src/base/_properties-hover.css +107 -0
- package/src/base/_properties-lg.css +171 -0
- package/src/base/_properties-md.css +171 -0
- package/src/base/_properties-open.css +107 -0
- package/src/base/_properties-sm.css +171 -0
- package/src/base/_properties-starting.css +55 -0
- package/src/base/_properties-stuck.css +55 -0
- package/src/base/_properties-xl.css +171 -0
- package/src/base/_properties.css +555 -0
- package/src/base/_reset.css +67 -75
- package/src/base/_switches.css +145 -0
- package/src/base/_typography.css +437 -370
- package/src/base/_utilities-box.css +142 -0
- package/src/base/_utilities-color.css +290 -0
- package/src/base/_utilities-effects.css +235 -0
- package/src/base/_utilities-flow.css +312 -0
- package/src/base/_utilities-grid.css +143 -0
- package/src/base/_utilities-margin.css +376 -0
- package/src/base/_utilities-pseudo.css +426 -0
- package/src/base/_utilities-sizing.css +259 -0
- package/src/base/_utilities-spacing.css +190 -0
- package/src/base/_utilities-tier-2xl.css +93 -0
- package/src/base/_utilities-tier-active.css +61 -0
- package/src/base/_utilities-tier-checked.css +61 -0
- package/src/base/_utilities-tier-current.css +61 -0
- package/src/base/_utilities-tier-disabled.css +61 -0
- package/src/base/_utilities-tier-focus-visible.css +61 -0
- package/src/base/_utilities-tier-focus-within.css +61 -0
- package/src/base/_utilities-tier-hover.css +63 -0
- package/src/base/_utilities-tier-lg.css +93 -0
- package/src/base/_utilities-tier-md.css +93 -0
- package/src/base/_utilities-tier-open.css +61 -0
- package/src/base/_utilities-tier-sm.css +93 -0
- package/src/base/_utilities-tier-starting.css +35 -0
- package/src/base/_utilities-tier-stuck.css +114 -0
- package/src/base/_utilities-tier-xl.css +93 -0
- package/src/base/_utilities-typography.css +141 -0
- package/src/base/_variables.css +323 -372
- package/src/base/_view-transitions.css +10 -12
- package/src/base/command-score.d.ts.map +1 -1
- package/src/base/command-score.js +1 -2
- package/src/base/command-score.ts +1 -2
- package/src/base/dialog-lifecycle.js +1 -1
- package/src/base/dialog-lifecycle.ts +1 -1
- package/src/base/embla.d.ts +6 -7
- package/src/base/embla.d.ts.map +1 -1
- package/src/base/embla.js +89 -55
- package/src/base/embla.ts +89 -55
- package/src/base/hotkeys.d.ts +0 -5
- package/src/base/hotkeys.d.ts.map +1 -1
- package/src/base/hotkeys.ts +0 -5
- package/src/base/navigation.d.ts +12 -1
- package/src/base/navigation.d.ts.map +1 -1
- package/src/base/navigation.js +229 -86
- package/src/base/navigation.ts +224 -92
- package/src/base/reveal.js +14 -14
- package/src/base/reveal.ts +14 -14
- package/src/base/scroll-state.d.ts +21 -0
- package/src/base/scroll-state.d.ts.map +1 -0
- package/src/base/scroll-state.js +177 -0
- package/src/base/scroll-state.ts +188 -0
- package/src/base/signals.d.ts +1 -2
- package/src/base/signals.d.ts.map +1 -1
- package/src/base/signals.js +4 -6
- package/src/base/signals.ts +4 -6
- package/src/base/style-format.d.ts +33 -0
- package/src/base/style-format.d.ts.map +1 -0
- package/src/base/style-format.js +160 -0
- package/src/base/style-format.ts +180 -0
- package/src/base/typeahead.d.ts +19 -4
- package/src/base/typeahead.d.ts.map +1 -1
- package/src/base/typeahead.js +68 -21
- package/src/base/typeahead.ts +73 -23
- package/src/base/utilities.d.ts +188 -0
- package/src/base/utilities.d.ts.map +1 -0
- package/src/base/utilities.js +750 -0
- package/src/base/utilities.ts +865 -0
- package/src/base/utils.d.ts +3 -7
- package/src/base/utils.d.ts.map +1 -1
- package/src/base/utils.js +4 -8
- package/src/base/utils.ts +4 -8
- package/src/base/zazz-element.d.ts +14 -8
- package/src/base/zazz-element.d.ts.map +1 -1
- package/src/base/zazz-element.js +14 -8
- package/src/base/zazz-element.ts +15 -8
- package/src/globals.d.ts +1 -1
- package/src/head.d.ts +50 -4
- package/src/head.d.ts.map +1 -1
- package/src/head.js +119 -38
- package/src/head.ts +172 -41
- package/src/index.css +57 -14
- package/src/index.js +5 -0
- package/src/index.ts +6 -0
- package/src/manifest.d.ts +36 -5
- package/src/manifest.d.ts.map +1 -1
- package/src/manifest.js +150 -6
- package/src/manifest.ts +167 -9
- package/src/primitives/accordion/accordion.css +18 -17
- package/src/primitives/accordion/accordion.html +42 -9
- package/src/primitives/alert-dialog/alert-dialog.css +13 -13
- package/src/primitives/alert-dialog/alert-dialog.html +26 -12
- package/src/primitives/autocomplete/autocomplete-groups.html +64 -33
- package/src/primitives/autocomplete/autocomplete.css +43 -39
- package/src/primitives/autocomplete/autocomplete.d.ts +6 -5
- package/src/primitives/autocomplete/autocomplete.d.ts.map +1 -1
- package/src/primitives/autocomplete/autocomplete.html +38 -26
- package/src/primitives/autocomplete/autocomplete.js +6 -5
- package/src/primitives/autocomplete/autocomplete.ts +6 -5
- package/src/primitives/avatar/avatar.html +110 -15
- package/src/primitives/badge/badge-icon.html +22 -8
- package/src/primitives/badge/badge.css +401 -128
- package/src/primitives/badge/badge.html +12 -6
- package/src/primitives/breadcrumbs/breadcrumbs.html +25 -5
- package/src/primitives/button/button-icon-only.html +17 -11
- package/src/primitives/button/button-icon.html +9 -3
- package/src/primitives/button/button.css +408 -164
- package/src/primitives/button/button.html +14 -7
- package/src/primitives/button-group/button-group-vertical.html +5 -5
- package/src/primitives/button-group/button-group.css +53 -25
- package/src/primitives/button-group/button-group.html +18 -12
- package/src/primitives/callout/callout.css +114 -0
- package/src/primitives/callout/callout.html +188 -0
- package/src/primitives/card/card-subgrid.html +249 -34
- package/src/primitives/card/card.css +125 -0
- package/src/primitives/card/card.html +141 -20
- package/src/primitives/carousel/carousel.css +30 -20
- package/src/primitives/carousel/carousel.d.ts +7 -10
- package/src/primitives/carousel/carousel.d.ts.map +1 -1
- package/src/primitives/carousel/carousel.html +420 -84
- package/src/primitives/carousel/carousel.js +1 -1
- package/src/primitives/carousel/carousel.ts +8 -11
- package/src/primitives/checkbox/checkbox-tasklist.html +6 -6
- package/src/primitives/checkbox/checkbox.css +98 -40
- package/src/primitives/checkbox/checkbox.d.ts.map +1 -1
- package/src/primitives/checkbox/checkbox.html +13 -8
- package/src/primitives/checkbox/checkbox.js +7 -9
- package/src/primitives/checkbox/checkbox.ts +7 -15
- package/src/primitives/combobox/combobox-multiselect.html +53 -33
- package/src/primitives/combobox/combobox.css +145 -122
- package/src/primitives/combobox/combobox.d.ts +12 -11
- package/src/primitives/combobox/combobox.d.ts.map +1 -1
- package/src/primitives/combobox/combobox.html +48 -28
- package/src/primitives/combobox/combobox.js +46 -51
- package/src/primitives/combobox/combobox.ts +48 -55
- package/src/primitives/command/command-actions.d.ts +2 -3
- package/src/primitives/command/command-actions.d.ts.map +1 -1
- package/src/primitives/command/command-actions.html +48 -33
- package/src/primitives/command/command-actions.js +12 -10
- package/src/primitives/command/command-actions.ts +12 -13
- package/src/primitives/command/command-dialog.html +49 -25
- package/src/primitives/command/command.css +52 -42
- package/src/primitives/command/command.d.ts +10 -7
- package/src/primitives/command/command.d.ts.map +1 -1
- package/src/primitives/command/command.html +95 -46
- package/src/primitives/command/command.js +30 -13
- package/src/primitives/command/command.ts +30 -12
- package/src/primitives/debug/audit-core.d.ts +64 -0
- package/src/primitives/debug/audit-core.d.ts.map +1 -0
- package/src/primitives/debug/audit-core.js +356 -0
- package/src/primitives/debug/audit-core.ts +535 -0
- package/src/primitives/debug/debug.d.ts +50 -0
- package/src/primitives/debug/debug.d.ts.map +1 -0
- package/src/primitives/debug/debug.js +168 -0
- package/src/primitives/debug/debug.ts +211 -0
- package/src/primitives/dialog/dialog-with-form.html +67 -45
- package/src/primitives/dialog/dialog.css +87 -61
- package/src/primitives/dialog/dialog.html +25 -17
- package/src/primitives/fields/fields.css +108 -134
- package/src/primitives/fields/fields.html +39 -0
- package/src/primitives/input/input-icon-leading.html +3 -3
- package/src/primitives/input/input-icon-trailing.html +3 -3
- package/src/primitives/input/input.css +87 -49
- package/src/primitives/input/input.html +15 -15
- package/src/primitives/input-group/input-group-password-group.html +15 -15
- package/src/primitives/input-group/input-group.css +118 -75
- package/src/primitives/input-group/input-group.html +42 -30
- package/src/primitives/kbd/kbd-group.html +15 -2
- package/src/primitives/kbd/kbd.css +44 -31
- package/src/primitives/kbd/kbd.html +7 -1
- package/src/primitives/layout/layout.css +159 -0
- package/src/primitives/layout/layout.html +35 -0
- package/src/primitives/lightbox/lightbox.css +178 -105
- package/src/primitives/lightbox/lightbox.d.ts.map +1 -1
- package/src/primitives/lightbox/lightbox.html +138 -166
- package/src/primitives/lightbox/lightbox.js +10 -13
- package/src/primitives/lightbox/lightbox.ts +12 -13
- package/src/primitives/menu/menu-interest.html +60 -18
- package/src/primitives/menu/menu.css +22 -17
- package/src/primitives/menu/menu.d.ts +5 -5
- package/src/primitives/menu/menu.html +195 -40
- package/src/primitives/menu/menu.js +8 -8
- package/src/primitives/menu/menu.ts +8 -8
- package/src/primitives/menubar/menubar-help-search.html +78 -32
- package/src/primitives/menubar/menubar.html +166 -38
- package/src/primitives/meter/meter.css +41 -38
- package/src/primitives/meter/meter.html +44 -9
- package/src/primitives/mobile-menu/mobile-menu.css +47 -40
- package/src/primitives/mobile-menu/mobile-menu.html +1460 -179
- package/src/primitives/navigation-menu/navigation-menu-featured.html +155 -33
- package/src/primitives/navigation-menu/navigation-menu-icon-grid.html +222 -47
- package/src/primitives/navigation-menu/navigation-menu-interest.html +130 -38
- package/src/primitives/navigation-menu/navigation-menu-megamenu.html +402 -72
- package/src/primitives/navigation-menu/navigation-menu-simple.html +90 -40
- package/src/primitives/navigation-menu/navigation-menu.css +104 -106
- package/src/primitives/navigation-menu/navigation-menu.html +554 -158
- package/src/primitives/otp/otp.css +43 -44
- package/src/primitives/otp/otp.d.ts +4 -5
- package/src/primitives/otp/otp.d.ts.map +1 -1
- package/src/primitives/otp/otp.html +7 -6
- package/src/primitives/otp/otp.js +13 -18
- package/src/primitives/otp/otp.ts +12 -19
- package/src/primitives/password-group/password-group.css +132 -107
- package/src/primitives/password-group/password-group.d.ts.map +1 -1
- package/src/primitives/password-group/password-group.html +23 -16
- package/src/primitives/password-group/password-group.js +11 -12
- package/src/primitives/password-group/password-group.ts +11 -12
- package/src/primitives/popover/popover.css +88 -95
- package/src/primitives/popover/popover.html +18 -0
- package/src/primitives/progress/progress-indeterminate.html +1 -1
- package/src/primitives/progress/progress.css +34 -35
- package/src/primitives/progress/progress.html +18 -4
- package/src/primitives/prose/prose.html +19 -12
- package/src/primitives/radio/radio.css +83 -46
- package/src/primitives/radio/radio.html +16 -11
- package/src/primitives/reveal/reveal.css +37 -46
- package/src/primitives/reveal/reveal.html +15 -0
- package/src/primitives/scroll-fade/scroll-fade.css +115 -0
- package/src/primitives/scroll-fade/scroll-fade.html +69 -0
- package/src/primitives/select/multiselect.d.ts +8 -10
- package/src/primitives/select/multiselect.d.ts.map +1 -1
- package/src/primitives/select/multiselect.js +23 -27
- package/src/primitives/select/multiselect.ts +23 -29
- package/src/primitives/select/select-align.html +79 -16
- package/src/primitives/select/select-multiple.html +8 -4
- package/src/primitives/select/select-sides.html +104 -21
- package/src/primitives/select/select.css +297 -186
- package/src/primitives/select/select.html +24 -5
- package/src/primitives/separator/separator.css +15 -18
- package/src/primitives/separator/separator.html +37 -10
- package/src/primitives/slider/slider.css +48 -38
- package/src/primitives/slider/slider.html +9 -1
- package/src/primitives/style-guard/style-guard.d.ts +19 -0
- package/src/primitives/style-guard/style-guard.d.ts.map +1 -0
- package/src/primitives/style-guard/style-guard.js +125 -0
- package/src/primitives/style-guard/style-guard.ts +153 -0
- package/src/primitives/switch/switch.css +42 -33
- package/src/primitives/switch/switch.html +11 -6
- package/src/primitives/table/table-alternating.html +1 -1
- package/src/primitives/table/table-grid.html +5 -5
- package/src/primitives/table/table-size-sm.html +1 -1
- package/src/primitives/table/table.css +64 -61
- package/src/primitives/table/table.html +7 -7
- package/src/primitives/tabs/tabs.css +167 -166
- package/src/primitives/tabs/tabs.d.ts +10 -11
- package/src/primitives/tabs/tabs.d.ts.map +1 -1
- package/src/primitives/tabs/tabs.html +192 -36
- package/src/primitives/tabs/tabs.js +14 -15
- package/src/primitives/tabs/tabs.ts +14 -15
- package/src/primitives/textarea/textarea.css +69 -44
- package/src/primitives/textarea/textarea.html +3 -3
- package/src/primitives/toaster/toaster.css +90 -92
- package/src/primitives/toaster/toaster.d.ts +0 -6
- package/src/primitives/toaster/toaster.d.ts.map +1 -1
- package/src/primitives/toaster/toaster.html +22 -18
- package/src/primitives/toaster/toaster.js +64 -72
- package/src/primitives/toaster/toaster.ts +71 -87
- package/src/primitives/toggle/toggle.css +368 -153
- package/src/primitives/toggle/toggle.html +27 -9
- package/src/primitives/toggle-group/toggle-group-multiple.html +3 -3
- package/src/primitives/toggle-group/toggle-group-vertical.html +4 -4
- package/src/primitives/toggle-group/toggle-group.css +71 -23
- package/src/primitives/toggle-group/toggle-group.html +3 -3
- package/src/primitives/toolbar/toolbar.html +35 -13
- package/src/primitives/tooltip/tooltip-disabled.html +3 -3
- package/src/primitives/tooltip/tooltip-sides.html +36 -14
- package/src/primitives/tooltip/tooltip-with-kbd.html +5 -5
- package/src/primitives/tooltip/tooltip.css +111 -80
- package/src/primitives/tooltip/tooltip.html +3 -3
- package/src/primitives/utilities/aspect-ratio.html +51 -7
- package/src/primitives/utilities/basis.html +64 -11
- package/src/primitives/utilities/col-span.html +65 -9
- package/src/primitives/utilities/compose.html +48 -10
- package/src/primitives/utilities/flex-align.html +89 -19
- package/src/primitives/utilities/flex-direction.html +111 -13
- package/src/primitives/utilities/flex-grow.html +41 -7
- package/src/primitives/utilities/gap.html +158 -19
- package/src/primitives/utilities/grid-cols.html +75 -7
- package/src/primitives/utilities/grid-responsive.html +111 -12
- package/src/primitives/utilities/margin-auto.html +38 -7
- package/src/primitives/utilities/object-fit.html +75 -13
- package/src/primitives/utilities/order.html +40 -4
- package/src/primitives/utilities/overflow.html +74 -20
- package/src/primitives/utilities/padding-compose.html +67 -10
- package/src/primitives/utilities/padding.html +84 -13
- package/src/primitives/utilities/pile.html +29 -0
- package/src/primitives/utilities/position.html +65 -8
- package/src/primitives/utilities/responsive-flex.html +54 -7
- package/src/primitives/utilities/responsive-grid.html +115 -12
- package/src/primitives/utilities/size.html +120 -16
- package/src/primitives/utilities/width.html +123 -16
- package/examples/about.html +0 -583
- package/examples/components.html +0 -1028
- package/examples/forms.html +0 -504
- package/examples/index.html +0 -261
- package/examples/layout.html +0 -313
- package/examples/products.html +0 -839
- package/examples/responsive.html +0 -332
- package/src/base/_layout.css +0 -571
- package/src/base/_utilities.css +0 -6758
- package/src/primitives/utilities/grid-pile.html +0 -5
|
@@ -3,46 +3,38 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @fileoverview `<ui-toaster>`: HTML web component for stacked toast notifications.
|
|
5
5
|
* @description Light-DOM custom element that hosts a top-layer toast stack, plus
|
|
6
|
-
* the `window.Toaster` imperative API.
|
|
7
|
-
* older toasts peeking behind, expand on hover, timer pause on hover/hidden tab)
|
|
8
|
-
* is adapted from Sonner by Emil Kowalski (https://sonner.emilkowal.ski, MIT).
|
|
6
|
+
* the `window.Toaster` imperative API. Timers pause on hover and in hidden tabs.
|
|
9
7
|
*
|
|
10
8
|
* The region is a `popover="manual"` element: it enters the top layer via
|
|
11
9
|
* `showPopover()` when the first toast arrives and leaves it after the last
|
|
12
10
|
* toast's exit transition. Toasts are plain `<li>` children, so the collapsed
|
|
13
|
-
* stack offsets in `
|
|
11
|
+
* stack offsets in `toaster.css` work with normal CSS transforms.
|
|
14
12
|
*
|
|
15
13
|
* Fire toasts two ways:
|
|
16
14
|
* - Declaratively, from any button, via a custom Invoker Command:
|
|
17
15
|
* `command="--toast"` (or `--toast-success|info|warning|destructive`) with
|
|
18
16
|
* `commandfor="<region id>"`. Toast content comes from the button's
|
|
19
|
-
* `data-title`, `data-description`, `data-variant`,
|
|
20
|
-
* `data-close-button` attributes.
|
|
17
|
+
* `data-toaster-title`, `data-toaster-description`, `data-toaster-variant`,
|
|
18
|
+
* `data-toaster-duration`, and `data-toaster-close-button` attributes.
|
|
21
19
|
* - Imperatively: `window.Toaster.toast({ title, description, variant, … })`
|
|
22
20
|
* and the `.success()/.info()/.warning()/.error()` shorthands.
|
|
23
21
|
*
|
|
24
22
|
* Region attributes:
|
|
25
|
-
* - `data-position`: `top-start | top-center | top-end | bottom-start |
|
|
23
|
+
* - `data-toaster-position`: `top-start | top-center | top-end | bottom-start |
|
|
26
24
|
* bottom-center | bottom-end` (logical; default `bottom-end`).
|
|
27
25
|
*
|
|
28
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Popover_API
|
|
29
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Invoker_Commands_API
|
|
30
|
-
*
|
|
31
26
|
* @example
|
|
32
|
-
* <ui-toaster
|
|
33
|
-
* <button commandfor="toaster" command="--toast" data-title="Saved">Save</button>
|
|
27
|
+
* <ui-toaster id="toaster" popover="manual"></ui-toaster>
|
|
28
|
+
* <button commandfor="toaster" command="--toast" data-toaster-title="Saved">Save</button>
|
|
34
29
|
*/
|
|
35
30
|
|
|
36
31
|
import { computed, effect, state } from "../../base/signals.ts";
|
|
37
32
|
import { ZazzElement, defineZazzElement } from "../../base/zazz-element.ts";
|
|
38
33
|
|
|
39
|
-
// `using`
|
|
40
|
-
//
|
|
41
|
-
// Management (Safari) don't define it, so give them a local stand-in.
|
|
34
|
+
// compiled `using` reads Symbol.dispose, which engines without native Explicit
|
|
35
|
+
// Resource Management (Safari) lack
|
|
42
36
|
(Symbol as { dispose: symbol }).dispose ??= Symbol("Symbol.dispose");
|
|
43
37
|
|
|
44
|
-
// --- Constants ---
|
|
45
|
-
|
|
46
38
|
/** Default toast lifetime in milliseconds. */
|
|
47
39
|
const TOAST_LIFETIME = 4000;
|
|
48
40
|
|
|
@@ -54,8 +46,6 @@ const EXIT_FALLBACK_MS = 600;
|
|
|
54
46
|
|
|
55
47
|
const VARIANTS: ReadonlyArray<string> = ["success", "info", "warning", "destructive"];
|
|
56
48
|
|
|
57
|
-
// --- Icons (adapted from Sonner's assets.tsx (MIT, Emil Kowalski)) ---
|
|
58
|
-
|
|
59
49
|
const ICONS: Record<string, string> = {
|
|
60
50
|
success:
|
|
61
51
|
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z" clip-rule="evenodd"/></svg>',
|
|
@@ -68,8 +58,6 @@ const ICONS: Record<string, string> = {
|
|
|
68
58
|
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',
|
|
69
59
|
};
|
|
70
60
|
|
|
71
|
-
// --- Typedefs ---
|
|
72
|
-
|
|
73
61
|
interface ToastAction {
|
|
74
62
|
/** Button label. */
|
|
75
63
|
label: string;
|
|
@@ -125,8 +113,6 @@ interface ToastStackLayout {
|
|
|
125
113
|
visible: boolean;
|
|
126
114
|
}
|
|
127
115
|
|
|
128
|
-
// --- Measurement ---
|
|
129
|
-
|
|
130
116
|
/**
|
|
131
117
|
* @description Unclamps every toast's block-size for a batch measurement (the
|
|
132
118
|
* inline style beats the collapsed block-size rule) and returns a disposer
|
|
@@ -146,8 +132,6 @@ function unclampForMeasure(toasts: readonly HTMLElement[]): Disposable {
|
|
|
146
132
|
};
|
|
147
133
|
}
|
|
148
134
|
|
|
149
|
-
// --- Stack math (pure) ---
|
|
150
|
-
|
|
151
135
|
/**
|
|
152
136
|
* @description Computes the collapsed-stack placement for every toast from the
|
|
153
137
|
* measured heights alone (oldest first, matching DOM order). Pure: the
|
|
@@ -180,14 +164,29 @@ function computeStackLayout(heights: number[]): {
|
|
|
180
164
|
return { toasts, frontToastHeightPx: count > 0 ? heights[count - 1] : null };
|
|
181
165
|
}
|
|
182
166
|
|
|
183
|
-
// --- <ui-toaster> element ---
|
|
184
|
-
|
|
185
167
|
/**
|
|
186
168
|
* @class
|
|
187
169
|
* @description Hosts the toast stack: builds toast markup, maintains the
|
|
188
170
|
* collapsed-stack CSS custom properties, runs auto-dismiss timers, and shows or
|
|
189
171
|
* hides the `popover="manual"` region as toasts come and go.
|
|
190
172
|
*/
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @description Adds or removes one token of an element's `data-toaster-state`
|
|
176
|
+
* list: `expanded` on the region; `front`, `visible`, `removed` on a toast.
|
|
177
|
+
*/
|
|
178
|
+
function setToasterState(node: Element, token: string, on: boolean): void {
|
|
179
|
+
const tokens = (node.getAttribute("data-toaster-state") ?? "").split(/\s+/).filter(Boolean);
|
|
180
|
+
const next = on ? [...new Set([...tokens, token])] : tokens.filter((t) => t !== token);
|
|
181
|
+
if (next.length) node.setAttribute("data-toaster-state", next.join(" "));
|
|
182
|
+
else node.removeAttribute("data-toaster-state");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** @description Whether a toast has been dismissed and is animating out. */
|
|
186
|
+
function isRemoved(toast: Element): boolean {
|
|
187
|
+
return toast.matches('[data-toaster-state~="removed"]');
|
|
188
|
+
}
|
|
189
|
+
|
|
191
190
|
class UiToaster extends ZazzElement {
|
|
192
191
|
#timers: Map<string, ToastTimer> = new Map();
|
|
193
192
|
|
|
@@ -224,9 +223,9 @@ class UiToaster extends ZazzElement {
|
|
|
224
223
|
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "-1");
|
|
225
224
|
|
|
226
225
|
// The live region must exist before toasts are inserted so additions announce.
|
|
227
|
-
if (!this.querySelector('[data-slot~="
|
|
226
|
+
if (!this.querySelector('[data-toaster-slot~="list"]')) {
|
|
228
227
|
const list = document.createElement("ol");
|
|
229
|
-
list.setAttribute("data-slot", "
|
|
228
|
+
list.setAttribute("data-toaster-slot", "list");
|
|
230
229
|
list.setAttribute("aria-live", "polite");
|
|
231
230
|
list.setAttribute("aria-relevant", "additions text");
|
|
232
231
|
list.setAttribute("aria-atomic", "false");
|
|
@@ -263,7 +262,7 @@ class UiToaster extends ZazzElement {
|
|
|
263
262
|
// one writes the computed stack placement to the DOM.
|
|
264
263
|
effect(
|
|
265
264
|
() => {
|
|
266
|
-
this
|
|
265
|
+
setToasterState(this, "expanded", this.#expanded.get());
|
|
267
266
|
},
|
|
268
267
|
{ signal },
|
|
269
268
|
);
|
|
@@ -287,8 +286,8 @@ class UiToaster extends ZazzElement {
|
|
|
287
286
|
for (let i = 0; i < entries.length; i++) {
|
|
288
287
|
const { node, height } = entries[i];
|
|
289
288
|
const layout = toasts[i];
|
|
290
|
-
node
|
|
291
|
-
node
|
|
289
|
+
setToasterState(node, "front", layout.front);
|
|
290
|
+
setToasterState(node, "visible", layout.visible);
|
|
292
291
|
node.style.zIndex = String(layout.zIndex);
|
|
293
292
|
node.style.setProperty("--toasts-before", String(layout.stackIndex));
|
|
294
293
|
node.style.setProperty("--initial-height", `${height}px`);
|
|
@@ -313,8 +312,6 @@ class UiToaster extends ZazzElement {
|
|
|
313
312
|
this.#timers.clear();
|
|
314
313
|
}
|
|
315
314
|
|
|
316
|
-
// --- Public API ---
|
|
317
|
-
|
|
318
315
|
/**
|
|
319
316
|
* @description Adds a toast to this region and shows the region if needed.
|
|
320
317
|
*
|
|
@@ -347,14 +344,14 @@ class UiToaster extends ZazzElement {
|
|
|
347
344
|
return;
|
|
348
345
|
}
|
|
349
346
|
|
|
350
|
-
const toast = this.#list().querySelector(`[data-
|
|
351
|
-
if (!(toast instanceof HTMLElement) || toast
|
|
347
|
+
const toast = this.#list().querySelector(`[data-toaster-id="${CSS.escape(id)}"]`);
|
|
348
|
+
if (!(toast instanceof HTMLElement) || isRemoved(toast)) return;
|
|
352
349
|
|
|
353
350
|
const timer = this.#timers.get(id);
|
|
354
351
|
if (timer) clearTimeout(timer.timeoutId);
|
|
355
352
|
this.#timers.delete(id);
|
|
356
353
|
|
|
357
|
-
toast
|
|
354
|
+
setToasterState(toast, "removed", true);
|
|
358
355
|
|
|
359
356
|
// Keyboard users keep their place: hand focus to the next toast before this
|
|
360
357
|
// one goes. A mouse click's incidental focus is left to drop to <body>;
|
|
@@ -367,7 +364,7 @@ class UiToaster extends ZazzElement {
|
|
|
367
364
|
active.matches(":focus-visible")
|
|
368
365
|
) {
|
|
369
366
|
this.#toasts()
|
|
370
|
-
.filter((t) => t
|
|
367
|
+
.filter((t) => !isRemoved(t))
|
|
371
368
|
.at(-1)
|
|
372
369
|
?.focus({ preventScroll: true });
|
|
373
370
|
}
|
|
@@ -381,17 +378,15 @@ class UiToaster extends ZazzElement {
|
|
|
381
378
|
*/
|
|
382
379
|
dismissAll(): void {
|
|
383
380
|
for (const toast of this.#toasts()) {
|
|
384
|
-
const toastId = toast.dataset.
|
|
381
|
+
const toastId = toast.dataset.toasterId;
|
|
385
382
|
if (toastId) this.dismiss(toastId);
|
|
386
383
|
}
|
|
387
384
|
}
|
|
388
385
|
|
|
389
|
-
// --- Invoker Commands ---
|
|
390
|
-
|
|
391
386
|
/**
|
|
392
387
|
* @description Handles the custom `--toast` Invoker Command fired by buttons
|
|
393
388
|
* with `commandfor` pointing at this region. `--toast-success` (etc.) sets the
|
|
394
|
-
* variant; everything else comes from the invoker's `data-*` attributes.
|
|
389
|
+
* variant; everything else comes from the invoker's `data-toaster-*` attributes.
|
|
395
390
|
*
|
|
396
391
|
* @param event - The command event.
|
|
397
392
|
*/
|
|
@@ -418,7 +413,13 @@ class UiToaster extends ZazzElement {
|
|
|
418
413
|
}
|
|
419
414
|
|
|
420
415
|
if (source instanceof HTMLElement) {
|
|
421
|
-
const {
|
|
416
|
+
const {
|
|
417
|
+
toasterTitle: title,
|
|
418
|
+
toasterDescription: description,
|
|
419
|
+
toasterVariant: variant,
|
|
420
|
+
toasterDuration: duration,
|
|
421
|
+
toasterCloseButton: closeButton,
|
|
422
|
+
} = source.dataset;
|
|
422
423
|
if (title) options.title = title;
|
|
423
424
|
if (description) options.description = description;
|
|
424
425
|
if (!options.variant && variant && VARIANTS.includes(variant)) {
|
|
@@ -439,8 +440,6 @@ class UiToaster extends ZazzElement {
|
|
|
439
440
|
this.addToast(options);
|
|
440
441
|
}
|
|
441
442
|
|
|
442
|
-
// --- Toast construction ---
|
|
443
|
-
|
|
444
443
|
/**
|
|
445
444
|
* @description Builds a toast `<li>`: status icon, title/description, and the
|
|
446
445
|
* optional action and close buttons. Text is set via `textContent`.
|
|
@@ -451,30 +450,30 @@ class UiToaster extends ZazzElement {
|
|
|
451
450
|
*/
|
|
452
451
|
#buildToast(options: ToastOptions, id: string): HTMLLIElement {
|
|
453
452
|
const toast = document.createElement("li");
|
|
454
|
-
toast.setAttribute("data-slot", "
|
|
455
|
-
toast.dataset.
|
|
453
|
+
toast.setAttribute("data-toaster-slot", "toast");
|
|
454
|
+
toast.dataset.toasterId = id;
|
|
456
455
|
toast.tabIndex = 0;
|
|
457
|
-
if (options.variant) toast.dataset.
|
|
456
|
+
if (options.variant) toast.dataset.toasterVariant = options.variant;
|
|
458
457
|
|
|
459
458
|
if (options.variant) {
|
|
460
459
|
const icon = document.createElement("span");
|
|
461
|
-
icon.setAttribute("data-slot", "
|
|
460
|
+
icon.setAttribute("data-toaster-slot", "icon");
|
|
462
461
|
icon.setAttribute("aria-hidden", "true");
|
|
463
462
|
icon.innerHTML = ICONS[options.variant];
|
|
464
463
|
toast.append(icon);
|
|
465
464
|
}
|
|
466
465
|
|
|
467
466
|
const content = document.createElement("div");
|
|
468
|
-
content.setAttribute("data-slot", "
|
|
467
|
+
content.setAttribute("data-toaster-slot", "content");
|
|
469
468
|
if (options.title) {
|
|
470
469
|
const title = document.createElement("div");
|
|
471
|
-
title.setAttribute("data-slot", "
|
|
470
|
+
title.setAttribute("data-toaster-slot", "title");
|
|
472
471
|
title.textContent = options.title;
|
|
473
472
|
content.append(title);
|
|
474
473
|
}
|
|
475
474
|
if (options.description) {
|
|
476
475
|
const description = document.createElement("div");
|
|
477
|
-
description.setAttribute("data-slot", "
|
|
476
|
+
description.setAttribute("data-toaster-slot", "description");
|
|
478
477
|
description.textContent = options.description;
|
|
479
478
|
content.append(description);
|
|
480
479
|
}
|
|
@@ -484,9 +483,9 @@ class UiToaster extends ZazzElement {
|
|
|
484
483
|
if (action) {
|
|
485
484
|
const button = document.createElement("button");
|
|
486
485
|
button.type = "button";
|
|
487
|
-
button.
|
|
488
|
-
button.setAttribute("data-slot", "
|
|
489
|
-
button.dataset.
|
|
486
|
+
button.dataset.ui = "button";
|
|
487
|
+
button.setAttribute("data-toaster-slot", "action");
|
|
488
|
+
button.dataset.buttonSize = "sm";
|
|
490
489
|
button.textContent = action.label;
|
|
491
490
|
button.addEventListener("click", (event) => {
|
|
492
491
|
action.onClick?.(event);
|
|
@@ -498,10 +497,10 @@ class UiToaster extends ZazzElement {
|
|
|
498
497
|
if (options.closeButton !== false) {
|
|
499
498
|
const close = document.createElement("button");
|
|
500
499
|
close.type = "button";
|
|
501
|
-
close.
|
|
502
|
-
close.setAttribute("data-slot", "
|
|
503
|
-
close.dataset.
|
|
504
|
-
close.dataset.
|
|
500
|
+
close.dataset.ui = "button";
|
|
501
|
+
close.setAttribute("data-toaster-slot", "close");
|
|
502
|
+
close.dataset.buttonVariant = "ghost";
|
|
503
|
+
close.dataset.buttonSize = "icon-sm";
|
|
505
504
|
close.setAttribute("aria-label", "Close notification");
|
|
506
505
|
close.innerHTML = ICONS.close;
|
|
507
506
|
close.addEventListener("click", () => this.dismiss(id));
|
|
@@ -511,20 +510,18 @@ class UiToaster extends ZazzElement {
|
|
|
511
510
|
return toast;
|
|
512
511
|
}
|
|
513
512
|
|
|
514
|
-
// --- Stack math ---
|
|
515
|
-
|
|
516
513
|
/**
|
|
517
514
|
* @description Remeasures the stack: the measure half of the stacking
|
|
518
515
|
* model. Batch-reads every live toast's natural height and writes the
|
|
519
516
|
* result into `#stack`; `#layout` derives the placement purely
|
|
520
517
|
* (`computeStackLayout`) and the stack effect writes the CSS custom
|
|
521
|
-
* properties `
|
|
522
|
-
* `--initial-height`, `--front-toast-height`) plus `data-front`,
|
|
523
|
-
* `data-visible`, and z-index. DOM order is chronological; the last child
|
|
518
|
+
* properties `toaster.css` reads (`--toasts-before`, `--offset`,
|
|
519
|
+
* `--initial-height`, `--front-toast-height`) plus `data-toaster-state~="front"`,
|
|
520
|
+
* `data-toaster-state~="visible"`, and z-index. DOM order is chronological; the last child
|
|
524
521
|
* is the front (newest) toast.
|
|
525
522
|
*/
|
|
526
523
|
#reindex(): void {
|
|
527
|
-
const toasts = this.#toasts().filter((toast) => toast
|
|
524
|
+
const toasts = this.#toasts().filter((toast) => !isRemoved(toast));
|
|
528
525
|
|
|
529
526
|
// Batch-measure with heights unclamped, restored at scope exit: one
|
|
530
527
|
// layout pass, no visible change (the stack effect is microtask-batched,
|
|
@@ -539,10 +536,10 @@ class UiToaster extends ZazzElement {
|
|
|
539
536
|
* @returns The toast list (created in `connectedCallback`).
|
|
540
537
|
*/
|
|
541
538
|
#list(): HTMLOListElement {
|
|
542
|
-
let list = this.querySelector('[data-slot~="
|
|
539
|
+
let list = this.querySelector('[data-toaster-slot~="list"]');
|
|
543
540
|
if (!(list instanceof HTMLOListElement)) {
|
|
544
541
|
list = document.createElement("ol");
|
|
545
|
-
list.setAttribute("data-slot", "
|
|
542
|
+
list.setAttribute("data-toaster-slot", "list");
|
|
546
543
|
this.append(list);
|
|
547
544
|
}
|
|
548
545
|
return list as HTMLOListElement;
|
|
@@ -554,14 +551,12 @@ class UiToaster extends ZazzElement {
|
|
|
554
551
|
#toasts(): HTMLElement[] {
|
|
555
552
|
return Array.from(this.#list().children)
|
|
556
553
|
.filter((child): child is HTMLElement => child instanceof HTMLElement)
|
|
557
|
-
.filter((child) => child.matches('[data-slot~="
|
|
554
|
+
.filter((child) => child.matches('[data-toaster-slot~="toast"]'));
|
|
558
555
|
}
|
|
559
556
|
|
|
560
|
-
// --- Expand / collapse ---
|
|
561
|
-
|
|
562
557
|
/**
|
|
563
558
|
* @description Expands or collapses the stack by writing the signal state.
|
|
564
|
-
* The attribute write and the timer pause/resume
|
|
559
|
+
* The attribute write and the timer pause/resume are owned
|
|
565
560
|
* by the effects in `connectedCallback`: no caller has to remember them.
|
|
566
561
|
*
|
|
567
562
|
* @param expanded - Whether the stack is expanded.
|
|
@@ -586,8 +581,6 @@ class UiToaster extends ZazzElement {
|
|
|
586
581
|
}, 100);
|
|
587
582
|
}
|
|
588
583
|
|
|
589
|
-
// --- Timers ---
|
|
590
|
-
|
|
591
584
|
/**
|
|
592
585
|
* @description Registers a toast's auto-dismiss timer and schedules it unless
|
|
593
586
|
* the stack is currently paused (expanded or hidden tab).
|
|
@@ -635,8 +628,6 @@ class UiToaster extends ZazzElement {
|
|
|
635
628
|
}
|
|
636
629
|
}
|
|
637
630
|
|
|
638
|
-
// --- Region show/hide ---
|
|
639
|
-
|
|
640
631
|
/**
|
|
641
632
|
* @description Puts the region on the top layer if it isn't already.
|
|
642
633
|
*/
|
|
@@ -644,8 +635,7 @@ class UiToaster extends ZazzElement {
|
|
|
644
635
|
try {
|
|
645
636
|
if (!this.matches(":popover-open")) this.showPopover();
|
|
646
637
|
} catch {
|
|
647
|
-
//
|
|
648
|
-
// element, which still renders (just not on the top layer).
|
|
638
|
+
// without the Popover API the region stays a fixed-position element
|
|
649
639
|
}
|
|
650
640
|
}
|
|
651
641
|
|
|
@@ -664,7 +654,7 @@ class UiToaster extends ZazzElement {
|
|
|
664
654
|
* @description Removes a dismissed toast after its exit transition (with a
|
|
665
655
|
* timeout safety net), then hides the region once the stack is empty.
|
|
666
656
|
*
|
|
667
|
-
* @param toast - The toast marked `data-removed
|
|
657
|
+
* @param toast - The toast marked `data-toaster-state~="removed"`.
|
|
668
658
|
*/
|
|
669
659
|
#finalizeRemoval(toast: HTMLElement): void {
|
|
670
660
|
let done = false;
|
|
@@ -692,8 +682,6 @@ class UiToaster extends ZazzElement {
|
|
|
692
682
|
}
|
|
693
683
|
}
|
|
694
684
|
|
|
695
|
-
// --- Imperative API ---
|
|
696
|
-
|
|
697
685
|
/**
|
|
698
686
|
* @description Resolves a target region from an id, element, or the document.
|
|
699
687
|
*
|
|
@@ -707,12 +695,12 @@ function resolveRegion(region?: string | Element): UiToaster | null {
|
|
|
707
695
|
? region
|
|
708
696
|
: typeof region === "string"
|
|
709
697
|
? document.getElementById(region)
|
|
710
|
-
: document.querySelector(
|
|
698
|
+
: document.querySelector('ui-toaster, [data-ui~="toaster"]');
|
|
711
699
|
|
|
712
700
|
if (node instanceof UiToaster) return node;
|
|
713
701
|
|
|
714
702
|
console.warn(
|
|
715
|
-
'Toaster: no <ui-toaster> found. Add `<ui-toaster
|
|
703
|
+
'Toaster: no <ui-toaster> found. Add `<ui-toaster popover="manual"></ui-toaster>` to the page.',
|
|
716
704
|
);
|
|
717
705
|
return null;
|
|
718
706
|
}
|
|
@@ -804,7 +792,7 @@ const Toaster = {
|
|
|
804
792
|
* @param id - Toast id returned by `toast()`.
|
|
805
793
|
*/
|
|
806
794
|
dismiss(id?: string): void {
|
|
807
|
-
for (const region of document.querySelectorAll(
|
|
795
|
+
for (const region of document.querySelectorAll('ui-toaster, [data-ui~="toaster"]')) {
|
|
808
796
|
if (region instanceof UiToaster) region.dismiss(id);
|
|
809
797
|
}
|
|
810
798
|
},
|
|
@@ -812,12 +800,8 @@ const Toaster = {
|
|
|
812
800
|
|
|
813
801
|
defineZazzElement("ui-toaster", UiToaster);
|
|
814
802
|
|
|
815
|
-
// Attach the imperative toast API to window (the documented public surface app
|
|
816
|
-
// authors call), then export for module consumers.
|
|
817
803
|
if (typeof window !== "undefined") {
|
|
818
804
|
window.Toaster = Toaster;
|
|
819
805
|
}
|
|
820
806
|
|
|
821
|
-
// computeStackLayout is exported for unit tests only; not part of the
|
|
822
|
-
// documented public API (window.Toaster is the surface app authors use).
|
|
823
807
|
export { Toaster, UiToaster, computeStackLayout };
|