@pixodesk/svg-animator-vue 1.0.28 → 1.0.29

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
@@ -57943,6 +57943,7 @@ ${codeFrame}` : message);
57943
57943
  subject: px.string().optional(),
57944
57944
  smoothing: px.number().optional(),
57945
57945
  pin: px.boolean().optional(),
57946
+ pinAlign: px.enum(["top", "center", "bottom"]).optional(),
57946
57947
  pinTop: px.number().optional(),
57947
57948
  pinDistance: px.number().optional(),
57948
57949
  range: PxScrollRangeSchema.optional()
@@ -61173,6 +61174,19 @@ ${codeFrame}` : message);
61173
61174
  TEXT_CONTENT_ATTR,
61174
61175
  "xml:space"
61175
61176
  ];
61177
+ var PAINT_STATIC_KEYS = [
61178
+ "fillOpacity",
61179
+ "fillRule",
61180
+ "strokeOpacity",
61181
+ "strokeDasharray",
61182
+ "strokeDashoffset",
61183
+ "strokeLinecap",
61184
+ "strokeLinejoin",
61185
+ "strokeMiterlimit",
61186
+ "mixBlendMode",
61187
+ "filter"
61188
+ ];
61189
+ var PAINT_ANIMATE_KEYS = ["fill", "stroke", "strokeWidth", "opacity", "fillOpacity", "strokeOpacity", "strokeDasharray", "strokeDashoffset"];
61176
61190
  function parseLen(v) {
61177
61191
  if (typeof v === "number") return v;
61178
61192
  if (typeof v === "string") {
@@ -61184,17 +61198,39 @@ ${codeFrame}` : message);
61184
61198
  function str(v) {
61185
61199
  return typeof v === "string" ? v : void 0;
61186
61200
  }
61201
+ function paintAnimateOf(node) {
61202
+ const bag = node.animate;
61203
+ if (!bag || typeof bag !== "object") return void 0;
61204
+ let out;
61205
+ for (const k of PAINT_ANIMATE_KEYS) {
61206
+ if (bag[k] !== void 0) (out != null ? out : out = {})[k] = bag[k];
61207
+ }
61208
+ return out;
61209
+ }
61187
61210
  function resolveStyle2(node, parent) {
61188
- var _a, _b, _c, _d, _e, _f, _g;
61189
- return {
61211
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
61212
+ const isTextRoot = node.type === "text";
61213
+ const nodeStyle = node.style;
61214
+ const own = (key) => {
61215
+ var _a2;
61216
+ return isTextRoot ? void 0 : (_a2 = node[key]) != null ? _a2 : nodeStyle == null ? void 0 : nodeStyle[key];
61217
+ };
61218
+ const res = {
61190
61219
  fontFamily: (_a = str(node.fontFamily)) != null ? _a : parent.fontFamily,
61191
61220
  fontSize: (_b = parseLen(node.fontSize)) != null ? _b : parent.fontSize,
61192
61221
  fill: (_c = node.fill) != null ? _c : parent.fill,
61193
61222
  stroke: (_d = node.stroke) != null ? _d : parent.stroke,
61194
61223
  strokeWidth: (_e = node.strokeWidth) != null ? _e : parent.strokeWidth,
61195
61224
  letterSpacing: (_f = parseLen(node.letterSpacing)) != null ? _f : parent.letterSpacing,
61196
- wordSpacing: (_g = parseLen(node.wordSpacing)) != null ? _g : parent.wordSpacing
61225
+ wordSpacing: (_g = parseLen(node.wordSpacing)) != null ? _g : parent.wordSpacing,
61226
+ opacity: (_h = parseLen(own("opacity"))) != null ? _h : parent.opacity,
61227
+ animate: (_i = isTextRoot ? void 0 : paintAnimateOf(node)) != null ? _i : parent.animate
61197
61228
  };
61229
+ for (const key of PAINT_STATIC_KEYS) {
61230
+ const v = (_j = own(key)) != null ? _j : parent[key];
61231
+ if (v !== void 0) res[key] = v;
61232
+ }
61233
+ return res;
61198
61234
  }
61199
61235
  function rootStyleOf(node) {
61200
61236
  var _a, _b, _c;
@@ -61213,6 +61249,11 @@ ${codeFrame}` : message);
61213
61249
  if (s.fill !== void 0) p.fill = s.fill;
61214
61250
  if (s.stroke !== void 0) p.stroke = s.stroke;
61215
61251
  if (s.strokeWidth !== void 0) p.strokeWidth = s.strokeWidth;
61252
+ if (s.opacity !== void 0 && s.opacity !== 1) p.opacity = s.opacity;
61253
+ for (const key of PAINT_STATIC_KEYS) {
61254
+ if (s[key] !== void 0) p[key] = s[key];
61255
+ }
61256
+ if (s.animate !== void 0) p.animate = s.animate;
61216
61257
  return p;
61217
61258
  }
