@pixldocs/canvas-renderer 0.5.143 → 0.5.145

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-r5VzSOHa.cjs");
3
+ const index = require("./index-DVjmPr0D.cjs");
4
4
  exports.FONT_FALLBACK_DEVANAGARI = index.FONT_FALLBACK_DEVANAGARI;
5
5
  exports.FONT_FALLBACK_MATH = index.FONT_FALLBACK_MATH;
6
6
  exports.FONT_FALLBACK_SYMBOLS = index.FONT_FALLBACK_SYMBOLS;
package/dist/index.d.ts CHANGED
@@ -259,7 +259,7 @@ export declare function normalizeFontFamily(fontStack: string): string;
259
259
  * Package version banner. Bump alongside package.json so we can confirm
260
260
  * (via browser:log) that the deployed bundle matches the expected build.
261
261
  */
262
- export declare const PACKAGE_VERSION = "0.5.143";
262
+ export declare const PACKAGE_VERSION = "0.5.145";
263
263
 
264
264
  export declare interface PageSettings {
265
265
  backgroundColor?: string;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { F, o, q, s, P, t, u, v, w, x, y, z, B, C, D, E, G, H, I, J, K, b, L, M, N, O, Q, R, S, U, V, W, X, Y, Z } from "./index-CUpy7HO9.js";
1
+ import { F, o, q, s, P, t, u, v, w, x, y, z, B, C, D, E, G, H, I, J, K, b, L, M, N, O, Q, R, S, U, V, W, X, Y, Z } from "./index-Br7Pk6Ol.js";
2
2
  export {
3
3
  F as FONT_FALLBACK_DEVANAGARI,
4
4
  o as FONT_FALLBACK_MATH,
@@ -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-CUpy7HO9.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-Br7Pk6Ol.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;
@@ -1208,6 +1208,105 @@ async function bakeTextAnchorPositionsFromLiveSvg(svg) {
1208
1208
  }
1209
1209
  }
1210
1210
  }
