@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/solid.source.jsx
CHANGED
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
createEffect,
|
|
6
6
|
on,
|
|
7
7
|
onCleanup,
|
|
8
|
-
onMount
|
|
8
|
+
onMount,
|
|
9
|
+
Show
|
|
9
10
|
} from "solid-js";
|
|
10
11
|
|
|
11
12
|
// src/core/lifecycle/sheetStack.ts
|
|
@@ -2897,11 +2898,54 @@ var BottomSheetEngine = class {
|
|
|
2897
2898
|
this.updateAriaSlider();
|
|
2898
2899
|
}
|
|
2899
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
|
+
}
|
|
2900
2944
|
measureFitSize() {
|
|
2901
2945
|
const vertical = layoutAxis(this.mode) === "height";
|
|
2902
2946
|
const handleSize = vertical ? this.handle.offsetHeight : this.handle.offsetWidth;
|
|
2903
2947
|
const content = this.scrollContainer;
|
|
2904
|
-
const natural = content ? handleSize + (vertical
|
|
2948
|
+
const natural = content ? handleSize + this.measureContentExtent(vertical) : handleSize;
|
|
2905
2949
|
if (typeof window === "undefined") return natural;
|
|
2906
2950
|
const viewport = vertical ? window.innerHeight : window.innerWidth;
|
|
2907
2951
|
return viewport > 0 ? Math.min(natural, viewport) : natural;
|
|
@@ -2910,22 +2954,62 @@ var BottomSheetEngine = class {
|
|
|
2910
2954
|
if (typeof ResizeObserver === "undefined") return;
|
|
2911
2955
|
if (!this.snapPointsRaw.some((p) => p.size === "fit" || p.size === "content"))
|
|
2912
2956
|
return;
|
|
2913
|
-
const targets = [this.handle];
|
|
2914
|
-
if (this.scrollContainer && this.scrollContainer !== this.handle) {
|
|
2915
|
-
targets.push(this.scrollContainer);
|
|
2916
|
-
}
|
|
2917
2957
|
let raf = 0;
|
|
2918
|
-
const
|
|
2958
|
+
const schedule = () => {
|
|
2919
2959
|
if (raf) return;
|
|
2920
2960
|
raf = requestAnimationFrame(() => {
|
|
2921
2961
|
raf = 0;
|
|
2922
2962
|
if (this.destroyed || this.gesture?.isDragging) return;
|
|
2923
2963
|
this.recompute();
|
|
2924
2964
|
});
|
|
2925
|
-
}
|
|
2926
|
-
|
|
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
|
+
}
|
|
2927
3007
|
this.teardowns.add(() => {
|
|
2928
3008
|
ro.disconnect();
|
|
3009
|
+
mo?.disconnect();
|
|
3010
|
+
for (const slot of slots) {
|
|
3011
|
+
slot.removeEventListener("slotchange", onSlotChange);
|
|
3012
|
+
}
|
|
2929
3013
|
if (raf) cancelAnimationFrame(raf);
|
|
2930
3014
|
});
|
|
2931
3015
|
}
|
|
@@ -3459,9 +3543,10 @@ var BottomSheet = (props) => {
|
|
|
3459
3543
|
role="slider"
|
|
3460
3544
|
tabIndex={0}
|
|
3461
3545
|
aria-label="Resize sheet"
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3546
|
+
/>
|
|
3547
|
+
<Show when={props.header}>
|
|
3548
|
+
<div class="bs-header">{props.header}</div>
|
|
3549
|
+
</Show>
|
|
3465
3550
|
<div
|
|
3466
3551
|
class="bs-content"
|
|
3467
3552
|
ref={(el) => contentEl = el}
|
|
@@ -3471,6 +3556,9 @@ var BottomSheet = (props) => {
|
|
|
3471
3556
|
>
|
|
3472
3557
|
{props.children}
|
|
3473
3558
|
</div>
|
|
3559
|
+
<Show when={props.footer}>
|
|
3560
|
+
<div class="bs-footer">{props.footer}</div>
|
|
3561
|
+
</Show>
|
|
3474
3562
|
<span class="bs-sr-only" role="status" aria-live="polite">
|
|
3475
3563
|
{state().activeId}
|
|
3476
3564
|
</span>
|
package/dist/styles.css
CHANGED
|
@@ -244,6 +244,12 @@
|
|
|
244
244
|
margin-left: calc(-1 * (var(--bs-handle-height) + 6px));
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
+
.bs-header {
|
|
248
|
+
flex: 0 0 auto;
|
|
249
|
+
padding: 0 16px 8px;
|
|
250
|
+
background: var(--bs-surface, var(--bs-surface-d));
|
|
251
|
+
}
|
|
252
|
+
|
|
247
253
|
.bs-content {
|
|
248
254
|
flex: 1;
|
|
249
255
|
min-height: 0;
|
|
@@ -261,6 +267,17 @@
|
|
|
261
267
|
background: var(--bs-surface, var(--bs-surface-d));
|
|
262
268
|
}
|
|
263
269
|
|
|
270
|
+
.bs-sheet[data-mode="bottom"]:has(.bs-footer:not([hidden]):has(*)) {
|
|
271
|
+
padding-bottom: 0;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.bs-header:not(:has(*)),
|
|
275
|
+
.bs-footer:not(:has(*)),
|
|
276
|
+
.bs-header[hidden],
|
|
277
|
+
.bs-footer[hidden] {
|
|
278
|
+
display: none;
|
|
279
|
+
}
|
|
280
|
+
|
|
264
281
|
.bs-screen {
|
|
265
282
|
position: absolute;
|
|
266
283
|
inset: 0;
|
package/dist/svelte-core.cjs
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 child of Array.from(scroller.children)) {
|
|
2906
|
+
if (hasSlot && child instanceof HTMLSlotElement) {
|
|
2907
|
+
for (const el of child.assignedElements()) out.push(el);
|
|
2908
|
+
} else {
|
|
2909
|
+
out.push(child);
|
|
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 child of Array.from(scroller.children)) {
|
|
2975
|
+
if (child instanceof HTMLSlotElement && !slots.has(child)) {
|
|
2976
|
+
child.addEventListener("slotchange", onSlotChange);
|
|
2977
|
+
slots.add(child);
|
|
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
|
};
|
package/dist/svelte-core.js
CHANGED
|
@@ -2895,11 +2895,54 @@ var BottomSheetEngine = class {
|
|
|
2895
2895
|
this.updateAriaSlider();
|
|
2896
2896
|
}
|
|
2897
2897
|
}
|
|
2898
|
+
contentTargets() {
|
|
2899
|
+
const scroller = this.scrollContainer;
|
|
2900
|
+
if (!scroller) return [];
|
|
2901
|
+
const hasSlot = typeof HTMLSlotElement !== "undefined";
|
|
2902
|
+
const out = [];
|
|
2903
|
+
for (const child of Array.from(scroller.children)) {
|
|
2904
|
+
if (hasSlot && child instanceof HTMLSlotElement) {
|
|
2905
|
+
for (const el of child.assignedElements()) out.push(el);
|
|
2906
|
+
} else {
|
|
2907
|
+
out.push(child);
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2910
|
+
return out;
|
|
2911
|
+
}
|
|
2912
|
+
measureContentExtent(vertical) {
|
|
2913
|
+
const content = this.scrollContainer;
|
|
2914
|
+
if (!content) return 0;
|
|
2915
|
+
const targets = this.contentTargets();
|
|
2916
|
+
if (targets.length === 0) {
|
|
2917
|
+
return vertical ? content.scrollHeight : content.scrollWidth;
|
|
2918
|
+
}
|
|
2919
|
+
let min = Infinity;
|
|
2920
|
+
let max = -Infinity;
|
|
2921
|
+
for (const el of targets) {
|
|
2922
|
+
const r = el.getBoundingClientRect();
|
|
2923
|
+
if (vertical) {
|
|
2924
|
+
if (r.top < min) min = r.top;
|
|
2925
|
+
if (r.bottom > max) max = r.bottom;
|
|
2926
|
+
} else {
|
|
2927
|
+
if (r.left < min) min = r.left;
|
|
2928
|
+
if (r.right > max) max = r.right;
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
if (!isFinite(min) || !isFinite(max) || max <= min) {
|
|
2932
|
+
return vertical ? content.scrollHeight : content.scrollWidth;
|
|
2933
|
+
}
|
|
2934
|
+
let pad = 0;
|
|
2935
|
+
if (typeof getComputedStyle !== "undefined") {
|
|
2936
|
+
const cs = getComputedStyle(content);
|
|
2937
|
+
pad = vertical ? (parseFloat(cs.paddingTop) || 0) + (parseFloat(cs.paddingBottom) || 0) : (parseFloat(cs.paddingLeft) || 0) + (parseFloat(cs.paddingRight) || 0);
|
|
2938
|
+
}
|
|
2939
|
+
return max - min + pad;
|
|
2940
|
+
}
|
|
2898
2941
|
measureFitSize() {
|
|
2899
2942
|
const vertical = layoutAxis(this.mode) === "height";
|
|
2900
2943
|
const handleSize = vertical ? this.handle.offsetHeight : this.handle.offsetWidth;
|
|
2901
2944
|
const content = this.scrollContainer;
|
|
2902
|
-
const natural = content ? handleSize + (vertical
|
|
2945
|
+
const natural = content ? handleSize + this.measureContentExtent(vertical) : handleSize;
|
|
2903
2946
|
if (typeof window === "undefined") return natural;
|
|
2904
2947
|
const viewport = vertical ? window.innerHeight : window.innerWidth;
|
|
2905
2948
|
return viewport > 0 ? Math.min(natural, viewport) : natural;
|
|
@@ -2908,22 +2951,62 @@ var BottomSheetEngine = class {
|
|
|
2908
2951
|
if (typeof ResizeObserver === "undefined") return;
|
|
2909
2952
|
if (!this.snapPointsRaw.some((p) => p.size === "fit" || p.size === "content"))
|
|
2910
2953
|
return;
|
|
2911
|
-
const targets = [this.handle];
|
|
2912
|
-
if (this.scrollContainer && this.scrollContainer !== this.handle) {
|
|
2913
|
-
targets.push(this.scrollContainer);
|
|
2914
|
-
}
|
|
2915
2954
|
let raf = 0;
|
|
2916
|
-
const
|
|
2955
|
+
const schedule = () => {
|
|
2917
2956
|
if (raf) return;
|
|
2918
2957
|
raf = requestAnimationFrame(() => {
|
|
2919
2958
|
raf = 0;
|
|
2920
2959
|
if (this.destroyed || this.gesture?.isDragging) return;
|
|
2921
2960
|
this.recompute();
|
|
2922
2961
|
});
|
|
2923
|
-
}
|
|
2924
|
-
|
|
2962
|
+
};
|
|
2963
|
+
const ro = new ResizeObserver(schedule);
|
|
2964
|
+
ro.observe(this.handle);
|
|
2965
|
+
const scroller = this.scrollContainer;
|
|
2966
|
+
const observed = /* @__PURE__ */ new Set();
|
|
2967
|
+
const slots = /* @__PURE__ */ new Set();
|
|
2968
|
+
const hasSlot = typeof HTMLSlotElement !== "undefined";
|
|
2969
|
+
const onSlotChange = () => resync();
|
|
2970
|
+
const trackSlots = () => {
|
|
2971
|
+
if (!scroller || !hasSlot) return;
|
|
2972
|
+
for (const child of Array.from(scroller.children)) {
|
|
2973
|
+
if (child instanceof HTMLSlotElement && !slots.has(child)) {
|
|
2974
|
+
child.addEventListener("slotchange", onSlotChange);
|
|
2975
|
+
slots.add(child);
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
};
|
|
2979
|
+
const resync = () => {
|
|
2980
|
+
trackSlots();
|
|
2981
|
+
const targets = this.contentTargets();
|
|
2982
|
+
for (const el of observed) {
|
|
2983
|
+
if (!targets.includes(el)) {
|
|
2984
|
+
ro.unobserve(el);
|
|
2985
|
+
observed.delete(el);
|
|
2986
|
+
}
|
|
2987
|
+
}
|
|
2988
|
+
for (const el of targets) {
|
|
2989
|
+
if (!observed.has(el)) {
|
|
2990
|
+
ro.observe(el);
|
|
2991
|
+
observed.add(el);
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
schedule();
|
|
2995
|
+
};
|
|
2996
|
+
let mo;
|
|
2997
|
+
if (scroller) {
|
|
2998
|
+
resync();
|
|
2999
|
+
if (typeof MutationObserver !== "undefined") {
|
|
3000
|
+
mo = new MutationObserver(resync);
|
|
3001
|
+
mo.observe(scroller, { childList: true });
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
2925
3004
|
this.teardowns.add(() => {
|
|
2926
3005
|
ro.disconnect();
|
|
3006
|
+
mo?.disconnect();
|
|
3007
|
+
for (const slot of slots) {
|
|
3008
|
+
slot.removeEventListener("slotchange", onSlotChange);
|
|
3009
|
+
}
|
|
2927
3010
|
if (raf) cancelAnimationFrame(raf);
|
|
2928
3011
|
});
|
|
2929
3012
|
}
|
|
@@ -3344,6 +3427,38 @@ var BottomSheetEngine = class {
|
|
|
3344
3427
|
}
|
|
3345
3428
|
};
|
|
3346
3429
|
|
|
3430
|
+
// src/core/features/teleport.ts
|
|
3431
|
+
var resolveTeleportTarget = (target) => {
|
|
3432
|
+
if (!target) return null;
|
|
3433
|
+
if (typeof target !== "string") return target;
|
|
3434
|
+
if (typeof document === "undefined") return null;
|
|
3435
|
+
if (target === "body") return document.body;
|
|
3436
|
+
return document.querySelector(target);
|
|
3437
|
+
};
|
|
3438
|
+
var teleportElements = (els, target) => {
|
|
3439
|
+
const records = [];
|
|
3440
|
+
for (const el of els) {
|
|
3441
|
+
if (!el || el.parentNode === target) continue;
|
|
3442
|
+
records.push({ el, parent: el.parentNode, next: el.nextSibling });
|
|
3443
|
+
target.appendChild(el);
|
|
3444
|
+
}
|
|
3445
|
+
return () => {
|
|
3446
|
+
for (let i = records.length - 1; i >= 0; i--) {
|
|
3447
|
+
const { el, parent, next } = records[i];
|
|
3448
|
+
if (parent && parent.isConnected) {
|
|
3449
|
+
const before = next && next.parentNode === parent ? next : null;
|
|
3450
|
+
try {
|
|
3451
|
+
parent.insertBefore(el, before);
|
|
3452
|
+
} catch {
|
|
3453
|
+
el.parentNode?.removeChild(el);
|
|
3454
|
+
}
|
|
3455
|
+
} else {
|
|
3456
|
+
el.parentNode?.removeChild(el);
|
|
3457
|
+
}
|
|
3458
|
+
}
|
|
3459
|
+
};
|
|
3460
|
+
};
|
|
3461
|
+
|
|
3347
3462
|
// src/svelte/useBottomSheet.svelte.ts
|
|
3348
3463
|
var SSR_STATE = Object.freeze({
|
|
3349
3464
|
size: 0,
|
|
@@ -3357,9 +3472,21 @@ function createBottomSheet(opts) {
|
|
|
3357
3472
|
const pending = [];
|
|
3358
3473
|
const attach = (refs) => {
|
|
3359
3474
|
if (engine) engine.destroy();
|
|
3360
|
-
const {
|
|
3475
|
+
const {
|
|
3476
|
+
onSnap,
|
|
3477
|
+
teleportTo,
|
|
3478
|
+
backdropColor,
|
|
3479
|
+
backdropOpacity,
|
|
3480
|
+
...engineOpts
|
|
3481
|
+
} = opts;
|
|
3361
3482
|
const created = new BottomSheetEngine({ ...engineOpts, ...refs });
|
|
3362
3483
|
engine = created;
|
|
3484
|
+
const target = resolveTeleportTarget(teleportTo);
|
|
3485
|
+
const restoreTeleport = target ? teleportElements([refs.backdrop, refs.scrim, refs.element], target) : null;
|
|
3486
|
+
if (backdropColor !== void 0) created.setScrimColor(backdropColor);
|
|
3487
|
+
if (backdropOpacity !== void 0) {
|
|
3488
|
+
created.setBackdropRange([0, backdropOpacity]);
|
|
3489
|
+
}
|
|
3363
3490
|
if (onSnap) {
|
|
3364
3491
|
created.on("snap", (payload) => onSnap(payload.id));
|
|
3365
3492
|
}
|
|
@@ -3368,6 +3495,7 @@ function createBottomSheet(opts) {
|
|
|
3368
3495
|
}
|
|
3369
3496
|
pending.length = 0;
|
|
3370
3497
|
return () => {
|
|
3498
|
+
restoreTeleport?.();
|
|
3371
3499
|
created.destroy();
|
|
3372
3500
|
if (engine === created) engine = null;
|
|
3373
3501
|
};
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
returnFocusTo?: HTMLElement | string | (() => HTMLElement | null);
|
|
40
40
|
ariaLabel?: string;
|
|
41
41
|
header?: Snippet<[EngineState & { activeId: TId }]>;
|
|
42
|
+
footer?: Snippet<[EngineState & { activeId: TId }]>;
|
|
42
43
|
leftButton?: Snippet;
|
|
43
44
|
rightButton?: Snippet;
|
|
44
45
|
screen?: Snippet;
|
|
@@ -82,6 +83,7 @@
|
|
|
82
83
|
returnFocusTo,
|
|
83
84
|
ariaLabel = "Bottom sheet",
|
|
84
85
|
header,
|
|
86
|
+
footer,
|
|
85
87
|
leftButton,
|
|
86
88
|
rightButton,
|
|
87
89
|
screen,
|
|
@@ -284,13 +286,13 @@
|
|
|
284
286
|
aria-valuemax={Math.max(0, allowedIds.length - 1)}
|
|
285
287
|
aria-valuenow={Math.max(0, activeIdx)}
|
|
286
288
|
aria-valuetext={viewState.activeId}
|
|
287
|
-
>
|
|
288
|
-
|
|
289
|
-
</div>
|
|
289
|
+
></div>
|
|
290
|
+
{#if header}<div class="bs-header">{@render header(viewState)}</div>{/if}
|
|
290
291
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
291
292
|
<div class="bs-content" bind:this={contentEl} tabindex="0" role="region" aria-label="Sheet content">
|
|
292
293
|
{#if children}{@render children()}{/if}
|
|
293
294
|
</div>
|
|
295
|
+
{#if footer}<div class="bs-footer">{@render footer(viewState)}</div>{/if}
|
|
294
296
|
<span class="bs-sr-only" role="status" aria-live="polite">
|
|
295
297
|
{viewState.activeId}
|
|
296
298
|
</span>
|