@link-foundation/ui-animation 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 +24 -0
- package/README.md +454 -2
- package/package.json +77 -4
- package/src/backgrounds/README.md +131 -0
- package/src/backgrounds/beams.d.ts +21 -0
- package/src/backgrounds/beams.js +140 -0
- package/src/backgrounds/common.d.ts +23 -0
- package/src/backgrounds/common.js +322 -0
- package/src/backgrounds/grid.d.ts +16 -0
- package/src/backgrounds/grid.js +122 -0
- package/src/backgrounds/nebula.d.ts +9 -0
- package/src/backgrounds/nebula.js +57 -0
- package/src/backgrounds/rain-cleanup.js +77 -0
- package/src/backgrounds/rain.d.ts +33 -0
- package/src/backgrounds/rain.js +238 -0
- package/src/backgrounds/shader.d.ts +14 -0
- package/src/backgrounds/shader.js +151 -0
- package/src/backgrounds/sprites.js +72 -0
- package/src/backgrounds/starfield.d.ts +38 -0
- package/src/backgrounds/starfield.js +168 -0
- package/src/clock.js +98 -0
- package/src/compile-waapi.js +147 -0
- package/src/diagnostics.js +51 -0
- package/src/easing.js +327 -0
- package/src/effects/decipher.js +83 -0
- package/src/effects.js +44 -0
- package/src/index.d.ts +581 -0
- package/src/index.js +74 -0
- package/src/layers.js +88 -0
- package/src/model.js +636 -0
- package/src/player.js +267 -0
- package/src/random.js +62 -0
- package/src/recorder/buffer.js +40 -0
- package/src/recorder/clock.js +2 -0
- package/src/recorder/format.js +125 -0
- package/src/recorder/input.js +53 -0
- package/src/recorder/recorder.js +183 -0
- package/src/recorder/redact.js +43 -0
- package/src/recorder/replay.js +115 -0
- package/src/recorder/state-at.js +62 -0
- package/src/recorder/store.js +92 -0
- package/src/recorder/to-playwright.js +113 -0
- package/src/recorder/verify.js +49 -0
- package/src/run.js +283 -0
- package/src/sample.js +160 -0
- package/src/timeline.js +115 -0
- package/src/timing.js +172 -0
- package/src/tokens.js +32 -0
- package/src/types.js +130 -0
- package/src/validate.js +218 -0
- package/src/values.js +331 -0
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type declarations of `@link-foundation/ui-animation` (see README.md).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { Diagnostic } from '@link-foundation/ui-core';
|
|
8
|
+
|
|
9
|
+
export type { Diagnostic };
|
|
10
|
+
|
|
11
|
+
/** Resolves a token path (`motion.duration.short`) to its value. */
|
|
12
|
+
export type ResolveToken = (path: string) => unknown;
|
|
13
|
+
|
|
14
|
+
/** Milliseconds, or a `(token PATH)` reference. */
|
|
15
|
+
export type Time = number | { type: 'token'; path: string };
|
|
16
|
+
|
|
17
|
+
export type Easing =
|
|
18
|
+
| { type: 'linear' }
|
|
19
|
+
| { type: 'named'; name: string }
|
|
20
|
+
| { type: 'cubic-bezier'; points: [number, number, number, number] }
|
|
21
|
+
| {
|
|
22
|
+
type: 'steps';
|
|
23
|
+
count: number;
|
|
24
|
+
position: 'start' | 'end' | 'both' | 'none';
|
|
25
|
+
}
|
|
26
|
+
| { type: 'spring'; stiffness: number; damping: number; mass: number };
|
|
27
|
+
|
|
28
|
+
export type Quantity = { value: number; unit: string };
|
|
29
|
+
|
|
30
|
+
/** `(envelope bell|sustain [(attack TIME)] [(release TIME)])` (ms). */
|
|
31
|
+
export type Envelope = {
|
|
32
|
+
type: 'bell' | 'sustain';
|
|
33
|
+
attack?: number;
|
|
34
|
+
release?: number;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type AnimValue =
|
|
38
|
+
| { type: 'number'; value: number }
|
|
39
|
+
| { type: 'color'; color: Record<string, unknown> }
|
|
40
|
+
| { type: 'text'; parts: (string | Quantity)[] }
|
|
41
|
+
| { type: 'token'; path: string };
|
|
42
|
+
|
|
43
|
+
export interface Key {
|
|
44
|
+
/** 0..1 */
|
|
45
|
+
offset: number;
|
|
46
|
+
value: AnimValue;
|
|
47
|
+
/** The easing of the segment that starts at this key. */
|
|
48
|
+
easing: Easing | null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface Track {
|
|
52
|
+
/** A CSS property, or a non-CSS property (`text`, `label`, ...). */
|
|
53
|
+
property: string;
|
|
54
|
+
keys: Key[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface EffectUse {
|
|
58
|
+
name: string;
|
|
59
|
+
params: Record<string, unknown>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface AnimationFields {
|
|
63
|
+
target: string | null;
|
|
64
|
+
/** `null`: the settle time of a spring easing, else 0. */
|
|
65
|
+
duration: Time | null;
|
|
66
|
+
delay: Time;
|
|
67
|
+
/** `Infinity` for `(iterations infinite)`. */
|
|
68
|
+
iterations: number;
|
|
69
|
+
direction: 'normal' | 'reverse' | 'alternate' | 'alternate-reverse';
|
|
70
|
+
fill: 'none' | 'forwards' | 'backwards' | 'both' | 'auto';
|
|
71
|
+
composite: 'replace' | 'add' | 'accumulate';
|
|
72
|
+
easing: Easing | null;
|
|
73
|
+
tracks: Track[];
|
|
74
|
+
effect: EffectUse | null;
|
|
75
|
+
/** `(persist true)`: a final clip-path/transform value may persist. */
|
|
76
|
+
persist: boolean;
|
|
77
|
+
envelope: Envelope | null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface Animation extends AnimationFields {
|
|
81
|
+
id: string;
|
|
82
|
+
kind: 'animation';
|
|
83
|
+
/** The states of `(on STATE)` that play this animation on its target. */
|
|
84
|
+
triggers: string[];
|
|
85
|
+
/** The fields of the `(reduced-motion ...)` block. */
|
|
86
|
+
reducedMotion: Partial<AnimationFields> | null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type TimelineItem =
|
|
90
|
+
| {
|
|
91
|
+
type: 'play';
|
|
92
|
+
id: string;
|
|
93
|
+
target: string | null;
|
|
94
|
+
targets: string[] | null;
|
|
95
|
+
}
|
|
96
|
+
| { type: 'sequence' | 'parallel'; items: TimelineItem[] }
|
|
97
|
+
| { type: 'at'; time: Time; items: TimelineItem[] }
|
|
98
|
+
| {
|
|
99
|
+
type: 'stagger';
|
|
100
|
+
step: Time;
|
|
101
|
+
items: TimelineItem[];
|
|
102
|
+
targets: string[] | null;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export interface Timeline {
|
|
106
|
+
id: string;
|
|
107
|
+
kind: 'timeline';
|
|
108
|
+
items: TimelineItem[];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface Trigger {
|
|
112
|
+
state: string;
|
|
113
|
+
/**
|
|
114
|
+
* The element whose state fires the trigger: the element that has the
|
|
115
|
+
* `(on STATE ...)` sublink, or the target of an animation that has it.
|
|
116
|
+
*/
|
|
117
|
+
element: string;
|
|
118
|
+
animation: string;
|
|
119
|
+
/** Where the animation plays; `null`: on `element`. */
|
|
120
|
+
target: string | null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface AnimationModel {
|
|
124
|
+
animations: Map<string, Animation>;
|
|
125
|
+
timelines: Map<string, Timeline>;
|
|
126
|
+
triggers: Trigger[];
|
|
127
|
+
diagnostics: Diagnostic[];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const ANIMATION_STATES: readonly string[];
|
|
131
|
+
export const ANIMATION_DEFAULTS: Readonly<AnimationFields>;
|
|
132
|
+
export function loadAnimations(text: string): AnimationModel;
|
|
133
|
+
|
|
134
|
+
// Easing
|
|
135
|
+
|
|
136
|
+
export type EasingFn = (t: number) => number;
|
|
137
|
+
export interface Spring {
|
|
138
|
+
/** The position (0 -> 1) at `tMs` milliseconds. */
|
|
139
|
+
at(tMs: number): number;
|
|
140
|
+
/** When it stays within 0.05% of 1 (ms); `Infinity` without damping. */
|
|
141
|
+
settleTime: number;
|
|
142
|
+
}
|
|
143
|
+
export const NAMED_EASINGS: Readonly<Record<string, readonly number[]>>;
|
|
144
|
+
export const SPRING_TOLERANCE: number;
|
|
145
|
+
export function isEasingName(name: string): boolean;
|
|
146
|
+
export const linear: EasingFn;
|
|
147
|
+
export function cubicBezier(
|
|
148
|
+
x1: number,
|
|
149
|
+
y1: number,
|
|
150
|
+
x2: number,
|
|
151
|
+
y2: number
|
|
152
|
+
): EasingFn;
|
|
153
|
+
export function steps(
|
|
154
|
+
n: number,
|
|
155
|
+
position?: 'start' | 'end' | 'both' | 'none'
|
|
156
|
+
): EasingFn;
|
|
157
|
+
export function spring(options?: {
|
|
158
|
+
stiffness?: number;
|
|
159
|
+
damping?: number;
|
|
160
|
+
mass?: number;
|
|
161
|
+
}): Spring;
|
|
162
|
+
export function springEasing(s: Spring): EasingFn;
|
|
163
|
+
export function toCssLinear(fn: EasingFn, samples?: number): string;
|
|
164
|
+
export function easingFunction(
|
|
165
|
+
easing: Easing | null,
|
|
166
|
+
resolveToken?: ResolveToken
|
|
167
|
+
): EasingFn;
|
|
168
|
+
export function easingCss(
|
|
169
|
+
easing: Easing | null,
|
|
170
|
+
resolveToken?: ResolveToken
|
|
171
|
+
): string;
|
|
172
|
+
|
|
173
|
+
// Sampling
|
|
174
|
+
|
|
175
|
+
export interface SampleOptions {
|
|
176
|
+
resolveToken?: ResolveToken;
|
|
177
|
+
/** The seed of effects without `(seed ...)`. */
|
|
178
|
+
seed?: number | string;
|
|
179
|
+
/** The text an effect works on. */
|
|
180
|
+
input?: string;
|
|
181
|
+
}
|
|
182
|
+
export type SampledValues = Record<string, number | string | unknown>;
|
|
183
|
+
export function sample(
|
|
184
|
+
animation: Animation,
|
|
185
|
+
tMs: number,
|
|
186
|
+
options?: SampleOptions
|
|
187
|
+
): SampledValues;
|
|
188
|
+
export function sampleTyped(
|
|
189
|
+
animation: Animation,
|
|
190
|
+
tMs: number,
|
|
191
|
+
options?: SampleOptions
|
|
192
|
+
): {
|
|
193
|
+
active: boolean;
|
|
194
|
+
values: Map<string, AnimValue>;
|
|
195
|
+
effects: Record<string, unknown>;
|
|
196
|
+
};
|
|
197
|
+
export function envelopeWeight(
|
|
198
|
+
envelope: Envelope | null,
|
|
199
|
+
progress: number,
|
|
200
|
+
duration: number
|
|
201
|
+
): number;
|
|
202
|
+
|
|
203
|
+
export interface Layer {
|
|
204
|
+
animation: Animation;
|
|
205
|
+
/** When the layer starts (ms). */
|
|
206
|
+
start?: number;
|
|
207
|
+
seed?: number | string;
|
|
208
|
+
input?: string;
|
|
209
|
+
}
|
|
210
|
+
export function sampleLayers(
|
|
211
|
+
layers: (Animation | Layer)[],
|
|
212
|
+
tMs: number,
|
|
213
|
+
options?: SampleOptions
|
|
214
|
+
): SampledValues;
|
|
215
|
+
|
|
216
|
+
// Random
|
|
217
|
+
|
|
218
|
+
export function seededRandom(seed: number | string): () => number;
|
|
219
|
+
export function seedNumber(seed: number | string): number;
|
|
220
|
+
export function hashString(text: string): number;
|
|
221
|
+
export function mix(...parts: (number | string)[]): number;
|
|
222
|
+
|
|
223
|
+
// Effects
|
|
224
|
+
|
|
225
|
+
export type EffectFn = (
|
|
226
|
+
input: string,
|
|
227
|
+
progress: number,
|
|
228
|
+
seed: number | string,
|
|
229
|
+
params: Record<string, unknown>
|
|
230
|
+
) => unknown;
|
|
231
|
+
export function registerEffect(
|
|
232
|
+
name: string,
|
|
233
|
+
fn: EffectFn,
|
|
234
|
+
options?: { property?: string }
|
|
235
|
+
): void;
|
|
236
|
+
export function getEffect(
|
|
237
|
+
name: string
|
|
238
|
+
): { fn: EffectFn; property: string } | undefined;
|
|
239
|
+
export function effectNames(): string[];
|
|
240
|
+
export const DECIPHER_CHARACTERS: string;
|
|
241
|
+
export function decipher(
|
|
242
|
+
input: string,
|
|
243
|
+
progress: number,
|
|
244
|
+
seed?: number | string
|
|
245
|
+
): string;
|
|
246
|
+
export function revealOrder(text: string, random: () => number): number[];
|
|
247
|
+
export function decipherFrame(
|
|
248
|
+
text: string,
|
|
249
|
+
progress: number,
|
|
250
|
+
order: number[],
|
|
251
|
+
random: () => number
|
|
252
|
+
): string;
|
|
253
|
+
|
|
254
|
+
// Validation
|
|
255
|
+
|
|
256
|
+
export interface FlashLimits {
|
|
257
|
+
maxFlashes: number;
|
|
258
|
+
minChange: number;
|
|
259
|
+
darkerBelow: number;
|
|
260
|
+
sampleRate: number;
|
|
261
|
+
windowMs: number;
|
|
262
|
+
}
|
|
263
|
+
export interface ValidateOptions {
|
|
264
|
+
resolveToken?: ResolveToken;
|
|
265
|
+
flash?: Partial<FlashLimits>;
|
|
266
|
+
}
|
|
267
|
+
export const PERSIST_PROPERTIES: readonly string[];
|
|
268
|
+
export const FLASH_PROPERTIES: readonly string[];
|
|
269
|
+
export const FLASH_LIMITS: Readonly<FlashLimits>;
|
|
270
|
+
export function luminanceChanges(
|
|
271
|
+
series: { t: number; l: number }[],
|
|
272
|
+
limits?: FlashLimits
|
|
273
|
+
): number[];
|
|
274
|
+
export function validateAnimation(
|
|
275
|
+
animation: Animation,
|
|
276
|
+
options?: ValidateOptions
|
|
277
|
+
): Diagnostic[];
|
|
278
|
+
export function validateAnimations(
|
|
279
|
+
model: AnimationModel,
|
|
280
|
+
options?: ValidateOptions
|
|
281
|
+
): Diagnostic[];
|
|
282
|
+
|
|
283
|
+
// WAAPI
|
|
284
|
+
|
|
285
|
+
export interface WaapiAnimation {
|
|
286
|
+
keyframes: Record<string, string | number | null>[];
|
|
287
|
+
options: {
|
|
288
|
+
duration: number;
|
|
289
|
+
easing: string;
|
|
290
|
+
fill: string;
|
|
291
|
+
composite: string;
|
|
292
|
+
delay?: number;
|
|
293
|
+
iterations?: number;
|
|
294
|
+
direction?: string;
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
export const NON_CSS_PROPERTIES: readonly string[];
|
|
298
|
+
export function isCssProperty(property: string): boolean;
|
|
299
|
+
export function keyframeProperty(property: string): string;
|
|
300
|
+
export function toWaapi(
|
|
301
|
+
animation: Animation,
|
|
302
|
+
options?: {
|
|
303
|
+
resolveToken?: ResolveToken;
|
|
304
|
+
isCssProperty?: (property: string) => boolean;
|
|
305
|
+
}
|
|
306
|
+
): WaapiAnimation;
|
|
307
|
+
|
|
308
|
+
// Timing and timelines
|
|
309
|
+
|
|
310
|
+
export interface Timing {
|
|
311
|
+
delay: number;
|
|
312
|
+
duration: number;
|
|
313
|
+
iterations: number;
|
|
314
|
+
direction: string;
|
|
315
|
+
fill: string;
|
|
316
|
+
easing: EasingFn;
|
|
317
|
+
active: number;
|
|
318
|
+
}
|
|
319
|
+
export const MOVEMENT_PROPERTIES: readonly string[];
|
|
320
|
+
export function resolveTiming(
|
|
321
|
+
animation: Animation,
|
|
322
|
+
resolveToken?: ResolveToken
|
|
323
|
+
): Timing;
|
|
324
|
+
export function timingAt(
|
|
325
|
+
timing: Timing,
|
|
326
|
+
tMs: number
|
|
327
|
+
): { iteration: number; progress: number; eased: number; phase: string } | null;
|
|
328
|
+
export function endTime(
|
|
329
|
+
animation: Animation,
|
|
330
|
+
resolveToken?: ResolveToken
|
|
331
|
+
): number;
|
|
332
|
+
export function reducedMotionVariant(animation: Animation): Animation;
|
|
333
|
+
export function flattenTimeline(
|
|
334
|
+
model: AnimationModel,
|
|
335
|
+
id: string,
|
|
336
|
+
options?: {
|
|
337
|
+
resolveToken?: ResolveToken;
|
|
338
|
+
variant?: (animation: Animation) => Animation;
|
|
339
|
+
target?: string | null;
|
|
340
|
+
}
|
|
341
|
+
): { start: number; id: string; target: string | null }[];
|
|
342
|
+
|
|
343
|
+
// Values and tokens
|
|
344
|
+
|
|
345
|
+
export function readValue(raw: string): AnimValue;
|
|
346
|
+
export function interpolate(
|
|
347
|
+
from: AnimValue,
|
|
348
|
+
to: AnimValue,
|
|
349
|
+
progress: number
|
|
350
|
+
): AnimValue;
|
|
351
|
+
export function valueCss(value: AnimValue): string;
|
|
352
|
+
export function relativeLuminance(color: Record<string, unknown>): number;
|
|
353
|
+
export function tokenResolver(
|
|
354
|
+
tokens: Map<string, { value: unknown }>
|
|
355
|
+
): ResolveToken;
|
|
356
|
+
|
|
357
|
+
// Player
|
|
358
|
+
|
|
359
|
+
export interface Clock {
|
|
360
|
+
now(): number;
|
|
361
|
+
requestFrame(callback: (time: number) => void): unknown;
|
|
362
|
+
cancelFrame(id: unknown): void;
|
|
363
|
+
}
|
|
364
|
+
export interface TimerClock extends Clock {
|
|
365
|
+
setTimeout(callback: () => void, ms: number): unknown;
|
|
366
|
+
clearTimeout(id: unknown): void;
|
|
367
|
+
}
|
|
368
|
+
export interface ManualClock extends TimerClock {
|
|
369
|
+
/** Move the time forward by `ms`, one frame (`step` ms) at a time. */
|
|
370
|
+
advance(ms: number, step?: number): void;
|
|
371
|
+
readonly pending: number;
|
|
372
|
+
}
|
|
373
|
+
/** One frame at 60 Hz (ms). */
|
|
374
|
+
export const FRAME_MS: number;
|
|
375
|
+
export function createManualClock(start?: number): ManualClock;
|
|
376
|
+
export function systemClock(): TimerClock;
|
|
377
|
+
export type Motion = 'full' | 'reduced';
|
|
378
|
+
export function defaultMotion(element: Element | null): Motion;
|
|
379
|
+
|
|
380
|
+
export interface PlayOptions {
|
|
381
|
+
/** Where to play (default: the animation's own target). */
|
|
382
|
+
target?: string;
|
|
383
|
+
seed?: number | string;
|
|
384
|
+
input?: string;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export interface PlayControl {
|
|
388
|
+
/** Resolves when every run has finished; rejects (AbortError) on cancel. */
|
|
389
|
+
finished: Promise<void>;
|
|
390
|
+
readonly currentTime: number;
|
|
391
|
+
readonly runs: {
|
|
392
|
+
id: string;
|
|
393
|
+
element: Element | null;
|
|
394
|
+
start: number;
|
|
395
|
+
end: number;
|
|
396
|
+
}[];
|
|
397
|
+
pause(): void;
|
|
398
|
+
play(): void;
|
|
399
|
+
seek(ms: number): void;
|
|
400
|
+
cancel(): void;
|
|
401
|
+
/** The sampled values at the current time on `target`. */
|
|
402
|
+
values(target?: string): SampledValues;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export type ElementSource =
|
|
406
|
+
| { nodeFor(id: string): Element | null }
|
|
407
|
+
| ((id: string) => Element | null)
|
|
408
|
+
| null
|
|
409
|
+
| undefined;
|
|
410
|
+
|
|
411
|
+
export interface PlayerOptions {
|
|
412
|
+
/** Links Notation text or a loaded model. */
|
|
413
|
+
animations?: string | AnimationModel;
|
|
414
|
+
clock?: Clock;
|
|
415
|
+
motion?: Motion | ((element: Element | null) => Motion);
|
|
416
|
+
animate?: (
|
|
417
|
+
element: Element,
|
|
418
|
+
keyframes: object[],
|
|
419
|
+
options: object
|
|
420
|
+
) => {
|
|
421
|
+
finished?: Promise<unknown>;
|
|
422
|
+
currentTime?: number | null;
|
|
423
|
+
pause?(): void;
|
|
424
|
+
play?(): void;
|
|
425
|
+
cancel?(): void;
|
|
426
|
+
};
|
|
427
|
+
resolveToken?: ResolveToken;
|
|
428
|
+
seed?: number | string;
|
|
429
|
+
isCssProperty?: (property: string) => boolean;
|
|
430
|
+
apply?: (element: Element, property: string, value: unknown) => void;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export interface StoreLike {
|
|
434
|
+
get(
|
|
435
|
+
id: string
|
|
436
|
+
): { properties?: { name: string; values: unknown[] }[] } | null | undefined;
|
|
437
|
+
subscribe(listener: (events: object[]) => void): () => void;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
export interface PlayerEvent {
|
|
441
|
+
kind: 'play' | 'cancel';
|
|
442
|
+
id: string;
|
|
443
|
+
run: number;
|
|
444
|
+
options: PlayOptions;
|
|
445
|
+
}
|
|
446
|
+
export interface Player {
|
|
447
|
+
subscribe(listener: (event: PlayerEvent) => void): () => void;
|
|
448
|
+
model: AnimationModel;
|
|
449
|
+
load(source: string | AnimationModel): AnimationModel;
|
|
450
|
+
play(id: string, options?: PlayOptions): PlayControl;
|
|
451
|
+
/** Play `(on STATE ...)` triggers on store state changes; returns unsubscribe. */
|
|
452
|
+
bindTriggers(store: StoreLike): () => void;
|
|
453
|
+
motion(id: string): Motion;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** The plays that fire when element `id` enters `state`. */
|
|
457
|
+
export function triggersFor(
|
|
458
|
+
model: AnimationModel,
|
|
459
|
+
store: StoreLike,
|
|
460
|
+
id: string,
|
|
461
|
+
state: string
|
|
462
|
+
): { animation: string; target: string }[];
|
|
463
|
+
|
|
464
|
+
export function createPlayer(
|
|
465
|
+
handle: ElementSource,
|
|
466
|
+
options?: PlayerOptions
|
|
467
|
+
): Player;
|
|
468
|
+
|
|
469
|
+
// Recording and replay
|
|
470
|
+
export interface RecordingEvent {
|
|
471
|
+
time: number;
|
|
472
|
+
kind:
|
|
473
|
+
| 'set'
|
|
474
|
+
| 'insert'
|
|
475
|
+
| 'remove'
|
|
476
|
+
| 'move'
|
|
477
|
+
| 'input'
|
|
478
|
+
| 'play'
|
|
479
|
+
| 'cancel'
|
|
480
|
+
| 'mark';
|
|
481
|
+
args: import('@link-foundation/ui-core').RawValue[];
|
|
482
|
+
}
|
|
483
|
+
export interface Recording {
|
|
484
|
+
id: string;
|
|
485
|
+
started?: string;
|
|
486
|
+
seed?: number;
|
|
487
|
+
viewport?: [number, number];
|
|
488
|
+
document?: string;
|
|
489
|
+
/** Initial store operations in Links Notation, including stable IDs. */
|
|
490
|
+
snapshot?: string;
|
|
491
|
+
redacted?: boolean;
|
|
492
|
+
truncated?: boolean;
|
|
493
|
+
events: RecordingEvent[];
|
|
494
|
+
headers?: string[];
|
|
495
|
+
}
|
|
496
|
+
export type RecordingSource = string | Recording;
|
|
497
|
+
export function parseRecording(text: string): Recording;
|
|
498
|
+
export function serializeRecording(recording: Recording): string;
|
|
499
|
+
export interface RecorderOptions {
|
|
500
|
+
store: import('@link-foundation/ui-store').Store;
|
|
501
|
+
player?: Player;
|
|
502
|
+
root?: Element;
|
|
503
|
+
handle?: { idFor(node: Node): string | null };
|
|
504
|
+
clock?: { now(): number };
|
|
505
|
+
seed?: number;
|
|
506
|
+
redact?: boolean;
|
|
507
|
+
maxEvents?: number;
|
|
508
|
+
/** Wall-clock origin, separate from the monotonic relative event clock. */
|
|
509
|
+
started?: number | string;
|
|
510
|
+
viewport?: [number, number];
|
|
511
|
+
document?: string;
|
|
512
|
+
}
|
|
513
|
+
export function createRecorder(options: RecorderOptions): {
|
|
514
|
+
start(): void;
|
|
515
|
+
stop(): string;
|
|
516
|
+
mark(label: string): void;
|
|
517
|
+
size(): number;
|
|
518
|
+
};
|
|
519
|
+
/** Pure: a store operation snapshot in Links Notation. */
|
|
520
|
+
export function stateAt(recording: RecordingSource, tMs: number): string;
|
|
521
|
+
export function animationsAt(
|
|
522
|
+
recording: RecordingSource,
|
|
523
|
+
tMs: number,
|
|
524
|
+
options?: {
|
|
525
|
+
model?: AnimationModel;
|
|
526
|
+
resolveToken?: ResolveToken;
|
|
527
|
+
}
|
|
528
|
+
): {
|
|
529
|
+
id: string;
|
|
530
|
+
time: number;
|
|
531
|
+
started: number;
|
|
532
|
+
target?: string;
|
|
533
|
+
input?: string;
|
|
534
|
+
seed?: number | string;
|
|
535
|
+
run?: string;
|
|
536
|
+
}[];
|
|
537
|
+
export interface ReplayControl {
|
|
538
|
+
play(): Promise<void>;
|
|
539
|
+
pause(): void;
|
|
540
|
+
seek(ms: number): void;
|
|
541
|
+
readonly time: number;
|
|
542
|
+
readonly duration: number;
|
|
543
|
+
}
|
|
544
|
+
export function replay(
|
|
545
|
+
recording: RecordingSource,
|
|
546
|
+
options: {
|
|
547
|
+
store: import('@link-foundation/ui-store').Store;
|
|
548
|
+
player?: Player;
|
|
549
|
+
clock?: TimerClock;
|
|
550
|
+
}
|
|
551
|
+
): ReplayControl;
|
|
552
|
+
export function verifyReplay(
|
|
553
|
+
recording: RecordingSource,
|
|
554
|
+
options: {
|
|
555
|
+
createApp(
|
|
556
|
+
seed: number | undefined,
|
|
557
|
+
clock: ManualClock
|
|
558
|
+
):
|
|
559
|
+
| {
|
|
560
|
+
store: import('@link-foundation/ui-store').Store;
|
|
561
|
+
dispatchInput(event: RecordingEvent): void | Promise<void>;
|
|
562
|
+
dispose?(): void;
|
|
563
|
+
}
|
|
564
|
+
| Promise<{
|
|
565
|
+
store: import('@link-foundation/ui-store').Store;
|
|
566
|
+
dispatchInput(event: RecordingEvent): void | Promise<void>;
|
|
567
|
+
dispose?(): void;
|
|
568
|
+
}>;
|
|
569
|
+
}
|
|
570
|
+
): Promise<{
|
|
571
|
+
ok: boolean;
|
|
572
|
+
mismatches: {
|
|
573
|
+
time: number;
|
|
574
|
+
expected: RecordingEvent | null;
|
|
575
|
+
actual: RecordingEvent | null;
|
|
576
|
+
}[];
|
|
577
|
+
}>;
|
|
578
|
+
export function toPlaywright(
|
|
579
|
+
recording: RecordingSource,
|
|
580
|
+
options?: { url?: string }
|
|
581
|
+
): string;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @link-foundation/ui-animation: animations written in Links Notation — a
|
|
3
|
+
* declarative model of keyframe tracks, easings, springs, effects,
|
|
4
|
+
* timelines and state triggers; a pure, seeded sampler; safety validators
|
|
5
|
+
* (persistent fill, WCAG 2.3.1 flashes, reduced motion); a Web Animations
|
|
6
|
+
* API compiler and a player. No GSAP; randomness is always seeded.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
loadAnimations,
|
|
11
|
+
ANIMATION_STATES,
|
|
12
|
+
ANIMATION_DEFAULTS,
|
|
13
|
+
} from './model.js';
|
|
14
|
+
export {
|
|
15
|
+
NAMED_EASINGS,
|
|
16
|
+
SPRING_TOLERANCE,
|
|
17
|
+
isEasingName,
|
|
18
|
+
linear,
|
|
19
|
+
cubicBezier,
|
|
20
|
+
steps,
|
|
21
|
+
spring,
|
|
22
|
+
springEasing,
|
|
23
|
+
toCssLinear,
|
|
24
|
+
easingFunction,
|
|
25
|
+
easingCss,
|
|
26
|
+
} from './easing.js';
|
|
27
|
+
export { sample, sampleTyped, envelopeWeight } from './sample.js';
|
|
28
|
+
export { sampleLayers } from './layers.js';
|
|
29
|
+
export { seededRandom, seedNumber, hashString, mix } from './random.js';
|
|
30
|
+
export { registerEffect, getEffect, effectNames } from './effects.js';
|
|
31
|
+
export {
|
|
32
|
+
decipher,
|
|
33
|
+
revealOrder,
|
|
34
|
+
decipherFrame,
|
|
35
|
+
DECIPHER_CHARACTERS,
|
|
36
|
+
} from './effects/decipher.js';
|
|
37
|
+
export {
|
|
38
|
+
validateAnimation,
|
|
39
|
+
validateAnimations,
|
|
40
|
+
luminanceChanges,
|
|
41
|
+
PERSIST_PROPERTIES,
|
|
42
|
+
FLASH_PROPERTIES,
|
|
43
|
+
FLASH_LIMITS,
|
|
44
|
+
} from './validate.js';
|
|
45
|
+
export {
|
|
46
|
+
toWaapi,
|
|
47
|
+
keyframeProperty,
|
|
48
|
+
isCssProperty,
|
|
49
|
+
NON_CSS_PROPERTIES,
|
|
50
|
+
} from './compile-waapi.js';
|
|
51
|
+
export { flattenTimeline } from './timeline.js';
|
|
52
|
+
export {
|
|
53
|
+
MOVEMENT_PROPERTIES,
|
|
54
|
+
resolveTiming,
|
|
55
|
+
timingAt,
|
|
56
|
+
endTime,
|
|
57
|
+
reducedMotionVariant,
|
|
58
|
+
} from './timing.js';
|
|
59
|
+
export {
|
|
60
|
+
readValue,
|
|
61
|
+
interpolate,
|
|
62
|
+
valueCss,
|
|
63
|
+
relativeLuminance,
|
|
64
|
+
} from './values.js';
|
|
65
|
+
export { tokenResolver } from './tokens.js';
|
|
66
|
+
export { createPlayer, defaultMotion, triggersFor } from './player.js';
|
|
67
|
+
export { createManualClock, systemClock, FRAME_MS } from './clock.js';
|
|
68
|
+
|
|
69
|
+
export { parseRecording, serializeRecording } from './recorder/format.js';
|
|
70
|
+
export { createRecorder } from './recorder/recorder.js';
|
|
71
|
+
export { stateAt, animationsAt } from './recorder/state-at.js';
|
|
72
|
+
export { replay } from './recorder/replay.js';
|
|
73
|
+
export { verifyReplay } from './recorder/verify.js';
|
|
74
|
+
export { toPlaywright } from './recorder/to-playwright.js';
|