@surdeddd/bottom-sheet 0.1.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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +377 -0
  3. package/dist/BottomSheetEngine-CvSVbo6c.d.cts +704 -0
  4. package/dist/BottomSheetEngine-DbO8rW_3.d.ts +704 -0
  5. package/dist/element.cjs +3442 -0
  6. package/dist/element.d.cts +88 -0
  7. package/dist/element.d.ts +88 -0
  8. package/dist/element.iife.global.js +3 -0
  9. package/dist/element.js +3442 -0
  10. package/dist/index.cjs +3693 -0
  11. package/dist/index.d.cts +184 -0
  12. package/dist/index.d.ts +184 -0
  13. package/dist/index.js +3669 -0
  14. package/dist/integrations/formik.cjs +27 -0
  15. package/dist/integrations/formik.d.cts +27 -0
  16. package/dist/integrations/formik.d.ts +27 -0
  17. package/dist/integrations/formik.js +25 -0
  18. package/dist/integrations/react-hook-form.cjs +28 -0
  19. package/dist/integrations/react-hook-form.d.cts +30 -0
  20. package/dist/integrations/react-hook-form.d.ts +30 -0
  21. package/dist/integrations/react-hook-form.js +26 -0
  22. package/dist/overlay.cjs +1058 -0
  23. package/dist/overlay.d.cts +282 -0
  24. package/dist/overlay.d.ts +282 -0
  25. package/dist/overlay.js +1053 -0
  26. package/dist/preact.cjs +2 -0
  27. package/dist/preact.d.cts +5 -0
  28. package/dist/preact.d.ts +5 -0
  29. package/dist/preact.js +2 -0
  30. package/dist/qwik.cjs +3046 -0
  31. package/dist/qwik.d.cts +55 -0
  32. package/dist/qwik.d.ts +55 -0
  33. package/dist/qwik.js +3044 -0
  34. package/dist/react.cjs +4162 -0
  35. package/dist/react.d.cts +301 -0
  36. package/dist/react.d.ts +301 -0
  37. package/dist/react.js +4156 -0
  38. package/dist/solid.cjs +3063 -0
  39. package/dist/solid.d.cts +66 -0
  40. package/dist/solid.d.ts +66 -0
  41. package/dist/solid.js +3061 -0
  42. package/dist/styles.css +508 -0
  43. package/dist/svelte.cjs +3200 -0
  44. package/dist/svelte.d.ts +89 -0
  45. package/dist/svelte.js +3177 -0
  46. package/dist/themes/ios.css +24 -0
  47. package/dist/themes/material.css +24 -0
  48. package/dist/themes/vercel.css +24 -0
  49. package/dist/transform-Brkf-wzo.d.cts +4 -0
  50. package/dist/transform-Brkf-wzo.d.ts +4 -0
  51. package/dist/vue.cjs +3361 -0
  52. package/dist/vue.d.ts +68 -0
  53. package/dist/vue.js +3358 -0
  54. package/package.json +288 -0
