@surdeddd/bottom-sheet 0.8.2 → 0.9.1

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.
Files changed (46) hide show
  1. package/dist/{BottomSheetEngine-7BDK2OWX.d.cts → BottomSheetEngine-BcyruNP1.d.cts} +12 -6
  2. package/dist/{BottomSheetEngine-BFTb0-4Z.d.ts → BottomSheetEngine-CBRcBwV-.d.ts} +12 -6
  3. package/dist/element.cjs +530 -349
  4. package/dist/element.d.cts +2 -1
  5. package/dist/element.d.ts +2 -1
  6. package/dist/element.iife.global.js +2 -2
  7. package/dist/element.js +530 -349
  8. package/dist/index.cjs +438 -294
  9. package/dist/index.d.cts +3 -3
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.js +438 -294
  12. package/dist/integrations/formik.d.cts +1 -1
  13. package/dist/integrations/formik.d.ts +1 -1
  14. package/dist/integrations/react-hook-form.d.cts +1 -1
  15. package/dist/integrations/react-hook-form.d.ts +1 -1
  16. package/dist/overlay.cjs +160 -96
  17. package/dist/overlay.d.cts +2 -0
  18. package/dist/overlay.d.ts +2 -0
  19. package/dist/overlay.js +160 -96
  20. package/dist/preact.d.cts +1 -1
  21. package/dist/preact.d.ts +1 -1
  22. package/dist/qwik.cjs +387 -211
  23. package/dist/qwik.d.cts +4 -3
  24. package/dist/qwik.d.ts +4 -3
  25. package/dist/qwik.js +387 -211
  26. package/dist/react.cjs +472 -296
  27. package/dist/react.d.cts +3 -2
  28. package/dist/react.d.ts +3 -2
  29. package/dist/react.js +472 -296
  30. package/dist/solid.cjs +417 -215
  31. package/dist/solid.d.cts +21 -7
  32. package/dist/solid.d.ts +21 -7
  33. package/dist/solid.js +417 -215
  34. package/dist/solid.source.jsx +412 -209
  35. package/dist/svelte-core.cjs +328 -209
  36. package/dist/svelte-core.js +328 -209
  37. package/dist/svelte-src/BottomSheet.svelte +56 -0
  38. package/dist/svelte.cjs +365 -210
  39. package/dist/svelte.d.cts +4 -0
  40. package/dist/svelte.d.ts +4 -0
  41. package/dist/svelte.js +365 -210
  42. package/dist/vue.cjs +358 -211
  43. package/dist/vue.d.cts +6 -0
  44. package/dist/vue.d.ts +6 -0
  45. package/dist/vue.js +358 -211
  46. package/package.json +6 -6
@@ -1,4 +1,4 @@
1
- import { e as SheetEventMap } from '../BottomSheetEngine-7BDK2OWX.cjs';
1
+ import { e as SheetEventMap } from '../BottomSheetEngine-BcyruNP1.cjs';
2
2
  import '../transform-jVfAikE9.cjs';
3
3
 
