@pixldocs/canvas-renderer 0.5.153 → 0.5.155

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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-Bp0cz5Mq.cjs");
3
+ const index = require("./index-BwHwQrnS.cjs");
4
4
  exports.DEPLOYMENT_VERSION_MARKER = index.DEPLOYMENT_VERSION_MARKER;
5
5
  exports.FONT_FALLBACK_DEVANAGARI = index.FONT_FALLBACK_DEVANAGARI;
6
6
  exports.FONT_FALLBACK_MATH = index.FONT_FALLBACK_MATH;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { D, F, o, q, s, P, t, u, v, w, x, y, z, B, C, E, G, H, I, J, K, L, b, M, N, O, Q, R, S, U, V, W, X, Y, Z, _ } from "./index-CAH9akzI.js";
1
+ import { D, F, o, q, s, P, t, u, v, w, x, y, z, B, C, E, G, H, I, J, K, L, b, M, N, O, Q, R, S, U, V, W, X, Y, Z, _ } from "./index-BQA8_wgq.js";
2
2
  export {
3
3
  D as DEPLOYMENT_VERSION_MARKER,
4
4
  F as FONT_FALLBACK_DEVANAGARI,
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jspdf = require("jspdf");
4
4
  const svg2pdf_js = require("svg2pdf.js");
5
5
  const fabric = require("fabric");
6
- const index = require("./index-Bp0cz5Mq.cjs");
6
+ const index = require("./index-BwHwQrnS.cjs");
7
7
  const pdfFonts = require("./pdfFonts-BTEVnYX8.cjs");
8
8
  function _interopNamespaceDefault(e) {
9
9
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -1327,6 +1327,51 @@ async function bakeTextAnchorPositionsFromLiveSvg(svg) {
1327
1327
  }
1328
1328
  }
1329
1329
  }
