@surdeddd/bottom-sheet 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +68 -1
  2. package/dist/{BottomSheetEngine-DzsIwD28.d.cts → BottomSheetCore-CsIjyq7C.d.cts} +61 -5
  3. package/dist/{BottomSheetEngine-DRjCU73e.d.ts → BottomSheetCore-D16lsa6g.d.ts} +61 -5
  4. package/dist/BottomSheetEngine-BYjAVrmd.d.cts +7 -0
  5. package/dist/BottomSheetEngine-YuCNugZn.d.ts +7 -0
  6. package/dist/core.cjs +3476 -0
  7. package/dist/core.d.cts +3 -0
  8. package/dist/core.d.ts +3 -0
  9. package/dist/core.js +3474 -0
  10. package/dist/debug.cjs +109 -0
  11. package/dist/debug.d.cts +22 -0
  12. package/dist/debug.d.ts +22 -0
  13. package/dist/debug.js +107 -0
  14. package/dist/element.cjs +994 -697
  15. package/dist/element.d.cts +2 -1
  16. package/dist/element.d.ts +2 -1
  17. package/dist/element.iife.global.js +2 -2
  18. package/dist/element.js +994 -697
  19. package/dist/features.cjs +533 -0
  20. package/dist/features.d.cts +13 -0
  21. package/dist/features.d.ts +13 -0
  22. package/dist/features.js +526 -0
  23. package/dist/index-DdYLOIIT.d.ts +15 -0
  24. package/dist/index-dfrzw-lI.d.cts +15 -0
  25. package/dist/index.cjs +823 -542
  26. package/dist/index.d.cts +6 -15
  27. package/dist/index.d.ts +6 -15
  28. package/dist/index.js +817 -543
  29. package/dist/integrations/formik.d.cts +1 -1
  30. package/dist/integrations/formik.d.ts +1 -1
  31. package/dist/integrations/react-hook-form.d.cts +1 -1
  32. package/dist/integrations/react-hook-form.d.ts +1 -1
  33. package/dist/overlay.cjs +13 -8
  34. package/dist/overlay.js +13 -8
  35. package/dist/preact.d.cts +2 -1
  36. package/dist/preact.d.ts +2 -1
  37. package/dist/qwik-lib/index.qwik.cjs +4267 -0
  38. package/dist/qwik-lib/index.qwik.mjs +4267 -0
  39. package/dist/qwik.cjs +816 -542
  40. package/dist/qwik.d.cts +2 -2
  41. package/dist/qwik.d.ts +2 -2
  42. package/dist/qwik.js +816 -542
  43. package/dist/react.cjs +816 -542
  44. package/dist/react.d.cts +3 -2
  45. package/dist/react.d.ts +3 -2
  46. package/dist/react.js +816 -542
  47. package/dist/solid.cjs +816 -542
  48. package/dist/solid.d.cts +64 -4
  49. package/dist/solid.d.ts +64 -4
  50. package/dist/solid.js +816 -542
  51. package/dist/solid.source.jsx +816 -542
  52. package/dist/svelte-core.cjs +816 -542
  53. package/dist/svelte-core.js +816 -542
  54. package/dist/svelte.cjs +816 -542
  55. package/dist/svelte.js +816 -542
  56. package/dist/vue.cjs +927 -645
  57. package/dist/vue.js +927 -645
  58. package/package.json +63 -11
