@n-uf/motion 26.11.48 → 26.11.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,24 @@
3
3
  Versions are calendar versions, `YY.M.R` (year, month of the release, counter
4
4
  within the month), the same scheme as `@n-uf/hypr-tiling`.
5
5
 
6
+ ## 26.11.49
7
+
8
+ Guides placed inside the window, and no "Can't go here" while the pointer enters a lane. With `@n-uf/placement`
9
+ 26.11.49. Host notes: draw guides through `guideRects` (or keep your own placing); nothing else changes for a host.
10
+
11
+ - `./drag`, **`guideRects(guides, { inside, inset?, clear?, minThickness? })`** (additive): where to draw guides
12
+ inside a window. Every guide lies inside `inside` by `inset` (2 px). A box is clipped. A thin guide (a line, a
13
+ striped strip or end: its shorter side is its thickness) keeps its thickness and moves inside rather than being
14
+ clipped, so a line at a lane's far end is as thick as at its head. It is then thinned from the content side to stay
15
+ clear of `clear` (the content), so a thin strip lies between the inset and the content, the same on both sides. A
16
+ thin guide under `minThickness` (2 px) is left out. A guide already in place comes back as given (the same object).
17
+ `GuideRectsOptions` and `PlacedGuide` are its types.
18
+ - `./drag`, **`pending` past a held lane's rect** (fix): a pointer coming from a refused stretch of a column into a
19
+ docked rail beside it showed "Can't go here" in the rail's first pixels (the column still holds there, within its
20
+ exit margin, and refuses). The held lane still holds, so lane to lane never passes through the float, and where the
21
+ pointer is inside another lane it hasn't entered yet the frame names that lane `pending`: a host shows no "Can't go
22
+ here" while it is set.
23
+
6
24
  ## 26.11.48
7
25
 
8
26
  The landing model's guides gain a kind, and a lane over a place that takes nothing is easier to reach. With
package/README.md CHANGED
@@ -7,42 +7,32 @@
7
7
  >