61218
61259
  function glyphFontFor(s, glyphs, soleFont, warnings) {
@@ -61226,6 +61267,7 @@ ${codeFrame}` : message);
61226
61267
  return names.length === 1 ? glyphs[names[0]] : void 0;
61227
61268
  }
61228
61269
  var MISSING_GLYPH_ADVANCE_EM = 0.6;
61270
+ var MISSING_GLYPH_CLASS_NAME = "px-missing-glyph";
61229
61271
  function missingGlyphBoxEm(advanceEm, ascentEm) {
61230
61272
  if (advanceEm <= 0 || ascentEm <= 0) return "";
61231
61273
  const inset = 0.08;
@@ -61261,7 +61303,7 @@ ${codeFrame}` : message);
61261
61303
  pen.x += g.width * scale;
61262
61304
  } else if (/\S/.test(ch)) {
61263
61305
  const advEm = g && g.width > 0 ? g.width : MISSING_GLYPH_ADVANCE_EM * upm;
61264
- placements.push({ glyphD: missingGlyphBoxEm(advEm, ascentEm), m: [scale, 0, 0, scale, pen.x, pen.y], paint, line, x: pen.x, y: pen.y, scale });
61306
+ placements.push({ glyphD: missingGlyphBoxEm(advEm, ascentEm), m: [scale, 0, 0, scale, pen.x, pen.y], paint, isMissing: true, line, x: pen.x, y: pen.y, scale });
61265
61307
  pen.x += advEm * scale;
61266
61308
  } else {
61267
61309
  pen.x += (g ? g.width : 0) * scale;
@@ -61324,7 +61366,7 @@ ${codeFrame}` : message);
61324
61366
  } else if (/\S/.test(ch)) {
61325
61367
  const wEm = g && g.width > 0 ? g.width : MISSING_GLYPH_ADVANCE_EM * gf.unitsPerEm;
61326
61368
  const boxAdv = wEm * scale;
61327
- cells.push({ glyphD: missingGlyphBoxEm(wEm, ascentEm), widthEm: wEm, scale, paint, midBase: adv + boxAdv / 2 });
61369
+ cells.push({ glyphD: missingGlyphBoxEm(wEm, ascentEm), widthEm: wEm, scale, paint, isMissing: true, midBase: adv + boxAdv / 2 });
61328
61370
  adv += boxAdv;
61329
61371
  } else {
61330
61372
  adv += (g ? g.width : 0) * scale;
@@ -61380,6 +61422,7 @@ ${codeFrame}` : message);
61380
61422
  const placements = placeCells.map((c) => ({
61381
61423
  glyphD: c.glyphD,
61382
61424
  paint: c.paint,
61425
+ isMissing: c.isMissing,
61383
61426
  m: alongAffine(sampler, base + c.midBase * k, c.scale, c.widthEm, perp)
61384
61427
  }));
61385
61428
  return toGroup(node, buildPaths(placements, create, warnings), create);
@@ -61468,12 +61511,13 @@ ${codeFrame}` : message);
61468
61511
  const transform = { keyframes: kfs };
61469
61512
  if (loop !== void 0) transform.loop = loop;
61470
61513
  const animate = { transform };
61514
+ if (c.paint.animate) Object.assign(animate, c.paint.animate);
61471
61515
  if (isClip && opKfs.some((k) => k.value === 0)) {
61472
61516
  const op = { keyframes: opKfs };
61473
61517
  if (loop !== void 0) op.loop = loop;
61474
61518
  animate.opacity = op;
61475
61519
  }
61476
- out.push(create("path", __spreadProps2(__spreadValues2({ d }, paintProps(c.paint)), { animate }), []));
61520
+ out.push(create("path", __spreadProps2(__spreadValues2(__spreadValues2({ d }, paintProps(c.paint)), missingGlyphProps(c.isMissing)), { animate }), []));
61477
61521
  }
61478
61522
  return out;
61479
61523
  }
@@ -61482,24 +61526,34 @@ ${codeFrame}` : message);
61482
61526
  if (paint.fill !== void 0) p.fill = paint.fill;
61483
61527
  if (paint.stroke !== void 0) p.stroke = paint.stroke;
61484
61528
  if (paint.strokeWidth !== void 0) p.strokeWidth = paint.strokeWidth;
61529
+ if (paint.opacity !== void 0) p.opacity = paint.opacity;
61530
+ for (const key of PAINT_STATIC_KEYS) {
61531
+ if (paint[key] !== void 0) p[key] = paint[key];
61532
+ }
61485
61533
  return p;
61486
61534
  }
