@surdeddd/bottom-sheet 0.21.1 → 0.22.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 (62) hide show
  1. package/README.md +32 -0
  2. package/dist/{BottomSheetCore-CK_mq14p.d.ts → BottomSheetCore-9i-Uh6T3.d.ts} +4 -1
  3. package/dist/{BottomSheetCore-BHv6LPmS.d.cts → BottomSheetCore-CQStdVy2.d.cts} +4 -1
  4. package/dist/{BottomSheetEngine-mmFzIK1Z.d.cts → BottomSheetEngine-CsQWHLNb.d.cts} +1 -1
  5. package/dist/{BottomSheetEngine-wLn6Q2kA.d.ts → BottomSheetEngine-Dn6h-7gF.d.ts} +1 -1
  6. package/dist/core.cjs +25 -7
  7. package/dist/core.d.cts +2 -2
  8. package/dist/core.d.ts +2 -2
  9. package/dist/core.js +25 -7
  10. package/dist/debug.d.cts +1 -1
  11. package/dist/debug.d.ts +1 -1
  12. package/dist/default-features-C3cilcW9.d.ts +11 -0
  13. package/dist/default-features-DkG9aho0.d.cts +11 -0
  14. package/dist/element.cjs +106 -15
  15. package/dist/element.d.cts +2 -2
  16. package/dist/element.d.ts +2 -2
  17. package/dist/element.iife.global.js +2 -2
  18. package/dist/element.js +106 -15
  19. package/dist/features.cjs +65 -1
  20. package/dist/features.d.cts +5 -10
  21. package/dist/features.d.ts +5 -10
  22. package/dist/features.js +65 -2
  23. package/dist/{index-juAyT76E.d.cts → index-CVGC5B5D.d.cts} +1 -1
  24. package/dist/{index-CWKv1Xy4.d.ts → index-CnsJQZp2.d.ts} +1 -1
  25. package/dist/index.cjs +89 -8
  26. package/dist/index.d.cts +5 -5
  27. package/dist/index.d.ts +5 -5
  28. package/dist/index.js +89 -8
  29. package/dist/integrations/formik.d.cts +1 -1
  30. package/dist/integrations/formik.d.ts +1 -1
  31. package/dist/integrations/react-hook-form.d.cts +1 -1
  32. package/dist/integrations/react-hook-form.d.ts +1 -1
  33. package/dist/preact.d.cts +2 -2
  34. package/dist/preact.d.ts +2 -2
  35. package/dist/qwik-lib/index.qwik.cjs +84 -6
  36. package/dist/qwik-lib/index.qwik.mjs +84 -6
  37. package/dist/qwik.cjs +90 -8
  38. package/dist/qwik.d.cts +3 -2
  39. package/dist/qwik.d.ts +3 -2
  40. package/dist/qwik.js +90 -8
  41. package/dist/react.cjs +89 -8
  42. package/dist/react.d.cts +3 -3
  43. package/dist/react.d.ts +3 -3
  44. package/dist/react.js +89 -8
  45. package/dist/solid.cjs +90 -8
  46. package/dist/solid.d.cts +4 -0
  47. package/dist/solid.d.ts +4 -0
  48. package/dist/solid.js +90 -8
  49. package/dist/solid.source.jsx +90 -8
  50. package/dist/styles.css +11 -0
  51. package/dist/svelte-core.cjs +89 -8
  52. package/dist/svelte-core.js +89 -8
  53. package/dist/svelte-src/BottomSheet.svelte +3 -0
  54. package/dist/svelte.cjs +90 -8
  55. package/dist/svelte.d.cts +1 -0
  56. package/dist/svelte.d.ts +1 -0
  57. package/dist/svelte.js +90 -8
  58. package/dist/vue.cjs +93 -8
  59. package/dist/vue.js +93 -8
  60. package/dist/webgl.d.cts +1 -1
  61. package/dist/webgl.d.ts +1 -1
  62. package/package.json +9 -9
