@surdeddd/bottom-sheet 0.9.1 → 0.11.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 (50) hide show
  1. package/README.md +126 -83
  2. package/dist/{BottomSheetEngine-CBRcBwV-.d.ts → BottomSheetEngine-DRjCU73e.d.ts} +6 -5
  3. package/dist/{BottomSheetEngine-BcyruNP1.d.cts → BottomSheetEngine-DzsIwD28.d.cts} +6 -5
  4. package/dist/element.cjs +388 -222
  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 +388 -222
  9. package/dist/index.cjs +389 -266
  10. package/dist/index.d.cts +2 -2
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.js +389 -266
  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 +191 -58
  18. package/dist/overlay.d.cts +4 -3
  19. package/dist/overlay.d.ts +4 -3
  20. package/dist/overlay.js +191 -58
  21. package/dist/preact.d.cts +2 -1
  22. package/dist/preact.d.ts +2 -1
  23. package/dist/qwik.cjs +396 -211
  24. package/dist/qwik.d.cts +11 -2
  25. package/dist/qwik.d.ts +11 -2
  26. package/dist/qwik.js +396 -211
  27. package/dist/react.cjs +500 -332
  28. package/dist/react.d.cts +26 -4
  29. package/dist/react.d.ts +26 -4
  30. package/dist/react.js +500 -332
  31. package/dist/solid.cjs +362 -210
  32. package/dist/solid.d.cts +14 -4
  33. package/dist/solid.d.ts +14 -4
  34. package/dist/solid.js +362 -210
  35. package/dist/solid.source.jsx +362 -210
  36. package/dist/styles.css +17 -1
  37. package/dist/svelte-core.cjs +345 -208
  38. package/dist/svelte-core.js +345 -208
  39. package/dist/svelte-src/BottomSheet.svelte +6 -0
  40. package/dist/svelte.cjs +359 -220
  41. package/dist/svelte.d.cts +2 -0
  42. package/dist/svelte.d.ts +2 -0
  43. package/dist/svelte.js +359 -220
  44. package/dist/teleport-7uYNiEAT.d.cts +3 -0
  45. package/dist/teleport-7uYNiEAT.d.ts +3 -0
  46. package/dist/vue.cjs +353 -209
  47. package/dist/vue.d.cts +3 -1
  48. package/dist/vue.d.ts +3 -1
  49. package/dist/vue.js +353 -209
  50. package/package.json +11 -9
package/dist/overlay.js CHANGED
@@ -118,6 +118,13 @@ var resolveSnap = (point, mode, measureFit) => {
118
118
  }
119
119
  };
120
120
 
121
+ // src/core/primitives/devWarn.ts
122
+ function devWarn(...args) {
123
+ if (typeof process !== "undefined" && process.env && process.env.NODE_ENV !== "production" && typeof console !== "undefined") {
124
+ console.warn(...args);
125
+ }
126
+ }
127
+
121
128
  // src/core/primitives/instance-id.ts
122
129
  var counters = {};
123
130
  function nextInstanceId(prefix) {
@@ -520,7 +527,147 @@ function installOverlaySwipe(deps) {
520
527
  };
521
528
  }
522
529
 
