@surdeddd/bottom-sheet 0.2.0 → 0.3.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/README.md +51 -21
- package/dist/{BottomSheetEngine-CIT9Htti.d.cts → BottomSheetEngine-CAymrH-P.d.cts} +67 -1
- package/dist/{BottomSheetEngine-Df9MwBbm.d.ts → BottomSheetEngine-DcqcuudN.d.ts} +67 -1
- package/dist/element.cjs +699 -116
- package/dist/element.d.cts +7 -2
- package/dist/element.d.ts +7 -2
- package/dist/element.iife.global.js +2 -2
- package/dist/element.js +699 -116
- package/dist/index.cjs +715 -145
- package/dist/index.d.cts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +713 -146
- 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/overlay.cjs +168 -35
- package/dist/overlay.d.cts +13 -0
- package/dist/overlay.d.ts +13 -0
- package/dist/overlay.js +168 -35
- package/dist/preact.d.cts +1 -1
- package/dist/preact.d.ts +1 -1
- package/dist/qwik.cjs +619 -119
- package/dist/qwik.d.cts +2 -2
- package/dist/qwik.d.ts +2 -2
- package/dist/qwik.js +620 -120
- package/dist/react.cjs +821 -191
- package/dist/react.d.cts +20 -3
- package/dist/react.d.ts +20 -3
- package/dist/react.js +821 -191
- package/dist/solid.cjs +656 -161
- package/dist/solid.d.cts +263 -4
- package/dist/solid.d.ts +263 -4
- package/dist/solid.js +657 -162
- package/dist/solid.source.jsx +3215 -0
- package/dist/styles.css +10 -10
- package/dist/svelte-core.cjs +3149 -0
- package/dist/svelte-core.js +3147 -0
- package/dist/svelte-src/BottomSheet.svelte +210 -0
- package/dist/svelte-src/index.js +2 -0
- package/dist/svelte.cjs +618 -124
- package/dist/svelte.d.cts +100 -0
- package/dist/svelte.d.ts +7 -3
- package/dist/svelte.js +619 -125
- package/dist/vue.cjs +612 -119
- package/dist/vue.d.cts +78 -0
- package/dist/vue.d.ts +6 -2
- package/dist/vue.js +612 -119
- package/package.json +103 -43
|
@@ -0,0 +1,3215 @@
|
|
|
1
|
+
// src/solid/index.tsx
|
|
2
|
+
import {
|
|
3
|
+
createSignal,
|
|
4
|
+
createMemo,
|
|
5
|
+
createEffect,
|
|
6
|
+
on,
|
|
7
|
+
onCleanup,
|
|
8
|
+
onMount
|
|
9
|
+
} from "solid-js";
|
|
10
|
+
|
|
11
|
+
// src/core/lifecycle/sheetStack.ts
|
|
12
|
+
var BASE_Z = 100;
|
|
13
|
+
var STEP = 10;
|
|
14
|
+
var SheetStack = class {
|
|
15
|
+
entries = [];
|
|
16
|
+
push(entry) {
|
|
17
|
+
this.entries.push(entry);
|
|
18
|
+
this.recompute();
|
|
19
|
+
return () => this.remove(entry.id);
|
|
20
|
+
}
|
|
21
|
+
remove(id) {
|
|
22
|
+
const idx = this.entries.findIndex((e) => e.id === id);
|
|
23
|
+
if (idx === -1) return;
|
|
24
|
+
this.entries.splice(idx, 1);
|
|
25
|
+
this.recompute();
|
|
26
|
+
}
|
|
27
|
+
promote(id) {
|
|
28
|
+
const idx = this.entries.findIndex((e) => e.id === id);
|
|
29
|
+
if (idx === -1) return;
|
|
30
|
+
if (idx !== this.entries.length - 1) {
|
|
31
|
+
const [entry] = this.entries.splice(idx, 1);
|
|
32
|
+
this.entries.push(entry);
|
|
33
|
+
}
|
|
34
|
+
this.recompute();
|
|
35
|
+
}
|
|
36
|
+
update() {
|
|
37
|
+
this.recompute();
|
|
38
|
+
}
|
|
39
|
+
size() {
|
|
40
|
+
return this.entries.length;
|
|
41
|
+
}
|
|
42
|
+
clear() {
|
|
43
|
+
this.entries = [];
|
|
44
|
+
}
|
|
45
|
+
recompute() {
|
|
46
|
+
let top = null;
|
|
47
|
+
const open = [];
|
|
48
|
+
for (const entry of this.entries) {
|
|
49
|
+
if (!entry.isOpen || entry.isOpen()) {
|
|
50
|
+
top = entry;
|
|
51
|
+
open.push(entry);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!top && this.entries.length > 0) {
|
|
55
|
+
top = this.entries[this.entries.length - 1];
|
|
56
|
+
}
|
|
57
|
+
this.entries.forEach((entry, i) => {
|
|
58
|
+
entry.setZIndex(BASE_Z + i * STEP);
|
|
59
|
+
entry.setIsTop(entry === top);
|
|
60
|
+
if (entry.setDepth) {
|
|
61
|
+
const openIdx = open.indexOf(entry);
|
|
62
|
+
entry.setDepth(openIdx === -1 ? 0 : open.length - 1 - openIdx);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var sheetStack = new SheetStack();
|
|
68
|
+
|
|
69
|
+
// src/core/primitives/transform.ts
|
|
70
|
+
function buildTransformTemplate(axis) {
|
|
71
|
+
switch (axis) {
|
|
72
|
+
case "bottom":
|
|
73
|
+
return (offset) => `translate3d(0, ${offset}px, 0)`;
|
|
74
|
+
case "top":
|
|
75
|
+
return (offset) => `translate3d(0, ${-offset}px, 0)`;
|
|
76
|
+
case "left":
|
|
77
|
+
return (offset) => `translate3d(${-offset}px, 0, 0)`;
|
|
78
|
+
case "right":
|
|
79
|
+
return (offset) => `translate3d(${offset}px, 0, 0)`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
var layoutAxis = (axis) => axis === "left" || axis === "right" ? "width" : "height";
|
|
83
|
+
|
|
84
|
+
// src/core/primitives/instance-id.ts
|
|
85
|
+
var counters = {};
|
|
86
|
+
function nextInstanceId(prefix) {
|
|
87
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
88
|
+
return `${prefix}-${crypto.randomUUID()}`;
|
|
89
|
+
}
|
|
90
|
+
counters[prefix] = (counters[prefix] ?? 0) + 1;
|
|
91
|
+
return `${prefix}-${counters[prefix]}`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/core/primitives/event-bus.ts
|
|
95
|
+
function createEventBus() {
|
|
96
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
97
|
+
return {
|
|
98
|
+
on(event, fn) {
|
|
99
|
+
let set = listeners.get(event);
|
|
100
|
+
if (!set) {
|
|
101
|
+
set = /* @__PURE__ */ new Set();
|
|
102
|
+
listeners.set(event, set);
|
|
103
|
+
}
|
|
104
|
+
set.add(fn);
|
|
105
|
+
return () => {
|
|
106
|
+
set.delete(fn);
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
emit(event, payload) {
|
|
110
|
+
const set = listeners.get(event);
|
|
111
|
+
if (!set) return;
|
|
112
|
+
for (const fn of [...set]) {
|
|
113
|
+
fn(payload);
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
listenerCount(event) {
|
|
117
|
+
return listeners.get(event)?.size ?? 0;
|
|
118
|
+
},
|
|
119
|
+
clear() {
|
|
120
|
+
listeners.clear();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/core/primitives/cssLength.ts
|
|
126
|
+
var probe = null;
|
|
127
|
+
var PROBE_ATTR = "data-bs-probe";
|
|
128
|
+
var ensureProbe = (axis) => {
|
|
129
|
+
if (typeof document === "undefined") return null;
|
|
130
|
+
if (!probe || !probe.isConnected) {
|
|
131
|
+
const existing = document.querySelector(`[${PROBE_ATTR}]`);
|
|
132
|
+
if (existing) {
|
|
133
|
+
probe = existing;
|
|
134
|
+
} else {
|
|
135
|
+
probe = document.createElement("div");
|
|
136
|
+
probe.setAttribute("aria-hidden", "true");
|
|
137
|
+
probe.setAttribute(PROBE_ATTR, "");
|
|
138
|
+
probe.style.cssText = "position:absolute;visibility:hidden;pointer-events:none;contain:strict;left:0;top:0;width:0;height:0;";
|
|
139
|
+
document.body.appendChild(probe);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (axis === "vertical") {
|
|
143
|
+
probe.style.width = "0";
|
|
144
|
+
probe.style.height = "";
|
|
145
|
+
} else {
|
|
146
|
+
probe.style.height = "0";
|
|
147
|
+
probe.style.width = "";
|
|
148
|
+
}
|
|
149
|
+
return probe;
|
|
150
|
+
};
|
|
151
|
+
var isViewportAxisVertical = (mode) => mode === "bottom" || mode === "top";
|
|
152
|
+
var viewportSize = (mode) => {
|
|
153
|
+
if (typeof window === "undefined") return 0;
|
|
154
|
+
return isViewportAxisVertical(mode) ? window.innerHeight : window.innerWidth;
|
|
155
|
+
};
|
|
156
|
+
var PERCENT = /^(-?\d+(?:\.\d+)?)%$/;
|
|
157
|
+
var resolveSnap = (point, mode, measureFit) => {
|
|
158
|
+
if (typeof point === "number") return Math.max(0, point);
|
|
159
|
+
if (point === "full") return viewportSize(mode);
|
|
160
|
+
if (point === "fit") return Math.max(0, measureFit?.() ?? 0);
|
|
161
|
+
const pctMatch = point.match(PERCENT);
|
|
162
|
+
if (pctMatch) {
|
|
163
|
+
const pct = parseFloat(pctMatch[1]) / 100;
|
|
164
|
+
return Math.max(0, viewportSize(mode) * pct);
|
|
165
|
+
}
|
|
166
|
+
const axis = isViewportAxisVertical(mode) ? "vertical" : "horizontal";
|
|
167
|
+
const el = ensureProbe(axis);
|
|
168
|
+
if (!el) return 0;
|
|
169
|
+
if (axis === "vertical") {
|
|
170
|
+
el.style.height = point;
|
|
171
|
+
return Math.max(0, el.getBoundingClientRect().height);
|
|
172
|
+
}
|
|
173
|
+
el.style.width = point;
|
|
174
|
+
return Math.max(0, el.getBoundingClientRect().width);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// src/core/primitives/snap-points.ts
|
|
178
|
+
var resolveSnapList = (points, mode, measureFit) => points.map((p) => {
|
|
179
|
+
const raw = resolveSnap(p.size, mode, measureFit);
|
|
180
|
+
if (!Number.isFinite(raw) || raw < 0) {
|
|
181
|
+
console.warn(
|
|
182
|
+
`[BottomSheet] snap "${p.id}" resolved to invalid size (${String(p.size)} \u2192 ${raw}); clamped to 0.`
|
|
183
|
+
);
|
|
184
|
+
return { id: p.id, size: 0 };
|
|
185
|
+
}
|
|
186
|
+
return { id: p.id, size: raw };
|
|
187
|
+
}).sort((a, b) => a.size - b.size);
|
|
188
|
+
var VH_NOT_DVH = /(^|[^a-z])vh\b/i;
|
|
189
|
+
var auditVhUsage = (points) => {
|
|
190
|
+
for (const p of points) {
|
|
191
|
+
if (typeof p.size !== "string") continue;
|
|
192
|
+
if (!VH_NOT_DVH.test(p.size)) continue;
|
|
193
|
+
console.warn(
|
|
194
|
+
`[BottomSheet] snap "${p.id}" uses "vh" \u2014 prefer "dvh" on mobile (iOS Safari URL bar makes vh unstable). See https://web.dev/blog/viewport-units`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
var findNearest = (size, resolved, allowed, direction = 0, bias = 0) => {
|
|
199
|
+
const pool = resolved.filter((p) => allowed.includes(p.id));
|
|
200
|
+
if (pool.length === 0) return null;
|
|
201
|
+
const target = size + direction * bias;
|
|
202
|
+
let best = pool[0];
|
|
203
|
+
let bestDist = Math.abs(target - best.size);
|
|
204
|
+
for (let i = 1; i < pool.length; i++) {
|
|
205
|
+
const cand = pool[i];
|
|
206
|
+
const dist = Math.abs(target - cand.size);
|
|
207
|
+
if (dist < bestDist) {
|
|
208
|
+
best = cand;
|
|
209
|
+
bestDist = dist;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return best;
|
|
213
|
+
};
|
|
214
|
+
var allowedRange = (resolved, allowed) => {
|
|
215
|
+
const pool = resolved.filter((p) => allowed.includes(p.id));
|
|
216
|
+
if (pool.length === 0) return { min: 0, max: 0 };
|
|
217
|
+
return {
|
|
218
|
+
min: pool[0].size,
|
|
219
|
+
max: pool[pool.length - 1].size
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
var findById = (id, resolved) => resolved.find((p) => p.id === id) ?? null;
|
|
223
|
+
var MOUSE_FLICK_VELOCITY = 0.4;
|
|
224
|
+
var MOUSE_DRAG_THRESHOLD = 12;
|
|
225
|
+
var DIRECTIONAL_INTENT_VELOCITY = 0.15;
|
|
226
|
+
var findDragSettleTarget = (input) => {
|
|
227
|
+
const speed = Math.abs(input.velocity);
|
|
228
|
+
const flickThreshold = input.pointerKind === "mouse" ? MOUSE_FLICK_VELOCITY : input.flickVelocity;
|
|
229
|
+
const dragThresh = input.pointerKind === "mouse" ? MOUSE_DRAG_THRESHOLD : input.dragThreshold;
|
|
230
|
+
let direction = 0;
|
|
231
|
+
if (speed > flickThreshold || speed > DIRECTIONAL_INTENT_VELOCITY) {
|
|
232
|
+
direction = input.velocity > 0 ? 1 : -1;
|
|
233
|
+
}
|
|
234
|
+
if (Math.abs(input.delta) < dragThresh && direction === 0) {
|
|
235
|
+
return findById(input.activeId, input.resolved);
|
|
236
|
+
}
|
|
237
|
+
const speedBias = speed > flickThreshold ? Math.min(speed * 180, input.maxAxisSize) : 0;
|
|
238
|
+
return findNearest(
|
|
239
|
+
input.size,
|
|
240
|
+
input.resolved,
|
|
241
|
+
input.allowed,
|
|
242
|
+
direction,
|
|
243
|
+
speedBias
|
|
244
|
+
);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// src/core/primitives/snap-resolver.ts
|
|
248
|
+
var SnapResolver = class {
|
|
249
|
+
constructor(raw, allowed, mode, measureFit, onMaxAxisSizeChange) {
|
|
250
|
+
this.mode = mode;
|
|
251
|
+
this.measureFit = measureFit;
|
|
252
|
+
this.onMaxAxisSizeChange = onMaxAxisSizeChange;
|
|
253
|
+
this.raw = raw;
|
|
254
|
+
this.allowedIds = allowed ?? raw.map((p) => p.id);
|
|
255
|
+
this.recompute();
|
|
256
|
+
}
|
|
257
|
+
mode;
|
|
258
|
+
measureFit;
|
|
259
|
+
onMaxAxisSizeChange;
|
|
260
|
+
raw;
|
|
261
|
+
allowedIds;
|
|
262
|
+
resolved = [];
|
|
263
|
+
maxAxisSize = 0;
|
|
264
|
+
rangeCache = null;
|
|
265
|
+
recompute() {
|
|
266
|
+
this.resolved = resolveSnapList(this.raw, this.mode, this.measureFit);
|
|
267
|
+
this.maxAxisSize = this.resolved.reduce(
|
|
268
|
+
(m, s) => s.size > m ? s.size : m,
|
|
269
|
+
0
|
|
270
|
+
);
|
|
271
|
+
this.rangeCache = null;
|
|
272
|
+
this.onMaxAxisSizeChange?.(this.maxAxisSize);
|
|
273
|
+
}
|
|
274
|
+
setRaw(raw) {
|
|
275
|
+
this.raw = raw;
|
|
276
|
+
this.recompute();
|
|
277
|
+
}
|
|
278
|
+
setAllowedIds(ids) {
|
|
279
|
+
this.allowedIds = ids;
|
|
280
|
+
this.rangeCache = null;
|
|
281
|
+
}
|
|
282
|
+
findById(id) {
|
|
283
|
+
return findById(id, this.resolved);
|
|
284
|
+
}
|
|
285
|
+
findDragSettleTarget(args) {
|
|
286
|
+
return findDragSettleTarget({
|
|
287
|
+
...args,
|
|
288
|
+
resolved: this.resolved,
|
|
289
|
+
allowed: this.allowedIds,
|
|
290
|
+
maxAxisSize: this.maxAxisSize
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
getAllowedRange() {
|
|
294
|
+
return this.rangeCache ?? (this.rangeCache = allowedRange(this.resolved, this.allowedIds));
|
|
295
|
+
}
|
|
296
|
+
getResolvedSnaps() {
|
|
297
|
+
return this.resolved;
|
|
298
|
+
}
|
|
299
|
+
getAllowedIds() {
|
|
300
|
+
return this.allowedIds;
|
|
301
|
+
}
|
|
302
|
+
getMaxAxisSize() {
|
|
303
|
+
return this.maxAxisSize;
|
|
304
|
+
}
|
|
305
|
+
setMaxAxisSize(n) {
|
|
306
|
+
this.maxAxisSize = n;
|
|
307
|
+
this.onMaxAxisSizeChange?.(n);
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// src/core/features/persist.ts
|
|
312
|
+
function readPersistedId(key) {
|
|
313
|
+
if (!key) return null;
|
|
314
|
+
if (typeof window === "undefined") return null;
|
|
315
|
+
if (typeof localStorage === "undefined") return null;
|
|
316
|
+
try {
|
|
317
|
+
return localStorage.getItem(key);
|
|
318
|
+
} catch {
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function installPersist(engine, key) {
|
|
323
|
+
const unsubscribe = engine.on("snap", ({ id }) => {
|
|
324
|
+
if (typeof window === "undefined") return;
|
|
325
|
+
if (typeof localStorage === "undefined") return;
|
|
326
|
+
try {
|
|
327
|
+
localStorage.setItem(key, id);
|
|
328
|
+
} catch {
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
return unsubscribe;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// src/core/features/auto-collapse.ts
|
|
335
|
+
function installAutoCollapse(deps) {
|
|
336
|
+
const { ms } = deps;
|
|
337
|
+
if (ms === void 0 || ms <= 0) {
|
|
338
|
+
return () => {
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
let timer = null;
|
|
342
|
+
const clearTimer = () => {
|
|
343
|
+
if (timer !== null) {
|
|
344
|
+
clearTimeout(timer);
|
|
345
|
+
timer = null;
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
const fire = () => {
|
|
349
|
+
if (deps.isDestroyed()) return;
|
|
350
|
+
if (deps.isDragging()) return;
|
|
351
|
+
const active = deps.resolveSnap(deps.getActiveId());
|
|
352
|
+
if (!active || active.size === 0) return;
|
|
353
|
+
let target = null;
|
|
354
|
+
for (const id of deps.getAllowedIds()) {
|
|
355
|
+
const snap = deps.resolveSnap(id);
|
|
356
|
+
if (!snap || snap.size <= 0) continue;
|
|
357
|
+
if (!target || snap.size < target.size) target = snap;
|
|
358
|
+
}
|
|
359
|
+
if (!target) return;
|
|
360
|
+
if (target.id === active.id || target.size >= active.size) return;
|
|
361
|
+
deps.snapTo(target.id);
|
|
362
|
+
};
|
|
363
|
+
const reset = () => {
|
|
364
|
+
clearTimer();
|
|
365
|
+
if (deps.isDestroyed()) return;
|
|
366
|
+
timer = setTimeout(() => {
|
|
367
|
+
timer = null;
|
|
368
|
+
fire();
|
|
369
|
+
}, ms);
|
|
370
|
+
};
|
|
371
|
+
const unsubscribe = deps.on("snap", () => reset());
|
|
372
|
+
if ((deps.resolveSnap(deps.getActiveId())?.size ?? 0) > 0) reset();
|
|
373
|
+
return () => {
|
|
374
|
+
clearTimer();
|
|
375
|
+
unsubscribe();
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// src/core/features/linked-sheets.ts
|
|
380
|
+
function notifyLinkedSheets(sheets, self) {
|
|
381
|
+
if (sheets.length === 0) return;
|
|
382
|
+
for (const linked of sheets) {
|
|
383
|
+
if (linked === self) continue;
|
|
384
|
+
try {
|
|
385
|
+
if (linked.state.size === 0) continue;
|
|
386
|
+
const ids = linked.getAllowedIds();
|
|
387
|
+
const target = ids.find((id) => id !== "closed");
|
|
388
|
+
if (target && target !== linked.state.activeId) {
|
|
389
|
+
void linked.snapTo(target);
|
|
390
|
+
}
|
|
391
|
+
} catch (err) {
|
|
392
|
+
queueMicrotask(() => {
|
|
393
|
+
throw err;
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// src/core/features/route.ts
|
|
400
|
+
function installRoute(deps) {
|
|
401
|
+
if (typeof window === "undefined") {
|
|
402
|
+
return () => {
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
if (!deps.routedTo && !deps.closeOnBack) {
|
|
406
|
+
return () => {
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
let routePushed = false;
|
|
410
|
+
let closeOnBackPushed = false;
|
|
411
|
+
let detachPopstate = null;
|
|
412
|
+
const popOurMarker = (key, expected) => {
|
|
413
|
+
const state = history.state;
|
|
414
|
+
if (state && state[key] === expected) {
|
|
415
|
+
try {
|
|
416
|
+
history.back();
|
|
417
|
+
} catch {
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
const onOpen = () => {
|
|
422
|
+
if (deps.routedTo && !detachPopstate) {
|
|
423
|
+
const target = deps.routedTo;
|
|
424
|
+
try {
|
|
425
|
+
history.pushState({ __bsRouted: target }, "", target);
|
|
426
|
+
routePushed = true;
|
|
427
|
+
} catch {
|
|
428
|
+
}
|
|
429
|
+
const onPop = (event) => {
|
|
430
|
+
if (deps.isDestroyed()) return;
|
|
431
|
+
const state = event.state;
|
|
432
|
+
if ((!state || state.__bsRouted !== target) && deps.getSize() > 0) {
|
|
433
|
+
routePushed = false;
|
|
434
|
+
void deps.close();
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
window.addEventListener("popstate", onPop);
|
|
438
|
+
detachPopstate = () => window.removeEventListener("popstate", onPop);
|
|
439
|
+
} else if (deps.closeOnBack && !detachPopstate) {
|
|
440
|
+
try {
|
|
441
|
+
history.pushState({ __bsSheet: deps.sheetId }, "");
|
|
442
|
+
closeOnBackPushed = true;
|
|
443
|
+
} catch {
|
|
444
|
+
}
|
|
445
|
+
const onPop = () => {
|
|
446
|
+
if (deps.isDestroyed()) return;
|
|
447
|
+
if (deps.getSize() > 0 && deps.isTopSheet()) {
|
|
448
|
+
const state = history.state;
|
|
449
|
+
if (state?.__bsSheet !== deps.sheetId) closeOnBackPushed = false;
|
|
450
|
+
void deps.close();
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
window.addEventListener("popstate", onPop);
|
|
454
|
+
detachPopstate = () => window.removeEventListener("popstate", onPop);
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
const onClose = () => {
|
|
458
|
+
detachPopstate?.();
|
|
459
|
+
detachPopstate = null;
|
|
460
|
+
if (routePushed) {
|
|
461
|
+
routePushed = false;
|
|
462
|
+
if (deps.routedTo !== void 0) popOurMarker("__bsRouted", deps.routedTo);
|
|
463
|
+
}
|
|
464
|
+
if (closeOnBackPushed) {
|
|
465
|
+
closeOnBackPushed = false;
|
|
466
|
+
popOurMarker("__bsSheet", deps.sheetId);
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
const unsubscribeOpen = deps.on("open", onOpen);
|
|
470
|
+
const unsubscribeClose = deps.on("close", onClose);
|
|
471
|
+
if (deps.getSize() > 0) onOpen();
|
|
472
|
+
return () => {
|
|
473
|
+
unsubscribeOpen();
|
|
474
|
+
unsubscribeClose();
|
|
475
|
+
detachPopstate?.();
|
|
476
|
+
detachPopstate = null;
|
|
477
|
+
if (routePushed) {
|
|
478
|
+
routePushed = false;
|
|
479
|
+
if (deps.routedTo !== void 0) popOurMarker("__bsRouted", deps.routedTo);
|
|
480
|
+
}
|
|
481
|
+
if (closeOnBackPushed) {
|
|
482
|
+
closeOnBackPushed = false;
|
|
483
|
+
popOurMarker("__bsSheet", deps.sheetId);
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// src/core/features/content-swipe.ts
|
|
489
|
+
var CONTENT_PULL_THRESHOLD = 60;
|
|
490
|
+
function installContentSwipe(deps) {
|
|
491
|
+
const { container } = deps;
|
|
492
|
+
let startY = 0;
|
|
493
|
+
let moved = false;
|
|
494
|
+
const onTouchStart = (e) => {
|
|
495
|
+
const t = e.touches[0];
|
|
496
|
+
if (!t) return;
|
|
497
|
+
startY = t.clientY;
|
|
498
|
+
moved = false;
|
|
499
|
+
};
|
|
500
|
+
const onTouchMove = (e) => {
|
|
501
|
+
const t = e.touches[0];
|
|
502
|
+
if (!t) return;
|
|
503
|
+
if (Math.abs(t.clientY - startY) > CONTENT_PULL_THRESHOLD) moved = true;
|
|
504
|
+
};
|
|
505
|
+
const onTouchEnd = (e) => {
|
|
506
|
+
if (!moved) return;
|
|
507
|
+
if (deps.isDragging() || deps.isAnimating()) return;
|
|
508
|
+
const t = e.changedTouches[0];
|
|
509
|
+
if (!t) return;
|
|
510
|
+
const deltaY = t.clientY - startY;
|
|
511
|
+
const atTop = container.scrollTop <= 0;
|
|
512
|
+
const allowed = deps.getAllowedIds();
|
|
513
|
+
const idx = allowed.indexOf(deps.getActiveId());
|
|
514
|
+
if (idx === -1) return;
|
|
515
|
+
if (atTop && deltaY > CONTENT_PULL_THRESHOLD && idx > 0) {
|
|
516
|
+
deps.snapTo(allowed[idx - 1]);
|
|
517
|
+
} else if (deltaY < -CONTENT_PULL_THRESHOLD && idx < allowed.length - 1) {
|
|
518
|
+
deps.snapTo(allowed[idx + 1]);
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
container.addEventListener("touchstart", onTouchStart, { passive: true });
|
|
522
|
+
container.addEventListener("touchmove", onTouchMove, { passive: true });
|
|
523
|
+
container.addEventListener("touchend", onTouchEnd, { passive: true });
|
|
524
|
+
return () => {
|
|
525
|
+
container.removeEventListener("touchstart", onTouchStart);
|
|
526
|
+
container.removeEventListener("touchmove", onTouchMove);
|
|
527
|
+
container.removeEventListener("touchend", onTouchEnd);
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// src/core/features/visual-viewport.ts
|
|
532
|
+
var SAFETY_PAD = 8;
|
|
533
|
+
function installVisualViewport(deps) {
|
|
534
|
+
if (typeof window === "undefined" || !window.visualViewport) {
|
|
535
|
+
return () => {
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
const vv = window.visualViewport;
|
|
539
|
+
let rafId = null;
|
|
540
|
+
const onResize = () => {
|
|
541
|
+
if (rafId !== null) return;
|
|
542
|
+
rafId = requestAnimationFrame(() => {
|
|
543
|
+
rafId = null;
|
|
544
|
+
if (deps.isDestroyed()) return;
|
|
545
|
+
deps.recomputeSnaps();
|
|
546
|
+
const isVertical = deps.isVerticalAxis();
|
|
547
|
+
const visible = isVertical ? vv.height : vv.width;
|
|
548
|
+
const windowSize = isVertical ? window.innerHeight : window.innerWidth;
|
|
549
|
+
const clamp = Math.max(0, Math.min(windowSize, visible) - SAFETY_PAD);
|
|
550
|
+
if (clamp < deps.getMaxAxisSize()) {
|
|
551
|
+
deps.setMaxAxisSize(clamp);
|
|
552
|
+
}
|
|
553
|
+
const max = deps.getMaxAxisSize();
|
|
554
|
+
deps.setSize(Math.min(deps.getSize(), max));
|
|
555
|
+
const current = deps.resolveActiveSnap();
|
|
556
|
+
if (current && !deps.isDragging()) {
|
|
557
|
+
deps.applySize(Math.min(current.size, max));
|
|
558
|
+
} else {
|
|
559
|
+
deps.applySize(deps.getSize());
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
};
|
|
563
|
+
vv.addEventListener("resize", onResize);
|
|
564
|
+
return () => {
|
|
565
|
+
vv.removeEventListener("resize", onResize);
|
|
566
|
+
if (rafId !== null) cancelAnimationFrame(rafId);
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// src/core/features/resize-observer.ts
|
|
571
|
+
function installResizeObserver(deps) {
|
|
572
|
+
if (typeof window === "undefined") {
|
|
573
|
+
return () => {
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
const onResize = () => {
|
|
577
|
+
if (deps.isDestroyed()) return;
|
|
578
|
+
deps.recomputeSnaps();
|
|
579
|
+
const mode = deps.getMode();
|
|
580
|
+
const isVerticalAxis = mode === "bottom" || mode === "top";
|
|
581
|
+
const viewportSize2 = isVerticalAxis ? window.innerHeight : window.innerWidth;
|
|
582
|
+
const max = deps.getMaxAxisSize();
|
|
583
|
+
if (viewportSize2 > 0 && viewportSize2 < max) {
|
|
584
|
+
deps.setMaxAxisSize(viewportSize2);
|
|
585
|
+
}
|
|
586
|
+
const wasAnimating = deps.isAnimating?.() ?? false;
|
|
587
|
+
deps.cancelInFlight();
|
|
588
|
+
deps.newCycle();
|
|
589
|
+
const current = deps.resolveActiveSnap();
|
|
590
|
+
const newMax = deps.getMaxAxisSize();
|
|
591
|
+
const targetSize = current ? Math.min(current.size, newMax) : Math.min(deps.getSize(), newMax);
|
|
592
|
+
deps.setSize(targetSize);
|
|
593
|
+
if (current && !deps.isDragging()) {
|
|
594
|
+
deps.applySize(targetSize);
|
|
595
|
+
if (wasAnimating) deps.resyncAfterCancel?.();
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
let resizeObserver = null;
|
|
599
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
600
|
+
resizeObserver = new ResizeObserver(onResize);
|
|
601
|
+
resizeObserver.observe(document.documentElement);
|
|
602
|
+
} else {
|
|
603
|
+
window.addEventListener("resize", onResize);
|
|
604
|
+
}
|
|
605
|
+
window.addEventListener("orientationchange", onResize);
|
|
606
|
+
const onVisibility = () => {
|
|
607
|
+
if (deps.isDestroyed()) return;
|
|
608
|
+
if (document.hidden) deps.cancelInFlight();
|
|
609
|
+
};
|
|
610
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
611
|
+
return () => {
|
|
612
|
+
resizeObserver?.disconnect();
|
|
613
|
+
window.removeEventListener("resize", onResize);
|
|
614
|
+
window.removeEventListener("orientationchange", onResize);
|
|
615
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// src/core/features/slider-keyboard.ts
|
|
620
|
+
function installSliderKeyboard(deps) {
|
|
621
|
+
const isVerticalAxis = deps.mode === "bottom" || deps.mode === "top";
|
|
622
|
+
const stepUp = isVerticalAxis ? "ArrowUp" : "ArrowRight";
|
|
623
|
+
const stepDown = isVerticalAxis ? "ArrowDown" : "ArrowLeft";
|
|
624
|
+
const sheetExpandsKey = deps.mode === "top" ? stepDown : stepUp;
|
|
625
|
+
const sheetCollapsesKey = deps.mode === "top" ? stepUp : stepDown;
|
|
626
|
+
const onHandleKey = (e) => {
|
|
627
|
+
if (deps.isDestroyed()) return;
|
|
628
|
+
const allowed = deps.getAllowedIds();
|
|
629
|
+
const idx = allowed.indexOf(deps.getActiveId());
|
|
630
|
+
if (idx === -1) return;
|
|
631
|
+
if (e.key === sheetExpandsKey && idx < allowed.length - 1) {
|
|
632
|
+
e.preventDefault();
|
|
633
|
+
deps.snapTo(allowed[idx + 1]);
|
|
634
|
+
} else if (e.key === sheetCollapsesKey && idx > 0) {
|
|
635
|
+
e.preventDefault();
|
|
636
|
+
deps.snapTo(allowed[idx - 1]);
|
|
637
|
+
} else if (e.key === "Home") {
|
|
638
|
+
e.preventDefault();
|
|
639
|
+
deps.snapTo(allowed[0]);
|
|
640
|
+
} else if (e.key === "End") {
|
|
641
|
+
e.preventDefault();
|
|
642
|
+
deps.snapTo(allowed[allowed.length - 1]);
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
deps.handle.addEventListener("keydown", onHandleKey);
|
|
646
|
+
return () => deps.handle.removeEventListener("keydown", onHandleKey);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// src/core/types.ts
|
|
650
|
+
var SCRIM_PRESETS = Object.freeze({
|
|
651
|
+
subtle: {
|
|
652
|
+
color: "rgba(0,0,0,0.2)",
|
|
653
|
+
blur: void 0,
|
|
654
|
+
range: [0.3, 1],
|
|
655
|
+
interactive: false
|
|
656
|
+
},
|
|
657
|
+
standard: {
|
|
658
|
+
color: "rgba(0,0,0,0.4)",
|
|
659
|
+
blur: void 0,
|
|
660
|
+
range: [0, 1],
|
|
661
|
+
interactive: false
|
|
662
|
+
},
|
|
663
|
+
monitoring: {
|
|
664
|
+
color: "rgba(15,15,20,0.55)",
|
|
665
|
+
blur: "4px",
|
|
666
|
+
range: [0, 1],
|
|
667
|
+
interactive: false
|
|
668
|
+
},
|
|
669
|
+
cinematic: {
|
|
670
|
+
color: "rgba(0,0,0,0.7)",
|
|
671
|
+
blur: "12px",
|
|
672
|
+
range: [0, 1],
|
|
673
|
+
interactive: false
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
// src/core/primitives/hot-path-thresholds.ts
|
|
678
|
+
var SIZE_WRITE_EPSILON = 0.5;
|
|
679
|
+
var OPACITY_WRITE_EPSILON = 5e-3;
|
|
680
|
+
var POINTER_EVENTS_OPACITY_THRESHOLD = 0.05;
|
|
681
|
+
var RANGE_DIVISION_EPSILON = 1e-4;
|
|
682
|
+
|
|
683
|
+
// src/core/primitives/opacity-dedup.ts
|
|
684
|
+
var WriteSentinel = class {
|
|
685
|
+
last = -1;
|
|
686
|
+
shouldWrite(next, epsilon) {
|
|
687
|
+
if (Math.abs(next - this.last) <= epsilon) return false;
|
|
688
|
+
this.last = next;
|
|
689
|
+
return true;
|
|
690
|
+
}
|
|
691
|
+
invalidate() {
|
|
692
|
+
this.last = -1;
|
|
693
|
+
}
|
|
694
|
+
setLastWritten(value) {
|
|
695
|
+
this.last = value;
|
|
696
|
+
}
|
|
697
|
+
get value() {
|
|
698
|
+
return this.last;
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
// src/core/primitives/devWarn.ts
|
|
703
|
+
function devWarn(...args) {
|
|
704
|
+
if (typeof process !== "undefined" && process.env && process.env.NODE_ENV !== "production" && typeof console !== "undefined") {
|
|
705
|
+
console.warn(...args);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// src/core/primitives/overlay-position.ts
|
|
710
|
+
function resolveSheetAnchoredStyle(mode, position, inset) {
|
|
711
|
+
const sizeOffset = `calc(var(--bs-size, 0px) + ${inset})`;
|
|
712
|
+
switch (mode) {
|
|
713
|
+
case "bottom":
|
|
714
|
+
if (position === "sheet-top-left") return { bottom: sizeOffset, left: inset };
|
|
715
|
+
if (position === "sheet-top-right") return { bottom: sizeOffset, right: inset };
|
|
716
|
+
return { bottom: sizeOffset, left: "50%", transform: "translateX(-50%)" };
|
|
717
|
+
case "top":
|
|
718
|
+
if (position === "sheet-top-left") return { top: sizeOffset, left: inset };
|
|
719
|
+
if (position === "sheet-top-right") return { top: sizeOffset, right: inset };
|
|
720
|
+
return { top: sizeOffset, left: "50%", transform: "translateX(-50%)" };
|
|
721
|
+
case "left":
|
|
722
|
+
if (position === "sheet-top-left") return { left: sizeOffset, top: inset };
|
|
723
|
+
if (position === "sheet-top-right") return { left: sizeOffset, bottom: inset };
|
|
724
|
+
return { left: sizeOffset, top: "50%", transform: "translateY(-50%)" };
|
|
725
|
+
case "right":
|
|
726
|
+
if (position === "sheet-top-left") return { right: sizeOffset, top: inset };
|
|
727
|
+
if (position === "sheet-top-right") return { right: sizeOffset, bottom: inset };
|
|
728
|
+
return { right: sizeOffset, top: "50%", transform: "translateY(-50%)" };
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
function applyOverlayPosition(ws, mode, position, inset) {
|
|
732
|
+
switch (position) {
|
|
733
|
+
case "top-left":
|
|
734
|
+
ws.top = inset;
|
|
735
|
+
ws.left = inset;
|
|
736
|
+
break;
|
|
737
|
+
case "top-center":
|
|
738
|
+
ws.top = inset;
|
|
739
|
+
ws.left = "50%";
|
|
740
|
+
ws.transform = "translateX(-50%)";
|
|
741
|
+
break;
|
|
742
|
+
case "top-right":
|
|
743
|
+
ws.top = inset;
|
|
744
|
+
ws.right = inset;
|
|
745
|
+
break;
|
|
746
|
+
case "center-left":
|
|
747
|
+
ws.top = "50%";
|
|
748
|
+
ws.left = inset;
|
|
749
|
+
ws.transform = "translateY(-50%)";
|
|
750
|
+
break;
|
|
751
|
+
case "center":
|
|
752
|
+
ws.top = "50%";
|
|
753
|
+
ws.left = "50%";
|
|
754
|
+
ws.transform = "translate(-50%, -50%)";
|
|
755
|
+
break;
|
|
756
|
+
case "center-right":
|
|
757
|
+
ws.top = "50%";
|
|
758
|
+
ws.right = inset;
|
|
759
|
+
ws.transform = "translateY(-50%)";
|
|
760
|
+
break;
|
|
761
|
+
case "bottom-left":
|
|
762
|
+
ws.bottom = inset;
|
|
763
|
+
ws.left = inset;
|
|
764
|
+
break;
|
|
765
|
+
case "bottom-center":
|
|
766
|
+
ws.bottom = inset;
|
|
767
|
+
ws.left = "50%";
|
|
768
|
+
ws.transform = "translateX(-50%)";
|
|
769
|
+
break;
|
|
770
|
+
case "bottom-right":
|
|
771
|
+
ws.bottom = inset;
|
|
772
|
+
ws.right = inset;
|
|
773
|
+
break;
|
|
774
|
+
case "sheet-top-left":
|
|
775
|
+
case "sheet-top-center":
|
|
776
|
+
case "sheet-top-right": {
|
|
777
|
+
const style = resolveSheetAnchoredStyle(mode, position, inset);
|
|
778
|
+
if (style.top !== void 0) ws.top = style.top;
|
|
779
|
+
if (style.bottom !== void 0) ws.bottom = style.bottom;
|
|
780
|
+
if (style.left !== void 0) ws.left = style.left;
|
|
781
|
+
if (style.right !== void 0) ws.right = style.right;
|
|
782
|
+
if (style.transform !== void 0) ws.transform = style.transform;
|
|
783
|
+
break;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// src/core/controllers/scrim-controller.ts
|
|
789
|
+
var VALID_CSS_LENGTH = /^-?\d+(?:\.\d+)?(?:px|em|rem|%)$/;
|
|
790
|
+
var ScrimController = class {
|
|
791
|
+
screenComponent;
|
|
792
|
+
backdrop;
|
|
793
|
+
mode;
|
|
794
|
+
isDestroyed;
|
|
795
|
+
isTopSheet;
|
|
796
|
+
getAllowedIds;
|
|
797
|
+
getResolvedSnaps;
|
|
798
|
+
snapToFn;
|
|
799
|
+
closeFn;
|
|
800
|
+
scrimInteractive = false;
|
|
801
|
+
scrimMode;
|
|
802
|
+
backdropRange;
|
|
803
|
+
screenRange;
|
|
804
|
+
scrimEnabled = true;
|
|
805
|
+
savedScrimRanges = null;
|
|
806
|
+
scrimTapToCloseEnabled = false;
|
|
807
|
+
detachScrimTap = null;
|
|
808
|
+
scrimOverlayTeardown = null;
|
|
809
|
+
backdropOpacitySentinel = new WriteSentinel();
|
|
810
|
+
screenOpacitySentinel = new WriteSentinel();
|
|
811
|
+
lastBackdropPointer = "";
|
|
812
|
+
lastScreenDisplay = "";
|
|
813
|
+
invalidateOpacityCache() {
|
|
814
|
+
this.backdropOpacitySentinel.invalidate();
|
|
815
|
+
this.screenOpacitySentinel.invalidate();
|
|
816
|
+
}
|
|
817
|
+
constructor(deps, opts) {
|
|
818
|
+
this.screenComponent = deps.screenComponent;
|
|
819
|
+
this.backdrop = deps.backdrop;
|
|
820
|
+
this.mode = deps.mode;
|
|
821
|
+
this.isDestroyed = deps.isDestroyed;
|
|
822
|
+
this.isTopSheet = deps.isTopSheet;
|
|
823
|
+
this.getAllowedIds = deps.getAllowedIds;
|
|
824
|
+
this.getResolvedSnaps = deps.getResolvedSnaps;
|
|
825
|
+
this.snapToFn = deps.snapTo;
|
|
826
|
+
this.closeFn = deps.close;
|
|
827
|
+
this.scrimMode = opts.scrimMode ?? "full";
|
|
828
|
+
const preset = opts.scrimPreset ? SCRIM_PRESETS[opts.scrimPreset] : null;
|
|
829
|
+
this.backdropRange = opts.backdropRange ?? preset?.range ?? [0, 1];
|
|
830
|
+
this.screenRange = opts.screenRange ?? preset?.range ?? [0, 1];
|
|
831
|
+
this.scrimTapToCloseEnabled = opts.scrimTapToClose ?? false;
|
|
832
|
+
if (this.screenComponent) {
|
|
833
|
+
this.applyScrimStyles({
|
|
834
|
+
color: opts.scrimColor ?? preset?.color,
|
|
835
|
+
blur: opts.scrimBlur ?? preset?.blur,
|
|
836
|
+
interactive: opts.scrimInteractive ?? preset?.interactive ?? false
|
|
837
|
+
});
|
|
838
|
+
if (this.scrimMode === "above-sheet") {
|
|
839
|
+
this.applyAboveSheetInset();
|
|
840
|
+
} else if (this.scrimMode === "off") {
|
|
841
|
+
const s = this.screenComponent.style;
|
|
842
|
+
s.opacity = "0";
|
|
843
|
+
s.display = "none";
|
|
844
|
+
this.screenOpacitySentinel.setLastWritten(0);
|
|
845
|
+
this.lastScreenDisplay = "none";
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
attach() {
|
|
850
|
+
if (this.scrimTapToCloseEnabled) {
|
|
851
|
+
this.setScrimTapToClose(true);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
applyOpacity(progress, progressChanged) {
|
|
855
|
+
if (!progressChanged && this.backdropOpacitySentinel.value !== -1 && this.screenOpacitySentinel.value !== -1) {
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
if (this.backdrop && this.isTopSheet()) {
|
|
859
|
+
const [s, e] = this.backdropRange;
|
|
860
|
+
const range = Math.max(e - s, RANGE_DIVISION_EPSILON);
|
|
861
|
+
const backdropOpacity = Math.min(
|
|
862
|
+
Math.max((progress - s) / range, 0),
|
|
863
|
+
1
|
|
864
|
+
);
|
|
865
|
+
if (this.backdropOpacitySentinel.shouldWrite(
|
|
866
|
+
backdropOpacity,
|
|
867
|
+
OPACITY_WRITE_EPSILON
|
|
868
|
+
)) {
|
|
869
|
+
this.backdrop.style.opacity = String(backdropOpacity);
|
|
870
|
+
}
|
|
871
|
+
const nextPointer = backdropOpacity > POINTER_EVENTS_OPACITY_THRESHOLD ? "auto" : "none";
|
|
872
|
+
if (nextPointer !== this.lastBackdropPointer) {
|
|
873
|
+
this.backdrop.style.pointerEvents = nextPointer;
|
|
874
|
+
this.lastBackdropPointer = nextPointer;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
if (this.screenComponent && this.scrimMode !== "off") {
|
|
878
|
+
const [ss, se] = this.screenRange;
|
|
879
|
+
const screenOpacity = Math.min(
|
|
880
|
+
1,
|
|
881
|
+
Math.max(
|
|
882
|
+
0,
|
|
883
|
+
(progress - ss) / Math.max(RANGE_DIVISION_EPSILON, se - ss)
|
|
884
|
+
)
|
|
885
|
+
);
|
|
886
|
+
if (this.screenOpacitySentinel.shouldWrite(
|
|
887
|
+
screenOpacity,
|
|
888
|
+
OPACITY_WRITE_EPSILON
|
|
889
|
+
)) {
|
|
890
|
+
this.screenComponent.style.opacity = String(screenOpacity);
|
|
891
|
+
}
|
|
892
|
+
const nextDisplay = screenOpacity > 0 ? "" : "none";
|
|
893
|
+
if (nextDisplay !== this.lastScreenDisplay) {
|
|
894
|
+
this.screenComponent.style.display = nextDisplay;
|
|
895
|
+
this.lastScreenDisplay = nextDisplay;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
setBackdropRange(range, applySize) {
|
|
900
|
+
if (this.isDestroyed()) return;
|
|
901
|
+
this.backdropRange = range;
|
|
902
|
+
this.invalidateOpacityCache();
|
|
903
|
+
applySize();
|
|
904
|
+
}
|
|
905
|
+
setScreenRange(range, applySize) {
|
|
906
|
+
if (this.isDestroyed()) return;
|
|
907
|
+
this.screenRange = range;
|
|
908
|
+
this.invalidateOpacityCache();
|
|
909
|
+
applySize();
|
|
910
|
+
}
|
|
911
|
+
setScrimColor(color) {
|
|
912
|
+
if (this.isDestroyed()) return;
|
|
913
|
+
this.applyScrimStyles({ color: color === void 0 ? null : color });
|
|
914
|
+
}
|
|
915
|
+
setScrimBlur(blur) {
|
|
916
|
+
if (this.isDestroyed()) return;
|
|
917
|
+
this.applyScrimStyles({ blur: blur === void 0 ? null : blur });
|
|
918
|
+
}
|
|
919
|
+
setScrimInteractive(interactive) {
|
|
920
|
+
if (this.isDestroyed()) return;
|
|
921
|
+
this.applyScrimStyles({ interactive });
|
|
922
|
+
}
|
|
923
|
+
setScrimMode(mode, applySize) {
|
|
924
|
+
if (this.isDestroyed()) return;
|
|
925
|
+
if (mode === this.scrimMode) return;
|
|
926
|
+
this.invalidateOpacityCache();
|
|
927
|
+
const previous = this.scrimMode;
|
|
928
|
+
this.scrimMode = mode;
|
|
929
|
+
if (this.screenComponent) {
|
|
930
|
+
const s = this.screenComponent.style;
|
|
931
|
+
if (previous === "above-sheet" && mode !== "above-sheet") {
|
|
932
|
+
s.position = "";
|
|
933
|
+
s.inset = "";
|
|
934
|
+
s.pointerEvents = "";
|
|
935
|
+
}
|
|
936
|
+
if (mode === "above-sheet") {
|
|
937
|
+
this.applyAboveSheetInset();
|
|
938
|
+
} else if (mode === "off") {
|
|
939
|
+
s.opacity = "0";
|
|
940
|
+
s.display = "none";
|
|
941
|
+
this.screenOpacitySentinel.setLastWritten(0);
|
|
942
|
+
this.lastScreenDisplay = "none";
|
|
943
|
+
} else {
|
|
944
|
+
if (this.lastScreenDisplay === "none") {
|
|
945
|
+
s.display = "";
|
|
946
|
+
this.lastScreenDisplay = "";
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
applySize();
|
|
951
|
+
}
|
|
952
|
+
setScrimTapToClose(enabled) {
|
|
953
|
+
if (this.isDestroyed()) return;
|
|
954
|
+
if (!this.screenComponent) return;
|
|
955
|
+
const installed = this.detachScrimTap !== null;
|
|
956
|
+
if (enabled === installed) return;
|
|
957
|
+
if (enabled) {
|
|
958
|
+
const target = this.screenComponent;
|
|
959
|
+
if (target.style.pointerEvents === "none") {
|
|
960
|
+
target.style.pointerEvents = "auto";
|
|
961
|
+
}
|
|
962
|
+
const onClick = () => {
|
|
963
|
+
if (this.isDestroyed()) return;
|
|
964
|
+
if (this.closeFn) {
|
|
965
|
+
this.closeFn();
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
const allowed = this.getAllowedIds();
|
|
969
|
+
const snaps = this.getResolvedSnaps();
|
|
970
|
+
const fallback = allowed.find((id) => {
|
|
971
|
+
const snap = findById(id, snaps);
|
|
972
|
+
return snap !== null && snap.size === 0;
|
|
973
|
+
});
|
|
974
|
+
if (fallback) this.snapToFn(fallback);
|
|
975
|
+
};
|
|
976
|
+
target.addEventListener("click", onClick);
|
|
977
|
+
this.detachScrimTap = () => target.removeEventListener("click", onClick);
|
|
978
|
+
this.scrimTapToCloseEnabled = true;
|
|
979
|
+
} else {
|
|
980
|
+
this.detachScrimTap?.();
|
|
981
|
+
this.detachScrimTap = null;
|
|
982
|
+
this.scrimTapToCloseEnabled = false;
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
setScrimEnabled(enabled, applySize) {
|
|
986
|
+
if (this.isDestroyed()) return;
|
|
987
|
+
if (enabled === this.scrimEnabled) return;
|
|
988
|
+
this.scrimEnabled = enabled;
|
|
989
|
+
this.invalidateOpacityCache();
|
|
990
|
+
if (!enabled) {
|
|
991
|
+
this.savedScrimRanges = {
|
|
992
|
+
screen: this.screenRange,
|
|
993
|
+
backdrop: this.backdropRange
|
|
994
|
+
};
|
|
995
|
+
this.screenRange = [1, 1];
|
|
996
|
+
this.backdropRange = [1, 1];
|
|
997
|
+
} else {
|
|
998
|
+
this.screenRange = this.savedScrimRanges?.screen ?? [0, 1];
|
|
999
|
+
this.backdropRange = this.savedScrimRanges?.backdrop ?? [0, 1];
|
|
1000
|
+
this.savedScrimRanges = null;
|
|
1001
|
+
}
|
|
1002
|
+
applySize();
|
|
1003
|
+
}
|
|
1004
|
+
setScrim(opts, applySize) {
|
|
1005
|
+
if (this.isDestroyed()) return;
|
|
1006
|
+
if (opts.preset) {
|
|
1007
|
+
const cfg = SCRIM_PRESETS[opts.preset];
|
|
1008
|
+
this.applyScrimStyles({
|
|
1009
|
+
color: cfg.color,
|
|
1010
|
+
blur: cfg.blur ?? null,
|
|
1011
|
+
interactive: cfg.interactive
|
|
1012
|
+
});
|
|
1013
|
+
if (!this.scrimEnabled && this.savedScrimRanges) {
|
|
1014
|
+
this.savedScrimRanges = { screen: cfg.range, backdrop: cfg.range };
|
|
1015
|
+
} else {
|
|
1016
|
+
this.screenRange = cfg.range;
|
|
1017
|
+
this.backdropRange = cfg.range;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
const noop = () => {
|
|
1021
|
+
};
|
|
1022
|
+
if (opts.mode !== void 0) this.setScrimMode(opts.mode, noop);
|
|
1023
|
+
if (opts.enabled !== void 0) this.setScrimEnabled(opts.enabled, noop);
|
|
1024
|
+
if (opts.tapToClose !== void 0) this.setScrimTapToClose(opts.tapToClose);
|
|
1025
|
+
this.applyScrimStyles({
|
|
1026
|
+
color: opts.color,
|
|
1027
|
+
blur: opts.blur,
|
|
1028
|
+
interactive: opts.interactive
|
|
1029
|
+
});
|
|
1030
|
+
if (opts.range !== void 0) {
|
|
1031
|
+
if (!this.scrimEnabled && this.savedScrimRanges) {
|
|
1032
|
+
this.savedScrimRanges = {
|
|
1033
|
+
screen: opts.range,
|
|
1034
|
+
backdrop: this.savedScrimRanges.backdrop
|
|
1035
|
+
};
|
|
1036
|
+
} else {
|
|
1037
|
+
this.screenRange = opts.range;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
this.invalidateOpacityCache();
|
|
1041
|
+
applySize();
|
|
1042
|
+
}
|
|
1043
|
+
setScrimOverlay(opts) {
|
|
1044
|
+
if (this.isDestroyed()) return () => {
|
|
1045
|
+
};
|
|
1046
|
+
if (!this.screenComponent) return () => {
|
|
1047
|
+
};
|
|
1048
|
+
this.scrimOverlayTeardown?.();
|
|
1049
|
+
const screen = this.screenComponent;
|
|
1050
|
+
const insetRaw = opts.inset ?? "16px";
|
|
1051
|
+
const inset = VALID_CSS_LENGTH.test(insetRaw) ? insetRaw : "16px";
|
|
1052
|
+
if (inset !== insetRaw) {
|
|
1053
|
+
devWarn(
|
|
1054
|
+
`[bottom-sheet] setScrimOverlay: invalid inset ${JSON.stringify(insetRaw)}; expected a CSS length like "16px" / "1rem" / "5%". Falling back to "16px".`
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
if (opts.children.ownerDocument && opts.children.ownerDocument !== screen.ownerDocument) {
|
|
1058
|
+
devWarn(
|
|
1059
|
+
"[bottom-sheet] setScrimOverlay: children belong to a different document than the scrim. Cross-document adoption can drop event listeners; construct children via the same document as the sheet root."
|
|
1060
|
+
);
|
|
1061
|
+
}
|
|
1062
|
+
const position = opts.position ?? "top-right";
|
|
1063
|
+
const interactive = opts.interactive ?? true;
|
|
1064
|
+
const wrapper = screen.ownerDocument.createElement("div");
|
|
1065
|
+
wrapper.className = "bs-scrim-overlay";
|
|
1066
|
+
const ws = wrapper.style;
|
|
1067
|
+
ws.position = "absolute";
|
|
1068
|
+
applyOverlayPosition(ws, this.mode, position, inset);
|
|
1069
|
+
if (interactive) {
|
|
1070
|
+
ws.pointerEvents = "auto";
|
|
1071
|
+
}
|
|
1072
|
+
wrapper.appendChild(opts.children);
|
|
1073
|
+
const host = screen.parentElement;
|
|
1074
|
+
if (!host) {
|
|
1075
|
+
devWarn(
|
|
1076
|
+
"[bottom-sheet] setScrimOverlay: scrim element has no parent, skipping overlay injection. Mount the sheet root before calling setScrimOverlay."
|
|
1077
|
+
);
|
|
1078
|
+
return () => {
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
host.appendChild(wrapper);
|
|
1082
|
+
const teardown = () => {
|
|
1083
|
+
if (wrapper.parentNode) wrapper.parentNode.removeChild(wrapper);
|
|
1084
|
+
if (this.scrimOverlayTeardown === teardown) {
|
|
1085
|
+
this.scrimOverlayTeardown = null;
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
this.scrimOverlayTeardown = teardown;
|
|
1089
|
+
return teardown;
|
|
1090
|
+
}
|
|
1091
|
+
destroy() {
|
|
1092
|
+
this.detachScrimTap?.();
|
|
1093
|
+
this.detachScrimTap = null;
|
|
1094
|
+
this.scrimOverlayTeardown?.();
|
|
1095
|
+
this.scrimOverlayTeardown = null;
|
|
1096
|
+
if (this.screenComponent) {
|
|
1097
|
+
const s = this.screenComponent.style;
|
|
1098
|
+
s.opacity = "";
|
|
1099
|
+
s.display = "";
|
|
1100
|
+
}
|
|
1101
|
+
if (this.backdrop) {
|
|
1102
|
+
this.backdrop.style.opacity = "";
|
|
1103
|
+
this.backdrop.style.pointerEvents = "";
|
|
1104
|
+
}
|
|
1105
|
+
this.invalidateOpacityCache();
|
|
1106
|
+
this.lastBackdropPointer = "";
|
|
1107
|
+
this.lastScreenDisplay = "";
|
|
1108
|
+
}
|
|
1109
|
+
applyScrimStyles(opts) {
|
|
1110
|
+
if (!this.screenComponent) return;
|
|
1111
|
+
const s = this.screenComponent.style;
|
|
1112
|
+
if (opts.color !== void 0) {
|
|
1113
|
+
s.background = opts.color === null ? "" : opts.color;
|
|
1114
|
+
}
|
|
1115
|
+
if (opts.blur !== void 0) {
|
|
1116
|
+
const w = s;
|
|
1117
|
+
if (opts.blur === null) {
|
|
1118
|
+
s.backdropFilter = "";
|
|
1119
|
+
w.webkitBackdropFilter = "";
|
|
1120
|
+
} else {
|
|
1121
|
+
const filter = `blur(${opts.blur})`;
|
|
1122
|
+
s.backdropFilter = filter;
|
|
1123
|
+
w.webkitBackdropFilter = filter;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
if (opts.interactive !== void 0) {
|
|
1127
|
+
this.scrimInteractive = opts.interactive;
|
|
1128
|
+
s.pointerEvents = opts.interactive ? "auto" : "none";
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
applyAboveSheetInset() {
|
|
1132
|
+
if (!this.screenComponent) return;
|
|
1133
|
+
const insetByMode = {
|
|
1134
|
+
bottom: "0 0 var(--bs-size) 0",
|
|
1135
|
+
top: "var(--bs-size) 0 0 0",
|
|
1136
|
+
left: "0 0 0 var(--bs-size)",
|
|
1137
|
+
right: "0 var(--bs-size) 0 0"
|
|
1138
|
+
};
|
|
1139
|
+
const s = this.screenComponent.style;
|
|
1140
|
+
s.position = "fixed";
|
|
1141
|
+
s.inset = insetByMode[this.mode];
|
|
1142
|
+
s.pointerEvents = this.scrimInteractive || this.scrimTapToCloseEnabled ? "auto" : "none";
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
|
|
1146
|
+
// src/core/animation/animation.ts
|
|
1147
|
+
var easeOutBack = (t) => {
|
|
1148
|
+
const c1 = 1.40158;
|
|
1149
|
+
const c3 = c1 + 1;
|
|
1150
|
+
return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
|
|
1151
|
+
};
|
|
1152
|
+
var easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
|
|
1153
|
+
var easeLinear = (t) => t;
|
|
1154
|
+
var easeOutQuint = (t) => 1 - Math.pow(1 - t, 5);
|
|
1155
|
+
var tween = ({
|
|
1156
|
+
from,
|
|
1157
|
+
to,
|
|
1158
|
+
duration,
|
|
1159
|
+
easing = easeOutCubic,
|
|
1160
|
+
onUpdate
|
|
1161
|
+
}) => {
|
|
1162
|
+
let cancelled = false;
|
|
1163
|
+
let rafId = 0;
|
|
1164
|
+
let resolveFn = null;
|
|
1165
|
+
const start = performance.now();
|
|
1166
|
+
const promise = new Promise((resolve) => {
|
|
1167
|
+
resolveFn = resolve;
|
|
1168
|
+
if (duration <= 0) {
|
|
1169
|
+
onUpdate(to);
|
|
1170
|
+
resolve();
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
const step = (now) => {
|
|
1174
|
+
if (cancelled) return;
|
|
1175
|
+
const elapsed = now - start;
|
|
1176
|
+
const t = Math.min(elapsed / duration, 1);
|
|
1177
|
+
const value = from + (to - from) * easing(t);
|
|
1178
|
+
onUpdate(value);
|
|
1179
|
+
if (t < 1) {
|
|
1180
|
+
rafId = requestAnimationFrame(step);
|
|
1181
|
+
} else {
|
|
1182
|
+
resolve();
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
rafId = requestAnimationFrame(step);
|
|
1186
|
+
});
|
|
1187
|
+
return {
|
|
1188
|
+
cancel: () => {
|
|
1189
|
+
cancelled = true;
|
|
1190
|
+
cancelAnimationFrame(rafId);
|
|
1191
|
+
resolveFn?.();
|
|
1192
|
+
},
|
|
1193
|
+
promise
|
|
1194
|
+
};
|
|
1195
|
+
};
|
|
1196
|
+
var prefersReducedMotion = () => {
|
|
1197
|
+
if (typeof window === "undefined" || !window.matchMedia) return false;
|
|
1198
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1199
|
+
};
|
|
1200
|
+
|
|
1201
|
+
// src/core/animation/spring.ts
|
|
1202
|
+
var DEFAULT_SPRING = {
|
|
1203
|
+
stiffness: 220,
|
|
1204
|
+
damping: 26,
|
|
1205
|
+
mass: 1,
|
|
1206
|
+
restDelta: 0.5,
|
|
1207
|
+
restSpeed: 0.5
|
|
1208
|
+
};
|
|
1209
|
+
var MAX_DT = 1 / 30;
|
|
1210
|
+
var runSpring = ({
|
|
1211
|
+
from,
|
|
1212
|
+
to,
|
|
1213
|
+
velocity = 0,
|
|
1214
|
+
config,
|
|
1215
|
+
onUpdate
|
|
1216
|
+
}) => {
|
|
1217
|
+
const cfg = { ...DEFAULT_SPRING, ...config };
|
|
1218
|
+
let cancelled = false;
|
|
1219
|
+
let rafId = 0;
|
|
1220
|
+
let resolveFn = null;
|
|
1221
|
+
let x = from;
|
|
1222
|
+
let v = velocity;
|
|
1223
|
+
let lastTime = performance.now();
|
|
1224
|
+
const promise = new Promise((resolve) => {
|
|
1225
|
+
resolveFn = resolve;
|
|
1226
|
+
const step = (now) => {
|
|
1227
|
+
if (cancelled) return;
|
|
1228
|
+
const dt = Math.min((now - lastTime) / 1e3, MAX_DT);
|
|
1229
|
+
lastTime = now;
|
|
1230
|
+
const steps = Math.max(1, Math.ceil(dt * 240));
|
|
1231
|
+
const subDt = dt / steps;
|
|
1232
|
+
let stepsLeft = steps;
|
|
1233
|
+
while (stepsLeft-- > 0) {
|
|
1234
|
+
const force = -cfg.stiffness * (x - to) - cfg.damping * v;
|
|
1235
|
+
const accel = force / cfg.mass;
|
|
1236
|
+
v += accel * subDt;
|
|
1237
|
+
x += v * subDt;
|
|
1238
|
+
}
|
|
1239
|
+
if (!Number.isFinite(x) || !Number.isFinite(v)) {
|
|
1240
|
+
onUpdate(to, 0);
|
|
1241
|
+
resolve();
|
|
1242
|
+
return;
|
|
1243
|
+
}
|
|
1244
|
+
onUpdate(x, v);
|
|
1245
|
+
const isAtRest = Math.abs(to - x) < (cfg.restDelta ?? 0.5) && Math.abs(v) < (cfg.restSpeed ?? 0.5);
|
|
1246
|
+
if (isAtRest) {
|
|
1247
|
+
onUpdate(to, 0);
|
|
1248
|
+
resolve();
|
|
1249
|
+
} else {
|
|
1250
|
+
rafId = requestAnimationFrame(step);
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
rafId = requestAnimationFrame(step);
|
|
1254
|
+
});
|
|
1255
|
+
return {
|
|
1256
|
+
cancel: () => {
|
|
1257
|
+
cancelled = true;
|
|
1258
|
+
cancelAnimationFrame(rafId);
|
|
1259
|
+
resolveFn?.();
|
|
1260
|
+
},
|
|
1261
|
+
promise
|
|
1262
|
+
};
|
|
1263
|
+
};
|
|
1264
|
+
|
|
1265
|
+
// src/core/animation/animation-presets.ts
|
|
1266
|
+
var DEFAULT_DURATION = 220;
|
|
1267
|
+
function resolveAnimationPreset(animation) {
|
|
1268
|
+
switch (animation) {
|
|
1269
|
+
case "ios-spring":
|
|
1270
|
+
return {
|
|
1271
|
+
kind: "spring",
|
|
1272
|
+
spring: { stiffness: 300, damping: 30, mass: 1 }
|
|
1273
|
+
};
|
|
1274
|
+
case "material-bounce":
|
|
1275
|
+
return {
|
|
1276
|
+
kind: "spring",
|
|
1277
|
+
spring: { stiffness: 200, damping: 22, mass: 1 }
|
|
1278
|
+
};
|
|
1279
|
+
case "linear":
|
|
1280
|
+
return { kind: "tween", duration: DEFAULT_DURATION, easing: easeLinear };
|
|
1281
|
+
case "snappy":
|
|
1282
|
+
return { kind: "tween", duration: 180, easing: easeOutQuint };
|
|
1283
|
+
case "tween":
|
|
1284
|
+
return { kind: "tween" };
|
|
1285
|
+
case "spring":
|
|
1286
|
+
case void 0:
|
|
1287
|
+
default:
|
|
1288
|
+
return { kind: "spring" };
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
// src/core/controllers/animation-runner.ts
|
|
1293
|
+
var DEFAULT_DURATION2 = 220;
|
|
1294
|
+
var VELOCITY_PX_PER_S = 1e3;
|
|
1295
|
+
var AnimationRunner = class {
|
|
1296
|
+
element;
|
|
1297
|
+
getRootEl;
|
|
1298
|
+
applySizeFn;
|
|
1299
|
+
getSize;
|
|
1300
|
+
isDragging;
|
|
1301
|
+
animationKind;
|
|
1302
|
+
springConfig;
|
|
1303
|
+
duration;
|
|
1304
|
+
easing;
|
|
1305
|
+
respectReducedMotion;
|
|
1306
|
+
reducedMotion = false;
|
|
1307
|
+
detachReducedMotion = null;
|
|
1308
|
+
viewTransitionsAvailable;
|
|
1309
|
+
currentTween = null;
|
|
1310
|
+
currentSpring = null;
|
|
1311
|
+
constructor(deps, opts) {
|
|
1312
|
+
this.element = deps.element;
|
|
1313
|
+
this.getRootEl = deps.getRootEl;
|
|
1314
|
+
this.applySizeFn = deps.applySize;
|
|
1315
|
+
this.getSize = deps.getSize;
|
|
1316
|
+
this.isDragging = deps.isDragging;
|
|
1317
|
+
const preset = resolveAnimationPreset(opts.animation);
|
|
1318
|
+
this.animationKind = preset.kind;
|
|
1319
|
+
this.duration = opts.duration ?? preset.duration ?? DEFAULT_DURATION2;
|
|
1320
|
+
this.easing = opts.easing ?? preset.easing ?? easeOutBack;
|
|
1321
|
+
this.springConfig = { ...preset.spring ?? {}, ...opts.spring ?? {} };
|
|
1322
|
+
this.respectReducedMotion = opts.respectReducedMotion ?? true;
|
|
1323
|
+
const viewTransitionsEnabled = opts.viewTransitions ?? false;
|
|
1324
|
+
this.viewTransitionsAvailable = viewTransitionsEnabled && typeof document !== "undefined" && typeof document.startViewTransition === "function";
|
|
1325
|
+
if (this.respectReducedMotion && typeof window !== "undefined" && typeof window.matchMedia === "function") {
|
|
1326
|
+
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
1327
|
+
this.reducedMotion = mq.matches;
|
|
1328
|
+
const onMqChange = (e) => {
|
|
1329
|
+
this.reducedMotion = e.matches;
|
|
1330
|
+
};
|
|
1331
|
+
if (typeof mq.addEventListener === "function") {
|
|
1332
|
+
mq.addEventListener("change", onMqChange);
|
|
1333
|
+
this.detachReducedMotion = () => mq.removeEventListener("change", onMqChange);
|
|
1334
|
+
} else if (typeof mq.addListener === "function") {
|
|
1335
|
+
mq.addListener(onMqChange);
|
|
1336
|
+
this.detachReducedMotion = () => mq.removeListener(onMqChange);
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
get isAnimating() {
|
|
1341
|
+
return this.currentTween !== null || this.currentSpring !== null;
|
|
1342
|
+
}
|
|
1343
|
+
cancel() {
|
|
1344
|
+
this.currentTween?.cancel();
|
|
1345
|
+
this.currentSpring?.cancel();
|
|
1346
|
+
}
|
|
1347
|
+
async animateTo(target, velocityPxPerMs) {
|
|
1348
|
+
if (target === this.getSize()) return;
|
|
1349
|
+
this.currentTween?.cancel();
|
|
1350
|
+
this.currentSpring?.cancel();
|
|
1351
|
+
this.getRootEl()?.setAttribute("data-animating", "true");
|
|
1352
|
+
this.element.style.willChange = "transform";
|
|
1353
|
+
if (this.reducedMotion) {
|
|
1354
|
+
this.applySizeFn(target);
|
|
1355
|
+
this.getRootEl()?.removeAttribute("data-animating");
|
|
1356
|
+
if (!this.isDragging()) this.element.style.willChange = "auto";
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
1359
|
+
if (this.animationKind === "spring") {
|
|
1360
|
+
const spring = runSpring({
|
|
1361
|
+
from: this.getSize(),
|
|
1362
|
+
to: target,
|
|
1363
|
+
velocity: velocityPxPerMs * VELOCITY_PX_PER_S,
|
|
1364
|
+
config: this.springConfig,
|
|
1365
|
+
onUpdate: (v) => this.applySizeFn(v)
|
|
1366
|
+
});
|
|
1367
|
+
this.currentSpring = spring;
|
|
1368
|
+
await spring.promise;
|
|
1369
|
+
if (this.currentSpring === spring) this.currentSpring = null;
|
|
1370
|
+
} else {
|
|
1371
|
+
const tw = tween({
|
|
1372
|
+
from: this.getSize(),
|
|
1373
|
+
to: target,
|
|
1374
|
+
duration: this.duration,
|
|
1375
|
+
easing: this.easing,
|
|
1376
|
+
onUpdate: (v) => this.applySizeFn(v)
|
|
1377
|
+
});
|
|
1378
|
+
this.currentTween = tw;
|
|
1379
|
+
await tw.promise;
|
|
1380
|
+
if (this.currentTween === tw) this.currentTween = null;
|
|
1381
|
+
}
|
|
1382
|
+
if (!this.isAnimating) {
|
|
1383
|
+
this.getRootEl()?.removeAttribute("data-animating");
|
|
1384
|
+
if (!this.isDragging()) this.element.style.willChange = "auto";
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
destroy() {
|
|
1388
|
+
this.detachReducedMotion?.();
|
|
1389
|
+
this.detachReducedMotion = null;
|
|
1390
|
+
this.currentTween = null;
|
|
1391
|
+
this.currentSpring = null;
|
|
1392
|
+
}
|
|
1393
|
+
};
|
|
1394
|
+
|
|
1395
|
+
// src/core/lifecycle/focusTrap.ts
|
|
1396
|
+
var FOCUSABLE = [
|
|
1397
|
+
"a[href]",
|
|
1398
|
+
"area[href]",
|
|
1399
|
+
"button:not([disabled])",
|
|
1400
|
+
"input:not([disabled]):not([type='hidden'])",
|
|
1401
|
+
"select:not([disabled])",
|
|
1402
|
+
"textarea:not([disabled])",
|
|
1403
|
+
"iframe",
|
|
1404
|
+
"object",
|
|
1405
|
+
"embed",
|
|
1406
|
+
"[contenteditable='true']",
|
|
1407
|
+
"[tabindex]:not([tabindex='-1'])"
|
|
1408
|
+
].join(",");
|
|
1409
|
+
var isVisible = (el) => {
|
|
1410
|
+
if (typeof el.checkVisibility === "function") {
|
|
1411
|
+
return el.checkVisibility({ checkOpacity: false, checkVisibilityCSS: true });
|
|
1412
|
+
}
|
|
1413
|
+
return el.offsetParent !== null;
|
|
1414
|
+
};
|
|
1415
|
+
var focusables = (root) => Array.from(root.querySelectorAll(FOCUSABLE)).filter(
|
|
1416
|
+
(el) => !el.hasAttribute("inert") && isVisible(el) && !el.matches("[aria-hidden='true']")
|
|
1417
|
+
);
|
|
1418
|
+
var trapStack = [];
|
|
1419
|
+
var installFocusTrap = (container, options = {}) => {
|
|
1420
|
+
if (typeof document === "undefined") return () => {
|
|
1421
|
+
};
|
|
1422
|
+
const token = {};
|
|
1423
|
+
trapStack.push(token);
|
|
1424
|
+
const isActive = () => trapStack[trapStack.length - 1] === token;
|
|
1425
|
+
const previouslyFocused = document.activeElement;
|
|
1426
|
+
const focusInitial = () => {
|
|
1427
|
+
const initial = typeof options.initialFocus === "string" ? container.querySelector(options.initialFocus) : options.initialFocus ?? focusables(container)[0] ?? container;
|
|
1428
|
+
initial?.focus({ preventScroll: true });
|
|
1429
|
+
};
|
|
1430
|
+
focusInitial();
|
|
1431
|
+
const handleKey = (e) => {
|
|
1432
|
+
if (!isActive()) return;
|
|
1433
|
+
if (e.key === "Escape" && options.onEscape) {
|
|
1434
|
+
options.onEscape();
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1437
|
+
if (e.key !== "Tab") return;
|
|
1438
|
+
const list = focusables(container);
|
|
1439
|
+
if (list.length === 0) {
|
|
1440
|
+
e.preventDefault();
|
|
1441
|
+
return;
|
|
1442
|
+
}
|
|
1443
|
+
const first = list[0];
|
|
1444
|
+
const last = list[list.length - 1];
|
|
1445
|
+
const active = document.activeElement;
|
|
1446
|
+
if (e.shiftKey && active === first) {
|
|
1447
|
+
e.preventDefault();
|
|
1448
|
+
last.focus();
|
|
1449
|
+
} else if (!e.shiftKey && active === last) {
|
|
1450
|
+
e.preventDefault();
|
|
1451
|
+
first.focus();
|
|
1452
|
+
}
|
|
1453
|
+
};
|
|
1454
|
+
const handleFocusIn = (e) => {
|
|
1455
|
+
if (!isActive()) return;
|
|
1456
|
+
const target = e.target;
|
|
1457
|
+
if (target && !container.contains(target)) {
|
|
1458
|
+
const list = focusables(container);
|
|
1459
|
+
list[0]?.focus({ preventScroll: true });
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
document.addEventListener("keydown", handleKey, true);
|
|
1463
|
+
document.addEventListener("focusin", handleFocusIn, true);
|
|
1464
|
+
let released = false;
|
|
1465
|
+
return () => {
|
|
1466
|
+
if (released) return;
|
|
1467
|
+
released = true;
|
|
1468
|
+
const idx = trapStack.indexOf(token);
|
|
1469
|
+
if (idx !== -1) trapStack.splice(idx, 1);
|
|
1470
|
+
document.removeEventListener("keydown", handleKey, true);
|
|
1471
|
+
document.removeEventListener("focusin", handleFocusIn, true);
|
|
1472
|
+
if (previouslyFocused && document.contains(previouslyFocused)) {
|
|
1473
|
+
previouslyFocused.focus({ preventScroll: true });
|
|
1474
|
+
} else {
|
|
1475
|
+
const fallback = document.querySelector("[data-bs-restore-fallback]");
|
|
1476
|
+
fallback?.focus({ preventScroll: true });
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
};
|
|
1480
|
+
|
|
1481
|
+
// src/core/lifecycle/scrollLock.ts
|
|
1482
|
+
var lockCount = 0;
|
|
1483
|
+
var savedStyles = null;
|
|
1484
|
+
var lockBodyScroll = () => {
|
|
1485
|
+
if (typeof document === "undefined") return () => {
|
|
1486
|
+
};
|
|
1487
|
+
if (lockCount === 0) {
|
|
1488
|
+
const body = document.body;
|
|
1489
|
+
savedStyles = {
|
|
1490
|
+
overflow: body.style.overflow,
|
|
1491
|
+
position: body.style.position,
|
|
1492
|
+
top: body.style.top,
|
|
1493
|
+
width: body.style.width,
|
|
1494
|
+
scrollY: window.scrollY
|
|
1495
|
+
};
|
|
1496
|
+
body.style.overflow = "hidden";
|
|
1497
|
+
body.style.position = "fixed";
|
|
1498
|
+
body.style.top = `-${savedStyles.scrollY}px`;
|
|
1499
|
+
body.style.width = "100%";
|
|
1500
|
+
}
|
|
1501
|
+
lockCount++;
|
|
1502
|
+
let released = false;
|
|
1503
|
+
return () => {
|
|
1504
|
+
if (released) return;
|
|
1505
|
+
released = true;
|
|
1506
|
+
lockCount = Math.max(0, lockCount - 1);
|
|
1507
|
+
if (lockCount === 0 && savedStyles) {
|
|
1508
|
+
const body = document.body;
|
|
1509
|
+
body.style.overflow = savedStyles.overflow;
|
|
1510
|
+
body.style.position = savedStyles.position;
|
|
1511
|
+
body.style.top = savedStyles.top;
|
|
1512
|
+
body.style.width = savedStyles.width;
|
|
1513
|
+
window.scrollTo(0, savedStyles.scrollY);
|
|
1514
|
+
savedStyles = null;
|
|
1515
|
+
}
|
|
1516
|
+
};
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
// src/core/features/inert-siblings.ts
|
|
1520
|
+
function createInertSiblings(rootProvider) {
|
|
1521
|
+
const tracked = [];
|
|
1522
|
+
return {
|
|
1523
|
+
apply() {
|
|
1524
|
+
if (typeof document === "undefined") return;
|
|
1525
|
+
let top = rootProvider();
|
|
1526
|
+
while (top.parentElement && top.parentElement !== document.body) {
|
|
1527
|
+
top = top.parentElement;
|
|
1528
|
+
}
|
|
1529
|
+
const parent = top.parentElement ?? document.body;
|
|
1530
|
+
for (const child of Array.from(parent.children)) {
|
|
1531
|
+
if (child === top) continue;
|
|
1532
|
+
if (child.hasAttribute("inert")) continue;
|
|
1533
|
+
if (child.classList.contains("bs-backdrop") || child.classList.contains("bs-screen") || child.classList.contains("bs-root")) {
|
|
1534
|
+
continue;
|
|
1535
|
+
}
|
|
1536
|
+
child.setAttribute("inert", "");
|
|
1537
|
+
tracked.push(child);
|
|
1538
|
+
}
|
|
1539
|
+
},
|
|
1540
|
+
remove() {
|
|
1541
|
+
for (const el of tracked) el.removeAttribute("inert");
|
|
1542
|
+
tracked.length = 0;
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
// src/core/controllers/lifecycle-controller.ts
|
|
1548
|
+
var LifecycleController = class {
|
|
1549
|
+
element;
|
|
1550
|
+
focusTrapEnabled;
|
|
1551
|
+
initialFocus;
|
|
1552
|
+
closeOnEscape;
|
|
1553
|
+
bodyScrollLockEnabled;
|
|
1554
|
+
inertSiblingsEnabled;
|
|
1555
|
+
inertSiblings;
|
|
1556
|
+
shouldApplyInertSiblings;
|
|
1557
|
+
returnFocus;
|
|
1558
|
+
releaseFocusTrap = null;
|
|
1559
|
+
releaseScrollLock = null;
|
|
1560
|
+
installed = false;
|
|
1561
|
+
destroyed = false;
|
|
1562
|
+
get isInstalled() {
|
|
1563
|
+
return this.installed;
|
|
1564
|
+
}
|
|
1565
|
+
constructor(deps, opts) {
|
|
1566
|
+
this.element = deps.element;
|
|
1567
|
+
this.focusTrapEnabled = opts.focusTrap ?? false;
|
|
1568
|
+
this.initialFocus = opts.initialFocus;
|
|
1569
|
+
this.closeOnEscape = opts.closeOnEscape ?? true;
|
|
1570
|
+
this.bodyScrollLockEnabled = opts.lockBodyScroll ?? true;
|
|
1571
|
+
this.inertSiblingsEnabled = opts.inertSiblings ?? false;
|
|
1572
|
+
this.shouldApplyInertSiblings = opts.shouldApplyInertSiblings ?? (() => true);
|
|
1573
|
+
this.returnFocus = opts.returnFocus;
|
|
1574
|
+
this.inertSiblings = createInertSiblings(() => this.element);
|
|
1575
|
+
}
|
|
1576
|
+
install() {
|
|
1577
|
+
if (this.destroyed) return;
|
|
1578
|
+
this.installed = true;
|
|
1579
|
+
if (this.bodyScrollLockEnabled && !this.releaseScrollLock) {
|
|
1580
|
+
this.releaseScrollLock = lockBodyScroll();
|
|
1581
|
+
}
|
|
1582
|
+
if (this.focusTrapEnabled && !this.releaseFocusTrap) {
|
|
1583
|
+
this.releaseFocusTrap = installFocusTrap(this.element, {
|
|
1584
|
+
initialFocus: this.initialFocus
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
if (this.inertSiblingsEnabled && this.shouldApplyInertSiblings()) {
|
|
1588
|
+
this.inertSiblings.apply();
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
setReturnFocus(target) {
|
|
1592
|
+
if (this.destroyed) return;
|
|
1593
|
+
this.returnFocus = target;
|
|
1594
|
+
}
|
|
1595
|
+
release() {
|
|
1596
|
+
if (!this.installed) return;
|
|
1597
|
+
this.installed = false;
|
|
1598
|
+
this.releaseFocusTrap?.();
|
|
1599
|
+
this.releaseFocusTrap = null;
|
|
1600
|
+
this.releaseScrollLock?.();
|
|
1601
|
+
this.releaseScrollLock = null;
|
|
1602
|
+
this.inertSiblings.remove();
|
|
1603
|
+
if (this.returnFocus) {
|
|
1604
|
+
const target = typeof this.returnFocus === "function" ? this.returnFocus() : this.returnFocus;
|
|
1605
|
+
target?.focus?.();
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
destroy() {
|
|
1609
|
+
this.release();
|
|
1610
|
+
this.destroyed = true;
|
|
1611
|
+
}
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
// src/core/gestures.ts
|
|
1615
|
+
var isAxisVertical = (mode) => mode === "bottom" || mode === "top";
|
|
1616
|
+
var SampleRing = class {
|
|
1617
|
+
slots;
|
|
1618
|
+
capacity;
|
|
1619
|
+
head = 0;
|
|
1620
|
+
size = 0;
|
|
1621
|
+
constructor(capacity) {
|
|
1622
|
+
this.capacity = capacity;
|
|
1623
|
+
this.slots = new Array(capacity);
|
|
1624
|
+
for (let i = 0; i < capacity; i++) this.slots[i] = { t: 0, v: 0 };
|
|
1625
|
+
}
|
|
1626
|
+
push(t, v) {
|
|
1627
|
+
const slot = this.slots[this.head];
|
|
1628
|
+
slot.t = t;
|
|
1629
|
+
slot.v = v;
|
|
1630
|
+
this.head = (this.head + 1) % this.capacity;
|
|
1631
|
+
if (this.size < this.capacity) this.size++;
|
|
1632
|
+
}
|
|
1633
|
+
pruneBefore(cutoff, minKeep) {
|
|
1634
|
+
while (this.size > minKeep) {
|
|
1635
|
+
const oldestIdx = (this.head - this.size + this.capacity) % this.capacity;
|
|
1636
|
+
if (this.slots[oldestIdx].t < cutoff) this.size--;
|
|
1637
|
+
else break;
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
get length() {
|
|
1641
|
+
return this.size;
|
|
1642
|
+
}
|
|
1643
|
+
oldest() {
|
|
1644
|
+
if (this.size === 0) return void 0;
|
|
1645
|
+
return this.slots[(this.head - this.size + this.capacity) % this.capacity];
|
|
1646
|
+
}
|
|
1647
|
+
newest() {
|
|
1648
|
+
if (this.size === 0) return void 0;
|
|
1649
|
+
return this.slots[(this.head - 1 + this.capacity) % this.capacity];
|
|
1650
|
+
}
|
|
1651
|
+
reset() {
|
|
1652
|
+
this.head = 0;
|
|
1653
|
+
this.size = 0;
|
|
1654
|
+
}
|
|
1655
|
+
};
|
|
1656
|
+
var installGestures = (handle, mode, callbacks) => {
|
|
1657
|
+
let activePointerId = null;
|
|
1658
|
+
let activePointerType = "touch";
|
|
1659
|
+
let startCoord = 0;
|
|
1660
|
+
let lastCoord = 0;
|
|
1661
|
+
const VELOCITY_WINDOW_MS = (kind) => kind === "mouse" ? 160 : 120;
|
|
1662
|
+
const MAX_SAMPLES = 32;
|
|
1663
|
+
const samples = new SampleRing(MAX_SAMPLES);
|
|
1664
|
+
const axis = isAxisVertical(mode) ? "Y" : "X";
|
|
1665
|
+
const sign = mode === "bottom" || mode === "right" ? -1 : 1;
|
|
1666
|
+
const coordOf = (e) => axis === "Y" ? e.clientY : e.clientX;
|
|
1667
|
+
const onPointerDown = (e) => {
|
|
1668
|
+
if (activePointerId !== null) return;
|
|
1669
|
+
if (e.button !== void 0 && e.button !== 0) return;
|
|
1670
|
+
activePointerId = e.pointerId;
|
|
1671
|
+
activePointerType = e.pointerType || "touch";
|
|
1672
|
+
startCoord = coordOf(e);
|
|
1673
|
+
lastCoord = startCoord;
|
|
1674
|
+
samples.reset();
|
|
1675
|
+
samples.push(e.timeStamp, startCoord);
|
|
1676
|
+
try {
|
|
1677
|
+
handle.setPointerCapture(e.pointerId);
|
|
1678
|
+
} catch {
|
|
1679
|
+
}
|
|
1680
|
+
callbacks.onStart(startCoord, activePointerType);
|
|
1681
|
+
};
|
|
1682
|
+
const onPointerMove = (e) => {
|
|
1683
|
+
if (e.pointerId !== activePointerId) return;
|
|
1684
|
+
const coord = coordOf(e);
|
|
1685
|
+
const rawDelta = coord - startCoord;
|
|
1686
|
+
const delta = rawDelta * sign;
|
|
1687
|
+
lastCoord = coord;
|
|
1688
|
+
samples.push(e.timeStamp, coord);
|
|
1689
|
+
const cutoff = e.timeStamp - VELOCITY_WINDOW_MS(activePointerType);
|
|
1690
|
+
samples.pruneBefore(cutoff, 2);
|
|
1691
|
+
callbacks.onMove(delta);
|
|
1692
|
+
};
|
|
1693
|
+
const finishGesture = (e) => {
|
|
1694
|
+
if (e.pointerId !== activePointerId) return;
|
|
1695
|
+
const rawDelta = lastCoord - startCoord;
|
|
1696
|
+
const delta = rawDelta * sign;
|
|
1697
|
+
let velocity = 0;
|
|
1698
|
+
if (samples.length >= 3) {
|
|
1699
|
+
const first = samples.oldest();
|
|
1700
|
+
const last = samples.newest();
|
|
1701
|
+
const dt = last.t - first.t;
|
|
1702
|
+
if (dt > 0) velocity = (last.v - first.v) / dt * sign;
|
|
1703
|
+
}
|
|
1704
|
+
const finishedKind = activePointerType;
|
|
1705
|
+
activePointerId = null;
|
|
1706
|
+
samples.reset();
|
|
1707
|
+
try {
|
|
1708
|
+
if (handle.hasPointerCapture(e.pointerId)) {
|
|
1709
|
+
handle.releasePointerCapture(e.pointerId);
|
|
1710
|
+
}
|
|
1711
|
+
} catch {
|
|
1712
|
+
}
|
|
1713
|
+
callbacks.onEnd(delta, velocity, finishedKind);
|
|
1714
|
+
};
|
|
1715
|
+
const onPointerCancel = (e) => {
|
|
1716
|
+
if (e.pointerId !== activePointerId) return;
|
|
1717
|
+
activePointerId = null;
|
|
1718
|
+
samples.reset();
|
|
1719
|
+
callbacks.onCancel?.();
|
|
1720
|
+
};
|
|
1721
|
+
handle.addEventListener("pointerdown", onPointerDown);
|
|
1722
|
+
handle.addEventListener("pointermove", onPointerMove);
|
|
1723
|
+
handle.addEventListener("pointerup", finishGesture);
|
|
1724
|
+
handle.addEventListener("pointercancel", onPointerCancel);
|
|
1725
|
+
handle.style.touchAction = isAxisVertical(mode) ? "pan-x" : "pan-y";
|
|
1726
|
+
return () => {
|
|
1727
|
+
handle.removeEventListener("pointerdown", onPointerDown);
|
|
1728
|
+
handle.removeEventListener("pointermove", onPointerMove);
|
|
1729
|
+
handle.removeEventListener("pointerup", finishGesture);
|
|
1730
|
+
handle.removeEventListener("pointercancel", onPointerCancel);
|
|
1731
|
+
if (activePointerId !== null && handle.hasPointerCapture(activePointerId)) {
|
|
1732
|
+
handle.releasePointerCapture(activePointerId);
|
|
1733
|
+
}
|
|
1734
|
+
};
|
|
1735
|
+
};
|
|
1736
|
+
|
|
1737
|
+
// src/core/primitives/rubber-band.ts
|
|
1738
|
+
function rubberBand(overshoot, maxAxisSize) {
|
|
1739
|
+
const cap = Math.min(maxAxisSize * 0.15, 80);
|
|
1740
|
+
if (cap <= 0) return 0;
|
|
1741
|
+
const abs = Math.abs(overshoot);
|
|
1742
|
+
return Math.sign(overshoot) * (cap * abs / (abs + cap));
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
// src/core/features/soft-keyboard.ts
|
|
1746
|
+
function dismissSoftKeyboardIfFocused(root) {
|
|
1747
|
+
if (typeof document === "undefined") return false;
|
|
1748
|
+
const active = document.activeElement;
|
|
1749
|
+
if (!active) return false;
|
|
1750
|
+
if (!root.contains(active)) return false;
|
|
1751
|
+
const tag = active.tagName;
|
|
1752
|
+
const isEditable = tag === "INPUT" || tag === "TEXTAREA" || active.isContentEditable === true;
|
|
1753
|
+
if (!isEditable) return false;
|
|
1754
|
+
try {
|
|
1755
|
+
active.blur();
|
|
1756
|
+
return true;
|
|
1757
|
+
} catch {
|
|
1758
|
+
return false;
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
// src/core/controllers/gesture-controller.ts
|
|
1763
|
+
var GestureController = class {
|
|
1764
|
+
deps;
|
|
1765
|
+
detach = null;
|
|
1766
|
+
isDragging_ = false;
|
|
1767
|
+
dragStartSize = 0;
|
|
1768
|
+
currentPointerKind = "touch";
|
|
1769
|
+
keyboardDismissed = false;
|
|
1770
|
+
dragPayload = { size: 0, delta: 0 };
|
|
1771
|
+
constructor(deps) {
|
|
1772
|
+
this.deps = deps;
|
|
1773
|
+
}
|
|
1774
|
+
get isDragging() {
|
|
1775
|
+
return this.isDragging_;
|
|
1776
|
+
}
|
|
1777
|
+
install() {
|
|
1778
|
+
if (this.detach) return this.detach;
|
|
1779
|
+
this.detach = installGestures(this.deps.handle, this.deps.mode, {
|
|
1780
|
+
onStart: (_coord, kind) => {
|
|
1781
|
+
this.deps.cancelAnimation();
|
|
1782
|
+
this.isDragging_ = true;
|
|
1783
|
+
this.dragStartSize = this.deps.getDragContext().size;
|
|
1784
|
+
this.currentPointerKind = kind;
|
|
1785
|
+
this.keyboardDismissed = false;
|
|
1786
|
+
this.deps.getRoot()?.setAttribute("data-dragging", "true");
|
|
1787
|
+
this.deps.element.style.willChange = "transform";
|
|
1788
|
+
this.deps.emit("dragstart", { size: this.dragStartSize });
|
|
1789
|
+
},
|
|
1790
|
+
onMove: (delta) => {
|
|
1791
|
+
const ctx = this.deps.getDragContext();
|
|
1792
|
+
const { min, max } = ctx.range;
|
|
1793
|
+
const maxAxis = ctx.maxAxisSize;
|
|
1794
|
+
const rubberOn = ctx.rubberBandEnabled;
|
|
1795
|
+
let next = this.dragStartSize + delta;
|
|
1796
|
+
if (next > max) {
|
|
1797
|
+
next = rubberOn ? max + rubberBand(next - max, maxAxis) : max;
|
|
1798
|
+
} else if (next < min) {
|
|
1799
|
+
next = rubberOn ? min - rubberBand(min - next, maxAxis) : min;
|
|
1800
|
+
}
|
|
1801
|
+
this.deps.applySize(next);
|
|
1802
|
+
if (!this.keyboardDismissed && this.currentPointerKind === "touch" && this.deps.mode === "bottom" && next < this.dragStartSize) {
|
|
1803
|
+
if (dismissSoftKeyboardIfFocused(this.deps.element)) {
|
|
1804
|
+
this.keyboardDismissed = true;
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
if (this.deps.listenerCount("drag") > 0) {
|
|
1808
|
+
this.dragPayload.size = next;
|
|
1809
|
+
this.dragPayload.delta = delta;
|
|
1810
|
+
this.deps.emit("drag", this.dragPayload);
|
|
1811
|
+
}
|
|
1812
|
+
},
|
|
1813
|
+
onEnd: (delta, velocity, kind) => {
|
|
1814
|
+
this.isDragging_ = false;
|
|
1815
|
+
this.keyboardDismissed = false;
|
|
1816
|
+
this.deps.getRoot()?.removeAttribute("data-dragging");
|
|
1817
|
+
this.deps.emit("dragend", {
|
|
1818
|
+
size: this.deps.getDragContext().size,
|
|
1819
|
+
velocity
|
|
1820
|
+
});
|
|
1821
|
+
this.deps.settleAfterDrag(delta, velocity, kind);
|
|
1822
|
+
},
|
|
1823
|
+
onCancel: () => {
|
|
1824
|
+
this.isDragging_ = false;
|
|
1825
|
+
this.keyboardDismissed = false;
|
|
1826
|
+
this.deps.getRoot()?.removeAttribute("data-dragging");
|
|
1827
|
+
this.deps.emit("dragend", {
|
|
1828
|
+
size: this.deps.getDragContext().size,
|
|
1829
|
+
velocity: 0
|
|
1830
|
+
});
|
|
1831
|
+
const restoreTo = this.dragStartSize;
|
|
1832
|
+
void this.deps.animateTo(restoreTo, 0);
|
|
1833
|
+
}
|
|
1834
|
+
});
|
|
1835
|
+
return this.detach;
|
|
1836
|
+
}
|
|
1837
|
+
forceClearDragState() {
|
|
1838
|
+
if (!this.isDragging_) return;
|
|
1839
|
+
this.isDragging_ = false;
|
|
1840
|
+
this.keyboardDismissed = false;
|
|
1841
|
+
this.deps.getRoot()?.removeAttribute("data-dragging");
|
|
1842
|
+
this.deps.element.style.willChange = "auto";
|
|
1843
|
+
}
|
|
1844
|
+
};
|
|
1845
|
+
|
|
1846
|
+
// src/core/primitives/aria-slider-writer.ts
|
|
1847
|
+
var AriaSliderWriter = class {
|
|
1848
|
+
constructor(handle, mode) {
|
|
1849
|
+
this.handle = handle;
|
|
1850
|
+
handle.setAttribute(
|
|
1851
|
+
"aria-orientation",
|
|
1852
|
+
mode === "bottom" || mode === "top" ? "vertical" : "horizontal"
|
|
1853
|
+
);
|
|
1854
|
+
}
|
|
1855
|
+
handle;
|
|
1856
|
+
setValue(allowedIds, activeId) {
|
|
1857
|
+
if (allowedIds.length === 0) {
|
|
1858
|
+
this.handle.removeAttribute("aria-valuemin");
|
|
1859
|
+
this.handle.removeAttribute("aria-valuemax");
|
|
1860
|
+
this.handle.removeAttribute("aria-valuenow");
|
|
1861
|
+
this.handle.removeAttribute("aria-valuetext");
|
|
1862
|
+
return;
|
|
1863
|
+
}
|
|
1864
|
+
const max = Math.max(allowedIds.length - 1, 0);
|
|
1865
|
+
const idx = Math.max(allowedIds.indexOf(activeId), 0);
|
|
1866
|
+
this.handle.setAttribute("aria-valuemin", "0");
|
|
1867
|
+
this.handle.setAttribute("aria-valuemax", String(max));
|
|
1868
|
+
this.handle.setAttribute("aria-valuenow", String(idx));
|
|
1869
|
+
this.handle.setAttribute("aria-valuetext", activeId);
|
|
1870
|
+
}
|
|
1871
|
+
};
|
|
1872
|
+
|
|
1873
|
+
// src/core/features/scroll-cache.ts
|
|
1874
|
+
function createScrollCache(deps) {
|
|
1875
|
+
const positions = /* @__PURE__ */ new Map();
|
|
1876
|
+
const isSmallSize = (size) => {
|
|
1877
|
+
const max = deps.getMaxAxisSize();
|
|
1878
|
+
if (max <= 0) return false;
|
|
1879
|
+
return size < max / 2;
|
|
1880
|
+
};
|
|
1881
|
+
return {
|
|
1882
|
+
cache(fromId, prevSize, nextSize) {
|
|
1883
|
+
const container = deps.scrollContainer;
|
|
1884
|
+
if (!container) return;
|
|
1885
|
+
if (isSmallSize(prevSize)) return;
|
|
1886
|
+
if (!isSmallSize(nextSize)) return;
|
|
1887
|
+
positions.set(fromId, container.scrollTop);
|
|
1888
|
+
},
|
|
1889
|
+
restore(toId, prevSize, nextSize) {
|
|
1890
|
+
const container = deps.scrollContainer;
|
|
1891
|
+
if (!container) return;
|
|
1892
|
+
if (isSmallSize(nextSize)) return;
|
|
1893
|
+
if (!isSmallSize(prevSize)) return;
|
|
1894
|
+
const cached = positions.get(toId);
|
|
1895
|
+
if (cached === void 0) return;
|
|
1896
|
+
container.scrollTop = cached;
|
|
1897
|
+
positions.delete(toId);
|
|
1898
|
+
},
|
|
1899
|
+
clear() {
|
|
1900
|
+
positions.clear();
|
|
1901
|
+
}
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
// src/core/primitives/anchor-animations.ts
|
|
1906
|
+
var DEFAULT_DURATION3 = 200;
|
|
1907
|
+
var DEFAULT_EASING = "cubic-bezier(0.22, 1, 0.36, 1)";
|
|
1908
|
+
var PRESET_FRAMES = {
|
|
1909
|
+
fade: {
|
|
1910
|
+
enter: [{ opacity: 0 }, { opacity: 1 }],
|
|
1911
|
+
exit: [{ opacity: 1 }, { opacity: 0 }]
|
|
1912
|
+
},
|
|
1913
|
+
scale: {
|
|
1914
|
+
enter: [
|
|
1915
|
+
{ opacity: 0, transform: "scale(0.85)" },
|
|
1916
|
+
{ opacity: 1, transform: "scale(1)" }
|
|
1917
|
+
],
|
|
1918
|
+
exit: [
|
|
1919
|
+
{ opacity: 1, transform: "scale(1)" },
|
|
1920
|
+
{ opacity: 0, transform: "scale(0.85)" }
|
|
1921
|
+
]
|
|
1922
|
+
},
|
|
1923
|
+
slide: {
|
|
1924
|
+
enter: [
|
|
1925
|
+
{ opacity: 0, transform: "translateY(10px)" },
|
|
1926
|
+
{ opacity: 1, transform: "translateY(0)" }
|
|
1927
|
+
],
|
|
1928
|
+
exit: [
|
|
1929
|
+
{ opacity: 1, transform: "translateY(0)" },
|
|
1930
|
+
{ opacity: 0, transform: "translateY(10px)" }
|
|
1931
|
+
]
|
|
1932
|
+
},
|
|
1933
|
+
pop: {
|
|
1934
|
+
enter: [
|
|
1935
|
+
{ opacity: 0, transform: "scale(0.6)", offset: 0 },
|
|
1936
|
+
{ opacity: 1, transform: "scale(1.06)", offset: 0.7 },
|
|
1937
|
+
{ opacity: 1, transform: "scale(1)", offset: 1 }
|
|
1938
|
+
],
|
|
1939
|
+
exit: [
|
|
1940
|
+
{ opacity: 1, transform: "scale(1)" },
|
|
1941
|
+
{ opacity: 0, transform: "scale(0.6)" }
|
|
1942
|
+
]
|
|
1943
|
+
}
|
|
1944
|
+
};
|
|
1945
|
+
var INSTANT = {
|
|
1946
|
+
finished: Promise.resolve(),
|
|
1947
|
+
cancel: () => {
|
|
1948
|
+
}
|
|
1949
|
+
};
|
|
1950
|
+
function resolveTransitionFrames(spec, phase) {
|
|
1951
|
+
const fallback = { frames: null, duration: 0, easing: DEFAULT_EASING };
|
|
1952
|
+
if (spec === "none") return fallback;
|
|
1953
|
+
if (spec === void 0 || typeof spec === "string") {
|
|
1954
|
+
const preset2 = PRESET_FRAMES[spec ?? "fade"];
|
|
1955
|
+
return {
|
|
1956
|
+
frames: preset2[phase],
|
|
1957
|
+
duration: DEFAULT_DURATION3,
|
|
1958
|
+
easing: DEFAULT_EASING
|
|
1959
|
+
};
|
|
1960
|
+
}
|
|
1961
|
+
const custom = phase === "enter" ? spec.enter : spec.exit;
|
|
1962
|
+
if (custom) {
|
|
1963
|
+
return {
|
|
1964
|
+
frames: custom,
|
|
1965
|
+
duration: spec.duration ?? DEFAULT_DURATION3,
|
|
1966
|
+
easing: spec.easing ?? DEFAULT_EASING
|
|
1967
|
+
};
|
|
1968
|
+
}
|
|
1969
|
+
if (spec.preset === "none") return fallback;
|
|
1970
|
+
const preset = PRESET_FRAMES[spec.preset ?? "fade"];
|
|
1971
|
+
return {
|
|
1972
|
+
frames: preset[phase],
|
|
1973
|
+
duration: spec.duration ?? DEFAULT_DURATION3,
|
|
1974
|
+
easing: spec.easing ?? DEFAULT_EASING
|
|
1975
|
+
};
|
|
1976
|
+
}
|
|
1977
|
+
function runAnchorTransition(el, spec, phase) {
|
|
1978
|
+
const respectReduced = typeof spec === "object" ? spec.respectReducedMotion !== false : true;
|
|
1979
|
+
if (respectReduced && prefersReducedMotion()) return INSTANT;
|
|
1980
|
+
const { frames, duration, easing } = resolveTransitionFrames(spec, phase);
|
|
1981
|
+
if (!frames || duration <= 0) return INSTANT;
|
|
1982
|
+
if (typeof el.animate !== "function") return INSTANT;
|
|
1983
|
+
const animation = el.animate(frames, {
|
|
1984
|
+
duration,
|
|
1985
|
+
easing,
|
|
1986
|
+
fill: "both"
|
|
1987
|
+
});
|
|
1988
|
+
const finished = animation.finished.then(() => void 0).catch(() => void 0);
|
|
1989
|
+
return {
|
|
1990
|
+
finished,
|
|
1991
|
+
cancel: () => {
|
|
1992
|
+
try {
|
|
1993
|
+
animation.cancel();
|
|
1994
|
+
} catch {
|
|
1995
|
+
return;
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
};
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
// src/core/features/sheet-anchors.ts
|
|
2002
|
+
function attachAnchor(deps, opts) {
|
|
2003
|
+
const doc = deps.host.ownerDocument;
|
|
2004
|
+
const wrapper = doc.createElement("div");
|
|
2005
|
+
wrapper.className = "bs-anchor";
|
|
2006
|
+
const interactive = opts.interactive ?? true;
|
|
2007
|
+
const position = opts.position ?? "sheet-top-right";
|
|
2008
|
+
const isDock = position === "dock-bottom" || position === "dock-top";
|
|
2009
|
+
const ws = wrapper.style;
|
|
2010
|
+
ws.position = "fixed";
|
|
2011
|
+
if (isDock) {
|
|
2012
|
+
ws.left = "0";
|
|
2013
|
+
ws.right = "0";
|
|
2014
|
+
if (position === "dock-bottom") {
|
|
2015
|
+
ws.bottom = "0";
|
|
2016
|
+
} else {
|
|
2017
|
+
ws.top = "0";
|
|
2018
|
+
}
|
|
2019
|
+
} else {
|
|
2020
|
+
applyOverlayPosition(ws, deps.mode, position, opts.inset ?? "16px");
|
|
2021
|
+
}
|
|
2022
|
+
if (opts.fadeRange) {
|
|
2023
|
+
const [r0, r1] = opts.fadeRange;
|
|
2024
|
+
const span = Math.max(r1 - r0, 1e-4);
|
|
2025
|
+
ws.opacity = `clamp(0, calc((var(--bs-progress, 0) - ${r0}) / ${span}), 1)`;
|
|
2026
|
+
}
|
|
2027
|
+
wrapper.appendChild(opts.element);
|
|
2028
|
+
deps.host.appendChild(wrapper);
|
|
2029
|
+
let visible = null;
|
|
2030
|
+
let inFlight = null;
|
|
2031
|
+
const shouldShow = (state) => {
|
|
2032
|
+
if (typeof opts.showOn === "function") return opts.showOn(state);
|
|
2033
|
+
if (Array.isArray(opts.showOn)) return opts.showOn.includes(state.activeId);
|
|
2034
|
+
return isDock || state.size > 0;
|
|
2035
|
+
};
|
|
2036
|
+
const applyVisibility = (next, animate) => {
|
|
2037
|
+
if (next === visible) return;
|
|
2038
|
+
visible = next;
|
|
2039
|
+
inFlight?.cancel();
|
|
2040
|
+
inFlight = null;
|
|
2041
|
+
wrapper.style.pointerEvents = next && interactive ? "auto" : "none";
|
|
2042
|
+
if (next) {
|
|
2043
|
+
wrapper.style.visibility = "";
|
|
2044
|
+
if (animate) {
|
|
2045
|
+
inFlight = runAnchorTransition(opts.element, opts.animation, "enter");
|
|
2046
|
+
}
|
|
2047
|
+
return;
|
|
2048
|
+
}
|
|
2049
|
+
if (!animate) {
|
|
2050
|
+
wrapper.style.visibility = "hidden";
|
|
2051
|
+
return;
|
|
2052
|
+
}
|
|
2053
|
+
const handle = runAnchorTransition(opts.element, opts.animation, "exit");
|
|
2054
|
+
inFlight = handle;
|
|
2055
|
+
void handle.finished.then(() => {
|
|
2056
|
+
if (inFlight === handle && visible === false) {
|
|
2057
|
+
wrapper.style.visibility = "hidden";
|
|
2058
|
+
}
|
|
2059
|
+
});
|
|
2060
|
+
};
|
|
2061
|
+
const evaluate = (animate) => {
|
|
2062
|
+
if (deps.isDestroyed()) return;
|
|
2063
|
+
applyVisibility(shouldShow(deps.getState()), animate);
|
|
2064
|
+
};
|
|
2065
|
+
const offs = [
|
|
2066
|
+
deps.on("snap", () => evaluate(true)),
|
|
2067
|
+
deps.on("open", () => evaluate(true)),
|
|
2068
|
+
deps.on("close", () => evaluate(true))
|
|
2069
|
+
];
|
|
2070
|
+
evaluate(false);
|
|
2071
|
+
return {
|
|
2072
|
+
wrapper,
|
|
2073
|
+
detach: () => {
|
|
2074
|
+
offs.forEach((off) => off());
|
|
2075
|
+
inFlight?.cancel();
|
|
2076
|
+
inFlight = null;
|
|
2077
|
+
if (wrapper.parentNode) wrapper.parentNode.removeChild(wrapper);
|
|
2078
|
+
},
|
|
2079
|
+
syncZ: (z) => {
|
|
2080
|
+
wrapper.style.zIndex = String(z);
|
|
2081
|
+
}
|
|
2082
|
+
};
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
// src/core/features/scrim-stages.ts
|
|
2086
|
+
var matchesId = (def, activeId) => {
|
|
2087
|
+
if (def.for === void 0) return false;
|
|
2088
|
+
return Array.isArray(def.for) ? def.for.includes(activeId) : def.for === activeId;
|
|
2089
|
+
};
|
|
2090
|
+
var matchesRange = (def, progress) => {
|
|
2091
|
+
if (!def.forRange) return false;
|
|
2092
|
+
const [from, to] = def.forRange;
|
|
2093
|
+
return progress >= from && progress <= to;
|
|
2094
|
+
};
|
|
2095
|
+
function installScrimStages(deps, opts) {
|
|
2096
|
+
const doc = deps.host.ownerDocument;
|
|
2097
|
+
const entries = opts.stages.map((def) => {
|
|
2098
|
+
const wrapper = doc.createElement("div");
|
|
2099
|
+
wrapper.className = "bs-scrim-stage";
|
|
2100
|
+
const ws = wrapper.style;
|
|
2101
|
+
ws.position = "absolute";
|
|
2102
|
+
applyOverlayPosition(
|
|
2103
|
+
ws,
|
|
2104
|
+
deps.mode,
|
|
2105
|
+
def.position ?? opts.position ?? "center",
|
|
2106
|
+
def.inset ?? opts.inset ?? "16px"
|
|
2107
|
+
);
|
|
2108
|
+
ws.visibility = "hidden";
|
|
2109
|
+
ws.pointerEvents = "none";
|
|
2110
|
+
wrapper.appendChild(def.element);
|
|
2111
|
+
deps.host.appendChild(wrapper);
|
|
2112
|
+
return { def, wrapper, inFlight: null };
|
|
2113
|
+
});
|
|
2114
|
+
let active = null;
|
|
2115
|
+
const resolveActive = () => {
|
|
2116
|
+
const state = deps.getState();
|
|
2117
|
+
if (state.size === 0) {
|
|
2118
|
+
return entries.find((e) => matchesId(e.def, state.activeId)) ?? null;
|
|
2119
|
+
}
|
|
2120
|
+
return entries.find((e) => matchesId(e.def, state.activeId)) ?? entries.find((e) => matchesRange(e.def, state.progress)) ?? null;
|
|
2121
|
+
};
|
|
2122
|
+
const hide = (entry, animate) => {
|
|
2123
|
+
entry.inFlight?.cancel();
|
|
2124
|
+
entry.wrapper.style.pointerEvents = "none";
|
|
2125
|
+
if (!animate) {
|
|
2126
|
+
entry.inFlight = null;
|
|
2127
|
+
entry.wrapper.style.visibility = "hidden";
|
|
2128
|
+
return;
|
|
2129
|
+
}
|
|
2130
|
+
const handle = runAnchorTransition(
|
|
2131
|
+
entry.def.element,
|
|
2132
|
+
entry.def.animation ?? opts.animation,
|
|
2133
|
+
"exit"
|
|
2134
|
+
);
|
|
2135
|
+
entry.inFlight = handle;
|
|
2136
|
+
void handle.finished.then(() => {
|
|
2137
|
+
if (entry.inFlight === handle && active !== entry) {
|
|
2138
|
+
entry.wrapper.style.visibility = "hidden";
|
|
2139
|
+
}
|
|
2140
|
+
});
|
|
2141
|
+
};
|
|
2142
|
+
const show = (entry, animate) => {
|
|
2143
|
+
entry.inFlight?.cancel();
|
|
2144
|
+
entry.inFlight = null;
|
|
2145
|
+
entry.wrapper.style.visibility = "";
|
|
2146
|
+
entry.wrapper.style.pointerEvents = entry.def.interactive ?? opts.interactive ?? false ? "auto" : "none";
|
|
2147
|
+
if (animate) {
|
|
2148
|
+
entry.inFlight = runAnchorTransition(
|
|
2149
|
+
entry.def.element,
|
|
2150
|
+
entry.def.animation ?? opts.animation,
|
|
2151
|
+
"enter"
|
|
2152
|
+
);
|
|
2153
|
+
}
|
|
2154
|
+
};
|
|
2155
|
+
const update = (animate) => {
|
|
2156
|
+
if (deps.isDestroyed()) return;
|
|
2157
|
+
const next = resolveActive();
|
|
2158
|
+
if (next === active) return;
|
|
2159
|
+
const prev = active;
|
|
2160
|
+
active = next;
|
|
2161
|
+
if (prev) hide(prev, animate);
|
|
2162
|
+
if (next) show(next, animate);
|
|
2163
|
+
};
|
|
2164
|
+
const offs = [
|
|
2165
|
+
deps.on("snap", () => update(true)),
|
|
2166
|
+
deps.on("open", () => update(true)),
|
|
2167
|
+
deps.on("close", () => update(true))
|
|
2168
|
+
];
|
|
2169
|
+
if (entries.some((e) => e.def.forRange)) {
|
|
2170
|
+
offs.push(deps.on("progress", () => update(true)));
|
|
2171
|
+
}
|
|
2172
|
+
update(false);
|
|
2173
|
+
return () => {
|
|
2174
|
+
offs.forEach((off) => off());
|
|
2175
|
+
for (const entry of entries) {
|
|
2176
|
+
entry.inFlight?.cancel();
|
|
2177
|
+
entry.inFlight = null;
|
|
2178
|
+
if (entry.wrapper.parentNode) {
|
|
2179
|
+
entry.wrapper.parentNode.removeChild(entry.wrapper);
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
active = null;
|
|
2183
|
+
};
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2186
|
+
// src/core/primitives/engine-options.ts
|
|
2187
|
+
var DEFAULT_FLICK_VELOCITY = 0.65;
|
|
2188
|
+
var DEFAULT_DRAG_THRESHOLD = 18;
|
|
2189
|
+
function resolveEngineOptions(opts, extras) {
|
|
2190
|
+
const initialAllowed = opts.allowed ?? opts.snapPoints.map((p) => p.id);
|
|
2191
|
+
let initialId = opts.initial ?? initialAllowed[0] ?? opts.snapPoints[0]?.id ?? "default";
|
|
2192
|
+
if (opts.persistKey) {
|
|
2193
|
+
const restored = readPersistedId(opts.persistKey);
|
|
2194
|
+
if (restored && initialAllowed.includes(restored)) {
|
|
2195
|
+
initialId = restored;
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
return {
|
|
2199
|
+
mode: opts.mode ?? "bottom",
|
|
2200
|
+
flickVelocity: opts.flickVelocity ?? DEFAULT_FLICK_VELOCITY,
|
|
2201
|
+
dragThreshold: opts.dragThreshold ?? DEFAULT_DRAG_THRESHOLD,
|
|
2202
|
+
rubberBandEnabled: opts.rubberBand ?? true,
|
|
2203
|
+
closeOnBack: opts.closeOnBack ?? false,
|
|
2204
|
+
initialAllowed,
|
|
2205
|
+
initialId,
|
|
2206
|
+
scrim: {
|
|
2207
|
+
scrimMode: opts.scrimMode,
|
|
2208
|
+
scrimColor: opts.scrimColor,
|
|
2209
|
+
scrimBlur: opts.scrimBlur,
|
|
2210
|
+
scrimInteractive: opts.scrimInteractive ?? (opts.scrimTapToClose ? true : void 0),
|
|
2211
|
+
scrimTapToClose: opts.scrimTapToClose,
|
|
2212
|
+
scrimPreset: opts.scrimPreset,
|
|
2213
|
+
screenRange: opts.screenRange,
|
|
2214
|
+
backdropRange: opts.backdropRange
|
|
2215
|
+
},
|
|
2216
|
+
animation: {
|
|
2217
|
+
animation: opts.animation,
|
|
2218
|
+
duration: opts.duration,
|
|
2219
|
+
easing: opts.easing,
|
|
2220
|
+
spring: opts.spring,
|
|
2221
|
+
respectReducedMotion: opts.respectReducedMotion,
|
|
2222
|
+
viewTransitions: opts.viewTransitions
|
|
2223
|
+
},
|
|
2224
|
+
lifecycle: {
|
|
2225
|
+
focusTrap: opts.focusTrap,
|
|
2226
|
+
initialFocus: opts.initialFocus,
|
|
2227
|
+
closeOnEscape: opts.closeOnEscape,
|
|
2228
|
+
lockBodyScroll: opts.lockBodyScroll,
|
|
2229
|
+
inertSiblings: opts.inertSiblings,
|
|
2230
|
+
shouldApplyInertSiblings: extras?.shouldApplyInertSiblings
|
|
2231
|
+
}
|
|
2232
|
+
};
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
// src/core/BottomSheetEngine.ts
|
|
2236
|
+
var HAPTIC_DURATION_MS = 8;
|
|
2237
|
+
var TeardownStack = class {
|
|
2238
|
+
fns = [];
|
|
2239
|
+
add(fn) {
|
|
2240
|
+
if (fn) this.fns.push(fn);
|
|
2241
|
+
}
|
|
2242
|
+
drain() {
|
|
2243
|
+
while (this.fns.length) {
|
|
2244
|
+
try {
|
|
2245
|
+
this.fns.pop()();
|
|
2246
|
+
} catch (err) {
|
|
2247
|
+
queueMicrotask(() => {
|
|
2248
|
+
throw err;
|
|
2249
|
+
});
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
};
|
|
2254
|
+
var BottomSheetEngine = class {
|
|
2255
|
+
id = nextInstanceId("bs");
|
|
2256
|
+
element;
|
|
2257
|
+
handle;
|
|
2258
|
+
scrollContainer;
|
|
2259
|
+
backdrop;
|
|
2260
|
+
screenComponent;
|
|
2261
|
+
scrimParent = null;
|
|
2262
|
+
mode;
|
|
2263
|
+
flickVelocity;
|
|
2264
|
+
dragThreshold;
|
|
2265
|
+
rubberBandEnabled;
|
|
2266
|
+
scrim;
|
|
2267
|
+
aria;
|
|
2268
|
+
animation;
|
|
2269
|
+
lifecycle;
|
|
2270
|
+
closeOnBack;
|
|
2271
|
+
routedTo;
|
|
2272
|
+
snapPointsRaw;
|
|
2273
|
+
snaps;
|
|
2274
|
+
activeId;
|
|
2275
|
+
size = 0;
|
|
2276
|
+
gesture;
|
|
2277
|
+
rootEl = null;
|
|
2278
|
+
destroyed = false;
|
|
2279
|
+
currentViewTransition = null;
|
|
2280
|
+
currentAbort = new AbortController();
|
|
2281
|
+
sizeWriteSentinel = new WriteSentinel();
|
|
2282
|
+
progressWriteSentinel = new WriteSentinel();
|
|
2283
|
+
isTopSheet = true;
|
|
2284
|
+
progressPayload = {
|
|
2285
|
+
value: 0,
|
|
2286
|
+
size: 0
|
|
2287
|
+
};
|
|
2288
|
+
dragContextBuf = {
|
|
2289
|
+
size: 0,
|
|
2290
|
+
maxAxisSize: 0,
|
|
2291
|
+
range: { min: 0, max: 0 },
|
|
2292
|
+
rubberBandEnabled: false
|
|
2293
|
+
};
|
|
2294
|
+
bus = createEventBus();
|
|
2295
|
+
persistKey;
|
|
2296
|
+
linkedSheets = [];
|
|
2297
|
+
scrollCache;
|
|
2298
|
+
teardowns = new TeardownStack();
|
|
2299
|
+
anchors = [];
|
|
2300
|
+
anchorHost = null;
|
|
2301
|
+
stackZ = 100;
|
|
2302
|
+
detachScrimStages = null;
|
|
2303
|
+
stackEffectEnabled = false;
|
|
2304
|
+
stackEffectPrimed = false;
|
|
2305
|
+
transformTemplate;
|
|
2306
|
+
constructor(opts) {
|
|
2307
|
+
const resolved = resolveEngineOptions(opts, {
|
|
2308
|
+
shouldApplyInertSiblings: () => {
|
|
2309
|
+
if (typeof document === "undefined") return false;
|
|
2310
|
+
const bodyChildren = Array.from(document.body.children);
|
|
2311
|
+
return bodyChildren.some(
|
|
2312
|
+
(c) => c === opts.element || c.contains(opts.element)
|
|
2313
|
+
);
|
|
2314
|
+
}
|
|
2315
|
+
});
|
|
2316
|
+
this.element = opts.element;
|
|
2317
|
+
this.handle = opts.handle ?? opts.element;
|
|
2318
|
+
this.scrollContainer = opts.scrollContainer;
|
|
2319
|
+
this.backdrop = opts.backdrop;
|
|
2320
|
+
this.screenComponent = opts.scrim ?? opts.screenComponent;
|
|
2321
|
+
this.scrimParent = this.screenComponent?.parentElement ?? null;
|
|
2322
|
+
this.mode = resolved.mode;
|
|
2323
|
+
this.transformTemplate = buildTransformTemplate(this.mode);
|
|
2324
|
+
this.aria = new AriaSliderWriter(this.handle, this.mode);
|
|
2325
|
+
this.flickVelocity = resolved.flickVelocity;
|
|
2326
|
+
this.dragThreshold = resolved.dragThreshold;
|
|
2327
|
+
this.rubberBandEnabled = resolved.rubberBandEnabled;
|
|
2328
|
+
this.scrim = new ScrimController(
|
|
2329
|
+
{
|
|
2330
|
+
mode: this.mode,
|
|
2331
|
+
screenComponent: this.screenComponent,
|
|
2332
|
+
backdrop: this.backdrop,
|
|
2333
|
+
isDestroyed: () => this.destroyed,
|
|
2334
|
+
isTopSheet: () => this.isTopSheet,
|
|
2335
|
+
getAllowedIds: () => this.snaps.getAllowedIds().slice(),
|
|
2336
|
+
getResolvedSnaps: () => this.snaps.getResolvedSnaps().slice(),
|
|
2337
|
+
snapTo: (id) => {
|
|
2338
|
+
void this.snapTo(id);
|
|
2339
|
+
},
|
|
2340
|
+
close: () => {
|
|
2341
|
+
void this.close();
|
|
2342
|
+
}
|
|
2343
|
+
},
|
|
2344
|
+
resolved.scrim
|
|
2345
|
+
);
|
|
2346
|
+
this.animation = new AnimationRunner(
|
|
2347
|
+
{
|
|
2348
|
+
element: this.element,
|
|
2349
|
+
getRootEl: () => this.rootEl,
|
|
2350
|
+
applySize: (size) => this.applySize(size),
|
|
2351
|
+
getSize: () => this.size,
|
|
2352
|
+
isDragging: () => this.gesture?.isDragging ?? false
|
|
2353
|
+
},
|
|
2354
|
+
resolved.animation
|
|
2355
|
+
);
|
|
2356
|
+
this.lifecycle = new LifecycleController(
|
|
2357
|
+
{
|
|
2358
|
+
element: this.element,
|
|
2359
|
+
close: () => this.close()
|
|
2360
|
+
},
|
|
2361
|
+
resolved.lifecycle
|
|
2362
|
+
);
|
|
2363
|
+
this.closeOnBack = resolved.closeOnBack;
|
|
2364
|
+
this.routedTo = opts.routedTo;
|
|
2365
|
+
this.stackEffectEnabled = opts.stackEffect ?? false;
|
|
2366
|
+
this.snapPointsRaw = opts.snapPoints;
|
|
2367
|
+
this.persistKey = opts.persistKey;
|
|
2368
|
+
if (opts.linkedSheets) {
|
|
2369
|
+
this.linkedSheets = opts.linkedSheets;
|
|
2370
|
+
}
|
|
2371
|
+
this.activeId = resolved.initialId;
|
|
2372
|
+
auditVhUsage(this.snapPointsRaw);
|
|
2373
|
+
this.rootEl = this.element.closest(".bs-root");
|
|
2374
|
+
this.snaps = new SnapResolver(
|
|
2375
|
+
this.snapPointsRaw,
|
|
2376
|
+
resolved.initialAllowed,
|
|
2377
|
+
this.mode,
|
|
2378
|
+
() => layoutAxis(this.mode) === "width" ? this.handle.offsetWidth : this.handle.offsetHeight,
|
|
2379
|
+
(maxAxisSize) => {
|
|
2380
|
+
this.element.style[layoutAxis(this.mode)] = `${maxAxisSize}px`;
|
|
2381
|
+
}
|
|
2382
|
+
);
|
|
2383
|
+
const initial = this.snaps.findById(this.activeId);
|
|
2384
|
+
if (initial) this.size = initial.size;
|
|
2385
|
+
this.applySize(this.size);
|
|
2386
|
+
this.updateAriaSlider();
|
|
2387
|
+
this.scrollCache = createScrollCache({
|
|
2388
|
+
scrollContainer: this.scrollContainer,
|
|
2389
|
+
getMaxAxisSize: () => this.snaps.getMaxAxisSize()
|
|
2390
|
+
});
|
|
2391
|
+
this.attach();
|
|
2392
|
+
this.registerInStack();
|
|
2393
|
+
if (this.snaps.getMaxAxisSize() === 0 && typeof IntersectionObserver !== "undefined" && typeof document !== "undefined") {
|
|
2394
|
+
const io = new IntersectionObserver((entries) => {
|
|
2395
|
+
for (const entry of entries) {
|
|
2396
|
+
if (!entry.isIntersecting) continue;
|
|
2397
|
+
if (this.destroyed) return;
|
|
2398
|
+
this.snaps.recompute();
|
|
2399
|
+
const current = this.snaps.findById(this.activeId);
|
|
2400
|
+
if (current) {
|
|
2401
|
+
this.size = current.size;
|
|
2402
|
+
this.applySize(this.size);
|
|
2403
|
+
this.updateAriaSlider();
|
|
2404
|
+
}
|
|
2405
|
+
io.disconnect();
|
|
2406
|
+
return;
|
|
2407
|
+
}
|
|
2408
|
+
});
|
|
2409
|
+
io.observe(this.element);
|
|
2410
|
+
this.teardowns.add(() => io.disconnect());
|
|
2411
|
+
}
|
|
2412
|
+
if (this.persistKey) {
|
|
2413
|
+
this.teardowns.add(installPersist(this, this.persistKey));
|
|
2414
|
+
}
|
|
2415
|
+
this.teardowns.add(
|
|
2416
|
+
installAutoCollapse({
|
|
2417
|
+
ms: opts.autoCollapseAfter,
|
|
2418
|
+
isDestroyed: () => this.destroyed,
|
|
2419
|
+
isDragging: () => this.gesture?.isDragging ?? false,
|
|
2420
|
+
getAllowedIds: () => this.snaps.getAllowedIds().slice(),
|
|
2421
|
+
getActiveId: () => this.activeId,
|
|
2422
|
+
resolveSnap: (id) => this.snaps.findById(id),
|
|
2423
|
+
snapTo: (id) => {
|
|
2424
|
+
void this.snapTo(id);
|
|
2425
|
+
},
|
|
2426
|
+
on: (event, fn) => this.on(event, fn)
|
|
2427
|
+
})
|
|
2428
|
+
);
|
|
2429
|
+
this.teardowns.add(
|
|
2430
|
+
installRoute({
|
|
2431
|
+
routedTo: this.routedTo,
|
|
2432
|
+
closeOnBack: this.closeOnBack,
|
|
2433
|
+
isTopSheet: () => this.isTopSheet,
|
|
2434
|
+
getSize: () => this.size,
|
|
2435
|
+
isDestroyed: () => this.destroyed,
|
|
2436
|
+
close: () => this.close(),
|
|
2437
|
+
on: (event, fn) => this.on(event, fn),
|
|
2438
|
+
sheetId: this.id
|
|
2439
|
+
})
|
|
2440
|
+
);
|
|
2441
|
+
if (this.size > 0) {
|
|
2442
|
+
this.handleOpen();
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
get state() {
|
|
2446
|
+
return {
|
|
2447
|
+
size: this.size,
|
|
2448
|
+
activeId: this.activeId,
|
|
2449
|
+
isDragging: this.gesture?.isDragging ?? false,
|
|
2450
|
+
isAnimating: this.animation.isAnimating,
|
|
2451
|
+
progress: this.computeProgress(this.size)
|
|
2452
|
+
};
|
|
2453
|
+
}
|
|
2454
|
+
on(event, fn) {
|
|
2455
|
+
return this.bus.on(event, fn);
|
|
2456
|
+
}
|
|
2457
|
+
use(plugin) {
|
|
2458
|
+
if (this.destroyed) {
|
|
2459
|
+
console.warn(
|
|
2460
|
+
`[BottomSheet] use("${plugin.name}") called on destroyed engine \u2014 ignored.`
|
|
2461
|
+
);
|
|
2462
|
+
return this;
|
|
2463
|
+
}
|
|
2464
|
+
const scoped = [];
|
|
2465
|
+
const scope = {
|
|
2466
|
+
add: (fn) => {
|
|
2467
|
+
if (typeof fn === "function") scoped.push(fn);
|
|
2468
|
+
}
|
|
2469
|
+
};
|
|
2470
|
+
let teardown;
|
|
2471
|
+
try {
|
|
2472
|
+
teardown = plugin.install(this, scope);
|
|
2473
|
+
} catch (err) {
|
|
2474
|
+
for (let i = scoped.length - 1; i >= 0; i--) {
|
|
2475
|
+
try {
|
|
2476
|
+
scoped[i]();
|
|
2477
|
+
} catch (cleanupErr) {
|
|
2478
|
+
queueMicrotask(() => {
|
|
2479
|
+
throw cleanupErr;
|
|
2480
|
+
});
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
queueMicrotask(() => {
|
|
2484
|
+
throw err;
|
|
2485
|
+
});
|
|
2486
|
+
return this;
|
|
2487
|
+
}
|
|
2488
|
+
for (const fn of scoped) this.teardowns.add(fn);
|
|
2489
|
+
if (typeof teardown === "function") {
|
|
2490
|
+
this.teardowns.add(teardown);
|
|
2491
|
+
}
|
|
2492
|
+
return this;
|
|
2493
|
+
}
|
|
2494
|
+
setLinkedSheets(sheets) {
|
|
2495
|
+
if (this.destroyed) return;
|
|
2496
|
+
this.linkedSheets = sheets;
|
|
2497
|
+
}
|
|
2498
|
+
getAllowedIds() {
|
|
2499
|
+
return this.snaps.getAllowedIds().slice();
|
|
2500
|
+
}
|
|
2501
|
+
async snapTo(id, velocityOrOpts = 0, _skipBeforeSnap = false) {
|
|
2502
|
+
if (this.destroyed) return;
|
|
2503
|
+
const opts = typeof velocityOrOpts === "object" ? velocityOrOpts : { velocity: velocityOrOpts };
|
|
2504
|
+
const velocityPxPerMs = opts.velocity ?? 0;
|
|
2505
|
+
const externalSignal = opts.signal;
|
|
2506
|
+
if (externalSignal?.aborted) return;
|
|
2507
|
+
const target = this.snaps.findById(id);
|
|
2508
|
+
if (!target) {
|
|
2509
|
+
console.warn(`[BottomSheet] unknown snap id: ${id}`);
|
|
2510
|
+
return;
|
|
2511
|
+
}
|
|
2512
|
+
if (!this.snaps.getAllowedIds().includes(id)) {
|
|
2513
|
+
console.warn(`[BottomSheet] snap "${id}" is not in allowed list`);
|
|
2514
|
+
return;
|
|
2515
|
+
}
|
|
2516
|
+
if (!_skipBeforeSnap && this.emitBeforeSnap(target, this.activeId)) {
|
|
2517
|
+
return;
|
|
2518
|
+
}
|
|
2519
|
+
const signal = this.newCycle();
|
|
2520
|
+
const onExternalAbort = () => {
|
|
2521
|
+
this.animation.cancel();
|
|
2522
|
+
this.newCycle();
|
|
2523
|
+
};
|
|
2524
|
+
externalSignal?.addEventListener("abort", onExternalAbort, { once: true });
|
|
2525
|
+
const wasClosed = this.size === 0;
|
|
2526
|
+
const previousId = this.activeId;
|
|
2527
|
+
const previousSize = this.size;
|
|
2528
|
+
this.scrollCache.cache(previousId, previousSize, target.size);
|
|
2529
|
+
this.activeId = id;
|
|
2530
|
+
if (this.animation.viewTransitionsAvailable) {
|
|
2531
|
+
this.currentViewTransition?.skipTransition?.();
|
|
2532
|
+
const vt = document.startViewTransition(() => {
|
|
2533
|
+
this.applySize(target.size);
|
|
2534
|
+
});
|
|
2535
|
+
this.currentViewTransition = vt;
|
|
2536
|
+
try {
|
|
2537
|
+
await vt.finished;
|
|
2538
|
+
} catch {
|
|
2539
|
+
}
|
|
2540
|
+
if (this.currentViewTransition === vt) this.currentViewTransition = null;
|
|
2541
|
+
} else {
|
|
2542
|
+
await this.animation.animateTo(target.size, velocityPxPerMs);
|
|
2543
|
+
}
|
|
2544
|
+
externalSignal?.removeEventListener("abort", onExternalAbort);
|
|
2545
|
+
if (signal.aborted) return;
|
|
2546
|
+
this.scrollCache.restore(id, previousSize, target.size);
|
|
2547
|
+
this.updateAriaSlider();
|
|
2548
|
+
this.emit("snap", { id, size: target.size });
|
|
2549
|
+
if (wasClosed && target.size > 0) {
|
|
2550
|
+
this.emit("open", { id });
|
|
2551
|
+
this.handleOpen();
|
|
2552
|
+
notifyLinkedSheets(this.linkedSheets, this);
|
|
2553
|
+
}
|
|
2554
|
+
if (target.size === 0) {
|
|
2555
|
+
this.emit("close", void 0);
|
|
2556
|
+
this.handleClose();
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
async dragTo(targetSize, velocityOrOpts = 0) {
|
|
2560
|
+
if (this.destroyed) return;
|
|
2561
|
+
const opts = typeof velocityOrOpts === "object" ? velocityOrOpts : { velocity: velocityOrOpts };
|
|
2562
|
+
const velocityPxPerMs = opts.velocity ?? 0;
|
|
2563
|
+
const externalSignal = opts.signal;
|
|
2564
|
+
if (externalSignal?.aborted) return;
|
|
2565
|
+
this.newCycle();
|
|
2566
|
+
const onExternalAbort = () => {
|
|
2567
|
+
this.animation.cancel();
|
|
2568
|
+
this.newCycle();
|
|
2569
|
+
};
|
|
2570
|
+
externalSignal?.addEventListener("abort", onExternalAbort, { once: true });
|
|
2571
|
+
const clamped = Math.max(0, Math.min(targetSize, this.snaps.getMaxAxisSize()));
|
|
2572
|
+
await this.animation.animateTo(clamped, velocityPxPerMs);
|
|
2573
|
+
externalSignal?.removeEventListener("abort", onExternalAbort);
|
|
2574
|
+
if (this.destroyed || externalSignal?.aborted) return;
|
|
2575
|
+
}
|
|
2576
|
+
open(id) {
|
|
2577
|
+
if (this.destroyed) return Promise.resolve();
|
|
2578
|
+
const target = id ?? this.snaps.getAllowedIds().find((a) => a !== "closed") ?? this.activeId;
|
|
2579
|
+
return this.snapTo(target);
|
|
2580
|
+
}
|
|
2581
|
+
close() {
|
|
2582
|
+
if (this.destroyed) return Promise.resolve();
|
|
2583
|
+
const closedId = this.snapPointsRaw.find((p) => p.id === "closed")?.id ?? this.snaps.getAllowedIds()[0];
|
|
2584
|
+
return this.snapTo(closedId ?? this.activeId);
|
|
2585
|
+
}
|
|
2586
|
+
setAllowed(ids, snap) {
|
|
2587
|
+
if (this.destroyed) return;
|
|
2588
|
+
this.snaps.setAllowedIds(ids);
|
|
2589
|
+
this.updateAriaSlider();
|
|
2590
|
+
if (snap && ids.includes(snap)) {
|
|
2591
|
+
void this.snapTo(snap, 0, true);
|
|
2592
|
+
} else if (!ids.includes(this.activeId)) {
|
|
2593
|
+
const fallback = ids[0];
|
|
2594
|
+
if (fallback) void this.snapTo(fallback, 0, true);
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
setBackdropRange(range) {
|
|
2598
|
+
this.scrim.setBackdropRange(range, () => this.applySize(this.size));
|
|
2599
|
+
}
|
|
2600
|
+
setScreenRange(range) {
|
|
2601
|
+
this.scrim.setScreenRange(range, () => this.applySize(this.size));
|
|
2602
|
+
}
|
|
2603
|
+
setScrimColor(color) {
|
|
2604
|
+
this.scrim.setScrimColor(color);
|
|
2605
|
+
}
|
|
2606
|
+
setScrimBlur(blur) {
|
|
2607
|
+
this.scrim.setScrimBlur(blur);
|
|
2608
|
+
}
|
|
2609
|
+
setScrimInteractive(interactive) {
|
|
2610
|
+
this.scrim.setScrimInteractive(interactive);
|
|
2611
|
+
}
|
|
2612
|
+
setScrim(opts) {
|
|
2613
|
+
this.scrim.setScrim(opts, () => this.applySize(this.size));
|
|
2614
|
+
}
|
|
2615
|
+
setScrimMode(mode) {
|
|
2616
|
+
this.scrim.setScrimMode(mode, () => this.applySize(this.size));
|
|
2617
|
+
}
|
|
2618
|
+
setScrimTapToClose(enabled) {
|
|
2619
|
+
this.scrim.setScrimTapToClose(enabled);
|
|
2620
|
+
}
|
|
2621
|
+
setScrimEnabled(enabled) {
|
|
2622
|
+
this.scrim.setScrimEnabled(enabled, () => this.applySize(this.size));
|
|
2623
|
+
}
|
|
2624
|
+
setScrimOverlay(opts) {
|
|
2625
|
+
return this.scrim.setScrimOverlay(opts);
|
|
2626
|
+
}
|
|
2627
|
+
addAnchor(opts) {
|
|
2628
|
+
if (this.destroyed || typeof document === "undefined") return () => {
|
|
2629
|
+
};
|
|
2630
|
+
if (!this.anchorHost) {
|
|
2631
|
+
this.anchorHost = this.rootEl ?? this.element.parentElement ?? document.body;
|
|
2632
|
+
this.anchorHost.style.setProperty("--bs-size", `${this.size}px`);
|
|
2633
|
+
this.anchorHost.style.setProperty(
|
|
2634
|
+
"--bs-progress",
|
|
2635
|
+
String(this.computeProgress(this.size))
|
|
2636
|
+
);
|
|
2637
|
+
}
|
|
2638
|
+
const handle = attachAnchor(
|
|
2639
|
+
{
|
|
2640
|
+
mode: this.mode,
|
|
2641
|
+
host: this.anchorHost,
|
|
2642
|
+
getState: () => ({
|
|
2643
|
+
activeId: this.activeId,
|
|
2644
|
+
size: this.size,
|
|
2645
|
+
progress: this.computeProgress(this.size)
|
|
2646
|
+
}),
|
|
2647
|
+
on: (event, fn) => this.on(event, fn),
|
|
2648
|
+
isDestroyed: () => this.destroyed
|
|
2649
|
+
},
|
|
2650
|
+
opts
|
|
2651
|
+
);
|
|
2652
|
+
handle.syncZ(this.stackZ + 1);
|
|
2653
|
+
this.anchors.push(handle);
|
|
2654
|
+
const detach = () => {
|
|
2655
|
+
const idx = this.anchors.indexOf(handle);
|
|
2656
|
+
if (idx === -1) return;
|
|
2657
|
+
this.anchors.splice(idx, 1);
|
|
2658
|
+
handle.detach();
|
|
2659
|
+
};
|
|
2660
|
+
this.teardowns.add(detach);
|
|
2661
|
+
return detach;
|
|
2662
|
+
}
|
|
2663
|
+
setScrimStages(opts) {
|
|
2664
|
+
if (this.destroyed || typeof document === "undefined") return () => {
|
|
2665
|
+
};
|
|
2666
|
+
this.detachScrimStages?.();
|
|
2667
|
+
this.detachScrimStages = null;
|
|
2668
|
+
if (!opts) return () => {
|
|
2669
|
+
};
|
|
2670
|
+
const host = this.screenComponent?.parentElement;
|
|
2671
|
+
if (!host) {
|
|
2672
|
+
console.warn(
|
|
2673
|
+
"[BottomSheet] setScrimStages: no scrim element mounted \u2014 pass `scrim` to the engine first."
|
|
2674
|
+
);
|
|
2675
|
+
return () => {
|
|
2676
|
+
};
|
|
2677
|
+
}
|
|
2678
|
+
const detachInstalled = installScrimStages(
|
|
2679
|
+
{
|
|
2680
|
+
mode: this.mode,
|
|
2681
|
+
host,
|
|
2682
|
+
getState: () => ({
|
|
2683
|
+
activeId: this.activeId,
|
|
2684
|
+
size: this.size,
|
|
2685
|
+
progress: this.computeProgress(this.size)
|
|
2686
|
+
}),
|
|
2687
|
+
on: (event, fn) => this.on(event, fn),
|
|
2688
|
+
isDestroyed: () => this.destroyed
|
|
2689
|
+
},
|
|
2690
|
+
opts
|
|
2691
|
+
);
|
|
2692
|
+
const detach = () => {
|
|
2693
|
+
if (this.detachScrimStages === detach) this.detachScrimStages = null;
|
|
2694
|
+
detachInstalled();
|
|
2695
|
+
};
|
|
2696
|
+
this.detachScrimStages = detach;
|
|
2697
|
+
this.teardowns.add(() => this.detachScrimStages?.());
|
|
2698
|
+
return detach;
|
|
2699
|
+
}
|
|
2700
|
+
getScrimState() {
|
|
2701
|
+
return { mode: this.scrim.scrimMode, enabled: this.scrim.scrimEnabled };
|
|
2702
|
+
}
|
|
2703
|
+
setSnapPoints(points, allowed) {
|
|
2704
|
+
if (this.destroyed) return;
|
|
2705
|
+
this.animation.cancel();
|
|
2706
|
+
this.newCycle();
|
|
2707
|
+
this.snapPointsRaw = points;
|
|
2708
|
+
auditVhUsage(points);
|
|
2709
|
+
this.snaps.setRaw(points);
|
|
2710
|
+
if (allowed) this.snaps.setAllowedIds(allowed);
|
|
2711
|
+
this.scrollCache.clear();
|
|
2712
|
+
this.scrim.invalidateOpacityCache();
|
|
2713
|
+
const current = this.snaps.findById(this.activeId);
|
|
2714
|
+
if (current) {
|
|
2715
|
+
this.applySize(current.size);
|
|
2716
|
+
}
|
|
2717
|
+
this.updateAriaSlider();
|
|
2718
|
+
}
|
|
2719
|
+
destroy() {
|
|
2720
|
+
this.destroyed = true;
|
|
2721
|
+
this.currentAbort.abort();
|
|
2722
|
+
this.currentViewTransition?.skipTransition?.();
|
|
2723
|
+
this.currentViewTransition = null;
|
|
2724
|
+
this.bus.clear();
|
|
2725
|
+
this.animation.cancel();
|
|
2726
|
+
this.gesture?.forceClearDragState();
|
|
2727
|
+
this.teardowns.drain();
|
|
2728
|
+
this.scrim.destroy();
|
|
2729
|
+
this.animation.destroy();
|
|
2730
|
+
this.lifecycle.destroy();
|
|
2731
|
+
if (this.backdrop) {
|
|
2732
|
+
this.backdrop.style.opacity = "";
|
|
2733
|
+
this.backdrop.style.pointerEvents = "";
|
|
2734
|
+
}
|
|
2735
|
+
if (this.screenComponent) {
|
|
2736
|
+
this.screenComponent.style.opacity = "";
|
|
2737
|
+
this.screenComponent.style.display = "";
|
|
2738
|
+
}
|
|
2739
|
+
this.sizeWriteSentinel.invalidate();
|
|
2740
|
+
this.progressWriteSentinel.invalidate();
|
|
2741
|
+
}
|
|
2742
|
+
emit(event, payload) {
|
|
2743
|
+
this.bus.emit(event, payload);
|
|
2744
|
+
}
|
|
2745
|
+
newCycle() {
|
|
2746
|
+
this.currentAbort.abort();
|
|
2747
|
+
this.currentAbort = new AbortController();
|
|
2748
|
+
return this.currentAbort.signal;
|
|
2749
|
+
}
|
|
2750
|
+
emitBeforeSnap(target, previousId) {
|
|
2751
|
+
let cancelled = false;
|
|
2752
|
+
let frozen = false;
|
|
2753
|
+
this.emit("before-snap", {
|
|
2754
|
+
id: target.id,
|
|
2755
|
+
size: target.size,
|
|
2756
|
+
previousId,
|
|
2757
|
+
cancel: () => {
|
|
2758
|
+
if (frozen) {
|
|
2759
|
+
console.warn(
|
|
2760
|
+
"[BottomSheet] before-snap.cancel() called asynchronously \u2014 ignored. cancel() must be invoked synchronously inside the listener."
|
|
2761
|
+
);
|
|
2762
|
+
return;
|
|
2763
|
+
}
|
|
2764
|
+
cancelled = true;
|
|
2765
|
+
}
|
|
2766
|
+
});
|
|
2767
|
+
frozen = true;
|
|
2768
|
+
return cancelled;
|
|
2769
|
+
}
|
|
2770
|
+
recomputeSnaps() {
|
|
2771
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2772
|
+
for (const p of this.snapPointsRaw) {
|
|
2773
|
+
if (seen.has(p.id)) {
|
|
2774
|
+
console.warn(
|
|
2775
|
+
`[BottomSheet] duplicate snap id "${p.id}" \u2014 only the first occurrence is reachable.`
|
|
2776
|
+
);
|
|
2777
|
+
}
|
|
2778
|
+
seen.add(p.id);
|
|
2779
|
+
}
|
|
2780
|
+
this.snaps.setRaw(this.snapPointsRaw);
|
|
2781
|
+
this.scrim.invalidateOpacityCache();
|
|
2782
|
+
}
|
|
2783
|
+
getAllowedRange() {
|
|
2784
|
+
return this.snaps.getAllowedRange();
|
|
2785
|
+
}
|
|
2786
|
+
allowedIdsBySize() {
|
|
2787
|
+
return this.snaps.getAllowedIds().slice().sort(
|
|
2788
|
+
(a, b) => (this.snaps.findById(a)?.size ?? 0) - (this.snaps.findById(b)?.size ?? 0)
|
|
2789
|
+
);
|
|
2790
|
+
}
|
|
2791
|
+
updateAriaSlider() {
|
|
2792
|
+
this.aria.setValue(this.allowedIdsBySize(), this.activeId);
|
|
2793
|
+
}
|
|
2794
|
+
registerInStack() {
|
|
2795
|
+
this.teardowns.add(sheetStack.push({
|
|
2796
|
+
id: this.id,
|
|
2797
|
+
setZIndex: (z) => {
|
|
2798
|
+
this.stackZ = z;
|
|
2799
|
+
this.element.style.zIndex = String(z);
|
|
2800
|
+
if (this.backdrop) this.backdrop.style.zIndex = String(z - 1);
|
|
2801
|
+
for (const anchor of this.anchors) anchor.syncZ(z + 1);
|
|
2802
|
+
},
|
|
2803
|
+
setIsTop: (isTop) => {
|
|
2804
|
+
this.isTopSheet = isTop;
|
|
2805
|
+
if (this.backdrop) {
|
|
2806
|
+
this.backdrop.style.display = isTop ? "" : "none";
|
|
2807
|
+
}
|
|
2808
|
+
},
|
|
2809
|
+
isOpen: () => this.size > 0,
|
|
2810
|
+
setDepth: (depth) => this.applyStackDepth(depth)
|
|
2811
|
+
}));
|
|
2812
|
+
}
|
|
2813
|
+
applyStackDepth(depth) {
|
|
2814
|
+
if (!this.stackEffectEnabled) return;
|
|
2815
|
+
this.element.setAttribute("data-stack-depth", String(depth));
|
|
2816
|
+
if (!this.stackEffectPrimed) {
|
|
2817
|
+
this.stackEffectPrimed = true;
|
|
2818
|
+
const isVertical = this.mode === "bottom" || this.mode === "top";
|
|
2819
|
+
this.element.style.transformOrigin = isVertical ? "50% 100%" : "0% 50%";
|
|
2820
|
+
this.element.style.transition = "scale 320ms cubic-bezier(0.29, 1.04, 0.84, 0.99)";
|
|
2821
|
+
}
|
|
2822
|
+
const scale = Math.max(1 - depth * 0.04, 0.86);
|
|
2823
|
+
this.element.style.scale = scale === 1 ? "" : String(scale);
|
|
2824
|
+
}
|
|
2825
|
+
attach() {
|
|
2826
|
+
this.gesture = new GestureController({
|
|
2827
|
+
handle: this.handle,
|
|
2828
|
+
element: this.element,
|
|
2829
|
+
mode: this.mode,
|
|
2830
|
+
getRoot: () => this.rootEl,
|
|
2831
|
+
getDragContext: () => {
|
|
2832
|
+
const buf = this.dragContextBuf;
|
|
2833
|
+
const r = this.getAllowedRange();
|
|
2834
|
+
buf.size = this.size;
|
|
2835
|
+
buf.maxAxisSize = this.snaps.getMaxAxisSize();
|
|
2836
|
+
buf.range.min = r.min;
|
|
2837
|
+
buf.range.max = r.max;
|
|
2838
|
+
buf.rubberBandEnabled = this.rubberBandEnabled;
|
|
2839
|
+
return buf;
|
|
2840
|
+
},
|
|
2841
|
+
cancelAnimation: () => this.animation.cancel(),
|
|
2842
|
+
applySize: (size) => this.applySize(size),
|
|
2843
|
+
animateTo: (size, velocity) => this.animation.animateTo(size, velocity),
|
|
2844
|
+
settleAfterDrag: (delta, velocity, kind) => this.settleAfterDrag(delta, velocity, kind),
|
|
2845
|
+
emit: (event, payload) => this.emit(event, payload),
|
|
2846
|
+
listenerCount: (event) => this.bus.listenerCount(event)
|
|
2847
|
+
});
|
|
2848
|
+
this.teardowns.add(this.gesture.install());
|
|
2849
|
+
try {
|
|
2850
|
+
this.attachFeatures();
|
|
2851
|
+
} catch (err) {
|
|
2852
|
+
this.teardowns.drain();
|
|
2853
|
+
try {
|
|
2854
|
+
this.scrim.destroy();
|
|
2855
|
+
} catch (destroyErr) {
|
|
2856
|
+
queueMicrotask(() => {
|
|
2857
|
+
throw destroyErr;
|
|
2858
|
+
});
|
|
2859
|
+
}
|
|
2860
|
+
try {
|
|
2861
|
+
this.animation.destroy();
|
|
2862
|
+
} catch (destroyErr) {
|
|
2863
|
+
queueMicrotask(() => {
|
|
2864
|
+
throw destroyErr;
|
|
2865
|
+
});
|
|
2866
|
+
}
|
|
2867
|
+
try {
|
|
2868
|
+
this.lifecycle.destroy();
|
|
2869
|
+
} catch (destroyErr) {
|
|
2870
|
+
queueMicrotask(() => {
|
|
2871
|
+
throw destroyErr;
|
|
2872
|
+
});
|
|
2873
|
+
}
|
|
2874
|
+
this.destroyed = true;
|
|
2875
|
+
throw err;
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
attachFeatures() {
|
|
2879
|
+
if (this.scrollContainer) {
|
|
2880
|
+
this.teardowns.add(installContentSwipe({
|
|
2881
|
+
container: this.scrollContainer,
|
|
2882
|
+
isDragging: () => this.gesture?.isDragging ?? false,
|
|
2883
|
+
isAnimating: () => this.animation.isAnimating,
|
|
2884
|
+
getAllowedIds: () => this.allowedIdsBySize(),
|
|
2885
|
+
getActiveId: () => this.activeId,
|
|
2886
|
+
snapTo: (id) => {
|
|
2887
|
+
void this.snapTo(id);
|
|
2888
|
+
}
|
|
2889
|
+
}));
|
|
2890
|
+
}
|
|
2891
|
+
if (typeof window !== "undefined") {
|
|
2892
|
+
this.teardowns.add(installResizeObserver({
|
|
2893
|
+
element: this.element,
|
|
2894
|
+
getMode: () => this.mode,
|
|
2895
|
+
isDestroyed: () => this.destroyed,
|
|
2896
|
+
isDragging: () => this.gesture?.isDragging ?? false,
|
|
2897
|
+
resolveActiveSnap: () => this.snaps.findById(this.activeId),
|
|
2898
|
+
getMaxAxisSize: () => this.snaps.getMaxAxisSize(),
|
|
2899
|
+
getSize: () => this.size,
|
|
2900
|
+
setMaxAxisSize: (size) => {
|
|
2901
|
+
this.snaps.setMaxAxisSize(size);
|
|
2902
|
+
},
|
|
2903
|
+
setSize: (size) => {
|
|
2904
|
+
this.size = size;
|
|
2905
|
+
},
|
|
2906
|
+
recomputeSnaps: () => this.recomputeSnaps(),
|
|
2907
|
+
applySize: (size) => this.applySize(size),
|
|
2908
|
+
cancelInFlight: () => {
|
|
2909
|
+
this.animation.cancel();
|
|
2910
|
+
},
|
|
2911
|
+
newCycle: () => {
|
|
2912
|
+
this.newCycle();
|
|
2913
|
+
},
|
|
2914
|
+
isAnimating: () => this.animation.isAnimating,
|
|
2915
|
+
resyncAfterCancel: () => this.resyncAfterResize()
|
|
2916
|
+
}));
|
|
2917
|
+
if (this.lifecycle.closeOnEscape) {
|
|
2918
|
+
const onKey = (e) => {
|
|
2919
|
+
if (this.destroyed || e.defaultPrevented) return;
|
|
2920
|
+
if (e.key === "Escape" && this.isTopSheet && this.size > 0) {
|
|
2921
|
+
void this.close();
|
|
2922
|
+
}
|
|
2923
|
+
};
|
|
2924
|
+
document.addEventListener("keydown", onKey);
|
|
2925
|
+
this.teardowns.add(
|
|
2926
|
+
() => document.removeEventListener("keydown", onKey)
|
|
2927
|
+
);
|
|
2928
|
+
}
|
|
2929
|
+
this.teardowns.add(installVisualViewport({
|
|
2930
|
+
element: this.element,
|
|
2931
|
+
isVerticalAxis: () => this.mode === "bottom" || this.mode === "top",
|
|
2932
|
+
isDestroyed: () => this.destroyed,
|
|
2933
|
+
isDragging: () => this.gesture?.isDragging ?? false,
|
|
2934
|
+
recomputeSnaps: () => this.recomputeSnaps(),
|
|
2935
|
+
resolveActiveSnap: () => this.snaps.findById(this.activeId),
|
|
2936
|
+
getMaxAxisSize: () => this.snaps.getMaxAxisSize(),
|
|
2937
|
+
getSize: () => this.size,
|
|
2938
|
+
setMaxAxisSize: (size) => {
|
|
2939
|
+
this.snaps.setMaxAxisSize(size);
|
|
2940
|
+
},
|
|
2941
|
+
setSize: (size) => {
|
|
2942
|
+
this.size = size;
|
|
2943
|
+
},
|
|
2944
|
+
applySize: (size) => this.applySize(size)
|
|
2945
|
+
}));
|
|
2946
|
+
}
|
|
2947
|
+
this.teardowns.add(installSliderKeyboard({
|
|
2948
|
+
handle: this.handle,
|
|
2949
|
+
mode: this.mode,
|
|
2950
|
+
isDestroyed: () => this.destroyed,
|
|
2951
|
+
getAllowedIds: () => this.allowedIdsBySize(),
|
|
2952
|
+
getActiveId: () => this.activeId,
|
|
2953
|
+
snapTo: (id) => {
|
|
2954
|
+
void this.snapTo(id);
|
|
2955
|
+
}
|
|
2956
|
+
}));
|
|
2957
|
+
this.scrim.attach();
|
|
2958
|
+
}
|
|
2959
|
+
settleAfterDrag(delta, velocity, kind = "touch") {
|
|
2960
|
+
const signal = this.newCycle();
|
|
2961
|
+
const target = this.snaps.findDragSettleTarget({
|
|
2962
|
+
delta,
|
|
2963
|
+
velocity,
|
|
2964
|
+
pointerKind: kind,
|
|
2965
|
+
size: this.size,
|
|
2966
|
+
activeId: this.activeId,
|
|
2967
|
+
flickVelocity: this.flickVelocity,
|
|
2968
|
+
dragThreshold: this.dragThreshold
|
|
2969
|
+
});
|
|
2970
|
+
if (!target) return;
|
|
2971
|
+
const previousId = this.activeId;
|
|
2972
|
+
if (target.id === previousId && target.size === this.size) return;
|
|
2973
|
+
if (this.emitBeforeSnap(target, previousId)) {
|
|
2974
|
+
const restore = this.snaps.findById(previousId);
|
|
2975
|
+
if (restore) {
|
|
2976
|
+
void this.animation.animateTo(restore.size, 0);
|
|
2977
|
+
}
|
|
2978
|
+
return;
|
|
2979
|
+
}
|
|
2980
|
+
const previousSize = this.size;
|
|
2981
|
+
const previousSnapSize = this.snaps.findById(previousId)?.size;
|
|
2982
|
+
this.scrollCache.cache(previousId, previousSize, target.size);
|
|
2983
|
+
this.activeId = target.id;
|
|
2984
|
+
void this.animation.animateTo(target.size, velocity).then(() => {
|
|
2985
|
+
if (signal.aborted) return;
|
|
2986
|
+
this.scrollCache.restore(target.id, previousSize, target.size);
|
|
2987
|
+
this.updateAriaSlider();
|
|
2988
|
+
this.emit("snap", { id: target.id, size: target.size });
|
|
2989
|
+
this.haptic();
|
|
2990
|
+
if (previousSnapSize === 0 && target.size > 0) {
|
|
2991
|
+
this.emit("open", { id: target.id });
|
|
2992
|
+
this.handleOpen();
|
|
2993
|
+
notifyLinkedSheets(this.linkedSheets, this);
|
|
2994
|
+
}
|
|
2995
|
+
if (target.size === 0) {
|
|
2996
|
+
this.emit("close", void 0);
|
|
2997
|
+
this.handleClose();
|
|
2998
|
+
}
|
|
2999
|
+
});
|
|
3000
|
+
}
|
|
3001
|
+
haptic() {
|
|
3002
|
+
if (typeof navigator !== "undefined" && "vibrate" in navigator) {
|
|
3003
|
+
try {
|
|
3004
|
+
navigator.vibrate(HAPTIC_DURATION_MS);
|
|
3005
|
+
} catch {
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
applySize(size) {
|
|
3010
|
+
this.size = size;
|
|
3011
|
+
const offset = this.snaps.getMaxAxisSize() - size;
|
|
3012
|
+
const style = this.element.style;
|
|
3013
|
+
style.transform = this.transformTemplate(offset);
|
|
3014
|
+
if (this.sizeWriteSentinel.shouldWrite(size, SIZE_WRITE_EPSILON)) {
|
|
3015
|
+
style.setProperty("--bs-size", `${size}px`);
|
|
3016
|
+
if (this.scrimParent) {
|
|
3017
|
+
this.scrimParent.style.setProperty("--bs-size", `${size}px`);
|
|
3018
|
+
}
|
|
3019
|
+
if (this.anchorHost && this.anchorHost !== this.scrimParent) {
|
|
3020
|
+
this.anchorHost.style.setProperty("--bs-size", `${size}px`);
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
3023
|
+
const progress = this.computeProgress(size);
|
|
3024
|
+
const progressChanged = this.progressWriteSentinel.shouldWrite(
|
|
3025
|
+
progress,
|
|
3026
|
+
OPACITY_WRITE_EPSILON
|
|
3027
|
+
);
|
|
3028
|
+
if (progressChanged) {
|
|
3029
|
+
style.setProperty("--bs-progress", String(progress));
|
|
3030
|
+
if (this.anchorHost) {
|
|
3031
|
+
this.anchorHost.style.setProperty("--bs-progress", String(progress));
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
this.scrim.applyOpacity(progress, progressChanged);
|
|
3035
|
+
if (progressChanged && this.bus.listenerCount("progress") > 0) {
|
|
3036
|
+
this.progressPayload.value = progress;
|
|
3037
|
+
this.progressPayload.size = size;
|
|
3038
|
+
this.emit("progress", this.progressPayload);
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
computeProgress(size) {
|
|
3042
|
+
const { min, max } = this.getAllowedRange();
|
|
3043
|
+
if (max <= min) return 0;
|
|
3044
|
+
return Math.min(Math.max((size - min) / (max - min), 0), 1);
|
|
3045
|
+
}
|
|
3046
|
+
handleOpen() {
|
|
3047
|
+
sheetStack.promote(this.id);
|
|
3048
|
+
try {
|
|
3049
|
+
this.lifecycle.install();
|
|
3050
|
+
} catch (err) {
|
|
3051
|
+
if (!this.destroyed) this.newCycle();
|
|
3052
|
+
this.handleClose();
|
|
3053
|
+
this.applySize(0);
|
|
3054
|
+
this.activeId = this.snapPointsRaw.find((p) => p.id === "closed")?.id ?? this.activeId;
|
|
3055
|
+
this.size = 0;
|
|
3056
|
+
queueMicrotask(() => {
|
|
3057
|
+
throw err;
|
|
3058
|
+
});
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3061
|
+
resyncAfterResize() {
|
|
3062
|
+
if (this.destroyed) return;
|
|
3063
|
+
const target = this.snaps.findById(this.activeId);
|
|
3064
|
+
if (!target) return;
|
|
3065
|
+
this.updateAriaSlider();
|
|
3066
|
+
this.emit("snap", { id: target.id, size: target.size });
|
|
3067
|
+
if (target.size > 0 && !this.lifecycle.isInstalled) {
|
|
3068
|
+
this.emit("open", { id: target.id });
|
|
3069
|
+
this.handleOpen();
|
|
3070
|
+
notifyLinkedSheets(this.linkedSheets, this);
|
|
3071
|
+
} else if (target.size === 0 && this.lifecycle.isInstalled) {
|
|
3072
|
+
this.emit("close", void 0);
|
|
3073
|
+
this.handleClose();
|
|
3074
|
+
}
|
|
3075
|
+
}
|
|
3076
|
+
handleClose() {
|
|
3077
|
+
this.lifecycle.release();
|
|
3078
|
+
sheetStack.update();
|
|
3079
|
+
}
|
|
3080
|
+
};
|
|
3081
|
+
|
|
3082
|
+
// src/solid/index.tsx
|
|
3083
|
+
var BottomSheet = (props) => {
|
|
3084
|
+
let sheetEl;
|
|
3085
|
+
let handleEl;
|
|
3086
|
+
let contentEl;
|
|
3087
|
+
let backdropEl;
|
|
3088
|
+
let scrimEl;
|
|
3089
|
+
const initialActive = () => props.initial ?? props.snapPoints[0]?.id ?? "default";
|
|
3090
|
+
const [state, setState] = createSignal({
|
|
3091
|
+
size: 0,
|
|
3092
|
+
activeId: initialActive(),
|
|
3093
|
+
isDragging: false,
|
|
3094
|
+
isAnimating: false,
|
|
3095
|
+
progress: 0
|
|
3096
|
+
});
|
|
3097
|
+
let engine = null;
|
|
3098
|
+
onMount(() => {
|
|
3099
|
+
if (!sheetEl) return;
|
|
3100
|
+
const engineOpts = {
|
|
3101
|
+
element: sheetEl,
|
|
3102
|
+
handle: handleEl,
|
|
3103
|
+
scrollContainer: contentEl,
|
|
3104
|
+
backdrop: props.backdrop !== false ? backdropEl : void 0,
|
|
3105
|
+
scrim: scrimEl,
|
|
3106
|
+
mode: props.mode ?? "bottom",
|
|
3107
|
+
snapPoints: props.snapPoints,
|
|
3108
|
+
allowed: props.allowed,
|
|
3109
|
+
initial: props.initial,
|
|
3110
|
+
animation: props.animation,
|
|
3111
|
+
spring: props.spring,
|
|
3112
|
+
focusTrap: props.focusTrap,
|
|
3113
|
+
closeOnEscape: props.closeOnEscape,
|
|
3114
|
+
closeOnBack: props.closeOnBack,
|
|
3115
|
+
lockBodyScroll: props.lockBodyScroll,
|
|
3116
|
+
rubberBand: props.rubberBand,
|
|
3117
|
+
backdropRange: props.backdropRange
|
|
3118
|
+
};
|
|
3119
|
+
engine = new BottomSheetEngine(engineOpts);
|
|
3120
|
+
props.engineRef?.(engine);
|
|
3121
|
+
const sync = () => {
|
|
3122
|
+
if (!engine) return;
|
|
3123
|
+
const s = engine.state;
|
|
3124
|
+
setState({ ...s });
|
|
3125
|
+
props.onChange?.(s);
|
|
3126
|
+
};
|
|
3127
|
+
sync();
|
|
3128
|
+
engine.on("snap", (payload) => {
|
|
3129
|
+
sync();
|
|
3130
|
+
props.onSnap?.(payload.id);
|
|
3131
|
+
});
|
|
3132
|
+
engine.on("dragstart", sync);
|
|
3133
|
+
engine.on("dragend", sync);
|
|
3134
|
+
if (props.backdrop !== false && props.closeOnBackdrop !== false && backdropEl) {
|
|
3135
|
+
const onBackdropClick = () => {
|
|
3136
|
+
void engine?.close();
|
|
3137
|
+
};
|
|
3138
|
+
backdropEl.addEventListener("click", onBackdropClick);
|
|
3139
|
+
onCleanup(() => {
|
|
3140
|
+
backdropEl?.removeEventListener("click", onBackdropClick);
|
|
3141
|
+
});
|
|
3142
|
+
}
|
|
3143
|
+
});
|
|
3144
|
+
onCleanup(() => {
|
|
3145
|
+
engine?.destroy();
|
|
3146
|
+
engine = null;
|
|
3147
|
+
props.engineRef?.(null);
|
|
3148
|
+
});
|
|
3149
|
+
createEffect(
|
|
3150
|
+
on(
|
|
3151
|
+
() => props.snapPoints,
|
|
3152
|
+
(points, prev) => {
|
|
3153
|
+
if (!engine || prev === void 0) return;
|
|
3154
|
+
engine.setSnapPoints(
|
|
3155
|
+
points,
|
|
3156
|
+
props.allowed
|
|
3157
|
+
);
|
|
3158
|
+
},
|
|
3159
|
+
{ defer: true }
|
|
3160
|
+
)
|
|
3161
|
+
);
|
|
3162
|
+
createEffect(
|
|
3163
|
+
on(
|
|
3164
|
+
() => props.allowed,
|
|
3165
|
+
(allowed, prev) => {
|
|
3166
|
+
if (!engine || prev === void 0) return;
|
|
3167
|
+
if (allowed) engine.setAllowed(allowed);
|
|
3168
|
+
},
|
|
3169
|
+
{ defer: true }
|
|
3170
|
+
)
|
|
3171
|
+
);
|
|
3172
|
+
const showBackdrop = createMemo(() => props.backdrop !== false);
|
|
3173
|
+
const mode = createMemo(() => props.mode ?? "bottom");
|
|
3174
|
+
const ariaLabel = createMemo(() => props.ariaLabel ?? "Bottom sheet");
|
|
3175
|
+
return <div class="bs-root">
|
|
3176
|
+
{showBackdrop() ? <div class="bs-backdrop" ref={(el) => backdropEl = el} /> : null}
|
|
3177
|
+
<div class="bs-screen" ref={(el) => scrimEl = el}>
|
|
3178
|
+
{props.screen}
|
|
3179
|
+
</div>
|
|
3180
|
+
<section
|
|
3181
|
+
class="bs-sheet"
|
|
3182
|
+
ref={(el) => sheetEl = el}
|
|
3183
|
+
data-mode={mode()}
|
|
3184
|
+
data-active={state().activeId}
|
|
3185
|
+
role="dialog"
|
|
3186
|
+
aria-modal={props.focusTrap ? "true" : void 0}
|
|
3187
|
+
aria-label={ariaLabel()}
|
|
3188
|
+
>
|
|
3189
|
+
<div
|
|
3190
|
+
class="bs-handle"
|
|
3191
|
+
ref={(el) => handleEl = el}
|
|
3192
|
+
role="slider"
|
|
3193
|
+
tabIndex={0}
|
|
3194
|
+
aria-label="Resize sheet"
|
|
3195
|
+
>
|
|
3196
|
+
{props.header}
|
|
3197
|
+
</div>
|
|
3198
|
+
<div
|
|
3199
|
+
class="bs-content"
|
|
3200
|
+
ref={(el) => contentEl = el}
|
|
3201
|
+
tabIndex={0}
|
|
3202
|
+
role="region"
|
|
3203
|
+
aria-label="Sheet content"
|
|
3204
|
+
>
|
|
3205
|
+
{props.children}
|
|
3206
|
+
</div>
|
|
3207
|
+
<span class="bs-sr-only" role="status" aria-live="polite">
|
|
3208
|
+
{state().activeId}
|
|
3209
|
+
</span>
|
|
3210
|
+
</section>
|
|
3211
|
+
</div>;
|
|
3212
|
+
};
|
|
3213
|
+
export {
|
|
3214
|
+
BottomSheet
|
|
3215
|
+
};
|