package/dist/vue.js CHANGED
@@ -375,14 +375,26 @@ function notifyLinkedSheets(sheets, self) {
375
375
  }
376
376
  }
377
377
 
378
+ // src/core/primitives/hot-path-thresholds.ts
379
+ var SIZE_WRITE_EPSILON = 0.5;
380
+ var OPACITY_WRITE_EPSILON = 5e-3;
381
+ var POINTER_EVENTS_OPACITY_THRESHOLD = 0.05;
382
+ var RANGE_DIVISION_EPSILON = 1e-4;
383
+
378
384
  // src/core/features/resize-observer.ts
379
385
  function installResizeObserver(deps) {
380
386
  if (typeof window === "undefined") {
381
387
  return () => {
382
388
  };
383
389
  }
390
+ const seatFor = () => {
391
+ const snap = deps.resolveActiveSnap();
392
+ const max = deps.getMaxAxisSize();
393
+ return { target: snap ? Math.min(snap.size, max) : null, max };
394
+ };
384
395
  const onResize = () => {
385
396
  if (deps.isDestroyed()) return;
397
+ const before = seatFor();
386
398
  deps.recomputeSnaps();
387
399
  const mode = deps.getMode();
388
400
  const isVerticalAxis = mode === "bottom" || mode === "top";
@@ -391,6 +403,10 @@ function installResizeObserver(deps) {
391
403
  if (viewportSize2 > 0 && viewportSize2 < max) {
392
404
  deps.setMaxAxisSize(viewportSize2);
393
405
  }
406
+ const after = seatFor();
407
+ if (before.target !== null && after.target !== null && Math.abs(after.target - before.target) < SIZE_WRITE_EPSILON && Math.abs(after.max - before.max) < SIZE_WRITE_EPSILON) {
408
+ return;
409
+ }
394
410
  const wasAnimating = deps.isAnimating?.() ?? false;
395
411
  deps.cancelInFlight();
396
412
  deps.newCycle();
@@ -659,12 +675,6 @@ var SCRIM_PRESETS = Object.freeze({
659
675
  }
660
676
  });
661
677
 
662
- // src/core/primitives/hot-path-thresholds.ts
663
- var SIZE_WRITE_EPSILON = 0.5;
664
- var OPACITY_WRITE_EPSILON = 5e-3;
665
- var POINTER_EVENTS_OPACITY_THRESHOLD = 0.05;
666
- var RANGE_DIVISION_EPSILON = 1e-4;
667
-
668
678
  // src/core/primitives/opacity-dedup.ts
669
679
  var WriteSentinel = class {
670
680
  constructor() {
@@ -2594,6 +2604,7 @@ var BottomSheetCore = class {
2594
2604
  __publicField(this, "lifecycle");
2595
2605
  __publicField(this, "closeOnBack");
2596
2606
  __publicField(this, "routedTo");
2607
+ __publicField(this, "fitContentToSnap");
2597
2608
  __publicField(this, "persistent");
2598
2609
  __publicField(this, "disableCloseFlag");
2599
2610
  __publicField(this, "disableDragFlag");
@@ -2707,6 +2718,7 @@ var BottomSheetCore = class {
2707
2718
  );
2708
2719
  this.closeOnBack = resolved.closeOnBack;
2709
2720
  this.routedTo = opts.routedTo;
2721
+ this.fitContentToSnap = opts.fitContentToSnap === true;
2710
2722
  this.persistent = resolved.persistent;
2711
2723
  this.disableCloseFlag = resolved.disableClose;
2712
2724
  this.disableDragFlag = resolved.disableDrag;
@@ -2808,7 +2820,8 @@ var BottomSheetCore = class {
2808
2820
  closeOnBack: this.closeOnBack,
2809
2821
  closeOnRouteChange: this.closeOnRouteChange,
2810
2822
  persistKey: this.persistKey,
2811
- autoCollapseAfter
2823
+ autoCollapseAfter,
2824
+ fitContentToSnap: this.fitContentToSnap
2812
2825
  },
2813
2826
  isDestroyed: () => this.destroyed,
2814
2827
  isDragging: () => this.isDraggingAny(),
@@ -2860,6 +2873,11 @@ var BottomSheetCore = class {
2860
2873
  "[BottomSheet] closeOnBack/routedTo/closeOnRouteChange need routeFeature() \u2014 option ignored"
2861
2874
  );
2862
2875
  }
2876
+ if (this.fitContentToSnap && !names.has("content-fit")) {
2877
+ devWarn(
2878
+ "[BottomSheet] fitContentToSnap needs contentFitFeature() \u2014 option ignored"
2879
+ );
2880
+ }
2863
2881
  if (this.persistKey && !names.has("persist")) {
2864
2882
  devWarn(
2865
2883
  "[BottomSheet] persistKey needs persistFeature() \u2014 snaps will not be saved"
@@ -4217,6 +4235,68 @@ function visualViewportFeature() {
4217
4235
  };
4218
4236
  }
4219
4237
 
4238
+ // src/core/features/content-fit.ts
4239
+ var INSET_VAR = "--bs-content-inset";
4240
+ var FIT_ATTR = "data-bs-fit-content";
4241
+ function contentFitFeature() {
4242
+ return {
4243
+ name: "content-fit",
4244
+ install: (ctx) => {
4245
+ const scroller = ctx.scrollContainer;
4246
+ if (!ctx.options.fitContentToSnap || !scroller || typeof window === "undefined") {
4247
+ return;
4248
+ }
4249
+ const sheet = ctx.element;
4250
+ let inset = 0;
4251
+ let unpaddedMax = -1;
4252
+ let top = 0;
4253
+ const hiddenAt = (size) => sheet.dataset.mode === "bottom" ? Math.max(0, ctx.getMaxAxisSize() - size) : 0;
4254
+ const follow = (size) => {
4255
+ if (unpaddedMax < 0) {
4256
+ unpaddedMax = scroller.scrollHeight - scroller.clientHeight - inset;
4257
+ top = scroller.scrollTop;
4258
+ }
4259
+ const limit = Math.max(0, unpaddedMax + hiddenAt(size));
4260
+ if (top > limit) {
4261
+ if (scroller.scrollTop > limit) scroller.scrollTop = limit;
4262
+ top = limit;
4263
+ }
4264
+ };
4265
+ const settle = () => {
4266
+ if (ctx.isDestroyed()) return;
4267
+ const size = ctx.getSize();
4268
+ unpaddedMax = -1;
4269
+ follow(size);
4270
+ inset = hiddenAt(size);
4271
+ sheet.style.setProperty(INSET_VAR, `${inset}px`);
4272
+ unpaddedMax = -1;
4273
+ };
4274
+ const moving = () => ctx.isAnimating() || ctx.isDragging();
4275
+ const whenIdle = () => {
4276
+ if (!moving()) settle();
4277
+ };
4278
+ sheet.setAttribute(FIT_ATTR, "");
4279
+ settle();
4280
+ const offProgress = ctx.on(
4281
+ "progress",
4282
+ (p) => moving() ? follow(p.size) : settle()
4283
+ );
4284
+ const offSnap = ctx.on("snap", settle);
4285
+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(whenIdle);
4286
+ observer?.observe(document.documentElement);
4287
+ window.addEventListener("orientationchange", whenIdle);
4288
+ return () => {
4289
+ offProgress();
4290
+ offSnap();
4291
+ observer?.disconnect();
4292
+ window.removeEventListener("orientationchange", whenIdle);
4293
+ sheet.removeAttribute(FIT_ATTR);
4294
+ sheet.style.removeProperty(INSET_VAR);
4295
+ };
4296
+ }
4297
+ };
4298
+ }
4299
+
4220
4300
  // src/core/default-features.ts
4221
4301
  function defaultEngineFeatures() {
4222
4302
  return [
@@ -4224,7 +4304,8 @@ function defaultEngineFeatures() {
4224
4304
  visualViewportFeature(),
4225
4305
  persistFeature(),
4226
4306
  autoCollapseFeature(),
4227
- routeFeature()
4307
+ routeFeature(),
4308
+ contentFitFeature()
4228
4309
  ];
4229
4310
  }
4230
4311
 
@@ -4441,6 +4522,10 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
4441
4522
  type: Boolean,
4442
4523
  required: false
4443
4524
  },
4525
+ fitContentToSnap: {
4526
+ type: Boolean,
4527
+ required: false
4528
+ },
4444
4529
  rubberBand: {
4445
4530
  type: Boolean,
4446
4531
  required: false
package/dist/webgl.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { f as EngineFeature } from './BottomSheetCore-BHv6LPmS.cjs';
1
+ import { E as EngineFeature } from './BottomSheetCore-CQStdVy2.cjs';
2
2
  import './transform-jVfAikE9.cjs';
3
3
 
4
4
  type WebGLRendererOptions = {
package/dist/webgl.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { f as EngineFeature } from './BottomSheetCore-CK_mq14p.js';
1
+ import { E as EngineFeature } from './BottomSheetCore-9i-Uh6T3.js';
2
2
  import './transform-jVfAikE9.js';
3
3
 
4
4
  type WebGLRendererOptions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@surdeddd/bottom-sheet",
3
- "version": "0.21.1",
3
+ "version": "0.22.0",
4
4
  "description": "Universal, headless bottom sheet — framework-agnostic core with React, Vue 3, Svelte, Solid, Qwik, Preact, Lit and Custom Element adapters. Pointer Events, snap points, momentum, a11y, SSR-safe.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -240,37 +240,37 @@
240
240
  {
241
241
  "name": "core (engine + types)",
242
242
  "path": "dist/index.js",
243
- "limit": "21.74 KB",
243
+ "limit": "22.1 KB",
244
244
  "gzip": true
245
245
  },
246
246
  {
247
247
  "name": "react adapter",
248
248
  "path": "dist/react.js",
249
- "limit": "29.16 KB",
249
+ "limit": "29.57 KB",
250
250
  "gzip": true
251
251
  },
252
252
  {
253
253
  "name": "vue adapter",
254
254
  "path": "dist/vue.js",
255
- "limit": "24.98 KB",
255
+ "limit": "25.32 KB",
256
256
  "gzip": true
257
257
  },
258
258
  {
259
259
  "name": "svelte adapter",
260
260
  "path": "dist/svelte.js",
261
- "limit": "24.59 KB",
261
+ "limit": "24.96 KB",
262
262
  "gzip": true
263
263
  },
264
264
  {
265
265
  "name": "solid adapter",
266
266
  "path": "dist/solid.js",
267
- "limit": "23.23 KB",
267
+ "limit": "23.61 KB",
268
268
  "gzip": true
269
269
  },
270
270
  {
271
271
  "name": "qwik adapter",
272
272
  "path": "dist/qwik.js",
273
- "limit": "23.25 KB",
273
+ "limit": "23.66 KB",
274
274
  "gzip": true
275
275
  },
276
276
  {
@@ -285,13 +285,13 @@
285
285
  {
286
286
  "name": "web component (self-contained)",
287
287
  "path": "dist/element.js",
288
- "limit": "28.35 KB",
288
+ "limit": "28.8 KB",
289
289
  "gzip": true
290
290
  },
291
291
  {
292
292
  "name": "web component (IIFE / CDN)",
293
293
  "path": "dist/element.iife.global.js",
294
- "limit": "27.9 KB",
294
+ "limit": "28.38 KB",
295
295
  "gzip": true
296
296
  },
297
297
  {