@mkbabb/keyframes.js 4.2.0 → 4.3.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 -0
- package/dist/{animate-WjeAtXAe.js → animate-D5KoLKwi.js} +2 -2
- package/dist/{animations-WlZvjmDT.js → animations-DaMcGoCd.js} +2 -2
- package/dist/binarySearch-DOP8erk-.js +13 -0
- package/dist/compile-C0xOTIC4.js +249 -0
- package/dist/decay-BvNmFk51.js +25 -0
- package/dist/{draw-svg-Dm9f0vTl.js → draw-svg-CF2cTJj-.js} +1 -1
- package/dist/{engine-Gk4Q7ltr.js → engine-BKm1GcJT.js} +302 -357
- package/dist/ingest-BFBYGTH-.js +139 -0
- package/dist/keyframes.d.ts +984 -6
- package/dist/keyframes.js +82 -236
- package/dist/{motion-path-DQ73oD2j.js → motion-path-CqmlG74k.js} +1 -1
- package/dist/scroll-scene-JpRpH1uU.js +197 -0
- package/dist/sequence-COn8zk5o.js +156 -0
- package/dist/springTimingFunction-CcJEvGwN.js +51 -0
- package/dist/{timeline-CPT7qUV1.js → timeline-BjcmprQ6.js} +173 -39
- package/dist/waapi-Bd5QadtA.js +179 -0
- package/package.json +22 -6
- package/dist/springTimingFunction-DMb11kBe.js +0 -178
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
|
|
@@ -391,6 +396,114 @@ animate(element, presets.fadeIn());
|
|
|
391
396
|
|
|
392
397
|
**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
398
|
|
|
399
|
+
## The round-trip — ingest, drive, compile
|
|
400
|
+
|
|
401
|
+
keyframes.js's authoring object **is** parsed CSS `@keyframes`. That one fact opens a loop no other engine can close:
|
|
402
|
+
|
|
403
|
+
1. **Ingest** — read the live web's CSS (`@keyframes` in a stylesheet, or a *running* CSS animation) straight into a kf `CSSKeyframesAnimation`.
|
|
404
|
+
2. **Drive** — run it through the engine: physics-shaped springs, perceptual `oklab` color, scroll-driven progress, weighted blending.
|
|
405
|
+
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).
|
|
406
|
+
|
|
407
|
+
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()`.
|
|
408
|
+
|
|
409
|
+
### Ingest — read the live web's CSS
|
|
410
|
+
|
|
411
|
+
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.
|
|
412
|
+
|
|
413
|
+
```ts
|
|
414
|
+
const { fromStyleSheets, fromLiveAnimations, adoptRunning } =
|
|
415
|
+
await loadAnimationEngine();
|
|
416
|
+
|
|
417
|
+
// Every @keyframes rule in document.styleSheets, reconstructed and keyed by name.
|
|
418
|
+
// The sibling `.class { animation: spin 2s … }` rule's options are recovered too,
|
|
419
|
+
// so each reconstructed animation carries its AUTHORED timing.
|
|
420
|
+
const { animations, diagnostics } = fromStyleSheets();
|
|
421
|
+
const spin = animations.get("spin")?.animation; // a CSSKeyframesAnimation
|
|
422
|
+
for (const d of diagnostics) console.warn(d.code, d.message); // e.g. CORS_SKIP
|
|
423
|
+
|
|
424
|
+
// Narrow to one name, or pass an explicit source (a sheet / array of sheets):
|
|
425
|
+
fromStyleSheets({ animationName: "spin" });
|
|
426
|
+
fromStyleSheets([...document.styleSheets]);
|
|
427
|
+
|
|
428
|
+
// fromLiveAnimations — the same walk, scoped to a RUNNING element's animations.
|
|
429
|
+
fromLiveAnimations(element);
|
|
430
|
+
|
|
431
|
+
// adoptRunning — the mid-flight TEMPORAL takeover: read the element's running
|
|
432
|
+
// CSS animation via getAnimations(), seed kf at the SAME currentTime (continuity,
|
|
433
|
+
// not seed-at-zero), and hand back the kf object to keep driving.
|
|
434
|
+
const { animation } = await adoptRunning(element, { animationName: "spin" });
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
`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.
|
|
438
|
+
|
|
439
|
+
### Scroll-as-CSS — the animation-timeline grammar
|
|
440
|
+
|
|
441
|
+
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).
|
|
442
|
+
|
|
443
|
+
```ts
|
|
444
|
+
const { parseScrollCSS, roundTripScrollCSS, createScrollScene, pinCSS } =
|
|
445
|
+
await loadAnimationEngine();
|
|
446
|
+
|
|
447
|
+
// PARSE the author grammar into typed options — verbatim, no DOM resolution:
|
|
448
|
+
const opts = parseScrollCSS(`
|
|
449
|
+
.hero { animation-timeline: scroll(root block); animation-range: entry 0% cover 100%; }
|
|
450
|
+
`);
|
|
451
|
+
// opts.timeline => { kind: "scroll", scroller: "root", axis: "block" }
|
|
452
|
+
// opts.range => { start: { phase: "entry", offset: "0%" }, end: { phase: "cover", offset: "100%" } }
|
|
453
|
+
|
|
454
|
+
// roundTripScrollCSS proves the grammar is an inverse pair (parse → serialize):
|
|
455
|
+
roundTripScrollCSS(`.hero { animation-timeline: scroll(root block); }`);
|
|
456
|
+
|
|
457
|
+
// DRIVE it — the JS fallback scene resolves the scroller against the DOM and
|
|
458
|
+
// maps the resolved range onto [0, 1]; feed `.progress` to any interpolator.
|
|
459
|
+
const scene = createScrollScene({ range: opts.range, scrub: 0.2 });
|
|
460
|
+
element.style.opacity = String(scene.progress);
|
|
461
|
+
|
|
462
|
+
// pinCSS — synthesize the position:sticky pin a scroll-pinned scene needs:
|
|
463
|
+
pinCSS(); // => "position: sticky; top: 0px;"
|
|
464
|
+
pinCSS({ top: 24 }); // => "position: sticky; top: 24px;"
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
`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.
|
|
468
|
+
|
|
469
|
+
### Compile — the parser run backward
|
|
470
|
+
|
|
471
|
+
`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**.
|
|
472
|
+
|
|
473
|
+
```ts
|
|
474
|
+
const { CSSKeyframesAnimation, compileToCSS } = await loadAnimationEngine();
|
|
475
|
+
|
|
476
|
+
const fade = new CSSKeyframesAnimation({ duration: 600 })
|
|
477
|
+
.fromString(`from { background-color: #c462d8; } to { background-color: #e85252; }`)
|
|
478
|
+
.setTargets(element);
|
|
479
|
+
|
|
480
|
+
const { css, eligible, refusals } = await compileToCSS([fade]);
|
|
481
|
+
// eligible === true, refusals === []
|
|
482
|
+
// css is a paste-ready @keyframes block. Because the platform interpolates color
|
|
483
|
+
// in sRGB but kf interpolates in perceptual oklab, the compiler DENSIFIES the
|
|
484
|
+
// color track into intermediate oklab() stops, so the browser's piecewise-linear
|
|
485
|
+
// fill TRACKS kf's perceptual lerp — gated on a ΔE proof (ship only if it matches):
|
|
486
|
+
//
|
|
487
|
+
// @keyframes a0 {
|
|
488
|
+
// 0% { background-color: oklab(0.6573 0.1489 -0.1223); }
|
|
489
|
+
// 6.6667% { background-color: oklab(0.6563 0.1503 -0.1091); }
|
|
490
|
+
// …
|
|
491
|
+
// }
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
**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:
|
|
495
|
+
|
|
496
|
+
| Refusal reason | What it proves | The faithful path |
|
|
497
|
+
|---|---|---|
|
|
498
|
+
| `weighted-blend` | no `animation-composition` twin exists | JS `AnimationGroup` |
|
|
499
|
+
| `custom-renderer` | a closure cannot be CSS | JS playback |
|
|
500
|
+
| `perceptual-oklab` | the oklab densify exceeds the ΔE band | JS playback (true perceptual lerp) |
|
|
501
|
+
| `computed-unit-drift` | the narrow case where verbatim emit would drift | JS playback |
|
|
502
|
+
|
|
503
|
+
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`.
|
|
504
|
+
|
|
505
|
+
> 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`.
|
|
506
|
+
|
|
394
507
|
## Web Animations API
|
|
395
508
|
|
|
396
509
|
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 +859,16 @@ Positions: a number (absolute ms), `"+=n"` / `"-=n"` (relative to the insertion
|
|
|
746
859
|
| `SequenceEffect` / proposed `EffectTiming` `align: sequence` | `Sequence` auto-append |
|
|
747
860
|
| `EffectTiming` `align: start` | `Sequence` `at: 0` |
|
|
748
861
|
|
|
862
|
+
## Ecosystem & agents
|
|
863
|
+
|
|
864
|
+
- **[`@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.
|
|
865
|
+
|
|
866
|
+
```sh
|
|
867
|
+
npm i @mkbabb/keyframes-vue @mkbabb/keyframes.js vue
|
|
868
|
+
```
|
|
869
|
+
|
|
870
|
+
- **[`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.
|
|
871
|
+
|
|
749
872
|
## Build & Development
|
|
750
873
|
|
|
751
874
|
```sh
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CSSKeyframesAnimation as e } from "./engine-
|
|
2
|
-
import { fromMotionPath as t } from "./motion-path-
|
|
1
|
+
import { CSSKeyframesAnimation as e } from "./engine-BKm1GcJT.js";
|
|
2
|
+
import { fromMotionPath as t } from "./motion-path-CqmlG74k.js";
|
|
3
3
|
//#region src/animation/animate.ts
|
|
4
4
|
var n = (e) => typeof e == "object" && !!e && !Array.isArray(e) && !(e instanceof Map) && typeof e.path == "string", r = (e) => e instanceof Map || typeof e == "object" && !!e && !Array.isArray(e);
|
|
5
5
|
function i(i, a, o) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as e } from "./springTimingFunction-
|
|
2
|
-
import { CSSKeyframesAnimation as t } from "./engine-
|
|
1
|
+
import { t as e } from "./springTimingFunction-CcJEvGwN.js";
|
|
2
|
+
import { CSSKeyframesAnimation as t } from "./engine-BKm1GcJT.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({
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/animation/internal/binarySearch.ts
|
|
2
|
+
function e(e, t, n, r) {
|
|
3
|
+
let i = 0, a = e.length - 1;
|
|
4
|
+
for (; i <= a;) {
|
|
5
|
+
let o = i + a >> 1, s = e[o];
|
|
6
|
+
if (t < n(s)) a = o - 1;
|
|
7
|
+
else if (t > r(s)) i = o + 1;
|
|
8
|
+
else return o;
|
|
9
|
+
}
|
|
10
|
+
return -1;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { e as t };
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { v as e } from "./timeline-BjcmprQ6.js";
|
|
2
|
+
import { t } from "./sequence-COn8zk5o.js";
|
|
3
|
+
import { AnimationGroup as n, getAnimationId as r } from "./engine-BKm1GcJT.js";
|
|
4
|
+
import { COLOR_SPACE_RANGES as i, camelCaseToHyphen as a, color2 as o, deltaEOK as s, formatCSS as c, normalizeColorUnit as l, reverseAnimationShorthand as u, sampleColorRamp as d, scale as f, timingFunctions as p, unflattenObjectToString as m } from "@mkbabb/value.js";
|
|
5
|
+
//#region src/animation/format.ts
|
|
6
|
+
function h(t) {
|
|
7
|
+
if (t.css !== void 0) return t.css;
|
|
8
|
+
let n = Object.entries(p).find(([e, n]) => n === t.fn)?.[0];
|
|
9
|
+
if (n === void 0) throw new e("timingFunction", t.fn, "a custom TimingFunction has no CSS animation-timing-function representation — attach a faithful Easing.css twin, or use a registry name / cubic-bezier() / linear() literal");
|
|
10
|
+
return a(n);
|
|
11
|
+
}
|
|
12
|
+
function g(e, t, n) {
|
|
13
|
+
let r = e.parsedVars[t] ?? {}, i = Object.entries(m(r)).map(([e, t]) => ` ${a(e)}: ${t};`), o = e.templateFrames[t], s = o.timingFunction ? h(o.timingFunction) : n;
|
|
14
|
+
return s !== n && i.push(` animation-timing-function: ${s};`), `{\n${i.join("\n").trim()}\n}`;
|
|
15
|
+
}
|
|
16
|
+
function _(e, t, n) {
|
|
17
|
+
let r = h(e.options.timingFunction), i = /* @__PURE__ */ new Map();
|
|
18
|
+
e.templateFrames.forEach((t, a) => {
|
|
19
|
+
let o = n?.get(a) ?? g(e, a, r), s = i.get(o);
|
|
20
|
+
s ? s.push(t.start) : i.set(o, [t.start]);
|
|
21
|
+
});
|
|
22
|
+
let a = "";
|
|
23
|
+
for (let [e, t] of i) a += `${t.join(", ")} ${e}\n`;
|
|
24
|
+
return `@keyframes ${t} {\n${a}}`;
|
|
25
|
+
}
|
|
26
|
+
function v(e, t) {
|
|
27
|
+
let n = {
|
|
28
|
+
name: t,
|
|
29
|
+
duration: e.duration,
|
|
30
|
+
timingFunction: h(e.timingFunction),
|
|
31
|
+
iterationCount: isFinite(e.iterationCount) ? e.iterationCount : Infinity,
|
|
32
|
+
direction: e.direction,
|
|
33
|
+
fillMode: e.fillMode
|
|
34
|
+
};
|
|
35
|
+
return e.delay > 0 && (n.delay = e.delay), u(n);
|
|
36
|
+
}
|
|
37
|
+
function y(e) {
|
|
38
|
+
return e === "replace" ? void 0 : `animation-composition: ${e};`;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/animation/compile-color.ts
|
|
42
|
+
var b = i.oklab.a.number.min, x = i.oklab.a.number.max, S = i.oklab.b.number.min, C = i.oklab.b.number.max, w = (e) => Math.round(e * 1e4) / 1e4, T = (e) => typeof e == "object" && !!e && e.unit === "color", E = (e) => l(e).value, D = (e) => {
|
|
43
|
+
let t = o(e, "oklab");
|
|
44
|
+
return [
|
|
45
|
+
t.l,
|
|
46
|
+
f(t.a, 0, 1, b, x),
|
|
47
|
+
f(t.b, 0, 1, S, C)
|
|
48
|
+
];
|
|
49
|
+
}, O = (e) => {
|
|
50
|
+
let [t, n, r] = D(e);
|
|
51
|
+
return `oklab(${w(t)} ${w(n)} ${w(r)})`;
|
|
52
|
+
}, k = (e, t) => {
|
|
53
|
+
let [n, r, i] = D(e), [a, o, c] = D(t);
|
|
54
|
+
return s(n, r, i, a, o, c);
|
|
55
|
+
}, A = (e, t, n) => o({
|
|
56
|
+
colorSpace: "oklab",
|
|
57
|
+
l: e,
|
|
58
|
+
a: f(t, b, x, 0, 1),
|
|
59
|
+
b: f(n, S, C, 0, 1),
|
|
60
|
+
alpha: 1
|
|
61
|
+
}, "oklab"), j = (e, t) => {
|
|
62
|
+
let [n, r, i] = D(e), [a, o, s] = D(t);
|
|
63
|
+
return A((n + a) / 2, (r + o) / 2, (i + s) / 2);
|
|
64
|
+
}, M = (e) => {
|
|
65
|
+
let t = /([\d.]+)\s*%/.exec(e.toString());
|
|
66
|
+
return t ? parseFloat(t[1]) : 0;
|
|
67
|
+
}, N = (e, t, n) => {
|
|
68
|
+
let r = (e.parsedVars[t] ?? {})[n];
|
|
69
|
+
if (Array.isArray(r)) return r.find((e) => T(e));
|
|
70
|
+
};
|
|
71
|
+
function P(e, t, n, r) {
|
|
72
|
+
let i = [], a = /* @__PURE__ */ new Set();
|
|
73
|
+
for (let t = 0; t + 1 < e.templateFrames.length; t++) {
|
|
74
|
+
let n = e.parsedVars[t] ?? {};
|
|
75
|
+
for (let [r, o] of Object.entries(n)) {
|
|
76
|
+
if (a.has(r) || !Array.isArray(o) || !o.some((e) => T(e))) continue;
|
|
77
|
+
let n = N(e, t, r), s = N(e, t + 1, r);
|
|
78
|
+
n && s && n.toString() !== s.toString() && (i.push(r), a.add(r));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (i.length === 0 || i.length > 1) return null;
|
|
82
|
+
let o = i[0], s = Math.max(3, n), c = o.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), l = e.options.colorSpace === "oklch" ? "oklch" : "oklab", u = e.options.hueMethod ? { hueMethod: e.options.hueMethod } : {}, f = [], p = 0;
|
|
83
|
+
for (let t = 0; t + 1 < e.templateFrames.length; t++) {
|
|
84
|
+
let n = N(e, t, o), r = N(e, t + 1, o);
|
|
85
|
+
if (!n || !r) continue;
|
|
86
|
+
let i = M(e.templateFrames[t].start), a = M(e.templateFrames[t + 1].start);
|
|
87
|
+
if (n.toString() === r.toString()) {
|
|
88
|
+
f.push({
|
|
89
|
+
pct: i,
|
|
90
|
+
css: n.toString()
|
|
91
|
+
});
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
let c = E(n), m = E(r), h = d(c, m, s, {
|
|
95
|
+
space: l,
|
|
96
|
+
...u
|
|
97
|
+
});
|
|
98
|
+
for (let e = 0; e < h.length; e++) {
|
|
99
|
+
let t = e / (h.length - 1), n = i + (a - i) * t;
|
|
100
|
+
f.push({
|
|
101
|
+
pct: w(n),
|
|
102
|
+
css: O(h[e])
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
for (let e = 0; e + 1 < h.length; e++) {
|
|
106
|
+
let t = (e + .5) / (h.length - 1), n = d(c, m, 1024, {
|
|
107
|
+
space: l,
|
|
108
|
+
...u
|
|
109
|
+
})[Math.round(t * 1023)], r = j(h[e], h[e + 1]);
|
|
110
|
+
p = Math.max(p, k(r, n));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
let m = e.templateFrames.length - 1, h = N(e, m, o);
|
|
114
|
+
if (h) {
|
|
115
|
+
let t = M(e.templateFrames[m].start);
|
|
116
|
+
f[f.length - 1]?.pct !== t && f.push({
|
|
117
|
+
pct: t,
|
|
118
|
+
css: h.toString()
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (p > r) return {
|
|
122
|
+
refused: !0,
|
|
123
|
+
delta: p
|
|
124
|
+
};
|
|
125
|
+
let g = "";
|
|
126
|
+
for (let { pct: e, css: t } of f) g += `${e}% {\n ${c}: ${t};\n}\n`;
|
|
127
|
+
return { block: `@keyframes ${t} {\n${g}}` };
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/animation/compile.ts
|
|
131
|
+
var F = .04, I = 16;
|
|
132
|
+
function L(e) {
|
|
133
|
+
let t = [];
|
|
134
|
+
for (let n of Object.keys(e.animations)) {
|
|
135
|
+
let i = e.animations[n], a = i.layer.blendMode, o = a === "weighted" || i.layer.weightSpring != null, s = a === "add" ? "add" : "replace";
|
|
136
|
+
t.push({
|
|
137
|
+
animation: i.animation,
|
|
138
|
+
name: B(r(i.animation)),
|
|
139
|
+
composition: s,
|
|
140
|
+
weighted: o,
|
|
141
|
+
delay: 0
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return t;
|
|
145
|
+
}
|
|
146
|
+
function R(e) {
|
|
147
|
+
return e.entries.map((e) => ({
|
|
148
|
+
animation: e.animation,
|
|
149
|
+
name: B(r(e.animation)),
|
|
150
|
+
composition: "replace",
|
|
151
|
+
weighted: !1,
|
|
152
|
+
delay: e.at
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
function z(e) {
|
|
156
|
+
return e.map((e, t) => {
|
|
157
|
+
let n = "animation" in e ? e.animation : e;
|
|
158
|
+
return {
|
|
159
|
+
animation: n,
|
|
160
|
+
name: B(r(n) || `anim-${t}`),
|
|
161
|
+
composition: "replace",
|
|
162
|
+
weighted: !1,
|
|
163
|
+
delay: 0
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function B(e) {
|
|
168
|
+
let t = e.replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
169
|
+
return /^[a-zA-Z_]/.test(t) ? t : `a${t}`;
|
|
170
|
+
}
|
|
171
|
+
var V = (e) => e % 1e3 == 0 ? `${e / 1e3}s` : `${e}ms`;
|
|
172
|
+
function H(e) {
|
|
173
|
+
for (let t = 0; t < e.templateFrames.length; t++) {
|
|
174
|
+
let n = e.parsedVars[t] ?? {};
|
|
175
|
+
for (let [e, t] of Object.entries(n)) if (!Array.isArray(t) || t.length === 0) return e;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function U(e, t, n) {
|
|
179
|
+
let { animation: r, name: i } = e;
|
|
180
|
+
if (e.weighted) return n.push({
|
|
181
|
+
name: i,
|
|
182
|
+
reason: "weighted-blend",
|
|
183
|
+
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"
|
|
184
|
+
}), null;
|
|
185
|
+
for (let e of r.frames) if (!r.usesDefaultRenderer(e.transform)) return n.push({
|
|
186
|
+
name: i,
|
|
187
|
+
reason: "custom-renderer",
|
|
188
|
+
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"
|
|
189
|
+
}), null;
|
|
190
|
+
let a = H(r);
|
|
191
|
+
if (a) return n.push({
|
|
192
|
+
name: i,
|
|
193
|
+
reason: "computed-unit-drift",
|
|
194
|
+
message: `computed-unit drift on "${a}" — the declared value cannot be re-emitted as a faithful authored string; the JS playback is the only faithful path`
|
|
195
|
+
}), null;
|
|
196
|
+
let o = P(r, i, t.densifyStops ?? 16, t.deltaEEpsilon ?? .04);
|
|
197
|
+
if (o && "refused" in o) return n.push({
|
|
198
|
+
name: i,
|
|
199
|
+
reason: "perceptual-oklab",
|
|
200
|
+
message: `perceptual oklab color track exceeds the densify ΔE-ε threshold (ΔE ${w(o.delta)} > ${t.deltaEEpsilon ?? .04}) — a faithful pure-CSS twin is not available; the JS playback is the only faithful path`
|
|
201
|
+
}), null;
|
|
202
|
+
let s = o && "block" in o ? o.block : _(r, i), c;
|
|
203
|
+
try {
|
|
204
|
+
c = v(r.options, i);
|
|
205
|
+
} catch {
|
|
206
|
+
return n.push({
|
|
207
|
+
name: i,
|
|
208
|
+
reason: "custom-renderer",
|
|
209
|
+
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"
|
|
210
|
+
}), null;
|
|
211
|
+
}
|
|
212
|
+
let l = y(e.composition), u = l ? `\n ${l}` : "", d = e.delay > 0 ? `\n animation-delay: ${V(e.delay)};` : "";
|
|
213
|
+
return `${s}\n\n${`.${i} {\n animation: ${c};${u}${d}\n}`}`;
|
|
214
|
+
}
|
|
215
|
+
async function W(e, r = {}) {
|
|
216
|
+
let i = e instanceof n ? L(e) : e instanceof t ? R(e) : z(e), a = /* @__PURE__ */ new Map();
|
|
217
|
+
for (let e of i) {
|
|
218
|
+
let t = a.get(e.name) ?? 0;
|
|
219
|
+
a.set(e.name, t + 1), t > 0 && (e.name = `${e.name}-${t + 1}`);
|
|
220
|
+
}
|
|
221
|
+
r.staggerDelays && i.forEach((e, t) => {
|
|
222
|
+
let n = r.staggerDelays[t];
|
|
223
|
+
typeof n == "number" && n > 0 && (e.delay += n);
|
|
224
|
+
});
|
|
225
|
+
let o = [], s = [];
|
|
226
|
+
for (let e of i) {
|
|
227
|
+
let t = U(e, r, o);
|
|
228
|
+
t && s.push(t);
|
|
229
|
+
}
|
|
230
|
+
let l = o.length === 0;
|
|
231
|
+
if (s.length === 0) return {
|
|
232
|
+
css: "",
|
|
233
|
+
eligible: l,
|
|
234
|
+
refusals: o
|
|
235
|
+
};
|
|
236
|
+
let u = s.join("\n\n"), d;
|
|
237
|
+
try {
|
|
238
|
+
d = await c(u, r.printWidth);
|
|
239
|
+
} catch {
|
|
240
|
+
d = u;
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
css: d,
|
|
244
|
+
eligible: l,
|
|
245
|
+
refusals: o
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
249
|
+
export { F as DEFAULT_DELTA_E_EPSILON, I as DEFAULT_DENSIFY_STOPS, W 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 };
|