@surdeddd/bottom-sheet 0.14.0 → 0.20.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 (56) hide show
  1. package/README.md +13 -0
  2. package/dist/{BottomSheetCore-DJYwWOqt.d.ts → BottomSheetCore-Cgn8b_6A.d.ts} +11 -2
  3. package/dist/{BottomSheetCore-Cp7dWy91.d.cts → BottomSheetCore-VPJZcKcg.d.cts} +11 -2
  4. package/dist/{BottomSheetEngine-Lm7HIVHv.d.cts → BottomSheetEngine-B8C2CwF9.d.cts} +1 -1
  5. package/dist/{BottomSheetEngine-O5PbeKfe.d.ts → BottomSheetEngine-DwYR_ygJ.d.ts} +1 -1
  6. package/dist/core.cjs +100 -9
  7. package/dist/core.d.cts +2 -2
  8. package/dist/core.d.ts +2 -2
  9. package/dist/core.js +100 -9
  10. package/dist/debug.d.cts +1 -1
  11. package/dist/debug.d.ts +1 -1
  12. package/dist/element.cjs +107 -9
  13. package/dist/element.d.cts +2 -2
  14. package/dist/element.d.ts +2 -2
  15. package/dist/element.iife.global.js +2 -2
  16. package/dist/element.js +107 -9
  17. package/dist/features.d.cts +4 -4
  18. package/dist/features.d.ts +4 -4
  19. package/dist/{index-Bb5TRmyg.d.cts → index-CnfbOKx0.d.cts} +1 -1
  20. package/dist/{index-Cl9ebCP2.d.ts → index-DcMkhXAy.d.ts} +1 -1
  21. package/dist/index.cjs +100 -9
  22. package/dist/index.d.cts +8 -8
  23. package/dist/index.d.ts +8 -8
  24. package/dist/index.js +100 -9
  25. package/dist/integrations/formik.d.cts +1 -1
  26. package/dist/integrations/formik.d.ts +1 -1
  27. package/dist/integrations/react-hook-form.d.cts +1 -1
  28. package/dist/integrations/react-hook-form.d.ts +1 -1
  29. package/dist/preact.d.cts +2 -2
  30. package/dist/preact.d.ts +2 -2
  31. package/dist/qwik-lib/index.qwik.cjs +98 -9
  32. package/dist/qwik-lib/index.qwik.mjs +98 -9
  33. package/dist/qwik.cjs +100 -9
  34. package/dist/qwik.d.cts +2 -2
  35. package/dist/qwik.d.ts +2 -2
  36. package/dist/qwik.js +100 -9
  37. package/dist/react.cjs +100 -9
  38. package/dist/react.d.cts +3 -3
  39. package/dist/react.d.ts +3 -3
  40. package/dist/react.js +100 -9
  41. package/dist/solid.cjs +100 -9
  42. package/dist/solid.d.cts +10 -1
  43. package/dist/solid.d.ts +10 -1
  44. package/dist/solid.js +100 -9
  45. package/dist/solid.source.jsx +100 -9
  46. package/dist/svelte-core.cjs +100 -9
  47. package/dist/svelte-core.js +100 -9
  48. package/dist/svelte.cjs +100 -9
  49. package/dist/svelte.js +100 -9
  50. package/dist/vue.cjs +100 -9
  51. package/dist/vue.js +100 -9
  52. package/dist/webgl.cjs +104 -14
  53. package/dist/webgl.d.cts +1 -1
  54. package/dist/webgl.d.ts +1 -1
  55. package/dist/webgl.js +104 -14
  56. package/package.json +39 -39
