@mkbabb/keyframes.js 4.3.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,30 +1,9 @@
1
- import { a as e, c as t, f as n, i as r } from "./timeline-BjcmprQ6.js";
1
+ import { a as e, c as t, f as n, i as r } from "./timeline-vY3eD3Ax.js";
2
2
  import { n as i } from "./decay-BvNmFk51.js";
3
- import { n as a, t as o } from "./waapi-Bd5QadtA.js";
4
- import { extractTimelineOptions as s, parseAnimationRange as c, parseAnimationTimeline as l, parseCSSStylesheet as u, serializeTimelineOptions as d } from "@mkbabb/value.js";
5
- //#region src/animation/scroll-grammar.ts
6
- function f(e) {
7
- return l(e);
8
- }
9
- function p(e) {
10
- return c(e);
11
- }
12
- function m(e) {
13
- return s(typeof e == "string" ? u(e) : e);
14
- }
15
- function h(e) {
16
- return d(e);
17
- }
18
- function g(e) {
19
- let t = m(e);
20
- return {
21
- options: t,
22
- declarations: h(t)
23
- };
24
- }
25
- //#endregion
3
+ import { n as a, t as o } from "./waapi-D0ssxKy1.js";
4
+ import { a as s, i as c, n as l, r as u, t as d } from "./scroll-grammar-B4kPvGh5.js";
26
5
  //#region src/animation/scroll-scene.ts
