@n-uf/motion 26.11.64 → 26.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/browser.d.ts +4 -4
  3. package/dist/browser.js +2 -2
  4. package/dist/{chunk-G5EJSZ3B.js → chunk-BCFPSDOQ.js} +6 -1
  5. package/dist/chunk-BCFPSDOQ.js.map +1 -0
  6. package/dist/{chunk-B53X43GW.js → chunk-F5FNGVQT.js} +6 -5
  7. package/dist/chunk-F5FNGVQT.js.map +1 -0
  8. package/dist/{chunk-K6TAWCGL.js → chunk-GDV76P2H.js} +63 -9
  9. package/dist/chunk-GDV76P2H.js.map +1 -0
  10. package/dist/{chunk-NI7JLDWZ.js → chunk-I4TKJWCD.js} +2 -2
  11. package/dist/chunk-I4TKJWCD.js.map +1 -0
  12. package/dist/{chunk-ALYH6YQK.js → chunk-MTSGXDVI.js} +60 -6
  13. package/dist/chunk-MTSGXDVI.js.map +1 -0
  14. package/dist/{chunk-5EMLVHP3.js → chunk-QZJLWSPO.js} +49 -2
  15. package/dist/chunk-QZJLWSPO.js.map +1 -0
  16. package/dist/{chunk-RWDYRT3H.js → chunk-TJC6AXFM.js} +12 -2
  17. package/dist/chunk-TJC6AXFM.js.map +1 -0
  18. package/dist/clock.d.ts +3 -3
  19. package/dist/clock.js +1 -1
  20. package/dist/drag.js +2 -2
  21. package/dist/{frame-loop-f0V4b464.d.ts → frame-loop-DjAXTSO9.d.ts} +7 -1
  22. package/dist/gestures.d.ts +3 -3
  23. package/dist/gestures.js +6 -2
  24. package/dist/index.d.ts +5 -5
  25. package/dist/index.js +11 -7
  26. package/dist/layout.d.ts +5 -5
  27. package/dist/layout.js +2 -2
  28. package/dist/{motion-sElR1A_c.d.ts → motion--ql49201.d.ts} +44 -10
  29. package/dist/{paged-swipe-CIzjr2DQ.d.ts → paged-swipe-DUfi6V9F.d.ts} +71 -2
  30. package/dist/{port-CmlUctqx.d.ts → port-DOxLK9GR.d.ts} +9 -1
  31. package/dist/{settle-7C9xxbFg.d.ts → settle-BvkDVDhE.d.ts} +39 -9
  32. package/dist/values.d.ts +10 -6
  33. package/dist/values.js +2 -2
  34. package/package.json +1 -1
  35. package/dist/chunk-5EMLVHP3.js.map +0 -1
  36. package/dist/chunk-ALYH6YQK.js.map +0 -1
  37. package/dist/chunk-B53X43GW.js.map +0 -1
  38. package/dist/chunk-G5EJSZ3B.js.map +0 -1
  39. package/dist/chunk-K6TAWCGL.js.map +0 -1
  40. package/dist/chunk-NI7JLDWZ.js.map +0 -1
  41. package/dist/chunk-RWDYRT3H.js.map +0 -1
@@ -3,7 +3,7 @@ import {
3
3
  createSettle,
4
4
  popIn,
5
5
  reveal
6
- } from "./chunk-ALYH6YQK.js";
6
+ } from "./chunk-MTSGXDVI.js";
7
7
 
8
8
  // src/layout/motion.ts
9
9
  var same = (a, b) => Math.abs(a.x - b.x) < 0.01 && Math.abs(a.y - b.y) < 0.01 && Math.abs(a.width - b.width) < 0.01 && Math.abs(a.height - b.height) < 0.01;
