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