8
8
  > Version numbers are dates (YY.M.R), not semantic versions, so any release may break things, including how frames are scheduled, how springs settle and how gestures are timed. Pin an exact version and read the [CHANGELOG](https://github.com/n-uf/motion/blob/main/packages/motion/CHANGELOG.md) before you upgrade. If you need a stable animation library, use [Motion](https://motion.dev) or [GSAP](https://gsap.com). Both work on the DOM, so neither is a drop-in replacement.
9
9
 
10
- Site and live demos: [motion.n-uf.com](https://motion.n-uf.com)
11
-
12
- One frame loop with an injected clock, fine-grained signals, springs and
13
- tweens, and a DOM-free gesture recognizer. No DOM, no framework, no globals:
14
- the host hands in a clock, and tests hand in a fake one.
10
+ How things move. One frame loop on an injected clock, fine-grained signals, values that animate (springs, tweens and one settle curve for moving windows), a DOM-free gesture recognizer, the drag intent and the landing model, and layout motion that glides a whole layout. No DOM, no framework, no globals: the host hands in a clock and plain event objects and reads plain numbers back, and tests hand in a fake clock.
15
11
 
16
12
  ```sh
17
13
  npm i @n-uf/motion
18
14
  ```
19
15
 
20
- - **clock/**: one frame loop that runs tasks in phases (input → update →
21
- layout → write) with a frame budget and stats, on a clock you pass in.
22
- - **signals/**: reactive values, computed values and effects; a change
23
- recomputes only what depends on it, and effects can run once per frame.
24
- - **values/**: springs and tweens over numbers, points, rects and vectors,
25
- stepped by the clock, with velocity that carries over a retarget, settle
26
- detection and a reduced-motion switch; and the window motion rules:
27
- `settle` (one fast-then-gentle curve that never passes its target), direct
28
- drag (`settle.hold`: what a pointer owns sits exactly under it) and `reveal`
29
- (glide a window without stretching its content).
30
- - **gestures/**: a recognizer that turns pointer, wheel and trackpad events
31
- (plain objects) into one gesture stream (click or drag, double click, long
32
- press, pinch, scroll, zoom, recovery from lost releases), a frame coalescer,
33
- and a dwell machine, for spring-loading.
16
+ ## Entry points
34
17
 
35
- One package, nine entries: `@n-uf/motion` (everything in the core), its four
36
- folders on their own (`@n-uf/motion/clock`, `/signals`, `/values`,
37
- `/gestures`), `@n-uf/motion/drag` (the drag intent), `@n-uf/motion/layout`
38
- (the window motion rules applied to a whole layout), `@n-uf/motion/testing`
39
- (frame-sampled checks of the motion rules, for tests and browser specs), and
40
- `@n-uf/motion/browser`, the clock on `requestAnimationFrame` and the
41
- reduced-motion media query. The core entries touch no DOM; importing several of
42
- them still gives one signal graph.
18
+ | Entry | What it gives |
19
+ |---|---|
20
+ | `@n-uf/motion` | Everything in `/clock`, `/signals`, `/values` and `/gestures`, and the shared value shapes (`Point`, `Rect`, `Vector`). |
21
+ | `@n-uf/motion/clock` | The frame loop (phases input, update, layout, write; a budget; stats) and a fake clock for tests. |
22
+ | `@n-uf/motion/signals` | `signal`, `computed`, `effect`, `batch`: a change recomputes only what depends on it, and effects can run once per frame. |
23
+ | `@n-uf/motion/values` | Springs, tweens and the settle curve, as motion values stepped by the loop; `reveal` and `popIn`; easing functions. |
24
+ | `@n-uf/motion/gestures` | The recognizer (click or drag, double click, long press, pinch, scroll, zoom), a frame coalescer, and state machines for touch press, paged swipe and dwell. |
25
+ | `@n-uf/motion/drag` | The drag intent (when a drop indicator shows, which target, what a release lands on), grip presses, drop previews and the landing model. |
26
+ | `@n-uf/motion/layout` | Layout motion: items glide to new rects, a held item follows the pointer 1:1 and lands, FLIP for DOM groups. |
27
+ | `@n-uf/motion/testing` | Frame-sampled checks of the motion rules (no overshoot, no jumps, held under the pointer), for tests and browser specs. |
28
+ | `@n-uf/motion/browser` | The clock on `requestAnimationFrame` and the reduced-motion media query. |
29
+
30
+ The core entries touch no DOM; importing several of them still gives one signal graph. `/drag`, `/layout`, `/testing` and `/browser` are not in the root.
43
31
 
44
32
  ## One frame
45
33
 
34
+ A pointer drives a spring that follows a target, and the DOM is written once per frame, only while something moves.
35
+
46
36
  ```ts
47
37
  import { computed, createFrameCoalescer, createFrameLoop, effect, signal, springValue } from "@n-uf/motion";
48
38
  import { createBrowserClock, prefersReducedMotion } from "@n-uf/motion/browser";
@@ -68,345 +58,9 @@ effect(() => {
68
58
  }, { schedule: loop.scheduler("write") });
69
59
  ```
70
60
 
71
- ## clock/
72
-
73
- | | |
74
- |---|---|
75
- | `ClockPort` | `{ now, requestFrame, cancelFrame, setTimer, clearTimer }`, the shape of hypr-tiling's `SchedulerPort`. |
76
- | `createFrameLoop({ clock, budgetMs?, frameMs?, maxDeltaMs?, maxRounds?, onError?, onOverBudget? })` | The loop. It requests a frame only while it has work. |
77
- | `loop.schedule(phase, task, { deferrable? })` | Run `task` once: this frame if `phase` is still ahead, else the next. Deduped by function; returns cancel. A `deferrable` task waits for a later frame when the budget is spent. |
78
- | `loop.repeat(phase, task)` | Run `task` every frame until it returns `false`; returns stop. |
79
- | `loop.scheduler(phase)` | For `effect(fn, { schedule })`: the effect runs in `phase`, at most once per frame. |
80
- | `loop.frames(phase)` | A frame source in that phase (for a coalescer). |
81
- | `loop.stats()` / `resetStats()` | Frames, frames over budget, deferred tasks, errors, last / max / mean frame ms, ms per phase, repeating and queued tasks. |
82
- | `createFakeClock({ now?, frameMs? })` | A clock that moves only when told: `tick(ms)`, `frame(dt?)`, `frames(n)`, `runUntilIdle()`, `spend(ms)` (work that takes time), `pendingFrames`, `pendingTimers`. |
83
-
84
- Each task gets `{ time, delta, index, phase, budgetMs, elapsed(), remaining() }`.
85
- `delta` is the time since the last frame, clamped to `maxDeltaMs` (default
86
- 64), and `frameMs` for the first frame after the loop was idle.
87
-
88
- Within a phase, one-shot tasks run first, then the repeating ones, then any
89
- one-shots they queued for that phase. A task queued for a later phase runs in
90
- the same frame; one queued for an earlier phase runs in the next.
91
-
92
- ```ts
93
- import { createFakeClock, createFrameLoop } from "@n-uf/motion";
94
-
95
- const clock = createFakeClock();
96
- const loop = createFrameLoop({ clock, budgetMs: 8 });
97
- loop.schedule("write", () => console.log("write"));
98
- loop.schedule("input", () => console.log("input"));
99
- clock.frame(); // input, write
100
- loop.stats(); // { frames: 1, overBudget: 0, ... }
101
- ```
102
-
103
- ## signals/
104
-
105
- | | |
106
- |---|---|
107
- | `signal(value, { equals? })` | Read and write `.value`; `peek()` reads without tracking. |
108
- | `computed(fn, { equals? })` | Lazy and cached; `fn(previous)`; a thrown error is kept and rethrown until a source changes. |
109
- | `effect(fn, { schedule? })` | Runs now and on every change; `fn` may return a cleanup. With `schedule`, runs go to the scheduler. Returns dispose. |
110
- | `batch(fn)`, `untracked(fn)`, `isSignal(x)` | |
61
+ ## A drag
111
62
 
112
- An effect's own writes don't re-run it; writes inside an effect are batched
113
- until it returns; effects that keep re-triggering each other throw instead
114
- of hanging. The graph algorithm is
115
- [alien-signals](https://github.com/stackblitz/alien-signals)' published core
116
- (`alien-signals/system`, the same core Vue 3.6 uses), under this API;
117
- [bench/RESULTS.md](./bench/RESULTS.md) has the comparison behind that choice.
118
-
119
- ```ts
120
- import { computed, createFakeClock, createFrameLoop, effect, signal } from "@n-uf/motion";
121
-
122
- const loop = createFrameLoop({ clock: createFakeClock() });
123
- const width = signal(800);
124
- const columns = computed(() => Math.max(1, Math.floor(width.value / 300)));
125
- effect(() => console.log("columns", columns.value), { schedule: loop.scheduler("write") });
126
- width.value = 850; // still 2 columns: the effect won't run
127
- width.value = 1300; // runs once, in the next frame's write phase
128
- ```
129
-
130
- ## values/
131
-
132
- | | |
133
- |---|---|
134
- | `createSpring(initial, { stiffness?, damping?, dampingRatio?, mass?, restDelta?, restSpeed? })` | Critically damped by default (`dampingRatio: 1`, `stiffness: 300`). Each step is the exact closed-form solution, so the curve doesn't depend on the frame rate. |
135
- | `createTween(initial, { duration?, easing? })` | Default 250 ms, `easeOutCubic`. A new target starts a new run from the current value. |
136
- | `motionValue(loop, animator, { phase?, reducedMotion? })` | Steps an animator on the loop while it moves; reading `.value` tracks it. |
137
- | `springValue(loop, initial, options)` / `tweenValue(...)` | The two together. |
138
- | `mv.set(target, { velocity? })`, `jump(value)`, `snap()`, `follow(() => target)`, `onSettle(fn)`, `dispose()`, `moving`, `velocity`, `target` | |
139
- | `springStep(state, target, params, dtMs)` | One pure scalar step, for hosts that step by hand. |
140
- | `linear`, `ease`, `easeIn`, `easeOut`, `easeInOut`, `easeOutCubic`, `easeInOutCubic`, `cubicBezier(x1, y1, x2, y2)` | Easing functions (functions, not CSS strings). |
141
-
142
- Values are plain: a number, `{ x, y }`, `{ x, y, width, height }` or an array
143
- of numbers, a fresh object after every change. Velocity is in units per
144
- second. A spring keeps its velocity when its target changes mid-flight. A
145
- value is at rest when it is within `restDelta` of the target and slower than
146
- `restSpeed` (defaults 0.1 and 1, tuned for pixels; use about 0.001 and 0.01
147
- for opacity or scale), and then it snaps onto the target exactly. With
148
- `reducedMotion` on (a boolean or a function read on every target and frame),
149
- targets are reached at once.
150
-
151
- Motion values step in the `layout` phase by default, after that phase's
152
- one-shot tasks: a target set in input, update or layout moves the value in
153
- the same frame, and `write` sees it.
154
-
155
- ```ts
156
- import { createFakeClock, createFrameLoop, springValue } from "@n-uf/motion";
157
-
158
- const clock = createFakeClock();
159
- const loop = createFrameLoop({ clock });
160
- const rect = springValue(loop, { x: 0, y: 0, width: 200, height: 100 }, { dampingRatio: 0.7 });
161
- rect.onSettle((r) => console.log("settled at", r));
162
- rect.set({ x: 300, y: 40, width: 240, height: 100 });
163
- clock.runUntilIdle(); // settled at { x: 300, y: 40, width: 240, height: 100 }
164
- ```
165
-
166
- ### Window motion: settle, direct drag, reveal
167
-
168
- Three rules make windows move the way a tiling window manager feels smooth
169
- (Hyprland is the reference): what the pointer drags is glued to it, everything
170
- else moves on one front-loaded curve that never passes its target, and content
171
- is never stretched.
172
-
173
- | | |
174
- |---|---|
175
- | `createSettle(initial, { omega?, restDelta? })` | The one curve for moving to a new place. On a new target every component gets the velocity `omega · distance` toward it from wherever it is drawn, so it follows `distance · e^(−omega·t)`: 90 % in `ln(10)/omega` s, then it eases in, and never passes the target (no overshoot on position, no wobble on size), however often it is retargeted. A velocity set by hand toward the target is capped at that speed; one away from it is kept, and the value turns around without crossing. |
176
- | `SETTLE_TEMPO` | `{ calm: 20, default: 25, quick: 37 }` (1/s): 90 % in 115, 92 or 62 ms. |
177
- | `settle.hold(value)` | Pin the value exactly there, at rest (same as `jumpTo`), for a direct drag. Call it on each pointer move; the next `setTarget` launches from there. |
178
- | `settleValue(loop, initial, { omega?, restDelta?, phase?, reducedMotion? })` | The settle on a frame loop. Pin it with `mv.jump(rect)`. |
179
- | `reveal(drawn, target)` | How to draw a window gliding at `drawn` whose content is laid out at `target`: move the element by `dx, dy`, draw the frame (chrome) at `width × height`, clip the content by `clipRight, clipBottom`. No scale, no layout per frame. |
180
- | `popIn(progress, from = 0.87)` | Opening and closing: a uniform scale about the center plus opacity. Drive `progress` with a settle on a number with `{ restDelta: 0.001 }` (the default 0.1 is for pixels) or a tween. |
181
-
182
- ```ts
183
- import { createFakeClock, createFrameLoop, settleValue } from "@n-uf/motion";
184
-
185
- const clock = createFakeClock();
186
- const loop = createFrameLoop({ clock });
187
- const win = settleValue(loop, { x: 0, y: 0, width: 400, height: 300 });
188
- win.set({ x: 400, y: 0, width: 200, height: 300 }); // a reflow: position and size arrive together
189
- clock.frame();
190
- win.set({ x: 300, y: 0, width: 300, height: 300 }); // retargeted mid-flight: on from where it is drawn
191
- clock.runUntilIdle();
192
- console.log(win.value); // { x: 300, y: 0, width: 300, height: 300 }, never past it on the way
193
- ```
194
-
195
- ## layout/
196
-
197
- `@n-uf/motion/layout` applies the window motion rules to a whole layout:
198
- give each item an id and a target rect, and it moves the real elements, every
199
- one on one frame loop that runs only while something moves. It animates the
200
- rects it is given and nothing else: which items move where (making room,
201
- drop targets) is the caller's layout.
202
-
203
- | | |
204
- |---|---|
205
- | `createLayoutMotion({ loop, omega?, phase?, popFrom?, reducedMotion?, onDraw?, onActiveChange? })` | The layout motion: `add(id, drawable, at, { shown? })`, `get`, `remove`, `retain(ids)` (removes every item not listed), `items`; `task(fn)` runs before the items step each frame, `onFrame(fn)` after; `onIdle`, `idle()`, `running`, `wake()`, `configure({ omega })`, `flush()`, `dispose()`. |
206
- | `reducedMotion` | A boolean or the host's query (the reduced-motion media query), read on every new target and every show or hide: while true, items are placed and shown at once, with no glide and no fade. |
207
- | `onDraw(batch)`, `flush()` | Batched drawing: every item that moved is drawn in one pass per frame (its drawable, then `onDraw` once with all their frames); an item at rest is not drawn. A change made between frames waits for the next frame, or `flush()` draws it now, which a host calls right after it commits a layout so the next paint shows no frame at the new box. |
208
- | `onActiveChange(active)` | Called once when the frames start and once when they stop. |
209
- | `item.moveTo(rect)` | Settle there from wherever it is drawn (a retarget mid-flight goes on from the drawn rect). The content is laid out at the new box once, and the item redrawn at once, so no frame shows the old offset from the new box. A size change is revealed, never scaled. |
210
- | `item.retarget(rect)` | Optional on a `LayoutItem`. Settle there like `moveTo`, but keep the content laid out where it is while the size is unchanged: for chasing a moving point (the direct drag's glide back to the pointer uses it), which would otherwise lay the content out on every frame. `holdItem` falls back to `moveTo` for an item without it. |
211
- | `item.jumpTo(rect)`, `item.hold(rect)`, `item.glideFrom(from, to)` | At once; drawn exactly where a pointer puts it (the content moves with it); drawn at `from`, then settle to `to`. |
212
- | `item.show(on, { now? })` | Appear or disappear with a uniform-scale fade (`popIn`); collapsing is a `moveTo` to the collapsed size, revealed. |
213
- | `item.drawn`, `target`, `box`, `settled`, `shown`, `showing`, `shownSettled` | Where it is drawn, where it is heading, where its content is laid out. |
214
- | `holdItem(item, grab)` | A direct drag of the real item, no copy: `move(pointer)` draws it 1:1 from the grab offset; `snapTo(slot)` glides into a slot, `snapTo(null)` back to the pointer (`follow()` once a frame until it is under it again); `land(slot)` and `cancel(home)` settle from the release rect, which they return. `preview(plan, slot)` once a frame plays a drop preview (`plan` from `@n-uf/motion/drag`'s `previewPlan`): `indicator` and `gap` (make room) keep the item under the pointer (`gap` with the caller's room open), `snap` glides it into the slot, and a release there finishes that glide. `resize(size)` holds it at a new size from now on (the caller laid its content out for it): the grab point keeps its share of the item, and it settles there from where it is drawn, revealed, never stretched (in a slot it stays put and takes the size when it leaves). |
215
- | `anchoredMorph(size, anchor, config?)` | A box held at a point that changes size about an anchor (its spot that sits on the point). `to(size, anchor)` settles the size and the anchor together from where they are drawn (at `MORPH_TEMPO`, which is `SETTLE_TEMPO.quick`: 90 % in about 60 ms, within 1 % in about 125 ms, the last pixels longer for large size changes, unless `config` says otherwise; a retarget mid-flight turns at once, no jump, no overshoot; true when the target changed); `jumpTo(size, anchor)` is there at once; `step(dt)` once a frame; `size`, `anchor`, `target` and `settled` read where it is drawn, heading and at rest; `rectAt(point)` is the box with its anchor exactly on the point, every frame; `progress` (0 to 1 since the last retarget) fades the content it came from out and the target's in. Draw each content with its own anchor on the point and neither moves from under the pointer. |
216
- | `flip(entries, change)` | FLIP for DOM groups on settle: record where each node is drawn, run `change` (the DOM moves), then each item glides from its old rect. |
217
- | `domDrawable({ node, frame?, content? })`, `layOutBox`, `drawBox` | Draw onto DOM styles: the node laid out at the box, moved by one transform, the frame at the drawn size, the content (or the node) clipped; hidden when gone. Any `{ layOut, draw }` drawable works (a canvas, a test). |
218
-
219
- ```ts
220
- import { createFakeClock, createFrameLoop } from "@n-uf/motion";
221
- import { createLayoutMotion, holdItem } from "@n-uf/motion/layout";
222
-
223
- const clock = createFakeClock();
224
- const loop = createFrameLoop({ clock });
225
- const motion = createLayoutMotion({ loop });
226
- const panel = motion.add("panel", { layOut: () => {}, draw: () => {} }, { x: 0, y: 0, width: 200, height: 100 });
227
- panel.moveTo({ x: 300, y: 0, width: 240, height: 100 }); // a settle, its new width revealed
228
- clock.runUntilIdle();
229
- const held = holdItem(panel, { x: 20, y: 10 }); // grabbed 20 px in, 10 px down
230
- held.move({ x: 120, y: 60 }); // a direct drag, 1:1: drawn at { x: 100, y: 50 }
231
- const release = held.land({ x: 0, y: 0, width: 200, height: 100 });
232
- console.log(release); // { x: 100, y: 50, width: 240, height: 100 }: the landing starts there
233
- clock.runUntilIdle();
234
- console.log(panel.drawn); // { x: 0, y: 0, width: 200, height: 100 }
235
- ```
236
-
237
- A host that draws every item itself, once per frame:
238
-
239
- ```ts
240
- import { createFakeClock, createFrameLoop } from "@n-uf/motion";
241
- import { createLayoutMotion } from "@n-uf/motion/layout";
242
-
243
- const clock = createFakeClock();
244
- const loop = createFrameLoop({ clock });
245
- const batches: string[][] = [];
246
- const host = createLayoutMotion({ loop, onDraw: (batch) => batches.push(batch.map((e) => e.id)) });
247
- const noop = { layOut: () => {}, draw: () => {} };
248
- const a = host.add("a", noop, { x: 0, y: 0, width: 100, height: 100 });
249
- host.add("b", noop, { x: 0, y: 200, width: 100, height: 100 });
250
- host.flush(); // both drawn now, in one batch: ["a", "b"]
251
- a.moveTo({ x: 300, y: 0, width: 100, height: 100 });
252
- host.flush(); // right after the host's commit: ["a"], at the rect it is drawn at
253
- clock.runUntilIdle(); // one batch per frame, each ["a"] (b is at rest)
254
- host.retain(["a"]); // b left the layout
255
- console.log(host.items.size); // 1
256
- ```
257
-
258
- ## testing/
259
-
260
- `@n-uf/motion/testing` checks recorded frames against the rules. Record what
261
- was drawn each frame (on the fake clock, or in a browser spec once per
262
- animation frame) and ask:
263
-
264
- | | |
265
- |---|---|
266
- | `checkNoOvershoot(samples, from, to, tolerance?)` | Every component stays between its start and end: no overshoot, no size wobble. |
267
- | `checkMonotonic(samples, to, tolerance?)` | The distance to the target never grows: no bounce, no restart backwards. |
268
- | `checkNoJumps(samples, omega, slack?)` | No frame moves further than a settle at `omega` could: catches snaps and restarts from an old place. Sample times are the stepped time (the loop's `delta`s), not wall-clock timestamps. |
269
- | `checkHeld(samples, tolerance?)` | A directly dragged rect is where the pointer puts it, every frame. |
270
- | `checkContentScale(samples, { uniformOnly?, tolerance? })` | Content's transform is never non-uniform (stretched); with `uniformOnly: false`, never scaled at all. |
271
- | `checkTempo(samples, from, to, t90, tolerance?, startT?)` | 90 % of the way within `t90` ms of `startT` (default: the first sample, so record the frame the move began); returns the measured time too. |
272
-
273
- Each returns `{ ok, failures }`, a failure naming the frame and component.
274
- The motion lab in the [n-uf/motion repository](https://github.com/n-uf/motion)
275
- (`apps/lab`) runs them on every move.
276
-
277
- ## gestures/
278
-
279
- | | |
280
- |---|---|
281
- | `createRecognizer({ toCanvas, timers?, dragModifier?, platform?, thresholds?, longPress?, multiClick?, pinch?, wheel?, staleMs? }, emit)` | Raw pointer, wheel and Safari gesture events in, `InputGesture`s out: `press`, `dragStart`, `move`, `longPress`, `release` (with `click` and `clickCount`), `cancel` (with a reason), `hover`, `pinch` (touch or trackpad, pinch or two-finger pan), `scroll`, `zoom`. Methods: `feed`, `cancel(reason)`, `reset`, `active`, `pinching`, `setDragModifier`, `dispose`. |
282
- | `GesturePointer` | The pointer every gesture reports (`screen`, `canvas`, `kind`, `buttons`, `modifiers`, `pointerId`, `button`). `SurfacePointer`, its old name, is removed: import `GesturePointer`. |
283
- | `RECOGNIZER_DEFAULTS` | Click-or-drag thresholds 4 / 6 / 8 px (mouse / pen / touch), long press after 500 ms for touch and pen, double click within 500 ms and 5 px (`DOUBLE_CLICK`, the package's one double click), pinch at 5 % scale or 10 px pan (read once both fingers have moved as often as each other, or one is three moves ahead, or one lifts). |
284
- | `wheelDeltaPx`, `classifyWheel`, `dampWheelPan`, `WHEEL_DEFAULTS`, `WHEEL_PAN_DEFAULTS` | Wheel normalization: lines and pages to px, Cmd/Ctrl+wheel (and the ctrl+wheel trackpad pinch) zooms by 2^(−dy / 300), Shift turns a vertical wheel horizontal, and a damped pan per event. |
285
- | `toModifiers`, `resolveDragModifier`, `defaultDragModifier`, `isHeld`, `modHeld`, `platformButton` | Modifier keys in one shape; the drag modifier per platform (Cmd on macOS, Alt elsewhere); on macOS a Ctrl+click is the secondary button. |
286
- | `createFrameCoalescer(onFrame, frames, { merge? })` | `schedule(sample)`, `flush()`, `cancel()`, `pending`. One delivery per frame with the latest sample (or `merge`d ones) and how many were folded. Same shape as hypr-tiling's. |
287
- | `dwellReducer`, `DWELL_IDLE`, `dwellDeadline`, `createDwellMachine` | `idle → dwelling → fired`, for spring-loaded targets: hold over the same key long enough and it fires once. |
288
- | `createMachine({ reducer, initial, clock, deadline? })` | Runs a pure reducer on a clock: arms the timer the state's deadline asks for and sends its input when it fires. `state` is reactive. |
289
- | `touchPressReducer`, `TOUCH_PRESS_IDLE`, `touchPressDeadline`, `createTouchPress`, `TOUCH_PRESS_DEFAULTS` | A touch on something draggable in a scrolling page, `idle → pressed → lifted \| scrolled`: before the hold (220 ms), travel mostly along the page's scroll direction (`scroll: "y"` or `"x"`) past 10 px is a scroll, which never lifts (short of 10 px it waits, so a finger scroll reported a few px at a time never lifts on the way); travel past 6 px mostly across it lifts where the finger is; a still finger lifts where it was pressed after the hold. |
290
- | `pagedSwipeReducer`, `PAGED_SWIPE_IDLE`, `pagedSwipeDeadline`, `createPagedSwipe`, `PAGED_SWIPE_DEFAULTS`, `swipeProgress` | Swiping between pages with a trackpad's wheel run or a finger, `idle → armed → tracking → settling → lockout`. It arms only along the swipe (more than twice the cross movement), without Ctrl, with the configured modifier, when nothing under the pointer scrolls further and a page is there; a run that breaks a rule belongs to scrolling until the wheel rests 120 ms. Past 24 px it tracks: `progress` is the travel over the page size, −1 to 1, held at 0 towards a missing page. At the end it commits at 35 % of the page or a peak of 0.6 px/ms towards it (the peak starts over when the travel crosses zero); the host sends `settled` after its transition, and a 350 ms lockout swallows the trackpad's momentum. On x or y (`along`). |
291
-
292
- The recognizer takes plain objects the host copies out of DOM events, with
293
- their timestamps; nothing in it touches the DOM. Mouse, pen and touch share
294
- one path. There is one press at a time, a second finger turns it into a
295
- pinch, and a press only becomes a drag past its device's threshold, so a
296
- modifier+click stays a click for the content. It recovers releases that never
297
- arrive (a move with no buttons down, the same pointer pressing again, a press
298
- left untouched for `staleMs` when another pointer goes down). Its `timers`
299
- are a clock (any `ClockPort`), used for the long press. Hit testing and
300
- routing (what is under a point, who gets the gesture) are the host's.
301
-
302
- ```ts
303
- import { createFakeClock, createRecognizer } from "@n-uf/motion";
304
-
305
- const clock = createFakeClock();
306
- const recognizer = createRecognizer({ toCanvas: (p) => p, timers: clock }, (g) => console.log(g.type));
307
- const finger = { pointerId: 1, pointerType: "touch", button: 0, screen: { x: 0, y: 0 } } as const;
308
- recognizer.feed({ ...finger, type: "pointerdown", buttons: 1, time: clock.now() }); // press
309
- clock.tick(500); // longPress
310
- recognizer.feed({ ...finger, type: "pointerup", buttons: 0, time: clock.now() }); // release, click: false
311
- ```
312
-
313
- A paged swipe, its timers on a clock:
314
-
315
- ```ts
316
- import { createFakeClock, createPagedSwipe, NO_MODIFIERS } from "@n-uf/motion";
317
-
318
- const clock = createFakeClock();
319
- const swipe = createPagedSwipe({ clock });
320
- swipe.send({ type: "context", hasPrev: true, hasNext: true, size: 1000 });
321
- swipe.send({ type: "wheel", dx: 400, dy: 0, t: clock.now(), modifiers: NO_MODIFIERS });
322
- console.log(swipe.state.phase, swipe.state.progress); // tracking 0.4
323
- clock.tick(120); // the wheel rests: past 35 %, it commits
324
- console.log(swipe.state.phase, swipe.state.target); // settling next
325
- swipe.send({ type: "settled" }); // the host's page transition is done: momentum is locked out
326
- console.log(swipe.state.phase); // lockout
327
- ```
328
-
329
- ## drag/
330
-
331
- `@n-uf/motion/drag` decides, from the pointer's path, when a drop indicator
332
- shows, which target it shows, when the others make room, and what a release
333
- lands on. It is pure: the host feeds it the pointer once a frame and plain-data
334
- targets, and draws what it says. It is only there, not in the root.
335
-
336
- | | |
337
- |---|---|
338
- | `createDragIntent({ home, lift?, liftRect?, floating?, earlyRelease?, tuning?, placeOf? })` | `update(point, time, targets, keys?)` once a frame while an item is dragged, returning `{ shown, room, roomPlace, aiming, atHome, arming, forced, refused, refusedSinceShown }` (`refusedSinceShown`: no target shows and the pointer has crossed a refusal since one last did, so a host that commits only drawn targets commits `release` too, as a quick drag across a refusal let go beyond it has no indicator drawn: read it from an `update` at the release point, called before `release`; the field is required, so a host or mock that builds a frame itself sets it; `arming`: the spring-loaded target the pointer dwells on, not armed yet; `forced`: `"float"` or `"rail"` when a modifier key won (the float key wins over dock targets only: over a refusal, or outside the float's `bounds`, it shows nothing and a release lands nowhere, `refused` naming the refusal); `refused`: the refusal under the pointer, a target marked `refuse: true` that the pick lands on, which no held target's band or grace covers, so nothing shows there and a release lands nowhere: pass a host's refusals in with the targets; a refused place is never drawn (no tint, outline or zone label), and while `refused` is set a host may say "Can't go here" at the pointer; `atHome`: the pointer is back inside `home` after it has been outside `home` itself; never true at the press or while it moves about inside `home`; with `floating` (the held item floats, `home` its box: a free placement, ranked like the float) home holds only where the pick there, home ignored, is no refusal and inside the window, so over a refusal in its box the frame is refused and a release lands nowhere, and on or past the window's edge nothing is picked; a docked item's home holds wherever it lies. A host sets it at lift from the placement layout, `floating: layout.items[id]?.floating === true`: the option is the intent's, read from `@n-uf/placement`'s layout item flag of the same name, not that flag itself. Over home no target is shown and a release does nothing, so a host that wants to say "a drop here returns it" draws its own indicator at the home rect for that frame); `release(point, targets, keys?)`, the target a release lands on or null (home); before the item has settled on a target that follows `earlyRelease`: `"target"` (the default) lands on the shown target, else the one under the pointer, and `"float"` makes what shows what lands, so the item floats where it is (over a refusal or outside the float's `bounds`, nowhere); `hide(time)` while the view scrolls under the pointer; `moveHome(dx, dy)`; `state`; `tuning`. |
339
- | `DRAG_DEFAULTS` | Lift at 5 px (a touch: a 180 ms hold, then 8 px); aiming below 0.45 px/ms over 50 ms, or within 12 px for 90 ms; a 10 px hysteresis margin (`band`) and a 4 px breakthrough, each at most a fifth of the hit areas' extents (`bandShare` 0.2), a 120 ms grace across the gap between two hit areas (`gapGrace`); a switch waits 150 ms (the switch delay); room after 160 ms (`roomAfter`, so a pointer moving across targets doesn't reflow the layout; a target marked `opensRoom`, whose indicator would lie over what its room moves, holds that long, or its own `roomHold` in ms, before it shows and has `room` in the frame that first shows it, and an armed spring-loaded target has its room as it shows; with its room open, one with a `roomHit` (its hit and landing rect) holds in `hit ∪ roomHit`, over a refusal or a target no more precise than it there, while a more precise target past the breakthrough and a held key still win); a spring-loaded target arms after a 200 ms dwell (`railArmDwellMs`: a pass at travelling speed never arms it, and platforms spring-load after a similar rest), never within 16 px of the lift point (`liftZone`: the "changed my mind" spot); Shift floats and ⌘/Ctrl (`"Mod"`, either key) goes to the nearest rail (`modifiers`; Alt is left free, so an app can keep it for unfreezing a frozen layout). Each is overridable per intent. |
340
- | `targetAt(targets, point)`, `inRect(rect, point, margin?)` | The most precise target under a point (priority 1, 2, 3, then the smaller hit area; a rect holds its edges exactly); a point in a rect grown or shrunk by a margin. A `DragTarget` whose hit area isn't one rect gives `hits`, every piece of it (`hit` is then the largest): the pointer is in the hit area when it is in any piece, and the hit area's size, for the smaller-hit-area rule and the drag intent's bands, is the pieces' together. A refusal ranks at `REFUSAL_RANK` (2.5, an ordering rank, not a priority: priorities stay 1, 2 and 3, and `refuse: true` is a refusal's tier; it orders after every target of priority 1 and 2, so a real target wins wherever the two meet or overlap, before the float's 3); `pickRank(t)` gives a target's rank. A zone with `bounds` (a refusal's and the float's: the window's stage) holds only points strictly inside it, its band and gap grace too, so a pointer clamped exactly onto the window's edge (`x + width`; a host that clamps to `width - 0.5` still picks inside) is never in it. This is the one pick rule: `@n-uf/placement/scene/cases` takes it as its hosts' `pick`. |
341
- | `liftDecision({ touch, distance, elapsed }, tuning?)` | `"wait"`, `"lift"` or `"refuse"`: when a press becomes a drag (`"refuse"` is a touch that moved before the hold: scroll wins). |
342
- | `createGripPress({ tuning?, double? })`, `GripRelease`, `DOUBLE_CLICK` | A press on a grip, start to end: `down(point, time, { touch?, clicks? })`, `move(point, time)` (the lift rule), `up(point, time)` → `"click"`, `"doubleActivate"` or null (it lifted). Two presses within `DOUBLE_CLICK` (500 ms and 5 px, the package's one double click, which the recognizer's `clickCount` uses too; browsers don't expose the system setting, so this is the common desktop default; `double` tunes it, and `clicks`, a `mousedown`'s `detail`, overrides it) give a click, then a double-activate: never a second click, never a lift. A press past the lift distance is a drag, also as the second press. |
343
- | `previewPlan(frame, preview, slotted?)`, `DragPreview`, `DRAG_PREVIEW_DEFAULT` | What to draw for a frame under one of four drop preview modes: `{ showIndicator, makeRoom, snapItem }`. `"item"`: the dragged item is the only preview, with no indicator for any target: it sits in a slotted target once the room is open and otherwise stays on the pointer (pair it with `earlyRelease: "float"`, so a release lands what shows). `"indicator"`: only the indicator, nothing moves. `"gap"` (make room): the others make room once the intent does; the item stays under the pointer. `"snap"` (the default): room opens and the item glides into a slotted target's room, with no indicator (a target without a slot keeps it). The object form `{ mode: "outline" \| "placeholder" \| "snap", placeGuides? }` (`DropPreviewMode`) draws with `"indicator"`'s, `"gap"`'s and `"item"`'s plan and adds `guides` (`PlaceGuides`: `"off"`, `"near"`, `"all"`; defaults `PLACE_GUIDES_DEFAULT`: snap and placeholder near, outline off): the guides to draw while no landing shows, `"off"` whenever one does, so a host shows where the item can go or where it will land, never both. It also carries `emptyLanes` (`"real"` by default, or `"edge"`), for the host to pass to `lanes()`: an empty lane drawn at its real size or as a thin striped edge. The string forms give `guides: "off"`. |
344
- | `createLandingModel({ regions, regionsFor?, floatLanding?, home?, margins?, gates?, approach?, placeGuides? })` | The landing model: where a docking drag lands, as state instead of a per-frame pick. `regions` are the drag's lanes (each with its spots in order: `along` stretch and `landing` rect), refused places, content and what blocks it, the stage and the item's size: what `@n-uf/placement/scene`'s `lanes()` gives, as plain data. `update(point, time, keys?)` returns `{ region, lane, spot, landing, room, guides, shift, pending? }` (`pending`: the lane the pointer is inside but hasn't entered yet; show no "Can't go here" while it is set, though a release lands nowhere), and `release()` the same answer (`{ kind: "spot" }`, `{ kind: "float", rect }` or null). The stage's edge is the easiest place to dock: a pointer up to `edge` (48 px) past the stage counts as on its edge, deep in the lane drawn there; beyond, nowhere. A held lane holds while the pointer is within `exit` (12 px) of it; over a spot's stretch it is that spot, over a refused stretch refused (`lanes()` joins a stretch shorter than the item to its spots). Entering a lane needs `path` (40 px) of slow path along it inside it (steps of at most `step`, so a crossing at 0.375 px/ms or faster never enters at any angle), or a still step (1.5 px per 8 ms) `depth` (8 px) inside it, the depth counted only from the sides facing into the stage, so a fly-through of a thin bar or rail opens no room. Inside a lane that touches the held one, past its exit margin, the held lane holds until that lane's gate passes or the pointer has slid `path` px along it at any speed (across it at most a third as far), then that lane takes it: lane to lane never passes through the float, and a fast crossing of the touching lane opens no room. Along a lane the spot changes `spot` (6 px) past a boundary, the same margin everywhere, so a wobble within it never flips the spot (passing a neighbor much longer than the held item, the single frame before the hop may find the landing up to 56 px from the pointer; every other frame is within 48 px); where the change reflows the window (the spots' `others` keys differ), on a step of at most `step` (3 px per 8 ms), or once the held landing trails the pointer by more than `trail` (40 px): a fast hand across docked items reflows only as often as it must to keep the item near, and a change that moves only the held item follows at any speed. With `regionsFor`, a reflowing change is kept only if, in the new spot's own regions (its room open), the pointer still picks it (cached per spot until `setRegions`). Outside lanes: refused, open space (`"open"`: the content less what blocks it, where the float lands), or nowhere. Shift makes a lane or open space open space and hides the guides. Guides (`{ id, lane, kind: "line" \| "box" \| "hatch", rect }`, keyed by `id`; a hatch is a striped cue in the guides' color, a short end inside a box whose room partly fits or a thin edge where an empty side rail would open, never a measure of the landing): a lane's `marks`, else its spots' landings; `"near"` the held lane's, else the approached lane's (within 80 px, kept until another is 16 px nearer or past 96 px), and over a refused place the nearest lane's at any distance; `"all"` every lane's. The model has no waits of its own; steps are normalized to 125 Hz. The host calls `update` whenever it likes (per pointer sample, per animation frame, or both): a repeated point keeps the last step and counts as still only once the pointer has stayed put for `rest` (22 ms) after a slow step or on the stage's edge, else for `pause` (60 ms), so a fast hand with samples far apart (20–30 Hz, dropped events) is never still between them; the first point (the lift) is never still either, so a lift over a lane's band doesn't enter it; and the host need only call again after the pointer stops (every frame does), and calls again with the same point when a key changes. `setRegions(regions, regionsFor?)` remaps spots by id and takes the `regionsFor` that answers for the new state; `hide()` lets the lane go. Additive: `createDragIntent` is unchanged. |
345
-
346
- A target is `{ id, priority, hit, slot?, label?, free? }`: `hit` is the hit
347
- area the pointer can be in, `priority` how precise it is (a tab strip 1, an
348
- insertion point 2, a large area 3). The rules:
349
-
350
- - The indicator shows only when the pointer has left the item's home, a target
351
- is under it, and the pointer aims (slows down or holds still). Crossing
352
- targets at speed shows nothing.
353
- - Hysteresis: the current target keeps the pointer within a margin (`band`)
354
- around its hit area, unless a more precise target is clearly under the
355
- pointer. That is for the seam between two tiles only: leaving a `free`
356
- target (the float) for a tile, or nothing, switches at once, so a hit area at
357
- the window's edge takes its first px. Both scale with the hit areas:
358
- along each axis, at most a fifth of the current hit area's extent and of the
359
- hit area under the pointer, so a small one (a 28 px row) is entered by a
360
- direct glide from its neighbor. Leaving the shown target, a
361
- travelling pointer hides the indicator at once; an aiming one moves it once
362
- the new target has held 150 ms (the switch delay), so no indicator ever shows
363
- for less.
364
- - Room is made once the shown target, and the place in it (`placeOf`: a tab
365
- index, say), have held 160 ms; never for a `free` target.
366
- - `placeOf(target, point, previous)` gets the place it gave that target on the
367
- last sample, so a place can hold near its boundary. A null place is no
368
- target: nothing shows there (a target beneath with a place can), no room
369
- opens, and a release there lands on a target beneath, else goes home.
370
- `placeOf` is also asked about the current target just outside its hit area
371
- (within the margin or the gap grace): answer the nearest place there, and
372
- return null only for a part of the target that takes no drop. It runs on
373
- every sample for each target under the pointer, so keep it cheap.
374
- - A release lands on the shown target whenever one shows (drop = shown), else
375
- on the target under the pointer, else nowhere. A release over home does
376
- nothing.
377
- - Spring-loading: a target marked `arm: "dwell"` (a side's rail, say) is no
378
- target until the pointer has rested in its hit area for `railArmDwellMs`; a
379
- fast pass, or a drop before then, lands on what lies beneath (the float).
380
- Armed, it shows at once and its hit area is `armedHit` (grown: a magnet, the
381
- armed target's band); moving out past that band's outer edge disarms it, and
382
- re-entering needs a new full dwell. The frame's `arming` lets a host highlight the
383
- strip while the dwell runs, and say the armed state in its live region. Home
384
- doesn't gate it: a strip that overlaps the item's own place (an item alone in its
385
- column, dragged to its own side's edge) arms by dwell there, shows while armed,
386
- and takes a release over home; an unarmed target, and a target that isn't
387
- spring-loaded, still never show over home, and a release there does nothing.
388
- A spring-loaded target arms only after the pointer has entered its hit area
389
- during the drag: the point the drag starts at counts as not entered, so a drag
390
- that starts inside the strip (a panel's grip under it at the window's edge)
391
- must leave it and come back before it arms, while entering from over home
392
- counts. Nothing arms by dwell within `liftZone` (16 px, about a grip's size)
393
- of the point the drag was lifted at (`lift`, else the first sample): back
394
- where it was lifted, a pause is "changed my mind" and commits nothing, even
395
- with the grip under a strip (a flush drawer at the window's edge). A host can
396
- give the zone as a rect instead (`liftRect`, the part of the grip the strip
397
- covers): then nothing arms inside that rect, the radius is not applied, and
398
- the strip arms just past the grip. Elsewhere,
399
- home under the strip included, it arms as above, and the rail key still forces
400
- the rail anywhere, the lift zone too.
401
- - Keys win over geometry: with `keys` passed (`DragKeys`: `{ shift?, alt?, ctrl?,
402
- meta? }`, the modifiers held on a pointer event; `tuning.modifiers` says which
403
- key does what, default Shift and ⌘/Ctrl), the float key (Shift) shows and lands
404
- on the `free` target over a dock target, a spring-loaded one or open space
405
- inside the window (over a refusal the frame is refused, and outside the
406
- float's `bounds` nothing shows); the rail key (⌘/Ctrl, `"Mod"`) on the nearest
407
- spring-loaded target, from anywhere. The frame's `forced` says which won.
408
- - The four drop preview values (`"indicator"`, `"gap"`, `"snap"`, `"item"`) only change what is drawn: all follow
409
- these rules, so a drop lands where the preview showed it in each.
63
+ The drag intent is pure: feed it the pointer once a frame and plain-data targets, and draw what it says.
410
64
 
411
65
  ```ts
412
66
  import { createDragIntent, type DragTarget } from "@n-uf/motion/drag";
@@ -416,69 +70,17 @@ const intent = createDragIntent({ home: { x: 300, y: 300, width: 100, height: 50
416
70
  for (let t = 0; t <= 300; t += 16) intent.update({ x: 100, y: 50 }, t, [slot]); // held still over the slot
417
71
  console.log(intent.state.shown?.id); // "slot"
418
72
  console.log(intent.release({ x: 100, y: 50 }, [slot])?.id); // "slot"
419
-
420
- // A pane that takes drops on its right half only; that half holds 6 px past the line.
421
- const pane: DragTarget = { id: "pane", priority: 2, hit: { x: 0, y: 0, width: 200, height: 100 } };
422
- const zones = createDragIntent<DragTarget>({
423
- home: { x: 300, y: 300, width: 100, height: 50 },
424
- placeOf: (_t, p, previous) => (p.x >= (previous === "right" ? 94 : 100) ? "right" : null),
425
- });
426
- for (let t = 0; t <= 300; t += 16) zones.update({ x: 50, y: 50 }, t, [pane]); // held over its left half
427
- console.log(zones.state.shown, zones.release({ x: 50, y: 50 }, [pane])); // null null: nothing shows, the item goes home
428
73
  ```
429
74
 
430
- The intent works in one coordinate space: the one its targets and home are in. On a page drawn scaled (a zoomed
431
- canvas, a fitted preview), convert each pointer sample into page coordinates first, `(p − origin) / scale`, and the
432
- hysteresis margin, breakthrough and stillness distances stay page px:
433
-
434
- ```ts
435
- // The page is drawn at half size, its top-left corner at (300, 200) on screen; targets are in page px.
436
- const origin = { x: 300, y: 200 };
437
- const scale = 0.5;
438
- const toPage = (p: { x: number; y: number }) => ({ x: (p.x - origin.x) / scale, y: (p.y - origin.y) / scale });
439
- const onPage = createDragIntent({ home: { x: 600, y: 600, width: 100, height: 50 } });
440
- const screen = { x: 350, y: 225 }; // the pointer, as the browser reports it
441
- for (let t = 0; t <= 300; t += 16) onPage.update(toPage(screen), t, [slot]); // page (100, 50): over the slot
442
- console.log(onPage.state.shown?.id, onPage.release(toPage(screen), [slot])?.id); // "slot" "slot"
443
- ```
444
-
445
- A host contract: clamp the pointer into the stage (the window the targets tile) before it reaches `update` and
446
- `release`, so a pointer past the window's edge means its nearest point of the window. A drop target at the window's
447
- edge then stays under a hand that overshoots it, which is what makes an edge target easy to hit. Draw the dragged item at
448
- the pointer itself. While a drag is in progress, suppress the context menu (a Ctrl-click on macOS opens one) and the
449
- browser shortcuts of the rail key (⌘/Ctrl): `preventDefault` on `contextmenu`, and on the `keydown` of Meta or Control.
450
- The intent doesn't see DOM events, and the gesture recognizer has no hook for this, so it is the host's job; leave keys
451
- alone when no drag is active.
452
-
453
- ## @n-uf/motion/browser
454
-
455
- | | |
456
- |---|---|
457
- | `createBrowserClock({ host?, fallbackFrameMs? })` | The `ClockPort` on `requestAnimationFrame`, `performance.now` and `setTimeout`; timeouts stand in for frames where there is no `requestAnimationFrame`. |
458
- | `prefersReducedMotion(host?)` | A function reading `(prefers-reduced-motion: reduce)`, for `reducedMotion`. |
459
-
460
- The host is typed by its shape, not by lib.dom, so tests and workers can pass
461
- their own.
462
-
463
- ## Testing
464
-
465
- Everything runs on `createFakeClock()`: frames, timers, springs and machine
466
- deadlines move only when the test moves the clock, so motion is exact and
467
- repeatable. `@n-uf/motion/testing` (above) checks the frames you record.
468
-
469
- ## Benchmarks
470
-
471
- `pnpm bench` times the signals against alien-signals' and
472
- @preact/signals-core's own APIs on graphs of a few thousand nodes, and prints
473
- bundle sizes and the deepest chain each survives. Results and the choice
474
- they led to are in [bench/RESULTS.md](./bench/RESULTS.md).
75
+ ## Documentation
475
76
 
476
- ## Versions
77
+ - [Design page](https://github.com/n-uf/motion/blob/main/docs/motion.md): the concept, the parts, the rules a consumer relies on.
78
+ - [Reference](https://github.com/n-uf/motion/blob/main/docs/motion-reference.md): every entry point's API, rules and longer examples.
79
+ - [CHANGELOG](https://github.com/n-uf/motion/blob/main/packages/motion/CHANGELOG.md)
80
+ - Site and live demos: [motion.n-uf.com](https://motion.n-uf.com)
477
81
 
478
- Calendar versions `YY.M.R` (year, month of the release, counter within the
479
- month), the same scheme as `@n-uf/hypr-tiling`. `pnpm version:bump` sets the
480
- next one; never type one by hand.
82
+ Its sibling [`@n-uf/placement`](https://www.npmjs.com/package/@n-uf/placement) owns where things go.
481
83
 
482
84
  ## License
483
85
 
484
- [PolyForm Perimeter 1.0.1](./LICENSE).
86
+ [PolyForm Perimeter 1.0.1](https://github.com/n-uf/motion/blob/main/LICENSE).
package/dist/drag.d.ts CHANGED
@@ -721,4 +721,29 @@ declare function createGripPress(options?: {
721
721
  readonly double?: Partial<DoubleClick>;
722
722
  }): GripPress;
723
723
 
724
- export { DRAG_DEFAULTS, DRAG_PREVIEW_DEFAULT, DoubleClick, type DragFrame, type DragIntent, type DragIntentOptions, type DragIntentState, type DragKeys, type DragModifiers, type DragPreview, type DragTarget, type DragTuning, type DropPreviewMode, type EmptyLanes, type GripPress, type GripRelease, LANDING_APPROACH, LANDING_GATES, LANDING_MARGINS, LANDING_TOUCH_MARGINS, type LandingApproach, type LandingFrame, type LandingGates, type LandingGuide, type LandingLane, type LandingMargins, type LandingMark, type LandingModel, type LandingOptions, type LandingRegion, type LandingRegions, type LandingRelease, type LandingSpot, type LiftDecision, type ModifierKey, PLACE_GUIDES_DEFAULT, type PlaceGuides, type PreviewPlan, REFUSAL_RANK, createDragIntent, createGripPress, createLandingModel, inRect, liftDecision, pickRank, previewPlan, targetAt };
724
+ /** A guide to place: any record with a `kind` and a `rect` (a landing model's `LandingGuide`, a lane's marks). */
725
+ interface PlacedGuide {
726
+ readonly kind: "line" | "box" | "hatch";
727
+ readonly rect: Rect;
728
+ }
729
+ interface GuideRectsOptions {
730
+ /** The area guides are drawn in: the window's inside (inside its border), px. */
731
+ readonly inside: Rect;
732
+ /** How far inside `inside` every guide stays, px (default 2). */
733
+ readonly inset?: number;
734
+ /** Rects a thin guide stays clear of (the content: a column's panels under an empty lane's thin edge). */
735
+ readonly clear?: readonly Rect[];
736
+ /** The least thickness a thin guide keeps, px (default 2); thinner, it is not drawn. */
737
+ readonly minThickness?: number;
738
+ }
739
+ /**
740
+ * Where to draw guides: every guide inside `inside` by `inset`. A box is clipped. A thin guide (a line, a striped
741
+ * strip or end: its shorter side is its thickness) keeps its thickness and moves inside rather than being clipped, so
742
+ * a line at a lane's far end is as thick as at its head. Then it is thinned, from the content side, to stay clear of
743
+ * `clear`, so a thin strip at the window's side lies between the inset and the content, the same on both sides. A
744
+ * guide with nothing left (or a thin one under `minThickness`) is left out. Pure; the guides come back as given with
745
+ * their placed `rect`.
746
+ */
747
+ declare function guideRects<G extends PlacedGuide>(guides: readonly G[], options: GuideRectsOptions): G[];
748
+
749
+ export { DRAG_DEFAULTS, DRAG_PREVIEW_DEFAULT, DoubleClick, type DragFrame, type DragIntent, type DragIntentOptions, type DragIntentState, type DragKeys, type DragModifiers, type DragPreview, type DragTarget, type DragTuning, type DropPreviewMode, type EmptyLanes, type GripPress, type GripRelease, type GuideRectsOptions, LANDING_APPROACH, LANDING_GATES, LANDING_MARGINS, LANDING_TOUCH_MARGINS, type LandingApproach, type LandingFrame, type LandingGates, type LandingGuide, type LandingLane, type LandingMargins, type LandingMark, type LandingModel, type LandingOptions, type LandingRegion, type LandingRegions, type LandingRelease, type LandingSpot, type LiftDecision, type ModifierKey, PLACE_GUIDES_DEFAULT, type PlaceGuides, type PlacedGuide, type PreviewPlan, REFUSAL_RANK, createDragIntent, createGripPress, createLandingModel, guideRects, inRect, liftDecision, pickRank, previewPlan, targetAt };
package/dist/drag.js CHANGED
@@ -449,6 +449,10 @@ function createLandingModel(options) {
449
449
  spotId = s?.id ?? spotId;
450
450
  region = s ? "lane" : "refused";
451
451
  if (!s) spotId = null;
452
+ if (!s && !strictlyIn(held2.rect, p)) {
453
+ const others = regions.lanes.filter((l) => l.id !== held2.id && strictlyIn(l.rect, p));
454
+ if (others.length > 0) pending = others.reduce((a, b) => depthIn(b.rect, p, regions.stage) > depthIn(a.rect, p, regions.stage) ? b : a).id;
455
+ }
452
456
  } else {
453
457
  laneId = spotId = null;
454
458
  const lanesHere = regions.lanes.filter((l) => strictlyIn(l.rect, p) && !(l.owns && nearLift));
@@ -578,6 +582,56 @@ function createGripPress(options = {}) {
578
582
  }
579
583
  };
580
584
  }
585
+
586
+ // src/drag/guide-rects.ts
587
+ var EPS = 1e-6;
588
+ function guideRects(guides, options) {
589
+ const inset = Number.isFinite(options.inset) ? Math.max(0, options.inset) : 2;
590
+ const min = Number.isFinite(options.minThickness) ? Math.max(0, options.minThickness) : 2;
591
+ const same = (a, b) => Math.abs(a.x - b.x) < EPS && Math.abs(a.y - b.y) < EPS && Math.abs(a.width - b.width) < EPS && Math.abs(a.height - b.height) < EPS;
592
+ const place = (g, rect) => same(g.rect, rect) ? g : { ...g, rect };
593
+ const x0 = options.inside.x + inset;
594
+ const y0 = options.inside.y + inset;
595
+ const x1 = options.inside.x + options.inside.width - inset;
596
+ const y1 = options.inside.y + options.inside.height - inset;
597
+ const clear = options.clear ?? [];
598
+ const out = [];
599
+ for (const g of guides) {
600
+ const r = g.rect;
601
+ if (g.kind === "box") {
602
+ const a = Math.max(r.x, x0);
603
+ const b = Math.max(r.y, y0);
604
+ const c = Math.min(r.x + r.width, x1);
605
+ const d = Math.min(r.y + r.height, y1);
606
+ if (c - a > EPS && d - b > EPS) out.push(place(g, { x: a, y: b, width: c - a, height: d - b }));
607
+ continue;
608
+ }
609
+ const thinX = r.width <= r.height;
610
+ const t = thinX ? r.width : r.height;
611
+ let lo = thinX ? r.x : r.y;
612
+ const lim0 = thinX ? x0 : y0;
613
+ const lim1 = thinX ? x1 : y1;
614
+ if (lo + t > lim1) lo = lim1 - t;
615
+ if (lo < lim0) lo = lim0;
616
+ let hi = Math.min(lo + t, lim1);
617
+ const s0 = Math.max(thinX ? r.y : r.x, thinX ? y0 : x0);
618
+ const s1 = Math.min(thinX ? r.y + r.height : r.x + r.width, thinX ? y1 : x1);
619
+ if (s1 - s0 <= EPS) continue;
620
+ for (const c of clear) {
621
+ const cs0 = thinX ? c.y : c.x;
622
+ const cs1 = thinX ? c.y + c.height : c.x + c.width;
623
+ if (cs1 <= s0 + EPS || cs0 >= s1 - EPS) continue;
624
+ const c0 = thinX ? c.x : c.y;
625
+ const c1 = thinX ? c.x + c.width : c.y + c.height;
626
+ if (c1 <= lo + EPS || c0 >= hi - EPS) continue;
627
+ if ((c0 + c1) / 2 >= (lo + hi) / 2) hi = Math.min(hi, c0);
628
+ else lo = Math.max(lo, c1);
629
+ }
630
+ if (hi - lo < Math.max(EPS, min)) continue;
631
+ out.push(place(g, thinX ? { x: lo, y: s0, width: hi - lo, height: s1 - s0 } : { x: s0, y: lo, width: s1 - s0, height: hi - lo }));
632
+ }
633
+ return out;
634
+ }
581
635
  export {
582
636
  DOUBLE_CLICK,
583
637
  DRAG_DEFAULTS,
@@ -591,6 +645,7 @@ export {
591
645
  createDragIntent,
592
646
  createGripPress,
593
647
  createLandingModel,
648
+ guideRects,
594
649
  inRect,
595
650
  liftDecision,
596
651
  pickRank,
package/dist/drag.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/drag/intent.ts","../src/drag/landing.ts","../src/drag/preview.ts","../src/drag/grip.ts"],"sourcesContent":["import type { Point, Rect } from \"../shapes\";\n\n/**\n * The drag intent model's tuning. Distances in px, speeds in px/ms, times in\n * ms; every value can be overridden per intent (see\n * {@link DragIntentOptions.tuning}).\n */\nexport interface DragTuning {\n /** A mouse press lifts once the pointer has moved this far. */\n readonly lift: number;\n /** A touch press lifts only after it has been held this long… */\n readonly touchHold: number;\n /** …and then moved this far (moving that far before the hold is over is not a drag). */\n readonly touchLift: number;\n /** The pointer's speed is measured over this window and smoothed. */\n readonly speedWindow: number;\n /** Aiming: the smoothed speed is below this… */\n readonly aimSpeed: number;\n /** …or the pointer has stayed within `still` px of one spot for `dwell` ms. */\n readonly still: number;\n readonly dwell: number;\n /** The current target holds while the pointer is within this band of its zone. */\n readonly band: number;\n /** A higher-priority target takes over at once when the pointer is this far inside it. */\n readonly breakthrough: number;\n /**\n * The band and the breakthrough scale with the zones: along each axis they are at most this share of the held\n * zone's extent and of the extent of the zone under the pointer (its `hit`), so a small zone (a 28 px row) can be\n * entered by a direct glide from its neighbor. Below a quarter, the pointer at a quarter of a zone is past them.\n */\n readonly bandShare: number;\n /** A gap between zones shorter than this keeps the current target (for a pointer that aims). */\n readonly gapGrace: number;\n /** Aiming, the shown target moves to another one only once that one has held this long. */\n readonly switchHold: number;\n /**\n * Room is made once the shown target, and the place in it, have held this long, so a pointer moving across targets\n * doesn't reflow the layout under it. A target with `opensRoom` holds this long before it shows, its room with it.\n */\n readonly roomAfter: number;\n /** The pointer has left the item's home once it is outside the home shrunk by this much on every side. */\n readonly homeInset: number;\n /**\n * Spring-loading: a target marked `arm: \"dwell\"` takes the drop only once the pointer has stayed in its zone this long\n * (ms); before that it is no target, so a fast pass, or a drop before it, lands on what lies beneath. 0 arms it at once.\n * Armed, its zone is its `armedHit` (the magnet: its band); moving out past that band's outer edge disarms it, and\n * re-entering needs a new full dwell. It arms only after the pointer has ENTERED its zone during the drag: the point\n * the drag starts at counts as not entered, so a drag that starts inside the zone (a panel's grip under the strip at\n * the window's edge) must leave it and come back before it can arm; entering from over home counts.\n */\n readonly railArmDwellMs: number;\n /**\n * The lift zone, a radius in px about the point the drag was lifted at ({@link DragIntentOptions.lift}, else the first\n * sample): no spring-loaded target arms by dwell inside it. Coming back to where you lifted and pausing is the\n * \"changed my mind\" gesture, so it commits nothing even where a strip lies over the grip (a flush drawer's grip at the\n * window's edge). 16 px is about a grip's size. Elsewhere, home under a strip included, arming works as before, and\n * the rail key forces the rail anywhere, the lift zone too.\n */\n readonly liftZone: number;\n /** The keys that win over geometry while held (see {@link DragModifiers}). */\n readonly modifiers: DragModifiers;\n}\n\n/**\n * A modifier key, by its `KeyboardEvent.key` name, or `\"Mod\"`: ⌘ (Meta) on macOS and Ctrl elsewhere. `\"Mod\"` counts\n * either key as held, so no platform detection is needed.\n */\nexport type ModifierKey = \"Shift\" | \"Alt\" | \"Control\" | \"Meta\" | \"Mod\";\n\n/** The modifier keys held on a sample (a pointer event's `shiftKey`, `altKey`, `ctrlKey`, `metaKey`). */\nexport interface DragKeys {\n readonly shift?: boolean;\n readonly alt?: boolean;\n readonly ctrl?: boolean;\n readonly meta?: boolean;\n}\n\n/**\n * Keys that win over geometry: while `floatKey` is held the drop floats (the `free` target) wherever the pointer is,\n * except over a refusal (the frame is refused) or outside the float's `bounds` (nothing);\n * while `railKey` is held it goes to the nearest target marked `arm` (a side's rail), without reaching it. `floatKey`\n * wins when both are held. `on: false` turns both off.\n */\nexport interface DragModifiers {\n readonly on: boolean;\n readonly floatKey: ModifierKey;\n readonly railKey: ModifierKey;\n}\n\n/**\n * The defaults: a mouse lifts after 5 px, a touch after a 180 ms hold and\n * 8 px; aiming is slower than 0.45 px/ms over 50 ms, or within 12 px for\n * 90 ms; a 10 px band and a 4 px breakthrough, each at most a fifth of the\n * zones' extents, and a 120 ms gap grace; a switch waits 150 ms (the shortest\n * an indicator may show); room after 160 ms. A spring-loaded target arms after\n * 200 ms of dwell (long enough that a pass at travelling speed never arms it,\n * short enough to feel like the platforms' spring-loading); Shift floats, ⌘/Ctrl\n * (`\"Mod\"`) goes to the nearest rail. Alt is left free: an app with a frozen\n * layout uses it to unfreeze temporarily, and a key should have one meaning.\n */\nexport const DRAG_DEFAULTS: DragTuning = {\n lift: 5,\n touchHold: 180,\n touchLift: 8,\n speedWindow: 50,\n aimSpeed: 0.45,\n still: 12,\n dwell: 90,\n band: 10,\n breakthrough: 4,\n bandShare: 0.2,\n gapGrace: 120,\n switchHold: 150,\n roomAfter: 160,\n homeInset: 6,\n railArmDwellMs: 200,\n liftZone: 16,\n modifiers: { on: true, floatKey: \"Shift\", railKey: \"Mod\" },\n};\n\nconst KEY_FIELD: Record<Exclude<ModifierKey, \"Mod\">, keyof DragKeys> = { Shift: \"shift\", Alt: \"alt\", Control: \"ctrl\", Meta: \"meta\" };\n/** Whether `key` is held in `keys` (`\"Mod\"`: ⌘ or Ctrl). */\nconst held = (keys: DragKeys | undefined, key: ModifierKey): boolean =>\n !!keys && (key === \"Mod\" ? !!(keys.meta || keys.ctrl) : !!keys[KEY_FIELD[key]]);\n\n/**\n * A drop target: plain data. `hit` is the zone the pointer can be in;\n * `priority` how precise it is (1 beats 2 beats 3; equal priorities go to the\n * smaller zone). `slot` is where the dragged item would land, `label` what to\n * call it; the model reads neither. A `free` target has no slot (the item\n * floats where it is dropped): no room is made for it. `hits`, when given, is\n * the whole zone as several rects (a zone that isn't one rect, `hit` the\n * largest of them): the pointer is in the zone when it is in any of them.\n *\n * `arm: \"dwell\"` makes it spring-loaded: it is no target until the pointer has\n * dwelt in its zone for `railArmDwellMs`; once armed its zone is `armedHit`\n * when given (a magnet: the zone grown), and leaving that disarms it.\n *\n * `refuse: true` makes it a refusal: a place that takes no drop (a host draws nothing over it, and at most says \"Can't\n * go here\" at the pointer). It takes part in\n * the pick under the pointer at {@link REFUSAL_RANK} (below every target of priority 1 or 2, whatever its own\n * `priority`, above priority 3), but it never becomes the current or the shown target, and a release over it lands\n * nowhere. Where the pick under the pointer is a refusal, no held target's band or gap grace keeps it: nothing shows,\n * and the frame's `refused` says which refusal it is.\n *\n * `bounds`, when given, is the drawn space the zone belongs to (a window's stage): the zone, its band and its gap grace\n * hold only points strictly inside it, so it is half-open toward the outside and a point on `bounds`' boundary or past\n * it is never in it. The window's boundary belongs only to the targets drawn against it: a refusal and a target over\n * the whole plane (the float) carry `bounds`, a gap or a slot doesn't. So a pointer a host clamps onto the window's\n * edge picks a gap whose hit reaches the edge, else nothing (a held target keeps its band), and never a refusal or the\n * float. The rule relies on the host clamping exactly onto the stage's edge (`x + width`, `y + height`): a host that\n * clamps to `width - 0.5` still picks inside the window, the float or a refusal there included.\n *\n * `opensRoom: true` marks a target whose indicator would lie over what its room moves (a side rail that pushes a column\n * aside). Showing it and making its room are then one decision: it shows only once it has held `roomAfter` ms, and the\n * frame that first shows it already has `room`. A sweep across it moves nothing, as for any target, and no frame draws\n * it over the column. Until it shows, a release still lands on it. An armed spring-loaded target has its room at once\n * too: its dwell was the decision. `roomHold` is how long this target holds before that decision, in ms, in place of\n * `roomAfter` (a rail or a new-column line against the window's edge, which a pointer rarely crosses on its way\n * elsewhere, can wait less). A\n * host that draws only a marker and doesn't use `previewPlan`'s room opens the room on\n * `frame.room && frame.shown?.opensRoom`.\n *\n * `roomHit`, with `opensRoom`, is where the target's room draws the item once it is open (its landing rect: an empty\n * rail or bar is entered over its drawn depth). While the target shows with its room open it holds in `hit ∪ roomHit`: wherever\n * the pointer is in `roomHit` and inside its `bounds` too. What lies there is drawn as the room, so a refusal or a\n * target of the same or a lower precision under it doesn't take over, and the frame isn't `refused` there. A more\n * precise target (a lower `priority`) still takes over once the pointer is past `breakthrough` into it, and a held key\n * still wins. Out of both the target is held as any other (its `hit` and band), so once it goes its zone is `hit` again.\n */\nexport interface DragTarget {\n readonly id: string;\n readonly priority: 1 | 2 | 3;\n readonly hit: Rect;\n readonly hits?: readonly Rect[];\n readonly slot?: Rect;\n readonly label?: string;\n readonly free?: boolean;\n readonly arm?: \"dwell\";\n readonly armedHit?: Rect;\n readonly refuse?: true;\n readonly bounds?: Rect;\n readonly opensRoom?: true;\n readonly roomHold?: number;\n readonly roomHit?: Rect;\n}\n\n/**\n * Where a refusal ranks in the pick ({@link targetAt}): an ordering rank, not a priority. Priorities stay the integers\n * 1, 2 and 3; a refusal's tier is `refuse: true`, and the pick orders it by this rank on the same scale: after every\n * target of priority 1 and 2 (a refusal and a real target where they meet or overlap: the target wins, so a gap keeps\n * its end), before priority 3 (the float: over drawn space that takes nothing, the refusal wins over floating).\n * Among refusals the smaller zone wins. `@n-uf/placement` exports the same value for its reference pick.\n */\nexport const REFUSAL_RANK = 2.5;\n\n/** A target's rank in the pick: its `priority`, a refusal's {@link REFUSAL_RANK}. Lower wins. */\nexport const pickRank = (t: Pick<DragTarget, \"priority\" | \"refuse\">): number => (t.refuse === true ? REFUSAL_RANK : t.priority);\n\n/** Whether `point` lies strictly inside `bounds` (none: everywhere). */\nconst within = (bounds: Rect | undefined, point: Point): boolean =>\n !bounds || (point.x > bounds.x && point.x < bounds.x + bounds.width && point.y > bounds.y && point.y < bounds.y + bounds.height);\n\n/** Whether `point` lies in `rect` grown by `margin` px on every side (shrunk, for a negative margin). */\nexport function inRect(rect: Rect, point: Point, margin = 0): boolean {\n return point.x >= rect.x - margin && point.x <= rect.x + rect.width + margin && point.y >= rect.y - margin && point.y <= rect.y + rect.height + margin;\n}\n\n/** How far `point` lies from `rect` (0 inside it). */\nconst distanceTo = (rect: Rect, point: Point): number =>\n Math.hypot(Math.max(rect.x - point.x, 0, point.x - (rect.x + rect.width)), Math.max(rect.y - point.y, 0, point.y - (rect.y + rect.height)));\n\n/** Whether `point` lies in a target's zone (`hits` when it has them, else `hit`), grown by `margin` px, and inside its `bounds`. */\nconst inZone = (t: DragTarget, point: Point, margin = 0): boolean => within(t.bounds, point) && (t.hits ? t.hits.some((r) => inRect(r, point, margin)) : inRect(t.hit, point, margin));\n\n/** A margin per axis: px grown (shrunk, when negative) left and right, and above and below. */\ninterface Margin {\n readonly x: number;\n readonly y: number;\n}\n/**\n * Whether `point` lies in a target's zone grown by `m.x` px left and right and `m.y` px above and below, and inside its\n * `bounds`: a band never reaches past a zone's bounds (the float's band holds nothing outside the window).\n */\nconst inZoneBy = (t: DragTarget, point: Point, m: Margin): boolean =>\n within(t.bounds, point) && (t.hits ?? [t.hit]).some((r) => point.x >= r.x - m.x && point.x <= r.x + r.width + m.x && point.y >= r.y - m.y && point.y <= r.y + r.height + m.y);\n/** `px`, but along each axis at most `share` of each zone's extent (its `hit`) along it. */\nconst scaled = (px: number, share: number, zones: readonly (DragTarget | null)[]): Margin => {\n let x = px;\n let y = px;\n for (const z of zones) {\n if (!z) continue;\n x = Math.min(x, share * z.hit.width);\n y = Math.min(y, share * z.hit.height);\n }\n return { x, y };\n};\nconst negate = (m: Margin): Margin => ({ x: -m.x, y: -m.y });\n\nconst area = (r: Rect): number => r.width * r.height;\n/** A target's zone's area: its `hits` together, else its `hit`. */\nconst zoneArea = (t: DragTarget): number => (t.hits ? t.hits.reduce((s, r) => s + area(r), 0) : area(t.hit));\n\n/**\n * The most precise target under `point`: the lowest rank ({@link pickRank}: the priority, a refusal's\n * {@link REFUSAL_RANK}), then the smallest zone; null when none is. A zone holds its edges (a closed rect), except\n * toward the outside of its `bounds`.\n */\nexport function targetAt<T extends DragTarget>(targets: readonly T[], point: Point): T | null {\n let best: T | null = null;\n for (const t of targets) {\n if (!inZone(t, point)) continue;\n if (!best || pickRank(t) < pickRank(best) || (pickRank(t) === pickRank(best) && zoneArea(t) < zoneArea(best))) best = t;\n }\n return best;\n}\n\n/** What a press does so far: not yet a drag (`wait`), a drag (`lift`), or never one (`refuse`: a touch that moved too soon). */\nexport type LiftDecision = \"wait\" | \"lift\" | \"refuse\";\n\n/**\n * The lift rule for a press that has moved `distance` px in `elapsed` ms. A\n * mouse (or pen) lifts at `lift` px. A touch lifts only after `touchHold` ms,\n * then at `touchLift` px; moving `touchLift` px before the hold is over\n * refuses the drag (the finger is scrolling or swiping).\n */\nexport function liftDecision(press: { readonly touch: boolean; readonly distance: number; readonly elapsed: number }, tuning: Partial<DragTuning> = {}): LiftDecision {\n const t = { ...DRAG_DEFAULTS, ...tuning };\n if (!press.touch) return press.distance >= t.lift ? \"lift\" : \"wait\";\n if (press.elapsed < t.touchHold) return press.distance >= t.touchLift ? \"refuse\" : \"wait\";\n return press.distance >= t.touchLift ? \"lift\" : \"wait\";\n}\n\n/** One update's answer. */\nexport interface DragFrame<T extends DragTarget> {\n /** The target the drop indicator shows, or null. */\n readonly shown: T | null;\n /**\n * The others make room for the shown target: it, and the place in it, have held `roomAfter` ms. For a target with\n * `opensRoom`, or an armed spring-loaded one, from the first frame that shows it.\n */\n readonly room: boolean;\n /**\n * The place the room is made for, or null. Within one target it stays on\n * the old place until a new one has held `roomAfter` ms (see\n * {@link DragIntentOptions.placeOf}).\n */\n readonly roomPlace: string | null;\n /** The pointer is aiming: slow, or nearly still for a moment. */\n readonly aiming: boolean;\n /**\n * The pointer is back inside `home` after it has been outside `home` itself. Never true at the press, nor while the\n * pointer only moves about inside `home`, even near its edge (where `state.leftHome` is already true: that flag is for\n * the indicator's gate and uses `homeInset`; this one does not). Over home no target is shown and a release does\n * nothing, so a host that wants to say \"a drop here returns it\" draws its own indicator for this frame (at the home\n * rect); the intent still shows no target.\n *\n * A docked item's home holds wherever it lies. The home of a floating item (`DragIntentOptions.floating`) is a free\n * placement, ranked like the float: it holds only where the pick there, home ignored, is no refusal and the point is\n * inside the window. Where it doesn't hold this is false and the pick is as anywhere else: over a refusal\n * `refused` says so, and a release lands nowhere.\n */\n readonly atHome: boolean;\n /**\n * A spring-loaded target (`arm: \"dwell\"`) the pointer is in and dwelling on, not armed yet (a host highlights it), or\n * null. Once it arms it is a target like any other and may show.\n */\n readonly arming: T | null;\n /**\n * A key held wins over geometry this frame: `\"float\"` (the float key) or `\"rail\"` (the rail key), else null. The\n * float key chooses the float over dock targets, not over a refusal or outside the window: there it is still\n * `\"float\"` (the key is held), but nothing shows, a release lands nowhere, and over a refusal `refused` says which.\n */\n readonly forced: \"float\" | \"rail\" | null;\n /**\n * The refusal (a target with `refuse: true`) the pointer is over, when it is the pick there: no target shows. A host\n * never draws the refused place; it may say \"Can't go here\" at the pointer. Null otherwise, and while a key forces a target; with the float key\n * held over a refusal it is that refusal (the key doesn't float over refused space).\n */\n readonly refused: T | null;\n /**\n * No target shows, and the pointer has been over a refusal since a target last showed (or since the lift). A refusal\n * hides the shown target at once, and the next one shows only once the pointer aims again, so a pointer that crosses\n * a refusal and is let go at speed over a target beyond it has no indicator drawn. Then this is true, and a release\n * still lands on what is under the pointer (`release`): a host that commits only what it has drawn commits that\n * release too. False whenever a target shows, over the refusal itself (`refused`), and after `hide`.\n *\n * Read it from the frame of an `update` at the release point, called before `release` (as `release` asks anyway), so\n * the last move counts. The field is required: a host or a test mock that builds a `DragFrame` itself must set it.\n */\n readonly refusedSinceShown: boolean;\n /**\n * What a release at this frame's point lands on, by the one check `release` makes (`earlyRelease` included), or null\n * (nowhere, or the item goes home). A host draws the landing from it, so what it draws and what a release lands on\n * never disagree. `createDragIntent` always sets it; it is optional only so a host or a test that builds a frame\n * itself needn't.\n */\n readonly landing?: T | null;\n}\n\n/** What a drag intent knows now. */\nexport interface DragIntentState<T extends DragTarget> {\n /** The pointer's smoothed speed, px/ms. */\n readonly speed: number;\n /** The target under the pointer as the hysteresis holds it, or null. */\n readonly current: T | null;\n /** The target the indicator shows, or null. */\n readonly shown: T | null;\n /** The pointer has left the item's home. */\n readonly leftHome: boolean;\n}\n\nexport interface DragIntentOptions<T extends DragTarget> {\n /** Where the item was lifted from: the indicator stays off until the pointer leaves it, and a release there does nothing. */\n readonly home: Rect;\n /** Where the press that lifted the item was (the grip); default the first sample's point. The lift zone is about it. */\n readonly lift?: Point;\n /**\n * The lift zone as a rect instead of a radius, in the same px as the samples: while a sample is inside it no\n * spring-loaded target arms by dwell, and the `liftZone` radius is not applied. A host passes the part of the grip\n * that a drop strip covers (grip ∩ strip), so a pause back there commits nothing while the rest of the strip, right\n * beside a wide grip, still arms. Absent: the `liftZone` radius about `lift`.\n */\n readonly liftRect?: Rect;\n /**\n * The held item floats, and `home` is its own box. A floating item's own place is a free placement: it ranks like the\n * float target, so home holds only where the pick there, home ignored, is no refusal and the point lies inside the\n * window (no target's `bounds` left with nothing picked). Over a refusal in its box the frame is refused and a\n * release lands nowhere; on or past the window's edge nothing is picked; elsewhere in its box home holds as before.\n * Absent (a docked item): home holds wherever it lies, as its own home target beats a refusal.\n */\n readonly floating?: boolean;\n /**\n * What a release does before the item has settled on a target (no room open for it yet). `\"target\"` (the default): it\n * lands on the shown target, else the target under the pointer, drawn or not, an `opensRoom` target that hasn't shown\n * included. `\"float\"`: what shows is what lands, for a host whose dragged item is the only preview (`previewPlan`'s\n * `\"item\"`): the item is still on the pointer, so it floats there (the `free` target; over a refusal or outside the\n * float's `bounds`, nowhere). `release` is its one reader.\n */\n readonly earlyRelease?: \"target\" | \"float\";\n /** Overrides of {@link DRAG_DEFAULTS}. */\n readonly tuning?: Partial<DragTuning>;\n /**\n * The place within a target the pointer is at (a tab index, a stack\n * position, a pane's edge), unique across targets; default: the target's id.\n * Moving between places of the shown target moves the indicator at once but\n * the room only once the new place has held `roomAfter` ms.\n *\n * - `previous` is the place this target had on the last sample (null if it\n * had none), so a place can hold near its boundary (hysteresis).\n * - A null place is no target: there is no drop at that point of the target.\n * It isn't picked or held, the indicator hides there at once (or shows a\n * target beneath that has a place), no room opens, and a release there\n * lands on a target beneath, else goes home.\n * - It is also asked about the current target while the pointer is just\n * outside its hit zone (within the band, or during the gap grace). Answer\n * the nearest place there: returning null outside the zone drops the band\n * and the grace, so the indicator hides a few px past the edge. Return null\n * only for a part of the target that takes no drop.\n * - It is called on every sample for each target under the pointer and for\n * the current one, so keep it cheap and free of side effects.\n */\n readonly placeOf?: (target: T, point: Point, previous: string | null) => string | null;\n}\n\n/** A drag's intent: feed it the pointer on every frame; it says what the indicator shows and what a release lands on. */\nexport interface DragIntent<T extends DragTarget> {\n /**\n * A pointer sample at `time` (ms), with the targets as they stand (they may\n * be rebuilt between calls: the model follows them by id). Call it once a\n * frame while the item is held, also when the pointer doesn't move: a\n * dwell is time passing. `keys`: the modifier keys held now (see {@link DragModifiers}).\n */\n update(point: Point, time: number, targets: readonly T[], keys?: DragKeys): DragFrame<T>;\n /**\n * What a release at `point` lands on: the shown target whenever one shows\n * (a drop lands where the indicator was), else the target under the\n * pointer, else null (the item goes home). A release over home is null: it\n * does nothing. Feed the release point to `update` first, so a last jump\n * of the pointer counts. With a modifier key held (`keys`), the target the key picks, even over home.\n */\n release(point: Point, targets: readonly T[], keys?: DragKeys): T | null;\n /**\n * Hide the indicator (the view is scrolling under the pointer, say). The\n * aim starts afresh: the next sample never counts as aiming, and a dwell\n * starts again.\n */\n hide(time: number): void;\n /** The item's home moved with the view (it scrolled) by (dx, dy). */\n moveHome(dx: number, dy: number): void;\n readonly state: DragIntentState<T>;\n readonly tuning: DragTuning;\n}\n\n/**\n * The drag intent model: when the drop indicator shows, which target it\n * shows, when the others make room, and what a release lands on. Pure: fed\n * pointer samples and plain-data targets, no DOM and no clock of its own.\n *\n * - The indicator shows only when the pointer has left the item's home, a\n * target is under it, and it is aiming (slow, or nearly still for a\n * moment). Time spent crossing a big target at speed doesn't count.\n * - The most precise target wins (priority, then the smaller zone).\n * - Hysteresis: the current target holds while the pointer is within `band`\n * px of its zone, unless a more precise one is clearly (`breakthrough` px)\n * under the pointer; both scale down for small zones (`bandShare` of the\n * held zone's and the entered zone's extents along each axis), so a small\n * zone is entered by a direct glide; for a pointer that aims, a short gap between zones\n * (`gapGrace` ms) keeps it too.\n * - Leaving the shown target: flying, the indicator hides at once; aiming, it\n * moves to the new target once that has held `switchHold` ms (so no\n * indicator shows for less than that), at once for a breakthrough. A target\n * kept only by the gap grace can keep the indicator, never show it.\n * - Room is made once the shown target has held `roomAfter` ms, never for a\n * free target, and closes at once when it changes. A target with `opensRoom`\n * holds that long before it shows and has its room in the same frame; an\n * armed spring-loaded target has its room as it shows. With its room open,\n * one with a `roomHit` holds wherever the pointer is in that room, over a\n * refusal or a target no more precise than it under the room included.\n * - Where `placeOf` gives a target no place (null), it is no target: it is\n * neither shown nor landed on there.\n * - Spring-loading: a target marked `arm: \"dwell\"` is no target until the\n * pointer has stayed in its zone `railArmDwellMs` (the frame's `arming` says\n * which one it dwells on); then it is armed: its zone is `armedHit` (the\n * magnet) and it shows at once. Leaving that zone disarms it.\n * - Keys win over geometry (`modifiers`): the float key shows the `free` target\n * wherever the pointer is over a dock target or open space inside the float's\n * `bounds`, the rail key the nearest target marked `arm`; a release with the\n * key held lands there. Over a refusal, or outside the float's `bounds`, the\n * float key picks nothing: nothing shows and a release lands nowhere.\n */\nexport function createDragIntent<T extends DragTarget>(options: DragIntentOptions<T>): DragIntent<T> {\n const tuning: DragTuning = { ...DRAG_DEFAULTS, ...options.tuning };\n const placeOf = options.placeOf ?? ((t: T) => t.id);\n // Each target's place on the last sample, by id: its `previous` on the next.\n let lastPlaces = new Map<string, string | null>();\n let home: Rect = { ...options.home };\n let samples: { x: number; y: number; t: number }[] = [];\n let cur: T | null = null;\n let curSince = 0;\n let lastInside = 0;\n let shown: T | null = null;\n let shownSince = 0;\n let place: string | null = null;\n let placeSince = 0;\n let roomPlace: string | null = null;\n let leftHome = false;\n // The pointer has been outside `home` itself (`leftHome` turns on already near its edge): `atHome`'s own memory.\n let wentOut = false;\n let speed = 0;\n let anchor: Point | null = null;\n let stillSince = 0;\n let restart = false;\n // The pointer has been over a refusal since a target last showed (the frame's `refusedSinceShown`).\n let crossedRefusal = false;\n // Spring-loading: the target armed (by id), and the one the pointer dwells on and since when.\n let armedId: string | null = null;\n let armingId: string | null = null;\n let armingSince = 0;\n // The spring-loaded targets (by id) the pointer has been outside of during this drag: only those can arm.\n const wasOutside = new Set<string>();\n // The point the drag was lifted at: no spring-loaded target arms by dwell within `liftZone` of it.\n let liftAt: Point | null = options.lift ? { ...options.lift } : null;\n const same =(a: T | null, b: T | null): boolean => (a === null || b === null ? a === b : a.id === b.id);\n // Targets may be rebuilt between calls: follow the ones held by id.\n const follow = (t: T | null, targets: readonly T[]): T | null => (t ? (targets.find((x) => x.id === t.id) ?? t) : null);\n /** An armed target as it acts: its zone is `armedHit` (the magnet) when it has one. */\n const asArmed = (x: T): T => {\n if (!x.armedHit) return x;\n const { hits: _pieces, ...rest } = x;\n return { ...rest, hit: x.armedHit } as T;\n };\n /** The targets as they act now: a spring-loaded one only once armed, in its armed zone. */\n const acting = (targets: readonly T[]): T[] => targets.filter((x) => x.arm !== \"dwell\" || x.id === armedId).map((x) => (x.id === armedId ? asArmed(x) : x));\n /**\n * The target a held key picks at `p`: the float key the `free` target, the rail key the nearest spring-loaded one.\n * The float key chooses the float over dock targets, not over refusals or outside the window: where the pick at `p`\n * (`has`: a target with a place there, or a refusal) is a refusal, it picks nothing and says which refusal; outside\n * the float's `bounds` (a pointer clamped onto the window's edge) it picks nothing. The rail key's drop lands on the\n * rail, not where the pointer is, so neither applies to it.\n */\n const forcedBy = (keys: DragKeys | undefined, p: Point, targets: readonly T[], has: (x: T) => boolean): { kind: \"float\" | \"rail\"; target: T | null; refused: T | null } | null => {\n const m = tuning.modifiers;\n if (!m.on || !keys) return null;\n if (held(keys, m.floatKey)) {\n const f = targets.find((x) => x.free);\n if (!f) return null;\n const under = targetAt(acting(targets).filter((x) => inZone(x, p) && has(x)), p);\n if (under?.refuse === true) return { kind: \"float\", target: null, refused: under };\n return within(f.bounds, p) ? { kind: \"float\", target: f, refused: null } : { kind: \"float\", target: null, refused: null };\n }\n if (!held(keys, m.railKey)) return null;\n let best: T | null = null;\n let bestD = Infinity;\n for (const x of targets) {\n if (x.arm !== \"dwell\") continue;\n const d = distanceTo(asArmed(x).hit, p);\n if (d < bestD) {\n best = x;\n bestD = d;\n }\n }\n return best ? { kind: \"rail\", target: asArmed(best), refused: null } : null;\n };\n\n /** What a release at `point` lands on, as things stand now: `release`'s answer, and every frame's `landing`. */\n const landAt = (point: Point, given: readonly T[], keys: DragKeys | undefined): T | null => {\n // A key held wins over geometry, home included; the float key over a refusal or outside the window lands nowhere.\n const forced = forcedBy(keys, point, given, (x) => x.refuse === true || placeOf(x, point, lastPlaces.get(x.id) ?? null) !== null);\n if (forced) {\n const ft = forced.target;\n return ft ? (given.find((x) => x.id === ft.id) ?? ft) : null;\n }\n // Over home a release does nothing, except onto an armed spring-loaded target whose zone overlaps home.\n if (inRect(home, point)) {\n const armed = armedId === null ? null : given.find((x) => x.id === armedId);\n return armed && inZone(asArmed(armed), point) && placeOf(armed, point, lastPlaces.get(armed.id) ?? null) !== null ? armed : null;\n }\n const targets = acting(given);\n // Drop = shown: a shown target is kept until it hides (flying out past its band hides it at once).\n const s = shown && !(shown.arm === \"dwell\" && shown.id !== armedId) ? follow(shown, given) : null;\n // The target under the pointer that has a place there (a null place is no drop); a refusal there lands nowhere.\n const under = targetAt(\n targets.filter((x) => inZone(x, point) && (x.refuse === true || placeOf(x, point, lastPlaces.get(x.id) ?? null) !== null)),\n point,\n );\n if (options.earlyRelease === \"float\") {\n // What shows is what lands: a target with a slot only once its room is open; before that the item is still on\n // the pointer, so it floats there. A target with no slot (the item's own place, a blocked one) needs no room.\n const needsNoRoom = (x: T): boolean => x.free === true || !x.slot;\n if (s && (needsNoRoom(s) || roomPlace !== null)) return s;\n if (under?.refuse) return null;\n if (under && !under.free && !under.slot) return given.find((x) => x.id === under.id) ?? under;\n const float = given.find((x) => x.free);\n return float && within(float.bounds, point) ? float : null;\n }\n if (s) return s;\n return under && !under.refuse ? (given.find((x) => x.id === under.id) ?? under) : null;\n };\n\n return {\n tuning,\n get state(): DragIntentState<T> {\n return { speed, current: cur, shown, leftHome };\n },\n update(point, time, given, keys) {\n const p = point;\n const t = time;\n samples.push({ x: p.x, y: p.y, t });\n while (samples.length > 2 && t - samples[0]!.t > tuning.speedWindow) samples.shift();\n const a = samples[0]!;\n speed = speed * 0.5 + (Math.hypot(p.x - a.x, p.y - a.y) / Math.max(1, t - a.t)) * 0.5;\n if (!anchor || Math.hypot(p.x - anchor.x, p.y - anchor.y) > tuning.still) {\n anchor = { x: p.x, y: p.y };\n stillSince = t;\n }\n if (!inRect(home, p, -tuning.homeInset)) leftHome = true;\n const atHome = inRect(home, p);\n if (!atHome) wentOut = true;\n // Each target's place at this point, worked out once per sample; a null place is no target.\n const places = new Map<string, string | null>();\n const placeAt = (x: T): string | null => {\n if (!places.has(x.id)) places.set(x.id, placeOf(x, p, lastPlaces.get(x.id) ?? null));\n return places.get(x.id)!;\n };\n const live = (x: T | null): x is T => x !== null && placeAt(x) !== null;\n // Spring-loading: the armed target holds while the pointer is in its armed zone; a target the pointer dwells in\n // arms once it has held `railArmDwellMs`. A key held wins over both.\n const forced = forcedBy(keys, p, given, (x) => x.refuse === true || live(x));\n if (armedId !== null) {\n const was = given.find((x) => x.id === armedId);\n if (!was || forced || !inZone(asArmed(was), p) || !live(was)) armedId = null;\n }\n // Spring-loading is not gated by `atHome`: a strip that overlaps the item's own place still arms by dwell.\n // A spring-loaded target arms only after the pointer has entered it: one it has been outside of during the drag.\n for (const x of given) if (x.arm === \"dwell\" && !inZone(x, p)) wasOutside.add(x.id);\n // Inside the lift zone nothing arms by dwell (\"changed my mind\"); the rail key still forces the rail.\n // With a `liftRect` the zone is that rect, the radius not applied.\n liftAt ??= { x: p.x, y: p.y };\n const inLiftZone = options.liftRect ? inRect(options.liftRect, p) : Math.hypot(p.x - liftAt.x, p.y - liftAt.y) <= tuning.liftZone;\n const dwelling = forced || inLiftZone ? null : targetAt(given.filter((x) => x.arm === \"dwell\" && x.id !== armedId && wasOutside.has(x.id) && inZone(x, p) && live(x)), p);\n let armedNow = false;\n if (!dwelling || armedId !== null) armingId = null;\n else {\n if (armingId !== dwelling.id) {\n armingId = dwelling.id;\n armingSince = t;\n }\n if (t - armingSince >= tuning.railArmDwellMs) {\n armedId = dwelling.id;\n armingId = null;\n armedNow = true;\n }\n }\n const arming = armingId === null ? null : (given.find((x) => x.id === armingId) ?? null);\n const targets = acting(given);\n // A docked item's home holds wherever it lies (its own home target beats a refusal). A floating item's own place\n // is a free placement, ranked like the float: its home holds only where the pick there, home ignored, is no\n // refusal and not nothing outside a target's `bounds` (past the window). Elsewhere the pick is as anywhere else.\n const underHome = atHome && options.floating ? targetAt(targets.filter((x) => inZone(x, p) && (x.refuse === true || live(x))), p) : null;\n const pastBounds = atHome && options.floating ? targets.some((x) => x.bounds !== undefined && !within(x.bounds, p)) : false;\n const homeHolds = atHome && (!options.floating || (underHome?.refuse !== true && !(underHome === null && pastBounds)));\n // Over home no target is picked, except a spring-loaded one that is armed (its zone overlaps home): home gates\n // geometry, not an armed dwell.\n const pickable = (x: T): boolean => !homeHolds || (x.arm === \"dwell\" && x.id === armedId);\n // A refusal takes part in the pick (it needs no place), but it is never a target: never held, never shown.\n const raw = targetAt(targets.filter((x) => pickable(x) && inZone(x, p) && (x.refuse === true || live(x))), p);\n // A spring-loaded target that isn't armed (any more) is no target: neither held nor shown.\n const disarmed = (x: T | null): boolean => x?.arm === \"dwell\" && x.id !== armedId;\n cur = disarmed(cur) ? null : follow(cur, targets);\n shown = disarmed(shown) ? null : follow(shown, targets);\n if (!live(cur)) cur = null;\n // A target shown with its room open holds in the room it opened (`roomHit`): what lies there is drawn as the room,\n // so a refusal under it is no refusal here.\n const roomHeld = cur && cur.opensRoom === true && cur.roomHit && roomPlace !== null && same(cur, shown) && pickable(cur) && within(cur.bounds, p) && inRect(cur.roomHit, p) ? cur : null;\n const refusedRaw = raw?.refuse === true && !roomHeld ? raw : null;\n // The band about a held zone, and the breakthrough into a zone, scaled with the zones (see `bandShare`).\n const bandOf = (held: T): Margin => scaled(tuning.band, tuning.bandShare, [held, raw && !same(raw, held) ? raw : null]);\n const pastBreakthrough = (x: T): boolean => inZoneBy(x, p, negate(scaled(tuning.breakthrough, tuning.bandShare, [x])));\n // Over a refusal nothing is held: no band and no gap grace keep the current target there.\n let next = refusedRaw ? null : raw;\n if (!refusedRaw && cur && pickable(cur) && (roomHeld !== null || inZoneBy(cur, p, bandOf(cur)))) {\n // Over a `free` target (the float everywhere) there is no edge to hold against: a more precise target takes over\n // once the pointer is in it, so a zone that ends at the window's edge is reached at its very first px. A refusal\n // here lies under the open room: it never takes over.\n const breaks = raw !== null && raw.refuse !== true && !same(raw, cur) && raw.priority < cur.priority && (cur.free === true || pastBreakthrough(raw));\n next = breaks ? raw : cur;\n }\n // The gap grace, like the band, never reaches past a zone's bounds: the float gets no grace outside the window.\n if (!refusedRaw && !next && cur && pickable(cur) && within(cur.bounds, p) && t - lastInside < tuning.gapGrace) next = cur;\n if (next && (inZone(next, p) || same(next, roomHeld))) lastInside = t;\n if (!same(next, cur)) curSince = t;\n cur = next;\n const aiming = !restart && (speed < tuning.aimSpeed || t - stillSince >= tuning.dwell);\n restart = false;\n const show = (s: T | null): void => {\n if (!same(s, shown)) shownSince = t;\n shown = s;\n };\n // Under the pointer (within its band, or in the room it holds), not just kept by the gap grace.\n const under = !!cur && (same(cur, roomHeld) || inZoneBy(cur, p, bandOf(cur)));\n // A target that opens its room as it shows shows only once it has held (`roomHold`, else `roomAfter`): one decision\n // for both, so a sweep moves nothing and the indicator never lies over what the room will move. An armed one has\n // had its dwell.\n const ready = (x: T): boolean => x.opensRoom !== true || x.arm === \"dwell\" || t - curSince >= (x.roomHold ?? tuning.roomAfter);\n // A shown target with no place here is no drop: the indicator hides at once (the switch hold is for targets).\n if (shown && !live(shown)) show(null);\n if (!shown) {\n if (cur && under && leftHome && aiming && ready(cur)) show(cur);\n } else if (same(cur, shown)) {\n // It stays while its target holds; but a pointer flying out past the band hides it at once.\n if (!aiming && !under) show(null);\n else shown = cur;\n } else if (!cur || !aiming) {\n show(null);\n } else if ((cur.priority < shown.priority && (shown.free === true || pastBreakthrough(cur))) || (under && t - curSince >= tuning.switchHold)) {\n // Not ready yet: the old indicator goes, and a release lands on the target under the pointer.\n show(ready(cur) ? cur : null);\n }\n // An armed target shows at once: the dwell was the aim. A key held wins over all of it.\n if (armedNow && cur?.id === armedId && under) show(cur);\n // A key that picks nothing here (the float key over a refusal or outside the window) shows nothing.\n if (forced) {\n if (!same(forced.target, cur)) curSince = t;\n cur = forced.target;\n show(forced.target);\n }\n // The place within the shown target, and the room: after the target and the place have both held; with the target\n // itself where showing it was already that decision (`opensRoom`, an armed target's dwell).\n const at = shown ? placeAt(shown) : null;\n if (at !== place) {\n place = at;\n placeSince = t;\n }\n if (!shown || shown.free) roomPlace = null;\n else if (shown.opensRoom === true || shown.arm === \"dwell\") roomPlace = place;\n else if (t - shownSince >= tuning.roomAfter && t - placeSince >= tuning.roomAfter) roomPlace = place;\n else if (shownSince === t) roomPlace = null;\n lastPlaces = places;\n // A refusal crossed since a target last showed: a release beyond it lands on what is under the pointer, drawn or not.\n // With a key held, the refusal is the one the key's pick met (the float key over a refusal), else none.\n const refused = forced ? forced.refused : refusedRaw;\n if (shown) crossedRefusal = false;\n else if (refused) crossedRefusal = true;\n return { shown, room: roomPlace !== null, roomPlace, aiming, atHome: !forced && wentOut && homeHolds, arming, forced: forced?.kind ?? null, refused, refusedSinceShown: !shown && !refused && crossedRefusal, landing: landAt(p, given, keys) };\n },\n release(point, given, keys) {\n return landAt(point, given, keys);\n },\n hide(time) {\n shown = null;\n cur = null;\n armedId = null;\n armingId = null;\n shownSince = time;\n place = null;\n roomPlace = null;\n lastPlaces = new Map();\n samples = [];\n anchor = null;\n restart = true;\n crossedRefusal = false;\n },\n moveHome(dx, dy) {\n home = { ...home, x: home.x + dx, y: home.y + dy };\n },\n };\n}\n","import type { Point, Rect } from \"../shapes\";\nimport type { DragKeys } from \"./intent\";\nimport type { PlaceGuides } from \"./preview\";\n\n/**\n * The landing model: where a docking drag's item lands, as state rather than a per-frame guess. A host gives it the\n * drag's regions (from `@n-uf/placement/scene`'s `lanes()`: plain data, the shapes below) and each pointer sample; it\n * says the region the pointer is in, the lane and spot held, where the item lands, whether the room is open, and the\n * place guides. Every change comes from where the pointer is and how it moved (margins, a path length, a step size):\n * the model has no waits of its own.\n *\n * - **The stage's edge** is the easiest place to dock: a pointer past the stage by up to `edge` px counts as on its\n * edge, so it lies deep inside a lane drawn against that edge; beyond, it is nowhere.\n * - **A lane holds** while the pointer is inside its rect grown by `exit`, whatever lies under it. Inside, over a spot's\n * stretch it is at that spot; over a refused stretch of the lane, refused (\"Can't go here\"). (Placement's `lanes()`\n * joins a refused stretch shorter than the item to its spots.)\n * - **Entering a lane** needs one of two gates: `path` px of slow pointer path along it inside it (steps of at most\n * `step`), or a still step (at most `still`) once `depth` px inside, the depth counted only from the lane's sides that\n * face into the stage (on the edge it is deep). A fly-through of a thin bar or rail at any angle meets neither, so its\n * room never opens. Inside a lane that touches the held one, past the held lane's exit margin, the held lane holds\n * until that lane's gate passes or the pointer has slid `path` px along it at any speed (across it at most a third as\n * far): lane to lane never passes through the float, and never opens a crossed lane's room. Over a refused place (a\n * lane's band lying over a column that takes nothing: an empty side rail's) a lane is entered on the first slow step\n * there (not on the lift), as there is nothing else to mean there; a fly-through still opens no room. A lane that owns\n * its rect (`owns`: a rail drop strip at the window's side) takes the pointer inside it from any lane it overlaps, a\n * held one too, once its own gate passes and only once the pointer came into it from outside since the lift. Within\n * `margins.lift` of the lift point (`options.lift`, else the first point; fixed for the drag) an owning lane takes the\n * pointer by no gate, so a pointer brought back there is in the item's own lane, not the strip. Elsewhere in the strip\n * a slow slide along it can take the pointer before it is back at the lift point.\n * - **Along a lane** the spot changes once the pointer is `spot` px past the boundary; where the change moves another\n * item (the two spots' `others` keys differ), on a step of at most `step`, or once the held landing trails the\n * pointer by more than `trail`: the item chases only as far as it must. A change that moves only the held item\n * follows the hand at any speed. With `regionsFor`, a reflowing change is kept only if, in the new spot's own regions\n * (its room open), the pointer still lies in that spot's stretch: the room shifting the boundary never bounces it.\n * - **Outside every lane:** a refused place, refused; open space (`\"open\"`: the content less what blocks it, the page),\n * the float at its landing; outside the stage (past `edge`), nowhere; else (docked content that takes nothing and\n * refuses nothing) refused.\n * - **Shift** turns a lane or open space into open space (the float), and hides the guides.\n * - **Guides** are the lane's `marks` (lines between items, a box per free stretch, in the layout as drawn), else its\n * spots' landings: the held lane's; else the approached lane's (the nearest within `reach`); over a refused place the\n * nearest lane's at any distance, so the lane behind a refused column shows its guides.\n * - Steps are measured between points that differ, normalized to 125 Hz, so the gates read the same at any input rate.\n * A repeated point keeps the last step; it is still only once the pointer has stayed put for `rest` ms.\n *\n * **The host's part:** call `update` whenever you like: per pointer sample, per animation frame, or both. Call it at\n * least once more after the pointer stops (every frame does), so it can become still, and again with the same point\n * when a key changes. Give `setRegions` the `regionsFor` that answers for the new state.\n */\n\n/** A place a drop in a lane lands: its stretch of the lane and its landing rect. Ids are stable across solves. */\nexport interface LandingSpot {\n readonly id: string;\n readonly along: readonly [number, number];\n readonly landing: Rect;\n /**\n * Where its drop draws every other item, as a key: a change between two spots with the same key moves only the held\n * item. Absent: every change to or from it counts as moving others.\n */\n readonly others?: string;\n}\n/**\n * A place guide's mark, in the layout as drawn: a line between two items that touch, a box over free room the item\n * lands in, a hatch over the part of a neighbor that gives way where the room is shorter than the item.\n */\nexport interface LandingMark {\n /** Stable while its neighbors stay; absent, the guide is keyed by its lane and place in the list. */\n readonly id?: string;\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n}\nexport interface LandingLane {\n readonly id: string;\n readonly rect: Rect;\n readonly axis: \"x\" | \"y\";\n readonly spots: readonly LandingSpot[];\n readonly refused: readonly { readonly along: readonly [number, number] }[];\n /** Its guides' marks; absent, its spots' landings are the guides. */\n readonly marks?: readonly LandingMark[];\n /**\n * Its rect is its own (a rail drop strip at the window's side): inside it, once its gate passes, it takes the pointer\n * from any lane it overlaps, a held one too. Absent: where lanes overlap, the deeper one wins.\n */\n readonly owns?: boolean;\n}\n/** A drag's regions (`lanes()` gives them). */\nexport interface LandingRegions {\n readonly lanes: readonly LandingLane[];\n readonly refused: readonly Rect[];\n readonly content: Rect;\n readonly blocked: readonly Rect[];\n readonly stage: Rect;\n /** The held item's size. */\n readonly item: { readonly width: number; readonly height: number };\n}\n\nexport interface LandingMargins {\n /** Past a held lane's rect before it lets go, px. */\n readonly exit: number;\n /** Past a spot boundary before the spot changes, px. */\n readonly spot: number;\n /** Past the stage that still counts as on its edge, px; beyond, nowhere. */\n readonly edge: number;\n /**\n * Around the lift point, px (16, as the drag intent's `liftZone`): an owning lane never takes the pointer there, so\n * away and back to where the item was lifted is home.\n */\n readonly lift?: number;\n}\nexport interface LandingGates {\n /** Pointer path inside a lane that enters it, px. */\n readonly path: number;\n /** Depth inside a lane where a still step enters it, px. */\n readonly depth: number;\n /** A still step, px per 8 ms. */\n readonly still: number;\n /**\n * The largest step that changes the spot along a lane where the change reflows the window, px per 8 ms; it also\n * bounds the steps the path gate counts (a fast crossing never enters).\n */\n readonly step: number;\n /** How far the held landing may trail the pointer before a fast reflowing change is taken anyway, px. */\n readonly trail: number;\n /**\n * The time a pointer has to stay put before it counts as still, ms, where its last step was already slow (at most\n * `step`) or it is on the stage's edge (a fling there is taken at once); repeated points before it aren't still.\n */\n readonly rest: number;\n /** The time a pointer that last moved fast has to stay put before it counts as still, ms: longer than sample gaps. */\n readonly pause: number;\n}\n/** The approach for near guides: the nearest lane within `reach`, kept until another is `nearer` closer or past `keep`. */\nexport interface LandingApproach {\n readonly reach: number;\n readonly keep: number;\n readonly nearer: number;\n}\n\nexport const LANDING_MARGINS: LandingMargins = { exit: 12, spot: 6, edge: 48, lift: 16 };\n/** A touch: wider margins, the finger's jitter. */\nexport const LANDING_TOUCH_MARGINS: LandingMargins = { exit: 16, spot: 8, edge: 48, lift: 16 };\nexport const LANDING_GATES: LandingGates = { path: 40, depth: 8, still: 1.5, step: 3, trail: 40, rest: 22, pause: 60 };\nexport const LANDING_APPROACH: LandingApproach = { reach: 80, keep: 96, nearer: 16 };\n\nexport interface LandingOptions {\n readonly regions: LandingRegions;\n /** The regions with `spot` held (its room open): the fixed-point check and the stretches while held. Cached per id. */\n readonly regionsFor?: (spot: string) => LandingRegions | null;\n /** The float's landing for a pointer over the document, or null where the item doesn't float. */\n readonly floatLanding?: (point: Point) => Rect | null;\n /** The item's own place at the lift: its lane and spot (the drag starts there, the room open). */\n readonly home?: { readonly lane: string; readonly spot: string };\n /** Where the item was lifted (the press), in the regions' space; default the first point `update` gets. */\n readonly lift?: Point;\n readonly margins?: Partial<LandingMargins>;\n readonly gates?: Partial<LandingGates>;\n readonly approach?: Partial<LandingApproach>;\n readonly placeGuides?: PlaceGuides;\n}\n\nexport type LandingRegion = \"lane\" | \"open\" | \"refused\" | \"nowhere\";\n\n/** A guide: a mark of a lane, where to draw it now (a spot's landing is a box). */\nexport interface LandingGuide {\n /** Stable while its neighbors stay: the mark's id, else `<lane>/<spot id>` for a spot's landing. Key a drawing by it. */\n readonly id: string;\n readonly lane: string;\n /** A line, a box, or a hatch over a neighbor that gives way (draw it over that item, in the guides' color). */\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n}\n\nexport interface LandingFrame {\n readonly region: LandingRegion;\n /** The lane held (also over its refused stretch), or null. */\n readonly lane: string | null;\n /** The spot held, or null. */\n readonly spot: string | null;\n /** Where a release now lands: the spot's landing, or the float's; null where it lands nowhere (the item goes home). */\n readonly landing: Rect | null;\n /** The room is open: a spot is held in a lane, no Shift. */\n readonly room: boolean;\n readonly guides: readonly LandingGuide[];\n /** Shift held: the region is open space wherever it was a lane or open space. */\n readonly shift: boolean;\n /**\n * The lane the pointer is inside but hasn't entered (its gate not passed yet: a fast pass, or the moment before a slow\n * step), else absent. A host shows no \"Can't go here\" while it is set, though a release now lands nowhere: the place\n * under the pointer is a lane's, not a refused one.\n */\n readonly pending?: string;\n}\n\n/** What a release lands: a spot (`home` when it is the item's own place), the float at `rect`, or nothing. */\nexport type LandingRelease = { readonly kind: \"spot\"; readonly lane: string; readonly spot: string; readonly home: boolean } | { readonly kind: \"float\"; readonly rect: Rect } | null;\n\nexport interface LandingModel {\n update(point: Point, time: number, keys?: DragKeys): LandingFrame;\n /** What a release lands, by the last frame: the same answer as its `landing`. */\n release(): LandingRelease;\n /**\n * The regions changed (a resize, a store change, a scroll): spots map by id; a lost one goes to its lane's nearest.\n * Pass the `regionsFor` that answers for the new state; without one, the old one stays (it must then read live state).\n */\n setRegions(regions: LandingRegions, regionsFor?: (spot: string) => LandingRegions | null): void;\n /** The view moved under the pointer: the gates start again, the lane is let go. */\n hide(): void;\n readonly frame: LandingFrame;\n}\n\nconst inside = (r: Rect, p: Point, grow = 0): boolean => p.x >= r.x - grow && p.x <= r.x + r.width + grow && p.y >= r.y - grow && p.y <= r.y + r.height + grow;\nconst strictlyIn = (r: Rect, p: Point): boolean => p.x >= r.x && p.x <= r.x + r.width && p.y >= r.y && p.y <= r.y + r.height;\n/**\n * How deep `p` lies inside `r` (0 on its edge or outside), counted only from the sides of `r` that face into `stage`: a\n * side on the stage's edge is open, as deep as the pointer can go.\n */\nfunction depthIn(r: Rect, p: Point, stage: Rect): number {\n if (!strictlyIn(r, p)) return 0;\n const on = (a: number, b: number): boolean => Math.abs(a - b) < 1;\n const sides = [\n on(r.x, stage.x) ? Infinity : p.x - r.x,\n on(r.x + r.width, stage.x + stage.width) ? Infinity : r.x + r.width - p.x,\n on(r.y, stage.y) ? Infinity : p.y - r.y,\n on(r.y + r.height, stage.y + stage.height) ? Infinity : r.y + r.height - p.y,\n ];\n return Math.max(0, Math.min(...sides));\n}\nconst distanceTo = (r: Rect, p: Point): number => Math.hypot(Math.max(r.x - p.x, 0, p.x - (r.x + r.width)), Math.max(r.y - p.y, 0, p.y - (r.y + r.height)));\nconst alongOf = (lane: LandingLane, p: Point): number => (lane.axis === \"x\" ? p.x : p.y);\nconst acrossOf = (lane: LandingLane, p: Point): number => (lane.axis === \"x\" ? p.y : p.x);\n/** Two rects meet: they overlap or touch (within 1 px), corners included. */\nconst touches = (a: Rect, b: Rect): boolean => a.x <= b.x + b.width + 1 && b.x <= a.x + a.width + 1 && a.y <= b.y + b.height + 1 && b.y <= a.y + a.height + 1;\n/** `p` onto `stage` when it lies past it by at most `reach`; else null (nowhere). */\nfunction ontoStage(stage: Rect, p: Point, reach: number): Point | null {\n if (!inside(stage, p, reach)) return null;\n return { x: Math.min(Math.max(p.x, stage.x), stage.x + stage.width), y: Math.min(Math.max(p.y, stage.y), stage.y + stage.height) };\n}\n\nexport function createLandingModel(options: LandingOptions): LandingModel {\n const margins = { ...LANDING_MARGINS, ...options.margins };\n const gates = { ...LANDING_GATES, ...options.gates };\n const approach = { ...LANDING_APPROACH, ...options.approach };\n const guidesLevel: PlaceGuides = options.placeGuides ?? \"off\";\n let base = options.regions;\n let regionsFor = options.regionsFor;\n const cache = new Map<string, LandingRegions | null>();\n /** The regions with `spot` held: the host's, cached for this lift until `setRegions`. */\n const heldRegions = (spot: string | null): LandingRegions => {\n if (!spot || !regionsFor) return base;\n if (!cache.has(spot)) cache.set(spot, regionsFor(spot));\n return cache.get(spot) ?? base;\n };\n\n let laneId: string | null = options.home?.lane ?? null;\n let spotId: string | null = options.home?.spot ?? null;\n let last: { p: Point; raw: Point; t: number } | null = null;\n /** The last point that differed from the one before, and the step then. */\n let moved: { raw: Point; t: number } | null = null;\n /** Where the item was lifted (`lift`, else the first point), fixed for the drag: back there, no owning lane takes it. */\n let liftAt: Point | null = options.lift ?? null;\n let lastStep = 0;\n /** Path inside each lane since the pointer last entered its rect. */\n const pathIn = new Map<string, number>();\n /** The path along and across each lane at any speed since the pointer entered it (a touching lane's takeover). */\n const slide = new Map<string, { along: number; across: number }>();\n /** The owning lanes the pointer has been outside since the lift: only those may take it (it came into them). */\n const cameIn = new Set<string>();\n let approached: string | null = null;\n let previous: LandingRegion = laneId ? \"lane\" : \"open\";\n let frame: LandingFrame = { region: previous, lane: laneId, spot: spotId, landing: null, room: !!spotId, guides: [], shift: false };\n\n const laneIn = (regions: LandingRegions, id: string | null): LandingLane | undefined => (id ? regions.lanes.find((l) => l.id === id) : undefined);\n const spotIn = (lane: LandingLane | undefined, id: string | null): LandingSpot | undefined => (lane && id ? lane.spots.find((s) => s.id === id) : undefined);\n\n /** The spot a point along `lane` picks: the spot whose stretch holds it, null over a refused stretch, else the nearest. */\n function pick(lane: LandingLane, a: number): LandingSpot | null {\n if (lane.refused.some((r) => a >= r.along[0] && a <= r.along[1])) return null;\n const hit = lane.spots.find((s) => a >= s.along[0] && a <= s.along[1]);\n if (hit) return hit;\n let best: LandingSpot | null = null;\n let dist = Infinity;\n for (const s of lane.spots) {\n const d = a < s.along[0] ? s.along[0] - a : a - s.along[1];\n if (d < dist) {\n best = s;\n dist = d;\n }\n }\n return best;\n }\n\n /** Along a held lane: the spot after hysteresis, the step gate and the fixed-point check. */\n function along(lane: LandingLane, p: Point, step: number): LandingSpot | null {\n const regions = heldRegions(spotId);\n const held = laneIn(regions, lane.id) ?? lane;\n const a = alongOf(held, p);\n const now = spotIn(held, spotId);\n const cand = pick(held, a);\n if (!cand) return null;\n if (!now || cand.id === now.id) return cand;\n // Past the boundary by the margin, the same everywhere (a wobble within it never flips the spot); where the change\n // moves another item, on a slow enough step. Else the last spot holds.\n const past = a < now.along[0] - margins.spot || a > now.along[1] + margins.spot;\n const reflows = now.others === undefined || now.others !== cand.others;\n if (!past) return now;\n // A fast reflowing change waits for a slow step, unless the held landing already trails the pointer by `trail`: the\n // item chases only as far as it must, so a fast hand across docked items never leaves it far behind.\n if (reflows && step > gates.step && distanceTo(now.landing, p) <= gates.trail) return now;\n // The fixed point: in the candidate's own regions (its room open), the pointer still picks it.\n if (regionsFor && reflows) {\n const theirs = heldRegions(cand.id);\n const lane2 = laneIn(theirs, lane.id);\n if (lane2 && pick(lane2, alongOf(lane2, p))?.id !== cand.id) return now;\n }\n return cand;\n }\n\n function guidesFor(p: Point, region: LandingRegion, shift: boolean): LandingGuide[] {\n if (guidesLevel === \"off\" || shift) return [];\n const regions = heldRegions(spotId);\n const all = (l: LandingLane): LandingGuide[] =>\n l.marks\n ? l.marks.map((m, i) => ({ id: m.id ?? `${l.id}#${i}`, lane: l.id, kind: m.kind, rect: m.rect }))\n : l.spots.map((s) => ({ id: `${l.id}/${s.id}`, lane: l.id, kind: \"box\" as const, rect: s.landing }));\n if (guidesLevel === \"all\") return regions.lanes.flatMap(all);\n if ((region === \"lane\" || region === \"refused\") && laneId) {\n approached = laneId;\n const l = laneIn(regions, laneId);\n return l ? all(l) : [];\n }\n let best: LandingLane | null = null;\n let bestD = Infinity;\n for (const l of regions.lanes) {\n const d = distanceTo(l.rect, p);\n if (d < bestD) {\n best = l;\n bestD = d;\n }\n }\n // Over a refused place: the nearest lane at any distance (the lane behind a refused column).\n if (region === \"refused\") {\n approached = best?.id ?? null;\n return best ? all(best) : [];\n }\n // The approached lane: the nearest within reach, kept until another is clearly nearer or it is past `keep`.\n const kept = laneIn(regions, approached);\n if (kept) {\n const d = distanceTo(kept.rect, p);\n if (d > approach.keep) approached = null;\n else if (best && best.id !== kept.id && bestD + approach.nearer < d) approached = bestD <= approach.reach ? best.id : null;\n } else approached = best && bestD <= approach.reach ? best.id : null;\n const l = laneIn(regions, approached);\n return l ? all(l) : [];\n }\n\n function update(raw: Point, t: number, keys?: DragKeys): LandingFrame {\n // Past the stage by up to `edge`: on its edge. Beyond: nowhere (kept as is).\n const p = ontoStage(heldRegions(spotId).stage, raw, margins.edge) ?? raw;\n // The step: the pointer as it moved (a fling past the edge isn't still) since the last point that differed,\n // normalized to 125 Hz (8 ms). A repeated point (a host updating per frame, or a gap between sparse samples) keeps\n // the last step until the pointer has stayed put for `rest` ms after a slow step or on the stage's edge, else for\n // `pause` ms; only then is it still. A hand moving fast with samples far apart is never still between them.\n let step = 0;\n if (moved && (raw.x !== moved.raw.x || raw.y !== moved.raw.y)) {\n step = (Math.hypot(raw.x - moved.raw.x, raw.y - moved.raw.y) * 8) / Math.max(1, t - moved.t);\n moved = { raw, t };\n lastStep = step;\n } else if (moved) {\n const stage = heldRegions(spotId).stage;\n const onEdge = p.x <= stage.x || p.y <= stage.y || p.x >= stage.x + stage.width || p.y >= stage.y + stage.height;\n const since = t - moved.t;\n step = since >= gates.pause || (since >= gates.rest && (lastStep <= gates.step || onEdge)) ? 0 : lastStep;\n } else {\n // The first point: how the pointer moves is unknown, never still (a lift over a lane's band doesn't enter it).\n moved = { raw, t };\n // (After `hide()` too, the lift point stays where the drag began.)\n liftAt ??= p;\n step = lastStep = Infinity;\n }\n const from = last?.p ?? null;\n // The pointer as it moved: a fling off the stage's edge moves across a lane there though its clamped point doesn't.\n const fromRaw = last?.raw ?? null;\n last = { p, raw, t };\n const shift = !!keys?.shift;\n const regions = heldRegions(spotId);\n // The path inside each lane: the part along the lane of slow steps from a point inside it to another (the step that\n // enters doesn't count, nor a fast one), so a crossing at `step` speed or faster never enters by path at any angle.\n // From a held lane, a touching lane counts the path along it and across it at any speed: a fast slide along it\n // (across it at most a third as far as along) is no crossing.\n const slow = step <= gates.step;\n for (const l of regions.lanes) {\n const was = from && strictlyIn(l.rect, from);\n const go = was ? Math.abs(alongOf(l, p) - alongOf(l, from)) : 0;\n const over = was && fromRaw ? Math.abs(acrossOf(l, raw) - acrossOf(l, fromRaw)) : 0;\n const inL = strictlyIn(l.rect, p);\n pathIn.set(l.id, inL ? (pathIn.get(l.id) ?? 0) + (slow ? go : 0) : 0);\n const s = slide.get(l.id);\n slide.set(l.id, inL ? { along: (s?.along ?? 0) + go, across: (s?.across ?? 0) + over } : { along: 0, across: 0 });\n if (l.owns && !inL) cameIn.add(l.id);\n }\n\n let region: LandingRegion;\n let pending: string | null = null;\n if (!inside(regions.stage, p)) {\n // Outside the stage: nowhere, and the lane is let go.\n region = \"nowhere\";\n laneId = spotId = null;\n } else {\n const held = laneIn(regions, laneId);\n const gate = (l: LandingLane): boolean => (pathIn.get(l.id) ?? 0) >= gates.path || (depthIn(l.rect, p, regions.stage) >= gates.depth && step <= gates.still);\n // Lane to lane: inside a lane touching the held one, past the held lane's exit margin (inside it the held lane holds,\n // P1), the held lane still holds until that lane's gate passes, then that lane takes it. Never the float between\n // them, never a fly-through's room.\n const touching = held ? regions.lanes.find((l) => l.id !== held.id && strictlyIn(l.rect, p) && touches(l.rect, held.rect) && !inside(held.rect, p, margins.exit)) : undefined;\n const sl = touching ? slide.get(touching.id) : undefined;\n const slid = !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along;\n // A lane that owns its rect (a rail drop strip) takes the pointer inside it from any lane it overlaps, a held one\n // too, once its own gate passes (so a pass across it opens nothing), and only once the pointer came into it (it has\n // been outside it since the lift): a press in a column's outer edge, or a slow reorder along it, stays in the column.\n // Never within `lift` of where the item was lifted: away and back there is home, wherever a strip lies, while the\n // rest of the strip (all of it over a lone panel's own place) still takes it.\n const nearLift = !!liftAt && Math.hypot(p.x - liftAt.x, p.y - liftAt.y) <= (margins.lift ?? 16);\n const owner = nearLift ? undefined : regions.lanes.find((l) => l.owns && l.id !== held?.id && cameIn.has(l.id) && strictlyIn(l.rect, p) && gate(l));\n const next = owner ?? (touching && (gate(touching) || slid) ? touching : undefined);\n if (held && !next && (touching || inside(held.rect, p, margins.exit))) {\n const s = along(held, p, step);\n spotId = s?.id ?? spotId;\n region = s ? \"lane\" : \"refused\";\n if (!s) spotId = null;\n } else {\n laneId = spotId = null;\n // Entering: a touching lane at once, else the path gate or the still gate; at a tie, the lane the pointer is\n // deeper in. Over a refused place (a lane's band over a column that takes nothing, an empty side rail's) a lane is\n // entered at once, never on the lift: there is nothing else the pointer can mean there, and nothing to fly\n // through to.\n // (Over something that takes nothing reaching past the lane, a column's panel under an empty rail's band, and in\n // no other lane; a drawn bar's own rect and its items lie within it, so its gate holds.)\n // Within the lift zone an owning lane is no lane at all: by no gate does it take the pointer there.\n const lanesHere = regions.lanes.filter((l) => strictlyIn(l.rect, p) && !(l.owns && nearLift));\n const within = (b: Rect, l: LandingLane): boolean => b.x >= l.rect.x - 1 && b.y >= l.rect.y - 1 && b.x + b.width <= l.rect.x + l.rect.width + 1 && b.y + b.height <= l.rect.y + l.rect.height + 1;\n // On a slow step only (as a slow hand inside a bar enters it): a fly-through across such a place opens no room.\n const overRefused = (l: LandingLane): boolean =>\n Number.isFinite(step) && step <= gates.step && lanesHere.length === 1 && [...regions.blocked, ...regions.refused].some((b) => strictlyIn(b, p) && !within(b, l));\n let entered: LandingLane | null = next ?? null;\n if (!entered)\n for (const l of lanesHere) {\n const deep = depthIn(l.rect, p, regions.stage);\n if ((gate(l) || overRefused(l)) && (!entered || deep > depthIn(entered.rect, p, regions.stage))) entered = l;\n }\n // Inside a lane not entered yet: no refused place to say so of, whatever lies under it.\n if (!entered && lanesHere.length > 0) pending = lanesHere.reduce((a, b) => (depthIn(b.rect, p, regions.stage) > depthIn(a.rect, p, regions.stage) ? b : a)).id;\n if (entered) {\n laneId = entered.id;\n const s = pick(entered, alongOf(entered, p));\n spotId = s?.id ?? null;\n region = s ? \"lane\" : \"refused\";\n } else if (regions.refused.some((r) => inside(r, p))) region = \"refused\";\n else if (inside(regions.content, p) && !regions.blocked.some((b) => strictlyIn(b, p))) region = \"open\";\n // Inside a lane not yet entered: what it was (on the way in, the document's float).\n else if (regions.lanes.some((l) => strictlyIn(l.rect, p))) region = previous === \"lane\" ? \"open\" : previous;\n else region = \"refused\";\n }\n }\n previous = region;\n const shown: LandingRegion = shift && (region === \"lane\" || region === \"open\") ? \"open\" : region;\n const r2 = heldRegions(spotId);\n const spot = spotIn(laneIn(r2, laneId), spotId);\n const landing = shown === \"lane\" ? (spot?.landing ?? null) : shown === \"open\" ? (options.floatLanding?.(p) ?? null) : null;\n frame = {\n region: shown,\n lane: laneId,\n spot: shown === \"lane\" ? spotId : null,\n landing,\n room: shown === \"lane\" && !!spot,\n guides: guidesFor(p, shown, shift),\n shift,\n ...(pending && shown !== \"lane\" ? { pending } : {}),\n };\n return frame;\n }\n\n return {\n update,\n release(): LandingRelease {\n if (frame.region === \"lane\" && frame.lane && frame.spot) return { kind: \"spot\", lane: frame.lane, spot: frame.spot, home: !!options.home && options.home.spot === frame.spot && options.home.lane === frame.lane };\n if (frame.region === \"open\" && frame.landing) return { kind: \"float\", rect: frame.landing };\n return null;\n },\n setRegions(regions: LandingRegions, nextRegionsFor?: (spot: string) => LandingRegions | null): void {\n base = regions;\n if (nextRegionsFor) regionsFor = nextRegionsFor;\n cache.clear();\n const l = laneIn(base, laneId);\n if (laneId && !l) laneId = spotId = null;\n else if (l && spotId && !spotIn(l, spotId) && last) spotId = pick(l, alongOf(l, last.p))?.id ?? null;\n },\n hide(): void {\n laneId = spotId = null;\n approached = null;\n pathIn.clear();\n slide.clear();\n cameIn.clear();\n last = moved = null;\n lastStep = 0;\n },\n get frame(): LandingFrame {\n return frame;\n },\n };\n}\n","import type { DragFrame, DragTarget } from \"./intent\";\n\n/**\n * How a drag previews its drop, from least to most motion while dragging:\n *\n * - `\"indicator\"`: nothing moves; only the indicator (an outline or an\n * insertion marker) shows the target.\n * - `\"gap\"`: once the room is made, the others move aside and open the slot;\n * the item stays under the pointer.\n * - `\"snap\"`: the gap opens and the item itself glides into it (for a target\n * with a slot; one without keeps the indicator).\n * - `\"item\"`: the dragged item is the only preview: no indicator for any\n * target. It sits in a slotted target once the room is open and otherwise\n * stays on the pointer. Pair it with the intent's `earlyRelease: \"float\"`, so\n * a release lands what shows.\n *\n * Every mode follows the same intent: what shows, when, and what a release\n * lands on are the drag intent's, so a drop always lands where the preview\n * showed it.\n */\nexport type DragPreview = \"indicator\" | \"gap\" | \"snap\" | \"item\";\n\n/** The preview a drag uses unless the host picks another. */\nexport const DRAG_PREVIEW_DEFAULT: DragPreview = \"snap\";\n\n/**\n * Place guides: faint marks on the free places that take the held item, shown only while no landing shows. `\"off\"`:\n * none; `\"near\"`: the places of the edge the pointer approaches; `\"all\"`: every place, from the lift.\n */\nexport type PlaceGuides = \"off\" | \"near\" | \"all\";\n\n/**\n * How a place guide draws an empty lane (an empty bar or side rail, its room not open yet): `\"real\"`, a box at the size\n * the lane will take, over what moves aside (the page, a column); `\"edge\"`, a thin striped strip on the lane's window\n * side. The landing is the same either way. Placement's `lanes()` takes it as `emptyLanes`.\n */\nexport type EmptyLanes = \"real\" | \"edge\";\n\n/**\n * A drop preview as a mode and its place guides, beside the string forms: `\"outline\"` is `\"indicator\"`'s plan,\n * `\"placeholder\"` is `\"gap\"`'s, and `\"snap\"` is `\"item\"`'s (the item the only preview). `placeGuides` defaults per mode\n * ({@link PLACE_GUIDES_DEFAULT}); `emptyLanes` (how its guides draw an empty lane) defaults to `\"real\"`.\n */\nexport type DropPreviewMode =\n | { readonly mode: \"outline\"; readonly placeGuides?: PlaceGuides; readonly emptyLanes?: EmptyLanes }\n | { readonly mode: \"placeholder\"; readonly placeGuides?: PlaceGuides; readonly emptyLanes?: EmptyLanes }\n | { readonly mode: \"snap\"; readonly placeGuides?: PlaceGuides; readonly emptyLanes?: EmptyLanes };\n\n/** Each mode's place guides when it names none: Snap and Placeholder near, Outline none. */\nexport const PLACE_GUIDES_DEFAULT: Readonly<Record<DropPreviewMode[\"mode\"], PlaceGuides>> = { outline: \"off\", placeholder: \"near\", snap: \"near\" };\n\n/** The string plan each mode draws with. */\nconst PLAN_OF: Readonly<Record<DropPreviewMode[\"mode\"], DragPreview>> = { outline: \"indicator\", placeholder: \"gap\", snap: \"item\" };\n\n/** What to draw for one frame of a drag. */\nexport interface PreviewPlan {\n /** Draw the indicator on the shown target. */\n readonly showIndicator: boolean;\n /** Lay the others out around the room (the gap is open). */\n readonly makeRoom: boolean;\n /** Draw the item in its slot instead of under the pointer. */\n readonly snapItem: boolean;\n /**\n * The place guides to draw this frame: the mode's `placeGuides` while no landing shows (no indicator, no room, no item\n * in its slot), `\"off\"` whenever one does, so the screen shows where the item can go or where it will land, never\n * both. Always `\"off\"` for the string forms. Optional, so a plan a host builds itself is still one: absent means\n * `\"off\"`.\n */\n readonly guides?: PlaceGuides;\n /** How the guides draw an empty lane (the object form's `emptyLanes`, `\"real\"` when it names none); absent for the string forms. */\n readonly emptyLanes?: EmptyLanes;\n}\n\n/**\n * The plan for a frame of the drag intent under `preview`. `slotted` says\n * whether the shown target's drop has a slot the item can sit in (default: a\n * target that isn't `free`); only such a target snaps, and in `\"snap\"` it\n * previews with the item rather than the indicator.\n *\n * - `\"indicator\"`: the indicator, never room, never a snap.\n * - `\"gap\"`: the indicator, and room when the intent makes it.\n * - `\"snap\"`: room when the intent makes it, the item snapped into a slotted\n * target's room; the indicator only for a target without a slot.\n * - `\"item\"`: as `\"snap\"`, with no indicator at all.\n *\n * The object form ({@link DropPreviewMode}) draws with its mode's string plan and adds its place guides (`guides`).\n */\nexport function previewPlan<T extends DragTarget>(\n frame: Pick<DragFrame<T>, \"shown\" | \"room\">,\n preview: DragPreview | DropPreviewMode,\n slotted: boolean = !!frame.shown && !frame.shown.free,\n): PreviewPlan {\n if (typeof preview === \"object\") {\n const plan = stringPlan(frame, PLAN_OF[preview.mode], slotted);\n const asked = preview.placeGuides ?? PLACE_GUIDES_DEFAULT[preview.mode];\n const landing = plan.showIndicator || plan.makeRoom || plan.snapItem;\n return { ...plan, guides: landing ? \"off\" : asked, emptyLanes: preview.emptyLanes ?? \"real\" };\n }\n return stringPlan(frame, preview, slotted);\n}\n\nfunction stringPlan<T extends DragTarget>(frame: Pick<DragFrame<T>, \"shown\" | \"room\">, preview: DragPreview, slotted: boolean): PreviewPlan {\n const shown = !!frame.shown;\n if (preview === \"indicator\") return { showIndicator: shown, makeRoom: false, snapItem: false, guides: \"off\" };\n if (preview === \"gap\") return { showIndicator: shown, makeRoom: frame.room, snapItem: false, guides: \"off\" };\n if (preview === \"item\") return { showIndicator: false, makeRoom: frame.room, snapItem: frame.room && shown && slotted, guides: \"off\" };\n // By design a slotted target draws nothing until the room opens (`roomAfter`); a release then still lands on it.\n return { showIndicator: shown && !slotted, makeRoom: frame.room, snapItem: frame.room && shown && slotted, guides: \"off\" };\n}\n","import { DOUBLE_CLICK, type DoubleClick } from \"../double-click\";\nimport type { Point } from \"../shapes\";\nimport { liftDecision, type DragTuning, type LiftDecision } from \"./intent\";\n\n/** How a press on a grip ended: a click, the second click of a double (`doubleActivate`, not a click), or a drag (`null`). */\nexport type GripRelease = \"click\" | \"doubleActivate\" | null;\n\n/** A press on a grip, start to end: whether it lifts, and what its release is. Pure: positions and times are the host's. */\nexport interface GripPress {\n /**\n * A press at `point`, `time` ms. `touch` for a finger (the touch lift rule). `clicks`, when the host has the\n * platform's count for this press (a `mousedown`'s `detail`, 1 or more), decides the double instead of the interval.\n */\n down(point: Point, time: number, options?: { readonly touch?: boolean; readonly clicks?: number }): void;\n /** The pointer moved: `liftDecision` for this press. Once `\"lift\"` it stays a drag; once `\"refuse\"` it never is. */\n move(point: Point, time: number): LiftDecision;\n /**\n * The press ended. `\"click\"`, or `\"doubleActivate\"` when it is the second click of a double (it is not a click\n * then); null when it lifted or was refused. A press that never moved past the lift distance never lifts, so an\n * unmoved double never starts a drag (a second press that moves past it is a drag like any other). A third click\n * after a double starts a new pair.\n */\n up(point: Point, time: number): GripRelease;\n /** Forget the press and the click before it (a cancelled press, a scroll). */\n cancel(): void;\n}\n\n/**\n * A grip's press, double-click included: a press that moves past the lift distance is a drag; one that doesn't is a\n * click, and a second such press within the double interval and distance is a double-activate (the host folds or\n * unfolds, say), never a second click and never a lift: an unmoved double never starts a drag.\n *\n * The first click of a double is delivered as `\"click\"` before the double is known (nothing waits for a second press),\n * so a host keeps a grip's click harmless (a use, a focus): the double-activate that follows must not have to undo it.\n */\nexport function createGripPress(options: { readonly tuning?: Partial<DragTuning>; readonly double?: Partial<DoubleClick> } = {}): GripPress {\n const tuning = options.tuning ?? {};\n // The package's one double click (`DOUBLE_CLICK`), unless the host tunes it.\n const dbl: DoubleClick = { ...DOUBLE_CLICK, ...options.double };\n let press: { at: Point; time: number; touch: boolean; double: boolean; state: LiftDecision } | null = null;\n // The last click (a press that ended as one): where and when it was pressed.\n let last: { at: Point; time: number } | null = null;\n return {\n down(point, time, o = {}) {\n const near = !!last && time - last.time <= dbl.ms && Math.hypot(point.x - last.at.x, point.y - last.at.y) <= dbl.px;\n const double = o.clicks !== undefined && o.clicks > 0 ? o.clicks === 2 : near;\n press = { at: { x: point.x, y: point.y }, time, touch: !!o.touch, double, state: \"wait\" };\n },\n move(point, time) {\n if (!press) return \"wait\";\n if (press.state !== \"wait\") return press.state;\n press.state = liftDecision({ touch: press.touch, distance: Math.hypot(point.x - press.at.x, point.y - press.at.y), elapsed: time - press.time }, tuning);\n return press.state;\n },\n up() {\n const p = press;\n press = null;\n if (!p || p.state !== \"wait\") {\n last = null;\n return null;\n }\n if (p.double) {\n last = null;\n return \"doubleActivate\";\n }\n last = { at: p.at, time: p.time };\n return \"click\";\n },\n cancel() {\n press = null;\n last = null;\n },\n };\n}\n"],"mappings":";;;;;AAoGO,IAAM,gBAA4B;AAAA,EACvC,MAAM;AAAA,EACN,WAAW;AAAA,EACX,WAAW;AAAA,EACX,aAAa;AAAA,EACb,UAAU;AAAA,EACV,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,cAAc;AAAA,EACd,WAAW;AAAA,EACX,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,WAAW;AAAA,EACX,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,WAAW,EAAE,IAAI,MAAM,UAAU,SAAS,SAAS,MAAM;AAC3D;AAEA,IAAM,YAAiE,EAAE,OAAO,SAAS,KAAK,OAAO,SAAS,QAAQ,MAAM,OAAO;AAEnI,IAAM,OAAO,CAAC,MAA4B,QACxC,CAAC,CAAC,SAAS,QAAQ,QAAQ,CAAC,EAAE,KAAK,QAAQ,KAAK,QAAQ,CAAC,CAAC,KAAK,UAAU,GAAG,CAAC;AAuExE,IAAM,eAAe;AAGrB,IAAM,WAAW,CAAC,MAAwD,EAAE,WAAW,OAAO,eAAe,EAAE;AAGtH,IAAM,SAAS,CAAC,QAA0B,UACxC,CAAC,UAAW,MAAM,IAAI,OAAO,KAAK,MAAM,IAAI,OAAO,IAAI,OAAO,SAAS,MAAM,IAAI,OAAO,KAAK,MAAM,IAAI,OAAO,IAAI,OAAO;AAGpH,SAAS,OAAO,MAAY,OAAc,SAAS,GAAY;AACpE,SAAO,MAAM,KAAK,KAAK,IAAI,UAAU,MAAM,KAAK,KAAK,IAAI,KAAK,QAAQ,UAAU,MAAM,KAAK,KAA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;AACP,cAAQ;AACR,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["held","distanceTo","held","l","within"]}
1
+ {"version":3,"sources":["../src/drag/intent.ts","../src/drag/landing.ts","../src/drag/preview.ts","../src/drag/grip.ts","../src/drag/guide-rects.ts"],"sourcesContent":["import type { Point, Rect } from \"../shapes\";\n\n/**\n * The drag intent model's tuning. Distances in px, speeds in px/ms, times in\n * ms; every value can be overridden per intent (see\n * {@link DragIntentOptions.tuning}).\n */\nexport interface DragTuning {\n /** A mouse press lifts once the pointer has moved this far. */\n readonly lift: number;\n /** A touch press lifts only after it has been held this long… */\n readonly touchHold: number;\n /** …and then moved this far (moving that far before the hold is over is not a drag). */\n readonly touchLift: number;\n /** The pointer's speed is measured over this window and smoothed. */\n readonly speedWindow: number;\n /** Aiming: the smoothed speed is below this… */\n readonly aimSpeed: number;\n /** …or the pointer has stayed within `still` px of one spot for `dwell` ms. */\n readonly still: number;\n readonly dwell: number;\n /** The current target holds while the pointer is within this band of its zone. */\n readonly band: number;\n /** A higher-priority target takes over at once when the pointer is this far inside it. */\n readonly breakthrough: number;\n /**\n * The band and the breakthrough scale with the zones: along each axis they are at most this share of the held\n * zone's extent and of the extent of the zone under the pointer (its `hit`), so a small zone (a 28 px row) can be\n * entered by a direct glide from its neighbor. Below a quarter, the pointer at a quarter of a zone is past them.\n */\n readonly bandShare: number;\n /** A gap between zones shorter than this keeps the current target (for a pointer that aims). */\n readonly gapGrace: number;\n /** Aiming, the shown target moves to another one only once that one has held this long. */\n readonly switchHold: number;\n /**\n * Room is made once the shown target, and the place in it, have held this long, so a pointer moving across targets\n * doesn't reflow the layout under it. A target with `opensRoom` holds this long before it shows, its room with it.\n */\n readonly roomAfter: number;\n /** The pointer has left the item's home once it is outside the home shrunk by this much on every side. */\n readonly homeInset: number;\n /**\n * Spring-loading: a target marked `arm: \"dwell\"` takes the drop only once the pointer has stayed in its zone this long\n * (ms); before that it is no target, so a fast pass, or a drop before it, lands on what lies beneath. 0 arms it at once.\n * Armed, its zone is its `armedHit` (the magnet: its band); moving out past that band's outer edge disarms it, and\n * re-entering needs a new full dwell. It arms only after the pointer has ENTERED its zone during the drag: the point\n * the drag starts at counts as not entered, so a drag that starts inside the zone (a panel's grip under the strip at\n * the window's edge) must leave it and come back before it can arm; entering from over home counts.\n */\n readonly railArmDwellMs: number;\n /**\n * The lift zone, a radius in px about the point the drag was lifted at ({@link DragIntentOptions.lift}, else the first\n * sample): no spring-loaded target arms by dwell inside it. Coming back to where you lifted and pausing is the\n * \"changed my mind\" gesture, so it commits nothing even where a strip lies over the grip (a flush drawer's grip at the\n * window's edge). 16 px is about a grip's size. Elsewhere, home under a strip included, arming works as before, and\n * the rail key forces the rail anywhere, the lift zone too.\n */\n readonly liftZone: number;\n /** The keys that win over geometry while held (see {@link DragModifiers}). */\n readonly modifiers: DragModifiers;\n}\n\n/**\n * A modifier key, by its `KeyboardEvent.key` name, or `\"Mod\"`: ⌘ (Meta) on macOS and Ctrl elsewhere. `\"Mod\"` counts\n * either key as held, so no platform detection is needed.\n */\nexport type ModifierKey = \"Shift\" | \"Alt\" | \"Control\" | \"Meta\" | \"Mod\";\n\n/** The modifier keys held on a sample (a pointer event's `shiftKey`, `altKey`, `ctrlKey`, `metaKey`). */\nexport interface DragKeys {\n readonly shift?: boolean;\n readonly alt?: boolean;\n readonly ctrl?: boolean;\n readonly meta?: boolean;\n}\n\n/**\n * Keys that win over geometry: while `floatKey` is held the drop floats (the `free` target) wherever the pointer is,\n * except over a refusal (the frame is refused) or outside the float's `bounds` (nothing);\n * while `railKey` is held it goes to the nearest target marked `arm` (a side's rail), without reaching it. `floatKey`\n * wins when both are held. `on: false` turns both off.\n */\nexport interface DragModifiers {\n readonly on: boolean;\n readonly floatKey: ModifierKey;\n readonly railKey: ModifierKey;\n}\n\n/**\n * The defaults: a mouse lifts after 5 px, a touch after a 180 ms hold and\n * 8 px; aiming is slower than 0.45 px/ms over 50 ms, or within 12 px for\n * 90 ms; a 10 px band and a 4 px breakthrough, each at most a fifth of the\n * zones' extents, and a 120 ms gap grace; a switch waits 150 ms (the shortest\n * an indicator may show); room after 160 ms. A spring-loaded target arms after\n * 200 ms of dwell (long enough that a pass at travelling speed never arms it,\n * short enough to feel like the platforms' spring-loading); Shift floats, ⌘/Ctrl\n * (`\"Mod\"`) goes to the nearest rail. Alt is left free: an app with a frozen\n * layout uses it to unfreeze temporarily, and a key should have one meaning.\n */\nexport const DRAG_DEFAULTS: DragTuning = {\n lift: 5,\n touchHold: 180,\n touchLift: 8,\n speedWindow: 50,\n aimSpeed: 0.45,\n still: 12,\n dwell: 90,\n band: 10,\n breakthrough: 4,\n bandShare: 0.2,\n gapGrace: 120,\n switchHold: 150,\n roomAfter: 160,\n homeInset: 6,\n railArmDwellMs: 200,\n liftZone: 16,\n modifiers: { on: true, floatKey: \"Shift\", railKey: \"Mod\" },\n};\n\nconst KEY_FIELD: Record<Exclude<ModifierKey, \"Mod\">, keyof DragKeys> = { Shift: \"shift\", Alt: \"alt\", Control: \"ctrl\", Meta: \"meta\" };\n/** Whether `key` is held in `keys` (`\"Mod\"`: ⌘ or Ctrl). */\nconst held = (keys: DragKeys | undefined, key: ModifierKey): boolean =>\n !!keys && (key === \"Mod\" ? !!(keys.meta || keys.ctrl) : !!keys[KEY_FIELD[key]]);\n\n/**\n * A drop target: plain data. `hit` is the zone the pointer can be in;\n * `priority` how precise it is (1 beats 2 beats 3; equal priorities go to the\n * smaller zone). `slot` is where the dragged item would land, `label` what to\n * call it; the model reads neither. A `free` target has no slot (the item\n * floats where it is dropped): no room is made for it. `hits`, when given, is\n * the whole zone as several rects (a zone that isn't one rect, `hit` the\n * largest of them): the pointer is in the zone when it is in any of them.\n *\n * `arm: \"dwell\"` makes it spring-loaded: it is no target until the pointer has\n * dwelt in its zone for `railArmDwellMs`; once armed its zone is `armedHit`\n * when given (a magnet: the zone grown), and leaving that disarms it.\n *\n * `refuse: true` makes it a refusal: a place that takes no drop (a host draws nothing over it, and at most says \"Can't\n * go here\" at the pointer). It takes part in\n * the pick under the pointer at {@link REFUSAL_RANK} (below every target of priority 1 or 2, whatever its own\n * `priority`, above priority 3), but it never becomes the current or the shown target, and a release over it lands\n * nowhere. Where the pick under the pointer is a refusal, no held target's band or gap grace keeps it: nothing shows,\n * and the frame's `refused` says which refusal it is.\n *\n * `bounds`, when given, is the drawn space the zone belongs to (a window's stage): the zone, its band and its gap grace\n * hold only points strictly inside it, so it is half-open toward the outside and a point on `bounds`' boundary or past\n * it is never in it. The window's boundary belongs only to the targets drawn against it: a refusal and a target over\n * the whole plane (the float) carry `bounds`, a gap or a slot doesn't. So a pointer a host clamps onto the window's\n * edge picks a gap whose hit reaches the edge, else nothing (a held target keeps its band), and never a refusal or the\n * float. The rule relies on the host clamping exactly onto the stage's edge (`x + width`, `y + height`): a host that\n * clamps to `width - 0.5` still picks inside the window, the float or a refusal there included.\n *\n * `opensRoom: true` marks a target whose indicator would lie over what its room moves (a side rail that pushes a column\n * aside). Showing it and making its room are then one decision: it shows only once it has held `roomAfter` ms, and the\n * frame that first shows it already has `room`. A sweep across it moves nothing, as for any target, and no frame draws\n * it over the column. Until it shows, a release still lands on it. An armed spring-loaded target has its room at once\n * too: its dwell was the decision. `roomHold` is how long this target holds before that decision, in ms, in place of\n * `roomAfter` (a rail or a new-column line against the window's edge, which a pointer rarely crosses on its way\n * elsewhere, can wait less). A\n * host that draws only a marker and doesn't use `previewPlan`'s room opens the room on\n * `frame.room && frame.shown?.opensRoom`.\n *\n * `roomHit`, with `opensRoom`, is where the target's room draws the item once it is open (its landing rect: an empty\n * rail or bar is entered over its drawn depth). While the target shows with its room open it holds in `hit ∪ roomHit`: wherever\n * the pointer is in `roomHit` and inside its `bounds` too. What lies there is drawn as the room, so a refusal or a\n * target of the same or a lower precision under it doesn't take over, and the frame isn't `refused` there. A more\n * precise target (a lower `priority`) still takes over once the pointer is past `breakthrough` into it, and a held key\n * still wins. Out of both the target is held as any other (its `hit` and band), so once it goes its zone is `hit` again.\n */\nexport interface DragTarget {\n readonly id: string;\n readonly priority: 1 | 2 | 3;\n readonly hit: Rect;\n readonly hits?: readonly Rect[];\n readonly slot?: Rect;\n readonly label?: string;\n readonly free?: boolean;\n readonly arm?: \"dwell\";\n readonly armedHit?: Rect;\n readonly refuse?: true;\n readonly bounds?: Rect;\n readonly opensRoom?: true;\n readonly roomHold?: number;\n readonly roomHit?: Rect;\n}\n\n/**\n * Where a refusal ranks in the pick ({@link targetAt}): an ordering rank, not a priority. Priorities stay the integers\n * 1, 2 and 3; a refusal's tier is `refuse: true`, and the pick orders it by this rank on the same scale: after every\n * target of priority 1 and 2 (a refusal and a real target where they meet or overlap: the target wins, so a gap keeps\n * its end), before priority 3 (the float: over drawn space that takes nothing, the refusal wins over floating).\n * Among refusals the smaller zone wins. `@n-uf/placement` exports the same value for its reference pick.\n */\nexport const REFUSAL_RANK = 2.5;\n\n/** A target's rank in the pick: its `priority`, a refusal's {@link REFUSAL_RANK}. Lower wins. */\nexport const pickRank = (t: Pick<DragTarget, \"priority\" | \"refuse\">): number => (t.refuse === true ? REFUSAL_RANK : t.priority);\n\n/** Whether `point` lies strictly inside `bounds` (none: everywhere). */\nconst within = (bounds: Rect | undefined, point: Point): boolean =>\n !bounds || (point.x > bounds.x && point.x < bounds.x + bounds.width && point.y > bounds.y && point.y < bounds.y + bounds.height);\n\n/** Whether `point` lies in `rect` grown by `margin` px on every side (shrunk, for a negative margin). */\nexport function inRect(rect: Rect, point: Point, margin = 0): boolean {\n return point.x >= rect.x - margin && point.x <= rect.x + rect.width + margin && point.y >= rect.y - margin && point.y <= rect.y + rect.height + margin;\n}\n\n/** How far `point` lies from `rect` (0 inside it). */\nconst distanceTo = (rect: Rect, point: Point): number =>\n Math.hypot(Math.max(rect.x - point.x, 0, point.x - (rect.x + rect.width)), Math.max(rect.y - point.y, 0, point.y - (rect.y + rect.height)));\n\n/** Whether `point` lies in a target's zone (`hits` when it has them, else `hit`), grown by `margin` px, and inside its `bounds`. */\nconst inZone = (t: DragTarget, point: Point, margin = 0): boolean => within(t.bounds, point) && (t.hits ? t.hits.some((r) => inRect(r, point, margin)) : inRect(t.hit, point, margin));\n\n/** A margin per axis: px grown (shrunk, when negative) left and right, and above and below. */\ninterface Margin {\n readonly x: number;\n readonly y: number;\n}\n/**\n * Whether `point` lies in a target's zone grown by `m.x` px left and right and `m.y` px above and below, and inside its\n * `bounds`: a band never reaches past a zone's bounds (the float's band holds nothing outside the window).\n */\nconst inZoneBy = (t: DragTarget, point: Point, m: Margin): boolean =>\n within(t.bounds, point) && (t.hits ?? [t.hit]).some((r) => point.x >= r.x - m.x && point.x <= r.x + r.width + m.x && point.y >= r.y - m.y && point.y <= r.y + r.height + m.y);\n/** `px`, but along each axis at most `share` of each zone's extent (its `hit`) along it. */\nconst scaled = (px: number, share: number, zones: readonly (DragTarget | null)[]): Margin => {\n let x = px;\n let y = px;\n for (const z of zones) {\n if (!z) continue;\n x = Math.min(x, share * z.hit.width);\n y = Math.min(y, share * z.hit.height);\n }\n return { x, y };\n};\nconst negate = (m: Margin): Margin => ({ x: -m.x, y: -m.y });\n\nconst area = (r: Rect): number => r.width * r.height;\n/** A target's zone's area: its `hits` together, else its `hit`. */\nconst zoneArea = (t: DragTarget): number => (t.hits ? t.hits.reduce((s, r) => s + area(r), 0) : area(t.hit));\n\n/**\n * The most precise target under `point`: the lowest rank ({@link pickRank}: the priority, a refusal's\n * {@link REFUSAL_RANK}), then the smallest zone; null when none is. A zone holds its edges (a closed rect), except\n * toward the outside of its `bounds`.\n */\nexport function targetAt<T extends DragTarget>(targets: readonly T[], point: Point): T | null {\n let best: T | null = null;\n for (const t of targets) {\n if (!inZone(t, point)) continue;\n if (!best || pickRank(t) < pickRank(best) || (pickRank(t) === pickRank(best) && zoneArea(t) < zoneArea(best))) best = t;\n }\n return best;\n}\n\n/** What a press does so far: not yet a drag (`wait`), a drag (`lift`), or never one (`refuse`: a touch that moved too soon). */\nexport type LiftDecision = \"wait\" | \"lift\" | \"refuse\";\n\n/**\n * The lift rule for a press that has moved `distance` px in `elapsed` ms. A\n * mouse (or pen) lifts at `lift` px. A touch lifts only after `touchHold` ms,\n * then at `touchLift` px; moving `touchLift` px before the hold is over\n * refuses the drag (the finger is scrolling or swiping).\n */\nexport function liftDecision(press: { readonly touch: boolean; readonly distance: number; readonly elapsed: number }, tuning: Partial<DragTuning> = {}): LiftDecision {\n const t = { ...DRAG_DEFAULTS, ...tuning };\n if (!press.touch) return press.distance >= t.lift ? \"lift\" : \"wait\";\n if (press.elapsed < t.touchHold) return press.distance >= t.touchLift ? \"refuse\" : \"wait\";\n return press.distance >= t.touchLift ? \"lift\" : \"wait\";\n}\n\n/** One update's answer. */\nexport interface DragFrame<T extends DragTarget> {\n /** The target the drop indicator shows, or null. */\n readonly shown: T | null;\n /**\n * The others make room for the shown target: it, and the place in it, have held `roomAfter` ms. For a target with\n * `opensRoom`, or an armed spring-loaded one, from the first frame that shows it.\n */\n readonly room: boolean;\n /**\n * The place the room is made for, or null. Within one target it stays on\n * the old place until a new one has held `roomAfter` ms (see\n * {@link DragIntentOptions.placeOf}).\n */\n readonly roomPlace: string | null;\n /** The pointer is aiming: slow, or nearly still for a moment. */\n readonly aiming: boolean;\n /**\n * The pointer is back inside `home` after it has been outside `home` itself. Never true at the press, nor while the\n * pointer only moves about inside `home`, even near its edge (where `state.leftHome` is already true: that flag is for\n * the indicator's gate and uses `homeInset`; this one does not). Over home no target is shown and a release does\n * nothing, so a host that wants to say \"a drop here returns it\" draws its own indicator for this frame (at the home\n * rect); the intent still shows no target.\n *\n * A docked item's home holds wherever it lies. The home of a floating item (`DragIntentOptions.floating`) is a free\n * placement, ranked like the float: it holds only where the pick there, home ignored, is no refusal and the point is\n * inside the window. Where it doesn't hold this is false and the pick is as anywhere else: over a refusal\n * `refused` says so, and a release lands nowhere.\n */\n readonly atHome: boolean;\n /**\n * A spring-loaded target (`arm: \"dwell\"`) the pointer is in and dwelling on, not armed yet (a host highlights it), or\n * null. Once it arms it is a target like any other and may show.\n */\n readonly arming: T | null;\n /**\n * A key held wins over geometry this frame: `\"float\"` (the float key) or `\"rail\"` (the rail key), else null. The\n * float key chooses the float over dock targets, not over a refusal or outside the window: there it is still\n * `\"float\"` (the key is held), but nothing shows, a release lands nowhere, and over a refusal `refused` says which.\n */\n readonly forced: \"float\" | \"rail\" | null;\n /**\n * The refusal (a target with `refuse: true`) the pointer is over, when it is the pick there: no target shows. A host\n * never draws the refused place; it may say \"Can't go here\" at the pointer. Null otherwise, and while a key forces a target; with the float key\n * held over a refusal it is that refusal (the key doesn't float over refused space).\n */\n readonly refused: T | null;\n /**\n * No target shows, and the pointer has been over a refusal since a target last showed (or since the lift). A refusal\n * hides the shown target at once, and the next one shows only once the pointer aims again, so a pointer that crosses\n * a refusal and is let go at speed over a target beyond it has no indicator drawn. Then this is true, and a release\n * still lands on what is under the pointer (`release`): a host that commits only what it has drawn commits that\n * release too. False whenever a target shows, over the refusal itself (`refused`), and after `hide`.\n *\n * Read it from the frame of an `update` at the release point, called before `release` (as `release` asks anyway), so\n * the last move counts. The field is required: a host or a test mock that builds a `DragFrame` itself must set it.\n */\n readonly refusedSinceShown: boolean;\n /**\n * What a release at this frame's point lands on, by the one check `release` makes (`earlyRelease` included), or null\n * (nowhere, or the item goes home). A host draws the landing from it, so what it draws and what a release lands on\n * never disagree. `createDragIntent` always sets it; it is optional only so a host or a test that builds a frame\n * itself needn't.\n */\n readonly landing?: T | null;\n}\n\n/** What a drag intent knows now. */\nexport interface DragIntentState<T extends DragTarget> {\n /** The pointer's smoothed speed, px/ms. */\n readonly speed: number;\n /** The target under the pointer as the hysteresis holds it, or null. */\n readonly current: T | null;\n /** The target the indicator shows, or null. */\n readonly shown: T | null;\n /** The pointer has left the item's home. */\n readonly leftHome: boolean;\n}\n\nexport interface DragIntentOptions<T extends DragTarget> {\n /** Where the item was lifted from: the indicator stays off until the pointer leaves it, and a release there does nothing. */\n readonly home: Rect;\n /** Where the press that lifted the item was (the grip); default the first sample's point. The lift zone is about it. */\n readonly lift?: Point;\n /**\n * The lift zone as a rect instead of a radius, in the same px as the samples: while a sample is inside it no\n * spring-loaded target arms by dwell, and the `liftZone` radius is not applied. A host passes the part of the grip\n * that a drop strip covers (grip ∩ strip), so a pause back there commits nothing while the rest of the strip, right\n * beside a wide grip, still arms. Absent: the `liftZone` radius about `lift`.\n */\n readonly liftRect?: Rect;\n /**\n * The held item floats, and `home` is its own box. A floating item's own place is a free placement: it ranks like the\n * float target, so home holds only where the pick there, home ignored, is no refusal and the point lies inside the\n * window (no target's `bounds` left with nothing picked). Over a refusal in its box the frame is refused and a\n * release lands nowhere; on or past the window's edge nothing is picked; elsewhere in its box home holds as before.\n * Absent (a docked item): home holds wherever it lies, as its own home target beats a refusal.\n */\n readonly floating?: boolean;\n /**\n * What a release does before the item has settled on a target (no room open for it yet). `\"target\"` (the default): it\n * lands on the shown target, else the target under the pointer, drawn or not, an `opensRoom` target that hasn't shown\n * included. `\"float\"`: what shows is what lands, for a host whose dragged item is the only preview (`previewPlan`'s\n * `\"item\"`): the item is still on the pointer, so it floats there (the `free` target; over a refusal or outside the\n * float's `bounds`, nowhere). `release` is its one reader.\n */\n readonly earlyRelease?: \"target\" | \"float\";\n /** Overrides of {@link DRAG_DEFAULTS}. */\n readonly tuning?: Partial<DragTuning>;\n /**\n * The place within a target the pointer is at (a tab index, a stack\n * position, a pane's edge), unique across targets; default: the target's id.\n * Moving between places of the shown target moves the indicator at once but\n * the room only once the new place has held `roomAfter` ms.\n *\n * - `previous` is the place this target had on the last sample (null if it\n * had none), so a place can hold near its boundary (hysteresis).\n * - A null place is no target: there is no drop at that point of the target.\n * It isn't picked or held, the indicator hides there at once (or shows a\n * target beneath that has a place), no room opens, and a release there\n * lands on a target beneath, else goes home.\n * - It is also asked about the current target while the pointer is just\n * outside its hit zone (within the band, or during the gap grace). Answer\n * the nearest place there: returning null outside the zone drops the band\n * and the grace, so the indicator hides a few px past the edge. Return null\n * only for a part of the target that takes no drop.\n * - It is called on every sample for each target under the pointer and for\n * the current one, so keep it cheap and free of side effects.\n */\n readonly placeOf?: (target: T, point: Point, previous: string | null) => string | null;\n}\n\n/** A drag's intent: feed it the pointer on every frame; it says what the indicator shows and what a release lands on. */\nexport interface DragIntent<T extends DragTarget> {\n /**\n * A pointer sample at `time` (ms), with the targets as they stand (they may\n * be rebuilt between calls: the model follows them by id). Call it once a\n * frame while the item is held, also when the pointer doesn't move: a\n * dwell is time passing. `keys`: the modifier keys held now (see {@link DragModifiers}).\n */\n update(point: Point, time: number, targets: readonly T[], keys?: DragKeys): DragFrame<T>;\n /**\n * What a release at `point` lands on: the shown target whenever one shows\n * (a drop lands where the indicator was), else the target under the\n * pointer, else null (the item goes home). A release over home is null: it\n * does nothing. Feed the release point to `update` first, so a last jump\n * of the pointer counts. With a modifier key held (`keys`), the target the key picks, even over home.\n */\n release(point: Point, targets: readonly T[], keys?: DragKeys): T | null;\n /**\n * Hide the indicator (the view is scrolling under the pointer, say). The\n * aim starts afresh: the next sample never counts as aiming, and a dwell\n * starts again.\n */\n hide(time: number): void;\n /** The item's home moved with the view (it scrolled) by (dx, dy). */\n moveHome(dx: number, dy: number): void;\n readonly state: DragIntentState<T>;\n readonly tuning: DragTuning;\n}\n\n/**\n * The drag intent model: when the drop indicator shows, which target it\n * shows, when the others make room, and what a release lands on. Pure: fed\n * pointer samples and plain-data targets, no DOM and no clock of its own.\n *\n * - The indicator shows only when the pointer has left the item's home, a\n * target is under it, and it is aiming (slow, or nearly still for a\n * moment). Time spent crossing a big target at speed doesn't count.\n * - The most precise target wins (priority, then the smaller zone).\n * - Hysteresis: the current target holds while the pointer is within `band`\n * px of its zone, unless a more precise one is clearly (`breakthrough` px)\n * under the pointer; both scale down for small zones (`bandShare` of the\n * held zone's and the entered zone's extents along each axis), so a small\n * zone is entered by a direct glide; for a pointer that aims, a short gap between zones\n * (`gapGrace` ms) keeps it too.\n * - Leaving the shown target: flying, the indicator hides at once; aiming, it\n * moves to the new target once that has held `switchHold` ms (so no\n * indicator shows for less than that), at once for a breakthrough. A target\n * kept only by the gap grace can keep the indicator, never show it.\n * - Room is made once the shown target has held `roomAfter` ms, never for a\n * free target, and closes at once when it changes. A target with `opensRoom`\n * holds that long before it shows and has its room in the same frame; an\n * armed spring-loaded target has its room as it shows. With its room open,\n * one with a `roomHit` holds wherever the pointer is in that room, over a\n * refusal or a target no more precise than it under the room included.\n * - Where `placeOf` gives a target no place (null), it is no target: it is\n * neither shown nor landed on there.\n * - Spring-loading: a target marked `arm: \"dwell\"` is no target until the\n * pointer has stayed in its zone `railArmDwellMs` (the frame's `arming` says\n * which one it dwells on); then it is armed: its zone is `armedHit` (the\n * magnet) and it shows at once. Leaving that zone disarms it.\n * - Keys win over geometry (`modifiers`): the float key shows the `free` target\n * wherever the pointer is over a dock target or open space inside the float's\n * `bounds`, the rail key the nearest target marked `arm`; a release with the\n * key held lands there. Over a refusal, or outside the float's `bounds`, the\n * float key picks nothing: nothing shows and a release lands nowhere.\n */\nexport function createDragIntent<T extends DragTarget>(options: DragIntentOptions<T>): DragIntent<T> {\n const tuning: DragTuning = { ...DRAG_DEFAULTS, ...options.tuning };\n const placeOf = options.placeOf ?? ((t: T) => t.id);\n // Each target's place on the last sample, by id: its `previous` on the next.\n let lastPlaces = new Map<string, string | null>();\n let home: Rect = { ...options.home };\n let samples: { x: number; y: number; t: number }[] = [];\n let cur: T | null = null;\n let curSince = 0;\n let lastInside = 0;\n let shown: T | null = null;\n let shownSince = 0;\n let place: string | null = null;\n let placeSince = 0;\n let roomPlace: string | null = null;\n let leftHome = false;\n // The pointer has been outside `home` itself (`leftHome` turns on already near its edge): `atHome`'s own memory.\n let wentOut = false;\n let speed = 0;\n let anchor: Point | null = null;\n let stillSince = 0;\n let restart = false;\n // The pointer has been over a refusal since a target last showed (the frame's `refusedSinceShown`).\n let crossedRefusal = false;\n // Spring-loading: the target armed (by id), and the one the pointer dwells on and since when.\n let armedId: string | null = null;\n let armingId: string | null = null;\n let armingSince = 0;\n // The spring-loaded targets (by id) the pointer has been outside of during this drag: only those can arm.\n const wasOutside = new Set<string>();\n // The point the drag was lifted at: no spring-loaded target arms by dwell within `liftZone` of it.\n let liftAt: Point | null = options.lift ? { ...options.lift } : null;\n const same =(a: T | null, b: T | null): boolean => (a === null || b === null ? a === b : a.id === b.id);\n // Targets may be rebuilt between calls: follow the ones held by id.\n const follow = (t: T | null, targets: readonly T[]): T | null => (t ? (targets.find((x) => x.id === t.id) ?? t) : null);\n /** An armed target as it acts: its zone is `armedHit` (the magnet) when it has one. */\n const asArmed = (x: T): T => {\n if (!x.armedHit) return x;\n const { hits: _pieces, ...rest } = x;\n return { ...rest, hit: x.armedHit } as T;\n };\n /** The targets as they act now: a spring-loaded one only once armed, in its armed zone. */\n const acting = (targets: readonly T[]): T[] => targets.filter((x) => x.arm !== \"dwell\" || x.id === armedId).map((x) => (x.id === armedId ? asArmed(x) : x));\n /**\n * The target a held key picks at `p`: the float key the `free` target, the rail key the nearest spring-loaded one.\n * The float key chooses the float over dock targets, not over refusals or outside the window: where the pick at `p`\n * (`has`: a target with a place there, or a refusal) is a refusal, it picks nothing and says which refusal; outside\n * the float's `bounds` (a pointer clamped onto the window's edge) it picks nothing. The rail key's drop lands on the\n * rail, not where the pointer is, so neither applies to it.\n */\n const forcedBy = (keys: DragKeys | undefined, p: Point, targets: readonly T[], has: (x: T) => boolean): { kind: \"float\" | \"rail\"; target: T | null; refused: T | null } | null => {\n const m = tuning.modifiers;\n if (!m.on || !keys) return null;\n if (held(keys, m.floatKey)) {\n const f = targets.find((x) => x.free);\n if (!f) return null;\n const under = targetAt(acting(targets).filter((x) => inZone(x, p) && has(x)), p);\n if (under?.refuse === true) return { kind: \"float\", target: null, refused: under };\n return within(f.bounds, p) ? { kind: \"float\", target: f, refused: null } : { kind: \"float\", target: null, refused: null };\n }\n if (!held(keys, m.railKey)) return null;\n let best: T | null = null;\n let bestD = Infinity;\n for (const x of targets) {\n if (x.arm !== \"dwell\") continue;\n const d = distanceTo(asArmed(x).hit, p);\n if (d < bestD) {\n best = x;\n bestD = d;\n }\n }\n return best ? { kind: \"rail\", target: asArmed(best), refused: null } : null;\n };\n\n /** What a release at `point` lands on, as things stand now: `release`'s answer, and every frame's `landing`. */\n const landAt = (point: Point, given: readonly T[], keys: DragKeys | undefined): T | null => {\n // A key held wins over geometry, home included; the float key over a refusal or outside the window lands nowhere.\n const forced = forcedBy(keys, point, given, (x) => x.refuse === true || placeOf(x, point, lastPlaces.get(x.id) ?? null) !== null);\n if (forced) {\n const ft = forced.target;\n return ft ? (given.find((x) => x.id === ft.id) ?? ft) : null;\n }\n // Over home a release does nothing, except onto an armed spring-loaded target whose zone overlaps home.\n if (inRect(home, point)) {\n const armed = armedId === null ? null : given.find((x) => x.id === armedId);\n return armed && inZone(asArmed(armed), point) && placeOf(armed, point, lastPlaces.get(armed.id) ?? null) !== null ? armed : null;\n }\n const targets = acting(given);\n // Drop = shown: a shown target is kept until it hides (flying out past its band hides it at once).\n const s = shown && !(shown.arm === \"dwell\" && shown.id !== armedId) ? follow(shown, given) : null;\n // The target under the pointer that has a place there (a null place is no drop); a refusal there lands nowhere.\n const under = targetAt(\n targets.filter((x) => inZone(x, point) && (x.refuse === true || placeOf(x, point, lastPlaces.get(x.id) ?? null) !== null)),\n point,\n );\n if (options.earlyRelease === \"float\") {\n // What shows is what lands: a target with a slot only once its room is open; before that the item is still on\n // the pointer, so it floats there. A target with no slot (the item's own place, a blocked one) needs no room.\n const needsNoRoom = (x: T): boolean => x.free === true || !x.slot;\n if (s && (needsNoRoom(s) || roomPlace !== null)) return s;\n if (under?.refuse) return null;\n if (under && !under.free && !under.slot) return given.find((x) => x.id === under.id) ?? under;\n const float = given.find((x) => x.free);\n return float && within(float.bounds, point) ? float : null;\n }\n if (s) return s;\n return under && !under.refuse ? (given.find((x) => x.id === under.id) ?? under) : null;\n };\n\n return {\n tuning,\n get state(): DragIntentState<T> {\n return { speed, current: cur, shown, leftHome };\n },\n update(point, time, given, keys) {\n const p = point;\n const t = time;\n samples.push({ x: p.x, y: p.y, t });\n while (samples.length > 2 && t - samples[0]!.t > tuning.speedWindow) samples.shift();\n const a = samples[0]!;\n speed = speed * 0.5 + (Math.hypot(p.x - a.x, p.y - a.y) / Math.max(1, t - a.t)) * 0.5;\n if (!anchor || Math.hypot(p.x - anchor.x, p.y - anchor.y) > tuning.still) {\n anchor = { x: p.x, y: p.y };\n stillSince = t;\n }\n if (!inRect(home, p, -tuning.homeInset)) leftHome = true;\n const atHome = inRect(home, p);\n if (!atHome) wentOut = true;\n // Each target's place at this point, worked out once per sample; a null place is no target.\n const places = new Map<string, string | null>();\n const placeAt = (x: T): string | null => {\n if (!places.has(x.id)) places.set(x.id, placeOf(x, p, lastPlaces.get(x.id) ?? null));\n return places.get(x.id)!;\n };\n const live = (x: T | null): x is T => x !== null && placeAt(x) !== null;\n // Spring-loading: the armed target holds while the pointer is in its armed zone; a target the pointer dwells in\n // arms once it has held `railArmDwellMs`. A key held wins over both.\n const forced = forcedBy(keys, p, given, (x) => x.refuse === true || live(x));\n if (armedId !== null) {\n const was = given.find((x) => x.id === armedId);\n if (!was || forced || !inZone(asArmed(was), p) || !live(was)) armedId = null;\n }\n // Spring-loading is not gated by `atHome`: a strip that overlaps the item's own place still arms by dwell.\n // A spring-loaded target arms only after the pointer has entered it: one it has been outside of during the drag.\n for (const x of given) if (x.arm === \"dwell\" && !inZone(x, p)) wasOutside.add(x.id);\n // Inside the lift zone nothing arms by dwell (\"changed my mind\"); the rail key still forces the rail.\n // With a `liftRect` the zone is that rect, the radius not applied.\n liftAt ??= { x: p.x, y: p.y };\n const inLiftZone = options.liftRect ? inRect(options.liftRect, p) : Math.hypot(p.x - liftAt.x, p.y - liftAt.y) <= tuning.liftZone;\n const dwelling = forced || inLiftZone ? null : targetAt(given.filter((x) => x.arm === \"dwell\" && x.id !== armedId && wasOutside.has(x.id) && inZone(x, p) && live(x)), p);\n let armedNow = false;\n if (!dwelling || armedId !== null) armingId = null;\n else {\n if (armingId !== dwelling.id) {\n armingId = dwelling.id;\n armingSince = t;\n }\n if (t - armingSince >= tuning.railArmDwellMs) {\n armedId = dwelling.id;\n armingId = null;\n armedNow = true;\n }\n }\n const arming = armingId === null ? null : (given.find((x) => x.id === armingId) ?? null);\n const targets = acting(given);\n // A docked item's home holds wherever it lies (its own home target beats a refusal). A floating item's own place\n // is a free placement, ranked like the float: its home holds only where the pick there, home ignored, is no\n // refusal and not nothing outside a target's `bounds` (past the window). Elsewhere the pick is as anywhere else.\n const underHome = atHome && options.floating ? targetAt(targets.filter((x) => inZone(x, p) && (x.refuse === true || live(x))), p) : null;\n const pastBounds = atHome && options.floating ? targets.some((x) => x.bounds !== undefined && !within(x.bounds, p)) : false;\n const homeHolds = atHome && (!options.floating || (underHome?.refuse !== true && !(underHome === null && pastBounds)));\n // Over home no target is picked, except a spring-loaded one that is armed (its zone overlaps home): home gates\n // geometry, not an armed dwell.\n const pickable = (x: T): boolean => !homeHolds || (x.arm === \"dwell\" && x.id === armedId);\n // A refusal takes part in the pick (it needs no place), but it is never a target: never held, never shown.\n const raw = targetAt(targets.filter((x) => pickable(x) && inZone(x, p) && (x.refuse === true || live(x))), p);\n // A spring-loaded target that isn't armed (any more) is no target: neither held nor shown.\n const disarmed = (x: T | null): boolean => x?.arm === \"dwell\" && x.id !== armedId;\n cur = disarmed(cur) ? null : follow(cur, targets);\n shown = disarmed(shown) ? null : follow(shown, targets);\n if (!live(cur)) cur = null;\n // A target shown with its room open holds in the room it opened (`roomHit`): what lies there is drawn as the room,\n // so a refusal under it is no refusal here.\n const roomHeld = cur && cur.opensRoom === true && cur.roomHit && roomPlace !== null && same(cur, shown) && pickable(cur) && within(cur.bounds, p) && inRect(cur.roomHit, p) ? cur : null;\n const refusedRaw = raw?.refuse === true && !roomHeld ? raw : null;\n // The band about a held zone, and the breakthrough into a zone, scaled with the zones (see `bandShare`).\n const bandOf = (held: T): Margin => scaled(tuning.band, tuning.bandShare, [held, raw && !same(raw, held) ? raw : null]);\n const pastBreakthrough = (x: T): boolean => inZoneBy(x, p, negate(scaled(tuning.breakthrough, tuning.bandShare, [x])));\n // Over a refusal nothing is held: no band and no gap grace keep the current target there.\n let next = refusedRaw ? null : raw;\n if (!refusedRaw && cur && pickable(cur) && (roomHeld !== null || inZoneBy(cur, p, bandOf(cur)))) {\n // Over a `free` target (the float everywhere) there is no edge to hold against: a more precise target takes over\n // once the pointer is in it, so a zone that ends at the window's edge is reached at its very first px. A refusal\n // here lies under the open room: it never takes over.\n const breaks = raw !== null && raw.refuse !== true && !same(raw, cur) && raw.priority < cur.priority && (cur.free === true || pastBreakthrough(raw));\n next = breaks ? raw : cur;\n }\n // The gap grace, like the band, never reaches past a zone's bounds: the float gets no grace outside the window.\n if (!refusedRaw && !next && cur && pickable(cur) && within(cur.bounds, p) && t - lastInside < tuning.gapGrace) next = cur;\n if (next && (inZone(next, p) || same(next, roomHeld))) lastInside = t;\n if (!same(next, cur)) curSince = t;\n cur = next;\n const aiming = !restart && (speed < tuning.aimSpeed || t - stillSince >= tuning.dwell);\n restart = false;\n const show = (s: T | null): void => {\n if (!same(s, shown)) shownSince = t;\n shown = s;\n };\n // Under the pointer (within its band, or in the room it holds), not just kept by the gap grace.\n const under = !!cur && (same(cur, roomHeld) || inZoneBy(cur, p, bandOf(cur)));\n // A target that opens its room as it shows shows only once it has held (`roomHold`, else `roomAfter`): one decision\n // for both, so a sweep moves nothing and the indicator never lies over what the room will move. An armed one has\n // had its dwell.\n const ready = (x: T): boolean => x.opensRoom !== true || x.arm === \"dwell\" || t - curSince >= (x.roomHold ?? tuning.roomAfter);\n // A shown target with no place here is no drop: the indicator hides at once (the switch hold is for targets).\n if (shown && !live(shown)) show(null);\n if (!shown) {\n if (cur && under && leftHome && aiming && ready(cur)) show(cur);\n } else if (same(cur, shown)) {\n // It stays while its target holds; but a pointer flying out past the band hides it at once.\n if (!aiming && !under) show(null);\n else shown = cur;\n } else if (!cur || !aiming) {\n show(null);\n } else if ((cur.priority < shown.priority && (shown.free === true || pastBreakthrough(cur))) || (under && t - curSince >= tuning.switchHold)) {\n // Not ready yet: the old indicator goes, and a release lands on the target under the pointer.\n show(ready(cur) ? cur : null);\n }\n // An armed target shows at once: the dwell was the aim. A key held wins over all of it.\n if (armedNow && cur?.id === armedId && under) show(cur);\n // A key that picks nothing here (the float key over a refusal or outside the window) shows nothing.\n if (forced) {\n if (!same(forced.target, cur)) curSince = t;\n cur = forced.target;\n show(forced.target);\n }\n // The place within the shown target, and the room: after the target and the place have both held; with the target\n // itself where showing it was already that decision (`opensRoom`, an armed target's dwell).\n const at = shown ? placeAt(shown) : null;\n if (at !== place) {\n place = at;\n placeSince = t;\n }\n if (!shown || shown.free) roomPlace = null;\n else if (shown.opensRoom === true || shown.arm === \"dwell\") roomPlace = place;\n else if (t - shownSince >= tuning.roomAfter && t - placeSince >= tuning.roomAfter) roomPlace = place;\n else if (shownSince === t) roomPlace = null;\n lastPlaces = places;\n // A refusal crossed since a target last showed: a release beyond it lands on what is under the pointer, drawn or not.\n // With a key held, the refusal is the one the key's pick met (the float key over a refusal), else none.\n const refused = forced ? forced.refused : refusedRaw;\n if (shown) crossedRefusal = false;\n else if (refused) crossedRefusal = true;\n return { shown, room: roomPlace !== null, roomPlace, aiming, atHome: !forced && wentOut && homeHolds, arming, forced: forced?.kind ?? null, refused, refusedSinceShown: !shown && !refused && crossedRefusal, landing: landAt(p, given, keys) };\n },\n release(point, given, keys) {\n return landAt(point, given, keys);\n },\n hide(time) {\n shown = null;\n cur = null;\n armedId = null;\n armingId = null;\n shownSince = time;\n place = null;\n roomPlace = null;\n lastPlaces = new Map();\n samples = [];\n anchor = null;\n restart = true;\n crossedRefusal = false;\n },\n moveHome(dx, dy) {\n home = { ...home, x: home.x + dx, y: home.y + dy };\n },\n };\n}\n","import type { Point, Rect } from \"../shapes\";\nimport type { DragKeys } from \"./intent\";\nimport type { PlaceGuides } from \"./preview\";\n\n/**\n * The landing model: where a docking drag's item lands, as state rather than a per-frame guess. A host gives it the\n * drag's regions (from `@n-uf/placement/scene`'s `lanes()`: plain data, the shapes below) and each pointer sample; it\n * says the region the pointer is in, the lane and spot held, where the item lands, whether the room is open, and the\n * place guides. Every change comes from where the pointer is and how it moved (margins, a path length, a step size):\n * the model has no waits of its own.\n *\n * - **The stage's edge** is the easiest place to dock: a pointer past the stage by up to `edge` px counts as on its\n * edge, so it lies deep inside a lane drawn against that edge; beyond, it is nowhere.\n * - **A lane holds** while the pointer is inside its rect grown by `exit`, whatever lies under it. Inside, over a spot's\n * stretch it is at that spot; over a refused stretch of the lane, refused (\"Can't go here\"). (Placement's `lanes()`\n * joins a refused stretch shorter than the item to its spots.)\n * - **Entering a lane** needs one of two gates: `path` px of slow pointer path along it inside it (steps of at most\n * `step`), or a still step (at most `still`) once `depth` px inside, the depth counted only from the lane's sides that\n * face into the stage (on the edge it is deep). A fly-through of a thin bar or rail at any angle meets neither, so its\n * room never opens. Inside a lane that touches the held one, past the held lane's exit margin, the held lane holds\n * until that lane's gate passes or the pointer has slid `path` px along it at any speed (across it at most a third as\n * far): lane to lane never passes through the float, and never opens a crossed lane's room. Over a refused place (a\n * lane's band lying over a column that takes nothing: an empty side rail's) a lane is entered on the first slow step\n * there (not on the lift), as there is nothing else to mean there; a fly-through still opens no room. A lane that owns\n * its rect (`owns`: a rail drop strip at the window's side) takes the pointer inside it from any lane it overlaps, a\n * held one too, once its own gate passes and only once the pointer came into it from outside since the lift. Within\n * `margins.lift` of the lift point (`options.lift`, else the first point; fixed for the drag) an owning lane takes the\n * pointer by no gate, so a pointer brought back there is in the item's own lane, not the strip. Elsewhere in the strip\n * a slow slide along it can take the pointer before it is back at the lift point.\n * - **Along a lane** the spot changes once the pointer is `spot` px past the boundary; where the change moves another\n * item (the two spots' `others` keys differ), on a step of at most `step`, or once the held landing trails the\n * pointer by more than `trail`: the item chases only as far as it must. A change that moves only the held item\n * follows the hand at any speed. With `regionsFor`, a reflowing change is kept only if, in the new spot's own regions\n * (its room open), the pointer still lies in that spot's stretch: the room shifting the boundary never bounces it.\n * - **Outside every lane:** a refused place, refused; open space (`\"open\"`: the content less what blocks it, the page),\n * the float at its landing; outside the stage (past `edge`), nowhere; else (docked content that takes nothing and\n * refuses nothing) refused.\n * - **Shift** turns a lane or open space into open space (the float), and hides the guides.\n * - **Guides** are the lane's `marks` (lines between items, a box per free stretch, in the layout as drawn), else its\n * spots' landings: the held lane's; else the approached lane's (the nearest within `reach`); over a refused place the\n * nearest lane's at any distance, so the lane behind a refused column shows its guides.\n * - Steps are measured between points that differ, normalized to 125 Hz, so the gates read the same at any input rate.\n * A repeated point keeps the last step; it is still only once the pointer has stayed put for `rest` ms.\n *\n * **The host's part:** call `update` whenever you like: per pointer sample, per animation frame, or both. Call it at\n * least once more after the pointer stops (every frame does), so it can become still, and again with the same point\n * when a key changes. Give `setRegions` the `regionsFor` that answers for the new state.\n */\n\n/** A place a drop in a lane lands: its stretch of the lane and its landing rect. Ids are stable across solves. */\nexport interface LandingSpot {\n readonly id: string;\n readonly along: readonly [number, number];\n readonly landing: Rect;\n /**\n * Where its drop draws every other item, as a key: a change between two spots with the same key moves only the held\n * item. Absent: every change to or from it counts as moving others.\n */\n readonly others?: string;\n}\n/**\n * A place guide's mark, in the layout as drawn: a line between two items that touch, a box over free room the item\n * lands in, a hatch over the part of a neighbor that gives way where the room is shorter than the item.\n */\nexport interface LandingMark {\n /** Stable while its neighbors stay; absent, the guide is keyed by its lane and place in the list. */\n readonly id?: string;\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n}\nexport interface LandingLane {\n readonly id: string;\n readonly rect: Rect;\n readonly axis: \"x\" | \"y\";\n readonly spots: readonly LandingSpot[];\n readonly refused: readonly { readonly along: readonly [number, number] }[];\n /** Its guides' marks; absent, its spots' landings are the guides. */\n readonly marks?: readonly LandingMark[];\n /**\n * Its rect is its own (a rail drop strip at the window's side): inside it, once its gate passes, it takes the pointer\n * from any lane it overlaps, a held one too. Absent: where lanes overlap, the deeper one wins.\n */\n readonly owns?: boolean;\n}\n/** A drag's regions (`lanes()` gives them). */\nexport interface LandingRegions {\n readonly lanes: readonly LandingLane[];\n readonly refused: readonly Rect[];\n readonly content: Rect;\n readonly blocked: readonly Rect[];\n readonly stage: Rect;\n /** The held item's size. */\n readonly item: { readonly width: number; readonly height: number };\n}\n\nexport interface LandingMargins {\n /** Past a held lane's rect before it lets go, px. */\n readonly exit: number;\n /** Past a spot boundary before the spot changes, px. */\n readonly spot: number;\n /** Past the stage that still counts as on its edge, px; beyond, nowhere. */\n readonly edge: number;\n /**\n * Around the lift point, px (16, as the drag intent's `liftZone`): an owning lane never takes the pointer there, so\n * away and back to where the item was lifted is home.\n */\n readonly lift?: number;\n}\nexport interface LandingGates {\n /** Pointer path inside a lane that enters it, px. */\n readonly path: number;\n /** Depth inside a lane where a still step enters it, px. */\n readonly depth: number;\n /** A still step, px per 8 ms. */\n readonly still: number;\n /**\n * The largest step that changes the spot along a lane where the change reflows the window, px per 8 ms; it also\n * bounds the steps the path gate counts (a fast crossing never enters).\n */\n readonly step: number;\n /** How far the held landing may trail the pointer before a fast reflowing change is taken anyway, px. */\n readonly trail: number;\n /**\n * The time a pointer has to stay put before it counts as still, ms, where its last step was already slow (at most\n * `step`) or it is on the stage's edge (a fling there is taken at once); repeated points before it aren't still.\n */\n readonly rest: number;\n /** The time a pointer that last moved fast has to stay put before it counts as still, ms: longer than sample gaps. */\n readonly pause: number;\n}\n/** The approach for near guides: the nearest lane within `reach`, kept until another is `nearer` closer or past `keep`. */\nexport interface LandingApproach {\n readonly reach: number;\n readonly keep: number;\n readonly nearer: number;\n}\n\nexport const LANDING_MARGINS: LandingMargins = { exit: 12, spot: 6, edge: 48, lift: 16 };\n/** A touch: wider margins, the finger's jitter. */\nexport const LANDING_TOUCH_MARGINS: LandingMargins = { exit: 16, spot: 8, edge: 48, lift: 16 };\nexport const LANDING_GATES: LandingGates = { path: 40, depth: 8, still: 1.5, step: 3, trail: 40, rest: 22, pause: 60 };\nexport const LANDING_APPROACH: LandingApproach = { reach: 80, keep: 96, nearer: 16 };\n\nexport interface LandingOptions {\n readonly regions: LandingRegions;\n /** The regions with `spot` held (its room open): the fixed-point check and the stretches while held. Cached per id. */\n readonly regionsFor?: (spot: string) => LandingRegions | null;\n /** The float's landing for a pointer over the document, or null where the item doesn't float. */\n readonly floatLanding?: (point: Point) => Rect | null;\n /** The item's own place at the lift: its lane and spot (the drag starts there, the room open). */\n readonly home?: { readonly lane: string; readonly spot: string };\n /** Where the item was lifted (the press), in the regions' space; default the first point `update` gets. */\n readonly lift?: Point;\n readonly margins?: Partial<LandingMargins>;\n readonly gates?: Partial<LandingGates>;\n readonly approach?: Partial<LandingApproach>;\n readonly placeGuides?: PlaceGuides;\n}\n\nexport type LandingRegion = \"lane\" | \"open\" | \"refused\" | \"nowhere\";\n\n/** A guide: a mark of a lane, where to draw it now (a spot's landing is a box). */\nexport interface LandingGuide {\n /** Stable while its neighbors stay: the mark's id, else `<lane>/<spot id>` for a spot's landing. Key a drawing by it. */\n readonly id: string;\n readonly lane: string;\n /** A line, a box, or a hatch over a neighbor that gives way (draw it over that item, in the guides' color). */\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n}\n\nexport interface LandingFrame {\n readonly region: LandingRegion;\n /** The lane held (also over its refused stretch), or null. */\n readonly lane: string | null;\n /** The spot held, or null. */\n readonly spot: string | null;\n /** Where a release now lands: the spot's landing, or the float's; null where it lands nowhere (the item goes home). */\n readonly landing: Rect | null;\n /** The room is open: a spot is held in a lane, no Shift. */\n readonly room: boolean;\n readonly guides: readonly LandingGuide[];\n /** Shift held: the region is open space wherever it was a lane or open space. */\n readonly shift: boolean;\n /**\n * The lane the pointer is inside but hasn't entered (its gate not passed yet: a fast pass, or the moment before a slow\n * step), else absent. A host shows no \"Can't go here\" while it is set, though a release now lands nowhere: the place\n * under the pointer is a lane's, not a refused one.\n */\n readonly pending?: string;\n}\n\n/** What a release lands: a spot (`home` when it is the item's own place), the float at `rect`, or nothing. */\nexport type LandingRelease = { readonly kind: \"spot\"; readonly lane: string; readonly spot: string; readonly home: boolean } | { readonly kind: \"float\"; readonly rect: Rect } | null;\n\nexport interface LandingModel {\n update(point: Point, time: number, keys?: DragKeys): LandingFrame;\n /** What a release lands, by the last frame: the same answer as its `landing`. */\n release(): LandingRelease;\n /**\n * The regions changed (a resize, a store change, a scroll): spots map by id; a lost one goes to its lane's nearest.\n * Pass the `regionsFor` that answers for the new state; without one, the old one stays (it must then read live state).\n */\n setRegions(regions: LandingRegions, regionsFor?: (spot: string) => LandingRegions | null): void;\n /** The view moved under the pointer: the gates start again, the lane is let go. */\n hide(): void;\n readonly frame: LandingFrame;\n}\n\nconst inside = (r: Rect, p: Point, grow = 0): boolean => p.x >= r.x - grow && p.x <= r.x + r.width + grow && p.y >= r.y - grow && p.y <= r.y + r.height + grow;\nconst strictlyIn = (r: Rect, p: Point): boolean => p.x >= r.x && p.x <= r.x + r.width && p.y >= r.y && p.y <= r.y + r.height;\n/**\n * How deep `p` lies inside `r` (0 on its edge or outside), counted only from the sides of `r` that face into `stage`: a\n * side on the stage's edge is open, as deep as the pointer can go.\n */\nfunction depthIn(r: Rect, p: Point, stage: Rect): number {\n if (!strictlyIn(r, p)) return 0;\n const on = (a: number, b: number): boolean => Math.abs(a - b) < 1;\n const sides = [\n on(r.x, stage.x) ? Infinity : p.x - r.x,\n on(r.x + r.width, stage.x + stage.width) ? Infinity : r.x + r.width - p.x,\n on(r.y, stage.y) ? Infinity : p.y - r.y,\n on(r.y + r.height, stage.y + stage.height) ? Infinity : r.y + r.height - p.y,\n ];\n return Math.max(0, Math.min(...sides));\n}\nconst distanceTo = (r: Rect, p: Point): number => Math.hypot(Math.max(r.x - p.x, 0, p.x - (r.x + r.width)), Math.max(r.y - p.y, 0, p.y - (r.y + r.height)));\nconst alongOf = (lane: LandingLane, p: Point): number => (lane.axis === \"x\" ? p.x : p.y);\nconst acrossOf = (lane: LandingLane, p: Point): number => (lane.axis === \"x\" ? p.y : p.x);\n/** Two rects meet: they overlap or touch (within 1 px), corners included. */\nconst touches = (a: Rect, b: Rect): boolean => a.x <= b.x + b.width + 1 && b.x <= a.x + a.width + 1 && a.y <= b.y + b.height + 1 && b.y <= a.y + a.height + 1;\n/** `p` onto `stage` when it lies past it by at most `reach`; else null (nowhere). */\nfunction ontoStage(stage: Rect, p: Point, reach: number): Point | null {\n if (!inside(stage, p, reach)) return null;\n return { x: Math.min(Math.max(p.x, stage.x), stage.x + stage.width), y: Math.min(Math.max(p.y, stage.y), stage.y + stage.height) };\n}\n\nexport function createLandingModel(options: LandingOptions): LandingModel {\n const margins = { ...LANDING_MARGINS, ...options.margins };\n const gates = { ...LANDING_GATES, ...options.gates };\n const approach = { ...LANDING_APPROACH, ...options.approach };\n const guidesLevel: PlaceGuides = options.placeGuides ?? \"off\";\n let base = options.regions;\n let regionsFor = options.regionsFor;\n const cache = new Map<string, LandingRegions | null>();\n /** The regions with `spot` held: the host's, cached for this lift until `setRegions`. */\n const heldRegions = (spot: string | null): LandingRegions => {\n if (!spot || !regionsFor) return base;\n if (!cache.has(spot)) cache.set(spot, regionsFor(spot));\n return cache.get(spot) ?? base;\n };\n\n let laneId: string | null = options.home?.lane ?? null;\n let spotId: string | null = options.home?.spot ?? null;\n let last: { p: Point; raw: Point; t: number } | null = null;\n /** The last point that differed from the one before, and the step then. */\n let moved: { raw: Point; t: number } | null = null;\n /** Where the item was lifted (`lift`, else the first point), fixed for the drag: back there, no owning lane takes it. */\n let liftAt: Point | null = options.lift ?? null;\n let lastStep = 0;\n /** Path inside each lane since the pointer last entered its rect. */\n const pathIn = new Map<string, number>();\n /** The path along and across each lane at any speed since the pointer entered it (a touching lane's takeover). */\n const slide = new Map<string, { along: number; across: number }>();\n /** The owning lanes the pointer has been outside since the lift: only those may take it (it came into them). */\n const cameIn = new Set<string>();\n let approached: string | null = null;\n let previous: LandingRegion = laneId ? \"lane\" : \"open\";\n let frame: LandingFrame = { region: previous, lane: laneId, spot: spotId, landing: null, room: !!spotId, guides: [], shift: false };\n\n const laneIn = (regions: LandingRegions, id: string | null): LandingLane | undefined => (id ? regions.lanes.find((l) => l.id === id) : undefined);\n const spotIn = (lane: LandingLane | undefined, id: string | null): LandingSpot | undefined => (lane && id ? lane.spots.find((s) => s.id === id) : undefined);\n\n /** The spot a point along `lane` picks: the spot whose stretch holds it, null over a refused stretch, else the nearest. */\n function pick(lane: LandingLane, a: number): LandingSpot | null {\n if (lane.refused.some((r) => a >= r.along[0] && a <= r.along[1])) return null;\n const hit = lane.spots.find((s) => a >= s.along[0] && a <= s.along[1]);\n if (hit) return hit;\n let best: LandingSpot | null = null;\n let dist = Infinity;\n for (const s of lane.spots) {\n const d = a < s.along[0] ? s.along[0] - a : a - s.along[1];\n if (d < dist) {\n best = s;\n dist = d;\n }\n }\n return best;\n }\n\n /** Along a held lane: the spot after hysteresis, the step gate and the fixed-point check. */\n function along(lane: LandingLane, p: Point, step: number): LandingSpot | null {\n const regions = heldRegions(spotId);\n const held = laneIn(regions, lane.id) ?? lane;\n const a = alongOf(held, p);\n const now = spotIn(held, spotId);\n const cand = pick(held, a);\n if (!cand) return null;\n if (!now || cand.id === now.id) return cand;\n // Past the boundary by the margin, the same everywhere (a wobble within it never flips the spot); where the change\n // moves another item, on a slow enough step. Else the last spot holds.\n const past = a < now.along[0] - margins.spot || a > now.along[1] + margins.spot;\n const reflows = now.others === undefined || now.others !== cand.others;\n if (!past) return now;\n // A fast reflowing change waits for a slow step, unless the held landing already trails the pointer by `trail`: the\n // item chases only as far as it must, so a fast hand across docked items never leaves it far behind.\n if (reflows && step > gates.step && distanceTo(now.landing, p) <= gates.trail) return now;\n // The fixed point: in the candidate's own regions (its room open), the pointer still picks it.\n if (regionsFor && reflows) {\n const theirs = heldRegions(cand.id);\n const lane2 = laneIn(theirs, lane.id);\n if (lane2 && pick(lane2, alongOf(lane2, p))?.id !== cand.id) return now;\n }\n return cand;\n }\n\n function guidesFor(p: Point, region: LandingRegion, shift: boolean): LandingGuide[] {\n if (guidesLevel === \"off\" || shift) return [];\n const regions = heldRegions(spotId);\n const all = (l: LandingLane): LandingGuide[] =>\n l.marks\n ? l.marks.map((m, i) => ({ id: m.id ?? `${l.id}#${i}`, lane: l.id, kind: m.kind, rect: m.rect }))\n : l.spots.map((s) => ({ id: `${l.id}/${s.id}`, lane: l.id, kind: \"box\" as const, rect: s.landing }));\n if (guidesLevel === \"all\") return regions.lanes.flatMap(all);\n if ((region === \"lane\" || region === \"refused\") && laneId) {\n approached = laneId;\n const l = laneIn(regions, laneId);\n return l ? all(l) : [];\n }\n let best: LandingLane | null = null;\n let bestD = Infinity;\n for (const l of regions.lanes) {\n const d = distanceTo(l.rect, p);\n if (d < bestD) {\n best = l;\n bestD = d;\n }\n }\n // Over a refused place: the nearest lane at any distance (the lane behind a refused column).\n if (region === \"refused\") {\n approached = best?.id ?? null;\n return best ? all(best) : [];\n }\n // The approached lane: the nearest within reach, kept until another is clearly nearer or it is past `keep`.\n const kept = laneIn(regions, approached);\n if (kept) {\n const d = distanceTo(kept.rect, p);\n if (d > approach.keep) approached = null;\n else if (best && best.id !== kept.id && bestD + approach.nearer < d) approached = bestD <= approach.reach ? best.id : null;\n } else approached = best && bestD <= approach.reach ? best.id : null;\n const l = laneIn(regions, approached);\n return l ? all(l) : [];\n }\n\n function update(raw: Point, t: number, keys?: DragKeys): LandingFrame {\n // Past the stage by up to `edge`: on its edge. Beyond: nowhere (kept as is).\n const p = ontoStage(heldRegions(spotId).stage, raw, margins.edge) ?? raw;\n // The step: the pointer as it moved (a fling past the edge isn't still) since the last point that differed,\n // normalized to 125 Hz (8 ms). A repeated point (a host updating per frame, or a gap between sparse samples) keeps\n // the last step until the pointer has stayed put for `rest` ms after a slow step or on the stage's edge, else for\n // `pause` ms; only then is it still. A hand moving fast with samples far apart is never still between them.\n let step = 0;\n if (moved && (raw.x !== moved.raw.x || raw.y !== moved.raw.y)) {\n step = (Math.hypot(raw.x - moved.raw.x, raw.y - moved.raw.y) * 8) / Math.max(1, t - moved.t);\n moved = { raw, t };\n lastStep = step;\n } else if (moved) {\n const stage = heldRegions(spotId).stage;\n const onEdge = p.x <= stage.x || p.y <= stage.y || p.x >= stage.x + stage.width || p.y >= stage.y + stage.height;\n const since = t - moved.t;\n step = since >= gates.pause || (since >= gates.rest && (lastStep <= gates.step || onEdge)) ? 0 : lastStep;\n } else {\n // The first point: how the pointer moves is unknown, never still (a lift over a lane's band doesn't enter it).\n moved = { raw, t };\n // (After `hide()` too, the lift point stays where the drag began.)\n liftAt ??= p;\n step = lastStep = Infinity;\n }\n const from = last?.p ?? null;\n // The pointer as it moved: a fling off the stage's edge moves across a lane there though its clamped point doesn't.\n const fromRaw = last?.raw ?? null;\n last = { p, raw, t };\n const shift = !!keys?.shift;\n const regions = heldRegions(spotId);\n // The path inside each lane: the part along the lane of slow steps from a point inside it to another (the step that\n // enters doesn't count, nor a fast one), so a crossing at `step` speed or faster never enters by path at any angle.\n // From a held lane, a touching lane counts the path along it and across it at any speed: a fast slide along it\n // (across it at most a third as far as along) is no crossing.\n const slow = step <= gates.step;\n for (const l of regions.lanes) {\n const was = from && strictlyIn(l.rect, from);\n const go = was ? Math.abs(alongOf(l, p) - alongOf(l, from)) : 0;\n const over = was && fromRaw ? Math.abs(acrossOf(l, raw) - acrossOf(l, fromRaw)) : 0;\n const inL = strictlyIn(l.rect, p);\n pathIn.set(l.id, inL ? (pathIn.get(l.id) ?? 0) + (slow ? go : 0) : 0);\n const s = slide.get(l.id);\n slide.set(l.id, inL ? { along: (s?.along ?? 0) + go, across: (s?.across ?? 0) + over } : { along: 0, across: 0 });\n if (l.owns && !inL) cameIn.add(l.id);\n }\n\n let region: LandingRegion;\n let pending: string | null = null;\n if (!inside(regions.stage, p)) {\n // Outside the stage: nowhere, and the lane is let go.\n region = \"nowhere\";\n laneId = spotId = null;\n } else {\n const held = laneIn(regions, laneId);\n const gate = (l: LandingLane): boolean => (pathIn.get(l.id) ?? 0) >= gates.path || (depthIn(l.rect, p, regions.stage) >= gates.depth && step <= gates.still);\n // Lane to lane: inside a lane touching the held one, past the held lane's exit margin (inside it the held lane holds,\n // P1), the held lane still holds until that lane's gate passes, then that lane takes it. Never the float between\n // them, never a fly-through's room.\n const touching = held ? regions.lanes.find((l) => l.id !== held.id && strictlyIn(l.rect, p) && touches(l.rect, held.rect) && !inside(held.rect, p, margins.exit)) : undefined;\n const sl = touching ? slide.get(touching.id) : undefined;\n const slid = !!sl && sl.along >= gates.path && sl.across * 3 <= sl.along;\n // A lane that owns its rect (a rail drop strip) takes the pointer inside it from any lane it overlaps, a held one\n // too, once its own gate passes (so a pass across it opens nothing), and only once the pointer came into it (it has\n // been outside it since the lift): a press in a column's outer edge, or a slow reorder along it, stays in the column.\n // Never within `lift` of where the item was lifted: away and back there is home, wherever a strip lies, while the\n // rest of the strip (all of it over a lone panel's own place) still takes it.\n const nearLift = !!liftAt && Math.hypot(p.x - liftAt.x, p.y - liftAt.y) <= (margins.lift ?? 16);\n const owner = nearLift ? undefined : regions.lanes.find((l) => l.owns && l.id !== held?.id && cameIn.has(l.id) && strictlyIn(l.rect, p) && gate(l));\n const next = owner ?? (touching && (gate(touching) || slid) ? touching : undefined);\n if (held && !next && (touching || inside(held.rect, p, margins.exit))) {\n const s = along(held, p, step);\n spotId = s?.id ?? spotId;\n region = s ? \"lane\" : \"refused\";\n if (!s) spotId = null;\n // Past its own rect, a held lane that refuses still holds (lane to lane never passes through the float), but\n // the pointer is in another lane it hasn't entered yet: that lane is pending, so a host shows no \"Can't go here\"\n // in a lane's first pixels when the pointer comes in over a refused stretch next to it.\n if (!s && !strictlyIn(held.rect, p)) {\n const others = regions.lanes.filter((l) => l.id !== held.id && strictlyIn(l.rect, p));\n if (others.length > 0) pending = others.reduce((a, b) => (depthIn(b.rect, p, regions.stage) > depthIn(a.rect, p, regions.stage) ? b : a)).id;\n }\n } else {\n laneId = spotId = null;\n // Entering: a touching lane at once, else the path gate or the still gate; at a tie, the lane the pointer is\n // deeper in. Over a refused place (a lane's band over a column that takes nothing, an empty side rail's) a lane is\n // entered at once, never on the lift: there is nothing else the pointer can mean there, and nothing to fly\n // through to.\n // (Over something that takes nothing reaching past the lane, a column's panel under an empty rail's band, and in\n // no other lane; a drawn bar's own rect and its items lie within it, so its gate holds.)\n // Within the lift zone an owning lane is no lane at all: by no gate does it take the pointer there.\n const lanesHere = regions.lanes.filter((l) => strictlyIn(l.rect, p) && !(l.owns && nearLift));\n const within = (b: Rect, l: LandingLane): boolean => b.x >= l.rect.x - 1 && b.y >= l.rect.y - 1 && b.x + b.width <= l.rect.x + l.rect.width + 1 && b.y + b.height <= l.rect.y + l.rect.height + 1;\n // On a slow step only (as a slow hand inside a bar enters it): a fly-through across such a place opens no room.\n const overRefused = (l: LandingLane): boolean =>\n Number.isFinite(step) && step <= gates.step && lanesHere.length === 1 && [...regions.blocked, ...regions.refused].some((b) => strictlyIn(b, p) && !within(b, l));\n let entered: LandingLane | null = next ?? null;\n if (!entered)\n for (const l of lanesHere) {\n const deep = depthIn(l.rect, p, regions.stage);\n if ((gate(l) || overRefused(l)) && (!entered || deep > depthIn(entered.rect, p, regions.stage))) entered = l;\n }\n // Inside a lane not entered yet: no refused place to say so of, whatever lies under it.\n if (!entered && lanesHere.length > 0) pending = lanesHere.reduce((a, b) => (depthIn(b.rect, p, regions.stage) > depthIn(a.rect, p, regions.stage) ? b : a)).id;\n if (entered) {\n laneId = entered.id;\n const s = pick(entered, alongOf(entered, p));\n spotId = s?.id ?? null;\n region = s ? \"lane\" : \"refused\";\n } else if (regions.refused.some((r) => inside(r, p))) region = \"refused\";\n else if (inside(regions.content, p) && !regions.blocked.some((b) => strictlyIn(b, p))) region = \"open\";\n // Inside a lane not yet entered: what it was (on the way in, the document's float).\n else if (regions.lanes.some((l) => strictlyIn(l.rect, p))) region = previous === \"lane\" ? \"open\" : previous;\n else region = \"refused\";\n }\n }\n previous = region;\n const shown: LandingRegion = shift && (region === \"lane\" || region === \"open\") ? \"open\" : region;\n const r2 = heldRegions(spotId);\n const spot = spotIn(laneIn(r2, laneId), spotId);\n const landing = shown === \"lane\" ? (spot?.landing ?? null) : shown === \"open\" ? (options.floatLanding?.(p) ?? null) : null;\n frame = {\n region: shown,\n lane: laneId,\n spot: shown === \"lane\" ? spotId : null,\n landing,\n room: shown === \"lane\" && !!spot,\n guides: guidesFor(p, shown, shift),\n shift,\n ...(pending && shown !== \"lane\" ? { pending } : {}),\n };\n return frame;\n }\n\n return {\n update,\n release(): LandingRelease {\n if (frame.region === \"lane\" && frame.lane && frame.spot) return { kind: \"spot\", lane: frame.lane, spot: frame.spot, home: !!options.home && options.home.spot === frame.spot && options.home.lane === frame.lane };\n if (frame.region === \"open\" && frame.landing) return { kind: \"float\", rect: frame.landing };\n return null;\n },\n setRegions(regions: LandingRegions, nextRegionsFor?: (spot: string) => LandingRegions | null): void {\n base = regions;\n if (nextRegionsFor) regionsFor = nextRegionsFor;\n cache.clear();\n const l = laneIn(base, laneId);\n if (laneId && !l) laneId = spotId = null;\n else if (l && spotId && !spotIn(l, spotId) && last) spotId = pick(l, alongOf(l, last.p))?.id ?? null;\n },\n hide(): void {\n laneId = spotId = null;\n approached = null;\n pathIn.clear();\n slide.clear();\n cameIn.clear();\n last = moved = null;\n lastStep = 0;\n },\n get frame(): LandingFrame {\n return frame;\n },\n };\n}\n","import type { DragFrame, DragTarget } from \"./intent\";\n\n/**\n * How a drag previews its drop, from least to most motion while dragging:\n *\n * - `\"indicator\"`: nothing moves; only the indicator (an outline or an\n * insertion marker) shows the target.\n * - `\"gap\"`: once the room is made, the others move aside and open the slot;\n * the item stays under the pointer.\n * - `\"snap\"`: the gap opens and the item itself glides into it (for a target\n * with a slot; one without keeps the indicator).\n * - `\"item\"`: the dragged item is the only preview: no indicator for any\n * target. It sits in a slotted target once the room is open and otherwise\n * stays on the pointer. Pair it with the intent's `earlyRelease: \"float\"`, so\n * a release lands what shows.\n *\n * Every mode follows the same intent: what shows, when, and what a release\n * lands on are the drag intent's, so a drop always lands where the preview\n * showed it.\n */\nexport type DragPreview = \"indicator\" | \"gap\" | \"snap\" | \"item\";\n\n/** The preview a drag uses unless the host picks another. */\nexport const DRAG_PREVIEW_DEFAULT: DragPreview = \"snap\";\n\n/**\n * Place guides: faint marks on the free places that take the held item, shown only while no landing shows. `\"off\"`:\n * none; `\"near\"`: the places of the edge the pointer approaches; `\"all\"`: every place, from the lift.\n */\nexport type PlaceGuides = \"off\" | \"near\" | \"all\";\n\n/**\n * How a place guide draws an empty lane (an empty bar or side rail, its room not open yet): `\"real\"`, a box at the size\n * the lane will take, over what moves aside (the page, a column); `\"edge\"`, a thin striped strip on the lane's window\n * side. The landing is the same either way. Placement's `lanes()` takes it as `emptyLanes`.\n */\nexport type EmptyLanes = \"real\" | \"edge\";\n\n/**\n * A drop preview as a mode and its place guides, beside the string forms: `\"outline\"` is `\"indicator\"`'s plan,\n * `\"placeholder\"` is `\"gap\"`'s, and `\"snap\"` is `\"item\"`'s (the item the only preview). `placeGuides` defaults per mode\n * ({@link PLACE_GUIDES_DEFAULT}); `emptyLanes` (how its guides draw an empty lane) defaults to `\"real\"`.\n */\nexport type DropPreviewMode =\n | { readonly mode: \"outline\"; readonly placeGuides?: PlaceGuides; readonly emptyLanes?: EmptyLanes }\n | { readonly mode: \"placeholder\"; readonly placeGuides?: PlaceGuides; readonly emptyLanes?: EmptyLanes }\n | { readonly mode: \"snap\"; readonly placeGuides?: PlaceGuides; readonly emptyLanes?: EmptyLanes };\n\n/** Each mode's place guides when it names none: Snap and Placeholder near, Outline none. */\nexport const PLACE_GUIDES_DEFAULT: Readonly<Record<DropPreviewMode[\"mode\"], PlaceGuides>> = { outline: \"off\", placeholder: \"near\", snap: \"near\" };\n\n/** The string plan each mode draws with. */\nconst PLAN_OF: Readonly<Record<DropPreviewMode[\"mode\"], DragPreview>> = { outline: \"indicator\", placeholder: \"gap\", snap: \"item\" };\n\n/** What to draw for one frame of a drag. */\nexport interface PreviewPlan {\n /** Draw the indicator on the shown target. */\n readonly showIndicator: boolean;\n /** Lay the others out around the room (the gap is open). */\n readonly makeRoom: boolean;\n /** Draw the item in its slot instead of under the pointer. */\n readonly snapItem: boolean;\n /**\n * The place guides to draw this frame: the mode's `placeGuides` while no landing shows (no indicator, no room, no item\n * in its slot), `\"off\"` whenever one does, so the screen shows where the item can go or where it will land, never\n * both. Always `\"off\"` for the string forms. Optional, so a plan a host builds itself is still one: absent means\n * `\"off\"`.\n */\n readonly guides?: PlaceGuides;\n /** How the guides draw an empty lane (the object form's `emptyLanes`, `\"real\"` when it names none); absent for the string forms. */\n readonly emptyLanes?: EmptyLanes;\n}\n\n/**\n * The plan for a frame of the drag intent under `preview`. `slotted` says\n * whether the shown target's drop has a slot the item can sit in (default: a\n * target that isn't `free`); only such a target snaps, and in `\"snap\"` it\n * previews with the item rather than the indicator.\n *\n * - `\"indicator\"`: the indicator, never room, never a snap.\n * - `\"gap\"`: the indicator, and room when the intent makes it.\n * - `\"snap\"`: room when the intent makes it, the item snapped into a slotted\n * target's room; the indicator only for a target without a slot.\n * - `\"item\"`: as `\"snap\"`, with no indicator at all.\n *\n * The object form ({@link DropPreviewMode}) draws with its mode's string plan and adds its place guides (`guides`).\n */\nexport function previewPlan<T extends DragTarget>(\n frame: Pick<DragFrame<T>, \"shown\" | \"room\">,\n preview: DragPreview | DropPreviewMode,\n slotted: boolean = !!frame.shown && !frame.shown.free,\n): PreviewPlan {\n if (typeof preview === \"object\") {\n const plan = stringPlan(frame, PLAN_OF[preview.mode], slotted);\n const asked = preview.placeGuides ?? PLACE_GUIDES_DEFAULT[preview.mode];\n const landing = plan.showIndicator || plan.makeRoom || plan.snapItem;\n return { ...plan, guides: landing ? \"off\" : asked, emptyLanes: preview.emptyLanes ?? \"real\" };\n }\n return stringPlan(frame, preview, slotted);\n}\n\nfunction stringPlan<T extends DragTarget>(frame: Pick<DragFrame<T>, \"shown\" | \"room\">, preview: DragPreview, slotted: boolean): PreviewPlan {\n const shown = !!frame.shown;\n if (preview === \"indicator\") return { showIndicator: shown, makeRoom: false, snapItem: false, guides: \"off\" };\n if (preview === \"gap\") return { showIndicator: shown, makeRoom: frame.room, snapItem: false, guides: \"off\" };\n if (preview === \"item\") return { showIndicator: false, makeRoom: frame.room, snapItem: frame.room && shown && slotted, guides: \"off\" };\n // By design a slotted target draws nothing until the room opens (`roomAfter`); a release then still lands on it.\n return { showIndicator: shown && !slotted, makeRoom: frame.room, snapItem: frame.room && shown && slotted, guides: \"off\" };\n}\n","import { DOUBLE_CLICK, type DoubleClick } from \"../double-click\";\nimport type { Point } from \"../shapes\";\nimport { liftDecision, type DragTuning, type LiftDecision } from \"./intent\";\n\n/** How a press on a grip ended: a click, the second click of a double (`doubleActivate`, not a click), or a drag (`null`). */\nexport type GripRelease = \"click\" | \"doubleActivate\" | null;\n\n/** A press on a grip, start to end: whether it lifts, and what its release is. Pure: positions and times are the host's. */\nexport interface GripPress {\n /**\n * A press at `point`, `time` ms. `touch` for a finger (the touch lift rule). `clicks`, when the host has the\n * platform's count for this press (a `mousedown`'s `detail`, 1 or more), decides the double instead of the interval.\n */\n down(point: Point, time: number, options?: { readonly touch?: boolean; readonly clicks?: number }): void;\n /** The pointer moved: `liftDecision` for this press. Once `\"lift\"` it stays a drag; once `\"refuse\"` it never is. */\n move(point: Point, time: number): LiftDecision;\n /**\n * The press ended. `\"click\"`, or `\"doubleActivate\"` when it is the second click of a double (it is not a click\n * then); null when it lifted or was refused. A press that never moved past the lift distance never lifts, so an\n * unmoved double never starts a drag (a second press that moves past it is a drag like any other). A third click\n * after a double starts a new pair.\n */\n up(point: Point, time: number): GripRelease;\n /** Forget the press and the click before it (a cancelled press, a scroll). */\n cancel(): void;\n}\n\n/**\n * A grip's press, double-click included: a press that moves past the lift distance is a drag; one that doesn't is a\n * click, and a second such press within the double interval and distance is a double-activate (the host folds or\n * unfolds, say), never a second click and never a lift: an unmoved double never starts a drag.\n *\n * The first click of a double is delivered as `\"click\"` before the double is known (nothing waits for a second press),\n * so a host keeps a grip's click harmless (a use, a focus): the double-activate that follows must not have to undo it.\n */\nexport function createGripPress(options: { readonly tuning?: Partial<DragTuning>; readonly double?: Partial<DoubleClick> } = {}): GripPress {\n const tuning = options.tuning ?? {};\n // The package's one double click (`DOUBLE_CLICK`), unless the host tunes it.\n const dbl: DoubleClick = { ...DOUBLE_CLICK, ...options.double };\n let press: { at: Point; time: number; touch: boolean; double: boolean; state: LiftDecision } | null = null;\n // The last click (a press that ended as one): where and when it was pressed.\n let last: { at: Point; time: number } | null = null;\n return {\n down(point, time, o = {}) {\n const near = !!last && time - last.time <= dbl.ms && Math.hypot(point.x - last.at.x, point.y - last.at.y) <= dbl.px;\n const double = o.clicks !== undefined && o.clicks > 0 ? o.clicks === 2 : near;\n press = { at: { x: point.x, y: point.y }, time, touch: !!o.touch, double, state: \"wait\" };\n },\n move(point, time) {\n if (!press) return \"wait\";\n if (press.state !== \"wait\") return press.state;\n press.state = liftDecision({ touch: press.touch, distance: Math.hypot(point.x - press.at.x, point.y - press.at.y), elapsed: time - press.time }, tuning);\n return press.state;\n },\n up() {\n const p = press;\n press = null;\n if (!p || p.state !== \"wait\") {\n last = null;\n return null;\n }\n if (p.double) {\n last = null;\n return \"doubleActivate\";\n }\n last = { at: p.at, time: p.time };\n return \"click\";\n },\n cancel() {\n press = null;\n last = null;\n },\n };\n}\n","import type { Rect } from \"../shapes\";\n\n/** A guide to place: any record with a `kind` and a `rect` (a landing model's `LandingGuide`, a lane's marks). */\nexport interface PlacedGuide {\n readonly kind: \"line\" | \"box\" | \"hatch\";\n readonly rect: Rect;\n}\n\nexport interface GuideRectsOptions {\n /** The area guides are drawn in: the window's inside (inside its border), px. */\n readonly inside: Rect;\n /** How far inside `inside` every guide stays, px (default 2). */\n readonly inset?: number;\n /** Rects a thin guide stays clear of (the content: a column's panels under an empty lane's thin edge). */\n readonly clear?: readonly Rect[];\n /** The least thickness a thin guide keeps, px (default 2); thinner, it is not drawn. */\n readonly minThickness?: number;\n}\n\nconst EPS = 1e-6;\n\n/**\n * Where to draw guides: every guide inside `inside` by `inset`. A box is clipped. A thin guide (a line, a striped\n * strip or end: its shorter side is its thickness) keeps its thickness and moves inside rather than being clipped, so\n * a line at a lane's far end is as thick as at its head. Then it is thinned, from the content side, to stay clear of\n * `clear`, so a thin strip at the window's side lies between the inset and the content, the same on both sides. A\n * guide with nothing left (or a thin one under `minThickness`) is left out. Pure; the guides come back as given with\n * their placed `rect`.\n */\nexport function guideRects<G extends PlacedGuide>(guides: readonly G[], options: GuideRectsOptions): G[] {\n const inset = Number.isFinite(options.inset) ? Math.max(0, options.inset!) : 2;\n const min = Number.isFinite(options.minThickness) ? Math.max(0, options.minThickness!) : 2;\n // A guide placed where it already was comes back as given (the same rect object), so a host can key on it.\n const same = (a: Rect, b: Rect): boolean => Math.abs(a.x - b.x) < EPS && Math.abs(a.y - b.y) < EPS && Math.abs(a.width - b.width) < EPS && Math.abs(a.height - b.height) < EPS;\n const place = (g: G, rect: Rect): G => (same(g.rect, rect) ? g : { ...g, rect });\n const x0 = options.inside.x + inset;\n const y0 = options.inside.y + inset;\n const x1 = options.inside.x + options.inside.width - inset;\n const y1 = options.inside.y + options.inside.height - inset;\n const clear = options.clear ?? [];\n const out: G[] = [];\n for (const g of guides) {\n const r = g.rect;\n if (g.kind === \"box\") {\n const a = Math.max(r.x, x0);\n const b = Math.max(r.y, y0);\n const c = Math.min(r.x + r.width, x1);\n const d = Math.min(r.y + r.height, y1);\n if (c - a > EPS && d - b > EPS) out.push(place(g, { x: a, y: b, width: c - a, height: d - b }));\n continue;\n }\n // A thin guide: thick along one axis (its shorter side), long along the other.\n const thinX = r.width <= r.height;\n // Along its thickness: moved inside whole; along its length: clipped.\n const t = thinX ? r.width : r.height;\n let lo = thinX ? r.x : r.y;\n const lim0 = thinX ? x0 : y0;\n const lim1 = thinX ? x1 : y1;\n if (lo + t > lim1) lo = lim1 - t;\n if (lo < lim0) lo = lim0;\n let hi = Math.min(lo + t, lim1);\n const s0 = Math.max(thinX ? r.y : r.x, thinX ? y0 : x0);\n const s1 = Math.min(thinX ? r.y + r.height : r.x + r.width, thinX ? y1 : x1);\n if (s1 - s0 <= EPS) continue;\n // Clear of what it must not cover: cut from the side the clear rect lies on.\n for (const c of clear) {\n const cs0 = thinX ? c.y : c.x;\n const cs1 = thinX ? c.y + c.height : c.x + c.width;\n if (cs1 <= s0 + EPS || cs0 >= s1 - EPS) continue;\n const c0 = thinX ? c.x : c.y;\n const c1 = thinX ? c.x + c.width : c.y + c.height;\n if (c1 <= lo + EPS || c0 >= hi - EPS) continue;\n // Keep the side away from the clear rect's middle.\n if ((c0 + c1) / 2 >= (lo + hi) / 2) hi = Math.min(hi, c0);\n else lo = Math.max(lo, c1);\n }\n if (hi - lo < Math.max(EPS, min)) continue;\n out.push(place(g, thinX ? { x: lo, y: s0, width: hi - lo, height: s1 - s0 } : { x: s0, y: lo, width: s1 - s0, height: hi - lo }));\n }\n return out;\n}\n"],"mappings":";;;;;AAoGO,IAAM,gBAA4B;AAAA,EACvC,MAAM;AAAA,EACN,WAAW;AAAA,EACX,WAAW;AAAA,EACX,aAAa;AAAA,EACb,UAAU;AAAA,EACV,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,cAAc;AAAA,EACd,WAAW;AAAA,EACX,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,WAAW;AAAA,EACX,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,WAAW,EAAE,IAAI,MAAM,UAAU,SAAS,SAAS,MAAM;AAC3D;AAEA,IAAM,YAAiE,EAAE,OAAO,SAAS,KAAK,OAAO,SAAS,QAAQ,MAAM,OAAO;AAEnI,IAAM,OAAO,CAAC,MAA4B,QACxC,CAAC,CAAC,SAAS,QAAQ,QAAQ,CAAC,EAAE,KAAK,QAAQ,KAAK,QAAQ,CAAC,CAAC,KAAK,UAAU,GAAG,CAAC;AAuExE,IAAM,eAAe;AAGrB,IAAM,WAAW,CAAC,MAAwD,EAAE,WAAW,OAAO,eAAe,EAAE;AAGtH,IAA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O,QAAQ,KAAK,EAAE;AAC3E,QAAI,KAAK,MAAM,IAAK;AAEpB,eAAW,KAAK,OAAO;AACrB,YAAM,MAAM,QAAQ,EAAE,IAAI,EAAE;AAC5B,YAAM,MAAM,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;AAC7C,UAAI,OAAO,KAAK,OAAO,OAAO,KAAK,IAAK;AACxC,YAAM,KAAK,QAAQ,EAAE,IAAI,EAAE;AAC3B,YAAM,KAAK,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE;AAC3C,UAAI,MAAM,KAAK,OAAO,MAAM,KAAK,IAAK;AAEtC,WAAK,KAAK,MAAM,MAAM,KAAK,MAAM,EAAG,MAAK,KAAK,IAAI,IAAI,EAAE;AAAA,UACnD,MAAK,KAAK,IAAI,IAAI,EAAE;AAAA,IAC3B;AACA,QAAI,KAAK,KAAK,KAAK,IAAI,KAAK,GAAG,EAAG;AAClC,QAAI,KAAK,MAAM,GAAG,QAAQ,EAAE,GAAG,IAAI,GAAG,IAAI,OAAO,KAAK,IAAI,QAAQ,KAAK,GAAG,IAAI,EAAE,GAAG,IAAI,GAAG,IAAI,OAAO,KAAK,IAAI,QAAQ,KAAK,GAAG,CAAC,CAAC;AAAA,EAClI;AACA,SAAO;AACT;","names":["held","distanceTo","held","l","within"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@n-uf/motion",
3
- "version": "26.11.48",
4
- "description": "One frame loop with an injected clock, fine-grained signals, springs and tweens, and a DOM-free gesture recogniser. No DOM, no framework.",
3
+ "version": "26.11.49",
4
+ "description": "How things move: one frame loop with an injected clock, fine-grained signals, springs, tweens and the settle curve, a DOM-free gesture recognizer, the drag intent and the landing model, and layout motion. No DOM, no framework.",
5
5
  "keywords": [
6
6
  "animation",
7
7
  "motion",