@n-uf/motion 26.12.4 → 26.12.6
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 +16 -0
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +2 -2
- package/dist/browser.js.map +1 -1
- package/dist/{chunk-I4TKJWCD.js → chunk-ELRGR2MI.js} +3 -3
- package/dist/{chunk-I4TKJWCD.js.map → chunk-ELRGR2MI.js.map} +1 -1
- package/dist/{chunk-MTSGXDVI.js → chunk-GLPO4HGL.js} +19 -1
- package/dist/chunk-GLPO4HGL.js.map +1 -0
- package/dist/{chunk-OOKRBVMB.js → chunk-LSIMILAL.js} +1 -1
- package/dist/chunk-LSIMILAL.js.map +1 -0
- package/dist/{chunk-BCFPSDOQ.js → chunk-LUFRN56Q.js} +1 -1
- package/dist/chunk-LUFRN56Q.js.map +1 -0
- package/dist/{chunk-QZJLWSPO.js → chunk-PIQEUBJE.js} +34 -3
- package/dist/chunk-PIQEUBJE.js.map +1 -0
- package/dist/{chunk-XKCRMQZQ.js → chunk-QZG3DQZ7.js} +1 -1
- package/dist/{chunk-XKCRMQZQ.js.map → chunk-QZG3DQZ7.js.map} +1 -1
- package/dist/{chunk-GDV76P2H.js → chunk-R4AHR32W.js} +4 -2
- package/dist/chunk-R4AHR32W.js.map +1 -0
- package/dist/clock.js +1 -1
- package/dist/drag.js +1 -1
- package/dist/gestures.d.ts +2 -1
- package/dist/gestures.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -7
- package/dist/layout.d.ts +2 -2
- package/dist/layout.js +2 -2
- package/dist/{motion--ql49201.d.ts → motion-CREdoi-4.d.ts} +48 -6
- package/dist/signals.js +1 -1
- package/dist/values.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-BCFPSDOQ.js.map +0 -1
- package/dist/chunk-GDV76P2H.js.map +0 -1
- package/dist/chunk-MTSGXDVI.js.map +0 -1
- package/dist/chunk-OOKRBVMB.js.map +0 -1
- package/dist/chunk-QZJLWSPO.js.map +0 -1
|
@@ -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 * Frames this loop has finished since it was created: a frame counts once\n * all four phases have run. {@link FrameLoop.resetStats} leaves it, so two\n * readings tell whether a frame ended between them.\n */\n readonly framesEnded: number;\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 = [new Map<FrameTask, Job>(), new Map<FrameTask, Job>(), new Map<FrameTask, Job>(), new Map<FrameTask, Job>()];\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 let framesEnded = 0;\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- the task may have stopped itself (its stop sets `alive`), which the rule can't follow\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 framesEnded++;\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 get framesEnded() {\n return framesEnded;\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,QAAQ,MAAM,KAAK,IAAI,MAAO,MAAM,OAAO,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SAAQ;AAAA,EACzB;AAEA,SAAO;AAAA,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":[]}
|
|
@@ -2,8 +2,9 @@ import {
|
|
|
2
2
|
SETTLE_TEMPO,
|
|
3
3
|
createSettle,
|
|
4
4
|
popIn,
|
|
5
|
-
reveal
|
|
6
|
-
|
|
5
|
+
reveal,
|
|
6
|
+
translateSettle
|
|
7
|
+
} from "./chunk-GLPO4HGL.js";
|
|
7
8
|
|
|
8
9
|
// src/layout/motion.ts
|
|
9
10
|
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;
|
|
@@ -19,6 +20,8 @@ function createLayoutMotion(options) {
|
|
|
19
20
|
const frames = /* @__PURE__ */ new Set();
|
|
20
21
|
const tempos = /* @__PURE__ */ new Set();
|
|
21
22
|
const removers = /* @__PURE__ */ new Map();
|
|
23
|
+
const rebasers = /* @__PURE__ */ new Map();
|
|
24
|
+
let rebasing = null;
|
|
22
25
|
let waiters = [];
|
|
23
26
|
let stop = null;
|
|
24
27
|
let woken = false;
|
|
@@ -78,6 +81,10 @@ function createLayoutMotion(options) {
|
|
|
78
81
|
dirty.clear();
|
|
79
82
|
if (batch.length > 0) onDraw(batch);
|
|
80
83
|
}
|
|
84
|
+
const wroteRebase = () => {
|
|
85
|
+
rebasing = null;
|
|
86
|
+
writeBatch();
|
|
87
|
+
};
|
|
81
88
|
function tick(frame) {
|
|
82
89
|
let moving = woken;
|
|
83
90
|
woken = false;
|
|
@@ -213,6 +220,13 @@ function createLayoutMotion(options) {
|
|
|
213
220
|
redraw: draw
|
|
214
221
|
};
|
|
215
222
|
drawers.set(id, drawNow);
|
|
223
|
+
rebasers.set(id, (dx, dy) => {
|
|
224
|
+
translateSettle(rect, { x: -dx, y: -dy, width: 0, height: 0 });
|
|
225
|
+
box = { x: box.x - dx, y: box.y - dy, width: box.width, height: box.height };
|
|
226
|
+
drawable.layOut(box);
|
|
227
|
+
if (onDraw) dirty.add(id);
|
|
228
|
+
else drawNow();
|
|
229
|
+
});
|
|
216
230
|
drawable.layOut(box);
|
|
217
231
|
draw();
|
|
218
232
|
items.set(id, item);
|
|
@@ -228,6 +242,7 @@ function createLayoutMotion(options) {
|
|
|
228
242
|
removers.set(id, () => {
|
|
229
243
|
tempos.delete(tempo);
|
|
230
244
|
drawers.delete(id);
|
|
245
|
+
rebasers.delete(id);
|
|
231
246
|
dirty.delete(id);
|
|
232
247
|
});
|
|
233
248
|
return item;
|
|
@@ -248,6 +263,19 @@ function createLayoutMotion(options) {
|
|
|
248
263
|
for (const id of [...items.keys()]) if (!keep.has(id)) remove(id);
|
|
249
264
|
},
|
|
250
265
|
flush: writeBatch,
|
|
266
|
+
rebase(dx, dy, opts = {}) {
|
|
267
|
+
const x = Number.isFinite(dx) ? dx : 0;
|
|
268
|
+
const y = Number.isFinite(dy) ? dy : 0;
|
|
269
|
+
if (x === 0 && y === 0) return;
|
|
270
|
+
const except = new Set(opts.except ?? []);
|
|
271
|
+
let moved = false;
|
|
272
|
+
for (const [id, move] of rebasers) {
|
|
273
|
+
if (except.has(id)) continue;
|
|
274
|
+
move(x, y);
|
|
275
|
+
moved = true;
|
|
276
|
+
}
|
|
277
|
+
if (onDraw && moved && !ticking && !rebasing) rebasing = loop.schedule("write", wroteRebase);
|
|
278
|
+
},
|
|
251
279
|
items,
|
|
252
280
|
task(task) {
|
|
253
281
|
tasks.add(task);
|
|
@@ -276,9 +304,12 @@ function createLayoutMotion(options) {
|
|
|
276
304
|
frames.clear();
|
|
277
305
|
tempos.clear();
|
|
278
306
|
removers.clear();
|
|
307
|
+
rebasers.clear();
|
|
279
308
|
unseen.clear();
|
|
280
309
|
seeing?.();
|
|
281
310
|
seeing = null;
|
|
311
|
+
rebasing?.();
|
|
312
|
+
rebasing = null;
|
|
282
313
|
const resolve = waiters;
|
|
283
314
|
waiters = [];
|
|
284
315
|
for (const r of resolve) r();
|
|
@@ -427,4 +458,4 @@ export {
|
|
|
427
458
|
MORPH_TEMPO,
|
|
428
459
|
anchoredMorph
|
|
429
460
|
};
|
|
430
|
-
//# sourceMappingURL=chunk-
|
|
461
|
+
//# sourceMappingURL=chunk-PIQEUBJE.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, translateSettle, 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 /**\n * Lay the content out in `box` (its position and size): called once per new box, never per frame. A box at a new\n * place with the same size moves the content; it need not lay it out again ({@link LayoutMotion.rebase} gives one).\n */\n layOut(box: Rect): void;\n /** Draw the item for this frame. */\n draw(frame: DrawFrame): void;\n}\n\n/**\n * One item the layout motion moves: give it a new place and it settles there from wherever it is drawn, once a frame\n * has shown it there.\n *\n * - {@link LayoutItem.moveTo}: a settle to the new place, retargeted from the drawn rect (no jump, no overshoot);\n * the content is laid out at the new box at once and the item redrawn at once, so no frame shows the old offset\n * from the new box.\n * - Seen: a rect placed by a jump ({@link LayoutMotion.add}, {@link LayoutItem.jumpTo}) is seen once a frame of the\n * loop has ended after it reached the screen (drawn; batched, written). A new target before that is a jump too: no\n * frame showed the rect a glide would start from, so the first frame shows the final place.\n * - Three statements: `jumpTo` and `add` say \"be here\", and motion checks them; `hold` and `glideFrom` say \"it is on\n * screen here\", and motion believes them; {@link LayoutMotion.rebase} says \"the frame the rects are measured in\n * moved, and nothing moved on screen\", and motion changes its numbers and nothing else.\n * - A size change is revealed: the content is laid out at the target size and the frame clipped, never scaled.\n * - {@link LayoutItem.show}: appear or disappear with a uniform-scale fade.\n */\nexport interface LayoutItem {\n readonly id: string;\n /** Where it is drawn now. */\n readonly drawn: Rect;\n /** Where it is heading (its settle's target). */\n readonly target: Rect;\n /** The box its content is laid out in. */\n readonly box: Rect;\n /** At rest on its target. */\n readonly settled: boolean;\n /** How shown it is, 0 to 1, and whether it is heading for shown. */\n readonly shown: number;\n readonly showing: boolean;\n /** Its appearance is at rest (fully shown, or gone). */\n readonly shownSettled: boolean;\n /**\n * Settle to `to` from where it is drawn; lays the content out at `to` and redraws at once. While the drawn rect was\n * placed by a jump and is not seen yet, this is a jump to `to` instead.\n */\n moveTo(to: Rect): void;\n /**\n * Settle to `to` from where it is drawn, like {@link LayoutItem.moveTo}, but keep the content laid out in its box\n * while `to` is the box's size: for chasing a moving point (a pointer), which would otherwise lay the content out\n * again on every frame. A new size lays it out at `to`, as `moveTo` does. Optional, so an item from before it (or\n * a test double) still works where it is used: {@link holdItem} falls back to `moveTo`. `createLayoutMotion`'s\n * items always have it. Before a jumped rect is seen, a jump, as for `moveTo`.\n */\n retarget?(to: Rect): void;\n /**\n * Be at `to` now, at rest: no glide. `jumpTo` and `add` say \"be here\", and motion checks them; `hold` and\n * `glideFrom` say \"it is on screen here\", and motion believes them: `to` is seen once a frame has ended after it,\n * and a target given before that jumps too. {@link LayoutMotion.rebase} says \"the frame moved, and nothing moved on\n * screen\": an unseen `to` stays unseen.\n */\n jumpTo(to: Rect): void;\n /**\n * Drawn at `from` now, then settle to `to` (a FLIP's invert and play: `from` in the item's own coordinates). The way\n * to animate an entrance. `jumpTo` and `add` say \"be here\", and motion checks them; `hold` and `glideFrom` say \"it\n * is on screen here\", and motion believes them: `from` counts as seen, and a new target glides on from the drawn\n * rect. {@link LayoutMotion.rebase} says \"the frame moved, and nothing moved on screen\": the glide goes on, moved\n * with the frame.\n */\n glideFrom(from: Rect, to: Rect): void;\n /**\n * Exactly at `r`, at rest (what a pointer holds); the content stays laid out in its box, moved with it. `jumpTo` and\n * `add` say \"be here\", and motion checks them; `hold` and `glideFrom` say \"it is on screen here\", and motion believes\n * them: `r` counts as seen, and a drop right after it glides. Never hold a rect that was not on screen to get a glide.\n * {@link LayoutMotion.rebase} says \"the frame moved, and nothing moved on screen\": the held rect moves with the\n * frame, still at rest, and the next hold is given in the new frame.\n */\n hold(r: Rect): void;\n /** Appear (true) or disappear (false) with a uniform-scale fade; `now`: without the fade. */\n show(on: boolean, options?: { readonly now?: boolean }): void;\n /** Draw it again now (after its drawable's element was laid out anew from outside). */\n redraw(): void;\n}\n\n/** A task the layout motion runs on every frame before it steps the items; true keeps the frames coming. */\nexport type LayoutTask = (frame: FrameInfo) => boolean | void;\n\n/** One item's frame in a batch ({@link LayoutMotionOptions.onDraw}). */\nexport interface DrawEntry {\n readonly id: string;\n readonly frame: DrawFrame;\n}\n\nexport interface LayoutMotionOptions {\n /** The frame loop every item steps on (one loop for all of them). */\n readonly loop: FrameLoop;\n /** The settle tempo, per second ({@link SETTLE_TEMPO}); default `SETTLE_TEMPO.default`. */\n readonly omega?: number;\n /** The frame phase the items step and draw in; default `\"layout\"`. */\n readonly phase?: Phase;\n /** Where an appearing item grows from, as a share of its size ({@link popIn}'s `from`); default 0.87. */\n readonly popFrom?: number;\n /**\n * Reduced motion: read on every new target and every show or hide. While true an item is placed on its new\n * target at once (no glide) and appears or disappears at once (no fade). A boolean, or the host's query (such as\n * the reduced-motion media query). Default false.\n */\n readonly reducedMotion?: boolean | (() => boolean);\n /**\n * Batched drawing: every item that changed is drawn in one pass per frame, after the items step: each one's\n * drawable, then this, once, with all of their frames. Changes made between frames (a new target, a hold) are\n * drawn on the next frame, or now by {@link LayoutMotion.flush}. Without it, each item is drawn as it changes.\n */\n readonly onDraw?: (batch: readonly DrawEntry[]) => void;\n /**\n * Called when frames start running (true) and when they stop (false: nothing moves any more), once per change, and\n * with false on `dispose` while they run. The one way to learn that the layout is idle; a test awaits\n * {@link LayoutMotion.idle} instead.\n */\n readonly onActiveChange?: (active: boolean) => void;\n}\n\n/**\n * Layout motion: items with an id and a target rect, each settled to its place on one shared frame loop.\n *\n * Give an item a new place ({@link LayoutItem.moveTo}) and it glides there from wherever it is drawn: the window\n * motion rules of `values/` (settle, reveal, popIn) applied to every item at once. The loop runs only while\n * something moves, or a task asks for frames, and stops by itself.\n *\n * A rect placed by a jump glides on only once it is seen: a frame of the loop has ended after it reached the screen\n * (see {@link LayoutItem}). An unbatched jump asks the loop for that one frame as a task, once per burst of jumps:\n * `loop.active` and the loop's queue count show it, as they show any scheduled task, but it is not a movement, so\n * `onActiveChange` is not called and {@link LayoutMotion.idle} does not wait for it. \"Seen\" is the clock's word: a\n * frame is the clock's statement that what was drawn before it ended is now presented (`ClockPort.requestFrame`).\n *\n * Three statements reach it: `jumpTo` and `add` say \"be here\", and motion checks them; `hold` and `glideFrom` say \"it\n * is on screen here\", and motion believes them; {@link LayoutMotion.rebase} says \"the frame the rects are measured in\n * moved, and nothing moved on screen\", and motion changes its numbers and nothing else.\n *\n * It only animates the rects it is given: which items move where, and when, is the caller's layout.\n */\nexport interface LayoutMotion {\n /**\n * Add an item drawn by `drawable`, at `at`, shown (or gone: `{ shown: false }`). Its content is laid out at once.\n * `jumpTo` and `add` say \"be here\", and motion checks them; `hold` and `glideFrom` say \"it is on screen here\", and\n * motion believes them: a target given before a frame has seen `at` is a jump. {@link LayoutMotion.rebase} says\n * \"the frame moved, and nothing moved on screen\", and changes no seen-ness. To animate an entrance, add it at its\n * place and {@link LayoutItem.glideFrom} where it comes from.\n */\n add(id: string, drawable: Drawable, at: Rect, options?: { readonly shown?: boolean }): LayoutItem;\n get(id: string): LayoutItem | undefined;\n /** Stop moving an item (its drawable is not touched again). */\n remove(id: string): void;\n /** Remove every item whose id is not in `ids` (the ones that left the layout). */\n retain(ids: Iterable<string>): void;\n /**\n * With {@link LayoutMotionOptions.onDraw}: draw the items changed since the last frame now, outside the loop. A\n * host calls it right after it commits a new layout, so the next paint shows every item where it is drawn, not a\n * frame at its new box. Without batching each item is already drawn as it changes, and it does nothing. It hands\n * the batch to the host but ends no frame: a jump flushed and then given a target still jumps.\n */\n flush(): void;\n /**\n * The frame the rects are measured in moved by (`dx`, `dy`) on screen, and nothing moved on screen: the third\n * statement, beside \"be here\" (`jumpTo`, `add`) and \"it is on screen here\" (`hold`, `glideFrom`). Motion subtracts\n * (`dx`, `dy`) from every item's drawn rect, target and box (a glide's start and goal with them) and changes nothing\n * else: each item keeps its velocity, its appearance (shown, showing, the fade) and whether a jumped rect has been\n * seen, in both directions. A host whose container moves on screen in a commit (a bar appears above the items)\n * calls it with the container's move, then gives its new targets as usual: every item stays where it is on screen\n * and glides on from there.\n *\n * It is the caller's word, like `hold`: motion cannot check that the frame moved. Never use it to move items: a\n * rebase with no matching move of the frame moves every item on screen with no glide, and still counts it as seen.\n * It comes first in a commit: every rect given after it is in the new frame. A host's own {@link LayoutTask} that\n * keeps rects of the frame rebases them itself; motion holds none of a task's state. Likewise, a host holding rects\n * through {@link holdItem} (the pointer's, a slot) gives them again in the new frame.\n *\n * Each moved box reaches its drawable through `layOut` (the same size at a new place), and each item is drawn in\n * the same paint: unbatched, at once; batched, the items are marked changed and the loop is asked for one write as a\n * task (as for the frame after an unbatched jump), not a movement: `onActiveChange` is not called and `idle()` does\n * not wait for it. A host may still `flush()` right after its commit. The same paint holds for a call from the\n * host's commit, not from inside `onDraw`.\n *\n * `except`: ids of items not measured in that frame (an item drawn in a layer of a frame that did not move); they\n * are left untouched. Unknown ids are ignored. A number that is not finite reads as 0, and (0, 0) does nothing at\n * all. Reduced motion changes nothing: a rebase is not a glide.\n */\n rebase(dx: number, dy: number, options?: { readonly except?: Iterable<string> }): void;\n readonly items: ReadonlyMap<string, LayoutItem>;\n /** Run `task` on every frame, before the items step; returns how to stop it. */\n task(task: LayoutTask): () => void;\n /** Call `listener` on every frame, after the items have stepped and been drawn; returns how to stop it. */\n onFrame(listener: (frame: FrameInfo) => void): () => void;\n /** Make sure at least one more frame runs (a task has something to do). */\n wake(): void;\n /** Set the tempo for every item (and the ones added later). */\n configure(config: { readonly omega?: number }): void;\n /**\n * Resolves once nothing moves (at once if nothing does): for a test. A host learns it from\n * {@link LayoutMotionOptions.onActiveChange}. Right after a jump it resolves at once, before the frame that sees the\n * jump: a target given then is still a jump. A test that means \"drawn and seen\" runs a frame (`clock.frame()`).\n */\n idle(): Promise<void>;\n /** Stop the frames and forget every item. */\n dispose(): void;\n}\n\n/** Two rects the same within a hundredth of a pixel. */\nconst same = (a: Rect, b: Rect): boolean =>\n Math.abs(a.x - b.x) < 0.01 && Math.abs(a.y - b.y) < 0.01 && Math.abs(a.width - b.width) < 0.01 && Math.abs(a.height - b.height) < 0.01;\nconst copy = (r: Rect): Rect => ({ x: r.x, y: r.y, width: r.width, height: r.height });\n\n/** Create the {@link LayoutMotion} for one surface. */\nexport function createLayoutMotion(options: LayoutMotionOptions): LayoutMotion {\n const { loop } = options;\n const phase = options.phase ?? \"layout\";\n const popFrom = options.popFrom ?? 0.87;\n let omega = options.omega ?? SETTLE_TEMPO.default;\n const items = new Map<string, LayoutItem>();\n const steps = new Map<string, (dt: number) => boolean>();\n const tasks = new Set<LayoutTask>();\n const frames = new Set<(frame: FrameInfo) => void>();\n const tempos = new Set<() => void>();\n /** What removing an item undoes besides its entry (its tempo hook). */\n const removers = new Map<string, () => void>();\n /** How to move each item's numbers when the frame moved ({@link LayoutMotion.rebase}). */\n const rebasers = new Map<string, (dx: number, dy: number) => void>();\n /** Cancels the write asked for to draw a batched rebase, while it is pending. */\n let rebasing: (() => void) | null = null;\n let waiters: (() => void)[] = [];\n let stop: (() => void) | null = null;\n let woken = false;\n let ticking = false;\n let active = false;\n const reduced = (): boolean => (typeof options.reducedMotion === \"function\" ? options.reducedMotion() : options.reducedMotion === true);\n const { onDraw, onActiveChange } = options;\n /** Batched drawing: how to draw each item, and the ones that changed since the last batch. */\n const drawers = new Map<string, () => DrawEntry>();\n const dirty = new Set<string>();\n /**\n * Items whose drawn rect was placed by a jump and is not seen yet: the count of the loop's ended frames when the\n * rect reached the screen (unbatched: drawn at the jump; batched: written by a batch), or null while no batch has\n * written it. The loop counts a frame only after all of its phases ran, so the rect is seen once that count has\n * grown, and a target later in the same frame, in any phase or order, still jumps. The count is `framesEnded`,\n * which `resetStats()` never touches.\n */\n const unseen = new Map<string, number | null>();\n /** Cancels the frame asked for to see the unbatched jumps, while it is pending. */\n let seeing: (() => void) | null = null;\n const ended = (): number => loop.framesEnded;\n /** The one function the frame to see jumps runs, so a burst of jumps queues one task. */\n const sawFrame = (): void => {\n seeing = null;\n };\n /** A rect placed by a jump (\"be here\"). Under reduced motion every target is a jump already: nothing to record. */\n const jumped = (id: string): void => {\n if (reduced()) return;\n unseen.set(id, onDraw ? null : ended());\n if (!onDraw && !seeing) seeing = loop.schedule(\"write\", sawFrame);\n };\n const isUnseen = (id: string): boolean => {\n const at = unseen.get(id);\n if (at === undefined) return false;\n if (at === null || at === ended()) return true;\n unseen.delete(id);\n return false;\n };\n /**\n * The caller says it is on screen (`hold`, `glideFrom`), or it left. When no jump is left to see, the frame asked\n * for them is cancelled, so a loop shared with other work isn't kept busy by this one.\n */\n const seen = (id: string): void => {\n unseen.delete(id);\n if (!seeing) return;\n const now = ended();\n for (const [other, at] of unseen) if (at !== null && at !== now) unseen.delete(other);\n if (unseen.size === 0) {\n seeing();\n seeing = null;\n }\n };\n\n const setActive = (on: boolean): void => {\n if (on === active) return;\n active = on;\n onActiveChange?.(on);\n };\n\n const wake = (): void => {\n woken = true;\n if (stop) return;\n stop = loop.repeat(phase, tick);\n setActive(true);\n };\n\n /** Draw every item that changed, then hand the batch over once. */\n function writeBatch(): void {\n if (!onDraw || dirty.size === 0) return;\n const batch: DrawEntry[] = [];\n for (const id of dirty) {\n const entry = drawers.get(id)?.();\n if (entry) batch.push(entry);\n // A jumped rect reaches the screen when a batch writes it.\n if (unseen.get(id) === null) unseen.set(id, ended());\n }\n dirty.clear();\n if (batch.length > 0) onDraw(batch);\n }\n\n /** The one function the write asked for by a batched rebase runs, so a burst of rebases queues one task. */\n const wroteRebase = (): void => {\n rebasing = null;\n writeBatch();\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- a task or listener of this frame may wake the loop again (it sets `woken`), which the rule can't follow\n if (moving || woken) return true;\n stop = null;\n setActive(false);\n const resolve = waiters;\n waiters = [];\n for (const r of resolve) r();\n return false;\n }\n\n function add(id: string, drawable: Drawable, at: Rect, opts: { readonly shown?: boolean } = {}): LayoutItem {\n if (items.has(id)) throw new Error(`layout motion: item \"${id}\" is already added (remove it first)`);\n const rect: Settle<Rect> = createSettle<Rect>(copy(at), { omega });\n // A number from 0 to 1: rest within a thousandth, not the default tenth (tuned for pixels).\n const pop: Settle<number> = createSettle(opts.shown === false ? 0 : 1, { omega, restDelta: 0.001 });\n let box = copy(at);\n const frameOf = (): DrawFrame => {\n const drawn = rect.value;\n return { drawn, box, reveal: reveal(drawn, box), pop: popIn(pop.value, popFrom), shown: pop.value, gone: pop.settled && pop.value === 0 };\n };\n const drawNow = (): DrawEntry => {\n const frame = frameOf();\n drawable.draw(frame);\n return { id, frame };\n };\n // Batched: mark it changed (the batch draws it); a change between frames asks for a frame to draw it in.\n const draw = (): void => {\n if (!onDraw) {\n drawNow();\n return;\n }\n dirty.add(id);\n if (!ticking) wake();\n };\n const layOut = (to: Rect): void => {\n box = copy(to);\n drawable.layOut(box);\n };\n /** Head for `to`: a settle from the drawn rect, or (reduced motion) there at once. */\n const aim = (to: Rect): void => {\n if (reduced()) {\n rect.jumpTo(copy(to));\n draw();\n return;\n }\n rect.setTarget(copy(to));\n wake();\n };\n /** It moved on the last step (so the step that brings it to rest still draws it, batched). */\n let moved = false;\n const tempo = (): void => {\n rect.configure({ omega });\n pop.configure({ omega });\n };\n const item: LayoutItem = {\n id,\n get drawn() {\n return rect.value;\n },\n get target() {\n return rect.target;\n },\n get box() {\n return box;\n },\n get settled() {\n return rect.settled;\n },\n get shown() {\n return pop.value;\n },\n get showing() {\n return pop.target === 1;\n },\n get shownSettled() {\n return pop.settled;\n },\n moveTo(to) {\n if (same(box, to) && same(rect.target, to)) return;\n // Placed by a jump and not seen yet: no frame showed where a glide would start, so this is a jump too.\n if (isUnseen(id)) {\n item.jumpTo(to);\n return;\n }\n layOut(to);\n // Laid out in the new box now: draw it at once at the drawn rect, else until the next frame it would show\n // the old offset from the new box (a dropped item would flash a frame away from where it was let go).\n draw();\n if (same(rect.target, to)) return;\n aim(to);\n },\n retarget(to) {\n if (to.width !== box.width || to.height !== box.height) {\n item.moveTo(to);\n return;\n }\n if (same(rect.target, to)) return;\n // Not seen yet: a jump, keeping the content laid out in its box as a retarget does.\n if (isUnseen(id)) {\n rect.jumpTo(copy(to));\n draw();\n jumped(id);\n return;\n }\n aim(to);\n },\n jumpTo(to) {\n layOut(to);\n rect.jumpTo(copy(to));\n draw();\n jumped(id);\n },\n glideFrom(from, to) {\n rect.jumpTo(copy(from));\n layOut(to);\n draw();\n aim(to);\n // The caller's word: `from` is on screen.\n seen(id);\n },\n hold(r) {\n rect.jumpTo(copy(r));\n draw();\n // The caller's word: `r` is on screen (where the pointer holds it), so a drop right after it glides.\n seen(id);\n },\n show(on, o = {}) {\n const want = on ? 1 : 0;\n if (o.now || reduced()) pop.jumpTo(want);\n else if (pop.target !== want) {\n pop.setTarget(want);\n wake();\n }\n draw();\n },\n redraw: draw,\n };\n drawers.set(id, drawNow);\n // The frame moved: the same place on screen in the new frame's numbers. Velocity, the fade and seen-ness stay.\n rebasers.set(id, (dx, dy) => {\n translateSettle(rect, { x: -dx, y: -dy, width: 0, height: 0 });\n box = { x: box.x - dx, y: box.y - dy, width: box.width, height: box.height };\n drawable.layOut(box);\n if (onDraw) dirty.add(id);\n else drawNow();\n });\n drawable.layOut(box);\n draw();\n items.set(id, item);\n // Placed at once: an add says \"be here\", like a jump.\n jumped(id);\n tempos.add(tempo);\n steps.set(id, (dt) => {\n const a = rect.step(dt);\n const b = pop.step(dt);\n // Batched, only an item that moved is drawn; else every item, every frame.\n if (!onDraw || a || b || moved) draw();\n moved = a || b;\n return a || b;\n });\n removers.set(id, () => {\n tempos.delete(tempo);\n drawers.delete(id);\n rebasers.delete(id);\n dirty.delete(id);\n });\n return item;\n }\n\n function remove(id: string): void {\n items.delete(id);\n steps.delete(id);\n removers.get(id)?.();\n removers.delete(id);\n seen(id);\n }\n\n return {\n add,\n get: (id) => items.get(id),\n remove,\n retain(ids) {\n const keep = new Set(ids);\n for (const id of [...items.keys()]) if (!keep.has(id)) remove(id);\n },\n flush: writeBatch,\n rebase(dx, dy, opts = {}) {\n const x = Number.isFinite(dx) ? dx : 0;\n const y = Number.isFinite(dy) ? dy : 0;\n if (x === 0 && y === 0) return;\n const except = new Set(opts.except ?? []);\n let moved = false;\n for (const [id, move] of rebasers) {\n if (except.has(id)) continue;\n move(x, y);\n moved = true;\n }\n // Batched: written in this paint. A frame's own tick writes them; else one write is asked for, a task and not a\n // movement (as the frame after an unbatched jump), so `idle()` and `onActiveChange` stay about movement.\n if (onDraw && moved && !ticking && !rebasing) rebasing = loop.schedule(\"write\", wroteRebase);\n },\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 rebasers.clear();\n unseen.clear();\n seeing?.();\n seeing = null;\n rebasing?.();\n rebasing = null;\n const resolve = waiters;\n waiters = [];\n for (const r of resolve) r();\n },\n };\n}\n","import type { Point, Rect } from \"../shapes\";\nimport type { LayoutItem } from \"./motion\";\n\n/**\n * An item held by a pointer: the real item (no copy) follows the pointer 1:1 from where it was grabbed, at the size\n * it was lifted at; its place stays reserved (that is the caller's layout). Then:\n *\n * - {@link HeldDrag.snapTo}: glide into a slot (a snap preview); `null` leaves the slot and glides back to the\n * pointer, following it as it moves ({@link HeldDrag.follow} once a frame), until it is under it again.\n * - {@link HeldDrag.land}: let go into a slot: the landing settles from where it was let go (the release rect), never\n * from its old home. Snapped into that slot already, it simply finishes that glide.\n * - {@link HeldDrag.cancel}: let go with no drop: it glides home from where it was let go.\n * - {@link HeldDrag.preview}: the three drop previews, per frame: indicator and gap keep the item under the pointer\n * (gap with the caller's room open), snap glides it into the slot; leaving glides it back to the pointer.\n * - {@link HeldDrag.resize}: the item takes a new size mid-drag (its content laid out anew by the caller), held at the\n * caller's `grab` in it where given: it settles to it from where it is drawn, the size revealed (never stretched),\n * and is held 1:1 again once there.\n */\nexport interface HeldDrag {\n /** Where the pointer is (null before the first move). */\n readonly pointer: Point | null;\n /** Where the pointer holds the item: the pointer less the grab offset, at the held size (lifted, or resized). */\n readonly held: Rect | null;\n /** The slot it sits in (a snap), or null. */\n readonly snapped: Rect | null;\n /** It left a slot (or took a new size) and is gliding back to the pointer. */\n readonly returning: boolean;\n /** The pointer moved: held 1:1 (unless it sits in a slot or is on its way back). */\n move(pointer: Point): void;\n /**\n * Into `slot` (a glide from where it is drawn; the same slot again does nothing), or out of the slot it sits in\n * (`null`: back to the pointer). Returns what changed: `\"snapped\"`, `\"left\"`, or null.\n */\n snapTo(slot: Rect | null): \"snapped\" | \"left\" | null;\n /** Once a frame: on its way back, retarget to the pointer; true on the frame it is under the pointer again. */\n follow(): boolean;\n /**\n * Once a frame, a drop preview's part for the item (`plan`: `@n-uf/motion/drag`'s `previewPlan`, or any\n * `{ snapItem }`): with `snapItem` it glides into `slot` (snap); else it stays under the pointer, or glides back to\n * it from a slot it left (indicator, gap). The room, if the plan makes any, is the caller's layout. In place of\n * {@link HeldDrag.snapTo} and {@link HeldDrag.follow}; returns what changed.\n */\n preview(plan: { readonly snapItem: boolean }, slot: Rect | null): \"snapped\" | \"left\" | null;\n /**\n * Hold it at `size` from now on (the caller has laid its content out for that size), the pointer holding it at `grab`\n * (px from the top-left corner at that size: where the caller's new form puts the spot the user pressed, a docking\n * drag's `DockAfter.grab`). Without `grab` the grab point keeps its share of the item. The item settles from where it\n * is drawn to its new held rect, the pointer less `grab` at `size` (its size revealed, never stretched): the held\n * point moves with the size on that one settle, so a still pointer sees both arrive together. Then it is held 1:1\n * again ({@link HeldDrag.follow} once a frame). In a slot it stays there, taking the new size when it leaves. The same\n * size and grab again do nothing; returns true on a change.\n */\n resize(size: { readonly width: number; readonly height: number }, grab?: Point): boolean;\n /** Where the pointer holds the item now, px from its top-left corner at the held size (the lift's, or the last resize's). */\n readonly grab: Point;\n /** Let go into `slot`: returns the release rect, where the landing starts. */\n land(slot: Rect): Rect;\n /** Let go with no drop: glides `home` from the release rect, which it returns. */\n cancel(home: Rect): Rect;\n}\n\n/** How close (px, every component) the way back has to come to count as under the pointer again. */\nconst CAUGHT = 0.5;\n\n/** Hold `item` from the pointer at `grab` (the pointer's offset from its top-left corner), at its drawn size now. */\nexport function holdItem(item: LayoutItem, grab: Point): HeldDrag {\n let size = { width: item.drawn.width, height: item.drawn.height };\n let at = { x: grab.x, y: grab.y };\n let pointer: Point | null = null;\n let snapped: Rect | null = null;\n let returning = false;\n const heldRect = (): Rect | null => (pointer ? { x: pointer.x - at.x, y: pointer.y - at.y, width: size.width, height: size.height } : null);\n const same = (a: Rect, b: Rect): boolean => Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y), Math.abs(a.width - b.width), Math.abs(a.height - b.height)) < 0.01;\n const snapTo = (slot: Rect | null): \"snapped\" | \"left\" | null => {\n if (slot) {\n if (snapped && same(snapped, slot)) return null;\n snapped = { ...slot };\n returning = false;\n item.moveTo(slot);\n return \"snapped\";\n }\n if (!snapped) return null;\n snapped = null;\n returning = true;\n return \"left\";\n };\n const follow = (): boolean => {\n const goal = heldRect();\n if (!returning || !goal) return false;\n // A chase of the pointer: retargeted every frame, laid out again only when its size changes (an item without\n // retarget, from before it or a test double, moves to it).\n if (item.retarget) item.retarget(goal);\n else item.moveTo(goal);\n const d = item.drawn;\n if (Math.max(Math.abs(d.x - goal.x), Math.abs(d.y - goal.y), Math.abs(d.width - goal.width), Math.abs(d.height - goal.height)) >= CAUGHT) return false;\n returning = false;\n item.hold(goal);\n return true;\n };\n const letGo = (to: Rect): Rect => {\n const release = { ...item.drawn };\n snapped = null;\n returning = false;\n item.moveTo(to);\n return release;\n };\n return {\n get pointer() {\n return pointer;\n },\n get held() {\n return heldRect();\n },\n get snapped() {\n return snapped;\n },\n get returning() {\n return returning;\n },\n move(p) {\n pointer = { x: p.x, y: p.y };\n if (snapped || returning) return;\n item.hold(heldRect()!);\n },\n snapTo,\n follow,\n preview(plan, slot) {\n const change = snapTo(plan.snapItem && slot ? slot : null);\n follow();\n return change;\n },\n get grab() {\n return { x: at.x, y: at.y };\n },\n resize(next, grab) {\n const sameSize = Math.abs(next.width - size.width) < 0.01 && Math.abs(next.height - size.height) < 0.01;\n if (sameSize && (!grab || (Math.abs(grab.x - at.x) < 0.01 && Math.abs(grab.y - at.y) < 0.01))) return false;\n // The caller's grab in the new form, else the old one's share of the item.\n at = grab ? { x: grab.x, y: grab.y } : { x: size.width ? (at.x / size.width) * next.width : 0, y: size.height ? (at.y / size.height) * next.height : 0 };\n size = { width: next.width, height: next.height };\n if (!snapped && pointer) {\n returning = true;\n follow();\n }\n return true;\n },\n land: letGo,\n cancel: letGo,\n };\n}\n","import type { Point, Rect } from \"../shapes\";\nimport { createSettle, SETTLE_TEMPO, type SettleConfig } from \"../values/settle\";\n\n/** A width and a height, px. */\nexport interface BoxSize {\n readonly width: number;\n readonly height: number;\n}\n\n/**\n * A box held at a point that changes size about an anchor: the anchor is the spot of the box that sits on the point\n * (a pointer's offset from the box's top-left corner). Its size and its anchor settle together to a new size and the\n * new box's anchor ({@link AnchoredMorph.to}), from wherever they are drawn, so a retarget mid-flight turns at once,\n * with no jump and no overshoot. At every step the anchor lies exactly on the point ({@link AnchoredMorph.rectAt}): a\n * caller who draws the old and the new content each with its own anchor on the point never moves either from under\n * the pointer, and fades between them by {@link AnchoredMorph.progress}.\n */\nexport interface AnchoredMorph {\n /** The size now. */\n readonly size: BoxSize;\n /** The anchor now: its offset from the box's top-left corner. */\n readonly anchor: Point;\n /** Where it is heading. */\n readonly target: { readonly size: BoxSize; readonly anchor: Point };\n /** At rest on the target. */\n readonly settled: boolean;\n /**\n * How far along the way from where the last retarget started to the target, 0 to 1 (1 at rest): to fade the content\n * it came from out and the target's in.\n */\n readonly progress: number;\n /** Head for `size` with `anchor` from where it is drawn. The same target again does nothing; true on a change. */\n to(size: BoxSize, anchor: Point): boolean;\n /** Be at `size` with `anchor` now, at rest. */\n jumpTo(size: BoxSize, anchor: Point): void;\n /** Advance by `dt` ms; true while still moving. */\n step(dt: number): boolean;\n /** The box now with its anchor on `point`. */\n rectAt(point: Point): Rect;\n}\n\n/**\n * The default tempo, a quick settle (`SETTLE_TEMPO.quick`): 90 % of the way in about 60 ms, within 1 % in about\n * 125 ms; the last pixels take longer for large size changes (a 300 px change rests after about 225 ms).\n */\nexport const MORPH_TEMPO = SETTLE_TEMPO.quick;\n\n/** A box of `size` held at `anchor`, at rest; `config` is the settle's (default tempo {@link MORPH_TEMPO}). */\nexport function anchoredMorph(size: BoxSize, anchor: Point, config: SettleConfig = {}): AnchoredMorph {\n // One settle over the four numbers, as a rect: x, y the anchor, width and height the size.\n const pack = (s: BoxSize, a: Point): Rect => ({ x: finite(a.x), y: finite(a.y), width: Math.max(0, finite(s.width)), height: Math.max(0, finite(s.height)) });\n const settle = createSettle<Rect>(pack(size, anchor), { omega: MORPH_TEMPO, ...config });\n let from: Rect = settle.value;\n const gap = (a: Rect, b: Rect): number => Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y), Math.abs(a.width - b.width), Math.abs(a.height - b.height));\n return {\n get size() {\n const v = settle.value;\n return { width: v.width, height: v.height };\n },\n get anchor() {\n const v = settle.value;\n return { x: v.x, y: v.y };\n },\n get target() {\n const t = settle.target;\n return { size: { width: t.width, height: t.height }, anchor: { x: t.x, y: t.y } };\n },\n get settled() {\n return settle.settled;\n },\n get progress() {\n const whole = gap(from, settle.target);\n if (settle.settled || whole < 1e-9) return 1;\n return Math.min(1, Math.max(0, 1 - gap(settle.value, settle.target) / whole));\n },\n to(s, a) {\n const goal = pack(s, a);\n if (gap(goal, settle.target) < 0.01) return false;\n from = settle.value;\n settle.setTarget(goal);\n return true;\n },\n jumpTo(s, a) {\n settle.jumpTo(pack(s, a));\n from = settle.value;\n },\n step(dt) {\n return settle.step(dt);\n },\n 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":";;;;;;;;;AA4OA,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;AAE7C,QAAM,WAAW,oBAAI,IAA8C;AAEnE,MAAI,WAAgC;AACpC,MAAI,UAA0B,CAAC;AAC/B,MAAI,OAA4B;AAChC,MAAI,QAAQ;AACZ,MAAI,UAAU;AACd,MAAI,SAAS;AACb,QAAM,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