@n-uf/motion 26.12.4 → 26.12.6

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.
Files changed (35) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +2 -2
  4. package/dist/browser.js.map +1 -1
  5. package/dist/{chunk-I4TKJWCD.js → chunk-ELRGR2MI.js} +3 -3
  6. package/dist/{chunk-I4TKJWCD.js.map → chunk-ELRGR2MI.js.map} +1 -1
  7. package/dist/{chunk-MTSGXDVI.js → chunk-GLPO4HGL.js} +19 -1
  8. package/dist/chunk-GLPO4HGL.js.map +1 -0
  9. package/dist/{chunk-OOKRBVMB.js → chunk-LSIMILAL.js} +1 -1
  10. package/dist/chunk-LSIMILAL.js.map +1 -0
  11. package/dist/{chunk-BCFPSDOQ.js → chunk-LUFRN56Q.js} +1 -1
  12. package/dist/chunk-LUFRN56Q.js.map +1 -0
  13. package/dist/{chunk-QZJLWSPO.js → chunk-PIQEUBJE.js} +34 -3
  14. package/dist/chunk-PIQEUBJE.js.map +1 -0
  15. package/dist/{chunk-XKCRMQZQ.js → chunk-QZG3DQZ7.js} +1 -1
  16. package/dist/{chunk-XKCRMQZQ.js.map → chunk-QZG3DQZ7.js.map} +1 -1
  17. package/dist/{chunk-GDV76P2H.js → chunk-R4AHR32W.js} +4 -2
  18. package/dist/chunk-R4AHR32W.js.map +1 -0
  19. package/dist/clock.js +1 -1
  20. package/dist/drag.js +1 -1
  21. package/dist/gestures.d.ts +2 -1
  22. package/dist/gestures.js +2 -2
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +7 -7
  25. package/dist/layout.d.ts +2 -2
  26. package/dist/layout.js +2 -2
  27. package/dist/{motion--ql49201.d.ts → motion-CREdoi-4.d.ts} +48 -6
  28. package/dist/signals.js +1 -1
  29. package/dist/values.js +3 -3
  30. package/package.json +1 -1
  31. package/dist/chunk-BCFPSDOQ.js.map +0 -1
  32. package/dist/chunk-GDV76P2H.js.map +0 -1
  33. package/dist/chunk-MTSGXDVI.js.map +0 -1
  34. package/dist/chunk-OOKRBVMB.js.map +0 -1
  35. package/dist/chunk-QZJLWSPO.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/drag/hand-speed.ts","../src/drag/intent.ts","../src/drag/preview.ts","../src/drag/landing.ts","../src/drag/grip.ts","../src/drag/guide-rects.ts"],"sourcesContent":["import { SAME_SAMPLE, sampleOrder } from \"../samples\";\nimport type { Point } from \"../shapes\";\n\n/**\n * The hand's speed, the one estimate a landing model's gates read when they ask \"fast or slow\": the slide count into a\n * touching lane, its entry (`slid`), the settle rule after a fling and the slow-path gate. Speeds are px/ms, as a landing\n * model's gates are.\n *\n * It is read over time, from the distinct samples since the hand last started:\n * - `step`, the newest step alone: a speed-up reads at once.\n * - `long`, over the newest samples that span at least `span` ms and `steps` steps. A speed's error comes from the\n * timestamps at its two ends, a share of a frame each, so the span holds several frames: a fling whose timestamps\n * jitter never reads slow over it. Unknown (null) until the samples since the hand started span that much.\n * - `speed`, the larger of the two (`long` unknown: `step`), so a speed-up reads at once and a slow-down only once it has\n * lasted the span.\n * - `steady`, a slide's evidence: `long` known, and the newest step not faster than `accelerating` times it, so a hand\n * gathering speed out of a hesitation or a rest is no slide yet.\n *\n * A gap of `gap` ms or more between two samples is a rest or a stroke the host lost samples of, and the hand tells them\n * apart by what it saw (decision record 0014):\n * - **A rest** starts the hand again: the samples before it never count. It is a rest when the pointer was seen standing\n * still for `still` ms of it (`hold`: a host that updates per frame reports a rest as it happens), or when the pointer\n * moved across it less than `carry` times the hand's speed so far (a host that sends nothing while the pointer rests),\n * or when the hand has no speed yet.\n * - **A lost stretch** (the pointer moved across it at about the hand's speed: frames the host dropped) carries the hand\n * on: the lost frames are filled in on a straight line at the gap's mean speed, so `long`, `speed` and `steady` read as\n * if they had come. A shorter interval of `fill` frames or more is filled in the same way.\n *\n * Either way the gap's own `step` is unknown (Infinity) unless it is no longer than `slowStep` px (a hand creeping a\n * pixel at a time, which reads slow): a gap may end a rest, so it is never a slow step, and a rest is never averaged into\n * the next fling. Across a lost stretch `speed` and `steady` read its mean, so a slide through it counts on.\n *\n * A sample under `SAME_SAMPLE` (1 ms) past the newest one the hand holds is the same sample (a release read a fraction\n * of a millisecond after the last frame): it is left out, so `step`, `long`, `speed` and `steady` read as they did\n * before it (the pointer's rest seen so far included), instead of reading its few pixels over so short a time as a slow\n * step. In a run of such samples (a host sampling above 1 kHz) the first one that lies 1 ms or more past the newest held\n * is a sample, read over its whole interval from it. A sample whose time lies before the newest held's (an event's time\n * against a frame's; times are expected never to go back) is left out in the same way, however far behind it lies. Two\n * of them, both `gap` ms or more behind, the second stamped `still` ms (at least 1 ms) or more later than the first,\n * with no in-order sample 1 ms or more past the newest held and no repeated frame (`hold`) between (a sample under 1 ms\n * past it is the same sample and ends nothing), are a clock that stepped back: the hand starts again from the second,\n * its step unknown. Known and accepted: two stale samples that far behind and that far apart restart the hand though\n * the clock did not step; a clock that stepped back by up to `gap` + `still` ms and one sample goes on by itself, its\n * first interval read short.\n *\n * Internal to the landing model (not exported from `./drag`).\n */\nexport interface HandSpeed {\n /** A distinct sample of the pointer at `t` ms. */\n push(p: Point, t: number): void;\n /** The pointer seen where its last sample was, at `t` ms (a repeated sample): standing still since. */\n hold(t: number): void;\n /** Forget every sample: the next one starts the hand. */\n reset(): void;\n readonly step: number;\n readonly long: number | null;\n readonly speed: number;\n readonly steady: boolean;\n}\n\n/** The crawl threshold: the longest step over a gap that still reads slow, a length in px (not a speed). */\nconst HAND_SLOW_STEP = 3;\n\nexport interface HandSpeedOptions {\n /** How long the samples `long` reads must span, ms. */\n readonly span: number;\n /** How many steps they must hold, at least. */\n readonly steps: number;\n /** A gap between two samples this long or longer is a rest or a lost stretch, ms. */\n readonly gap: number;\n /**\n * The longest step over a gap that still reads as the speed it is, px (`HAND_SLOW_STEP`, 3 by default; a length, not\n * a speed, so a landing model's `gates.stepSpeed` does not set it): a hand creeping a pixel or two at a time reads\n * slow; a longer step over a gap (a fling out of a rest) is unknown.\n */\n readonly slowStep: number;\n /** How long the pointer seen standing still makes a gap a rest, whatever it moved across it, ms. */\n readonly still: number;\n /**\n * The least share of the hand's speed so far the pointer must move at across a gap for the gap to be a lost stretch\n * rather than a rest.\n */\n readonly carry: number;\n /** An interval this many frames long or longer (a frame: the longest interval of the samples held) is filled in. */\n readonly fill: number;\n /** How much faster than `long` the newest step may be and the hand still be steady (a slide). */\n readonly accelerating: number;\n /** How much faster `long` may read than half a span before and the hand still be steady (not gathering speed). */\n readonly gathering: number;\n}\n\n/**\n * The defaults: at least 48 ms and 5 steps (48 ms at 125 Hz, 80 ms at 60 Hz), so a fling at 2.4 px/ms whose timestamps\n * are off by up to half a frame at 125 Hz, or a third at 60 Hz, still reads above 2 px/ms; a gap of 40 ms (more than\n * two 60 Hz frames with their timestamps half a frame off; a landing model takes the smaller of it and its `pause`); a\n * rest seen for 20 ms (more than a 60 Hz frame, so the repeated sample a host sends within the frame of a move is no\n * rest); a lost stretch at half the hand's speed or more (a rest of 40 ms or more ends with one frame's step, a third of\n * the gap at most, so a hand resuming at its speed reads as resting); filled from two and a half frames (a frame whose\n * timestamps are off by half a frame lasts two at most, so jitter alone is never filled); steady up to 1.5 times.\n */\nexport const HAND_SPEED: HandSpeedOptions = { span: 48, steps: 5, gap: 40, slowStep: HAND_SLOW_STEP, still: 20, carry: 0.5, fill: 2.5, accelerating: 1.5, gathering: 1.25 };\n\n/** The most frames a lost stretch is filled with: the newest ones (more than the span and a half reads). */\nconst FILL_MAX = 32;\n\nexport function createHandSpeed(options: Partial<HandSpeedOptions> = {}): HandSpeed {\n const o = { ...HAND_SPEED, ...options };\n let samples: { p: Point; t: number }[] = [];\n /** The newest step as `speed` and `steady` read it: across a lost stretch, its mean. */\n let newest = Infinity;\n /** The newest step as `step` reads it: across a gap, unknown unless a crawl. */\n let step = Infinity;\n let long: number | null = null;\n /** `long` as it read at the samples of the last span, oldest first. */\n let longs: { t: number; v: number }[] = [];\n /** When the pointer was last seen standing still at the newest sample (`hold`), or null. */\n let heldTo: number | null = null;\n /** The earliest time of the run of samples `gap` ms or more before the newest held that is going on, or null. */\n let behind: number | null = null;\n const dist = (a: Point, b: Point): number => Math.hypot(b.x - a.x, b.y - a.y);\n /** The path over the samples held. */\n const path = (): number => {\n let sum = 0;\n for (let i = 1; i < samples.length; i++) sum += dist(samples[i - 1]!.p, samples[i]!.p);\n return sum;\n };\n /** The hand's speed so far: `long`, else over the samples held (two at least), else null. */\n const sofar = (): number | null => {\n if (long !== null) return long;\n const first = samples[0]!;\n const lastT = samples[samples.length - 1]!.t;\n return samples.length > 1 && lastT > first.t ? path() / (lastT - first.t) : null;\n };\n /** One sample into the window (a real one, or a lost frame filled in). */\n const add = (p: Point, t: number): void => {\n const last = samples[samples.length - 1];\n if (!last) newest = step = Infinity;\n else {\n const d = dist(last.p, p);\n newest = step = d / (t - last.t);\n }\n samples.push({ p, t });\n // Keep the newest samples that span the window, and no more.\n while (samples.length > o.steps + 1 && t - samples[1]!.t >= o.span) samples.shift();\n const first = samples[0]!;\n if (samples.length > o.steps && t - first.t >= o.span) {\n long = path() / (t - first.t);\n longs.push({ t, v: long });\n while (longs.length > 1 && t - longs[1]!.t >= o.span / 2) longs.shift();\n } else long = null;\n };\n return {\n push(p, t) {\n const last = samples[samples.length - 1];\n const seenStill = !!last && heldTo !== null && heldTo - last.t >= o.still;\n if (!last) {\n heldTo = behind = null;\n add(p, t);\n return;\n }\n const dt = t - last.t;\n // The same sample: nothing about the hand changes, the pointer's rest seen so far included (a release read under a\n // millisecond after the last frame never reads slow, and a run of such samples is read from the first one a\n // millisecond or more past the newest held). One that lies before the newest held (an event's time against a\n // frame's) is left out the same way, however far behind it lies: one late stamp is no clock step. Only two of\n // them, both `gap` ms or more behind (the first noted in `behind`) and `still` ms or more apart, with no in-order\n // sample or repeated frame between, are a clock that stepped back, and the hand starts again from the second. The\n // two lie at least `SAME_SAMPLE` apart whatever `still` is: stamps closer than that are one sample. A sample under\n // it past the newest held is left out, and a run of them is read from the first one that lies this far past the\n // newest sample held, over the whole interval (`sampleOrder`, shared with the release velocity).\n if (sampleOrder(last.t, t) !== \"next\") {\n if (dt > -Math.max(o.gap, SAME_SAMPLE)) return;\n if (behind === null || t < behind) behind = t;\n if (t - behind < Math.max(o.still, SAME_SAMPLE)) return;\n heldTo = behind = null;\n samples = [{ p, t }];\n newest = step = Infinity;\n long = null;\n longs = [];\n return;\n }\n heldTo = behind = null;\n const d = dist(last.p, p);\n // The gap's own step: it may end a rest, so it is unknown unless it is a crawl.\n const across = d <= o.slowStep ? d / dt : Infinity;\n if (dt >= o.gap) {\n const v = sofar();\n if (seenStill || v === null || d / dt < v * o.carry) {\n // A rest: the hand starts again here.\n samples = [{ p, t }];\n newest = step = across;\n long = null;\n longs = [];\n return;\n }\n }\n // A lost stretch, or an interval of `fill` frames or more the pointer didn't rest in: the frames the host lost,\n // filled in on a straight line at the mean speed across it. A frame is the longest interval held, so a jittered\n // frame never fills in more frames than were lost: the span `long` reads still holds `steps` frames of real time,\n // and a fling whose timestamps jitter still never reads slow across it.\n let frame = 1;\n for (let i = 1; i < samples.length; i++) frame = Math.max(frame, samples[i]!.t - samples[i - 1]!.t);\n if (!seenStill && samples.length > 1 && (dt >= o.gap || dt >= o.fill * frame)) {\n const n = Math.floor(dt / frame);\n for (let i = Math.max(1, n - FILL_MAX); i < n; i++) add({ x: last.p.x + ((p.x - last.p.x) * i) / n, y: last.p.y + ((p.y - last.p.y) * i) / n }, last.t + (dt * i) / n);\n }\n add(p, t);\n if (dt >= o.gap) step = across;\n },\n hold(t) {\n const last = samples[samples.length - 1];\n // A repeated frame in order ends a run of stale samples, as a sample in order does.\n if (last && t > last.t) {\n heldTo = t;\n behind = null;\n }\n },\n reset() {\n samples = [];\n newest = step = Infinity;\n long = null;\n longs = [];\n heldTo = behind = null;\n },\n get step() {\n return step;\n },\n get long() {\n return long;\n },\n get speed() {\n return long === null ? newest : Math.max(newest, long);\n },\n get steady() {\n // Known for half a span, not faster now than then by more than `gathering`, and the newest step in line with it.\n const then = longs[0];\n return long !== null && newest <= long * o.accelerating && !!then && longs[longs.length - 1]!.t - then.t >= o.span / 2 && long <= then.v * o.gathering;\n },\n };\n}\n","import { isHeld, type ModifierKey, type Modifiers } from \"../keys\";\nimport type { Point, Rect } from \"../shapes\";\nimport { HAND_SPEED } from \"./hand-speed\";\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 grip under a strip at the\n * window's edge) must leave it and come back before it can arm; entering from over home counts.\n */\n readonly armAfter: 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 grip at the window's\n * edge). 16 px is about a grip's size. Elsewhere, home under a strip included, arming works as before, and the arm key\n * forces the nearest spring-loaded target 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 * The modifier keys held on a sample (a pointer event's `shiftKey`, `altKey`, `ctrlKey`, `metaKey`): the recognizer's\n * {@link Modifiers}, any field left out not held.\n */\nexport type DragKeys = Partial<Modifiers>;\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 `armKey` is held it goes to the nearest spring-loaded target (marked `arm`), armed, without reaching it.\n * `floatKey` wins when both are held. `on: false` turns both off.\n */\nexport interface DragModifiers {\n readonly on: boolean;\n readonly floatKey: ModifierKey;\n readonly armKey: 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 spring-loaded target. Alt is left free: a host\n * keeps it for a meaning of its own, 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 armAfter: 200,\n liftZone: 16,\n modifiers: { on: true, floatKey: \"shift\", armKey: \"mod\" },\n};\n\n/**\n * A drop target: plain data. The spring-loading and room fields (`arm`, `armedHit`, `opensRoom`, `roomHold`, `roomHit`) are\n * the intent's own: they are read here, and `@n-uf/docking`'s `DockDrop` sets them (`@n-uf/placement`'s `Target` has none\n * of them). `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 `armAfter`; 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 clamped onto the window's edge\n * picks a gap whose hit reaches the edge, else nothing (a held target keeps its band), and never a refusal or the\n * float. Give the intent the window's stage as {@link DragIntentOptions.bounds} and it clamps every sample exactly\n * onto that edge (`x + width`, `y + height`) itself.\n *\n * `opensRoom: true` marks a target whose indicator would lie over what its room moves (a drop at an edge that pushes\n * its neighbor aside). Showing it and making its room are then one decision: it shows only once it has held\n * `roomAfter` ms, and the frame that first shows it already has `room`. A sweep across it moves nothing, as for any\n * target, and no frame draws it over what moves. Until it shows, a release still lands on it. An armed spring-loaded\n * target has its room at once too: its dwell was the decision. `roomHold` is how long this target holds before that\n * decision, in ms, in place of `roomAfter` (a target against the window's edge, which a pointer rarely crosses on its\n * way elsewhere, can wait less). A host that draws only a marker and doesn't use `previewPlan`'s room opens the room\n * on `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 * edge 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. This is the one export of the rank: `@n-uf/docking`'s reference host (which doesn't\n * import motion) keeps a private copy of the same value, and a test holds the two equal.\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. Home holds wherever it lies.\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 `\"armed\"` (the arm key: the nearest\n * spring-loaded target, armed), else null. The float key chooses the float over the other targets, not over a refusal\n * or outside the window: there it is still `\"float\"` (the key is held), but nothing shows, a release lands nowhere,\n * and over a refusal `refused` says which.\n */\n readonly forced: \"float\" | \"armed\" | 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 * What a release at this frame's point lands on, by the one check `release` makes, or null (nowhere, or the item\n * goes home). A host draws the landing from it, so what it draws and what a release lands on never disagree.\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 /**\n * Where the item was lifted from: the indicator stays off until the pointer leaves it, and a release there does\n * nothing. Absent: no home (the pointer has left it from the first sample, and a release anywhere lands on what is\n * under it), for a host whose targets hold the item's own place themselves.\n */\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 drawn space the drag happens in (a window's stage), in the same px as the samples: every point `update` and\n * `release` take is clamped onto it, exactly onto its edge (`x + width`, `y + height`), so a pointer past the window\n * picks what is drawn against its edge (see {@link DragTarget}'s `bounds`). Absent: points are taken as given. A view\n * that resizes during the drag passes the new one to {@link DragIntent.setBounds}.\n */\n readonly bounds?: Rect;\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` and `time` lands on: the shown target whenever one shows (a drop lands where the\n * indicator was), else the target under the pointer, else null (the item goes home). A release over home is null: it\n * does nothing. With a modifier key held (`keys`), the target the key picks, even over home. A point that differs\n * from the last `update`'s is that update's sample first, so a last jump of the pointer counts. That sample is no\n * frame: `HAND_SPEED.gap` (40) ms or more after the last `update` it is stamped at that update's time, so no dwell,\n * arm, switch hold, room or gap grace runs on through time no frame drew, and it keeps the speed that update read.\n * Call it with the pointer-up point and time, with no `update` of your own first.\n */\n release(point: Point, time: number, targets: readonly T[], keys?: DragKeys): T | null;\n /** The drawn space changed during the drag (the view resized): later points are clamped onto `bounds`, or none. */\n setBounds(bounds: Rect | undefined): void;\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). With no home, nothing. */\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 `armAfter` (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 another target or open space inside the float's\n * `bounds`, the arm 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 * - With `bounds`, every point is clamped onto it first (exactly onto its edge).\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 | null = options.home ? { ...options.home } : null;\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 drawn space every point is clamped onto (`bounds`), and the last point `update` took (after the clamp).\n let bounds: Rect | undefined = options.bounds ? { ...options.bounds } : undefined;\n let lastPoint: Point | null = null;\n /** The time of the last `update` (the last frame). */\n let lastT = 0;\n /** The sample being taken is the release's own, `HAND_SPEED.gap` ms or more after the last frame (see `release`). */\n let unseen = false;\n const clampInto = (p: Point): Point =>\n bounds ? { x: Math.min(Math.max(p.x, bounds.x), bounds.x + bounds.width), y: Math.min(Math.max(p.y, bounds.y), bounds.y + bounds.height) } : p;\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 arm key the nearest spring-loaded one.\n * The float key chooses the float over the other targets, not over refusals or outside the window: where the pick at\n * `p` (`has`: a target with a place there, or a refusal) is a refusal, it picks nothing and says which refusal;\n * outside the float's `bounds` (a pointer clamped onto the window's edge) it picks nothing. The arm key's drop lands\n * on the spring-loaded target, 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\" | \"armed\"; target: T | null; refused: T | null } | null => {\n const m = tuning.modifiers;\n if (!m.on || !keys) return null;\n if (isHeld(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 (!isHeld(keys, m.armKey)) 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: \"armed\", 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 (home && 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 (s) return s;\n return under && !under.refuse ? (given.find((x) => x.id === under.id) ?? under) : null;\n };\n\n function update(point: Point, time: number, given: readonly T[], keys?: DragKeys): DragFrame<T> {\n const p = clampInto(point);\n lastPoint = p;\n const t = time;\n lastT = t;\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 // (The release's own sample after time no frame drew keeps the speed the last frame read: stamped at that frame's\n // time, its move would read as one made in no time, end the aim and land a target no frame showed.)\n if (!unseen) 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 (!home || !inRect(home, p, -tuning.homeInset)) leftHome = true;\n const atHome = !!home && 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 `armAfter`. 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 arm key still forces the nearest one.\n liftAt ??= { x: p.x, y: p.y };\n const inLiftZone = 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.armAfter) {\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 // Home holds wherever it lies (the item's own place beats a refusal).\n const homeHolds = atHome;\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 // 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 return { shown, room: roomPlace !== null, roomPlace, aiming, atHome: !forced && wentOut && homeHolds, arming, forced: forced?.kind ?? null, refused, landing: landAt(p, given, keys) };\n }\n\n return {\n tuning,\n get state(): DragIntentState<T> {\n return { speed, current: cur, shown, leftHome };\n },\n update,\n release(point, time, given, keys) {\n // The last update's sample is the release's: a point that differs from it is one more sample first. That sample is\n // no frame: `HAND_SPEED.gap` ms or more after the last one, it is stamped at the last frame's time, so it counts\n // where the pointer went and none of the time no frame drew (no dwell, arm, switch, room or grace runs on), with the\n // speed the last frame read (no aim ended by a move read as made in no time).\n const p = clampInto(point);\n if (!lastPoint || lastPoint.x !== p.x || lastPoint.y !== p.y) {\n unseen = !!lastPoint && time - lastT >= HAND_SPEED.gap;\n try {\n update(p, unseen ? lastT : time, given, keys);\n } finally {\n unseen = false;\n }\n }\n return landAt(p, given, keys);\n },\n setBounds(next) {\n bounds = next ? { ...next } : undefined;\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 },\n moveHome(dx, dy) {\n if (home) home = { ...home, x: home.x + dx, y: home.y + dy };\n },\n };\n}\n","import type { Rect } from \"../shapes\";\nimport type { DragFrame, DragTarget } from \"./intent\";\nimport type { LandingRegion } from \"./region\";\n\n/**\n * How a drag previews its drop, from least to most motion while dragging. One vocabulary for both drag models (the\n * intent and the landing model):\n *\n * - `\"outline\"`: nothing moves; only the indicator (an outline or an insertion marker) shows the landing.\n * - `\"placeholder\"`: once the room is made, the others move aside and open the slot; the item stays under the pointer.\n * - `\"glide\"`: the slot opens and the item itself glides into it (for a landing with a slot; one without keeps the\n * indicator).\n * - `\"snap\"`: the dragged item is the only preview: no indicator for any landing. It sits in a slotted landing once\n * the room is open and otherwise stays on the pointer.\n *\n * Every mode follows the same model: what shows, when, and what a release lands on are the model's, so a drop always\n * lands where the preview showed it.\n */\nexport type PreviewMode = \"outline\" | \"placeholder\" | \"glide\" | \"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/** A drag's preview: its mode and its place guides (default per mode, {@link PLACE_GUIDES_DEFAULT}). */\nexport interface DragPreview {\n readonly mode: PreviewMode;\n readonly placeGuides?: PlaceGuides;\n}\n\n/** The preview a drag uses unless the host picks another. */\nexport const DRAG_PREVIEW_DEFAULT: DragPreview = { mode: \"glide\" };\n\n/** Each mode's place guides when it names none: Snap and Placeholder near, Outline and Glide none. */\nexport const PLACE_GUIDES_DEFAULT: Readonly<Record<PreviewMode, PlaceGuides>> = { outline: \"off\", placeholder: \"near\", glide: \"off\", snap: \"near\" };\n\n/**\n * The place guides a preview asks for: its `placeGuides`, else its mode's default. The one reading of the level:\n * `previewPlan` draws it, and the landing model (`createLandingModel({ preview })`) names its lanes by it.\n */\nexport function guidesOf(preview: DragPreview | PreviewMode): PlaceGuides {\n const p: DragPreview = typeof preview === \"string\" ? { mode: preview } : preview;\n return p.placeGuides ?? PLACE_GUIDES_DEFAULT[p.mode];\n}\n\n/** What to draw for one frame of a drag. */\nexport interface PreviewPlan {\n /** Draw the indicator on the shown landing. */\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 preview's `placeGuides` while no landing shows (no indicator, no room, no\n * item in its slot), `\"off\"` whenever one does, so the screen shows where the item can go or where it will land,\n * never both.\n */\n readonly guides: PlaceGuides;\n}\n\n/**\n * A frame `previewPlan` reads: the drag intent's (what shows) or the landing model's (where it lands: a\n * `LandingFrame`'s `region`, `landing` and `room`).\n */\nexport type PreviewFrame<T extends DragTarget = DragTarget> =\n | Pick<DragFrame<T>, \"shown\" | \"room\">\n | { readonly region: LandingRegion; readonly landing: Rect | null; readonly room: boolean };\n\n/**\n * The plan for a frame of either drag model under `preview` (a mode alone is `{ mode }`). From an intent's frame a\n * landing shows when a target shows, slotted unless it is `free`; from a landing frame it shows wherever the frame has a\n * landing, slotted in a lane (the float is not). `slotted` overrides that.\n *\n * - `\"outline\"`: the indicator, never room, never a snap.\n * - `\"placeholder\"`: the indicator, and room when the model makes it.\n * - `\"glide\"`: room when the model makes it, the item snapped into a slotted landing's room; the indicator only for a\n * landing without a slot.\n * - `\"snap\"`: as `\"glide\"`, with no indicator at all.\n */\nexport function previewPlan<T extends DragTarget>(frame: PreviewFrame<T>, preview: DragPreview | PreviewMode, slotted?: boolean): PreviewPlan {\n const p: DragPreview = typeof preview === \"string\" ? { mode: preview } : preview;\n const landing = \"region\" in frame;\n const shown = landing ? frame.landing !== null : !!frame.shown;\n const slots = slotted ?? (landing ? frame.region === \"lane\" : !!frame.shown && !frame.shown.free);\n const plan = planOf(p.mode, shown, frame.room, slots);\n const drawn = plan.showIndicator || plan.makeRoom || plan.snapItem;\n return { ...plan, guides: drawn ? \"off\" : guidesOf(p) };\n}\n\nfunction planOf(mode: PreviewMode, shown: boolean, room: boolean, slotted: boolean): Omit<PreviewPlan, \"guides\"> {\n if (mode === \"outline\") return { showIndicator: shown, makeRoom: false, snapItem: false };\n if (mode === \"placeholder\") return { showIndicator: shown, makeRoom: room, snapItem: false };\n if (mode === \"snap\") return { showIndicator: false, makeRoom: room, snapItem: room && shown && slotted };\n // By design a slotted landing draws nothing until the room opens (`roomAfter`); a release then still lands on it.\n return { showIndicator: shown && !slotted, makeRoom: room, snapItem: room && shown && slotted };\n}\n","import type { Point, Rect } from \"../shapes\";\nimport { isHeld } from \"../keys\";\nimport { createHandSpeed, HAND_SPEED } from \"./hand-speed\";\nimport { DRAG_DEFAULTS, type DragKeys, type DragModifiers } from \"./intent\";\nimport { DRAG_PREVIEW_DEFAULT, guidesOf, type DragPreview, type PlaceGuides, type PreviewMode } from \"./preview\";\nimport type { LandingRegion } from \"./region\";\n\n/**\n * The landing model: where a docking drag's item lands, as a held place rather than a per-frame guess. A host gives it the\n * drag's geometry (`@n-uf/docking`'s `dockDrag(...)` fits `LandingGeometry` as it is: the regions for hit-testing and\n * `landingOf(held)`) and each pointer sample; it says the region the pointer is in, the lane and spot held, the held place a\n * release lands (`frame.held`), where the item lands, whether the room is open, and which lanes' place guides show with\n * the held place each stands for. It picks held places and does no layout: every rect of a held place comes from the geometry. Every\n * change comes from where the pointer is and how it moved (margins, a path length, a step size): the model has no waits\n * 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\"). (Docking'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 * `stepSpeed`), or a still step (at most `stillSpeed`) once `depth` px inside, the depth measured across the lane: only from its\n * two sides parallel to its axis that face into the stage (on the edge it is deep), never from its ends along its axis\n * (a rail's end that meets a bar is no wall). A fly-through of a thin bar or rail at any angle meets neither, so its\n * room never opens. **No distance that reaches into a lane is more than `laneShare` (a third) of that lane's\n * thickness** (its rect's extent across its axis, the rect as hit-tested, not as drawn): the depth gate is\n * `min(depth, laneShare × thickness)`, and so is the held lane's exit margin measured into a lane that touches it,\n * or, where no touching lane lies under the pointer, into a blocked or refused rect that touches it (its thickness\n * the way the pointer reaches into it, across a bar beside the held lane, along a rect past its end: a full title\n * bar that takes nothing shows its refusal from its middle third on).\n * The first third of a lane still belongs to the lane you came from; from there on a still pointer is in the new\n * lane, so a thin lane (a 24 px title bar) is entered at its middle and shows its guide there. Lanes of 36 px and more\n * (48 with the touch margins) keep the full `exit`, and of 24 px and more the full `depth`. Inside a lane that touches\n * the held one, past the held lane's exit margin into it (where the pointer is inside several, the thinnest one's),\n * the held lane holds until one of those lanes' own gate passes or the pointer has slid `path` px along it (across it\n * at most a third as far) as a steady slide no faster than `slideSpeed` (2 px/ms), as the hand's speed reads it: lane\n * to lane never passes through the float, and never opens a crossed lane's room. A fling, along the lane or across it, is no entry: the touching lane is\n * entered only by its own gate (the slow path, or a rest past `pause`). The cost: above 2 px/ms a hand sliding along a\n * corner lane keeps the previous lane's end spot until it slows or rests, and a slide counts only once the hand's\n * speed is known and steady (a span and a half, 72 ms at 125 Hz, 120 ms at 60 Hz). The hold through a touching lane is\n * for crossing a corner: more than `exit + path` from the held lane's rect (the full `exit`, whatever lane lies there)\n * the frame is held but refused (the lane kept for its guides; no spot, no landing, nothing pending; a release goes\n * home), sticky until the pointer is back within `exit + path - spot`. Over a refused place (a lane's band lying over a column that takes nothing: an empty\n * side rail's) a lane is entered on the first slow step there (not on the lift), as there is nothing else to mean\n * there; a fly-through still opens no room. A touching lane's takeover reads the same rule, so a held lane never\n * pre-empts it. After a fling (the hand's speed above `slideSpeed`) no lane is entered by a slow-step gate (still,\n * over-refused) until the hand has read slow (or rested) for `pause`: jitter right after a flick docks nothing, while\n * on the stage's edge a fling is taken at once.\n * - **The hand's speed** (`createHandSpeed`, ./hand-speed) is the one estimate every gate that asks \"fast or slow\"\n * reads: the slide count and its entry, the settle rule, the slow path. It reads a speed-up at once (the newest step)\n * and a slow-down only once it has lasted its span (at least 48 ms and 5 steps), so a fling whose timestamps jitter\n * never reads slow; a gap of 40 ms or more that was a rest (the pointer seen standing still in it, or moving across\n * it at less than half the hand's speed) starts the hand again, so a rest is never averaged into the next fling, while\n * a gap the pointer moved on through (frames the host lost) carries the hand on, its lost frames filled in, so a\n * dropped frame never loses a slide; a step across a gap is never a slow step; and a slide counts only while the hand\n * reads steady (not gathering speed), from where the pointer crossed into the lane. A host sampling slower than 25 Hz\n * (every step a gap, the hand with no speed yet) slides into a touching lane only by its own gates. 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 held 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 * - **A float's lift zone.** A lift is a float's when it has no `home` option and no lane has a spot marked `home` (a\n * docked item's own place; docking always marks it), so a docked item lifted without `home` stays docked. A float has a zone of\n * its own, the same `margins.lift` around the press: within it no lane takes the pointer, and the frame is judged as if\n * the regions had no lanes (the float is at the hand, so a nudge moves it; blocked and refused places are judged as on\n * any frame, so a float lying over one is refused there). No lane's path counts inside it. The zone is left once, at\n * the first point farther than `lift` from the press, and never re-entered: the lanes act as usual from then on, a\n * held lane included, so a slide back through the press point changes nothing. A float lying inside a lane's band\n * (an empty bar's) stays a float for the first `lift` px, and the lane takes it by its gates after.\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 `stepSpeed`, or once the held landing trails the\n * pointer by more than `trail` (`landingOf` the spot held): the item chases only as far as it must. A change that\n * moves only the held item follows the hand at any speed. With `spotsOf`, a reflowing change is kept only if, with the\n * new spot held (its room open), the pointer still lies in that spot's stretch: the room shifting the boundary never\n * bounces it.\n * - **A sliding spot** (a free stretch as one spot) lands where the hand is: the model names the spot and the pointer,\n * and the geometry says where (`landingOf`). Nothing reflows inside it, so there are no steps there; a step comes only\n * where the order changes (passing a neighbor), as between any two spots.\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 * - **The float key** (`modifiers.floatKey`, Shift by default) turns a lane or open space into open space (the float), and\n * hides the guides.\n * - **Guides** name lanes and the held place each lane's guide stands for (`frame.guides`); the geometry draws them (a lane's\n * marks in that held place's layout). `\"near\"` shows a lane only where the pointer can enter it: the held lane's (also over its own\n * refused stretch); else the pending lane's (the pointer inside it, its gate not passed: a release floats or goes\n * home); else, with the pointer in open space, the approached lane's (the nearest within `reach`, by default the\n * entry margin `exit`, acquired within `max(reach - spot, reach / 2)` and kept to `reach`, so it never blinks at the\n * edge: a release floats). Over a refused place outside every lane no guide shows, however near the lane behind it\n * lies; a host that wants the early guide sets `approach.reach` (in open space only: over a refused place none shows\n * at any reach). That lane (the one the Near rule picks), held, stands for the frame's held place; pending or approached,\n * for the held place the pointer would land in there (the spot it picks along it), so its guide before entry is its mark\n * after it. `\"all\"` shows every lane's, every other lane standing for the frame's held place (the screen); with no Near\n * lane, the lane nearest the pointer within `reach` stands for its would-land held place, for the corner only (not made\n * Near, pending or enterable), switching exactly at `reach`. Where that lane's guide meets another's, the geometry\n * gives it that lane.\n * - Steps are speeds (px/ms) between points that differ, so the gates read the same speed at any input rate from 60 Hz\n * to 8 kHz. A point stamped under 1 ms after the newest one the hand holds is the same sample and changes no step (a\n * run of them is read from the first one 1 ms or more past it); one stamped before it is left out too. A repeated\n * point keeps the last step; it is still only once the pointer has stayed put for `rest` ms.\n * - **The pointer** is taken onto the stage by the model itself (past it by up to `edge`, onto its edge).\n *\n * **The host's part:** call `update` whenever you like: per pointer sample, per animation frame, or both. Times never go\n * back: give every call a time no earlier than the one before. Call it at least once more after the pointer stops,\n * `rest` ms or more later (every frame does), so it can become still and a rest reads as one (a rest the model never\n * sees is told from frames the host lost only by how far the pointer moved across it), and again with the same point\n * when a key changes. `release(point, time)` takes the release point as one more sample when it differs from the last;\n * that sample is no frame, and the hand's rest gap or more after the last `update` it counts none of the time between,\n * so a rest no frame drew counts for nothing (a slow page docks late, never falsely).\n * When the state under the drag changes (a resize, a store change), hand the new geometry whole to `setGeometry`.\n */\n\n/** A place a drop in a lane lands: its stretch of the lane and its listed landing rect. Ids are stable across solves. */\nexport interface LandingSpot {\n readonly id: string;\n readonly along: readonly [number, number];\n /** Its landing as listed (a sliding spot's at rest): what `home` compares with. Where it lands now is `landingOf`. */\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 /** The held item's own place at the lift (a docked item's; docking marks it): a lift with no spot marked home is a float's. */\n readonly home?: boolean;\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 /**\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}\n\n/** One lane a frame shows place guides for, with the held place its guide stands for (`LandingFrame.guides`). */\nexport interface LandingGuideRef {\n readonly lane: string;\n readonly held: LandingHeld | null;\n}\n\nexport interface LandingMargins {\n /**\n * Past a held lane's rect before it lets go, px: at most, since into a lane that touches the held one it is at most\n * `laneShare` of that lane's thickness, and so it is into a blocked or refused rect that touches it (no touching lane\n * there; the rect's thickness the way the pointer reaches into it: across a bar beside the held lane, along a rect past\n * its end).\n */\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 /**\n * The share of a lane's thickness (its rect's extent across its axis) that any distance reaching into it may take, at\n * most: the held lane's `exit` into a lane that touches it (or into a blocked or refused rect that touches it), and the\n * gates' `depth` (default a third). The first third\n * of a lane still belongs to the lane you came from; from there on a still pointer is in the new lane. A share that\n * isn't a positive number takes the default. The drag intent's `bandShare` and placement's tiling-hit cap are the\n * same kind of rule, each over its own model's distances.\n */\n readonly laneShare?: 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: at most `margins.laneShare` of the lane's thickness. */\n readonly depth: number;\n /** The speed of a still step, at most, px/ms. */\n readonly stillSpeed: number;\n /**\n * The fastest step that changes the spot along a lane where the change reflows the window, px/ms; it also bounds the\n * steps the path gate counts (a fast crossing never enters).\n */\n readonly stepSpeed: 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 * `stepSpeed`) 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 /**\n * The time a pointer that last moved fast has to stay put before it counts as still, ms: longer than sample gaps. Also\n * the settle window after a fling (a step above `slideSpeed`): no lane is entered by a slow-step gate (still,\n * over-refused) until the hand has been slow, or resting, this long.\n */\n readonly pause: number;\n /**\n * The fastest step at which a slide along a lane touching the held one takes it, px/ms (default 2). Above it a fling\n * is no entry; the lane's own gate (the slow path, or a rest past `pause`) still enters it.\n */\n readonly slideSpeed: number;\n}\n/**\n * The approach for near guides, with the pointer in open space: the nearest lane within `reach`, kept until another is\n * `nearer` closer or past `keep` (read as at least `reach`: a kept lane is never shown past it). The guide shows only\n * within `reach` of the lane, so by default only where the pointer can enter it.\n */\nexport interface LandingApproach {\n /**\n * How near a lane's rect the pointer is in open space for the lane's guides to show, px (default 12: the entry\n * margin). A lane is acquired within `max(reach - margins.spot, reach / 2)` and kept until `reach` (or `keep`), so\n * at the edge the guide never blinks.\n */\n readonly reach: number;\n /** How far a kept lane stays the approached one, px (default 12). Below `reach` it is `reach`. */\n readonly keep: number;\n /** How much nearer another lane has to be to take over from the kept one, px (default 16). */\n readonly nearer: number;\n}\n\n/** The default `laneShare`: a third of a lane's thickness. */\nconst LANE_SHARE = 1 / 3;\n/** The margins: 12 px exit, 6 px spot, 48 px edge, 16 px lift; a distance into a lane at most a third of its thickness. */\nexport const LANDING_MARGINS: LandingMargins = { exit: 12, spot: 6, edge: 48, lift: 16, laneShare: LANE_SHARE };\n/** A touch: wider margins, the finger's jitter. */\nexport const LANDING_TOUCH_MARGINS: LandingMargins = { exit: 16, spot: 8, edge: 48, lift: 16, laneShare: LANE_SHARE };\n\n/**\n * `px`, as a distance reaching into `rect` across `axis` (the long axis of the lane it is measured for): at most `share`\n * of its thickness, its extent across that axis. The one place the lane-share rule lives. A rect of no thickness (zero,\n * negative, not a number) caps nothing. The cap is the thickness divided by the share's reciprocal, so the default third\n * is exact (a 24 px lane gives 8, not a hair under it).\n */\nfunction intoRect(rect: Rect, axis: LandingLane[\"axis\"], px: number, share: number): number {\n return capBy(axis === \"x\" ? rect.height : rect.width, px, share);\n}\n/** `px`, at most `share` of a thickness `t`; a thickness that isn't positive caps nothing. */\nfunction capBy(t: number, px: number, share: number): number {\n if (!(t > 0) || share === Infinity) return px;\n return Math.min(px, t / (1 / share));\n}\n/**\n * `px`, as a distance reaching from `from` into `rect` at `p`: at most `share` of the rect's extent in each direction the\n * pointer lies past `from`'s rect (out of its side, the rect's extent across; past its end, along). So a bar beside a\n * lane is measured across it, and a long rect past a lane's end along its length.\n */\nfunction reachInto(rect: Rect, from: Rect, p: Point, px: number, share: number): number {\n let m = px;\n if (p.x < from.x || p.x > from.x + from.width) m = capBy(rect.width, m, share);\n if (p.y < from.y || p.y > from.y + from.height) m = capBy(rect.height, m, share);\n return m;\n}\n/** `px`, as a distance reaching into `lane`: at most `share` of its thickness (its rect's extent across its axis). */\nconst intoLane = (lane: LandingLane, px: number, share: number): number => intoRect(lane.rect, lane.axis, px, share);\n/**\n * The gates: 40 px of path, 8 px deep, a still step at most 0.1875 px/ms, a reflowing one at most 0.375 px/ms, a slide\n * into a touching lane at most 2 px/ms.\n */\nexport const LANDING_GATES: LandingGates = { path: 40, depth: 8, stillSpeed: 0.1875, stepSpeed: 0.375, trail: 40, rest: 22, pause: 60, slideSpeed: 2 };\nexport const LANDING_APPROACH: LandingApproach = { reach: LANDING_MARGINS.exit, keep: LANDING_MARGINS.exit, nearer: 16 };\n\n/**\n * The keys the landing model reads: the drag intent's {@link DragModifiers} less the arm key (the model has no\n * spring-loaded targets). While `floatKey` is held a lane or open space is open space and the guides hide; `on: false`\n * turns the key off. A host hands the model the same `modifiers` as its drag intent's tuning.\n */\nexport type LandingModifiers = Pick<DragModifiers, \"on\" | \"floatKey\">;\n/** The default keys: the drag intent's (`DRAG_DEFAULTS.modifiers`), Shift floats. */\nexport const LANDING_MODIFIERS: LandingModifiers = { on: DRAG_DEFAULTS.modifiers.on, floatKey: DRAG_DEFAULTS.modifiers.floatKey };\n\n/**\n * A held place of the drag: where a release now lands. A spot of a lane with the pointer (a sliding spot lands where the hand\n * holds it: the geometry says where), or the float at the pointer. A frame with none is at rest (it lands nowhere).\n */\nexport type LandingHeld =\n | { readonly kind: \"spot\"; readonly lane: string; readonly spot: string; readonly point: Point }\n | { readonly kind: \"float\"; readonly point: Point };\n\n/**\n * The drag's geometry, from the host's docking layer (`@n-uf/docking`'s `dockDrag(...)` fits it as it is): the regions\n * for hit-testing, as seen, and the one rect the model reads of a held place.\n */\nexport interface LandingGeometry {\n /** Hit-testing: the lanes (hit rects, spots' stretches, refused stretches), refused places, content, blocked, stage. */\n readonly regions: LandingRegions;\n /**\n * Where the item lands in a held place (its rect in that held place's layout), or null where it lands nowhere (a float\n * where the item doesn't float). The frame's landing, and the trail gate's: the model does no geometry of its own.\n */\n readonly landingOf: (held: LandingHeld) => Rect | null;\n /**\n * A spot's lane with its stretches cut in that spot's own layout (a panel column by halves of what it draws), or null:\n * the stretches along a held lane, and the fixed-point check. Absent: the stretches as seen. Asked once per spot until\n * the geometry changes.\n */\n readonly spotsOf?: (spot: string) => readonly LandingSpot[] | null;\n}\n\nexport interface LandingOptions extends LandingGeometry {\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 /**\n * The keys that win over the lanes (see {@link LandingModifiers}): the same `modifiers` shape as the drag intent's\n * tuning, the float key only. Default Shift floats ({@link LANDING_MODIFIERS}).\n */\n readonly modifiers?: Partial<LandingModifiers>;\n /**\n * The drag's preview, the one `previewPlan` reads: its guide level (`placeGuides`, else the mode's default,\n * `PLACE_GUIDES_DEFAULT`) is how many lanes' guides the frame names. A mode alone is `{ mode }`. Default\n * `DRAG_PREVIEW_DEFAULT` (Glide: none). The guide level has no other home: a host passes the preview here and to\n * `previewPlan`.\n */\n readonly preview?: DragPreview | PreviewMode;\n}\n\nexport type { LandingRegion };\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 /** The held place a release now lands (the screen's: what the host draws), or null at rest. */\n readonly held: LandingHeld | null;\n /** Where a release now lands: `landingOf(held)`; 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, the float key not held. */\n readonly room: boolean;\n /**\n * The lanes whose place guides show, each with the held place its guide stands for: the frame's `held` (the screen), or,\n * for the Near lane before entry (pending or approached), the held place the pointer would land there (the spot it picks\n * along it). The host's geometry draws them (`@n-uf/docking`'s `guides(frame)`).\n */\n readonly guides: readonly LandingGuideRef[];\n /** The float key (`modifiers.floatKey`, Shift by default) 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: the last frame's held place (a spot with the pointer, `home` when it lands at the item's own place;\n * the float at the pointer), or nothing. The host commits that held place's layout (`@n-uf/docking`'s `after(release)`).\n */\nexport type LandingRelease =\n | { readonly kind: \"spot\"; readonly lane: string; readonly spot: string; readonly point: Point; readonly home: boolean }\n | { readonly kind: \"float\"; readonly point: Point }\n | null;\n\nexport interface LandingModel {\n update(point: Point, time: number, keys?: DragKeys): LandingFrame;\n /**\n * What a release at `point` and `time` lands: the same answer as the last frame's `landing`. A point that differs\n * from the last `update`'s is that update's sample first (with `keys`, else the last keys), so a last jump counts.\n * That sample is no frame: `min(40, gates.pause)` ms or more after the last `update` it counts none of the time\n * between (its step is unknown, and it adds nothing to a slide), so a rest no frame drew counts for nothing: a slow\n * page docks late, never falsely. Call it with the pointer-up point and time, with no `update` of your own first.\n */\n release(point: Point, time: number, keys?: DragKeys): LandingRelease;\n /**\n * The geometry changed (a resize, a store change, a scroll): the new state's regions and readers, whole. Spots map by\n * id; a lost one goes to its lane's nearest.\n */\n setGeometry(geometry: LandingGeometry): 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 `lane` (0 on its edge or outside): measured across the lane, from its two sides parallel to\n * its axis (a rail's long sides, a bar's), and only from those that face into `stage`: a side on the stage's edge is\n * open, as deep as the pointer can go. The lane's ends along its own axis never count, wherever they lie (a rail's end\n * that meets a bar is no wall), so the depth is the same all along the lane.\n */\nfunction depthIn(lane: LandingLane, p: Point, stage: Rect): number {\n const r = lane.rect;\n if (!strictlyIn(r, p)) return 0;\n const on = (a: number, b: number): boolean => Math.abs(a - b) < 1;\n const sides =\n lane.axis === \"x\"\n ? [on(r.y, stage.y) ? Infinity : p.y - r.y, on(r.y + r.height, stage.y + stage.height) ? Infinity : r.y + r.height - p.y]\n : [on(r.x, stage.x) ? Infinity : p.x - r.x, on(r.x + r.width, stage.x + stage.width) ? Infinity : r.x + r.width - p.x];\n return Math.max(0, Math.min(...sides));\n}\nconst lerp = (a: Point, b: Point, u: number): Point => ({ x: a.x + (b.x - a.x) * u, y: a.y + (b.y - a.y) * u });\n/** Where the step from `a` (outside `r`) to `b` (inside it) crosses into `r`, as a share of the step (0 to 1). */\nfunction entryOf(r: Rect, a: Point, b: Point): number {\n const enter = (from: number, to: number, lo: number, hi: number): number => (from < lo ? (lo - from) / (to - from) : from > hi ? (hi - from) / (to - from) : 0);\n return Math.min(1, Math.max(0, enter(a.x, b.x, r.x, r.x + r.width), enter(a.y, b.y, r.y, r.y + r.height)));\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 // A share that isn't a positive number (zero, negative, NaN, an explicit undefined over the default) is the default.\n const laneShare = typeof margins.laneShare === \"number\" && margins.laneShare > 0 ? margins.laneShare : LANE_SHARE;\n const approach = { ...LANDING_APPROACH, ...options.approach };\n const modifiers = { ...LANDING_MODIFIERS, ...options.modifiers };\n const guidesLevel: PlaceGuides = guidesOf(options.preview ?? DRAG_PREVIEW_DEFAULT);\n let base = options.regions;\n let landingOf = options.landingOf;\n let spotsOf = options.spotsOf;\n const cache = new Map<string, readonly LandingSpot[] | null>();\n /**\n * `lane` with `spot` held: its stretches in that spot's own layout (`spotsOf`, asked once per spot until the geometry\n * changes), else as seen.\n */\n const heldLaneOf = (lane: LandingLane, spot: string | null): LandingLane => {\n if (!spot || !spotsOf) return lane;\n if (!cache.has(spot)) cache.set(spot, spotsOf(spot));\n const spots = cache.get(spot);\n return spots ? { ...lane, spots } : lane;\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 /** The lift is a float's: no `home` option and no spot marked home in the lanes at the lift (a docked item has one). */\n const floatLift = !options.home && !options.regions.lanes.some((l) => l.spots.some((s) => s.home));\n /** Whether a float lift has left its lift zone: once, for good (`floatZone`). */\n let floatLeft = false;\n /** Whether the held lane's hold is refused for lying far beyond it (sticky, as the lift zone is). */\n let farHeld = false;\n /**\n * The hand read faster than `gates.slideSpeed` (a fling), and hasn't settled since: until it has read slow (at most\n * `gates.stepSpeed`, or resting) for `pause` ms from `slowFrom`, no lane is entered by a slow-step gate (still,\n * over-refused).\n */\n let flung = false;\n let slowFrom: number | null = null;\n let lastStep = 0;\n /** The hand's speed (`createHandSpeed`): the one estimate every gate that asks \"fast or slow\" reads. */\n const handGap = Math.min(HAND_SPEED.gap, gates.pause);\n const hand = createHandSpeed({ gap: handGap, still: Math.min(HAND_SPEED.still, gates.rest) });\n /**\n * The sample being taken is the release's own, `handGap` ms or more after the last frame: no frame drew the time\n * between, so it counts none of it (its step is unknown, and it adds nothing to a slide).\n */\n let unseen = false;\n /** The keys the last `update` had: a release at a new point samples with them unless it names its own. */\n let lastKeys: DragKeys | undefined;\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 /** The lane pending on the last frame: it stays pending while the pointer stays inside it (`pendingIn`). */\n let lastPending: string | null = null;\n /**\n * The pending lane among `here` (the lanes the pointer is strictly inside): the one pending on the last frame while it\n * is among them, until another is deeper by `margins.spot`; else the deepest. So at a corner where two lanes overlap\n * a wobble never flips the pending lane, nor its guides.\n */\n const pendingIn = (here: readonly LandingLane[], p: Point, stage: Rect): string => {\n const deepest = here.reduce((a, b) => (depthIn(b, p, stage) > depthIn(a, p, stage) ? b : a));\n const kept = here.find((l) => l.id === lastPending);\n return kept && depthIn(deepest, p, stage) <= depthIn(kept, p, stage) + margins.spot ? kept.id : deepest.id;\n };\n let previous: LandingRegion = laneId ? \"lane\" : \"open\";\n let frame: LandingFrame = { region: previous, lane: laneId, spot: spotId, held: null, landing: null, room: !!spotId, guides: [], shift: false };\n /** The spot the last frame lands on, as its lane lists it, or null. */\n let landedOn: LandingSpot | 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 /** 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 held = heldLaneOf(lane, spotId);\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.stepSpeed && distanceTo(landingOf({ kind: \"spot\", lane: lane.id, spot: now.id, point: p }) ?? now.landing, p) <= gates.trail) return now;\n // The fixed point: with the candidate held (its room open), the pointer still picks it along the lane.\n if (spotsOf && reflows) {\n const lane2 = heldLaneOf(lane, cand.id);\n if (pick(lane2, alongOf(lane2, p))?.id !== cand.id) return now;\n }\n return cand;\n }\n\n /**\n * The lanes whose guides show, each with the held place its guide stands for. `\"near\"`: the Near lane only; `\"all\"`: every\n * lane. The Near lane held stands for the frame's held place; pending or approached, for the held place the pointer would land in\n * there (the spot it picks along it), so its guide before entry is its mark after it. Every other lane stands for the\n * frame's held place (the screen). The geometry draws them; the model does none.\n */\n function guidesFor(p: Point, region: LandingRegion, shift: boolean, pending: string | null, held: LandingHeld | null): LandingFrame[\"guides\"] {\n if (guidesLevel === \"off\" || shift) return [];\n const near = nearLane(p, region, pending, base);\n const wouldLand = (l: LandingLane): LandingHeld | null => {\n if (l.id === laneId) return held;\n const s = pick(l, alongOf(l, p));\n return s ? { kind: \"spot\", lane: l.id, spot: s.id, point: p } : held;\n };\n if (guidesLevel === \"near\") return near ? [{ lane: near.id, held: wouldLand(near) }] : [];\n // \"all\": with no Near lane, the lane nearest the pointer within `reach` stands for its would-land held place too, for the\n // corner only (it isn't made Near, pending or enterable): its guide is what entry draws, and it owns the corners it\n // meets. The switch lies exactly at `reach` of its rect.\n let owner = near;\n if (!owner) {\n let d = approach.reach;\n for (const l of base.lanes) {\n const dl = distanceTo(l.rect, p);\n if (dl <= d) {\n owner = l;\n d = dl;\n }\n }\n }\n return base.lanes.map((l) => ({ lane: l.id, held: owner && l.id === owner.id ? wouldLand(l) : held }));\n }\n\n /**\n * The lane whose guides the Near rule shows, or null: the held lane (also over its own refused stretch), else the\n * pending one, else, with the pointer in open space, the approached one (kept with hysteresis).\n */\n function nearLane(p: Point, region: LandingRegion, pending: string | null, regions: LandingRegions): LandingLane | null {\n // The held lane's, also over its own refused stretch.\n if ((region === \"lane\" || region === \"refused\") && laneId) {\n approached = laneId;\n return laneIn(regions, laneId) ?? null;\n }\n // The pending lane's: the pointer is inside it, its gate not passed (the place under it, a refused one too, is its).\n if (pending) {\n approached = pending;\n return laneIn(regions, pending) ?? null;\n }\n // Only in open space the approach counts: over a refused place outside every lane, or nowhere, no lane's guides show.\n if (region !== \"open\") {\n approached = null;\n return null;\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 // The approached lane: the nearest within reach, kept until another is clearly nearer or it is past `keep` (at least\n // `reach`: a lane acquired within reach is never dropped at once). Acquired only within `max(reach - margins.spot,\n // reach / 2)`, so a pointer wobbling at the reach's edge never blinks the guide (a band between acquiring and letting\n // go), and a small reach or wide touch margins still leave half the reach to acquire in.\n const acquire = Math.max(0, approach.reach - margins.spot, approach.reach / 2);\n const kept = laneIn(regions, approached);\n if (kept) {\n const d = distanceTo(kept.rect, p);\n if (d > Math.max(approach.keep, approach.reach)) approached = null;\n else if (best && best.id !== kept.id && bestD + approach.nearer < d) approached = bestD <= acquire ? best.id : null;\n } else approached = best && bestD <= acquire ? best.id : null;\n return laneIn(regions, approached) ?? null;\n }\n\n function update(raw: Point, t: number, keys?: DragKeys): LandingFrame {\n lastKeys = keys;\n // Past the stage by up to `edge`: on its edge. Beyond: nowhere (kept as is).\n const p = ontoStage(base.stage, raw, margins.edge) ?? raw;\n // The step: the pointer's speed as it moved (a fling past the edge isn't still) since the last point that differed,\n // px/ms. A repeated point (a host updating per frame, or a gap between sparse samples) keeps the last step until the\n // pointer has stayed put for `rest` ms after a slow step or on the stage's edge, else for `pause` ms; only then is it\n // 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 const before = moved.t;\n moved = { raw, t };\n hand.push(raw, t);\n // The step across a gap (40 ms or `pause`, the smaller) may end a rest, so it says nothing about how the hand moves\n // now: unknown, never a slow step (a fling out of a rest docks nowhere on its first frame), unless it is no longer\n // than `HAND_SPEED.slowStep` (3) px (a hand creeping a pixel at a time, which is slow). The hand's speed reads\n // across a gap the pointer moved on through (frames the host lost), so a slide through it counts on. The release's\n // own sample after a time no frame drew (`unseen`) is unknown even as a crawl: a rest no frame drew counts nothing.\n step = unseen ? Infinity : hand.step;\n lastStep = step;\n // A fling (the hand reading faster than `slideSpeed`) unsettles it; it is slow again from the last sample before it\n // reads slow (at most `stepSpeed`). A step the hand's speed can't read yet (the first after a rest) is neither.\n const sp = hand.speed;\n if (Number.isFinite(sp) && sp > gates.slideSpeed) {\n flung = true;\n slowFrom = null;\n } else if (!Number.isFinite(sp) || !Number.isFinite(step) || sp > gates.stepSpeed) slowFrom = null;\n else slowFrom ??= before;\n } else if (moved) {\n const stage = base.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.stepSpeed || onEdge)) ? 0 : lastStep;\n // The hand sees the pointer standing still: a gap it ends is a rest, whatever the pointer moves across it.\n hand.hold(t);\n // Resting: the hand has been still since its last sample.\n slowFrom ??= moved.t;\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 hand.reset();\n hand.push(raw, t);\n // (After `hide()` too, the lift point stays where the drag began.)\n liftAt ??= p;\n step = lastStep = Infinity;\n }\n // Settled again once slow for `pause` since the fling: only then do the slow-step gates (still, over-refused) count.\n // On the stage's edge a fling is taken at once, as the still gate's `rest` says: the edge is where a fling docks.\n if (flung && slowFrom !== null && t - slowFrom >= gates.pause) flung = false;\n const edgeStage = base.stage;\n const settled = !flung || p.x <= edgeStage.x || p.y <= edgeStage.y || p.x >= edgeStage.x + edgeStage.width || p.y >= edgeStage.y + edgeStage.height;\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 = modifiers.on && isHeld(keys, modifiers.floatKey);\n // A float lift (`floatLift`): within `lift` of the press no lane takes the pointer (the frame is judged as if the regions\n // had no lanes: blocked and refused places as on any frame), until the pointer first lies farther than `lift`; once\n // left it is never re-entered, so a slide back through the press point changes nothing (a held lane stays held).\n if (floatLift && liftAt && Math.hypot(p.x - liftAt.x, p.y - liftAt.y) > (margins.lift ?? 16)) floatLeft = true;\n const floatZone = floatLift && !floatLeft && !!liftAt;\n const regions = floatZone ? { ...base, lanes: [] } : base;\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 `stepSpeed` 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 while the hand reads steady and no\n // faster than `slideSpeed` (`hand`): a brisk slide along it (across it at most a third as far as along) is no\n // crossing. (The slow path counts a step at most `stepSpeed`, as the hand's speed reads it: a jittered fling never;\n // nor a step across a gap, which may end a rest, though the hand's speed reads across frames the host lost.)\n const slow = Number.isFinite(step) && (Number.isFinite(hand.speed) ? hand.speed <= gates.stepSpeed : step <= gates.stepSpeed);\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 // Only a steady hand no faster than `slideSpeed` adds to the count: a fling (or a hand gathering speed out of a rest\n // or a hesitation, or one the speed can't read yet) adds nothing and resets nothing. So a fling never counts, even\n // where its timestamps jitter, while a steady slide whose timestamps jitter keeps its count. It counts from where\n // the pointer crossed into the lane: the step that enters adds its part inside it, so a step the host lost frames\n // of across the lane's edge counts what those frames would have.\n // (Nor does the release's own sample after a time no frame drew: a crawl over it may read as frames the host lost.)\n const counts = !unseen && hand.steady && hand.speed <= gates.slideSpeed;\n const u = !was && inL && from && fromRaw ? entryOf(l.rect, from, p) : 0;\n const by =\n was ? { along: go, across: over }\n : u > 0 && from && fromRaw ? { along: Math.abs(alongOf(l, p) - alongOf(l, lerp(from, p, u))), across: Math.abs(acrossOf(l, raw) - acrossOf(l, lerp(fromRaw, raw, u))) }\n : { along: 0, across: 0 };\n slide.set(l.id, !inL ? { along: 0, across: 0 } : counts ? { along: (s?.along ?? 0) + by.along, across: (s?.across ?? 0) + by.across } : (s ?? { 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 // (The still gate, like the over-refused rule, waits for a flung hand to settle.)\n // The still gate's depth is at most `laneShare` of the lane's thickness, so a thin lane's middle third takes a rest.\n const gate = (l: LandingLane): boolean =>\n (pathIn.get(l.id) ?? 0) >= gates.path || (depthIn(l, p, regions.stage) >= intoLane(l, gates.depth, laneShare) && step <= gates.stillSpeed && settled);\n // Lane to lane: inside the lanes touching the held one, past the held lane's exit margin into them (inside it the\n // held lane holds, P1), the held lane still holds until one of those lanes' own gate passes, then that lane takes it\n // (the first such, in the regions' order). Never the float between them, never a fly-through's room. The margin\n // reaches at most `laneShare` into each of them: where the pointer is inside several (a corner), the thinnest one's\n // sets it, so the middle third of every lane is free of the held lane's hold. A lane that doesn't touch the held one\n // gets no cap: nothing would hold the pointer past it, and lane to lane never passes through the float.\n const touchingAll = held ? regions.lanes.filter((l) => l.id !== held.id && strictlyIn(l.rect, p) && touches(l.rect, held.rect)) : [];\n const exitInto = touchingAll.reduce((m, l) => intoLane(l, m, laneShare), margins.exit);\n const touchingHere = held && !inside(held.rect, p, exitInto) ? touchingAll : [];\n const touching = touchingHere[0];\n // The same cap over a place that takes nothing beside the held lane: where no touching lane lies under the pointer,\n // the hold reaches at most `laneShare` into a blocked or refused rect that touches the held lane (its thickness the\n // way the pointer reaches into it: across a bar beside the held lane, along a rect past its end; inside several,\n // the thinnest one's), so a thin bar that takes nothing (a full title bar) shows its refusal from its middle third\n // on. Open space, and a rect that doesn't touch the held lane, keep the full `exit`: the hold never passes through\n // the float.\n const holdExit =\n held && touchingAll.length === 0\n ? [...regions.blocked, ...regions.refused].filter((b) => strictlyIn(b, p) && touches(b, held.rect)).reduce((m, b) => reachInto(b, held.rect, p, m, laneShare), margins.exit)\n : margins.exit;\n // A fling (the hand's speed above `slideSpeed`) is no entry, along the lane as well as across it.\n const slid = (l: LandingLane): boolean => {\n const sl = slide.get(l.id);\n return !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along && hand.speed <= gates.slideSpeed;\n };\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 held, 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 // The lanes the pointer is inside (within the lift zone an owning lane is no lane at all), and the over-refused\n // rule: over a place that takes nothing reaching past the lane (a column's panel under an empty rail's band), in no\n // other lane, a lane is entered on a slow step only (a fly-through opens no room). Entering reads it, and so does a\n // touching lane's takeover: a held lane never pre-empts it.\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 const overRefused = (l: LandingLane): boolean =>\n Number.isFinite(step) && step <= gates.stepSpeed && settled && lanesHere.length === 1 && [...regions.blocked, ...regions.refused].some((b) => strictlyIn(b, p) && !within(b, l));\n const next = homeHere ? undefined : (owner ?? touchingHere.find((l) => gate(l) || slid(l) || overRefused(l)));\n // (The far refusal belongs to the held lane's hold: any other branch lets it go.)\n if (!(held && !homeHere && !next && (touching || inside(held.rect, p, holdExit)))) farHeld = false;\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, holdExit))) {\n // The hold through a touching lane is for crossing a corner: more than `exit + path` from the held lane's rect\n // (a fling up a rail that didn't enter it), the frame is held but refused: the lane kept (its guides stay), no\n // spot, no landing, nothing pending, so the host shows its tag and a release goes home. Sticky, like the lift\n // zone: set past `exit + path`, cleared only within `exit + path - spot`, so a wobble at its edge never flips it.\n const d = distanceTo(held.rect, p);\n farHeld = farHeld ? d > margins.exit + gates.path - margins.spot : d > margins.exit + gates.path;\n const far = farHeld;\n const s = far ? null : 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 && !far && !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 = pendingIn(others, p, regions.stage);\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 let entered: LandingLane | null = next ?? null;\n if (!entered)\n for (const l of lanesHere) {\n const deep = depthIn(l, p, regions.stage);\n if ((gate(l) || overRefused(l)) && (!entered || deep > depthIn(entered, 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 = pendingIn(lanesHere, p, regions.stage);\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 // (A zone frame inside a real lane leaves `previous` as it was: the zone's lane-less verdict is not carried past it.)\n previous = floatZone && base.lanes.some((l) => strictlyIn(l.rect, p)) ? previous : region;\n lastPending = pending;\n const shown: LandingRegion = shift && (region === \"lane\" || region === \"open\") ? \"open\" : region;\n const lane0 = laneIn(base, laneId);\n const heldLane = lane0 ? heldLaneOf(lane0, spotId) : undefined;\n const spot = spotIn(heldLane, spotId);\n landedOn = shown === \"lane\" && spot ? spot : null;\n // The held place a release lands now, and where it lands: the geometry's (a sliding spot's landing follows the hand).\n const held: LandingHeld | null = shown === \"lane\" ? (spot && laneId ? { kind: \"spot\", lane: laneId, spot: spot.id, point: p } : null) : shown === \"open\" ? { kind: \"float\", point: p } : null;\n const landing = held ? landingOf(held) : null;\n frame = {\n region: shown,\n lane: laneId,\n spot: shown === \"lane\" ? spotId : null,\n held: held && (held.kind === \"spot\" || landing) ? held : null,\n landing,\n room: shown === \"lane\" && !!spot,\n guides: guidesFor(p, shown, shift, pending && shown !== \"lane\" ? pending : null, held && (held.kind === \"spot\" || landing) ? held : null),\n shift,\n ...(pending && shown !== \"lane\" ? { pending } : {}),\n };\n return frame;\n }\n\n return {\n update,\n release(point: Point, time: number, keys?: DragKeys): LandingRelease {\n // The last update's sample is the release's: a point that differs from it is one more sample first. That sample is\n // no frame: `handGap` ms or more after the last one, the time between counts nothing (a slow page docks late, on\n // the next frame it draws, never on a rest no frame drew).\n if (!last || last.raw.x !== point.x || last.raw.y !== point.y) {\n unseen = !!last && time - last.t >= handGap;\n try {\n update(point, time, keys ?? lastKeys);\n } finally {\n unseen = false;\n }\n }\n const s = frame.held;\n if (s?.kind === \"spot\" && frame.region === \"lane\") {\n // Home only at the item's own place: its own spot, landing where it lies (a sliding spot anywhere else on its\n // stretch moves it).\n const ownSpot = !!options.home && options.home.spot === s.spot && options.home.lane === s.lane;\n const at = frame.landing;\n const home = ownSpot && !!landedOn && !!at && Math.max(Math.abs(at.x - landedOn.landing.x), Math.abs(at.y - landedOn.landing.y), Math.abs(at.width - landedOn.landing.width), Math.abs(at.height - landedOn.landing.height)) < 1e-6;\n return { kind: \"spot\", lane: s.lane, spot: s.spot, point: s.point, home };\n }\n if (s?.kind === \"float\" && frame.region === \"open\" && frame.landing) return { kind: \"float\", point: s.point };\n return null;\n },\n setGeometry(geometry: LandingGeometry): void {\n base = geometry.regions;\n landingOf = geometry.landingOf;\n spotsOf = geometry.spotsOf;\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 lastPending = null;\n farHeld = false;\n flung = false;\n slowFrom = 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 { 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 lane's marks, as a host's geometry draws a frame's guides). */\nexport interface PlacedGuide {\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n /**\n * The axis of the lane the guide marks, when the guide knows it. It only decides a box that is no longer than it is\n * thick (a square): its long side is its axis, and a square has none, so `axis` (default `\"x\"`) says.\n */\n readonly axis?: \"x\" | \"y\";\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. A box a clear rect thinned is held to it too. */\n readonly minThickness?: number;\n /**\n * The thickness a `line` guide is drawn at, px (default 2). A line thinner than this (docking gives the line\n * between two docked panels zero thickness) is widened to it, centered on its own position, before the inset, the\n * clear rects and `minThickness` apply; a line at least this thick is unchanged. Only lines are widened. `0` turns\n * the widening off: a line keeps the thickness it has, and a zero-thick one is dropped by `minThickness`.\n */\n readonly lineThickness?: number;\n /**\n * The least length, along the box's axis, a part of a box that a clear rect cut keeps, px (default 8,\n * `MIN_BOX_LENGTH`); shorter, that part is not drawn. Corner-cut parts included; a box nothing touches is kept as is.\n */\n readonly minLength?: number;\n}\n\n/** The least length, px, a box part a clear rect cut keeps (`minLength`'s default). */\nexport const MIN_BOX_LENGTH = 8;\n/** The thickness, px, a thinner line is drawn at, centered on its place (`lineThickness`'s default). */\nconst LINE_THICKNESS = 2;\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, then each clear rect, grown by its clearance, is\n * taken out of it, by one model:\n *\n * - One axis per box: its long side, decided once from the box clipped to `inside`, before any clear rect is applied\n * (a square takes the guide's `axis`, else x). Cutting a box never turns its axis.\n * - Thinning comes first. A clear rect over only part of the thickness that reaches one side of the box thins it when\n * its overlap across the box is smaller than its overlap along it: the box loses that thickness from that side and no\n * length (a neighbor poking 2 px into a bar costs 2 px of thickness, not its whole length in the bar's length). The\n * deepest intrusion from each side wins, whatever the order. Only a shallow intrusion thins, at most half the box's\n * thickness. A box thinned below `minThickness` is dropped. A rect that pokes in deeper than half the thickness (the\n * held outline flush with one side), as deep as it is long, or touches neither side, is a corner (below).\n * - A clear rect across the box's whole thickness (of the thinned box) is an interval along the axis, and the box less all of them is a\n * 1-D interval subtraction: inside the box (the held item's outline sliding inside its room) both sides stay, over\n * one end the other side. The result does not depend on the order of the clear rects.\n * - A clear rect over only part of the thickness (a corner) then cuts each part on the side that faces it, the\n * largest part kept (no L-shapes). Corners are applied by their distance along the axis (start, then end, then\n * across), whatever the input order, so the result is the same for any order.\n * - `minLength` (default 8, `MIN_BOX_LENGTH`) is applied once at the end, along the axis, to every part a clear rect\n * cut, corner-cut ones included. A part nothing touched is the clipped box and is kept at any length.\n * - Ids follow the side, not the rank: a part keeps the guide's `id` when no interior cut lies before it along the\n * axis, and gets `<id>#<k + 1>` when k of them do. A cut is a full-thickness clear interval strictly inside the box\n * (box length on both sides of it); overlapping or touching ones count as one, and one that touches or overlaps the\n * box's start or end only trims the box, it is no cut (a neighbor flush with the box's start, grown by its clearance,\n * leaves the part before a held rect as `<id>`). The part before a cut is always `<id>`, the part after one cut\n * always `<id>#2`, whether or not the part before survives, so a host keys each part by its id as a held item slides.\n * The exception: while the held rect overlaps the box's start (or end) it only trims the box, so the part left is\n * `<id>`, and it becomes `<id>#2` once the held rect lies strictly inside the box. A guide's own `id` must not end in `#` and digits\n * (`b#2` would collide with the second part of `b`), and an `id` that is not a string is not suffixed (a split\n * box's parts then share it: unsupported). Parts come back in order along the axis.\n *\n * A line thinner than `lineThickness` (default 2 px; a zero-thick line is a place between two things, a joint) is first\n * widened to it, centered on its own position, so the inset, the clear rects and `minThickness` below see a line of that\n * thickness; `lineThickness: 0` leaves lines as given. 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. A clear rect over its thickness that meets only one end of its length (it covers the\n * guide's start or its end, not both) shortens it, as it trims a box: the guide keeps the part away from the rect, at\n * least `minLength` long, else it is left out; a toolbar over the last 10 px of a column's line costs 10 px of length\n * (and the clearance), not the line. Then it is thinned, from the content side, to stay that far clear of the rects\n * over its middle (or over all of its length), so a thin strip at the window's side lies between the inset and the\n * content, the same on both sides. A guide with nothing left (or a thin one under `minThickness`) is left out. A clear rect whose x, y, width or height isn't finite is ignored. 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 const lineThickness = Number.isFinite(options.lineThickness) ? Math.max(0, options.lineThickness!) : LINE_THICKNESS;\n const minLength = Number.isFinite(options.minLength) ? Math.max(0, options.minLength!) : MIN_BOX_LENGTH;\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. One whose x, y, width or height\n // isn't finite is ignored (it would take every box out and give thin guides non-finite fields).\n const finite = (r: Rect): boolean => Number.isFinite(r.x) && Number.isFinite(r.y) && Number.isFinite(r.width) && Number.isFinite(r.height);\n const allClear = (options.clear ?? [])\n .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 .filter((c) => finite(c.k));\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 type Box = { a: number; b: number; c: number; d: number };\n // The box clipped to `inside`. Its axis is its long side, decided here once (a square: the guide's `axis`, else\n // x), before any clear rect is applied, so cutting it never turns the axis.\n const box: Box = { a: Math.max(r.x, x0), b: Math.max(r.y, y0), c: Math.min(r.x + r.width, x1), d: Math.min(r.y + r.height, y1) };\n // Written as \"not more than\" so a non-finite box (NaN in its rect or in `inside`) is left out, never drawn as NaN.\n if (!(box.c - box.a > EPS) || !(box.d - box.b > EPS)) continue;\n const w = box.c - box.a;\n const h = box.d - box.b;\n const alongX = w > h || (w === h && (g as { axis?: unknown }).axis !== \"y\");\n // Axis coordinates: `s` along the box, `t` across it.\n const s0 = alongX ? box.a : box.b;\n const s1 = alongX ? box.c : box.d;\n const t0 = alongX ? box.b : box.a;\n const t1 = alongX ? box.d : box.c;\n const toBox = (p0: number, p1: number, q0: number, q1: number): Box => (alongX ? { a: p0, b: q0, c: p1, d: q1 } : { a: q0, b: p0, c: q1, d: p1 });\n // Each clear rect, grown by its clearance, that lies over the box.\n const over = clear\n .map(({ k, gap }) => ({\n x0: k.x - gap,\n x1: k.x + k.width + gap,\n y0: k.y - gap,\n y1: k.y + k.height + gap,\n s0: (alongX ? k.x : k.y) - gap,\n s1: (alongX ? k.x + k.width : k.y + k.height) + gap,\n t0: (alongX ? k.y : k.x) - gap,\n t1: (alongX ? k.y + k.height : k.x + k.width) + gap,\n }))\n .filter((k) => k.s1 > s0 + EPS && k.s0 < s1 - EPS && k.t1 > t0 + EPS && k.t0 < t1 - EPS);\n // First, thinning: a clear rect over only part of the thickness, reaching one side of the box, whose overlap across\n // is smaller than its overlap along the box, thins the box from that side by that overlap, no length lost. The\n // deepest intrusion from each side wins, so the order of the clear rects never matters. Only a shallow one thins, at\n // most half the box's thickness: a deeper one (the held outline flush with one side) is a corner, so the box never\n // shrinks to a sliver beside it.\n let v0 = t0;\n let v1 = t1;\n const half = (t1 - t0) / 2 + EPS;\n for (const k of over) {\n if (k.t0 <= t0 + EPS && k.t1 >= t1 - EPS) continue;\n const along = Math.min(k.s1, s1) - Math.max(k.s0, s0);\n if (k.t0 <= t0 + EPS) {\n if (k.t1 - t0 < along - EPS && k.t1 - t0 <= half) v0 = Math.max(v0, k.t1);\n } else if (k.t1 >= t1 - EPS) {\n if (t1 - k.t0 < along - EPS && t1 - k.t0 <= half) v1 = Math.min(v1, k.t0);\n }\n }\n // A box thinned below `minThickness` is dropped, as a thin guide is.\n if ((v0 > t0 || v1 < t1) && v1 - v0 < Math.max(EPS, min)) continue;\n // What is left to cut is judged against the thinned box: a thinning rect no longer overlaps it.\n const rest = over.filter((k) => k.t1 > v0 + EPS && k.t0 < v1 - EPS);\n const kept = toBox(s0, s1, v0, v1);\n // Across the box's whole thickness: interval subtraction along the axis (order does not matter). The cut\n // intervals, merged, split the box into parts; a part's `k` is how many intervals lie before it.\n const full = rest\n .filter((k) => k.t0 <= v0 + EPS && k.t1 >= v1 - EPS)\n .map((k): [number, number] => [Math.max(k.s0, s0), Math.min(k.s1, s1)])\n .sort((p, q) => p[0] - q[0] || p[1] - q[1]);\n const cuts: [number, number][] = [];\n for (const [lo, hi] of full) {\n const last = cuts[cuts.length - 1];\n if (last && lo <= last[1] + EPS) last[1] = Math.max(last[1], hi);\n else cuts.push([lo, hi]);\n }\n // A part's `k` counts the interior cuts before it: a cut that touches or overlaps the box's start or end trims the\n // box, it is no cut (so a neighbor flush with the box's start never renames the part before a held rect).\n const spans: { lo: number; hi: number; k: number }[] = [];\n let at = s0;\n let k = 0;\n for (const [lo, hi] of cuts) {\n if (lo - at > EPS) spans.push({ lo: at, hi: lo, k });\n if (lo > s0 + EPS && hi < s1 - EPS) k++;\n at = hi;\n }\n if (s1 - at > EPS) spans.push({ lo: at, hi: s1, k });\n // Over only part of the thickness (a corner): cut on the side that faces it, the largest part kept (no L-shapes),\n // each corner rect in turn by its distance along the axis, so the result never depends on the input order.\n const corners = rest\n .filter((k) => !(k.t0 <= v0 + EPS && k.t1 >= v1 - EPS))\n .sort((p, q) => p.s0 - q.s0 || p.s1 - q.s1 || p.t0 - q.t0 || p.t1 - q.t1);\n const longEnough = Math.max(EPS, minLength - EPS);\n for (const span of spans) {\n let p: Box | null = toBox(span.lo, span.hi, v0, v1);\n for (const k of corners) {\n const { a, b, c, d } = p;\n if (k.x1 <= a + EPS || k.x0 >= c - EPS || k.y1 <= b + EPS || k.y0 >= d - EPS) continue;\n const cut: Box[] = [\n { a, b, c: Math.min(c, k.x0), d },\n { a: Math.max(a, k.x1), b, c, d },\n { a, b, c, d: Math.min(d, k.y0) },\n { a, b: Math.max(b, k.y1), c, d },\n ].filter((q) => q.c - q.a > EPS && q.d - q.b > EPS);\n p = cut.length === 0 ? null : cut.reduce((q, s) => ((s.c - s.a) * (s.d - s.b) > (q.c - q.a) * (q.d - q.b) ? s : q));\n if (!p) break;\n }\n if (!p) continue;\n // A part a clear rect cut keeps `minLength` along the axis; a part nothing cut is the clipped box (thinned or not).\n const touched = Math.abs(p.a - kept.a) > EPS || Math.abs(p.b - kept.b) > EPS || Math.abs(p.c - kept.c) > EPS || Math.abs(p.d - kept.d) > EPS;\n if (touched && (alongX ? p.c - p.a : p.d - p.b) < longEnough) continue;\n const placed = place(g, { x: p.a, y: p.b, width: p.c - p.a, height: p.d - p.b });\n // The side names the part: `<id>` before any full-thickness cut, `<id>#<k + 1>` after k of them.\n const id = (g as { id?: unknown }).id;\n out.push(span.k === 0 || typeof id !== \"string\" ? placed : ({ ...placed, id: `${id}#${span.k + 1}` } as G));\n }\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 // A line thinner than `lineThickness` is widened to it, centered on its own position, before anything else is\n // applied (a non-finite thickness is left as is: it is dropped below).\n const own = thinX ? r.width : r.height;\n const widen = g.kind === \"line\" && own < lineThickness;\n // Along its thickness: moved inside whole; along its length: clipped.\n const t = widen ? lineThickness : own;\n let lo = (thinX ? r.x : r.y) - (widen ? (lineThickness - own) / 2 : 0);\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 l0 = Math.max(thinX ? r.y : r.x, thinX ? y0 : x0);\n const l1 = Math.min(thinX ? r.y + r.height : r.x + r.width, thinX ? y1 : x1);\n if (l1 - l0 <= EPS) continue;\n // Each clear rect, grown by its clearance: its extent along the guide's length (a, b) and across its thickness (c0, c1).\n const around = clear.map(({ k: c, gap }) => ({\n a: (thinX ? c.y : c.x) - gap,\n b: (thinX ? c.y + c.height : c.x + c.width) + gap,\n c0: (thinX ? c.x : c.y) - gap,\n c1: (thinX ? c.x + c.width : c.y + c.height) + gap,\n }));\n // A rect over the thickness that meets only one end of the length (its start or its end, not both, not the middle)\n // shortens the guide, as it trims a box: the guide keeps the part away from it. The ends are the clipped guide's, so\n // the order of the rects never matters.\n let s0 = l0;\n let s1 = l1;\n let shortened = false;\n for (const k of around) {\n if (k.b <= l0 + EPS || k.a >= l1 - EPS || k.c1 <= lo + EPS || k.c0 >= hi - EPS) continue;\n const atStart = k.a <= l0 + EPS;\n const atEnd = k.b >= l1 - EPS;\n if (atStart === atEnd) continue;\n if (atStart) s0 = Math.max(s0, k.b);\n else s1 = Math.min(s1, k.a);\n shortened = true;\n }\n // What is left of the length keeps `minLength`, as a part of a box a clear rect cut does.\n if (s1 - s0 <= EPS || (shortened && s1 - s0 < Math.max(EPS, minLength - EPS))) continue;\n // A rect over the middle of the length (or all of it) cuts across the thickness, from the side it lies on, where it\n // still lies over what is left.\n for (const k of around) {\n if (k.b <= s0 + EPS || k.a >= s1 - EPS || k.c1 <= lo + EPS || k.c0 >= hi - EPS) continue;\n if ((k.a <= l0 + EPS) !== (k.b >= l1 - EPS)) continue;\n // Keep the side away from the clear rect's middle.\n if ((k.c0 + k.c1) / 2 >= (lo + hi) / 2) hi = Math.min(hi, k.c0);\n else lo = Math.max(lo, k.c1);\n }\n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I,EAAE,KAAK,KAAK,OAAO,EAAE,KAAK,KAAK,OAAO,EAAE,MAAM,KAAK,OAAO,EAAE,MAAM,KAAK,IAAK;AAChF,UAAK,EAAE,KAAK,KAAK,QAAU,EAAE,KAAK,KAAK,IAAM;AAE7C,WAAK,EAAE,KAAK,EAAE,MAAM,MAAM,KAAK,MAAM,EAAG,MAAK,KAAK,IAAI,IAAI,EAAE,EAAE;AAAA,UACzD,MAAK,KAAK,IAAI,IAAI,EAAE,EAAE;AAAA,IAC7B;AACA,QAAI,KAAK,KAAK,KAAK,IAAI,KAAK,GAAG,EAAG;AAClC,QAAI,KAAK,MAAM,GAAG,QAAQ,EAAE,GAAG,IAAI,GAAG,IAAI,OAAO,KAAK,IAAI,QAAQ,KAAK,GAAG,IAAI,EAAE,GAAG,IAAI,GAAG,IAAI,OAAO,KAAK,IAAI,QAAQ,KAAK,GAAG,CAAC,CAAC;AAAA,EAClI;AACA,SAAO;AACT;","names":["distanceTo","held","within","s0","s1","k","gap","lo","hi"]}
