react-devbelt 0.0.0-stage → 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 (55) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +16 -0
  3. package/README.md +292 -2
  4. package/dist/announce-6XECDMRI.js +12 -0
  5. package/dist/announce-6XECDMRI.js.map +1 -0
  6. package/dist/chunk-3SXZJ6OP.js +65 -0
  7. package/dist/chunk-3SXZJ6OP.js.map +1 -0
  8. package/dist/chunk-63DO3YVL.js +330 -0
  9. package/dist/chunk-63DO3YVL.js.map +1 -0
  10. package/dist/chunk-6PAFI4BJ.js +14615 -0
  11. package/dist/chunk-6PAFI4BJ.js.map +1 -0
  12. package/dist/chunk-7JLNVGRQ.js +164 -0
  13. package/dist/chunk-7JLNVGRQ.js.map +1 -0
  14. package/dist/chunk-C7RMX5PF.js +57 -0
  15. package/dist/chunk-C7RMX5PF.js.map +1 -0
  16. package/dist/chunk-GNJF3UHO.js +1030 -0
  17. package/dist/chunk-GNJF3UHO.js.map +1 -0
  18. package/dist/chunk-PRTINXUT.js +105 -0
  19. package/dist/chunk-PRTINXUT.js.map +1 -0
  20. package/dist/chunk-QRXHNBFY.js +22 -0
  21. package/dist/chunk-QRXHNBFY.js.map +1 -0
  22. package/dist/chunk-QT3YSHQA.js +18 -0
  23. package/dist/chunk-QT3YSHQA.js.map +1 -0
  24. package/dist/chunk-UBSHMGMV.js +8016 -0
  25. package/dist/chunk-UBSHMGMV.js.map +1 -0
  26. package/dist/context-D2euxPc4.d.ts +6 -0
  27. package/dist/core.d.ts +266 -0
  28. package/dist/core.js +1070 -0
  29. package/dist/core.js.map +1 -0
  30. package/dist/findable-rows-UQBKFZ45.js +356 -0
  31. package/dist/findable-rows-UQBKFZ45.js.map +1 -0
  32. package/dist/index.d.ts +57 -0
  33. package/dist/index.js +47 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/install.d.ts +2 -0
  36. package/dist/install.js +21 -0
  37. package/dist/install.js.map +1 -0
  38. package/dist/next.d.ts +18 -0
  39. package/dist/next.js +13 -0
  40. package/dist/next.js.map +1 -0
  41. package/dist/plugin-C8VytW9X.d.ts +162 -0
  42. package/dist/plugins.d.ts +118 -0
  43. package/dist/plugins.js +36 -0
  44. package/dist/plugins.js.map +1 -0
  45. package/dist/sheet-presentation-S6GGOKMB.js +2667 -0
  46. package/dist/sheet-presentation-S6GGOKMB.js.map +1 -0
  47. package/dist/styles.css +2 -0
  48. package/dist/toolbar-entry-XIOWCGBL.js +1685 -0
  49. package/dist/toolbar-entry-XIOWCGBL.js.map +1 -0
  50. package/dist/ui.d.ts +37 -0
  51. package/dist/ui.js +126 -0
  52. package/dist/ui.js.map +1 -0
  53. package/licenses/motion-MIT.txt +21 -0
  54. package/licenses/ui-sdk-APACHE-2.0.txt +202 -0
  55. package/package.json +115 -3