27
- var _ = {
6
+ var f = {
28
7
  normal: {
29
8
  start: 0,
30
9
  end: 1
@@ -54,7 +33,7 @@ var _ = {
54
33
  end: 1
55
34
  }
56
35
  };
57
- function v(e) {
36
+ function p(e) {
58
37
  if (e == null) return null;
59
38
  let t = e.trim();
60
39
  if (t.endsWith("%")) {
@@ -63,24 +42,24 @@ function v(e) {
63
42
  }
64
43
  return null;
65
44
  }
66
- function y(e, t) {
45
+ function m(e, t) {
67
46
  if (e == null) return t;
68
- let n = v(e.offset);
47
+ let n = p(e.offset);
69
48
  if (n != null) {
70
49
  if (e.phase != null && e.phase !== "normal") {
71
- let t = _[e.phase];
50
+ let t = f[e.phase];
72
51
  return t.start + n * (t.end - t.start);
73
52
  }
74
53
  return n;
75
54
  }
76
- return e.phase == null ? t : _[e.phase].start;
55
+ return e.phase == null ? t : f[e.phase].start;
77
56
  }
78
- function b(e) {
57
+ function h(e) {
79
58
  if (e == null) return {
80
59
  start: 0,
81
60
  end: 1
82
61
  };
83
- let t = y(e.start, 0), n = y(e.end, 1);
62
+ let t = m(e.start, 0), n = m(e.end, 1);
84
63
  return n > t ? {
85
64
  start: t,
86
65
  end: n
@@ -89,7 +68,7 @@ function b(e) {
89
68
  end: 1
90
69
  };
91
70
  }
92
- function x(e) {
71
+ function g(e) {
93
72
  let { animation: t, nativeSpec: n, scrub: i, snap: s, velocity: c } = e;
94
73
  if (i) return {
95
74
  backend: "js",
@@ -125,11 +104,11 @@ function x(e) {
125
104
  reason: u.reason
126
105
  };
127
106
  }
128
- function S(e) {
107
+ function _(e) {
129
108
  let t = ["position: sticky;"];
130
109
  return e?.bottom == null ? t.push(`top: ${e?.top ?? 0}px;`) : t.push(`bottom: ${e.bottom}px;`), t.join(" ");
131
110
  }
132
- var C = class {
111
+ var v = class {
133
112
  resolvedRange;
134
113
  snapPoints;
135
114
  snapSpring;
@@ -140,7 +119,7 @@ var C = class {
140
119
  wasInside = !1;
141
120
  subscribers = new Map([["enter", /* @__PURE__ */ new Set()], ["leave", /* @__PURE__ */ new Set()]]);
142
121
  constructor(r = {}) {
143
- if (this.resolvedRange = b(r.range), this.scrubSeconds = r.scrub ?? 0, this.snapPoints = r.snap != null && r.snap.length > 0 ? r.snap : void 0, this.scrubSeconds > 0) {
122
+ if (this.resolvedRange = h(r.range), this.scrubSeconds = r.scrub ?? 0, this.snapPoints = r.snap != null && r.snap.length > 0 ? r.snap : void 0, this.scrubSeconds > 0) {
144
123
  let e = n(1 / (this.scrubSeconds * 60 + 1), .01, 1);
145
124
  this.smoother = new t({
146
125
  damping: e,
@@ -190,8 +169,8 @@ var C = class {
190
169
  for (let n of this.subscribers.get(e)) n(t);
191
170
  }
192
171
  };
193
- function w(e = {}) {
194
- return new C(e);
172
+ function y(e = {}) {
173
+ return new v(e);
195
174
  }
196
175
  //#endregion
197
- export { C as ScrollScene, w as createScrollScene, x as dispatchScrollBackend, m as parseScrollCSS, p as parseScrollRange, f as parseScrollTimeline, S as pinCSS, b as resolveRange, g as roundTripScrollCSS, h as serializeScrollOptions };
176
+ export { v as ScrollScene, y as createScrollScene, g as dispatchScrollBackend, d as parseScrollCSS, l as parseScrollRange, u as parseScrollTimeline, _ as pinCSS, h as resolveRange, c as roundTripScrollCSS, s as serializeScrollOptions };
@@ -1,8 +1,44 @@
1
- import { f as e, l as t } from "./timeline-BjcmprQ6.js";
2
- //#region src/animation/sequence.ts
1
+ import { f as e, l as t } from "./timeline-vY3eD3Ax.js";
2
+ //#region src/animation/sequence-events.ts
3
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 {
4
39
  entries = [];
5
40
  labels = /* @__PURE__ */ new Map();
41
+ _events = new n();
6
42
  cursor = 0;
7
43
  _time = 0;
8
44
  respectReducedMotion;
@@ -42,6 +78,9 @@ var n = class {
42
78
  label(e, t) {
43
79
  return this.labels.set(e, this.resolvePosition(t)), this;
44
80
  }
81
+ on(e, t) {
82
+ return this._events.subscribe(e, t);
83
+ }
45
84
  add(e, t) {
46
85
  let n = this.resolvePosition(t);
47
86
  return this.entries.push({
@@ -62,7 +101,7 @@ var n = class {
62
101
  return n;
63
102
  }
64
103
  seek(e) {
65
- return this._time = e, this._applyAt(e), this;
104
+ return this._time = e, this._fireCrossings(e), this._applyAt(e), this;
66
105
  }
67
106
  _applyAt(t) {
68
107
  for (let { animation: n, at: r } of this.entries) {
@@ -70,6 +109,9 @@ var n = class {
70
109
  n.interpFrames(i, !0);
71
110
  }
72
111
  }
112
+ _fireCrossings(e) {
113
+ this._events.fire(this.entries, this.labels, e);
114
+ }
73
115
  _fold(t) {
74
116
  let n = this.duration;
75
117
  if (n <= 0) return 0;
@@ -85,7 +127,7 @@ var n = class {
85
127
  }
86
128
  play() {
87
129
  if (this._playingPromise) return this._playingPromise;
88
- if (this.respectReducedMotion && r()) return this.seek(this.duration), Promise.resolve();
130
+ if (this.respectReducedMotion && i()) return this.seek(this.duration), Promise.resolve();
89
131
  for (let { animation: e, at: t } of this.entries) e.startTime = t, e.started = !0, e.managed = !0;
90
132
  this._time = 0, this._paused = !1, this._playOrigin = void 0, this._lastClock = void 0;
91
133
  let e = new Promise((e) => {
@@ -99,7 +141,7 @@ var n = class {
99
141
  this._playOrigin === void 0 && (this._playOrigin = this._rate === 0 ? e : e - this._time / this._rate), this._lastClock = e;
100
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);
101
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);
102
- if (this._applyAt(i), r) {
144
+ if (this._fireCrossings(i), this._applyAt(i), r) {
103
145
  this._settle();
104
146
  let e = this._resolvePlay;
105
147
  return this._resolvePlay = null, e?.(), !1;
@@ -151,6 +193,6 @@ var n = class {
151
193
  yoyo(e = !0) {
152
194
  return this._yoyoOn = e, this;
153
195
  }
154
- }, r = () => typeof matchMedia == "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
196
+ }, i = () => typeof matchMedia == "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
155
197
  //#endregion
156
- export { n as t };
198
+ export { r as t };
@@ -1,6 +1,18 @@
1
- import { a as e } from "./timeline-BjcmprQ6.js";
1
+ import { a as e } from "./timeline-vY3eD3Ax.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
2
14
  //#region src/animation/springLinearStops.ts
3
- function t(t) {
15
+ function n(t) {
4
16
  let n = t.sampleCount ?? 24, r = t.settleThreshold ?? .001, i = t.maxDuration ?? t.response * 4, a = new e({
5
17
  response: t.response,
6
18
  dampingFraction: t.dampingFraction,
@@ -19,10 +31,10 @@ function t(t) {
19
31
  }
20
32
  //#endregion
21
33
  //#region src/animation/springTimingFunction.ts
22
- function n(n) {
23
- let r = n.sampleCount ?? 64, i = n.settleThreshold ?? .001, a = n.maxDuration ?? n.response * 4, o = new e({
24
- response: n.response,
25
- dampingFraction: n.dampingFraction,
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,
26
38
  initial: 0,
27
39
  settleThreshold: i,
28
40
  velocitySettleThreshold: i
@@ -39,13 +51,13 @@ function n(n) {
39
51
  let t = e * r, n = Math.floor(t), i = t - n, a = s[n];
40
52
  return a + (s[n + 1] - a) * i;
41
53
  }, u = {
42
- response: n.response,
43
- dampingFraction: n.dampingFraction
54
+ response: t.response,
55
+ dampingFraction: t.dampingFraction
44
56
  };
45
- return n.settleThreshold !== void 0 && (u.settleThreshold = n.settleThreshold), n.maxDuration !== void 0 && (u.maxDuration = n.maxDuration), {
57
+ return t.settleThreshold !== void 0 && (u.settleThreshold = t.settleThreshold), t.maxDuration !== void 0 && (u.maxDuration = t.maxDuration), {
46
58
  fn: l,
47
- css: t(u)
59
+ css: n(u)
48
60
  };
49
61
  }
50
62
  //#endregion
51
- export { t as n, n as t };
63
+ export { n, t as r, r as t };