@core-ease/telegram-kit 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +299 -0
  3. package/dist/animation/index.d.mts +4 -0
  4. package/dist/animation/index.d.ts +4 -0
  5. package/dist/animation/index.js +2413 -0
  6. package/dist/animation/index.mjs +5 -0
  7. package/dist/animation/lottie/index.d.mts +10 -0
  8. package/dist/animation/lottie/index.d.ts +10 -0
  9. package/dist/animation/lottie/index.js +2313 -0
  10. package/dist/animation/lottie/index.mjs +4 -0
  11. package/dist/animation/tgs/index.d.mts +18 -0
  12. package/dist/animation/tgs/index.d.ts +18 -0
  13. package/dist/animation/tgs/index.js +2402 -0
  14. package/dist/animation/tgs/index.mjs +4 -0
  15. package/dist/bot/index.d.mts +477 -0
  16. package/dist/bot/index.d.ts +477 -0
  17. package/dist/bot/index.js +870 -0
  18. package/dist/bot/index.mjs +847 -0
  19. package/dist/bot-D8BnLWIi.d.mts +2041 -0
  20. package/dist/bot-D8BnLWIi.d.ts +2041 -0
  21. package/dist/browser.global.js +23 -0
  22. package/dist/chunk-7AARTHNW.mjs +40 -0
  23. package/dist/chunk-7CVYPKAL.mjs +15 -0
  24. package/dist/chunk-B3PWALX5.mjs +4418 -0
  25. package/dist/chunk-BQEUEAVK.mjs +2262 -0
  26. package/dist/chunk-FPWYSKK2.mjs +3089 -0
  27. package/dist/chunk-JXK5HCDV.mjs +254 -0
  28. package/dist/chunk-OMH2JGOH.mjs +88 -0
  29. package/dist/chunk-PXO36YTU.mjs +38 -0
  30. package/dist/core/index.d.mts +151 -0
  31. package/dist/core/index.d.ts +151 -0
  32. package/dist/core/index.js +3837 -0
  33. package/dist/core/index.mjs +495 -0
  34. package/dist/dev/index.d.mts +77 -0
  35. package/dist/dev/index.d.ts +77 -0
  36. package/dist/dev/index.js +3214 -0
  37. package/dist/dev/index.mjs +151 -0
  38. package/dist/engine-BDm1_hzn.d.mts +382 -0
  39. package/dist/engine-BDm1_hzn.d.ts +382 -0
  40. package/dist/format/index.d.mts +61 -0
  41. package/dist/format/index.d.ts +61 -0
  42. package/dist/format/index.js +121 -0
  43. package/dist/format/index.mjs +112 -0
  44. package/dist/hooks/index.d.mts +1 -0
  45. package/dist/hooks/index.d.ts +1 -0
  46. package/dist/hooks/index.js +4234 -0
  47. package/dist/hooks/index.mjs +3 -0
  48. package/dist/hooks-C5Per70R.d.mts +1066 -0
  49. package/dist/hooks-C5Per70R.d.ts +1066 -0
  50. package/dist/index.d.mts +849 -0
  51. package/dist/index.d.ts +849 -0
  52. package/dist/index.js +5026 -0
  53. package/dist/index.mjs +478 -0
  54. package/dist/keyboards/index.d.mts +50 -0
  55. package/dist/keyboards/index.d.ts +50 -0
  56. package/dist/keyboards/index.js +127 -0
  57. package/dist/keyboards/index.mjs +124 -0
  58. package/dist/links/index.d.mts +53 -0
  59. package/dist/links/index.d.ts +53 -0
  60. package/dist/links/index.js +139 -0
  61. package/dist/links/index.mjs +133 -0
  62. package/dist/lottie/index.d.mts +3 -0
  63. package/dist/lottie/index.d.ts +3 -0
  64. package/dist/lottie/index.js +2313 -0
  65. package/dist/lottie/index.mjs +4 -0
  66. package/dist/qr/index.d.mts +75 -0
  67. package/dist/qr/index.d.ts +75 -0
  68. package/dist/qr/index.js +983 -0
  69. package/dist/qr/index.mjs +946 -0
  70. package/dist/sdk/index.d.mts +322 -0
  71. package/dist/sdk/index.d.ts +322 -0
  72. package/dist/sdk/index.js +3138 -0
  73. package/dist/sdk/index.mjs +2 -0
  74. package/dist/server/index.d.mts +28 -0
  75. package/dist/server/index.d.ts +28 -0
  76. package/dist/server/index.js +254 -0
  77. package/dist/server/index.mjs +246 -0
  78. package/dist/tgs/index.d.mts +3 -0
  79. package/dist/tgs/index.d.ts +3 -0
  80. package/dist/tgs/index.js +2402 -0
  81. package/dist/tgs/index.mjs +4 -0
  82. package/dist/webapp-B-3_74nK.d.mts +842 -0
  83. package/dist/webapp-B-3_74nK.d.ts +842 -0
  84. package/dist/webapp-BDi9q3-a.d.mts +42 -0
  85. package/dist/webapp-YvmwFYUQ.d.ts +42 -0
  86. package/package.json +165 -0
