@zazz-ui/core 0.1.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/CHANGELOG.md +19 -0
- package/LICENSE +21 -0
- package/README.md +61 -0
- package/dist/sri.json +75 -0
- package/dist/zazz.css +1 -0
- package/dist/zazz.js +1 -0
- package/examples/about.html +590 -0
- package/examples/components.html +1040 -0
- package/examples/forms.html +511 -0
- package/examples/index.html +268 -0
- package/examples/layout.html +320 -0
- package/examples/products.html +846 -0
- package/examples/responsive.html +339 -0
- package/package.json +85 -0
- package/src/base/_layers.css +12 -0
- package/src/base/_layout.css +568 -0
- package/src/base/_reset.css +515 -0
- package/src/base/_typography.css +495 -0
- package/src/base/_utilities.css +6628 -0
- package/src/base/_variables.css +682 -0
- package/src/base/_view-transitions.css +103 -0
- package/src/base/command-score.d.ts +12 -0
- package/src/base/command-score.d.ts.map +1 -0
- package/src/base/command-score.js +151 -0
- package/src/base/command-score.ts +192 -0
- package/src/base/dialog-lifecycle.d.ts +11 -0
- package/src/base/dialog-lifecycle.d.ts.map +1 -0
- package/src/base/dialog-lifecycle.js +65 -0
- package/src/base/dialog-lifecycle.ts +80 -0
- package/src/base/embla.d.ts +90 -0
- package/src/base/embla.d.ts.map +1 -0
- package/src/base/embla.js +643 -0
- package/src/base/embla.ts +791 -0
- package/src/base/hotkeys.d.ts +82 -0
- package/src/base/hotkeys.d.ts.map +1 -0
- package/src/base/hotkeys.js +141 -0
- package/src/base/hotkeys.ts +195 -0
- package/src/base/navigation.d.ts +2 -0
- package/src/base/navigation.d.ts.map +1 -0
- package/src/base/navigation.js +136 -0
- package/src/base/navigation.ts +151 -0
- package/src/base/reveal.d.ts +80 -0
- package/src/base/reveal.d.ts.map +1 -0
- package/src/base/reveal.js +305 -0
- package/src/base/reveal.ts +379 -0
- package/src/base/signals.d.ts +89 -0
- package/src/base/signals.d.ts.map +1 -0
- package/src/base/signals.js +134 -0
- package/src/base/signals.ts +164 -0
- package/src/base/typeahead.d.ts +105 -0
- package/src/base/typeahead.d.ts.map +1 -0
- package/src/base/typeahead.js +411 -0
- package/src/base/typeahead.ts +500 -0
- package/src/base/utils.d.ts +56 -0
- package/src/base/utils.d.ts.map +1 -0
- package/src/base/utils.js +88 -0
- package/src/base/utils.ts +98 -0
- package/src/base/zazz-element.d.ts +44 -0
- package/src/base/zazz-element.d.ts.map +1 -0
- package/src/base/zazz-element.js +59 -0
- package/src/base/zazz-element.ts +73 -0
- package/src/globals.d.ts +148 -0
- package/src/head.d.ts +95 -0
- package/src/head.d.ts.map +1 -0
- package/src/head.js +311 -0
- package/src/head.ts +433 -0
- package/src/index.css +71 -0
- package/src/index.d.ts +36 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +35 -0
- package/src/index.ts +36 -0
- package/src/manifest.d.ts +90 -0
- package/src/manifest.d.ts.map +1 -0
- package/src/manifest.js +614 -0
- package/src/manifest.ts +667 -0
- package/src/primitives/accordion/accordion.css +104 -0
- package/src/primitives/accordion/accordion.html +69 -0
- package/src/primitives/alert-dialog/alert-dialog.css +38 -0
- package/src/primitives/alert-dialog/alert-dialog.html +53 -0
- package/src/primitives/autocomplete/autocomplete-groups.html +77 -0
- package/src/primitives/autocomplete/autocomplete.css +114 -0
- package/src/primitives/autocomplete/autocomplete.d.ts +30 -0
- package/src/primitives/autocomplete/autocomplete.d.ts.map +1 -0
- package/src/primitives/autocomplete/autocomplete.html +66 -0
- package/src/primitives/autocomplete/autocomplete.js +41 -0
- package/src/primitives/autocomplete/autocomplete.ts +46 -0
- package/src/primitives/avatar/avatar.html +44 -0
- package/src/primitives/badge/badge-icon.html +36 -0
- package/src/primitives/badge/badge.css +251 -0
- package/src/primitives/badge/badge.html +7 -0
- package/src/primitives/breadcrumbs/breadcrumbs.html +9 -0
- package/src/primitives/button/button-icon-only.html +84 -0
- package/src/primitives/button/button-icon.html +82 -0
- package/src/primitives/button/button.css +319 -0
- package/src/primitives/button/button.html +8 -0
- package/src/primitives/button-group/button-group-vertical.html +6 -0
- package/src/primitives/button-group/button-group.css +94 -0
- package/src/primitives/button-group/button-group.html +64 -0
- package/src/primitives/card/card-subgrid.html +118 -0
- package/src/primitives/card/card.html +53 -0
- package/src/primitives/carousel/carousel.css +61 -0
- package/src/primitives/carousel/carousel.d.ts +16 -0
- package/src/primitives/carousel/carousel.d.ts.map +1 -0
- package/src/primitives/carousel/carousel.html +315 -0
- package/src/primitives/carousel/carousel.js +73 -0
- package/src/primitives/carousel/carousel.ts +84 -0
- package/src/primitives/checkbox/checkbox-tasklist.html +71 -0
- package/src/primitives/checkbox/checkbox.css +82 -0
- package/src/primitives/checkbox/checkbox.d.ts +21 -0
- package/src/primitives/checkbox/checkbox.d.ts.map +1 -0
- package/src/primitives/checkbox/checkbox.html +17 -0
- package/src/primitives/checkbox/checkbox.js +190 -0
- package/src/primitives/checkbox/checkbox.ts +219 -0
- package/src/primitives/combobox/combobox-multiselect.html +91 -0
- package/src/primitives/combobox/combobox.css +307 -0
- package/src/primitives/combobox/combobox.d.ts +100 -0
- package/src/primitives/combobox/combobox.d.ts.map +1 -0
- package/src/primitives/combobox/combobox.html +73 -0
- package/src/primitives/combobox/combobox.js +503 -0
- package/src/primitives/combobox/combobox.ts +559 -0
- package/src/primitives/command/command-actions.d.ts +31 -0
- package/src/primitives/command/command-actions.d.ts.map +1 -0
- package/src/primitives/command/command-actions.html +89 -0
- package/src/primitives/command/command-actions.js +70 -0
- package/src/primitives/command/command-actions.ts +77 -0
- package/src/primitives/command/command-dialog.html +77 -0
- package/src/primitives/command/command.css +151 -0
- package/src/primitives/command/command.d.ts +52 -0
- package/src/primitives/command/command.d.ts.map +1 -0
- package/src/primitives/command/command.html +119 -0
- package/src/primitives/command/command.js +146 -0
- package/src/primitives/command/command.ts +157 -0
- package/src/primitives/dialog/dialog-with-form.html +200 -0
- package/src/primitives/dialog/dialog.css +229 -0
- package/src/primitives/dialog/dialog.html +90 -0
- package/src/primitives/fields/fields.css +278 -0
- package/src/primitives/input/input-icon-leading.html +19 -0
- package/src/primitives/input/input-icon-trailing.html +18 -0
- package/src/primitives/input/input.css +114 -0
- package/src/primitives/input/input.html +61 -0
- package/src/primitives/input-group/input-group-password-group.html +108 -0
- package/src/primitives/input-group/input-group.css +215 -0
- package/src/primitives/input-group/input-group.html +132 -0
- package/src/primitives/kbd/kbd-group.html +18 -0
- package/src/primitives/kbd/kbd.css +87 -0
- package/src/primitives/kbd/kbd.html +7 -0
- package/src/primitives/lightbox/lightbox.css +459 -0
- package/src/primitives/lightbox/lightbox.d.ts +7 -0
- package/src/primitives/lightbox/lightbox.d.ts.map +1 -0
- package/src/primitives/lightbox/lightbox.html +665 -0
- package/src/primitives/lightbox/lightbox.js +96 -0
- package/src/primitives/lightbox/lightbox.ts +113 -0
- package/src/primitives/menu/menu-interest.html +52 -0
- package/src/primitives/menu/menu.css +55 -0
- package/src/primitives/menu/menu.d.ts +38 -0
- package/src/primitives/menu/menu.d.ts.map +1 -0
- package/src/primitives/menu/menu.html +70 -0
- package/src/primitives/menu/menu.js +117 -0
- package/src/primitives/menu/menu.ts +131 -0
- package/src/primitives/menubar/menubar-help-search.html +103 -0
- package/src/primitives/menubar/menubar.html +166 -0
- package/src/primitives/meter/meter.css +178 -0
- package/src/primitives/meter/meter.html +38 -0
- package/src/primitives/mobile-menu/mobile-menu.css +145 -0
- package/src/primitives/mobile-menu/mobile-menu.html +614 -0
- package/src/primitives/navigation-menu/navigation-menu-featured.html +76 -0
- package/src/primitives/navigation-menu/navigation-menu-icon-grid.html +158 -0
- package/src/primitives/navigation-menu/navigation-menu-interest.html +103 -0
- package/src/primitives/navigation-menu/navigation-menu-megamenu.html +141 -0
- package/src/primitives/navigation-menu/navigation-menu-simple.html +96 -0
- package/src/primitives/navigation-menu/navigation-menu.css +295 -0
- package/src/primitives/navigation-menu/navigation-menu.html +576 -0
- package/src/primitives/otp/otp.css +126 -0
- package/src/primitives/otp/otp.d.ts +89 -0
- package/src/primitives/otp/otp.d.ts.map +1 -0
- package/src/primitives/otp/otp.html +22 -0
- package/src/primitives/otp/otp.js +226 -0
- package/src/primitives/otp/otp.ts +279 -0
- package/src/primitives/password-group/password-group.css +238 -0
- package/src/primitives/password-group/password-group.d.ts +25 -0
- package/src/primitives/password-group/password-group.d.ts.map +1 -0
- package/src/primitives/password-group/password-group.html +109 -0
- package/src/primitives/password-group/password-group.js +76 -0
- package/src/primitives/password-group/password-group.ts +95 -0
- package/src/primitives/popover/popover.css +233 -0
- package/src/primitives/progress/progress-indeterminate.html +1 -0
- package/src/primitives/progress/progress.css +105 -0
- package/src/primitives/progress/progress.html +7 -0
- package/src/primitives/prose/prose.html +65 -0
- package/src/primitives/radio/radio.css +84 -0
- package/src/primitives/radio/radio.html +17 -0
- package/src/primitives/reveal/reveal.css +167 -0
- package/src/primitives/select/multiselect.d.ts +43 -0
- package/src/primitives/select/multiselect.d.ts.map +1 -0
- package/src/primitives/select/multiselect.js +147 -0
- package/src/primitives/select/multiselect.ts +188 -0
- package/src/primitives/select/select-align.html +49 -0
- package/src/primitives/select/select-multiple.html +12 -0
- package/src/primitives/select/select-sides.html +65 -0
- package/src/primitives/select/select.css +481 -0
- package/src/primitives/select/select.html +16 -0
- package/src/primitives/separator/separator.css +49 -0
- package/src/primitives/separator/separator.html +16 -0
- package/src/primitives/slider/slider.css +122 -0
- package/src/primitives/slider/slider.html +1 -0
- package/src/primitives/switch/switch.css +126 -0
- package/src/primitives/switch/switch.html +13 -0
- package/src/primitives/table/table-alternating.html +36 -0
- package/src/primitives/table/table-grid.html +30 -0
- package/src/primitives/table/table-size-sm.html +26 -0
- package/src/primitives/table/table.css +158 -0
- package/src/primitives/table/table.html +45 -0
- package/src/primitives/tabs/tabs.css +328 -0
- package/src/primitives/tabs/tabs.d.ts +35 -0
- package/src/primitives/tabs/tabs.d.ts.map +1 -0
- package/src/primitives/tabs/tabs.html +75 -0
- package/src/primitives/tabs/tabs.js +84 -0
- package/src/primitives/tabs/tabs.ts +93 -0
- package/src/primitives/textarea/textarea.css +78 -0
- package/src/primitives/textarea/textarea.html +10 -0
- package/src/primitives/toaster/toaster.css +309 -0
- package/src/primitives/toaster/toaster.d.ts +138 -0
- package/src/primitives/toaster/toaster.d.ts.map +1 -0
- package/src/primitives/toaster/toaster.html +77 -0
- package/src/primitives/toaster/toaster.js +736 -0
- package/src/primitives/toaster/toaster.ts +823 -0
- package/src/primitives/toggle/toggle.css +295 -0
- package/src/primitives/toggle/toggle.html +68 -0
- package/src/primitives/toggle-group/toggle-group-multiple.html +14 -0
- package/src/primitives/toggle-group/toggle-group-vertical.html +14 -0
- package/src/primitives/toggle-group/toggle-group.css +73 -0
- package/src/primitives/toggle-group/toggle-group.html +53 -0
- package/src/primitives/toolbar/toolbar.html +45 -0
- package/src/primitives/tooltip/tooltip-disabled.html +19 -0
- package/src/primitives/tooltip/tooltip-sides.html +57 -0
- package/src/primitives/tooltip/tooltip-with-kbd.html +31 -0
- package/src/primitives/tooltip/tooltip.css +235 -0
- package/src/primitives/tooltip/tooltip.html +12 -0
- package/src/primitives/utilities/aspect-ratio.html +17 -0
- package/src/primitives/utilities/basis.html +27 -0
- package/src/primitives/utilities/col-span.html +23 -0
- package/src/primitives/utilities/compose.html +19 -0
- package/src/primitives/utilities/flex-align.html +26 -0
- package/src/primitives/utilities/flex-direction.html +36 -0
- package/src/primitives/utilities/flex-grow.html +17 -0
- package/src/primitives/utilities/gap.html +62 -0
- package/src/primitives/utilities/grid-cols.html +20 -0
- package/src/primitives/utilities/grid-pile.html +5 -0
- package/src/primitives/utilities/grid-responsive.html +31 -0
- package/src/primitives/utilities/margin-auto.html +13 -0
- package/src/primitives/utilities/object-fit.html +41 -0
- package/src/primitives/utilities/order.html +17 -0
- package/src/primitives/utilities/overflow.html +26 -0
- package/src/primitives/utilities/padding-compose.html +23 -0
- package/src/primitives/utilities/padding.html +30 -0
- package/src/primitives/utilities/position.html +13 -0
- package/src/primitives/utilities/responsive-flex.html +22 -0
- package/src/primitives/utilities/responsive-grid.html +31 -0
- package/src/primitives/utilities/size.html +22 -0
- package/src/primitives/utilities/width.html +22 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Minimal hotkey parsing and matching for the command family.
|
|
3
|
+
* @description Turns `"mod+k"`-style specs into structured hotkeys and matches
|
|
4
|
+
* them against keyboard events. `mod` resolves to Meta on Apple platforms and
|
|
5
|
+
* Control elsewhere. Bare-key hotkeys (no modifier) are suppressed while the
|
|
6
|
+
* user types in an editable context so accelerators never eat input.
|
|
7
|
+
*
|
|
8
|
+
* This file is a deliberate seam (like `signals.ts`): the kit's needs are a
|
|
9
|
+
* parser, a matcher, and an editable-target guard, so a dependency was not
|
|
10
|
+
* worth the pinning contract; swap the internals here if a library ever
|
|
11
|
+
* earns its keep.
|
|
12
|
+
*
|
|
13
|
+
* Spec grammar: `+`-separated tokens, case-insensitive. Modifiers: `mod`,
|
|
14
|
+
* `ctrl`/`control`, `alt`/`option`, `shift`, `meta`/`cmd`/`super`. The final
|
|
15
|
+
* token is the key, compared against `KeyboardEvent.key` (single letters
|
|
16
|
+
* case-insensitively, so `mod+K` and `mod+k` are the same hotkey).
|
|
17
|
+
*/
|
|
18
|
+
/** A parsed hotkey: required modifiers plus the terminal key. */
|
|
19
|
+
interface Hotkey {
|
|
20
|
+
/** Required `KeyboardEvent.key`, lowercased for single characters. */
|
|
21
|
+
key: string;
|
|
22
|
+
/** Requires Control. */
|
|
23
|
+
ctrl: boolean;
|
|
24
|
+
/** Requires Alt/Option. */
|
|
25
|
+
alt: boolean;
|
|
26
|
+
/** Requires Shift. */
|
|
27
|
+
shift: boolean;
|
|
28
|
+
/** Requires Meta/Command. */
|
|
29
|
+
meta: boolean;
|
|
30
|
+
/** Requires the platform primary modifier (Meta on Apple, Control elsewhere). */
|
|
31
|
+
mod: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @description Parses a `"mod+shift+p"`-style spec into a structured hotkey.
|
|
35
|
+
*
|
|
36
|
+
* @param spec - The hotkey spec, `+`-separated, case-insensitive.
|
|
37
|
+
* @returns The parsed hotkey, or null for an empty/invalid spec.
|
|
38
|
+
*/
|
|
39
|
+
declare function parseHotkey(spec: string): Hotkey | null;
|
|
40
|
+
/**
|
|
41
|
+
* @description Matches a keyboard event against a parsed hotkey. Modifier
|
|
42
|
+
* states must match exactly (`mod+k` does not fire on `mod+shift+k`) except
|
|
43
|
+
* that `mod` claims whichever of Meta/Control the platform assigns it.
|
|
44
|
+
*
|
|
45
|
+
* @param event - The keyboard event to test.
|
|
46
|
+
* @param hotkey - The parsed hotkey to match.
|
|
47
|
+
* @param apple - Platform override for tests; defaults to detection.
|
|
48
|
+
* @returns True when the event is exactly this hotkey.
|
|
49
|
+
*/
|
|
50
|
+
declare function matchesHotkey(event: KeyboardEvent, hotkey: Hotkey, apple?: boolean): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* @description Whether a node is an editable context (form field or
|
|
53
|
+
* contenteditable), where bare-key hotkeys must not fire.
|
|
54
|
+
*
|
|
55
|
+
* @param node - The event target to inspect.
|
|
56
|
+
* @returns True when typing belongs to the node, not to hotkeys.
|
|
57
|
+
*/
|
|
58
|
+
declare function isEditableTarget(node: EventTarget | null): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* @description Whether a hotkey uses no modifier at all (a bare key), which
|
|
61
|
+
* should be suppressed in editable contexts.
|
|
62
|
+
*
|
|
63
|
+
* @param hotkey - The parsed hotkey.
|
|
64
|
+
* @returns True when no modifier is required.
|
|
65
|
+
*/
|
|
66
|
+
declare function isBareKey(hotkey: Hotkey): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* @description Binds a document-level listener for one hotkey spec. Bare-key
|
|
69
|
+
* specs are suppressed while focus is in an editable context; matches call
|
|
70
|
+
* `preventDefault()` before the callback.
|
|
71
|
+
*
|
|
72
|
+
* @param spec - The hotkey spec, e.g. `"mod+k"`.
|
|
73
|
+
* @param callback - Runs on each match, receiving the keyboard event.
|
|
74
|
+
* @param options - `signal` unbinds the listener when aborted.
|
|
75
|
+
* @returns True when the spec parsed and the listener was bound.
|
|
76
|
+
*/
|
|
77
|
+
declare function bindHotkey(spec: string, callback: (event: KeyboardEvent) => void, options?: {
|
|
78
|
+
signal?: AbortSignal;
|
|
79
|
+
}): boolean;
|
|
80
|
+
export { parseHotkey, matchesHotkey, isEditableTarget, isBareKey, bindHotkey };
|
|
81
|
+
export type { Hotkey };
|
|
82
|
+
//# sourceMappingURL=hotkeys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hotkeys.d.ts","sourceRoot":"","sources":["hotkeys.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;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"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// --- Parsing ---
|
|
3
|
+
/**
|
|
4
|
+
* @description Parses a `"mod+shift+p"`-style spec into a structured hotkey.
|
|
5
|
+
*
|
|
6
|
+
* @param spec - The hotkey spec, `+`-separated, case-insensitive.
|
|
7
|
+
* @returns The parsed hotkey, or null for an empty/invalid spec.
|
|
8
|
+
*/
|
|
9
|
+
function parseHotkey(spec) {
|
|
10
|
+
const tokens = spec
|
|
11
|
+
.split("+")
|
|
12
|
+
.map((token) => token.trim().toLowerCase())
|
|
13
|
+
.filter((token) => token.length > 0);
|
|
14
|
+
if (tokens.length === 0)
|
|
15
|
+
return null;
|
|
16
|
+
const hotkey = {
|
|
17
|
+
key: "",
|
|
18
|
+
ctrl: false,
|
|
19
|
+
alt: false,
|
|
20
|
+
shift: false,
|
|
21
|
+
meta: false,
|
|
22
|
+
mod: false,
|
|
23
|
+
};
|
|
24
|
+
for (const token of tokens.slice(0, -1)) {
|
|
25
|
+
switch (token) {
|
|
26
|
+
case "mod":
|
|
27
|
+
hotkey.mod = true;
|
|
28
|
+
break;
|
|
29
|
+
case "ctrl":
|
|
30
|
+
case "control":
|
|
31
|
+
hotkey.ctrl = true;
|
|
32
|
+
break;
|
|
33
|
+
case "alt":
|
|
34
|
+
case "option":
|
|
35
|
+
hotkey.alt = true;
|
|
36
|
+
break;
|
|
37
|
+
case "shift":
|
|
38
|
+
hotkey.shift = true;
|
|
39
|
+
break;
|
|
40
|
+
case "meta":
|
|
41
|
+
case "cmd":
|
|
42
|
+
case "super":
|
|
43
|
+
hotkey.meta = true;
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
// Unknown modifier: reject rather than silently matching too much
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
hotkey.key = tokens[tokens.length - 1];
|
|
51
|
+
return hotkey;
|
|
52
|
+
}
|
|
53
|
+
// --- Matching ---
|
|
54
|
+
/**
|
|
55
|
+
* @description Whether the current platform treats Meta as the primary
|
|
56
|
+
* modifier (macOS, iOS, iPadOS).
|
|
57
|
+
*
|
|
58
|
+
* @returns True on Apple platforms.
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
function isApplePlatform() {
|
|
62
|
+
if (typeof navigator === "undefined")
|
|
63
|
+
return false;
|
|
64
|
+
return /mac|iphone|ipad|ipod/i.test(navigator.platform || navigator.userAgent);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @description Matches a keyboard event against a parsed hotkey. Modifier
|
|
68
|
+
* states must match exactly (`mod+k` does not fire on `mod+shift+k`) except
|
|
69
|
+
* that `mod` claims whichever of Meta/Control the platform assigns it.
|
|
70
|
+
*
|
|
71
|
+
* @param event - The keyboard event to test.
|
|
72
|
+
* @param hotkey - The parsed hotkey to match.
|
|
73
|
+
* @param apple - Platform override for tests; defaults to detection.
|
|
74
|
+
* @returns True when the event is exactly this hotkey.
|
|
75
|
+
*/
|
|
76
|
+
function matchesHotkey(event, hotkey, apple = isApplePlatform()) {
|
|
77
|
+
const wantMeta = hotkey.meta || (hotkey.mod && apple);
|
|
78
|
+
const wantCtrl = hotkey.ctrl || (hotkey.mod && !apple);
|
|
79
|
+
if (event.metaKey !== wantMeta)
|
|
80
|
+
return false;
|
|
81
|
+
if (event.ctrlKey !== wantCtrl)
|
|
82
|
+
return false;
|
|
83
|
+
if (event.altKey !== hotkey.alt)
|
|
84
|
+
return false;
|
|
85
|
+
if (event.shiftKey !== hotkey.shift)
|
|
86
|
+
return false;
|
|
87
|
+
return event.key.toLowerCase() === hotkey.key;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* @description Whether a node is an editable context (form field or
|
|
91
|
+
* contenteditable), where bare-key hotkeys must not fire.
|
|
92
|
+
*
|
|
93
|
+
* @param node - The event target to inspect.
|
|
94
|
+
* @returns True when typing belongs to the node, not to hotkeys.
|
|
95
|
+
*/
|
|
96
|
+
function isEditableTarget(node) {
|
|
97
|
+
if (!(node instanceof HTMLElement))
|
|
98
|
+
return false;
|
|
99
|
+
if (node.isContentEditable)
|
|
100
|
+
return true;
|
|
101
|
+
return (node instanceof HTMLInputElement ||
|
|
102
|
+
node instanceof HTMLTextAreaElement ||
|
|
103
|
+
node instanceof HTMLSelectElement);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @description Whether a hotkey uses no modifier at all (a bare key), which
|
|
107
|
+
* should be suppressed in editable contexts.
|
|
108
|
+
*
|
|
109
|
+
* @param hotkey - The parsed hotkey.
|
|
110
|
+
* @returns True when no modifier is required.
|
|
111
|
+
*/
|
|
112
|
+
function isBareKey(hotkey) {
|
|
113
|
+
return !hotkey.ctrl && !hotkey.alt && !hotkey.meta && !hotkey.mod;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @description Binds a document-level listener for one hotkey spec. Bare-key
|
|
117
|
+
* specs are suppressed while focus is in an editable context; matches call
|
|
118
|
+
* `preventDefault()` before the callback.
|
|
119
|
+
*
|
|
120
|
+
* @param spec - The hotkey spec, e.g. `"mod+k"`.
|
|
121
|
+
* @param callback - Runs on each match, receiving the keyboard event.
|
|
122
|
+
* @param options - `signal` unbinds the listener when aborted.
|
|
123
|
+
* @returns True when the spec parsed and the listener was bound.
|
|
124
|
+
*/
|
|
125
|
+
function bindHotkey(spec, callback, options = {}) {
|
|
126
|
+
const hotkey = parseHotkey(spec);
|
|
127
|
+
if (!hotkey || typeof document === "undefined")
|
|
128
|
+
return false;
|
|
129
|
+
document.addEventListener("keydown", (event) => {
|
|
130
|
+
if (event.defaultPrevented || event.repeat)
|
|
131
|
+
return;
|
|
132
|
+
if (isBareKey(hotkey) && isEditableTarget(event.target))
|
|
133
|
+
return;
|
|
134
|
+
if (!matchesHotkey(event, hotkey))
|
|
135
|
+
return;
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
callback(event);
|
|
138
|
+
}, { signal: options.signal });
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
export { parseHotkey, matchesHotkey, isEditableTarget, isBareKey, bindHotkey };
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Minimal hotkey parsing and matching for the command family.
|
|
5
|
+
* @description Turns `"mod+k"`-style specs into structured hotkeys and matches
|
|
6
|
+
* them against keyboard events. `mod` resolves to Meta on Apple platforms and
|
|
7
|
+
* Control elsewhere. Bare-key hotkeys (no modifier) are suppressed while the
|
|
8
|
+
* user types in an editable context so accelerators never eat input.
|
|
9
|
+
*
|
|
10
|
+
* This file is a deliberate seam (like `signals.ts`): the kit's needs are a
|
|
11
|
+
* parser, a matcher, and an editable-target guard, so a dependency was not
|
|
12
|
+
* worth the pinning contract; swap the internals here if a library ever
|
|
13
|
+
* earns its keep.
|
|
14
|
+
*
|
|
15
|
+
* Spec grammar: `+`-separated tokens, case-insensitive. Modifiers: `mod`,
|
|
16
|
+
* `ctrl`/`control`, `alt`/`option`, `shift`, `meta`/`cmd`/`super`. The final
|
|
17
|
+
* token is the key, compared against `KeyboardEvent.key` (single letters
|
|
18
|
+
* case-insensitively, so `mod+K` and `mod+k` are the same hotkey).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// --- Types ---
|
|
22
|
+
|
|
23
|
+
/** A parsed hotkey: required modifiers plus the terminal key. */
|
|
24
|
+
interface Hotkey {
|
|
25
|
+
/** Required `KeyboardEvent.key`, lowercased for single characters. */
|
|
26
|
+
key: string;
|
|
27
|
+
/** Requires Control. */
|
|
28
|
+
ctrl: boolean;
|
|
29
|
+
/** Requires Alt/Option. */
|
|
30
|
+
alt: boolean;
|
|
31
|
+
/** Requires Shift. */
|
|
32
|
+
shift: boolean;
|
|
33
|
+
/** Requires Meta/Command. */
|
|
34
|
+
meta: boolean;
|
|
35
|
+
/** Requires the platform primary modifier (Meta on Apple, Control elsewhere). */
|
|
36
|
+
mod: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// --- Parsing ---
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @description Parses a `"mod+shift+p"`-style spec into a structured hotkey.
|
|
43
|
+
*
|
|
44
|
+
* @param spec - The hotkey spec, `+`-separated, case-insensitive.
|
|
45
|
+
* @returns The parsed hotkey, or null for an empty/invalid spec.
|
|
46
|
+
*/
|
|
47
|
+
function parseHotkey(spec: string): Hotkey | null {
|
|
48
|
+
const tokens = spec
|
|
49
|
+
.split("+")
|
|
50
|
+
.map((token) => token.trim().toLowerCase())
|
|
51
|
+
.filter((token) => token.length > 0);
|
|
52
|
+
if (tokens.length === 0) return null;
|
|
53
|
+
|
|
54
|
+
const hotkey: Hotkey = {
|
|
55
|
+
key: "",
|
|
56
|
+
ctrl: false,
|
|
57
|
+
alt: false,
|
|
58
|
+
shift: false,
|
|
59
|
+
meta: false,
|
|
60
|
+
mod: false,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
for (const token of tokens.slice(0, -1)) {
|
|
64
|
+
switch (token) {
|
|
65
|
+
case "mod":
|
|
66
|
+
hotkey.mod = true;
|
|
67
|
+
break;
|
|
68
|
+
case "ctrl":
|
|
69
|
+
case "control":
|
|
70
|
+
hotkey.ctrl = true;
|
|
71
|
+
break;
|
|
72
|
+
case "alt":
|
|
73
|
+
case "option":
|
|
74
|
+
hotkey.alt = true;
|
|
75
|
+
break;
|
|
76
|
+
case "shift":
|
|
77
|
+
hotkey.shift = true;
|
|
78
|
+
break;
|
|
79
|
+
case "meta":
|
|
80
|
+
case "cmd":
|
|
81
|
+
case "super":
|
|
82
|
+
hotkey.meta = true;
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
// Unknown modifier: reject rather than silently matching too much
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
hotkey.key = tokens[tokens.length - 1];
|
|
91
|
+
return hotkey;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// --- Matching ---
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @description Whether the current platform treats Meta as the primary
|
|
98
|
+
* modifier (macOS, iOS, iPadOS).
|
|
99
|
+
*
|
|
100
|
+
* @returns True on Apple platforms.
|
|
101
|
+
* @private
|
|
102
|
+
*/
|
|
103
|
+
function isApplePlatform(): boolean {
|
|
104
|
+
if (typeof navigator === "undefined") return false;
|
|
105
|
+
return /mac|iphone|ipad|ipod/i.test(navigator.platform || navigator.userAgent);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @description Matches a keyboard event against a parsed hotkey. Modifier
|
|
110
|
+
* states must match exactly (`mod+k` does not fire on `mod+shift+k`) except
|
|
111
|
+
* that `mod` claims whichever of Meta/Control the platform assigns it.
|
|
112
|
+
*
|
|
113
|
+
* @param event - The keyboard event to test.
|
|
114
|
+
* @param hotkey - The parsed hotkey to match.
|
|
115
|
+
* @param apple - Platform override for tests; defaults to detection.
|
|
116
|
+
* @returns True when the event is exactly this hotkey.
|
|
117
|
+
*/
|
|
118
|
+
function matchesHotkey(
|
|
119
|
+
event: KeyboardEvent,
|
|
120
|
+
hotkey: Hotkey,
|
|
121
|
+
apple: boolean = isApplePlatform(),
|
|
122
|
+
): boolean {
|
|
123
|
+
const wantMeta = hotkey.meta || (hotkey.mod && apple);
|
|
124
|
+
const wantCtrl = hotkey.ctrl || (hotkey.mod && !apple);
|
|
125
|
+
|
|
126
|
+
if (event.metaKey !== wantMeta) return false;
|
|
127
|
+
if (event.ctrlKey !== wantCtrl) return false;
|
|
128
|
+
if (event.altKey !== hotkey.alt) return false;
|
|
129
|
+
if (event.shiftKey !== hotkey.shift) return false;
|
|
130
|
+
|
|
131
|
+
return event.key.toLowerCase() === hotkey.key;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @description Whether a node is an editable context (form field or
|
|
136
|
+
* contenteditable), where bare-key hotkeys must not fire.
|
|
137
|
+
*
|
|
138
|
+
* @param node - The event target to inspect.
|
|
139
|
+
* @returns True when typing belongs to the node, not to hotkeys.
|
|
140
|
+
*/
|
|
141
|
+
function isEditableTarget(node: EventTarget | null): boolean {
|
|
142
|
+
if (!(node instanceof HTMLElement)) return false;
|
|
143
|
+
if (node.isContentEditable) return true;
|
|
144
|
+
return (
|
|
145
|
+
node instanceof HTMLInputElement ||
|
|
146
|
+
node instanceof HTMLTextAreaElement ||
|
|
147
|
+
node instanceof HTMLSelectElement
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @description Whether a hotkey uses no modifier at all (a bare key), which
|
|
153
|
+
* should be suppressed in editable contexts.
|
|
154
|
+
*
|
|
155
|
+
* @param hotkey - The parsed hotkey.
|
|
156
|
+
* @returns True when no modifier is required.
|
|
157
|
+
*/
|
|
158
|
+
function isBareKey(hotkey: Hotkey): boolean {
|
|
159
|
+
return !hotkey.ctrl && !hotkey.alt && !hotkey.meta && !hotkey.mod;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @description Binds a document-level listener for one hotkey spec. Bare-key
|
|
164
|
+
* specs are suppressed while focus is in an editable context; matches call
|
|
165
|
+
* `preventDefault()` before the callback.
|
|
166
|
+
*
|
|
167
|
+
* @param spec - The hotkey spec, e.g. `"mod+k"`.
|
|
168
|
+
* @param callback - Runs on each match, receiving the keyboard event.
|
|
169
|
+
* @param options - `signal` unbinds the listener when aborted.
|
|
170
|
+
* @returns True when the spec parsed and the listener was bound.
|
|
171
|
+
*/
|
|
172
|
+
function bindHotkey(
|
|
173
|
+
spec: string,
|
|
174
|
+
callback: (event: KeyboardEvent) => void,
|
|
175
|
+
options: { signal?: AbortSignal } = {},
|
|
176
|
+
): boolean {
|
|
177
|
+
const hotkey = parseHotkey(spec);
|
|
178
|
+
if (!hotkey || typeof document === "undefined") return false;
|
|
179
|
+
|
|
180
|
+
document.addEventListener(
|
|
181
|
+
"keydown",
|
|
182
|
+
(event) => {
|
|
183
|
+
if (event.defaultPrevented || event.repeat) return;
|
|
184
|
+
if (isBareKey(hotkey) && isEditableTarget(event.target)) return;
|
|
185
|
+
if (!matchesHotkey(event, hotkey)) return;
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
callback(event);
|
|
188
|
+
},
|
|
189
|
+
{ signal: options.signal },
|
|
190
|
+
);
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export { parseHotkey, matchesHotkey, isEditableTarget, isBareKey, bindHotkey };
|
|
195
|
+
export type { Hotkey };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["navigation.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { refreshAll } from "./zazz-element.js";
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview SPA-like navigation via the Navigation API.
|
|
5
|
+
* @description Intercepts same-origin navigations and swaps `<main>` content
|
|
6
|
+
* without a full page reload. The browser still manages the URL and history
|
|
7
|
+
* stack; one `navigate` listener handles link clicks, back/forward, and
|
|
8
|
+
* programmatic navigations.
|
|
9
|
+
*
|
|
10
|
+
* A same-document swap is only valid when the source and destination share the
|
|
11
|
+
* same layout (retail → retail). Each layout stamps its `<main>` with
|
|
12
|
+
* `data-layout` (retail | portal | utility); when those differ — e.g. a retail
|
|
13
|
+
* page → the chrome-less utility login — the header/footer must change too, so
|
|
14
|
+
* we hand the navigation back to the browser for a full load instead of
|
|
15
|
+
* swapping `<main>` in isolation (which would leave the wrong chrome behind).
|
|
16
|
+
*
|
|
17
|
+
* Persistent overlays — e.g. the `<ui-toaster>` toaster — must live outside
|
|
18
|
+
* `<main>` (end of `<body>`): the swap replaces `<main>` wholesale, so anything
|
|
19
|
+
* inside it is destroyed mid-navigation. Placed outside, an active toast stack
|
|
20
|
+
* rides through the swap untouched; its exclusion from the view-transition
|
|
21
|
+
* repaint is CSS-side (`view-transition-name: toaster` in _toaster.css, frozen
|
|
22
|
+
* group in _view-transitions.css).
|
|
23
|
+
*
|
|
24
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Navigation_API
|
|
25
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/NavigateEvent/scroll
|
|
26
|
+
*/
|
|
27
|
+
if ("navigation" in window) {
|
|
28
|
+
/**
|
|
29
|
+
* URL we've decided to hand back to the browser for a full load. The
|
|
30
|
+
* `navigate` listener checks this first and bails out (no intercept) so the
|
|
31
|
+
* browser performs a real navigation. Without it, `location.assign()` from
|
|
32
|
+
* inside the handler would re-enter this same listener, re-intercept, fail to
|
|
33
|
+
* find a usable `<main>` again, and loop forever. Cleared as soon as it's seen.
|
|
34
|
+
*/
|
|
35
|
+
let bypassUrl = null;
|
|
36
|
+
window.navigation.addEventListener("navigate", (e) => {
|
|
37
|
+
// A navigation we already chose to full-load: let the browser handle it.
|
|
38
|
+
if (bypassUrl !== null && e.destination.url === bypassUrl) {
|
|
39
|
+
bypassUrl = null;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (!e.canIntercept ||
|
|
43
|
+
e.hashChange ||
|
|
44
|
+
e.downloadRequest !== null ||
|
|
45
|
+
e.formData !== null ||
|
|
46
|
+
!isSameOrigin(e.destination.url)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
e.intercept({
|
|
50
|
+
async handler() {
|
|
51
|
+
let doc;
|
|
52
|
+
try {
|
|
53
|
+
const res = await fetch(e.destination.url);
|
|
54
|
+
if (!res.ok)
|
|
55
|
+
throw new Error(res.statusText);
|
|
56
|
+
doc = new DOMParser().parseFromString(await res.text(), "text/html");
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
fullReload(e.destination.url); // Network/HTTP failure: full load.
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const newMain = doc.querySelector("main");
|
|
63
|
+
const currentMain = document.querySelector("main");
|
|
64
|
+
// Bail to a full load when we can't safely swap in place:
|
|
65
|
+
// - either page lacks <main> (e.g. a legacy / non-Zazz page), or
|
|
66
|
+
// - the layout differs (retail ↔ portal ↔ utility), so the header and
|
|
67
|
+
// footer chrome — which lives outside <main> — must change too.
|
|
68
|
+
if (!(newMain instanceof HTMLElement) ||
|
|
69
|
+
!(currentMain instanceof HTMLElement) ||
|
|
70
|
+
newMain.dataset.layout !== currentMain.dataset.layout) {
|
|
71
|
+
fullReload(e.destination.url);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const updateDOM = () => {
|
|
75
|
+
currentMain.replaceWith(newMain);
|
|
76
|
+
document.title = doc.title;
|
|
77
|
+
// Restore scroll while the new snapshot is captured so the transition
|
|
78
|
+
// animates from the correct position instead of jumping afterwards.
|
|
79
|
+
e.scroll();
|
|
80
|
+
};
|
|
81
|
+
if (document.startViewTransition) {
|
|
82
|
+
await document.startViewTransition(updateDOM).finished;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
updateDOM();
|
|
86
|
+
}
|
|
87
|
+
// Re-scan the swapped-in content: every module that owns page-scoped
|
|
88
|
+
// work registered a refresh hook (reveal, class-form carousels, …) —
|
|
89
|
+
// this module never names a component. Custom elements need nothing:
|
|
90
|
+
// their lifecycle callbacks ride the swap natively.
|
|
91
|
+
refreshAll(newMain);
|
|
92
|
+
routeFocus(newMain);
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
/**
|
|
97
|
+
* @description Hands a navigation back to the browser for a full page load.
|
|
98
|
+
* Records the URL so the re-entrant `navigate` event skips interception
|
|
99
|
+
* instead of looping.
|
|
100
|
+
*
|
|
101
|
+
* @param url - The destination URL to load normally.
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
104
|
+
function fullReload(url) {
|
|
105
|
+
bypassUrl = url;
|
|
106
|
+
location.assign(url);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* @description Routes focus to the primary heading in swapped main content.
|
|
110
|
+
*
|
|
111
|
+
* @param main - The newly inserted `<main>` element.
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
function routeFocus(main) {
|
|
115
|
+
const target = main.querySelector("h1") ?? main;
|
|
116
|
+
if (!(target instanceof HTMLElement))
|
|
117
|
+
return;
|
|
118
|
+
if (!target.hasAttribute("tabindex")) {
|
|
119
|
+
target.tabIndex = -1;
|
|
120
|
+
}
|
|
121
|
+
target.focus({ preventScroll: true });
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @description Checks whether a URL shares the current document origin.
|
|
125
|
+
*
|
|
126
|
+
* @param url - The URL to compare.
|
|
127
|
+
* @returns True when the URL origin matches `location.origin`.
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
function isSameOrigin(url) {
|
|
131
|
+
return new URL(url, location.href).origin === location.origin;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
console.warn("Navigation API not supported. That's okay, we'll just use a full page reload.");
|
|
136
|
+
}
|