@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
|
@@ -54,42 +54,35 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
54
54
|
/**
|
|
55
55
|
* @fileoverview `<ui-toaster>`: HTML web component for stacked toast notifications.
|
|
56
56
|
* @description Light-DOM custom element that hosts a top-layer toast stack, plus
|
|
57
|
-
* the `window.Toaster` imperative API.
|
|
58
|
-
* older toasts peeking behind, expand on hover, timer pause on hover/hidden tab)
|
|
59
|
-
* is adapted from Sonner by Emil Kowalski (https://sonner.emilkowal.ski, MIT).
|
|
57
|
+
* the `window.Toaster` imperative API. Timers pause on hover and in hidden tabs.
|
|
60
58
|
*
|
|
61
59
|
* The region is a `popover="manual"` element: it enters the top layer via
|
|
62
60
|
* `showPopover()` when the first toast arrives and leaves it after the last
|
|
63
61
|
* toast's exit transition. Toasts are plain `<li>` children, so the collapsed
|
|
64
|
-
* stack offsets in `
|
|
62
|
+
* stack offsets in `toaster.css` work with normal CSS transforms.
|
|
65
63
|
*
|
|
66
64
|
* Fire toasts two ways:
|
|
67
65
|
* - Declaratively, from any button, via a custom Invoker Command:
|
|
68
66
|
* `command="--toast"` (or `--toast-success|info|warning|destructive`) with
|
|
69
67
|
* `commandfor="<region id>"`. Toast content comes from the button's
|
|
70
|
-
* `data-title`, `data-description`, `data-variant`,
|
|
71
|
-
* `data-close-button` attributes.
|
|
68
|
+
* `data-toaster-title`, `data-toaster-description`, `data-toaster-variant`,
|
|
69
|
+
* `data-toaster-duration`, and `data-toaster-close-button` attributes.
|
|
72
70
|
* - Imperatively: `window.Toaster.toast({ title, description, variant, … })`
|
|
73
71
|
* and the `.success()/.info()/.warning()/.error()` shorthands.
|
|
74
72
|
*
|
|
75
73
|
* Region attributes:
|
|
76
|
-
* - `data-position`: `top-start | top-center | top-end | bottom-start |
|
|
74
|
+
* - `data-toaster-position`: `top-start | top-center | top-end | bottom-start |
|
|
77
75
|
* bottom-center | bottom-end` (logical; default `bottom-end`).
|
|
78
76
|
*
|
|
79
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Popover_API
|
|
80
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Invoker_Commands_API
|
|
81
|
-
*
|
|
82
77
|
* @example
|
|
83
|
-
* <ui-toaster
|
|
84
|
-
* <button commandfor="toaster" command="--toast" data-title="Saved">Save</button>
|
|
78
|
+
* <ui-toaster id="toaster" popover="manual"></ui-toaster>
|
|
79
|
+
* <button commandfor="toaster" command="--toast" data-toaster-title="Saved">Save</button>
|
|
85
80
|
*/
|
|
86
81
|
import { computed, effect, state } from "../../base/signals.js";
|
|
87
82
|
import { ZazzElement, defineZazzElement } from "../../base/zazz-element.js";
|
|
88
|
-
// `using`
|
|
89
|
-
//
|
|
90
|
-
// Management (Safari) don't define it, so give them a local stand-in.
|
|
83
|
+
// compiled `using` reads Symbol.dispose, which engines without native Explicit
|
|
84
|
+
// Resource Management (Safari) lack
|
|
91
85
|
Symbol.dispose ??= Symbol("Symbol.dispose");
|
|
92
|
-
// --- Constants ---
|
|
93
86
|
/** Default toast lifetime in milliseconds. */
|
|
94
87
|
const TOAST_LIFETIME = 4000;
|
|
95
88
|
/** Maximum number of toasts shown in the collapsed stack. */
|
|
@@ -97,7 +90,6 @@ const VISIBLE_TOASTS = 3;
|
|
|
97
90
|
/** Safety net for node removal when no exit `transitionend` fires. */
|
|
98
91
|
const EXIT_FALLBACK_MS = 600;
|
|
99
92
|
const VARIANTS = ["success", "info", "warning", "destructive"];
|
|
100
|
-
// --- Icons (adapted from Sonner's assets.tsx (MIT, Emil Kowalski)) ---
|
|
101
93
|
const ICONS = {
|
|
102
94
|
success: '<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>',
|
|
103
95
|
info: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clip-rule="evenodd"/></svg>',
|
|
@@ -105,7 +97,6 @@ const ICONS = {
|
|
|
105
97
|
destructive: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z" clip-rule="evenodd"/></svg>',
|
|
106
98
|
close: '<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>',
|
|
107
99
|
};
|
|
108
|
-
// --- Measurement ---
|
|
109
100
|
/**
|
|
110
101
|
* @description Unclamps every toast's block-size for a batch measurement (the
|
|
111
102
|
* inline style beats the collapsed block-size rule) and returns a disposer
|
|
@@ -126,7 +117,6 @@ function unclampForMeasure(toasts) {
|
|
|
126
117
|
},
|
|
127
118
|
};
|
|
128
119
|
}
|
|
129
|
-
// --- Stack math (pure) ---
|
|
130
120
|
/**
|
|
131
121
|
* @description Computes the collapsed-stack placement for every toast from the
|
|
132
122
|
* measured heights alone (oldest first, matching DOM order). Pure: the
|
|
@@ -153,13 +143,28 @@ function computeStackLayout(heights) {
|
|
|
153
143
|
}
|
|
154
144
|
return { toasts, frontToastHeightPx: count > 0 ? heights[count - 1] : null };
|
|
155
145
|
}
|
|
156
|
-
// --- <ui-toaster> element ---
|
|
157
146
|
/**
|
|
158
147
|
* @class
|
|
159
148
|
* @description Hosts the toast stack: builds toast markup, maintains the
|
|
160
149
|
* collapsed-stack CSS custom properties, runs auto-dismiss timers, and shows or
|
|
161
150
|
* hides the `popover="manual"` region as toasts come and go.
|
|
162
151
|
*/
|
|
152
|
+
/**
|
|
153
|
+
* @description Adds or removes one token of an element's `data-toaster-state`
|
|
154
|
+
* list: `expanded` on the region; `front`, `visible`, `removed` on a toast.
|
|
155
|
+
*/
|
|
156
|
+
function setToasterState(node, token, on) {
|
|
157
|
+
const tokens = (node.getAttribute("data-toaster-state") ?? "").split(/\s+/).filter(Boolean);
|
|
158
|
+
const next = on ? [...new Set([...tokens, token])] : tokens.filter((t) => t !== token);
|
|
159
|
+
if (next.length)
|
|
160
|
+
node.setAttribute("data-toaster-state", next.join(" "));
|
|
161
|
+
else
|
|
162
|
+
node.removeAttribute("data-toaster-state");
|
|
163
|
+
}
|
|
164
|
+
/** @description Whether a toast has been dismissed and is animating out. */
|
|
165
|
+
function isRemoved(toast) {
|
|
166
|
+
return toast.matches('[data-toaster-state~="removed"]');
|
|
167
|
+
}
|
|
163
168
|
class UiToaster extends ZazzElement {
|
|
164
169
|
#timers = new Map();
|
|
165
170
|
#counter = 0;
|
|
@@ -189,9 +194,9 @@ class UiToaster extends ZazzElement {
|
|
|
189
194
|
if (!this.hasAttribute("tabindex"))
|
|
190
195
|
this.setAttribute("tabindex", "-1");
|
|
191
196
|
// The live region must exist before toasts are inserted so additions announce.
|
|
192
|
-
if (!this.querySelector('[data-slot~="
|
|
197
|
+
if (!this.querySelector('[data-toaster-slot~="list"]')) {
|
|
193
198
|
const list = document.createElement("ol");
|
|
194
|
-
list.setAttribute("data-slot", "
|
|
199
|
+
list.setAttribute("data-toaster-slot", "list");
|
|
195
200
|
list.setAttribute("aria-live", "polite");
|
|
196
201
|
list.setAttribute("aria-relevant", "additions text");
|
|
197
202
|
list.setAttribute("aria-atomic", "false");
|
|
@@ -218,7 +223,7 @@ class UiToaster extends ZazzElement {
|
|
|
218
223
|
// one owns the expanded attribute, one owns pausing/resuming the timers,
|
|
219
224
|
// one writes the computed stack placement to the DOM.
|
|
220
225
|
effect(() => {
|
|
221
|
-
this
|
|
226
|
+
setToasterState(this, "expanded", this.#expanded.get());
|
|
222
227
|
}, { signal });
|
|
223
228
|
effect(() => {
|
|
224
229
|
if (this.#paused.get()) {
|
|
@@ -234,8 +239,8 @@ class UiToaster extends ZazzElement {
|
|
|
234
239
|
for (let i = 0; i < entries.length; i++) {
|
|
235
240
|
const { node, height } = entries[i];
|
|
236
241
|
const layout = toasts[i];
|
|
237
|
-
node
|
|
238
|
-
node
|
|
242
|
+
setToasterState(node, "front", layout.front);
|
|
243
|
+
setToasterState(node, "visible", layout.visible);
|
|
239
244
|
node.style.zIndex = String(layout.zIndex);
|
|
240
245
|
node.style.setProperty("--toasts-before", String(layout.stackIndex));
|
|
241
246
|
node.style.setProperty("--initial-height", `${height}px`);
|
|
@@ -253,7 +258,6 @@ class UiToaster extends ZazzElement {
|
|
|
253
258
|
clearTimeout(timer.timeoutId);
|
|
254
259
|
this.#timers.clear();
|
|
255
260
|
}
|
|
256
|
-
// --- Public API ---
|
|
257
261
|
/**
|
|
258
262
|
* @description Adds a toast to this region and shows the region if needed.
|
|
259
263
|
*
|
|
@@ -281,14 +285,14 @@ class UiToaster extends ZazzElement {
|
|
|
281
285
|
this.dismissAll();
|
|
282
286
|
return;
|
|
283
287
|
}
|
|
284
|
-
const toast = this.#list().querySelector(`[data-
|
|
285
|
-
if (!(toast instanceof HTMLElement) || toast
|
|
288
|
+
const toast = this.#list().querySelector(`[data-toaster-id="${CSS.escape(id)}"]`);
|
|
289
|
+
if (!(toast instanceof HTMLElement) || isRemoved(toast))
|
|
286
290
|
return;
|
|
287
291
|
const timer = this.#timers.get(id);
|
|
288
292
|
if (timer)
|
|
289
293
|
clearTimeout(timer.timeoutId);
|
|
290
294
|
this.#timers.delete(id);
|
|
291
|
-
toast
|
|
295
|
+
setToasterState(toast, "removed", true);
|
|
292
296
|
// Keyboard users keep their place: hand focus to the next toast before this
|
|
293
297
|
// one goes. A mouse click's incidental focus is left to drop to <body>;
|
|
294
298
|
// holding it would pin the stack expanded after the pointer leaves, and
|
|
@@ -298,7 +302,7 @@ class UiToaster extends ZazzElement {
|
|
|
298
302
|
toast.contains(active) &&
|
|
299
303
|
active.matches(":focus-visible")) {
|
|
300
304
|
this.#toasts()
|
|
301
|
-
.filter((t) => t
|
|
305
|
+
.filter((t) => !isRemoved(t))
|
|
302
306
|
.at(-1)
|
|
303
307
|
?.focus({ preventScroll: true });
|
|
304
308
|
}
|
|
@@ -310,16 +314,15 @@ class UiToaster extends ZazzElement {
|
|
|
310
314
|
*/
|
|
311
315
|
dismissAll() {
|
|
312
316
|
for (const toast of this.#toasts()) {
|
|
313
|
-
const toastId = toast.dataset.
|
|
317
|
+
const toastId = toast.dataset.toasterId;
|
|
314
318
|
if (toastId)
|
|
315
319
|
this.dismiss(toastId);
|
|
316
320
|
}
|
|
317
321
|
}
|
|
318
|
-
// --- Invoker Commands ---
|
|
319
322
|
/**
|
|
320
323
|
* @description Handles the custom `--toast` Invoker Command fired by buttons
|
|
321
324
|
* with `commandfor` pointing at this region. `--toast-success` (etc.) sets the
|
|
322
|
-
* variant; everything else comes from the invoker's `data-*` attributes.
|
|
325
|
+
* variant; everything else comes from the invoker's `data-toaster-*` attributes.
|
|
323
326
|
*
|
|
324
327
|
* @param event - The command event.
|
|
325
328
|
*/
|
|
@@ -344,7 +347,7 @@ class UiToaster extends ZazzElement {
|
|
|
344
347
|
options.variant = suffix;
|
|
345
348
|
}
|
|
346
349
|
if (source instanceof HTMLElement) {
|
|
347
|
-
const { title, description, variant, duration, closeButton } = source.dataset;
|
|
350
|
+
const { toasterTitle: title, toasterDescription: description, toasterVariant: variant, toasterDuration: duration, toasterCloseButton: closeButton, } = source.dataset;
|
|
348
351
|
if (title)
|
|
349
352
|
options.title = title;
|
|
350
353
|
if (description)
|
|
@@ -367,7 +370,6 @@ class UiToaster extends ZazzElement {
|
|
|
367
370
|
}
|
|
368
371
|
this.addToast(options);
|
|
369
372
|
}
|
|
370
|
-
// --- Toast construction ---
|
|
371
373
|
/**
|
|
372
374
|
* @description Builds a toast `<li>`: status icon, title/description, and the
|
|
373
375
|
* optional action and close buttons. Text is set via `textContent`.
|
|
@@ -378,29 +380,29 @@ class UiToaster extends ZazzElement {
|
|
|
378
380
|
*/
|
|
379
381
|
#buildToast(options, id) {
|
|
380
382
|
const toast = document.createElement("li");
|
|
381
|
-
toast.setAttribute("data-slot", "
|
|
382
|
-
toast.dataset.
|
|
383
|
+
toast.setAttribute("data-toaster-slot", "toast");
|
|
384
|
+
toast.dataset.toasterId = id;
|
|
383
385
|
toast.tabIndex = 0;
|
|
384
386
|
if (options.variant)
|
|
385
|
-
toast.dataset.
|
|
387
|
+
toast.dataset.toasterVariant = options.variant;
|
|
386
388
|
if (options.variant) {
|
|
387
389
|
const icon = document.createElement("span");
|
|
388
|
-
icon.setAttribute("data-slot", "
|
|
390
|
+
icon.setAttribute("data-toaster-slot", "icon");
|
|
389
391
|
icon.setAttribute("aria-hidden", "true");
|
|
390
392
|
icon.innerHTML = ICONS[options.variant];
|
|
391
393
|
toast.append(icon);
|
|
392
394
|
}
|
|
393
395
|
const content = document.createElement("div");
|
|
394
|
-
content.setAttribute("data-slot", "
|
|
396
|
+
content.setAttribute("data-toaster-slot", "content");
|
|
395
397
|
if (options.title) {
|
|
396
398
|
const title = document.createElement("div");
|
|
397
|
-
title.setAttribute("data-slot", "
|
|
399
|
+
title.setAttribute("data-toaster-slot", "title");
|
|
398
400
|
title.textContent = options.title;
|
|
399
401
|
content.append(title);
|
|
400
402
|
}
|
|
401
403
|
if (options.description) {
|
|
402
404
|
const description = document.createElement("div");
|
|
403
|
-
description.setAttribute("data-slot", "
|
|
405
|
+
description.setAttribute("data-toaster-slot", "description");
|
|
404
406
|
description.textContent = options.description;
|
|
405
407
|
content.append(description);
|
|
406
408
|
}
|
|
@@ -409,9 +411,9 @@ class UiToaster extends ZazzElement {
|
|
|
409
411
|
if (action) {
|
|
410
412
|
const button = document.createElement("button");
|
|
411
413
|
button.type = "button";
|
|
412
|
-
button.
|
|
413
|
-
button.setAttribute("data-slot", "
|
|
414
|
-
button.dataset.
|
|
414
|
+
button.dataset.ui = "button";
|
|
415
|
+
button.setAttribute("data-toaster-slot", "action");
|
|
416
|
+
button.dataset.buttonSize = "sm";
|
|
415
417
|
button.textContent = action.label;
|
|
416
418
|
button.addEventListener("click", (event) => {
|
|
417
419
|
action.onClick?.(event);
|
|
@@ -423,10 +425,10 @@ class UiToaster extends ZazzElement {
|
|
|
423
425
|
if (options.closeButton !== false) {
|
|
424
426
|
const close = document.createElement("button");
|
|
425
427
|
close.type = "button";
|
|
426
|
-
close.
|
|
427
|
-
close.setAttribute("data-slot", "
|
|
428
|
-
close.dataset.
|
|
429
|
-
close.dataset.
|
|
428
|
+
close.dataset.ui = "button";
|
|
429
|
+
close.setAttribute("data-toaster-slot", "close");
|
|
430
|
+
close.dataset.buttonVariant = "ghost";
|
|
431
|
+
close.dataset.buttonSize = "icon-sm";
|
|
430
432
|
close.setAttribute("aria-label", "Close notification");
|
|
431
433
|
close.innerHTML = ICONS.close;
|
|
432
434
|
close.addEventListener("click", () => this.dismiss(id));
|
|
@@ -434,21 +436,20 @@ class UiToaster extends ZazzElement {
|
|
|
434
436
|
}
|
|
435
437
|
return toast;
|
|
436
438
|
}
|
|
437
|
-
// --- Stack math ---
|
|
438
439
|
/**
|
|
439
440
|
* @description Remeasures the stack: the measure half of the stacking
|
|
440
441
|
* model. Batch-reads every live toast's natural height and writes the
|
|
441
442
|
* result into `#stack`; `#layout` derives the placement purely
|
|
442
443
|
* (`computeStackLayout`) and the stack effect writes the CSS custom
|
|
443
|
-
* properties `
|
|
444
|
-
* `--initial-height`, `--front-toast-height`) plus `data-front`,
|
|
445
|
-
* `data-visible`, and z-index. DOM order is chronological; the last child
|
|
444
|
+
* properties `toaster.css` reads (`--toasts-before`, `--offset`,
|
|
445
|
+
* `--initial-height`, `--front-toast-height`) plus `data-toaster-state~="front"`,
|
|
446
|
+
* `data-toaster-state~="visible"`, and z-index. DOM order is chronological; the last child
|
|
446
447
|
* is the front (newest) toast.
|
|
447
448
|
*/
|
|
448
449
|
#reindex() {
|
|
449
450
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
450
451
|
try {
|
|
451
|
-
const toasts = this.#toasts().filter((toast) => toast
|
|
452
|
+
const toasts = this.#toasts().filter((toast) => !isRemoved(toast));
|
|
452
453
|
// Batch-measure with heights unclamped, restored at scope exit: one
|
|
453
454
|
// layout pass, no visible change (the stack effect is microtask-batched,
|
|
454
455
|
// so its DOM writes land after the restore).
|
|
@@ -468,10 +469,10 @@ class UiToaster extends ZazzElement {
|
|
|
468
469
|
* @returns The toast list (created in `connectedCallback`).
|
|
469
470
|
*/
|
|
470
471
|
#list() {
|
|
471
|
-
let list = this.querySelector('[data-slot~="
|
|
472
|
+
let list = this.querySelector('[data-toaster-slot~="list"]');
|
|
472
473
|
if (!(list instanceof HTMLOListElement)) {
|
|
473
474
|
list = document.createElement("ol");
|
|
474
|
-
list.setAttribute("data-slot", "
|
|
475
|
+
list.setAttribute("data-toaster-slot", "list");
|
|
475
476
|
this.append(list);
|
|
476
477
|
}
|
|
477
478
|
return list;
|
|
@@ -482,12 +483,11 @@ class UiToaster extends ZazzElement {
|
|
|
482
483
|
#toasts() {
|
|
483
484
|
return Array.from(this.#list().children)
|
|
484
485
|
.filter((child) => child instanceof HTMLElement)
|
|
485
|
-
.filter((child) => child.matches('[data-slot~="
|
|
486
|
+
.filter((child) => child.matches('[data-toaster-slot~="toast"]'));
|
|
486
487
|
}
|
|
487
|
-
// --- Expand / collapse ---
|
|
488
488
|
/**
|
|
489
489
|
* @description Expands or collapses the stack by writing the signal state.
|
|
490
|
-
* The attribute write and the timer pause/resume
|
|
490
|
+
* The attribute write and the timer pause/resume are owned
|
|
491
491
|
* by the effects in `connectedCallback`: no caller has to remember them.
|
|
492
492
|
*
|
|
493
493
|
* @param expanded - Whether the stack is expanded.
|
|
@@ -512,7 +512,6 @@ class UiToaster extends ZazzElement {
|
|
|
512
512
|
this.#setExpanded(false);
|
|
513
513
|
}, 100);
|
|
514
514
|
}
|
|
515
|
-
// --- Timers ---
|
|
516
515
|
/**
|
|
517
516
|
* @description Registers a toast's auto-dismiss timer and schedules it unless
|
|
518
517
|
* the stack is currently paused (expanded or hidden tab).
|
|
@@ -561,7 +560,6 @@ class UiToaster extends ZazzElement {
|
|
|
561
560
|
this.#schedule(id, timer);
|
|
562
561
|
}
|
|
563
562
|
}
|
|
564
|
-
// --- Region show/hide ---
|
|
565
563
|
/**
|
|
566
564
|
* @description Puts the region on the top layer if it isn't already.
|
|
567
565
|
*/
|
|
@@ -571,8 +569,7 @@ class UiToaster extends ZazzElement {
|
|
|
571
569
|
this.showPopover();
|
|
572
570
|
}
|
|
573
571
|
catch {
|
|
574
|
-
//
|
|
575
|
-
// element, which still renders (just not on the top layer).
|
|
572
|
+
// without the Popover API the region stays a fixed-position element
|
|
576
573
|
}
|
|
577
574
|
}
|
|
578
575
|
/**
|
|
@@ -591,7 +588,7 @@ class UiToaster extends ZazzElement {
|
|
|
591
588
|
* @description Removes a dismissed toast after its exit transition (with a
|
|
592
589
|
* timeout safety net), then hides the region once the stack is empty.
|
|
593
590
|
*
|
|
594
|
-
* @param toast - The toast marked `data-removed
|
|
591
|
+
* @param toast - The toast marked `data-toaster-state~="removed"`.
|
|
595
592
|
*/
|
|
596
593
|
#finalizeRemoval(toast) {
|
|
597
594
|
let done = false;
|
|
@@ -618,7 +615,6 @@ class UiToaster extends ZazzElement {
|
|
|
618
615
|
window.setTimeout(remove, Math.max(EXIT_FALLBACK_MS, duration * 1000 + 100));
|
|
619
616
|
}
|
|
620
617
|
}
|
|
621
|
-
// --- Imperative API ---
|
|
622
618
|
/**
|
|
623
619
|
* @description Resolves a target region from an id, element, or the document.
|
|
624
620
|
*
|
|
@@ -631,10 +627,10 @@ function resolveRegion(region) {
|
|
|
631
627
|
? region
|
|
632
628
|
: typeof region === "string"
|
|
633
629
|
? document.getElementById(region)
|
|
634
|
-
: document.querySelector(
|
|
630
|
+
: document.querySelector('ui-toaster, [data-ui~="toaster"]');
|
|
635
631
|
if (node instanceof UiToaster)
|
|
636
632
|
return node;
|
|
637
|
-
console.warn('Toaster: no <ui-toaster> found. Add `<ui-toaster
|
|
633
|
+
console.warn('Toaster: no <ui-toaster> found. Add `<ui-toaster popover="manual"></ui-toaster>` to the page.');
|
|
638
634
|
return null;
|
|
639
635
|
}
|
|
640
636
|
/**
|
|
@@ -719,18 +715,14 @@ const Toaster = {
|
|
|
719
715
|
* @param id - Toast id returned by `toast()`.
|
|
720
716
|
*/
|
|
721
717
|
dismiss(id) {
|
|
722
|
-
for (const region of document.querySelectorAll(
|
|
718
|
+
for (const region of document.querySelectorAll('ui-toaster, [data-ui~="toaster"]')) {
|
|
723
719
|
if (region instanceof UiToaster)
|
|
724
720
|
region.dismiss(id);
|
|
725
721
|
}
|
|
726
722
|
},
|
|
727
723
|
};
|
|
728
724
|
defineZazzElement("ui-toaster", UiToaster);
|
|
729
|
-
// Attach the imperative toast API to window (the documented public surface app
|
|
730
|
-
// authors call), then export for module consumers.
|
|
731
725
|
if (typeof window !== "undefined") {
|
|
732
726
|
window.Toaster = Toaster;
|
|
733
727
|
}
|
|
734
|
-
// computeStackLayout is exported for unit tests only; not part of the
|
|
735
|
-
// documented public API (window.Toaster is the surface app authors use).
|
|
736
728
|
export { Toaster, UiToaster, computeStackLayout };
|