@zazz-ui/core 0.4.1 → 0.5.1
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 +345 -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 +61 -31
- 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 +76 -26
- 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
|
@@ -1,12 +1,31 @@
|
|
|
1
|
-
<div
|
|
2
|
-
<label data-slot="
|
|
3
|
-
<select
|
|
1
|
+
<div data-ui="field">
|
|
2
|
+
<label data-field-slot="label" for="f-sort">Sort by</label>
|
|
3
|
+
<select data-ui="select" id="f-sort" name="sort">
|
|
4
4
|
<button>
|
|
5
5
|
<selectedcontent></selectedcontent>
|
|
6
6
|
</button>
|
|
7
7
|
<!-- Keep label in optgroup as a fallback -->
|
|
8
|
-
<optgroup
|
|
9
|
-
|
|
8
|
+
<optgroup
|
|
9
|
+
label="Sort by"
|
|
10
|
+
style="
|
|
11
|
+
--display: grid;
|
|
12
|
+
--gap: 1px;
|
|
13
|
+
"
|
|
14
|
+
>
|
|
15
|
+
<legend
|
|
16
|
+
style="
|
|
17
|
+
--display: inline-flex;
|
|
18
|
+
--p: 2;
|
|
19
|
+
--font-size: var(--font-size-eyebrow);
|
|
20
|
+
--font-weight: var(--font-weight-eyebrow);
|
|
21
|
+
--leading: var(--leading-eyebrow);
|
|
22
|
+
--tracking: var(--tracking-eyebrow);
|
|
23
|
+
--text-transform: uppercase;
|
|
24
|
+
--text: var(--color-muted-foreground);
|
|
25
|
+
"
|
|
26
|
+
>
|
|
27
|
+
Sort by
|
|
28
|
+
</legend>
|
|
10
29
|
<option value="recent" selected>Most recent</option>
|
|
11
30
|
<option value="popular">Most popular</option>
|
|
12
31
|
<option value="price-asc">Price: low to high</option>
|
|
@@ -1,44 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* separator.css: Separator (
|
|
2
|
+
* separator.css: Separator ([data-ui~="separator"] on native <hr>)
|
|
3
3
|
*
|
|
4
4
|
* @layer variables, components
|
|
5
|
-
* @requires
|
|
6
|
-
* @uses <hr>: the platform's separator (implicit role="separator")
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @tokens --ui-separator-* (@layer variables)
|
|
5
|
+
* @requires _layers.css, _variables.css, _reset.css, _properties.css (--_bg-resolved)
|
|
6
|
+
* @uses <hr>: the platform's separator (implicit role="separator")
|
|
7
|
+
* @uses data-separator-orientation="vertical": flips to a stretching
|
|
8
|
+
* column rule for flex/grid rows; pair with aria-orientation="vertical"
|
|
9
|
+
* when the separator is meaningful, or role="presentation" when
|
|
10
|
+
* purely decorative
|
|
11
|
+
* @tokens --ui-separator-* (@layer variables; --ui-separator-bg backs the --bg utility)
|
|
13
12
|
*/
|
|
14
13
|
|
|
15
14
|
@layer variables {
|
|
16
15
|
:root {
|
|
17
|
-
--ui-separator-
|
|
18
|
-
--ui-separator-thickness:
|
|
16
|
+
--ui-separator-bg: var(--color-border);
|
|
17
|
+
--ui-separator-thickness: 1px;
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
@layer
|
|
21
|
+
@layer ui.components {
|
|
23
22
|
/* ===========================================================================
|
|
24
23
|
SEPARATOR: a themed <hr>, horizontal or vertical
|
|
25
|
-
-
|
|
26
|
-
and the vertical form. Spacing is composition (my-xs / mx-xs utilities),
|
|
27
|
-
like every other recipe.
|
|
24
|
+
- Spacing is composition (--my / --mx utilities).
|
|
28
25
|
- Meaningful separators keep hr's implicit separator role (add
|
|
29
26
|
aria-orientation="vertical" for the vertical form: AT assumes
|
|
30
27
|
horizontal); decorative ones take role="presentation".
|
|
31
28
|
=========================================================================== */
|
|
32
29
|
|
|
33
|
-
|
|
30
|
+
:where([data-ui~="separator"]) {
|
|
34
31
|
border: none;
|
|
35
|
-
background-color: var(--ui-separator-
|
|
32
|
+
background-color: var(--_bg-resolved, var(--ui-separator-bg));
|
|
36
33
|
block-size: var(--ui-separator-thickness);
|
|
37
34
|
inline-size: auto;
|
|
38
35
|
flex-shrink: 0;
|
|
39
36
|
}
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
:where([data-ui~="separator"][data-separator-orientation="vertical"]) {
|
|
42
39
|
inline-size: var(--ui-separator-thickness);
|
|
43
40
|
block-size: auto;
|
|
44
41
|
/* Stretches to the row height as a flex/grid item; the fallback keeps it
|
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
<div
|
|
1
|
+
<div
|
|
2
|
+
style="
|
|
3
|
+
--display: flex-col;
|
|
4
|
+
--gap: 4;
|
|
5
|
+
--max-w: 96;
|
|
6
|
+
"
|
|
7
|
+
>
|
|
2
8
|
<div>
|
|
3
|
-
<p
|
|
4
|
-
|
|
9
|
+
<p
|
|
10
|
+
style="
|
|
11
|
+
--font-size: var(--font-size-sm);
|
|
12
|
+
--font-weight: strong;
|
|
13
|
+
"
|
|
14
|
+
>
|
|
15
|
+
Zazz Design Framework
|
|
16
|
+
</p>
|
|
17
|
+
<p
|
|
18
|
+
style="
|
|
19
|
+
--font-size: var(--font-size-sm);
|
|
20
|
+
--text: var(--color-muted-foreground);
|
|
21
|
+
"
|
|
22
|
+
>
|
|
23
|
+
Web-native primitives.
|
|
24
|
+
</p>
|
|
5
25
|
</div>
|
|
6
26
|
|
|
7
|
-
<hr
|
|
27
|
+
<hr data-ui="separator" />
|
|
8
28
|
|
|
9
|
-
<div
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
29
|
+
<div
|
|
30
|
+
style="
|
|
31
|
+
--display: flex;
|
|
32
|
+
--items: center;
|
|
33
|
+
--gap: 2;
|
|
34
|
+
--font-size: var(--font-size-sm);
|
|
35
|
+
"
|
|
36
|
+
>
|
|
37
|
+
<a href="#" data-ui="button" data-button-variant="link">Docs</a>
|
|
38
|
+
<hr data-ui="separator" data-separator-orientation="vertical" aria-orientation="vertical" />
|
|
39
|
+
<a href="#" data-ui="button" data-button-variant="link">Components</a>
|
|
40
|
+
<hr data-ui="separator" data-separator-orientation="vertical" aria-orientation="vertical" />
|
|
41
|
+
<a href="#" data-ui="button" data-button-variant="link">Themes</a>
|
|
15
42
|
</div>
|
|
16
43
|
</div>
|
|
@@ -1,38 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* slider.css — Range input (input[type="range"])
|
|
3
3
|
*
|
|
4
|
-
* @layer reset
|
|
5
|
-
* @requires
|
|
4
|
+
* @layer variables, reset
|
|
5
|
+
* @requires _layers.css, _variables.css
|
|
6
6
|
* @uses appearance: none — redraws track + thumb from theme tokens
|
|
7
|
-
* @tokens --ui-slider-* (
|
|
7
|
+
* @tokens --ui-slider-* (@layer variables, on :root so subtree hooks work)
|
|
8
8
|
*
|
|
9
9
|
* Note: The active region is NOT filled (parity across engines); add a paint
|
|
10
10
|
* via JS if a filled track is needed. The thumb is centered on the track with a
|
|
11
11
|
* calc'd negative margin so retuning either size keeps it aligned.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
@layer
|
|
15
|
-
:
|
|
16
|
-
--ui-slider-ring-color: var(--ring
|
|
14
|
+
@layer variables {
|
|
15
|
+
:root {
|
|
16
|
+
--ui-slider-ring-color: var(--color-ring);
|
|
17
17
|
|
|
18
|
-
--ui-slider-track-
|
|
19
|
-
--ui-slider-track-
|
|
20
|
-
--ui-slider-track-border: 1px solid var(--muted);
|
|
21
|
-
--ui-slider-track-
|
|
22
|
-
--ui-slider-thumb-size: var(--
|
|
23
|
-
--ui-slider-thumb-
|
|
18
|
+
--ui-slider-track-h: calc(var(--spacing) * 1.5);
|
|
19
|
+
--ui-slider-track-bg: var(--color-muted);
|
|
20
|
+
--ui-slider-track-border: 1px solid var(--color-muted);
|
|
21
|
+
--ui-slider-track-rounded: var(--radius-full);
|
|
22
|
+
--ui-slider-thumb-size: calc(var(--spacing) * 4);
|
|
23
|
+
--ui-slider-thumb-bg: var(--color-background);
|
|
24
24
|
|
|
25
25
|
--ui-slider-thumb-shadow: var(--shadow-xs);
|
|
26
|
-
--ui-slider-thumb-border: 1px solid var(--border);
|
|
27
|
-
--ui-slider-thumb-
|
|
28
|
-
|
|
26
|
+
--ui-slider-thumb-border: 1px solid var(--color-border);
|
|
27
|
+
--ui-slider-thumb-rounded: var(--radius-full);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@layer reset {
|
|
32
|
+
:where(input[type="range"]) {
|
|
33
|
+
/* derived on the element so a subtree --ui-slider-track-h keeps the thumb centered */
|
|
34
|
+
--ui-slider-thumb-offset: calc(var(--ui-slider-track-h) * -1);
|
|
29
35
|
|
|
30
36
|
-webkit-appearance: none;
|
|
31
37
|
appearance: none;
|
|
32
38
|
inline-size: 100%;
|
|
33
39
|
background: transparent;
|
|
34
40
|
cursor: grab;
|
|
35
|
-
border-radius: var(--ui-slider-track-
|
|
41
|
+
border-radius: var(--ui-slider-track-rounded);
|
|
36
42
|
|
|
37
43
|
/* transparent outline keeps focus visible in forced-colors / high-contrast
|
|
38
44
|
modes; the visible focus ring lives on the thumb via --shadow-ring */
|
|
@@ -41,30 +47,31 @@
|
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
:where(input[type="range"])::-webkit-slider-runnable-track {
|
|
44
|
-
block-size: var(--ui-slider-track-
|
|
50
|
+
block-size: var(--ui-slider-track-h);
|
|
45
51
|
inline-size: 100%;
|
|
46
|
-
background: var(--ui-slider-track-
|
|
52
|
+
background: var(--ui-slider-track-bg);
|
|
47
53
|
border: var(--ui-slider-track-border);
|
|
48
|
-
border-radius: var(--ui-slider-track-
|
|
54
|
+
border-radius: var(--ui-slider-track-rounded);
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
:where(input[type="range"])::-moz-range-track {
|
|
52
|
-
block-size: var(--ui-slider-track-
|
|
58
|
+
block-size: var(--ui-slider-track-h);
|
|
53
59
|
inline-size: 100%;
|
|
54
|
-
background: var(--ui-slider-track-
|
|
60
|
+
background: var(--ui-slider-track-bg);
|
|
55
61
|
border: var(--ui-slider-track-border);
|
|
56
|
-
border-radius: var(--ui-slider-track-
|
|
62
|
+
border-radius: var(--ui-slider-track-rounded);
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
:where(input[type="range"])::-webkit-slider-thumb {
|
|
60
|
-
/* ring
|
|
61
|
-
|
|
66
|
+
/* the ring is a box-shadow so it composes with --ui-slider-thumb-shadow;
|
|
67
|
+
widths animate from 0 so it grows in on focus */
|
|
62
68
|
--_ring-offset-width: 0px;
|
|
63
69
|
--_ring-width: 0px;
|
|
64
|
-
--_ring: color-mix(in oklch, var(--ui-slider-ring-color) var(--ring-opacity), transparent);
|
|
70
|
+
--_ring-fill: color-mix(in oklch, var(--ui-slider-ring-color) var(--ring-opacity), transparent);
|
|
65
71
|
box-shadow:
|
|
66
|
-
0 0 0 var(--_ring-offset-width) var(--ring-offset-color),
|
|
67
|
-
0 0 0 calc(var(--_ring-offset-width) + var(--_ring-width))
|
|
72
|
+
0 0 0 var(--_ring-offset-width) var(--ring-offset-shadow-color),
|
|
73
|
+
0 0 0 calc(var(--_ring-offset-width) + var(--_ring-width))
|
|
74
|
+
var(--_ring-fill, var(--ring-shadow-color)),
|
|
68
75
|
var(--ui-slider-thumb-shadow);
|
|
69
76
|
|
|
70
77
|
-webkit-appearance: none;
|
|
@@ -72,37 +79,40 @@
|
|
|
72
79
|
margin-block-start: var(--ui-slider-thumb-offset);
|
|
73
80
|
inline-size: var(--ui-slider-thumb-size);
|
|
74
81
|
block-size: var(--ui-slider-thumb-size);
|
|
75
|
-
background-color: var(--ui-slider-thumb-
|
|
82
|
+
background-color: var(--ui-slider-thumb-bg);
|
|
76
83
|
border: var(--ui-slider-thumb-border);
|
|
77
|
-
border-radius: var(--ui-slider-thumb-
|
|
84
|
+
border-radius: var(--ui-slider-thumb-rounded);
|
|
78
85
|
|
|
79
86
|
transition: var(--default-transition);
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
:where(input[type="range"])::-moz-range-thumb {
|
|
83
|
-
/* ring
|
|
84
|
-
|
|
90
|
+
/* the ring is a box-shadow so it composes with --ui-slider-thumb-shadow;
|
|
91
|
+
widths animate from 0 so it grows in on focus */
|
|
85
92
|
--_ring-offset-width: 0px;
|
|
86
93
|
--_ring-width: 0px;
|
|
87
|
-
--_ring: color-mix(in oklch, var(--ui-slider-ring-color) var(--ring-opacity), transparent);
|
|
94
|
+
--_ring-fill: color-mix(in oklch, var(--ui-slider-ring-color) var(--ring-opacity), transparent);
|
|
88
95
|
|
|
89
96
|
appearance: none;
|
|
90
97
|
inline-size: var(--ui-slider-thumb-size);
|
|
91
98
|
block-size: var(--ui-slider-thumb-size);
|
|
92
|
-
background-color: var(--ui-slider-thumb-
|
|
99
|
+
background-color: var(--ui-slider-thumb-bg);
|
|
93
100
|
border: var(--ui-slider-thumb-border);
|
|
94
|
-
border-radius: var(--ui-slider-thumb-
|
|
101
|
+
border-radius: var(--ui-slider-thumb-rounded);
|
|
95
102
|
|
|
96
103
|
box-shadow:
|
|
97
|
-
0 0 0 var(--_ring-offset-width) var(--ring-offset-color),
|
|
98
|
-
0 0 0 calc(var(--_ring-offset-width) + var(--_ring-width))
|
|
104
|
+
0 0 0 var(--_ring-offset-width) var(--ring-offset-shadow-color),
|
|
105
|
+
0 0 0 calc(var(--_ring-offset-width) + var(--_ring-width))
|
|
106
|
+
var(--_ring-fill, var(--ring-shadow-color)),
|
|
99
107
|
var(--ui-slider-thumb-shadow);
|
|
100
108
|
|
|
101
109
|
transition: var(--default-transition);
|
|
102
110
|
}
|
|
103
111
|
|
|
104
|
-
|
|
105
|
-
|
|
112
|
+
@media (hover: hover) {
|
|
113
|
+
:where(input[type="range"]:hover) {
|
|
114
|
+
--ui-slider-thumb-border: 1px solid var(--color-primary);
|
|
115
|
+
}
|
|
106
116
|
}
|
|
107
117
|
|
|
108
118
|
:where(input[type="range"]:active) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type Styled = Element & ElementCSSInlineStyle;
|
|
2
|
+
/**
|
|
3
|
+
* @namespace StyleGuard
|
|
4
|
+
* @property {Function} start - Guards `root` (default `document.body`); idempotent for the same root, re-roots otherwise.
|
|
5
|
+
* @property {Function} stop - Disconnects the guard.
|
|
6
|
+
* @property {Function} restore - Re-applies `el`'s snapshot by hand.
|
|
7
|
+
*/
|
|
8
|
+
declare const StyleGuard: {
|
|
9
|
+
start(root?: Element): void;
|
|
10
|
+
stop(): void;
|
|
11
|
+
restore(el: Styled): void;
|
|
12
|
+
};
|
|
13
|
+
declare global {
|
|
14
|
+
interface Window {
|
|
15
|
+
StyleGuard: typeof StyleGuard;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export { StyleGuard };
|
|
19
|
+
//# sourceMappingURL=style-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style-guard.d.ts","sourceRoot":"","sources":["style-guard.ts"],"names":[],"mappings":"AAuBA,KAAK,MAAM,GAAG,OAAO,GAAG,qBAAqB,CAAC;AA6E9C;;;;;GAKG;AACH,QAAA,MAAM,UAAU;IACd,KAAK,QAAO,OAAO,GAAmB,IAAI;IAe1C,IAAI,IAAI,IAAI;IAKZ,OAAO,KAAK,MAAM,GAAG,IAAI;CAK1B,CAAC;AAWF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,EAAE,OAAO,UAAU,CAAC;KAC/B;CACF;AAKD,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const snapshots = new WeakMap();
|
|
3
|
+
function utilitiesOf(el) {
|
|
4
|
+
const utilities = new Map();
|
|
5
|
+
const style = el.style;
|
|
6
|
+
for (let i = 0; i < style.length; i++) {
|
|
7
|
+
const name = style.item(i);
|
|
8
|
+
if (name.startsWith("--")) {
|
|
9
|
+
utilities.set(name, [style.getPropertyValue(name), style.getPropertyPriority(name)]);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return utilities;
|
|
13
|
+
}
|
|
14
|
+
/** Parses the `--` declarations out of a raw `style` attribute value. */
|
|
15
|
+
function utilitiesIn(text) {
|
|
16
|
+
const utilities = new Map();
|
|
17
|
+
if (!text)
|
|
18
|
+
return utilities;
|
|
19
|
+
for (const declaration of text.split(";")) {
|
|
20
|
+
const colon = declaration.indexOf(":");
|
|
21
|
+
if (colon === -1)
|
|
22
|
+
continue;
|
|
23
|
+
const name = declaration.slice(0, colon).trim();
|
|
24
|
+
if (!name.startsWith("--"))
|
|
25
|
+
continue;
|
|
26
|
+
let value = declaration.slice(colon + 1).trim();
|
|
27
|
+
let priority = "";
|
|
28
|
+
if (/!\s*important$/i.test(value)) {
|
|
29
|
+
value = value.replace(/!\s*important$/i, "").trim();
|
|
30
|
+
priority = "important";
|
|
31
|
+
}
|
|
32
|
+
utilities.set(name, [value, priority]);
|
|
33
|
+
}
|
|
34
|
+
return utilities;
|
|
35
|
+
}
|
|
36
|
+
/** The non-utility declarations of a `style` text, normalized, for telling a rewrite from a removal. */
|
|
37
|
+
function rawOf(text) {
|
|
38
|
+
return (text ?? "")
|
|
39
|
+
.split(";")
|
|
40
|
+
.map((declaration) => declaration.trim())
|
|
41
|
+
.filter((declaration) => declaration && !declaration.startsWith("--"))
|
|
42
|
+
.sort()
|
|
43
|
+
.join(";");
|
|
44
|
+
}
|
|
45
|
+
function isGuarded(el) {
|
|
46
|
+
return el instanceof Element && "style" in el && el.getAttribute("data-ui-guard") !== "off";
|
|
47
|
+
}
|
|
48
|
+
let observer = null;
|
|
49
|
+
let guardedRoot = null;
|
|
50
|
+
/**
|
|
51
|
+
* Reconciles one element after a `style` write: a write that drops every utility at
|
|
52
|
+
* once is restored; anything else (a targeted removal, new utilities) becomes the new
|
|
53
|
+
* snapshot.
|
|
54
|
+
*/
|
|
55
|
+
function reconcile(el, previous, oldValue) {
|
|
56
|
+
const current = utilitiesOf(el);
|
|
57
|
+
const droppedAll = previous !== undefined && previous.size > 0 && current.size === 0;
|
|
58
|
+
// one utility removed on its own leaves every other declaration untouched: a choice, not a rewrite
|
|
59
|
+
const singleRemoval = droppedAll && previous.size === 1 && rawOf(oldValue) === rawOf(el.getAttribute("style"));
|
|
60
|
+
if (droppedAll && !singleRemoval) {
|
|
61
|
+
for (const [name, [value, priority]] of previous)
|
|
62
|
+
el.style.setProperty(name, value, priority);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
snapshots.set(el, current);
|
|
66
|
+
}
|
|
67
|
+
function onMutations(records) {
|
|
68
|
+
for (const record of records) {
|
|
69
|
+
const el = record.target;
|
|
70
|
+
if (!isGuarded(el))
|
|
71
|
+
continue;
|
|
72
|
+
reconcile(el, snapshots.get(el) ?? utilitiesIn(record.oldValue), record.oldValue);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @namespace StyleGuard
|
|
77
|
+
* @property {Function} start - Guards `root` (default `document.body`); idempotent for the same root, re-roots otherwise.
|
|
78
|
+
* @property {Function} stop - Disconnects the guard.
|
|
79
|
+
* @property {Function} restore - Re-applies `el`'s snapshot by hand.
|
|
80
|
+
*/
|
|
81
|
+
const StyleGuard = {
|
|
82
|
+
start(root = document.body) {
|
|
83
|
+
if (observer && guardedRoot === root)
|
|
84
|
+
return;
|
|
85
|
+
if (observer)
|
|
86
|
+
StyleGuard.stop();
|
|
87
|
+
guardedRoot = root;
|
|
88
|
+
for (const el of root.querySelectorAll('[style*="--"]')) {
|
|
89
|
+
if (isGuarded(el))
|
|
90
|
+
snapshots.set(el, utilitiesOf(el));
|
|
91
|
+
}
|
|
92
|
+
observer = new MutationObserver(onMutations);
|
|
93
|
+
observer.observe(root, {
|
|
94
|
+
attributes: true,
|
|
95
|
+
attributeFilter: ["style"],
|
|
96
|
+
attributeOldValue: true,
|
|
97
|
+
subtree: true,
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
stop() {
|
|
101
|
+
observer?.disconnect();
|
|
102
|
+
observer = null;
|
|
103
|
+
guardedRoot = null;
|
|
104
|
+
},
|
|
105
|
+
restore(el) {
|
|
106
|
+
const previous = snapshots.get(el);
|
|
107
|
+
if (!previous)
|
|
108
|
+
return;
|
|
109
|
+
for (const [name, [value, priority]] of previous)
|
|
110
|
+
el.style.setProperty(name, value, priority);
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
// Auto-initialize in the browser once the DOM is ready
|
|
114
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
115
|
+
if (document.readyState === "loading") {
|
|
116
|
+
document.addEventListener("DOMContentLoaded", () => StyleGuard.start());
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
StyleGuard.start();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (typeof window !== "undefined") {
|
|
123
|
+
window.StyleGuard = StyleGuard;
|
|
124
|
+
}
|
|
125
|
+
export { StyleGuard };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Style guard: keeps utilities alive when scripts rewrite the whole `style` attribute.
|
|
5
|
+
* @description Optional, production. A `MutationObserver` on `style` snapshots each
|
|
6
|
+
* element's `--` declarations on first sight and re-applies them only when one
|
|
7
|
+
* write drops every one of them at once — the `el.style.cssText = …` and
|
|
8
|
+
* jQuery `.attr('style', …)` signature. A single `removeProperty('--p')` is a
|
|
9
|
+
* choice and stays removed (with a single utility, "all" and "one" coincide: the guard
|
|
10
|
+
* tells them apart by whether the other declarations survived the write).
|
|
11
|
+
* `data-ui-guard="off"` opts an element out. A template
|
|
12
|
+
* that emits two `style` attributes cannot be repaired (the parser keeps the
|
|
13
|
+
* first); that is an authoring error.
|
|
14
|
+
* @example
|
|
15
|
+
* <script type="module" src="/zazz/primitives/style-guard/style-guard.js"></script>
|
|
16
|
+
* <!-- guards document.body once the DOM is ready -->
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** name → [value, priority] for every `--` declaration on the element. */
|
|
20
|
+
type Utilities = Map<string, [string, string]>;
|
|
21
|
+
|
|
22
|
+
const snapshots = new WeakMap<Element, Utilities>();
|
|
23
|
+
|
|
24
|
+
type Styled = Element & ElementCSSInlineStyle;
|
|
25
|
+
|
|
26
|
+
function utilitiesOf(el: Styled): Utilities {
|
|
27
|
+
const utilities: Utilities = new Map();
|
|
28
|
+
const style = el.style;
|
|
29
|
+
for (let i = 0; i < style.length; i++) {
|
|
30
|
+
const name = style.item(i);
|
|
31
|
+
if (name.startsWith("--")) {
|
|
32
|
+
utilities.set(name, [style.getPropertyValue(name), style.getPropertyPriority(name)]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return utilities;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Parses the `--` declarations out of a raw `style` attribute value. */
|
|
39
|
+
function utilitiesIn(text: string | null): Utilities {
|
|
40
|
+
const utilities: Utilities = new Map();
|
|
41
|
+
if (!text) return utilities;
|
|
42
|
+
for (const declaration of text.split(";")) {
|
|
43
|
+
const colon = declaration.indexOf(":");
|
|
44
|
+
if (colon === -1) continue;
|
|
45
|
+
const name = declaration.slice(0, colon).trim();
|
|
46
|
+
if (!name.startsWith("--")) continue;
|
|
47
|
+
let value = declaration.slice(colon + 1).trim();
|
|
48
|
+
let priority = "";
|
|
49
|
+
if (/!\s*important$/i.test(value)) {
|
|
50
|
+
value = value.replace(/!\s*important$/i, "").trim();
|
|
51
|
+
priority = "important";
|
|
52
|
+
}
|
|
53
|
+
utilities.set(name, [value, priority]);
|
|
54
|
+
}
|
|
55
|
+
return utilities;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The non-utility declarations of a `style` text, normalized, for telling a rewrite from a removal. */
|
|
59
|
+
function rawOf(text: string | null): string {
|
|
60
|
+
return (text ?? "")
|
|
61
|
+
.split(";")
|
|
62
|
+
.map((declaration) => declaration.trim())
|
|
63
|
+
.filter((declaration) => declaration && !declaration.startsWith("--"))
|
|
64
|
+
.sort()
|
|
65
|
+
.join(";");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function isGuarded(el: Node): el is Styled {
|
|
69
|
+
return el instanceof Element && "style" in el && el.getAttribute("data-ui-guard") !== "off";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let observer: MutationObserver | null = null;
|
|
73
|
+
let guardedRoot: Element | null = null;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Reconciles one element after a `style` write: a write that drops every utility at
|
|
77
|
+
* once is restored; anything else (a targeted removal, new utilities) becomes the new
|
|
78
|
+
* snapshot.
|
|
79
|
+
*/
|
|
80
|
+
function reconcile(el: Styled, previous: Utilities | undefined, oldValue: string | null): void {
|
|
81
|
+
const current = utilitiesOf(el);
|
|
82
|
+
const droppedAll = previous !== undefined && previous.size > 0 && current.size === 0;
|
|
83
|
+
// one utility removed on its own leaves every other declaration untouched: a choice, not a rewrite
|
|
84
|
+
const singleRemoval =
|
|
85
|
+
droppedAll && previous.size === 1 && rawOf(oldValue) === rawOf(el.getAttribute("style"));
|
|
86
|
+
if (droppedAll && !singleRemoval) {
|
|
87
|
+
for (const [name, [value, priority]] of previous) el.style.setProperty(name, value, priority);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
snapshots.set(el, current);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function onMutations(records: MutationRecord[]): void {
|
|
94
|
+
for (const record of records) {
|
|
95
|
+
const el = record.target;
|
|
96
|
+
if (!isGuarded(el)) continue;
|
|
97
|
+
reconcile(el, snapshots.get(el) ?? utilitiesIn(record.oldValue), record.oldValue);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @namespace StyleGuard
|
|
103
|
+
* @property {Function} start - Guards `root` (default `document.body`); idempotent for the same root, re-roots otherwise.
|
|
104
|
+
* @property {Function} stop - Disconnects the guard.
|
|
105
|
+
* @property {Function} restore - Re-applies `el`'s snapshot by hand.
|
|
106
|
+
*/
|
|
107
|
+
const StyleGuard = {
|
|
108
|
+
start(root: Element = document.body): void {
|
|
109
|
+
if (observer && guardedRoot === root) return;
|
|
110
|
+
if (observer) StyleGuard.stop();
|
|
111
|
+
guardedRoot = root;
|
|
112
|
+
for (const el of root.querySelectorAll('[style*="--"]')) {
|
|
113
|
+
if (isGuarded(el)) snapshots.set(el, utilitiesOf(el));
|
|
114
|
+
}
|
|
115
|
+
observer = new MutationObserver(onMutations);
|
|
116
|
+
observer.observe(root, {
|
|
117
|
+
attributes: true,
|
|
118
|
+
attributeFilter: ["style"],
|
|
119
|
+
attributeOldValue: true,
|
|
120
|
+
subtree: true,
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
stop(): void {
|
|
124
|
+
observer?.disconnect();
|
|
125
|
+
observer = null;
|
|
126
|
+
guardedRoot = null;
|
|
127
|
+
},
|
|
128
|
+
restore(el: Styled): void {
|
|
129
|
+
const previous = snapshots.get(el);
|
|
130
|
+
if (!previous) return;
|
|
131
|
+
for (const [name, [value, priority]] of previous) el.style.setProperty(name, value, priority);
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// Auto-initialize in the browser once the DOM is ready
|
|
136
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
137
|
+
if (document.readyState === "loading") {
|
|
138
|
+
document.addEventListener("DOMContentLoaded", () => StyleGuard.start());
|
|
139
|
+
} else {
|
|
140
|
+
StyleGuard.start();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
declare global {
|
|
145
|
+
interface Window {
|
|
146
|
+
StyleGuard: typeof StyleGuard;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (typeof window !== "undefined") {
|
|
150
|
+
window.StyleGuard = StyleGuard;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { StyleGuard };
|