61535
+ function missingGlyphProps(isMissing) {
61536
+ return isMissing ? { class: MISSING_GLYPH_CLASS_NAME } : {};
61537
+ }
61487
61538
  function buildPaths(placements, create, warnings) {
61488
- var _a, _b, _c;
61489
61539
  if (!placements.length) {
61490
61540
  warnings == null ? void 0 : warnings.push("textGlyphs: nothing to render");
61491
61541
  return [];
61492
61542
  }
61493
61543
  const byPaint = /* @__PURE__ */ new Map();
61494
61544
  for (const p of placements) {
61495
- const key = JSON.stringify([(_a = p.paint.fill) != null ? _a : null, (_b = p.paint.stroke) != null ? _b : null, (_c = p.paint.strokeWidth) != null ? _c : null]);
61545
+ const key = JSON.stringify([p.paint, !!p.isMissing]);
61496
61546
  const baked = transformPathData(p.glyphD, p.m);
61497
61547
  const entry = byPaint.get(key);
61498
61548
  if (entry) entry.d += baked;
61499
- else byPaint.set(key, { paint: p.paint, d: baked });
61549
+ else byPaint.set(key, { paint: p.paint, d: baked, isMissing: p.isMissing });
61500
61550
  }
61501
61551
  const out = [];
61502
- for (const { paint, d } of byPaint.values()) out.push(create("path", __spreadValues2({ d }, paintProps(paint)), []));
61552
+ for (const { paint, d, isMissing } of byPaint.values()) {
61553
+ out.push(create("path", __spreadValues2(__spreadValues2(__spreadValues2({
61554
+ d
61555
+ }, paintProps(paint)), missingGlyphProps(isMissing)), paint.animate !== void 0 ? { animate: __spreadValues2({}, paint.animate) } : {}), []));
61556
+ }
61503
61557
  return out;
61504
61558
  }
61505
61559
  function toGroup(node, children, create) {
@@ -63000,8 +63054,11 @@ ${codeFrame}` : message);
63000
63054
  driver.refresh();
63001
63055
  return driver;
63002
63056
  }
63057
+ function pinScrollportHeight(svgRoot) {
63058
+ const scroller = findNearestScroller(svgRoot, "y");
63059
+ return scroller ? scroller.clientHeight : document.documentElement.clientHeight;
63060
+ }
63003
63061
  function applyScrollPin(svgRoot, scroll) {
63004
- var _a;
63005
63062
  const styled = svgRoot;
63006
63063
  if (!(scroll == null ? void 0 : scroll.pin) || !styled.style) return () => {
63007
63064
  };
@@ -63009,7 +63066,28 @@ ${codeFrame}` : message);
63009
63066
  const prevPosition = style.position;
63010
63067
  const prevTop = style.top;
63011
63068
  style.position = "sticky";
63012
- style.top = ((_a = scroll.pinTop) != null ? _a : 0) + "px";
63069
+ const alignFactor = scroll.pinAlign === "center" ? 0.5 : scroll.pinAlign === "bottom" ? 1 : 0;
63070
+ const applyTop = () => {
63071
+ var _a;
63072
+ const extra = (_a = scroll.pinTop) != null ? _a : 0;
63073
+ if (!alignFactor) {
63074
+ style.top = extra + "px";
63075
+ return;
63076
+ }
63077
+ const portSize = pinScrollportHeight(svgRoot);
63078
+ const ownSize = svgRoot.getBoundingClientRect().height;
63079
+ style.top = Math.round((portSize - ownSize) * alignFactor + extra) + "px";
63080
+ };
63081
+ applyTop();
63082
+ let resizeObserver = null;
63083
+ const onWindowResize = alignFactor ? applyTop : null;
63084
+ if (alignFactor) {
63085
+ if (onWindowResize) window.addEventListener("resize", onWindowResize);
63086
+ if (typeof ResizeObserver !== "undefined") {
63087
+ resizeObserver = new ResizeObserver(applyTop);
63088
+ resizeObserver.observe(svgRoot);
63089
+ }
63090
+ }
63013
63091
  let wrapper = null;
63014
63092
  const parent = svgRoot.parentElement;
63015
63093
  if (scroll.pinDistance && scroll.pinDistance > 0 && parent) {
@@ -63020,6 +63098,8 @@ ${codeFrame}` : message);
63020
63098
  wrapper.appendChild(svgRoot);
63021
63099
  }
63022
63100
  return () => {
63101
+ if (onWindowResize) window.removeEventListener("resize", onWindowResize);
63102
+ resizeObserver == null ? void 0 : resizeObserver.disconnect();
63023
63103
  style.position = prevPosition;
63024
63104
  style.top = prevTop;
63025
63105
  if (wrapper == null ? void 0 : wrapper.parentElement) {