@@ -0,0 +1,526 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
4
+
5
+ // src/core/features/history-coordinator.ts
6
+ var entries = [];
7
+ var subscribers = /* @__PURE__ */ new Set();
8
+ var suppress = 0;
9
+ var internalDepth = 0;
10
+ var pendingRebrands = [];
11
+ var listenerInstalled = false;
12
+ var patchInstalled = false;
13
+ var origPushState = null;
14
+ var origReplaceState = null;
15
+ var patchedPushState = null;
16
+ var patchedReplaceState = null;
17
+ var hasWindow = () => typeof window !== "undefined";
18
+ var hasHistory = () => typeof history !== "undefined";
19
+ var brandMarker = (surface) => ({
20
+ ...surface.markerState(),
21
+ __bs: true
22
+ });
23
+ var runInternal = (fn) => {
24
+ internalDepth += 1;
25
+ try {
26
+ fn();
27
+ } finally {
28
+ internalDepth -= 1;
29
+ }
30
+ };
31
+ var notifyRouteChange = () => {
32
+ const snapshot = Array.from(subscribers);
33
+ for (const fn of snapshot) fn();
34
+ };
35
+ var ensureListener = () => {
36
+ if (listenerInstalled || !hasWindow()) return;
37
+ window.addEventListener("popstate", onPopState);
38
+ listenerInstalled = true;
39
+ };
40
+ var maybeTeardownListener = () => {
41
+ if (!listenerInstalled) return;
42
+ if (entries.length > 0 || subscribers.size > 0 || suppress > 0) return;
43
+ if (hasWindow()) window.removeEventListener("popstate", onPopState);
44
+ listenerInstalled = false;
45
+ };
46
+ var installPatch = () => {
47
+ if (patchInstalled || !hasHistory()) return;
48
+ origPushState = history.pushState;
49
+ origReplaceState = history.replaceState;
50
+ patchedPushState = function(...args) {
51
+ origPushState.apply(this, args);
52
+ if (internalDepth === 0) notifyRouteChange();
53
+ };
54
+ patchedReplaceState = function(...args) {
55
+ origReplaceState.apply(this, args);
56
+ if (internalDepth === 0) notifyRouteChange();
57
+ };
58
+ history.pushState = patchedPushState;
59
+ history.replaceState = patchedReplaceState;
60
+ patchInstalled = true;
61
+ };
62
+ var removePatch = () => {
63
+ if (!patchInstalled) return;
64
+ if (history.pushState === patchedPushState && origPushState) {
65
+ history.pushState = origPushState;
66
+ }
67
+ if (history.replaceState === patchedReplaceState && origReplaceState) {
68
+ history.replaceState = origReplaceState;
69
+ }
70
+ origPushState = null;
71
+ origReplaceState = null;
72
+ patchedPushState = null;
73
+ patchedReplaceState = null;
74
+ patchInstalled = false;
75
+ };
76
+ function onPopState() {
77
+ if (suppress > 0) {
78
+ suppress -= 1;
79
+ const rebrand = pendingRebrands.shift();
80
+ if (rebrand) rebrand();
81
+ maybeTeardownListener();
82
+ return;
83
+ }
84
+ if (entries.length === 0) {
85
+ notifyRouteChange();
86
+ maybeTeardownListener();
87
+ return;
88
+ }
89
+ let target = null;
90
+ let targetIdx = -1;
91
+ for (let i = entries.length - 1; i >= 0; i -= 1) {
92
+ const entry = entries[i];
93
+ if (!entry.surface.isOpen()) continue;
94
+ if (!target) {
95
+ target = entry;
96
+ targetIdx = i;
97
+ }
98
+ if (entry.surface.isTop()) {
99
+ target = entry;
100
+ targetIdx = i;
101
+ break;
102
+ }
103
+ }
104
+ if (!target) {
105
+ const removed = entries.pop();
106
+ if (removed) removed.live = false;
107
+ maybeTeardownListener();
108
+ return;
109
+ }
110
+ target.live = false;
111
+ entries.splice(targetIdx, 1);
112
+ const settled = target;
113
+ void Promise.resolve(settled.surface.close()).then(() => {
114
+ if (settled.surface.isOpen()) restore(settled);
115
+ });
116
+ maybeTeardownListener();
117
+ }
118
+ function restore(entry) {
119
+ if (!hasWindow() || !hasHistory()) return;
120
+ entry.live = true;
121
+ runInternal(() => {
122
+ try {
123
+ history.pushState(brandMarker(entry.surface), "", entry.surface.url);
124
+ } catch {
125
+ entry.live = false;
126
+ }
127
+ });
128
+ if (entry.live) {
129
+ entries.push(entry);
130
+ ensureListener();
131
+ }
132
+ }
133
+ function pushBackMarker(surface) {
134
+ const entry = { surface, priorUrl: void 0, live: false };
135
+ if (!hasWindow() || !hasHistory()) {
136
+ return entry;
137
+ }
138
+ entry.priorUrl = surface.url !== void 0 ? location.href : void 0;
139
+ runInternal(() => {
140
+ try {
141
+ history.pushState(brandMarker(surface), "", surface.url);
142
+ entry.live = true;
143
+ } catch {
144
+ entry.live = false;
145
+ }
146
+ });
147
+ if (entry.live) {
148
+ entries.push(entry);
149
+ ensureListener();
150
+ }
151
+ return entry;
152
+ }
153
+ function popBackMarker(handle) {
154
+ if (!hasWindow() || !hasHistory()) return;
155
+ const entry = handle;
156
+ const idx = entries.indexOf(entry);
157
+ if (idx === -1 || !entry.live) return;
158
+ const last = entries.length - 1;
159
+ entry.live = false;
160
+ entries.splice(idx, 1);
161
+ let rebrand = null;
162
+ if (idx !== last) {
163
+ const rebrandSurface = entries[entries.length - 1].surface;
164
+ const rebrandUrl = entry.priorUrl;
165
+ rebrand = () => {
166
+ runInternal(() => {
167
+ history.replaceState(
168
+ brandMarker(rebrandSurface),
169
+ "",
170
+ rebrandUrl !== void 0 ? rebrandUrl : location.href
171
+ );
172
+ });
173
+ };
174
+ }
175
+ pendingRebrands.push(rebrand);
176
+ suppress += 1;
177
+ runInternal(() => {
178
+ try {
179
+ history.back();
180
+ } catch {
181
+ suppress = Math.max(0, suppress - 1);
182
+ pendingRebrands.pop();
183
+ }
184
+ });
185
+ maybeTeardownListener();
186
+ }
187
+ function subscribeRouteChange(fn) {
188
+ if (!hasWindow() || !hasHistory()) return () => {
189
+ };
190
+ subscribers.add(fn);
191
+ if (subscribers.size === 1) installPatch();
192
+ ensureListener();
193
+ return () => {
194
+ if (!subscribers.has(fn)) return;
195
+ subscribers.delete(fn);
196
+ if (subscribers.size === 0) removePatch();
197
+ maybeTeardownListener();
198
+ };
199
+ }
200
+
201
+ // src/core/features/route.ts
202
+ function installRoute(deps) {
203
+ if (typeof window === "undefined") {
204
+ return () => {
205
+ };
206
+ }
207
+ if (!deps.routedTo && !deps.closeOnBack) {
208
+ return () => {
209
+ };
210
+ }
211
+ let handle = null;
212
+ const onOpen = () => {
213
+ if (handle) return;
214
+ handle = pushBackMarker({
215
+ isOpen: () => !deps.isDestroyed() && deps.getSize() > 0,
216
+ isTop: deps.isTopSheet,
217
+ close: deps.close,
218
+ markerState: () => deps.routedTo !== void 0 ? { __bsRouted: deps.sheetId } : { __bsSheet: deps.sheetId },
219
+ url: deps.routedTo
220
+ });
221
+ };
222
+ const onClose = () => {
223
+ if (!handle) return;
224
+ popBackMarker(handle);
225
+ handle = null;
226
+ };
227
+ const unsubscribeOpen = deps.on("open", onOpen);
228
+ const unsubscribeClose = deps.on("close", onClose);
229
+ if (deps.getSize() > 0) onOpen();
230
+ return () => {
231
+ unsubscribeOpen();
232
+ unsubscribeClose();
233
+ if (handle) {
234
+ popBackMarker(handle);
235
+ handle = null;
236
+ }
237
+ };
238
+ }
239
+ function installRouteChange(deps) {
240
+ return subscribeRouteChange(() => {
241
+ if (deps.isDestroyed() || deps.getSize() <= 0) return;
242
+ void deps.close();
243
+ });
244
+ }
245
+
246
+ // src/core/features/persist.ts
247
+ function installPersist(engine, key) {
248
+ const unsubscribe = engine.on("snap", ({ id }) => {
249
+ if (typeof window === "undefined") return;
250
+ if (typeof localStorage === "undefined") return;
251
+ try {
252
+ localStorage.setItem(key, id);
253
+ } catch {
254
+ }
255
+ });
256
+ return unsubscribe;
257
+ }
258
+
259
+ // src/core/features/auto-collapse.ts
260
+ function installAutoCollapse(deps) {
261
+ const { ms } = deps;
262
+ if (ms === void 0 || ms <= 0) {
263
+ return () => {
264
+ };
265
+ }
266
+ let timer = null;
267
+ const clearTimer = () => {
268
+ if (timer !== null) {
269
+ clearTimeout(timer);
270
+ timer = null;
271
+ }
272
+ };
273
+ const fire = () => {
274
+ if (deps.isDestroyed()) return;
275
+ if (deps.isDragging()) return;
276
+ const active = deps.resolveSnap(deps.getActiveId());
277
+ if (!active || active.size === 0) return;
278
+ let target = null;
279
+ for (const id of deps.getAllowedIds()) {
280
+ const snap = deps.resolveSnap(id);
281
+ if (!snap || snap.size <= 0) continue;
282
+ if (!target || snap.size < target.size) target = snap;
283
+ }
284
+ if (!target) return;
285
+ if (target.id === active.id || target.size >= active.size) return;
286
+ deps.snapTo(target.id);
287
+ };
288
+ const reset = () => {
289
+ clearTimer();
290
+ if (deps.isDestroyed()) return;
291
+ timer = setTimeout(() => {
292
+ timer = null;
293
+ fire();
294
+ }, ms);
295
+ };
296
+ const unsubscribe = deps.on("snap", () => reset());
297
+ if ((deps.resolveSnap(deps.getActiveId())?.size ?? 0) > 0) reset();
298
+ return () => {
299
+ clearTimer();
300
+ unsubscribe();
301
+ };
302
+ }
303
+
304
+ // src/core/features/content-swipe.ts
305
+ var CONTENT_PULL_THRESHOLD = 60;
306
+ function installContentSwipe(deps) {
307
+ const { container } = deps;
308
+ let startY = 0;
309
+ let startScrollTop = 0;
310
+ let moved = false;
311
+ const onTouchStart = (e) => {
312
+ const t = e.touches[0];
313
+ if (!t) return;
314
+ startY = t.clientY;
315
+ startScrollTop = container.scrollTop;
316
+ moved = false;
317
+ };
318
+ const onTouchMove = (e) => {
319
+ const t = e.touches[0];
320
+ if (!t) return;
321
+ if (Math.abs(t.clientY - startY) > CONTENT_PULL_THRESHOLD) moved = true;
322
+ };
323
+ const onTouchEnd = (e) => {
324
+ if (!moved) return;
325
+ if (deps.isDragging() || deps.isAnimating()) return;
326
+ if (container.scrollTop !== startScrollTop) return;
327
+ const t = e.changedTouches[0];
328
+ if (!t) return;
329
+ const deltaY = t.clientY - startY;
330
+ const atTop = container.scrollTop <= 0;
331
+ const allowed = deps.getAllowedIds();
332
+ const idx = allowed.indexOf(deps.getActiveId());
333
+ if (idx === -1) return;
334
+ if (atTop && deltaY > CONTENT_PULL_THRESHOLD && idx > 0) {
335
+ deps.snapTo(allowed[idx - 1]);
336
+ } else if (deltaY < -CONTENT_PULL_THRESHOLD && idx < allowed.length - 1) {
337
+ deps.snapTo(allowed[idx + 1]);
338
+ }
339
+ };
340
+ container.addEventListener("touchstart", onTouchStart, { passive: true });
341
+ container.addEventListener("touchmove", onTouchMove, { passive: true });
342
+ container.addEventListener("touchend", onTouchEnd, { passive: true });
343
+ return () => {
344
+ container.removeEventListener("touchstart", onTouchStart);
345
+ container.removeEventListener("touchmove", onTouchMove);
346
+ container.removeEventListener("touchend", onTouchEnd);
347
+ };
348
+ }
349
+
350
+ // src/core/features/visual-viewport.ts
351
+ var SAFETY_PAD = 8;
352
+ function installVisualViewport(deps) {
353
+ if (typeof window === "undefined" || !window.visualViewport) {
354
+ return () => {
355
+ };
356
+ }
357
+ const vv = window.visualViewport;
358
+ let rafId = null;
359
+ const onResize = () => {
360
+ if (rafId !== null) return;
361
+ rafId = requestAnimationFrame(() => {
362
+ rafId = null;
363
+ if (deps.isDestroyed()) return;
364
+ deps.recomputeSnaps();
365
+ const isVertical = deps.isVerticalAxis();
366
+ const visible = isVertical ? vv.height : vv.width;
367
+ const windowSize = isVertical ? window.innerHeight : window.innerWidth;
368
+ const clamp = Math.max(0, Math.min(windowSize, visible) - SAFETY_PAD);
369
+ if (clamp < deps.getMaxAxisSize()) {
370
+ deps.setMaxAxisSize(clamp);
371
+ }
372
+ const wasAnimating = deps.isAnimating?.() ?? false;
373
+ deps.cancelInFlight();
374
+ deps.newCycle();
375
+ const max = deps.getMaxAxisSize();
376
+ deps.setSize(Math.min(deps.getSize(), max));
377
+ const current = deps.resolveActiveSnap();
378
+ if (current && !deps.isDragging()) {
379
+ deps.applySize(Math.min(current.size, max));
380
+ if (wasAnimating) deps.resyncAfterCancel?.();
381
+ } else {
382
+ deps.applySize(deps.getSize());
383
+ }
384
+ });
385
+ };
386
+ vv.addEventListener("resize", onResize);
387
+ return () => {
388
+ vv.removeEventListener("resize", onResize);
389
+ if (rafId !== null) cancelAnimationFrame(rafId);
390
+ };
391
+ }
392
+
393
+ // src/core/primitives/teardown-stack.ts
394
+ var TeardownStack = class {
395
+ constructor() {
396
+ __publicField(this, "fns", []);
397
+ }
398
+ add(fn) {
399
+ if (fn) this.fns.push(fn);
400
+ }
401
+ drain() {
402
+ while (this.fns.length) {
403
+ try {
404
+ this.fns.pop()();
405
+ } catch (err) {
406
+ queueMicrotask(() => {
407
+ throw err;
408
+ });
409
+ }
410
+ }
411
+ }
412
+ };
413
+
414
+ // src/core/features/engine-features.ts
415
+ function routeFeature() {
416
+ return {
417
+ name: "route",
418
+ install: (ctx) => {
419
+ const teardowns = new TeardownStack();
420
+ if (ctx.options.closeOnRouteChange) {
421
+ teardowns.add(
422
+ installRouteChange({
423
+ isDestroyed: ctx.isDestroyed,
424
+ getSize: ctx.getSize,
425
+ close: () => ctx.close()
426
+ })
427
+ );
428
+ }
429
+ teardowns.add(
430
+ installRoute({
431
+ routedTo: ctx.options.routedTo,
432
+ closeOnBack: ctx.options.closeOnBack,
433
+ isTopSheet: ctx.isTopSheet,
434
+ getSize: ctx.getSize,
435
+ isDestroyed: ctx.isDestroyed,
436
+ close: () => ctx.close("back"),
437
+ on: ctx.on,
438
+ sheetId: ctx.sheetId
439
+ })
440
+ );
441
+ return () => teardowns.drain();
442
+ }
443
+ };
444
+ }
445
+ function persistFeature() {
446
+ return {
447
+ name: "persist",
448
+ install: (ctx) => {
449
+ const key = ctx.options.persistKey;
450
+ if (!key) return;
451
+ return installPersist({ on: ctx.on }, key);
452
+ }
453
+ };
454
+ }
455
+ function autoCollapseFeature() {
456
+ return {
457
+ name: "auto-collapse",
458
+ install: (ctx) => installAutoCollapse({
459
+ ms: ctx.options.autoCollapseAfter,
460
+ isDestroyed: ctx.isDestroyed,
461
+ isDragging: ctx.isDragging,
462
+ getAllowedIds: ctx.getAllowedIds,
463
+ getActiveId: ctx.getActiveId,
464
+ resolveSnap: ctx.resolveSnap,
465
+ snapTo: ctx.snapTo,
466
+ on: ctx.on
467
+ })
468
+ };
469
+ }
470
+ function contentSwipeFeature() {
471
+ return {
472
+ name: "content-swipe",
473
+ stage: "attach",
474
+ install: (ctx) => {
475
+ if (!ctx.scrollContainer) return;
476
+ return installContentSwipe({
477
+ container: ctx.scrollContainer,
478
+ isDragging: ctx.isDragging,
479
+ isAnimating: ctx.isAnimating,
480
+ getAllowedIds: ctx.allowedIdsBySize,
481
+ getActiveId: ctx.getActiveId,
482
+ snapTo: ctx.snapTo
483
+ });
484
+ }
485
+ };
486
+ }
487
+ function visualViewportFeature() {
488
+ return {
489
+ name: "visual-viewport",
490
+ install: (ctx) => {
491
+ if (typeof window === "undefined") return;
492
+ return installVisualViewport({
493
+ element: ctx.element,
494
+ isVerticalAxis: ctx.isVerticalAxis,
495
+ isDestroyed: ctx.isDestroyed,
496
+ isDragging: ctx.isDragging,
497
+ recomputeSnaps: ctx.recomputeSnaps,
498
+ resolveActiveSnap: ctx.resolveActiveSnap,
499
+ getMaxAxisSize: ctx.getMaxAxisSize,
500
+ getSize: ctx.getSize,
501
+ setMaxAxisSize: ctx.setMaxAxisSize,
502
+ setSize: ctx.setSize,
503
+ applySize: ctx.applySize,
504
+ cancelInFlight: ctx.cancelInFlight,
505
+ newCycle: ctx.newCycle,
506
+ isAnimating: ctx.isAnimating,
507
+ resyncAfterCancel: ctx.resyncAfterResize
508
+ });
509
+ }
510
+ };
511
+ }
512
+
513
+ // src/core/default-features.ts
514
+ function defaultEngineFeatures() {
515
+ return [
516
+ contentSwipeFeature(),
517
+ visualViewportFeature(),
518
+ persistFeature(),
519
+ autoCollapseFeature(),
520
+ routeFeature()
521
+ ];
522
+ }
523
+
524
+ export { autoCollapseFeature, contentSwipeFeature, defaultEngineFeatures, persistFeature, routeFeature, visualViewportFeature };
525
+ //# sourceMappingURL=features.js.map
526
+ //# sourceMappingURL=features.js.map
@@ -0,0 +1,15 @@
1
+ import { b as SnapPointDef, c as SheetMode } from './BottomSheetCore-D16lsa6g.js';
2
+
3
+ type ResolvedSnap = {
4
+ id: string;
5
+ size: number;
6
+ };
7
+ declare const resolveSnapList: (points: SnapPointDef[], mode: SheetMode, measureFit?: () => number) => ResolvedSnap[];
8
+ declare const findNearest: (size: number, resolved: ResolvedSnap[], allowed: string[], direction?: 1 | -1 | 0, bias?: number) => ResolvedSnap | null;
9
+ declare const allowedRange: (resolved: ResolvedSnap[], allowed: string[]) => {
10
+ min: number;
11
+ max: number;
12
+ };
13
+ declare const findById: (id: string, resolved: ResolvedSnap[]) => ResolvedSnap | null;
14
+
15
+ export { type ResolvedSnap as R, allowedRange as a, findNearest as b, findById as f, resolveSnapList as r };
@@ -0,0 +1,15 @@
1
+ import { b as SnapPointDef, c as SheetMode } from './BottomSheetCore-CsIjyq7C.cjs';
2
+
3
+ type ResolvedSnap = {
4
+ id: string;
5
+ size: number;
6
+ };
7
+ declare const resolveSnapList: (points: SnapPointDef[], mode: SheetMode, measureFit?: () => number) => ResolvedSnap[];
8
+ declare const findNearest: (size: number, resolved: ResolvedSnap[], allowed: string[], direction?: 1 | -1 | 0, bias?: number) => ResolvedSnap | null;
9
+ declare const allowedRange: (resolved: ResolvedSnap[], allowed: string[]) => {
10
+ min: number;
11
+ max: number;
12
+ };
13
+ declare const findById: (id: string, resolved: ResolvedSnap[]) => ResolvedSnap | null;
14
+
15
+ export { type ResolvedSnap as R, allowedRange as a, findNearest as b, findById as f, resolveSnapList as r };