@n-uf/motion 26.11.47 → 26.11.49

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.d.ts CHANGED
@@ -411,20 +411,29 @@ declare const DRAG_PREVIEW_DEFAULT: DragPreview;
411
411
  * none; `"near"`: the places of the edge the pointer approaches; `"all"`: every place, from the lift.
412
412
  */
413
413
  type PlaceGuides = "off" | "near" | "all";
414
+ /**
415
+ * How a place guide draws an empty lane (an empty bar or side rail, its room not open yet): `"real"`, a box at the size
416
+ * the lane will take, over what moves aside (the page, a column); `"edge"`, a thin striped strip on the lane's window
417
+ * side. The landing is the same either way. Placement's `lanes()` takes it as `emptyLanes`.
418
+ */
419
+ type EmptyLanes = "real" | "edge";
414
420
  /**
415
421
  * A drop preview as a mode and its place guides, beside the string forms: `"outline"` is `"indicator"`'s plan,
416
422
  * `"placeholder"` is `"gap"`'s, and `"snap"` is `"item"`'s (the item the only preview). `placeGuides` defaults per mode
417
- * ({@link PLACE_GUIDES_DEFAULT}).
423
+ * ({@link PLACE_GUIDES_DEFAULT}); `emptyLanes` (how its guides draw an empty lane) defaults to `"real"`.
418
424
  */
419
425
  type DropPreviewMode = {
420
426
  readonly mode: "outline";
421
427
  readonly placeGuides?: PlaceGuides;
428
+ readonly emptyLanes?: EmptyLanes;
422
429
  } | {
423
430
  readonly mode: "placeholder";
424
431
  readonly placeGuides?: PlaceGuides;
432
+ readonly emptyLanes?: EmptyLanes;
425
433
  } | {
426
434
  readonly mode: "snap";
427
435
  readonly placeGuides?: PlaceGuides;
436
+ readonly emptyLanes?: EmptyLanes;
428
437
  };
429
438
  /** Each mode's place guides when it names none: Snap and Placeholder near, Outline none. */
430
439
  declare const PLACE_GUIDES_DEFAULT: Readonly<Record<DropPreviewMode["mode"], PlaceGuides>>;
@@ -443,6 +452,8 @@ interface PreviewPlan {
443
452
  * `"off"`.
444
453
  */
445
454
  readonly guides?: PlaceGuides;
455
+ /** How the guides draw an empty lane (the object form's `emptyLanes`, `"real"` when it names none); absent for the string forms. */
456
+ readonly emptyLanes?: EmptyLanes;
446
457
  }
447
458
  /**
448
459
  * The plan for a frame of the drag intent under `preview`. `slotted` says
@@ -477,7 +488,14 @@ declare function previewPlan<T extends DragTarget>(frame: Pick<DragFrame<T>, "sh
477
488
  * face into the stage (on the edge it is deep). A fly-through of a thin bar or rail at any angle meets neither, so its
478
489
  * room never opens. Inside a lane that touches the held one, past the held lane's exit margin, the held lane holds
479
490
  * until that lane's gate passes or the pointer has slid `path` px along it at any speed (across it at most a third as
480
- * far): lane to lane never passes through the float, and never opens a crossed lane's room.
491
+ * far): lane to lane never passes through the float, and never opens a crossed lane's room. Over a refused place (a
492
+ * lane's band lying over a column that takes nothing: an empty side rail's) a lane is entered on the first slow step
493
+ * there (not on the lift), as there is nothing else to mean there; a fly-through still opens no room. A lane that owns
494
+ * its rect (`owns`: a rail drop strip at the window's side) takes the pointer inside it from any lane it overlaps, a
495
+ * held one too, once its own gate passes and only once the pointer came into it from outside since the lift. Within
496
+ * `margins.lift` of the lift point (`options.lift`, else the first point; fixed for the drag) an owning lane takes the
497
+ * pointer by no gate, so a pointer brought back there is in the item's own lane, not the strip. Elsewhere in the strip
498
+ * a slow slide along it can take the pointer before it is back at the lift point.
481
499
  * - **Along a lane** the spot changes once the pointer is `spot` px past the boundary; where the change moves another
482
500
  * item (the two spots' `others` keys differ), on a step of at most `step`, or once the held landing trails the
483
501
  * pointer by more than `trail`: the item chases only as far as it must. A change that moves only the held item
@@ -508,11 +526,14 @@ interface LandingSpot {
508
526
  */
