@bevelo/motion 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +49 -2
- package/dist/index.cjs +6364 -0
- package/dist/index.d.cts +1832 -0
- package/dist/index.d.ts +1832 -0
- package/dist/index.js +6278 -0
- package/dist/live/flip.cjs +78 -0
- package/dist/live/flip.d.cts +21 -0
- package/dist/live/flip.d.ts +21 -0
- package/dist/live/flip.js +77 -0
- package/dist/live/presence.cjs +7 -0
- package/dist/live/presence.d.cts +2 -0
- package/dist/live/presence.d.ts +2 -0
- package/dist/live/presence.js +1 -0
- package/dist/live/spring-value.cjs +4 -0
- package/dist/live/spring-value.d.cts +41 -0
- package/dist/live/spring-value.d.ts +41 -0
- package/dist/live/spring-value.js +1 -0
- package/dist/presence-BadXSYGX.cjs +499 -0
- package/dist/presence-CbHtzolg.d.cts +126 -0
- package/dist/presence-CbHtzolg.d.ts +126 -0
- package/dist/presence-Dt789xG9.js +470 -0
- package/dist/spring-CfdnEGs4.d.cts +118 -0
- package/dist/spring-CfdnEGs4.d.ts +118 -0
- package/dist/spring-value-D7dvds3M.cjs +373 -0
- package/dist/spring-value-fKpX3pAG.js +338 -0
- package/dist/timeline.cjs +53 -0
- package/dist/timeline.d.cts +61 -0
- package/dist/timeline.d.ts +61 -0
- package/dist/timeline.js +52 -0
- package/package.json +63 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1832 @@
|
|
|
1
|
+
import { C as linear, S as easeSpringSettle, _ as easeOutBack, a as springEasing, b as easeOutQuint, c as cubicBezier, d as easeExit, f as easeIn, g as easeOut, h as easeMove, i as solveSpring, l as easeEmphasis, m as easeInOutCubic, n as SpringConfig, o as springFromDuration, p as easeInOut, r as SpringSolution, s as Easing, t as DEFAULT_SPRING, u as easeEnter, v as easeOutCubic, w as linearEasing, x as easePop, y as easeOutExpo } from "./spring-CfdnEGs4.js";
|
|
2
|
+
import { _ as presenceGroupStep, a as PresenceOptions, c as createPresence, d as PresenceEvent, f as PresenceGroupEntry, g as PresenceState, h as PresenceMode, i as PresenceGroupOptions, l as createPresenceGroup, m as PresenceGroupState, n as PresenceEntry, o as PresenceRunner, p as PresenceGroupEvent, r as PresenceGroup, s as PresenceSnapshot, t as Presence, u as cssRunner, v as presenceStep } from "./presence-CbHtzolg.js";
|
|
3
|
+
import { SpringRunnerOptions, SpringValue, SpringValueOptions, createSpringValue, springRunner } from "./live/spring-value.js";
|
|
4
|
+
import { FlipOptions, FlipRun, flip } from "./live/flip.js";
|
|
5
|
+
import { Timeline, TimelineOptions, createTimeline } from "./timeline.js";
|
|
6
|
+
import { Environment, FrameLoop, Rect, RectCache } from "@bevelo/runtime";
|
|
7
|
+
/**
|
|
8
|
+
* The clock seam. Anything that animates over time takes one of these instead of
|
|
9
|
+
* reading the time itself, which is what makes the motion deterministic.
|
|
10
|
+
*/
|
|
11
|
+
interface Scheduler {
|
|
12
|
+
/** Current time in milliseconds, in the same epoch the frame callback receives. */
|
|
13
|
+
now(): number;
|
|
14
|
+
/**
|
|
15
|
+
* Schedules `callback` for the next frame and returns a handle for {@link Scheduler.cancel}.
|
|
16
|
+
* The callback receives the frame's timestamp, not the time the request was made.
|
|
17
|
+
*/
|
|
18
|
+
request(callback: (now: number) => void): number;
|
|
19
|
+
/** Cancels a pending request. Cancelling an unknown or already-fired handle is a no-op. */
|
|
20
|
+
cancel(handle: number): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A scheduler a test drives by hand. `advance` is the only source of time: no
|
|
24
|
+
* callbacks run until it is called, which is what makes frame-by-frame
|
|
25
|
+
* assertions possible.
|
|
26
|
+
*/
|
|
27
|
+
interface ManualScheduler extends Scheduler {
|
|
28
|
+
/**
|
|
29
|
+
* Moves the clock forward by `ms`, delivering frames on the way at the same
|
|
30
|
+
* cadence requestAnimationFrame would (one frame per {@link FRAME_MS}), so a
|
|
31
|
+
* test observes the same intermediate values a browser would show.
|
|
32
|
+
*
|
|
33
|
+
* The last step is shortened to land exactly on `target`: a test that advances
|
|
34
|
+
* by an animation's duration must see the frame at that duration. Rejected:
|
|
35
|
+
* dropping the partial step, which forces every test to add a trailing tick and
|
|
36
|
+
* makes "advance(300) is finished" false.
|
|
37
|
+
*
|
|
38
|
+
* Throws a RangeError for a negative or non-finite duration; a clock that
|
|
39
|
+
* silently ignores such a value hides a caller bug for the rest of the test.
|
|
40
|
+
*/
|
|
41
|
+
advance(ms: number): void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The real scheduler: performance.now() plus requestAnimationFrame, with a
|
|
45
|
+
* setTimeout(16) fallback for environments that have no rAF (workers, older
|
|
46
|
+
* jsdom, some test runners).
|
|
47
|
+
*
|
|
48
|
+
* Handles come from this module's own counter rather than the browser's: rAF and
|
|
49
|
+
* setTimeout have separate, overlapping id spaces, so using the raw ids would let
|
|
50
|
+
* a cancel hit the wrong pending callback.
|
|
51
|
+
*/
|
|
52
|
+
export declare function createScheduler(): Scheduler;
|
|
53
|
+
/**
|
|
54
|
+
* The scheduler tests use. Frames are delivered one at a time as the clock moves,
|
|
55
|
+
* never batched, because batching would hide the intermediate values a visual
|
|
56
|
+
* regression depends on.
|
|
57
|
+
*/
|
|
58
|
+
export declare function createManualScheduler(): ManualScheduler;
|
|
59
|
+
/**
|
|
60
|
+
* One stop on the progress axis. `easing` shapes the segment that *starts* here;
|
|
61
|
+
* the last frame's easing is never used because there is no segment after it.
|
|
62
|
+
*/
|
|
63
|
+
interface Keyframe$1 {
|
|
64
|
+
/** Position on the timeline, 0..1. Must increase strictly from frame to frame. */
|
|
65
|
+
readonly at: number;
|
|
66
|
+
/** Value to show at `at`. */
|
|
67
|
+
readonly value: number;
|
|
68
|
+
/** Curve for the segment leaving this frame. Defaults to linear. */
|
|
69
|
+
readonly easing?: Easing;
|
|
70
|
+
}
|
|
71
|
+
export declare function sampleFrames(frames: readonly Keyframe$1[], progress: number): number;
|
|
72
|
+
/**
|
|
73
|
+
* Expresses an easing as a keyframe list. This is exact, not a resampling: the
|
|
74
|
+
* easing lives on the single segment, so sampling the result reproduces the curve
|
|
75
|
+
* to the last bit.
|
|
76
|
+
*
|
|
77
|
+
* Rejected: sampling the curve into N linear segments. It quantises the motion
|
|
78
|
+
* (visible on a long spring) and still needs a frame count the caller has to
|
|
79
|
+
* choose without knowing the motion's duration.
|
|
80
|
+
*/
|
|
81
|
+
export declare function framesFromEasing(easing: Easing, from: number, to: number): readonly Keyframe$1[];
|
|
82
|
+
/**
|
|
83
|
+
* Expresses a spring as a keyframe list, using the same normalisation as
|
|
84
|
+
* {@link springEasing}. `from` and `to` come from the config (default 0 and 1),
|
|
85
|
+
* because a spring's endpoints are part of its physical description.
|
|
86
|
+
*/
|
|
87
|
+
export declare function framesFromSpring(config?: SpringConfig): readonly Keyframe$1[];
|
|
88
|
+
/**
|
|
89
|
+
* What the animation needs from its host. The driver is the only thing that knows
|
|
90
|
+
* whether the user asked for reduced motion; the loop just obeys.
|
|
91
|
+
*/
|
|
92
|
+
interface Driver {
|
|
93
|
+
readonly scheduler: Scheduler;
|
|
94
|
+
/** True when the user asked the OS to reduce motion, checked when a motion starts. */
|
|
95
|
+
reducedMotion(): boolean;
|
|
96
|
+
}
|
|
97
|
+
/** A running or finished motion. */
|
|
98
|
+
interface Animation {
|
|
99
|
+
/** True once no further frames will run, whether it completed or was stopped. */
|
|
100
|
+
readonly done: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Ends the motion without calling `onComplete`. Resolves `finished`; idempotent.
|
|
103
|
+
* The target value is *not* forced, because the caller interrupted the motion on
|
|
104
|
+
* purpose (a reversal, a new target) and will set its own value.
|
|
105
|
+
*/
|
|
106
|
+
stop(): void;
|
|
107
|
+
/** Resolves when the motion ends, by completion or by `stop()`. Never rejects. */
|
|
108
|
+
readonly finished: Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Freezes the motion where it is: no frames are requested and `finished` stays
|
|
111
|
+
* pending. `play()` resumes from the same value — the pause is not a jump.
|
|
112
|
+
*/
|
|
113
|
+
pause(): void;
|
|
114
|
+
/** Resumes a paused motion. A no-op while running, paused-never, or done. */
|
|
115
|
+
play(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Swaps the direction of travel: a motion heading for `to` turns back toward
|
|
118
|
+
* `from` and completes there. Reversing twice returns to the original
|
|
119
|
+
* direction. A no-op once `done` — a finished motion does not resurrect.
|
|
120
|
+
*/
|
|
121
|
+
reverse(): void;
|
|
122
|
+
/**
|
|
123
|
+
* The position inside the motion, in milliseconds (0 to `durationMs`).
|
|
124
|
+
* Setting it renders the jumped-to value synchronously — a scrubber sees the
|
|
125
|
+
* card move while paused — but does not restart timing, so a jump mid-flight
|
|
126
|
+
* keeps the current rate. Ignored once `done`.
|
|
127
|
+
*/
|
|
128
|
+
time: number;
|
|
129
|
+
/**
|
|
130
|
+
* Playback rate multiplier: 1 is real time, 2 is double, -1 plays backwards
|
|
131
|
+
* (the same thing `reverse()` sets up). `0` freezes the motion in place like
|
|
132
|
+
* `pause()` but keeps the frame alive. Must be finite.
|
|
133
|
+
*/
|
|
134
|
+
speed: number;
|
|
135
|
+
}
|
|
136
|
+
interface AnimateBase {
|
|
137
|
+
/** Value at the start of the motion: a number, or CSS text ("#fff", "10px 4px"). */
|
|
138
|
+
readonly from: number | string;
|
|
139
|
+
/** Value at the end of the motion, in the same shapes as `from`. */
|
|
140
|
+
readonly to: number | string;
|
|
141
|
+
/** Clock and reduced-motion policy. */
|
|
142
|
+
readonly driver: Driver;
|
|
143
|
+
/** Called once per frame with the interpolated value and its 0..1 progress. */
|
|
144
|
+
readonly onUpdate?: (value: number | string, progress: number) => void;
|
|
145
|
+
/** Called once when the motion reaches the target. Not called after `stop()`. */
|
|
146
|
+
readonly onComplete?: () => void;
|
|
147
|
+
}
|
|
148
|
+
/** A motion whose duration comes from the spring itself. */
|
|
149
|
+
interface SpringAnimateOptions extends AnimateBase {
|
|
150
|
+
readonly spring: SpringConfig;
|
|
151
|
+
}
|
|
152
|
+
/** A motion shaped by a curve over a fixed duration. */
|
|
153
|
+
interface EasingAnimateOptions extends AnimateBase {
|
|
154
|
+
readonly easing: Easing;
|
|
155
|
+
/** Total duration in milliseconds. Defaults to 300. */
|
|
156
|
+
readonly durationMs?: number;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The motion to run: a spring (physical, duration implied) or an easing over a
|
|
160
|
+
* duration. A discriminated union rather than an optional pair, so "both" and
|
|
161
|
+
* "neither" are unrepresentable.
|
|
162
|
+
*/
|
|
163
|
+
type AnimateOptions = SpringAnimateOptions | EasingAnimateOptions;
|
|
164
|
+
/**
|
|
165
|
+
* The numeric-endpoint shape: both ends are numbers, so the callback sees
|
|
166
|
+
* numbers. This is the overwhelmingly common call, and keeping it a separate
|
|
167
|
+
* overload is what lets existing numeric callers keep their `(value: number)`
|
|
168
|
+
* callbacks without a cast — the union type would force every one of them to
|
|
169
|
+
* narrow a string that can never arrive.
|
|
170
|
+
*/
|
|
171
|
+
interface NumericAnimateBase {
|
|
172
|
+
readonly from: number;
|
|
173
|
+
readonly to: number;
|
|
174
|
+
readonly driver: Driver;
|
|
175
|
+
readonly onUpdate?: (value: number, progress: number) => void;
|
|
176
|
+
readonly onComplete?: () => void;
|
|
177
|
+
}
|
|
178
|
+
interface NumericSpringAnimateOptions extends NumericAnimateBase {
|
|
179
|
+
readonly spring: SpringConfig;
|
|
180
|
+
}
|
|
181
|
+
interface NumericEasingAnimateOptions extends NumericAnimateBase {
|
|
182
|
+
readonly easing: Easing;
|
|
183
|
+
readonly durationMs?: number;
|
|
184
|
+
}
|
|
185
|
+
type NumericAnimateOptions = NumericSpringAnimateOptions | NumericEasingAnimateOptions;
|
|
186
|
+
/**
|
|
187
|
+
* Runs a motion from `from` to `to`, sampling it once per scheduler frame.
|
|
188
|
+
*
|
|
189
|
+
* Degenerate motions complete synchronously inside this call with a single update
|
|
190
|
+
* at the target: reduced motion, and a zero-length motion (a spring whose endpoints
|
|
191
|
+
* are equal). Rejected: scheduling one empty frame for them, which delays the
|
|
192
|
+
* final value by a frame for no observable motion and forces callers to handle
|
|
193
|
+
* "done immediately after construction" anyway.
|
|
194
|
+
*
|
|
195
|
+
* The last frame always reports exactly `to` and progress 1, not a value 1e-9
|
|
196
|
+
* short of it, so a component's final state is exactly the requested one.
|
|
197
|
+
*/
|
|
198
|
+
export declare function animate(options: NumericAnimateOptions): Animation;
|
|
199
|
+
export declare function animate(options: AnimateOptions): Animation;
|
|
200
|
+
/**
|
|
201
|
+
* One unit of orchestration: a motion started by a function. Returning a promise
|
|
202
|
+
* means "I am still running"; resolving means "I settled"; rejecting is a failure
|
|
203
|
+
* the orchestrator reports after the contract in question allows it to stop or
|
|
204
|
+
* settle.
|
|
205
|
+
*/
|
|
206
|
+
type Step = () => Promise<void> | void;
|
|
207
|
+
/** Where a stagger starts: the first step, the last, or the middle and outwards. */
|
|
208
|
+
type StaggerFrom = "start" | "end" | "center";
|
|
209
|
+
/**
|
|
210
|
+
* Options every orchestrator accepts, so a caller can build one options value and
|
|
211
|
+
* hand it to any of them. `scheduler` is the clock the orchestration runs on;
|
|
212
|
+
* `reducedMotion` drops any delays the orchestrator would otherwise insert.
|
|
213
|
+
*/
|
|
214
|
+
interface OrchestrationOptions {
|
|
215
|
+
/** The clock time is read from. Nothing in this module schedules a timer. */
|
|
216
|
+
readonly scheduler: Scheduler;
|
|
217
|
+
/** True when the user asked the OS to reduce motion, checked when the run starts. */
|
|
218
|
+
readonly reducedMotion?: boolean;
|
|
219
|
+
}
|
|
220
|
+
/** Options for {@link stagger}: a delay between consecutive step starts. */
|
|
221
|
+
interface StaggerOptions extends OrchestrationOptions {
|
|
222
|
+
/** Milliseconds between consecutive starts. Must be finite and >= 0. */
|
|
223
|
+
readonly delayMs: number;
|
|
224
|
+
/** Which step starts first. Defaults to `"start"`. */
|
|
225
|
+
readonly from?: StaggerFrom;
|
|
226
|
+
}
|
|
227
|
+
/** {@link sequence} has no delay of its own, but takes the shared options shape. */
|
|
228
|
+
type SequenceOptions = OrchestrationOptions;
|
|
229
|
+
/** {@link parallel} starts everything at once, but takes the shared options shape. */
|
|
230
|
+
type ParallelOptions = OrchestrationOptions;
|
|
231
|
+
/** Options for {@link tween}. */
|
|
232
|
+
interface TweenOptions {
|
|
233
|
+
/** Total duration in milliseconds. Defaults to 300. */
|
|
234
|
+
readonly durationMs?: number;
|
|
235
|
+
/** Curve applied to progress. Defaults to {@link linear}. */
|
|
236
|
+
readonly easing?: Easing;
|
|
237
|
+
/** Called once per frame with the sampled value and its 0..1 progress. */
|
|
238
|
+
readonly onUpdate?: (value: number, progress: number) => void;
|
|
239
|
+
/**
|
|
240
|
+
* Cancels the tween. It resolves with the last value it reached, not the target:
|
|
241
|
+
* the caller interrupted the motion on purpose and will set its own value.
|
|
242
|
+
*/
|
|
243
|
+
readonly signal?: AbortSignal;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Tweens a plain number from `from` to `to` over the driver's clock, resolving
|
|
247
|
+
* with the value it ended on.
|
|
248
|
+
*
|
|
249
|
+
* The target is reported exactly, not a float hair short of it, and the promise
|
|
250
|
+
* never rejects: an interrupted tween is a normal outcome. Reduced motion resolves
|
|
251
|
+
* synchronously with `to`; a zero duration does the same.
|
|
252
|
+
*/
|
|
253
|
+
export declare function tween(driver: Driver, from: number, to: number, options?: TweenOptions): Promise<number>;
|
|
254
|
+
/**
|
|
255
|
+
* Runs the steps with `delayMs` between their starts, in the order `from`
|
|
256
|
+
* selects, and resolves once every step has settled.
|
|
257
|
+
*
|
|
258
|
+
* Failures are aggregated like Promise.allSettled: the first step to fail decides
|
|
259
|
+
* the rejection, but the earlier rejection is reported only after the other steps
|
|
260
|
+
* settle, so a caller's cleanup never races a still-running motion. That is the
|
|
261
|
+
* difference from a sequence, which stops at the first failure instead.
|
|
262
|
+
*/
|
|
263
|
+
export declare function stagger(steps: readonly Step[], options: StaggerOptions): Promise<void>;
|
|
264
|
+
/**
|
|
265
|
+
* Runs the steps strictly one after another: step N+1 is started only after step N
|
|
266
|
+
* resolved. Resolves when the last step settles; the first failure stops the run
|
|
267
|
+
* and rejects with that error, so no later step starts after a failure.
|
|
268
|
+
*
|
|
269
|
+
* The scheduler stays in the shared options shape, but a sequence has no delay of
|
|
270
|
+
* its own to measure: starting the next step in the microtask after the previous
|
|
271
|
+
* one resolved is exactly "as soon as possible", and inserting a frame would add
|
|
272
|
+
* 16ms of dead time per step. Reduced motion is therefore a no-op here — there is
|
|
273
|
+
* no delay to drop — which is why the caller sees the same order either way.
|
|
274
|
+
*/
|
|
275
|
+
export declare function sequence(steps: readonly Step[], options: SequenceOptions): Promise<void>;
|
|
276
|
+
/**
|
|
277
|
+
* Starts every step in the same tick, then resolves once all of them settled.
|
|
278
|
+
*
|
|
279
|
+
* Failure reporting follows {@link stagger} (allSettled semantics, first error
|
|
280
|
+
* wins); nothing here can be delayed, so reduced motion and the scheduler have
|
|
281
|
+
* nothing to change beyond being part of the shared options shape.
|
|
282
|
+
*/
|
|
283
|
+
export declare function parallel(steps: readonly Step[], options: ParallelOptions): Promise<void>;
|
|
284
|
+
/** An element's box in viewport coordinates, as getBoundingClientRect reports it. */
|
|
285
|
+
interface LayoutRect {
|
|
286
|
+
readonly x: number;
|
|
287
|
+
readonly y: number;
|
|
288
|
+
readonly width: number;
|
|
289
|
+
readonly height: number;
|
|
290
|
+
}
|
|
291
|
+
/** One measurement of an element. Plain data: a snapshot never reads the DOM again. */
|
|
292
|
+
interface LayoutSnapshot {
|
|
293
|
+
readonly rect: LayoutRect;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The difference between two snapshots as a compositor transform.
|
|
297
|
+
*
|
|
298
|
+
* `translate` moves the element's top-left corner and `scale` changes its size
|
|
299
|
+
* around that corner; both are expressed in the coordinate space of the *from*
|
|
300
|
+
* element and assume the top-left transform origin.
|
|
301
|
+
*/
|
|
302
|
+
interface LayoutTransform {
|
|
303
|
+
readonly translateX: number;
|
|
304
|
+
readonly translateY: number;
|
|
305
|
+
readonly scaleX: number;
|
|
306
|
+
readonly scaleY: number;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* The part of an element this module needs. Structural rather than `HTMLElement`
|
|
310
|
+
* so a test can supply a plain object and a real element satisfies it unchanged.
|
|
311
|
+
*/
|
|
312
|
+
interface LayoutElement {
|
|
313
|
+
getBoundingClientRect(): LayoutRect;
|
|
314
|
+
readonly style: {
|
|
315
|
+
transform: string;
|
|
316
|
+
transformOrigin?: string;
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
/** Clock, reduced-motion policy and the shape of the flip. Durations are milliseconds. */
|
|
320
|
+
interface LayoutOptions {
|
|
321
|
+
/**
|
|
322
|
+
* Clock and the user's reduced-motion preference. Optional so the documented
|
|
323
|
+
* `{ durationMs, easing }` call works: without one, the binding uses a real
|
|
324
|
+
* scheduler and `prefers-reduced-motion`. A component that already owns a
|
|
325
|
+
* clock (or a test) injects its own, which is what makes the flip deterministic.
|
|
326
|
+
*/
|
|
327
|
+
readonly driver?: Driver;
|
|
328
|
+
/** How long the flip takes. Defaults to 300. */
|
|
329
|
+
readonly durationMs?: number;
|
|
330
|
+
/** Curve for the flip. Defaults to a cubic ease-out ("settle into place"). */
|
|
331
|
+
readonly easing?: Easing;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Reads an element's box.
|
|
335
|
+
*
|
|
336
|
+
* The rect is copied, not kept live: a DOMRect is re-read on property access in
|
|
337
|
+
* some engines, and a snapshot that changes underneath the caller would make the
|
|
338
|
+
* before/after pair meaningless.
|
|
339
|
+
*/
|
|
340
|
+
export declare function measure(element: LayoutElement): LayoutSnapshot;
|
|
341
|
+
/**
|
|
342
|
+
* The compositor transform that maps `from` onto `to`: a move becomes a
|
|
343
|
+
* translation, a resize becomes a scale about the top-left corner.
|
|
344
|
+
*
|
|
345
|
+
* A zero-width or zero-height source cannot be scaled (any factor would be
|
|
346
|
+
* infinity), so that axis reports scale 1: the element simply appears at its
|
|
347
|
+
* target size instead of growing from nothing.
|
|
348
|
+
*
|
|
349
|
+
* Throws a RangeError for non-finite snapshots — a plausible-looking transform
|
|
350
|
+
* built from NaN is worse than a loud failure.
|
|
351
|
+
*/
|
|
352
|
+
export declare function flipTransform(from: LayoutSnapshot, to: LayoutSnapshot): LayoutTransform;
|
|
353
|
+
/**
|
|
354
|
+
* The FLIP step for one element: writes the transform that undoes the difference
|
|
355
|
+
* between the two measurements, then animates it back to none.
|
|
356
|
+
*
|
|
357
|
+
* Returns void because a caller that does not care about completion (a component
|
|
358
|
+
* that just re-renders) should not have to hold a promise. layoutAnimation is the
|
|
359
|
+
* variant that waits. Calling it again for the same element before the motion
|
|
360
|
+
* ends cancels the previous flip and starts from the new snapshots.
|
|
361
|
+
*/
|
|
362
|
+
export declare function applyTransform(element: LayoutElement, from: LayoutSnapshot, to: LayoutSnapshot, options?: LayoutOptions): void;
|
|
363
|
+
/**
|
|
364
|
+
* Runs a layout change and animates every listed element from its old position to
|
|
365
|
+
* its new one.
|
|
366
|
+
*
|
|
367
|
+
* `run` is called between the two measurements and is expected to change the DOM
|
|
368
|
+
* synchronously — that is the whole contract. All "before" rects are read before
|
|
369
|
+
* anything is written, so a transform on one element can never distort the
|
|
370
|
+
* measurement of another.
|
|
371
|
+
*
|
|
372
|
+
* Resolves when every motion has finished. Under reduced motion the callback still
|
|
373
|
+
* runs (the layout must change) but no transform is written and the promise
|
|
374
|
+
* resolves at once.
|
|
375
|
+
*/
|
|
376
|
+
export declare function layoutAnimation(elements: readonly LayoutElement[], run: () => void, options?: LayoutOptions): Promise<void>;
|
|
377
|
+
/** A segment's value and velocity at one instant. */
|
|
378
|
+
interface Evaluated {
|
|
379
|
+
/** The value, in the property's own units. */
|
|
380
|
+
readonly value: number;
|
|
381
|
+
/** Units per second. */
|
|
382
|
+
readonly velocity: number;
|
|
383
|
+
}
|
|
384
|
+
/** One closed-form piece of motion. */
|
|
385
|
+
interface Segment {
|
|
386
|
+
readonly durationMs: number;
|
|
387
|
+
/** Sample at `elapsedMs` since the segment started. Clamped to its own bounds. */
|
|
388
|
+
at(elapsedMs: number): Evaluated;
|
|
389
|
+
/** True once `elapsedMs` is at or past `durationMs`. */
|
|
390
|
+
done(elapsedMs: number): boolean;
|
|
391
|
+
}
|
|
392
|
+
/** The names a policy may use instead of an easing function. */
|
|
393
|
+
type EaseName = "linear" | "easeIn" | "easeOut" | "easeInOut" | "easeOutCubic" | "easeInOutCubic" | "easeOutQuint" | "easeOutExpo" | "easeOutBack" | "easeEnter" | "easeExit" | "easeMove" | "easeEmphasis" | "easePop" | "easeSpringSettle";
|
|
394
|
+
/** An easing: a named one, four bezier numbers, a function, or one per keyframe segment. */
|
|
395
|
+
type Ease = Easing | readonly [number, number, number, number] | EaseName | readonly (Easing | EaseName | readonly [number, number, number, number])[];
|
|
396
|
+
/** How a repeated segment alternates: restart, or play backwards on odd reps. */
|
|
397
|
+
type RepeatType = "loop" | "reverse" | "mirror";
|
|
398
|
+
/**
|
|
399
|
+
* Timing modifiers every policy accepts, independent of its kind: wait before
|
|
400
|
+
* travelling, and travel again. They live on the policy rather than the
|
|
401
|
+
* transition bag because the policy is what builds the segment — the
|
|
402
|
+
* decorators (pure/decorators.ts) fold them into the same closed form.
|
|
403
|
+
*/
|
|
404
|
+
interface SegmentTiming {
|
|
405
|
+
/** Milliseconds to hold the start value before the motion begins. */
|
|
406
|
+
readonly delayMs?: number;
|
|
407
|
+
/** Extra plays after the first: repeat 2 is three traversals. */
|
|
408
|
+
readonly repeat?: number;
|
|
409
|
+
readonly repeatType?: RepeatType;
|
|
410
|
+
/** Rest between repetitions, in milliseconds. */
|
|
411
|
+
readonly repeatDelayMs?: number;
|
|
412
|
+
}
|
|
413
|
+
/** A physical spring. `velocity` is in units per second and is the initial velocity. */
|
|
414
|
+
interface TimingOverrides extends Omit<SegmentTiming, "delayMs"> {
|
|
415
|
+
readonly delayMs?: number | (() => number);
|
|
416
|
+
}
|
|
417
|
+
interface SpringPolicy extends SegmentTiming {
|
|
418
|
+
readonly type: "spring";
|
|
419
|
+
readonly stiffness?: number;
|
|
420
|
+
readonly damping?: number;
|
|
421
|
+
readonly mass?: number;
|
|
422
|
+
/** Initial velocity, in units per second. */
|
|
423
|
+
readonly velocity?: number;
|
|
424
|
+
/** Distance below which the spring is considered at rest, in the property's units. */
|
|
425
|
+
readonly restDistance?: number;
|
|
426
|
+
/** Velocity below which the spring is considered at rest, in units per second. */
|
|
427
|
+
readonly restVelocity?: number;
|
|
428
|
+
}
|
|
429
|
+
/** A curve over a fixed duration. */
|
|
430
|
+
interface TweenPolicy extends SegmentTiming {
|
|
431
|
+
readonly type: "tween";
|
|
432
|
+
readonly durationMs?: number;
|
|
433
|
+
readonly ease?: Ease;
|
|
434
|
+
}
|
|
435
|
+
/** An explicit list of values, with optional times and per-segment easing. */
|
|
436
|
+
interface KeyframesPolicy extends SegmentTiming {
|
|
437
|
+
readonly type: "keyframes";
|
|
438
|
+
readonly values: readonly number[];
|
|
439
|
+
/** Normalised 0..1 stops, same length as `values`. Defaults to an even spread. */
|
|
440
|
+
readonly times?: readonly number[];
|
|
441
|
+
readonly ease?: Ease;
|
|
442
|
+
readonly durationMs?: number;
|
|
443
|
+
}
|
|
444
|
+
/** A released value with momentum: drag release, a fling, a flick. */
|
|
445
|
+
interface InertiaPolicy extends SegmentTiming {
|
|
446
|
+
readonly type: "inertia";
|
|
447
|
+
readonly power?: number;
|
|
448
|
+
readonly timeConstant?: number;
|
|
449
|
+
/** Bounds the value bounces against, when given. */
|
|
450
|
+
readonly min?: number;
|
|
451
|
+
readonly max?: number;
|
|
452
|
+
readonly bounceStiffness?: number;
|
|
453
|
+
readonly bounceDamping?: number;
|
|
454
|
+
}
|
|
455
|
+
/** Lands in one write. Reduced motion's positional path, and an explicit "no animation". */
|
|
456
|
+
interface InstantPolicy extends SegmentTiming {
|
|
457
|
+
readonly type: "instant";
|
|
458
|
+
}
|
|
459
|
+
/** How a track gets from one value to another. */
|
|
460
|
+
type Policy = SpringPolicy | TweenPolicy | KeyframesPolicy | InertiaPolicy | InstantPolicy;
|
|
461
|
+
/** A policy's kind, for diagnostics and for the selected default. */
|
|
462
|
+
type PolicyKind = Policy["type"];
|
|
463
|
+
/** Everything a segment builder needs: where it is, where it goes, how fast it is already moving. */
|
|
464
|
+
interface SegmentInput {
|
|
465
|
+
readonly from: number;
|
|
466
|
+
readonly to: number;
|
|
467
|
+
/** Units per second at the moment the segment starts. */
|
|
468
|
+
readonly velocity: number;
|
|
469
|
+
}
|
|
470
|
+
/** A policy resolved once, into something that builds segments. */
|
|
471
|
+
type SegmentFactory = (input: SegmentInput) => Segment;
|
|
472
|
+
/** The result of resolving a policy: its kind, and the factory. */
|
|
473
|
+
interface ResolvedPolicy {
|
|
474
|
+
readonly kind: PolicyKind;
|
|
475
|
+
readonly build: SegmentFactory;
|
|
476
|
+
readonly restDistance?: number;
|
|
477
|
+
}
|
|
478
|
+
/** Which family a property belongs to, which decides its default policy. */
|
|
479
|
+
type PropertyRole = "transform" | "scale" | "opacity" | "color" | "other";
|
|
480
|
+
/** A value after parsing: what the interpolator and the writer need to know. */
|
|
481
|
+
type ParsedValue = {
|
|
482
|
+
readonly kind: "number";
|
|
483
|
+
readonly value: number;
|
|
484
|
+
} | {
|
|
485
|
+
readonly kind: "unit";
|
|
486
|
+
readonly value: number;
|
|
487
|
+
readonly unit: string;
|
|
488
|
+
} | {
|
|
489
|
+
readonly kind: "color";
|
|
490
|
+
readonly r: number;
|
|
491
|
+
readonly g: number;
|
|
492
|
+
readonly b: number;
|
|
493
|
+
readonly a: number;
|
|
494
|
+
} |
|
|
495
|
+
/** Several animatable numbers inside one string, e.g. "0px 4px rgba(0,0,0,.2)". */
|
|
496
|
+
{
|
|
497
|
+
readonly kind: "complex";
|
|
498
|
+
readonly format: (values: readonly number[]) => string;
|
|
499
|
+
readonly values: readonly number[];
|
|
500
|
+
} |
|
|
501
|
+
/** Not interpolatable; the target wins at the end of the segment. */
|
|
502
|
+
{
|
|
503
|
+
readonly kind: "opaque";
|
|
504
|
+
readonly text: string;
|
|
505
|
+
};
|
|
506
|
+
/**
|
|
507
|
+
* Turns a policy's easing into a function.
|
|
508
|
+
*
|
|
509
|
+
* A four-number array is a cubic bezier. A function is used as it is. A named
|
|
510
|
+
* easing is looked up. An *array of easings* is only meaningful for keyframes
|
|
511
|
+
* (one per segment), so it is rejected here rather than silently using the first.
|
|
512
|
+
*/
|
|
513
|
+
export declare function resolveEase(ease?: Ease): Easing;
|
|
514
|
+
/**
|
|
515
|
+
* A spring segment. `from`/`to`/`velocity` come from the input; the physics from
|
|
516
|
+
* the policy.
|
|
517
|
+
*
|
|
518
|
+
* `durationMs` is the solver's own settling time, unless the policy names rest
|
|
519
|
+
* thresholds, in which case the segment ends as soon as both are met — which is
|
|
520
|
+
* what makes a spring *feel* settled at 0.5 px rather than only when its velocity
|
|
521
|
+
* has decayed to the solver's default 1e-3 units per second.
|
|
522
|
+
*/
|
|
523
|
+
export declare function springSegment(policy: SpringPolicy, input: SegmentInput): Segment;
|
|
524
|
+
/** A tween segment: an ease over a duration, both with defaults. */
|
|
525
|
+
export declare function tweenSegment(policy: TweenPolicy, input: SegmentInput): Segment;
|
|
526
|
+
/**
|
|
527
|
+
* A keyframe segment: N values with times and per-segment easing.
|
|
528
|
+
*
|
|
529
|
+
* The first and last values replace `input.from`/`input.to`: a keyframes policy
|
|
530
|
+
* owns its endpoints, and `input` only says when the segment starts. Rejected
|
|
531
|
+
* alternative — blending the input endpoints with the list — makes the same policy
|
|
532
|
+
* describe different motion depending on what segment ran before it, which is
|
|
533
|
+
* exactly the ambiguity a policy is supposed to remove.
|
|
534
|
+
*/
|
|
535
|
+
export declare function keyframesSegment(policy: KeyframesPolicy, input: SegmentInput): Segment;
|
|
536
|
+
/**
|
|
537
|
+
* An inertia segment: an exponential decay, with a bounce when bounds are given.
|
|
538
|
+
*
|
|
539
|
+
* Velocity decays as `v0 * e^(-t / timeConstant)` and the value approaches
|
|
540
|
+
* `from + v0 * timeConstant`, which is the physical shape of a flick: fast at the
|
|
541
|
+
* release, then a long tail. `to` from the input is ignored on purpose — a
|
|
542
|
+
* released value has no target; asking for one is a spring.
|
|
543
|
+
*/
|
|
544
|
+
export declare function inertiaSegment(policy: InertiaPolicy, input: SegmentInput): Segment;
|
|
545
|
+
/** A segment that is already at its target. */
|
|
546
|
+
export declare function instantSegment(input: SegmentInput): Segment;
|
|
547
|
+
/**
|
|
548
|
+
* Resolves a policy once. An already-resolved policy is returned as it is, so a
|
|
549
|
+
* caller can resolve at setup and pass the result down — including a policy that
|
|
550
|
+
* was resolved for a *different* role: it was resolved deliberately, and
|
|
551
|
+
* re-resolving it against this property's role would quietly replace the caller's
|
|
552
|
+
* choice with a default. No policy means the default for the property's role.
|
|
553
|
+
*
|
|
554
|
+
* `timing` is stage-level orchestration timing (a staggered entrance, say): it
|
|
555
|
+
* wraps whatever the policy resolves to — including the role default, which a
|
|
556
|
+
* transition bag alone could never reach because it carries no kind. Delay
|
|
557
|
+
* composes additively with the policy's own delayMs, which is what "parent delay
|
|
558
|
+
* plus own delay" means; the other fields only apply when the policy did not
|
|
559
|
+
* name them.
|
|
560
|
+
*/
|
|
561
|
+
export declare function resolvePolicy(policy?: Policy | ResolvedPolicy, role?: PropertyRole, timing?: TimingOverrides): ResolvedPolicy;
|
|
562
|
+
/**
|
|
563
|
+
* The policy a property gets when nothing says otherwise.
|
|
564
|
+
*
|
|
565
|
+
* The numbers are the ones that make a component kit feel right: a transform on a
|
|
566
|
+
* spring stiff enough to feel attached, a scale slightly stiffer (a scale that
|
|
567
|
+
* overshoots reads as a mistake, not as bounce), and everything else on the house
|
|
568
|
+
* tween.
|
|
569
|
+
*/
|
|
570
|
+
export declare function defaultPolicy(role: PropertyRole): Policy;
|
|
571
|
+
/** The kinds a resolved policy can be, for diagnostics. */
|
|
572
|
+
export declare const POLICY_KINDS: readonly PolicyKind[];
|
|
573
|
+
interface RepeatOptions {
|
|
574
|
+
/** Extra plays after the first: repeat 2 is three traversals. */
|
|
575
|
+
readonly count: number;
|
|
576
|
+
readonly type?: RepeatType;
|
|
577
|
+
/** Rest between repetitions, in milliseconds. The first play has no lead-in gap. */
|
|
578
|
+
readonly gapMs?: number;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Holds the segment's start value — with zero velocity — until `delayMs` has
|
|
582
|
+
* passed, then plays the inner segment untouched.
|
|
583
|
+
*
|
|
584
|
+
* Velocity is zero during the wait on purpose: a spring's `at(0)` reports its
|
|
585
|
+
* launch velocity, and a value that is not moving yet must not claim one —
|
|
586
|
+
* the track's continuity math would inherit a velocity the element never had.
|
|
587
|
+
*/
|
|
588
|
+
export declare function delaySegment(inner: Segment, delayMs: number): Segment;
|
|
589
|
+
/**
|
|
590
|
+
* Plays the segment `count` extra times.
|
|
591
|
+
*
|
|
592
|
+
* - loop: every rep restarts from the segment's start — the value jumps back.
|
|
593
|
+
* - reverse/mirror: odd reps play the segment backwards (elapsed folded through
|
|
594
|
+
* `duration - t`, velocity negated). "mirror" is an alias: for a closed-form
|
|
595
|
+
* segment, reflecting time IS mirroring the motion.
|
|
596
|
+
*
|
|
597
|
+
* During `gapMs` the rep's end value holds with zero velocity. An infinite
|
|
598
|
+
* count never reports done — the stage keeps sampling, which is exactly what a
|
|
599
|
+
* loading pulse wants.
|
|
600
|
+
*/
|
|
601
|
+
export declare function repeatSegment(inner: Segment, options: RepeatOptions): Segment;
|
|
602
|
+
/** Parses a value once, so a frame never parses a string twice. */
|
|
603
|
+
export declare function parseValue(input: number | string): ParsedValue;
|
|
604
|
+
/**
|
|
605
|
+
* Interpolates two parsed values at `progress` 0..1. Same kind in, same kind out;
|
|
606
|
+
* a kind mismatch falls back to the target, because a wrong midpoint is worse than
|
|
607
|
+
* a hard switch.
|
|
608
|
+
*
|
|
609
|
+
* At progress 1 every branch returns the target *itself*, not `from + (to - from) * 1`,
|
|
610
|
+
* which is one rounding away from it: a track finishes by writing this value, and the
|
|
611
|
+
* host asked for exactly that value.
|
|
612
|
+
*/
|
|
613
|
+
export declare function mixValue(from: ParsedValue, to: ParsedValue, progress: number): number | string;
|
|
614
|
+
/** What a track needs from its stage. */
|
|
615
|
+
interface TrackDeps {
|
|
616
|
+
/** The stage's policy, inherited when the spec has none. */
|
|
617
|
+
readonly policy?: Policy | ResolvedPolicy;
|
|
618
|
+
/** The stage's per-property policies, consulted before `policy`. */
|
|
619
|
+
readonly policies?: Readonly<Record<string, Policy | ResolvedPolicy>>;
|
|
620
|
+
/** The stage's orchestration timing, applied on top of the resolved policy. */
|
|
621
|
+
readonly timing?: TimingOverrides;
|
|
622
|
+
/** Whether the user asked for reduced motion; positional travel lands instead. */
|
|
623
|
+
readonly reducedMotion?: () => boolean;
|
|
624
|
+
/** Called after each sample, with the track, so the stage can write and schedule. */
|
|
625
|
+
readonly onChange?: (track: Track) => void;
|
|
626
|
+
/**
|
|
627
|
+
* Asks the stage for a frame. `launch()` needs it: a release that starts travel is standing
|
|
628
|
+
* demand, and unlike a sample there is no compute pass to notice it.
|
|
629
|
+
*/
|
|
630
|
+
readonly request?: () => void;
|
|
631
|
+
}
|
|
632
|
+
/** Creates a track from a spec. The stage registers it and samples it once per frame. */
|
|
633
|
+
export declare function createTrack(spec: TrackSpec, deps?: TrackDeps): Track;
|
|
634
|
+
/** What a value track needs from its stage — TrackDeps minus the numeric intent. */
|
|
635
|
+
interface ValueTrackDeps extends TrackDeps {
|
|
636
|
+
/** Resolves a pair the pure decomposer cannot share, such as % and calc(). */
|
|
637
|
+
readonly resolve?: (from: string, to: string) => {
|
|
638
|
+
readonly from: string;
|
|
639
|
+
readonly to: string;
|
|
640
|
+
} | undefined;
|
|
641
|
+
}
|
|
642
|
+
interface ValueKeyframesPolicy extends Omit<KeyframesPolicy, "values"> {
|
|
643
|
+
readonly values: readonly (number | string)[];
|
|
644
|
+
}
|
|
645
|
+
interface ValueTrackSpec extends Omit<TrackSpec, "intent" | "keyframes"> {
|
|
646
|
+
/** The host's target as text: "#fff", "10px 4px", "20%". */
|
|
647
|
+
readonly intent: () => string;
|
|
648
|
+
readonly keyframes?: () => ValueKeyframesPolicy | undefined;
|
|
649
|
+
}
|
|
650
|
+
interface ValueLaunchInput {
|
|
651
|
+
/** Where the lanes start. Defaults to the current formatted value. */
|
|
652
|
+
readonly value?: string | number;
|
|
653
|
+
/** Where to travel. Defaults to the intent. */
|
|
654
|
+
readonly to?: string | number;
|
|
655
|
+
/** Retimes every lane's travel. Per-lane velocity is not carried (see launch). */
|
|
656
|
+
readonly policy?: Policy;
|
|
657
|
+
}
|
|
658
|
+
/** A track whose value is CSS text. Same lifecycle as Track, string instead of number. */
|
|
659
|
+
interface ValueTrack {
|
|
660
|
+
readonly name: string;
|
|
661
|
+
/** The formatted value the last sampled frame produced. */
|
|
662
|
+
value(): string;
|
|
663
|
+
/** True when no lane has a segment in flight and the value is the intent. */
|
|
664
|
+
readonly settled: boolean;
|
|
665
|
+
/** Advance one frame: re-plan if the intent changed, then sample every lane. */
|
|
666
|
+
sample(now: number): boolean;
|
|
667
|
+
/** Use this policy for every lane's next retarget. */
|
|
668
|
+
updatePolicy(policy?: Policy | ResolvedPolicy, role?: PropertyRole, timing?: TimingOverrides): void;
|
|
669
|
+
/** Write a value with no travel: parses it and lands every lane. */
|
|
670
|
+
jump(to: string | number): void;
|
|
671
|
+
/** Retarget with travel, per lane. Velocity is per-lane and not caller-set. */
|
|
672
|
+
launch(input?: ValueLaunchInput): void;
|
|
673
|
+
/** Notified once per frame with the formatted value. Returns the unsubscribe. */
|
|
674
|
+
subscribe(listener: (value: string) => void): () => void;
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Creates a value track. `spec.intent` is read as text; each sample compares it
|
|
678
|
+
* with the last plan's source and, on change, decomposes (current → target)
|
|
679
|
+
* into per-lane targets the lane tracks then chase with full continuity.
|
|
680
|
+
*/
|
|
681
|
+
export declare function createValueTrack(spec: ValueTrackSpec, deps?: ValueTrackDeps): ValueTrack;
|
|
682
|
+
/** What a track needs to run. */
|
|
683
|
+
interface TrackSpec {
|
|
684
|
+
/** The property it drives: a transform channel (x, scale), or a CSS property (opacity). */
|
|
685
|
+
readonly name: string;
|
|
686
|
+
/** Internal input tracks can feed derived values without becoming a CSS property. */
|
|
687
|
+
readonly write?: boolean;
|
|
688
|
+
/** The desired value right now. Read once per frame; a change re-segments from continuity. */
|
|
689
|
+
readonly intent: () => number;
|
|
690
|
+
/**
|
|
691
|
+
* A keyframe sequence the intent currently names, or undefined for ordinary
|
|
692
|
+
* single-target travel. When present, a change in the sequence — not just in
|
|
693
|
+
* its last stop — re-segments through the stops: the segment plays
|
|
694
|
+
* values[0]…values[n] and lands on the last, which is also what `intent()`
|
|
695
|
+
* reports as the target. The getter is read once per sample, so a new array
|
|
696
|
+
* on the next render replays the path without re-registering the track.
|
|
697
|
+
*/
|
|
698
|
+
readonly keyframes?: () => KeyframesPolicy | undefined;
|
|
699
|
+
/** Distinguishes an intentional replay from an equal array on a new render. */
|
|
700
|
+
readonly keyframeRevision?: () => string | number;
|
|
701
|
+
/** On initial=false, mount at the resting stop instead of playing the mount sequence. */
|
|
702
|
+
readonly settleKeyframes?: boolean;
|
|
703
|
+
/** How to travel. Defaults to the policy of the stage, then to the role's default. */
|
|
704
|
+
readonly policy?: Policy | ResolvedPolicy;
|
|
705
|
+
/** Which family the property belongs to; decides the default policy. */
|
|
706
|
+
readonly role?: PropertyRole;
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* What a host hands a track when it wants to start travel itself.
|
|
710
|
+
*
|
|
711
|
+
* The case this exists for: a gesture has been moving the element with `jump()`, which is
|
|
712
|
+
* the right tool while the pointer owns the value (no travel to interpolate, no velocity to
|
|
713
|
+
* inherit). On release the host knows two things the track does not — where the element was
|
|
714
|
+
* let go and how fast — and wants the travel to continue from there. Without this the only
|
|
715
|
+
* way was to re-target with `jump()` (velocity zeroed, so the throw is gone) or to sample an
|
|
716
|
+
* inertia segment by hand in a frame job, which is engine work leaking into a component.
|
|
717
|
+
*
|
|
718
|
+
* Rejected alternative: a `velocity` field on the spec, read once at registration. A release
|
|
719
|
+
* velocity is known at release, not at registration.
|
|
720
|
+
*/
|
|
721
|
+
interface LaunchInput {
|
|
722
|
+
/** Where the element is now. Defaults to the value on screen. */
|
|
723
|
+
readonly value?: number;
|
|
724
|
+
/** Units per second it is moving. Defaults to 0 — a launch from rest. */
|
|
725
|
+
readonly velocity?: number;
|
|
726
|
+
/** Where to travel. Defaults to the intent, which is the usual case: the resting slot. */
|
|
727
|
+
readonly to?: number;
|
|
728
|
+
/**
|
|
729
|
+
* How to travel, for this launch only.
|
|
730
|
+
*
|
|
731
|
+
* A track's policy is resolved when it registers, which is right for state-driven travel:
|
|
732
|
+
* the same element interrupts the same way all session. A throw is not that — the release
|
|
733
|
+
* velocity wants an inertia policy while the snap back on the same lane wants a spring —
|
|
734
|
+
* and re-registering a track to change its curve would lose the continuity that made
|
|
735
|
+
* launching worth it. Omitted means the track's own policy.
|
|
736
|
+
*/
|
|
737
|
+
readonly policy?: Policy;
|
|
738
|
+
}
|
|
739
|
+
/** One animatable lane with continuity. */
|
|
740
|
+
interface Track {
|
|
741
|
+
readonly name: string;
|
|
742
|
+
/** The value the last sampled frame produced. */
|
|
743
|
+
value(): number;
|
|
744
|
+
/** Units per second at the last sample. */
|
|
745
|
+
velocity(): number;
|
|
746
|
+
/** True when no segment is in flight and the value is the intent. */
|
|
747
|
+
readonly settled: boolean;
|
|
748
|
+
/**
|
|
749
|
+
* Advance one frame: re-segment if the intent changed, then sample. Returns true while
|
|
750
|
+
* a segment is still running, which is the stage's cue to request a frame.
|
|
751
|
+
*/
|
|
752
|
+
sample(now: number): boolean;
|
|
753
|
+
/** Use this policy for the next retarget without interrupting the current segment. */
|
|
754
|
+
updatePolicy(policy?: Policy | ResolvedPolicy, role?: PropertyRole, timing?: TimingOverrides): void;
|
|
755
|
+
/** Jump to a value without animating: a gesture moving the target, or reduced motion. */
|
|
756
|
+
jump(to: number): void;
|
|
757
|
+
/**
|
|
758
|
+
* Start travel from a value and a velocity the host measured — the release of a drag.
|
|
759
|
+
*
|
|
760
|
+
* The segment begins on the next frame (so the launch value is what that frame reports) and
|
|
761
|
+
* travels to the intent's target unless `to` names another. It requests a frame by itself:
|
|
762
|
+
* a launch is standing demand, unlike registering a track. Non-finite fields are ignored
|
|
763
|
+
* rather than thrown on, because a pointer stream that produced NaN must not crash the
|
|
764
|
+
* handler that ends a gesture.
|
|
765
|
+
*/
|
|
766
|
+
launch(input?: LaunchInput): void;
|
|
767
|
+
/** Notified once per frame with the sampled value. Returns the unsubscribe. */
|
|
768
|
+
subscribe(listener: (value: number) => void): () => void;
|
|
769
|
+
}
|
|
770
|
+
/** A value computed from other tracks, once per frame, after its inputs. */
|
|
771
|
+
interface DerivedTrack {
|
|
772
|
+
readonly name: string;
|
|
773
|
+
/** The inputs it reads, by name; used to order the pass and to reject cycles. */
|
|
774
|
+
readonly inputs: readonly string[];
|
|
775
|
+
value(): number | string;
|
|
776
|
+
}
|
|
777
|
+
/** What a stage needs. */
|
|
778
|
+
interface StageOptions {
|
|
779
|
+
/** The loop decisions are taken on. Defaults to the process frame loop. */
|
|
780
|
+
readonly frame?: FrameLoop;
|
|
781
|
+
/** The policy every track on this stage inherits unless it declares its own. */
|
|
782
|
+
readonly policy?: Policy;
|
|
783
|
+
/**
|
|
784
|
+
* Per-property policies, keyed by track name: `x` gets its own curve while
|
|
785
|
+
* `opacity` keeps the stage default. A name absent from the map falls through
|
|
786
|
+
* to `policy`, then to the role default — the same order a spec's own
|
|
787
|
+
* `policy` field already uses.
|
|
788
|
+
*/
|
|
789
|
+
readonly policies?: Readonly<Record<string, Policy | ResolvedPolicy>>;
|
|
790
|
+
/**
|
|
791
|
+
* Timing every track inherits: delay before the first play, repeats after it.
|
|
792
|
+
* Unlike `policy` this composes with whatever each track resolves to —
|
|
793
|
+
* including the role defaults — which is what an orchestration stagger needs:
|
|
794
|
+
* children keep their own curves and only their start times fan out.
|
|
795
|
+
*/
|
|
796
|
+
readonly timing?: TimingOverrides;
|
|
797
|
+
/** Whether the user asked for reduced motion. Defaults to the runtime environment. */
|
|
798
|
+
readonly reducedMotion?: () => boolean;
|
|
799
|
+
/** A label for diagnostics and test failures. */
|
|
800
|
+
readonly name?: string;
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* One element's visual state.
|
|
804
|
+
*
|
|
805
|
+
* The stage is the only thing that writes the element's style, and it writes each
|
|
806
|
+
* property once per frame. It owns the tracks for the element, evaluates them in the
|
|
807
|
+
* compute pass, and flushes them in the write pass — which is what makes "two
|
|
808
|
+
* subsystems fight over one transform" impossible rather than unlikely.
|
|
809
|
+
*
|
|
810
|
+
* One property can be handed to someone else: `claim()` takes a lane away from the
|
|
811
|
+
* stage's own passes, and `adopt()` is how the value the screen reached comes back. The
|
|
812
|
+
* pair exists for acceleration, where the browser owns a composited transform channel
|
|
813
|
+
* for the length of one segment.
|
|
814
|
+
*/
|
|
815
|
+
interface Stage {
|
|
816
|
+
readonly element: Element;
|
|
817
|
+
/**
|
|
818
|
+
* Ask the frame loop for a frame because something an intent reads has changed.
|
|
819
|
+
*
|
|
820
|
+
* Registering a job is not standing demand: the loop sleeps when nothing asks. A
|
|
821
|
+
* track that is animating asks from inside its own sample; everything else is the
|
|
822
|
+
* host's job — a component calls this from the effect that reads its state, so the
|
|
823
|
+
* engine never has to poll a signal it does not know about.
|
|
824
|
+
*/
|
|
825
|
+
request(): void;
|
|
826
|
+
/** Update future retargets after a host commit; in-flight segments keep their curve. */
|
|
827
|
+
update(options: Pick<StageOptions, "policy" | "policies" | "timing">): void;
|
|
828
|
+
/** Registers a track. Names are unique per stage; a duplicate throws. */
|
|
829
|
+
track(spec: TrackSpec): Track;
|
|
830
|
+
/**
|
|
831
|
+
* Registers a track whose value is CSS text rather than a number: a colour, a
|
|
832
|
+
* unit pair, a complex string. The same lifecycle as `track`, with the value
|
|
833
|
+
* decomposed into numeric lanes underneath (live/bundle.ts).
|
|
834
|
+
*
|
|
835
|
+
* Names share the track namespace, so a property is either numeric or textual
|
|
836
|
+
* for the life of the stage — a host that might write `x: "50%"` registers a
|
|
837
|
+
* value track up front. `claim`/`adopt` do not apply: acceleration only ever
|
|
838
|
+
* takes transform and opacity lanes, which are numeric. A derived value may
|
|
839
|
+
* not read one either: its inputs are numbers.
|
|
840
|
+
*/
|
|
841
|
+
valueTrack(spec: ValueTrackSpec): ValueTrack;
|
|
842
|
+
/**
|
|
843
|
+
* Takes a lane away from the stage: while the claim is outstanding, the write pass does
|
|
844
|
+
* not write this channel or property and the track for it does not sample.
|
|
845
|
+
*
|
|
846
|
+
* This is the missing half of "one writer per property". A driver that hands a whole
|
|
847
|
+
* segment to the browser (`createWaapiDriver`) owns that property for the length of the
|
|
848
|
+
* run, so the stage must stop writing it — otherwise the inline style and the animation
|
|
849
|
+
* disagree about who is right, and a later plain write silently loses to the browser's
|
|
850
|
+
* fill. Claiming is by name, so a name with no track is a valid claim: a host may claim a
|
|
851
|
+
* lane before it registers the track, and the claim then applies when the track arrives.
|
|
852
|
+
* The name is the track's name, not the CSS spelling: the writer treats `x` and
|
|
853
|
+
* `translateX` as one lane, but a claim matches one string, so a driver must be handed the
|
|
854
|
+
* name the stage's track has.
|
|
855
|
+
*
|
|
856
|
+
* The claim is counted, not a boolean: twice-claimed returns a second release, and the
|
|
857
|
+
* lane is the stage's again only when the last one runs. Returns the release, which is
|
|
858
|
+
* idempotent — a teardown path that runs twice must not release a claim it no longer
|
|
859
|
+
* holds. Rejected alternative: a non-counted `claim()/release()` pair, which cannot tell
|
|
860
|
+
* "the second animation on this lane finished" apart from the claim "the first one did".
|
|
861
|
+
*
|
|
862
|
+
* Two consequences the host inherits. `settled` still reports the claimed track's own
|
|
863
|
+
* state, so a lane claimed mid-segment reads as unsettled until the run releases and
|
|
864
|
+
* adopts — presence waits for the handover, which is the run's completion, not a lie about
|
|
865
|
+
* the value. And a lane a derived value reads must not be claimed: the derived pass reads
|
|
866
|
+
* the track's last value, which is exactly the disagreement `WaapiRunOptions.pure` refuses
|
|
867
|
+
* to accelerate.
|
|
868
|
+
*/
|
|
869
|
+
claim(name: string): () => void;
|
|
870
|
+
/**
|
|
871
|
+
* Takes a value the screen already shows as the track's own, without animating to it.
|
|
872
|
+
*
|
|
873
|
+
* The seam `claim()` needs on the way out: when the browser finishes (or is demoted, or
|
|
874
|
+
* cancelled), the element is on the run's last value while the track still remembers the
|
|
875
|
+
* one before it. Releasing without adopting makes the next state-driven change travel
|
|
876
|
+
* from where the track was — a visible jump at exactly the handover this pair exists to
|
|
877
|
+
* hide. Adoption jumps the track: value and target become `value`, velocity zero, and a
|
|
878
|
+
* segment in flight is dropped, because the motion that was in flight belonged to the
|
|
879
|
+
* browser and is over.
|
|
880
|
+
*
|
|
881
|
+
* It is a separate call rather than a parameter on the release because the release does
|
|
882
|
+
* not know the value: only the owner of the run does, and a claim can also be released
|
|
883
|
+
* with nothing to adopt. Rejected alternative: a `launch()`-shaped adopt with a
|
|
884
|
+
* velocity, which would restart travel in the same call — the handover is "this is where
|
|
885
|
+
* we are", and the host's next state change is what starts the next travel.
|
|
886
|
+
*
|
|
887
|
+
* A name with no track, or a non-finite value from a pointer stream, is ignored: this is
|
|
888
|
+
* called from teardown and demotion paths that must not throw.
|
|
889
|
+
*/
|
|
890
|
+
adopt(name: string, value: number): void;
|
|
891
|
+
/** Move a live channel to a gesture's value without starting a new segment. */
|
|
892
|
+
jump(name: string, value: number | string): void;
|
|
893
|
+
/** Registers a derived value. Inputs must already exist; a cycle throws. */
|
|
894
|
+
derived(name: string, inputs: readonly string[], compute: (values: Readonly<Record<string, number>>) => number | string): DerivedTrack;
|
|
895
|
+
/** The last sampled value of a track, or undefined when the stage does not own that name. */
|
|
896
|
+
value(name: string): number | string | undefined;
|
|
897
|
+
/** Writes the current values to the DOM. Runs in the write beat. */
|
|
898
|
+
flush(): void;
|
|
899
|
+
/** The static style for the current intent, with no animation: the server render, reduced motion, a test. */
|
|
900
|
+
present(): Readonly<Record<string, string>>;
|
|
901
|
+
/** Frames the element's current bounding box, through the runtime cache when it has one. */
|
|
902
|
+
readonly rect: () => Rect;
|
|
903
|
+
/** True when every track has settled. */
|
|
904
|
+
readonly settled: boolean;
|
|
905
|
+
/** Removes every track, job and listener. */
|
|
906
|
+
dispose(): void;
|
|
907
|
+
}
|
|
908
|
+
/** What a writer can be asked to write. */
|
|
909
|
+
interface StyleWriter {
|
|
910
|
+
/** Set a value. Transform channels are composed into one transform; anything else is one property. */
|
|
911
|
+
set(property: string, value: number | string): void;
|
|
912
|
+
/** Write everything that changed since the last flush, in one pass. */
|
|
913
|
+
flush(): void;
|
|
914
|
+
/** The style that would be written next, without writing. Used by present() and tests. */
|
|
915
|
+
peek(): Readonly<Record<string, string>>;
|
|
916
|
+
/** True when a write is pending. */
|
|
917
|
+
readonly dirty: boolean;
|
|
918
|
+
/** Leaves the element as it is. Called on teardown. */
|
|
919
|
+
destroy(): void;
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* A whole-element intent: property to value, the shape a host writes.
|
|
923
|
+
*
|
|
924
|
+
* The engine itself deals in one intent per track (a function), which is what keeps a track
|
|
925
|
+
* from re-segmenting when an unrelated property changes. This type is the convenience the
|
|
926
|
+
* adapters and the docs share: this element wants y 240 and opacity 1, and a stage turns it
|
|
927
|
+
* into one track per key.
|
|
928
|
+
*/
|
|
929
|
+
type StageIntent = Readonly<Record<string, number | string>>;
|
|
930
|
+
/** True for a channel composed into transform (x, scale, rotate...). */
|
|
931
|
+
export declare function isTransformChannel(property: string): boolean;
|
|
932
|
+
/** True for a channel written to transform-origin (originX, originY). */
|
|
933
|
+
export declare function isOriginChannel(property: string): boolean;
|
|
934
|
+
/** A value as CSS text: numbers formatted once, strings used as given. */
|
|
935
|
+
export declare function formatCssValue(value: number | string): string;
|
|
936
|
+
/** One channel as CSS text, using the unit a number means for that channel. */
|
|
937
|
+
export declare function formatChannelValue(property: string, value: number): string;
|
|
938
|
+
/**
|
|
939
|
+
* Composes transform channels into one transform value. Pure: no element, no state,
|
|
940
|
+
* which is what lets present() produce a transform for a server render.
|
|
941
|
+
*
|
|
942
|
+
* Order: translate3d -> scale -> rotate -> skew. Each group is emitted only when one of
|
|
943
|
+
* its channels was set, so an element that only moves pays for one function. The 2D and
|
|
944
|
+
* 3D spellings of the same axis are one lane by design (translateX over x, rotateZ over
|
|
945
|
+
* rotate, scaleX/scaleY over scale): the long form wins, so two components that use
|
|
946
|
+
* different names for the same axis cannot double the travel.
|
|
947
|
+
*/
|
|
948
|
+
export declare function composeTransform(channels: Readonly<Record<string, number | string>>): string;
|
|
949
|
+
/**
|
|
950
|
+
* Composes origin channels into one transform-origin value. The missing axis is written
|
|
951
|
+
* as 50%, CSS's own default: setting originX alone must not move the vertical origin to
|
|
952
|
+
* 0, which is what a single-value transform-origin would do.
|
|
953
|
+
*/
|
|
954
|
+
export declare function composeOrigin(origins: Readonly<Record<string, number | string>>): string;
|
|
955
|
+
/** Creates a writer bound to one element. It reads nothing; every write is explicit. */
|
|
956
|
+
export declare function createStyleWriter(element: Element): StyleWriter;
|
|
957
|
+
/** The loop a stage, a scroll source or a presence list uses when the host passes none. */
|
|
958
|
+
export declare function processFrameLoop(): FrameLoop;
|
|
959
|
+
export declare function formatDOMValue(property: string, value: number | string): string;
|
|
960
|
+
export declare function readDOMValue(element: Element, property: string, fallback: string): string;
|
|
961
|
+
/**
|
|
962
|
+
* The environment a stage uses when it is given none.
|
|
963
|
+
*
|
|
964
|
+
* Created on first use, not at import: importing this module on a server must not install a
|
|
965
|
+
* matchMedia listener that nothing will read. One per module graph is the point — a media
|
|
966
|
+
* query per stage would be a media query per component.
|
|
967
|
+
*/
|
|
968
|
+
/** Creates a stage for an element. One stage per element; the caller owns disposal. */
|
|
969
|
+
export declare function createStage(element: Element, options?: StageOptions): Stage;
|
|
970
|
+
/** How a registered element takes part in a commit. */
|
|
971
|
+
type SceneMode = "position" | "size" | "shared";
|
|
972
|
+
/** What one registration declares. */
|
|
973
|
+
interface SceneRegisterOptions {
|
|
974
|
+
/**
|
|
975
|
+
* How the element moves. Defaults to "position": a translate is exact in any containing
|
|
976
|
+
* block, while a scale needs a correction for everything inside it — so it is opt-in.
|
|
977
|
+
*/
|
|
978
|
+
readonly mode?: SceneMode;
|
|
979
|
+
/**
|
|
980
|
+
* The name two elements are matched by across one commit, required by "shared".
|
|
981
|
+
*
|
|
982
|
+
* The leaving element has to actually leave during the commit — removed from the
|
|
983
|
+
* document or unregistered inside run() — because that is what makes it the one whose
|
|
984
|
+
* box the arrival takes, without the scene guessing from geometry.
|
|
985
|
+
*/
|
|
986
|
+
readonly sharedId?: string;
|
|
987
|
+
}
|
|
988
|
+
/** What a scene needs. */
|
|
989
|
+
interface SceneOptions {
|
|
990
|
+
/** The loop projections are sampled on. Required, like a group's: a scene has no element to inherit one from. */
|
|
991
|
+
readonly frame: FrameLoop;
|
|
992
|
+
/** The policy every projection inherits. Defaults to the house policy for the role. */
|
|
993
|
+
readonly policy?: Policy;
|
|
994
|
+
/** Whether the user asked for reduced motion. Defaults to the runtime environment. */
|
|
995
|
+
readonly reducedMotion?: () => boolean;
|
|
996
|
+
/** How long the shared crossfade takes. Defaults to 300 ms; the morph itself follows the policy. */
|
|
997
|
+
readonly crossfadeMs?: number;
|
|
998
|
+
/**
|
|
999
|
+
* The cache projections are measured through. Defaults to one of the scene's own; a host
|
|
1000
|
+
* that already measured this layout (a sortable space, a drop target) shares its cache
|
|
1001
|
+
* rather than measuring the same elements twice.
|
|
1002
|
+
*/
|
|
1003
|
+
readonly cache?: RectCache;
|
|
1004
|
+
/** A label for diagnostics and test failures. */
|
|
1005
|
+
readonly name?: string;
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* What a public cancel does with the elements it stops.
|
|
1009
|
+
*
|
|
1010
|
+
* The default lands, because "stop animating this projection" almost always means "and let
|
|
1011
|
+
* the element be where it really is". Holding the picture is the exception, so it is the
|
|
1012
|
+
* opt-in: a host that pauses a transition needs the written offset to survive, and writing
|
|
1013
|
+
* identity there would be the jump the pause existed to avoid.
|
|
1014
|
+
*/
|
|
1015
|
+
interface SceneCancelOptions {
|
|
1016
|
+
/**
|
|
1017
|
+
* true (the default): every channel lands on its identity value, so the element sits at its real
|
|
1018
|
+
* layout position and the next commit measures a clean box.
|
|
1019
|
+
* false: the projection freezes where it is, leaving the written offset in place — the caller is
|
|
1020
|
+
* saying "hold this picture", the way a paused transition should.
|
|
1021
|
+
*/
|
|
1022
|
+
readonly land?: boolean;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* A layout space: the elements registered in it, and the one pass that animates a change.
|
|
1026
|
+
*
|
|
1027
|
+
* The scene owns every registered element's transform (and the transform-origin a scale
|
|
1028
|
+
* needs), because one writer per element is the rule the whole live layer exists to keep.
|
|
1029
|
+
*/
|
|
1030
|
+
interface Scene {
|
|
1031
|
+
/**
|
|
1032
|
+
* Adds an element under `id`. The scene does not own the element: the host unregisters
|
|
1033
|
+
* it (or unmounts it) and the scene never removes anything from the document itself.
|
|
1034
|
+
*/
|
|
1035
|
+
register(id: string, element: Element, options?: SceneRegisterOptions): void;
|
|
1036
|
+
/**
|
|
1037
|
+
* Drops an element. An element the host keeps is left at its layout position rather than
|
|
1038
|
+
* on the last written offset, so reusing it elsewhere is safe. Unknown ids are ignored:
|
|
1039
|
+
* teardown paths call this twice and a throw there is a crash during unmount.
|
|
1040
|
+
*/
|
|
1041
|
+
unregister(id: string): void;
|
|
1042
|
+
/**
|
|
1043
|
+
* The whole pass: measure, run the host's synchronous DOM change, measure, invert, and
|
|
1044
|
+
* animate every channel to identity. Resolves when every projection has landed; a commit
|
|
1045
|
+
* that starts nothing resolves at once.
|
|
1046
|
+
*
|
|
1047
|
+
* A commit issued while another is in flight supersedes it (the elements start from their
|
|
1048
|
+
* painted boxes), and both promises resolve when the scene as a whole lands. A run() that
|
|
1049
|
+
* throws propagates synchronously and leaves the scene idle.
|
|
1050
|
+
*/
|
|
1051
|
+
commit(run: () => void): Promise<void>;
|
|
1052
|
+
/** True while at least one projection is travelling. */
|
|
1053
|
+
readonly projecting: boolean;
|
|
1054
|
+
/**
|
|
1055
|
+
* True while at least one element holds a frozen offset from `cancel({ land: false })`.
|
|
1056
|
+
*
|
|
1057
|
+
* The state this makes visible: after a freeze the scene is idle — `projecting` is false,
|
|
1058
|
+
* `settled()` has answered, the loop is asleep — and a transform is still on an element.
|
|
1059
|
+
* A host's "is anything moving?" guard must therefore read `!projecting && !frozen`;
|
|
1060
|
+
* `!projecting` alone is "nothing is travelling", which is a weaker claim. It is a scene
|
|
1061
|
+
* level answer rather than per-element because a freeze is always taken for a group of
|
|
1062
|
+
* elements at once (the cancel), and a host asking "may I take this picture down?" asks
|
|
1063
|
+
* about the picture.
|
|
1064
|
+
*
|
|
1065
|
+
* Derived from the registration flags rather than a counter beside them: a second copy of
|
|
1066
|
+
* "how many are frozen" is state that can drift, and this is one scan of a small map.
|
|
1067
|
+
* Rejected alternative: `frozenIds` — an array that would be allocated per read, for a
|
|
1068
|
+
* question no current host asks; the ids are the host's own, since it registered them.
|
|
1069
|
+
*/
|
|
1070
|
+
readonly frozen: boolean;
|
|
1071
|
+
/**
|
|
1072
|
+
* Resolves when nothing is projecting, immediately when nothing is. This is presence's
|
|
1073
|
+
* question ("may I unmount this yet?") asked of a whole layout space instead of one
|
|
1074
|
+
* element's tracks.
|
|
1075
|
+
*
|
|
1076
|
+
* A frozen scene resolves at once: a held picture is not travelling, and a presence
|
|
1077
|
+
* machine waiting on this must not wait forever for a flight that was cancelled on
|
|
1078
|
+
* purpose. "At rest" is `!projecting && !frozen` — see `frozen`.
|
|
1079
|
+
*/
|
|
1080
|
+
settled(): Promise<void>;
|
|
1081
|
+
/**
|
|
1082
|
+
* Stops every projection now. Resolves the `settled()`/commit promises that were waiting,
|
|
1083
|
+
* and leaves the scene idle. A cancel with nothing projecting does nothing.
|
|
1084
|
+
*
|
|
1085
|
+
* The next commit starts from the painted box either way: a landed element has no offset
|
|
1086
|
+
* left to measure, a frozen one does — and the scene remembers it froze rather than
|
|
1087
|
+
* assuming the element is at rest on its layout box.
|
|
1088
|
+
*
|
|
1089
|
+
* Rejected alternative: an `immediately` flag on commit(), which would thread "stop the
|
|
1090
|
+
* last motion" through the call that starts the next one, for every host that never
|
|
1091
|
+
* cancels anything.
|
|
1092
|
+
*/
|
|
1093
|
+
cancel(options?: SceneCancelOptions): void;
|
|
1094
|
+
/** Stops writing and leaves the elements as they are. Nothing is cancelled into a jump. */
|
|
1095
|
+
dispose(): void;
|
|
1096
|
+
}
|
|
1097
|
+
/** Creates a scene. One scene per layout space; the caller owns disposal. */
|
|
1098
|
+
export declare function createScene(options: SceneOptions): Scene;
|
|
1099
|
+
/** The part of Animation this driver uses, so a test (and a platform without one) can supply its own. */
|
|
1100
|
+
interface WaapiAnimation {
|
|
1101
|
+
cancel(): void;
|
|
1102
|
+
readonly finished: Promise<unknown>;
|
|
1103
|
+
}
|
|
1104
|
+
/** One element.animate call, narrowed to what a segment needs. */
|
|
1105
|
+
type WaapiAnimate = (element: Element, keyframes: Keyframe[], options: KeyframeAnimationOptions) => WaapiAnimation;
|
|
1106
|
+
/** What a driver needs. */
|
|
1107
|
+
interface WaapiDriverOptions {
|
|
1108
|
+
/**
|
|
1109
|
+
* The platform's element.animate. Defaults to it; the driver reads the element's own
|
|
1110
|
+
* method per play rather than at creation, because a driver is reusable across documents
|
|
1111
|
+
* (an iframe, a test window) and a method captured once belongs to the document that
|
|
1112
|
+
* created it.
|
|
1113
|
+
*/
|
|
1114
|
+
readonly animate?: WaapiAnimate;
|
|
1115
|
+
}
|
|
1116
|
+
/** One segment handed to the browser. */
|
|
1117
|
+
interface WaapiRunOptions {
|
|
1118
|
+
/**
|
|
1119
|
+
* A transform channel ("x", "y", "scale", "rotate"…) or a compositable CSS property
|
|
1120
|
+
* ("opacity"). Not "transform": the lane's endpoint is a matrix, not the number the
|
|
1121
|
+
* segment travels through — name the channel.
|
|
1122
|
+
*/
|
|
1123
|
+
readonly property: string;
|
|
1124
|
+
/** Where the segment starts, in the property's own units. */
|
|
1125
|
+
readonly from: number;
|
|
1126
|
+
/** Where it ends. Must be where the function ends: see decision 3. */
|
|
1127
|
+
readonly to: number;
|
|
1128
|
+
/** The closed form to hand over. */
|
|
1129
|
+
readonly segment: Segment;
|
|
1130
|
+
/** The loop the wall clock comes from. */
|
|
1131
|
+
readonly frame: FrameLoop;
|
|
1132
|
+
/**
|
|
1133
|
+
* Declares that no derived value reads this value in the same pass (decision 4).
|
|
1134
|
+
* Defaults to true: the common case is an unconsumed value, and a default of false would
|
|
1135
|
+
* put every eligible segment on the JS path, which is the expensive failure. The caller
|
|
1136
|
+
* that knows a derived lane reads it is the one exception, and it says so.
|
|
1137
|
+
*/
|
|
1138
|
+
readonly pure?: boolean;
|
|
1139
|
+
/**
|
|
1140
|
+
* The element's other transform channels, held at these values in both endpoints. The
|
|
1141
|
+
* writer composes every channel into one transform string, so an animation carrying only
|
|
1142
|
+
* its own channel would erase a static scale or rotation the element has. Ignored for a
|
|
1143
|
+
* CSS property.
|
|
1144
|
+
*/
|
|
1145
|
+
readonly rest?: Readonly<Record<string, number | string>>;
|
|
1146
|
+
/**
|
|
1147
|
+
* The stage the element's visual state belongs to, when the host has one. Passing it makes
|
|
1148
|
+
* the driver take the lane properly: an accelerated run claims `property` while it is in
|
|
1149
|
+
* flight, and completion, cancellation or demotion adopt the value the screen reached and
|
|
1150
|
+
* release the claim, so the stage's next state-driven change travels from where the element
|
|
1151
|
+
* is rather than from where the track was.
|
|
1152
|
+
*
|
|
1153
|
+
* Per run, not per driver. A driver is reusable across elements and documents (that is why
|
|
1154
|
+
* `animate` is read off the element), while a stage belongs to exactly one element — a
|
|
1155
|
+
* driver-level stage would silently claim the wrong element's lane the second time it was
|
|
1156
|
+
* used. Only an accelerated run claims: a refused or demoted run is on the JS path, where
|
|
1157
|
+
* the caller's own track was the writer all along. Omitted, the caller owns the lane and
|
|
1158
|
+
* writes the value back itself.
|
|
1159
|
+
*/
|
|
1160
|
+
readonly stage?: Stage;
|
|
1161
|
+
/**
|
|
1162
|
+
* Stops in the generated easing. Defaults to DEFAULT_STOPS; at least 2. More stops buy a
|
|
1163
|
+
* tighter copy of a hard curve: a spring that overshoots a quarter of its travel is 0.3% of
|
|
1164
|
+
* the travel at 32 and 0.08% at 64.
|
|
1165
|
+
*/
|
|
1166
|
+
readonly stops?: number;
|
|
1167
|
+
}
|
|
1168
|
+
/** A segment in flight. */
|
|
1169
|
+
interface WaapiRun {
|
|
1170
|
+
/** "waapi" while the browser owns the motion; "js" when the engine samples instead. */
|
|
1171
|
+
readonly kind: "waapi" | "js";
|
|
1172
|
+
/** Why this run is on the JS path. Undefined only while kind is "waapi". */
|
|
1173
|
+
readonly reason: string | undefined;
|
|
1174
|
+
/** Resolves once, on completion, demotion or cancellation. Never rejects. */
|
|
1175
|
+
readonly finished: Promise<void>;
|
|
1176
|
+
/**
|
|
1177
|
+
* The value the engine continues from. On the accelerated path there is no per-frame
|
|
1178
|
+
* sample to report, so this is the function at the current frame time — what the engine
|
|
1179
|
+
* would have sampled, and what the browser is showing to within the easing's error. On the
|
|
1180
|
+
* JS path it is the value the last frame produced. Frozen once the run ends, so an
|
|
1181
|
+
* interruption cannot move while the caller re-segments.
|
|
1182
|
+
*/
|
|
1183
|
+
value(): number;
|
|
1184
|
+
/**
|
|
1185
|
+
* Takes the lane back: cancels the animation, releases its forwards fill and freezes the
|
|
1186
|
+
* value at this frame. Idempotent, and the only way to release a *completed* run's fill —
|
|
1187
|
+
* with fill: "both" the browser keeps applying the end value until then, which is what
|
|
1188
|
+
* makes the handover seamless and what must not outlive the caller's ownership.
|
|
1189
|
+
*/
|
|
1190
|
+
cancel(): void;
|
|
1191
|
+
}
|
|
1192
|
+
/** Hands segments to the browser. */
|
|
1193
|
+
interface WaapiDriver {
|
|
1194
|
+
play(element: Element, request: WaapiRunOptions): WaapiRun;
|
|
1195
|
+
}
|
|
1196
|
+
export declare function segmentCssEasing(segment: Segment, from?: number, to?: number, stops?: number): string;
|
|
1197
|
+
/** Creates a driver. One driver can play any number of segments. */
|
|
1198
|
+
export declare function createWaapiDriver(options?: WaapiDriverOptions): WaapiDriver;
|
|
1199
|
+
/** One scroll position, or both. "both" names y as the primary axis for progress/length. */
|
|
1200
|
+
type ScrollAxis = "x" | "y" | "both";
|
|
1201
|
+
/**
|
|
1202
|
+
* What a scroll source reports. Replaced, and frozen, only when a number changed, so
|
|
1203
|
+
* `before === after` answers "did anything change" without reading the fields — the same
|
|
1204
|
+
* rule the gesture snapshot follows, and what a React adapter needs for
|
|
1205
|
+
* useSyncExternalStore.
|
|
1206
|
+
*/
|
|
1207
|
+
interface ScrollState {
|
|
1208
|
+
/** Horizontal position in px. 0 when the axis does not sample x. */
|
|
1209
|
+
readonly x: number;
|
|
1210
|
+
/** Vertical position in px. 0 when the axis does not sample y. */
|
|
1211
|
+
readonly y: number;
|
|
1212
|
+
/** The primary axis's position over its scrollable length, clamped to 0..1. */
|
|
1213
|
+
readonly progress: number;
|
|
1214
|
+
/** The primary axis's scrollable length in px: scrollHeight - clientHeight (or the width pair). */
|
|
1215
|
+
readonly length: number;
|
|
1216
|
+
}
|
|
1217
|
+
/** What a scroll source needs to run. */
|
|
1218
|
+
interface ScrollSourceOptions {
|
|
1219
|
+
/**
|
|
1220
|
+
* The loop the position is sampled on. Required, not defaulted: a source is a sensor and
|
|
1221
|
+
* has no element to inherit a loop from, and a default here would hide the second clock
|
|
1222
|
+
* a browser test and a manual test must not have. Rejected alternative: a process loop
|
|
1223
|
+
* like the stage's, which would let two loops disagree about the ordering guarantee.
|
|
1224
|
+
*/
|
|
1225
|
+
readonly frame: FrameLoop;
|
|
1226
|
+
/**
|
|
1227
|
+
* The scrollable element. Defaults to the document's viewport. It must be the element
|
|
1228
|
+
* that owns the overflow, not a wrapper around it: a wrapper's scrollTop is 0 forever.
|
|
1229
|
+
*/
|
|
1230
|
+
readonly container?: Element;
|
|
1231
|
+
/** Which axes to sample. Defaults to "y". */
|
|
1232
|
+
readonly axis?: ScrollAxis;
|
|
1233
|
+
/** A label for diagnostics and frame job names. */
|
|
1234
|
+
readonly name?: string;
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* A scroll position as a source a host's intent reads. `y`/`x`/`progress`/`length` are
|
|
1238
|
+
* reads of the last sampled frame: cheap, no layout, safe inside an intent.
|
|
1239
|
+
*/
|
|
1240
|
+
interface ScrollSource {
|
|
1241
|
+
/** Horizontal position in px, from the last sampled frame. */
|
|
1242
|
+
readonly x: number;
|
|
1243
|
+
/** Vertical position in px, from the last sampled frame. */
|
|
1244
|
+
readonly y: number;
|
|
1245
|
+
/** The primary axis's progress through the scrollable length, 0..1. */
|
|
1246
|
+
readonly progress: number;
|
|
1247
|
+
/** The primary axis's scrollable length in px. */
|
|
1248
|
+
readonly length: number;
|
|
1249
|
+
/** The four numbers as one object; same identity until one of them changes. */
|
|
1250
|
+
readonly state: ScrollState;
|
|
1251
|
+
/**
|
|
1252
|
+
* Re-measures the metrics on the next frame. The seam for content that changed size
|
|
1253
|
+
* without a scroll or a resize the source can hear — a list that appended rows, a panel
|
|
1254
|
+
* that expanded — because the alternative is observing every child of the container,
|
|
1255
|
+
* which is the one thing a big list must not pay for.
|
|
1256
|
+
*/
|
|
1257
|
+
request(): void;
|
|
1258
|
+
/** Fires with the new numbers only when one actually changed. Returns the unsubscribe. */
|
|
1259
|
+
subscribe(listener: (state: ScrollState) => void): () => void;
|
|
1260
|
+
/** Removes every listener and the frame job, so nothing is sampled or reported again. */
|
|
1261
|
+
dispose(): void;
|
|
1262
|
+
}
|
|
1263
|
+
/** Creates a scroll source. The caller owns disposal. */
|
|
1264
|
+
export declare function createScrollSource(options: ScrollSourceOptions): ScrollSource;
|
|
1265
|
+
/** How an element becomes a target, whichever measurement the platform offers. */
|
|
1266
|
+
interface InViewOptions {
|
|
1267
|
+
/**
|
|
1268
|
+
* Stop after the element *first becomes visible*. Defaults to false. The answer is final
|
|
1269
|
+
* once true — the element may leave and the source keeps reporting true — which is what
|
|
1270
|
+
* "reveal once and stay revealed" means. Rejected alternative: stop after the first
|
|
1271
|
+
* entry whatever it says, which would freeze an element mounted below the fold at "never
|
|
1272
|
+
* visible", the common case for anything that reveals on scroll.
|
|
1273
|
+
*/
|
|
1274
|
+
readonly once?: boolean;
|
|
1275
|
+
/**
|
|
1276
|
+
* The observer's `rootMargin`, e.g. "0px 0px -20% 0px": positive grows the root, so
|
|
1277
|
+
* "100px" turns the element visible 100px before it enters. Percentages resolve against
|
|
1278
|
+
* the root's size. Validated here, because the fallback has to parse it anyway and a
|
|
1279
|
+
* typo should fail at creation rather than read as 0px in one path and 0 in the other.
|
|
1280
|
+
*/
|
|
1281
|
+
readonly margin?: string;
|
|
1282
|
+
/**
|
|
1283
|
+
* The fraction of the element that must be inside the root, 0..1. Defaults to 0, which
|
|
1284
|
+
* means "any part". 1 means the whole element, which is the observer's last threshold.
|
|
1285
|
+
*/
|
|
1286
|
+
readonly amount?: number;
|
|
1287
|
+
/** The clipping root. Defaults to the viewport, the observer's own default. */
|
|
1288
|
+
readonly root?: Element | Document | null;
|
|
1289
|
+
/**
|
|
1290
|
+
* The loop the per-frame fallback measures on. Ignored when the document has an
|
|
1291
|
+
* IntersectionObserver, which needs no frame at all.
|
|
1292
|
+
*/
|
|
1293
|
+
readonly frame?: FrameLoop;
|
|
1294
|
+
/**
|
|
1295
|
+
* A rect cache shared with the rest of the app. Defaults to one created here and
|
|
1296
|
+
* disposed with the source; a cache you pass in is never disposed, because it is not
|
|
1297
|
+
* this module's to close (the same rule the drag controller follows with the space's).
|
|
1298
|
+
*/
|
|
1299
|
+
readonly cache?: RectCache;
|
|
1300
|
+
/** The environment the fallback reads the viewport from. Defaults to one created here. */
|
|
1301
|
+
readonly environment?: Environment;
|
|
1302
|
+
}
|
|
1303
|
+
/** A boolean source the host reads, and may render from. */
|
|
1304
|
+
interface InView {
|
|
1305
|
+
/**
|
|
1306
|
+
* True while the element is inside the root. The first answer is false: it is measured in
|
|
1307
|
+
* the read pass, never in the constructor, because a synchronous measure there is the
|
|
1308
|
+
* forced layout inside a renderer's commit that the frame exists to prevent — so an
|
|
1309
|
+
* element already in view reports true on the frame after it mounts, not on the line that
|
|
1310
|
+
* created it.
|
|
1311
|
+
*/
|
|
1312
|
+
readonly inView: boolean;
|
|
1313
|
+
/**
|
|
1314
|
+
* Fires with the new answer only when it changed. Returns the unsubscribe.
|
|
1315
|
+
*
|
|
1316
|
+
* The second argument is the observer's own IntersectionObserverEntry when the
|
|
1317
|
+
* platform has one; on the per-frame measurement fallback there is no entry to
|
|
1318
|
+
* hand over, so it is undefined — a listener that needs entry fields must check.
|
|
1319
|
+
*/
|
|
1320
|
+
subscribe(listener: (inView: boolean, entry?: IntersectionObserverEntry) => void): () => void;
|
|
1321
|
+
/** Releases the observer (or the job and listeners) and stops reporting. */
|
|
1322
|
+
dispose(): void;
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* The loop the fallback measures on when the host passed none.
|
|
1326
|
+
*
|
|
1327
|
+
* Created on first use, not at import: importing this module on a server must not build a
|
|
1328
|
+
* loop nothing will run. Rejected alternative: a module-level loop constant. Reported
|
|
1329
|
+
* contract gap: stage.ts keeps the same private process loop, so an observer-less engine
|
|
1330
|
+
* ends up with two rAF chains until the barrel exports one shared process loop.
|
|
1331
|
+
*/
|
|
1332
|
+
/** Creates an in-view source for one element. The caller owns disposal. */
|
|
1333
|
+
export declare function createInView(element: Element, options?: InViewOptions): InView;
|
|
1334
|
+
/**
|
|
1335
|
+
* The attribute names a track may drive: the geometry SVG expresses as attributes, curated
|
|
1336
|
+
* rather than guessed from a name list.
|
|
1337
|
+
*
|
|
1338
|
+
* The list is the contract, and it is closed on purpose: a name outside it is written to style,
|
|
1339
|
+
* where an unknown property is a silent no-op, so "animate dx" would quietly do nothing.
|
|
1340
|
+
* isSvgAttribute() is how a host asks instead of assuming. d and points are here even though a
|
|
1341
|
+
* track can only produce a number: a derived value may return the path string, and that has to
|
|
1342
|
+
* land in the attribute rather than in style.
|
|
1343
|
+
*/
|
|
1344
|
+
export declare const SVG_ATTRIBUTE_NAMES: ReadonlySet<string>;
|
|
1345
|
+
/** True for a name this stage writes with setAttribute (including the composed transform). */
|
|
1346
|
+
export declare function isSvgAttribute(name: string): boolean;
|
|
1347
|
+
/**
|
|
1348
|
+
* Composes transform channels into the transform ATTRIBUTE's grammar, in the writer's order:
|
|
1349
|
+
* translate -> scale -> rotate -> skew.
|
|
1350
|
+
*
|
|
1351
|
+
* The order is the API for the same reason it is in writer.ts: matrix multiplication does not
|
|
1352
|
+
* commute, translate is leftmost so it applies in the parent's axes, and one fixed order is what
|
|
1353
|
+
* lets two subsystems write one string. The differences from composeTransform are grammar, not
|
|
1354
|
+
* taste: functions take unitless numbers, only 2D functions exist, skew is two functions because
|
|
1355
|
+
* SVG has no skew(a, b), and origin channels wrap the whole thing between a translate pair — CSS
|
|
1356
|
+
* transform-origin is not part of the attribute, so the conjugation is the only way "rotate about
|
|
1357
|
+
* this point" can mean anything here.
|
|
1358
|
+
*/
|
|
1359
|
+
export declare function composeSvgTransform(channels: Readonly<Record<string, number | string>>, origins?: Readonly<Record<string, number>>): string;
|
|
1360
|
+
/** The two dash values a drawing channel pair produces. */
|
|
1361
|
+
interface PathDash {
|
|
1362
|
+
/** stroke-dasharray: one dash, then one gap. */
|
|
1363
|
+
readonly dasharray: string;
|
|
1364
|
+
/** stroke-dashoffset: where the dash starts, relative to the path's start. */
|
|
1365
|
+
readonly dashoffset: string;
|
|
1366
|
+
}
|
|
1367
|
+
/**
|
|
1368
|
+
* The dash pair for a progress through a path of length user units.
|
|
1369
|
+
*
|
|
1370
|
+
* The model is one dash and one gap, both in the path's own units: a dash of pathLength * length
|
|
1371
|
+
* and a gap of pathSpacing * length. That makes the three channels independent readings of the
|
|
1372
|
+
* same path rather than a state machine — pathLength 1 with the default spacing is "100 100" on a
|
|
1373
|
+
* 100-unit path, which is the whole path drawn and a gap of one whole path before the pattern
|
|
1374
|
+
* repeats, i.e. a fully revealed line. Rejected alternative: normalising the element by setting
|
|
1375
|
+
* the SVG pathLength attribute to 1 and animating 0..1 directly, which writes an attribute the
|
|
1376
|
+
* host may own for its own reasons and moves the unit conversion into the browser.
|
|
1377
|
+
*
|
|
1378
|
+
* The offset is emitted negated because a negative stroke-dashoffset shifts the pattern forward
|
|
1379
|
+
* along the path, so a positive pathOffset starts the visible dash later — the reading a host
|
|
1380
|
+
* means by "offset the drawing".
|
|
1381
|
+
*/
|
|
1382
|
+
export declare function composePathDash(length: number, pathLength: number, pathOffset: number, pathSpacing: number): PathDash;
|
|
1383
|
+
/** What the SVG writer needs from its stage. */
|
|
1384
|
+
interface SvgWriterOptions {
|
|
1385
|
+
/**
|
|
1386
|
+
* The element's total path length in user units, read at every flush that draws.
|
|
1387
|
+
*
|
|
1388
|
+
* A provider rather than a number so the stage's pathLength.refresh() is visible without
|
|
1389
|
+
* rebuilding the writer; it answers undefined for an element with no length at all, which is
|
|
1390
|
+
* the case a drawing channel must not silently drop.
|
|
1391
|
+
*/
|
|
1392
|
+
readonly length?: () => number | undefined;
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Creates the writer for one SVG element: attributes, the composed transform attribute, drawing
|
|
1396
|
+
* channels, and the CSS properties — one writer, so "one write per property per frame" is a
|
|
1397
|
+
* property of the stage rather than a hope about its callers.
|
|
1398
|
+
*
|
|
1399
|
+
* The style half is literally createStyleWriter, not a copy: will-change, the dirty diffing and
|
|
1400
|
+
* the clear-on-quiet-frame rule are identical for an SVG element's CSS properties, and a second
|
|
1401
|
+
* implementation of them would be the five-copies problem the runtime package deleted. What the
|
|
1402
|
+
* SVG writer adds is the routing in front of it.
|
|
1403
|
+
*/
|
|
1404
|
+
export declare function createSvgWriter(element: Element, options?: SvgWriterOptions): StyleWriter;
|
|
1405
|
+
/** What a stage needs, plus the one thing an SVG stage needs that an HTML one does not. */
|
|
1406
|
+
interface SvgStageOptions extends Omit<StageOptions, "frame"> {
|
|
1407
|
+
/**
|
|
1408
|
+
* The loop decisions are taken on. Required, unlike the HTML stage's optional one.
|
|
1409
|
+
*
|
|
1410
|
+
* stage.ts keeps its process frame as a module-private singleton, and a second lazy singleton
|
|
1411
|
+
* here would mean a second requestAnimationFrame chain on every page that mixes HTML and SVG
|
|
1412
|
+
* stages — the duplicate the runtime package exists to delete. A host already owns a loop (one
|
|
1413
|
+
* per document, which is the rule), so it passes that one. Rejected alternative: duplicating the
|
|
1414
|
+
* singleton, which is one line and two frames per tick.
|
|
1415
|
+
*/
|
|
1416
|
+
readonly frame: FrameLoop;
|
|
1417
|
+
/**
|
|
1418
|
+
* The path length in user units, for an element that cannot report its own: a server render, or
|
|
1419
|
+
* jsdom. getTotalLength() wins when the element has one, because the element is the truth; this
|
|
1420
|
+
* is the fallback, not an override.
|
|
1421
|
+
*/
|
|
1422
|
+
readonly length?: number;
|
|
1423
|
+
}
|
|
1424
|
+
/** The element's own path metrics, for a host that wants to reason about the drawing. */
|
|
1425
|
+
interface SvgPathMetrics {
|
|
1426
|
+
/** The total path length in user units, read once when the stage was created. */
|
|
1427
|
+
readonly length: number;
|
|
1428
|
+
/**
|
|
1429
|
+
* Re-reads the element's length. Call it after replacing the path data: a stage reads the length
|
|
1430
|
+
* once, because a per-frame getTotalLength() is a geometry read per frame, and a stale length is
|
|
1431
|
+
* a dash that ends early. Returns the length now in use.
|
|
1432
|
+
*/
|
|
1433
|
+
refresh(): number;
|
|
1434
|
+
}
|
|
1435
|
+
/**
|
|
1436
|
+
* One SVG element's visual state.
|
|
1437
|
+
*
|
|
1438
|
+
* The same object shape as Stage, so a host can hold either and call track/flush/present/dispose
|
|
1439
|
+
* without caring which sink is behind it. Two halves are added because an SVG element has two
|
|
1440
|
+
* sinks where an HTML element has one: present() stays the CSS half (exactly what the shared
|
|
1441
|
+
* interface promises), and attributes() is the attribute half — geometry and the composed
|
|
1442
|
+
* transform. Rejected alternative: one record holding both, which every host would then have to
|
|
1443
|
+
* split with isSvgAttribute before it could render anything.
|
|
1444
|
+
*/
|
|
1445
|
+
interface SvgStage extends Stage {
|
|
1446
|
+
/** The attribute values the current intent implies: geometry, and the composed transform. */
|
|
1447
|
+
attributes(): Readonly<Record<string, string>>;
|
|
1448
|
+
/**
|
|
1449
|
+
* The element's path metrics, present only when it can report a length: a browser's
|
|
1450
|
+
* getTotalLength(), or the { length } option. Absent means the drawing channels are refused at
|
|
1451
|
+
* registration, which is the loud answer to "why does nothing draw".
|
|
1452
|
+
*/
|
|
1453
|
+
readonly pathLength?: SvgPathMetrics;
|
|
1454
|
+
}
|
|
1455
|
+
/**
|
|
1456
|
+
* Creates a stage for one SVG element. One stage per element; the caller owns disposal.
|
|
1457
|
+
*
|
|
1458
|
+
* The stage machinery below the writer is stage.ts's, repeated rather than shared because
|
|
1459
|
+
* createStage's writer is not injectable. The alternative — a second animation model beside the
|
|
1460
|
+
* tracks — would mean an interruption path that does not re-segment from (value, velocity), and
|
|
1461
|
+
* that is the one thing every caller of this engine depends on.
|
|
1462
|
+
*/
|
|
1463
|
+
export declare function createSvgStage(element: Element, options: SvgStageOptions): SvgStage;
|
|
1464
|
+
/** Where a stagger starts: the first child, the last, or the middle and outwards. */
|
|
1465
|
+
type GroupDirection = "forward" | "reverse" | "center";
|
|
1466
|
+
/**
|
|
1467
|
+
* How the group's own stage relates to its children: it travels before them, after
|
|
1468
|
+
* them, or alongside the first child.
|
|
1469
|
+
*/
|
|
1470
|
+
type GroupWhen = "beforeChildren" | "afterChildren" | "together";
|
|
1471
|
+
/** The values a play travels every child to, keyed by track name. */
|
|
1472
|
+
type GroupTarget = Readonly<Record<string, number>>;
|
|
1473
|
+
/** What one play does: how the children are spread out, and when the group itself moves. */
|
|
1474
|
+
interface GroupPlayOptions {
|
|
1475
|
+
/** Milliseconds between consecutive child starts. Defaults to 0: every child together. */
|
|
1476
|
+
readonly stagger?: number;
|
|
1477
|
+
/** Milliseconds before the first child starts. Defaults to 0. */
|
|
1478
|
+
readonly delay?: number;
|
|
1479
|
+
/** Which child starts first. Defaults to `"forward"`. */
|
|
1480
|
+
readonly direction?: GroupDirection;
|
|
1481
|
+
/** Where the group's own stage travels relative to the children. Defaults to `"together"`. */
|
|
1482
|
+
readonly when?: GroupWhen;
|
|
1483
|
+
}
|
|
1484
|
+
/** What a group needs. */
|
|
1485
|
+
interface GroupOptions {
|
|
1486
|
+
/** The loop decisions are taken on. The group schedules on it and never on requestAnimationFrame. */
|
|
1487
|
+
readonly frame: FrameLoop;
|
|
1488
|
+
/**
|
|
1489
|
+
* The group's own stage, when the group itself travels (a panel that opens before its
|
|
1490
|
+
* rows). Its tracks read {@link Group.selfTarget}; without it, `when` has nothing to
|
|
1491
|
+
* order and the children are the whole schedule.
|
|
1492
|
+
*/
|
|
1493
|
+
readonly stage?: Stage;
|
|
1494
|
+
/** A label for diagnostics and test failures. */
|
|
1495
|
+
readonly name?: string;
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* A schedule over child stages.
|
|
1499
|
+
*
|
|
1500
|
+
* The group never builds a segment: it decides when each child's intent is allowed to
|
|
1501
|
+
* change, and the child's stage — its policy, its tracks — does the rest.
|
|
1502
|
+
*/
|
|
1503
|
+
interface Group {
|
|
1504
|
+
/**
|
|
1505
|
+
* Registers a child under `key`. Returns the remove, so a host can unmount one row
|
|
1506
|
+
* without tearing the schedule down. The stage is never disposed by the group.
|
|
1507
|
+
*/
|
|
1508
|
+
add(key: string, stage: Stage): () => void;
|
|
1509
|
+
/**
|
|
1510
|
+
* The target the group currently holds for one of a child's tracks, or undefined while
|
|
1511
|
+
* that child is still being held. Read from a track's intent:
|
|
1512
|
+
* `intent: () => group.targetOf("row-a", "y") ?? 240` — the fallback is the child's
|
|
1513
|
+
* rest value, which is what keeps a held child still.
|
|
1514
|
+
*/
|
|
1515
|
+
targetOf(key: string, property: string): number | undefined;
|
|
1516
|
+
/** The same gate for the group's own stage, keyed by nothing because there is one. */
|
|
1517
|
+
selfTarget(property: string): number | undefined;
|
|
1518
|
+
/**
|
|
1519
|
+
* Travels every child to `target`, releasing them in the order the options select.
|
|
1520
|
+
* Resolves once every child (and the group's own stage, when it travels) has landed;
|
|
1521
|
+
* it never rejects.
|
|
1522
|
+
*
|
|
1523
|
+
* A play while one is in flight retargets: children already travelling keep their
|
|
1524
|
+
* continuity and re-segment, children still held take the new schedule. Rejected
|
|
1525
|
+
* alternative: queue it, which makes a fast open/close/open feel a whole animation
|
|
1526
|
+
* behind the pointer.
|
|
1527
|
+
*/
|
|
1528
|
+
play(target: GroupTarget, options?: GroupPlayOptions): Promise<void>;
|
|
1529
|
+
/** True while the play in flight replaced one that had not finished. */
|
|
1530
|
+
readonly interrupted: boolean;
|
|
1531
|
+
/** True when no play is in flight: every released child has landed. */
|
|
1532
|
+
readonly settled: boolean;
|
|
1533
|
+
/** Removes the schedule's jobs. The children's stages keep their values and finish their travel. */
|
|
1534
|
+
dispose(): void;
|
|
1535
|
+
}
|
|
1536
|
+
/** Creates a group: a schedule over child stages, measured in frames on `options.frame`. */
|
|
1537
|
+
export declare function createGroup(options: GroupOptions): Group;
|
|
1538
|
+
/** What createGestureState needs. */
|
|
1539
|
+
interface GestureStateOptions {
|
|
1540
|
+
/**
|
|
1541
|
+
* The element to attach during creation: the same thing as calling attach() first, and the
|
|
1542
|
+
* shape a host that builds the state inside a render wants. Rejected alternative: making
|
|
1543
|
+
* attach mandatory, which leaves a window in which the host holds a state nothing can
|
|
1544
|
+
* reach.
|
|
1545
|
+
*/
|
|
1546
|
+
readonly element?: Element;
|
|
1547
|
+
/**
|
|
1548
|
+
* The CSS `pointer-events` the host gives the element. "auto" (the default) means it is a
|
|
1549
|
+
* hit target, so hover and press are observed. "none" declares the opposite: an overlay or
|
|
1550
|
+
* decorative layer the pointer passes through, so nothing is wired to the pointer and
|
|
1551
|
+
* hovered/pressed stay false forever.
|
|
1552
|
+
*
|
|
1553
|
+
* A declaration rather than a computed style, for a reason that shows up in real overlays:
|
|
1554
|
+
* `pointer-events: none` on a wrapper still lets a pointer entering an *interactive child*
|
|
1555
|
+
* fire pointerenter on the wrapper through the ancestor path, so the events look exactly
|
|
1556
|
+
* like a genuine hover and only the host can say they are not. Reading
|
|
1557
|
+
* getComputedStyle would add a layout read to an event path and would have to be re-read
|
|
1558
|
+
* after every style change. Rejected alternative: silently trusting the events, which makes
|
|
1559
|
+
* an overlay over a draggable hover both elements at once.
|
|
1560
|
+
*/
|
|
1561
|
+
readonly pointerEvents?: "auto" | "none";
|
|
1562
|
+
/**
|
|
1563
|
+
* Read live at release time, not cached at attach: when true, a press
|
|
1564
|
+
* released anywhere — inside the element or not — still reports a tap.
|
|
1565
|
+
* The host mutates the options object; the gesture never copies it.
|
|
1566
|
+
*/
|
|
1567
|
+
globalTapTarget?: boolean;
|
|
1568
|
+
}
|
|
1569
|
+
/** The three answers as one object, so a host can compare two reads by reference. */
|
|
1570
|
+
interface GestureSnapshot {
|
|
1571
|
+
readonly hovered: boolean;
|
|
1572
|
+
readonly pressed: boolean;
|
|
1573
|
+
readonly focused: boolean;
|
|
1574
|
+
}
|
|
1575
|
+
/** Hover, press and focus for one element, as an intent source. */
|
|
1576
|
+
interface GestureState {
|
|
1577
|
+
/** True while a hover-capable pointer is over the element, or a press that started there is down. */
|
|
1578
|
+
readonly hovered: boolean;
|
|
1579
|
+
/** True between a pointerdown on the element and its release or cancel. */
|
|
1580
|
+
readonly pressed: boolean;
|
|
1581
|
+
/** True while the element has focus *and* its ring should show: `:focus-visible`, not `:focus`. */
|
|
1582
|
+
readonly focused: boolean;
|
|
1583
|
+
/**
|
|
1584
|
+
* The current triple. Replaced, and frozen, only when one of the three changed, so
|
|
1585
|
+
* `before === after` answers "did anything change" without reading the fields. It is also
|
|
1586
|
+
* what a React adapter hands to useSyncExternalStore as its snapshot: a getter that built a
|
|
1587
|
+
* fresh object per read would re-render for a change that did not happen.
|
|
1588
|
+
*/
|
|
1589
|
+
readonly state: GestureSnapshot;
|
|
1590
|
+
/**
|
|
1591
|
+
* Binds an element. Idempotent per element — the same element returns the same detach, so
|
|
1592
|
+
* an idempotent ref callback costs nothing — and a *different* element replaces the bound
|
|
1593
|
+
* one, because a single hovered flag cannot honestly describe two elements at once.
|
|
1594
|
+
*/
|
|
1595
|
+
attach(element: Element): () => void;
|
|
1596
|
+
/** Fires with the new triple only when hovered, pressed or focused actually changed. Returns the unsubscribe. */
|
|
1597
|
+
onChange(listener: (state: GestureSnapshot) => void): () => void;
|
|
1598
|
+
/**
|
|
1599
|
+
* Fires with each gesture occurrence — hoverStart/End, pressStart,
|
|
1600
|
+
* panSessionStart, panStart/pan/panEnd, tap, tapCancel, focus, blur.
|
|
1601
|
+
* Occurrences, not state: a listener that misses one misses it for good,
|
|
1602
|
+
* which is why the state channel exists beside it. Returns the unsubscribe.
|
|
1603
|
+
*/
|
|
1604
|
+
onGesture(listener: (event: GestureEvent) => void): () => void;
|
|
1605
|
+
/** Removes every listener, on the element and on the document. Fires no notification. */
|
|
1606
|
+
dispose(): void;
|
|
1607
|
+
}
|
|
1608
|
+
/** Where a gesture event happened, in client coordinates. */
|
|
1609
|
+
interface GesturePoint {
|
|
1610
|
+
readonly x: number;
|
|
1611
|
+
readonly y: number;
|
|
1612
|
+
}
|
|
1613
|
+
/**
|
|
1614
|
+
* A pan's geometry: offset is travel from the press's pointerdown, delta is
|
|
1615
|
+
* travel since the pan started (the deadzone is not part of it), and velocity
|
|
1616
|
+
* is the last sampled rate in px per second.
|
|
1617
|
+
*/
|
|
1618
|
+
interface PanGestureInfo {
|
|
1619
|
+
readonly point: GesturePoint;
|
|
1620
|
+
readonly offset: GesturePoint;
|
|
1621
|
+
readonly delta: GesturePoint;
|
|
1622
|
+
readonly velocity: GesturePoint;
|
|
1623
|
+
}
|
|
1624
|
+
/**
|
|
1625
|
+
* One gesture occurrence. State answers "is it hovered"; events answer "it
|
|
1626
|
+
* just happened" — a tap completed, a pan crossed its threshold, a hover
|
|
1627
|
+
* began. The engine names them after what it observed; a host maps them onto
|
|
1628
|
+
* its own callback names.
|
|
1629
|
+
*/
|
|
1630
|
+
type GestureEvent = {
|
|
1631
|
+
readonly type: "hoverStart" | "hoverEnd" | "pressStart" | "panSessionStart" | "tap" | "tapCancel" | "focus" | "blur";
|
|
1632
|
+
readonly event: Event;
|
|
1633
|
+
readonly point: GesturePoint;
|
|
1634
|
+
} | {
|
|
1635
|
+
readonly type: "panStart" | "pan" | "panEnd";
|
|
1636
|
+
readonly event: Event;
|
|
1637
|
+
readonly info: PanGestureInfo;
|
|
1638
|
+
};
|
|
1639
|
+
/** Creates hover, press and focus state for one element at a time. */
|
|
1640
|
+
export declare function createGestureState(options?: GestureStateOptions): GestureState;
|
|
1641
|
+
/** What createPinchGesture needs. */
|
|
1642
|
+
interface PinchGestureOptions {
|
|
1643
|
+
/**
|
|
1644
|
+
* The element to attach during creation: the same thing as calling attach()
|
|
1645
|
+
* first. Every pointer in a gesture must *start* on this element — a finger
|
|
1646
|
+
* that lands elsewhere is tracking something else, and letting it join would
|
|
1647
|
+
* measure a pinch across two unrelated surfaces.
|
|
1648
|
+
*/
|
|
1649
|
+
readonly element?: Element;
|
|
1650
|
+
}
|
|
1651
|
+
/** A point in client (viewport) coordinates. */
|
|
1652
|
+
interface PinchPoint {
|
|
1653
|
+
readonly x: number;
|
|
1654
|
+
readonly y: number;
|
|
1655
|
+
}
|
|
1656
|
+
/** The pinch measurement as one object, so a host can compare two reads by reference. */
|
|
1657
|
+
interface PinchSnapshot {
|
|
1658
|
+
/** True while two or more pointers are down on the element. */
|
|
1659
|
+
readonly active: boolean;
|
|
1660
|
+
/** How many pointers are currently down on the element, gesture or not. */
|
|
1661
|
+
readonly pointerCount: number;
|
|
1662
|
+
/** Midpoint of the tracked pointers; with one pointer it is that pointer. */
|
|
1663
|
+
readonly center: PinchPoint;
|
|
1664
|
+
/** Distance between the two farthest-tracked pointers; 0 with fewer than two. */
|
|
1665
|
+
readonly distance: number;
|
|
1666
|
+
/** distance / baseline distance; 1 while inactive. Multiply, don't add. */
|
|
1667
|
+
readonly scale: number;
|
|
1668
|
+
/** Shortest-arc rotation from the baseline angle, in degrees; 0 while inactive. */
|
|
1669
|
+
readonly rotation: number;
|
|
1670
|
+
/** Center displacement since the baseline was taken, in client px. */
|
|
1671
|
+
readonly pan: PinchPoint;
|
|
1672
|
+
}
|
|
1673
|
+
/** Pinch/resize measurements for one element at a time, as an intent source. */
|
|
1674
|
+
interface PinchGesture {
|
|
1675
|
+
/** The current measurement. Replaced only when a number actually changed. */
|
|
1676
|
+
readonly state: PinchSnapshot;
|
|
1677
|
+
/** Convenience read of `state.active`. */
|
|
1678
|
+
readonly active: boolean;
|
|
1679
|
+
/** Binds an element. Idempotent per element, like GestureState.attach. */
|
|
1680
|
+
attach(element: Element): () => void;
|
|
1681
|
+
/** Fires with the new snapshot only when a measured value actually changed. */
|
|
1682
|
+
onChange(listener: (state: PinchSnapshot, event?: Event) => void): () => void;
|
|
1683
|
+
/** Removes every listener and forgets every pointer. Fires no notification. */
|
|
1684
|
+
dispose(): void;
|
|
1685
|
+
}
|
|
1686
|
+
/** Creates pinch/resize measurement state for one element at a time. */
|
|
1687
|
+
export declare function createPinchGesture(options?: PinchGestureOptions): PinchGesture;
|
|
1688
|
+
/** What a view transition needs from its host. */
|
|
1689
|
+
interface ViewTransitionOptions {
|
|
1690
|
+
/** Duration applied to every pseudo-element animation, in milliseconds. */
|
|
1691
|
+
readonly duration?: number;
|
|
1692
|
+
/** CSS easing applied to the same animations (keyword or cubic-bezier()). */
|
|
1693
|
+
readonly easing?: string;
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* What `.add()` accepts: an element, or a selector resolved against the
|
|
1697
|
+
* document at call time. A selector that matches nothing refuses — naming an
|
|
1698
|
+
* element that is not there is a bug the caller should hear about, not a
|
|
1699
|
+
* transition that silently morphs nothing.
|
|
1700
|
+
*/
|
|
1701
|
+
type ViewTransitionTarget = Element | string;
|
|
1702
|
+
/**
|
|
1703
|
+
* The five animation roles a named layer can carry, matching the pseudo-tree
|
|
1704
|
+
* the platform builds: `layout` drives `::view-transition-group` (the morph),
|
|
1705
|
+
* `new`/`old` drive the two snapshots whenever they exist, and `enter`/`exit`
|
|
1706
|
+
* are the presence-gated halves — `enter` fires only when the layer has a new
|
|
1707
|
+
* view and no old one, `exit` only the reverse.
|
|
1708
|
+
*/
|
|
1709
|
+
type ViewRole = "enter" | "exit" | "new" | "old" | "layout";
|
|
1710
|
+
/**
|
|
1711
|
+
* Keyframes for one role, as CSS declarations: property → value or value
|
|
1712
|
+
* list. camelCase properties are kebab-cased on the way out. A list of N
|
|
1713
|
+
* values becomes N evenly spaced stops; a single value becomes the 100% stop
|
|
1714
|
+
* and the layer's natural state supplies the start. Numbers are emitted
|
|
1715
|
+
* verbatim — write units in strings where CSS needs them ("100px", "50%").
|
|
1716
|
+
*/
|
|
1717
|
+
type ViewKeyframes = Record<string, string | number | readonly (string | number)[]>;
|
|
1718
|
+
/** Per-role timing, in milliseconds / CSS easing — the same units options take. */
|
|
1719
|
+
interface ViewKeyframesOptions {
|
|
1720
|
+
readonly duration?: number;
|
|
1721
|
+
readonly easing?: string;
|
|
1722
|
+
readonly delay?: number;
|
|
1723
|
+
}
|
|
1724
|
+
/** A running view transition. */
|
|
1725
|
+
interface ViewTransition {
|
|
1726
|
+
/** Resolves when the transition's animations finish (or are skipped). */
|
|
1727
|
+
readonly finished: Promise<void>;
|
|
1728
|
+
/** Resolves once the pseudo-element tree exists and can be retimed. */
|
|
1729
|
+
readonly ready: Promise<void>;
|
|
1730
|
+
/** Resolves when the update callback's returned promise settles. */
|
|
1731
|
+
readonly updateCallbackDone: Promise<void>;
|
|
1732
|
+
/**
|
|
1733
|
+
* Pairs two elements into one morph: the first carries a `view-transition-name`
|
|
1734
|
+
* into the old snapshot, and the update callback moves that name onto the
|
|
1735
|
+
* second before the new snapshot — so the browser animates the first into the
|
|
1736
|
+
* second instead of treating them as unrelated boxes. Call it synchronously
|
|
1737
|
+
* after {@link animateView}, before the update renders.
|
|
1738
|
+
*
|
|
1739
|
+
* Both arguments resolve at call time — an element or a selector — so the
|
|
1740
|
+
* pair's new end must already be in the document (a hidden modal, a moved
|
|
1741
|
+
* card). An element the update itself creates cannot be named this way;
|
|
1742
|
+
* that is the enter/exit DSL's job, which this surface does not yet have.
|
|
1743
|
+
*
|
|
1744
|
+
* `name` defaults to a generated unique ident, which is what allows several
|
|
1745
|
+
* pairs in one transition. Pass a shared name when CSS has to target the
|
|
1746
|
+
* pair's pseudo-elements (`::view-transition-old(name)`) — the caller then
|
|
1747
|
+
* owns uniqueness across concurrent transitions. Names are released back to
|
|
1748
|
+
* `none` when the transition settles.
|
|
1749
|
+
*/
|
|
1750
|
+
add(oldTarget: ViewTransitionTarget, newTarget?: ViewTransitionTarget, name?: string): this;
|
|
1751
|
+
/**
|
|
1752
|
+
* Tags every element this transition named with a `view-transition-class`,
|
|
1753
|
+
* so authors can target the generated layers from CSS —
|
|
1754
|
+
* `::view-transition-group(.name)`, `::view-transition-old/new(.name)` —
|
|
1755
|
+
* without knowing the opaque generated name. Applies to pairs added after
|
|
1756
|
+
* the call and before it; elements already named get the class too.
|
|
1757
|
+
*/
|
|
1758
|
+
class(name: string): this;
|
|
1759
|
+
/**
|
|
1760
|
+
* Group nesting control. By default a named element's layer nests under its
|
|
1761
|
+
* nearest named ancestor (`view-transition-group: contain`), mirroring how
|
|
1762
|
+
* the DOM paints. `.group(false)` writes `view-transition-group: none` on the
|
|
1763
|
+
* resolved elements so the layer stays flat and escapes an ancestor's
|
|
1764
|
+
* clip/transform — the lift-out-of-a-card case. `.group(true)` restores the
|
|
1765
|
+
* default by removing the property.
|
|
1766
|
+
*/
|
|
1767
|
+
group(enabled?: boolean): this;
|
|
1768
|
+
/**
|
|
1769
|
+
* Registers a target that only exists in the new snapshot — an element the
|
|
1770
|
+
* update creates or reveals. Unlike {@link add} the target resolves inside
|
|
1771
|
+
* the update callback, so a selector can match DOM the update itself
|
|
1772
|
+
* renders. An Element reference works too when the update appends it. A
|
|
1773
|
+
* target that never materialises simply produces no layer.
|
|
1774
|
+
*
|
|
1775
|
+
* Presence is sampled when the update callback settles, before the browser
|
|
1776
|
+
* captures the new snapshot — the same contract `startViewTransition`
|
|
1777
|
+
* itself has. If the update defers its DOM writes (a React `setState` that
|
|
1778
|
+
* has not committed), return a promise from `update` that resolves after
|
|
1779
|
+
* the commit, or the enter layer resolves against stale DOM.
|
|
1780
|
+
*/
|
|
1781
|
+
enter(target: ViewTransitionTarget): this;
|
|
1782
|
+
/**
|
|
1783
|
+
* Registers a target leaving in this update — resolved eagerly like
|
|
1784
|
+
* {@link add}'s first argument, named into the old snapshot, and left alone
|
|
1785
|
+
* so the update can remove it. If the element survives the update it becomes
|
|
1786
|
+
* an ordinary morph instead, and `exit` keyframes stay gated off.
|
|
1787
|
+
*/
|
|
1788
|
+
exit(target: ViewTransitionTarget): this;
|
|
1789
|
+
/**
|
|
1790
|
+
* Registers a self-morph: the same element in both snapshots, grouped under
|
|
1791
|
+
* its own name — the explicit form of `.add(target)` for hosts that think
|
|
1792
|
+
* in roles rather than pairs.
|
|
1793
|
+
*/
|
|
1794
|
+
layout(target: ViewTransitionTarget): this;
|
|
1795
|
+
/**
|
|
1796
|
+
* Attaches keyframes to the last registered target's role. The definition
|
|
1797
|
+
* compiles to `@keyframes` plus a `::view-transition-*` rule injected for the
|
|
1798
|
+
* duration of the transition and removed when it settles; presence gating is
|
|
1799
|
+
* automatic — `enter` rules are emitted only for new-only layers, `exit`
|
|
1800
|
+
* only for old-only ones. `layout` with an empty definition and options
|
|
1801
|
+
* retimes just the group morph. Timing falls back to the transition-level
|
|
1802
|
+
* `duration`/`easing`, then to 250ms/`ease`.
|
|
1803
|
+
*/
|
|
1804
|
+
keyframes(role: ViewRole, definition: ViewKeyframes, options?: ViewKeyframesOptions): this;
|
|
1805
|
+
/** Jumps straight to the new state, skipping the animation. */
|
|
1806
|
+
skipAnimation(): void;
|
|
1807
|
+
}
|
|
1808
|
+
/**
|
|
1809
|
+
* Runs `update` inside a native view transition. Where the platform has no
|
|
1810
|
+
* `startViewTransition`, the update still runs and every promise resolves —
|
|
1811
|
+
* the caller gets the end state either way, which is the graceful-degradation
|
|
1812
|
+
* contract Motion's own wrapper keeps.
|
|
1813
|
+
*/
|
|
1814
|
+
export declare function animateView(update: () => void | Promise<void>, options?: ViewTransitionOptions): ViewTransition;
|
|
1815
|
+
/** A sampled path morph. `at` is pure: same progress in, same `d` out, any order. */
|
|
1816
|
+
interface PathMorph {
|
|
1817
|
+
/** Commands per path — the structure both inputs were required to share. */
|
|
1818
|
+
readonly commands: number;
|
|
1819
|
+
/** The `d` string at `progress` (0 = from, 1 = to; clamped outside). */
|
|
1820
|
+
at(progress: number): string;
|
|
1821
|
+
}
|
|
1822
|
+
/**
|
|
1823
|
+
* Interpolates two path strings that share one command structure.
|
|
1824
|
+
*
|
|
1825
|
+
* The check is exact — same letters, same arity, same count — because a morph
|
|
1826
|
+
* between different structures has no honest answer, and the failure belongs
|
|
1827
|
+
* at setup where the host can resample, not mid-animation where it renders
|
|
1828
|
+
* garbage. Rejected: normalising both paths to cubics (that is a different,
|
|
1829
|
+
* lossy operation the caller should opt into explicitly).
|
|
1830
|
+
*/
|
|
1831
|
+
export declare function morphPath(from: string, to: string): PathMorph;
|
|
1832
|
+
export { type AnimateOptions, type Animation, DEFAULT_SPRING, type DerivedTrack, type Driver, type Ease, type EaseName, type Easing, type EasingAnimateOptions, type Evaluated, type FlipOptions, type FlipRun, type GestureEvent, type GesturePoint, type GestureSnapshot, type GestureState, type GestureStateOptions, type Group, type GroupDirection, type GroupOptions, type GroupPlayOptions, type GroupTarget, type GroupWhen, type InView, type InViewOptions, type InertiaPolicy, type InstantPolicy, type Keyframe$1 as Keyframe, type KeyframesPolicy, type LaunchInput, type LayoutElement, type LayoutOptions, type LayoutRect, type LayoutSnapshot, type LayoutTransform, type ManualScheduler, type OrchestrationOptions, type PanGestureInfo, type ParallelOptions, type ParsedValue, type PathDash, type PathMorph, type PinchGesture, type PinchGestureOptions, type PinchPoint, type PinchSnapshot, type Policy, type PolicyKind, type Presence, type PresenceEntry, type PresenceEvent, type PresenceGroup, type PresenceGroupEntry, type PresenceGroupEvent, type PresenceGroupOptions, type PresenceGroupState, type PresenceMode, type PresenceOptions, type PresenceRunner, type PresenceSnapshot, type PresenceState, type PropertyRole, type RepeatOptions, type RepeatType, type ResolvedPolicy, type Scene, type SceneCancelOptions, type SceneMode, type SceneOptions, type SceneRegisterOptions, type Scheduler, type ScrollAxis, type ScrollSource, type ScrollSourceOptions, type ScrollState, type Segment, type SegmentFactory, type SegmentInput, type SequenceOptions, type SpringAnimateOptions, type SpringConfig, type SpringPolicy, type SpringRunnerOptions, type SpringSolution, type SpringValue, type SpringValueOptions, type Stage, type StageIntent, type StageOptions, type StaggerFrom, type StaggerOptions, type Step, type StyleWriter, type SvgPathMetrics, type SvgStage, type SvgStageOptions, type SvgWriterOptions, type Timeline, type TimelineOptions, type TimingOverrides, type Track, type TrackSpec, type TweenOptions, type TweenPolicy, type ValueKeyframesPolicy, type ValueLaunchInput, type ValueTrack, type ValueTrackSpec, type ViewKeyframes, type ViewKeyframesOptions, type ViewRole, type ViewTransition, type ViewTransitionOptions, type ViewTransitionTarget, type WaapiAnimate, type WaapiAnimation, type WaapiDriver, type WaapiDriverOptions, type WaapiRun, type WaapiRunOptions, createPresence, createPresenceGroup, createSpringValue, createTimeline, cssRunner, cubicBezier, easeEmphasis, easeEnter, easeExit, easeIn, easeInOut, easeInOutCubic, easeMove, easeOut, easeOutBack, easeOutCubic, easeOutExpo, easeOutQuint, easePop, easeSpringSettle, flip, linear, linearEasing, presenceGroupStep, presenceStep, solveSpring, springEasing, springFromDuration, springRunner };
|