@pixldocs/canvas-renderer 0.5.154 → 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-Cl1_1tTg.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-CoH2Xntr.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-Cl1_1tTg.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;
@@ -1893,6 +1938,7 @@ 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);
1941
+ promoteFabricLineAnchorsToSelectableText(svgToDraw);
1896
1942
  await convertTextDecorationsToLines(svgToDraw);
1897
1943
  const rewritten = rewriteSvgFontsForJsPDFWithSourceMeta(new XMLSerializer().serializeToString(svgToDraw));
1898
1944
  const rewrittenDoc = parser.parseFromString(rewritten, "image/svg+xml");
@@ -2478,7 +2524,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
2478
2524
  async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
2479
2525
  if (!colorMap || Object.keys(colorMap).length === 0) return null;
2480
2526
  try {
2481
- const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-Cl1_1tTg.cjs")).then((n) => n.canvasImageLoader);
2527
+ const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-BwHwQrnS.cjs")).then((n) => n.canvasImageLoader);
2482
2528
  return await getNormalizedSvgUrl(imageUrl, colorMap);
2483
2529
  } catch {
2484
2530
  return null;
@@ -3259,7 +3305,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
3259
3305
  }
3260
3306
  let fetchUrl = imageUrl;
3261
3307
  if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
3262
- const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-Cl1_1tTg.cjs")).then((n) => n.canvasImageLoader);
3308
+ const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-BwHwQrnS.cjs")).then((n) => n.canvasImageLoader);
3263
3309
  if (isPrivateUrl(imageUrl)) return null;
3264
3310
  const proxyUrl = new URL(`${index.API_URL}/image-proxy`);
3265
3311
  proxyUrl.searchParams.set("url", imageUrl);
@@ -5240,5 +5286,6 @@ exports.exportFabricCanvasToVectorPdf = exportFabricCanvasToVectorPdf;
5240
5286
  exports.exportMultiPagePdf = exportMultiPagePdf;
5241
5287
  exports.logTextMeasurementDiagnostic = logTextMeasurementDiagnostic;
5242
5288
  exports.preparePagesForExport = preparePagesForExport;
5289
+ exports.promoteFabricLineAnchorsToSelectableText = promoteFabricLineAnchorsToSelectableText;
5243
5290
  exports.rewriteSvgFontsForJsPDFWithSourceMeta = rewriteSvgFontsForJsPDFWithSourceMeta;
5244
- //# sourceMappingURL=vectorPdfExport-BHADcvGH.cjs.map
5291
+ //# sourceMappingURL=vectorPdfExport-C5NmVmxB.cjs.map