@link-foundation/ui-animation 0.0.0-stage → 0.0.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.
Files changed (51) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +454 -2
  3. package/package.json +77 -4
  4. package/src/backgrounds/README.md +131 -0
  5. package/src/backgrounds/beams.d.ts +21 -0
  6. package/src/backgrounds/beams.js +140 -0
  7. package/src/backgrounds/common.d.ts +23 -0
  8. package/src/backgrounds/common.js +322 -0
  9. package/src/backgrounds/grid.d.ts +16 -0
  10. package/src/backgrounds/grid.js +122 -0
  11. package/src/backgrounds/nebula.d.ts +9 -0
  12. package/src/backgrounds/nebula.js +57 -0
  13. package/src/backgrounds/rain-cleanup.js +77 -0
  14. package/src/backgrounds/rain.d.ts +33 -0
  15. package/src/backgrounds/rain.js +238 -0
  16. package/src/backgrounds/shader.d.ts +14 -0
  17. package/src/backgrounds/shader.js +151 -0
  18. package/src/backgrounds/sprites.js +72 -0
  19. package/src/backgrounds/starfield.d.ts +38 -0
  20. package/src/backgrounds/starfield.js +168 -0
  21. package/src/clock.js +98 -0
  22. package/src/compile-waapi.js +147 -0
  23. package/src/diagnostics.js +51 -0
  24. package/src/easing.js +327 -0
  25. package/src/effects/decipher.js +83 -0
  26. package/src/effects.js +44 -0
  27. package/src/index.d.ts +581 -0
  28. package/src/index.js +74 -0
  29. package/src/layers.js +88 -0
  30. package/src/model.js +636 -0
  31. package/src/player.js +267 -0
  32. package/src/random.js +62 -0
  33. package/src/recorder/buffer.js +40 -0
  34. package/src/recorder/clock.js +2 -0
  35. package/src/recorder/format.js +125 -0
  36. package/src/recorder/input.js +53 -0
  37. package/src/recorder/recorder.js +183 -0
  38. package/src/recorder/redact.js +43 -0
  39. package/src/recorder/replay.js +115 -0
  40. package/src/recorder/state-at.js +62 -0
  41. package/src/recorder/store.js +92 -0
  42. package/src/recorder/to-playwright.js +113 -0
  43. package/src/recorder/verify.js +49 -0
  44. package/src/run.js +283 -0
  45. package/src/sample.js +160 -0
  46. package/src/timeline.js +115 -0
  47. package/src/timing.js +172 -0
  48. package/src/tokens.js +32 -0
  49. package/src/types.js +130 -0
  50. package/src/validate.js +218 -0
  51. package/src/values.js +331 -0
