@n-uf/motion 26.11.54 → 26.11.55

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.
@@ -273,151 +273,6 @@ function createDragIntent(options) {
273
273
  };
274
274
  }
275
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
276
  // src/drag/hand-speed.ts
422
277
  var HAND_SLOW_STEP = 3;
423
278
  var HAND_SPEED = { span: 48, steps: 5, gap: 40, slowStep: HAND_SLOW_STEP, accelerating: 1.5, gathering: 1.25 };
@@ -473,8 +328,6 @@ function createHandSpeed(options = {}) {
473
328
  }
474
329
 
475
330
  // src/drag/landing.ts
476
- var SLIDE_STEP = 1;
477
- var SNAP_DISTANCE = 8;
478
331
  var LANDING_MARGINS = { exit: 12, spot: 6, edge: 48, lift: 16 };
479
332
  var LANDING_TOUCH_MARGINS = { exit: 16, spot: 8, edge: 48, lift: 16 };
480
333
  var LANDING_GATES = { path: 40, depth: 8, stillSpeed: 0.1875, stepSpeed: 0.375, trail: 40, rest: 22, pause: 60, slideSpeed: 2 };
@@ -502,12 +355,14 @@ function createLandingModel(options) {
502
355
  const approach = { ...LANDING_APPROACH, ...options.approach };
503
356
  const guidesLevel = options.placeGuides ?? "off";
504
357
  let base = options.regions;
505
- let regionsFor = options.regionsFor;
358
+ let landingOf = options.landingOf;
359
+ let spotsOf = options.spotsOf;
506
360
  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;
361
+ const heldLaneOf = (lane, spot) => {
362
+ if (!spot || !spotsOf) return lane;
363
+ if (!cache.has(spot)) cache.set(spot, spotsOf(spot));
364
+ const spots = cache.get(spot);
365
+ return spots ? { ...lane, spots } : lane;
511
366
  };
512
367
  let laneId = options.home?.lane ?? null;
513
368
  let spotId = options.home?.spot ?? null;
@@ -515,6 +370,8 @@ function createLandingModel(options) {
515
370
  let moved = null;
516
371
  let liftAt = options.lift ?? null;
517
372
  let inLiftZone = true;
373
+ const floatLift = !options.home && !options.regions.lanes.some((l) => l.spots.some((s) => s.home));
374
+ let floatLeft = false;
518
375
  let farHeld = false;
519
376
  let flung = false;
520
377
  let slowFrom = null;
@@ -532,7 +389,7 @@ function createLandingModel(options) {
532
389
  return kept && depthIn(deepest, p, stage) <= depthIn(kept, p, stage) + margins.spot ? kept.id : deepest.id;
533
390
  };
534
391
  let previous = laneId ? "lane" : "open";
535
- let frame = { region: previous, lane: laneId, spot: spotId, landing: null, room: !!spotId, guides: [], shift: false };
392
+ let frame = { region: previous, lane: laneId, spot: spotId, held: null, landing: null, room: !!spotId, guides: [], shift: false };
536
393
  let landedOn = null;
537
394
  const laneIn = (regions, id) => id ? regions.lanes.find((l) => l.id === id) : void 0;
538
395
  const spotIn = (lane, id) => lane && id ? lane.spots.find((s) => s.id === id) : void 0;
@@ -551,35 +408,8 @@ function createLandingModel(options) {
551
408
  }
552
409
  return best;
553
410
  }
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
411
  function along(lane, p, step) {
581
- const regions = heldRegions(spotId);
582
- const held = laneIn(regions, lane.id) ?? lane;
412
+ const held = heldLaneOf(lane, spotId);
583
413
  const a = alongOf(held, p);
584
414
  const now = spotIn(held, spotId);
585
415
  const cand = pick(held, a);
@@ -588,117 +418,34 @@ function createLandingModel(options) {
588
418
  const past = a < now.along[0] - margins.spot || a > now.along[1] + margins.spot;
589
419
  const reflows = now.others === void 0 || now.others !== cand.others;
590
420
  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;
421
+ if (reflows && step > gates.stepSpeed && distanceTo2(landingOf({ kind: "spot", lane: lane.id, spot: now.id, point: p }) ?? now.landing, p) <= gates.trail) return now;
422
+ if (spotsOf && reflows) {
423
+ const lane2 = heldLaneOf(lane, cand.id);
424
+ if (pick(lane2, alongOf(lane2, p))?.id !== cand.id) return now;
596
425
  }
597
426
  return cand;
598
427
  }
599
- function guidesFor(p, region, shift, pending, landing) {
428
+ function guidesFor(p, region, shift, pending, held) {
600
429
  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);
430
+ const near = nearLane(p, region, pending, base);
635
431
  const wouldLand = (l) => {
636
- if (l.id === laneId) return region === "lane" ? landing : null;
432
+ if (l.id === laneId) return held;
637
433
  const s = pick(l, alongOf(l, p));
638
- return s ? landingAt(l, s, p, regions.item) : null;
434
+ return s ? { kind: "spot", lane: l.id, spot: s.id, point: p } : held;
639
435
  };
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) {
436
+ if (guidesLevel === "near") return near ? [{ lane: near.id, held: wouldLand(near) }] : [];
437
+ let owner = near;
438
+ if (!owner) {
651
439
  let d = approach.reach;
652
- for (const l of regions.lanes) {
440
+ for (const l of base.lanes) {
653
441
  const dl = distanceTo2(l.rect, p);
654
- if (owns(l) && dl <= d) {
442
+ if (dl <= d) {
655
443
  owner = l;
656
444
  d = dl;
657
445
  }
658
446
  }
659
447
  }
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
- });
448
+ return base.lanes.map((l) => ({ lane: l.id, held: owner && l.id === owner.id ? wouldLand(l) : held }));
702
449
  }
703
450
  function nearLane(p, region, pending, regions) {
704
451
  if ((region === "lane" || region === "refused") && laneId) {
@@ -733,7 +480,7 @@ function createLandingModel(options) {
733
480
  }
734
481
  function update(raw, t, keys) {
735
482
  lastKeys = keys;
736
- const p = ontoStage(heldRegions(spotId).stage, raw, margins.edge) ?? raw;
483
+ const p = ontoStage(base.stage, raw, margins.edge) ?? raw;
737
484
  let step = 0;
738
485
  if (moved && (raw.x !== moved.raw.x || raw.y !== moved.raw.y)) {
739
486
  const before = moved.t;
@@ -749,7 +496,7 @@ function createLandingModel(options) {
749
496
  } else if (!Number.isFinite(sp) || sp > gates.stepSpeed) slowFrom = null;
750
497
  else slowFrom ??= before;
751
498
  } else if (moved) {
752
- const stage = heldRegions(spotId).stage;
499
+ const stage = base.stage;
753
500
  const onEdge = p.x <= stage.x || p.y <= stage.y || p.x >= stage.x + stage.width || p.y >= stage.y + stage.height;
754
501
  const since = t - moved.t;
755
502
  step = since >= gates.pause || since >= gates.rest && (lastStep <= gates.stepSpeed || onEdge) ? 0 : lastStep;
@@ -762,13 +509,15 @@ function createLandingModel(options) {
762
509
  step = lastStep = Infinity;
763
510
  }
764
511
  if (flung && slowFrom !== null && t - slowFrom >= gates.pause) flung = false;
765
- const edgeStage = heldRegions(spotId).stage;
512
+ const edgeStage = base.stage;
766
513
  const settled = !flung || p.x <= edgeStage.x || p.y <= edgeStage.y || p.x >= edgeStage.x + edgeStage.width || p.y >= edgeStage.y + edgeStage.height;
767
514
  const from = last?.p ?? null;
768
515
  const fromRaw = last?.raw ?? null;
769
516
  last = { p, raw, t };
770
517
  const shift = !!keys?.shift;
771
- const regions = heldRegions(spotId);
518
+ if (floatLift && liftAt && Math.hypot(p.x - liftAt.x, p.y - liftAt.y) > (margins.lift ?? 16)) floatLeft = true;
519
+ const floatZone = floatLift && !floatLeft && !!liftAt;
520
+ const regions = floatZone ? { ...base, lanes: [] } : base;
772
521
  const slow = Number.isFinite(hand.speed) ? hand.speed <= gates.stepSpeed : step <= gates.stepSpeed;
773
522
  for (const l of regions.lanes) {
774
523
  const was = from && strictlyIn(l.rect, from);
@@ -787,9 +536,9 @@ function createLandingModel(options) {
787
536
  region = "nowhere";
788
537
  laneId = spotId = null;
789
538
  } else {
790
- const held = laneIn(regions, laneId);
539
+ const held2 = laneIn(regions, laneId);
791
540
  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;
541
+ 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;
793
542
  const sl = touching ? slide.get(touching.id) : void 0;
794
543
  const slid = !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along && hand.speed <= gates.slideSpeed;
795
544
  const liftR = margins.lift ?? 16;
@@ -798,29 +547,29 @@ function createLandingModel(options) {
798
547
  inLiftZone = far <= (inLiftZone ? liftR : Math.max(0, liftR - margins.spot));
799
548
  }
800
549
  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));
550
+ 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));
802
551
  const ownLane = nearLift && options.home ? laneIn(regions, options.home.lane) : void 0;
803
552
  const homeHere = ownLane && strictlyIn(ownLane.rect, p) ? ownLane : void 0;
804
553
  const lanesHere = regions.lanes.filter((l) => strictlyIn(l.rect, p) && !(l.owns && nearLift));
805
554
  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
555
  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
556
  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;
557
+ if (!(held2 && !homeHere && !next && (touching || inside(held2.rect, p, margins.exit)))) farHeld = false;
809
558
  if (homeHere) {
810
559
  const s = spotIn(homeHere, options.home.spot) ?? pick(homeHere, alongOf(homeHere, p));
811
560
  laneId = homeHere.id;
812
561
  spotId = s?.id ?? null;
813
562
  region = s ? "lane" : "refused";
814
- } else if (held && !next && (touching || inside(held.rect, p, margins.exit))) {
815
- const d = distanceTo2(held.rect, p);
563
+ } else if (held2 && !next && (touching || inside(held2.rect, p, margins.exit))) {
564
+ const d = distanceTo2(held2.rect, p);
816
565
  farHeld = farHeld ? d > margins.exit + gates.path - margins.spot : d > margins.exit + gates.path;
817
566
  const far = farHeld;
818
- const s = far ? null : along(held, p, step);
567
+ const s = far ? null : along(held2, p, step);
819
568
  spotId = s?.id ?? spotId;
820
569
  region = s ? "lane" : "refused";
821
570
  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));
571
+ if (!s && !far && !strictlyIn(held2.rect, p)) {
572
+ const others = regions.lanes.filter((l) => l.id !== held2.id && strictlyIn(l.rect, p));
824
573
  if (others.length > 0) pending = pendingIn(others, p, regions.stage);
825
574
  }
826
575
  } else {
@@ -843,21 +592,23 @@ function createLandingModel(options) {
843
592
  else region = "refused";
844
593
  }
845
594
  }
846
- previous = region;
595
+ previous = floatZone && base.lanes.some((l) => strictlyIn(l.rect, p)) ? previous : region;
847
596
  lastPending = pending;
848
597
  const shown = shift && (region === "lane" || region === "open") ? "open" : region;
849
- const r2 = heldRegions(spotId);
850
- const heldLane = laneIn(r2, laneId);
598
+ const lane0 = laneIn(base, laneId);
599
+ const heldLane = lane0 ? heldLaneOf(lane0, spotId) : void 0;
851
600
  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;
601
+ landedOn = shown === "lane" && spot ? spot : null;
602
+ const held = shown === "lane" ? spot && laneId ? { kind: "spot", lane: laneId, spot: spot.id, point: p } : null : shown === "open" ? { kind: "float", point: p } : null;
603
+ const landing = held ? landingOf(held) : null;
854
604
  frame = {
855
605
  region: shown,
856
606
  lane: laneId,
857
607
  spot: shown === "lane" ? spotId : null,
608
+ held: held && (held.kind === "spot" || landing) ? held : null,
858
609
  landing,
859
610
  room: shown === "lane" && !!spot,
860
- guides: guidesFor(p, shown, shift, pending && shown !== "lane" ? pending : null, landing),
611
+ guides: guidesFor(p, shown, shift, pending && shown !== "lane" ? pending : null, held && (held.kind === "spot" || landing) ? held : null),
861
612
  shift,
862
613
  ...pending && shown !== "lane" ? { pending } : {}
863
614
  };
@@ -867,22 +618,20 @@ function createLandingModel(options) {
867
618
  update,
868
619
  release(point, time, keys) {
869
620
  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 };
621
+ const s = frame.held;
622
+ if (s?.kind === "spot" && frame.region === "lane") {
623
+ const ownSpot = !!options.home && options.home.spot === s.spot && options.home.lane === s.lane;
624
+ const at = frame.landing;
625
+ const home = ownSpot && !!landedOn && !!at && Math.max(Math.abs(at.x - landedOn.landing.x), Math.abs(at.y - landedOn.landing.y), Math.abs(at.width - landedOn.landing.width), Math.abs(at.height - landedOn.landing.height)) < 1e-6;
626
+ return { kind: "spot", lane: s.lane, spot: s.spot, point: s.point, home };
879
627
  }
880
- if (frame.region === "open" && frame.landing) return { kind: "float", rect: frame.landing };
628
+ if (s?.kind === "float" && frame.region === "open" && frame.landing) return { kind: "float", point: s.point };
881
629
  return null;
882
630
  },
883
- setRegions(regions, nextRegionsFor) {
884
- base = regions;
885
- if (nextRegionsFor) regionsFor = nextRegionsFor;
631
+ setGeometry(geometry) {
632
+ base = geometry.regions;
633
+ landingOf = geometry.landingOf;
634
+ spotsOf = geometry.spotsOf;
886
635
  cache.clear();
887
636
  const l = laneIn(base, laneId);
888
637
  if (laneId && !l) laneId = spotId = null;
@@ -965,6 +714,151 @@ function createGripPress(options = {}) {
965
714
  };
966
715
  }
967
716
 
717
+ // src/drag/guide-rects.ts
718
+ var MIN_BOX_LENGTH = 8;
719
+ var LINE_THICKNESS = 2;
720
+ var EPS = 1e-6;
721
+ function guideRects(guides, options) {
722
+ const inset = Number.isFinite(options.inset) ? Math.max(0, options.inset) : 2;
723
+ const min = Number.isFinite(options.minThickness) ? Math.max(0, options.minThickness) : 2;
724
+ const lineThickness = Number.isFinite(options.lineThickness) ? Math.max(0, options.lineThickness) : LINE_THICKNESS;
725
+ const minLength = Number.isFinite(options.minLength) ? Math.max(0, options.minLength) : MIN_BOX_LENGTH;
726
+ 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;
727
+ const place = (g, rect) => same(g.rect, rect) ? g : { ...g, rect };
728
+ const x0 = options.inside.x + inset;
729
+ const y0 = options.inside.y + inset;
730
+ const x1 = options.inside.x + options.inside.width - inset;
731
+ const y1 = options.inside.y + options.inside.height - inset;
732
+ const gap = Number.isFinite(options.clearance) ? Math.max(0, options.clearance) : 2;
733
+ const finite = (r) => Number.isFinite(r.x) && Number.isFinite(r.y) && Number.isFinite(r.width) && Number.isFinite(r.height);
734
+ const allClear = (options.clear ?? []).map(
735
+ (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 }
736
+ ).filter((c) => finite(c.k));
737
+ const out = [];
738
+ for (const g of guides) {
739
+ const r = g.rect;
740
+ const clear = allClear.filter((c) => !c.kinds || c.kinds.includes(g.kind));
741
+ if (g.kind === "box") {
742
+ 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) };
743
+ if (!(box.c - box.a > EPS) || !(box.d - box.b > EPS)) continue;
744
+ const w = box.c - box.a;
745
+ const h = box.d - box.b;
746
+ const alongX = w > h || w === h && g.axis !== "y";
747
+ const s02 = alongX ? box.a : box.b;
748
+ const s12 = alongX ? box.c : box.d;
749
+ const t0 = alongX ? box.b : box.a;
750
+ const t1 = alongX ? box.d : box.c;
751
+ const toBox = (p0, p1, q0, q1) => alongX ? { a: p0, b: q0, c: p1, d: q1 } : { a: q0, b: p0, c: q1, d: p1 };
752
+ const over = clear.map(({ k: k2, gap: gap2 }) => ({
753
+ x0: k2.x - gap2,
754
+ x1: k2.x + k2.width + gap2,
755
+ y0: k2.y - gap2,
756
+ y1: k2.y + k2.height + gap2,
757
+ s0: (alongX ? k2.x : k2.y) - gap2,
758
+ s1: (alongX ? k2.x + k2.width : k2.y + k2.height) + gap2,
759
+ t0: (alongX ? k2.y : k2.x) - gap2,
760
+ t1: (alongX ? k2.y + k2.height : k2.x + k2.width) + gap2
761
+ })).filter((k2) => k2.s1 > s02 + EPS && k2.s0 < s12 - EPS && k2.t1 > t0 + EPS && k2.t0 < t1 - EPS);
762
+ let v0 = t0;
763
+ let v1 = t1;
764
+ const half = (t1 - t0) / 2 + EPS;
765
+ for (const k2 of over) {
766
+ if (k2.t0 <= t0 + EPS && k2.t1 >= t1 - EPS) continue;
767
+ const along = Math.min(k2.s1, s12) - Math.max(k2.s0, s02);
768
+ if (k2.t0 <= t0 + EPS) {
769
+ if (k2.t1 - t0 < along - EPS && k2.t1 - t0 <= half) v0 = Math.max(v0, k2.t1);
770
+ } else if (k2.t1 >= t1 - EPS) {
771
+ if (t1 - k2.t0 < along - EPS && t1 - k2.t0 <= half) v1 = Math.min(v1, k2.t0);
772
+ }
773
+ }
774
+ if ((v0 > t0 || v1 < t1) && v1 - v0 < Math.max(EPS, min)) continue;
775
+ const rest = over.filter((k2) => k2.t1 > v0 + EPS && k2.t0 < v1 - EPS);
776
+ const kept = toBox(s02, s12, v0, v1);
777
+ 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]);
778
+ const cuts = [];
779
+ for (const [lo2, hi2] of full) {
780
+ const last = cuts[cuts.length - 1];
781
+ if (last && lo2 <= last[1] + EPS) last[1] = Math.max(last[1], hi2);
782
+ else cuts.push([lo2, hi2]);
783
+ }
784
+ const spans = [];
785
+ let at = s02;
786
+ let k = 0;
787
+ for (const [lo2, hi2] of cuts) {
788
+ if (lo2 - at > EPS) spans.push({ lo: at, hi: lo2, k });
789
+ if (lo2 > s02 + EPS && hi2 < s12 - EPS) k++;
790
+ at = hi2;
791
+ }
792
+ if (s12 - at > EPS) spans.push({ lo: at, hi: s12, k });
793
+ 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);
794
+ const longEnough = Math.max(EPS, minLength - EPS);
795
+ for (const span of spans) {
796
+ let p = toBox(span.lo, span.hi, v0, v1);
797
+ for (const k2 of corners) {
798
+ const { a, b, c, d } = p;
799
+ if (k2.x1 <= a + EPS || k2.x0 >= c - EPS || k2.y1 <= b + EPS || k2.y0 >= d - EPS) continue;
800
+ const cut = [
801
+ { a, b, c: Math.min(c, k2.x0), d },
802
+ { a: Math.max(a, k2.x1), b, c, d },
803
+ { a, b, c, d: Math.min(d, k2.y0) },
804
+ { a, b: Math.max(b, k2.y1), c, d }
805
+ ].filter((q) => q.c - q.a > EPS && q.d - q.b > EPS);
806
+ 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);
807
+ if (!p) break;
808
+ }
809
+ if (!p) continue;
810
+ 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;
811
+ if (touched && (alongX ? p.c - p.a : p.d - p.b) < longEnough) continue;
812
+ const placed = place(g, { x: p.a, y: p.b, width: p.c - p.a, height: p.d - p.b });
813
+ const id = g.id;
814
+ out.push(span.k === 0 || typeof id !== "string" ? placed : { ...placed, id: `${id}#${span.k + 1}` });
815
+ }
816
+ continue;
817
+ }
818
+ const thinX = r.width <= r.height;
819
+ const own = thinX ? r.width : r.height;
820
+ const widen = g.kind === "line" && own < lineThickness;
821
+ const t = widen ? lineThickness : own;
822
+ let lo = (thinX ? r.x : r.y) - (widen ? (lineThickness - own) / 2 : 0);
823
+ const lim0 = thinX ? x0 : y0;
824
+ const lim1 = thinX ? x1 : y1;
825
+ if (lo + t > lim1) lo = lim1 - t;
826
+ if (lo < lim0) lo = lim0;
827
+ let hi = Math.min(lo + t, lim1);
828
+ const l0 = Math.max(thinX ? r.y : r.x, thinX ? y0 : x0);
829
+ const l1 = Math.min(thinX ? r.y + r.height : r.x + r.width, thinX ? y1 : x1);
830
+ if (l1 - l0 <= EPS) continue;
831
+ const around = clear.map(({ k: c, gap: gap2 }) => ({
832
+ a: (thinX ? c.y : c.x) - gap2,
833
+ b: (thinX ? c.y + c.height : c.x + c.width) + gap2,
834
+ c0: (thinX ? c.x : c.y) - gap2,
835
+ c1: (thinX ? c.x + c.width : c.y + c.height) + gap2
836
+ }));
837
+ let s0 = l0;
838
+ let s1 = l1;
839
+ let shortened = false;
840
+ for (const k of around) {
841
+ if (k.b <= l0 + EPS || k.a >= l1 - EPS || k.c1 <= lo + EPS || k.c0 >= hi - EPS) continue;
842
+ const atStart = k.a <= l0 + EPS;
843
+ const atEnd = k.b >= l1 - EPS;
844
+ if (atStart === atEnd) continue;
845
+ if (atStart) s0 = Math.max(s0, k.b);
846
+ else s1 = Math.min(s1, k.a);
847
+ shortened = true;
848
+ }
849
+ if (s1 - s0 <= EPS || shortened && s1 - s0 < Math.max(EPS, minLength - EPS)) continue;
850
+ for (const k of around) {
851
+ if (k.b <= s0 + EPS || k.a >= s1 - EPS || k.c1 <= lo + EPS || k.c0 >= hi - EPS) continue;
852
+ if (k.a <= l0 + EPS !== k.b >= l1 - EPS) continue;
853
+ if ((k.c0 + k.c1) / 2 >= (lo + hi) / 2) hi = Math.min(hi, k.c0);
854
+ else lo = Math.max(lo, k.c1);
855
+ }
856
+ if (hi - lo < Math.max(EPS, min)) continue;
857
+ 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 }));
858
+ }
859
+ return out;
860
+ }
861
+
968
862
  export {
969
863
  DRAG_DEFAULTS,
970
864
  REFUSAL_RANK,
@@ -973,9 +867,6 @@ export {
973
867
  targetAt,
974
868
  liftDecision,
975
869
  createDragIntent,
976
- MIN_BOX_LENGTH,
977
- guideRects,
978
- SNAP_DISTANCE,
979
870
  LANDING_MARGINS,
980
871
  LANDING_TOUCH_MARGINS,
981
872
  LANDING_GATES,
@@ -984,6 +875,8 @@ export {
984
875
  DRAG_PREVIEW_DEFAULT,
985
876
  PLACE_GUIDES_DEFAULT,
986
877
  previewPlan,
987
- createGripPress
878
+ createGripPress,
879
+ MIN_BOX_LENGTH,
880
+ guideRects
988
881
  };
989
- //# sourceMappingURL=chunk-IT2FMZOM.js.map
882
+ //# sourceMappingURL=chunk-W7YP7VB2.js.map