1211
+ async function logTextMeasurementDiagnostic(svg) {
1212
+ var _a, _b, _c, _d, _e;
1213
+ if (typeof window === "undefined" || typeof document === "undefined") return;
1214
+ try {
1215
+ const params = new URLSearchParams(((_a = window.location) == null ? void 0 : _a.search) || "");
1216
+ if (params.get("pdfdiag") !== "1") return;
1217
+ } catch {
1218
+ return;
1219
+ }
1220
+ if (!svg) return;
1221
+ const tempContainer = document.createElement("div");
1222
+ tempContainer.style.cssText = "position:fixed;left:-9999px;top:-9999px;visibility:hidden;pointer-events:none;";
1223
+ const clone = svg.cloneNode(true);
1224
+ for (const tn of clone.querySelectorAll("text, tspan, textPath")) {
1225
+ const sf = tn.getAttribute("data-source-font-family");
1226
+ const sw = tn.getAttribute("data-source-font-weight");
1227
+ const ss = tn.getAttribute("data-source-font-style");
1228
+ if (sf) tn.setAttribute("font-family", sf);
1229
+ if (sw) tn.setAttribute("font-weight", sw);
1230
+ if (ss) tn.setAttribute("font-style", ss);
1231
+ }
1232
+ tempContainer.appendChild(clone);
1233
+ document.body.appendChild(tempContainer);
1234
+ const measureCanvas = document.createElement("canvas");
1235
+ const mctx = measureCanvas.getContext("2d");
1236
+ try {
1237
+ const liveTexts = Array.from(clone.querySelectorAll("text"));
1238
+ const srcTexts = Array.from(svg.querySelectorAll("text"));
1239
+ const rows = [];
1240
+ for (let i = 0; i < liveTexts.length; i++) {
1241
+ const live = liveTexts[i];
1242
+ const src = srcTexts[i];
1243
+ if (!live || !src) continue;
1244
+ const liveTspans = Array.from(live.querySelectorAll("tspan"));
1245
+ const srcTspans = Array.from(src.querySelectorAll("tspan"));
1246
+ const tspans = liveTspans.length ? liveTspans : [live];
1247
+ const srcs = srcTspans.length ? srcTspans : [src];
1248
+ for (let j = 0; j < tspans.length; j++) {
1249
+ const ln = tspans[j];
1250
+ const sn = srcs[j];
1251
+ const text = ln.textContent || "";
1252
+ const fam = (ln.getAttribute("font-family") || "").replace(/['"]/g, "").trim();
1253
+ const wt = ln.getAttribute("font-weight") || "400";
1254
+ const sty = ln.getAttribute("font-style") || "normal";
1255
+ const sz = parseFloat(ln.getAttribute("font-size") || src.getAttribute("font-size") || "16") || 16;
1256
+ let domX = null;
1257
+ let bboxW = null;
1258
+ try {
1259
+ if (ln.getNumberOfChars && ln.getNumberOfChars() > 0) {
1260
+ domX = ln.getStartPositionOfChar(0).x;
1261
+ }
1262
+ } catch {
1263
+ }
1264
+ try {
1265
+ bboxW = ((_b = ln.getBBox) == null ? void 0 : _b.call(ln).width) ?? null;
1266
+ } catch {
1267
+ }
1268
+ let canvasW = null;
1269
+ if (mctx) {
1270
+ mctx.font = `${sty} ${wt} ${sz}px "${fam}"`;
1271
+ try {
1272
+ canvasW = mctx.measureText(text).width;
1273
+ } catch {
1274
+ }
1275
+ }
1276
+ rows.push({
1277
+ line: text.length > 40 ? text.slice(0, 37) + "..." : text,
1278
+ font: `${fam} ${wt} ${sty}`,
1279
+ size: sz,
1280
+ srcAnchor: sn.getAttribute("text-anchor") || ((_c = sn.parentElement) == null ? void 0 : _c.getAttribute("text-anchor")) || "",
1281
+ srcX: sn.getAttribute("x") || ((_d = sn.parentElement) == null ? void 0 : _d.getAttribute("x")) || "",
1282
+ domX: domX !== null ? +domX.toFixed(2) : null,
1283
+ bboxW: bboxW !== null ? +bboxW.toFixed(2) : null,
1284
+ measureCtxW: canvasW !== null ? +canvasW.toFixed(2) : null
1285
+ });
1286
+ }
1287
+ }
1288
+ if (rows.length > 0) {
1289
+ console.log("[PDF-DIAG] ===== text measurement diagnostic =====");
1290
+ console.log(
1291
+ "[PDF-DIAG] env=",
1292
+ typeof navigator !== "undefined" ? navigator.userAgent.slice(0, 80) : "n/a",
1293
+ "dpr=",
1294
+ window.devicePixelRatio,
1295
+ "fontsReady=",
1296
+ !!((_e = document.fonts) == null ? void 0 : _e.ready)
1297
+ );
1298
+ for (const r of rows) {
1299
+ console.log("[PDF-DIAG]", JSON.stringify(r));
1300
+ }
1301
+ console.log("[PDF-DIAG] ===== end =====");
1302
+ }
1303
+ } finally {
1304
+ try {
1305
+ document.body.removeChild(tempContainer);
1306
+ } catch {
1307
+ }
1308
+ }
1309
+ }
1211
1310
  async function _convertTextDecorationsToLines_impl(svg) {
1212
1311
  const doc = svg.ownerDocument;
1213
1312
  if (!doc) return;
@@ -1658,6 +1757,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
1658
1757
  }
1659
1758
  sanitizeSvgTreeForPdf(svgToDraw);
1660
1759
  try {
1760
+ await logTextMeasurementDiagnostic(svgToDraw);
1661
1761
  await bakeTextAnchorPositionsFromLiveSvg(svgToDraw);
1662
1762
  } catch (e) {
1663
1763
  console.warn("[Vector PDF] anchor-bake pass failed (continuing):", e);
@@ -2248,7 +2348,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
2248
2348
  async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
2249
2349
  if (!colorMap || Object.keys(colorMap).length === 0) return null;
2250
2350
  try {
2251
- const { getNormalizedSvgUrl } = await import("./index-CUpy7HO9.js").then((n) => n._);
2351
+ const { getNormalizedSvgUrl } = await import("./index-Br7Pk6Ol.js").then((n) => n._);
2252
2352
  return await getNormalizedSvgUrl(imageUrl, colorMap);
2253
2353
  } catch {
2254
2354
  return null;
@@ -3029,7 +3129,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
3029
3129
  }
3030
3130
  let fetchUrl = imageUrl;
3031
3131
  if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
3032
- const { isPrivateUrl } = await import("./index-CUpy7HO9.js").then((n) => n._);
3132
+ const { isPrivateUrl } = await import("./index-Br7Pk6Ol.js").then((n) => n._);
3033
3133
  if (isPrivateUrl(imageUrl)) return null;
3034
3134
  const proxyUrl = new URL(`${API_URL}/image-proxy`);
3035
3135
  proxyUrl.searchParams.set("url", imageUrl);
@@ -5009,7 +5109,8 @@ export {
5009
5109
  embedFontsForSvg,
5010
5110
  exportFabricCanvasToVectorPdf,
5011
5111
  exportMultiPagePdf,
5112
+ logTextMeasurementDiagnostic,
5012
5113
  preparePagesForExport,
5013
5114
  rewriteSvgFontsForJsPDFWithSourceMeta
5014
5115
  };
5015
- //# sourceMappingURL=vectorPdfExport-GvaizFte.js.map
5116
+ //# sourceMappingURL=vectorPdfExport-B63qQqDW.js.map