@n-uf/motion 26.11.53 → 26.11.54

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 (46) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +22 -29
  3. package/dist/browser.d.ts +79 -3
  4. package/dist/browser.js +49 -3
  5. package/dist/browser.js.map +1 -1
  6. package/dist/chunk-4XGH5367.js +379 -0
  7. package/dist/chunk-4XGH5367.js.map +1 -0
  8. package/dist/{chunk-SIAZRWYD.js → chunk-ALYH6YQK.js} +4 -7
  9. package/dist/chunk-ALYH6YQK.js.map +1 -0
  10. package/dist/{chunk-BVPVUJ42.js → chunk-G5EJSZ3B.js} +77 -30
  11. package/dist/chunk-G5EJSZ3B.js.map +1 -0
  12. package/dist/chunk-IT2FMZOM.js +989 -0
  13. package/dist/chunk-IT2FMZOM.js.map +1 -0
  14. package/dist/{chunk-V7DEXKBZ.js → chunk-NI7JLDWZ.js} +35 -8
  15. package/dist/chunk-NI7JLDWZ.js.map +1 -0
  16. package/dist/{chunk-7EAAKM6U.js → chunk-QMGPJ2FG.js} +37 -89
  17. package/dist/chunk-QMGPJ2FG.js.map +1 -0
  18. package/dist/chunk-RWDYRT3H.js +14 -0
  19. package/dist/chunk-RWDYRT3H.js.map +1 -0
  20. package/dist/clock.d.ts +40 -7
  21. package/dist/clock.js +3 -1
  22. package/dist/double-click-DBfbiP2U.d.ts +39 -0
  23. package/dist/drag.d.ts +155 -190
  24. package/dist/drag.js +24 -912
  25. package/dist/drag.js.map +1 -1
  26. package/dist/{frame-loop-C88dc9xw.d.ts → frame-loop-f0V4b464.d.ts} +11 -11
  27. package/dist/gestures.d.ts +40 -74
  28. package/dist/gestures.js +8 -7
  29. package/dist/index.d.ts +10 -6
  30. package/dist/index.js +60 -10
  31. package/dist/layout.d.ts +9 -233
  32. package/dist/layout.js +7 -427
  33. package/dist/layout.js.map +1 -1
  34. package/dist/motion-sElR1A_c.d.ts +163 -0
  35. package/dist/reveal-Dg5fqoWS.d.ts +51 -0
  36. package/dist/{reveal-C-ewJfFn.d.ts → settle-7C9xxbFg.d.ts} +7 -57
  37. package/dist/values.d.ts +15 -7
  38. package/dist/values.js +2 -2
  39. package/package.json +2 -2
  40. package/dist/chunk-7EAAKM6U.js.map +0 -1
  41. package/dist/chunk-BVPVUJ42.js.map +0 -1
  42. package/dist/chunk-IJSIYH2D.js +0 -7
  43. package/dist/chunk-IJSIYH2D.js.map +0 -1
  44. package/dist/chunk-SIAZRWYD.js.map +0 -1
  45. package/dist/chunk-V7DEXKBZ.js.map +0 -1
  46. package/dist/double-click-jtUSNuHL.d.ts +0 -16
