@pixldocs/canvas-renderer 0.5.148 → 0.5.149

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-Bt1m9Esp.cjs");
3
+ const index = require("./index-C6IaOn7u.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-BkhtOI5W.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-Bpxp8eDf.js";
2
2
  export {
3
3
  D as DEPLOYMENT_VERSION_MARKER,
4
4
  F as FONT_FALLBACK_DEVANAGARI,
@@ -1,7 +1,7 @@
1
1
  import { jsPDF, ShadingPattern } from "jspdf";
2
2
  import { svg2pdf } from "svg2pdf.js";
3
3
  import * as fabric from "fabric";
4
- import { g as getCanvasForPage, c as captureFabricCanvasSvgForPdf, f as findNodeById, a as getAbsoluteBounds, p as parseTextMarkdown, r as renderSmartElementToSvg, n as normalizeShapeType, h as hasEdgeFade, b as getProxiedImageUrl, d as bakeEdgeFade, i as isElement, e as isGroup, j as buildRoundedTrianglePath, A as API_URL, k as getImageProxyFetchOptions, l as getRoundedRectRadii, T as TRIANGLE_STROKE_MITER_LIMIT, m as getTrianglePoints } from "./index-BkhtOI5W.js";
4
+ import { g as getCanvasForPage, c as captureFabricCanvasSvgForPdf, f as findNodeById, a as getAbsoluteBounds, p as parseTextMarkdown, r as renderSmartElementToSvg, n as normalizeShapeType, h as hasEdgeFade, b as getProxiedImageUrl, d as bakeEdgeFade, i as isElement, e as isGroup, j as buildRoundedTrianglePath, A as API_URL, k as getImageProxyFetchOptions, l as getRoundedRectRadii, T as TRIANGLE_STROKE_MITER_LIMIT, m as getTrianglePoints } from "./index-Bpxp8eDf.js";
5
5
  import { resetPdfFontRegistry, FONT_FALLBACK_SYMBOLS, FONT_FALLBACK_MATH, FONT_FALLBACK_DEVANAGARI, embedFontWithGoogleFallback, getEmbeddedVariantsList, isFontAvailable, isFamilyEmbedded, resolveBestRegisteredVariant, getEmbeddedJsPDFFontName, resolveFontWeight, doesVariantSupportChar } from "./pdfFonts-b3_bv7F0.js";
6
6
  async function embedFontsForSvg(pdf, svgStr) {
7
7
  var _a;
@@ -1234,24 +1234,26 @@ async function bakeTextAnchorPositionsFromLiveSvg(svg) {
1234
1234
  if (cleaned) node.setAttribute("style", cleaned);
1235
1235
  else node.removeAttribute("style");
1236
1236
  };
1237
- const bakeNode = (srcNode, liveNode, anchorOverride) => {
1237
+ const readInheritedX = (node) => {
1238
+ let cur = node;
1239
+ while (cur) {
1240
+ const v = cur.getAttribute("x");
1241
+ if (v) {
1242
+ const parsed = parseFloat(v.split(/[\s,]+/)[0]);
1243
+ return Number.isFinite(parsed) ? parsed : NaN;
1244
+ }
1245
+ cur = cur.parentElement;
1246
+ }
1247
+ return NaN;
1248
+ };
1249
+ const bakeNode = (srcNode, liveNode, anchorOverride, refXOverride) => {
1238
1250
  const anchor = (anchorOverride || _resolveAnchor(srcNode)).trim().toLowerCase();
1239
1251
  if (anchor !== "middle" && anchor !== "end") return;
1240
1252
  try {
1241
1253
  const content = srcNode.textContent || "";
1242
1254
  if (content.length > 0) {
1243
1255
  const width = _measureWidthCanvas(srcNode, content);
1244
- let refXAttr = null;
1245
- let cur = srcNode;
1246
- while (cur) {
1247
- const v = cur.getAttribute("x");
1248
- if (v) {
1249
- refXAttr = v;
1250
- break;
1251
- }
1252
- cur = cur.parentElement;
1253
- }
1254
- const refX = refXAttr !== null ? parseFloat(refXAttr.split(/[\s,]+/)[0]) : NaN;
1256
+ const refX = Number.isFinite(refXOverride) ? refXOverride : readInheritedX(srcNode);
1255
1257
  if (width !== null && Number.isFinite(refX)) {
1256
1258
  const newX = anchor === "middle" ? refX - width / 2 : refX - width;
1257
1259
  srcNode.setAttribute("x", String(newX));
@@ -1278,9 +1280,15 @@ async function bakeTextAnchorPositionsFromLiveSvg(svg) {
1278
1280
  if (srcTspans.length > 0) {
1279
1281
  const parentAnchor = _resolveAnchor(srcText);
1280
1282
  const tspanAnchors = srcTspans.map((tspan) => _resolveAnchor(tspan));
1281
- bakeNode(srcText, liveText, parentAnchor);
1283
+ const parentRefX = readInheritedX(srcText);
1284
+ const tspanRefXs = srcTspans.map((tspan) => readInheritedX(tspan));
1282
1285
  for (let j = 0; j < srcTspans.length; j++) {
1283
- if (liveTspans[j]) bakeNode(srcTspans[j], liveTspans[j], tspanAnchors[j]);
1286
+ const refX = Number.isFinite(tspanRefXs[j]) ? tspanRefXs[j] : parentRefX;
1287
+ if (liveTspans[j]) bakeNode(srcTspans[j], liveTspans[j], tspanAnchors[j] || parentAnchor, refX);
1288
+ }
1289
+ if (parentAnchor === "middle" || parentAnchor === "end") {
1290
+ srcText.setAttribute("text-anchor", "start");
1291
+ stripTextAnchorStyle(srcText);
1284
1292
  }
1285
1293
  } else {
1286
1294
  bakeNode(srcText, liveText);
@@ -2450,7 +2458,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
2450
2458
  async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
2451
2459
  if (!colorMap || Object.keys(colorMap).length === 0) return null;
2452
2460
  try {
2453
- const { getNormalizedSvgUrl } = await import("./index-BkhtOI5W.js").then((n) => n.$);
2461
+ const { getNormalizedSvgUrl } = await import("./index-Bpxp8eDf.js").then((n) => n.$);
2454
2462
  return await getNormalizedSvgUrl(imageUrl, colorMap);
2455
2463
  } catch {
2456
2464
  return null;
@@ -3231,7 +3239,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
3231
3239
  }
3232
3240
  let fetchUrl = imageUrl;
3233
3241
  if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
3234
- const { isPrivateUrl } = await import("./index-BkhtOI5W.js").then((n) => n.$);
3242
+ const { isPrivateUrl } = await import("./index-Bpxp8eDf.js").then((n) => n.$);
3235
3243
  if (isPrivateUrl(imageUrl)) return null;
3236
3244
  const proxyUrl = new URL(`${API_URL}/image-proxy`);
3237
3245
  proxyUrl.searchParams.set("url", imageUrl);
@@ -5215,4 +5223,4 @@ export {
5215
5223
  preparePagesForExport,
5216
5224
  rewriteSvgFontsForJsPDFWithSourceMeta
5217
5225
  };
5218
- //# sourceMappingURL=vectorPdfExport-BX2pT0Zn.js.map
5226
+ //# sourceMappingURL=vectorPdfExport-DkZDHKeR.js.map