@pixldocs/canvas-renderer 0.5.114 → 0.5.116

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.cjs CHANGED
@@ -14017,7 +14017,7 @@ function PixldocsPreview(props) {
14017
14017
  !canvasSettled && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) })
14018
14018
  ] });
14019
14019
  }
14020
- const PACKAGE_VERSION = "0.5.114";
14020
+ const PACKAGE_VERSION = "0.5.116";
14021
14021
  const roundParityValue = (value) => {
14022
14022
  if (typeof value !== "number") return value;
14023
14023
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -16049,7 +16049,7 @@ function splitIntoRuns(text, mainSupportsChar) {
16049
16049
  return runs;
16050
16050
  }
16051
16051
  function rewriteSvgFontsForJsPDF(svgStr) {
16052
- var _a, _b, _c;
16052
+ var _a, _b;
16053
16053
  const parser = new DOMParser();
16054
16054
  const doc = parser.parseFromString(svgStr, "image/svg+xml");
16055
16055
  const allTextEls = Array.from(doc.querySelectorAll("text, tspan, textPath"));
@@ -16188,26 +16188,37 @@ function rewriteSvgFontsForJsPDF(svgStr) {
16188
16188
  }
16189
16189
  }
16190
16190
  const SVG_NS = "http://www.w3.org/2000/svg";
16191
- const transformedTspans = Array.from(doc.querySelectorAll("tspan[transform]"));
16192
- for (const tspan of transformedTspans) {
16193
- const parentText = tspan.parentElement;
16194
- if (!parentText || parentText.tagName.toLowerCase() !== "text") continue;
16195
- const transformVal = tspan.getAttribute("transform") || "";
16196
- if (!/skewX/i.test(transformVal)) continue;
16197
- const wrapper = doc.createElementNS(SVG_NS, "text");
16191
+ const positionedRunParents = Array.from(doc.querySelectorAll("text")).filter((textEl) => {
16192
+ const directTspans = Array.from(textEl.children).filter((child) => child.tagName.toLowerCase() === "tspan");
16193
+ if (directTspans.length === 0) return false;
16194
+ const directText = Array.from(textEl.childNodes).filter((node) => node.nodeType === 3).map((node) => node.textContent || "").join("");
16195
+ if (directText.trim()) return false;
16196
+ const hasTransformedRun = directTspans.some((tspan) => /skewX/i.test(tspan.getAttribute("transform") || ""));
16197
+ const allPositioned = directTspans.every((tspan) => tspan.hasAttribute("x") || tspan.hasAttribute("y"));
16198
+ return hasTransformedRun || directTspans.length > 1 && allPositioned;
16199
+ });
16200
+ for (const parentText of positionedRunParents) {
16201
+ if (!parentText.parentNode) continue;
16202
+ const directTspans = Array.from(parentText.children).filter((child) => child.tagName.toLowerCase() === "tspan");
16198
16203
  let parentTransform = "";
16199
- for (const attr of Array.from(parentText.attributes)) {
16204
+ const parentAttrs = Array.from(parentText.attributes).filter((attr) => {
16200
16205
  if (attr.name === "transform") {
16201
16206
  parentTransform = attr.value;
16202
- continue;
16207
+ return false;
16203
16208
  }
16204
- wrapper.setAttribute(attr.name, attr.value);
16205
- }
16206
- const combined = parentTransform ? `${parentTransform} ${transformVal}` : transformVal;
16207
- wrapper.setAttribute("transform", combined);
16208
- tspan.removeAttribute("transform");
16209
- wrapper.appendChild(tspan);
16210
- (_c = parentText.parentNode) == null ? void 0 : _c.insertBefore(wrapper, parentText.nextSibling);
16209
+ return true;
16210
+ });
16211
+ for (const tspan of directTspans) {
16212
+ const wrapper = doc.createElementNS(SVG_NS, "text");
16213
+ for (const attr of parentAttrs) wrapper.setAttribute(attr.name, attr.value);
16214
+ const runTransform = tspan.getAttribute("transform") || "";
16215
+ const combined = [parentTransform, runTransform].filter(Boolean).join(" ");
16216
+ if (combined) wrapper.setAttribute("transform", combined);
16217
+ tspan.removeAttribute("transform");
16218
+ wrapper.appendChild(tspan);
16219
+ parentText.parentNode.insertBefore(wrapper, parentText);
16220
+ }
16221
+ parentText.parentNode.removeChild(parentText);
16211
16222
  }
16212
16223
  return new XMLSerializer().serializeToString(doc.documentElement);
16213
16224
  }