@pixldocs/canvas-renderer 0.5.147 → 0.5.148

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-D78ekQx5.cjs");
3
+ const index = require("./index-Bt1m9Esp.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-NMZJF9C9.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-BkhtOI5W.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-NMZJF9C9.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-BkhtOI5W.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;
@@ -1180,6 +1180,44 @@ async function bakeTextAnchorPositionsFromLiveSvg(svg) {
1180
1180
  tempContainer.appendChild(clone);
1181
1181
  document.body.appendChild(tempContainer);
1182
1182
  let baked = 0;
1183
+ const _measureCanvas = typeof document !== "undefined" ? document.createElement("canvas") : null;
1184
+ const _mctx = (_measureCanvas == null ? void 0 : _measureCanvas.getContext("2d")) || null;
1185
+ const _resolveFontSize = (node) => {
1186
+ let cur = node;
1187
+ while (cur) {
1188
+ const fs = cur.getAttribute("font-size");
1189
+ if (fs) {
1190
+ const n = parseFloat(fs);
1191
+ if (Number.isFinite(n) && n > 0) return n;
1192
+ }
1193
+ cur = cur.parentElement;
1194
+ }
1195
+ return 16;
1196
+ };
1197
+ const _resolveFontAttr = (node, attr, fallback) => {
1198
+ let cur = node;
1199
+ while (cur) {
1200
+ const v = cur.getAttribute(`data-source-${attr}`) || cur.getAttribute(attr);
1201
+ if (v) return v;
1202
+ cur = cur.parentElement;
1203
+ }
1204
+ return fallback;
1205
+ };
1206
+ const _measureWidthCanvas = (srcNode, content) => {
1207
+ if (!_mctx || !content) return null;
1208
+ const family = _resolveFontAttr(srcNode, "font-family", "").replace(/['"]/g, "").trim();
1209
+ const weight = _resolveFontAttr(srcNode, "font-weight", "400");
1210
+ const style = _resolveFontAttr(srcNode, "font-style", "normal");
1211
+ const size = _resolveFontSize(srcNode);
1212
+ if (!family) return null;
1213
+ try {
1214
+ _mctx.font = `${style} ${weight} ${size}px "${family}"`;
1215
+ const w = _mctx.measureText(content).width;
1216
+ return Number.isFinite(w) && w > 0 ? w : null;
1217
+ } catch {
1218
+ return null;
1219
+ }
1220
+ };
1183
1221
  try {
1184
1222
  const srcTexts = Array.from(svg.querySelectorAll("text"));
1185
1223
  const liveTexts = Array.from(clone.querySelectorAll("text"));
@@ -1199,6 +1237,32 @@ async function bakeTextAnchorPositionsFromLiveSvg(svg) {
1199
1237
  const bakeNode = (srcNode, liveNode, anchorOverride) => {
1200
1238
  const anchor = (anchorOverride || _resolveAnchor(srcNode)).trim().toLowerCase();
1201
1239
  if (anchor !== "middle" && anchor !== "end") return;
1240
+ try {
1241
+ const content = srcNode.textContent || "";
1242
+ if (content.length > 0) {
1243
+ 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;
1255
+ if (width !== null && Number.isFinite(refX)) {
1256
+ const newX = anchor === "middle" ? refX - width / 2 : refX - width;
1257
+ srcNode.setAttribute("x", String(newX));
1258
+ srcNode.setAttribute("text-anchor", "start");
1259
+ stripTextAnchorStyle(srcNode);
1260
+ baked++;
1261
+ return;
1262
+ }
1263
+ }
1264
+ } catch {
1265
+ }
1202
1266
  try {
1203
1267
  const n = typeof liveNode.getNumberOfChars === "function" ? liveNode.getNumberOfChars() : 0;
1204
1268
  if (!n) return;
@@ -2386,7 +2450,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
2386
2450
  async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
2387
2451
  if (!colorMap || Object.keys(colorMap).length === 0) return null;
2388
2452
  try {
2389
- const { getNormalizedSvgUrl } = await import("./index-NMZJF9C9.js").then((n) => n.$);
2453
+ const { getNormalizedSvgUrl } = await import("./index-BkhtOI5W.js").then((n) => n.$);
2390
2454
  return await getNormalizedSvgUrl(imageUrl, colorMap);
2391
2455
  } catch {
2392
2456
  return null;
@@ -3167,7 +3231,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
3167
3231
  }
3168
3232
  let fetchUrl = imageUrl;
3169
3233
  if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
3170
- const { isPrivateUrl } = await import("./index-NMZJF9C9.js").then((n) => n.$);
3234
+ const { isPrivateUrl } = await import("./index-BkhtOI5W.js").then((n) => n.$);
3171
3235
  if (isPrivateUrl(imageUrl)) return null;
3172
3236
  const proxyUrl = new URL(`${API_URL}/image-proxy`);
3173
3237
  proxyUrl.searchParams.set("url", imageUrl);
@@ -5151,4 +5215,4 @@ export {
5151
5215
  preparePagesForExport,
5152
5216
  rewriteSvgFontsForJsPDFWithSourceMeta
5153
5217
  };
5154
- //# sourceMappingURL=vectorPdfExport-_m5TiQjK.js.map
5218
+ //# sourceMappingURL=vectorPdfExport-BX2pT0Zn.js.map