4
4
  type FormikStateLike = {
@@ -1,4 +1,4 @@
1
- import { e as SheetEventMap } from '../BottomSheetEngine-BFTb0-4Z.js';
1
+ import { e as SheetEventMap } from '../BottomSheetEngine-CBRcBwV-.js';
2
2
  import '../transform-jVfAikE9.js';
3
3
 
4
4
  type FormikStateLike = {
@@ -1,4 +1,4 @@
1
- import { e as SheetEventMap } from '../BottomSheetEngine-7BDK2OWX.cjs';
1
+ import { e as SheetEventMap } from '../BottomSheetEngine-BcyruNP1.cjs';
2
2
  import '../transform-jVfAikE9.cjs';
3
3
 
4
4
  type RhfFormStateLike = {
@@ -1,4 +1,4 @@
1
- import { e as SheetEventMap } from '../BottomSheetEngine-BFTb0-4Z.js';
1
+ import { e as SheetEventMap } from '../BottomSheetEngine-CBRcBwV-.js';
2
2
  import '../transform-jVfAikE9.js';
3
3
 
4
4
  type RhfFormStateLike = {
package/dist/overlay.cjs CHANGED
@@ -73,14 +73,6 @@ var SheetStack = class {
73
73
  };
74
74
  var sheetStack = new SheetStack();
75
75
 
76
- // src/core/primitives/transform.ts
77
- var CLOSED_TRANSFORM = {
78
- bottom: "translate3d(0, 100%, 0)",
79
- top: "translate3d(0, -100%, 0)",
80
- left: "translate3d(-100%, 0, 0)",
81
- right: "translate3d(100%, 0, 0)"
82
- };
83
-
84
76
  // src/core/primitives/cssLength.ts
85
77
  var probe = null;
86
78
  var PROBE_ATTR = "data-bs-probe";
@@ -189,9 +181,35 @@ var isVisible = (el) => {
189
181
  }
190
182
  return el.offsetParent !== null;
191
183
  };
192
- var focusables = (root) => Array.from(root.querySelectorAll(FOCUSABLE)).filter(
184
+ var collectFocusables = (root) => {
185
+ const out = Array.from(root.querySelectorAll(FOCUSABLE));
186
+ if (typeof HTMLSlotElement !== "undefined") {
187
+ for (const slot of Array.from(root.querySelectorAll("slot"))) {
188
+ for (const assigned of slot.assignedElements()) {
189
+ if (assigned.matches(FOCUSABLE)) out.push(assigned);
190
+ out.push(...collectFocusables(assigned));
191
+ }
192
+ }
193
+ }
194
+ return out;
195
+ };
196
+ var focusables = (root) => collectFocusables(root).filter(
193
197
  (el) => !el.hasAttribute("inert") && isVisible(el) && !el.matches("[aria-hidden='true']")
194
198
  );
199
+ var containsComposed = (container, node) => {
200
+ let n = node;
201
+ while (n) {
202
+ if (n === container) return true;
203
+ const slot = n.assignedSlot;
204
+ if (slot) {
205
+ n = slot;
206
+ continue;
207
+ }
208
+ const parent = n.parentNode;
209
+ n = parent instanceof ShadowRoot ? parent.host : parent;
210
+ }
211
+ return false;
212
+ };
195
213
  var trapStack = [];
196
214
  var installFocusTrap = (container, options = {}) => {
197
215
  if (typeof document === "undefined") return () => {
@@ -201,7 +219,13 @@ var installFocusTrap = (container, options = {}) => {
201
219
  const isActive = () => trapStack[trapStack.length - 1] === token;
202
220
  const previouslyFocused = document.activeElement;
203
221
  const focusInitial = () => {
204
- const initial = typeof options.initialFocus === "string" ? container.querySelector(options.initialFocus) : options.initialFocus ?? focusables(container)[0] ?? container;
222
+ const spec = options.initialFocus;
223
+ if (spec === false) {
224
+ if (!container.hasAttribute("tabindex")) container.tabIndex = -1;
225
+ container.focus({ preventScroll: true });
226
+ return;
227
+ }
228
+ const initial = typeof spec === "string" ? container.querySelector(spec) : spec ?? focusables(container)[0] ?? container;
205
229
  initial?.focus({ preventScroll: true });
206
230
  };
207
231
  focusInitial();
@@ -231,7 +255,7 @@ var installFocusTrap = (container, options = {}) => {
231
255
  const handleFocusIn = (e) => {
232
256
  if (!isActive()) return;
233
257
  const target = e.target;
234
- if (target && !container.contains(target)) {
258
+ if (target && !containsComposed(container, target)) {
235
259
  const list = focusables(container);
236
260
  list[0]?.focus({ preventScroll: true });
237
261
  }
@@ -268,8 +292,14 @@ var lockBodyScroll = () => {
268
292
  position: body.style.position,
269
293
  top: body.style.top,
270
294
  width: body.style.width,
295
+ paddingRight: body.style.paddingRight,
271
296
  scrollY: window.scrollY
272
297
  };
298
+ const scrollbarGap = window.innerWidth - document.documentElement.clientWidth;
299
+ if (scrollbarGap > 0) {
300
+ const current = parseFloat(getComputedStyle(body).paddingRight) || 0;
301
+ body.style.paddingRight = `${current + scrollbarGap}px`;
302
+ }
273
303
  body.style.overflow = "hidden";
274
304
  body.style.position = "fixed";
275
305
  body.style.top = `-${savedStyles.scrollY}px`;
@@ -287,6 +317,7 @@ var lockBodyScroll = () => {
287
317
  body.style.position = savedStyles.position;
288
318
  body.style.top = savedStyles.top;
289
319
  body.style.width = savedStyles.width;
320
+ body.style.paddingRight = savedStyles.paddingRight;
290
321
  window.scrollTo(0, savedStyles.scrollY);
291
322
  savedStyles = null;
292
323
  }
@@ -394,6 +425,103 @@ var prefersReducedMotion = () => {
394
425
  return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
395
426
  };
396
427
 
428
+ // src/core/primitives/transform.ts
429
+ var CLOSED_TRANSFORM = {
430
+ bottom: "translate3d(0, 100%, 0)",
431
+ top: "translate3d(0, -100%, 0)",
432
+ left: "translate3d(-100%, 0, 0)",
433
+ right: "translate3d(100%, 0, 0)"
434
+ };
435
+
436
+ // src/core/primitives/overlay-transforms.ts
437
+ var closedTransform = (edge) => CLOSED_TRANSFORM[edge];
438
+ var closedTransformFor = (edge, animation, peekPx) => {
439
+ switch (animation) {
440
+ case "fade":
441
+ return "translate3d(0, 0, 0)";
442
+ case "scale":
443
+ return "translate3d(0, 0, 0) scale(0.94)";
444
+ case "slide":
445
+ default:
446
+ if (peekPx !== void 0 && edge === "bottom") {
447
+ return `translate3d(0, calc(100% - ${peekPx}px), 0)`;
448
+ }
449
+ return closedTransform(edge);
450
+ }
451
+ };
452
+ var openTransformFor = (animation) => animation === "scale" ? "translate3d(0, 0, 0) scale(1)" : "translate3d(0, 0, 0)";
453
+
454
+ // src/core/features/overlay-swipe.ts
455
+ function installOverlaySwipe(deps) {
456
+ const el = deps.element;
457
+ const edge = deps.edge;
458
+ const isVertical = edge === "bottom" || edge === "top";
459
+ const sign = edge === "bottom" || edge === "right" ? 1 : -1;
460
+ const SLOP = 8;
461
+ let startX = 0;
462
+ let startY = 0;
463
+ let startT = 0;
464
+ let tracking = false;
465
+ let dragging = false;
466
+ let pointerId = null;
467
+ const previousTouchAction = el.style.touchAction;
468
+ el.style.touchAction = isVertical ? "pan-x" : "pan-y";
469
+ const onDown = (e) => {
470
+ if (e.button !== void 0 && e.button !== 0) return;
471
+ pointerId = e.pointerId;
472
+ startX = e.clientX;
473
+ startY = e.clientY;
474
+ startT = performance.now();
475
+ tracking = true;
476
+ dragging = false;
477
+ };
478
+ const onMove = (e) => {
479
+ if (!tracking || e.pointerId !== pointerId) return;
480
+ const delta = isVertical ? e.clientY - startY : e.clientX - startX;
481
+ if (!dragging) {
482
+ if (Math.abs(delta) < SLOP) return;
483
+ dragging = true;
484
+ el.style.transition = "none";
485
+ try {
486
+ el.setPointerCapture(e.pointerId);
487
+ } catch {
488
+ }
489
+ }
490
+ const offset = Math.max(0, sign * delta);
491
+ el.style.transform = isVertical ? `translate3d(0, ${sign * offset}px, 0)` : `translate3d(${sign * offset}px, 0, 0)`;
492
+ };
493
+ const finish = (e) => {
494
+ if (!tracking || e.pointerId !== pointerId) return;
495
+ tracking = false;
496
+ pointerId = null;
497
+ if (!dragging) return;
498
+ dragging = false;
499
+ const dt = performance.now() - startT || 1;
500
+ const delta = isVertical ? e.clientY - startY : e.clientX - startX;
501
+ const offset = Math.max(0, sign * delta);
502
+ const velocity = sign * delta / dt;
503
+ const size = isVertical ? el.offsetHeight : el.offsetWidth;
504
+ const past = offset > size * deps.getThreshold() || velocity > deps.getVelocityThreshold();
505
+ el.style.transition = deps.getExitTransition();
506
+ if (past) {
507
+ deps.close();
508
+ } else {
509
+ el.style.transform = deps.getOpenTransform();
510
+ }
511
+ };
512
+ el.addEventListener("pointerdown", onDown);
513
+ el.addEventListener("pointermove", onMove);
514
+ el.addEventListener("pointerup", finish);
515
+ el.addEventListener("pointercancel", finish);
516
+ return () => {
517
+ el.style.touchAction = previousTouchAction;
518
+ el.removeEventListener("pointerdown", onDown);
519
+ el.removeEventListener("pointermove", onMove);
520
+ el.removeEventListener("pointerup", finish);
521
+ el.removeEventListener("pointercancel", finish);
522
+ };
523
+ }
524
+
397
525
  // src/core/overlay.ts
398
526
  var OVERLAY_PRESETS = Object.freeze({
399
527
  sheet: Object.freeze({
@@ -425,22 +553,6 @@ var OVERLAY_PRESETS = Object.freeze({
425
553
  swipeToClose: false
426
554
  })
427
555
  });
428
- var closedTransform = (edge) => CLOSED_TRANSFORM[edge];
429
- var closedTransformFor = (edge, animation, peekPx) => {
430
- switch (animation) {
431
- case "fade":
432
- return "translate3d(0, 0, 0)";
433
- case "scale":
434
- return "translate3d(0, 0, 0) scale(0.94)";
435
- case "slide":
436
- default:
437
- if (peekPx !== void 0 && edge === "bottom") {
438
- return `translate3d(0, calc(100% - ${peekPx}px), 0)`;
439
- }
440
- return closedTransform(edge);
441
- }
442
- };
443
- var openTransformFor = (animation) => animation === "scale" ? "translate3d(0, 0, 0) scale(1)" : "translate3d(0, 0, 0)";
444
556
  var OverlayEngine = class {
445
557
  constructor(opts) {
446
558
  __publicField(this, "id", nextInstanceId("ovl"));
@@ -573,6 +685,7 @@ var OverlayEngine = class {
573
685
  if (this.backdrop) {
574
686
  this.backdrop.style.transition = `opacity ${dur}ms ease-out`;
575
687
  }
688
+ this.setWillChange(true);
576
689
  const cycle = ++this.cycleNonce;
577
690
  return new Promise((resolve) => {
578
691
  requestAnimationFrame(() => {
@@ -595,6 +708,7 @@ var OverlayEngine = class {
595
708
  this.releaseInteractiveListeners();
596
709
  this.isOpen_ = false;
597
710
  this.isAnimating_ = false;
711
+ this.setWillChange(false);
598
712
  this.element.style.transform = closedTransformFor(
599
713
  this.edge,
600
714
  this.enterAnimation,
@@ -625,6 +739,7 @@ var OverlayEngine = class {
625
739
  ).then(() => {
626
740
  if (this.destroyed || cycle !== this.cycleNonce) return resolve();
627
741
  this.isAnimating_ = false;
742
+ this.setWillChange(false);
628
743
  this.element.setAttribute("data-state", "open");
629
744
  this.emit("open", void 0);
630
745
  this.onOpenCb?.();
@@ -648,6 +763,7 @@ var OverlayEngine = class {
648
763
  if (this.backdrop) {
649
764
  this.backdrop.style.transition = `opacity ${dur}ms ease-in`;
650
765
  }
766
+ this.setWillChange(true);
651
767
  const cycle = ++this.cycleNonce;
652
768
  return new Promise((resolve) => {
653
769
  requestAnimationFrame(() => {
@@ -673,6 +789,7 @@ var OverlayEngine = class {
673
789
  ).then(() => {
674
790
  if (this.destroyed || cycle !== this.cycleNonce) return resolve();
675
791
  this.isAnimating_ = false;
792
+ this.setWillChange(false);
676
793
  if (this.peekPx === void 0) {
677
794
  this.element.setAttribute("hidden", "");
678
795
  }
@@ -695,6 +812,7 @@ var OverlayEngine = class {
695
812
  this.destroyed = true;
696
813
  this.cycleNonce++;
697
814
  this.bus.clear();
815
+ this.setWillChange(false);
698
816
  this.releaseInteractiveListeners();
699
817
  this.releaseStackEntry?.();
700
818
  this.releaseStackEntry = null;
@@ -920,7 +1038,6 @@ var OverlayEngine = class {
920
1038
  this.originalNextSibling = null;
921
1039
  }
922
1040
  applyClosedStyles() {
923
- this.element.style.willChange = "transform, opacity";
924
1041
  this.element.style.transform = closedTransformFor(
925
1042
  this.edge,
926
1043
  this.enterAnimation,
@@ -934,7 +1051,12 @@ var OverlayEngine = class {
934
1051
  if (this.backdrop) {
935
1052
  this.backdrop.style.opacity = "0";
936
1053
  this.backdrop.style.pointerEvents = "none";
937
- this.backdrop.style.willChange = "opacity";
1054
+ }
1055
+ }
1056
+ setWillChange(on) {
1057
+ this.element.style.willChange = on ? "transform, opacity" : "";
1058
+ if (this.backdrop) {
1059
+ this.backdrop.style.willChange = on ? "opacity" : "";
938
1060
  }
939
1061
  }
940
1062
  awaitTransition(cycle, property = "transform") {
@@ -1020,73 +1142,15 @@ var OverlayEngine = class {
1020
1142
  this.lifecycle.release();
1021
1143
  }
1022
1144
  installSwipeToClose() {
1023
- const el = this.element;
1024
- const edge = this.edge;
1025
- const isVertical = edge === "bottom" || edge === "top";
1026
- const sign = edge === "bottom" || edge === "right" ? 1 : -1;
1027
- const SLOP = 8;
1028
- let startX = 0;
1029
- let startY = 0;
1030
- let startT = 0;
1031
- let tracking = false;
1032
- let dragging = false;
1033
- let pointerId = null;
1034
- const previousTouchAction = el.style.touchAction;
1035
- el.style.touchAction = isVertical ? "pan-x" : "pan-y";
1036
- const onDown = (e) => {
1037
- if (e.button !== void 0 && e.button !== 0) return;
1038
- pointerId = e.pointerId;
1039
- startX = e.clientX;
1040
- startY = e.clientY;
1041
- startT = performance.now();
1042
- tracking = true;
1043
- dragging = false;
1044
- };
1045
- const onMove = (e) => {
1046
- if (!tracking || e.pointerId !== pointerId) return;
1047
- const delta = isVertical ? e.clientY - startY : e.clientX - startX;
1048
- if (!dragging) {
1049
- if (Math.abs(delta) < SLOP) return;
1050
- dragging = true;
1051
- el.style.transition = "none";
1052
- try {
1053
- el.setPointerCapture(e.pointerId);
1054
- } catch {
1055
- }
1056
- }
1057
- const offset = Math.max(0, sign * delta);
1058
- el.style.transform = isVertical ? `translate3d(0, ${sign * offset}px, 0)` : `translate3d(${sign * offset}px, 0, 0)`;
1059
- };
1060
- const finish = (e) => {
1061
- if (!tracking || e.pointerId !== pointerId) return;
1062
- tracking = false;
1063
- pointerId = null;
1064
- if (!dragging) return;
1065
- dragging = false;
1066
- const dt = performance.now() - startT || 1;
1067
- const delta = isVertical ? e.clientY - startY : e.clientX - startX;
1068
- const offset = Math.max(0, sign * delta);
1069
- const velocity = sign * delta / dt;
1070
- const size = isVertical ? el.offsetHeight : el.offsetWidth;
1071
- const past = offset > size * this.swipeThreshold || velocity > this.swipeVelocityThreshold;
1072
- el.style.transition = `transform ${this.effectiveDuration()}ms ${this.exitEasing}`;
1073
- if (past) {
1074
- void this.close("swipe");
1075
- } else {
1076
- el.style.transform = openTransformFor(this.enterAnimation);
1077
- }
1078
- };
1079
- el.addEventListener("pointerdown", onDown);
1080
- el.addEventListener("pointermove", onMove);
1081
- el.addEventListener("pointerup", finish);
1082
- el.addEventListener("pointercancel", finish);
1083
- return () => {
1084
- el.style.touchAction = previousTouchAction;
1085
- el.removeEventListener("pointerdown", onDown);
1086
- el.removeEventListener("pointermove", onMove);
1087
- el.removeEventListener("pointerup", finish);
1088
- el.removeEventListener("pointercancel", finish);
1089
- };
1145
+ return installOverlaySwipe({
1146
+ element: this.element,
1147
+ edge: this.edge,
1148
+ getThreshold: () => this.swipeThreshold,
1149
+ getVelocityThreshold: () => this.swipeVelocityThreshold,
1150
+ getExitTransition: () => `transform ${this.effectiveDuration()}ms ${this.exitEasing}`,
1151
+ getOpenTransform: () => openTransformFor(this.enterAnimation),
1152
+ close: () => void this.close("swipe")
1153
+ });
1090
1154
  }
1091
1155
  registerInStack() {
1092
1156
  this.releaseStackEntry = sheetStack.push({
@@ -2,6 +2,7 @@ import { T as TransformAxis } from './transform-jVfAikE9.cjs';
2
2
 
3
3
  type OverlayEdge = TransformAxis;
4
4
  type OverlayAnimation = "slide" | "fade" | "scale";
5
+
5
6
  type OverlayCloseReason = "escape" | "backdrop" | "swipe" | "back" | "programmatic" | "outside-pointer";
6
7
  type SwipeToCloseConfig = {
7
8
  enabled?: boolean;
@@ -147,6 +148,7 @@ declare class OverlayEngine {
147
148
  private maybeMount;
148
149
  private restoreMount;
149
150
  private applyClosedStyles;
151
+ private setWillChange;
150
152
  private awaitTransition;
151
153
  private installInteractiveListeners;
152
154
  private releaseInteractiveListeners;
package/dist/overlay.d.ts CHANGED
@@ -2,6 +2,7 @@ import { T as TransformAxis } from './transform-jVfAikE9.js';
2
2
 
3
3
  type OverlayEdge = TransformAxis;
4
4
  type OverlayAnimation = "slide" | "fade" | "scale";
5
+
5
6
  type OverlayCloseReason = "escape" | "backdrop" | "swipe" | "back" | "programmatic" | "outside-pointer";
6
7
  type SwipeToCloseConfig = {
7
8
  enabled?: boolean;
@@ -147,6 +148,7 @@ declare class OverlayEngine {
147
148
  private maybeMount;
148
149
  private restoreMount;
149
150
  private applyClosedStyles;
151
+ private setWillChange;
150
152
  private awaitTransition;
151
153
  private installInteractiveListeners;
152
154
  private releaseInteractiveListeners;