@n-uf/motion 26.11.50 → 26.11.52

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.
package/dist/drag.js CHANGED
@@ -278,24 +278,198 @@ function createDragIntent(options) {
278
278
  };
279
279
  }
280
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
+
281
459
  // src/drag/landing.ts
282
460
  var SLIDE_STEP = 1;
283
461
  var SNAP_DISTANCE = 8;
284
462
  var LANDING_MARGINS = { exit: 12, spot: 6, edge: 48, lift: 16 };
285
463
  var LANDING_TOUCH_MARGINS = { exit: 16, spot: 8, edge: 48, lift: 16 };
286
- var LANDING_GATES = { path: 40, depth: 8, still: 1.5, step: 3, trail: 40, rest: 22, pause: 60 };
287
- var LANDING_APPROACH = { reach: 80, keep: 96, nearer: 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 };
288
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;
289
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;
290
- function depthIn(r, p, stage) {
468
+ function depthIn(lane, p, stage) {
469
+ const r = lane.rect;
291
470
  if (!strictlyIn(r, p)) return 0;
292
471
  const on = (a, b) => Math.abs(a - b) < 1;
293
- const sides = [
294
- on(r.x, stage.x) ? Infinity : p.x - r.x,
295
- on(r.x + r.width, stage.x + stage.width) ? Infinity : r.x + r.width - p.x,
296
- on(r.y, stage.y) ? Infinity : p.y - r.y,
297
- on(r.y + r.height, stage.y + stage.height) ? Infinity : r.y + r.height - p.y
298
- ];
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];
299
473
  return Math.max(0, Math.min(...sides));
300
474
  }
301
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)));
@@ -325,11 +499,21 @@ function createLandingModel(options) {
325
499
  let moved = null;
326
500
  let liftAt = options.lift ?? null;
327
501
  let inLiftZone = true;
502
+ let farHeld = false;
503
+ let flung = false;
504
+ let slowFrom = null;
328
505
  let lastStep = 0;
506
+ const hand = createHandSpeed({ gap: Math.min(HAND_SPEED.gap, gates.pause) });
329
507
  const pathIn = /* @__PURE__ */ new Map();
330
508
  const slide = /* @__PURE__ */ new Map();
331
509
  const cameIn = /* @__PURE__ */ new Set();
332
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
+ };
333
517
  let previous = laneId ? "lane" : "open";
334
518
  let frame = { region: previous, lane: laneId, spot: spotId, landing: null, room: !!spotId, guides: [], shift: false };
335
519
  let landedOn = null;
@@ -395,61 +579,122 @@ function createLandingModel(options) {
395
579
  }
396
580
  return cand;
397
581
  }
