@surdeddd/bottom-sheet 0.8.2 → 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 +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
package/dist/qwik.cjs CHANGED
@@ -267,18 +267,25 @@ var SnapResolver = class {
267
267
  __publicField(this, "resolved", []);
268
268
  __publicField(this, "maxAxisSize", 0);
269
269
  __publicField(this, "rangeCache", null);
270
+ __publicField(this, "notified", false);
270
271
  this.raw = raw;
271
272
  this.allowedIds = allowed ?? raw.map((p) => p.id);
272
273
  this.recompute();
273
274
  }
274
275
  recompute() {
275
- this.resolved = resolveSnapList(this.raw, this.mode, this.measureFit);
276
- this.maxAxisSize = this.resolved.reduce(
276
+ const measure = this.measureFit;
277
+ let measured;
278
+ const measureOnce = measure ? () => measured ?? (measured = measure()) : void 0;
279
+ this.resolved = resolveSnapList(this.raw, this.mode, measureOnce);
280
+ const nextMax = this.resolved.reduce(
277
281
  (m, s) => s.size > m ? s.size : m,
278
282
  0
279
283
  );
280
284
  this.rangeCache = null;
281
- this.onMaxAxisSizeChange?.(this.maxAxisSize);
285
+ const changed = nextMax !== this.maxAxisSize || !this.notified;
286
+ this.maxAxisSize = nextMax;
287
+ this.notified = true;
288
+ if (changed) this.onMaxAxisSizeChange?.(this.maxAxisSize);
282
289
  }
283
290
  setRaw(raw) {
284
291
  this.raw = raw;
@@ -431,7 +438,10 @@ var ensureHandler = () => {
431
438
  target.consumed = true;
432
439
  const idx = closers.indexOf(target);
433
440
  if (idx !== -1) closers.splice(idx, 1);
434
- target.close();
441
+ const settled = target;
442
+ void Promise.resolve(settled.close()).then(() => {
443
+ if (settled.isOpen()) settled.restore();
444
+ });
435
445
  });
436
446
  };
437
447
  var programmaticBack = () => {
@@ -467,16 +477,7 @@ function installRoute(deps) {
467
477
  pushed = false;
468
478
  }
469
479
  };