@@ -0,0 +1,2667 @@
1
+ "use client";
2
+ import {
3
+ trackKeyboard
4
+ } from "./chunk-PRTINXUT.js";
5
+ import {
6
+ isIOS,
7
+ isRTL,
8
+ physicalSide,
9
+ swallowNextClick
10
+ } from "./chunk-63DO3YVL.js";
11
+ import {
12
+ ahead,
13
+ on,
14
+ setStyle,
15
+ writeStyle
16
+ } from "./chunk-7JLNVGRQ.js";
17
+
18
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/motion/handoff.js
19
+ function handoff(input) {
20
+ if (!input.towardMore) {
21
+ return input.scrollAtStart ? "sheet" : "scroll";
22
+ }
23
+ return !input.atLargest && input.expandOnScroll ? "sheet" : "scroll";
24
+ }
25
+
26
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/motion/projection.js
27
+ function projectDistance(velocity, rate) {
28
+ return velocity * rate / (1 - rate);
29
+ }
30
+ function chooseSnapTarget(input) {
31
+ const { extent, velocity, candidates } = input;
32
+ if (Math.abs(velocity) < input.minFlingVelocity) {
33
+ return nearestIndex(candidates, extent);
34
+ }
35
+ const projected = extent + projectDistance(velocity, input.rate);
36
+ const nextInDirection = firstBeyond(candidates, extent, Math.sign(velocity));
37
+ let target = nearestIndex(candidates, projected);
38
+ const isBehind = velocity > 0 ? candidates[target] <= extent + 0.5 : candidates[target] >= extent - 0.5;
39
+ if (isBehind && nextInDirection !== -1) {
40
+ target = nextInDirection;
41
+ }
42
+ if (!input.skipSnapPoints && nextInDirection !== -1) {
43
+ target = velocity > 0 ? Math.min(target, nextInDirection) : Math.max(target, nextInDirection);
44
+ }
45
+ return target;
46
+ }
47
+ function nearestIndex(candidates, value) {
48
+ let best = 0;
49
+ for (let index = 1; index < candidates.length; index++) {
50
+ if (Math.abs(candidates[index] - value) < Math.abs(candidates[best] - value)) {
51
+ best = index;
52
+ }
53
+ }
54
+ return best;
55
+ }
56
+ function firstBeyond(candidates, extent, direction) {
57
+ if (direction > 0) {
58
+ return candidates.findIndex((candidate) => candidate > extent + 0.5);
59
+ }
60
+ for (let index = candidates.length - 1; index >= 0; index--) {
61
+ if (candidates[index] < extent - 0.5) {
62
+ return index;
63
+ }
64
+ }
65
+ return -1;
66
+ }
67
+
68
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/motion/rubber-band.js
69
+ var iosRubberBandCoefficient = 0.55;
70
+ function rubberBand(overshoot, dimension, coefficient = iosRubberBandCoefficient) {
71
+ if (overshoot <= 0) {
72
+ return 0;
73
+ }
74
+ return (1 - 1 / (overshoot * coefficient / dimension + 1)) * dimension;
75
+ }
76
+ function rubberBandInverse(shown, dimension, coefficient = iosRubberBandCoefficient) {
77
+ if (shown <= 0) {
78
+ return 0;
79
+ }
80
+ const ratio = Math.min(shown / dimension, 0.999999);
81
+ return (1 / (1 - ratio) - 1) * dimension / coefficient;
82
+ }
83
+ function rubberBandSlope(overshoot, dimension, coefficient = iosRubberBandCoefficient) {
84
+ if (overshoot <= 0) {
85
+ return 1;
86
+ }
87
+ const base = overshoot * coefficient / dimension + 1;
88
+ return coefficient / (base * base);
89
+ }
90
+
91
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/motion/spring.js
92
+ function solveSpring(response, dampingRatio, displacement, velocity) {
93
+ const omega = 2 * Math.PI / (response * 1e3);
94
+ const zeta = dampingRatio;
95
+ if (Math.abs(zeta - 1) < 1e-6) {
96
+ return criticallyDamped(omega, displacement, velocity);
97
+ }
98
+ if (zeta < 1) {
99
+ return underdamped(omega, zeta, displacement, velocity);
100
+ }
101
+ return overdamped(omega, zeta, displacement, velocity);
102
+ }
103
+ function underdamped(omega, zeta, x0, v0) {
104
+ const decay = zeta * omega;
105
+ const damped = omega * Math.sqrt(1 - zeta * zeta);
106
+ const b = (v0 + decay * x0) / damped;
107
+ return {
108
+ position: (t) => Math.exp(-decay * t) * (x0 * Math.cos(damped * t) + b * Math.sin(damped * t)),
109
+ velocity: (t) => {
110
+ const cos = Math.cos(damped * t);
111
+ const sin = Math.sin(damped * t);
112
+ return Math.exp(-decay * t) * ((b * damped - decay * x0) * cos - (x0 * damped + decay * b) * sin);
113
+ }
114
+ };
115
+ }
116
+ function criticallyDamped(omega, x0, v0) {
117
+ const b = v0 + omega * x0;
118
+ return {
119
+ position: (t) => Math.exp(-omega * t) * (x0 + b * t),
120
+ velocity: (t) => Math.exp(-omega * t) * (b - omega * (x0 + b * t))
121
+ };
122
+ }
123
+ function overdamped(omega, zeta, x0, v0) {
124
+ const root = Math.sqrt(zeta * zeta - 1);
125
+ const fast = -omega * (zeta + root);
126
+ const slow = -omega * (zeta - root);
127
+ const slowWeight = (v0 - fast * x0) / (slow - fast);
128
+ const fastWeight = x0 - slowWeight;
129
+ return {
130
+ position: (t) => slowWeight * Math.exp(slow * t) + fastWeight * Math.exp(fast * t),
131
+ velocity: (t) => slowWeight * slow * Math.exp(slow * t) + fastWeight * fast * Math.exp(fast * t)
132
+ };
133
+ }
134
+ function settleTime(solver, {
135
+ positionTolerance = 0.5,
136
+ velocityTolerance = 0.02,
137
+ step = 1,
138
+ limit = 1e4
139
+ } = {}) {
140
+ for (let t = 0; t <= limit; t += step) {
141
+ if (Math.abs(solver.position(t)) <= positionTolerance && Math.abs(solver.velocity(t)) <= velocityTolerance) {
142
+ return t;
143
+ }
144
+ }
145
+ return limit;
146
+ }
147
+ function springLinearEasing(solver, from, to, duration, step = 1e3 / 120) {
148
+ const distance = to - from;
149
+ if (Math.abs(distance) < 1e-6) {
150
+ return "linear";
151
+ }
152
+ const stops = [];
153
+ for (let t = 0; t < duration; t += step) {
154
+ stops.push(round(1 + solver.position(t) / distance));
155
+ }
156
+ stops.push("1");
157
+ return `linear(${stops.join(", ")})`;
158
+ }
159
+ function round(value) {
160
+ return String(Math.round(value * 1e4) / 1e4);
161
+ }
162
+
163
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/motion/machine.js
164
+ var none = [];
165
+ var nudgeVelocity = 1;
166
+ function initialState(extent, restingIndex) {
167
+ return { phase: "idle", extent, restingIndex };
168
+ }
169
+ function next(state, event, config) {
170
+ switch (event.type) {
171
+ case "down":
172
+ return onDown(state, event, config);
173
+ case "move":
174
+ return onMove(state, event, config);
175
+ case "up":
176
+ return onUp(state, event, config);
177
+ case "settled":
178
+ return onSettled(state);
179
+ case "rest":
180
+ return onRest(state, event, config);
181
+ case "snap-to":
182
+ return onSnapTo(state, event, config);
183
+ case "nudge":
184
+ return onNudge(state, event, config);
185
+ case "close":
186
+ return settleTo(state, config, {
187
+ targetIndex: -1,
188
+ motion: currentMotion(state, event.time),
189
+ time: event.time,
190
+ reason: "imperative",
191
+ outcome: { type: "dismiss", reason: "imperative" }
192
+ });
193
+ }
194
+ }
195
+ function currentMotion(state, time) {
196
+ if (state.phase !== "settling") {
197
+ return { extent: state.extent, velocity: 0 };
198
+ }
199
+ const solver = solveSpring(
200
+ state.response,
201
+ state.dampingRatio,
202
+ state.from - state.to,
203
+ state.velocity
204
+ );
205
+ const elapsed = Math.max(0, time - state.startTime);
206
+ return {
207
+ extent: state.to + solver.position(elapsed),
208
+ velocity: solver.velocity(elapsed)
209
+ };
210
+ }
211
+ function onDown(state, event, config) {
212
+ const slop = event.pointer === "mouse" ? config.physics.mouseSlop : config.physics.touchSlop;
213
+ if (state.phase === "idle" && state.restingIndex >= 0) {
214
+ return {
215
+ state: {
216
+ ...state,
217
+ phase: "pending",
218
+ originX: event.x,
219
+ originY: event.y,
220
+ slop
221
+ },
222
+ effects: none
223
+ };
224
+ }
225
+ if (state.phase !== "settling") {
226
+ return { state, effects: none };
227
+ }
228
+ const { extent } = currentMotion(state, event.time);
229
+ const dragging = {
230
+ phase: "dragging",
231
+ extent,
232
+ restingIndex: state.restingIndex,
233
+ anchorY: event.y,
234
+ anchorExtent: unconstrainExtent(extent, config),
235
+ lastY: event.y,
236
+ isScrollingContent: false
237
+ };
238
+ return {
239
+ state: dragging,
240
+ effects: [{ type: "move", extent }]
241
+ };
242
+ }
243
+ function onMove(state, event, config) {
244
+ if (state.phase === "pending") {
245
+ return leavePending(state, event, config);
246
+ }
247
+ if (state.phase === "scrolling" && config.contentScroll) {
248
+ return config.contentScroll.move(state, event);
249
+ }
250
+ if (state.phase === "dragging") {
251
+ return drag(state, event, config);
252
+ }
253
+ return { state, effects: none };
254
+ }
255
+ function leavePending(state, event, config) {
256
+ const dx = event.x - state.originX;
257
+ const dy = event.y - state.originY;
258
+ if (Math.max(Math.abs(dx), Math.abs(dy)) < state.slop) {
259
+ return { state, effects: none };
260
+ }
261
+ if (Math.abs(dx) > Math.abs(dy)) {
262
+ return {
263
+ state: initialState(state.extent, state.restingIndex),
264
+ effects: none
265
+ };
266
+ }
267
+ const scrolling = config.contentScroll?.claim(state, event, dy < 0, config);
268
+ if (scrolling) {
269
+ return { state: scrolling, effects: none };
270
+ }
271
+ const dragging = {
272
+ ...startDragging(state, state.originY + Math.sign(dy) * state.slop),
273
+ lastY: event.y
274
+ };
275
+ const extent = constrainExtent(
276
+ dragging.anchorExtent + (dragging.anchorY - event.y),
277
+ config
278
+ );
279
+ return {
280
+ state: { ...dragging, extent },
281
+ effects: [{ type: "move", extent }]
282
+ };
283
+ }
284
+ function startDragging(state, y) {
285
+ return {
286
+ phase: "dragging",
287
+ extent: state.extent,
288
+ restingIndex: state.restingIndex,
289
+ anchorY: y,
290
+ anchorExtent: state.extent,
291
+ lastY: y,
292
+ isScrollingContent: false
293
+ };
294
+ }
295
+ function drag(state, event, config) {
296
+ const delta = state.lastY - event.y;
297
+ const anchor = state.isScrollingContent ? { anchorY: state.lastY, anchorExtent: state.extent } : state;
298
+ const fingerExtent = anchor.anchorExtent + (anchor.anchorY - event.y);
299
+ const scrolled = config.contentScroll?.drag(
300
+ state,
301
+ event,
302
+ delta,
303
+ fingerExtent,
304
+ config
305
+ );
306
+ if (scrolled) {
307
+ return scrolled;
308
+ }
309
+ const extent = constrainExtent(fingerExtent, config);
310
+ const dragging = {
311
+ ...state,
312
+ anchorY: anchor.anchorY,
313
+ anchorExtent: anchor.anchorExtent,
314
+ extent,
315
+ lastY: event.y,
316
+ isScrollingContent: false
317
+ };
318
+ return {
319
+ state: dragging,
320
+ effects: [{ type: "move", extent }]
321
+ };
322
+ }
323
+ function onUp(state, event, config) {
324
+ if (state.phase === "pending" || state.phase === "scrolling") {
325
+ return {
326
+ state: initialState(state.extent, state.restingIndex),
327
+ effects: none
328
+ };
329
+ }
330
+ if (state.phase !== "dragging") {
331
+ return { state, effects: none };
332
+ }
333
+ const released = config.contentScroll?.release(state, event, config);
334
+ if (released) {
335
+ return released;
336
+ }
337
+ const velocity = -event.velocity * bandSlope(state.extent, config);
338
+ const candidates = [0, ...snapExtents(config)];
339
+ const physics = config.physics;
340
+ const target = {
341
+ candidates,
342
+ rate: physics.projectionRate,
343
+ minFlingVelocity: physics.minFlingVelocity,
344
+ skipSnapPoints: physics.skipSnapPoints
345
+ };
346
+ const candidate = chooseSnapTarget({
347
+ ...target,
348
+ extent: state.extent,
349
+ velocity
350
+ });
351
+ const release = {
352
+ motion: { extent: state.extent, velocity },
353
+ time: event.time,
354
+ reason: "swipe"
355
+ };
356
+ if (config.dismissible) {
357
+ if (candidate > 0) {
358
+ return settleTo(state, config, { ...release, targetIndex: candidate - 1 });
359
+ }
360
+ return settleTo(state, config, {
361
+ ...release,
362
+ targetIndex: -1,
363
+ outcome: { type: "dismiss", reason: "swipe" }
364
+ });
365
+ }
366
+ const fingerExtent = state.anchorExtent + (state.anchorY - state.lastY);
367
+ const wouldDismiss = chooseSnapTarget({
368
+ ...target,
369
+ extent: fingerExtent,
370
+ velocity: -event.velocity
371
+ }) === 0;
372
+ const index = Math.max(0, candidate - 1);
373
+ if (!wouldDismiss) {
374
+ return settleTo(state, config, { ...release, targetIndex: index });
375
+ }
376
+ return settleTo(state, config, {
377
+ ...release,
378
+ targetIndex: 0,
379
+ outcome: { type: "attempt-dismiss", reason: "swipe" }
380
+ });
381
+ }
382
+ function onSettled(state) {
383
+ if (state.phase !== "settling") {
384
+ return { state, effects: none };
385
+ }
386
+ return { state: initialState(state.to, state.targetIndex), effects: none };
387
+ }
388
+ function onRest(state, event, config) {
389
+ if (event.extent < 1 && config.dismissible) {
390
+ return {
391
+ state: initialState(0, -1),
392
+ effects: [{ type: "dismiss", reason: "swipe" }]
393
+ };
394
+ }
395
+ const index = nearestIndex(snapExtents(config), event.extent);
396
+ const effects = index === state.restingIndex ? [] : [{ type: "snap", id: config.snapPoints[index].id, reason: "swipe" }];
397
+ return { state: initialState(event.extent, index), effects };
398
+ }
399
+ function onSnapTo(state, event, config) {
400
+ const index = config.snapPoints.findIndex((point) => point.id === event.id);
401
+ if (index === -1 || state.phase === "dragging") {
402
+ return { state, effects: none };
403
+ }
404
+ return settleTo(state, config, {
405
+ targetIndex: index,
406
+ motion: currentMotion(state, event.time),
407
+ time: event.time,
408
+ reason: event.reason
409
+ });
410
+ }
411
+ function onNudge(state, event, config) {
412
+ if (state.phase !== "idle" || state.restingIndex < 0) {
413
+ return { state, effects: none };
414
+ }
415
+ return settleTo(state, config, {
416
+ targetIndex: state.restingIndex,
417
+ motion: { extent: state.extent, velocity: -nudgeVelocity },
418
+ time: event.time,
419
+ reason: "imperative"
420
+ });
421
+ }
422
+ function settleTo(state, config, options) {
423
+ const { targetIndex, motion, time, reason } = options;
424
+ const physics = config.physics;
425
+ const to = targetIndex < 0 ? 0 : config.snapPoints[targetIndex].extent;
426
+ const hasMomentum = Math.abs(motion.velocity) >= physics.minFlingVelocity;
427
+ const dampingRatio = hasMomentum ? physics.momentumDampingRatio : physics.dampingRatio;
428
+ const settling = {
429
+ phase: "settling",
430
+ extent: motion.extent,
431
+ restingIndex: state.restingIndex,
432
+ targetIndex,
433
+ from: motion.extent,
434
+ to,
435
+ velocity: motion.velocity,
436
+ response: physics.response,
437
+ dampingRatio,
438
+ startTime: time
439
+ };
440
+ const effects = [
441
+ {
442
+ type: "settle",
443
+ from: motion.extent,
444
+ to,
445
+ velocity: motion.velocity,
446
+ response: physics.response,
447
+ dampingRatio
448
+ }
449
+ ];
450
+ if (targetIndex >= 0 && targetIndex !== state.restingIndex) {
451
+ effects.push({
452
+ type: "snap",
453
+ id: config.snapPoints[targetIndex].id,
454
+ reason
455
+ });
456
+ }
457
+ if (options.outcome) {
458
+ effects.push(options.outcome);
459
+ }
460
+ return { state: settling, effects };
461
+ }
462
+ function constrainExtent(fingerExtent, config) {
463
+ const largest = largestExtent(config);
464
+ const { coefficient, dimension } = band(config);
465
+ if (fingerExtent > largest) {
466
+ return largest + rubberBand(fingerExtent - largest, dimension, coefficient);
467
+ }
468
+ if (config.dismissible) {
469
+ return Math.max(0, fingerExtent);
470
+ }
471
+ const smallest = config.snapPoints[0].extent;
472
+ if (fingerExtent < smallest) {
473
+ return smallest - rubberBand(smallest - fingerExtent, dimension, coefficient);
474
+ }
475
+ return fingerExtent;
476
+ }
477
+ function unconstrainExtent(extent, config) {
478
+ const largest = largestExtent(config);
479
+ const { coefficient, dimension } = band(config);
480
+ if (extent > largest) {
481
+ return largest + rubberBandInverse(extent - largest, dimension, coefficient);
482
+ }
483
+ const smallest = config.snapPoints[0].extent;
484
+ if (!config.dismissible && extent < smallest) {
485
+ return smallest - rubberBandInverse(smallest - extent, dimension, coefficient);
486
+ }
487
+ return extent;
488
+ }
489
+ function band(config) {
490
+ return {
491
+ coefficient: config.physics.rubberBand,
492
+ dimension: config.physics.rubberBandDimension ?? config.dimension
493
+ };
494
+ }
495
+ function bandSlope(extent, config) {
496
+ const { coefficient, dimension } = band(config);
497
+ const largest = largestExtent(config);
498
+ const smallest = config.snapPoints[0].extent;
499
+ const overshoot = extent > largest ? extent - largest : !config.dismissible && extent < smallest ? smallest - extent : 0;
500
+ if (overshoot <= 0) {
501
+ return 1;
502
+ }
503
+ return rubberBandSlope(
504
+ rubberBandInverse(overshoot, dimension, coefficient),
505
+ dimension,
506
+ coefficient
507
+ );
508
+ }
509
+ function largestExtent(config) {
510
+ return config.snapPoints[config.snapPoints.length - 1].extent;
511
+ }
512
+ function snapExtents(config) {
513
+ return config.snapPoints.map((point) => point.extent);
514
+ }
515
+
516
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/motion/content-scroll.js
517
+ var none2 = [];
518
+ var contentScroll = {
519
+ // Past the slop, whether the scroll area under the finger takes the gesture.
520
+ // Returns the scrolling state when it does.
521
+ claim(state, event, towardMore, config) {
522
+ if (!event.scroll) {
523
+ return;
524
+ }
525
+ const owner = handoff({
526
+ towardMore,
527
+ scrollAtStart: event.scroll.atStart,
528
+ atLargest: state.extent >= largestExtent(config) - 0.5,
529
+ expandOnScroll: config.expandOnScroll
530
+ });
531
+ if (owner !== "scroll") {
532
+ return;
533
+ }
534
+ return {
535
+ phase: "scrolling",
536
+ extent: state.extent,
537
+ restingIndex: state.restingIndex,
538
+ lastY: event.y
539
+ };
540
+ },
541
+ // A move while the content scrolls. The content reached its top while the
542
+ // finger keeps pulling down: the rest of the same gesture moves the sheet.
543
+ move(state, event) {
544
+ const isMovingDown = event.y > state.lastY;
545
+ if (isMovingDown && event.scroll?.atStart) {
546
+ return { state: startDragging(state, event.y), effects: none2 };
547
+ }
548
+ return { state: { ...state, lastY: event.y }, effects: none2 };
549
+ },
550
+ // A drag move the content takes, or undefined when the sheet moves.
551
+ // `delta` is positive when the finger moves up, and `fingerExtent` is where
552
+ // the finger would put the sheet.
553
+ drag(state, event, delta, fingerExtent, config) {
554
+ const scroll = event.scroll;
555
+ if (!scroll) {
556
+ return;
557
+ }
558
+ if (state.isScrollingContent && (delta > 0 ? !scroll.atEnd : !scroll.atStart)) {
559
+ const effects2 = [{ type: "scroll", delta }];
560
+ return { state: { ...state, lastY: event.y }, effects: effects2 };
561
+ }
562
+ const largest = largestExtent(config);
563
+ if (!(delta > 0 && fingerExtent > largest && state.extent <= largest && !scroll.atEnd)) {
564
+ return;
565
+ }
566
+ const effects = [
567
+ { type: "scroll", delta: fingerExtent - largest }
568
+ ];
569
+ if (state.extent !== largest) {
570
+ effects.unshift({ type: "move", extent: largest });
571
+ }
572
+ const scrolling = {
573
+ ...state,
574
+ extent: largest,
575
+ anchorY: event.y,
576
+ anchorExtent: largest,
577
+ lastY: event.y,
578
+ isScrollingContent: true
579
+ };
580
+ return { state: scrolling, effects };
581
+ },
582
+ // A release while the content scrolls: the sheet reached its largest snap
583
+ // point on the way, rests there, and the content coasts.
584
+ release(state, event, config) {
585
+ if (!state.isScrollingContent) {
586
+ return;
587
+ }
588
+ const largestIndex = config.snapPoints.length - 1;
589
+ const effects = [
590
+ { type: "fling-scroll", velocity: -event.velocity }
591
+ ];
592
+ if (state.restingIndex !== largestIndex) {
593
+ effects.push({
594
+ type: "snap",
595
+ id: config.snapPoints[largestIndex].id,
596
+ reason: "swipe"
597
+ });
598
+ }
599
+ return { state: initialState(state.extent, largestIndex), effects };
600
+ }
601
+ };
602
+
603
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/motion/physics.js
604
+ var sheetPhysics = {
605
+ ios: {
606
+ response: 0.34,
607
+ dampingRatio: 1,
608
+ momentumDampingRatio: 0.88,
609
+ projectionRate: 0.99,
610
+ minFlingVelocity: 0.5,
611
+ skipSnapPoints: true,
612
+ // UIKit's sheet band stops near 23pt: d 24, c 1.9 fit the recording.
613
+ rubberBand: 1.9,
614
+ rubberBandDimension: 24,
615
+ touchSlop: 8,
616
+ mouseSlop: 4,
617
+ dim: 0.2,
618
+ velocityHorizon: 70
619
+ }
620
+ };
621
+
622
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/motion/snap-points.js
623
+ function snapPointId(point) {
624
+ return String(point);
625
+ }
626
+ function snapPointExtent(point, context) {
627
+ if (typeof point === "number") {
628
+ return point <= 1 ? point * context.container : point;
629
+ }
630
+ if (point === "content") {
631
+ return context.content;
632
+ }
633
+ const amount = parseFloat(point);
634
+ if (point.endsWith("rem")) {
635
+ return amount * context.rootFontSize;
636
+ }
637
+ if (point.endsWith("%")) {
638
+ return amount / 100 * context.container;
639
+ }
640
+ if (point.endsWith("px")) {
641
+ return amount;
642
+ }
643
+ return NaN;
644
+ }
645
+ function resolveSnapPoints(points, context) {
646
+ const measured = points.map((value, index) => ({
647
+ value,
648
+ index,
649
+ extent: Math.min(snapPointExtent(value, context), context.content)
650
+ })).filter((point) => point.extent > 0).sort((a, b) => a.extent - b.extent || a.index - b.index);
651
+ const resolved = [];
652
+ for (const point of measured) {
653
+ const id = snapPointId(point.value);
654
+ const previous = resolved[resolved.length - 1];
655
+ if (previous && point.extent - previous.extent < 1) {
656
+ previous.ids.push(id);
657
+ if (point.index > previous.index) {
658
+ Object.assign(previous, { id, value: point.value, index: point.index });
659
+ }
660
+ previous.extent = Math.max(previous.extent, point.extent);
661
+ continue;
662
+ }
663
+ resolved.push({
664
+ id,
665
+ value: point.value,
666
+ extent: Math.round(point.extent * 100) / 100,
667
+ ids: [id],
668
+ index: point.index
669
+ });
670
+ }
671
+ return resolved.map(({ index, ...point }) => point);
672
+ }
673
+ function findSnapIndex(resolved, point) {
674
+ if (point === null || point === void 0) {
675
+ return -1;
676
+ }
677
+ const id = String(point);
678
+ return resolved.findIndex((entry) => entry.ids.includes(id));
679
+ }
680
+ function isAtOrBelow(resolved, point, limit) {
681
+ const below = findSnapIndex(resolved, limit);
682
+ const index = findSnapIndex(resolved, point);
683
+ return below >= 0 && index >= 0 && index <= below;
684
+ }
685
+
686
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/popups/sheet-axis.js
687
+ function resolveSide(side, el) {
688
+ return physicalSide(
689
+ side,
690
+ side === "start" || side === "end" ? isRTL(el) : false
691
+ );
692
+ }
693
+ var isVertical = (side) => side === "bottom" || side === "top";
694
+ var towardEdge = (side) => side === "bottom" || side === "right" ? 1 : -1;
695
+ function axisPoint(side, clientX, clientY, into) {
696
+ const vertical = isVertical(side);
697
+ into.y = (vertical ? clientY : clientX) * towardEdge(side);
698
+ into.x = vertical ? clientX : clientY;
699
+ return into;
700
+ }
701
+ function translateValue(side, offset) {
702
+ const value = `${Math.round(offset * towardEdge(side) * 100) / 100}px`;
703
+ return isVertical(side) ? `0 ${value}` : `${value} 0`;
704
+ }
705
+ function sizeAlong(el, side) {
706
+ return isVertical(side) ? el.offsetHeight : el.offsetWidth;
707
+ }
708
+ function scrollContext(target, sheet, side) {
709
+ const area = scrollAreaAt(target, sheet, side);
710
+ if (!area) {
711
+ return null;
712
+ }
713
+ const { start, end } = scrollEdges(area, side);
714
+ return { atStart: start, atEnd: end, area };
715
+ }
716
+ function scrollAreaAt(target, sheet, side) {
717
+ const view = sheet.ownerDocument.defaultView;
718
+ if (!view || !(target instanceof Element) || !sheet.contains(target)) {
719
+ return null;
720
+ }
721
+ const vertical = isVertical(side);
722
+ for (let node = target; node && node !== sheet.parentElement; node = node.parentElement) {
723
+ const scrollable = vertical ? node.scrollHeight > node.clientHeight + 1 : node.scrollWidth > node.clientWidth + 1;
724
+ if (!scrollable || !(node instanceof HTMLElement)) {
725
+ continue;
726
+ }
727
+ const overflow = vertical ? view.getComputedStyle(node).overflowY : view.getComputedStyle(node).overflowX;
728
+ if (/auto|scroll/.test(overflow)) {
729
+ return node;
730
+ }
731
+ }
732
+ return null;
733
+ }
734
+ function forwardScroll(area, side) {
735
+ if (isVertical(side)) {
736
+ const max2 = area.scrollHeight - area.clientHeight;
737
+ return {
738
+ position: side === "bottom" ? area.scrollTop : max2 - area.scrollTop,
739
+ max: max2
740
+ };
741
+ }
742
+ const max = area.scrollWidth - area.clientWidth;
743
+ const left = Math.abs(area.scrollLeft);
744
+ const fromLeft = isRTL(area) ? max - left : left;
745
+ return { position: side === "right" ? fromLeft : max - fromLeft, max };
746
+ }
747
+ function scrollEdges(area, side) {
748
+ const { position, max } = forwardScroll(area, side);
749
+ return { start: position <= 0.5, end: position >= max - 1 };
750
+ }
751
+ function scrollForward(area, side, delta) {
752
+ if (isVertical(side)) {
753
+ area.scrollTop += side === "bottom" ? delta : -delta;
754
+ } else {
755
+ const physical = side === "right" ? delta : -delta;
756
+ area.scrollLeft += isRTL(area) ? -physical : physical;
757
+ }
758
+ }
759
+
760
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/popups/sheet-driver.js
761
+ var openHold = 1e3;
762
+ function afterFirstFrame(view, start) {
763
+ view.requestAnimationFrame(() => view.requestAnimationFrame(start));
764
+ }
765
+ var toolbarBleed = 120;
766
+ function closedExtentFor(side) {
767
+ return side === "bottom" ? -toolbarBleed : -32;
768
+ }
769
+ var reducedSettle = 200;
770
+ var reducedFade = 150;
771
+ function setStyles(el, styles) {
772
+ const restores = Object.entries(styles).map(
773
+ ([name, value]) => setStyle(el, name, value)
774
+ );
775
+ return () => restores.forEach((restore) => restore());
776
+ }
777
+
778
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/motion/curves.js
779
+ var clamp01 = (value) => Math.max(0, Math.min(1, value));
780
+ function dimAmount(extent, snapExtents2, largestUndimmedIndex = -1) {
781
+ const lower = largestUndimmedIndex < 0 ? 0 : snapExtents2[largestUndimmedIndex];
782
+ const upper = largestUndimmedIndex < 0 ? snapExtents2[0] : snapExtents2[largestUndimmedIndex + 1];
783
+ if (upper === void 0 || upper <= lower) {
784
+ return extent > lower ? 1 : 0;
785
+ }
786
+ return clamp01((extent - lower) / (upper - lower));
787
+ }
788
+ function expandAmount(extent, snapExtents2) {
789
+ const largest = snapExtents2[snapExtents2.length - 1];
790
+ const lower = snapExtents2.length > 1 ? snapExtents2[snapExtents2.length - 2] : 0;
791
+ if (largest <= lower) {
792
+ return extent >= largest ? 1 : 0;
793
+ }
794
+ return clamp01((extent - lower) / (largest - lower));
795
+ }
796
+ function progressAmount(extent, snapExtents2) {
797
+ const largest = snapExtents2[snapExtents2.length - 1];
798
+ return largest > 0 ? clamp01(extent / largest) : 0;
799
+ }
800
+
801
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/popups/sheet-effects.js
802
+ var sampleStep = 1e3 / 60;
803
+ var variables = [
804
+ "--drawer-progress",
805
+ "--drawer-dim",
806
+ "--drawer-expand",
807
+ "--drawer-stack"
808
+ ];
809
+ var registered = /* @__PURE__ */ new WeakSet();
810
+ function registerVariables(doc) {
811
+ const css = doc.defaultView?.CSS;
812
+ if (registered.has(doc) || !css?.registerProperty) {
813
+ return;
814
+ }
815
+ registered.add(doc);
816
+ for (const name of variables) {
817
+ try {
818
+ css.registerProperty({
819
+ name,
820
+ syntax: "<number>",
821
+ inherits: false,
822
+ initialValue: "0"
823
+ });
824
+ } catch {
825
+ }
826
+ }
827
+ }
828
+ function prepareVariables() {
829
+ if (typeof document !== "undefined" && !registered.has(document)) {
830
+ ahead(() => registerVariables(document));
831
+ }
832
+ }
833
+ var supportsLinear = () => typeof CSS !== "undefined" && CSS.supports("animation-timing-function", "linear(0, 1)");
834
+ var round2 = (value) => Math.round(value * 1e4) / 1e4;
835
+ function createSheetEffects(targets) {
836
+ registerVariables(targets.sheet.ownerDocument);
837
+ let snapExtents2 = [1];
838
+ let undimmedIndex = -1;
839
+ let running = [];
840
+ const seeking = /* @__PURE__ */ new Map();
841
+ const values = { dim: 0, progress: 0, expand: 0 };
842
+ let dimHold;
843
+ function configure(next2) {
844
+ snapExtents2 = next2.snapExtents.length ? next2.snapExtents : [1];
845
+ undimmedIndex = next2.undimmedIndex;
846
+ }
847
+ function compute(extent, into = values) {
848
+ into.dim = round2(dimAmount(extent, snapExtents2, undimmedIndex));
849
+ into.progress = round2(progressAmount(extent, snapExtents2));
850
+ into.expand = round2(expandAmount(extent, snapExtents2));
851
+ return into;
852
+ }
853
+ let destroyed = false;
854
+ function apply(extent, { rest = false } = {}) {
855
+ if (destroyed) {
856
+ return;
857
+ }
858
+ stopRunning();
859
+ compute(extent);
860
+ writeDim(values.dim);
861
+ writeVariables(targets.sheet, values);
862
+ writeStack(values.progress);
863
+ for (const outlet of targets.outlets()) {
864
+ writeVariables(outlet.el, values);
865
+ if (outlet.keyframes) {
866
+ seekOutlet(outlet, values.expand, rest);
867
+ }
868
+ }
869
+ if (rest) {
870
+ targets.themeColor?.(values.dim);
871
+ }
872
+ }
873
+ function writeDim(dim) {
874
+ const backdrop = targets.backdrop();
875
+ if (backdrop) {
876
+ backdrop.style.opacity = String(dim);
877
+ }
878
+ const hold = holdDim();
879
+ if (hold) {
880
+ hold.currentTime = dim * 1e3;
881
+ }
882
+ }
883
+ function holdDim() {
884
+ if (!targets.dimmed || dimHold) {
885
+ return dimHold;
886
+ }
887
+ dimHold = targets.dimmed.animate(
888
+ { opacity: [0, 1] },
889
+ { ...backdropDim, duration: 1e3, fill: "both" }
890
+ );
891
+ dimHold.pause();
892
+ dimHold.currentTime = 0;
893
+ return dimHold;
894
+ }
895
+ function writeStack(progress) {
896
+ const ancestors = targets.ancestors();
897
+ for (let depth = 0; depth < ancestors.length; depth++) {
898
+ ancestors[depth].style.setProperty(
899
+ "--drawer-stack",
900
+ String(depth + progress)
901
+ );
902
+ }
903
+ }
904
+ function writeVariables(el, { dim, progress, expand }) {
905
+ el.style.setProperty("--drawer-progress", String(progress));
906
+ el.style.setProperty("--drawer-dim", String(dim));
907
+ el.style.setProperty("--drawer-expand", String(expand));
908
+ }
909
+ function seekOutlet(outlet, amount, rest) {
910
+ let animation = seeking.get(outlet.el);
911
+ if (!animation) {
912
+ animation = outlet.el.animate(asKeyframes(outlet.keyframes), {
913
+ duration: 1e3,
914
+ fill: "both"
915
+ });
916
+ animation.pause();
917
+ seeking.set(outlet.el, animation);
918
+ }
919
+ animation.currentTime = amount * 1e3;
920
+ if (!rest) {
921
+ return;
922
+ }
923
+ animation.commitStyles?.();
924
+ animation.cancel();
925
+ seeking.delete(outlet.el);
926
+ }
927
+ function play(motion) {
928
+ if (destroyed) {
929
+ return;
930
+ }
931
+ stopRunning();
932
+ stopSeeking();
933
+ if (!supportsLinear()) {
934
+ return apply(
935
+ motion.type === "settle" ? motion.extentAt(motion.duration) : 0,
936
+ { rest: true }
937
+ );
938
+ }
939
+ const samples = sampleCurves(motion);
940
+ holdDim();
941
+ const timing = motion.type === "settle" ? { duration: Math.max(1, motion.duration), fill: "both" } : { timeline: motion.timeline, fill: "both" };
942
+ const animate = (el, keyframes, curve, pseudo) => {
943
+ const animation = el.animate(keyframes, {
944
+ ...timing,
945
+ ...pseudo,
946
+ easing: easing(curve)
947
+ });
948
+ if (motion.type === "settle") {
949
+ animation.startTime = motion.startTime;
950
+ }
951
+ running.push(animation);
952
+ };
953
+ const backdrop = targets.backdrop();
954
+ if (backdrop) {
955
+ animate(backdrop, { opacity: [0, 1] }, samples.dim);
956
+ }
957
+ if (targets.dimmed) {
958
+ animate(targets.dimmed, { opacity: [0, 1] }, samples.dim, backdropDim);
959
+ }
960
+ animateVariables(targets.sheet, samples, animate);
961
+ targets.ancestors().forEach(
962
+ (el, depth) => animate(el, { "--drawer-stack": [depth, depth + 1] }, samples.progress)
963
+ );
964
+ for (const outlet of targets.outlets()) {
965
+ animateVariables(outlet.el, samples, animate);
966
+ if (outlet.keyframes) {
967
+ animate(outlet.el, asKeyframes(outlet.keyframes), samples.expand);
968
+ }
969
+ }
970
+ if (motion.type !== "settle") {
971
+ return;
972
+ }
973
+ const end = motion.extentAt(motion.duration);
974
+ writeRest(end);
975
+ const batch = running;
976
+ if (batch[0]) {
977
+ batch[0].onfinish = () => running === batch && stopRunning();
978
+ }
979
+ }
980
+ function animateVariables(el, samples, animate) {
981
+ animate(el, { "--drawer-progress": [0, 1] }, samples.progress);
982
+ animate(el, { "--drawer-dim": [0, 1] }, samples.dim);
983
+ animate(el, { "--drawer-expand": [0, 1] }, samples.expand);
984
+ }
985
+ function writeRest(extent) {
986
+ const end = compute(extent, { dim: 0, progress: 0, expand: 0 });
987
+ writeDim(end.dim);
988
+ writeVariables(targets.sheet, end);
989
+ writeStack(end.progress);
990
+ for (const outlet of targets.outlets()) {
991
+ writeVariables(outlet.el, end);
992
+ if (!outlet.keyframes) {
993
+ continue;
994
+ }
995
+ for (const [property, frames] of Object.entries(outlet.keyframes)) {
996
+ const value = frames[end.expand >= 0.5 ? frames.length - 1 : 0];
997
+ outlet.el.style.setProperty(cssName(property), String(value));
998
+ }
999
+ }
1000
+ targets.themeColor?.(end.dim);
1001
+ }
1002
+ function sampleCurves(motion) {
1003
+ const curves = {
1004
+ dim: [],
1005
+ progress: [],
1006
+ expand: []
1007
+ };
1008
+ const point = { dim: 0, progress: 0, expand: 0 };
1009
+ const count = motion.type === "settle" ? Math.max(2, Math.ceil(motion.duration / sampleStep) + 1) : 61;
1010
+ for (let index = 0; index < count; index++) {
1011
+ const at = index / (count - 1);
1012
+ const extent = motion.type === "settle" ? motion.extentAt(Math.min(motion.duration, index * sampleStep)) : motion.extentAt(at);
1013
+ compute(extent, point);
1014
+ curves.dim.push(point.dim);
1015
+ curves.progress.push(point.progress);
1016
+ curves.expand.push(point.expand);
1017
+ }
1018
+ return curves;
1019
+ }
1020
+ function sync(startTime) {
1021
+ for (const animation of running) {
1022
+ animation.startTime = startTime;
1023
+ }
1024
+ }
1025
+ function stopRunning() {
1026
+ if (!running.length) {
1027
+ return;
1028
+ }
1029
+ for (const animation of running) {
1030
+ animation.cancel();
1031
+ }
1032
+ running = [];
1033
+ }
1034
+ function stopSeeking() {
1035
+ for (const animation of seeking.values()) {
1036
+ animation.cancel();
1037
+ }
1038
+ seeking.clear();
1039
+ }
1040
+ function destroy() {
1041
+ destroyed = true;
1042
+ stopRunning();
1043
+ stopSeeking();
1044
+ targets.backdrop()?.style.removeProperty("opacity");
1045
+ dimHold?.cancel();
1046
+ for (const name of variables.slice(0, 3)) {
1047
+ targets.sheet.style.removeProperty(name);
1048
+ }
1049
+ for (const outlet of targets.outlets()) {
1050
+ for (const name of variables.slice(0, 3)) {
1051
+ outlet.el.style.removeProperty(name);
1052
+ }
1053
+ for (const property of Object.keys(outlet.keyframes ?? {})) {
1054
+ outlet.el.style.removeProperty(cssName(property));
1055
+ }
1056
+ }
1057
+ }
1058
+ return {
1059
+ configure,
1060
+ compute,
1061
+ apply,
1062
+ play,
1063
+ sync,
1064
+ follow: play,
1065
+ stop: stopRunning,
1066
+ destroy
1067
+ };
1068
+ }
1069
+ var backdropDim = { pseudoElement: "::backdrop" };
1070
+ function easing(curve) {
1071
+ return `linear(${curve.map(round2).join(", ")})`;
1072
+ }
1073
+ var asKeyframes = (keyframes) => keyframes;
1074
+ function cssName(property) {
1075
+ return property.startsWith("--") ? property : property.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
1076
+ }
1077
+
1078
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/motion/velocity.js
1079
+ var defaults = {
1080
+ /** How far back samples count, in ms before the newest. Defaults to 70. */
1081
+ horizon: 70,
1082
+ /** How old the newest sample can be, in ms, before the pointer counts as stopped and reads 0. Defaults to 40. */
1083
+ staleAfter: 40,
1084
+ /** The fastest the tracker reads, in px/ms either way. Defaults to 8. */
1085
+ maxSpeed: 8,
1086
+ /** How many samples it keeps. Defaults to 20, enough for the horizon at 240 Hz. */
1087
+ capacity: 20
1088
+ };
1089
+ function leastSquaresVelocity(times, positions, start = 0, end = times.length) {
1090
+ const count = end - start;
1091
+ if (count < 2) {
1092
+ return 0;
1093
+ }
1094
+ const newest = times[end - 1];
1095
+ if (count < 4) {
1096
+ return linearSlope(times, positions, start, end);
1097
+ }
1098
+ let s0 = 0, s1 = 0, s2 = 0, s3 = 0, s4 = 0;
1099
+ let x0 = 0, x1 = 0, x2 = 0;
1100
+ for (let index = start; index < end; index++) {
1101
+ const t = times[index] - newest;
1102
+ const x = positions[index];
1103
+ const t2 = t * t;
1104
+ s0 += 1;
1105
+ s1 += t;
1106
+ s2 += t2;
1107
+ s3 += t2 * t;
1108
+ s4 += t2 * t2;
1109
+ x0 += x;
1110
+ x1 += x * t;
1111
+ x2 += x * t2;
1112
+ }
1113
+ const determinant = s0 * (s2 * s4 - s3 * s3) - s1 * (s1 * s4 - s3 * s2) + s2 * (s1 * s3 - s2 * s2);
1114
+ if (Math.abs(determinant) < 1e-9) {
1115
+ return linearSlope(times, positions, start, end);
1116
+ }
1117
+ const numerator = s0 * (x1 * s4 - s3 * x2) - x0 * (s1 * s4 - s3 * s2) + s2 * (s1 * x2 - x1 * s2);
1118
+ return numerator / determinant;
1119
+ }
1120
+ function linearSlope(times, positions, start, end) {
1121
+ let meanTime = 0, meanPosition = 0;
1122
+ const count = end - start;
1123
+ for (let index = start; index < end; index++) {
1124
+ meanTime += times[index] / count;
1125
+ meanPosition += positions[index] / count;
1126
+ }
1127
+ let covariance = 0, variance = 0;
1128
+ for (let index = start; index < end; index++) {
1129
+ const dt = times[index] - meanTime;
1130
+ covariance += dt * (positions[index] - meanPosition);
1131
+ variance += dt * dt;
1132
+ }
1133
+ return variance > 0 ? covariance / variance : 0;
1134
+ }
1135
+ function createVelocityTracker(options = {}) {
1136
+ const { horizon, staleAfter, maxSpeed, capacity } = {
1137
+ ...defaults,
1138
+ ...options
1139
+ };
1140
+ const times = new Float64Array(capacity);
1141
+ const positions = new Float64Array(capacity);
1142
+ const windowTimes = new Float64Array(capacity);
1143
+ const windowPositions = new Float64Array(capacity);
1144
+ let count = 0;
1145
+ let newestIndex = -1;
1146
+ function add(time, position) {
1147
+ if (count > 0 && time <= times[newestIndex]) {
1148
+ return;
1149
+ }
1150
+ newestIndex = (newestIndex + 1) % capacity;
1151
+ times[newestIndex] = time;
1152
+ positions[newestIndex] = position;
1153
+ count = Math.min(count + 1, capacity);
1154
+ }
1155
+ function velocity(now) {
1156
+ if (count < 2) {
1157
+ return 0;
1158
+ }
1159
+ const newest = times[newestIndex];
1160
+ if (now - newest > staleAfter) {
1161
+ return 0;
1162
+ }
1163
+ let windowCount = 0;
1164
+ for (let age = count - 1; age >= 0; age--) {
1165
+ const index = (newestIndex - age + capacity) % capacity;
1166
+ if (newest - times[index] > horizon) {
1167
+ continue;
1168
+ }
1169
+ windowTimes[windowCount] = times[index];
1170
+ windowPositions[windowCount] = positions[index];
1171
+ windowCount++;
1172
+ }
1173
+ const fitted = leastSquaresVelocity(
1174
+ windowTimes,
1175
+ windowPositions,
1176
+ 0,
1177
+ windowCount
1178
+ );
1179
+ return Math.max(-maxSpeed, Math.min(maxSpeed, fitted));
1180
+ }
1181
+ function reset() {
1182
+ count = 0;
1183
+ newestIndex = -1;
1184
+ }
1185
+ return { add, velocity, reset };
1186
+ }
1187
+
1188
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/popups/sheet-pointer.js
1189
+ var contentDecelerationRate = 0.998;
1190
+ var ignoredTargets = 'input, textarea, select, [contenteditable]:not([contenteditable="false"]), [data-drawer-no-drag]';
1191
+ function sampleTranslate(motion, translate) {
1192
+ const frames = [];
1193
+ for (let elapsed = 0; elapsed < motion.duration; elapsed += 1e3 / 60) {
1194
+ frames.push(translate(motion.extentAt(elapsed)));
1195
+ }
1196
+ frames.push(translate(motion.extentAt(motion.duration)));
1197
+ return frames;
1198
+ }
1199
+ function createPointerDriver(options) {
1200
+ const { sheet } = options;
1201
+ const doc = sheet.ownerDocument;
1202
+ const view = doc.defaultView ?? window;
1203
+ let state = initialState(0, -1);
1204
+ let shown = 0;
1205
+ let pendingExtent = null;
1206
+ let pendingScroll = 0;
1207
+ let frame = 0;
1208
+ let animation = null;
1209
+ let fade = null;
1210
+ let closing = null;
1211
+ let coast = null;
1212
+ let area = null;
1213
+ let touch = null;
1214
+ let pointerId = null;
1215
+ let dragging = false;
1216
+ let mouseDragged = false;
1217
+ let targetId = null;
1218
+ const point = { x: 0, y: 0 };
1219
+ const tracker = createVelocityTracker({
1220
+ horizon: options.config().physics.velocityHorizon
1221
+ });
1222
+ const offs = [
1223
+ on(doc, "touchstart", onTouchStart, { capture: true, passive: true }),
1224
+ on(doc, "touchmove", onTouchMove, { capture: true, passive: false }),
1225
+ on(doc, "touchend", onTouchEnd, { capture: true, passive: true }),
1226
+ on(doc, "touchcancel", onTouchEnd, { capture: true, passive: true }),
1227
+ on(sheet, "pointerdown", onPointerDown)
1228
+ ];
1229
+ let destroyed = false;
1230
+ function writeTranslate(extent) {
1231
+ if (destroyed) {
1232
+ return;
1233
+ }
1234
+ sheet.style.translate = translateValue(
1235
+ options.side(),
1236
+ options.size() - extent
1237
+ );
1238
+ shown = extent;
1239
+ }
1240
+ function dispatch(event, source) {
1241
+ if (destroyed) {
1242
+ return;
1243
+ }
1244
+ const result = next(state, event, options.config());
1245
+ state = result.state;
1246
+ const time = "time" in event ? event.time : performance.now();
1247
+ for (const effect of result.effects) {
1248
+ run(effect, time, source);
1249
+ }
1250
+ const isDragging = state.phase === "dragging";
1251
+ if (isDragging === dragging) {
1252
+ return;
1253
+ }
1254
+ dragging = isDragging;
1255
+ options.onDragChange(dragging);
1256
+ }
1257
+ function run(effect, time, source) {
1258
+ switch (effect.type) {
1259
+ case "move":
1260
+ if (animation) {
1261
+ stopAnimation();
1262
+ writeTranslate(effect.extent);
1263
+ options.onFrame(effect.extent);
1264
+ } else {
1265
+ pendingExtent = effect.extent;
1266
+ schedule();
1267
+ }
1268
+ return;
1269
+ case "settle":
1270
+ return startSettle(effect, time);
1271
+ case "scroll":
1272
+ pendingScroll += effect.delta;
1273
+ return schedule();
1274
+ case "fling-scroll":
1275
+ if (area) {
1276
+ coast = {
1277
+ velocity: effect.velocity,
1278
+ startTime: time,
1279
+ startScroll: 0,
1280
+ area
1281
+ };
1282
+ }
1283
+ return schedule();
1284
+ case "snap":
1285
+ targetId = effect.id;
1286
+ return options.onSnap(effect.id, effect.reason, source);
1287
+ case "dismiss":
1288
+ if (effect.reason !== "swipe") {
1289
+ return;
1290
+ }
1291
+ closing = "swipe";
1292
+ return options.onDismiss(source);
1293
+ case "attempt-dismiss":
1294
+ return options.onDismissAttempt(source);
1295
+ }
1296
+ }
1297
+ function startSettle(effect, startTime) {
1298
+ stopAnimation();
1299
+ pendingExtent = null;
1300
+ const closed = options.closedExtent();
1301
+ const from = effect.from <= 0 ? closed : effect.from;
1302
+ const to = effect.to <= 0 ? closed : effect.to;
1303
+ const isFade = options.reducedMotion() && (from === closed || to === closed);
1304
+ const motion = options.reducedMotion() ? reducedMotion(from, to, isFade) : springMotion(from, to, effect);
1305
+ writeTranslate(isFade ? Math.max(to, 0) : to);
1306
+ if (Math.abs(to - from) < 0.5 && effect.velocity === 0 || motion.duration === 0) {
1307
+ return finishSettle();
1308
+ }
1309
+ const size = options.size();
1310
+ const side = options.side();
1311
+ animation = isFade ? sheet.animate(
1312
+ { opacity: from === closed ? [0, 1] : [1, 0] },
1313
+ { duration: motion.duration, fill: "both" }
1314
+ ) : Math.abs(to - from) < 1 ? sheet.animate(
1315
+ {
1316
+ translate: sampleTranslate(
1317
+ motion,
1318
+ (extent) => translateValue(side, size - extent)
1319
+ )
1320
+ },
1321
+ { duration: motion.duration, fill: "backwards" }
1322
+ ) : sheet.animate(
1323
+ {
1324
+ translate: [
1325
+ translateValue(side, size - from),
1326
+ translateValue(side, size - to)
1327
+ ]
1328
+ },
1329
+ {
1330
+ duration: motion.duration,
1331
+ easing: motion.easing,
1332
+ fill: "backwards"
1333
+ }
1334
+ );
1335
+ if (isFade) {
1336
+ fade = animation;
1337
+ }
1338
+ const running = animation;
1339
+ animation.onfinish = () => {
1340
+ if (animation === running) {
1341
+ finishSettle();
1342
+ }
1343
+ };
1344
+ animation.startTime = startTime;
1345
+ options.onMotion({
1346
+ type: "settle",
1347
+ extentAt: motion.extentAt,
1348
+ startTime,
1349
+ duration: motion.duration
1350
+ });
1351
+ }
1352
+ function springMotion(from, to, effect) {
1353
+ const solver = solveSpring(
1354
+ effect.response,
1355
+ effect.dampingRatio,
1356
+ from - to,
1357
+ effect.velocity
1358
+ );
1359
+ const duration = settleTime(solver);
1360
+ return {
1361
+ duration,
1362
+ easing: springLinearEasing(solver, from, to, duration),
1363
+ extentAt: (elapsed) => to + solver.position(elapsed)
1364
+ };
1365
+ }
1366
+ function reducedMotion(from, to, isFade) {
1367
+ const duration = isFade ? reducedFade : reducedSettle;
1368
+ const ease = (t) => 1 - (1 - t) ** 3;
1369
+ return {
1370
+ duration,
1371
+ easing: "cubic-bezier(0.33, 1, 0.68, 1)",
1372
+ extentAt: (elapsed) => from + (to - from) * ease(Math.min(1, elapsed / duration))
1373
+ };
1374
+ }
1375
+ function stopAnimation() {
1376
+ animation?.cancel();
1377
+ animation = null;
1378
+ if (fade) {
1379
+ fade.cancel();
1380
+ fade = null;
1381
+ }
1382
+ }
1383
+ function finishSettle() {
1384
+ stopAnimation();
1385
+ dispatch({ type: "settled" });
1386
+ if (state.phase !== "idle") {
1387
+ return;
1388
+ }
1389
+ if (state.restingIndex < 0) {
1390
+ closing = null;
1391
+ targetId = null;
1392
+ return options.onRest(null);
1393
+ }
1394
+ targetId = options.config().snapPoints[state.restingIndex].id;
1395
+ options.onRest(targetId);
1396
+ }
1397
+ function schedule() {
1398
+ frame ||= view.requestAnimationFrame(flush);
1399
+ }
1400
+ function flush(now) {
1401
+ frame = 0;
1402
+ if (pendingScroll && area) {
1403
+ scrollForward(area, options.side(), pendingScroll);
1404
+ pendingScroll = 0;
1405
+ }
1406
+ if (coast) {
1407
+ stepCoast(now);
1408
+ }
1409
+ if (pendingExtent === null) {
1410
+ return;
1411
+ }
1412
+ writeTranslate(pendingExtent);
1413
+ pendingExtent = null;
1414
+ options.onFrame(shown);
1415
+ }
1416
+ function stepCoast(now) {
1417
+ if (!coast) {
1418
+ return;
1419
+ }
1420
+ const elapsed = Math.max(0, now - coast.startTime);
1421
+ const travelled = coast.velocity * (contentDecelerationRate ** elapsed - 1) / Math.log(contentDecelerationRate);
1422
+ scrollForward(coast.area, options.side(), travelled - coast.startScroll);
1423
+ coast.startScroll = travelled;
1424
+ if (Math.abs(coast.velocity * contentDecelerationRate ** elapsed) < 0.01) {
1425
+ coast = null;
1426
+ } else {
1427
+ schedule();
1428
+ }
1429
+ }
1430
+ function isIgnored(target) {
1431
+ return target instanceof Element && target.closest(ignoredTargets) !== null;
1432
+ }
1433
+ function scroll(target) {
1434
+ const context = scrollContext(target, sheet, options.side());
1435
+ area = context?.area ?? null;
1436
+ return context && { atStart: context.atStart, atEnd: context.atEnd };
1437
+ }
1438
+ function onTouchStart(event) {
1439
+ if (touch || event.touches.length > 1 || closing) {
1440
+ return;
1441
+ }
1442
+ if (!options.owns(event.target) || isIgnored(event.target)) {
1443
+ return;
1444
+ }
1445
+ const first = event.changedTouches[0];
1446
+ touch = {
1447
+ id: first.identifier,
1448
+ originX: first.clientX,
1449
+ originY: first.clientY
1450
+ };
1451
+ coast = null;
1452
+ tracker.reset();
1453
+ axisPoint(options.side(), first.clientX, first.clientY, point);
1454
+ tracker.add(event.timeStamp, point.y);
1455
+ dispatch(
1456
+ {
1457
+ type: "down",
1458
+ time: event.timeStamp,
1459
+ x: point.x,
1460
+ y: point.y,
1461
+ pointer: "touch"
1462
+ },
1463
+ event
1464
+ );
1465
+ }
1466
+ function onTouchMove(event) {
1467
+ const current = findTouch(event.changedTouches);
1468
+ if (!current) {
1469
+ return;
1470
+ }
1471
+ axisPoint(options.side(), current.clientX, current.clientY, point);
1472
+ tracker.add(event.timeStamp, point.y);
1473
+ const wasDragging = state.phase === "dragging";
1474
+ const context = scroll(event.target);
1475
+ dispatch(
1476
+ {
1477
+ type: "move",
1478
+ time: event.timeStamp,
1479
+ x: point.x,
1480
+ y: point.y,
1481
+ scroll: context
1482
+ },
1483
+ event
1484
+ );
1485
+ if (state.phase === "pending") {
1486
+ return claimEarly(event, current, context);
1487
+ }
1488
+ if (state.phase !== "dragging") {
1489
+ return;
1490
+ }
1491
+ if (event.cancelable) {
1492
+ event.preventDefault();
1493
+ } else if (!wasDragging && area) {
1494
+ area.style.overscrollBehavior = "none";
1495
+ }
1496
+ }
1497
+ function claimEarly(event, current, context) {
1498
+ if (!event.cancelable || !touch) {
1499
+ return;
1500
+ }
1501
+ const origin = axisPoint(options.side(), touch.originX, touch.originY, {
1502
+ x: 0,
1503
+ y: 0
1504
+ });
1505
+ if (Math.abs(point.y - origin.y) < Math.abs(point.x - origin.x)) {
1506
+ return;
1507
+ }
1508
+ const largest = options.config().snapPoints.at(-1)?.extent ?? 0;
1509
+ const owner = context ? handoff({
1510
+ towardMore: point.y < origin.y,
1511
+ scrollAtStart: context.atStart,
1512
+ atLargest: shown >= largest - 0.5,
1513
+ expandOnScroll: options.config().expandOnScroll
1514
+ }) : "sheet";
1515
+ if (owner === "sheet") {
1516
+ event.preventDefault();
1517
+ }
1518
+ }
1519
+ function onTouchEnd(event) {
1520
+ if (!findTouch(event.changedTouches)) {
1521
+ return;
1522
+ }
1523
+ touch = null;
1524
+ if (area) {
1525
+ area.style.removeProperty("overscroll-behavior");
1526
+ }
1527
+ const velocity = event.type === "touchcancel" ? 0 : tracker.velocity(event.timeStamp);
1528
+ dispatch({ type: "up", time: event.timeStamp, velocity }, event);
1529
+ }
1530
+ function findTouch(touches) {
1531
+ if (!touch) {
1532
+ return null;
1533
+ }
1534
+ for (let index = 0; index < touches.length; index++) {
1535
+ if (touches[index].identifier === touch.id) {
1536
+ return touches[index];
1537
+ }
1538
+ }
1539
+ return null;
1540
+ }
1541
+ function onPointerDown(event) {
1542
+ if (event.pointerType === "touch" || event.button !== 0 || pointerId !== null || closing) {
1543
+ return;
1544
+ }
1545
+ const target = event.target;
1546
+ if (!options.owns(target) || isIgnored(target) || !(target instanceof Element) || !options.canMouseDrag(target)) {
1547
+ return;
1548
+ }
1549
+ pointerId = event.pointerId;
1550
+ mouseDragged = false;
1551
+ coast = null;
1552
+ tracker.reset();
1553
+ axisPoint(options.side(), event.clientX, event.clientY, point);
1554
+ tracker.add(event.timeStamp, point.y);
1555
+ offPointer = [
1556
+ on(doc, "pointermove", onPointerMove, { capture: true }),
1557
+ on(doc, "pointerup", onPointerUp, { capture: true }),
1558
+ on(doc, "pointercancel", onPointerUp, { capture: true })
1559
+ ];
1560
+ const pointer = event.pointerType === "pen" ? "pen" : "mouse";
1561
+ dispatch(
1562
+ { type: "down", time: event.timeStamp, x: point.x, y: point.y, pointer },
1563
+ event
1564
+ );
1565
+ }
1566
+ let offPointer = [];
1567
+ function onPointerMove(event) {
1568
+ if (event.pointerId !== pointerId) {
1569
+ return;
1570
+ }
1571
+ const coalesced = event.getCoalescedEvents?.();
1572
+ for (const sample of coalesced?.length ? coalesced : [event]) {
1573
+ tracker.add(
1574
+ sample.timeStamp,
1575
+ axisPoint(options.side(), sample.clientX, sample.clientY, point).y
1576
+ );
1577
+ }
1578
+ axisPoint(options.side(), event.clientX, event.clientY, point);
1579
+ dispatch(
1580
+ {
1581
+ type: "move",
1582
+ time: event.timeStamp,
1583
+ x: point.x,
1584
+ y: point.y,
1585
+ scroll: scroll(event.target)
1586
+ },
1587
+ event
1588
+ );
1589
+ if (state.phase !== "dragging" || mouseDragged) {
1590
+ return;
1591
+ }
1592
+ mouseDragged = true;
1593
+ doc.getSelection()?.removeAllRanges();
1594
+ sheet.style.userSelect = "none";
1595
+ try {
1596
+ sheet.setPointerCapture(event.pointerId);
1597
+ } catch {
1598
+ }
1599
+ }
1600
+ function onPointerUp(event) {
1601
+ if (event.pointerId !== pointerId) {
1602
+ return;
1603
+ }
1604
+ pointerId = null;
1605
+ offPointer.forEach((off) => off());
1606
+ offPointer = [];
1607
+ sheet.style.removeProperty("user-select");
1608
+ const velocity = event.type === "pointercancel" ? 0 : tracker.velocity(event.timeStamp);
1609
+ dispatch({ type: "up", time: event.timeStamp, velocity }, event);
1610
+ if (mouseDragged) {
1611
+ swallowNextClick(doc);
1612
+ }
1613
+ }
1614
+ return {
1615
+ open(id, animate) {
1616
+ closing = null;
1617
+ targetId = id;
1618
+ stopAnimation();
1619
+ const index = options.config().snapPoints.findIndex((point2) => point2.id === id);
1620
+ if (!animate && index >= 0) {
1621
+ state = initialState(options.config().snapPoints[index].extent, index);
1622
+ writeTranslate(state.extent);
1623
+ return options.onRest(id);
1624
+ }
1625
+ state = initialState(0, -1);
1626
+ writeTranslate(options.closedExtent());
1627
+ dispatch({
1628
+ type: "snap-to",
1629
+ time: performance.now() + openHold,
1630
+ id,
1631
+ reason: "imperative"
1632
+ });
1633
+ const opening = animation;
1634
+ if (!opening) {
1635
+ return;
1636
+ }
1637
+ afterFirstFrame(view, (frameTime) => {
1638
+ if (animation !== opening || state.phase !== "settling") {
1639
+ return;
1640
+ }
1641
+ opening.startTime = frameTime;
1642
+ state = { ...state, startTime: frameTime };
1643
+ options.onMotionStart(frameTime);
1644
+ });
1645
+ },
1646
+ close() {
1647
+ const wasClosing = closing;
1648
+ closing = "close";
1649
+ if (!wasClosing) {
1650
+ dispatch({ type: "close", time: performance.now() });
1651
+ }
1652
+ },
1653
+ snapTo(id, reason) {
1654
+ if (closing === "close") {
1655
+ return;
1656
+ }
1657
+ closing = null;
1658
+ dispatch({ type: "snap-to", time: performance.now(), id, reason });
1659
+ },
1660
+ nudge() {
1661
+ if (!closing && !options.reducedMotion()) {
1662
+ dispatch({ type: "nudge", time: performance.now() });
1663
+ }
1664
+ },
1665
+ relayout(immediate, fallback) {
1666
+ const points = options.config().snapPoints;
1667
+ if (closing || targetId === null || state.phase === "dragging" || state.phase === "pending") {
1668
+ return writeTranslate(shown);
1669
+ }
1670
+ const kept = points.findIndex((point2) => point2.id === targetId);
1671
+ const wanted = points.findIndex((point2) => point2.id === fallback);
1672
+ const index = kept >= 0 ? kept : wanted >= 0 ? wanted : nearestIndex(
1673
+ points.map((point2) => point2.extent),
1674
+ shown
1675
+ );
1676
+ const { id, extent } = points[index];
1677
+ if (state.phase === "idle") {
1678
+ state = initialState(shown, kept);
1679
+ if (immediate || Math.abs(extent - shown) < 0.5) {
1680
+ state = initialState(extent, index);
1681
+ writeTranslate(extent);
1682
+ if (!immediate) {
1683
+ return;
1684
+ }
1685
+ if (id !== targetId) {
1686
+ run(
1687
+ { type: "snap", id, reason: "content-resize" },
1688
+ performance.now()
1689
+ );
1690
+ }
1691
+ return options.onRest(id);
1692
+ }
1693
+ }
1694
+ dispatch({
1695
+ type: "snap-to",
1696
+ time: performance.now(),
1697
+ id,
1698
+ reason: "content-resize"
1699
+ });
1700
+ },
1701
+ target: () => closing ? null : targetId,
1702
+ isMoving: () => state.phase !== "idle",
1703
+ destroy() {
1704
+ destroyed = true;
1705
+ stopAnimation();
1706
+ if (frame) {
1707
+ view.cancelAnimationFrame(frame);
1708
+ }
1709
+ offs.forEach((off) => off());
1710
+ offPointer.forEach((off) => off());
1711
+ if (dragging) {
1712
+ options.onDragChange(false);
1713
+ }
1714
+ for (const property of ["translate", "user-select", "opacity"]) {
1715
+ sheet.style.removeProperty(property);
1716
+ }
1717
+ }
1718
+ };
1719
+ }
1720
+
1721
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/popups/sheet-scroll-snap.js
1722
+ var restTimeout = 120;
1723
+ var overscrollRoom = 24;
1724
+ function createScrollSnapDriver(options) {
1725
+ const { sheet, host } = options;
1726
+ const doc = sheet.ownerDocument;
1727
+ const view = doc.defaultView ?? window;
1728
+ let state = initialState(0, -1);
1729
+ let extentAtTop = 0;
1730
+ let markers = [];
1731
+ let flip = null;
1732
+ let touching = false;
1733
+ let restMissed = false;
1734
+ let dragging = false;
1735
+ let closing = null;
1736
+ let restTimer = 0;
1737
+ let frame = 0;
1738
+ let targetId = null;
1739
+ let scrollAreas = [];
1740
+ let caught = null;
1741
+ const restoreHost = setStyles(host, {
1742
+ inset: `0 0 calc(var(--keyboard-inset, 0px) - ${toolbarBleed}px) 0`,
1743
+ display: "block",
1744
+ "overflow-y": "scroll",
1745
+ "overflow-x": "hidden",
1746
+ "scroll-snap-type": "y mandatory",
1747
+ "scrollbar-width": "none",
1748
+ "overscroll-behavior": "contain",
1749
+ "pointer-events": "auto"
1750
+ });
1751
+ const restoreSheet = setStyles(sheet, {
1752
+ position: "absolute",
1753
+ left: "0",
1754
+ right: "0"
1755
+ });
1756
+ const supportsScrollEnd = "onscrollend" in host;
1757
+ const Timeline = view.ScrollTimeline;
1758
+ const offs = [
1759
+ on(host, "scroll", onScroll, { passive: true }),
1760
+ ...supportsScrollEnd ? [on(host, "scrollend", onRest2)] : [],
1761
+ on(
1762
+ host,
1763
+ "touchstart",
1764
+ () => {
1765
+ touching = true;
1766
+ restMissed = false;
1767
+ if (flip && !closing) {
1768
+ catchFlip();
1769
+ }
1770
+ },
1771
+ { passive: true }
1772
+ ),
1773
+ on(host, "touchend", onTouchEnd, { passive: true }),
1774
+ on(host, "touchcancel", onTouchEnd, { passive: true })
1775
+ ];
1776
+ const visibility = new IntersectionObserver(onVisibility, {
1777
+ root: host,
1778
+ rootMargin: "0px 0px -1px 0px",
1779
+ threshold: 0
1780
+ });
1781
+ visibility.observe(sheet);
1782
+ const container = () => options.config().dimension;
1783
+ const largestExtent2 = () => options.config().snapPoints.at(-1)?.extent ?? 0;
1784
+ const maxScroll = () => largestExtent2() + overscrollRoom - extentAtTop;
1785
+ const scrollExtent = () => Math.min(host.scrollTop + extentAtTop, largestExtent2());
1786
+ function layout() {
1787
+ const config = options.config();
1788
+ extentAtTop = config.dismissible ? -toolbarBleed : config.snapPoints[0].extent;
1789
+ sheet.style.top = `${container() - extentAtTop}px`;
1790
+ for (const marker2 of markers) {
1791
+ marker2.remove();
1792
+ }
1793
+ const extents = config.snapPoints.map((point) => point.extent);
1794
+ const targets = config.dismissible ? [extentAtTop, ...extents] : extents;
1795
+ markers = targets.map((extent) => marker(extent - extentAtTop, "start"));
1796
+ markers.push(marker(maxScroll() + host.clientHeight - 1, "none"));
1797
+ host.append(...markers);
1798
+ scrollAreas = findScrollAreas(sheet);
1799
+ }
1800
+ function marker(top, align) {
1801
+ const el = doc.createElement("div");
1802
+ el.setAttribute("aria-hidden", "true");
1803
+ el.style.cssText = `position:absolute;left:0;width:1px;height:1px;top:${top}px;scroll-snap-align:${align};pointer-events:none`;
1804
+ return el;
1805
+ }
1806
+ function onScroll() {
1807
+ if (flip || closing) {
1808
+ return;
1809
+ }
1810
+ if (caught && touching && Math.abs(host.scrollTop - caught.offsetTop) > 1) {
1811
+ releaseCatch();
1812
+ }
1813
+ if (touching && !dragging) {
1814
+ setDragging(true);
1815
+ }
1816
+ if (!Timeline) {
1817
+ frame ||= view.requestAnimationFrame(followScroll);
1818
+ }
1819
+ view.clearTimeout(restTimer);
1820
+ if (!supportsScrollEnd && !touching) {
1821
+ restTimer = view.setTimeout(onRest2, restTimeout);
1822
+ }
1823
+ }
1824
+ function followScroll() {
1825
+ frame = 0;
1826
+ options.onFrame(scrollExtent());
1827
+ }
1828
+ function onTouchEnd() {
1829
+ touching = false;
1830
+ setDragging(false);
1831
+ if (caught) {
1832
+ releaseCatch();
1833
+ const points = options.config().snapPoints;
1834
+ const index = nearestIndex(
1835
+ points.map((point) => point.extent),
1836
+ scrollExtent()
1837
+ );
1838
+ return moveTo(points[index].id, "swipe");
1839
+ }
1840
+ if (!options.config().dismissible && host.scrollTop < -2) {
1841
+ options.onDismissAttempt();
1842
+ }
1843
+ if (restMissed || !supportsScrollEnd) {
1844
+ restTimer = view.setTimeout(onRest2, restTimeout);
1845
+ }
1846
+ restMissed = false;
1847
+ }
1848
+ function setDragging(value) {
1849
+ if (dragging === value) {
1850
+ return;
1851
+ }
1852
+ dragging = value;
1853
+ options.onDragChange(value);
1854
+ }
1855
+ function onRest2() {
1856
+ if (touching) {
1857
+ restMissed = true;
1858
+ return;
1859
+ }
1860
+ if (flip || closing) {
1861
+ return;
1862
+ }
1863
+ const config = options.config();
1864
+ const result = next(state, { type: "rest", extent: scrollExtent() }, config);
1865
+ state = result.state;
1866
+ for (const effect of result.effects) {
1867
+ if (effect.type === "snap") {
1868
+ targetId = effect.id;
1869
+ options.onSnap(effect.id, effect.reason);
1870
+ }
1871
+ }
1872
+ if (state.restingIndex >= 0) {
1873
+ settle(config.snapPoints[state.restingIndex].id);
1874
+ }
1875
+ }
1876
+ function onVisibility(entries) {
1877
+ const entry = entries[entries.length - 1];
1878
+ if (entry.isIntersecting || flip || closing || targetId === null || !options.config().dismissible) {
1879
+ return;
1880
+ }
1881
+ closing = "swipe";
1882
+ targetId = null;
1883
+ options.onDismiss();
1884
+ }
1885
+ function catchFlip() {
1886
+ if (!flip) {
1887
+ return;
1888
+ }
1889
+ const scroll = Math.max(
1890
+ 0,
1891
+ flip.extentAt(performance.now() - flip.startTime) - extentAtTop
1892
+ );
1893
+ stopFlip();
1894
+ caught = marker(scroll, "start");
1895
+ host.append(caught);
1896
+ host.scrollTop = scroll;
1897
+ followScroll();
1898
+ trackScroll();
1899
+ }
1900
+ function releaseCatch() {
1901
+ caught?.remove();
1902
+ caught = null;
1903
+ }
1904
+ function animateTo(target, from, startTime, onFinish) {
1905
+ stopFlip();
1906
+ const physics = options.config().physics;
1907
+ const solver = solveSpring(
1908
+ physics.response,
1909
+ physics.dampingRatio,
1910
+ from - target,
1911
+ 0
1912
+ );
1913
+ const duration = Math.max(1, settleTime(solver));
1914
+ const scrolled = Math.max(extentAtTop, target);
1915
+ host.scrollTop = scrolled - extentAtTop;
1916
+ const extentAt = (elapsed) => target + solver.position(Math.max(0, elapsed));
1917
+ const easing2 = Math.abs(target - from) < 0.5 ? "linear" : springLinearEasing(solver, from, target, duration);
1918
+ const animation = sheet.animate(
1919
+ { translate: [`0 ${scrolled - from}px`, `0 ${scrolled - target}px`] },
1920
+ { duration, easing: easing2, fill: "both" }
1921
+ );
1922
+ animation.startTime = startTime;
1923
+ flip = { animation, to: target, extentAt, startTime };
1924
+ options.onMotion({ type: "settle", extentAt, startTime, duration });
1925
+ animation.onfinish = () => {
1926
+ if (flip?.animation !== animation) {
1927
+ return;
1928
+ }
1929
+ flip = null;
1930
+ onFinish();
1931
+ animation.cancel();
1932
+ };
1933
+ }
1934
+ function stopFlip() {
1935
+ flip?.animation.cancel();
1936
+ flip = null;
1937
+ }
1938
+ function settle(id) {
1939
+ const config = options.config();
1940
+ const index = config.snapPoints.findIndex((point) => point.id === id);
1941
+ state = initialState(config.snapPoints[index].extent, index);
1942
+ targetId = id;
1943
+ host.style.pointerEvents = options.isInteractive(id) ? "none" : "auto";
1944
+ const atLargest = index === config.snapPoints.length - 1;
1945
+ for (const area of scrollAreas) {
1946
+ area.style.overflowY = atLargest ? "" : "hidden";
1947
+ }
1948
+ options.onRest(id);
1949
+ trackScroll();
1950
+ }
1951
+ function trackScroll() {
1952
+ if (!Timeline) {
1953
+ return;
1954
+ }
1955
+ const max = maxScroll();
1956
+ const timeline = new Timeline({ source: host, axis: "block" });
1957
+ options.onMotion({
1958
+ type: "timeline",
1959
+ timeline,
1960
+ extentAt: (progress) => Math.min(largestExtent2(), progress * max + extentAtTop)
1961
+ });
1962
+ }
1963
+ function moveTo(id, reason) {
1964
+ const point = options.config().snapPoints.find((entry) => entry.id === id);
1965
+ if (!point || closing === "close") {
1966
+ return;
1967
+ }
1968
+ closing = null;
1969
+ if (id !== targetId) {
1970
+ targetId = id;
1971
+ options.onSnap(id, reason);
1972
+ }
1973
+ const from = flip ? flip.extentAt(performance.now() - flip.startTime) : scrollExtent();
1974
+ animateTo(point.extent, from, performance.now(), () => settle(id));
1975
+ }
1976
+ return {
1977
+ open(id, animate) {
1978
+ closing = null;
1979
+ targetId = id;
1980
+ layout();
1981
+ const point = options.config().snapPoints.find((entry) => entry.id === id);
1982
+ if (!point) {
1983
+ return;
1984
+ }
1985
+ if (!animate) {
1986
+ host.scrollTop = point.extent - extentAtTop;
1987
+ return settle(id);
1988
+ }
1989
+ animateTo(
1990
+ point.extent,
1991
+ -toolbarBleed,
1992
+ performance.now() + openHold,
1993
+ () => settle(id)
1994
+ );
1995
+ const opening = flip;
1996
+ afterFirstFrame(view, (frameTime) => {
1997
+ if (!opening || flip !== opening) {
1998
+ return;
1999
+ }
2000
+ opening.animation.startTime = frameTime;
2001
+ opening.startTime = frameTime;
2002
+ options.onMotionStart(frameTime);
2003
+ });
2004
+ },
2005
+ close() {
2006
+ const wasClosing = closing;
2007
+ closing = "close";
2008
+ if (wasClosing) {
2009
+ return;
2010
+ }
2011
+ targetId = null;
2012
+ const from = flip ? flip.extentAt(performance.now() - flip.startTime) : scrollExtent();
2013
+ animateTo(
2014
+ -toolbarBleed,
2015
+ from,
2016
+ performance.now(),
2017
+ () => options.onRest(null)
2018
+ );
2019
+ },
2020
+ snapTo: moveTo,
2021
+ nudge() {
2022
+ if (closing || options.reducedMotion() || targetId === null) {
2023
+ return;
2024
+ }
2025
+ const point = options.config().snapPoints.find((entry) => entry.id === targetId);
2026
+ if (point) {
2027
+ animateTo(
2028
+ point.extent,
2029
+ point.extent - 20,
2030
+ performance.now(),
2031
+ () => settle(point.id)
2032
+ );
2033
+ }
2034
+ },
2035
+ relayout(_immediate, fallback) {
2036
+ if (closing || touching) {
2037
+ return;
2038
+ }
2039
+ const points = options.config().snapPoints;
2040
+ const kept = points.findIndex((point2) => point2.id === targetId);
2041
+ const wanted = points.findIndex((point2) => point2.id === fallback);
2042
+ const index = kept >= 0 ? kept : wanted >= 0 ? wanted : nearestIndex(
2043
+ points.map((point2) => point2.extent),
2044
+ scrollExtent()
2045
+ );
2046
+ layout();
2047
+ const point = points[index];
2048
+ if (point.id !== targetId) {
2049
+ targetId = point.id;
2050
+ options.onSnap(point.id, "content-resize");
2051
+ }
2052
+ host.scrollTop = point.extent - extentAtTop;
2053
+ settle(point.id);
2054
+ },
2055
+ target: () => closing ? null : targetId,
2056
+ isMoving: () => !!flip || dragging,
2057
+ destroy() {
2058
+ stopFlip();
2059
+ releaseCatch();
2060
+ view.clearTimeout(restTimer);
2061
+ if (frame) {
2062
+ view.cancelAnimationFrame(frame);
2063
+ }
2064
+ visibility.disconnect();
2065
+ offs.forEach((off) => off());
2066
+ for (const marker2 of markers) {
2067
+ marker2.remove();
2068
+ }
2069
+ for (const area of scrollAreas) {
2070
+ area.style.removeProperty("overflow-y");
2071
+ }
2072
+ if (dragging) {
2073
+ options.onDragChange(false);
2074
+ }
2075
+ sheet.style.removeProperty("top");
2076
+ restoreSheet();
2077
+ restoreHost();
2078
+ }
2079
+ };
2080
+ }
2081
+ function findScrollAreas(sheet) {
2082
+ const view = sheet.ownerDocument.defaultView ?? window;
2083
+ return Array.from(sheet.querySelectorAll("*")).filter(
2084
+ (el) => /auto|scroll/.test(view.getComputedStyle(el).overflowY)
2085
+ );
2086
+ }
2087
+
2088
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/popups/theme-color.js
2089
+ function channels(color) {
2090
+ const match = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/.exec(color);
2091
+ return match ? [match[1], match[2], match[3]].map(Number) : null;
2092
+ }
2093
+ function dimThemeColor(doc, alpha) {
2094
+ const metas = Array.from(
2095
+ doc.querySelectorAll('meta[name="theme-color"]')
2096
+ );
2097
+ const originals = metas.map((meta) => meta.content);
2098
+ const bases = originals.map((color) => channels(resolveColor(doc, color)));
2099
+ let written = -1;
2100
+ function write(dim) {
2101
+ const shade = Math.round(dim * alpha * 100) / 100;
2102
+ if (shade === written) {
2103
+ return;
2104
+ }
2105
+ written = shade;
2106
+ metas.forEach((meta, index) => {
2107
+ const base = bases[index];
2108
+ if (!base) {
2109
+ return;
2110
+ }
2111
+ meta.content = shade ? `rgb(${base.map((channel) => Math.round(channel * (1 - shade))).join(" ")})` : originals[index];
2112
+ });
2113
+ }
2114
+ function restore() {
2115
+ metas.forEach((meta, index) => meta.content = originals[index]);
2116
+ written = -1;
2117
+ }
2118
+ return { write, restore };
2119
+ }
2120
+ function resolveColor(doc, color) {
2121
+ const probe = doc.createElement("span");
2122
+ probe.style.color = color;
2123
+ probe.style.display = "none";
2124
+ doc.body.append(probe);
2125
+ const resolved = doc.defaultView?.getComputedStyle(probe).color ?? color;
2126
+ probe.remove();
2127
+ return resolved;
2128
+ }
2129
+
2130
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/popups/sheet.js
2131
+ var controls = 'a[href], button, label, summary, [role="button"], [role="link"], [role="slider"], [tabindex]:not([tabindex="-1"])';
2132
+ var isDragSurface = (target) => !target.closest(controls);
2133
+ var none3 = () => {
2134
+ };
2135
+ function withDefaults(options) {
2136
+ return {
2137
+ side: () => "bottom",
2138
+ // check-code: allow return-type the literal would widen to `string[]`.
2139
+ snapPoints: () => ["content"],
2140
+ snapPoint: () => null,
2141
+ dismissible: () => true,
2142
+ modalAbove: () => void 0,
2143
+ // check-code: allow return-type the literal would widen to string.
2144
+ driver: () => "auto",
2145
+ expandOnScroll: () => true,
2146
+ physics: () => void 0,
2147
+ backdrop: () => void 0,
2148
+ hostBackdrop: false,
2149
+ outlets: () => [],
2150
+ parent: () => void 0,
2151
+ themeColor: () => false,
2152
+ preventEdgeSwipe: () => false,
2153
+ canMouseDrag: isDragSurface,
2154
+ onSnap: none3,
2155
+ onRest: none3,
2156
+ onDismissAttempt: none3,
2157
+ onDragChange: none3,
2158
+ onLayout: none3,
2159
+ ...withoutUndefined(options)
2160
+ };
2161
+ }
2162
+ function withoutUndefined(object) {
2163
+ return Object.fromEntries(
2164
+ Object.entries(object).filter(([, value]) => value !== void 0)
2165
+ );
2166
+ }
2167
+ var sheets = /* @__PURE__ */ new WeakSet();
2168
+ var sheetLayers = /* @__PURE__ */ new WeakMap();
2169
+ function parentSheet(layer) {
2170
+ for (let up = layer.parent; up; up = up.parent) {
2171
+ const sheet = sheetLayers.get(up);
2172
+ if (sheet) {
2173
+ return sheet;
2174
+ }
2175
+ }
2176
+ }
2177
+ function sheetAt(target) {
2178
+ for (let node = target instanceof Element ? target : null; node; ) {
2179
+ if (sheets.has(node)) {
2180
+ return node;
2181
+ }
2182
+ const root = node.getRootNode();
2183
+ node = node.parentElement ?? (root instanceof ShadowRoot ? root.host : null);
2184
+ }
2185
+ return null;
2186
+ }
2187
+ var edgeZone = 24;
2188
+ function usesScrollSnap(view, options) {
2189
+ const driver = options.driver();
2190
+ if (driver !== "auto") {
2191
+ return driver === "scroll-snap";
2192
+ }
2193
+ return options.modalAbove() === void 0 && options.expandOnScroll() && !!view.matchMedia?.("(hover: none) and (pointer: coarse)").matches;
2194
+ }
2195
+ var keyboardMotion = {
2196
+ duration: 250,
2197
+ easing: "cubic-bezier(0.38, 0.7, 0.125, 1)"
2198
+ };
2199
+ function attachSheet(el, input) {
2200
+ const options = withDefaults(input);
2201
+ const { host } = options;
2202
+ const doc = el.ownerDocument;
2203
+ const view = doc.defaultView ?? window;
2204
+ const reducedMotion = view.matchMedia?.("(prefers-reduced-motion: reduce)");
2205
+ let side = resolveSide(options.side(), el);
2206
+ let resolved = [];
2207
+ let size = 0;
2208
+ let physicsSource;
2209
+ let physics = sheetPhysics.ios;
2210
+ let theme;
2211
+ let restoreBackdrop;
2212
+ const config = {
2213
+ snapPoints: [],
2214
+ dimension: 0,
2215
+ dismissible: true,
2216
+ expandOnScroll: true,
2217
+ physics,
2218
+ contentScroll
2219
+ };
2220
+ const scrollSnap = side === "bottom" && usesScrollSnap(view, options);
2221
+ sheets.add(el);
2222
+ const restoreStyles = [styleHost(host, side, el), styleSheet(el)];
2223
+ let ancestors = [];
2224
+ const effects = createSheetEffects({
2225
+ sheet: el,
2226
+ backdrop: options.backdrop,
2227
+ dimmed: options.hostBackdrop ? host : void 0,
2228
+ outlets: options.outlets,
2229
+ ancestors: () => ancestors,
2230
+ themeColor: (dim) => theme?.write(dim)
2231
+ });
2232
+ function readConfig() {
2233
+ const source = options.physics();
2234
+ if (source !== physicsSource) {
2235
+ physicsSource = source;
2236
+ physics = source ? { ...sheetPhysics.ios, ...source } : sheetPhysics.ios;
2237
+ }
2238
+ config.physics = physics;
2239
+ config.dismissible = options.dismissible();
2240
+ config.expandOnScroll = options.expandOnScroll();
2241
+ return config;
2242
+ }
2243
+ function measure() {
2244
+ const nextSide = resolveSide(options.side(), el);
2245
+ if (nextSide !== side) {
2246
+ side = nextSide;
2247
+ restoreStyles[0]();
2248
+ restoreStyles[0] = styleHost(host, side, el);
2249
+ }
2250
+ const container = (isVertical(side) ? host.clientHeight : host.clientWidth) - (scrollSnap ? toolbarBleed : 0);
2251
+ size = sizeAlong(el, side);
2252
+ const rootFontSize = parseFloat(view.getComputedStyle(doc.documentElement).fontSize) || 16;
2253
+ const next2 = resolveSnapPoints(options.snapPoints(), {
2254
+ container,
2255
+ content: size,
2256
+ rootFontSize
2257
+ });
2258
+ if (!next2.length) {
2259
+ next2.push({
2260
+ id: "content",
2261
+ value: "content",
2262
+ extent: size,
2263
+ ids: ["content"]
2264
+ });
2265
+ }
2266
+ const changed = container !== config.dimension || next2.length !== resolved.length || next2.some(
2267
+ (point, index) => point.id !== resolved[index].id || Math.abs(point.extent - resolved[index].extent) >= 0.5
2268
+ );
2269
+ resolved = next2;
2270
+ config.dimension = container;
2271
+ config.snapPoints = resolved.map(({ id, extent }) => ({ id, extent }));
2272
+ effects.configure({
2273
+ snapExtents: config.snapPoints.map((point) => point.extent),
2274
+ undimmedIndex: findSnapIndex(resolved, options.modalAbove())
2275
+ });
2276
+ if (changed) {
2277
+ reportLayout();
2278
+ }
2279
+ return changed;
2280
+ }
2281
+ let destroyed = false;
2282
+ const valueOf = (id) => id === null ? null : resolved.find((point) => point.id === id)?.value ?? null;
2283
+ const driverOptions = {
2284
+ sheet: el,
2285
+ host,
2286
+ side: () => side,
2287
+ config: readConfig,
2288
+ size: () => size,
2289
+ closedExtent: () => closedExtentFor(side),
2290
+ reducedMotion: () => !!reducedMotion?.matches,
2291
+ owns: (target) => sheetAt(target) === el,
2292
+ canMouseDrag: options.canMouseDrag,
2293
+ onSnap: (id, reason, event) => {
2294
+ const value = valueOf(id);
2295
+ if (value !== null) {
2296
+ options.onSnap(value, reason, event);
2297
+ }
2298
+ },
2299
+ onRest(id) {
2300
+ if (destroyed) {
2301
+ return;
2302
+ }
2303
+ const point = resolved.find((entry) => entry.id === id);
2304
+ effects.apply(point?.extent ?? closedExtentFor(side), { rest: true });
2305
+ options.onRest(valueOf(id));
2306
+ if (revealAtRest && id !== null) {
2307
+ revealFocused();
2308
+ }
2309
+ revealAtRest = false;
2310
+ },
2311
+ onDismiss: options.onDismiss,
2312
+ onDismissAttempt: options.onDismissAttempt,
2313
+ onDragChange: options.onDragChange,
2314
+ isInteractive: (id) => sheet.isInteractiveAt(valueOf(id)),
2315
+ onFrame: (extent) => destroyed || effects.apply(extent),
2316
+ onMotion: (motion) => destroyed || effects.play(motion),
2317
+ onMotionStart: (startTime) => destroyed || effects.sync(startTime)
2318
+ };
2319
+ let attaching = true;
2320
+ function reportLayout() {
2321
+ if (!attaching) {
2322
+ return options.onLayout({ side, snapPoints: resolved });
2323
+ }
2324
+ queueMicrotask(
2325
+ () => destroyed || options.onLayout({ side, snapPoints: resolved })
2326
+ );
2327
+ }
2328
+ measure();
2329
+ readConfig();
2330
+ const driver = scrollSnap ? createScrollSnapDriver(driverOptions) : createPointerDriver(driverOptions);
2331
+ el.setAttribute("data-driver", scrollSnap ? "scroll-snap" : "pointer");
2332
+ attaching = false;
2333
+ const observer = new ResizeObserver(() => {
2334
+ relayout(false);
2335
+ });
2336
+ observer.observe(el);
2337
+ observer.observe(host);
2338
+ let keyboardFrom = 0;
2339
+ let viewportHeight = view.visualViewport?.height;
2340
+ let keyboardSlide = null;
2341
+ const offKeyboard = trackKeyboard(host, {
2342
+ before: () => keyboardFrom = el.getBoundingClientRect().top,
2343
+ after: followKeyboard
2344
+ });
2345
+ const offs = [
2346
+ offKeyboard,
2347
+ // A listener that can cancel touches makes the browser wait for script
2348
+ // before it scrolls, so it's added only for a sheet that asks for it.
2349
+ ...options.preventEdgeSwipe() ? [
2350
+ on(doc, "touchstart", preventEdgeSwipe, {
2351
+ capture: true,
2352
+ passive: false
2353
+ })
2354
+ ] : [],
2355
+ ...isIOS() ? [
2356
+ on(doc, "touchend", focusWithoutScrolling, {
2357
+ capture: true,
2358
+ passive: false
2359
+ })
2360
+ ] : [],
2361
+ on(el, "focusin", revealWhenStill)
2362
+ ];
2363
+ function followKeyboard() {
2364
+ relayout(true);
2365
+ revealFocused();
2366
+ const height = view.visualViewport?.height;
2367
+ if (height === viewportHeight) {
2368
+ return;
2369
+ }
2370
+ viewportHeight = height;
2371
+ keyboardSlide?.cancel();
2372
+ keyboardSlide = null;
2373
+ const shift = keyboardFrom - el.getBoundingClientRect().top;
2374
+ if (Math.abs(shift) < 1 || reducedMotion?.matches) {
2375
+ return;
2376
+ }
2377
+ keyboardSlide = host.animate(
2378
+ { translate: [`0 ${shift}px`, "0 0"] },
2379
+ keyboardMotion
2380
+ );
2381
+ }
2382
+ function preventEdgeSwipe(event) {
2383
+ if (!event.cancelable) {
2384
+ return;
2385
+ }
2386
+ const touch = event.touches[0];
2387
+ if (!touch || touch.clientX > edgeZone && touch.clientX < view.innerWidth - edgeZone) {
2388
+ return;
2389
+ }
2390
+ const target = event.target;
2391
+ if (target && (host.contains(target) || options.backdrop()?.contains(target))) {
2392
+ event.preventDefault();
2393
+ }
2394
+ }
2395
+ function focusWithoutScrolling(event) {
2396
+ const target = event.target;
2397
+ if (!(target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement)) {
2398
+ return;
2399
+ }
2400
+ if (!el.contains(target) || target === doc.activeElement || driver.isMoving() || !event.cancelable) {
2401
+ return;
2402
+ }
2403
+ event.preventDefault();
2404
+ target.focus({ preventScroll: true });
2405
+ }
2406
+ let revealAtRest = false;
2407
+ function revealWhenStill() {
2408
+ if (driver.isMoving()) {
2409
+ revealAtRest = true;
2410
+ } else {
2411
+ revealFocused();
2412
+ }
2413
+ }
2414
+ function revealFocused() {
2415
+ const field = doc.activeElement;
2416
+ if (!(field instanceof HTMLElement) || !el.contains(field) || field === el) {
2417
+ return;
2418
+ }
2419
+ const area = scrollAreaAt(field, el, "bottom");
2420
+ if (!area) {
2421
+ return;
2422
+ }
2423
+ const visual = view.visualViewport;
2424
+ const visibleBottom = Math.min(
2425
+ area.getBoundingClientRect().bottom,
2426
+ visual ? visual.offsetTop + visual.height : view.innerHeight
2427
+ );
2428
+ const { top, bottom } = field.getBoundingClientRect();
2429
+ const margin = 16;
2430
+ const areaTop = area.getBoundingClientRect().top;
2431
+ const delta = bottom + margin > visibleBottom ? bottom + margin - visibleBottom : top - margin < areaTop ? top - margin - areaTop : 0;
2432
+ if (delta) {
2433
+ area.scrollBy({
2434
+ top: delta,
2435
+ behavior: reducedMotion?.matches ? "instant" : "smooth"
2436
+ });
2437
+ }
2438
+ }
2439
+ function relayout(immediate) {
2440
+ if (measure()) {
2441
+ driver.relayout(
2442
+ immediate,
2443
+ resolved[findSnapIndex(resolved, options.snapPoint())]?.id
2444
+ );
2445
+ }
2446
+ }
2447
+ function idOf(point) {
2448
+ const index = findSnapIndex(resolved, point);
2449
+ return resolved[index >= 0 ? index : 0]?.id;
2450
+ }
2451
+ const sheet = {
2452
+ element: el,
2453
+ parent: options.parent,
2454
+ open(animate) {
2455
+ if (destroyed) {
2456
+ return;
2457
+ }
2458
+ ancestors = [];
2459
+ for (let parent = options.parent(); parent; parent = parent.parent()) {
2460
+ ancestors.push(parent.element);
2461
+ }
2462
+ measure();
2463
+ readConfig();
2464
+ if (options.themeColor()) {
2465
+ theme ??= dimThemeColor(doc, physics.dim);
2466
+ }
2467
+ if (animate) {
2468
+ effects.apply(closedExtentFor(side));
2469
+ }
2470
+ restoreBackdrop?.();
2471
+ const backdrop = options.backdrop();
2472
+ restoreBackdrop = backdrop && setStyles(backdrop, { "will-change": "opacity" });
2473
+ driver.open(idOf(options.snapPoint()), animate);
2474
+ },
2475
+ close: () => destroyed || driver.close(),
2476
+ snapTo(point, reason) {
2477
+ const index = findSnapIndex(resolved, point);
2478
+ if (index >= 0 && resolved[index].id !== driver.target()) {
2479
+ driver.snapTo(resolved[index].id, reason);
2480
+ }
2481
+ },
2482
+ nudge: () => driver.nudge(),
2483
+ snapPoints: () => resolved,
2484
+ target: () => valueOf(driver.target()),
2485
+ isInteractiveAt: (point) => isAtOrBelow(resolved, point, options.modalAbove()),
2486
+ refresh() {
2487
+ relayout(false);
2488
+ },
2489
+ destroy() {
2490
+ destroyed = true;
2491
+ observer.disconnect();
2492
+ keyboardSlide?.cancel();
2493
+ offs.forEach((off) => off());
2494
+ driver.destroy();
2495
+ effects.destroy();
2496
+ restoreBackdrop?.();
2497
+ theme?.restore();
2498
+ restoreStyles.forEach((restore) => restore());
2499
+ el.removeAttribute("data-driver");
2500
+ sheets.delete(el);
2501
+ }
2502
+ };
2503
+ return sheet;
2504
+ }
2505
+ function styleHost(host, side, sheet) {
2506
+ const vertical = isVertical(side);
2507
+ const rtl = sheet.ownerDocument.defaultView?.getComputedStyle(host).direction === "rtl";
2508
+ const atEnd = side === "bottom" || side === "right" !== rtl;
2509
+ return setStyles(host, {
2510
+ position: "fixed",
2511
+ inset: "0 0 var(--keyboard-inset, 0px) 0",
2512
+ width: "auto",
2513
+ height: "auto",
2514
+ "max-width": "none",
2515
+ "max-height": "none",
2516
+ margin: "0",
2517
+ padding: "0",
2518
+ border: "0",
2519
+ background: "transparent",
2520
+ color: "inherit",
2521
+ overflow: "visible",
2522
+ display: "flex",
2523
+ "flex-direction": vertical ? "column" : "row",
2524
+ "justify-content": atEnd ? "flex-end" : "flex-start",
2525
+ "pointer-events": "none"
2526
+ });
2527
+ }
2528
+ function styleSheet(sheet) {
2529
+ return setStyles(sheet, {
2530
+ "pointer-events": "auto",
2531
+ "overscroll-behavior": "contain",
2532
+ "will-change": "translate"
2533
+ });
2534
+ }
2535
+
2536
+ // ../../node_modules/.pnpm/@ui-sdk+core@0.1.0-beta.5/node_modules/@ui-sdk/core/dist/foundation/popups/sheet-presentation.js
2537
+ function styleBackdrop(host) {
2538
+ const slot = host.getAttribute("data-slot");
2539
+ if (!slot) {
2540
+ return;
2541
+ }
2542
+ writeStyle(
2543
+ host.ownerDocument,
2544
+ `ui-sdk-sheet-${slot}`,
2545
+ `@layer ui-sdk { :where([data-slot="${slot}"])::backdrop { background: var(--sheet-backdrop, rgb(0 0 0 / 0.2)); pointer-events: auto } }`
2546
+ );
2547
+ }
2548
+ function isolate(container, keep) {
2549
+ const restores = [];
2550
+ const walk = (node) => {
2551
+ for (const child of Array.from(node.children)) {
2552
+ if (keep.includes(child)) {
2553
+ continue;
2554
+ }
2555
+ if (keep.some((el) => el && child.contains(el))) {
2556
+ walk(child);
2557
+ } else if (child instanceof HTMLElement) {
2558
+ restores.push(setStyle(child, "display", "none"));
2559
+ }
2560
+ }
2561
+ };
2562
+ walk(container);
2563
+ return () => restores.forEach((restore) => restore());
2564
+ }
2565
+ function drillIn(el, popup, config) {
2566
+ let restore;
2567
+ const unbind = popup.bind(el, {
2568
+ ...config,
2569
+ position: void 0,
2570
+ inline: true,
2571
+ onShow() {
2572
+ const [parent, trigger] = config.drillIn();
2573
+ if (parent) {
2574
+ restore = isolate(parent, [el, trigger]);
2575
+ }
2576
+ return () => restore?.();
2577
+ },
2578
+ onClose() {
2579
+ restore?.();
2580
+ restore = setStyle(el, "display", "none");
2581
+ }
2582
+ });
2583
+ return () => {
2584
+ unbind();
2585
+ restore?.();
2586
+ };
2587
+ }
2588
+ function presentSheet(el, popup, config) {
2589
+ if (config.drillIn) {
2590
+ return drillIn(el, popup, config);
2591
+ }
2592
+ const host = el.parentElement;
2593
+ if (!host) {
2594
+ return;
2595
+ }
2596
+ styleBackdrop(host);
2597
+ let sheet;
2598
+ return popup.bind(el, {
2599
+ ...config,
2600
+ position: void 0,
2601
+ host: () => host,
2602
+ onShow(layer) {
2603
+ const shown = showSheet(el, host, popup, config, layer);
2604
+ sheet = shown.sheet;
2605
+ return () => {
2606
+ shown.hide();
2607
+ sheet = void 0;
2608
+ };
2609
+ },
2610
+ onClose: () => sheet?.close()
2611
+ });
2612
+ }
2613
+ function showSheet(el, host, popup, config, layer) {
2614
+ let rest = null;
2615
+ const stackedOn = parentSheet(layer);
2616
+ const dimsHost = !config.backdrop?.();
2617
+ const sheet = attachSheet(el, {
2618
+ host,
2619
+ snapPoints: () => config.snapPoints ?? ["content"],
2620
+ snapPoint: () => rest,
2621
+ backdrop: config.backdrop,
2622
+ hostBackdrop: dimsHost,
2623
+ dismissible: config.dismissible,
2624
+ onDismissAttempt: config.onDismissAttempt,
2625
+ parent: () => stackedOn?.(),
2626
+ onSnap: (point) => rest = point,
2627
+ onDismiss(event) {
2628
+ popup.requestClose("swipe", event);
2629
+ requestAnimationFrame(() => {
2630
+ const point = rest ?? sheet.snapPoints()[0]?.value;
2631
+ if (layer.active() && point !== void 0) {
2632
+ sheet.snapTo(point, "imperative");
2633
+ }
2634
+ });
2635
+ }
2636
+ });
2637
+ sheetLayers.set(layer, () => sheet);
2638
+ config.onSheet?.(sheet);
2639
+ const offGrow = on(el, "focusin", (event) => {
2640
+ const largest = sheet.snapPoints().at(-1);
2641
+ if (largest && sheet.snapPoints().length > 1 && event.target.matches("input, textarea")) {
2642
+ sheet.snapTo(largest.value, "imperative");
2643
+ }
2644
+ });
2645
+ const color = dimsHost ? getComputedStyle(el).getPropertyValue("--sheet-backdrop") : "transparent";
2646
+ if (color) {
2647
+ host.style.setProperty("--sheet-backdrop", color);
2648
+ }
2649
+ if (layer.active()) {
2650
+ sheet.open(popup.opener() !== "initial");
2651
+ }
2652
+ return {
2653
+ sheet,
2654
+ hide() {
2655
+ offGrow();
2656
+ sheetLayers.delete(layer);
2657
+ sheet.destroy();
2658
+ config.onSheet?.(void 0);
2659
+ host.style.removeProperty("--sheet-backdrop");
2660
+ }
2661
+ };
2662
+ }
2663
+ export {
2664
+ prepareVariables,
2665
+ presentSheet
2666
+ };
2667
+ //# sourceMappingURL=sheet-presentation-S6GGOKMB.js.map