@pixodesk/svg-animator-vue 1.0.24 → 1.0.26

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/dist/index.umd.js CHANGED
@@ -57641,8 +57641,10 @@ ${codeFrame}` : message);
57641
57641
  children: px.lazy(() => px.array(PxNodeSchema), []).optional()
57642
57642
  }), PxAttrValueSchema);
57643
57643
  var PxSvgNodeExtra = px.object({
57644
- width: px.number().optional(),
57645
- height: px.number().optional(),
57644
+ // `"100%"` and other SVG length strings are legal here — a number-only slot rejected
57645
+ // real documents (e.g. apple-store-look-14-main.json) at the root <svg>.
57646
+ width: px.union([px.number(), px.string()]).optional(),
57647
+ height: px.union([px.number(), px.string()]).optional(),
57646
57648
  viewBox: px.string().optional(),
57647
57649
  animator: PxAnimatorConfigSchema.optional()
57648
57650
  });
@@ -58671,7 +58673,7 @@ ${codeFrame}` : message);
58671
58673
  if (newAnimate) cloned.animate = newAnimate;
58672
58674
  return cloned;
58673
58675
  }
58674
- var LOOP_JUMP_SHIFT_MS = 10;
58676
+ var LOOP_JUMP_SHIFT_MS = 1;
58675
58677
  function deepEqualValue(a, b) {
58676
58678
  if (a === b) return true;
58677
58679
  if (typeof a !== typeof b || a === null || b === null || typeof a !== "object") return false;
@@ -58920,6 +58922,8 @@ ${codeFrame}` : message);
58920
58922
  const looped = [];
58921
58923
  const separateBoundary = loop.extend !== PxLoopExtend.before;
58922
58924
  const originalTerminalKf = keyframes[keyframes.length - 1];
58925
+ let terminalEasingOverride;
58926
+ let hasTerminalEasingOverride = false;
58923
58927
  function appendRep(repStart, isReversed, partial) {
58924
58928
  var _a2;
58925
58929
  let entries;
@@ -58960,7 +58964,16 @@ ${codeFrame}` : message);
58960
58964
  const prevKf = looped.length > 0 ? looped[looped.length - 1] : originalTerminalKf;
58961
58965
  const isBoundary = separateBoundary && i === 0 && prevKf !== void 0 && Math.abs(((_a2 = prevKf.t) != null ? _a2 : 0) - (repStart + entry.relT * segDuration)) < 1e-9;