package/dist/element.cjs CHANGED
@@ -367,6 +367,11 @@ var init_snap_resolver = __esm({
367
367
  this.raw = raw;
368
368
  this.recompute();
369
369
  }
370
+ setMode(mode) {
371
+ if (mode === this.mode) return;
372
+ this.mode = mode;
373
+ this.recompute();
374
+ }
370
375
  setAllowedIds(ids) {
371
376
  this.allowedIds = ids;
372
377
  this.rangeCache = null;
@@ -1009,6 +1014,11 @@ var init_scrim_controller = __esm({
1009
1014
  if (this.isDestroyed()) return;
1010
1015
  this.applyScrimStyles({ interactive });
1011
1016
  }
1017
+ setSheetMode(mode) {
1018
+ if (this.isDestroyed() || mode === this.mode) return;
1019
+ this.mode = mode;
1020
+ this.invalidateOpacityCache();
1021
+ }
1012
1022
  setScrimMode(mode, applySize) {
1013
1023
  if (this.isDestroyed()) return;
1014
1024
  if (mode === this.scrimMode) return;
@@ -1989,6 +1999,7 @@ var init_gestures = __esm({
1989
1999
  let activePointerId = null;
1990
2000
  let activePointerType = "touch";
1991
2001
  let startCoord = 0;
2002
+ let startCross = 0;
1992
2003
  let lastCoord = 0;
1993
2004
  let pendingStart = false;
1994
2005
  const VELOCITY_WINDOW_MS = (kind) => kind === "mouse" ? 160 : 120;
@@ -1997,6 +2008,7 @@ var init_gestures = __esm({
1997
2008
  const axis = isAxisVertical(mode) ? "Y" : "X";
1998
2009
  const sign = mode === "bottom" || mode === "right" ? -1 : 1;
1999
2010
  const coordOf = (e) => axis === "Y" ? e.clientY : e.clientX;
2011
+ const crossOf = (e) => axis === "Y" ? e.clientX : e.clientY;
2000
2012
  const capture = (pointerId) => {
2001
2013
  try {
2002
2014
  handle.setPointerCapture(pointerId);
@@ -2015,6 +2027,7 @@ var init_gestures = __esm({
2015
2027
  activePointerId = e.pointerId;
2016
2028
  activePointerType = e.pointerType || "touch";
2017
2029
  startCoord = coordOf(e);
2030
+ startCross = crossOf(e);
2018
2031
  lastCoord = startCoord;
2019
2032
  samples.reset();
2020
2033
  samples.push(e.timeStamp, startCoord);
@@ -2031,7 +2044,7 @@ var init_gestures = __esm({
2031
2044
  const rawDelta = coord - startCoord;
2032
2045
  const delta = rawDelta * sign;
2033
2046
  if (pendingStart) {
2034
- const verdict = options.deferStart(e, delta);
2047
+ const verdict = options.deferStart(e, delta, crossOf(e) - startCross);
2035
2048
  if (verdict === false) {
2036
2049
  releaseTracking();
2037
2050
  return;
@@ -2271,6 +2284,13 @@ var init_drag_zones = __esm({
2271
2284
  // src/core/primitives/content-gesture.ts
2272
2285
  function decideContentGesture(input) {
2273
2286
  const slop = input.slop ?? CONTENT_DRAG_SLOP;
2287
+ const cross = input.crossDelta ?? 0;
2288
+ const sharesScrollAxis = input.sharesScrollAxis ?? true;
2289
+ if (!sharesScrollAxis) {
2290
+ if (Math.abs(input.delta) < slop && Math.abs(cross) < slop) return "pending";
2291
+ if (Math.abs(input.delta) <= Math.abs(cross)) return "scroll";
2292
+ return "drag";
2293
+ }
2274
2294
  if (Math.abs(input.delta) < slop) return "pending";
2275
2295
  if (input.scrollTop > 0) return "scroll";
2276
2296
  if (input.delta > 0 && input.atMaxSnap) return "scroll";
@@ -2283,6 +2303,37 @@ var init_content_gesture = __esm({
2283
2303
  }
2284
2304
  });
2285
2305
 
2306
+ // src/core/primitives/logical-mode.ts
2307
+ var isLogicalMode, readDirection, resolveMode;
2308
+ var init_logical_mode = __esm({
2309
+ "src/core/primitives/logical-mode.ts"() {
2310
+ isLogicalMode = (mode) => mode === "start" || mode === "end";
2311
+ readDirection = (el) => {
2312
+ if (!el) return "ltr";
2313
+ if (typeof getComputedStyle === "function") {
2314
+ try {
2315
+ if (getComputedStyle(el).direction === "rtl") return "rtl";
2316
+ } catch {
2317
+ }
2318
+ }
2319
+ try {
2320
+ const marked = el.closest?.("[dir]");
2321
+ if (marked) {
2322
+ return marked.getAttribute("dir")?.toLowerCase() === "rtl" ? "rtl" : "ltr";
2323
+ }
2324
+ } catch {
2325
+ }
2326
+ return "ltr";
2327
+ };
2328
+ resolveMode = (mode, el) => {
2329
+ if (!isLogicalMode(mode)) return mode;
2330
+ const rtl = readDirection(el) === "rtl";
2331
+ if (mode === "start") return rtl ? "right" : "left";
2332
+ return rtl ? "left" : "right";
2333
+ };
2334
+ }
2335
+ });
2336
+
2286
2337
  // src/core/primitives/touch-scroll-guard.ts
2287
2338
  function installTouchScrollGuard(surface, isDragging) {
2288
2339
  const onTouchMove = (e) => {
@@ -2675,7 +2726,7 @@ function resolveEngineOptions(opts, extras) {
2675
2726
  }
2676
2727
  }
2677
2728
  return {
2678
- mode: opts.mode ?? "bottom",
2729
+ mode: resolveMode(opts.mode ?? "bottom", opts.element),
2679
2730
  flickVelocity: opts.flickVelocity ?? DEFAULT_FLICK_VELOCITY,
2680
2731
  dragThreshold: opts.dragThreshold ?? DEFAULT_DRAG_THRESHOLD,
2681
2732
  dragFrom: opts.dragFrom ?? (opts.handle ? "handle" : "sheet"),
@@ -2723,6 +2774,7 @@ function resolveEngineOptions(opts, extras) {
2723
2774
  var DEFAULT_FLICK_VELOCITY, DEFAULT_DRAG_THRESHOLD, readPersistedIdSafe;
2724
2775
  var init_engine_options = __esm({
2725
2776
  "src/core/primitives/engine-options.ts"() {
2777
+ init_logical_mode();
2726
2778
  DEFAULT_FLICK_VELOCITY = 0.65;
2727
2779
  DEFAULT_DRAG_THRESHOLD = 18;
2728
2780
  readPersistedIdSafe = (key) => {
@@ -2787,6 +2839,7 @@ var init_BottomSheetCore = __esm({
2787
2839
  init_gesture_controller();
2788
2840
  init_drag_zones();
2789
2841
  init_content_gesture();
2842
+ init_logical_mode();
2790
2843
  init_touch_scroll_guard();
2791
2844
  init_aria_slider_writer();
2792
2845
  init_hot_path_thresholds();
@@ -2823,6 +2876,7 @@ var init_BottomSheetCore = __esm({
2823
2876
  __publicField(this, "disableDragFlag");
2824
2877
  __publicField(this, "closeOnRouteChange");
2825
2878
  __publicField(this, "maxHeight");
2879
+ __publicField(this, "maxHeightDeps");
2826
2880
  __publicField(this, "snapPointsRaw");
2827
2881
  __publicField(this, "snaps");
2828
2882
  __publicField(this, "activeId");
@@ -2830,6 +2884,7 @@ var init_BottomSheetCore = __esm({
2830
2884
  __publicField(this, "gesture");
2831
2885
  __publicField(this, "contentGesture");
2832
2886
  __publicField(this, "detachSheetGesture", null);
2887
+ __publicField(this, "detachSliderKeyboard", null);
2833
2888
  __publicField(this, "rootEl", null);
2834
2889
  __publicField(this, "destroyed", false);
2835
2890
  __publicField(this, "restClosed", false);
@@ -2881,6 +2936,7 @@ var init_BottomSheetCore = __esm({
2881
2936
  this.screenComponent = opts.scrim ?? opts.screenComponent;
2882
2937
  this.scrimParent = this.screenComponent?.parentElement ?? null;
2883
2938
  this.mode = resolved.mode;
2939
+ this.element.dataset.mode = this.mode;
2884
2940
  this.transformTemplate = buildTransformTemplate(this.mode);
2885
2941
  this.aria = new AriaSliderWriter(this.handle, this.mode);
2886
2942
  this.flickVelocity = resolved.flickVelocity;
@@ -2947,7 +3003,7 @@ var init_BottomSheetCore = __esm({
2947
3003
  auditVhUsage(this.snapPointsRaw);
2948
3004
  this.auditDuplicateSnapIds(this.snapPointsRaw);
2949
3005
  this.rootEl = this.element.closest(".bs-root");
2950
- this.maxHeight = createMaxHeightController({
3006
+ this.maxHeightDeps = {
2951
3007
  element: this.element,
2952
3008
  mode: this.mode,
2953
3009
  getMaxAxisSize: () => this.snaps.getMaxAxisSize(),
@@ -2955,7 +3011,8 @@ var init_BottomSheetCore = __esm({
2955
3011
  this.snaps.setMaxAxisSize(size);
2956
3012
  },
2957
3013
  recompute: () => this.recompute()
2958
- });
3014
+ };
3015
+ this.maxHeight = createMaxHeightController(this.maxHeightDeps);
2959
3016
  this.fitDeps = {
2960
3017
  element: this.element,
2961
3018
  scrollContainer: this.scrollContainer,
@@ -3289,6 +3346,37 @@ var init_BottomSheetCore = __esm({
3289
3346
  getDragFrom() {
3290
3347
  return this.dragFromMode;
3291
3348
  }
3349
+ setMode(mode) {
3350
+ if (this.destroyed) return;
3351
+ const next = resolveMode(mode, this.element);
3352
+ if (next === this.mode) return;
3353
+ const wasVertical = this.mode === "bottom" || this.mode === "top";
3354
+ const nowVertical = next === "bottom" || next === "top";
3355
+ this.gesture?.forceClearDragState();
3356
+ this.detachSheetGesture?.();
3357
+ this.animation.cancel();
3358
+ this.element.style.removeProperty(layoutAxis(this.mode));
3359
+ this.mode = next;
3360
+ this.element.dataset.mode = next;
3361
+ this.transformTemplate = buildTransformTemplate(next);
3362
+ this.maxHeightDeps.mode = next;
3363
+ this.fitDeps.mode = next;
3364
+ this.snaps.setMode(next);
3365
+ this.scrim.setSheetMode(next);
3366
+ if (wasVertical !== nowVertical) {
3367
+ this.aria = new AriaSliderWriter(this.handle, next);
3368
+ }
3369
+ this.detachSliderKeyboard?.();
3370
+ this.mountSliderKeyboard();
3371
+ this.mountSheetGesture();
3372
+ this.recompute();
3373
+ const active = this.snaps.findById(this.activeId);
3374
+ if (active) this.applySize(active.size);
3375
+ this.updateAriaSlider();
3376
+ }
3377
+ getMode() {
3378
+ return this.mode;
3379
+ }
3292
3380
  isTop() {
3293
3381
  return this.isTopSheet;
3294
3382
  }
@@ -3637,7 +3725,7 @@ var init_BottomSheetCore = __esm({
3637
3725
  const point = this.snapPointsRaw.find((p) => p.id === this.activeId);
3638
3726
  return point?.dragFromContent ?? this.dragFromContentDefault;
3639
3727
  }
3640
- decideContentDrag(surface, e, delta) {
3728
+ decideContentDrag(surface, e, delta, crossDelta) {
3641
3729
  if (this.destroyed) return false;
3642
3730
  if (e.pointerType === "mouse") return false;
3643
3731
  if (this.gesture?.isDragging) return false;
@@ -3645,6 +3733,8 @@ var init_BottomSheetCore = __esm({
3645
3733
  if (!isDragAllowedFrom(e.target, "sheet")) return false;
3646
3734
  const decision = decideContentGesture({
3647
3735
  delta,
3736
+ crossDelta,
3737
+ sharesScrollAxis: this.mode === "bottom" || this.mode === "top",
3648
3738
  scrollTop: surface.scrollTop,
3649
3739
  atMaxSnap: this.size >= this.getAllowedRange().max - 0.5
3650
3740
  });
@@ -3657,7 +3747,7 @@ var init_BottomSheetCore = __esm({
3657
3747
  const controller = new GestureController(
3658
3748
  this.buildGestureDeps(surface, {
3659
3749
  manageTouchAction: false,
3660
- deferStart: (e, delta) => this.decideContentDrag(surface, e, delta)
3750
+ deferStart: (e, delta, crossDelta) => this.decideContentDrag(surface, e, delta, crossDelta)
3661
3751
  })
3662
3752
  );
3663
3753
  this.contentGesture = controller;
@@ -3783,7 +3873,11 @@ var init_BottomSheetCore = __esm({
3783
3873
  );
3784
3874
  }
3785
3875
  }
3786
- this.teardowns.add(installSliderKeyboard({
3876
+ this.mountSliderKeyboard();
3877
+ this.scrim.attach();
3878
+ }
3879
+ mountSliderKeyboard() {
3880
+ const detach = installSliderKeyboard({
3787
3881
  handle: this.handle,
3788
3882
  mode: this.mode,
3789
3883
  isDestroyed: () => this.destroyed,
@@ -3792,8 +3886,12 @@ var init_BottomSheetCore = __esm({
3792
3886
  snapTo: (id) => {
3793
3887
  void this.snapTo(id);
3794
3888
  }
3795
- }));
3796
- this.scrim.attach();
3889
+ });
3890
+ this.detachSliderKeyboard = detach;
3891
+ this.teardowns.add(() => {
3892
+ this.detachSliderKeyboard?.();
3893
+ this.detachSliderKeyboard = null;
3894
+ });
3797
3895
  }
3798
3896
  settleAfterDrag(delta, velocity, kind = "touch") {
3799
3897
  const signal = this.newCycle();
@@ -1,5 +1,5 @@
1
- import { B as BottomSheetEngine } from './BottomSheetEngine-Lm7HIVHv.cjs';
2
- import { C as CloseReason, A as AnchorOptions, S as ScrimStagesOptions, E as EngineState } from './BottomSheetCore-Cp7dWy91.cjs';
1
+ import { B as BottomSheetEngine } from './BottomSheetEngine-B8C2CwF9.cjs';
2
+ import { C as CloseReason, A as AnchorOptions, e as ScrimStagesOptions, E as EngineState } from './BottomSheetCore-VPJZcKcg.cjs';
3
3
  import './transform-jVfAikE9.cjs';
4
4
 
5
5
  declare const BaseHTMLElement: typeof HTMLElement;
package/dist/element.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as BottomSheetEngine } from './BottomSheetEngine-O5PbeKfe.js';
2
- import { C as CloseReason, A as AnchorOptions, S as ScrimStagesOptions, E as EngineState } from './BottomSheetCore-DJYwWOqt.js';
1
+ import { B as BottomSheetEngine } from './BottomSheetEngine-DwYR_ygJ.js';
2
+ import { C as CloseReason, A as AnchorOptions, e as ScrimStagesOptions, E as EngineState } from './BottomSheetCore-Cgn8b_6A.js';
3
3
  import './transform-jVfAikE9.js';
4
4
 
5
5
  declare const BaseHTMLElement: typeof HTMLElement;