@n-uf/motion 26.11.52 → 26.11.54

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 (46) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/README.md +22 -29
  3. package/dist/browser.d.ts +79 -3
  4. package/dist/browser.js +49 -3
  5. package/dist/browser.js.map +1 -1
  6. package/dist/chunk-4XGH5367.js +379 -0
  7. package/dist/chunk-4XGH5367.js.map +1 -0
  8. package/dist/{chunk-SIAZRWYD.js → chunk-ALYH6YQK.js} +4 -7
  9. package/dist/chunk-ALYH6YQK.js.map +1 -0
  10. package/dist/{chunk-BVPVUJ42.js → chunk-G5EJSZ3B.js} +77 -30
  11. package/dist/chunk-G5EJSZ3B.js.map +1 -0
  12. package/dist/chunk-IT2FMZOM.js +989 -0
  13. package/dist/chunk-IT2FMZOM.js.map +1 -0
  14. package/dist/{chunk-V7DEXKBZ.js → chunk-NI7JLDWZ.js} +35 -8
  15. package/dist/chunk-NI7JLDWZ.js.map +1 -0
  16. package/dist/{chunk-7EAAKM6U.js → chunk-QMGPJ2FG.js} +37 -89
  17. package/dist/chunk-QMGPJ2FG.js.map +1 -0
  18. package/dist/chunk-RWDYRT3H.js +14 -0
  19. package/dist/chunk-RWDYRT3H.js.map +1 -0
  20. package/dist/clock.d.ts +40 -7
  21. package/dist/clock.js +3 -1
  22. package/dist/double-click-DBfbiP2U.d.ts +39 -0
  23. package/dist/drag.d.ts +170 -192
  24. package/dist/drag.js +24 -892
  25. package/dist/drag.js.map +1 -1
  26. package/dist/{frame-loop-C88dc9xw.d.ts → frame-loop-f0V4b464.d.ts} +11 -11
  27. package/dist/gestures.d.ts +40 -74
  28. package/dist/gestures.js +8 -7
  29. package/dist/index.d.ts +10 -6
  30. package/dist/index.js +60 -10
  31. package/dist/layout.d.ts +9 -233
  32. package/dist/layout.js +7 -427
  33. package/dist/layout.js.map +1 -1
  34. package/dist/motion-sElR1A_c.d.ts +163 -0
  35. package/dist/reveal-Dg5fqoWS.d.ts +51 -0
  36. package/dist/{reveal-C-ewJfFn.d.ts → settle-7C9xxbFg.d.ts} +7 -57
  37. package/dist/values.d.ts +15 -7
  38. package/dist/values.js +2 -2
  39. package/package.json +2 -2
  40. package/dist/chunk-7EAAKM6U.js.map +0 -1
  41. package/dist/chunk-BVPVUJ42.js.map +0 -1
  42. package/dist/chunk-IJSIYH2D.js +0 -7
  43. package/dist/chunk-IJSIYH2D.js.map +0 -1
  44. package/dist/chunk-SIAZRWYD.js.map +0 -1
  45. package/dist/chunk-V7DEXKBZ.js.map +0 -1
  46. package/dist/double-click-jtUSNuHL.d.ts +0 -16
