@brett_lamy/ui 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,257 @@
1
+ "use client";
2
+ import { LocalStreams as e, StreamFullError as t } from "./append-stream.js";
3
+ import { CloudSync as n, deviceId as r, useCloud as i } from "./durable-streams.js";
4
+ import { useEffect as a, useSyncExternalStore as o } from "react";
5
+ //#region src/lib/session-recorder.ts
6
+ var s = "sessions", c = (e) => `session/${e}`, l = 5e6, u = [], d = null, f = new e({ evict(e) {
7
+ let t = [...u].reverse().find((t) => t.local && t.id !== d && c(t.id) !== e);
8
+ return t ? (f.remove(c(t.id)), !0) : !1;
9
+ } }), p = new n(f, [s]);
10
+ async function m() {
11
+ let e = await f.read(s), t = p.pulledRecords(s), n = /* @__PURE__ */ new Set(), r = [...e, ...t].filter((e) => {
12
+ let t = `${e.t}:${e.id}`;
13
+ return !n.has(t) && (n.add(t), !0);
14
+ }), i = new Set(r.filter((e) => e.t === "delete").map((e) => e.id)), a = [];
15
+ for (let e of r) {
16
+ if (e.t !== "start" || i.has(e.id)) continue;
17
+ let t = r.find((t) => t.t === "end" && t.id === e.id), n = f.length(c(e.id)), o = p.getSettings().enabled;
18
+ !n && !o || a.push({
19
+ id: e.id,
20
+ startedAt: e.at,
21
+ endedAt: t?.at,
22
+ events: n || t?.events,
23
+ url: e.url,
24
+ title: e.title,
25
+ width: e.width,
26
+ height: e.height,
27
+ device: e.device,
28
+ live: e.id === d,
29
+ local: n > 0,
30
+ truncated: t?.truncated
31
+ });
32
+ }
33
+ return a.sort((e, t) => t.startedAt - e.startedAt);
34
+ }
35
+ var h = /* @__PURE__ */ new Set(), g = !1, _ = !1;
36
+ async function v() {
37
+ if (g) {
38
+ _ = !0;
39
+ return;
40
+ }
41
+ g = !0;
42
+ try {
43
+ do
44
+ _ = !1, u = await m(), h.forEach((e) => e());
45
+ while (_);
46
+ } finally {
47
+ g = !1;
48
+ }
49
+ }
50
+ function y(e) {
51
+ h.add(e);
52
+ let t = [f.subscribe(() => void v()), p.subscribe(() => void v())];
53
+ return v(), () => {
54
+ h.delete(e), t.forEach((e) => e());
55
+ };
56
+ }
57
+ function b() {
58
+ return o(y, () => u, () => u);
59
+ }
60
+ function x() {
61
+ return d;
62
+ }
63
+ async function S(e) {
64
+ e === d && await f.flush();
65
+ let t = c(e);
66
+ return f.length(t) > 0 ? f.read(t) : p.readRemote(t);
67
+ }
68
+ async function C(e) {
69
+ e !== d && (f.remove(c(e)), await f.append(s, [{
70
+ t: "delete",
71
+ id: e,
72
+ at: Date.now()
73
+ }]));
74
+ }
75
+ async function w() {
76
+ for (let e of u) await C(e.id);
77
+ }
78
+ function T() {
79
+ return {
80
+ used: f.size(),
81
+ quota: l
82
+ };
83
+ }
84
+ function E() {
85
+ let { status: e, settings: t } = i(p);
86
+ return {
87
+ status: e,
88
+ settings: t,
89
+ configure: (e) => p.configure(e)
90
+ };
91
+ }
92
+ var D = class {
93
+ opts;
94
+ id = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`;
95
+ buffer = [];
96
+ events = 0;
97
+ started = !1;
98
+ last = Date.now();
99
+ info;
100
+ timer;
101
+ stopRecord;
102
+ dead = !1;
103
+ constructor(e, t) {
104
+ this.opts = e, this.info = {
105
+ t: "start",
106
+ id: this.id,
107
+ at: Date.now(),
108
+ url: location.href,
109
+ title: document.title,
110
+ width: innerWidth,
111
+ height: innerHeight,
112
+ device: t
113
+ };
114
+ }
115
+ start(e) {
116
+ this.stopRecord = e({
117
+ emit: (e) => this.push(e),
118
+ blockClass: this.opts.blockClass,
119
+ ignoreClass: this.opts.ignoreClass,
120
+ maskAllInputs: this.opts.maskAllInputs,
121
+ sampling: {
122
+ mousemove: 60,
123
+ scroll: 150,
124
+ input: "last"
125
+ },
126
+ slimDOMOptions: {
127
+ script: !0,
128
+ comment: !0,
129
+ headFavicon: !0,
130
+ headMetaSocial: !0,
131
+ headMetaRobots: !0,
132
+ headMetaHttpEquiv: !0,
133
+ headMetaVerification: !0
134
+ }
135
+ }), this.timer = setInterval(() => this.flush(), this.opts.flushMs), document.addEventListener("visibilitychange", this.onHide), addEventListener("pagehide", this.onLeave);
136
+ }
137
+ onHide = () => {
138
+ document.visibilityState === "hidden" && this.flush(!0);
139
+ };
140
+ onLeave = () => {
141
+ this.flush(!0);
142
+ };
143
+ push(e) {
144
+ if (!this.dead) {
145
+ if (e.type === 4 && !this.events) {
146
+ let t = e.data;
147
+ this.info = {
148
+ ...this.info,
149
+ at: e.timestamp,
150
+ url: t.href ?? this.info.url,
151
+ width: t.width ?? this.info.width,
152
+ height: t.height ?? this.info.height
153
+ };
154
+ }
155
+ this.buffer.push(e), this.events++, this.last = Math.max(this.last, e.timestamp), this.buffer.length >= 400 && this.flush();
156
+ }
157
+ }
158
+ flush(e = !1) {
159
+ if (!this.buffer.length || this.dead) return;
160
+ let t = this.buffer;
161
+ this.buffer = [];
162
+ let n = c(this.id), r = () => (this.started || (this.started = !0, d = this.id, f.appendSync(s, [this.info])), e ? Promise.resolve(f.appendSync(n, t)) : f.append(n, t));
163
+ try {
164
+ r().catch((e) => this.fail(e));
165
+ } catch (e) {
166
+ this.fail(e);
167
+ }
168
+ }
169
+ fail(e) {
170
+ if (!(e instanceof t)) throw e;
171
+ this.dead = !0, this.stopRecord?.(), clearInterval(this.timer);
172
+ try {
173
+ f.appendSync(s, [{
174
+ t: "end",
175
+ id: this.id,
176
+ at: this.last,
177
+ events: this.events,
178
+ truncated: !0
179
+ }]);
180
+ } catch {}
181
+ }
182
+ stop() {
183
+ if (!this.dead) {
184
+ if (this.stopRecord?.(), clearInterval(this.timer), document.removeEventListener("visibilitychange", this.onHide), removeEventListener("pagehide", this.onLeave), !this.started && this.events < 4) {
185
+ this.dead = !0;
186
+ return;
187
+ }
188
+ this.flush(!0), this.dead = !0;
189
+ try {
190
+ f.appendSync(s, [{
191
+ t: "end",
192
+ id: this.id,
193
+ at: this.last,
194
+ events: this.events
195
+ }]);
196
+ } catch {}
197
+ d === this.id && (d = null);
198
+ }
199
+ }
200
+ }, O = 0, k = null, A = null, j = {
201
+ blockClass: "rr-block",
202
+ ignoreClass: "rr-ignore",
203
+ maskAllInputs: !0,
204
+ maxSessions: 30,
205
+ flushMs: 1500
206
+ };
207
+ async function M(e) {
208
+ let { record: t } = await import("rrweb");
209
+ if (!(O === 0 || k)) {
210
+ await v();
211
+ for (let t of u.filter((e) => e.local).slice(Math.max(0, e.maxSessions - 1))) f.remove(c(t.id));
212
+ k = new D(e, r()), k.start(t);
213
+ }
214
+ }
215
+ async function N() {
216
+ if (await A, O > 0 || !k) return;
217
+ let e = k;
218
+ k = null, e.stop(), v();
219
+ }
220
+ function P(e = {}) {
221
+ O++;
222
+ let t = Object.fromEntries(Object.entries(e).filter(([, e]) => e !== void 0));
223
+ (O === 1 || !k) && (A = M({
224
+ ...j,
225
+ ...t
226
+ }));
227
+ let n = !1;
228
+ return () => {
229
+ n || (n = !0, --O === 0 && N());
230
+ };
231
+ }
232
+ function F({ enabled: e = !0, ...t } = {}) {
233
+ let { blockClass: n, ignoreClass: r, maskAllInputs: i, maxSessions: o, flushMs: s } = t;
234
+ a(() => {
235
+ if (!e) return;
236
+ p.start();
237
+ let t = P({
238
+ blockClass: n,
239
+ ignoreClass: r,
240
+ maskAllInputs: i,
241
+ maxSessions: o,
242
+ flushMs: s
243
+ });
244
+ return () => {
245
+ t();
246
+ };
247
+ }, [
248
+ e,
249
+ n,
250
+ r,
251
+ i,
252
+ o,
253
+ s
254
+ ]);
255
+ }
256
+ //#endregion
257
+ export { w as clearSessions, x as currentSessionId, C as deleteSession, S as readSession, p as sessionCloud, P as startSessionRecording, T as storageUsage, E as useSessionCloud, F as useSessionRecording, b as useSessions };
@@ -13,10 +13,18 @@ export interface SheetDragOptions {
13
13
  maxReveal: number;
14
14
  /** Extra resting heights between `peek` and `maxReveal` (px of body). */
15
15
  detents?: number[];
16
- /** Allow dragging below the resting height to fold into a FAB. */
16
+ /** Allow dragging below the resting height to fold into a FAB (or, with `fold: 'dismiss'`, to dismiss). */
17
17
  minimizable?: boolean;
18
18
  minimized?: boolean;
19
19
  onMinimizedChange?: (minimized: boolean) => void;
20
+ /**
21
+ * What folding means. `fab` (default) closes the peek on the way down, then the caller morphs the surface into
22
+ * a FAB. `dismiss` holds the body at `peek` and leaves the caller to slide the whole surface off its edge by
23
+ * `minimize` (0 at rest → 1 gone).
24
+ */
25
+ fold?: 'fab' | 'dismiss';
26
+ /** Downward travel below `peek` (px) that folds all the way (`minimize` = 1). Default `peek` + `SHEET_MINIMIZE_TRAVEL`. */
27
+ foldTravel?: number;
20
28
  /** Spring the body settles with (default `tray`). */
21
29
  spring?: SpringName;
22
30
  }
@@ -49,5 +57,5 @@ export interface SheetDragState {
49
57
  * velocity*, so a flick keeps its momentum. Grabbing mid-flight catches the body where it is. State changes
50
58
  * from outside (a tap, Escape, `peek` changing) spring too.
51
59
  */
52
- export declare function useSheetDrag({ open, onOpenChange, peek, maxReveal, detents, minimizable, minimized, onMinimizedChange, spring, }: SheetDragOptions): SheetDragState;
60
+ export declare function useSheetDrag({ open, onOpenChange, peek, maxReveal, detents, minimizable, minimized, onMinimizedChange, fold, foldTravel, spring, }: SheetDragOptions): SheetDragState;
53
61
  //# sourceMappingURL=sheet-drag.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sheet-drag.d.ts","sourceRoot":"","sources":["../../src/lib/sheet-drag.ts"],"names":[],"mappings":"AACA,OAAO,EAAgD,KAAK,YAAY,IAAI,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE7G,OAAO,EAAW,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAMxD,gEAAgE;AAChE,eAAO,MAAM,cAAc,IAAI,CAAC;AAChC,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAMxC,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,CAAC,IAAI,EA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aAAa,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;QAC/D,aAAa,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;QAC/D,WAAW,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;QAC7D,eAAe,EAAE,MAAM,IAAI,CAAC;QAC5B,oBAAoB,EAAE,MAAM,IAAI,CAAC;KAClC,CAAC;IACF,sEAAsE;IACtE,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAID;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,OAAY,EACZ,WAAmB,EACnB,SAAiB,EACjB,iBAAiB,EACjB,IAAY,EACZ,UAAU,EACV,MAAe,GAChB,EAAE,gBAAgB,GAAG,cAAc,CAwKnC"}
@@ -3,126 +3,129 @@ import { prefersReducedMotion as e, springs as t } from "./motion.js";
3
3
  import { animate as n } from "framer-motion";
4
4
  import { useEffect as r, useLayoutEffect as i, useRef as a, useState as o } from "react";
5
5
  //#region src/lib/sheet-drag.ts
6
- var s = typeof window > "u" ? r : i, c = 4, l = 96, u = 200, d = .4, f = (e) => Math.max(0, e) ** .72;
7
- function p({ open: i, onOpenChange: c, peek: l, maxReveal: p, detents: m = [], minimizable: h = !1, minimized: g = !1, onMinimizedChange: _, spring: v = "tray" }) {
8
- let [y, b] = o(null), x = y != null && y > l && y < p ? y : null, S = i ? p : x ?? l, C = +!!g, [w, T] = o(S), [E, D] = o(C), [O, k] = o(!1), [A, j] = o(!1), [M, N] = o(0), P = a({
9
- reveal: S,
10
- minimize: C
11
- }), F = a({}), I = a({
6
+ var s = typeof window > "u" ? r : i, c = 4, l = 96, u = {
7
+ fab: .5,
8
+ dismiss: .2
9
+ }, d = 200, f = .4, p = (e) => Math.max(0, e) ** .72;
10
+ function m({ open: i, onOpenChange: c, peek: l, maxReveal: m, detents: h = [], minimizable: g = !1, minimized: _ = !1, onMinimizedChange: v, fold: y = "fab", foldTravel: b, spring: x = "tray" }) {
11
+ let [S, C] = o(null), w = S != null && S > l && S < m ? S : null, T = i ? m : w ?? l, E = +!!_, [D, O] = o(T), [k, A] = o(E), [j, M] = o(!1), [N, P] = o(!1), [F, I] = o(0), L = a({
12
+ reveal: T,
13
+ minimize: E
14
+ }), R = a({}), z = a({
12
15
  reveal: 0,
13
16
  minimize: 0
14
- }), L = a({
17
+ }), B = a({
15
18
  active: !1,
16
19
  y: 0,
17
20
  from: 0,
18
21
  moved: !1,
19
22
  samples: []
20
- }), R = a(!1), z = l + 96, B = (e) => h && e < l ? Math.min(1, (l - e) / z) : 0, V = () => {
21
- F.current.r?.stop(), F.current.m?.stop(), F.current = {};
22
- }, H = (e, t) => {
23
- P.current = {
23
+ }), V = a(!1), H = Math.max(1, b ?? l + 96), U = (e) => g && e < l ? Math.min(1, (l - e) / H) : 0, W = () => {
24
+ R.current.r?.stop(), R.current.m?.stop(), R.current = {};
25
+ }, G = (e, t) => {
26
+ L.current = {
24
27
  reveal: e,
25
28
  minimize: t
26
- }, T(e), D(t);
29
+ }, O(e), A(t);
27
30
  };
28
31
  s(() => {
29
- if (L.current.active) return;
30
- let r = !R.current;
31
- R.current = !0;
32
- let i = P.current;
33
- if (r || e() || Math.abs(i.reveal - S) < .5 && Math.abs(i.minimize - C) < .005) {
34
- V(), H(S, C), j(!1);
32
+ if (B.current.active) return;
33
+ let r = !V.current;
34
+ V.current = !0;
35
+ let i = L.current;
36
+ if (r || e() || Math.abs(i.reveal - T) < .5 && Math.abs(i.minimize - E) < .005) {
37
+ W(), G(T, E), P(!1);
35
38
  return;
36
39
  }
37
- V(), j(!0);
40
+ W(), P(!0);
38
41
  let a = 2, o = () => {
39
- --a === 0 && j(!1);
40
- }, s = t[v];
41
- F.current.r = n(i.reveal, S, {
42
+ --a === 0 && P(!1);
43
+ }, s = t[x];
44
+ R.current.r = n(i.reveal, T, {
42
45
  ...s,
43
- velocity: I.current.reveal,
46
+ velocity: z.current.reveal,
44
47
  onUpdate: (e) => {
45
- let t = Math.max(0, Math.min(p, e));
46
- P.current.reveal = t, T(t);
48
+ let t = Math.max(0, Math.min(m, e));
49
+ L.current.reveal = t, O(t);
47
50
  },
48
51
  onComplete: o
49
- }), F.current.m = n(i.minimize, C, {
52
+ }), R.current.m = n(i.minimize, E, {
50
53
  ...s,
51
- velocity: I.current.minimize,
54
+ velocity: z.current.minimize,
52
55
  onUpdate: (e) => {
53
56
  let t = Math.max(0, Math.min(1, e));
54
- P.current.minimize = t, D(t);
57
+ L.current.minimize = t, A(t);
55
58
  },
56
59
  onComplete: o
57
- }), I.current = {
60
+ }), z.current = {
58
61
  reveal: 0,
59
62
  minimize: 0
60
63
  };
61
64
  }, [
62
- S,
63
- C,
64
- M
65
- ]), r(() => () => V(), []);
66
- let U = (e) => {
67
- V(), j(!1), L.current = {
65
+ T,
66
+ E,
67
+ F
68
+ ]), r(() => () => W(), []);
69
+ let K = (e) => {
70
+ W(), P(!1), B.current = {
68
71
  active: !0,
69
72
  y: e.clientY,
70
- from: P.current.reveal,
73
+ from: L.current.reveal,
71
74
  moved: !1,
72
75
  samples: [{
73
76
  t: e.timeStamp,
74
77
  y: e.clientY
75
78
  }]
76
79
  }, e.currentTarget.setPointerCapture(e.pointerId);
77
- }, W = (e) => {
78
- let t = L.current;
80
+ }, q = (e) => {
81
+ let t = B.current;
79
82
  if (!t.active) return;
80
83
  let n = t.y - e.clientY;
81
84
  if (!t.moved && Math.abs(n) < 4) return;
82
- t.moved || k(!0), t.moved = !0, t.samples.push({
85
+ t.moved || M(!0), t.moved = !0, t.samples.push({
83
86
  t: e.timeStamp,
84
87
  y: e.clientY
85
88
  }), t.samples.length > 6 && t.samples.shift();
86
- let r = t.from + n, i = h ? 0 : Math.min(l, p), a = r > p ? p + f(r - p) * .35 : r < i ? Math.max(0, i - f(i - r)) : r;
87
- H(Math.min(p + 24, a), B(r));
88
- }, G = (e, t) => {
89
- let n = L.current;
90
- if (n.active = !1, k(!1), !n.moved) return;
91
- let r = n.samples.filter((e) => t - e.t < 90)[0] ?? n.samples[0], a = Math.max(1, t - (r?.t ?? t)), o = r ? (r.y - e) / a : 0, s = n.from + (n.y - e), f = s + o * u, v = h && B(f) > .5 && B(s) > .08, y = [
89
+ let r = t.from + n, i = g && y === "fab" ? 0 : Math.min(l, m), a = y === "dismiss" && g ? i : Math.max(0, i - p(i - r)), o = r > m ? m + p(r - m) * .35 : r < i ? a : r;
90
+ G(Math.min(m + 24, o), U(r));
91
+ }, J = (e, t) => {
92
+ let n = B.current;
93
+ if (n.active = !1, M(!1), !n.moved) return;
94
+ let r = n.samples.filter((e) => t - e.t < 90)[0] ?? n.samples[0], a = Math.max(1, t - (r?.t ?? t)), o = r ? (r.y - e) / a : 0, s = n.from + (n.y - e), p = s + o * d, b = g && U(p) > u[y] && U(s) > .08, x = [
92
95
  l,
93
- ...m.filter((e) => e > l && e < p),
94
- p
95
- ], x = Math.max(0, Math.min(p, f)), S = Math.abs(o) > d ? y.filter((e) => o > 0 ? e > s + 1 : e < s - 1) : [], C = S.length ? o > 0 ? Math.min(...S) : Math.max(...S) : y.reduce((e, t) => Math.abs(t - x) < Math.abs(e - x) ? t : e, y[0]), w = !v && C === p && p > l, T = !v && C !== l && C !== p ? C : null;
96
- I.current = {
96
+ ...h.filter((e) => e > l && e < m),
97
+ m
98
+ ], S = Math.max(0, Math.min(m, p)), w = Math.abs(o) > f ? x.filter((e) => o > 0 ? e > s + 1 : e < s - 1) : [], T = w.length ? o > 0 ? Math.min(...w) : Math.max(...w) : x.reduce((e, t) => Math.abs(t - S) < Math.abs(e - S) ? t : e, x[0]), E = !b && T === m && m > l, D = !b && T !== l && T !== m ? T : null;
99
+ z.current = {
97
100
  reveal: o * 1e3,
98
- minimize: h && s < l ? -o * 1e3 / z : 0
99
- }, b(T), v !== g && _?.(v), w !== i && c(w), N((e) => e + 1);
100
- }, K = (e) => {
101
- L.current.active && (e.currentTarget.hasPointerCapture(e.pointerId) && e.currentTarget.releasePointerCapture(e.pointerId), G(e.clientY, e.timeStamp));
102
- }, q = () => {
103
- L.current.active && (L.current.active = !1, k(!1), N((e) => e + 1));
101
+ minimize: g && s < l ? -o * 1e3 / H : 0
102
+ }, C(D), b !== _ && v?.(b), E !== i && c(E), I((e) => e + 1);
103
+ }, Y = (e) => {
104
+ B.current.active && (e.currentTarget.hasPointerCapture(e.pointerId) && e.currentTarget.releasePointerCapture(e.pointerId), J(e.clientY, e.timeStamp));
105
+ }, X = () => {
106
+ B.current.active && (B.current.active = !1, M(!1), I((e) => e + 1));
104
107
  };
105
108
  return {
106
- reveal: w,
107
- minimize: E,
108
- dragging: O,
109
- settling: A,
110
- detent: x,
109
+ reveal: D,
110
+ minimize: k,
111
+ dragging: j,
112
+ settling: N,
113
+ detent: w,
111
114
  handlers: {
112
- onPointerDown: U,
113
- onPointerMove: W,
114
- onPointerUp: K,
115
- onPointerCancel: q,
116
- onLostPointerCapture: q
115
+ onPointerDown: K,
116
+ onPointerMove: q,
117
+ onPointerUp: Y,
118
+ onPointerCancel: X,
119
+ onLostPointerCapture: X
117
120
  },
118
121
  toggle: () => {
119
- if (L.current.moved) {
120
- L.current.moved = !1;
122
+ if (B.current.moved) {
123
+ B.current.moved = !1;
121
124
  return;
122
125
  }
123
- b(null), _?.(!1), c(!i);
126
+ C(null), v?.(!1), c(!i);
124
127
  }
125
128
  };
126
129
  }
127
130
  //#endregion
128
- export { l as SHEET_MINIMIZE_TRAVEL, c as SHEET_TAP_SLOP, p as useSheetDrag };
131
+ export { l as SHEET_MINIMIZE_TRAVEL, c as SHEET_TAP_SLOP, m as useSheetDrag };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brett_lamy/ui",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -41,6 +41,7 @@
41
41
  "perfect-freehand": "^1.2.2",
42
42
  "react-aria": "^3.51.0",
43
43
  "react-aria-components": "^1",
44
+ "rrweb": "2.0.0-alpha.20",
44
45
  "tailwind-merge": "^3"
45
46
  },
46
47
  "peerDependencies": {
@@ -1,13 +0,0 @@
1
- import * as React from 'react';
2
- export interface SnapSheetProps {
3
- open: boolean;
4
- onClose: () => void;
5
- snaps?: number[];
6
- children?: React.ReactNode;
7
- /** Classes for the sheet surface (the panel), merged last — e.g. `bg-background` for a surface other than `bg-card`. */
8
- className?: string;
9
- /** Styles for the sheet surface (the panel). */
10
- style?: React.CSSProperties;
11
- }
12
- export declare function SnapSheet({ open, onClose, snaps: snapsProp, children, className, style }: SnapSheetProps): import("react/jsx-runtime").JSX.Element | null;
13
- //# sourceMappingURL=snap-sheet.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snap-sheet.d.ts","sourceRoot":"","sources":["../../src/components/snap-sheet.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,wHAAwH;IACxH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AACD,wBAAgB,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,cAAc,kDA+GxG"}
@@ -1,100 +0,0 @@
1
- "use client";
2
- import { cn as e } from "../lib/utils.js";
3
- import { prefersReducedMotion as t, springs as n } from "../lib/motion.js";
4
- import { animate as r, motion as i, useMotionValue as a, useTransform as o } from "framer-motion";
5
- import * as s from "react";
6
- import { useEffect as c, useRef as l, useState as u } from "react";
7
- import { jsx as d, jsxs as f } from "react/jsx-runtime";
8
- //#region src/components/snap-sheet.tsx
9
- function p({ open: p, onClose: m, snaps: h, children: g, className: _, style: v }) {
10
- let y = h || [.55, .94], b = Math.max(...y), [x, S] = u(!1), C = l(null), w = a(1e4), T = l(null), E = l({
11
- drag: !1,
12
- y0: 0,
13
- ty0: 0,
14
- samples: []
15
- }), D = () => C.current ? C.current.offsetHeight : 700, O = (e) => D() * (b - y[e]), k = o(w, (e) => {
16
- let t = D();
17
- return Math.min(1, Math.max(0, (b - e / t) / b));
18
- }), A = (e, i = 0, a) => {
19
- if (T.current?.stop(), t()) {
20
- w.set(e), a?.();
21
- return;
22
- }
23
- T.current = r(w, e, {
24
- ...n.tray,
25
- velocity: i,
26
- onComplete: a
27
- });
28
- };
29
- if (c(() => {
30
- p ? S(!0) : x && A(D() * b, 0, () => S(!1));
31
- }, [p]), s.useLayoutEffect(() => {
32
- !x || !p || (w.set(D() * b), A(O(0)));
33
- }, [x]), c(() => () => T.current?.stop(), []), !p && !x) return null;
34
- let j = (e) => {
35
- T.current?.stop(), E.current = {
36
- drag: !0,
37
- y0: e.clientY,
38
- ty0: w.get(),
39
- samples: [{
40
- t: e.timeStamp,
41
- y: e.clientY
42
- }]
43
- }, e.currentTarget.setPointerCapture(e.pointerId);
44
- }, M = (e) => {
45
- let t = E.current;
46
- if (!t.drag) return;
47
- t.samples.push({
48
- t: e.timeStamp,
49
- y: e.clientY
50
- }), t.samples.length > 6 && t.samples.shift();
51
- let n = t.ty0 + (e.clientY - t.y0), r = O(y.indexOf(b));
52
- n < r && (n = r - (r - n) ** .72), w.set(Math.max(0, n));
53
- }, N = (e) => {
54
- let t = E.current;
55
- if (!t.drag) return;
56
- t.drag = !1;
57
- let n = t.samples.filter((t) => e.timeStamp - t.t < 90)[0] ?? t.samples[0], r = n ? (e.clientY - n.y) / Math.max(1, e.timeStamp - n.t) : 0, i = w.get() + r * 200, a = D(), o = -1, s = Infinity;
58
- if (y.forEach((e, t) => {
59
- let n = Math.abs(i - a * (b - e));
60
- n < s && (s = n, o = t);
61
- }), Math.abs(i - a * b) < s || i > a * (b - Math.min(...y)) + a * .12) {
62
- A(a * b, r * 1e3), m();
63
- return;
64
- }
65
- A(O(o), r * 1e3);
66
- };
67
- return /* @__PURE__ */ f("div", {
68
- ref: C,
69
- "data-slot": "snap-sheet",
70
- className: "absolute inset-0 z-70 overflow-hidden",
71
- children: [/* @__PURE__ */ d(i.div, {
72
- "data-slot": "snap-sheet-scrim",
73
- onClick: m,
74
- className: "absolute inset-0 bg-black/45",
75
- style: { opacity: k }
76
- }), /* @__PURE__ */ f(i.div, {
77
- "data-slot": "snap-sheet-panel",
78
- className: e("absolute right-0 bottom-0 left-0 flex h-(--sheet-h) touch-none flex-col rounded-t-2xl border-x border-t border-border bg-card shadow-[0_-12px_40px_black] shadow-black/8 dark:shadow-black/50", _),
79
- style: {
80
- ...v,
81
- y: w,
82
- "--sheet-h": b * 100 + "%"
83
- },
84
- children: [/* @__PURE__ */ d("div", {
85
- "data-slot": "snap-sheet-handle",
86
- onPointerDown: j,
87
- onPointerMove: M,
88
- onPointerUp: N,
89
- onPointerCancel: N,
90
- className: "shrink-0 cursor-grab touch-none pt-2 pb-1",
91
- children: /* @__PURE__ */ d("div", { className: "mx-auto h-[5px] w-[38px] rounded-[3px] bg-handle" })
92
- }), /* @__PURE__ */ d("div", {
93
- className: "flex min-h-0 flex-1 flex-col",
94
- children: g
95
- })]
96
- })]
97
- });
98
- }
99
- //#endregion
100
- export { p as SnapSheet };