@mkbabb/keyframes.js 4.4.0 → 5.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.
Files changed (39) hide show
  1. package/README.md +36 -221
  2. package/dist/animation-BGyzfzBq.js +947 -0
  3. package/dist/compile-CcSUwM8R.js +276 -0
  4. package/dist/{waapi-D9MHMm_9.js → delegation-DWwr4IXr.js} +116 -32
  5. package/dist/{draw-svg-DYRDxBlL.js → draw-svg-GURj9nin.js} +17 -13
  6. package/dist/easing-registry-DHV2-5gA.js +27 -0
  7. package/dist/easing-registry-y1p9McFy.js +2 -0
  8. package/dist/engine/index.d.ts +2873 -0
  9. package/dist/engine/index.js +17 -0
  10. package/dist/engine-DEVgCTUy.js +156 -0
  11. package/dist/engine-DrBtsKaf.js +4 -0
  12. package/dist/{format-BUgCTjmr.js → format-C-Gi9r7L.js} +4 -4
  13. package/dist/{scroll-grammar-B4kPvGh5.js → grammar-BLucehC4.js} +1 -1
  14. package/dist/group-vJcsHKN9.js +360 -0
  15. package/dist/{ingest-CNM5xkQT.js → ingest-S5hUe20K.js} +62 -56
  16. package/dist/keyframes.d.ts +585 -989
  17. package/dist/keyframes.js +188 -129
  18. package/dist/morph-svg-BToeumw5.js +89 -0
  19. package/dist/{motion-path-J-RSNmRQ.js → motion-path-pQVbamWT.js} +16 -12
  20. package/dist/parse-flatten-DRMHFytp.js +2 -0
  21. package/dist/parse-flatten-ZZUSEQEL.js +63 -0
  22. package/dist/{animations-5nf2kBkv.js → presets-BG2Fczzq.js} +124 -73
  23. package/dist/{scheduler-7eIr_q1g.js → scheduler-CUtVnuoU.js} +1 -1
  24. package/dist/{scroll-scene-CXEgM49Q.js → scroll-CxpYFO4u.js} +50 -46
  25. package/dist/sequence-C_DCiOIQ.js +708 -0
  26. package/dist/validate-DDeGnvSt.js +39 -0
  27. package/package.json +45 -6
  28. package/dist/animate-CuUJt2Tb.js +0 -26
  29. package/dist/compile-DgNRG6Lo.js +0 -251
  30. package/dist/decay-BvNmFk51.js +0 -25
  31. package/dist/engine-CNHvTgpw.js +0 -1122
  32. package/dist/errors-W8zkvPw4.js +0 -21
  33. package/dist/morph-svg-DRjl9Hfz.js +0 -62
  34. package/dist/rolldown-runtime-Dy4uBu1J.js +0 -11
  35. package/dist/sequence-CF5hazqz.js +0 -198
  36. package/dist/springTimingFunction-CDHZ00JQ.js +0 -63
  37. package/dist/timeline-B7SV3T_E.js +0 -442
  38. package/dist/utils-D7nuAND5.js +0 -97
  39. package/dist/validate-8r6Yo-uc.js +0 -35
