@svnrnns/react-bottom-sheets 1.0.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/index.js ADDED
@@ -0,0 +1,727 @@
1
+ import { jsx as D, Fragment as pe, jsxs as Zt } from "react/jsx-runtime";
2
+ import { createContext as Jt, useContext as Qt, useRef as B, useCallback as y, useEffect as W, useState as Y, useLayoutEffect as zt, useSyncExternalStore as be } from "react";
3
+ import { flushSync as ve, createPortal as Se } from "react-dom";
4
+ let ye = 0;
5
+ function Ce() {
6
+ return Symbol(`bottom-sheet-${++ye}`);
7
+ }
8
+ let Q = [];
9
+ const Ct = /* @__PURE__ */ new Set();
10
+ function Pt() {
11
+ Ct.forEach((t) => t());
12
+ }
13
+ function wt() {
14
+ return Q;
15
+ }
16
+ function we(t) {
17
+ return Ct.add(t), () => Ct.delete(t);
18
+ }
19
+ function xe(t) {
20
+ const e = Ce(), n = { ...t, id: e };
21
+ return Q = [...Q, n], Pt(), e;
22
+ }
23
+ function j(t) {
24
+ Q = Q.filter((e) => e.id !== t), Pt();
25
+ }
26
+ function Ee() {
27
+ Q = [], Pt();
28
+ }
29
+ const st = /* @__PURE__ */ new Map(), xt = /* @__PURE__ */ new Map(), Et = /* @__PURE__ */ new Set();
30
+ function Te(t, e) {
31
+ st.set(t, e);
32
+ const n = xt.get(t);
33
+ n !== void 0 && (xt.delete(t), e.snapToIndex(n)), Et.has(t) && (Et.delete(t), e.openFully());
34
+ }
35
+ function Pe(t) {
36
+ st.delete(t);
37
+ }
38
+ function Fe(t) {
39
+ return st.get(t);
40
+ }
41
+ function Re(t, e) {
42
+ const n = st.get(t);
43
+ n ? n.snapToIndex(e) : xt.set(t, e);
44
+ }
45
+ function Ne(t) {
46
+ const e = st.get(t);
47
+ e ? e.openFully() : Et.add(t);
48
+ }
49
+ function Oe(t, e, n) {
50
+ const o = t.trim();
51
+ if (!o) return null;
52
+ if (o.endsWith("%")) {
53
+ const s = parseFloat(o.slice(0, -1));
54
+ return Number.isNaN(s) || s < 0 || s > 100 ? null : s / 100 * e;
55
+ }
56
+ if (o.endsWith("px")) {
57
+ const s = parseFloat(o.slice(0, -2));
58
+ return Number.isNaN(s) ? null : s;
59
+ }
60
+ if (o.endsWith("rem")) {
61
+ const s = parseFloat(o.slice(0, -3));
62
+ return Number.isNaN(s) ? null : s * n;
63
+ }
64
+ const r = parseFloat(o);
65
+ return Number.isNaN(r) ? null : r;
66
+ }
67
+ function Be() {
68
+ if (typeof document > "u") return 16;
69
+ const t = document.documentElement, e = getComputedStyle(t).fontSize, n = parseFloat(e);
70
+ return Number.isNaN(n) ? 16 : n;
71
+ }
72
+ function De(t, e) {
73
+ if (!(t != null && t.length)) return [];
74
+ const n = Be(), o = t.map((s) => Oe(s, e, n)).filter((s) => s !== null && s >= 0), r = [...new Set(o)];
75
+ return r.sort((s, c) => s - c), r;
76
+ }
77
+ const Me = 80, Ie = 0.35, Vt = 0.08;
78
+ function Ut(t) {
79
+ return Vt + (Ie - Vt) / (1 + t / Me);
80
+ }
81
+ function St(t, e, n) {
82
+ if (t >= e && t <= n) return t;
83
+ if (t < e) {
84
+ const s = e - t, c = Ut(s);
85
+ return e - s * c;
86
+ }
87
+ const o = t - n, r = Ut(o);
88
+ return n + o * r;
89
+ }
90
+ const qt = 0.5, Gt = 0.6, Ye = 0.5;
91
+ function ke(t, e, n, o, r = 0) {
92
+ const s = e + r;
93
+ if (n.length === 0)
94
+ return t >= s * Gt ? { action: "close" } : { action: "snap", targetY: 0 };
95
+ const c = [...n].sort((S, z) => S - z), m = c[0], d = e - m, C = e + r, f = d, E = C - f, v = f + Gt * E;
96
+ if (o > qt) {
97
+ if (t >= v)
98
+ return { action: "close" };
99
+ const S = Le(t, c, e);
100
+ if (S !== void 0)
101
+ return { action: "snap", targetY: e - S, targetIndex: n.indexOf(S) };
102
+ }
103
+ if (o < -qt) {
104
+ const S = Ae(t, c, e);
105
+ if (S !== void 0) {
106
+ const z = e - S, it = c.indexOf(S);
107
+ return { action: "snap", targetY: z, targetIndex: it };
108
+ }
109
+ }
110
+ const F = $e(t, c, e);
111
+ if (He(t, F, c, e) >= Ye && F < c.length - 1) {
112
+ const S = c[F + 1];
113
+ return { action: "snap", targetY: e - S, targetIndex: F + 1 };
114
+ }
115
+ if (F > 0 || t < f) {
116
+ const S = c[F];
117
+ return { action: "snap", targetY: e - S, targetIndex: F };
118
+ }
119
+ return t >= v ? { action: "close" } : { action: "snap", targetY: d, targetIndex: 0 };
120
+ }
121
+ function Le(t, e, n) {
122
+ const o = n - t;
123
+ for (let r = e.length - 1; r >= 0; r--)
124
+ if (e[r] < o) return e[r];
125
+ }
126
+ function Ae(t, e, n) {
127
+ const o = n - t;
128
+ for (let r = 0; r < e.length; r++)
129
+ if (e[r] > o) return e[r];
130
+ }
131
+ function $e(t, e, n) {
132
+ const o = n - t;
133
+ let r = 0, s = 1 / 0;
134
+ for (let c = 0; c < e.length; c++) {
135
+ const m = Math.abs(e[c] - o);
136
+ m < s && (s = m, r = c);
137
+ }
138
+ return r;
139
+ }
140
+ function He(t, e, n, o) {
141
+ if (e >= n.length - 1) return 0;
142
+ const r = o - t, s = n[e], m = n[e + 1] - s;
143
+ if (m <= 0) return 0;
144
+ const d = (r - s) / m;
145
+ return Math.max(0, Math.min(1, d));
146
+ }
147
+ const te = Jt(null);
148
+ function _e() {
149
+ return Qt(te);
150
+ }
151
+ function yt(t, e) {
152
+ let n = t;
153
+ for (; n && n !== document.body; ) {
154
+ if (n instanceof HTMLElement && e.has(n))
155
+ return { el: n, getCanDrag: e.get(n) };
156
+ n = n.parentNode;
157
+ }
158
+ return null;
159
+ }
160
+ function We() {
161
+ const t = B(/* @__PURE__ */ new Map()), e = y((s, c) => (t.current.set(s, c), () => {
162
+ t.current.delete(s);
163
+ }), []), n = y((s) => yt(s, t.current) !== null, []), o = y((s) => {
164
+ const c = yt(s, t.current);
165
+ return c ? !c.getCanDrag() : !1;
166
+ }, []), r = y((s) => {
167
+ const c = yt(s, t.current);
168
+ return c ? c.getCanDrag() : !1;
169
+ }, []);
170
+ return {
171
+ registerScrollContainer: e,
172
+ isInScrollContainer: n,
173
+ shouldBlockGestures: o,
174
+ canCaptureForDownSwipe: r
175
+ };
176
+ }
177
+ const ze = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])', Ve = "modals-close";
178
+ function Tt(t) {
179
+ return Array.from(t.querySelectorAll(ze));
180
+ }
181
+ function Ue(t) {
182
+ return Tt(t).filter(
183
+ (e) => !e.classList.contains(Ve)
184
+ );
185
+ }
186
+ function qe(t, e, n = !1) {
187
+ W(() => {
188
+ if (!e || !t.current) return;
189
+ const o = t.current, r = document.activeElement;
190
+ if (!n) {
191
+ const c = Ue(o), m = Tt(o), d = c[0] ?? m[0];
192
+ d ? d.focus() : (o.setAttribute("tabindex", "-1"), o.focus());
193
+ }
194
+ function s(c) {
195
+ if (c.key !== "Tab") return;
196
+ const m = Tt(o), d = m[0], C = m[m.length - 1];
197
+ c.shiftKey ? document.activeElement === d && C && (c.preventDefault(), C.focus()) : document.activeElement === C && d && (c.preventDefault(), d.focus());
198
+ }
199
+ return o.addEventListener("keydown", s), () => {
200
+ o.removeEventListener("keydown", s), r && typeof r.focus == "function" && r.focus();
201
+ };
202
+ }, [e, n]);
203
+ }
204
+ const Ge = typeof window < "u" ? () => window.innerHeight : () => 800, Xe = 5;
205
+ function ft(t, e) {
206
+ return typeof document > "u" ? e : getComputedStyle(document.documentElement).getPropertyValue(t).trim() || e;
207
+ }
208
+ function _() {
209
+ const t = ft("--bottom-sheet-duration", "0.5s"), e = t.match(/^([\d.]+)s$/);
210
+ if (e) return parseFloat(e[1]) * 1e3;
211
+ const n = t.match(/^([\d.]+)ms$/);
212
+ return n ? parseFloat(n[1]) : 500;
213
+ }
214
+ function je(t, e, n) {
215
+ const o = 1 - t;
216
+ return 3 * o * o * t * e + 3 * o * t * t * n + t * t * t;
217
+ }
218
+ function Ke(t, e) {
219
+ const n = e.match(/cubic-bezier\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)/);
220
+ if (!n) return t;
221
+ const o = n.map(Number), r = o[2], s = o[4];
222
+ return je(t, r, s);
223
+ }
224
+ function Xt(t) {
225
+ return t === 0 ? 1 : Math.max(0.5, 0.9 - (t - 1) * 0.05);
226
+ }
227
+ function jt(t) {
228
+ return t === 0 ? 0 : 12 + (t - 1) * 8;
229
+ }
230
+ function Ze({ descriptor: t, index: e, isTop: n, stackDepth: o }) {
231
+ const r = Qt(ee), {
232
+ id: s,
233
+ component: c,
234
+ props: m,
235
+ height: d,
236
+ width: C,
237
+ snapPoint: f,
238
+ className: E,
239
+ onClose: v,
240
+ enableBackdrop: F,
241
+ enableClickBackdropToClose: dt,
242
+ disableEsc: S,
243
+ gestureOnlyOnHandler: z,
244
+ disableSwipeDownToClose: it
245
+ } = t, ct = C ?? (r == null ? void 0 : r.defaultWidth), Ft = ct == null ? void 0 : typeof ct == "number" ? `${ct}px` : ct, k = Ge(), M = typeof document < "u" && parseFloat(ft("--bottom-sheet-close-extra-offset", "0")) || 0, ne = !!(f != null && f.length), I = d == null && !ne, V = B(null), at = B(null), U = B(null), q = We(), [h, tt] = Y(() => d != null ? Kt(d) : I ? 0 : k), [Rt, Nt] = Y(!I), lt = h + M, p = De(f, k).filter((i) => i <= h).sort((i, l) => i - l), et = p.length > 0 ? h - p[0] : 0, [G, R] = Y(
246
+ () => I ? k : p.length > 0 ? lt : 0
247
+ ), [K, X] = Y(!1), [ut, g] = Y(!1), [ht, re] = Y(!1), [oe, mt] = Y(0), N = B(null), L = B(null), P = B(!1), A = B(null);
248
+ zt(() => {
249
+ p.length > 0 && R(lt);
250
+ }, []), W(() => {
251
+ var w;
252
+ if (d != null) {
253
+ tt(Kt(d)), Nt(!0);
254
+ return;
255
+ }
256
+ if (!I) {
257
+ const b = U.current;
258
+ if (!b) return;
259
+ const T = new ResizeObserver(() => {
260
+ const O = b.getBoundingClientRect().height;
261
+ tt((H) => Math.min(Math.max(H, O), k));
262
+ });
263
+ T.observe(b);
264
+ const x = b.getBoundingClientRect().height;
265
+ return tt((O) => Math.min(Math.max(O, x), k)), () => T.disconnect();
266
+ }
267
+ if (!V.current) return;
268
+ const l = () => {
269
+ const b = V.current, T = at.current, x = U.current;
270
+ if (!b || !T || !x) return;
271
+ if (h === 0) {
272
+ const Wt = Math.min(b.getBoundingClientRect().height, k);
273
+ Wt > 0 && (tt(Wt), Nt(!0));
274
+ return;
275
+ }
276
+ const O = getComputedStyle(b), H = parseFloat(O.paddingTop) || 0, vt = parseFloat(O.paddingBottom) || 0, J = O.gap || "0.5rem", me = J.endsWith("rem") ? parseFloat(J) * (parseFloat(getComputedStyle(document.documentElement).fontSize) || 16) : parseFloat(J) || 8, Ht = x.firstElementChild, ge = Ht ? Ht.getBoundingClientRect().height : x.scrollHeight || x.getBoundingClientRect().height, _t = Math.min(
277
+ H + vt + T.offsetHeight + me + ge,
278
+ k
279
+ );
280
+ _t > 0 && (A.current && (clearTimeout(A.current), A.current = null), tt(_t), g(!0), A.current = setTimeout(() => {
281
+ A.current = null, g(!1);
282
+ }, _()));
283
+ }, u = new ResizeObserver(l);
284
+ U.current && u.observe(U.current);
285
+ const a = (w = U.current) == null ? void 0 : w.firstElementChild;
286
+ return a && u.observe(a), at.current && u.observe(at.current), u.observe(V.current), requestAnimationFrame(l), () => {
287
+ u.disconnect(), A.current && (clearTimeout(A.current), A.current = null);
288
+ };
289
+ }, [d, k, I, h]), W(() => {
290
+ ht || I && !Rt || (re(!0), R(lt), requestAnimationFrame(() => {
291
+ mt(1), g(!0), R(et);
292
+ const i = _();
293
+ setTimeout(() => g(!1), i);
294
+ }));
295
+ }, [ht, I, Rt, et, lt, h]);
296
+ const nt = y(() => {
297
+ if (ut) return;
298
+ mt(0), g(!0);
299
+ const i = _();
300
+ if (R(h + M), n && r) {
301
+ r.setTopSheetClosingProgress(0);
302
+ const l = Date.now(), u = () => {
303
+ const a = Date.now() - l, w = Math.min(1, a / i);
304
+ r == null || r.setTopSheetClosingProgress(w), w < 1 ? requestAnimationFrame(u) : (v == null || v(), j(s), r == null || r.setTopSheetClosingProgress(null), g(!1));
305
+ };
306
+ requestAnimationFrame(u);
307
+ } else {
308
+ const l = setTimeout(() => {
309
+ v == null || v(), j(s), g(!1);
310
+ }, i);
311
+ return () => clearTimeout(l);
312
+ }
313
+ }, [s, h, M, v, ut, n, r]), rt = y(
314
+ (i) => {
315
+ if (ut) return;
316
+ if (p.length === 0) {
317
+ R(0);
318
+ return;
319
+ }
320
+ const l = Math.max(0, Math.min(i, p.length - 1)), u = h - p[l];
321
+ g(!0), R(u);
322
+ const a = _(), w = setTimeout(() => g(!1), a);
323
+ return () => clearTimeout(w);
324
+ },
325
+ [p, h, ut]
326
+ ), Ot = y(() => {
327
+ if (p.length > 0)
328
+ rt(p.length - 1);
329
+ else {
330
+ g(!0), R(0);
331
+ const i = setTimeout(() => g(!1), _());
332
+ return () => clearTimeout(i);
333
+ }
334
+ }, [p.length, rt]);
335
+ zt(() => {
336
+ if (r)
337
+ return r.registerController(s, { snapToIndex: rt, openFully: Ot, close: nt }), () => r.unregisterController(s);
338
+ }, [s, r, rt, Ot, nt]), W(() => {
339
+ if (!n) return;
340
+ const i = (l) => {
341
+ l.key === "Escape" && !S && (l.preventDefault(), ve(() => {
342
+ X(!1), g(!1);
343
+ }), N.current = null, L.current = null, nt());
344
+ };
345
+ return window.addEventListener("keydown", i), () => window.removeEventListener("keydown", i);
346
+ }, [n, S, nt]), qe(V, n && ht);
347
+ const Bt = y((i) => {
348
+ if (P.current && V.current && i != null) {
349
+ try {
350
+ V.current.releasePointerCapture(i);
351
+ } catch {
352
+ }
353
+ X(!1);
354
+ }
355
+ N.current = null, L.current = null, P.current = !1;
356
+ }, []), se = y(
357
+ (i) => {
358
+ var a;
359
+ if (i.button !== 0) return;
360
+ const l = i.pointerType === "touch", u = ((a = U.current) == null ? void 0 : a.contains(i.target)) ?? !1;
361
+ if (l && u) {
362
+ if (q.isInScrollContainer(i.target))
363
+ return;
364
+ i.currentTarget.setPointerCapture(i.pointerId), P.current = !0, X(!0);
365
+ }
366
+ },
367
+ [q]
368
+ ), ie = y(
369
+ (i) => {
370
+ if (i.button !== 0) return;
371
+ const l = i.pointerId;
372
+ N.current = { y: i.clientY, sheetY: G, time: Date.now() }, L.current = { y: i.clientY, time: Date.now() };
373
+ const u = (a) => {
374
+ a.pointerId === l && (window.removeEventListener("pointerup", u), window.removeEventListener("pointercancel", u), Bt(l));
375
+ };
376
+ window.addEventListener("pointerup", u), window.addEventListener("pointercancel", u);
377
+ },
378
+ [G, Bt]
379
+ ), ce = y(
380
+ (i) => {
381
+ if (!N.current) return;
382
+ if (i.buttons === 0) {
383
+ P.current && (i.currentTarget.releasePointerCapture(i.pointerId), X(!1)), N.current = null, L.current = null, P.current = !1;
384
+ return;
385
+ }
386
+ L.current = { y: i.clientY, time: Date.now() };
387
+ const l = i.clientY - N.current.y, u = i.pointerType === "touch" ? 1 : Xe;
388
+ if (!P.current && Math.abs(l) > u) {
389
+ const T = i.target;
390
+ if (q.isInScrollContainer(T)) {
391
+ if (q.shouldBlockGestures(T) || !q.canCaptureForDownSwipe(T) || l <= 0) return;
392
+ i.preventDefault();
393
+ }
394
+ i.currentTarget.setPointerCapture(i.pointerId), P.current = !0, X(!0);
395
+ }
396
+ if (!P.current) return;
397
+ let a = N.current.sheetY + l;
398
+ const w = 0, b = h + M;
399
+ if (p.length > 0) {
400
+ const T = Math.max(...p), x = h - T;
401
+ a > b || a < x ? a = St(a, x, b) : a = Math.max(x, Math.min(b, a));
402
+ } else
403
+ a > b || a < w ? a = St(a, w, b) : a = Math.max(w, Math.min(b, a));
404
+ R(a);
405
+ },
406
+ [h, M, p, q]
407
+ ), ae = y(
408
+ (i) => {
409
+ if (!N.current) return;
410
+ const l = P.current;
411
+ l && (i.currentTarget.releasePointerCapture(i.pointerId), X(!1));
412
+ const u = L.current, a = u && u.time !== N.current.time ? (i.clientY - u.y) / (Date.now() - u.time) : 0;
413
+ if (N.current = null, L.current = null, P.current = !1, !l) return;
414
+ const w = ke(
415
+ G,
416
+ h,
417
+ p,
418
+ a,
419
+ M
420
+ );
421
+ if (w.action === "close") {
422
+ if (it) {
423
+ const O = p.length > 0 ? h - p[0] : 0;
424
+ g(!0), R(O);
425
+ const H = _();
426
+ setTimeout(() => g(!1), H);
427
+ return;
428
+ }
429
+ mt(0), g(!0), R(h + M);
430
+ const x = _();
431
+ if (n && r) {
432
+ r.setTopSheetClosingProgress(0);
433
+ const O = Date.now(), H = () => {
434
+ const vt = Date.now() - O, J = Math.min(1, vt / x);
435
+ r == null || r.setTopSheetClosingProgress(J), J < 1 ? requestAnimationFrame(H) : (v == null || v(), j(s), r == null || r.setTopSheetClosingProgress(null), g(!1));
436
+ };
437
+ requestAnimationFrame(H);
438
+ } else
439
+ setTimeout(() => {
440
+ v == null || v(), j(s), g(!1);
441
+ }, x);
442
+ return;
443
+ }
444
+ const b = w.targetY ?? 0;
445
+ g(!0), R(b);
446
+ const T = _();
447
+ setTimeout(() => g(!1), T);
448
+ },
449
+ [
450
+ G,
451
+ h,
452
+ p,
453
+ M,
454
+ s,
455
+ v,
456
+ it,
457
+ n,
458
+ r
459
+ ]
460
+ ), le = y((i) => {
461
+ P.current && (i.currentTarget.releasePointerCapture(i.pointerId), X(!1)), N.current = null, L.current = null, P.current = !1;
462
+ }, []);
463
+ W(() => {
464
+ if (!K) return;
465
+ const i = document.body.style.userSelect;
466
+ return document.body.style.userSelect = "none", () => {
467
+ document.body.style.userSelect = i;
468
+ };
469
+ }, [K]);
470
+ const Dt = {
471
+ onPointerDownCapture: se,
472
+ onPointerDown: ie,
473
+ onPointerMove: ce,
474
+ onPointerUp: ae,
475
+ onPointerCancel: le
476
+ }, ot = ft("--bottom-sheet-duration", "0.5s"), Z = ft("--bottom-sheet-easing", "cubic-bezier(0.32, 0.72, 0, 1)"), Mt = (r == null ? void 0 : r.topSheetClosingProgress) ?? null, $ = o >= 1 && Mt != null, gt = $ ? Ke(Mt, Z) : 0, ue = K || $ ? "none" : `transform ${ot} ${Z}, height ${ot} ${Z}, transform-origin ${ot} ${Z}`, pt = Xt(o), fe = Xt(o - 1), bt = jt(o), de = jt(o - 1), It = $ ? pt + (fe - pt) * gt : pt, Yt = $ ? bt + (de - bt) * gt : bt, kt = h + M, he = kt > et ? Math.max(0, Math.min(1, (G - et) / (kt - et))) : 0, Lt = K ? 1 - he : oe, At = K ? "none" : `opacity ${ot} ${Z}`, $t = B(null);
477
+ return W(() => {
478
+ if (!n || !r) return;
479
+ const i = F ? Lt : 0, l = At, u = F && dt ? "auto" : "none", a = $t.current;
480
+ a && a.opacity === i && a.transition === l && a.pointerEvents === u || ($t.current = { opacity: i, transition: l, pointerEvents: u }, r.setOverlayStyle({ opacity: i, transition: l, pointerEvents: u }));
481
+ }, [n, r, F, dt, Lt, At]), /* @__PURE__ */ D(pe, { children: /* @__PURE__ */ Zt(
482
+ "div",
483
+ {
484
+ ref: V,
485
+ role: n ? "dialog" : void 0,
486
+ "aria-modal": n ? !0 : void 0,
487
+ className: `bottom-sheet${K ? " dragging" : ""}${o > 0 ? " stacked" : ""} ${E ?? ""}`.trim(),
488
+ ...o === 0 && !z ? Dt : {},
489
+ style: {
490
+ position: "fixed",
491
+ ...Ft ? {
492
+ width: Ft,
493
+ maxWidth: "100%",
494
+ left: "50%",
495
+ transform: `translateX(-50%) translateY(${G}px) scale(${It}) translateY(-${Yt}%)`,
496
+ transformOrigin: "bottom center"
497
+ } : {
498
+ left: 0,
499
+ right: 0,
500
+ transform: `translateY(${G}px) scale(${It}) translateY(-${Yt}%)`,
501
+ transformOrigin: "bottom center"
502
+ },
503
+ bottom: 0,
504
+ ...I ? { height: h === 0 ? "auto" : h, maxHeight: "100vh" } : { height: h, maxHeight: "100vh" },
505
+ "--bottom-sheet-height": `${h}px`,
506
+ transition: ue,
507
+ zIndex: e + 1,
508
+ display: "flex",
509
+ flexDirection: "column",
510
+ background: "var(--bottom-sheet-bg)",
511
+ borderRadius: "var(--bottom-sheet-border-radius)",
512
+ boxShadow: "var(--bottom-sheet-shadow)",
513
+ padding: "var(--bottom-sheet-padding)"
514
+ },
515
+ children: [
516
+ /* @__PURE__ */ D(
517
+ "div",
518
+ {
519
+ ref: at,
520
+ className: "bottom-sheet-handler",
521
+ ...o === 0 && z ? Dt : {},
522
+ style: {
523
+ flexShrink: 0,
524
+ display: "flex",
525
+ alignItems: "center",
526
+ justifyContent: "center",
527
+ padding: "var(--bottom-sheet-handler-padding)",
528
+ gap: "var(--bottom-sheet-gap)"
529
+ },
530
+ children: /* @__PURE__ */ D(
531
+ "div",
532
+ {
533
+ style: {
534
+ width: "var(--bottom-sheet-handler-width)",
535
+ height: "var(--bottom-sheet-handler-height)",
536
+ borderRadius: "var(--bottom-sheet-handler-border-radius)",
537
+ background: "var(--bottom-sheet-handler-bg)"
538
+ }
539
+ }
540
+ )
541
+ }
542
+ ),
543
+ /* @__PURE__ */ D(
544
+ "div",
545
+ {
546
+ ref: U,
547
+ className: "bottom-sheet-content",
548
+ style: {
549
+ ...I && h === 0 ? { flex: "0 0 auto", overflow: "visible", minHeight: 0 } : { flex: 1, overflow: "auto", minHeight: 0 }
550
+ },
551
+ children: /* @__PURE__ */ D(te.Provider, { value: q, children: /* @__PURE__ */ D(
552
+ c,
553
+ {
554
+ ...m,
555
+ closeDrawer: nt,
556
+ snapToIndex: rt
557
+ }
558
+ ) })
559
+ }
560
+ ),
561
+ /* @__PURE__ */ D(
562
+ "div",
563
+ {
564
+ className: "bottom-sheet-stack-overlay",
565
+ "aria-hidden": !0,
566
+ style: {
567
+ position: "absolute",
568
+ inset: 0,
569
+ background: "var(--bottom-sheet-stack-overlay-bg)",
570
+ borderRadius: "inherit",
571
+ pointerEvents: o === 0 && !$ ? "none" : "auto",
572
+ opacity: $ && o === 1 ? 1 - gt : o === 0 ? 0 : 1,
573
+ transition: $ ? "none" : `opacity ${ot} ${Z}`,
574
+ ...o > 0 || $ ? { cursor: "default" } : {}
575
+ }
576
+ }
577
+ )
578
+ ]
579
+ }
580
+ ) });
581
+ }
582
+ function Kt(t) {
583
+ if (typeof t == "number") return t;
584
+ if (typeof document > "u") return 400;
585
+ const e = t.trim();
586
+ if (e.endsWith("%"))
587
+ return window.innerHeight * parseFloat(e.slice(0, -1)) / 100;
588
+ if (e.endsWith("px")) return parseFloat(e.slice(0, -2)) || 400;
589
+ if (e.endsWith("rem")) {
590
+ const n = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
591
+ return parseFloat(e.slice(0, -3)) * n || 400;
592
+ }
593
+ return parseFloat(e) || 400;
594
+ }
595
+ const ee = Jt(null);
596
+ function Je() {
597
+ return be(we, wt, wt);
598
+ }
599
+ function on({ width: t } = {}) {
600
+ const e = Je(), [n, o] = Y(null), [r, s] = Y({ opacity: 0, transition: "opacity 0.5s cubic-bezier(0.32, 0.72, 0, 1)", pointerEvents: "none" }), c = y(
601
+ (f, E) => {
602
+ Te(f, E);
603
+ },
604
+ []
605
+ ), m = y((f) => {
606
+ Pe(f);
607
+ }, []), d = typeof document < "u" ? document.body : null;
608
+ return e.length > 0 && d ? /* @__PURE__ */ D(ee.Provider, { value: { registerController: c, unregisterController: m, defaultWidth: t, setOverlayStyle: s, topSheetClosingProgress: n, setTopSheetClosingProgress: o }, children: Se(
609
+ /* @__PURE__ */ Zt("div", { className: "bottom-sheets-portal", "aria-hidden": "false", children: [
610
+ e.length > 0 && /* @__PURE__ */ D(
611
+ "div",
612
+ {
613
+ className: "bottom-sheet-overlay",
614
+ style: {
615
+ position: "fixed",
616
+ inset: 0,
617
+ background: "var(--bottom-sheet-overlay-bg)",
618
+ backdropFilter: "var(--bottom-sheet-overlay-blur-filter)",
619
+ zIndex: 0,
620
+ pointerEvents: r.pointerEvents ?? "none",
621
+ opacity: r.opacity,
622
+ transition: r.transition
623
+ },
624
+ onClick: () => {
625
+ var E;
626
+ const f = e[e.length - 1];
627
+ f != null && f.enableClickBackdropToClose && ((E = Fe(f.id)) == null || E.close());
628
+ },
629
+ "aria-hidden": !0
630
+ }
631
+ ),
632
+ e.map((f, E) => /* @__PURE__ */ D(
633
+ Ze,
634
+ {
635
+ descriptor: f,
636
+ index: E,
637
+ isTop: E === e.length - 1,
638
+ stackDepth: e.length - 1 - E
639
+ },
640
+ f.id.toString()
641
+ ))
642
+ ] }),
643
+ d
644
+ ) }) : null;
645
+ }
646
+ function sn(t) {
647
+ const e = {
648
+ component: t.component,
649
+ props: t.props ?? {},
650
+ height: t.height,
651
+ width: t.width,
652
+ snapPoint: t.snapPoint ?? t.snapPoints,
653
+ className: t.className,
654
+ onClose: t.onClose,
655
+ enableClickBackdropToClose: t.enableClickBackdropToClose,
656
+ enableBackdrop: t.enableBackdrop,
657
+ disableEsc: t.disableEsc,
658
+ gestureOnlyOnHandler: t.gestureOnlyOnHandler,
659
+ disableSwipeDownToClose: t.disableSwipeDownToClose
660
+ }, n = xe(e);
661
+ return {
662
+ id: n,
663
+ close: () => j(n),
664
+ snapToIndex: (o) => Re(n, o),
665
+ openFully: () => Ne(n)
666
+ };
667
+ }
668
+ function cn() {
669
+ const t = wt();
670
+ if (t.length > 0) {
671
+ const e = t[t.length - 1];
672
+ j(e.id);
673
+ }
674
+ }
675
+ function an(t) {
676
+ j(t);
677
+ }
678
+ function ln() {
679
+ Ee();
680
+ }
681
+ function un({ children: t, className: e, style: n }) {
682
+ const o = B(null), r = B(0), s = _e();
683
+ return W(() => {
684
+ if (!s || !o.current) return;
685
+ const c = o.current, m = () => c.scrollTop === 0;
686
+ return s.registerScrollContainer(c, m);
687
+ }, [s]), W(() => {
688
+ const c = o.current;
689
+ if (!c) return;
690
+ const m = (C) => {
691
+ var f;
692
+ r.current = ((f = C.touches[0]) == null ? void 0 : f.clientY) ?? 0;
693
+ }, d = (C) => {
694
+ if (c.scrollTop > 0 || !C.cancelable) return;
695
+ const f = C.touches[0];
696
+ if (!f) return;
697
+ f.clientY - r.current > 8 && C.preventDefault();
698
+ };
699
+ return c.addEventListener("touchstart", m, { passive: !0 }), c.addEventListener("touchmove", d, { passive: !1, capture: !0 }), () => {
700
+ c.removeEventListener("touchstart", m), c.removeEventListener("touchmove", d, { capture: !0 });
701
+ };
702
+ }, []), /* @__PURE__ */ D(
703
+ "div",
704
+ {
705
+ ref: o,
706
+ className: e,
707
+ style: {
708
+ flex: 1,
709
+ minHeight: 0,
710
+ overflow: "auto",
711
+ WebkitOverflowScrolling: "touch",
712
+ overscrollBehaviorY: "contain",
713
+ ...n
714
+ },
715
+ children: t
716
+ }
717
+ );
718
+ }
719
+ export {
720
+ on as BottomSheetRoot,
721
+ un as BottomSheetScrollable,
722
+ ln as closeAllBottomSheets,
723
+ an as closeBottomSheet,
724
+ cn as popBottomSheet,
725
+ sn as pushBottomSheet
726
+ };
727
+ //# sourceMappingURL=index.js.map