@surdeddd/bottom-sheet 0.12.0 → 0.14.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 (66) hide show
  1. package/README.md +85 -1
  2. package/dist/{BottomSheetEngine-D6oiEfZ4.d.cts → BottomSheetCore-Cp7dWy91.d.cts} +85 -5
  3. package/dist/{BottomSheetEngine-Dhy0X_e9.d.ts → BottomSheetCore-DJYwWOqt.d.ts} +85 -5
  4. package/dist/BottomSheetEngine-Lm7HIVHv.d.cts +7 -0
  5. package/dist/BottomSheetEngine-O5PbeKfe.d.ts +7 -0
  6. package/dist/core.cjs +3680 -0
  7. package/dist/core.d.cts +3 -0
  8. package/dist/core.d.ts +3 -0
  9. package/dist/core.js +3678 -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 +1314 -829
  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 +1314 -829
  19. package/dist/features.cjs +489 -0
  20. package/dist/features.d.cts +13 -0
  21. package/dist/features.d.ts +13 -0
  22. package/dist/features.js +482 -0
  23. package/dist/index-Bb5TRmyg.d.cts +9 -0
  24. package/dist/index-Cl9ebCP2.d.ts +9 -0
  25. package/dist/index.cjs +979 -1293
  26. package/dist/index.d.cts +43 -55
  27. package/dist/index.d.ts +43 -55
  28. package/dist/index.js +973 -1280
  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 +11 -10
  34. package/dist/overlay.js +11 -10
  35. package/dist/preact.d.cts +2 -1
  36. package/dist/preact.d.ts +2 -1
  37. package/dist/qwik-lib/index.qwik.cjs +4418 -0
  38. package/dist/qwik-lib/index.qwik.mjs +4418 -0
  39. package/dist/qwik.cjs +1089 -657
  40. package/dist/qwik.d.cts +4 -2
  41. package/dist/qwik.d.ts +4 -2
  42. package/dist/qwik.js +1089 -657
  43. package/dist/react.cjs +1100 -665
  44. package/dist/react.d.cts +3 -3
  45. package/dist/react.d.ts +3 -3
  46. package/dist/react.js +1100 -665
  47. package/dist/solid.cjs +1095 -657
  48. package/dist/solid.d.cts +90 -4
  49. package/dist/solid.d.ts +90 -4
  50. package/dist/solid.js +1095 -657
  51. package/dist/solid.source.jsx +1103 -657
  52. package/dist/styles.css +24 -4
  53. package/dist/svelte-core.cjs +981 -557
  54. package/dist/svelte-core.js +981 -557
  55. package/dist/svelte-src/BottomSheet.svelte +14 -0
  56. package/dist/svelte.cjs +1091 -657
  57. package/dist/svelte.d.cts +2 -0
  58. package/dist/svelte.d.ts +2 -0
  59. package/dist/svelte.js +1091 -657
  60. package/dist/vue.cjs +1105 -657
  61. package/dist/vue.js +1105 -657
  62. package/dist/webgl.cjs +583 -0
  63. package/dist/webgl.d.cts +17 -0
  64. package/dist/webgl.d.ts +17 -0
  65. package/dist/webgl.js +581 -0
  66. package/package.json +88 -12
