@surdeddd/bottom-sheet 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/{BottomSheetEngine-CAymrH-P.d.cts → BottomSheetEngine-BJrH7qY3.d.cts} +39 -3
  2. package/dist/{BottomSheetEngine-DcqcuudN.d.ts → BottomSheetEngine-L05jGZvU.d.ts} +39 -3
  3. package/dist/element.cjs +480 -89
  4. package/dist/element.d.cts +23 -4
  5. package/dist/element.d.ts +23 -4
  6. package/dist/element.iife.global.js +2 -2
  7. package/dist/element.js +480 -89
  8. package/dist/index.cjs +341 -80
  9. package/dist/index.d.cts +3 -2
  10. package/dist/index.d.ts +3 -2
  11. package/dist/index.js +341 -80
  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 +13 -2
  17. package/dist/overlay.js +13 -2
  18. package/dist/preact.d.cts +1 -1
  19. package/dist/preact.d.ts +1 -1
  20. package/dist/qwik.cjs +352 -81
  21. package/dist/qwik.d.cts +4 -2
  22. package/dist/qwik.d.ts +4 -2
  23. package/dist/qwik.js +352 -81
  24. package/dist/react.cjs +427 -87
  25. package/dist/react.d.cts +29 -4
  26. package/dist/react.d.ts +29 -4
  27. package/dist/react.js +427 -87
  28. package/dist/solid.cjs +341 -80
  29. package/dist/solid.d.cts +38 -2
  30. package/dist/solid.d.ts +38 -2
  31. package/dist/solid.js +341 -80
  32. package/dist/solid.source.jsx +341 -80
  33. package/dist/styles.css +57 -56
  34. package/dist/svelte-core.cjs +346 -80
  35. package/dist/svelte-core.js +346 -80
  36. package/dist/svelte-src/BottomSheet.svelte +103 -5
  37. package/dist/svelte.cjs +421 -88
  38. package/dist/svelte.d.cts +21 -0
  39. package/dist/svelte.d.ts +21 -0
  40. package/dist/svelte.js +421 -88
  41. package/dist/vue.cjs +584 -91
  42. package/dist/vue.d.cts +51 -2
  43. package/dist/vue.d.ts +51 -2
  44. package/dist/vue.js +585 -92
  45. package/package.json +6 -6
