@surdeddd/bottom-sheet 0.4.1 → 0.6.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 (41) hide show
  1. package/dist/{BottomSheetEngine-L05jGZvU.d.ts → BottomSheetEngine-BHjKFtnM.d.ts} +2 -0
  2. package/dist/{BottomSheetEngine-BJrH7qY3.d.cts → BottomSheetEngine-CqiCz64W.d.cts} +2 -0
  3. package/dist/element.cjs +111 -12
  4. package/dist/element.d.cts +1 -1
  5. package/dist/element.d.ts +1 -1
  6. package/dist/element.iife.global.js +2 -2
  7. package/dist/element.js +111 -12
  8. package/dist/index.cjs +91 -8
  9. package/dist/index.d.cts +2 -2
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.js +91 -8
  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/preact.d.cts +1 -1
  17. package/dist/preact.d.ts +1 -1
  18. package/dist/qwik.cjs +94 -10
  19. package/dist/qwik.d.cts +2 -2
  20. package/dist/qwik.d.ts +2 -2
  21. package/dist/qwik.js +94 -10
  22. package/dist/react.cjs +151 -10
  23. package/dist/react.d.cts +9 -2
  24. package/dist/react.d.ts +9 -2
  25. package/dist/react.js +151 -10
  26. package/dist/solid.cjs +122 -18
  27. package/dist/solid.d.cts +3 -0
  28. package/dist/solid.d.ts +3 -0
  29. package/dist/solid.js +124 -20
  30. package/dist/solid.source.jsx +100 -12
  31. package/dist/styles.css +17 -0
  32. package/dist/svelte-core.cjs +137 -9
  33. package/dist/svelte-core.js +137 -9
  34. package/dist/svelte-src/BottomSheet.svelte +5 -3
  35. package/dist/svelte.cjs +189 -46
  36. package/dist/svelte.d.cts +1 -0
  37. package/dist/svelte.d.ts +1 -0
  38. package/dist/svelte.js +189 -46
  39. package/dist/vue.cjs +176 -32
  40. package/dist/vue.js +176 -32
  41. package/package.json +1 -1
package/dist/react.js CHANGED
@@ -2903,11 +2903,54 @@ var BottomSheetEngine = class {
2903
2903
  this.updateAriaSlider();
2904
2904
  }
2905
2905
  }
