@mkbabb/keyframes.js 5.3.5 → 6.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/README.md +123 -67
- package/dist/engine/index.d.ts +354 -404
- package/dist/engine/index.js +2362 -1606
- package/dist/keyframes.d.ts +462 -470
- package/dist/keyframes.js +180 -146
- package/dist/registry-CPtiwlwX.js +162 -0
- package/dist/registry-Dd7GzvJm.js +2 -0
- package/dist/{sequence-CES7o7hs.js → sequence-BUgKKePR.js} +128 -98
- package/package.json +15 -12
- package/dist/easing-registry-BAgudUsG.js +0 -2
- package/dist/easing-registry-BlbS88NR.js +0 -27
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ CSS keyframe animations for anything in JavaScript. Specify your keyframes in st
|
|
|
6
6
|
|
|
7
7
|
## Quick Start
|
|
8
8
|
|
|
9
|
-
Create a `CSSKeyframesAnimation`, feed it CSS `@keyframes`, add targets, play. The engine class is a static, synchronous import from the `@mkbabb/keyframes.js/engine` subpath (it carries
|
|
9
|
+
Create a `CSSKeyframesAnimation`, feed it CSS `@keyframes`, add targets, play. The engine class is a static, synchronous import from the `@mkbabb/keyframes.js/engine` subpath (it carries Value's CSS parser and color/value capabilities; the light `.` barrel shares only Value's small `/math` leaf):
|
|
10
10
|
|
|
11
11
|
```ts run
|
|
12
12
|
import { CSSKeyframesAnimation } from "@mkbabb/keyframes.js/engine";
|
|
@@ -85,7 +85,7 @@ type TransformFunction<V extends Vars> = (v: V, t: number) => void;
|
|
|
85
85
|
|
|
86
86
|
Called at each timestep `t` (0 to `duration`) with the interpolated variables `v`. The variables arrive in the same shape you specified in your keyframes—deeply nested objects included.
|
|
87
87
|
|
|
88
|
-
Every
|
|
88
|
+
Every declaration is parsed into a structural `CssValue` tree. Numeric scalar leaves retain their CSS unit (`px`, `em`, `deg`, etc.); compatible units share a numeric interpolation slot, computed lengths resolve against the bound browser target, and incompatible kinds fail explicitly.
|
|
89
89
|
|
|
90
90
|
### The timing function
|
|
91
91
|
|
|
@@ -138,7 +138,7 @@ anim.setTargets(element);
|
|
|
138
138
|
await anim.play();
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
The engine surface (`AnimationEngine`): `KeyframesAnimation`, `CSSKeyframesAnimation`, `AnimationGroup`, `getAnimationId`, `
|
|
141
|
+
The engine surface (`AnimationEngine`): `KeyframesAnimation`, `CSSKeyframesAnimation`, `AnimationGroup`, `getAnimationId`, `resolveKeyframes`, `MotionPath`/`fromMotionPath`, `DrawSVG`/`fromDrawSVG`, `MorphSVG`/`fromMorphSVG`, `presets`, and the option constants `DIRECTIONS`, `FILL_MODES`, `defaultOptions`, `defaultLayerConfig`. The **type** surface stays on the static barrel — `import type { KeyframesAnimation } from "@mkbabb/keyframes.js"` costs no runtime edge.
|
|
142
142
|
|
|
143
143
|
### `MotionPath`
|
|
144
144
|
|
|
@@ -179,7 +179,7 @@ Options: `from`/`to` (`"0%"`–`"100%"` strings or `0`–`1` numbers; default dr
|
|
|
179
179
|
|
|
180
180
|
### `MorphSVG`
|
|
181
181
|
|
|
182
|
-
Path-shape morphing — interpolate one SVG path `d` into another. value.js's `PathGeometry` owns the geometry (arc-length sampling via `getTotalLength()`/`getPointAtLength()`); keyframes samples both paths at `samples` uniform points and lerps the matched point sets, so the engine's native numeric interpolation
|
|
182
|
+
Path-shape morphing — interpolate one SVG path `d` into another. value.js's `PathGeometry` owns the geometry (arc-length sampling via `getTotalLength()`/`getPointAtLength()`); keyframes samples both paths at `samples` uniform points and lerps the matched point sets, so the engine's native numeric interpolation _is_ the morph (a true blend — the midpoint is distinct from both endpoints, not a cross-fade).
|
|
183
183
|
|
|
184
184
|
```ts run
|
|
185
185
|
const { fromMorphSVG, MorphSVG } = await loadAnimationEngine();
|
|
@@ -212,10 +212,15 @@ const { keyframes } = resolveKeyframes(`
|
|
|
212
212
|
100% { color: green }
|
|
213
213
|
}
|
|
214
214
|
`);
|
|
215
|
-
|
|
215
|
+
const resolvedColor = keyframes.get("0%")?.color;
|
|
216
|
+
resolvedColor?.kind; // => "scalar"
|
|
217
|
+
const channels = resolvedColor?.kind === "scalar" && resolvedColor.payload.type === "color"
|
|
218
|
+
? resolvedColor.payload.value.channels
|
|
219
|
+
: [];
|
|
220
|
+
channels; // => [0, 0, 255]
|
|
216
221
|
```
|
|
217
222
|
|
|
218
|
-
**What it refuses.** A condition that resolves to nothing is a CSS
|
|
223
|
+
**What it refuses.** A condition that resolves to nothing is a CSS _guaranteed-invalid value_ — `if()` with no matching branch and no `else`, or an over-deep/self-referential `@function` chain (cycle-guarded at depth 32) — **drops the declaration** (the prior/initial value wins), never an empty or malformed string. A `@function` call whose argument can't be coerced to the parameter's declared syntax drops the whole call too, surfaced as a named `CUSTOM_FN_ARG_DROP` diagnostic on `resolveKeyframes`'s `diagnostics` channel — never a silent `NaN`.
|
|
219
224
|
|
|
220
225
|
Covered by the three focused Vitest files in `test/resolve/` (the
|
|
221
226
|
`if(supports)`/`if(media)` pass, the element-aware
|
|
@@ -256,11 +261,11 @@ The default transform applies interpolated values to `element.style` for each ta
|
|
|
256
261
|
- Math expressions (`calc(100% - 10px)`)
|
|
257
262
|
- Any `key: value` pair parseable as a CSS value, function, or list thereof
|
|
258
263
|
|
|
259
|
-
The parser
|
|
264
|
+
The parser consumes [`@mkbabb/value.js/css`](https://github.com/mkbabb/value.js) for CSS grammar and typed parse results. Keyframes does not carry a second parser dependency or consume Value's package root.
|
|
260
265
|
|
|
261
266
|
### Units
|
|
262
267
|
|
|
263
|
-
Unit parsing and resolution (length, angle, time, percentage, color, and container-query units) are handled
|
|
268
|
+
Unit parsing and resolution (length, angle, time, percentage, color, and container-query units) are handled through Value 4's rootless capability entries. Parsed values use immutable structural `CssScalar`, `CssList`, and `CssCall` nodes; parsing returns an explicit result rather than mutable token objects. Computed container units are resolved against the measured layout epoch; consumers that change the containing layout must call `bumpLayoutEpoch()` before sampling again so cached conversions are invalidated.
|
|
264
269
|
|
|
265
270
|
## `AnimationGroup`
|
|
266
271
|
|
|
@@ -272,17 +277,23 @@ group.setTargets(element);
|
|
|
272
277
|
group.play();
|
|
273
278
|
```
|
|
274
279
|
|
|
275
|
-
Three
|
|
280
|
+
Three composition operators:
|
|
276
281
|
|
|
277
282
|
- **`replace`**: highest `zIndex` wins (default)
|
|
278
283
|
- **`add`**: numeric values accumulate
|
|
279
|
-
- **`
|
|
284
|
+
- **`accumulate`**: numeric values accumulate across repeated composition
|
|
285
|
+
|
|
286
|
+
Replacement and composition are orthogonal to the layer's `weight` (0–1). A
|
|
287
|
+
static `weight` produces a linear blend; `weightSpring` lets the same scalar be
|
|
288
|
+
driven by the group's spring-transition API.
|
|
280
289
|
|
|
281
290
|
Managed children are paused and resumed by the group clock: pause captures the
|
|
282
291
|
last rAF timestamp, resume clears the managed pause directly (never by calling a
|
|
283
292
|
child's public `resume()`), and settling releases the child from group ownership.
|
|
284
293
|
|
|
285
|
-
Layer configuration per animation: `zIndex`, `
|
|
294
|
+
Layer configuration per animation: `zIndex`, `op`, `weight`, `weightSpring`,
|
|
295
|
+
`enabled`, `properties` (whitelist). Property whitelisting enables effect
|
|
296
|
+
layering—one layer animates position, another animates opacity.
|
|
286
297
|
|
|
287
298
|
The group manages its own `requestAnimationFrame` loop and marks child animations as `managed`.
|
|
288
299
|
|
|
@@ -290,7 +301,7 @@ The group manages its own `requestAnimationFrame` loop and marks child animation
|
|
|
290
301
|
|
|
291
302
|
## Presets
|
|
292
303
|
|
|
293
|
-
30+ ready-to-use animations in `src/animation/presets/`. All return `CSSKeyframesAnimation` instances and accept optional `InputAnimationOptions`. Each builds a
|
|
304
|
+
30+ ready-to-use animations in `src/animation/presets/`. All return `CSSKeyframesAnimation` instances and accept optional `InputAnimationOptions`. Each builds a `CSSKeyframesAnimation` with Value's parser/color graph, so the presets ride the heavy dynamic boundary (the `presets` namespace on `loadAnimationEngine()`) rather than the parser-free static barrel:
|
|
294
305
|
|
|
295
306
|
```ts
|
|
296
307
|
import { loadAnimationEngine } from "@mkbabb/keyframes.js";
|
|
@@ -307,15 +318,15 @@ anim.play();
|
|
|
307
318
|
|
|
308
319
|
keyframes.js's authoring object **is** parsed CSS `@keyframes`. That one fact opens a loop no other engine can close:
|
|
309
320
|
|
|
310
|
-
1. **Ingest** — read the live web's CSS (`@keyframes` in a stylesheet, or a
|
|
321
|
+
1. **Ingest** — read the live web's CSS (`@keyframes` in a stylesheet, or a _running_ CSS animation) straight into a kf `CSSKeyframesAnimation`.
|
|
311
322
|
2. **Drive** — run it through the engine: physics-shaped springs, perceptual `oklab` color, scroll-driven progress, weighted blending.
|
|
312
|
-
3. **Compile** — emit the result **back** to zero-runtime CSS. Three sibling emitters run the SAME parser
|
|
323
|
+
3. **Compile** — emit the result **back** to zero-runtime CSS. Three sibling emitters run the SAME parser _backward_ over the same data model (`format.ts` is `keyframes.ts` in reverse): [`compileToCSS`](#compile--the-parser-run-backward) (plain `@keyframes`), [`compileToViewTransition`](#compiletoviewtransition) (the `::view-transition-*` pseudo tree), and [`compileToEntry`](#compiletoentry) (`@starting-style`/`allow-discrete` entry-exit).
|
|
313
324
|
|
|
314
|
-
This is the moat. GSAP, Motion, and anime author in a bespoke tween model — for them "export to CSS" is a lossy re-derivation nobody ships, and "import the page's CSS" has no meaning. Because kf's internal model is
|
|
325
|
+
This is the moat. GSAP, Motion, and anime author in a bespoke tween model — for them "export to CSS" is a lossy re-derivation nobody ships, and "import the page's CSS" has no meaning. Because kf's internal model is _already_ CSS, the forward and backward halves are inverses over one structure: a `var()`, a `matrix3d()`, a `cqw` round-trips **verbatim**. The whole round-trip rides the heavy engine, reached through one `await loadAnimationEngine()`.
|
|
315
326
|
|
|
316
327
|
### Ingest — read the live web's CSS
|
|
317
328
|
|
|
318
|
-
Walk the document's stylesheets into kf objects, or take over a CSS animation
|
|
329
|
+
Walk the document's stylesheets into kf objects, or take over a CSS animation _mid-flight_. Every entry point returns a **diagnostics** channel — a cross-origin sheet whose `cssRules` throws becomes a `CORS_SKIP` row, never a silent drop.
|
|
319
330
|
|
|
320
331
|
```ts
|
|
321
332
|
const { fromStyleSheets, fromLiveAnimations, adoptRunning } =
|
|
@@ -348,8 +359,13 @@ const { animation } = await adoptRunning(element, { animationName: "spin" });
|
|
|
348
359
|
The CSS `animation-timeline` / `animation-range` grammar, round-tripped through value.js's typed extractor, and driven by a JS `ScrollScene` where the platform's native scroll-driven timelines aren't available. value.js owns the scroll **values** (the grammar, parsed verbatim — `scroll(root block)`, `entry 0%`, `cover 100%`); the kf `ScrollScene` owns **time** (resolving the live scroller against the DOM).
|
|
349
360
|
|
|
350
361
|
```ts
|
|
351
|
-
const {
|
|
352
|
-
|
|
362
|
+
const {
|
|
363
|
+
parseScrollCSS,
|
|
364
|
+
roundTripScrollCSS,
|
|
365
|
+
createScrollScene,
|
|
366
|
+
driveScrollCSS,
|
|
367
|
+
pinCSS,
|
|
368
|
+
} = await loadAnimationEngine();
|
|
353
369
|
|
|
354
370
|
// PARSE the author grammar into typed options — verbatim, no DOM resolution:
|
|
355
371
|
const opts = parseScrollCSS(`
|
|
@@ -372,7 +388,7 @@ const driven = driveScrollCSS(opts, element, { scrub: 0.2 });
|
|
|
372
388
|
driven.backend; // "native" or "js"
|
|
373
389
|
|
|
374
390
|
// pinCSS — synthesize the position:sticky pin a scroll-pinned scene needs:
|
|
375
|
-
pinCSS();
|
|
391
|
+
pinCSS(); // => "position: sticky; top: 0px;"
|
|
376
392
|
pinCSS({ top: 24 }); // => "position: sticky; top: 24px;"
|
|
377
393
|
```
|
|
378
394
|
|
|
@@ -386,7 +402,9 @@ pinCSS({ top: 24 }); // => "position: sticky; top: 24px;"
|
|
|
386
402
|
const { CSSKeyframesAnimation, compileToCSS } = await loadAnimationEngine();
|
|
387
403
|
|
|
388
404
|
const fade = new CSSKeyframesAnimation({ duration: 600 })
|
|
389
|
-
.fromString(
|
|
405
|
+
.fromString(
|
|
406
|
+
`from { background-color: #c462d8; } to { background-color: #e85252; }`,
|
|
407
|
+
)
|
|
390
408
|
.setTargets(element);
|
|
391
409
|
|
|
392
410
|
const { css, eligible, refusals } = await compileToCSS([fade]);
|
|
@@ -405,14 +423,14 @@ const { css, eligible, refusals } = await compileToCSS([fade]);
|
|
|
405
423
|
|
|
406
424
|
**The honest-refusal surface (the trust seam).** What cannot round-trip faithfully is **refused** with a named reason — never silently approximated. `compileToCSS` returns `{ css, eligible, refusals }`; when `eligible` is `false`, `refusals` names each child and why, and the JS playback is the only faithful path for those:
|
|
407
425
|
|
|
408
|
-
| Refusal reason
|
|
409
|
-
|
|
410
|
-
| `
|
|
411
|
-
| `custom-renderer`
|
|
412
|
-
| `perceptual-oklab`
|
|
413
|
-
| `computed-unit-drift` | the narrow case where verbatim emit would drift | JS playback
|
|
426
|
+
| Refusal reason | What it proves | The faithful path |
|
|
427
|
+
| --------------------- | ----------------------------------------------- | ---------------------------------- |
|
|
428
|
+
| `weight-blend` | no `animation-composition` twin exists | JS `AnimationGroup` |
|
|
429
|
+
| `custom-renderer` | a closure cannot be CSS | JS playback |
|
|
430
|
+
| `perceptual-oklab` | the oklab densify exceeds the ΔE band | JS playback (true perceptual lerp) |
|
|
431
|
+
| `computed-unit-drift` | the narrow case where verbatim emit would drift | JS playback |
|
|
414
432
|
|
|
415
|
-
A refusal is **marketing for the moat**: it names exactly the kf axis (weighted blending, perceptual color) that exceeds pure CSS. `compileToCSS(input, options?)` options: `staggerDelays` (the materialized `stagger.delays(total)`, emitted as literal per-child `animation-delay`), `densifyStops` (the oklab stop count), `deltaEEpsilon` (the ship-vs-refuse threshold)
|
|
433
|
+
A refusal is **marketing for the moat**: it names exactly the kf axis (weighted blending, perceptual color) that exceeds pure CSS. `compileToCSS(input, options?)` options: `staggerDelays` (the materialized `stagger.delays(total)`, emitted as literal per-child `animation-delay`), `densifyStops` (the oklab stop count), `deltaEEpsilon` (the ship-vs-refuse threshold).
|
|
416
434
|
|
|
417
435
|
> The snippets in this section are reached through `loadAnimationEngine()` and run against the built `dist/`; the executable examples are covered by the test suite.
|
|
418
436
|
|
|
@@ -428,15 +446,15 @@ A spring keyframed across **multiple** declared stops is compositor-eligible too
|
|
|
428
446
|
|
|
429
447
|
keyframes.js targets a modern-web Baseline and documents the tier of every platform facility it leans on:
|
|
430
448
|
|
|
431
|
-
| Facility
|
|
432
|
-
|
|
433
|
-
| `prefers-reduced-motion`
|
|
434
|
-
| `scheduler.yield()`
|
|
435
|
-
| WAAPI `linear()` springs
|
|
436
|
-
| `Element.animate()` (WAAPI) | Widely available
|
|
437
|
-
| CSS `if()` / `@function`
|
|
449
|
+
| Facility | Baseline tier | Behavior |
|
|
450
|
+
| --------------------------- | ------------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
451
|
+
| `prefers-reduced-motion` | Widely available | Native `matchMedia`; SSR-safe no-op off-DOM |
|
|
452
|
+
| `scheduler.yield()` | Newly available | Feature-detected; falls back to a `MessageChannel` macrotask (≤20 LOC) |
|
|
453
|
+
| WAAPI `linear()` springs | Newly available | Feature-detected; the rAF spring path is the default fallback |
|
|
454
|
+
| `Element.animate()` (WAAPI) | Widely available | Opt-out via `useWAAPI: false` |
|
|
455
|
+
| CSS `if()` / `@function` | Limited availability (Chromium) | kf resolves both in JS at parse/bind time — see [The emerging-CSS resolver](#the-emerging-css-resolver) |
|
|
438
456
|
|
|
439
|
-
**Tree-shaking — the
|
|
457
|
+
**Tree-shaking — the Value boundary.** The package is `"sideEffects": false` and splits along a static/dynamic boundary. The light physics/interpolation engines — `SpringProgress`, `SmoothProgress`, `NumericAnimation`, `ElementMorph`, the `Timeline` family, `RAFPlayback`, and the spring-stop helpers — share only the rootless `@mkbabb/value.js/math` leaf. They do not pull Value's CSS parser, color system, or Keyframes' heavy engine into the eager graph. The heavy engine (`KeyframesAnimation`, `CSSKeyframesAnimation`, `AnimationGroup`) is reached through `loadAnimationEngine()`'s dynamic `import()` or the explicit `./engine` entry.
|
|
440
458
|
|
|
441
459
|
**Reduced motion.** Both the light and heavy engines honor `prefers-reduced-motion: reduce`. Opt in per surface:
|
|
442
460
|
|
|
@@ -452,9 +470,9 @@ Off-DOM (SSR / Node) the check is a no-op and animations proceed normally.
|
|
|
452
470
|
|
|
453
471
|
The library also ships general-purpose interpolation primitives, decoupled from CSS and the DOM. These compose into a pipeline: `timeline → progress → interpolator → values → apply`.
|
|
454
472
|
|
|
455
|
-
Everything in this section lives on the **light static barrel** — `import { NumericAnimation, SpringProgress, … } from "@mkbabb/keyframes.js"` — and carries
|
|
473
|
+
Everything in this section lives on the **light static barrel** — `import { NumericAnimation, SpringProgress, … } from "@mkbabb/keyframes.js"` — and carries only Value's rootless `/math` leaf, never its parser/color graph (see [tree-shaking](#baseline-tree-shaking--reduced-motion)). Two conventions hold throughout:
|
|
456
474
|
|
|
457
|
-
- **Easing is callable.** Every light primitive takes a `TimingFunction` (`t => t'`) or a typed `Easing` — `toEasing` normalizes a bare callable to the typed shape, synchronously. A string easing
|
|
475
|
+
- **Easing is callable.** Every light primitive takes a `TimingFunction` (`t => t'`) or a typed `Easing` — `toEasing` normalizes a bare callable to the typed shape, synchronously. A string easing _name_ throws an `UnknownEasingError` — resolve it once, up front: `const easing = await resolveEasing("easeOutCubic")`.
|
|
458
476
|
- **Every snippet executes.** Each example below runs against the built package in CI; `// =>` comments are asserted results, not aspirations.
|
|
459
477
|
|
|
460
478
|
### `NumericAnimation`
|
|
@@ -492,7 +510,7 @@ Exponential smoothing for progress values. Frame-rate independent via `tickDt(dt
|
|
|
492
510
|
const smooth = new SmoothProgress({ damping: 0.15 });
|
|
493
511
|
smooth.setTarget(1);
|
|
494
512
|
smooth.tickDt(16.7); // one frame step — asymptotically approaches the target
|
|
495
|
-
smooth.snap();
|
|
513
|
+
smooth.snap(); // instantly converge
|
|
496
514
|
smooth.current; // => 1
|
|
497
515
|
|
|
498
516
|
// Managed — the smoother owns a rAF loop until it settles:
|
|
@@ -515,7 +533,10 @@ morph.apply(element, 0.5); // writes transform + transformOrigin at progress 0.5
|
|
|
515
533
|
// Managed playback — feed it a spring for the canonical overshoot
|
|
516
534
|
const springy = new ElementMorph(sourceEl, targetEl, {
|
|
517
535
|
duration: 250,
|
|
518
|
-
timingFunction: springTimingFunction({
|
|
536
|
+
timingFunction: springTimingFunction({
|
|
537
|
+
response: 0.4,
|
|
538
|
+
dampingFraction: 0.7,
|
|
539
|
+
}),
|
|
519
540
|
});
|
|
520
541
|
await springy.play(element);
|
|
521
542
|
```
|
|
@@ -549,6 +570,7 @@ manual.tick(); // => 0.25
|
|
|
549
570
|
Options: `easing` (callable or `Easing`), `smoothing` (`SmoothProgressOptions` or `false`), `boundaryEpsilon` (snap eased values within this distance of 0/1 to the boundary — prevents scroll-endpoint oscillation, default 0.005).
|
|
550
571
|
|
|
551
572
|
Subclasses:
|
|
573
|
+
|
|
552
574
|
- **`KeyframesScrollTimeline`** — scroll position → progress. `threshold` sets viewport fraction for full progress (default 0.35). Injectable `getScrollY`/`getViewportHeight`.
|
|
553
575
|
- **`ManualTimeline`** — externally set value → progress. Smoothing off by default.
|
|
554
576
|
|
|
@@ -562,7 +584,7 @@ A live-target spring tracker — the physics core under [`drag`](#drag--draggabl
|
|
|
562
584
|
|
|
563
585
|
```ts run
|
|
564
586
|
const spring = new SpringProgress({ response: 0.5, dampingFraction: 0.86 });
|
|
565
|
-
spring.target = 1;
|
|
587
|
+
spring.target = 1; // re-seat the closed form — continuous, no jump
|
|
566
588
|
spring.tickDt(16.7); // advance one frame (milliseconds); returns the new value
|
|
567
589
|
spring.settled; // => false
|
|
568
590
|
|
|
@@ -575,7 +597,10 @@ spring.target = 0.5;
|
|
|
575
597
|
spring.stop();
|
|
576
598
|
|
|
577
599
|
// The time-based surface (Motion's idiom): perceptual duration + bounce
|
|
578
|
-
const bouncy = SpringProgress.fromDuration({
|
|
600
|
+
const bouncy = SpringProgress.fromDuration({
|
|
601
|
+
visualDuration: 0.4,
|
|
602
|
+
bounce: 0.3,
|
|
603
|
+
});
|
|
579
604
|
bouncy.settled; // => true
|
|
580
605
|
```
|
|
581
606
|
|
|
@@ -643,7 +668,10 @@ delay.delays(5); // => [100, 50, 0, 50, 100]
|
|
|
643
668
|
delay(0, 5); // => 100
|
|
644
669
|
|
|
645
670
|
// Reshape the distribution with an easing (resolved up front):
|
|
646
|
-
const eased = stagger(4, {
|
|
671
|
+
const eased = stagger(4, {
|
|
672
|
+
each: 100,
|
|
673
|
+
ease: await resolveEasing("easeOutCubic"),
|
|
674
|
+
});
|
|
647
675
|
eased(3, 4); // => 300
|
|
648
676
|
```
|
|
649
677
|
|
|
@@ -660,11 +688,23 @@ await flip(card, () => card.classList.toggle("expanded"), { duration: 200 });
|
|
|
660
688
|
// Shared-element FLIP — animate `a` onto `b`'s rect; springs welcome:
|
|
661
689
|
await flipShared(a, b, {
|
|
662
690
|
duration: 200,
|
|
663
|
-
timingFunction: springTimingFunction({
|
|
691
|
+
timingFunction: springTimingFunction({
|
|
692
|
+
response: 0.3,
|
|
693
|
+
dampingFraction: 0.8,
|
|
694
|
+
}),
|
|
664
695
|
});
|
|
665
696
|
```
|
|
666
697
|
|
|
667
|
-
Options: `duration` (default 300), `timingFunction` (callable or `Easing` — `springTimingFunction(…)` makes the FLIP springy), `transformOrigin` (default `"top left"`). Both return the play promise
|
|
698
|
+
Options: `duration` (default 300), `timingFunction` (callable or `Easing` — `springTimingFunction(…)` makes the FLIP springy), `transformOrigin` (default `"top left"`). Both return a `FlipHandle`: the play promise, extended with `cancel()`.
|
|
699
|
+
|
|
700
|
+
**Interruptible.** `handle.cancel()` halts the play at its current frame (the element keeps that frame's transform) and settles the promise. Calling `flip` (or `flipShared`) again on an element whose play is still running is a **re-target**: First is the element's current interpolated rect (its live visual box), the running play is halted and its handle settles, and the new play glides on from that frame — no snap back to the stale First, no waiting out the old duration.
|
|
701
|
+
|
|
702
|
+
```ts
|
|
703
|
+
let resort = flip(list, () => sortBy(list, "date"), { duration: 680 });
|
|
704
|
+
// A second click mid-flight glides on from where the list is right now:
|
|
705
|
+
resort = flip(list, () => sortBy(list, "attendance"), { duration: 680 });
|
|
706
|
+
resort.cancel(); // or stop it where it stands
|
|
707
|
+
```
|
|
668
708
|
|
|
669
709
|
### `drag` / `Draggable`
|
|
670
710
|
|
|
@@ -713,16 +753,18 @@ const fade = new CSSKeyframesAnimation({ duration: 300 })
|
|
|
713
753
|
.fromString(`from { opacity: 0; } to { opacity: 1; }`)
|
|
714
754
|
.setTargets(box);
|
|
715
755
|
const slide = new CSSKeyframesAnimation({ duration: 400 })
|
|
716
|
-
.fromString(
|
|
756
|
+
.fromString(
|
|
757
|
+
`from { transform: translateX(-100px); } to { transform: translateX(0); }`,
|
|
758
|
+
)
|
|
717
759
|
.setTargets(card);
|
|
718
760
|
|
|
719
761
|
const seq = new Sequence()
|
|
720
|
-
.add(fade)
|
|
762
|
+
.add(fade) // auto-append at 0
|
|
721
763
|
.add(slide, "-=100"); // overlap the previous segment by 100ms
|
|
722
764
|
|
|
723
765
|
seq.duration; // => 600
|
|
724
|
-
seq.seek(300);
|
|
725
|
-
await seq.play();
|
|
766
|
+
seq.seek(300); // scrub — master playhead → each child's local clock
|
|
767
|
+
await seq.play(); // the rAF transport drives the SAME map: play ≡ seek
|
|
726
768
|
seq.timeScale(2).repeat(2).yoyo(); // transport persists across plays
|
|
727
769
|
```
|
|
728
770
|
|
|
@@ -730,11 +772,11 @@ Positions: a number (absolute ms), `"+=n"` / `"-=n"` (relative to the insertion
|
|
|
730
772
|
|
|
731
773
|
**Web Animations Level 2, in production.** `AnimationGroup` and `Sequence` are the production realization of WAAPI Level 2's `GroupEffect`/`SequenceEffect` model — grouping semantics no browser has ever shipped (polyfill-only, still a Working Draft, with `SequenceEffect` proposed for deletion upstream — [csswg-drafts#9557](https://github.com/w3c/csswg-drafts/issues/9557)) — running over real WAAPI children where eligible, with weighted blending and a transport the spec lacks. The correspondence is named, not mimicked: keyframes.js does not mirror the unsettled L2 class shapes, polyfill the missing native API, or pin its surface to class names the CSSWG is actively reworking.
|
|
732
774
|
|
|
733
|
-
| Web Animations Level 2 concept
|
|
734
|
-
|
|
|
735
|
-
| `GroupEffect` (parallel children)
|
|
736
|
-
| `SequenceEffect` / proposed `EffectTiming` `align: sequence` | `Sequence` auto-append
|
|
737
|
-
| `EffectTiming` `align: start`
|
|
775
|
+
| Web Animations Level 2 concept | keyframes.js surface |
|
|
776
|
+
| ------------------------------------------------------------ | ----------------------------------- |
|
|
777
|
+
| `GroupEffect` (parallel children) | [`AnimationGroup`](#animationgroup) |
|
|
778
|
+
| `SequenceEffect` / proposed `EffectTiming` `align: sequence` | `Sequence` auto-append |
|
|
779
|
+
| `EffectTiming` `align: start` | `Sequence` `at: 0` |
|
|
738
780
|
|
|
739
781
|
### `viewTransition`
|
|
740
782
|
|
|
@@ -743,7 +785,9 @@ The LIGHT View-Transitions dispatch: mutate the DOM behind a native View Transit
|
|
|
743
785
|
```ts run
|
|
744
786
|
// Off-platform (no `document.startViewTransition`, no shared pairs) it degrades
|
|
745
787
|
// to a bare immediate mutation — backend queryable SYNCHRONOUSLY at dispatch:
|
|
746
|
-
const vt = viewTransition(() => box.classList.add("open"), {
|
|
788
|
+
const vt = viewTransition(() => box.classList.add("open"), {
|
|
789
|
+
types: ["forward"],
|
|
790
|
+
});
|
|
747
791
|
vt.backend; // => "immediate"
|
|
748
792
|
await vt.finished; // never rejects — a skipped/aborted transition settles cleanly
|
|
749
793
|
```
|
|
@@ -755,14 +799,22 @@ Options: `types` (typed same-doc VT), `shared` (`[from, to]` `flipShared` fallba
|
|
|
755
799
|
The round-trip engine pointed at native View Transitions: compile a **name-keyed role spec** to a PURE, ZERO-RUNTIME CSS artifact over the `::view-transition-*` pseudo tree (HEAVY — reached via `loadAnimationEngine()`). Each name's `old`/`new` get a full kf `@keyframes` block + `animation` shorthand (springs → `linear()`); `::view-transition-group(name)` gets a **timing-only** override (duration + timing-function, never `animation-name` — the UA's rect-morph keyframes ARE the free zero-runtime FLIP), so the group stays temporally coherent with the tracks. Non-round-trippable shapes REFUSE with a named reason (the CC-3 four ∪ `vt-scroll-grammar` / `vt-element-scoped-computed` / `vt-snapshot-inapplicable` / `vt-name-collision`).
|
|
756
800
|
|
|
757
801
|
```ts run
|
|
758
|
-
const { CSSKeyframesAnimation, compileToViewTransition } =
|
|
802
|
+
const { CSSKeyframesAnimation, compileToViewTransition } =
|
|
803
|
+
await loadAnimationEngine();
|
|
759
804
|
|
|
760
805
|
const out = new CSSKeyframesAnimation({ duration: 300 });
|
|
761
|
-
out.fromString(
|
|
806
|
+
out.fromString(
|
|
807
|
+
`@keyframes o { from { opacity: 1 } to { opacity: 0; transform: scale(0.9) } }`,
|
|
808
|
+
);
|
|
762
809
|
const enter = new CSSKeyframesAnimation({ duration: 300 });
|
|
763
|
-
enter.fromString(
|
|
764
|
-
|
|
765
|
-
|
|
810
|
+
enter.fromString(
|
|
811
|
+
`@keyframes n { from { opacity: 0; transform: scale(1.05) } to { opacity: 1 } }`,
|
|
812
|
+
);
|
|
813
|
+
|
|
814
|
+
const vt = await compileToViewTransition(
|
|
815
|
+
{ hero: { old: out, new: enter } },
|
|
816
|
+
{ types: ["forward"] },
|
|
817
|
+
);
|
|
766
818
|
vt.names; // => ["hero"]
|
|
767
819
|
vt.css.includes("::view-transition-group(hero)"); // => true
|
|
768
820
|
vt.css.includes("animation-name"); // => false // the group override is timing-only
|
|
@@ -778,15 +830,20 @@ Modern entry/exit compilation: compile a selector-keyed `{ enter?, exit? }` spec
|
|
|
778
830
|
const { CSSKeyframesAnimation, compileToEntry } = await loadAnimationEngine();
|
|
779
831
|
|
|
780
832
|
const enter = new CSSKeyframesAnimation({ duration: 350 });
|
|
781
|
-
enter.fromString(
|
|
782
|
-
|
|
783
|
-
|
|
833
|
+
enter.fromString(
|
|
834
|
+
`@keyframes en { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: translateY(0) } }`,
|
|
835
|
+
);
|
|
836
|
+
|
|
837
|
+
const dialog = await compileToEntry(
|
|
838
|
+
{ ".dialog": { enter } },
|
|
839
|
+
{ openSelector: "[open]" },
|
|
840
|
+
);
|
|
784
841
|
dialog.eligible; // => true
|
|
785
842
|
dialog.css.includes("@starting-style"); // => true
|
|
786
|
-
dialog.css.includes("display
|
|
843
|
+
dialog.css.includes("display 0.35s allow-discrete"); // => true
|
|
787
844
|
```
|
|
788
845
|
|
|
789
|
-
Options: `openSelector` (`".open"` | `"[data-open]"` | `":popover-open"` | `"[open]"`, concatenated onto the base selector), `display` (the open display, default `"block"`), `overlay` (emit `overlay allow-discrete`, default `true`)
|
|
846
|
+
Options: `openSelector` (`".open"` | `"[data-open]"` | `":popover-open"` | `"[open]"`, concatenated onto the base selector), `display` (the open display, default `"block"`), `overlay` (emit `overlay allow-discrete`, default `true`). The `exit` defaults to `enter` reversed. **Born-open elements RUN the entry at first render** (an `@starting-style` platform semantic — an SSR'd open dialog animates in on load; opt out by not matching the open selector at initial render). Where `transition-behavior` is unsupported the artifact **degrades honestly** — snap-entry, correct end state, no broken half-transition.
|
|
790
847
|
|
|
791
848
|
## Ecosystem & agents
|
|
792
849
|
|
|
@@ -816,7 +873,7 @@ make ci-linux # node:24-slim container · npm ci → gh-pages → demo:correc
|
|
|
816
873
|
|
|
817
874
|
It pulls `node:24-slim` (kf's CI Node), mounts the repo at `/workspace`, installs the Playwright browser, builds the demo, and runs the demo gate roster with `KF_REQUIRE_BROWSER=1`, exiting with the container's code. `docker` is the only requirement.
|
|
818
875
|
|
|
819
|
-
**
|
|
876
|
+
**Dependency**: [`@mkbabb/value.js`](https://github.com/mkbabb/value.js), consumed only through its exact `/color`, `/value`, `/css`, `/easing`, `/math`, and `/transform` capability entries.
|
|
820
877
|
|
|
821
878
|
**TypeScript**: `strict: true`, `verbatimModuleSyntax: true`, `target: ES2022`, `moduleResolution: bundler`.
|
|
822
879
|
|
|
@@ -839,5 +896,4 @@ before pushing.
|
|
|
839
896
|
- [CSSOM View Module](https://www.w3.org/TR/cssom-view-1/). W3C. — `getComputedStyle`, unit resolution for relative values.
|
|
840
897
|
- [Web Animations API](https://www.w3.org/TR/web-animations-1/). W3C. — `Element.animate()`; the WAAPI delegation path.
|
|
841
898
|
- [`@mkbabb/value.js`](https://github.com/mkbabb/value.js) — CSS value parsing, color spaces, unit conversion, easing functions.
|
|
842
|
-
-
|
|
843
|
-
- de Casteljau, P. (1959). *Outillages méthodes calcul*. — The recursive subdivision algorithm used for general Bezier curves.
|
|
899
|
+
- de Casteljau, P. (1959). _Outillages méthodes calcul_. — The recursive subdivision algorithm used for general Bezier curves.
|