@n-uf/motion 26.11.49 → 26.11.50

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 CHANGED
@@ -3,6 +3,43 @@
3
3
  Versions are calendar versions, `YY.M.R` (year, month of the release, counter
4
4
  within the month), the same scheme as `@n-uf/hypr-tiling`.
5
5
 
6
+ ## 26.11.50
7
+
8
+ Sliding spots: a free stretch exposed as one spot, where the item lands at the hand. With `@n-uf/placement`'s
9
+ `stretchPositions: "free"` (placement's default from this release). Host notes: additive; pass the press's `grab` to `createLandingModel`, draw `frame.landing`
10
+ (it moves with the pointer over a sliding spot) and commit a sliding spot through its target's `after(point, grab)`,
11
+ as for a float. A host that commits a spot by its id alone must pass the pointer for a sliding one.
12
+
13
+ - `./drag`, **`LandingSpot.slide`** (`LandingSlide`: `{ from, to, snaps, snapDistance? }`, additive): over a sliding
14
+ spot the frame's `landing` is the spot's landing moved along the lane to the pointer less the grab, clamped to
15
+ `[from, to]` and snapped to the nearest snap point within `snapDistance` (`SNAP_DISTANCE`, 8 px). No steps inside it;
16
+ passing a neighbor is still one step.
17
+ - `./drag`, **`LandingOptions.grab`** (additive): where the pointer holds the item, from its top left corner; default
18
+ the middle of `regions.item`.
19
+ - `./drag`, **`LandingRelease.at`** (additive): on a sliding spot, the landing's start along the lane, exactly as the
20
+ frame shows it (a snap point, else on the spot's `step`), read once at the release; `home` holds only at the
21
+ item's own place.
22
+ - `./drag`, **`LandingSlide.step`** (additive, default 1): the grain of a start that snaps to nothing, px, clamped to
23
+ `[from, to]` (0: wherever the pointer puts it). The frame, a release's `at` and the spot's own commit round by the
24
+ same step, so the rect a frame draws is the rect the drop commits; placement's spots carry `step: 1` (whole pixels).
25
+ A host that builds its own sliding spots and wants the old unrounded frame gives `step: 0`.
26
+ - `./drag`, **the lift zone is the item's own lane's** (fix): within `margins.lift` of the lift point the landing model
27
+ now takes `home.lane` as the lane whenever the pointer lies in it, whatever lane the pointer came through, and
28
+ `home.spot` as the spot (a sliding one still lets the landing follow the hand and snap). Before, only owning lanes (a rail drop strip) were kept out of the zone: a plain lane's
29
+ band lying over the home lane's corner (an empty bar over the top of a rail) kept the pointer on a slow return and
30
+ the release landed in that lane instead of home. Away and back to the lift point is home on every layout, at any
31
+ speed; within `lift` of the press no nudge to a neighboring spot is reachable. The zone is a held state with
32
+ hysteresis: the drag starts in it, leaves it past `margins.lift` and re-enters only within `margins.lift -
33
+ margins.spot`, so a wobble at its edge never flips a cut near the press.
34
+ - `./drag`, **`guideRects` keeps every guide `clearance` px clear of `clear`** (fix, `GuideRectsOptions.clearance`,
35
+ additive, default 2): a box never read `clear` and could touch the content (0 px); it is now cut on the side that faces
36
+ each clear rect (the rect grown by `clearance` taken out, the largest remaining part kept, none: dropped). A thin guide
37
+ keeps being thinned from the content side, now with the same 2 px gap (a strip beside content is 2 px thinner than
38
+ before, and may fall under `minThickness` and be left out). Clearance is per clear rect: `clear` takes `Rect |
39
+ ClearRect` (`{ rect, clearance, kinds? }`, additive type). A plain rect keeps the default gap for every kind; pass
40
+ `{ rect, clearance: 0 }` for content a thin guide may run flush against, which is the old thin-guide result, and `kinds:
41
+ ["line", "hatch"]` where a box may still lie over it (an empty lane's real-size box moves the content aside).
42
+
6
43
  ## 26.11.49
7
44
 
8
45
  Guides placed inside the window, and no "Can't go here" while the pointer enters a lane. With `@n-uf/placement`
package/dist/drag.d.ts CHANGED
@@ -495,12 +495,22 @@ declare function previewPlan<T extends DragTarget>(frame: Pick<DragFrame<T>, "sh
495
495
  * held one too, once its own gate passes and only once the pointer came into it from outside since the lift. Within
496
496
  * `margins.lift` of the lift point (`options.lift`, else the first point; fixed for the drag) an owning lane takes the
497
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.
498
+ * a slow slide along it can take the pointer before it is back at the lift point. More generally, within
499
+ * `margins.lift` of the lift point the lane is the item's own (`home.lane`) whenever the pointer lies in it, whatever
500
+ * lane the pointer came through (a plain lane's band over the home lane's corner included), and its spot is the
501
+ * item's own (`home.spot`; a sliding one still lets the landing follow the hand and snap): away and back to where the
502
+ * item was lifted is home on every layout, so no nudge to a neighboring spot is reachable within `lift` of the press.
503
+ * The zone is a held state like a held lane: the drag starts in it, leaves it past `lift` and re-enters only within
504
+ * `lift - spot`, so a wobble at its edge never flips a cut near the press.
499
505
  * - **Along a lane** the spot changes once the pointer is `spot` px past the boundary; where the change moves another
500
506
  * item (the two spots' `others` keys differ), on a step of at most `step`, or once the held landing trails the
501
507
  * pointer by more than `trail`: the item chases only as far as it must. A change that moves only the held item
502
508
  * follows the hand at any speed. With `regionsFor`, a reflowing change is kept only if, in the new spot's own regions
503
509
  * (its room open), the pointer still lies in that spot's stretch: the room shifting the boundary never bounces it.
510
+ * - **A sliding spot** (`slide`: a free stretch as one spot) lands where the hand is: its landing moved along the lane to
511
+ * the pointer less the grab (`grab`), clamped to its range, and snapped to its ends, the item's own place or a dock
512
+ * inside within `snapDistance`. Nothing reflows inside it, so there are no steps there; a step comes only where the
513
+ * order changes (passing a neighbor), as between any two spots. A release reads where it starts (`at`) once.
504
514
  * - **Outside every lane:** a refused place, refused; open space (`"open"`: the content less what blocks it, the page),
505
515
  * the float at its landing; outside the stage (past `edge`), nowhere; else (docked content that takes nothing and
506
516
  * refuses nothing) refused.
@@ -525,7 +535,32 @@ interface LandingSpot {
525
535
  * item. Absent: every change to or from it counts as moving others.
526
536
  */
527
537
  readonly others?: string;
538
+ /**
539
+ * A sliding spot (a free stretch exposed as one spot): over it the landing follows the pointer, `landing` moved along
540
+ * the lane to the pointer less the grab, clamped to `[from, to]` and snapped to a point of `snaps` within
541
+ * `snapDistance`, else on whole pixels (`step`). Absent: the landing is `landing`.
542
+ */
543
+ readonly slide?: LandingSlide;
544
+ }
545
+ /** A sliding spot's range: where its landing's start may lie along the lane, and the points it snaps to. */
546
+ interface LandingSlide {
547
+ /** The landing's start at the stretch's start (flush against the neighbor before it), px along the lane. */
548
+ readonly from: number;
549
+ /** The landing's start at the stretch's end (flush against the neighbor after it), px along the lane. */
550
+ readonly to: number;
551
+ /** The starts it snaps to: its two ends, the item's own place where it lies here, any discrete dock inside. */
552
+ readonly snaps: readonly number[];
553
+ /** How near a snap point the landing's start snaps to it, px (default `SNAP_DISTANCE`). */
554
+ readonly snapDistance?: number;
555
+ /**
556
+ * The grain of a start that snaps to nothing, px: a multiple of `step`, clamped to `[from, to]` (default 1, whole
557
+ * pixels; 0: wherever the pointer puts it). Give the step the spot's commit uses, so the frame, the release's `at`
558
+ * and the commit agree.
559
+ */
560
+ readonly step?: number;
528
561
  }
562
+ /** How near a sliding spot's snap point its landing snaps to it, px. */
563
+ declare const SNAP_DISTANCE = 8;
529
564
  /**
530
565
  * 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
566
  * lands in, a hatch over the part of a neighbor that gives way where the room is shorter than the item.
@@ -624,6 +659,13 @@ interface LandingOptions {
624
659
  };
625
660
  /** Where the item was lifted (the press), in the regions' space; default the first point `update` gets. */
626
661
  readonly lift?: Point;
662
+ /**
663
+ * Where the pointer holds the item, from its top left corner as it is now, px (the press's, as `lanes()` takes it).
664
+ * Over a sliding spot the landing's start is the pointer less this, along the item's own length (its longer side; a
665
+ * landing of another length at the same share of it); across it, and in a lane across its length, the middle.
666
+ * Default: the middle of `regions.item`.
667
+ */
668
+ readonly grab?: Point;
627
669
  readonly margins?: Partial<LandingMargins>;
628
670
  readonly gates?: Partial<LandingGates>;
629
671
  readonly approach?: Partial<LandingApproach>;
@@ -659,12 +701,17 @@ interface LandingFrame {
659
701
  */
660
702
  readonly pending?: string;
661
703
  }
662
- /** What a release lands: a spot (`home` when it is the item's own place), the float at `rect`, or nothing. */
704
+ /**
705
+ * What a release lands: a spot (`home` when it is the item's own place), the float at `rect`, or nothing. On a sliding
706
+ * spot, `at` is where the landing starts along the lane, as the frame shows it (read once, at the release: a snap
707
+ * point, else on the spot's `step`), and `home` holds only where that is the item's own place.
708
+ */
663
709
  type LandingRelease = {
664
710
  readonly kind: "spot";
665
711
  readonly lane: string;
666
712
  readonly spot: string;
667
713
  readonly home: boolean;
714
+ readonly at?: number;
668
715
  } | {
669
716
  readonly kind: "float";
670
717
  readonly rect: Rect;
@@ -726,24 +773,45 @@ interface PlacedGuide {
726
773
  readonly kind: "line" | "box" | "hatch";
727
774
  readonly rect: Rect;
728
775
  }
776
+ /** A rect guides stay clear of, with a clearance of its own, px (0: guides may lie flush against it). */
777
+ interface ClearRect {
778
+ readonly rect: Rect;
779
+ readonly clearance: number;
780
+ /**
781
+ * The guide kinds this rect constrains (default: all). Content a thin guide keeps clear of, but an empty lane's
782
+ * real-size box lies over (it moves the content aside), is `kinds: ["line", "hatch"]`.
783
+ */
784
+ readonly kinds?: readonly PlacedGuide["kind"][];
785
+ }
729
786
  interface GuideRectsOptions {
730
787
  /** The area guides are drawn in: the window's inside (inside its border), px. */
731
788
  readonly inside: Rect;
732
789
  /** How far inside `inside` every guide stays, px (default 2). */
733
790
  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[];
791
+ /**
792
+ * Rects guides stay clear of. A plain `Rect` keeps `clearance` px (the default gap) for every kind: something guides
793
+ * must keep apart from, such as the held item's outline. `{ rect, clearance, kinds? }` keeps its own, for the kinds
794
+ * it names: `{ rect, clearance: 0, kinds: ["line", "hatch"] }` is a boundary a thin guide may run flush against (the
795
+ * content: a column's panels under an empty lane's thin edge) while a box may still lie over it.
796
+ */
797
+ readonly clear?: readonly (Rect | ClearRect)[];
798
+ /** How far clear of a plain `clear` rect a guide stays, px (default 2): "clear of" means at least this far. */
799
+ readonly clearance?: number;
736
800
  /** The least thickness a thin guide keeps, px (default 2); thinner, it is not drawn. */
737
801
  readonly minThickness?: number;
738
802
  }
739
803
  /**
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`.
804
+ * Where to draw guides: every guide inside `inside` by `inset`, and at least `clearance` px clear of every `clear` rect
805
+ * ("clear of" means at least that far: a plain rect keeps the options' `clearance`, default 2; `{ rect, clearance }`
806
+ * keeps its own, so pass `{ rect, clearance: 0 }` for content a thin guide may run flush against, and `kinds` to
807
+ * constrain only some kinds of guide, default all). A box is clipped,
808
+ * then cut on the side that faces each clear rect (the clear rect grown by its clearance is taken out of it, and the
809
+ * largest remaining part, left, right, above or below, is kept). A thin guide (a line, a striped strip or end: its
810
+ * shorter side is its thickness) keeps its thickness and moves inside rather than being clipped, so a line at a lane's
811
+ * far end is as thick as at its head. Then it is thinned, from the content side, to stay that far clear of `clear`, so
812
+ * a thin strip at the window's side lies between the inset and the content, the same on both sides. A guide with nothing left (or a thin one under `minThickness`) is left out. Pure; the guides come
813
+ * back as given with their placed `rect`, the same object where nothing moved.
746
814
  */
747
815
  declare function guideRects<G extends PlacedGuide>(guides: readonly G[], options: GuideRectsOptions): G[];
748
816
 
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 };
817
+ export { type ClearRect, 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 LandingSlide, type LandingSpot, type LiftDecision, type ModifierKey, PLACE_GUIDES_DEFAULT, type PlaceGuides, type PlacedGuide, type PreviewPlan, REFUSAL_RANK, SNAP_DISTANCE, createDragIntent, createGripPress, createLandingModel, guideRects, inRect, liftDecision, pickRank, previewPlan, targetAt };
package/dist/drag.js CHANGED
@@ -279,6 +279,8 @@ function createDragIntent(options) {
279
279
  }
280
280
 
281
281
  // src/drag/landing.ts
282
+ var SLIDE_STEP = 1;
283
+ var SNAP_DISTANCE = 8;
282
284
  var LANDING_MARGINS = { exit: 12, spot: 6, edge: 48, lift: 16 };
283
285
  var LANDING_TOUCH_MARGINS = { exit: 16, spot: 8, edge: 48, lift: 16 };
284
286
  var LANDING_GATES = { path: 40, depth: 8, still: 1.5, step: 3, trail: 40, rest: 22, pause: 60 };
@@ -322,6 +324,7 @@ function createLandingModel(options) {
322
324
  let last = null;
323
325
  let moved = null;
324
326
  let liftAt = options.lift ?? null;
327
+ let inLiftZone = true;
325
328
  let lastStep = 0;
326
329
  const pathIn = /* @__PURE__ */ new Map();
327
330
  const slide = /* @__PURE__ */ new Map();
@@ -329,6 +332,7 @@ function createLandingModel(options) {
329
332
  let approached = null;
330
333
  let previous = laneId ? "lane" : "open";
331
334
  let frame = { region: previous, lane: laneId, spot: spotId, landing: null, room: !!spotId, guides: [], shift: false };
335
+ let landedOn = null;
332
336
  const laneIn = (regions, id) => id ? regions.lanes.find((l) => l.id === id) : void 0;
333
337
  const spotIn = (lane, id) => lane && id ? lane.spots.find((s) => s.id === id) : void 0;
334
338
  function pick(lane, a) {
@@ -346,6 +350,32 @@ function createLandingModel(options) {
346
350
  }
347
351
  return best;
348
352
  }
353
+ function landingAt(lane, spot, p, item) {
354
+ const s = spot.slide;
355
+ if (!s) return spot.landing;
356
+ const ax = lane.axis;
357
+ const long = item.width >= item.height ? "x" : "y";
358
+ const size = long === "x" ? item.width : item.height;
359
+ const g = options.grab ? long === "x" ? options.grab.x : options.grab.y : size / 2;
360
+ const share = ax === long && size > 0 && Number.isFinite(g) ? Math.min(1, Math.max(0, g / size)) : 0.5;
361
+ const length = ax === "x" ? spot.landing.width : spot.landing.height;
362
+ const lo = Math.min(s.from, s.to);
363
+ const hi = Math.max(s.from, s.to);
364
+ const free = Math.min(hi, Math.max(lo, alongOf(lane, p) - share * length));
365
+ const reach = s.snapDistance ?? SNAP_DISTANCE;
366
+ let at = free;
367
+ let best = Infinity;
368
+ for (const q of s.snaps) {
369
+ const d = Math.abs(q - free);
370
+ if (d <= reach && d < best) {
371
+ best = d;
372
+ at = q;
373
+ }
374
+ }
375
+ const step = s.step ?? SLIDE_STEP;
376
+ if (best === Infinity && step > 0) at = Math.min(hi, Math.max(lo, Math.round(free / step) * step));
377
+ return ax === "x" ? { ...spot.landing, x: at } : { ...spot.landing, y: at };
378
+ }
349
379
  function along(lane, p, step) {
350
380
  const regions = heldRegions(spotId);
351
381
  const held2 = laneIn(regions, lane.id) ?? lane;
@@ -441,10 +471,22 @@ function createLandingModel(options) {
441
471
  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;
442
472
  const sl = touching ? slide.get(touching.id) : void 0;
443
473
  const slid = !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along;
444
- const nearLift = !!liftAt && Math.hypot(p.x - liftAt.x, p.y - liftAt.y) <= (margins.lift ?? 16);
474
+ const liftR = margins.lift ?? 16;
475
+ if (liftAt) {
476
+ const far = Math.hypot(p.x - liftAt.x, p.y - liftAt.y);
477
+ inLiftZone = far <= (inLiftZone ? liftR : Math.max(0, liftR - margins.spot));
478
+ }
479
+ const nearLift = !!liftAt && inLiftZone;
445
480
  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);
447
- if (held2 && !next && (touching || inside(held2.rect, p, margins.exit))) {
481
+ const ownLane = nearLift && options.home ? laneIn(regions, options.home.lane) : void 0;
482
+ const homeHere = ownLane && strictlyIn(ownLane.rect, p) ? ownLane : void 0;
483
+ const next = homeHere ? void 0 : owner ?? (touching && (gate(touching) || slid) ? touching : void 0);
484
+ if (homeHere) {
485
+ const s = spotIn(homeHere, options.home.spot) ?? pick(homeHere, alongOf(homeHere, p));
486
+ laneId = homeHere.id;
487
+ spotId = s?.id ?? null;
488
+ region = s ? "lane" : "refused";
489
+ } else if (held2 && !next && (touching || inside(held2.rect, p, margins.exit))) {
448
490
  const s = along(held2, p, step);
449
491
  spotId = s?.id ?? spotId;
450
492
  region = s ? "lane" : "refused";
@@ -479,8 +521,10 @@ function createLandingModel(options) {
479
521
  previous = region;
480
522
  const shown = shift && (region === "lane" || region === "open") ? "open" : region;
481
523
  const r2 = heldRegions(spotId);
482
- const spot = spotIn(laneIn(r2, laneId), spotId);
483
- const landing = shown === "lane" ? spot?.landing ?? null : shown === "open" ? options.floatLanding?.(p) ?? null : null;
524
+ const heldLane = laneIn(r2, laneId);
525
+ const spot = spotIn(heldLane, spotId);
526
+ landedOn = shown === "lane" && spot && heldLane ? { spot, axis: heldLane.axis } : null;
527
+ const landing = shown === "lane" ? spot && heldLane ? landingAt(heldLane, spot, p, r2.item) : null : shown === "open" ? options.floatLanding?.(p) ?? null : null;
484
528
  frame = {
485
529
  region: shown,
486
530
  lane: laneId,
@@ -496,7 +540,16 @@ function createLandingModel(options) {
496
540
  return {
497
541
  update,
498
542
  release() {
499
- if (frame.region === "lane" && frame.lane && frame.spot) return { kind: "spot", lane: frame.lane, spot: frame.spot, home: !!options.home && options.home.spot === frame.spot && options.home.lane === frame.lane };
543
+ if (frame.region === "lane" && frame.lane && frame.spot) {
544
+ const ownSpot = !!options.home && options.home.spot === frame.spot && options.home.lane === frame.lane;
545
+ const on = landedOn;
546
+ if (on?.spot.slide && frame.landing) {
547
+ const start = (r) => on.axis === "x" ? r.x : r.y;
548
+ const at = start(frame.landing);
549
+ return { kind: "spot", lane: frame.lane, spot: frame.spot, home: ownSpot && Math.abs(at - start(on.spot.landing)) < 1e-6, at };
550
+ }
551
+ return { kind: "spot", lane: frame.lane, spot: frame.spot, home: ownSpot };
552
+ }
500
553
  if (frame.region === "open" && frame.landing) return { kind: "float", rect: frame.landing };
501
554
  return null;
502
555
  },
@@ -594,15 +647,39 @@ function guideRects(guides, options) {
594
647
  const y0 = options.inside.y + inset;
595
648
  const x1 = options.inside.x + options.inside.width - inset;
596
649
  const y1 = options.inside.y + options.inside.height - inset;
597
- const clear = options.clear ?? [];
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
+ );
598
654
  const out = [];
599
655
  for (const g of guides) {
600
656
  const r = g.rect;
657
+ const clear = allClear.filter((c) => !c.kinds || c.kinds.includes(g.kind));
601
658
  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);
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
+ }
606
683
  if (c - a > EPS && d - b > EPS) out.push(place(g, { x: a, y: b, width: c - a, height: d - b }));
607
684
  continue;
608
685
  }
@@ -617,12 +694,12 @@ function guideRects(guides, options) {
617
694
  const s0 = Math.max(thinX ? r.y : r.x, thinX ? y0 : x0);
618
695
  const s1 = Math.min(thinX ? r.y + r.height : r.x + r.width, thinX ? y1 : x1);
619
696
  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;
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;
623
700
  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;
701
+ const c0 = (thinX ? c.x : c.y) - gap2;
702
+ const c1 = (thinX ? c.x + c.width : c.y + c.height) + gap2;
626
703
  if (c1 <= lo + EPS || c0 >= hi - EPS) continue;
627
704
  if ((c0 + c1) / 2 >= (lo + hi) / 2) hi = Math.min(hi, c0);
628
705
  else lo = Math.max(lo, c1);
@@ -642,6 +719,7 @@ export {
642
719
  LANDING_TOUCH_MARGINS,
643
720
  PLACE_GUIDES_DEFAULT,
644
721
  REFUSAL_RANK,
722
+ SNAP_DISTANCE,
645
723
  createDragIntent,
646
724
  createGripPress,
647
725
  createLandingModel,
package/dist/drag.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/drag/intent.ts","../src/drag/landing.ts","../src/drag/preview.ts","../src/drag/grip.ts","../src/drag/guide-rects.ts"],"sourcesContent":["import type { Point, Rect } from \"../shapes\";\n\n/**\n * The drag intent model's tuning. Distances in px, speeds in px/ms, times in\n * ms; every value can be overridden per intent (see\n * {@link DragIntentOptions.tuning}).\n */\nexport interface DragTuning {\n /** A mouse press lifts once the pointer has moved this far. */\n readonly lift: number;\n /** A touch press lifts only after it has been held this long… */\n readonly touchHold: number;\n /** …and then moved this far (moving that far before the hold is over is not a drag). */\n readonly touchLift: number;\n /** The pointer's speed is measured over this window and smoothed. */\n readonly speedWindow: number;\n /** Aiming: the smoothed speed is below this… */\n readonly aimSpeed: number;\n /** …or the pointer has stayed within `still` px of one spot for `dwell` ms. */\n readonly still: number;\n readonly dwell: number;\n /** The current target holds while the pointer is within this band of its zone. */\n readonly band: number;\n /** A higher-priority target takes over at once when the pointer is this far inside it. */\n readonly breakthrough: number;\n /**\n * The band and the breakthrough scale with the zones: along each axis they are at most this share of the held\n * zone's extent and of the extent of the zone under the pointer (its `hit`), so a small zone (a 28 px row) can be\n * entered by a direct glide from its neighbor. Below a quarter, the pointer at a quarter of a zone is past them.\n */\n readonly bandShare: number;\n /** A gap between zones shorter than this keeps the current target (for a pointer that aims). */\n readonly gapGrace: number;\n /** Aiming, the shown target moves to another one only once that one has held this long. */\n readonly switchHold: number;\n /**\n * Room is made once the shown target, and the place in it, have held this long, so a pointer moving across targets\n * doesn't reflow the layout under it. A target with `opensRoom` holds this long before it shows, its room with it.\n */\n readonly roomAfter: number;\n /** The pointer has left the item's home once it is outside the home shrunk by this much on every side. */\n readonly homeInset: number;\n /**\n * Spring-loading: a target marked `arm: \"dwell\"` takes the drop only once the pointer has stayed in its zone this long\n * (ms); before that it is no target, so a fast pass, or a drop before it, lands on what lies beneath. 0 arms it at once.\n * Armed, its zone is its `armedHit` (the magnet: its band); moving out past that band's outer edge disarms it, and\n * re-entering needs a new full dwell. It arms only after the pointer has ENTERED its zone during the drag: the point\n * the drag starts at counts as not entered, so a drag that starts inside the zone (a panel's grip under the strip at\n * the window's edge) must leave it and come back before it can arm; entering from over home counts.\n */\n readonly railArmDwellMs: number;\n /**\n * The lift zone, a radius in px about the point the drag was lifted at ({@link DragIntentOptions.lift}, else the first\n * sample): no spring-loaded target arms by dwell inside it. Coming back to where you lifted and pausing is the\n * \"changed my mind\" gesture, so it commits nothing even where a strip lies over the grip (a flush drawer's grip at the\n * window's edge). 16 px is about a grip's size. Elsewhere, home under a strip included, arming works as before, and\n * the rail key forces the rail anywhere, the lift zone too.\n */\n readonly liftZone: number;\n /** The keys that win over geometry while held (see {@link DragModifiers}). */\n readonly modifiers: DragModifiers;\n}\n\n/**\n * A modifier key, by its `KeyboardEvent.key` name, or `\"Mod\"`: ⌘ (Meta) on macOS and Ctrl elsewhere. `\"Mod\"` counts\n * either key as held, so no platform detection is needed.\n */\nexport type ModifierKey = \"Shift\" | \"Alt\" | \"Control\" | \"Meta\" | \"Mod\";\n\n/** The modifier keys held on a sample (a pointer event's `shiftKey`, `altKey`, `ctrlKey`, `metaKey`). */\nexport interface DragKeys {\n readonly shift?: boolean;\n readonly alt?: boolean;\n readonly ctrl?: boolean;\n readonly meta?: boolean;\n}\n\n/**\n * Keys that win over geometry: while `floatKey` is held the drop floats (the `free` target) wherever the pointer is,\n * except over a refusal (the frame is refused) or outside the float's `bounds` (nothing);\n * while `railKey` is held it goes to the nearest target marked `arm` (a side's rail), without reaching it. `floatKey`\n * wins when both are held. `on: false` turns both off.\n */\nexport interface DragModifiers {\n readonly on: boolean;\n readonly floatKey: ModifierKey;\n readonly railKey: ModifierKey;\n}\n\n/**\n * The defaults: a mouse lifts after 5 px, a touch after a 180 ms hold and\n * 8 px; aiming is slower than 0.45 px/ms over 50 ms, or within 12 px for\n * 90 ms; a 10 px band and a 4 px breakthrough, each at most a fifth of the\n * zones' extents, and a 120 ms gap grace; a switch waits 150 ms (the shortest\n * an indicator may show); room after 160 ms. A spring-loaded target arms after\n * 200 ms of dwell (long enough that a pass at travelling speed never arms it,\n * short enough to feel like the platforms' spring-loading); Shift floats, ⌘/Ctrl\n * (`\"Mod\"`) goes to the nearest rail. Alt is left free: an app with a frozen\n * layout uses it to unfreeze temporarily, and a key should have one meaning.\n */\nexport const DRAG_DEFAULTS: DragTuning = {\n lift: 5,\n touchHold: 180,\n touchLift: 8,\n speedWindow: 50,\n aimSpeed: 0.45,\n still: 12,\n dwell: 90,\n band: 10,\n breakthrough: 4,\n bandShare: 0.2,\n gapGrace: 120,\n switchHold: 150,\n roomAfter: 160,\n homeInset: 6,\n railArmDwellMs: 200,\n liftZone: 16,\n modifiers: { on: true, floatKey: \"Shift\", railKey: \"Mod\" },\n};\n\nconst KEY_FIELD: Record<Exclude<ModifierKey, \"Mod\">, keyof DragKeys> = { Shift: \"shift\", Alt: \"alt\", Control: \"ctrl\", Meta: \"meta\" };\n/** Whether `key` is held in `keys` (`\"Mod\"`: ⌘ or Ctrl). */\nconst held = (keys: DragKeys | undefined, key: ModifierKey): boolean =>\n !!keys && (key === \"Mod\" ? !!(keys.meta || keys.ctrl) : !!keys[KEY_FIELD[key]]);\n\n/**\n * A drop target: plain data. `hit` is the zone the pointer can be in;\n * `priority` how precise it is (1 beats 2 beats 3; equal priorities go to the\n * smaller zone). `slot` is where the dragged item would land, `label` what to\n * call it; the model reads neither. A `free` target has no slot (the item\n * floats where it is dropped): no room is made for it. `hits`, when given, is\n * the whole zone as several rects (a zone that isn't one rect, `hit` the\n * largest of them): the pointer is in the zone when it is in any of them.\n *\n * `arm: \"dwell\"` makes it spring-loaded: it is no target until the pointer has\n * dwelt in its zone for `railArmDwellMs`; once armed its zone is `armedHit`\n * when given (a magnet: the zone grown), and leaving that disarms it.\n *\n * `refuse: true` makes it a refusal: a place that takes no drop (a host draws nothing over it, and at most says \"Can't\n * go here\" at the pointer). It takes part in\n * the pick under the pointer at {@link REFUSAL_RANK} (below every target of priority 1 or 2, whatever its own\n * `priority`, above priority 3), but it never becomes the current or the shown target, and a release over it lands\n * nowhere. Where the pick under the pointer is a refusal, no held target's band or gap grace keeps it: nothing shows,\n * and the frame's `refused` says which refusal it is.\n *\n * `bounds`, when given, is the drawn space the zone belongs to (a window's stage): the zone, its band and its gap grace\n * hold only points strictly inside it, so it is half-open toward the outside and a point on `bounds`' boundary or past\n * it is never in it. The window's boundary belongs only to the targets drawn against it: a refusal and a target over\n * the whole plane (the float) carry `bounds`, a gap or a slot doesn't. So a pointer a host clamps onto the window's\n * edge picks a gap whose hit reaches the edge, else nothing (a held target keeps its band), and never a refusal or the\n * float. The rule relies on the host clamping exactly onto the stage's edge (`x + width`, `y + height`): a host that\n * clamps to `width - 0.5` still picks inside the window, the float or a refusal there included.\n *\n * `opensRoom: true` marks a target whose indicator would lie over what its room moves (a side rail that pushes a column\n * aside). Showing it and making its room are then one decision: it shows only once it has held `roomAfter` ms, and the\n * frame that first shows it already has `room`. A sweep across it moves nothing, as for any target, and no frame draws\n * it over the column. Until it shows, a release still lands on it. An armed spring-loaded target has its room at once\n * too: its dwell was the decision. `roomHold` is how long this target holds before that decision, in ms, in place of\n * `roomAfter` (a rail or a new-column line against the window's edge, which a pointer rarely crosses on its way\n * elsewhere, can wait less). A\n * host that draws only a marker and doesn't use `previewPlan`'s room opens the room on\n * `frame.room && frame.shown?.opensRoom`.\n *\n * `roomHit`, with `opensRoom`, is where the target's room draws the item once it is open (its landing rect: an empty\n * rail or bar is entered over its drawn depth). While the target shows with its room open it holds in `hit ∪ roomHit`: wherever\n * the pointer is in `roomHit` and inside its `bounds` too. What lies there is drawn as the room, so a refusal or a\n * target of the same or a lower precision under it doesn't take over, and the frame isn't `refused` there. A more\n * precise target (a lower `priority`) still takes over once the pointer is past `breakthrough` into it, and a held key\n * still wins. Out of both the target is held as any other (its `hit` and band), so once it goes its zone is `hit` again.\n */\nexport interface DragTarget {\n readonly id: string;\n readonly priority: 1 | 2 | 3;\n readonly hit: Rect;\n readonly hits?: readonly Rect[];\n readonly slot?: Rect;\n readonly label?: string;\n readonly free?: boolean;\n readonly arm?: \"dwell\";\n readonly armedHit?: Rect;\n readonly refuse?: true;\n readonly bounds?: Rect;\n readonly opensRoom?: true;\n readonly roomHold?: number;\n readonly roomHit?: Rect;\n}\n\n/**\n * Where a refusal ranks in the pick ({@link targetAt}): an ordering rank, not a priority. Priorities stay the integers\n * 1, 2 and 3; a refusal's tier is `refuse: true`, and the pick orders it by this rank on the same scale: after every\n * target of priority 1 and 2 (a refusal and a real target where they meet or overlap: the target wins, so a gap keeps\n * its end), before priority 3 (the float: over drawn space that takes nothing, the refusal wins over floating).\n * Among refusals the smaller zone wins. `@n-uf/placement` exports the same value for its reference pick.\n */\nexport const REFUSAL_RANK = 2.5;\n\n/** A target's rank in the pick: its `priority`, a refusal's {@link REFUSAL_RANK}. Lower wins. */\nexport const pickRank = (t: Pick<DragTarget, \"priority\" | \"refuse\">): number => (t.refuse === true ? REFUSAL_RANK : t.priority);\n\n/** Whether `point` lies strictly inside `bounds` (none: everywhere). */\nconst within = (bounds: Rect | undefined, point: Point): boolean =>\n !bounds || (point.x > bounds.x && point.x < bounds.x + bounds.width && point.y > bounds.y && point.y < bounds.y + bounds.height);\n\n/** Whether `point` lies in `rect` grown by `margin` px on every side (shrunk, for a negative margin). */\nexport function inRect(rect: Rect, point: Point, margin = 0): boolean {\n return point.x >= rect.x - margin && point.x <= rect.x + rect.width + margin && point.y >= rect.y - margin && point.y <= rect.y + rect.height + margin;\n}\n\n/** How far `point` lies from `rect` (0 inside it). */\nconst distanceTo = (rect: Rect, point: Point): number =>\n Math.hypot(Math.max(rect.x - point.x, 0, point.x - (rect.x + rect.width)), Math.max(rect.y - point.y, 0, point.y - (rect.y + rect.height)));\n\n/** Whether `point` lies in a target's zone (`hits` when it has them, else `hit`), grown by `margin` px, and inside its `bounds`. */\nconst inZone = (t: DragTarget, point: Point, margin = 0): boolean => within(t.bounds, point) && (t.hits ? t.hits.some((r) => inRect(r, point, margin)) : inRect(t.hit, point, margin));\n\n/** A margin per axis: px grown (shrunk, when negative) left and right, and above and below. */\ninterface Margin {\n readonly x: number;\n readonly y: number;\n}\n/**\n * Whether `point` lies in a target's zone grown by `m.x` px left and right and `m.y` px above and below, and inside its\n * `bounds`: a band never reaches past a zone's bounds (the float's band holds nothing outside the window).\n */\nconst inZoneBy = (t: DragTarget, point: Point, m: Margin): boolean =>\n within(t.bounds, point) && (t.hits ?? [t.hit]).some((r) => point.x >= r.x - m.x && point.x <= r.x + r.width + m.x && point.y >= r.y - m.y && point.y <= r.y + r.height + m.y);\n/** `px`, but along each axis at most `share` of each zone's extent (its `hit`) along it. */\nconst scaled = (px: number, share: number, zones: readonly (DragTarget | null)[]): Margin => {\n let x = px;\n let y = px;\n for (const z of zones) {\n if (!z) continue;\n x = Math.min(x, share * z.hit.width);\n y = Math.min(y, share * z.hit.height);\n }\n return { x, y };\n};\nconst negate = (m: Margin): Margin => ({ x: -m.x, y: -m.y });\n\nconst area = (r: Rect): number => r.width * r.height;\n/** A target's zone's area: its `hits` together, else its `hit`. */\nconst zoneArea = (t: DragTarget): number => (t.hits ? t.hits.reduce((s, r) => s + area(r), 0) : area(t.hit));\n\n/**\n * The most precise target under `point`: the lowest rank ({@link pickRank}: the priority, a refusal's\n * {@link REFUSAL_RANK}), then the smallest zone; null when none is. A zone holds its edges (a closed rect), except\n * toward the outside of its `bounds`.\n */\nexport function targetAt<T extends DragTarget>(targets: readonly T[], point: Point): T | null {\n let best: T | null = null;\n for (const t of targets) {\n if (!inZone(t, point)) continue;\n if (!best || pickRank(t) < pickRank(best) || (pickRank(t) === pickRank(best) && zoneArea(t) < zoneArea(best))) best = t;\n }\n return best;\n}\n\n/** What a press does so far: not yet a drag (`wait`), a drag (`lift`), or never one (`refuse`: a touch that moved too soon). */\nexport type LiftDecision = \"wait\" | \"lift\" | \"refuse\";\n\n/**\n * The lift rule for a press that has moved `distance` px in `elapsed` ms. A\n * mouse (or pen) lifts at `lift` px. A touch lifts only after `touchHold` ms,\n * then at `touchLift` px; moving `touchLift` px before the hold is over\n * refuses the drag (the finger is scrolling or swiping).\n */\nexport function liftDecision(press: { readonly touch: boolean; readonly distance: number; readonly elapsed: number }, tuning: Partial<DragTuning> = {}): LiftDecision {\n const t = { ...DRAG_DEFAULTS, ...tuning };\n if (!press.touch) return press.distance >= t.lift ? \"lift\" : \"wait\";\n if (press.elapsed < t.touchHold) return press.distance >= t.touchLift ? \"refuse\" : \"wait\";\n return press.distance >= t.touchLift ? \"lift\" : \"wait\";\n}\n\n/** One update's answer. */\nexport interface DragFrame<T extends DragTarget> {\n /** The target the drop indicator shows, or null. */\n readonly shown: T | null;\n /**\n * The others make room for the shown target: it, and the place in it, have held `roomAfter` ms. For a target with\n * `opensRoom`, or an armed spring-loaded one, from the first frame that shows it.\n */\n readonly room: boolean;\n /**\n * The place the room is made for, or null. Within one target it stays on\n * the old place until a new one has held `roomAfter` ms (see\n * {@link DragIntentOptions.placeOf}).\n */\n readonly roomPlace: string | null;\n /** The pointer is aiming: slow, or nearly still for a moment. */\n readonly aiming: boolean;\n /**\n * The pointer is back inside `home` after it has been outside `home` itself. Never true at the press, nor while the\n * pointer only moves about inside `home`, even near its edge (where `state.leftHome` is already true: that flag is for\n * the indicator's gate and uses `homeInset`; this one does not). Over home no target is shown and a release does\n * nothing, so a host that wants to say \"a drop here returns it\" draws its own indicator for this frame (at the home\n * rect); the intent still shows no target.\n *\n * A docked item's home holds wherever it lies. The home of a floating item (`DragIntentOptions.floating`) is a free\n * placement, ranked like the float: it holds only where the pick there, home ignored, is no refusal and the point is\n * inside the window. Where it doesn't hold this is false and the pick is as anywhere else: over a refusal\n * `refused` says so, and a release lands nowhere.\n */\n readonly atHome: boolean;\n /**\n * A spring-loaded target (`arm: \"dwell\"`) the pointer is in and dwelling on, not armed yet (a host highlights it), or\n * null. Once it arms it is a target like any other and may show.\n */\n readonly arming: T | null;\n /**\n * A key held wins over geometry this frame: `\"float\"` (the float key) or `\"rail\"` (the rail key), else null. The\n * float key chooses the float over dock targets, not over a refusal or outside the window: there it is still\n * `\"float\"` (the key is held), but nothing shows, a release lands nowhere, and over a refusal `refused` says which.\n */\n readonly forced: \"float\" | \"rail\" | null;\n /**\n * The refusal (a target with `refuse: true`) the pointer is over, when it is the pick there: no target shows. A host\n * never draws the refused place; it may say \"Can't go here\" at the pointer. Null otherwise, and while a key forces a target; with the float key\n * held over a refusal it is that refusal (the key doesn't float over refused space).\n */\n readonly refused: T | null;\n /**\n * No target shows, and the pointer has been over a refusal since a target last showed (or since the lift). A refusal\n * hides the shown target at once, and the next one shows only once the pointer aims again, so a pointer that crosses\n * a refusal and is let go at speed over a target beyond it has no indicator drawn. Then this is true, and a release\n * still lands on what is under the pointer (`release`): a host that commits only what it has drawn commits that\n * release too. False whenever a target shows, over the refusal itself (`refused`), and after `hide`.\n *\n * Read it from the frame of an `update` at the release point, called before `release` (as `release` asks anyway), so\n * the last move counts. The field is required: a host or a test mock that builds a `DragFrame` itself must set it.\n */\n readonly refusedSinceShown: boolean;\n /**\n * What a release at this frame's point lands on, by the one check `release` makes (`earlyRelease` included), or null\n * (nowhere, or the item goes home). A host draws the landing from it, so what it draws and what a release lands on\n * never disagree. `createDragIntent` always sets it; it is optional only so a host or a test that builds a frame\n * itself needn't.\n */\n readonly landing?: T | null;\n}\n\n/** What a drag intent knows now. */\nexport interface DragIntentState<T extends DragTarget> {\n /** The pointer's smoothed speed, px/ms. */\n readonly speed: number;\n /** The target under the pointer as the hysteresis holds it, or null. */\n readonly current: T | null;\n /** The target the indicator shows, or null. */\n readonly shown: T | null;\n /** The pointer has left the item's home. */\n readonly leftHome: boolean;\n}\n\nexport interface DragIntentOptions<T extends DragTarget> {\n /** Where the item was lifted from: the indicator stays off until the pointer leaves it, and a release there does nothing. */\n readonly home: Rect;\n /** Where the press that lifted the item was (the grip); default the first sample's point. The lift zone is about it. */\n readonly lift?: Point;\n /**\n * The lift zone as a rect instead of a radius, in the same px as the samples: while a sample is inside it no\n * spring-loaded target arms by dwell, and the `liftZone` radius is not applied. A host passes the part of the grip\n * that a drop strip covers (grip ∩ strip), so a pause back there commits nothing while the rest of the strip, right\n * beside a wide grip, still arms. Absent: the `liftZone` radius about `lift`.\n */\n readonly liftRect?: Rect;\n /**\n * The held item floats, and `home` is its own box. A floating item's own place is a free placement: it ranks like the\n * float target, so home holds only where the pick there, home ignored, is no refusal and the point lies inside the\n * window (no target's `bounds` left with nothing picked). Over a refusal in its box the frame is refused and a\n * release lands nowhere; on or past the window's edge nothing is picked; elsewhere in its box home holds as before.\n * Absent (a docked item): home holds wherever it lies, as its own home target beats a refusal.\n */\n readonly floating?: boolean;\n /**\n * What a release does before the item has settled on a target (no room open for it yet). `\"target\"` (the default): it\n * lands on the shown target, else the target under the pointer, drawn or not, an `opensRoom` target that hasn't shown\n * included. `\"float\"`: what shows is what lands, for a host whose dragged item is the only preview (`previewPlan`'s\n * `\"item\"`): the item is still on the pointer, so it floats there (the `free` target; over a refusal or outside the\n * float's `bounds`, nowhere). `release` is its one reader.\n */\n readonly earlyRelease?: \"target\" | \"float\";\n /** Overrides of {@link DRAG_DEFAULTS}. */\n readonly tuning?: Partial<DragTuning>;\n /**\n * The place within a target the pointer is at (a tab index, a stack\n * position, a pane's edge), unique across targets; default: the target's id.\n * Moving between places of the shown target moves the indicator at once but\n * the room only once the new place has held `roomAfter` ms.\n *\n * - `previous` is the place this target had on the last sample (null if it\n * had none), so a place can hold near its boundary (hysteresis).\n * - A null place is no target: there is no drop at that point of the target.\n * It isn't picked or held, the indicator hides there at once (or shows a\n * target beneath that has a place), no room opens, and a release there\n * lands on a target beneath, else goes home.\n * - It is also asked about the current target while the pointer is just\n * outside its hit zone (within the band, or during the gap grace). Answer\n * the nearest place there: returning null outside the zone drops the band\n * and the grace, so the indicator hides a few px past the edge. Return null\n * only for a part of the target that takes no drop.\n * - It is called on every sample for each target under the pointer and for\n * the current one, so keep it cheap and free of side effects.\n */\n readonly placeOf?: (target: T, point: Point, previous: string | null) => string | null;\n}\n\n/** A drag's intent: feed it the pointer on every frame; it says what the indicator shows and what a release lands on. */\nexport interface DragIntent<T extends DragTarget> {\n /**\n * A pointer sample at `time` (ms), with the targets as they stand (they may\n * be rebuilt between calls: the model follows them by id). Call it once a\n * frame while the item is held, also when the pointer doesn't move: a\n * dwell is time passing. `keys`: the modifier keys held now (see {@link DragModifiers}).\n */\n update(point: Point, time: number, targets: readonly T[], keys?: DragKeys): DragFrame<T>;\n /**\n * What a release at `point` lands on: the shown target whenever one shows\n * (a drop lands where the indicator was), else the target under the\n * pointer, else null (the item goes home). A release over home is null: it\n * does nothing. Feed the release point to `update` first, so a last jump\n * of the pointer counts. With a modifier key held (`keys`), the target the key picks, even over home.\n */\n release(point: Point, targets: readonly T[], keys?: DragKeys): T | null;\n /**\n * Hide the indicator (the view is scrolling under the pointer, say). The\n * aim starts afresh: the next sample never counts as aiming, and a dwell\n * starts again.\n */\n hide(time: number): void;\n /** The item's home moved with the view (it scrolled) by (dx, dy). */\n moveHome(dx: number, dy: number): void;\n readonly state: DragIntentState<T>;\n readonly tuning: DragTuning;\n}\n\n/**\n * The drag intent model: when the drop indicator shows, which target it\n * shows, when the others make room, and what a release lands on. Pure: fed\n * pointer samples and plain-data targets, no DOM and no clock of its own.\n *\n * - The indicator shows only when the pointer has left the item's home, a\n * target is under it, and it is aiming (slow, or nearly still for a\n * moment). Time spent crossing a big target at speed doesn't count.\n * - The most precise target wins (priority, then the smaller zone).\n * - Hysteresis: the current target holds while the pointer is within `band`\n * px of its zone, unless a more precise one is clearly (`breakthrough` px)\n * under the pointer; both scale down for small zones (`bandShare` of the\n * held zone's and the entered zone's extents along each axis), so a small\n * zone is entered by a direct glide; for a pointer that aims, a short gap between zones\n * (`gapGrace` ms) keeps it too.\n * - Leaving the shown target: flying, the indicator hides at once; aiming, it\n * moves to the new target once that has held `switchHold` ms (so no\n * indicator shows for less than that), at once for a breakthrough. A target\n * kept only by the gap grace can keep the indicator, never show it.\n * - Room is made once the shown target has held `roomAfter` ms, never for a\n * free target, and closes at once when it changes. A target with `opensRoom`\n * holds that long before it shows and has its room in the same frame; an\n * armed spring-loaded target has its room as it shows. With its room open,\n * one with a `roomHit` holds wherever the pointer is in that room, over a\n * refusal or a target no more precise than it under the room included.\n * - Where `placeOf` gives a target no place (null), it is no target: it is\n * neither shown nor landed on there.\n * - Spring-loading: a target marked `arm: \"dwell\"` is no target until the\n * pointer has stayed in its zone `railArmDwellMs` (the frame's `arming` says\n * which one it dwells on); then it is armed: its zone is `armedHit` (the\n * magnet) and it shows at once. Leaving that zone disarms it.\n * - Keys win over geometry (`modifiers`): the float key shows the `free` target\n * wherever the pointer is over a dock target or open space inside the float's\n * `bounds`, the rail key the nearest target marked `arm`; a release with the\n * key held lands there. Over a refusal, or outside the float's `bounds`, the\n * float key picks nothing: nothing shows and a release lands nowhere.\n */\nexport function createDragIntent<T extends DragTarget>(options: DragIntentOptions<T>): DragIntent<T> {\n const tuning: DragTuning = { ...DRAG_DEFAULTS, ...options.tuning };\n const placeOf = options.placeOf ?? ((t: T) => t.id);\n // Each target's place on the last sample, by id: its `previous` on the next.\n let lastPlaces = new Map<string, string | null>();\n let home: Rect = { ...options.home };\n let samples: { x: number; y: number; t: number }[] = [];\n let cur: T | null = null;\n let curSince = 0;\n let lastInside = 0;\n let shown: T | null = null;\n let shownSince = 0;\n let place: string | null = null;\n let placeSince = 0;\n let roomPlace: string | null = null;\n let leftHome = false;\n // The pointer has been outside `home` itself (`leftHome` turns on already near its edge): `atHome`'s own memory.\n let wentOut = false;\n let speed = 0;\n let anchor: Point | null = null;\n let stillSince = 0;\n let restart = false;\n // The pointer has been over a refusal since a target last showed (the frame's `refusedSinceShown`).\n let crossedRefusal = false;\n // Spring-loading: the target armed (by id), and the one the pointer dwells on and since when.\n let armedId: string | null = null;\n let armingId: string | null = null;\n let armingSince = 0;\n // The spring-loaded targets (by id) the pointer has been outside of during this drag: only those can arm.\n const wasOutside = new Set<string>();\n // The point the drag was lifted at: no spring-loaded target arms by dwell within `liftZone` of it.\n let liftAt: Point | null = options.lift ? { ...options.lift } : null;\n const same =(a: T | null, b: T | null): boolean => (a === null || b === null ? a === b : a.id === b.id);\n // Targets may be rebuilt between calls: follow the ones held by id.\n const follow = (t: T | null, targets: readonly T[]): T | null => (t ? (targets.find((x) => x.id === t.id) ?? t) : null);\n /** An armed target as it acts: its zone is `armedHit` (the magnet) when it has one. */\n const asArmed = (x: T): T => {\n if (!x.armedHit) return x;\n const { hits: _pieces, ...rest } = x;\n return { ...rest, hit: x.armedHit } as T;\n };\n /** The targets as they act now: a spring-loaded one only once armed, in its armed zone. */\n const acting = (targets: readonly T[]): T[] => targets.filter((x) => x.arm !== \"dwell\" || x.id === armedId).map((x) => (x.id === armedId ? asArmed(x) : x));\n /**\n * The target a held key picks at `p`: the float key the `free` target, the rail key the nearest spring-loaded one.\n * The float key chooses the float over dock targets, not over refusals or outside the window: where the pick at `p`\n * (`has`: a target with a place there, or a refusal) is a refusal, it picks nothing and says which refusal; outside\n * the float's `bounds` (a pointer clamped onto the window's edge) it picks nothing. The rail key's drop lands on the\n * rail, not where the pointer is, so neither applies to it.\n */\n const forcedBy = (keys: DragKeys | undefined, p: Point, targets: readonly T[], has: (x: T) => boolean): { kind: \"float\" | \"rail\"; target: T | null; refused: T | null } | null => {\n const m = tuning.modifiers;\n if (!m.on || !keys) return null;\n if (held(keys, m.floatKey)) {\n const f = targets.find((x) => x.free);\n if (!f) return null;\n const under = targetAt(acting(targets).filter((x) => inZone(x, p) && has(x)), p);\n if (under?.refuse === true) return { kind: \"float\", target: null, refused: under };\n return within(f.bounds, p) ? { kind: \"float\", target: f, refused: null } : { kind: \"float\", target: null, refused: null };\n }\n if (!held(keys, m.railKey)) return null;\n let best: T | null = null;\n let bestD = Infinity;\n for (const x of targets) {\n if (x.arm !== \"dwell\") continue;\n const d = distanceTo(asArmed(x).hit, p);\n if (d < bestD) {\n best = x;\n bestD = d;\n }\n }\n return best ? { kind: \"rail\", target: asArmed(best), refused: null } : null;\n };\n\n /** What a release at `point` lands on, as things stand now: `release`'s answer, and every frame's `landing`. */\n const landAt = (point: Point, given: readonly T[], keys: DragKeys | undefined): T | null => {\n // A key held wins over geometry, home included; the float key over a refusal or outside the window lands nowhere.\n const forced = forcedBy(keys, point, given, (x) => x.refuse === true || placeOf(x, point, lastPlaces.get(x.id) ?? null) !== null);\n if (forced) {\n const ft = forced.target;\n return ft ? (given.find((x) => x.id === ft.id) ?? ft) : null;\n }\n // Over home a release does nothing, except onto an armed spring-loaded target whose zone overlaps home.\n if (inRect(home, point)) {\n const armed = armedId === null ? null : given.find((x) => x.id === armedId);\n return armed && inZone(asArmed(armed), point) && placeOf(armed, point, lastPlaces.get(armed.id) ?? null) !== null ? armed : null;\n }\n const targets = acting(given);\n // Drop = shown: a shown target is kept until it hides (flying out past its band hides it at once).\n const s = shown && !(shown.arm === \"dwell\" && shown.id !== armedId) ? follow(shown, given) : null;\n // The target under the pointer that has a place there (a null place is no drop); a refusal there lands nowhere.\n const under = targetAt(\n targets.filter((x) => inZone(x, point) && (x.refuse === true || placeOf(x, point, lastPlaces.get(x.id) ?? null) !== null)),\n point,\n );\n if (options.earlyRelease === \"float\") {\n // What shows is what lands: a target with a slot only once its room is open; before that the item is still on\n // the pointer, so it floats there. A target with no slot (the item's own place, a blocked one) needs no room.\n const needsNoRoom = (x: T): boolean => x.free === true || !x.slot;\n if (s && (needsNoRoom(s) || roomPlace !== null)) return s;\n if (under?.refuse) return null;\n if (under && !under.free && !under.slot) return given.find((x) => x.id === under.id) ?? under;\n const float = given.find((x) => x.free);\n return float && within(float.bounds, point) ? float : null;\n }\n if (s) return s;\n return under && !under.refuse ? (given.find((x) => x.id === under.id) ?? under) : null;\n };\n\n return {\n tuning,\n get state(): DragIntentState<T> {\n return { speed, current: cur, shown, leftHome };\n },\n update(point, time, given, keys) {\n const p = point;\n const t = time;\n samples.push({ x: p.x, y: p.y, t });\n while (samples.length > 2 && t - samples[0]!.t > tuning.speedWindow) samples.shift();\n const a = samples[0]!;\n speed = speed * 0.5 + (Math.hypot(p.x - a.x, p.y - a.y) / Math.max(1, t - a.t)) * 0.5;\n if (!anchor || Math.hypot(p.x - anchor.x, p.y - anchor.y) > tuning.still) {\n anchor = { x: p.x, y: p.y };\n stillSince = t;\n }\n if (!inRect(home, p, -tuning.homeInset)) leftHome = true;\n const atHome = inRect(home, p);\n if (!atHome) wentOut = true;\n // Each target's place at this point, worked out once per sample; a null place is no target.\n const places = new Map<string, string | null>();\n const placeAt = (x: T): string | null => {\n if (!places.has(x.id)) places.set(x.id, placeOf(x, p, lastPlaces.get(x.id) ?? null));\n return places.get(x.id)!;\n };\n const live = (x: T | null): x is T => x !== null && placeAt(x) !== null;\n // Spring-loading: the armed target holds while the pointer is in its armed zone; a target the pointer dwells in\n // arms once it has held `railArmDwellMs`. A key held wins over both.\n const forced = forcedBy(keys, p, given, (x) => x.refuse === true || live(x));\n if (armedId !== null) {\n const was = given.find((x) => x.id === armedId);\n if (!was || forced || !inZone(asArmed(was), p) || !live(was)) armedId = null;\n }\n // Spring-loading is not gated by `atHome`: a strip that overlaps the item's own place still arms by dwell.\n // A spring-loaded target arms only after the pointer has entered it: one it has been outside of during the drag.\n for (const x of given) if (x.arm === \"dwell\" && !inZone(x, p)) wasOutside.add(x.id);\n // Inside the lift zone nothing arms by dwell (\"changed my mind\"); the rail key still forces the rail.\n // With a `liftRect` the zone is that rect, the radius not applied.\n liftAt ??= { x: p.x, y: p.y };\n const inLiftZone = options.liftRect ? inRect(options.liftRect, p) : Math.hypot(p.x - liftAt.x, p.y - liftAt.y) <= tuning.liftZone;\n const dwelling = forced || inLiftZone ? null : targetAt(given.filter((x) => x.arm === \"dwell\" && x.id !== armedId && wasOutside.has(x.id) && inZone(x, p) && live(x)), p);\n let armedNow = false;\n if (!dwelling || armedId !== null) armingId = null;\n else {\n if (armingId !== dwelling.id) {\n armingId = dwelling.id;\n armingSince = t;\n }\n if (t - armingSince >= tuning.railArmDwellMs) {\n armedId = dwelling.id;\n armingId = null;\n armedNow = true;\n }\n }\n const arming = armingId === null ? null : (given.find((x) => x.id === armingId) ?? null);\n const targets = acting(given);\n // A docked item's home holds wherever it lies (its own home target beats a refusal). A floating item's own place\n // is a free placement, ranked like the float: its home holds only where the pick there, home ignored, is no\n // refusal and not nothing outside a target's `bounds` (past the window). Elsewhere the pick is as anywhere else.\n const underHome = atHome && options.floating ? targetAt(targets.filter((x) => inZone(x, p) && (x.refuse === true || live(x))), p) : null;\n const pastBounds = atHome && options.floating ? targets.some((x) => x.bounds !== undefined && !within(x.bounds, p)) : false;\n const homeHolds = atHome && (!options.floating || (underHome?.refuse !== true && !(underHome === null && pastBounds)));\n // Over home no target is picked, except a spring-loaded one that is armed (its zone overlaps home): home gates\n // geometry, not an armed dwell.\n const pickable = (x: T): boolean => !homeHolds || (x.arm === \"dwell\" && x.id === armedId);\n // A refusal takes part in the pick (it needs no place), but it is never a target: never held, never shown.\n const raw = targetAt(targets.filter((x) => pickable(x) && inZone(x, p) && (x.refuse === true || live(x))), p);\n // A spring-loaded target that isn't armed (any more) is no target: neither held nor shown.\n const disarmed = (x: T | null): boolean => x?.arm === \"dwell\" && x.id !== armedId;\n cur = disarmed(cur) ? null : follow(cur, targets);\n shown = disarmed(shown) ? null : follow(shown, targets);\n if (!live(cur)) cur = null;\n // A target shown with its room open holds in the room it opened (`roomHit`): what lies there is drawn as the room,\n // so a refusal under it is no refusal here.\n const roomHeld = cur && cur.opensRoom === true && cur.roomHit && roomPlace !== null && same(cur, shown) && pickable(cur) && within(cur.bounds, p) && inRect(cur.roomHit, p) ? cur : null;\n const refusedRaw = raw?.refuse === true && !roomHeld ? raw : null;\n // The band about a held zone, and the breakthrough into a zone, scaled with the zones (see `bandShare`).\n const bandOf = (held: T): Margin => scaled(tuning.band, tuning.bandShare, [held, raw && !same(raw, held) ? raw : null]);\n const pastBreakthrough = (x: T): boolean => inZoneBy(x, p, negate(scaled(tuning.breakthrough, tuning.bandShare, [x])));\n // Over a refusal nothing is held: no band and no gap grace keep the current target there.\n let next = refusedRaw ? null : raw;\n if (!refusedRaw && cur && pickable(cur) && (roomHeld !== null || inZoneBy(cur, p, bandOf(cur)))) {\n // Over a `free` target (the float everywhere) there is no edge to hold against: a more precise target takes over\n // once the pointer is in it, so a zone that ends at the window's edge is reached at its very first px. A refusal\n // here lies under the open room: it never takes over.\n const breaks = raw !== null && raw.refuse !== true && !same(raw, cur) && raw.priority < cur.priority && (cur.free === true || pastBreakthrough(raw));\n next = breaks ? raw : cur;\n }\n // The gap grace, like the band, never reaches past a zone's bounds: the float gets no grace outside the window.\n if (!refusedRaw && !next && cur && pickable(cur) && within(cur.bounds, p) && t - lastInside < tuning.gapGrace) next = cur;\n if (next && (inZone(next, p) || same(next, roomHeld))) lastInside = t;\n if (!same(next, cur)) curSince = t;\n cur = next;\n const aiming = !restart && (speed < tuning.aimSpeed || t - stillSince >= tuning.dwell);\n restart = false;\n const show = (s: T | null): void => {\n if (!same(s, shown)) shownSince = t;\n shown = s;\n };\n // Under the pointer (within its band, or in the room it holds), not just kept by the gap grace.\n const under = !!cur && (same(cur, roomHeld) || inZoneBy(cur, p, bandOf(cur)));\n // A target that opens its room as it shows shows only once it has held (`roomHold`, else `roomAfter`): one decision\n // for both, so a sweep moves nothing and the indicator never lies over what the room will move. An armed one has\n // had its dwell.\n const ready = (x: T): boolean => x.opensRoom !== true || x.arm === \"dwell\" || t - curSince >= (x.roomHold ?? tuning.roomAfter);\n // A shown target with no place here is no drop: the indicator hides at once (the switch hold is for targets).\n if (shown && !live(shown)) show(null);\n if (!shown) {\n if (cur && under && leftHome && aiming && ready(cur)) show(cur);\n } else if (same(cur, shown)) {\n // It stays while its target holds; but a pointer flying out past the band hides it at once.\n if (!aiming && !under) show(null);\n else shown = cur;\n } else if (!cur || !aiming) {\n show(null);\n } else if ((cur.priority < shown.priority && (shown.free === true || pastBreakthrough(cur))) || (under && t - curSince >= tuning.switchHold)) {\n // Not ready yet: the old indicator goes, and a release lands on the target under the pointer.\n show(ready(cur) ? cur : null);\n }\n // An armed target shows at once: the dwell was the aim. A key held wins over all of it.\n if (armedNow && cur?.id === armedId && under) show(cur);\n // A key that picks nothing here (the float key over a refusal or outside the window) shows nothing.\n if (forced) {\n if (!same(forced.target, cur)) curSince = t;\n cur = forced.target;\n show(forced.target);\n }\n // The place within the shown target, and the room: after the target and the place have both held; with the target\n // itself where showing it was already that decision (`opensRoom`, an armed target's dwell).\n const at = shown ? placeAt(shown) : null;\n if (at !== place) {\n place = at;\n placeSince = t;\n }\n if (!shown || shown.free) roomPlace = null;\n else if (shown.opensRoom === true || shown.arm === \"dwell\") roomPlace = place;\n else if (t - shownSince >= tuning.roomAfter && t - placeSince >= tuning.roomAfter) roomPlace = place;\n else if (shownSince === t) roomPlace = null;\n lastPlaces = places;\n // A refusal crossed since a target last showed: a release beyond it lands on what is under the pointer, drawn or not.\n // With a key held, the refusal is the one the key's pick met (the float key over a refusal), else none.\n const refused = forced ? forced.refused : refusedRaw;\n if (shown) crossedRefusal = false;\n else if (refused) crossedRefusal = true;\n return { shown, room: roomPlace !== null, roomPlace, aiming, atHome: !forced && wentOut && homeHolds, arming, forced: forced?.kind ?? null, refused, refusedSinceShown: !shown && !refused && crossedRefusal, landing: landAt(p, given, keys) };\n },\n release(point, given, keys) {\n return landAt(point, given, keys);\n },\n hide(time) {\n shown = null;\n cur = null;\n armedId = null;\n armingId = null;\n shownSince = time;\n place = null;\n roomPlace = null;\n lastPlaces = new Map();\n samples = [];\n anchor = null;\n restart = true;\n crossedRefusal = false;\n },\n moveHome(dx, dy) {\n home = { ...home, x: home.x + dx, y: home.y + dy };\n },\n };\n}\n","import type { Point, Rect } from \"../shapes\";\nimport type { DragKeys } from \"./intent\";\nimport type { PlaceGuides } from \"./preview\";\n\n/**\n * The landing model: where a docking drag's item lands, as state rather than a per-frame guess. A host gives it the\n * drag's regions (from `@n-uf/placement/scene`'s `lanes()`: plain data, the shapes below) and each pointer sample; it\n * says the region the pointer is in, the lane and spot held, where the item lands, whether the room is open, and the\n * place guides. Every change comes from where the pointer is and how it moved (margins, a path length, a step size):\n * the model has no waits of its own.\n *\n * - **The stage's edge** is the easiest place to dock: a pointer past the stage by up to `edge` px counts as on its\n * edge, so it lies deep inside a lane drawn against that edge; beyond, it is nowhere.\n * - **A lane holds** while the pointer is inside its rect grown by `exit`, whatever lies under it. Inside, over a spot's\n * stretch it is at that spot; over a refused stretch of the lane, refused (\"Can't go here\"). (Placement's `lanes()`\n * joins a refused stretch shorter than the item to its spots.)\n * - **Entering a lane** needs one of two gates: `path` px of slow pointer path along it inside it (steps of at most\n * `step`), or a still step (at most `still`) once `depth` px inside, the depth counted only from the lane's sides that\n * 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\n * room never opens. Inside a lane that touches the held one, past the held lane's exit margin, the held lane holds\n * 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\n * far): lane to lane never passes through the float, and never opens a crossed lane's room. Over a refused place (a\n * lane's band lying over a column that takes nothing: an empty side rail's) a lane is entered on the first slow step\n * there (not on the lift), as there is nothing else to mean there; a fly-through still opens no room. A lane that owns\n * its rect (`owns`: a rail drop strip at the window's side) takes the pointer inside it from any lane it overlaps, a\n * held one too, once its own gate passes and only once the pointer came into it from outside since the lift. Within\n * `margins.lift` of the lift point (`options.lift`, else the first point; fixed for the drag) an owning lane takes the\n * pointer by no gate, so a pointer brought back there is in the item's own lane, not the strip. Elsewhere in the strip\n * a slow slide along it can take the pointer before it is back at the lift point.\n * - **Along a lane** the spot changes once the pointer is `spot` px past the boundary; where the change moves another\n * item (the two spots' `others` keys differ), on a step of at most `step`, or once the held landing trails the\n * pointer by more than `trail`: the item chases only as far as it must. A change that moves only the held item\n * follows the hand at any speed. With `regionsFor`, a reflowing change is kept only if, in the new spot's own regions\n * (its room open), the pointer still lies in that spot's stretch: the room shifting the boundary never bounces it.\n * - **Outside every lane:** a refused place, refused; open space (`\"open\"`: the content less what blocks it, the page),\n * the float at its landing; outside the stage (past `edge`), nowhere; else (docked content that takes nothing and\n * refuses nothing) refused.\n * - **Shift** turns a lane or open space into open space (the float), and hides the guides.\n * - **Guides** are the lane's `marks` (lines between items, a box per free stretch, in the layout as drawn), else its\n * spots' landings: the held lane's; else the approached lane's (the nearest within `reach`); over a refused place the\n * nearest lane's at any distance, so the lane behind a refused column shows its guides.\n * - Steps are measured between points that differ, normalized to 125 Hz, so the gates read the same at any input rate.\n * A repeated point keeps the last step; it is still only once the pointer has stayed put for `rest` ms.\n *\n * **The host's part:** call `update` whenever you like: per pointer sample, per animation frame, or both. Call it at\n * least once more after the pointer stops (every frame does), so it can become still, and again with the same point\n * when a key changes. Give `setRegions` the `regionsFor` that answers for the new state.\n */\n\n/** A place a drop in a lane lands: its stretch of the lane and its landing rect. Ids are stable across solves. */\nexport interface LandingSpot {\n readonly id: string;\n readonly along: readonly [number, number];\n readonly landing: Rect;\n /**\n * Where its drop draws every other item, as a key: a change between two spots with the same key moves only the held\n * item. Absent: every change to or from it counts as moving others.\n */\n readonly others?: string;\n}\n/**\n * A place guide's mark, in the layout as drawn: a line between two items that touch, a box over free room the item\n * lands in, a hatch over the part of a neighbor that gives way where the room is shorter than the item.\n */\nexport interface LandingMark {\n /** Stable while its neighbors stay; absent, the guide is keyed by its lane and place in the list. */\n readonly id?: string;\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n}\nexport interface LandingLane {\n readonly id: string;\n readonly rect: Rect;\n readonly axis: \"x\" | \"y\";\n readonly spots: readonly LandingSpot[];\n readonly refused: readonly { readonly along: readonly [number, number] }[];\n /** Its guides' marks; absent, its spots' landings are the guides. */\n readonly marks?: readonly LandingMark[];\n /**\n * Its rect is its own (a rail drop strip at the window's side): inside it, once its gate passes, it takes the pointer\n * from any lane it overlaps, a held one too. Absent: where lanes overlap, the deeper one wins.\n */\n readonly owns?: boolean;\n}\n/** A drag's regions (`lanes()` gives them). */\nexport interface LandingRegions {\n readonly lanes: readonly LandingLane[];\n readonly refused: readonly Rect[];\n readonly content: Rect;\n readonly blocked: readonly Rect[];\n readonly stage: Rect;\n /** The held item's size. */\n readonly item: { readonly width: number; readonly height: number };\n}\n\nexport interface LandingMargins {\n /** Past a held lane's rect before it lets go, px. */\n readonly exit: number;\n /** Past a spot boundary before the spot changes, px. */\n readonly spot: number;\n /** Past the stage that still counts as on its edge, px; beyond, nowhere. */\n readonly edge: number;\n /**\n * Around the lift point, px (16, as the drag intent's `liftZone`): an owning lane never takes the pointer there, so\n * away and back to where the item was lifted is home.\n */\n readonly lift?: number;\n}\nexport interface LandingGates {\n /** Pointer path inside a lane that enters it, px. */\n readonly path: number;\n /** Depth inside a lane where a still step enters it, px. */\n readonly depth: number;\n /** A still step, px per 8 ms. */\n readonly still: number;\n /**\n * The largest step that changes the spot along a lane where the change reflows the window, px per 8 ms; it also\n * bounds the steps the path gate counts (a fast crossing never enters).\n */\n readonly step: number;\n /** How far the held landing may trail the pointer before a fast reflowing change is taken anyway, px. */\n readonly trail: number;\n /**\n * The time a pointer has to stay put before it counts as still, ms, where its last step was already slow (at most\n * `step`) or it is on the stage's edge (a fling there is taken at once); repeated points before it aren't still.\n */\n readonly rest: number;\n /** The time a pointer that last moved fast has to stay put before it counts as still, ms: longer than sample gaps. */\n readonly pause: number;\n}\n/** The approach for near guides: the nearest lane within `reach`, kept until another is `nearer` closer or past `keep`. */\nexport interface LandingApproach {\n readonly reach: number;\n readonly keep: number;\n readonly nearer: number;\n}\n\nexport const LANDING_MARGINS: LandingMargins = { exit: 12, spot: 6, edge: 48, lift: 16 };\n/** A touch: wider margins, the finger's jitter. */\nexport const LANDING_TOUCH_MARGINS: LandingMargins = { exit: 16, spot: 8, edge: 48, lift: 16 };\nexport const LANDING_GATES: LandingGates = { path: 40, depth: 8, still: 1.5, step: 3, trail: 40, rest: 22, pause: 60 };\nexport const LANDING_APPROACH: LandingApproach = { reach: 80, keep: 96, nearer: 16 };\n\nexport interface LandingOptions {\n readonly regions: LandingRegions;\n /** The regions with `spot` held (its room open): the fixed-point check and the stretches while held. Cached per id. */\n readonly regionsFor?: (spot: string) => LandingRegions | null;\n /** The float's landing for a pointer over the document, or null where the item doesn't float. */\n readonly floatLanding?: (point: Point) => Rect | null;\n /** The item's own place at the lift: its lane and spot (the drag starts there, the room open). */\n readonly home?: { readonly lane: string; readonly spot: string };\n /** Where the item was lifted (the press), in the regions' space; default the first point `update` gets. */\n readonly lift?: Point;\n readonly margins?: Partial<LandingMargins>;\n readonly gates?: Partial<LandingGates>;\n readonly approach?: Partial<LandingApproach>;\n readonly placeGuides?: PlaceGuides;\n}\n\nexport type LandingRegion = \"lane\" | \"open\" | \"refused\" | \"nowhere\";\n\n/** A guide: a mark of a lane, where to draw it now (a spot's landing is a box). */\nexport interface LandingGuide {\n /** Stable while its neighbors stay: the mark's id, else `<lane>/<spot id>` for a spot's landing. Key a drawing by it. */\n readonly id: string;\n readonly lane: string;\n /** A line, a box, or a hatch over a neighbor that gives way (draw it over that item, in the guides' color). */\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n}\n\nexport interface LandingFrame {\n readonly region: LandingRegion;\n /** The lane held (also over its refused stretch), or null. */\n readonly lane: string | null;\n /** The spot held, or null. */\n readonly spot: string | null;\n /** Where a release now lands: the spot's landing, or the float's; null where it lands nowhere (the item goes home). */\n readonly landing: Rect | null;\n /** The room is open: a spot is held in a lane, no Shift. */\n readonly room: boolean;\n readonly guides: readonly LandingGuide[];\n /** Shift held: the region is open space wherever it was a lane or open space. */\n readonly shift: boolean;\n /**\n * The lane the pointer is inside but hasn't entered (its gate not passed yet: a fast pass, or the moment before a slow\n * step), else absent. A host shows no \"Can't go here\" while it is set, though a release now lands nowhere: the place\n * under the pointer is a lane's, not a refused one.\n */\n readonly pending?: string;\n}\n\n/** What a release lands: a spot (`home` when it is the item's own place), the float at `rect`, or nothing. */\nexport type LandingRelease = { readonly kind: \"spot\"; readonly lane: string; readonly spot: string; readonly home: boolean } | { readonly kind: \"float\"; readonly rect: Rect } | null;\n\nexport interface LandingModel {\n update(point: Point, time: number, keys?: DragKeys): LandingFrame;\n /** What a release lands, by the last frame: the same answer as its `landing`. */\n release(): LandingRelease;\n /**\n * The regions changed (a resize, a store change, a scroll): spots map by id; a lost one goes to its lane's nearest.\n * Pass the `regionsFor` that answers for the new state; without one, the old one stays (it must then read live state).\n */\n setRegions(regions: LandingRegions, regionsFor?: (spot: string) => LandingRegions | null): void;\n /** The view moved under the pointer: the gates start again, the lane is let go. */\n hide(): void;\n readonly frame: LandingFrame;\n}\n\nconst inside = (r: Rect, p: Point, grow = 0): boolean => p.x >= r.x - grow && p.x <= r.x + r.width + grow && p.y >= r.y - grow && p.y <= r.y + r.height + grow;\nconst strictlyIn = (r: Rect, p: Point): boolean => p.x >= r.x && p.x <= r.x + r.width && p.y >= r.y && p.y <= r.y + r.height;\n/**\n * How deep `p` lies inside `r` (0 on its edge or outside), counted only from the sides of `r` that face into `stage`: a\n * side on the stage's edge is open, as deep as the pointer can go.\n */\nfunction depthIn(r: Rect, p: Point, stage: Rect): number {\n if (!strictlyIn(r, p)) return 0;\n const on = (a: number, b: number): boolean => Math.abs(a - b) < 1;\n const sides = [\n on(r.x, stage.x) ? Infinity : p.x - r.x,\n on(r.x + r.width, stage.x + stage.width) ? Infinity : r.x + r.width - p.x,\n on(r.y, stage.y) ? Infinity : p.y - r.y,\n on(r.y + r.height, stage.y + stage.height) ? Infinity : r.y + r.height - p.y,\n ];\n return Math.max(0, Math.min(...sides));\n}\nconst distanceTo = (r: Rect, p: Point): number => 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)));\nconst alongOf = (lane: LandingLane, p: Point): number => (lane.axis === \"x\" ? p.x : p.y);\nconst acrossOf = (lane: LandingLane, p: Point): number => (lane.axis === \"x\" ? p.y : p.x);\n/** Two rects meet: they overlap or touch (within 1 px), corners included. */\nconst touches = (a: Rect, b: Rect): boolean => a.x <= b.x + b.width + 1 && b.x <= a.x + a.width + 1 && a.y <= b.y + b.height + 1 && b.y <= a.y + a.height + 1;\n/** `p` onto `stage` when it lies past it by at most `reach`; else null (nowhere). */\nfunction ontoStage(stage: Rect, p: Point, reach: number): Point | null {\n if (!inside(stage, p, reach)) return null;\n return { x: Math.min(Math.max(p.x, stage.x), stage.x + stage.width), y: Math.min(Math.max(p.y, stage.y), stage.y + stage.height) };\n}\n\nexport function createLandingModel(options: LandingOptions): LandingModel {\n const margins = { ...LANDING_MARGINS, ...options.margins };\n const gates = { ...LANDING_GATES, ...options.gates };\n const approach = { ...LANDING_APPROACH, ...options.approach };\n const guidesLevel: PlaceGuides = options.placeGuides ?? \"off\";\n let base = options.regions;\n let regionsFor = options.regionsFor;\n const cache = new Map<string, LandingRegions | null>();\n /** The regions with `spot` held: the host's, cached for this lift until `setRegions`. */\n const heldRegions = (spot: string | null): LandingRegions => {\n if (!spot || !regionsFor) return base;\n if (!cache.has(spot)) cache.set(spot, regionsFor(spot));\n return cache.get(spot) ?? base;\n };\n\n let laneId: string | null = options.home?.lane ?? null;\n let spotId: string | null = options.home?.spot ?? null;\n let last: { p: Point; raw: Point; t: number } | null = null;\n /** The last point that differed from the one before, and the step then. */\n let moved: { raw: Point; t: number } | null = null;\n /** Where the item was lifted (`lift`, else the first point), fixed for the drag: back there, no owning lane takes it. */\n let liftAt: Point | null = options.lift ?? null;\n let lastStep = 0;\n /** Path inside each lane since the pointer last entered its rect. */\n const pathIn = new Map<string, number>();\n /** The path along and across each lane at any speed since the pointer entered it (a touching lane's takeover). */\n const slide = new Map<string, { along: number; across: number }>();\n /** The owning lanes the pointer has been outside since the lift: only those may take it (it came into them). */\n const cameIn = new Set<string>();\n let approached: string | null = null;\n let previous: LandingRegion = laneId ? \"lane\" : \"open\";\n let frame: LandingFrame = { region: previous, lane: laneId, spot: spotId, landing: null, room: !!spotId, guides: [], shift: false };\n\n const laneIn = (regions: LandingRegions, id: string | null): LandingLane | undefined => (id ? regions.lanes.find((l) => l.id === id) : undefined);\n const spotIn = (lane: LandingLane | undefined, id: string | null): LandingSpot | undefined => (lane && id ? lane.spots.find((s) => s.id === id) : undefined);\n\n /** The spot a point along `lane` picks: the spot whose stretch holds it, null over a refused stretch, else the nearest. */\n function pick(lane: LandingLane, a: number): LandingSpot | null {\n if (lane.refused.some((r) => a >= r.along[0] && a <= r.along[1])) return null;\n const hit = lane.spots.find((s) => a >= s.along[0] && a <= s.along[1]);\n if (hit) return hit;\n let best: LandingSpot | null = null;\n let dist = Infinity;\n for (const s of lane.spots) {\n const d = a < s.along[0] ? s.along[0] - a : a - s.along[1];\n if (d < dist) {\n best = s;\n dist = d;\n }\n }\n return best;\n }\n\n /** Along a held lane: the spot after hysteresis, the step gate and the fixed-point check. */\n function along(lane: LandingLane, p: Point, step: number): LandingSpot | null {\n const regions = heldRegions(spotId);\n const held = laneIn(regions, lane.id) ?? lane;\n const a = alongOf(held, p);\n const now = spotIn(held, spotId);\n const cand = pick(held, a);\n if (!cand) return null;\n if (!now || cand.id === now.id) return cand;\n // Past the boundary by the margin, the same everywhere (a wobble within it never flips the spot); where the change\n // moves another item, on a slow enough step. Else the last spot holds.\n const past = a < now.along[0] - margins.spot || a > now.along[1] + margins.spot;\n const reflows = now.others === undefined || now.others !== cand.others;\n if (!past) return now;\n // A fast reflowing change waits for a slow step, unless the held landing already trails the pointer by `trail`: the\n // item chases only as far as it must, so a fast hand across docked items never leaves it far behind.\n if (reflows && step > gates.step && distanceTo(now.landing, p) <= gates.trail) return now;\n // The fixed point: in the candidate's own regions (its room open), the pointer still picks it.\n if (regionsFor && reflows) {\n const theirs = heldRegions(cand.id);\n const lane2 = laneIn(theirs, lane.id);\n if (lane2 && pick(lane2, alongOf(lane2, p))?.id !== cand.id) return now;\n }\n return cand;\n }\n\n function guidesFor(p: Point, region: LandingRegion, shift: boolean): LandingGuide[] {\n if (guidesLevel === \"off\" || shift) return [];\n const regions = heldRegions(spotId);\n const all = (l: LandingLane): LandingGuide[] =>\n l.marks\n ? l.marks.map((m, i) => ({ id: m.id ?? `${l.id}#${i}`, lane: l.id, kind: m.kind, rect: m.rect }))\n : l.spots.map((s) => ({ id: `${l.id}/${s.id}`, lane: l.id, kind: \"box\" as const, rect: s.landing }));\n if (guidesLevel === \"all\") return regions.lanes.flatMap(all);\n if ((region === \"lane\" || region === \"refused\") && laneId) {\n approached = laneId;\n const l = laneIn(regions, laneId);\n return l ? all(l) : [];\n }\n let best: LandingLane | null = null;\n let bestD = Infinity;\n for (const l of regions.lanes) {\n const d = distanceTo(l.rect, p);\n if (d < bestD) {\n best = l;\n bestD = d;\n }\n }\n // Over a refused place: the nearest lane at any distance (the lane behind a refused column).\n if (region === \"refused\") {\n approached = best?.id ?? null;\n return best ? all(best) : [];\n }\n // The approached lane: the nearest within reach, kept until another is clearly nearer or it is past `keep`.\n const kept = laneIn(regions, approached);\n if (kept) {\n const d = distanceTo(kept.rect, p);\n if (d > approach.keep) approached = null;\n else if (best && best.id !== kept.id && bestD + approach.nearer < d) approached = bestD <= approach.reach ? best.id : null;\n } else approached = best && bestD <= approach.reach ? best.id : null;\n const l = laneIn(regions, approached);\n return l ? all(l) : [];\n }\n\n function update(raw: Point, t: number, keys?: DragKeys): LandingFrame {\n // Past the stage by up to `edge`: on its edge. Beyond: nowhere (kept as is).\n const p = ontoStage(heldRegions(spotId).stage, raw, margins.edge) ?? raw;\n // The step: the pointer as it moved (a fling past the edge isn't still) since the last point that differed,\n // normalized to 125 Hz (8 ms). A repeated point (a host updating per frame, or a gap between sparse samples) keeps\n // the last step until the pointer has stayed put for `rest` ms after a slow step or on the stage's edge, else for\n // `pause` ms; only then is it still. A hand moving fast with samples far apart is never still between them.\n let step = 0;\n if (moved && (raw.x !== moved.raw.x || raw.y !== moved.raw.y)) {\n step = (Math.hypot(raw.x - moved.raw.x, raw.y - moved.raw.y) * 8) / Math.max(1, t - moved.t);\n moved = { raw, t };\n lastStep = step;\n } else if (moved) {\n const stage = heldRegions(spotId).stage;\n const onEdge = p.x <= stage.x || p.y <= stage.y || p.x >= stage.x + stage.width || p.y >= stage.y + stage.height;\n const since = t - moved.t;\n step = since >= gates.pause || (since >= gates.rest && (lastStep <= gates.step || onEdge)) ? 0 : lastStep;\n } else {\n // The first point: how the pointer moves is unknown, never still (a lift over a lane's band doesn't enter it).\n moved = { raw, t };\n // (After `hide()` too, the lift point stays where the drag began.)\n liftAt ??= p;\n step = lastStep = Infinity;\n }\n const from = last?.p ?? null;\n // The pointer as it moved: a fling off the stage's edge moves across a lane there though its clamped point doesn't.\n const fromRaw = last?.raw ?? null;\n last = { p, raw, t };\n const shift = !!keys?.shift;\n const regions = heldRegions(spotId);\n // The path inside each lane: the part along the lane of slow steps from a point inside it to another (the step that\n // enters doesn't count, nor a fast one), so a crossing at `step` speed or faster never enters by path at any angle.\n // From a held lane, a touching lane counts the path along it and across it at any speed: a fast slide along it\n // (across it at most a third as far as along) is no crossing.\n const slow = step <= gates.step;\n for (const l of regions.lanes) {\n const was = from && strictlyIn(l.rect, from);\n const go = was ? Math.abs(alongOf(l, p) - alongOf(l, from)) : 0;\n const over = was && fromRaw ? Math.abs(acrossOf(l, raw) - acrossOf(l, fromRaw)) : 0;\n const inL = strictlyIn(l.rect, p);\n pathIn.set(l.id, inL ? (pathIn.get(l.id) ?? 0) + (slow ? go : 0) : 0);\n const s = slide.get(l.id);\n slide.set(l.id, inL ? { along: (s?.along ?? 0) + go, across: (s?.across ?? 0) + over } : { along: 0, across: 0 });\n if (l.owns && !inL) cameIn.add(l.id);\n }\n\n let region: LandingRegion;\n let pending: string | null = null;\n if (!inside(regions.stage, p)) {\n // Outside the stage: nowhere, and the lane is let go.\n region = \"nowhere\";\n laneId = spotId = null;\n } else {\n const held = laneIn(regions, laneId);\n const gate = (l: LandingLane): boolean => (pathIn.get(l.id) ?? 0) >= gates.path || (depthIn(l.rect, p, regions.stage) >= gates.depth && step <= gates.still);\n // Lane to lane: inside a lane touching the held one, past the held lane's exit margin (inside it the held lane holds,\n // P1), the held lane still holds until that lane's gate passes, then that lane takes it. Never the float between\n // them, never a fly-through's room.\n 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)) : undefined;\n const sl = touching ? slide.get(touching.id) : undefined;\n const slid = !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along;\n // A lane that owns its rect (a rail drop strip) takes the pointer inside it from any lane it overlaps, a held one\n // too, once its own gate passes (so a pass across it opens nothing), and only once the pointer came into it (it has\n // been outside it since the lift): a press in a column's outer edge, or a slow reorder along it, stays in the column.\n // Never within `lift` of where the item was lifted: away and back there is home, wherever a strip lies, while the\n // rest of the strip (all of it over a lone panel's own place) still takes it.\n const nearLift = !!liftAt && Math.hypot(p.x - liftAt.x, p.y - liftAt.y) <= (margins.lift ?? 16);\n const owner = nearLift ? undefined : regions.lanes.find((l) => l.owns && l.id !== held?.id && cameIn.has(l.id) && strictlyIn(l.rect, p) && gate(l));\n const next = owner ?? (touching && (gate(touching) || slid) ? touching : undefined);\n if (held && !next && (touching || inside(held.rect, p, margins.exit))) {\n const s = along(held, p, step);\n spotId = s?.id ?? spotId;\n region = s ? \"lane\" : \"refused\";\n if (!s) spotId = null;\n // Past its own rect, a held lane that refuses still holds (lane to lane never passes through the float), but\n // the pointer is in another lane it hasn't entered yet: that lane is pending, so a host shows no \"Can't go here\"\n // in a lane's first pixels when the pointer comes in over a refused stretch next to it.\n if (!s && !strictlyIn(held.rect, p)) {\n const others = regions.lanes.filter((l) => l.id !== held.id && strictlyIn(l.rect, p));\n if (others.length > 0) pending = others.reduce((a, b) => (depthIn(b.rect, p, regions.stage) > depthIn(a.rect, p, regions.stage) ? b : a)).id;\n }\n } else {\n laneId = spotId = null;\n // Entering: a touching lane at once, else the path gate or the still gate; at a tie, the lane the pointer is\n // deeper in. Over a refused place (a lane's band over a column that takes nothing, an empty side rail's) a lane is\n // entered at once, never on the lift: there is nothing else the pointer can mean there, and nothing to fly\n // through to.\n // (Over something that takes nothing reaching past the lane, a column's panel under an empty rail's band, and in\n // no other lane; a drawn bar's own rect and its items lie within it, so its gate holds.)\n // Within the lift zone an owning lane is no lane at all: by no gate does it take the pointer there.\n const lanesHere = regions.lanes.filter((l) => strictlyIn(l.rect, p) && !(l.owns && nearLift));\n const within = (b: Rect, l: LandingLane): boolean => 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;\n // On a slow step only (as a slow hand inside a bar enters it): a fly-through across such a place opens no room.\n const overRefused = (l: LandingLane): boolean =>\n Number.isFinite(step) && step <= gates.step && lanesHere.length === 1 && [...regions.blocked, ...regions.refused].some((b) => strictlyIn(b, p) && !within(b, l));\n let entered: LandingLane | null = next ?? null;\n if (!entered)\n for (const l of lanesHere) {\n const deep = depthIn(l.rect, p, regions.stage);\n if ((gate(l) || overRefused(l)) && (!entered || deep > depthIn(entered.rect, p, regions.stage))) entered = l;\n }\n // Inside a lane not entered yet: no refused place to say so of, whatever lies under it.\n 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;\n if (entered) {\n laneId = entered.id;\n const s = pick(entered, alongOf(entered, p));\n spotId = s?.id ?? null;\n region = s ? \"lane\" : \"refused\";\n } else if (regions.refused.some((r) => inside(r, p))) region = \"refused\";\n else if (inside(regions.content, p) && !regions.blocked.some((b) => strictlyIn(b, p))) region = \"open\";\n // Inside a lane not yet entered: what it was (on the way in, the document's float).\n else if (regions.lanes.some((l) => strictlyIn(l.rect, p))) region = previous === \"lane\" ? \"open\" : previous;\n else region = \"refused\";\n }\n }\n previous = region;\n const shown: LandingRegion = shift && (region === \"lane\" || region === \"open\") ? \"open\" : region;\n const r2 = heldRegions(spotId);\n const spot = spotIn(laneIn(r2, laneId), spotId);\n const landing = shown === \"lane\" ? (spot?.landing ?? null) : shown === \"open\" ? (options.floatLanding?.(p) ?? null) : null;\n frame = {\n region: shown,\n lane: laneId,\n spot: shown === \"lane\" ? spotId : null,\n landing,\n room: shown === \"lane\" && !!spot,\n guides: guidesFor(p, shown, shift),\n shift,\n ...(pending && shown !== \"lane\" ? { pending } : {}),\n };\n return frame;\n }\n\n return {\n update,\n release(): LandingRelease {\n if (frame.region === \"lane\" && frame.lane && frame.spot) return { kind: \"spot\", lane: frame.lane, spot: frame.spot, home: !!options.home && options.home.spot === frame.spot && options.home.lane === frame.lane };\n if (frame.region === \"open\" && frame.landing) return { kind: \"float\", rect: frame.landing };\n return null;\n },\n setRegions(regions: LandingRegions, nextRegionsFor?: (spot: string) => LandingRegions | null): void {\n base = regions;\n if (nextRegionsFor) regionsFor = nextRegionsFor;\n cache.clear();\n const l = laneIn(base, laneId);\n if (laneId && !l) laneId = spotId = null;\n else if (l && spotId && !spotIn(l, spotId) && last) spotId = pick(l, alongOf(l, last.p))?.id ?? null;\n },\n hide(): void {\n laneId = spotId = null;\n approached = null;\n pathIn.clear();\n slide.clear();\n cameIn.clear();\n last = moved = null;\n lastStep = 0;\n },\n get frame(): LandingFrame {\n return frame;\n },\n };\n}\n","import type { DragFrame, DragTarget } from \"./intent\";\n\n/**\n * How a drag previews its drop, from least to most motion while dragging:\n *\n * - `\"indicator\"`: nothing moves; only the indicator (an outline or an\n * insertion marker) shows the target.\n * - `\"gap\"`: once the room is made, the others move aside and open the slot;\n * the item stays under the pointer.\n * - `\"snap\"`: the gap opens and the item itself glides into it (for a target\n * with a slot; one without keeps the indicator).\n * - `\"item\"`: the dragged item is the only preview: no indicator for any\n * target. It sits in a slotted target once the room is open and otherwise\n * stays on the pointer. Pair it with the intent's `earlyRelease: \"float\"`, so\n * a release lands what shows.\n *\n * Every mode follows the same intent: what shows, when, and what a release\n * lands on are the drag intent's, so a drop always lands where the preview\n * showed it.\n */\nexport type DragPreview = \"indicator\" | \"gap\" | \"snap\" | \"item\";\n\n/** The preview a drag uses unless the host picks another. */\nexport const DRAG_PREVIEW_DEFAULT: DragPreview = \"snap\";\n\n/**\n * Place guides: faint marks on the free places that take the held item, shown only while no landing shows. `\"off\"`:\n * none; `\"near\"`: the places of the edge the pointer approaches; `\"all\"`: every place, from the lift.\n */\nexport type PlaceGuides = \"off\" | \"near\" | \"all\";\n\n/**\n * 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\n * the lane will take, over what moves aside (the page, a column); `\"edge\"`, a thin striped strip on the lane's window\n * side. The landing is the same either way. Placement's `lanes()` takes it as `emptyLanes`.\n */\nexport type EmptyLanes = \"real\" | \"edge\";\n\n/**\n * A drop preview as a mode and its place guides, beside the string forms: `\"outline\"` is `\"indicator\"`'s plan,\n * `\"placeholder\"` is `\"gap\"`'s, and `\"snap\"` is `\"item\"`'s (the item the only preview). `placeGuides` defaults per mode\n * ({@link PLACE_GUIDES_DEFAULT}); `emptyLanes` (how its guides draw an empty lane) defaults to `\"real\"`.\n */\nexport type DropPreviewMode =\n | { readonly mode: \"outline\"; readonly placeGuides?: PlaceGuides; readonly emptyLanes?: EmptyLanes }\n | { readonly mode: \"placeholder\"; readonly placeGuides?: PlaceGuides; readonly emptyLanes?: EmptyLanes }\n | { readonly mode: \"snap\"; readonly placeGuides?: PlaceGuides; readonly emptyLanes?: EmptyLanes };\n\n/** Each mode's place guides when it names none: Snap and Placeholder near, Outline none. */\nexport const PLACE_GUIDES_DEFAULT: Readonly<Record<DropPreviewMode[\"mode\"], PlaceGuides>> = { outline: \"off\", placeholder: \"near\", snap: \"near\" };\n\n/** The string plan each mode draws with. */\nconst PLAN_OF: Readonly<Record<DropPreviewMode[\"mode\"], DragPreview>> = { outline: \"indicator\", placeholder: \"gap\", snap: \"item\" };\n\n/** What to draw for one frame of a drag. */\nexport interface PreviewPlan {\n /** Draw the indicator on the shown target. */\n readonly showIndicator: boolean;\n /** Lay the others out around the room (the gap is open). */\n readonly makeRoom: boolean;\n /** Draw the item in its slot instead of under the pointer. */\n readonly snapItem: boolean;\n /**\n * The place guides to draw this frame: the mode's `placeGuides` while no landing shows (no indicator, no room, no item\n * in its slot), `\"off\"` whenever one does, so the screen shows where the item can go or where it will land, never\n * both. Always `\"off\"` for the string forms. Optional, so a plan a host builds itself is still one: absent means\n * `\"off\"`.\n */\n readonly guides?: PlaceGuides;\n /** How the guides draw an empty lane (the object form's `emptyLanes`, `\"real\"` when it names none); absent for the string forms. */\n readonly emptyLanes?: EmptyLanes;\n}\n\n/**\n * The plan for a frame of the drag intent under `preview`. `slotted` says\n * whether the shown target's drop has a slot the item can sit in (default: a\n * target that isn't `free`); only such a target snaps, and in `\"snap\"` it\n * previews with the item rather than the indicator.\n *\n * - `\"indicator\"`: the indicator, never room, never a snap.\n * - `\"gap\"`: the indicator, and room when the intent makes it.\n * - `\"snap\"`: room when the intent makes it, the item snapped into a slotted\n * target's room; the indicator only for a target without a slot.\n * - `\"item\"`: as `\"snap\"`, with no indicator at all.\n *\n * The object form ({@link DropPreviewMode}) draws with its mode's string plan and adds its place guides (`guides`).\n */\nexport function previewPlan<T extends DragTarget>(\n frame: Pick<DragFrame<T>, \"shown\" | \"room\">,\n preview: DragPreview | DropPreviewMode,\n slotted: boolean = !!frame.shown && !frame.shown.free,\n): PreviewPlan {\n if (typeof preview === \"object\") {\n const plan = stringPlan(frame, PLAN_OF[preview.mode], slotted);\n const asked = preview.placeGuides ?? PLACE_GUIDES_DEFAULT[preview.mode];\n const landing = plan.showIndicator || plan.makeRoom || plan.snapItem;\n return { ...plan, guides: landing ? \"off\" : asked, emptyLanes: preview.emptyLanes ?? \"real\" };\n }\n return stringPlan(frame, preview, slotted);\n}\n\nfunction stringPlan<T extends DragTarget>(frame: Pick<DragFrame<T>, \"shown\" | \"room\">, preview: DragPreview, slotted: boolean): PreviewPlan {\n const shown = !!frame.shown;\n if (preview === \"indicator\") return { showIndicator: shown, makeRoom: false, snapItem: false, guides: \"off\" };\n if (preview === \"gap\") return { showIndicator: shown, makeRoom: frame.room, snapItem: false, guides: \"off\" };\n if (preview === \"item\") return { showIndicator: false, makeRoom: frame.room, snapItem: frame.room && shown && slotted, guides: \"off\" };\n // By design a slotted target draws nothing until the room opens (`roomAfter`); a release then still lands on it.\n return { showIndicator: shown && !slotted, makeRoom: frame.room, snapItem: frame.room && shown && slotted, guides: \"off\" };\n}\n","import { DOUBLE_CLICK, type DoubleClick } from \"../double-click\";\nimport type { Point } from \"../shapes\";\nimport { liftDecision, type DragTuning, type LiftDecision } from \"./intent\";\n\n/** How a press on a grip ended: a click, the second click of a double (`doubleActivate`, not a click), or a drag (`null`). */\nexport type GripRelease = \"click\" | \"doubleActivate\" | null;\n\n/** A press on a grip, start to end: whether it lifts, and what its release is. Pure: positions and times are the host's. */\nexport interface GripPress {\n /**\n * A press at `point`, `time` ms. `touch` for a finger (the touch lift rule). `clicks`, when the host has the\n * platform's count for this press (a `mousedown`'s `detail`, 1 or more), decides the double instead of the interval.\n */\n down(point: Point, time: number, options?: { readonly touch?: boolean; readonly clicks?: number }): void;\n /** The pointer moved: `liftDecision` for this press. Once `\"lift\"` it stays a drag; once `\"refuse\"` it never is. */\n move(point: Point, time: number): LiftDecision;\n /**\n * The press ended. `\"click\"`, or `\"doubleActivate\"` when it is the second click of a double (it is not a click\n * then); null when it lifted or was refused. A press that never moved past the lift distance never lifts, so an\n * unmoved double never starts a drag (a second press that moves past it is a drag like any other). A third click\n * after a double starts a new pair.\n */\n up(point: Point, time: number): GripRelease;\n /** Forget the press and the click before it (a cancelled press, a scroll). */\n cancel(): void;\n}\n\n/**\n * A grip's press, double-click included: a press that moves past the lift distance is a drag; one that doesn't is a\n * click, and a second such press within the double interval and distance is a double-activate (the host folds or\n * unfolds, say), never a second click and never a lift: an unmoved double never starts a drag.\n *\n * The first click of a double is delivered as `\"click\"` before the double is known (nothing waits for a second press),\n * so a host keeps a grip's click harmless (a use, a focus): the double-activate that follows must not have to undo it.\n */\nexport function createGripPress(options: { readonly tuning?: Partial<DragTuning>; readonly double?: Partial<DoubleClick> } = {}): GripPress {\n const tuning = options.tuning ?? {};\n // The package's one double click (`DOUBLE_CLICK`), unless the host tunes it.\n const dbl: DoubleClick = { ...DOUBLE_CLICK, ...options.double };\n let press: { at: Point; time: number; touch: boolean; double: boolean; state: LiftDecision } | null = null;\n // The last click (a press that ended as one): where and when it was pressed.\n let last: { at: Point; time: number } | null = null;\n return {\n down(point, time, o = {}) {\n const near = !!last && time - last.time <= dbl.ms && Math.hypot(point.x - last.at.x, point.y - last.at.y) <= dbl.px;\n const double = o.clicks !== undefined && o.clicks > 0 ? o.clicks === 2 : near;\n press = { at: { x: point.x, y: point.y }, time, touch: !!o.touch, double, state: \"wait\" };\n },\n move(point, time) {\n if (!press) return \"wait\";\n if (press.state !== \"wait\") return press.state;\n press.state = liftDecision({ touch: press.touch, distance: Math.hypot(point.x - press.at.x, point.y - press.at.y), elapsed: time - press.time }, tuning);\n return press.state;\n },\n up() {\n const p = press;\n press = null;\n if (!p || p.state !== \"wait\") {\n last = null;\n return null;\n }\n if (p.double) {\n last = null;\n return \"doubleActivate\";\n }\n last = { at: p.at, time: p.time };\n return \"click\";\n },\n cancel() {\n press = null;\n last = null;\n },\n };\n}\n","import type { Rect } from \"../shapes\";\n\n/** A guide to place: any record with a `kind` and a `rect` (a landing model's `LandingGuide`, a lane's marks). */\nexport interface PlacedGuide {\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n}\n\nexport interface GuideRectsOptions {\n /** The area guides are drawn in: the window's inside (inside its border), px. */\n readonly inside: Rect;\n /** How far inside `inside` every guide stays, px (default 2). */\n readonly inset?: number;\n /** Rects a thin guide stays clear of (the content: a column's panels under an empty lane's thin edge). */\n readonly clear?: readonly Rect[];\n /** The least thickness a thin guide keeps, px (default 2); thinner, it is not drawn. */\n readonly minThickness?: number;\n}\n\nconst EPS = 1e-6;\n\n/**\n * Where to draw guides: every guide inside `inside` by `inset`. A box is clipped. A thin guide (a line, a striped\n * strip or end: its shorter side is its thickness) keeps its thickness and moves inside rather than being clipped, so\n * 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\n * `clear`, so a thin strip at the window's side lies between the inset and the content, the same on both sides. A\n * guide with nothing left (or a thin one under `minThickness`) is left out. Pure; the guides come back as given with\n * their placed `rect`.\n */\nexport function guideRects<G extends PlacedGuide>(guides: readonly G[], options: GuideRectsOptions): G[] {\n const inset = Number.isFinite(options.inset) ? Math.max(0, options.inset!) : 2;\n const min = Number.isFinite(options.minThickness) ? Math.max(0, options.minThickness!) : 2;\n // A guide placed where it already was comes back as given (the same rect object), so a host can key on it.\n const same = (a: Rect, b: Rect): boolean => 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;\n const place = (g: G, rect: Rect): G => (same(g.rect, rect) ? g : { ...g, rect });\n const x0 = options.inside.x + inset;\n const y0 = options.inside.y + inset;\n const x1 = options.inside.x + options.inside.width - inset;\n const y1 = options.inside.y + options.inside.height - inset;\n const clear = options.clear ?? [];\n const out: G[] = [];\n for (const g of guides) {\n const r = g.rect;\n if (g.kind === \"box\") {\n const a = Math.max(r.x, x0);\n const b = Math.max(r.y, y0);\n const c = Math.min(r.x + r.width, x1);\n const d = Math.min(r.y + r.height, y1);\n if (c - a > EPS && d - b > EPS) out.push(place(g, { x: a, y: b, width: c - a, height: d - b }));\n continue;\n }\n // A thin guide: thick along one axis (its shorter side), long along the other.\n const thinX = r.width <= r.height;\n // Along its thickness: moved inside whole; along its length: clipped.\n const t = thinX ? r.width : r.height;\n let lo = thinX ? r.x : r.y;\n const lim0 = thinX ? x0 : y0;\n const lim1 = thinX ? x1 : y1;\n if (lo + t > lim1) lo = lim1 - t;\n if (lo < lim0) lo = lim0;\n let hi = Math.min(lo + t, lim1);\n const s0 = Math.max(thinX ? r.y : r.x, thinX ? y0 : x0);\n const s1 = Math.min(thinX ? r.y + r.height : r.x + r.width, thinX ? y1 : x1);\n if (s1 - s0 <= EPS) continue;\n // Clear of what it must not cover: cut from the side the clear rect lies on.\n for (const c of clear) {\n const cs0 = thinX ? c.y : c.x;\n const cs1 = thinX ? c.y + c.height : c.x + c.width;\n if (cs1 <= s0 + EPS || cs0 >= s1 - EPS) continue;\n const c0 = thinX ? c.x : c.y;\n const c1 = thinX ? c.x + c.width : c.y + c.height;\n if (c1 <= lo + EPS || c0 >= hi - EPS) continue;\n // Keep the side away from the clear rect's middle.\n if ((c0 + c1) / 2 >= (lo + hi) / 2) hi = Math.min(hi, c0);\n else lo = Math.max(lo, c1);\n }\n if (hi - lo < Math.max(EPS, min)) continue;\n 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 }));\n }\n return out;\n}\n"],"mappings":";;;;;AAoGO,IAAM,gBAA4B;AAAA,EACvC,MAAM;AAAA,EACN,WAAW;AAAA,EACX,WAAW;AAAA,EACX,aAAa;AAAA,EACb,UAAU;AAAA,EACV,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,cAAc;AAAA,EACd,WAAW;AAAA,EACX,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,WAAW;AAAA,EACX,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,WAAW,EAAE,IAAI,MAAM,UAAU,SAAS,SAAS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ts","../src/drag/guide-rects.ts"],"sourcesContent":["import type { Point, Rect } from \"../shapes\";\n\n/**\n * The drag intent model's tuning. Distances in px, speeds in px/ms, times in\n * ms; every value can be overridden per intent (see\n * {@link DragIntentOptions.tuning}).\n */\nexport interface DragTuning {\n /** A mouse press lifts once the pointer has moved this far. */\n readonly lift: number;\n /** A touch press lifts only after it has been held this long… */\n readonly touchHold: number;\n /** …and then moved this far (moving that far before the hold is over is not a drag). */\n readonly touchLift: number;\n /** The pointer's speed is measured over this window and smoothed. */\n readonly speedWindow: number;\n /** Aiming: the smoothed speed is below this… */\n readonly aimSpeed: number;\n /** …or the pointer has stayed within `still` px of one spot for `dwell` ms. */\n readonly still: number;\n readonly dwell: number;\n /** The current target holds while the pointer is within this band of its zone. */\n readonly band: number;\n /** A higher-priority target takes over at once when the pointer is this far inside it. */\n readonly breakthrough: number;\n /**\n * The band and the breakthrough scale with the zones: along each axis they are at most this share of the held\n * zone's extent and of the extent of the zone under the pointer (its `hit`), so a small zone (a 28 px row) can be\n * entered by a direct glide from its neighbor. Below a quarter, the pointer at a quarter of a zone is past them.\n */\n readonly bandShare: number;\n /** A gap between zones shorter than this keeps the current target (for a pointer that aims). */\n readonly gapGrace: number;\n /** Aiming, the shown target moves to another one only once that one has held this long. */\n readonly switchHold: number;\n /**\n * Room is made once the shown target, and the place in it, have held this long, so a pointer moving across targets\n * doesn't reflow the layout under it. A target with `opensRoom` holds this long before it shows, its room with it.\n */\n readonly roomAfter: number;\n /** The pointer has left the item's home once it is outside the home shrunk by this much on every side. */\n readonly homeInset: number;\n /**\n * Spring-loading: a target marked `arm: \"dwell\"` takes the drop only once the pointer has stayed in its zone this long\n * (ms); before that it is no target, so a fast pass, or a drop before it, lands on what lies beneath. 0 arms it at once.\n * Armed, its zone is its `armedHit` (the magnet: its band); moving out past that band's outer edge disarms it, and\n * re-entering needs a new full dwell. It arms only after the pointer has ENTERED its zone during the drag: the point\n * the drag starts at counts as not entered, so a drag that starts inside the zone (a panel's grip under the strip at\n * the window's edge) must leave it and come back before it can arm; entering from over home counts.\n */\n readonly railArmDwellMs: number;\n /**\n * The lift zone, a radius in px about the point the drag was lifted at ({@link DragIntentOptions.lift}, else the first\n * sample): no spring-loaded target arms by dwell inside it. Coming back to where you lifted and pausing is the\n * \"changed my mind\" gesture, so it commits nothing even where a strip lies over the grip (a flush drawer's grip at the\n * window's edge). 16 px is about a grip's size. Elsewhere, home under a strip included, arming works as before, and\n * the rail key forces the rail anywhere, the lift zone too.\n */\n readonly liftZone: number;\n /** The keys that win over geometry while held (see {@link DragModifiers}). */\n readonly modifiers: DragModifiers;\n}\n\n/**\n * A modifier key, by its `KeyboardEvent.key` name, or `\"Mod\"`: ⌘ (Meta) on macOS and Ctrl elsewhere. `\"Mod\"` counts\n * either key as held, so no platform detection is needed.\n */\nexport type ModifierKey = \"Shift\" | \"Alt\" | \"Control\" | \"Meta\" | \"Mod\";\n\n/** The modifier keys held on a sample (a pointer event's `shiftKey`, `altKey`, `ctrlKey`, `metaKey`). */\nexport interface DragKeys {\n readonly shift?: boolean;\n readonly alt?: boolean;\n readonly ctrl?: boolean;\n readonly meta?: boolean;\n}\n\n/**\n * Keys that win over geometry: while `floatKey` is held the drop floats (the `free` target) wherever the pointer is,\n * except over a refusal (the frame is refused) or outside the float's `bounds` (nothing);\n * while `railKey` is held it goes to the nearest target marked `arm` (a side's rail), without reaching it. `floatKey`\n * wins when both are held. `on: false` turns both off.\n */\nexport interface DragModifiers {\n readonly on: boolean;\n readonly floatKey: ModifierKey;\n readonly railKey: ModifierKey;\n}\n\n/**\n * The defaults: a mouse lifts after 5 px, a touch after a 180 ms hold and\n * 8 px; aiming is slower than 0.45 px/ms over 50 ms, or within 12 px for\n * 90 ms; a 10 px band and a 4 px breakthrough, each at most a fifth of the\n * zones' extents, and a 120 ms gap grace; a switch waits 150 ms (the shortest\n * an indicator may show); room after 160 ms. A spring-loaded target arms after\n * 200 ms of dwell (long enough that a pass at travelling speed never arms it,\n * short enough to feel like the platforms' spring-loading); Shift floats, ⌘/Ctrl\n * (`\"Mod\"`) goes to the nearest rail. Alt is left free: an app with a frozen\n * layout uses it to unfreeze temporarily, and a key should have one meaning.\n */\nexport const DRAG_DEFAULTS: DragTuning = {\n lift: 5,\n touchHold: 180,\n touchLift: 8,\n speedWindow: 50,\n aimSpeed: 0.45,\n still: 12,\n dwell: 90,\n band: 10,\n breakthrough: 4,\n bandShare: 0.2,\n gapGrace: 120,\n switchHold: 150,\n roomAfter: 160,\n homeInset: 6,\n railArmDwellMs: 200,\n liftZone: 16,\n modifiers: { on: true, floatKey: \"Shift\", railKey: \"Mod\" },\n};\n\nconst KEY_FIELD: Record<Exclude<ModifierKey, \"Mod\">, keyof DragKeys> = { Shift: \"shift\", Alt: \"alt\", Control: \"ctrl\", Meta: \"meta\" };\n/** Whether `key` is held in `keys` (`\"Mod\"`: ⌘ or Ctrl). */\nconst held = (keys: DragKeys | undefined, key: ModifierKey): boolean =>\n !!keys && (key === \"Mod\" ? !!(keys.meta || keys.ctrl) : !!keys[KEY_FIELD[key]]);\n\n/**\n * A drop target: plain data. `hit` is the zone the pointer can be in;\n * `priority` how precise it is (1 beats 2 beats 3; equal priorities go to the\n * smaller zone). `slot` is where the dragged item would land, `label` what to\n * call it; the model reads neither. A `free` target has no slot (the item\n * floats where it is dropped): no room is made for it. `hits`, when given, is\n * the whole zone as several rects (a zone that isn't one rect, `hit` the\n * largest of them): the pointer is in the zone when it is in any of them.\n *\n * `arm: \"dwell\"` makes it spring-loaded: it is no target until the pointer has\n * dwelt in its zone for `railArmDwellMs`; once armed its zone is `armedHit`\n * when given (a magnet: the zone grown), and leaving that disarms it.\n *\n * `refuse: true` makes it a refusal: a place that takes no drop (a host draws nothing over it, and at most says \"Can't\n * go here\" at the pointer). It takes part in\n * the pick under the pointer at {@link REFUSAL_RANK} (below every target of priority 1 or 2, whatever its own\n * `priority`, above priority 3), but it never becomes the current or the shown target, and a release over it lands\n * nowhere. Where the pick under the pointer is a refusal, no held target's band or gap grace keeps it: nothing shows,\n * and the frame's `refused` says which refusal it is.\n *\n * `bounds`, when given, is the drawn space the zone belongs to (a window's stage): the zone, its band and its gap grace\n * hold only points strictly inside it, so it is half-open toward the outside and a point on `bounds`' boundary or past\n * it is never in it. The window's boundary belongs only to the targets drawn against it: a refusal and a target over\n * the whole plane (the float) carry `bounds`, a gap or a slot doesn't. So a pointer a host clamps onto the window's\n * edge picks a gap whose hit reaches the edge, else nothing (a held target keeps its band), and never a refusal or the\n * float. The rule relies on the host clamping exactly onto the stage's edge (`x + width`, `y + height`): a host that\n * clamps to `width - 0.5` still picks inside the window, the float or a refusal there included.\n *\n * `opensRoom: true` marks a target whose indicator would lie over what its room moves (a side rail that pushes a column\n * aside). Showing it and making its room are then one decision: it shows only once it has held `roomAfter` ms, and the\n * frame that first shows it already has `room`. A sweep across it moves nothing, as for any target, and no frame draws\n * it over the column. Until it shows, a release still lands on it. An armed spring-loaded target has its room at once\n * too: its dwell was the decision. `roomHold` is how long this target holds before that decision, in ms, in place of\n * `roomAfter` (a rail or a new-column line against the window's edge, which a pointer rarely crosses on its way\n * elsewhere, can wait less). A\n * host that draws only a marker and doesn't use `previewPlan`'s room opens the room on\n * `frame.room && frame.shown?.opensRoom`.\n *\n * `roomHit`, with `opensRoom`, is where the target's room draws the item once it is open (its landing rect: an empty\n * rail or bar is entered over its drawn depth). While the target shows with its room open it holds in `hit ∪ roomHit`: wherever\n * the pointer is in `roomHit` and inside its `bounds` too. What lies there is drawn as the room, so a refusal or a\n * target of the same or a lower precision under it doesn't take over, and the frame isn't `refused` there. A more\n * precise target (a lower `priority`) still takes over once the pointer is past `breakthrough` into it, and a held key\n * still wins. Out of both the target is held as any other (its `hit` and band), so once it goes its zone is `hit` again.\n */\nexport interface DragTarget {\n readonly id: string;\n readonly priority: 1 | 2 | 3;\n readonly hit: Rect;\n readonly hits?: readonly Rect[];\n readonly slot?: Rect;\n readonly label?: string;\n readonly free?: boolean;\n readonly arm?: \"dwell\";\n readonly armedHit?: Rect;\n readonly refuse?: true;\n readonly bounds?: Rect;\n readonly opensRoom?: true;\n readonly roomHold?: number;\n readonly roomHit?: Rect;\n}\n\n/**\n * Where a refusal ranks in the pick ({@link targetAt}): an ordering rank, not a priority. Priorities stay the integers\n * 1, 2 and 3; a refusal's tier is `refuse: true`, and the pick orders it by this rank on the same scale: after every\n * target of priority 1 and 2 (a refusal and a real target where they meet or overlap: the target wins, so a gap keeps\n * its end), before priority 3 (the float: over drawn space that takes nothing, the refusal wins over floating).\n * Among refusals the smaller zone wins. `@n-uf/placement` exports the same value for its reference pick.\n */\nexport const REFUSAL_RANK = 2.5;\n\n/** A target's rank in the pick: its `priority`, a refusal's {@link REFUSAL_RANK}. Lower wins. */\nexport const pickRank = (t: Pick<DragTarget, \"priority\" | \"refuse\">): number => (t.refuse === true ? REFUSAL_RANK : t.priority);\n\n/** Whether `point` lies strictly inside `bounds` (none: everywhere). */\nconst within = (bounds: Rect | undefined, point: Point): boolean =>\n !bounds || (point.x > bounds.x && point.x < bounds.x + bounds.width && point.y > bounds.y && point.y < bounds.y + bounds.height);\n\n/** Whether `point` lies in `rect` grown by `margin` px on every side (shrunk, for a negative margin). */\nexport function inRect(rect: Rect, point: Point, margin = 0): boolean {\n return point.x >= rect.x - margin && point.x <= rect.x + rect.width + margin && point.y >= rect.y - margin && point.y <= rect.y + rect.height + margin;\n}\n\n/** How far `point` lies from `rect` (0 inside it). */\nconst distanceTo = (rect: Rect, point: Point): number =>\n Math.hypot(Math.max(rect.x - point.x, 0, point.x - (rect.x + rect.width)), Math.max(rect.y - point.y, 0, point.y - (rect.y + rect.height)));\n\n/** Whether `point` lies in a target's zone (`hits` when it has them, else `hit`), grown by `margin` px, and inside its `bounds`. */\nconst inZone = (t: DragTarget, point: Point, margin = 0): boolean => within(t.bounds, point) && (t.hits ? t.hits.some((r) => inRect(r, point, margin)) : inRect(t.hit, point, margin));\n\n/** A margin per axis: px grown (shrunk, when negative) left and right, and above and below. */\ninterface Margin {\n readonly x: number;\n readonly y: number;\n}\n/**\n * Whether `point` lies in a target's zone grown by `m.x` px left and right and `m.y` px above and below, and inside its\n * `bounds`: a band never reaches past a zone's bounds (the float's band holds nothing outside the window).\n */\nconst inZoneBy = (t: DragTarget, point: Point, m: Margin): boolean =>\n within(t.bounds, point) && (t.hits ?? [t.hit]).some((r) => point.x >= r.x - m.x && point.x <= r.x + r.width + m.x && point.y >= r.y - m.y && point.y <= r.y + r.height + m.y);\n/** `px`, but along each axis at most `share` of each zone's extent (its `hit`) along it. */\nconst scaled = (px: number, share: number, zones: readonly (DragTarget | null)[]): Margin => {\n let x = px;\n let y = px;\n for (const z of zones) {\n if (!z) continue;\n x = Math.min(x, share * z.hit.width);\n y = Math.min(y, share * z.hit.height);\n }\n return { x, y };\n};\nconst negate = (m: Margin): Margin => ({ x: -m.x, y: -m.y });\n\nconst area = (r: Rect): number => r.width * r.height;\n/** A target's zone's area: its `hits` together, else its `hit`. */\nconst zoneArea = (t: DragTarget): number => (t.hits ? t.hits.reduce((s, r) => s + area(r), 0) : area(t.hit));\n\n/**\n * The most precise target under `point`: the lowest rank ({@link pickRank}: the priority, a refusal's\n * {@link REFUSAL_RANK}), then the smallest zone; null when none is. A zone holds its edges (a closed rect), except\n * toward the outside of its `bounds`.\n */\nexport function targetAt<T extends DragTarget>(targets: readonly T[], point: Point): T | null {\n let best: T | null = null;\n for (const t of targets) {\n if (!inZone(t, point)) continue;\n if (!best || pickRank(t) < pickRank(best) || (pickRank(t) === pickRank(best) && zoneArea(t) < zoneArea(best))) best = t;\n }\n return best;\n}\n\n/** What a press does so far: not yet a drag (`wait`), a drag (`lift`), or never one (`refuse`: a touch that moved too soon). */\nexport type LiftDecision = \"wait\" | \"lift\" | \"refuse\";\n\n/**\n * The lift rule for a press that has moved `distance` px in `elapsed` ms. A\n * mouse (or pen) lifts at `lift` px. A touch lifts only after `touchHold` ms,\n * then at `touchLift` px; moving `touchLift` px before the hold is over\n * refuses the drag (the finger is scrolling or swiping).\n */\nexport function liftDecision(press: { readonly touch: boolean; readonly distance: number; readonly elapsed: number }, tuning: Partial<DragTuning> = {}): LiftDecision {\n const t = { ...DRAG_DEFAULTS, ...tuning };\n if (!press.touch) return press.distance >= t.lift ? \"lift\" : \"wait\";\n if (press.elapsed < t.touchHold) return press.distance >= t.touchLift ? \"refuse\" : \"wait\";\n return press.distance >= t.touchLift ? \"lift\" : \"wait\";\n}\n\n/** One update's answer. */\nexport interface DragFrame<T extends DragTarget> {\n /** The target the drop indicator shows, or null. */\n readonly shown: T | null;\n /**\n * The others make room for the shown target: it, and the place in it, have held `roomAfter` ms. For a target with\n * `opensRoom`, or an armed spring-loaded one, from the first frame that shows it.\n */\n readonly room: boolean;\n /**\n * The place the room is made for, or null. Within one target it stays on\n * the old place until a new one has held `roomAfter` ms (see\n * {@link DragIntentOptions.placeOf}).\n */\n readonly roomPlace: string | null;\n /** The pointer is aiming: slow, or nearly still for a moment. */\n readonly aiming: boolean;\n /**\n * The pointer is back inside `home` after it has been outside `home` itself. Never true at the press, nor while the\n * pointer only moves about inside `home`, even near its edge (where `state.leftHome` is already true: that flag is for\n * the indicator's gate and uses `homeInset`; this one does not). Over home no target is shown and a release does\n * nothing, so a host that wants to say \"a drop here returns it\" draws its own indicator for this frame (at the home\n * rect); the intent still shows no target.\n *\n * A docked item's home holds wherever it lies. The home of a floating item (`DragIntentOptions.floating`) is a free\n * placement, ranked like the float: it holds only where the pick there, home ignored, is no refusal and the point is\n * inside the window. Where it doesn't hold this is false and the pick is as anywhere else: over a refusal\n * `refused` says so, and a release lands nowhere.\n */\n readonly atHome: boolean;\n /**\n * A spring-loaded target (`arm: \"dwell\"`) the pointer is in and dwelling on, not armed yet (a host highlights it), or\n * null. Once it arms it is a target like any other and may show.\n */\n readonly arming: T | null;\n /**\n * A key held wins over geometry this frame: `\"float\"` (the float key) or `\"rail\"` (the rail key), else null. The\n * float key chooses the float over dock targets, not over a refusal or outside the window: there it is still\n * `\"float\"` (the key is held), but nothing shows, a release lands nowhere, and over a refusal `refused` says which.\n */\n readonly forced: \"float\" | \"rail\" | null;\n /**\n * The refusal (a target with `refuse: true`) the pointer is over, when it is the pick there: no target shows. A host\n * never draws the refused place; it may say \"Can't go here\" at the pointer. Null otherwise, and while a key forces a target; with the float key\n * held over a refusal it is that refusal (the key doesn't float over refused space).\n */\n readonly refused: T | null;\n /**\n * No target shows, and the pointer has been over a refusal since a target last showed (or since the lift). A refusal\n * hides the shown target at once, and the next one shows only once the pointer aims again, so a pointer that crosses\n * a refusal and is let go at speed over a target beyond it has no indicator drawn. Then this is true, and a release\n * still lands on what is under the pointer (`release`): a host that commits only what it has drawn commits that\n * release too. False whenever a target shows, over the refusal itself (`refused`), and after `hide`.\n *\n * Read it from the frame of an `update` at the release point, called before `release` (as `release` asks anyway), so\n * the last move counts. The field is required: a host or a test mock that builds a `DragFrame` itself must set it.\n */\n readonly refusedSinceShown: boolean;\n /**\n * What a release at this frame's point lands on, by the one check `release` makes (`earlyRelease` included), or null\n * (nowhere, or the item goes home). A host draws the landing from it, so what it draws and what a release lands on\n * never disagree. `createDragIntent` always sets it; it is optional only so a host or a test that builds a frame\n * itself needn't.\n */\n readonly landing?: T | null;\n}\n\n/** What a drag intent knows now. */\nexport interface DragIntentState<T extends DragTarget> {\n /** The pointer's smoothed speed, px/ms. */\n readonly speed: number;\n /** The target under the pointer as the hysteresis holds it, or null. */\n readonly current: T | null;\n /** The target the indicator shows, or null. */\n readonly shown: T | null;\n /** The pointer has left the item's home. */\n readonly leftHome: boolean;\n}\n\nexport interface DragIntentOptions<T extends DragTarget> {\n /** Where the item was lifted from: the indicator stays off until the pointer leaves it, and a release there does nothing. */\n readonly home: Rect;\n /** Where the press that lifted the item was (the grip); default the first sample's point. The lift zone is about it. */\n readonly lift?: Point;\n /**\n * The lift zone as a rect instead of a radius, in the same px as the samples: while a sample is inside it no\n * spring-loaded target arms by dwell, and the `liftZone` radius is not applied. A host passes the part of the grip\n * that a drop strip covers (grip ∩ strip), so a pause back there commits nothing while the rest of the strip, right\n * beside a wide grip, still arms. Absent: the `liftZone` radius about `lift`.\n */\n readonly liftRect?: Rect;\n /**\n * The held item floats, and `home` is its own box. A floating item's own place is a free placement: it ranks like the\n * float target, so home holds only where the pick there, home ignored, is no refusal and the point lies inside the\n * window (no target's `bounds` left with nothing picked). Over a refusal in its box the frame is refused and a\n * release lands nowhere; on or past the window's edge nothing is picked; elsewhere in its box home holds as before.\n * Absent (a docked item): home holds wherever it lies, as its own home target beats a refusal.\n */\n readonly floating?: boolean;\n /**\n * What a release does before the item has settled on a target (no room open for it yet). `\"target\"` (the default): it\n * lands on the shown target, else the target under the pointer, drawn or not, an `opensRoom` target that hasn't shown\n * included. `\"float\"`: what shows is what lands, for a host whose dragged item is the only preview (`previewPlan`'s\n * `\"item\"`): the item is still on the pointer, so it floats there (the `free` target; over a refusal or outside the\n * float's `bounds`, nowhere). `release` is its one reader.\n */\n readonly earlyRelease?: \"target\" | \"float\";\n /** Overrides of {@link DRAG_DEFAULTS}. */\n readonly tuning?: Partial<DragTuning>;\n /**\n * The place within a target the pointer is at (a tab index, a stack\n * position, a pane's edge), unique across targets; default: the target's id.\n * Moving between places of the shown target moves the indicator at once but\n * the room only once the new place has held `roomAfter` ms.\n *\n * - `previous` is the place this target had on the last sample (null if it\n * had none), so a place can hold near its boundary (hysteresis).\n * - A null place is no target: there is no drop at that point of the target.\n * It isn't picked or held, the indicator hides there at once (or shows a\n * target beneath that has a place), no room opens, and a release there\n * lands on a target beneath, else goes home.\n * - It is also asked about the current target while the pointer is just\n * outside its hit zone (within the band, or during the gap grace). Answer\n * the nearest place there: returning null outside the zone drops the band\n * and the grace, so the indicator hides a few px past the edge. Return null\n * only for a part of the target that takes no drop.\n * - It is called on every sample for each target under the pointer and for\n * the current one, so keep it cheap and free of side effects.\n */\n readonly placeOf?: (target: T, point: Point, previous: string | null) => string | null;\n}\n\n/** A drag's intent: feed it the pointer on every frame; it says what the indicator shows and what a release lands on. */\nexport interface DragIntent<T extends DragTarget> {\n /**\n * A pointer sample at `time` (ms), with the targets as they stand (they may\n * be rebuilt between calls: the model follows them by id). Call it once a\n * frame while the item is held, also when the pointer doesn't move: a\n * dwell is time passing. `keys`: the modifier keys held now (see {@link DragModifiers}).\n */\n update(point: Point, time: number, targets: readonly T[], keys?: DragKeys): DragFrame<T>;\n /**\n * What a release at `point` lands on: the shown target whenever one shows\n * (a drop lands where the indicator was), else the target under the\n * pointer, else null (the item goes home). A release over home is null: it\n * does nothing. Feed the release point to `update` first, so a last jump\n * of the pointer counts. With a modifier key held (`keys`), the target the key picks, even over home.\n */\n release(point: Point, targets: readonly T[], keys?: DragKeys): T | null;\n /**\n * Hide the indicator (the view is scrolling under the pointer, say). The\n * aim starts afresh: the next sample never counts as aiming, and a dwell\n * starts again.\n */\n hide(time: number): void;\n /** The item's home moved with the view (it scrolled) by (dx, dy). */\n moveHome(dx: number, dy: number): void;\n readonly state: DragIntentState<T>;\n readonly tuning: DragTuning;\n}\n\n/**\n * The drag intent model: when the drop indicator shows, which target it\n * shows, when the others make room, and what a release lands on. Pure: fed\n * pointer samples and plain-data targets, no DOM and no clock of its own.\n *\n * - The indicator shows only when the pointer has left the item's home, a\n * target is under it, and it is aiming (slow, or nearly still for a\n * moment). Time spent crossing a big target at speed doesn't count.\n * - The most precise target wins (priority, then the smaller zone).\n * - Hysteresis: the current target holds while the pointer is within `band`\n * px of its zone, unless a more precise one is clearly (`breakthrough` px)\n * under the pointer; both scale down for small zones (`bandShare` of the\n * held zone's and the entered zone's extents along each axis), so a small\n * zone is entered by a direct glide; for a pointer that aims, a short gap between zones\n * (`gapGrace` ms) keeps it too.\n * - Leaving the shown target: flying, the indicator hides at once; aiming, it\n * moves to the new target once that has held `switchHold` ms (so no\n * indicator shows for less than that), at once for a breakthrough. A target\n * kept only by the gap grace can keep the indicator, never show it.\n * - Room is made once the shown target has held `roomAfter` ms, never for a\n * free target, and closes at once when it changes. A target with `opensRoom`\n * holds that long before it shows and has its room in the same frame; an\n * armed spring-loaded target has its room as it shows. With its room open,\n * one with a `roomHit` holds wherever the pointer is in that room, over a\n * refusal or a target no more precise than it under the room included.\n * - Where `placeOf` gives a target no place (null), it is no target: it is\n * neither shown nor landed on there.\n * - Spring-loading: a target marked `arm: \"dwell\"` is no target until the\n * pointer has stayed in its zone `railArmDwellMs` (the frame's `arming` says\n * which one it dwells on); then it is armed: its zone is `armedHit` (the\n * magnet) and it shows at once. Leaving that zone disarms it.\n * - Keys win over geometry (`modifiers`): the float key shows the `free` target\n * wherever the pointer is over a dock target or open space inside the float's\n * `bounds`, the rail key the nearest target marked `arm`; a release with the\n * key held lands there. Over a refusal, or outside the float's `bounds`, the\n * float key picks nothing: nothing shows and a release lands nowhere.\n */\nexport function createDragIntent<T extends DragTarget>(options: DragIntentOptions<T>): DragIntent<T> {\n const tuning: DragTuning = { ...DRAG_DEFAULTS, ...options.tuning };\n const placeOf = options.placeOf ?? ((t: T) => t.id);\n // Each target's place on the last sample, by id: its `previous` on the next.\n let lastPlaces = new Map<string, string | null>();\n let home: Rect = { ...options.home };\n let samples: { x: number; y: number; t: number }[] = [];\n let cur: T | null = null;\n let curSince = 0;\n let lastInside = 0;\n let shown: T | null = null;\n let shownSince = 0;\n let place: string | null = null;\n let placeSince = 0;\n let roomPlace: string | null = null;\n let leftHome = false;\n // The pointer has been outside `home` itself (`leftHome` turns on already near its edge): `atHome`'s own memory.\n let wentOut = false;\n let speed = 0;\n let anchor: Point | null = null;\n let stillSince = 0;\n let restart = false;\n // The pointer has been over a refusal since a target last showed (the frame's `refusedSinceShown`).\n let crossedRefusal = false;\n // Spring-loading: the target armed (by id), and the one the pointer dwells on and since when.\n let armedId: string | null = null;\n let armingId: string | null = null;\n let armingSince = 0;\n // The spring-loaded targets (by id) the pointer has been outside of during this drag: only those can arm.\n const wasOutside = new Set<string>();\n // The point the drag was lifted at: no spring-loaded target arms by dwell within `liftZone` of it.\n let liftAt: Point | null = options.lift ? { ...options.lift } : null;\n const same =(a: T | null, b: T | null): boolean => (a === null || b === null ? a === b : a.id === b.id);\n // Targets may be rebuilt between calls: follow the ones held by id.\n const follow = (t: T | null, targets: readonly T[]): T | null => (t ? (targets.find((x) => x.id === t.id) ?? t) : null);\n /** An armed target as it acts: its zone is `armedHit` (the magnet) when it has one. */\n const asArmed = (x: T): T => {\n if (!x.armedHit) return x;\n const { hits: _pieces, ...rest } = x;\n return { ...rest, hit: x.armedHit } as T;\n };\n /** The targets as they act now: a spring-loaded one only once armed, in its armed zone. */\n const acting = (targets: readonly T[]): T[] => targets.filter((x) => x.arm !== \"dwell\" || x.id === armedId).map((x) => (x.id === armedId ? asArmed(x) : x));\n /**\n * The target a held key picks at `p`: the float key the `free` target, the rail key the nearest spring-loaded one.\n * The float key chooses the float over dock targets, not over refusals or outside the window: where the pick at `p`\n * (`has`: a target with a place there, or a refusal) is a refusal, it picks nothing and says which refusal; outside\n * the float's `bounds` (a pointer clamped onto the window's edge) it picks nothing. The rail key's drop lands on the\n * rail, not where the pointer is, so neither applies to it.\n */\n const forcedBy = (keys: DragKeys | undefined, p: Point, targets: readonly T[], has: (x: T) => boolean): { kind: \"float\" | \"rail\"; target: T | null; refused: T | null } | null => {\n const m = tuning.modifiers;\n if (!m.on || !keys) return null;\n if (held(keys, m.floatKey)) {\n const f = targets.find((x) => x.free);\n if (!f) return null;\n const under = targetAt(acting(targets).filter((x) => inZone(x, p) && has(x)), p);\n if (under?.refuse === true) return { kind: \"float\", target: null, refused: under };\n return within(f.bounds, p) ? { kind: \"float\", target: f, refused: null } : { kind: \"float\", target: null, refused: null };\n }\n if (!held(keys, m.railKey)) return null;\n let best: T | null = null;\n let bestD = Infinity;\n for (const x of targets) {\n if (x.arm !== \"dwell\") continue;\n const d = distanceTo(asArmed(x).hit, p);\n if (d < bestD) {\n best = x;\n bestD = d;\n }\n }\n return best ? { kind: \"rail\", target: asArmed(best), refused: null } : null;\n };\n\n /** What a release at `point` lands on, as things stand now: `release`'s answer, and every frame's `landing`. */\n const landAt = (point: Point, given: readonly T[], keys: DragKeys | undefined): T | null => {\n // A key held wins over geometry, home included; the float key over a refusal or outside the window lands nowhere.\n const forced = forcedBy(keys, point, given, (x) => x.refuse === true || placeOf(x, point, lastPlaces.get(x.id) ?? null) !== null);\n if (forced) {\n const ft = forced.target;\n return ft ? (given.find((x) => x.id === ft.id) ?? ft) : null;\n }\n // Over home a release does nothing, except onto an armed spring-loaded target whose zone overlaps home.\n if (inRect(home, point)) {\n const armed = armedId === null ? null : given.find((x) => x.id === armedId);\n return armed && inZone(asArmed(armed), point) && placeOf(armed, point, lastPlaces.get(armed.id) ?? null) !== null ? armed : null;\n }\n const targets = acting(given);\n // Drop = shown: a shown target is kept until it hides (flying out past its band hides it at once).\n const s = shown && !(shown.arm === \"dwell\" && shown.id !== armedId) ? follow(shown, given) : null;\n // The target under the pointer that has a place there (a null place is no drop); a refusal there lands nowhere.\n const under = targetAt(\n targets.filter((x) => inZone(x, point) && (x.refuse === true || placeOf(x, point, lastPlaces.get(x.id) ?? null) !== null)),\n point,\n );\n if (options.earlyRelease === \"float\") {\n // What shows is what lands: a target with a slot only once its room is open; before that the item is still on\n // the pointer, so it floats there. A target with no slot (the item's own place, a blocked one) needs no room.\n const needsNoRoom = (x: T): boolean => x.free === true || !x.slot;\n if (s && (needsNoRoom(s) || roomPlace !== null)) return s;\n if (under?.refuse) return null;\n if (under && !under.free && !under.slot) return given.find((x) => x.id === under.id) ?? under;\n const float = given.find((x) => x.free);\n return float && within(float.bounds, point) ? float : null;\n }\n if (s) return s;\n return under && !under.refuse ? (given.find((x) => x.id === under.id) ?? under) : null;\n };\n\n return {\n tuning,\n get state(): DragIntentState<T> {\n return { speed, current: cur, shown, leftHome };\n },\n update(point, time, given, keys) {\n const p = point;\n const t = time;\n samples.push({ x: p.x, y: p.y, t });\n while (samples.length > 2 && t - samples[0]!.t > tuning.speedWindow) samples.shift();\n const a = samples[0]!;\n speed = speed * 0.5 + (Math.hypot(p.x - a.x, p.y - a.y) / Math.max(1, t - a.t)) * 0.5;\n if (!anchor || Math.hypot(p.x - anchor.x, p.y - anchor.y) > tuning.still) {\n anchor = { x: p.x, y: p.y };\n stillSince = t;\n }\n if (!inRect(home, p, -tuning.homeInset)) leftHome = true;\n const atHome = inRect(home, p);\n if (!atHome) wentOut = true;\n // Each target's place at this point, worked out once per sample; a null place is no target.\n const places = new Map<string, string | null>();\n const placeAt = (x: T): string | null => {\n if (!places.has(x.id)) places.set(x.id, placeOf(x, p, lastPlaces.get(x.id) ?? null));\n return places.get(x.id)!;\n };\n const live = (x: T | null): x is T => x !== null && placeAt(x) !== null;\n // Spring-loading: the armed target holds while the pointer is in its armed zone; a target the pointer dwells in\n // arms once it has held `railArmDwellMs`. A key held wins over both.\n const forced = forcedBy(keys, p, given, (x) => x.refuse === true || live(x));\n if (armedId !== null) {\n const was = given.find((x) => x.id === armedId);\n if (!was || forced || !inZone(asArmed(was), p) || !live(was)) armedId = null;\n }\n // Spring-loading is not gated by `atHome`: a strip that overlaps the item's own place still arms by dwell.\n // A spring-loaded target arms only after the pointer has entered it: one it has been outside of during the drag.\n for (const x of given) if (x.arm === \"dwell\" && !inZone(x, p)) wasOutside.add(x.id);\n // Inside the lift zone nothing arms by dwell (\"changed my mind\"); the rail key still forces the rail.\n // With a `liftRect` the zone is that rect, the radius not applied.\n liftAt ??= { x: p.x, y: p.y };\n const inLiftZone = options.liftRect ? inRect(options.liftRect, p) : Math.hypot(p.x - liftAt.x, p.y - liftAt.y) <= tuning.liftZone;\n const dwelling = forced || inLiftZone ? null : targetAt(given.filter((x) => x.arm === \"dwell\" && x.id !== armedId && wasOutside.has(x.id) && inZone(x, p) && live(x)), p);\n let armedNow = false;\n if (!dwelling || armedId !== null) armingId = null;\n else {\n if (armingId !== dwelling.id) {\n armingId = dwelling.id;\n armingSince = t;\n }\n if (t - armingSince >= tuning.railArmDwellMs) {\n armedId = dwelling.id;\n armingId = null;\n armedNow = true;\n }\n }\n const arming = armingId === null ? null : (given.find((x) => x.id === armingId) ?? null);\n const targets = acting(given);\n // A docked item's home holds wherever it lies (its own home target beats a refusal). A floating item's own place\n // is a free placement, ranked like the float: its home holds only where the pick there, home ignored, is no\n // refusal and not nothing outside a target's `bounds` (past the window). Elsewhere the pick is as anywhere else.\n const underHome = atHome && options.floating ? targetAt(targets.filter((x) => inZone(x, p) && (x.refuse === true || live(x))), p) : null;\n const pastBounds = atHome && options.floating ? targets.some((x) => x.bounds !== undefined && !within(x.bounds, p)) : false;\n const homeHolds = atHome && (!options.floating || (underHome?.refuse !== true && !(underHome === null && pastBounds)));\n // Over home no target is picked, except a spring-loaded one that is armed (its zone overlaps home): home gates\n // geometry, not an armed dwell.\n const pickable = (x: T): boolean => !homeHolds || (x.arm === \"dwell\" && x.id === armedId);\n // A refusal takes part in the pick (it needs no place), but it is never a target: never held, never shown.\n const raw = targetAt(targets.filter((x) => pickable(x) && inZone(x, p) && (x.refuse === true || live(x))), p);\n // A spring-loaded target that isn't armed (any more) is no target: neither held nor shown.\n const disarmed = (x: T | null): boolean => x?.arm === \"dwell\" && x.id !== armedId;\n cur = disarmed(cur) ? null : follow(cur, targets);\n shown = disarmed(shown) ? null : follow(shown, targets);\n if (!live(cur)) cur = null;\n // A target shown with its room open holds in the room it opened (`roomHit`): what lies there is drawn as the room,\n // so a refusal under it is no refusal here.\n const roomHeld = cur && cur.opensRoom === true && cur.roomHit && roomPlace !== null && same(cur, shown) && pickable(cur) && within(cur.bounds, p) && inRect(cur.roomHit, p) ? cur : null;\n const refusedRaw = raw?.refuse === true && !roomHeld ? raw : null;\n // The band about a held zone, and the breakthrough into a zone, scaled with the zones (see `bandShare`).\n const bandOf = (held: T): Margin => scaled(tuning.band, tuning.bandShare, [held, raw && !same(raw, held) ? raw : null]);\n const pastBreakthrough = (x: T): boolean => inZoneBy(x, p, negate(scaled(tuning.breakthrough, tuning.bandShare, [x])));\n // Over a refusal nothing is held: no band and no gap grace keep the current target there.\n let next = refusedRaw ? null : raw;\n if (!refusedRaw && cur && pickable(cur) && (roomHeld !== null || inZoneBy(cur, p, bandOf(cur)))) {\n // Over a `free` target (the float everywhere) there is no edge to hold against: a more precise target takes over\n // once the pointer is in it, so a zone that ends at the window's edge is reached at its very first px. A refusal\n // here lies under the open room: it never takes over.\n const breaks = raw !== null && raw.refuse !== true && !same(raw, cur) && raw.priority < cur.priority && (cur.free === true || pastBreakthrough(raw));\n next = breaks ? raw : cur;\n }\n // The gap grace, like the band, never reaches past a zone's bounds: the float gets no grace outside the window.\n if (!refusedRaw && !next && cur && pickable(cur) && within(cur.bounds, p) && t - lastInside < tuning.gapGrace) next = cur;\n if (next && (inZone(next, p) || same(next, roomHeld))) lastInside = t;\n if (!same(next, cur)) curSince = t;\n cur = next;\n const aiming = !restart && (speed < tuning.aimSpeed || t - stillSince >= tuning.dwell);\n restart = false;\n const show = (s: T | null): void => {\n if (!same(s, shown)) shownSince = t;\n shown = s;\n };\n // Under the pointer (within its band, or in the room it holds), not just kept by the gap grace.\n const under = !!cur && (same(cur, roomHeld) || inZoneBy(cur, p, bandOf(cur)));\n // A target that opens its room as it shows shows only once it has held (`roomHold`, else `roomAfter`): one decision\n // for both, so a sweep moves nothing and the indicator never lies over what the room will move. An armed one has\n // had its dwell.\n const ready = (x: T): boolean => x.opensRoom !== true || x.arm === \"dwell\" || t - curSince >= (x.roomHold ?? tuning.roomAfter);\n // A shown target with no place here is no drop: the indicator hides at once (the switch hold is for targets).\n if (shown && !live(shown)) show(null);\n if (!shown) {\n if (cur && under && leftHome && aiming && ready(cur)) show(cur);\n } else if (same(cur, shown)) {\n // It stays while its target holds; but a pointer flying out past the band hides it at once.\n if (!aiming && !under) show(null);\n else shown = cur;\n } else if (!cur || !aiming) {\n show(null);\n } else if ((cur.priority < shown.priority && (shown.free === true || pastBreakthrough(cur))) || (under && t - curSince >= tuning.switchHold)) {\n // Not ready yet: the old indicator goes, and a release lands on the target under the pointer.\n show(ready(cur) ? cur : null);\n }\n // An armed target shows at once: the dwell was the aim. A key held wins over all of it.\n if (armedNow && cur?.id === armedId && under) show(cur);\n // A key that picks nothing here (the float key over a refusal or outside the window) shows nothing.\n if (forced) {\n if (!same(forced.target, cur)) curSince = t;\n cur = forced.target;\n show(forced.target);\n }\n // The place within the shown target, and the room: after the target and the place have both held; with the target\n // itself where showing it was already that decision (`opensRoom`, an armed target's dwell).\n const at = shown ? placeAt(shown) : null;\n if (at !== place) {\n place = at;\n placeSince = t;\n }\n if (!shown || shown.free) roomPlace = null;\n else if (shown.opensRoom === true || shown.arm === \"dwell\") roomPlace = place;\n else if (t - shownSince >= tuning.roomAfter && t - placeSince >= tuning.roomAfter) roomPlace = place;\n else if (shownSince === t) roomPlace = null;\n lastPlaces = places;\n // A refusal crossed since a target last showed: a release beyond it lands on what is under the pointer, drawn or not.\n // With a key held, the refusal is the one the key's pick met (the float key over a refusal), else none.\n const refused = forced ? forced.refused : refusedRaw;\n if (shown) crossedRefusal = false;\n else if (refused) crossedRefusal = true;\n return { shown, room: roomPlace !== null, roomPlace, aiming, atHome: !forced && wentOut && homeHolds, arming, forced: forced?.kind ?? null, refused, refusedSinceShown: !shown && !refused && crossedRefusal, landing: landAt(p, given, keys) };\n },\n release(point, given, keys) {\n return landAt(point, given, keys);\n },\n hide(time) {\n shown = null;\n cur = null;\n armedId = null;\n armingId = null;\n shownSince = time;\n place = null;\n roomPlace = null;\n lastPlaces = new Map();\n samples = [];\n anchor = null;\n restart = true;\n crossedRefusal = false;\n },\n moveHome(dx, dy) {\n home = { ...home, x: home.x + dx, y: home.y + dy };\n },\n };\n}\n","import type { Point, Rect } from \"../shapes\";\nimport type { DragKeys } from \"./intent\";\nimport type { PlaceGuides } from \"./preview\";\n\n/**\n * The landing model: where a docking drag's item lands, as state rather than a per-frame guess. A host gives it the\n * drag's regions (from `@n-uf/placement/scene`'s `lanes()`: plain data, the shapes below) and each pointer sample; it\n * says the region the pointer is in, the lane and spot held, where the item lands, whether the room is open, and the\n * place guides. Every change comes from where the pointer is and how it moved (margins, a path length, a step size):\n * the model has no waits of its own.\n *\n * - **The stage's edge** is the easiest place to dock: a pointer past the stage by up to `edge` px counts as on its\n * edge, so it lies deep inside a lane drawn against that edge; beyond, it is nowhere.\n * - **A lane holds** while the pointer is inside its rect grown by `exit`, whatever lies under it. Inside, over a spot's\n * stretch it is at that spot; over a refused stretch of the lane, refused (\"Can't go here\"). (Placement's `lanes()`\n * joins a refused stretch shorter than the item to its spots.)\n * - **Entering a lane** needs one of two gates: `path` px of slow pointer path along it inside it (steps of at most\n * `step`), or a still step (at most `still`) once `depth` px inside, the depth counted only from the lane's sides that\n * 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\n * room never opens. Inside a lane that touches the held one, past the held lane's exit margin, the held lane holds\n * 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\n * far): lane to lane never passes through the float, and never opens a crossed lane's room. Over a refused place (a\n * lane's band lying over a column that takes nothing: an empty side rail's) a lane is entered on the first slow step\n * there (not on the lift), as there is nothing else to mean there; a fly-through still opens no room. A lane that owns\n * its rect (`owns`: a rail drop strip at the window's side) takes the pointer inside it from any lane it overlaps, a\n * held one too, once its own gate passes and only once the pointer came into it from outside since the lift. Within\n * `margins.lift` of the lift point (`options.lift`, else the first point; fixed for the drag) an owning lane takes the\n * pointer by no gate, so a pointer brought back there is in the item's own lane, not the strip. Elsewhere in the strip\n * a slow slide along it can take the pointer before it is back at the lift point. More generally, within\n * `margins.lift` of the lift point the lane is the item's own (`home.lane`) whenever the pointer lies in it, whatever\n * lane the pointer came through (a plain lane's band over the home lane's corner included), and its spot is the\n * item's own (`home.spot`; a sliding one still lets the landing follow the hand and snap): away and back to where the\n * item was lifted is home on every layout, so no nudge to a neighboring spot is reachable within `lift` of the press.\n * The zone is a held state like a held lane: the drag starts in it, leaves it past `lift` and re-enters only within\n * `lift - spot`, so a wobble at its edge never flips a cut near the press.\n * - **Along a lane** the spot changes once the pointer is `spot` px past the boundary; where the change moves another\n * item (the two spots' `others` keys differ), on a step of at most `step`, or once the held landing trails the\n * pointer by more than `trail`: the item chases only as far as it must. A change that moves only the held item\n * follows the hand at any speed. With `regionsFor`, a reflowing change is kept only if, in the new spot's own regions\n * (its room open), the pointer still lies in that spot's stretch: the room shifting the boundary never bounces it.\n * - **A sliding spot** (`slide`: a free stretch as one spot) lands where the hand is: its landing moved along the lane to\n * the pointer less the grab (`grab`), clamped to its range, and snapped to its ends, the item's own place or a dock\n * inside within `snapDistance`. Nothing reflows inside it, so there are no steps there; a step comes only where the\n * order changes (passing a neighbor), as between any two spots. A release reads where it starts (`at`) once.\n * - **Outside every lane:** a refused place, refused; open space (`\"open\"`: the content less what blocks it, the page),\n * the float at its landing; outside the stage (past `edge`), nowhere; else (docked content that takes nothing and\n * refuses nothing) refused.\n * - **Shift** turns a lane or open space into open space (the float), and hides the guides.\n * - **Guides** are the lane's `marks` (lines between items, a box per free stretch, in the layout as drawn), else its\n * spots' landings: the held lane's; else the approached lane's (the nearest within `reach`); over a refused place the\n * nearest lane's at any distance, so the lane behind a refused column shows its guides.\n * - Steps are measured between points that differ, normalized to 125 Hz, so the gates read the same at any input rate.\n * A repeated point keeps the last step; it is still only once the pointer has stayed put for `rest` ms.\n *\n * **The host's part:** call `update` whenever you like: per pointer sample, per animation frame, or both. Call it at\n * least once more after the pointer stops (every frame does), so it can become still, and again with the same point\n * when a key changes. Give `setRegions` the `regionsFor` that answers for the new state.\n */\n\n/** A place a drop in a lane lands: its stretch of the lane and its landing rect. Ids are stable across solves. */\nexport interface LandingSpot {\n readonly id: string;\n readonly along: readonly [number, number];\n readonly landing: Rect;\n /**\n * Where its drop draws every other item, as a key: a change between two spots with the same key moves only the held\n * item. Absent: every change to or from it counts as moving others.\n */\n readonly others?: string;\n /**\n * A sliding spot (a free stretch exposed as one spot): over it the landing follows the pointer, `landing` moved along\n * the lane to the pointer less the grab, clamped to `[from, to]` and snapped to a point of `snaps` within\n * `snapDistance`, else on whole pixels (`step`). Absent: the landing is `landing`.\n */\n readonly slide?: LandingSlide;\n}\n/** A sliding spot's range: where its landing's start may lie along the lane, and the points it snaps to. */\nexport interface LandingSlide {\n /** The landing's start at the stretch's start (flush against the neighbor before it), px along the lane. */\n readonly from: number;\n /** The landing's start at the stretch's end (flush against the neighbor after it), px along the lane. */\n readonly to: number;\n /** The starts it snaps to: its two ends, the item's own place where it lies here, any discrete dock inside. */\n readonly snaps: readonly number[];\n /** How near a snap point the landing's start snaps to it, px (default `SNAP_DISTANCE`). */\n readonly snapDistance?: number;\n /**\n * The grain of a start that snaps to nothing, px: a multiple of `step`, clamped to `[from, to]` (default 1, whole\n * pixels; 0: wherever the pointer puts it). Give the step the spot's commit uses, so the frame, the release's `at`\n * and the commit agree.\n */\n readonly step?: number;\n}\n/** The grain of a sliding spot's free start, px, when it names none: whole pixels. */\nconst SLIDE_STEP = 1;\n/** How near a sliding spot's snap point its landing snaps to it, px. */\nexport const SNAP_DISTANCE = 8;\n/**\n * A place guide's mark, in the layout as drawn: a line between two items that touch, a box over free room the item\n * lands in, a hatch over the part of a neighbor that gives way where the room is shorter than the item.\n */\nexport interface LandingMark {\n /** Stable while its neighbors stay; absent, the guide is keyed by its lane and place in the list. */\n readonly id?: string;\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n}\nexport interface LandingLane {\n readonly id: string;\n readonly rect: Rect;\n readonly axis: \"x\" | \"y\";\n readonly spots: readonly LandingSpot[];\n readonly refused: readonly { readonly along: readonly [number, number] }[];\n /** Its guides' marks; absent, its spots' landings are the guides. */\n readonly marks?: readonly LandingMark[];\n /**\n * Its rect is its own (a rail drop strip at the window's side): inside it, once its gate passes, it takes the pointer\n * from any lane it overlaps, a held one too. Absent: where lanes overlap, the deeper one wins.\n */\n readonly owns?: boolean;\n}\n/** A drag's regions (`lanes()` gives them). */\nexport interface LandingRegions {\n readonly lanes: readonly LandingLane[];\n readonly refused: readonly Rect[];\n readonly content: Rect;\n readonly blocked: readonly Rect[];\n readonly stage: Rect;\n /** The held item's size. */\n readonly item: { readonly width: number; readonly height: number };\n}\n\nexport interface LandingMargins {\n /** Past a held lane's rect before it lets go, px. */\n readonly exit: number;\n /** Past a spot boundary before the spot changes, px. */\n readonly spot: number;\n /** Past the stage that still counts as on its edge, px; beyond, nowhere. */\n readonly edge: number;\n /**\n * Around the lift point, px (16, as the drag intent's `liftZone`): an owning lane never takes the pointer there, so\n * away and back to where the item was lifted is home.\n */\n readonly lift?: number;\n}\nexport interface LandingGates {\n /** Pointer path inside a lane that enters it, px. */\n readonly path: number;\n /** Depth inside a lane where a still step enters it, px. */\n readonly depth: number;\n /** A still step, px per 8 ms. */\n readonly still: number;\n /**\n * The largest step that changes the spot along a lane where the change reflows the window, px per 8 ms; it also\n * bounds the steps the path gate counts (a fast crossing never enters).\n */\n readonly step: number;\n /** How far the held landing may trail the pointer before a fast reflowing change is taken anyway, px. */\n readonly trail: number;\n /**\n * The time a pointer has to stay put before it counts as still, ms, where its last step was already slow (at most\n * `step`) or it is on the stage's edge (a fling there is taken at once); repeated points before it aren't still.\n */\n readonly rest: number;\n /** The time a pointer that last moved fast has to stay put before it counts as still, ms: longer than sample gaps. */\n readonly pause: number;\n}\n/** The approach for near guides: the nearest lane within `reach`, kept until another is `nearer` closer or past `keep`. */\nexport interface LandingApproach {\n readonly reach: number;\n readonly keep: number;\n readonly nearer: number;\n}\n\nexport const LANDING_MARGINS: LandingMargins = { exit: 12, spot: 6, edge: 48, lift: 16 };\n/** A touch: wider margins, the finger's jitter. */\nexport const LANDING_TOUCH_MARGINS: LandingMargins = { exit: 16, spot: 8, edge: 48, lift: 16 };\nexport const LANDING_GATES: LandingGates = { path: 40, depth: 8, still: 1.5, step: 3, trail: 40, rest: 22, pause: 60 };\nexport const LANDING_APPROACH: LandingApproach = { reach: 80, keep: 96, nearer: 16 };\n\nexport interface LandingOptions {\n readonly regions: LandingRegions;\n /** The regions with `spot` held (its room open): the fixed-point check and the stretches while held. Cached per id. */\n readonly regionsFor?: (spot: string) => LandingRegions | null;\n /** The float's landing for a pointer over the document, or null where the item doesn't float. */\n readonly floatLanding?: (point: Point) => Rect | null;\n /** The item's own place at the lift: its lane and spot (the drag starts there, the room open). */\n readonly home?: { readonly lane: string; readonly spot: string };\n /** Where the item was lifted (the press), in the regions' space; default the first point `update` gets. */\n readonly lift?: Point;\n /**\n * Where the pointer holds the item, from its top left corner as it is now, px (the press's, as `lanes()` takes it).\n * Over a sliding spot the landing's start is the pointer less this, along the item's own length (its longer side; a\n * landing of another length at the same share of it); across it, and in a lane across its length, the middle.\n * Default: the middle of `regions.item`.\n */\n readonly grab?: Point;\n readonly margins?: Partial<LandingMargins>;\n readonly gates?: Partial<LandingGates>;\n readonly approach?: Partial<LandingApproach>;\n readonly placeGuides?: PlaceGuides;\n}\n\nexport type LandingRegion = \"lane\" | \"open\" | \"refused\" | \"nowhere\";\n\n/** A guide: a mark of a lane, where to draw it now (a spot's landing is a box). */\nexport interface LandingGuide {\n /** Stable while its neighbors stay: the mark's id, else `<lane>/<spot id>` for a spot's landing. Key a drawing by it. */\n readonly id: string;\n readonly lane: string;\n /** A line, a box, or a hatch over a neighbor that gives way (draw it over that item, in the guides' color). */\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n}\n\nexport interface LandingFrame {\n readonly region: LandingRegion;\n /** The lane held (also over its refused stretch), or null. */\n readonly lane: string | null;\n /** The spot held, or null. */\n readonly spot: string | null;\n /** Where a release now lands: the spot's landing, or the float's; null where it lands nowhere (the item goes home). */\n readonly landing: Rect | null;\n /** The room is open: a spot is held in a lane, no Shift. */\n readonly room: boolean;\n readonly guides: readonly LandingGuide[];\n /** Shift held: the region is open space wherever it was a lane or open space. */\n readonly shift: boolean;\n /**\n * The lane the pointer is inside but hasn't entered (its gate not passed yet: a fast pass, or the moment before a slow\n * step), else absent. A host shows no \"Can't go here\" while it is set, though a release now lands nowhere: the place\n * under the pointer is a lane's, not a refused one.\n */\n readonly pending?: string;\n}\n\n/**\n * What a release lands: a spot (`home` when it is the item's own place), the float at `rect`, or nothing. On a sliding\n * spot, `at` is where the landing starts along the lane, as the frame shows it (read once, at the release: a snap\n * point, else on the spot's `step`), and `home` holds only where that is the item's own place.\n */\nexport type LandingRelease =\n | { readonly kind: \"spot\"; readonly lane: string; readonly spot: string; readonly home: boolean; readonly at?: number }\n | { readonly kind: \"float\"; readonly rect: Rect }\n | null;\n\nexport interface LandingModel {\n update(point: Point, time: number, keys?: DragKeys): LandingFrame;\n /** What a release lands, by the last frame: the same answer as its `landing`. */\n release(): LandingRelease;\n /**\n * The regions changed (a resize, a store change, a scroll): spots map by id; a lost one goes to its lane's nearest.\n * Pass the `regionsFor` that answers for the new state; without one, the old one stays (it must then read live state).\n */\n setRegions(regions: LandingRegions, regionsFor?: (spot: string) => LandingRegions | null): void;\n /** The view moved under the pointer: the gates start again, the lane is let go. */\n hide(): void;\n readonly frame: LandingFrame;\n}\n\nconst inside = (r: Rect, p: Point, grow = 0): boolean => p.x >= r.x - grow && p.x <= r.x + r.width + grow && p.y >= r.y - grow && p.y <= r.y + r.height + grow;\nconst strictlyIn = (r: Rect, p: Point): boolean => p.x >= r.x && p.x <= r.x + r.width && p.y >= r.y && p.y <= r.y + r.height;\n/**\n * How deep `p` lies inside `r` (0 on its edge or outside), counted only from the sides of `r` that face into `stage`: a\n * side on the stage's edge is open, as deep as the pointer can go.\n */\nfunction depthIn(r: Rect, p: Point, stage: Rect): number {\n if (!strictlyIn(r, p)) return 0;\n const on = (a: number, b: number): boolean => Math.abs(a - b) < 1;\n const sides = [\n on(r.x, stage.x) ? Infinity : p.x - r.x,\n on(r.x + r.width, stage.x + stage.width) ? Infinity : r.x + r.width - p.x,\n on(r.y, stage.y) ? Infinity : p.y - r.y,\n on(r.y + r.height, stage.y + stage.height) ? Infinity : r.y + r.height - p.y,\n ];\n return Math.max(0, Math.min(...sides));\n}\nconst distanceTo = (r: Rect, p: Point): number => 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)));\nconst alongOf = (lane: LandingLane, p: Point): number => (lane.axis === \"x\" ? p.x : p.y);\nconst acrossOf = (lane: LandingLane, p: Point): number => (lane.axis === \"x\" ? p.y : p.x);\n/** Two rects meet: they overlap or touch (within 1 px), corners included. */\nconst touches = (a: Rect, b: Rect): boolean => a.x <= b.x + b.width + 1 && b.x <= a.x + a.width + 1 && a.y <= b.y + b.height + 1 && b.y <= a.y + a.height + 1;\n/** `p` onto `stage` when it lies past it by at most `reach`; else null (nowhere). */\nfunction ontoStage(stage: Rect, p: Point, reach: number): Point | null {\n if (!inside(stage, p, reach)) return null;\n return { x: Math.min(Math.max(p.x, stage.x), stage.x + stage.width), y: Math.min(Math.max(p.y, stage.y), stage.y + stage.height) };\n}\n\nexport function createLandingModel(options: LandingOptions): LandingModel {\n const margins = { ...LANDING_MARGINS, ...options.margins };\n const gates = { ...LANDING_GATES, ...options.gates };\n const approach = { ...LANDING_APPROACH, ...options.approach };\n const guidesLevel: PlaceGuides = options.placeGuides ?? \"off\";\n let base = options.regions;\n let regionsFor = options.regionsFor;\n const cache = new Map<string, LandingRegions | null>();\n /** The regions with `spot` held: the host's, cached for this lift until `setRegions`. */\n const heldRegions = (spot: string | null): LandingRegions => {\n if (!spot || !regionsFor) return base;\n if (!cache.has(spot)) cache.set(spot, regionsFor(spot));\n return cache.get(spot) ?? base;\n };\n\n let laneId: string | null = options.home?.lane ?? null;\n let spotId: string | null = options.home?.spot ?? null;\n let last: { p: Point; raw: Point; t: number } | null = null;\n /** The last point that differed from the one before, and the step then. */\n let moved: { raw: Point; t: number } | null = null;\n /** Where the item was lifted (`lift`, else the first point), fixed for the drag: back there, no owning lane takes it. */\n let liftAt: Point | null = options.lift ?? null;\n /** Whether the pointer is held in the lift zone (`nearLift`). */\n let inLiftZone = true;\n let lastStep = 0;\n /** Path inside each lane since the pointer last entered its rect. */\n const pathIn = new Map<string, number>();\n /** The path along and across each lane at any speed since the pointer entered it (a touching lane's takeover). */\n const slide = new Map<string, { along: number; across: number }>();\n /** The owning lanes the pointer has been outside since the lift: only those may take it (it came into them). */\n const cameIn = new Set<string>();\n let approached: string | null = null;\n let previous: LandingRegion = laneId ? \"lane\" : \"open\";\n let frame: LandingFrame = { region: previous, lane: laneId, spot: spotId, landing: null, room: !!spotId, guides: [], shift: false };\n /** The spot the last frame lands on (in its own regions) and its lane's axis, or null. */\n let landedOn: { readonly spot: LandingSpot; readonly axis: \"x\" | \"y\" } | null = null;\n\n const laneIn = (regions: LandingRegions, id: string | null): LandingLane | undefined => (id ? regions.lanes.find((l) => l.id === id) : undefined);\n const spotIn = (lane: LandingLane | undefined, id: string | null): LandingSpot | undefined => (lane && id ? lane.spots.find((s) => s.id === id) : undefined);\n\n /** The spot a point along `lane` picks: the spot whose stretch holds it, null over a refused stretch, else the nearest. */\n function pick(lane: LandingLane, a: number): LandingSpot | null {\n if (lane.refused.some((r) => a >= r.along[0] && a <= r.along[1])) return null;\n const hit = lane.spots.find((s) => a >= s.along[0] && a <= s.along[1]);\n if (hit) return hit;\n let best: LandingSpot | null = null;\n let dist = Infinity;\n for (const s of lane.spots) {\n const d = a < s.along[0] ? s.along[0] - a : a - s.along[1];\n if (d < dist) {\n best = s;\n dist = d;\n }\n }\n return best;\n }\n\n /**\n * Where `spot` lands for a pointer at `p` in `lane`: its landing, or on a sliding spot that landing moved along the lane\n * to the pointer less the grab, clamped to its range and snapped to the nearest snap point within its snap distance.\n */\n function landingAt(lane: LandingLane, spot: LandingSpot, p: Point, item: { readonly width: number; readonly height: number }): Rect {\n const s = spot.slide;\n if (!s) return spot.landing;\n const ax = lane.axis;\n // The grab's share along the item's own length (its longer side); across it, or a lane across its length, the middle.\n const long: \"x\" | \"y\" = item.width >= item.height ? \"x\" : \"y\";\n const size = long === \"x\" ? item.width : item.height;\n const g = options.grab ? (long === \"x\" ? options.grab.x : options.grab.y) : size / 2;\n const share = ax === long && size > 0 && Number.isFinite(g) ? Math.min(1, Math.max(0, g / size)) : 0.5;\n const length = ax === \"x\" ? spot.landing.width : spot.landing.height;\n const lo = Math.min(s.from, s.to);\n const hi = Math.max(s.from, s.to);\n const free = Math.min(hi, Math.max(lo, alongOf(lane, p) - share * length));\n const reach = s.snapDistance ?? SNAP_DISTANCE;\n let at = free;\n let best = Infinity;\n for (const q of s.snaps) {\n const d = Math.abs(q - free);\n if (d <= reach && d < best) {\n best = d;\n at = q;\n }\n }\n // Snapped to nothing: the spot's grain (`LandingSlide.step`), the same rounding its commit applies.\n const step = s.step ?? SLIDE_STEP;\n if (best === Infinity && step > 0) at = Math.min(hi, Math.max(lo, Math.round(free / step) * step));\n return ax === \"x\" ? { ...spot.landing, x: at } : { ...spot.landing, y: at };\n }\n\n /** Along a held lane: the spot after hysteresis, the step gate and the fixed-point check. */\n function along(lane: LandingLane, p: Point, step: number): LandingSpot | null {\n const regions = heldRegions(spotId);\n const held = laneIn(regions, lane.id) ?? lane;\n const a = alongOf(held, p);\n const now = spotIn(held, spotId);\n const cand = pick(held, a);\n if (!cand) return null;\n if (!now || cand.id === now.id) return cand;\n // Past the boundary by the margin, the same everywhere (a wobble within it never flips the spot); where the change\n // moves another item, on a slow enough step. Else the last spot holds.\n const past = a < now.along[0] - margins.spot || a > now.along[1] + margins.spot;\n const reflows = now.others === undefined || now.others !== cand.others;\n if (!past) return now;\n // A fast reflowing change waits for a slow step, unless the held landing already trails the pointer by `trail`: the\n // item chases only as far as it must, so a fast hand across docked items never leaves it far behind.\n if (reflows && step > gates.step && distanceTo(now.landing, p) <= gates.trail) return now;\n // The fixed point: in the candidate's own regions (its room open), the pointer still picks it.\n if (regionsFor && reflows) {\n const theirs = heldRegions(cand.id);\n const lane2 = laneIn(theirs, lane.id);\n if (lane2 && pick(lane2, alongOf(lane2, p))?.id !== cand.id) return now;\n }\n return cand;\n }\n\n function guidesFor(p: Point, region: LandingRegion, shift: boolean): LandingGuide[] {\n if (guidesLevel === \"off\" || shift) return [];\n const regions = heldRegions(spotId);\n const all = (l: LandingLane): LandingGuide[] =>\n l.marks\n ? l.marks.map((m, i) => ({ id: m.id ?? `${l.id}#${i}`, lane: l.id, kind: m.kind, rect: m.rect }))\n : l.spots.map((s) => ({ id: `${l.id}/${s.id}`, lane: l.id, kind: \"box\" as const, rect: s.landing }));\n if (guidesLevel === \"all\") return regions.lanes.flatMap(all);\n if ((region === \"lane\" || region === \"refused\") && laneId) {\n approached = laneId;\n const l = laneIn(regions, laneId);\n return l ? all(l) : [];\n }\n let best: LandingLane | null = null;\n let bestD = Infinity;\n for (const l of regions.lanes) {\n const d = distanceTo(l.rect, p);\n if (d < bestD) {\n best = l;\n bestD = d;\n }\n }\n // Over a refused place: the nearest lane at any distance (the lane behind a refused column).\n if (region === \"refused\") {\n approached = best?.id ?? null;\n return best ? all(best) : [];\n }\n // The approached lane: the nearest within reach, kept until another is clearly nearer or it is past `keep`.\n const kept = laneIn(regions, approached);\n if (kept) {\n const d = distanceTo(kept.rect, p);\n if (d > approach.keep) approached = null;\n else if (best && best.id !== kept.id && bestD + approach.nearer < d) approached = bestD <= approach.reach ? best.id : null;\n } else approached = best && bestD <= approach.reach ? best.id : null;\n const l = laneIn(regions, approached);\n return l ? all(l) : [];\n }\n\n function update(raw: Point, t: number, keys?: DragKeys): LandingFrame {\n // Past the stage by up to `edge`: on its edge. Beyond: nowhere (kept as is).\n const p = ontoStage(heldRegions(spotId).stage, raw, margins.edge) ?? raw;\n // The step: the pointer as it moved (a fling past the edge isn't still) since the last point that differed,\n // normalized to 125 Hz (8 ms). A repeated point (a host updating per frame, or a gap between sparse samples) keeps\n // the last step until the pointer has stayed put for `rest` ms after a slow step or on the stage's edge, else for\n // `pause` ms; only then is it still. A hand moving fast with samples far apart is never still between them.\n let step = 0;\n if (moved && (raw.x !== moved.raw.x || raw.y !== moved.raw.y)) {\n step = (Math.hypot(raw.x - moved.raw.x, raw.y - moved.raw.y) * 8) / Math.max(1, t - moved.t);\n moved = { raw, t };\n lastStep = step;\n } else if (moved) {\n const stage = heldRegions(spotId).stage;\n const onEdge = p.x <= stage.x || p.y <= stage.y || p.x >= stage.x + stage.width || p.y >= stage.y + stage.height;\n const since = t - moved.t;\n step = since >= gates.pause || (since >= gates.rest && (lastStep <= gates.step || onEdge)) ? 0 : lastStep;\n } else {\n // The first point: how the pointer moves is unknown, never still (a lift over a lane's band doesn't enter it).\n moved = { raw, t };\n // (After `hide()` too, the lift point stays where the drag began.)\n liftAt ??= p;\n step = lastStep = Infinity;\n }\n const from = last?.p ?? null;\n // The pointer as it moved: a fling off the stage's edge moves across a lane there though its clamped point doesn't.\n const fromRaw = last?.raw ?? null;\n last = { p, raw, t };\n const shift = !!keys?.shift;\n const regions = heldRegions(spotId);\n // The path inside each lane: the part along the lane of slow steps from a point inside it to another (the step that\n // enters doesn't count, nor a fast one), so a crossing at `step` speed or faster never enters by path at any angle.\n // From a held lane, a touching lane counts the path along it and across it at any speed: a fast slide along it\n // (across it at most a third as far as along) is no crossing.\n const slow = step <= gates.step;\n for (const l of regions.lanes) {\n const was = from && strictlyIn(l.rect, from);\n const go = was ? Math.abs(alongOf(l, p) - alongOf(l, from)) : 0;\n const over = was && fromRaw ? Math.abs(acrossOf(l, raw) - acrossOf(l, fromRaw)) : 0;\n const inL = strictlyIn(l.rect, p);\n pathIn.set(l.id, inL ? (pathIn.get(l.id) ?? 0) + (slow ? go : 0) : 0);\n const s = slide.get(l.id);\n slide.set(l.id, inL ? { along: (s?.along ?? 0) + go, across: (s?.across ?? 0) + over } : { along: 0, across: 0 });\n if (l.owns && !inL) cameIn.add(l.id);\n }\n\n let region: LandingRegion;\n let pending: string | null = null;\n if (!inside(regions.stage, p)) {\n // Outside the stage: nowhere, and the lane is let go.\n region = \"nowhere\";\n laneId = spotId = null;\n } else {\n const held = laneIn(regions, laneId);\n const gate = (l: LandingLane): boolean => (pathIn.get(l.id) ?? 0) >= gates.path || (depthIn(l.rect, p, regions.stage) >= gates.depth && step <= gates.still);\n // Lane to lane: inside a lane touching the held one, past the held lane's exit margin (inside it the held lane holds,\n // P1), the held lane still holds until that lane's gate passes, then that lane takes it. Never the float between\n // them, never a fly-through's room.\n 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)) : undefined;\n const sl = touching ? slide.get(touching.id) : undefined;\n const slid = !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along;\n // A lane that owns its rect (a rail drop strip) takes the pointer inside it from any lane it overlaps, a held one\n // too, once its own gate passes (so a pass across it opens nothing), and only once the pointer came into it (it has\n // been outside it since the lift): a press in a column's outer edge, or a slow reorder along it, stays in the column.\n // Never within `lift` of where the item was lifted: away and back there is home, wherever a strip lies, while the\n // rest of the strip (all of it over a lone panel's own place) still takes it.\n // The zone is a held state, like a held lane: the drag starts in it, leaves it past `lift` of the lift point and\n // re-enters it only within `lift - spot`, so a wobble at its edge never flips a cut that lies near the press.\n const liftR = margins.lift ?? 16;\n if (liftAt) {\n const far = Math.hypot(p.x - liftAt.x, p.y - liftAt.y);\n inLiftZone = far <= (inLiftZone ? liftR : Math.max(0, liftR - margins.spot));\n }\n const nearLift = !!liftAt && inLiftZone;\n const owner = nearLift ? undefined : regions.lanes.find((l) => l.owns && l.id !== held?.id && cameIn.has(l.id) && strictlyIn(l.rect, p) && gate(l));\n // The lift zone is the item's own lane's: within `lift` of where it was lifted, in whatever lane the pointer came\n // through, the lane choice is the home lane (when the pointer lies in it, as the lift point did), and its spot the\n // item's own. So away and back to the lift point is home on every layout, a plain lane's band lying over the home\n // lane's corner included.\n const ownLane = nearLift && options.home ? laneIn(regions, options.home.lane) : undefined;\n const homeHere = ownLane && strictlyIn(ownLane.rect, p) ? ownLane : undefined;\n const next = homeHere ? undefined : (owner ?? (touching && (gate(touching) || slid) ? touching : undefined));\n if (homeHere) {\n // Its spot is the item's own (a hand within the lift zone is at home: the home spot owns it, so a pointer coming\n // in a few px short of the lift point, or held at its edge by a grab at the item's far end, is not on a\n // neighbor's stretch); a lane that lost the id picks along it as entering does.\n const s = spotIn(homeHere, options.home!.spot) ?? pick(homeHere, alongOf(homeHere, p));\n laneId = homeHere.id;\n spotId = s?.id ?? null;\n region = s ? \"lane\" : \"refused\";\n } else if (held && !next && (touching || inside(held.rect, p, margins.exit))) {\n const s = along(held, p, step);\n spotId = s?.id ?? spotId;\n region = s ? \"lane\" : \"refused\";\n if (!s) spotId = null;\n // Past its own rect, a held lane that refuses still holds (lane to lane never passes through the float), but\n // the pointer is in another lane it hasn't entered yet: that lane is pending, so a host shows no \"Can't go here\"\n // in a lane's first pixels when the pointer comes in over a refused stretch next to it.\n if (!s && !strictlyIn(held.rect, p)) {\n const others = regions.lanes.filter((l) => l.id !== held.id && strictlyIn(l.rect, p));\n if (others.length > 0) pending = others.reduce((a, b) => (depthIn(b.rect, p, regions.stage) > depthIn(a.rect, p, regions.stage) ? b : a)).id;\n }\n } else {\n laneId = spotId = null;\n // Entering: a touching lane at once, else the path gate or the still gate; at a tie, the lane the pointer is\n // deeper in. Over a refused place (a lane's band over a column that takes nothing, an empty side rail's) a lane is\n // entered at once, never on the lift: there is nothing else the pointer can mean there, and nothing to fly\n // through to.\n // (Over something that takes nothing reaching past the lane, a column's panel under an empty rail's band, and in\n // no other lane; a drawn bar's own rect and its items lie within it, so its gate holds.)\n // Within the lift zone an owning lane is no lane at all: by no gate does it take the pointer there.\n const lanesHere = regions.lanes.filter((l) => strictlyIn(l.rect, p) && !(l.owns && nearLift));\n const within = (b: Rect, l: LandingLane): boolean => 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;\n // On a slow step only (as a slow hand inside a bar enters it): a fly-through across such a place opens no room.\n const overRefused = (l: LandingLane): boolean =>\n Number.isFinite(step) && step <= gates.step && lanesHere.length === 1 && [...regions.blocked, ...regions.refused].some((b) => strictlyIn(b, p) && !within(b, l));\n let entered: LandingLane | null = next ?? null;\n if (!entered)\n for (const l of lanesHere) {\n const deep = depthIn(l.rect, p, regions.stage);\n if ((gate(l) || overRefused(l)) && (!entered || deep > depthIn(entered.rect, p, regions.stage))) entered = l;\n }\n // Inside a lane not entered yet: no refused place to say so of, whatever lies under it.\n 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;\n if (entered) {\n laneId = entered.id;\n const s = pick(entered, alongOf(entered, p));\n spotId = s?.id ?? null;\n region = s ? \"lane\" : \"refused\";\n } else if (regions.refused.some((r) => inside(r, p))) region = \"refused\";\n else if (inside(regions.content, p) && !regions.blocked.some((b) => strictlyIn(b, p))) region = \"open\";\n // Inside a lane not yet entered: what it was (on the way in, the document's float).\n else if (regions.lanes.some((l) => strictlyIn(l.rect, p))) region = previous === \"lane\" ? \"open\" : previous;\n else region = \"refused\";\n }\n }\n previous = region;\n const shown: LandingRegion = shift && (region === \"lane\" || region === \"open\") ? \"open\" : region;\n const r2 = heldRegions(spotId);\n const heldLane = laneIn(r2, laneId);\n const spot = spotIn(heldLane, spotId);\n landedOn = shown === \"lane\" && spot && heldLane ? { spot, axis: heldLane.axis } : null;\n // A sliding spot's landing follows the pointer; any other spot's is its own.\n const landing = shown === \"lane\" ? (spot && heldLane ? landingAt(heldLane, spot, p, r2.item) : null) : shown === \"open\" ? (options.floatLanding?.(p) ?? null) : null;\n frame = {\n region: shown,\n lane: laneId,\n spot: shown === \"lane\" ? spotId : null,\n landing,\n room: shown === \"lane\" && !!spot,\n guides: guidesFor(p, shown, shift),\n shift,\n ...(pending && shown !== \"lane\" ? { pending } : {}),\n };\n return frame;\n }\n\n return {\n update,\n release(): LandingRelease {\n if (frame.region === \"lane\" && frame.lane && frame.spot) {\n const ownSpot = !!options.home && options.home.spot === frame.spot && options.home.lane === frame.lane;\n // A sliding spot: where its landing starts, read once here (so a wobble never stores a jitter), exactly as the\n // frame shows it (a snap point, else on the spot's grain). It is home only at the item's own place: the home\n // spot's own landing.\n const on = landedOn;\n if (on?.spot.slide && frame.landing) {\n const start = (r: Rect): number => (on.axis === \"x\" ? r.x : r.y);\n const at = start(frame.landing);\n return { kind: \"spot\", lane: frame.lane, spot: frame.spot, home: ownSpot && Math.abs(at - start(on.spot.landing)) < 1e-6, at };\n }\n return { kind: \"spot\", lane: frame.lane, spot: frame.spot, home: ownSpot };\n }\n if (frame.region === \"open\" && frame.landing) return { kind: \"float\", rect: frame.landing };\n return null;\n },\n setRegions(regions: LandingRegions, nextRegionsFor?: (spot: string) => LandingRegions | null): void {\n base = regions;\n if (nextRegionsFor) regionsFor = nextRegionsFor;\n cache.clear();\n const l = laneIn(base, laneId);\n if (laneId && !l) laneId = spotId = null;\n else if (l && spotId && !spotIn(l, spotId) && last) spotId = pick(l, alongOf(l, last.p))?.id ?? null;\n },\n hide(): void {\n laneId = spotId = null;\n approached = null;\n pathIn.clear();\n slide.clear();\n cameIn.clear();\n last = moved = null;\n lastStep = 0;\n },\n get frame(): LandingFrame {\n return frame;\n },\n };\n}\n","import type { DragFrame, DragTarget } from \"./intent\";\n\n/**\n * How a drag previews its drop, from least to most motion while dragging:\n *\n * - `\"indicator\"`: nothing moves; only the indicator (an outline or an\n * insertion marker) shows the target.\n * - `\"gap\"`: once the room is made, the others move aside and open the slot;\n * the item stays under the pointer.\n * - `\"snap\"`: the gap opens and the item itself glides into it (for a target\n * with a slot; one without keeps the indicator).\n * - `\"item\"`: the dragged item is the only preview: no indicator for any\n * target. It sits in a slotted target once the room is open and otherwise\n * stays on the pointer. Pair it with the intent's `earlyRelease: \"float\"`, so\n * a release lands what shows.\n *\n * Every mode follows the same intent: what shows, when, and what a release\n * lands on are the drag intent's, so a drop always lands where the preview\n * showed it.\n */\nexport type DragPreview = \"indicator\" | \"gap\" | \"snap\" | \"item\";\n\n/** The preview a drag uses unless the host picks another. */\nexport const DRAG_PREVIEW_DEFAULT: DragPreview = \"snap\";\n\n/**\n * Place guides: faint marks on the free places that take the held item, shown only while no landing shows. `\"off\"`:\n * none; `\"near\"`: the places of the edge the pointer approaches; `\"all\"`: every place, from the lift.\n */\nexport type PlaceGuides = \"off\" | \"near\" | \"all\";\n\n/**\n * 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\n * the lane will take, over what moves aside (the page, a column); `\"edge\"`, a thin striped strip on the lane's window\n * side. The landing is the same either way. Placement's `lanes()` takes it as `emptyLanes`.\n */\nexport type EmptyLanes = \"real\" | \"edge\";\n\n/**\n * A drop preview as a mode and its place guides, beside the string forms: `\"outline\"` is `\"indicator\"`'s plan,\n * `\"placeholder\"` is `\"gap\"`'s, and `\"snap\"` is `\"item\"`'s (the item the only preview). `placeGuides` defaults per mode\n * ({@link PLACE_GUIDES_DEFAULT}); `emptyLanes` (how its guides draw an empty lane) defaults to `\"real\"`.\n */\nexport type DropPreviewMode =\n | { readonly mode: \"outline\"; readonly placeGuides?: PlaceGuides; readonly emptyLanes?: EmptyLanes }\n | { readonly mode: \"placeholder\"; readonly placeGuides?: PlaceGuides; readonly emptyLanes?: EmptyLanes }\n | { readonly mode: \"snap\"; readonly placeGuides?: PlaceGuides; readonly emptyLanes?: EmptyLanes };\n\n/** Each mode's place guides when it names none: Snap and Placeholder near, Outline none. */\nexport const PLACE_GUIDES_DEFAULT: Readonly<Record<DropPreviewMode[\"mode\"], PlaceGuides>> = { outline: \"off\", placeholder: \"near\", snap: \"near\" };\n\n/** The string plan each mode draws with. */\nconst PLAN_OF: Readonly<Record<DropPreviewMode[\"mode\"], DragPreview>> = { outline: \"indicator\", placeholder: \"gap\", snap: \"item\" };\n\n/** What to draw for one frame of a drag. */\nexport interface PreviewPlan {\n /** Draw the indicator on the shown target. */\n readonly showIndicator: boolean;\n /** Lay the others out around the room (the gap is open). */\n readonly makeRoom: boolean;\n /** Draw the item in its slot instead of under the pointer. */\n readonly snapItem: boolean;\n /**\n * The place guides to draw this frame: the mode's `placeGuides` while no landing shows (no indicator, no room, no item\n * in its slot), `\"off\"` whenever one does, so the screen shows where the item can go or where it will land, never\n * both. Always `\"off\"` for the string forms. Optional, so a plan a host builds itself is still one: absent means\n * `\"off\"`.\n */\n readonly guides?: PlaceGuides;\n /** How the guides draw an empty lane (the object form's `emptyLanes`, `\"real\"` when it names none); absent for the string forms. */\n readonly emptyLanes?: EmptyLanes;\n}\n\n/**\n * The plan for a frame of the drag intent under `preview`. `slotted` says\n * whether the shown target's drop has a slot the item can sit in (default: a\n * target that isn't `free`); only such a target snaps, and in `\"snap\"` it\n * previews with the item rather than the indicator.\n *\n * - `\"indicator\"`: the indicator, never room, never a snap.\n * - `\"gap\"`: the indicator, and room when the intent makes it.\n * - `\"snap\"`: room when the intent makes it, the item snapped into a slotted\n * target's room; the indicator only for a target without a slot.\n * - `\"item\"`: as `\"snap\"`, with no indicator at all.\n *\n * The object form ({@link DropPreviewMode}) draws with its mode's string plan and adds its place guides (`guides`).\n */\nexport function previewPlan<T extends DragTarget>(\n frame: Pick<DragFrame<T>, \"shown\" | \"room\">,\n preview: DragPreview | DropPreviewMode,\n slotted: boolean = !!frame.shown && !frame.shown.free,\n): PreviewPlan {\n if (typeof preview === \"object\") {\n const plan = stringPlan(frame, PLAN_OF[preview.mode], slotted);\n const asked = preview.placeGuides ?? PLACE_GUIDES_DEFAULT[preview.mode];\n const landing = plan.showIndicator || plan.makeRoom || plan.snapItem;\n return { ...plan, guides: landing ? \"off\" : asked, emptyLanes: preview.emptyLanes ?? \"real\" };\n }\n return stringPlan(frame, preview, slotted);\n}\n\nfunction stringPlan<T extends DragTarget>(frame: Pick<DragFrame<T>, \"shown\" | \"room\">, preview: DragPreview, slotted: boolean): PreviewPlan {\n const shown = !!frame.shown;\n if (preview === \"indicator\") return { showIndicator: shown, makeRoom: false, snapItem: false, guides: \"off\" };\n if (preview === \"gap\") return { showIndicator: shown, makeRoom: frame.room, snapItem: false, guides: \"off\" };\n if (preview === \"item\") return { showIndicator: false, makeRoom: frame.room, snapItem: frame.room && shown && slotted, guides: \"off\" };\n // By design a slotted target draws nothing until the room opens (`roomAfter`); a release then still lands on it.\n return { showIndicator: shown && !slotted, makeRoom: frame.room, snapItem: frame.room && shown && slotted, guides: \"off\" };\n}\n","import { DOUBLE_CLICK, type DoubleClick } from \"../double-click\";\nimport type { Point } from \"../shapes\";\nimport { liftDecision, type DragTuning, type LiftDecision } from \"./intent\";\n\n/** How a press on a grip ended: a click, the second click of a double (`doubleActivate`, not a click), or a drag (`null`). */\nexport type GripRelease = \"click\" | \"doubleActivate\" | null;\n\n/** A press on a grip, start to end: whether it lifts, and what its release is. Pure: positions and times are the host's. */\nexport interface GripPress {\n /**\n * A press at `point`, `time` ms. `touch` for a finger (the touch lift rule). `clicks`, when the host has the\n * platform's count for this press (a `mousedown`'s `detail`, 1 or more), decides the double instead of the interval.\n */\n down(point: Point, time: number, options?: { readonly touch?: boolean; readonly clicks?: number }): void;\n /** The pointer moved: `liftDecision` for this press. Once `\"lift\"` it stays a drag; once `\"refuse\"` it never is. */\n move(point: Point, time: number): LiftDecision;\n /**\n * The press ended. `\"click\"`, or `\"doubleActivate\"` when it is the second click of a double (it is not a click\n * then); null when it lifted or was refused. A press that never moved past the lift distance never lifts, so an\n * unmoved double never starts a drag (a second press that moves past it is a drag like any other). A third click\n * after a double starts a new pair.\n */\n up(point: Point, time: number): GripRelease;\n /** Forget the press and the click before it (a cancelled press, a scroll). */\n cancel(): void;\n}\n\n/**\n * A grip's press, double-click included: a press that moves past the lift distance is a drag; one that doesn't is a\n * click, and a second such press within the double interval and distance is a double-activate (the host folds or\n * unfolds, say), never a second click and never a lift: an unmoved double never starts a drag.\n *\n * The first click of a double is delivered as `\"click\"` before the double is known (nothing waits for a second press),\n * so a host keeps a grip's click harmless (a use, a focus): the double-activate that follows must not have to undo it.\n */\nexport function createGripPress(options: { readonly tuning?: Partial<DragTuning>; readonly double?: Partial<DoubleClick> } = {}): GripPress {\n const tuning = options.tuning ?? {};\n // The package's one double click (`DOUBLE_CLICK`), unless the host tunes it.\n const dbl: DoubleClick = { ...DOUBLE_CLICK, ...options.double };\n let press: { at: Point; time: number; touch: boolean; double: boolean; state: LiftDecision } | null = null;\n // The last click (a press that ended as one): where and when it was pressed.\n let last: { at: Point; time: number } | null = null;\n return {\n down(point, time, o = {}) {\n const near = !!last && time - last.time <= dbl.ms && Math.hypot(point.x - last.at.x, point.y - last.at.y) <= dbl.px;\n const double = o.clicks !== undefined && o.clicks > 0 ? o.clicks === 2 : near;\n press = { at: { x: point.x, y: point.y }, time, touch: !!o.touch, double, state: \"wait\" };\n },\n move(point, time) {\n if (!press) return \"wait\";\n if (press.state !== \"wait\") return press.state;\n press.state = liftDecision({ touch: press.touch, distance: Math.hypot(point.x - press.at.x, point.y - press.at.y), elapsed: time - press.time }, tuning);\n return press.state;\n },\n up() {\n const p = press;\n press = null;\n if (!p || p.state !== \"wait\") {\n last = null;\n return null;\n }\n if (p.double) {\n last = null;\n return \"doubleActivate\";\n }\n last = { at: p.at, time: p.time };\n return \"click\";\n },\n cancel() {\n press = null;\n last = null;\n },\n };\n}\n","import type { Rect } from \"../shapes\";\n\n/** A guide to place: any record with a `kind` and a `rect` (a landing model's `LandingGuide`, a lane's marks). */\nexport interface PlacedGuide {\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n}\n\n/** A rect guides stay clear of, with a clearance of its own, px (0: guides may lie flush against it). */\nexport interface ClearRect {\n readonly rect: Rect;\n readonly clearance: number;\n /**\n * The guide kinds this rect constrains (default: all). Content a thin guide keeps clear of, but an empty lane's\n * real-size box lies over (it moves the content aside), is `kinds: [\"line\", \"hatch\"]`.\n */\n readonly kinds?: readonly PlacedGuide[\"kind\"][];\n}\n\nexport interface GuideRectsOptions {\n /** The area guides are drawn in: the window's inside (inside its border), px. */\n readonly inside: Rect;\n /** How far inside `inside` every guide stays, px (default 2). */\n readonly inset?: number;\n /**\n * Rects guides stay clear of. A plain `Rect` keeps `clearance` px (the default gap) for every kind: something guides\n * must keep apart from, such as the held item's outline. `{ rect, clearance, kinds? }` keeps its own, for the kinds\n * it names: `{ rect, clearance: 0, kinds: [\"line\", \"hatch\"] }` is a boundary a thin guide may run flush against (the\n * content: a column's panels under an empty lane's thin edge) while a box may still lie over it.\n */\n readonly clear?: readonly (Rect | ClearRect)[];\n /** How far clear of a plain `clear` rect a guide stays, px (default 2): \"clear of\" means at least this far. */\n readonly clearance?: number;\n /** The least thickness a thin guide keeps, px (default 2); thinner, it is not drawn. */\n readonly minThickness?: number;\n}\n\nconst EPS = 1e-6;\n\n/**\n * Where to draw guides: every guide inside `inside` by `inset`, and at least `clearance` px clear of every `clear` rect\n * (\"clear of\" means at least that far: a plain rect keeps the options' `clearance`, default 2; `{ rect, clearance }`\n * keeps its own, so pass `{ rect, clearance: 0 }` for content a thin guide may run flush against, and `kinds` to\n * constrain only some kinds of guide, default all). A box is clipped,\n * then cut on the side that faces each clear rect (the clear rect grown by its clearance is taken out of it, and the\n * largest remaining part, left, right, above or below, is kept). A thin guide (a line, a striped strip or end: its\n * shorter side is its thickness) keeps its thickness and moves inside rather than being clipped, so a line at a lane's\n * far end is as thick as at its head. Then it is thinned, from the content side, to stay that far clear of `clear`, so\n * a thin strip at the window's side lies between the inset and the content, the same on both sides. A guide with nothing left (or a thin one under `minThickness`) is left out. Pure; the guides come\n * back as given with their placed `rect`, the same object where nothing moved.\n */\nexport function guideRects<G extends PlacedGuide>(guides: readonly G[], options: GuideRectsOptions): G[] {\n const inset = Number.isFinite(options.inset) ? Math.max(0, options.inset!) : 2;\n const min = Number.isFinite(options.minThickness) ? Math.max(0, options.minThickness!) : 2;\n // A guide placed where it already was comes back as given (the same rect object), so a host can key on it.\n const same = (a: Rect, b: Rect): boolean => 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;\n const place = (g: G, rect: Rect): G => (same(g.rect, rect) ? g : { ...g, rect });\n const x0 = options.inside.x + inset;\n const y0 = options.inside.y + inset;\n const x1 = options.inside.x + options.inside.width - inset;\n const y1 = options.inside.y + options.inside.height - inset;\n const gap = Number.isFinite(options.clearance) ? Math.max(0, options.clearance!) : 2;\n // Each clear rect with the gap it keeps: its own, or the options' for a plain one.\n const allClear = (options.clear ?? []).map((c): { k: Rect; gap: number; kinds?: readonly PlacedGuide[\"kind\"][] } =>\n \"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 },\n );\n const out: G[] = [];\n for (const g of guides) {\n const r = g.rect;\n // The clear rects that constrain this kind of guide.\n const clear = allClear.filter((c) => !c.kinds || c.kinds.includes(g.kind));\n if (g.kind === \"box\") {\n let a = Math.max(r.x, x0);\n let b = Math.max(r.y, y0);\n let c = Math.min(r.x + r.width, x1);\n let d = Math.min(r.y + r.height, y1);\n // Clear of what it must not cover: each clear rect, grown by the clearance, is taken out of the box, and the\n // largest part left of it (left, right, above or below) is kept.\n for (const { k, gap } of clear) {\n const k0 = k.x - gap;\n const k1 = k.x + k.width + gap;\n const l0 = k.y - gap;\n const l1 = k.y + k.height + gap;\n if (c - a <= EPS || d - b <= EPS) break;\n if (k1 <= a + EPS || k0 >= c - EPS || l1 <= b + EPS || l0 >= d - EPS) continue;\n const parts = [\n { a, b, c: Math.min(c, k0), d },\n { a: Math.max(a, k1), b, c, d },\n { a, b, c, d: Math.min(d, l0) },\n { a, b: Math.max(b, l1), c, d },\n ].filter((p) => p.c - p.a > EPS && p.d - p.b > EPS);\n if (parts.length === 0) {\n c = a;\n break;\n }\n const best = parts.reduce((p, q) => ((q.c - q.a) * (q.d - q.b) > (p.c - p.a) * (p.d - p.b) ? q : p));\n ({ a, b, c, d } = best);\n }\n if (c - a > EPS && d - b > EPS) out.push(place(g, { x: a, y: b, width: c - a, height: d - b }));\n continue;\n }\n // A thin guide: thick along one axis (its shorter side), long along the other.\n const thinX = r.width <= r.height;\n // Along its thickness: moved inside whole; along its length: clipped.\n const t = thinX ? r.width : r.height;\n let lo = thinX ? r.x : r.y;\n const lim0 = thinX ? x0 : y0;\n const lim1 = thinX ? x1 : y1;\n if (lo + t > lim1) lo = lim1 - t;\n if (lo < lim0) lo = lim0;\n let hi = Math.min(lo + t, lim1);\n const s0 = Math.max(thinX ? r.y : r.x, thinX ? y0 : x0);\n const s1 = Math.min(thinX ? r.y + r.height : r.x + r.width, thinX ? y1 : x1);\n if (s1 - s0 <= EPS) continue;\n // Clear of what it must not cover: cut from the side the clear rect (grown by the clearance) lies on.\n for (const { k: c, gap } of clear) {\n const cs0 = (thinX ? c.y : c.x) - gap;\n const cs1 = (thinX ? c.y + c.height : c.x + c.width) + gap;\n if (cs1 <= s0 + EPS || cs0 >= s1 - EPS) continue;\n const c0 = (thinX ? c.x : c.y) - gap;\n const c1 = (thinX ? c.x + c.width : c.y + c.height) + gap;\n if (c1 <= lo + EPS || c0 >= hi - EPS) continue;\n // Keep the side away from the clear rect's middle.\n if ((c0 + c1) / 2 >= (lo + hi) / 2) hi = Math.min(hi, c0);\n else lo = Math.max(lo, c1);\n }\n if (hi - lo < Math.max(EPS, min)) continue;\n 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 }));\n }\n return out;\n}\n"],"mappings":";;;;;AAoGO,IAAM,gBAA4B;AAAA,EACvC,MAAM;AAAA,EACN,WAAW;AAAA,EACX,WAAW;AAAA,EACX,aAAa;AAAA,EACb,UAAU;AAAA,EACV,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,cAAc;AAAA,EACd,WAAW;AAAA,EACX,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,WAAW;AAAA,EACX,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,WAAW,EAAE,IAAI,MAAM,UAAU,SAAS,SAAS,MAAM;AAC3D;AAEA,IAAM,YAAiE,EAAE,OAAO,SAAS,KAAK,OAAO,SAAS,QAAQ,MAAM,OAAO;AAEnI,IAAM,OAAO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
  "description": "How things move: one frame loop with an injected clock, fine-grained signals, springs, tweens and the settle curve, a DOM-free gesture recognizer, the drag intent and the landing model, and layout motion. No DOM, no framework.",
5
5
  "keywords": [
6
6
  "animation",