@@ -0,0 +1,379 @@
1
+ import {
2
+ SETTLE_TEMPO,
3
+ createSettle,
4
+ popIn,
5
+ reveal
6
+ } from "./chunk-ALYH6YQK.js";
7
+
8
+ // src/layout/motion.ts
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;
10
+ var copy = (r) => ({ x: r.x, y: r.y, width: r.width, height: r.height });
11
+ function createLayoutMotion(options) {
12
+ const { loop } = options;
13
+ const phase = options.phase ?? "layout";
14
+ const popFrom = options.popFrom ?? 0.87;
15
+ let omega = options.omega ?? SETTLE_TEMPO.default;
16
+ const items = /* @__PURE__ */ new Map();
17
+ const steps = /* @__PURE__ */ new Map();
18
+ const tasks = /* @__PURE__ */ new Set();
19
+ const frames = /* @__PURE__ */ new Set();
20
+ const tempos = /* @__PURE__ */ new Set();
21
+ const removers = /* @__PURE__ */ new Map();
22
+ let waiters = [];
23
+ let stop = null;
24
+ let woken = false;
25
+ let ticking = false;
26
+ let active = false;
27
+ const reduced = () => typeof options.reducedMotion === "function" ? options.reducedMotion() : options.reducedMotion === true;
28
+ const { onDraw, onActiveChange } = options;
29
+ const drawers = /* @__PURE__ */ new Map();
30
+ const dirty = /* @__PURE__ */ new Set();
31
+ const setActive = (on) => {
32
+ if (on === active) return;
33
+ active = on;
34
+ onActiveChange?.(on);
35
+ };
36
+ const wake = () => {
37
+ woken = true;
38
+ if (stop) return;
39
+ stop = loop.repeat(phase, tick);
40
+ setActive(true);
41
+ };
42
+ function writeBatch() {
43
+ if (!onDraw || dirty.size === 0) return;
44
+ const batch = [];
45
+ for (const id of dirty) {
46
+ const entry = drawers.get(id)?.();
47
+ if (entry) batch.push(entry);
48
+ }
49
+ dirty.clear();
50
+ if (batch.length > 0) onDraw(batch);
51
+ }
52
+ function tick(frame) {
53
+ let moving = woken;
54
+ woken = false;
55
+ ticking = true;
56
+ for (const task of [...tasks]) if (task(frame)) moving = true;
57
+ for (const step of [...steps.values()]) if (step(frame.delta)) moving = true;
58
+ writeBatch();
59
+ ticking = false;
60
+ for (const listener of [...frames]) listener(frame);
61
+ if (moving || woken) return true;
62
+ stop = null;
63
+ setActive(false);
64
+ const resolve = waiters;
65
+ waiters = [];
66
+ for (const r of resolve) r();
67
+ return false;
68
+ }
69
+ function add(id, drawable, at, opts = {}) {
70
+ if (items.has(id)) throw new Error(`layout motion: item "${id}" is already added (remove it first)`);
71
+ const rect = createSettle(copy(at), { omega });
72
+ const pop = createSettle(opts.shown === false ? 0 : 1, { omega, restDelta: 1e-3 });
73
+ let box = copy(at);
74
+ const frameOf = () => {
75
+ const drawn = rect.value;
76
+ return { drawn, box, reveal: reveal(drawn, box), pop: popIn(pop.value, popFrom), shown: pop.value, gone: pop.settled && pop.value === 0 };
77
+ };
78
+ const drawNow = () => {
79
+ const frame = frameOf();
80
+ drawable.draw(frame);
81
+ return { id, frame };
82
+ };
83
+ const draw = () => {
84
+ if (!onDraw) {
85
+ drawNow();
86
+ return;
87
+ }
88
+ dirty.add(id);
89
+ if (!ticking) wake();
90
+ };
91
+ const layOut = (to) => {
92
+ box = copy(to);
93
+ drawable.layOut(box);
94
+ };
95
+ const aim = (to) => {
96
+ if (reduced()) {
97
+ rect.jumpTo(copy(to));
98
+ draw();
99
+ return;
100
+ }
101
+ rect.setTarget(copy(to));
102
+ wake();
103
+ };
104
+ let moved = false;
105
+ const tempo = () => {
106
+ rect.configure({ omega });
107
+ pop.configure({ omega });
108
+ };
109
+ const item = {
110
+ id,
111
+ get drawn() {
112
+ return rect.value;
113
+ },
114
+ get target() {
115
+ return rect.target;
116
+ },
117
+ get box() {
118
+ return box;
119
+ },
120
+ get settled() {
121
+ return rect.settled;
122
+ },
123
+ get shown() {
124
+ return pop.value;
125
+ },
126
+ get showing() {
127
+ return pop.target === 1;
128
+ },
129
+ get shownSettled() {
130
+ return pop.settled;
131
+ },
132
+ moveTo(to) {
133
+ if (same(box, to) && same(rect.target, to)) return;
134
+ layOut(to);
135
+ draw();
136
+ if (same(rect.target, to)) return;
137
+ aim(to);
138
+ },
139
+ retarget(to) {
140
+ if (to.width !== box.width || to.height !== box.height) {
141
+ item.moveTo(to);
142
+ return;
143
+ }
144
+ if (same(rect.target, to)) return;
145
+ aim(to);
146
+ },
147
+ jumpTo(to) {
148
+ layOut(to);
149
+ rect.jumpTo(copy(to));
150
+ draw();
151
+ },
152
+ glideFrom(from, to) {
153
+ rect.jumpTo(copy(from));
154
+ layOut(to);
155
+ draw();
156
+ aim(to);
157
+ },
158
+ hold(r) {
159
+ rect.jumpTo(copy(r));
160
+ draw();
161
+ },
162
+ show(on, o = {}) {
163
+ const want = on ? 1 : 0;
164
+ if (o.now || reduced()) pop.jumpTo(want);
165
+ else if (pop.target !== want) {
166
+ pop.setTarget(want);
167
+ wake();
168
+ }
169
+ draw();
170
+ },
171
+ redraw: draw
172
+ };
173
+ drawers.set(id, drawNow);
174
+ drawable.layOut(box);
175
+ draw();
176
+ items.set(id, item);
177
+ tempos.add(tempo);
178
+ steps.set(id, (dt) => {
179
+ const a = rect.step(dt);
180
+ const b = pop.step(dt);
181
+ if (!onDraw || a || b || moved) draw();
182
+ moved = a || b;
183
+ return a || b;
184
+ });
185
+ removers.set(id, () => {
186
+ tempos.delete(tempo);
187
+ drawers.delete(id);
188
+ dirty.delete(id);
189
+ });
190
+ return item;
191
+ }
192
+ function remove(id) {
193
+ items.delete(id);
194
+ steps.delete(id);
195
+ removers.get(id)?.();
196
+ removers.delete(id);
197
+ }
198
+ return {
199
+ add,
200
+ get: (id) => items.get(id),
201
+ remove,
202
+ retain(ids) {
203
+ const keep = new Set(ids);
204
+ for (const id of [...items.keys()]) if (!keep.has(id)) remove(id);
205
+ },
206
+ flush: writeBatch,
207
+ items,
208
+ task(task) {
209
+ tasks.add(task);
210
+ wake();
211
+ return () => tasks.delete(task);
212
+ },
213
+ onFrame(listener) {
214
+ frames.add(listener);
215
+ return () => frames.delete(listener);
216
+ },
217
+ wake,
218
+ configure(config) {
219
+ if (config.omega !== void 0) omega = config.omega;
220
+ for (const t of tempos) t();
221
+ },
222
+ idle: () => stop ? new Promise((r) => waiters.push(r)) : Promise.resolve(),
223
+ dispose() {
224
+ stop?.();
225
+ stop = null;
226
+ setActive(false);
227
+ items.clear();
228
+ steps.clear();
229
+ drawers.clear();
230
+ dirty.clear();
231
+ tasks.clear();
232
+ frames.clear();
233
+ tempos.clear();
234
+ removers.clear();
235
+ const resolve = waiters;
236
+ waiters = [];
237
+ for (const r of resolve) r();
238
+ }
239
+ };
240
+ }
241
+
242
+ // src/layout/held.ts
243
+ var CAUGHT = 0.5;
244
+ function holdItem(item, grab) {
245
+ let size = { width: item.drawn.width, height: item.drawn.height };
246
+ let at = { x: grab.x, y: grab.y };
247
+ let pointer = null;
248
+ let snapped = null;
249
+ let returning = false;
250
+ const heldRect = () => pointer ? { x: pointer.x - at.x, y: pointer.y - at.y, width: size.width, height: size.height } : null;
251
+ const same2 = (a, b) => 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;
252
+ const snapTo = (slot) => {
253
+ if (slot) {
254
+ if (snapped && same2(snapped, slot)) return null;
255
+ snapped = { ...slot };
256
+ returning = false;
257
+ item.moveTo(slot);
258
+ return "snapped";
259
+ }
260
+ if (!snapped) return null;
261
+ snapped = null;
262
+ returning = true;
263
+ return "left";
264
+ };
265
+ const follow = () => {
266
+ const goal = heldRect();
267
+ if (!returning || !goal) return false;
268
+ if (item.retarget) item.retarget(goal);
269
+ else item.moveTo(goal);
270
+ const d = item.drawn;
271
+ 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;
272
+ returning = false;
273
+ item.hold(goal);
274
+ return true;
275
+ };
276
+ const letGo = (to) => {
277
+ const release = { ...item.drawn };
278
+ snapped = null;
279
+ returning = false;
280
+ item.moveTo(to);
281
+ return release;
282
+ };
283
+ return {
284
+ get pointer() {
285
+ return pointer;
286
+ },
287
+ get held() {
288
+ return heldRect();
289
+ },
290
+ get snapped() {
291
+ return snapped;
292
+ },
293
+ get returning() {
294
+ return returning;
295
+ },
296
+ move(p) {
297
+ pointer = { x: p.x, y: p.y };
298
+ if (snapped || returning) return;
299
+ item.hold(heldRect());
300
+ },
301
+ snapTo,
302
+ follow,
303
+ preview(plan, slot) {
304
+ const change = snapTo(plan.snapItem && slot ? slot : null);
305
+ follow();
306
+ return change;
307
+ },
308
+ resize(next) {
309
+ if (Math.abs(next.width - size.width) < 0.01 && Math.abs(next.height - size.height) < 0.01) return false;
310
+ at = { x: size.width ? at.x / size.width * next.width : 0, y: size.height ? at.y / size.height * next.height : 0 };
311
+ size = { width: next.width, height: next.height };
312
+ if (!snapped && pointer) {
313
+ returning = true;
314
+ follow();
315
+ }
316
+ return true;
317
+ },
318
+ land: letGo,
319
+ cancel: letGo
320
+ };
321
+ }
322
+
323
+ // src/layout/anchored.ts
324
+ var MORPH_TEMPO = SETTLE_TEMPO.quick;
325
+ function anchoredMorph(size, anchor, config = {}) {
326
+ const pack = (s, a) => ({ x: finite(a.x), y: finite(a.y), width: Math.max(0, finite(s.width)), height: Math.max(0, finite(s.height)) });
327
+ const settle = createSettle(pack(size, anchor), { omega: MORPH_TEMPO, ...config });
328
+ let from = settle.value;
329
+ const gap = (a, b) => 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));
330
+ return {
331
+ get size() {
332
+ const v = settle.value;
333
+ return { width: v.width, height: v.height };
334
+ },
335
+ get anchor() {
336
+ const v = settle.value;
337
+ return { x: v.x, y: v.y };
338
+ },
339
+ get target() {
340
+ const t = settle.target;
341
+ return { size: { width: t.width, height: t.height }, anchor: { x: t.x, y: t.y } };
342
+ },
343
+ get settled() {
344
+ return settle.settled;
345
+ },
346
+ get progress() {
347
+ const whole = gap(from, settle.target);
348
+ if (settle.settled || whole < 1e-9) return 1;
349
+ return Math.min(1, Math.max(0, 1 - gap(settle.value, settle.target) / whole));
350
+ },
351
+ to(s, a) {
352
+ const goal = pack(s, a);
353
+ if (gap(goal, settle.target) < 0.01) return false;
354
+ from = settle.value;
355
+ settle.setTarget(goal);
356
+ return true;
357
+ },
358
+ jumpTo(s, a) {
359
+ settle.jumpTo(pack(s, a));
360
+ from = settle.value;
361
+ },
362
+ step(dt) {
363
+ return settle.step(dt);
364
+ },
365
+ rectAt(p) {
366
+ const v = settle.value;
367
+ return { x: p.x - v.x, y: p.y - v.y, width: v.width, height: v.height };
368
+ }
369
+ };
370
+ }
371
+ var finite = (v) => Number.isFinite(v) ? v : 0;
372
+
373
+ export {
374
+ createLayoutMotion,
375
+ holdItem,
376
+ MORPH_TEMPO,
377
+ anchoredMorph
378
+ };
379
+ //# sourceMappingURL=chunk-4XGH5367.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.\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 * - 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 /** Settle to `to` from where it is drawn; lays the content out at `to` and redraws at once. */\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.\n */\n retarget?(to: Rect): void;\n /** Be at `to` now, at rest: no glide. */\n jumpTo(to: Rect): void;\n /** Drawn at `from` now, then settle to `to` (a FLIP's invert and play: `from` in the item's own coordinates). */\n glideFrom(from: Rect, to: Rect): void;\n /** Exactly at `r`, at rest (what a pointer holds); the content stays laid out in its box, moved with it. */\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 * It only animates the rects it is given: which items move where, and when, is the caller's layout.\n */\nexport interface LayoutMotion {\n /** Add an item drawn by `drawable`, at `at`, shown (or gone: `{ shown: false }`). Its content is laid out at once. */\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.\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}.\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 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 }\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 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 aim(to);\n },\n jumpTo(to) {\n layOut(to);\n rect.jumpTo(copy(to));\n draw();\n },\n glideFrom(from, to) {\n rect.jumpTo(copy(from));\n layOut(to);\n draw();\n aim(to);\n },\n hold(r) {\n rect.jumpTo(copy(r));\n draw();\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 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 }\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 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): it settles\n * to it from where it is drawn, the size revealed (never stretched), 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 grab point keeps its share\n * of the item, so the pointer stays on the same spot of it; the item settles from where it is drawn to its new held\n * rect (its size revealed, never stretched), then is held 1:1 again ({@link HeldDrag.follow} once a frame). In a\n * slot it stays there, taking the new size when it leaves. The same size again does nothing; returns true on a\n * change.\n */\n resize(size: { readonly width: number; readonly height: number }): boolean;\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 resize(next) {\n if (Math.abs(next.width - size.width) < 0.01 && Math.abs(next.height - size.height) < 0.01) return false;\n at = { 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 rectAt(p) {\n const v = settle.value;\n return { x: p.x - v.x, y: p.y - v.y, width: v.width, height: v.height };\n },\n };\n}\n\nconst finite = (v: number): number => (Number.isFinite(v) ? v : 0);\n"],"mappings":";;;;;;;;AAkKA,IAAM,OAAO,CAAC,GAAS,MACrB,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,QAAQ,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,QAAQ,KAAK,IAAI,EAAE,QAAQ,EAAE,KAAK,IAAI,QAAQ,KAAK,IAAI,EAAE,SAAS,EAAE,MAAM,IAAI;AACpI,IAAM,OAAO,CAAC,OAAmB,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,GAAG,OAAO,EAAE,OAAO,QAAQ,EAAE,OAAO;AAG7E,SAAS,mBAAmB,SAA4C;AAC7E,QAAM,EAAE,KAAK,IAAI;AACjB,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,UAAU,QAAQ,WAAW;AACnC,MAAI,QAAQ,QAAQ,SAAS,aAAa;AAC1C,QAAM,QAAQ,oBAAI,IAAwB;AAC1C,QAAM,QAAQ,oBAAI,IAAqC;AACvD,QAAM,QAAQ,oBAAI,IAAgB;AAClC,QAAM,SAAS,oBAAI,IAAgC;AACnD,QAAM,SAAS,oBAAI,IAAgB;AAEnC,QAAM,WAAW,oBAAI,IAAwB;AAC7C,MAAI,UAA0B,CAAC;AAC/B,MAAI,OAA4B;AAChC,MAAI,QAAQ;AACZ,MAAI,UAAU;AACd,MAAI,SAAS;AACb,QAAM,UAAU,MAAgB,OAAO,QAAQ,kBAAkB,aAAa,QAAQ,cAAc,IAAI,QAAQ,kBAAkB;AAClI,QAAM,EAAE,QAAQ,e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,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"]}
@@ -121,10 +121,10 @@ var ComponentAnimator = class {
121
121
  this.cachedValue = null;
122
122
  this.settled = true;
123
123
  }
