@surdeddd/bottom-sheet 0.2.0 → 0.4.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/README.md +51 -21
- package/dist/{BottomSheetEngine-CIT9Htti.d.cts → BottomSheetEngine-BJrH7qY3.d.cts} +105 -3
- package/dist/{BottomSheetEngine-Df9MwBbm.d.ts → BottomSheetEngine-L05jGZvU.d.ts} +105 -3
- package/dist/element.cjs +1170 -196
- package/dist/element.d.cts +29 -5
- package/dist/element.d.ts +29 -5
- package/dist/element.iife.global.js +2 -2
- package/dist/element.js +1170 -196
- package/dist/index.cjs +1051 -220
- package/dist/index.d.cts +18 -3
- package/dist/index.d.ts +18 -3
- package/dist/index.js +1049 -221
- package/dist/integrations/formik.d.cts +1 -1
- package/dist/integrations/formik.d.ts +1 -1
- package/dist/integrations/react-hook-form.d.cts +1 -1
- package/dist/integrations/react-hook-form.d.ts +1 -1
- package/dist/overlay.cjs +181 -37
- package/dist/overlay.d.cts +13 -0
- package/dist/overlay.d.ts +13 -0
- package/dist/overlay.js +181 -37
- package/dist/preact.d.cts +1 -1
- package/dist/preact.d.ts +1 -1
- package/dist/qwik.cjs +966 -195
- package/dist/qwik.d.cts +4 -2
- package/dist/qwik.d.ts +4 -2
- package/dist/qwik.js +967 -196
- package/dist/react.cjs +1242 -272
- package/dist/react.d.cts +47 -5
- package/dist/react.d.ts +47 -5
- package/dist/react.js +1242 -272
- package/dist/solid.cjs +992 -236
- package/dist/solid.d.cts +299 -4
- package/dist/solid.d.ts +299 -4
- package/dist/solid.js +993 -237
- package/dist/solid.source.jsx +3476 -0
- package/dist/styles.css +67 -66
- package/dist/svelte-core.cjs +3415 -0
- package/dist/svelte-core.js +3413 -0
- package/dist/svelte-src/BottomSheet.svelte +308 -0
- package/dist/svelte-src/index.js +2 -0
- package/dist/svelte.cjs +1034 -207
- package/dist/svelte.d.cts +121 -0
- package/dist/svelte.d.ts +28 -3
- package/dist/svelte.js +1035 -208
- package/dist/vue.cjs +1191 -205
- package/dist/vue.d.cts +127 -0
- package/dist/vue.d.ts +57 -4
- package/dist/vue.js +1192 -206
- package/package.json +105 -45
package/dist/overlay.js
CHANGED
|
@@ -20,16 +20,52 @@ var SheetStack = class {
|
|
|
20
20
|
this.entries.splice(idx, 1);
|
|
21
21
|
this.recompute();
|
|
22
22
|
}
|
|
23
|
+
promote(id) {
|
|
24
|
+
const idx = this.entries.findIndex((e) => e.id === id);
|
|
25
|
+
if (idx === -1) return;
|
|
26
|
+
if (idx !== this.entries.length - 1) {
|
|
27
|
+
const [entry] = this.entries.splice(idx, 1);
|
|
28
|
+
this.entries.push(entry);
|
|
29
|
+
}
|
|
30
|
+
this.recompute();
|
|
31
|
+
}
|
|
32
|
+
update() {
|
|
33
|
+
this.recompute();
|
|
34
|
+
}
|
|
23
35
|
size() {
|
|
24
36
|
return this.entries.length;
|
|
25
37
|
}
|
|
38
|
+
depthOf(id) {
|
|
39
|
+
const open = [];
|
|
40
|
+
for (const entry of this.entries) {
|
|
41
|
+
if (!entry.isOpen || entry.isOpen()) open.push(entry);
|
|
42
|
+
}
|
|
43
|
+
const idx = open.findIndex((e) => e.id === id);
|
|
44
|
+
if (idx === -1) return 0;
|
|
45
|
+
return open.length - 1 - idx;
|
|
46
|
+
}
|
|
26
47
|
clear() {
|
|
27
48
|
this.entries = [];
|
|
28
49
|
}
|
|
29
50
|
recompute() {
|
|
51
|
+
let top = null;
|
|
52
|
+
const open = [];
|
|
53
|
+
for (const entry of this.entries) {
|
|
54
|
+
if (!entry.isOpen || entry.isOpen()) {
|
|
55
|
+
top = entry;
|
|
56
|
+
open.push(entry);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!top && this.entries.length > 0) {
|
|
60
|
+
top = this.entries[this.entries.length - 1];
|
|
61
|
+
}
|
|
30
62
|
this.entries.forEach((entry, i) => {
|
|
31
63
|
entry.setZIndex(BASE_Z + i * STEP);
|
|
32
|
-
entry.setIsTop(
|
|
64
|
+
entry.setIsTop(entry === top);
|
|
65
|
+
if (entry.setDepth) {
|
|
66
|
+
const openIdx = open.indexOf(entry);
|
|
67
|
+
entry.setDepth(openIdx === -1 ? 0 : open.length - 1 - openIdx);
|
|
68
|
+
}
|
|
33
69
|
});
|
|
34
70
|
}
|
|
35
71
|
};
|
|
@@ -74,7 +110,9 @@ var PERCENT = /^(-?\d+(?:\.\d+)?)%$/;
|
|
|
74
110
|
var resolveSnap = (point, mode, measureFit) => {
|
|
75
111
|
if (typeof point === "number") return Math.max(0, point);
|
|
76
112
|
if (point === "full") return viewportSize();
|
|
77
|
-
if (point === "fit"
|
|
113
|
+
if (point === "fit" || point === "content") {
|
|
114
|
+
return Math.max(0, 0);
|
|
115
|
+
}
|
|
78
116
|
const pctMatch = point.match(PERCENT);
|
|
79
117
|
if (pctMatch) {
|
|
80
118
|
const pct = parseFloat(pctMatch[1]) / 100;
|
|
@@ -152,9 +190,13 @@ var isVisible = (el) => {
|
|
|
152
190
|
var focusables = (root) => Array.from(root.querySelectorAll(FOCUSABLE)).filter(
|
|
153
191
|
(el) => !el.hasAttribute("inert") && isVisible(el) && !el.matches("[aria-hidden='true']")
|
|
154
192
|
);
|
|
193
|
+
var trapStack = [];
|
|
155
194
|
var installFocusTrap = (container, options = {}) => {
|
|
156
195
|
if (typeof document === "undefined") return () => {
|
|
157
196
|
};
|
|
197
|
+
const token = {};
|
|
198
|
+
trapStack.push(token);
|
|
199
|
+
const isActive = () => trapStack[trapStack.length - 1] === token;
|
|
158
200
|
const previouslyFocused = document.activeElement;
|
|
159
201
|
const focusInitial = () => {
|
|
160
202
|
const initial = typeof options.initialFocus === "string" ? container.querySelector(options.initialFocus) : options.initialFocus ?? focusables(container)[0] ?? container;
|
|
@@ -162,6 +204,7 @@ var installFocusTrap = (container, options = {}) => {
|
|
|
162
204
|
};
|
|
163
205
|
focusInitial();
|
|
164
206
|
const handleKey = (e) => {
|
|
207
|
+
if (!isActive()) return;
|
|
165
208
|
if (e.key === "Escape" && options.onEscape) {
|
|
166
209
|
options.onEscape();
|
|
167
210
|
return;
|
|
@@ -184,6 +227,7 @@ var installFocusTrap = (container, options = {}) => {
|
|
|
184
227
|
}
|
|
185
228
|
};
|
|
186
229
|
const handleFocusIn = (e) => {
|
|
230
|
+
if (!isActive()) return;
|
|
187
231
|
const target = e.target;
|
|
188
232
|
if (target && !container.contains(target)) {
|
|
189
233
|
const list = focusables(container);
|
|
@@ -196,6 +240,8 @@ var installFocusTrap = (container, options = {}) => {
|
|
|
196
240
|
return () => {
|
|
197
241
|
if (released) return;
|
|
198
242
|
released = true;
|
|
243
|
+
const idx = trapStack.indexOf(token);
|
|
244
|
+
if (idx !== -1) trapStack.splice(idx, 1);
|
|
199
245
|
document.removeEventListener("keydown", handleKey, true);
|
|
200
246
|
document.removeEventListener("focusin", handleFocusIn, true);
|
|
201
247
|
if (previouslyFocused && document.contains(previouslyFocused)) {
|
|
@@ -251,11 +297,17 @@ function createInertSiblings(rootProvider) {
|
|
|
251
297
|
return {
|
|
252
298
|
apply() {
|
|
253
299
|
if (typeof document === "undefined") return;
|
|
254
|
-
|
|
255
|
-
|
|
300
|
+
let top = rootProvider();
|
|
301
|
+
while (top.parentElement && top.parentElement !== document.body) {
|
|
302
|
+
top = top.parentElement;
|
|
303
|
+
}
|
|
304
|
+
const parent = top.parentElement ?? document.body;
|
|
256
305
|
for (const child of Array.from(parent.children)) {
|
|
257
|
-
if (child ===
|
|
306
|
+
if (child === top) continue;
|
|
258
307
|
if (child.hasAttribute("inert")) continue;
|
|
308
|
+
if (child.classList.contains("bs-backdrop") || child.classList.contains("bs-screen") || child.classList.contains("bs-root")) {
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
259
311
|
child.setAttribute("inert", "");
|
|
260
312
|
tracked.push(child);
|
|
261
313
|
}
|
|
@@ -271,7 +323,6 @@ function createInertSiblings(rootProvider) {
|
|
|
271
323
|
var LifecycleController = class {
|
|
272
324
|
constructor(deps, opts) {
|
|
273
325
|
__publicField(this, "element");
|
|
274
|
-
__publicField(this, "closeFn");
|
|
275
326
|
__publicField(this, "focusTrapEnabled");
|
|
276
327
|
__publicField(this, "initialFocus");
|
|
277
328
|
__publicField(this, "closeOnEscape");
|
|
@@ -285,7 +336,6 @@ var LifecycleController = class {
|
|
|
285
336
|
__publicField(this, "installed", false);
|
|
286
337
|
__publicField(this, "destroyed", false);
|
|
287
338
|
this.element = deps.element;
|
|
288
|
-
this.closeFn = deps.close;
|
|
289
339
|
this.focusTrapEnabled = opts.focusTrap ?? false;
|
|
290
340
|
this.initialFocus = opts.initialFocus;
|
|
291
341
|
this.closeOnEscape = opts.closeOnEscape ?? true;
|
|
@@ -295,6 +345,9 @@ var LifecycleController = class {
|
|
|
295
345
|
this.returnFocus = opts.returnFocus;
|
|
296
346
|
this.inertSiblings = createInertSiblings(() => this.element);
|
|
297
347
|
}
|
|
348
|
+
get isInstalled() {
|
|
349
|
+
return this.installed;
|
|
350
|
+
}
|
|
298
351
|
install() {
|
|
299
352
|
if (this.destroyed) return;
|
|
300
353
|
this.installed = true;
|
|
@@ -303,8 +356,7 @@ var LifecycleController = class {
|
|
|
303
356
|
}
|
|
304
357
|
if (this.focusTrapEnabled && !this.releaseFocusTrap) {
|
|
305
358
|
this.releaseFocusTrap = installFocusTrap(this.element, {
|
|
306
|
-
initialFocus: this.initialFocus
|
|
307
|
-
onEscape: this.closeOnEscape ? () => void this.closeFn() : void 0
|
|
359
|
+
initialFocus: this.initialFocus
|
|
308
360
|
});
|
|
309
361
|
}
|
|
310
362
|
if (this.inertSiblingsEnabled && this.shouldApplyInertSiblings()) {
|
|
@@ -324,7 +376,7 @@ var LifecycleController = class {
|
|
|
324
376
|
this.releaseScrollLock = null;
|
|
325
377
|
this.inertSiblings.remove();
|
|
326
378
|
if (this.returnFocus) {
|
|
327
|
-
const target = typeof this.returnFocus === "function" ? this.returnFocus() : this.returnFocus;
|
|
379
|
+
const target = typeof this.returnFocus === "function" ? this.returnFocus() : typeof this.returnFocus === "string" ? typeof document !== "undefined" ? document.querySelector(this.returnFocus) : null : this.returnFocus;
|
|
328
380
|
target?.focus?.();
|
|
329
381
|
}
|
|
330
382
|
}
|
|
@@ -334,6 +386,12 @@ var LifecycleController = class {
|
|
|
334
386
|
}
|
|
335
387
|
};
|
|
336
388
|
|
|
389
|
+
// src/core/animation/animation.ts
|
|
390
|
+
var prefersReducedMotion = () => {
|
|
391
|
+
if (typeof window === "undefined" || !window.matchMedia) return false;
|
|
392
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
393
|
+
};
|
|
394
|
+
|
|
337
395
|
// src/core/overlay.ts
|
|
338
396
|
var OVERLAY_PRESETS = Object.freeze({
|
|
339
397
|
sheet: Object.freeze({
|
|
@@ -413,6 +471,10 @@ var OverlayEngine = class {
|
|
|
413
471
|
__publicField(this, "closeOnOutsidePointerEnabled");
|
|
414
472
|
__publicField(this, "detachOutsidePointer", null);
|
|
415
473
|
__publicField(this, "detachSwipe", null);
|
|
474
|
+
__publicField(this, "respectReducedMotionEnabled");
|
|
475
|
+
__publicField(this, "isTop", true);
|
|
476
|
+
__publicField(this, "backPushed", false);
|
|
477
|
+
__publicField(this, "movedToTarget", false);
|
|
416
478
|
__publicField(this, "onOpenCb");
|
|
417
479
|
__publicField(this, "onCloseCb");
|
|
418
480
|
__publicField(this, "isOpen_", false);
|
|
@@ -449,6 +511,7 @@ var OverlayEngine = class {
|
|
|
449
511
|
this.mountTarget = opts.mountTo;
|
|
450
512
|
this.peekRaw = opts.peek;
|
|
451
513
|
this.closeOnOutsidePointerEnabled = opts.closeOnOutsidePointer ?? false;
|
|
514
|
+
this.respectReducedMotionEnabled = opts.respectReducedMotion ?? true;
|
|
452
515
|
this.onOpenCb = opts.onOpen;
|
|
453
516
|
this.onCloseCb = opts.onClose;
|
|
454
517
|
if (this.peekRaw !== void 0 && this.edge !== "bottom") {
|
|
@@ -496,15 +559,17 @@ var OverlayEngine = class {
|
|
|
496
559
|
this.emit("before-open", void 0);
|
|
497
560
|
this.isOpen_ = true;
|
|
498
561
|
this.isAnimating_ = true;
|
|
562
|
+
sheetStack.promote(this.id);
|
|
499
563
|
this.element.removeAttribute("hidden");
|
|
500
564
|
this.element.setAttribute("data-state", "entering");
|
|
501
565
|
if (this.focusTrapEnabled) {
|
|
502
566
|
this.element.setAttribute("aria-modal", "true");
|
|
503
567
|
}
|
|
504
|
-
const
|
|
568
|
+
const dur = this.effectiveDuration();
|
|
569
|
+
const transitionStr = `transform ${dur}ms ${this.enterEasing}, opacity ${dur}ms ease-out`;
|
|
505
570
|
this.element.style.transition = transitionStr;
|
|
506
571
|
if (this.backdrop) {
|
|
507
|
-
this.backdrop.style.transition = `opacity ${
|
|
572
|
+
this.backdrop.style.transition = `opacity ${dur}ms ease-out`;
|
|
508
573
|
}
|
|
509
574
|
const cycle = ++this.cycleNonce;
|
|
510
575
|
return new Promise((resolve) => {
|
|
@@ -516,7 +581,7 @@ var OverlayEngine = class {
|
|
|
516
581
|
this.element.style.opacity = "1";
|
|
517
582
|
if (this.backdrop) {
|
|
518
583
|
this.backdrop.style.opacity = String(this.backdropOpacity);
|
|
519
|
-
this.backdrop.style.pointerEvents = "auto";
|
|
584
|
+
this.backdrop.style.pointerEvents = this.backdropOpacity > 0 ? "auto" : "none";
|
|
520
585
|
if (this.backdropFilter) {
|
|
521
586
|
this.backdrop.style.backdropFilter = this.backdropFilter;
|
|
522
587
|
this.backdrop.style.webkitBackdropFilter = this.backdropFilter;
|
|
@@ -552,7 +617,10 @@ var OverlayEngine = class {
|
|
|
552
617
|
});
|
|
553
618
|
return resolve();
|
|
554
619
|
}
|
|
555
|
-
this.awaitTransition(
|
|
620
|
+
this.awaitTransition(
|
|
621
|
+
cycle,
|
|
622
|
+
this.enterAnimation === "fade" ? "opacity" : "transform"
|
|
623
|
+
).then(() => {
|
|
556
624
|
if (this.destroyed || cycle !== this.cycleNonce) return resolve();
|
|
557
625
|
this.isAnimating_ = false;
|
|
558
626
|
this.element.setAttribute("data-state", "open");
|
|
@@ -569,11 +637,14 @@ var OverlayEngine = class {
|
|
|
569
637
|
this.emit("before-close", void 0);
|
|
570
638
|
this.isOpen_ = false;
|
|
571
639
|
this.isAnimating_ = true;
|
|
640
|
+
sheetStack.update();
|
|
641
|
+
this.popBackMarker(reason);
|
|
572
642
|
this.element.setAttribute("data-state", "exiting");
|
|
573
|
-
const
|
|
643
|
+
const dur = this.effectiveDuration();
|
|
644
|
+
const transitionStr = `transform ${dur}ms ${this.exitEasing}, opacity ${dur}ms ease-in`;
|
|
574
645
|
this.element.style.transition = transitionStr;
|
|
575
646
|
if (this.backdrop) {
|
|
576
|
-
this.backdrop.style.transition = `opacity ${
|
|
647
|
+
this.backdrop.style.transition = `opacity ${dur}ms ease-in`;
|
|
577
648
|
}
|
|
578
649
|
const cycle = ++this.cycleNonce;
|
|
579
650
|
return new Promise((resolve) => {
|
|
@@ -584,7 +655,7 @@ var OverlayEngine = class {
|
|
|
584
655
|
this.exitAnimation,
|
|
585
656
|
this.peekPx
|
|
586
657
|
);
|
|
587
|
-
this.element.style.opacity = "0";
|
|
658
|
+
this.element.style.opacity = this.peekPx !== void 0 ? "1" : "0";
|
|
588
659
|
if (this.backdrop) {
|
|
589
660
|
this.backdrop.style.opacity = "0";
|
|
590
661
|
this.backdrop.style.pointerEvents = "none";
|
|
@@ -594,7 +665,10 @@ var OverlayEngine = class {
|
|
|
594
665
|
}
|
|
595
666
|
}
|
|
596
667
|
this.releaseInteractiveListeners();
|
|
597
|
-
this.awaitTransition(
|
|
668
|
+
this.awaitTransition(
|
|
669
|
+
cycle,
|
|
670
|
+
this.exitAnimation === "fade" ? "opacity" : "transform"
|
|
671
|
+
).then(() => {
|
|
598
672
|
if (this.destroyed || cycle !== this.cycleNonce) return resolve();
|
|
599
673
|
this.isAnimating_ = false;
|
|
600
674
|
if (this.peekPx === void 0) {
|
|
@@ -622,7 +696,11 @@ var OverlayEngine = class {
|
|
|
622
696
|
this.releaseInteractiveListeners();
|
|
623
697
|
this.releaseStackEntry?.();
|
|
624
698
|
this.releaseStackEntry = null;
|
|
699
|
+
const hadOriginalParent = this.originalParent !== null;
|
|
625
700
|
this.restoreMount();
|
|
701
|
+
if (this.movedToTarget && !hadOriginalParent && this.element.parentNode) {
|
|
702
|
+
this.element.parentNode.removeChild(this.element);
|
|
703
|
+
}
|
|
626
704
|
}
|
|
627
705
|
setBackdropOpacity(opacity) {
|
|
628
706
|
if (this.destroyed) return;
|
|
@@ -723,6 +801,36 @@ var OverlayEngine = class {
|
|
|
723
801
|
}
|
|
724
802
|
}
|
|
725
803
|
}
|
|
804
|
+
if (opts.duration !== void 0) this.duration = opts.duration;
|
|
805
|
+
if (opts.enterEasing !== void 0) this.enterEasing = opts.enterEasing;
|
|
806
|
+
if (opts.exitEasing !== void 0) this.exitEasing = opts.exitEasing;
|
|
807
|
+
if (opts.closeOnEscape !== void 0) {
|
|
808
|
+
this.closeOnEscape = opts.closeOnEscape;
|
|
809
|
+
if (!opts.closeOnEscape) {
|
|
810
|
+
this.detachEscape?.();
|
|
811
|
+
this.detachEscape = null;
|
|
812
|
+
} else if (this.isOpen_) {
|
|
813
|
+
this.installInteractiveListeners();
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (opts.closeOnBackdrop !== void 0) {
|
|
817
|
+
this.closeOnBackdropEnabled = opts.closeOnBackdrop;
|
|
818
|
+
if (!opts.closeOnBackdrop) {
|
|
819
|
+
this.detachBackdrop?.();
|
|
820
|
+
this.detachBackdrop = null;
|
|
821
|
+
} else if (this.isOpen_) {
|
|
822
|
+
this.installInteractiveListeners();
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (opts.closeOnOutsidePointer !== void 0) {
|
|
826
|
+
this.closeOnOutsidePointerEnabled = opts.closeOnOutsidePointer;
|
|
827
|
+
if (!opts.closeOnOutsidePointer) {
|
|
828
|
+
this.detachOutsidePointer?.();
|
|
829
|
+
this.detachOutsidePointer = null;
|
|
830
|
+
} else if (this.isOpen_) {
|
|
831
|
+
this.installInteractiveListeners();
|
|
832
|
+
}
|
|
833
|
+
}
|
|
726
834
|
if (opts.children !== void 0) {
|
|
727
835
|
if (opts.children === null) {
|
|
728
836
|
this.clearOverlayChildren();
|
|
@@ -756,6 +864,22 @@ var OverlayEngine = class {
|
|
|
756
864
|
emit(event, payload) {
|
|
757
865
|
this.bus.emit(event, payload);
|
|
758
866
|
}
|
|
867
|
+
effectiveDuration() {
|
|
868
|
+
return this.respectReducedMotionEnabled && prefersReducedMotion() ? 0 : this.duration;
|
|
869
|
+
}
|
|
870
|
+
popBackMarker(reason) {
|
|
871
|
+
if (!this.backPushed) return;
|
|
872
|
+
this.backPushed = false;
|
|
873
|
+
if (reason === "back") return;
|
|
874
|
+
const state = history.state;
|
|
875
|
+
if (state && state.__bsOverlay === this.id) {
|
|
876
|
+
try {
|
|
877
|
+
history.back();
|
|
878
|
+
} catch {
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
759
883
|
resolvePeekPx(raw) {
|
|
760
884
|
if (typeof raw === "number") return Math.max(0, raw);
|
|
761
885
|
try {
|
|
@@ -777,6 +901,7 @@ var OverlayEngine = class {
|
|
|
777
901
|
this.originalParent = this.element.parentNode;
|
|
778
902
|
this.originalNextSibling = this.element.nextSibling;
|
|
779
903
|
target.appendChild(this.element);
|
|
904
|
+
this.movedToTarget = true;
|
|
780
905
|
this.mounted = true;
|
|
781
906
|
}
|
|
782
907
|
restoreMount() {
|
|
@@ -810,7 +935,7 @@ var OverlayEngine = class {
|
|
|
810
935
|
this.backdrop.style.willChange = "opacity";
|
|
811
936
|
}
|
|
812
937
|
}
|
|
813
|
-
awaitTransition(cycle) {
|
|
938
|
+
awaitTransition(cycle, property = "transform") {
|
|
814
939
|
return new Promise((resolve) => {
|
|
815
940
|
let done = false;
|
|
816
941
|
const finish = () => {
|
|
@@ -825,10 +950,10 @@ var OverlayEngine = class {
|
|
|
825
950
|
finish();
|
|
826
951
|
return;
|
|
827
952
|
}
|
|
828
|
-
if (e.propertyName ===
|
|
953
|
+
if (e.target === this.element && e.propertyName === property) finish();
|
|
829
954
|
};
|
|
830
955
|
this.element.addEventListener("transitionend", onEnd);
|
|
831
|
-
const timer = window.setTimeout(finish, this.
|
|
956
|
+
const timer = window.setTimeout(finish, this.effectiveDuration() + 50);
|
|
832
957
|
});
|
|
833
958
|
}
|
|
834
959
|
installInteractiveListeners() {
|
|
@@ -838,7 +963,10 @@ var OverlayEngine = class {
|
|
|
838
963
|
}
|
|
839
964
|
if (this.closeOnEscape && !this.detachEscape) {
|
|
840
965
|
const handler = (e) => {
|
|
841
|
-
if (e.
|
|
966
|
+
if (e.defaultPrevented) return;
|
|
967
|
+
if (e.key === "Escape" && this.isOpen_ && this.isTop) {
|
|
968
|
+
void this.close("escape");
|
|
969
|
+
}
|
|
842
970
|
};
|
|
843
971
|
document.addEventListener("keydown", handler);
|
|
844
972
|
this.detachEscape = () => document.removeEventListener("keydown", handler);
|
|
@@ -851,10 +979,14 @@ var OverlayEngine = class {
|
|
|
851
979
|
if (this.closeOnBackEnabled && typeof window !== "undefined" && !this.detachHardwareBack) {
|
|
852
980
|
try {
|
|
853
981
|
history.pushState({ __bsOverlay: this.id }, "");
|
|
982
|
+
this.backPushed = true;
|
|
854
983
|
} catch {
|
|
855
984
|
}
|
|
856
985
|
const onPop = () => {
|
|
857
|
-
if (this.isOpen_
|
|
986
|
+
if (this.isOpen_ && this.isTop) {
|
|
987
|
+
this.backPushed = false;
|
|
988
|
+
void this.close("back");
|
|
989
|
+
}
|
|
858
990
|
};
|
|
859
991
|
window.addEventListener("popstate", onPop);
|
|
860
992
|
this.detachHardwareBack = () => window.removeEventListener("popstate", onPop);
|
|
@@ -890,43 +1022,52 @@ var OverlayEngine = class {
|
|
|
890
1022
|
const edge = this.edge;
|
|
891
1023
|
const isVertical = edge === "bottom" || edge === "top";
|
|
892
1024
|
const sign = edge === "bottom" || edge === "right" ? 1 : -1;
|
|
893
|
-
const
|
|
894
|
-
const velocityThreshold = this.swipeVelocityThreshold;
|
|
1025
|
+
const SLOP = 8;
|
|
895
1026
|
let startX = 0;
|
|
896
1027
|
let startY = 0;
|
|
897
1028
|
let startT = 0;
|
|
1029
|
+
let tracking = false;
|
|
898
1030
|
let dragging = false;
|
|
899
1031
|
let pointerId = null;
|
|
1032
|
+
const previousTouchAction = el.style.touchAction;
|
|
1033
|
+
el.style.touchAction = isVertical ? "pan-x" : "pan-y";
|
|
900
1034
|
const onDown = (e) => {
|
|
901
1035
|
if (e.button !== void 0 && e.button !== 0) return;
|
|
902
1036
|
pointerId = e.pointerId;
|
|
903
1037
|
startX = e.clientX;
|
|
904
1038
|
startY = e.clientY;
|
|
905
1039
|
startT = performance.now();
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
try {
|
|
909
|
-
el.setPointerCapture(e.pointerId);
|
|
910
|
-
} catch {
|
|
911
|
-
}
|
|
1040
|
+
tracking = true;
|
|
1041
|
+
dragging = false;
|
|
912
1042
|
};
|
|
913
1043
|
const onMove = (e) => {
|
|
914
|
-
if (!
|
|
1044
|
+
if (!tracking || e.pointerId !== pointerId) return;
|
|
915
1045
|
const delta = isVertical ? e.clientY - startY : e.clientX - startX;
|
|
1046
|
+
if (!dragging) {
|
|
1047
|
+
if (Math.abs(delta) < SLOP) return;
|
|
1048
|
+
dragging = true;
|
|
1049
|
+
el.style.transition = "none";
|
|
1050
|
+
try {
|
|
1051
|
+
el.setPointerCapture(e.pointerId);
|
|
1052
|
+
} catch {
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
916
1055
|
const offset = Math.max(0, sign * delta);
|
|
917
1056
|
el.style.transform = isVertical ? `translate3d(0, ${sign * offset}px, 0)` : `translate3d(${sign * offset}px, 0, 0)`;
|
|
918
1057
|
};
|
|
919
1058
|
const finish = (e) => {
|
|
920
|
-
if (!
|
|
921
|
-
|
|
1059
|
+
if (!tracking || e.pointerId !== pointerId) return;
|
|
1060
|
+
tracking = false;
|
|
922
1061
|
pointerId = null;
|
|
1062
|
+
if (!dragging) return;
|
|
1063
|
+
dragging = false;
|
|
923
1064
|
const dt = performance.now() - startT || 1;
|
|
924
1065
|
const delta = isVertical ? e.clientY - startY : e.clientX - startX;
|
|
925
1066
|
const offset = Math.max(0, sign * delta);
|
|
926
1067
|
const velocity = sign * delta / dt;
|
|
927
1068
|
const size = isVertical ? el.offsetHeight : el.offsetWidth;
|
|
928
|
-
const past = offset > size *
|
|
929
|
-
el.style.transition = `transform ${this.
|
|
1069
|
+
const past = offset > size * this.swipeThreshold || velocity > this.swipeVelocityThreshold;
|
|
1070
|
+
el.style.transition = `transform ${this.effectiveDuration()}ms ${this.exitEasing}`;
|
|
930
1071
|
if (past) {
|
|
931
1072
|
void this.close("swipe");
|
|
932
1073
|
} else {
|
|
@@ -938,6 +1079,7 @@ var OverlayEngine = class {
|
|
|
938
1079
|
el.addEventListener("pointerup", finish);
|
|
939
1080
|
el.addEventListener("pointercancel", finish);
|
|
940
1081
|
return () => {
|
|
1082
|
+
el.style.touchAction = previousTouchAction;
|
|
941
1083
|
el.removeEventListener("pointerdown", onDown);
|
|
942
1084
|
el.removeEventListener("pointermove", onMove);
|
|
943
1085
|
el.removeEventListener("pointerup", finish);
|
|
@@ -952,10 +1094,12 @@ var OverlayEngine = class {
|
|
|
952
1094
|
if (this.backdrop) this.backdrop.style.zIndex = String(z - 1);
|
|
953
1095
|
},
|
|
954
1096
|
setIsTop: (isTop) => {
|
|
1097
|
+
this.isTop = isTop;
|
|
955
1098
|
if (this.backdrop) {
|
|
956
1099
|
this.backdrop.style.display = isTop ? "" : "none";
|
|
957
1100
|
}
|
|
958
|
-
}
|
|
1101
|
+
},
|
|
1102
|
+
isOpen: () => this.isOpen_
|
|
959
1103
|
});
|
|
960
1104
|
}
|
|
961
1105
|
};
|
package/dist/preact.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { BottomSheet, BottomSheetFromConfig, BottomSheetFromConfigProps, BottomSheetHandle, BottomSheetProps, HeaderProp, Overlay, OverlayHandle, OverlayProps, SheetConfig, UseBottomSheetRefs, UseBottomSheetReturn, UseOverlayReturn, useBottomSheet, useOverlay } from './react.cjs';
|
|
2
|
-
export { E as EngineState,
|
|
2
|
+
export { E as EngineState, b as SheetMode, d as SnapPoint, a as SnapPointDef } from './BottomSheetEngine-BJrH7qY3.cjs';
|
|
3
3
|
export { OverlayEdge, OverlayOptions, OverlayState } from './overlay.cjs';
|
|
4
4
|
import 'react';
|
|
5
5
|
import './transform-jVfAikE9.cjs';
|
package/dist/preact.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { BottomSheet, BottomSheetFromConfig, BottomSheetFromConfigProps, BottomSheetHandle, BottomSheetProps, HeaderProp, Overlay, OverlayHandle, OverlayProps, SheetConfig, UseBottomSheetRefs, UseBottomSheetReturn, UseOverlayReturn, useBottomSheet, useOverlay } from './react.js';
|
|
2
|
-
export { E as EngineState,
|
|
2
|
+
export { E as EngineState, b as SheetMode, d as SnapPoint, a as SnapPointDef } from './BottomSheetEngine-L05jGZvU.js';
|
|
3
3
|
export { OverlayEdge, OverlayOptions, OverlayState } from './overlay.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
import './transform-jVfAikE9.js';
|