2906
+ contentTargets() {
2907
+ const scroller = this.scrollContainer;
2908
+ if (!scroller) return [];
2909
+ const hasSlot = typeof HTMLSlotElement !== "undefined";
2910
+ const out = [];
2911
+ for (const child of Array.from(scroller.children)) {
2912
+ if (hasSlot && child instanceof HTMLSlotElement) {
2913
+ for (const el of child.assignedElements()) out.push(el);
2914
+ } else {
2915
+ out.push(child);
2916
+ }
2917
+ }
2918
+ return out;
2919
+ }
2920
+ measureContentExtent(vertical) {
2921
+ const content = this.scrollContainer;
2922
+ if (!content) return 0;
2923
+ const targets = this.contentTargets();
2924
+ if (targets.length === 0) {
2925
+ return vertical ? content.scrollHeight : content.scrollWidth;
2926
+ }
2927
+ let min = Infinity;
2928
+ let max = -Infinity;
2929
+ for (const el of targets) {
2930
+ const r = el.getBoundingClientRect();
2931
+ if (vertical) {
2932
+ if (r.top < min) min = r.top;
2933
+ if (r.bottom > max) max = r.bottom;
2934
+ } else {
2935
+ if (r.left < min) min = r.left;
2936
+ if (r.right > max) max = r.right;
2937
+ }
2938
+ }
2939
+ if (!isFinite(min) || !isFinite(max) || max <= min) {
2940
+ return vertical ? content.scrollHeight : content.scrollWidth;
2941
+ }
2942
+ let pad = 0;
2943
+ if (typeof getComputedStyle !== "undefined") {
2944
+ const cs = getComputedStyle(content);
2945
+ pad = vertical ? (parseFloat(cs.paddingTop) || 0) + (parseFloat(cs.paddingBottom) || 0) : (parseFloat(cs.paddingLeft) || 0) + (parseFloat(cs.paddingRight) || 0);
2946
+ }
2947
+ return max - min + pad;
2948
+ }
2906
2949
  measureFitSize() {
2907
2950
  const vertical = layoutAxis(this.mode) === "height";
2908
2951
  const handleSize = vertical ? this.handle.offsetHeight : this.handle.offsetWidth;
2909
2952
  const content = this.scrollContainer;
2910
- const natural = content ? handleSize + (vertical ? content.scrollHeight : content.scrollWidth) : handleSize;
2953
+ const natural = content ? handleSize + this.measureContentExtent(vertical) : handleSize;
2911
2954
  if (typeof window === "undefined") return natural;
2912
2955
  const viewport = vertical ? window.innerHeight : window.innerWidth;
2913
2956
  return viewport > 0 ? Math.min(natural, viewport) : natural;
@@ -2916,22 +2959,62 @@ var BottomSheetEngine = class {
2916
2959
  if (typeof ResizeObserver === "undefined") return;
2917
2960
  if (!this.snapPointsRaw.some((p) => p.size === "fit" || p.size === "content"))
2918
2961
  return;
2919
- const targets = [this.handle];
2920
- if (this.scrollContainer && this.scrollContainer !== this.handle) {
2921
- targets.push(this.scrollContainer);
2922
- }
2923
2962
  let raf = 0;
2924
- const ro = new ResizeObserver(() => {
2963
+ const schedule = () => {
2925
2964
  if (raf) return;
2926
2965
  raf = requestAnimationFrame(() => {
2927
2966
  raf = 0;
2928
2967
  if (this.destroyed || this.gesture?.isDragging) return;
2929
2968
  this.recompute();
2930
2969
  });
2931
- });
2932
- for (const t of targets) ro.observe(t);
2970
+ };
2971
+ const ro = new ResizeObserver(schedule);
2972
+ ro.observe(this.handle);
2973
+ const scroller = this.scrollContainer;
2974
+ const observed = /* @__PURE__ */ new Set();
2975
+ const slots = /* @__PURE__ */ new Set();
2976
+ const hasSlot = typeof HTMLSlotElement !== "undefined";
2977
+ const onSlotChange = () => resync();
2978
+ const trackSlots = () => {
2979
+ if (!scroller || !hasSlot) return;
2980
+ for (const child of Array.from(scroller.children)) {
2981
+ if (child instanceof HTMLSlotElement && !slots.has(child)) {
2982
+ child.addEventListener("slotchange", onSlotChange);
2983
+ slots.add(child);
2984
+ }
2985
+ }
2986
+ };
2987
+ const resync = () => {
2988
+ trackSlots();
2989
+ const targets = this.contentTargets();
2990
+ for (const el of observed) {
2991
+ if (!targets.includes(el)) {
2992
+ ro.unobserve(el);
2993
+ observed.delete(el);
2994
+ }
2995
+ }
2996
+ for (const el of targets) {
2997
+ if (!observed.has(el)) {
2998
+ ro.observe(el);
2999
+ observed.add(el);
3000
+ }
3001
+ }
3002
+ schedule();
3003
+ };
3004
+ let mo;
3005
+ if (scroller) {
3006
+ resync();
3007
+ if (typeof MutationObserver !== "undefined") {
3008
+ mo = new MutationObserver(resync);
3009
+ mo.observe(scroller, { childList: true });
3010
+ }
3011
+ }
2933
3012
  this.teardowns.add(() => {
2934
3013
  ro.disconnect();
3014
+ mo?.disconnect();
3015
+ for (const slot of slots) {
3016
+ slot.removeEventListener("slotchange", onSlotChange);
3017
+ }
2935
3018
  if (raf) cancelAnimationFrame(raf);
2936
3019
  });
2937
3020
  }
@@ -3352,6 +3435,38 @@ var BottomSheetEngine = class {
3352
3435
  }
3353
3436
  };
3354
3437
 
3438
+ // src/core/features/teleport.ts
3439
+ var resolveTeleportTarget = (target) => {
3440
+ if (!target) return null;
3441
+ if (typeof target !== "string") return target;
3442
+ if (typeof document === "undefined") return null;
3443
+ if (target === "body") return document.body;
3444
+ return document.querySelector(target);
3445
+ };
3446
+ var teleportElements = (els, target) => {
3447
+ const records = [];
3448
+ for (const el of els) {
3449
+ if (!el || el.parentNode === target) continue;
3450
+ records.push({ el, parent: el.parentNode, next: el.nextSibling });
3451
+ target.appendChild(el);
3452
+ }
3453
+ return () => {
3454
+ for (let i = records.length - 1; i >= 0; i--) {
3455
+ const { el, parent, next } = records[i];
3456
+ if (parent && parent.isConnected) {
3457
+ const before = next && next.parentNode === parent ? next : null;
3458
+ try {
3459
+ parent.insertBefore(el, before);
3460
+ } catch {
3461
+ el.parentNode?.removeChild(el);
3462
+ }
3463
+ } else {
3464
+ el.parentNode?.removeChild(el);
3465
+ }
3466
+ }
3467
+ };
3468
+ };
3469
+
3355
3470
  // src/react/useBottomSheet.ts
