@surdeddd/bottom-sheet 0.10.0 → 0.12.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 (42) hide show
  1. package/README.md +52 -35
  2. package/dist/{BottomSheetEngine-DzsIwD28.d.cts → BottomSheetEngine-D6oiEfZ4.d.cts} +1 -0
  3. package/dist/{BottomSheetEngine-DRjCU73e.d.ts → BottomSheetEngine-Dhy0X_e9.d.ts} +1 -0
  4. package/dist/element.cjs +250 -136
  5. package/dist/element.d.cts +1 -1
  6. package/dist/element.d.ts +1 -1
  7. package/dist/element.iife.global.js +2 -2
  8. package/dist/element.js +250 -136
  9. package/dist/index.cjs +257 -164
  10. package/dist/index.d.cts +2 -2
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.js +257 -164
  13. package/dist/integrations/formik.d.cts +1 -1
  14. package/dist/integrations/formik.d.ts +1 -1
  15. package/dist/integrations/react-hook-form.d.cts +1 -1
  16. package/dist/integrations/react-hook-form.d.ts +1 -1
  17. package/dist/overlay.cjs +161 -33
  18. package/dist/overlay.d.cts +1 -3
  19. package/dist/overlay.d.ts +1 -3
  20. package/dist/overlay.js +161 -33
  21. package/dist/preact.d.cts +1 -1
  22. package/dist/preact.d.ts +1 -1
  23. package/dist/qwik.cjs +240 -131
  24. package/dist/qwik.d.cts +2 -2
  25. package/dist/qwik.d.ts +2 -2
  26. package/dist/qwik.js +240 -131
  27. package/dist/react.cjs +257 -164
  28. package/dist/react.d.cts +2 -2
  29. package/dist/react.d.ts +2 -2
  30. package/dist/react.js +257 -164
  31. package/dist/solid.cjs +240 -131
  32. package/dist/solid.d.cts +1 -0
  33. package/dist/solid.d.ts +1 -0
  34. package/dist/solid.js +240 -131
  35. package/dist/solid.source.jsx +240 -131
  36. package/dist/svelte-core.cjs +240 -131
  37. package/dist/svelte-core.js +240 -131
  38. package/dist/svelte.cjs +252 -143
  39. package/dist/svelte.js +252 -143
  40. package/dist/vue.cjs +240 -131
  41. package/dist/vue.js +240 -131
  42. package/package.json +10 -8
package/dist/qwik.cjs CHANGED
@@ -441,46 +441,202 @@ function notifyLinkedSheets(sheets, self) {
441
441
  }
442
442
  }
443
443
 
444
- // src/core/features/route.ts
445
- var closers = [];
446
- var handlerInstalled = false;
444
+ // src/core/features/history-coordinator.ts
445
+ var entries = [];
446
+ var subscribers = /* @__PURE__ */ new Set();
447
447
  var suppress = 0;