523
- // src/core/overlay.ts
530
+ // src/core/features/history-coordinator.ts
531
+ var entries = [];
532
+ var subscribers = /* @__PURE__ */ new Set();
533
+ var suppress = 0;
534
+ var pendingRebrand = null;
535
+ var listenerInstalled = false;
536
+ var hasWindow = () => typeof window !== "undefined";
537
+ var hasHistory = () => typeof history !== "undefined";
538
+ var runInternal = (fn) => {
539
+ try {
540
+ fn();
541
+ } finally {
542
+ }
543
+ };
544
+ var notifyRouteChange = () => {
545
+ const snapshot = Array.from(subscribers);
546
+ for (const fn of snapshot) fn();
547
+ };
548
+ var ensureListener = () => {
549
+ if (listenerInstalled || !hasWindow()) return;
550
+ window.addEventListener("popstate", onPopState);
551
+ listenerInstalled = true;
552
+ };
553
+ var maybeTeardownListener = () => {
554
+ if (!listenerInstalled) return;
555
+ if (entries.length > 0 || subscribers.size > 0 || suppress > 0) return;
556
+ if (hasWindow()) window.removeEventListener("popstate", onPopState);
557
+ listenerInstalled = false;
558
+ };
559
+ function onPopState() {
560
+ if (suppress > 0) {
561
+ suppress -= 1;
562
+ const rebrand = pendingRebrand;
563
+ pendingRebrand = null;
564
+ if (rebrand) rebrand();
565
+ maybeTeardownListener();
566
+ return;
567
+ }
568
+ if (entries.length === 0) {
569
+ notifyRouteChange();
570
+ maybeTeardownListener();
571
+ return;
572
+ }
573
+ let target = null;
574
+ let targetIdx = -1;
575
+ for (let i = entries.length - 1; i >= 0; i -= 1) {
576
+ const entry = entries[i];
577
+ if (!entry.surface.isOpen()) continue;
578
+ if (!target) {
579
+ target = entry;
580
+ targetIdx = i;
581
+ }
582
+ if (entry.surface.isTop()) {
583
+ target = entry;
584
+ targetIdx = i;
585
+ break;
586
+ }
587
+ }
588
+ if (!target) {
589
+ const removed = entries.pop();
590
+ if (removed) removed.live = false;
591
+ maybeTeardownListener();
592
+ return;
593
+ }
594
+ target.live = false;
595
+ entries.splice(targetIdx, 1);
596
+ const settled = target;
597
+ void Promise.resolve(settled.surface.close()).then(() => {
598
+ if (settled.surface.isOpen()) restore(settled);
599
+ });
600
+ maybeTeardownListener();
601
+ }
602
+ function restore(entry) {
603
+ if (!hasWindow() || !hasHistory()) return;
604
+ entry.live = true;
605
+ runInternal(() => {
606
+ try {
607
+ history.pushState(entry.surface.markerState(), "", entry.surface.url);
608
+ } catch {
609
+ entry.live = false;
610
+ }
611
+ });
612
+ if (entry.live) {
613
+ entries.push(entry);
614
+ ensureListener();
615
+ }
616
+ }
617
+ function pushBackMarker(surface) {
618
+ const entry = { surface, priorUrl: void 0, live: false };
619
+ if (!hasWindow() || !hasHistory()) {
620
+ return entry;
621
+ }
622
+ entry.priorUrl = surface.url !== void 0 ? location.href : void 0;
623
+ runInternal(() => {
624
+ try {
625
+ history.pushState(surface.markerState(), "", surface.url);
626
+ entry.live = true;
627
+ } catch {
628
+ entry.live = false;
629
+ }
630
+ });
631
+ if (entry.live) {
632
+ entries.push(entry);
633
+ ensureListener();
634
+ }
635
+ return entry;
636
+ }
637
+ function popBackMarker(handle) {
638
+ if (!hasWindow() || !hasHistory()) return;
639
+ const entry = handle;
640
+ const idx = entries.indexOf(entry);
641
+ if (idx === -1 || !entry.live) return;
642
+ const last = entries.length - 1;
643
+ entry.live = false;
644
+ entries.splice(idx, 1);
645
+ if (idx !== last) {
646
+ const rebrandSurface = entries[entries.length - 1].surface;
647
+ const rebrandUrl = entry.priorUrl;
648
+ pendingRebrand = () => {
649
+ runInternal(() => {
650
+ history.replaceState(
651
+ rebrandSurface.markerState(),
652
+ "",
653
+ rebrandUrl !== void 0 ? rebrandUrl : location.href
654
+ );
655
+ });
656
+ };
657
+ }
658
+ suppress += 1;
659
+ runInternal(() => {
660
+ try {
661
+ history.back();
662
+ } catch {
663
+ suppress = Math.max(0, suppress - 1);
664
+ pendingRebrand = null;
665
+ }
666
+ });
667
+ maybeTeardownListener();
668
+ }
669
+
670
+ // src/core/overlay-options.ts
524
671
  var OVERLAY_PRESETS = Object.freeze({
525
672
  sheet: Object.freeze({
526
673
  enterAnimation: "slide",
@@ -551,6 +698,8 @@ var OVERLAY_PRESETS = Object.freeze({
551
698
  swipeToClose: false
552
699
  })
553
700
  });
701
+
702
+ // src/core/overlay.ts
554
703
  var OverlayEngine = class {
555
704
  constructor(opts) {
556
705
  __publicField(this, "id", nextInstanceId("ovl"));
@@ -585,7 +734,7 @@ var OverlayEngine = class {
585
734
  __publicField(this, "detachSwipe", null);
586
735
  __publicField(this, "respectReducedMotionEnabled");
587
736
  __publicField(this, "isTop", true);
588
- __publicField(this, "backPushed", false);
737
+ __publicField(this, "backMarker", null);
589
738
  __publicField(this, "movedToTarget", false);
590
739
  __publicField(this, "onOpenCb");
591
740
  __publicField(this, "onCloseCb");
@@ -597,7 +746,6 @@ var OverlayEngine = class {
597
746
  __publicField(this, "bus", createEventBus());
598
747
  __publicField(this, "detachEscape", null);
599
748
  __publicField(this, "detachBackdrop", null);
600
- __publicField(this, "detachHardwareBack", null);
601
749
  __publicField(this, "releaseStackEntry", null);
602
750
  __publicField(this, "lifecycle");
603
751
  this.element = opts.element;
@@ -627,7 +775,7 @@ var OverlayEngine = class {
627
775
  this.onOpenCb = opts.onOpen;
628
776
  this.onCloseCb = opts.onClose;
629
777
  if (this.peekRaw !== void 0 && this.edge !== "bottom") {
630
- console.warn(
778
+ devWarn(
631
779
  "[OverlayEngine] `peek` is only supported on edge: 'bottom' \u2014 ignoring."
632
780
  );
633
781
  this.peekRaw = void 0;
@@ -694,10 +842,9 @@ var OverlayEngine = class {
694
842
  this.element.style.opacity = "1";
695
843
  if (this.backdrop) {
696
844
  this.backdrop.style.opacity = String(this.backdropOpacity);
697
- this.backdrop.style.pointerEvents = this.backdropOpacity > 0 ? "auto" : "none";
845
+ this.syncBackdropPointerEvents();
698
846
  if (this.backdropFilter) {
699
- this.backdrop.style.backdropFilter = this.backdropFilter;
700
- this.backdrop.style.webkitBackdropFilter = this.backdropFilter;
847
+ this.applyBackdropFilter(this.backdropFilter);
701
848
  }
702
849
  }
703
850
  try {
@@ -717,8 +864,7 @@ var OverlayEngine = class {
717
864
  this.backdrop.style.opacity = "0";
718
865
  this.backdrop.style.pointerEvents = "none";
719
866
  if (this.backdropFilter) {
720
- this.backdrop.style.backdropFilter = "";
721
- this.backdrop.style.webkitBackdropFilter = "";
867
+ this.applyBackdropFilter(void 0);
722
868
  }
723
869
  }
724
870
  this.element.setAttribute("data-state", "closed");
@@ -753,7 +899,10 @@ var OverlayEngine = class {
753
899
  this.isOpen_ = false;
754
900
  this.isAnimating_ = true;
755
901
  sheetStack.update();
756
- this.popBackMarker(reason);
902
+ if (reason !== "back" && this.backMarker) {
903
+ popBackMarker(this.backMarker);
904
+ }
905
+ this.backMarker = null;
757
906
  this.element.setAttribute("data-state", "exiting");
758
907
  const dur = this.effectiveDuration();
759
908
  const transitionStr = `transform ${dur}ms ${this.exitEasing}, opacity ${dur}ms ease-in`;
@@ -776,8 +925,7 @@ var OverlayEngine = class {
776
925
  this.backdrop.style.opacity = "0";
777
926
  this.backdrop.style.pointerEvents = "none";
778
927
  if (this.backdropFilter) {
779
- this.backdrop.style.backdropFilter = "";
780
- this.backdrop.style.webkitBackdropFilter = "";
928
+ this.applyBackdropFilter(void 0);
781
929
  }
782
930
  }
783
931
  this.releaseInteractiveListeners();
@@ -812,6 +960,10 @@ var OverlayEngine = class {
812
960
  this.bus.clear();
813
961
  this.setWillChange(false);
814
962
  this.releaseInteractiveListeners();
963
+ if (this.backMarker) {
964
+ popBackMarker(this.backMarker);
965
+ this.backMarker = null;
966
+ }
815
967
  this.releaseStackEntry?.();
816
968
  this.releaseStackEntry = null;
817
969
  const hadOriginalParent = this.originalParent !== null;
@@ -825,20 +977,14 @@ var OverlayEngine = class {
825
977
  this.backdropOpacity = opacity;
826
978
  if (this.isOpen_ && this.backdrop) {
827
979
  this.backdrop.style.opacity = String(opacity);
980
+ this.syncBackdropPointerEvents();
828
981
  }
829
982
  }
830
983
  setBackdropFilter(filter) {
831
984
  if (this.destroyed) return;
832
985
  this.backdropFilter = filter;
833
986
  if (!this.isOpen_ || !this.backdrop) return;
834
- const style = this.backdrop.style;
835
- if (filter) {
836
- this.backdrop.style.backdropFilter = filter;
837
- style.webkitBackdropFilter = filter;
838
- } else {
839
- this.backdrop.style.backdropFilter = "";
840
- style.webkitBackdropFilter = "";
841
- }
987
+ this.applyBackdropFilter(filter);
842
988
  }
843
989
  setSwipeToClose(config) {
844
990
  if (this.destroyed) return;
@@ -907,16 +1053,10 @@ var OverlayEngine = class {
907
1053
  if (this.isOpen_ && this.backdrop) {
908
1054
  if (merged.backdropOpacity !== void 0) {
909
1055
  this.backdrop.style.opacity = String(this.backdropOpacity);
1056
+ this.syncBackdropPointerEvents();
910
1057
  }
911
1058
  if (merged.backdropFilter !== void 0) {
912
- const style = this.backdrop.style;
913
- if (this.backdropFilter) {
914
- this.backdrop.style.backdropFilter = this.backdropFilter;
915
- style.webkitBackdropFilter = this.backdropFilter;
916
- } else {
917
- this.backdrop.style.backdropFilter = "";
918
- style.webkitBackdropFilter = "";
919
- }
1059
+ this.applyBackdropFilter(this.backdropFilter);
920
1060
  }
921
1061
  }
922
1062
  if (opts.duration !== void 0) this.duration = opts.duration;
@@ -985,19 +1125,6 @@ var OverlayEngine = class {
985
1125
  effectiveDuration() {
986
1126
  return this.respectReducedMotionEnabled && prefersReducedMotion() ? 0 : this.duration;
987
1127
  }
988
- popBackMarker(reason) {
989
- if (!this.backPushed) return;
990
- this.backPushed = false;
991
- if (reason === "back") return;
992
- const state = history.state;
993
- if (state && state.__bsOverlay === this.id) {
994
- try {
995
- history.back();
996
- } catch {
997
- return;
998
- }
999
- }
1000
- }
1001
1128
  resolvePeekPx(raw) {
1002
1129
  if (typeof raw === "number") return Math.max(0, raw);
1003
1130
  try {
@@ -1051,6 +1178,21 @@ var OverlayEngine = class {
1051
1178
  this.backdrop.style.pointerEvents = "none";
1052
1179
  }
1053
1180
  }
1181
+ syncBackdropPointerEvents() {
1182
+ if (!this.backdrop) return;
1183
+ this.backdrop.style.pointerEvents = this.backdropOpacity > 0 ? "auto" : "none";
1184
+ }
1185
+ applyBackdropFilter(filter) {
1186
+ if (!this.backdrop) return;
1187
+ const style = this.backdrop.style;
1188
+ if (filter) {
1189
+ this.backdrop.style.backdropFilter = filter;
1190
+ style.webkitBackdropFilter = filter;
1191
+ } else {
1192
+ this.backdrop.style.backdropFilter = "";
1193
+ style.webkitBackdropFilter = "";
1194
+ }
1195
+ }
1054
1196
  setWillChange(on) {
1055
1197
  this.element.style.willChange = on ? "transform, opacity" : "";
1056
1198
  if (this.backdrop) {
@@ -1098,21 +1240,6 @@ var OverlayEngine = class {
1098
1240
  this.backdrop.addEventListener("click", handler);
1099
1241
  this.detachBackdrop = () => this.backdrop?.removeEventListener("click", handler);
1100
1242
  }
1101
- if (this.closeOnBackEnabled && typeof window !== "undefined" && !this.detachHardwareBack) {
1102
- try {
1103
- history.pushState({ __bsOverlay: this.id }, "");
1104
- this.backPushed = true;
1105
- } catch {
1106
- }
1107
- const onPop = () => {
1108
- if (this.isOpen_ && this.isTop) {
1109
- this.backPushed = false;
1110
- void this.close("back");
1111
- }
1112
- };
1113
- window.addEventListener("popstate", onPop);
1114
- this.detachHardwareBack = () => window.removeEventListener("popstate", onPop);
1115
- }
1116
1243
  if (this.closeOnOutsidePointerEnabled && !this.detachOutsidePointer) {
1117
1244
  const handler = (e) => {
1118
1245
  if (!this.isOpen_) return;
@@ -1125,14 +1252,20 @@ var OverlayEngine = class {
1125
1252
  document.addEventListener("pointerdown", handler, true);
1126
1253
  this.detachOutsidePointer = () => document.removeEventListener("pointerdown", handler, true);
1127
1254
  }
1255
+ if (this.closeOnBackEnabled && this.backMarker === null && typeof window !== "undefined") {
1256
+ this.backMarker = pushBackMarker({
1257
+ isOpen: () => this.isOpen_,
1258
+ isTop: () => this.isTop,
1259
+ close: () => this.close("back"),
1260
+ markerState: () => ({ __bsOverlay: this.id })
1261
+ });
1262
+ }
1128
1263
  }
1129
1264
  releaseInteractiveListeners() {
1130
1265
  this.detachEscape?.();
1131
1266
  this.detachEscape = null;
1132
1267
  this.detachBackdrop?.();
1133
1268
  this.detachBackdrop = null;
1134
- this.detachHardwareBack?.();
1135
- this.detachHardwareBack = null;
1136
1269
  this.detachSwipe?.();
1137
1270
  this.detachSwipe = null;
1138
1271
  this.detachOutsidePointer?.();
package/dist/preact.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { BottomSheet, BottomSheetFromConfig, BottomSheetFromConfigProps, BottomSheetHandle, BottomSheetProps, HeaderProp, Overlay, OverlayHandle, OverlayProps, SheetConfig, UseBottomSheetRefs, UseBottomSheetReturn, UseOverlayReturn, useBottomSheet, useOverlay } from './react.cjs';
2
- export { E as EngineState, b as SheetMode, d as SnapPoint, a as SnapPointDef } from './BottomSheetEngine-BcyruNP1.cjs';
2
+ export { E as EngineState, b as SheetMode, e as SnapPoint, a as SnapPointDef } from './BottomSheetEngine-DzsIwD28.cjs';
3
3
  export { OverlayEdge, OverlayOptions, OverlayState } from './overlay.cjs';
4
4
  import 'react';
5
+ import './teleport-7uYNiEAT.cjs';
5
6
  import './transform-jVfAikE9.cjs';
package/dist/preact.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { BottomSheet, BottomSheetFromConfig, BottomSheetFromConfigProps, BottomSheetHandle, BottomSheetProps, HeaderProp, Overlay, OverlayHandle, OverlayProps, SheetConfig, UseBottomSheetRefs, UseBottomSheetReturn, UseOverlayReturn, useBottomSheet, useOverlay } from './react.js';
2
- export { E as EngineState, b as SheetMode, d as SnapPoint, a as SnapPointDef } from './BottomSheetEngine-CBRcBwV-.js';
2
+ export { E as EngineState, b as SheetMode, e as SnapPoint, a as SnapPointDef } from './BottomSheetEngine-DRjCU73e.js';
3
3
  export { OverlayEdge, OverlayOptions, OverlayState } from './overlay.js';
4
4
  import 'react';
5
+ import './teleport-7uYNiEAT.js';
5
6
  import './transform-jVfAikE9.js';