@zazz-ui/core 0.15.1 → 0.16.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 +29 -14
- package/CHANGELOG.md +156 -0
- package/README.md +6 -5
- package/dist/{csp-LRx1fynI.js → csp-C1f62vyT.js} +1 -1
- package/dist/sri.json +70 -65
- package/dist/zazz.css +1 -1
- package/dist/zazz.js +1 -1
- package/editor/zazz.css-data.json +74 -2
- package/editor/zazz.html-data.json +119 -79
- package/editor/zazz.language-data.json +401 -313
- package/editor/zazz.lint-data.json +1752 -1731
- package/package.json +2 -1
- package/src/base/_defaults.css +11 -11
- package/src/base/_reset.css +2 -10
- package/src/base/_typography.css +17 -568
- package/src/base/_utilities-box.css +17 -17
- package/src/base/_utilities-pseudo.css +2 -2
- package/src/base/_variables.css +142 -97
- package/src/base/carousel-scroll.d.ts +1 -1
- package/src/base/carousel-scroll.js +6 -6
- package/src/base/carousel-scroll.ts +6 -6
- package/src/base/carousel.d.ts.map +1 -1
- package/src/base/carousel.js +6 -2
- package/src/base/carousel.ts +6 -2
- package/src/base/csp.js +2 -2
- package/src/base/csp.ts +2 -2
- package/src/base/kit-styling.d.ts.map +1 -1
- package/src/base/kit-styling.js +186 -183
- package/src/base/kit-styling.ts +186 -183
- package/src/base/navigation.d.ts +2 -2
- package/src/base/navigation.d.ts.map +1 -1
- package/src/base/navigation.js +25 -21
- package/src/base/navigation.ts +27 -21
- package/src/base/utilities.d.ts +1 -1
- package/src/base/utilities.d.ts.map +1 -1
- package/src/base/utilities.js +20 -4
- package/src/base/utilities.ts +21 -5
- package/src/base/zazz-element.d.ts +1 -1
- package/src/base/zazz-element.js +1 -1
- package/src/base/zazz-element.ts +1 -1
- package/src/{base → behaviors}/gesture.d.ts +4 -3
- package/src/behaviors/gesture.d.ts.map +1 -0
- package/src/{base → behaviors}/gesture.js +1 -1
- package/src/{base → behaviors}/gesture.ts +5 -4
- package/src/{base → behaviors}/hotkeys.d.ts +2 -1
- package/src/behaviors/hotkeys.d.ts.map +1 -0
- package/src/{base → behaviors}/hotkeys.ts +2 -1
- package/src/behaviors/list-navigation.d.ts +64 -0
- package/src/behaviors/list-navigation.d.ts.map +1 -0
- package/src/behaviors/list-navigation.js +66 -0
- package/src/behaviors/list-navigation.ts +107 -0
- package/src/{base → behaviors}/typeahead.d.ts +3 -1
- package/src/behaviors/typeahead.d.ts.map +1 -0
- package/src/{base → behaviors}/typeahead.js +12 -17
- package/src/{base → behaviors}/typeahead.ts +12 -17
- package/src/css-properties.json +704 -0
- package/src/index.css +7 -0
- package/src/manifest.d.ts +20 -9
- package/src/manifest.d.ts.map +1 -1
- package/src/manifest.js +125 -37
- package/src/manifest.ts +132 -38
- package/src/primitives/accordion/accordion.json +49 -0
- package/src/primitives/alert-dialog/alert-dialog.json +35 -0
- package/src/primitives/autocomplete/autocomplete.d.ts +2 -2
- package/src/primitives/autocomplete/autocomplete.d.ts.map +1 -1
- package/src/primitives/autocomplete/autocomplete.js +2 -2
- package/src/primitives/autocomplete/autocomplete.json +65 -0
- package/src/primitives/autocomplete/autocomplete.ts +2 -2
- package/src/primitives/avatar/avatar.css +108 -0
- package/src/primitives/avatar/avatar.html +20 -74
- package/src/primitives/avatar/avatar.json +48 -0
- package/src/primitives/badge/badge.css +45 -10
- package/src/primitives/badge/badge.html +4 -0
- package/src/primitives/badge/badge.json +83 -0
- package/src/primitives/breadcrumbs/breadcrumbs.json +20 -0
- package/src/primitives/button/button.css +50 -66
- package/src/primitives/button/button.html +4 -0
- package/src/primitives/button/button.json +85 -0
- package/src/primitives/button-group/button-group.css +4 -15
- package/src/primitives/button-group/button-group.json +40 -0
- package/src/primitives/callout/callout.css +1 -1
- package/src/primitives/callout/callout.html +12 -12
- package/src/primitives/callout/callout.json +54 -0
- package/src/primitives/card/card-article.html +13 -37
- package/src/primitives/card/card-horizontal.html +11 -14
- package/src/primitives/card/card-login.html +4 -4
- package/src/primitives/card/card-product.html +3 -3
- package/src/primitives/card/card-subgrid.html +4 -4
- package/src/primitives/card/card.css +1 -1
- package/src/primitives/card/card.html +8 -8
- package/src/primitives/card/card.json +73 -0
- package/src/primitives/carousel/carousel.css +1 -1
- package/src/primitives/carousel/carousel.json +89 -0
- package/src/primitives/checkbox/checkbox.css +1 -2
- package/src/primitives/checkbox/checkbox.json +51 -0
- package/src/primitives/combobox/combobox.css +3 -2
- package/src/primitives/combobox/combobox.d.ts +2 -2
- package/src/primitives/combobox/combobox.d.ts.map +1 -1
- package/src/primitives/combobox/combobox.js +2 -2
- package/src/primitives/combobox/combobox.json +113 -0
- package/src/primitives/combobox/combobox.ts +2 -2
- package/src/primitives/command/command-actions.html +1 -1
- package/src/primitives/command/command.d.ts +4 -3
- package/src/primitives/command/command.d.ts.map +1 -1
- package/src/primitives/command/command.js +7 -6
- package/src/primitives/command/command.json +86 -0
- package/src/primitives/command/command.ts +7 -6
- package/src/primitives/debug/audit-core.d.ts +19 -12
- package/src/primitives/debug/audit-core.d.ts.map +1 -1
- package/src/primitives/debug/audit-core.js +78 -16
- package/src/primitives/debug/audit-core.ts +94 -22
- package/src/primitives/debug/debug.d.ts +6 -4
- package/src/primitives/debug/debug.d.ts.map +1 -1
- package/src/primitives/debug/debug.js +50 -21
- package/src/primitives/debug/debug.json +29 -0
- package/src/primitives/debug/debug.ts +57 -35
- package/src/primitives/dialog/dialog.css +1 -4
- package/src/primitives/dialog/dialog.json +78 -0
- package/src/primitives/drawer/drawer.css +4 -2
- package/src/primitives/drawer/drawer.d.ts.map +1 -1
- package/src/primitives/drawer/drawer.js +76 -4
- package/src/primitives/drawer/drawer.json +98 -0
- package/src/primitives/drawer/drawer.ts +78 -5
- package/src/primitives/fields/fields.css +11 -4
- package/src/primitives/fields/fields.json +92 -0
- package/src/primitives/font/font.css +188 -0
- package/src/primitives/font/font.html +14 -0
- package/src/primitives/font/font.json +39 -0
- package/src/primitives/group/group.json +25 -0
- package/src/primitives/input/input.css +1 -2
- package/src/primitives/input/input.json +56 -0
- package/src/primitives/input-group/input-group-password-group.html +1 -1
- package/src/primitives/input-group/input-group.css +32 -3
- package/src/primitives/input-group/input-group.html +5 -8
- package/src/primitives/input-group/input-group.json +69 -0
- package/src/primitives/kbd/kbd.css +1 -1
- package/src/primitives/kbd/kbd.json +52 -0
- package/src/primitives/layout/layout.json +45 -0
- package/src/primitives/lightbox/lightbox.css +4 -3
- package/src/primitives/lightbox/lightbox.html +2 -2
- package/src/primitives/lightbox/lightbox.js +1 -1
- package/src/primitives/lightbox/lightbox.json +87 -0
- package/src/primitives/lightbox/lightbox.ts +1 -1
- package/src/primitives/link/link.css +28 -0
- package/src/primitives/link/link.html +5 -0
- package/src/primitives/link/link.json +23 -0
- package/src/primitives/menu/menu.d.ts +3 -0
- package/src/primitives/menu/menu.d.ts.map +1 -1
- package/src/primitives/menu/menu.js +10 -25
- package/src/primitives/menu/menu.json +51 -0
- package/src/primitives/menu/menu.ts +10 -27
- package/src/primitives/menubar/menubar.json +23 -0
- package/src/primitives/meter/meter.css +24 -3
- package/src/primitives/meter/meter.json +41 -0
- package/src/primitives/mobile-menu/mobile-menu.html +1 -1
- package/src/primitives/mobile-menu/mobile-menu.json +64 -0
- package/src/primitives/navigation-menu/navigation-menu-featured.html +58 -58
- package/src/primitives/navigation-menu/navigation-menu-megamenu.html +6 -113
- package/src/primitives/navigation-menu/navigation-menu.css +11 -5
- package/src/primitives/navigation-menu/navigation-menu.html +1 -1
- package/src/primitives/navigation-menu/navigation-menu.json +82 -0
- package/src/primitives/otp/otp.css +1 -1
- package/src/primitives/otp/otp.d.ts +3 -3
- package/src/primitives/otp/otp.js +5 -5
- package/src/primitives/otp/otp.json +75 -0
- package/src/primitives/otp/otp.ts +5 -5
- package/src/primitives/password-group/password-group.css +32 -2
- package/src/primitives/password-group/password-group.html +1 -1
- package/src/primitives/password-group/password-group.json +74 -0
- package/src/primitives/popover/popover.css +1 -1
- package/src/primitives/popover/popover.json +64 -0
- package/src/primitives/progress/progress.css +25 -3
- package/src/primitives/progress/progress.json +41 -0
- package/src/primitives/prose/prose.css +341 -0
- package/src/primitives/prose/prose.html +11 -11
- package/src/primitives/prose/prose.json +47 -0
- package/src/primitives/radio/radio.css +1 -1
- package/src/primitives/radio/radio.json +48 -0
- package/src/primitives/reveal/reveal.json +72 -0
- package/src/primitives/scroll-fade/scroll-fade.css +0 -3
- package/src/primitives/scroll-fade/scroll-fade.json +34 -0
- package/src/primitives/select/select.css +2 -2
- package/src/primitives/select/select.json +119 -0
- package/src/primitives/separator/separator.json +34 -0
- package/src/primitives/slider/slider.css +87 -13
- package/src/primitives/slider/slider.json +49 -0
- package/src/primitives/style-guard/style-guard.js +1 -1
- package/src/primitives/style-guard/style-guard.json +22 -0
- package/src/primitives/style-guard/style-guard.ts +2 -2
- package/src/primitives/switch/switch.css +107 -18
- package/src/primitives/switch/switch.json +71 -0
- package/src/primitives/table/table.json +74 -0
- package/src/primitives/tabs/tabs.css +24 -12
- package/src/primitives/tabs/tabs.d.ts +4 -2
- package/src/primitives/tabs/tabs.d.ts.map +1 -1
- package/src/primitives/tabs/tabs.js +14 -24
- package/src/primitives/tabs/tabs.json +94 -0
- package/src/primitives/tabs/tabs.ts +14 -26
- package/src/primitives/textarea/textarea.css +1 -1
- package/src/primitives/textarea/textarea.json +48 -0
- package/src/primitives/toaster/toaster.d.ts.map +1 -1
- package/src/primitives/toaster/toaster.js +4 -4
- package/src/primitives/toaster/toaster.json +101 -0
- package/src/primitives/toaster/toaster.ts +5 -5
- package/src/primitives/toggle/toggle.css +2 -52
- package/src/primitives/toggle/toggle.json +84 -0
- package/src/primitives/toggle-group/toggle-group.css +1 -1
- package/src/primitives/toggle-group/toggle-group.json +41 -0
- package/src/primitives/toolbar/toolbar.json +26 -0
- package/src/primitives/tooltip/tooltip.css +1 -1
- package/src/primitives/tooltip/tooltip.json +85 -0
- package/src/primitives/utilities/aspect-ratio.html +3 -3
- package/src/primitives/utilities/basis.html +5 -5
- package/src/primitives/utilities/col-span.html +5 -5
- package/src/primitives/utilities/compose.html +3 -3
- package/src/primitives/utilities/flex-align.html +3 -3
- package/src/primitives/utilities/flex-direction.html +8 -8
- package/src/primitives/utilities/flex-grow.html +3 -3
- package/src/primitives/utilities/flex-reverse.html +8 -8
- package/src/primitives/utilities/gallery.html +19 -19
- package/src/primitives/utilities/gap.html +12 -12
- package/src/primitives/utilities/grid-cols.html +6 -6
- package/src/primitives/utilities/grid-responsive.html +9 -9
- package/src/primitives/utilities/inline-flex.html +2 -2
- package/src/primitives/utilities/margin-auto.html +1 -1
- package/src/primitives/utilities/object-fit.html +3 -3
- package/src/primitives/utilities/order.html +3 -3
- package/src/primitives/utilities/overflow.html +14 -14
- package/src/primitives/utilities/padding-compose.html +3 -3
- package/src/primitives/utilities/padding.html +4 -4
- package/src/primitives/utilities/position.html +1 -1
- package/src/primitives/utilities/responsive-flex.html +4 -4
- package/src/primitives/utilities/responsive-grid.html +9 -9
- package/src/primitives/utilities/size.html +5 -5
- package/src/primitives/utilities/subgrid-col.html +7 -7
- package/src/primitives/utilities/subgrid-row.html +9 -9
- package/src/primitives/utilities/subgrid.html +9 -9
- package/src/primitives/utilities/utilities.json +48 -0
- package/src/primitives/utilities/width.html +5 -5
- package/src/base/gesture.d.ts.map +0 -1
- package/src/base/hotkeys.d.ts.map +0 -1
- package/src/base/typeahead.d.ts.map +0 -1
- /package/src/{base → behaviors}/command-score.d.ts +0 -0
- /package/src/{base → behaviors}/command-score.d.ts.map +0 -0
- /package/src/{base → behaviors}/command-score.js +0 -0
- /package/src/{base → behaviors}/command-score.ts +0 -0
- /package/src/{base → behaviors}/hotkeys.js +0 -0
package/src/base/navigation.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import { refreshAll } from "./zazz-element.js";
|
|
3
3
|
/**
|
|
4
4
|
* @fileoverview Opt-in in-page navigation via the Navigation API.
|
|
5
|
-
* @description With `<html data-
|
|
5
|
+
* @description With `<html data-navigation="swap">` on both the current and
|
|
6
6
|
* the destination page, a same-origin navigation fetches the destination and
|
|
7
7
|
* swaps the whole `<body>` in place instead of loading a new document. The
|
|
8
8
|
* browser still owns the URL and history; one `navigate` listener covers link
|
|
9
9
|
* clicks, back/forward, and programmatic navigations.
|
|
10
10
|
*
|
|
11
11
|
* Nothing persists implicitly. An element survives a swap only when it carries
|
|
12
|
-
* `data-
|
|
12
|
+
* `data-navigation-persist="<id>"` and the destination has an element with the same id:
|
|
13
13
|
* the live element takes the new one's place, keeping its DOM and state (a toast
|
|
14
14
|
* stack, a playing video, an open mini-cart). Everything else comes from the new
|
|
15
15
|
* page, so headers, footers and current-page links are never stale. A carried
|
|
@@ -25,8 +25,9 @@ import { refreshAll } from "./zazz-element.js";
|
|
|
25
25
|
* stays, so keep page-specific CSS scoped to that page's markup.
|
|
26
26
|
*
|
|
27
27
|
* An element whose content depends on the page (a section sidebar, a table of
|
|
28
|
-
* contents) should not persist; `data-
|
|
29
|
-
* the destination and carries only its scroll
|
|
28
|
+
* contents) should not persist; adding `data-navigation-persist-mode="scroll"`
|
|
29
|
+
* beside the id renders it from the destination and carries only its scroll
|
|
30
|
+
* offset. The window itself
|
|
30
31
|
* scrolls as the browser decides: to the top or the target for a new entry,
|
|
31
32
|
* restored on back/forward.
|
|
32
33
|
*
|
|
@@ -36,8 +37,8 @@ import { refreshAll } from "./zazz-element.js";
|
|
|
36
37
|
* form posts are never intercepted.
|
|
37
38
|
*
|
|
38
39
|
* Another library that drives navigation (htmx, Turbo, a client router) keeps
|
|
39
|
-
* its own. A link or form inside `data-
|
|
40
|
-
* default, and the nearest `data-
|
|
40
|
+
* its own. A link or form inside `data-navigation="off"` gets the browser's
|
|
41
|
+
* default, and the nearest `data-navigation` ancestor decides. Entries the
|
|
41
42
|
* page pushed with `history.pushState()` stay the page's: Back or Forward into
|
|
42
43
|
* or out of one is never swapped, so the library restores it on `popstate`.
|
|
43
44
|
* So does an entry the swap made once a script gives it `history.state` (htmx
|
|
@@ -51,9 +52,13 @@ import { refreshAll } from "./zazz-element.js";
|
|
|
51
52
|
*/
|
|
52
53
|
/** The opt-in, on `<html>` of both pages. */
|
|
53
54
|
const SWAP = "swap";
|
|
55
|
+
/** A carried element: `data-navigation-persist="<id>"` in the default mode. */
|
|
56
|
+
const PERSIST = '[data-navigation-persist]:not([data-navigation-persist-mode="scroll"])';
|
|
57
|
+
/** An element rendered fresh that takes the old one's scroll offset. */
|
|
58
|
+
const PERSIST_SCROLL = '[data-navigation-persist][data-navigation-persist-mode="scroll"]';
|
|
54
59
|
/** True when `doc` opted in to in-page navigation. */
|
|
55
60
|
function optedIn(doc) {
|
|
56
|
-
return doc.documentElement.getAttribute("data-
|
|
61
|
+
return doc.documentElement.getAttribute("data-navigation") === SWAP;
|
|
57
62
|
}
|
|
58
63
|
/**
|
|
59
64
|
* @description Records the scroll offsets of `root` and its scrolled
|
|
@@ -98,9 +103,9 @@ function adoptCurrent(keep, slot) {
|
|
|
98
103
|
}
|
|
99
104
|
/**
|
|
100
105
|
* @description Replaces the current body with `next`, carrying over every
|
|
101
|
-
* `data-
|
|
106
|
+
* `data-navigation-persist` element whose id appears in both, scroll offsets included;
|
|
102
107
|
* links in a carried element take `aria-current` from the destination. A
|
|
103
|
-
* `data-
|
|
108
|
+
* `data-navigation-persist-mode="scroll"` element comes from `next` and takes the scroll
|
|
104
109
|
* offset of the current element with the same id. Returns the new body.
|
|
105
110
|
*
|
|
106
111
|
* @param next - The destination's parsed `<body>`.
|
|
@@ -112,28 +117,28 @@ function swapBody(next) {
|
|
|
112
117
|
// both bodies are connected would lay out the doubled document.
|
|
113
118
|
const live = new Map();
|
|
114
119
|
const offsets = [];
|
|
115
|
-
for (const el of current.querySelectorAll(
|
|
116
|
-
const id = el.getAttribute("data-
|
|
120
|
+
for (const el of current.querySelectorAll(PERSIST)) {
|
|
121
|
+
const id = el.getAttribute("data-navigation-persist");
|
|
117
122
|
if (id && !live.has(id))
|
|
118
123
|
live.set(id, el);
|
|
119
124
|
}
|
|
120
125
|
for (const keep of live.values())
|
|
121
126
|
offsets.push(...scrollOffsets(keep));
|
|
122
127
|
const scrolled = new Map();
|
|
123
|
-
for (const el of current.querySelectorAll(
|
|
124
|
-
const id = el.getAttribute("data-
|
|
128
|
+
for (const el of current.querySelectorAll(PERSIST_SCROLL)) {
|
|
129
|
+
const id = el.getAttribute("data-navigation-persist");
|
|
125
130
|
if (id && !scrolled.has(id))
|
|
126
131
|
scrolled.set(id, [el.scrollTop, el.scrollLeft]);
|
|
127
132
|
}
|
|
128
133
|
const body = document.importNode(next, true);
|
|
129
134
|
const placeholders = [];
|
|
130
|
-
for (const slot of body.querySelectorAll(
|
|
131
|
-
const keep = live.get(slot.getAttribute("data-
|
|
135
|
+
for (const slot of body.querySelectorAll(PERSIST)) {
|
|
136
|
+
const keep = live.get(slot.getAttribute("data-navigation-persist") ?? "");
|
|
132
137
|
if (keep)
|
|
133
138
|
placeholders.push([slot, keep]);
|
|
134
139
|
}
|
|
135
|
-
for (const el of body.querySelectorAll(
|
|
136
|
-
const id = el.getAttribute("data-
|
|
140
|
+
for (const el of body.querySelectorAll(PERSIST_SCROLL)) {
|
|
141
|
+
const id = el.getAttribute("data-navigation-persist") ?? "";
|
|
137
142
|
const offset = scrolled.get(id);
|
|
138
143
|
scrolled.delete(id);
|
|
139
144
|
if (offset)
|
|
@@ -323,11 +328,10 @@ if ("navigation" in window) {
|
|
|
323
328
|
// Forward stay swaps: after one, every entry shares this document.
|
|
324
329
|
// Back and Forward are ours only between entries we made: a traversal into
|
|
325
330
|
// or out of an entry the page pushed is the page's to restore. A link,
|
|
326
|
-
// form or region under `data-
|
|
331
|
+
// form or region under `data-navigation="off"` (an htmx-boosted area, a
|
|
327
332
|
// client router's outlet) always gets the browser's default.
|
|
328
333
|
if (!optedIn(document) ||
|
|
329
|
-
e.sourceElement?.closest("[data-
|
|
330
|
-
"off" ||
|
|
334
|
+
e.sourceElement?.closest("[data-navigation]")?.getAttribute("data-navigation") === "off" ||
|
|
331
335
|
(e.destination.sameDocument &&
|
|
332
336
|
e.navigationType === "traverse" &&
|
|
333
337
|
!(owns(e.destination.key) && owns(window.navigation.currentEntry?.key))) ||
|
|
@@ -421,6 +425,6 @@ if ("navigation" in window) {
|
|
|
421
425
|
});
|
|
422
426
|
}
|
|
423
427
|
else if (optedIn(document)) {
|
|
424
|
-
console.warn("Navigation API not supported: data-
|
|
428
|
+
console.warn("Navigation API not supported: data-navigation falls back to full page loads.");
|
|
425
429
|
}
|
|
426
430
|
export { adoptStyles, swapBody };
|
package/src/base/navigation.ts
CHANGED
|
@@ -4,14 +4,14 @@ import { refreshAll } from "./zazz-element.ts";
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @fileoverview Opt-in in-page navigation via the Navigation API.
|
|
7
|
-
* @description With `<html data-
|
|
7
|
+
* @description With `<html data-navigation="swap">` on both the current and
|
|
8
8
|
* the destination page, a same-origin navigation fetches the destination and
|
|
9
9
|
* swaps the whole `<body>` in place instead of loading a new document. The
|
|
10
10
|
* browser still owns the URL and history; one `navigate` listener covers link
|
|
11
11
|
* clicks, back/forward, and programmatic navigations.
|
|
12
12
|
*
|
|
13
13
|
* Nothing persists implicitly. An element survives a swap only when it carries
|
|
14
|
-
* `data-
|
|
14
|
+
* `data-navigation-persist="<id>"` and the destination has an element with the same id:
|
|
15
15
|
* the live element takes the new one's place, keeping its DOM and state (a toast
|
|
16
16
|
* stack, a playing video, an open mini-cart). Everything else comes from the new
|
|
17
17
|
* page, so headers, footers and current-page links are never stale. A carried
|
|
@@ -27,8 +27,9 @@ import { refreshAll } from "./zazz-element.ts";
|
|
|
27
27
|
* stays, so keep page-specific CSS scoped to that page's markup.
|
|
28
28
|
*
|
|
29
29
|
* An element whose content depends on the page (a section sidebar, a table of
|
|
30
|
-
* contents) should not persist; `data-
|
|
31
|
-
* the destination and carries only its scroll
|
|
30
|
+
* contents) should not persist; adding `data-navigation-persist-mode="scroll"`
|
|
31
|
+
* beside the id renders it from the destination and carries only its scroll
|
|
32
|
+
* offset. The window itself
|
|
32
33
|
* scrolls as the browser decides: to the top or the target for a new entry,
|
|
33
34
|
* restored on back/forward.
|
|
34
35
|
*
|
|
@@ -38,8 +39,8 @@ import { refreshAll } from "./zazz-element.ts";
|
|
|
38
39
|
* form posts are never intercepted.
|
|
39
40
|
*
|
|
40
41
|
* Another library that drives navigation (htmx, Turbo, a client router) keeps
|
|
41
|
-
* its own. A link or form inside `data-
|
|
42
|
-
* default, and the nearest `data-
|
|
42
|
+
* its own. A link or form inside `data-navigation="off"` gets the browser's
|
|
43
|
+
* default, and the nearest `data-navigation` ancestor decides. Entries the
|
|
43
44
|
* page pushed with `history.pushState()` stay the page's: Back or Forward into
|
|
44
45
|
* or out of one is never swapped, so the library restores it on `popstate`.
|
|
45
46
|
* So does an entry the swap made once a script gives it `history.state` (htmx
|
|
@@ -55,9 +56,15 @@ import { refreshAll } from "./zazz-element.ts";
|
|
|
55
56
|
/** The opt-in, on `<html>` of both pages. */
|
|
56
57
|
const SWAP = "swap";
|
|
57
58
|
|
|
59
|
+
/** A carried element: `data-navigation-persist="<id>"` in the default mode. */
|
|
60
|
+
const PERSIST = '[data-navigation-persist]:not([data-navigation-persist-mode="scroll"])';
|
|
61
|
+
|
|
62
|
+
/** An element rendered fresh that takes the old one's scroll offset. */
|
|
63
|
+
const PERSIST_SCROLL = '[data-navigation-persist][data-navigation-persist-mode="scroll"]';
|
|
64
|
+
|
|
58
65
|
/** True when `doc` opted in to in-page navigation. */
|
|
59
66
|
function optedIn(doc: Document): boolean {
|
|
60
|
-
return doc.documentElement.getAttribute("data-
|
|
67
|
+
return doc.documentElement.getAttribute("data-navigation") === SWAP;
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
/** `Element.moveBefore` keeps iframes, media and custom elements live; not in every browser yet. */
|
|
@@ -105,9 +112,9 @@ function adoptCurrent(keep: Element, slot: Element): void {
|
|
|
105
112
|
|
|
106
113
|
/**
|
|
107
114
|
* @description Replaces the current body with `next`, carrying over every
|
|
108
|
-
* `data-
|
|
115
|
+
* `data-navigation-persist` element whose id appears in both, scroll offsets included;
|
|
109
116
|
* links in a carried element take `aria-current` from the destination. A
|
|
110
|
-
* `data-
|
|
117
|
+
* `data-navigation-persist-mode="scroll"` element comes from `next` and takes the scroll
|
|
111
118
|
* offset of the current element with the same id. Returns the new body.
|
|
112
119
|
*
|
|
113
120
|
* @param next - The destination's parsed `<body>`.
|
|
@@ -119,25 +126,25 @@ function swapBody(next: HTMLElement): HTMLElement {
|
|
|
119
126
|
// both bodies are connected would lay out the doubled document.
|
|
120
127
|
const live = new Map<string, Element>();
|
|
121
128
|
const offsets: [Element, number, number][] = [];
|
|
122
|
-
for (const el of current.querySelectorAll(
|
|
123
|
-
const id = el.getAttribute("data-
|
|
129
|
+
for (const el of current.querySelectorAll(PERSIST)) {
|
|
130
|
+
const id = el.getAttribute("data-navigation-persist");
|
|
124
131
|
if (id && !live.has(id)) live.set(id, el);
|
|
125
132
|
}
|
|
126
133
|
for (const keep of live.values()) offsets.push(...scrollOffsets(keep));
|
|
127
134
|
const scrolled = new Map<string, [number, number]>();
|
|
128
|
-
for (const el of current.querySelectorAll(
|
|
129
|
-
const id = el.getAttribute("data-
|
|
135
|
+
for (const el of current.querySelectorAll(PERSIST_SCROLL)) {
|
|
136
|
+
const id = el.getAttribute("data-navigation-persist");
|
|
130
137
|
if (id && !scrolled.has(id)) scrolled.set(id, [el.scrollTop, el.scrollLeft]);
|
|
131
138
|
}
|
|
132
139
|
|
|
133
140
|
const body = document.importNode(next, true);
|
|
134
141
|
const placeholders: [Element, Element][] = [];
|
|
135
|
-
for (const slot of body.querySelectorAll(
|
|
136
|
-
const keep = live.get(slot.getAttribute("data-
|
|
142
|
+
for (const slot of body.querySelectorAll(PERSIST)) {
|
|
143
|
+
const keep = live.get(slot.getAttribute("data-navigation-persist") ?? "");
|
|
137
144
|
if (keep) placeholders.push([slot, keep]);
|
|
138
145
|
}
|
|
139
|
-
for (const el of body.querySelectorAll(
|
|
140
|
-
const id = el.getAttribute("data-
|
|
146
|
+
for (const el of body.querySelectorAll(PERSIST_SCROLL)) {
|
|
147
|
+
const id = el.getAttribute("data-navigation-persist") ?? "";
|
|
141
148
|
const offset = scrolled.get(id);
|
|
142
149
|
scrolled.delete(id);
|
|
143
150
|
if (offset) offsets.push([el, ...offset]);
|
|
@@ -325,12 +332,11 @@ if ("navigation" in window) {
|
|
|
325
332
|
// Forward stay swaps: after one, every entry shares this document.
|
|
326
333
|
// Back and Forward are ours only between entries we made: a traversal into
|
|
327
334
|
// or out of an entry the page pushed is the page's to restore. A link,
|
|
328
|
-
// form or region under `data-
|
|
335
|
+
// form or region under `data-navigation="off"` (an htmx-boosted area, a
|
|
329
336
|
// client router's outlet) always gets the browser's default.
|
|
330
337
|
if (
|
|
331
338
|
!optedIn(document) ||
|
|
332
|
-
e.sourceElement?.closest("[data-
|
|
333
|
-
"off" ||
|
|
339
|
+
e.sourceElement?.closest("[data-navigation]")?.getAttribute("data-navigation") === "off" ||
|
|
334
340
|
(e.destination.sameDocument &&
|
|
335
341
|
e.navigationType === "traverse" &&
|
|
336
342
|
!(owns(e.destination.key) && owns(window.navigation.currentEntry?.key))) ||
|
|
@@ -421,7 +427,7 @@ if ("navigation" in window) {
|
|
|
421
427
|
});
|
|
422
428
|
});
|
|
423
429
|
} else if (optedIn(document)) {
|
|
424
|
-
console.warn("Navigation API not supported: data-
|
|
430
|
+
console.warn("Navigation API not supported: data-navigation falls back to full page loads.");
|
|
425
431
|
}
|
|
426
432
|
|
|
427
433
|
export { adoptStyles, swapBody };
|
package/src/base/utilities.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ export interface Utility {
|
|
|
110
110
|
omitTiers?: readonly (Breakpoint | State)[];
|
|
111
111
|
/**
|
|
112
112
|
* What a dual utility's number multiplies (default `var(--spacing)`):
|
|
113
|
-
* `--radius: 2` is two steps of `--spacing` times `--radius-
|
|
113
|
+
* `--radius: 2` is two steps of `--spacing` times `--radius-coefficient`.
|
|
114
114
|
*/
|
|
115
115
|
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K,CAAC,EAAE,IAAI,CAAC;CACd;AAID,sGAAsG;AACtG,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAyBzD"}
|
package/src/base/utilities.js
CHANGED
|
@@ -194,6 +194,22 @@ export const RETIRED_TOKENS = {
|
|
|
194
194
|
container: "`--container-type: inline-size`",
|
|
195
195
|
"theme-dark": '`data-theme="dark"`',
|
|
196
196
|
"theme-light": '`data-theme="light"`',
|
|
197
|
+
"text-display": '`data-font="display"`',
|
|
198
|
+
"text-h1": '`data-font="h1"`',
|
|
199
|
+
"text-h2": '`data-font="h2"`',
|
|
200
|
+
"text-h3": '`data-font="h3"`',
|
|
201
|
+
"text-h4": '`data-font="h4"`',
|
|
202
|
+
"text-h5": '`data-font="h5"`',
|
|
203
|
+
"text-h6": '`data-font="h6"`',
|
|
204
|
+
"text-2xl": '`data-font="2xl"`',
|
|
205
|
+
"text-xl": '`data-font="xl"`',
|
|
206
|
+
"text-lg": '`data-font="lg"`',
|
|
207
|
+
"text-md": '`data-font="md"`',
|
|
208
|
+
"text-sm": '`data-font="sm"`',
|
|
209
|
+
"text-xs": '`data-font="xs"`',
|
|
210
|
+
"text-2xs": '`data-font="2xs"`',
|
|
211
|
+
"text-eyebrow": '`data-font="eyebrow"`',
|
|
212
|
+
"text-link": '`data-ui="link"`',
|
|
197
213
|
};
|
|
198
214
|
/** The kit's looping animations: each is a keyframe name and a token (`--spin`). */
|
|
199
215
|
export const ANIMATION_TOKENS = ["spin", "ping", "pulse", "bounce"];
|
|
@@ -672,7 +688,7 @@ export const UTILITIES = [
|
|
|
672
688
|
family: "sizing",
|
|
673
689
|
noBase: "auto",
|
|
674
690
|
},
|
|
675
|
-
// typography: one utility per property; roles live in
|
|
691
|
+
// typography: one utility per property; roles live in primitives/font/font.css
|
|
676
692
|
{ name: "font-size", pseudo: true, properties: ["font-size"], mode: "raw", family: "typography" },
|
|
677
693
|
{
|
|
678
694
|
name: "font-weight",
|
|
@@ -1009,7 +1025,7 @@ export const UTILITIES = [
|
|
|
1009
1025
|
},
|
|
1010
1026
|
// box: no tiers, except radius (both), its corners, pointer-events, --container
|
|
1011
1027
|
// and --container-type (breakpoints), and z (states)
|
|
1012
|
-
// a number is that many --spacing steps times --radius-
|
|
1028
|
+
// a number is that many --spacing steps times --radius-coefficient, like the
|
|
1013
1029
|
// --radius-* tokens (`--radius: 2.5` is --radius-md); `full` is the pill token
|
|
1014
1030
|
{
|
|
1015
1031
|
name: "radius",
|
|
@@ -1019,7 +1035,7 @@ export const UTILITIES = [
|
|
|
1019
1035
|
tiers: "both",
|
|
1020
1036
|
noBase: "0",
|
|
1021
1037
|
pseudo: true,
|
|
1022
|
-
scale: "var(--spacing) * var(--radius-
|
|
1038
|
+
scale: "var(--spacing) * var(--radius-coefficient)",
|
|
1023
1039
|
aliases: { full: "var(--radius-full)" },
|
|
1024
1040
|
},
|
|
1025
1041
|
// two logical corners each (Tailwind's rounded-t/-b/-l/-r), after --radius so they
|
|
@@ -1036,7 +1052,7 @@ export const UTILITIES = [
|
|
|
1036
1052
|
family: "box",
|
|
1037
1053
|
tiers: "breakpoints",
|
|
1038
1054
|
noBase: "0",
|
|
1039
|
-
scale: "var(--spacing) * var(--radius-
|
|
1055
|
+
scale: "var(--spacing) * var(--radius-coefficient)",
|
|
1040
1056
|
aliases: { full: "var(--radius-full)" },
|
|
1041
1057
|
})),
|
|
1042
1058
|
// the radius rules leave corner-shape to the defaults layer (see generate-utilities.ts);
|
package/src/base/utilities.ts
CHANGED
|
@@ -199,7 +199,7 @@ export interface Utility {
|
|
|
199
199
|
omitTiers?: readonly (Breakpoint | State)[];
|
|
200
200
|
/**
|
|
201
201
|
* What a dual utility's number multiplies (default `var(--spacing)`):
|
|
202
|
-
* `--radius: 2` is two steps of `--spacing` times `--radius-
|
|
202
|
+
* `--radius: 2` is two steps of `--spacing` times `--radius-coefficient`.
|
|
203
203
|
*/
|
|
204
204
|
scale?: string;
|
|
205
205
|
/**
|
|
@@ -327,6 +327,22 @@ export const RETIRED_TOKENS: Readonly<Record<string, string>> = {
|
|
|
327
327
|
container: "`--container-type: inline-size`",
|
|
328
328
|
"theme-dark": '`data-theme="dark"`',
|
|
329
329
|
"theme-light": '`data-theme="light"`',
|
|
330
|
+
"text-display": '`data-font="display"`',
|
|
331
|
+
"text-h1": '`data-font="h1"`',
|
|
332
|
+
"text-h2": '`data-font="h2"`',
|
|
333
|
+
"text-h3": '`data-font="h3"`',
|
|
334
|
+
"text-h4": '`data-font="h4"`',
|
|
335
|
+
"text-h5": '`data-font="h5"`',
|
|
336
|
+
"text-h6": '`data-font="h6"`',
|
|
337
|
+
"text-2xl": '`data-font="2xl"`',
|
|
338
|
+
"text-xl": '`data-font="xl"`',
|
|
339
|
+
"text-lg": '`data-font="lg"`',
|
|
340
|
+
"text-md": '`data-font="md"`',
|
|
341
|
+
"text-sm": '`data-font="sm"`',
|
|
342
|
+
"text-xs": '`data-font="xs"`',
|
|
343
|
+
"text-2xs": '`data-font="2xs"`',
|
|
344
|
+
"text-eyebrow": '`data-font="eyebrow"`',
|
|
345
|
+
"text-link": '`data-ui="link"`',
|
|
330
346
|
};
|
|
331
347
|
|
|
332
348
|
/** The kit's looping animations: each is a keyframe name and a token (`--spin`). */
|
|
@@ -818,7 +834,7 @@ export const UTILITIES: readonly Utility[] = [
|
|
|
818
834
|
family: "sizing",
|
|
819
835
|
noBase: "auto",
|
|
820
836
|
},
|
|
821
|
-
// typography: one utility per property; roles live in
|
|
837
|
+
// typography: one utility per property; roles live in primitives/font/font.css
|
|
822
838
|
{ name: "font-size", pseudo: true, properties: ["font-size"], mode: "raw", family: "typography" },
|
|
823
839
|
{
|
|
824
840
|
name: "font-weight",
|
|
@@ -1155,7 +1171,7 @@ export const UTILITIES: readonly Utility[] = [
|
|
|
1155
1171
|
},
|
|
1156
1172
|
// box: no tiers, except radius (both), its corners, pointer-events, --container
|
|
1157
1173
|
// and --container-type (breakpoints), and z (states)
|
|
1158
|
-
// a number is that many --spacing steps times --radius-
|
|
1174
|
+
// a number is that many --spacing steps times --radius-coefficient, like the
|
|
1159
1175
|
// --radius-* tokens (`--radius: 2.5` is --radius-md); `full` is the pill token
|
|
1160
1176
|
{
|
|
1161
1177
|
name: "radius",
|
|
@@ -1165,7 +1181,7 @@ export const UTILITIES: readonly Utility[] = [
|
|
|
1165
1181
|
tiers: "both",
|
|
1166
1182
|
noBase: "0",
|
|
1167
1183
|
pseudo: true,
|
|
1168
|
-
scale: "var(--spacing) * var(--radius-
|
|
1184
|
+
scale: "var(--spacing) * var(--radius-coefficient)",
|
|
1169
1185
|
aliases: { full: "var(--radius-full)" },
|
|
1170
1186
|
},
|
|
1171
1187
|
// two logical corners each (Tailwind's rounded-t/-b/-l/-r), after --radius so they
|
|
@@ -1184,7 +1200,7 @@ export const UTILITIES: readonly Utility[] = [
|
|
|
1184
1200
|
family: "box",
|
|
1185
1201
|
tiers: "breakpoints",
|
|
1186
1202
|
noBase: "0",
|
|
1187
|
-
scale: "var(--spacing) * var(--radius-
|
|
1203
|
+
scale: "var(--spacing) * var(--radius-coefficient)",
|
|
1188
1204
|
aliases: { full: "var(--radius-full)" },
|
|
1189
1205
|
})),
|
|
1190
1206
|
// the radius rules leave corner-shape to the defaults layer (see generate-utilities.ts);
|
|
@@ -25,7 +25,7 @@ declare abstract class ZazzElement extends HTMLElement {
|
|
|
25
25
|
#private;
|
|
26
26
|
connectedCallback(): void;
|
|
27
27
|
/**
|
|
28
|
-
* A `moveBefore()` move (a `data-
|
|
28
|
+
* A `moveBefore()` move (a `data-navigation-persist` element riding a navigation swap)
|
|
29
29
|
* keeps the element connected: without this, the browser would fire
|
|
30
30
|
* disconnect + connect and the element would tear down and set up again.
|
|
31
31
|
*/
|
package/src/base/zazz-element.js
CHANGED
|
@@ -31,7 +31,7 @@ class ZazzElement extends HTMLElement {
|
|
|
31
31
|
this.setup(this.#controller.signal);
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
* A `moveBefore()` move (a `data-
|
|
34
|
+
* A `moveBefore()` move (a `data-navigation-persist` element riding a navigation swap)
|
|
35
35
|
* keeps the element connected: without this, the browser would fire
|
|
36
36
|
* disconnect + connect and the element would tear down and set up again.
|
|
37
37
|
*/
|
package/src/base/zazz-element.ts
CHANGED
|
@@ -34,7 +34,7 @@ abstract class ZazzElement extends HTMLElement {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* A `moveBefore()` move (a `data-
|
|
37
|
+
* A `moveBefore()` move (a `data-navigation-persist` element riding a navigation swap)
|
|
38
38
|
* keeps the element connected: without this, the browser would fire
|
|
39
39
|
* disconnect + connect and the element would tear down and set up again.
|
|
40
40
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Shared drag tracking for gesture-driven primitives
|
|
3
|
-
* swipe-to-dismiss, the drawer
|
|
2
|
+
* @fileoverview Shared drag tracking for gesture-driven primitives: toast
|
|
3
|
+
* swipe-to-dismiss, the drawer, and the carousel's mouse drag
|
|
4
|
+
* (`base/carousel-scroll.ts`).
|
|
4
5
|
* @description A gesture has two phases, and this module owns only the first.
|
|
5
6
|
*
|
|
6
7
|
* - **Track** (pointer down): `trackDrag()` reports the pointer's offset along a
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
* A drag starts only once the pointer has moved past a small slop, so a press
|
|
19
20
|
* on a button inside the element is still a click; the click that would follow
|
|
20
21
|
* a real drag is swallowed. Form fields, editable content, and anything inside
|
|
21
|
-
* `[data-
|
|
22
|
+
* `[data-draggable="false"]` never start a drag, and neither does a press that is
|
|
22
23
|
* selecting text: give a surface that should drag from its text
|
|
23
24
|
* `user-select: none`.
|
|
24
25
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gesture.d.ts","sourceRoot":"","sources":["gesture.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH,oCAAoC;AACpC,KAAK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AED;;;;;;;GAOG;AACH,iBAAS,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAKpE;AAmCD;;;;;;;;;;;;;;GAcG;AACH,iBAAS,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CA4InE;AAED,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,QAAQ,EACR,UAAU,EACV,aAAa,EACb,SAAS,GACV,CAAC;AACF,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -13,7 +13,7 @@ const MIN_FLICK_MS = 120;
|
|
|
13
13
|
*/
|
|
14
14
|
const CLICK_SUPPRESS_MS = 50;
|
|
15
15
|
/** Targets that never start a drag: they need the pointer for themselves. */
|
|
16
|
-
const NO_DRAG = 'input, select, textarea, [contenteditable]:not([contenteditable="false"]), [data-
|
|
16
|
+
const NO_DRAG = 'input, select, textarea, [contenteditable]:not([contenteditable="false"]), [data-draggable="false"]';
|
|
17
17
|
/**
|
|
18
18
|
* @description Creates a rolling velocity estimate from the samples of the
|
|
19
19
|
* last 100ms. A whole-gesture average (distance over total time) under-reads
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @fileoverview Shared drag tracking for gesture-driven primitives
|
|
5
|
-
* swipe-to-dismiss, the drawer
|
|
4
|
+
* @fileoverview Shared drag tracking for gesture-driven primitives: toast
|
|
5
|
+
* swipe-to-dismiss, the drawer, and the carousel's mouse drag
|
|
6
|
+
* (`base/carousel-scroll.ts`).
|
|
6
7
|
* @description A gesture has two phases, and this module owns only the first.
|
|
7
8
|
*
|
|
8
9
|
* - **Track** (pointer down): `trackDrag()` reports the pointer's offset along a
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
* A drag starts only once the pointer has moved past a small slop, so a press
|
|
21
22
|
* on a button inside the element is still a click; the click that would follow
|
|
22
23
|
* a real drag is swallowed. Form fields, editable content, and anything inside
|
|
23
|
-
* `[data-
|
|
24
|
+
* `[data-draggable="false"]` never start a drag, and neither does a press that is
|
|
24
25
|
* selecting text: give a surface that should drag from its text
|
|
25
26
|
* `user-select: none`.
|
|
26
27
|
*
|
|
@@ -117,7 +118,7 @@ const CLICK_SUPPRESS_MS = 50;
|
|
|
117
118
|
|
|
118
119
|
/** Targets that never start a drag: they need the pointer for themselves. */
|
|
119
120
|
const NO_DRAG =
|
|
120
|
-
'input, select, textarea, [contenteditable]:not([contenteditable="false"]), [data-
|
|
121
|
+
'input, select, textarea, [contenteditable]:not([contenteditable="false"]), [data-draggable="false"]';
|
|
121
122
|
|
|
122
123
|
/**
|
|
123
124
|
* @description Creates a rolling velocity estimate from the samples of the
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Minimal hotkey parsing and matching for the command family
|
|
2
|
+
* @fileoverview Minimal hotkey parsing and matching for the command family
|
|
3
|
+
* (`primitives/command/command.ts`).
|
|
3
4
|
* @description Turns `"mod+k"`-style specs into structured hotkeys and matches
|
|
4
5
|
* them against keyboard events. `mod` resolves to Meta on Apple platforms and
|
|
5
6
|
* Control elsewhere. Bare-key hotkeys (no modifier) are suppressed while the
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hotkeys.d.ts","sourceRoot":"","sources":["hotkeys.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AAIH,iEAAiE;AACjE,UAAU,MAAM;IACd,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,wBAAwB;IACxB,IAAI,EAAE,OAAO,CAAC;IACd,2BAA2B;IAC3B,GAAG,EAAE,OAAO,CAAC;IACb,sBAAsB;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,6BAA6B;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,iFAAiF;IACjF,GAAG,EAAE,OAAO,CAAC;CACd;AAID;;;;;GAKG;AACH,iBAAS,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA6ChD;AAgBD;;;;;;;;;GASG;AACH,iBAAS,aAAa,CACpB,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,OAA2B,GACjC,OAAO,CAUT;AAED;;;;;;GAMG;AACH,iBAAS,gBAAgB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,CAQ3D;AAED;;;;;;GAMG;AACH,iBAAS,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE1C;AAED;;;;;;;;;GASG;AACH,iBAAS,UAAU,CACjB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EACxC,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GACrC,OAAO,CAgBT;AAED,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AAC/E,YAAY,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @fileoverview Minimal hotkey parsing and matching for the command family
|
|
4
|
+
* @fileoverview Minimal hotkey parsing and matching for the command family
|
|
5
|
+
* (`primitives/command/command.ts`).
|
|
5
6
|
* @description Turns `"mod+k"`-style specs into structured hotkeys and matches
|
|
6
7
|
* them against keyboard events. `mod` resolves to Meta on Apple platforms and
|
|
7
8
|
* Control elsewhere. Bare-key hotkeys (no modifier) are suppressed while the
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview List navigation: the keys that move through a list of items.
|
|
3
|
+
* @description The decision half of arrow-key navigation, shared by the
|
|
4
|
+
* tabs, the menu, and the typeahead engine (autocomplete, combobox, command).
|
|
5
|
+
*
|
|
6
|
+
* A key press is two questions, and each has one function:
|
|
7
|
+
*
|
|
8
|
+
* - `listStep()`: which step is this key? The arrows along the list's
|
|
9
|
+
* orientation are `next` and `previous`, mirrored in RTL for a horizontal
|
|
10
|
+
* list; Home and End are `first` and `last`. Any other key is `null`, so the
|
|
11
|
+
* caller returns before it calls `preventDefault()`.
|
|
12
|
+
* - `stepIndex()`: where does that step land? Lists wrap at both ends.
|
|
13
|
+
*
|
|
14
|
+
* The primitive owns everything else: which elements are items, and what
|
|
15
|
+
* moving means there (focus a link, check a radio, set
|
|
16
|
+
* `aria-activedescendant`). `isDisabledItem()` is the one test for an item the
|
|
17
|
+
* keys skip.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const step = listStep(event.key, { orientation: "horizontal", rtl });
|
|
21
|
+
* if (!step) return;
|
|
22
|
+
* event.preventDefault();
|
|
23
|
+
* items[stepIndex(items.indexOf(target), step, items.length)]?.focus();
|
|
24
|
+
*/
|
|
25
|
+
/** A move through a list. */
|
|
26
|
+
type ListStep = "next" | "previous" | "first" | "last";
|
|
27
|
+
/** How a list is laid out, which decides the arrow keys that move through it. */
|
|
28
|
+
interface ListLayout {
|
|
29
|
+
/** The axis the items run along. Defaults to `vertical`. */
|
|
30
|
+
orientation?: "vertical" | "horizontal";
|
|
31
|
+
/** Whether the list's writing direction is right to left. Only a horizontal list reads it. */
|
|
32
|
+
rtl?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @description Maps a key to a step through a list. The arrows across the
|
|
36
|
+
* list's orientation are not steps, so a vertical list leaves ArrowLeft and
|
|
37
|
+
* ArrowRight to the page.
|
|
38
|
+
*
|
|
39
|
+
* @param key - The `KeyboardEvent.key` pressed.
|
|
40
|
+
* @param layout - The list's orientation and writing direction.
|
|
41
|
+
* @returns The step, or null when the key does not move through the list.
|
|
42
|
+
*/
|
|
43
|
+
declare function listStep(key: string, layout?: ListLayout): ListStep | null;
|
|
44
|
+
/**
|
|
45
|
+
* @description Reducer for a step through a wrapping list. From no current
|
|
46
|
+
* item, `next` enters at the first item and `previous` at the last.
|
|
47
|
+
*
|
|
48
|
+
* @param current - The current index, -1 for none.
|
|
49
|
+
* @param step - The step to take.
|
|
50
|
+
* @param count - How many items the list has.
|
|
51
|
+
* @returns The index the step lands on, -1 when the list is empty.
|
|
52
|
+
*/
|
|
53
|
+
declare function stepIndex(current: number, step: ListStep, count: number): number;
|
|
54
|
+
/**
|
|
55
|
+
* @description Whether the keys skip an item: a disabled form control, or any
|
|
56
|
+
* element marked `aria-disabled="true"` (a link has no `disabled`).
|
|
57
|
+
*
|
|
58
|
+
* @param item - The list item.
|
|
59
|
+
* @returns True when the item is disabled.
|
|
60
|
+
*/
|
|
61
|
+
declare function isDisabledItem(item: Element): boolean;
|
|
62
|
+
export { listStep, stepIndex, isDisabledItem };
|
|
63
|
+
export type { ListLayout, ListStep };
|
|
64
|
+
//# sourceMappingURL=list-navigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-navigation.d.ts","sourceRoot":"","sources":["list-navigation.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,6BAA6B;AAC7B,KAAK,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,CAAC;AAEvD,iFAAiF;AACjF,UAAU,UAAU;IAClB,4DAA4D;IAC5D,WAAW,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;IACxC,8FAA8F;IAC9F,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAID;;;;;;;;GAQG;AACH,iBAAS,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,UAAe,GAAG,QAAQ,GAAG,IAAI,CAcvE;AAID;;;;;;;;GAQG;AACH,iBAAS,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAYzE;AAID;;;;;;GAMG;AACH,iBAAS,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAE9C;AAED,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;AAC/C,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC"}
|