448
- var ensureHandler = () => {
449
- if (handlerInstalled || typeof window === "undefined") return;
450
- handlerInstalled = true;
451
- window.addEventListener("popstate", () => {
452
- if (suppress > 0) {
453
- suppress -= 1;
454
- return;
448
+ var internalDepth = 0;
449
+ var pendingRebrand = null;
450
+ var listenerInstalled = false;
451
+ var patchInstalled = false;
452
+ var origPushState = null;
453
+ var origReplaceState = null;
454
+ var patchedPushState = null;
455
+ var patchedReplaceState = null;
456
+ var hasWindow = () => typeof window !== "undefined";
457
+ var hasHistory = () => typeof history !== "undefined";
458
+ var brandMarker = (surface) => ({
459
+ ...surface.markerState(),
460
+ __bs: true
461
+ });
462
+ var runInternal = (fn) => {
463
+ internalDepth += 1;
464
+ try {
465
+ fn();
466
+ } finally {
467
+ internalDepth -= 1;
468
+ }
469
+ };
470
+ var notifyRouteChange = () => {
471
+ const snapshot = Array.from(subscribers);
472
+ for (const fn of snapshot) fn();
473
+ };
474
+ var ensureListener = () => {
475
+ if (listenerInstalled || !hasWindow()) return;
476
+ window.addEventListener("popstate", onPopState);
477
+ listenerInstalled = true;
478
+ };
479
+ var maybeTeardownListener = () => {
480
+ if (!listenerInstalled) return;
481
+ if (entries.length > 0 || subscribers.size > 0 || suppress > 0) return;
482
+ if (hasWindow()) window.removeEventListener("popstate", onPopState);
483
+ listenerInstalled = false;
484
+ };
485
+ var installPatch = () => {
486
+ if (patchInstalled || !hasHistory()) return;
487
+ origPushState = history.pushState;
488
+ origReplaceState = history.replaceState;
489
+ patchedPushState = function(...args) {
490
+ origPushState.apply(this, args);
491
+ if (internalDepth === 0) notifyRouteChange();
492
+ };
493
+ patchedReplaceState = function(...args) {
494
+ origReplaceState.apply(this, args);
495
+ if (internalDepth === 0) notifyRouteChange();
496
+ };
497
+ history.pushState = patchedPushState;
498
+ history.replaceState = patchedReplaceState;
499
+ patchInstalled = true;
500
+ };
501
+ var removePatch = () => {
502
+ if (!patchInstalled) return;
503
+ if (history.pushState === patchedPushState && origPushState) {
504
+ history.pushState = origPushState;
505
+ }
506
+ if (history.replaceState === patchedReplaceState && origReplaceState) {
507
+ history.replaceState = origReplaceState;
508
+ }
509
+ origPushState = null;
510
+ origReplaceState = null;
511
+ patchedPushState = null;
512
+ patchedReplaceState = null;
513
+ patchInstalled = false;
514
+ };
515
+ function onPopState() {
516
+ if (suppress > 0) {
517
+ suppress -= 1;
518
+ const rebrand = pendingRebrand;
519
+ pendingRebrand = null;
520
+ if (rebrand) rebrand();
521
+ maybeTeardownListener();
522
+ return;
523
+ }
524
+ if (entries.length === 0) {
525
+ notifyRouteChange();
526
+ maybeTeardownListener();
527
+ return;
528
+ }
529
+ let target = null;
530
+ let targetIdx = -1;
531
+ for (let i = entries.length - 1; i >= 0; i -= 1) {
532
+ const entry = entries[i];
533
+ if (!entry.surface.isOpen()) continue;
534
+ if (!target) {
535
+ target = entry;
536
+ targetIdx = i;
455
537
  }
456
- let target = null;
457
- for (let i = closers.length - 1; i >= 0; i -= 1) {
458
- const c = closers[i];
459
- if (!c.isOpen()) continue;
460
- if (!target) target = c;
461
- if (c.isTop()) {
462
- target = c;
463
- break;
464
- }
538
+ if (entry.surface.isTop()) {
539
+ target = entry;
540
+ targetIdx = i;
541
+ break;
465
542
  }
466
- if (!target) return;
467
- target.consumed = true;
468
- const idx = closers.indexOf(target);
469
- if (idx !== -1) closers.splice(idx, 1);
470
- const settled = target;
471
- void Promise.resolve(settled.close()).then(() => {
472
- if (settled.isOpen()) settled.restore();
473
- });
543
+ }
544
+ if (!target) {
545
+ const removed = entries.pop();
546
+ if (removed) removed.live = false;
547
+ maybeTeardownListener();
548
+ return;
549
+ }
550
+ target.live = false;
551
+ entries.splice(targetIdx, 1);
552
+ const settled = target;
553
+ void Promise.resolve(settled.surface.close()).then(() => {
554
+ if (settled.surface.isOpen()) restore(settled);
474
555
  });
475
- };
476
- var programmaticBack = () => {
477
- suppress += 1;
478
- try {
479
- history.back();
480
- } catch {
481
- suppress = Math.max(0, suppress - 1);
556
+ maybeTeardownListener();
557
+ }
558
+ function restore(entry) {
559
+ if (!hasWindow() || !hasHistory()) return;
560
+ entry.live = true;
561
+ runInternal(() => {
562
+ try {
563
+ history.pushState(brandMarker(entry.surface), "", entry.surface.url);
564
+ } catch {
565
+ entry.live = false;
566
+ }
567
+ });
568
+ if (entry.live) {
569
+ entries.push(entry);
570
+ ensureListener();
482
571
  }
483
- };
572
+ }
573
+ function pushBackMarker(surface) {
574
+ const entry = { surface, priorUrl: void 0, live: false };
575
+ if (!hasWindow() || !hasHistory()) {
576
+ return entry;
577
+ }
578
+ entry.priorUrl = surface.url !== void 0 ? location.href : void 0;
579
+ runInternal(() => {
580
+ try {
581
+ history.pushState(brandMarker(surface), "", surface.url);
582
+ entry.live = true;
583
+ } catch {
584
+ entry.live = false;
585
+ }
586
+ });
587
+ if (entry.live) {
588
+ entries.push(entry);
589
+ ensureListener();
590
+ }
591
+ return entry;
592
+ }
593
+ function popBackMarker(handle) {
594
+ if (!hasWindow() || !hasHistory()) return;
595
+ const entry = handle;
596
+ const idx = entries.indexOf(entry);
597
+ if (idx === -1 || !entry.live) return;
598
+ const last = entries.length - 1;
599
+ entry.live = false;
600
+ entries.splice(idx, 1);
601
+ if (idx !== last) {
602
+ const rebrandSurface = entries[entries.length - 1].surface;
603
+ const rebrandUrl = entry.priorUrl;
604
+ pendingRebrand = () => {
605
+ runInternal(() => {
606
+ history.replaceState(
607
+ brandMarker(rebrandSurface),
608
+ "",
609
+ rebrandUrl !== void 0 ? rebrandUrl : location.href
610
+ );
611
+ });
612
+ };
613
+ }
614
+ suppress += 1;
615
+ runInternal(() => {
616
+ try {
617
+ history.back();
618
+ } catch {
619
+ suppress = Math.max(0, suppress - 1);
620
+ pendingRebrand = null;
621
+ }
622
+ });
623
+ maybeTeardownListener();
624
+ }
625
+ function subscribeRouteChange(fn) {
626
+ if (!hasWindow() || !hasHistory()) return () => {
627
+ };
628
+ subscribers.add(fn);
629
+ if (subscribers.size === 1) installPatch();
630
+ ensureListener();
631
+ return () => {
632
+ if (!subscribers.has(fn)) return;
633
+ subscribers.delete(fn);
634
+ if (subscribers.size === 0) removePatch();
635
+ maybeTeardownListener();
636
+ };
637
+ }
638
+
639
+ // src/core/features/route.ts
484
640
  function installRoute(deps) {
485
641
  if (typeof window === "undefined") {
486
642
  return () => {
@@ -490,92 +646,39 @@ function installRoute(deps) {
490
646
  return () => {
491
647
  };
492
648
  }
493
- let pushed = false;
494
- let closer = null;
495
- const teardownEntry = () => {
496
- if (closer) {
497
- const idx = closers.indexOf(closer);
498
- if (idx !== -1) closers.splice(idx, 1);
499
- }
500
- const wasConsumed = closer?.consumed ?? false;
501
- closer = null;
502
- if (pushed && !wasConsumed) {
503
- pushed = false;
504
- programmaticBack();
505
- } else {
506
- pushed = false;
507
- }
508
- };
509
- const pushEntry = () => {
510
- try {
511
- if (deps.routedTo !== void 0) {
512
- history.pushState({ __bsRouted: deps.sheetId }, "", deps.routedTo);
513
- } else {
514
- history.pushState({ __bsSheet: deps.sheetId }, "");
515
- }
516
- pushed = true;
517
- } catch {
518
- pushed = false;
519
- }
520
- };
649
+ let handle = null;
521
650
  const onOpen = () => {
522
- if (closer) return;
523
- const self = {
651
+ if (handle) return;
652
+ handle = pushBackMarker({
524
653
  isOpen: () => !deps.isDestroyed() && deps.getSize() > 0,
525
- isTop: () => deps.isTopSheet(),
526
- close: () => deps.close(),
527
- restore: () => {
528
- if (deps.isDestroyed() || closer !== self) return;
529
- self.consumed = false;
530
- if (!closers.includes(self)) closers.push(self);
531
- pushEntry();
532
- },
533
- consumed: false
534
- };
535
- closer = self;
536
- ensureHandler();
537
- closers.push(self);
538
- pushEntry();
654
+ isTop: deps.isTopSheet,
655
+ close: deps.close,
656
+ markerState: () => deps.routedTo !== void 0 ? { __bsRouted: deps.sheetId } : { __bsSheet: deps.sheetId },
657
+ url: deps.routedTo
658
+ });
659
+ };
660
+ const onClose = () => {
661
+ if (!handle) return;
662
+ popBackMarker(handle);
663
+ handle = null;
539
664
  };
540
665
  const unsubscribeOpen = deps.on("open", onOpen);
541
- const unsubscribeClose = deps.on("close", teardownEntry);
666
+ const unsubscribeClose = deps.on("close", onClose);
542
667
  if (deps.getSize() > 0) onOpen();
543
668
  return () => {
544
669
  unsubscribeOpen();
545
670
  unsubscribeClose();
546
- teardownEntry();
671
+ if (handle) {
672
+ popBackMarker(handle);
673
+ handle = null;
674
+ }
547
675
  };
548
676
  }
549
677
  function installRouteChange(deps) {
550
- if (typeof window === "undefined" || typeof history === "undefined") {
551
- return () => {
552
- };
553
- }
554
- const onChange = () => {
678
+ return subscribeRouteChange(() => {
555
679
  if (deps.isDestroyed() || deps.getSize() <= 0) return;
556
680
  void deps.close();
557
- };
558
- const wrap = (key) => {
559
- const original = history[key];
560
- const patched = function(...args) {
561
- original.apply(this, args);
562
- onChange();
563
- };
564
- history[key] = patched;
565
- return () => {
566
- if (history[key] === patched) {
567
- history[key] = original;
568
- }
569
- };
570
- };
571
- window.addEventListener("popstate", onChange);
572
- const restorePush = wrap("pushState");
573
- const restoreReplace = wrap("replaceState");
574
- return () => {
575
- window.removeEventListener("popstate", onChange);
576
- restorePush();
577
- restoreReplace();
578
- };
681
+ });
579
682
  }
580
683
 
581
684
  // src/core/features/content-swipe.ts
@@ -845,11 +948,15 @@ function createMaxHeightController(deps) {
845
948
 
846
949
  // src/core/features/fit-measurement.ts
847
950
  var measureSheetNatural = (element, content, vertical) => {
848
- if (!content) {
849
- return vertical ? element.offsetHeight : element.offsetWidth;
850
- }
851
951
  const axis = vertical ? "height" : "width";
852
952
  const sheetStyle = element.style;
953
+ if (!content) {
954
+ const prev = sheetStyle[axis];
955
+ sheetStyle[axis] = "auto";
956
+ const poked2 = vertical ? element.offsetHeight : element.offsetWidth;
957
+ sheetStyle[axis] = prev;
958
+ return poked2;
959
+ }
853
960
  const cs = content.style;
854
961
  const prevSheet = sheetStyle[axis];
855
962
  const prevFlex = cs.flex;
@@ -2428,7 +2535,7 @@ var matchesRange = (def, progress) => {
2428
2535
  };
2429
2536
  function installScrimStages(deps, opts) {
2430
2537
  const doc = deps.host.ownerDocument;
2431
- const entries = opts.stages.map((def) => {
2538
+ const entries2 = opts.stages.map((def) => {
2432
2539
  const wrapper = doc.createElement("div");
2433
2540
  wrapper.className = "bs-scrim-stage";
2434
2541
  const ws = wrapper.style;
@@ -2449,9 +2556,9 @@ function installScrimStages(deps, opts) {
2449
2556
  const resolveActive = () => {
2450
2557
  const state = deps.getState();
2451
2558
  if (state.size === 0) {
2452
- return entries.find((e) => matchesId(e.def, state.activeId)) ?? null;
2559
+ return entries2.find((e) => matchesId(e.def, state.activeId)) ?? null;
2453
2560
  }
2454
- return entries.find((e) => matchesId(e.def, state.activeId)) ?? entries.find((e) => matchesRange(e.def, state.progress)) ?? null;
2561
+ return entries2.find((e) => matchesId(e.def, state.activeId)) ?? entries2.find((e) => matchesRange(e.def, state.progress)) ?? null;
2455
2562
  };
2456
2563
  const hide = (entry, animate) => {
2457
2564
  entry.inFlight?.cancel();
@@ -2500,13 +2607,13 @@ function installScrimStages(deps, opts) {
2500
2607
  deps.on("open", () => update(true)),
2501
2608
  deps.on("close", () => update(true))
2502
2609
  ];
2503
- if (entries.some((e) => e.def.forRange)) {
2610
+ if (entries2.some((e) => e.def.forRange)) {
2504
2611
  offs.push(deps.on("progress", () => update(true)));
2505
2612
  }
2506
2613
  update(false);
2507
2614
  return () => {
2508
2615
  offs.forEach((off) => off());
2509
- for (const entry of entries) {
2616
+ for (const entry of entries2) {
2510
2617
  entry.inFlight?.cancel();
2511
2618
  entry.inFlight = null;
2512
2619
  if (entry.wrapper.parentNode) {
@@ -2765,17 +2872,12 @@ var BottomSheetEngine = class {
2765
2872
  this.attach();
2766
2873
  this.registerInStack();
2767
2874
  if (this.snaps.getMaxAxisSize() === 0 && typeof IntersectionObserver !== "undefined" && typeof document !== "undefined") {
2768
- const io = new IntersectionObserver((entries) => {
2769
- for (const entry of entries) {
2875
+ const io = new IntersectionObserver((entries2) => {
2876
+ for (const entry of entries2) {
2770
2877
  if (!entry.isIntersecting) continue;
2771
2878
  if (this.destroyed) return;
2772
2879
  this.snaps.recompute();
2773
- const current = this.snaps.findById(this.activeId);
2774
- if (current) {
2775
- this.size = current.size;
2776
- this.applySize(this.size);
2777
- this.updateAriaSlider();
2778
- }
2880
+ this.healActiveSnap();
2779
2881
  io.disconnect();
2780
2882
  return;
2781
2883
  }
@@ -2939,6 +3041,8 @@ var BottomSheetEngine = class {
2939
3041
  const vt = document.startViewTransition(() => {
2940
3042
  this.applySize(target.size);
2941
3043
  });
3044
+ vt.ready?.catch(() => {
3045
+ });
2942
3046
  this.currentViewTransition = vt;
2943
3047
  try {
2944
3048
  await vt.finished;
@@ -3190,11 +3294,16 @@ var BottomSheetEngine = class {
3190
3294
  this.maxHeight.clampTo();
3191
3295
  this.scrim.invalidateOpacityCache();
3192
3296
  if (this.gesture?.isDragging) return;
3297
+ this.healActiveSnap();
3298
+ }
3299
+ healActiveSnap() {
3193
3300
  const current = this.snaps.findById(this.activeId);
3194
- if (current) {
3195
- this.size = current.size;
3196
- this.applySize(this.size);
3197
- this.updateAriaSlider();
3301
+ if (!current) return;
3302
+ this.size = current.size;
3303
+ this.applySize(this.size);
3304
+ this.updateAriaSlider();
3305
+ if (this.size > 0 && !this.lifecycle.isInstalled && !this.opening && !this.animation.isAnimating) {
3306
+ this.emitOpenSequence(this.activeId);
3198
3307
  }
3199
3308
  }
3200
3309
  destroy() {
@@ -3483,9 +3592,9 @@ var BottomSheetEngine = class {
3483
3592
  return;
3484
3593
  }
3485
3594
  if (this.emitBeforeSnap(target, previousId)) {
3486
- const restore = this.snaps.findById(previousId);
3487
- if (restore) {
3488
- void this.animation.animateTo(restore.size, 0);
3595
+ const restore2 = this.snaps.findById(previousId);
3596
+ if (restore2) {
3597
+ void this.animation.animateTo(restore2.size, 0);
3489
3598
  }
3490
3599
  return;
3491
3600
  }
package/dist/qwik.d.cts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as _builder_io_qwik from '@builder.io/qwik';
2
2
  import { QRL } from '@builder.io/qwik';
3
3
  import { T as TeleportTarget } from './teleport-7uYNiEAT.cjs';
4
- import { a as SnapPointDef, b as SheetMode, c as EngineOptions, d as SheetEventMap, E as EngineState } from './BottomSheetEngine-DzsIwD28.cjs';
5
- export { e as SnapPoint } from './BottomSheetEngine-DzsIwD28.cjs';
4
+ import { a as SnapPointDef, b as SheetMode, c as EngineOptions, d as SheetEventMap, E as EngineState } from './BottomSheetEngine-D6oiEfZ4.cjs';
5
+ export { e as SnapPoint } from './BottomSheetEngine-D6oiEfZ4.cjs';
6
6
  import './transform-jVfAikE9.cjs';
7
7
 
8
8
  type BottomSheetProps<TId extends string = string> = {
package/dist/qwik.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as _builder_io_qwik from '@builder.io/qwik';
2
2
  import { QRL } from '@builder.io/qwik';
3
3
  import { T as TeleportTarget } from './teleport-7uYNiEAT.js';
4
- import { a as SnapPointDef, b as SheetMode, c as EngineOptions, d as SheetEventMap, E as EngineState } from './BottomSheetEngine-DRjCU73e.js';
5
- export { e as SnapPoint } from './BottomSheetEngine-DRjCU73e.js';
4
+ import { a as SnapPointDef, b as SheetMode, c as EngineOptions, d as SheetEventMap, E as EngineState } from './BottomSheetEngine-Dhy0X_e9.js';
5
+ export { e as SnapPoint } from './BottomSheetEngine-Dhy0X_e9.js';
6
6
  import './transform-jVfAikE9.js';
7
7
 
8
8
  type BottomSheetProps<TId extends string = string> = {