@pixodesk/svg-animator-web 1.0.6
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 +100 -0
- package/dist/index.cjs +1753 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +396 -0
- package/dist/index.d.ts +396 -0
- package/dist/index.js +1705 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.cjs +1 -0
- package/dist/index.min.js +1 -0
- package/dist/index.umd.js +1727 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/index.umd.min.js +1 -0
- package/package.json +59 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1753 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __objRest = (source, exclude) => {
|
|
24
|
+
var target = {};
|
|
25
|
+
for (var prop in source)
|
|
26
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
27
|
+
target[prop] = source[prop];
|
|
28
|
+
if (source != null && __getOwnPropSymbols)
|
|
29
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
30
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
31
|
+
target[prop] = source[prop];
|
|
32
|
+
}
|
|
33
|
+
return target;
|
|
34
|
+
};
|
|
35
|
+
var __export = (target, all) => {
|
|
36
|
+
for (var name in all)
|
|
37
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
38
|
+
};
|
|
39
|
+
var __copyProps = (to, from, except, desc) => {
|
|
40
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
41
|
+
for (let key of __getOwnPropNames(from))
|
|
42
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
43
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
44
|
+
}
|
|
45
|
+
return to;
|
|
46
|
+
};
|
|
47
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
48
|
+
|
|
49
|
+
// src/index.ts
|
|
50
|
+
var index_exports = {};
|
|
51
|
+
__export(index_exports, {
|
|
52
|
+
COLOUR_ATTR_NAMES: () => COLOUR_ATTR_NAMES,
|
|
53
|
+
PX_ANIM_ATTR_NAME: () => PX_ANIM_ATTR_NAME,
|
|
54
|
+
PX_ANIM_SRC_ATTR_NAME: () => PX_ANIM_SRC_ATTR_NAME,
|
|
55
|
+
STYLE_ATTR_NAMES: () => STYLE_ATTR_NAMES,
|
|
56
|
+
TRANSFORM_FN_NAMES: () => TRANSFORM_FN_NAMES,
|
|
57
|
+
calcAnimationValues: () => calcAnimationValues,
|
|
58
|
+
camelCaseToKebabWordIfNeeded: () => camelCaseToKebabWordIfNeeded,
|
|
59
|
+
createAnimator: () => createAnimator,
|
|
60
|
+
createAnimatorImpl: () => createAnimatorImpl,
|
|
61
|
+
createBasicFrameLoopAnimator: () => createBasicFrameLoopAnimator,
|
|
62
|
+
createFrameLoopAnimator: () => createFrameLoopAnimator,
|
|
63
|
+
createWebApiAnimator: () => createWebApiAnimator,
|
|
64
|
+
generateNewIds: () => generateNewIds,
|
|
65
|
+
getAnimatorConfig: () => getAnimatorConfig,
|
|
66
|
+
getBindings: () => getBindings,
|
|
67
|
+
getChildren: () => getChildren,
|
|
68
|
+
getDefs: () => getDefs,
|
|
69
|
+
getNormalizedProps: () => getNormalizedProps,
|
|
70
|
+
isPxElementFileFormat: () => isPxElementFileFormat,
|
|
71
|
+
isPxElementFileFormatDeep: () => isPxElementFileFormatDeep,
|
|
72
|
+
loadTagAnimators: () => loadTagAnimators,
|
|
73
|
+
normalizeDocument: () => getNormalisedBindings,
|
|
74
|
+
renderNode: () => renderNode,
|
|
75
|
+
setupAnimationTriggers: () => setupAnimationTriggers,
|
|
76
|
+
toRGBA: () => toRGBA
|
|
77
|
+
});
|
|
78
|
+
module.exports = __toCommonJS(index_exports);
|
|
79
|
+
|
|
80
|
+
// src/PxAnimatorUtil.ts
|
|
81
|
+
function bezierToSvgPath(path) {
|
|
82
|
+
var _a, _b, _c, _d;
|
|
83
|
+
const v = path.v;
|
|
84
|
+
const i = path.i;
|
|
85
|
+
const o = path.o;
|
|
86
|
+
const c = path.c;
|
|
87
|
+
if (!v.length) return "";
|
|
88
|
+
const d = [];
|
|
89
|
+
const len = v.length;
|
|
90
|
+
d.push("M" + v[0][0] + "," + v[0][1]);
|
|
91
|
+
for (let idx = 1; idx < len; idx++) {
|
|
92
|
+
const prevV = v[idx - 1];
|
|
93
|
+
const prevO = (_a = o == null ? void 0 : o[idx - 1]) != null ? _a : prevV;
|
|
94
|
+
const currI = (_b = i == null ? void 0 : i[idx]) != null ? _b : v[idx];
|
|
95
|
+
const currV = v[idx];
|
|
96
|
+
const isLine = prevO[0] === prevV[0] && prevO[1] === prevV[1] && (currI[0] === currV[0] && currI[1] === currV[1]);
|
|
97
|
+
if (isLine) {
|
|
98
|
+
d.push("L" + currV[0] + "," + currV[1]);
|
|
99
|
+
} else {
|
|
100
|
+
d.push("C" + prevO[0] + "," + prevO[1] + "," + currI[0] + "," + currI[1] + "," + currV[0] + "," + currV[1]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (c && len > 0) {
|
|
104
|
+
const lastV = v[len - 1];
|
|
105
|
+
const lastO = (_c = o == null ? void 0 : o[len - 1]) != null ? _c : lastV;
|
|
106
|
+
const firstI = (_d = i == null ? void 0 : i[0]) != null ? _d : v[0];
|
|
107
|
+
const firstV = v[0];
|
|
108
|
+
const isLine = lastO[0] === lastV[0] && lastO[1] === lastV[1] && (firstI[0] === firstV[0] && firstI[1] === firstV[1]);
|
|
109
|
+
if (!isLine) {
|
|
110
|
+
d.push("C" + lastO[0] + "," + lastO[1] + "," + firstI[0] + "," + firstI[1] + "," + firstV[0] + "," + firstV[1]);
|
|
111
|
+
}
|
|
112
|
+
d.push("z");
|
|
113
|
+
}
|
|
114
|
+
return d.join("");
|
|
115
|
+
}
|
|
116
|
+
function interpolateNum(a, b, t) {
|
|
117
|
+
return a + (b - a) * t;
|
|
118
|
+
}
|
|
119
|
+
function interpolateVec(a, b, t) {
|
|
120
|
+
const res = [];
|
|
121
|
+
const count = Math.max(a.length, b.length);
|
|
122
|
+
for (let i = 0; i < count; i++) {
|
|
123
|
+
res[i] = interpolateNum(a[i] || 0, b[i] || 0, t);
|
|
124
|
+
}
|
|
125
|
+
return res;
|
|
126
|
+
}
|
|
127
|
+
function interpolateColor(a, b, t) {
|
|
128
|
+
return [
|
|
129
|
+
interpolateNum(a[0] || 0, b[0] || 0, t),
|
|
130
|
+
interpolateNum(a[1] || 0, b[1] || 0, t),
|
|
131
|
+
interpolateNum(a[2] || 0, b[2] || 0, t),
|
|
132
|
+
interpolateNum(a[3] === void 0 ? 1 : a[3], b[3] === void 0 ? 1 : b[3], t)
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
function interpolateBeziers(paths1, paths2, progress) {
|
|
136
|
+
const count = Math.max(paths1.length, paths2.length);
|
|
137
|
+
const res = [];
|
|
138
|
+
for (let i = 0; i < count; i++) {
|
|
139
|
+
res.push(interpolateBezier(paths1[i], paths2[i], progress));
|
|
140
|
+
}
|
|
141
|
+
return res;
|
|
142
|
+
}
|
|
143
|
+
function interpolateBezier(path1, path2, progress) {
|
|
144
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
145
|
+
if (!path1 || !path2) return path1 || path2 || { v: [] };
|
|
146
|
+
const t = Math.min(Math.max(progress, 0), 1);
|
|
147
|
+
const len = Math.min(path1.v.length, path2.v.length);
|
|
148
|
+
const v = [];
|
|
149
|
+
const i = [];
|
|
150
|
+
const o = [];
|
|
151
|
+
for (let idx = 0; idx < len; idx++) {
|
|
152
|
+
const v1 = path1.v[idx];
|
|
153
|
+
const v2 = path2.v[idx];
|
|
154
|
+
v.push(interpolateVec(v1, v2, t));
|
|
155
|
+
const i1 = (_b = (_a = path1.i) == null ? void 0 : _a[idx]) != null ? _b : v1;
|
|
156
|
+
const i2 = (_d = (_c = path2.i) == null ? void 0 : _c[idx]) != null ? _d : v2;
|
|
157
|
+
i.push(interpolateVec(i1, i2, t));
|
|
158
|
+
const o1 = (_f = (_e = path1.o) == null ? void 0 : _e[idx]) != null ? _f : v1;
|
|
159
|
+
const o2 = (_h = (_g = path2.o) == null ? void 0 : _g[idx]) != null ? _h : v2;
|
|
160
|
+
o.push(interpolateVec(o1, o2, t));
|
|
161
|
+
}
|
|
162
|
+
return { v, i: i.length ? i : void 0, o: o.length ? o : void 0, c: (_i = path1.c) != null ? _i : path2.c };
|
|
163
|
+
}
|
|
164
|
+
function remap(value, inMin, inMax, outMin, outMax) {
|
|
165
|
+
if (inMax === inMin) return outMin;
|
|
166
|
+
const t = (value - inMin) / (inMax - inMin);
|
|
167
|
+
return outMin + t * (outMax - outMin);
|
|
168
|
+
}
|
|
169
|
+
function cubicBezier(easing) {
|
|
170
|
+
const [p1x, p1y, p2x, p2y] = easing;
|
|
171
|
+
const cx = 3 * p1x;
|
|
172
|
+
const bx = 3 * (p2x - p1x) - cx;
|
|
173
|
+
const ax = 1 - cx - bx;
|
|
174
|
+
const cy = 3 * p1y;
|
|
175
|
+
const by = 3 * (p2y - p1y) - cy;
|
|
176
|
+
const ay = 1 - cy - by;
|
|
177
|
+
function sampleCurveX(t) {
|
|
178
|
+
return ((ax * t + bx) * t + cx) * t;
|
|
179
|
+
}
|
|
180
|
+
function sampleCurveY(t) {
|
|
181
|
+
return ((ay * t + by) * t + cy) * t;
|
|
182
|
+
}
|
|
183
|
+
function sampleCurveDerivativeX(t) {
|
|
184
|
+
return (3 * ax * t + 2 * bx) * t + cx;
|
|
185
|
+
}
|
|
186
|
+
function solveCurveX(x) {
|
|
187
|
+
if (x <= 0) return 0;
|
|
188
|
+
if (x >= 1) return 1;
|
|
189
|
+
let t2 = x;
|
|
190
|
+
let t0 = 0;
|
|
191
|
+
let t1 = 1;
|
|
192
|
+
for (let i = 0; i < 8; i++) {
|
|
193
|
+
const x2 = sampleCurveX(t2) - x;
|
|
194
|
+
if (Math.abs(x2) < 1e-6) return t2;
|
|
195
|
+
const d2 = sampleCurveDerivativeX(t2);
|
|
196
|
+
if (Math.abs(d2) < 1e-6) break;
|
|
197
|
+
t2 -= x2 / d2;
|
|
198
|
+
}
|
|
199
|
+
t2 = x;
|
|
200
|
+
while (t0 < t1) {
|
|
201
|
+
const x2 = sampleCurveX(t2);
|
|
202
|
+
if (Math.abs(x2 - x) < 1e-6) return t2;
|
|
203
|
+
if (x > x2) t0 = t2;
|
|
204
|
+
else t1 = t2;
|
|
205
|
+
t2 = (t1 + t0) / 2;
|
|
206
|
+
}
|
|
207
|
+
return t2;
|
|
208
|
+
}
|
|
209
|
+
return function(x) {
|
|
210
|
+
return sampleCurveY(solveCurveX(x));
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function toRGBA(color) {
|
|
214
|
+
const r = Math.round(color[0] * 255);
|
|
215
|
+
const g = Math.round(color[1] * 255);
|
|
216
|
+
const b = Math.round(color[2] * 255);
|
|
217
|
+
return color.length === 4 ? "rgba(" + r + "," + g + "," + b + "," + color[3] + ")" : "rgb(" + r + "," + g + "," + b + ")";
|
|
218
|
+
}
|
|
219
|
+
function parseRgba(s) {
|
|
220
|
+
var _a;
|
|
221
|
+
const inner = (_a = s.match(/rgba?\((.*)\)/)) == null ? void 0 : _a[1];
|
|
222
|
+
if (!inner) throw new Error("Invalid rgb/rgba format");
|
|
223
|
+
const parts = inner.split(",").map((v) => +v.trim());
|
|
224
|
+
return [parts[0] / 255, parts[1] / 255, parts[2] / 255, ...parts[3] !== void 0 ? [parts[3]] : []];
|
|
225
|
+
}
|
|
226
|
+
function parseHex(s) {
|
|
227
|
+
const hex = s.slice(1);
|
|
228
|
+
const isShort = hex.length <= 4;
|
|
229
|
+
const r = isShort ? hex[0] + hex[0] : hex.slice(0, 2);
|
|
230
|
+
const g = isShort ? hex[1] + hex[1] : hex.slice(2, 4);
|
|
231
|
+
const b = isShort ? hex[2] + hex[2] : hex.slice(4, 6);
|
|
232
|
+
const a = hex.length === 4 ? hex[3] + hex[3] : hex.length === 8 ? hex.slice(6, 8) : null;
|
|
233
|
+
const result = [
|
|
234
|
+
parseInt(r, 16) / 255,
|
|
235
|
+
parseInt(g, 16) / 255,
|
|
236
|
+
parseInt(b, 16) / 255
|
|
237
|
+
];
|
|
238
|
+
if (a !== null) {
|
|
239
|
+
result.push(parseInt(a, 16) / 255);
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
function parseColor(s) {
|
|
244
|
+
if (!s) return void 0;
|
|
245
|
+
if (Array.isArray(s)) return s;
|
|
246
|
+
if (typeof s !== "string") return void 0;
|
|
247
|
+
if (s.startsWith("#")) {
|
|
248
|
+
return parseHex(s);
|
|
249
|
+
} else if (s.startsWith("rgb")) {
|
|
250
|
+
return parseRgba(s);
|
|
251
|
+
} else {
|
|
252
|
+
console.warn("Unsupported color format: " + s);
|
|
253
|
+
}
|
|
254
|
+
return void 0;
|
|
255
|
+
}
|
|
256
|
+
var COLOUR_ATTR_NAMES = /* @__PURE__ */ new Set(["color", "fill", "flood-color", "lighting-color", "stop-color", "stroke"]);
|
|
257
|
+
var TRANSFORM_FN_NAMES = /* @__PURE__ */ new Set(["translate", "rotate", "scale", "skew"]);
|
|
258
|
+
var PCT_BASED_ATTR_NAMES = /* @__PURE__ */ new Set(["offset-distance", "offsetDistance"]);
|
|
259
|
+
var STYLE_ATTR_NAMES = /* @__PURE__ */ new Set(["offset-distance", "offsetDistance"]);
|
|
260
|
+
var DEFAULT_DURATION_MS = 1e3;
|
|
261
|
+
function kebabToCamelCaseWord(kebab) {
|
|
262
|
+
return kebab.includes("-") ? kebab.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()) : kebab;
|
|
263
|
+
}
|
|
264
|
+
function isCamelCaseWord(word) {
|
|
265
|
+
return !word.includes("-") && /[a-z][A-Z]/.test(word);
|
|
266
|
+
}
|
|
267
|
+
var SVG_CAMEL_CASE_ATTRS = /* @__PURE__ */ new Set([
|
|
268
|
+
// Transform/positioning
|
|
269
|
+
"viewBox",
|
|
270
|
+
"preserveAspectRatio",
|
|
271
|
+
// Gradient
|
|
272
|
+
"gradientUnits",
|
|
273
|
+
"gradientTransform",
|
|
274
|
+
"spreadMethod",
|
|
275
|
+
// Pattern
|
|
276
|
+
"patternUnits",
|
|
277
|
+
"patternContentUnits",
|
|
278
|
+
"patternTransform",
|
|
279
|
+
// Clipping/masking
|
|
280
|
+
"clipPathUnits",
|
|
281
|
+
"maskUnits",
|
|
282
|
+
"maskContentUnits",
|
|
283
|
+
// Text
|
|
284
|
+
"textLength",
|
|
285
|
+
"lengthAdjust",
|
|
286
|
+
"startOffset",
|
|
287
|
+
// Filter
|
|
288
|
+
"filterUnits",
|
|
289
|
+
"primitiveUnits",
|
|
290
|
+
"stdDeviation",
|
|
291
|
+
"baseFrequency",
|
|
292
|
+
"numOctaves",
|
|
293
|
+
"surfaceScale",
|
|
294
|
+
"diffuseConstant",
|
|
295
|
+
"specularConstant",
|
|
296
|
+
"specularExponent",
|
|
297
|
+
"kernelMatrix",
|
|
298
|
+
"kernelUnitLength",
|
|
299
|
+
"edgeMode",
|
|
300
|
+
"preserveAlpha",
|
|
301
|
+
"targetX",
|
|
302
|
+
"targetY"
|
|
303
|
+
// // Animation
|
|
304
|
+
// 'attributeName',
|
|
305
|
+
// 'attributeType',
|
|
306
|
+
// 'calcMode',
|
|
307
|
+
// 'keyTimes',
|
|
308
|
+
// 'keySplines',
|
|
309
|
+
// 'repeatCount',
|
|
310
|
+
// 'repeatDur'
|
|
311
|
+
]);
|
|
312
|
+
function camelCaseToKebabWordIfNeeded(camel) {
|
|
313
|
+
return SVG_CAMEL_CASE_ATTRS.has(camel) ? camel : camel.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
314
|
+
}
|
|
315
|
+
function clamp(value, min, max) {
|
|
316
|
+
return Math.max(min, Math.min(value, max));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// src/PxAnimatorDOM.ts
|
|
320
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
321
|
+
var INTERNAL_ATTRS = /* @__PURE__ */ new Set(["type", "children", "animate", "style", "animator", "defs", "bindings"]);
|
|
322
|
+
function createElement(tagName, props, style, children) {
|
|
323
|
+
const element = document.createElementNS(SVG_NS, tagName);
|
|
324
|
+
for (const propName in props) {
|
|
325
|
+
element.setAttribute(camelCaseToKebabWordIfNeeded(propName), props[propName]);
|
|
326
|
+
}
|
|
327
|
+
if (style) {
|
|
328
|
+
for (const styleProp in style) {
|
|
329
|
+
element.style[styleProp] = String(style[styleProp]);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (children) {
|
|
333
|
+
for (const child of children) {
|
|
334
|
+
element.appendChild(child);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return element;
|
|
338
|
+
}
|
|
339
|
+
function resolveStyle(style, defs) {
|
|
340
|
+
var _a;
|
|
341
|
+
if (!style) return void 0;
|
|
342
|
+
if (typeof style === "string") {
|
|
343
|
+
return (_a = defs == null ? void 0 : defs.styles) == null ? void 0 : _a[style];
|
|
344
|
+
}
|
|
345
|
+
return style;
|
|
346
|
+
}
|
|
347
|
+
function getNormalizedProps(props) {
|
|
348
|
+
const propsCopy = {};
|
|
349
|
+
for (const key of Object.keys(props)) {
|
|
350
|
+
if (INTERNAL_ATTRS.has(key)) continue;
|
|
351
|
+
let value = props[key];
|
|
352
|
+
if (COLOUR_ATTR_NAMES.has(key) && Array.isArray(value)) {
|
|
353
|
+
propsCopy[key] = toRGBA(value);
|
|
354
|
+
} else if (TRANSFORM_FN_NAMES.has(key)) {
|
|
355
|
+
if (Array.isArray(value)) {
|
|
356
|
+
if (key === "translate") value = value.map((v) => v + "px");
|
|
357
|
+
value = value.join(",");
|
|
358
|
+
}
|
|
359
|
+
if (key === "rotate") value = value + "deg";
|
|
360
|
+
propsCopy["transform"] = key + "(" + value + ")";
|
|
361
|
+
} else if (value !== void 0 && value !== null) {
|
|
362
|
+
propsCopy[key] = String(value);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return propsCopy;
|
|
366
|
+
}
|
|
367
|
+
function renderNode(node, defs) {
|
|
368
|
+
if (!node) return null;
|
|
369
|
+
const _a = node, { type, children, animate, style } = _a, props = __objRest(_a, ["type", "children", "animate", "style"]);
|
|
370
|
+
const nodeDefs = node.defs || defs;
|
|
371
|
+
const resolvedStyle = resolveStyle(style, nodeDefs);
|
|
372
|
+
let childElements;
|
|
373
|
+
if (children) {
|
|
374
|
+
for (const ch of children) {
|
|
375
|
+
const child = renderNode(ch, nodeDefs);
|
|
376
|
+
if (child) {
|
|
377
|
+
if (!childElements) childElements = [];
|
|
378
|
+
childElements.push(child);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return createElement(
|
|
383
|
+
type || "g",
|
|
384
|
+
getNormalizedProps(props),
|
|
385
|
+
resolvedStyle,
|
|
386
|
+
childElements
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// src/PxAnimatorTriggers.ts
|
|
391
|
+
function setupAnimationTriggers(api, config) {
|
|
392
|
+
const { startOn, outAction = "continue", scrollIntoViewThreshold = 0.5 } = config;
|
|
393
|
+
const root = api.getRootElement();
|
|
394
|
+
if (!root) {
|
|
395
|
+
console.warn("setupAnimationTriggers: No root element found for animation.");
|
|
396
|
+
return api;
|
|
397
|
+
}
|
|
398
|
+
const start = () => {
|
|
399
|
+
api.play();
|
|
400
|
+
};
|
|
401
|
+
const handleEndAction = () => {
|
|
402
|
+
switch (outAction) {
|
|
403
|
+
case "pause":
|
|
404
|
+
api.pause();
|
|
405
|
+
break;
|
|
406
|
+
case "reset":
|
|
407
|
+
api.cancel();
|
|
408
|
+
break;
|
|
409
|
+
case "reverse":
|
|
410
|
+
api.play();
|
|
411
|
+
break;
|
|
412
|
+
case "continue":
|
|
413
|
+
default:
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
switch (startOn) {
|
|
418
|
+
case "load": {
|
|
419
|
+
const startHandler = () => start();
|
|
420
|
+
if (document.readyState === "complete") {
|
|
421
|
+
startHandler();
|
|
422
|
+
} else {
|
|
423
|
+
window.addEventListener("load", startHandler, { once: true });
|
|
424
|
+
}
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
case "mouseOver": {
|
|
428
|
+
const mouseOverHandler = () => start();
|
|
429
|
+
const mouseOutHandler = () => handleEndAction();
|
|
430
|
+
root.addEventListener("mouseenter", mouseOverHandler);
|
|
431
|
+
root.addEventListener("mouseleave", mouseOutHandler);
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
case "click": {
|
|
435
|
+
const clickHandler = () => {
|
|
436
|
+
if (api.isPlaying()) {
|
|
437
|
+
handleEndAction();
|
|
438
|
+
} else {
|
|
439
|
+
start();
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
root.addEventListener("click", clickHandler);
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
case "scrollIntoView": {
|
|
446
|
+
const observer = new IntersectionObserver(
|
|
447
|
+
(entries) => {
|
|
448
|
+
entries.forEach((entry) => {
|
|
449
|
+
if (entry.isIntersecting && entry.intersectionRatio >= scrollIntoViewThreshold) {
|
|
450
|
+
start();
|
|
451
|
+
} else {
|
|
452
|
+
handleEndAction();
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
},
|
|
456
|
+
{ threshold: scrollIntoViewThreshold }
|
|
457
|
+
);
|
|
458
|
+
observer.observe(root);
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
case "programmatic":
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
return api;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// src/PxAnimatorTypes.ts
|
|
468
|
+
var PX_ANIM_SRC_ATTR_NAME = "data-px-animation-src";
|
|
469
|
+
var PX_ANIM_ATTR_NAME = "_px_animator";
|
|
470
|
+
function isPxElementFileFormat(fileJson) {
|
|
471
|
+
if (!(fileJson && typeof fileJson === "object" && !Array.isArray(fileJson))) {
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
return fileJson["type"] === "svg" || fileJson["tagName"] === "svg";
|
|
475
|
+
}
|
|
476
|
+
function isObject(v) {
|
|
477
|
+
return v && typeof v === "object" && !Array.isArray(v);
|
|
478
|
+
}
|
|
479
|
+
function validateFillMode(v, path, errors) {
|
|
480
|
+
if (v === "forwards" || v === "backwards" || v === "both" || v === "none") return true;
|
|
481
|
+
errors.push(path + ': invalid FillMode "' + v + `", expected 'forwards'|'backwards'|'both'|'none'`);
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
function validatePlaybackDirection(v, path, errors) {
|
|
485
|
+
if (v === "normal" || v === "reverse" || v === "alternate" || v === "alternate-reverse") return true;
|
|
486
|
+
errors.push(path + ': invalid PlaybackDirection "' + v + `", expected 'normal'|'reverse'|'alternate'|'alternate-reverse'`);
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
function validatePxEasingOrRef(v, path, errors) {
|
|
490
|
+
if (typeof v === "string") return true;
|
|
491
|
+
if (Array.isArray(v) && v.length === 4 && v.every((n) => typeof n === "number")) return true;
|
|
492
|
+
errors.push(path + ": invalid easing, expected string or [number, number, number, number]");
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
function validatePxKeyframe(v, path, errors) {
|
|
496
|
+
if (!isObject(v)) {
|
|
497
|
+
errors.push(path + ": expected object");
|
|
498
|
+
return false;
|
|
499
|
+
}
|
|
500
|
+
let valid = true;
|
|
501
|
+
if (v.time !== void 0 && typeof v.time !== "number") {
|
|
502
|
+
errors.push(path + ".time: expected number, got " + typeof v.time);
|
|
503
|
+
valid = false;
|
|
504
|
+
}
|
|
505
|
+
if (v.t !== void 0 && typeof v.t !== "number") {
|
|
506
|
+
errors.push(path + ".t: expected number, got " + typeof v.t);
|
|
507
|
+
valid = false;
|
|
508
|
+
}
|
|
509
|
+
if (v.easing !== void 0 && !validatePxEasingOrRef(v.easing, path + ".easing", errors)) valid = false;
|
|
510
|
+
if (v.e !== void 0 && !validatePxEasingOrRef(v.e, path + ".e", errors)) valid = false;
|
|
511
|
+
return valid;
|
|
512
|
+
}
|
|
513
|
+
function validatePxPropertyAnimation(v, path, errors) {
|
|
514
|
+
if (!isObject(v)) {
|
|
515
|
+
errors.push(path + ": expected object");
|
|
516
|
+
return false;
|
|
517
|
+
}
|
|
518
|
+
let valid = true;
|
|
519
|
+
if (v.keyframes !== void 0) {
|
|
520
|
+
if (!Array.isArray(v.keyframes)) {
|
|
521
|
+
errors.push(path + ".keyframes: expected array");
|
|
522
|
+
valid = false;
|
|
523
|
+
} else {
|
|
524
|
+
v.keyframes.forEach((kf, i) => {
|
|
525
|
+
if (!validatePxKeyframe(kf, path + ".keyframes[" + i + "]", errors)) valid = false;
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (v.kfs !== void 0) {
|
|
530
|
+
if (!Array.isArray(v.kfs)) {
|
|
531
|
+
errors.push(path + ".kfs: expected array");
|
|
532
|
+
valid = false;
|
|
533
|
+
} else {
|
|
534
|
+
v.kfs.forEach((kf, i) => {
|
|
535
|
+
if (!validatePxKeyframe(kf, path + ".kfs[" + i + "]", errors)) valid = false;
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return valid;
|
|
540
|
+
}
|
|
541
|
+
function validatePxAnimationDefinition(v, path, errors) {
|
|
542
|
+
if (!isObject(v)) {
|
|
543
|
+
errors.push(path + ": expected object");
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
546
|
+
let valid = true;
|
|
547
|
+
for (const key of Object.keys(v)) {
|
|
548
|
+
if (!validatePxPropertyAnimation(v[key], path + "." + key, errors)) valid = false;
|
|
549
|
+
}
|
|
550
|
+
return valid;
|
|
551
|
+
}
|
|
552
|
+
function validatePxElementAnimation(v, path, errors) {
|
|
553
|
+
if (typeof v === "string") return true;
|
|
554
|
+
if (Array.isArray(v)) {
|
|
555
|
+
let valid = true;
|
|
556
|
+
v.forEach((item, i) => {
|
|
557
|
+
if (typeof item !== "string" && !validatePxAnimationDefinition(item, path + "[" + i + "]", errors)) {
|
|
558
|
+
valid = false;
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
return valid;
|
|
562
|
+
}
|
|
563
|
+
if (isObject(v)) return validatePxAnimationDefinition(v, path, errors);
|
|
564
|
+
errors.push(path + ": expected string, array, or PxAnimationDefinition object");
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
function validatePxTrigger(v, path, errors) {
|
|
568
|
+
if (!isObject(v)) {
|
|
569
|
+
errors.push(path + ": expected object");
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
let valid = true;
|
|
573
|
+
const validStartOn = ["load", "mouseOver", "click", "scrollIntoView", "programmatic"];
|
|
574
|
+
if (!validStartOn.includes(v.startOn)) {
|
|
575
|
+
errors.push(path + '.startOn: invalid value "' + v.startOn + '", expected ' + validStartOn.join("|"));
|
|
576
|
+
valid = false;
|
|
577
|
+
}
|
|
578
|
+
if (v.outAction !== void 0) {
|
|
579
|
+
const validOutAction = ["continue", "pause", "reset", "reverse"];
|
|
580
|
+
if (!validOutAction.includes(v.outAction)) {
|
|
581
|
+
errors.push(path + '.outAction: invalid value "' + v.outAction + '", expected ' + validOutAction.join("|"));
|
|
582
|
+
valid = false;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
if (v.scrollIntoViewThreshold !== void 0 && typeof v.scrollIntoViewThreshold !== "number") {
|
|
586
|
+
errors.push(path + ".scrollIntoViewThreshold: expected number, got " + typeof v.scrollIntoViewThreshold);
|
|
587
|
+
valid = false;
|
|
588
|
+
}
|
|
589
|
+
return valid;
|
|
590
|
+
}
|
|
591
|
+
function validatePxAnimatorConfig(v, path, errors) {
|
|
592
|
+
if (!isObject(v)) {
|
|
593
|
+
errors.push(path + ": expected object");
|
|
594
|
+
return false;
|
|
595
|
+
}
|
|
596
|
+
let valid = true;
|
|
597
|
+
if (v.mode !== void 0 && !["auto", "webapi", "frames"].includes(v.mode)) {
|
|
598
|
+
errors.push(path + '.mode: invalid value "' + v.mode + `", expected 'auto'|'webapi'|'frames'`);
|
|
599
|
+
valid = false;
|
|
600
|
+
}
|
|
601
|
+
if (v.duration !== void 0 && typeof v.duration !== "number") {
|
|
602
|
+
errors.push(path + ".duration: expected number, got " + typeof v.duration);
|
|
603
|
+
valid = false;
|
|
604
|
+
}
|
|
605
|
+
if (v.delay !== void 0 && typeof v.delay !== "number") {
|
|
606
|
+
errors.push(path + ".delay: expected number, got " + typeof v.delay);
|
|
607
|
+
valid = false;
|
|
608
|
+
}
|
|
609
|
+
if (v.iterations !== void 0 && typeof v.iterations !== "number" && v.iterations !== "infinite") {
|
|
610
|
+
errors.push(path + ".iterations: expected number or 'infinite', got " + typeof v.iterations);
|
|
611
|
+
valid = false;
|
|
612
|
+
}
|
|
613
|
+
if (v.fill !== void 0 && !validateFillMode(v.fill, path + ".fill", errors)) valid = false;
|
|
614
|
+
if (v.direction !== void 0 && !validatePlaybackDirection(v.direction, path + ".direction", errors)) valid = false;
|
|
615
|
+
if (v.frameRate !== void 0 && typeof v.frameRate !== "number") {
|
|
616
|
+
errors.push(path + ".frameRate: expected number, got " + typeof v.frameRate);
|
|
617
|
+
valid = false;
|
|
618
|
+
}
|
|
619
|
+
if (v.trigger !== void 0 && !validatePxTrigger(v.trigger, path + ".trigger", errors)) valid = false;
|
|
620
|
+
return valid;
|
|
621
|
+
}
|
|
622
|
+
function validatePxDefs(v, path, errors) {
|
|
623
|
+
if (!isObject(v)) {
|
|
624
|
+
errors.push(path + ": expected object");
|
|
625
|
+
return false;
|
|
626
|
+
}
|
|
627
|
+
let valid = true;
|
|
628
|
+
if (v.easings !== void 0) {
|
|
629
|
+
if (!isObject(v.easings)) {
|
|
630
|
+
errors.push(path + ".easings: expected object");
|
|
631
|
+
valid = false;
|
|
632
|
+
} else {
|
|
633
|
+
for (const key of Object.keys(v.easings)) {
|
|
634
|
+
if (!validatePxEasingOrRef(v.easings[key], path + ".easings." + key, errors)) valid = false;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (v.animations !== void 0) {
|
|
639
|
+
if (!isObject(v.animations)) {
|
|
640
|
+
errors.push(path + ".animations: expected object");
|
|
641
|
+
valid = false;
|
|
642
|
+
} else {
|
|
643
|
+
for (const key of Object.keys(v.animations)) {
|
|
644
|
+
if (!validatePxAnimationDefinition(v.animations[key], path + ".animations." + key, errors)) valid = false;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (v.styles !== void 0 && !isObject(v.styles)) {
|
|
649
|
+
errors.push(path + ".styles: expected object");
|
|
650
|
+
valid = false;
|
|
651
|
+
}
|
|
652
|
+
return valid;
|
|
653
|
+
}
|
|
654
|
+
function validatePxBinding(v, path, errors) {
|
|
655
|
+
if (!isObject(v)) {
|
|
656
|
+
errors.push(path + ": expected object");
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
let valid = true;
|
|
660
|
+
if (typeof v.id !== "string") {
|
|
661
|
+
errors.push(path + ".id: expected string, got " + typeof v.id);
|
|
662
|
+
valid = false;
|
|
663
|
+
}
|
|
664
|
+
if (!validatePxElementAnimation(v.animate, path + ".animate", errors)) valid = false;
|
|
665
|
+
return valid;
|
|
666
|
+
}
|
|
667
|
+
function validatePxNode(v, path, errors) {
|
|
668
|
+
if (!isObject(v)) {
|
|
669
|
+
errors.push(path + ": expected object");
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
672
|
+
let valid = true;
|
|
673
|
+
if (typeof v.type !== "string") {
|
|
674
|
+
errors.push(path + ".type: expected string, got " + typeof v.type);
|
|
675
|
+
valid = false;
|
|
676
|
+
}
|
|
677
|
+
if (v.children !== void 0) {
|
|
678
|
+
if (!Array.isArray(v.children)) {
|
|
679
|
+
errors.push(path + ".children: expected array");
|
|
680
|
+
valid = false;
|
|
681
|
+
} else {
|
|
682
|
+
v.children.forEach((child, i) => {
|
|
683
|
+
if (!validatePxNode(child, path + ".children[" + i + "]", errors)) valid = false;
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
if (v.animate !== void 0 && !validatePxElementAnimation(v.animate, path + ".animate", errors)) valid = false;
|
|
688
|
+
return valid;
|
|
689
|
+
}
|
|
690
|
+
function validatePxSvgNode(v, path, errors) {
|
|
691
|
+
if (!validatePxNode(v, path, errors)) return false;
|
|
692
|
+
let valid = true;
|
|
693
|
+
if (v.type !== "svg") {
|
|
694
|
+
errors.push(path + ".type: expected 'svg', got '" + v.type + "'");
|
|
695
|
+
valid = false;
|
|
696
|
+
}
|
|
697
|
+
if (v.width !== void 0 && typeof v.width !== "number") {
|
|
698
|
+
errors.push(path + ".width: expected number, got " + typeof v.width);
|
|
699
|
+
valid = false;
|
|
700
|
+
}
|
|
701
|
+
if (v.height !== void 0 && typeof v.height !== "number") {
|
|
702
|
+
errors.push(path + ".height: expected number, got " + typeof v.height);
|
|
703
|
+
valid = false;
|
|
704
|
+
}
|
|
705
|
+
if (v.viewBox !== void 0 && typeof v.viewBox !== "string") {
|
|
706
|
+
errors.push(path + ".viewBox: expected string, got " + typeof v.viewBox);
|
|
707
|
+
valid = false;
|
|
708
|
+
}
|
|
709
|
+
if (v.animator !== void 0 && !validatePxAnimatorConfig(v.animator, path + ".animator", errors)) valid = false;
|
|
710
|
+
if (v.defs !== void 0 && !validatePxDefs(v.defs, path + ".defs", errors)) valid = false;
|
|
711
|
+
if (v.bindings !== void 0) {
|
|
712
|
+
if (!Array.isArray(v.bindings)) {
|
|
713
|
+
errors.push(path + ".bindings: expected array");
|
|
714
|
+
valid = false;
|
|
715
|
+
} else {
|
|
716
|
+
v.bindings.forEach((binding, i) => {
|
|
717
|
+
if (!validatePxBinding(binding, path + ".bindings[" + i + "]", errors)) valid = false;
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
if (v.design !== void 0 && !validatePxNode(v.design, path + ".design", errors)) valid = false;
|
|
722
|
+
return valid;
|
|
723
|
+
}
|
|
724
|
+
function isPxElementFileFormatDeep(fileJson) {
|
|
725
|
+
const errors = [];
|
|
726
|
+
const valid = validatePxSvgNode(fileJson, "root", errors);
|
|
727
|
+
return { valid, errors };
|
|
728
|
+
}
|
|
729
|
+
function getAnimatorConfig(doc) {
|
|
730
|
+
var _a, _b;
|
|
731
|
+
return (doc == null ? void 0 : doc.animator) || ((_a = doc == null ? void 0 : doc.meta) == null ? void 0 : _a.animator) || (doc == null ? void 0 : doc.animation) || ((_b = doc == null ? void 0 : doc.meta) == null ? void 0 : _b.animation);
|
|
732
|
+
}
|
|
733
|
+
function getDefs(doc) {
|
|
734
|
+
var _a;
|
|
735
|
+
if (!doc) return void 0;
|
|
736
|
+
return doc.defs || ((_a = doc.meta) == null ? void 0 : _a.defs);
|
|
737
|
+
}
|
|
738
|
+
function getBindings(doc) {
|
|
739
|
+
var _a;
|
|
740
|
+
if (!doc) return void 0;
|
|
741
|
+
return doc.bindings || ((_a = doc.meta) == null ? void 0 : _a.bindings);
|
|
742
|
+
}
|
|
743
|
+
function getChildren(doc) {
|
|
744
|
+
return doc == null ? void 0 : doc.children;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// src/PxDefinitions.ts
|
|
748
|
+
function parsePathCommands(d) {
|
|
749
|
+
const tokens = d.split(/([MLCZmlcz]|[\s,]+)/).map((t) => t.trim()).filter((t) => t && t !== ",");
|
|
750
|
+
const commands = [];
|
|
751
|
+
let currentCommand = null;
|
|
752
|
+
for (const token of tokens) {
|
|
753
|
+
if (/[MLCZmlcz]/.test(token)) {
|
|
754
|
+
currentCommand = { type: token, values: [] };
|
|
755
|
+
commands.push(currentCommand);
|
|
756
|
+
} else if (currentCommand) {
|
|
757
|
+
const value = +token;
|
|
758
|
+
currentCommand.values.push(Number.isNaN(value) ? 0 : value);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return commands;
|
|
762
|
+
}
|
|
763
|
+
function parseSvgPathToBezier(d) {
|
|
764
|
+
const res = [];
|
|
765
|
+
let currentPath;
|
|
766
|
+
const commands = parsePathCommands(d);
|
|
767
|
+
for (const command of commands) {
|
|
768
|
+
const type = command.type;
|
|
769
|
+
const values = command.values;
|
|
770
|
+
if (type === "M" || type === "m") {
|
|
771
|
+
const x = values[0] || 0;
|
|
772
|
+
const y = values[1] || 0;
|
|
773
|
+
currentPath = {
|
|
774
|
+
v: [[x, y]],
|
|
775
|
+
i: [[x, y]],
|
|
776
|
+
o: [[x, y]],
|
|
777
|
+
c: false
|
|
778
|
+
};
|
|
779
|
+
res.push(currentPath);
|
|
780
|
+
continue;
|
|
781
|
+
}
|
|
782
|
+
if (!currentPath) {
|
|
783
|
+
currentPath = {
|
|
784
|
+
v: [[0, 0]],
|
|
785
|
+
i: [[0, 0]],
|
|
786
|
+
o: [[0, 0]],
|
|
787
|
+
c: false
|
|
788
|
+
};
|
|
789
|
+
res.push(currentPath);
|
|
790
|
+
}
|
|
791
|
+
if (type === "L") {
|
|
792
|
+
const x = values[0] || 0;
|
|
793
|
+
const y = values[1] || 0;
|
|
794
|
+
currentPath.v.push([x, y]);
|
|
795
|
+
currentPath.i.push([x, y]);
|
|
796
|
+
currentPath.o.push([x, y]);
|
|
797
|
+
} else if (type === "C") {
|
|
798
|
+
const outX = values[0] || 0;
|
|
799
|
+
const outY = values[1] || 0;
|
|
800
|
+
const inX2 = values[2] || 0;
|
|
801
|
+
const inY2 = values[3] || 0;
|
|
802
|
+
const x2 = values[4] || 0;
|
|
803
|
+
const y2 = values[5] || 0;
|
|
804
|
+
currentPath.o[currentPath.o.length - 1] = [outX, outY];
|
|
805
|
+
currentPath.v.push([x2, y2]);
|
|
806
|
+
currentPath.i.push([inX2, inY2]);
|
|
807
|
+
currentPath.o.push([x2, y2]);
|
|
808
|
+
} else if (type === "Z" || type === "z") {
|
|
809
|
+
currentPath.c = true;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
return res;
|
|
813
|
+
}
|
|
814
|
+
function extractPathData(str) {
|
|
815
|
+
if (str.startsWith("path(") && str.endsWith(")")) {
|
|
816
|
+
return str.slice(5, -1);
|
|
817
|
+
}
|
|
818
|
+
if (/^[MmZzLlHhVvCcSsQqTtAa]/.test(str)) {
|
|
819
|
+
return str;
|
|
820
|
+
}
|
|
821
|
+
return void 0;
|
|
822
|
+
}
|
|
823
|
+
function isPathString(value) {
|
|
824
|
+
return typeof value === "string" && extractPathData(value) !== void 0;
|
|
825
|
+
}
|
|
826
|
+
function normalizePathValue(value) {
|
|
827
|
+
if (value && typeof value === "object" && "paths" in value) {
|
|
828
|
+
const pathsArray = value.paths;
|
|
829
|
+
if (Array.isArray(pathsArray) && pathsArray.length > 0) {
|
|
830
|
+
if (isPathString(pathsArray[0])) {
|
|
831
|
+
const paths = [];
|
|
832
|
+
for (const pathStr of pathsArray) {
|
|
833
|
+
const d = extractPathData(pathStr);
|
|
834
|
+
if (d) {
|
|
835
|
+
paths.push(...parseSvgPathToBezier(d));
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
return { paths };
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
return value;
|
|
842
|
+
}
|
|
843
|
+
if (Array.isArray(value)) {
|
|
844
|
+
if (value.length > 0 && isPathString(value[0])) {
|
|
845
|
+
const paths = [];
|
|
846
|
+
for (const pathStr of value) {
|
|
847
|
+
const d = extractPathData(pathStr);
|
|
848
|
+
if (d) {
|
|
849
|
+
paths.push(...parseSvgPathToBezier(d));
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
return { paths };
|
|
853
|
+
}
|
|
854
|
+
return { paths: value };
|
|
855
|
+
}
|
|
856
|
+
if (isPathString(value)) {
|
|
857
|
+
const d = extractPathData(value);
|
|
858
|
+
return { paths: parseSvgPathToBezier(d) };
|
|
859
|
+
}
|
|
860
|
+
return value;
|
|
861
|
+
}
|
|
862
|
+
function resolveEasing(easing, defs) {
|
|
863
|
+
var _a;
|
|
864
|
+
if (!easing) return void 0;
|
|
865
|
+
if (Array.isArray(easing)) {
|
|
866
|
+
return easing;
|
|
867
|
+
}
|
|
868
|
+
if ((_a = defs == null ? void 0 : defs.easings) == null ? void 0 : _a[easing]) {
|
|
869
|
+
return defs.easings[easing];
|
|
870
|
+
}
|
|
871
|
+
console.warn("Unknown easing name: " + easing);
|
|
872
|
+
return void 0;
|
|
873
|
+
}
|
|
874
|
+
function resolveAnimation(animRef, defs) {
|
|
875
|
+
var _a;
|
|
876
|
+
if (typeof animRef === "string") {
|
|
877
|
+
const resolved = (_a = defs == null ? void 0 : defs.animations) == null ? void 0 : _a[animRef];
|
|
878
|
+
if (!resolved) {
|
|
879
|
+
console.warn("Unknown animation name: " + animRef);
|
|
880
|
+
}
|
|
881
|
+
return resolved;
|
|
882
|
+
}
|
|
883
|
+
return animRef;
|
|
884
|
+
}
|
|
885
|
+
function resolveElementAnimation(animate, defs) {
|
|
886
|
+
if (!animate) return [];
|
|
887
|
+
const results = [];
|
|
888
|
+
if (typeof animate === "string") {
|
|
889
|
+
const resolved = resolveAnimation(animate, defs);
|
|
890
|
+
if (resolved) results.push(resolved);
|
|
891
|
+
} else if (Array.isArray(animate)) {
|
|
892
|
+
for (const item of animate) {
|
|
893
|
+
const resolved = resolveAnimation(item, defs);
|
|
894
|
+
if (resolved) results.push(resolved);
|
|
895
|
+
}
|
|
896
|
+
} else {
|
|
897
|
+
results.push(animate);
|
|
898
|
+
}
|
|
899
|
+
return results;
|
|
900
|
+
}
|
|
901
|
+
function normalizeKeyframes(propName, propAnim, duration, defs) {
|
|
902
|
+
var _a, _b, _c, _d, _e;
|
|
903
|
+
const keyframes = propAnim.keyframes || propAnim.kfs || [];
|
|
904
|
+
const normalized = [];
|
|
905
|
+
for (const kf of keyframes) {
|
|
906
|
+
const timePct = (_b = (_a = kf.time) != null ? _a : kf.t) != null ? _b : 0;
|
|
907
|
+
let value = (_c = kf.value) != null ? _c : kf.v;
|
|
908
|
+
const easing = (_d = kf.easing) != null ? _d : kf.e;
|
|
909
|
+
if (propName === "d") {
|
|
910
|
+
value = normalizePathValue(value);
|
|
911
|
+
}
|
|
912
|
+
if (COLOUR_ATTR_NAMES.has(propName)) {
|
|
913
|
+
value = (_e = parseColor(value)) != null ? _e : value;
|
|
914
|
+
}
|
|
915
|
+
normalized.push({
|
|
916
|
+
t: timePct,
|
|
917
|
+
v: value,
|
|
918
|
+
e: resolveEasing(easing, defs)
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
normalized.sort((a, b) => {
|
|
922
|
+
var _a2, _b2;
|
|
923
|
+
return ((_a2 = a.t) != null ? _a2 : 0) - ((_b2 = b.t) != null ? _b2 : 0);
|
|
924
|
+
});
|
|
925
|
+
return normalized;
|
|
926
|
+
}
|
|
927
|
+
function mergeAnimationDefinitions(animations) {
|
|
928
|
+
const merged = {};
|
|
929
|
+
for (const anim of animations) {
|
|
930
|
+
for (const [prop, propAnim] of Object.entries(anim)) {
|
|
931
|
+
merged[prop] = propAnim;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
return merged;
|
|
935
|
+
}
|
|
936
|
+
var _elementIdCounter = 0;
|
|
937
|
+
function generateElementId() {
|
|
938
|
+
return "_px_el_" + ++_elementIdCounter;
|
|
939
|
+
}
|
|
940
|
+
function normalizeAnimationDefinition(animDef, duration, defs) {
|
|
941
|
+
const normalized = {};
|
|
942
|
+
for (const [propName, propAnim] of Object.entries(animDef)) {
|
|
943
|
+
const normalizedKfs = normalizeKeyframes(propName, propAnim, duration, defs);
|
|
944
|
+
if (normalizedKfs.length > 0) {
|
|
945
|
+
normalized[propName] = { kfs: normalizedKfs };
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
return normalized;
|
|
949
|
+
}
|
|
950
|
+
function getNormalisedBindings(doc) {
|
|
951
|
+
const animatorConfig = getAnimatorConfig(doc) || {};
|
|
952
|
+
const defs = getDefs(doc);
|
|
953
|
+
const duration = animatorConfig.duration || 1e3;
|
|
954
|
+
const bindings = [];
|
|
955
|
+
const processAnimation = (id, animate) => {
|
|
956
|
+
if (!animate) return null;
|
|
957
|
+
const animDefs = resolveElementAnimation(animate, defs);
|
|
958
|
+
if (animDefs.length === 0) return null;
|
|
959
|
+
const merged = mergeAnimationDefinitions(animDefs);
|
|
960
|
+
const normalizedAnim = normalizeAnimationDefinition(merged, duration, defs);
|
|
961
|
+
if (Object.keys(normalizedAnim).length === 0) return null;
|
|
962
|
+
return {
|
|
963
|
+
id,
|
|
964
|
+
animate: normalizedAnim
|
|
965
|
+
};
|
|
966
|
+
};
|
|
967
|
+
const docBindings = getBindings(doc);
|
|
968
|
+
if (docBindings) {
|
|
969
|
+
for (const binding of docBindings) {
|
|
970
|
+
const normalized = processAnimation(binding.id, binding.animate);
|
|
971
|
+
if (normalized) bindings.push(normalized);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
const processNode = (node) => {
|
|
975
|
+
if (node.animate) {
|
|
976
|
+
const nodeId = node.id || generateElementId();
|
|
977
|
+
node.id = nodeId;
|
|
978
|
+
const normalized = processAnimation(nodeId, node.animate);
|
|
979
|
+
if (normalized) bindings.push(normalized);
|
|
980
|
+
}
|
|
981
|
+
if (node.children) {
|
|
982
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
983
|
+
processNode(node.children[i]);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
if (doc.children) {
|
|
988
|
+
for (let i = 0; i < doc.children.length; i++) {
|
|
989
|
+
processNode(doc.children[i]);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
return bindings;
|
|
993
|
+
}
|
|
994
|
+
function getKeyframesPair(keyframes, progress) {
|
|
995
|
+
var _a, _b;
|
|
996
|
+
let prevKf = keyframes[0];
|
|
997
|
+
let nextKf = keyframes[keyframes.length - 1];
|
|
998
|
+
for (let j = 0; j < keyframes.length - 1; j++) {
|
|
999
|
+
const aOff = (_a = keyframes[j].t) != null ? _a : 0;
|
|
1000
|
+
const bOff = (_b = keyframes[j + 1].t) != null ? _b : 0;
|
|
1001
|
+
if (aOff <= progress && progress <= bOff) {
|
|
1002
|
+
prevKf = keyframes[j];
|
|
1003
|
+
nextKf = keyframes[j + 1];
|
|
1004
|
+
break;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
return { prevKf, nextKf };
|
|
1008
|
+
}
|
|
1009
|
+
function calcPropertyValue(propName, propAnim, progress) {
|
|
1010
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1011
|
+
const keyframes = propAnim.kfs || propAnim.keyframes || [];
|
|
1012
|
+
if (keyframes.length === 0) return null;
|
|
1013
|
+
const { prevKf, nextKf } = getKeyframesPair(keyframes, progress);
|
|
1014
|
+
let localProgress = prevKf === nextKf ? 0 : remap(progress, (_a = prevKf.t) != null ? _a : 0, (_b = nextKf.t) != null ? _b : 0, 0, 1);
|
|
1015
|
+
localProgress = clamp(localProgress, 0, 1);
|
|
1016
|
+
const easing = (_c = prevKf.e) != null ? _c : prevKf.easing;
|
|
1017
|
+
if (easing && Array.isArray(easing)) {
|
|
1018
|
+
try {
|
|
1019
|
+
localProgress = cubicBezier(easing)(localProgress);
|
|
1020
|
+
} catch (e) {
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
let cssAttrName = isCamelCaseWord(propName) ? camelCaseToKebabWordIfNeeded(propName) : propName;
|
|
1024
|
+
let cssValue = null;
|
|
1025
|
+
const prevV = (_d = prevKf == null ? void 0 : prevKf.v) != null ? _d : prevKf == null ? void 0 : prevKf.value;
|
|
1026
|
+
const nextV = (_e = nextKf == null ? void 0 : nextKf.v) != null ? _e : nextKf == null ? void 0 : nextKf.value;
|
|
1027
|
+
if (cssAttrName === "d") {
|
|
1028
|
+
const prevPaths = (_f = prevV == null ? void 0 : prevV.paths) != null ? _f : Array.isArray(prevV) ? prevV : [];
|
|
1029
|
+
const nextPaths = (_g = nextV == null ? void 0 : nextV.paths) != null ? _g : Array.isArray(nextV) ? nextV : [];
|
|
1030
|
+
cssValue = interpolateBeziers(
|
|
1031
|
+
prevPaths,
|
|
1032
|
+
nextPaths,
|
|
1033
|
+
localProgress
|
|
1034
|
+
).map((bz) => bezierToSvgPath(bz)).join("");
|
|
1035
|
+
} else if (COLOUR_ATTR_NAMES.has(cssAttrName)) {
|
|
1036
|
+
cssValue = toRGBA(interpolateColor(
|
|
1037
|
+
prevV || [0, 0, 0, 1],
|
|
1038
|
+
nextV || [0, 0, 0, 1],
|
|
1039
|
+
localProgress
|
|
1040
|
+
));
|
|
1041
|
+
cssAttrName = propName;
|
|
1042
|
+
} else if (cssAttrName === "stroke-dasharray") {
|
|
1043
|
+
cssValue = interpolateVec(
|
|
1044
|
+
prevV || [],
|
|
1045
|
+
nextV || [],
|
|
1046
|
+
localProgress
|
|
1047
|
+
).join(" ");
|
|
1048
|
+
cssAttrName = propName;
|
|
1049
|
+
} else if (cssAttrName === "translate") {
|
|
1050
|
+
const v = interpolateVec(
|
|
1051
|
+
prevV || [0, 0],
|
|
1052
|
+
nextV || [0, 0],
|
|
1053
|
+
localProgress
|
|
1054
|
+
);
|
|
1055
|
+
cssValue = "translate(" + v.join(",") + ")";
|
|
1056
|
+
cssAttrName = "transform";
|
|
1057
|
+
} else if (cssAttrName === "rotate") {
|
|
1058
|
+
const v = interpolateNum(
|
|
1059
|
+
+(prevV || 0),
|
|
1060
|
+
+(nextV || 0),
|
|
1061
|
+
localProgress
|
|
1062
|
+
);
|
|
1063
|
+
cssValue = "rotate(" + v + ")";
|
|
1064
|
+
cssAttrName = "transform";
|
|
1065
|
+
} else if (cssAttrName === "scale") {
|
|
1066
|
+
const v = interpolateVec(
|
|
1067
|
+
prevV || [1, 1],
|
|
1068
|
+
nextV || [1, 1],
|
|
1069
|
+
localProgress
|
|
1070
|
+
);
|
|
1071
|
+
cssValue = "scale(" + v.join(",") + ")";
|
|
1072
|
+
cssAttrName = "transform";
|
|
1073
|
+
} else {
|
|
1074
|
+
const num = interpolateNum(
|
|
1075
|
+
+(prevV || 0),
|
|
1076
|
+
+(nextV || 0),
|
|
1077
|
+
localProgress
|
|
1078
|
+
);
|
|
1079
|
+
cssValue = num;
|
|
1080
|
+
}
|
|
1081
|
+
if (PCT_BASED_ATTR_NAMES.has(cssAttrName) && typeof cssValue === "number") {
|
|
1082
|
+
cssValue = cssValue * 100 + "%";
|
|
1083
|
+
}
|
|
1084
|
+
return { k: cssAttrName, v: cssValue === null ? "" : "" + cssValue };
|
|
1085
|
+
}
|
|
1086
|
+
function calcAnimationValues(animDef, progress) {
|
|
1087
|
+
const result = {};
|
|
1088
|
+
for (const [propName, propAnim] of Object.entries(animDef)) {
|
|
1089
|
+
const computed = calcPropertyValue(propName, propAnim, progress);
|
|
1090
|
+
if (computed) {
|
|
1091
|
+
result[computed.k] = computed.v;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
return result;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
// src/PxAnimatorFrameLoop.ts
|
|
1098
|
+
function getSelector(id) {
|
|
1099
|
+
return "#" + id;
|
|
1100
|
+
}
|
|
1101
|
+
function createBasicFrameLoopAnimator(doc, adapter, callbacks) {
|
|
1102
|
+
const config = getAnimatorConfig(doc) || {};
|
|
1103
|
+
const bindings = getNormalisedBindings(doc);
|
|
1104
|
+
const _iterations = config.iterations;
|
|
1105
|
+
let iterations = 1;
|
|
1106
|
+
if (typeof _iterations === "number") iterations = _iterations || 1;
|
|
1107
|
+
if (_iterations === "infinite") iterations = Infinity;
|
|
1108
|
+
if (iterations < 1) iterations = 1;
|
|
1109
|
+
const duration = +(config.duration || DEFAULT_DURATION_MS);
|
|
1110
|
+
const totalDuration = duration && iterations ? duration * (iterations === Infinity ? Infinity : iterations) : duration ? (iterations != null ? iterations : 1) * duration : 0;
|
|
1111
|
+
const direction = config.direction || "normal";
|
|
1112
|
+
let timerId = null;
|
|
1113
|
+
let playing = false;
|
|
1114
|
+
let timeBeforeLastStartMs = config.delay || 0;
|
|
1115
|
+
let lastStartedTs = 0;
|
|
1116
|
+
let playbackRate = 1;
|
|
1117
|
+
let finishCalled = false;
|
|
1118
|
+
const frameRate = config.frameRate;
|
|
1119
|
+
const minFrameIntervalMs = frameRate && frameRate > 0 ? 1e3 / frameRate : 0;
|
|
1120
|
+
let lastRenderTs = 0;
|
|
1121
|
+
const getAnimCurrentTime = () => {
|
|
1122
|
+
const runningElapsed = lastStartedTs ? (Date.now() - lastStartedTs) * playbackRate : 0;
|
|
1123
|
+
let time = timeBeforeLastStartMs + runningElapsed;
|
|
1124
|
+
if (Number.isFinite(totalDuration) && time > totalDuration) time = totalDuration;
|
|
1125
|
+
if (time < 0) time = 0;
|
|
1126
|
+
return time;
|
|
1127
|
+
};
|
|
1128
|
+
function renderFrame(currentTimeMs) {
|
|
1129
|
+
function getEffectiveProgress() {
|
|
1130
|
+
const safeDuration = duration > 0 ? duration : 1;
|
|
1131
|
+
let rawProgress = 0;
|
|
1132
|
+
let iteration = 0;
|
|
1133
|
+
if (duration > 0) {
|
|
1134
|
+
currentTimeMs = clamp(currentTimeMs, 0, iterations * safeDuration);
|
|
1135
|
+
iteration = Math.max(0, Math.ceil(currentTimeMs / safeDuration) - 1);
|
|
1136
|
+
iteration = Math.min(iteration, iterations - 1);
|
|
1137
|
+
const iterationTime = currentTimeMs - iteration * safeDuration;
|
|
1138
|
+
rawProgress = clamp(iterationTime / safeDuration, 0, 1);
|
|
1139
|
+
} else {
|
|
1140
|
+
rawProgress = currentTimeMs;
|
|
1141
|
+
}
|
|
1142
|
+
let baseProgress = rawProgress;
|
|
1143
|
+
const dir = direction || "normal";
|
|
1144
|
+
let effectiveProgress2 = baseProgress;
|
|
1145
|
+
if (dir === "reverse") {
|
|
1146
|
+
effectiveProgress2 = 1 - baseProgress;
|
|
1147
|
+
} else if (dir === "alternate") {
|
|
1148
|
+
if (iteration % 2 === 1) effectiveProgress2 = 1 - baseProgress;
|
|
1149
|
+
} else if (dir === "alternate-reverse") {
|
|
1150
|
+
if (iteration % 2 === 0) effectiveProgress2 = 1 - baseProgress;
|
|
1151
|
+
}
|
|
1152
|
+
return effectiveProgress2;
|
|
1153
|
+
}
|
|
1154
|
+
let effectiveProgress = getEffectiveProgress();
|
|
1155
|
+
for (const binding of bindings || []) {
|
|
1156
|
+
const animDef = binding.animate;
|
|
1157
|
+
if (!animDef || typeof animDef !== "object" || Array.isArray(animDef)) {
|
|
1158
|
+
console.warn("Empty or unresolved binding", binding);
|
|
1159
|
+
continue;
|
|
1160
|
+
}
|
|
1161
|
+
const computedValues = calcAnimationValues(animDef, effectiveProgress * duration);
|
|
1162
|
+
for (const [attrName, value] of Object.entries(computedValues)) {
|
|
1163
|
+
adapter.setAttribute(binding.id, attrName, value);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
const tick = () => {
|
|
1168
|
+
var _a;
|
|
1169
|
+
if (!adapter.isConnected()) {
|
|
1170
|
+
pauseAnim();
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
const currentTime = getAnimCurrentTime();
|
|
1174
|
+
if (minFrameIntervalMs > 0) {
|
|
1175
|
+
const now = Date.now();
|
|
1176
|
+
if (lastRenderTs && now - lastRenderTs < minFrameIntervalMs) {
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
lastRenderTs = now;
|
|
1180
|
+
}
|
|
1181
|
+
if (duration <= 0) {
|
|
1182
|
+
}
|
|
1183
|
+
if (totalDuration && Number.isFinite(totalDuration) && currentTime >= totalDuration) {
|
|
1184
|
+
renderFrame(totalDuration);
|
|
1185
|
+
if (!finishCalled) {
|
|
1186
|
+
finishCalled = true;
|
|
1187
|
+
(_a = callbacks == null ? void 0 : callbacks.onFinish) == null ? void 0 : _a.call(callbacks);
|
|
1188
|
+
}
|
|
1189
|
+
pauseAnim();
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
renderFrame(currentTime);
|
|
1193
|
+
};
|
|
1194
|
+
if (config.delay) {
|
|
1195
|
+
renderFrame(getAnimCurrentTime());
|
|
1196
|
+
}
|
|
1197
|
+
const _isPlaying = () => {
|
|
1198
|
+
if (!playing) return false;
|
|
1199
|
+
if (!adapter.isConnected()) {
|
|
1200
|
+
return false;
|
|
1201
|
+
}
|
|
1202
|
+
if (Number.isFinite(totalDuration) && getAnimCurrentTime() >= totalDuration) return false;
|
|
1203
|
+
return true;
|
|
1204
|
+
};
|
|
1205
|
+
const loopAnim = (isFirst) => {
|
|
1206
|
+
if (timerId !== null) {
|
|
1207
|
+
cancelAnimationFrame(timerId);
|
|
1208
|
+
timerId = null;
|
|
1209
|
+
}
|
|
1210
|
+
if (!(isFirst || _isPlaying())) {
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
timerId = requestAnimationFrame(() => {
|
|
1214
|
+
timerId = null;
|
|
1215
|
+
tick();
|
|
1216
|
+
loopAnim();
|
|
1217
|
+
});
|
|
1218
|
+
};
|
|
1219
|
+
const startAnim = () => {
|
|
1220
|
+
if (playing) return;
|
|
1221
|
+
playing = true;
|
|
1222
|
+
lastStartedTs = Date.now();
|
|
1223
|
+
loopAnim(true);
|
|
1224
|
+
};
|
|
1225
|
+
const pauseAnim = () => {
|
|
1226
|
+
if (!playing) return;
|
|
1227
|
+
timeBeforeLastStartMs = getAnimCurrentTime();
|
|
1228
|
+
lastStartedTs = 0;
|
|
1229
|
+
playing = false;
|
|
1230
|
+
if (timerId !== null) {
|
|
1231
|
+
cancelAnimationFrame(timerId);
|
|
1232
|
+
timerId = null;
|
|
1233
|
+
}
|
|
1234
|
+
renderFrame(timeBeforeLastStartMs);
|
|
1235
|
+
};
|
|
1236
|
+
const cancelAnim = () => {
|
|
1237
|
+
var _a;
|
|
1238
|
+
pauseAnim();
|
|
1239
|
+
timeBeforeLastStartMs = 0;
|
|
1240
|
+
lastStartedTs = 0;
|
|
1241
|
+
playing = false;
|
|
1242
|
+
finishCalled = false;
|
|
1243
|
+
renderFrame(timeBeforeLastStartMs);
|
|
1244
|
+
(_a = callbacks == null ? void 0 : callbacks.onCancel) == null ? void 0 : _a.call(callbacks);
|
|
1245
|
+
};
|
|
1246
|
+
const finishAnim = (callOnFinish = true) => {
|
|
1247
|
+
var _a;
|
|
1248
|
+
if (Number.isFinite(totalDuration)) {
|
|
1249
|
+
timeBeforeLastStartMs = totalDuration;
|
|
1250
|
+
} else {
|
|
1251
|
+
timeBeforeLastStartMs = getAnimCurrentTime();
|
|
1252
|
+
}
|
|
1253
|
+
lastStartedTs = 0;
|
|
1254
|
+
playing = false;
|
|
1255
|
+
renderFrame(timeBeforeLastStartMs);
|
|
1256
|
+
if (callOnFinish && !finishCalled) {
|
|
1257
|
+
finishCalled = true;
|
|
1258
|
+
(_a = callbacks == null ? void 0 : callbacks.onFinish) == null ? void 0 : _a.call(callbacks);
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1261
|
+
const api = {
|
|
1262
|
+
"isReady": () => true,
|
|
1263
|
+
"getRootElement": () => null,
|
|
1264
|
+
"isPlaying": () => {
|
|
1265
|
+
return _isPlaying();
|
|
1266
|
+
},
|
|
1267
|
+
"play": () => {
|
|
1268
|
+
var _a;
|
|
1269
|
+
startAnim();
|
|
1270
|
+
(_a = callbacks == null ? void 0 : callbacks.onPlay) == null ? void 0 : _a.call(callbacks);
|
|
1271
|
+
},
|
|
1272
|
+
"pause": () => {
|
|
1273
|
+
var _a;
|
|
1274
|
+
pauseAnim();
|
|
1275
|
+
(_a = callbacks == null ? void 0 : callbacks.onPause) == null ? void 0 : _a.call(callbacks);
|
|
1276
|
+
},
|
|
1277
|
+
"cancel": () => {
|
|
1278
|
+
cancelAnim();
|
|
1279
|
+
},
|
|
1280
|
+
"finish": () => {
|
|
1281
|
+
finishAnim(true);
|
|
1282
|
+
},
|
|
1283
|
+
"setPlaybackRate": (rate) => {
|
|
1284
|
+
if (!isFinite(rate) || rate === 0) {
|
|
1285
|
+
console.warn("setPlaybackRate: rate must be finite and non-zero");
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
const current = getAnimCurrentTime();
|
|
1289
|
+
playbackRate = rate;
|
|
1290
|
+
timeBeforeLastStartMs = current;
|
|
1291
|
+
if (playing) lastStartedTs = Date.now();
|
|
1292
|
+
},
|
|
1293
|
+
"getCurrentTime": () => {
|
|
1294
|
+
return getAnimCurrentTime();
|
|
1295
|
+
},
|
|
1296
|
+
"setCurrentTime": (newTime) => {
|
|
1297
|
+
if (newTime < 0) newTime = 0;
|
|
1298
|
+
if (Number.isFinite(totalDuration) && newTime > totalDuration) newTime = totalDuration;
|
|
1299
|
+
timeBeforeLastStartMs = newTime;
|
|
1300
|
+
if (playing) lastStartedTs = Date.now();
|
|
1301
|
+
renderFrame(getAnimCurrentTime());
|
|
1302
|
+
},
|
|
1303
|
+
"destroy": () => {
|
|
1304
|
+
api.cancel();
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1307
|
+
return api;
|
|
1308
|
+
}
|
|
1309
|
+
function createFrameLoopAnimator(doc, adapter, callbacks, rootElement) {
|
|
1310
|
+
const config = getAnimatorConfig(doc) || {};
|
|
1311
|
+
if (!rootElement) {
|
|
1312
|
+
if (doc.id) {
|
|
1313
|
+
const rootSelector = getSelector(doc.id);
|
|
1314
|
+
rootElement = document.querySelector(rootSelector);
|
|
1315
|
+
if (!rootElement) console.warn("createFrameLoopAnimator: No root element found for selector: ", rootSelector);
|
|
1316
|
+
} else {
|
|
1317
|
+
console.warn("createFrameLoopAnimator: No root element provided");
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
let api = createBasicFrameLoopAnimator(
|
|
1321
|
+
doc,
|
|
1322
|
+
adapter || createDomAdapter(rootElement),
|
|
1323
|
+
callbacks
|
|
1324
|
+
);
|
|
1325
|
+
api = __spreadProps(__spreadValues({}, api), {
|
|
1326
|
+
"getRootElement": () => rootElement || null
|
|
1327
|
+
});
|
|
1328
|
+
if (config.trigger) setupAnimationTriggers(api, config.trigger);
|
|
1329
|
+
return api;
|
|
1330
|
+
}
|
|
1331
|
+
function createDomAdapter(rootElement) {
|
|
1332
|
+
const warnedSelectors = /* @__PURE__ */ new Set();
|
|
1333
|
+
const adapter = {
|
|
1334
|
+
isConnected: () => {
|
|
1335
|
+
if (!rootElement) return true;
|
|
1336
|
+
return rootElement.isConnected;
|
|
1337
|
+
},
|
|
1338
|
+
setAttribute: (id, attrName, value) => {
|
|
1339
|
+
attrName = camelCaseToKebabWordIfNeeded(attrName);
|
|
1340
|
+
const selector = getSelector(id);
|
|
1341
|
+
const elements = (rootElement == null ? void 0 : rootElement.querySelectorAll(selector)) || document.querySelectorAll(selector);
|
|
1342
|
+
if (elements.length === 0 && !warnedSelectors.has(selector)) {
|
|
1343
|
+
warnedSelectors.add(selector);
|
|
1344
|
+
console.warn('setAttribute: No elements found for selector "' + selector + '"');
|
|
1345
|
+
}
|
|
1346
|
+
for (let i = 0; i < elements.length; i++) {
|
|
1347
|
+
const element = elements[i];
|
|
1348
|
+
element.setAttribute(attrName, value);
|
|
1349
|
+
if (STYLE_ATTR_NAMES.has(attrName)) {
|
|
1350
|
+
element.style[attrName] = value;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
return adapter;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
// src/PxAnimatorWebApi.ts
|
|
1359
|
+
function convertToWebApiKeyframes(animDef, unsupportedSet, config) {
|
|
1360
|
+
var _a, _b, _c, _d;
|
|
1361
|
+
const result = /* @__PURE__ */ new Map();
|
|
1362
|
+
for (const [propName, propAnim] of Object.entries(animDef)) {
|
|
1363
|
+
const keyframes = propAnim.kfs || propAnim.keyframes || [];
|
|
1364
|
+
const cssKeyframes = [];
|
|
1365
|
+
for (const kf of keyframes) {
|
|
1366
|
+
let t = (_b = (_a = kf.t) != null ? _a : kf.time) != null ? _b : 0;
|
|
1367
|
+
t = clamp(t / (config.duration || 1), 0, 1);
|
|
1368
|
+
let value = (_c = kf.v) != null ? _c : kf.value;
|
|
1369
|
+
const e = (_d = kf.e) != null ? _d : kf.easing;
|
|
1370
|
+
const cssKf = {
|
|
1371
|
+
offset: t,
|
|
1372
|
+
easing: e && Array.isArray(e) ? "cubic-bezier(" + e.join(",") + ")" : void 0
|
|
1373
|
+
};
|
|
1374
|
+
let cssValue;
|
|
1375
|
+
let cssKey = propName;
|
|
1376
|
+
if (COLOUR_ATTR_NAMES.has(propName) && Array.isArray(value)) {
|
|
1377
|
+
cssValue = toRGBA(value);
|
|
1378
|
+
} else if (TRANSFORM_FN_NAMES.has(propName)) {
|
|
1379
|
+
if (Array.isArray(value)) {
|
|
1380
|
+
if (propName === "translate") value = value.map((v) => v + "px");
|
|
1381
|
+
value = value.join(",");
|
|
1382
|
+
}
|
|
1383
|
+
if (propName === "rotate") value = value + "deg";
|
|
1384
|
+
cssValue = propName + "(" + value + ")";
|
|
1385
|
+
cssKey = "transform";
|
|
1386
|
+
} else {
|
|
1387
|
+
cssValue = "" + value;
|
|
1388
|
+
}
|
|
1389
|
+
if (!CSS.supports(cssKey, cssValue)) unsupportedSet.add(cssKey);
|
|
1390
|
+
cssKey = kebabToCamelCaseWord(cssKey);
|
|
1391
|
+
cssKf[cssKey] = cssValue;
|
|
1392
|
+
cssKeyframes.push(cssKf);
|
|
1393
|
+
}
|
|
1394
|
+
if (cssKeyframes.length > 0) {
|
|
1395
|
+
result.set(propName, cssKeyframes);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
return result;
|
|
1399
|
+
}
|
|
1400
|
+
function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsupportedAttrs) {
|
|
1401
|
+
const config = getAnimatorConfig(doc) || {};
|
|
1402
|
+
const bindings = getNormalisedBindings(doc);
|
|
1403
|
+
if (!rootElement) {
|
|
1404
|
+
if (doc.id) {
|
|
1405
|
+
const rootSelector = getSelector(doc.id);
|
|
1406
|
+
rootElement = document.querySelector(rootSelector);
|
|
1407
|
+
if (!rootElement) console.warn("createFrameLoopAnimator: No root element found for selector: ", rootSelector);
|
|
1408
|
+
} else {
|
|
1409
|
+
console.warn("createFrameLoopAnimator: No root element provided");
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
const animations = [];
|
|
1413
|
+
const _iterations = config.iterations;
|
|
1414
|
+
let iterations;
|
|
1415
|
+
if (typeof _iterations === "number") iterations = _iterations;
|
|
1416
|
+
if (_iterations === "infinite") iterations = Infinity;
|
|
1417
|
+
const unsupportedSet = /* @__PURE__ */ new Set();
|
|
1418
|
+
if (!(bindings == null ? void 0 : bindings.length)) {
|
|
1419
|
+
console.warn("createWebApiAnimator: No animation bindings defined");
|
|
1420
|
+
}
|
|
1421
|
+
for (const binding of bindings || []) {
|
|
1422
|
+
const animDef = binding.animate;
|
|
1423
|
+
if (!animDef || typeof animDef !== "object" || Array.isArray(animDef)) {
|
|
1424
|
+
console.warn("createWebApiAnimator: Empty or unresolved binding", binding);
|
|
1425
|
+
continue;
|
|
1426
|
+
}
|
|
1427
|
+
const selector = getSelector(binding.id);
|
|
1428
|
+
const elements = (rootElement == null ? void 0 : rootElement.querySelectorAll(selector)) || document.querySelectorAll(selector);
|
|
1429
|
+
if (elements.length === 0) {
|
|
1430
|
+
console.warn('createWebApiAnimator: No elements found for selector "' + selector + '"');
|
|
1431
|
+
}
|
|
1432
|
+
const keyframesMap = convertToWebApiKeyframes(animDef, unsupportedSet, config);
|
|
1433
|
+
for (let i = 0; i < elements.length; i++) {
|
|
1434
|
+
const element = elements[i];
|
|
1435
|
+
const positiveDelay = config.delay && config.delay > 0 ? config.delay : void 0;
|
|
1436
|
+
const seekPosition = config.delay && config.delay < 0 && config.duration ? -config.delay % config.duration : void 0;
|
|
1437
|
+
const effectOptions = {
|
|
1438
|
+
duration: config.duration,
|
|
1439
|
+
delay: positiveDelay,
|
|
1440
|
+
fill: config.fill,
|
|
1441
|
+
direction: config.direction,
|
|
1442
|
+
iterations
|
|
1443
|
+
};
|
|
1444
|
+
for (const [, keyframes] of keyframesMap) {
|
|
1445
|
+
if (keyframes.length > 0) {
|
|
1446
|
+
try {
|
|
1447
|
+
const effect = new KeyframeEffect(element, keyframes, effectOptions);
|
|
1448
|
+
const anim = new Animation(effect, document.timeline);
|
|
1449
|
+
if (callbacks == null ? void 0 : callbacks.onFinish) anim.onfinish = () => {
|
|
1450
|
+
var _a;
|
|
1451
|
+
return (_a = callbacks.onFinish) == null ? void 0 : _a.call(callbacks);
|
|
1452
|
+
};
|
|
1453
|
+
if (callbacks == null ? void 0 : callbacks.onRemove) anim.onremove = () => {
|
|
1454
|
+
var _a;
|
|
1455
|
+
return (_a = callbacks.onRemove) == null ? void 0 : _a.call(callbacks);
|
|
1456
|
+
};
|
|
1457
|
+
if (seekPosition) {
|
|
1458
|
+
anim.currentTime = seekPosition;
|
|
1459
|
+
}
|
|
1460
|
+
animations.push(anim);
|
|
1461
|
+
} catch (e) {
|
|
1462
|
+
console.warn(e);
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
if (!forceEvenIfHasUnsupportedAttrs && unsupportedSet.size) {
|
|
1469
|
+
console.warn("Unsupported CSS attrs: " + [...unsupportedSet].join(", "));
|
|
1470
|
+
return null;
|
|
1471
|
+
}
|
|
1472
|
+
const api = {
|
|
1473
|
+
"isReady": () => true,
|
|
1474
|
+
"getRootElement": () => rootElement || null,
|
|
1475
|
+
"isPlaying": () => {
|
|
1476
|
+
var _a;
|
|
1477
|
+
return ((_a = animations[0]) == null ? void 0 : _a.playState) === "running";
|
|
1478
|
+
},
|
|
1479
|
+
"play": () => {
|
|
1480
|
+
var _a;
|
|
1481
|
+
animations.forEach((a) => a.play());
|
|
1482
|
+
(_a = callbacks == null ? void 0 : callbacks.onPlay) == null ? void 0 : _a.call(callbacks);
|
|
1483
|
+
},
|
|
1484
|
+
"pause": () => {
|
|
1485
|
+
var _a;
|
|
1486
|
+
animations.forEach((a) => a.pause());
|
|
1487
|
+
(_a = callbacks == null ? void 0 : callbacks.onPause) == null ? void 0 : _a.call(callbacks);
|
|
1488
|
+
},
|
|
1489
|
+
"cancel": () => {
|
|
1490
|
+
var _a;
|
|
1491
|
+
animations.forEach((a) => a.cancel());
|
|
1492
|
+
(_a = callbacks == null ? void 0 : callbacks.onCancel) == null ? void 0 : _a.call(callbacks);
|
|
1493
|
+
},
|
|
1494
|
+
"finish": () => {
|
|
1495
|
+
animations.forEach((a) => a.finish());
|
|
1496
|
+
},
|
|
1497
|
+
"setPlaybackRate": (rate) => {
|
|
1498
|
+
animations.forEach((a) => a.playbackRate = rate);
|
|
1499
|
+
return api;
|
|
1500
|
+
},
|
|
1501
|
+
"getCurrentTime": () => {
|
|
1502
|
+
var _a, _b;
|
|
1503
|
+
const res = (_b = (_a = animations[0]) == null ? void 0 : _a.currentTime) != null ? _b : null;
|
|
1504
|
+
return res !== null ? +res : null;
|
|
1505
|
+
},
|
|
1506
|
+
"setCurrentTime": (time) => {
|
|
1507
|
+
animations.forEach((a) => {
|
|
1508
|
+
a.currentTime = time;
|
|
1509
|
+
});
|
|
1510
|
+
},
|
|
1511
|
+
"destroy": () => {
|
|
1512
|
+
api.cancel();
|
|
1513
|
+
animations.splice(0, animations.length);
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
if (config.trigger) {
|
|
1517
|
+
setupAnimationTriggers(api, config.trigger);
|
|
1518
|
+
}
|
|
1519
|
+
return api;
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
// src/PxAnimator.ts
|
|
1523
|
+
function createAnimatorFromConfig(doc, adapter, callbacks, rootElement) {
|
|
1524
|
+
const animatorConfig = getAnimatorConfig(doc) || {};
|
|
1525
|
+
let res;
|
|
1526
|
+
if (animatorConfig.mode === "frames") {
|
|
1527
|
+
res = createFrameLoopAnimator(doc, adapter, callbacks, rootElement);
|
|
1528
|
+
} else {
|
|
1529
|
+
res = createWebApiAnimator(
|
|
1530
|
+
doc,
|
|
1531
|
+
callbacks,
|
|
1532
|
+
rootElement,
|
|
1533
|
+
animatorConfig.mode === "webapi"
|
|
1534
|
+
// Forcing "webapi"
|
|
1535
|
+
) || createFrameLoopAnimator(doc, adapter, callbacks, rootElement);
|
|
1536
|
+
}
|
|
1537
|
+
if (animatorConfig.debugInstName) {
|
|
1538
|
+
window[animatorConfig.debugInstName] = res;
|
|
1539
|
+
}
|
|
1540
|
+
return res;
|
|
1541
|
+
}
|
|
1542
|
+
var _idCounter = 0;
|
|
1543
|
+
function generateUniqueId() {
|
|
1544
|
+
const timestamp = Date.now().toString(36);
|
|
1545
|
+
const counter = (++_idCounter).toString(36);
|
|
1546
|
+
const random = Math.random().toString(36).substring(2, 6);
|
|
1547
|
+
return "_px_" + timestamp + counter + random;
|
|
1548
|
+
}
|
|
1549
|
+
function deepClone(value) {
|
|
1550
|
+
if (value === null || typeof value !== "object") return value;
|
|
1551
|
+
if (Array.isArray(value)) return value.map((item) => deepClone(item));
|
|
1552
|
+
const obj = value;
|
|
1553
|
+
const cloned = {};
|
|
1554
|
+
for (const key of Object.keys(obj)) {
|
|
1555
|
+
cloned[key] = deepClone(obj[key]);
|
|
1556
|
+
}
|
|
1557
|
+
return cloned;
|
|
1558
|
+
}
|
|
1559
|
+
function generateNewIds(doc) {
|
|
1560
|
+
const cloned = deepClone(doc);
|
|
1561
|
+
const idMap = /* @__PURE__ */ new Map();
|
|
1562
|
+
const hashRefAttrs = /* @__PURE__ */ new Set(["href", "xlink:href"]);
|
|
1563
|
+
const urlRefAttrs = /* @__PURE__ */ new Set([
|
|
1564
|
+
"fill",
|
|
1565
|
+
"stroke",
|
|
1566
|
+
"clip-path",
|
|
1567
|
+
"clipPath",
|
|
1568
|
+
"mask",
|
|
1569
|
+
"marker",
|
|
1570
|
+
"marker-start",
|
|
1571
|
+
"marker-mid",
|
|
1572
|
+
"marker-end",
|
|
1573
|
+
"filter",
|
|
1574
|
+
"flood-color",
|
|
1575
|
+
"lighting-color"
|
|
1576
|
+
]);
|
|
1577
|
+
const directIdRefAttrs = /* @__PURE__ */ new Set(["baseId", "targetId", "boundElementId"]);
|
|
1578
|
+
function collectIds(node) {
|
|
1579
|
+
if (!node || typeof node !== "object") return;
|
|
1580
|
+
if (node.id && typeof node.id === "string") {
|
|
1581
|
+
const oldId = node.id;
|
|
1582
|
+
const newId = generateUniqueId();
|
|
1583
|
+
idMap.set(oldId, newId);
|
|
1584
|
+
node.id = newId;
|
|
1585
|
+
}
|
|
1586
|
+
if (Array.isArray(node.children)) {
|
|
1587
|
+
for (const child of node.children) {
|
|
1588
|
+
collectIds(child);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
function updateRefs(node) {
|
|
1593
|
+
if (!node || typeof node !== "object") return;
|
|
1594
|
+
for (const [key, value] of Object.entries(node)) {
|
|
1595
|
+
if (key === "children") {
|
|
1596
|
+
if (Array.isArray(value)) {
|
|
1597
|
+
for (const child of value) {
|
|
1598
|
+
updateRefs(child);
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
continue;
|
|
1602
|
+
}
|
|
1603
|
+
if (typeof value === "string") {
|
|
1604
|
+
if (hashRefAttrs.has(key) && value.startsWith("#")) {
|
|
1605
|
+
const oldId = value.slice(1);
|
|
1606
|
+
const newId = idMap.get(oldId);
|
|
1607
|
+
if (newId) {
|
|
1608
|
+
node[key] = "#" + newId;
|
|
1609
|
+
}
|
|
1610
|
+
} else if (urlRefAttrs.has(key)) {
|
|
1611
|
+
node[key] = replaceUrlRefs(value, idMap);
|
|
1612
|
+
} else if (directIdRefAttrs.has(key)) {
|
|
1613
|
+
const newId = idMap.get(value);
|
|
1614
|
+
if (newId) {
|
|
1615
|
+
node[key] = newId;
|
|
1616
|
+
}
|
|
1617
|
+
} else if (value.includes("url(#")) {
|
|
1618
|
+
node[key] = replaceUrlRefs(value, idMap);
|
|
1619
|
+
}
|
|
1620
|
+
} else if (key === "style" && typeof value === "object" && value !== null) {
|
|
1621
|
+
for (const [styleProp, styleValue] of Object.entries(value)) {
|
|
1622
|
+
if (typeof styleValue === "string") {
|
|
1623
|
+
value[styleProp] = replaceUrlRefs(styleValue, idMap);
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
} else if (typeof value === "object" && value !== null && key !== "animate") {
|
|
1627
|
+
updateRefs(value);
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
collectIds(cloned);
|
|
1632
|
+
updateRefs(cloned);
|
|
1633
|
+
const docBindings = cloned.bindings;
|
|
1634
|
+
if (Array.isArray(docBindings)) {
|
|
1635
|
+
for (const binding of docBindings) {
|
|
1636
|
+
if (binding.id) {
|
|
1637
|
+
const newId = idMap.get(binding.id);
|
|
1638
|
+
if (newId) {
|
|
1639
|
+
binding.id = newId;
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
return cloned;
|
|
1645
|
+
}
|
|
1646
|
+
function replaceUrlRefs(value, idMap) {
|
|
1647
|
+
return value.replace(/url\(#([^)]+)\)/g, (match, oldId) => {
|
|
1648
|
+
const newId = idMap.get(oldId);
|
|
1649
|
+
return newId ? "url(#" + newId + ")" : match;
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
function createAnimatorImpl(doc, adapter, callbacks, containerElement) {
|
|
1653
|
+
const animatorConfig = getAnimatorConfig(doc) || {};
|
|
1654
|
+
animatorConfig.debug = true;
|
|
1655
|
+
let rootElement = null;
|
|
1656
|
+
if (containerElement && doc.children) {
|
|
1657
|
+
doc = generateNewIds(doc);
|
|
1658
|
+
const containerEl = typeof containerElement === "string" ? document.querySelector(containerElement) : containerElement;
|
|
1659
|
+
if (containerEl) {
|
|
1660
|
+
rootElement = renderNode(doc);
|
|
1661
|
+
if (rootElement) {
|
|
1662
|
+
containerEl.replaceChildren(rootElement);
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
return createAnimatorFromConfig(doc, adapter, callbacks, rootElement);
|
|
1667
|
+
}
|
|
1668
|
+
function createAnimator(docOrUrl, adapter, callbacks, containerElement) {
|
|
1669
|
+
if (typeof docOrUrl === "object") {
|
|
1670
|
+
return createAnimatorImpl(docOrUrl, adapter, callbacks, containerElement);
|
|
1671
|
+
}
|
|
1672
|
+
let animator = null;
|
|
1673
|
+
fetch(docOrUrl).then((res) => res.json()).then((json) => {
|
|
1674
|
+
if (isPxElementFileFormat(json)) {
|
|
1675
|
+
animator = createAnimatorImpl(json, adapter, callbacks, containerElement);
|
|
1676
|
+
} else {
|
|
1677
|
+
console.error("Invalid animation document format");
|
|
1678
|
+
}
|
|
1679
|
+
});
|
|
1680
|
+
return {
|
|
1681
|
+
"isReady": () => !!animator,
|
|
1682
|
+
"getRootElement": () => animator ? animator.getRootElement() : null,
|
|
1683
|
+
"isPlaying": () => (animator == null ? void 0 : animator.isPlaying()) || false,
|
|
1684
|
+
"play": () => {
|
|
1685
|
+
animator == null ? void 0 : animator.play();
|
|
1686
|
+
},
|
|
1687
|
+
"pause": () => {
|
|
1688
|
+
animator == null ? void 0 : animator.pause();
|
|
1689
|
+
},
|
|
1690
|
+
"cancel": () => {
|
|
1691
|
+
animator == null ? void 0 : animator.cancel();
|
|
1692
|
+
},
|
|
1693
|
+
"finish": () => {
|
|
1694
|
+
animator == null ? void 0 : animator.finish();
|
|
1695
|
+
},
|
|
1696
|
+
"setPlaybackRate": (rate) => {
|
|
1697
|
+
animator == null ? void 0 : animator.setPlaybackRate(rate);
|
|
1698
|
+
},
|
|
1699
|
+
"getCurrentTime": () => (animator == null ? void 0 : animator.getCurrentTime()) || 0,
|
|
1700
|
+
"setCurrentTime": (time) => {
|
|
1701
|
+
animator == null ? void 0 : animator.setCurrentTime(time);
|
|
1702
|
+
},
|
|
1703
|
+
"destroy": () => {
|
|
1704
|
+
animator == null ? void 0 : animator.destroy();
|
|
1705
|
+
}
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1708
|
+
function loadTagAnimators() {
|
|
1709
|
+
const elements = document.querySelectorAll("[" + PX_ANIM_SRC_ATTR_NAME + "]");
|
|
1710
|
+
for (let i = 0; i < elements.length; i++) {
|
|
1711
|
+
const element = elements[i];
|
|
1712
|
+
if (!element[PX_ANIM_ATTR_NAME]) {
|
|
1713
|
+
const src = element.getAttribute(PX_ANIM_SRC_ATTR_NAME);
|
|
1714
|
+
if (src) {
|
|
1715
|
+
element[PX_ANIM_ATTR_NAME] = createAnimator(src, void 0, void 0, element);
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
if (typeof window !== "undefined") {
|
|
1721
|
+
window["loadTagAnimators"] = loadTagAnimators;
|
|
1722
|
+
window["createAnimator"] = createAnimator;
|
|
1723
|
+
window["setupAnimationTriggers"] = setupAnimationTriggers;
|
|
1724
|
+
}
|
|
1725
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1726
|
+
0 && (module.exports = {
|
|
1727
|
+
COLOUR_ATTR_NAMES,
|
|
1728
|
+
PX_ANIM_ATTR_NAME,
|
|
1729
|
+
PX_ANIM_SRC_ATTR_NAME,
|
|
1730
|
+
STYLE_ATTR_NAMES,
|
|
1731
|
+
TRANSFORM_FN_NAMES,
|
|
1732
|
+
calcAnimationValues,
|
|
1733
|
+
camelCaseToKebabWordIfNeeded,
|
|
1734
|
+
createAnimator,
|
|
1735
|
+
createAnimatorImpl,
|
|
1736
|
+
createBasicFrameLoopAnimator,
|
|
1737
|
+
createFrameLoopAnimator,
|
|
1738
|
+
createWebApiAnimator,
|
|
1739
|
+
generateNewIds,
|
|
1740
|
+
getAnimatorConfig,
|
|
1741
|
+
getBindings,
|
|
1742
|
+
getChildren,
|
|
1743
|
+
getDefs,
|
|
1744
|
+
getNormalizedProps,
|
|
1745
|
+
isPxElementFileFormat,
|
|
1746
|
+
isPxElementFileFormatDeep,
|
|
1747
|
+
loadTagAnimators,
|
|
1748
|
+
normalizeDocument,
|
|
1749
|
+
renderNode,
|
|
1750
|
+
setupAnimationTriggers,
|
|
1751
|
+
toRGBA
|
|
1752
|
+
});
|
|
1753
|
+
//# sourceMappingURL=index.cjs.map
|