@n-uf/motion 26.11.53 → 26.11.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +123 -0
- package/README.md +23 -30
- package/dist/browser.d.ts +79 -3
- package/dist/browser.js +49 -3
- package/dist/browser.js.map +1 -1
- package/dist/chunk-4XGH5367.js +379 -0
- package/dist/chunk-4XGH5367.js.map +1 -0
- package/dist/{chunk-SIAZRWYD.js → chunk-ALYH6YQK.js} +4 -7
- package/dist/chunk-ALYH6YQK.js.map +1 -0
- package/dist/{chunk-BVPVUJ42.js → chunk-G5EJSZ3B.js} +77 -30
- package/dist/chunk-G5EJSZ3B.js.map +1 -0
- package/dist/{chunk-V7DEXKBZ.js → chunk-NI7JLDWZ.js} +35 -8
- package/dist/chunk-NI7JLDWZ.js.map +1 -0
- package/dist/{chunk-7EAAKM6U.js → chunk-QMGPJ2FG.js} +37 -89
- package/dist/chunk-QMGPJ2FG.js.map +1 -0
- package/dist/chunk-RWDYRT3H.js +14 -0
- package/dist/chunk-RWDYRT3H.js.map +1 -0
- package/dist/chunk-W7YP7VB2.js +882 -0
- package/dist/chunk-W7YP7VB2.js.map +1 -0
- package/dist/clock.d.ts +40 -7
- package/dist/clock.js +3 -1
- package/dist/double-click-DBfbiP2U.d.ts +39 -0
- package/dist/drag.d.ts +227 -285
- package/dist/drag.js +23 -913
- package/dist/drag.js.map +1 -1
- package/dist/{frame-loop-C88dc9xw.d.ts → frame-loop-f0V4b464.d.ts} +11 -11
- package/dist/gestures.d.ts +40 -74
- package/dist/gestures.js +8 -7
- package/dist/index.d.ts +10 -6
- package/dist/index.js +58 -10
- package/dist/layout.d.ts +9 -233
- package/dist/layout.js +7 -427
- package/dist/layout.js.map +1 -1
- package/dist/motion-sElR1A_c.d.ts +163 -0
- package/dist/reveal-Dg5fqoWS.d.ts +51 -0
- package/dist/{reveal-C-ewJfFn.d.ts → settle-7C9xxbFg.d.ts} +7 -57
- package/dist/values.d.ts +15 -7
- package/dist/values.js +2 -2
- package/package.json +2 -2
- package/dist/chunk-7EAAKM6U.js.map +0 -1
- package/dist/chunk-BVPVUJ42.js.map +0 -1
- package/dist/chunk-IJSIYH2D.js +0 -7
- package/dist/chunk-IJSIYH2D.js.map +0 -1
- package/dist/chunk-SIAZRWYD.js.map +0 -1
- package/dist/chunk-V7DEXKBZ.js.map +0 -1
- package/dist/double-click-jtUSNuHL.d.ts +0 -16
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/clock/fake-clock.ts
|
|
2
2
|
function createFakeClock(options = {}) {
|
|
3
3
|
let now = options.now ?? 0;
|
|
4
|
-
const
|
|
4
|
+
const frameInterval = options.frameInterval ?? 16;
|
|
5
5
|
let nextHandle = 1;
|
|
6
6
|
let order = 0;
|
|
7
7
|
let frameCallbacks = /* @__PURE__ */ new Map();
|
|
@@ -27,7 +27,7 @@ function createFakeClock(options = {}) {
|
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
29
|
const clock = {
|
|
30
|
-
|
|
30
|
+
frameInterval,
|
|
31
31
|
get pendingFrames() {
|
|
32
32
|
return frameCallbacks.size;
|
|
33
33
|
},
|
|
@@ -61,7 +61,7 @@ function createFakeClock(options = {}) {
|
|
|
61
61
|
checkStep(ms, "spend");
|
|
62
62
|
now += ms;
|
|
63
63
|
},
|
|
64
|
-
frame(dt =
|
|
64
|
+
frame(dt = frameInterval) {
|
|
65
65
|
clock.tick(dt);
|
|
66
66
|
const due = frameCallbacks;
|
|
67
67
|
frameCallbacks = /* @__PURE__ */ new Map();
|
|
@@ -93,9 +93,9 @@ var PHASES = ["input", "update", "layout", "write"];
|
|
|
93
93
|
var PHASE_INDEX = { input: 0, update: 1, layout: 2, write: 3 };
|
|
94
94
|
function createFrameLoop(options) {
|
|
95
95
|
const clock = options.clock;
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
const
|
|
96
|
+
const budget = options.budget ?? 10;
|
|
97
|
+
const frameInterval = options.frameInterval ?? 1e3 / 60;
|
|
98
|
+
const maxDelta = options.maxDelta ?? 64;
|
|
99
99
|
const maxRounds = options.maxRounds ?? 8;
|
|
100
100
|
const onError = options.onError;
|
|
101
101
|
const onOverBudget = options.onOverBudget;
|
|
@@ -116,10 +116,10 @@ function createFrameLoop(options) {
|
|
|
116
116
|
let overBudget = 0;
|
|
117
117
|
let deferred = 0;
|
|
118
118
|
let errors = 0;
|
|
119
|
-
let
|
|
120
|
-
let
|
|
121
|
-
let
|
|
122
|
-
const
|
|
119
|
+
let lastFrame = 0;
|
|
120
|
+
let longestFrame = 0;
|
|
121
|
+
let totalTime = 0;
|
|
122
|
+
const perPhase = [0, 0, 0, 0];
|
|
123
123
|
const queuedCount = () => {
|
|
124
124
|
let count = 0;
|
|
125
125
|
for (let p = 0; p < 4; p++) count += queues[p].size + carried[p].length;
|
|
@@ -152,7 +152,7 @@ function createFrameLoop(options) {
|
|
|
152
152
|
for (let i = 0; i < jobs.length; i++) {
|
|
153
153
|
const job = jobs[i];
|
|
154
154
|
if (job.cancelled) continue;
|
|
155
|
-
if (job.deferrable && clock.now() - frameStart >=
|
|
155
|
+
if (job.deferrable && clock.now() - frameStart >= budget) {
|
|
156
156
|
carried[phase].push(job);
|
|
157
157
|
deferred++;
|
|
158
158
|
continue;
|
|
@@ -205,7 +205,7 @@ function createFrameLoop(options) {
|
|
|
205
205
|
handle = null;
|
|
206
206
|
if (disposed) return;
|
|
207
207
|
const time = clock.now();
|
|
208
|
-
const delta = lastTime === null ?
|
|
208
|
+
const delta = lastTime === null ? frameInterval : Math.min(Math.max(time - lastTime, 0), maxDelta);
|
|
209
209
|
lastTime = time;
|
|
210
210
|
frameStart = time;
|
|
211
211
|
const info = {
|
|
@@ -213,9 +213,9 @@ function createFrameLoop(options) {
|
|
|
213
213
|
delta,
|
|
214
214
|
index: index++,
|
|
215
215
|
phase: PHASES[0],
|
|
216
|
-
|
|
216
|
+
budget,
|
|
217
217
|
elapsed: () => clock.now() - frameStart,
|
|
218
|
-
remaining: () =>
|
|
218
|
+
remaining: () => budget - (clock.now() - frameStart)
|
|
219
219
|
};
|
|
220
220
|
running = true;
|
|
221
221
|
try {
|
|
@@ -226,7 +226,7 @@ function createFrameLoop(options) {
|
|
|
226
226
|
drain(p, info);
|
|
227
227
|
runRepeaters(p, info);
|
|
228
228
|
drain(p, info);
|
|
229
|
-
|
|
229
|
+
perPhase[p] = clock.now() - phaseStart;
|
|
230
230
|
}
|
|
231
231
|
} finally {
|
|
232
232
|
running = false;
|
|
@@ -235,10 +235,10 @@ function createFrameLoop(options) {
|
|
|
235
235
|
restoreCarried();
|
|
236
236
|
const took = clock.now() - frameStart;
|
|
237
237
|
frameCount++;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
if (took >
|
|
241
|
-
if (took >
|
|
238
|
+
lastFrame = took;
|
|
239
|
+
totalTime += took;
|
|
240
|
+
if (took > longestFrame) longestFrame = took;
|
|
241
|
+
if (took > budget) {
|
|
242
242
|
overBudget++;
|
|
243
243
|
if (onOverBudget !== void 0) onOverBudget(stats());
|
|
244
244
|
}
|
|
@@ -255,10 +255,10 @@ function createFrameLoop(options) {
|
|
|
255
255
|
overBudget,
|
|
256
256
|
deferred,
|
|
257
257
|
errors,
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
258
|
+
lastFrame,
|
|
259
|
+
longestFrame,
|
|
260
|
+
meanFrame: frameCount === 0 ? 0 : totalTime / frameCount,
|
|
261
|
+
perPhase: { input: perPhase[0], update: perPhase[1], layout: perPhase[2], write: perPhase[3] },
|
|
262
262
|
repeating: liveRepeaters,
|
|
263
263
|
queued: queuedCount()
|
|
264
264
|
});
|
|
@@ -282,7 +282,7 @@ function createFrameLoop(options) {
|
|
|
282
282
|
};
|
|
283
283
|
const loop = {
|
|
284
284
|
clock,
|
|
285
|
-
|
|
285
|
+
budget,
|
|
286
286
|
get active() {
|
|
287
287
|
return running || handle !== null;
|
|
288
288
|
},
|
|
@@ -342,10 +342,10 @@ function createFrameLoop(options) {
|
|
|
342
342
|
overBudget = 0;
|
|
343
343
|
deferred = 0;
|
|
344
344
|
errors = 0;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
345
|
+
lastFrame = 0;
|
|
346
|
+
longestFrame = 0;
|
|
347
|
+
totalTime = 0;
|
|
348
|
+
perPhase.fill(0);
|
|
349
349
|
},
|
|
350
350
|
dispose() {
|
|
351
351
|
if (disposed) return;
|
|
@@ -364,9 +364,56 @@ function createFrameLoop(options) {
|
|
|
364
364
|
return loop;
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
+
// src/clock/coalescer.ts
|
|
368
|
+
function createFrameCoalescer(onFrame, frames, options = {}) {
|
|
369
|
+
const merge = options.merge;
|
|
370
|
+
let handle = null;
|
|
371
|
+
let sample;
|
|
372
|
+
let count = 0;
|
|
373
|
+
const deliver = () => {
|
|
374
|
+
const delivered = sample;
|
|
375
|
+
const folded = count;
|
|
376
|
+
sample = void 0;
|
|
377
|
+
count = 0;
|
|
378
|
+
onFrame(delivered, folded);
|
|
379
|
+
};
|
|
380
|
+
const onFrameDue = () => {
|
|
381
|
+
handle = null;
|
|
382
|
+
if (count > 0) deliver();
|
|
383
|
+
};
|
|
384
|
+
return {
|
|
385
|
+
schedule(next) {
|
|
386
|
+
sample = count > 0 && merge !== void 0 ? merge(sample, next) : next;
|
|
387
|
+
count++;
|
|
388
|
+
if (handle === null) handle = frames.requestFrame(onFrameDue);
|
|
389
|
+
},
|
|
390
|
+
flush() {
|
|
391
|
+
if (handle !== null) {
|
|
392
|
+
frames.cancelFrame(handle);
|
|
393
|
+
handle = null;
|
|
394
|
+
}
|
|
395
|
+
if (count === 0) return false;
|
|
396
|
+
deliver();
|
|
397
|
+
return true;
|
|
398
|
+
},
|
|
399
|
+
cancel() {
|
|
400
|
+
if (handle !== null) {
|
|
401
|
+
frames.cancelFrame(handle);
|
|
402
|
+
handle = null;
|
|
403
|
+
}
|
|
404
|
+
sample = void 0;
|
|
405
|
+
count = 0;
|
|
406
|
+
},
|
|
407
|
+
get pending() {
|
|
408
|
+
return count > 0;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
367
413
|
export {
|
|
368
414
|
createFakeClock,
|
|
369
415
|
PHASES,
|
|
370
|
-
createFrameLoop
|
|
416
|
+
createFrameLoop,
|
|
417
|
+
createFrameCoalescer
|
|
371
418
|
};
|
|
372
|
-
//# sourceMappingURL=chunk-
|
|
419
|
+
//# sourceMappingURL=chunk-G5EJSZ3B.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/clock/fake-clock.ts","../src/clock/frame-loop.ts","../src/clock/coalescer.ts"],"sourcesContent":["import type { ClockPort } from \"./port\";\n\n/** Options of {@link createFakeClock}. */\nexport interface FakeClockOptions {\n /** Starting time in ms. Default 0. */\n readonly now?: number;\n /** How far {@link FakeClock.frame} moves time by default. Default 16 (round numbers in tests). */\n readonly frameInterval?: number;\n}\n\n/**\n * A clock that only moves when a test moves it. Timers fire in time order\n * (ties in the order they were set), each with `now()` at its due time.\n * Frame callbacks run on {@link FakeClock.frame}; a callback requested during\n * a frame waits for the next one, as with requestAnimationFrame.\n */\nexport interface FakeClock extends ClockPort {\n /** The default frame step in ms. */\n readonly frameInterval: number;\n /** Frame callbacks waiting for the next frame. */\n readonly pendingFrames: number;\n /** Timers not yet fired. */\n readonly pendingTimers: number;\n /** Move time forward by `ms`, firing the timers that come due on the way. */\n tick(ms: number): void;\n /** Move `now()` forward by `ms` without firing anything: work that takes time. */\n spend(ms: number): void;\n /**\n * Move time forward by `dt` (default {@link FakeClock.frameInterval}), fire due\n * timers, then run the frame callbacks requested before this call. Returns\n * how many callbacks ran.\n */\n frame(dt?: number): number;\n /** Run `count` frames; returns how many callbacks ran in all. */\n frames(count: number, dt?: number): number;\n /**\n * Run frames until none is requested; returns how many frames ran. Throws\n * after `maxFrames` (default 1000): something keeps asking for frames.\n */\n runUntilIdle(options?: { readonly maxFrames?: number; readonly dt?: number }): number;\n}\n\ninterface Timer {\n readonly at: number;\n readonly order: number;\n readonly callback: () => void;\n}\n\n/** A {@link FakeClock} for tests. */\nexport function createFakeClock(options: FakeClockOptions = {}): FakeClock {\n let now = options.now ?? 0;\n const frameInterval = options.frameInterval ?? 16;\n let nextHandle = 1;\n let order = 0;\n let frameCallbacks = new Map<number, () => void>();\n const timers = new Map<number, Timer>();\n\n const checkStep = (ms: number, what: string): void => {\n if (!Number.isFinite(ms) || ms < 0) throw new RangeError(`fake clock: ${what} needs a finite ms >= 0, got ${ms}`);\n };\n\n const fireDue = (until: number): void => {\n for (;;) {\n let dueHandle = -1;\n let due: Timer | null = null;\n for (const [handle, timer] of timers) {\n if (timer.at > until) continue;\n if (due === null || timer.at < due.at || (timer.at === due.at && timer.order < due.order)) {\n due = timer;\n dueHandle = handle;\n }\n }\n if (due === null) return;\n timers.delete(dueHandle);\n if (due.at > now) now = due.at;\n due.callback();\n }\n };\n\n const clock: FakeClock = {\n frameInterval,\n get pendingFrames() {\n return frameCallbacks.size;\n },\n get pendingTimers() {\n return timers.size;\n },\n now: () => now,\n requestFrame(callback) {\n const handle = nextHandle++;\n frameCallbacks.set(handle, callback);\n return handle;\n },\n cancelFrame(handle) {\n frameCallbacks.delete(handle);\n },\n setTimer(callback, ms) {\n const handle = nextHandle++;\n timers.set(handle, { at: now + Math.max(0, ms), order: order++, callback });\n return handle;\n },\n clearTimer(handle) {\n timers.delete(handle);\n },\n tick(ms) {\n checkStep(ms, \"tick\");\n const until = now + ms;\n fireDue(until);\n if (until > now) now = until;\n },\n spend(ms) {\n checkStep(ms, \"spend\");\n now += ms;\n },\n frame(dt = frameInterval) {\n clock.tick(dt);\n const due = frameCallbacks;\n frameCallbacks = new Map();\n for (const callback of due.values()) callback();\n return due.size;\n },\n frames(count, dt) {\n let ran = 0;\n for (let i = 0; i < count; i++) ran += clock.frame(dt);\n return ran;\n },\n runUntilIdle({ maxFrames = 1000, dt } = {}) {\n let frames = 0;\n while (frameCallbacks.size > 0) {\n if (frames >= maxFrames) {\n throw new Error(`fake clock: still requesting frames after ${maxFrames} frames`);\n }\n clock.frame(dt);\n frames++;\n }\n return frames;\n },\n };\n return clock;\n}\n","import type { ClockPort, FrameSource } from \"./port\";\n\n/**\n * The phases of a frame, in the order they run:\n * - `input`: coalesced pointer, wheel and key samples are delivered;\n * - `update`: state changes (a gesture machine's intent, an engine transaction);\n * - `layout`: derived geometry, then motion values step toward their targets;\n * - `write`: the host writes the results out (transforms, canvas, DOM).\n */\nexport type Phase = \"input\" | \"update\" | \"layout\" | \"write\";\n\n/** {@link Phase} in run order. */\nexport const PHASES: readonly Phase[] = [\"input\", \"update\", \"layout\", \"write\"];\n\nconst PHASE_INDEX: Readonly<Record<Phase, number>> = { input: 0, update: 1, layout: 2, write: 3 };\n\n/** What a task sees of the frame it runs in. */\nexport interface FrameInfo {\n /** `clock.now()` when the frame started. */\n readonly time: number;\n /**\n * Ms since the previous frame, clamped to `maxDelta`. The first frame\n * after the loop was idle gets `frameInterval`, not the idle gap.\n */\n readonly delta: number;\n /** Frame counter, from 0. */\n readonly index: number;\n /** The phase running now. */\n readonly phase: Phase;\n /** The loop's frame budget in ms. */\n readonly budget: number;\n /** Ms spent in this frame so far. */\n elapsed(): number;\n /** Ms of budget left in this frame (negative when over). */\n remaining(): number;\n}\n\n/** A one-shot task. */\nexport type FrameTask = (frame: FrameInfo) => void;\n\n/** A task that runs every frame; it stops when it returns `false`. */\nexport type RepeatingTask = (frame: FrameInfo) => boolean | void;\n\n/** Options of {@link FrameLoop.schedule}. */\nexport interface ScheduleOptions {\n /**\n * May wait for a later frame when this frame is over budget. Default\n * `false`: the task runs this frame whatever the cost. Repeating tasks\n * always run.\n */\n readonly deferrable?: boolean;\n}\n\n/** Counters of a frame loop since it was created or last reset. */\nexport interface FrameStats {\n /** Frames run. */\n readonly frames: number;\n /** Frames that took longer than the budget. */\n readonly overBudget: number;\n /** Deferrable tasks moved to a later frame because the budget was spent. */\n readonly deferred: number;\n /** Tasks that threw. */\n readonly errors: number;\n /** Duration of the last frame in ms. */\n readonly lastFrame: number;\n /** Longest frame in ms. */\n readonly longestFrame: number;\n /** Mean frame duration in ms. */\n readonly meanFrame: number;\n /** Duration of each phase in the last frame, in ms. */\n readonly perPhase: Readonly<Record<Phase, number>>;\n /** Repeating tasks currently registered. */\n readonly repeating: number;\n /** One-shot tasks waiting for a frame. */\n readonly queued: number;\n}\n\n/** Options of {@link createFrameLoop}. */\nexport interface FrameLoopOptions {\n /** The clock: frames, time and timers all come from it. */\n readonly clock: ClockPort;\n /** Frame budget in ms. Default 10. */\n readonly budget?: number;\n /** `delta` of the first frame after the loop was idle. Default 1000/60. */\n readonly frameInterval?: number;\n /** Largest `delta` handed to tasks (a long pause doesn't make motion jump). Default 64. */\n readonly maxDelta?: number;\n /**\n * How many times one phase drains tasks that were queued for that same\n * phase while it ran (an effect that triggers another effect). The rest\n * waits for the next frame. Default 8.\n */\n readonly maxRounds?: number;\n /**\n * Called when a task throws; the frame carries on. Without it, the first\n * error of a frame is rethrown once the frame is done (and the next frame\n * is already requested). A repeating task that throws is stopped.\n */\n readonly onError?: (error: unknown, phase: Phase) => void;\n /** Called after a frame that took longer than the budget. */\n readonly onOverBudget?: (stats: FrameStats) => void;\n}\n\n/**\n * One frame loop. It requests a frame only while it has work, runs the\n * phases in order, and goes idle (no frame requested) when nothing is left.\n */\nexport interface FrameLoop {\n /** The clock the loop runs on. */\n readonly clock: ClockPort;\n /** The frame budget in ms. */\n readonly budget: number;\n /** Whether a frame is requested or running. */\n readonly active: boolean;\n /** The phase running now, or `null` outside a frame. */\n readonly phase: Phase | null;\n /**\n * Run `task` once in `phase`: in this frame if that phase is still ahead,\n * otherwise in the next one. Scheduling the same function again before it\n * runs does nothing. Returns a cancel function.\n */\n schedule(phase: Phase, task: FrameTask, options?: ScheduleOptions): () => void;\n /** Run `task` in `phase` every frame until it returns `false` or the returned stop is called. */\n repeat(phase: Phase, task: RepeatingTask): () => void;\n /**\n * A scheduler for `effect(fn, { schedule })`: the effect runs in `phase`,\n * at most once per frame. The same function is returned for a phase each time.\n */\n scheduler(phase: Phase): (run: () => void) => void;\n /** A {@link FrameSource} whose frames are this loop's `phase`, for a coalescer. */\n frames(phase: Phase): FrameSource;\n /** Counters since creation or the last {@link FrameLoop.resetStats}. */\n stats(): FrameStats;\n /** Zero the counters. */\n resetStats(): void;\n /** Cancel the requested frame and drop every task. The loop does nothing after this. */\n dispose(): void;\n}\n\ninterface Job {\n readonly task: FrameTask;\n readonly deferrable: boolean;\n cancelled: boolean;\n}\n\ninterface Repeater {\n readonly task: RepeatingTask;\n alive: boolean;\n}\n\n/** Create a frame loop on `options.clock`. */\nexport function createFrameLoop(options: FrameLoopOptions): FrameLoop {\n const clock = options.clock;\n const budget = options.budget ?? 10;\n const frameInterval = options.frameInterval ?? 1000 / 60;\n const maxDelta = options.maxDelta ?? 64;\n const maxRounds = options.maxRounds ?? 8;\n const onError = options.onError;\n const onOverBudget = options.onOverBudget;\n\n const queues: Map<FrameTask, Job>[] = [new Map(), new Map(), new Map(), new Map()];\n const carried: Job[][] = [[], [], [], []];\n const repeaters: Repeater[][] = [[], [], [], []];\n const schedulers: ((run: () => void) => void)[] = [];\n let liveRepeaters = 0;\n let handle: number | null = null;\n let running = false;\n let current = -1;\n let lastTime: number | null = null;\n let index = 0;\n let frameStart = 0;\n let disposed = false;\n let frameError: { error: unknown } | null = null;\n\n let frameCount = 0;\n let overBudget = 0;\n let deferred = 0;\n let errors = 0;\n let lastFrame = 0;\n let longestFrame = 0;\n let totalTime = 0;\n const perPhase = [0, 0, 0, 0];\n\n const queuedCount = (): number => {\n let count = 0;\n for (let p = 0; p < 4; p++) count += queues[p]!.size + carried[p]!.length;\n return count;\n };\n\n const hasWork = (): boolean => liveRepeaters > 0 || queuedCount() > 0;\n\n const request = (): void => {\n if (handle !== null || running || disposed) return;\n handle = clock.requestFrame(runFrame);\n };\n\n /** Drop a requested frame that has nothing left to do. */\n const releaseIfIdle = (): void => {\n if (running || handle === null || hasWork()) return;\n clock.cancelFrame(handle);\n handle = null;\n lastTime = null;\n };\n\n const report = (error: unknown, phase: number): void => {\n errors++;\n if (onError !== undefined) {\n onError(error, PHASES[phase]!);\n } else if (frameError === null) {\n frameError = { error };\n }\n };\n\n const drain = (phase: number, info: FrameInfo): void => {\n const queue = queues[phase]!;\n for (let round = 0; queue.size > 0 && round < maxRounds; round++) {\n const jobs = Array.from(queue.values());\n queue.clear();\n for (let i = 0; i < jobs.length; i++) {\n const job = jobs[i]!;\n if (job.cancelled) continue;\n if (job.deferrable && clock.now() - frameStart >= budget) {\n carried[phase]!.push(job);\n deferred++;\n continue;\n }\n try {\n job.task(info);\n } catch (error) {\n report(error, phase);\n }\n }\n }\n };\n\n const runRepeaters = (phase: number, info: FrameInfo): void => {\n const list = repeaters[phase]!;\n // New repeaters pushed during the pass run in this pass too.\n for (let i = 0; i < list.length; i++) {\n const repeater = list[i]!;\n if (!repeater.alive) continue;\n let keep: boolean | void;\n try {\n keep = repeater.task(info);\n } catch (error) {\n report(error, phase);\n keep = false;\n }\n if (keep === false && repeater.alive) {\n repeater.alive = false;\n liveRepeaters--;\n }\n }\n let kept = 0;\n for (let i = 0; i < list.length; i++) {\n const repeater = list[i]!;\n if (repeater.alive) list[kept++] = repeater;\n }\n list.length = kept;\n };\n\n /** Put deferred jobs back at the front of their queues for the next frame. */\n const restoreCarried = (): void => {\n for (let p = 0; p < 4; p++) {\n const jobs = carried[p]!;\n if (jobs.length === 0) continue;\n const queue = queues[p]!;\n const later = Array.from(queue.values());\n queue.clear();\n for (const job of jobs) if (!job.cancelled) queue.set(job.task, job);\n for (const job of later) if (!queue.has(job.task)) queue.set(job.task, job);\n jobs.length = 0;\n }\n };\n\n function runFrame(): void {\n handle = null;\n if (disposed) return;\n const time = clock.now();\n const delta = lastTime === null ? frameInterval : Math.min(Math.max(time - lastTime, 0), maxDelta);\n lastTime = time;\n frameStart = time;\n const info = {\n time,\n delta,\n index: index++,\n phase: PHASES[0]!,\n budget,\n elapsed: (): number => clock.now() - frameStart,\n remaining: (): number => budget - (clock.now() - frameStart),\n };\n running = true;\n try {\n for (let p = 0; p < 4; p++) {\n current = p;\n info.phase = PHASES[p]!;\n const phaseStart = clock.now();\n drain(p, info);\n runRepeaters(p, info);\n drain(p, info);\n perPhase[p] = clock.now() - phaseStart;\n }\n } finally {\n running = false;\n current = -1;\n }\n restoreCarried();\n const took = clock.now() - frameStart;\n frameCount++;\n lastFrame = took;\n totalTime += took;\n if (took > longestFrame) longestFrame = took;\n if (took > budget) {\n overBudget++;\n if (onOverBudget !== undefined) onOverBudget(stats());\n }\n if (hasWork()) request();\n else lastTime = null;\n if (frameError !== null) {\n const { error } = frameError;\n frameError = null;\n throw error;\n }\n }\n\n const stats = (): FrameStats => ({\n frames: frameCount,\n overBudget,\n deferred,\n errors,\n lastFrame,\n longestFrame,\n meanFrame: frameCount === 0 ? 0 : totalTime / frameCount,\n perPhase: { input: perPhase[0]!, update: perPhase[1]!, layout: perPhase[2]!, write: perPhase[3]! },\n repeating: liveRepeaters,\n queued: queuedCount(),\n });\n\n const schedule = (phase: Phase, task: FrameTask, scheduleOptions?: ScheduleOptions): (() => void) => {\n if (disposed) return () => {};\n const queue = queues[PHASE_INDEX[phase]]!;\n let job = queue.get(task);\n if (job === undefined) {\n job = { task, deferrable: scheduleOptions?.deferrable ?? false, cancelled: false };\n queue.set(task, job);\n request();\n }\n const scheduled = job;\n return () => {\n if (scheduled.cancelled) return;\n scheduled.cancelled = true;\n if (queue.get(task) === scheduled) queue.delete(task);\n releaseIfIdle();\n };\n };\n\n const loop: FrameLoop = {\n clock,\n budget,\n get active() {\n return running || handle !== null;\n },\n get phase() {\n return current < 0 ? null : PHASES[current]!;\n },\n schedule,\n repeat(phase, task) {\n if (disposed) return () => {};\n const repeater: Repeater = { task, alive: true };\n repeaters[PHASE_INDEX[phase]]!.push(repeater);\n liveRepeaters++;\n request();\n return () => {\n if (!repeater.alive) return;\n repeater.alive = false;\n liveRepeaters--;\n releaseIfIdle();\n };\n },\n scheduler(phase) {\n const p = PHASE_INDEX[phase];\n let made = schedulers[p];\n if (made === undefined) {\n made = (run) => {\n schedule(phase, run);\n };\n schedulers[p] = made;\n }\n return made;\n },\n frames(phase) {\n let next = 1;\n const pending = new Map<number, () => void>();\n return {\n requestFrame(callback) {\n const id = next++;\n const task = (): void => {\n pending.delete(id);\n callback();\n };\n pending.set(id, schedule(phase, task));\n return id;\n },\n cancelFrame(id) {\n const cancel = pending.get(id);\n if (cancel === undefined) return;\n pending.delete(id);\n cancel();\n },\n };\n },\n stats,\n resetStats() {\n frameCount = 0;\n overBudget = 0;\n deferred = 0;\n errors = 0;\n lastFrame = 0;\n longestFrame = 0;\n totalTime = 0;\n perPhase.fill(0);\n },\n dispose() {\n if (disposed) return;\n disposed = true;\n if (handle !== null) clock.cancelFrame(handle);\n handle = null;\n for (let p = 0; p < 4; p++) {\n queues[p]!.clear();\n carried[p]!.length = 0;\n for (const repeater of repeaters[p]!) repeater.alive = false;\n repeaters[p]!.length = 0;\n }\n liveRepeaters = 0;\n },\n };\n return loop;\n}\n","import type { FrameSource } from \"./port\";\n\n/** Options of {@link createFrameCoalescer}. */\nexport interface CoalescerOptions<T> {\n /**\n * How a new sample folds into the pending one. Default: keep the latest\n * (pointer positions). Wheel deltas want a sum instead.\n */\n readonly merge?: (pending: T, next: T) => T;\n}\n\n/**\n * Collapses a burst of samples into at most one delivery per frame. Same\n * shape as hypr-tiling's `createFrameCoalescer` (`schedule`, `cancel`),\n * plus `flush` and `pending`.\n */\nexport interface FrameCoalescer<T> {\n /** Record a sample and make sure a frame is requested. */\n schedule(sample: T): void;\n /**\n * Deliver the pending sample now, if there is one (before a pointer-up, so\n * the last move is seen first). Returns whether it delivered.\n */\n flush(): boolean;\n /** Drop the pending sample and the requested frame. Nothing is delivered after this. */\n cancel(): void;\n /** Whether a sample is waiting for its frame. */\n readonly pending: boolean;\n}\n\n/**\n * Deliver samples to `onFrame` once per frame of `frames`: the browser clock,\n * the fake clock, or a frame loop phase (`loop.frames(\"input\")`). `onFrame`\n * also gets how many samples were folded into this one.\n */\nexport function createFrameCoalescer<T>(\n onFrame: (sample: T, count: number) => void,\n frames: FrameSource,\n options: CoalescerOptions<T> = {},\n): FrameCoalescer<T> {\n const merge = options.merge;\n let handle: number | null = null;\n let sample: T | undefined;\n let count = 0;\n\n const deliver = (): void => {\n const delivered = sample as T;\n const folded = count;\n sample = undefined;\n count = 0;\n onFrame(delivered, folded);\n };\n\n const onFrameDue = (): void => {\n handle = null;\n if (count > 0) deliver();\n };\n\n return {\n schedule(next) {\n sample = count > 0 && merge !== undefined ? merge(sample as T, next) : next;\n count++;\n if (handle === null) handle = frames.requestFrame(onFrameDue);\n },\n flush() {\n if (handle !== null) {\n frames.cancelFrame(handle);\n handle = null;\n }\n if (count === 0) return false;\n deliver();\n return true;\n },\n cancel() {\n if (handle !== null) {\n frames.cancelFrame(handle);\n handle = null;\n }\n sample = undefined;\n count = 0;\n },\n get pending() {\n return count > 0;\n },\n };\n}\n"],"mappings":";AAiDO,SAAS,gBAAgB,UAA4B,CAAC,GAAc;AACzE,MAAI,MAAM,QAAQ,OAAO;AACzB,QAAM,gBAAgB,QAAQ,iBAAiB;AAC/C,MAAI,aAAa;AACjB,MAAI,QAAQ;AACZ,MAAI,iBAAiB,oBAAI,IAAwB;AACjD,QAAM,SAAS,oBAAI,IAAmB;AAEtC,QAAM,YAAY,CAAC,IAAY,SAAuB;AACpD,QAAI,CAAC,OAAO,SAAS,EAAE,KAAK,KAAK,EAAG,OAAM,IAAI,WAAW,eAAe,IAAI,gCAAgC,EAAE,EAAE;AAAA,EAClH;AAEA,QAAM,UAAU,CAAC,UAAwB;AACvC,eAAS;AACP,UAAI,YAAY;AAChB,UAAI,MAAoB;AACxB,iBAAW,CAAC,QAAQ,KAAK,KAAK,QAAQ;AACpC,YAAI,MAAM,KAAK,MAAO;AACtB,YAAI,QAAQ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AAA,IACL,SAAS,MAAM;AACb,eAAS,QAAQ,KAAK,UAAU,SAAY,MAAM,QAAa,IAAI,IAAI;AACvE;AACA,UAAI,WAAW,KAAM,UAAS,OAAO,aAAa,UAAU;AAAA,IAC9D;AAAA,IACA,QAAQ;AACN,UAAI,WAAW,MAAM;AACnB,eAAO,YAAY,MAAM;AACzB,iBAAS;AAAA,MACX;AACA,UAAI,UAAU,EAAG,QAAO;AACxB,cAAQ;AACR,aAAO;AAAA,IACT;AAAA,IACA,SAAS;AACP,UAAI,WAAW,MAAM;AACnB,eAAO,YAAY,MAAM;AACzB,iBAAS;AAAA,MACX;AACA,eAAS;AACT,cAAQ;AAAA,IACV;AAAA,IACA,IAAI,UAAU;AACZ,aAAO,QAAQ;AAAA,IACjB;AAAA,EACF;AACF;","names":[]}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
sameLayout,
|
|
14
14
|
shapeEquals,
|
|
15
15
|
writeComponents
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-ALYH6YQK.js";
|
|
17
17
|
|
|
18
18
|
// src/values/easing.ts
|
|
19
19
|
var linear = (t) => t;
|
|
@@ -126,9 +126,9 @@ function advance(solver, d0, v0, t, out) {
|
|
|
126
126
|
out[1] = c1 * r1 * e1 + c2 * r2 * e2;
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
function springStep(state, target, params,
|
|
129
|
+
function springStep(state, target, params, dt) {
|
|
130
130
|
const out = new Float64Array(2);
|
|
131
|
-
advance(solverFor(params), state.value - target, state.velocity,
|
|
131
|
+
advance(solverFor(params), state.value - target, state.velocity, dt / 1e3, out);
|
|
132
132
|
return { value: target + out[0], velocity: out[1] };
|
|
133
133
|
}
|
|
134
134
|
var SpringAnimator = class extends ComponentAnimator {
|
|
@@ -245,6 +245,10 @@ var TweenAnimator = class {
|
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
|
+
/** A tween's run is its duration and easing: a velocity set by hand changes nothing. */
|
|
249
|
+
setVelocity(velocity) {
|
|
250
|
+
this.check(velocity, "the velocity");
|
|
251
|
+
}
|
|
248
252
|
jumpTo(value) {
|
|
249
253
|
this.check(value, "the value");
|
|
250
254
|
writeComponents(value, this.x);
|
|
@@ -259,9 +263,9 @@ var TweenAnimator = class {
|
|
|
259
263
|
this.cachedValue = null;
|
|
260
264
|
this.settled = true;
|
|
261
265
|
}
|
|
262
|
-
step(
|
|
266
|
+
step(dt) {
|
|
263
267
|
if (this.settled) return false;
|
|
264
|
-
this.elapsed += Math.max(0,
|
|
268
|
+
this.elapsed += Math.max(0, dt);
|
|
265
269
|
const p = this.duration <= 0 ? 1 : Math.min(1, this.elapsed / this.duration);
|
|
266
270
|
if (p >= 1) {
|
|
267
271
|
this.snap();
|
|
@@ -288,6 +292,7 @@ var Motion = class {
|
|
|
288
292
|
current;
|
|
289
293
|
movingSignal;
|
|
290
294
|
listeners = /* @__PURE__ */ new Set();
|
|
295
|
+
changes = /* @__PURE__ */ new Set();
|
|
291
296
|
follows = /* @__PURE__ */ new Set();
|
|
292
297
|
stop = null;
|
|
293
298
|
disposed = false;
|
|
@@ -318,11 +323,22 @@ var Motion = class {
|
|
|
318
323
|
get moving() {
|
|
319
324
|
return this.movingSignal.value;
|
|
320
325
|
}
|
|
326
|
+
/** Tell the change listeners when the value is no longer `before`. */
|
|
327
|
+
changed(before) {
|
|
328
|
+
const now = this.current.peek();
|
|
329
|
+
if (now !== before) for (const listener of Array.from(this.changes)) listener(now);
|
|
330
|
+
}
|
|
331
|
+
/** Publish the animator's value, and tell the change listeners. */
|
|
332
|
+
publish() {
|
|
333
|
+
const before = this.current.peek();
|
|
334
|
+
this.current.value = this.animator.value;
|
|
335
|
+
this.changed(before);
|
|
336
|
+
}
|
|
321
337
|
tick = (frame) => {
|
|
322
338
|
if (this.reduced()) this.animator.snap();
|
|
323
339
|
else this.animator.step(frame.delta);
|
|
324
340
|
if (!this.animator.settled) {
|
|
325
|
-
this.
|
|
341
|
+
this.publish();
|
|
326
342
|
return true;
|
|
327
343
|
}
|
|
328
344
|
this.stop = null;
|
|
@@ -341,10 +357,12 @@ var Motion = class {
|
|
|
341
357
|
}
|
|
342
358
|
/** Publish the resting value and tell the listeners. */
|
|
343
359
|
rest() {
|
|
360
|
+
const before = this.current.peek();
|
|
344
361
|
batch(() => {
|
|
345
362
|
this.current.value = this.animator.value;
|
|
346
363
|
this.movingSignal.value = false;
|
|
347
364
|
});
|
|
365
|
+
this.changed(before);
|
|
348
366
|
const value = this.animator.value;
|
|
349
367
|
for (const listener of Array.from(this.listeners)) listener(value);
|
|
350
368
|
}
|
|
@@ -352,7 +370,7 @@ var Motion = class {
|
|
|
352
370
|
if (this.disposed) return;
|
|
353
371
|
untracked(() => {
|
|
354
372
|
this.animator.setTarget(target);
|
|
355
|
-
if (options?.velocity !== void 0) this.animator.setVelocity
|
|
373
|
+
if (options?.velocity !== void 0) this.animator.setVelocity(options.velocity);
|
|
356
374
|
if (this.reduced()) this.animator.snap();
|
|
357
375
|
if (this.animator.settled) {
|
|
358
376
|
this.halt();
|
|
@@ -401,12 +419,21 @@ var Motion = class {
|
|
|
401
419
|
this.listeners.delete(listener);
|
|
402
420
|
};
|
|
403
421
|
}
|
|
422
|
+
subscribe(listener) {
|
|
423
|
+
if (this.disposed) return () => {
|
|
424
|
+
};
|
|
425
|
+
this.changes.add(listener);
|
|
426
|
+
return () => {
|
|
427
|
+
this.changes.delete(listener);
|
|
428
|
+
};
|
|
429
|
+
}
|
|
404
430
|
dispose() {
|
|
405
431
|
if (this.disposed) return;
|
|
406
432
|
this.disposed = true;
|
|
407
433
|
this.halt();
|
|
408
434
|
for (const stop of Array.from(this.follows)) stop();
|
|
409
435
|
this.listeners.clear();
|
|
436
|
+
this.changes.clear();
|
|
410
437
|
this.movingSignal.value = false;
|
|
411
438
|
}
|
|
412
439
|
};
|
|
@@ -442,4 +469,4 @@ export {
|
|
|
442
469
|
settleValue,
|
|
443
470
|
tweenValue
|
|
444
471
|
};
|
|
445
|
-
//# sourceMappingURL=chunk-
|
|
472
|
+
//# sourceMappingURL=chunk-NI7JLDWZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/values/easing.ts","../src/values/spring.ts","../src/values/tween.ts","../src/values/motion-value.ts"],"sourcesContent":["/** Maps progress in [0, 1] to eased progress (0 at 0, 1 at 1). */\nexport type Easing = (progress: number) => number;\n\n/** No easing. */\nexport const linear: Easing = (t) => t;\n\nconst EPSILON = 1e-7;\n\n/**\n * The CSS `cubic-bezier(x1, y1, x2, y2)` curve as a function, solved\n * numerically (Newton steps, then bisection). `x1` and `x2` must be in [0, 1].\n */\nexport function cubicBezier(x1: number, y1: number, x2: number, y2: number): Easing {\n if (!(x1 >= 0 && x1 <= 1 && x2 >= 0 && x2 <= 1)) {\n throw new RangeError(`cubicBezier: x1 and x2 must be in [0, 1], got ${x1} and ${x2}`);\n }\n if (x1 === y1 && x2 === y2) return linear;\n const cx = 3 * x1;\n const bx = 3 * (x2 - x1) - cx;\n const ax = 1 - cx - bx;\n const cy = 3 * y1;\n const by = 3 * (y2 - y1) - cy;\n const ay = 1 - cy - by;\n const sampleX = (t: number): number => ((ax * t + bx) * t + cx) * t;\n const sampleY = (t: number): number => ((ay * t + by) * t + cy) * t;\n const slopeX = (t: number): number => (3 * ax * t + 2 * bx) * t + cx;\n const solveX = (x: number): number => {\n let t = x;\n for (let i = 0; i < 8; i++) {\n const error = sampleX(t) - x;\n if (Math.abs(error) < EPSILON) return t;\n const slope = slopeX(t);\n if (Math.abs(slope) < 1e-6) break;\n t -= error / slope;\n }\n let low = 0;\n let high = 1;\n t = x;\n for (let i = 0; i < 40; i++) {\n const value = sampleX(t);\n if (Math.abs(value - x) < EPSILON) return t;\n if (x > value) low = t;\n else high = t;\n t = (low + high) / 2;\n }\n return t;\n };\n return (progress) => (progress <= 0 ? 0 : progress >= 1 ? 1 : sampleY(solveX(progress)));\n}\n\n/** CSS `ease`. */\nexport const ease: Easing = /* @__PURE__ */ cubicBezier(0.25, 0.1, 0.25, 1);\n/** CSS `ease-in`. */\nexport const easeIn: Easing = /* @__PURE__ */ cubicBezier(0.42, 0, 1, 1);\n/** CSS `ease-out`. */\nexport const easeOut: Easing = /* @__PURE__ */ cubicBezier(0, 0, 0.58, 1);\n/** CSS `ease-in-out`. */\nexport const easeInOut: Easing = /* @__PURE__ */ cubicBezier(0.42, 0, 0.58, 1);\n/** Cubic ease-out: fast start, gentle stop. The tween default. */\nexport const easeOutCubic: Easing = (t) => 1 - (1 - t) ** 3;\n/** Cubic ease-in-out. */\nexport const easeInOutCubic: Easing = (t) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2);\n","import type { Animatable, Widen } from \"../shapes\";\nimport { writeComponents } from \"../shapes\";\nimport type { Animator } from \"./animator\";\nimport { ComponentAnimator, criticalStep } from \"./step\";\n\n/**\n * Spring settings. Time is in milliseconds everywhere in the API; the physics\n * runs in seconds, so velocity is in units per second.\n */\nexport interface SpringConfig {\n /** Spring constant k. Higher is snappier. Default 300. */\n readonly stiffness?: number;\n /** Damping coefficient c. When set it wins over `dampingRatio`. */\n readonly damping?: number;\n /**\n * Damping as a fraction of critical damping: 1 is critical (the fastest\n * approach with no overshoot), below 1 overshoots and rings, above 1 is\n * sluggish. Default 1.\n */\n readonly dampingRatio?: number;\n /** Mass m. Default 1. */\n readonly mass?: number;\n /** Distance from the target that counts as arrived. Default 0.1 (tuned for pixels). */\n readonly restDelta?: number;\n /** Speed, in units per second, that counts as stopped. Default 1 (tuned for pixels). */\n readonly restSpeed?: number;\n}\n\n/** A {@link SpringConfig} with every field resolved. */\nexport interface SpringParams {\n readonly stiffness: number;\n readonly damping: number;\n readonly dampingRatio: number;\n readonly mass: number;\n readonly restDelta: number;\n readonly restSpeed: number;\n}\n\n/** Defaults of {@link SpringConfig}: critically damped. */\nexport const SPRING_DEFAULTS: SpringParams = {\n stiffness: 300,\n damping: 2 * Math.sqrt(300),\n dampingRatio: 1,\n mass: 1,\n restDelta: 0.1,\n restSpeed: 1,\n};\n\nfunction positive(name: string, value: number): number {\n if (!(value > 0) || !Number.isFinite(value)) throw new RangeError(`spring: ${name} must be a finite number > 0, got ${value}`);\n return value;\n}\n\n/** Resolve a {@link SpringConfig} over the defaults. Throws on a non-positive field. */\nexport function resolveSpring(config: SpringConfig = {}): SpringParams {\n const stiffness = positive(\"stiffness\", config.stiffness ?? SPRING_DEFAULTS.stiffness);\n const mass = positive(\"mass\", config.mass ?? SPRING_DEFAULTS.mass);\n const critical = 2 * Math.sqrt(stiffness * mass);\n const damping = positive(\n config.damping !== undefined ? \"damping\" : \"dampingRatio\",\n config.damping ?? (config.dampingRatio ?? SPRING_DEFAULTS.dampingRatio) * critical,\n );\n return {\n stiffness,\n damping,\n dampingRatio: damping / critical,\n mass,\n restDelta: positive(\"restDelta\", config.restDelta ?? SPRING_DEFAULTS.restDelta),\n restSpeed: positive(\"restSpeed\", config.restSpeed ?? SPRING_DEFAULTS.restSpeed),\n };\n}\n\nconst UNDERDAMPED = 0;\nconst CRITICAL = 1;\nconst OVERDAMPED = 2;\n\n/** The closed-form solution's constants for one set of params. */\ninterface Solver {\n readonly mode: typeof UNDERDAMPED | typeof CRITICAL | typeof OVERDAMPED;\n readonly omega: number;\n readonly decay: number;\n readonly omegaD: number;\n readonly r1: number;\n readonly r2: number;\n}\n\nfunction solverFor(params: SpringParams): Solver {\n const omega = Math.sqrt(params.stiffness / params.mass);\n const zeta = params.dampingRatio;\n if (Math.abs(zeta - 1) < 1e-6) return { mode: CRITICAL, omega, decay: omega, omegaD: 0, r1: 0, r2: 0 };\n if (zeta < 1) {\n return { mode: UNDERDAMPED, omega, decay: zeta * omega, omegaD: omega * Math.sqrt(1 - zeta * zeta), r1: 0, r2: 0 };\n }\n const root = Math.sqrt(zeta * zeta - 1);\n return { mode: OVERDAMPED, omega, decay: 0, omegaD: 0, r1: -omega * (zeta - root), r2: -omega * (zeta + root) };\n}\n\n/**\n * Advance one component exactly: displacement `d0` from the target and\n * velocity `v0` (per second) after `t` seconds. Writes into out[0], out[1].\n * Exact for any `t`, so the curve doesn't depend on the frame rate.\n */\nfunction advance(solver: Solver, d0: number, v0: number, t: number, out: Float64Array): void {\n if (solver.mode === CRITICAL) {\n criticalStep(solver.omega, Math.exp(-solver.omega * t), d0, v0, t, out);\n } else if (solver.mode === UNDERDAMPED) {\n const a = solver.decay;\n const wd = solver.omegaD;\n const e = Math.exp(-a * t);\n const cos = Math.cos(wd * t);\n const sin = Math.sin(wd * t);\n out[0] = e * (d0 * cos + ((v0 + a * d0) / wd) * sin);\n out[1] = e * (v0 * cos - ((a * v0 + solver.omega * solver.omega * d0) / wd) * sin);\n } else {\n const { r1, r2 } = solver;\n const c2 = (v0 - r1 * d0) / (r2 - r1);\n const c1 = d0 - c2;\n const e1 = Math.exp(r1 * t);\n const e2 = Math.exp(r2 * t);\n out[0] = c1 * e1 + c2 * e2;\n out[1] = c1 * r1 * e1 + c2 * r2 * e2;\n }\n}\n\n/** A scalar spring's position and velocity (units per second). */\nexport interface SpringState {\n readonly value: number;\n readonly velocity: number;\n}\n\n/**\n * One pure spring step for a scalar: where `state` is after `dt` ms heading for\n * `target`. Doesn't settle or snap; {@link createSpring} does that.\n */\nexport function springStep(state: SpringState, target: number, params: SpringParams, dt: number): SpringState {\n const out = new Float64Array(2);\n advance(solverFor(params), state.value - target, state.velocity, dt / 1000, out);\n return { value: target + out[0]!, velocity: out[1]! };\n}\n\n/** A spring over any {@link Animatable} shape, stepped by hand or by `motionValue`. */\nexport interface Spring<T> extends Animator<T> {\n /** The resolved settings. */\n readonly params: SpringParams;\n /** Set the velocity in units per second (a gesture's release velocity). */\n setVelocity(velocity: T): void;\n /** Change settings mid-flight; position and velocity carry on. */\n configure(config: SpringConfig): void;\n}\n\nclass SpringAnimator extends ComponentAnimator implements Spring<Animatable> {\n config: SpringConfig;\n params: SpringParams;\n solver: Solver;\n\n constructor(initial: Animatable, config: SpringConfig) {\n super(initial, \"spring\");\n this.config = config;\n this.params = resolveSpring(config);\n this.solver = solverFor(this.params);\n }\n\n setTarget(target: Animatable): void {\n this.check(target, \"the target\");\n writeComponents(target, this.goal);\n // Position and velocity stay as they are: a retarget carries the motion on.\n this.updateSettled();\n }\n\n setVelocity(velocity: Animatable): void {\n this.check(velocity, \"the velocity\");\n writeComponents(velocity, this.v);\n this.updateSettled();\n }\n\n configure(config: SpringConfig): void {\n this.config = { ...this.config, ...config };\n this.params = resolveSpring(this.config);\n this.solver = solverFor(this.params);\n }\n\n protected begin(): void {}\n\n protected advance(d0: number, v0: number, t: number, out: Float64Array): void {\n advance(this.solver, d0, v0, t, out);\n }\n\n protected rests(_i: number, d: number, v: number): boolean {\n return !(Math.abs(d) > this.params.restDelta || Math.abs(v) > this.params.restSpeed);\n }\n}\n\n/**\n * A spring starting at rest on `initial`. `initial` fixes the shape: a\n * number, a vector (array), a point `{ x, y }` or a rect `{ x, y, width,\n * height }`; targets and velocities must have the same shape.\n */\nexport function createSpring<T extends Animatable>(initial: T, config: SpringConfig = {}): Spring<Widen<T>> {\n return new SpringAnimator(initial, config) as unknown as Spring<Widen<T>>;\n}\n","import type { Animatable, Layout, Widen } from \"../shapes\";\nimport { layoutOf, makeValue, sameLayout, writeComponents } from \"../shapes\";\nimport type { Animator } from \"./animator\";\nimport { easeOutCubic, type Easing } from \"./easing\";\n\n/** Tween settings. */\nexport interface TweenConfig {\n /** Length of a run in ms. Default 250. 0 jumps to the target on the next step. */\n readonly duration?: number;\n /** Easing of the run. Default {@link easeOutCubic}. */\n readonly easing?: Easing;\n}\n\n/** A tween over any {@link Animatable} shape. */\nexport interface Tween<T> extends Animator<T> {\n /** Run progress in [0, 1]. */\n readonly progress: number;\n /** Change duration or easing; applies from the next target. */\n configure(config: TweenConfig): void;\n}\n\nclass TweenAnimator implements Tween<Animatable> {\n readonly layout: Layout;\n readonly x: Float64Array;\n readonly from: Float64Array;\n readonly goal: Float64Array;\n duration: number;\n easing: Easing;\n elapsed = 0;\n settled = true;\n cachedValue: Animatable | null = null;\n\n constructor(initial: Animatable, config: TweenConfig) {\n this.layout = layoutOf(initial);\n const size = this.layout.size;\n this.x = new Float64Array(size);\n this.from = new Float64Array(size);\n this.goal = new Float64Array(size);\n writeComponents(initial, this.x);\n writeComponents(initial, this.from);\n writeComponents(initial, this.goal);\n this.duration = 250;\n this.easing = easeOutCubic;\n this.configure(config);\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 target(): Animatable {\n return makeValue(this.layout, this.goal);\n }\n\n get progress(): number {\n if (this.settled) return 1;\n return this.duration <= 0 ? 0 : Math.min(1, this.elapsed / this.duration);\n }\n\n /** The eased curve's slope at the current progress, as units per second. */\n get velocity(): Animatable {\n const out = new Float64Array(this.layout.size);\n if (!this.settled && this.duration > 0) {\n const p = this.progress;\n const h = 1e-3;\n const lo = Math.max(0, p - h);\n const hi = Math.min(1, p + h);\n const slope = (this.easing(hi) - this.easing(lo)) / (hi - lo);\n const perSecond = (slope / this.duration) * 1000;\n for (let i = 0; i < out.length; i++) out[i] = (this.goal[i]! - this.from[i]!) * perSecond;\n }\n return makeValue(this.layout, out);\n }\n\n configure(config: TweenConfig): void {\n if (config.duration !== undefined) {\n if (!(config.duration >= 0) || !Number.isFinite(config.duration)) {\n throw new RangeError(`tween: duration must be a finite number >= 0, got ${config.duration}`);\n }\n this.duration = config.duration;\n }\n if (config.easing !== undefined) this.easing = config.easing;\n }\n\n check(value: Animatable, what: string): void {\n if (!sameLayout(layoutOf(value), this.layout)) {\n throw new TypeError(`tween: ${what} has a different shape than the tween's value`);\n }\n }\n\n setTarget(target: Animatable): void {\n this.check(target, \"the target\");\n writeComponents(target, this.goal);\n // A new run starts from wherever the value is now (no jump).\n this.from.set(this.x);\n this.elapsed = 0;\n this.settled = true;\n for (let i = 0; i < this.x.length; i++) {\n if (this.x[i] !== this.goal[i]) {\n this.settled = false;\n break;\n }\n }\n }\n\n /** A tween's run is its duration and easing: a velocity set by hand changes nothing. */\n setVelocity(velocity: Animatable): void {\n this.check(velocity, \"the velocity\");\n }\n\n jumpTo(value: Animatable): void {\n this.check(value, \"the value\");\n writeComponents(value, this.x);\n writeComponents(value, this.from);\n writeComponents(value, this.goal);\n this.cachedValue = null;\n this.settled = true;\n }\n\n snap(): void {\n this.x.set(this.goal);\n this.from.set(this.goal);\n this.cachedValue = null;\n this.settled = true;\n }\n\n step(dt: number): boolean {\n if (this.settled) return false;\n this.elapsed += Math.max(0, dt);\n const p = this.duration <= 0 ? 1 : Math.min(1, this.elapsed / this.duration);\n if (p >= 1) {\n this.snap();\n return false;\n }\n const eased = this.easing(p);\n for (let i = 0; i < this.x.length; i++) {\n this.x[i] = this.from[i]! + (this.goal[i]! - this.from[i]!) * eased;\n }\n this.cachedValue = null;\n return true;\n }\n}\n\n/**\n * A tween starting at rest on `initial` (same shapes as `createSpring`).\n * Velocity doesn't carry over a retarget: a new target starts a new run from\n * the current value. Use a spring where motion must stay continuous.\n */\nexport function createTween<T extends Animatable>(initial: T, config: TweenConfig = {}): Tween<Widen<T>> {\n return new TweenAnimator(initial, config) as unknown as Tween<Widen<T>>;\n}\n","import type { FrameInfo, FrameLoop, Phase } from \"../clock/frame-loop\";\nimport type { Animatable, Widen } from \"../shapes\";\nimport { shapeEquals } from \"../shapes\";\nimport { batch, effect, signal, untracked, type ReadonlySignal, type Signal } from \"../signals/signals\";\nimport type { Animator } from \"./animator\";\nimport { createSettle, type Settle, type SettleConfig } from \"./settle\";\nimport { createSpring, type Spring, type SpringConfig } from \"./spring\";\nimport { createTween, type Tween, type TweenConfig } from \"./tween\";\n\n/** Options of {@link motionValue}. */\nexport interface MotionOptions {\n /**\n * The frame phase that steps the value. Default `\"layout\"`: it steps after\n * that phase's one-shot tasks, so a target set in input, update or layout\n * moves the value in the same frame, and `write` sees the new value.\n */\n readonly phase?: Phase;\n /**\n * The reduced-motion switch: while it is (or returns) `true`, every new\n * target is reached at once, and a value in flight snaps on its next frame.\n * A function is read on each `set` and each frame, so it can read a signal\n * or a media query.\n */\n readonly reducedMotion?: boolean | (() => boolean);\n}\n\n/** Options of {@link MotionValue.set}. */\nexport interface SetOptions<T> {\n /** Start with this velocity (units per second), e.g. a gesture's release velocity. Springs and settles (a settle caps it toward the target); tweens ignore it. */\n readonly velocity?: T;\n}\n\n/**\n * An animated value on a frame loop. Reading `value` inside a computed or an\n * effect tracks it; it changes once per frame while moving and the loop goes\n * idle when it settles.\n */\nexport interface MotionValue<T, A extends Animator<unknown> = Animator<T>> extends ReadonlySignal<T> {\n /** Where the value is heading. */\n readonly target: T;\n /** The current velocity, units per second. */\n readonly velocity: T;\n /** Whether it is moving (reactive). */\n readonly moving: boolean;\n /** The spring, settle or tween underneath. Change it through this value (`jump`, not the animator's `jumpTo`), so the signal and the loop follow. */\n readonly animator: A;\n /** Head for `target`; a spring keeps its velocity, a settle launches from where it is drawn, a tween restarts. */\n set(target: T, options?: SetOptions<T>): void;\n /** Put the value at `value` at once, at rest. */\n jump(value: T): void;\n /** Finish now: put the value on its target, at rest. */\n snap(): void;\n /**\n * Keep heading for whatever `source` returns. `source` is tracked like an\n * effect, and re-read in this value's phase at most once per frame. Returns\n * a stop function.\n */\n follow(source: () => T): () => void;\n /**\n * Call `listener` each time the value comes to rest: on the frame it\n * settles, or at once when `set` (under reduced motion), `snap` or `jump`\n * leaves it at rest. Returns an unsubscribe function.\n */\n onSettle(listener: (value: T) => void): () => void;\n /**\n * Call `listener` after each change of the value (once per frame while it moves, and when `set`, `snap` or `jump`\n * moves it), with the new value; not at once, and not for a write that leaves it the same. The plain way to follow a\n * value: no signals needed. Returns an unsubscribe function.\n */\n subscribe(listener: (value: T) => void): () => void;\n /** Stop stepping, drop listeners and follows. */\n dispose(): void;\n}\n\nclass Motion<T> implements MotionValue<T> {\n readonly loop: FrameLoop;\n readonly animator: Animator<T>;\n readonly phase: Phase;\n readonly reduced: () => boolean;\n readonly current: Signal<T>;\n readonly movingSignal: Signal<boolean>;\n readonly listeners = new Set<(value: T) => void>();\n readonly changes = new Set<(value: T) => void>();\n readonly follows = new Set<() => void>();\n stop: (() => void) | null = null;\n disposed = false;\n\n constructor(loop: FrameLoop, animator: Animator<T>, options: MotionOptions) {\n this.loop = loop;\n this.animator = animator;\n this.phase = options.phase ?? \"layout\";\n const reducedMotion = options.reducedMotion ?? false;\n this.reduced = typeof reducedMotion === \"function\" ? reducedMotion : () => reducedMotion;\n this.current = signal(animator.value, {\n equals: shapeEquals as (a: T, b: T) => boolean,\n });\n this.movingSignal = signal(false);\n if (!animator.settled) this.start();\n }\n\n get value(): T {\n return this.current.value;\n }\n\n peek(): T {\n return this.current.peek();\n }\n\n get target(): T {\n return this.animator.target;\n }\n\n get velocity(): T {\n return this.animator.velocity;\n }\n\n get moving(): boolean {\n return this.movingSignal.value;\n }\n\n /** Tell the change listeners when the value is no longer `before`. */\n changed(before: T): void {\n const now = this.current.peek();\n if (now !== before) for (const listener of Array.from(this.changes)) listener(now);\n }\n\n /** Publish the animator's value, and tell the change listeners. */\n publish(): void {\n const before = this.current.peek();\n this.current.value = this.animator.value;\n this.changed(before);\n }\n\n readonly tick = (frame: FrameInfo): boolean => {\n if (this.reduced()) this.animator.snap();\n else this.animator.step(frame.delta);\n if (!this.animator.settled) {\n this.publish();\n return true;\n }\n this.stop = null;\n this.rest();\n return false;\n };\n\n start(): void {\n if (this.stop !== null || this.disposed) return;\n this.stop = this.loop.repeat(this.phase, this.tick);\n this.movingSignal.value = true;\n }\n\n halt(): void {\n if (this.stop === null) return;\n this.stop();\n this.stop = null;\n }\n\n /** Publish the resting value and tell the listeners. */\n rest(): void {\n const before = this.current.peek();\n batch(() => {\n this.current.value = this.animator.value;\n this.movingSignal.value = false;\n });\n this.changed(before);\n const value = this.animator.value;\n for (const listener of Array.from(this.listeners)) listener(value);\n }\n\n set(target: T, options?: SetOptions<T>): void {\n if (this.disposed) return;\n untracked(() => {\n this.animator.setTarget(target);\n if (options?.velocity !== undefined) this.animator.setVelocity(options.velocity);\n if (this.reduced()) this.animator.snap();\n if (this.animator.settled) {\n this.halt();\n this.rest();\n } else {\n this.start();\n }\n });\n }\n\n jump(value: T): void {\n if (this.disposed) return;\n untracked(() => {\n this.animator.jumpTo(value);\n this.halt();\n this.rest();\n });\n }\n\n snap(): void {\n if (this.disposed) return;\n untracked(() => {\n this.animator.snap();\n this.halt();\n this.rest();\n });\n }\n\n follow(source: () => T): () => void {\n if (this.disposed) return () => {};\n const dispose = effect(\n () => {\n const target = source();\n this.set(target);\n },\n { schedule: this.loop.scheduler(this.phase) },\n );\n const stop = (): void => {\n dispose();\n this.follows.delete(stop);\n };\n this.follows.add(stop);\n return stop;\n }\n\n onSettle(listener: (value: T) => void): () => void {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n subscribe(listener: (value: T) => void): () => void {\n if (this.disposed) return () => {};\n this.changes.add(listener);\n return () => {\n this.changes.delete(listener);\n };\n }\n\n dispose(): void {\n if (this.disposed) return;\n this.disposed = true;\n this.halt();\n for (const stop of Array.from(this.follows)) stop();\n this.listeners.clear();\n this.changes.clear();\n this.movingSignal.value = false;\n }\n}\n\n/** The value type an animator moves. */\nexport type AnimatorValue<A> = A extends Animator<infer T> ? T : never;\n\n/** Step `animator` on `loop` while it moves, and expose it as a signal. */\nexport function motionValue<A extends Animator<unknown>>(\n loop: FrameLoop,\n animator: A,\n options: MotionOptions = {},\n): MotionValue<AnimatorValue<A>, A> {\n return new Motion(loop, animator, options) as unknown as MotionValue<AnimatorValue<A>, A>;\n}\n\n/** A spring-driven {@link MotionValue}: `createSpring` plus `motionValue`. */\nexport function springValue<T extends Animatable>(\n loop: FrameLoop,\n initial: T,\n options: SpringConfig & MotionOptions = {},\n): MotionValue<Widen<T>, Spring<Widen<T>>> {\n return motionValue(loop, createSpring(initial, options), options) as MotionValue<Widen<T>, Spring<Widen<T>>>;\n}\n\n/**\n * A settle-driven {@link MotionValue}: `createSettle` plus `motionValue`. The\n * one curve for things moving to a new place (see {@link Settle}). To hold it\n * to a pointer, `jump` it on each move; the next `set` launches from there.\n */\nexport function settleValue<T extends Animatable>(\n loop: FrameLoop,\n initial: T,\n options: SettleConfig & MotionOptions = {},\n): MotionValue<Widen<T>, Settle<Widen<T>>> {\n return motionValue(loop, createSettle(initial, options), options) as MotionValue<Widen<T>, Settle<Widen<T>>>;\n}\n\n/** A tween-driven {@link MotionValue}: `createTween` plus `motionValue`. */\nexport function tweenValue<T extends Animatable>(\n loop: FrameLoop,\n initial: T,\n options: TweenConfig & MotionOptions = {},\n): MotionValue<Widen<T>, Tween<Widen<T>>> {\n return motionValue(loop, createTween(initial, options), options) as MotionValue<Widen<T>, Tween<Widen<T>>>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAIO,IAAM,SAAiB,CAAC,MAAM;AAErC,IAAM,UAAU;AAMT,SAAS,YAAY,IAAY,IAAY,IAAY,IAAoB;AAClF,MAAI,EAAE,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,MAAM,IAAI;AAC/C,UAAM,IAAI,WAAW,iDAAiD,EAAE,QAAQ,EAAE,EAAE;AAAA,EACtF;AACA,MAAI,OAAO,MAAM,OAAO,GAAI,QAAO;AACnC,QAAM,KAAK,IAAI;AACf,QAAM,KAAK,KAAK,KAAK,MAAM;AAC3B,QAAM,KAAK,IAAI,KAAK;AACpB,QAAM,KAAK,IAAI;AACf,QAAM,KAAK,KAAK,KAAK,MAAM;AAC3B,QAAM,KAAK,IAAI,KAAK;AACpB,QAAM,UAAU,CAAC,QAAwB,KAAK,IAAI,MAAM,IAAI,MAAM;AAClE,QAAM,UAAU,CAAC,QAAwB,KAAK,IAAI,MAAM,IAAI,MAAM;AAClE,QAAM,SAAS,CAAC,OAAuB,IAAI,KAAK,IAAI,IAAI,MAAM,IAAI;AAClE,QAAM,SAAS,CAAC,MAAsB;AACpC,QAAI,IAAI;AACR,aAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AAC1B,YAAM,QA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