@surdeddd/bottom-sheet 0.2.0 → 0.3.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-CAymrH-P.d.cts} +67 -1
- package/dist/{BottomSheetEngine-Df9MwBbm.d.ts → BottomSheetEngine-DcqcuudN.d.ts} +67 -1
- package/dist/element.cjs +699 -116
- package/dist/element.d.cts +7 -2
- package/dist/element.d.ts +7 -2
- package/dist/element.iife.global.js +2 -2
- package/dist/element.js +699 -116
- package/dist/index.cjs +715 -145
- package/dist/index.d.cts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +713 -146
- 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 +168 -35
- package/dist/overlay.d.cts +13 -0
- package/dist/overlay.d.ts +13 -0
- package/dist/overlay.js +168 -35
- package/dist/preact.d.cts +1 -1
- package/dist/preact.d.ts +1 -1
- package/dist/qwik.cjs +619 -119
- package/dist/qwik.d.cts +2 -2
- package/dist/qwik.d.ts +2 -2
- package/dist/qwik.js +620 -120
- package/dist/react.cjs +821 -191
- package/dist/react.d.cts +20 -3
- package/dist/react.d.ts +20 -3
- package/dist/react.js +821 -191
- package/dist/solid.cjs +656 -161
- package/dist/solid.d.cts +263 -4
- package/dist/solid.d.ts +263 -4
- package/dist/solid.js +657 -162
- package/dist/solid.source.jsx +3215 -0
- package/dist/styles.css +10 -10
- package/dist/svelte-core.cjs +3149 -0
- package/dist/svelte-core.js +3147 -0
- package/dist/svelte-src/BottomSheet.svelte +210 -0
- package/dist/svelte-src/index.js +2 -0
- package/dist/svelte.cjs +618 -124
- package/dist/svelte.d.cts +100 -0
- package/dist/svelte.d.ts +7 -3
- package/dist/svelte.js +619 -125
- package/dist/vue.cjs +612 -119
- package/dist/vue.d.cts +78 -0
- package/dist/vue.d.ts +6 -2
- package/dist/vue.js +612 -119
- package/package.json +103 -43
package/dist/overlay.js
CHANGED
|
@@ -20,6 +20,18 @@ 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
|
}
|
|
@@ -27,9 +39,24 @@ var SheetStack = class {
|
|
|
27
39
|
this.entries = [];
|
|
28
40
|
}
|
|
29
41
|
recompute() {
|
|
42
|
+
let top = null;
|
|
43
|
+
const open = [];
|
|
44
|
+
for (const entry of this.entries) {
|
|
45
|
+
if (!entry.isOpen || entry.isOpen()) {
|
|
46
|
+
top = entry;
|
|
47
|
+
open.push(entry);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!top && this.entries.length > 0) {
|
|
51
|
+
top = this.entries[this.entries.length - 1];
|
|
52
|
+
}
|
|
30
53
|
this.entries.forEach((entry, i) => {
|
|
31
54
|
entry.setZIndex(BASE_Z + i * STEP);
|
|
32
|
-
entry.setIsTop(
|
|
55
|
+
entry.setIsTop(entry === top);
|
|
56
|
+
if (entry.setDepth) {
|
|
57
|
+
const openIdx = open.indexOf(entry);
|
|
58
|
+
entry.setDepth(openIdx === -1 ? 0 : open.length - 1 - openIdx);
|
|
59
|
+
}
|
|
33
60
|
});
|
|
34
61
|
}
|
|
35
62
|
};
|
|
@@ -152,9 +179,13 @@ var isVisible = (el) => {
|
|
|
152
179
|
var focusables = (root) => Array.from(root.querySelectorAll(FOCUSABLE)).filter(
|
|
153
180
|
(el) => !el.hasAttribute("inert") && isVisible(el) && !el.matches("[aria-hidden='true']")
|
|
154
181
|
);
|
|
182
|
+
var trapStack = [];
|
|
155
183
|
var installFocusTrap = (container, options = {}) => {
|
|
156
184
|
if (typeof document === "undefined") return () => {
|
|
157
185
|
};
|
|
186
|
+
const token = {};
|
|
187
|
+
trapStack.push(token);
|
|
188
|
+
const isActive = () => trapStack[trapStack.length - 1] === token;
|
|
158
189
|
const previouslyFocused = document.activeElement;
|
|
159
190
|
const focusInitial = () => {
|
|
160
191
|
const initial = typeof options.initialFocus === "string" ? container.querySelector(options.initialFocus) : options.initialFocus ?? focusables(container)[0] ?? container;
|
|
@@ -162,6 +193,7 @@ var installFocusTrap = (container, options = {}) => {
|
|
|
162
193
|
};
|
|
163
194
|
focusInitial();
|
|
164
195
|
const handleKey = (e) => {
|
|
196
|
+
if (!isActive()) return;
|
|
165
197
|
if (e.key === "Escape" && options.onEscape) {
|
|
166
198
|
options.onEscape();
|
|
167
199
|
return;
|
|
@@ -184,6 +216,7 @@ var installFocusTrap = (container, options = {}) => {
|
|
|
184
216
|
}
|
|
185
217
|
};
|
|
186
218
|
const handleFocusIn = (e) => {
|
|
219
|
+
if (!isActive()) return;
|
|
187
220
|
const target = e.target;
|
|
188
221
|
if (target && !container.contains(target)) {
|
|
189
222
|
const list = focusables(container);
|
|
@@ -196,6 +229,8 @@ var installFocusTrap = (container, options = {}) => {
|
|
|
196
229
|
return () => {
|
|
197
230
|
if (released) return;
|
|
198
231
|
released = true;
|
|
232
|
+
const idx = trapStack.indexOf(token);
|
|
233
|
+
if (idx !== -1) trapStack.splice(idx, 1);
|
|
199
234
|
document.removeEventListener("keydown", handleKey, true);
|
|
200
235
|
document.removeEventListener("focusin", handleFocusIn, true);
|
|
201
236
|
if (previouslyFocused && document.contains(previouslyFocused)) {
|
|
@@ -251,11 +286,17 @@ function createInertSiblings(rootProvider) {
|
|
|
251
286
|
return {
|
|
252
287
|
apply() {
|
|
253
288
|
if (typeof document === "undefined") return;
|
|
254
|
-
|
|
255
|
-
|
|
289
|
+
let top = rootProvider();
|
|
290
|
+
while (top.parentElement && top.parentElement !== document.body) {
|
|
291
|
+
top = top.parentElement;
|
|
292
|
+
}
|
|
293
|
+
const parent = top.parentElement ?? document.body;
|
|
256
294
|
for (const child of Array.from(parent.children)) {
|
|
257
|
-
if (child ===
|
|
295
|
+
if (child === top) continue;
|
|
258
296
|
if (child.hasAttribute("inert")) continue;
|
|
297
|
+
if (child.classList.contains("bs-backdrop") || child.classList.contains("bs-screen") || child.classList.contains("bs-root")) {
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
259
300
|
child.setAttribute("inert", "");
|
|
260
301
|
tracked.push(child);
|
|
261
302
|
}
|
|
@@ -271,7 +312,6 @@ function createInertSiblings(rootProvider) {
|
|
|
271
312
|
var LifecycleController = class {
|
|
272
313
|
constructor(deps, opts) {
|
|
273
314
|
__publicField(this, "element");
|
|
274
|
-
__publicField(this, "closeFn");
|
|
275
315
|
__publicField(this, "focusTrapEnabled");
|
|
276
316
|
__publicField(this, "initialFocus");
|
|
277
317
|
__publicField(this, "closeOnEscape");
|
|
@@ -285,7 +325,6 @@ var LifecycleController = class {
|
|
|
285
325
|
__publicField(this, "installed", false);
|
|
286
326
|
__publicField(this, "destroyed", false);
|
|
287
327
|
this.element = deps.element;
|
|
288
|
-
this.closeFn = deps.close;
|
|
289
328
|
this.focusTrapEnabled = opts.focusTrap ?? false;
|
|
290
329
|
this.initialFocus = opts.initialFocus;
|
|
291
330
|
this.closeOnEscape = opts.closeOnEscape ?? true;
|
|
@@ -295,6 +334,9 @@ var LifecycleController = class {
|
|
|
295
334
|
this.returnFocus = opts.returnFocus;
|
|
296
335
|
this.inertSiblings = createInertSiblings(() => this.element);
|
|
297
336
|
}
|
|
337
|
+
get isInstalled() {
|
|
338
|
+
return this.installed;
|
|
339
|
+
}
|
|
298
340
|
install() {
|
|
299
341
|
if (this.destroyed) return;
|
|
300
342
|
this.installed = true;
|
|
@@ -303,8 +345,7 @@ var LifecycleController = class {
|
|
|
303
345
|
}
|
|
304
346
|
if (this.focusTrapEnabled && !this.releaseFocusTrap) {
|
|
305
347
|
this.releaseFocusTrap = installFocusTrap(this.element, {
|
|
306
|
-
initialFocus: this.initialFocus
|
|
307
|
-
onEscape: this.closeOnEscape ? () => void this.closeFn() : void 0
|
|
348
|
+
initialFocus: this.initialFocus
|
|
308
349
|
});
|
|
309
350
|
}
|
|
310
351
|
if (this.inertSiblingsEnabled && this.shouldApplyInertSiblings()) {
|
|
@@ -334,6 +375,12 @@ var LifecycleController = class {
|
|
|
334
375
|
}
|
|
335
376
|
};
|
|
336
377
|
|
|
378
|
+
// src/core/animation/animation.ts
|
|
379
|
+
var prefersReducedMotion = () => {
|
|
380
|
+
if (typeof window === "undefined" || !window.matchMedia) return false;
|
|
381
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
382
|
+
};
|
|
383
|
+
|
|
337
384
|
// src/core/overlay.ts
|
|
338
385
|
var OVERLAY_PRESETS = Object.freeze({
|
|
339
386
|
sheet: Object.freeze({
|
|
@@ -413,6 +460,10 @@ var OverlayEngine = class {
|
|
|
413
460
|
__publicField(this, "closeOnOutsidePointerEnabled");
|
|
414
461
|
__publicField(this, "detachOutsidePointer", null);
|
|
415
462
|
__publicField(this, "detachSwipe", null);
|
|
463
|
+
__publicField(this, "respectReducedMotionEnabled");
|
|
464
|
+
__publicField(this, "isTop", true);
|
|
465
|
+
__publicField(this, "backPushed", false);
|
|
466
|
+
__publicField(this, "movedToTarget", false);
|
|
416
467
|
__publicField(this, "onOpenCb");
|
|
417
468
|
__publicField(this, "onCloseCb");
|
|
418
469
|
__publicField(this, "isOpen_", false);
|
|
@@ -449,6 +500,7 @@ var OverlayEngine = class {
|
|
|
449
500
|
this.mountTarget = opts.mountTo;
|
|
450
501
|
this.peekRaw = opts.peek;
|
|
451
502
|
this.closeOnOutsidePointerEnabled = opts.closeOnOutsidePointer ?? false;
|
|
503
|
+
this.respectReducedMotionEnabled = opts.respectReducedMotion ?? true;
|
|
452
504
|
this.onOpenCb = opts.onOpen;
|
|
453
505
|
this.onCloseCb = opts.onClose;
|
|
454
506
|
if (this.peekRaw !== void 0 && this.edge !== "bottom") {
|
|
@@ -496,15 +548,17 @@ var OverlayEngine = class {
|
|
|
496
548
|
this.emit("before-open", void 0);
|
|
497
549
|
this.isOpen_ = true;
|
|
498
550
|
this.isAnimating_ = true;
|
|
551
|
+
sheetStack.promote(this.id);
|
|
499
552
|
this.element.removeAttribute("hidden");
|
|
500
553
|
this.element.setAttribute("data-state", "entering");
|
|
501
554
|
if (this.focusTrapEnabled) {
|
|
502
555
|
this.element.setAttribute("aria-modal", "true");
|
|
503
556
|
}
|
|
504
|
-
const
|
|
557
|
+
const dur = this.effectiveDuration();
|
|
558
|
+
const transitionStr = `transform ${dur}ms ${this.enterEasing}, opacity ${dur}ms ease-out`;
|
|
505
559
|
this.element.style.transition = transitionStr;
|
|
506
560
|
if (this.backdrop) {
|
|
507
|
-
this.backdrop.style.transition = `opacity ${
|
|
561
|
+
this.backdrop.style.transition = `opacity ${dur}ms ease-out`;
|
|
508
562
|
}
|
|
509
563
|
const cycle = ++this.cycleNonce;
|
|
510
564
|
return new Promise((resolve) => {
|
|
@@ -516,7 +570,7 @@ var OverlayEngine = class {
|
|
|
516
570
|
this.element.style.opacity = "1";
|
|
517
571
|
if (this.backdrop) {
|
|
518
572
|
this.backdrop.style.opacity = String(this.backdropOpacity);
|
|
519
|
-
this.backdrop.style.pointerEvents = "auto";
|
|
573
|
+
this.backdrop.style.pointerEvents = this.backdropOpacity > 0 ? "auto" : "none";
|
|
520
574
|
if (this.backdropFilter) {
|
|
521
575
|
this.backdrop.style.backdropFilter = this.backdropFilter;
|
|
522
576
|
this.backdrop.style.webkitBackdropFilter = this.backdropFilter;
|
|
@@ -552,7 +606,10 @@ var OverlayEngine = class {
|
|
|
552
606
|
});
|
|
553
607
|
return resolve();
|
|
554
608
|
}
|
|
555
|
-
this.awaitTransition(
|
|
609
|
+
this.awaitTransition(
|
|
610
|
+
cycle,
|
|
611
|
+
this.enterAnimation === "fade" ? "opacity" : "transform"
|
|
612
|
+
).then(() => {
|
|
556
613
|
if (this.destroyed || cycle !== this.cycleNonce) return resolve();
|
|
557
614
|
this.isAnimating_ = false;
|
|
558
615
|
this.element.setAttribute("data-state", "open");
|
|
@@ -569,11 +626,14 @@ var OverlayEngine = class {
|
|
|
569
626
|
this.emit("before-close", void 0);
|
|
570
627
|
this.isOpen_ = false;
|
|
571
628
|
this.isAnimating_ = true;
|
|
629
|
+
sheetStack.update();
|
|
630
|
+
this.popBackMarker(reason);
|
|
572
631
|
this.element.setAttribute("data-state", "exiting");
|
|
573
|
-
const
|
|
632
|
+
const dur = this.effectiveDuration();
|
|
633
|
+
const transitionStr = `transform ${dur}ms ${this.exitEasing}, opacity ${dur}ms ease-in`;
|
|
574
634
|
this.element.style.transition = transitionStr;
|
|
575
635
|
if (this.backdrop) {
|
|
576
|
-
this.backdrop.style.transition = `opacity ${
|
|
636
|
+
this.backdrop.style.transition = `opacity ${dur}ms ease-in`;
|
|
577
637
|
}
|
|
578
638
|
const cycle = ++this.cycleNonce;
|
|
579
639
|
return new Promise((resolve) => {
|
|
@@ -584,7 +644,7 @@ var OverlayEngine = class {
|
|
|
584
644
|
this.exitAnimation,
|
|
585
645
|
this.peekPx
|
|
586
646
|
);
|
|
587
|
-
this.element.style.opacity = "0";
|
|
647
|
+
this.element.style.opacity = this.peekPx !== void 0 ? "1" : "0";
|
|
588
648
|
if (this.backdrop) {
|
|
589
649
|
this.backdrop.style.opacity = "0";
|
|
590
650
|
this.backdrop.style.pointerEvents = "none";
|
|
@@ -594,7 +654,10 @@ var OverlayEngine = class {
|
|
|
594
654
|
}
|
|
595
655
|
}
|
|
596
656
|
this.releaseInteractiveListeners();
|
|
597
|
-
this.awaitTransition(
|
|
657
|
+
this.awaitTransition(
|
|
658
|
+
cycle,
|
|
659
|
+
this.exitAnimation === "fade" ? "opacity" : "transform"
|
|
660
|
+
).then(() => {
|
|
598
661
|
if (this.destroyed || cycle !== this.cycleNonce) return resolve();
|
|
599
662
|
this.isAnimating_ = false;
|
|
600
663
|
if (this.peekPx === void 0) {
|
|
@@ -622,7 +685,11 @@ var OverlayEngine = class {
|
|
|
622
685
|
this.releaseInteractiveListeners();
|
|
623
686
|
this.releaseStackEntry?.();
|
|
624
687
|
this.releaseStackEntry = null;
|
|
688
|
+
const hadOriginalParent = this.originalParent !== null;
|
|
625
689
|
this.restoreMount();
|
|
690
|
+
if (this.movedToTarget && !hadOriginalParent && this.element.parentNode) {
|
|
691
|
+
this.element.parentNode.removeChild(this.element);
|
|
692
|
+
}
|
|
626
693
|
}
|
|
627
694
|
setBackdropOpacity(opacity) {
|
|
628
695
|
if (this.destroyed) return;
|
|
@@ -723,6 +790,36 @@ var OverlayEngine = class {
|
|
|
723
790
|
}
|
|
724
791
|
}
|
|
725
792
|
}
|
|
793
|
+
if (opts.duration !== void 0) this.duration = opts.duration;
|
|
794
|
+
if (opts.enterEasing !== void 0) this.enterEasing = opts.enterEasing;
|
|
795
|
+
if (opts.exitEasing !== void 0) this.exitEasing = opts.exitEasing;
|
|
796
|
+
if (opts.closeOnEscape !== void 0) {
|
|
797
|
+
this.closeOnEscape = opts.closeOnEscape;
|
|
798
|
+
if (!opts.closeOnEscape) {
|
|
799
|
+
this.detachEscape?.();
|
|
800
|
+
this.detachEscape = null;
|
|
801
|
+
} else if (this.isOpen_) {
|
|
802
|
+
this.installInteractiveListeners();
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
if (opts.closeOnBackdrop !== void 0) {
|
|
806
|
+
this.closeOnBackdropEnabled = opts.closeOnBackdrop;
|
|
807
|
+
if (!opts.closeOnBackdrop) {
|
|
808
|
+
this.detachBackdrop?.();
|
|
809
|
+
this.detachBackdrop = null;
|
|
810
|
+
} else if (this.isOpen_) {
|
|
811
|
+
this.installInteractiveListeners();
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
if (opts.closeOnOutsidePointer !== void 0) {
|
|
815
|
+
this.closeOnOutsidePointerEnabled = opts.closeOnOutsidePointer;
|
|
816
|
+
if (!opts.closeOnOutsidePointer) {
|
|
817
|
+
this.detachOutsidePointer?.();
|
|
818
|
+
this.detachOutsidePointer = null;
|
|
819
|
+
} else if (this.isOpen_) {
|
|
820
|
+
this.installInteractiveListeners();
|
|
821
|
+
}
|
|
822
|
+
}
|
|
726
823
|
if (opts.children !== void 0) {
|
|
727
824
|
if (opts.children === null) {
|
|
728
825
|
this.clearOverlayChildren();
|
|
@@ -756,6 +853,22 @@ var OverlayEngine = class {
|
|
|
756
853
|
emit(event, payload) {
|
|
757
854
|
this.bus.emit(event, payload);
|
|
758
855
|
}
|
|
856
|
+
effectiveDuration() {
|
|
857
|
+
return this.respectReducedMotionEnabled && prefersReducedMotion() ? 0 : this.duration;
|
|
858
|
+
}
|
|
859
|
+
popBackMarker(reason) {
|
|
860
|
+
if (!this.backPushed) return;
|
|
861
|
+
this.backPushed = false;
|
|
862
|
+
if (reason === "back") return;
|
|
863
|
+
const state = history.state;
|
|
864
|
+
if (state && state.__bsOverlay === this.id) {
|
|
865
|
+
try {
|
|
866
|
+
history.back();
|
|
867
|
+
} catch {
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
759
872
|
resolvePeekPx(raw) {
|
|
760
873
|
if (typeof raw === "number") return Math.max(0, raw);
|
|
761
874
|
try {
|
|
@@ -777,6 +890,7 @@ var OverlayEngine = class {
|
|
|
777
890
|
this.originalParent = this.element.parentNode;
|
|
778
891
|
this.originalNextSibling = this.element.nextSibling;
|
|
779
892
|
target.appendChild(this.element);
|
|
893
|
+
this.movedToTarget = true;
|
|
780
894
|
this.mounted = true;
|
|
781
895
|
}
|
|
782
896
|
restoreMount() {
|
|
@@ -810,7 +924,7 @@ var OverlayEngine = class {
|
|
|
810
924
|
this.backdrop.style.willChange = "opacity";
|
|
811
925
|
}
|
|
812
926
|
}
|
|
813
|
-
awaitTransition(cycle) {
|
|
927
|
+
awaitTransition(cycle, property = "transform") {
|
|
814
928
|
return new Promise((resolve) => {
|
|
815
929
|
let done = false;
|
|
816
930
|
const finish = () => {
|
|
@@ -825,10 +939,10 @@ var OverlayEngine = class {
|
|
|
825
939
|
finish();
|
|
826
940
|
return;
|
|
827
941
|
}
|
|
828
|
-
if (e.propertyName ===
|
|
942
|
+
if (e.target === this.element && e.propertyName === property) finish();
|
|
829
943
|
};
|
|
830
944
|
this.element.addEventListener("transitionend", onEnd);
|
|
831
|
-
const timer = window.setTimeout(finish, this.
|
|
945
|
+
const timer = window.setTimeout(finish, this.effectiveDuration() + 50);
|
|
832
946
|
});
|
|
833
947
|
}
|
|
834
948
|
installInteractiveListeners() {
|
|
@@ -838,7 +952,10 @@ var OverlayEngine = class {
|
|
|
838
952
|
}
|
|
839
953
|
if (this.closeOnEscape && !this.detachEscape) {
|
|
840
954
|
const handler = (e) => {
|
|
841
|
-
if (e.
|
|
955
|
+
if (e.defaultPrevented) return;
|
|
956
|
+
if (e.key === "Escape" && this.isOpen_ && this.isTop) {
|
|
957
|
+
void this.close("escape");
|
|
958
|
+
}
|
|
842
959
|
};
|
|
843
960
|
document.addEventListener("keydown", handler);
|
|
844
961
|
this.detachEscape = () => document.removeEventListener("keydown", handler);
|
|
@@ -851,10 +968,14 @@ var OverlayEngine = class {
|
|
|
851
968
|
if (this.closeOnBackEnabled && typeof window !== "undefined" && !this.detachHardwareBack) {
|
|
852
969
|
try {
|
|
853
970
|
history.pushState({ __bsOverlay: this.id }, "");
|
|
971
|
+
this.backPushed = true;
|
|
854
972
|
} catch {
|
|
855
973
|
}
|
|
856
974
|
const onPop = () => {
|
|
857
|
-
if (this.isOpen_
|
|
975
|
+
if (this.isOpen_ && this.isTop) {
|
|
976
|
+
this.backPushed = false;
|
|
977
|
+
void this.close("back");
|
|
978
|
+
}
|
|
858
979
|
};
|
|
859
980
|
window.addEventListener("popstate", onPop);
|
|
860
981
|
this.detachHardwareBack = () => window.removeEventListener("popstate", onPop);
|
|
@@ -890,43 +1011,52 @@ var OverlayEngine = class {
|
|
|
890
1011
|
const edge = this.edge;
|
|
891
1012
|
const isVertical = edge === "bottom" || edge === "top";
|
|
892
1013
|
const sign = edge === "bottom" || edge === "right" ? 1 : -1;
|
|
893
|
-
const
|
|
894
|
-
const velocityThreshold = this.swipeVelocityThreshold;
|
|
1014
|
+
const SLOP = 8;
|
|
895
1015
|
let startX = 0;
|
|
896
1016
|
let startY = 0;
|
|
897
1017
|
let startT = 0;
|
|
1018
|
+
let tracking = false;
|
|
898
1019
|
let dragging = false;
|
|
899
1020
|
let pointerId = null;
|
|
1021
|
+
const previousTouchAction = el.style.touchAction;
|
|
1022
|
+
el.style.touchAction = isVertical ? "pan-x" : "pan-y";
|
|
900
1023
|
const onDown = (e) => {
|
|
901
1024
|
if (e.button !== void 0 && e.button !== 0) return;
|
|
902
1025
|
pointerId = e.pointerId;
|
|
903
1026
|
startX = e.clientX;
|
|
904
1027
|
startY = e.clientY;
|
|
905
1028
|
startT = performance.now();
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
try {
|
|
909
|
-
el.setPointerCapture(e.pointerId);
|
|
910
|
-
} catch {
|
|
911
|
-
}
|
|
1029
|
+
tracking = true;
|
|
1030
|
+
dragging = false;
|
|
912
1031
|
};
|
|
913
1032
|
const onMove = (e) => {
|
|
914
|
-
if (!
|
|
1033
|
+
if (!tracking || e.pointerId !== pointerId) return;
|
|
915
1034
|
const delta = isVertical ? e.clientY - startY : e.clientX - startX;
|
|
1035
|
+
if (!dragging) {
|
|
1036
|
+
if (Math.abs(delta) < SLOP) return;
|
|
1037
|
+
dragging = true;
|
|
1038
|
+
el.style.transition = "none";
|
|
1039
|
+
try {
|
|
1040
|
+
el.setPointerCapture(e.pointerId);
|
|
1041
|
+
} catch {
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
916
1044
|
const offset = Math.max(0, sign * delta);
|
|
917
1045
|
el.style.transform = isVertical ? `translate3d(0, ${sign * offset}px, 0)` : `translate3d(${sign * offset}px, 0, 0)`;
|
|
918
1046
|
};
|
|
919
1047
|
const finish = (e) => {
|
|
920
|
-
if (!
|
|
921
|
-
|
|
1048
|
+
if (!tracking || e.pointerId !== pointerId) return;
|
|
1049
|
+
tracking = false;
|
|
922
1050
|
pointerId = null;
|
|
1051
|
+
if (!dragging) return;
|
|
1052
|
+
dragging = false;
|
|
923
1053
|
const dt = performance.now() - startT || 1;
|
|
924
1054
|
const delta = isVertical ? e.clientY - startY : e.clientX - startX;
|
|
925
1055
|
const offset = Math.max(0, sign * delta);
|
|
926
1056
|
const velocity = sign * delta / dt;
|
|
927
1057
|
const size = isVertical ? el.offsetHeight : el.offsetWidth;
|
|
928
|
-
const past = offset > size *
|
|
929
|
-
el.style.transition = `transform ${this.
|
|
1058
|
+
const past = offset > size * this.swipeThreshold || velocity > this.swipeVelocityThreshold;
|
|
1059
|
+
el.style.transition = `transform ${this.effectiveDuration()}ms ${this.exitEasing}`;
|
|
930
1060
|
if (past) {
|
|
931
1061
|
void this.close("swipe");
|
|
932
1062
|
} else {
|
|
@@ -938,6 +1068,7 @@ var OverlayEngine = class {
|
|
|
938
1068
|
el.addEventListener("pointerup", finish);
|
|
939
1069
|
el.addEventListener("pointercancel", finish);
|
|
940
1070
|
return () => {
|
|
1071
|
+
el.style.touchAction = previousTouchAction;
|
|
941
1072
|
el.removeEventListener("pointerdown", onDown);
|
|
942
1073
|
el.removeEventListener("pointermove", onMove);
|
|
943
1074
|
el.removeEventListener("pointerup", finish);
|
|
@@ -952,10 +1083,12 @@ var OverlayEngine = class {
|
|
|
952
1083
|
if (this.backdrop) this.backdrop.style.zIndex = String(z - 1);
|
|
953
1084
|
},
|
|
954
1085
|
setIsTop: (isTop) => {
|
|
1086
|
+
this.isTop = isTop;
|
|
955
1087
|
if (this.backdrop) {
|
|
956
1088
|
this.backdrop.style.display = isTop ? "" : "none";
|
|
957
1089
|
}
|
|
958
|
-
}
|
|
1090
|
+
},
|
|
1091
|
+
isOpen: () => this.isOpen_
|
|
959
1092
|
});
|
|
960
1093
|
}
|
|
961
1094
|
};
|
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-CAymrH-P.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-DcqcuudN.js';
|
|
3
3
|
export { OverlayEdge, OverlayOptions, OverlayState } from './overlay.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
import './transform-jVfAikE9.js';
|