@@ -0,0 +1,72 @@
1
+ import { radians } from './common.js';
2
+
3
+ /** Original normalized sprite outlines, drawn once per look/DPR. */
4
+ function outline(Path, shape) {
5
+ const p = new Path();
6
+ if (shape === 'dot' || shape === 'soft-dot' || shape === 'ring') {
7
+ p.arc(0, 0, 1, 0, Math.PI * 2);
8
+ } else if (shape === 'square') {
9
+ p.rect(-0.8, -0.8, 1.6, 1.6);
10
+ } else if (
11
+ shape === 'cross' ||
12
+ shape === 'cross-x' ||
13
+ shape === 'telescope-flare'
14
+ ) {
15
+ p.moveTo(-1, 0);
16
+ p.lineTo(1, 0);
17
+ p.moveTo(0, -1);
18
+ p.lineTo(0, 1);
19
+ if (shape === 'telescope-flare') {
20
+ p.arc(0, 0, 0.25, 0, Math.PI * 2);
21
+ }
22
+ } else {
23
+ const points =
24
+ { diamond: 2, 'star-4': 4, 'star-5': 5, 'star-6': 6, sparkle: 4 }[
25
+ shape
26
+ ] ?? 4;
27
+ for (let i = 0; i < points * 2; i++) {
28
+ const angle = (i * Math.PI) / points - Math.PI / 2;
29
+ const r = i % 2 ? (shape === 'sparkle' ? 0.12 : 0.4) : 1;
30
+ const x = Math.cos(angle) * r,
31
+ y = Math.sin(angle) * r;
32
+ if (i === 0) {
33
+ p.moveTo(x, y);
34
+ } else {
35
+ p.lineTo(x, y);
36
+ }
37
+ }
38
+ p.closePath();
39
+ }
40
+ return p;
41
+ }
42
+
43
+ export function sprite(canvas, win, o, dpr, hue) {
44
+ const image = canvas.ownerDocument.createElement('canvas');
45
+ const extent = Math.ceil((o.size + o.glow * 2 + 4) * dpr);
46
+ image.width = image.height = extent;
47
+ const ctx = image.getContext('2d');
48
+ if (!ctx) {
49
+ throw new Error('Sprite context unavailable');
50
+ }
51
+ ctx.translate(extent / 2, extent / 2);
52
+ ctx.rotate(radians(o.shape === 'cross-x' ? 45 : 0));
53
+ ctx.scale((o.size * dpr) / 2, (o.size * dpr) / 2);
54
+ ctx.fillStyle = ctx.strokeStyle = o.color;
55
+ ctx.filter = `hue-rotate(${hue}deg)`;
56
+ ctx.shadowColor = o.glowColor;
57
+ ctx.shadowBlur = o.glow * dpr;
58
+ const path = outline(win.Path2D, o.shape);
59
+ if (['ring', 'cross', 'cross-x', 'telescope-flare'].includes(o.shape)) {
60
+ ctx.lineWidth = 0.18;
61
+ ctx.stroke(path);
62
+ } else if (o.shape === 'soft-dot') {
63
+ const gradient = ctx.createRadialGradient(0, 0, 0, 0, 0, 1);
64
+ gradient.addColorStop(0, o.color);
65
+ gradient.addColorStop(1, 'transparent');
66
+ ctx.fillStyle = gradient;
67
+ ctx.fill(path);
68
+ } else {
69
+ ctx.fill(path);
70
+ }
71
+ return { image, size: extent / dpr };
72
+ }
@@ -0,0 +1,38 @@
1
+ import type { CommonOptions, LayerHandle } from './common.js';
2
+ export interface StarfieldOptions extends CommonOptions {
3
+ seed?: number | string;
4
+ count?: number;
5
+ shape?:
6
+ | 'dot'
7
+ | 'soft-dot'
8
+ | 'ring'
9
+ | 'square'
10
+ | 'diamond'
11
+ | 'cross'
12
+ | 'cross-x'
13
+ | 'star-4'
14
+ | 'star-5'
15
+ | 'star-6'
16
+ | 'sparkle'
17
+ | 'telescope-flare';
18
+ size?: number;
19
+ sizeSpread?: number;
20
+ color?: string;
21
+ hueSpread?: number;
22
+ brightness?: number;
23
+ glow?: number;
24
+ glowColor?: string;
25
+ twinkleRate?: number;
26
+ twinkleDepth?: number;
27
+ rotation?: number;
28
+ spin?: number;
29
+ motion?: 'still' | 'drift' | 'warp' | 'orbit';
30
+ direction?: number;
31
+ speed?: number;
32
+ streak?: number;
33
+ blend?: 'normal' | 'add' | 'screen';
34
+ }
35
+ export function mount(
36
+ canvas: HTMLCanvasElement,
37
+ options?: StarfieldOptions
38
+ ): LayerHandle<StarfieldOptions>;
@@ -0,0 +1,168 @@
1
+ import { seededRandom } from '../random.js';
2
+ import { mountLayer, changed, clamp, bounded, radians } from './common.js';
3
+ import { sprite } from './sprites.js';
4
+
5
+ const defaults = {
6
+ count: 160,
7
+ seed: 224,
8
+ shape: 'dot',
9
+ size: 2,
10
+ sizeSpread: 0.5,
11
+ color: '#ffffff',
12
+ hueSpread: 0,
13
+ brightness: 1,
14
+ glow: 0,
15
+ glowColor: '#ffffff',
16
+ twinkleRate: 1,
17
+ twinkleDepth: 0.3,
18
+ rotation: 0,
19
+ spin: 0,
20
+ motion: 'still',
21
+ direction: 90,
22
+ speed: 20,
23
+ streak: 0,
24
+ blend: 'normal',
25
+ };
26
+ const looks = ['shape', 'size', 'color', 'hueSpread', 'glow', 'glowColor'];
27
+
28
+ function create(canvas, win) {
29
+ const ctx = canvas.getContext('2d');
30
+ if (!ctx || !win.Path2D) {
31
+ return null;
32
+ }
33
+ let o,
34
+ area,
35
+ stars = [],
36
+ sprites = [],
37
+ dirty = true,
38
+ twinkleClock = 0,
39
+ rotationClock = 0;
40
+ const seed = () => {
41
+ const random = seededRandom(o.seed);
42
+ const count = Math.min(
43
+ 6000,
44
+ Math.round(
45
+ (clamp(o.count, 0, 3000) * area.width * area.height) / (1920 * 1080)
46
+ )
47
+ );
48
+ stars = Array.from({ length: count }, () => ({
49
+ x: random(),
50
+ y: random(),
51
+ depth: 0.2 + random() * 0.8,
52
+ phase: random() * Math.PI * 2,
53
+ size: random(),
54
+ hue: Math.floor(random() * 9),
55
+ }));
56
+ };
57
+ const rebuild = () => {
58
+ sprites = Array.from({ length: 9 }, (_, i) =>
59
+ sprite(canvas, win, o, area.dpr, (i / 4 - 1) * o.hueSpread)
60
+ );
61
+ dirty = false;
62
+ };
63
+ function advance(star, dt) {
64
+ const speed = o.speed * star.depth;
65
+ if (o.motion === 'drift') {
66
+ star.x =
67
+ (star.x +
68
+ (Math.cos(radians(o.direction)) * speed * dt) / area.width +
69
+ 1) %
70
+ 1;
71
+ star.y =
72
+ (star.y +
73
+ (Math.sin(radians(o.direction)) * speed * dt) / area.height +
74
+ 1) %
75
+ 1;
76
+ } else if (o.motion === 'warp') {
77
+ star.x = (0.5 + (star.x - 0.5) * (1 + (speed * dt) / 200) + 1) % 1;
78
+ star.y = (0.5 + (star.y - 0.5) * (1 + (speed * dt) / 200) + 1) % 1;
79
+ } else if (o.motion === 'orbit') {
80
+ const x = (star.x - 0.5) * area.width,
81
+ y = (star.y - 0.5) * area.height;
82
+ const angle = (speed * dt) / Math.max(40, Math.hypot(x, y));
83
+ star.x = 0.5 + (x * Math.cos(angle) - y * Math.sin(angle)) / area.width;
84
+ star.y = 0.5 + (x * Math.sin(angle) + y * Math.cos(angle)) / area.height;
85
+ }
86
+ }
87
+ return {
88
+ defaults,
89
+ update(next, before) {
90
+ o = bounded(next, {
91
+ count: [0, 3000],
92
+ size: [0.5, 24],
93
+ sizeSpread: [0, 1],
94
+ hueSpread: [0, 180],
95
+ brightness: [0, 1],
96
+ glow: [0, 40],
97
+ twinkleRate: [0, 5],
98
+ twinkleDepth: [0, 1],
99
+ rotation: [0, 180],
100
+ spin: [-180, 180],
101
+ direction: [0, 360],
102
+ speed: [0, 400],
103
+ streak: [0, 20],
104
+ });
105
+ dirty ||= changed(next, before, looks);
106
+ if (area && changed(next, before, ['count', 'seed'])) {
107
+ seed();
108
+ }
109
+ return changed(
110
+ next,
111
+ before,
112
+ Object.keys(defaults).filter(
113
+ (key) => !['twinkleRate', 'spin', 'direction'].includes(key)
114
+ )
115
+ );
116
+ },
117
+ resize(next, old) {
118
+ area = next;
119
+ if (!old || changed(next, old, ['width', 'height'])) {
120
+ seed();
121
+ }
122
+ dirty ||= !old || next.dpr !== old.dpr;
123
+ },
124
+ draw(dt, { still }) {
125
+ if (dirty) {
126
+ rebuild();
127
+ }
128
+ twinkleClock += still ? 0 : dt * o.twinkleRate;
129
+ rotationClock += still ? 0 : dt * o.spin;
130
+ ctx.setTransform(area.ratio, 0, 0, area.ratio, 0, 0);
131
+ ctx.clearRect(0, 0, area.width, area.height);
132
+ ctx.globalCompositeOperation =
133
+ { normal: 'source-over', add: 'lighter', screen: 'screen' }[o.blend] ??
134
+ 'source-over';
135
+ for (const star of stars) {
136
+ if (!still) {
137
+ advance(star, dt);
138
+ }
139
+ const item = sprites[star.hue];
140
+ const size = item.size * (1 - o.sizeSpread * star.size);
141
+ ctx.globalAlpha = clamp(
142
+ o.brightness *
143
+ (1 -
144
+ o.twinkleDepth *
145
+ (0.5 +
146
+ 0.5 * Math.sin(twinkleClock * Math.PI * 2 + star.phase))),
147
+ 0,
148
+ 1
149
+ );
150
+ ctx.save();
151
+ ctx.translate(star.x * area.width, star.y * area.height);
152
+ ctx.rotate(radians(o.rotation + rotationClock));
153
+ ctx.drawImage(
154
+ item.image,
155
+ -size / 2,
156
+ -size / 2,
157
+ size * (1 + (still ? 0 : (o.streak * o.speed) / 400)),
158
+ size
159
+ );
160
+ ctx.restore();
161
+ }
162
+ },
163
+ };
164
+ }
165
+
166
+ /** Mount one star layer; stack up to four canvases with independent options. */
167
+ export const mount = (canvas, options = {}) =>
168
+ mountLayer(canvas, options, create);
package/src/clock.js ADDED
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Clocks of the player: the page clock (`performance.now()` and animation
3
+ * frames) and a manual clock that only moves when told to, which makes
4
+ * playback deterministic in tests and offline rendering.
5
+ */
6
+
7
+ /** One frame at 60 Hz (ms). */
8
+ export const FRAME_MS = 1000 / 60;
9
+
10
+ /**
11
+ * A clock that only moves when told to.
12
+ * @param {number} [start]
13
+ * @returns {import('./index.js').ManualClock}
14
+ */
15
+ export function createManualClock(start = 0) {
16
+ let now = start;
17
+ let nextId = 1;
18
+ const frames = new Map();
19
+ const timers = new Map();
20
+ const runFrames = () => {
21
+ const callbacks = [...frames.values()];
22
+ frames.clear();
23
+ for (const callback of callbacks) {
24
+ callback(now);
25
+ }
26
+ };
27
+ return {
28
+ now: () => now,
29
+ requestFrame(callback) {
30
+ const id = nextId++;
31
+ frames.set(id, callback);
32
+ return id;
33
+ },
34
+ cancelFrame(id) {
35
+ frames.delete(id);
36
+ },
37
+ setTimeout(callback, ms) {
38
+ const id = nextId++;
39
+ timers.set(id, { at: now + Math.max(0, ms), callback });
40
+ return id;
41
+ },
42
+ clearTimeout(id) {
43
+ timers.delete(id);
44
+ },
45
+ /** Move the time forward by `ms`, one frame (`step` ms) at a time. */
46
+ advance(ms, step = FRAME_MS) {
47
+ if (
48
+ !Number.isFinite(ms) ||
49
+ ms < 0 ||
50
+ !Number.isFinite(step) ||
51
+ step <= 0
52
+ ) {
53
+ throw new RangeError('Invalid clock advance');
54
+ }
55
+ const end = now + ms;
56
+ do {
57
+ const frameAt = Math.min(end, now + step);
58
+ for (;;) {
59
+ let due;
60
+ for (const item of timers) {
61
+ if (item[1].at <= frameAt && (!due || item[1].at < due[1].at)) {
62
+ due = item;
63
+ }
64
+ }
65
+ if (!due) {
66
+ break;
67
+ }
68
+ timers.delete(due[0]);
69
+ now = due[1].at;
70
+ due[1].callback();
71
+ }
72
+ now = frameAt;
73
+ runFrames();
74
+ } while (now < end);
75
+ },
76
+ /** Pending frame callbacks. */
77
+ get pending() {
78
+ return frames.size + timers.size;
79
+ },
80
+ };
81
+ }
82
+
83
+ /** The clock of the page: `performance.now()` and animation frames. */
84
+ export function systemClock() {
85
+ const raf = globalThis.requestAnimationFrame;
86
+ return {
87
+ now: () => globalThis.performance.now(),
88
+ setTimeout: (callback, ms) => setTimeout(callback, ms),
89
+ clearTimeout: (id) => clearTimeout(id),
90
+ requestFrame: raf
91
+ ? (callback) => raf(callback)
92
+ : (callback) =>
93
+ setTimeout(() => callback(globalThis.performance.now()), FRAME_MS),
94
+ cancelFrame: raf
95
+ ? (id) => globalThis.cancelAnimationFrame(id)
96
+ : (id) => clearTimeout(id),
97
+ };
98
+ }
@@ -0,0 +1,147 @@
1
+ /**
2
+ * `toWaapi(animation, { resolveToken })`: an animation as the arguments of
3
+ * `element.animate(keyframes, options)` (Web Animations API).
4
+ *
5
+ * Keyframes are written per offset; a key easing becomes the `easing` of its
6
+ * keyframe (WAAPI applies it to the segment that starts there), defaulting
7
+ * to the animation easing. `options.easing` stays linear so offsets are time
8
+ * positions. Values are CSS text
9
+ * (`scale: '0.96'`). Tracks of non-CSS properties (`text`, ...) and effects
10
+ * are left out: the player runs them in its frame loop. An animation with an
11
+ * `(envelope ...)` is baked into sampled keyframes, since WAAPI has no
12
+ * envelope.
13
+ */
14
+
15
+ import { easingCss } from './easing.js';
16
+ import { sampleTyped } from './sample.js';
17
+ import { resolveDuration, resolveTime } from './timing.js';
18
+ import { resolveValue, valueCss } from './values.js';
19
+
20
+ /** Properties of UI elements that are not CSS: the frame loop runs them. */
21
+ export const NON_CSS_PROPERTIES = Object.freeze([
22
+ 'text',
23
+ 'label',
24
+ 'value',
25
+ 'title',
26
+ 'placeholder',
27
+ 'progress',
28
+ ]);
29
+
30
+ /** Whether a track property is a CSS property WAAPI can animate. */
31
+ export const isCssProperty = (property) =>
32
+ !NON_CSS_PROPERTIES.includes(property);
33
+
34
+ /** Keyframes sampled for an animation with an envelope. */
35
+ const BAKED_SAMPLES = 40;
36
+
37
+ /**
38
+ * The WAAPI keyframe key of a CSS property: `background-color` ->
39
+ * `backgroundColor`, `offset` -> `cssOffset`, `float` -> `cssFloat`; custom
40
+ * properties (`--x`) stay as they are.
41
+ */
42
+ export function keyframeProperty(property) {
43
+ if (property.startsWith('--')) {
44
+ return property;
45
+ }
46
+ if (property === 'offset' || property === 'float') {
47
+ return `css${property[0].toUpperCase()}${property.slice(1)}`;
48
+ }
49
+ let out = '';
50
+ for (let i = 0; i < property.length; i++) {
51
+ const c = property[i];
52
+ if (c === '-' && i + 1 < property.length) {
53
+ i++;
54
+ out += property[i].toUpperCase();
55
+ } else {
56
+ out += c;
57
+ }
58
+ }
59
+ return out;
60
+ }
61
+
62
+ function trackKeyframes(tracks, resolveToken, defaultEasing) {
63
+ const frames = [];
64
+ for (const track of tracks) {
65
+ const name = keyframeProperty(track.property);
66
+ for (const key of track.keys) {
67
+ const css = easingCss(key.easing ?? defaultEasing, resolveToken);
68
+ const easing = css === 'linear' ? null : css;
69
+ let frame = frames.find(
70
+ (f) =>
71
+ f.offset === key.offset &&
72
+ (f.easing ?? null) === easing &&
73
+ !Object.hasOwn(f, name)
74
+ );
75
+ if (!frame) {
76
+ frame = { offset: key.offset };
77
+ if (easing) {
78
+ frame.easing = easing;
79
+ }
80
+ frames.push(frame);
81
+ }
82
+ frame[name] = valueCss(resolveValue(key.value, resolveToken));
83
+ }
84
+ }
85
+ return frames.sort((a, b) => a.offset - b.offset);
86
+ }
87
+
88
+ /** One iteration sampled into linear keyframes (segment easing included). */
89
+ function bakedKeyframes(animation, tracks, duration, resolveToken) {
90
+ const single = {
91
+ ...animation,
92
+ tracks,
93
+ effect: null,
94
+ delay: 0,
95
+ iterations: 1,
96
+ direction: 'normal',
97
+ fill: 'both',
98
+ duration,
99
+ };
100
+ const frames = [];
101
+ for (let i = 0; i <= BAKED_SAMPLES; i++) {
102
+ const offset = i / BAKED_SAMPLES;
103
+ const { values } = sampleTyped(single, offset * duration, { resolveToken });
104
+ const frame = { offset };
105
+ for (const [property, value] of values) {
106
+ frame[keyframeProperty(property)] = valueCss(value);
107
+ }
108
+ frames.push(frame);
109
+ }
110
+ return frames;
111
+ }
112
+
113
+ /**
114
+ * @param {import('./types.js').Animation} animation
115
+ * @param {{ resolveToken?: (path: string) => unknown,
116
+ * isCssProperty?: (property: string) => boolean }} [options]
117
+ * @returns {{ keyframes: Record<string, string|number>[], options: Record<string, string|number> }}
118
+ */
119
+ export function toWaapi(animation, options = {}) {
120
+ const { resolveToken } = options;
121
+ const css = options.isCssProperty ?? isCssProperty;
122
+ const tracks = animation.tracks.filter(
123
+ (t) => css(t.property) && t.keys.length > 0
124
+ );
125
+ const duration = resolveDuration(animation, resolveToken);
126
+ const baked = Boolean(animation.envelope);
127
+ const keyframes = baked
128
+ ? bakedKeyframes(animation, tracks, duration, resolveToken)
129
+ : trackKeyframes(tracks, resolveToken, animation.easing);
130
+ const timing = {
131
+ duration,
132
+ easing: 'linear',
133
+ fill: animation.fill ?? 'none',
134
+ composite: animation.composite ?? 'replace',
135
+ };
136
+ const delay = resolveTime(animation.delay ?? 0, resolveToken) ?? 0;
137
+ if (delay !== 0) {
138
+ timing.delay = delay;
139
+ }
140
+ if ((animation.iterations ?? 1) !== 1) {
141
+ timing.iterations = animation.iterations;
142
+ }
143
+ if ((animation.direction ?? 'normal') !== 'normal') {
144
+ timing.direction = animation.direction;
145
+ }
146
+ return { keyframes, options: timing };
147
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Diagnostics of the animation model and the validators, in the shape of
3
+ * ui-core diagnostics: `{ code, severity, message, at }`, where `at` names
4
+ * the animation or timeline (`element`) and the part (`property`, `track`).
5
+ */
6
+
7
+ const of = (at) =>
8
+ at.element === undefined || at.element === null ? '' : ` of "${at.element}"`;
9
+ const text = (at) => (at.text === undefined ? '' : ` "${at.text}"`);
10
+ const track = (at) => (at.track === undefined ? '' : ` "${at.track}"`);
11
+
12
+ const MESSAGES = {
13
+ 'anonymous-animation': () =>
14
+ 'An animation or timeline has no id; write (NAME: animation ...) so that timelines and triggers can play it',
15
+ 'unknown-sublink': (at) =>
16
+ `The ${at.kind}${of(at)} has the unknown part${text(at)}; it is ignored`,
17
+ 'invalid-value': (at) =>
18
+ `The ${at.property}${of(at)} has the invalid value${text(at)}; expected ${at.expected}`,
19
+ 'unknown-easing': (at) =>
20
+ `The easing${of(at)} is unknown${text(at)}; use a name (standard, linear, ...), (cubic-bezier a b c d), (steps n) or (spring (stiffness k) (damping c) (mass m))`,
21
+ 'empty-track': (at) =>
22
+ `The track${track(at)}${of(at)} has no (key OFFSET VALUE)`,
23
+ 'key-offset-range': (at) =>
24
+ `A key of the track${track(at)}${of(at)} has the offset${text(at)}; key offsets are numbers from 0 to 1`,
25
+ 'key-offset-order': (at) =>
26
+ `The keys of the track${track(at)}${of(at)} are not sorted: the offset${text(at)} comes after a larger one`,
27
+ 'unknown-effect': (at) =>
28
+ `The effect${text(at)}${of(at)} is not registered; register it with registerEffect(name, fn)`,
29
+ 'unknown-state': (at) =>
30
+ `The trigger${of(at)} has the unknown state${text(at)}; a state is hover, focus, pressed or disabled`,
31
+ 'unknown-animation': (at) =>
32
+ `The ${at.property}${of(at)} plays${text(at)}, which is not an animation or timeline`,
33
+ 'timeline-cycle': (at) =>
34
+ `The timeline${of(at)} plays itself through${text(at)}; timelines must not form a cycle`,
35
+ 'persistent-fill': (at) =>
36
+ `The animation${of(at)} has (fill ${at.fill}) on the ${at.track} track: the final ${at.track} stays on the element after it ends and breaks later layout (immortality issue-7, R19); use (fill none) or (fill backwards), or write (persist true) if the end state must stay`,
37
+ flash: (at) =>
38
+ `The ${at.track} track${of(at)} flashes ${at.flashes} times within one second (WCAG 2.3.1 allows at most ${at.limit}); slow it down, soften the change below 10% luminance, or remove it`,
39
+ 'missing-reduced-motion': (at) =>
40
+ `The animation${of(at)} moves (${at.track}) for ${at.duration}ms but has no (reduced-motion ...) block; under reduced motion only its opacity tracks will play`,
41
+ };
42
+
43
+ /**
44
+ * @param {string} code
45
+ * @param {'error'|'warning'|'info'} severity
46
+ * @param {Record<string, any>} at
47
+ * @returns {import('./types.js').Diagnostic}
48
+ */
49
+ export function animationDiagnostic(code, severity, at) {
50
+ return { code, severity, message: MESSAGES[code](at), at };
51
+ }