@@ -0,0 +1,184 @@
1
+ import { c as SnapPoint, a as SheetMode, S as SnapPointDef, b as EngineOptions } from './BottomSheetEngine-CvSVbo6c.cjs';
2
+ export { B as BottomSheetEngine, E as EngineState, P as Plugin, e as SCRIM_PRESETS, f as ScrimOverlayOptions, g as ScrimOverlayPosition, h as ScrimPreset, i as ScrimPresetConfig, j as ScrimUpdate, d as SheetEventMap, k as SnapId, T as TeardownScope } from './BottomSheetEngine-CvSVbo6c.cjs';
3
+ export { OVERLAY_PRESETS, Overlay, OverlayAnimation, OverlayCloseReason, OverlayEdge, Overlay as OverlayEngine, OverlayEventMap, OverlayMountTarget, OverlayOptions, OverlayPreset, OverlayState, OverlayUpdate, SwipeToCloseConfig, createOverlay } from './overlay.cjs';
4
+ import './transform-Brkf-wzo.cjs';
5
+
6
+ declare const easeOutBack: (t: number) => number;
7
+ declare const easeOutCubic: (t: number) => number;
8
+ type Tween = {
9
+ cancel: () => void;
10
+ promise: Promise<void>;
11
+ };
12
+ type TweenOptions = {
13
+ from: number;
14
+ to: number;
15
+ duration: number;
16
+ easing?: (t: number) => number;
17
+ onUpdate: (value: number) => void;
18
+ };
19
+ /**
20
+ * rAF tween. Promise resolves both on natural completion AND on cancel so
21
+ * callers awaiting it always settle; they're expected to cycle-nonce-check
22
+ * after the await before running post-settle effects.
23
+ */
24
+ declare const tween: ({ from, to, duration, easing, onUpdate, }: TweenOptions) => Tween;
25
+ declare const prefersReducedMotion: () => boolean;
26
+
27
+ /**
28
+ * Damped harmonic oscillator: x'' = -k(x - target)/m - c*x'/m
29
+ * Integrated with semi-implicit Euler at variable dt; settles when both
30
+ * displacement and velocity drop below epsilon.
31
+ */
32
+ type SpringConfig = {
33
+ stiffness: number;
34
+ damping: number;
35
+ mass: number;
36
+ /** Stop animation when |x - target| < restDelta AND |v| < restSpeed. */
37
+ restDelta?: number;
38
+ restSpeed?: number;
39
+ };
40
+ declare const DEFAULT_SPRING: SpringConfig;
41
+ type SpringRunOptions = {
42
+ from: number;
43
+ to: number;
44
+ velocity?: number;
45
+ config?: Partial<SpringConfig>;
46
+ onUpdate: (value: number, velocity: number) => void;
47
+ };
48
+ type SpringHandle = {
49
+ cancel: () => void;
50
+ promise: Promise<void>;
51
+ };
52
+ /**
53
+ * Run a spring animation from `from` to `to` with initial velocity. The
54
+ * promise resolves on natural settle AND on cancel so awaiters always
55
+ * settle; callers cycle-nonce-check after the await before running
56
+ * post-settle effects.
57
+ */
58
+ declare const runSpring: ({ from, to, velocity, config, onUpdate, }: SpringRunOptions) => SpringHandle;
59
+
60
+ /**
61
+ * Resolve a `SnapPoint` to pixels.
62
+ *
63
+ * number → as-is
64
+ * "full" → viewport along the axis
65
+ * "fit" → measureFit() — handle/header offset
66
+ * "30%" → percent of viewport along axis (fast path)
67
+ * any other → CSS length resolved via probe element (dvh, vmin,
68
+ * clamp(), env(safe-area-inset-bottom), ...)
69
+ */
70
+ declare const resolveSnap: (point: SnapPoint | string, mode: SheetMode, measureFit?: () => number) => number;
71
+
72
+ type ResolvedSnap = {
73
+ id: string;
74
+ size: number;
75
+ };
76
+ declare const resolveSnapList: (points: SnapPointDef[], mode: SheetMode, measureFit?: () => number) => ResolvedSnap[];
77
+ /**
78
+ * Finds the snap point closest to `size`, optionally biased by drag
79
+ * direction (positive = expanding) so flicks settle on the next-up snap
80
+ * even when geometrically closer to the previous one.
81
+ */
82
+ declare const findNearest: (size: number, resolved: ResolvedSnap[], allowed: string[], direction?: 1 | -1 | 0, bias?: number) => ResolvedSnap | null;
83
+ declare const allowedRange: (resolved: ResolvedSnap[], allowed: string[]) => {
84
+ min: number;
85
+ max: number;
86
+ };
87
+ declare const findById: (id: string, resolved: ResolvedSnap[]) => ResolvedSnap | null;
88
+
89
+ type PointerKind = "touch" | "mouse" | "pen";
90
+ type GestureCallbacks = {
91
+ onStart: (axisCoord: number, pointerType: PointerKind) => void;
92
+ onMove: (delta: number) => void;
93
+ onEnd: (delta: number, velocity: number, pointerType: PointerKind) => void;
94
+ onCancel?: () => void;
95
+ };
96
+ /**
97
+ * Pointer Events handler with velocity tracking. Listens on `handle` for the
98
+ * initial press, then captures the pointer so movement outside the element is
99
+ * still tracked. Multi-touch is ignored: only the first pointer drives the gesture.
100
+ *
101
+ * Velocity is computed from the last ~80ms of samples for stable flick detection.
102
+ */
103
+ declare const installGestures: (handle: HTMLElement, mode: SheetMode, callbacks: GestureCallbacks) => (() => void);
104
+ /**
105
+ * @deprecated Renamed to `installGestures` for naming consistency with the
106
+ * other `installX` feature factories. Will be removed in v2 — see
107
+ * `docs/migration-v2.md`.
108
+ */
109
+ declare const attachGestures: (handle: HTMLElement, mode: SheetMode, callbacks: GestureCallbacks) => (() => void);
110
+
111
+ /**
112
+ * Trap Tab focus inside `container`. Calls `onEscape` when Esc is pressed
113
+ * (caller decides whether to close the sheet). Returns a teardown function
114
+ * that releases the trap and restores focus to the previously-active element.
115
+ *
116
+ * SSR-safe: if `document` is unavailable, returns a no-op teardown.
117
+ */
118
+ declare const installFocusTrap: (container: HTMLElement, options?: {
119
+ initialFocus?: HTMLElement | string;
120
+ onEscape?: () => void;
121
+ }) => (() => void);
122
+
123
+ declare const lockBodyScroll: () => (() => void);
124
+
125
+ /**
126
+ * Multi-sheet z-index orchestration.
127
+ *
128
+ * When you have a sheet that itself opens another sheet (e.g. menu → detail),
129
+ * naive rendering stacks them at the same z-index and the second one is
130
+ * obscured. The stack assigns ascending z-indices and notifies the topmost
131
+ * sheet so it can render its backdrop while inner sheets skip theirs.
132
+ */
133
+ type StackEntry = {
134
+ id: string;
135
+ setZIndex: (z: number) => void;
136
+ setIsTop: (isTop: boolean) => void;
137
+ };
138
+ declare class SheetStack {
139
+ private entries;
140
+ push(entry: StackEntry): () => void;
141
+ remove(id: string): void;
142
+ size(): number;
143
+ clear(): void;
144
+ private recompute;
145
+ }
146
+ /** Process-wide singleton so any adapter can reach the same stack. */
147
+ declare const sheetStack: SheetStack;
148
+
149
+ /**
150
+ * Route-based / context-based sheet config registry. Caller maps a key
151
+ * (route name, screen id, modal kind, anything) to a partial engine config;
152
+ * `manager.resolve(key)` returns the merged options ready to feed into
153
+ * `BottomSheetEngine` or any adapter.
154
+ *
155
+ * Lifecycle hooks (`onOpen`, `onClose`) are stored alongside the config so
156
+ * the consumer can attach them via `engine.on(...)` without ceremony.
157
+ *
158
+ * const manager = createSheetManager({
159
+ * home: { snapPoints: [...], allowed: ["min","half","full"], onOpen: load },
160
+ * marker: { snapPoints: [...], allowed: ["half","full"], onOpen: focus },
161
+ * });
162
+ * manager.resolve("home"); // → { snapPoints, allowed, onOpen, onClose }
163
+ */
164
+ type SheetConfig<Key extends string = string> = Partial<Omit<EngineOptions, "element" | "handle" | "scrollContainer" | "backdrop">> & {
165
+ /** Logical key (route name, modal kind, ...) — useful for telemetry. */
166
+ key?: Key;
167
+ onOpen?: (key: Key) => void;
168
+ onClose?: (key: Key) => void;
169
+ };
170
+ type SheetManager<Key extends string = string> = {
171
+ /** Register or replace a config. */
172
+ register(key: Key, config: SheetConfig<Key>): void;
173
+ /** Remove a registered config. */
174
+ unregister(key: Key): void;
175
+ /** Look up a config by key. Returns null if absent. */
176
+ resolve(key: Key): SheetConfig<Key> | null;
177
+ /** Get all registered keys. */
178
+ keys(): Key[];
179
+ /** Run `onClose(prev)` then `onOpen(next)` — for route transitions. */
180
+ transition(prev: Key | null, next: Key | null): void;
181
+ };
182
+ declare const createSheetManager: <Key extends string = string>(initial?: Record<Key, SheetConfig<Key>>) => SheetManager<Key>;
183
+
184
+ export { DEFAULT_SPRING, EngineOptions, type ResolvedSnap, type SheetConfig, type SheetManager, SheetMode, SnapPoint, SnapPointDef, type SpringConfig, type SpringHandle, type SpringRunOptions, type StackEntry, type Tween, type TweenOptions, allowedRange, attachGestures, createSheetManager, easeOutBack, easeOutCubic, findById, findNearest, installFocusTrap, installGestures, lockBodyScroll, prefersReducedMotion, resolveSnap, resolveSnapList, runSpring, sheetStack, tween };
@@ -0,0 +1,184 @@
1
+ import { c as SnapPoint, a as SheetMode, S as SnapPointDef, b as EngineOptions } from './BottomSheetEngine-DbO8rW_3.js';
2
+ export { B as BottomSheetEngine, E as EngineState, P as Plugin, e as SCRIM_PRESETS, f as ScrimOverlayOptions, g as ScrimOverlayPosition, h as ScrimPreset, i as ScrimPresetConfig, j as ScrimUpdate, d as SheetEventMap, k as SnapId, T as TeardownScope } from './BottomSheetEngine-DbO8rW_3.js';
3
+ export { OVERLAY_PRESETS, Overlay, OverlayAnimation, OverlayCloseReason, OverlayEdge, Overlay as OverlayEngine, OverlayEventMap, OverlayMountTarget, OverlayOptions, OverlayPreset, OverlayState, OverlayUpdate, SwipeToCloseConfig, createOverlay } from './overlay.js';
4
+ import './transform-Brkf-wzo.js';
5
+
6
+ declare const easeOutBack: (t: number) => number;
7
+ declare const easeOutCubic: (t: number) => number;
8
+ type Tween = {
9
+ cancel: () => void;
10
+ promise: Promise<void>;
11
+ };
12
+ type TweenOptions = {
13
+ from: number;
14
+ to: number;
15
+ duration: number;
16
+ easing?: (t: number) => number;
17
+ onUpdate: (value: number) => void;
18
+ };
19
+ /**
20
+ * rAF tween. Promise resolves both on natural completion AND on cancel so
21
+ * callers awaiting it always settle; they're expected to cycle-nonce-check
22
+ * after the await before running post-settle effects.
23
+ */
24
+ declare const tween: ({ from, to, duration, easing, onUpdate, }: TweenOptions) => Tween;
25
+ declare const prefersReducedMotion: () => boolean;
26
+
27
+ /**
28
+ * Damped harmonic oscillator: x'' = -k(x - target)/m - c*x'/m
29
+ * Integrated with semi-implicit Euler at variable dt; settles when both
30
+ * displacement and velocity drop below epsilon.
31
+ */
32
+ type SpringConfig = {
33
+ stiffness: number;
34
+ damping: number;
35
+ mass: number;
36
+ /** Stop animation when |x - target| < restDelta AND |v| < restSpeed. */
37
+ restDelta?: number;
38
+ restSpeed?: number;
39
+ };
40
+ declare const DEFAULT_SPRING: SpringConfig;
41
+ type SpringRunOptions = {
42
+ from: number;
43
+ to: number;
44
+ velocity?: number;
45
+ config?: Partial<SpringConfig>;
46
+ onUpdate: (value: number, velocity: number) => void;
47
+ };
48
+ type SpringHandle = {
49
+ cancel: () => void;
50
+ promise: Promise<void>;
51
+ };
52
+ /**
53
+ * Run a spring animation from `from` to `to` with initial velocity. The
54
+ * promise resolves on natural settle AND on cancel so awaiters always
55
+ * settle; callers cycle-nonce-check after the await before running
56
+ * post-settle effects.
57
+ */
58
+ declare const runSpring: ({ from, to, velocity, config, onUpdate, }: SpringRunOptions) => SpringHandle;
59
+
60
+ /**
61
+ * Resolve a `SnapPoint` to pixels.
62
+ *
63
+ * number → as-is
64
+ * "full" → viewport along the axis
65
+ * "fit" → measureFit() — handle/header offset
66
+ * "30%" → percent of viewport along axis (fast path)
67
+ * any other → CSS length resolved via probe element (dvh, vmin,
68
+ * clamp(), env(safe-area-inset-bottom), ...)
69
+ */
70
+ declare const resolveSnap: (point: SnapPoint | string, mode: SheetMode, measureFit?: () => number) => number;
71
+
72
+ type ResolvedSnap = {
73
+ id: string;
74
+ size: number;
75
+ };
76
+ declare const resolveSnapList: (points: SnapPointDef[], mode: SheetMode, measureFit?: () => number) => ResolvedSnap[];
77
+ /**
78
+ * Finds the snap point closest to `size`, optionally biased by drag
79
+ * direction (positive = expanding) so flicks settle on the next-up snap
80
+ * even when geometrically closer to the previous one.
81
+ */
82
+ declare const findNearest: (size: number, resolved: ResolvedSnap[], allowed: string[], direction?: 1 | -1 | 0, bias?: number) => ResolvedSnap | null;
83
+ declare const allowedRange: (resolved: ResolvedSnap[], allowed: string[]) => {
84
+ min: number;
85
+ max: number;
86
+ };
87
+ declare const findById: (id: string, resolved: ResolvedSnap[]) => ResolvedSnap | null;
88
+
89
+ type PointerKind = "touch" | "mouse" | "pen";
90
+ type GestureCallbacks = {
91
+ onStart: (axisCoord: number, pointerType: PointerKind) => void;
92
+ onMove: (delta: number) => void;
93
+ onEnd: (delta: number, velocity: number, pointerType: PointerKind) => void;
94
+ onCancel?: () => void;
95
+ };
96
+ /**
97
+ * Pointer Events handler with velocity tracking. Listens on `handle` for the
98
+ * initial press, then captures the pointer so movement outside the element is
99
+ * still tracked. Multi-touch is ignored: only the first pointer drives the gesture.
100
+ *
101
+ * Velocity is computed from the last ~80ms of samples for stable flick detection.
102
+ */
103
+ declare const installGestures: (handle: HTMLElement, mode: SheetMode, callbacks: GestureCallbacks) => (() => void);
104
+ /**
105
+ * @deprecated Renamed to `installGestures` for naming consistency with the
106
+ * other `installX` feature factories. Will be removed in v2 — see
107
+ * `docs/migration-v2.md`.
108
+ */
109
+ declare const attachGestures: (handle: HTMLElement, mode: SheetMode, callbacks: GestureCallbacks) => (() => void);
110
+
111
+ /**
112
+ * Trap Tab focus inside `container`. Calls `onEscape` when Esc is pressed
113
+ * (caller decides whether to close the sheet). Returns a teardown function
114
+ * that releases the trap and restores focus to the previously-active element.
115
+ *
116
+ * SSR-safe: if `document` is unavailable, returns a no-op teardown.
117
+ */
118
+ declare const installFocusTrap: (container: HTMLElement, options?: {
119
+ initialFocus?: HTMLElement | string;
120
+ onEscape?: () => void;
121
+ }) => (() => void);
122
+
123
+ declare const lockBodyScroll: () => (() => void);
124
+
125
+ /**
126
+ * Multi-sheet z-index orchestration.
127
+ *
128
+ * When you have a sheet that itself opens another sheet (e.g. menu → detail),
129
+ * naive rendering stacks them at the same z-index and the second one is
130
+ * obscured. The stack assigns ascending z-indices and notifies the topmost
131
+ * sheet so it can render its backdrop while inner sheets skip theirs.
132
+ */
133
+ type StackEntry = {
134
+ id: string;
135
+ setZIndex: (z: number) => void;
136
+ setIsTop: (isTop: boolean) => void;
137
+ };
138
+ declare class SheetStack {
139
+ private entries;
140
+ push(entry: StackEntry): () => void;
141
+ remove(id: string): void;
142
+ size(): number;
143
+ clear(): void;
144
+ private recompute;
145
+ }
146
+ /** Process-wide singleton so any adapter can reach the same stack. */
147
+ declare const sheetStack: SheetStack;
148
+
149
+ /**
150
+ * Route-based / context-based sheet config registry. Caller maps a key
151
+ * (route name, screen id, modal kind, anything) to a partial engine config;
152
+ * `manager.resolve(key)` returns the merged options ready to feed into
153
+ * `BottomSheetEngine` or any adapter.
154
+ *
155
+ * Lifecycle hooks (`onOpen`, `onClose`) are stored alongside the config so
156
+ * the consumer can attach them via `engine.on(...)` without ceremony.
157
+ *
158
+ * const manager = createSheetManager({
159
+ * home: { snapPoints: [...], allowed: ["min","half","full"], onOpen: load },
160
+ * marker: { snapPoints: [...], allowed: ["half","full"], onOpen: focus },
161
+ * });
162
+ * manager.resolve("home"); // → { snapPoints, allowed, onOpen, onClose }
163
+ */
164
+ type SheetConfig<Key extends string = string> = Partial<Omit<EngineOptions, "element" | "handle" | "scrollContainer" | "backdrop">> & {
165
+ /** Logical key (route name, modal kind, ...) — useful for telemetry. */
166
+ key?: Key;
167
+ onOpen?: (key: Key) => void;
168
+ onClose?: (key: Key) => void;
169
+ };
170
+ type SheetManager<Key extends string = string> = {
171
+ /** Register or replace a config. */
172
+ register(key: Key, config: SheetConfig<Key>): void;
173
+ /** Remove a registered config. */
174
+ unregister(key: Key): void;
175
+ /** Look up a config by key. Returns null if absent. */
176
+ resolve(key: Key): SheetConfig<Key> | null;
177
+ /** Get all registered keys. */
178
+ keys(): Key[];
179
+ /** Run `onClose(prev)` then `onOpen(next)` — for route transitions. */
180
+ transition(prev: Key | null, next: Key | null): void;
181
+ };
182
+ declare const createSheetManager: <Key extends string = string>(initial?: Record<Key, SheetConfig<Key>>) => SheetManager<Key>;
183
+
184
+ export { DEFAULT_SPRING, EngineOptions, type ResolvedSnap, type SheetConfig, type SheetManager, SheetMode, SnapPoint, SnapPointDef, type SpringConfig, type SpringHandle, type SpringRunOptions, type StackEntry, type Tween, type TweenOptions, allowedRange, attachGestures, createSheetManager, easeOutBack, easeOutCubic, findById, findNearest, installFocusTrap, installGestures, lockBodyScroll, prefersReducedMotion, resolveSnap, resolveSnapList, runSpring, sheetStack, tween };