@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.
- package/dist/{BottomSheetEngine-L05jGZvU.d.ts → BottomSheetEngine-BHjKFtnM.d.ts} +2 -0
- package/dist/{BottomSheetEngine-BJrH7qY3.d.cts → BottomSheetEngine-CqiCz64W.d.cts} +2 -0
- package/dist/element.cjs +111 -12
- package/dist/element.d.cts +1 -1
- package/dist/element.d.ts +1 -1
- package/dist/element.iife.global.js +2 -2
- package/dist/element.js +111 -12
- package/dist/index.cjs +91 -8
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +91 -8
- package/dist/integrations/formik.d.cts +1 -1
- package/dist/integrations/formik.d.ts +1 -1
- package/dist/integrations/react-hook-form.d.cts +1 -1
- package/dist/integrations/react-hook-form.d.ts +1 -1
- package/dist/preact.d.cts +1 -1
- package/dist/preact.d.ts +1 -1
- package/dist/qwik.cjs +94 -10
- package/dist/qwik.d.cts +2 -2
- package/dist/qwik.d.ts +2 -2
- package/dist/qwik.js +94 -10
- package/dist/react.cjs +151 -10
- package/dist/react.d.cts +9 -2
- package/dist/react.d.ts +9 -2
- package/dist/react.js +151 -10
- package/dist/solid.cjs +122 -18
- package/dist/solid.d.cts +3 -0
- package/dist/solid.d.ts +3 -0
- package/dist/solid.js +124 -20
- package/dist/solid.source.jsx +100 -12
- package/dist/styles.css +17 -0
- package/dist/svelte-core.cjs +137 -9
- package/dist/svelte-core.js +137 -9
- package/dist/svelte-src/BottomSheet.svelte +5 -3
- package/dist/svelte.cjs +189 -46
- package/dist/svelte.d.cts +1 -0
- package/dist/svelte.d.ts +1 -0
- package/dist/svelte.js +189 -46
- package/dist/vue.cjs +176 -32
- package/dist/vue.js +176 -32
- package/package.json +1 -1
package/dist/svelte.cjs
CHANGED
|
@@ -2919,11 +2919,54 @@ var BottomSheetEngine = class {
|
|
|
2919
2919
|
this.updateAriaSlider();
|
|
2920
2920
|
}
|
|
2921
2921
|
}
|
|
2922
|
+
contentTargets() {
|
|
2923
|
+
const scroller = this.scrollContainer;
|
|
2924
|
+
if (!scroller) return [];
|
|
2925
|
+
const hasSlot = typeof HTMLSlotElement !== "undefined";
|
|
2926
|
+
const out = [];
|
|
2927
|
+
for (const child2 of Array.from(scroller.children)) {
|
|
2928
|
+
if (hasSlot && child2 instanceof HTMLSlotElement) {
|
|
2929
|
+
for (const el of child2.assignedElements()) out.push(el);
|
|
2930
|
+
} else {
|
|
2931
|
+
out.push(child2);
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
return out;
|
|
2935
|
+
}
|
|
2936
|
+
measureContentExtent(vertical) {
|
|
2937
|
+
const content = this.scrollContainer;
|
|
2938
|
+
if (!content) return 0;
|
|
2939
|
+
const targets = this.contentTargets();
|
|
2940
|
+
if (targets.length === 0) {
|
|
2941
|
+
return vertical ? content.scrollHeight : content.scrollWidth;
|
|
2942
|
+
}
|
|
2943
|
+
let min = Infinity;
|
|
2944
|
+
let max = -Infinity;
|
|
2945
|
+
for (const el of targets) {
|
|
2946
|
+
const r = el.getBoundingClientRect();
|
|
2947
|
+
if (vertical) {
|
|
2948
|
+
if (r.top < min) min = r.top;
|
|
2949
|
+
if (r.bottom > max) max = r.bottom;
|
|
2950
|
+
} else {
|
|
2951
|
+
if (r.left < min) min = r.left;
|
|
2952
|
+
if (r.right > max) max = r.right;
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2955
|
+
if (!isFinite(min) || !isFinite(max) || max <= min) {
|
|
2956
|
+
return vertical ? content.scrollHeight : content.scrollWidth;
|
|
2957
|
+
}
|
|
2958
|
+
let pad = 0;
|
|
2959
|
+
if (typeof getComputedStyle !== "undefined") {
|
|
2960
|
+
const cs = getComputedStyle(content);
|
|
2961
|
+
pad = vertical ? (parseFloat(cs.paddingTop) || 0) + (parseFloat(cs.paddingBottom) || 0) : (parseFloat(cs.paddingLeft) || 0) + (parseFloat(cs.paddingRight) || 0);
|
|
2962
|
+
}
|
|
2963
|
+
return max - min + pad;
|
|
2964
|
+
}
|
|
2922
2965
|
measureFitSize() {
|
|
2923
2966
|
const vertical = layoutAxis(this.mode) === "height";
|
|
2924
2967
|
const handleSize = vertical ? this.handle.offsetHeight : this.handle.offsetWidth;
|
|
2925
2968
|
const content = this.scrollContainer;
|
|
2926
|
-
const natural = content ? handleSize + (vertical
|
|
2969
|
+
const natural = content ? handleSize + this.measureContentExtent(vertical) : handleSize;
|
|
2927
2970
|
if (typeof window === "undefined") return natural;
|
|
2928
2971
|
const viewport = vertical ? window.innerHeight : window.innerWidth;
|
|
2929
2972
|
return viewport > 0 ? Math.min(natural, viewport) : natural;
|
|
@@ -2932,22 +2975,62 @@ var BottomSheetEngine = class {
|
|
|
2932
2975
|
if (typeof ResizeObserver === "undefined") return;
|
|
2933
2976
|
if (!this.snapPointsRaw.some((p) => p.size === "fit" || p.size === "content"))
|
|
2934
2977
|
return;
|
|
2935
|
-
const targets = [this.handle];
|
|
2936
|
-
if (this.scrollContainer && this.scrollContainer !== this.handle) {
|
|
2937
|
-
targets.push(this.scrollContainer);
|
|
2938
|
-
}
|
|
2939
2978
|
let raf = 0;
|
|
2940
|
-
const
|
|
2979
|
+
const schedule = () => {
|
|
2941
2980
|
if (raf) return;
|
|
2942
2981
|
raf = requestAnimationFrame(() => {
|
|
2943
2982
|
raf = 0;
|
|
2944
2983
|
if (this.destroyed || this.gesture?.isDragging) return;
|
|
2945
2984
|
this.recompute();
|
|
2946
2985
|
});
|
|
2947
|
-
}
|
|
2948
|
-
|
|
2986
|
+
};
|
|
2987
|
+
const ro = new ResizeObserver(schedule);
|
|
2988
|
+
ro.observe(this.handle);
|
|
2989
|
+
const scroller = this.scrollContainer;
|
|
2990
|
+
const observed = /* @__PURE__ */ new Set();
|
|
2991
|
+
const slots = /* @__PURE__ */ new Set();
|
|
2992
|
+
const hasSlot = typeof HTMLSlotElement !== "undefined";
|
|
2993
|
+
const onSlotChange = () => resync();
|
|
2994
|
+
const trackSlots = () => {
|
|
2995
|
+
if (!scroller || !hasSlot) return;
|
|
2996
|
+
for (const child2 of Array.from(scroller.children)) {
|
|
2997
|
+
if (child2 instanceof HTMLSlotElement && !slots.has(child2)) {
|
|
2998
|
+
child2.addEventListener("slotchange", onSlotChange);
|
|
2999
|
+
slots.add(child2);
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
};
|
|
3003
|
+
const resync = () => {
|
|
3004
|
+
trackSlots();
|
|
3005
|
+
const targets = this.contentTargets();
|
|
3006
|
+
for (const el of observed) {
|
|
3007
|
+
if (!targets.includes(el)) {
|
|
3008
|
+
ro.unobserve(el);
|
|
3009
|
+
observed.delete(el);
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3012
|
+
for (const el of targets) {
|
|
3013
|
+
if (!observed.has(el)) {
|
|
3014
|
+
ro.observe(el);
|
|
3015
|
+
observed.add(el);
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
schedule();
|
|
3019
|
+
};
|
|
3020
|
+
let mo;
|
|
3021
|
+
if (scroller) {
|
|
3022
|
+
resync();
|
|
3023
|
+
if (typeof MutationObserver !== "undefined") {
|
|
3024
|
+
mo = new MutationObserver(resync);
|
|
3025
|
+
mo.observe(scroller, { childList: true });
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
2949
3028
|
this.teardowns.add(() => {
|
|
2950
3029
|
ro.disconnect();
|
|
3030
|
+
mo?.disconnect();
|
|
3031
|
+
for (const slot of slots) {
|
|
3032
|
+
slot.removeEventListener("slotchange", onSlotChange);
|
|
3033
|
+
}
|
|
2951
3034
|
if (raf) cancelAnimationFrame(raf);
|
|
2952
3035
|
});
|
|
2953
3036
|
}
|
|
@@ -3368,6 +3451,38 @@ var BottomSheetEngine = class {
|
|
|
3368
3451
|
}
|
|
3369
3452
|
};
|
|
3370
3453
|
|
|
3454
|
+
// src/core/features/teleport.ts
|
|
3455
|
+
var resolveTeleportTarget = (target) => {
|
|
3456
|
+
if (!target) return null;
|
|
3457
|
+
if (typeof target !== "string") return target;
|
|
3458
|
+
if (typeof document === "undefined") return null;
|
|
3459
|
+
if (target === "body") return document.body;
|
|
3460
|
+
return document.querySelector(target);
|
|
3461
|
+
};
|
|
3462
|
+
var teleportElements = (els, target) => {
|
|
3463
|
+
const records = [];
|
|
3464
|
+
for (const el of els) {
|
|
3465
|
+
if (!el || el.parentNode === target) continue;
|
|
3466
|
+
records.push({ el, parent: el.parentNode, next: el.nextSibling });
|
|
3467
|
+
target.appendChild(el);
|
|
3468
|
+
}
|
|
3469
|
+
return () => {
|
|
3470
|
+
for (let i = records.length - 1; i >= 0; i--) {
|
|
3471
|
+
const { el, parent, next } = records[i];
|
|
3472
|
+
if (parent && parent.isConnected) {
|
|
3473
|
+
const before = next && next.parentNode === parent ? next : null;
|
|
3474
|
+
try {
|
|
3475
|
+
parent.insertBefore(el, before);
|
|
3476
|
+
} catch {
|
|
3477
|
+
el.parentNode?.removeChild(el);
|
|
3478
|
+
}
|
|
3479
|
+
} else {
|
|
3480
|
+
el.parentNode?.removeChild(el);
|
|
3481
|
+
}
|
|
3482
|
+
}
|
|
3483
|
+
};
|
|
3484
|
+
};
|
|
3485
|
+
|
|
3371
3486
|
// src/svelte/useBottomSheet.svelte.ts
|
|
3372
3487
|
var SSR_STATE = Object.freeze({
|
|
3373
3488
|
size: 0,
|
|
@@ -3381,9 +3496,21 @@ function createBottomSheet(opts) {
|
|
|
3381
3496
|
const pending = [];
|
|
3382
3497
|
const attach = (refs) => {
|
|
3383
3498
|
if (engine) engine.destroy();
|
|
3384
|
-
const {
|
|
3499
|
+
const {
|
|
3500
|
+
onSnap,
|
|
3501
|
+
teleportTo,
|
|
3502
|
+
backdropColor,
|
|
3503
|
+
backdropOpacity,
|
|
3504
|
+
...engineOpts
|
|
3505
|
+
} = opts;
|
|
3385
3506
|
const created = new BottomSheetEngine({ ...engineOpts, ...refs });
|
|
3386
3507
|
engine = created;
|
|
3508
|
+
const target = resolveTeleportTarget(teleportTo);
|
|
3509
|
+
const restoreTeleport = target ? teleportElements([refs.backdrop, refs.scrim, refs.element], target) : null;
|
|
3510
|
+
if (backdropColor !== void 0) created.setScrimColor(backdropColor);
|
|
3511
|
+
if (backdropOpacity !== void 0) {
|
|
3512
|
+
created.setBackdropRange([0, backdropOpacity]);
|
|
3513
|
+
}
|
|
3387
3514
|
if (onSnap) {
|
|
3388
3515
|
created.on("snap", (payload) => onSnap(payload.id));
|
|
3389
3516
|
}
|
|
@@ -3392,6 +3519,7 @@ function createBottomSheet(opts) {
|
|
|
3392
3519
|
}
|
|
3393
3520
|
pending.length = 0;
|
|
3394
3521
|
return () => {
|
|
3522
|
+
restoreTeleport?.();
|
|
3395
3523
|
created.destroy();
|
|
3396
3524
|
if (engine === created) engine = null;
|
|
3397
3525
|
};
|
|
@@ -3438,9 +3566,11 @@ function createBottomSheet(opts) {
|
|
|
3438
3566
|
};
|
|
3439
3567
|
}
|
|
3440
3568
|
var root_1 = $2__namespace.from_html(`<div class="bs-backdrop" aria-hidden="true"></div>`);
|
|
3441
|
-
var
|
|
3442
|
-
var
|
|
3443
|
-
var
|
|
3569
|
+
var root_3 = $2__namespace.from_html(`<div class="bs-header"><!></div>`);
|
|
3570
|
+
var root_5 = $2__namespace.from_html(`<div class="bs-footer"><!></div>`);
|
|
3571
|
+
var root_6 = $2__namespace.from_html(`<div class="bs-button-slot" data-side="left"><!></div>`);
|
|
3572
|
+
var root_7 = $2__namespace.from_html(`<div class="bs-button-slot" data-side="right"><!></div>`);
|
|
3573
|
+
var root = $2__namespace.from_html(`<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"> </span></section> <!> <!></div>`);
|
|
3444
3574
|
function BottomSheet($$anchor, $$props) {
|
|
3445
3575
|
$2__namespace.push($$props, true);
|
|
3446
3576
|
let mode = $2__namespace.prop($$props, "mode", 3, "bottom"), animation = $2__namespace.prop($$props, "animation", 3, "spring"), focusTrap = $2__namespace.prop($$props, "focusTrap", 3, false), closeOnEscape = $2__namespace.prop($$props, "closeOnEscape", 3, true), closeOnBack = $2__namespace.prop($$props, "closeOnBack", 3, false), lockBodyScroll2 = $2__namespace.prop($$props, "lockBodyScroll", 3, true), rubberBand2 = $2__namespace.prop($$props, "rubberBand", 3, true), backdrop = $2__namespace.prop($$props, "backdrop", 3, true), closeOnBackdrop = $2__namespace.prop($$props, "closeOnBackdrop", 3, true), persistent = $2__namespace.prop($$props, "persistent", 3, false), disableClose = $2__namespace.prop($$props, "disableClose", 3, false), disableDrag = $2__namespace.prop($$props, "disableDrag", 3, false), closeOnRouteChange = $2__namespace.prop($$props, "closeOnRouteChange", 3, false), openProp = $2__namespace.prop($$props, "open", 15), snap = $2__namespace.prop($$props, "snap", 15), ariaLabel = $2__namespace.prop($$props, "ariaLabel", 3, "Bottom sheet");
|
|
@@ -3621,66 +3751,79 @@ function BottomSheet($$anchor, $$props) {
|
|
|
3621
3751
|
var section = $2__namespace.sibling(div_2, 2);
|
|
3622
3752
|
var div_3 = $2__namespace.child(section);
|
|
3623
3753
|
$2__namespace.set_attribute(div_3, "aria-valuemin", 0);
|
|
3624
|
-
|
|
3754
|
+
$2__namespace.bind_this(div_3, ($$value) => $2__namespace.set(handleEl, $$value), () => $2__namespace.get(handleEl));
|
|
3755
|
+
var node_3 = $2__namespace.sibling(div_3, 2);
|
|
3625
3756
|
{
|
|
3626
3757
|
var consequent_2 = ($$anchor2) => {
|
|
3627
|
-
var
|
|
3628
|
-
var node_4 = $2__namespace.
|
|
3758
|
+
var div_4 = root_3();
|
|
3759
|
+
var node_4 = $2__namespace.child(div_4);
|
|
3629
3760
|
$2__namespace.snippet(node_4, () => $$props.header, () => $2__namespace.get(viewState));
|
|
3630
|
-
$2__namespace.
|
|
3761
|
+
$2__namespace.reset(div_4);
|
|
3762
|
+
$2__namespace.append($$anchor2, div_4);
|
|
3631
3763
|
};
|
|
3632
3764
|
$2__namespace.if(node_3, ($$render) => {
|
|
3633
3765
|
if ($$props.header) $$render(consequent_2);
|
|
3634
3766
|
});
|
|
3635
3767
|
}
|
|
3636
|
-
$2__namespace.
|
|
3637
|
-
|
|
3638
|
-
var div_4 = $2__namespace.sibling(div_3, 2);
|
|
3639
|
-
var node_5 = $2__namespace.child(div_4);
|
|
3768
|
+
var div_5 = $2__namespace.sibling(node_3, 2);
|
|
3769
|
+
var node_5 = $2__namespace.child(div_5);
|
|
3640
3770
|
{
|
|
3641
3771
|
var consequent_3 = ($$anchor2) => {
|
|
3642
|
-
var
|
|
3643
|
-
var node_6 = $2__namespace.first_child(
|
|
3772
|
+
var fragment_1 = $2__namespace.comment();
|
|
3773
|
+
var node_6 = $2__namespace.first_child(fragment_1);
|
|
3644
3774
|
$2__namespace.snippet(node_6, () => $$props.children);
|
|
3645
|
-
$2__namespace.append($$anchor2,
|
|
3775
|
+
$2__namespace.append($$anchor2, fragment_1);
|
|
3646
3776
|
};
|
|
3647
3777
|
$2__namespace.if(node_5, ($$render) => {
|
|
3648
3778
|
if ($$props.children) $$render(consequent_3);
|
|
3649
3779
|
});
|
|
3650
3780
|
}
|
|
3651
|
-
$2__namespace.reset(
|
|
3652
|
-
$2__namespace.bind_this(
|
|
3653
|
-
var
|
|
3654
|
-
var text = $2__namespace.child(span, true);
|
|
3655
|
-
$2__namespace.reset(span);
|
|
3656
|
-
$2__namespace.reset(section);
|
|
3657
|
-
$2__namespace.bind_this(section, ($$value) => $2__namespace.set(sheetEl, $$value), () => $2__namespace.get(sheetEl));
|
|
3658
|
-
var node_7 = $2__namespace.sibling(section, 2);
|
|
3781
|
+
$2__namespace.reset(div_5);
|
|
3782
|
+
$2__namespace.bind_this(div_5, ($$value) => $2__namespace.set(contentEl, $$value), () => $2__namespace.get(contentEl));
|
|
3783
|
+
var node_7 = $2__namespace.sibling(div_5, 2);
|
|
3659
3784
|
{
|
|
3660
3785
|
var consequent_4 = ($$anchor2) => {
|
|
3661
|
-
var
|
|
3662
|
-
var node_8 = $2__namespace.child(
|
|
3663
|
-
$2__namespace.snippet(node_8, () => $$props.
|
|
3664
|
-
$2__namespace.reset(
|
|
3665
|
-
$2__namespace.
|
|
3666
|
-
$2__namespace.append($$anchor2, div_5);
|
|
3786
|
+
var div_6 = root_5();
|
|
3787
|
+
var node_8 = $2__namespace.child(div_6);
|
|
3788
|
+
$2__namespace.snippet(node_8, () => $$props.footer, () => $2__namespace.get(viewState));
|
|
3789
|
+
$2__namespace.reset(div_6);
|
|
3790
|
+
$2__namespace.append($$anchor2, div_6);
|
|
3667
3791
|
};
|
|
3668
3792
|
$2__namespace.if(node_7, ($$render) => {
|
|
3669
|
-
if ($$props.
|
|
3793
|
+
if ($$props.footer) $$render(consequent_4);
|
|
3670
3794
|
});
|
|
3671
3795
|
}
|
|
3672
|
-
var
|
|
3796
|
+
var span = $2__namespace.sibling(node_7, 2);
|
|
3797
|
+
var text = $2__namespace.child(span, true);
|
|
3798
|
+
$2__namespace.reset(span);
|
|
3799
|
+
$2__namespace.reset(section);
|
|
3800
|
+
$2__namespace.bind_this(section, ($$value) => $2__namespace.set(sheetEl, $$value), () => $2__namespace.get(sheetEl));
|
|
3801
|
+
var node_9 = $2__namespace.sibling(section, 2);
|
|
3673
3802
|
{
|
|
3674
3803
|
var consequent_5 = ($$anchor2) => {
|
|
3675
|
-
var
|
|
3676
|
-
var node_10 = $2__namespace.child(
|
|
3677
|
-
$2__namespace.snippet(node_10, () => $$props.
|
|
3678
|
-
$2__namespace.reset(
|
|
3679
|
-
$2__namespace.template_effect(() => $2__namespace.set_attribute(
|
|
3680
|
-
$2__namespace.append($$anchor2,
|
|
3804
|
+
var div_7 = root_6();
|
|
3805
|
+
var node_10 = $2__namespace.child(div_7);
|
|
3806
|
+
$2__namespace.snippet(node_10, () => $$props.leftButton);
|
|
3807
|
+
$2__namespace.reset(div_7);
|
|
3808
|
+
$2__namespace.template_effect(() => $2__namespace.set_attribute(div_7, "data-mode", mode()));
|
|
3809
|
+
$2__namespace.append($$anchor2, div_7);
|
|
3681
3810
|
};
|
|
3682
3811
|
$2__namespace.if(node_9, ($$render) => {
|
|
3683
|
-
if ($$props.
|
|
3812
|
+
if ($$props.leftButton) $$render(consequent_5);
|
|
3813
|
+
});
|
|
3814
|
+
}
|
|
3815
|
+
var node_11 = $2__namespace.sibling(node_9, 2);
|
|
3816
|
+
{
|
|
3817
|
+
var consequent_6 = ($$anchor2) => {
|
|
3818
|
+
var div_8 = root_7();
|
|
3819
|
+
var node_12 = $2__namespace.child(div_8);
|
|
3820
|
+
$2__namespace.snippet(node_12, () => $$props.rightButton);
|
|
3821
|
+
$2__namespace.reset(div_8);
|
|
3822
|
+
$2__namespace.template_effect(() => $2__namespace.set_attribute(div_8, "data-mode", mode()));
|
|
3823
|
+
$2__namespace.append($$anchor2, div_8);
|
|
3824
|
+
};
|
|
3825
|
+
$2__namespace.if(node_11, ($$render) => {
|
|
3826
|
+
if ($$props.rightButton) $$render(consequent_6);
|
|
3684
3827
|
});
|
|
3685
3828
|
}
|
|
3686
3829
|
$2__namespace.reset(div);
|
package/dist/svelte.d.cts
CHANGED
|
@@ -95,6 +95,7 @@ export type BottomSheetProps<TId extends string = string> = {
|
|
|
95
95
|
returnFocusTo?: HTMLElement | string | (() => HTMLElement | null);
|
|
96
96
|
ariaLabel?: string;
|
|
97
97
|
header?: Snippet<[EngineState & { activeId: TId }]>;
|
|
98
|
+
footer?: Snippet<[EngineState & { activeId: TId }]>;
|
|
98
99
|
leftButton?: Snippet;
|
|
99
100
|
rightButton?: Snippet;
|
|
100
101
|
screen?: Snippet;
|
package/dist/svelte.d.ts
CHANGED
|
@@ -95,6 +95,7 @@ export type BottomSheetProps<TId extends string = string> = {
|
|
|
95
95
|
returnFocusTo?: HTMLElement | string | (() => HTMLElement | null);
|
|
96
96
|
ariaLabel?: string;
|
|
97
97
|
header?: Snippet<[EngineState & { activeId: TId }]>;
|
|
98
|
+
footer?: Snippet<[EngineState & { activeId: TId }]>;
|
|
98
99
|
leftButton?: Snippet;
|
|
99
100
|
rightButton?: Snippet;
|
|
100
101
|
screen?: Snippet;
|
package/dist/svelte.js
CHANGED
|
@@ -2897,11 +2897,54 @@ var BottomSheetEngine = class {
|
|
|
2897
2897
|
this.updateAriaSlider();
|
|
2898
2898
|
}
|
|
2899
2899
|
}
|
|
2900
|
+
contentTargets() {
|
|
2901
|
+
const scroller = this.scrollContainer;
|
|
2902
|
+
if (!scroller) return [];
|
|
2903
|
+
const hasSlot = typeof HTMLSlotElement !== "undefined";
|
|
2904
|
+
const out = [];
|
|
2905
|
+
for (const child2 of Array.from(scroller.children)) {
|
|
2906
|
+
if (hasSlot && child2 instanceof HTMLSlotElement) {
|
|
2907
|
+
for (const el of child2.assignedElements()) out.push(el);
|
|
2908
|
+
} else {
|
|
2909
|
+
out.push(child2);
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
return out;
|
|
2913
|
+
}
|
|
2914
|
+
measureContentExtent(vertical) {
|
|
2915
|
+
const content = this.scrollContainer;
|
|
2916
|
+
if (!content) return 0;
|
|
2917
|
+
const targets = this.contentTargets();
|
|
2918
|
+
if (targets.length === 0) {
|
|
2919
|
+
return vertical ? content.scrollHeight : content.scrollWidth;
|
|
2920
|
+
}
|
|
2921
|
+
let min = Infinity;
|
|
2922
|
+
let max = -Infinity;
|
|
2923
|
+
for (const el of targets) {
|
|
2924
|
+
const r = el.getBoundingClientRect();
|
|
2925
|
+
if (vertical) {
|
|
2926
|
+
if (r.top < min) min = r.top;
|
|
2927
|
+
if (r.bottom > max) max = r.bottom;
|
|
2928
|
+
} else {
|
|
2929
|
+
if (r.left < min) min = r.left;
|
|
2930
|
+
if (r.right > max) max = r.right;
|
|
2931
|
+
}
|
|
2932
|
+
}
|
|
2933
|
+
if (!isFinite(min) || !isFinite(max) || max <= min) {
|
|
2934
|
+
return vertical ? content.scrollHeight : content.scrollWidth;
|
|
2935
|
+
}
|
|
2936
|
+
let pad = 0;
|
|
2937
|
+
if (typeof getComputedStyle !== "undefined") {
|
|
2938
|
+
const cs = getComputedStyle(content);
|
|
2939
|
+
pad = vertical ? (parseFloat(cs.paddingTop) || 0) + (parseFloat(cs.paddingBottom) || 0) : (parseFloat(cs.paddingLeft) || 0) + (parseFloat(cs.paddingRight) || 0);
|
|
2940
|
+
}
|
|
2941
|
+
return max - min + pad;
|
|
2942
|
+
}
|
|
2900
2943
|
measureFitSize() {
|
|
2901
2944
|
const vertical = layoutAxis(this.mode) === "height";
|
|
2902
2945
|
const handleSize = vertical ? this.handle.offsetHeight : this.handle.offsetWidth;
|
|
2903
2946
|
const content = this.scrollContainer;
|
|
2904
|
-
const natural = content ? handleSize + (vertical
|
|
2947
|
+
const natural = content ? handleSize + this.measureContentExtent(vertical) : handleSize;
|
|
2905
2948
|
if (typeof window === "undefined") return natural;
|
|
2906
2949
|
const viewport = vertical ? window.innerHeight : window.innerWidth;
|
|
2907
2950
|
return viewport > 0 ? Math.min(natural, viewport) : natural;
|
|
@@ -2910,22 +2953,62 @@ var BottomSheetEngine = class {
|
|
|
2910
2953
|
if (typeof ResizeObserver === "undefined") return;
|
|
2911
2954
|
if (!this.snapPointsRaw.some((p) => p.size === "fit" || p.size === "content"))
|
|
2912
2955
|
return;
|
|
2913
|
-
const targets = [this.handle];
|
|
2914
|
-
if (this.scrollContainer && this.scrollContainer !== this.handle) {
|
|
2915
|
-
targets.push(this.scrollContainer);
|
|
2916
|
-
}
|
|
2917
2956
|
let raf = 0;
|
|
2918
|
-
const
|
|
2957
|
+
const schedule = () => {
|
|
2919
2958
|
if (raf) return;
|
|
2920
2959
|
raf = requestAnimationFrame(() => {
|
|
2921
2960
|
raf = 0;
|
|
2922
2961
|
if (this.destroyed || this.gesture?.isDragging) return;
|
|
2923
2962
|
this.recompute();
|
|
2924
2963
|
});
|
|
2925
|
-
}
|
|
2926
|
-
|
|
2964
|
+
};
|
|
2965
|
+
const ro = new ResizeObserver(schedule);
|
|
2966
|
+
ro.observe(this.handle);
|
|
2967
|
+
const scroller = this.scrollContainer;
|
|
2968
|
+
const observed = /* @__PURE__ */ new Set();
|
|
2969
|
+
const slots = /* @__PURE__ */ new Set();
|
|
2970
|
+
const hasSlot = typeof HTMLSlotElement !== "undefined";
|
|
2971
|
+
const onSlotChange = () => resync();
|
|
2972
|
+
const trackSlots = () => {
|
|
2973
|
+
if (!scroller || !hasSlot) return;
|
|
2974
|
+
for (const child2 of Array.from(scroller.children)) {
|
|
2975
|
+
if (child2 instanceof HTMLSlotElement && !slots.has(child2)) {
|
|
2976
|
+
child2.addEventListener("slotchange", onSlotChange);
|
|
2977
|
+
slots.add(child2);
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
};
|
|
2981
|
+
const resync = () => {
|
|
2982
|
+
trackSlots();
|
|
2983
|
+
const targets = this.contentTargets();
|
|
2984
|
+
for (const el of observed) {
|
|
2985
|
+
if (!targets.includes(el)) {
|
|
2986
|
+
ro.unobserve(el);
|
|
2987
|
+
observed.delete(el);
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
for (const el of targets) {
|
|
2991
|
+
if (!observed.has(el)) {
|
|
2992
|
+
ro.observe(el);
|
|
2993
|
+
observed.add(el);
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2996
|
+
schedule();
|
|
2997
|
+
};
|
|
2998
|
+
let mo;
|
|
2999
|
+
if (scroller) {
|
|
3000
|
+
resync();
|
|
3001
|
+
if (typeof MutationObserver !== "undefined") {
|
|
3002
|
+
mo = new MutationObserver(resync);
|
|
3003
|
+
mo.observe(scroller, { childList: true });
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
2927
3006
|
this.teardowns.add(() => {
|
|
2928
3007
|
ro.disconnect();
|
|
3008
|
+
mo?.disconnect();
|
|
3009
|
+
for (const slot of slots) {
|
|
3010
|
+
slot.removeEventListener("slotchange", onSlotChange);
|
|
3011
|
+
}
|
|
2929
3012
|
if (raf) cancelAnimationFrame(raf);
|
|
2930
3013
|
});
|
|
2931
3014
|
}
|
|
@@ -3346,6 +3429,38 @@ var BottomSheetEngine = class {
|
|
|
3346
3429
|
}
|
|
3347
3430
|
};
|
|
3348
3431
|
|
|
3432
|
+
// src/core/features/teleport.ts
|
|
3433
|
+
var resolveTeleportTarget = (target) => {
|
|
3434
|
+
if (!target) return null;
|
|
3435
|
+
if (typeof target !== "string") return target;
|
|
3436
|
+
if (typeof document === "undefined") return null;
|
|
3437
|
+
if (target === "body") return document.body;
|
|
3438
|
+
return document.querySelector(target);
|
|
3439
|
+
};
|
|
3440
|
+
var teleportElements = (els, target) => {
|
|
3441
|
+
const records = [];
|
|
3442
|
+
for (const el of els) {
|
|
3443
|
+
if (!el || el.parentNode === target) continue;
|
|
3444
|
+
records.push({ el, parent: el.parentNode, next: el.nextSibling });
|
|
3445
|
+
target.appendChild(el);
|
|
3446
|
+
}
|
|
3447
|
+
return () => {
|
|
3448
|
+
for (let i = records.length - 1; i >= 0; i--) {
|
|
3449
|
+
const { el, parent, next } = records[i];
|
|
3450
|
+
if (parent && parent.isConnected) {
|
|
3451
|
+
const before = next && next.parentNode === parent ? next : null;
|
|
3452
|
+
try {
|
|
3453
|
+
parent.insertBefore(el, before);
|
|
3454
|
+
} catch {
|
|
3455
|
+
el.parentNode?.removeChild(el);
|
|
3456
|
+
}
|
|
3457
|
+
} else {
|
|
3458
|
+
el.parentNode?.removeChild(el);
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
};
|
|
3462
|
+
};
|
|
3463
|
+
|
|
3349
3464
|
// src/svelte/useBottomSheet.svelte.ts
|
|
3350
3465
|
var SSR_STATE = Object.freeze({
|
|
3351
3466
|
size: 0,
|
|
@@ -3359,9 +3474,21 @@ function createBottomSheet(opts) {
|
|
|
3359
3474
|
const pending = [];
|
|
3360
3475
|
const attach = (refs) => {
|
|
3361
3476
|
if (engine) engine.destroy();
|
|
3362
|
-
const {
|
|
3477
|
+
const {
|
|
3478
|
+
onSnap,
|
|
3479
|
+
teleportTo,
|
|
3480
|
+
backdropColor,
|
|
3481
|
+
backdropOpacity,
|
|
3482
|
+
...engineOpts
|
|
3483
|
+
} = opts;
|
|
3363
3484
|
const created = new BottomSheetEngine({ ...engineOpts, ...refs });
|
|
3364
3485
|
engine = created;
|
|
3486
|
+
const target = resolveTeleportTarget(teleportTo);
|
|
3487
|
+
const restoreTeleport = target ? teleportElements([refs.backdrop, refs.scrim, refs.element], target) : null;
|
|
3488
|
+
if (backdropColor !== void 0) created.setScrimColor(backdropColor);
|
|
3489
|
+
if (backdropOpacity !== void 0) {
|
|
3490
|
+
created.setBackdropRange([0, backdropOpacity]);
|
|
3491
|
+
}
|
|
3365
3492
|
if (onSnap) {
|
|
3366
3493
|
created.on("snap", (payload) => onSnap(payload.id));
|
|
3367
3494
|
}
|
|
@@ -3370,6 +3497,7 @@ function createBottomSheet(opts) {
|
|
|
3370
3497
|
}
|
|
3371
3498
|
pending.length = 0;
|
|
3372
3499
|
return () => {
|
|
3500
|
+
restoreTeleport?.();
|
|
3373
3501
|
created.destroy();
|
|
3374
3502
|
if (engine === created) engine = null;
|
|
3375
3503
|
};
|
|
@@ -3416,9 +3544,11 @@ function createBottomSheet(opts) {
|
|
|
3416
3544
|
};
|
|
3417
3545
|
}
|
|
3418
3546
|
var root_1 = $2.from_html(`<div class="bs-backdrop" aria-hidden="true"></div>`);
|
|
3419
|
-
var
|
|
3420
|
-
var
|
|
3421
|
-
var
|
|
3547
|
+
var root_3 = $2.from_html(`<div class="bs-header"><!></div>`);
|
|
3548
|
+
var root_5 = $2.from_html(`<div class="bs-footer"><!></div>`);
|
|
3549
|
+
var root_6 = $2.from_html(`<div class="bs-button-slot" data-side="left"><!></div>`);
|
|
3550
|
+
var root_7 = $2.from_html(`<div class="bs-button-slot" data-side="right"><!></div>`);
|
|
3551
|
+
var root = $2.from_html(`<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"> </span></section> <!> <!></div>`);
|
|
3422
3552
|
function BottomSheet($$anchor, $$props) {
|
|
3423
3553
|
$2.push($$props, true);
|
|
3424
3554
|
let mode = $2.prop($$props, "mode", 3, "bottom"), animation = $2.prop($$props, "animation", 3, "spring"), focusTrap = $2.prop($$props, "focusTrap", 3, false), closeOnEscape = $2.prop($$props, "closeOnEscape", 3, true), closeOnBack = $2.prop($$props, "closeOnBack", 3, false), lockBodyScroll2 = $2.prop($$props, "lockBodyScroll", 3, true), rubberBand2 = $2.prop($$props, "rubberBand", 3, true), backdrop = $2.prop($$props, "backdrop", 3, true), closeOnBackdrop = $2.prop($$props, "closeOnBackdrop", 3, true), persistent = $2.prop($$props, "persistent", 3, false), disableClose = $2.prop($$props, "disableClose", 3, false), disableDrag = $2.prop($$props, "disableDrag", 3, false), closeOnRouteChange = $2.prop($$props, "closeOnRouteChange", 3, false), openProp = $2.prop($$props, "open", 15), snap = $2.prop($$props, "snap", 15), ariaLabel = $2.prop($$props, "ariaLabel", 3, "Bottom sheet");
|
|
@@ -3599,66 +3729,79 @@ function BottomSheet($$anchor, $$props) {
|
|
|
3599
3729
|
var section = $2.sibling(div_2, 2);
|
|
3600
3730
|
var div_3 = $2.child(section);
|
|
3601
3731
|
$2.set_attribute(div_3, "aria-valuemin", 0);
|
|
3602
|
-
|
|
3732
|
+
$2.bind_this(div_3, ($$value) => $2.set(handleEl, $$value), () => $2.get(handleEl));
|
|
3733
|
+
var node_3 = $2.sibling(div_3, 2);
|
|
3603
3734
|
{
|
|
3604
3735
|
var consequent_2 = ($$anchor2) => {
|
|
3605
|
-
var
|
|
3606
|
-
var node_4 = $2.
|
|
3736
|
+
var div_4 = root_3();
|
|
3737
|
+
var node_4 = $2.child(div_4);
|
|
3607
3738
|
$2.snippet(node_4, () => $$props.header, () => $2.get(viewState));
|
|
3608
|
-
$2.
|
|
3739
|
+
$2.reset(div_4);
|
|
3740
|
+
$2.append($$anchor2, div_4);
|
|
3609
3741
|
};
|
|
3610
3742
|
$2.if(node_3, ($$render) => {
|
|
3611
3743
|
if ($$props.header) $$render(consequent_2);
|
|
3612
3744
|
});
|
|
3613
3745
|
}
|
|
3614
|
-
$2.
|
|
3615
|
-
|
|
3616
|
-
var div_4 = $2.sibling(div_3, 2);
|
|
3617
|
-
var node_5 = $2.child(div_4);
|
|
3746
|
+
var div_5 = $2.sibling(node_3, 2);
|
|
3747
|
+
var node_5 = $2.child(div_5);
|
|
3618
3748
|
{
|
|
3619
3749
|
var consequent_3 = ($$anchor2) => {
|
|
3620
|
-
var
|
|
3621
|
-
var node_6 = $2.first_child(
|
|
3750
|
+
var fragment_1 = $2.comment();
|
|
3751
|
+
var node_6 = $2.first_child(fragment_1);
|
|
3622
3752
|
$2.snippet(node_6, () => $$props.children);
|
|
3623
|
-
$2.append($$anchor2,
|
|
3753
|
+
$2.append($$anchor2, fragment_1);
|
|
3624
3754
|
};
|
|
3625
3755
|
$2.if(node_5, ($$render) => {
|
|
3626
3756
|
if ($$props.children) $$render(consequent_3);
|
|
3627
3757
|
});
|
|
3628
3758
|
}
|
|
3629
|
-
$2.reset(
|
|
3630
|
-
$2.bind_this(
|
|
3631
|
-
var
|
|
3632
|
-
var text = $2.child(span, true);
|
|
3633
|
-
$2.reset(span);
|
|
3634
|
-
$2.reset(section);
|
|
3635
|
-
$2.bind_this(section, ($$value) => $2.set(sheetEl, $$value), () => $2.get(sheetEl));
|
|
3636
|
-
var node_7 = $2.sibling(section, 2);
|
|
3759
|
+
$2.reset(div_5);
|
|
3760
|
+
$2.bind_this(div_5, ($$value) => $2.set(contentEl, $$value), () => $2.get(contentEl));
|
|
3761
|
+
var node_7 = $2.sibling(div_5, 2);
|
|
3637
3762
|
{
|
|
3638
3763
|
var consequent_4 = ($$anchor2) => {
|
|
3639
|
-
var
|
|
3640
|
-
var node_8 = $2.child(
|
|
3641
|
-
$2.snippet(node_8, () => $$props.
|
|
3642
|
-
$2.reset(
|
|
3643
|
-
$2.
|
|
3644
|
-
$2.append($$anchor2, div_5);
|
|
3764
|
+
var div_6 = root_5();
|
|
3765
|
+
var node_8 = $2.child(div_6);
|
|
3766
|
+
$2.snippet(node_8, () => $$props.footer, () => $2.get(viewState));
|
|
3767
|
+
$2.reset(div_6);
|
|
3768
|
+
$2.append($$anchor2, div_6);
|
|
3645
3769
|
};
|
|
3646
3770
|
$2.if(node_7, ($$render) => {
|
|
3647
|
-
if ($$props.
|
|
3771
|
+
if ($$props.footer) $$render(consequent_4);
|
|
3648
3772
|
});
|
|
3649
3773
|
}
|
|
3650
|
-
var
|
|
3774
|
+
var span = $2.sibling(node_7, 2);
|
|
3775
|
+
var text = $2.child(span, true);
|
|
3776
|
+
$2.reset(span);
|
|
3777
|
+
$2.reset(section);
|
|
3778
|
+
$2.bind_this(section, ($$value) => $2.set(sheetEl, $$value), () => $2.get(sheetEl));
|
|
3779
|
+
var node_9 = $2.sibling(section, 2);
|
|
3651
3780
|
{
|
|
3652
3781
|
var consequent_5 = ($$anchor2) => {
|
|
3653
|
-
var
|
|
3654
|
-
var node_10 = $2.child(
|
|
3655
|
-
$2.snippet(node_10, () => $$props.
|
|
3656
|
-
$2.reset(
|
|
3657
|
-
$2.template_effect(() => $2.set_attribute(
|
|
3658
|
-
$2.append($$anchor2,
|
|
3782
|
+
var div_7 = root_6();
|
|
3783
|
+
var node_10 = $2.child(div_7);
|
|
3784
|
+
$2.snippet(node_10, () => $$props.leftButton);
|
|
3785
|
+
$2.reset(div_7);
|
|
3786
|
+
$2.template_effect(() => $2.set_attribute(div_7, "data-mode", mode()));
|
|
3787
|
+
$2.append($$anchor2, div_7);
|
|
3659
3788
|
};
|
|
3660
3789
|
$2.if(node_9, ($$render) => {
|
|
3661
|
-
if ($$props.
|
|
3790
|
+
if ($$props.leftButton) $$render(consequent_5);
|
|
3791
|
+
});
|
|
3792
|
+
}
|
|
3793
|
+
var node_11 = $2.sibling(node_9, 2);
|
|
3794
|
+
{
|
|
3795
|
+
var consequent_6 = ($$anchor2) => {
|
|
3796
|
+
var div_8 = root_7();
|
|
3797
|
+
var node_12 = $2.child(div_8);
|
|
3798
|
+
$2.snippet(node_12, () => $$props.rightButton);
|
|
3799
|
+
$2.reset(div_8);
|
|
3800
|
+
$2.template_effect(() => $2.set_attribute(div_8, "data-mode", mode()));
|
|
3801
|
+
$2.append($$anchor2, div_8);
|
|
3802
|
+
};
|
|
3803
|
+
$2.if(node_11, ($$render) => {
|
|
3804
|
+
if ($$props.rightButton) $$render(consequent_6);
|
|
3662
3805
|
});
|
|
3663
3806
|
}
|
|
3664
3807
|
$2.reset(div);
|