@mkbabb/keyframes.js 4.2.0 → 4.4.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 CHANGED
@@ -55,6 +55,10 @@ The [demo apps](demo/) exercise this pattern end-to-end — [try them live](http
55
55
  - [Units](#units)
56
56
  - [AnimationGroup](#animationgroup)
57
57
  - [Presets](#presets)
58
+ - [The round-trip — ingest, drive, compile](#the-round-trip--ingest-drive-compile)
59
+ - [Ingest — read the live web's CSS](#ingest--read-the-live-webs-css)
60
+ - [Scroll-as-CSS — the animation-timeline grammar](#scroll-as-css--the-animation-timeline-grammar)
61
+ - [Compile — the parser run backward](#compile--the-parser-run-backward)
58
62
  - [Web Animations API](#web-animations-api)
59
63
  - [Baseline, tree-shaking & reduced motion](#baseline-tree-shaking--reduced-motion)
60
64
  - [Beyond CSS](#beyond-css)
@@ -70,6 +74,7 @@ The [demo apps](demo/) exercise this pattern end-to-end — [try them live](http
70
74
  - [drag / Draggable](#drag--draggable)
71
75
  - [decay / decayRest](#decay--decayrest)
72
76
  - [Sequence](#sequence)
77
+ - [Ecosystem & agents](#ecosystem--agents)
73
78
  - [Build & Development](#build--development)
74
79
 
75
80
  ## Installation
@@ -238,7 +243,7 @@ anim.setTargets(element);
238
243
  await anim.play();
239
244
  ```
240
245
 
241
- The engine surface (`AnimationEngine`): `Animation`, `CSSKeyframesAnimation`, `AnimationGroup`, `getAnimationId`, `getTimingFunction`, `resolveKeyframes`, `animate`, `MotionPath`/`fromMotionPath`, `DrawSVG`/`fromDrawSVG`, `presets`, and the option constants `DIRECTIONS`, `FILL_MODES`, `defaultOptions`, `defaultLayerConfig`. The **type** surface stays on the static barrel — `import type { Animation } from "@mkbabb/keyframes.js"` costs no runtime edge.
246
+ The engine surface (`AnimationEngine`): `Animation`, `CSSKeyframesAnimation`, `AnimationGroup`, `getAnimationId`, `getTimingFunction`, `resolveKeyframes`, `animate`, `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 { Animation } from "@mkbabb/keyframes.js"` costs no runtime edge.
242
247
 
243
248
  ### `animate`
244
249
 
@@ -295,6 +300,23 @@ new DrawSVG(pathEl, { autoPlay: false }); // class form; `.finished` resolves on
295
300
 
296
301
  Options: `from`/`to` (`"0%"`–`"100%"` strings or `0`–`1` numbers; default draw-in `0% → 100%`), `autoPlay`, plus every `AnimationOptions` key. The target must be SVG geometry (`<path>`, `<line>`, `<circle>`, …) exposing `getTotalLength()`.
297
302
 
303
+ ### `MorphSVG`
304
+
305
+ 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).
306
+
307
+ ```ts
308
+ const { fromMorphSVG, MorphSVG } = await loadAnimationEngine();
309
+
310
+ // Morph a triangle into a square over 600ms:
311
+ const morph = new MorphSVG("M0,0 L10,0 L5,10 Z", "M0,0 L10,0 L10,10 L0,10 Z", {
312
+ samples: 64,
313
+ duration: 600,
314
+ });
315
+ const dAtMid = morph.sampleD(0.5); // the interpolated `d` at t = 0.5
316
+ ```
317
+
318
+ Options: `samples` (point count per path; default `64`), plus every `AnimationOptions` key. Both inputs must be non-degenerate path `d` strings (non-zero arc length, ≥ 2 samples) — a degenerate input refuses with a typed `AnimationOptionError`. `MorphSVG.sampleD(t)` reassembles the morphed `d` at any `t`; the per-point coordinates also surface as `--morph-{i}-x`/`--morph-{i}-y` custom properties for direct CSS binding.
319
+
298
320
  ## `CSSKeyframesAnimation`
299
321
 
300
322
  An abstraction over `Animation` that parses CSS `@keyframes` into `TemplateAnimationFrame` objects, then adds them to a base `Animation`.
@@ -391,6 +413,114 @@ animate(element, presets.fadeIn());
391
413
 
392
414
  **Fade**: `fadeIn`, `fadeOut` · **Attention**: `pulse`, `heartbeat`, `glow`, `shake`, `bounce` · **Entrance/Exit**: `flip`, `rotateIn`, `slideIn`, `slideInLeft/Right`, `slideOutLeft/Right`, `blurIn/Out/InOut`, `jumpUp/Down`, `warpLeft/Right` · **Effects**: `hover`, `typewriter`, `typingCursor`, `rainbowText`, `progressBar`, `skeletonLoading`, `spinner`, `parallaxScroll`, `gradientBackground`, `rotateScale`, `accordionExpand`, `notificationBounce`, `textFocusBlur`
393
415
 
416
+ ## The round-trip — ingest, drive, compile
417
+
418
+ keyframes.js's authoring object **is** parsed CSS `@keyframes`. That one fact opens a loop no other engine can close:
419
+
420
+ 1. **Ingest** — read the live web's CSS (`@keyframes` in a stylesheet, or a *running* CSS animation) straight into a kf `CSSKeyframesAnimation`.
421
+ 2. **Drive** — run it through the engine: physics-shaped springs, perceptual `oklab` color, scroll-driven progress, weighted blending.
422
+ 3. **Compile** — emit the result **back** to zero-runtime CSS — `compileToCSS` is the parser run *backward* over the same data model (`format.ts` is `keyframes.ts` in reverse).
423
+
424
+ 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()`.
425
+
426
+ ### Ingest — read the live web's CSS
427
+
428
+ 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.
429
+
430
+ ```ts
431
+ const { fromStyleSheets, fromLiveAnimations, adoptRunning } =
432
+ await loadAnimationEngine();
433
+
434
+ // Every @keyframes rule in document.styleSheets, reconstructed and keyed by name.
435
+ // The sibling `.class { animation: spin 2s … }` rule's options are recovered too,
436
+ // so each reconstructed animation carries its AUTHORED timing.
437
+ const { animations, diagnostics } = fromStyleSheets();
438
+ const spin = animations.get("spin")?.animation; // a CSSKeyframesAnimation
439
+ for (const d of diagnostics) console.warn(d.code, d.message); // e.g. CORS_SKIP
440
+
441
+ // Narrow to one name, or pass an explicit source (a sheet / array of sheets):
442
+ fromStyleSheets({ animationName: "spin" });
443
+ fromStyleSheets([...document.styleSheets]);
444
+
445
+ // fromLiveAnimations — the same walk, scoped to a RUNNING element's animations.
446
+ fromLiveAnimations(element);
447
+
448
+ // adoptRunning — the mid-flight TEMPORAL takeover: read the element's running
449
+ // CSS animation via getAnimations(), seed kf at the SAME currentTime (continuity,
450
+ // not seed-at-zero), and hand back the kf object to keep driving.
451
+ const { animation } = await adoptRunning(element, { animationName: "spin" });
452
+ ```
453
+
454
+ `fromStyleSheets(source?, options?)` and `fromLiveAnimations(element, options?)` return `{ animations: Map<name, { name, animation, diagnostics }>, diagnostics }`. `resolveLiveKeyframes` is the lower-level walk both share. `adoptRunning(el, options)` returns `{ animation, … }` — the reconstructed kf object seeded at the live playhead.
455
+
456
+ ### Scroll-as-CSS — the animation-timeline grammar
457
+
458
+ 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).
459
+
460
+ ```ts
461
+ const { parseScrollCSS, roundTripScrollCSS, createScrollScene, pinCSS } =
462
+ await loadAnimationEngine();
463
+
464
+ // PARSE the author grammar into typed options — verbatim, no DOM resolution:
465
+ const opts = parseScrollCSS(`
466
+ .hero { animation-timeline: scroll(root block); animation-range: entry 0% cover 100%; }
467
+ `);
468
+ // opts.timeline => { kind: "scroll", scroller: "root", axis: "block" }
469
+ // opts.range => { start: { phase: "entry", offset: "0%" }, end: { phase: "cover", offset: "100%" } }
470
+
471
+ // roundTripScrollCSS proves the grammar is an inverse pair (parse → serialize):
472
+ roundTripScrollCSS(`.hero { animation-timeline: scroll(root block); }`);
473
+
474
+ // DRIVE it — the JS fallback scene resolves the scroller against the DOM and
475
+ // maps the resolved range onto [0, 1]; feed `.progress` to any interpolator.
476
+ const scene = createScrollScene({ range: opts.range, scrub: 0.2 });
477
+ element.style.opacity = String(scene.progress);
478
+
479
+ // pinCSS — synthesize the position:sticky pin a scroll-pinned scene needs:
480
+ pinCSS(); // => "position: sticky; top: 0px;"
481
+ pinCSS({ top: 24 }); // => "position: sticky; top: 24px;"
482
+ ```
483
+
484
+ `dispatchScrollBackend` picks the conservative-correct backend (native `ScrollTimeline` where eligible, the JS scene otherwise); `serializeScrollOptions` is the inverse of `parseScrollCSS`. Where the platform ships native scroll-driven timelines, [`createNativeTimeline`](#timeline) is the additive fast lane and this scene is the general fallback.
485
+
486
+ ### Compile — the parser run backward
487
+
488
+ `compileToCSS` walks an orchestration graph — an [`AnimationGroup`](#animationgroup), a [`Sequence`](#sequence), or a bare child list (e.g. a [`stagger`](#stagger)-delayed cohort) — and emits a **pure, zero-runtime CSS** artifact: one `@keyframes` block + an `animation` shorthand per child, `replace`/`add` layering as `animation-composition`, springs as `linear()`, materialized stagger delays, and computed units (`vh`/`cqw`/`calc()`/`var()`) verbatim. A human pastes the result and ships with **zero kf bytes on the page**.
489
+
490
+ ```ts
491
+ const { CSSKeyframesAnimation, compileToCSS } = await loadAnimationEngine();
492
+
493
+ const fade = new CSSKeyframesAnimation({ duration: 600 })
494
+ .fromString(`from { background-color: #c462d8; } to { background-color: #e85252; }`)
495
+ .setTargets(element);
496
+
497
+ const { css, eligible, refusals } = await compileToCSS([fade]);
498
+ // eligible === true, refusals === []
499
+ // css is a paste-ready @keyframes block. Because the platform interpolates color
500
+ // in sRGB but kf interpolates in perceptual oklab, the compiler DENSIFIES the
501
+ // color track into intermediate oklab() stops, so the browser's piecewise-linear
502
+ // fill TRACKS kf's perceptual lerp — gated on a ΔE proof (ship only if it matches):
503
+ //
504
+ // @keyframes a0 {
505
+ // 0% { background-color: oklab(0.6573 0.1489 -0.1223); }
506
+ // 6.6667% { background-color: oklab(0.6563 0.1503 -0.1091); }
507
+ // …
508
+ // }
509
+ ```
510
+
511
+ **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:
512
+
513
+ | Refusal reason | What it proves | The faithful path |
514
+ |---|---|---|
515
+ | `weighted-blend` | no `animation-composition` twin exists | JS `AnimationGroup` |
516
+ | `custom-renderer` | a closure cannot be CSS | JS playback |
517
+ | `perceptual-oklab` | the oklab densify exceeds the ΔE band | JS playback (true perceptual lerp) |
518
+ | `computed-unit-drift` | the narrow case where verbatim emit would drift | JS playback |
519
+
520
+ 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), `printWidth`.
521
+
522
+ > The snippets in this section are reached through `loadAnimationEngine()` and run against the built `dist/` (the `ts run` README examples in §Beyond CSS / §Animation are the CI-asserted set — `npm run proof:readme-runs`); the round-trip surface above is additionally exercised by `proof:ingest-replay`, `proof:scroll-roundtrip`, and `proof:compile-replay`.
523
+
394
524
  ## Web Animations API
395
525
 
396
526
  When `useWAAPI` is `true` (default), eligible animations run on the compositor thread via `Element.animate()`. Eligibility requires: DOM targets, uniform timing function across frames, no computed units, no custom transform function, no color interpolation. Falls back to `requestAnimationFrame` silently.
@@ -746,6 +876,16 @@ Positions: a number (absolute ms), `"+=n"` / `"-=n"` (relative to the insertion
746
876
  | `SequenceEffect` / proposed `EffectTiming` `align: sequence` | `Sequence` auto-append |
747
877
  | `EffectTiming` `align: start` | `Sequence` `at: 0` |
748
878
 
879
+ ## Ecosystem & agents
880
+
881
+ - **[`@mkbabb/keyframes-vue`](packages/keyframes-vue/)** — a thin Vue 3 adapter over this library. Two on-brand primitives: the declarative `<Keyframes :css>` component (the author's CSS `@keyframes` → a scalar-progress slot — the component no other engine can write, because no other engine parses author CSS as its source format) and the `useKfAnimation` composable kernel. `@mkbabb/keyframes.js` and `vue` are **peers** — the core library never carries Vue.
882
+
883
+ ```sh
884
+ npm i @mkbabb/keyframes-vue @mkbabb/keyframes.js vue
885
+ ```
886
+
887
+ - **[`llms.txt`](./llms.txt)** — the agent surface: a machine-readable index of every capability, **generated** from the CI-verified published surface (`docs/published-surface.md`) so it cannot drift from the shipped API. Point an LLM/agent at it for a grounded map of the primitives, the static/dynamic boundary, and the round-trip. `llms-full.txt` carries the expanded form.
888
+
749
889
  ## Build & Development
750
890
 
751
891
  ```sh
@@ -757,6 +897,16 @@ npm run bench # vitest bench
757
897
  npm run proof:readme-runs # execute every runnable README snippet against the built dist/
758
898
  ```
759
899
 
900
+ ### Local CI repro
901
+
902
+ A macOS-pass / Linux-fail CI flake (a render-race, an absolute frame/ms threshold) can be reproduced locally — no push, no 30-minute wait — by running the demo-smoke roster inside the same Linux container the CI runner uses:
903
+
904
+ ```sh
905
+ make ci-linux # node:24-slim container · npm ci → gh-pages → proof:all:demo
906
+ ```
907
+
908
+ 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.
909
+
760
910
  **Dependencies**: [`@mkbabb/value.js`](https://github.com/mkbabb/value.js) (ValueUnit, Color, math, parsing, normalization) and [`@mkbabb/parse-that`](https://github.com/mkbabb/parse-that) (parser combinators).
761
911
 
762
912
  **TypeScript**: `strict: true`, `verbatimModuleSyntax: true`, `target: ES2022`, `moduleResolution: bundler`.
@@ -0,0 +1,26 @@
1
+ import { t as e } from "./sequence-CF5hazqz.js";
2
+ import { AnimationGroup as t, CSSKeyframesAnimation as n } from "./engine-CNHvTgpw.js";
3
+ import { fromMotionPath as r } from "./motion-path-J-RSNmRQ.js";
4
+ //#region src/animation/animate.ts
5
+ var i = (e) => typeof e == "object" && !!e && !Array.isArray(e) && !(e instanceof Map) && typeof e.path == "string", a = (e) => e instanceof Map || typeof e == "object" && !!e && !Array.isArray(e);
6
+ function o(o, s, c) {
7
+ let { transform: l, autoPlay: u = !0, ...d } = c ?? {};
8
+ if (s instanceof t || s instanceof e) {
9
+ let e = Array.isArray(o) ? o : [o];
10
+ return s.setTargets?.(...e), u && s.play(), s;
11
+ }
12
+ if (i(s)) return r(o, {
13
+ ...s,
14
+ ...d,
15
+ autoPlay: u
16
+ });
17
+ let f = new n(d);
18
+ if (typeof s == "string") f.fromString(s, l);
19
+ else if (Array.isArray(s)) f.fromVars(s, l);
20
+ else if (a(s)) f.fromKeyframes(s, l);
21
+ else throw Error("animate(): unrecognized input — pass a CSS @keyframes string, a keyframe map ({ \"0%\": {...} }), a vars array ([from, to]), or a MotionPath spec ({ path }).");
22
+ let p = Array.isArray(o) ? o : [o];
23
+ return f.setTargets(...p), u && f.play(), f;
24
+ }
25
+ //#endregion
26
+ export { o as animate };
@@ -1,5 +1,5 @@
1
- import { t as e } from "./springTimingFunction-DMb11kBe.js";
2
- import { CSSKeyframesAnimation as t } from "./engine-Gk4Q7ltr.js";
1
+ import { t as e } from "./springTimingFunction-CDHZ00JQ.js";
2
+ import { CSSKeyframesAnimation as t } from "./engine-CNHvTgpw.js";
3
3
  import { CSSCubicBezier as n, steppedEase as r } from "@mkbabb/value.js";
4
4
  //#region src/animation/animations.ts
5
5
  var ee = "\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n", i = (e) => new t({
@@ -221,4 +221,4 @@ var ee = "\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n", i =
221
221
  loop: $
222
222
  };
223
223
  //#endregion
224
- export { k as accordionExpand, Q as attentionPresets, b as blurIn, he as blurInOut, x as blurOut, l as bounce, X as enterPresets, Z as exitPresets, i as fadeIn, a as fadeOut, u as flip, g as glow, C as gradientBackground, m as heartbeat, V as hover, U as jumpDown, H as jumpUp, $ as loopPresets, j as notificationBounce, P as parallaxScroll, Ne as presetTaxonomy, _e as progressBar, o as pulse, _ as rainbowText, d as rotateIn, T as rotateScale, s as shake, S as skeletonLoading, f as slideIn, I as slideInLeft, F as slideInLeftKeyframes, z as slideInRight, R as slideInRightKeyframes, L as slideOutLeft, B as slideOutRight, N as spinner, q as springPop, G as springScaleIn, K as springSlideIn, Y as springWobble, be as textFocusBlur, ce as typewriter, D as typingCursor, v as warpLeft, y as warpRight };
224
+ export { k as accordionExpand, Q as attentionPresets, b as blurIn, he as blurInOut, x as blurOut, l as bounce, X as enterPresets, Z as exitPresets, i as fadeIn, a as fadeOut, u as flipPreset, g as glow, C as gradientBackground, m as heartbeat, V as hover, U as jumpDown, H as jumpUp, $ as loopPresets, j as notificationBounce, P as parallaxScroll, Ne as presetTaxonomy, _e as progressBar, o as pulse, _ as rainbowText, d as rotateIn, T as rotateScale, s as shake, S as skeletonLoading, f as slideIn, I as slideInLeft, F as slideInLeftKeyframes, z as slideInRight, R as slideInRightKeyframes, L as slideOutLeft, B as slideOutRight, N as spinner, q as springPop, G as springScaleIn, K as springSlideIn, Y as springWobble, be as textFocusBlur, ce as typewriter, D as typingCursor, v as warpLeft, y as warpRight };
@@ -0,0 +1,251 @@
1
+ import { t as e } from "./sequence-CF5hazqz.js";
2
+ import { AnimationGroup as t, getAnimationId as n } from "./engine-CNHvTgpw.js";
3
+ import { a as r, i, n as a, t as o } from "./format-BUgCTjmr.js";
4
+ import { a as s } from "./scroll-grammar-B4kPvGh5.js";
5
+ import { COLOR_SPACE_RANGES as c, color2 as l, deltaEOK as u, formatCSS as d, normalizeColorUnit as f, reverseCSSTime as p, sampleColorRamp as m, scale as h } from "@mkbabb/value.js";
6
+ //#region src/animation/compile-color.ts
7
+ var g = c.oklab.a.number.min, _ = c.oklab.a.number.max, v = c.oklab.b.number.min, y = c.oklab.b.number.max, b = (e) => Math.round(e * 1e4) / 1e4, x = (e) => typeof e == "object" && !!e && e.unit === "color", S = (e) => f(e).value, C = (e) => {
8
+ let t = l(e, "oklab");
9
+ return [
10
+ t.l,
11
+ h(t.a, 0, 1, g, _),
12
+ h(t.b, 0, 1, v, y)
13
+ ];
14
+ }, w = (e) => {
15
+ let [t, n, r] = C(e);
16
+ return `oklab(${b(t)} ${b(n)} ${b(r)})`;
17
+ }, T = (e, t) => {
18
+ let [n, r, i] = C(e), [a, o, s] = C(t);
19
+ return u(n, r, i, a, o, s);
20
+ }, E = (e, t, n) => l({
21
+ colorSpace: "oklab",
22
+ l: e,
23
+ a: h(t, g, _, 0, 1),
24
+ b: h(n, v, y, 0, 1),
25
+ alpha: 1
26
+ }, "oklab"), D = (e, t) => {
27
+ let [n, r, i] = C(e), [a, o, s] = C(t);
28
+ return E((n + a) / 2, (r + o) / 2, (i + s) / 2);
29
+ }, O = (e) => {
30
+ let t = /([\d.]+)\s*%/.exec(e.toString());
31
+ return t ? parseFloat(t[1]) : 0;
32
+ }, k = (e, t, n) => {
33
+ let r = (e.parsedVars[t] ?? {})[n];
34
+ if (Array.isArray(r)) return r.find((e) => x(e));
35
+ };
36
+ function A(e, t, n, r, i) {
37
+ let a = t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), o = [], s = 0;
38
+ for (let a = 0; a + 1 < e.templateFrames.length; a++) {
39
+ let c = k(e, a, t), l = k(e, a + 1, t);
40
+ if (!c || !l) continue;
41
+ let u = O(e.templateFrames[a].start), d = O(e.templateFrames[a + 1].start);
42
+ if (c.toString() === l.toString()) {
43
+ o.push({
44
+ pct: u,
45
+ css: c.toString()
46
+ });
47
+ continue;
48
+ }
49
+ let f = S(c), p = S(l), h = m(f, p, n, {
50
+ space: r,
51
+ ...i
52
+ });
53
+ for (let e = 0; e < h.length; e++) {
54
+ let t = e / (h.length - 1), n = u + (d - u) * t;
55
+ o.push({
56
+ pct: b(n),
57
+ css: w(h[e])
58
+ });
59
+ }
60
+ for (let e = 0; e + 1 < h.length; e++) {
61
+ let t = (e + .5) / (h.length - 1), n = m(f, p, 1024, {
62
+ space: r,
63
+ ...i
64
+ })[Math.round(t * 1023)], a = D(h[e], h[e + 1]);
65
+ s = Math.max(s, T(a, n));
66
+ }
67
+ }
68
+ let c = e.templateFrames.length - 1, l = k(e, c, t);
69
+ if (l) {
70
+ let t = O(e.templateFrames[c].start);
71
+ o[o.length - 1]?.pct !== t && o.push({
72
+ pct: t,
73
+ css: l.toString()
74
+ });
75
+ }
76
+ return {
77
+ cssProp: a,
78
+ stops: o,
79
+ worstDelta: s
80
+ };
81
+ }
82
+ function j(e, t, n, r) {
83
+ let i = [], a = /* @__PURE__ */ new Set();
84
+ for (let t = 0; t + 1 < e.templateFrames.length; t++) {
85
+ let n = e.parsedVars[t] ?? {};
86
+ for (let [r, o] of Object.entries(n)) {
87
+ if (a.has(r) || !Array.isArray(o) || !o.some((e) => x(e))) continue;
88
+ let n = k(e, t, r), s = k(e, t + 1, r);
89
+ n && s && n.toString() !== s.toString() && (i.push(r), a.add(r));
90
+ }
91
+ }
92
+ if (i.length === 0) return null;
93
+ let o = Math.max(3, n), s = e.options.colorSpace === "oklch" ? "oklch" : "oklab", c = e.options.hueMethod ? { hueMethod: e.options.hueMethod } : {}, l = 0, u = /* @__PURE__ */ new Map(), d = [];
94
+ for (let t of i) {
95
+ let n = A(e, t, o, s, c);
96
+ l = Math.max(l, n.worstDelta);
97
+ for (let { pct: e, css: t } of n.stops) {
98
+ let r = u.get(e);
99
+ r || (r = [], u.set(e, r), d.push(e)), r.push(`${n.cssProp}: ${t};`);
100
+ }
101
+ }
102
+ if (l > r) return {
103
+ refused: !0,
104
+ delta: l
105
+ };
106
+ d.sort((e, t) => e - t);
107
+ let f = "";
108
+ for (let e of d) {
109
+ let t = u.get(e);
110
+ f += `${e}% {\n ${t.join("\n ")}\n}\n`;
111
+ }
112
+ return { block: `@keyframes ${t} {\n${f}}` };
113
+ }
114
+ //#endregion
115
+ //#region src/animation/compile.ts
116
+ var M = .04, N = 16;
117
+ function P(e) {
118
+ let t = [];
119
+ for (let r of Object.keys(e.animations)) {
120
+ let i = e.animations[r], a = i.layer.blendMode, o = a === "weighted" && i.layer.weightSpring != null, s = a === "weighted" && i.layer.weightSpring == null, c = a === "add" ? "add" : s ? "accumulate" : "replace";
121
+ t.push({
122
+ animation: i.animation,
123
+ name: L(n(i.animation)),
124
+ composition: c,
125
+ weighted: o,
126
+ ...s ? { staticWeight: i.layer.weight } : {},
127
+ delay: 0
128
+ });
129
+ }
130
+ return t;
131
+ }
132
+ function F(e) {
133
+ return e.entries.map((e) => ({
134
+ animation: e.animation,
135
+ name: L(n(e.animation)),
136
+ composition: "replace",
137
+ weighted: !1,
138
+ delay: e.at
139
+ }));
140
+ }
141
+ function I(e) {
142
+ return e.map((e, t) => {
143
+ let r = "animation" in e ? e.animation : e;
144
+ return {
145
+ animation: r,
146
+ name: L(n(r) || `anim-${t}`),
147
+ composition: "replace",
148
+ weighted: !1,
149
+ delay: 0
150
+ };
151
+ });
152
+ }
153
+ function L(e) {
154
+ let t = e.replace(/[^a-zA-Z0-9_-]/g, "-");
155
+ return /^[a-zA-Z_]/.test(t) ? t : `a${t}`;
156
+ }
157
+ function R(e) {
158
+ for (let t = 0; t < e.templateFrames.length; t++) {
159
+ let n = e.parsedVars[t] ?? {};
160
+ for (let [e, t] of Object.entries(n)) if (!Array.isArray(t) || t.length === 0) return e;
161
+ }
162
+ }
163
+ function z(e, t, n) {
164
+ let { animation: s, name: c } = e;
165
+ if (e.weighted) return n.push({
166
+ name: c,
167
+ reason: "weighted-blend",
168
+ message: "weighted layer blend has no animation-composition equivalent (CSS composites replace/add/accumulate only); the weighted axis is kf's unique blend tier — the JS playback is the only faithful path"
169
+ }), null;
170
+ for (let e of s.frames) if (!s.usesDefaultRenderer(e.transform)) return n.push({
171
+ name: c,
172
+ reason: "custom-renderer",
173
+ message: "custom renderer (a transform closure, not the default DOM-style renderer) cannot be expressed as CSS — the JS playback is the only faithful path"
174
+ }), null;
175
+ let l = R(s);
176
+ if (l) return n.push({
177
+ name: c,
178
+ reason: "computed-unit-drift",
179
+ message: `computed-unit drift on "${l}" — the declared value cannot be re-emitted as a faithful authored string; the JS playback is the only faithful path`
180
+ }), null;
181
+ let u = j(s, c, t.densifyStops ?? 16, t.deltaEEpsilon ?? .04);
182
+ if (u && "refused" in u) return n.push({
183
+ name: c,
184
+ reason: "perceptual-oklab",
185
+ message: `perceptual oklab color track exceeds the densify ΔE-ε threshold (ΔE ${b(u.delta)} > ${t.deltaEEpsilon ?? .04}) — a faithful pure-CSS twin is not available; the JS playback is the only faithful path`
186
+ }), null;
187
+ let d;
188
+ if (e.staticWeight != null) {
189
+ let t = r(s, c, e.staticWeight);
190
+ if ("refused" in t) return n.push({
191
+ name: c,
192
+ reason: "weighted-blend",
193
+ message: `static-weight pre-multiply cannot scale the non-numeric leaf "${t.key}" (a color/string has no scalar weight) — the weighted blend is kf's unique tier; the JS playback is the only faithful path`
194
+ }), null;
195
+ d = t.block;
196
+ }
197
+ let f = d ?? (u && "block" in u ? u.block : i(s, c)), m;
198
+ try {
199
+ m = a(s.options, c);
200
+ } catch {
201
+ return n.push({
202
+ name: c,
203
+ reason: "custom-renderer",
204
+ message: "easing has no faithful CSS timing-function twin (a custom closure cannot be CSS) — attach an Easing.css twin or use a registry name / cubic-bezier() / linear(); the JS playback is the only faithful path"
205
+ }), null;
206
+ }
207
+ let h = o(e.composition), g = h ? `\n ${h}` : "", _ = e.delay > 0 ? `\n animation-delay: ${p(e.delay)};` : "", v = B(s);
208
+ return `${f}\n\n${`.${c} {\n animation: ${m};${g}${_}${v}\n}`}`;
209
+ }
210
+ function B(e) {
211
+ let t = e.scrollOptions;
212
+ if (t == null) return "";
213
+ let n = s(t), r = "";
214
+ for (let [e, t] of Object.entries(n)) t != null && (r += `\n ${e}: ${t};`);
215
+ return r;
216
+ }
217
+ async function V(n, r = {}) {
218
+ let i = n instanceof t ? P(n) : n instanceof e ? F(n) : I(n), a = /* @__PURE__ */ new Map();
219
+ for (let e of i) {
220
+ let t = a.get(e.name) ?? 0;
221
+ a.set(e.name, t + 1), t > 0 && (e.name = `${e.name}-${t + 1}`);
222
+ }
223
+ r.staggerDelays && i.forEach((e, t) => {
224
+ let n = r.staggerDelays[t];
225
+ typeof n == "number" && n > 0 && (e.delay += n);
226
+ });
227
+ let o = [], s = [];
228
+ for (let e of i) {
229
+ let t = z(e, r, o);
230
+ t && s.push(t);
231
+ }
232
+ let c = o.length === 0;
233
+ if (s.length === 0) return {
234
+ css: "",
235
+ eligible: c,
236
+ refusals: o
237
+ };
238
+ let l = s.join("\n\n"), u;
239
+ try {
240
+ u = await d(l, r.printWidth);
241
+ } catch {
242
+ u = l;
243
+ }
244
+ return {
245
+ css: u,
246
+ eligible: c,
247
+ refusals: o
248
+ };
249
+ }
250
+ //#endregion
251
+ export { M as DEFAULT_DELTA_E_EPSILON, N as DEFAULT_DENSIFY_STOPS, V as compileToCSS };
@@ -0,0 +1,25 @@
1
+ //#region src/animation/decay.ts
2
+ var e = 5;
3
+ function t(t) {
4
+ let n = t.initial ?? 0, r = t.velocity, i = t.friction ?? e;
5
+ if (i <= 0) throw Error("decay() requires a friction coefficient > 0.");
6
+ let a = n + r / i;
7
+ return (e) => {
8
+ if (e <= 0) return {
9
+ value: n,
10
+ velocity: r
11
+ };
12
+ let t = Math.exp(-i * e);
13
+ return {
14
+ value: a - r / i * t,
15
+ velocity: r * t
16
+ };
17
+ };
18
+ }
19
+ function n(t) {
20
+ let n = t.friction ?? e;
21
+ if (n <= 0) throw Error("decayRest() requires a friction coefficient > 0.");
22
+ return (t.initial ?? 0) + t.velocity / n;
23
+ }
24
+ //#endregion
25
+ export { n, t };
@@ -1,4 +1,4 @@
1
- import { CSSKeyframesAnimation as e } from "./engine-Gk4Q7ltr.js";
1
+ import { CSSKeyframesAnimation as e } from "./engine-CNHvTgpw.js";
2
2
  //#region src/animation/draw-svg.ts
3
3
  var t = (e) => {
4
4
  if (typeof e == "number") {