@@ -0,0 +1,989 @@
1
+ import {
2
+ DOUBLE_CLICK,
3
+ isHeld
4
+ } from "./chunk-RWDYRT3H.js";
5
+
6
+ // src/drag/intent.ts
7
+ var DRAG_DEFAULTS = {
8
+ lift: 5,
9
+ touchHold: 180,
10
+ touchLift: 8,
11
+ speedWindow: 50,
12
+ aimSpeed: 0.45,
13
+ still: 12,
14
+ dwell: 90,
15
+ band: 10,
16
+ breakthrough: 4,
17
+ bandShare: 0.2,
18
+ gapGrace: 120,
19
+ switchHold: 150,
20
+ roomAfter: 160,
21
+ homeInset: 6,
22
+ armAfter: 200,
23
+ liftZone: 16,
24
+ modifiers: { on: true, floatKey: "shift", armKey: "mod" }
25
+ };
26
+ var REFUSAL_RANK = 2.5;
27
+ var pickRank = (t) => t.refuse === true ? REFUSAL_RANK : t.priority;
28
+ var within = (bounds, point) => !bounds || point.x > bounds.x && point.x < bounds.x + bounds.width && point.y > bounds.y && point.y < bounds.y + bounds.height;
29
+ function inRect(rect, point, margin = 0) {
30
+ return point.x >= rect.x - margin && point.x <= rect.x + rect.width + margin && point.y >= rect.y - margin && point.y <= rect.y + rect.height + margin;
31
+ }
32
+ var distanceTo = (rect, point) => Math.hypot(Math.max(rect.x - point.x, 0, point.x - (rect.x + rect.width)), Math.max(rect.y - point.y, 0, point.y - (rect.y + rect.height)));
33
+ var inZone = (t, point, margin = 0) => within(t.bounds, point) && (t.hits ? t.hits.some((r) => inRect(r, point, margin)) : inRect(t.hit, point, margin));
34
+ var inZoneBy = (t, point, m) => within(t.bounds, point) && (t.hits ?? [t.hit]).some((r) => point.x >= r.x - m.x && point.x <= r.x + r.width + m.x && point.y >= r.y - m.y && point.y <= r.y + r.height + m.y);
35
+ var scaled = (px, share, zones) => {
36
+ let x = px;
37
+ let y = px;
38
+ for (const z of zones) {
39
+ if (!z) continue;
40
+ x = Math.min(x, share * z.hit.width);
41
+ y = Math.min(y, share * z.hit.height);
42
+ }
43
+ return { x, y };
44
+ };
45
+ var negate = (m) => ({ x: -m.x, y: -m.y });
46
+ var area = (r) => r.width * r.height;
47
+ var zoneArea = (t) => t.hits ? t.hits.reduce((s, r) => s + area(r), 0) : area(t.hit);
48
+ function targetAt(targets, point) {
49
+ let best = null;
50
+ for (const t of targets) {
51
+ if (!inZone(t, point)) continue;
52
+ if (!best || pickRank(t) < pickRank(best) || pickRank(t) === pickRank(best) && zoneArea(t) < zoneArea(best)) best = t;
53
+ }
54
+ return best;
55
+ }
56
+ function liftDecision(press, tuning = {}) {
57
+ const t = { ...DRAG_DEFAULTS, ...tuning };
58
+ if (!press.touch) return press.distance >= t.lift ? "lift" : "wait";
59
+ if (press.elapsed < t.touchHold) return press.distance >= t.touchLift ? "refuse" : "wait";
60
+ return press.distance >= t.touchLift ? "lift" : "wait";
61
+ }
62
+ function createDragIntent(options) {
63
+ const tuning = { ...DRAG_DEFAULTS, ...options.tuning };
64
+ const placeOf = options.placeOf ?? ((t) => t.id);
65
+ let lastPlaces = /* @__PURE__ */ new Map();
66
+ let home = { ...options.home };
67
+ let samples = [];
68
+ let cur = null;
69
+ let curSince = 0;
70
+ let lastInside = 0;
71
+ let shown = null;
72
+ let shownSince = 0;
73
+ let place = null;
74
+ let placeSince = 0;
75
+ let roomPlace = null;
76
+ let leftHome = false;
77
+ let wentOut = false;
78
+ let speed = 0;
79
+ let anchor = null;
80
+ let stillSince = 0;
81
+ let restart = false;
82
+ let bounds = options.bounds ? { ...options.bounds } : void 0;
83
+ let lastPoint = null;
84
+ const clampInto = (p) => bounds ? { x: Math.min(Math.max(p.x, bounds.x), bounds.x + bounds.width), y: Math.min(Math.max(p.y, bounds.y), bounds.y + bounds.height) } : p;
85
+ let armedId = null;
86
+ let armingId = null;
87
+ let armingSince = 0;
88
+ const wasOutside = /* @__PURE__ */ new Set();
89
+ let liftAt = options.lift ? { ...options.lift } : null;
90
+ const same = (a, b) => a === null || b === null ? a === b : a.id === b.id;
91
+ const follow = (t, targets) => t ? targets.find((x) => x.id === t.id) ?? t : null;
92
+ const asArmed = (x) => {
93
+ if (!x.armedHit) return x;
94
+ const { hits: _pieces, ...rest } = x;
95
+ return { ...rest, hit: x.armedHit };
96
+ };
97
+ const acting = (targets) => targets.filter((x) => x.arm !== "dwell" || x.id === armedId).map((x) => x.id === armedId ? asArmed(x) : x);
98
+ const forcedBy = (keys, p, targets, has) => {
99
+ const m = tuning.modifiers;
100
+ if (!m.on || !keys) return null;
101
+ if (isHeld(keys, m.floatKey)) {
102
+ const f = targets.find((x) => x.free);
103
+ if (!f) return null;
104
+ const under = targetAt(acting(targets).filter((x) => inZone(x, p) && has(x)), p);
105
+ if (under?.refuse === true) return { kind: "float", target: null, refused: under };
106
+ return within(f.bounds, p) ? { kind: "float", target: f, refused: null } : { kind: "float", target: null, refused: null };
107
+ }
108
+ if (!isHeld(keys, m.armKey)) return null;
109
+ let best = null;
110
+ let bestD = Infinity;
111
+ for (const x of targets) {
112
+ if (x.arm !== "dwell") continue;
113
+ const d = distanceTo(asArmed(x).hit, p);
114
+ if (d < bestD) {
115
+ best = x;
116
+ bestD = d;
117
+ }
118
+ }
119
+ return best ? { kind: "armed", target: asArmed(best), refused: null } : null;
120
+ };
121
+ const landAt = (point, given, keys) => {
122
+ const forced = forcedBy(keys, point, given, (x) => x.refuse === true || placeOf(x, point, lastPlaces.get(x.id) ?? null) !== null);
123
+ if (forced) {
124
+ const ft = forced.target;
125
+ return ft ? given.find((x) => x.id === ft.id) ?? ft : null;
126
+ }
127
+ if (inRect(home, point)) {
128
+ const armed = armedId === null ? null : given.find((x) => x.id === armedId);
129
+ return armed && inZone(asArmed(armed), point) && placeOf(armed, point, lastPlaces.get(armed.id) ?? null) !== null ? armed : null;
130
+ }
131
+ const targets = acting(given);
132
+ const s = shown && !(shown.arm === "dwell" && shown.id !== armedId) ? follow(shown, given) : null;
133
+ const under = targetAt(
134
+ targets.filter((x) => inZone(x, point) && (x.refuse === true || placeOf(x, point, lastPlaces.get(x.id) ?? null) !== null)),
135
+ point
136
+ );
137
+ if (s) return s;
138
+ return under && !under.refuse ? given.find((x) => x.id === under.id) ?? under : null;
139
+ };
140
+ function update(point, time, given, keys) {
141
+ const p = clampInto(point);
142
+ lastPoint = p;
143
+ const t = time;
144
+ samples.push({ x: p.x, y: p.y, t });
145
+ while (samples.length > 2 && t - samples[0].t > tuning.speedWindow) samples.shift();
146
+ const a = samples[0];
147
+ speed = speed * 0.5 + Math.hypot(p.x - a.x, p.y - a.y) / Math.max(1, t - a.t) * 0.5;
148
+ if (!anchor || Math.hypot(p.x - anchor.x, p.y - anchor.y) > tuning.still) {
149
+ anchor = { x: p.x, y: p.y };
150
+ stillSince = t;
151
+ }
152
+ if (!inRect(home, p, -tuning.homeInset)) leftHome = true;
153
+ const atHome = inRect(home, p);
154
+ if (!atHome) wentOut = true;
155
+ const places = /* @__PURE__ */ new Map();
156
+ const placeAt = (x) => {
157
+ if (!places.has(x.id)) places.set(x.id, placeOf(x, p, lastPlaces.get(x.id) ?? null));
158
+ return places.get(x.id);
159
+ };
160
+ const live = (x) => x !== null && placeAt(x) !== null;
161
+ const forced = forcedBy(keys, p, given, (x) => x.refuse === true || live(x));
162
+ if (armedId !== null) {
163
+ const was = given.find((x) => x.id === armedId);
164
+ if (!was || forced || !inZone(asArmed(was), p) || !live(was)) armedId = null;
165
+ }
166
+ for (const x of given) if (x.arm === "dwell" && !inZone(x, p)) wasOutside.add(x.id);
167
+ liftAt ??= { x: p.x, y: p.y };
168
+ const inLiftZone = Math.hypot(p.x - liftAt.x, p.y - liftAt.y) <= tuning.liftZone;
169
+ const dwelling = forced || inLiftZone ? null : targetAt(given.filter((x) => x.arm === "dwell" && x.id !== armedId && wasOutside.has(x.id) && inZone(x, p) && live(x)), p);
170
+ let armedNow = false;
171
+ if (!dwelling || armedId !== null) armingId = null;
172
+ else {
173
+ if (armingId !== dwelling.id) {
174
+ armingId = dwelling.id;
175
+ armingSince = t;
176
+ }
177
+ if (t - armingSince >= tuning.armAfter) {
178
+ armedId = dwelling.id;
179
+ armingId = null;
180
+ armedNow = true;
181
+ }
182
+ }
183
+ const arming = armingId === null ? null : given.find((x) => x.id === armingId) ?? null;
184
+ const targets = acting(given);
185
+ const homeHolds = atHome;
186
+ const pickable = (x) => !homeHolds || x.arm === "dwell" && x.id === armedId;
187
+ const raw = targetAt(targets.filter((x) => pickable(x) && inZone(x, p) && (x.refuse === true || live(x))), p);
188
+ const disarmed = (x) => x?.arm === "dwell" && x.id !== armedId;
189
+ cur = disarmed(cur) ? null : follow(cur, targets);
190
+ shown = disarmed(shown) ? null : follow(shown, targets);
191
+ if (!live(cur)) cur = null;
192
+ const roomHeld = cur && cur.opensRoom === true && cur.roomHit && roomPlace !== null && same(cur, shown) && pickable(cur) && within(cur.bounds, p) && inRect(cur.roomHit, p) ? cur : null;
193
+ const refusedRaw = raw?.refuse === true && !roomHeld ? raw : null;
194
+ const bandOf = (held) => scaled(tuning.band, tuning.bandShare, [held, raw && !same(raw, held) ? raw : null]);
195
+ const pastBreakthrough = (x) => inZoneBy(x, p, negate(scaled(tuning.breakthrough, tuning.bandShare, [x])));
196
+ let next = refusedRaw ? null : raw;
197
+ if (!refusedRaw && cur && pickable(cur) && (roomHeld !== null || inZoneBy(cur, p, bandOf(cur)))) {
198
+ const breaks = raw !== null && raw.refuse !== true && !same(raw, cur) && raw.priority < cur.priority && (cur.free === true || pastBreakthrough(raw));
199
+ next = breaks ? raw : cur;
200
+ }
201
+ if (!refusedRaw && !next && cur && pickable(cur) && within(cur.bounds, p) && t - lastInside < tuning.gapGrace) next = cur;
202
+ if (next && (inZone(next, p) || same(next, roomHeld))) lastInside = t;
203
+ if (!same(next, cur)) curSince = t;
204
+ cur = next;
205
+ const aiming = !restart && (speed < tuning.aimSpeed || t - stillSince >= tuning.dwell);
206
+ restart = false;
207
+ const show = (s) => {
208
+ if (!same(s, shown)) shownSince = t;
209
+ shown = s;
210
+ };
211
+ const under = !!cur && (same(cur, roomHeld) || inZoneBy(cur, p, bandOf(cur)));
212
+ const ready = (x) => x.opensRoom !== true || x.arm === "dwell" || t - curSince >= (x.roomHold ?? tuning.roomAfter);
213
+ if (shown && !live(shown)) show(null);
214
+ if (!shown) {
215
+ if (cur && under && leftHome && aiming && ready(cur)) show(cur);
216
+ } else if (same(cur, shown)) {
217
+ if (!aiming && !under) show(null);
218
+ else shown = cur;
219
+ } else if (!cur || !aiming) {
220
+ show(null);
221
+ } else if (cur.priority < shown.priority && (shown.free === true || pastBreakthrough(cur)) || under && t - curSince >= tuning.switchHold) {
222
+ show(ready(cur) ? cur : null);
223
+ }
224
+ if (armedNow && cur?.id === armedId && under) show(cur);
225
+ if (forced) {
226
+ if (!same(forced.target, cur)) curSince = t;
227
+ cur = forced.target;
228
+ show(forced.target);
229
+ }
230
+ const at = shown ? placeAt(shown) : null;
231
+ if (at !== place) {
232
+ place = at;
233
+ placeSince = t;
234
+ }
235
+ if (!shown || shown.free) roomPlace = null;
236
+ else if (shown.opensRoom === true || shown.arm === "dwell") roomPlace = place;
237
+ else if (t - shownSince >= tuning.roomAfter && t - placeSince >= tuning.roomAfter) roomPlace = place;
238
+ else if (shownSince === t) roomPlace = null;
239
+ lastPlaces = places;
240
+ const refused = forced ? forced.refused : refusedRaw;
241
+ return { shown, room: roomPlace !== null, roomPlace, aiming, atHome: !forced && wentOut && homeHolds, arming, forced: forced?.kind ?? null, refused, landing: landAt(p, given, keys) };
242
+ }
243
+ return {
244
+ tuning,
245
+ get state() {
246
+ return { speed, current: cur, shown, leftHome };
247
+ },
248
+ update,
249
+ release(point, time, given, keys) {
250
+ const p = clampInto(point);
251
+ if (!lastPoint || lastPoint.x !== p.x || lastPoint.y !== p.y) update(p, time, given, keys);
252
+ return landAt(p, given, keys);
253
+ },
254
+ setBounds(next) {
255
+ bounds = next ? { ...next } : void 0;
256
+ },
257
+ hide(time) {
258
+ shown = null;
259
+ cur = null;
260
+ armedId = null;
261
+ armingId = null;
262
+ shownSince = time;
263
+ place = null;
264
+ roomPlace = null;
265
+ lastPlaces = /* @__PURE__ */ new Map();
266
+ samples = [];
267
+ anchor = null;
268
+ restart = true;
269
+ },
270
+ moveHome(dx, dy) {
271
+ home = { ...home, x: home.x + dx, y: home.y + dy };
272
+ }
273
+ };
274
+ }
275
+
276
+ // src/drag/guide-rects.ts
277
+ var MIN_BOX_LENGTH = 8;
278
+ var LINE_THICKNESS = 2;
279
+ var EPS = 1e-6;
280
+ function guideRects(guides, options) {
281
+ const inset = Number.isFinite(options.inset) ? Math.max(0, options.inset) : 2;
282
+ const min = Number.isFinite(options.minThickness) ? Math.max(0, options.minThickness) : 2;
283
+ const lineThickness = Number.isFinite(options.lineThickness) ? Math.max(0, options.lineThickness) : LINE_THICKNESS;
284
+ const minLength = Number.isFinite(options.minLength) ? Math.max(0, options.minLength) : MIN_BOX_LENGTH;
285
+ const same = (a, b) => Math.abs(a.x - b.x) < EPS && Math.abs(a.y - b.y) < EPS && Math.abs(a.width - b.width) < EPS && Math.abs(a.height - b.height) < EPS;
286
+ const place = (g, rect) => same(g.rect, rect) ? g : { ...g, rect };
287
+ const x0 = options.inside.x + inset;
288
+ const y0 = options.inside.y + inset;
289
+ const x1 = options.inside.x + options.inside.width - inset;
290
+ const y1 = options.inside.y + options.inside.height - inset;
291
+ const gap = Number.isFinite(options.clearance) ? Math.max(0, options.clearance) : 2;
292
+ const finite = (r) => Number.isFinite(r.x) && Number.isFinite(r.y) && Number.isFinite(r.width) && Number.isFinite(r.height);
293
+ const allClear = (options.clear ?? []).map(
294
+ (c) => "rect" in c ? { k: c.rect, gap: Number.isFinite(c.clearance) ? Math.max(0, c.clearance) : gap, ...c.kinds ? { kinds: c.kinds } : {} } : { k: c, gap }
295
+ ).filter((c) => finite(c.k));
296
+ const out = [];
297
+ for (const g of guides) {
298
+ const r = g.rect;
299
+ const clear = allClear.filter((c) => !c.kinds || c.kinds.includes(g.kind));
300
+ if (g.kind === "box") {
301
+ const box = { a: Math.max(r.x, x0), b: Math.max(r.y, y0), c: Math.min(r.x + r.width, x1), d: Math.min(r.y + r.height, y1) };
302
+ if (!(box.c - box.a > EPS) || !(box.d - box.b > EPS)) continue;
303
+ const w = box.c - box.a;
304
+ const h = box.d - box.b;
305
+ const alongX = w > h || w === h && g.axis !== "y";
306
+ const s02 = alongX ? box.a : box.b;
307
+ const s12 = alongX ? box.c : box.d;
308
+ const t0 = alongX ? box.b : box.a;
309
+ const t1 = alongX ? box.d : box.c;
310
+ const toBox = (p0, p1, q0, q1) => alongX ? { a: p0, b: q0, c: p1, d: q1 } : { a: q0, b: p0, c: q1, d: p1 };
311
+ const over = clear.map(({ k: k2, gap: gap2 }) => ({
312
+ x0: k2.x - gap2,
313
+ x1: k2.x + k2.width + gap2,
314
+ y0: k2.y - gap2,
315
+ y1: k2.y + k2.height + gap2,
316
+ s0: (alongX ? k2.x : k2.y) - gap2,
317
+ s1: (alongX ? k2.x + k2.width : k2.y + k2.height) + gap2,
318
+ t0: (alongX ? k2.y : k2.x) - gap2,
319
+ t1: (alongX ? k2.y + k2.height : k2.x + k2.width) + gap2
320
+ })).filter((k2) => k2.s1 > s02 + EPS && k2.s0 < s12 - EPS && k2.t1 > t0 + EPS && k2.t0 < t1 - EPS);
321
+ let v0 = t0;
322
+ let v1 = t1;
323
+ const half = (t1 - t0) / 2 + EPS;
324
+ for (const k2 of over) {
325
+ if (k2.t0 <= t0 + EPS && k2.t1 >= t1 - EPS) continue;
326
+ const along = Math.min(k2.s1, s12) - Math.max(k2.s0, s02);
327
+ if (k2.t0 <= t0 + EPS) {
328
+ if (k2.t1 - t0 < along - EPS && k2.t1 - t0 <= half) v0 = Math.max(v0, k2.t1);
329
+ } else if (k2.t1 >= t1 - EPS) {
330
+ if (t1 - k2.t0 < along - EPS && t1 - k2.t0 <= half) v1 = Math.min(v1, k2.t0);
331
+ }
332
+ }
333
+ if ((v0 > t0 || v1 < t1) && v1 - v0 < Math.max(EPS, min)) continue;
334
+ const rest = over.filter((k2) => k2.t1 > v0 + EPS && k2.t0 < v1 - EPS);
335
+ const kept = toBox(s02, s12, v0, v1);
336
+ const full = rest.filter((k2) => k2.t0 <= v0 + EPS && k2.t1 >= v1 - EPS).map((k2) => [Math.max(k2.s0, s02), Math.min(k2.s1, s12)]).sort((p, q) => p[0] - q[0] || p[1] - q[1]);
337
+ const cuts = [];
338
+ for (const [lo2, hi2] of full) {
339
+ const last = cuts[cuts.length - 1];
340
+ if (last && lo2 <= last[1] + EPS) last[1] = Math.max(last[1], hi2);
341
+ else cuts.push([lo2, hi2]);
342
+ }
343
+ const spans = [];
344
+ let at = s02;
345
+ let k = 0;
346
+ for (const [lo2, hi2] of cuts) {
347
+ if (lo2 - at > EPS) spans.push({ lo: at, hi: lo2, k });
348
+ if (lo2 > s02 + EPS && hi2 < s12 - EPS) k++;
349
+ at = hi2;
350
+ }
351
+ if (s12 - at > EPS) spans.push({ lo: at, hi: s12, k });
352
+ const corners = rest.filter((k2) => !(k2.t0 <= v0 + EPS && k2.t1 >= v1 - EPS)).sort((p, q) => p.s0 - q.s0 || p.s1 - q.s1 || p.t0 - q.t0 || p.t1 - q.t1);
353
+ const longEnough = Math.max(EPS, minLength - EPS);
354
+ for (const span of spans) {
355
+ let p = toBox(span.lo, span.hi, v0, v1);
356
+ for (const k2 of corners) {
357
+ const { a, b, c, d } = p;
358
+ if (k2.x1 <= a + EPS || k2.x0 >= c - EPS || k2.y1 <= b + EPS || k2.y0 >= d - EPS) continue;
359
+ const cut = [
360
+ { a, b, c: Math.min(c, k2.x0), d },
361
+ { a: Math.max(a, k2.x1), b, c, d },
362
+ { a, b, c, d: Math.min(d, k2.y0) },
363
+ { a, b: Math.max(b, k2.y1), c, d }
364
+ ].filter((q) => q.c - q.a > EPS && q.d - q.b > EPS);
365
+ p = cut.length === 0 ? null : cut.reduce((q, s) => (s.c - s.a) * (s.d - s.b) > (q.c - q.a) * (q.d - q.b) ? s : q);
366
+ if (!p) break;
367
+ }
368
+ if (!p) continue;
369
+ const touched = Math.abs(p.a - kept.a) > EPS || Math.abs(p.b - kept.b) > EPS || Math.abs(p.c - kept.c) > EPS || Math.abs(p.d - kept.d) > EPS;
370
+ if (touched && (alongX ? p.c - p.a : p.d - p.b) < longEnough) continue;
371
+ const placed = place(g, { x: p.a, y: p.b, width: p.c - p.a, height: p.d - p.b });
372
+ const id = g.id;
373
+ out.push(span.k === 0 || typeof id !== "string" ? placed : { ...placed, id: `${id}#${span.k + 1}` });
374
+ }
375
+ continue;
376
+ }
377
+ const thinX = r.width <= r.height;
378
+ const own = thinX ? r.width : r.height;
379
+ const widen = g.kind === "line" && own < lineThickness;
380
+ const t = widen ? lineThickness : own;
381
+ let lo = (thinX ? r.x : r.y) - (widen ? (lineThickness - own) / 2 : 0);
382
+ const lim0 = thinX ? x0 : y0;
383
+ const lim1 = thinX ? x1 : y1;
384
+ if (lo + t > lim1) lo = lim1 - t;
385
+ if (lo < lim0) lo = lim0;
386
+ let hi = Math.min(lo + t, lim1);
387
+ const l0 = Math.max(thinX ? r.y : r.x, thinX ? y0 : x0);
388
+ const l1 = Math.min(thinX ? r.y + r.height : r.x + r.width, thinX ? y1 : x1);
389
+ if (l1 - l0 <= EPS) continue;
390
+ const around = clear.map(({ k: c, gap: gap2 }) => ({
391
+ a: (thinX ? c.y : c.x) - gap2,
392
+ b: (thinX ? c.y + c.height : c.x + c.width) + gap2,
393
+ c0: (thinX ? c.x : c.y) - gap2,
394
+ c1: (thinX ? c.x + c.width : c.y + c.height) + gap2
395
+ }));
396
+ let s0 = l0;
397
+ let s1 = l1;
398
+ let shortened = false;
399
+ for (const k of around) {
400
+ if (k.b <= l0 + EPS || k.a >= l1 - EPS || k.c1 <= lo + EPS || k.c0 >= hi - EPS) continue;
401
+ const atStart = k.a <= l0 + EPS;
402
+ const atEnd = k.b >= l1 - EPS;
403
+ if (atStart === atEnd) continue;
404
+ if (atStart) s0 = Math.max(s0, k.b);
405
+ else s1 = Math.min(s1, k.a);
406
+ shortened = true;
407
+ }
408
+ if (s1 - s0 <= EPS || shortened && s1 - s0 < Math.max(EPS, minLength - EPS)) continue;
409
+ for (const k of around) {
410
+ if (k.b <= s0 + EPS || k.a >= s1 - EPS || k.c1 <= lo + EPS || k.c0 >= hi - EPS) continue;
411
+ if (k.a <= l0 + EPS !== k.b >= l1 - EPS) continue;
412
+ if ((k.c0 + k.c1) / 2 >= (lo + hi) / 2) hi = Math.min(hi, k.c0);
413
+ else lo = Math.max(lo, k.c1);
414
+ }
415
+ if (hi - lo < Math.max(EPS, min)) continue;
416
+ out.push(place(g, thinX ? { x: lo, y: s0, width: hi - lo, height: s1 - s0 } : { x: s0, y: lo, width: s1 - s0, height: hi - lo }));
417
+ }
418
+ return out;
419
+ }
420
+
421
+ // src/drag/hand-speed.ts
422
+ var HAND_SLOW_STEP = 3;
423
+ var HAND_SPEED = { span: 48, steps: 5, gap: 40, slowStep: HAND_SLOW_STEP, accelerating: 1.5, gathering: 1.25 };
424
+ function createHandSpeed(options = {}) {
425
+ const o = { ...HAND_SPEED, ...options };
426
+ let samples = [];
427
+ let step = Infinity;
428
+ let long = null;
429
+ let longs = [];
430
+ return {
431
+ push(p, t) {
432
+ const last = samples[samples.length - 1];
433
+ if (last && t - last.t >= o.gap) {
434
+ const d = Math.hypot(p.x - last.p.x, p.y - last.p.y);
435
+ samples = [{ p, t }];
436
+ step = d <= o.slowStep ? d / Math.max(1, t - last.t) : Infinity;
437
+ long = null;
438
+ longs = [];
439
+ return;
440
+ }
441
+ step = last ? Math.hypot(p.x - last.p.x, p.y - last.p.y) / Math.max(1, t - last.t) : Infinity;
442
+ samples.push({ p, t });
443
+ while (samples.length > o.steps + 1 && t - samples[1].t >= o.span) samples.shift();
444
+ const first = samples[0];
445
+ if (samples.length > o.steps && t - first.t >= o.span) {
446
+ let path = 0;
447
+ for (let i = 1; i < samples.length; i++) path += Math.hypot(samples[i].p.x - samples[i - 1].p.x, samples[i].p.y - samples[i - 1].p.y);
448
+ long = path / (t - first.t);
449
+ longs.push({ t, v: long });
450
+ while (longs.length > 1 && t - longs[1].t >= o.span / 2) longs.shift();
451
+ } else long = null;
452
+ },
453
+ reset() {
454
+ samples = [];
455
+ step = Infinity;
456
+ long = null;
457
+ longs = [];
458
+ },
459
+ get step() {
460
+ return step;
461
+ },
462
+ get long() {
463
+ return long;
464
+ },
465
+ get speed() {
466
+ return long === null ? step : Math.max(step, long);
467
+ },
468
+ get steady() {
469
+ const then = longs[0];
470
+ return long !== null && step <= long * o.accelerating && !!then && longs[longs.length - 1].t - then.t >= o.span / 2 && long <= then.v * o.gathering;
471
+ }
472
+ };
473
+ }
474
+
475
+ // src/drag/landing.ts
476
+ var SLIDE_STEP = 1;
477
+ var SNAP_DISTANCE = 8;
478
+ var LANDING_MARGINS = { exit: 12, spot: 6, edge: 48, lift: 16 };
479
+ var LANDING_TOUCH_MARGINS = { exit: 16, spot: 8, edge: 48, lift: 16 };
480
+ var LANDING_GATES = { path: 40, depth: 8, stillSpeed: 0.1875, stepSpeed: 0.375, trail: 40, rest: 22, pause: 60, slideSpeed: 2 };
481
+ var LANDING_APPROACH = { reach: LANDING_MARGINS.exit, keep: LANDING_MARGINS.exit, nearer: 16 };
482
+ var inside = (r, p, grow = 0) => p.x >= r.x - grow && p.x <= r.x + r.width + grow && p.y >= r.y - grow && p.y <= r.y + r.height + grow;
483
+ var strictlyIn = (r, p) => p.x >= r.x && p.x <= r.x + r.width && p.y >= r.y && p.y <= r.y + r.height;
484
+ function depthIn(lane, p, stage) {
485
+ const r = lane.rect;
486
+ if (!strictlyIn(r, p)) return 0;
487
+ const on = (a, b) => Math.abs(a - b) < 1;
488
+ const sides = lane.axis === "x" ? [on(r.y, stage.y) ? Infinity : p.y - r.y, on(r.y + r.height, stage.y + stage.height) ? Infinity : r.y + r.height - p.y] : [on(r.x, stage.x) ? Infinity : p.x - r.x, on(r.x + r.width, stage.x + stage.width) ? Infinity : r.x + r.width - p.x];
489
+ return Math.max(0, Math.min(...sides));
490
+ }
491
+ var distanceTo2 = (r, p) => Math.hypot(Math.max(r.x - p.x, 0, p.x - (r.x + r.width)), Math.max(r.y - p.y, 0, p.y - (r.y + r.height)));
492
+ var alongOf = (lane, p) => lane.axis === "x" ? p.x : p.y;
493
+ var acrossOf = (lane, p) => lane.axis === "x" ? p.y : p.x;
494
+ var touches = (a, b) => a.x <= b.x + b.width + 1 && b.x <= a.x + a.width + 1 && a.y <= b.y + b.height + 1 && b.y <= a.y + a.height + 1;
495
+ function ontoStage(stage, p, reach) {
496
+ if (!inside(stage, p, reach)) return null;
497
+ return { x: Math.min(Math.max(p.x, stage.x), stage.x + stage.width), y: Math.min(Math.max(p.y, stage.y), stage.y + stage.height) };
498
+ }
499
+ function createLandingModel(options) {
500
+ const margins = { ...LANDING_MARGINS, ...options.margins };
501
+ const gates = { ...LANDING_GATES, ...options.gates };
502
+ const approach = { ...LANDING_APPROACH, ...options.approach };
503
+ const guidesLevel = options.placeGuides ?? "off";
504
+ let base = options.regions;
505
+ let regionsFor = options.regionsFor;
506
+ const cache = /* @__PURE__ */ new Map();
507
+ const heldRegions = (spot) => {
508
+ if (!spot || !regionsFor) return base;
509
+ if (!cache.has(spot)) cache.set(spot, regionsFor(spot));
510
+ return cache.get(spot) ?? base;
511
+ };
512
+ let laneId = options.home?.lane ?? null;
513
+ let spotId = options.home?.spot ?? null;
514
+ let last = null;
515
+ let moved = null;
516
+ let liftAt = options.lift ?? null;
517
+ let inLiftZone = true;
518
+ let farHeld = false;
519
+ let flung = false;
520
+ let slowFrom = null;
521
+ let lastStep = 0;
522
+ const hand = createHandSpeed({ gap: Math.min(HAND_SPEED.gap, gates.pause) });
523
+ let lastKeys;
524
+ const pathIn = /* @__PURE__ */ new Map();
525
+ const slide = /* @__PURE__ */ new Map();
526
+ const cameIn = /* @__PURE__ */ new Set();
527
+ let approached = null;
528
+ let lastPending = null;
529
+ const pendingIn = (here, p, stage) => {
530
+ const deepest = here.reduce((a, b) => depthIn(b, p, stage) > depthIn(a, p, stage) ? b : a);
531
+ const kept = here.find((l) => l.id === lastPending);
532
+ return kept && depthIn(deepest, p, stage) <= depthIn(kept, p, stage) + margins.spot ? kept.id : deepest.id;
533
+ };
534
+ let previous = laneId ? "lane" : "open";
535
+ let frame = { region: previous, lane: laneId, spot: spotId, landing: null, room: !!spotId, guides: [], shift: false };
536
+ let landedOn = null;
537
+ const laneIn = (regions, id) => id ? regions.lanes.find((l) => l.id === id) : void 0;
538
+ const spotIn = (lane, id) => lane && id ? lane.spots.find((s) => s.id === id) : void 0;
539
+ function pick(lane, a) {
540
+ if (lane.refused.some((r) => a >= r.along[0] && a <= r.along[1])) return null;
541
+ const hit = lane.spots.find((s) => a >= s.along[0] && a <= s.along[1]);
542
+ if (hit) return hit;
543
+ let best = null;
544
+ let dist = Infinity;
545
+ for (const s of lane.spots) {
546
+ const d = a < s.along[0] ? s.along[0] - a : a - s.along[1];
547
+ if (d < dist) {
548
+ best = s;
549
+ dist = d;
550
+ }
551
+ }
552
+ return best;
553
+ }
554
+ function landingAt(lane, spot, p, item) {
555
+ const s = spot.slide;
556
+ if (!s) return spot.landing;
557
+ const ax = lane.axis;
558
+ const long = item.width >= item.height ? "x" : "y";
559
+ const size = long === "x" ? item.width : item.height;
560
+ const g = options.grab ? long === "x" ? options.grab.x : options.grab.y : size / 2;
561
+ const share = ax === long && size > 0 && Number.isFinite(g) ? Math.min(1, Math.max(0, g / size)) : 0.5;
562
+ const length = ax === "x" ? spot.landing.width : spot.landing.height;
563
+ const lo = Math.min(s.from, s.to);
564
+ const hi = Math.max(s.from, s.to);
565
+ const free = Math.min(hi, Math.max(lo, alongOf(lane, p) - share * length));
566
+ const reach = s.snapDistance ?? SNAP_DISTANCE;
567
+ let at = free;
568
+ let best = Infinity;
569
+ for (const q of s.snaps) {
570
+ const d = Math.abs(q - free);
571
+ if (d <= reach && d < best) {
572
+ best = d;
573
+ at = q;
574
+ }
575
+ }
576
+ const step = s.step ?? SLIDE_STEP;
577
+ if (best === Infinity && step > 0) at = Math.min(hi, Math.max(lo, Math.round(free / step) * step));
578
+ return ax === "x" ? { ...spot.landing, x: at } : { ...spot.landing, y: at };
579
+ }
580
+ function along(lane, p, step) {
581
+ const regions = heldRegions(spotId);
582
+ const held = laneIn(regions, lane.id) ?? lane;
583
+ const a = alongOf(held, p);
584
+ const now = spotIn(held, spotId);
585
+ const cand = pick(held, a);
586
+ if (!cand) return null;
587
+ if (!now || cand.id === now.id) return cand;
588
+ const past = a < now.along[0] - margins.spot || a > now.along[1] + margins.spot;
589
+ const reflows = now.others === void 0 || now.others !== cand.others;
590
+ if (!past) return now;
591
+ if (reflows && step > gates.stepSpeed && distanceTo2(now.landing, p) <= gates.trail) return now;
592
+ if (regionsFor && reflows) {
593
+ const theirs = heldRegions(cand.id);
594
+ const lane2 = laneIn(theirs, lane.id);
595
+ if (lane2 && pick(lane2, alongOf(lane2, p))?.id !== cand.id) return now;
596
+ }
597
+ return cand;
598
+ }
599
+ function guidesFor(p, region, shift, pending, landing) {
600
+ if (guidesLevel === "off" || shift) return [];
601
+ const regions = heldRegions(spotId);
602
+ const all = (l, near2 = false) => {
603
+ if (near2 && l.entry) return view(l, true);
604
+ return l.marks ? l.marks.map((m, i) => ({ id: m.id ?? `${l.id}#${i}`, lane: l.id, kind: m.kind, rect: m.rect })) : view(l);
605
+ };
606
+ function view(l, near2 = false) {
607
+ const marks = near2 && l.entry ? l.entry : l.marks;
608
+ if (!marks) return l.spots.map((s) => ({ id: `${l.id}/${s.id}`, lane: l.id, kind: "box", rect: s.landing }));
609
+ const box = l.rect;
610
+ return marks.flatMap((m, i) => {
611
+ const left = Math.max(m.rect.x, box.x);
612
+ const top = Math.max(m.rect.y, box.y);
613
+ const width = Math.min(m.rect.x + m.rect.width, box.x + box.width) - left;
614
+ const height = Math.min(m.rect.y + m.rect.height, box.y + box.height) - top;
615
+ const kept2 = width > m.rect.width - 1e-6 && height > m.rect.height - 1e-6;
616
+ if (!kept2 && (m.kind === "line" || width <= 1e-6 || height <= 1e-6)) return [];
617
+ return [{ id: m.id ?? `${l.id}#${i}`, lane: l.id, kind: m.kind, rect: kept2 ? m.rect : { x: left, y: top, width, height } }];
618
+ });
619
+ }
620
+ const area2 = (a, c) => Math.min(a.x + a.width, c.x + c.width) - Math.max(a.x, c.x) > 1e-6 && Math.min(a.y + a.height, c.y + c.height) - Math.max(a.y, c.y) > 1e-6;
621
+ const drawn = (g) => {
622
+ const r = g.rect;
623
+ const vertical = r.width <= r.height;
624
+ const own = vertical ? r.width : r.height;
625
+ if (g.kind !== "line" || own >= LINE_THICKNESS) return r;
626
+ const d = (LINE_THICKNESS - own) / 2;
627
+ return vertical ? { x: r.x - d, y: r.y, width: LINE_THICKNESS, height: r.height } : { x: r.x, y: r.y - d, width: r.width, height: LINE_THICKNESS };
628
+ };
629
+ const less = (gs, cs, thick = false) => {
630
+ if (cs.length === 0) return [...gs];
631
+ const clear = cs.map((rect) => ({ rect, clearance: 0 }));
632
+ return gs.flatMap((g) => cs.some((c) => area2(thick ? drawn(g) : g.rect, c)) ? guideRects([g], { inside: g.rect, inset: 0, clear, minLength: 0, minThickness: 0 }) : [g]);
633
+ };
634
+ const near = nearLane(p, region, pending, regions);
635
+ const wouldLand = (l) => {
636
+ if (l.id === laneId) return region === "lane" ? landing : null;
637
+ const s = pick(l, alongOf(l, p));
638
+ return s ? landingAt(l, s, p, regions.item) : null;
639
+ };
640
+ const nearGuides = (l) => {
641
+ const at2 = l.marks || l.entry ? wouldLand(l) : null;
642
+ if (!at2) return all(l, true);
643
+ const longEnough = (g) => g.kind !== "box" || (l.axis === "x" ? g.rect.width : g.rect.height) > MIN_BOX_LENGTH;
644
+ const whole = all(l, true);
645
+ return less(whole, [at2]).filter((g) => longEnough(g) || whole.some((w) => w.id === g.id && w.rect === g.rect));
646
+ };
647
+ if (guidesLevel === "near") return near ? nearGuides(near) : [];
648
+ const owns = (l) => !!l && !!l.entry && !!l.corners?.length;
649
+ let owner = owns(near) ? near : null;
650
+ if (!owner && !near) {
651
+ let d = approach.reach;
652
+ for (const l of regions.lanes) {
653
+ const dl = distanceTo2(l.rect, p);
654
+ if (owns(l) && dl <= d) {
655
+ owner = l;
656
+ d = dl;
657
+ }
658
+ }
659
+ }
660
+ const ownerMarks = owner ? nearGuides(owner) : [];
661
+ const cutBy = ownerMarks.map(drawn);
662
+ const takes = (l) => {
663
+ const across = (r) => l.axis === "x" ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
664
+ return view(l).every((g) => {
665
+ const mine = drawn(g);
666
+ return cutBy.every((c) => !area2(mine, c) || across(c)[0] <= across(mine)[0] + 1e-6 && across(c)[1] >= across(mine)[1] - 1e-6);
667
+ });
668
+ };
669
+ const named = owner ? owner.corners.map((id) => regions.lanes.find((x) => x.id === id)).filter((x) => !!x) : [];
670
+ const handed = new Set(named.filter(takes).map((x) => x.id));
671
+ const kept = named.filter((x) => !handed.has(x.id)).flatMap((x) => view(x).map(drawn));
672
+ const at = owner && (owner.marks || owner.entry) ? wouldLand(owner) : null;
673
+ const without = (gs, r) => gs.flatMap((g) => {
674
+ if (!r || !area2(drawn(g), r)) return [g];
675
+ const a = g.rect;
676
+ if (g.kind === "line") {
677
+ const vertical = a.width <= a.height;
678
+ const from = vertical ? a.y : a.x;
679
+ const to = from + (vertical ? a.height : a.width);
680
+ const c0 = vertical ? r.y : r.x;
681
+ const c1 = c0 + (vertical ? r.height : r.width);
682
+ const spans = [];
683
+ if (c0 > from + 1e-6) spans.push([from, Math.min(to, c0)]);
684
+ if (c1 < to - 1e-6) spans.push([Math.max(from, c1), to]);
685
+ return spans.map(([s, e], k) => ({ ...g, id: k ? `${g.id}~l${k}` : g.id, rect: vertical ? { x: a.x, y: s, width: a.width, height: e - s } : { x: s, y: a.y, width: e - s, height: a.height } }));
686
+ }
687
+ const x0 = Math.max(a.x, r.x);
688
+ const x1 = Math.min(a.x + a.width, r.x + r.width);
689
+ const pieces = [];
690
+ if (r.x > a.x) pieces.push({ x: a.x, y: a.y, width: r.x - a.x, height: a.height });
691
+ if (r.x + r.width < a.x + a.width) pieces.push({ x: r.x + r.width, y: a.y, width: a.x + a.width - r.x - r.width, height: a.height });
692
+ if (r.y > a.y) pieces.push({ x: x0, y: a.y, width: x1 - x0, height: r.y - a.y });
693
+ if (r.y + r.height < a.y + a.height) pieces.push({ x: x0, y: r.y + r.height, width: x1 - x0, height: a.y + a.height - r.y - r.height });
694
+ return pieces.map((rect, k) => ({ ...g, id: k ? `${g.id}~l${k}` : g.id, rect }));
695
+ });
696
+ return regions.lanes.flatMap((l) => {
697
+ if (owner && l.id === owner.id) return less(ownerMarks, kept, true);
698
+ if (near && l.id === near.id) return nearGuides(l);
699
+ if (!named.some((x) => x.id === l.id)) return all(l);
700
+ return without(handed.has(l.id) ? less(view(l), cutBy, true) : all(l), at);
701
+ });
702
+ }
703
+ function nearLane(p, region, pending, regions) {
704
+ if ((region === "lane" || region === "refused") && laneId) {
705
+ approached = laneId;
706
+ return laneIn(regions, laneId) ?? null;
707
+ }
708
+ if (pending) {
709
+ approached = pending;
710
+ return laneIn(regions, pending) ?? null;
711
+ }
712
+ if (region !== "open") {
713
+ approached = null;
714
+ return null;
715
+ }
716
+ let best = null;
717
+ let bestD = Infinity;
718
+ for (const l of regions.lanes) {
719
+ const d = distanceTo2(l.rect, p);
720
+ if (d < bestD) {
721
+ best = l;
722
+ bestD = d;
723
+ }
724
+ }
725
+ const acquire = Math.max(0, approach.reach - margins.spot, approach.reach / 2);
726
+ const kept = laneIn(regions, approached);
727
+ if (kept) {
728
+ const d = distanceTo2(kept.rect, p);
729
+ if (d > Math.max(approach.keep, approach.reach)) approached = null;
730
+ else if (best && best.id !== kept.id && bestD + approach.nearer < d) approached = bestD <= acquire ? best.id : null;
731
+ } else approached = best && bestD <= acquire ? best.id : null;
732
+ return laneIn(regions, approached) ?? null;
733
+ }
734
+ function update(raw, t, keys) {
735
+ lastKeys = keys;
736
+ const p = ontoStage(heldRegions(spotId).stage, raw, margins.edge) ?? raw;
737
+ let step = 0;
738
+ if (moved && (raw.x !== moved.raw.x || raw.y !== moved.raw.y)) {
739
+ const before = moved.t;
740
+ step = Math.hypot(raw.x - moved.raw.x, raw.y - moved.raw.y) / Math.max(1, t - moved.t);
741
+ moved = { raw, t };
742
+ hand.push(raw, t);
743
+ step = hand.step;
744
+ lastStep = step;
745
+ const sp = hand.speed;
746
+ if (Number.isFinite(sp) && sp > gates.slideSpeed) {
747
+ flung = true;
748
+ slowFrom = null;
749
+ } else if (!Number.isFinite(sp) || sp > gates.stepSpeed) slowFrom = null;
750
+ else slowFrom ??= before;
751
+ } else if (moved) {
752
+ const stage = heldRegions(spotId).stage;
753
+ const onEdge = p.x <= stage.x || p.y <= stage.y || p.x >= stage.x + stage.width || p.y >= stage.y + stage.height;
754
+ const since = t - moved.t;
755
+ step = since >= gates.pause || since >= gates.rest && (lastStep <= gates.stepSpeed || onEdge) ? 0 : lastStep;
756
+ slowFrom ??= moved.t;
757
+ } else {
758
+ moved = { raw, t };
759
+ hand.reset();
760
+ hand.push(raw, t);
761
+ liftAt ??= p;
762
+ step = lastStep = Infinity;
763
+ }
764
+ if (flung && slowFrom !== null && t - slowFrom >= gates.pause) flung = false;
765
+ const edgeStage = heldRegions(spotId).stage;
766
+ const settled = !flung || p.x <= edgeStage.x || p.y <= edgeStage.y || p.x >= edgeStage.x + edgeStage.width || p.y >= edgeStage.y + edgeStage.height;
767
+ const from = last?.p ?? null;
768
+ const fromRaw = last?.raw ?? null;
769
+ last = { p, raw, t };
770
+ const shift = !!keys?.shift;
771
+ const regions = heldRegions(spotId);
772
+ const slow = Number.isFinite(hand.speed) ? hand.speed <= gates.stepSpeed : step <= gates.stepSpeed;
773
+ for (const l of regions.lanes) {
774
+ const was = from && strictlyIn(l.rect, from);
775
+ const go = was ? Math.abs(alongOf(l, p) - alongOf(l, from)) : 0;
776
+ const over = was && fromRaw ? Math.abs(acrossOf(l, raw) - acrossOf(l, fromRaw)) : 0;
777
+ const inL = strictlyIn(l.rect, p);
778
+ pathIn.set(l.id, inL ? (pathIn.get(l.id) ?? 0) + (slow ? go : 0) : 0);
779
+ const s = slide.get(l.id);
780
+ const counts = hand.steady && hand.speed <= gates.slideSpeed;
781
+ slide.set(l.id, !inL ? { along: 0, across: 0 } : counts ? { along: (s?.along ?? 0) + go, across: (s?.across ?? 0) + over } : s ?? { along: 0, across: 0 });
782
+ if (l.owns && !inL) cameIn.add(l.id);
783
+ }
784
+ let region;
785
+ let pending = null;
786
+ if (!inside(regions.stage, p)) {
787
+ region = "nowhere";
788
+ laneId = spotId = null;
789
+ } else {
790
+ const held = laneIn(regions, laneId);
791
+ const gate = (l) => (pathIn.get(l.id) ?? 0) >= gates.path || depthIn(l, p, regions.stage) >= gates.depth && step <= gates.stillSpeed && settled;
792
+ const touching = held ? regions.lanes.find((l) => l.id !== held.id && strictlyIn(l.rect, p) && touches(l.rect, held.rect) && !inside(held.rect, p, margins.exit)) : void 0;
793
+ const sl = touching ? slide.get(touching.id) : void 0;
794
+ const slid = !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along && hand.speed <= gates.slideSpeed;
795
+ const liftR = margins.lift ?? 16;
796
+ if (liftAt) {
797
+ const far = Math.hypot(p.x - liftAt.x, p.y - liftAt.y);
798
+ inLiftZone = far <= (inLiftZone ? liftR : Math.max(0, liftR - margins.spot));
799
+ }
800
+ const nearLift = !!liftAt && inLiftZone;
801
+ const owner = nearLift ? void 0 : regions.lanes.find((l) => l.owns && l.id !== held?.id && cameIn.has(l.id) && strictlyIn(l.rect, p) && gate(l));
802
+ const ownLane = nearLift && options.home ? laneIn(regions, options.home.lane) : void 0;
803
+ const homeHere = ownLane && strictlyIn(ownLane.rect, p) ? ownLane : void 0;
804
+ const lanesHere = regions.lanes.filter((l) => strictlyIn(l.rect, p) && !(l.owns && nearLift));
805
+ const within2 = (b, l) => b.x >= l.rect.x - 1 && b.y >= l.rect.y - 1 && b.x + b.width <= l.rect.x + l.rect.width + 1 && b.y + b.height <= l.rect.y + l.rect.height + 1;
806
+ const overRefused = (l) => Number.isFinite(step) && step <= gates.stepSpeed && settled && lanesHere.length === 1 && [...regions.blocked, ...regions.refused].some((b) => strictlyIn(b, p) && !within2(b, l));
807
+ const next = homeHere ? void 0 : owner ?? (touching && (gate(touching) || slid || overRefused(touching)) ? touching : void 0);
808
+ if (!(held && !homeHere && !next && (touching || inside(held.rect, p, margins.exit)))) farHeld = false;
809
+ if (homeHere) {
810
+ const s = spotIn(homeHere, options.home.spot) ?? pick(homeHere, alongOf(homeHere, p));
811
+ laneId = homeHere.id;
812
+ spotId = s?.id ?? null;
813
+ region = s ? "lane" : "refused";
814
+ } else if (held && !next && (touching || inside(held.rect, p, margins.exit))) {
815
+ const d = distanceTo2(held.rect, p);
816
+ farHeld = farHeld ? d > margins.exit + gates.path - margins.spot : d > margins.exit + gates.path;
817
+ const far = farHeld;
818
+ const s = far ? null : along(held, p, step);
819
+ spotId = s?.id ?? spotId;
820
+ region = s ? "lane" : "refused";
821
+ if (!s) spotId = null;
822
+ if (!s && !far && !strictlyIn(held.rect, p)) {
823
+ const others = regions.lanes.filter((l) => l.id !== held.id && strictlyIn(l.rect, p));
824
+ if (others.length > 0) pending = pendingIn(others, p, regions.stage);
825
+ }
826
+ } else {
827
+ laneId = spotId = null;
828
+ let entered = next ?? null;
829
+ if (!entered)
830
+ for (const l of lanesHere) {
831
+ const deep = depthIn(l, p, regions.stage);
832
+ if ((gate(l) || overRefused(l)) && (!entered || deep > depthIn(entered, p, regions.stage))) entered = l;
833
+ }
834
+ if (!entered && lanesHere.length > 0) pending = pendingIn(lanesHere, p, regions.stage);
835
+ if (entered) {
836
+ laneId = entered.id;
837
+ const s = pick(entered, alongOf(entered, p));
838
+ spotId = s?.id ?? null;
839
+ region = s ? "lane" : "refused";
840
+ } else if (regions.refused.some((r) => inside(r, p))) region = "refused";
841
+ else if (inside(regions.content, p) && !regions.blocked.some((b) => strictlyIn(b, p))) region = "open";
842
+ else if (regions.lanes.some((l) => strictlyIn(l.rect, p))) region = previous === "lane" ? "open" : previous;
843
+ else region = "refused";
844
+ }
845
+ }
846
+ previous = region;
847
+ lastPending = pending;
848
+ const shown = shift && (region === "lane" || region === "open") ? "open" : region;
849
+ const r2 = heldRegions(spotId);
850
+ const heldLane = laneIn(r2, laneId);
851
+ const spot = spotIn(heldLane, spotId);
852
+ landedOn = shown === "lane" && spot && heldLane ? { spot, axis: heldLane.axis } : null;
853
+ const landing = shown === "lane" ? spot && heldLane ? landingAt(heldLane, spot, p, r2.item) : null : shown === "open" ? options.floatLanding?.(p) ?? null : null;
854
+ frame = {
855
+ region: shown,
856
+ lane: laneId,
857
+ spot: shown === "lane" ? spotId : null,
858
+ landing,
859
+ room: shown === "lane" && !!spot,
860
+ guides: guidesFor(p, shown, shift, pending && shown !== "lane" ? pending : null, landing),
861
+ shift,
862
+ ...pending && shown !== "lane" ? { pending } : {}
863
+ };
864
+ return frame;
865
+ }
866
+ return {
867
+ update,
868
+ release(point, time, keys) {
869
+ if (!last || last.raw.x !== point.x || last.raw.y !== point.y) update(point, time, keys ?? lastKeys);
870
+ if (frame.region === "lane" && frame.lane && frame.spot) {
871
+ const ownSpot = !!options.home && options.home.spot === frame.spot && options.home.lane === frame.lane;
872
+ const on = landedOn;
873
+ if (on?.spot.slide && frame.landing) {
874
+ const start = (r) => on.axis === "x" ? r.x : r.y;
875
+ const at = start(frame.landing);
876
+ return { kind: "spot", lane: frame.lane, spot: frame.spot, home: ownSpot && Math.abs(at - start(on.spot.landing)) < 1e-6, at };
877
+ }
878
+ return { kind: "spot", lane: frame.lane, spot: frame.spot, home: ownSpot };
879
+ }
880
+ if (frame.region === "open" && frame.landing) return { kind: "float", rect: frame.landing };
881
+ return null;
882
+ },
883
+ setRegions(regions, nextRegionsFor) {
884
+ base = regions;
885
+ if (nextRegionsFor) regionsFor = nextRegionsFor;
886
+ cache.clear();
887
+ const l = laneIn(base, laneId);
888
+ if (laneId && !l) laneId = spotId = null;
889
+ else if (l && spotId && !spotIn(l, spotId) && last) spotId = pick(l, alongOf(l, last.p))?.id ?? null;
890
+ },
891
+ hide() {
892
+ laneId = spotId = null;
893
+ approached = null;
894
+ lastPending = null;
895
+ farHeld = false;
896
+ flung = false;
897
+ slowFrom = null;
898
+ pathIn.clear();
899
+ slide.clear();
900
+ cameIn.clear();
901
+ last = moved = null;
902
+ lastStep = 0;
903
+ },
904
+ get frame() {
905
+ return frame;
906
+ }
907
+ };
908
+ }
909
+
910
+ // src/drag/preview.ts
911
+ var DRAG_PREVIEW_DEFAULT = { mode: "glide" };
912
+ var PLACE_GUIDES_DEFAULT = { outline: "off", placeholder: "near", glide: "off", snap: "near" };
913
+ function previewPlan(frame, preview, slotted) {
914
+ const p = typeof preview === "string" ? { mode: preview } : preview;
915
+ const landing = "region" in frame;
916
+ const shown = landing ? frame.landing !== null : !!frame.shown;
917
+ const slots = slotted ?? (landing ? frame.region === "lane" : !!frame.shown && !frame.shown.free);
918
+ const plan = planOf(p.mode, shown, frame.room, slots);
919
+ const drawn = plan.showIndicator || plan.makeRoom || plan.snapItem;
920
+ return { ...plan, guides: drawn ? "off" : p.placeGuides ?? PLACE_GUIDES_DEFAULT[p.mode] };
921
+ }
922
+ function planOf(mode, shown, room, slotted) {
923
+ if (mode === "outline") return { showIndicator: shown, makeRoom: false, snapItem: false };
924
+ if (mode === "placeholder") return { showIndicator: shown, makeRoom: room, snapItem: false };
925
+ if (mode === "snap") return { showIndicator: false, makeRoom: room, snapItem: room && shown && slotted };
926
+ return { showIndicator: shown && !slotted, makeRoom: room, snapItem: room && shown && slotted };
927
+ }
928
+
929
+ // src/drag/grip.ts
930
+ function createGripPress(options = {}) {
931
+ const tuning = options.tuning ?? {};
932
+ const dbl = { ...DOUBLE_CLICK, ...options.double };
933
+ let press = null;
934
+ let last = null;
935
+ return {
936
+ down(point, time, o = {}) {
937
+ const near = !!last && time - last.time <= dbl.ms && Math.hypot(point.x - last.at.x, point.y - last.at.y) <= dbl.px;
938
+ const double = o.clicks !== void 0 && o.clicks > 0 ? o.clicks === 2 : near;
939
+ press = { at: { x: point.x, y: point.y }, time, touch: !!o.touch, double, state: "wait" };
940
+ },
941
+ move(point, time) {
942
+ if (!press) return "wait";
943
+ if (press.state !== "wait") return press.state;
944
+ press.state = liftDecision({ touch: press.touch, distance: Math.hypot(point.x - press.at.x, point.y - press.at.y), elapsed: time - press.time }, tuning);
945
+ return press.state;
946
+ },
947
+ up() {
948
+ const p = press;
949
+ press = null;
950
+ if (!p || p.state !== "wait") {
951
+ last = null;
952
+ return null;
953
+ }
954
+ if (p.double) {
955
+ last = null;
956
+ return "doubleActivate";
957
+ }
958
+ last = { at: p.at, time: p.time };
959
+ return "click";
960
+ },
961
+ cancel() {
962
+ press = null;
963
+ last = null;
964
+ }
965
+ };
966
+ }
967
+
968
+ export {
969
+ DRAG_DEFAULTS,
970
+ REFUSAL_RANK,
971
+ pickRank,
972
+ inRect,
973
+ targetAt,
974
+ liftDecision,
975
+ createDragIntent,
976
+ MIN_BOX_LENGTH,
977
+ guideRects,
978
+ SNAP_DISTANCE,
979
+ LANDING_MARGINS,
980
+ LANDING_TOUCH_MARGINS,
981
+ LANDING_GATES,
982
+ LANDING_APPROACH,
983
+ createLandingModel,
984
+ DRAG_PREVIEW_DEFAULT,
985
+ PLACE_GUIDES_DEFAULT,
986
+ previewPlan,
987
+ createGripPress
988
+ };
989
+ //# sourceMappingURL=chunk-IT2FMZOM.js.map