1330
+ function promoteFabricLineAnchorsToSelectableText(svg) {
1331
+ const doc = svg.ownerDocument;
1332
+ if (!doc) return;
1333
+ const lineTspans = Array.from(svg.querySelectorAll('tspan[data-pd-line-anchor="1"]'));
1334
+ if (lineTspans.length === 0) return;
1335
+ const SVG_NS = "http://www.w3.org/2000/svg";
1336
+ const touchedParents = /* @__PURE__ */ new Set();
1337
+ let promoted = 0;
1338
+ for (const tspan of lineTspans) {
1339
+ const parentText = tspan.parentElement;
1340
+ if (!parentText || parentText.tagName.toLowerCase() !== "text" || !parentText.parentNode) continue;
1341
+ const rawWidth = Number.parseFloat(tspan.getAttribute("data-pd-line-width") || "");
1342
+ const rawX = Number.parseFloat(tspan.getAttribute("x") || parentText.getAttribute("x") || "");
1343
+ if (!Number.isFinite(rawWidth) || rawWidth <= 0 || !Number.isFinite(rawX)) continue;
1344
+ const anchor = (tspan.getAttribute("text-anchor") || "start").trim().toLowerCase();
1345
+ if (anchor !== "middle" && anchor !== "end") continue;
1346
+ const startX = anchor === "end" ? rawX - rawWidth : anchor === "middle" ? rawX - rawWidth / 2 : rawX;
1347
+ const y = tspan.getAttribute("y") || parentText.getAttribute("y") || "0";
1348
+ const wrapper = doc.createElementNS(SVG_NS, "text");
1349
+ for (const attr of Array.from(parentText.attributes)) {
1350
+ if (["x", "y", "dx", "dy", "text-anchor", "textLength", "lengthAdjust"].includes(attr.name)) continue;
1351
+ wrapper.setAttribute(attr.name, attr.value);
1352
+ }
1353
+ for (const attr of Array.from(tspan.attributes)) {
1354
+ if (["x", "y", "dx", "dy", "text-anchor", "data-pd-line-anchor", "data-pd-line-width", "textLength", "lengthAdjust"].includes(attr.name)) continue;
1355
+ wrapper.setAttribute(attr.name, attr.value);
1356
+ }
1357
+ wrapper.setAttribute("x", startX.toFixed(3));
1358
+ wrapper.setAttribute("y", y);
1359
+ wrapper.setAttribute("text-anchor", "start");
1360
+ wrapper.setAttribute("textLength", rawWidth.toFixed(3));
1361
+ wrapper.setAttribute("lengthAdjust", "spacing");
1362
+ wrapper.textContent = tspan.textContent || "";
1363
+ parentText.parentNode.insertBefore(wrapper, parentText);
1364
+ tspan.remove();
1365
+ touchedParents.add(parentText);
1366
+ promoted++;
1367
+ }
1368
+ for (const parentText of touchedParents) {
1369
+ if (!parentText.parentNode) continue;
1370
+ const hasText = Array.from(parentText.childNodes).some((node) => (node.textContent || "").trim().length > 0);
1371
+ if (!hasText) parentText.parentNode.removeChild(parentText);
1372
+ }
1373
+ if (promoted > 0) console.log(`[Vector PDF][parity] promoted ${promoted} Fabric line anchor(s) to selectable fixed-width text`);
1374
+ }
1330
1375
  async function logTextMeasurementDiagnostic(svg) {
1331
1376
  var _a, _b, _c, _d, _e;
1332
1377
  if (typeof window === "undefined" || typeof document === "undefined") return;
@@ -1855,7 +1900,7 @@ async function collectInlinedFontFaceCss() {
1855
1900
  return cachedInlinedFontFaceCss;
1856
1901
  }
1857
1902
  async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey, options) {
1858
- var _a, _b;
1903
+ var _a;
1859
1904
  try {
1860
1905
  const parser = new DOMParser();
1861
1906
  const processedSvg = inlineNestedSvgImageDataUris(rawSvg, parser);
@@ -1893,27 +1938,11 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
1893
1938
  console.warn("[Vector PDF] anchor-bake pass failed (continuing):", e);
1894
1939
  }
1895
1940
  await rasterizeShadowMarkers(svgToDraw);
1896
- try {
1897
- if (svgToDraw.querySelector("g[data-pd-shadow-blur] text, g[data-pd-text-bg] text")) {
1898
- const { convertAllTextToPath } = await Promise.resolve().then(() => require("./svgTextToPath-IM1f6F-f.cjs"));
1899
- const outlined = await convertAllTextToPath(
1900
- new XMLSerializer().serializeToString(svgToDraw),
1901
- void 0,
1902
- { mode: "shadow-bound" }
1903
- );
1904
- const outlinedDoc = parser.parseFromString(outlined, "image/svg+xml");
1905
- if (!outlinedDoc.querySelector("parsererror") && ((_a = outlinedDoc.documentElement) == null ? void 0 : _a.tagName.toLowerCase()) === "svg") {
1906
- svgToDraw = outlinedDoc.documentElement;
1907
- console.log("[Vector PDF][parity] decorated text outlined for headless alignment");
1908
- }
1909
- }
1910
- } catch (outlineErr) {
1911
- console.warn("[Vector PDF] shadow-bound text outline failed (continuing):", outlineErr);
1912
- }
1941
+ promoteFabricLineAnchorsToSelectableText(svgToDraw);
1913
1942
  await convertTextDecorationsToLines(svgToDraw);
1914
1943
  const rewritten = rewriteSvgFontsForJsPDFWithSourceMeta(new XMLSerializer().serializeToString(svgToDraw));
1915
1944
  const rewrittenDoc = parser.parseFromString(rewritten, "image/svg+xml");
1916
- if (!rewrittenDoc.querySelector("parsererror") && ((_b = rewrittenDoc.documentElement) == null ? void 0 : _b.tagName.toLowerCase()) === "svg") {
1945
+ if (!rewrittenDoc.querySelector("parsererror") && ((_a = rewrittenDoc.documentElement) == null ? void 0 : _a.tagName.toLowerCase()) === "svg") {
1917
1946
  return rewrittenDoc.documentElement;
1918
1947
  }
1919
1948
  return svgToDraw;
@@ -2495,7 +2524,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
2495
2524
  async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
2496
2525
  if (!colorMap || Object.keys(colorMap).length === 0) return null;
2497
2526
  try {
2498
- const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-Bp0cz5Mq.cjs")).then((n) => n.canvasImageLoader);
2527
+ const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-BwHwQrnS.cjs")).then((n) => n.canvasImageLoader);
2499
2528
  return await getNormalizedSvgUrl(imageUrl, colorMap);
2500
2529
  } catch {
2501
2530
  return null;
@@ -3276,7 +3305,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
3276
3305
  }
3277
3306
  let fetchUrl = imageUrl;
3278
3307
  if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
3279
- const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-Bp0cz5Mq.cjs")).then((n) => n.canvasImageLoader);
3308
+ const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-BwHwQrnS.cjs")).then((n) => n.canvasImageLoader);
3280
3309
  if (isPrivateUrl(imageUrl)) return null;
3281
3310
  const proxyUrl = new URL(`${index.API_URL}/image-proxy`);
3282
3311
  proxyUrl.searchParams.set("url", imageUrl);
@@ -5257,5 +5286,6 @@ exports.exportFabricCanvasToVectorPdf = exportFabricCanvasToVectorPdf;
5257
5286
  exports.exportMultiPagePdf = exportMultiPagePdf;
5258
5287
  exports.logTextMeasurementDiagnostic = logTextMeasurementDiagnostic;
5259
5288
  exports.preparePagesForExport = preparePagesForExport;
5289
+ exports.promoteFabricLineAnchorsToSelectableText = promoteFabricLineAnchorsToSelectableText;
5260
5290
  exports.rewriteSvgFontsForJsPDFWithSourceMeta = rewriteSvgFontsForJsPDFWithSourceMeta;
5261
- //# sourceMappingURL=vectorPdfExport-YSo453Ul.cjs.map
5291
+ //# sourceMappingURL=vectorPdfExport-C5NmVmxB.cjs.map