@zazz-ui/core 0.13.0 → 0.14.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 +93 -0
- package/README.md +5 -9
- package/dist/sri.json +34 -30
- package/dist/zazz.css +1 -1
- package/dist/zazz.js +1 -1
- package/editor/zazz.css-data.json +173 -3
- package/editor/zazz.html-data.json +138 -0
- package/editor/zazz.language-data.json +313 -125
- package/editor/zazz.lint-data.json +1501 -1383
- package/package.json +1 -5
- package/src/base/_defaults.css +1 -1
- package/src/base/_reset.css +16 -2
- package/src/base/_variables.css +43 -31
- package/src/base/carousel-scroll.d.ts +161 -0
- package/src/base/carousel-scroll.d.ts.map +1 -0
- package/src/base/carousel-scroll.js +1035 -0
- package/src/base/carousel-scroll.ts +1227 -0
- package/src/base/carousel.d.ts +34 -0
- package/src/base/carousel.d.ts.map +1 -0
- package/src/base/carousel.js +279 -0
- package/src/base/carousel.ts +292 -0
- package/src/base/dialog-lifecycle.js +1 -1
- package/src/base/dialog-lifecycle.ts +1 -1
- package/src/base/gesture.d.ts +201 -0
- package/src/base/gesture.d.ts.map +1 -0
- package/src/base/gesture.js +317 -0
- package/src/base/gesture.ts +494 -0
- package/src/base/kit-styling.d.ts.map +1 -1
- package/src/base/kit-styling.js +182 -162
- package/src/base/kit-styling.ts +182 -162
- package/src/base/utils.d.ts +1 -1
- package/src/base/utils.js +2 -2
- package/src/base/utils.ts +2 -2
- package/src/globals.d.ts +7 -30
- package/src/head.d.ts.map +1 -1
- package/src/head.js +1 -25
- package/src/head.ts +1 -25
- package/src/index.css +1 -0
- package/src/index.d.ts +6 -5
- package/src/index.d.ts.map +1 -1
- package/src/index.js +6 -5
- package/src/index.ts +6 -5
- package/src/manifest.d.ts +1 -1
- package/src/manifest.d.ts.map +1 -1
- package/src/manifest.js +25 -13
- package/src/manifest.ts +26 -14
- package/src/primitives/button/button.css +1 -1
- package/src/primitives/carousel/carousel.css +103 -20
- package/src/primitives/carousel/carousel.d.ts +4 -32
- package/src/primitives/carousel/carousel.d.ts.map +1 -1
- package/src/primitives/carousel/carousel.js +39 -14
- package/src/primitives/carousel/carousel.ts +21 -25
- package/src/primitives/dialog/dialog.css +14 -8
- package/src/primitives/drawer/drawer-indent.html +27 -0
- package/src/primitives/drawer/drawer-nested.html +72 -0
- package/src/primitives/drawer/drawer-responsive-dialog.html +44 -0
- package/src/primitives/drawer/drawer-snap.html +26 -0
- package/src/primitives/drawer/drawer.css +528 -0
- package/src/primitives/drawer/drawer.d.ts +24 -0
- package/src/primitives/drawer/drawer.d.ts.map +1 -0
- package/src/primitives/drawer/drawer.html +42 -0
- package/src/primitives/drawer/drawer.js +765 -0
- package/src/primitives/drawer/drawer.ts +823 -0
- package/src/primitives/fields/fields.css +4 -2
- package/src/primitives/input/input.css +4 -3
- package/src/primitives/input-group/input-group.css +5 -5
- package/src/primitives/lightbox/lightbox.css +2 -2
- package/src/primitives/lightbox/lightbox.d.ts.map +1 -1
- package/src/primitives/lightbox/lightbox.js +9 -8
- package/src/primitives/lightbox/lightbox.ts +9 -8
- package/src/primitives/password-group/password-group.css +5 -5
- package/src/primitives/radio/radio.css +15 -10
- package/src/primitives/slider/slider.css +2 -2
- package/src/primitives/switch/switch.css +6 -6
- package/src/primitives/tabs/tabs.css +10 -10
- package/src/primitives/toaster/toaster.css +29 -1
- package/src/primitives/toaster/toaster.d.ts.map +1 -1
- package/src/primitives/toaster/toaster.js +117 -9
- package/src/primitives/toaster/toaster.ts +136 -9
- package/src/primitives/tooltip/tooltip.css +93 -10
- package/src/base/embla.d.ts +0 -90
- package/src/base/embla.d.ts.map +0 -1
- package/src/base/embla.js +0 -878
- package/src/base/embla.ts +0 -1066
|
@@ -0,0 +1,765 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Drawer: drag-to-dismiss for `<dialog data-ui="drawer">` bottom sheets.
|
|
4
|
+
* @description A drawer is a native modal `<dialog>`, opened and closed like
|
|
5
|
+
* any other (`command="show-modal"`, `command="close"`, Esc, the backdrop with
|
|
6
|
+
* `closedby="any"`). This script adds the gesture: drag the drawer down and
|
|
7
|
+
* let go to dismiss it.
|
|
8
|
+
*
|
|
9
|
+
* - `data-ui="drawer"` is a drawer on every device.
|
|
10
|
+
* - `data-ui="dialog drawer"` is a drawer below the `sm` band on a touch
|
|
11
|
+
* screen, and a plain dialog (no dragging) everywhere else.
|
|
12
|
+
*
|
|
13
|
+
* While the pointer is down the drawer follows it 1:1 and the backdrop fades
|
|
14
|
+
* with it. Letting go past a quarter of the drawer's height, or with a quick
|
|
15
|
+
* downward flick, slides it off the bottom edge and then closes it through
|
|
16
|
+
* `requestClose()`, so `cancel` and `close` fire as they do for Esc; anything
|
|
17
|
+
* less returns it to rest. Until it has slid out it can be caught again. Pulling it up
|
|
18
|
+
* past its resting place meets resistance.
|
|
19
|
+
*
|
|
20
|
+
* A drag starts anywhere on the drawer except on form fields, selected text,
|
|
21
|
+
* and anything inside `[data-ui-no-drag]`. Inside scrolling content it starts
|
|
22
|
+
* only once that content is scrolled to the top and the pointer moves down,
|
|
23
|
+
* so the body scrolls first and the drawer follows; the handle
|
|
24
|
+
* (`data-drawer-slot="handle"`) always drags. There is no custom element and
|
|
25
|
+
* nothing to initialize: the script binds a drawer when it opens.
|
|
26
|
+
*
|
|
27
|
+
* **Snap points.** `data-drawer-snap="148px 0.5 1"` gives the drawer resting
|
|
28
|
+
* heights, smallest first: a number up to 1 is a share of the drawer's full
|
|
29
|
+
* height, a `px` or `rem` length is a visible height. It opens at the first.
|
|
30
|
+
* Letting go settles on the nearest; a flick moves one stop in its direction,
|
|
31
|
+
* a very fast one goes all the way (or one stop, with
|
|
32
|
+
* `data-drawer-snap-sequential`), and from the lowest stop a flick or enough
|
|
33
|
+
* travel downward closes the drawer. Below the largest stop the drawer takes
|
|
34
|
+
* every vertical drag and its content does not scroll. A click on the handle
|
|
35
|
+
* steps to the next stop; make the handle a `<button>` to give the keyboard
|
|
36
|
+
* the same. Each change fires `zazz:drawer-snap` (`detail.index`,
|
|
37
|
+
* `detail.value` in px), `data-drawer-state` carries `expanded` at the largest
|
|
38
|
+
* stop, and `snapDrawer(dialog, index)` moves it from script.
|
|
39
|
+
*
|
|
40
|
+
* **The software keyboard.** A phone lays a drawer out against the full
|
|
41
|
+
* screen, which the keyboard does not shrink. While a field in the front
|
|
42
|
+
* drawer has the keyboard up, the drawer's content ends at the keyboard's top
|
|
43
|
+
* edge (its surface runs on underneath), the focused field scrolls into what
|
|
44
|
+
* is still visible, and the page behind stays where it was. Nothing to author.
|
|
45
|
+
*
|
|
46
|
+
* **Stacked drawers.** A drawer opened over another scales the one behind back
|
|
47
|
+
* and lifts it, and that one follows as the front drawer is dragged. Nothing
|
|
48
|
+
* to author: the script counts the open drawers.
|
|
49
|
+
*
|
|
50
|
+
* **Indent.** Wrap the page in `<ui-drawer-indent>` (or put
|
|
51
|
+
* `data-ui="drawer-indent"` on its wrapper) and it scales back behind any open
|
|
52
|
+
* drawer, with rounded top corners, and follows the drag of the last one. Only
|
|
53
|
+
* transforms animate. While indented the wrapper is transformed, so a
|
|
54
|
+
* `position: fixed` element inside it moves with the page; `position: sticky`
|
|
55
|
+
* is unaffected.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* <button data-ui="button" command="show-modal" commandfor="filters">Filters</button>
|
|
59
|
+
* <dialog id="filters" data-ui="drawer" closedby="any">
|
|
60
|
+
* <div data-drawer-slot="handle"></div>
|
|
61
|
+
* <div data-drawer-slot="content">
|
|
62
|
+
* <header data-drawer-slot="header">…</header>
|
|
63
|
+
* <div data-drawer-slot="body">…</div>
|
|
64
|
+
* </div>
|
|
65
|
+
* </dialog>
|
|
66
|
+
*/
|
|
67
|
+
import { currentTranslate, maxTransitionMs, pickSnap, rubberBand, trackDrag, } from "../../base/gesture.js";
|
|
68
|
+
// --- Tuning ---
|
|
69
|
+
/** Share of the drawer's visible height, at its lowest stop, that dismisses on its own. */
|
|
70
|
+
const CLOSE_RATIO = 0.25;
|
|
71
|
+
/** Speed that moves the drawer one stop, or dismisses it from the lowest, in px/ms. */
|
|
72
|
+
const FLICK_VELOCITY = 0.4;
|
|
73
|
+
/** Speed that skips every stop: all the way open, or closed, in px/ms. */
|
|
74
|
+
const FLING_VELOCITY = 2;
|
|
75
|
+
/**
|
|
76
|
+
* After inner content scrolls, how long before the drawer may be dragged, in
|
|
77
|
+
* ms. A fast scroll that reaches the top would otherwise carry straight on
|
|
78
|
+
* into dragging the drawer away.
|
|
79
|
+
*/
|
|
80
|
+
const SCROLL_GUARD_MS = 100;
|
|
81
|
+
/** Length of the backdrop's scrub animation: its timeline is drag progress, not time. */
|
|
82
|
+
const SCRUB_MS = 1000;
|
|
83
|
+
const DRAWER = 'dialog[data-ui~="drawer"]';
|
|
84
|
+
const HANDLE = '[data-drawer-slot~="handle"]';
|
|
85
|
+
const INDENT = 'ui-drawer-indent, [data-ui~="drawer-indent"]';
|
|
86
|
+
const INDENT_STATE = "data-drawer-indent-state";
|
|
87
|
+
// --- Helpers ---
|
|
88
|
+
/** Adds or removes one token of a space-separated state attribute; an empty attribute is removed. */
|
|
89
|
+
function setToken(element, attribute, token, on) {
|
|
90
|
+
const tokens = new Set((element.getAttribute(attribute) ?? "").split(/\s+/).filter(Boolean));
|
|
91
|
+
if (tokens.has(token) === on)
|
|
92
|
+
return;
|
|
93
|
+
if (on)
|
|
94
|
+
tokens.add(token);
|
|
95
|
+
else
|
|
96
|
+
tokens.delete(token);
|
|
97
|
+
if (tokens.size)
|
|
98
|
+
element.setAttribute(attribute, [...tokens].join(" "));
|
|
99
|
+
else
|
|
100
|
+
element.removeAttribute(attribute);
|
|
101
|
+
}
|
|
102
|
+
/** Adds or removes a token of a drawer's `data-drawer-state`. */
|
|
103
|
+
function setState(dialog, token, on) {
|
|
104
|
+
setToken(dialog, "data-drawer-state", token, on);
|
|
105
|
+
}
|
|
106
|
+
/** Adds or removes the `dragging` token of a drawer's `data-drawer-state`. */
|
|
107
|
+
function setDragging(dialog, on) {
|
|
108
|
+
setState(dialog, "dragging", on);
|
|
109
|
+
}
|
|
110
|
+
/** Clears everything a drag wrote on the drawer. */
|
|
111
|
+
function reset(dialog) {
|
|
112
|
+
setDragging(dialog, false);
|
|
113
|
+
dialog.style.removeProperty("translate");
|
|
114
|
+
dialog.style.removeProperty("--_drawer-backdrop");
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @description Reads a drawer's snap points as resting positions: px the
|
|
118
|
+
* drawer is pushed down at each, the smallest visible height first.
|
|
119
|
+
*
|
|
120
|
+
* @param dialog - The drawer.
|
|
121
|
+
* @param height - The drawer's full visible height in px.
|
|
122
|
+
* @returns The positions, descending; `[0]` without usable snap points.
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
function readStops(dialog, height) {
|
|
126
|
+
const raw = dialog.getAttribute("data-drawer-snap")?.trim();
|
|
127
|
+
if (!raw)
|
|
128
|
+
return [0];
|
|
129
|
+
const rem = Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
|
|
130
|
+
const positions = new Set();
|
|
131
|
+
for (const token of raw.split(/\s+/)) {
|
|
132
|
+
const value = Number.parseFloat(token);
|
|
133
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
134
|
+
continue;
|
|
135
|
+
let visible = value * height;
|
|
136
|
+
if (token.endsWith("rem"))
|
|
137
|
+
visible = value * rem;
|
|
138
|
+
else if (token.endsWith("px") || value > 1)
|
|
139
|
+
visible = value;
|
|
140
|
+
positions.add(Math.round(height - Math.min(height, Math.max(1, visible))));
|
|
141
|
+
}
|
|
142
|
+
return positions.size ? [...positions].sort((a, b) => b - a) : [0];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* @description Starts a paused opacity animation on the drawer's backdrop, to
|
|
146
|
+
* be scrubbed with the drag. An animation, not a style write: it reaches the
|
|
147
|
+
* pseudo-element without restyling the drawer's content, in engines that do
|
|
148
|
+
* not re-resolve `::backdrop` when a non-inherited property changes on its
|
|
149
|
+
* dialog (WebKit).
|
|
150
|
+
*
|
|
151
|
+
* @param dialog - The drawer.
|
|
152
|
+
* @returns The animation, or null where `::backdrop` cannot be animated; the
|
|
153
|
+
* caller then writes `--_drawer-backdrop`, which drawer.css reads.
|
|
154
|
+
* @private
|
|
155
|
+
*/
|
|
156
|
+
function scrubBackdrop(dialog) {
|
|
157
|
+
try {
|
|
158
|
+
const animation = dialog.animate([{ opacity: 1 }, { opacity: 0 }], {
|
|
159
|
+
pseudoElement: "::backdrop",
|
|
160
|
+
duration: SCRUB_MS,
|
|
161
|
+
fill: "both",
|
|
162
|
+
});
|
|
163
|
+
animation.pause();
|
|
164
|
+
return animation;
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** Whether drawer.css has the dialog in drawer mode right now. */
|
|
171
|
+
function inDrawerMode(dialog) {
|
|
172
|
+
return getComputedStyle(dialog).getPropertyValue("--_drawer-mode").trim() === "1";
|
|
173
|
+
}
|
|
174
|
+
/** Whether an element scrolls its content on the block axis. */
|
|
175
|
+
function scrolls(element) {
|
|
176
|
+
if (element.scrollHeight <= element.clientHeight)
|
|
177
|
+
return false;
|
|
178
|
+
const overflow = getComputedStyle(element).overflowY;
|
|
179
|
+
return overflow === "auto" || overflow === "scroll";
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* @description Whether a press may drag the drawer, given what it landed on
|
|
183
|
+
* and which way it is moving.
|
|
184
|
+
*
|
|
185
|
+
* @param dialog - The drawer.
|
|
186
|
+
* @param drag - The drag about to start; `offset` carries its direction.
|
|
187
|
+
* @param lastScroll - When content inside the drawer last scrolled.
|
|
188
|
+
* @param partial - Whether the drawer rests below its largest snap point.
|
|
189
|
+
* @returns Whether the drawer takes the gesture.
|
|
190
|
+
* @private
|
|
191
|
+
*/
|
|
192
|
+
function claims(dialog, drag, lastScroll, partial) {
|
|
193
|
+
if (!inDrawerMode(dialog))
|
|
194
|
+
return false;
|
|
195
|
+
// a press on the backdrop targets the dialog, outside its box
|
|
196
|
+
const box = dialog.getBoundingClientRect();
|
|
197
|
+
if (drag.startY < box.top || drag.startX < box.left || drag.startX > box.right)
|
|
198
|
+
return false;
|
|
199
|
+
if (drag.target.closest(HANDLE))
|
|
200
|
+
return true;
|
|
201
|
+
// below its largest stop the drawer moves before anything inside it scrolls
|
|
202
|
+
if (partial)
|
|
203
|
+
return true;
|
|
204
|
+
// scrolling content goes first: it must be at the top, and the pull downward
|
|
205
|
+
const down = drag.offset > 0;
|
|
206
|
+
for (let node = drag.target; node && dialog.contains(node); node = node.parentElement) {
|
|
207
|
+
if (scrolls(node) && (node.scrollTop > 0 || !down))
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
return performance.now() - lastScroll >= SCROLL_GUARD_MS;
|
|
211
|
+
}
|
|
212
|
+
// --- Stack ---
|
|
213
|
+
/** The open drawers in drawer mode, the front one last. */
|
|
214
|
+
const stack = [];
|
|
215
|
+
/**
|
|
216
|
+
* @description Writes each open drawer's place in the stack: how many drawers
|
|
217
|
+
* sit in front of it (`--_drawer-depth`, `stacked`) and whether it opened over
|
|
218
|
+
* another (`nested`). Runs when a drawer opens or closes, never per frame.
|
|
219
|
+
* @private
|
|
220
|
+
*/
|
|
221
|
+
function restack() {
|
|
222
|
+
// a drawer removed from the page while open never reports its close
|
|
223
|
+
for (let index = stack.length - 1; index >= 0; index--) {
|
|
224
|
+
const dialog = stack[index];
|
|
225
|
+
if (!dialog.isConnected || !dialog.open)
|
|
226
|
+
stack.splice(index, 1);
|
|
227
|
+
}
|
|
228
|
+
stack.forEach((dialog, index) => {
|
|
229
|
+
const depth = stack.length - 1 - index;
|
|
230
|
+
setState(dialog, "following", false);
|
|
231
|
+
setState(dialog, "stacked", depth > 0);
|
|
232
|
+
setState(dialog, "nested", index > 0);
|
|
233
|
+
if (depth > 0)
|
|
234
|
+
dialog.style.setProperty("--_drawer-depth", String(depth));
|
|
235
|
+
else
|
|
236
|
+
dialog.style.removeProperty("--_drawer-depth");
|
|
237
|
+
});
|
|
238
|
+
indentPose(stack.length > 0);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* @description Moves the drawers behind `front` with its drag: at progress 1
|
|
242
|
+
* each sits where it will once `front` is gone. The depth is a non-inheriting
|
|
243
|
+
* property, so the write restyles those drawers and not their content.
|
|
244
|
+
*
|
|
245
|
+
* @param front - The drawer being dragged or released.
|
|
246
|
+
* @param progress - How far `front` is toward closed, 0 to 1.
|
|
247
|
+
* @param live - Whether a pointer is driving it (transitions off).
|
|
248
|
+
* @private
|
|
249
|
+
*/
|
|
250
|
+
function follow(front, progress, live) {
|
|
251
|
+
const index = stack.indexOf(front);
|
|
252
|
+
for (let behind = 0; behind < index; behind++) {
|
|
253
|
+
const dialog = stack[behind];
|
|
254
|
+
dialog.style.setProperty("--_drawer-depth", String(index - behind - progress));
|
|
255
|
+
setState(dialog, "following", live);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// --- Indent ---
|
|
259
|
+
/** The page wrapper that is indented right now, and what ends its return to rest. */
|
|
260
|
+
let indented = null;
|
|
261
|
+
let cancelOutdent = null;
|
|
262
|
+
/**
|
|
263
|
+
* @description Measures what the indent needs, once per activation and on
|
|
264
|
+
* resize: the scale that pulls each side in by the inset hook, and where the
|
|
265
|
+
* viewport sits inside the wrapper (the transform's origin, the clip, and the
|
|
266
|
+
* corner pieces all hang off its top edge).
|
|
267
|
+
* @private
|
|
268
|
+
*/
|
|
269
|
+
function measureIndent(wrapper) {
|
|
270
|
+
const box = wrapper.getBoundingClientRect();
|
|
271
|
+
const width = wrapper.offsetWidth || 1;
|
|
272
|
+
const inset = Number.parseFloat(getComputedStyle(wrapper).getPropertyValue("--_drawer-indent-inset")) || 0;
|
|
273
|
+
const top = Math.max(0, -box.top);
|
|
274
|
+
const bottom = Math.max(0, wrapper.offsetHeight - top - window.innerHeight);
|
|
275
|
+
wrapper.style.setProperty("--_drawer-indent-scale", String(Math.max(0, 1 - (inset * 2) / width)));
|
|
276
|
+
wrapper.style.setProperty("--_drawer-indent-top", `${top}px`);
|
|
277
|
+
wrapper.style.setProperty("--_drawer-indent-bottom", `${bottom}px`);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* @description Indents the page wrapper or sends it back to rest. The pose is
|
|
281
|
+
* a state token and the motion a CSS transition; the `on` token (clip,
|
|
282
|
+
* corners, backing) outlasts the pose until the return has finished.
|
|
283
|
+
*
|
|
284
|
+
* @param active - Whether a drawer is open.
|
|
285
|
+
* @private
|
|
286
|
+
*/
|
|
287
|
+
function indentPose(active) {
|
|
288
|
+
// a wrapper that left the page takes its state with it
|
|
289
|
+
if (indented && !indented.isConnected) {
|
|
290
|
+
cancelOutdent?.();
|
|
291
|
+
indented = null;
|
|
292
|
+
}
|
|
293
|
+
const wrapper = indented ?? document.querySelector(INDENT);
|
|
294
|
+
if (!wrapper)
|
|
295
|
+
return;
|
|
296
|
+
if (active) {
|
|
297
|
+
cancelOutdent?.();
|
|
298
|
+
if (indented !== wrapper) {
|
|
299
|
+
measureIndent(wrapper);
|
|
300
|
+
indented = wrapper;
|
|
301
|
+
}
|
|
302
|
+
setToken(wrapper, INDENT_STATE, "on", true);
|
|
303
|
+
setToken(wrapper, INDENT_STATE, "active", true);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (!indented || cancelOutdent)
|
|
307
|
+
return;
|
|
308
|
+
setToken(wrapper, INDENT_STATE, "dragging", false);
|
|
309
|
+
wrapper.style.removeProperty("--_drawer-indent-amount");
|
|
310
|
+
setToken(wrapper, INDENT_STATE, "active", false);
|
|
311
|
+
const off = () => {
|
|
312
|
+
cancelOutdent?.();
|
|
313
|
+
wrapper.removeAttribute(INDENT_STATE);
|
|
314
|
+
for (const name of ["scale", "top", "bottom"]) {
|
|
315
|
+
wrapper.style.removeProperty(`--_drawer-indent-${name}`);
|
|
316
|
+
}
|
|
317
|
+
indented = null;
|
|
318
|
+
};
|
|
319
|
+
const ms = maxTransitionMs(wrapper);
|
|
320
|
+
if (ms <= 0) {
|
|
321
|
+
off();
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const onReturned = (event) => {
|
|
325
|
+
if (event.target === wrapper && event.propertyName === "scale")
|
|
326
|
+
off();
|
|
327
|
+
};
|
|
328
|
+
const timer = window.setTimeout(off, ms + 100);
|
|
329
|
+
wrapper.addEventListener("transitionend", onReturned);
|
|
330
|
+
cancelOutdent = () => {
|
|
331
|
+
window.clearTimeout(timer);
|
|
332
|
+
wrapper.removeEventListener("transitionend", onReturned);
|
|
333
|
+
cancelOutdent = null;
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* @description Links the indent to the last open drawer's drag.
|
|
338
|
+
*
|
|
339
|
+
* @param progress - How far the drawer is toward closed, 0 to 1.
|
|
340
|
+
* @param live - Whether a pointer is driving it (transitions off).
|
|
341
|
+
* @private
|
|
342
|
+
*/
|
|
343
|
+
function indentProgress(progress, live) {
|
|
344
|
+
if (!indented)
|
|
345
|
+
return;
|
|
346
|
+
setToken(indented, INDENT_STATE, "dragging", live);
|
|
347
|
+
if (live)
|
|
348
|
+
indented.style.setProperty("--_drawer-indent-amount", String(1 - progress));
|
|
349
|
+
else
|
|
350
|
+
indented.style.removeProperty("--_drawer-indent-amount");
|
|
351
|
+
}
|
|
352
|
+
// --- Keyboard ---
|
|
353
|
+
/** The keyboard's height on the front drawer, which drawer.css adds to its bottom padding. */
|
|
354
|
+
const KEYBOARD_INSET = "--_drawer-keyboard";
|
|
355
|
+
/** Space kept between a revealed field and the keyboard's top edge, in px. */
|
|
356
|
+
const REVEAL_GAP = 16;
|
|
357
|
+
/** Inputs that open a picker or nothing rather than the software keyboard. */
|
|
358
|
+
const NO_KEYBOARD = /^(?:button|checkbox|color|file|hidden|image|radio|range|reset|submit|date|datetime-local|month|time|week)$/;
|
|
359
|
+
/** Whether focus on this element opens the software keyboard. */
|
|
360
|
+
function typesText(element) {
|
|
361
|
+
if (element instanceof HTMLTextAreaElement)
|
|
362
|
+
return !element.readOnly;
|
|
363
|
+
if (element instanceof HTMLInputElement)
|
|
364
|
+
return !element.readOnly && !NO_KEYBOARD.test(element.type);
|
|
365
|
+
return element instanceof HTMLElement && element.isContentEditable;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* @description How much of the layout viewport the software keyboard covers,
|
|
369
|
+
* from the bottom: the part below the visual viewport. 0 while the page is
|
|
370
|
+
* pinch-zoomed, when the visual viewport is smaller for another reason.
|
|
371
|
+
* @private
|
|
372
|
+
*/
|
|
373
|
+
function keyboardInset() {
|
|
374
|
+
const viewport = window.visualViewport;
|
|
375
|
+
if (!viewport || Math.abs(viewport.scale - 1) > 0.01)
|
|
376
|
+
return 0;
|
|
377
|
+
const bottom = Math.max(0, viewport.offsetTop) + viewport.height;
|
|
378
|
+
return Math.max(0, Math.round(window.innerHeight - Math.min(window.innerHeight, bottom)));
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* @description Keeps an open drawer usable with the software keyboard up.
|
|
382
|
+
* iOS lays out the top layer against the layout viewport, which the keyboard
|
|
383
|
+
* does not shrink, and scrolls the page behind a modal to reveal a focused
|
|
384
|
+
* field. While the drawer is the front one this writes the keyboard's height
|
|
385
|
+
* to `--_drawer-keyboard` (drawer.css pads the sheet by it, so its
|
|
386
|
+
* content ends at the keyboard's top edge), holds the page at its scroll
|
|
387
|
+
* position, and scrolls a focused field into the part of its scrolling slot
|
|
388
|
+
* that is still visible.
|
|
389
|
+
*
|
|
390
|
+
* @param dialog - The drawer.
|
|
391
|
+
* @param signal - Aborts when the drawer closes.
|
|
392
|
+
* @param onChange - Runs after the inset changes, once the new padding is in place.
|
|
393
|
+
* @private
|
|
394
|
+
*/
|
|
395
|
+
function trackKeyboard(dialog, signal, onChange) {
|
|
396
|
+
const viewport = window.visualViewport;
|
|
397
|
+
if (!viewport)
|
|
398
|
+
return;
|
|
399
|
+
const front = () => stack[stack.length - 1] === dialog;
|
|
400
|
+
const pageX = window.scrollX;
|
|
401
|
+
const pageY = window.scrollY;
|
|
402
|
+
let frame = 0;
|
|
403
|
+
let current = 0;
|
|
404
|
+
const update = () => {
|
|
405
|
+
frame = 0;
|
|
406
|
+
const inset = front() ? keyboardInset() : 0;
|
|
407
|
+
if (inset === current)
|
|
408
|
+
return;
|
|
409
|
+
current = inset;
|
|
410
|
+
if (inset > 0)
|
|
411
|
+
dialog.style.setProperty(KEYBOARD_INSET, `${inset}px`);
|
|
412
|
+
else
|
|
413
|
+
dialog.style.removeProperty(KEYBOARD_INSET);
|
|
414
|
+
onChange();
|
|
415
|
+
};
|
|
416
|
+
const schedule = () => {
|
|
417
|
+
if (!frame)
|
|
418
|
+
frame = requestAnimationFrame(update);
|
|
419
|
+
};
|
|
420
|
+
/** Scrolls the field's scrolling slot so the field sits above the keyboard and below the slot's top. */
|
|
421
|
+
const reveal = (field) => {
|
|
422
|
+
if (!dialog.contains(field) || document.activeElement !== field)
|
|
423
|
+
return;
|
|
424
|
+
let container = field.parentElement;
|
|
425
|
+
while (container && dialog.contains(container) && !scrolls(container)) {
|
|
426
|
+
container = container.parentElement;
|
|
427
|
+
}
|
|
428
|
+
if (!container || !dialog.contains(container))
|
|
429
|
+
return;
|
|
430
|
+
const box = container.getBoundingClientRect();
|
|
431
|
+
const target = field.getBoundingClientRect();
|
|
432
|
+
const visibleBottom = Math.min(box.bottom, viewport.offsetTop + viewport.height) - REVEAL_GAP;
|
|
433
|
+
const visibleTop = Math.max(box.top, viewport.offsetTop) + REVEAL_GAP;
|
|
434
|
+
let by = 0;
|
|
435
|
+
if (target.bottom > visibleBottom)
|
|
436
|
+
by = target.bottom - visibleBottom;
|
|
437
|
+
if (target.top - by < visibleTop)
|
|
438
|
+
by = target.top - visibleTop;
|
|
439
|
+
if (Math.abs(by) < 1)
|
|
440
|
+
return;
|
|
441
|
+
const still = matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
442
|
+
container.scrollBy({ top: by, behavior: still ? "instant" : "smooth" });
|
|
443
|
+
};
|
|
444
|
+
viewport.addEventListener("resize", schedule, { signal });
|
|
445
|
+
viewport.addEventListener("scroll", schedule, { signal });
|
|
446
|
+
// the page behind a modal stays where it was, whatever iOS scrolls to show the field
|
|
447
|
+
window.addEventListener("scroll", () => {
|
|
448
|
+
if (!front() || (window.scrollX === pageX && window.scrollY === pageY))
|
|
449
|
+
return;
|
|
450
|
+
window.scrollTo({ left: pageX, top: pageY, behavior: "instant" });
|
|
451
|
+
}, { passive: true, signal });
|
|
452
|
+
// the keyboard settles over a few frames: reveal after it has, and again once it is up
|
|
453
|
+
dialog.addEventListener("focusin", (event) => {
|
|
454
|
+
const field = event.target;
|
|
455
|
+
if (!(field instanceof Element) || !typesText(field) || !front())
|
|
456
|
+
return;
|
|
457
|
+
for (const ms of [100, 350]) {
|
|
458
|
+
const timer = window.setTimeout(() => {
|
|
459
|
+
update();
|
|
460
|
+
reveal(field);
|
|
461
|
+
}, ms);
|
|
462
|
+
signal.addEventListener("abort", () => window.clearTimeout(timer), { once: true });
|
|
463
|
+
}
|
|
464
|
+
}, { signal });
|
|
465
|
+
signal.addEventListener("abort", () => {
|
|
466
|
+
cancelAnimationFrame(frame);
|
|
467
|
+
dialog.style.removeProperty(KEYBOARD_INSET);
|
|
468
|
+
});
|
|
469
|
+
update();
|
|
470
|
+
}
|
|
471
|
+
/** Open drawers and what unbinds or moves each. */
|
|
472
|
+
const bound = new WeakMap();
|
|
473
|
+
/** Each drawer's backdrop animation, kept past its close so the next open can drop it. */
|
|
474
|
+
const fades = new WeakMap();
|
|
475
|
+
/**
|
|
476
|
+
* @description Binds drag-to-dismiss to an open drawer until it closes.
|
|
477
|
+
*
|
|
478
|
+
* @param dialog - The drawer.
|
|
479
|
+
*/
|
|
480
|
+
function bindDrawer(dialog) {
|
|
481
|
+
if (bound.has(dialog))
|
|
482
|
+
return;
|
|
483
|
+
const controller = new AbortController();
|
|
484
|
+
const { signal } = controller;
|
|
485
|
+
// what the last dismissal left in place: the slid-out translate, the cleared backdrop
|
|
486
|
+
fades.get(dialog)?.cancel();
|
|
487
|
+
fades.delete(dialog);
|
|
488
|
+
reset(dialog);
|
|
489
|
+
const snaps = dialog.hasAttribute("data-drawer-snap");
|
|
490
|
+
let lastScroll = 0;
|
|
491
|
+
// where the drawer was when the drag caught it (mid snap-back, usually its stop)
|
|
492
|
+
let base = 0;
|
|
493
|
+
let height = 1;
|
|
494
|
+
// the sheet's bleed past the bottom edge: the most it may be pulled up
|
|
495
|
+
let lift = 0;
|
|
496
|
+
// resting positions, px pushed down, the lowest snap point first; and the one it rests at
|
|
497
|
+
let stops = [0];
|
|
498
|
+
let active = 0;
|
|
499
|
+
let fade = null;
|
|
500
|
+
// undoes a dismissal still sliding out, so a new drag can catch the drawer
|
|
501
|
+
let cancelClose = null;
|
|
502
|
+
const measure = () => {
|
|
503
|
+
lift = Math.max(0, -Number.parseFloat(getComputedStyle(dialog).marginBlockEnd) || 0);
|
|
504
|
+
// the layout height: a stacked drawer's scale must not shrink it
|
|
505
|
+
height = Math.max(1, dialog.offsetHeight - lift);
|
|
506
|
+
stops = snaps ? readStops(dialog, height) : [0];
|
|
507
|
+
active = Math.min(active, stops.length - 1);
|
|
508
|
+
};
|
|
509
|
+
/** Writes where the drawer rests: drawer.css turns `--_drawer-snap` into its `translate`. */
|
|
510
|
+
const place = () => {
|
|
511
|
+
if (!snaps)
|
|
512
|
+
return;
|
|
513
|
+
const largest = active === stops.length - 1;
|
|
514
|
+
dialog.style.setProperty("--_drawer-snap", `${stops[active] ?? 0}px`);
|
|
515
|
+
setState(dialog, "expanded", largest);
|
|
516
|
+
setState(dialog, "partial", !largest);
|
|
517
|
+
};
|
|
518
|
+
/** Everything that moves with the drawer's progress toward closed, besides its backdrop. */
|
|
519
|
+
const link = (progress, live) => {
|
|
520
|
+
follow(dialog, progress, live);
|
|
521
|
+
if (stack.length === 1 && stack[0] === dialog)
|
|
522
|
+
indentProgress(progress, live);
|
|
523
|
+
};
|
|
524
|
+
/**
|
|
525
|
+
* Runs the backdrop from where the drag left it to clear or back to full,
|
|
526
|
+
* in `ms`. Back at full the animation is dropped; clear, it holds until the
|
|
527
|
+
* drawer next opens, over whatever the closed dialog's own backdrop does.
|
|
528
|
+
*/
|
|
529
|
+
const settle = (closing, ms) => {
|
|
530
|
+
dialog.style.removeProperty("--_drawer-backdrop");
|
|
531
|
+
const animation = fade;
|
|
532
|
+
if (!animation)
|
|
533
|
+
return;
|
|
534
|
+
const done = () => {
|
|
535
|
+
if (closing || fade !== animation || animation.playState !== "finished")
|
|
536
|
+
return;
|
|
537
|
+
animation.cancel();
|
|
538
|
+
fades.delete(dialog);
|
|
539
|
+
fade = null;
|
|
540
|
+
};
|
|
541
|
+
const at = Number(animation.currentTime) || 0;
|
|
542
|
+
const left = closing ? SCRUB_MS - at : at;
|
|
543
|
+
if (ms <= 0 || left <= 0) {
|
|
544
|
+
animation.playbackRate = closing ? 1 : -1;
|
|
545
|
+
animation.finish();
|
|
546
|
+
done();
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
animation.playbackRate = ((closing ? 1 : -1) * left) / ms;
|
|
550
|
+
animation.play();
|
|
551
|
+
animation.finished.then(done, () => { });
|
|
552
|
+
};
|
|
553
|
+
/** Settles the drawer on a stop; the dialog's `translate` transition carries it there. */
|
|
554
|
+
const snapTo = (index) => {
|
|
555
|
+
const next = Math.min(Math.max(index, 0), stops.length - 1);
|
|
556
|
+
const changed = next !== active;
|
|
557
|
+
active = next;
|
|
558
|
+
place();
|
|
559
|
+
setDragging(dialog, false);
|
|
560
|
+
settle(false, maxTransitionMs(dialog));
|
|
561
|
+
dialog.style.removeProperty("translate");
|
|
562
|
+
link(0, false);
|
|
563
|
+
if (!changed)
|
|
564
|
+
return;
|
|
565
|
+
dialog.dispatchEvent(new CustomEvent("zazz:drawer-snap", {
|
|
566
|
+
bubbles: true,
|
|
567
|
+
detail: { index: active, value: height - (stops[active] ?? 0) },
|
|
568
|
+
}));
|
|
569
|
+
};
|
|
570
|
+
const rest = () => snapTo(active);
|
|
571
|
+
/** Closes the dialog; a `cancel` listener that keeps it open sends it back to rest. */
|
|
572
|
+
const close = () => {
|
|
573
|
+
if (!dialog.open)
|
|
574
|
+
return;
|
|
575
|
+
if (typeof dialog.requestClose === "function")
|
|
576
|
+
dialog.requestClose();
|
|
577
|
+
else
|
|
578
|
+
dialog.close();
|
|
579
|
+
if (!dialog.open)
|
|
580
|
+
return;
|
|
581
|
+
if (stack.length === 1)
|
|
582
|
+
indentPose(true);
|
|
583
|
+
rest();
|
|
584
|
+
};
|
|
585
|
+
/**
|
|
586
|
+
* Slides the drawer off the bottom edge while it is still open, then closes
|
|
587
|
+
* it. The slide is the drawer's own `translate` transition, so it does not
|
|
588
|
+
* depend on the engine animating a dialog's exit (WebKit removes a closed
|
|
589
|
+
* dialog at once), and until it ends the drawer can be caught again.
|
|
590
|
+
* Whatever is linked to the drawer leaves with it.
|
|
591
|
+
*/
|
|
592
|
+
const slideOutAndClose = (ms) => {
|
|
593
|
+
dialog.style.translate = `0 ${height + lift}px`;
|
|
594
|
+
settle(true, ms);
|
|
595
|
+
follow(dialog, 1, false);
|
|
596
|
+
if (stack.length === 1 && stack[0] === dialog)
|
|
597
|
+
indentPose(false);
|
|
598
|
+
if (ms <= 0) {
|
|
599
|
+
close();
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
const onSlid = (event) => {
|
|
603
|
+
if (event.target === dialog && event.propertyName === "translate")
|
|
604
|
+
finish();
|
|
605
|
+
};
|
|
606
|
+
const finish = () => {
|
|
607
|
+
cancelClose?.();
|
|
608
|
+
close();
|
|
609
|
+
};
|
|
610
|
+
// the timer covers a transition that never reports its end
|
|
611
|
+
const timer = window.setTimeout(finish, ms + 100);
|
|
612
|
+
dialog.addEventListener("transitionend", onSlid);
|
|
613
|
+
cancelClose = () => {
|
|
614
|
+
window.clearTimeout(timer);
|
|
615
|
+
dialog.removeEventListener("transitionend", onSlid);
|
|
616
|
+
cancelClose = null;
|
|
617
|
+
};
|
|
618
|
+
};
|
|
619
|
+
bound.set(dialog, { controller, snapTo });
|
|
620
|
+
if (inDrawerMode(dialog)) {
|
|
621
|
+
measure();
|
|
622
|
+
place();
|
|
623
|
+
stack.push(dialog);
|
|
624
|
+
restack();
|
|
625
|
+
trackKeyboard(dialog, signal, () => {
|
|
626
|
+
measure();
|
|
627
|
+
place();
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
signal.addEventListener("abort", () => {
|
|
631
|
+
cancelClose?.();
|
|
632
|
+
// a drawer closed some other way mid-drag: nothing may hold the backdrop
|
|
633
|
+
if (fade?.playState === "paused") {
|
|
634
|
+
fade.cancel();
|
|
635
|
+
fades.delete(dialog);
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
dialog.addEventListener("scroll", () => {
|
|
639
|
+
lastScroll = performance.now();
|
|
640
|
+
}, { capture: true, passive: true, signal });
|
|
641
|
+
// the handle steps through the snap points: a click, so a button handle works from the keyboard
|
|
642
|
+
dialog.addEventListener("click", (event) => {
|
|
643
|
+
if (stops.length < 2 || !(event.target instanceof Element))
|
|
644
|
+
return;
|
|
645
|
+
if (event.target.closest(HANDLE))
|
|
646
|
+
snapTo((active + 1) % stops.length);
|
|
647
|
+
}, { signal });
|
|
648
|
+
window.addEventListener("resize", () => {
|
|
649
|
+
if (!stack.includes(dialog))
|
|
650
|
+
return;
|
|
651
|
+
measure();
|
|
652
|
+
place();
|
|
653
|
+
}, { signal });
|
|
654
|
+
trackDrag(dialog, {
|
|
655
|
+
axis: "y",
|
|
656
|
+
signal,
|
|
657
|
+
canStart: (drag) => claims(dialog, drag, lastScroll, active < stops.length - 1),
|
|
658
|
+
onStart: () => {
|
|
659
|
+
// a drawer caught on its way out: what left with it comes back
|
|
660
|
+
if (cancelClose && stack.length === 1)
|
|
661
|
+
indentPose(true);
|
|
662
|
+
cancelClose?.();
|
|
663
|
+
base = currentTranslate(dialog).y;
|
|
664
|
+
measure();
|
|
665
|
+
if (!fade) {
|
|
666
|
+
fade = scrubBackdrop(dialog);
|
|
667
|
+
if (fade)
|
|
668
|
+
fades.set(dialog, fade);
|
|
669
|
+
}
|
|
670
|
+
fade?.pause();
|
|
671
|
+
setDragging(dialog, true);
|
|
672
|
+
},
|
|
673
|
+
onMove: ({ offset }) => {
|
|
674
|
+
const travel = base + offset;
|
|
675
|
+
const top = stops[stops.length - 1] ?? 0;
|
|
676
|
+
const y = travel >= top ? travel : top + rubberBand(travel - top, lift + top);
|
|
677
|
+
dialog.style.translate = `0 ${y}px`;
|
|
678
|
+
// progress runs from the lowest stop to gone: above it nothing fades
|
|
679
|
+
const lowest = stops[0] ?? 0;
|
|
680
|
+
const progress = Math.min(1, Math.max(0, (y - lowest) / Math.max(1, height - lowest)));
|
|
681
|
+
if (fade)
|
|
682
|
+
fade.currentTime = progress * SCRUB_MS;
|
|
683
|
+
else
|
|
684
|
+
dialog.style.setProperty("--_drawer-backdrop", String(1 - progress));
|
|
685
|
+
link(progress, true);
|
|
686
|
+
},
|
|
687
|
+
onEnd: ({ offset, velocity }) => {
|
|
688
|
+
const target = pickSnap({
|
|
689
|
+
stops,
|
|
690
|
+
position: base + offset,
|
|
691
|
+
velocity,
|
|
692
|
+
active,
|
|
693
|
+
size: height,
|
|
694
|
+
closeRatio: CLOSE_RATIO,
|
|
695
|
+
flick: FLICK_VELOCITY,
|
|
696
|
+
fling: FLING_VELOCITY,
|
|
697
|
+
sequential: dialog.hasAttribute("data-drawer-snap-sequential"),
|
|
698
|
+
});
|
|
699
|
+
// transitions back on: the inline translate now eases to wherever it is set
|
|
700
|
+
setDragging(dialog, false);
|
|
701
|
+
if (target < 0)
|
|
702
|
+
slideOutAndClose(maxTransitionMs(dialog));
|
|
703
|
+
else
|
|
704
|
+
snapTo(target);
|
|
705
|
+
},
|
|
706
|
+
onCancel: rest,
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
/** Unbinds a drawer that closed. */
|
|
710
|
+
function unbindDrawer(dialog) {
|
|
711
|
+
bound.get(dialog)?.controller.abort();
|
|
712
|
+
bound.delete(dialog);
|
|
713
|
+
dialog.removeAttribute("data-drawer-state");
|
|
714
|
+
dialog.style.removeProperty("--_drawer-depth");
|
|
715
|
+
const index = stack.indexOf(dialog);
|
|
716
|
+
if (index < 0)
|
|
717
|
+
return;
|
|
718
|
+
stack.splice(index, 1);
|
|
719
|
+
restack();
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* @description Moves an open drawer to one of its snap points.
|
|
723
|
+
*
|
|
724
|
+
* @param dialog - The drawer.
|
|
725
|
+
* @param index - The snap point, counted from the smallest; clamped to the ones it has.
|
|
726
|
+
*/
|
|
727
|
+
function snapDrawer(dialog, index) {
|
|
728
|
+
bound.get(dialog)?.snapTo(index);
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* @description Starts drawer binding for the page: every drawer is bound when
|
|
732
|
+
* the dialog lifecycle reports it open and unbound when it closes. Idempotent.
|
|
733
|
+
*/
|
|
734
|
+
const initDrawers = function () {
|
|
735
|
+
if (initDrawers._bound)
|
|
736
|
+
return;
|
|
737
|
+
initDrawers._bound = true;
|
|
738
|
+
document.addEventListener("zazz:dialog-open", (event) => {
|
|
739
|
+
if (event.target instanceof HTMLDialogElement && event.target.matches(DRAWER)) {
|
|
740
|
+
bindDrawer(event.target);
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
document.addEventListener("zazz:dialog-close", (event) => {
|
|
744
|
+
if (event.target instanceof HTMLDialogElement)
|
|
745
|
+
unbindDrawer(event.target);
|
|
746
|
+
});
|
|
747
|
+
window.addEventListener("resize", () => {
|
|
748
|
+
if (indented)
|
|
749
|
+
measureIndent(indented);
|
|
750
|
+
});
|
|
751
|
+
// drawers that were already open when the script loaded
|
|
752
|
+
for (const dialog of document.querySelectorAll(`${DRAWER}[open]`)) {
|
|
753
|
+
bindDrawer(dialog);
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
// Auto-initialize when DOM is ready (only in browser environment)
|
|
757
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
758
|
+
if (document.readyState === "loading") {
|
|
759
|
+
document.addEventListener("DOMContentLoaded", initDrawers);
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
initDrawers();
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
export { bindDrawer, initDrawers, snapDrawer };
|