@pixodesk/svg-animator-web 1.0.30 → 1.0.34
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/README.md +11 -9
- package/dist/index.cjs +247 -87
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +247 -87
- package/dist/index.js.map +1 -1
- package/dist/index.min.cjs +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.prerendered-waapi.umd.js +135 -17
- package/dist/index.prerendered-waapi.umd.js.map +1 -1
- package/dist/index.prerendered-waapi.umd.min.js +1 -1
- package/dist/index.prerendered.umd.js +136 -18
- package/dist/index.prerendered.umd.js.map +1 -1
- package/dist/index.prerendered.umd.min.js +1 -1
- package/dist/{index.umd.js → pixodesk-svg-animator.umd.js} +240 -86
- package/dist/pixodesk-svg-animator.umd.js.map +1 -0
- package/dist/pixodesk-svg-animator.umd.min.js +1 -0
- package/package.json +5 -5
- package/dist/index.umd.js.map +0 -1
- package/dist/index.umd.min.js +0 -1
|
@@ -21,6 +21,18 @@ var PixodeskAnimator = (() => {
|
|
|
21
21
|
return a;
|
|
22
22
|
};
|
|
23
23
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __objRest = (source, exclude) => {
|
|
25
|
+
var target = {};
|
|
26
|
+
for (var prop in source)
|
|
27
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
if (source != null && __getOwnPropSymbols)
|
|
30
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
+
target[prop] = source[prop];
|
|
33
|
+
}
|
|
34
|
+
return target;
|
|
35
|
+
};
|
|
24
36
|
var __export = (target, all) => {
|
|
25
37
|
for (var name in all)
|
|
26
38
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -291,6 +303,38 @@ var PixodeskAnimator = (() => {
|
|
|
291
303
|
if (o) segs.push("translate(" + -o[0] + tu + "," + -o[1] + tu + ")");
|
|
292
304
|
return segs.join("");
|
|
293
305
|
}
|
|
306
|
+
function parseTransformParts(str) {
|
|
307
|
+
var _a, _b;
|
|
308
|
+
if (!str || typeof str !== "string") return void 0;
|
|
309
|
+
const out = {};
|
|
310
|
+
const re = /([a-zA-Z]+)\s*\(([^)]*)\)/g;
|
|
311
|
+
const order = ["translate", "rotate", "skewX", "scale"];
|
|
312
|
+
let lastIdx = -1;
|
|
313
|
+
let m;
|
|
314
|
+
while ((m = re.exec(str)) !== null) {
|
|
315
|
+
const fn = m[1];
|
|
316
|
+
const idx = order.indexOf(fn);
|
|
317
|
+
if (idx < 0 || idx <= lastIdx) return void 0;
|
|
318
|
+
lastIdx = idx;
|
|
319
|
+
const nums = m[2].split(/[\s,]+/).filter(Boolean).map(Number);
|
|
320
|
+
if (nums.some((n) => Number.isNaN(n))) return void 0;
|
|
321
|
+
if (fn === "translate") {
|
|
322
|
+
if (nums.length < 1 || nums.length > 2) return void 0;
|
|
323
|
+
out.translate = [nums[0], (_a = nums[1]) != null ? _a : 0];
|
|
324
|
+
} else if (fn === "rotate") {
|
|
325
|
+
if (nums.length !== 1) return void 0;
|
|
326
|
+
out.rotate = nums[0];
|
|
327
|
+
} else if (fn === "skewX") {
|
|
328
|
+
if (nums.length !== 1) return void 0;
|
|
329
|
+
out.skew = nums[0];
|
|
330
|
+
} else {
|
|
331
|
+
if (nums.length < 1 || nums.length > 2) return void 0;
|
|
332
|
+
out.scale = [nums[0], (_b = nums[1]) != null ? _b : nums[0]];
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (str.replace(/([a-zA-Z]+)\s*\(([^)]*)\)/g, "").replace(/[\s,]/g, "").length) return void 0;
|
|
336
|
+
return Object.keys(out).length ? out : void 0;
|
|
337
|
+
}
|
|
294
338
|
function kebabToCamelCaseWord(kebab) {
|
|
295
339
|
return kebab.includes("-") ? kebab.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()) : kebab;
|
|
296
340
|
}
|
|
@@ -454,7 +498,51 @@ var PixodeskAnimator = (() => {
|
|
|
454
498
|
};
|
|
455
499
|
function getAnimatorConfig(doc) {
|
|
456
500
|
var _a;
|
|
457
|
-
|
|
501
|
+
const cfg = (doc == null ? void 0 : doc.animator) || ((_a = doc == null ? void 0 : doc.meta) == null ? void 0 : _a.animator);
|
|
502
|
+
return cfg ? flattenAnimatorTimeline(cfg) : void 0;
|
|
503
|
+
}
|
|
504
|
+
var flattenMemo = /* @__PURE__ */ new WeakMap();
|
|
505
|
+
function flattenAnimatorTimeline(cfg) {
|
|
506
|
+
const timeline = cfg.timeline;
|
|
507
|
+
if (timeline === void 0 || timeline === null || typeof timeline !== "object") return cfg;
|
|
508
|
+
const memoised = flattenMemo.get(cfg);
|
|
509
|
+
if (memoised) return memoised;
|
|
510
|
+
const _a = cfg, { timeline: _dropped } = _a, flat = __objRest(_a, ["timeline"]);
|
|
511
|
+
if (timeline.type === "scroll" || timeline.type === "view") {
|
|
512
|
+
flat.timelineSource = "scroll";
|
|
513
|
+
if (timeline.duration !== void 0) flat.duration = timeline.duration;
|
|
514
|
+
if (timeline.iterations !== void 0) flat.iterations = timeline.iterations;
|
|
515
|
+
const scroll = __spreadValues({}, flat.scroll || {});
|
|
516
|
+
scroll.kind = timeline.type;
|
|
517
|
+
if (timeline.engine !== void 0) scroll.driver = timeline.engine;
|
|
518
|
+
if (timeline.axis !== void 0) scroll.axis = timeline.axis;
|
|
519
|
+
if (timeline.source !== void 0) scroll.source = timeline.source;
|
|
520
|
+
if (timeline.subject !== void 0) scroll.subject = timeline.subject;
|
|
521
|
+
if (timeline.smoothing !== void 0) scroll.smoothing = timeline.smoothing;
|
|
522
|
+
if (timeline.range !== void 0) scroll.range = timeline.range;
|
|
523
|
+
const pin = timeline.pin;
|
|
524
|
+
if (typeof pin === "boolean") scroll.pin = pin;
|
|
525
|
+
else if (pin && typeof pin === "object") {
|
|
526
|
+
scroll.pin = true;
|
|
527
|
+
if (pin.align !== void 0) scroll.pinAlign = pin.align;
|
|
528
|
+
if (pin.top !== void 0) scroll.pinTop = pin.top;
|
|
529
|
+
if (pin.distance !== void 0) scroll.pinDistance = pin.distance;
|
|
530
|
+
}
|
|
531
|
+
flat.scroll = scroll;
|
|
532
|
+
} else {
|
|
533
|
+
if (timeline.duration !== void 0) flat.duration = timeline.duration;
|
|
534
|
+
if (timeline.trigger !== void 0) {
|
|
535
|
+
const _b = timeline.trigger, { onFinish } = _b, restTrigger = __objRest(_b, ["onFinish"]);
|
|
536
|
+
if (Object.keys(restTrigger).length) flat.trigger = restTrigger;
|
|
537
|
+
if (onFinish !== void 0) flat.resetOnFinish = onFinish === "reset";
|
|
538
|
+
}
|
|
539
|
+
if (timeline.delay !== void 0) flat.delay = timeline.delay;
|
|
540
|
+
if (timeline.iterations !== void 0) flat.iterations = timeline.iterations;
|
|
541
|
+
if (timeline.direction !== void 0) flat.direction = timeline.direction;
|
|
542
|
+
if (timeline.fill !== void 0) flat.fill = timeline.fill;
|
|
543
|
+
}
|
|
544
|
+
flattenMemo.set(cfg, flat);
|
|
545
|
+
return flat;
|
|
458
546
|
}
|
|
459
547
|
function getDefs(doc) {
|
|
460
548
|
var _a;
|
|
@@ -466,7 +554,7 @@ var PixodeskAnimator = (() => {
|
|
|
466
554
|
if (!doc) return void 0;
|
|
467
555
|
const animateById = (_a = getAnimatorConfig(doc)) == null ? void 0 : _a.animateById;
|
|
468
556
|
if (!animateById) return void 0;
|
|
469
|
-
return Object.entries(animateById).map(([id, anim]) => ({ id, animate: anim }));
|
|
557
|
+
return Object.entries(animateById).map(([id, anim]) => ({ id: id.startsWith("#") ? id.slice(1) : id, animate: anim }));
|
|
470
558
|
}
|
|
471
559
|
|
|
472
560
|
// ../svg-animator-core/src/PxMotionPath.ts
|
|
@@ -490,12 +578,12 @@ var PixodeskAnimator = (() => {
|
|
|
490
578
|
return (_a = kf.easing) != null ? _a : kf.e;
|
|
491
579
|
}
|
|
492
580
|
function propAnimIsMotionPath(anim) {
|
|
493
|
-
var _a, _b
|
|
494
|
-
const kfs =
|
|
581
|
+
var _a, _b;
|
|
582
|
+
const kfs = anim.keyframes;
|
|
495
583
|
if (!Array.isArray(kfs)) return false;
|
|
496
584
|
if (anim.autoOrient) return true;
|
|
497
585
|
for (const kf of kfs) {
|
|
498
|
-
if (((
|
|
586
|
+
if (((_a = kf.tangentIn) != null ? _a : kf.ti) || ((_b = kf.tangentOut) != null ? _b : kf.to)) return true;
|
|
499
587
|
}
|
|
500
588
|
return false;
|
|
501
589
|
}
|
|
@@ -529,14 +617,14 @@ var PixodeskAnimator = (() => {
|
|
|
529
617
|
var DEFAULT_ROTATION_TOL = 5;
|
|
530
618
|
var DEFAULT_MAX_SAMPLES = 32;
|
|
531
619
|
function materialiseMotionPathInPropAnim(anim, opts) {
|
|
532
|
-
var _a, _b, _c
|
|
620
|
+
var _a, _b, _c;
|
|
533
621
|
if (!propAnimIsMotionPath(anim)) return anim;
|
|
534
|
-
const kfs =
|
|
622
|
+
const kfs = anim.keyframes;
|
|
535
623
|
if (!Array.isArray(kfs) || kfs.length < 2) return anim;
|
|
536
624
|
const autoOrient = !!anim.autoOrient;
|
|
537
|
-
const flatnessTol = (
|
|
538
|
-
const rotationTol = (
|
|
539
|
-
const maxSamples = (
|
|
625
|
+
const flatnessTol = (_a = opts == null ? void 0 : opts.flatnessTolerance) != null ? _a : DEFAULT_FLATNESS_TOL;
|
|
626
|
+
const rotationTol = (_b = opts == null ? void 0 : opts.rotationTolerance) != null ? _b : DEFAULT_ROTATION_TOL;
|
|
627
|
+
const maxSamples = (_c = opts == null ? void 0 : opts.maxSamplesPerSegment) != null ? _c : DEFAULT_MAX_SAMPLES;
|
|
540
628
|
const out = [];
|
|
541
629
|
const firstPos = getKfTranslate(kfs[0]);
|
|
542
630
|
if (!firstPos) return anim;
|
|
@@ -565,7 +653,7 @@ var PixodeskAnimator = (() => {
|
|
|
565
653
|
const lastInE = getKfEasing(kfs[kfs.length - 1]);
|
|
566
654
|
if (lastInE) out[out.length - 1].e = lastInE;
|
|
567
655
|
if (autoOrient) unwrapAutoOrientRotations(out);
|
|
568
|
-
const result = {
|
|
656
|
+
const result = { keyframes: out };
|
|
569
657
|
if (anim.loop !== void 0) result.loop = anim.loop;
|
|
570
658
|
return result;
|
|
571
659
|
}
|
|
@@ -1193,7 +1281,7 @@ var PixodeskAnimator = (() => {
|
|
|
1193
1281
|
}
|
|
1194
1282
|
function normalizeKeyframes(propName, propAnim, duration, defs) {
|
|
1195
1283
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1196
|
-
const keyframes = propAnim.keyframes ||
|
|
1284
|
+
const keyframes = propAnim.keyframes || [];
|
|
1197
1285
|
const normalized = [];
|
|
1198
1286
|
for (const kf of keyframes) {
|
|
1199
1287
|
const timePct = (_b = (_a = kf.time) != null ? _a : kf.t) != null ? _b : 0;
|
|
@@ -1241,6 +1329,36 @@ var PixodeskAnimator = (() => {
|
|
|
1241
1329
|
function generateElementId() {
|
|
1242
1330
|
return "_px_el_" + ++_elementIdCounter;
|
|
1243
1331
|
}
|
|
1332
|
+
function mergeStaticTransformIntoAnimDef(animDef, staticTransform) {
|
|
1333
|
+
if (!animDef) return animDef;
|
|
1334
|
+
const staticParts = staticTransform && typeof staticTransform === "object" && !Array.isArray(staticTransform) ? staticTransform : parseTransformParts(staticTransform);
|
|
1335
|
+
if (!staticParts || !Object.keys(staticParts).length) return animDef;
|
|
1336
|
+
const mergeKfValue = (v) => v && typeof v === "object" && !Array.isArray(v) ? __spreadValues(__spreadValues({}, staticParts), v) : v;
|
|
1337
|
+
const transformAnim = animDef["transform"];
|
|
1338
|
+
if (transformAnim && typeof transformAnim === "object") {
|
|
1339
|
+
const anim = transformAnim;
|
|
1340
|
+
if (Array.isArray(anim.keyframes)) {
|
|
1341
|
+
const out = __spreadProps(__spreadValues({}, anim), {
|
|
1342
|
+
keyframes: anim.keyframes.map((kf) => __spreadProps(__spreadValues({}, kf), { value: mergeKfValue(kf.value) }))
|
|
1343
|
+
});
|
|
1344
|
+
if (out.value !== void 0) out.value = mergeKfValue(out.value);
|
|
1345
|
+
return __spreadProps(__spreadValues({}, animDef), { transform: out });
|
|
1346
|
+
}
|
|
1347
|
+
return animDef;
|
|
1348
|
+
}
|
|
1349
|
+
const channels = Object.keys(animDef).filter((k) => TRANSFORM_FN_NAMES.has(k));
|
|
1350
|
+
if (channels.length !== 1) return animDef;
|
|
1351
|
+
const ch = channels[0];
|
|
1352
|
+
const chAnim = animDef[ch];
|
|
1353
|
+
if (!chAnim || typeof chAnim !== "object" || !Array.isArray(chAnim.keyframes)) return animDef;
|
|
1354
|
+
const lifted = __spreadProps(__spreadValues({}, chAnim), {
|
|
1355
|
+
keyframes: chAnim.keyframes.map((kf) => __spreadProps(__spreadValues({}, kf), { value: __spreadProps(__spreadValues({}, staticParts), { [ch]: kf.value }) }))
|
|
1356
|
+
});
|
|
1357
|
+
if (lifted.value !== void 0) lifted.value = __spreadProps(__spreadValues({}, staticParts), { [ch]: lifted.value });
|
|
1358
|
+
const rest = __spreadValues({}, animDef);
|
|
1359
|
+
delete rest[ch];
|
|
1360
|
+
return __spreadProps(__spreadValues({}, rest), { transform: lifted });
|
|
1361
|
+
}
|
|
1244
1362
|
function normalizeAnimationDefinition(animDef, duration, defs, engine = PxAnimatorEngine.waapi) {
|
|
1245
1363
|
const normalized = {};
|
|
1246
1364
|
for (const [propName, propAnim] of Object.entries(animDef)) {
|
|
@@ -1249,7 +1367,7 @@ var PixodeskAnimator = (() => {
|
|
|
1249
1367
|
}
|
|
1250
1368
|
const normalizedKfs = normalizeKeyframes(propName, propAnim, duration, defs);
|
|
1251
1369
|
if (normalizedKfs.length > 0) {
|
|
1252
|
-
const out = {
|
|
1370
|
+
const out = { keyframes: normalizedKfs };
|
|
1253
1371
|
if (propAnim.autoOrient !== void 0) out.autoOrient = propAnim.autoOrient;
|
|
1254
1372
|
if (propAnim.loop !== void 0) out.loop = propAnim.loop;
|
|
1255
1373
|
normalized[propName] = engine === PxAnimatorEngine.waapi && propName === "transform" ? materialiseMotionPathInPropAnim(out) : out;
|
|
@@ -1262,11 +1380,11 @@ var PixodeskAnimator = (() => {
|
|
|
1262
1380
|
const defs = getDefs(doc);
|
|
1263
1381
|
const duration = animatorConfig.duration || 1e3;
|
|
1264
1382
|
const bindings = [];
|
|
1265
|
-
const processAnimation = (id, animate) => {
|
|
1383
|
+
const processAnimation = (id, animate, staticTransform) => {
|
|
1266
1384
|
if (!animate) return null;
|
|
1267
1385
|
const animDefs = resolveElementAnimation(animate, defs);
|
|
1268
1386
|
if (animDefs.length === 0) return null;
|
|
1269
|
-
const merged = mergeAnimationDefinitions(animDefs);
|
|
1387
|
+
const merged = mergeStaticTransformIntoAnimDef(mergeAnimationDefinitions(animDefs), staticTransform);
|
|
1270
1388
|
const normalizedAnim = normalizeAnimationDefinition(merged, duration, defs, engine);
|
|
1271
1389
|
if (Object.keys(normalizedAnim).length === 0) return null;
|
|
1272
1390
|
return {
|
|
@@ -1286,7 +1404,7 @@ var PixodeskAnimator = (() => {
|
|
|
1286
1404
|
if (inlineAnim && Object.keys(inlineAnim).length > 0) {
|
|
1287
1405
|
const nodeId = node.id || generateElementId();
|
|
1288
1406
|
node.id = nodeId;
|
|
1289
|
-
const normalized = processAnimation(nodeId, inlineAnim);
|
|
1407
|
+
const normalized = processAnimation(nodeId, inlineAnim, node.transform);
|
|
1290
1408
|
if (normalized) bindings.push(normalized);
|
|
1291
1409
|
}
|
|
1292
1410
|
if (node.children) {
|
|
@@ -1488,7 +1606,7 @@ var PixodeskAnimator = (() => {
|
|
|
1488
1606
|
const result = /* @__PURE__ */ new Map();
|
|
1489
1607
|
for (const [propName, propAnim] of Object.entries(animDef)) {
|
|
1490
1608
|
const duration = config.duration || 1;
|
|
1491
|
-
const clippedKeyframes = clipKeyframesToDuration(propName, propAnim.
|
|
1609
|
+
const clippedKeyframes = clipKeyframesToDuration(propName, propAnim.keyframes || [], duration);
|
|
1492
1610
|
const cssKeyframes = [];
|
|
1493
1611
|
for (let i = 0; i < clippedKeyframes.length; i++) {
|
|
1494
1612
|
const kf = clippedKeyframes[i];
|