package/dist/svelte.js CHANGED
@@ -39,6 +39,15 @@ var SheetStack = class {
39
39
  size() {
40
40
  return this.entries.length;
41
41
  }
42
+ depthOf(id) {
43
+ const open = [];
44
+ for (const entry of this.entries) {
45
+ if (!entry.isOpen || entry.isOpen()) open.push(entry);
46
+ }
47
+ const idx = open.findIndex((e) => e.id === id);
48
+ if (idx === -1) return 0;
49
+ return open.length - 1 - idx;
50
+ }
42
51
  clear() {
43
52
  this.entries = [];
44
53
  }
@@ -157,7 +166,9 @@ var PERCENT = /^(-?\d+(?:\.\d+)?)%$/;
157
166
  var resolveSnap = (point, mode, measureFit) => {
158
167
  if (typeof point === "number") return Math.max(0, point);
159
168
  if (point === "full") return viewportSize(mode);
160
- if (point === "fit") return Math.max(0, measureFit?.() ?? 0);
169
+ if (point === "fit" || point === "content") {
170
+ return Math.max(0, measureFit?.() ?? 0);
171
+ }
161
172
  const pctMatch = point.match(PERCENT);
162
173
  if (pctMatch) {
163
174
  const pct = parseFloat(pctMatch[1]) / 100;
@@ -394,6 +405,42 @@ function notifyLinkedSheets(sheets, self) {
394
405
  }
395
406
 
396
407
  // src/core/features/route.ts
408
+ var closers = [];
409
+ var handlerInstalled = false;
410
+ var suppress = 0;
411
+ var ensureHandler = () => {
412
+ if (handlerInstalled || typeof window === "undefined") return;
413
+ handlerInstalled = true;
414
+ window.addEventListener("popstate", () => {
415
+ if (suppress > 0) {
416
+ suppress -= 1;
417
+ return;
418
+ }
419
+ let target = null;
420
+ for (let i = closers.length - 1; i >= 0; i -= 1) {
421
+ const c = closers[i];
422
+ if (!c.isOpen()) continue;
423
+ if (!target) target = c;
424
+ if (c.isTop()) {
425
+ target = c;
426
+ break;
427
+ }
428
+ }
429
+ if (!target) return;
430
+ target.consumed = true;
431
+ const idx = closers.indexOf(target);
432
+ if (idx !== -1) closers.splice(idx, 1);
433
+ target.close();
434
+ });
435
+ };
436
+ var programmaticBack = () => {
437
+ suppress += 1;
438
+ try {
439
+ history.back();
440
+ } catch {
441
+ suppress = Math.max(0, suppress - 1);
442
+ }
443
+ };
397
444
  function installRoute(deps) {
398
445
  if (typeof window === "undefined") {
399
446
  return () => {
@@ -403,82 +450,81 @@ function installRoute(deps) {
403
450
  return () => {
404
451
  };
405
452
  }
406
- let routePushed = false;
407
- let closeOnBackPushed = false;
408
- let detachPopstate = null;
409
- const popOurMarker = (key, expected) => {
410
- const state2 = history.state;
411
- if (state2 && state2[key] === expected) {
412
- try {
413
- history.back();
414
- } catch {
415
- }
453
+ let pushed = false;
454
+ let closer = null;
455
+ const teardownEntry = () => {
456
+ if (closer) {
457
+ const idx = closers.indexOf(closer);
458
+ if (idx !== -1) closers.splice(idx, 1);
459
+ }
460
+ const wasConsumed = closer?.consumed ?? false;
461
+ closer = null;
462
+ if (pushed && !wasConsumed) {
463
+ pushed = false;
464
+ programmaticBack();
465
+ } else {
466
+ pushed = false;
416
467
  }
417
468
  };
418
469
  const onOpen = () => {
419
- if (deps.routedTo && !detachPopstate) {
420
- const target = deps.routedTo;
421
- try {
422
- history.pushState({ __bsRouted: target }, "", target);
423
- routePushed = true;
424
- } catch {
425
- }
426
- const onPop = (event) => {
427
- if (deps.isDestroyed()) return;
428
- const state2 = event.state;
429
- if ((!state2 || state2.__bsRouted !== target) && deps.getSize() > 0) {
430
- routePushed = false;
431
- void deps.close();
432
- }
433
- };
434
- window.addEventListener("popstate", onPop);
435
- detachPopstate = () => window.removeEventListener("popstate", onPop);
436
- } else if (deps.closeOnBack && !detachPopstate) {
437
- try {
470
+ if (closer) return;
471
+ closer = {
472
+ isOpen: () => !deps.isDestroyed() && deps.getSize() > 0,
473
+ isTop: () => deps.isTopSheet(),
474
+ close: () => void deps.close(),
475
+ consumed: false
476
+ };
477
+ ensureHandler();
478
+ closers.push(closer);
479
+ try {
480
+ if (deps.routedTo !== void 0) {
481
+ history.pushState({ __bsRouted: deps.sheetId }, "", deps.routedTo);
482
+ } else {
438
483
  history.pushState({ __bsSheet: deps.sheetId }, "");
439
- closeOnBackPushed = true;
440
- } catch {
441
484
  }
442
- const onPop = () => {
443
- if (deps.isDestroyed()) return;
444
- if (deps.getSize() > 0 && deps.isTopSheet()) {
445
- const state2 = history.state;
446
- if (state2?.__bsSheet !== deps.sheetId) closeOnBackPushed = false;
447
- void deps.close();
448
- }
449
- };
450
- window.addEventListener("popstate", onPop);
451
- detachPopstate = () => window.removeEventListener("popstate", onPop);
452
- }
453
- };
454
- const onClose = () => {
455
- detachPopstate?.();
456
- detachPopstate = null;
457
- if (routePushed) {
458
- routePushed = false;
459
- if (deps.routedTo !== void 0) popOurMarker("__bsRouted", deps.routedTo);
460
- }
461
- if (closeOnBackPushed) {
462
- closeOnBackPushed = false;
463
- popOurMarker("__bsSheet", deps.sheetId);
485
+ pushed = true;
486
+ } catch {
487
+ pushed = false;
464
488
  }
465
489
  };
466
490
  const unsubscribeOpen = deps.on("open", onOpen);
467
- const unsubscribeClose = deps.on("close", onClose);
491
+ const unsubscribeClose = deps.on("close", teardownEntry);
468
492
  if (deps.getSize() > 0) onOpen();
469
493
  return () => {
470
494
  unsubscribeOpen();
471
495
  unsubscribeClose();
472
- detachPopstate?.();
473
- detachPopstate = null;
474
- if (routePushed) {
475
- routePushed = false;
476
- if (deps.routedTo !== void 0) popOurMarker("__bsRouted", deps.routedTo);
477
- }
478
- if (closeOnBackPushed) {
479
- closeOnBackPushed = false;
480
- popOurMarker("__bsSheet", deps.sheetId);
481
- }
496
+ teardownEntry();
497
+ };
498
+ }
499
+ function installRouteChange(deps) {
500
+ if (typeof window === "undefined" || typeof history === "undefined") {
501
+ return () => {
502
+ };
503
+ }
504
+ const onChange = () => {
505
+ if (deps.isDestroyed() || deps.getSize() <= 0) return;
506
+ void deps.close();
507
+ };
508
+ const wrap = (key) => {
509
+ const original = history[key];
510
+ const patched = function(...args) {
511
+ original.apply(this, args);
512
+ onChange();
513
+ };
514
+ history[key] = patched;
515
+ return () => {
516
+ if (history[key] === patched) {
517
+ history[key] = original;
518
+ }
519
+ };
520
+ };
521
+ window.addEventListener("popstate", onChange);
522
+ const restorePush = wrap("pushState");
523
+ const restoreReplace = wrap("replaceState");
524
+ return () => {
525
+ window.removeEventListener("popstate", onChange);
526
+ restorePush();
527
+ restoreReplace();
482
528
  };
483
529
  }
484
530
 
@@ -786,6 +832,7 @@ function applyOverlayPosition(ws, mode, position, inset) {
786
832
 
787
833
  // src/core/controllers/scrim-controller.ts
788
834
  var VALID_CSS_LENGTH = /^-?\d+(?:\.\d+)?(?:px|em|rem|%)$/;
835
+ var DEFAULT_SCRIM_DIM = "rgba(0, 0, 0, 0.4)";
789
836
  var ScrimController = class {
790
837
  constructor(deps, opts) {
791
838
  __publicField(this, "screenComponent");
@@ -824,9 +871,11 @@ var ScrimController = class {
824
871
  this.backdropRange = opts.backdropRange ?? preset?.range ?? [0, 1];
825
872
  this.screenRange = opts.screenRange ?? preset?.range ?? [0, 1];
826
873
  this.scrimTapToCloseEnabled = opts.scrimTapToClose ?? false;
874
+ const explicitColor = opts.scrimColor ?? preset?.color;
875
+ const effectiveColor = explicitColor ?? (this.scrimMode !== "off" && !this.backdrop ? DEFAULT_SCRIM_DIM : void 0);
827
876
  if (this.screenComponent) {
828
877
  this.applyScrimStyles({
829
- color: opts.scrimColor ?? preset?.color,
878
+ color: effectiveColor,
830
879
  blur: opts.scrimBlur ?? preset?.blur,
831
880
  interactive: opts.scrimInteractive ?? preset?.interactive ?? false
832
881
  });
@@ -1600,7 +1649,7 @@ var LifecycleController = class {
1600
1649
  this.releaseScrollLock = null;
1601
1650
  this.inertSiblings.remove();
1602
1651
  if (this.returnFocus) {
1603
- const target = typeof this.returnFocus === "function" ? this.returnFocus() : this.returnFocus;
1652
+ const target = typeof this.returnFocus === "function" ? this.returnFocus() : typeof this.returnFocus === "string" ? typeof document !== "undefined" ? document.querySelector(this.returnFocus) : null : this.returnFocus;
1604
1653
  target?.focus?.();
1605
1654
  }
1606
1655
  }
@@ -1767,6 +1816,7 @@ var GestureController = class {
1767
1816
  __publicField(this, "dragStartSize", 0);
1768
1817
  __publicField(this, "currentPointerKind", "touch");
1769
1818
  __publicField(this, "keyboardDismissed", false);
1819
+ __publicField(this, "dragSuppressed", false);
1770
1820
  __publicField(this, "dragPayload", { size: 0, delta: 0 });
1771
1821
  this.deps = deps;
1772
1822
  }
@@ -1777,6 +1827,11 @@ var GestureController = class {
1777
1827
  if (this.detach) return this.detach;
1778
1828
  this.detach = installGestures(this.deps.handle, this.deps.mode, {
1779
1829
  onStart: (_coord, kind) => {
1830
+ if (this.deps.getDisableDrag?.()) {
1831
+ this.dragSuppressed = true;
1832
+ return;
1833
+ }
1834
+ this.dragSuppressed = false;
1780
1835
  this.deps.cancelAnimation();
1781
1836
  this.isDragging_ = true;
1782
1837
  this.dragStartSize = this.deps.getDragContext().size;
@@ -1787,6 +1842,7 @@ var GestureController = class {
1787
1842
  this.deps.emit("dragstart", { size: this.dragStartSize });
1788
1843
  },
1789
1844
  onMove: (delta) => {
1845
+ if (this.dragSuppressed) return;
1790
1846
  const ctx = this.deps.getDragContext();
1791
1847
  const { min, max } = ctx.range;
1792
1848
  const maxAxis = ctx.maxAxisSize;
@@ -1810,6 +1866,10 @@ var GestureController = class {
1810
1866
  }
1811
1867
  },
1812
1868
  onEnd: (delta, velocity, kind) => {
1869
+ if (this.dragSuppressed) {
1870
+ this.dragSuppressed = false;
1871
+ return;
1872
+ }
1813
1873
  this.isDragging_ = false;
1814
1874
  this.keyboardDismissed = false;
1815
1875
  this.deps.getRoot()?.removeAttribute("data-dragging");
@@ -1820,6 +1880,10 @@ var GestureController = class {
1820
1880
  this.deps.settleAfterDrag(delta, velocity, kind);
1821
1881
  },
1822
1882
  onCancel: () => {
1883
+ if (this.dragSuppressed) {
1884
+ this.dragSuppressed = false;
1885
+ return;
1886
+ }
1823
1887
  this.isDragging_ = false;
1824
1888
  this.keyboardDismissed = false;
1825
1889
  this.deps.getRoot()?.removeAttribute("data-dragging");
@@ -2199,6 +2263,12 @@ function resolveEngineOptions(opts, extras) {
2199
2263
  dragThreshold: opts.dragThreshold ?? DEFAULT_DRAG_THRESHOLD,
2200
2264
  rubberBandEnabled: opts.rubberBand ?? true,
2201
2265
  closeOnBack: opts.closeOnBack ?? false,
2266
+ persistent: opts.persistent ?? false,
2267
+ disableClose: opts.disableClose ?? false,
2268
+ disableDrag: opts.disableDrag ?? false,
2269
+ closeOnRouteChange: opts.closeOnRouteChange ?? false,
2270
+ radius: opts.radius,
2271
+ maxHeight: opts.maxHeight,
2202
2272
  initialAllowed,
2203
2273
  initialId,
2204
2274
  scrim: {
@@ -2225,7 +2295,8 @@ function resolveEngineOptions(opts, extras) {
2225
2295
  closeOnEscape: opts.closeOnEscape,
2226
2296
  lockBodyScroll: opts.lockBodyScroll,
2227
2297
  inertSiblings: opts.inertSiblings,
2228
- shouldApplyInertSiblings: extras?.shouldApplyInertSiblings
2298
+ shouldApplyInertSiblings: extras?.shouldApplyInertSiblings,
2299
+ returnFocus: opts.returnFocusTo
2229
2300
  }
2230
2301
  };
2231
2302
  }
@@ -2270,6 +2341,11 @@ var BottomSheetEngine = class {
2270
2341
  __publicField(this, "lifecycle");
2271
2342
  __publicField(this, "closeOnBack");
2272
2343
  __publicField(this, "routedTo");
2344
+ __publicField(this, "persistent");
2345
+ __publicField(this, "disableCloseFlag");
2346
+ __publicField(this, "disableDragFlag");
2347
+ __publicField(this, "closeOnRouteChange");
2348
+ __publicField(this, "maxHeightCap");
2273
2349
  __publicField(this, "snapPointsRaw");
2274
2350
  __publicField(this, "snaps");
2275
2351
  __publicField(this, "activeId");
@@ -2282,6 +2358,7 @@ var BottomSheetEngine = class {
2282
2358
  __publicField(this, "sizeWriteSentinel", new WriteSentinel());
2283
2359
  __publicField(this, "progressWriteSentinel", new WriteSentinel());
2284
2360
  __publicField(this, "isTopSheet", true);
2361
+ __publicField(this, "opening", false);
2285
2362
  __publicField(this, "progressPayload", {
2286
2363
  value: 0,
2287
2364
  size: 0
@@ -2338,7 +2415,8 @@ var BottomSheetEngine = class {
2338
2415
  void this.snapTo(id);
2339
2416
  },
2340
2417
  close: () => {
2341
- void this.close();
2418
+ if (!this.canDismiss()) return;
2419
+ void this.close("backdrop");
2342
2420
  }
2343
2421
  },
2344
2422
  resolved.scrim
@@ -2362,6 +2440,10 @@ var BottomSheetEngine = class {
2362
2440
  );
2363
2441
  this.closeOnBack = resolved.closeOnBack;
2364
2442
  this.routedTo = opts.routedTo;
2443
+ this.persistent = resolved.persistent;
2444
+ this.disableCloseFlag = resolved.disableClose;
2445
+ this.disableDragFlag = resolved.disableDrag;
2446
+ this.closeOnRouteChange = resolved.closeOnRouteChange;
2365
2447
  this.stackEffectEnabled = opts.stackEffect ?? false;
2366
2448
  this.snapPointsRaw = opts.snapPoints;
2367
2449
  this.persistKey = opts.persistKey;
@@ -2375,7 +2457,7 @@ var BottomSheetEngine = class {
2375
2457
  this.snapPointsRaw,
2376
2458
  resolved.initialAllowed,
2377
2459
  this.mode,
2378
- () => layoutAxis(this.mode) === "width" ? this.handle.offsetWidth : this.handle.offsetHeight,
2460
+ () => this.measureFitSize(),
2379
2461
  (maxAxisSize) => {
2380
2462
  this.element.style[layoutAxis(this.mode)] = `${maxAxisSize}px`;
2381
2463
  }
@@ -2409,6 +2491,19 @@ var BottomSheetEngine = class {
2409
2491
  io.observe(this.element);
2410
2492
  this.teardowns.add(() => io.disconnect());
2411
2493
  }
2494
+ this.installFitObserver();
2495
+ if (resolved.radius !== void 0) this.setRadius(resolved.radius);
2496
+ if (resolved.maxHeight !== void 0) this.setMaxHeight(resolved.maxHeight);
2497
+ this.applyAutoAriaLabelledBy();
2498
+ if (this.closeOnRouteChange) {
2499
+ this.teardowns.add(
2500
+ installRouteChange({
2501
+ isDestroyed: () => this.destroyed,
2502
+ getSize: () => this.size,
2503
+ close: () => this.close()
2504
+ })
2505
+ );
2506
+ }
2412
2507
  if (this.persistKey) {
2413
2508
  this.teardowns.add(installPersist(this, this.persistKey));
2414
2509
  }
@@ -2433,7 +2528,7 @@ var BottomSheetEngine = class {
2433
2528
  isTopSheet: () => this.isTopSheet,
2434
2529
  getSize: () => this.size,
2435
2530
  isDestroyed: () => this.destroyed,
2436
- close: () => this.close(),
2531
+ close: () => this.close("back"),
2437
2532
  on: (event, fn) => this.on(event, fn),
2438
2533
  sheetId: this.id
2439
2534
  })
@@ -2527,6 +2622,10 @@ var BottomSheetEngine = class {
2527
2622
  const previousSize = this.size;
2528
2623
  this.scrollCache.cache(previousId, previousSize, target.size);
2529
2624
  this.activeId = id;
2625
+ if (wasClosed && target.size > 0) {
2626
+ this.opening = true;
2627
+ sheetStack.promote(this.id);
2628
+ }
2530
2629
  if (this.animation.viewTransitionsAvailable) {
2531
2630
  this.currentViewTransition?.skipTransition?.();
2532
2631
  const vt = document.startViewTransition(() => {
@@ -2541,19 +2640,26 @@ var BottomSheetEngine = class {
2541
2640
  } else {
2542
2641
  await this.animation.animateTo(target.size, velocityPxPerMs);
2543
2642
  }
2643
+ this.opening = false;
2544
2644
  externalSignal?.removeEventListener("abort", onExternalAbort);
2545
2645
  if (signal.aborted) return;
2546
2646
  this.scrollCache.restore(id, previousSize, target.size);
2547
2647
  this.updateAriaSlider();
2548
- this.emit("snap", { id, size: target.size });
2648
+ this.emit("snap", {
2649
+ id,
2650
+ size: target.size,
2651
+ progress: this.computeProgress(target.size)
2652
+ });
2549
2653
  if (wasClosed && target.size > 0) {
2550
2654
  this.emit("open", { id });
2551
2655
  this.handleOpen();
2552
2656
  notifyLinkedSheets(this.linkedSheets, this);
2657
+ this.emit("opened", { id });
2553
2658
  }
2554
2659
  if (target.size === 0) {
2555
2660
  this.emit("close", void 0);
2556
2661
  this.handleClose();
2662
+ this.emit("closed", void 0);
2557
2663
  }
2558
2664
  }
2559
2665
  async dragTo(targetSize, velocityOrOpts = 0) {
@@ -2578,11 +2684,74 @@ var BottomSheetEngine = class {
2578
2684
  const target = id ?? this.snaps.getAllowedIds().find((a) => a !== "closed") ?? this.activeId;
2579
2685
  return this.snapTo(target);
2580
2686
  }
2581
- close() {
2687
+ close(reason = "programmatic") {
2582
2688
  if (this.destroyed) return Promise.resolve();
2689
+ if (this.disableCloseFlag) return Promise.resolve();
2690
+ if (this.size > 0 && this.emitBeforeClose(reason)) return Promise.resolve();
2583
2691
  const closedId = this.snapPointsRaw.find((p) => p.id === "closed")?.id ?? this.snaps.getAllowedIds()[0];
2584
2692
  return this.snapTo(closedId ?? this.activeId);
2585
2693
  }
2694
+ canDismiss() {
2695
+ return !this.persistent && !this.disableCloseFlag && !this.destroyed;
2696
+ }
2697
+ isTop() {
2698
+ return this.isTopSheet;
2699
+ }
2700
+ depth() {
2701
+ return sheetStack.depthOf(this.id);
2702
+ }
2703
+ expand() {
2704
+ if (this.destroyed) return Promise.resolve();
2705
+ const ids = this.allowedIdsBySize();
2706
+ const target = ids[ids.length - 1];
2707
+ if (!target) return Promise.resolve();
2708
+ return this.snapTo(target);
2709
+ }
2710
+ collapse() {
2711
+ if (this.destroyed) return Promise.resolve();
2712
+ const ids = this.allowedIdsBySize();
2713
+ const nonZero = ids.find((id) => (this.snaps.findById(id)?.size ?? 0) > 0);
2714
+ const target = nonZero ?? ids[0];
2715
+ if (!target) return Promise.resolve();
2716
+ return this.snapTo(target);
2717
+ }
2718
+ setRadius(r) {
2719
+ if (this.destroyed) return;
2720
+ this.element.style.setProperty(
2721
+ "--bs-radius",
2722
+ typeof r === "number" ? `${r}px` : r
2723
+ );
2724
+ }
2725
+ setMaxHeight(h) {
2726
+ if (this.destroyed) return;
2727
+ const value = typeof h === "number" ? `${h}px` : h;
2728
+ const axis = layoutAxis(this.mode);
2729
+ this.element.style.setProperty(
2730
+ axis === "height" ? "maxHeight" : "maxWidth",
2731
+ value
2732
+ );
2733
+ if (typeof h === "number") {
2734
+ this.maxHeightCap = h;
2735
+ this.clampToMaxHeight();
2736
+ } else if (typeof window !== "undefined") {
2737
+ const probe2 = document.createElement("div");
2738
+ probe2.style.cssText = `position:absolute;visibility:hidden;pointer-events:none;${axis === "height" ? "height" : "width"}:${value};`;
2739
+ document.body.appendChild(probe2);
2740
+ const measured = axis === "height" ? probe2.offsetHeight : probe2.offsetWidth;
2741
+ probe2.remove();
2742
+ this.maxHeightCap = measured > 0 ? measured : void 0;
2743
+ this.clampToMaxHeight();
2744
+ }
2745
+ }
2746
+ clampToMaxHeight() {
2747
+ if (this.maxHeightCap === void 0) return;
2748
+ if (this.snaps.getMaxAxisSize() > this.maxHeightCap) {
2749
+ this.snaps.setMaxAxisSize(this.maxHeightCap);
2750
+ }
2751
+ if (this.size > this.maxHeightCap && !this.gesture?.isDragging) {
2752
+ this.applySize(this.maxHeightCap);
2753
+ }
2754
+ }
2586
2755
  setAllowed(ids, snap) {
2587
2756
  if (this.destroyed) return;
2588
2757
  this.snaps.setAllowedIds(ids);
@@ -2716,8 +2885,53 @@ var BottomSheetEngine = class {
2716
2885
  }
2717
2886
  this.updateAriaSlider();
2718
2887
  }
2888
+ recompute() {
2889
+ if (this.destroyed) return;
2890
+ this.snaps.recompute();
2891
+ this.scrim.invalidateOpacityCache();
2892
+ if (this.gesture?.isDragging) return;
2893
+ const current = this.snaps.findById(this.activeId);
2894
+ if (current) {
2895
+ this.size = current.size;
2896
+ this.applySize(this.size);
2897
+ this.updateAriaSlider();
2898
+ }
2899
+ }
2900
+ measureFitSize() {
2901
+ const vertical = layoutAxis(this.mode) === "height";
2902
+ const handleSize = vertical ? this.handle.offsetHeight : this.handle.offsetWidth;
2903
+ const content = this.scrollContainer;
2904
+ const natural = content ? handleSize + (vertical ? content.scrollHeight : content.scrollWidth) : handleSize;
2905
+ if (typeof window === "undefined") return natural;
2906
+ const viewport = vertical ? window.innerHeight : window.innerWidth;
2907
+ return viewport > 0 ? Math.min(natural, viewport) : natural;
2908
+ }
2909
+ installFitObserver() {
2910
+ if (typeof ResizeObserver === "undefined") return;
2911
+ if (!this.snapPointsRaw.some((p) => p.size === "fit" || p.size === "content"))
2912
+ return;
2913
+ const targets = [this.handle];
2914
+ if (this.scrollContainer && this.scrollContainer !== this.handle) {
2915
+ targets.push(this.scrollContainer);
2916
+ }
2917
+ let raf = 0;
2918
+ const ro = new ResizeObserver(() => {
2919
+ if (raf) return;
2920
+ raf = requestAnimationFrame(() => {
2921
+ raf = 0;
2922
+ if (this.destroyed || this.gesture?.isDragging) return;
2923
+ this.recompute();
2924
+ });
2925
+ });
2926
+ for (const t of targets) ro.observe(t);
2927
+ this.teardowns.add(() => {
2928
+ ro.disconnect();
2929
+ if (raf) cancelAnimationFrame(raf);
2930
+ });
2931
+ }
2719
2932
  destroy() {
2720
2933
  this.destroyed = true;
2934
+ this.opening = false;
2721
2935
  this.currentAbort.abort();
2722
2936
  this.currentViewTransition?.skipTransition?.();
2723
2937
  this.currentViewTransition = null;
@@ -2767,6 +2981,36 @@ var BottomSheetEngine = class {
2767
2981
  frozen = true;
2768
2982
  return cancelled;
2769
2983
  }
2984
+ emitBeforeClose(reason) {
2985
+ let cancelled = false;
2986
+ let frozen = false;
2987
+ this.emit("before-close", {
2988
+ reason,
2989
+ cancel: () => {
2990
+ if (frozen) {
2991
+ console.warn(
2992
+ "[BottomSheet] before-close.cancel() called asynchronously \u2014 ignored. cancel() must be invoked synchronously inside the listener."
2993
+ );
2994
+ return;
2995
+ }
2996
+ cancelled = true;
2997
+ }
2998
+ });
2999
+ frozen = true;
3000
+ return cancelled;
3001
+ }
3002
+ applyAutoAriaLabelledBy() {
3003
+ if (typeof document === "undefined") return;
3004
+ if (!this.lifecycle.focusTrapEnabled) return;
3005
+ if (this.element.getAttribute("aria-labelledby")) return;
3006
+ const scope = this.handle ?? this.element;
3007
+ const titled = scope.querySelector("[data-bs-title]") ?? scope.querySelector("h1,h2,h3,h4,h5,h6");
3008
+ if (!titled) return;
3009
+ if (!titled.id) {
3010
+ titled.id = nextInstanceId("bs-title");
3011
+ }
3012
+ this.element.setAttribute("aria-labelledby", titled.id);
3013
+ }
2770
3014
  recomputeSnaps() {
2771
3015
  const seen = /* @__PURE__ */ new Set();
2772
3016
  for (const p of this.snapPointsRaw) {
@@ -2802,11 +3046,8 @@ var BottomSheetEngine = class {
2802
3046
  },
2803
3047
  setIsTop: (isTop) => {
2804
3048
  this.isTopSheet = isTop;
2805
- if (this.backdrop) {
2806
- this.backdrop.style.display = isTop ? "" : "none";
2807
- }
2808
3049
  },
2809
- isOpen: () => this.size > 0,
3050
+ isOpen: () => this.size > 0 || this.opening,
2810
3051
  setDepth: (depth) => this.applyStackDepth(depth)
2811
3052
  }));
2812
3053
  }
@@ -2838,6 +3079,7 @@ var BottomSheetEngine = class {
2838
3079
  buf.rubberBandEnabled = this.rubberBandEnabled;
2839
3080
  return buf;
2840
3081
  },
3082
+ getDisableDrag: () => this.disableDragFlag,
2841
3083
  cancelAnimation: () => this.animation.cancel(),
2842
3084
  applySize: (size) => this.applySize(size),
2843
3085
  animateTo: (size, velocity) => this.animation.animateTo(size, velocity),
@@ -2917,8 +3159,9 @@ var BottomSheetEngine = class {
2917
3159
  if (this.lifecycle.closeOnEscape) {
2918
3160
  const onKey = (e) => {
2919
3161
  if (this.destroyed || e.defaultPrevented) return;
3162
+ if (!this.canDismiss()) return;
2920
3163
  if (e.key === "Escape" && this.isTopSheet && this.size > 0) {
2921
- void this.close();
3164
+ void this.close("escape");
2922
3165
  }
2923
3166
  };
2924
3167
  document.addEventListener("keydown", onKey);
@@ -2981,20 +3224,31 @@ var BottomSheetEngine = class {
2981
3224
  const previousSnapSize = this.snaps.findById(previousId)?.size;
2982
3225
  this.scrollCache.cache(previousId, previousSize, target.size);
2983
3226
  this.activeId = target.id;
3227
+ if (previousSnapSize === 0 && target.size > 0) {
3228
+ this.opening = true;
3229
+ sheetStack.promote(this.id);
3230
+ }
2984
3231
  void this.animation.animateTo(target.size, velocity).then(() => {
3232
+ this.opening = false;
2985
3233
  if (signal.aborted) return;
2986
3234
  this.scrollCache.restore(target.id, previousSize, target.size);
2987
3235
  this.updateAriaSlider();
2988
- this.emit("snap", { id: target.id, size: target.size });
3236
+ this.emit("snap", {
3237
+ id: target.id,
3238
+ size: target.size,
3239
+ progress: this.computeProgress(target.size)
3240
+ });
2989
3241
  this.haptic();
2990
3242
  if (previousSnapSize === 0 && target.size > 0) {
2991
3243
  this.emit("open", { id: target.id });
2992
3244
  this.handleOpen();
2993
3245
  notifyLinkedSheets(this.linkedSheets, this);
3246
+ this.emit("opened", { id: target.id });
2994
3247
  }
2995
3248
  if (target.size === 0) {
2996
3249
  this.emit("close", void 0);
2997
3250
  this.handleClose();
3251
+ this.emit("closed", void 0);
2998
3252
  }
2999
3253
  });
3000
3254
  }
@@ -3063,17 +3317,24 @@ var BottomSheetEngine = class {
3063
3317
  const target = this.snaps.findById(this.activeId);
3064
3318
  if (!target) return;
3065
3319
  this.updateAriaSlider();
3066
- this.emit("snap", { id: target.id, size: target.size });
3320
+ this.emit("snap", {
3321
+ id: target.id,
3322
+ size: target.size,
3323
+ progress: this.computeProgress(target.size)
3324
+ });
3067
3325
  if (target.size > 0 && !this.lifecycle.isInstalled) {
3068
3326
  this.emit("open", { id: target.id });
3069
3327
  this.handleOpen();
3070
3328
  notifyLinkedSheets(this.linkedSheets, this);
3329
+ this.emit("opened", { id: target.id });
3071
3330
  } else if (target.size === 0 && this.lifecycle.isInstalled) {
3072
3331
  this.emit("close", void 0);
3073
3332
  this.handleClose();
3333
+ this.emit("closed", void 0);
3074
3334
  }
3075
3335
  }
3076
3336
  handleClose() {
3337
+ this.opening = false;
3077
3338
  this.lifecycle.release();
3078
3339
  sheetStack.update();
3079
3340
  }
@@ -3127,6 +3388,10 @@ function createBottomSheet(opts) {
3127
3388
  snapTo: (id) => engine?.snapTo(id) ?? Promise.resolve(),
3128
3389
  open: (id) => engine?.open(id) ?? Promise.resolve(),
3129
3390
  close: () => engine?.close() ?? Promise.resolve(),
3391
+ expand: () => engine?.expand() ?? Promise.resolve(),
3392
+ collapse: () => engine?.collapse() ?? Promise.resolve(),
3393
+ isTop: () => engine?.isTop() ?? false,
3394
+ depth: () => engine?.depth() ?? 0,
3130
3395
  setAllowed: (ids, snap) => engine?.setAllowed(ids, snap),
3131
3396
  setSnapPoints: (points, allowed) => engine?.setSnapPoints(points, allowed),
3132
3397
  setScrim: (scrimOpts) => engine?.setScrim(scrimOpts),
@@ -3136,6 +3401,7 @@ function createBottomSheet(opts) {
3136
3401
  }),
3137
3402
  setScrimStages: (stagesOpts) => engine?.setScrimStages(stagesOpts) ?? (() => {
3138
3403
  }),
3404
+ recompute: () => engine?.recompute(),
3139
3405
  destroy: () => {
3140
3406
  engine?.destroy();
3141
3407
  engine = null;
@@ -3149,7 +3415,7 @@ var root_4 = $2.from_html(`<div class="bs-button-slot" data-side="right"><!></di
3149
3415
  var root = $2.from_html(`<div class="bs-root"><!> <div class="bs-screen"><!></div> <section class="bs-sheet" role="dialog"><!> <!> <div class="bs-handle" role="slider" tabindex="0" aria-label="Resize sheet"><!></div> <div class="bs-content" tabindex="0" role="region" aria-label="Sheet content"><!></div> <span class="bs-sr-only" role="status" aria-live="polite"> </span></section></div>`);
3150
3416
  function BottomSheet($$anchor, $$props) {
3151
3417
  $2.push($$props, true);
3152
- let mode = $2.prop($$props, "mode", 3, "bottom"), animation = $2.prop($$props, "animation", 3, "spring"), focusTrap = $2.prop($$props, "focusTrap", 3, false), closeOnEscape = $2.prop($$props, "closeOnEscape", 3, true), closeOnBack = $2.prop($$props, "closeOnBack", 3, false), lockBodyScroll2 = $2.prop($$props, "lockBodyScroll", 3, true), rubberBand2 = $2.prop($$props, "rubberBand", 3, true), backdrop = $2.prop($$props, "backdrop", 3, true), closeOnBackdrop = $2.prop($$props, "closeOnBackdrop", 3, true), ariaLabel = $2.prop($$props, "ariaLabel", 3, "Bottom sheet");
3418
+ let mode = $2.prop($$props, "mode", 3, "bottom"), animation = $2.prop($$props, "animation", 3, "spring"), focusTrap = $2.prop($$props, "focusTrap", 3, false), closeOnEscape = $2.prop($$props, "closeOnEscape", 3, true), closeOnBack = $2.prop($$props, "closeOnBack", 3, false), lockBodyScroll2 = $2.prop($$props, "lockBodyScroll", 3, true), rubberBand2 = $2.prop($$props, "rubberBand", 3, true), backdrop = $2.prop($$props, "backdrop", 3, true), closeOnBackdrop = $2.prop($$props, "closeOnBackdrop", 3, true), persistent = $2.prop($$props, "persistent", 3, false), disableClose = $2.prop($$props, "disableClose", 3, false), disableDrag = $2.prop($$props, "disableDrag", 3, false), closeOnRouteChange = $2.prop($$props, "closeOnRouteChange", 3, false), openProp = $2.prop($$props, "open", 15), snap = $2.prop($$props, "snap", 15), ariaLabel = $2.prop($$props, "ariaLabel", 3, "Bottom sheet");
3153
3419
  let sheetEl = $2.state(void 0);
3154
3420
  let handleEl = $2.state(void 0);
3155
3421
  let contentEl = $2.state(void 0);
@@ -3182,7 +3448,14 @@ function BottomSheet($$anchor, $$props) {
3182
3448
  closeOnBack: closeOnBack(),
3183
3449
  lockBodyScroll: lockBodyScroll2(),
3184
3450
  rubberBand: rubberBand2(),
3185
- backdropRange: $$props.backdropRange
3451
+ backdropRange: $$props.backdropRange,
3452
+ persistent: persistent(),
3453
+ disableClose: disableClose(),
3454
+ disableDrag: disableDrag(),
3455
+ closeOnRouteChange: closeOnRouteChange(),
3456
+ radius: $$props.radius,
3457
+ maxHeight: $$props.maxHeight,
3458
+ returnFocusTo: $$props.returnFocusTo
3186
3459
  });
3187
3460
  const sync = () => {
3188
3461
  if (!engine) return;
@@ -3190,14 +3463,32 @@ function BottomSheet($$anchor, $$props) {
3190
3463
  $$props.onchange?.($2.get(viewState));
3191
3464
  };
3192
3465
  sync();
3466
+ if ($$props.backdropColor !== void 0) engine.setScrimColor($$props.backdropColor);
3467
+ if ($$props.backdropOpacity !== void 0) engine.setBackdropRange([0, $$props.backdropOpacity]);
3193
3468
  engine.on("snap", (payload) => {
3194
3469
  sync();
3470
+ snap(payload.id);
3195
3471
  $$props.onsnap?.(payload.id);
3196
3472
  });
3197
- engine.on("open", (payload) => $$props.onopen?.(payload.id));
3198
- engine.on("close", () => $$props.onclose?.());
3199
- engine.on("dragstart", sync);
3200
- engine.on("dragend", sync);
3473
+ engine.on("open", (payload) => {
3474
+ openProp(true);
3475
+ $$props.onopen?.(payload.id);
3476
+ });
3477
+ engine.on("close", () => {
3478
+ openProp(false);
3479
+ $$props.onclose?.();
3480
+ });
3481
+ engine.on("before-close", (payload) => $$props.onbeforeclose?.(payload));
3482
+ engine.on("opened", (payload) => $$props.onopened?.(payload.id));
3483
+ engine.on("closed", () => $$props.onclosed?.());
3484
+ engine.on("dragstart", () => {
3485
+ sync();
3486
+ $$props.ondragstart?.();
3487
+ });
3488
+ engine.on("dragend", () => {
3489
+ sync();
3490
+ $$props.ondragend?.();
3491
+ });
3201
3492
  });
3202
3493
  onDestroy(() => {
3203
3494
  engine?.destroy();
@@ -3206,13 +3497,46 @@ function BottomSheet($$anchor, $$props) {
3206
3497
  const snapTo = (id) => engine?.snapTo(id) ?? Promise.resolve();
3207
3498
  const open = (id) => engine?.open(id) ?? Promise.resolve();
3208
3499
  const close = () => engine?.close() ?? Promise.resolve();
3209
- const setAllowed = (ids, snap) => engine?.setAllowed(ids, snap);
3500
+ const expand = () => engine?.expand() ?? Promise.resolve();
3501
+ const collapse = () => engine?.collapse() ?? Promise.resolve();
3502
+ const isTop = () => engine?.isTop() ?? false;
3503
+ const depth = () => engine?.depth() ?? 0;
3504
+ const setAllowed = (ids, snap2) => engine?.setAllowed(ids, snap2);
3210
3505
  const setSnapPoints = (points, nextAllowed) => engine?.setSnapPoints(points, nextAllowed);
3211
3506
  const setScrim = (opts) => engine?.setScrim(opts);
3212
3507
  const setScrimOverlay = (opts) => engine?.setScrimOverlay(opts) ?? (() => {
3213
3508
  });
3509
+ const setRadius = (r) => engine?.setRadius(r);
3510
+ const setMaxHeight = (h) => engine?.setMaxHeight(h);
3511
+ const canDismiss = () => engine?.canDismiss() ?? false;
3214
3512
  const getState = () => engine?.state ?? $2.get(viewState);
3215
3513
  const getEngine = () => engine;
3514
+ $2.user_effect(() => {
3515
+ if ($$props.radius !== void 0) engine?.setRadius($$props.radius);
3516
+ });
3517
+ $2.user_effect(() => {
3518
+ if ($$props.maxHeight !== void 0) engine?.setMaxHeight($$props.maxHeight);
3519
+ });
3520
+ $2.user_effect(() => {
3521
+ if ($$props.backdropColor !== void 0) engine?.setScrimColor($$props.backdropColor);
3522
+ });
3523
+ $2.user_effect(() => {
3524
+ if ($$props.backdropOpacity !== void 0) engine?.setBackdropRange([0, $$props.backdropOpacity]);
3525
+ });
3526
+ $2.user_effect(() => {
3527
+ if (snap() === void 0) return;
3528
+ const next = snap();
3529
+ if (!engine || untrack(() => $2.get(viewState).activeId) === next) return;
3530
+ void engine.snapTo(next);
3531
+ });
3532
+ $2.user_effect(() => {
3533
+ if (openProp() === void 0) return;
3534
+ const next = openProp();
3535
+ if (!engine) return;
3536
+ const isOpen = untrack(() => $2.get(viewState).size) > 0;
3537
+ if (next && !isOpen) void engine.open();
3538
+ else if (!next && isOpen) void engine.close();
3539
+ });
3216
3540
  let allowedIds = $2.derived(() => $$props.allowed && $$props.allowed.length > 0 ? $$props.allowed : $$props.snapPoints.map((s) => s.id));
3217
3541
  let activeIdx = $2.derived(() => $2.get(allowedIds).indexOf($2.get(viewState).activeId));
3218
3542
  let isVerticalAxis = $2.derived(() => mode() === "bottom" || mode() === "top");
@@ -3220,10 +3544,17 @@ function BottomSheet($$anchor, $$props) {
3220
3544
  snapTo,
3221
3545
  open,
3222
3546
  close,
3547
+ expand,
3548
+ collapse,
3549
+ isTop,
3550
+ depth,
3223
3551
  setAllowed,
3224
3552
  setSnapPoints,
3225
3553
  setScrim,
3226
3554
  setScrimOverlay,
3555
+ setRadius,
3556
+ setMaxHeight,
3557
+ canDismiss,
3227
3558
  getState,
3228
3559
  getEngine
3229
3560
  };
@@ -3234,7 +3565,9 @@ function BottomSheet($$anchor, $$props) {
3234
3565
  var div_1 = root_1();
3235
3566
  $2.bind_this(div_1, ($$value) => $2.set(backdropEl, $$value), () => $2.get(backdropEl));
3236
3567
  $2.delegated("click", div_1, function(...$$args) {
3237
- (closeOnBackdrop() ? () => engine?.close() : void 0)?.apply(this, $$args);
3568
+ (closeOnBackdrop() ? () => {
3569
+ if (engine?.canDismiss()) void engine.close("backdrop");
3570
+ } : void 0)?.apply(this, $$args);
3238
3571
  });
3239
3572
  $2.append($$anchor2, div_1);
3240
3573
  };