509
527
  readonly others?: string;
510
528
  }
511
- /** A place guide's mark: a line between two items, a box over a free stretch, in the layout as drawn. */
529
+ /**
530
+ * A place guide's mark, in the layout as drawn: a line between two items that touch, a box over free room the item
531
+ * lands in, a hatch over the part of a neighbor that gives way where the room is shorter than the item.
532
+ */
512
533
  interface LandingMark {
513
534
  /** Stable while its neighbors stay; absent, the guide is keyed by its lane and place in the list. */
514
535
  readonly id?: string;
515
- readonly kind: "line" | "box";
536
+ readonly kind: "line" | "box" | "hatch";
516
537
  readonly rect: Rect;
517
538
  }
518
539
  interface LandingLane {
@@ -525,6 +546,11 @@ interface LandingLane {
525
546
  }[];
526
547
  /** Its guides' marks; absent, its spots' landings are the guides. */
527
548
  readonly marks?: readonly LandingMark[];
549
+ /**
550
+ * Its rect is its own (a rail drop strip at the window's side): inside it, once its gate passes, it takes the pointer
551
+ * from any lane it overlaps, a held one too. Absent: where lanes overlap, the deeper one wins.
552
+ */
553
+ readonly owns?: boolean;
528
554
  }
529
555
  /** A drag's regions (`lanes()` gives them). */