470
- const onOpen = () => {
471
- if (closer) return;
472
- closer = {
473
- isOpen: () => !deps.isDestroyed() && deps.getSize() > 0,
474
- isTop: () => deps.isTopSheet(),
475
- close: () => void deps.close(),
476
- consumed: false
477
- };
478
- ensureHandler();
479
- closers.push(closer);
480
+ const pushEntry = () => {
480
481
  try {
481
482
  if (deps.routedTo !== void 0) {
482
483
  history.pushState({ __bsRouted: deps.sheetId }, "", deps.routedTo);
@@ -488,6 +489,25 @@ function installRoute(deps) {
488
489
  pushed = false;
489
490
  }
490
491
  };
492
+ const onOpen = () => {
493
+ if (closer) return;
494
+ const self = {
495
+ isOpen: () => !deps.isDestroyed() && deps.getSize() > 0,
496
+ isTop: () => deps.isTopSheet(),
497
+ close: () => deps.close(),
498
+ restore: () => {
499
+ if (deps.isDestroyed() || closer !== self) return;
500
+ self.consumed = false;
501
+ if (!closers.includes(self)) closers.push(self);
502
+ pushEntry();
503
+ },
504
+ consumed: false
505
+ };
506
+ closer = self;
507
+ ensureHandler();
508
+ closers.push(self);
509
+ pushEntry();
510
+ };
491
511
  const unsubscribeOpen = deps.on("open", onOpen);
492
512
  const unsubscribeClose = deps.on("close", teardownEntry);
493
513
  if (deps.getSize() > 0) onOpen();
@@ -534,11 +554,13 @@ var CONTENT_PULL_THRESHOLD = 60;
534
554
  function installContentSwipe(deps) {
535
555
  const { container } = deps;
536
556
  let startY = 0;
557
+ let startScrollTop = 0;
537
558
  let moved = false;
538
559
  const onTouchStart = (e) => {
539
560
  const t = e.touches[0];
540
561
  if (!t) return;
541
562
  startY = t.clientY;
563
+ startScrollTop = container.scrollTop;
542
564
  moved = false;
543
565
  };
544
566
  const onTouchMove = (e) => {
@@ -549,6 +571,7 @@ function installContentSwipe(deps) {
549
571
  const onTouchEnd = (e) => {
550
572
  if (!moved) return;
551
573
  if (deps.isDragging() || deps.isAnimating()) return;
574
+ if (container.scrollTop !== startScrollTop) return;
552
575
  const t = e.changedTouches[0];
553
576
  if (!t) return;
554
577
  const deltaY = t.clientY - startY;
@@ -660,6 +683,131 @@ function installResizeObserver(deps) {
660
683
  };
661
684
  }
662
685
 
686
+ // src/core/features/fit-observer.ts
687
+ var contentTargets = (scroller) => {
688
+ if (!scroller) return [];
689
+ const hasSlot = typeof HTMLSlotElement !== "undefined";
690
+ const out = [];
691
+ for (const child of Array.from(scroller.children)) {
692
+ if (hasSlot && child instanceof HTMLSlotElement) {
693
+ for (const el of child.assignedElements()) out.push(el);
694
+ } else {
695
+ out.push(child);
696
+ }
697
+ }
698
+ return out;
699
+ };
700
+ function installFitObserver(deps) {
701
+ if (typeof ResizeObserver === "undefined") return () => {
702
+ };
703
+ if (!deps.hasFitSnap()) return () => {
704
+ };
705
+ let raf = 0;
706
+ const schedule = () => {
707
+ if (raf) return;
708
+ raf = requestAnimationFrame(() => {
709
+ raf = 0;
710
+ if (deps.isDestroyed() || deps.isDragging()) return;
711
+ deps.recompute();
712
+ });
713
+ };
714
+ const ro = new ResizeObserver(schedule);
715
+ ro.observe(deps.handle);
716
+ const scroller = deps.scrollContainer;
717
+ const observed = /* @__PURE__ */ new Set();
718
+ const slots = /* @__PURE__ */ new Set();
719
+ const hasSlot = typeof HTMLSlotElement !== "undefined";
720
+ const onSlotChange = () => resync();
721
+ const trackSlots = () => {
722
+ if (!scroller || !hasSlot) return;
723
+ for (const child of Array.from(scroller.children)) {
724
+ if (child instanceof HTMLSlotElement && !slots.has(child)) {
725
+ child.addEventListener("slotchange", onSlotChange);
726
+ slots.add(child);
727
+ }
728
+ }
729
+ };
730
+ const resync = () => {
731
+ trackSlots();
732
+ const targets = contentTargets(scroller);
733
+ for (const el of observed) {
734
+ if (!targets.includes(el)) {
735
+ ro.unobserve(el);
736
+ observed.delete(el);
737
+ }
738
+ }
739
+ for (const el of targets) {
740
+ if (!observed.has(el)) {
741
+ ro.observe(el);
742
+ observed.add(el);
743
+ }
744
+ }
745
+ schedule();
746
+ };
747
+ let mo;
748
+ if (scroller) {
749
+ resync();
750
+ if (typeof MutationObserver !== "undefined") {
751
+ mo = new MutationObserver(resync);
752
+ mo.observe(scroller, { childList: true });
753
+ }
754
+ }
755
+ return () => {
756
+ ro.disconnect();
757
+ mo?.disconnect();
758
+ for (const slot of slots) {
759
+ slot.removeEventListener("slotchange", onSlotChange);
760
+ }
761
+ if (raf) cancelAnimationFrame(raf);
762
+ };
763
+ }
764
+
765
+ // src/core/features/fit-measurement.ts
766
+ var measureSheetNatural = (element, content, vertical) => {
767
+ if (!content) {
768
+ return vertical ? element.offsetHeight : element.offsetWidth;
769
+ }
770
+ const axis = vertical ? "height" : "width";
771
+ const sheetStyle = element.style;
772
+ const cs = content.style;
773
+ const prevSheet = sheetStyle[axis];
774
+ const prevFlex = cs.flex;
775
+ const prevContent = vertical ? cs.height : cs.width;
776
+ sheetStyle[axis] = "auto";
777
+ cs.flex = "none";
778
+ if (vertical) cs.height = "auto";
779
+ else cs.width = "auto";
780
+ const poked = vertical ? element.offsetHeight : element.offsetWidth;
781
+ const contentBox = vertical ? content.clientHeight : content.clientWidth;
782
+ const contentScroll = vertical ? content.scrollHeight : content.scrollWidth;
783
+ const natural = Math.max(poked, poked - contentBox + contentScroll);
784
+ sheetStyle[axis] = prevSheet;
785
+ cs.flex = prevFlex;
786
+ if (vertical) cs.height = prevContent;
787
+ else cs.width = prevContent;
788
+ return natural;
789
+ };
790
+ var containingExtent = (element, vertical) => {
791
+ const op = element.offsetParent;
792
+ if (op && op !== document.body && op !== document.documentElement) {
793
+ return vertical ? op.clientHeight : op.clientWidth;
794
+ }
795
+ return vertical ? window.innerHeight : window.innerWidth;
796
+ };
797
+ var measureFitSize = (deps) => {
798
+ const vertical = layoutAxis(deps.mode) === "height";
799
+ const natural = measureSheetNatural(
800
+ deps.element,
801
+ deps.scrollContainer,
802
+ vertical
803
+ );
804
+ const cap = deps.getMaxHeightCap();
805
+ const capped = cap !== void 0 ? Math.min(natural, cap) : natural;
806
+ if (typeof window === "undefined") return capped;
807
+ const viewport = containingExtent(deps.element, vertical);
808
+ return viewport > 0 ? Math.min(capped, viewport) : capped;
809
+ };
810
+
663
811
  // src/core/features/slider-keyboard.ts
664
812
  function installSliderKeyboard(deps) {
665
813
  const isVerticalAxis = deps.mode === "bottom" || deps.mode === "top";
@@ -1146,6 +1294,9 @@ var ScrimController = class {
1146
1294
  const s = this.screenComponent.style;
1147
1295
  s.opacity = "";
1148
1296
  s.display = "";
1297
+ s.position = "";
1298
+ s.inset = "";
1299
+ s.pointerEvents = "";
1149
1300
  }
1150
1301
  if (this.backdrop) {
1151
1302
  this.backdrop.style.opacity = "";
@@ -1394,7 +1545,12 @@ var AnimationRunner = class {
1394
1545
  this.currentSpring?.cancel();
1395
1546
  }
1396
1547
  async animateTo(target, velocityPxPerMs) {
1397
- if (target === this.getSize()) return;
1548
+ if (target === this.getSize()) {
1549
+ if (!this.isAnimating && !this.isDragging()) {
1550
+ this.element.style.willChange = "";
1551
+ }
1552
+ return;
1553
+ }
1398
1554
  this.currentTween?.cancel();
1399
1555
  this.currentSpring?.cancel();
1400
1556
  this.getRootEl()?.setAttribute("data-animating", "true");
@@ -1402,7 +1558,7 @@ var AnimationRunner = class {
1402
1558
  if (this.reducedMotion) {
1403
1559
  this.applySizeFn(target);
1404
1560
  this.getRootEl()?.removeAttribute("data-animating");
1405
- if (!this.isDragging()) this.element.style.willChange = "auto";
1561
+ if (!this.isDragging()) this.element.style.willChange = "";
1406
1562
  return;
1407
1563
  }
1408
1564
  if (this.animationKind === "spring") {
@@ -1430,7 +1586,7 @@ var AnimationRunner = class {
1430
1586
  }
1431
1587
  if (!this.isAnimating) {
1432
1588
  this.getRootEl()?.removeAttribute("data-animating");
1433
- if (!this.isDragging()) this.element.style.willChange = "auto";
1589
+ if (!this.isDragging()) this.element.style.willChange = "";
1434
1590
  }
1435
1591
  }
1436
1592
  destroy() {
@@ -1461,9 +1617,35 @@ var isVisible = (el) => {
1461
1617
  }
1462
1618
  return el.offsetParent !== null;
1463
1619
  };
1464
- var focusables = (root) => Array.from(root.querySelectorAll(FOCUSABLE)).filter(
1620
+ var collectFocusables = (root) => {
1621
+ const out = Array.from(root.querySelectorAll(FOCUSABLE));
1622
+ if (typeof HTMLSlotElement !== "undefined") {
1623
+ for (const slot of Array.from(root.querySelectorAll("slot"))) {
1624
+ for (const assigned of slot.assignedElements()) {
1625
+ if (assigned.matches(FOCUSABLE)) out.push(assigned);
1626
+ out.push(...collectFocusables(assigned));
1627
+ }
1628
+ }
1629
+ }
1630
+ return out;
1631
+ };
1632
+ var focusables = (root) => collectFocusables(root).filter(
1465
1633
  (el) => !el.hasAttribute("inert") && isVisible(el) && !el.matches("[aria-hidden='true']")
1466
1634
  );
1635
+ var containsComposed = (container, node) => {
1636
+ let n = node;
1637
+ while (n) {
1638
+ if (n === container) return true;
1639
+ const slot = n.assignedSlot;
1640
+ if (slot) {
1641
+ n = slot;
1642
+ continue;
1643
+ }
1644
+ const parent = n.parentNode;
1645
+ n = parent instanceof ShadowRoot ? parent.host : parent;
1646
+ }
1647
+ return false;
1648
+ };
1467
1649
  var trapStack = [];
1468
1650
  var installFocusTrap = (container, options = {}) => {
1469
1651
  if (typeof document === "undefined") return () => {
@@ -1473,7 +1655,13 @@ var installFocusTrap = (container, options = {}) => {
1473
1655
  const isActive = () => trapStack[trapStack.length - 1] === token;
1474
1656
  const previouslyFocused = document.activeElement;
1475
1657
  const focusInitial = () => {
1476
- const initial = typeof options.initialFocus === "string" ? container.querySelector(options.initialFocus) : options.initialFocus ?? focusables(container)[0] ?? container;
1658
+ const spec = options.initialFocus;
1659
+ if (spec === false) {
1660
+ if (!container.hasAttribute("tabindex")) container.tabIndex = -1;
1661
+ container.focus({ preventScroll: true });
1662
+ return;
1663
+ }
1664
+ const initial = typeof spec === "string" ? container.querySelector(spec) : spec ?? focusables(container)[0] ?? container;
1477
1665
  initial?.focus({ preventScroll: true });
1478
1666
  };
1479
1667
  focusInitial();
@@ -1503,7 +1691,7 @@ var installFocusTrap = (container, options = {}) => {
1503
1691
  const handleFocusIn = (e) => {
1504
1692
  if (!isActive()) return;
1505
1693
  const target = e.target;
1506
- if (target && !container.contains(target)) {
1694
+ if (target && !containsComposed(container, target)) {
1507
1695
  const list = focusables(container);
1508
1696
  list[0]?.focus({ preventScroll: true });
1509
1697
  }
@@ -1540,8 +1728,14 @@ var lockBodyScroll = () => {
1540
1728
  position: body.style.position,
1541
1729
  top: body.style.top,
1542
1730
  width: body.style.width,
1731
+ paddingRight: body.style.paddingRight,
1543
1732
  scrollY: window.scrollY
1544
1733
  };
1734
+ const scrollbarGap = window.innerWidth - document.documentElement.clientWidth;
1735
+ if (scrollbarGap > 0) {
1736
+ const current = parseFloat(getComputedStyle(body).paddingRight) || 0;
1737
+ body.style.paddingRight = `${current + scrollbarGap}px`;
1738
+ }
1545
1739
  body.style.overflow = "hidden";
1546
1740
  body.style.position = "fixed";
1547
1741
  body.style.top = `-${savedStyles.scrollY}px`;
@@ -1559,6 +1753,7 @@ var lockBodyScroll = () => {
1559
1753
  body.style.position = savedStyles.position;
1560
1754
  body.style.top = savedStyles.top;
1561
1755
  body.style.width = savedStyles.width;
1756
+ body.style.paddingRight = savedStyles.paddingRight;
1562
1757
  window.scrollTo(0, savedStyles.scrollY);
1563
1758
  savedStyles = null;
1564
1759
  }
@@ -1771,12 +1966,14 @@ var installGestures = (handle, mode, callbacks) => {
1771
1966
  handle.addEventListener("pointermove", onPointerMove);
1772
1967
  handle.addEventListener("pointerup", finishGesture);
1773
1968
  handle.addEventListener("pointercancel", onPointerCancel);
1969
+ const prevTouchAction = handle.style.touchAction;
1774
1970
  handle.style.touchAction = isAxisVertical(mode) ? "pan-x" : "pan-y";
1775
1971
  return () => {
1776
1972
  handle.removeEventListener("pointerdown", onPointerDown);
1777
1973
  handle.removeEventListener("pointermove", onPointerMove);
1778
1974
  handle.removeEventListener("pointerup", finishGesture);
1779
1975
  handle.removeEventListener("pointercancel", onPointerCancel);
1976
+ handle.style.touchAction = prevTouchAction;
1780
1977
  if (activePointerId !== null && handle.hasPointerCapture(activePointerId)) {
1781
1978
  handle.releasePointerCapture(activePointerId);
1782
1979
  }
@@ -1903,7 +2100,7 @@ var GestureController = class {
1903
2100
  this.isDragging_ = false;
1904
2101
  this.keyboardDismissed = false;
1905
2102
  this.deps.getRoot()?.removeAttribute("data-dragging");
1906
- this.deps.element.style.willChange = "auto";
2103
+ this.deps.element.style.willChange = "";
1907
2104
  }
1908
2105
  };
1909
2106
 
@@ -2302,8 +2499,7 @@ function resolveEngineOptions(opts, extras) {
2302
2499
  };
2303
2500
  }
2304
2501
 
2305
- // src/core/BottomSheetEngine.ts
2306
- var HAPTIC_DURATION_MS = 8;
2502
+ // src/core/primitives/teardown-stack.ts
2307
2503
  var TeardownStack = class {
2308
2504
  constructor() {
2309
2505
  __publicField(this, "fns", []);
@@ -2323,6 +2519,9 @@ var TeardownStack = class {
2323
2519
  }
2324
2520
  }
2325
2521
  };
2522
+
2523
+ // src/core/BottomSheetEngine.ts
2524
+ var HAPTIC_DURATION_MS = 8;
2326
2525
  var BottomSheetEngine = class {
2327
2526
  constructor(opts) {
2328
2527
  __publicField(this, "id", nextInstanceId("bs"));
@@ -2347,6 +2546,7 @@ var BottomSheetEngine = class {
2347
2546
  __publicField(this, "disableDragFlag");
2348
2547
  __publicField(this, "closeOnRouteChange");
2349
2548
  __publicField(this, "maxHeightCap");
2549
+ __publicField(this, "maxHeightRaw");
2350
2550
  __publicField(this, "snapPointsRaw");
2351
2551
  __publicField(this, "snaps");
2352
2552
  __publicField(this, "activeId");
@@ -2382,6 +2582,7 @@ var BottomSheetEngine = class {
2382
2582
  __publicField(this, "detachScrimStages", null);
2383
2583
  __publicField(this, "stackEffectEnabled", false);
2384
2584
  __publicField(this, "stackEffectPrimed", false);
2585
+ __publicField(this, "fitDeps");
2385
2586
  __publicField(this, "transformTemplate");
2386
2587
  const resolved = resolveEngineOptions(opts, {
2387
2588
  shouldApplyInertSiblings: () => {
@@ -2454,12 +2655,19 @@ var BottomSheetEngine = class {
2454
2655
  }
2455
2656
  this.activeId = resolved.initialId;
2456
2657
  auditVhUsage(this.snapPointsRaw);
2658
+ this.auditDuplicateSnapIds(this.snapPointsRaw);
2457
2659
  this.rootEl = this.element.closest(".bs-root");
2660
+ this.fitDeps = {
2661
+ element: this.element,
2662
+ scrollContainer: this.scrollContainer,
2663
+ mode: this.mode,
2664
+ getMaxHeightCap: () => this.maxHeightCap
2665
+ };
2458
2666
  this.snaps = new SnapResolver(
2459
2667
  this.snapPointsRaw,
2460
2668
  resolved.initialAllowed,
2461
2669
  this.mode,
2462
- () => this.measureFitSize(),
2670
+ () => measureFitSize(this.fitDeps),
2463
2671
  (maxAxisSize) => {
2464
2672
  this.element.style[layoutAxis(this.mode)] = `${maxAxisSize}px`;
2465
2673
  }
@@ -2493,7 +2701,18 @@ var BottomSheetEngine = class {
2493
2701
  io.observe(this.element);
2494
2702
  this.teardowns.add(() => io.disconnect());
2495
2703
  }
2496
- this.installFitObserver();
2704
+ this.teardowns.add(
2705
+ installFitObserver({
2706
+ handle: this.handle,
2707
+ scrollContainer: this.scrollContainer,
2708
+ hasFitSnap: () => this.snapPointsRaw.some(
2709
+ (p) => p.size === "fit" || p.size === "content"
2710
+ ),
2711
+ isDestroyed: () => this.destroyed,
2712
+ isDragging: () => this.gesture?.isDragging ?? false,
2713
+ recompute: () => this.recompute()
2714
+ })
2715
+ );
2497
2716
  if (resolved.radius !== void 0) this.setRadius(resolved.radius);
2498
2717
  if (resolved.maxHeight !== void 0) this.setMaxHeight(resolved.maxHeight);
2499
2718
  this.applyAutoAriaLabelledBy();
@@ -2644,27 +2863,33 @@ var BottomSheetEngine = class {
2644
2863
  } else {
2645
2864
  await this.animation.animateTo(target.size, velocityPxPerMs);
2646
2865
  }
2647
- this.opening = false;
2648
2866
  externalSignal?.removeEventListener("abort", onExternalAbort);
2649
2867
  if (signal.aborted) return;
2650
- this.scrollCache.restore(id, previousSize, target.size);
2868
+ this.opening = false;
2869
+ this.completeSnap(id, target.size, previousSize, wasClosed, false);
2870
+ }
2871
+ completeSnap(id, targetSize, previousSize, wasClosed, withHaptic) {
2872
+ this.scrollCache.restore(id, previousSize, targetSize);
2651
2873
  this.updateAriaSlider();
2652
2874
  this.emit("snap", {
2653
2875
  id,
2654
2876
  size: this.size,
2655
2877
  progress: this.computeProgress(this.size)
2656
2878
  });
2657
- if (wasClosed && target.size > 0) {
2658
- this.emit("open", { id });
2659
- this.handleOpen();
2660
- notifyLinkedSheets(this.linkedSheets, this);
2661
- this.emit("opened", { id });
2662
- }
2663
- if (target.size === 0) {
2664
- this.emit("close", void 0);
2665
- this.handleClose();
2666
- this.emit("closed", void 0);
2667
- }
2879
+ if (withHaptic) this.haptic();
2880
+ if (wasClosed && targetSize > 0) this.emitOpenSequence(id);
2881
+ if (targetSize === 0) this.emitCloseSequence();
2882
+ }
2883
+ emitOpenSequence(id) {
2884
+ this.emit("open", { id });
2885
+ this.handleOpen();
2886
+ notifyLinkedSheets(this.linkedSheets, this);
2887
+ this.emit("opened", { id });
2888
+ }
2889
+ emitCloseSequence() {
2890
+ this.emit("close", void 0);
2891
+ this.handleClose();
2892
+ this.emit("closed", void 0);
2668
2893
  }
2669
2894
  async dragTo(targetSize, velocityOrOpts = 0) {
2670
2895
  if (this.destroyed) return;
@@ -2685,19 +2910,31 @@ var BottomSheetEngine = class {
2685
2910
  }
2686
2911
  open(id) {
2687
2912
  if (this.destroyed) return Promise.resolve();
2688
- const target = id ?? this.snaps.getAllowedIds().find((a) => a !== "closed") ?? this.activeId;
2913
+ const target = id ?? this.snaps.getAllowedIds().find((a) => (this.snaps.findById(a)?.size ?? 0) > 0) ?? this.activeId;
2689
2914
  return this.snapTo(target);
2690
2915
  }
2691
2916
  close(reason = "programmatic") {
2692
2917
  if (this.destroyed) return Promise.resolve();
2693
2918
  if (this.disableCloseFlag) return Promise.resolve();
2694
2919
  if (this.size > 0 && this.emitBeforeClose(reason)) return Promise.resolve();
2695
- const closedId = this.snapPointsRaw.find((p) => p.id === "closed")?.id ?? this.snaps.getAllowedIds()[0];
2920
+ const closedId = this.snapPointsRaw.find((p) => p.id === "closed")?.id ?? this.snaps.getAllowedIds().find((a) => this.snaps.findById(a)?.size === 0) ?? this.snaps.getAllowedIds()[0];
2696
2921
  return this.snapTo(closedId ?? this.activeId);
2697
2922
  }
2698
2923
  canDismiss() {
2699
2924
  return !this.persistent && !this.disableCloseFlag && !this.destroyed;
2700
2925
  }
2926
+ setPersistent(value) {
2927
+ if (this.destroyed) return;
2928
+ this.persistent = value;
2929
+ }
2930
+ setDisableClose(value) {
2931
+ if (this.destroyed) return;
2932
+ this.disableCloseFlag = value;
2933
+ }
2934
+ setDisableDrag(value) {
2935
+ if (this.destroyed) return;
2936
+ this.disableDragFlag = value;
2937
+ }
2701
2938
  isTop() {
2702
2939
  return this.isTopSheet;
2703
2940
  }
@@ -2734,18 +2971,23 @@ var BottomSheetEngine = class {
2734
2971
  axis === "height" ? "max-height" : "max-width",
2735
2972
  value
2736
2973
  );
2737
- if (typeof h === "number") {
2738
- this.maxHeightCap = h;
2739
- this.recompute();
2740
- } else if (typeof window !== "undefined") {
2741
- const probe2 = document.createElement("div");
2742
- probe2.style.cssText = `position:absolute;visibility:hidden;pointer-events:none;${axis === "height" ? "height" : "width"}:${value};`;
2743
- document.body.appendChild(probe2);
2744
- const measured = axis === "height" ? probe2.offsetHeight : probe2.offsetWidth;
2745
- probe2.remove();
2746
- this.maxHeightCap = measured > 0 ? measured : void 0;
2747
- this.recompute();
2974
+ this.maxHeightRaw = h;
2975
+ this.resolveMaxHeightCap();
2976
+ this.recompute();
2977
+ }
2978
+ resolveMaxHeightCap() {
2979
+ const raw = this.maxHeightRaw;
2980
+ if (raw === void 0) {
2981
+ this.maxHeightCap = void 0;
2982
+ return;
2983
+ }
2984
+ if (typeof raw === "number") {
2985
+ this.maxHeightCap = raw;
2986
+ return;
2748
2987
  }
2988
+ if (typeof window === "undefined") return;
2989
+ const measured = resolveSnap(raw, this.mode);
2990
+ this.maxHeightCap = measured > 0 ? measured : void 0;
2749
2991
  }
2750
2992
  clampToMaxHeight() {
2751
2993
  if (this.maxHeightCap === void 0) return;
@@ -2876,6 +3118,7 @@ var BottomSheetEngine = class {
2876
3118
  this.newCycle();
2877
3119
  this.snapPointsRaw = points;
2878
3120
  auditVhUsage(points);
3121
+ this.auditDuplicateSnapIds(points);
2879
3122
  this.snaps.setRaw(points);
2880
3123
  if (allowed) this.snaps.setAllowedIds(allowed);
2881
3124
  this.scrollCache.clear();
@@ -2888,6 +3131,7 @@ var BottomSheetEngine = class {
2888
3131
  }
2889
3132
  recompute() {
2890
3133
  if (this.destroyed) return;
3134
+ this.resolveMaxHeightCap();
2891
3135
  this.snaps.recompute();
2892
3136
  this.clampToMaxHeight();
2893
3137
  this.scrim.invalidateOpacityCache();
@@ -2899,129 +3143,6 @@ var BottomSheetEngine = class {
2899
3143
  this.updateAriaSlider();
2900
3144
  }
2901
3145
  }
2902
- contentTargets() {
2903
- const scroller = this.scrollContainer;
2904
- if (!scroller) return [];
2905
- const hasSlot = typeof HTMLSlotElement !== "undefined";
2906
- const out = [];
2907
- for (const child of Array.from(scroller.children)) {
2908
- if (hasSlot && child instanceof HTMLSlotElement) {
2909
- for (const el of child.assignedElements()) out.push(el);
2910
- } else {
2911
- out.push(child);
2912
- }
2913
- }
2914
- return out;
2915
- }
2916
- measureSheetNatural(vertical) {
2917
- const el = this.element;
2918
- const content = this.scrollContainer;
2919
- if (!content) {
2920
- return vertical ? el.offsetHeight : el.offsetWidth;
2921
- }
2922
- const axis = vertical ? "height" : "width";
2923
- const sheetStyle = el.style;
2924
- const cs = content.style;
2925
- const prevSheet = sheetStyle[axis];
2926
- const prevFlex = cs.flex;
2927
- const prevContent = vertical ? cs.height : cs.width;
2928
- sheetStyle[axis] = "auto";
2929
- cs.flex = "none";
2930
- if (vertical) cs.height = "auto";
2931
- else cs.width = "auto";
2932
- const poked = vertical ? el.offsetHeight : el.offsetWidth;
2933
- const contentBox = vertical ? content.clientHeight : content.clientWidth;
2934
- const contentScroll = vertical ? content.scrollHeight : content.scrollWidth;
2935
- const natural = Math.max(poked, poked - contentBox + contentScroll);
2936
- sheetStyle[axis] = prevSheet;
2937
- cs.flex = prevFlex;
2938
- if (vertical) cs.height = prevContent;
2939
- else cs.width = prevContent;
2940
- return natural;
2941
- }
2942
- measureFitSize() {
2943
- const vertical = layoutAxis(this.mode) === "height";
2944
- const natural = this.measureSheetNatural(vertical);
2945
- const capped = this.maxHeightCap !== void 0 ? Math.min(natural, this.maxHeightCap) : natural;
2946
- if (typeof window === "undefined") return capped;
2947
- const viewport = this.containingExtent(vertical);
2948
- return viewport > 0 ? Math.min(capped, viewport) : capped;
2949
- }
2950
- // The fit cap is the sheet's containing block, not always the window: a
2951
- // position:fixed sheet nested under a transform/filter/will-change ancestor
2952
- // is clipped to that ancestor, so capping by window.innerHeight oversizes the
2953
- // sheet and the content/footer get clipped. offsetParent resolves to that
2954
- // ancestor when present, and is null (→ viewport) for a plain fixed sheet.
2955
- containingExtent(vertical) {
2956
- const op = this.element.offsetParent;
2957
- if (op && op !== document.body && op !== document.documentElement) {
2958
- return vertical ? op.clientHeight : op.clientWidth;
2959
- }
2960
- return vertical ? window.innerHeight : window.innerWidth;
2961
- }
2962
- installFitObserver() {
2963
- if (typeof ResizeObserver === "undefined") return;
2964
- if (!this.snapPointsRaw.some((p) => p.size === "fit" || p.size === "content"))
2965
- return;
2966
- let raf = 0;
2967
- const schedule = () => {
2968
- if (raf) return;
2969
- raf = requestAnimationFrame(() => {
2970
- raf = 0;
2971
- if (this.destroyed || this.gesture?.isDragging) return;
2972
- this.recompute();
2973
- });
2974
- };
2975
- const ro = new ResizeObserver(schedule);
2976
- ro.observe(this.handle);
2977
- const scroller = this.scrollContainer;
2978
- const observed = /* @__PURE__ */ new Set();
2979
- const slots = /* @__PURE__ */ new Set();
2980
- const hasSlot = typeof HTMLSlotElement !== "undefined";
2981
- const onSlotChange = () => resync();
2982
- const trackSlots = () => {
2983
- if (!scroller || !hasSlot) return;
2984
- for (const child of Array.from(scroller.children)) {
2985
- if (child instanceof HTMLSlotElement && !slots.has(child)) {
2986
- child.addEventListener("slotchange", onSlotChange);
2987
- slots.add(child);
2988
- }
2989
- }
2990
- };
2991
- const resync = () => {
2992
- trackSlots();
2993
- const targets = this.contentTargets();
2994
- for (const el of observed) {
2995
- if (!targets.includes(el)) {
2996
- ro.unobserve(el);
2997
- observed.delete(el);
2998
- }
2999
- }
3000
- for (const el of targets) {
3001
- if (!observed.has(el)) {
3002
- ro.observe(el);
3003
- observed.add(el);
3004
- }
3005
- }
3006
- schedule();
3007
- };
3008
- let mo;
3009
- if (scroller) {
3010
- resync();
3011
- if (typeof MutationObserver !== "undefined") {
3012
- mo = new MutationObserver(resync);
3013
- mo.observe(scroller, { childList: true });
3014
- }
3015
- }
3016
- this.teardowns.add(() => {
3017
- ro.disconnect();
3018
- mo?.disconnect();
3019
- for (const slot of slots) {
3020
- slot.removeEventListener("slotchange", onSlotChange);
3021
- }
3022
- if (raf) cancelAnimationFrame(raf);
3023
- });
3024
- }
3025
3146
  destroy() {
3026
3147
  this.destroyed = true;
3027
3148
  this.opening = false;
@@ -3039,9 +3160,10 @@ var BottomSheetEngine = class {
3039
3160
  this.backdrop.style.opacity = "";
3040
3161
  this.backdrop.style.pointerEvents = "";
3041
3162
  }
3042
- if (this.anchorHost) {
3043
- this.anchorHost.style.removeProperty("--bs-size");
3044
- this.anchorHost.style.removeProperty("--bs-progress");
3163
+ for (const host of [this.anchorHost, this.scrimParent, this.rootEl]) {
3164
+ if (!host) continue;
3165
+ host.style.removeProperty("--bs-size");
3166
+ host.style.removeProperty("--bs-progress");
3045
3167
  }
3046
3168
  if (this.screenComponent) {
3047
3169
  this.screenComponent.style.opacity = "";
@@ -3055,6 +3177,7 @@ var BottomSheetEngine = class {
3055
3177
  }
3056
3178
  newCycle() {
3057
3179
  this.allowOvershoot = false;
3180
+ this.opening = false;
3058
3181
  this.currentAbort.abort();
3059
3182
  this.currentAbort = new AbortController();
3060
3183
  return this.currentAbort.signal;
@@ -3110,8 +3233,14 @@ var BottomSheetEngine = class {
3110
3233
  this.element.setAttribute("aria-labelledby", titled.id);
3111
3234
  }
3112
3235
  recomputeSnaps() {
3236
+ this.resolveMaxHeightCap();
3237
+ this.snaps.setRaw(this.snapPointsRaw);
3238
+ this.clampToMaxHeight();
3239
+ this.scrim.invalidateOpacityCache();
3240
+ }
3241
+ auditDuplicateSnapIds(points) {
3113
3242
  const seen = /* @__PURE__ */ new Set();
3114
- for (const p of this.snapPointsRaw) {
3243
+ for (const p of points) {
3115
3244
  if (seen.has(p.id)) {
3116
3245
  console.warn(
3117
3246
  `[BottomSheet] duplicate snap id "${p.id}" \u2014 only the first occurrence is reachable.`
@@ -3119,9 +3248,6 @@ var BottomSheetEngine = class {
3119
3248
  }
3120
3249
  seen.add(p.id);
3121
3250
  }
3122
- this.snaps.setRaw(this.snapPointsRaw);
3123
- this.clampToMaxHeight();
3124
- this.scrim.invalidateOpacityCache();
3125
3251
  }
3126
3252
  getAllowedRange() {
3127
3253
  return this.snaps.getAllowedRange();
@@ -3309,9 +3435,15 @@ var BottomSheetEngine = class {
3309
3435
  flickVelocity: this.flickVelocity,
3310
3436
  dragThreshold: this.dragThreshold
3311
3437
  });
3312
- if (!target) return;
3438
+ if (!target) {
3439
+ this.clearWillChangeIfIdle();
3440
+ return;
3441
+ }
3313
3442
  const previousId = this.activeId;
3314
- if (target.id === previousId && target.size === this.size) return;
3443
+ if (target.id === previousId && target.size === this.size) {
3444
+ this.clearWillChangeIfIdle();
3445
+ return;
3446
+ }
3315
3447
  if (this.emitBeforeSnap(target, previousId)) {
3316
3448
  const restore = this.snaps.findById(previousId);
3317
3449
  if (restore) {
@@ -3334,27 +3466,19 @@ var BottomSheetEngine = class {
3334
3466
  if (signal.aborted) return;
3335
3467
  this.allowOvershoot = false;
3336
3468
  this.opening = false;
3337
- this.scrollCache.restore(target.id, previousSize, target.size);
3338
- this.updateAriaSlider();
3339
- this.emit("snap", {
3340
- id: target.id,
3341
- size: this.size,
3342
- progress: this.computeProgress(this.size)
3343
- });
3344
- this.haptic();
3345
- if (previousSnapSize === 0 && target.size > 0) {
3346
- this.emit("open", { id: target.id });
3347
- this.handleOpen();
3348
- notifyLinkedSheets(this.linkedSheets, this);
3349
- this.emit("opened", { id: target.id });
3350
- }
3351
- if (target.size === 0) {
3352
- this.emit("close", void 0);
3353
- this.handleClose();
3354
- this.emit("closed", void 0);
3355
- }
3469
+ this.completeSnap(
3470
+ target.id,
3471
+ target.size,
3472
+ previousSize,
3473
+ previousSnapSize === 0,
3474
+ true
3475
+ );
3356
3476
  });
3357
3477
  }
3478
+ clearWillChangeIfIdle() {
3479
+ if (this.animation.isAnimating || this.gesture?.isDragging) return;
3480
+ this.element.style.willChange = "";
3481
+ }
3358
3482
  haptic() {
3359
3483
  if (typeof navigator !== "undefined" && "vibrate" in navigator) {
3360
3484
  try {
@@ -3435,14 +3559,9 @@ var BottomSheetEngine = class {
3435
3559
  progress: this.computeProgress(this.size)
3436
3560
  });
3437
3561
  if (target.size > 0 && !this.lifecycle.isInstalled) {
3438
- this.emit("open", { id: target.id });
3439
- this.handleOpen();
3440
- notifyLinkedSheets(this.linkedSheets, this);
3441
- this.emit("opened", { id: target.id });
3562
+ this.emitOpenSequence(target.id);
3442
3563
  } else if (target.size === 0 && this.lifecycle.isInstalled) {
3443
- this.emit("close", void 0);
3444
- this.handleClose();
3445
- this.emit("closed", void 0);
3564
+ this.emitCloseSequence();
3446
3565
  }
3447
3566
  }
3448
3567
  handleClose() {
@@ -3459,6 +3578,8 @@ var BottomSheet = qwik.component$((props) => {
3459
3578
  const scrimRef = qwik.useSignal();
3460
3579
  const headerRef = qwik.useSignal();
3461
3580
  const footerRef = qwik.useSignal();
3581
+ const leftBtnRef = qwik.useSignal();
3582
+ const rightBtnRef = qwik.useSignal();
3462
3583
  const initialActive = props.initial ?? props.snapPoints[0]?.id ?? "default";
3463
3584
  const state = qwik.useStore({
3464
3585
  size: 0,
@@ -3497,6 +3618,7 @@ var BottomSheet = qwik.component$((props) => {
3497
3618
  disableClose: props.disableClose,
3498
3619
  disableDrag: props.disableDrag,
3499
3620
  closeOnRouteChange: props.closeOnRouteChange,
3621
+ stackEffect: props.stackEffect,
3500
3622
  returnFocusTo: props.returnFocusTo,
3501
3623
  radius: props.radius,
3502
3624
  maxHeight: props.maxHeight
@@ -3532,9 +3654,33 @@ var BottomSheet = qwik.component$((props) => {
3532
3654
  if (empty) el.setAttribute("hidden", "");
3533
3655
  else el.removeAttribute("hidden");
3534
3656
  };
3535
- collapseEmpty(headerRef.value);
3536
- collapseEmpty(footerRef.value);
3657
+ const collapseBoth = () => {
3658
+ collapseEmpty(headerRef.value);
3659
+ collapseEmpty(footerRef.value);
3660
+ collapseEmpty(leftBtnRef.value);
3661
+ collapseEmpty(rightBtnRef.value);
3662
+ };
3663
+ collapseBoth();
3664
+ let slotObserver;
3665
+ if (typeof MutationObserver !== "undefined") {
3666
+ slotObserver = new MutationObserver(collapseBoth);
3667
+ for (const el of [
3668
+ headerRef.value,
3669
+ footerRef.value,
3670
+ leftBtnRef.value,
3671
+ rightBtnRef.value
3672
+ ]) {
3673
+ if (el) {
3674
+ slotObserver.observe(el, {
3675
+ childList: true,
3676
+ subtree: true,
3677
+ characterData: true
3678
+ });
3679
+ }
3680
+ }
3681
+ }
3537
3682
  cleanup(() => {
3683
+ slotObserver?.disconnect();
3538
3684
  if (onBackdropClick && backdropRef.value) {
3539
3685
  backdropRef.value.removeEventListener("click", onBackdropClick);
3540
3686
  }
@@ -3560,6 +3706,16 @@ var BottomSheet = qwik.component$((props) => {
3560
3706
  if (radius !== void 0) engine.setRadius(radius);
3561
3707
  if (maxHeight !== void 0) engine.setMaxHeight(maxHeight);
3562
3708
  });
3709
+ qwik.useTask$(({ track }) => {
3710
+ const persistent = track(() => props.persistent);
3711
+ const disableClose = track(() => props.disableClose);
3712
+ const disableDrag = track(() => props.disableDrag);
3713
+ const engine = engineStore.engine;
3714
+ if (!engine) return;
3715
+ if (persistent !== void 0) engine.setPersistent(persistent);
3716
+ if (disableClose !== void 0) engine.setDisableClose(disableClose);
3717
+ if (disableDrag !== void 0) engine.setDisableDrag(disableDrag);
3718
+ });
3563
3719
  const showBackdrop = props.backdrop !== false;
3564
3720
  const mode = props.mode ?? "bottom";
3565
3721
  const ariaLabel = props.ariaLabel ?? "Bottom sheet";
@@ -3593,6 +3749,26 @@ var BottomSheet = qwik.component$((props) => {
3593
3749
  /* @__PURE__ */ jsxRuntime.jsx("span", { class: "bs-sr-only", role: "status", "aria-live": "polite", children: state.activeId })
3594
3750
  ]
3595
3751
  }
3752
+ ),
3753
+ /* @__PURE__ */ jsxRuntime.jsx(
3754
+ "div",
3755
+ {
3756
+ class: "bs-button-slot",
3757
+ "data-side": "left",
3758
+ "data-mode": mode,
3759
+ ref: leftBtnRef,
3760
+ children: /* @__PURE__ */ jsxRuntime.jsx(qwik.Slot, { name: "leftButton" })
3761
+ }
3762
+ ),
3763
+ /* @__PURE__ */ jsxRuntime.jsx(
3764
+ "div",
3765
+ {
3766
+ class: "bs-button-slot",
3767
+ "data-side": "right",
3768
+ "data-mode": mode,
3769
+ ref: rightBtnRef,
3770
+ children: /* @__PURE__ */ jsxRuntime.jsx(qwik.Slot, { name: "rightButton" })
3771
+ }
3596
3772
  )
3597
3773
  ] });
3598
3774
  });