@algorisys/tinyfly 0.64.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/LICENSE +21 -0
- package/README.md +672 -0
- package/bin/tinyfly.mjs +59 -0
- package/lib/addons/adapters.js +756 -0
- package/lib/addons/dom-adapter-ChrbtkLC.js +243 -0
- package/lib/addons/drivers.js +72 -0
- package/lib/addons/export.js +1169 -0
- package/lib/addons/gsap-compat.js +2576 -0
- package/lib/addons/interaction.js +225 -0
- package/lib/addons/smooth-scroll-DaSacemU.js +671 -0
- package/lib/addons/teach.js +215 -0
- package/lib/browser/tinyfly.iife.js +2 -0
- package/lib/browser/tinyfly.js +6372 -0
- package/lib/browser/tinyfly.umd.js +2 -0
- package/lib/cli/tools.js +2325 -0
- package/lib/embed/tinyfly-embed.iife.js +18 -0
- package/lib/embed/tinyfly-embed.js +2316 -0
- package/lib/engine/tinyfly-engine.js +1972 -0
- package/lib/engine/tinyfly-engine.umd.cjs +2 -0
- package/lib/frameworks/react.js +32 -0
- package/lib/frameworks/solid.js +27 -0
- package/lib/frameworks/svelte.js +15 -0
- package/lib/frameworks/vue.js +29 -0
- package/lib/player/tinyfly-player.es.js +2306 -0
- package/lib/player/tinyfly-player.iife.js +2 -0
- package/lib/player/tinyfly-player.umd.js +2 -0
- package/lib/types/adapters/canvas/canvas-adapter.d.ts +238 -0
- package/lib/types/adapters/canvas/index.d.ts +1 -0
- package/lib/types/adapters/dom/dom-adapter.d.ts +50 -0
- package/lib/types/adapters/dom/flip.d.ts +60 -0
- package/lib/types/adapters/dom/index.d.ts +2 -0
- package/lib/types/adapters/filter-utils.d.ts +32 -0
- package/lib/types/adapters/index.d.ts +5 -0
- package/lib/types/adapters/shine-utils.d.ts +26 -0
- package/lib/types/adapters/svg/index.d.ts +1 -0
- package/lib/types/adapters/svg/svg-adapter.d.ts +47 -0
- package/lib/types/adapters/svg-transform-box.d.ts +13 -0
- package/lib/types/adapters/text-content.d.ts +11 -0
- package/lib/types/adapters/webgl/index.d.ts +1 -0
- package/lib/types/adapters/webgl/webgl-adapter.d.ts +69 -0
- package/lib/types/browser/index.d.ts +41 -0
- package/lib/types/compat/gsap/custom-eases.d.ts +28 -0
- package/lib/types/compat/gsap/defaults.d.ts +19 -0
- package/lib/types/compat/gsap/draw-svg-vars.d.ts +36 -0
- package/lib/types/compat/gsap/ease-map.d.ts +51 -0
- package/lib/types/compat/gsap/image-sequence.d.ts +61 -0
- package/lib/types/compat/gsap/index.d.ts +65 -0
- package/lib/types/compat/gsap/inertia-vars.d.ts +39 -0
- package/lib/types/compat/gsap/keyframes-vars.d.ts +8 -0
- package/lib/types/compat/gsap/layout.d.ts +6 -0
- package/lib/types/compat/gsap/live-context.d.ts +87 -0
- package/lib/types/compat/gsap/live-draggable.d.ts +75 -0
- package/lib/types/compat/gsap/live-flip.d.ts +73 -0
- package/lib/types/compat/gsap/live-morph.d.ts +18 -0
- package/lib/types/compat/gsap/live-motion-path.d.ts +33 -0
- package/lib/types/compat/gsap/live-scroll-to.d.ts +52 -0
- package/lib/types/compat/gsap/live-scroll.d.ts +108 -0
- package/lib/types/compat/gsap/live-transition.d.ts +40 -0
- package/lib/types/compat/gsap/live.d.ts +341 -0
- package/lib/types/compat/gsap/morph-vars.d.ts +21 -0
- package/lib/types/compat/gsap/motion-path-vars.d.ts +38 -0
- package/lib/types/compat/gsap/playhead-crossings.d.ts +47 -0
- package/lib/types/compat/gsap/position.d.ts +37 -0
- package/lib/types/compat/gsap/quick-play.d.ts +38 -0
- package/lib/types/compat/gsap/split-text.d.ts +66 -0
- package/lib/types/compat/gsap/spring-vars.d.ts +34 -0
- package/lib/types/compat/gsap/stage.d.ts +182 -0
- package/lib/types/compat/gsap/stagger-grid.d.ts +30 -0
- package/lib/types/compat/gsap/text-vars.d.ts +39 -0
- package/lib/types/compat/gsap/timeline.d.ts +161 -0
- package/lib/types/compat/gsap/utils.d.ts +60 -0
- package/lib/types/compat/gsap/vars.d.ts +79 -0
- package/lib/types/drivers/index.d.ts +8 -0
- package/lib/types/drivers/scroll-driver.d.ts +218 -0
- package/lib/types/drivers/scroll-markers.d.ts +41 -0
- package/lib/types/drivers/scroll-math.d.ts +87 -0
- package/lib/types/drivers/scroll-pin.d.ts +45 -0
- package/lib/types/drivers/scroll-snap.d.ts +47 -0
- package/lib/types/drivers/smooth-scroll.d.ts +118 -0
- package/lib/types/drivers/types.d.ts +23 -0
- package/lib/types/drivers/visibility-driver.d.ts +56 -0
- package/lib/types/embed/controls.d.ts +46 -0
- package/lib/types/embed/index.d.ts +17 -0
- package/lib/types/embed/mount.d.ts +41 -0
- package/lib/types/embed/tools.d.ts +33 -0
- package/lib/types/engine/authoring/custom-ease.d.ts +49 -0
- package/lib/types/engine/authoring/index.d.ts +3 -0
- package/lib/types/engine/authoring/random.d.ts +38 -0
- package/lib/types/engine/authoring/resolve-values.d.ts +57 -0
- package/lib/types/engine/core/bake.d.ts +66 -0
- package/lib/types/engine/core/clock.d.ts +44 -0
- package/lib/types/engine/core/index.d.ts +8 -0
- package/lib/types/engine/core/inertia.d.ts +30 -0
- package/lib/types/engine/core/playhead-crossings.d.ts +47 -0
- package/lib/types/engine/core/spring.d.ts +132 -0
- package/lib/types/engine/core/stagger.d.ts +40 -0
- package/lib/types/engine/core/timeline.d.ts +203 -0
- package/lib/types/engine/core/track.d.ts +90 -0
- package/lib/types/engine/export/byte-writer.d.ts +36 -0
- package/lib/types/engine/export/css.d.ts +31 -0
- package/lib/types/engine/export/gif-decode.test-helper.d.ts +24 -0
- package/lib/types/engine/export/gif.d.ts +134 -0
- package/lib/types/engine/export/index.d.ts +9 -0
- package/lib/types/engine/export/lottie.d.ts +104 -0
- package/lib/types/engine/export/mp4.d.ts +64 -0
- package/lib/types/engine/export/quantize.d.ts +56 -0
- package/lib/types/engine/export/sprite-sheet.d.ts +46 -0
- package/lib/types/engine/export/video.d.ts +99 -0
- package/lib/types/engine/export/webp.d.ts +82 -0
- package/lib/types/engine/index.d.ts +7 -0
- package/lib/types/engine/interpolation/easing.d.ts +65 -0
- package/lib/types/engine/interpolation/index.d.ts +2 -0
- package/lib/types/engine/interpolation/interpolators.d.ts +25 -0
- package/lib/types/engine/path/index.d.ts +11 -0
- package/lib/types/engine/path/motion-path.d.ts +24 -0
- package/lib/types/engine/path/path-builders.d.ts +38 -0
- package/lib/types/engine/path/path-morph.d.ts +47 -0
- package/lib/types/engine/path/path-utils.d.ts +73 -0
- package/lib/types/engine/serialization/index.d.ts +1 -0
- package/lib/types/engine/serialization/json.d.ts +30 -0
- package/lib/types/engine/text/index.d.ts +2 -0
- package/lib/types/engine/text/text-value.d.ts +16 -0
- package/lib/types/engine/types.d.ts +401 -0
- package/lib/types/frameworks/react.d.ts +35 -0
- package/lib/types/frameworks/solid.d.ts +16 -0
- package/lib/types/frameworks/svelte.d.ts +19 -0
- package/lib/types/frameworks/vue.d.ts +27 -0
- package/lib/types/interaction/draggable.d.ts +133 -0
- package/lib/types/interaction/index.d.ts +3 -0
- package/lib/types/interaction/observer.d.ts +80 -0
- package/lib/types/interaction/snap.d.ts +30 -0
- package/lib/types/player/index.d.ts +7 -0
- package/lib/types/player/media-sync.d.ts +60 -0
- package/lib/types/player/player.d.ts +238 -0
- package/lib/types/player/sequence-types.d.ts +68 -0
- package/lib/types/player/sequencer.d.ts +91 -0
- package/lib/types/teach/diagrams.d.ts +137 -0
- package/lib/types/teach/index.d.ts +11 -0
- package/lib/types/teach/lesson.d.ts +55 -0
- package/package.json +170 -0
|
@@ -0,0 +1,2306 @@
|
|
|
1
|
+
function ee(i) {
|
|
2
|
+
return typeof i == "object" && i !== null && i.type === "cubic-bezier";
|
|
3
|
+
}
|
|
4
|
+
function ie(i) {
|
|
5
|
+
return typeof i == "object" && i !== null && i.type !== "cubic-bezier";
|
|
6
|
+
}
|
|
7
|
+
const lt = 1;
|
|
8
|
+
function Xt(i) {
|
|
9
|
+
return i.property === "text" && "textConfig" in i;
|
|
10
|
+
}
|
|
11
|
+
function ut(i) {
|
|
12
|
+
return i.kind === "inertia" && "inertia" in i;
|
|
13
|
+
}
|
|
14
|
+
function ft(i) {
|
|
15
|
+
return i.kind === "spring" && "spring" in i;
|
|
16
|
+
}
|
|
17
|
+
function se(i) {
|
|
18
|
+
return i.property === "motionPath" && "motionPathConfig" in i;
|
|
19
|
+
}
|
|
20
|
+
function qt(i, t, e = "start") {
|
|
21
|
+
if (t <= 1) return 0;
|
|
22
|
+
if (typeof e == "number") {
|
|
23
|
+
const s = Math.max(0, Math.min(t - 1, e));
|
|
24
|
+
return Math.abs(i - s);
|
|
25
|
+
}
|
|
26
|
+
switch (e) {
|
|
27
|
+
case "end":
|
|
28
|
+
return t - 1 - i;
|
|
29
|
+
case "center":
|
|
30
|
+
return Math.abs(i - (t - 1) / 2);
|
|
31
|
+
case "edges":
|
|
32
|
+
return (t - 1) / 2 - Math.abs(i - (t - 1) / 2);
|
|
33
|
+
default:
|
|
34
|
+
return i;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function ne(i, t = "start") {
|
|
38
|
+
if (i <= 1) return 0;
|
|
39
|
+
let e = 0;
|
|
40
|
+
for (let s = 0; s < i; s++)
|
|
41
|
+
e = Math.max(e, qt(s, i, t));
|
|
42
|
+
return e;
|
|
43
|
+
}
|
|
44
|
+
function Yt(i, t, e) {
|
|
45
|
+
if (e.offsets) return e.offsets[i] ?? 0;
|
|
46
|
+
const s = e.from ?? "start", n = qt(i, t, s);
|
|
47
|
+
if (e.amount !== void 0) {
|
|
48
|
+
const r = ne(t, s);
|
|
49
|
+
return r === 0 ? 0 : e.amount * n / r;
|
|
50
|
+
}
|
|
51
|
+
return e.each !== void 0 ? e.each * n : 0;
|
|
52
|
+
}
|
|
53
|
+
function re(i, t) {
|
|
54
|
+
return Array.from({ length: i }, (e, s) => Yt(s, i, t));
|
|
55
|
+
}
|
|
56
|
+
function mt(i, t) {
|
|
57
|
+
return i <= 1 ? 0 : Math.max(...re(i, t));
|
|
58
|
+
}
|
|
59
|
+
const U = 1, Nt = 6e4, j = Nt / U, F = {
|
|
60
|
+
stiffness: 180,
|
|
61
|
+
damping: 12,
|
|
62
|
+
mass: 1,
|
|
63
|
+
velocity: 0,
|
|
64
|
+
restDelta: 0.01,
|
|
65
|
+
restSpeed: 0.1
|
|
66
|
+
};
|
|
67
|
+
class ae {
|
|
68
|
+
from;
|
|
69
|
+
to;
|
|
70
|
+
stiffness;
|
|
71
|
+
damping;
|
|
72
|
+
mass;
|
|
73
|
+
restDelta;
|
|
74
|
+
restSpeed;
|
|
75
|
+
/** value[i] is the spring's position at time i * SPRING_STEP_MS */
|
|
76
|
+
/**
|
|
77
|
+
* Travel distance, used to scale the rest thresholds.
|
|
78
|
+
*
|
|
79
|
+
* Without this the thresholds are absolute, and a spring animating `scale`
|
|
80
|
+
* from 0 to 1 hits them ~100x sooner than one animating `x` from 0 to 100 —
|
|
81
|
+
* so the small one is declared "settled" at its first pass through the
|
|
82
|
+
* target and never shows the overshoot at all. Scaling by travel makes
|
|
83
|
+
* settling depend on the spring's parameters, not on the units of whatever
|
|
84
|
+
* property it happens to drive.
|
|
85
|
+
*/
|
|
86
|
+
distance;
|
|
87
|
+
samples;
|
|
88
|
+
velocity;
|
|
89
|
+
/** Once at rest we stop simulating; every later time returns `to`. */
|
|
90
|
+
settledStep = null;
|
|
91
|
+
constructor(t) {
|
|
92
|
+
this.from = t.from, this.to = t.to, this.stiffness = t.stiffness ?? F.stiffness, this.damping = t.damping ?? F.damping, this.mass = t.mass ?? F.mass, this.restDelta = t.restDelta ?? F.restDelta, this.restSpeed = t.restSpeed ?? F.restSpeed, this.distance = Math.abs(this.to - this.from) || 1, this.samples = [this.from], this.velocity = t.velocity ?? F.velocity, this.isAtRest(this.from) && (this.settledStep = 0);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Whether a position/velocity pair counts as settled.
|
|
96
|
+
*
|
|
97
|
+
* Both thresholds are fractions of the spring's travel distance:
|
|
98
|
+
* `restDelta` as a fraction of the distance, and `restSpeed` as a fraction
|
|
99
|
+
* of the distance per second. That keeps settling scale-invariant.
|
|
100
|
+
*/
|
|
101
|
+
isAtRest(t) {
|
|
102
|
+
return Math.abs(t - this.to) < this.restDelta * this.distance && Math.abs(this.velocity) < this.restSpeed * this.distance;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Position at `timeMs`. Times before 0 clamp to the start value; times past
|
|
106
|
+
* settling return the target exactly.
|
|
107
|
+
*/
|
|
108
|
+
valueAt(t) {
|
|
109
|
+
if (t <= 0) return this.from;
|
|
110
|
+
const e = Math.floor(t / U);
|
|
111
|
+
if (this.simulateTo(e + 1), this.settledStep !== null && e >= this.settledStep)
|
|
112
|
+
return this.to;
|
|
113
|
+
const s = this.samples[Math.min(e, this.samples.length - 1)], n = this.samples[Math.min(e + 1, this.samples.length - 1)], r = t / U - e;
|
|
114
|
+
return s + (n - s) * r;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* How long the spring takes to settle, in milliseconds — the natural duration
|
|
118
|
+
* of a spring track. Runs the simulation to completion once.
|
|
119
|
+
*/
|
|
120
|
+
settleTime() {
|
|
121
|
+
return this.simulateTo(j + 1), this.settledStep !== null ? this.settledStep * U : Nt;
|
|
122
|
+
}
|
|
123
|
+
/** Advance the cached simulation until it holds at least `steps` samples. */
|
|
124
|
+
simulateTo(t) {
|
|
125
|
+
if (this.settledStep !== null) return;
|
|
126
|
+
const e = Math.min(t, j + 1), s = U / 1e3;
|
|
127
|
+
for (; this.samples.length < e; ) {
|
|
128
|
+
const n = this.samples[this.samples.length - 1], r = n - this.to, a = -this.stiffness * r, o = -this.damping * this.velocity, c = (a + o) / this.mass;
|
|
129
|
+
this.velocity += c * s;
|
|
130
|
+
const h = n + this.velocity * s;
|
|
131
|
+
if (this.samples.push(h), this.isAtRest(h)) {
|
|
132
|
+
this.settledStep = this.samples.length - 1;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
this.samples.length > j && (this.settledStep = j);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const At = 4, oe = 2e-3, ce = 1e-4, he = 6e4;
|
|
140
|
+
function gt(i) {
|
|
141
|
+
const t = i.friction ?? At;
|
|
142
|
+
return t > 0 ? t : At;
|
|
143
|
+
}
|
|
144
|
+
function le(i) {
|
|
145
|
+
return i.from + i.velocity / gt(i);
|
|
146
|
+
}
|
|
147
|
+
function ue(i, t) {
|
|
148
|
+
if (t === void 0) return i;
|
|
149
|
+
if (typeof t == "number")
|
|
150
|
+
return t > 0 ? Math.round(i / t) * t : i;
|
|
151
|
+
if (t.length === 0) return i;
|
|
152
|
+
let e = t[0];
|
|
153
|
+
for (const s of t)
|
|
154
|
+
Math.abs(s - i) < Math.abs(e - i) && (e = s);
|
|
155
|
+
return e;
|
|
156
|
+
}
|
|
157
|
+
function Vt(i) {
|
|
158
|
+
let t = ue(le(i), i.end);
|
|
159
|
+
return i.min !== void 0 && (t = Math.max(i.min, t)), i.max !== void 0 && (t = Math.min(i.max, t)), t;
|
|
160
|
+
}
|
|
161
|
+
function Wt(i) {
|
|
162
|
+
const t = Math.abs(Vt(i) - i.from);
|
|
163
|
+
if (t === 0) return 0;
|
|
164
|
+
const e = i.restDelta ?? Math.max(ce, t * oe);
|
|
165
|
+
if (e >= t) return 0;
|
|
166
|
+
const s = Math.log(t / e) / gt(i);
|
|
167
|
+
return Math.min(he, s * 1e3);
|
|
168
|
+
}
|
|
169
|
+
function St(i, t) {
|
|
170
|
+
if (t <= 0) return i.from;
|
|
171
|
+
const e = Vt(i);
|
|
172
|
+
if (t >= Wt(i)) return e;
|
|
173
|
+
const s = gt(i);
|
|
174
|
+
return i.from + (e - i.from) * (1 - Math.exp(-s * t / 1e3));
|
|
175
|
+
}
|
|
176
|
+
const dt = (i) => i, fe = (i) => i * i, de = (i) => 1 - (1 - i) * (1 - i), pe = (i) => i < 0.5 ? 2 * i * i : 1 - Math.pow(-2 * i + 2, 2) / 2, Ut = (i) => i * i * i, Ht = (i) => 1 - Math.pow(1 - i, 3), Qt = (i) => i < 0.5 ? 4 * i * i * i : 1 - Math.pow(-2 * i + 2, 3) / 2, me = Ut, ge = Ht, ye = Qt, Te = {
|
|
177
|
+
linear: dt,
|
|
178
|
+
"ease-in": me,
|
|
179
|
+
"ease-out": ge,
|
|
180
|
+
"ease-in-out": ye,
|
|
181
|
+
"ease-in-quad": fe,
|
|
182
|
+
"ease-out-quad": de,
|
|
183
|
+
"ease-in-out-quad": pe,
|
|
184
|
+
"ease-in-cubic": Ut,
|
|
185
|
+
"ease-out-cubic": Ht,
|
|
186
|
+
"ease-in-out-cubic": Qt
|
|
187
|
+
};
|
|
188
|
+
function be(i) {
|
|
189
|
+
const [t, e, s, n] = i, r = 3 * t, a = 3 * (s - t) - r, o = 1 - r - a, c = 3 * e, h = 3 * (n - e) - c, u = 1 - c - h, l = (p) => ((o * p + a) * p + r) * p, f = (p) => ((u * p + h) * p + c) * p, d = (p) => (3 * o * p + 2 * a) * p + r, b = (p) => {
|
|
190
|
+
let g = p;
|
|
191
|
+
for (let A = 0; A < 8; A++) {
|
|
192
|
+
const _ = l(g) - p;
|
|
193
|
+
if (Math.abs(_) < 1e-7)
|
|
194
|
+
return g;
|
|
195
|
+
const m = d(g);
|
|
196
|
+
if (Math.abs(m) < 1e-7)
|
|
197
|
+
break;
|
|
198
|
+
g -= _ / m;
|
|
199
|
+
}
|
|
200
|
+
let y = 0, T = 1;
|
|
201
|
+
for (g = p; y < T; ) {
|
|
202
|
+
const A = l(g);
|
|
203
|
+
if (Math.abs(A - p) < 1e-7)
|
|
204
|
+
return g;
|
|
205
|
+
p > A ? y = g : T = g, g = (y + T) / 2;
|
|
206
|
+
}
|
|
207
|
+
return g;
|
|
208
|
+
};
|
|
209
|
+
return (p) => {
|
|
210
|
+
if (p <= 0) return 0;
|
|
211
|
+
if (p >= 1) return 1;
|
|
212
|
+
const g = b(p);
|
|
213
|
+
return f(g);
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function st(i, t = "out") {
|
|
217
|
+
if (t === "out") return i;
|
|
218
|
+
const e = (s) => 1 - i(1 - s);
|
|
219
|
+
return t === "in" ? e : (s) => s < 0.5 ? e(s * 2) / 2 : i(s * 2 - 1) / 2 + 0.5;
|
|
220
|
+
}
|
|
221
|
+
function Ae(i = 1, t = 0.3) {
|
|
222
|
+
const e = Math.max(1, i), s = t / (2 * Math.PI) * Math.asin(1 / e);
|
|
223
|
+
return (n) => n <= 0 ? 0 : n >= 1 ? 1 : e * Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / t) + 1;
|
|
224
|
+
}
|
|
225
|
+
const Se = (i) => {
|
|
226
|
+
if (i <= 0) return 0;
|
|
227
|
+
if (i >= 1) return 1;
|
|
228
|
+
if (i < 1 / 2.75) return 7.5625 * i * i;
|
|
229
|
+
if (i < 2 / 2.75) {
|
|
230
|
+
const n = i - 0.5454545454545454;
|
|
231
|
+
return 7.5625 * n * n + 0.75;
|
|
232
|
+
}
|
|
233
|
+
if (i < 2.5 / 2.75) {
|
|
234
|
+
const n = i - 0.8181818181818182;
|
|
235
|
+
return 7.5625 * n * n + 0.9375;
|
|
236
|
+
}
|
|
237
|
+
const s = i - 2.625 / 2.75;
|
|
238
|
+
return 7.5625 * s * s + 0.984375;
|
|
239
|
+
};
|
|
240
|
+
function _e(i = 1.70158) {
|
|
241
|
+
return (t) => {
|
|
242
|
+
if (t <= 0) return 0;
|
|
243
|
+
if (t >= 1) return 1;
|
|
244
|
+
const e = t - 1;
|
|
245
|
+
return e * e * ((i + 1) * e + i) + 1;
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function Me(i, t = "end") {
|
|
249
|
+
const e = Math.max(1, Math.floor(i));
|
|
250
|
+
return (s) => {
|
|
251
|
+
if (s >= 1) return 1;
|
|
252
|
+
if (s <= 0) return t === "start" || t === "both" ? t === "start" ? 1 / e : 1 / (e + 1) : 0;
|
|
253
|
+
const n = Math.floor(s * e);
|
|
254
|
+
switch (t) {
|
|
255
|
+
case "start":
|
|
256
|
+
return Math.min(1, (n + 1) / e);
|
|
257
|
+
case "both":
|
|
258
|
+
return (n + 1) / (e + 1);
|
|
259
|
+
case "none":
|
|
260
|
+
return e === 1 ? 0 : Math.min(1, n / (e - 1));
|
|
261
|
+
default:
|
|
262
|
+
return n / e;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function ke(i) {
|
|
267
|
+
switch (i.type) {
|
|
268
|
+
case "steps":
|
|
269
|
+
return Me(i.count, i.position);
|
|
270
|
+
case "elastic":
|
|
271
|
+
return st(Ae(i.amplitude, i.period), i.mode);
|
|
272
|
+
case "bounce":
|
|
273
|
+
return st(Se, i.mode);
|
|
274
|
+
case "back":
|
|
275
|
+
return st(_e(i.overshoot), i.mode);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function we(i) {
|
|
279
|
+
return i === void 0 ? dt : ee(i) ? be(i.points) : ie(i) ? ke(i) : Te[i] ?? dt;
|
|
280
|
+
}
|
|
281
|
+
const _t = 32, Pe = 256, Y = /* @__PURE__ */ new Map(), xe = /[MmLlHhVvCcSsQqTtAaZz]/, ve = /^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/, Ce = {
|
|
282
|
+
M: 2,
|
|
283
|
+
L: 2,
|
|
284
|
+
H: 1,
|
|
285
|
+
V: 1,
|
|
286
|
+
C: 6,
|
|
287
|
+
S: 4,
|
|
288
|
+
Q: 4,
|
|
289
|
+
T: 2,
|
|
290
|
+
A: 7,
|
|
291
|
+
Z: 0
|
|
292
|
+
};
|
|
293
|
+
function Ie(i) {
|
|
294
|
+
const t = [];
|
|
295
|
+
let e = 0, s = null;
|
|
296
|
+
const n = () => {
|
|
297
|
+
for (; e < i.length && /[\s,]/.test(i[e]); ) e++;
|
|
298
|
+
};
|
|
299
|
+
for (; e < i.length && (n(), !(e >= i.length)); ) {
|
|
300
|
+
const r = i[e];
|
|
301
|
+
if (xe.test(r)) {
|
|
302
|
+
s = { type: r, args: [] }, t.push(s), e++;
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (!s) break;
|
|
306
|
+
const a = s.type === "A" || s.type === "a", o = s.args.length % 7;
|
|
307
|
+
if (a && (o === 3 || o === 4)) {
|
|
308
|
+
if (r !== "0" && r !== "1") break;
|
|
309
|
+
s.args.push(r === "1" ? 1 : 0), e++;
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
const c = ve.exec(i.slice(e));
|
|
313
|
+
if (!c) break;
|
|
314
|
+
s.args.push(parseFloat(c[0])), e += c[0].length;
|
|
315
|
+
}
|
|
316
|
+
return t;
|
|
317
|
+
}
|
|
318
|
+
function Re(i, t, e, s, n, r, a, o, c) {
|
|
319
|
+
if (i === o && t === c) return [];
|
|
320
|
+
let h = Math.abs(e), u = Math.abs(s);
|
|
321
|
+
if (h === 0 || u === 0) return [[i, t, o, c, o, c]];
|
|
322
|
+
const l = n * Math.PI / 180, f = Math.cos(l), d = Math.sin(l), b = (i - o) / 2, p = (t - c) / 2, g = f * b + d * p, y = -d * b + f * p, T = g * g / (h * h) + y * y / (u * u);
|
|
323
|
+
if (T > 1) {
|
|
324
|
+
const w = Math.sqrt(T);
|
|
325
|
+
h *= w, u *= w;
|
|
326
|
+
}
|
|
327
|
+
const A = r === a ? -1 : 1, _ = h * h * u * u - h * h * y * y - u * u * g * g, m = h * h * y * y + u * u * g * g, M = A * Math.sqrt(Math.max(0, _ / m)), S = M * h * y / u, R = -M * u * g / h, Q = f * S - d * R + (i + o) / 2, k = d * S + f * R + (t + c) / 2, C = (w, v, I, O) => {
|
|
328
|
+
const it = w * I + v * O, G = Math.sqrt((w * w + v * v) * (I * I + O * O)), q = Math.acos(Math.max(-1, Math.min(1, it / G)));
|
|
329
|
+
return w * O - v * I < 0 ? -q : q;
|
|
330
|
+
}, P = C(1, 0, (g - S) / h, (y - R) / u);
|
|
331
|
+
let x = C((g - S) / h, (y - R) / u, (-g - S) / h, (-y - R) / u);
|
|
332
|
+
!a && x > 0 && (x -= 2 * Math.PI), a && x < 0 && (x += 2 * Math.PI);
|
|
333
|
+
const E = Math.max(1, Math.ceil(Math.abs(x) / (Math.PI / 2))), et = x / E, z = 4 / 3 * Math.tan(et / 4), yt = (w) => {
|
|
334
|
+
const v = h * Math.cos(w), I = u * Math.sin(w);
|
|
335
|
+
return [f * v - d * I + Q, d * v + f * I + k];
|
|
336
|
+
}, Tt = (w) => {
|
|
337
|
+
const v = -h * Math.sin(w), I = u * Math.cos(w);
|
|
338
|
+
return [f * v - d * I, d * v + f * I];
|
|
339
|
+
}, bt = [];
|
|
340
|
+
for (let w = 0; w < E; w++) {
|
|
341
|
+
const v = P + w * et, I = v + et, [O, it] = yt(v), [G, q] = w === E - 1 ? [o, c] : yt(I), [Zt, Kt] = Tt(v), [Jt, te] = Tt(I);
|
|
342
|
+
bt.push([O + z * Zt, it + z * Kt, G - z * Jt, q - z * te, G, q]);
|
|
343
|
+
}
|
|
344
|
+
return bt;
|
|
345
|
+
}
|
|
346
|
+
function B(i, t, e, s, n) {
|
|
347
|
+
const r = 1 - n;
|
|
348
|
+
return r * r * r * i + 3 * r * r * n * t + 3 * r * n * n * e + n * n * n * s;
|
|
349
|
+
}
|
|
350
|
+
function Mt(i, t, e, s, n) {
|
|
351
|
+
const r = 1 - n;
|
|
352
|
+
return 3 * r * r * (t - i) + 6 * r * n * (e - t) + 3 * n * n * (s - e);
|
|
353
|
+
}
|
|
354
|
+
function N(i, t, e, s) {
|
|
355
|
+
return {
|
|
356
|
+
subpath: 0,
|
|
357
|
+
type: "L",
|
|
358
|
+
points: [e, s],
|
|
359
|
+
startX: i,
|
|
360
|
+
startY: t,
|
|
361
|
+
endX: e,
|
|
362
|
+
endY: s,
|
|
363
|
+
length: Math.hypot(e - i, s - t)
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function Z(i, t, e) {
|
|
367
|
+
const [s, n, r, a, o, c] = e, h = [0];
|
|
368
|
+
let u = i, l = t, f = 0;
|
|
369
|
+
for (let d = 1; d <= _t; d++) {
|
|
370
|
+
const b = d / _t, p = B(i, s, r, o, b), g = B(t, n, a, c, b);
|
|
371
|
+
f += Math.hypot(p - u, g - l), h.push(f), u = p, l = g;
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
subpath: 0,
|
|
375
|
+
type: "C",
|
|
376
|
+
points: [s, n, r, a, o, c],
|
|
377
|
+
startX: i,
|
|
378
|
+
startY: t,
|
|
379
|
+
endX: o,
|
|
380
|
+
endY: c,
|
|
381
|
+
length: f,
|
|
382
|
+
lengths: h
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
function J(i) {
|
|
386
|
+
const t = Y.get(i);
|
|
387
|
+
if (t) return t;
|
|
388
|
+
const e = [];
|
|
389
|
+
let s = 0, n = 0, r = 0, a = 0, o = null, c = null, h = -1;
|
|
390
|
+
const u = /* @__PURE__ */ new Set(), l = (p) => {
|
|
391
|
+
h < 0 && (h = 0), p.subpath = h, e.push(p);
|
|
392
|
+
};
|
|
393
|
+
for (const { type: p, args: g } of Ie(i)) {
|
|
394
|
+
const y = p.toUpperCase(), T = p !== y, A = Ce[y];
|
|
395
|
+
if (y === "Z") {
|
|
396
|
+
(s !== r || n !== a) && l(N(s, n, r, a)), h >= 0 && u.add(h), s = r, n = a, o = c = null;
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
for (let _ = 0; _ + A <= g.length; _ += A) {
|
|
400
|
+
const m = g.slice(_, _ + A), M = T ? s : 0, S = T ? n : 0;
|
|
401
|
+
let R = null, Q = null;
|
|
402
|
+
switch (y) {
|
|
403
|
+
case "M":
|
|
404
|
+
_ === 0 ? (s = m[0] + M, n = m[1] + S, r = s, a = n, (h < 0 || e[e.length - 1]?.subpath === h) && h++) : (l(N(s, n, m[0] + M, m[1] + S)), s = m[0] + M, n = m[1] + S);
|
|
405
|
+
break;
|
|
406
|
+
case "L":
|
|
407
|
+
l(N(s, n, m[0] + M, m[1] + S)), s = m[0] + M, n = m[1] + S;
|
|
408
|
+
break;
|
|
409
|
+
case "H":
|
|
410
|
+
l(N(s, n, m[0] + M, n)), s = m[0] + M;
|
|
411
|
+
break;
|
|
412
|
+
case "V":
|
|
413
|
+
l(N(s, n, s, m[0] + S)), n = m[0] + S;
|
|
414
|
+
break;
|
|
415
|
+
case "C": {
|
|
416
|
+
const k = [m[0] + M, m[1] + S, m[2] + M, m[3] + S, m[4] + M, m[5] + S];
|
|
417
|
+
l(Z(s, n, k)), R = [k[2], k[3]], s = k[4], n = k[5];
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
case "S": {
|
|
421
|
+
const [k, C] = o ? [2 * s - o[0], 2 * n - o[1]] : [s, n], P = [k, C, m[0] + M, m[1] + S, m[2] + M, m[3] + S];
|
|
422
|
+
l(Z(s, n, P)), R = [P[2], P[3]], s = P[4], n = P[5];
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
case "Q":
|
|
426
|
+
case "T": {
|
|
427
|
+
let k = s, C = n;
|
|
428
|
+
y === "Q" ? (k = m[0] + M, C = m[1] + S) : c && (k = 2 * s - c[0], C = 2 * n - c[1]);
|
|
429
|
+
const P = y === "Q" ? m[2] + M : m[0] + M, x = y === "Q" ? m[3] + S : m[1] + S;
|
|
430
|
+
l(
|
|
431
|
+
Z(s, n, [
|
|
432
|
+
s + 2 / 3 * (k - s),
|
|
433
|
+
n + 2 / 3 * (C - n),
|
|
434
|
+
P + 2 / 3 * (k - P),
|
|
435
|
+
x + 2 / 3 * (C - x),
|
|
436
|
+
P,
|
|
437
|
+
x
|
|
438
|
+
])
|
|
439
|
+
), Q = [k, C], s = P, n = x;
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
case "A": {
|
|
443
|
+
const k = m[5] + M, C = m[6] + S;
|
|
444
|
+
let P = s, x = n;
|
|
445
|
+
for (const E of Re(s, n, m[0], m[1], m[2], m[3], m[4], k, C))
|
|
446
|
+
l(Z(P, x, E)), P = E[4], x = E[5];
|
|
447
|
+
s = k, n = C;
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
o = R, c = Q;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
const f = e.reduce((p, g) => p + g.length, 0), d = [];
|
|
455
|
+
for (let p = 0; p < e.length; ) {
|
|
456
|
+
const g = e[p].subpath;
|
|
457
|
+
let y = p, T = 0;
|
|
458
|
+
for (; y < e.length && e[y].subpath === g; ) T += e[y++].length;
|
|
459
|
+
const A = e[p], _ = e[y - 1], m = u.has(g) || Math.abs(_.endX - A.startX) < 1e-9 && Math.abs(_.endY - A.startY) < 1e-9;
|
|
460
|
+
d.push({ start: p, end: y, length: T, closed: m }), p = y;
|
|
461
|
+
}
|
|
462
|
+
const b = { segments: e, totalLength: f, subpaths: d };
|
|
463
|
+
return Y.size >= Pe && Y.delete(Y.keys().next().value), Y.set(i, b), b;
|
|
464
|
+
}
|
|
465
|
+
function De(i, t) {
|
|
466
|
+
const e = i.lengths;
|
|
467
|
+
if (t <= 0) return 0;
|
|
468
|
+
if (t >= i.length) return 1;
|
|
469
|
+
let s = 0, n = e.length - 1;
|
|
470
|
+
for (; s < n - 1; ) {
|
|
471
|
+
const o = s + n >> 1;
|
|
472
|
+
e[o] < t ? s = o : n = o;
|
|
473
|
+
}
|
|
474
|
+
const r = e[n] - e[s], a = r > 0 ? (t - e[s]) / r : 0;
|
|
475
|
+
return (s + a) / (e.length - 1);
|
|
476
|
+
}
|
|
477
|
+
function Be(i, t) {
|
|
478
|
+
if (i.type === "L") {
|
|
479
|
+
const l = i.length > 0 ? Math.max(0, Math.min(1, t / i.length)) : 0;
|
|
480
|
+
return {
|
|
481
|
+
x: i.startX + (i.endX - i.startX) * l,
|
|
482
|
+
y: i.startY + (i.endY - i.startY) * l,
|
|
483
|
+
angle: Math.atan2(i.endY - i.startY, i.endX - i.startX) * 180 / Math.PI
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
const [e, s, n, r, a, o] = i.points, c = De(i, t);
|
|
487
|
+
let h = Mt(i.startX, e, n, a, c), u = Mt(i.startY, s, r, o, c);
|
|
488
|
+
if (Math.hypot(h, u) < 1e-9) {
|
|
489
|
+
const l = c < 0.5 ? Math.min(1, c + 1e-3) : Math.max(0, c - 1e-3), f = B(i.startX, e, n, a, l), d = B(i.startY, s, r, o, l), b = B(i.startX, e, n, a, c), p = B(i.startY, s, r, o, c);
|
|
490
|
+
h = c < 0.5 ? f - b : b - f, u = c < 0.5 ? d - p : p - d;
|
|
491
|
+
}
|
|
492
|
+
return {
|
|
493
|
+
x: B(i.startX, e, n, a, c),
|
|
494
|
+
y: B(i.startY, s, r, o, c),
|
|
495
|
+
angle: Math.atan2(u, h) * 180 / Math.PI
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function zt(i, t, e = 0, s = i.length) {
|
|
499
|
+
if (s <= e) return { x: 0, y: 0, angle: 0 };
|
|
500
|
+
let n = 0;
|
|
501
|
+
for (let r = e; r < s; r++) {
|
|
502
|
+
const a = i[r];
|
|
503
|
+
if (n + a.length >= t || r === s - 1)
|
|
504
|
+
return Be(a, t - n);
|
|
505
|
+
n += a.length;
|
|
506
|
+
}
|
|
507
|
+
return { x: 0, y: 0, angle: 0 };
|
|
508
|
+
}
|
|
509
|
+
function Ee(i, t) {
|
|
510
|
+
const { segments: e, totalLength: s } = J(i);
|
|
511
|
+
return zt(e, Math.max(0, Math.min(1, t)) * s);
|
|
512
|
+
}
|
|
513
|
+
const Le = 24, $e = 320, Oe = 2.5, V = 72, Fe = 0.2, Xe = 128, K = /* @__PURE__ */ new Map();
|
|
514
|
+
let nt = 0, L;
|
|
515
|
+
const kt = (i) => Math.round(i * 100) / 100;
|
|
516
|
+
function wt(i, t) {
|
|
517
|
+
const { segments: e, subpaths: s, totalLength: n } = J(i);
|
|
518
|
+
if (e.length === 0) return [];
|
|
519
|
+
if (t) {
|
|
520
|
+
const r = s.every((a) => a.closed);
|
|
521
|
+
return [{ segments: e, start: 0, end: e.length, length: n, closed: r }];
|
|
522
|
+
}
|
|
523
|
+
return s.filter((r) => r.length > 0).map((r) => ({ segments: e, start: r.start, end: r.end, length: r.length, closed: r.closed }));
|
|
524
|
+
}
|
|
525
|
+
function pt(i, t) {
|
|
526
|
+
const e = i.closed ? (t % 1 + 1) % 1 : Math.max(0, Math.min(1, t)), s = zt(i.segments, e * i.length, i.start, i.end);
|
|
527
|
+
return [s.x, s.y];
|
|
528
|
+
}
|
|
529
|
+
function Pt(i) {
|
|
530
|
+
const t = [];
|
|
531
|
+
let e = 0;
|
|
532
|
+
for (let s = i.start; s < i.end; s++)
|
|
533
|
+
e += i.segments[s].length, i.length > 0 && t.push(e / i.length);
|
|
534
|
+
return t;
|
|
535
|
+
}
|
|
536
|
+
function xt(i, t) {
|
|
537
|
+
const e = [];
|
|
538
|
+
for (let s = 0; s < t; s++)
|
|
539
|
+
e.push(pt(i, i.closed ? s / t : s / (t - 1)));
|
|
540
|
+
return e;
|
|
541
|
+
}
|
|
542
|
+
function vt(i) {
|
|
543
|
+
let t = 0, e = 0;
|
|
544
|
+
for (const [s, n] of i)
|
|
545
|
+
t += s, e += n;
|
|
546
|
+
return t /= i.length, e /= i.length, i.map(([s, n]) => [s - t, n - e]);
|
|
547
|
+
}
|
|
548
|
+
function qe(i, t, e) {
|
|
549
|
+
const s = i.closed && t.closed;
|
|
550
|
+
if (e !== void 0)
|
|
551
|
+
return { offset: s ? Math.abs(e) % V / V : 0, reversed: e < 0 };
|
|
552
|
+
const n = vt(xt(i, V)), r = vt(xt(t, V)), a = V;
|
|
553
|
+
let o = { offset: 0, reversed: !1 }, c = 1 / 0;
|
|
554
|
+
for (const h of [!1, !0]) {
|
|
555
|
+
const u = s ? a : 1;
|
|
556
|
+
for (let l = 0; l < u; l++) {
|
|
557
|
+
let f = 0;
|
|
558
|
+
for (let d = 0; d < a && f < c; d++) {
|
|
559
|
+
const b = s ? h ? (l - d + a) % a : (d + l) % a : h ? a - 1 - d : d, p = n[d][0] - r[b][0], g = n[d][1] - r[b][1];
|
|
560
|
+
f += p * p + g * g;
|
|
561
|
+
}
|
|
562
|
+
f < c && (c = f, o = { offset: s ? l / a : 0, reversed: h });
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return o;
|
|
566
|
+
}
|
|
567
|
+
function Ye(i, t, e) {
|
|
568
|
+
return e ? ((t.reversed ? t.offset - i : i + t.offset) % 1 + 1) % 1 : t.reversed ? 1 - i : i;
|
|
569
|
+
}
|
|
570
|
+
function Ne(i, t, e) {
|
|
571
|
+
return e ? ((t.reversed ? t.offset - i : i - t.offset) % 1 + 1) % 1 : t.reversed ? 1 - i : i;
|
|
572
|
+
}
|
|
573
|
+
function Ve(i, t, e) {
|
|
574
|
+
const s = i.closed && t.closed, n = qe(i, t, e.shapeIndex), r = Math.max(
|
|
575
|
+
Le,
|
|
576
|
+
Math.min($e, Math.ceil(Math.max(i.length, t.length) / Oe))
|
|
577
|
+
), a = /* @__PURE__ */ new Set(), o = (l) => a.add(Math.round(l * 1e7) / 1e7);
|
|
578
|
+
for (let l = 0; l <= r; l++) o(l / r);
|
|
579
|
+
for (const l of Pt(i)) o(l);
|
|
580
|
+
for (const l of Pt(t)) o(Ne(l, n, s));
|
|
581
|
+
let c = [...a].sort((l, f) => l - f);
|
|
582
|
+
s && (c = c.filter((l) => l < 1));
|
|
583
|
+
const h = [], u = [];
|
|
584
|
+
for (const l of c)
|
|
585
|
+
h.push(...pt(i, l)), u.push(...pt(t, Ye(l, n, s)));
|
|
586
|
+
return We({ from: h, to: u, closed: s });
|
|
587
|
+
}
|
|
588
|
+
function We(i) {
|
|
589
|
+
const t = i.from.length / 2;
|
|
590
|
+
if (t <= 3) return i;
|
|
591
|
+
const e = new Uint8Array(t);
|
|
592
|
+
e[0] = 1, e[t - 1] = 1;
|
|
593
|
+
const s = [[0, t - 1]];
|
|
594
|
+
for (; s.length > 0; ) {
|
|
595
|
+
const [a, o] = s.pop();
|
|
596
|
+
let c = -1, h = Fe;
|
|
597
|
+
for (let u = a + 1; u < o; u++) {
|
|
598
|
+
const l = Math.max(Ct(i.from, a, o, u), Ct(i.to, a, o, u));
|
|
599
|
+
l > h && (h = l, c = u);
|
|
600
|
+
}
|
|
601
|
+
c !== -1 && (e[c] = 1, s.push([a, c], [c, o]));
|
|
602
|
+
}
|
|
603
|
+
const n = [], r = [];
|
|
604
|
+
for (let a = 0; a < t; a++)
|
|
605
|
+
e[a] && (n.push(i.from[a * 2], i.from[a * 2 + 1]), r.push(i.to[a * 2], i.to[a * 2 + 1]));
|
|
606
|
+
return { from: n, to: r, closed: i.closed };
|
|
607
|
+
}
|
|
608
|
+
function Ct(i, t, e, s) {
|
|
609
|
+
const n = i[t * 2], r = i[t * 2 + 1], a = i[e * 2] - n, o = i[e * 2 + 1] - r, c = i[s * 2] - n, h = i[s * 2 + 1] - r, u = a * a + o * o, l = u === 0 ? 0 : Math.max(0, Math.min(1, (c * a + h * o) / u));
|
|
610
|
+
return Math.hypot(c - l * a, h - l * o);
|
|
611
|
+
}
|
|
612
|
+
function Ue(i, t, e) {
|
|
613
|
+
const s = e.shapeIndex;
|
|
614
|
+
if (L && L.from === i && L.to === t && L.shapeIndex === s) return L.plan;
|
|
615
|
+
const r = K.get(String(s ?? "auto"))?.get(i)?.get(t);
|
|
616
|
+
if (r)
|
|
617
|
+
return L = { from: i, to: t, shapeIndex: s, plan: r }, r;
|
|
618
|
+
const a = J(i).subpaths.filter((d) => d.length > 0).length === J(t).subpaths.filter((d) => d.length > 0).length, o = wt(i, !a), c = wt(t, !a), h = {
|
|
619
|
+
pairs: o.map((d, b) => Ve(d, c[b], e))
|
|
620
|
+
};
|
|
621
|
+
nt >= Xe && (K.clear(), nt = 0);
|
|
622
|
+
const u = String(s ?? "auto"), l = K.get(u) ?? /* @__PURE__ */ new Map();
|
|
623
|
+
K.set(u, l);
|
|
624
|
+
const f = l.get(i) ?? /* @__PURE__ */ new Map();
|
|
625
|
+
return l.set(i, f), f.set(t, h), nt++, L = { from: i, to: t, shapeIndex: s, plan: h }, h;
|
|
626
|
+
}
|
|
627
|
+
function He(i, t, e, s = {}) {
|
|
628
|
+
if (!i) return t;
|
|
629
|
+
if (!t) return i;
|
|
630
|
+
const n = Math.max(0, Math.min(1, e));
|
|
631
|
+
if (n === 0) return i;
|
|
632
|
+
if (n === 1) return t;
|
|
633
|
+
const r = Ue(i, t, s);
|
|
634
|
+
if (r.pairs.length === 0) return n < 0.5 ? i : t;
|
|
635
|
+
let a = "";
|
|
636
|
+
for (const o of r.pairs) {
|
|
637
|
+
for (let c = 0; c < o.from.length; c += 2) {
|
|
638
|
+
const h = kt(o.from[c] + (o.to[c] - o.from[c]) * n), u = kt(o.from[c + 1] + (o.to[c + 1] - o.from[c + 1]) * n);
|
|
639
|
+
a += `${c === 0 ? a ? " M" : "M" : " L"}${h} ${u}`;
|
|
640
|
+
}
|
|
641
|
+
o.closed && (a += " Z");
|
|
642
|
+
}
|
|
643
|
+
return a;
|
|
644
|
+
}
|
|
645
|
+
function Qe(i) {
|
|
646
|
+
return /^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(i);
|
|
647
|
+
}
|
|
648
|
+
const D = (i, t, e) => i + (t - i) * e, Gt = 512, rt = /* @__PURE__ */ new Map(), at = /* @__PURE__ */ new Map();
|
|
649
|
+
function It(i) {
|
|
650
|
+
const t = rt.get(i);
|
|
651
|
+
if (t) return t;
|
|
652
|
+
const e = i.replace("#", ""), s = [
|
|
653
|
+
parseInt(e.slice(0, 2), 16),
|
|
654
|
+
parseInt(e.slice(2, 4), 16),
|
|
655
|
+
parseInt(e.slice(4, 6), 16)
|
|
656
|
+
];
|
|
657
|
+
return rt.size < Gt && rt.set(i, s), s;
|
|
658
|
+
}
|
|
659
|
+
const Rt = (i) => i.charCodeAt(0) === 35, Dt = (i) => i.startsWith("rgb"), Bt = (i) => i.startsWith("rgba"), ze = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/, ot = (i) => Math.round(i).toString(16).padStart(2, "0");
|
|
660
|
+
function Ge(i, t, e) {
|
|
661
|
+
return `#${ot(i)}${ot(t)}${ot(e)}`;
|
|
662
|
+
}
|
|
663
|
+
function Et(i) {
|
|
664
|
+
const t = at.get(i);
|
|
665
|
+
if (t) return t;
|
|
666
|
+
const e = i.match(ze);
|
|
667
|
+
if (!e)
|
|
668
|
+
throw new Error(`Invalid rgb color: ${i}`);
|
|
669
|
+
const s = parseInt(e[1], 10), n = parseInt(e[2], 10), r = parseInt(e[3], 10), a = e[4] !== void 0 ? [s, n, r, parseFloat(e[4])] : [s, n, r];
|
|
670
|
+
return at.size < Gt && at.set(i, a), a;
|
|
671
|
+
}
|
|
672
|
+
const je = (i, t, e) => {
|
|
673
|
+
if (Rt(i) && Rt(t)) {
|
|
674
|
+
const [s, n, r] = It(i), [a, o, c] = It(t), h = D(s, a, e), u = D(n, o, e), l = D(r, c, e);
|
|
675
|
+
return Ge(h, u, l);
|
|
676
|
+
}
|
|
677
|
+
if ((Dt(i) || Bt(i)) && (Dt(t) || Bt(t))) {
|
|
678
|
+
const s = Et(i), n = Et(t), r = Math.round(D(s[0], n[0], e)), a = Math.round(D(s[1], n[1], e)), o = Math.round(D(s[2], n[2], e));
|
|
679
|
+
if (s.length === 4 || n.length === 4) {
|
|
680
|
+
const c = s[3] ?? 1, h = n[3] ?? 1, u = D(c, h, e);
|
|
681
|
+
return `rgba(${r}, ${a}, ${o}, ${u})`;
|
|
682
|
+
}
|
|
683
|
+
return `rgb(${r}, ${a}, ${o})`;
|
|
684
|
+
}
|
|
685
|
+
return e < 1 ? i : t;
|
|
686
|
+
}, Ze = (i, t, e) => {
|
|
687
|
+
const s = Math.min(i.length, t.length), n = [];
|
|
688
|
+
for (let r = 0; r < s; r++)
|
|
689
|
+
n.push(D(i[r], t[r], e));
|
|
690
|
+
return n;
|
|
691
|
+
}, Lt = (i, t, e) => e < 1 ? i : t, Ke = (i, t, e) => He(i, t, e);
|
|
692
|
+
function Je(i) {
|
|
693
|
+
return typeof i == "number" ? D : Array.isArray(i) ? Ze : typeof i == "string" ? i.startsWith("#") || i.startsWith("rgb") ? je : Qe(i) ? Ke : Lt : Lt;
|
|
694
|
+
}
|
|
695
|
+
function ti(i) {
|
|
696
|
+
const t = [...i.keyframes].sort((e, s) => e.time - s.time);
|
|
697
|
+
return {
|
|
698
|
+
...i,
|
|
699
|
+
keyframes: t
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
function $(i) {
|
|
703
|
+
return i.targets && i.targets.length > 0 ? i.targets : [i.target];
|
|
704
|
+
}
|
|
705
|
+
function X(i, t, e, s) {
|
|
706
|
+
const n = e ?? 0;
|
|
707
|
+
return !s || t <= 1 ? n : n + Yt(i, t, s);
|
|
708
|
+
}
|
|
709
|
+
class ct {
|
|
710
|
+
track;
|
|
711
|
+
targets;
|
|
712
|
+
constructor(t) {
|
|
713
|
+
this.track = t, this.targets = $(t);
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Get the interpolated value at a specific time.
|
|
717
|
+
*
|
|
718
|
+
* For a multi-target track this returns the *first* target's value; callers
|
|
719
|
+
* that need every target should use `getTargetValues`.
|
|
720
|
+
*/
|
|
721
|
+
getValueAtTime(t) {
|
|
722
|
+
return this.valueForOffset(t - X(0, this.targets.length, this.track.delay, this.track.stagger));
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Every target's value at a specific time, in target order.
|
|
726
|
+
*
|
|
727
|
+
* Single-target tracks yield one entry; staggered tracks yield one per target,
|
|
728
|
+
* each sampled at its own offset time.
|
|
729
|
+
*/
|
|
730
|
+
getTargetValues(t) {
|
|
731
|
+
const e = this.targets.length, s = [];
|
|
732
|
+
for (let n = 0; n < e; n++) {
|
|
733
|
+
const r = X(n, e, this.track.delay, this.track.stagger), a = this.valueForOffset(t - r);
|
|
734
|
+
a !== void 0 && s.push({ target: this.targets[n], value: a, start: r + this.track.keyframes[0].time });
|
|
735
|
+
}
|
|
736
|
+
return s;
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Get the duration of this track — the last keyframe, plus any delay, the
|
|
740
|
+
* widest stagger offset, and any trailing hold.
|
|
741
|
+
*/
|
|
742
|
+
getDuration() {
|
|
743
|
+
const { keyframes: t } = this.track;
|
|
744
|
+
if (t.length === 0)
|
|
745
|
+
return 0;
|
|
746
|
+
const e = t[t.length - 1].time, s = this.track.stagger ? mt(this.targets.length, this.track.stagger) : 0;
|
|
747
|
+
return e + (this.track.delay ?? 0) + s + (this.track.endDelay ?? 0);
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Get the track metadata.
|
|
751
|
+
*/
|
|
752
|
+
getTrack() {
|
|
753
|
+
return this.track;
|
|
754
|
+
}
|
|
755
|
+
/** Interpolated value at a time already shifted into the track's own frame. */
|
|
756
|
+
valueForOffset(t) {
|
|
757
|
+
const { keyframes: e } = this.track;
|
|
758
|
+
if (e.length === 0)
|
|
759
|
+
return;
|
|
760
|
+
if (e.length === 1 || t <= e[0].time)
|
|
761
|
+
return e[0].value;
|
|
762
|
+
if (t >= e[e.length - 1].time)
|
|
763
|
+
return e[e.length - 1].value;
|
|
764
|
+
const { from: s, to: n } = this.findSurroundingKeyframes(t);
|
|
765
|
+
if (!s || !n)
|
|
766
|
+
return;
|
|
767
|
+
if (s.time === t)
|
|
768
|
+
return s.value;
|
|
769
|
+
const r = n.time - s.time, a = (t - s.time) / r, c = we(n.easing)(a);
|
|
770
|
+
return Je(s.value)(s.value, n.value, c);
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Find the keyframes surrounding a given time.
|
|
774
|
+
*/
|
|
775
|
+
findSurroundingKeyframes(t) {
|
|
776
|
+
const { keyframes: e } = this.track;
|
|
777
|
+
for (let s = 0; s < e.length - 1; s++)
|
|
778
|
+
if (t >= e[s].time && t <= e[s + 1].time)
|
|
779
|
+
return { from: e[s], to: e[s + 1] };
|
|
780
|
+
return { from: null, to: null };
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
class ei {
|
|
784
|
+
track;
|
|
785
|
+
targets;
|
|
786
|
+
sampler;
|
|
787
|
+
constructor(t) {
|
|
788
|
+
this.track = t, this.targets = $(t), this.sampler = new ae(t.spring);
|
|
789
|
+
}
|
|
790
|
+
getValueAtTime(t) {
|
|
791
|
+
return this.sampler.valueAt(t - X(0, this.targets.length, this.track.delay, this.track.stagger));
|
|
792
|
+
}
|
|
793
|
+
getTargetValues(t) {
|
|
794
|
+
const e = this.targets.length, s = [];
|
|
795
|
+
for (let n = 0; n < e; n++) {
|
|
796
|
+
const r = X(n, e, this.track.delay, this.track.stagger);
|
|
797
|
+
s.push({ target: this.targets[n], value: this.sampler.valueAt(t - r), start: r });
|
|
798
|
+
}
|
|
799
|
+
return s;
|
|
800
|
+
}
|
|
801
|
+
/** Settle time plus delay and the widest stagger offset. */
|
|
802
|
+
getDuration() {
|
|
803
|
+
const t = this.track.stagger ? mt(this.targets.length, this.track.stagger) : 0;
|
|
804
|
+
return this.sampler.settleTime() + (this.track.delay ?? 0) + t;
|
|
805
|
+
}
|
|
806
|
+
getTrack() {
|
|
807
|
+
return this.track;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
class ii {
|
|
811
|
+
track;
|
|
812
|
+
targets;
|
|
813
|
+
duration;
|
|
814
|
+
constructor(t) {
|
|
815
|
+
this.track = t, this.targets = $(t), this.duration = Wt(t.inertia);
|
|
816
|
+
}
|
|
817
|
+
getValueAtTime(t) {
|
|
818
|
+
return St(this.track.inertia, t - X(0, this.targets.length, this.track.delay, this.track.stagger));
|
|
819
|
+
}
|
|
820
|
+
getTargetValues(t) {
|
|
821
|
+
const e = this.targets.length, s = [];
|
|
822
|
+
for (let n = 0; n < e; n++) {
|
|
823
|
+
const r = X(n, e, this.track.delay, this.track.stagger);
|
|
824
|
+
s.push({ target: this.targets[n], value: St(this.track.inertia, t - r), start: r });
|
|
825
|
+
}
|
|
826
|
+
return s;
|
|
827
|
+
}
|
|
828
|
+
/** Settle time plus delay and the widest stagger offset. */
|
|
829
|
+
getDuration() {
|
|
830
|
+
const t = this.track.stagger ? mt(this.targets.length, this.track.stagger) : 0;
|
|
831
|
+
return this.duration + (this.track.delay ?? 0) + t;
|
|
832
|
+
}
|
|
833
|
+
getTrack() {
|
|
834
|
+
return this.track;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
function si(i, t) {
|
|
838
|
+
const e = { ...Ee(i.pathData, t) };
|
|
839
|
+
if (i.matrix) {
|
|
840
|
+
const [s, n, r, a, o, c] = i.matrix, { x: h, y: u } = e;
|
|
841
|
+
e.x = s * h + r * u + o, e.y = n * h + a * u + c;
|
|
842
|
+
const l = e.angle * Math.PI / 180, f = Math.cos(l), d = Math.sin(l);
|
|
843
|
+
e.angle = Math.atan2(n * f + a * d, s * f + r * d) * 180 / Math.PI;
|
|
844
|
+
}
|
|
845
|
+
return i.autoRotate && i.rotateOffset && (e.angle += i.rotateOffset), e;
|
|
846
|
+
}
|
|
847
|
+
const ht = {
|
|
848
|
+
upperCase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
849
|
+
lowerCase: "abcdefghijklmnopqrstuvwxyz",
|
|
850
|
+
upperAndLowerCase: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
851
|
+
numbers: "0123456789"
|
|
852
|
+
}, ni = 20;
|
|
853
|
+
function ri(i) {
|
|
854
|
+
const t = ht[i ?? "upperCase"] ?? i ?? ht.upperCase, e = Array.from(t);
|
|
855
|
+
return e.length > 0 ? e : Array.from(ht.upperCase);
|
|
856
|
+
}
|
|
857
|
+
function ai(i, t, e) {
|
|
858
|
+
let s = (i | 0) ^ Math.imul(t + 1, 2654435761) ^ Math.imul(e + 1, 2246822507);
|
|
859
|
+
return s = Math.imul(s ^ s >>> 16, 2146121005), s = Math.imul(s ^ s >>> 15, 2221713035), (s ^ s >>> 16) >>> 0;
|
|
860
|
+
}
|
|
861
|
+
function oi(i, t, e = 0) {
|
|
862
|
+
const s = i.from ?? "", n = i.to, r = Math.max(0, Math.min(1, t));
|
|
863
|
+
if (r <= 0) return s;
|
|
864
|
+
if (r >= 1) return n;
|
|
865
|
+
const a = Array.from(s), o = Array.from(n), c = i.rightToLeft ?? !1;
|
|
866
|
+
if (i.mode === "type") {
|
|
867
|
+
const T = Math.round(r * Math.max(a.length, o.length));
|
|
868
|
+
return c ? a.slice(0, Math.max(0, a.length - T)).join("") + o.slice(Math.max(0, o.length - T)).join("") : o.slice(0, T).join("") + a.slice(T).join("");
|
|
869
|
+
}
|
|
870
|
+
const h = Math.max(0, Math.min(0.999, i.revealDelay ?? 0)), u = Math.max(0, (r - h) / (1 - h)), l = Math.floor(u * o.length), f = i.tweenLength === !1 ? o.length : Math.round(a.length + (o.length - a.length) * r), d = ri(i.chars), b = i.refreshRate ?? ni, p = b > 0 ? Math.floor(e * b / 1e3) : 0, g = i.seed ?? 1;
|
|
871
|
+
let y = "";
|
|
872
|
+
for (let T = 0; T < f; T++) {
|
|
873
|
+
const A = c ? T >= f - l : T < l, _ = c ? o[o.length - (f - T)] : o[T];
|
|
874
|
+
A && _ !== void 0 || _ === " " || _ === `
|
|
875
|
+
` ? y += _ : y += d[ai(g, T, p) % d.length];
|
|
876
|
+
}
|
|
877
|
+
return y;
|
|
878
|
+
}
|
|
879
|
+
class ci {
|
|
880
|
+
id;
|
|
881
|
+
name;
|
|
882
|
+
/** Caption text per language, per marker id */
|
|
883
|
+
captions;
|
|
884
|
+
_tracks = [];
|
|
885
|
+
_trackPlayers = /* @__PURE__ */ new Map();
|
|
886
|
+
_motionPathTracks = /* @__PURE__ */ new Map();
|
|
887
|
+
_springTracks = /* @__PURE__ */ new Map();
|
|
888
|
+
_textTracks = /* @__PURE__ */ new Map();
|
|
889
|
+
_config;
|
|
890
|
+
_currentTime = 0;
|
|
891
|
+
_playbackState = "idle";
|
|
892
|
+
_direction = "forward";
|
|
893
|
+
_loopIteration = 0;
|
|
894
|
+
_explicitDuration;
|
|
895
|
+
/** Milliseconds still to wait at a loop boundary before the next iteration */
|
|
896
|
+
_repeatDelayRemaining = 0;
|
|
897
|
+
/**
|
|
898
|
+
* A forward loop reached its end with a repeat delay armed: the playhead
|
|
899
|
+
* holds on the last frame for the delay, then returns to the start.
|
|
900
|
+
*/
|
|
901
|
+
_wrapAfterDelay = !1;
|
|
902
|
+
onUpdate = null;
|
|
903
|
+
onComplete = null;
|
|
904
|
+
constructor(t) {
|
|
905
|
+
if (this.id = t.id, this.name = t.name, this.captions = t.captions, this._config = t.config ?? {}, this._explicitDuration = t.config?.duration, t.tracks)
|
|
906
|
+
for (const e of t.tracks)
|
|
907
|
+
this.addTrack(e);
|
|
908
|
+
}
|
|
909
|
+
get tracks() {
|
|
910
|
+
return [...this._tracks];
|
|
911
|
+
}
|
|
912
|
+
get duration() {
|
|
913
|
+
return this._explicitDuration !== void 0 ? this._explicitDuration : this._calculateDuration();
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Set an explicit timeline duration (ms). Pass `undefined` to fall back to the
|
|
917
|
+
* duration calculated from the last keyframe across all tracks.
|
|
918
|
+
*/
|
|
919
|
+
setDuration(t) {
|
|
920
|
+
if (this._explicitDuration = t, t !== void 0)
|
|
921
|
+
this._config = { ...this._config, duration: t };
|
|
922
|
+
else if (this._config.duration !== void 0) {
|
|
923
|
+
const e = { ...this._config };
|
|
924
|
+
delete e.duration, this._config = e;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
get currentTime() {
|
|
928
|
+
return this._currentTime;
|
|
929
|
+
}
|
|
930
|
+
get playbackState() {
|
|
931
|
+
return this._playbackState;
|
|
932
|
+
}
|
|
933
|
+
get direction() {
|
|
934
|
+
return this._direction;
|
|
935
|
+
}
|
|
936
|
+
get loopIteration() {
|
|
937
|
+
return this._loopIteration;
|
|
938
|
+
}
|
|
939
|
+
/** Milliseconds of `repeatDelay` still to wait at a loop boundary (0 when not waiting). */
|
|
940
|
+
get repeatDelayRemaining() {
|
|
941
|
+
return this._repeatDelayRemaining;
|
|
942
|
+
}
|
|
943
|
+
get speed() {
|
|
944
|
+
return this._config.speed ?? 1;
|
|
945
|
+
}
|
|
946
|
+
set speed(t) {
|
|
947
|
+
this._config.speed = t;
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Start or resume playback.
|
|
951
|
+
* If at the end and direction is forward, reset to beginning.
|
|
952
|
+
* If at the beginning and direction is reverse, reset to end.
|
|
953
|
+
*/
|
|
954
|
+
play() {
|
|
955
|
+
const t = this.duration;
|
|
956
|
+
this._direction === "forward" && this._currentTime >= t && t > 0 ? (this._currentTime = 0, this._loopIteration = 0) : this._direction === "reverse" && this._currentTime <= 0 && t > 0 && (this._currentTime = t, this._loopIteration = 0), this._playbackState = "playing";
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Pause playback at current position.
|
|
960
|
+
*/
|
|
961
|
+
pause() {
|
|
962
|
+
this._playbackState = "paused";
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* Stop playback and reset to beginning.
|
|
966
|
+
*/
|
|
967
|
+
stop() {
|
|
968
|
+
this._playbackState = "idle", this._repeatDelayRemaining = 0, this._wrapAfterDelay = !1, this._currentTime = 0, this._loopIteration = 0, this._direction = "forward";
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Seek to a specific time.
|
|
972
|
+
*/
|
|
973
|
+
seek(t) {
|
|
974
|
+
const e = this.duration > 0 ? this.duration : 1 / 0;
|
|
975
|
+
this._currentTime = Math.max(0, Math.min(t, e)), this._repeatDelayRemaining = 0, this._wrapAfterDelay = !1;
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* Toggle or set playback direction.
|
|
979
|
+
*/
|
|
980
|
+
reverse() {
|
|
981
|
+
this._direction = this._direction === "forward" ? "reverse" : "forward";
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Advance the timeline by delta milliseconds.
|
|
985
|
+
* Call this from your animation loop or clock.
|
|
986
|
+
*/
|
|
987
|
+
tick(t) {
|
|
988
|
+
if (this._playbackState !== "playing")
|
|
989
|
+
return;
|
|
990
|
+
const e = this.duration;
|
|
991
|
+
if (e <= 0)
|
|
992
|
+
return;
|
|
993
|
+
let n = t * this.speed;
|
|
994
|
+
if (this._repeatDelayRemaining > 0) {
|
|
995
|
+
const o = Math.min(this._repeatDelayRemaining, n);
|
|
996
|
+
if (this._repeatDelayRemaining -= o, n -= o, this._repeatDelayRemaining > 0) {
|
|
997
|
+
this.onUpdate?.(this.getStateAtTime(this._currentTime));
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
this._wrapAfterDelay && (this._wrapAfterDelay = !1, this._currentTime = 0);
|
|
1001
|
+
}
|
|
1002
|
+
const r = 1e3;
|
|
1003
|
+
for (let o = 0; o < r && n > 0 && this._playbackState === "playing"; o++)
|
|
1004
|
+
if (this._direction === "forward") {
|
|
1005
|
+
const c = e - this._currentTime;
|
|
1006
|
+
if (n >= c) {
|
|
1007
|
+
if (n -= c, this._currentTime = e, !this._handleEndReached())
|
|
1008
|
+
break;
|
|
1009
|
+
} else
|
|
1010
|
+
this._currentTime += n, n = 0;
|
|
1011
|
+
} else {
|
|
1012
|
+
const c = this._currentTime;
|
|
1013
|
+
if (n >= c) {
|
|
1014
|
+
if (n -= c, this._currentTime = 0, !this._handleStartReached())
|
|
1015
|
+
break;
|
|
1016
|
+
} else
|
|
1017
|
+
this._currentTime -= n, n = 0;
|
|
1018
|
+
}
|
|
1019
|
+
const a = this.getStateAtTime(this._currentTime);
|
|
1020
|
+
this.onUpdate?.(a);
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Get the animation state at a specific time.
|
|
1024
|
+
*/
|
|
1025
|
+
getStateAtTime(t) {
|
|
1026
|
+
const e = /* @__PURE__ */ new Map();
|
|
1027
|
+
if (this._hasSharedWrites())
|
|
1028
|
+
this._resolveShared(t, e);
|
|
1029
|
+
else
|
|
1030
|
+
for (const [s, n] of this._trackPlayers) {
|
|
1031
|
+
const r = n.getTrack().property;
|
|
1032
|
+
for (const { target: a, value: o, start: c } of n.getTargetValues(t))
|
|
1033
|
+
this._write(e, s, a, r, o, t - c);
|
|
1034
|
+
}
|
|
1035
|
+
return {
|
|
1036
|
+
values: e,
|
|
1037
|
+
currentTime: this._currentTime,
|
|
1038
|
+
playbackState: this._playbackState,
|
|
1039
|
+
direction: this._direction,
|
|
1040
|
+
loopIteration: this._loopIteration
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Several tracks drive the same target+property. Which one applies at `time`:
|
|
1045
|
+
*
|
|
1046
|
+
* 1. Of the tracks that have started (their first keyframe, plus delay and
|
|
1047
|
+
* stagger, is at or before `time`), the one that started LAST.
|
|
1048
|
+
* 2. If none has started yet, the one that starts FIRST — so the value before
|
|
1049
|
+
* anything plays is the first animation's starting value.
|
|
1050
|
+
* 3. Ties on start time go to the track added LAST.
|
|
1051
|
+
*
|
|
1052
|
+
* This is what makes a sequence of tweens on one property play as a sequence:
|
|
1053
|
+
* a later tween holds its starting value, but does not apply it until its
|
|
1054
|
+
* turn. `findConflicts()` reports overlaps by the same rule.
|
|
1055
|
+
*/
|
|
1056
|
+
_resolveShared(t, e) {
|
|
1057
|
+
const s = /* @__PURE__ */ new Map();
|
|
1058
|
+
for (const [n, r] of this._trackPlayers) {
|
|
1059
|
+
const a = r.getTrack().property;
|
|
1060
|
+
for (const { target: o, value: c, start: h } of r.getTargetValues(t)) {
|
|
1061
|
+
const u = `${o}\0${a}`, l = h <= t, f = s.get(u);
|
|
1062
|
+
(!f || (l !== f.started ? l : l ? h >= f.start : h <= f.start)) && s.set(u, { trackId: n, target: o, property: a, value: c, start: h, started: l });
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
for (const { trackId: n, target: r, property: a, value: o, start: c } of s.values())
|
|
1066
|
+
this._write(e, n, r, a, o, t - c);
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Write one track's value for a target, expanding the progress of motion paths
|
|
1070
|
+
* (into x/y/rotation) and text tracks (into the string). `elapsed` is the time
|
|
1071
|
+
* since this target's animation on the track started.
|
|
1072
|
+
*/
|
|
1073
|
+
_write(t, e, s, n, r, a) {
|
|
1074
|
+
if (r === void 0) return;
|
|
1075
|
+
let o = t.get(s);
|
|
1076
|
+
o || (o = /* @__PURE__ */ new Map(), t.set(s, o));
|
|
1077
|
+
const c = this._textTracks.get(e);
|
|
1078
|
+
if (c && typeof r == "number") {
|
|
1079
|
+
o.set("text", oi(c.textConfig, r, Math.max(0, a)));
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
const h = this._motionPathTracks.get(e);
|
|
1083
|
+
if (h && typeof r == "number") {
|
|
1084
|
+
const u = si(h.motionPathConfig, r);
|
|
1085
|
+
o.set("motionPathX", u.x), o.set("motionPathY", u.y), h.motionPathConfig.autoRotate && o.set("motionPathRotate", u.angle);
|
|
1086
|
+
} else
|
|
1087
|
+
o.set(n, r);
|
|
1088
|
+
}
|
|
1089
|
+
/** Cached: does any target+property have more than one track? */
|
|
1090
|
+
_sharedWrites = null;
|
|
1091
|
+
_hasSharedWrites() {
|
|
1092
|
+
if (this._sharedWrites === null) {
|
|
1093
|
+
const t = /* @__PURE__ */ new Set();
|
|
1094
|
+
this._sharedWrites = !1;
|
|
1095
|
+
t: for (const e of this._tracks)
|
|
1096
|
+
for (const s of $(e)) {
|
|
1097
|
+
const n = `${s}\0${e.property}`;
|
|
1098
|
+
if (t.has(n)) {
|
|
1099
|
+
this._sharedWrites = !0;
|
|
1100
|
+
break t;
|
|
1101
|
+
}
|
|
1102
|
+
t.add(n);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
return this._sharedWrites;
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Add a track to the timeline.
|
|
1109
|
+
*/
|
|
1110
|
+
addTrack(t) {
|
|
1111
|
+
if (this._tracks.push(t), this._sharedWrites = null, ut(t)) {
|
|
1112
|
+
this._trackPlayers.set(t.id, new ii(t));
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
if (ft(t)) {
|
|
1116
|
+
this._trackPlayers.set(t.id, new ei(t)), this._springTracks.set(t.id, t);
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
if (Xt(t))
|
|
1120
|
+
this._trackPlayers.set(t.id, new ct(t)), this._textTracks.set(t.id, t);
|
|
1121
|
+
else if (se(t)) {
|
|
1122
|
+
const e = {
|
|
1123
|
+
id: t.id,
|
|
1124
|
+
target: t.target,
|
|
1125
|
+
property: t.property,
|
|
1126
|
+
keyframes: t.keyframes,
|
|
1127
|
+
delay: t.delay,
|
|
1128
|
+
endDelay: t.endDelay,
|
|
1129
|
+
targets: t.targets,
|
|
1130
|
+
stagger: t.stagger
|
|
1131
|
+
};
|
|
1132
|
+
this._trackPlayers.set(t.id, new ct(e)), this._motionPathTracks.set(t.id, t);
|
|
1133
|
+
} else
|
|
1134
|
+
this._trackPlayers.set(t.id, new ct(t));
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* Replace a track with a new version, keeping its place in the track order
|
|
1138
|
+
* (which decides ties when tracks overlap). The new track may have a
|
|
1139
|
+
* different id. Does nothing if no track has `trackId`.
|
|
1140
|
+
*/
|
|
1141
|
+
replaceTrack(t, e) {
|
|
1142
|
+
const s = this._tracks.findIndex((r) => r.id === t);
|
|
1143
|
+
if (s < 0) return;
|
|
1144
|
+
const n = this._tracks.slice(s + 1);
|
|
1145
|
+
this.removeTrack(t);
|
|
1146
|
+
for (const r of n) this.removeTrack(r.id);
|
|
1147
|
+
this.addTrack(e);
|
|
1148
|
+
for (const r of n) this.addTrack(r);
|
|
1149
|
+
}
|
|
1150
|
+
/**
|
|
1151
|
+
* Remove a track by its ID.
|
|
1152
|
+
*/
|
|
1153
|
+
removeTrack(t) {
|
|
1154
|
+
this._tracks = this._tracks.filter((e) => e.id !== t), this._sharedWrites = null, this._trackPlayers.delete(t), this._motionPathTracks.delete(t), this._springTracks.delete(t), this._textTracks.delete(t);
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Tracks matching a filter. All provided fields must match (AND).
|
|
1158
|
+
*
|
|
1159
|
+
* This is the closest principled equivalent to GSAP's per-tween handle: we
|
|
1160
|
+
* have no live tween objects to hold, so a "tween" is addressed by describing
|
|
1161
|
+
* the tracks it produced.
|
|
1162
|
+
*/
|
|
1163
|
+
getTracks(t = {}) {
|
|
1164
|
+
return this._tracks.filter((e) => this._matches(e, t));
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Remove every track matching a filter. Returns the ids removed.
|
|
1168
|
+
*
|
|
1169
|
+
* `timeline.removeTracks({ target: 'box' })` is the equivalent of killing all
|
|
1170
|
+
* tweens on an element.
|
|
1171
|
+
*/
|
|
1172
|
+
removeTracks(t = {}) {
|
|
1173
|
+
const e = this.getTracks(t).map((s) => s.id);
|
|
1174
|
+
for (const s of e)
|
|
1175
|
+
this.removeTrack(s);
|
|
1176
|
+
return e;
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* The time span a track is active over: [start, end] in milliseconds.
|
|
1180
|
+
*/
|
|
1181
|
+
getTrackSpan(t) {
|
|
1182
|
+
const e = this._trackPlayers.get(t);
|
|
1183
|
+
if (!e) return;
|
|
1184
|
+
const s = e.getTrack(), n = s.delay ?? 0;
|
|
1185
|
+
if (ft(s) || ut(s))
|
|
1186
|
+
return { from: n, to: e.getDuration() };
|
|
1187
|
+
const r = s.keyframes;
|
|
1188
|
+
if (!(!r || r.length === 0))
|
|
1189
|
+
return { from: r[0].time + n, to: e.getDuration() };
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* Overlapping writes to the same target+property.
|
|
1193
|
+
*
|
|
1194
|
+
* Where two spans overlap, the track that starts later wins from the moment it
|
|
1195
|
+
* starts (ties: the one added later) — see `_resolveShared`. That is
|
|
1196
|
+
* predictable but silent, so an authoring tool should call this and warn,
|
|
1197
|
+
* because a silently discarded stretch of a track looks like a bug.
|
|
1198
|
+
*/
|
|
1199
|
+
findConflicts() {
|
|
1200
|
+
const t = [];
|
|
1201
|
+
for (let e = 0; e < this._tracks.length; e++) {
|
|
1202
|
+
const s = this._tracks[e], n = this.getTrackSpan(s.id);
|
|
1203
|
+
if (n)
|
|
1204
|
+
for (let r = 0; r < e; r++) {
|
|
1205
|
+
const a = this._tracks[r];
|
|
1206
|
+
if (a.property !== s.property) continue;
|
|
1207
|
+
const o = $(a).filter((l) => $(s).includes(l));
|
|
1208
|
+
if (o.length === 0) continue;
|
|
1209
|
+
const c = this.getTrackSpan(a.id);
|
|
1210
|
+
if (!c || !(c.from <= n.to && n.from <= c.to)) continue;
|
|
1211
|
+
const u = n.from >= c.from;
|
|
1212
|
+
for (const l of o)
|
|
1213
|
+
t.push({
|
|
1214
|
+
target: l,
|
|
1215
|
+
property: s.property,
|
|
1216
|
+
losingTrackId: u ? a.id : s.id,
|
|
1217
|
+
winningTrackId: u ? s.id : a.id
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
return t;
|
|
1222
|
+
}
|
|
1223
|
+
_matches(t, e) {
|
|
1224
|
+
if (e.id !== void 0 && t.id !== e.id || e.property !== void 0 && t.property !== e.property || e.target !== void 0 && !$(t).includes(e.target)) return !1;
|
|
1225
|
+
if (e.timeRange) {
|
|
1226
|
+
const s = this.getTrackSpan(t.id);
|
|
1227
|
+
if (!s || s.to < e.timeRange.from || s.from > e.timeRange.to) return !1;
|
|
1228
|
+
}
|
|
1229
|
+
return !0;
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Export timeline as a serializable definition.
|
|
1233
|
+
*/
|
|
1234
|
+
toDefinition() {
|
|
1235
|
+
return {
|
|
1236
|
+
formatVersion: lt,
|
|
1237
|
+
id: this.id,
|
|
1238
|
+
name: this.name,
|
|
1239
|
+
config: { ...this._config },
|
|
1240
|
+
tracks: [...this._tracks],
|
|
1241
|
+
...this.captions && { captions: this.captions }
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1244
|
+
/** The playback configuration, as loaded (read-only). */
|
|
1245
|
+
get config() {
|
|
1246
|
+
return this._config;
|
|
1247
|
+
}
|
|
1248
|
+
/** The timeline's markers, in time order (empty when it has none). */
|
|
1249
|
+
get markers() {
|
|
1250
|
+
return [...this._config.markers ?? []].sort((t, e) => t.time - e.time);
|
|
1251
|
+
}
|
|
1252
|
+
/** Start the between-iterations pause, if the timeline configures one. */
|
|
1253
|
+
_armRepeatDelay() {
|
|
1254
|
+
this._repeatDelayRemaining = this._config.repeatDelay ?? 0;
|
|
1255
|
+
}
|
|
1256
|
+
_calculateDuration() {
|
|
1257
|
+
let t = 0;
|
|
1258
|
+
for (const [, e] of this._trackPlayers)
|
|
1259
|
+
t = Math.max(t, e.getDuration());
|
|
1260
|
+
return t;
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Handle reaching the end of the timeline.
|
|
1264
|
+
* Returns true if we looped and should continue, false if we stopped.
|
|
1265
|
+
*/
|
|
1266
|
+
_handleEndReached() {
|
|
1267
|
+
const t = this._config.loop ?? 0;
|
|
1268
|
+
return t === -1 || this._loopIteration < t ? (this._loopIteration++, this._armRepeatDelay(), this._config.alternate ? this._direction = "reverse" : this._repeatDelayRemaining > 0 ? this._wrapAfterDelay = !0 : this._currentTime = 0, this._repeatDelayRemaining === 0) : (this._playbackState = "idle", this.onComplete?.(), !1);
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Handle reaching the start of the timeline (in reverse).
|
|
1272
|
+
* Returns true if we looped and should continue, false if we stopped.
|
|
1273
|
+
*/
|
|
1274
|
+
_handleStartReached() {
|
|
1275
|
+
const t = this._config.loop ?? 0;
|
|
1276
|
+
return this._config.alternate && (t === -1 || this._loopIteration < t) ? (this._loopIteration++, this._armRepeatDelay(), this._direction = "forward", this._repeatDelayRemaining === 0) : (this._playbackState = "idle", this.onComplete?.(), !1);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
const hi = 100;
|
|
1280
|
+
function li(i, t, e, s) {
|
|
1281
|
+
const n = [], r = [], { duration: a, alternate: o } = s, c = (d, b, p, g) => {
|
|
1282
|
+
r.push([d, b]);
|
|
1283
|
+
const y = [];
|
|
1284
|
+
i.forEach((T, A) => {
|
|
1285
|
+
(p === "forward" ? (g ? T >= d : T > d) && T <= b : (g ? T <= d : T < d) && T >= b) && y.push(A);
|
|
1286
|
+
}), y.sort((T, A) => (p === "forward" ? i[T] - i[A] : i[A] - i[T]) || T - A);
|
|
1287
|
+
for (const T of y) n.push({ kind: "event", index: T, direction: p });
|
|
1288
|
+
};
|
|
1289
|
+
let h = t.time, u = t.direction, l = t.fresh === !0;
|
|
1290
|
+
const f = Math.min(hi, Math.max(0, e.iteration - t.iteration));
|
|
1291
|
+
for (let d = 0; d < f; d++) {
|
|
1292
|
+
const b = u === "forward" ? a : 0;
|
|
1293
|
+
c(h, b, u, l), n.push({ kind: "repeat" }), o ? (u = u === "forward" ? "reverse" : "forward", h = b, l = !1) : (h = u === "forward" ? 0 : a, l = !0);
|
|
1294
|
+
}
|
|
1295
|
+
return f > 0 && s.holding && !o ? { crossings: n, passes: r } : (c(h, e.time, u, l), { crossings: n, passes: r });
|
|
1296
|
+
}
|
|
1297
|
+
function ui(i) {
|
|
1298
|
+
return { ...i, ...Array.isArray(i.end) && { end: [...i.end] } };
|
|
1299
|
+
}
|
|
1300
|
+
function W(i) {
|
|
1301
|
+
const t = i.endDelay;
|
|
1302
|
+
return {
|
|
1303
|
+
...i.delay !== void 0 && { delay: i.delay },
|
|
1304
|
+
...t !== void 0 && { endDelay: t },
|
|
1305
|
+
...i.targets !== void 0 && { targets: [...i.targets] },
|
|
1306
|
+
...i.stagger !== void 0 && { stagger: { ...i.stagger } }
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
function fi(i) {
|
|
1310
|
+
if (ut(i)) {
|
|
1311
|
+
const t = i;
|
|
1312
|
+
return {
|
|
1313
|
+
id: t.id,
|
|
1314
|
+
target: t.target,
|
|
1315
|
+
property: t.property,
|
|
1316
|
+
kind: "inertia",
|
|
1317
|
+
inertia: ui(t.inertia),
|
|
1318
|
+
...W(t)
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
if (ft(i)) {
|
|
1322
|
+
const t = i;
|
|
1323
|
+
return {
|
|
1324
|
+
id: t.id,
|
|
1325
|
+
target: t.target,
|
|
1326
|
+
property: t.property,
|
|
1327
|
+
kind: "spring",
|
|
1328
|
+
spring: { ...t.spring },
|
|
1329
|
+
...W(t)
|
|
1330
|
+
};
|
|
1331
|
+
}
|
|
1332
|
+
if (Xt(i)) {
|
|
1333
|
+
const t = i;
|
|
1334
|
+
return {
|
|
1335
|
+
id: t.id,
|
|
1336
|
+
target: t.target,
|
|
1337
|
+
property: "text",
|
|
1338
|
+
textConfig: { ...t.textConfig },
|
|
1339
|
+
keyframes: [...t.keyframes].sort((e, s) => e.time - s.time),
|
|
1340
|
+
...W(t)
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
if (i.property === "motionPath" && "motionPathConfig" in i) {
|
|
1344
|
+
const t = i, e = [...t.keyframes].sort((s, n) => s.time - n.time);
|
|
1345
|
+
return {
|
|
1346
|
+
id: t.id,
|
|
1347
|
+
target: t.target,
|
|
1348
|
+
property: "motionPath",
|
|
1349
|
+
motionPathConfig: { ...t.motionPathConfig },
|
|
1350
|
+
keyframes: e,
|
|
1351
|
+
...W(t)
|
|
1352
|
+
};
|
|
1353
|
+
}
|
|
1354
|
+
return ti({
|
|
1355
|
+
id: i.id,
|
|
1356
|
+
target: i.target,
|
|
1357
|
+
property: i.property,
|
|
1358
|
+
keyframes: i.keyframes,
|
|
1359
|
+
...W(i)
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
function tt(i) {
|
|
1363
|
+
const t = i.formatVersion ?? 1;
|
|
1364
|
+
if (t > lt)
|
|
1365
|
+
throw new Error(
|
|
1366
|
+
`tinyfly: this animation uses format version ${t}, but this tinyfly reads up to version ${lt}. Update tinyfly to play it.`
|
|
1367
|
+
);
|
|
1368
|
+
return new ci({
|
|
1369
|
+
id: i.id,
|
|
1370
|
+
name: i.name,
|
|
1371
|
+
config: i.config,
|
|
1372
|
+
tracks: i.tracks.map(fi),
|
|
1373
|
+
captions: i.captions
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
const di = /* @__PURE__ */ new Set([
|
|
1377
|
+
"blur",
|
|
1378
|
+
"brightness",
|
|
1379
|
+
"glow",
|
|
1380
|
+
"glowColor",
|
|
1381
|
+
"shadowX",
|
|
1382
|
+
"shadowY",
|
|
1383
|
+
"shadowBlur",
|
|
1384
|
+
"shadowColor"
|
|
1385
|
+
]), pi = "#ffffff", mi = "rgba(0, 0, 0, 0.5)";
|
|
1386
|
+
function gi(i) {
|
|
1387
|
+
const t = [];
|
|
1388
|
+
if (i.blur !== void 0 && t.push(`blur(${Math.max(0, i.blur)}px)`), i.brightness !== void 0 && t.push(`brightness(${Math.max(0, i.brightness)})`), i.glow !== void 0 && t.push(`drop-shadow(0 0 ${Math.max(0, i.glow)}px ${i.glowColor ?? pi})`), i.shadowX !== void 0 || i.shadowY !== void 0 || i.shadowBlur !== void 0) {
|
|
1389
|
+
const e = i.shadowX ?? 0, s = i.shadowY ?? 0, n = Math.max(0, i.shadowBlur ?? 0);
|
|
1390
|
+
t.push(`drop-shadow(${e}px ${s}px ${n}px ${i.shadowColor ?? mi})`);
|
|
1391
|
+
}
|
|
1392
|
+
return t.length > 0 ? t.join(" ") : null;
|
|
1393
|
+
}
|
|
1394
|
+
function yi(i, t) {
|
|
1395
|
+
const e = i.childNodes.length === 1 ? i.firstChild : null;
|
|
1396
|
+
if (e && e.nodeType === 3) {
|
|
1397
|
+
const s = e;
|
|
1398
|
+
s.data !== t && (s.data = t);
|
|
1399
|
+
return;
|
|
1400
|
+
}
|
|
1401
|
+
i.textContent !== t && (i.textContent = t);
|
|
1402
|
+
}
|
|
1403
|
+
function Ti(i) {
|
|
1404
|
+
if (!("ownerSVGElement" in i)) return;
|
|
1405
|
+
const t = i.style;
|
|
1406
|
+
!t || t.transformBox || (t.transformBox = "fill-box", t.transformOrigin || (t.transformOrigin = "50% 50%"));
|
|
1407
|
+
}
|
|
1408
|
+
const $t = /* @__PURE__ */ new Set([
|
|
1409
|
+
"width",
|
|
1410
|
+
"height",
|
|
1411
|
+
"top",
|
|
1412
|
+
"right",
|
|
1413
|
+
"bottom",
|
|
1414
|
+
"left",
|
|
1415
|
+
"margin",
|
|
1416
|
+
"marginTop",
|
|
1417
|
+
"marginRight",
|
|
1418
|
+
"marginBottom",
|
|
1419
|
+
"marginLeft",
|
|
1420
|
+
"padding",
|
|
1421
|
+
"paddingTop",
|
|
1422
|
+
"paddingRight",
|
|
1423
|
+
"paddingBottom",
|
|
1424
|
+
"paddingLeft",
|
|
1425
|
+
"borderRadius",
|
|
1426
|
+
"borderWidth",
|
|
1427
|
+
"fontSize",
|
|
1428
|
+
"lineHeight",
|
|
1429
|
+
"letterSpacing",
|
|
1430
|
+
"outlineWidth",
|
|
1431
|
+
"gap",
|
|
1432
|
+
"rowGap",
|
|
1433
|
+
"columnGap"
|
|
1434
|
+
]), bi = /* @__PURE__ */ new Set([
|
|
1435
|
+
"x",
|
|
1436
|
+
"y",
|
|
1437
|
+
"z",
|
|
1438
|
+
"rotate",
|
|
1439
|
+
"rotateX",
|
|
1440
|
+
"rotateY",
|
|
1441
|
+
"rotateZ",
|
|
1442
|
+
"scale",
|
|
1443
|
+
"scaleX",
|
|
1444
|
+
"scaleY",
|
|
1445
|
+
"scaleZ",
|
|
1446
|
+
"skewX",
|
|
1447
|
+
"skewY",
|
|
1448
|
+
// Motion path properties
|
|
1449
|
+
"motionPathX",
|
|
1450
|
+
"motionPathY",
|
|
1451
|
+
"motionPathRotate"
|
|
1452
|
+
]), Ai = /* @__PURE__ */ new Set(["originX", "originY"]), Si = /* @__PURE__ */ new Set(["clipTop", "clipRight", "clipBottom", "clipLeft"]), _i = {
|
|
1453
|
+
fill: "backgroundColor",
|
|
1454
|
+
stroke: "borderColor",
|
|
1455
|
+
strokeWidth: "borderWidth",
|
|
1456
|
+
color: "color",
|
|
1457
|
+
backgroundColor: "backgroundColor",
|
|
1458
|
+
borderColor: "borderColor"
|
|
1459
|
+
}, Ot = {
|
|
1460
|
+
fill: "fill",
|
|
1461
|
+
stroke: "stroke",
|
|
1462
|
+
strokeWidth: "strokeWidth",
|
|
1463
|
+
strokeDasharray: "strokeDasharray",
|
|
1464
|
+
strokeDashoffset: "strokeDashoffset",
|
|
1465
|
+
fillOpacity: "fillOpacity",
|
|
1466
|
+
strokeOpacity: "strokeOpacity"
|
|
1467
|
+
}, Mi = "http://www.w3.org/2000/svg";
|
|
1468
|
+
class H {
|
|
1469
|
+
targets = /* @__PURE__ */ new Map();
|
|
1470
|
+
/**
|
|
1471
|
+
* Register an HTML element as an animation target.
|
|
1472
|
+
*/
|
|
1473
|
+
registerTarget(t, e) {
|
|
1474
|
+
this.targets.set(t, e);
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* Unregister a target by its ID.
|
|
1478
|
+
*/
|
|
1479
|
+
unregisterTarget(t) {
|
|
1480
|
+
this.targets.delete(t);
|
|
1481
|
+
}
|
|
1482
|
+
/**
|
|
1483
|
+
* Get a registered target element.
|
|
1484
|
+
*/
|
|
1485
|
+
getTarget(t) {
|
|
1486
|
+
return this.targets.get(t);
|
|
1487
|
+
}
|
|
1488
|
+
/**
|
|
1489
|
+
* Clear all registered targets.
|
|
1490
|
+
*/
|
|
1491
|
+
clearTargets() {
|
|
1492
|
+
this.targets.clear();
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* Apply animation state to all registered targets.
|
|
1496
|
+
*/
|
|
1497
|
+
applyState(t) {
|
|
1498
|
+
for (const [e, s] of t.values) {
|
|
1499
|
+
const n = this.targets.get(e);
|
|
1500
|
+
n && this.applyProperties(n, s);
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
/**
|
|
1504
|
+
* Apply properties to a single element.
|
|
1505
|
+
*/
|
|
1506
|
+
applyProperties(t, e) {
|
|
1507
|
+
const s = [];
|
|
1508
|
+
let n = null, r = null, a = null;
|
|
1509
|
+
const o = e.has("motionPathX"), c = e.has("motionPathY"), h = e.has("motionPathRotate");
|
|
1510
|
+
for (const [f, d] of e)
|
|
1511
|
+
if (!(f === "x" && o) && !(f === "y" && c) && !((f === "rotate" || f === "rotateZ") && h)) {
|
|
1512
|
+
if (bi.has(f)) {
|
|
1513
|
+
const b = this.buildTransformPart(f, d);
|
|
1514
|
+
b && s.push(b);
|
|
1515
|
+
} else if (Ai.has(f))
|
|
1516
|
+
typeof d == "number" && ((n ??= {})[f] = d);
|
|
1517
|
+
else if (Si.has(f))
|
|
1518
|
+
typeof d == "number" && ((r ??= {})[f] = d);
|
|
1519
|
+
else if (di.has(f))
|
|
1520
|
+
(a ??= {})[f] = d;
|
|
1521
|
+
else if (f !== "perspective") {
|
|
1522
|
+
if (f !== "shine") if (f === "text" && typeof d == "string")
|
|
1523
|
+
yi(t, d);
|
|
1524
|
+
else if (f === "d" && typeof d == "string") {
|
|
1525
|
+
const b = t;
|
|
1526
|
+
(b.tagName?.toLowerCase() === "path" ? b : b.querySelector?.("path"))?.setAttribute?.("d", d);
|
|
1527
|
+
} else
|
|
1528
|
+
this.applyStyleProperty(t, f, d);
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
const u = e.get("shine");
|
|
1532
|
+
typeof u == "number" && this.applyShine(t, u);
|
|
1533
|
+
const l = e.get("perspective");
|
|
1534
|
+
if (typeof l == "number" && s.unshift(`perspective(${l}px)`), s.length > 0 && (t.style.transform = s.join(" "), Ti(t)), n) {
|
|
1535
|
+
const f = n.originX ?? 50, d = n.originY ?? 50;
|
|
1536
|
+
t.style.transformOrigin = `${f}% ${d}%`;
|
|
1537
|
+
}
|
|
1538
|
+
if (r) {
|
|
1539
|
+
const f = r.clipTop ?? 0, d = r.clipRight ?? 0, b = r.clipBottom ?? 0, p = r.clipLeft ?? 0;
|
|
1540
|
+
t.style.clipPath = `inset(${f}% ${d}% ${b}% ${p}%)`;
|
|
1541
|
+
}
|
|
1542
|
+
if (a) {
|
|
1543
|
+
const f = gi(a);
|
|
1544
|
+
f && (t.style.filter = f);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Build a transform function string for a property.
|
|
1549
|
+
*/
|
|
1550
|
+
buildTransformPart(t, e) {
|
|
1551
|
+
if (typeof e != "number") return null;
|
|
1552
|
+
switch (t) {
|
|
1553
|
+
case "x":
|
|
1554
|
+
case "motionPathX":
|
|
1555
|
+
return `translateX(${e}px)`;
|
|
1556
|
+
case "y":
|
|
1557
|
+
case "motionPathY":
|
|
1558
|
+
return `translateY(${e}px)`;
|
|
1559
|
+
case "z":
|
|
1560
|
+
return `translateZ(${e}px)`;
|
|
1561
|
+
case "rotate":
|
|
1562
|
+
case "rotateZ":
|
|
1563
|
+
case "motionPathRotate":
|
|
1564
|
+
return `rotate(${e}deg)`;
|
|
1565
|
+
case "rotateX":
|
|
1566
|
+
return `rotateX(${e}deg)`;
|
|
1567
|
+
case "rotateY":
|
|
1568
|
+
return `rotateY(${e}deg)`;
|
|
1569
|
+
case "scale":
|
|
1570
|
+
return `scale(${e})`;
|
|
1571
|
+
case "scaleX":
|
|
1572
|
+
return `scaleX(${e})`;
|
|
1573
|
+
case "scaleY":
|
|
1574
|
+
return `scaleY(${e})`;
|
|
1575
|
+
case "scaleZ":
|
|
1576
|
+
return `scaleZ(${e})`;
|
|
1577
|
+
case "skewX":
|
|
1578
|
+
return `skewX(${e}deg)`;
|
|
1579
|
+
case "skewY":
|
|
1580
|
+
return `skewY(${e}deg)`;
|
|
1581
|
+
default:
|
|
1582
|
+
return null;
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
* Apply a shine sweep to a (text) element.
|
|
1587
|
+
*
|
|
1588
|
+
* `progress` runs 0..1 as the highlight travels from just off the left edge to
|
|
1589
|
+
* just off the right. Two layered, text-clipped gradients are used: a moving
|
|
1590
|
+
* white highlight band on top of a solid layer of the element's base colour,
|
|
1591
|
+
* so the text stays visible while the sheen passes over the glyphs.
|
|
1592
|
+
*/
|
|
1593
|
+
applyShine(t, e) {
|
|
1594
|
+
t.dataset.shineBase || (t.dataset.shineBase = t.style.color || "currentColor");
|
|
1595
|
+
const s = t.dataset.shineBase, n = -20 + e * 140, r = t.style;
|
|
1596
|
+
r.color = "transparent", r.backgroundImage = `linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${s}, ${s})`, r.backgroundSize = "250% 100%, 100% 100%", r.backgroundPosition = `${n}% 0, 0 0`, r.backgroundRepeat = "no-repeat", r.webkitBackgroundClip = "text", r.backgroundClip = "text";
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* Apply a single style property to an element.
|
|
1600
|
+
*/
|
|
1601
|
+
applyStyleProperty(t, e, s) {
|
|
1602
|
+
let n;
|
|
1603
|
+
if (t.namespaceURI === Mi && e in Ot) {
|
|
1604
|
+
const o = Array.isArray(s) ? s.join(", ") : String(s);
|
|
1605
|
+
t.style[Ot[e]] = o;
|
|
1606
|
+
return;
|
|
1607
|
+
} else e === "fill" && t.dataset?.elementType === "text" ? n = "color" : n = _i[e] ?? e;
|
|
1608
|
+
let a;
|
|
1609
|
+
typeof s == "number" ? $t.has(e) || $t.has(n) ? a = `${s}px` : a = String(s) : Array.isArray(s) ? a = s.join(", ") : a = s, t.style[n] = a;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
class Ft {
|
|
1613
|
+
media;
|
|
1614
|
+
offset;
|
|
1615
|
+
driftTolerance;
|
|
1616
|
+
constructor(t, e = {}) {
|
|
1617
|
+
this.media = t, this.offset = e.offset ?? 0, this.driftTolerance = Math.max(0, e.driftTolerance ?? 0.15);
|
|
1618
|
+
}
|
|
1619
|
+
/** Map a timeline time (ms) to the media's time (seconds), never negative. */
|
|
1620
|
+
targetTime(t) {
|
|
1621
|
+
return Math.max(0, t / 1e3 + this.offset);
|
|
1622
|
+
}
|
|
1623
|
+
/**
|
|
1624
|
+
* Reconcile the media with the timeline for the current frame.
|
|
1625
|
+
*
|
|
1626
|
+
* @param timelineTimeMs current timeline time in milliseconds
|
|
1627
|
+
* @param isPlaying whether the timeline is playing
|
|
1628
|
+
*/
|
|
1629
|
+
update(t, e) {
|
|
1630
|
+
const s = this.targetTime(t);
|
|
1631
|
+
e ? (this.media.paused && this.safePlay(), Math.abs(this.media.currentTime - s) > this.driftTolerance && (this.media.currentTime = s)) : (this.media.paused || this.media.pause(), this.media.currentTime !== s && (this.media.currentTime = s));
|
|
1632
|
+
}
|
|
1633
|
+
/** Hard-align the media to a timeline time (used on explicit seeks). */
|
|
1634
|
+
seek(t) {
|
|
1635
|
+
this.media.currentTime = this.targetTime(t);
|
|
1636
|
+
}
|
|
1637
|
+
/** Mirror the timeline playback rate onto the media. */
|
|
1638
|
+
setRate(t) {
|
|
1639
|
+
this.media.playbackRate = t;
|
|
1640
|
+
}
|
|
1641
|
+
/** Pause the media and release it. */
|
|
1642
|
+
dispose() {
|
|
1643
|
+
this.media.paused || this.media.pause();
|
|
1644
|
+
}
|
|
1645
|
+
safePlay() {
|
|
1646
|
+
const t = this.media.play();
|
|
1647
|
+
t && typeof t.catch == "function" && t.catch(() => {
|
|
1648
|
+
});
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
function ki(i, t, e, s, n) {
|
|
1652
|
+
const r = e - n;
|
|
1653
|
+
if (r < 0) {
|
|
1654
|
+
t.paused || t.pause(), t.currentTime = 0;
|
|
1655
|
+
return;
|
|
1656
|
+
}
|
|
1657
|
+
i.update(r, s);
|
|
1658
|
+
}
|
|
1659
|
+
class jt {
|
|
1660
|
+
container;
|
|
1661
|
+
timeline = null;
|
|
1662
|
+
adapter;
|
|
1663
|
+
animationFrameId;
|
|
1664
|
+
lastTime;
|
|
1665
|
+
options;
|
|
1666
|
+
targets = {};
|
|
1667
|
+
isDestroyed = !1;
|
|
1668
|
+
mediaSync;
|
|
1669
|
+
mediaTargets = [];
|
|
1670
|
+
symbolInstances = [];
|
|
1671
|
+
markerList = [];
|
|
1672
|
+
listeners = /* @__PURE__ */ new Set();
|
|
1673
|
+
/** Where the playhead was when marker crossings were last worked out */
|
|
1674
|
+
playhead = { time: 0, iteration: 0, direction: "forward" };
|
|
1675
|
+
/** Stop at the next marker crossed (step mode, or `next()`) */
|
|
1676
|
+
stepping = !1;
|
|
1677
|
+
lastMarkerId = null;
|
|
1678
|
+
reducedQuery;
|
|
1679
|
+
onReducedChange = () => this.applyReducedMotion();
|
|
1680
|
+
visibilityObserver;
|
|
1681
|
+
onScreen = !0;
|
|
1682
|
+
/** Playback was paused by leaving the screen, and resumes on return */
|
|
1683
|
+
pausedByVisibility = !1;
|
|
1684
|
+
/** `autoplay` waits for the first time the container is seen */
|
|
1685
|
+
autoplayWhenSeen = !1;
|
|
1686
|
+
onDocumentVisibility = () => this.updateVisibility();
|
|
1687
|
+
constructor(t, e = {}) {
|
|
1688
|
+
if (typeof t == "string") {
|
|
1689
|
+
const s = document.querySelector(t);
|
|
1690
|
+
if (!s)
|
|
1691
|
+
throw new Error(`Container not found: ${t}`);
|
|
1692
|
+
this.container = s;
|
|
1693
|
+
} else
|
|
1694
|
+
this.container = t;
|
|
1695
|
+
this.options = e, this.adapter = new H();
|
|
1696
|
+
}
|
|
1697
|
+
/**
|
|
1698
|
+
* Load animation from a URL or JSON object.
|
|
1699
|
+
*/
|
|
1700
|
+
async load(t) {
|
|
1701
|
+
let e;
|
|
1702
|
+
if (typeof t == "string") {
|
|
1703
|
+
const s = await fetch(t);
|
|
1704
|
+
if (!s.ok)
|
|
1705
|
+
throw new Error(`Failed to load animation: ${s.statusText}`);
|
|
1706
|
+
e = await s.json();
|
|
1707
|
+
} else
|
|
1708
|
+
e = t;
|
|
1709
|
+
this.options.speed !== void 0 && (e.config = { ...e.config, speed: this.options.speed }), this.options.loop !== void 0 && (e.config = { ...e.config, loop: this.options.loop }), this.options.alternate !== void 0 && (e.config = { ...e.config, alternate: this.options.alternate }), this.timeline = tt(e), this.markerList = this.timeline.markers, this.lastMarkerId = null, this.options.onComplete && (this.timeline.onComplete = this.options.onComplete), this.options.onUpdate && (this.timeline.onUpdate = this.options.onUpdate), this.autoRegisterTargets(), this.setupSymbolInstances(), this.scanMedia(), this.showInitialFrame(), this.watchReducedMotion(), this.watchVisibility(), this.options.autoplay && !this.reducedMotion && (this.options.playWhenVisible && !this.onScreen ? this.autoplayWhenSeen = !0 : this.play());
|
|
1710
|
+
}
|
|
1711
|
+
// --- teaching: frames, markers, reduced motion, visibility -----------------
|
|
1712
|
+
/**
|
|
1713
|
+
* Be told whenever the time, play state or current marker may have changed —
|
|
1714
|
+
* for controls and captions. Returns a function that stops it.
|
|
1715
|
+
*/
|
|
1716
|
+
subscribe(t) {
|
|
1717
|
+
return this.listeners.add(t), () => this.listeners.delete(t);
|
|
1718
|
+
}
|
|
1719
|
+
notify() {
|
|
1720
|
+
for (const t of this.listeners) t();
|
|
1721
|
+
}
|
|
1722
|
+
/** Whether the reader asked for reduced motion (and the player respects it). */
|
|
1723
|
+
get reducedMotion() {
|
|
1724
|
+
return this.reducedQuery?.matches === !0;
|
|
1725
|
+
}
|
|
1726
|
+
/** The timeline's markers, in time order. */
|
|
1727
|
+
get markers() {
|
|
1728
|
+
return this.markerList;
|
|
1729
|
+
}
|
|
1730
|
+
/** The last marker at or before the playhead. */
|
|
1731
|
+
get currentMarker() {
|
|
1732
|
+
const t = this.currentTime;
|
|
1733
|
+
let e;
|
|
1734
|
+
for (const s of this.markers)
|
|
1735
|
+
if (s.time <= t + 0.5) e = s;
|
|
1736
|
+
else break;
|
|
1737
|
+
return e;
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Caption for a marker (default: the current one) in a language (default: the
|
|
1741
|
+
* container's closest `lang`, then the document's), falling back to the
|
|
1742
|
+
* marker's own label.
|
|
1743
|
+
*/
|
|
1744
|
+
caption(t, e) {
|
|
1745
|
+
const s = t ? this.markers.find((a) => a.id === t) : this.currentMarker;
|
|
1746
|
+
if (!s) return;
|
|
1747
|
+
const n = e ?? this.language(), r = (a) => a?.[n]?.[s.id] ?? a?.[n.split("-")[0]]?.[s.id];
|
|
1748
|
+
return r(this.options.captions) ?? r(this.timeline?.captions) ?? s.label;
|
|
1749
|
+
}
|
|
1750
|
+
/** Move to the next marker: animated, or a jump under reduced motion. At the last marker, to the end. */
|
|
1751
|
+
next() {
|
|
1752
|
+
if (!this.timeline) return;
|
|
1753
|
+
const t = this.currentTime, e = this.markers.find((s) => s.time > t + 0.5);
|
|
1754
|
+
if (this.reducedMotion) {
|
|
1755
|
+
this.seek(e ? e.time : this.duration);
|
|
1756
|
+
return;
|
|
1757
|
+
}
|
|
1758
|
+
t >= this.duration - 0.5 || (this.stepping = e !== void 0, this.startPlaying());
|
|
1759
|
+
}
|
|
1760
|
+
/** Jump back to the previous marker (or the start). */
|
|
1761
|
+
prev() {
|
|
1762
|
+
if (!this.timeline) return;
|
|
1763
|
+
const t = this.currentTime, e = [...this.markers].reverse().find((s) => s.time < t - 0.5);
|
|
1764
|
+
this.pause(), this.seek(e ? e.time : 0);
|
|
1765
|
+
}
|
|
1766
|
+
/** Jump to a marker by id, paused there. */
|
|
1767
|
+
goToMarker(t) {
|
|
1768
|
+
const e = this.markers.find((s) => s.id === t);
|
|
1769
|
+
e && (this.pause(), this.seek(e.time));
|
|
1770
|
+
}
|
|
1771
|
+
language() {
|
|
1772
|
+
return this.container.closest("[lang]")?.getAttribute("lang") || (typeof document < "u" ? document.documentElement.lang : "") || "en";
|
|
1773
|
+
}
|
|
1774
|
+
showInitialFrame() {
|
|
1775
|
+
if (!this.timeline) return;
|
|
1776
|
+
const t = this.options.initialFrame ?? "start";
|
|
1777
|
+
if (t === "none") return;
|
|
1778
|
+
const e = t === "end" ? this.timeline.duration : t === "start" ? 0 : t;
|
|
1779
|
+
this.timeline.seek(Math.max(0, Math.min(this.timeline.duration, e))), this.applyState();
|
|
1780
|
+
}
|
|
1781
|
+
watchReducedMotion() {
|
|
1782
|
+
this.options.respectReducedMotion === !1 || typeof window > "u" || typeof window.matchMedia != "function" || (this.reducedQuery ??= window.matchMedia("(prefers-reduced-motion: reduce)"), this.reducedQuery.addEventListener?.("change", this.onReducedChange), this.reducedQuery.matches && this.applyReducedMotion());
|
|
1783
|
+
}
|
|
1784
|
+
/** Under reduced motion: stop, and show the finished state. */
|
|
1785
|
+
applyReducedMotion() {
|
|
1786
|
+
!this.reducedMotion || !this.timeline || (this.autoplayWhenSeen = !1, this.pause(), this.seek(this.timeline.duration));
|
|
1787
|
+
}
|
|
1788
|
+
watchVisibility() {
|
|
1789
|
+
if (!(!this.options.playWhenVisible || typeof window > "u")) {
|
|
1790
|
+
if (typeof IntersectionObserver == "function") {
|
|
1791
|
+
this.visibilityObserver?.disconnect(), this.listeners.clear(), this.visibilityObserver = new IntersectionObserver((e) => {
|
|
1792
|
+
for (const s of e) this.onScreen = s.isIntersecting;
|
|
1793
|
+
this.updateVisibility();
|
|
1794
|
+
}), this.visibilityObserver.observe(this.container);
|
|
1795
|
+
const t = this.container.getBoundingClientRect?.();
|
|
1796
|
+
t && (t.width > 0 || t.height > 0) && (this.onScreen = t.bottom > 0 && t.top < window.innerHeight && t.right > 0 && t.left < window.innerWidth);
|
|
1797
|
+
}
|
|
1798
|
+
document.addEventListener("visibilitychange", this.onDocumentVisibility);
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
updateVisibility() {
|
|
1802
|
+
const t = this.onScreen && document.visibilityState !== "hidden";
|
|
1803
|
+
!t && this.isPlaying ? (this.pausedByVisibility = !0, this.pause()) : t && (this.pausedByVisibility || this.autoplayWhenSeen) && !this.reducedMotion && (this.pausedByVisibility = !1, this.autoplayWhenSeen = !1, this.startPlaying());
|
|
1804
|
+
}
|
|
1805
|
+
/** Report the current marker if it changed since the last frame. */
|
|
1806
|
+
announceMarker() {
|
|
1807
|
+
if (!this.options.onMarker) return;
|
|
1808
|
+
const t = this.currentMarker, e = t?.id;
|
|
1809
|
+
e !== this.lastMarkerId && (this.lastMarkerId = e, this.options.onMarker(t));
|
|
1810
|
+
}
|
|
1811
|
+
/**
|
|
1812
|
+
* Find embedded media elements (`[data-tinyfly-media]`) in the container and
|
|
1813
|
+
* bind each to the timeline. Emitted by the editor's export for audio/video
|
|
1814
|
+
* scene elements; the `data-tinyfly-start` attribute sets when each begins.
|
|
1815
|
+
*/
|
|
1816
|
+
scanMedia() {
|
|
1817
|
+
this.mediaTargets = [], this.container.querySelectorAll("[data-tinyfly-media]").forEach((e) => {
|
|
1818
|
+
const s = e, n = Number(s.getAttribute("data-tinyfly-start") ?? "0") || 0, r = s.getAttribute("data-volume");
|
|
1819
|
+
r !== null && (s.volume = Math.max(0, Math.min(1, Number(r) || 0))), this.mediaTargets.push({ el: s, startTime: n, sync: new Ft(s) });
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
/** Sync all discovered media targets to a timeline time. */
|
|
1823
|
+
syncAllMedia(t, e) {
|
|
1824
|
+
for (const s of this.mediaTargets)
|
|
1825
|
+
ki(s.sync, s.el, t, e, s.startTime);
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* Load animation from inline JSON string.
|
|
1829
|
+
*/
|
|
1830
|
+
loadFromString(t) {
|
|
1831
|
+
const e = JSON.parse(t);
|
|
1832
|
+
this.load(e);
|
|
1833
|
+
}
|
|
1834
|
+
/**
|
|
1835
|
+
* Register a target element by name.
|
|
1836
|
+
*/
|
|
1837
|
+
registerTarget(t, e) {
|
|
1838
|
+
if (typeof e == "string") {
|
|
1839
|
+
const s = this.container.querySelector(e);
|
|
1840
|
+
s && (this.targets[t] = s, this.adapter.registerTarget(t, s));
|
|
1841
|
+
} else
|
|
1842
|
+
this.targets[t] = e, this.adapter.registerTarget(t, e);
|
|
1843
|
+
}
|
|
1844
|
+
/**
|
|
1845
|
+
* Auto-register targets using data-tinyfly attribute.
|
|
1846
|
+
*/
|
|
1847
|
+
autoRegisterTargets() {
|
|
1848
|
+
this.container.querySelectorAll("[data-tinyfly]").forEach((e) => {
|
|
1849
|
+
const s = e.closest("[data-tinyfly-symbol]");
|
|
1850
|
+
if (s && s !== e) return;
|
|
1851
|
+
const n = e.getAttribute("data-tinyfly");
|
|
1852
|
+
n && this.registerTarget(n, e);
|
|
1853
|
+
}), this.timeline && new Set(this.timeline.tracks.map((s) => s.target)).forEach((s) => {
|
|
1854
|
+
if (!this.targets[s]) {
|
|
1855
|
+
const n = this.container.querySelector(`[data-tinyfly="${s}"]`) || this.container.querySelector(`.${s}`) || this.container.querySelector(`#${s}`);
|
|
1856
|
+
n && this.registerTarget(s, n);
|
|
1857
|
+
}
|
|
1858
|
+
});
|
|
1859
|
+
}
|
|
1860
|
+
/**
|
|
1861
|
+
* Bind each embedded symbol instance (`[data-tinyfly-symbol="id"]`) to its
|
|
1862
|
+
* symbol's nested timeline: a private adapter drives the instance's inner
|
|
1863
|
+
* elements, looped over the symbol's duration and synced to the main playhead.
|
|
1864
|
+
*/
|
|
1865
|
+
setupSymbolInstances() {
|
|
1866
|
+
this.symbolInstances = [];
|
|
1867
|
+
const t = this.options.symbols;
|
|
1868
|
+
if (!t || t.length === 0) return;
|
|
1869
|
+
const e = new Map(t.map((s) => [s.id, s]));
|
|
1870
|
+
this.container.querySelectorAll("[data-tinyfly-symbol]").forEach((s) => {
|
|
1871
|
+
const n = s.getAttribute("data-tinyfly-symbol");
|
|
1872
|
+
if (!n) return;
|
|
1873
|
+
const r = e.get(n);
|
|
1874
|
+
if (!r || !r.timeline.tracks?.length) return;
|
|
1875
|
+
const a = new H();
|
|
1876
|
+
s.querySelectorAll("[data-tinyfly]").forEach((o) => {
|
|
1877
|
+
const c = o.getAttribute("data-tinyfly");
|
|
1878
|
+
c && a.registerTarget(c, o);
|
|
1879
|
+
}), this.symbolInstances.push({ adapter: a, timeline: tt(r.timeline) });
|
|
1880
|
+
});
|
|
1881
|
+
}
|
|
1882
|
+
/**
|
|
1883
|
+
* Attach an audio/video element (or any {@link SyncableMedia}) that should
|
|
1884
|
+
* stay in sync with the animation timeline. The timeline remains the clock;
|
|
1885
|
+
* the media follows its play/pause/seek and rate, with drift corrected as it
|
|
1886
|
+
* plays. Pass `{ offset }` to start the media at a timeline offset.
|
|
1887
|
+
*/
|
|
1888
|
+
attachMedia(t, e) {
|
|
1889
|
+
this.mediaSync = new Ft(t, e), this.timeline && (this.mediaSync.setRate(this.timeline.speed), this.mediaSync.update(this.timeline.currentTime, this.isPlaying));
|
|
1890
|
+
}
|
|
1891
|
+
/** Detach and pause the currently synced media, if any. */
|
|
1892
|
+
detachMedia() {
|
|
1893
|
+
this.mediaSync?.dispose(), this.mediaSync = void 0;
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* Start or resume playback.
|
|
1897
|
+
*/
|
|
1898
|
+
play() {
|
|
1899
|
+
!this.timeline || this.isDestroyed || (this.autoplayWhenSeen = !1, this.stepping = this.options.stepMode === !0, this.startPlaying());
|
|
1900
|
+
}
|
|
1901
|
+
startPlaying() {
|
|
1902
|
+
if (!this.timeline || this.isDestroyed) return;
|
|
1903
|
+
const t = this.timeline.playbackState === "idle";
|
|
1904
|
+
this.timeline.play(), t && this.timeline.currentTime === 0 && this.applyState(), this.playhead = { time: this.timeline.currentTime, iteration: this.timeline.loopIteration, direction: this.timeline.direction }, this.mediaSync?.update(this.timeline.currentTime, !0), this.syncAllMedia(this.timeline.currentTime, !0), this.startAnimationLoop(), this.notify();
|
|
1905
|
+
}
|
|
1906
|
+
/**
|
|
1907
|
+
* Pause playback.
|
|
1908
|
+
*/
|
|
1909
|
+
pause() {
|
|
1910
|
+
this.timeline && (this.stepping = !1, this.timeline.pause(), this.notify(), this.mediaSync?.update(this.timeline.currentTime, !1), this.syncAllMedia(this.timeline.currentTime, !1), this.stopAnimationLoop());
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Stop playback and reset to beginning.
|
|
1914
|
+
*/
|
|
1915
|
+
stop() {
|
|
1916
|
+
this.timeline && (this.timeline.stop(), this.stopAnimationLoop(), this.applyState(), this.mediaSync?.update(this.timeline.currentTime, !1), this.syncAllMedia(this.timeline.currentTime, !1));
|
|
1917
|
+
}
|
|
1918
|
+
/**
|
|
1919
|
+
* Seek to a specific time (in milliseconds).
|
|
1920
|
+
*/
|
|
1921
|
+
seek(t) {
|
|
1922
|
+
this.timeline && (this.timeline.seek(t), this.applyState(), this.playhead = { time: this.timeline.currentTime, iteration: this.timeline.loopIteration, direction: this.timeline.direction }, this.mediaSync?.seek(this.timeline.currentTime), this.syncAllMedia(this.timeline.currentTime, this.isPlaying));
|
|
1923
|
+
}
|
|
1924
|
+
/**
|
|
1925
|
+
* Set playback speed.
|
|
1926
|
+
*/
|
|
1927
|
+
setSpeed(t) {
|
|
1928
|
+
this.timeline && (this.timeline.speed = t, this.mediaSync?.setRate(t));
|
|
1929
|
+
}
|
|
1930
|
+
/**
|
|
1931
|
+
* Reverse playback direction.
|
|
1932
|
+
*/
|
|
1933
|
+
reverse() {
|
|
1934
|
+
this.timeline && this.timeline.reverse();
|
|
1935
|
+
}
|
|
1936
|
+
/**
|
|
1937
|
+
* Get current playback time.
|
|
1938
|
+
*/
|
|
1939
|
+
get currentTime() {
|
|
1940
|
+
return this.timeline?.currentTime ?? 0;
|
|
1941
|
+
}
|
|
1942
|
+
/**
|
|
1943
|
+
* Get total duration.
|
|
1944
|
+
*/
|
|
1945
|
+
get duration() {
|
|
1946
|
+
return this.timeline?.duration ?? 0;
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* Check if currently playing.
|
|
1950
|
+
*/
|
|
1951
|
+
get isPlaying() {
|
|
1952
|
+
return this.timeline?.playbackState === "playing";
|
|
1953
|
+
}
|
|
1954
|
+
/**
|
|
1955
|
+
* Clean up resources.
|
|
1956
|
+
*/
|
|
1957
|
+
destroy() {
|
|
1958
|
+
this.isDestroyed = !0, this.stopAnimationLoop(), this.reducedQuery?.removeEventListener?.("change", this.onReducedChange), this.visibilityObserver?.disconnect(), typeof document < "u" && document.removeEventListener("visibilitychange", this.onDocumentVisibility), this.mediaSync?.dispose(), this.mediaSync = void 0;
|
|
1959
|
+
for (const t of this.mediaTargets)
|
|
1960
|
+
t.el.paused || t.el.pause();
|
|
1961
|
+
this.mediaTargets = [], this.adapter.clearTargets();
|
|
1962
|
+
for (const t of this.symbolInstances) t.adapter.clearTargets();
|
|
1963
|
+
this.symbolInstances = [], this.timeline = null;
|
|
1964
|
+
}
|
|
1965
|
+
startAnimationLoop() {
|
|
1966
|
+
if (this.animationFrameId !== void 0) return;
|
|
1967
|
+
this.lastTime = performance.now();
|
|
1968
|
+
const t = (e) => {
|
|
1969
|
+
if (this.isDestroyed || !this.timeline) return;
|
|
1970
|
+
const s = e - (this.lastTime ?? e);
|
|
1971
|
+
this.lastTime = e;
|
|
1972
|
+
const n = this.playhead;
|
|
1973
|
+
this.timeline.tick(s), this.stopAtMarker(n), this.applyState();
|
|
1974
|
+
const r = this.timeline.playbackState === "playing";
|
|
1975
|
+
this.mediaSync?.update(this.timeline.currentTime, r), this.syncAllMedia(this.timeline.currentTime, r), this.timeline.playbackState === "playing" ? this.animationFrameId = requestAnimationFrame(t) : (this.animationFrameId = void 0, this.notify());
|
|
1976
|
+
};
|
|
1977
|
+
this.animationFrameId = requestAnimationFrame(t);
|
|
1978
|
+
}
|
|
1979
|
+
/**
|
|
1980
|
+
* If this frame crossed a marker it should stop at — the next one while
|
|
1981
|
+
* stepping, or any marker with `pause` — put the playhead exactly there and pause.
|
|
1982
|
+
*/
|
|
1983
|
+
stopAtMarker(t) {
|
|
1984
|
+
const e = this.timeline, s = { time: e.currentTime, iteration: e.loopIteration, direction: e.direction };
|
|
1985
|
+
this.playhead = s;
|
|
1986
|
+
const n = this.markers;
|
|
1987
|
+
if (n.length === 0) return;
|
|
1988
|
+
const { crossings: r } = li(
|
|
1989
|
+
n.map((a) => a.time),
|
|
1990
|
+
t,
|
|
1991
|
+
s,
|
|
1992
|
+
{ duration: e.duration, alternate: e.config.alternate === !0, holding: e.repeatDelayRemaining > 0 }
|
|
1993
|
+
);
|
|
1994
|
+
for (const a of r) {
|
|
1995
|
+
if (a.kind !== "event") continue;
|
|
1996
|
+
const o = n[a.index];
|
|
1997
|
+
if (this.stepping || o.pause) {
|
|
1998
|
+
this.stepping = !1, e.pause(), e.seek(o.time), this.playhead = { time: o.time, iteration: e.loopIteration, direction: e.direction };
|
|
1999
|
+
return;
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
stopAnimationLoop() {
|
|
2004
|
+
this.animationFrameId !== void 0 && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = void 0);
|
|
2005
|
+
}
|
|
2006
|
+
applyState() {
|
|
2007
|
+
if (!this.timeline) return;
|
|
2008
|
+
const t = this.timeline.currentTime;
|
|
2009
|
+
this.adapter.applyState(this.timeline.getStateAtTime(t)), this.announceMarker(), this.notify();
|
|
2010
|
+
for (const e of this.symbolInstances) {
|
|
2011
|
+
const s = e.timeline.duration;
|
|
2012
|
+
e.adapter.applyState(e.timeline.getStateAtTime(s > 0 ? t % s : t));
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
async function Pi(i, t, e = {}) {
|
|
2017
|
+
const s = new jt(i, { ...e, autoplay: !0 });
|
|
2018
|
+
return await s.load(t), s;
|
|
2019
|
+
}
|
|
2020
|
+
function xi(i, t = {}) {
|
|
2021
|
+
return new jt(i, t);
|
|
2022
|
+
}
|
|
2023
|
+
class wi {
|
|
2024
|
+
container;
|
|
2025
|
+
containerA;
|
|
2026
|
+
containerB;
|
|
2027
|
+
adapterA;
|
|
2028
|
+
adapterB;
|
|
2029
|
+
timelineA = null;
|
|
2030
|
+
timelineB = null;
|
|
2031
|
+
/** Symbol nested timelines by id (from the sequence). */
|
|
2032
|
+
symbolDefs = /* @__PURE__ */ new Map();
|
|
2033
|
+
/** Per-scene-slot symbol instances (nested adapter + timeline), keyed by the
|
|
2034
|
+
* slot's scene adapter. */
|
|
2035
|
+
nestedByAdapter = /* @__PURE__ */ new Map();
|
|
2036
|
+
sequence = null;
|
|
2037
|
+
options;
|
|
2038
|
+
_currentSceneIndex = 0;
|
|
2039
|
+
_state = "idle";
|
|
2040
|
+
_isPlaying = !1;
|
|
2041
|
+
_isDestroyed = !1;
|
|
2042
|
+
loopIteration = 0;
|
|
2043
|
+
animationFrameId;
|
|
2044
|
+
lastTime;
|
|
2045
|
+
transitionTimer;
|
|
2046
|
+
constructor(t, e = {}) {
|
|
2047
|
+
if (typeof t == "string") {
|
|
2048
|
+
const s = document.querySelector(t);
|
|
2049
|
+
if (!s) throw new Error(`Container not found: ${t}`);
|
|
2050
|
+
this.container = s;
|
|
2051
|
+
} else
|
|
2052
|
+
this.container = t;
|
|
2053
|
+
this.options = e, this.container.style.position = "relative", this.container.style.overflow = "hidden", this.containerA = this.createSceneContainer(), this.containerB = this.createSceneContainer(), this.container.appendChild(this.containerA), this.container.appendChild(this.containerB), this.containerB.style.visibility = "hidden", this.adapterA = new H(), this.adapterB = new H();
|
|
2054
|
+
}
|
|
2055
|
+
/**
|
|
2056
|
+
* Load a sequence from a URL or inline definition.
|
|
2057
|
+
*/
|
|
2058
|
+
async load(t) {
|
|
2059
|
+
let e;
|
|
2060
|
+
if (typeof t == "string") {
|
|
2061
|
+
const s = await fetch(t);
|
|
2062
|
+
if (!s.ok)
|
|
2063
|
+
throw new Error(`Failed to load sequence: ${s.statusText}`);
|
|
2064
|
+
e = await s.json();
|
|
2065
|
+
} else
|
|
2066
|
+
e = t;
|
|
2067
|
+
this.sequence = e, this.symbolDefs.clear();
|
|
2068
|
+
for (const s of e.symbols ?? [])
|
|
2069
|
+
s.timeline?.tracks?.length && this.symbolDefs.set(s.id, s.timeline);
|
|
2070
|
+
this.container.style.width = `${e.canvas.width}px`, this.container.style.height = `${e.canvas.height}px`, e.scenes.length > 0 && (this.renderScene(e.scenes[0], this.containerA, this.adapterA), this.timelineA = this.createTimeline(e.scenes[0])), this.options.autoplay && this.play();
|
|
2071
|
+
}
|
|
2072
|
+
/**
|
|
2073
|
+
* Start or resume playback.
|
|
2074
|
+
*/
|
|
2075
|
+
play() {
|
|
2076
|
+
if (!(!this.sequence || this._isDestroyed) && this.sequence.scenes.length !== 0) {
|
|
2077
|
+
if (this._isPlaying = !0, this._state === "idle") {
|
|
2078
|
+
if (this._state = "playing-scene", this._currentSceneIndex = 0, this.timelineA)
|
|
2079
|
+
this.timelineA.onComplete = () => this.onSceneComplete(), this.timelineA.play();
|
|
2080
|
+
else {
|
|
2081
|
+
this.onSceneComplete();
|
|
2082
|
+
return;
|
|
2083
|
+
}
|
|
2084
|
+
this.options.onSceneChange?.(0);
|
|
2085
|
+
} else this._state === "playing-scene" && this.timelineA && this.timelineA.play();
|
|
2086
|
+
this.startAnimationLoop();
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
/**
|
|
2090
|
+
* Pause playback.
|
|
2091
|
+
*/
|
|
2092
|
+
pause() {
|
|
2093
|
+
this._isPlaying && (this._isPlaying = !1, this.timelineA && this.timelineA.pause(), this.timelineB && this.timelineB.pause(), this.stopAnimationLoop());
|
|
2094
|
+
}
|
|
2095
|
+
/**
|
|
2096
|
+
* Stop playback and reset to beginning.
|
|
2097
|
+
*/
|
|
2098
|
+
stop() {
|
|
2099
|
+
if (this._isPlaying = !1, this._state = "idle", this._currentSceneIndex = 0, this.loopIteration = 0, this.transitionTimer !== void 0 && (clearTimeout(this.transitionTimer), this.transitionTimer = void 0), this.timelineA && this.timelineA.stop(), this.timelineB && this.timelineB.stop(), this.stopAnimationLoop(), this.sequence && this.sequence.scenes.length > 0 && (this.clearContainer(this.containerA), this.clearContainer(this.containerB), this.adapterA.clearTargets(), this.adapterB.clearTargets(), this.containerB.style.visibility = "hidden", this.resetTransitionStyles(this.containerA), this.resetTransitionStyles(this.containerB), this.renderScene(this.sequence.scenes[0], this.containerA, this.adapterA), this.timelineA = this.createTimeline(this.sequence.scenes[0]), this.timelineA)) {
|
|
2100
|
+
const t = this.timelineA.getStateAtTime(0);
|
|
2101
|
+
this.adapterA.applyState(t), this.applyNested(this.adapterA, 0);
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* Jump to a specific scene by index.
|
|
2106
|
+
*/
|
|
2107
|
+
goToScene(t) {
|
|
2108
|
+
if (!this.sequence || t < 0 || t >= this.sequence.scenes.length) return;
|
|
2109
|
+
const e = this._isPlaying;
|
|
2110
|
+
this.transitionTimer !== void 0 && (clearTimeout(this.transitionTimer), this.transitionTimer = void 0), this.stopAnimationLoop(), this.timelineA && this.timelineA.stop(), this.timelineB && this.timelineB.stop(), this._currentSceneIndex = t, this._state = e ? "playing-scene" : "idle", this.clearContainer(this.containerA), this.clearContainer(this.containerB), this.adapterA.clearTargets(), this.adapterB.clearTargets(), this.containerB.style.visibility = "hidden", this.resetTransitionStyles(this.containerA), this.resetTransitionStyles(this.containerB);
|
|
2111
|
+
const s = this.sequence.scenes[t];
|
|
2112
|
+
if (this.renderScene(s, this.containerA, this.adapterA), this.timelineA = this.createTimeline(s), this.options.onSceneChange?.(t), e)
|
|
2113
|
+
this.timelineA ? (this.timelineA.onComplete = () => this.onSceneComplete(), this.timelineA.play(), this.startAnimationLoop()) : this.onSceneComplete();
|
|
2114
|
+
else if (this.timelineA) {
|
|
2115
|
+
const n = this.timelineA.getStateAtTime(0);
|
|
2116
|
+
this.adapterA.applyState(n), this.applyNested(this.adapterA, 0);
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
/**
|
|
2120
|
+
* Clean up all resources.
|
|
2121
|
+
*/
|
|
2122
|
+
destroy() {
|
|
2123
|
+
this._isDestroyed = !0, this._isPlaying = !1, this.transitionTimer !== void 0 && (clearTimeout(this.transitionTimer), this.transitionTimer = void 0), this.stopAnimationLoop(), this.adapterA.clearTargets(), this.adapterB.clearTargets();
|
|
2124
|
+
for (const t of this.nestedByAdapter.values())
|
|
2125
|
+
for (const e of t) e.adapter.clearTargets();
|
|
2126
|
+
this.nestedByAdapter.clear(), this.timelineA && this.timelineA.stop(), this.timelineB && this.timelineB.stop(), this.timelineA = null, this.timelineB = null, this.containerA.parentNode && this.containerA.remove(), this.containerB.parentNode && this.containerB.remove(), this.sequence = null;
|
|
2127
|
+
}
|
|
2128
|
+
get currentSceneIndex() {
|
|
2129
|
+
return this._currentSceneIndex;
|
|
2130
|
+
}
|
|
2131
|
+
get sceneCount() {
|
|
2132
|
+
return this.sequence?.scenes.length ?? 0;
|
|
2133
|
+
}
|
|
2134
|
+
get isPlaying() {
|
|
2135
|
+
return this._isPlaying;
|
|
2136
|
+
}
|
|
2137
|
+
get state() {
|
|
2138
|
+
return this._state;
|
|
2139
|
+
}
|
|
2140
|
+
// --- Private methods ---
|
|
2141
|
+
createSceneContainer() {
|
|
2142
|
+
const t = document.createElement("div");
|
|
2143
|
+
return t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.width = "100%", t.style.height = "100%", t;
|
|
2144
|
+
}
|
|
2145
|
+
renderScene(t, e, s) {
|
|
2146
|
+
e.innerHTML = "", s.clearTargets();
|
|
2147
|
+
const n = document.createElement("div");
|
|
2148
|
+
n.style.cssText = "position:absolute;inset:0;transform-origin:center center", n.setAttribute("data-tinyfly", "Camera"), e.appendChild(n), s.registerTarget("Camera", n);
|
|
2149
|
+
for (const r of t.elements) {
|
|
2150
|
+
if (!r.html) continue;
|
|
2151
|
+
const a = document.createElement("div");
|
|
2152
|
+
a.innerHTML = r.html.trim();
|
|
2153
|
+
const o = a.firstElementChild;
|
|
2154
|
+
if (o) {
|
|
2155
|
+
n.appendChild(o);
|
|
2156
|
+
const c = o.getAttribute("data-tinyfly");
|
|
2157
|
+
c && s.registerTarget(c, o);
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
this.setupNested(n, s);
|
|
2161
|
+
}
|
|
2162
|
+
/**
|
|
2163
|
+
* For each symbol instance container (`[data-tinyfly-symbol]`) in a scene slot,
|
|
2164
|
+
* bind its inner elements to a private adapter driven by the symbol's timeline.
|
|
2165
|
+
*/
|
|
2166
|
+
setupNested(t, e) {
|
|
2167
|
+
const s = [];
|
|
2168
|
+
t.querySelectorAll("[data-tinyfly-symbol]").forEach((n) => {
|
|
2169
|
+
const r = n.getAttribute("data-tinyfly-symbol");
|
|
2170
|
+
if (!r) return;
|
|
2171
|
+
const a = this.symbolDefs.get(r);
|
|
2172
|
+
if (!a) return;
|
|
2173
|
+
const o = new H();
|
|
2174
|
+
n.querySelectorAll("[data-tinyfly]").forEach((c) => {
|
|
2175
|
+
const h = c.getAttribute("data-tinyfly");
|
|
2176
|
+
h && o.registerTarget(h, c);
|
|
2177
|
+
}), s.push({ adapter: o, timeline: tt(a) });
|
|
2178
|
+
}), s.length ? this.nestedByAdapter.set(e, s) : this.nestedByAdapter.delete(e);
|
|
2179
|
+
}
|
|
2180
|
+
/** Apply the nested symbol states for a slot at a given scene time. */
|
|
2181
|
+
applyNested(t, e) {
|
|
2182
|
+
const s = this.nestedByAdapter.get(t);
|
|
2183
|
+
if (s)
|
|
2184
|
+
for (const n of s) {
|
|
2185
|
+
const r = n.timeline.duration;
|
|
2186
|
+
n.adapter.applyState(n.timeline.getStateAtTime(r > 0 ? e % r : e));
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
clearContainer(t) {
|
|
2190
|
+
t.innerHTML = "";
|
|
2191
|
+
}
|
|
2192
|
+
createTimeline(t) {
|
|
2193
|
+
return t.timeline ? tt(t.timeline) : null;
|
|
2194
|
+
}
|
|
2195
|
+
onSceneComplete() {
|
|
2196
|
+
if (this._isDestroyed || !this.sequence) return;
|
|
2197
|
+
const t = this._currentSceneIndex + 1;
|
|
2198
|
+
if (t >= this.sequence.scenes.length) {
|
|
2199
|
+
const e = this.options.loop ?? this.sequence.loop ?? 0;
|
|
2200
|
+
e === -1 || e > 0 && this.loopIteration < e - 1 ? (this.loopIteration++, this.beginTransitionTo(0)) : (this._isPlaying = !1, this._state = "idle", this.stopAnimationLoop(), this.options.onComplete?.());
|
|
2201
|
+
} else
|
|
2202
|
+
this.beginTransitionTo(t);
|
|
2203
|
+
}
|
|
2204
|
+
beginTransitionTo(t) {
|
|
2205
|
+
if (!this.sequence || this._isDestroyed) return;
|
|
2206
|
+
const e = this.sequence.scenes[t], s = e.transition;
|
|
2207
|
+
if (s.type === "none" || s.duration <= 0) {
|
|
2208
|
+
this.switchToScene(t);
|
|
2209
|
+
return;
|
|
2210
|
+
}
|
|
2211
|
+
this._state = "transitioning", this.containerB.style.visibility = "visible", this.renderScene(e, this.containerB, this.adapterB), this.timelineB = this.createTimeline(e), this.timelineB && this.timelineB.play(), this.applyTransition(s.type, s.duration), this.transitionTimer = window.setTimeout(() => {
|
|
2212
|
+
this.finishTransition(t);
|
|
2213
|
+
}, s.duration);
|
|
2214
|
+
}
|
|
2215
|
+
applyTransition(t, e) {
|
|
2216
|
+
const s = `${e}ms`, n = "ease-in-out";
|
|
2217
|
+
switch (this.resetTransitionStyles(this.containerA), this.resetTransitionStyles(this.containerB), t) {
|
|
2218
|
+
case "fade":
|
|
2219
|
+
this.containerB.style.opacity = "0";
|
|
2220
|
+
break;
|
|
2221
|
+
case "slide-left":
|
|
2222
|
+
this.containerB.style.transform = "translateX(100%)";
|
|
2223
|
+
break;
|
|
2224
|
+
case "slide-right":
|
|
2225
|
+
this.containerB.style.transform = "translateX(-100%)";
|
|
2226
|
+
break;
|
|
2227
|
+
case "slide-up":
|
|
2228
|
+
this.containerB.style.transform = "translateY(100%)";
|
|
2229
|
+
break;
|
|
2230
|
+
case "slide-down":
|
|
2231
|
+
this.containerB.style.transform = "translateY(-100%)";
|
|
2232
|
+
break;
|
|
2233
|
+
}
|
|
2234
|
+
switch (this.containerB.offsetHeight, this.containerA.style.transition = `opacity ${s} ${n}, transform ${s} ${n}`, this.containerB.style.transition = `opacity ${s} ${n}, transform ${s} ${n}`, t) {
|
|
2235
|
+
case "fade":
|
|
2236
|
+
this.containerA.style.opacity = "0", this.containerB.style.opacity = "1";
|
|
2237
|
+
break;
|
|
2238
|
+
case "slide-left":
|
|
2239
|
+
this.containerA.style.transform = "translateX(-100%)", this.containerB.style.transform = "translateX(0)";
|
|
2240
|
+
break;
|
|
2241
|
+
case "slide-right":
|
|
2242
|
+
this.containerA.style.transform = "translateX(100%)", this.containerB.style.transform = "translateX(0)";
|
|
2243
|
+
break;
|
|
2244
|
+
case "slide-up":
|
|
2245
|
+
this.containerA.style.transform = "translateY(-100%)", this.containerB.style.transform = "translateY(0)";
|
|
2246
|
+
break;
|
|
2247
|
+
case "slide-down":
|
|
2248
|
+
this.containerA.style.transform = "translateY(100%)", this.containerB.style.transform = "translateY(0)";
|
|
2249
|
+
break;
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
resetTransitionStyles(t) {
|
|
2253
|
+
t.style.transition = "", t.style.opacity = "1", t.style.transform = "";
|
|
2254
|
+
}
|
|
2255
|
+
finishTransition(t) {
|
|
2256
|
+
this.transitionTimer = void 0, this.timelineA && (this.timelineA.stop(), this.timelineA = null), this.adapterA.clearTargets(), this.clearContainer(this.containerA);
|
|
2257
|
+
const e = this.containerA;
|
|
2258
|
+
this.containerA = this.containerB, this.containerB = e;
|
|
2259
|
+
const s = this.adapterA;
|
|
2260
|
+
this.adapterA = this.adapterB, this.adapterB = s, this.timelineA = this.timelineB, this.timelineB = null, this.containerB.style.visibility = "hidden", this.resetTransitionStyles(this.containerA), this.resetTransitionStyles(this.containerB), this._currentSceneIndex = t, this._state = "playing-scene", this.options.onSceneChange?.(t), this.timelineA ? (this.timelineA.onComplete = () => this.onSceneComplete(), this.timelineA.playbackState !== "playing" && this.timelineA.play()) : this.onSceneComplete();
|
|
2261
|
+
}
|
|
2262
|
+
switchToScene(t) {
|
|
2263
|
+
if (!this.sequence || this._isDestroyed) return;
|
|
2264
|
+
this.timelineA && this.timelineA.stop(), this.adapterA.clearTargets(), this.clearContainer(this.containerA);
|
|
2265
|
+
const e = this.sequence.scenes[t];
|
|
2266
|
+
this.renderScene(e, this.containerA, this.adapterA), this.timelineA = this.createTimeline(e), this._currentSceneIndex = t, this._state = "playing-scene", this.options.onSceneChange?.(t), this.timelineA ? (this.timelineA.onComplete = () => this.onSceneComplete(), this.timelineA.play()) : this.onSceneComplete();
|
|
2267
|
+
}
|
|
2268
|
+
startAnimationLoop() {
|
|
2269
|
+
if (this.animationFrameId !== void 0) return;
|
|
2270
|
+
this.lastTime = performance.now();
|
|
2271
|
+
const t = (e) => {
|
|
2272
|
+
if (this._isDestroyed || !this._isPlaying) return;
|
|
2273
|
+
const s = e - (this.lastTime ?? e);
|
|
2274
|
+
if (this.lastTime = e, this.timelineA && this.timelineA.playbackState === "playing") {
|
|
2275
|
+
this.timelineA.tick(s);
|
|
2276
|
+
const n = this.timelineA.getStateAtTime(this.timelineA.currentTime);
|
|
2277
|
+
this.adapterA.applyState(n), this.applyNested(this.adapterA, this.timelineA.currentTime);
|
|
2278
|
+
}
|
|
2279
|
+
if (this._state === "transitioning" && this.timelineB && this.timelineB.playbackState === "playing") {
|
|
2280
|
+
this.timelineB.tick(s);
|
|
2281
|
+
const n = this.timelineB.getStateAtTime(this.timelineB.currentTime);
|
|
2282
|
+
this.adapterB.applyState(n), this.applyNested(this.adapterB, this.timelineB.currentTime);
|
|
2283
|
+
}
|
|
2284
|
+
this._isPlaying ? this.animationFrameId = requestAnimationFrame(t) : this.animationFrameId = void 0;
|
|
2285
|
+
};
|
|
2286
|
+
this.animationFrameId = requestAnimationFrame(t);
|
|
2287
|
+
}
|
|
2288
|
+
stopAnimationLoop() {
|
|
2289
|
+
this.animationFrameId !== void 0 && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = void 0);
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
async function vi(i, t, e = {}) {
|
|
2293
|
+
const s = new wi(i, { ...e, autoplay: !0 });
|
|
2294
|
+
return await s.load(t), s;
|
|
2295
|
+
}
|
|
2296
|
+
const Ci = { type: "none", duration: 0 };
|
|
2297
|
+
export {
|
|
2298
|
+
Ci as DEFAULT_TRANSITION,
|
|
2299
|
+
Ft as MediaSync,
|
|
2300
|
+
jt as TinyflyPlayer,
|
|
2301
|
+
wi as TinyflySequencer,
|
|
2302
|
+
xi as create,
|
|
2303
|
+
Pi as play,
|
|
2304
|
+
vi as playSequence,
|
|
2305
|
+
ki as syncMediaElement
|
|
2306
|
+
};
|