3356
3471
  var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
3357
3472
  var SSR_STATE = Object.freeze({
@@ -3385,6 +3500,17 @@ function useBottomSheet(opts) {
3385
3500
  scrim: screenRef.current ?? void 0
3386
3501
  });
3387
3502
  engineRef.current = engine;
3503
+ const target = resolveTeleportTarget(optsRef.current.teleportTo);
3504
+ const restoreTeleport = target ? teleportElements(
3505
+ [backdropRef.current, screenRef.current, sheetRef.current],
3506
+ target
3507
+ ) : null;
3508
+ if (optsRef.current.backdropColor !== void 0) {
3509
+ engine.setScrimColor(optsRef.current.backdropColor);
3510
+ }
3511
+ if (optsRef.current.backdropOpacity !== void 0) {
3512
+ engine.setBackdropRange([0, optsRef.current.backdropOpacity]);
3513
+ }
3388
3514
  cachedSnapshotRef.current = { ...engine.state };
3389
3515
  setMounted((n) => n + 1);
3390
3516
  const refresh = () => {
@@ -3416,6 +3542,7 @@ function useBottomSheet(opts) {
3416
3542
  ];
3417
3543
  return () => {
3418
3544
  offs.forEach((off) => off());
3545
+ restoreTeleport?.();
3419
3546
  engine.destroy();
3420
3547
  engineRef.current = null;
3421
3548
  cachedSnapshotRef.current = SSR_STATE;
@@ -3431,6 +3558,18 @@ function useBottomSheet(opts) {
3431
3558
  const ids = opts.allowed ? Array.from(opts.allowed) : opts.snapPoints.map((p) => p.id);
3432
3559
  engineRef.current.setAllowed(ids);
3433
3560
  }, [allowedKey, snapKey]);
3561
+ useEffect(() => {
3562
+ if (!engineRef.current) return;
3563
+ if (opts.backdropColor !== void 0) {
3564
+ engineRef.current.setScrimColor(opts.backdropColor);
3565
+ }
3566
+ }, [opts.backdropColor]);
3567
+ useEffect(() => {
3568
+ if (!engineRef.current) return;
3569
+ if (opts.backdropOpacity !== void 0) {
3570
+ engineRef.current.setBackdropRange([0, opts.backdropOpacity]);
3571
+ }
3572
+ }, [opts.backdropOpacity]);
3434
3573
  const subscribe = useCallback((fn) => {
3435
3574
  subscribersRef.current.add(fn);
3436
3575
  return () => subscribersRef.current.delete(fn);
@@ -3530,6 +3669,7 @@ var BottomSheet = forwardRef(
3530
3669
  className = "",
3531
3670
  style,
3532
3671
  header,
3672
+ footer,
3533
3673
  children,
3534
3674
  leftButton,
3535
3675
  rightButton,
@@ -3717,10 +3857,10 @@ var BottomSheet = forwardRef(
3717
3857
  className: "bs-handle",
3718
3858
  role: "slider",
3719
3859
  tabIndex: 0,
3720
- "aria-label": "Resize sheet",
3721
- children: typeof header === "function" ? header(state) : header
3860
+ "aria-label": "Resize sheet"
3722
3861
  }
3723
3862
  ),
3863
+ header != null && header !== false && /* @__PURE__ */ jsx("div", { className: "bs-header", children: typeof header === "function" ? header(state) : header }),
3724
3864
  /* @__PURE__ */ jsx(
3725
3865
  "div",
3726
3866
  {
@@ -3732,6 +3872,7 @@ var BottomSheet = forwardRef(
3732
3872
  children
3733
3873
  }
3734
3874
  ),
3875
+ footer != null && footer !== false && /* @__PURE__ */ jsx("div", { className: "bs-footer", children: typeof footer === "function" ? footer(state) : footer }),
3735
3876
  /* @__PURE__ */ jsx("span", { className: "bs-sr-only", role: "status", "aria-live": "polite", children: announce })
3736
3877
  ]
3737
3878
  }
package/dist/solid.cjs CHANGED
@@ -2898,11 +2898,54 @@ var BottomSheetEngine = class {
2898
2898
  this.updateAriaSlider();
2899
2899
  }
2900
2900
  }
2901
+ contentTargets() {
2902
+ const scroller = this.scrollContainer;
2903
+ if (!scroller) return [];
2904
+ const hasSlot = typeof HTMLSlotElement !== "undefined";
2905
+ const out = [];
2906
+ for (const child of Array.from(scroller.children)) {
2907
+ if (hasSlot && child instanceof HTMLSlotElement) {
2908
+ for (const el of child.assignedElements()) out.push(el);
2909
+ } else {
2910
+ out.push(child);
2911
+ }
2912
+ }
2913
+ return out;
2914
+ }
2915
+ measureContentExtent(vertical) {
2916
+ const content = this.scrollContainer;
2917
+ if (!content) return 0;
2918
+ const targets = this.contentTargets();
2919
+ if (targets.length === 0) {
2920
+ return vertical ? content.scrollHeight : content.scrollWidth;
2921
+ }
2922
+ let min = Infinity;
2923
+ let max = -Infinity;
2924
+ for (const el of targets) {
2925
+ const r = el.getBoundingClientRect();
2926
+ if (vertical) {
2927
+ if (r.top < min) min = r.top;
2928
+ if (r.bottom > max) max = r.bottom;
2929
+ } else {
2930
+ if (r.left < min) min = r.left;
2931
+ if (r.right > max) max = r.right;
2932
+ }
2933
+ }
2934
+ if (!isFinite(min) || !isFinite(max) || max <= min) {
2935
+ return vertical ? content.scrollHeight : content.scrollWidth;
2936
+ }
2937
+ let pad = 0;
2938
+ if (typeof getComputedStyle !== "undefined") {
2939
+ const cs = getComputedStyle(content);
2940
+ pad = vertical ? (parseFloat(cs.paddingTop) || 0) + (parseFloat(cs.paddingBottom) || 0) : (parseFloat(cs.paddingLeft) || 0) + (parseFloat(cs.paddingRight) || 0);
2941
+ }
2942
+ return max - min + pad;
2943
+ }
2901
2944
  measureFitSize() {
2902
2945
  const vertical = layoutAxis(this.mode) === "height";
2903
2946
  const handleSize = vertical ? this.handle.offsetHeight : this.handle.offsetWidth;
2904
2947
  const content = this.scrollContainer;
2905
- const natural = content ? handleSize + (vertical ? content.scrollHeight : content.scrollWidth) : handleSize;
2948
+ const natural = content ? handleSize + this.measureContentExtent(vertical) : handleSize;
2906
2949
  if (typeof window === "undefined") return natural;
2907
2950
  const viewport = vertical ? window.innerHeight : window.innerWidth;
2908
2951
  return viewport > 0 ? Math.min(natural, viewport) : natural;
@@ -2911,22 +2954,62 @@ var BottomSheetEngine = class {
2911
2954
  if (typeof ResizeObserver === "undefined") return;
2912
2955
  if (!this.snapPointsRaw.some((p) => p.size === "fit" || p.size === "content"))
2913
2956
  return;
2914
- const targets = [this.handle];
2915
- if (this.scrollContainer && this.scrollContainer !== this.handle) {
2916
- targets.push(this.scrollContainer);
2917
- }
2918
2957
  let raf = 0;
2919
- const ro = new ResizeObserver(() => {
2958
+ const schedule = () => {
2920
2959
  if (raf) return;
2921
2960
  raf = requestAnimationFrame(() => {
2922
2961
  raf = 0;
2923
2962
  if (this.destroyed || this.gesture?.isDragging) return;
2924
2963
  this.recompute();
2925
2964
  });
2926
- });
2927
- for (const t of targets) ro.observe(t);
2965
+ };
2966
+ const ro = new ResizeObserver(schedule);
2967
+ ro.observe(this.handle);
2968
+ const scroller = this.scrollContainer;
2969
+ const observed = /* @__PURE__ */ new Set();
2970
+ const slots = /* @__PURE__ */ new Set();
2971
+ const hasSlot = typeof HTMLSlotElement !== "undefined";
2972
+ const onSlotChange = () => resync();
2973
+ const trackSlots = () => {
2974
+ if (!scroller || !hasSlot) return;
2975
+ for (const child of Array.from(scroller.children)) {
2976
+ if (child instanceof HTMLSlotElement && !slots.has(child)) {
2977
+ child.addEventListener("slotchange", onSlotChange);
2978
+ slots.add(child);
2979
+ }
2980
+ }
2981
+ };
2982
+ const resync = () => {
2983
+ trackSlots();
2984
+ const targets = this.contentTargets();
2985
+ for (const el of observed) {
2986
+ if (!targets.includes(el)) {
2987
+ ro.unobserve(el);
2988
+ observed.delete(el);
2989
+ }
2990
+ }
2991
+ for (const el of targets) {
2992
+ if (!observed.has(el)) {
2993
+ ro.observe(el);
2994
+ observed.add(el);
2995
+ }
2996
+ }
2997
+ schedule();
2998
+ };
2999
+ let mo;
3000
+ if (scroller) {
3001
+ resync();
3002
+ if (typeof MutationObserver !== "undefined") {
3003
+ mo = new MutationObserver(resync);
3004
+ mo.observe(scroller, { childList: true });
3005
+ }
3006
+ }
2928
3007
  this.teardowns.add(() => {
2929
3008
  ro.disconnect();
3009
+ mo?.disconnect();
3010
+ for (const slot of slots) {
3011
+ slot.removeEventListener("slotchange", onSlotChange);
3012
+ }
2930
3013
  if (raf) cancelAnimationFrame(raf);
2931
3014
  });
2932
3015
  }
@@ -3348,8 +3431,10 @@ var BottomSheetEngine = class {
3348
3431
  };
3349
3432
 
3350
3433
  // src/solid/index.tsx
3351
- var _tmpl$ = /* @__PURE__ */ web.template(`<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>`);
3352
- var _tmpl$2 = /* @__PURE__ */ web.template(`<div class=bs-backdrop>`);
3434
+ var _tmpl$ = /* @__PURE__ */ web.template(`<div class=bs-header>`);
3435
+ var _tmpl$2 = /* @__PURE__ */ web.template(`<div class=bs-footer>`);
3436
+ var _tmpl$3 = /* @__PURE__ */ web.template(`<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>`);
3437
+ var _tmpl$4 = /* @__PURE__ */ web.template(`<div class=bs-backdrop>`);
3353
3438
  var BottomSheet = (props) => {
3354
3439
  let sheetEl;
3355
3440
  let handleEl;
@@ -3434,23 +3519,42 @@ var BottomSheet = (props) => {
3434
3519
  const mode = solidJs.createMemo(() => props.mode ?? "bottom");
3435
3520
  const ariaLabel = solidJs.createMemo(() => props.ariaLabel ?? "Bottom sheet");
3436
3521
  return (() => {
3437
- var _el$ = _tmpl$(), _el$2 = _el$.firstChild, _el$3 = _el$2.nextSibling, _el$4 = _el$3.firstChild, _el$5 = _el$4.nextSibling, _el$6 = _el$5.nextSibling;
3522
+ var _el$ = _tmpl$3(), _el$2 = _el$.firstChild, _el$3 = _el$2.nextSibling, _el$4 = _el$3.firstChild, _el$6 = _el$4.nextSibling, _el$8 = _el$6.nextSibling;
3438
3523
  web.insert(_el$, (() => {
3439
3524
  var _c$ = web.memo(() => !!showBackdrop());
3440
3525
  return () => _c$() ? (() => {
3441
- var _el$7 = _tmpl$2();
3442
- web.use((el) => backdropEl = el, _el$7);
3443
- return _el$7;
3526
+ var _el$9 = _tmpl$4();
3527
+ web.use((el) => backdropEl = el, _el$9);
3528
+ return _el$9;
3444
3529
  })() : null;
3445
3530
  })(), _el$2);
3446
3531
  web.use((el) => scrimEl = el, _el$2);
3447
3532
  web.insert(_el$2, () => props.screen);
3448
3533
  web.use((el) => sheetEl = el, _el$3);
3449
3534
  web.use((el) => handleEl = el, _el$4);
3450
- web.insert(_el$4, () => props.header);
3451
- web.use((el) => contentEl = el, _el$5);
3452
- web.insert(_el$5, () => props.children);
3453
- web.insert(_el$6, () => state().activeId);
3535
+ web.insert(_el$3, web.createComponent(solidJs.Show, {
3536
+ get when() {
3537
+ return props.header;
3538
+ },
3539
+ get children() {
3540
+ var _el$5 = _tmpl$();
3541
+ web.insert(_el$5, () => props.header);
3542
+ return _el$5;
3543
+ }
3544
+ }), _el$6);
3545
+ web.use((el) => contentEl = el, _el$6);
3546
+ web.insert(_el$6, () => props.children);
3547
+ web.insert(_el$3, web.createComponent(solidJs.Show, {
3548
+ get when() {
3549
+ return props.footer;
3550
+ },
3551
+ get children() {
3552
+ var _el$7 = _tmpl$2();
3553
+ web.insert(_el$7, () => props.footer);
3554
+ return _el$7;
3555
+ }
3556
+ }), _el$8);
3557
+ web.insert(_el$8, () => state().activeId);
3454
3558
  web.effect((_p$) => {
3455
3559
  var _v$ = mode(), _v$2 = state().activeId, _v$3 = props.focusTrap ? "true" : void 0, _v$4 = ariaLabel();
3456
3560
  _v$ !== _p$.e && web.setAttribute(_el$3, "data-mode", _p$.e = _v$);
package/dist/solid.d.cts CHANGED
@@ -273,6 +273,8 @@ declare class BottomSheetEngine {
273
273
  };
274
274
  setSnapPoints(points: EngineOptions["snapPoints"], allowed?: string[]): void;
275
275
  recompute(): void;
276
+ private contentTargets;
277
+ private measureContentExtent;
276
278
  private measureFitSize;
277
279
  private installFitObserver;
278
280
  destroy(): void;
@@ -326,6 +328,7 @@ type BottomSheetProps<TId extends string = string> = {
326
328
  }) => void;
327
329
  engineRef?: (engine: BottomSheetEngine | null) => void;
328
330
  header?: JSX.Element;
331
+ footer?: JSX.Element;
329
332
  screen?: JSX.Element;
330
333
  children?: JSX.Element;
331
334
  };
package/dist/solid.d.ts CHANGED
@@ -273,6 +273,8 @@ declare class BottomSheetEngine {
273
273
  };
274
274
  setSnapPoints(points: EngineOptions["snapPoints"], allowed?: string[]): void;
275
275
  recompute(): void;
276
+ private contentTargets;
277
+ private measureContentExtent;
276
278
  private measureFitSize;
277
279
  private installFitObserver;
278
280
  destroy(): void;
@@ -326,6 +328,7 @@ type BottomSheetProps<TId extends string = string> = {
326
328
  }) => void;
327
329
  engineRef?: (engine: BottomSheetEngine | null) => void;
328
330
  header?: JSX.Element;
331
+ footer?: JSX.Element;
329
332
  screen?: JSX.Element;
330
333
  children?: JSX.Element;
331
334
  };
package/dist/solid.js CHANGED
@@ -1,5 +1,5 @@
1
- import { insert, memo, use, effect, setAttribute, template } from 'solid-js/web';
2
- import { createSignal, onMount, onCleanup, createEffect, on, createMemo } from 'solid-js';
1
+ import { insert, memo, use, createComponent, effect, setAttribute, template } from 'solid-js/web';
2
+ import { createSignal, onMount, onCleanup, createEffect, on, createMemo, Show } from 'solid-js';
3
3
 
4
4
  var __defProp = Object.defineProperty;
5
5
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -2896,11 +2896,54 @@ var BottomSheetEngine = class {
2896
2896
  this.updateAriaSlider();
2897
2897
  }
2898
2898
  }
2899
+ contentTargets() {
2900
+ const scroller = this.scrollContainer;
2901
+ if (!scroller) return [];
2902
+ const hasSlot = typeof HTMLSlotElement !== "undefined";
2903
+ const out = [];
2904
+ for (const child of Array.from(scroller.children)) {
2905
+ if (hasSlot && child instanceof HTMLSlotElement) {
2906
+ for (const el of child.assignedElements()) out.push(el);
2907
+ } else {
2908
+ out.push(child);
2909
+ }
2910
+ }
2911
+ return out;
2912
+ }
2913
+ measureContentExtent(vertical) {
2914
+ const content = this.scrollContainer;
2915
+ if (!content) return 0;
2916
+ const targets = this.contentTargets();
2917
+ if (targets.length === 0) {
2918
+ return vertical ? content.scrollHeight : content.scrollWidth;
2919
+ }
2920
+ let min = Infinity;
2921
+ let max = -Infinity;
2922
+ for (const el of targets) {
2923
+ const r = el.getBoundingClientRect();
2924
+ if (vertical) {
2925
+ if (r.top < min) min = r.top;
2926
+ if (r.bottom > max) max = r.bottom;
2927
+ } else {
2928
+ if (r.left < min) min = r.left;
2929
+ if (r.right > max) max = r.right;
2930
+ }
2931
+ }
2932
+ if (!isFinite(min) || !isFinite(max) || max <= min) {
2933
+ return vertical ? content.scrollHeight : content.scrollWidth;
2934
+ }
2935
+ let pad = 0;
2936
+ if (typeof getComputedStyle !== "undefined") {
2937
+ const cs = getComputedStyle(content);
2938
+ pad = vertical ? (parseFloat(cs.paddingTop) || 0) + (parseFloat(cs.paddingBottom) || 0) : (parseFloat(cs.paddingLeft) || 0) + (parseFloat(cs.paddingRight) || 0);
2939
+ }
2940
+ return max - min + pad;
2941
+ }
2899
2942
  measureFitSize() {
2900
2943
  const vertical = layoutAxis(this.mode) === "height";
2901
2944
  const handleSize = vertical ? this.handle.offsetHeight : this.handle.offsetWidth;
2902
2945
  const content = this.scrollContainer;
2903
- const natural = content ? handleSize + (vertical ? content.scrollHeight : content.scrollWidth) : handleSize;
2946
+ const natural = content ? handleSize + this.measureContentExtent(vertical) : handleSize;
2904
2947
  if (typeof window === "undefined") return natural;
2905
2948
  const viewport = vertical ? window.innerHeight : window.innerWidth;
2906
2949
  return viewport > 0 ? Math.min(natural, viewport) : natural;
@@ -2909,22 +2952,62 @@ var BottomSheetEngine = class {
2909
2952
  if (typeof ResizeObserver === "undefined") return;
2910
2953
  if (!this.snapPointsRaw.some((p) => p.size === "fit" || p.size === "content"))
2911
2954
  return;
2912
- const targets = [this.handle];
2913
- if (this.scrollContainer && this.scrollContainer !== this.handle) {
2914
- targets.push(this.scrollContainer);
2915
- }
2916
2955
  let raf = 0;
2917
- const ro = new ResizeObserver(() => {
2956
+ const schedule = () => {
2918
2957
  if (raf) return;
2919
2958
  raf = requestAnimationFrame(() => {
2920
2959
  raf = 0;
2921
2960
  if (this.destroyed || this.gesture?.isDragging) return;
2922
2961
  this.recompute();
2923
2962
  });
2924
- });
2925
- for (const t of targets) ro.observe(t);
2963
+ };
2964
+ const ro = new ResizeObserver(schedule);
2965
+ ro.observe(this.handle);
2966
+ const scroller = this.scrollContainer;
2967
+ const observed = /* @__PURE__ */ new Set();
2968
+ const slots = /* @__PURE__ */ new Set();
2969
+ const hasSlot = typeof HTMLSlotElement !== "undefined";
2970
+ const onSlotChange = () => resync();
2971
+ const trackSlots = () => {
2972
+ if (!scroller || !hasSlot) return;
2973
+ for (const child of Array.from(scroller.children)) {
2974
+ if (child instanceof HTMLSlotElement && !slots.has(child)) {
2975
+ child.addEventListener("slotchange", onSlotChange);
2976
+ slots.add(child);
2977
+ }
2978
+ }
2979
+ };
2980
+ const resync = () => {
2981
+ trackSlots();
2982
+ const targets = this.contentTargets();
2983
+ for (const el of observed) {
2984
+ if (!targets.includes(el)) {
2985
+ ro.unobserve(el);
2986
+ observed.delete(el);
2987
+ }
2988
+ }
2989
+ for (const el of targets) {
2990
+ if (!observed.has(el)) {
2991
+ ro.observe(el);
2992
+ observed.add(el);
2993
+ }
2994
+ }
2995
+ schedule();
2996
+ };
2997
+ let mo;
2998
+ if (scroller) {
2999
+ resync();
3000
+ if (typeof MutationObserver !== "undefined") {
3001
+ mo = new MutationObserver(resync);
3002
+ mo.observe(scroller, { childList: true });
3003
+ }
3004
+ }
2926
3005
  this.teardowns.add(() => {
2927
3006
  ro.disconnect();
3007
+ mo?.disconnect();
3008
+ for (const slot of slots) {
3009
+ slot.removeEventListener("slotchange", onSlotChange);
3010
+ }
2928
3011
  if (raf) cancelAnimationFrame(raf);
2929
3012
  });
2930
3013
  }
@@ -3346,8 +3429,10 @@ var BottomSheetEngine = class {
3346
3429
  };
3347
3430
 
3348
3431
  // src/solid/index.tsx
3349
- var _tmpl$ = /* @__PURE__ */ template(`<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>`);
3350
- var _tmpl$2 = /* @__PURE__ */ template(`<div class=bs-backdrop>`);
3432
+ var _tmpl$ = /* @__PURE__ */ template(`<div class=bs-header>`);
3433
+ var _tmpl$2 = /* @__PURE__ */ template(`<div class=bs-footer>`);
3434
+ var _tmpl$3 = /* @__PURE__ */ template(`<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>`);
3435
+ var _tmpl$4 = /* @__PURE__ */ template(`<div class=bs-backdrop>`);
3351
3436
  var BottomSheet = (props) => {
3352
3437
  let sheetEl;
3353
3438
  let handleEl;
@@ -3432,23 +3517,42 @@ var BottomSheet = (props) => {
3432
3517
  const mode = createMemo(() => props.mode ?? "bottom");
3433
3518
  const ariaLabel = createMemo(() => props.ariaLabel ?? "Bottom sheet");
3434
3519
  return (() => {
3435
- var _el$ = _tmpl$(), _el$2 = _el$.firstChild, _el$3 = _el$2.nextSibling, _el$4 = _el$3.firstChild, _el$5 = _el$4.nextSibling, _el$6 = _el$5.nextSibling;
3520
+ var _el$ = _tmpl$3(), _el$2 = _el$.firstChild, _el$3 = _el$2.nextSibling, _el$4 = _el$3.firstChild, _el$6 = _el$4.nextSibling, _el$8 = _el$6.nextSibling;
3436
3521
  insert(_el$, (() => {
3437
3522
  var _c$ = memo(() => !!showBackdrop());
3438
3523
  return () => _c$() ? (() => {
3439
- var _el$7 = _tmpl$2();
3440
- use((el) => backdropEl = el, _el$7);
3441
- return _el$7;
3524
+ var _el$9 = _tmpl$4();
3525
+ use((el) => backdropEl = el, _el$9);
3526
+ return _el$9;
3442
3527
  })() : null;
3443
3528
  })(), _el$2);
3444
3529
  use((el) => scrimEl = el, _el$2);
3445
3530
  insert(_el$2, () => props.screen);
3446
3531
  use((el) => sheetEl = el, _el$3);
3447
3532
  use((el) => handleEl = el, _el$4);
3448
- insert(_el$4, () => props.header);
3449
- use((el) => contentEl = el, _el$5);
3450
- insert(_el$5, () => props.children);
3451
- insert(_el$6, () => state().activeId);
3533
+ insert(_el$3, createComponent(Show, {
3534
+ get when() {
3535
+ return props.header;
3536
+ },
3537
+ get children() {
3538
+ var _el$5 = _tmpl$();
3539
+ insert(_el$5, () => props.header);
3540
+ return _el$5;
3541
+ }
3542
+ }), _el$6);
3543
+ use((el) => contentEl = el, _el$6);
3544
+ insert(_el$6, () => props.children);
3545
+ insert(_el$3, createComponent(Show, {
3546
+ get when() {
3547
+ return props.footer;
3548
+ },
3549
+ get children() {
3550
+ var _el$7 = _tmpl$2();
3551
+ insert(_el$7, () => props.footer);
3552
+ return _el$7;
3553
+ }
3554
+ }), _el$8);
3555
+ insert(_el$8, () => state().activeId);
3452
3556
  effect((_p$) => {
3453
3557
  var _v$ = mode(), _v$2 = state().activeId, _v$3 = props.focusTrap ? "true" : void 0, _v$4 = ariaLabel();
3454
3558
  _v$ !== _p$.e && setAttribute(_el$3, "data-mode", _p$.e = _v$);