124
- step(dtMs) {
124
+ step(dt) {
125
125
  if (this.settled) return false;
126
- if (!(dtMs > 0)) return true;
127
- const t = dtMs / 1e3;
126
+ if (!(dt > 0)) return true;
127
+ const t = dt / 1e3;
128
128
  const { x, v, goal, scratch } = this;
129
129
  this.begin(t);
130
130
  let resting = true;
@@ -183,9 +183,6 @@ var SettleAnimator = class extends ComponentAnimator {
183
183
  for (let i = 0; i < this.x.length; i++) this.rule(i, false);
184
184
  this.updateSettled();
185
185
  }
186
- hold(value) {
187
- this.jumpTo(value);
188
- }
189
186
  configure(config) {
190
187
  if (config.omega !== void 0) this.omega = positive("omega", config.omega);
191
188
  if (config.restDelta !== void 0) this.restDelta = positive("restDelta", config.restDelta);
@@ -237,4 +234,4 @@ export {
237
234
  reveal,
238
235
  popIn
239
236
  };
240
- //# sourceMappingURL=chunk-SIAZRWYD.js.map
237
+ //# sourceMappingURL=chunk-ALYH6YQK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shapes.ts","../src/values/step.ts","../src/values/settle.ts","../src/values/reveal.ts"],"sourcesContent":["/** A point or a 2D vector. */\nexport interface Point {\n x: number;\n y: number;\n}\n\n/** An axis-aligned rectangle. */\nexport interface Rect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/** Any number of components. */\nexport type Vector = readonly number[];\n\n/** The value shapes springs and tweens move: plain numbers, nothing else. */\nexport type Animatable = number | Point | Rect | Vector;\n\n/** The shape type of an {@link Animatable}: literal numbers widen to `number`. */\nexport type Widen<T> = T extends number\n ? number\n : T extends Vector\n ? Vector\n : T extends Rect\n ? Rect\n : T extends Point\n ? Point\n : never;\n\nconst SCALAR = 0;\nconst VECTOR = 1;\nconst POINT = 2;\nconst RECT = 3;\n\n/** How a shape maps onto a flat list of numbers. Internal to values/. */\nexport interface Layout {\n readonly kind: typeof SCALAR | typeof VECTOR | typeof POINT | typeof RECT;\n readonly size: number;\n}\n\nconst SCALAR_LAYOUT: Layout = { kind: SCALAR, size: 1 };\nconst POINT_LAYOUT: Layout = { kind: POINT, size: 2 };\nconst RECT_LAYOUT: Layout = { kind: RECT, size: 4 };\n\nexport function layoutOf(value: Animatable): Layout {\n if (typeof value === \"number\") return SCALAR_LAYOUT;\n if (Array.isArray(value)) return { kind: VECTOR, size: value.length };\n if (\"width\" in value) return RECT_LAYOUT;\n return POINT_LAYOUT;\n}\n\nexport function sameLayout(a: Layout, b: Layout): boolean {\n return a.kind === b.kind && a.size === b.size;\n}\n\n/** Copy `value`'s components into `out`. */\nexport function writeComponents(value: Animatable, out: Float64Array): void {\n if (typeof value === \"number\") {\n out[0] = value;\n } else if (Array.isArray(value)) {\n for (let i = 0; i < value.length; i++) out[i] = value[i]!;\n } else if (\"width\" in value) {\n out[0] = value.x;\n out[1] = value.y;\n out[2] = value.width;\n out[3] = value.height;\n } else {\n const point = value as Point;\n out[0] = point.x;\n out[1] = point.y;\n }\n}\n\n/** A fresh value of `layout`'s shape from `components`. */\nexport function makeValue(layout: Layout, components: Float64Array): Animatable {\n switch (layout.kind) {\n case SCALAR:\n return components[0]!;\n case POINT:\n return { x: components[0]!, y: components[1]! };\n case RECT:\n return { x: components[0]!, y: components[1]!, width: components[2]!, height: components[3]! };\n default:\n return Array.from(components);\n }\n}\n\n/** Component-wise equality of two values of the same shape. */\nexport function shapeEquals(a: Animatable, b: Animatable): boolean {\n if (typeof a === \"number\" || typeof b === \"number\") return a === b;\n if (Array.isArray(a) || Array.isArray(b)) {\n const u = a as Vector;\n const v = b as Vector;\n if (u.length !== v.length) return false;\n for (let i = 0; i < u.length; i++) if (u[i] !== v[i]) return false;\n return true;\n }\n const p = a as Partial<Rect>;\n const q = b as Partial<Rect>;\n return p.x === q.x && p.y === q.y && p.width === q.width && p.height === q.height;\n}\n","import type { Animatable, Layout } from \"../shapes\";\nimport { layoutOf, makeValue, sameLayout, writeComponents } from \"../shapes\";\nimport type { Animator } from \"./animator\";\n\n/**\n * The exact critically damped step for one component, shared by the spring and the settle: displacement `d0` from the\n * target and velocity `v0` (per second) after `t` seconds, with `e` = e^(−w·t) worked out once per step. Writes into\n * out[0], out[1]: d(t) = e·(d0 + b·t), v(t) = e·(v0 − w·b·t), b = v0 + w·d0.\n */\nexport function criticalStep(w: number, e: number, d0: number, v0: number, t: number, out: Float64Array): void {\n const b = v0 + w * d0;\n out[0] = e * (d0 + b * t);\n out[1] = e * (v0 - w * b * t);\n}\n\n/**\n * What the spring and the settle share: a value of any {@link Animatable} shape kept as components (position, velocity\n * and target), its shape check, the rest test of a step, jump and snap. Each one adds only its own law: `begin` (what a\n * step works out once), `advance` (one component over `t` seconds) and `rests` (when a component counts as arrived).\n */\nexport abstract class ComponentAnimator implements Animator<Animatable> {\n readonly layout: Layout;\n readonly x: Float64Array;\n readonly v: Float64Array;\n readonly goal: Float64Array;\n readonly scratch = new Float64Array(2);\n settled = true;\n cachedValue: Animatable | null = null;\n /** How errors call it (\"spring\", \"settle\"). */\n private readonly name: string;\n\n constructor(initial: Animatable, name: string) {\n this.name = name;\n this.layout = layoutOf(initial);\n this.x = new Float64Array(this.layout.size);\n this.v = new Float64Array(this.layout.size);\n this.goal = new Float64Array(this.layout.size);\n writeComponents(initial, this.x);\n writeComponents(initial, this.goal);\n }\n\n get value(): Animatable {\n if (this.cachedValue === null) this.cachedValue = makeValue(this.layout, this.x);\n return this.cachedValue;\n }\n\n get velocity(): Animatable {\n return makeValue(this.layout, this.v);\n }\n\n get target(): Animatable {\n return makeValue(this.layout, this.goal);\n }\n\n check(value: Animatable, what: string): void {\n if (!sameLayout(layoutOf(value), this.layout)) {\n throw new TypeError(`${this.name}: ${what} has a different shape than the ${this.name}'s value`);\n }\n }\n\n /** At rest exactly when on the target and not moving. */\n updateSettled(): void {\n for (let i = 0; i < this.x.length; i++) {\n if (this.x[i] !== this.goal[i] || this.v[i] !== 0) {\n this.settled = false;\n return;\n }\n }\n this.settled = true;\n }\n\n abstract setTarget(target: Animatable): void;\n\n abstract setVelocity(velocity: Animatable): void;\n\n jumpTo(value: Animatable): void {\n this.check(value, \"the value\");\n writeComponents(value, this.x);\n writeComponents(value, this.goal);\n this.v.fill(0);\n this.cachedValue = null;\n this.settled = true;\n }\n\n snap(): void {\n this.x.set(this.goal);\n this.v.fill(0);\n this.cachedValue = null;\n this.settled = true;\n }\n\n /** Work out what every component's step of `t` seconds shares. */\n protected abstract begin(t: number): void;\n /** One component, `d0` from its target at `v0` per second, after `t` seconds: into out[0], out[1]. */\n protected abstract advance(d0: number, v0: number, t: number, out: Float64Array): void;\n /** Whether component `i`, now `d` from its target at `v` per second, counts as arrived. */\n protected abstract rests(i: number, d: number, v: number): boolean;\n\n step(dt: number): boolean {\n if (this.settled) return false;\n if (!(dt > 0)) return true;\n const t = dt / 1000;\n const { x, v, goal, scratch } = this;\n this.begin(t);\n let resting = true;\n for (let i = 0; i < x.length; i++) {\n this.advance(x[i]! - goal[i]!, v[i]!, t, scratch);\n x[i] = goal[i]! + scratch[0]!;\n v[i] = scratch[1]!;\n if (resting && !this.rests(i, scratch[0]!, scratch[1]!)) resting = false;\n }\n this.cachedValue = null;\n if (resting) this.snap();\n return !this.settled;\n }\n}\n","import type { Animatable, Widen } from \"../shapes\";\nimport { writeComponents } from \"../shapes\";\nimport type { Animator } from \"./animator\";\nimport { ComponentAnimator, criticalStep } from \"./step\";\n\n/**\n * Tempos for {@link createSettle}, in 1/s: a settle covers 90 % of the way in\n * ln(10)/omega seconds and is within 1 % in twice that.\n *\n * - `calm` 20: 90 % in 115 ms, done in 230 ms.\n * - `default` 25: 90 % in 92 ms, done in 184 ms.\n * - `quick` 37: 90 % in 62 ms, done in 124 ms (a fast Hyprland setup).\n */\nexport const SETTLE_TEMPO = { calm: 20, default: 25, quick: 37 } as const;\n\n/** Settings of {@link createSettle}. */\nexport interface SettleConfig {\n /** The tempo in 1/s (see {@link SETTLE_TEMPO}). Higher is faster. Default 25. */\n readonly omega?: number;\n /** Distance from the target that counts as arrived. Default 0.1 (tuned for pixels). */\n readonly restDelta?: number;\n}\n\n/**\n * The one curve for things that move to a new place: a window's rect between\n * layout targets, a drawer, a camera. Fast at the start, gentle at the end,\n * and it never passes its target.\n *\n * It is a critically damped spring (stiffness omega², damping 2·omega) with\n * one rule on its velocity, per component:\n *\n * - **Launch.** On a new target, each component gets the velocity\n * omega · distance toward it, from wherever it is drawn: standing still,\n * moving toward it, or moving away (it turns at once rather than drifting\n * further first). From there the spring follows `distance · e^(−omega·t)`\n * exactly: most of the move happens at once, the rest eases in.\n * - **Clamp.** That speed is also the most it may have toward the target, so a\n * velocity set by hand (`setVelocity`, a fling) toward the target is capped\n * there instead of shooting past.\n * - **Carry.** A velocity set by hand away from the target is kept, and the\n * value turns around; a critically damped spring turning around never\n * crosses the target either.\n *\n * So after a new target every component goes straight from where it is drawn\n * to the target and never past it: no overshoot on position, no wobble on\n * size, whatever the retargets. A new target starts from the drawn value,\n * never from the old start.\n *\n * Holding (a pointer owns the value): call `jumpTo(value)` on each move. The\n * value sits exactly there, at rest; the next `setTarget` launches from it.\n */\nexport interface Settle<T> extends Animator<T> {\n /** The tempo in 1/s. */\n readonly omega: number;\n /** Set the velocity (units per second); a component moving toward the target is clamped as in the launch rule. */\n setVelocity(velocity: T): void;\n /** Change the tempo or rest distance mid-flight; the value and velocity carry on, re-clamped. */\n configure(config: SettleConfig): void;\n}\n\n/** Defaults of {@link SettleConfig}. */\nexport const SETTLE_DEFAULTS = { omega: SETTLE_TEMPO.default, restDelta: 0.1 } as const;\n\nfunction positive(name: string, value: number): number {\n if (!(value > 0) || !Number.isFinite(value)) throw new RangeError(`settle: ${name} must be a finite number > 0, got ${value}`);\n return value;\n}\n\nclass SettleAnimator extends ComponentAnimator implements Settle<Animatable> {\n omega: number;\n restDelta: number;\n // One step's shared numbers (`begin`): e^(−omega·t) and the rest speed.\n private e = 1;\n private restSpeed = 0;\n\n constructor(initial: Animatable, config: SettleConfig) {\n super(initial, \"settle\");\n this.omega = positive(\"omega\", config.omega ?? SETTLE_DEFAULTS.omega);\n this.restDelta = positive(\"restDelta\", config.restDelta ?? SETTLE_DEFAULTS.restDelta);\n }\n\n /** The launch/clamp/carry rule on component `i`: `launch` for a new target, else clamp or carry. */\n rule(i: number, launch: boolean): void {\n const d = this.x[i]! - this.goal[i]!;\n const v = this.v[i]!;\n const limit = d === 0 ? 0 : -this.omega * d;\n if (launch) {\n this.v[i] = limit;\n return;\n }\n if (d === 0) return;\n // Moving away from the target (d and v the same sign): carry.\n if (d * v > 0) return;\n // Moving toward it: no faster than a launch from here.\n if (Math.abs(v) > Math.abs(limit)) this.v[i] = limit;\n }\n\n setTarget(target: Animatable): void {\n this.check(target, \"the target\");\n writeComponents(target, this.goal);\n for (let i = 0; i < this.x.length; i++) this.rule(i, true);\n this.updateSettled();\n }\n\n setVelocity(velocity: Animatable): void {\n this.check(velocity, \"the velocity\");\n writeComponents(velocity, this.v);\n for (let i = 0; i < this.x.length; i++) this.rule(i, false);\n this.updateSettled();\n }\n\n configure(config: SettleConfig): void {\n if (config.omega !== undefined) this.omega = positive(\"omega\", config.omega);\n if (config.restDelta !== undefined) this.restDelta = positive(\"restDelta\", config.restDelta);\n for (let i = 0; i < this.x.length; i++) this.rule(i, false);\n }\n\n protected begin(t: number): void {\n this.e = Math.exp(-this.omega * t);\n // At rest when every component is within restDelta and no faster than a launch from there would be.\n this.restSpeed = this.omega * this.restDelta * 1.000001;\n }\n\n protected advance(d0: number, v0: number, t: number, out: Float64Array): void {\n criticalStep(this.omega, this.e, d0, v0, t, out);\n }\n\n protected rests(i: number, d: number, v: number): boolean {\n // Within a few float steps of the goal counts as arrived too: a restDelta finer than that would never be met.\n const near = Math.max(this.restDelta, 4 * Number.EPSILON * Math.abs(this.goal[i]!));\n return !(Math.abs(d) > near || Math.abs(v) > Math.max(this.restSpeed, this.omega * near));\n }\n}\n\n/**\n * A settle starting at rest on `initial` (a number, a vector, a point or a\n * rect; targets and velocities must have the same shape). See {@link Settle}.\n */\nexport function createSettle<T extends Animatable>(initial: T, config: SettleConfig = {}): Settle<Widen<T>> {\n return new SettleAnimator(initial, config) as unknown as Settle<Widen<T>>;\n}\n","import type { Rect } from \"../shapes\";\n\n/**\n * How to draw a window whose rect is gliding without stretching its content.\n *\n * The content is laid out once at the target size and never scaled. The\n * window's element sits at its target in the layout; to draw it at the\n * gliding rect:\n *\n * - move the element by (`dx`, `dy`), so its top-left corner is the drawn rect's;\n * - draw the frame (background, border, shadow) at `width` × `height`: the drawn size;\n * - clip the content by `clipRight` and `clipBottom` so it fits a frame\n * smaller than the target (CSS: `clip-path: inset(0 clipRight clipBottom 0)`).\n *\n * A window that shrinks shows a band of its own background closing in at the\n * right and bottom; one that grows reveals content already laid out at its\n * new size. Text is never stretched. One transform and one clip per frame, no\n * layout per frame.\n */\nexport interface RevealFrame {\n /** Move the element (laid out at the target) right by this much. */\n readonly dx: number;\n /** Move the element (laid out at the target) down by this much. */\n readonly dy: number;\n /** The frame's width: the drawn rect's. */\n readonly width: number;\n /** The frame's height: the drawn rect's. */\n readonly height: number;\n /** Clip this much off the content's right edge (0 when the frame is at least as wide as the target). */\n readonly clipRight: number;\n /** Clip this much off the content's bottom edge (0 when the frame is at least as tall as the target). */\n readonly clipBottom: number;\n}\n\n/** The {@link RevealFrame} for content laid out at `target` and drawn at `drawn`. */\nexport function reveal(drawn: Rect, target: Rect): RevealFrame {\n return {\n dx: drawn.x - target.x,\n dy: drawn.y - target.y,\n width: Math.max(0, drawn.width),\n height: Math.max(0, drawn.height),\n clipRight: Math.max(0, target.width - drawn.width),\n clipBottom: Math.max(0, target.height - drawn.height),\n };\n}\n\n/** A uniform pop-in (or pop-out, run backwards): scale about the center and opacity. */\nexport interface PopIn {\n /** Scale about the window's center: the same on both axes, so nothing is stretched. */\n readonly scale: number;\n readonly opacity: number;\n}\n\n/**\n * Opening and closing: the window grows from `from` of its size to full, about\n * its center, while fading in. `progress` runs 0 to 1 (take it from a settle\n * on a number with `{ restDelta: 0.001 }`, since the default 0.1 is tuned for\n * pixels and would snap the last 10 %; or from a tween); closing runs it from\n * 1 to 0. Hyprland's default is `popin 87%`.\n */\nexport function popIn(progress: number, from = 0.87): PopIn {\n const p = Math.min(1, Math.max(0, progress));\n return { scale: from + (1 - from) * p, opacity: p };\n}\n"],"mappings":";AA+BA,IAAM,SAAS;AACf,IAAM,SAAS;AACf,IAAM,QAAQ;AACd,IAAM,OAAO;AAQb,IAAM,gBAAwB,EAAE,MAAM,QAAQ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