@@ -28,6 +28,34 @@ function createLayoutMotion(options) {
28
28
  const { onDraw, onActiveChange } = options;
29
29
  const drawers = /* @__PURE__ */ new Map();
30
30
  const dirty = /* @__PURE__ */ new Set();
31
+ const unseen = /* @__PURE__ */ new Map();
32
+ let seeing = null;
33
+ const ended = () => loop.framesEnded;
34
+ const sawFrame = () => {
35
+ seeing = null;
36
+ };
37
+ const jumped = (id) => {
38
+ if (reduced()) return;
39
+ unseen.set(id, onDraw ? null : ended());
40
+ if (!onDraw && !seeing) seeing = loop.schedule("write", sawFrame);
41
+ };
42
+ const isUnseen = (id) => {
43
+ const at = unseen.get(id);
44
+ if (at === void 0) return false;
45
+ if (at === null || at === ended()) return true;
46
+ unseen.delete(id);
47
+ return false;
48
+ };
49
+ const seen = (id) => {
50
+ unseen.delete(id);
51
+ if (!seeing) return;
52
+ const now = ended();
53
+ for (const [other, at] of unseen) if (at !== null && at !== now) unseen.delete(other);
54
+ if (unseen.size === 0) {
55
+ seeing();
56
+ seeing = null;
57
+ }
58
+ };
31
59
  const setActive = (on) => {
32
60
  if (on === active) return;
33
61
  active = on;
@@ -45,6 +73,7 @@ function createLayoutMotion(options) {
45
73
  for (const id of dirty) {
46
74
  const entry = drawers.get(id)?.();
47
75
  if (entry) batch.push(entry);
76
+ if (unseen.get(id) === null) unseen.set(id, ended());
48
77
  }
49
78
  dirty.clear();
50
79
  if (batch.length > 0) onDraw(batch);
@@ -131,6 +160,10 @@ function createLayoutMotion(options) {
131
160
  },
132
161
  moveTo(to) {
133
162
  if (same(box, to) && same(rect.target, to)) return;
163
+ if (isUnseen(id)) {
164
+ item.jumpTo(to);
165
+ return;
166
+ }
134
167
  layOut(to);
135
168
  draw();
136
169
  if (same(rect.target, to)) return;
@@ -142,22 +175,31 @@ function createLayoutMotion(options) {
142
175
  return;
143
176
  }
144
177
  if (same(rect.target, to)) return;
178
+ if (isUnseen(id)) {
179
+ rect.jumpTo(copy(to));
180
+ draw();
181
+ jumped(id);
182
+ return;
183
+ }
145
184
  aim(to);
146
185
  },
147
186
  jumpTo(to) {
148
187
  layOut(to);
149
188
  rect.jumpTo(copy(to));
150
189
  draw();
190
+ jumped(id);
151
191
  },
152
192
  glideFrom(from, to) {
153
193
  rect.jumpTo(copy(from));
154
194
  layOut(to);
155
195
  draw();
156
196
  aim(to);
197
+ seen(id);
157
198
  },
158
199
  hold(r) {
159
200
  rect.jumpTo(copy(r));
160
201
  draw();
202
+ seen(id);
161
203
  },
162
204
  show(on, o = {}) {
163
205
  const want = on ? 1 : 0;
@@ -174,6 +216,7 @@ function createLayoutMotion(options) {
174
216
  drawable.layOut(box);
175
217
  draw();
176
218
  items.set(id, item);
219
+ jumped(id);
177
220
  tempos.add(tempo);
178
221
  steps.set(id, (dt) => {
179
222
  const a = rect.step(dt);
@@ -194,6 +237,7 @@ function createLayoutMotion(options) {
194
237
  steps.delete(id);
195
238
  removers.get(id)?.();
196
239
  removers.delete(id);
240
+ seen(id);
197
241
  }
198
242
  return {
199
243
  add,
@@ -232,6 +276,9 @@ function createLayoutMotion(options) {
232
276
  frames.clear();
233
277
  tempos.clear();
234
278
  removers.clear();
279
+ unseen.clear();
280
+ seeing?.();
281
+ seeing = null;
235
282
  const resolve = waiters;
236
283
  waiters = [];
237
284
  for (const r of resolve) r();
@@ -380,4 +427,4 @@ export {
380
427
  MORPH_TEMPO,
381
428
  anchoredMorph
382
429
  };
383
- //# sourceMappingURL=chunk-5EMLVHP3.js.map
430
+ //# sourceMappingURL=chunk-QZJLWSPO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/layout/motion.ts","../src/layout/held.ts","../src/layout/anchored.ts"],"sourcesContent":["import type { FrameInfo, FrameLoop, Phase } from \"../clock/frame-loop\";\nimport type { Rect } from \"../shapes\";\nimport { popIn, reveal, type PopIn, type RevealFrame } from \"../values/reveal\";\nimport { createSettle, SETTLE_TEMPO, type Settle } from \"../values/settle\";\n\n/**\n * What a {@link Drawable} draws on a frame: where the item is drawn, the box its content is laid out in, how to draw\n * the one at the other without stretching ({@link reveal}), and its appearance ({@link popIn}).\n */\nexport interface DrawFrame {\n /** Where the item is drawn this frame (its frame: background, border, shadow). */\n readonly drawn: Rect;\n /** The box its content is laid out in: where it is heading, or (held) where it was laid out last. */\n readonly box: Rect;\n /** How to draw `box`'s content at `drawn`: a move, the frame at the drawn size, the content clipped. */\n readonly reveal: RevealFrame;\n /** Its uniform appearance: scale about its center and opacity. */\n readonly pop: PopIn;\n /** How shown it is, 0 (gone) to 1. */\n readonly shown: number;\n /** All the way gone: hidden and at rest (out of sight and out of the way of the pointer). */\n readonly gone: boolean;\n}\n\n/**\n * How an item reaches the screen. The layout motion never measures or touches anything itself: it lays an item's\n * content out once per new box and draws it once per frame through this. {@link domDrawable} writes an element's\n * style; a canvas or a test can draw anything else.\n */\nexport interface Drawable {\n /** Lay the content out in `box` (its position and size): called once per new box, never per frame. */\n layOut(box: Rect): void;\n /** Draw the item for this frame. */\n draw(frame: DrawFrame): void;\n}\n\n/**\n * One item the layout motion moves: give it a new place and it settles there from wherever it is drawn, once a frame\n * has shown it there.\n *\n * - {@link LayoutItem.moveTo}: a settle to the new place, retargeted from the drawn rect (no jump, no overshoot);\n * the content is laid out at the new box at once and the item redrawn at once, so no frame shows the old offset\n * from the new box.\n * - Seen: a rect placed by a jump ({@link LayoutMotion.add}, {@link LayoutItem.jumpTo}) is seen once a frame of the\n * loop has ended after it reached the screen (drawn; batched, written). A new target before that is a jump too: no\n * frame showed the rect a glide would start from, so the first frame shows the final place. `jumpTo` and `add` say\n * \"be here\", and motion checks them; `hold` and `glideFrom` say \"it is on screen here\", and motion believes them.\n * - A size change is revealed: the content is laid out at the target size and the frame clipped, never scaled.\n * - {@link LayoutItem.show}: appear or disappear with a uniform-scale fade.\n */\nexport interface LayoutItem {\n readonly id: string;\n /** Where it is drawn now. */\n readonly drawn: Rect;\n /** Where it is heading (its settle's target). */\n readonly target: Rect;\n /** The box its content is laid out in. */\n readonly box: Rect;\n /** At rest on its target. */\n readonly settled: boolean;\n /** How shown it is, 0 to 1, and whether it is heading for shown. */\n readonly shown: number;\n readonly showing: boolean;\n /** Its appearance is at rest (fully shown, or gone). */\n readonly shownSettled: boolean;\n /**\n * Settle to `to` from where it is drawn; lays the content out at `to` and redraws at once. While the drawn rect was\n * placed by a jump and is not seen yet, this is a jump to `to` instead.\n */\n moveTo(to: Rect): void;\n /**\n * Settle to `to` from where it is drawn, like {@link LayoutItem.moveTo}, but keep the content laid out in its box\n * while `to` is the box's size: for chasing a moving point (a pointer), which would otherwise lay the content out\n * again on every frame. A new size lays it out at `to`, as `moveTo` does. Optional, so an item from before it (or\n * a test double) still works where it is used: {@link holdItem} falls back to `moveTo`. `createLayoutMotion`'s\n * items always have it. Before a jumped rect is seen, a jump, as for `moveTo`.\n */\n retarget?(to: Rect): void;\n /**\n * Be at `to` now, at rest: no glide. `jumpTo` and `add` say \"be here\", and motion checks them; `hold` and\n * `glideFrom` say \"it is on screen here\", and motion believes them: `to` is seen once a frame has ended after it,\n * and a target given before that jumps too.\n */\n jumpTo(to: Rect): void;\n /**\n * Drawn at `from` now, then settle to `to` (a FLIP's invert and play: `from` in the item's own coordinates). The way\n * to animate an entrance. `jumpTo` and `add` say \"be here\", and motion checks them; `hold` and `glideFrom` say \"it\n * is on screen here\", and motion believes them: `from` counts as seen, and a new target glides on from the drawn\n * rect.\n */\n glideFrom(from: Rect, to: Rect): void;\n /**\n * Exactly at `r`, at rest (what a pointer holds); the content stays laid out in its box, moved with it. `jumpTo` and\n * `add` say \"be here\", and motion checks them; `hold` and `glideFrom` say \"it is on screen here\", and motion believes\n * them: `r` counts as seen, and a drop right after it glides. Never hold a rect that was not on screen to get a glide.\n */\n hold(r: Rect): void;\n /** Appear (true) or disappear (false) with a uniform-scale fade; `now`: without the fade. */\n show(on: boolean, options?: { readonly now?: boolean }): void;\n /** Draw it again now (after its drawable's element was laid out anew from outside). */\n redraw(): void;\n}\n\n/** A task the layout motion runs on every frame before it steps the items; true keeps the frames coming. */\nexport type LayoutTask = (frame: FrameInfo) => boolean | void;\n\n/** One item's frame in a batch ({@link LayoutMotionOptions.onDraw}). */\nexport interface DrawEntry {\n readonly id: string;\n readonly frame: DrawFrame;\n}\n\nexport interface LayoutMotionOptions {\n /** The frame loop every item steps on (one loop for all of them). */\n readonly loop: FrameLoop;\n /** The settle tempo, per second ({@link SETTLE_TEMPO}); default `SETTLE_TEMPO.default`. */\n readonly omega?: number;\n /** The frame phase the items step and draw in; default `\"layout\"`. */\n readonly phase?: Phase;\n /** Where an appearing item grows from, as a share of its size ({@link popIn}'s `from`); default 0.87. */\n readonly popFrom?: number;\n /**\n * Reduced motion: read on every new target and every show or hide. While true an item is placed on its new\n * target at once (no glide) and appears or disappears at once (no fade). A boolean, or the host's query (such as\n * the reduced-motion media query). Default false.\n */\n readonly reducedMotion?: boolean | (() => boolean);\n /**\n * Batched drawing: every item that changed is drawn in one pass per frame, after the items step: each one's\n * drawable, then this, once, with all of their frames. Changes made between frames (a new target, a hold) are\n * drawn on the next frame, or now by {@link LayoutMotion.flush}. Without it, each item is drawn as it changes.\n */\n readonly onDraw?: (batch: readonly DrawEntry[]) => void;\n /**\n * Called when frames start running (true) and when they stop (false: nothing moves any more), once per change, and\n * with false on `dispose` while they run. The one way to learn that the layout is idle; a test awaits\n * {@link LayoutMotion.idle} instead.\n */\n readonly onActiveChange?: (active: boolean) => void;\n}\n\n/**\n * Layout motion: items with an id and a target rect, each settled to its place on one shared frame loop.\n *\n * Give an item a new place ({@link LayoutItem.moveTo}) and it glides there from wherever it is drawn: the window\n * motion rules of `values/` (settle, reveal, popIn) applied to every item at once. The loop runs only while\n * something moves, or a task asks for frames, and stops by itself.\n *\n * A rect placed by a jump glides on only once it is seen: a frame of the loop has ended after it reached the screen\n * (see {@link LayoutItem}). An unbatched jump asks the loop for that one frame as a task, once per burst of jumps:\n * `loop.active` and the loop's queue count show it, as they show any scheduled task, but it is not a movement, so\n * `onActiveChange` is not called and {@link LayoutMotion.idle} does not wait for it. \"Seen\" is the clock's word: a\n * frame is the clock's statement that what was drawn before it ended is now presented (`ClockPort.requestFrame`).\n *\n * It only animates the rects it is given: which items move where, and when, is the caller's layout.\n */\nexport interface LayoutMotion {\n /**\n * Add an item drawn by `drawable`, at `at`, shown (or gone: `{ shown: false }`). Its content is laid out at once.\n * `jumpTo` and `add` say \"be here\", and motion checks them; `hold` and `glideFrom` say \"it is on screen here\", and\n * motion believes them: a target given before a frame has seen `at` is a jump. To animate an entrance, add it at its\n * place and {@link LayoutItem.glideFrom} where it comes from.\n */\n add(id: string, drawable: Drawable, at: Rect, options?: { readonly shown?: boolean }): LayoutItem;\n get(id: string): LayoutItem | undefined;\n /** Stop moving an item (its drawable is not touched again). */\n remove(id: string): void;\n /** Remove every item whose id is not in `ids` (the ones that left the layout). */\n retain(ids: Iterable<string>): void;\n /**\n * With {@link LayoutMotionOptions.onDraw}: draw the items changed since the last frame now, outside the loop. A\n * host calls it right after it commits a new layout, so the next paint shows every item where it is drawn, not a\n * frame at its new box. Without batching each item is already drawn as it changes, and it does nothing. It hands\n * the batch to the host but ends no frame: a jump flushed and then given a target still jumps.\n */\n flush(): void;\n readonly items: ReadonlyMap<string, LayoutItem>;\n /** Run `task` on every frame, before the items step; returns how to stop it. */\n task(task: LayoutTask): () => void;\n /** Call `listener` on every frame, after the items have stepped and been drawn; returns how to stop it. */\n onFrame(listener: (frame: FrameInfo) => void): () => void;\n /** Make sure at least one more frame runs (a task has something to do). */\n wake(): void;\n /** Set the tempo for every item (and the ones added later). */\n configure(config: { readonly omega?: number }): void;\n /**\n * Resolves once nothing moves (at once if nothing does): for a test. A host learns it from\n * {@link LayoutMotionOptions.onActiveChange}. Right after a jump it resolves at once, before the frame that sees the\n * jump: a target given then is still a jump. A test that means \"drawn and seen\" runs a frame (`clock.frame()`).\n */\n idle(): Promise<void>;\n /** Stop the frames and forget every item. */\n dispose(): void;\n}\n\n/** Two rects the same within a hundredth of a pixel. */\nconst same = (a: Rect, b: Rect): boolean =>\n Math.abs(a.x - b.x) < 0.01 && Math.abs(a.y - b.y) < 0.01 && Math.abs(a.width - b.width) < 0.01 && Math.abs(a.height - b.height) < 0.01;\nconst copy = (r: Rect): Rect => ({ x: r.x, y: r.y, width: r.width, height: r.height });\n\n/** Create the {@link LayoutMotion} for one surface. */\nexport function createLayoutMotion(options: LayoutMotionOptions): LayoutMotion {\n const { loop } = options;\n const phase = options.phase ?? \"layout\";\n const popFrom = options.popFrom ?? 0.87;\n let omega = options.omega ?? SETTLE_TEMPO.default;\n const items = new Map<string, LayoutItem>();\n const steps = new Map<string, (dt: number) => boolean>();\n const tasks = new Set<LayoutTask>();\n const frames = new Set<(frame: FrameInfo) => void>();\n const tempos = new Set<() => void>();\n /** What removing an item undoes besides its entry (its tempo hook). */\n const removers = new Map<string, () => void>();\n let waiters: (() => void)[] = [];\n let stop: (() => void) | null = null;\n let woken = false;\n let ticking = false;\n let active = false;\n const reduced = (): boolean => (typeof options.reducedMotion === \"function\" ? options.reducedMotion() : options.reducedMotion === true);\n const { onDraw, onActiveChange } = options;\n /** Batched drawing: how to draw each item, and the ones that changed since the last batch. */\n const drawers = new Map<string, () => DrawEntry>();\n const dirty = new Set<string>();\n /**\n * Items whose drawn rect was placed by a jump and is not seen yet: the count of the loop's ended frames when the\n * rect reached the screen (unbatched: drawn at the jump; batched: written by a batch), or null while no batch has\n * written it. The loop counts a frame only after all of its phases ran, so the rect is seen once that count has\n * grown, and a target later in the same frame, in any phase or order, still jumps. The count is `framesEnded`,\n * which `resetStats()` never touches.\n */\n const unseen = new Map<string, number | null>();\n /** Cancels the frame asked for to see the unbatched jumps, while it is pending. */\n let seeing: (() => void) | null = null;\n const ended = (): number => loop.framesEnded;\n /** The one function the frame to see jumps runs, so a burst of jumps queues one task. */\n const sawFrame = (): void => {\n seeing = null;\n };\n /** A rect placed by a jump (\"be here\"). Under reduced motion every target is a jump already: nothing to record. */\n const jumped = (id: string): void => {\n if (reduced()) return;\n unseen.set(id, onDraw ? null : ended());\n if (!onDraw && !seeing) seeing = loop.schedule(\"write\", sawFrame);\n };\n const isUnseen = (id: string): boolean => {\n const at = unseen.get(id);\n if (at === undefined) return false;\n if (at === null || at === ended()) return true;\n unseen.delete(id);\n return false;\n };\n /**\n * The caller says it is on screen (`hold`, `glideFrom`), or it left. When no jump is left to see, the frame asked\n * for them is cancelled, so a loop shared with other work isn't kept busy by this one.\n */\n const seen = (id: string): void => {\n unseen.delete(id);\n if (!seeing) return;\n const now = ended();\n for (const [other, at] of unseen) if (at !== null && at !== now) unseen.delete(other);\n if (unseen.size === 0) {\n seeing();\n seeing = null;\n }\n };\n\n const setActive = (on: boolean): void => {\n if (on === active) return;\n active = on;\n onActiveChange?.(on);\n };\n\n const wake = (): void => {\n woken = true;\n if (stop) return;\n stop = loop.repeat(phase, tick);\n setActive(true);\n };\n\n /** Draw every item that changed, then hand the batch over once. */\n function writeBatch(): void {\n if (!onDraw || dirty.size === 0) return;\n const batch: DrawEntry[] = [];\n for (const id of dirty) {\n const entry = drawers.get(id)?.();\n if (entry) batch.push(entry);\n // A jumped rect reaches the screen when a batch writes it.\n if (unseen.get(id) === null) unseen.set(id, ended());\n }\n dirty.clear();\n if (batch.length > 0) onDraw(batch);\n }\n\n function tick(frame: FrameInfo): boolean {\n let moving = woken;\n woken = false;\n ticking = true;\n for (const task of [...tasks]) if (task(frame)) moving = true;\n for (const step of [...steps.values()]) if (step(frame.delta)) moving = true;\n writeBatch();\n ticking = false;\n for (const listener of [...frames]) listener(frame);\n if (moving || woken) return true;\n stop = null;\n setActive(false);\n const resolve = waiters;\n waiters = [];\n for (const r of resolve) r();\n return false;\n }\n\n function add(id: string, drawable: Drawable, at: Rect, opts: { readonly shown?: boolean } = {}): LayoutItem {\n if (items.has(id)) throw new Error(`layout motion: item \"${id}\" is already added (remove it first)`);\n const rect: Settle<Rect> = createSettle<Rect>(copy(at), { omega });\n // A number from 0 to 1: rest within a thousandth, not the default tenth (tuned for pixels).\n const pop: Settle<number> = createSettle(opts.shown === false ? 0 : 1, { omega, restDelta: 0.001 });\n let box = copy(at);\n const frameOf = (): DrawFrame => {\n const drawn = rect.value;\n return { drawn, box, reveal: reveal(drawn, box), pop: popIn(pop.value, popFrom), shown: pop.value, gone: pop.settled && pop.value === 0 };\n };\n const drawNow = (): DrawEntry => {\n const frame = frameOf();\n drawable.draw(frame);\n return { id, frame };\n };\n // Batched: mark it changed (the batch draws it); a change between frames asks for a frame to draw it in.\n const draw = (): void => {\n if (!onDraw) {\n drawNow();\n return;\n }\n dirty.add(id);\n if (!ticking) wake();\n };\n const layOut = (to: Rect): void => {\n box = copy(to);\n drawable.layOut(box);\n };\n /** Head for `to`: a settle from the drawn rect, or (reduced motion) there at once. */\n const aim = (to: Rect): void => {\n if (reduced()) {\n rect.jumpTo(copy(to));\n draw();\n return;\n }\n rect.setTarget(copy(to));\n wake();\n };\n /** It moved on the last step (so the step that brings it to rest still draws it, batched). */\n let moved = false;\n const tempo = (): void => {\n rect.configure({ omega });\n pop.configure({ omega });\n };\n const item: LayoutItem = {\n id,\n get drawn() {\n return rect.value;\n },\n get target() {\n return rect.target;\n },\n get box() {\n return box;\n },\n get settled() {\n return rect.settled;\n },\n get shown() {\n return pop.value;\n },\n get showing() {\n return pop.target === 1;\n },\n get shownSettled() {\n return pop.settled;\n },\n moveTo(to) {\n if (same(box, to) && same(rect.target, to)) return;\n // Placed by a jump and not seen yet: no frame showed where a glide would start, so this is a jump too.\n if (isUnseen(id)) {\n item.jumpTo(to);\n return;\n }\n layOut(to);\n // Laid out in the new box now: draw it at once at the drawn rect, else until the next frame it would show\n // the old offset from the new box (a dropped item would flash a frame away from where it was let go).\n draw();\n if (same(rect.target, to)) return;\n aim(to);\n },\n retarget(to) {\n if (to.width !== box.width || to.height !== box.height) {\n item.moveTo(to);\n return;\n }\n if (same(rect.target, to)) return;\n // Not seen yet: a jump, keeping the content laid out in its box as a retarget does.\n if (isUnseen(id)) {\n rect.jumpTo(copy(to));\n draw();\n jumped(id);\n return;\n }\n aim(to);\n },\n jumpTo(to) {\n layOut(to);\n rect.jumpTo(copy(to));\n draw();\n jumped(id);\n },\n glideFrom(from, to) {\n rect.jumpTo(copy(from));\n layOut(to);\n draw();\n aim(to);\n // The caller's word: `from` is on screen.\n seen(id);\n },\n hold(r) {\n rect.jumpTo(copy(r));\n draw();\n // The caller's word: `r` is on screen (where the pointer holds it), so a drop right after it glides.\n seen(id);\n },\n show(on, o = {}) {\n const want = on ? 1 : 0;\n if (o.now || reduced()) pop.jumpTo(want);\n else if (pop.target !== want) {\n pop.setTarget(want);\n wake();\n }\n draw();\n },\n redraw: draw,\n };\n drawers.set(id, drawNow);\n drawable.layOut(box);\n draw();\n items.set(id, item);\n // Placed at once: an add says \"be here\", like a jump.\n jumped(id);\n tempos.add(tempo);\n steps.set(id, (dt) => {\n const a = rect.step(dt);\n const b = pop.step(dt);\n // Batched, only an item that moved is drawn; else every item, every frame.\n if (!onDraw || a || b || moved) draw();\n moved = a || b;\n return a || b;\n });\n removers.set(id, () => {\n tempos.delete(tempo);\n drawers.delete(id);\n dirty.delete(id);\n });\n return item;\n }\n\n function remove(id: string): void {\n items.delete(id);\n steps.delete(id);\n removers.get(id)?.();\n removers.delete(id);\n seen(id);\n }\n\n return {\n add,\n get: (id) => items.get(id),\n remove,\n retain(ids) {\n const keep = new Set(ids);\n for (const id of [...items.keys()]) if (!keep.has(id)) remove(id);\n },\n flush: writeBatch,\n items,\n task(task) {\n tasks.add(task);\n wake();\n return () => tasks.delete(task);\n },\n onFrame(listener) {\n frames.add(listener);\n return () => frames.delete(listener);\n },\n wake,\n configure(config) {\n if (config.omega !== undefined) omega = config.omega;\n for (const t of tempos) t();\n },\n idle: () => (stop ? new Promise<void>((r) => waiters.push(r)) : Promise.resolve()),\n dispose() {\n stop?.();\n stop = null;\n setActive(false);\n items.clear();\n steps.clear();\n drawers.clear();\n dirty.clear();\n tasks.clear();\n frames.clear();\n tempos.clear();\n removers.clear();\n unseen.clear();\n seeing?.();\n seeing = null;\n const resolve = waiters;\n waiters = [];\n for (const r of resolve) r();\n },\n };\n}\n","import type { Point, Rect } from \"../shapes\";\nimport type { LayoutItem } from \"./motion\";\n\n/**\n * An item held by a pointer: the real item (no copy) follows the pointer 1:1 from where it was grabbed, at the size\n * it was lifted at; its place stays reserved (that is the caller's layout). Then:\n *\n * - {@link HeldDrag.snapTo}: glide into a slot (a snap preview); `null` leaves the slot and glides back to the\n * pointer, following it as it moves ({@link HeldDrag.follow} once a frame), until it is under it again.\n * - {@link HeldDrag.land}: let go into a slot: the landing settles from where it was let go (the release rect), never\n * from its old home. Snapped into that slot already, it simply finishes that glide.\n * - {@link HeldDrag.cancel}: let go with no drop: it glides home from where it was let go.\n * - {@link HeldDrag.preview}: the three drop previews, per frame: indicator and gap keep the item under the pointer\n * (gap with the caller's room open), snap glides it into the slot; leaving glides it back to the pointer.\n * - {@link HeldDrag.resize}: the item takes a new size mid-drag (its content laid out anew by the caller), held at the\n * caller's `grab` in it where given: it settles to it from where it is drawn, the size revealed (never stretched),\n * and is held 1:1 again once there.\n */\nexport interface HeldDrag {\n /** Where the pointer is (null before the first move). */\n readonly pointer: Point | null;\n /** Where the pointer holds the item: the pointer less the grab offset, at the held size (lifted, or resized). */\n readonly held: Rect | null;\n /** The slot it sits in (a snap), or null. */\n readonly snapped: Rect | null;\n /** It left a slot (or took a new size) and is gliding back to the pointer. */\n readonly returning: boolean;\n /** The pointer moved: held 1:1 (unless it sits in a slot or is on its way back). */\n move(pointer: Point): void;\n /**\n * Into `slot` (a glide from where it is drawn; the same slot again does nothing), or out of the slot it sits in\n * (`null`: back to the pointer). Returns what changed: `\"snapped\"`, `\"left\"`, or null.\n */\n snapTo(slot: Rect | null): \"snapped\" | \"left\" | null;\n /** Once a frame: on its way back, retarget to the pointer; true on the frame it is under the pointer again. */\n follow(): boolean;\n /**\n * Once a frame, a drop preview's part for the item (`plan`: `@n-uf/motion/drag`'s `previewPlan`, or any\n * `{ snapItem }`): with `snapItem` it glides into `slot` (snap); else it stays under the pointer, or glides back to\n * it from a slot it left (indicator, gap). The room, if the plan makes any, is the caller's layout. In place of\n * {@link HeldDrag.snapTo} and {@link HeldDrag.follow}; returns what changed.\n */\n preview(plan: { readonly snapItem: boolean }, slot: Rect | null): \"snapped\" | \"left\" | null;\n /**\n * Hold it at `size` from now on (the caller has laid its content out for that size), the pointer holding it at `grab`\n * (px from the top-left corner at that size: where the caller's new form puts the spot the user pressed, a docking\n * drag's `DockAfter.grab`). Without `grab` the grab point keeps its share of the item. The item settles from where it\n * is drawn to its new held rect, the pointer less `grab` at `size` (its size revealed, never stretched): the held\n * point moves with the size on that one settle, so a still pointer sees both arrive together. Then it is held 1:1\n * again ({@link HeldDrag.follow} once a frame). In a slot it stays there, taking the new size when it leaves. The same\n * size and grab again do nothing; returns true on a change.\n */\n resize(size: { readonly width: number; readonly height: number }, grab?: Point): boolean;\n /** Where the pointer holds the item now, px from its top-left corner at the held size (the lift's, or the last resize's). */\n readonly grab: Point;\n /** Let go into `slot`: returns the release rect, where the landing starts. */\n land(slot: Rect): Rect;\n /** Let go with no drop: glides `home` from the release rect, which it returns. */\n cancel(home: Rect): Rect;\n}\n\n/** How close (px, every component) the way back has to come to count as under the pointer again. */\nconst CAUGHT = 0.5;\n\n/** Hold `item` from the pointer at `grab` (the pointer's offset from its top-left corner), at its drawn size now. */\nexport function holdItem(item: LayoutItem, grab: Point): HeldDrag {\n let size = { width: item.drawn.width, height: item.drawn.height };\n let at = { x: grab.x, y: grab.y };\n let pointer: Point | null = null;\n let snapped: Rect | null = null;\n let returning = false;\n const heldRect = (): Rect | null => (pointer ? { x: pointer.x - at.x, y: pointer.y - at.y, width: size.width, height: size.height } : null);\n const same = (a: Rect, b: Rect): boolean => Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y), Math.abs(a.width - b.width), Math.abs(a.height - b.height)) < 0.01;\n const snapTo = (slot: Rect | null): \"snapped\" | \"left\" | null => {\n if (slot) {\n if (snapped && same(snapped, slot)) return null;\n snapped = { ...slot };\n returning = false;\n item.moveTo(slot);\n return \"snapped\";\n }\n if (!snapped) return null;\n snapped = null;\n returning = true;\n return \"left\";\n };\n const follow = (): boolean => {\n const goal = heldRect();\n if (!returning || !goal) return false;\n // A chase of the pointer: retargeted every frame, laid out again only when its size changes (an item without\n // retarget, from before it or a test double, moves to it).\n if (item.retarget) item.retarget(goal);\n else item.moveTo(goal);\n const d = item.drawn;\n if (Math.max(Math.abs(d.x - goal.x), Math.abs(d.y - goal.y), Math.abs(d.width - goal.width), Math.abs(d.height - goal.height)) >= CAUGHT) return false;\n returning = false;\n item.hold(goal);\n return true;\n };\n const letGo = (to: Rect): Rect => {\n const release = { ...item.drawn };\n snapped = null;\n returning = false;\n item.moveTo(to);\n return release;\n };\n return {\n get pointer() {\n return pointer;\n },\n get held() {\n return heldRect();\n },\n get snapped() {\n return snapped;\n },\n get returning() {\n return returning;\n },\n move(p) {\n pointer = { x: p.x, y: p.y };\n if (snapped || returning) return;\n item.hold(heldRect()!);\n },\n snapTo,\n follow,\n preview(plan, slot) {\n const change = snapTo(plan.snapItem && slot ? slot : null);\n follow();\n return change;\n },\n get grab() {\n return { x: at.x, y: at.y };\n },\n resize(next, grab) {\n const sameSize = Math.abs(next.width - size.width) < 0.01 && Math.abs(next.height - size.height) < 0.01;\n if (sameSize && (!grab || (Math.abs(grab.x - at.x) < 0.01 && Math.abs(grab.y - at.y) < 0.01))) return false;\n // The caller's grab in the new form, else the old one's share of the item.\n at = grab ? { x: grab.x, y: grab.y } : { x: size.width ? (at.x / size.width) * next.width : 0, y: size.height ? (at.y / size.height) * next.height : 0 };\n size = { width: next.width, height: next.height };\n if (!snapped && pointer) {\n returning = true;\n follow();\n }\n return true;\n },\n land: letGo,\n cancel: letGo,\n };\n}\n","import type { Point, Rect } from \"../shapes\";\nimport { createSettle, SETTLE_TEMPO, type SettleConfig } from \"../values/settle\";\n\n/** A width and a height, px. */\nexport interface BoxSize {\n readonly width: number;\n readonly height: number;\n}\n\n/**\n * A box held at a point that changes size about an anchor: the anchor is the spot of the box that sits on the point\n * (a pointer's offset from the box's top-left corner). Its size and its anchor settle together to a new size and the\n * new box's anchor ({@link AnchoredMorph.to}), from wherever they are drawn, so a retarget mid-flight turns at once,\n * with no jump and no overshoot. At every step the anchor lies exactly on the point ({@link AnchoredMorph.rectAt}): a\n * caller who draws the old and the new content each with its own anchor on the point never moves either from under\n * the pointer, and fades between them by {@link AnchoredMorph.progress}.\n */\nexport interface AnchoredMorph {\n /** The size now. */\n readonly size: BoxSize;\n /** The anchor now: its offset from the box's top-left corner. */\n readonly anchor: Point;\n /** Where it is heading. */\n readonly target: { readonly size: BoxSize; readonly anchor: Point };\n /** At rest on the target. */\n readonly settled: boolean;\n /**\n * How far along the way from where the last retarget started to the target, 0 to 1 (1 at rest): to fade the content\n * it came from out and the target's in.\n */\n readonly progress: number;\n /** Head for `size` with `anchor` from where it is drawn. The same target again does nothing; true on a change. */\n to(size: BoxSize, anchor: Point): boolean;\n /** Be at `size` with `anchor` now, at rest. */\n jumpTo(size: BoxSize, anchor: Point): void;\n /** Advance by `dt` ms; true while still moving. */\n step(dt: number): boolean;\n /** The box now with its anchor on `point`. */\n rectAt(point: Point): Rect;\n}\n\n/**\n * The default tempo, a quick settle (`SETTLE_TEMPO.quick`): 90 % of the way in about 60 ms, within 1 % in about\n * 125 ms; the last pixels take longer for large size changes (a 300 px change rests after about 225 ms).\n */\nexport const MORPH_TEMPO = SETTLE_TEMPO.quick;\n\n/** A box of `size` held at `anchor`, at rest; `config` is the settle's (default tempo {@link MORPH_TEMPO}). */\nexport function anchoredMorph(size: BoxSize, anchor: Point, config: SettleConfig = {}): AnchoredMorph {\n // One settle over the four numbers, as a rect: x, y the anchor, width and height the size.\n const pack = (s: BoxSize, a: Point): Rect => ({ x: finite(a.x), y: finite(a.y), width: Math.max(0, finite(s.width)), height: Math.max(0, finite(s.height)) });\n const settle = createSettle<Rect>(pack(size, anchor), { omega: MORPH_TEMPO, ...config });\n let from: Rect = settle.value;\n const gap = (a: Rect, b: Rect): number => Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y), Math.abs(a.width - b.width), Math.abs(a.height - b.height));\n return {\n get size() {\n const v = settle.value;\n return { width: v.width, height: v.height };\n },\n get anchor() {\n const v = settle.value;\n return { x: v.x, y: v.y };\n },\n get target() {\n const t = settle.target;\n return { size: { width: t.width, height: t.height }, anchor: { x: t.x, y: t.y } };\n },\n get settled() {\n return settle.settled;\n },\n get progress() {\n const whole = gap(from, settle.target);\n if (settle.settled || whole < 1e-9) return 1;\n return Math.min(1, Math.max(0, 1 - gap(settle.value, settle.target) / whole));\n },\n to(s, a) {\n const goal = pack(s, a);\n if (gap(goal, settle.target) < 0.01) return false;\n from = settle.value;\n settle.setTarget(goal);\n return true;\n },\n jumpTo(s, a) {\n settle.jumpTo(pack(s, a));\n from = settle.value;\n },\n step(dt) {\n return settle.step(dt);\n },\n rect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AG,QAAQ,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,EAAE,EAAE;AAAA,IAClF;AAAA,IACA,IAAI,UAAU;AACZ,aAAO,OAAO;AAAA,IAChB;AAAA,IACA,IAAI,WAAW;AACb,YAAM,QAAQ,IAAI,MAAM,OAAO,MAAM;AACrC,UAAI,OAAO,WAAW,QAAQ,KAAM,QAAO;AAC3C,aAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,IAAI,IAAI,OAAO,OAAO,OAAO,MAAM,IAAI,KAAK,CAAC;AAAA,IAC9E;AAAA,IACA,GAAG,GAAG,GAAG;AACP,YAAM,OAAO,KAAK,GAAG,CAAC;AACtB,UAAI,IAAI,MAAM,OAAO,MAAM,IAAI,KAAM,QAAO;AAC5C,aAAO,OAAO;AACd,aAAO,UAAU,IAAI;AACrB,aAAO;AAAA,IACT;AAAA,IACA,OAAO,GAAG,GAAG;AACX,aAAO,OAAO,KAAK,GAAG,CAAC,CAAC;AACxB,aAAO,OAAO;AAAA,IAChB;AAAA,IACA,KAAK,IAAI;AACP,aAAO,OAAO,KAAK,EAAE;AAAA,IACvB;AAAA,IACA,OAAO,GAAG;AACR,YAAM,IAAI,OAAO;AACjB,aAAO,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,OAAO,QAAQ,EAAE,OAAO;AAAA,IACxE;AAAA,EACF;AACF;AAEA,IAAM,SAAS,CAAC,MAAuB,OAAO,SAAS,CAAC,IAAI,IAAI;","names":["same","grab"]}
@@ -7,8 +7,18 @@ function isHeld(modifiers, key) {
7
7
  return key === "mod" ? !!(modifiers.meta || modifiers.ctrl) : !!modifiers[key];
8
8
  }
9
9
 
10
+ // src/samples.ts
11
+ var SAME_SAMPLE = 1;
12
+ function sampleOrder(newest, t) {
13
+ const dt = t - newest;
14
+ if (dt < 0) return "behind";
15
+ return dt < SAME_SAMPLE ? "same" : "next";
16
+ }
17
+
10
18
  export {
11
19
  DOUBLE_CLICK,
12
- isHeld
20
+ isHeld,
21
+ SAME_SAMPLE,
22
+ sampleOrder
13
23
  };
14
- //# sourceMappingURL=chunk-RWDYRT3H.js.map
24
+ //# sourceMappingURL=chunk-TJC6AXFM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/double-click.ts","../src/keys.ts","../src/samples.ts"],"sourcesContent":["/**\n * A double click: two presses within `ms` of each other (press to press) and `px` of the first. One value for the whole\n * package: the gesture recognizer's `clickCount` (`RECOGNIZER_DEFAULTS.multiClick`) and a grip's double-activate\n * (`createGripPress`) both default to it.\n */\nexport interface DoubleClick {\n readonly ms: number;\n readonly px: number;\n}\n\n/**\n * 500 ms and 5 px: the desktop systems' own default interval (browsers don't expose the user's setting). A host that has\n * the platform's count (a `mousedown`'s `detail`) can pass it to `createGripPress`'s `down` instead.\n */\nexport const DOUBLE_CLICK: DoubleClick = Object.freeze({ ms: 500, px: 5 });\n","/**\n * Modifier keys, the package's one shape for them: the gesture stream's pointers carry `Modifiers`, a drag's samples a\n * partial set of them, and both name a key by `ModifierKey`. Here at the root of `src`, so `./drag` reads them without\n * loading `./gestures`.\n */\n\n/** Pointer modifiers, ctrl included (the drag modifier may be \"ctrl\") */\nexport interface Modifiers {\n shift: boolean;\n alt: boolean;\n meta: boolean;\n ctrl: boolean;\n}\n\n/**\n * A modifier key, the package's one name for it (the recognizer's drag modifier, a drag's float and arm keys): a field\n * of {@link Modifiers}, or `\"mod\"`: ⌘ (meta) or Ctrl, either one held counts, so no platform is needed.\n */\nexport type ModifierKey = keyof Modifiers | \"mod\";\n\n/**\n * Whether `key` is held in `modifiers` (a pointer's, or the keys a drag sample carries; absent fields are not held).\n * `\"mod\"`: ⌘ (meta) or Ctrl, either one. Null: never.\n */\nexport function isHeld(modifiers: Partial<Modifiers> | undefined, key: ModifierKey | null): boolean {\n if (key === null || !modifiers) return false;\n return key === \"mod\" ? !!(modifiers.meta || modifiers.ctrl) : !!modifiers[key];\n}\n","/**\n * How pointer samples are read in time, shared by every estimate of a pointer's speed (the landing model's hand speed,\n * a gesture's release velocity). Internal: not exported from any entry.\n */\n\n/**\n * The shortest interval between two samples that is two samples, ms. A sample under it past the newest one held (a\n * release read a fraction of a millisecond after the last frame, or two timestamps of one frame) is the same sample\n * seen twice: its distance over so short a time says nothing about how fast the pointer moves.\n */\nexport const SAME_SAMPLE = 1;\n\n/**\n * How a sample stamped `t` stands to the newest one held, stamped `newest` (ms): the `next` sample (at least\n * {@link SAME_SAMPLE} past it), the `same` sample (under that past it), or `behind` it (stamped earlier; times are\n * expected never to go back, so one that does is an event's time read against a frame's, or a clock that stepped back).\n * A stamp that is not a number compares as `next`: callers that can get one leave it out first.\n */\nexport function sampleOrder(newest: number, t: number): \"next\" | \"same\" | \"behind\" {\n const dt = t - newest;\n if (dt < 0) return \"behind\";\n return dt < SAME_SAMPLE ? \"same\" : \"next\";\n}\n"],"mappings":";AAcO,IAAM,eAA4B,OAAO,OAAO,EAAE,IAAI,KAAK,IAAI,EAAE,CAAC;;;ACUlE,SAAS,OAAO,WAA2C,KAAkC;AAClG,MAAI,QAAQ,QAAQ,CAAC,UAAW,QAAO;AACvC,SAAO,QAAQ,QAAQ,CAAC,EAAE,UAAU,QAAQ,UAAU,QAAQ,CAAC,CAAC,UAAU,GAAG;AAC/E;;;ACjBO,IAAM,cAAc;AAQpB,SAAS,YAAY,QAAgB,GAAuC;AACjF,QAAM,KAAK,IAAI;AACf,MAAI,KAAK,EAAG,QAAO;AACnB,SAAO,KAAK,cAAc,SAAS;AACrC;","names":[]}
package/dist/clock.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { C as ClockPort, F as FrameSource } from './port-CmlUctqx.js';
2
- export { T as TimerSource } from './port-CmlUctqx.js';
3
- export { F as FrameInfo, a as FrameLoop, b as FrameLoopOptions, c as FrameStats, d as FrameTask, P as PHASES, e as Phase, R as RepeatingTask, S as ScheduleOptions, f as createFrameLoop } from './frame-loop-f0V4b464.js';
1
+ import { C as ClockPort, F as FrameSource } from './port-DOxLK9GR.js';
2
+ export { T as TimerSource } from './port-DOxLK9GR.js';
3
+ export { F as FrameInfo, a as FrameLoop, b as FrameLoopOptions, c as FrameStats, d as FrameTask, P as PHASES, e as Phase, R as RepeatingTask, S as ScheduleOptions, f as createFrameLoop } from './frame-loop-DjAXTSO9.js';
4
4
 
5
5
  /** Options of {@link createFakeClock}. */
6
6
  interface FakeClockOptions {
package/dist/clock.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  createFakeClock,
4
4
  createFrameCoalescer,
5
5
  createFrameLoop
6
- } from "./chunk-G5EJSZ3B.js";
6
+ } from "./chunk-BCFPSDOQ.js";
7
7
  export {
8
8
  PHASES,
9
9
  createFakeClock,
package/dist/drag.js CHANGED
@@ -19,10 +19,10 @@ import {
19
19
  pickRank,
20
20
  previewPlan,
21
21
  targetAt
22
- } from "./chunk-B53X43GW.js";
22
+ } from "./chunk-F5FNGVQT.js";
23
23
  import {
24
24
  isHeld
25
- } from "./chunk-RWDYRT3H.js";
25
+ } from "./chunk-TJC6AXFM.js";
26
26
  export {
27
27
  DRAG_DEFAULTS,
28
28
  DRAG_PREVIEW_DEFAULT,
@@ -1,4 +1,4 @@
1
- import { C as ClockPort, F as FrameSource } from './port-CmlUctqx.js';
1
+ import { C as ClockPort, F as FrameSource } from './port-DOxLK9GR.js';
2
2
 
3
3
  /**
4
4
  * The phases of a frame, in the order they run:
@@ -104,6 +104,12 @@ interface FrameLoop {
104
104
  readonly active: boolean;
105
105
  /** The phase running now, or `null` outside a frame. */
106
106
  readonly phase: Phase | null;
107
+ /**
108
+ * Frames this loop has finished since it was created: a frame counts once
109
+ * all four phases have run. {@link FrameLoop.resetStats} leaves it, so two
110
+ * readings tell whether a frame ended between them.
111
+ */
112
+ readonly framesEnded: number;
107
113
  /**
108
114
  * Run `task` once in `phase`: in this frame if that phase is still ahead,
109
115
  * otherwise in the next one. Scheduling the same function again before it
@@ -3,9 +3,9 @@ export { i as isHeld } from './keys-BpcrOp4S.js';
3
3
  import { P as Point } from './shapes-EbQlwbCu.js';
4
4
  import { a as DoubleClick } from './double-click-jtUSNuHL.js';
5
5
  export { D as DOUBLE_CLICK } from './double-click-jtUSNuHL.js';
6
- import { C as ClockPort, T as TimerSource } from './port-CmlUctqx.js';
7
- import { M as Machine, D as Deadline } from './paged-swipe-CIzjr2DQ.js';
8
- export { a as MachineOptions, P as PAGED_SWIPE_DEFAULTS, b as PAGED_SWIPE_EMPTY_CONTEXT, c as PAGED_SWIPE_IDLE, d as PagedSwipeConfig, e as PagedSwipeContext, f as PagedSwipeInput, g as PagedSwipeOptions, h as PagedSwipeState, S as SwipeSide, i as createMachine, j as createPagedSwipe, p as pagedSwipeDeadline, k as pagedSwipeReducer, r as rubberBand, s as swipeProgress } from './paged-swipe-CIzjr2DQ.js';
6
+ import { C as ClockPort, T as TimerSource } from './port-DOxLK9GR.js';
7
+ import { M as Machine, D as Deadline } from './paged-swipe-DUfi6V9F.js';
8
+ export { a as MachineOptions, P as PAGED_SWIPE_DEFAULTS, b as PAGED_SWIPE_EMPTY_CONTEXT, c as PAGED_SWIPE_IDLE, d as PagedSwipeConfig, e as PagedSwipeContext, f as PagedSwipeInput, g as PagedSwipeOptions, h as PagedSwipeState, R as RELEASE_RULE, i as ReleaseRule, j as ReleaseSample, S as SwipeSide, k as createMachine, l as createPagedSwipe, p as pagedSwipeDeadline, m as pagedSwipeReducer, r as releaseVelocity, n as rubberBand, s as swipeProgress } from './paged-swipe-DUfi6V9F.js';
9
9
 
10
10
  /**
11
11
  * Input types: plain event objects in, one gesture stream out. Nothing here
package/dist/gestures.js CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  PAGED_SWIPE_EMPTY_CONTEXT,
7
7
  PAGED_SWIPE_IDLE,
8
8
  RECOGNIZER_DEFAULTS,
9
+ RELEASE_RULE,
9
10
  TOUCH_PRESS_DEFAULTS,
10
11
  TOUCH_PRESS_IDLE,
11
12
  WHEEL_DEFAULTS,
@@ -24,6 +25,7 @@ import {
24
25
  pagedSwipeDeadline,
25
26
  pagedSwipeReducer,
26
27
  platformButton,
28
+ releaseVelocity,
27
29
  resolveDragModifier,
28
30
  rubberBand,
29
31
  swipeProgress,
@@ -31,12 +33,12 @@ import {
31
33
  touchPressDeadline,
32
34
  touchPressReducer,
33
35
  wheelDelta
34
- } from "./chunk-K6TAWCGL.js";
36
+ } from "./chunk-GDV76P2H.js";
35
37
  import "./chunk-OOKRBVMB.js";
36
38
  import {
37
39
  DOUBLE_CLICK,
38
40
  isHeld
39
- } from "./chunk-RWDYRT3H.js";
41
+ } from "./chunk-TJC6AXFM.js";
40
42
  export {
41
43
  DOUBLE_CLICK,
42
44
  DWELL_DEFAULTS,
@@ -46,6 +48,7 @@ export {
46
48
  PAGED_SWIPE_EMPTY_CONTEXT,
47
49
  PAGED_SWIPE_IDLE,
48
50
  RECOGNIZER_DEFAULTS,
51
+ RELEASE_RULE,
49
52
  TOUCH_PRESS_DEFAULTS,
50
53
  TOUCH_PRESS_IDLE,
51
54
  WHEEL_DEFAULTS,
@@ -65,6 +68,7 @@ export {
65
68
  pagedSwipeDeadline,
66
69
  pagedSwipeReducer,
67
70
  platformButton,
71
+ releaseVelocity,
68
72
  resolveDragModifier,
69
73
  rubberBand,
70
74
  swipeProgress,
package/dist/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- export { C as ClockPort, F as FrameSource, T as TimerSource } from './port-CmlUctqx.js';
1
+ export { C as ClockPort, F as FrameSource, T as TimerSource } from './port-DOxLK9GR.js';
2
2
  export { CoalescerOptions, FakeClock, FakeClockOptions, FrameCoalescer, createFakeClock, createFrameCoalescer } from './clock.js';
3
- export { F as FrameInfo, a as FrameLoop, b as FrameLoopOptions, c as FrameStats, d as FrameTask, P as PHASES, e as Phase, R as RepeatingTask, S as ScheduleOptions, f as createFrameLoop } from './frame-loop-f0V4b464.js';
3
+ export { F as FrameInfo, a as FrameLoop, b as FrameLoopOptions, c as FrameStats, d as FrameTask, P as PHASES, e as Phase, R as RepeatingTask, S as ScheduleOptions, f as createFrameLoop } from './frame-loop-DjAXTSO9.js';
4
4
  export { EffectCleanup, EffectOptions, Equals, ReadonlySignal, Signal, SignalOptions, batch, computed, effect, isSignal, signal, untracked } from './signals.js';
5
- export { A as Animator, S as SETTLE_DEFAULTS, a as SETTLE_TEMPO, b as Settle, c as SettleConfig, d as createSettle } from './settle-7C9xxbFg.js';
5
+ export { A as Animator, S as SETTLE_DEFAULTS, a as SETTLE_TEMPO, b as Settle, c as SettleConfig, d as SettleRange, e as createSettle } from './settle-BvkDVDhE.js';
6
6
  export { A as Animatable, P as Point, R as Rect, V as Vector, W as Widen, s as shapeEquals } from './shapes-EbQlwbCu.js';
7
7
  export { AnimatorValue, Easing, MotionOptions, MotionValue, SPRING_DEFAULTS, SetOptions, Spring, SpringConfig, SpringParams, SpringState, Tween, TweenConfig, createSpring, createTween, cubicBezier, ease, easeIn, easeInOut, easeInOutCubic, easeOut, easeOutCubic, linear, motionValue, resolveSpring, settleValue, springStep, springValue, tweenValue } from './values.js';
8
8
  export { P as PopIn, R as RevealFrame, p as popIn, r as reveal } from './reveal-Dg5fqoWS.js';
9
9
  export { CancelReason, DWELL_DEFAULTS, DWELL_IDLE, DwellConfig, DwellInput, DwellMachineOptions, DwellState, GesturePointer, InputGesture, InputGestureType, NO_MODIFIERS, Platform, PointerKind, RECOGNIZER_DEFAULTS, RawInputEvent, RawPointerEvent, RawPointerType, RawSafariGestureEvent, RawWheelEvent, Recognizer, RecognizerOptions, RecognizerTimers, TOUCH_PRESS_DEFAULTS, TOUCH_PRESS_IDLE, TouchPressConfig, TouchPressInput, TouchPressOptions, TouchPressState, WHEEL_DEFAULTS, WHEEL_PAN_DEFAULTS, WheelIntent, WheelOptions, WheelPanOptions, classifyWheel, createDwellMachine, createRecognizer, createTouchPress, dampWheelPan, defaultDragModifier, dwellDeadline, dwellReducer, modHeld, platformButton, resolveDragModifier, toModifiers, touchPressDeadline, touchPressReducer, wheelDelta } from './gestures.js';
10
10
  export { D as DOUBLE_CLICK, a as DoubleClick } from './double-click-jtUSNuHL.js';
11
- export { D as Deadline, M as Machine, a as MachineOptions, P as PAGED_SWIPE_DEFAULTS, b as PAGED_SWIPE_EMPTY_CONTEXT, c as PAGED_SWIPE_IDLE, d as PagedSwipeConfig, e as PagedSwipeContext, f as PagedSwipeInput, g as PagedSwipeOptions, h as PagedSwipeState, S as SwipeSide, i as createMachine, j as createPagedSwipe, p as pagedSwipeDeadline, k as pagedSwipeReducer, r as rubberBand, s as swipeProgress } from './paged-swipe-CIzjr2DQ.js';
11
+ export { D as Deadline, M as Machine, a as MachineOptions, P as PAGED_SWIPE_DEFAULTS, b as PAGED_SWIPE_EMPTY_CONTEXT, c as PAGED_SWIPE_IDLE, d as PagedSwipeConfig, e as PagedSwipeContext, f as PagedSwipeInput, g as PagedSwipeOptions, h as PagedSwipeState, R as RELEASE_RULE, i as ReleaseRule, j as ReleaseSample, S as SwipeSide, k as createMachine, l as createPagedSwipe, p as pagedSwipeDeadline, m as pagedSwipeReducer, r as releaseVelocity, n as rubberBand, s as swipeProgress } from './paged-swipe-DUfi6V9F.js';
12
12
  export { ClearRect, DRAG_DEFAULTS, DRAG_PREVIEW_DEFAULT, DragFrame, DragIntent, DragIntentOptions, DragIntentState, DragKeys, DragModifiers, DragPreview, DragTarget, DragTuning, GripPress, GripRelease, GuideRectsOptions, LANDING_APPROACH, LANDING_GATES, LANDING_MARGINS, LANDING_MODIFIERS, LANDING_TOUCH_MARGINS, LandingApproach, LandingFrame, LandingGates, LandingGeometry, LandingGuideRef, LandingHeld, LandingLane, LandingMargins, LandingModel, LandingModifiers, LandingOptions, LandingRegion, LandingRegions, LandingRelease, LandingSpot, LiftDecision, MIN_BOX_LENGTH, PLACE_GUIDES_DEFAULT, PlaceGuides, PlacedGuide, PreviewFrame, PreviewMode, PreviewPlan, REFUSAL_RANK, createDragIntent, createGripPress, createLandingModel, guideRects, guidesOf, inRect, liftDecision, pickRank, previewPlan, targetAt } from './drag.js';
13
13
  export { M as ModifierKey, a as Modifiers, i as isHeld } from './keys-BpcrOp4S.js';
14
- export { D as DrawEntry, a as DrawFrame, b as Drawable, L as LayoutItem, c as LayoutMotion, d as LayoutMotionOptions, e as LayoutTask, f as createLayoutMotion } from './motion-sElR1A_c.js';
14
+ export { D as DrawEntry, a as DrawFrame, b as Drawable, L as LayoutItem, c as LayoutMotion, d as LayoutMotionOptions, e as LayoutTask, f as createLayoutMotion } from './motion--ql49201.js';
15
15
  export { AnchoredMorph, BoxSize, HeldDrag, MORPH_TEMPO, anchoredMorph, holdItem } from './layout.js';
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  createFakeClock,
4
4
  createFrameCoalescer,
5
5
  createFrameLoop
6
- } from "./chunk-G5EJSZ3B.js";
6
+ } from "./chunk-BCFPSDOQ.js";
7
7
  import "./chunk-FQNHO2VT.js";
8
8
  import {
9
9
  SPRING_DEFAULTS,
@@ -23,7 +23,7 @@ import {
23
23
  springStep,
24
24
  springValue,
25
25
  tweenValue
26
- } from "./chunk-NI7JLDWZ.js";
26
+ } from "./chunk-I4TKJWCD.js";
27
27
  import {
28
28
  DWELL_DEFAULTS,
29
29
  DWELL_IDLE,
@@ -32,6 +32,7 @@ import {
32
32
  PAGED_SWIPE_EMPTY_CONTEXT,
33
33
  PAGED_SWIPE_IDLE,
34
34
  RECOGNIZER_DEFAULTS,
35
+ RELEASE_RULE,
35
36
  TOUCH_PRESS_DEFAULTS,
36
37
  TOUCH_PRESS_IDLE,
37
38
  WHEEL_DEFAULTS,
@@ -50,6 +51,7 @@ import {
50
51
  pagedSwipeDeadline,
51
52
  pagedSwipeReducer,
52
53
  platformButton,
54
+ releaseVelocity,
53
55
  resolveDragModifier,
54
56
  rubberBand,
55
57
  swipeProgress,
@@ -57,7 +59,7 @@ import {
57
59
  touchPressDeadline,
58
60
  touchPressReducer,
59
61
  wheelDelta
60
- } from "./chunk-K6TAWCGL.js";
62
+ } from "./chunk-GDV76P2H.js";
61
63
  import {
62
64
  batch,
63
65
  computed,
@@ -87,17 +89,17 @@ import {
87
89
  pickRank,
88
90
  previewPlan,
89
91
  targetAt
90
- } from "./chunk-B53X43GW.js";
92
+ } from "./chunk-F5FNGVQT.js";
91
93
  import {
92
94
  DOUBLE_CLICK,
93
95
  isHeld
94
- } from "./chunk-RWDYRT3H.js";
96
+ } from "./chunk-TJC6AXFM.js";
95
97
  import {
96
98
  MORPH_TEMPO,
97
99
  anchoredMorph,
98
100
  createLayoutMotion,
99
101
  holdItem
100
- } from "./chunk-5EMLVHP3.js";
102
+ } from "./chunk-QZJLWSPO.js";
101
103
  import {
102
104
  SETTLE_DEFAULTS,
103
105
  SETTLE_TEMPO,
@@ -105,7 +107,7 @@ import {
105
107
  popIn,
106
108
  reveal,
107
109
  shapeEquals
108
- } from "./chunk-ALYH6YQK.js";
110
+ } from "./chunk-MTSGXDVI.js";
109
111
  export {
110
112
  DOUBLE_CLICK,
111
113
  DRAG_DEFAULTS,
@@ -127,6 +129,7 @@ export {
127
129
  PLACE_GUIDES_DEFAULT,
128
130
  RECOGNIZER_DEFAULTS,
129
131
  REFUSAL_RANK,
132
+ RELEASE_RULE,
130
133
  SETTLE_DEFAULTS,
131
134
  SETTLE_TEMPO,
132
135
  SPRING_DEFAULTS,
@@ -181,6 +184,7 @@ export {
181
184
  platformButton,
182
185
  popIn,
183
186
  previewPlan,
187
+ releaseVelocity,
184
188
  resolveDragModifier,
185
189
  resolveSpring,
186
190
  reveal,
package/dist/layout.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { L as LayoutItem } from './motion-sElR1A_c.js';
2
- export { D as DrawEntry, a as DrawFrame, b as Drawable, c as LayoutMotion, d as LayoutMotionOptions, e as LayoutTask, f as createLayoutMotion } from './motion-sElR1A_c.js';
1
+ import { L as LayoutItem } from './motion--ql49201.js';
2
+ export { D as DrawEntry, a as DrawFrame, b as Drawable, c as LayoutMotion, d as LayoutMotionOptions, e as LayoutTask, f as createLayoutMotion } from './motion--ql49201.js';
3
3
  import { P as Point, R as Rect } from './shapes-EbQlwbCu.js';
4
- import { c as SettleConfig } from './settle-7C9xxbFg.js';
5
- import './frame-loop-f0V4b464.js';
6
- import './port-CmlUctqx.js';
4
+ import { c as SettleConfig } from './settle-BvkDVDhE.js';
5
+ import './frame-loop-DjAXTSO9.js';
6
+ import './port-DOxLK9GR.js';
7
7
  import './reveal-Dg5fqoWS.js';
8
8
 
9
9
  /**
package/dist/layout.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  anchoredMorph,
4
4
  createLayoutMotion,
5
5
  holdItem
6
- } from "./chunk-5EMLVHP3.js";
7
- import "./chunk-ALYH6YQK.js";
6
+ } from "./chunk-QZJLWSPO.js";
7
+ import "./chunk-MTSGXDVI.js";
8
8
  export {
9
9
  MORPH_TEMPO,
10
10
  anchoredMorph,
@@ -1,4 +1,4 @@
1
- import { F as FrameInfo, a as FrameLoop, e as Phase } from './frame-loop-f0V4b464.js';
1
+ import { F as FrameInfo, a as FrameLoop, e as Phase } from './frame-loop-DjAXTSO9.js';
2
2
  import { R as Rect } from './shapes-EbQlwbCu.js';
3
3
  import { R as RevealFrame, P as PopIn } from './reveal-Dg5fqoWS.js';
4
4
 
@@ -32,11 +32,16 @@ interface Drawable {
32
32
  draw(frame: DrawFrame): void;
33
33
  }
34
34
  /**
35
- * One item the layout motion moves: give it a new place and it settles there from wherever it is drawn.
35
+ * One item the layout motion moves: give it a new place and it settles there from wherever it is drawn, once a frame
36
+ * has shown it there.
36
37
  *
37
38
  * - {@link LayoutItem.moveTo}: a settle to the new place, retargeted from the drawn rect (no jump, no overshoot);
38
39
  * the content is laid out at the new box at once and the item redrawn at once, so no frame shows the old offset
39
40
  * from the new box.
41
+ * - Seen: a rect placed by a jump ({@link LayoutMotion.add}, {@link LayoutItem.jumpTo}) is seen once a frame of the
42
+ * loop has ended after it reached the screen (drawn; batched, written). A new target before that is a jump too: no
43
+ * frame showed the rect a glide would start from, so the first frame shows the final place. `jumpTo` and `add` say
44
+ * "be here", and motion checks them; `hold` and `glideFrom` say "it is on screen here", and motion believes them.
40
45
  * - A size change is revealed: the content is laid out at the target size and the frame clipped, never scaled.
41
46
  * - {@link LayoutItem.show}: appear or disappear with a uniform-scale fade.
42
47
  */
@@ -55,21 +60,37 @@ interface LayoutItem {
55
60
  readonly showing: boolean;
56
61
  /** Its appearance is at rest (fully shown, or gone). */
57
62
  readonly shownSettled: boolean;
58
- /** Settle to `to` from where it is drawn; lays the content out at `to` and redraws at once. */
63
+ /**
64
+ * Settle to `to` from where it is drawn; lays the content out at `to` and redraws at once. While the drawn rect was
65
+ * placed by a jump and is not seen yet, this is a jump to `to` instead.
66
+ */
59
67
  moveTo(to: Rect): void;
60
68
  /**
61
69
  * Settle to `to` from where it is drawn, like {@link LayoutItem.moveTo}, but keep the content laid out in its box
62
70
  * while `to` is the box's size: for chasing a moving point (a pointer), which would otherwise lay the content out
63
71
  * again on every frame. A new size lays it out at `to`, as `moveTo` does. Optional, so an item from before it (or
64
72
  * a test double) still works where it is used: {@link holdItem} falls back to `moveTo`. `createLayoutMotion`'s
65
- * items always have it.
73
+ * items always have it. Before a jumped rect is seen, a jump, as for `moveTo`.
66
74
  */
67
75
  retarget?(to: Rect): void;
68
- /** Be at `to` now, at rest: no glide. */
76
+ /**
77
+ * Be at `to` now, at rest: no glide. `jumpTo` and `add` say "be here", and motion checks them; `hold` and
78
+ * `glideFrom` say "it is on screen here", and motion believes them: `to` is seen once a frame has ended after it,
79
+ * and a target given before that jumps too.
80
+ */
69
81
  jumpTo(to: Rect): void;
70
- /** Drawn at `from` now, then settle to `to` (a FLIP's invert and play: `from` in the item's own coordinates). */
82
+ /**
83
+ * Drawn at `from` now, then settle to `to` (a FLIP's invert and play: `from` in the item's own coordinates). The way
84
+ * to animate an entrance. `jumpTo` and `add` say "be here", and motion checks them; `hold` and `glideFrom` say "it
85
+ * is on screen here", and motion believes them: `from` counts as seen, and a new target glides on from the drawn
86
+ * rect.
87
+ */
71
88
  glideFrom(from: Rect, to: Rect): void;
72
- /** Exactly at `r`, at rest (what a pointer holds); the content stays laid out in its box, moved with it. */
89
+ /**
90
+ * Exactly at `r`, at rest (what a pointer holds); the content stays laid out in its box, moved with it. `jumpTo` and
91
+ * `add` say "be here", and motion checks them; `hold` and `glideFrom` say "it is on screen here", and motion believes
92
+ * them: `r` counts as seen, and a drop right after it glides. Never hold a rect that was not on screen to get a glide.
93
+ */
73
94
  hold(r: Rect): void;
74
95
  /** Appear (true) or disappear (false) with a uniform-scale fade; `now`: without the fade. */
75
96
  show(on: boolean, options?: {
@@ -120,10 +141,21 @@ interface LayoutMotionOptions {
120
141
  * motion rules of `values/` (settle, reveal, popIn) applied to every item at once. The loop runs only while
121
142
  * something moves, or a task asks for frames, and stops by itself.
122
143
  *
144
+ * A rect placed by a jump glides on only once it is seen: a frame of the loop has ended after it reached the screen
145
+ * (see {@link LayoutItem}). An unbatched jump asks the loop for that one frame as a task, once per burst of jumps:
146
+ * `loop.active` and the loop's queue count show it, as they show any scheduled task, but it is not a movement, so
147
+ * `onActiveChange` is not called and {@link LayoutMotion.idle} does not wait for it. "Seen" is the clock's word: a
148
+ * frame is the clock's statement that what was drawn before it ended is now presented (`ClockPort.requestFrame`).
149
+ *
123
150
  * It only animates the rects it is given: which items move where, and when, is the caller's layout.
124
151
  */
125
152
  interface LayoutMotion {
126
- /** Add an item drawn by `drawable`, at `at`, shown (or gone: `{ shown: false }`). Its content is laid out at once. */
153
+ /**
154
+ * Add an item drawn by `drawable`, at `at`, shown (or gone: `{ shown: false }`). Its content is laid out at once.
155
+ * `jumpTo` and `add` say "be here", and motion checks them; `hold` and `glideFrom` say "it is on screen here", and
156
+ * motion believes them: a target given before a frame has seen `at` is a jump. To animate an entrance, add it at its
157
+ * place and {@link LayoutItem.glideFrom} where it comes from.
158
+ */
127
159
  add(id: string, drawable: Drawable, at: Rect, options?: {
128
160
  readonly shown?: boolean;
129
161
  }): LayoutItem;
@@ -135,7 +167,8 @@ interface LayoutMotion {
135
167
  /**
136
168
  * With {@link LayoutMotionOptions.onDraw}: draw the items changed since the last frame now, outside the loop. A
137
169
  * host calls it right after it commits a new layout, so the next paint shows every item where it is drawn, not a
138
- * frame at its new box. Without batching each item is already drawn as it changes, and it does nothing.
170
+ * frame at its new box. Without batching each item is already drawn as it changes, and it does nothing. It hands
171
+ * the batch to the host but ends no frame: a jump flushed and then given a target still jumps.
139
172
  */
140
173
  flush(): void;
141
174
  readonly items: ReadonlyMap<string, LayoutItem>;
@@ -151,7 +184,8 @@ interface LayoutMotion {
151
184
  }): void;
152
185
  /**
153
186
  * Resolves once nothing moves (at once if nothing does): for a test. A host learns it from
154
- * {@link LayoutMotionOptions.onActiveChange}.
187
+ * {@link LayoutMotionOptions.onActiveChange}. Right after a jump it resolves at once, before the frame that sees the
188
+ * jump: a target given then is still a jump. A test that means "drawn and seen" runs a frame (`clock.frame()`).
155
189
  */
156
190
  idle(): Promise<void>;
157
191
  /** Stop the frames and forget every item. */