398
- function guidesFor(p, region, shift) {
582
+ function guidesFor(p, region, shift, pending, landing) {
399
583
  if (guidesLevel === "off" || shift) return [];
400
584
  const regions = heldRegions(spotId);
401
- const all = (l2) => l2.marks ? l2.marks.map((m, i) => ({ id: m.id ?? `${l2.id}#${i}`, lane: l2.id, kind: m.kind, rect: m.rect })) : l2.spots.map((s) => ({ id: `${l2.id}/${s.id}`, lane: l2.id, kind: "box", rect: s.landing }));
402
- if (guidesLevel === "all") return regions.lanes.flatMap(all);
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) {
403
630
  if ((region === "lane" || region === "refused") && laneId) {
404
631
  approached = laneId;
405
- const l2 = laneIn(regions, laneId);
406
- return l2 ? all(l2) : [];
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;
407
641
  }
408
642
  let best = null;
409
643
  let bestD = Infinity;
410
- for (const l2 of regions.lanes) {
411
- const d = distanceTo2(l2.rect, p);
644
+ for (const l of regions.lanes) {
645
+ const d = distanceTo2(l.rect, p);
412
646
  if (d < bestD) {
413
- best = l2;
647
+ best = l;
414
648
  bestD = d;
415
649
  }
416
650
  }
417
- if (region === "refused") {
418
- approached = best?.id ?? null;
419
- return best ? all(best) : [];
420
- }
651
+ const acquire = Math.max(0, approach.reach - margins.spot, approach.reach / 2);
421
652
  const kept = laneIn(regions, approached);
422
653
  if (kept) {
423
654
  const d = distanceTo2(kept.rect, p);
424
- if (d > approach.keep) approached = null;
425
- else if (best && best.id !== kept.id && bestD + approach.nearer < d) approached = bestD <= approach.reach ? best.id : null;
426
- } else approached = best && bestD <= approach.reach ? best.id : null;
427
- const l = laneIn(regions, approached);
428
- return l ? all(l) : [];
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;
429
659
  }
430
660
  function update(raw, t, keys) {
431
661
  const p = ontoStage(heldRegions(spotId).stage, raw, margins.edge) ?? raw;
432
662
  let step = 0;
433
663
  if (moved && (raw.x !== moved.raw.x || raw.y !== moved.raw.y)) {
664
+ const before = moved.t;
434
665
  step = Math.hypot(raw.x - moved.raw.x, raw.y - moved.raw.y) * 8 / Math.max(1, t - moved.t);
435
666
  moved = { raw, t };
667
+ hand.push(raw, t);
668
+ step = hand.step;
436
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;
437
676
  } else if (moved) {
438
677
  const stage = heldRegions(spotId).stage;
439
678
  const onEdge = p.x <= stage.x || p.y <= stage.y || p.x >= stage.x + stage.width || p.y >= stage.y + stage.height;
440
679
  const since = t - moved.t;
441
680
  step = since >= gates.pause || since >= gates.rest && (lastStep <= gates.step || onEdge) ? 0 : lastStep;
681
+ slowFrom ??= moved.t;
442
682
  } else {
443
683
  moved = { raw, t };
684
+ hand.reset();
685
+ hand.push(raw, t);
444
686
  liftAt ??= p;
445
687
  step = lastStep = Infinity;
446
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;
447
692
  const from = last?.p ?? null;
448
693
  const fromRaw = last?.raw ?? null;
449
694
  last = { p, raw, t };
450
695
  const shift = !!keys?.shift;
451
696
  const regions = heldRegions(spotId);
452
- const slow = step <= gates.step;
697
+ const slow = Number.isFinite(hand.speed) ? hand.speed <= gates.step : step <= gates.step;
453
698
  for (const l of regions.lanes) {
454
699
  const was = from && strictlyIn(l.rect, from);
455
700
  const go = was ? Math.abs(alongOf(l, p) - alongOf(l, from)) : 0;
@@ -457,7 +702,8 @@ function createLandingModel(options) {
457
702
  const inL = strictlyIn(l.rect, p);
458
703
  pathIn.set(l.id, inL ? (pathIn.get(l.id) ?? 0) + (slow ? go : 0) : 0);
459
704
  const s = slide.get(l.id);
460
- slide.set(l.id, inL ? { along: (s?.along ?? 0) + go, across: (s?.across ?? 0) + over } : { along: 0, across: 0 });
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 });
461
707
  if (l.owns && !inL) cameIn.add(l.id);
462
708
  }
463
709
  let region;
@@ -467,10 +713,10 @@ function createLandingModel(options) {
467
713
  laneId = spotId = null;
468
714
  } else {
469
715
  const held2 = laneIn(regions, laneId);
470
- const gate = (l) => (pathIn.get(l.id) ?? 0) >= gates.path || depthIn(l.rect, p, regions.stage) >= gates.depth && step <= gates.still;
716
+ const gate = (l) => (pathIn.get(l.id) ?? 0) >= gates.path || depthIn(l, p, regions.stage) >= gates.depth && step <= gates.still && settled;
471
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;
472
718
  const sl = touching ? slide.get(touching.id) : void 0;
473
- const slid = !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along;
719
+ const slid = !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along && hand.speed <= gates.slide;
474
720
  const liftR = margins.lift ?? 16;
475
721
  if (liftAt) {
476
722
  const far = Math.hypot(p.x - liftAt.x, p.y - liftAt.y);
@@ -480,33 +726,37 @@ function createLandingModel(options) {
480
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));
481
727
  const ownLane = nearLift && options.home ? laneIn(regions, options.home.lane) : void 0;
482
728
  const homeHere = ownLane && strictlyIn(ownLane.rect, p) ? ownLane : void 0;
483
- const next = homeHere ? void 0 : owner ?? (touching && (gate(touching) || slid) ? touching : 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;
484
734
  if (homeHere) {
485
735
  const s = spotIn(homeHere, options.home.spot) ?? pick(homeHere, alongOf(homeHere, p));
486
736
  laneId = homeHere.id;
487
737
  spotId = s?.id ?? null;
488
738
  region = s ? "lane" : "refused";
489
739
  } else if (held2 && !next && (touching || inside(held2.rect, p, margins.exit))) {
490
- const s = along(held2, p, step);
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);
491
744
  spotId = s?.id ?? spotId;
492
745
  region = s ? "lane" : "refused";
493
746
  if (!s) spotId = null;
494
- if (!s && !strictlyIn(held2.rect, p)) {
747
+ if (!s && !far && !strictlyIn(held2.rect, p)) {
495
748
  const others = regions.lanes.filter((l) => l.id !== held2.id && strictlyIn(l.rect, p));
496
- if (others.length > 0) pending = others.reduce((a, b) => depthIn(b.rect, p, regions.stage) > depthIn(a.rect, p, regions.stage) ? b : a).id;
749
+ if (others.length > 0) pending = pendingIn(others, p, regions.stage);
497
750
  }
498
751
  } else {
499
752
  laneId = spotId = null;
500
- const lanesHere = regions.lanes.filter((l) => strictlyIn(l.rect, p) && !(l.owns && nearLift));
501
- 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;
502
- const overRefused = (l) => Number.isFinite(step) && step <= gates.step && lanesHere.length === 1 && [...regions.blocked, ...regions.refused].some((b) => strictlyIn(b, p) && !within2(b, l));
503
753
  let entered = next ?? null;
504
754
  if (!entered)
505
755
  for (const l of lanesHere) {
506
- const deep = depthIn(l.rect, p, regions.stage);
507
- if ((gate(l) || overRefused(l)) && (!entered || deep > depthIn(entered.rect, p, regions.stage))) entered = l;
756
+ const deep = depthIn(l, p, regions.stage);
757
+ if ((gate(l) || overRefused(l)) && (!entered || deep > depthIn(entered, p, regions.stage))) entered = l;
508
758
  }
509
- if (!entered && lanesHere.length > 0) pending = lanesHere.reduce((a, b) => depthIn(b.rect, p, regions.stage) > depthIn(a.rect, p, regions.stage) ? b : a).id;
759
+ if (!entered && lanesHere.length > 0) pending = pendingIn(lanesHere, p, regions.stage);
510
760
  if (entered) {
511
761
  laneId = entered.id;
512
762
  const s = pick(entered, alongOf(entered, p));
@@ -519,6 +769,7 @@ function createLandingModel(options) {
519
769
  }
520
770
  }
521
771
  previous = region;
772
+ lastPending = pending;
522
773
  const shown = shift && (region === "lane" || region === "open") ? "open" : region;
523
774
  const r2 = heldRegions(spotId);
524
775
  const heldLane = laneIn(r2, laneId);
@@ -531,7 +782,7 @@ function createLandingModel(options) {
531
782
  spot: shown === "lane" ? spotId : null,
532
783
  landing,
533
784
  room: shown === "lane" && !!spot,
534
- guides: guidesFor(p, shown, shift),
785
+ guides: guidesFor(p, shown, shift, pending && shown !== "lane" ? pending : null, landing),
535
786
  shift,
536
787
  ...pending && shown !== "lane" ? { pending } : {}
537
788
  };
@@ -564,6 +815,10 @@ function createLandingModel(options) {
564
815
  hide() {
565
816
  laneId = spotId = null;
566
817
  approached = null;
818
+ lastPending = null;
819
+ farHeld = false;
820
+ flung = false;
821
+ slowFrom = null;
567
822
  pathIn.clear();
568
823
  slide.clear();
569
824
  cameIn.clear();
@@ -635,80 +890,6 @@ function createGripPress(options = {}) {
635
890
  }
636
891
  };
637
892
  }
638
-
639
- // src/drag/guide-rects.ts
640
- var EPS = 1e-6;
641
- function guideRects(guides, options) {
642
- const inset = Number.isFinite(options.inset) ? Math.max(0, options.inset) : 2;
643
- const min = Number.isFinite(options.minThickness) ? Math.max(0, options.minThickness) : 2;
644
- 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;
645
- const place = (g, rect) => same(g.rect, rect) ? g : { ...g, rect };
646
- const x0 = options.inside.x + inset;
647
- const y0 = options.inside.y + inset;
648
- const x1 = options.inside.x + options.inside.width - inset;
649
- const y1 = options.inside.y + options.inside.height - inset;
650
- const gap = Number.isFinite(options.clearance) ? Math.max(0, options.clearance) : 2;
651
- const allClear = (options.clear ?? []).map(
652
- (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 }
653
- );
654
- const out = [];
655
- for (const g of guides) {
656
- const r = g.rect;
657
- const clear = allClear.filter((c) => !c.kinds || c.kinds.includes(g.kind));
658
- if (g.kind === "box") {
659
- let a = Math.max(r.x, x0);
660
- let b = Math.max(r.y, y0);
661
- let c = Math.min(r.x + r.width, x1);
662
- let d = Math.min(r.y + r.height, y1);
663
- for (const { k, gap: gap2 } of clear) {
664
- const k0 = k.x - gap2;
665
- const k1 = k.x + k.width + gap2;
666
- const l0 = k.y - gap2;
667
- const l1 = k.y + k.height + gap2;
668
- if (c - a <= EPS || d - b <= EPS) break;
669
- if (k1 <= a + EPS || k0 >= c - EPS || l1 <= b + EPS || l0 >= d - EPS) continue;
670
- const parts = [
671
- { a, b, c: Math.min(c, k0), d },
672
- { a: Math.max(a, k1), b, c, d },
673
- { a, b, c, d: Math.min(d, l0) },
674
- { a, b: Math.max(b, l1), c, d }
675
- ].filter((p) => p.c - p.a > EPS && p.d - p.b > EPS);
676
- if (parts.length === 0) {
677
- c = a;
678
- break;
679
- }
680
- const best = parts.reduce((p, q) => (q.c - q.a) * (q.d - q.b) > (p.c - p.a) * (p.d - p.b) ? q : p);
681
- ({ a, b, c, d } = best);
682
- }
683
- if (c - a > EPS && d - b > EPS) out.push(place(g, { x: a, y: b, width: c - a, height: d - b }));
684
- continue;
685
- }
686
- const thinX = r.width <= r.height;
687
- const t = thinX ? r.width : r.height;
688
- let lo = thinX ? r.x : r.y;
689
- const lim0 = thinX ? x0 : y0;
690
- const lim1 = thinX ? x1 : y1;
691
- if (lo + t > lim1) lo = lim1 - t;
692
- if (lo < lim0) lo = lim0;
693
- let hi = Math.min(lo + t, lim1);
694
- const s0 = Math.max(thinX ? r.y : r.x, thinX ? y0 : x0);
695
- const s1 = Math.min(thinX ? r.y + r.height : r.x + r.width, thinX ? y1 : x1);
696
- if (s1 - s0 <= EPS) continue;
697
- for (const { k: c, gap: gap2 } of clear) {
698
- const cs0 = (thinX ? c.y : c.x) - gap2;
699
- const cs1 = (thinX ? c.y + c.height : c.x + c.width) + gap2;
700
- if (cs1 <= s0 + EPS || cs0 >= s1 - EPS) continue;
701
- const c0 = (thinX ? c.x : c.y) - gap2;
702
- const c1 = (thinX ? c.x + c.width : c.y + c.height) + gap2;
703
- if (c1 <= lo + EPS || c0 >= hi - EPS) continue;
704
- if ((c0 + c1) / 2 >= (lo + hi) / 2) hi = Math.min(hi, c0);
705
- else lo = Math.max(lo, c1);
706
- }
707
- if (hi - lo < Math.max(EPS, min)) continue;
708
- 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 }));
709
- }
710
- return out;
711
- }
712
893
  export {
713
894
  DOUBLE_CLICK,
714
895
  DRAG_DEFAULTS,
@@ -717,6 +898,7 @@ export {
717
898
  LANDING_GATES,
718
899
  LANDING_MARGINS,
719
900
  LANDING_TOUCH_MARGINS,
901
+ MIN_BOX_LENGTH,
720
902
  PLACE_GUIDES_DEFAULT,
721
903
  REFUSAL_RANK,
722
904
  SNAP_DISTANCE,