@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,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { refreshAll } from "./zazz-element.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview SPA-like navigation via the Navigation API.
|
|
7
|
+
* @description Intercepts same-origin navigations and swaps `<main>` content
|
|
8
|
+
* without a full page reload. The browser still manages the URL and history
|
|
9
|
+
* stack; one `navigate` listener handles link clicks, back/forward, and
|
|
10
|
+
* programmatic navigations.
|
|
11
|
+
*
|
|
12
|
+
* A same-document swap is only valid when the source and destination share the
|
|
13
|
+
* same layout (retail → retail). Each layout stamps its `<main>` with
|
|
14
|
+
* `data-layout` (retail | portal | utility); when those differ — e.g. a retail
|
|
15
|
+
* page → the chrome-less utility login — the header/footer must change too, so
|
|
16
|
+
* we hand the navigation back to the browser for a full load instead of
|
|
17
|
+
* swapping `<main>` in isolation (which would leave the wrong chrome behind).
|
|
18
|
+
*
|
|
19
|
+
* Persistent overlays — e.g. the `<ui-toaster>` toaster — must live outside
|
|
20
|
+
* `<main>` (end of `<body>`): the swap replaces `<main>` wholesale, so anything
|
|
21
|
+
* inside it is destroyed mid-navigation. Placed outside, an active toast stack
|
|
22
|
+
* rides through the swap untouched; its exclusion from the view-transition
|
|
23
|
+
* repaint is CSS-side (`view-transition-name: toaster` in _toaster.css, frozen
|
|
24
|
+
* group in _view-transitions.css).
|
|
25
|
+
*
|
|
26
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Navigation_API
|
|
27
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/NavigateEvent/scroll
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
if ("navigation" in window) {
|
|
31
|
+
/**
|
|
32
|
+
* URL we've decided to hand back to the browser for a full load. The
|
|
33
|
+
* `navigate` listener checks this first and bails out (no intercept) so the
|
|
34
|
+
* browser performs a real navigation. Without it, `location.assign()` from
|
|
35
|
+
* inside the handler would re-enter this same listener, re-intercept, fail to
|
|
36
|
+
* find a usable `<main>` again, and loop forever. Cleared as soon as it's seen.
|
|
37
|
+
*/
|
|
38
|
+
let bypassUrl: string | null = null;
|
|
39
|
+
|
|
40
|
+
window.navigation.addEventListener("navigate", (e) => {
|
|
41
|
+
// A navigation we already chose to full-load: let the browser handle it.
|
|
42
|
+
if (bypassUrl !== null && e.destination.url === bypassUrl) {
|
|
43
|
+
bypassUrl = null;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (
|
|
48
|
+
!e.canIntercept ||
|
|
49
|
+
e.hashChange ||
|
|
50
|
+
e.downloadRequest !== null ||
|
|
51
|
+
e.formData !== null ||
|
|
52
|
+
!isSameOrigin(e.destination.url)
|
|
53
|
+
) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
e.intercept({
|
|
58
|
+
async handler() {
|
|
59
|
+
let doc: Document;
|
|
60
|
+
try {
|
|
61
|
+
const res = await fetch(e.destination.url);
|
|
62
|
+
if (!res.ok) throw new Error(res.statusText);
|
|
63
|
+
doc = new DOMParser().parseFromString(await res.text(), "text/html");
|
|
64
|
+
} catch {
|
|
65
|
+
fullReload(e.destination.url); // Network/HTTP failure: full load.
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const newMain = doc.querySelector("main");
|
|
70
|
+
const currentMain = document.querySelector("main");
|
|
71
|
+
|
|
72
|
+
// Bail to a full load when we can't safely swap in place:
|
|
73
|
+
// - either page lacks <main> (e.g. a legacy / non-Zazz page), or
|
|
74
|
+
// - the layout differs (retail ↔ portal ↔ utility), so the header and
|
|
75
|
+
// footer chrome — which lives outside <main> — must change too.
|
|
76
|
+
if (
|
|
77
|
+
!(newMain instanceof HTMLElement) ||
|
|
78
|
+
!(currentMain instanceof HTMLElement) ||
|
|
79
|
+
newMain.dataset.layout !== currentMain.dataset.layout
|
|
80
|
+
) {
|
|
81
|
+
fullReload(e.destination.url);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const updateDOM = () => {
|
|
86
|
+
currentMain.replaceWith(newMain);
|
|
87
|
+
document.title = doc.title;
|
|
88
|
+
// Restore scroll while the new snapshot is captured so the transition
|
|
89
|
+
// animates from the correct position instead of jumping afterwards.
|
|
90
|
+
e.scroll();
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
if (document.startViewTransition) {
|
|
94
|
+
await document.startViewTransition(updateDOM).finished;
|
|
95
|
+
} else {
|
|
96
|
+
updateDOM();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Re-scan the swapped-in content: every module that owns page-scoped
|
|
100
|
+
// work registered a refresh hook (reveal, class-form carousels, …) —
|
|
101
|
+
// this module never names a component. Custom elements need nothing:
|
|
102
|
+
// their lifecycle callbacks ride the swap natively.
|
|
103
|
+
refreshAll(newMain);
|
|
104
|
+
routeFocus(newMain);
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @description Hands a navigation back to the browser for a full page load.
|
|
111
|
+
* Records the URL so the re-entrant `navigate` event skips interception
|
|
112
|
+
* instead of looping.
|
|
113
|
+
*
|
|
114
|
+
* @param url - The destination URL to load normally.
|
|
115
|
+
* @private
|
|
116
|
+
*/
|
|
117
|
+
function fullReload(url: string): void {
|
|
118
|
+
bypassUrl = url;
|
|
119
|
+
location.assign(url);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @description Routes focus to the primary heading in swapped main content.
|
|
124
|
+
*
|
|
125
|
+
* @param main - The newly inserted `<main>` element.
|
|
126
|
+
* @private
|
|
127
|
+
*/
|
|
128
|
+
function routeFocus(main: HTMLElement): void {
|
|
129
|
+
const target = main.querySelector("h1") ?? main;
|
|
130
|
+
if (!(target instanceof HTMLElement)) return;
|
|
131
|
+
|
|
132
|
+
if (!target.hasAttribute("tabindex")) {
|
|
133
|
+
target.tabIndex = -1;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
target.focus({ preventScroll: true });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @description Checks whether a URL shares the current document origin.
|
|
141
|
+
*
|
|
142
|
+
* @param url - The URL to compare.
|
|
143
|
+
* @returns True when the URL origin matches `location.origin`.
|
|
144
|
+
* @private
|
|
145
|
+
*/
|
|
146
|
+
function isSameOrigin(url: string): boolean {
|
|
147
|
+
return new URL(url, location.href).origin === location.origin;
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
console.warn("Navigation API not supported. That's okay, we'll just use a full page reload.");
|
|
151
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
interface RevealConfig {
|
|
2
|
+
/** Margin around the root (viewport) for IntersectionObserver. */
|
|
3
|
+
margin: string;
|
|
4
|
+
/** Visibility threshold (0–1) to trigger animations. */
|
|
5
|
+
threshold: number;
|
|
6
|
+
/** Default animation duration (ms number or CSS time string). */
|
|
7
|
+
duration: number | string;
|
|
8
|
+
/** Default animation timing function. */
|
|
9
|
+
ease: string;
|
|
10
|
+
/** Default base animation delay in milliseconds. */
|
|
11
|
+
wait: number;
|
|
12
|
+
/** Default translation distance for slide animations. */
|
|
13
|
+
distance: string;
|
|
14
|
+
/** Default delay between staggered elements in milliseconds. */
|
|
15
|
+
step: number;
|
|
16
|
+
/** Scale factor for grow animations (< 1). */
|
|
17
|
+
grow: number;
|
|
18
|
+
/** Scale factor for shrink animations (> 1). */
|
|
19
|
+
shrink: number;
|
|
20
|
+
}
|
|
21
|
+
interface RevealOptions {
|
|
22
|
+
/** Configuration options for the animation system. */
|
|
23
|
+
config?: Partial<RevealConfig>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @class
|
|
27
|
+
* @description Initializes viewport entry animations.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const reveal = new Reveal();
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const reveal = new Reveal({
|
|
34
|
+
* config: {
|
|
35
|
+
* duration: 400,
|
|
36
|
+
* ease: "ease-in-out",
|
|
37
|
+
* threshold: 0.3,
|
|
38
|
+
* margin: "100px",
|
|
39
|
+
* step: 40,
|
|
40
|
+
* },
|
|
41
|
+
* });
|
|
42
|
+
*/
|
|
43
|
+
declare class Reveal {
|
|
44
|
+
#private;
|
|
45
|
+
/**
|
|
46
|
+
* @description Prevents automatic initialization on DOM ready.
|
|
47
|
+
* Assigned below (browser environments only).
|
|
48
|
+
*/
|
|
49
|
+
static disableAutoInit: () => void;
|
|
50
|
+
/**
|
|
51
|
+
* @description Returns the auto-initialized Reveal instance, if any.
|
|
52
|
+
* Assigned below (browser environments only).
|
|
53
|
+
*/
|
|
54
|
+
static getAutoInstance: () => Reveal | null;
|
|
55
|
+
static get defaultConfig(): RevealConfig;
|
|
56
|
+
config: RevealConfig;
|
|
57
|
+
/**
|
|
58
|
+
* @description Creates a new Reveal instance.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Configuration options.
|
|
61
|
+
*/
|
|
62
|
+
constructor(options?: RevealOptions);
|
|
63
|
+
/**
|
|
64
|
+
* @description Initializes the animation system by setting global CSS variables
|
|
65
|
+
* and configuring all animated elements.
|
|
66
|
+
*/
|
|
67
|
+
init(): void;
|
|
68
|
+
/**
|
|
69
|
+
* @description Reinitializes the animation system after dynamically adding elements.
|
|
70
|
+
*
|
|
71
|
+
* Disconnects old observers and rescans the document.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* container.innerHTML = newContent;
|
|
75
|
+
* reveal.refresh();
|
|
76
|
+
*/
|
|
77
|
+
refresh(): void;
|
|
78
|
+
}
|
|
79
|
+
export { Reveal };
|
|
80
|
+
//# sourceMappingURL=reveal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reveal.d.ts","sourceRoot":"","sources":["reveal.ts"],"names":[],"mappings":"AAIA,UAAU,YAAY;IACpB,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,aAAa;IACrB,sDAAsD;IACtD,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;CAChC;AAkDD;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAM,MAAM;;IACV;;;OAGG;IACH,OAAe,eAAe,EAAE,MAAM,IAAI,CAAC;IAE3C;;;OAGG;IACH,OAAe,eAAe,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAmBpD,MAAM,KAAK,aAAa,IAAI,YAAY,CAEvC;IAID,MAAM,EAAE,YAAY,CAAC;IAErB;;;;OAIG;IACH,YAAY,OAAO,GAAE,aAAkB,EAGtC;IA2JD;;;OAGG;IACH,IAAI,IAAI,IAAI,CAmBX;IAED;;;;;;;;OAQG;IACH,OAAO,IAAI,IAAI,CAEd;CACF;AA4CD,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { registerRefresh } from "./zazz-element.js";
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Scroll-based reveal animations.
|
|
5
|
+
* @description A lightweight, configurable animation system for scroll-based
|
|
6
|
+
* reveals and staggered animations, focused on viewport entry.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* <!-- Single element -->
|
|
10
|
+
* <div data-reveal="slide-up" data-reveal-duration="300">Content</div>
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* <!-- Stagger group (direct children are animated) -->
|
|
14
|
+
* <div data-reveal-each="fade" data-reveal-step="100">
|
|
15
|
+
* <div>Item 1</div>
|
|
16
|
+
* <div>Item 2</div>
|
|
17
|
+
* </div>
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* @description Reads a CSS custom property from `:root` computed styles.
|
|
21
|
+
* @param name - Custom property name (e.g. "--ui-reveal-global-duration").
|
|
22
|
+
* @returns Trimmed value, or "" when unset.
|
|
23
|
+
*/
|
|
24
|
+
function getRootCssVar(name) {
|
|
25
|
+
return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @description Whether the engine computes stagger delays natively: reveal.css
|
|
29
|
+
* derives each child's `--ui-reveal-wait` from `sibling-index()`. Where
|
|
30
|
+
* unsupported (Firefox), `#configureStaggerGroup` falls back to writing a
|
|
31
|
+
* per-child `--ui-reveal-wait` inline.
|
|
32
|
+
*/
|
|
33
|
+
const supportsSiblingIndex = typeof CSS !== "undefined" && CSS.supports("top", "calc(sibling-index() * 1px)");
|
|
34
|
+
/**
|
|
35
|
+
* @description Parses a CSS time value into milliseconds.
|
|
36
|
+
* @param value - CSS time string (e.g. "300ms", "0.5s") or bare number string.
|
|
37
|
+
* @returns Duration in milliseconds.
|
|
38
|
+
*/
|
|
39
|
+
function parseCssTimeMs(value) {
|
|
40
|
+
const str = value.trim();
|
|
41
|
+
if (!str)
|
|
42
|
+
return 0;
|
|
43
|
+
if (/^-?\d*\.?\d+ms$/.test(str))
|
|
44
|
+
return parseFloat(str);
|
|
45
|
+
if (/^-?\d*\.?\d+s$/.test(str))
|
|
46
|
+
return parseFloat(str) * 1000;
|
|
47
|
+
return parseInt(str, 10) || 0;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @class
|
|
51
|
+
* @description Initializes viewport entry animations.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const reveal = new Reveal();
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* const reveal = new Reveal({
|
|
58
|
+
* config: {
|
|
59
|
+
* duration: 400,
|
|
60
|
+
* ease: "ease-in-out",
|
|
61
|
+
* threshold: 0.3,
|
|
62
|
+
* margin: "100px",
|
|
63
|
+
* step: 40,
|
|
64
|
+
* },
|
|
65
|
+
* });
|
|
66
|
+
*/
|
|
67
|
+
class Reveal {
|
|
68
|
+
/**
|
|
69
|
+
* @description Default config from `--ui-reveal-global-*` tokens in `_reveal.css`.
|
|
70
|
+
*/
|
|
71
|
+
static #readDefaultConfig() {
|
|
72
|
+
return {
|
|
73
|
+
margin: "0px",
|
|
74
|
+
threshold: 0.2,
|
|
75
|
+
duration: getRootCssVar("--ui-reveal-global-duration") || "400ms",
|
|
76
|
+
ease: getRootCssVar("--ui-reveal-global-ease") || "cubic-bezier(0.4, 0, 0.2, 1)",
|
|
77
|
+
wait: parseCssTimeMs(getRootCssVar("--ui-reveal-global-wait")),
|
|
78
|
+
distance: getRootCssVar("--ui-reveal-global-distance") || "1rem",
|
|
79
|
+
step: 80,
|
|
80
|
+
grow: parseFloat(getRootCssVar("--ui-reveal-global-grow")) || 0.97,
|
|
81
|
+
shrink: parseFloat(getRootCssVar("--ui-reveal-global-shrink")) || 1.03,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
static get defaultConfig() {
|
|
85
|
+
return Reveal.#readDefaultConfig();
|
|
86
|
+
}
|
|
87
|
+
#observers = new Map();
|
|
88
|
+
config;
|
|
89
|
+
/**
|
|
90
|
+
* @description Creates a new Reveal instance.
|
|
91
|
+
*
|
|
92
|
+
* @param options - Configuration options.
|
|
93
|
+
*/
|
|
94
|
+
constructor(options = {}) {
|
|
95
|
+
this.config = { ...Reveal.defaultConfig, ...options.config };
|
|
96
|
+
this.init();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @description Gets or creates an IntersectionObserver for a given set of options.
|
|
100
|
+
*
|
|
101
|
+
* @param options - Observer options.
|
|
102
|
+
* @returns The observer instance.
|
|
103
|
+
*/
|
|
104
|
+
#getObserver(options) {
|
|
105
|
+
const optionsKey = JSON.stringify(options);
|
|
106
|
+
let observer = this.#observers.get(optionsKey);
|
|
107
|
+
if (!observer) {
|
|
108
|
+
observer = new IntersectionObserver((entries, obs) => {
|
|
109
|
+
entries.forEach((entry) => {
|
|
110
|
+
if (entry.isIntersecting) {
|
|
111
|
+
entry.target.classList.add("in-viewport");
|
|
112
|
+
obs.unobserve(entry.target);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}, options);
|
|
116
|
+
this.#observers.set(optionsKey, observer);
|
|
117
|
+
}
|
|
118
|
+
return observer;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @description Gets IntersectionObserver options for an element.
|
|
122
|
+
*
|
|
123
|
+
* @param element - The element to get options for.
|
|
124
|
+
* @returns Observer configuration options.
|
|
125
|
+
*/
|
|
126
|
+
#getElementObserverOptions(element) {
|
|
127
|
+
const margin = element.dataset.revealMargin || this.config.margin;
|
|
128
|
+
const threshold = parseFloat(element.dataset.revealThreshold || this.config.threshold.toString());
|
|
129
|
+
return {
|
|
130
|
+
rootMargin: margin,
|
|
131
|
+
threshold: Math.min(Math.max(threshold, 0), 1),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* @description Normalizes a duration to a CSS time value without duplicating units.
|
|
136
|
+
*
|
|
137
|
+
* @param value - Milliseconds as a number, or a CSS time string.
|
|
138
|
+
* @returns A CSS time value (e.g. "300ms", "0.333s").
|
|
139
|
+
*/
|
|
140
|
+
#formatTime(value) {
|
|
141
|
+
const str = value.toString().trim();
|
|
142
|
+
if (/^-?\d*\.?\d+(ms|s)$/.test(str))
|
|
143
|
+
return str;
|
|
144
|
+
return `${Math.max(0, parseInt(str, 10) || 0)}ms`;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @description Sets CSS custom properties on an element when a value is provided.
|
|
148
|
+
*
|
|
149
|
+
* @param element - The element to set properties on.
|
|
150
|
+
* @param properties - CSS custom properties to set.
|
|
151
|
+
*/
|
|
152
|
+
#setRevealProperties(element, properties) {
|
|
153
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
154
|
+
if (value !== null && value !== undefined) {
|
|
155
|
+
element.style.setProperty(key, value.toString());
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* @description Configures stagger animation properties and observes child elements.
|
|
161
|
+
*
|
|
162
|
+
* The stagger delay (`base + step × position`) is computed natively where
|
|
163
|
+
* possible: the group carries `--ui-reveal-stagger-base`/`--ui-reveal-stagger-step`
|
|
164
|
+
* and each child derives its own `--ui-reveal-wait` via `sibling-index()` in
|
|
165
|
+
* reveal.css (reversed groups count from the end via `sibling-count()`).
|
|
166
|
+
* Where unsupported (Firefox), the same math runs here and lands as a
|
|
167
|
+
* per-child inline `--ui-reveal-wait`.
|
|
168
|
+
*
|
|
169
|
+
* @param groupElement - The parent stagger container.
|
|
170
|
+
*/
|
|
171
|
+
#configureStaggerGroup(groupElement) {
|
|
172
|
+
const dataset = groupElement.dataset;
|
|
173
|
+
const groupOptions = this.#getElementObserverOptions(groupElement);
|
|
174
|
+
const groupObserver = this.#getObserver(groupOptions);
|
|
175
|
+
const groupProps = {
|
|
176
|
+
step: Math.max(0, parseInt(dataset.revealStep || this.config.step.toString(), 10) || 0),
|
|
177
|
+
duration: dataset.revealDuration
|
|
178
|
+
? Math.max(0, parseInt(dataset.revealDuration, 10) || 0)
|
|
179
|
+
: this.config.duration,
|
|
180
|
+
ease: dataset.revealEase || this.config.ease,
|
|
181
|
+
baseWait: Math.max(0, parseInt(dataset.revealWait || this.config.wait.toString(), 10) || 0),
|
|
182
|
+
distance: dataset.revealDistance || this.config.distance,
|
|
183
|
+
order: dataset.revealOrder,
|
|
184
|
+
};
|
|
185
|
+
const childrenArray = Array.from(groupElement.children);
|
|
186
|
+
const sequence = groupProps.order === "reversed" ? childrenArray.reverse() : childrenArray;
|
|
187
|
+
if (supportsSiblingIndex) {
|
|
188
|
+
this.#setRevealProperties(groupElement, {
|
|
189
|
+
"--ui-reveal-stagger-base": `${groupProps.baseWait}ms`,
|
|
190
|
+
"--ui-reveal-stagger-step": `${groupProps.step}ms`,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
sequence.forEach((child, i) => {
|
|
194
|
+
if (!(child instanceof HTMLElement))
|
|
195
|
+
return;
|
|
196
|
+
this.#setRevealProperties(child, {
|
|
197
|
+
"--ui-reveal-duration": this.#formatTime(groupProps.duration),
|
|
198
|
+
"--ui-reveal-ease": groupProps.ease,
|
|
199
|
+
// Fallback only: natively each child computes this in reveal.css.
|
|
200
|
+
"--ui-reveal-wait": supportsSiblingIndex
|
|
201
|
+
? null
|
|
202
|
+
: `${groupProps.baseWait + groupProps.step * i}ms`,
|
|
203
|
+
"--ui-reveal-distance": groupProps.distance,
|
|
204
|
+
"--ui-reveal-scale": dataset.revealScale || null,
|
|
205
|
+
});
|
|
206
|
+
groupObserver.observe(child);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* @description Configures animation properties for a single element and observes it.
|
|
211
|
+
*
|
|
212
|
+
* @param element - The element to configure and observe.
|
|
213
|
+
*/
|
|
214
|
+
#configureSingleElement(element) {
|
|
215
|
+
const dataset = element.dataset;
|
|
216
|
+
const elementOptions = this.#getElementObserverOptions(element);
|
|
217
|
+
const elementObserver = this.#getObserver(elementOptions);
|
|
218
|
+
const elementDuration = dataset.revealDuration
|
|
219
|
+
? Math.max(0, parseInt(dataset.revealDuration, 10) || 0)
|
|
220
|
+
: null;
|
|
221
|
+
const elementWait = dataset.revealWait
|
|
222
|
+
? Math.max(0, parseInt(dataset.revealWait, 10) || 0)
|
|
223
|
+
: null;
|
|
224
|
+
this.#setRevealProperties(element, {
|
|
225
|
+
"--ui-reveal-duration": elementDuration !== null ? this.#formatTime(elementDuration) : null,
|
|
226
|
+
"--ui-reveal-wait": elementWait !== null ? this.#formatTime(elementWait) : null,
|
|
227
|
+
"--ui-reveal-ease": dataset.revealEase || null,
|
|
228
|
+
"--ui-reveal-distance": dataset.revealDistance || null,
|
|
229
|
+
"--ui-reveal-scale": dataset.revealScale || null,
|
|
230
|
+
});
|
|
231
|
+
elementObserver.observe(element);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* @description Initializes the animation system by setting global CSS variables
|
|
235
|
+
* and configuring all animated elements.
|
|
236
|
+
*/
|
|
237
|
+
init() {
|
|
238
|
+
this.#observers.forEach((observer) => observer.disconnect());
|
|
239
|
+
this.#observers.clear();
|
|
240
|
+
const rootStyle = document.documentElement.style;
|
|
241
|
+
rootStyle.setProperty("--ui-reveal-global-duration", this.#formatTime(this.config.duration));
|
|
242
|
+
rootStyle.setProperty("--ui-reveal-global-ease", this.config.ease);
|
|
243
|
+
rootStyle.setProperty("--ui-reveal-global-wait", this.#formatTime(this.config.wait));
|
|
244
|
+
rootStyle.setProperty("--ui-reveal-global-distance", this.config.distance);
|
|
245
|
+
rootStyle.setProperty("--ui-reveal-global-grow", this.config.grow.toString());
|
|
246
|
+
rootStyle.setProperty("--ui-reveal-global-shrink", this.config.shrink.toString());
|
|
247
|
+
document.querySelectorAll("[data-reveal]").forEach((element) => {
|
|
248
|
+
if (element instanceof HTMLElement)
|
|
249
|
+
this.#configureSingleElement(element);
|
|
250
|
+
});
|
|
251
|
+
document.querySelectorAll("[data-reveal-each]").forEach((group) => {
|
|
252
|
+
if (group instanceof HTMLElement)
|
|
253
|
+
this.#configureStaggerGroup(group);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* @description Reinitializes the animation system after dynamically adding elements.
|
|
258
|
+
*
|
|
259
|
+
* Disconnects old observers and rescans the document.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* container.innerHTML = newContent;
|
|
263
|
+
* reveal.refresh();
|
|
264
|
+
*/
|
|
265
|
+
refresh() {
|
|
266
|
+
this.init();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// Auto-initialize when DOM is ready (only in browser environment)
|
|
270
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
271
|
+
let autoInstance = null;
|
|
272
|
+
const autoInit = () => {
|
|
273
|
+
if (!autoInstance) {
|
|
274
|
+
autoInstance = new Reveal();
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
if (document.readyState === "loading") {
|
|
278
|
+
document.addEventListener("DOMContentLoaded", autoInit);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
autoInit();
|
|
282
|
+
}
|
|
283
|
+
// After a SPA <main> swap, re-scan the new content for [data-reveal] targets.
|
|
284
|
+
registerRefresh(() => Reveal.getAutoInstance()?.refresh());
|
|
285
|
+
/**
|
|
286
|
+
* @description Prevents automatic initialization on DOM ready.
|
|
287
|
+
*/
|
|
288
|
+
Reveal.disableAutoInit = () => {
|
|
289
|
+
autoInstance = "disabled";
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* @description Returns the auto-initialized Reveal instance, if any.
|
|
293
|
+
*
|
|
294
|
+
* @returns The auto instance, or null when disabled or not yet created.
|
|
295
|
+
*/
|
|
296
|
+
Reveal.getAutoInstance = () => {
|
|
297
|
+
return autoInstance === "disabled" ? null : autoInstance;
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
// Attach to window for the documented public API (`window.Reveal`, `new Reveal()`),
|
|
301
|
+
// and export for module consumers (navigation.js imports it via the main.js bundle).
|
|
302
|
+
if (typeof window !== "undefined") {
|
|
303
|
+
window.Reveal = Reveal;
|
|
304
|
+
}
|
|
305
|
+
export { Reveal };
|