@@ -1,21 +0,0 @@
1
- //#region src/animation/internal/errors.ts
2
- var e = (e) => typeof e == "string" ? JSON.stringify(e) : typeof e == "function" ? `[function ${e.name || "anonymous"}]` : String(e), t = class extends Error {
3
- option;
4
- value;
5
- code;
6
- constructor(t, n, r, i) {
7
- super(`Invalid value for animation option "${t}": ${e(n)} — ${r}`), this.name = "AnimationOptionError", this.option = t, this.value = n, i !== void 0 && (this.code = i);
8
- }
9
- }, n = class extends Error {
10
- easingName;
11
- constructor(t) {
12
- super(`Unknown easing name ${e(t)} — not a value.js registry entry or cubic-bezier() literal. Pass a callable TimingFunction (or a typed Easing), or resolve the name first via \`await resolveEasing(name)\`.`), this.name = "UnknownEasingError", this.easingName = t;
13
- }
14
- };
15
- function r(e, n, r, i) {
16
- let a = r(n);
17
- if (a === void 0) throw new t(e, n, i);
18
- return a;
19
- }
20
- //#endregion
21
- export { n, r, t };
@@ -1,62 +0,0 @@
1
- import { t as e } from "./errors-W8zkvPw4.js";
2
- import { CSSKeyframesAnimation as t } from "./engine-CNHvTgpw.js";
3
- import { PathGeometry as n } from "@mkbabb/value.js";
4
- //#region src/animation/morph-svg.ts
5
- var r = 64, i = (e) => `--morph-${e}-x`, a = (e) => `--morph-${e}-y`, o = (e, t) => {
6
- let n = Array(t + 1);
7
- for (let r = 0; r <= t; r++) n[r] = e.getPointAtT(r / t);
8
- return n;
9
- }, s = (e) => {
10
- if (e.length === 0) return "";
11
- let t = (e) => Number.isInteger(e) ? `${e}` : e.toFixed(3), n = `M ${t(e[0].x)} ${t(e[0].y)}`;
12
- for (let r = 1; r < e.length; r++) n += ` L ${t(e[r].x)} ${t(e[r].y)}`;
13
- return n;
14
- };
15
- function c(s, c, l = {}) {
16
- let { samples: u = r, target: d, autoPlay: f = !0, ...p } = l;
17
- if (typeof s != "string" || s.length === 0) throw new e("from", s, "fromMorphSVG(): `from` must be a non-empty SVG path `d` string.");
18
- if (typeof c != "string" || c.length === 0) throw new e("to", c, "fromMorphSVG(): `to` must be a non-empty SVG path `d` string.");
19
- if (!Number.isInteger(u) || u < 2) throw new e("samples", u, "fromMorphSVG(): `samples` must be an integer >= 2 (a 1-sample morph is just the two endpoints, with no body to interpolate).");
20
- let m = new n(s), h = new n(c);
21
- if (m.totalLength === 0) throw new e("from", s, "fromMorphSVG(): the `from` path has zero arc-length — a morph between a zero-length path and anything is malformed input, not an identity animation.");
22
- if (h.totalLength === 0) throw new e("to", c, "fromMorphSVG(): the `to` path has zero arc-length — a morph between a zero-length path and anything is malformed input, not an identity animation.");
23
- let g = o(m, u), _ = o(h, u), v = {}, y = {};
24
- for (let e = 0; e <= u; e++) v[i(e)] = g[e].x, v[a(e)] = g[e].y, y[i(e)] = _[e].x, y[a(e)] = _[e].y;
25
- let b = {
26
- "0%": v,
27
- "100%": y
28
- }, x = new t(p).fromKeyframes(b);
29
- return d != null && x.setTargets(d), f && x.play(), x;
30
- }
31
- var l = class {
32
- animation;
33
- samples;
34
- constructor(e, t, n = {}) {
35
- this.animation = c(e, t, n), this.samples = n.samples ?? r;
36
- }
37
- sampleD(e) {
38
- let t = (e < 0 ? 0 : e > 1 ? 1 : e) * this.animation.options.duration, n = this.animation.interpFrames(t, !1), r = Array(this.samples + 1);
39
- for (let e = 0; e <= this.samples; e++) {
40
- let t = n[i(e)]?.[0]?.value, o = n[a(e)]?.[0]?.value;
41
- r[e] = {
42
- x: t ?? 0,
43
- y: o ?? 0
44
- };
45
- }
46
- return s(r);
47
- }
48
- play() {
49
- return this.animation.play();
50
- }
51
- pause() {
52
- return this.animation.pause(), this;
53
- }
54
- stop() {
55
- return this.animation.stop(), this;
56
- }
57
- get finished() {
58
- return this.animation.finished;
59
- }
60
- };
61
- //#endregion
62
- export { l as MorphSVG, c as fromMorphSVG };
@@ -1,11 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var e = Object.defineProperty, t = (t, n) => {
3
- let r = {};
4
- for (var i in t) e(r, i, {
5
- get: t[i],
6
- enumerable: !0
7
- });
8
- return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
9
- };
10
- //#endregion
11
- export { t };
@@ -1,198 +0,0 @@
1
- import { f as e, l as t } from "./timeline-B7SV3T_E.js";
2
- //#region src/animation/sequence-events.ts
3
- var n = class {
4
- subscribers = new Map([
5
- ["segment:enter", /* @__PURE__ */ new Set()],
6
- ["segment:leave", /* @__PURE__ */ new Set()],
7
- ["label", /* @__PURE__ */ new Set()]
8
- ]);
9
- _activeSegments = /* @__PURE__ */ new Set();
10
- _prevPhase = void 0;
11
- subscribe(e, t) {
12
- let n = this.subscribers.get(e);
13
- return n.add(t), () => n.delete(t);
14
- }
15
- fire(e, t, n) {
16
- let r = this.subscribers.get("segment:enter"), i = this.subscribers.get("segment:leave"), a = this.subscribers.get("label");
17
- if (r.size === 0 && i.size === 0 && a.size === 0) {
18
- this._prevPhase = n;
19
- return;
20
- }
21
- let o = this._prevPhase;
22
- if (r.size > 0 || i.size > 0) for (let t of e) {
23
- let e = n >= t.at && n < t.at + t.animation.options.duration, a = this._activeSegments.has(t);
24
- if (e && !a) {
25
- this._activeSegments.add(t);
26
- for (let e of r) e(t.animation, n);
27
- } else if (!e && a) {
28
- this._activeSegments.delete(t);
29
- for (let e of i) e(t.animation, n);
30
- }
31
- }
32
- if (a.size > 0 && o !== void 0 && o !== n) {
33
- let e = Math.min(o, n), r = Math.max(o, n);
34
- for (let [i, o] of t) if (o > e && o <= r) for (let e of a) e(i, n);
35
- }
36
- this._prevPhase = n;
37
- }
38
- }, r = class {
39
- entries = [];
40
- labels = /* @__PURE__ */ new Map();
41
- _events = new n();
42
- cursor = 0;
43
- _time = 0;
44
- respectReducedMotion;
45
- playback = new t();
46
- _boundFrame;
47
- _resolvePlay = null;
48
- _playOrigin = void 0;
49
- _playingPromise = null;
50
- _rate = 1;
51
- _repeatCount = 1;
52
- _yoyoOn = !1;
53
- _paused = !1;
54
- _lastClock = void 0;
55
- constructor(e) {
56
- this.respectReducedMotion = e?.respectReducedMotion ?? !1, this._boundFrame = this._frame.bind(this);
57
- }
58
- get duration() {
59
- let e = 0;
60
- for (let t of this.entries) {
61
- let n = t.at + t.animation.options.duration;
62
- n > e && (e = n);
63
- }
64
- return e;
65
- }
66
- get time() {
67
- return this._time;
68
- }
69
- get progress() {
70
- return this.duration === 0 ? 0 : this._time / this.duration;
71
- }
72
- set progress(t) {
73
- this.seek(e(t, 0, 1) * this.duration);
74
- }
75
- get rate() {
76
- return this._rate;
77
- }
78
- label(e, t) {
79
- return this.labels.set(e, this.resolvePosition(t)), this;
80
- }
81
- on(e, t) {
82
- return this._events.subscribe(e, t);
83
- }
84
- add(e, t) {
85
- let n = this.resolvePosition(t);
86
- return this.entries.push({
87
- animation: e,
88
- at: n
89
- }), this.entries.sort((e, t) => e.at - t.at), this.cursor = n + e.options.duration, this;
90
- }
91
- resolvePosition(e) {
92
- if (e === void 0) return this.cursor;
93
- if (typeof e == "number") return e;
94
- let t = /^([+-])=(\d*\.?\d+)$/.exec(e);
95
- if (t) {
96
- let e = t[1] === "+" ? 1 : -1;
97
- return this.cursor + e * Number.parseFloat(t[2]);
98
- }
99
- let n = this.labels.get(e);
100
- if (n === void 0) throw Error(`Sequence: unknown position "${e}". Register it with .label("${e}", at) first, or pass a number / "+=n" / "-=n".`);
101
- return n;
102
- }
103
- seek(e) {
104
- return this._time = e, this._fireCrossings(e), this._applyAt(e), this;
105
- }
106
- _applyAt(t) {
107
- for (let { animation: n, at: r } of this.entries) {
108
- let i = e(t - r, 0, n.options.duration);
109
- n.interpFrames(i, !0);
110
- }
111
- }
112
- _fireCrossings(e) {
113
- this._events.fire(this.entries, this.labels, e);
114
- }
115
- _fold(t) {
116
- let n = this.duration;
117
- if (n <= 0) return 0;
118
- let r = e(t, 0, n * this._repeatCount), i = Math.floor(r / n), a = r - i * n;
119
- return a === 0 && i > 0 && (--i, a = n), this._yoyoOn && i % 2 == 1 ? n - a : a;
120
- }
121
- setTargets(...e) {
122
- for (let { animation: t } of this.entries) t.setTargets(...e);
123
- return this;
124
- }
125
- get finished() {
126
- return this._playingPromise ?? Promise.resolve();
127
- }
128
- play() {
129
- if (this._playingPromise) return this._playingPromise;
130
- if (this.respectReducedMotion && i()) return this.seek(this.duration), Promise.resolve();
131
- for (let { animation: e, at: t } of this.entries) e.startTime = t, e.started = !0, e.managed = !0;
132
- this._time = 0, this._paused = !1, this._playOrigin = void 0, this._lastClock = void 0;
133
- let e = new Promise((e) => {
134
- this._resolvePlay = e, this.playback.loop(this._boundFrame);
135
- });
136
- return this._playingPromise = e, e.finally(() => {
137
- this._playingPromise = null;
138
- }), e;
139
- }
140
- async _frame(e) {
141
- this._playOrigin === void 0 && (this._playOrigin = this._rate === 0 ? e : e - this._time / this._rate), this._lastClock = e;
142
- let t = (e - this._playOrigin) * this._rate, n = this.duration * this._repeatCount, r = this._rate >= 0 ? t >= n : t <= 0, i = r ? this._rate >= 0 ? this._restPhase() : 0 : this._fold(t);
143
- if (this._time = i, this._isForwardMonotone()) for (let { animation: e, at: t } of this.entries) i >= t && i - t < e.options.duration && await e.advanceTo(i);
144
- if (this._fireCrossings(i), this._applyAt(i), r) {
145
- this._settle();
146
- let e = this._resolvePlay;
147
- return this._resolvePlay = null, e?.(), !1;
148
- }
149
- return !0;
150
- }
151
- _isForwardMonotone() {
152
- return this._rate === 1 && this._repeatCount === 1 && !this._yoyoOn;
153
- }
154
- _restPhase() {
155
- let e = this.duration;
156
- return this._yoyoOn && (this._repeatCount - 1) % 2 == 1 ? 0 : e;
157
- }
158
- _reanchor() {
159
- if (!this._playingPromise) return;
160
- let e = this._lastClock;
161
- if (e === void 0) {
162
- this._playOrigin = void 0;
163
- return;
164
- }
165
- this._playOrigin = this._rate === 0 ? e : e - this._time / this._rate;
166
- }
167
- _settle() {
168
- for (let { animation: e } of this.entries) e.managed = !1, e.started = !1, e.startTime = void 0;
169
- this._playOrigin = void 0, this._lastClock = void 0, this._paused = !1;
170
- }
171
- stop() {
172
- this.playback.stop(), this._settle();
173
- let e = this._resolvePlay;
174
- return this._resolvePlay = null, e?.(), this;
175
- }
176
- pause() {
177
- return !this._playingPromise || this._paused ? this : (this._paused = !0, this.playback.stop(), this._playOrigin = void 0, this);
178
- }
179
- resume() {
180
- return !this._playingPromise || !this._paused ? this : (this._paused = !1, this._playOrigin = void 0, this._lastClock = void 0, this.playback.loop(this._boundFrame), this);
181
- }
182
- timeScale(e) {
183
- if (!Number.isFinite(e)) throw Error(`Sequence.timeScale(n): n must be a finite number, got ${e}.`);
184
- return this._rate = e, this._reanchor(), this;
185
- }
186
- reverse() {
187
- return this._rate = -this._rate, this._reanchor(), this;
188
- }
189
- repeat(e) {
190
- if (e !== Infinity && (!Number.isInteger(e) || e < 1)) throw Error(`Sequence.repeat(count): count must be a positive integer or Infinity, got ${e}.`);
191
- return this._repeatCount = e, this;
192
- }
193
- yoyo(e = !0) {
194
- return this._yoyoOn = e, this;
195
- }
196
- }, i = () => typeof matchMedia == "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
197
- //#endregion
198
- export { r as t };
@@ -1,63 +0,0 @@
1
- import { a as e } from "./timeline-B7SV3T_E.js";
2
- //#region src/animation/internal/binarySearch.ts
3
- function t(e, t, n, r) {
4
- let i = 0, a = e.length - 1;
5
- for (; i <= a;) {
6
- let o = i + a >> 1, s = e[o];
7
- if (t < n(s)) a = o - 1;
8
- else if (t > r(s)) i = o + 1;
9
- else return o;
10
- }
11
- return -1;
12
- }
13
- //#endregion
14
- //#region src/animation/springLinearStops.ts
15
- function n(t) {
16
- let n = t.sampleCount ?? 24, r = t.settleThreshold ?? .001, i = t.maxDuration ?? t.response * 4, a = new e({
17
- response: t.response,
18
- dampingFraction: t.dampingFraction,
19
- initial: 0,
20
- settleThreshold: r,
21
- velocitySettleThreshold: r
22
- });
23
- a.target = 1;
24
- let o = ["0"], s = i / (n + 1);
25
- for (let e = 1; e <= n; e++) {
26
- a._stepSeconds(s);
27
- let t = e / (n + 1) * 100, r = a.settled ? 1 : a.value;
28
- o.push(`${r.toFixed(5)} ${t.toFixed(3)}%`);
29
- }
30
- return o.push("1"), a.dispose(), `linear(${o.join(", ")})`;
31
- }
32
- //#endregion
33
- //#region src/animation/springTimingFunction.ts
34
- function r(t) {
35
- let r = t.sampleCount ?? 64, i = t.settleThreshold ?? .001, a = t.maxDuration ?? t.response * 4, o = new e({
36
- response: t.response,
37
- dampingFraction: t.dampingFraction,
38
- initial: 0,
39
- settleThreshold: i,
40
- velocitySettleThreshold: i
41
- });
42
- o.target = 1;
43
- let s = new Float64Array(r + 1);
44
- s[0] = 0;
45
- let c = a / r;
46
- for (let e = 1; e <= r; e++) o._stepSeconds(c), s[e] = o.settled ? 1 : o.value;
47
- s[r] = 1, o.dispose();
48
- let l = (e) => {
49
- if (e <= 0) return 0;
50
- if (e >= 1) return 1;
51
- let t = e * r, n = Math.floor(t), i = t - n, a = s[n];
52
- return a + (s[n + 1] - a) * i;
53
- }, u = {
54
- response: t.response,
55
- dampingFraction: t.dampingFraction
56
- };
57
- return t.settleThreshold !== void 0 && (u.settleThreshold = t.settleThreshold), t.maxDuration !== void 0 && (u.maxDuration = t.maxDuration), {
58
- fn: l,
59
- css: n(u)
60
- };
61
- }
62
- //#endregion
63
- export { n, t as r, r as t };