58962
58966
  if (isBoundary) {
58963
- if (deepEqualValue(prevKf.v, entry.v)) continue;
58967
+ if (deepEqualValue(prevKf.v, entry.v)) {
58968
+ if (looped.length > 0) {
58969
+ prevKf.e = entry.e;
58970
+ prevKf.tangentOut = entry.tangentOut;
58971
+ } else {
58972
+ terminalEasingOverride = entry.e;
58973
+ hasTerminalEasingOverride = true;
58974
+ }
58975
+ continue;
58976
+ }
58964
58977
  if (looped.length > 0) {
58965
58978
  delete prevKf.tangentIn;
58966
58979
  delete prevKf.tangentOut;
@@ -59041,6 +59054,11 @@ ${codeFrame}` : message);
59041
59054
  if (loop.extend === PxLoopExtend.before) {
59042
59055
  return [...looped, ...keyframes];
59043
59056
  } else {
59057
+ if (hasTerminalEasingOverride && keyframes.length > 0) {
59058
+ const head = keyframes.slice(0, -1);
59059
+ const tail = __spreadProps2(__spreadValues2({}, keyframes[keyframes.length - 1]), { e: terminalEasingOverride });
59060
+ return [...head, tail, ...looped];
59061
+ }
59044
59062
  return [...keyframes, ...looped];
59045
59063
  }
59046
59064
  }
@@ -59157,6 +59175,9 @@ ${codeFrame}` : message);
59157
59175
  function normalizeAnimationDefinition(animDef, duration, defs, engine = PxAnimatorEngine.waapi) {
59158
59176
  const normalized = {};
59159
59177
  for (const [propName, propAnim] of Object.entries(animDef)) {
59178
+ if (propName === "transform" && propAnim.alongPathMode === "offsetPath" && animDef["offsetDistance"] !== void 0) {
59179
+ continue;
59180
+ }
59160
59181
  const normalizedKfs = normalizeKeyframes(propName, propAnim, duration, defs);
59161
59182
  if (normalizedKfs.length > 0) {
59162
59183
  const out = { kfs: normalizedKfs };
@@ -61836,9 +61857,138 @@ ${codeFrame}` : message);
61836
61857
  applyAllRetimeEffects(node, ctx);
61837
61858
  return node;
61838
61859
  }
61860
+ var kfTime = (kf) => {
61861
+ var _a, _b;
61862
+ return (_b = (_a = kf.t) != null ? _a : kf.time) != null ? _b : 0;
61863
+ };
61864
+ var kfValue = (kf) => {
61865
+ var _a;
61866
+ return (_a = kf.v) != null ? _a : kf.value;
61867
+ };
61868
+ var kfEasing = (kf) => {
61869
+ var _a;
61870
+ return (_a = kf.e) != null ? _a : kf.easing;
61871
+ };
61872
+ var kfTangentIn = (kf) => {
61873
+ var _a;
61874
+ return (_a = kf.tangentIn) != null ? _a : kf.ti;
61875
+ };
61876
+ var kfTangentOut = (kf) => {
61877
+ var _a;
61878
+ return (_a = kf.tangentOut) != null ? _a : kf.to;
61879
+ };
61880
+ function cubicAt(p0, c1, c2, p1, t) {
61881
+ const u = 1 - t;
61882
+ const a = u * u * u, b = 3 * u * u * t, c = 3 * u * t * t, d = t * t * t;
61883
+ return [
61884
+ a * p0[0] + b * c1[0] + c * c2[0] + d * p1[0],
61885
+ a * p0[1] + b * c1[1] + c * c2[1] + d * p1[1]
61886
+ ];
61887
+ }
61888
+ function cubicLength(p0, c1, c2, p1, steps = 64) {
61889
+ let len = 0;
61890
+ let prev = p0;
61891
+ for (let i = 1; i <= steps; i++) {
61892
+ const pt = cubicAt(p0, c1, c2, p1, i / steps);
61893
+ len += Math.hypot(pt[0] - prev[0], pt[1] - prev[1]);
61894
+ prev = pt;
61895
+ }
61896
+ return len;
61897
+ }
61898
+ var fmt2 = (n) => {
61899
+ const r = Math.round(n * 1e4) / 1e4;
61900
+ return Object.is(r, -0) ? "0" : String(r);
61901
+ };
61902
+ function buildOffsetPath(propAnim) {
61903
+ var _a, _b, _c, _d;
61904
+ if (propAnim.alongPathMode !== "offsetPath") return void 0;
61905
+ const kfs = (_a = propAnim.keyframes) != null ? _a : propAnim.kfs;
61906
+ if (!kfs || kfs.length < 2) return void 0;
61907
+ const first = kfValue(kfs[0]);
61908
+ const anchor = (first == null ? void 0 : first.origin) && first.origin.length >= 2 ? [first.origin[0], first.origin[1]] : [0, 0];
61909
+ const points = [];
61910
+ for (const kf of kfs) {
61911
+ const v = kfValue(kf);
61912
+ const tr = v == null ? void 0 : v.translate;
61913
+ if (!tr || tr.length < 2) return void 0;
61914
+ const parts = Object.keys(v);
61915
+ if (parts.some((p) => p !== "translate" && p !== "origin")) return void 0;
61916
+ const o = (_b = v == null ? void 0 : v.origin) != null ? _b : [0, 0];
61917
+ if (o[0] !== anchor[0] || o[1] !== anchor[1]) return void 0;
61918
+ points.push([tr[0] + anchor[0], tr[1] + anchor[1]]);
61919
+ }
61920
+ if (!kfs.some((kf) => kfTangentIn(kf) || kfTangentOut(kf))) return void 0;
61921
+ let d = "M" + fmt2(points[0][0]) + "," + fmt2(points[0][1]);
61922
+ const segLens = [];
61923
+ for (let i = 0; i < points.length - 1; i++) {
61924
+ const p0 = points[i], p1 = points[i + 1];
61925
+ const to = (_c = kfTangentOut(kfs[i])) != null ? _c : [0, 0];
61926
+ const ti = (_d = kfTangentIn(kfs[i + 1])) != null ? _d : [0, 0];
61927
+ const c1 = [p0[0] + to[0], p0[1] + to[1]];
61928
+ const c2 = [p1[0] + ti[0], p1[1] + ti[1]];
61929
+ d += "C" + fmt2(c1[0]) + "," + fmt2(c1[1]) + "," + fmt2(c2[0]) + "," + fmt2(c2[1]) + "," + fmt2(p1[0]) + "," + fmt2(p1[1]);
61930
+ segLens.push(cubicLength(p0, c1, c2, p1));
61931
+ }
61932
+ const total = segLens.reduce((a, b) => a + b, 0);
61933
+ if (!(total > 0)) return void 0;
61934
+ const distanceKfs = [];
61935
+ let cum = 0;
61936
+ for (let i = 0; i < kfs.length; i++) {
61937
+ if (i > 0) cum += segLens[i - 1];
61938
+ const out = { t: kfTime(kfs[i]), v: cum / total };
61939
+ const e = kfEasing(kfs[i]);
61940
+ if (e !== void 0) out.e = e;
61941
+ distanceKfs.push(out);
61942
+ }
61943
+ return { pathStr: d, distanceKfs, autoOrient: !!propAnim.autoOrient, anchor };
61944
+ }
61945
+ function materialiseOffsetPathsInTree(root) {
61946
+ const walk = (node) => {
61947
+ var _a;
61948
+ let out = node;
61949
+ const anim = node.animate;
61950
+ const transform = anim == null ? void 0 : anim["transform"];
61951
+ if (transform) {
61952
+ const built = buildOffsetPath(transform);
61953
+ if (built) {
61954
+ const newAnimate = __spreadValues2({}, anim);
61955
+ delete newAnimate["transform"];
61956
+ const distance = { keyframes: built.distanceKfs };
61957
+ if (transform.loop !== void 0) distance.loop = transform.loop;
61958
+ newAnimate["offsetDistance"] = distance;
61959
+ const staticTr = node.transform;
61960
+ let newTransform = staticTr;
61961
+ if (staticTr && typeof staticTr === "object") {
61962
+ const t = __spreadValues2({}, staticTr);
61963
+ delete t["translate"];
61964
+ delete t["origin"];
61965
+ newTransform = Object.keys(t).length ? t : void 0;
61966
+ }
61967
+ out = __spreadProps2(__spreadValues2({}, node), {
61968
+ animate: newAnimate,
61969
+ style: __spreadProps2(__spreadValues2({}, node.style), {
61970
+ offsetPath: "path('" + built.pathStr + "')",
61971
+ offsetAnchor: fmt2(built.anchor[0]) + "px " + fmt2(built.anchor[1]) + "px",
61972
+ offsetRotate: built.autoOrient ? "auto" : "0deg",
61973
+ offsetDistance: "0%"
61974
+ })
61975
+ });
61976
+ if (newTransform !== void 0) out.transform = newTransform;
61977
+ else delete out.transform;
61978
+ }
61979
+ }
61980
+ if ((_a = out.children) == null ? void 0 : _a.length) {
61981
+ const children = out.children.map(walk);
61982
+ if (children.some((c, i) => c !== out.children[i])) out = __spreadProps2(__spreadValues2({}, out), { children });
61983
+ }
61984
+ return out;
61985
+ };
61986
+ return walk(root);
61987
+ }
61839
61988
  function materialiseAllInTree(doc, engine, opts) {
61840
61989
  var _a, _b;
61841
61990
  let root = applyPlayerEffects(doc).root;
61991
+ root = materialiseOffsetPathsInTree(root);
61842
61992
  const duration = (_b = (_a = getAnimatorConfig(root)) == null ? void 0 : _a.duration) != null ? _b : DEFAULT_DURATION_MS;
61843
61993
  root = materialiseInternalLoopsInTree(root, duration);
61844
61994
  if (engine === PxAnimatorEngine.waapi) {
@@ -62334,6 +62484,8 @@ ${codeFrame}` : message);
62334
62484
  } else if (propName === "d") {
62335
62485
  const paths = value && typeof value === "object" && Array.isArray(value.paths) ? value.paths : [];
62336
62486
  cssValue = 'path("' + paths.map((bz) => bezierToSvgPath(bz, true)).join("") + '")';
62487
+ } else if (PCT_BASED_ATTR_NAMES.has(propName) && typeof value === "number") {
62488
+ cssValue = value * 100 + "%";
62337
62489
  } else {
62338
62490
  cssValue = "" + value;
62339
62491
  }