1
+ {"version":3,"sources":["../src/drag/hand-speed.ts","../src/drag/intent.ts","../src/drag/preview.ts","../src/drag/landing.ts","../src/drag/grip.ts","../src/drag/guide-rects.ts"],"sourcesContent":["import { SAME_SAMPLE, sampleOrder } from \"../samples\";\nimport type { Point } from \"../shapes\";\n\n/**\n * The hand's speed, the one estimate a landing model's gates read when they ask \"fast or slow\": the slide count into a\n * touching lane, its entry (`slid`), the settle rule after a fling and the slow-path gate. Speeds are px/ms, as a landing\n * model's gates are.\n *\n * It is read over time, from the distinct samples since the hand last started:\n * - `step`, the newest step alone: a speed-up reads at once.\n * - `long`, over the newest samples that span at least `span` ms and `steps` steps. A speed's error comes from the\n * timestamps at its two ends, a share of a frame each, so the span holds several frames: a fling whose timestamps\n * jitter never reads slow over it. Unknown (null) until the samples since the hand started span that much.\n * - `speed`, the larger of the two (`long` unknown: `step`), so a speed-up reads at once and a slow-down only once it has\n * lasted the span.\n * - `steady`, a slide's evidence: `long` known, and the newest step not faster than `accelerating` times it, so a hand\n * gathering speed out of a hesitation or a rest is no slide yet.\n *\n * A gap of `gap` ms or more between two samples is a rest or a stroke the host lost samples of, and the hand tells them\n * apart by what it saw (decision record 0014):\n * - **A rest** starts the hand again: the samples before it never count. It is a rest when the pointer was seen standing\n * still for `still` ms of it (`hold`: a host that updates per frame reports a rest as it happens), or when the pointer\n * moved across it less than `carry` times the hand's speed so far (a host that sends nothing while the pointer rests),\n * or when the hand has no speed yet.\n * - **A lost stretch** (the pointer moved across it at about the hand's speed: frames the host dropped) carries the hand\n * on: the lost frames are filled in on a straight line at the gap's mean speed, so `long`, `speed` and `steady` read as\n * if they had come. A shorter interval of `fill` frames or more is filled in the same way.\n *\n * Either way the gap's own `step` is unknown (Infinity) unless it is no longer than `slowStep` px (a hand creeping a\n * pixel at a time, which reads slow): a gap may end a rest, so it is never a slow step, and a rest is never averaged into\n * the next fling. Across a lost stretch `speed` and `steady` read its mean, so a slide through it counts on.\n *\n * A sample under `SAME_SAMPLE` (1 ms) past the newest one the hand holds is the same sample (a release read a fraction\n * of a millisecond after the last frame): it is left out, so `step`, `long`, `speed` and `steady` read as they did\n * before it (the pointer's rest seen so far included), instead of reading its few pixels over so short a time as a slow\n * step. In a run of such samples (a host sampling above 1 kHz) the first one that lies 1 ms or more past the newest held\n * is a sample, read over its whole interval from it. A sample whose time lies before the newest held's (an event's time\n * against a frame's; times are expected never to go back) is left out in the same way, however far behind it lies. Two\n * of them, both `gap` ms or more behind, the second stamped `still` ms (at least 1 ms) or more later than the first,\n * with no in-order sample 1 ms or more past the newest held and no repeated frame (`hold`) between (a sample under 1 ms\n * past it is the same sample and ends nothing), are a clock that stepped back: the hand starts again from the second,\n * its step unknown. Known and accepted: two stale samples that far behind and that far apart restart the hand though\n * the clock did not step; a clock that stepped back by up to `gap` + `still` ms and one sample goes on by itself, its\n * first interval read short.\n *\n * Internal to the landing model (not exported from `./drag`).\n */\nexport interface HandSpeed {\n /** A distinct sample of the pointer at `t` ms. */\n push(p: Point, t: number): void;\n /** The pointer seen where its last sample was, at `t` ms (a repeated sample): standing still since. */\n hold(t: number): void;\n /** Forget every sample: the next one starts the hand. */\n reset(): void;\n readonly step: number;\n readonly long: number | null;\n readonly speed: number;\n readonly steady: boolean;\n}\n\n/** The crawl threshold: the longest step over a gap that still reads slow, a length in px (not a speed). */\nconst HAND_SLOW_STEP = 3;\n\nexport interface HandSpeedOptions {\n /** How long the samples `long` reads must span, ms. */\n readonly span: number;\n /** How many steps they must hold, at least. */\n readonly steps: number;\n /** A gap between two samples this long or longer is a rest or a lost stretch, ms. */\n readonly gap: number;\n /**\n * The longest step over a gap that still reads as the speed it is, px (`HAND_SLOW_STEP`, 3 by default; a length, not\n * a speed, so a landing model's `gates.stepSpeed` does not set it): a hand creeping a pixel or two at a time reads\n * slow; a longer step over a gap (a fling out of a rest) is unknown.\n */\n readonly slowStep: number;\n /** How long the pointer seen standing still makes a gap a rest, whatever it moved across it, ms. */\n readonly still: number;\n /**\n * The least share of the hand's speed so far the pointer must move at across a gap for the gap to be a lost stretch\n * rather than a rest.\n */\n readonly carry: number;\n /** An interval this many frames long or longer (a frame: the longest interval of the samples held) is filled in. */\n readonly fill: number;\n /** How much faster than `long` the newest step may be and the hand still be steady (a slide). */\n readonly accelerating: number;\n /** How much faster `long` may read than half a span before and the hand still be steady (not gathering speed). */\n readonly gathering: number;\n}\n\n/**\n * The defaults: at least 48 ms and 5 steps (48 ms at 125 Hz, 80 ms at 60 Hz), so a fling at 2.4 px/ms whose timestamps\n * are off by up to half a frame at 125 Hz, or a third at 60 Hz, still reads above 2 px/ms; a gap of 40 ms (more than\n * two 60 Hz frames with their timestamps half a frame off; a landing model takes the smaller of it and its `pause`); a\n * rest seen for 20 ms (more than a 60 Hz frame, so the repeated sample a host sends within the frame of a move is no\n * rest); a lost stretch at half the hand's speed or more (a rest of 40 ms or more ends with one frame's step, a third of\n * the gap at most, so a hand resuming at its speed reads as resting); filled from two and a half frames (a frame whose\n * timestamps are off by half a frame lasts two at most, so jitter alone is never filled); steady up to 1.5 times.\n */\nexport const HAND_SPEED: HandSpeedOptions = { span: 48, steps: 5, gap: 40, slowStep: HAND_SLOW_STEP, still: 20, carry: 0.5, fill: 2.5, accelerating: 1.5, gathering: 1.25 };\n\n/** The most frames a lost stretch is filled with: the newest ones (more than the span and a half reads). */\nconst FILL_MAX = 32;\n\nexport function createHandSpeed(options: Partial<HandSpeedOptions> = {}): HandSpeed {\n const o = { ...HAND_SPEED, ...options };\n let samples: { p: Point; t: number }[] = [];\n /** The newest step as `speed` and `steady` read it: across a lost stretch, its mean. */\n let newest = Infinity;\n /** The newest step as `step` reads it: across a gap, unknown unless a crawl. */\n let step = Infinity;\n let long: number | null = null;\n /** `long` as it read at the samples of the last span, oldest first. */\n let longs: { t: number; v: number }[] = [];\n /** When the pointer was last seen standing still at the newest sample (`hold`), or null. */\n let heldTo: number | null = null;\n /** The earliest time of the run of samples `gap` ms or more before the newest held that is going on, or null. */\n let behind: number | null = null;\n const dist = (a: Point, b: Point): number => Math.hypot(b.x - a.x, b.y - a.y);\n /** The path over the samples held. */\n const path = (): number => {\n let sum = 0;\n for (let i = 1; i < samples.length; i++) sum += dist(samples[i - 1]!.p, samples[i]!.p);\n return sum;\n };\n /** The hand's speed so far: `long`, else over the samples held (two at least), else null. */\n const sofar = (): number | null => {\n if (long !== null) return long;\n const first = samples[0]!;\n const lastT = samples[samples.length - 1]!.t;\n return samples.length > 1 && lastT > first.t ? path() / (lastT - first.t) : null;\n };\n /** One sample into the window (a real one, or a lost frame filled in). */\n const add = (p: Point, t: number): void => {\n const last = samples[samples.length - 1];\n if (!last) newest = step = Infinity;\n else {\n const d = dist(last.p, p);\n newest = step = d / (t - last.t);\n }\n samples.push({ p, t });\n // Keep the newest samples that span the window, and no more.\n while (samples.length > o.steps + 1 && t - samples[1]!.t >= o.span) samples.shift();\n const first = samples[0]!;\n if (samples.length > o.steps && t - first.t >= o.span) {\n long = path() / (t - first.t);\n longs.push({ t, v: long });\n while (longs.length > 1 && t - longs[1]!.t >= o.span / 2) longs.shift();\n } else long = null;\n };\n return {\n push(p, t) {\n const last = samples[samples.length - 1];\n const seenStill = !!last && heldTo !== null && heldTo - last.t >= o.still;\n if (!last) {\n heldTo = behind = null;\n add(p, t);\n return;\n }\n const dt = t - last.t;\n // The same sample: nothing about the hand changes, the pointer's rest seen so far included (a release read under a\n // millisecond after the last frame never reads slow, and a run of such samples is read from the first one a\n // millisecond or more past the newest held). One that lies before the newest held (an event's time against a\n // frame's) is left out the same way, however far behind it lies: one late stamp is no clock step. Only two of\n // them, both `gap` ms or more behind (the first noted in `behind`) and `still` ms or more apart, with no in-order\n // sample or repeated frame between, are a clock that stepped back, and the hand starts again from the second. The\n // two lie at least `SAME_SAMPLE` apart whatever `still` is: stamps closer than that are one sample. A sample under\n // it past the newest held is left out, and a run of them is read from the first one that lies this far past the\n // newest sample held, over the whole interval (`sampleOrder`, shared with the release velocity).\n if (sampleOrder(last.t, t) !== \"next\") {\n if (dt > -Math.max(o.gap, SAME_SAMPLE)) return;\n if (behind === null || t < behind) behind = t;\n if (t - behind < Math.max(o.still, SAME_SAMPLE)) return;\n heldTo = behind = null;\n samples = [{ p, t }];\n newest = step = Infinity;\n long = null;\n longs = [];\n return;\n }\n heldTo = behind = null;\n const d = dist(last.p, p);\n // The gap's own step: it may end a rest, so it is unknown unless it is a crawl.\n const across = d <= o.slowStep ? d / dt : Infinity;\n if (dt >= o.gap) {\n const v = sofar();\n if (seenStill || v === null || d / dt < v * o.carry) {\n // A rest: the hand starts again here.\n samples = [{ p, t }];\n newest = step = across;\n long = null;\n longs = [];\n return;\n }\n }\n // A lost stretch, or an interval of `fill` frames or more the pointer didn't rest in: the frames the host lost,\n // filled in on a straight line at the mean speed across it. A frame is the longest interval held, so a jittered\n // frame never fills in more frames than were lost: the span `long` reads still holds `steps` frames of real time,\n // and a fling whose timestamps jitter still never reads slow across it.\n let frame = 1;\n for (let i = 1; i < samples.length; i++) frame = Math.max(frame, samples[i]!.t - samples[i - 1]!.t);\n if (!seenStill && samples.length > 1 && (dt >= o.gap || dt >= o.fill * frame)) {\n const n = Math.floor(dt / frame);\n for (let i = Math.max(1, n - FILL_MAX); i < n; i++) add({ x: last.p.x + ((p.x - last.p.x) * i) / n, y: last.p.y + ((p.y - last.p.y) * i) / n }, last.t + (dt * i) / n);\n }\n add(p, t);\n if (dt >= o.gap) step = across;\n },\n hold(t) {\n const last = samples[samples.length - 1];\n // A repeated frame in order ends a run of stale samples, as a sample in order does.\n if (last && t > last.t) {\n heldTo = t;\n behind = null;\n }\n },\n reset() {\n samples = [];\n newest = step = Infinity;\n long = null;\n longs = [];\n heldTo = behind = null;\n },\n get step() {\n return step;\n },\n get long() {\n return long;\n },\n get speed() {\n return long === null ? newest : Math.max(newest, long);\n },\n get steady() {\n // Known for half a span, not faster now than then by more than `gathering`, and the newest step in line with it.\n const then = longs[0];\n return long !== null && newest <= long * o.accelerating && !!then && longs[longs.length - 1]!.t - then.t >= o.span / 2 && long <= then.v * o.gathering;\n },\n };\n}\n","import { isHeld, type ModifierKey, type Modifiers } from \"../keys\";\nimport type { Point, Rect } from \"../shapes\";\nimport { HAND_SPEED } from \"./hand-speed\";\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 grip under a strip at the\n * window's edge) must leave it and come back before it can arm; entering from over home counts.\n */\n readonly armAfter: 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 grip at the window's\n * edge). 16 px is about a grip's size. Elsewhere, home under a strip included, arming works as before, and the arm key\n * forces the nearest spring-loaded target 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 * The modifier keys held on a sample (a pointer event's `shiftKey`, `altKey`, `ctrlKey`, `metaKey`): the recognizer's\n * {@link Modifiers}, any field left out not held.\n */\nexport type DragKeys = Partial<Modifiers>;\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 `armKey` is held it goes to the nearest spring-loaded target (marked `arm`), armed, without reaching it.\n * `floatKey` wins when both are held. `on: false` turns both off.\n */\nexport interface DragModifiers {\n readonly on: boolean;\n readonly floatKey: ModifierKey;\n readonly armKey: 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 spring-loaded target. Alt is left free: a host\n * keeps it for a meaning of its own, 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 armAfter: 200,\n liftZone: 16,\n modifiers: { on: true, floatKey: \"shift\", armKey: \"mod\" },\n};\n\n/**\n * A drop target: plain data. The spring-loading and room fields (`arm`, `armedHit`, `opensRoom`, `roomHold`, `roomHit`) are\n * the intent's own: they are read here, and `@n-uf/docking`'s `DockDrop` sets them (`@n-uf/placement`'s `Target` has none\n * of them). `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 `armAfter`; 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 clamped onto the window's edge\n * picks a gap whose hit reaches the edge, else nothing (a held target keeps its band), and never a refusal or the\n * float. Give the intent the window's stage as {@link DragIntentOptions.bounds} and it clamps every sample exactly\n * onto that edge (`x + width`, `y + height`) itself.\n *\n * `opensRoom: true` marks a target whose indicator would lie over what its room moves (a drop at an edge that pushes\n * its neighbor aside). Showing it and making its room are then one decision: it shows only once it has held\n * `roomAfter` ms, and the frame that first shows it already has `room`. A sweep across it moves nothing, as for any\n * target, and no frame draws it over what moves. Until it shows, a release still lands on it. An armed spring-loaded\n * target has its room at once too: its dwell was the decision. `roomHold` is how long this target holds before that\n * decision, in ms, in place of `roomAfter` (a target against the window's edge, which a pointer rarely crosses on its\n * way elsewhere, can wait less). A host that draws only a marker and doesn't use `previewPlan`'s room opens the room\n * on `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 * edge 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. This is the one export of the rank: `@n-uf/docking`'s reference host (which doesn't\n * import motion) keeps a private copy of the same value, and a test holds the two equal.\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. Home holds wherever it lies.\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 `\"armed\"` (the arm key: the nearest\n * spring-loaded target, armed), else null. The float key chooses the float over the other targets, not over a refusal\n * or outside the window: there it is still `\"float\"` (the key is held), but nothing shows, a release lands nowhere,\n * and over a refusal `refused` says which.\n */\n readonly forced: \"float\" | \"armed\" | 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 * What a release at this frame's point lands on, by the one check `release` makes, or null (nowhere, or the item\n * goes home). A host draws the landing from it, so what it draws and what a release lands on never disagree.\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 /**\n * Where the item was lifted from: the indicator stays off until the pointer leaves it, and a release there does\n * nothing. Absent: no home (the pointer has left it from the first sample, and a release anywhere lands on what is\n * under it), for a host whose targets hold the item's own place themselves.\n */\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 drawn space the drag happens in (a window's stage), in the same px as the samples: every point `update` and\n * `release` take is clamped onto it, exactly onto its edge (`x + width`, `y + height`), so a pointer past the window\n * picks what is drawn against its edge (see {@link DragTarget}'s `bounds`). Absent: points are taken as given. A view\n * that resizes during the drag passes the new one to {@link DragIntent.setBounds}.\n */\n readonly bounds?: Rect;\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` and `time` lands on: the shown target whenever one shows (a drop lands where the\n * indicator was), else the target under the pointer, else null (the item goes home). A release over home is null: it\n * does nothing. With a modifier key held (`keys`), the target the key picks, even over home. A point that differs\n * from the last `update`'s is that update's sample first, so a last jump of the pointer counts. That sample is no\n * frame: `HAND_SPEED.gap` (40) ms or more after the last `update` it is stamped at that update's time, so no dwell,\n * arm, switch hold, room or gap grace runs on through time no frame drew, and it keeps the speed that update read.\n * Call it with the pointer-up point and time, with no `update` of your own first.\n */\n release(point: Point, time: number, targets: readonly T[], keys?: DragKeys): T | null;\n /** The drawn space changed during the drag (the view resized): later points are clamped onto `bounds`, or none. */\n setBounds(bounds: Rect | undefined): void;\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). With no home, nothing. */\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 `armAfter` (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 another target or open space inside the float's\n * `bounds`, the arm 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 * - With `bounds`, every point is clamped onto it first (exactly onto its edge).\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 | null = options.home ? { ...options.home } : null;\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 drawn space every point is clamped onto (`bounds`), and the last point `update` took (after the clamp).\n let bounds: Rect | undefined = options.bounds ? { ...options.bounds } : undefined;\n let lastPoint: Point | null = null;\n /** The time of the last `update` (the last frame). */\n let lastT = 0;\n /** The sample being taken is the release's own, `HAND_SPEED.gap` ms or more after the last frame (see `release`). */\n let unseen = false;\n const clampInto = (p: Point): Point =>\n bounds ? { x: Math.min(Math.max(p.x, bounds.x), bounds.x + bounds.width), y: Math.min(Math.max(p.y, bounds.y), bounds.y + bounds.height) } : p;\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 arm key the nearest spring-loaded one.\n * The float key chooses the float over the other targets, not over refusals or outside the window: where the pick at\n * `p` (`has`: a target with a place there, or a refusal) is a refusal, it picks nothing and says which refusal;\n * outside the float's `bounds` (a pointer clamped onto the window's edge) it picks nothing. The arm key's drop lands\n * on the spring-loaded target, 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\" | \"armed\"; target: T | null; refused: T | null } | null => {\n const m = tuning.modifiers;\n if (!m.on || !keys) return null;\n if (isHeld(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 (!isHeld(keys, m.armKey)) 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: \"armed\", 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 (home && 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 (s) return s;\n return under && !under.refuse ? (given.find((x) => x.id === under.id) ?? under) : null;\n };\n\n function update(point: Point, time: number, given: readonly T[], keys?: DragKeys): DragFrame<T> {\n const p = clampInto(point);\n lastPoint = p;\n const t = time;\n lastT = t;\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 // (The release's own sample after time no frame drew keeps the speed the last frame read: stamped at that frame's\n // time, its move would read as one made in no time, end the aim and land a target no frame showed.)\n if (!unseen) 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 (!home || !inRect(home, p, -tuning.homeInset)) leftHome = true;\n const atHome = !!home && 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 `armAfter`. 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 arm key still forces the nearest one.\n liftAt ??= { x: p.x, y: p.y };\n const inLiftZone = 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.armAfter) {\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 // Home holds wherever it lies (the item's own place beats a refusal).\n const homeHolds = atHome;\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 // 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 return { shown, room: roomPlace !== null, roomPlace, aiming, atHome: !forced && wentOut && homeHolds, arming, forced: forced?.kind ?? null, refused, landing: landAt(p, given, keys) };\n }\n\n return {\n tuning,\n get state(): DragIntentState<T> {\n return { speed, current: cur, shown, leftHome };\n },\n update,\n release(point, time, given, keys) {\n // The last update's sample is the release's: a point that differs from it is one more sample first. That sample is\n // no frame: `HAND_SPEED.gap` ms or more after the last one, it is stamped at the last frame's time, so it counts\n // where the pointer went and none of the time no frame drew (no dwell, arm, switch, room or grace runs on), with the\n // speed the last frame read (no aim ended by a move read as made in no time).\n const p = clampInto(point);\n if (!lastPoint || lastPoint.x !== p.x || lastPoint.y !== p.y) {\n unseen = !!lastPoint && time - lastT >= HAND_SPEED.gap;\n try {\n update(p, unseen ? lastT : time, given, keys);\n } finally {\n unseen = false;\n }\n }\n return landAt(p, given, keys);\n },\n setBounds(next) {\n bounds = next ? { ...next } : undefined;\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 },\n moveHome(dx, dy) {\n if (home) home = { ...home, x: home.x + dx, y: home.y + dy };\n },\n };\n}\n","import type { Rect } from \"../shapes\";\nimport type { DragFrame, DragTarget } from \"./intent\";\nimport type { LandingRegion } from \"./region\";\n\n/**\n * How a drag previews its drop, from least to most motion while dragging. One vocabulary for both drag models (the\n * intent and the landing model):\n *\n * - `\"outline\"`: nothing moves; only the indicator (an outline or an insertion marker) shows the landing.\n * - `\"placeholder\"`: once the room is made, the others move aside and open the slot; the item stays under the pointer.\n * - `\"glide\"`: the slot opens and the item itself glides into it (for a landing with a slot; one without keeps the\n * indicator).\n * - `\"snap\"`: the dragged item is the only preview: no indicator for any landing. It sits in a slotted landing once\n * the room is open and otherwise stays on the pointer.\n *\n * Every mode follows the same model: what shows, when, and what a release lands on are the model's, so a drop always\n * lands where the preview showed it.\n */\nexport type PreviewMode = \"outline\" | \"placeholder\" | \"glide\" | \"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/** A drag's preview: its mode and its place guides (default per mode, {@link PLACE_GUIDES_DEFAULT}). */\nexport interface DragPreview {\n readonly mode: PreviewMode;\n readonly placeGuides?: PlaceGuides;\n}\n\n/** The preview a drag uses unless the host picks another. */\nexport const DRAG_PREVIEW_DEFAULT: DragPreview = { mode: \"glide\" };\n\n/** Each mode's place guides when it names none: Snap and Placeholder near, Outline and Glide none. */\nexport const PLACE_GUIDES_DEFAULT: Readonly<Record<PreviewMode, PlaceGuides>> = { outline: \"off\", placeholder: \"near\", glide: \"off\", snap: \"near\" };\n\n/**\n * The place guides a preview asks for: its `placeGuides`, else its mode's default. The one reading of the level:\n * `previewPlan` draws it, and the landing model (`createLandingModel({ preview })`) names its lanes by it.\n */\nexport function guidesOf(preview: DragPreview | PreviewMode): PlaceGuides {\n const p: DragPreview = typeof preview === \"string\" ? { mode: preview } : preview;\n return p.placeGuides ?? PLACE_GUIDES_DEFAULT[p.mode];\n}\n\n/** What to draw for one frame of a drag. */\nexport interface PreviewPlan {\n /** Draw the indicator on the shown landing. */\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 preview's `placeGuides` while no landing shows (no indicator, no room, no\n * item in its slot), `\"off\"` whenever one does, so the screen shows where the item can go or where it will land,\n * never both.\n */\n readonly guides: PlaceGuides;\n}\n\n/**\n * A frame `previewPlan` reads: the drag intent's (what shows) or the landing model's (where it lands: a\n * `LandingFrame`'s `region`, `landing` and `room`).\n */\nexport type PreviewFrame<T extends DragTarget = DragTarget> =\n | Pick<DragFrame<T>, \"shown\" | \"room\">\n | { readonly region: LandingRegion; readonly landing: Rect | null; readonly room: boolean };\n\n/**\n * The plan for a frame of either drag model under `preview` (a mode alone is `{ mode }`). From an intent's frame a\n * landing shows when a target shows, slotted unless it is `free`; from a landing frame it shows wherever the frame has a\n * landing, slotted in a lane (the float is not). `slotted` overrides that.\n *\n * - `\"outline\"`: the indicator, never room, never a snap.\n * - `\"placeholder\"`: the indicator, and room when the model makes it.\n * - `\"glide\"`: room when the model makes it, the item snapped into a slotted landing's room; the indicator only for a\n * landing without a slot.\n * - `\"snap\"`: as `\"glide\"`, with no indicator at all.\n */\nexport function previewPlan<T extends DragTarget>(frame: PreviewFrame<T>, preview: DragPreview | PreviewMode, slotted?: boolean): PreviewPlan {\n const p: DragPreview = typeof preview === \"string\" ? { mode: preview } : preview;\n const landing = \"region\" in frame;\n const shown = landing ? frame.landing !== null : !!frame.shown;\n const slots = slotted ?? (landing ? frame.region === \"lane\" : !!frame.shown && !frame.shown.free);\n const plan = planOf(p.mode, shown, frame.room, slots);\n const drawn = plan.showIndicator || plan.makeRoom || plan.snapItem;\n return { ...plan, guides: drawn ? \"off\" : guidesOf(p) };\n}\n\nfunction planOf(mode: PreviewMode, shown: boolean, room: boolean, slotted: boolean): Omit<PreviewPlan, \"guides\"> {\n if (mode === \"outline\") return { showIndicator: shown, makeRoom: false, snapItem: false };\n if (mode === \"placeholder\") return { showIndicator: shown, makeRoom: room, snapItem: false };\n if (mode === \"snap\") return { showIndicator: false, makeRoom: room, snapItem: room && shown && slotted };\n // By design a slotted landing draws nothing until the room opens (`roomAfter`); a release then still lands on it.\n return { showIndicator: shown && !slotted, makeRoom: room, snapItem: room && shown && slotted };\n}\n","import type { Point, Rect } from \"../shapes\";\nimport { isHeld } from \"../keys\";\nimport { createHandSpeed, HAND_SPEED } from \"./hand-speed\";\nimport { DRAG_DEFAULTS, type DragKeys, type DragModifiers } from \"./intent\";\nimport { DRAG_PREVIEW_DEFAULT, guidesOf, type DragPreview, type PlaceGuides, type PreviewMode } from \"./preview\";\nimport type { LandingRegion } from \"./region\";\n\n/**\n * The landing model: where a docking drag's item lands, as a held place rather than a per-frame guess. A host gives it the\n * drag's geometry (`@n-uf/docking`'s `dockDrag(...)` fits `LandingGeometry` as it is: the regions for hit-testing and\n * `landingOf(held)`) and each pointer sample; it says the region the pointer is in, the lane and spot held, the held place a\n * release lands (`frame.held`), where the item lands, whether the room is open, and which lanes' place guides show with\n * the held place each stands for. It picks held places and does no layout: every rect of a held place comes from the geometry. Every\n * change comes from where the pointer is and how it moved (margins, a path length, a step size): the model has no waits\n * 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\"). (Docking'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 * `stepSpeed`), or a still step (at most `stillSpeed`) once `depth` px inside, the depth measured across the lane: only from its\n * two sides parallel to its axis that face into the stage (on the edge it is deep), never from its ends along its axis\n * (a rail's end that meets a bar is no wall). A fly-through of a thin bar or rail at any angle meets neither, so its\n * room never opens. **No distance that reaches into a lane is more than `laneShare` (a third) of that lane's\n * thickness** (its rect's extent across its axis, the rect as hit-tested, not as drawn): the depth gate is\n * `min(depth, laneShare × thickness)`, and so is the held lane's exit margin measured into a lane that touches it,\n * or, where no touching lane lies under the pointer, into a blocked or refused rect that touches it (its thickness\n * the way the pointer reaches into it, across a bar beside the held lane, along a rect past its end: a full title\n * bar that takes nothing shows its refusal from its middle third on).\n * The first third of a lane still belongs to the lane you came from; from there on a still pointer is in the new\n * lane, so a thin lane (a 24 px title bar) is entered at its middle and shows its guide there. Lanes of 36 px and more\n * (48 with the touch margins) keep the full `exit`, and of 24 px and more the full `depth`. Inside a lane that touches\n * the held one, past the held lane's exit margin into it (where the pointer is inside several, the thinnest one's),\n * the held lane holds until one of those lanes' own gate passes or the pointer has slid `path` px along it (across it\n * at most a third as far) as a steady slide no faster than `slideSpeed` (2 px/ms), as the hand's speed reads it: lane\n * to lane never passes through the float, and never opens a crossed lane's room. A fling, along the lane or across it, is no entry: the touching lane is\n * entered only by its own gate (the slow path, or a rest past `pause`). The cost: above 2 px/ms a hand sliding along a\n * corner lane keeps the previous lane's end spot until it slows or rests, and a slide counts only once the hand's\n * speed is known and steady (a span and a half, 72 ms at 125 Hz, 120 ms at 60 Hz). The hold through a touching lane is\n * for crossing a corner: more than `exit + path` from the held lane's rect (the full `exit`, whatever lane lies there)\n * the frame is held but refused (the lane kept for its guides; no spot, no landing, nothing pending; a release goes\n * home), sticky until the pointer is back within `exit + path - spot`. Over a refused place (a lane's band lying over a column that takes nothing: an empty\n * side rail's) a lane is entered on the first slow step there (not on the lift), as there is nothing else to mean\n * there; a fly-through still opens no room. A touching lane's takeover reads the same rule, so a held lane never\n * pre-empts it. After a fling (the hand's speed above `slideSpeed`) no lane is entered by a slow-step gate (still,\n * over-refused) until the hand has read slow (or rested) for `pause`: jitter right after a flick docks nothing, while\n * on the stage's edge a fling is taken at once.\n * - **The hand's speed** (`createHandSpeed`, ./hand-speed) is the one estimate every gate that asks \"fast or slow\"\n * reads: the slide count and its entry, the settle rule, the slow path. It reads a speed-up at once (the newest step)\n * and a slow-down only once it has lasted its span (at least 48 ms and 5 steps), so a fling whose timestamps jitter\n * never reads slow; a gap of 40 ms or more that was a rest (the pointer seen standing still in it, or moving across\n * it at less than half the hand's speed) starts the hand again, so a rest is never averaged into the next fling, while\n * a gap the pointer moved on through (frames the host lost) carries the hand on, its lost frames filled in, so a\n * dropped frame never loses a slide; a step across a gap is never a slow step; and a slide counts only while the hand\n * reads steady (not gathering speed), from where the pointer crossed into the lane. A host sampling slower than 25 Hz\n * (every step a gap, the hand with no speed yet) slides into a touching lane only by its own gates. 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 held 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 * - **A float's lift zone.** A lift is a float's when it has no `home` option and no lane has a spot marked `home` (a\n * docked item's own place; docking always marks it), so a docked item lifted without `home` stays docked. A float has a zone of\n * its own, the same `margins.lift` around the press: within it no lane takes the pointer, and the frame is judged as if\n * the regions had no lanes (the float is at the hand, so a nudge moves it; blocked and refused places are judged as on\n * any frame, so a float lying over one is refused there). No lane's path counts inside it. The zone is left once, at\n * the first point farther than `lift` from the press, and never re-entered: the lanes act as usual from then on, a\n * held lane included, so a slide back through the press point changes nothing. A float lying inside a lane's band\n * (an empty bar's) stays a float for the first `lift` px, and the lane takes it by its gates after.\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 `stepSpeed`, or once the held landing trails the\n * pointer by more than `trail` (`landingOf` the spot held): the item chases only as far as it must. A change that\n * moves only the held item follows the hand at any speed. With `spotsOf`, a reflowing change is kept only if, with the\n * new spot held (its room open), the pointer still lies in that spot's stretch: the room shifting the boundary never\n * bounces it.\n * - **A sliding spot** (a free stretch as one spot) lands where the hand is: the model names the spot and the pointer,\n * and the geometry says where (`landingOf`). Nothing reflows inside it, so there are no steps there; a step comes only\n * where the order changes (passing a neighbor), as between any two spots.\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 * - **The float key** (`modifiers.floatKey`, Shift by default) turns a lane or open space into open space (the float), and\n * hides the guides.\n * - **Guides** name lanes and the held place each lane's guide stands for (`frame.guides`); the geometry draws them (a lane's\n * marks in that held place's layout). `\"near\"` shows a lane only where the pointer can enter it: the held lane's (also over its own\n * refused stretch); else the pending lane's (the pointer inside it, its gate not passed: a release floats or goes\n * home); else, with the pointer in open space, the approached lane's (the nearest within `reach`, by default the\n * entry margin `exit`, acquired within `max(reach - spot, reach / 2)` and kept to `reach`, so it never blinks at the\n * edge: a release floats). Over a refused place outside every lane no guide shows, however near the lane behind it\n * lies; a host that wants the early guide sets `approach.reach` (in open space only: over a refused place none shows\n * at any reach). That lane (the one the Near rule picks), held, stands for the frame's held place; pending or approached,\n * for the held place the pointer would land in there (the spot it picks along it), so its guide before entry is its mark\n * after it. `\"all\"` shows every lane's, every other lane standing for the frame's held place (the screen); with no Near\n * lane, the lane nearest the pointer within `reach` stands for its would-land held place, for the corner only (not made\n * Near, pending or enterable), switching exactly at `reach`. Where that lane's guide meets another's, the geometry\n * gives it that lane.\n * - Steps are speeds (px/ms) between points that differ, so the gates read the same speed at any input rate from 60 Hz\n * to 8 kHz. A point stamped under 1 ms after the newest one the hand holds is the same sample and changes no step (a\n * run of them is read from the first one 1 ms or more past it); one stamped before it is left out too. A repeated\n * point keeps the last step; it is still only once the pointer has stayed put for `rest` ms.\n * - **The pointer** is taken onto the stage by the model itself (past it by up to `edge`, onto its edge).\n *\n * **The host's part:** call `update` whenever you like: per pointer sample, per animation frame, or both. Times never go\n * back: give every call a time no earlier than the one before. Call it at least once more after the pointer stops,\n * `rest` ms or more later (every frame does), so it can become still and a rest reads as one (a rest the model never\n * sees is told from frames the host lost only by how far the pointer moved across it), and again with the same point\n * when a key changes. `release(point, time)` takes the release point as one more sample when it differs from the last;\n * that sample is no frame, and the hand's rest gap or more after the last `update` it counts none of the time between,\n * so a rest no frame drew counts for nothing (a slow page docks late, never falsely).\n * When the state under the drag changes (a resize, a store change), hand the new geometry whole to `setGeometry`.\n */\n\n/** A place a drop in a lane lands: its stretch of the lane and its listed landing rect. Ids are stable across solves. */\nexport interface LandingSpot {\n readonly id: string;\n readonly along: readonly [number, number];\n /** Its landing as listed (a sliding spot's at rest): what `home` compares with. Where it lands now is `landingOf`. */\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 /** The held item's own place at the lift (a docked item's; docking marks it): a lift with no spot marked home is a float's. */\n readonly home?: boolean;\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 /**\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}\n\n/** One lane a frame shows place guides for, with the held place its guide stands for (`LandingFrame.guides`). */\nexport interface LandingGuideRef {\n readonly lane: string;\n readonly held: LandingHeld | null;\n}\n\nexport interface LandingMargins {\n /**\n * Past a held lane's rect before it lets go, px: at most, since into a lane that touches the held one it is at most\n * `laneShare` of that lane's thickness, and so it is into a blocked or refused rect that touches it (no touching lane\n * there; the rect's thickness the way the pointer reaches into it: across a bar beside the held lane, along a rect past\n * its end).\n */\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 /**\n * The share of a lane's thickness (its rect's extent across its axis) that any distance reaching into it may take, at\n * most: the held lane's `exit` into a lane that touches it (or into a blocked or refused rect that touches it), and the\n * gates' `depth` (default a third). The first third\n * of a lane still belongs to the lane you came from; from there on a still pointer is in the new lane. A share that\n * isn't a positive number takes the default. The drag intent's `bandShare` and placement's tiling-hit cap are the\n * same kind of rule, each over its own model's distances.\n */\n readonly laneShare?: 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: at most `margins.laneShare` of the lane's thickness. */\n readonly depth: number;\n /** The speed of a still step, at most, px/ms. */\n readonly stillSpeed: number;\n /**\n * The fastest step that changes the spot along a lane where the change reflows the window, px/ms; it also bounds the\n * steps the path gate counts (a fast crossing never enters).\n */\n readonly stepSpeed: 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 * `stepSpeed`) 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 /**\n * The time a pointer that last moved fast has to stay put before it counts as still, ms: longer than sample gaps. Also\n * the settle window after a fling (a step above `slideSpeed`): no lane is entered by a slow-step gate (still,\n * over-refused) until the hand has been slow, or resting, this long.\n */\n readonly pause: number;\n /**\n * The fastest step at which a slide along a lane touching the held one takes it, px/ms (default 2). Above it a fling\n * is no entry; the lane's own gate (the slow path, or a rest past `pause`) still enters it.\n */\n readonly slideSpeed: number;\n}\n/**\n * The approach for near guides, with the pointer in open space: the nearest lane within `reach`, kept until another is\n * `nearer` closer or past `keep` (read as at least `reach`: a kept lane is never shown past it). The guide shows only\n * within `reach` of the lane, so by default only where the pointer can enter it.\n */\nexport interface LandingApproach {\n /**\n * How near a lane's rect the pointer is in open space for the lane's guides to show, px (default 12: the entry\n * margin). A lane is acquired within `max(reach - margins.spot, reach / 2)` and kept until `reach` (or `keep`), so\n * at the edge the guide never blinks.\n */\n readonly reach: number;\n /** How far a kept lane stays the approached one, px (default 12). Below `reach` it is `reach`. */\n readonly keep: number;\n /** How much nearer another lane has to be to take over from the kept one, px (default 16). */\n readonly nearer: number;\n}\n\n/** The default `laneShare`: a third of a lane's thickness. */\nconst LANE_SHARE = 1 / 3;\n/** The margins: 12 px exit, 6 px spot, 48 px edge, 16 px lift; a distance into a lane at most a third of its thickness. */\nexport const LANDING_MARGINS: LandingMargins = { exit: 12, spot: 6, edge: 48, lift: 16, laneShare: LANE_SHARE };\n/** A touch: wider margins, the finger's jitter. */\nexport const LANDING_TOUCH_MARGINS: LandingMargins = { exit: 16, spot: 8, edge: 48, lift: 16, laneShare: LANE_SHARE };\n\n/**\n * `px`, as a distance reaching into `rect` across `axis` (the long axis of the lane it is measured for): at most `share`\n * of its thickness, its extent across that axis. The one place the lane-share rule lives. A rect of no thickness (zero,\n * negative, not a number) caps nothing. The cap is the thickness divided by the share's reciprocal, so the default third\n * is exact (a 24 px lane gives 8, not a hair under it).\n */\nfunction intoRect(rect: Rect, axis: LandingLane[\"axis\"], px: number, share: number): number {\n return capBy(axis === \"x\" ? rect.height : rect.width, px, share);\n}\n/** `px`, at most `share` of a thickness `t`; a thickness that isn't positive caps nothing. */\nfunction capBy(t: number, px: number, share: number): number {\n if (!(t > 0) || share === Infinity) return px;\n return Math.min(px, t / (1 / share));\n}\n/**\n * `px`, as a distance reaching from `from` into `rect` at `p`: at most `share` of the rect's extent in each direction the\n * pointer lies past `from`'s rect (out of its side, the rect's extent across; past its end, along). So a bar beside a\n * lane is measured across it, and a long rect past a lane's end along its length.\n */\nfunction reachInto(rect: Rect, from: Rect, p: Point, px: number, share: number): number {\n let m = px;\n if (p.x < from.x || p.x > from.x + from.width) m = capBy(rect.width, m, share);\n if (p.y < from.y || p.y > from.y + from.height) m = capBy(rect.height, m, share);\n return m;\n}\n/** `px`, as a distance reaching into `lane`: at most `share` of its thickness (its rect's extent across its axis). */\nconst intoLane = (lane: LandingLane, px: number, share: number): number => intoRect(lane.rect, lane.axis, px, share);\n/**\n * The gates: 40 px of path, 8 px deep, a still step at most 0.1875 px/ms, a reflowing one at most 0.375 px/ms, a slide\n * into a touching lane at most 2 px/ms.\n */\nexport const LANDING_GATES: LandingGates = { path: 40, depth: 8, stillSpeed: 0.1875, stepSpeed: 0.375, trail: 40, rest: 22, pause: 60, slideSpeed: 2 };\nexport const LANDING_APPROACH: LandingApproach = { reach: LANDING_MARGINS.exit, keep: LANDING_MARGINS.exit, nearer: 16 };\n\n/**\n * The keys the landing model reads: the drag intent's {@link DragModifiers} less the arm key (the model has no\n * spring-loaded targets). While `floatKey` is held a lane or open space is open space and the guides hide; `on: false`\n * turns the key off. A host hands the model the same `modifiers` as its drag intent's tuning.\n */\nexport type LandingModifiers = Pick<DragModifiers, \"on\" | \"floatKey\">;\n/** The default keys: the drag intent's (`DRAG_DEFAULTS.modifiers`), Shift floats. */\nexport const LANDING_MODIFIERS: LandingModifiers = { on: DRAG_DEFAULTS.modifiers.on, floatKey: DRAG_DEFAULTS.modifiers.floatKey };\n\n/**\n * A held place of the drag: where a release now lands. A spot of a lane with the pointer (a sliding spot lands where the hand\n * holds it: the geometry says where), or the float at the pointer. A frame with none is at rest (it lands nowhere).\n */\nexport type LandingHeld =\n | { readonly kind: \"spot\"; readonly lane: string; readonly spot: string; readonly point: Point }\n | { readonly kind: \"float\"; readonly point: Point };\n\n/**\n * The drag's geometry, from the host's docking layer (`@n-uf/docking`'s `dockDrag(...)` fits it as it is): the regions\n * for hit-testing, as seen, and the one rect the model reads of a held place.\n */\nexport interface LandingGeometry {\n /** Hit-testing: the lanes (hit rects, spots' stretches, refused stretches), refused places, content, blocked, stage. */\n readonly regions: LandingRegions;\n /**\n * Where the item lands in a held place (its rect in that held place's layout), or null where it lands nowhere (a float\n * where the item doesn't float). The frame's landing, and the trail gate's: the model does no geometry of its own.\n */\n readonly landingOf: (held: LandingHeld) => Rect | null;\n /**\n * A spot's lane with its stretches cut in that spot's own layout (a panel column by halves of what it draws), or null:\n * the stretches along a held lane, and the fixed-point check. Absent: the stretches as seen. Asked once per spot until\n * the geometry changes.\n */\n readonly spotsOf?: (spot: string) => readonly LandingSpot[] | null;\n}\n\nexport interface LandingOptions extends LandingGeometry {\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 /**\n * The keys that win over the lanes (see {@link LandingModifiers}): the same `modifiers` shape as the drag intent's\n * tuning, the float key only. Default Shift floats ({@link LANDING_MODIFIERS}).\n */\n readonly modifiers?: Partial<LandingModifiers>;\n /**\n * The drag's preview, the one `previewPlan` reads: its guide level (`placeGuides`, else the mode's default,\n * `PLACE_GUIDES_DEFAULT`) is how many lanes' guides the frame names. A mode alone is `{ mode }`. Default\n * `DRAG_PREVIEW_DEFAULT` (Glide: none). The guide level has no other home: a host passes the preview here and to\n * `previewPlan`.\n */\n readonly preview?: DragPreview | PreviewMode;\n}\n\nexport type { LandingRegion };\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 /** The held place a release now lands (the screen's: what the host draws), or null at rest. */\n readonly held: LandingHeld | null;\n /** Where a release now lands: `landingOf(held)`; 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, the float key not held. */\n readonly room: boolean;\n /**\n * The lanes whose place guides show, each with the held place its guide stands for: the frame's `held` (the screen), or,\n * for the Near lane before entry (pending or approached), the held place the pointer would land there (the spot it picks\n * along it). The host's geometry draws them (`@n-uf/docking`'s `guides(frame)`).\n */\n readonly guides: readonly LandingGuideRef[];\n /** The float key (`modifiers.floatKey`, Shift by default) 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: the last frame's held place (a spot with the pointer, `home` when it lands at the item's own place;\n * the float at the pointer), or nothing. The host commits that held place's layout (`@n-uf/docking`'s `after(release)`).\n */\nexport type LandingRelease =\n | { readonly kind: \"spot\"; readonly lane: string; readonly spot: string; readonly point: Point; readonly home: boolean }\n | { readonly kind: \"float\"; readonly point: Point }\n | null;\n\nexport interface LandingModel {\n update(point: Point, time: number, keys?: DragKeys): LandingFrame;\n /**\n * What a release at `point` and `time` lands: the same answer as the last frame's `landing`. A point that differs\n * from the last `update`'s is that update's sample first (with `keys`, else the last keys), so a last jump counts.\n * That sample is no frame: `min(40, gates.pause)` ms or more after the last `update` it counts none of the time\n * between (its step is unknown, and it adds nothing to a slide), so a rest no frame drew counts for nothing: a slow\n * page docks late, never falsely. Call it with the pointer-up point and time, with no `update` of your own first.\n */\n release(point: Point, time: number, keys?: DragKeys): LandingRelease;\n /**\n * The geometry changed (a resize, a store change, a scroll): the new state's regions and readers, whole. Spots map by\n * id; a lost one goes to its lane's nearest.\n */\n setGeometry(geometry: LandingGeometry): 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 `lane` (0 on its edge or outside): measured across the lane, from its two sides parallel to\n * its axis (a rail's long sides, a bar's), and only from those that face into `stage`: a side on the stage's edge is\n * open, as deep as the pointer can go. The lane's ends along its own axis never count, wherever they lie (a rail's end\n * that meets a bar is no wall), so the depth is the same all along the lane.\n */\nfunction depthIn(lane: LandingLane, p: Point, stage: Rect): number {\n const r = lane.rect;\n if (!strictlyIn(r, p)) return 0;\n const on = (a: number, b: number): boolean => Math.abs(a - b) < 1;\n const sides =\n lane.axis === \"x\"\n ? [on(r.y, stage.y) ? Infinity : p.y - r.y, on(r.y + r.height, stage.y + stage.height) ? Infinity : r.y + r.height - p.y]\n : [on(r.x, stage.x) ? Infinity : p.x - r.x, on(r.x + r.width, stage.x + stage.width) ? Infinity : r.x + r.width - p.x];\n return Math.max(0, Math.min(...sides));\n}\nconst lerp = (a: Point, b: Point, u: number): Point => ({ x: a.x + (b.x - a.x) * u, y: a.y + (b.y - a.y) * u });\n/** Where the step from `a` (outside `r`) to `b` (inside it) crosses into `r`, as a share of the step (0 to 1). */\nfunction entryOf(r: Rect, a: Point, b: Point): number {\n const enter = (from: number, to: number, lo: number, hi: number): number => (from < lo ? (lo - from) / (to - from) : from > hi ? (hi - from) / (to - from) : 0);\n return Math.min(1, Math.max(0, enter(a.x, b.x, r.x, r.x + r.width), enter(a.y, b.y, r.y, r.y + r.height)));\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 // A share that isn't a positive number (zero, negative, NaN, an explicit undefined over the default) is the default.\n const laneShare = typeof margins.laneShare === \"number\" && margins.laneShare > 0 ? margins.laneShare : LANE_SHARE;\n const approach = { ...LANDING_APPROACH, ...options.approach };\n const modifiers = { ...LANDING_MODIFIERS, ...options.modifiers };\n const guidesLevel: PlaceGuides = guidesOf(options.preview ?? DRAG_PREVIEW_DEFAULT);\n let base = options.regions;\n let landingOf = options.landingOf;\n let spotsOf = options.spotsOf;\n const cache = new Map<string, readonly LandingSpot[] | null>();\n /**\n * `lane` with `spot` held: its stretches in that spot's own layout (`spotsOf`, asked once per spot until the geometry\n * changes), else as seen.\n */\n const heldLaneOf = (lane: LandingLane, spot: string | null): LandingLane => {\n if (!spot || !spotsOf) return lane;\n if (!cache.has(spot)) cache.set(spot, spotsOf(spot));\n const spots = cache.get(spot);\n return spots ? { ...lane, spots } : lane;\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 /** The lift is a float's: no `home` option and no spot marked home in the lanes at the lift (a docked item has one). */\n const floatLift = !options.home && !options.regions.lanes.some((l) => l.spots.some((s) => s.home));\n /** Whether a float lift has left its lift zone: once, for good (`floatZone`). */\n let floatLeft = false;\n /** Whether the held lane's hold is refused for lying far beyond it (sticky, as the lift zone is). */\n let farHeld = false;\n /**\n * The hand read faster than `gates.slideSpeed` (a fling), and hasn't settled since: until it has read slow (at most\n * `gates.stepSpeed`, or resting) for `pause` ms from `slowFrom`, no lane is entered by a slow-step gate (still,\n * over-refused).\n */\n let flung = false;\n let slowFrom: number | null = null;\n let lastStep = 0;\n /** The hand's speed (`createHandSpeed`): the one estimate every gate that asks \"fast or slow\" reads. */\n const handGap = Math.min(HAND_SPEED.gap, gates.pause);\n const hand = createHandSpeed({ gap: handGap, still: Math.min(HAND_SPEED.still, gates.rest) });\n /**\n * The sample being taken is the release's own, `handGap` ms or more after the last frame: no frame drew the time\n * between, so it counts none of it (its step is unknown, and it adds nothing to a slide).\n */\n let unseen = false;\n /** The keys the last `update` had: a release at a new point samples with them unless it names its own. */\n let lastKeys: DragKeys | undefined;\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 /** The lane pending on the last frame: it stays pending while the pointer stays inside it (`pendingIn`). */\n let lastPending: string | null = null;\n /**\n * The pending lane among `here` (the lanes the pointer is strictly inside): the one pending on the last frame while it\n * is among them, until another is deeper by `margins.spot`; else the deepest. So at a corner where two lanes overlap\n * a wobble never flips the pending lane, nor its guides.\n */\n const pendingIn = (here: readonly LandingLane[], p: Point, stage: Rect): string => {\n const deepest = here.reduce((a, b) => (depthIn(b, p, stage) > depthIn(a, p, stage) ? b : a));\n const kept = here.find((l) => l.id === lastPending);\n return kept && depthIn(deepest, p, stage) <= depthIn(kept, p, stage) + margins.spot ? kept.id : deepest.id;\n };\n let previous: LandingRegion = laneId ? \"lane\" : \"open\";\n let frame: LandingFrame = { region: previous, lane: laneId, spot: spotId, held: null, landing: null, room: !!spotId, guides: [], shift: false };\n /** The spot the last frame lands on, as its lane lists it, or null. */\n let landedOn: LandingSpot | 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 /** 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 held = heldLaneOf(lane, spotId);\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.stepSpeed && distanceTo(landingOf({ kind: \"spot\", lane: lane.id, spot: now.id, point: p }) ?? now.landing, p) <= gates.trail) return now;\n // The fixed point: with the candidate held (its room open), the pointer still picks it along the lane.\n if (spotsOf && reflows) {\n const lane2 = heldLaneOf(lane, cand.id);\n if (pick(lane2, alongOf(lane2, p))?.id !== cand.id) return now;\n }\n return cand;\n }\n\n /**\n * The lanes whose guides show, each with the held place its guide stands for. `\"near\"`: the Near lane only; `\"all\"`: every\n * lane. The Near lane held stands for the frame's held place; pending or approached, for the held place the pointer would land in\n * there (the spot it picks along it), so its guide before entry is its mark after it. Every other lane stands for the\n * frame's held place (the screen). The geometry draws them; the model does none.\n */\n function guidesFor(p: Point, region: LandingRegion, shift: boolean, pending: string | null, held: LandingHeld | null): LandingFrame[\"guides\"] {\n if (guidesLevel === \"off\" || shift) return [];\n const near = nearLane(p, region, pending, base);\n const wouldLand = (l: LandingLane): LandingHeld | null => {\n if (l.id === laneId) return held;\n const s = pick(l, alongOf(l, p));\n return s ? { kind: \"spot\", lane: l.id, spot: s.id, point: p } : held;\n };\n if (guidesLevel === \"near\") return near ? [{ lane: near.id, held: wouldLand(near) }] : [];\n // \"all\": with no Near lane, the lane nearest the pointer within `reach` stands for its would-land held place too, for the\n // corner only (it isn't made Near, pending or enterable): its guide is what entry draws, and it owns the corners it\n // meets. The switch lies exactly at `reach` of its rect.\n let owner = near;\n if (!owner) {\n let d = approach.reach;\n for (const l of base.lanes) {\n const dl = distanceTo(l.rect, p);\n if (dl <= d) {\n owner = l;\n d = dl;\n }\n }\n }\n return base.lanes.map((l) => ({ lane: l.id, held: owner && l.id === owner.id ? wouldLand(l) : held }));\n }\n\n /**\n * The lane whose guides the Near rule shows, or null: the held lane (also over its own refused stretch), else the\n * pending one, else, with the pointer in open space, the approached one (kept with hysteresis).\n */\n function nearLane(p: Point, region: LandingRegion, pending: string | null, regions: LandingRegions): LandingLane | null {\n // The held lane's, also over its own refused stretch.\n if ((region === \"lane\" || region === \"refused\") && laneId) {\n approached = laneId;\n return laneIn(regions, laneId) ?? null;\n }\n // The pending lane's: the pointer is inside it, its gate not passed (the place under it, a refused one too, is its).\n if (pending) {\n approached = pending;\n return laneIn(regions, pending) ?? null;\n }\n // Only in open space the approach counts: over a refused place outside every lane, or nowhere, no lane's guides show.\n if (region !== \"open\") {\n approached = null;\n return null;\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 // The approached lane: the nearest within reach, kept until another is clearly nearer or it is past `keep` (at least\n // `reach`: a lane acquired within reach is never dropped at once). Acquired only within `max(reach - margins.spot,\n // reach / 2)`, so a pointer wobbling at the reach's edge never blinks the guide (a band between acquiring and letting\n // go), and a small reach or wide touch margins still leave half the reach to acquire in.\n const acquire = Math.max(0, approach.reach - margins.spot, approach.reach / 2);\n const kept = laneIn(regions, approached);\n if (kept) {\n const d = distanceTo(kept.rect, p);\n if (d > Math.max(approach.keep, approach.reach)) approached = null;\n else if (best && best.id !== kept.id && bestD + approach.nearer < d) approached = bestD <= acquire ? best.id : null;\n } else approached = best && bestD <= acquire ? best.id : null;\n return laneIn(regions, approached) ?? null;\n }\n\n function update(raw: Point, t: number, keys?: DragKeys): LandingFrame {\n lastKeys = keys;\n // Past the stage by up to `edge`: on its edge. Beyond: nowhere (kept as is).\n const p = ontoStage(base.stage, raw, margins.edge) ?? raw;\n // The step: the pointer's speed as it moved (a fling past the edge isn't still) since the last point that differed,\n // px/ms. A repeated point (a host updating per frame, or a gap between sparse samples) keeps the last step until the\n // pointer has stayed put for `rest` ms after a slow step or on the stage's edge, else for `pause` ms; only then is it\n // 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 const before = moved.t;\n moved = { raw, t };\n hand.push(raw, t);\n // The step across a gap (40 ms or `pause`, the smaller) may end a rest, so it says nothing about how the hand moves\n // now: unknown, never a slow step (a fling out of a rest docks nowhere on its first frame), unless it is no longer\n // than `HAND_SPEED.slowStep` (3) px (a hand creeping a pixel at a time, which is slow). The hand's speed reads\n // across a gap the pointer moved on through (frames the host lost), so a slide through it counts on. The release's\n // own sample after a time no frame drew (`unseen`) is unknown even as a crawl: a rest no frame drew counts nothing.\n step = unseen ? Infinity : hand.step;\n lastStep = step;\n // A fling (the hand reading faster than `slideSpeed`) unsettles it; it is slow again from the last sample before it\n // reads slow (at most `stepSpeed`). A step the hand's speed can't read yet (the first after a rest) is neither.\n const sp = hand.speed;\n if (Number.isFinite(sp) && sp > gates.slideSpeed) {\n flung = true;\n slowFrom = null;\n } else if (!Number.isFinite(sp) || !Number.isFinite(step) || sp > gates.stepSpeed) slowFrom = null;\n else slowFrom ??= before;\n } else if (moved) {\n const stage = base.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.stepSpeed || onEdge)) ? 0 : lastStep;\n // The hand sees the pointer standing still: a gap it ends is a rest, whatever the pointer moves across it.\n hand.hold(t);\n // Resting: the hand has been still since its last sample.\n slowFrom ??= moved.t;\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 hand.reset();\n hand.push(raw, t);\n // (After `hide()` too, the lift point stays where the drag began.)\n liftAt ??= p;\n step = lastStep = Infinity;\n }\n // Settled again once slow for `pause` since the fling: only then do the slow-step gates (still, over-refused) count.\n // On the stage's edge a fling is taken at once, as the still gate's `rest` says: the edge is where a fling docks.\n if (flung && slowFrom !== null && t - slowFrom >= gates.pause) flung = false;\n const edgeStage = base.stage;\n const settled = !flung || p.x <= edgeStage.x || p.y <= edgeStage.y || p.x >= edgeStage.x + edgeStage.width || p.y >= edgeStage.y + edgeStage.height;\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 = modifiers.on && isHeld(keys, modifiers.floatKey);\n // A float lift (`floatLift`): within `lift` of the press no lane takes the pointer (the frame is judged as if the regions\n // had no lanes: blocked and refused places as on any frame), until the pointer first lies farther than `lift`; once\n // left it is never re-entered, so a slide back through the press point changes nothing (a held lane stays held).\n if (floatLift && liftAt && Math.hypot(p.x - liftAt.x, p.y - liftAt.y) > (margins.lift ?? 16)) floatLeft = true;\n const floatZone = floatLift && !floatLeft && !!liftAt;\n const regions = floatZone ? { ...base, lanes: [] } : base;\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 `stepSpeed` 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 while the hand reads steady and no\n // faster than `slideSpeed` (`hand`): a brisk slide along it (across it at most a third as far as along) is no\n // crossing. (The slow path counts a step at most `stepSpeed`, as the hand's speed reads it: a jittered fling never;\n // nor a step across a gap, which may end a rest, though the hand's speed reads across frames the host lost.)\n const slow = Number.isFinite(step) && (Number.isFinite(hand.speed) ? hand.speed <= gates.stepSpeed : step <= gates.stepSpeed);\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 // Only a steady hand no faster than `slideSpeed` adds to the count: a fling (or a hand gathering speed out of a rest\n // or a hesitation, or one the speed can't read yet) adds nothing and resets nothing. So a fling never counts, even\n // where its timestamps jitter, while a steady slide whose timestamps jitter keeps its count. It counts from where\n // the pointer crossed into the lane: the step that enters adds its part inside it, so a step the host lost frames\n // of across the lane's edge counts what those frames would have.\n // (Nor does the release's own sample after a time no frame drew: a crawl over it may read as frames the host lost.)\n const counts = !unseen && hand.steady && hand.speed <= gates.slideSpeed;\n const u = !was && inL && from && fromRaw ? entryOf(l.rect, from, p) : 0;\n const by =\n was ? { along: go, across: over }\n : u > 0 && from && fromRaw ? { along: Math.abs(alongOf(l, p) - alongOf(l, lerp(from, p, u))), across: Math.abs(acrossOf(l, raw) - acrossOf(l, lerp(fromRaw, raw, u))) }\n : { along: 0, across: 0 };\n slide.set(l.id, !inL ? { along: 0, across: 0 } : counts ? { along: (s?.along ?? 0) + by.along, across: (s?.across ?? 0) + by.across } : (s ?? { 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 // (The still gate, like the over-refused rule, waits for a flung hand to settle.)\n // The still gate's depth is at most `laneShare` of the lane's thickness, so a thin lane's middle third takes a rest.\n const gate = (l: LandingLane): boolean =>\n (pathIn.get(l.id) ?? 0) >= gates.path || (depthIn(l, p, regions.stage) >= intoLane(l, gates.depth, laneShare) && step <= gates.stillSpeed && settled);\n // Lane to lane: inside the lanes touching the held one, past the held lane's exit margin into them (inside it the\n // held lane holds, P1), the held lane still holds until one of those lanes' own gate passes, then that lane takes it\n // (the first such, in the regions' order). Never the float between them, never a fly-through's room. The margin\n // reaches at most `laneShare` into each of them: where the pointer is inside several (a corner), the thinnest one's\n // sets it, so the middle third of every lane is free of the held lane's hold. A lane that doesn't touch the held one\n // gets no cap: nothing would hold the pointer past it, and lane to lane never passes through the float.\n const touchingAll = held ? regions.lanes.filter((l) => l.id !== held.id && strictlyIn(l.rect, p) && touches(l.rect, held.rect)) : [];\n const exitInto = touchingAll.reduce((m, l) => intoLane(l, m, laneShare), margins.exit);\n const touchingHere = held && !inside(held.rect, p, exitInto) ? touchingAll : [];\n const touching = touchingHere[0];\n // The same cap over a place that takes nothing beside the held lane: where no touching lane lies under the pointer,\n // the hold reaches at most `laneShare` into a blocked or refused rect that touches the held lane (its thickness the\n // way the pointer reaches into it: across a bar beside the held lane, along a rect past its end; inside several,\n // the thinnest one's), so a thin bar that takes nothing (a full title bar) shows its refusal from its middle third\n // on. Open space, and a rect that doesn't touch the held lane, keep the full `exit`: the hold never passes through\n // the float.\n const holdExit =\n held && touchingAll.length === 0\n ? [...regions.blocked, ...regions.refused].filter((b) => strictlyIn(b, p) && touches(b, held.rect)).reduce((m, b) => reachInto(b, held.rect, p, m, laneShare), margins.exit)\n : margins.exit;\n // A fling (the hand's speed above `slideSpeed`) is no entry, along the lane as well as across it.\n const slid = (l: LandingLane): boolean => {\n const sl = slide.get(l.id);\n return !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along && hand.speed <= gates.slideSpeed;\n };\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 held, 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 // The lanes the pointer is inside (within the lift zone an owning lane is no lane at all), and the over-refused\n // rule: over a place that takes nothing reaching past the lane (a column's panel under an empty rail's band), in no\n // other lane, a lane is entered on a slow step only (a fly-through opens no room). Entering reads it, and so does a\n // touching lane's takeover: a held lane never pre-empts it.\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 const overRefused = (l: LandingLane): boolean =>\n Number.isFinite(step) && step <= gates.stepSpeed && settled && lanesHere.length === 1 && [...regions.blocked, ...regions.refused].some((b) => strictlyIn(b, p) && !within(b, l));\n const next = homeHere ? undefined : (owner ?? touchingHere.find((l) => gate(l) || slid(l) || overRefused(l)));\n // (The far refusal belongs to the held lane's hold: any other branch lets it go.)\n if (!(held && !homeHere && !next && (touching || inside(held.rect, p, holdExit)))) farHeld = false;\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, holdExit))) {\n // The hold through a touching lane is for crossing a corner: more than `exit + path` from the held lane's rect\n // (a fling up a rail that didn't enter it), the frame is held but refused: the lane kept (its guides stay), no\n // spot, no landing, nothing pending, so the host shows its tag and a release goes home. Sticky, like the lift\n // zone: set past `exit + path`, cleared only within `exit + path - spot`, so a wobble at its edge never flips it.\n const d = distanceTo(held.rect, p);\n farHeld = farHeld ? d > margins.exit + gates.path - margins.spot : d > margins.exit + gates.path;\n const far = farHeld;\n const s = far ? null : 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 && !far && !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 = pendingIn(others, p, regions.stage);\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 let entered: LandingLane | null = next ?? null;\n if (!entered)\n for (const l of lanesHere) {\n const deep = depthIn(l, p, regions.stage);\n if ((gate(l) || overRefused(l)) && (!entered || deep > depthIn(entered, 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 = pendingIn(lanesHere, p, regions.stage);\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 // (A zone frame inside a real lane leaves `previous` as it was: the zone's lane-less verdict is not carried past it.)\n previous = floatZone && base.lanes.some((l) => strictlyIn(l.rect, p)) ? previous : region;\n lastPending = pending;\n const shown: LandingRegion = shift && (region === \"lane\" || region === \"open\") ? \"open\" : region;\n const lane0 = laneIn(base, laneId);\n const heldLane = lane0 ? heldLaneOf(lane0, spotId) : undefined;\n const spot = spotIn(heldLane, spotId);\n landedOn = shown === \"lane\" && spot ? spot : null;\n // The held place a release lands now, and where it lands: the geometry's (a sliding spot's landing follows the hand).\n const held: LandingHeld | null = shown === \"lane\" ? (spot && laneId ? { kind: \"spot\", lane: laneId, spot: spot.id, point: p } : null) : shown === \"open\" ? { kind: \"float\", point: p } : null;\n const landing = held ? landingOf(held) : null;\n frame = {\n region: shown,\n lane: laneId,\n spot: shown === \"lane\" ? spotId : null,\n held: held && (held.kind === \"spot\" || landing) ? held : null,\n landing,\n room: shown === \"lane\" && !!spot,\n guides: guidesFor(p, shown, shift, pending && shown !== \"lane\" ? pending : null, held && (held.kind === \"spot\" || landing) ? held : null),\n shift,\n ...(pending && shown !== \"lane\" ? { pending } : {}),\n };\n return frame;\n }\n\n return {\n update,\n release(point: Point, time: number, keys?: DragKeys): LandingRelease {\n // The last update's sample is the release's: a point that differs from it is one more sample first. That sample is\n // no frame: `handGap` ms or more after the last one, the time between counts nothing (a slow page docks late, on\n // the next frame it draws, never on a rest no frame drew).\n if (!last || last.raw.x !== point.x || last.raw.y !== point.y) {\n unseen = !!last && time - last.t >= handGap;\n try {\n update(point, time, keys ?? lastKeys);\n } finally {\n unseen = false;\n }\n }\n const s = frame.held;\n if (s?.kind === \"spot\" && frame.region === \"lane\") {\n // Home only at the item's own place: its own spot, landing where it lies (a sliding spot anywhere else on its\n // stretch moves it).\n const ownSpot = !!options.home && options.home.spot === s.spot && options.home.lane === s.lane;\n const at = frame.landing;\n const home = ownSpot && !!landedOn && !!at && Math.max(Math.abs(at.x - landedOn.landing.x), Math.abs(at.y - landedOn.landing.y), Math.abs(at.width - landedOn.landing.width), Math.abs(at.height - landedOn.landing.height)) < 1e-6;\n return { kind: \"spot\", lane: s.lane, spot: s.spot, point: s.point, home };\n }\n if (s?.kind === \"float\" && frame.region === \"open\" && frame.landing) return { kind: \"float\", point: s.point };\n return null;\n },\n setGeometry(geometry: LandingGeometry): void {\n base = geometry.regions;\n landingOf = geometry.landingOf;\n spotsOf = geometry.spotsOf;\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 lastPending = null;\n farHeld = false;\n flung = false;\n slowFrom = 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 { 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 lane's marks, as a host's geometry draws a frame's guides). */\nexport interface PlacedGuide {\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n /**\n * The axis of the lane the guide marks, when the guide knows it. It only decides a box that is no longer than it is\n * thick (a square): its long side is its axis, and a square has none, so `axis` (default `\"x\"`) says.\n */\n readonly axis?: \"x\" | \"y\";\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. A box a clear rect thinned is held to it too. */\n readonly minThickness?: number;\n /**\n * The thickness a `line` guide is drawn at, px (default 2). A line thinner than this (docking gives the line\n * between two docked panels zero thickness) is widened to it, centered on its own position, before the inset, the\n * clear rects and `minThickness` apply; a line at least this thick is unchanged. Only lines are widened. `0` turns\n * the widening off: a line keeps the thickness it has, and a zero-thick one is dropped by `minThickness`.\n */\n readonly lineThickness?: number;\n /**\n * The least length, along the box's axis, a part of a box that a clear rect cut keeps, px (default 8,\n * `MIN_BOX_LENGTH`); shorter, that part is not drawn. Corner-cut parts included; a box nothing touches is kept as is.\n */\n readonly minLength?: number;\n}\n\n/** The least length, px, a box part a clear rect cut keeps (`minLength`'s default). */\nexport const MIN_BOX_LENGTH = 8;\n/** The thickness, px, a thinner line is drawn at, centered on its place (`lineThickness`'s default). */\nconst LINE_THICKNESS = 2;\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, then each clear rect, grown by its clearance, is\n * taken out of it, by one model:\n *\n * - One axis per box: its long side, decided once from the box clipped to `inside`, before any clear rect is applied\n * (a square takes the guide's `axis`, else x). Cutting a box never turns its axis.\n * - Thinning comes first. A clear rect over only part of the thickness that reaches one side of the box thins it when\n * its overlap across the box is smaller than its overlap along it: the box loses that thickness from that side and no\n * length (a neighbor poking 2 px into a bar costs 2 px of thickness, not its whole length in the bar's length). The\n * deepest intrusion from each side wins, whatever the order. Only a shallow intrusion thins, at most half the box's\n * thickness. A box thinned below `minThickness` is dropped. A rect that pokes in deeper than half the thickness (the\n * held outline flush with one side), as deep as it is long, or touches neither side, is a corner (below).\n * - A clear rect across the box's whole thickness (of the thinned box) is an interval along the axis, and the box less all of them is a\n * 1-D interval subtraction: inside the box (the held item's outline sliding inside its room) both sides stay, over\n * one end the other side. The result does not depend on the order of the clear rects.\n * - A clear rect over only part of the thickness (a corner) then cuts each part on the side that faces it, the\n * largest part kept (no L-shapes). Corners are applied by their distance along the axis (start, then end, then\n * across), whatever the input order, so the result is the same for any order.\n * - `minLength` (default 8, `MIN_BOX_LENGTH`) is applied once at the end, along the axis, to every part a clear rect\n * cut, corner-cut ones included. A part nothing touched is the clipped box and is kept at any length.\n * - Ids follow the side, not the rank: a part keeps the guide's `id` when no interior cut lies before it along the\n * axis, and gets `<id>#<k + 1>` when k of them do. A cut is a full-thickness clear interval strictly inside the box\n * (box length on both sides of it); overlapping or touching ones count as one, and one that touches or overlaps the\n * box's start or end only trims the box, it is no cut (a neighbor flush with the box's start, grown by its clearance,\n * leaves the part before a held rect as `<id>`). The part before a cut is always `<id>`, the part after one cut\n * always `<id>#2`, whether or not the part before survives, so a host keys each part by its id as a held item slides.\n * The exception: while the held rect overlaps the box's start (or end) it only trims the box, so the part left is\n * `<id>`, and it becomes `<id>#2` once the held rect lies strictly inside the box. A guide's own `id` must not end in `#` and digits\n * (`b#2` would collide with the second part of `b`), and an `id` that is not a string is not suffixed (a split\n * box's parts then share it: unsupported). Parts come back in order along the axis.\n *\n * A line thinner than `lineThickness` (default 2 px; a zero-thick line is a place between two things, a joint) is first\n * widened to it, centered on its own position, so the inset, the clear rects and `minThickness` below see a line of that\n * thickness; `lineThickness: 0` leaves lines as given. 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. A clear rect over its thickness that meets only one end of its length (it covers the\n * guide's start or its end, not both) shortens it, as it trims a box: the guide keeps the part away from the rect, at\n * least `minLength` long, else it is left out; a toolbar over the last 10 px of a column's line costs 10 px of length\n * (and the clearance), not the line. Then it is thinned, from the content side, to stay that far clear of the rects\n * over its middle (or over all of its length), so a thin strip at the window's side lies between the inset and the\n * content, the same on both sides. A guide with nothing left (or a thin one under `minThickness`) is left out. A clear rect whose x, y, width or height isn't finite is ignored. 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 const lineThickness = Number.isFinite(options.lineThickness) ? Math.max(0, options.lineThickness!) : LINE_THICKNESS;\n const minLength = Number.isFinite(options.minLength) ? Math.max(0, options.minLength!) : MIN_BOX_LENGTH;\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. One whose x, y, width or height\n // isn't finite is ignored (it would take every box out and give thin guides non-finite fields).\n const finite = (r: Rect): boolean => Number.isFinite(r.x) && Number.isFinite(r.y) && Number.isFinite(r.width) && Number.isFinite(r.height);\n const allClear = (options.clear ?? [])\n .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 .filter((c) => finite(c.k));\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 type Box = { a: number; b: number; c: number; d: number };\n // The box clipped to `inside`. Its axis is its long side, decided here once (a square: the guide's `axis`, else\n // x), before any clear rect is applied, so cutting it never turns the axis.\n const box: Box = { a: Math.max(r.x, x0), b: Math.max(r.y, y0), c: Math.min(r.x + r.width, x1), d: Math.min(r.y + r.height, y1) };\n // Written as \"not more than\" so a non-finite box (NaN in its rect or in `inside`) is left out, never drawn as NaN.\n if (!(box.c - box.a > EPS) || !(box.d - box.b > EPS)) continue;\n const w = box.c - box.a;\n const h = box.d - box.b;\n const alongX = w > h || (w === h && (g as { axis?: unknown }).axis !== \"y\");\n // Axis coordinates: `s` along the box, `t` across it.\n const s0 = alongX ? box.a : box.b;\n const s1 = alongX ? box.c : box.d;\n const t0 = alongX ? box.b : box.a;\n const t1 = alongX ? box.d : box.c;\n const toBox = (p0: number, p1: number, q0: number, q1: number): Box => (alongX ? { a: p0, b: q0, c: p1, d: q1 } : { a: q0, b: p0, c: q1, d: p1 });\n // Each clear rect, grown by its clearance, that lies over the box.\n const over = clear\n .map(({ k, gap }) => ({\n x0: k.x - gap,\n x1: k.x + k.width + gap,\n y0: k.y - gap,\n y1: k.y + k.height + gap,\n s0: (alongX ? k.x : k.y) - gap,\n s1: (alongX ? k.x + k.width : k.y + k.height) + gap,\n t0: (alongX ? k.y : k.x) - gap,\n t1: (alongX ? k.y + k.height : k.x + k.width) + gap,\n }))\n .filter((k) => k.s1 > s0 + EPS && k.s0 < s1 - EPS && k.t1 > t0 + EPS && k.t0 < t1 - EPS);\n // First, thinning: a clear rect over only part of the thickness, reaching one side of the box, whose overlap across\n // is smaller than its overlap along the box, thins the box from that side by that overlap, no length lost. The\n // deepest intrusion from each side wins, so the order of the clear rects never matters. Only a shallow one thins, at\n // most half the box's thickness: a deeper one (the held outline flush with one side) is a corner, so the box never\n // shrinks to a sliver beside it.\n let v0 = t0;\n let v1 = t1;\n const half = (t1 - t0) / 2 + EPS;\n for (const k of over) {\n if (k.t0 <= t0 + EPS && k.t1 >= t1 - EPS) continue;\n const along = Math.min(k.s1, s1) - Math.max(k.s0, s0);\n if (k.t0 <= t0 + EPS) {\n if (k.t1 - t0 < along - EPS && k.t1 - t0 <= half) v0 = Math.max(v0, k.t1);\n } else if (k.t1 >= t1 - EPS) {\n if (t1 - k.t0 < along - EPS && t1 - k.t0 <= half) v1 = Math.min(v1, k.t0);\n }\n }\n // A box thinned below `minThickness` is dropped, as a thin guide is.\n if ((v0 > t0 || v1 < t1) && v1 - v0 < Math.max(EPS, min)) continue;\n // What is left to cut is judged against the thinned box: a thinning rect no longer overlaps it.\n const rest = over.filter((k) => k.t1 > v0 + EPS && k.t0 < v1 - EPS);\n const kept = toBox(s0, s1, v0, v1);\n // Across the box's whole thickness: interval subtraction along the axis (order does not matter). The cut\n // intervals, merged, split the box into parts; a part's `k` is how many intervals lie before it.\n const full = rest\n .filter((k) => k.t0 <= v0 + EPS && k.t1 >= v1 - EPS)\n .map((k): [number, number] => [Math.max(k.s0, s0), Math.min(k.s1, s1)])\n .sort((p, q) => p[0] - q[0] || p[1] - q[1]);\n const cuts: [number, number][] = [];\n for (const [lo, hi] of full) {\n const last = cuts[cuts.length - 1];\n if (last && lo <= last[1] + EPS) last[1] = Math.max(last[1], hi);\n else cuts.push([lo, hi]);\n }\n // A part's `k` counts the interior cuts before it: a cut that touches or overlaps the box's start or end trims the\n // box, it is no cut (so a neighbor flush with the box's start never renames the part before a held rect).\n const spans: { lo: number; hi: number; k: number }[] = [];\n let at = s0;\n let k = 0;\n for (const [lo, hi] of cuts) {\n if (lo - at > EPS) spans.push({ lo: at, hi: lo, k });\n if (lo > s0 + EPS && hi < s1 - EPS) k++;\n at = hi;\n }\n if (s1 - at > EPS) spans.push({ lo: at, hi: s1, k });\n // Over only part of the thickness (a corner): cut on the side that faces it, the largest part kept (no L-shapes),\n // each corner rect in turn by its distance along the axis, so the result never depends on the input order.\n const corners = rest\n .filter((k) => !(k.t0 <= v0 + EPS && k.t1 >= v1 - EPS))\n .sort((p, q) => p.s0 - q.s0 || p.s1 - q.s1 || p.t0 - q.t0 || p.t1 - q.t1);\n const longEnough = Math.max(EPS, minLength - EPS);\n for (const span of spans) {\n let p: Box | null = toBox(span.lo, span.hi, v0, v1);\n for (const k of corners) {\n const { a, b, c, d } = p;\n if (k.x1 <= a + EPS || k.x0 >= c - EPS || k.y1 <= b + EPS || k.y0 >= d - EPS) continue;\n const cut: Box[] = [\n { a, b, c: Math.min(c, k.x0), d },\n { a: Math.max(a, k.x1), b, c, d },\n { a, b, c, d: Math.min(d, k.y0) },\n { a, b: Math.max(b, k.y1), c, d },\n ].filter((q) => q.c - q.a > EPS && q.d - q.b > EPS);\n p = cut.length === 0 ? null : cut.reduce((q, s) => ((s.c - s.a) * (s.d - s.b) > (q.c - q.a) * (q.d - q.b) ? s : q));\n if (!p) break;\n }\n if (!p) continue;\n // A part a clear rect cut keeps `minLength` along the axis; a part nothing cut is the clipped box (thinned or not).\n const touched = Math.abs(p.a - kept.a) > EPS || Math.abs(p.b - kept.b) > EPS || Math.abs(p.c - kept.c) > EPS || Math.abs(p.d - kept.d) > EPS;\n if (touched && (alongX ? p.c - p.a : p.d - p.b) < longEnough) continue;\n const placed = place(g, { x: p.a, y: p.b, width: p.c - p.a, height: p.d - p.b });\n // The side names the part: `<id>` before any full-thickness cut, `<id>#<k + 1>` after k of them.\n const id = (g as { id?: unknown }).id;\n out.push(span.k === 0 || typeof id !== \"string\" ? placed : { ...placed, id: `${id}#${span.k + 1}` });\n }\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 // A line thinner than `lineThickness` is widened to it, centered on its own position, before anything else is\n // applied (a non-finite thickness is left as is: it is dropped below).\n const own = thinX ? r.width : r.height;\n const widen = g.kind === \"line\" && own < lineThickness;\n // Along its thickness: moved inside whole; along its length: clipped.\n const t = widen ? lineThickness : own;\n let lo = (thinX ? r.x : r.y) - (widen ? (lineThickness - own) / 2 : 0);\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 l0 = Math.max(thinX ? r.y : r.x, thinX ? y0 : x0);\n const l1 = Math.min(thinX ? r.y + r.height : r.x + r.width, thinX ? y1 : x1);\n if (l1 - l0 <= EPS) continue;\n // Each clear rect, grown by its clearance: its extent along the guide's length (a, b) and across its thickness (c0, c1).\n const around = clear.map(({ k: c, gap }) => ({\n a: (thinX ? c.y : c.x) - gap,\n b: (thinX ? c.y + c.height : c.x + c.width) + gap,\n c0: (thinX ? c.x : c.y) - gap,\n c1: (thinX ? c.x + c.width : c.y + c.height) + gap,\n }));\n // A rect over the thickness that meets only one end of the length (its start or its end, not both, not the middle)\n // shortens the guide, as it trims a box: the guide keeps the part away from it. The ends are the clipped guide's, so\n // the order of the rects never matters.\n let s0 = l0;\n let s1 = l1;\n let shortened = false;\n for (const k of around) {\n if (k.b <= l0 + EPS || k.a >= l1 - EPS || k.c1 <= lo + EPS || k.c0 >= hi - EPS) continue;\n const atStart = k.a <= l0 + EPS;\n const atEnd = k.b >= l1 - EPS;\n if (atStart === atEnd) continue;\n if (atStart) s0 = Math.max(s0, k.b);\n else s1 = Math.min(s1, k.a);\n shortened = true;\n }\n // What is left of the length keeps `minLength`, as a part of a box a clear rect cut does.\n if (s1 - s0 <= EPS || (shortened && s1 - s0 < Math.max(EPS, minLength - EPS))) continue;\n // A rect over the middle of the length (or all of it) cuts across the thickness, from the side it lies on, where it\n // still lies over what is left.\n for (const k of around) {\n if (k.b <= s0 + EPS || k.a >= s1 - EPS || k.c1 <= lo + EPS || k.c0 >= hi - EPS) continue;\n if ((k.a <= l0 + EPS) !== (k.b >= l1 - EPS)) continue;\n // Keep the side away from the clear rect's middle.\n if ((k.c0 + k.c1) / 2 >= (lo + hi) / 2) hi = Math.min(hi, k.c0);\n else lo = Math.max(lo, k.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":";;;;;;;;AA6DA,IAAM,iBAAiB;AAuChB,IAAM,aAA+B,EAAE,MAAM,IAAI,OAAO,GAAG,KAAK,IAAI,UAAU,gBAAgB,OAAO,IAAI,OAAO,KAAK,MAAM,KAAK,cAAc,KAAK,WAAW,KAAK;AAG1K,IAAM,WAAW;AAEV,SAAS,gBAAgB,UAAqC,CAAC,GAAc;AAClF,QAAM,IAAI,EAAE,GAAG,YAAY,GAAG,QAAQ;AACtC,MAAI,UAAqC,CAAC;AAE1C,MAAI,SAAS;AAEb,MAAI,OAAO;AACX,MAAI,OAAsB;AAE1B,MAAI,QAAoC,CAAC;AAEzC,MAAI,SAAwB;AAE5B,MAAI,SAAwB;AAC5B,QAAM,OAAO,CAAC,GAAU,MAAqB,KAAK,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;AAE5E,QAAM,OAAO,MAAc;AACzB,QAAI,MAAM;AACV,aAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,IAAK,QAAO,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