@n-uf/motion 26.11.51 → 26.11.53
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/CHANGELOG.md +172 -0
- package/dist/drag.d.ts +129 -18
- package/dist/drag.js +317 -116
- package/dist/drag.js.map +1 -1
- package/package.json +1 -1
package/dist/drag.js
CHANGED
|
@@ -278,24 +278,218 @@ 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 lineThickness = Number.isFinite(options.lineThickness) ? Math.max(0, options.lineThickness) : 2;
|
|
288
|
+
const minLength = Number.isFinite(options.minLength) ? Math.max(0, options.minLength) : MIN_BOX_LENGTH;
|
|
289
|
+
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;
|
|
290
|
+
const place = (g, rect) => same(g.rect, rect) ? g : { ...g, rect };
|
|
291
|
+
const x0 = options.inside.x + inset;
|
|
292
|
+
const y0 = options.inside.y + inset;
|
|
293
|
+
const x1 = options.inside.x + options.inside.width - inset;
|
|
294
|
+
const y1 = options.inside.y + options.inside.height - inset;
|
|
295
|
+
const gap = Number.isFinite(options.clearance) ? Math.max(0, options.clearance) : 2;
|
|
296
|
+
const finite = (r) => Number.isFinite(r.x) && Number.isFinite(r.y) && Number.isFinite(r.width) && Number.isFinite(r.height);
|
|
297
|
+
const allClear = (options.clear ?? []).map(
|
|
298
|
+
(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 }
|
|
299
|
+
).filter((c) => finite(c.k));
|
|
300
|
+
const out = [];
|
|
301
|
+
for (const g of guides) {
|
|
302
|
+
const r = g.rect;
|
|
303
|
+
const clear = allClear.filter((c) => !c.kinds || c.kinds.includes(g.kind));
|
|
304
|
+
if (g.kind === "box") {
|
|
305
|
+
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) };
|
|
306
|
+
if (!(box.c - box.a > EPS) || !(box.d - box.b > EPS)) continue;
|
|
307
|
+
const w = box.c - box.a;
|
|
308
|
+
const h = box.d - box.b;
|
|
309
|
+
const alongX = w > h || w === h && g.axis !== "y";
|
|
310
|
+
const s02 = alongX ? box.a : box.b;
|
|
311
|
+
const s12 = alongX ? box.c : box.d;
|
|
312
|
+
const t0 = alongX ? box.b : box.a;
|
|
313
|
+
const t1 = alongX ? box.d : box.c;
|
|
314
|
+
const toBox = (p0, p1, q0, q1) => alongX ? { a: p0, b: q0, c: p1, d: q1 } : { a: q0, b: p0, c: q1, d: p1 };
|
|
315
|
+
const over = clear.map(({ k: k2, gap: gap2 }) => ({
|
|
316
|
+
x0: k2.x - gap2,
|
|
317
|
+
x1: k2.x + k2.width + gap2,
|
|
318
|
+
y0: k2.y - gap2,
|
|
319
|
+
y1: k2.y + k2.height + gap2,
|
|
320
|
+
s0: (alongX ? k2.x : k2.y) - gap2,
|
|
321
|
+
s1: (alongX ? k2.x + k2.width : k2.y + k2.height) + gap2,
|
|
322
|
+
t0: (alongX ? k2.y : k2.x) - gap2,
|
|
323
|
+
t1: (alongX ? k2.y + k2.height : k2.x + k2.width) + gap2
|
|
324
|
+
})).filter((k2) => k2.s1 > s02 + EPS && k2.s0 < s12 - EPS && k2.t1 > t0 + EPS && k2.t0 < t1 - EPS);
|
|
325
|
+
let v0 = t0;
|
|
326
|
+
let v1 = t1;
|
|
327
|
+
const half = (t1 - t0) / 2 + EPS;
|
|
328
|
+
for (const k2 of over) {
|
|
329
|
+
if (k2.t0 <= t0 + EPS && k2.t1 >= t1 - EPS) continue;
|
|
330
|
+
const along = Math.min(k2.s1, s12) - Math.max(k2.s0, s02);
|
|
331
|
+
if (k2.t0 <= t0 + EPS) {
|
|
332
|
+
if (k2.t1 - t0 < along - EPS && k2.t1 - t0 <= half) v0 = Math.max(v0, k2.t1);
|
|
333
|
+
} else if (k2.t1 >= t1 - EPS) {
|
|
334
|
+
if (t1 - k2.t0 < along - EPS && t1 - k2.t0 <= half) v1 = Math.min(v1, k2.t0);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if ((v0 > t0 || v1 < t1) && v1 - v0 < Math.max(EPS, min)) continue;
|
|
338
|
+
const rest = over.filter((k2) => k2.t1 > v0 + EPS && k2.t0 < v1 - EPS);
|
|
339
|
+
const kept = toBox(s02, s12, v0, v1);
|
|
340
|
+
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]);
|
|
341
|
+
const cuts = [];
|
|
342
|
+
for (const [lo2, hi2] of full) {
|
|
343
|
+
const last = cuts[cuts.length - 1];
|
|
344
|
+
if (last && lo2 <= last[1] + EPS) last[1] = Math.max(last[1], hi2);
|
|
345
|
+
else cuts.push([lo2, hi2]);
|
|
346
|
+
}
|
|
347
|
+
const spans = [];
|
|
348
|
+
let at = s02;
|
|
349
|
+
let k = 0;
|
|
350
|
+
for (const [lo2, hi2] of cuts) {
|
|
351
|
+
if (lo2 - at > EPS) spans.push({ lo: at, hi: lo2, k });
|
|
352
|
+
if (lo2 > s02 + EPS && hi2 < s12 - EPS) k++;
|
|
353
|
+
at = hi2;
|
|
354
|
+
}
|
|
355
|
+
if (s12 - at > EPS) spans.push({ lo: at, hi: s12, k });
|
|
356
|
+
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);
|
|
357
|
+
const longEnough = Math.max(EPS, minLength - EPS);
|
|
358
|
+
for (const span of spans) {
|
|
359
|
+
let p = toBox(span.lo, span.hi, v0, v1);
|
|
360
|
+
for (const k2 of corners) {
|
|
361
|
+
const { a, b, c, d } = p;
|
|
362
|
+
if (k2.x1 <= a + EPS || k2.x0 >= c - EPS || k2.y1 <= b + EPS || k2.y0 >= d - EPS) continue;
|
|
363
|
+
const cut = [
|
|
364
|
+
{ a, b, c: Math.min(c, k2.x0), d },
|
|
365
|
+
{ a: Math.max(a, k2.x1), b, c, d },
|
|
366
|
+
{ a, b, c, d: Math.min(d, k2.y0) },
|
|
367
|
+
{ a, b: Math.max(b, k2.y1), c, d }
|
|
368
|
+
].filter((q) => q.c - q.a > EPS && q.d - q.b > EPS);
|
|
369
|
+
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);
|
|
370
|
+
if (!p) break;
|
|
371
|
+
}
|
|
372
|
+
if (!p) continue;
|
|
373
|
+
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;
|
|
374
|
+
if (touched && (alongX ? p.c - p.a : p.d - p.b) < longEnough) continue;
|
|
375
|
+
const placed = place(g, { x: p.a, y: p.b, width: p.c - p.a, height: p.d - p.b });
|
|
376
|
+
const id = g.id;
|
|
377
|
+
out.push(span.k === 0 || typeof id !== "string" ? placed : { ...placed, id: `${id}#${span.k + 1}` });
|
|
378
|
+
}
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const thinX = r.width <= r.height;
|
|
382
|
+
const own = thinX ? r.width : r.height;
|
|
383
|
+
const widen = g.kind === "line" && own < lineThickness;
|
|
384
|
+
const t = widen ? lineThickness : own;
|
|
385
|
+
let lo = (thinX ? r.x : r.y) - (widen ? (lineThickness - own) / 2 : 0);
|
|
386
|
+
const lim0 = thinX ? x0 : y0;
|
|
387
|
+
const lim1 = thinX ? x1 : y1;
|
|
388
|
+
if (lo + t > lim1) lo = lim1 - t;
|
|
389
|
+
if (lo < lim0) lo = lim0;
|
|
390
|
+
let hi = Math.min(lo + t, lim1);
|
|
391
|
+
const l0 = Math.max(thinX ? r.y : r.x, thinX ? y0 : x0);
|
|
392
|
+
const l1 = Math.min(thinX ? r.y + r.height : r.x + r.width, thinX ? y1 : x1);
|
|
393
|
+
if (l1 - l0 <= EPS) continue;
|
|
394
|
+
const around = clear.map(({ k: c, gap: gap2 }) => ({
|
|
395
|
+
a: (thinX ? c.y : c.x) - gap2,
|
|
396
|
+
b: (thinX ? c.y + c.height : c.x + c.width) + gap2,
|
|
397
|
+
c0: (thinX ? c.x : c.y) - gap2,
|
|
398
|
+
c1: (thinX ? c.x + c.width : c.y + c.height) + gap2
|
|
399
|
+
}));
|
|
400
|
+
let s0 = l0;
|
|
401
|
+
let s1 = l1;
|
|
402
|
+
let shortened = false;
|
|
403
|
+
for (const k of around) {
|
|
404
|
+
if (k.b <= l0 + EPS || k.a >= l1 - EPS || k.c1 <= lo + EPS || k.c0 >= hi - EPS) continue;
|
|
405
|
+
const atStart = k.a <= l0 + EPS;
|
|
406
|
+
const atEnd = k.b >= l1 - EPS;
|
|
407
|
+
if (atStart === atEnd) continue;
|
|
408
|
+
if (atStart) s0 = Math.max(s0, k.b);
|
|
409
|
+
else s1 = Math.min(s1, k.a);
|
|
410
|
+
shortened = true;
|
|
411
|
+
}
|
|
412
|
+
if (s1 - s0 <= EPS || shortened && s1 - s0 < Math.max(EPS, minLength - EPS)) continue;
|
|
413
|
+
for (const k of around) {
|
|
414
|
+
if (k.b <= s0 + EPS || k.a >= s1 - EPS || k.c1 <= lo + EPS || k.c0 >= hi - EPS) continue;
|
|
415
|
+
if (k.a <= l0 + EPS !== k.b >= l1 - EPS) continue;
|
|
416
|
+
if ((k.c0 + k.c1) / 2 >= (lo + hi) / 2) hi = Math.min(hi, k.c0);
|
|
417
|
+
else lo = Math.max(lo, k.c1);
|
|
418
|
+
}
|
|
419
|
+
if (hi - lo < Math.max(EPS, min)) continue;
|
|
420
|
+
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 }));
|
|
421
|
+
}
|
|
422
|
+
return out;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// src/drag/hand-speed.ts
|
|
426
|
+
var HAND_SLOW_STEP = 3;
|
|
427
|
+
var HAND_SPEED = { span: 48, steps: 5, gap: 40, slowStep: HAND_SLOW_STEP, accelerating: 1.5, gathering: 1.25 };
|
|
428
|
+
function createHandSpeed(options = {}) {
|
|
429
|
+
const o = { ...HAND_SPEED, ...options };
|
|
430
|
+
let samples = [];
|
|
431
|
+
let step = Infinity;
|
|
432
|
+
let long = null;
|
|
433
|
+
let longs = [];
|
|
434
|
+
return {
|
|
435
|
+
push(p, t) {
|
|
436
|
+
const last = samples[samples.length - 1];
|
|
437
|
+
if (last && t - last.t >= o.gap) {
|
|
438
|
+
const d = Math.hypot(p.x - last.p.x, p.y - last.p.y);
|
|
439
|
+
samples = [{ p, t }];
|
|
440
|
+
step = d <= o.slowStep ? d * 8 / Math.max(1, t - last.t) : Infinity;
|
|
441
|
+
long = null;
|
|
442
|
+
longs = [];
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
step = last ? Math.hypot(p.x - last.p.x, p.y - last.p.y) * 8 / Math.max(1, t - last.t) : Infinity;
|
|
446
|
+
samples.push({ p, t });
|
|
447
|
+
while (samples.length > o.steps + 1 && t - samples[1].t >= o.span) samples.shift();
|
|
448
|
+
const first = samples[0];
|
|
449
|
+
if (samples.length > o.steps && t - first.t >= o.span) {
|
|
450
|
+
let path = 0;
|
|
451
|
+
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);
|
|
452
|
+
long = path * 8 / (t - first.t);
|
|
453
|
+
longs.push({ t, v: long });
|
|
454
|
+
while (longs.length > 1 && t - longs[1].t >= o.span / 2) longs.shift();
|
|
455
|
+
} else long = null;
|
|
456
|
+
},
|
|
457
|
+
reset() {
|
|
458
|
+
samples = [];
|
|
459
|
+
step = Infinity;
|
|
460
|
+
long = null;
|
|
461
|
+
longs = [];
|
|
462
|
+
},
|
|
463
|
+
get step() {
|
|
464
|
+
return step;
|
|
465
|
+
},
|
|
466
|
+
get long() {
|
|
467
|
+
return long;
|
|
468
|
+
},
|
|
469
|
+
get speed() {
|
|
470
|
+
return long === null ? step : Math.max(step, long);
|
|
471
|
+
},
|
|
472
|
+
get steady() {
|
|
473
|
+
const then = longs[0];
|
|
474
|
+
return long !== null && step <= long * o.accelerating && !!then && longs[longs.length - 1].t - then.t >= o.span / 2 && long <= then.v * o.gathering;
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
281
479
|
// src/drag/landing.ts
|
|
282
480
|
var SLIDE_STEP = 1;
|
|
283
481
|
var SNAP_DISTANCE = 8;
|
|
284
482
|
var LANDING_MARGINS = { exit: 12, spot: 6, edge: 48, lift: 16 };
|
|
285
483
|
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:
|
|
484
|
+
var LANDING_GATES = { path: 40, depth: 8, still: 1.5, step: 3, trail: 40, rest: 22, pause: 60, slide: 16 };
|
|
485
|
+
var LANDING_APPROACH = { reach: LANDING_MARGINS.exit, keep: LANDING_MARGINS.exit, nearer: 16 };
|
|
288
486
|
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
487
|
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(
|
|
488
|
+
function depthIn(lane, p, stage) {
|
|
489
|
+
const r = lane.rect;
|
|
291
490
|
if (!strictlyIn(r, p)) return 0;
|
|
292
491
|
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
|
-
];
|
|
492
|
+
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
493
|
return Math.max(0, Math.min(...sides));
|
|
300
494
|
}
|
|
301
495
|
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 +519,21 @@ function createLandingModel(options) {
|
|
|
325
519
|
let moved = null;
|
|
326
520
|
let liftAt = options.lift ?? null;
|
|
327
521
|
let inLiftZone = true;
|
|
522
|
+
let farHeld = false;
|
|
523
|
+
let flung = false;
|
|
524
|
+
let slowFrom = null;
|
|
328
525
|
let lastStep = 0;
|
|
526
|
+
const hand = createHandSpeed({ gap: Math.min(HAND_SPEED.gap, gates.pause) });
|
|
329
527
|
const pathIn = /* @__PURE__ */ new Map();
|
|
330
528
|
const slide = /* @__PURE__ */ new Map();
|
|
331
529
|
const cameIn = /* @__PURE__ */ new Set();
|
|
332
530
|
let approached = null;
|
|
531
|
+
let lastPending = null;
|
|
532
|
+
const pendingIn = (here, p, stage) => {
|
|
533
|
+
const deepest = here.reduce((a, b) => depthIn(b, p, stage) > depthIn(a, p, stage) ? b : a);
|
|
534
|
+
const kept = here.find((l) => l.id === lastPending);
|
|
535
|
+
return kept && depthIn(deepest, p, stage) <= depthIn(kept, p, stage) + margins.spot ? kept.id : deepest.id;
|
|
536
|
+
};
|
|
333
537
|
let previous = laneId ? "lane" : "open";
|
|
334
538
|
let frame = { region: previous, lane: laneId, spot: spotId, landing: null, room: !!spotId, guides: [], shift: false };
|
|
335
539
|
let landedOn = null;
|
|
@@ -395,61 +599,122 @@ function createLandingModel(options) {
|
|
|
395
599
|
}
|
|
396
600
|
return cand;
|
|
397
601
|
}
|
|
398
|
-
function guidesFor(p, region, shift) {
|
|
602
|
+
function guidesFor(p, region, shift, pending, landing) {
|
|
399
603
|
if (guidesLevel === "off" || shift) return [];
|
|
400
604
|
const regions = heldRegions(spotId);
|
|
401
|
-
const all = (
|
|
402
|
-
|
|
605
|
+
const all = (l, near2 = false) => {
|
|
606
|
+
const marks = near2 && l.entry ? l.entry : l.marks;
|
|
607
|
+
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 }));
|
|
608
|
+
};
|
|
609
|
+
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;
|
|
610
|
+
const less = (gs, cs) => {
|
|
611
|
+
if (cs.length === 0) return [...gs];
|
|
612
|
+
const clear = cs.map((rect) => ({ rect, clearance: 0 }));
|
|
613
|
+
return gs.flatMap((g) => cs.some((c) => area2(g.rect, c)) ? guideRects([g], { inside: g.rect, inset: 0, clear, minLength: 0, minThickness: 0 }) : [g]);
|
|
614
|
+
};
|
|
615
|
+
const near = nearLane(p, region, pending, regions);
|
|
616
|
+
const wouldLand = (l) => {
|
|
617
|
+
if (l.id === laneId) return region === "lane" ? landing : null;
|
|
618
|
+
const s = pick(l, alongOf(l, p));
|
|
619
|
+
return s ? landingAt(l, s, p, regions.item) : null;
|
|
620
|
+
};
|
|
621
|
+
const nearGuides = (l) => {
|
|
622
|
+
const at = l.marks || l.entry ? wouldLand(l) : null;
|
|
623
|
+
if (!at) return all(l, true);
|
|
624
|
+
const longEnough = (g) => g.kind !== "box" || (l.axis === "x" ? g.rect.width : g.rect.height) > MIN_BOX_LENGTH;
|
|
625
|
+
const whole = all(l, true);
|
|
626
|
+
return less(whole, [at]).filter((g) => longEnough(g) || whole.some((w) => w.id === g.id && w.rect === g.rect));
|
|
627
|
+
};
|
|
628
|
+
if (guidesLevel === "near") return near ? nearGuides(near) : [];
|
|
629
|
+
const owns = (l) => !!l && !!l.entry && !!l.corners?.length;
|
|
630
|
+
let owner = owns(near) ? near : null;
|
|
631
|
+
if (!owner && !near) {
|
|
632
|
+
let d = approach.reach;
|
|
633
|
+
for (const l of regions.lanes) {
|
|
634
|
+
const dl = distanceTo2(l.rect, p);
|
|
635
|
+
if (owns(l) && dl <= d) {
|
|
636
|
+
owner = l;
|
|
637
|
+
d = dl;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
const ownerMarks = owner ? nearGuides(owner) : [];
|
|
642
|
+
const cutBy = owner ? owner.entry.map((m) => m.rect) : [];
|
|
643
|
+
return regions.lanes.flatMap((l) => {
|
|
644
|
+
if (owner && l.id === owner.id) return ownerMarks;
|
|
645
|
+
if (near && l.id === near.id) return nearGuides(l);
|
|
646
|
+
return owner?.corners.includes(l.id) ? less(all(l), cutBy) : all(l);
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
function nearLane(p, region, pending, regions) {
|
|
403
650
|
if ((region === "lane" || region === "refused") && laneId) {
|
|
404
651
|
approached = laneId;
|
|
405
|
-
|
|
406
|
-
|
|
652
|
+
return laneIn(regions, laneId) ?? null;
|
|
653
|
+
}
|
|
654
|
+
if (pending) {
|
|
655
|
+
approached = pending;
|
|
656
|
+
return laneIn(regions, pending) ?? null;
|
|
657
|
+
}
|
|
658
|
+
if (region !== "open") {
|
|
659
|
+
approached = null;
|
|
660
|
+
return null;
|
|
407
661
|
}
|
|
408
662
|
let best = null;
|
|
409
663
|
let bestD = Infinity;
|
|
410
|
-
for (const
|
|
411
|
-
const d = distanceTo2(
|
|
664
|
+
for (const l of regions.lanes) {
|
|
665
|
+
const d = distanceTo2(l.rect, p);
|
|
412
666
|
if (d < bestD) {
|
|
413
|
-
best =
|
|
667
|
+
best = l;
|
|
414
668
|
bestD = d;
|
|
415
669
|
}
|
|
416
670
|
}
|
|
417
|
-
|
|
418
|
-
approached = best?.id ?? null;
|
|
419
|
-
return best ? all(best) : [];
|
|
420
|
-
}
|
|
671
|
+
const acquire = Math.max(0, approach.reach - margins.spot, approach.reach / 2);
|
|
421
672
|
const kept = laneIn(regions, approached);
|
|
422
673
|
if (kept) {
|
|
423
674
|
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 <=
|
|
426
|
-
} else approached = best && bestD <=
|
|
427
|
-
|
|
428
|
-
return l ? all(l) : [];
|
|
675
|
+
if (d > Math.max(approach.keep, approach.reach)) approached = null;
|
|
676
|
+
else if (best && best.id !== kept.id && bestD + approach.nearer < d) approached = bestD <= acquire ? best.id : null;
|
|
677
|
+
} else approached = best && bestD <= acquire ? best.id : null;
|
|
678
|
+
return laneIn(regions, approached) ?? null;
|
|
429
679
|
}
|
|
430
680
|
function update(raw, t, keys) {
|
|
431
681
|
const p = ontoStage(heldRegions(spotId).stage, raw, margins.edge) ?? raw;
|
|
432
682
|
let step = 0;
|
|
433
683
|
if (moved && (raw.x !== moved.raw.x || raw.y !== moved.raw.y)) {
|
|
684
|
+
const before = moved.t;
|
|
434
685
|
step = Math.hypot(raw.x - moved.raw.x, raw.y - moved.raw.y) * 8 / Math.max(1, t - moved.t);
|
|
435
686
|
moved = { raw, t };
|
|
687
|
+
hand.push(raw, t);
|
|
688
|
+
step = hand.step;
|
|
436
689
|
lastStep = step;
|
|
690
|
+
const sp = hand.speed;
|
|
691
|
+
if (Number.isFinite(sp) && sp > gates.slide) {
|
|
692
|
+
flung = true;
|
|
693
|
+
slowFrom = null;
|
|
694
|
+
} else if (!Number.isFinite(sp) || sp > gates.step) slowFrom = null;
|
|
695
|
+
else slowFrom ??= before;
|
|
437
696
|
} else if (moved) {
|
|
438
697
|
const stage = heldRegions(spotId).stage;
|
|
439
698
|
const onEdge = p.x <= stage.x || p.y <= stage.y || p.x >= stage.x + stage.width || p.y >= stage.y + stage.height;
|
|
440
699
|
const since = t - moved.t;
|
|
441
700
|
step = since >= gates.pause || since >= gates.rest && (lastStep <= gates.step || onEdge) ? 0 : lastStep;
|
|
701
|
+
slowFrom ??= moved.t;
|
|
442
702
|
} else {
|
|
443
703
|
moved = { raw, t };
|
|
704
|
+
hand.reset();
|
|
705
|
+
hand.push(raw, t);
|
|
444
706
|
liftAt ??= p;
|
|
445
707
|
step = lastStep = Infinity;
|
|
446
708
|
}
|
|
709
|
+
if (flung && slowFrom !== null && t - slowFrom >= gates.pause) flung = false;
|
|
710
|
+
const edgeStage = heldRegions(spotId).stage;
|
|
711
|
+
const settled = !flung || p.x <= edgeStage.x || p.y <= edgeStage.y || p.x >= edgeStage.x + edgeStage.width || p.y >= edgeStage.y + edgeStage.height;
|
|
447
712
|
const from = last?.p ?? null;
|
|
448
713
|
const fromRaw = last?.raw ?? null;
|
|
449
714
|
last = { p, raw, t };
|
|
450
715
|
const shift = !!keys?.shift;
|
|
451
716
|
const regions = heldRegions(spotId);
|
|
452
|
-
const slow = step <= gates.step;
|
|
717
|
+
const slow = Number.isFinite(hand.speed) ? hand.speed <= gates.step : step <= gates.step;
|
|
453
718
|
for (const l of regions.lanes) {
|
|
454
719
|
const was = from && strictlyIn(l.rect, from);
|
|
455
720
|
const go = was ? Math.abs(alongOf(l, p) - alongOf(l, from)) : 0;
|
|
@@ -457,7 +722,8 @@ function createLandingModel(options) {
|
|
|
457
722
|
const inL = strictlyIn(l.rect, p);
|
|
458
723
|
pathIn.set(l.id, inL ? (pathIn.get(l.id) ?? 0) + (slow ? go : 0) : 0);
|
|
459
724
|
const s = slide.get(l.id);
|
|
460
|
-
|
|
725
|
+
const counts = hand.steady && hand.speed <= gates.slide;
|
|
726
|
+
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
727
|
if (l.owns && !inL) cameIn.add(l.id);
|
|
462
728
|
}
|
|
463
729
|
let region;
|
|
@@ -467,10 +733,10 @@ function createLandingModel(options) {
|
|
|
467
733
|
laneId = spotId = null;
|
|
468
734
|
} else {
|
|
469
735
|
const held2 = laneIn(regions, laneId);
|
|
470
|
-
const gate = (l) => (pathIn.get(l.id) ?? 0) >= gates.path || depthIn(l
|
|
736
|
+
const gate = (l) => (pathIn.get(l.id) ?? 0) >= gates.path || depthIn(l, p, regions.stage) >= gates.depth && step <= gates.still && settled;
|
|
471
737
|
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
738
|
const sl = touching ? slide.get(touching.id) : void 0;
|
|
473
|
-
const slid = !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along;
|
|
739
|
+
const slid = !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along && hand.speed <= gates.slide;
|
|
474
740
|
const liftR = margins.lift ?? 16;
|
|
475
741
|
if (liftAt) {
|
|
476
742
|
const far = Math.hypot(p.x - liftAt.x, p.y - liftAt.y);
|
|
@@ -480,33 +746,37 @@ function createLandingModel(options) {
|
|
|
480
746
|
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
747
|
const ownLane = nearLift && options.home ? laneIn(regions, options.home.lane) : void 0;
|
|
482
748
|
const homeHere = ownLane && strictlyIn(ownLane.rect, p) ? ownLane : void 0;
|
|
483
|
-
const
|
|
749
|
+
const lanesHere = regions.lanes.filter((l) => strictlyIn(l.rect, p) && !(l.owns && nearLift));
|
|
750
|
+
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;
|
|
751
|
+
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));
|
|
752
|
+
const next = homeHere ? void 0 : owner ?? (touching && (gate(touching) || slid || overRefused(touching)) ? touching : void 0);
|
|
753
|
+
if (!(held2 && !homeHere && !next && (touching || inside(held2.rect, p, margins.exit)))) farHeld = false;
|
|
484
754
|
if (homeHere) {
|
|
485
755
|
const s = spotIn(homeHere, options.home.spot) ?? pick(homeHere, alongOf(homeHere, p));
|
|
486
756
|
laneId = homeHere.id;
|
|
487
757
|
spotId = s?.id ?? null;
|
|
488
758
|
region = s ? "lane" : "refused";
|
|
489
759
|
} else if (held2 && !next && (touching || inside(held2.rect, p, margins.exit))) {
|
|
490
|
-
const
|
|
760
|
+
const d = distanceTo2(held2.rect, p);
|
|
761
|
+
farHeld = farHeld ? d > margins.exit + gates.path - margins.spot : d > margins.exit + gates.path;
|
|
762
|
+
const far = farHeld;
|
|
763
|
+
const s = far ? null : along(held2, p, step);
|
|
491
764
|
spotId = s?.id ?? spotId;
|
|
492
765
|
region = s ? "lane" : "refused";
|
|
493
766
|
if (!s) spotId = null;
|
|
494
|
-
if (!s && !strictlyIn(held2.rect, p)) {
|
|
767
|
+
if (!s && !far && !strictlyIn(held2.rect, p)) {
|
|
495
768
|
const others = regions.lanes.filter((l) => l.id !== held2.id && strictlyIn(l.rect, p));
|
|
496
|
-
if (others.length > 0) pending = others
|
|
769
|
+
if (others.length > 0) pending = pendingIn(others, p, regions.stage);
|
|
497
770
|
}
|
|
498
771
|
} else {
|
|
499
772
|
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
773
|
let entered = next ?? null;
|
|
504
774
|
if (!entered)
|
|
505
775
|
for (const l of lanesHere) {
|
|
506
|
-
const deep = depthIn(l
|
|
507
|
-
if ((gate(l) || overRefused(l)) && (!entered || deep > depthIn(entered
|
|
776
|
+
const deep = depthIn(l, p, regions.stage);
|
|
777
|
+
if ((gate(l) || overRefused(l)) && (!entered || deep > depthIn(entered, p, regions.stage))) entered = l;
|
|
508
778
|
}
|
|
509
|
-
if (!entered && lanesHere.length > 0) pending = lanesHere
|
|
779
|
+
if (!entered && lanesHere.length > 0) pending = pendingIn(lanesHere, p, regions.stage);
|
|
510
780
|
if (entered) {
|
|
511
781
|
laneId = entered.id;
|
|
512
782
|
const s = pick(entered, alongOf(entered, p));
|
|
@@ -519,6 +789,7 @@ function createLandingModel(options) {
|
|
|
519
789
|
}
|
|
520
790
|
}
|
|
521
791
|
previous = region;
|
|
792
|
+
lastPending = pending;
|
|
522
793
|
const shown = shift && (region === "lane" || region === "open") ? "open" : region;
|
|
523
794
|
const r2 = heldRegions(spotId);
|
|
524
795
|
const heldLane = laneIn(r2, laneId);
|
|
@@ -531,7 +802,7 @@ function createLandingModel(options) {
|
|
|
531
802
|
spot: shown === "lane" ? spotId : null,
|
|
532
803
|
landing,
|
|
533
804
|
room: shown === "lane" && !!spot,
|
|
534
|
-
guides: guidesFor(p, shown, shift),
|
|
805
|
+
guides: guidesFor(p, shown, shift, pending && shown !== "lane" ? pending : null, landing),
|
|
535
806
|
shift,
|
|
536
807
|
...pending && shown !== "lane" ? { pending } : {}
|
|
537
808
|
};
|
|
@@ -564,6 +835,10 @@ function createLandingModel(options) {
|
|
|
564
835
|
hide() {
|
|
565
836
|
laneId = spotId = null;
|
|
566
837
|
approached = null;
|
|
838
|
+
lastPending = null;
|
|
839
|
+
farHeld = false;
|
|
840
|
+
flung = false;
|
|
841
|
+
slowFrom = null;
|
|
567
842
|
pathIn.clear();
|
|
568
843
|
slide.clear();
|
|
569
844
|
cameIn.clear();
|
|
@@ -635,81 +910,6 @@ function createGripPress(options = {}) {
|
|
|
635
910
|
}
|
|
636
911
|
};
|
|
637
912
|
}
|
|
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 finite = (r) => Number.isFinite(r.x) && Number.isFinite(r.y) && Number.isFinite(r.width) && Number.isFinite(r.height);
|
|
652
|
-
const allClear = (options.clear ?? []).map(
|
|
653
|
-
(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 }
|
|
654
|
-
).filter((c) => finite(c.k));
|
|
655
|
-
const out = [];
|
|
656
|
-
for (const g of guides) {
|
|
657
|
-
const r = g.rect;
|
|
658
|
-
const clear = allClear.filter((c) => !c.kinds || c.kinds.includes(g.kind));
|
|
659
|
-
if (g.kind === "box") {
|
|
660
|
-
let a = Math.max(r.x, x0);
|
|
661
|
-
let b = Math.max(r.y, y0);
|
|
662
|
-
let c = Math.min(r.x + r.width, x1);
|
|
663
|
-
let d = Math.min(r.y + r.height, y1);
|
|
664
|
-
for (const { k, gap: gap2 } of clear) {
|
|
665
|
-
const k0 = k.x - gap2;
|
|
666
|
-
const k1 = k.x + k.width + gap2;
|
|
667
|
-
const l0 = k.y - gap2;
|
|
668
|
-
const l1 = k.y + k.height + gap2;
|
|
669
|
-
if (c - a <= EPS || d - b <= EPS) break;
|
|
670
|
-
if (k1 <= a + EPS || k0 >= c - EPS || l1 <= b + EPS || l0 >= d - EPS) continue;
|
|
671
|
-
const parts = [
|
|
672
|
-
{ a, b, c: Math.min(c, k0), d },
|
|
673
|
-
{ a: Math.max(a, k1), b, c, d },
|
|
674
|
-
{ a, b, c, d: Math.min(d, l0) },
|
|
675
|
-
{ a, b: Math.max(b, l1), c, d }
|
|
676
|
-
].filter((p) => p.c - p.a > EPS && p.d - p.b > EPS);
|
|
677
|
-
if (parts.length === 0) {
|
|
678
|
-
c = a;
|
|
679
|
-
break;
|
|
680
|
-
}
|
|
681
|
-
const best = parts.reduce((p, q) => (q.c - q.a) * (q.d - q.b) > (p.c - p.a) * (p.d - p.b) ? q : p);
|
|
682
|
-
({ a, b, c, d } = best);
|
|
683
|
-
}
|
|
684
|
-
if (c - a > EPS && d - b > EPS) out.push(place(g, { x: a, y: b, width: c - a, height: d - b }));
|
|
685
|
-
continue;
|
|
686
|
-
}
|
|
687
|
-
const thinX = r.width <= r.height;
|
|
688
|
-
const t = thinX ? r.width : r.height;
|
|
689
|
-
let lo = thinX ? r.x : r.y;
|
|
690
|
-
const lim0 = thinX ? x0 : y0;
|
|
691
|
-
const lim1 = thinX ? x1 : y1;
|
|
692
|
-
if (lo + t > lim1) lo = lim1 - t;
|
|
693
|
-
if (lo < lim0) lo = lim0;
|
|
694
|
-
let hi = Math.min(lo + t, lim1);
|
|
695
|
-
const s0 = Math.max(thinX ? r.y : r.x, thinX ? y0 : x0);
|
|
696
|
-
const s1 = Math.min(thinX ? r.y + r.height : r.x + r.width, thinX ? y1 : x1);
|
|
697
|
-
if (s1 - s0 <= EPS) continue;
|
|
698
|
-
for (const { k: c, gap: gap2 } of clear) {
|
|
699
|
-
const cs0 = (thinX ? c.y : c.x) - gap2;
|
|
700
|
-
const cs1 = (thinX ? c.y + c.height : c.x + c.width) + gap2;
|
|
701
|
-
if (cs1 <= s0 + EPS || cs0 >= s1 - EPS) continue;
|
|
702
|
-
const c0 = (thinX ? c.x : c.y) - gap2;
|
|
703
|
-
const c1 = (thinX ? c.x + c.width : c.y + c.height) + gap2;
|
|
704
|
-
if (c1 <= lo + EPS || c0 >= hi - EPS) continue;
|
|
705
|
-
if ((c0 + c1) / 2 >= (lo + hi) / 2) hi = Math.min(hi, c0);
|
|
706
|
-
else lo = Math.max(lo, c1);
|
|
707
|
-
}
|
|
708
|
-
if (hi - lo < Math.max(EPS, min)) continue;
|
|
709
|
-
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 }));
|
|
710
|
-
}
|
|
711
|
-
return out;
|
|
712
|
-
}
|
|
713
913
|
export {
|
|
714
914
|
DOUBLE_CLICK,
|
|
715
915
|
DRAG_DEFAULTS,
|
|
@@ -718,6 +918,7 @@ export {
|
|
|
718
918
|
LANDING_GATES,
|
|
719
919
|
LANDING_MARGINS,
|
|
720
920
|
LANDING_TOUCH_MARGINS,
|
|
921
|
+
MIN_BOX_LENGTH,
|
|
721
922
|
PLACE_GUIDES_DEFAULT,
|
|
722
923
|
REFUSAL_RANK,
|
|
723
924
|
SNAP_DISTANCE,
|