@@ -0,0 +1,2262 @@
1
+ "use client";
2
+ import { __spreadValues } from './chunk-PXO36YTU.mjs';
3
+ import * as React from 'react';
4
+ import { jsx } from 'react/jsx-runtime';
5
+
6
+ // src/_internal/animation/lottie/bezierEasing.ts
7
+ function A(a1, a2) {
8
+ return 1 - 3 * a2 + 3 * a1;
9
+ }
10
+ function B(a1, a2) {
11
+ return 3 * a2 - 6 * a1;
12
+ }
13
+ function C(a1) {
14
+ return 3 * a1;
15
+ }
16
+ function calcBezier(t, a1, a2) {
17
+ return ((A(a1, a2) * t + B(a1, a2)) * t + C(a1)) * t;
18
+ }
19
+ function getSlope(t, a1, a2) {
20
+ return 3 * A(a1, a2) * t * t + 2 * B(a1, a2) * t + C(a1);
21
+ }
22
+ function makeBezierEasing(x1, y1, x2, y2) {
23
+ if (x1 === y1 && x2 === y2) {
24
+ return (x) => x;
25
+ }
26
+ const clampedX1 = Math.min(Math.max(x1, 0), 1);
27
+ const clampedX2 = Math.min(Math.max(x2, 0), 1);
28
+ function getTForX(x) {
29
+ let t = x;
30
+ for (let i = 0; i < 8; i++) {
31
+ const currentSlope = getSlope(t, clampedX1, clampedX2);
32
+ if (currentSlope === 0) break;
33
+ const currentX = calcBezier(t, clampedX1, clampedX2) - x;
34
+ t -= currentX / currentSlope;
35
+ }
36
+ let lower = 0;
37
+ let upper = 1;
38
+ let candidate = t;
39
+ if (candidate < 0 || candidate > 1 || isNaN(candidate)) {
40
+ candidate = x;
41
+ for (let i = 0; i < 20; i++) {
42
+ const currentX = calcBezier(candidate, clampedX1, clampedX2);
43
+ if (Math.abs(currentX - x) < 1e-6) break;
44
+ if (currentX < x) {
45
+ lower = candidate;
46
+ } else {
47
+ upper = candidate;
48
+ }
49
+ candidate = (lower + upper) / 2;
50
+ }
51
+ }
52
+ return candidate;
53
+ }
54
+ return (x) => {
55
+ if (x <= 0) return 0;
56
+ if (x >= 1) return 1;
57
+ const t = getTForX(x);
58
+ return calcBezier(t, y1, y2);
59
+ };
60
+ }
61
+
62
+ // src/_internal/animation/lottie/interpolate.ts
63
+ var easingCache = /* @__PURE__ */ new Map();
64
+ function getEasing(ox, oy, ix, iy) {
65
+ const key = `${ox}|${oy}|${ix}|${iy}`;
66
+ let fn = easingCache.get(key);
67
+ if (!fn) {
68
+ fn = makeBezierEasing(ox, oy, ix, iy);
69
+ easingCache.set(key, fn);
70
+ }
71
+ return fn;
72
+ }
73
+ function componentAt(v, idx) {
74
+ var _a, _b;
75
+ if (v == null) return 0.5;
76
+ if (Array.isArray(v)) return (_b = (_a = v[idx]) != null ? _a : v[0]) != null ? _b : 0.5;
77
+ return v;
78
+ }
79
+ function getAnimatedValue(prop, frame) {
80
+ if (!prop) return [0];
81
+ if (prop.a === 0 || !Array.isArray(prop.k) || typeof prop.k[0] === "number") {
82
+ const k = prop.k;
83
+ return Array.isArray(k) ? k : [k];
84
+ }
85
+ const keyframes = prop.k;
86
+ return sampleKeyframes(keyframes, frame);
87
+ }
88
+ function sampleKeyframes(keyframes, frame) {
89
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
90
+ if (keyframes.length === 0) return [0];
91
+ if (frame <= keyframes[0].t) {
92
+ return (_a = keyframes[0].s) != null ? _a : [0];
93
+ }
94
+ const last = keyframes[keyframes.length - 1];
95
+ if (frame >= last.t) {
96
+ return (_d = (_c = last.s) != null ? _c : (_b = keyframes[keyframes.length - 2]) == null ? void 0 : _b.e) != null ? _d : [0];
97
+ }
98
+ for (let idx = 0; idx < keyframes.length - 1; idx++) {
99
+ const kf = keyframes[idx];
100
+ const next = keyframes[idx + 1];
101
+ if (frame >= kf.t && frame < next.t) {
102
+ const startVal = (_e = kf.s) != null ? _e : [0];
103
+ const endVal = (_g = (_f = kf.e) != null ? _f : next.s) != null ? _g : startVal;
104
+ if (kf.h === 1) {
105
+ return startVal;
106
+ }
107
+ const span = next.t - kf.t;
108
+ const linearT = span > 0 ? (frame - kf.t) / span : 0;
109
+ const dims = Math.max(startVal.length, endVal.length);
110
+ const out = new Array(dims);
111
+ for (let d = 0; d < dims; d++) {
112
+ const ox = componentAt((_h = kf.o) == null ? void 0 : _h.x, d);
113
+ const oy = componentAt((_i = kf.o) == null ? void 0 : _i.y, d);
114
+ const ix = componentAt((_j = kf.i) == null ? void 0 : _j.x, d);
115
+ const iy = componentAt((_k = kf.i) == null ? void 0 : _k.y, d);
116
+ const ease = getEasing(ox, oy, ix, iy);
117
+ const easedT = ease(linearT);
118
+ const s = (_m = (_l = startVal[d]) != null ? _l : startVal[0]) != null ? _m : 0;
119
+ const e = (_o = (_n = endVal[d]) != null ? _n : endVal[0]) != null ? _o : s;
120
+ out[d] = s + (e - s) * easedT;
121
+ }
122
+ return out;
123
+ }
124
+ }
125
+ return (_p = last.s) != null ? _p : [0];
126
+ }
127
+ function getAnimatedPosition(prop, frame) {
128
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
129
+ if (!prop) return [0, 0, 0];
130
+ if (prop.a === 0 || !Array.isArray(prop.k) || typeof prop.k[0] === "number") {
131
+ const k = prop.k;
132
+ return Array.isArray(k) ? k : [k, 0, 0];
133
+ }
134
+ const keyframes = prop.k;
135
+ if (keyframes.length === 0) return [0, 0, 0];
136
+ if (frame <= keyframes[0].t) return (_a = keyframes[0].s) != null ? _a : [0, 0, 0];
137
+ const last = keyframes[keyframes.length - 1];
138
+ if (frame >= last.t) return (_b = last.s) != null ? _b : [0, 0, 0];
139
+ for (let idx = 0; idx < keyframes.length - 1; idx++) {
140
+ const kf = keyframes[idx];
141
+ const next = keyframes[idx + 1];
142
+ if (frame >= kf.t && frame < next.t) {
143
+ const startVal = (_c = kf.s) != null ? _c : [0, 0, 0];
144
+ const endVal = (_e = (_d = kf.e) != null ? _d : next.s) != null ? _e : startVal;
145
+ if (kf.h === 1) return startVal;
146
+ const span = next.t - kf.t;
147
+ const linearT = span > 0 ? (frame - kf.t) / span : 0;
148
+ const ox = componentAt((_f = kf.o) == null ? void 0 : _f.x, 0);
149
+ const oy = componentAt((_g = kf.o) == null ? void 0 : _g.y, 0);
150
+ const ix = componentAt((_h = kf.i) == null ? void 0 : _h.x, 0);
151
+ const iy = componentAt((_i = kf.i) == null ? void 0 : _i.y, 0);
152
+ const easedT = getEasing(ox, oy, ix, iy)(linearT);
153
+ if (kf.to && kf.ti) {
154
+ const p0 = startVal;
155
+ const p3 = endVal;
156
+ const p1 = [p0[0] + kf.to[0], p0[1] + kf.to[1], ((_j = p0[2]) != null ? _j : 0) + ((_k = kf.to[2]) != null ? _k : 0)];
157
+ const p2 = [p3[0] + kf.ti[0], p3[1] + kf.ti[1], ((_l = p3[2]) != null ? _l : 0) + ((_m = kf.ti[2]) != null ? _m : 0)];
158
+ return cubicBezierPoint(p0, p1, p2, p3, easedT);
159
+ }
160
+ const dims = Math.max(startVal.length, endVal.length);
161
+ const out = new Array(dims);
162
+ for (let d = 0; d < dims; d++) {
163
+ const s = (_n = startVal[d]) != null ? _n : 0;
164
+ const e = (_o = endVal[d]) != null ? _o : s;
165
+ out[d] = s + (e - s) * easedT;
166
+ }
167
+ return out;
168
+ }
169
+ }
170
+ return (_p = last.s) != null ? _p : [0, 0, 0];
171
+ }
172
+ function cubicBezierPoint(p0, p1, p2, p3, t) {
173
+ var _a, _b, _c, _d;
174
+ const mt = 1 - t;
175
+ const a = mt * mt * mt;
176
+ const b = 3 * mt * mt * t;
177
+ const c = 3 * mt * t * t;
178
+ const d = t * t * t;
179
+ const dims = Math.max(p0.length, p1.length, p2.length, p3.length);
180
+ const out = new Array(dims);
181
+ for (let i = 0; i < dims; i++) {
182
+ out[i] = a * ((_a = p0[i]) != null ? _a : 0) + b * ((_b = p1[i]) != null ? _b : 0) + c * ((_c = p2[i]) != null ? _c : 0) + d * ((_d = p3[i]) != null ? _d : 0);
183
+ }
184
+ return out;
185
+ }
186
+ function lerpShapeValue(a, b, t) {
187
+ var _a, _b, _c, _d, _e, _f;
188
+ const count = Math.min(a.v.length, b.v.length);
189
+ const v = new Array(count);
190
+ const i = new Array(count);
191
+ const o = new Array(count);
192
+ for (let idx = 0; idx < count; idx++) {
193
+ const av = (_a = a.v[idx]) != null ? _a : [0, 0];
194
+ const bv = (_b = b.v[idx]) != null ? _b : av;
195
+ const ai = (_c = a.i[idx]) != null ? _c : [0, 0];
196
+ const bi = (_d = b.i[idx]) != null ? _d : ai;
197
+ const ao = (_e = a.o[idx]) != null ? _e : [0, 0];
198
+ const bo = (_f = b.o[idx]) != null ? _f : ao;
199
+ v[idx] = [av[0] + (bv[0] - av[0]) * t, av[1] + (bv[1] - av[1]) * t];
200
+ i[idx] = [ai[0] + (bi[0] - ai[0]) * t, ai[1] + (bi[1] - ai[1]) * t];
201
+ o[idx] = [ao[0] + (bo[0] - ao[0]) * t, ao[1] + (bo[1] - ao[1]) * t];
202
+ }
203
+ return { c: a.c, v, i, o };
204
+ }
205
+ function getAnimatedShape(prop, frame) {
206
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
207
+ const empty = { c: false, v: [], i: [], o: [] };
208
+ if (!prop) return empty;
209
+ if (prop.a === 0) {
210
+ return (_a = prop.k) != null ? _a : empty;
211
+ }
212
+ const keyframes = prop.k;
213
+ if (!keyframes || keyframes.length === 0) return empty;
214
+ if (frame <= keyframes[0].t) return (_c = (_b = keyframes[0].s) == null ? void 0 : _b[0]) != null ? _c : empty;
215
+ const last = keyframes[keyframes.length - 1];
216
+ if (frame >= last.t) return (_e = (_d = last.s) == null ? void 0 : _d[0]) != null ? _e : empty;
217
+ for (let idx = 0; idx < keyframes.length - 1; idx++) {
218
+ const kf = keyframes[idx];
219
+ const next = keyframes[idx + 1];
220
+ if (frame >= kf.t && frame < next.t) {
221
+ const startVal = (_g = (_f = kf.s) == null ? void 0 : _f[0]) != null ? _g : empty;
222
+ const endVal = (_k = (_j = (_h = kf.e) == null ? void 0 : _h[0]) != null ? _j : (_i = next.s) == null ? void 0 : _i[0]) != null ? _k : startVal;
223
+ if (kf.h === 1) return startVal;
224
+ const span = next.t - kf.t;
225
+ const linearT = span > 0 ? (frame - kf.t) / span : 0;
226
+ const ox = componentAt((_l = kf.o) == null ? void 0 : _l.x, 0);
227
+ const oy = componentAt((_m = kf.o) == null ? void 0 : _m.y, 0);
228
+ const ix = componentAt((_n = kf.i) == null ? void 0 : _n.x, 0);
229
+ const iy = componentAt((_o = kf.i) == null ? void 0 : _o.y, 0);
230
+ const easedT = getEasing(ox, oy, ix, iy)(linearT);
231
+ return lerpShapeValue(startVal, endVal, easedT);
232
+ }
233
+ }
234
+ return (_q = (_p = last.s) == null ? void 0 : _p[0]) != null ? _q : empty;
235
+ }
236
+
237
+ // src/_internal/animation/lottie/matrix.ts
238
+ function identity() {
239
+ return [1, 0, 0, 1, 0, 0];
240
+ }
241
+ function multiply(m1, m2) {
242
+ return [
243
+ m1[0] * m2[0] + m1[2] * m2[1],
244
+ m1[1] * m2[0] + m1[3] * m2[1],
245
+ m1[0] * m2[2] + m1[2] * m2[3],
246
+ m1[1] * m2[2] + m1[3] * m2[3],
247
+ m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
248
+ m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
249
+ ];
250
+ }
251
+ function translate(m, x, y) {
252
+ return multiply(m, [1, 0, 0, 1, x, y]);
253
+ }
254
+ function rotate(m, radians) {
255
+ const c = Math.cos(radians);
256
+ const s = Math.sin(radians);
257
+ return multiply(m, [c, s, -s, c, 0, 0]);
258
+ }
259
+ function scale(m, sx, sy) {
260
+ return multiply(m, [sx, 0, 0, sy, 0, 0]);
261
+ }
262
+ function skew(m, skewDeg, skewAxisDeg) {
263
+ if (!skewDeg) return m;
264
+ const axis = skewAxisDeg * Math.PI / 180;
265
+ const angle = -skewDeg * Math.PI / 180;
266
+ const sMat = multiply(
267
+ [Math.cos(axis), Math.sin(axis), -Math.sin(axis), Math.cos(axis), 0, 0],
268
+ [1, 0, Math.tan(angle), 1, 0, 0]
269
+ );
270
+ const back = [
271
+ Math.cos(-axis),
272
+ Math.sin(-axis),
273
+ -Math.sin(-axis),
274
+ Math.cos(-axis),
275
+ 0,
276
+ 0
277
+ ];
278
+ return multiply(m, multiply(sMat, back));
279
+ }
280
+ function applyToPoint(m, x, y) {
281
+ return [m[0] * x + m[2] * y + m[4], m[1] * x + m[3] * y + m[5]];
282
+ }
283
+
284
+ // src/_internal/animation/lottie/path.ts
285
+ var CIRCLE_K = 0.5522847498307936;
286
+ function shapeValueToBezierPath(sv) {
287
+ var _a, _b, _c, _d, _e, _f, _g;
288
+ const vertices = [];
289
+ const count = (_b = (_a = sv.v) == null ? void 0 : _a.length) != null ? _b : 0;
290
+ for (let idx = 0; idx < count; idx++) {
291
+ const v = (_c = sv.v[idx]) != null ? _c : [0, 0];
292
+ const i = (_e = (_d = sv.i) == null ? void 0 : _d[idx]) != null ? _e : [0, 0];
293
+ const o = (_g = (_f = sv.o) == null ? void 0 : _f[idx]) != null ? _g : [0, 0];
294
+ vertices.push({ v: [v[0], v[1]], i: [i[0], i[1]], o: [o[0], o[1]] });
295
+ }
296
+ return { closed: !!sv.c, vertices };
297
+ }
298
+ function rectToBezierPath(cx, cy, width, height, radius) {
299
+ const w = width / 2;
300
+ const h = height / 2;
301
+ const r = Math.max(0, Math.min(radius, w, h));
302
+ const k = r * CIRCLE_K;
303
+ if (r <= 0.01) {
304
+ return {
305
+ closed: true,
306
+ vertices: [
307
+ { v: [cx + w, cy - h], i: [0, 0], o: [0, 0] },
308
+ { v: [cx + w, cy + h], i: [0, 0], o: [0, 0] },
309
+ { v: [cx - w, cy + h], i: [0, 0], o: [0, 0] },
310
+ { v: [cx - w, cy - h], i: [0, 0], o: [0, 0] }
311
+ ]
312
+ };
313
+ }
314
+ return {
315
+ closed: true,
316
+ vertices: [
317
+ { v: [cx + w, cy - h + r], i: [0, -k], o: [0, 0] },
318
+ { v: [cx + w, cy + h - r], i: [0, 0], o: [0, k] },
319
+ { v: [cx + w - r, cy + h], i: [k, 0], o: [0, 0] },
320
+ { v: [cx - w + r, cy + h], i: [0, 0], o: [-k, 0] },
321
+ { v: [cx - w, cy + h - r], i: [0, k], o: [0, 0] },
322
+ { v: [cx - w, cy - h + r], i: [0, 0], o: [0, -k] },
323
+ { v: [cx - w + r, cy - h], i: [-k, 0], o: [0, 0] },
324
+ { v: [cx + w - r, cy - h], i: [0, 0], o: [k, 0] }
325
+ ]
326
+ };
327
+ }
328
+ function ellipseToBezierPath(cx, cy, width, height) {
329
+ const rx = width / 2;
330
+ const ry = height / 2;
331
+ const kx = rx * CIRCLE_K;
332
+ const ky = ry * CIRCLE_K;
333
+ return {
334
+ closed: true,
335
+ vertices: [
336
+ { v: [cx, cy - ry], i: [-kx, 0], o: [kx, 0] },
337
+ { v: [cx + rx, cy], i: [0, -ky], o: [0, ky] },
338
+ { v: [cx, cy + ry], i: [kx, 0], o: [-kx, 0] },
339
+ { v: [cx - rx, cy], i: [0, ky], o: [0, -ky] }
340
+ ]
341
+ };
342
+ }
343
+ function starToBezierPath(cx, cy, points, outerRadius, innerRadius, outerRoundness, innerRoundness, rotationDeg, isPolygon) {
344
+ const vertices = [];
345
+ const numPoints = Math.max(3, Math.round(points));
346
+ const angleStep = Math.PI / numPoints;
347
+ const startAngle = (rotationDeg - 90) * (Math.PI / 180);
348
+ const totalPoints = isPolygon ? numPoints : numPoints * 2;
349
+ for (let idx = 0; idx < totalPoints; idx++) {
350
+ const isOuter = isPolygon ? true : idx % 2 === 0;
351
+ const radius = isOuter ? outerRadius : innerRadius;
352
+ const angle = startAngle + idx * (isPolygon ? angleStep * 2 : angleStep);
353
+ const x = cx + radius * Math.cos(angle);
354
+ const y = cy + radius * Math.sin(angle);
355
+ const roundness = (isOuter ? outerRoundness : innerRoundness) / 100;
356
+ const tangentLen = radius * (Math.PI / (isPolygon ? numPoints : numPoints)) * roundness / 2;
357
+ const perpAngle = angle + Math.PI / 2;
358
+ const tx = Math.cos(perpAngle) * tangentLen;
359
+ const ty = Math.sin(perpAngle) * tangentLen;
360
+ vertices.push({ v: [x, y], i: [-tx, -ty], o: [tx, ty] });
361
+ }
362
+ return { closed: true, vertices };
363
+ }
364
+ function tracePathOnContext(ctx, path, m) {
365
+ const verts = path.vertices;
366
+ if (verts.length === 0) return;
367
+ const p0 = applyToPoint(m, verts[0].v[0], verts[0].v[1]);
368
+ ctx.moveTo(p0[0], p0[1]);
369
+ for (let idx = 0; idx < verts.length - 1; idx++) {
370
+ drawSegment(ctx, verts[idx], verts[idx + 1], m);
371
+ }
372
+ if (path.closed && verts.length > 1) {
373
+ drawSegment(ctx, verts[verts.length - 1], verts[0], m);
374
+ ctx.closePath();
375
+ }
376
+ }
377
+ function drawSegment(ctx, from, to, m) {
378
+ const c1 = applyToPoint(m, from.v[0] + from.o[0], from.v[1] + from.o[1]);
379
+ const c2 = applyToPoint(m, to.v[0] + to.i[0], to.v[1] + to.i[1]);
380
+ const end = applyToPoint(m, to.v[0], to.v[1]);
381
+ ctx.bezierCurveTo(c1[0], c1[1], c2[0], c2[1], end[0], end[1]);
382
+ }
383
+ function flattenSegment(from, to, samples) {
384
+ const pts = [];
385
+ const p0 = from.v;
386
+ const p1 = [from.v[0] + from.o[0], from.v[1] + from.o[1]];
387
+ const p2 = [to.v[0] + to.i[0], to.v[1] + to.i[1]];
388
+ const p3 = to.v;
389
+ for (let s = 1; s <= samples; s++) {
390
+ const t = s / samples;
391
+ const mt = 1 - t;
392
+ const a = mt * mt * mt;
393
+ const b = 3 * mt * mt * t;
394
+ const c = 3 * mt * t * t;
395
+ const d = t * t * t;
396
+ pts.push([
397
+ a * p0[0] + b * p1[0] + c * p2[0] + d * p3[0],
398
+ a * p0[1] + b * p1[1] + c * p2[1] + d * p3[1]
399
+ ]);
400
+ }
401
+ return pts;
402
+ }
403
+ function flattenPath(path, samplesPerSegment = 16) {
404
+ const verts = path.vertices;
405
+ const points = [];
406
+ if (verts.length === 0) return { points, closed: path.closed };
407
+ points.push(verts[0].v);
408
+ for (let idx = 0; idx < verts.length - 1; idx++) {
409
+ points.push(...flattenSegment(verts[idx], verts[idx + 1], samplesPerSegment));
410
+ }
411
+ if (path.closed && verts.length > 1) {
412
+ points.push(...flattenSegment(verts[verts.length - 1], verts[0], samplesPerSegment));
413
+ }
414
+ return { points, closed: path.closed };
415
+ }
416
+ function polylineLength(points) {
417
+ let len = 0;
418
+ for (let i = 1; i < points.length; i++) {
419
+ const dx = points[i][0] - points[i - 1][0];
420
+ const dy = points[i][1] - points[i - 1][1];
421
+ len += Math.hypot(dx, dy);
422
+ }
423
+ return len;
424
+ }
425
+ function trimPaths(paths, startPct, endPct, offsetPct, mode = 1) {
426
+ if (paths.length === 0) return paths;
427
+ if (mode === 2) {
428
+ const out = [];
429
+ for (const p of paths) {
430
+ out.push(...trimPaths([p], startPct, endPct, offsetPct, 1));
431
+ }
432
+ return out;
433
+ }
434
+ const flattened = paths.map((p) => flattenPath(p, 20));
435
+ const combined = flattened.map((f, idx) => ({ pathIdx: idx, points: f.points }));
436
+ const lengths = combined.map((c) => polylineLength(c.points));
437
+ const totalLength = lengths.reduce((a, b) => a + b, 0);
438
+ if (totalLength <= 0) return paths;
439
+ let s = (Math.min(startPct, endPct) / 100 + offsetPct / 360) % 1;
440
+ let e = (Math.max(startPct, endPct) / 100 + offsetPct / 360) % 1;
441
+ if (s < 0) s += 1;
442
+ if (e < 0) e += 1;
443
+ const startDist = s * totalLength;
444
+ const endDist = e * totalLength;
445
+ const wraps = endDist < startDist;
446
+ const resultVertices = [];
447
+ let cursor = 0;
448
+ const pushRange = (lo, hi) => {
449
+ for (const seg of combined) {
450
+ const segLen = polylineLength(seg.points);
451
+ const segStart = cursor;
452
+ const segEnd = cursor + segLen;
453
+ cursor = segEnd;
454
+ if (segEnd < lo || segStart > hi) continue;
455
+ let acc = segStart;
456
+ for (let i = 1; i < seg.points.length; i++) {
457
+ const p0 = seg.points[i - 1];
458
+ const p1 = seg.points[i];
459
+ const segPieceLen = Math.hypot(p1[0] - p0[0], p1[1] - p0[1]);
460
+ const pieceStart = acc;
461
+ const pieceEnd = acc + segPieceLen;
462
+ acc = pieceEnd;
463
+ if (pieceEnd < lo || pieceStart > hi) continue;
464
+ const clipLo = Math.max(lo, pieceStart);
465
+ const clipHi = Math.min(hi, pieceEnd);
466
+ const t0 = segPieceLen > 0 ? (clipLo - pieceStart) / segPieceLen : 0;
467
+ const t1 = segPieceLen > 0 ? (clipHi - pieceStart) / segPieceLen : 0;
468
+ const pt0 = [
469
+ p0[0] + (p1[0] - p0[0]) * t0,
470
+ p0[1] + (p1[1] - p0[1]) * t0
471
+ ];
472
+ const pt1 = [
473
+ p0[0] + (p1[0] - p0[0]) * t1,
474
+ p0[1] + (p1[1] - p0[1]) * t1
475
+ ];
476
+ if (resultVertices.length === 0 || resultVertices[resultVertices.length - 1].v[0] !== pt0[0] || resultVertices[resultVertices.length - 1].v[1] !== pt0[1]) {
477
+ resultVertices.push({ v: pt0, i: [0, 0], o: [0, 0] });
478
+ }
479
+ resultVertices.push({ v: pt1, i: [0, 0], o: [0, 0] });
480
+ }
481
+ }
482
+ cursor = 0;
483
+ };
484
+ if (!wraps) {
485
+ pushRange(startDist, endDist);
486
+ } else {
487
+ pushRange(startDist, totalLength);
488
+ pushRange(0, endDist);
489
+ }
490
+ return [{ closed: false, vertices: resultVertices }];
491
+ }
492
+
493
+ // src/_internal/animation/lottie/paint.ts
494
+ function colorToCss(rgb, opacity01) {
495
+ var _a, _b, _c;
496
+ const r = Math.round(((_a = rgb[0]) != null ? _a : 0) * (rgb[0] <= 1 ? 255 : 1));
497
+ const g = Math.round(((_b = rgb[1]) != null ? _b : 0) * (rgb[1] <= 1 ? 255 : 1));
498
+ const b = Math.round(((_c = rgb[2]) != null ? _c : 0) * (rgb[2] <= 1 ? 255 : 1));
499
+ const a = (rgb[3] !== void 0 ? rgb[3] : 1) * opacity01;
500
+ return `rgba(${clamp255(r)}, ${clamp255(g)}, ${clamp255(b)}, ${clampAlpha(a)})`;
501
+ }
502
+ function clamp255(v) {
503
+ return Math.max(0, Math.min(255, v));
504
+ }
505
+ function clampAlpha(v) {
506
+ return Math.max(0, Math.min(1, v));
507
+ }
508
+ function parseGradientStops(g, frame) {
509
+ var _a, _b, _c, _d;
510
+ const flat = getAnimatedValue(g.k, frame);
511
+ const stopCount = g.p;
512
+ const stops = [];
513
+ for (let i = 0; i < stopCount; i++) {
514
+ const base = i * 4;
515
+ stops.push({
516
+ offset: (_a = flat[base]) != null ? _a : i / Math.max(1, stopCount - 1),
517
+ r: ((_b = flat[base + 1]) != null ? _b : 0) * 255,
518
+ g: ((_c = flat[base + 2]) != null ? _c : 0) * 255,
519
+ b: ((_d = flat[base + 3]) != null ? _d : 0) * 255,
520
+ a: 1
521
+ });
522
+ }
523
+ const alphaStart = stopCount * 4;
524
+ if (flat.length > alphaStart) {
525
+ const alphaCount = (flat.length - alphaStart) / 2;
526
+ for (let i = 0; i < alphaCount; i++) {
527
+ const base = alphaStart + i * 2;
528
+ const offset = flat[base];
529
+ const alpha = flat[base + 1];
530
+ let nearest = stops[0];
531
+ let nearestDist = Infinity;
532
+ for (const s of stops) {
533
+ const dist = Math.abs(s.offset - offset);
534
+ if (dist < nearestDist) {
535
+ nearestDist = dist;
536
+ nearest = s;
537
+ }
538
+ }
539
+ if (nearest) nearest.a = alpha;
540
+ }
541
+ }
542
+ return stops;
543
+ }
544
+ function buildGradient(ctx, item, frame, m, opacity01) {
545
+ var _a, _b, _c, _d, _e, _f;
546
+ const start = getAnimatedValue(item.s, frame);
547
+ const end = getAnimatedValue(item.e, frame);
548
+ const [sx, sy] = applyToPoint(m, (_a = start[0]) != null ? _a : 0, (_b = start[1]) != null ? _b : 0);
549
+ const [ex, ey] = applyToPoint(m, (_c = end[0]) != null ? _c : 0, (_d = end[1]) != null ? _d : 0);
550
+ let gradient;
551
+ if (item.t === 2) {
552
+ const radius = Math.hypot(ex - sx, ey - sy) || 1;
553
+ const hRaw = item.h ? (_e = getAnimatedValue(item.h, frame)[0]) != null ? _e : 0 : 0;
554
+ const h = Math.max(-0.99, Math.min(0.99, Math.abs(hRaw) > 1 ? hRaw / 100 : hRaw));
555
+ const aDeg = item.a ? (_f = getAnimatedValue(item.a, frame)[0]) != null ? _f : 0 : 0;
556
+ if (h !== 0) {
557
+ const baseAngle = Math.atan2(ey - sy, ex - sx);
558
+ const angle = baseAngle + aDeg * Math.PI / 180;
559
+ const hx = sx + Math.cos(angle) * h * radius;
560
+ const hy = sy + Math.sin(angle) * h * radius;
561
+ gradient = ctx.createRadialGradient(hx, hy, 0, sx, sy, radius);
562
+ } else {
563
+ gradient = ctx.createRadialGradient(sx, sy, 0, sx, sy, radius);
564
+ }
565
+ } else {
566
+ gradient = ctx.createLinearGradient(sx, sy, ex, ey);
567
+ }
568
+ const stops = parseGradientStops(item.g, frame);
569
+ for (const stop of stops) {
570
+ gradient.addColorStop(
571
+ Math.max(0, Math.min(1, stop.offset)),
572
+ `rgba(${clamp255(stop.r)}, ${clamp255(stop.g)}, ${clamp255(stop.b)}, ${clampAlpha(
573
+ stop.a * opacity01
574
+ )})`
575
+ );
576
+ }
577
+ return gradient;
578
+ }
579
+ var LINE_CAP = ["butt", "round", "square"];
580
+ var LINE_JOIN = ["miter", "round", "bevel"];
581
+ function applyStrokeStyle(ctx, item, frame, m) {
582
+ var _a, _b, _c, _d, _e, _f, _g;
583
+ const widthArr = getAnimatedValue(item.w, frame);
584
+ const scaleFactor = Math.hypot(m[0], m[1]);
585
+ ctx.lineWidth = Math.max(0, ((_a = widthArr[0]) != null ? _a : 1) * scaleFactor);
586
+ ctx.lineCap = (_c = LINE_CAP[((_b = item.lc) != null ? _b : 2) - 1]) != null ? _c : "round";
587
+ ctx.lineJoin = (_e = LINE_JOIN[((_d = item.lj) != null ? _d : 2) - 1]) != null ? _e : "round";
588
+ ctx.miterLimit = (_f = item.ml) != null ? _f : 4;
589
+ if (item.d && item.d.length > 0) {
590
+ const dashArr = [];
591
+ let dashOffset = 0;
592
+ for (const d of item.d) {
593
+ const val = (_g = getAnimatedValue(d.v, frame)[0]) != null ? _g : 0;
594
+ if (d.n === "o") {
595
+ dashOffset = val * scaleFactor;
596
+ } else {
597
+ dashArr.push(val * scaleFactor);
598
+ }
599
+ }
600
+ ctx.setLineDash(dashArr.length > 0 ? dashArr : []);
601
+ ctx.lineDashOffset = dashOffset;
602
+ } else {
603
+ ctx.setLineDash([]);
604
+ }
605
+ }
606
+
607
+ // src/_internal/animation/lottie/shapeGroup.ts
608
+ function computeLocalTransform(t, frame) {
609
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
610
+ if (!t) return { matrix: identity(), opacity: 1 };
611
+ let anchor = [0, 0];
612
+ let position = [0, 0];
613
+ let scaleVal = [100, 100];
614
+ let rotationDeg = 0;
615
+ let skewDeg = 0;
616
+ let skewAxisDeg = 0;
617
+ let opacityPct = 100;
618
+ if (t.a) anchor = getAnimatedValue(t.a, frame);
619
+ if (t.p) {
620
+ if (t.p.s && t.p.x && t.p.y) {
621
+ const px = (_a = getAnimatedValue(t.p.x, frame)[0]) != null ? _a : 0;
622
+ const py = (_b = getAnimatedValue(t.p.y, frame)[0]) != null ? _b : 0;
623
+ position = [px, py];
624
+ } else {
625
+ position = getAnimatedPosition(t.p, frame);
626
+ }
627
+ }
628
+ if (t.s) scaleVal = getAnimatedValue(t.s, frame);
629
+ if (t.r) rotationDeg = (_c = getAnimatedValue(t.r, frame)[0]) != null ? _c : 0;
630
+ if (t.sk) skewDeg = (_d = getAnimatedValue(t.sk, frame)[0]) != null ? _d : 0;
631
+ if (t.sa) skewAxisDeg = (_e = getAnimatedValue(t.sa, frame)[0]) != null ? _e : 0;
632
+ if (t.o) opacityPct = (_f = getAnimatedValue(t.o, frame)[0]) != null ? _f : 100;
633
+ let m = identity();
634
+ m = translate(m, (_g = position[0]) != null ? _g : 0, (_h = position[1]) != null ? _h : 0);
635
+ m = rotate(m, (rotationDeg != null ? rotationDeg : 0) * Math.PI / 180);
636
+ if (skewDeg) m = skew(m, skewDeg, skewAxisDeg);
637
+ m = scale(m, ((_i = scaleVal[0]) != null ? _i : 100) / 100, ((_j = scaleVal[1]) != null ? _j : 100) / 100);
638
+ m = translate(m, -((_k = anchor[0]) != null ? _k : 0), -((_l = anchor[1]) != null ? _l : 0));
639
+ return { matrix: m, opacity: Math.max(0, Math.min(1, opacityPct / 100)) };
640
+ }
641
+ function buildShapePath(item, frame) {
642
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
643
+ switch (item.ty) {
644
+ case "sh": {
645
+ const sv = getAnimatedShape(item.ks, frame);
646
+ return shapeValueToBezierPath(sv);
647
+ }
648
+ case "rc": {
649
+ const rc = item;
650
+ const pos = getAnimatedValue(rc.p, frame);
651
+ const size = getAnimatedValue(rc.s, frame);
652
+ const radius = (_a = getAnimatedValue(rc.r, frame)[0]) != null ? _a : 0;
653
+ return rectToBezierPath((_b = pos[0]) != null ? _b : 0, (_c = pos[1]) != null ? _c : 0, (_d = size[0]) != null ? _d : 0, (_e = size[1]) != null ? _e : 0, radius);
654
+ }
655
+ case "el": {
656
+ const el = item;
657
+ const pos = getAnimatedValue(el.p, frame);
658
+ const size = getAnimatedValue(el.s, frame);
659
+ return ellipseToBezierPath((_f = pos[0]) != null ? _f : 0, (_g = pos[1]) != null ? _g : 0, (_h = size[0]) != null ? _h : 0, (_i = size[1]) != null ? _i : 0);
660
+ }
661
+ case "sr": {
662
+ const sr = item;
663
+ const pos = getAnimatedValue(sr.p, frame);
664
+ const outerRadius = (_j = getAnimatedValue(sr.or, frame)[0]) != null ? _j : 0;
665
+ const innerRadius = sr.ir ? (_k = getAnimatedValue(sr.ir, frame)[0]) != null ? _k : 0 : outerRadius * 0.5;
666
+ const outerRoundness = (_l = getAnimatedValue(sr.os, frame)[0]) != null ? _l : 0;
667
+ const innerRoundness = sr.is ? (_m = getAnimatedValue(sr.is, frame)[0]) != null ? _m : 0 : 0;
668
+ const rotationDeg = (_n = getAnimatedValue(sr.r, frame)[0]) != null ? _n : 0;
669
+ const points = (_o = getAnimatedValue(sr.pt, frame)[0]) != null ? _o : 5;
670
+ return starToBezierPath(
671
+ (_p = pos[0]) != null ? _p : 0,
672
+ (_q = pos[1]) != null ? _q : 0,
673
+ points,
674
+ outerRadius,
675
+ innerRadius,
676
+ outerRoundness,
677
+ innerRoundness,
678
+ rotationDeg,
679
+ sr.sy === 2
680
+ );
681
+ }
682
+ default:
683
+ return null;
684
+ }
685
+ }
686
+ function tracePathsAsOne(ctx, paths, m) {
687
+ ctx.beginPath();
688
+ for (const p of paths) tracePathOnContext(ctx, p, m);
689
+ }
690
+ function paintFill(rc, paths, m, fillStyle, mergeMode, fillRule = "nonzero") {
691
+ var _a;
692
+ if (paths.length === 0) return;
693
+ const rule = mergeMode === 5 ? "evenodd" : fillRule;
694
+ if (mergeMode === 3 || mergeMode === 4) {
695
+ const sctx = rc.scratchCtx;
696
+ sctx.save();
697
+ sctx.setTransform(1, 0, 0, 1, 0, 0);
698
+ sctx.clearRect(0, 0, rc.canvasWidth, rc.canvasHeight);
699
+ sctx.beginPath();
700
+ tracePathOnContext(sctx, paths[0], m);
701
+ sctx.fillStyle = fillStyle;
702
+ sctx.fill(rule);
703
+ for (let i = 1; i < paths.length; i++) {
704
+ sctx.globalCompositeOperation = mergeMode === 3 ? "destination-out" : "destination-in";
705
+ sctx.beginPath();
706
+ tracePathOnContext(sctx, paths[i], m);
707
+ sctx.fillStyle = fillStyle;
708
+ sctx.fill(rule);
709
+ }
710
+ sctx.restore();
711
+ rc.ctx.drawImage(rc.scratchCanvas, 0, 0);
712
+ return;
713
+ }
714
+ const hasPerPathOpacity = paths.some((p) => p.opacity !== void 0 && p.opacity !== 1);
715
+ if (hasPerPathOpacity) {
716
+ const baseAlpha = rc.ctx.globalAlpha;
717
+ rc.ctx.fillStyle = fillStyle;
718
+ for (const p of paths) {
719
+ rc.ctx.beginPath();
720
+ tracePathOnContext(rc.ctx, p, m);
721
+ rc.ctx.globalAlpha = baseAlpha * ((_a = p.opacity) != null ? _a : 1);
722
+ rc.ctx.fill(rule);
723
+ }
724
+ rc.ctx.globalAlpha = baseAlpha;
725
+ return;
726
+ }
727
+ tracePathsAsOne(rc.ctx, paths, m);
728
+ rc.ctx.fillStyle = fillStyle;
729
+ rc.ctx.fill(rule);
730
+ }
731
+ function paintStroke(rc, paths, m, strokeStyle) {
732
+ var _a;
733
+ if (paths.length === 0) return;
734
+ const hasPerPathOpacity = paths.some((p) => p.opacity !== void 0 && p.opacity !== 1);
735
+ if (hasPerPathOpacity) {
736
+ const baseAlpha = rc.ctx.globalAlpha;
737
+ rc.ctx.strokeStyle = strokeStyle;
738
+ for (const p of paths) {
739
+ rc.ctx.beginPath();
740
+ tracePathOnContext(rc.ctx, p, m);
741
+ rc.ctx.globalAlpha = baseAlpha * ((_a = p.opacity) != null ? _a : 1);
742
+ rc.ctx.stroke();
743
+ }
744
+ rc.ctx.globalAlpha = baseAlpha;
745
+ return;
746
+ }
747
+ tracePathsAsOne(rc.ctx, paths, m);
748
+ rc.ctx.strokeStyle = strokeStyle;
749
+ rc.ctx.stroke();
750
+ }
751
+ function renderShapeItems(rc, items, parentMatrix, parentOpacity) {
752
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
753
+ const trItem = items.find((i) => i.ty === "tr");
754
+ const { matrix: groupMatrix, opacity: groupOpacity } = computeLocalTransform(
755
+ trItem,
756
+ rc.frame
757
+ );
758
+ const localMatrix = multiply(parentMatrix, groupMatrix);
759
+ const localOpacity = parentOpacity * groupOpacity;
760
+ let currentPaths = [];
761
+ let mergeMode = null;
762
+ const drawOps = [];
763
+ for (let idx = 0; idx < items.length; idx++) {
764
+ const item = items[idx];
765
+ if (item.hd) continue;
766
+ switch (item.ty) {
767
+ case "tr":
768
+ continue;
769
+ case "gr": {
770
+ const group = item;
771
+ drawOps.push(() => renderShapeItems(rc, group.it, localMatrix, localOpacity));
772
+ break;
773
+ }
774
+ case "sh":
775
+ case "rc":
776
+ case "el":
777
+ case "sr": {
778
+ const path = buildShapePath(item, rc.frame);
779
+ if (path) currentPaths = [...currentPaths, path];
780
+ break;
781
+ }
782
+ case "tm": {
783
+ const tm = item;
784
+ const s = (_a = getAnimatedValue(tm.s, rc.frame)[0]) != null ? _a : 0;
785
+ const e = (_b = getAnimatedValue(tm.e, rc.frame)[0]) != null ? _b : 100;
786
+ const o = (_c = getAnimatedValue(tm.o, rc.frame)[0]) != null ? _c : 0;
787
+ currentPaths = trimPaths(currentPaths, s, e, o, (_d = tm.m) != null ? _d : 1);
788
+ break;
789
+ }
790
+ case "rp": {
791
+ const rp = item;
792
+ const copies = Math.max(0, Math.round((_e = getAnimatedValue(rp.c, rc.frame)[0]) != null ? _e : 0));
793
+ const offset = (_f = getAnimatedValue(rp.o, rc.frame)[0]) != null ? _f : 0;
794
+ const rTr = rp.tr;
795
+ const repPos = getAnimatedValue(rTr.p, rc.frame);
796
+ getAnimatedValue(rTr.a, rc.frame);
797
+ const repScale = getAnimatedValue(rTr.s, rc.frame);
798
+ const repRotation = (_g = getAnimatedValue(rTr.r, rc.frame)[0]) != null ? _g : 0;
799
+ const startOpacityPct = rTr.so ? (_h = getAnimatedValue(rTr.so, rc.frame)[0]) != null ? _h : 100 : 100;
800
+ const endOpacityPct = rTr.eo ? (_i = getAnimatedValue(rTr.eo, rc.frame)[0]) != null ? _i : 100 : 100;
801
+ const basePaths = currentPaths;
802
+ const repeated = [];
803
+ for (let c = 0; c < copies; c++) {
804
+ const n = c + offset;
805
+ const copyOpacity = copies > 1 ? (startOpacityPct + (endOpacityPct - startOpacityPct) * c / (copies - 1)) / 100 : startOpacityPct / 100;
806
+ let compound = identity();
807
+ for (let k = 0; k < Math.abs(n); k++) {
808
+ compound = translate(compound, (_j = repPos[0]) != null ? _j : 0, (_k = repPos[1]) != null ? _k : 0);
809
+ compound = rotate(compound, (repRotation != null ? repRotation : 0) * Math.PI / 180);
810
+ compound = scale(compound, ((_l = repScale[0]) != null ? _l : 100) / 100, ((_m = repScale[1]) != null ? _m : 100) / 100);
811
+ }
812
+ for (const p of basePaths) {
813
+ repeated.push({
814
+ closed: p.closed,
815
+ opacity: copyOpacity,
816
+ vertices: p.vertices.map((v) => {
817
+ const [vx, vy] = applyMat(compound, v.v[0], v.v[1]);
818
+ const [ix, iy] = applyMatDelta(compound, v.i[0], v.i[1]);
819
+ const [ox, oy] = applyMatDelta(compound, v.o[0], v.o[1]);
820
+ return { v: [vx, vy], i: [ix, iy], o: [ox, oy] };
821
+ })
822
+ });
823
+ }
824
+ }
825
+ currentPaths = repeated;
826
+ break;
827
+ }
828
+ case "mm": {
829
+ mergeMode = (_n = item.mm) != null ? _n : 1;
830
+ break;
831
+ }
832
+ case "fl": {
833
+ const fl = item;
834
+ const paths = currentPaths;
835
+ const mm = mergeMode;
836
+ const fillRule = fl.r === 2 ? "evenodd" : "nonzero";
837
+ drawOps.push(() => {
838
+ var _a2;
839
+ const color = getAnimatedValue(fl.c, rc.frame);
840
+ const opacity = ((_a2 = getAnimatedValue(fl.o, rc.frame)[0]) != null ? _a2 : 100) / 100;
841
+ const css = colorToCss(color, opacity * localOpacity);
842
+ paintFill(rc, paths, localMatrix, css, mm, fillRule);
843
+ });
844
+ break;
845
+ }
846
+ case "gf": {
847
+ const gf = item;
848
+ const paths = currentPaths;
849
+ const mm = mergeMode;
850
+ const fillRule = gf.r === 2 ? "evenodd" : "nonzero";
851
+ drawOps.push(() => {
852
+ var _a2;
853
+ const opacity = ((_a2 = getAnimatedValue(gf.o, rc.frame)[0]) != null ? _a2 : 100) / 100;
854
+ const gradient = buildGradient(rc.ctx, gf, rc.frame, localMatrix, opacity * localOpacity);
855
+ paintFill(rc, paths, localMatrix, gradient, mm, fillRule);
856
+ });
857
+ break;
858
+ }
859
+ case "st": {
860
+ const st = item;
861
+ const paths = currentPaths;
862
+ drawOps.push(() => {
863
+ var _a2;
864
+ const color = getAnimatedValue(st.c, rc.frame);
865
+ const opacity = ((_a2 = getAnimatedValue(st.o, rc.frame)[0]) != null ? _a2 : 100) / 100;
866
+ const css = colorToCss(color, opacity * localOpacity);
867
+ applyStrokeStyle(rc.ctx, st, rc.frame, localMatrix);
868
+ paintStroke(rc, paths, localMatrix, css);
869
+ });
870
+ break;
871
+ }
872
+ case "gs": {
873
+ const gs = item;
874
+ const paths = currentPaths;
875
+ drawOps.push(() => {
876
+ var _a2;
877
+ const opacity = ((_a2 = getAnimatedValue(gs.o, rc.frame)[0]) != null ? _a2 : 100) / 100;
878
+ const gradient = buildGradient(rc.ctx, gs, rc.frame, localMatrix, opacity * localOpacity);
879
+ applyStrokeStyle(rc.ctx, gs, rc.frame, localMatrix);
880
+ paintStroke(rc, paths, localMatrix, gradient);
881
+ });
882
+ break;
883
+ }
884
+ }
885
+ }
886
+ for (let i = drawOps.length - 1; i >= 0; i--) {
887
+ drawOps[i]();
888
+ }
889
+ }
890
+ function applyMat(m, x, y) {
891
+ return [m[0] * x + m[2] * y + m[4], m[1] * x + m[3] * y + m[5]];
892
+ }
893
+ function applyMatDelta(m, x, y) {
894
+ return [m[0] * x + m[2] * y, m[1] * x + m[3] * y];
895
+ }
896
+
897
+ // src/_internal/animation/lottie/engine.ts
898
+ var BLEND_MODES = {
899
+ 0: "source-over",
900
+ 1: "multiply",
901
+ 2: "screen",
902
+ 3: "overlay",
903
+ 4: "darken",
904
+ 5: "lighten",
905
+ 6: "color-dodge",
906
+ 7: "color-burn",
907
+ 8: "hard-light",
908
+ 9: "soft-light",
909
+ 10: "difference",
910
+ 11: "exclusion",
911
+ 12: "hue",
912
+ 13: "saturation",
913
+ 14: "color",
914
+ 15: "luminosity"
915
+ };
916
+ function makeCanvas(w, h) {
917
+ let canvas;
918
+ if (typeof OffscreenCanvas !== "undefined") {
919
+ canvas = new OffscreenCanvas(Math.max(1, w), Math.max(1, h));
920
+ } else {
921
+ canvas = document.createElement("canvas");
922
+ canvas.width = Math.max(1, w);
923
+ canvas.height = Math.max(1, h);
924
+ }
925
+ const ctx = canvas.getContext("2d");
926
+ return { canvas, ctx };
927
+ }
928
+ function lumaToAlphaMask(source, w, h) {
929
+ const { canvas, ctx } = makeCanvas(w, h);
930
+ ctx.drawImage(source, 0, 0);
931
+ const img = ctx.getImageData(0, 0, Math.max(1, w), Math.max(1, h));
932
+ const d = img.data;
933
+ for (let i = 0; i < d.length; i += 4) {
934
+ const luma = 0.2126 * d[i] + 0.7152 * d[i + 1] + 0.0722 * d[i + 2];
935
+ d[i + 3] = Math.round(luma / 255 * d[i + 3]);
936
+ }
937
+ ctx.putImageData(img, 0, 0);
938
+ return canvas;
939
+ }
940
+ function getLayerMatrix(layer, layersByInd, frame, cache) {
941
+ var _a;
942
+ const ind = (_a = layer.ind) != null ? _a : -1;
943
+ const cached = cache.get(ind);
944
+ if (cached) return cached;
945
+ const { matrix: own } = computeLocalTransform(layer.ks, frame);
946
+ let result = own;
947
+ if (layer.parent != null) {
948
+ const parent = layersByInd.get(layer.parent);
949
+ if (parent && parent !== layer) {
950
+ const parentMatrix = getLayerMatrix(parent, layersByInd, frame, cache);
951
+ result = multiply(parentMatrix, own);
952
+ }
953
+ }
954
+ if (ind >= 0) cache.set(ind, result);
955
+ return result;
956
+ }
957
+ function applyMasks(ctx, layer, matrix, frame, canvasWidth, canvasHeight) {
958
+ var _a;
959
+ const masks = layer.masksProperties;
960
+ if (!masks || masks.length === 0) return false;
961
+ const active = masks.filter((m) => {
962
+ var _a2;
963
+ return ((_a2 = m.mode) != null ? _a2 : "a") !== "n";
964
+ });
965
+ if (active.length === 0) return false;
966
+ let clipped = false;
967
+ let additiveBatch = [];
968
+ const flushAdditive = () => {
969
+ if (additiveBatch.length === 0) return;
970
+ ctx.beginPath();
971
+ for (const mask of additiveBatch) {
972
+ const sv = getAnimatedShape(mask.pt, frame);
973
+ tracePathOnContext(ctx, shapeValueToBezierPath(sv), matrix);
974
+ }
975
+ ctx.clip("nonzero");
976
+ clipped = true;
977
+ additiveBatch = [];
978
+ };
979
+ for (const mask of active) {
980
+ const mode = (_a = mask.mode) != null ? _a : "a";
981
+ const isAdditive = (mode === "a" || mode === "l") && !mask.inv;
982
+ if (isAdditive) {
983
+ additiveBatch.push(mask);
984
+ continue;
985
+ }
986
+ flushAdditive();
987
+ const sv = getAnimatedShape(mask.pt, frame);
988
+ const path = shapeValueToBezierPath(sv);
989
+ const keepOutside = mode === "s" || mask.inv;
990
+ ctx.beginPath();
991
+ if (keepOutside) {
992
+ ctx.rect(0, 0, canvasWidth, canvasHeight);
993
+ tracePathOnContext(ctx, path, matrix);
994
+ ctx.clip("evenodd");
995
+ } else {
996
+ tracePathOnContext(ctx, path, matrix);
997
+ ctx.clip("nonzero");
998
+ }
999
+ clipped = true;
1000
+ }
1001
+ flushAdditive();
1002
+ return clipped;
1003
+ }
1004
+ function renderSolidLayer(ctx, layer, matrix) {
1005
+ var _a, _b, _c;
1006
+ const w = (_a = layer.sw) != null ? _a : 0;
1007
+ const h = (_b = layer.sh) != null ? _b : 0;
1008
+ ctx.save();
1009
+ ctx.beginPath();
1010
+ const p0 = applyPoint(matrix, 0, 0);
1011
+ const p1 = applyPoint(matrix, w, 0);
1012
+ const p2 = applyPoint(matrix, w, h);
1013
+ const p3 = applyPoint(matrix, 0, h);
1014
+ ctx.moveTo(p0[0], p0[1]);
1015
+ ctx.lineTo(p1[0], p1[1]);
1016
+ ctx.lineTo(p2[0], p2[1]);
1017
+ ctx.lineTo(p3[0], p3[1]);
1018
+ ctx.closePath();
1019
+ ctx.fillStyle = (_c = layer.sc) != null ? _c : "#000000";
1020
+ ctx.fill();
1021
+ ctx.restore();
1022
+ }
1023
+ function applyPoint(m, x, y) {
1024
+ return [m[0] * x + m[2] * y + m[4], m[1] * x + m[3] * y + m[5]];
1025
+ }
1026
+ function resolveImageSrc(asset) {
1027
+ var _a, _b;
1028
+ if (asset.e === 1) {
1029
+ if (!asset.p) return null;
1030
+ if (asset.p.startsWith("data:")) return asset.p;
1031
+ return `data:image/png;base64,${asset.p}`;
1032
+ }
1033
+ if (asset.u) return asset.u + ((_a = asset.p) != null ? _a : "");
1034
+ return (_b = asset.p) != null ? _b : null;
1035
+ }
1036
+ function renderImageLayer(ctx, asset, matrix, opts) {
1037
+ var _a, _b;
1038
+ const src = resolveImageSrc(asset);
1039
+ if (!src) return;
1040
+ let img = opts.imageCache.get(asset.id);
1041
+ if (!img) {
1042
+ img = new Image();
1043
+ img.src = src;
1044
+ opts.imageCache.set(asset.id, img);
1045
+ img.addEventListener("load", () => {
1046
+ var _a2;
1047
+ return (_a2 = opts.onAssetLoaded) == null ? void 0 : _a2.call(opts);
1048
+ });
1049
+ return;
1050
+ }
1051
+ if (!img.complete || img.naturalWidth === 0) return;
1052
+ const w = (_a = asset.w) != null ? _a : img.naturalWidth;
1053
+ const h = (_b = asset.h) != null ? _b : img.naturalHeight;
1054
+ ctx.save();
1055
+ ctx.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
1056
+ ctx.drawImage(img, 0, 0, w, h);
1057
+ ctx.restore();
1058
+ }
1059
+ function renderLayers(targetCtx, layers, assetsById, parentMatrix, parentOpacity, docFrame, opts) {
1060
+ var _a, _b, _c, _d;
1061
+ const layersByInd = /* @__PURE__ */ new Map();
1062
+ for (const l of layers) {
1063
+ if (l.ind != null) layersByInd.set(l.ind, l);
1064
+ }
1065
+ const matrixCache = /* @__PURE__ */ new Map();
1066
+ const isLayerActive = (layer) => {
1067
+ var _a2, _b2;
1068
+ if (layer.hd) return false;
1069
+ const startFrame = (_a2 = layer.ip) != null ? _a2 : 0;
1070
+ const endFrame = (_b2 = layer.op) != null ? _b2 : Infinity;
1071
+ return docFrame >= startFrame && docFrame < endFrame;
1072
+ };
1073
+ const renderMatteSource = (matteLayer) => {
1074
+ if (!isLayerActive(matteLayer)) return null;
1075
+ const ownMatrix = getLayerMatrix(matteLayer, layersByInd, docFrame, matrixCache);
1076
+ const matrix = multiply(parentMatrix, ownMatrix);
1077
+ const { opacity: ownOpacity } = computeLocalTransform(matteLayer.ks, docFrame);
1078
+ const opacity = parentOpacity * ownOpacity;
1079
+ const scratch = makeCanvas(opts.canvasWidth, opts.canvasHeight);
1080
+ scratch.ctx.save();
1081
+ scratch.ctx.globalAlpha = opacity;
1082
+ applyMasks(scratch.ctx, matteLayer, matrix, docFrame, opts.canvasWidth, opts.canvasHeight);
1083
+ renderSingleLayer(scratch.ctx, matteLayer, assetsById, matrix, 1, docFrame, opts);
1084
+ scratch.ctx.restore();
1085
+ return scratch;
1086
+ };
1087
+ for (let idx = layers.length - 1; idx >= 0; idx--) {
1088
+ const layer = layers[idx];
1089
+ if (layer.hd) continue;
1090
+ if (!isLayerActive(layer)) continue;
1091
+ if (layer.td === 1) continue;
1092
+ const ownMatrix = getLayerMatrix(layer, layersByInd, docFrame, matrixCache);
1093
+ const matrix = multiply(parentMatrix, ownMatrix);
1094
+ const { opacity: ownOpacity } = computeLocalTransform(layer.ks, docFrame);
1095
+ const opacity = parentOpacity * ownOpacity;
1096
+ const matteLayer = layer.tt && idx > 0 ? layers[idx - 1] : null;
1097
+ const pendingMatte = matteLayer && matteLayer.td === 1 ? renderMatteSource(matteLayer) : null;
1098
+ const needsMatte = !!layer.tt && !!pendingMatte;
1099
+ let drawCtx;
1100
+ let scratch = null;
1101
+ if (needsMatte) {
1102
+ scratch = makeCanvas(opts.canvasWidth, opts.canvasHeight);
1103
+ drawCtx = scratch.ctx;
1104
+ } else {
1105
+ drawCtx = targetCtx;
1106
+ }
1107
+ drawCtx.save();
1108
+ if (drawCtx === targetCtx) {
1109
+ drawCtx.globalAlpha = opacity;
1110
+ drawCtx.globalCompositeOperation = (_b = BLEND_MODES[(_a = layer.bm) != null ? _a : 0]) != null ? _b : "source-over";
1111
+ } else {
1112
+ drawCtx.globalAlpha = opacity;
1113
+ }
1114
+ applyMasks(drawCtx, layer, matrix, docFrame, opts.canvasWidth, opts.canvasHeight);
1115
+ renderSingleLayer(drawCtx, layer, assetsById, matrix, 1, docFrame, opts);
1116
+ drawCtx.restore();
1117
+ if (needsMatte && scratch && pendingMatte) {
1118
+ const tt = layer.tt;
1119
+ const isLuma = tt === 3 || tt === 4;
1120
+ const matteSource = isLuma ? lumaToAlphaMask(pendingMatte.canvas, opts.canvasWidth, opts.canvasHeight) : pendingMatte.canvas;
1121
+ scratch.ctx.save();
1122
+ scratch.ctx.globalCompositeOperation = tt === 2 || tt === 4 ? "destination-out" : "destination-in";
1123
+ scratch.ctx.setTransform(1, 0, 0, 1, 0, 0);
1124
+ scratch.ctx.drawImage(matteSource, 0, 0);
1125
+ scratch.ctx.restore();
1126
+ targetCtx.save();
1127
+ targetCtx.globalCompositeOperation = (_d = BLEND_MODES[(_c = layer.bm) != null ? _c : 0]) != null ? _d : "source-over";
1128
+ targetCtx.drawImage(scratch.canvas, 0, 0);
1129
+ targetCtx.restore();
1130
+ }
1131
+ }
1132
+ }
1133
+ function renderSingleLayer(ctx, layer, assetsById, matrix, opacity, docFrame, opts) {
1134
+ var _a, _b, _c;
1135
+ switch (layer.ty) {
1136
+ case 4: {
1137
+ if (!layer.shapes) return;
1138
+ const scratch = opts.getShapeScratch ? opts.getShapeScratch(opts.canvasWidth, opts.canvasHeight) : makeCanvas(opts.canvasWidth, opts.canvasHeight);
1139
+ const rc = {
1140
+ ctx,
1141
+ frame: docFrame,
1142
+ canvasWidth: opts.canvasWidth,
1143
+ canvasHeight: opts.canvasHeight,
1144
+ scratchCanvas: scratch.canvas,
1145
+ scratchCtx: scratch.ctx
1146
+ };
1147
+ renderShapeItems(rc, layer.shapes, matrix, opacity);
1148
+ break;
1149
+ }
1150
+ case 1: {
1151
+ renderSolidLayer(ctx, layer, matrix);
1152
+ break;
1153
+ }
1154
+ case 0: {
1155
+ const asset = layer.refId ? assetsById.get(layer.refId) : void 0;
1156
+ if (!asset || !asset.layers) return;
1157
+ const stretch = (_a = layer.sr) != null ? _a : 1;
1158
+ const innerFrame = layer.tm ? (_b = getAnimatedValue(layer.tm, docFrame)[0]) != null ? _b : docFrame : (docFrame - ((_c = layer.st) != null ? _c : 0)) / stretch;
1159
+ renderLayers(ctx, asset.layers, assetsById, matrix, opacity, innerFrame, opts);
1160
+ break;
1161
+ }
1162
+ case 2: {
1163
+ const asset = layer.refId ? assetsById.get(layer.refId) : void 0;
1164
+ if (asset) renderImageLayer(ctx, asset, matrix, opts);
1165
+ break;
1166
+ }
1167
+ case 3:
1168
+ break;
1169
+ case 5:
1170
+ opts.warnOnce(
1171
+ "text-layer",
1172
+ "react-tgs-player: text layers are not rendered by this zero-dependency engine (not used by valid .tgs stickers)."
1173
+ );
1174
+ break;
1175
+ }
1176
+ }
1177
+ function buildAssetsMap(doc) {
1178
+ var _a;
1179
+ const map = /* @__PURE__ */ new Map();
1180
+ for (const asset of (_a = doc.assets) != null ? _a : []) {
1181
+ map.set(asset.id, asset);
1182
+ }
1183
+ return map;
1184
+ }
1185
+ function renderDocumentFrame(doc, frame, opts) {
1186
+ const assetsById = buildAssetsMap(doc);
1187
+ opts.ctx.save();
1188
+ opts.ctx.clearRect(0, 0, opts.canvasWidth, opts.canvasHeight);
1189
+ const scaleX = opts.canvasWidth / doc.w;
1190
+ const scaleY = opts.canvasHeight / doc.h;
1191
+ const base = [scaleX, 0, 0, scaleY, 0, 0];
1192
+ renderLayers(opts.ctx, doc.layers, assetsById, base, 1, frame, opts);
1193
+ opts.ctx.restore();
1194
+ }
1195
+
1196
+ // src/_internal/animation/lottie/animation.ts
1197
+ var memoryImageCache = /* @__PURE__ */ new Map();
1198
+ var imageCache = {
1199
+ get: (k) => memoryImageCache.get(k),
1200
+ set: (k, v) => void memoryImageCache.set(k, v)
1201
+ };
1202
+ var warnedKeys = /* @__PURE__ */ new Set();
1203
+ function warnOnce(key, message) {
1204
+ if (warnedKeys.has(key)) return;
1205
+ warnedKeys.add(key);
1206
+ console.warn(message);
1207
+ }
1208
+ var LottieAnimationController = class {
1209
+ constructor(options) {
1210
+ this.doc = null;
1211
+ this.state = "loading";
1212
+ this.currentFrame = 0;
1213
+ this.direction = 1;
1214
+ this.speed = 1;
1215
+ this.loop = false;
1216
+ this.mode = "normal";
1217
+ this.loopsCompleted = 0;
1218
+ this.segment = null;
1219
+ this.rafHandle = null;
1220
+ this.lastTs = null;
1221
+ this.shapeScratch = null;
1222
+ this.listeners = /* @__PURE__ */ new Map();
1223
+ var _a, _b, _c, _d, _e;
1224
+ this.canvas = options.canvas;
1225
+ const ctx = this.canvas.getContext("2d");
1226
+ if (!ctx) throw new Error("react-tgs-player: could not acquire a 2D canvas context");
1227
+ this.ctx = ctx;
1228
+ this.direction = (_a = options.direction) != null ? _a : 1;
1229
+ this.speed = (_b = options.speed) != null ? _b : 1;
1230
+ this.loop = (_c = options.loop) != null ? _c : false;
1231
+ this.mode = (_d = options.mode) != null ? _d : "normal";
1232
+ this.segment = (_e = options.segments) != null ? _e : null;
1233
+ }
1234
+ on(event, fn) {
1235
+ let set = this.listeners.get(event);
1236
+ if (!set) {
1237
+ set = /* @__PURE__ */ new Set();
1238
+ this.listeners.set(event, set);
1239
+ }
1240
+ set.add(fn);
1241
+ return () => set.delete(fn);
1242
+ }
1243
+ emit(event, detail) {
1244
+ const set = this.listeners.get(event);
1245
+ if (!set) return;
1246
+ for (const fn of set) fn(detail);
1247
+ }
1248
+ setDocument(doc) {
1249
+ this.doc = doc;
1250
+ const [inF, outF] = this.getBounds();
1251
+ this.currentFrame = this.direction === -1 ? outF : inF;
1252
+ this.state = "stopped";
1253
+ this.emit("ready");
1254
+ this.renderCurrentFrame();
1255
+ }
1256
+ setError(errors) {
1257
+ this.state = "error";
1258
+ this.emit("error", { errors });
1259
+ }
1260
+ getBounds() {
1261
+ if (!this.doc) return [0, 0];
1262
+ if (this.segment) return this.segment;
1263
+ return [this.doc.ip, this.doc.op];
1264
+ }
1265
+ resize(width, height) {
1266
+ this.canvas.width = width;
1267
+ this.canvas.height = height;
1268
+ this.renderCurrentFrame();
1269
+ }
1270
+ setSegment(segment) {
1271
+ this.segment = segment;
1272
+ const [inF, outF] = this.getBounds();
1273
+ this.currentFrame = Math.min(Math.max(this.currentFrame, inF), outF);
1274
+ this.renderCurrentFrame();
1275
+ }
1276
+ play() {
1277
+ if (!this.doc) return;
1278
+ if (this.state === "destroyed") return;
1279
+ this.state = "playing";
1280
+ this.emit("play");
1281
+ this.startLoop();
1282
+ }
1283
+ pause() {
1284
+ this.state = "paused";
1285
+ this.stopLoop();
1286
+ this.emit("pause");
1287
+ }
1288
+ freeze() {
1289
+ if (this.state !== "playing") return;
1290
+ this.state = "frozen";
1291
+ this.stopLoop();
1292
+ }
1293
+ unfreeze() {
1294
+ if (this.state !== "frozen") return;
1295
+ this.play();
1296
+ }
1297
+ stop() {
1298
+ if (!this.doc) return;
1299
+ this.state = "stopped";
1300
+ this.stopLoop();
1301
+ const [inF, outF] = this.getBounds();
1302
+ this.currentFrame = this.direction === -1 ? outF : inF;
1303
+ this.loopsCompleted = 0;
1304
+ this.renderCurrentFrame();
1305
+ this.emit("stop");
1306
+ }
1307
+ destroy() {
1308
+ this.stopLoop();
1309
+ this.state = "destroyed";
1310
+ this.doc = null;
1311
+ this.shapeScratch = null;
1312
+ this.listeners.clear();
1313
+ }
1314
+ togglePlay() {
1315
+ this.state === "playing" ? this.pause() : this.play();
1316
+ }
1317
+ setSpeed(speed) {
1318
+ this.speed = speed;
1319
+ }
1320
+ setDirection(direction) {
1321
+ this.direction = direction;
1322
+ }
1323
+ setLoop(loop) {
1324
+ this.loop = loop;
1325
+ }
1326
+ setMode(mode) {
1327
+ this.mode = mode;
1328
+ }
1329
+ getCurrentFrame() {
1330
+ return this.currentFrame;
1331
+ }
1332
+ getState() {
1333
+ return this.state;
1334
+ }
1335
+ getTotalFrames() {
1336
+ const [inF, outF] = this.getBounds();
1337
+ return outF - inF;
1338
+ }
1339
+ seek(value) {
1340
+ if (!this.doc) return;
1341
+ const [inF, outF] = this.getBounds();
1342
+ let frame;
1343
+ if (typeof value === "string" && value.trim().endsWith("%")) {
1344
+ const pct = parseFloat(value) / 100;
1345
+ frame = inF + (outF - inF) * pct;
1346
+ } else {
1347
+ frame = Number(value);
1348
+ }
1349
+ frame = Math.min(Math.max(frame, inF), outF);
1350
+ this.currentFrame = frame;
1351
+ this.renderCurrentFrame();
1352
+ this.emitFrameEvent();
1353
+ if (this.state !== "playing") ;
1354
+ }
1355
+ startLoop() {
1356
+ if (this.rafHandle != null) return;
1357
+ this.lastTs = null;
1358
+ const tick = (ts) => {
1359
+ if (this.state !== "playing") {
1360
+ this.rafHandle = null;
1361
+ return;
1362
+ }
1363
+ if (this.lastTs == null) this.lastTs = ts;
1364
+ const dtMs = ts - this.lastTs;
1365
+ this.lastTs = ts;
1366
+ this.advance(dtMs);
1367
+ this.rafHandle = requestAnimationFrame(tick);
1368
+ };
1369
+ this.rafHandle = requestAnimationFrame(tick);
1370
+ }
1371
+ stopLoop() {
1372
+ if (this.rafHandle != null) {
1373
+ cancelAnimationFrame(this.rafHandle);
1374
+ this.rafHandle = null;
1375
+ }
1376
+ this.lastTs = null;
1377
+ }
1378
+ advance(dtMs) {
1379
+ if (!this.doc) return;
1380
+ const [inF, outF] = this.getBounds();
1381
+ const fps = this.doc.fr || 30;
1382
+ const framesDelta = dtMs / 1e3 * fps * this.speed * this.direction;
1383
+ let next = this.currentFrame + framesDelta;
1384
+ const span = Math.max(1, outF - inF);
1385
+ const loopLimit = this.loop === true ? Infinity : this.loop === false ? 1 : Math.max(1, this.loop);
1386
+ if (this.mode === "bounce") {
1387
+ if (next >= outF) {
1388
+ if (this.direction === 1 && (this.loop === true || this.loopsCompleted < loopLimit - 0.5)) {
1389
+ this.direction = -1;
1390
+ next = outF - (next - outF);
1391
+ this.loopsCompleted += 0.5;
1392
+ this.emit("loop");
1393
+ } else {
1394
+ next = outF;
1395
+ this.finishPlayback();
1396
+ }
1397
+ } else if (next <= inF) {
1398
+ if (this.direction === -1 && (this.loop === true || this.loopsCompleted < loopLimit - 0.5)) {
1399
+ this.direction = 1;
1400
+ next = inF + (inF - next);
1401
+ this.loopsCompleted += 0.5;
1402
+ this.emit("loop");
1403
+ } else {
1404
+ next = inF;
1405
+ this.finishPlayback();
1406
+ }
1407
+ }
1408
+ } else {
1409
+ if (next >= outF && this.direction === 1) {
1410
+ if (this.loop === true || this.loopsCompleted < loopLimit - 1) {
1411
+ next = inF + (next - outF) % span;
1412
+ this.loopsCompleted += 1;
1413
+ this.emit("loop");
1414
+ } else {
1415
+ next = outF;
1416
+ this.finishPlayback();
1417
+ }
1418
+ } else if (next <= inF && this.direction === -1) {
1419
+ if (this.loop === true || this.loopsCompleted < loopLimit - 1) {
1420
+ next = outF - (inF - next) % span;
1421
+ this.loopsCompleted += 1;
1422
+ this.emit("loop");
1423
+ } else {
1424
+ next = inF;
1425
+ this.finishPlayback();
1426
+ }
1427
+ }
1428
+ }
1429
+ this.currentFrame = next;
1430
+ this.renderCurrentFrame();
1431
+ this.emitFrameEvent();
1432
+ }
1433
+ finishPlayback() {
1434
+ this.state = "paused";
1435
+ this.stopLoop();
1436
+ this.emit("complete");
1437
+ }
1438
+ emitFrameEvent() {
1439
+ const [inF, outF] = this.getBounds();
1440
+ const span = Math.max(1, outF - inF);
1441
+ this.emit("frame", {
1442
+ frame: this.currentFrame,
1443
+ progress: (this.currentFrame - inF) / span
1444
+ });
1445
+ }
1446
+ getShapeScratch(w, h) {
1447
+ const cur = this.shapeScratch;
1448
+ if (cur && cur.canvas.width === Math.max(1, w) && cur.canvas.height === Math.max(1, h)) {
1449
+ return cur;
1450
+ }
1451
+ let canvas;
1452
+ if (typeof OffscreenCanvas !== "undefined") {
1453
+ canvas = new OffscreenCanvas(Math.max(1, w), Math.max(1, h));
1454
+ } else {
1455
+ canvas = document.createElement("canvas");
1456
+ canvas.width = Math.max(1, w);
1457
+ canvas.height = Math.max(1, h);
1458
+ }
1459
+ const ctx = canvas.getContext("2d");
1460
+ this.shapeScratch = { canvas, ctx };
1461
+ return this.shapeScratch;
1462
+ }
1463
+ renderCurrentFrame() {
1464
+ if (!this.doc) return;
1465
+ const opts = {
1466
+ ctx: this.ctx,
1467
+ canvasWidth: this.canvas.width,
1468
+ canvasHeight: this.canvas.height,
1469
+ imageCache,
1470
+ onAssetLoaded: () => this.renderCurrentFrame(),
1471
+ warnOnce,
1472
+ getShapeScratch: (w, h) => this.getShapeScratch(w, h)
1473
+ };
1474
+ try {
1475
+ renderDocumentFrame(this.doc, this.currentFrame, opts);
1476
+ } catch (err) {
1477
+ this.setError([err.message]);
1478
+ }
1479
+ }
1480
+ };
1481
+
1482
+ // src/_internal/animation/inflate/deflate.ts
1483
+ var ByteSink = class {
1484
+ constructor(initialSize = 1 << 16) {
1485
+ this.len = 0;
1486
+ this.buf = new Uint8Array(initialSize);
1487
+ }
1488
+ ensure(extra) {
1489
+ if (this.len + extra <= this.buf.length) return;
1490
+ let newSize = this.buf.length * 2;
1491
+ while (newSize < this.len + extra) newSize *= 2;
1492
+ const next = new Uint8Array(newSize);
1493
+ next.set(this.buf.subarray(0, this.len));
1494
+ this.buf = next;
1495
+ }
1496
+ pushByte(b) {
1497
+ this.ensure(1);
1498
+ this.buf[this.len++] = b;
1499
+ }
1500
+ pushBytes(src, start, count) {
1501
+ this.ensure(count);
1502
+ this.buf.set(src.subarray(start, start + count), this.len);
1503
+ this.len += count;
1504
+ }
1505
+ copyBack(distance, length) {
1506
+ this.ensure(length);
1507
+ let srcPos = this.len - distance;
1508
+ for (let i = 0; i < length; i++) {
1509
+ this.buf[this.len + i] = this.buf[srcPos + i];
1510
+ }
1511
+ this.len += length;
1512
+ }
1513
+ toUint8Array() {
1514
+ return this.buf.subarray(0, this.len);
1515
+ }
1516
+ };
1517
+ var BitReader = class {
1518
+ constructor(data) {
1519
+ this.pos = 0;
1520
+ this.bitBuf = 0;
1521
+ this.bitCount = 0;
1522
+ this.data = data;
1523
+ }
1524
+ get bytePos() {
1525
+ return this.pos;
1526
+ }
1527
+ hasMore() {
1528
+ return this.pos < this.data.length || this.bitCount > 0;
1529
+ }
1530
+ readBits(n) {
1531
+ while (this.bitCount < n) {
1532
+ if (this.pos >= this.data.length) {
1533
+ this.bitBuf |= 0 << this.bitCount;
1534
+ this.bitCount += 8;
1535
+ this.pos++;
1536
+ continue;
1537
+ }
1538
+ this.bitBuf |= this.data[this.pos++] << this.bitCount;
1539
+ this.bitCount += 8;
1540
+ }
1541
+ const value = this.bitBuf & (1 << n) - 1;
1542
+ this.bitBuf >>>= n;
1543
+ this.bitCount -= n;
1544
+ return value;
1545
+ }
1546
+ alignToByte() {
1547
+ this.bitBuf = 0;
1548
+ this.bitCount = 0;
1549
+ }
1550
+ readAlignedByte() {
1551
+ return this.data[this.pos++];
1552
+ }
1553
+ };
1554
+ var HuffmanTree = class {
1555
+ constructor(codeLengths) {
1556
+ this.codesByLength = /* @__PURE__ */ new Map();
1557
+ let maxLen = 0;
1558
+ for (const l of codeLengths) if (l > maxLen) maxLen = l;
1559
+ this.maxLen = maxLen;
1560
+ if (maxLen === 0) return;
1561
+ const blCount = new Array(maxLen + 1).fill(0);
1562
+ for (const l of codeLengths) if (l > 0) blCount[l]++;
1563
+ const nextCode = new Array(maxLen + 1).fill(0);
1564
+ let code = 0;
1565
+ for (let bits = 1; bits <= maxLen; bits++) {
1566
+ code = code + blCount[bits - 1] << 1;
1567
+ nextCode[bits] = code;
1568
+ }
1569
+ for (let sym = 0; sym < codeLengths.length; sym++) {
1570
+ const len = codeLengths[sym];
1571
+ if (len === 0) continue;
1572
+ const c = nextCode[len]++;
1573
+ let map = this.codesByLength.get(len);
1574
+ if (!map) {
1575
+ map = /* @__PURE__ */ new Map();
1576
+ this.codesByLength.set(len, map);
1577
+ }
1578
+ map.set(c, sym);
1579
+ }
1580
+ }
1581
+ decode(reader) {
1582
+ let code = 0;
1583
+ for (let len = 1; len <= this.maxLen; len++) {
1584
+ code = code << 1 | reader.readBits(1);
1585
+ const map = this.codesByLength.get(len);
1586
+ if (map && map.has(code)) {
1587
+ return map.get(code);
1588
+ }
1589
+ }
1590
+ throw new Error("Invalid Huffman code in DEFLATE stream");
1591
+ }
1592
+ };
1593
+ var LENGTH_BASE = [
1594
+ 3,
1595
+ 4,
1596
+ 5,
1597
+ 6,
1598
+ 7,
1599
+ 8,
1600
+ 9,
1601
+ 10,
1602
+ 11,
1603
+ 13,
1604
+ 15,
1605
+ 17,
1606
+ 19,
1607
+ 23,
1608
+ 27,
1609
+ 31,
1610
+ 35,
1611
+ 43,
1612
+ 51,
1613
+ 59,
1614
+ 67,
1615
+ 83,
1616
+ 99,
1617
+ 115,
1618
+ 131,
1619
+ 163,
1620
+ 195,
1621
+ 227,
1622
+ 258
1623
+ ];
1624
+ var LENGTH_EXTRA_BITS = [
1625
+ 0,
1626
+ 0,
1627
+ 0,
1628
+ 0,
1629
+ 0,
1630
+ 0,
1631
+ 0,
1632
+ 0,
1633
+ 1,
1634
+ 1,
1635
+ 1,
1636
+ 1,
1637
+ 2,
1638
+ 2,
1639
+ 2,
1640
+ 2,
1641
+ 3,
1642
+ 3,
1643
+ 3,
1644
+ 3,
1645
+ 4,
1646
+ 4,
1647
+ 4,
1648
+ 4,
1649
+ 5,
1650
+ 5,
1651
+ 5,
1652
+ 5,
1653
+ 0
1654
+ ];
1655
+ var DIST_BASE = [
1656
+ 1,
1657
+ 2,
1658
+ 3,
1659
+ 4,
1660
+ 5,
1661
+ 7,
1662
+ 9,
1663
+ 13,
1664
+ 17,
1665
+ 25,
1666
+ 33,
1667
+ 49,
1668
+ 65,
1669
+ 97,
1670
+ 129,
1671
+ 193,
1672
+ 257,
1673
+ 385,
1674
+ 513,
1675
+ 769,
1676
+ 1025,
1677
+ 1537,
1678
+ 2049,
1679
+ 3073,
1680
+ 4097,
1681
+ 6145,
1682
+ 8193,
1683
+ 12289,
1684
+ 16385,
1685
+ 24577
1686
+ ];
1687
+ var DIST_EXTRA_BITS = [
1688
+ 0,
1689
+ 0,
1690
+ 0,
1691
+ 0,
1692
+ 1,
1693
+ 1,
1694
+ 2,
1695
+ 2,
1696
+ 3,
1697
+ 3,
1698
+ 4,
1699
+ 4,
1700
+ 5,
1701
+ 5,
1702
+ 6,
1703
+ 6,
1704
+ 7,
1705
+ 7,
1706
+ 8,
1707
+ 8,
1708
+ 9,
1709
+ 9,
1710
+ 10,
1711
+ 10,
1712
+ 11,
1713
+ 11,
1714
+ 12,
1715
+ 12,
1716
+ 13,
1717
+ 13
1718
+ ];
1719
+ var CODE_LENGTH_ORDER = [
1720
+ 16,
1721
+ 17,
1722
+ 18,
1723
+ 0,
1724
+ 8,
1725
+ 7,
1726
+ 9,
1727
+ 6,
1728
+ 10,
1729
+ 5,
1730
+ 11,
1731
+ 4,
1732
+ 12,
1733
+ 3,
1734
+ 13,
1735
+ 2,
1736
+ 14,
1737
+ 1,
1738
+ 15
1739
+ ];
1740
+ function buildFixedLiteralLengths() {
1741
+ const lengths = new Array(288);
1742
+ for (let i = 0; i <= 143; i++) lengths[i] = 8;
1743
+ for (let i = 144; i <= 255; i++) lengths[i] = 9;
1744
+ for (let i = 256; i <= 279; i++) lengths[i] = 7;
1745
+ for (let i = 280; i <= 287; i++) lengths[i] = 8;
1746
+ return lengths;
1747
+ }
1748
+ function buildFixedDistLengths() {
1749
+ return new Array(30).fill(5);
1750
+ }
1751
+ function inflateBlock(reader, sink, litTree, distTree) {
1752
+ for (; ; ) {
1753
+ const sym = litTree.decode(reader);
1754
+ if (sym < 256) {
1755
+ sink.pushByte(sym);
1756
+ continue;
1757
+ }
1758
+ if (sym === 256) {
1759
+ return;
1760
+ }
1761
+ const lengthIndex = sym - 257;
1762
+ if (lengthIndex >= LENGTH_BASE.length) {
1763
+ throw new Error("Invalid length code in DEFLATE stream");
1764
+ }
1765
+ const length = LENGTH_BASE[lengthIndex] + reader.readBits(LENGTH_EXTRA_BITS[lengthIndex]);
1766
+ const distSym = distTree.decode(reader);
1767
+ if (distSym >= DIST_BASE.length) {
1768
+ throw new Error("Invalid distance code in DEFLATE stream");
1769
+ }
1770
+ const distance = DIST_BASE[distSym] + reader.readBits(DIST_EXTRA_BITS[distSym]);
1771
+ sink.copyBack(distance, length);
1772
+ }
1773
+ }
1774
+ function inflateDynamicBlock(reader, sink) {
1775
+ var _a;
1776
+ const hlit = reader.readBits(5) + 257;
1777
+ const hdist = reader.readBits(5) + 1;
1778
+ const hclen = reader.readBits(4) + 4;
1779
+ const codeLengthLengths = new Array(19).fill(0);
1780
+ for (let i = 0; i < hclen; i++) {
1781
+ codeLengthLengths[CODE_LENGTH_ORDER[i]] = reader.readBits(3);
1782
+ }
1783
+ const codeLengthTree = new HuffmanTree(codeLengthLengths);
1784
+ const allLengths = [];
1785
+ while (allLengths.length < hlit + hdist) {
1786
+ const sym = codeLengthTree.decode(reader);
1787
+ if (sym <= 15) {
1788
+ allLengths.push(sym);
1789
+ } else if (sym === 16) {
1790
+ const repeat = reader.readBits(2) + 3;
1791
+ const prev = (_a = allLengths[allLengths.length - 1]) != null ? _a : 0;
1792
+ for (let i = 0; i < repeat; i++) allLengths.push(prev);
1793
+ } else if (sym === 17) {
1794
+ const repeat = reader.readBits(3) + 3;
1795
+ for (let i = 0; i < repeat; i++) allLengths.push(0);
1796
+ } else if (sym === 18) {
1797
+ const repeat = reader.readBits(7) + 11;
1798
+ for (let i = 0; i < repeat; i++) allLengths.push(0);
1799
+ } else {
1800
+ throw new Error("Invalid code length symbol in DEFLATE stream");
1801
+ }
1802
+ }
1803
+ const litLengths = allLengths.slice(0, hlit);
1804
+ const distLengths = allLengths.slice(hlit, hlit + hdist);
1805
+ const litTree = new HuffmanTree(litLengths);
1806
+ const distTree = new HuffmanTree(distLengths);
1807
+ inflateBlock(reader, sink, litTree, distTree);
1808
+ }
1809
+ function inflateRaw(data) {
1810
+ const reader = new BitReader(data);
1811
+ const sink = new ByteSink(Math.max(1 << 16, data.length * 4));
1812
+ let fixedLitTree = null;
1813
+ let fixedDistTree = null;
1814
+ for (; ; ) {
1815
+ const bfinal = reader.readBits(1);
1816
+ const btype = reader.readBits(2);
1817
+ if (btype === 0) {
1818
+ reader.alignToByte();
1819
+ const len = reader.readAlignedByte() | reader.readAlignedByte() << 8;
1820
+ reader.readAlignedByte();
1821
+ reader.readAlignedByte();
1822
+ for (let i = 0; i < len; i++) {
1823
+ sink.pushByte(reader.readAlignedByte());
1824
+ }
1825
+ } else if (btype === 1) {
1826
+ if (!fixedLitTree) {
1827
+ fixedLitTree = new HuffmanTree(buildFixedLiteralLengths());
1828
+ fixedDistTree = new HuffmanTree(buildFixedDistLengths());
1829
+ }
1830
+ inflateBlock(reader, sink, fixedLitTree, fixedDistTree);
1831
+ } else if (btype === 2) {
1832
+ inflateDynamicBlock(reader, sink);
1833
+ } else {
1834
+ throw new Error("Invalid DEFLATE block type");
1835
+ }
1836
+ if (bfinal === 1) break;
1837
+ if (!reader.hasMore()) break;
1838
+ }
1839
+ return sink.toUint8Array();
1840
+ }
1841
+
1842
+ // src/_internal/animation/inflate/gunzip.ts
1843
+ var GZIP_MAGIC_0 = 31;
1844
+ var GZIP_MAGIC_1 = 139;
1845
+ var FLAG_FHCRC = 2;
1846
+ var FLAG_FEXTRA = 4;
1847
+ var FLAG_FNAME = 8;
1848
+ var FLAG_FCOMMENT = 16;
1849
+ function isGzip(data) {
1850
+ return data.length > 2 && data[0] === GZIP_MAGIC_0 && data[1] === GZIP_MAGIC_1;
1851
+ }
1852
+ function gunzip(data) {
1853
+ if (!isGzip(data)) {
1854
+ throw new Error("Not a valid gzip stream (bad magic bytes)");
1855
+ }
1856
+ let pos = 2;
1857
+ const cm = data[pos++];
1858
+ if (cm !== 8) {
1859
+ throw new Error(`Unsupported gzip compression method: ${cm}`);
1860
+ }
1861
+ const flags = data[pos++];
1862
+ pos += 4;
1863
+ pos += 1;
1864
+ pos += 1;
1865
+ if (flags & FLAG_FEXTRA) {
1866
+ const xlen = data[pos] | data[pos + 1] << 8;
1867
+ pos += 2 + xlen;
1868
+ }
1869
+ if (flags & FLAG_FNAME) {
1870
+ while (pos < data.length && data[pos] !== 0) pos++;
1871
+ pos++;
1872
+ }
1873
+ if (flags & FLAG_FCOMMENT) {
1874
+ while (pos < data.length && data[pos] !== 0) pos++;
1875
+ pos++;
1876
+ }
1877
+ if (flags & FLAG_FHCRC) {
1878
+ pos += 2;
1879
+ }
1880
+ const deflateData = data.subarray(pos);
1881
+ return inflateRaw(deflateData);
1882
+ }
1883
+ function bytesToUtf8(bytes) {
1884
+ if (typeof TextDecoder !== "undefined") {
1885
+ return new TextDecoder("utf-8").decode(bytes);
1886
+ }
1887
+ let out = "";
1888
+ let i = 0;
1889
+ while (i < bytes.length) {
1890
+ const b0 = bytes[i++];
1891
+ if (b0 < 128) {
1892
+ out += String.fromCharCode(b0);
1893
+ } else if (b0 >= 192 && b0 < 224) {
1894
+ const b1 = bytes[i++];
1895
+ out += String.fromCharCode((b0 & 31) << 6 | b1 & 63);
1896
+ } else if (b0 >= 224 && b0 < 240) {
1897
+ const b1 = bytes[i++];
1898
+ const b2 = bytes[i++];
1899
+ out += String.fromCharCode(
1900
+ (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63
1901
+ );
1902
+ } else {
1903
+ const b1 = bytes[i++];
1904
+ const b2 = bytes[i++];
1905
+ const b3 = bytes[i++];
1906
+ const codePoint = (b0 & 7) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
1907
+ out += String.fromCodePoint(codePoint);
1908
+ }
1909
+ }
1910
+ return out;
1911
+ }
1912
+
1913
+ // src/_internal/animation/lottie/loader.ts
1914
+ function base64ToBytes(base64) {
1915
+ const binary = atob(base64);
1916
+ const bytes = new Uint8Array(binary.length);
1917
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
1918
+ return bytes;
1919
+ }
1920
+ function looksLikeBase64(str) {
1921
+ const trimmed = str.trim();
1922
+ if (trimmed.length < 8) return false;
1923
+ return /^[A-Za-z0-9+/]+={0,2}$/.test(trimmed) && trimmed.length % 4 === 0;
1924
+ }
1925
+ async function fetchArrayBuffer(url) {
1926
+ const res = await fetch(url);
1927
+ if (!res.ok) {
1928
+ throw new Error(`[@core-ease/telegram-kit] : failed to fetch "${url}" (HTTP ${res.status})`);
1929
+ }
1930
+ return res.arrayBuffer();
1931
+ }
1932
+ function bytesToJson(bytes) {
1933
+ const data = isGzip(bytes) ? gunzip(bytes) : bytes;
1934
+ const text = bytesToUtf8(data);
1935
+ return JSON.parse(text);
1936
+ }
1937
+ async function loadTgsSource(src) {
1938
+ if (src instanceof ArrayBuffer) {
1939
+ return bytesToJson(new Uint8Array(src));
1940
+ }
1941
+ if (src instanceof Uint8Array) {
1942
+ return bytesToJson(src);
1943
+ }
1944
+ if (typeof src === "object" && src !== null) {
1945
+ return src;
1946
+ }
1947
+ if (typeof src === "string") {
1948
+ const trimmed = src.trim();
1949
+ if (trimmed.startsWith("{")) {
1950
+ return JSON.parse(trimmed);
1951
+ }
1952
+ if (trimmed.startsWith("data:")) {
1953
+ const comma = trimmed.indexOf(",");
1954
+ const meta = trimmed.slice(5, comma);
1955
+ const payload = trimmed.slice(comma + 1);
1956
+ const bytes = meta.includes("base64") ? base64ToBytes(payload) : new TextEncoder().encode(decodeURIComponent(payload));
1957
+ return bytesToJson(bytes);
1958
+ }
1959
+ if (looksLikeBase64(trimmed)) {
1960
+ try {
1961
+ return bytesToJson(base64ToBytes(trimmed));
1962
+ } catch (e) {
1963
+ }
1964
+ }
1965
+ const url = new URL(trimmed, typeof window !== "undefined" ? window.location.href : void 0);
1966
+ const buffer = await fetchArrayBuffer(url.toString());
1967
+ return bytesToJson(new Uint8Array(buffer));
1968
+ }
1969
+ throw new Error("[@core-ease/telegram-kit] : unsupported `src` type");
1970
+ }
1971
+ var DEFAULT_SIZE = 512;
1972
+ function useResolvedCssSize(width, height) {
1973
+ return {
1974
+ width: width != null ? width : "100%",
1975
+ height: height != null ? height : "100%"
1976
+ };
1977
+ }
1978
+ function createAnimationPlayerComponent(displayName, defaultAriaLabel) {
1979
+ const Component = React.forwardRef(
1980
+ function AnimationPlayer(props, ref) {
1981
+ const {
1982
+ src,
1983
+ autoplay = false,
1984
+ loop = false,
1985
+ speed = 1,
1986
+ direction = 1,
1987
+ mode = "normal",
1988
+ segments,
1989
+ hover = false,
1990
+ pauseWhenOffscreen = true,
1991
+ width,
1992
+ height,
1993
+ className,
1994
+ style,
1995
+ ariaLabel = defaultAriaLabel,
1996
+ onReady,
1997
+ onPlay,
1998
+ onPause,
1999
+ onStop,
2000
+ onComplete,
2001
+ onLoop,
2002
+ onFrame,
2003
+ onError,
2004
+ validate
2005
+ } = props;
2006
+ const canvasRef = React.useRef(null);
2007
+ const controllerRef = React.useRef(null);
2008
+ const containerRef = React.useRef(null);
2009
+ const docRef = React.useRef(null);
2010
+ const wasPlayingBeforeFreeze = React.useRef(false);
2011
+ const callbacksRef = React.useRef(props);
2012
+ callbacksRef.current = props;
2013
+ React.useImperativeHandle(
2014
+ ref,
2015
+ () => ({
2016
+ play: () => {
2017
+ var _a;
2018
+ return (_a = controllerRef.current) == null ? void 0 : _a.play();
2019
+ },
2020
+ pause: () => {
2021
+ var _a;
2022
+ return (_a = controllerRef.current) == null ? void 0 : _a.pause();
2023
+ },
2024
+ stop: () => {
2025
+ var _a;
2026
+ return (_a = controllerRef.current) == null ? void 0 : _a.stop();
2027
+ },
2028
+ togglePlay: () => {
2029
+ var _a;
2030
+ return (_a = controllerRef.current) == null ? void 0 : _a.togglePlay();
2031
+ },
2032
+ seek: (value) => {
2033
+ var _a;
2034
+ return (_a = controllerRef.current) == null ? void 0 : _a.seek(value);
2035
+ },
2036
+ setSpeed: (s) => {
2037
+ var _a;
2038
+ return (_a = controllerRef.current) == null ? void 0 : _a.setSpeed(s);
2039
+ },
2040
+ setDirection: (d) => {
2041
+ var _a;
2042
+ return (_a = controllerRef.current) == null ? void 0 : _a.setDirection(d);
2043
+ },
2044
+ setLoop: (l) => {
2045
+ var _a;
2046
+ return (_a = controllerRef.current) == null ? void 0 : _a.setLoop(l);
2047
+ },
2048
+ setMode: (m) => {
2049
+ var _a;
2050
+ return (_a = controllerRef.current) == null ? void 0 : _a.setMode(m);
2051
+ },
2052
+ setSegment: (seg) => {
2053
+ var _a;
2054
+ return (_a = controllerRef.current) == null ? void 0 : _a.setSegment(seg);
2055
+ },
2056
+ getCurrentFrame: () => {
2057
+ var _a, _b;
2058
+ return (_b = (_a = controllerRef.current) == null ? void 0 : _a.getCurrentFrame()) != null ? _b : 0;
2059
+ },
2060
+ getTotalFrames: () => {
2061
+ var _a, _b;
2062
+ return (_b = (_a = controllerRef.current) == null ? void 0 : _a.getTotalFrames()) != null ? _b : 0;
2063
+ },
2064
+ getState: () => {
2065
+ var _a, _b;
2066
+ return (_b = (_a = controllerRef.current) == null ? void 0 : _a.getState()) != null ? _b : "loading";
2067
+ },
2068
+ getAnimationData: () => docRef.current,
2069
+ getCanvas: () => canvasRef.current
2070
+ }),
2071
+ []
2072
+ );
2073
+ React.useEffect(() => {
2074
+ const canvas = canvasRef.current;
2075
+ if (!canvas) return;
2076
+ const controller = new LottieAnimationController({
2077
+ canvas,
2078
+ loop,
2079
+ autoplay,
2080
+ speed,
2081
+ direction,
2082
+ mode,
2083
+ segments
2084
+ });
2085
+ controllerRef.current = controller;
2086
+ const offReady = controller.on("ready", () => {
2087
+ var _a, _b;
2088
+ return (_b = (_a = callbacksRef.current).onReady) == null ? void 0 : _b.call(_a);
2089
+ });
2090
+ const offPlay = controller.on("play", () => {
2091
+ var _a, _b;
2092
+ return (_b = (_a = callbacksRef.current).onPlay) == null ? void 0 : _b.call(_a);
2093
+ });
2094
+ const offPause = controller.on("pause", () => {
2095
+ var _a, _b;
2096
+ return (_b = (_a = callbacksRef.current).onPause) == null ? void 0 : _b.call(_a);
2097
+ });
2098
+ const offStop = controller.on("stop", () => {
2099
+ var _a, _b;
2100
+ return (_b = (_a = callbacksRef.current).onStop) == null ? void 0 : _b.call(_a);
2101
+ });
2102
+ const offComplete = controller.on("complete", () => {
2103
+ var _a, _b;
2104
+ return (_b = (_a = callbacksRef.current).onComplete) == null ? void 0 : _b.call(_a);
2105
+ });
2106
+ const offLoop = controller.on("loop", () => {
2107
+ var _a, _b;
2108
+ return (_b = (_a = callbacksRef.current).onLoop) == null ? void 0 : _b.call(_a);
2109
+ });
2110
+ const offFrame = controller.on("frame", (d) => {
2111
+ var _a, _b;
2112
+ return (_b = (_a = callbacksRef.current).onFrame) == null ? void 0 : _b.call(_a, d);
2113
+ });
2114
+ const offError = controller.on("error", (d) => {
2115
+ var _a, _b;
2116
+ return (_b = (_a = callbacksRef.current).onError) == null ? void 0 : _b.call(_a, d == null ? void 0 : d.errors);
2117
+ });
2118
+ return () => {
2119
+ offReady();
2120
+ offPlay();
2121
+ offPause();
2122
+ offStop();
2123
+ offComplete();
2124
+ offLoop();
2125
+ offFrame();
2126
+ offError();
2127
+ controller.destroy();
2128
+ controllerRef.current = null;
2129
+ };
2130
+ }, []);
2131
+ React.useEffect(() => {
2132
+ let cancelled = false;
2133
+ const controller = controllerRef.current;
2134
+ if (!controller) return;
2135
+ loadTgsSource(src).then((doc) => {
2136
+ var _a, _b;
2137
+ if (cancelled) return;
2138
+ if (validate) {
2139
+ const errors = validate(doc);
2140
+ if (errors.length > 0) {
2141
+ (_b = (_a = callbacksRef.current).onError) == null ? void 0 : _b.call(_a, errors);
2142
+ }
2143
+ }
2144
+ docRef.current = doc;
2145
+ controller.setDocument(doc);
2146
+ if (autoplay) controller.play();
2147
+ }).catch((err) => {
2148
+ var _a, _b;
2149
+ if (cancelled) return;
2150
+ controller.setError([err.message]);
2151
+ (_b = (_a = callbacksRef.current).onError) == null ? void 0 : _b.call(_a, [err.message]);
2152
+ });
2153
+ return () => {
2154
+ cancelled = true;
2155
+ };
2156
+ }, [src, validate]);
2157
+ React.useEffect(() => {
2158
+ var _a;
2159
+ return (_a = controllerRef.current) == null ? void 0 : _a.setSpeed(speed);
2160
+ }, [speed]);
2161
+ React.useEffect(() => {
2162
+ var _a;
2163
+ return (_a = controllerRef.current) == null ? void 0 : _a.setDirection(direction);
2164
+ }, [direction]);
2165
+ React.useEffect(() => {
2166
+ var _a;
2167
+ return (_a = controllerRef.current) == null ? void 0 : _a.setLoop(loop);
2168
+ }, [loop]);
2169
+ React.useEffect(() => {
2170
+ var _a;
2171
+ return (_a = controllerRef.current) == null ? void 0 : _a.setMode(mode);
2172
+ }, [mode]);
2173
+ React.useEffect(() => {
2174
+ var _a;
2175
+ return (_a = controllerRef.current) == null ? void 0 : _a.setSegment(segments != null ? segments : null);
2176
+ }, [segments]);
2177
+ React.useEffect(() => {
2178
+ const canvas = canvasRef.current;
2179
+ const container = containerRef.current;
2180
+ if (!canvas || !container) return;
2181
+ const applySize = () => {
2182
+ var _a;
2183
+ const rect = container.getBoundingClientRect();
2184
+ const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
2185
+ const w = Math.max(1, Math.round((rect.width || DEFAULT_SIZE) * dpr));
2186
+ const h = Math.max(1, Math.round((rect.height || DEFAULT_SIZE) * dpr));
2187
+ if (canvas.width !== w || canvas.height !== h) {
2188
+ (_a = controllerRef.current) == null ? void 0 : _a.resize(w, h);
2189
+ }
2190
+ };
2191
+ applySize();
2192
+ if (typeof ResizeObserver !== "undefined") {
2193
+ const ro = new ResizeObserver(applySize);
2194
+ ro.observe(container);
2195
+ return () => ro.disconnect();
2196
+ }
2197
+ return void 0;
2198
+ }, []);
2199
+ React.useEffect(() => {
2200
+ if (!pauseWhenOffscreen) return;
2201
+ const container = containerRef.current;
2202
+ if (!container || typeof IntersectionObserver === "undefined") return;
2203
+ const io = new IntersectionObserver((entries) => {
2204
+ const entry = entries[0];
2205
+ const controller = controllerRef.current;
2206
+ if (!controller) return;
2207
+ if (entry.isIntersecting) {
2208
+ controller.unfreeze();
2209
+ } else if (controller.getState() === "playing") {
2210
+ controller.freeze();
2211
+ }
2212
+ });
2213
+ io.observe(container);
2214
+ return () => io.disconnect();
2215
+ }, [pauseWhenOffscreen]);
2216
+ React.useEffect(() => {
2217
+ if (typeof document === "undefined") return;
2218
+ const onVisibility = () => {
2219
+ const controller = controllerRef.current;
2220
+ if (!controller) return;
2221
+ if (document.hidden) {
2222
+ if (controller.getState() === "playing") {
2223
+ wasPlayingBeforeFreeze.current = true;
2224
+ controller.freeze();
2225
+ }
2226
+ } else if (wasPlayingBeforeFreeze.current) {
2227
+ wasPlayingBeforeFreeze.current = false;
2228
+ controller.unfreeze();
2229
+ }
2230
+ };
2231
+ document.addEventListener("visibilitychange", onVisibility);
2232
+ return () => document.removeEventListener("visibilitychange", onVisibility);
2233
+ }, []);
2234
+ const handleMouseEnter = React.useCallback(() => {
2235
+ var _a;
2236
+ if (hover) (_a = controllerRef.current) == null ? void 0 : _a.play();
2237
+ }, [hover]);
2238
+ const handleMouseLeave = React.useCallback(() => {
2239
+ var _a;
2240
+ if (hover) (_a = controllerRef.current) == null ? void 0 : _a.stop();
2241
+ }, [hover]);
2242
+ const cssSize = useResolvedCssSize(width, height);
2243
+ return /* @__PURE__ */ jsx(
2244
+ "div",
2245
+ {
2246
+ ref: containerRef,
2247
+ className,
2248
+ style: __spreadValues({ width: cssSize.width, height: cssSize.height, lineHeight: 0 }, style),
2249
+ onMouseEnter: handleMouseEnter,
2250
+ onMouseLeave: handleMouseLeave,
2251
+ role: "img",
2252
+ "aria-label": ariaLabel,
2253
+ children: /* @__PURE__ */ jsx("canvas", { ref: canvasRef, style: { width: "100%", height: "100%", display: "block" } })
2254
+ }
2255
+ );
2256
+ }
2257
+ );
2258
+ Component.displayName = displayName;
2259
+ return Component;
2260
+ }
2261
+
2262
+ export { LottieAnimationController, createAnimationPlayerComponent, gunzip, isGzip, loadTgsSource, renderDocumentFrame };