530
556
  interface LandingRegions {
@@ -546,6 +572,11 @@ interface LandingMargins {
546
572
  readonly spot: number;
547
573
  /** Past the stage that still counts as on its edge, px; beyond, nowhere. */
548
574
  readonly edge: number;
575
+ /**
576
+ * Around the lift point, px (16, as the drag intent's `liftZone`): an owning lane never takes the pointer there, so
577
+ * away and back to where the item was lifted is home.
578
+ */
579
+ readonly lift?: number;
549
580
  }
550
581
  interface LandingGates {
551
582
  /** Pointer path inside a lane that enters it, px. */
@@ -591,6 +622,8 @@ interface LandingOptions {
591
622
  readonly lane: string;
592
623
  readonly spot: string;
593
624
  };
625
+ /** Where the item was lifted (the press), in the regions' space; default the first point `update` gets. */
626
+ readonly lift?: Point;
594
627
  readonly margins?: Partial<LandingMargins>;
595
628
  readonly gates?: Partial<LandingGates>;
596
629
  readonly approach?: Partial<LandingApproach>;
@@ -602,7 +635,8 @@ interface LandingGuide {
602
635
  /** Stable while its neighbors stay: the mark's id, else `<lane>/<spot id>` for a spot's landing. Key a drawing by it. */
603
636
  readonly id: string;
604
637
  readonly lane: string;
605
- readonly kind: "line" | "box";
638
+ /** A line, a box, or a hatch over a neighbor that gives way (draw it over that item, in the guides' color). */
639
+ readonly kind: "line" | "box" | "hatch";
606
640
  readonly rect: Rect;
607
641
  }
608
642
  interface LandingFrame {
@@ -618,6 +652,12 @@ interface LandingFrame {
618
652
  readonly guides: readonly LandingGuide[];
619
653
  /** Shift held: the region is open space wherever it was a lane or open space. */
620
654
  readonly shift: boolean;
655
+ /**
656
+ * The lane the pointer is inside but hasn't entered (its gate not passed yet: a fast pass, or the moment before a slow
657
+ * step), else absent. A host shows no "Can't go here" while it is set, though a release now lands nowhere: the place
658
+ * under the pointer is a lane's, not a refused one.
659
+ */
660
+ readonly pending?: string;
621
661
  }
622
662
  /** What a release lands: a spot (`home` when it is the item's own place), the float at `rect`, or nothing. */
623
663
  type LandingRelease = {
@@ -681,4 +721,29 @@ declare function createGripPress(options?: {
681
721
  readonly double?: Partial<DoubleClick>;
682
722
  }): GripPress;
683
723
 
684
- export { DRAG_DEFAULTS, DRAG_PREVIEW_DEFAULT, DoubleClick, type DragFrame, type DragIntent, type DragIntentOptions, type DragIntentState, type DragKeys, type DragModifiers, type DragPreview, type DragTarget, type DragTuning, type DropPreviewMode, type GripPress, type GripRelease, LANDING_APPROACH, LANDING_GATES, LANDING_MARGINS, LANDING_TOUCH_MARGINS, type LandingApproach, type LandingFrame, type LandingGates, type LandingGuide, type LandingLane, type LandingMargins, type LandingMark, type LandingModel, type LandingOptions, type LandingRegion, type LandingRegions, type LandingRelease, type LandingSpot, type LiftDecision, type ModifierKey, PLACE_GUIDES_DEFAULT, type PlaceGuides, type PreviewPlan, REFUSAL_RANK, createDragIntent, createGripPress, createLandingModel, inRect, liftDecision, pickRank, previewPlan, targetAt };
724
+ /** A guide to place: any record with a `kind` and a `rect` (a landing model's `LandingGuide`, a lane's marks). */
725
+ interface PlacedGuide {
726
+ readonly kind: "line" | "box" | "hatch";
727
+ readonly rect: Rect;
728
+ }
729
+ interface GuideRectsOptions {
730
+ /** The area guides are drawn in: the window's inside (inside its border), px. */
731
+ readonly inside: Rect;
732
+ /** How far inside `inside` every guide stays, px (default 2). */
733
+ readonly inset?: number;
734
+ /** Rects a thin guide stays clear of (the content: a column's panels under an empty lane's thin edge). */
735
+ readonly clear?: readonly Rect[];
736
+ /** The least thickness a thin guide keeps, px (default 2); thinner, it is not drawn. */
737
+ readonly minThickness?: number;
738
+ }
739
+ /**
740
+ * Where to draw guides: every guide inside `inside` by `inset`. A box is clipped. A thin guide (a line, a striped
741
+ * strip or end: its shorter side is its thickness) keeps its thickness and moves inside rather than being clipped, so
742
+ * a line at a lane's far end is as thick as at its head. Then it is thinned, from the content side, to stay clear of
743
+ * `clear`, so a thin strip at the window's side lies between the inset and the content, the same on both sides. A
744
+ * guide with nothing left (or a thin one under `minThickness`) is left out. Pure; the guides come back as given with
745
+ * their placed `rect`.
746
+ */
747
+ declare function guideRects<G extends PlacedGuide>(guides: readonly G[], options: GuideRectsOptions): G[];
748
+
749
+ export { DRAG_DEFAULTS, DRAG_PREVIEW_DEFAULT, DoubleClick, type DragFrame, type DragIntent, type DragIntentOptions, type DragIntentState, type DragKeys, type DragModifiers, type DragPreview, type DragTarget, type DragTuning, type DropPreviewMode, type EmptyLanes, type GripPress, type GripRelease, type GuideRectsOptions, LANDING_APPROACH, LANDING_GATES, LANDING_MARGINS, LANDING_TOUCH_MARGINS, type LandingApproach, type LandingFrame, type LandingGates, type LandingGuide, type LandingLane, type LandingMargins, type LandingMark, type LandingModel, type LandingOptions, type LandingRegion, type LandingRegions, type LandingRelease, type LandingSpot, type LiftDecision, type ModifierKey, PLACE_GUIDES_DEFAULT, type PlaceGuides, type PlacedGuide, type PreviewPlan, REFUSAL_RANK, createDragIntent, createGripPress, createLandingModel, guideRects, inRect, liftDecision, pickRank, previewPlan, targetAt };
package/dist/drag.js CHANGED
@@ -279,8 +279,8 @@ function createDragIntent(options) {
279
279
  }
280
280
 
281
281
  // src/drag/landing.ts
282
- var LANDING_MARGINS = { exit: 12, spot: 6, edge: 48 };
283
- var LANDING_TOUCH_MARGINS = { exit: 16, spot: 8, edge: 48 };
282
+ var LANDING_MARGINS = { exit: 12, spot: 6, edge: 48, lift: 16 };
283
+ var LANDING_TOUCH_MARGINS = { exit: 16, spot: 8, edge: 48, lift: 16 };
284
284
  var LANDING_GATES = { path: 40, depth: 8, still: 1.5, step: 3, trail: 40, rest: 22, pause: 60 };
285
285
  var LANDING_APPROACH = { reach: 80, keep: 96, nearer: 16 };
286
286
  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;
@@ -321,9 +321,11 @@ function createLandingModel(options) {
321
321
  let spotId = options.home?.spot ?? null;
322
322
  let last = null;
323
323
  let moved = null;
324
+ let liftAt = options.lift ?? null;
324
325
  let lastStep = 0;
325
326
  const pathIn = /* @__PURE__ */ new Map();
326
327
  const slide = /* @__PURE__ */ new Map();
328
+ const cameIn = /* @__PURE__ */ new Set();
327
329
  let approached = null;
328
330
  let previous = laneId ? "lane" : "open";
329
331
  let frame = { region: previous, lane: laneId, spot: spotId, landing: null, room: !!spotId, guides: [], shift: false };
@@ -409,6 +411,7 @@ function createLandingModel(options) {
409
411
  step = since >= gates.pause || since >= gates.rest && (lastStep <= gates.step || onEdge) ? 0 : lastStep;
410
412
  } else {
411
413
  moved = { raw, t };
414
+ liftAt ??= p;
412
415
  step = lastStep = Infinity;
413
416
  }
414
417
  const from = last?.p ?? null;
@@ -425,8 +428,10 @@ function createLandingModel(options) {
425
428
  pathIn.set(l.id, inL ? (pathIn.get(l.id) ?? 0) + (slow ? go : 0) : 0);
426
429
  const s = slide.get(l.id);
427
430
  slide.set(l.id, inL ? { along: (s?.along ?? 0) + go, across: (s?.across ?? 0) + over } : { along: 0, across: 0 });
431
+ if (l.owns && !inL) cameIn.add(l.id);
428
432
  }
429
433
  let region;
434
+ let pending = null;
430
435
  if (!inside(regions.stage, p)) {
431
436
  region = "nowhere";
432
437
  laneId = spotId = null;
@@ -436,21 +441,30 @@ function createLandingModel(options) {
436
441
  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;
437
442
  const sl = touching ? slide.get(touching.id) : void 0;
438
443
  const slid = !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along;
439
- const next = touching && (gate(touching) || slid) ? touching : void 0;
444
+ const nearLift = !!liftAt && Math.hypot(p.x - liftAt.x, p.y - liftAt.y) <= (margins.lift ?? 16);
445
+ 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));
446
+ const next = owner ?? (touching && (gate(touching) || slid) ? touching : void 0);
440
447
  if (held2 && !next && (touching || inside(held2.rect, p, margins.exit))) {
441
448
  const s = along(held2, p, step);
442
449
  spotId = s?.id ?? spotId;
443
450
  region = s ? "lane" : "refused";
444
451
  if (!s) spotId = null;
452
+ if (!s && !strictlyIn(held2.rect, p)) {
453
+ const others = regions.lanes.filter((l) => l.id !== held2.id && strictlyIn(l.rect, p));
454
+ if (others.length > 0) pending = others.reduce((a, b) => depthIn(b.rect, p, regions.stage) > depthIn(a.rect, p, regions.stage) ? b : a).id;
455
+ }
445
456
  } else {
446
457
  laneId = spotId = null;
458
+ const lanesHere = regions.lanes.filter((l) => strictlyIn(l.rect, p) && !(l.owns && nearLift));
459
+ 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;
460
+ const overRefused = (l) => Number.isFinite(step) && step <= gates.step && lanesHere.length === 1 && [...regions.blocked, ...regions.refused].some((b) => strictlyIn(b, p) && !within2(b, l));
447
461
  let entered = next ?? null;
448
462
  if (!entered)
449
- for (const l of regions.lanes) {
450
- if (!strictlyIn(l.rect, p)) continue;
463
+ for (const l of lanesHere) {
451
464
  const deep = depthIn(l.rect, p, regions.stage);
452
- if (gate(l) && (!entered || deep > depthIn(entered.rect, p, regions.stage))) entered = l;
465
+ if ((gate(l) || overRefused(l)) && (!entered || deep > depthIn(entered.rect, p, regions.stage))) entered = l;
453
466
  }
467
+ 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;
454
468
  if (entered) {
455
469
  laneId = entered.id;
456
470
  const s = pick(entered, alongOf(entered, p));
@@ -474,7 +488,8 @@ function createLandingModel(options) {
474
488
  landing,
475
489
  room: shown === "lane" && !!spot,
476
490
  guides: guidesFor(p, shown, shift),
477
- shift
491
+ shift,
492
+ ...pending && shown !== "lane" ? { pending } : {}
478
493
  };
479
494
  return frame;
480
495
  }
@@ -498,6 +513,7 @@ function createLandingModel(options) {
498
513
  approached = null;
499
514
  pathIn.clear();
500
515
  slide.clear();
516
+ cameIn.clear();
501
517
  last = moved = null;
502
518
  lastStep = 0;
503
519
  },
@@ -516,7 +532,7 @@ function previewPlan(frame, preview, slotted = !!frame.shown && !frame.shown.fre
516
532
  const plan = stringPlan(frame, PLAN_OF[preview.mode], slotted);
517
533
  const asked = preview.placeGuides ?? PLACE_GUIDES_DEFAULT[preview.mode];
518
534
  const landing = plan.showIndicator || plan.makeRoom || plan.snapItem;
519
- return { ...plan, guides: landing ? "off" : asked };
535
+ return { ...plan, guides: landing ? "off" : asked, emptyLanes: preview.emptyLanes ?? "real" };
520
536
  }
521
537
  return stringPlan(frame, preview, slotted);
522
538
  }
@@ -566,6 +582,56 @@ function createGripPress(options = {}) {
566
582
  }
567
583
  };
568
584
  }
585
+
586
+ // src/drag/guide-rects.ts
587
+ var EPS = 1e-6;
588
+ function guideRects(guides, options) {
589
+ const inset = Number.isFinite(options.inset) ? Math.max(0, options.inset) : 2;
590
+ const min = Number.isFinite(options.minThickness) ? Math.max(0, options.minThickness) : 2;
591
+ 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;
592
+ const place = (g, rect) => same(g.rect, rect) ? g : { ...g, rect };
593
+ const x0 = options.inside.x + inset;
594
+ const y0 = options.inside.y + inset;
595
+ const x1 = options.inside.x + options.inside.width - inset;
596
+ const y1 = options.inside.y + options.inside.height - inset;
597
+ const clear = options.clear ?? [];
598
+ const out = [];
599
+ for (const g of guides) {
600
+ const r = g.rect;
601
+ if (g.kind === "box") {
602
+ const a = Math.max(r.x, x0);
603
+ const b = Math.max(r.y, y0);
604
+ const c = Math.min(r.x + r.width, x1);
605
+ const d = Math.min(r.y + r.height, y1);
606
+ if (c - a > EPS && d - b > EPS) out.push(place(g, { x: a, y: b, width: c - a, height: d - b }));
607
+ continue;
608
+ }
609
+ const thinX = r.width <= r.height;
610
+ const t = thinX ? r.width : r.height;
611
+ let lo = thinX ? r.x : r.y;
612
+ const lim0 = thinX ? x0 : y0;
613
+ const lim1 = thinX ? x1 : y1;
614
+ if (lo + t > lim1) lo = lim1 - t;
615
+ if (lo < lim0) lo = lim0;
616
+ let hi = Math.min(lo + t, lim1);
617
+ const s0 = Math.max(thinX ? r.y : r.x, thinX ? y0 : x0);
618
+ const s1 = Math.min(thinX ? r.y + r.height : r.x + r.width, thinX ? y1 : x1);
619
+ if (s1 - s0 <= EPS) continue;
620
+ for (const c of clear) {
621
+ const cs0 = thinX ? c.y : c.x;
622
+ const cs1 = thinX ? c.y + c.height : c.x + c.width;
623
+ if (cs1 <= s0 + EPS || cs0 >= s1 - EPS) continue;
624
+ const c0 = thinX ? c.x : c.y;
625
+ const c1 = thinX ? c.x + c.width : c.y + c.height;
626
+ if (c1 <= lo + EPS || c0 >= hi - EPS) continue;
627
+ if ((c0 + c1) / 2 >= (lo + hi) / 2) hi = Math.min(hi, c0);
628
+ else lo = Math.max(lo, c1);
629
+ }
630
+ if (hi - lo < Math.max(EPS, min)) continue;
631
+ 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 }));
632
+ }
633
+ return out;
634
+ }
569
635
  export {
570
636
  DOUBLE_CLICK,
571
637
  DRAG_DEFAULTS,
@@ -579,6 +645,7 @@ export {
579
645
  createDragIntent,
580
646
  createGripPress,
581
647
  createLandingModel,
648
+ guideRects,
582
649
  inRect,
583
650
  liftDecision,
584
651
  pickRank,