@@ -0,0 +1,489 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
6
+
7
+ // src/core/features/history-coordinator.ts
8
+ var entries = [];
9
+ var subscribers = /* @__PURE__ */ new Set();
10
+ var suppress = 0;
11
+ var internalDepth = 0;
12
+ var pendingRebrands = [];
13
+ var listenerInstalled = false;
14
+ var patchInstalled = false;
15
+ var origPushState = null;
16
+ var origReplaceState = null;
17
+ var patchedPushState = null;
18
+ var patchedReplaceState = null;
19
+ var hasWindow = () => typeof window !== "undefined";
20
+ var hasHistory = () => typeof history !== "undefined";
21
+ var brandMarker = (surface) => ({
22
+ ...surface.markerState(),
23
+ __bs: true
24
+ });
25
+ var runInternal = (fn) => {
26
+ internalDepth += 1;
27
+ try {
28
+ fn();
29
+ } finally {
30
+ internalDepth -= 1;
31
+ }
32
+ };
33
+ var notifyRouteChange = () => {
34
+ const snapshot = Array.from(subscribers);
35
+ for (const fn of snapshot) fn();
36
+ };
37
+ var ensureListener = () => {
38
+ if (listenerInstalled || !hasWindow()) return;
39
+ window.addEventListener("popstate", onPopState);
40
+ listenerInstalled = true;
41
+ };
42
+ var maybeTeardownListener = () => {
43
+ if (!listenerInstalled) return;
44
+ if (entries.length > 0 || subscribers.size > 0 || suppress > 0) return;
45
+ if (hasWindow()) window.removeEventListener("popstate", onPopState);
46
+ listenerInstalled = false;
47
+ };
48
+ var installPatch = () => {
49
+ if (patchInstalled || !hasHistory()) return;
50
+ origPushState = history.pushState;
51
+ origReplaceState = history.replaceState;
52
+ patchedPushState = function(...args) {
53
+ origPushState.apply(this, args);
54
+ if (internalDepth === 0) notifyRouteChange();
55
+ };
56
+ patchedReplaceState = function(...args) {
57
+ origReplaceState.apply(this, args);
58
+ if (internalDepth === 0) notifyRouteChange();
59
+ };
60
+ history.pushState = patchedPushState;
61
+ history.replaceState = patchedReplaceState;
62
+ patchInstalled = true;
63
+ };
64
+ var removePatch = () => {
65
+ if (!patchInstalled) return;
66
+ if (history.pushState === patchedPushState && origPushState) {
67
+ history.pushState = origPushState;
68
+ }
69
+ if (history.replaceState === patchedReplaceState && origReplaceState) {
70
+ history.replaceState = origReplaceState;
71
+ }
72
+ origPushState = null;
73
+ origReplaceState = null;
74
+ patchedPushState = null;
75
+ patchedReplaceState = null;
76
+ patchInstalled = false;
77
+ };
78
+ function onPopState() {
79
+ if (suppress > 0) {
80
+ suppress -= 1;
81
+ const rebrand = pendingRebrands.shift();
82
+ if (rebrand) rebrand();
83
+ maybeTeardownListener();
84
+ return;
85
+ }
86
+ if (entries.length === 0) {
87
+ notifyRouteChange();
88
+ maybeTeardownListener();
89
+ return;
90
+ }
91
+ let target = null;
92
+ let targetIdx = -1;
93
+ for (let i = entries.length - 1; i >= 0; i -= 1) {
94
+ const entry = entries[i];
95
+ if (!entry.surface.isOpen()) continue;
96
+ if (!target) {
97
+ target = entry;
98
+ targetIdx = i;
99
+ }
100
+ if (entry.surface.isTop()) {
101
+ target = entry;
102
+ targetIdx = i;
103
+ break;
104
+ }
105
+ }
106
+ if (!target) {
107
+ const removed = entries.pop();
108
+ if (removed) removed.live = false;
109
+ maybeTeardownListener();
110
+ return;
111
+ }
112
+ target.live = false;
113
+ entries.splice(targetIdx, 1);
114
+ const settled = target;
115
+ void Promise.resolve(settled.surface.close()).then(() => {
116
+ if (settled.surface.isOpen()) restore(settled);
117
+ });
118
+ maybeTeardownListener();
119
+ }
120
+ function restore(entry) {
121
+ if (!hasWindow() || !hasHistory()) return;
122
+ entry.live = true;
123
+ runInternal(() => {
124
+ try {
125
+ history.pushState(brandMarker(entry.surface), "", entry.surface.url);
126
+ } catch {
127
+ entry.live = false;
128
+ }
129
+ });
130
+ if (entry.live) {
131
+ entries.push(entry);
132
+ ensureListener();
133
+ }
134
+ }
135
+ function pushBackMarker(surface) {
136
+ const entry = { surface, priorUrl: void 0, live: false };
137
+ if (!hasWindow() || !hasHistory()) {
138
+ return entry;
139
+ }
140
+ entry.priorUrl = surface.url !== void 0 ? location.href : void 0;
141
+ runInternal(() => {
142
+ try {
143
+ history.pushState(brandMarker(surface), "", surface.url);
144
+ entry.live = true;
145
+ } catch {
146
+ entry.live = false;
147
+ }
148
+ });
149
+ if (entry.live) {
150
+ entries.push(entry);
151
+ ensureListener();
152
+ }
153
+ return entry;
154
+ }
155
+ function popBackMarker(handle) {
156
+ if (!hasWindow() || !hasHistory()) return;
157
+ const entry = handle;
158
+ const idx = entries.indexOf(entry);
159
+ if (idx === -1 || !entry.live) return;
160
+ const last = entries.length - 1;
161
+ entry.live = false;
162
+ entries.splice(idx, 1);
163
+ let rebrand = null;
164
+ if (idx !== last) {
165
+ const rebrandSurface = entries[entries.length - 1].surface;
166
+ const rebrandUrl = entry.priorUrl;
167
+ rebrand = () => {
168
+ runInternal(() => {
169
+ history.replaceState(
170
+ brandMarker(rebrandSurface),
171
+ "",
172
+ rebrandUrl !== void 0 ? rebrandUrl : location.href
173
+ );
174
+ });
175
+ };
176
+ }
177
+ pendingRebrands.push(rebrand);
178
+ suppress += 1;
179
+ runInternal(() => {
180
+ try {
181
+ history.back();
182
+ } catch {
183
+ suppress = Math.max(0, suppress - 1);
184
+ pendingRebrands.pop();
185
+ }
186
+ });
187
+ maybeTeardownListener();
188
+ }
189
+ function subscribeRouteChange(fn) {
190
+ if (!hasWindow() || !hasHistory()) return () => {
191
+ };
192
+ subscribers.add(fn);
193
+ if (subscribers.size === 1) installPatch();
194
+ ensureListener();
195
+ return () => {
196
+ if (!subscribers.has(fn)) return;
197
+ subscribers.delete(fn);
198
+ if (subscribers.size === 0) removePatch();
199
+ maybeTeardownListener();
200
+ };
201
+ }
202
+
203
+ // src/core/features/route.ts
204
+ function installRoute(deps) {
205
+ if (typeof window === "undefined") {
206
+ return () => {
207
+ };
208
+ }
209
+ if (!deps.routedTo && !deps.closeOnBack) {
210
+ return () => {
211
+ };
212
+ }
213
+ let handle = null;
214
+ const onOpen = () => {
215
+ if (handle) return;
216
+ handle = pushBackMarker({
217
+ isOpen: () => !deps.isDestroyed() && deps.getSize() > 0,
218
+ isTop: deps.isTopSheet,
219
+ close: deps.close,
220
+ markerState: () => deps.routedTo !== void 0 ? { __bsRouted: deps.sheetId } : { __bsSheet: deps.sheetId },
221
+ url: deps.routedTo
222
+ });
223
+ };
224
+ const onClose = () => {
225
+ if (!handle) return;
226
+ popBackMarker(handle);
227
+ handle = null;
228
+ };
229
+ const unsubscribeOpen = deps.on("open", onOpen);
230
+ const unsubscribeClose = deps.on("close", onClose);
231
+ if (deps.getSize() > 0) onOpen();
232
+ return () => {
233
+ unsubscribeOpen();
234
+ unsubscribeClose();
235
+ if (handle) {
236
+ popBackMarker(handle);
237
+ handle = null;
238
+ }
239
+ };
240
+ }
241
+ function installRouteChange(deps) {
242
+ return subscribeRouteChange(() => {
243
+ if (deps.isDestroyed() || deps.getSize() <= 0) return;
244
+ void deps.close();
245
+ });
246
+ }
247
+
248
+ // src/core/features/persist.ts
249
+ function installPersist(engine, key) {
250
+ const unsubscribe = engine.on("snap", ({ id }) => {
251
+ if (typeof window === "undefined") return;
252
+ if (typeof localStorage === "undefined") return;
253
+ try {
254
+ localStorage.setItem(key, id);
255
+ } catch {
256
+ }
257
+ });
258
+ return unsubscribe;
259
+ }
260
+
261
+ // src/core/features/auto-collapse.ts
262
+ function installAutoCollapse(deps) {
263
+ const { ms } = deps;
264
+ if (ms === void 0 || ms <= 0) {
265
+ return () => {
266
+ };
267
+ }
268
+ let timer = null;
269
+ const clearTimer = () => {
270
+ if (timer !== null) {
271
+ clearTimeout(timer);
272
+ timer = null;
273
+ }
274
+ };
275
+ const fire = () => {
276
+ if (deps.isDestroyed()) return;
277
+ if (deps.isDragging()) return;
278
+ const active = deps.resolveSnap(deps.getActiveId());
279
+ if (!active || active.size === 0) return;
280
+ let target = null;
281
+ for (const id of deps.getAllowedIds()) {
282
+ const snap = deps.resolveSnap(id);
283
+ if (!snap || snap.size <= 0) continue;
284
+ if (!target || snap.size < target.size) target = snap;
285
+ }
286
+ if (!target) return;
287
+ if (target.id === active.id || target.size >= active.size) return;
288
+ deps.snapTo(target.id);
289
+ };
290
+ const reset = () => {
291
+ clearTimer();
292
+ if (deps.isDestroyed()) return;
293
+ timer = setTimeout(() => {
294
+ timer = null;
295
+ fire();
296
+ }, ms);
297
+ };
298
+ const unsubscribe = deps.on("snap", () => reset());
299
+ if ((deps.resolveSnap(deps.getActiveId())?.size ?? 0) > 0) reset();
300
+ return () => {
301
+ clearTimer();
302
+ unsubscribe();
303
+ };
304
+ }
305
+
306
+ // src/core/features/content-drag.ts
307
+ function installContentDrag(deps) {
308
+ const detach = deps.attachDragSurface(deps.container, "content");
309
+ return () => detach?.();
310
+ }
311
+
312
+ // src/core/features/visual-viewport.ts
313
+ var SAFETY_PAD = 8;
314
+ function installVisualViewport(deps) {
315
+ if (typeof window === "undefined" || !window.visualViewport) {
316
+ return () => {
317
+ };
318
+ }
319
+ const vv = window.visualViewport;
320
+ let rafId = null;
321
+ const onResize = () => {
322
+ if (rafId !== null) return;
323
+ rafId = requestAnimationFrame(() => {
324
+ rafId = null;
325
+ if (deps.isDestroyed()) return;
326
+ deps.recomputeSnaps();
327
+ const isVertical = deps.isVerticalAxis();
328
+ const visible = isVertical ? vv.height : vv.width;
329
+ const windowSize = isVertical ? window.innerHeight : window.innerWidth;
330
+ const clamp = Math.max(0, Math.min(windowSize, visible) - SAFETY_PAD);
331
+ if (clamp < deps.getMaxAxisSize()) {
332
+ deps.setMaxAxisSize(clamp);
333
+ }
334
+ const wasAnimating = deps.isAnimating?.() ?? false;
335
+ deps.cancelInFlight();
336
+ deps.newCycle();
337
+ const max = deps.getMaxAxisSize();
338
+ deps.setSize(Math.min(deps.getSize(), max));
339
+ const current = deps.resolveActiveSnap();
340
+ if (current && !deps.isDragging()) {
341
+ deps.applySize(Math.min(current.size, max));
342
+ if (wasAnimating) deps.resyncAfterCancel?.();
343
+ } else {
344
+ deps.applySize(deps.getSize());
345
+ }
346
+ });
347
+ };
348
+ vv.addEventListener("resize", onResize);
349
+ return () => {
350
+ vv.removeEventListener("resize", onResize);
351
+ if (rafId !== null) cancelAnimationFrame(rafId);
352
+ };
353
+ }
354
+
355
+ // src/core/primitives/teardown-stack.ts
356
+ var TeardownStack = class {
357
+ constructor() {
358
+ __publicField(this, "fns", []);
359
+ }
360
+ add(fn) {
361
+ if (fn) this.fns.push(fn);
362
+ }
363
+ drain() {
364
+ while (this.fns.length) {
365
+ try {
366
+ this.fns.pop()();
367
+ } catch (err) {
368
+ queueMicrotask(() => {
369
+ throw err;
370
+ });
371
+ }
372
+ }
373
+ }
374
+ };
375
+
376
+ // src/core/features/engine-features.ts
377
+ function routeFeature() {
378
+ return {
379
+ name: "route",
380
+ install: (ctx) => {
381
+ const teardowns = new TeardownStack();
382
+ if (ctx.options.closeOnRouteChange) {
383
+ teardowns.add(
384
+ installRouteChange({
385
+ isDestroyed: ctx.isDestroyed,
386
+ getSize: ctx.getSize,
387
+ close: () => ctx.close()
388
+ })
389
+ );
390
+ }
391
+ teardowns.add(
392
+ installRoute({
393
+ routedTo: ctx.options.routedTo,
394
+ closeOnBack: ctx.options.closeOnBack,
395
+ isTopSheet: ctx.isTopSheet,
396
+ getSize: ctx.getSize,
397
+ isDestroyed: ctx.isDestroyed,
398
+ close: () => ctx.close("back"),
399
+ on: ctx.on,
400
+ sheetId: ctx.sheetId
401
+ })
402
+ );
403
+ return () => teardowns.drain();
404
+ }
405
+ };
406
+ }
407
+ function persistFeature() {
408
+ return {
409
+ name: "persist",
410
+ install: (ctx) => {
411
+ const key = ctx.options.persistKey;
412
+ if (!key) return;
413
+ return installPersist({ on: ctx.on }, key);
414
+ }
415
+ };
416
+ }
417
+ function autoCollapseFeature() {
418
+ return {
419
+ name: "auto-collapse",
420
+ install: (ctx) => installAutoCollapse({
421
+ ms: ctx.options.autoCollapseAfter,
422
+ isDestroyed: ctx.isDestroyed,
423
+ isDragging: ctx.isDragging,
424
+ getAllowedIds: ctx.getAllowedIds,
425
+ getActiveId: ctx.getActiveId,
426
+ resolveSnap: ctx.resolveSnap,
427
+ snapTo: ctx.snapTo,
428
+ on: ctx.on
429
+ })
430
+ };
431
+ }
432
+ function contentSwipeFeature() {
433
+ return {
434
+ name: "content-swipe",
435
+ stage: "attach",
436
+ install: (ctx) => {
437
+ if (!ctx.scrollContainer) return;
438
+ return installContentDrag({
439
+ container: ctx.scrollContainer,
440
+ attachDragSurface: ctx.attachDragSurface
441
+ });
442
+ }
443
+ };
444
+ }
445
+ function visualViewportFeature() {
446
+ return {
447
+ name: "visual-viewport",
448
+ install: (ctx) => {
449
+ if (typeof window === "undefined") return;
450
+ return installVisualViewport({
451
+ element: ctx.element,
452
+ isVerticalAxis: ctx.isVerticalAxis,
453
+ isDestroyed: ctx.isDestroyed,
454
+ isDragging: ctx.isDragging,
455
+ recomputeSnaps: ctx.recomputeSnaps,
456
+ resolveActiveSnap: ctx.resolveActiveSnap,
457
+ getMaxAxisSize: ctx.getMaxAxisSize,
458
+ getSize: ctx.getSize,
459
+ setMaxAxisSize: ctx.setMaxAxisSize,
460
+ setSize: ctx.setSize,
461
+ applySize: ctx.applySize,
462
+ cancelInFlight: ctx.cancelInFlight,
463
+ newCycle: ctx.newCycle,
464
+ isAnimating: ctx.isAnimating,
465
+ resyncAfterCancel: ctx.resyncAfterResize
466
+ });
467
+ }
468
+ };
469
+ }
470
+
471
+ // src/core/default-features.ts
472
+ function defaultEngineFeatures() {
473
+ return [
474
+ contentSwipeFeature(),
475
+ visualViewportFeature(),
476
+ persistFeature(),
477
+ autoCollapseFeature(),
478
+ routeFeature()
479
+ ];
480
+ }
481
+
482
+ exports.autoCollapseFeature = autoCollapseFeature;
483
+ exports.contentSwipeFeature = contentSwipeFeature;
484
+ exports.defaultEngineFeatures = defaultEngineFeatures;
485
+ exports.persistFeature = persistFeature;
486
+ exports.routeFeature = routeFeature;
487
+ exports.visualViewportFeature = visualViewportFeature;
488
+ //# sourceMappingURL=features.cjs.map
489
+ //# sourceMappingURL=features.cjs.map
@@ -0,0 +1,13 @@
1
+ import { f as EngineFeature } from './BottomSheetCore-Cp7dWy91.cjs';
2
+ export { m as EngineFeatureContext, n as EngineFeatureOptions, o as EngineFeatureStage } from './BottomSheetCore-Cp7dWy91.cjs';
3
+ import './transform-jVfAikE9.cjs';
4
+
5
+ declare function defaultEngineFeatures(): EngineFeature[];
6
+
7
+ declare function routeFeature(): EngineFeature;
8
+ declare function persistFeature(): EngineFeature;
9
+ declare function autoCollapseFeature(): EngineFeature;
10
+ declare function contentSwipeFeature(): EngineFeature;
11
+ declare function visualViewportFeature(): EngineFeature;
12
+
13
+ export { EngineFeature, autoCollapseFeature, contentSwipeFeature, defaultEngineFeatures, persistFeature, routeFeature, visualViewportFeature };
@@ -0,0 +1,13 @@
1
+ import { f as EngineFeature } from './BottomSheetCore-DJYwWOqt.js';
2
+ export { m as EngineFeatureContext, n as EngineFeatureOptions, o as EngineFeatureStage } from './BottomSheetCore-DJYwWOqt.js';
3
+ import './transform-jVfAikE9.js';
4
+
5
+ declare function defaultEngineFeatures(): EngineFeature[];
6
+
7
+ declare function routeFeature(): EngineFeature;
8
+ declare function persistFeature(): EngineFeature;
9
+ declare function autoCollapseFeature(): EngineFeature;
10
+ declare function contentSwipeFeature(): EngineFeature;
11
+ declare function visualViewportFeature(): EngineFeature;
12
+
13
+ export { EngineFeature, autoCollapseFeature, contentSwipeFeature, defaultEngineFeatures, persistFeature, routeFeature, visualViewportFeature };