@n-uf/motion 26.11.54 → 26.11.56

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.
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/drag/intent.ts","../src/drag/guide-rects.ts","../src/drag/hand-speed.ts","../src/drag/landing.ts","../src/drag/preview.ts","../src/drag/grip.ts"],"sourcesContent":["import { isHeld, type ModifierKey, type Modifiers } from \"../keys\";\nimport type { Point, Rect } from \"../shapes\";\n\n/**\n * The drag intent model's tuning. Distances in px, speeds in px/ms, times in\n * ms; every value can be overridden per intent (see\n * {@link DragIntentOptions.tuning}).\n */\nexport interface DragTuning {\n /** A mouse press lifts once the pointer has moved this far. */\n readonly lift: number;\n /** A touch press lifts only after it has been held this long… */\n readonly touchHold: number;\n /** …and then moved this far (moving that far before the hold is over is not a drag). */\n readonly touchLift: number;\n /** The pointer's speed is measured over this window and smoothed. */\n readonly speedWindow: number;\n /** Aiming: the smoothed speed is below this… */\n readonly aimSpeed: number;\n /** …or the pointer has stayed within `still` px of one spot for `dwell` ms. */\n readonly still: number;\n readonly dwell: number;\n /** The current target holds while the pointer is within this band of its zone. */\n readonly band: number;\n /** A higher-priority target takes over at once when the pointer is this far inside it. */\n readonly breakthrough: number;\n /**\n * The band and the breakthrough scale with the zones: along each axis they are at most this share of the held\n * zone's extent and of the extent of the zone under the pointer (its `hit`), so a small zone (a 28 px row) can be\n * entered by a direct glide from its neighbor. Below a quarter, the pointer at a quarter of a zone is past them.\n */\n readonly bandShare: number;\n /** A gap between zones shorter than this keeps the current target (for a pointer that aims). */\n readonly gapGrace: number;\n /** Aiming, the shown target moves to another one only once that one has held this long. */\n readonly switchHold: number;\n /**\n * Room is made once the shown target, and the place in it, have held this long, so a pointer moving across targets\n * doesn't reflow the layout under it. A target with `opensRoom` holds this long before it shows, its room with it.\n */\n readonly roomAfter: number;\n /** The pointer has left the item's home once it is outside the home shrunk by this much on every side. */\n readonly homeInset: number;\n /**\n * Spring-loading: a target marked `arm: \"dwell\"` takes the drop only once the pointer has stayed in its zone this long\n * (ms); before that it is no target, so a fast pass, or a drop before it, lands on what lies beneath. 0 arms it at once.\n * Armed, its zone is its `armedHit` (the magnet: its band); moving out past that band's outer edge disarms it, and\n * re-entering needs a new full dwell. It arms only after the pointer has ENTERED its zone during the drag: the point\n * the drag starts at counts as not entered, so a drag that starts inside the zone (a 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. `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. `@n-uf/placement` exports the same value for its reference pick.\n */\nexport const REFUSAL_RANK = 2.5;\n\n/** A target's rank in the pick: its `priority`, a refusal's {@link REFUSAL_RANK}. Lower wins. */\nexport const pickRank = (t: Pick<DragTarget, \"priority\" | \"refuse\">): number => (t.refuse === true ? REFUSAL_RANK : t.priority);\n\n/** Whether `point` lies strictly inside `bounds` (none: everywhere). */\nconst within = (bounds: Rect | undefined, point: Point): boolean =>\n !bounds || (point.x > bounds.x && point.x < bounds.x + bounds.width && point.y > bounds.y && point.y < bounds.y + bounds.height);\n\n/** Whether `point` lies in `rect` grown by `margin` px on every side (shrunk, for a negative margin). */\nexport function inRect(rect: Rect, point: Point, margin = 0): boolean {\n return point.x >= rect.x - margin && point.x <= rect.x + rect.width + margin && point.y >= rect.y - margin && point.y <= rect.y + rect.height + margin;\n}\n\n/** How far `point` lies from `rect` (0 inside it). */\nconst distanceTo = (rect: Rect, point: Point): number =>\n Math.hypot(Math.max(rect.x - point.x, 0, point.x - (rect.x + rect.width)), Math.max(rect.y - point.y, 0, point.y - (rect.y + rect.height)));\n\n/** Whether `point` lies in a target's zone (`hits` when it has them, else `hit`), grown by `margin` px, and inside its `bounds`. */\nconst inZone = (t: DragTarget, point: Point, margin = 0): boolean => within(t.bounds, point) && (t.hits ? t.hits.some((r) => inRect(r, point, margin)) : inRect(t.hit, point, margin));\n\n/** A margin per axis: px grown (shrunk, when negative) left and right, and above and below. */\ninterface Margin {\n readonly x: number;\n readonly y: number;\n}\n/**\n * Whether `point` lies in a target's zone grown by `m.x` px left and right and `m.y` px above and below, and inside its\n * `bounds`: a band never reaches past a zone's bounds (the float's band holds nothing outside the window).\n */\nconst inZoneBy = (t: DragTarget, point: Point, m: Margin): boolean =>\n within(t.bounds, point) && (t.hits ?? [t.hit]).some((r) => point.x >= r.x - m.x && point.x <= r.x + r.width + m.x && point.y >= r.y - m.y && point.y <= r.y + r.height + m.y);\n/** `px`, but along each axis at most `share` of each zone's extent (its `hit`) along it. */\nconst scaled = (px: number, share: number, zones: readonly (DragTarget | null)[]): Margin => {\n let x = px;\n let y = px;\n for (const z of zones) {\n if (!z) continue;\n x = Math.min(x, share * z.hit.width);\n y = Math.min(y, share * z.hit.height);\n }\n return { x, y };\n};\nconst negate = (m: Margin): Margin => ({ x: -m.x, y: -m.y });\n\nconst area = (r: Rect): number => r.width * r.height;\n/** A target's zone's area: its `hits` together, else its `hit`. */\nconst zoneArea = (t: DragTarget): number => (t.hits ? t.hits.reduce((s, r) => s + area(r), 0) : area(t.hit));\n\n/**\n * The most precise target under `point`: the lowest rank ({@link pickRank}: the priority, a refusal's\n * {@link REFUSAL_RANK}), then the smallest zone; null when none is. A zone holds its edges (a closed rect), except\n * toward the outside of its `bounds`.\n */\nexport function targetAt<T extends DragTarget>(targets: readonly T[], point: Point): T | null {\n let best: T | null = null;\n for (const t of targets) {\n if (!inZone(t, point)) continue;\n if (!best || pickRank(t) < pickRank(best) || (pickRank(t) === pickRank(best) && zoneArea(t) < zoneArea(best))) best = t;\n }\n return best;\n}\n\n/** What a press does so far: not yet a drag (`wait`), a drag (`lift`), or never one (`refuse`: a touch that moved too soon). */\nexport type LiftDecision = \"wait\" | \"lift\" | \"refuse\";\n\n/**\n * The lift rule for a press that has moved `distance` px in `elapsed` ms. A\n * mouse (or pen) lifts at `lift` px. A touch lifts only after `touchHold` ms,\n * then at `touchLift` px; moving `touchLift` px before the hold is over\n * refuses the drag (the finger is scrolling or swiping).\n */\nexport function liftDecision(press: { readonly touch: boolean; readonly distance: number; readonly elapsed: number }, tuning: Partial<DragTuning> = {}): LiftDecision {\n const t = { ...DRAG_DEFAULTS, ...tuning };\n if (!press.touch) return press.distance >= t.lift ? \"lift\" : \"wait\";\n if (press.elapsed < t.touchHold) return press.distance >= t.touchLift ? \"refuse\" : \"wait\";\n return press.distance >= t.touchLift ? \"lift\" : \"wait\";\n}\n\n/** One update's answer. */\nexport interface DragFrame<T extends DragTarget> {\n /** The target the drop indicator shows, or null. */\n readonly shown: T | null;\n /**\n * The others make room for the shown target: it, and the place in it, have held `roomAfter` ms. For a target with\n * `opensRoom`, or an armed spring-loaded one, from the first frame that shows it.\n */\n readonly room: boolean;\n /**\n * The place the room is made for, or null. Within one target it stays on\n * the old place until a new one has held `roomAfter` ms (see\n * {@link DragIntentOptions.placeOf}).\n */\n readonly roomPlace: string | null;\n /** The pointer is aiming: slow, or nearly still for a moment. */\n readonly aiming: boolean;\n /**\n * The pointer is back inside `home` after it has been outside `home` itself. Never true at the press, nor while the\n * pointer only moves about inside `home`, even near its edge (where `state.leftHome` is already true: that flag is for\n * the indicator's gate and uses `homeInset`; this one does not). Over home no target is shown and a release does\n * nothing, so a host that wants to say \"a drop here returns it\" draws its own indicator for this frame (at the home\n * rect); the intent still shows no target. 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 /** Where the item was lifted from: the indicator stays off until the pointer leaves it, and a release there does nothing. */\n readonly home: Rect;\n /** Where the press that lifted the item was (the grip); default the first sample's point. The lift zone is about it. */\n readonly lift?: Point;\n /**\n * The 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.\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). */\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 = { ...options.home };\n let samples: { x: number; y: number; t: number }[] = [];\n let cur: T | null = null;\n let curSince = 0;\n let lastInside = 0;\n let shown: T | null = null;\n let shownSince = 0;\n let place: string | null = null;\n let placeSince = 0;\n let roomPlace: string | null = null;\n let leftHome = false;\n // The pointer has been outside `home` itself (`leftHome` turns on already near its edge): `atHome`'s own memory.\n let wentOut = false;\n let speed = 0;\n let anchor: Point | null = null;\n let stillSince = 0;\n let restart = false;\n // The 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 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 (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 samples.push({ x: p.x, y: p.y, t });\n while (samples.length > 2 && t - samples[0]!.t > tuning.speedWindow) samples.shift();\n const a = samples[0]!;\n speed = speed * 0.5 + (Math.hypot(p.x - a.x, p.y - a.y) / Math.max(1, t - a.t)) * 0.5;\n if (!anchor || Math.hypot(p.x - anchor.x, p.y - anchor.y) > tuning.still) {\n anchor = { x: p.x, y: p.y };\n stillSince = t;\n }\n if (!inRect(home, p, -tuning.homeInset)) leftHome = true;\n const atHome = inRect(home, p);\n if (!atHome) wentOut = true;\n // Each target's place at this point, worked out once per sample; a null place is no target.\n const places = new Map<string, string | null>();\n const placeAt = (x: T): string | null => {\n if (!places.has(x.id)) places.set(x.id, placeOf(x, p, lastPlaces.get(x.id) ?? null));\n return places.get(x.id)!;\n };\n const live = (x: T | null): x is T => x !== null && placeAt(x) !== null;\n // Spring-loading: the armed target holds while the pointer is in its armed zone; a target the pointer dwells in\n // arms once it has held `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.\n const p = clampInto(point);\n if (!lastPoint || lastPoint.x !== p.x || lastPoint.y !== p.y) update(p, time, given, keys);\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 home = { ...home, x: home.x + dx, y: home.y + dy };\n },\n };\n}\n","import type { Rect } from \"../shapes\";\n\n/** A guide to place: any record with a `kind` and a `rect` (a landing model's `LandingGuide`, a lane's marks). */\nexport interface PlacedGuide {\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n /**\n * 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). */\nexport const 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 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","import 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 (a rest, a hesitation, a host that stopped sending) starts the hand\n * again: the samples before it never count, and the gap's own step is unknown (Infinity) unless it is no longer than\n * `slowStep` px (a hand creeping a pixel at a time, which reads slow), so a rest is never averaged into the next fling.\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 /** 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 starts the hand again, 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 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, so a hesitation of 40 ms or more starts the hand again; a\n * landing model takes the smaller of it and its `pause`); steady up to 1.5 times.\n */\nexport const HAND_SPEED: HandSpeedOptions = { span: 48, steps: 5, gap: 40, slowStep: HAND_SLOW_STEP, accelerating: 1.5, gathering: 1.25 };\n\nexport function createHandSpeed(options: Partial<HandSpeedOptions> = {}): HandSpeed {\n const o = { ...HAND_SPEED, ...options };\n let samples: { p: Point; t: number }[] = [];\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 return {\n push(p, t) {\n const last = samples[samples.length - 1];\n if (last && t - last.t >= o.gap) {\n // A rest or a gap: the hand starts again here. The gap's step tells nothing about its speed (a fling out of a\n // rest), unless it is no longer than `slowStep` px: a hand creeping a pixel at a time is slow, whatever the gap.\n const d = Math.hypot(p.x - last.p.x, p.y - last.p.y);\n samples = [{ p, t }];\n step = d <= o.slowStep ? d / Math.max(1, t - last.t) : Infinity;\n long = null;\n longs = [];\n return;\n }\n step = last ? Math.hypot(p.x - last.p.x, p.y - last.p.y) / Math.max(1, t - last.t) : Infinity;\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 let path = 0;\n for (let i = 1; i < samples.length; i++) path += Math.hypot(samples[i]!.p.x - samples[i - 1]!.p.x, samples[i]!.p.y - samples[i - 1]!.p.y);\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 reset() {\n samples = [];\n step = Infinity;\n long = null;\n longs = [];\n },\n get step() {\n return step;\n },\n get long() {\n return long;\n },\n get speed() {\n return long === null ? step : Math.max(step, 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 && step <= long * o.accelerating && !!then && longs[longs.length - 1]!.t - then.t >= o.span / 2 && long <= then.v * o.gathering;\n },\n };\n}\n","import type { Point, Rect } from \"../shapes\";\nimport { guideRects, LINE_THICKNESS, MIN_BOX_LENGTH } from \"./guide-rects\";\nimport { createHandSpeed, HAND_SPEED } from \"./hand-speed\";\nimport type { DragKeys } from \"./intent\";\nimport type { PlaceGuides } from \"./preview\";\nimport type { LandingRegion } from \"./region\";\n\n/**\n * The landing model: where a docking drag's item lands, as state rather than a per-frame guess. A host gives it the\n * drag's regions (from `@n-uf/docking`'s `lanes()`: plain data, the shapes below) and each pointer sample; it\n * says the region the pointer is in, the lane and spot held, where the item lands, whether the room is open, and the\n * place guides. Every change comes from where the pointer is and how it moved (margins, a path length, a step size):\n * the model has no waits of its own.\n *\n * - **The stage's edge** is the easiest place to dock: a pointer past the stage by up to `edge` px counts as on its\n * edge, so it lies deep inside a lane drawn against that edge; beyond, it is nowhere.\n * - **A lane holds** while the pointer is inside its rect grown by `exit`, whatever lies under it. Inside, over a spot's\n * stretch it is at that spot; over a refused stretch of the lane, refused (\"Can't go here\"). (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. Inside a lane that touches the held one, past the held lane's exit margin, the held lane holds\n * until that lane's gate passes or the pointer has slid `path` px along it (across it at most a third as far) as a\n * steady slide no faster than `slideSpeed` (2 px/ms), as the hand's speed reads it: lane to lane never passes through the\n * 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 `path` past the held lane's exit margin the frame is held but refused (the lane\n * kept for its guides; no spot, no landing, nothing pending; a release goes home), sticky until the pointer is back\n * 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 (a rest, a hesitation) starts the hand again, so a rest is never averaged\n * into the next fling; and a slide counts only while the hand reads steady (not gathering speed). A host sampling\n * slower than 25 Hz (every step a gap) 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 a held state like a held lane: the drag starts in it, leaves it past `lift` and re-enters only within\n * `lift - spot`, so a wobble at its edge never flips a cut near the press.\n * - **Along a lane** the spot changes once the pointer is `spot` px past the boundary; where the change moves another\n * item (the two spots' `others` keys differ), on a step of at most `stepSpeed`, or once the held landing trails the\n * pointer by more than `trail`: the item chases only as far as it must. A change that moves only the held item\n * follows the hand at any speed. With `regionsFor`, a reflowing change is kept only if, in the new spot's own regions\n * (its room open), the pointer still lies in that spot's stretch: the room shifting the boundary never bounces it.\n * - **A sliding spot** (`slide`: a free stretch as one spot) lands where the hand is: its landing moved along the lane to\n * the pointer less the grab (`grab`), clamped to its range, and snapped to its ends, the item's own place or a dock\n * inside within `snapDistance`. Nothing reflows inside it, so there are no steps there; a step comes only where the\n * order changes (passing a neighbor), as between any two spots. A release reads where it starts (`at`) once.\n * - **Outside every lane:** a refused place, refused; open space (`\"open\"`: the content less what blocks it, the page),\n * the float at its landing; outside the stage (past `edge`), nowhere; else (docked content that takes nothing and\n * refuses nothing) refused.\n * - **Shift** turns a lane or open space into open space (the float), and hides the guides.\n * - **Guides** are the lane's `marks` (lines between items, a box per free stretch, in the layout as drawn), else its\n * spots' landings. `\"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) shows its `entry` marks where it has them (docking's\n * prediction of an empty lane's marks once entered), so its guide before entry is its mark after it. Its guide leaves\n * out the held toolbar at the landing it takes there (held) or would take (the spot the pointer picks, a sliding\n * spot's start from the grab), never at its floating rect, so a host passes no held rect in `guideRects`' `clear`; a\n * part that cut leaves no longer than `MIN_BOX_LENGTH` (the padding before a clamped landing) is not drawn. `\"all\"`\n * shows every lane's; the lane the Near rule picks shows its `entry` and owns the corners it shares: each lane it\n * names in `corners` is cut by what the owner draws (its guide, less the landing), by the interval subtraction of\n * `guideRects`, but only where that mark covers the lane's marks across their whole thickness; otherwise the named\n * lane keeps the corner and the owner's mark gives the overlap up. Every mark is compared as it is drawn: inside its\n * lane's `rect`, a line at its drawn thickness (2 px). Under `\"near\"` too the Near lane's `entry` is clipped to its\n * `rect`. With no Near lane, the corner goes to the lane with `entry` nearest the pointer within `reach`, for the\n * corner only (it isn't made Near, pending or enterable). Beyond reach of every such lane, every lane's `marks`,\n * where the bar keeps a shared corner. No two lanes' guides overlap on any frame.\n * - Steps are speeds (px/ms) between points that differ, so the gates read the same at any input rate. 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. Call it at\n * least once more after the pointer stops (every frame does), so it can become still, and again with the same point\n * when a key changes. `release(point, time)` takes the release point as one more sample when it differs from the last.\n * Give `setRegions` the `regionsFor` that answers for the new state.\n */\n\n/** A place a drop in a lane lands: its stretch of the lane and its landing rect. Ids are stable across solves. */\nexport interface LandingSpot {\n readonly id: string;\n readonly along: readonly [number, number];\n readonly landing: Rect;\n /**\n * Where its drop draws every other item, as a key: a change between two spots with the same key moves only the held\n * item. Absent: every change to or from it counts as moving others.\n */\n readonly others?: string;\n /**\n * A sliding spot (a free stretch exposed as one spot): over it the landing follows the pointer, `landing` moved along\n * the lane to the pointer less the grab, clamped to `[from, to]` and snapped to a point of `snaps` within\n * `snapDistance`, else on whole pixels (`step`). Absent: the landing is `landing`.\n */\n readonly slide?: LandingSlide;\n}\n/** A sliding spot's range: where its landing's start may lie along the lane, and the points it snaps to. */\nexport interface LandingSlide {\n /** The landing's start at the stretch's start (flush against the neighbor before it), px along the lane. */\n readonly from: number;\n /** The landing's start at the stretch's end (flush against the neighbor after it), px along the lane. */\n readonly to: number;\n /** The starts it snaps to: its two ends, the item's own place where it lies here, any discrete dock inside. */\n readonly snaps: readonly number[];\n /** How near a snap point the landing's start snaps to it, px (default `SNAP_DISTANCE`). */\n readonly snapDistance?: number;\n /**\n * The grain of a start that snaps to nothing, px: a multiple of `step`, clamped to `[from, to]` (default 1, whole\n * pixels; 0: wherever the pointer puts it). Give the step the spot's commit uses, so the frame, the release's `at`\n * and the commit agree.\n */\n readonly step?: number;\n}\n/** The grain of a sliding spot's free start, px, when it names none: whole pixels. */\nconst SLIDE_STEP = 1;\n/** How near a sliding spot's snap point its landing snaps to it, px. */\nexport const SNAP_DISTANCE = 8;\n/**\n * A place guide's mark, in the layout as drawn: a line between two items that touch, a box over free room the item\n * lands in, a hatch over the part of a neighbor that gives way where the room is shorter than the item.\n */\nexport interface LandingMark {\n /** Stable while its neighbors stay; absent, the guide is keyed by its lane and place in the list. */\n readonly id?: string;\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n}\nexport interface LandingLane {\n readonly id: string;\n readonly rect: Rect;\n readonly axis: \"x\" | \"y\";\n readonly spots: readonly LandingSpot[];\n readonly refused: readonly { readonly along: readonly [number, number] }[];\n /** Its guides' marks; absent, its spots' landings are the guides. */\n readonly marks?: readonly LandingMark[];\n /**\n * Its marks while it is the lane the pointer picks (held, pending or approached), where they differ from `marks`: a\n * prediction of its marks once entered that owns a corner `marks` gives up (docking's `lanes()` gives it for an empty\n * lane). Shown in place of `marks` then, clipped to this lane's `rect` (a mark is drawn inside its lane), and under\n * `\"all\"` every lane in `corners` is cut where it overlaps what is drawn of it, if that covers the lane's marks across\n * their whole thickness; else that lane keeps the corner.\n */\n readonly entry?: readonly LandingMark[];\n /**\n * The lanes whose marks `entry` overlaps: while this lane is the one the pointer picks (or the nearest within reach)\n * each is cut where its marks overlap this lane's drawn mark, only where that mark covers them across their whole\n * thickness; otherwise the named lane keeps the corner.\n */\n readonly corners?: readonly string[];\n /**\n * Its rect is its own (a rail drop strip at the window's side): inside it, once its gate passes, it takes the pointer\n * from any lane it overlaps, a held one too. Absent: where lanes overlap, the deeper one wins.\n */\n readonly owns?: boolean;\n}\n/** A drag's regions (`lanes()` gives them). */\nexport interface LandingRegions {\n readonly lanes: readonly LandingLane[];\n readonly refused: readonly Rect[];\n readonly content: Rect;\n readonly blocked: readonly Rect[];\n readonly stage: Rect;\n /** The held item's size. */\n readonly item: { readonly width: number; readonly height: number };\n}\n\nexport interface LandingMargins {\n /** Past a held lane's rect before it lets go, px. */\n readonly exit: number;\n /** Past a spot boundary before the spot changes, px. */\n readonly spot: number;\n /** Past the stage that still counts as on its edge, px; beyond, nowhere. */\n readonly edge: number;\n /**\n * Around the lift point, px (16, as the drag intent's `liftZone`): an owning lane never takes the pointer there, so\n * away and back to where the item was lifted is home.\n */\n readonly lift?: number;\n}\nexport interface LandingGates {\n /** Pointer path inside a lane that enters it, px. */\n readonly path: number;\n /** Depth inside a lane where a still step enters it, px. */\n readonly depth: number;\n /** 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\nexport const LANDING_MARGINS: LandingMargins = { exit: 12, spot: 6, edge: 48, lift: 16 };\n/** A touch: wider margins, the finger's jitter. */\nexport const LANDING_TOUCH_MARGINS: LandingMargins = { exit: 16, spot: 8, edge: 48, lift: 16 };\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\nexport interface LandingOptions {\n readonly regions: LandingRegions;\n /** The regions with `spot` held (its room open): the fixed-point check and the stretches while held. Cached per id. */\n readonly regionsFor?: (spot: string) => LandingRegions | null;\n /** The float's landing for a pointer over the document, or null where the item doesn't float. */\n readonly floatLanding?: (point: Point) => Rect | null;\n /** The item's own place at the lift: its lane and spot (the drag starts there, the room open). */\n readonly home?: { readonly lane: string; readonly spot: string };\n /** Where the item was lifted (the press), in the regions' space; default the first point `update` gets. */\n readonly lift?: Point;\n /**\n * Where the pointer holds the item, from its top left corner as it is now, px (the press's, as `lanes()` takes it).\n * Over a sliding spot the landing's start is the pointer less this, along the item's own length (its longer side; a\n * landing of another length at the same share of it); across it, and in a lane across its length, the middle.\n * Default: the middle of `regions.item`.\n */\n readonly grab?: Point;\n readonly margins?: Partial<LandingMargins>;\n readonly gates?: Partial<LandingGates>;\n readonly approach?: Partial<LandingApproach>;\n readonly placeGuides?: PlaceGuides;\n}\n\nexport type { LandingRegion };\n\n/** A guide: a mark of a lane, where to draw it now (a spot's landing is a box). */\nexport interface LandingGuide {\n /** Stable while its neighbors stay: the mark's id, else `<lane>/<spot id>` for a spot's landing. Key a drawing by it. */\n readonly id: string;\n readonly lane: string;\n /** A line, a box, or a hatch over a neighbor that gives way (draw it over that item, in the guides' color). */\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n}\n\nexport interface LandingFrame {\n readonly region: LandingRegion;\n /** The lane held (also over its refused stretch), or null. */\n readonly lane: string | null;\n /** The spot held, or null. */\n readonly spot: string | null;\n /** Where a release now lands: the spot's landing, or the float's; null where it lands nowhere (the item goes home). */\n readonly landing: Rect | null;\n /** The room is open: a spot is held in a lane, no Shift. */\n readonly room: boolean;\n readonly guides: readonly LandingGuide[];\n /** Shift held: the region is open space wherever it was a lane or open space. */\n readonly shift: boolean;\n /**\n * The lane the pointer is inside but hasn't entered (its gate not passed yet: a fast pass, or the moment before a slow\n * step), else absent. A host shows no \"Can't go here\" while it is set, though a release now lands nowhere: the place\n * under the pointer is a lane's, not a refused one.\n */\n readonly pending?: string;\n}\n\n/**\n * What a release lands: a spot (`home` when it is the item's own place), the float at `rect`, or nothing. On a sliding\n * spot, `at` is where the landing starts along the lane, as the frame shows it (read once, at the release: a snap\n * point, else on the spot's `step`), and `home` holds only where that is the item's own place.\n */\nexport type LandingRelease =\n | { readonly kind: \"spot\"; readonly lane: string; readonly spot: string; readonly home: boolean; readonly at?: number }\n | { readonly kind: \"float\"; readonly rect: Rect }\n | null;\n\nexport interface LandingModel {\n update(point: Point, time: number, keys?: DragKeys): LandingFrame;\n /**\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 */\n release(point: Point, time: number, keys?: DragKeys): LandingRelease;\n /**\n * The regions changed (a resize, a store change, a scroll): spots map by id; a lost one goes to its lane's nearest.\n * Pass the `regionsFor` that answers for the new state; without one, the old one stays (it must then read live state).\n */\n setRegions(regions: LandingRegions, regionsFor?: (spot: string) => LandingRegions | null): void;\n /** The view moved under the pointer: the gates start again, the lane is let go. */\n hide(): void;\n readonly frame: LandingFrame;\n}\n\nconst inside = (r: Rect, p: Point, grow = 0): boolean => p.x >= r.x - grow && p.x <= r.x + r.width + grow && p.y >= r.y - grow && p.y <= r.y + r.height + grow;\nconst strictlyIn = (r: Rect, p: Point): boolean => p.x >= r.x && p.x <= r.x + r.width && p.y >= r.y && p.y <= r.y + r.height;\n/**\n * How deep `p` lies inside `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 distanceTo = (r: Rect, p: Point): number => Math.hypot(Math.max(r.x - p.x, 0, p.x - (r.x + r.width)), Math.max(r.y - p.y, 0, p.y - (r.y + r.height)));\nconst alongOf = (lane: LandingLane, p: Point): number => (lane.axis === \"x\" ? p.x : p.y);\nconst acrossOf = (lane: LandingLane, p: Point): number => (lane.axis === \"x\" ? p.y : p.x);\n/** Two rects meet: they overlap or touch (within 1 px), corners included. */\nconst touches = (a: Rect, b: Rect): boolean => a.x <= b.x + b.width + 1 && b.x <= a.x + a.width + 1 && a.y <= b.y + b.height + 1 && b.y <= a.y + a.height + 1;\n/** `p` onto `stage` when it lies past it by at most `reach`; else null (nowhere). */\nfunction ontoStage(stage: Rect, p: Point, reach: number): Point | null {\n if (!inside(stage, p, reach)) return null;\n return { x: Math.min(Math.max(p.x, stage.x), stage.x + stage.width), y: Math.min(Math.max(p.y, stage.y), stage.y + stage.height) };\n}\n\nexport function createLandingModel(options: LandingOptions): LandingModel {\n const margins = { ...LANDING_MARGINS, ...options.margins };\n const gates = { ...LANDING_GATES, ...options.gates };\n const approach = { ...LANDING_APPROACH, ...options.approach };\n const guidesLevel: PlaceGuides = options.placeGuides ?? \"off\";\n let base = options.regions;\n let regionsFor = options.regionsFor;\n const cache = new Map<string, LandingRegions | null>();\n /** The regions with `spot` held: the host's, cached for this lift until `setRegions`. */\n const heldRegions = (spot: string | null): LandingRegions => {\n if (!spot || !regionsFor) return base;\n if (!cache.has(spot)) cache.set(spot, regionsFor(spot));\n return cache.get(spot) ?? base;\n };\n\n let laneId: string | null = options.home?.lane ?? null;\n let spotId: string | null = options.home?.spot ?? null;\n let last: { p: Point; raw: Point; t: number } | null = null;\n /** The last point that differed from the one before, and the step then. */\n let moved: { raw: Point; t: number } | null = null;\n /** Where the item was lifted (`lift`, else the first point), fixed for the drag: back there, no owning lane takes it. */\n let liftAt: Point | null = options.lift ?? null;\n /** Whether the pointer is held in the lift zone (`nearLift`). */\n let inLiftZone = true;\n /** 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 hand = createHandSpeed({ gap: Math.min(HAND_SPEED.gap, gates.pause) });\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, landing: null, room: !!spotId, guides: [], shift: false };\n /** The spot the last frame lands on (in its own regions) and its lane's axis, or null. */\n let landedOn: { readonly spot: LandingSpot; readonly axis: \"x\" | \"y\" } | null = null;\n\n const laneIn = (regions: LandingRegions, id: string | null): LandingLane | undefined => (id ? regions.lanes.find((l) => l.id === id) : undefined);\n const spotIn = (lane: LandingLane | undefined, id: string | null): LandingSpot | undefined => (lane && id ? lane.spots.find((s) => s.id === id) : undefined);\n\n /** The spot a point along `lane` picks: the spot whose stretch holds it, null over a refused stretch, else the nearest. */\n function pick(lane: LandingLane, a: number): LandingSpot | null {\n if (lane.refused.some((r) => a >= r.along[0] && a <= r.along[1])) return null;\n const hit = lane.spots.find((s) => a >= s.along[0] && a <= s.along[1]);\n if (hit) return hit;\n let best: LandingSpot | null = null;\n let dist = Infinity;\n for (const s of lane.spots) {\n const d = a < s.along[0] ? s.along[0] - a : a - s.along[1];\n if (d < dist) {\n best = s;\n dist = d;\n }\n }\n return best;\n }\n\n /**\n * Where `spot` lands for a pointer at `p` in `lane`: its landing, or on a sliding spot that landing moved along the lane\n * to the pointer less the grab, clamped to its range and snapped to the nearest snap point within its snap distance.\n */\n function landingAt(lane: LandingLane, spot: LandingSpot, p: Point, item: { readonly width: number; readonly height: number }): Rect {\n const s = spot.slide;\n if (!s) return spot.landing;\n const ax = lane.axis;\n // The grab's share along the item's own length (its longer side); across it, or a lane across its length, the middle.\n const long: \"x\" | \"y\" = item.width >= item.height ? \"x\" : \"y\";\n const size = long === \"x\" ? item.width : item.height;\n const g = options.grab ? (long === \"x\" ? options.grab.x : options.grab.y) : size / 2;\n const share = ax === long && size > 0 && Number.isFinite(g) ? Math.min(1, Math.max(0, g / size)) : 0.5;\n const length = ax === \"x\" ? spot.landing.width : spot.landing.height;\n const lo = Math.min(s.from, s.to);\n const hi = Math.max(s.from, s.to);\n const free = Math.min(hi, Math.max(lo, alongOf(lane, p) - share * length));\n const reach = s.snapDistance ?? SNAP_DISTANCE;\n let at = free;\n let best = Infinity;\n for (const q of s.snaps) {\n const d = Math.abs(q - free);\n if (d <= reach && d < best) {\n best = d;\n at = q;\n }\n }\n // Snapped to nothing: the spot's grain (`LandingSlide.step`), the same rounding its commit applies.\n const step = s.step ?? SLIDE_STEP;\n if (best === Infinity && step > 0) at = Math.min(hi, Math.max(lo, Math.round(free / step) * step));\n return ax === \"x\" ? { ...spot.landing, x: at } : { ...spot.landing, y: at };\n }\n\n /** Along a held lane: the spot after hysteresis, the step gate and the fixed-point check. */\n function along(lane: LandingLane, p: Point, step: number): LandingSpot | null {\n const regions = heldRegions(spotId);\n const held = laneIn(regions, lane.id) ?? lane;\n const a = alongOf(held, p);\n const now = spotIn(held, spotId);\n const cand = pick(held, a);\n if (!cand) return null;\n if (!now || cand.id === now.id) return cand;\n // Past the boundary by the margin, the same everywhere (a wobble within it never flips the spot); where the change\n // moves another item, on a slow enough step. Else the last spot holds.\n const past = a < now.along[0] - margins.spot || a > now.along[1] + margins.spot;\n const reflows = now.others === undefined || now.others !== cand.others;\n if (!past) return now;\n // A fast reflowing change waits for a slow step, unless the held landing already trails the pointer by `trail`: the\n // item chases only as far as it must, so a fast hand across docked items never leaves it far behind.\n if (reflows && step > gates.stepSpeed && distanceTo(now.landing, p) <= gates.trail) return now;\n // The fixed point: in the candidate's own regions (its room open), the pointer still picks it.\n if (regionsFor && reflows) {\n const theirs = heldRegions(cand.id);\n const lane2 = laneIn(theirs, lane.id);\n if (lane2 && pick(lane2, alongOf(lane2, p))?.id !== cand.id) return now;\n }\n return cand;\n }\n\n function guidesFor(p: Point, region: LandingRegion, shift: boolean, pending: string | null, landing: Rect | null): LandingGuide[] {\n if (guidesLevel === \"off\" || shift) return [];\n const regions = heldRegions(spotId);\n /**\n * A lane's guides: its `marks` as they are, or while it is the lane the pointer picks (`near`) its `entry` inside its\n * rect; else a box per spot landing. What a lane returns is never clipped to its hit rect (a held layout draws its\n * marks outside it: placement keeps the hit rect as seen), but for that entry.\n */\n const all = (l: LandingLane, near = false): LandingGuide[] => {\n if (near && l.entry) return view(l, true);\n return l.marks ? l.marks.map((m, i) => ({ id: m.id ?? `${l.id}#${i}`, lane: l.id, kind: m.kind, rect: m.rect })) : view(l);\n };\n /**\n * A lane's marks as they are drawn, inside its rect (a box to the piece inside, a line kept whole or not at all, as\n * placement clips a lane's marks): the view the corner decision below compares and cuts, for the owner and for the\n * lanes it names alike. Never what a lane returns, but for a handed lane (cut from this) and the Near lane's entry.\n */\n function view(l: LandingLane, near = false): LandingGuide[] {\n const marks = near && l.entry ? l.entry : l.marks;\n if (!marks) return l.spots.map((s) => ({ id: `${l.id}/${s.id}`, lane: l.id, kind: \"box\" as const, rect: s.landing }));\n const box = l.rect;\n return marks.flatMap((m, i): LandingGuide[] => {\n const left = Math.max(m.rect.x, box.x);\n const top = Math.max(m.rect.y, box.y);\n const width = Math.min(m.rect.x + m.rect.width, box.x + box.width) - left;\n const height = Math.min(m.rect.y + m.rect.height, box.y + box.height) - top;\n const kept = width > m.rect.width - 1e-6 && height > m.rect.height - 1e-6;\n if (!kept && (m.kind === \"line\" || width <= 1e-6 || height <= 1e-6)) return [];\n return [{ id: m.id ?? `${l.id}#${i}`, lane: l.id, kind: m.kind, rect: kept ? m.rect : { x: left, y: top, width, height } }];\n });\n }\n const area = (a: Rect, c: Rect): boolean => Math.min(a.x + a.width, c.x + c.width) - Math.max(a.x, c.x) > 1e-6 && Math.min(a.y + a.height, c.y + c.height) - Math.max(a.y, c.y) > 1e-6;\n /** A guide's rect as it is drawn: a line thinner than `LINE_THICKNESS` is that thick, centered on its place. */\n const drawn = (g: LandingGuide): Rect => {\n const r = g.rect;\n const vertical = r.width <= r.height;\n const own = vertical ? r.width : r.height;\n if (g.kind !== \"line\" || own >= LINE_THICKNESS) return r;\n const d = (LINE_THICKNESS - own) / 2;\n return vertical ? { x: r.x - d, y: r.y, width: LINE_THICKNESS, height: r.height } : { x: r.x, y: r.y - d, width: r.width, height: LINE_THICKNESS };\n };\n /**\n * `gs` less the rects `cs`, by `guideRects`' interval subtraction; a guide they don't overlap stays as it is. With\n * `thick` a guide meets a rect by its drawn rect (a joint line is drawn 2 px thick: over a rect that took the corner\n * it is cut, not left drawn on it).\n */\n const less = (gs: readonly LandingGuide[], cs: readonly Rect[], thick = false): LandingGuide[] => {\n if (cs.length === 0) return [...gs];\n const clear = cs.map((rect) => ({ rect, clearance: 0 }));\n return gs.flatMap((g) => (cs.some((c) => area(thick ? drawn(g) : g.rect, c)) ? guideRects([g], { inside: g.rect, inset: 0, clear, minLength: 0, minThickness: 0 }) : [g]));\n };\n const near = nearLane(p, region, pending, regions);\n // The Near lane's guide less the held toolbar at the landing it takes there (held: the frame's landing) or would\n // take (pending or approached: the spot the pointer picks along it, a sliding spot's start from the grab), never\n // its floating rect: so the guide before entry is the mark after it, and a host passes no held rect.\n const wouldLand = (l: LandingLane): Rect | null => {\n if (l.id === laneId) return region === \"lane\" ? landing : null;\n const s = pick(l, alongOf(l, p));\n return s ? landingAt(l, s, p, regions.item) : null;\n };\n const nearGuides = (l: LandingLane): LandingGuide[] => {\n // (A lane with no marks shows its spots' landings: those are the guide, nothing to cut.)\n const at = l.marks || l.entry ? wouldLand(l) : null;\n if (!at) return all(l, true);\n // A box part this cut leaves `MIN_BOX_LENGTH` (8 px) or less along the lane (the bar's padding before a landing at\n // its clamp) is no room and is not drawn; a part the cut didn't touch is kept at any length, as `guideRects` keeps\n // one. (Left in, a host's `guideRects` would inset the stub to a few px, find it longer across the lane than along,\n // and keep it as a box across the lane, untrimmed and unthinned.)\n const longEnough = (g: LandingGuide): boolean => g.kind !== \"box\" || (l.axis === \"x\" ? g.rect.width : g.rect.height) > MIN_BOX_LENGTH;\n const whole = all(l, true);\n return less(whole, [at]).filter((g) => longEnough(g) || whole.some((w) => w.id === g.id && w.rect === g.rect));\n };\n if (guidesLevel === \"near\") return near ? nearGuides(near) : [];\n // \"all\": every lane's. The lane the pointer picks shows its marks once entered (`entry`). The corner two lanes share\n // goes to the Near lane, else to the lane nearest the pointer within `reach`, for the corner only (it isn't made\n // Near, pending or enterable): the lanes the owner names in `corners` are cut where they overlap what it draws, if\n // that covers their marks across their whole thickness, else they keep the corner. With neither, each lane's\n // `marks` (where two lanes would overlap, one already gave the corner up: the bar keeps it).\n const owns = (l: LandingLane | null | undefined): l is LandingLane => !!l && !!l.entry && !!l.corners?.length;\n let owner: LandingLane | null = owns(near) ? near : null;\n if (!owner && !near) {\n let d = approach.reach;\n for (const l of regions.lanes) {\n const dl = distanceTo(l.rect, p);\n if (owns(l) && dl <= d) {\n owner = l;\n d = dl;\n }\n }\n }\n // Where the corner goes is decided here, once, on marks as they will be drawn (`view`, `drawn`), the owner's and the\n // named lanes' alike; what a lane returns is never replaced by that view but where the corner is cut from it. The\n // owner shows its mark once entered less the landing it would take there, whether it is Near or only the corner's\n // owner by reach: the lane the pointer approaches shows what entry draws, with no jump at entry. A lane it names\n // hands the corner over only where that mark covers the lane's marks across their whole thickness; the lane is then\n // cut by exactly that mark. Else it keeps the corner and the owner's mark gives the overlap up (a lane that stops\n // short of the bar's band, or reaches only part of it, takes nothing it can't draw). Either way the named lane\n // leaves out the landing the held toolbar takes (or would take), as the owner's guide does: the stub the landing\n // leaves outside it stays the lane's.\n const ownerMarks = owner ? nearGuides(owner) : [];\n const cutBy = ownerMarks.map(drawn);\n const takes = (l: LandingLane): boolean => {\n const across = (r: Rect): readonly [number, number] => (l.axis === \"x\" ? [r.y, r.y + r.height] : [r.x, r.x + r.width]);\n return view(l).every((g) => {\n const mine = drawn(g);\n return cutBy.every((c) => !area(mine, c) || (across(c)[0] <= across(mine)[0] + 1e-6 && across(c)[1] >= across(mine)[1] - 1e-6));\n });\n };\n const named = owner ? owner.corners!.map((id) => regions.lanes.find((x) => x.id === id)).filter((x): x is LandingLane => !!x) : [];\n const handed = new Set(named.filter(takes).map((x) => x.id));\n const kept = named.filter((x) => !handed.has(x.id)).flatMap((x) => view(x).map(drawn));\n const at = owner && (owner.marks || owner.entry) ? wouldLand(owner) : null;\n /**\n * `gs` less the rect `r`, in two dimensions: a box keeps the pieces around it; a line it touches is shortened along\n * its length to the parts outside it, as `guideRects` shortens one (not drawn only where `r` covers all its length).\n */\n const without = (gs: readonly LandingGuide[], r: Rect | null): LandingGuide[] =>\n gs.flatMap((g) => {\n if (!r || !area(drawn(g), r)) return [g];\n const a = g.rect;\n if (g.kind === \"line\") {\n const vertical = a.width <= a.height;\n const from = vertical ? a.y : a.x;\n const to = from + (vertical ? a.height : a.width);\n const c0 = vertical ? r.y : r.x;\n const c1 = c0 + (vertical ? r.height : r.width);\n const spans: [number, number][] = [];\n if (c0 > from + 1e-6) spans.push([from, Math.min(to, c0)]);\n if (c1 < to - 1e-6) spans.push([Math.max(from, c1), to]);\n return spans.map(([s, e], k) => ({ ...g, id: k ? `${g.id}~l${k}` : g.id, rect: vertical ? { x: a.x, y: s, width: a.width, height: e - s } : { x: s, y: a.y, width: e - s, height: a.height } }));\n }\n const x0 = Math.max(a.x, r.x);\n const x1 = Math.min(a.x + a.width, r.x + r.width);\n const pieces: Rect[] = [];\n if (r.x > a.x) pieces.push({ x: a.x, y: a.y, width: r.x - a.x, height: a.height });\n if (r.x + r.width < a.x + a.width) pieces.push({ x: r.x + r.width, y: a.y, width: a.x + a.width - r.x - r.width, height: a.height });\n if (r.y > a.y) pieces.push({ x: x0, y: a.y, width: x1 - x0, height: r.y - a.y });\n if (r.y + r.height < a.y + a.height) pieces.push({ x: x0, y: r.y + r.height, width: x1 - x0, height: a.y + a.height - r.y - r.height });\n return pieces.map((rect, k) => ({ ...g, id: k ? `${g.id}~l${k}` : g.id, rect }));\n });\n return regions.lanes.flatMap((l) => {\n if (owner && l.id === owner.id) return less(ownerMarks, kept, true);\n if (near && l.id === near.id) return nearGuides(l);\n if (!named.some((x) => x.id === l.id)) return all(l);\n return without(handed.has(l.id) ? less(view(l), cutBy, true) : all(l), at);\n });\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(heldRegions(spotId).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 step = Math.hypot(raw.x - moved.raw.x, raw.y - moved.raw.y) / Math.max(1, t - moved.t);\n moved = { raw, t };\n hand.push(raw, t);\n // The step that ends a rest (a gap of 40 ms or `pause`, the smaller) says nothing about how the hand moves now:\n // unknown, never a slow step (a fling out of a rest docks nowhere on its first frame), unless it is no longer than\n // `HAND_SPEED.slowStep` (3) px (a hand creeping a pixel at a time, which is slow).\n step = 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) || sp > gates.stepSpeed) slowFrom = null;\n else slowFrom ??= before;\n } else if (moved) {\n const stage = heldRegions(spotId).stage;\n const onEdge = p.x <= stage.x || p.y <= stage.y || p.x >= stage.x + stage.width || p.y >= stage.y + stage.height;\n const since = t - moved.t;\n step = since >= gates.pause || (since >= gates.rest && (lastStep <= gates.stepSpeed || onEdge)) ? 0 : lastStep;\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 = heldRegions(spotId).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 = !!keys?.shift;\n const regions = heldRegions(spotId);\n // The path inside each lane: the part along the lane of slow steps from a point inside it to another (the step that\n // enters doesn't count, nor a fast one), so a crossing at `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 const slow = 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.\n const counts = hand.steady && hand.speed <= gates.slideSpeed;\n slide.set(l.id, !inL ? { along: 0, across: 0 } : counts ? { along: (s?.along ?? 0) + go, across: (s?.across ?? 0) + over } : (s ?? { along: 0, across: 0 }));\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 const gate = (l: LandingLane): boolean => (pathIn.get(l.id) ?? 0) >= gates.path || (depthIn(l, p, regions.stage) >= gates.depth && step <= gates.stillSpeed && settled);\n // Lane to lane: inside a lane touching the held one, past the held lane's exit margin (inside it the held lane holds,\n // P1), the held lane still holds until that lane's gate passes, then that lane takes it. Never the float between\n // them, never a fly-through's room.\n const touching = held ? regions.lanes.find((l) => l.id !== held.id && strictlyIn(l.rect, p) && touches(l.rect, held.rect) && !inside(held.rect, p, margins.exit)) : undefined;\n const sl = touching ? slide.get(touching.id) : undefined;\n // A fling (the hand's speed above `slideSpeed`) is no entry, along the lane as well as across it.\n const slid = !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along && hand.speed <= gates.slideSpeed;\n // A lane that owns its rect (a rail drop strip) takes the pointer inside it from any lane it overlaps, a held one\n // too, once its own gate passes (so a pass across it opens nothing), and only once the pointer came into it (it has\n // been outside it since the lift): a press in a column's outer edge, or a slow reorder along it, stays in the column.\n // Never within `lift` of where the item was lifted: away and back there is home, wherever a strip lies, while the\n // rest of the strip (all of it over a lone panel's own place) still takes it.\n // The zone is a held state, like a held lane: the drag starts in it, leaves it past `lift` of the lift point and\n // re-enters it only within `lift - spot`, so a wobble at its edge never flips a cut that lies near the press.\n const liftR = margins.lift ?? 16;\n if (liftAt) {\n const far = Math.hypot(p.x - liftAt.x, p.y - liftAt.y);\n inLiftZone = far <= (inLiftZone ? liftR : Math.max(0, liftR - margins.spot));\n }\n const nearLift = !!liftAt && inLiftZone;\n const owner = nearLift ? undefined : regions.lanes.find((l) => l.owns && l.id !== held?.id && cameIn.has(l.id) && strictlyIn(l.rect, p) && gate(l));\n // The lift zone is the item's own lane's: within `lift` of where it was lifted, in whatever lane the pointer came\n // through, the lane choice is the home lane (when the pointer lies in it, as the lift point did), and its spot the\n // item's own. So away and back to the lift point is home on every layout, a plain lane's band lying over the home\n // lane's corner included.\n const ownLane = nearLift && options.home ? laneIn(regions, options.home.lane) : undefined;\n const homeHere = ownLane && strictlyIn(ownLane.rect, p) ? ownLane : undefined;\n // 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 ?? (touching && (gate(touching) || slid || overRefused(touching)) ? touching : undefined));\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, margins.exit)))) 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, margins.exit))) {\n // The hold through a touching lane is for crossing a corner: more than `path` past the held lane's exit margin\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 previous = region;\n lastPending = pending;\n const shown: LandingRegion = shift && (region === \"lane\" || region === \"open\") ? \"open\" : region;\n const r2 = heldRegions(spotId);\n const heldLane = laneIn(r2, laneId);\n const spot = spotIn(heldLane, spotId);\n landedOn = shown === \"lane\" && spot && heldLane ? { spot, axis: heldLane.axis } : null;\n // A sliding spot's landing follows the pointer; any other spot's is its own.\n const landing = shown === \"lane\" ? (spot && heldLane ? landingAt(heldLane, spot, p, r2.item) : null) : shown === \"open\" ? (options.floatLanding?.(p) ?? null) : null;\n frame = {\n region: shown,\n lane: laneId,\n spot: shown === \"lane\" ? spotId : null,\n landing,\n room: shown === \"lane\" && !!spot,\n guides: guidesFor(p, shown, shift, pending && shown !== \"lane\" ? pending : null, landing),\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.\n if (!last || last.raw.x !== point.x || last.raw.y !== point.y) update(point, time, keys ?? lastKeys);\n if (frame.region === \"lane\" && frame.lane && frame.spot) {\n const ownSpot = !!options.home && options.home.spot === frame.spot && options.home.lane === frame.lane;\n // A sliding spot: where its landing starts, read once here (so a wobble never stores a jitter), exactly as the\n // frame shows it (a snap point, else on the spot's grain). It is home only at the item's own place: the home\n // spot's own landing.\n const on = landedOn;\n if (on?.spot.slide && frame.landing) {\n const start = (r: Rect): number => (on.axis === \"x\" ? r.x : r.y);\n const at = start(frame.landing);\n return { kind: \"spot\", lane: frame.lane, spot: frame.spot, home: ownSpot && Math.abs(at - start(on.spot.landing)) < 1e-6, at };\n }\n return { kind: \"spot\", lane: frame.lane, spot: frame.spot, home: ownSpot };\n }\n if (frame.region === \"open\" && frame.landing) return { kind: \"float\", rect: frame.landing };\n return null;\n },\n setRegions(regions: LandingRegions, nextRegionsFor?: (spot: string) => LandingRegions | null): void {\n base = regions;\n if (nextRegionsFor) regionsFor = nextRegionsFor;\n cache.clear();\n const l = laneIn(base, laneId);\n if (laneId && !l) laneId = spotId = null;\n else if (l && spotId && !spotIn(l, spotId) && last) spotId = pick(l, alongOf(l, last.p))?.id ?? null;\n },\n hide(): void {\n laneId = spotId = null;\n approached = null;\n 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 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/** 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\" : (p.placeGuides ?? PLACE_GUIDES_DEFAULT[p.mode]) };\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 { 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"],"mappings":";;;;;;AA6FO,IAAM,gBAA4B;AAAA,EACvC,MAAM;AAAA,EACN,WAAW;AAAA,EACX,WAAW;AAAA,EACX,aAAa;AAAA,EACb,UAAU;AAAA,EACV,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,cAAc;AAAA,EACd,WAAW;AAA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