@surdeddd/bottom-sheet 0.8.1 → 0.9.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.
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 +365 -217
  43. package/dist/vue.d.cts +6 -0
  44. package/dist/vue.d.ts +6 -0
  45. package/dist/vue.js +365 -217
  46. package/package.json +6 -6
package/dist/overlay.js CHANGED
@@ -71,14 +71,6 @@ var SheetStack = class {
71
71
  };
72
72
  var sheetStack = new SheetStack();
73
73
 
74
- // src/core/primitives/transform.ts
75
- var CLOSED_TRANSFORM = {
76
- bottom: "translate3d(0, 100%, 0)",
77
- top: "translate3d(0, -100%, 0)",
78
- left: "translate3d(-100%, 0, 0)",
79
- right: "translate3d(100%, 0, 0)"
80
- };
81
-
82
74
  // src/core/primitives/cssLength.ts
83
75
  var probe = null;
84
76
  var PROBE_ATTR = "data-bs-probe";
@@ -187,9 +179,35 @@ var isVisible = (el) => {
187
179
  }
188
180
  return el.offsetParent !== null;
189
181
  };
190
- var focusables = (root) => Array.from(root.querySelectorAll(FOCUSABLE)).filter(
182
+ var collectFocusables = (root) => {
183
+ const out = Array.from(root.querySelectorAll(FOCUSABLE));
184
+ if (typeof HTMLSlotElement !== "undefined") {
185
+ for (const slot of Array.from(root.querySelectorAll("slot"))) {
186
+ for (const assigned of slot.assignedElements()) {
187
+ if (assigned.matches(FOCUSABLE)) out.push(assigned);
188
+ out.push(...collectFocusables(assigned));
189
+ }
190
+ }
191
+ }
192
+ return out;
193
+ };
194
+ var focusables = (root) => collectFocusables(root).filter(
191
195
  (el) => !el.hasAttribute("inert") && isVisible(el) && !el.matches("[aria-hidden='true']")
192
196
  );
197
+ var containsComposed = (container, node) => {
198
+ let n = node;
199
+ while (n) {
200
+ if (n === container) return true;
201
+ const slot = n.assignedSlot;
202
+ if (slot) {
203
+ n = slot;
204
+ continue;
205
+ }
206
+ const parent = n.parentNode;
207
+ n = parent instanceof ShadowRoot ? parent.host : parent;
208
+ }
209
+ return false;
210
+ };
193
211
  var trapStack = [];
194
212
  var installFocusTrap = (container, options = {}) => {
195
213
  if (typeof document === "undefined") return () => {
@@ -199,7 +217,13 @@ var installFocusTrap = (container, options = {}) => {
199
217
  const isActive = () => trapStack[trapStack.length - 1] === token;
200
218
  const previouslyFocused = document.activeElement;
201
219
  const focusInitial = () => {
202
- const initial = typeof options.initialFocus === "string" ? container.querySelector(options.initialFocus) : options.initialFocus ?? focusables(container)[0] ?? container;
220
+ const spec = options.initialFocus;
221
+ if (spec === false) {
222
+ if (!container.hasAttribute("tabindex")) container.tabIndex = -1;
223
+ container.focus({ preventScroll: true });
224
+ return;
225
+ }
226
+ const initial = typeof spec === "string" ? container.querySelector(spec) : spec ?? focusables(container)[0] ?? container;
203
227
  initial?.focus({ preventScroll: true });
204
228
  };
205
229
  focusInitial();
@@ -229,7 +253,7 @@ var installFocusTrap = (container, options = {}) => {
229
253
  const handleFocusIn = (e) => {
230
254
  if (!isActive()) return;
231
255
  const target = e.target;
232
- if (target && !container.contains(target)) {
256
+ if (target && !containsComposed(container, target)) {
233
257
  const list = focusables(container);
234
258
  list[0]?.focus({ preventScroll: true });
235
259
  }
@@ -266,8 +290,14 @@ var lockBodyScroll = () => {
266
290
  position: body.style.position,
267
291
  top: body.style.top,
268
292
  width: body.style.width,
293
+ paddingRight: body.style.paddingRight,
269
294
  scrollY: window.scrollY
270
295
  };
296
+ const scrollbarGap = window.innerWidth - document.documentElement.clientWidth;
297
+ if (scrollbarGap > 0) {
298
+ const current = parseFloat(getComputedStyle(body).paddingRight) || 0;
299
+ body.style.paddingRight = `${current + scrollbarGap}px`;
300
+ }
271
301
  body.style.overflow = "hidden";
272
302
  body.style.position = "fixed";
273
303
  body.style.top = `-${savedStyles.scrollY}px`;
@@ -285,6 +315,7 @@ var lockBodyScroll = () => {
285
315
  body.style.position = savedStyles.position;
286
316
  body.style.top = savedStyles.top;
287
317
  body.style.width = savedStyles.width;
318
+ body.style.paddingRight = savedStyles.paddingRight;
288
319
  window.scrollTo(0, savedStyles.scrollY);
289
320
  savedStyles = null;
290
321
  }
@@ -392,6 +423,103 @@ var prefersReducedMotion = () => {
392
423
  return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
393
424
  };
394
425
 
426
+ // src/core/primitives/transform.ts
427
+ var CLOSED_TRANSFORM = {
428
+ bottom: "translate3d(0, 100%, 0)",
429
+ top: "translate3d(0, -100%, 0)",
430
+ left: "translate3d(-100%, 0, 0)",
431
+ right: "translate3d(100%, 0, 0)"
432
+ };
433
+
434
+ // src/core/primitives/overlay-transforms.ts
435
+ var closedTransform = (edge) => CLOSED_TRANSFORM[edge];
436
+ var closedTransformFor = (edge, animation, peekPx) => {
437
+ switch (animation) {
438
+ case "fade":
439
+ return "translate3d(0, 0, 0)";
440
+ case "scale":
441
+ return "translate3d(0, 0, 0) scale(0.94)";
442
+ case "slide":
443
+ default:
444
+ if (peekPx !== void 0 && edge === "bottom") {
445
+ return `translate3d(0, calc(100% - ${peekPx}px), 0)`;
446
+ }
447
+ return closedTransform(edge);
448
+ }
449
+ };
450
+ var openTransformFor = (animation) => animation === "scale" ? "translate3d(0, 0, 0) scale(1)" : "translate3d(0, 0, 0)";
451
+
452
+ // src/core/features/overlay-swipe.ts
453
+ function installOverlaySwipe(deps) {
454
+ const el = deps.element;
455
+ const edge = deps.edge;
456
+ const isVertical = edge === "bottom" || edge === "top";
457
+ const sign = edge === "bottom" || edge === "right" ? 1 : -1;
458
+ const SLOP = 8;
459
+ let startX = 0;
460
+ let startY = 0;
461
+ let startT = 0;
462
+ let tracking = false;
463
+ let dragging = false;
464
+ let pointerId = null;
465
+ const previousTouchAction = el.style.touchAction;
466
+ el.style.touchAction = isVertical ? "pan-x" : "pan-y";
467
+ const onDown = (e) => {
468
+ if (e.button !== void 0 && e.button !== 0) return;
469
+ pointerId = e.pointerId;
470
+ startX = e.clientX;
471
+ startY = e.clientY;
472
+ startT = performance.now();
473
+ tracking = true;
474
+ dragging = false;
475
+ };
476
+ const onMove = (e) => {
477
+ if (!tracking || e.pointerId !== pointerId) return;
478
+ const delta = isVertical ? e.clientY - startY : e.clientX - startX;
479
+ if (!dragging) {
480
+ if (Math.abs(delta) < SLOP) return;
481
+ dragging = true;
482
+ el.style.transition = "none";
483
+ try {
484
+ el.setPointerCapture(e.pointerId);
485
+ } catch {
486
+ }
487
+ }
488
+ const offset = Math.max(0, sign * delta);
489
+ el.style.transform = isVertical ? `translate3d(0, ${sign * offset}px, 0)` : `translate3d(${sign * offset}px, 0, 0)`;
490
+ };
491
+ const finish = (e) => {
492
+ if (!tracking || e.pointerId !== pointerId) return;
493
+ tracking = false;
494
+ pointerId = null;
495
+ if (!dragging) return;
496
+ dragging = false;
497
+ const dt = performance.now() - startT || 1;
498
+ const delta = isVertical ? e.clientY - startY : e.clientX - startX;
499
+ const offset = Math.max(0, sign * delta);
500
+ const velocity = sign * delta / dt;
501
+ const size = isVertical ? el.offsetHeight : el.offsetWidth;
502
+ const past = offset > size * deps.getThreshold() || velocity > deps.getVelocityThreshold();
503
+ el.style.transition = deps.getExitTransition();
504
+ if (past) {
505
+ deps.close();
506
+ } else {
507
+ el.style.transform = deps.getOpenTransform();
508
+ }
509
+ };
510
+ el.addEventListener("pointerdown", onDown);
511
+ el.addEventListener("pointermove", onMove);
512
+ el.addEventListener("pointerup", finish);
513
+ el.addEventListener("pointercancel", finish);
514
+ return () => {
515
+ el.style.touchAction = previousTouchAction;
516
+ el.removeEventListener("pointerdown", onDown);
517
+ el.removeEventListener("pointermove", onMove);
518
+ el.removeEventListener("pointerup", finish);
519
+ el.removeEventListener("pointercancel", finish);
520
+ };
521
+ }
522
+
395
523
  // src/core/overlay.ts
396
524
  var OVERLAY_PRESETS = Object.freeze({
397
525
  sheet: Object.freeze({
@@ -423,22 +551,6 @@ var OVERLAY_PRESETS = Object.freeze({
423
551
  swipeToClose: false
424
552
  })
425
553
  });
426
- var closedTransform = (edge) => CLOSED_TRANSFORM[edge];
427
- var closedTransformFor = (edge, animation, peekPx) => {
428
- switch (animation) {
429
- case "fade":
430
- return "translate3d(0, 0, 0)";
431
- case "scale":
432
- return "translate3d(0, 0, 0) scale(0.94)";
433
- case "slide":
434
- default:
435
- if (peekPx !== void 0 && edge === "bottom") {
436
- return `translate3d(0, calc(100% - ${peekPx}px), 0)`;
437
- }
438
- return closedTransform(edge);
439
- }
440
- };
441
- var openTransformFor = (animation) => animation === "scale" ? "translate3d(0, 0, 0) scale(1)" : "translate3d(0, 0, 0)";
442
554
  var OverlayEngine = class {
443
555
  constructor(opts) {
444
556
  __publicField(this, "id", nextInstanceId("ovl"));
@@ -571,6 +683,7 @@ var OverlayEngine = class {
571
683
  if (this.backdrop) {
572
684
  this.backdrop.style.transition = `opacity ${dur}ms ease-out`;
573
685
  }
686
+ this.setWillChange(true);
574
687
  const cycle = ++this.cycleNonce;
575
688
  return new Promise((resolve) => {
576
689
  requestAnimationFrame(() => {
@@ -593,6 +706,7 @@ var OverlayEngine = class {
593
706
  this.releaseInteractiveListeners();
594
707
  this.isOpen_ = false;
595
708
  this.isAnimating_ = false;
709
+ this.setWillChange(false);
596
710
  this.element.style.transform = closedTransformFor(
597
711
  this.edge,
598
712
  this.enterAnimation,
@@ -623,6 +737,7 @@ var OverlayEngine = class {
623
737
  ).then(() => {
624
738
  if (this.destroyed || cycle !== this.cycleNonce) return resolve();
625
739
  this.isAnimating_ = false;
740
+ this.setWillChange(false);
626
741
  this.element.setAttribute("data-state", "open");
627
742
  this.emit("open", void 0);
628
743
  this.onOpenCb?.();
@@ -646,6 +761,7 @@ var OverlayEngine = class {
646
761
  if (this.backdrop) {
647
762
  this.backdrop.style.transition = `opacity ${dur}ms ease-in`;
648
763
  }
764
+ this.setWillChange(true);
649
765
  const cycle = ++this.cycleNonce;
650
766
  return new Promise((resolve) => {
651
767
  requestAnimationFrame(() => {
@@ -671,6 +787,7 @@ var OverlayEngine = class {
671
787
  ).then(() => {
672
788
  if (this.destroyed || cycle !== this.cycleNonce) return resolve();
673
789
  this.isAnimating_ = false;
790
+ this.setWillChange(false);
674
791
  if (this.peekPx === void 0) {
675
792
  this.element.setAttribute("hidden", "");
676
793
  }
@@ -693,6 +810,7 @@ var OverlayEngine = class {
693
810
  this.destroyed = true;
694
811
  this.cycleNonce++;
695
812
  this.bus.clear();
813
+ this.setWillChange(false);
696
814
  this.releaseInteractiveListeners();
697
815
  this.releaseStackEntry?.();
698
816
  this.releaseStackEntry = null;
@@ -918,7 +1036,6 @@ var OverlayEngine = class {
918
1036
  this.originalNextSibling = null;
919
1037
  }
920
1038
  applyClosedStyles() {
921
- this.element.style.willChange = "transform, opacity";
922
1039
  this.element.style.transform = closedTransformFor(
923
1040
  this.edge,
924
1041
  this.enterAnimation,
@@ -932,7 +1049,12 @@ var OverlayEngine = class {
932
1049
  if (this.backdrop) {
933
1050
  this.backdrop.style.opacity = "0";
934
1051
  this.backdrop.style.pointerEvents = "none";
935
- this.backdrop.style.willChange = "opacity";
1052
+ }
1053
+ }
1054
+ setWillChange(on) {
1055
+ this.element.style.willChange = on ? "transform, opacity" : "";
1056
+ if (this.backdrop) {
1057
+ this.backdrop.style.willChange = on ? "opacity" : "";
936
1058
  }
937
1059
  }
938
1060
  awaitTransition(cycle, property = "transform") {
@@ -1018,73 +1140,15 @@ var OverlayEngine = class {
1018
1140
  this.lifecycle.release();
1019
1141
  }
1020
1142
  installSwipeToClose() {
1021
- const el = this.element;
1022
- const edge = this.edge;
1023
- const isVertical = edge === "bottom" || edge === "top";
1024
- const sign = edge === "bottom" || edge === "right" ? 1 : -1;
1025
- const SLOP = 8;
1026
- let startX = 0;
1027
- let startY = 0;
1028
- let startT = 0;
1029
- let tracking = false;
1030
- let dragging = false;
1031
- let pointerId = null;
1032
- const previousTouchAction = el.style.touchAction;
1033
- el.style.touchAction = isVertical ? "pan-x" : "pan-y";
1034
- const onDown = (e) => {
1035
- if (e.button !== void 0 && e.button !== 0) return;
1036
- pointerId = e.pointerId;
1037
- startX = e.clientX;
1038
- startY = e.clientY;
1039
- startT = performance.now();
1040
- tracking = true;
1041
- dragging = false;
1042
- };
1043
- const onMove = (e) => {
1044
- if (!tracking || e.pointerId !== pointerId) return;
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
- }
1055
- const offset = Math.max(0, sign * delta);
1056
- el.style.transform = isVertical ? `translate3d(0, ${sign * offset}px, 0)` : `translate3d(${sign * offset}px, 0, 0)`;
1057
- };
1058
- const finish = (e) => {
1059
- if (!tracking || e.pointerId !== pointerId) return;
1060
- tracking = false;
1061
- pointerId = null;
1062
- if (!dragging) return;
1063
- dragging = false;
1064
- const dt = performance.now() - startT || 1;
1065
- const delta = isVertical ? e.clientY - startY : e.clientX - startX;
1066
- const offset = Math.max(0, sign * delta);
1067
- const velocity = sign * delta / dt;
1068
- const size = isVertical ? el.offsetHeight : el.offsetWidth;
1069
- const past = offset > size * this.swipeThreshold || velocity > this.swipeVelocityThreshold;
1070
- el.style.transition = `transform ${this.effectiveDuration()}ms ${this.exitEasing}`;
1071
- if (past) {
1072
- void this.close("swipe");
1073
- } else {
1074
- el.style.transform = openTransformFor(this.enterAnimation);
1075
- }
1076
- };
1077
- el.addEventListener("pointerdown", onDown);
1078
- el.addEventListener("pointermove", onMove);
1079
- el.addEventListener("pointerup", finish);
1080
- el.addEventListener("pointercancel", finish);
1081
- return () => {
1082
- el.style.touchAction = previousTouchAction;
1083
- el.removeEventListener("pointerdown", onDown);
1084
- el.removeEventListener("pointermove", onMove);
1085
- el.removeEventListener("pointerup", finish);
1086
- el.removeEventListener("pointercancel", finish);
1087
- };
1143
+ return installOverlaySwipe({
1144
+ element: this.element,
1145
+ edge: this.edge,
1146
+ getThreshold: () => this.swipeThreshold,
1147
+ getVelocityThreshold: () => this.swipeVelocityThreshold,
1148
+ getExitTransition: () => `transform ${this.effectiveDuration()}ms ${this.exitEasing}`,
1149
+ getOpenTransform: () => openTransformFor(this.enterAnimation),
1150
+ close: () => void this.close("swipe")
1151
+ });
1088
1152
  }
1089
1153
  registerInStack() {
1090
1154
  this.releaseStackEntry = sheetStack.push({
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, b as SheetMode, d as SnapPoint, a as SnapPointDef } from './BottomSheetEngine-7BDK2OWX.cjs';
2
+ export { E as EngineState, b as SheetMode, d as SnapPoint, a as SnapPointDef } from './BottomSheetEngine-BcyruNP1.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, b as SheetMode, d as SnapPoint, a as SnapPointDef } from './BottomSheetEngine-BFTb0-4Z.js';
2
+ export { E as EngineState, b as SheetMode, d as SnapPoint, a as SnapPointDef } from './BottomSheetEngine-CBRcBwV-.js';
3
3
  export { OverlayEdge, OverlayOptions, OverlayState } from './overlay.js';
4
4
  import 'react';
5
5
  import './transform-jVfAikE9.js';