@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
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Scroll-state polyfill for the `stuck` utility state.
|
|
4
|
+
* @description Where container scroll-state queries are unsupported (Safari and
|
|
5
|
+
* Firefox today), reproduces `scroll-state(stuck: <side>)` for the containers
|
|
6
|
+
* `_utilities-tier-stuck.css` reads: every sticky element (a `style` holding
|
|
7
|
+
* `: sticky`) or `--stuck-state` element that holds a `--<utility>--stuck`
|
|
8
|
+
* reader. It writes the sides each one is stuck to, physical and logical, to the
|
|
9
|
+
* container's `data-ui-stuck`, which the same CSS gates read, so markup does not
|
|
10
|
+
* change: `--position: sticky; --top: 0; --stuck-state: top` around a
|
|
11
|
+
* `--bg--stuck: …` descendant.
|
|
12
|
+
*
|
|
13
|
+
* Geometry, not sentinels (an extra element would take a grid cell or a flex
|
|
14
|
+
* gap): on scroll and resize, once per frame, a container is stuck to a side
|
|
15
|
+
* when it sits at that side's sticky offset in its scroll root and the root has
|
|
16
|
+
* scrolled away from that side's start, so an element merely resting at its
|
|
17
|
+
* offset (a header at the top of an unscrolled page) is not stuck. It reads as
|
|
18
|
+
* unstuck once its containing block starts pushing it out, slightly before the
|
|
19
|
+
* native query does.
|
|
20
|
+
*
|
|
21
|
+
* `index.ts` imports this module only where `scroll-state` is unsupported, so
|
|
22
|
+
* Chromium never loads it; `start()` also refuses to run there.
|
|
23
|
+
*/
|
|
24
|
+
import { registerRefresh } from "./zazz-element.js";
|
|
25
|
+
/** The attribute `STUCK_STATE.polyfill` names in `base/utilities.ts`. */
|
|
26
|
+
const ATTRIBUTE = "data-ui-stuck";
|
|
27
|
+
/** `STUCK_STATE`'s containers, holding a reader. */
|
|
28
|
+
const CONTAINERS = '[style*=": sticky"], [style*="--stuck-state:"]';
|
|
29
|
+
const READER = '[style*="--stuck:"]';
|
|
30
|
+
const OPPOSITE = { top: "bottom", right: "left", bottom: "top", left: "right" };
|
|
31
|
+
let tracked = [];
|
|
32
|
+
let controller;
|
|
33
|
+
let frame = 0;
|
|
34
|
+
/** @description The nearest scrolling ancestor, or null for the viewport. @private */
|
|
35
|
+
function scrollRoot(el) {
|
|
36
|
+
for (let node = el.parentElement; node && node !== document.body; node = node.parentElement) {
|
|
37
|
+
const { overflowX, overflowY } = getComputedStyle(node);
|
|
38
|
+
if (/auto|scroll|hidden/.test(overflowX + overflowY))
|
|
39
|
+
return node;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @description The logical sides a physical side also answers to, for the
|
|
45
|
+
* container's own writing mode and direction (`block-start` is `top` in horizontal-tb).
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
function logicalNames(side, { writingMode, direction }) {
|
|
49
|
+
const vertical = !writingMode.startsWith("horizontal");
|
|
50
|
+
const blockStart = vertical ? (writingMode.endsWith("lr") ? "left" : "right") : "top";
|
|
51
|
+
const inlineStart = vertical
|
|
52
|
+
? direction === "rtl"
|
|
53
|
+
? "bottom"
|
|
54
|
+
: "top"
|
|
55
|
+
: direction === "rtl"
|
|
56
|
+
? "right"
|
|
57
|
+
: "left";
|
|
58
|
+
const names = [];
|
|
59
|
+
if (side === blockStart)
|
|
60
|
+
names.push("block-start");
|
|
61
|
+
if (side === OPPOSITE[blockStart])
|
|
62
|
+
names.push("block-end");
|
|
63
|
+
if (side === inlineStart)
|
|
64
|
+
names.push("inline-start");
|
|
65
|
+
if (side === OPPOSITE[inlineStart])
|
|
66
|
+
names.push("inline-end");
|
|
67
|
+
return names;
|
|
68
|
+
}
|
|
69
|
+
/** @description The sides `el` is stuck to right now. @private */
|
|
70
|
+
function stuckSides(el, style) {
|
|
71
|
+
if (style.position !== "sticky")
|
|
72
|
+
return [];
|
|
73
|
+
const root = scrollRoot(el);
|
|
74
|
+
const scroller = root ?? document.scrollingElement ?? document.documentElement;
|
|
75
|
+
// the root's scrollport, in viewport coordinates
|
|
76
|
+
const port = root
|
|
77
|
+
? (() => {
|
|
78
|
+
const r = root.getBoundingClientRect();
|
|
79
|
+
const top = r.top + root.clientTop;
|
|
80
|
+
const left = r.left + root.clientLeft;
|
|
81
|
+
return { top, left, bottom: top + root.clientHeight, right: left + root.clientWidth };
|
|
82
|
+
})()
|
|
83
|
+
: { top: 0, left: 0, bottom: innerHeight, right: innerWidth };
|
|
84
|
+
const rect = el.getBoundingClientRect();
|
|
85
|
+
const maxTop = scroller.scrollHeight - scroller.clientHeight;
|
|
86
|
+
const maxLeft = scroller.scrollWidth - scroller.clientWidth;
|
|
87
|
+
// scrollLeft runs 0 → -max in rtl
|
|
88
|
+
const rtl = getComputedStyle(scroller).direction === "rtl";
|
|
89
|
+
const x = scroller.scrollLeft;
|
|
90
|
+
const scrolledFrom = {
|
|
91
|
+
top: scroller.scrollTop > 0,
|
|
92
|
+
bottom: scroller.scrollTop < maxTop - 0.5,
|
|
93
|
+
left: rtl ? x > -maxLeft + 0.5 : x > 0,
|
|
94
|
+
right: rtl ? x < 0 : x < maxLeft - 0.5,
|
|
95
|
+
};
|
|
96
|
+
const at = {
|
|
97
|
+
top: rect.top - port.top,
|
|
98
|
+
bottom: port.bottom - rect.bottom,
|
|
99
|
+
left: rect.left - port.left,
|
|
100
|
+
right: port.right - rect.right,
|
|
101
|
+
};
|
|
102
|
+
return Object.keys(at).filter((side) => {
|
|
103
|
+
const offset = style[side];
|
|
104
|
+
return (offset !== "auto" && scrolledFrom[side] && Math.abs(at[side] - Number.parseFloat(offset)) < 1);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/** @description Writes each container's stuck sides to its `data-ui-stuck`. @private */
|
|
108
|
+
function write() {
|
|
109
|
+
frame = 0;
|
|
110
|
+
for (const el of tracked) {
|
|
111
|
+
const style = getComputedStyle(el);
|
|
112
|
+
const value = stuckSides(el, style)
|
|
113
|
+
.flatMap((side) => [side, ...logicalNames(side, style)])
|
|
114
|
+
.join(" ");
|
|
115
|
+
if (value) {
|
|
116
|
+
if (el.getAttribute(ATTRIBUTE) !== value)
|
|
117
|
+
el.setAttribute(ATTRIBUTE, value);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
el.removeAttribute(ATTRIBUTE);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function schedule() {
|
|
125
|
+
frame ||= requestAnimationFrame(write);
|
|
126
|
+
}
|
|
127
|
+
/** @description (Re)collects the containers holding a reader, e.g. after a navigation swap. @private */
|
|
128
|
+
function scan() {
|
|
129
|
+
if (!controller)
|
|
130
|
+
return;
|
|
131
|
+
for (const el of tracked)
|
|
132
|
+
if (!el.isConnected)
|
|
133
|
+
el.removeAttribute(ATTRIBUTE);
|
|
134
|
+
tracked = [...document.querySelectorAll(CONTAINERS)].filter((el) => el.querySelector(READER));
|
|
135
|
+
schedule();
|
|
136
|
+
}
|
|
137
|
+
// --- Public API ---
|
|
138
|
+
/** True where the browser evaluates container scroll-state queries itself. */
|
|
139
|
+
function isSupported() {
|
|
140
|
+
return typeof CSS !== "undefined" && CSS.supports("container-type", "scroll-state");
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* @description Starts the polyfill; idempotent, and a no-op where `scroll-state`
|
|
144
|
+
* is supported unless `force` is set (tests).
|
|
145
|
+
*/
|
|
146
|
+
function start({ force = false } = {}) {
|
|
147
|
+
if (controller || (!force && isSupported()))
|
|
148
|
+
return;
|
|
149
|
+
controller = new AbortController();
|
|
150
|
+
const options = { passive: true, capture: true, signal: controller.signal };
|
|
151
|
+
// capture: scroll does not bubble, and nested scrollers count too
|
|
152
|
+
document.addEventListener("scroll", schedule, options);
|
|
153
|
+
window.addEventListener("resize", schedule, options);
|
|
154
|
+
scan();
|
|
155
|
+
}
|
|
156
|
+
/** @description Stops the polyfill and clears every `data-ui-stuck` it wrote. */
|
|
157
|
+
function stop() {
|
|
158
|
+
controller?.abort();
|
|
159
|
+
controller = undefined;
|
|
160
|
+
cancelAnimationFrame(frame);
|
|
161
|
+
frame = 0;
|
|
162
|
+
for (const el of tracked)
|
|
163
|
+
el.removeAttribute(ATTRIBUTE);
|
|
164
|
+
tracked = [];
|
|
165
|
+
}
|
|
166
|
+
const ScrollState = { start, stop, isSupported, refresh: scan };
|
|
167
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
168
|
+
if (document.readyState === "loading") {
|
|
169
|
+
document.addEventListener("DOMContentLoaded", () => start(), { once: true });
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
start();
|
|
173
|
+
}
|
|
174
|
+
// a navigation swap brings new containers
|
|
175
|
+
registerRefresh(scan);
|
|
176
|
+
}
|
|
177
|
+
export { ScrollState };
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Scroll-state polyfill for the `stuck` utility state.
|
|
5
|
+
* @description Where container scroll-state queries are unsupported (Safari and
|
|
6
|
+
* Firefox today), reproduces `scroll-state(stuck: <side>)` for the containers
|
|
7
|
+
* `_utilities-tier-stuck.css` reads: every sticky element (a `style` holding
|
|
8
|
+
* `: sticky`) or `--stuck-state` element that holds a `--<utility>--stuck`
|
|
9
|
+
* reader. It writes the sides each one is stuck to, physical and logical, to the
|
|
10
|
+
* container's `data-ui-stuck`, which the same CSS gates read, so markup does not
|
|
11
|
+
* change: `--position: sticky; --top: 0; --stuck-state: top` around a
|
|
12
|
+
* `--bg--stuck: …` descendant.
|
|
13
|
+
*
|
|
14
|
+
* Geometry, not sentinels (an extra element would take a grid cell or a flex
|
|
15
|
+
* gap): on scroll and resize, once per frame, a container is stuck to a side
|
|
16
|
+
* when it sits at that side's sticky offset in its scroll root and the root has
|
|
17
|
+
* scrolled away from that side's start, so an element merely resting at its
|
|
18
|
+
* offset (a header at the top of an unscrolled page) is not stuck. It reads as
|
|
19
|
+
* unstuck once its containing block starts pushing it out, slightly before the
|
|
20
|
+
* native query does.
|
|
21
|
+
*
|
|
22
|
+
* `index.ts` imports this module only where `scroll-state` is unsupported, so
|
|
23
|
+
* Chromium never loads it; `start()` also refuses to run there.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { registerRefresh } from "./zazz-element.ts";
|
|
27
|
+
|
|
28
|
+
// --- Containers ---
|
|
29
|
+
|
|
30
|
+
type Side = "top" | "right" | "bottom" | "left";
|
|
31
|
+
|
|
32
|
+
/** The attribute `STUCK_STATE.polyfill` names in `base/utilities.ts`. */
|
|
33
|
+
const ATTRIBUTE = "data-ui-stuck";
|
|
34
|
+
/** `STUCK_STATE`'s containers, holding a reader. */
|
|
35
|
+
const CONTAINERS = '[style*=": sticky"], [style*="--stuck-state:"]';
|
|
36
|
+
const READER = '[style*="--stuck:"]';
|
|
37
|
+
const OPPOSITE: Record<Side, Side> = { top: "bottom", right: "left", bottom: "top", left: "right" };
|
|
38
|
+
|
|
39
|
+
let tracked: HTMLElement[] = [];
|
|
40
|
+
let controller: AbortController | undefined;
|
|
41
|
+
let frame = 0;
|
|
42
|
+
|
|
43
|
+
/** @description The nearest scrolling ancestor, or null for the viewport. @private */
|
|
44
|
+
function scrollRoot(el: Element): Element | null {
|
|
45
|
+
for (let node = el.parentElement; node && node !== document.body; node = node.parentElement) {
|
|
46
|
+
const { overflowX, overflowY } = getComputedStyle(node);
|
|
47
|
+
if (/auto|scroll|hidden/.test(overflowX + overflowY)) return node;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @description The logical sides a physical side also answers to, for the
|
|
54
|
+
* container's own writing mode and direction (`block-start` is `top` in horizontal-tb).
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
function logicalNames(side: Side, { writingMode, direction }: CSSStyleDeclaration): string[] {
|
|
58
|
+
const vertical = !writingMode.startsWith("horizontal");
|
|
59
|
+
const blockStart: Side = vertical ? (writingMode.endsWith("lr") ? "left" : "right") : "top";
|
|
60
|
+
const inlineStart: Side = vertical
|
|
61
|
+
? direction === "rtl"
|
|
62
|
+
? "bottom"
|
|
63
|
+
: "top"
|
|
64
|
+
: direction === "rtl"
|
|
65
|
+
? "right"
|
|
66
|
+
: "left";
|
|
67
|
+
const names: string[] = [];
|
|
68
|
+
if (side === blockStart) names.push("block-start");
|
|
69
|
+
if (side === OPPOSITE[blockStart]) names.push("block-end");
|
|
70
|
+
if (side === inlineStart) names.push("inline-start");
|
|
71
|
+
if (side === OPPOSITE[inlineStart]) names.push("inline-end");
|
|
72
|
+
return names;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** @description The sides `el` is stuck to right now. @private */
|
|
76
|
+
function stuckSides(el: HTMLElement, style: CSSStyleDeclaration): Side[] {
|
|
77
|
+
if (style.position !== "sticky") return [];
|
|
78
|
+
const root = scrollRoot(el);
|
|
79
|
+
const scroller = root ?? document.scrollingElement ?? document.documentElement;
|
|
80
|
+
// the root's scrollport, in viewport coordinates
|
|
81
|
+
const port = root
|
|
82
|
+
? (() => {
|
|
83
|
+
const r = root.getBoundingClientRect();
|
|
84
|
+
const top = r.top + root.clientTop;
|
|
85
|
+
const left = r.left + root.clientLeft;
|
|
86
|
+
return { top, left, bottom: top + root.clientHeight, right: left + root.clientWidth };
|
|
87
|
+
})()
|
|
88
|
+
: { top: 0, left: 0, bottom: innerHeight, right: innerWidth };
|
|
89
|
+
const rect = el.getBoundingClientRect();
|
|
90
|
+
const maxTop = scroller.scrollHeight - scroller.clientHeight;
|
|
91
|
+
const maxLeft = scroller.scrollWidth - scroller.clientWidth;
|
|
92
|
+
// scrollLeft runs 0 → -max in rtl
|
|
93
|
+
const rtl = getComputedStyle(scroller).direction === "rtl";
|
|
94
|
+
const x = scroller.scrollLeft;
|
|
95
|
+
const scrolledFrom: Record<Side, boolean> = {
|
|
96
|
+
top: scroller.scrollTop > 0,
|
|
97
|
+
bottom: scroller.scrollTop < maxTop - 0.5,
|
|
98
|
+
left: rtl ? x > -maxLeft + 0.5 : x > 0,
|
|
99
|
+
right: rtl ? x < 0 : x < maxLeft - 0.5,
|
|
100
|
+
};
|
|
101
|
+
const at: Record<Side, number> = {
|
|
102
|
+
top: rect.top - port.top,
|
|
103
|
+
bottom: port.bottom - rect.bottom,
|
|
104
|
+
left: rect.left - port.left,
|
|
105
|
+
right: port.right - rect.right,
|
|
106
|
+
};
|
|
107
|
+
return (Object.keys(at) as Side[]).filter((side) => {
|
|
108
|
+
const offset = style[side];
|
|
109
|
+
return (
|
|
110
|
+
offset !== "auto" && scrolledFrom[side] && Math.abs(at[side] - Number.parseFloat(offset)) < 1
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** @description Writes each container's stuck sides to its `data-ui-stuck`. @private */
|
|
116
|
+
function write(): void {
|
|
117
|
+
frame = 0;
|
|
118
|
+
for (const el of tracked) {
|
|
119
|
+
const style = getComputedStyle(el);
|
|
120
|
+
const value = stuckSides(el, style)
|
|
121
|
+
.flatMap((side) => [side, ...logicalNames(side, style)])
|
|
122
|
+
.join(" ");
|
|
123
|
+
if (value) {
|
|
124
|
+
if (el.getAttribute(ATTRIBUTE) !== value) el.setAttribute(ATTRIBUTE, value);
|
|
125
|
+
} else {
|
|
126
|
+
el.removeAttribute(ATTRIBUTE);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function schedule(): void {
|
|
132
|
+
frame ||= requestAnimationFrame(write);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** @description (Re)collects the containers holding a reader, e.g. after a navigation swap. @private */
|
|
136
|
+
function scan(): void {
|
|
137
|
+
if (!controller) return;
|
|
138
|
+
for (const el of tracked) if (!el.isConnected) el.removeAttribute(ATTRIBUTE);
|
|
139
|
+
tracked = [...document.querySelectorAll<HTMLElement>(CONTAINERS)].filter((el) =>
|
|
140
|
+
el.querySelector(READER),
|
|
141
|
+
);
|
|
142
|
+
schedule();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// --- Public API ---
|
|
146
|
+
|
|
147
|
+
/** True where the browser evaluates container scroll-state queries itself. */
|
|
148
|
+
function isSupported(): boolean {
|
|
149
|
+
return typeof CSS !== "undefined" && CSS.supports("container-type", "scroll-state");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @description Starts the polyfill; idempotent, and a no-op where `scroll-state`
|
|
154
|
+
* is supported unless `force` is set (tests).
|
|
155
|
+
*/
|
|
156
|
+
function start({ force = false }: { force?: boolean } = {}): void {
|
|
157
|
+
if (controller || (!force && isSupported())) return;
|
|
158
|
+
controller = new AbortController();
|
|
159
|
+
const options = { passive: true, capture: true, signal: controller.signal };
|
|
160
|
+
// capture: scroll does not bubble, and nested scrollers count too
|
|
161
|
+
document.addEventListener("scroll", schedule, options);
|
|
162
|
+
window.addEventListener("resize", schedule, options);
|
|
163
|
+
scan();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** @description Stops the polyfill and clears every `data-ui-stuck` it wrote. */
|
|
167
|
+
function stop(): void {
|
|
168
|
+
controller?.abort();
|
|
169
|
+
controller = undefined;
|
|
170
|
+
cancelAnimationFrame(frame);
|
|
171
|
+
frame = 0;
|
|
172
|
+
for (const el of tracked) el.removeAttribute(ATTRIBUTE);
|
|
173
|
+
tracked = [];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const ScrollState = { start, stop, isSupported, refresh: scan };
|
|
177
|
+
|
|
178
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
179
|
+
if (document.readyState === "loading") {
|
|
180
|
+
document.addEventListener("DOMContentLoaded", () => start(), { once: true });
|
|
181
|
+
} else {
|
|
182
|
+
start();
|
|
183
|
+
}
|
|
184
|
+
// a navigation swap brings new containers
|
|
185
|
+
registerRefresh(scan);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export { ScrollState };
|
package/src/base/signals.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview TC39 Signals wrapper: the kit reactive-state seam.
|
|
3
|
-
* @description
|
|
3
|
+
* @description Reactive component state via the TC39 Signals proposal. This
|
|
4
4
|
* module is the only file in the kit allowed to import `signal-polyfill`;
|
|
5
5
|
* component scripts import `state`, `computed`, and `effect` from here, so when
|
|
6
6
|
* the proposal's API shifts or engines ship native signals, one file changes.
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
* The bare `signal-polyfill` specifier resolves through the page's import map in
|
|
16
16
|
* browsers (pinned jsDelivr URL) and through `node_modules` in tests/bundlers.
|
|
17
17
|
*
|
|
18
|
-
* @see https://github.com/tc39/proposal-signals
|
|
19
18
|
* @see https://github.com/proposal-signals/signal-polyfill
|
|
20
19
|
*/
|
|
21
20
|
import { Signal } from "signal-polyfill";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["signals.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["signals.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAUzC;;;;;;;;;;GAUG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAE/E;AAED;;;;;;;;;GASG;AACH,iBAAS,QAAQ,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAE1F;AAID,4BAA4B;AAC5B,UAAU,aAAa;IACrB,yEAAyE;IACzE,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,uEAAuE;AACvE,KAAK,cAAc,GAAG,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;AAEhD,sFAAsF;AACtF,KAAK,aAAa,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,UAAU,CAAC;AA2B/C;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAS,MAAM,CAAC,QAAQ,EAAE,cAAc,EAAE,OAAO,GAAE,aAAkB,GAAG,aAAa,CAsBpF;AAID;;;;;;;;;GASG;AACH,QAAA,MAAM,OAAO;;;;CAA8B,CAAC;AAO5C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC5C,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC"}
|
package/src/base/signals.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* @fileoverview TC39 Signals wrapper: the kit reactive-state seam.
|
|
4
|
-
* @description
|
|
4
|
+
* @description Reactive component state via the TC39 Signals proposal. This
|
|
5
5
|
* module is the only file in the kit allowed to import `signal-polyfill`;
|
|
6
6
|
* component scripts import `state`, `computed`, and `effect` from here, so when
|
|
7
7
|
* the proposal's API shifts or engines ship native signals, one file changes.
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
* The bare `signal-polyfill` specifier resolves through the page's import map in
|
|
17
17
|
* browsers (pinned jsDelivr URL) and through `node_modules` in tests/bundlers.
|
|
18
18
|
*
|
|
19
|
-
* @see https://github.com/tc39/proposal-signals
|
|
20
19
|
* @see https://github.com/proposal-signals/signal-polyfill
|
|
21
20
|
*/
|
|
22
21
|
import { Signal } from "signal-polyfill";
|
|
@@ -53,10 +52,9 @@ function state(initialValue, options) {
|
|
|
53
52
|
function computed(computation, options) {
|
|
54
53
|
return new Signal.Computed(computation, options);
|
|
55
54
|
}
|
|
56
|
-
// The proposal
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
// microtask so N writes in one task trigger one re-run.
|
|
55
|
+
// The proposal ships no effect(). One shared Watcher notifies synchronously on
|
|
56
|
+
// the first dirty signal; re-runs are batched to a microtask so N writes in one
|
|
57
|
+
// task trigger one re-run.
|
|
60
58
|
let needsEnqueue = true;
|
|
61
59
|
const watcher = new Signal.subtle.Watcher(() => {
|
|
62
60
|
if (needsEnqueue) {
|
package/src/base/signals.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @fileoverview TC39 Signals wrapper: the kit reactive-state seam.
|
|
5
|
-
* @description
|
|
5
|
+
* @description Reactive component state via the TC39 Signals proposal. This
|
|
6
6
|
* module is the only file in the kit allowed to import `signal-polyfill`;
|
|
7
7
|
* component scripts import `state`, `computed`, and `effect` from here, so when
|
|
8
8
|
* the proposal's API shifts or engines ship native signals, one file changes.
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
* The bare `signal-polyfill` specifier resolves through the page's import map in
|
|
18
18
|
* browsers (pinned jsDelivr URL) and through `node_modules` in tests/bundlers.
|
|
19
19
|
*
|
|
20
|
-
* @see https://github.com/tc39/proposal-signals
|
|
21
20
|
* @see https://github.com/proposal-signals/signal-polyfill
|
|
22
21
|
*/
|
|
23
22
|
|
|
@@ -74,10 +73,9 @@ type EffectCallback = () => void | (() => void);
|
|
|
74
73
|
/** The disposer `effect` returns: callable, and a `using`-compatible `Disposable`. */
|
|
75
74
|
type EffectDispose = (() => void) & Disposable;
|
|
76
75
|
|
|
77
|
-
// The proposal
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
// microtask so N writes in one task trigger one re-run.
|
|
76
|
+
// The proposal ships no effect(). One shared Watcher notifies synchronously on
|
|
77
|
+
// the first dirty signal; re-runs are batched to a microtask so N writes in one
|
|
78
|
+
// task trigger one re-run.
|
|
81
79
|
let needsEnqueue = true;
|
|
82
80
|
|
|
83
81
|
const watcher = new Signal.subtle.Watcher(() => {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** `[start, end)` offsets into a style value. */
|
|
2
|
+
export type Range = [number, number];
|
|
3
|
+
/** One declaration of a style value, with its parts' offsets (all trimmed). */
|
|
4
|
+
export interface ScannedDeclaration {
|
|
5
|
+
/** The whole declaration. */
|
|
6
|
+
span: Range;
|
|
7
|
+
/** The name; a declaration still being typed (`--p`) is all name. */
|
|
8
|
+
name: string;
|
|
9
|
+
nameSpan: Range;
|
|
10
|
+
/** Offset of the colon, or -1 when there is none yet. */
|
|
11
|
+
colon: number;
|
|
12
|
+
value: string;
|
|
13
|
+
/** Empty (`[colon + 1, colon + 1]`) when nothing follows the colon. */
|
|
14
|
+
valueSpan: Range;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Scans a style value into declarations, splitting on top-level `;` (not inside
|
|
18
|
+
* parentheses or quotes). Empty segments are skipped.
|
|
19
|
+
*/
|
|
20
|
+
export declare function scanDeclarations(value: string): ScannedDeclaration[];
|
|
21
|
+
/** Splits a style value on top-level `;`, ignoring ones inside parentheses or quotes. */
|
|
22
|
+
export declare function splitDeclarations(value: string): string[];
|
|
23
|
+
/** `--px :6` → `--px: 6`. A declaration without a colon is kept as written. */
|
|
24
|
+
export declare function normalize(declaration: string): string;
|
|
25
|
+
/** Declarations in cascade order (a stable sort). */
|
|
26
|
+
export declare function orderDeclarations(declarations: string[]): string[];
|
|
27
|
+
/**
|
|
28
|
+
* The formatted `style` value: normalized declarations in cascade order, one
|
|
29
|
+
* per line under `attrIndent` (the attribute's own indent) when there are two
|
|
30
|
+
* or more, a bare declaration when there is one.
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatStyleValue(value: string, attrIndent: string): string;
|
|
33
|
+
//# sourceMappingURL=style-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style-format.d.ts","sourceRoot":"","sources":["style-format.ts"],"names":[],"mappings":"AAgCA,iDAAiD;AACjD,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAErC,+EAA+E;AAC/E,MAAM,WAAW,kBAAkB;IACjC,6BAA6B;IAC7B,IAAI,EAAE,KAAK,CAAC;IACZ,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,KAAK,CAAC;IAChB,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,SAAS,EAAE,KAAK,CAAC;CAClB;AASD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAsCpE;AAED,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAEzD;AAsBD,+EAA+E;AAC/E,wBAAgB,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAIrD;AA8BD,qDAAqD;AACrD,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAGlE;AAID;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAM1E"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview How a `style=""` of utilities is written: normalized, in
|
|
4
|
+
* cascade order, one declaration per line.
|
|
5
|
+
* @description The `zazz/style-format` lint rule (`@zazz-ui/eslint-plugin`)
|
|
6
|
+
* writes `style` with it: fixed on save, by the commit hook, and by
|
|
7
|
+
* `vp run fmt:html`. Development tooling only; no runtime entry imports it.
|
|
8
|
+
*
|
|
9
|
+
* Order: utilities follow the `UTILITIES` table (family, then emission order,
|
|
10
|
+
* shorthands first), each led by its `--*--starting` tier (the value it
|
|
11
|
+
* transitions from reads before the value it lands on; CSS order does not
|
|
12
|
+
* matter, the generated setter sits in `@starting-style`) and followed by its
|
|
13
|
+
* tiers (breakpoints small to large, then states in `STATES` order) and its
|
|
14
|
+
* `--group-*` forms; then the
|
|
15
|
+
* `--before-*` forms, then `--after-*`; then other custom properties (`--ui-*`
|
|
16
|
+
* hooks) and raw CSS, each kept in source order. Custom properties do not
|
|
17
|
+
* depend on declaration order, and the sort is stable, so a repeated name
|
|
18
|
+
* keeps its winner and raw shorthands keep their place before longhands.
|
|
19
|
+
*/
|
|
20
|
+
import { BREAKPOINTS, PSEUDO_ONLY, PSEUDO_SIDES, STATES, UTILITIES, parseUtilityName, } from "./utilities.js";
|
|
21
|
+
/** Trims `[start, end)` of `text` to its non-whitespace extent. */
|
|
22
|
+
function trimRange(text, start, end) {
|
|
23
|
+
while (start < end && /\s/.test(text[start]))
|
|
24
|
+
start++;
|
|
25
|
+
while (end > start && /\s/.test(text[end - 1]))
|
|
26
|
+
end--;
|
|
27
|
+
return [start, end];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Scans a style value into declarations, splitting on top-level `;` (not inside
|
|
31
|
+
* parentheses or quotes). Empty segments are skipped.
|
|
32
|
+
*/
|
|
33
|
+
export function scanDeclarations(value) {
|
|
34
|
+
const found = [];
|
|
35
|
+
const push = (from, to) => {
|
|
36
|
+
const span = trimRange(value, from, to);
|
|
37
|
+
if (span[0] === span[1])
|
|
38
|
+
return;
|
|
39
|
+
const colon = value.indexOf(":", span[0]);
|
|
40
|
+
const hasColon = colon !== -1 && colon < span[1];
|
|
41
|
+
const nameSpan = hasColon ? trimRange(value, span[0], colon) : span;
|
|
42
|
+
const valueSpan = hasColon
|
|
43
|
+
? trimRange(value, colon + 1, span[1])
|
|
44
|
+
: [span[1], span[1]];
|
|
45
|
+
found.push({
|
|
46
|
+
span,
|
|
47
|
+
name: value.slice(...nameSpan),
|
|
48
|
+
nameSpan,
|
|
49
|
+
colon: hasColon ? colon : -1,
|
|
50
|
+
value: value.slice(...valueSpan),
|
|
51
|
+
valueSpan,
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
let depth = 0;
|
|
55
|
+
let quote = null;
|
|
56
|
+
let start = 0;
|
|
57
|
+
for (let i = 0; i < value.length; i++) {
|
|
58
|
+
const ch = value[i];
|
|
59
|
+
if (quote) {
|
|
60
|
+
if (ch === "\\")
|
|
61
|
+
i++;
|
|
62
|
+
else if (ch === quote)
|
|
63
|
+
quote = null;
|
|
64
|
+
}
|
|
65
|
+
else if (ch === '"' || ch === "'")
|
|
66
|
+
quote = ch;
|
|
67
|
+
else if (ch === "(")
|
|
68
|
+
depth++;
|
|
69
|
+
else if (ch === ")")
|
|
70
|
+
depth = Math.max(0, depth - 1);
|
|
71
|
+
else if (ch === ";" && depth === 0) {
|
|
72
|
+
push(start, i);
|
|
73
|
+
start = i + 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
push(start, value.length);
|
|
77
|
+
return found;
|
|
78
|
+
}
|
|
79
|
+
/** Splits a style value on top-level `;`, ignoring ones inside parentheses or quotes. */
|
|
80
|
+
export function splitDeclarations(value) {
|
|
81
|
+
return scanDeclarations(value).map(({ span }) => value.slice(...span));
|
|
82
|
+
}
|
|
83
|
+
/** Collapses whitespace runs to one space, outside quotes. */
|
|
84
|
+
function collapse(text) {
|
|
85
|
+
let out = "";
|
|
86
|
+
let quote = null;
|
|
87
|
+
for (let i = 0; i < text.length; i++) {
|
|
88
|
+
const ch = text[i];
|
|
89
|
+
if (quote) {
|
|
90
|
+
out += ch;
|
|
91
|
+
if (ch === "\\" && i + 1 < text.length)
|
|
92
|
+
out += text[++i];
|
|
93
|
+
else if (ch === quote)
|
|
94
|
+
quote = null;
|
|
95
|
+
}
|
|
96
|
+
else if (ch === '"' || ch === "'") {
|
|
97
|
+
quote = ch;
|
|
98
|
+
out += ch;
|
|
99
|
+
}
|
|
100
|
+
else if (/\s/.test(ch)) {
|
|
101
|
+
if (!out.endsWith(" "))
|
|
102
|
+
out += " ";
|
|
103
|
+
}
|
|
104
|
+
else
|
|
105
|
+
out += ch;
|
|
106
|
+
}
|
|
107
|
+
return out.trim();
|
|
108
|
+
}
|
|
109
|
+
/** `--px :6` → `--px: 6`. A declaration without a colon is kept as written. */
|
|
110
|
+
export function normalize(declaration) {
|
|
111
|
+
const colon = declaration.indexOf(":");
|
|
112
|
+
if (colon === -1)
|
|
113
|
+
return collapse(declaration);
|
|
114
|
+
return `${declaration.slice(0, colon).trim()}: ${collapse(declaration.slice(colon + 1))}`;
|
|
115
|
+
}
|
|
116
|
+
// --- Order ---
|
|
117
|
+
const UTILITY_RANK = new Map([...UTILITIES, ...PSEUDO_ONLY].map((utility, i) => [utility.name, i]));
|
|
118
|
+
// the starting tier leads its utility, ahead of the base (rank 0)
|
|
119
|
+
const TIER_RANK = new Map([...BREAKPOINTS, ...STATES].map((tier, i) => [tier, tier === "starting" ? -1 : i + 1]));
|
|
120
|
+
/** Sort key: utilities by side, table order, own-before-group, tier; everything else after. */
|
|
121
|
+
function rank(declaration) {
|
|
122
|
+
const colon = declaration.indexOf(":");
|
|
123
|
+
const name = colon === -1 ? "" : declaration.slice(0, colon).trim();
|
|
124
|
+
if (!name.startsWith("--"))
|
|
125
|
+
return [2];
|
|
126
|
+
const parsed = parseUtilityName(name);
|
|
127
|
+
const utility = UTILITY_RANK.get(parsed.name);
|
|
128
|
+
if (utility === undefined || name.startsWith("--ui-"))
|
|
129
|
+
return [1];
|
|
130
|
+
const side = parsed.side ? PSEUDO_SIDES.indexOf(parsed.side) + 1 : 0;
|
|
131
|
+
return [0, side, utility, parsed.group ? 1 : 0, parsed.tier ? TIER_RANK.get(parsed.tier) : 0];
|
|
132
|
+
}
|
|
133
|
+
function compare(a, b) {
|
|
134
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
135
|
+
const delta = (a[i] ?? -1) - (b[i] ?? -1);
|
|
136
|
+
if (delta)
|
|
137
|
+
return delta;
|
|
138
|
+
}
|
|
139
|
+
return 0;
|
|
140
|
+
}
|
|
141
|
+
/** Declarations in cascade order (a stable sort). */
|
|
142
|
+
export function orderDeclarations(declarations) {
|
|
143
|
+
const ranks = new Map(declarations.map((d) => [d, rank(d)]));
|
|
144
|
+
return [...declarations].sort((a, b) => compare(ranks.get(a), ranks.get(b)));
|
|
145
|
+
}
|
|
146
|
+
// --- Layout ---
|
|
147
|
+
/**
|
|
148
|
+
* The formatted `style` value: normalized declarations in cascade order, one
|
|
149
|
+
* per line under `attrIndent` (the attribute's own indent) when there are two
|
|
150
|
+
* or more, a bare declaration when there is one.
|
|
151
|
+
*/
|
|
152
|
+
export function formatStyleValue(value, attrIndent) {
|
|
153
|
+
const declarations = orderDeclarations(splitDeclarations(value).map(normalize));
|
|
154
|
+
if (declarations.length === 0)
|
|
155
|
+
return value;
|
|
156
|
+
if (declarations.length === 1)
|
|
157
|
+
return declarations[0];
|
|
158
|
+
const inner = `${attrIndent} `;
|
|
159
|
+
return `\n${declarations.map((d) => `${inner}${d};`).join("\n")}\n${attrIndent}`;
|
|
160
|
+
}
|