@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-CUpy7HO9.js → index-Br7Pk6Ol.js} +10 -6
- package/dist/index-Br7Pk6Ol.js.map +1 -0
- package/dist/{index-r5VzSOHa.cjs → index-DVjmPr0D.cjs} +10 -6
- package/dist/index-DVjmPr0D.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{vectorPdfExport-GvaizFte.js → vectorPdfExport-B63qQqDW.js} +105 -4
- package/dist/vectorPdfExport-B63qQqDW.js.map +1 -0
- package/dist/{vectorPdfExport-JVEe_tSQ.cjs → vectorPdfExport-C9jFFq3k.cjs} +105 -4
- package/dist/vectorPdfExport-C9jFFq3k.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/index-CUpy7HO9.js.map +0 -1
- package/dist/index-r5VzSOHa.cjs.map +0 -1
- package/dist/vectorPdfExport-GvaizFte.js.map +0 -1
- package/dist/vectorPdfExport-JVEe_tSQ.cjs.map +0 -1
|
@@ -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-
|
|
6
|
+
const index = require("./index-DVjmPr0D.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" } });
|
|
@@ -1227,6 +1227,105 @@ async function bakeTextAnchorPositionsFromLiveSvg(svg) {
|
|
|
1227
1227
|
}
|
|
1228
1228
|
}
|
|
1229
1229
|
}
|
|
1230
|
+
async function logTextMeasurementDiagnostic(svg) {
|
|
1231
|
+
var _a, _b, _c, _d, _e;
|
|
1232
|
+
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
1233
|
+
try {
|
|
1234
|
+
const params = new URLSearchParams(((_a = window.location) == null ? void 0 : _a.search) || "");
|
|
1235
|
+
if (params.get("pdfdiag") !== "1") return;
|
|
1236
|
+
} catch {
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
if (!svg) return;
|
|
1240
|
+
const tempContainer = document.createElement("div");
|
|
1241
|
+
tempContainer.style.cssText = "position:fixed;left:-9999px;top:-9999px;visibility:hidden;pointer-events:none;";
|
|
1242
|
+
const clone = svg.cloneNode(true);
|
|
1243
|
+
for (const tn of clone.querySelectorAll("text, tspan, textPath")) {
|
|
1244
|
+
const sf = tn.getAttribute("data-source-font-family");
|
|
1245
|
+
const sw = tn.getAttribute("data-source-font-weight");
|
|
1246
|
+
const ss = tn.getAttribute("data-source-font-style");
|
|
1247
|
+
if (sf) tn.setAttribute("font-family", sf);
|
|
1248
|
+
if (sw) tn.setAttribute("font-weight", sw);
|
|
1249
|
+
if (ss) tn.setAttribute("font-style", ss);
|
|
1250
|
+
}
|
|
1251
|
+
tempContainer.appendChild(clone);
|
|
1252
|
+
document.body.appendChild(tempContainer);
|
|
1253
|
+
const measureCanvas = document.createElement("canvas");
|
|
1254
|
+
const mctx = measureCanvas.getContext("2d");
|
|
1255
|
+
try {
|
|
1256
|
+
const liveTexts = Array.from(clone.querySelectorAll("text"));
|
|
1257
|
+
const srcTexts = Array.from(svg.querySelectorAll("text"));
|
|
1258
|
+
const rows = [];
|
|
1259
|
+
for (let i = 0; i < liveTexts.length; i++) {
|
|
1260
|
+
const live = liveTexts[i];
|
|
1261
|
+
const src = srcTexts[i];
|
|
1262
|
+
if (!live || !src) continue;
|
|
1263
|
+
const liveTspans = Array.from(live.querySelectorAll("tspan"));
|
|
1264
|
+
const srcTspans = Array.from(src.querySelectorAll("tspan"));
|
|
1265
|
+
const tspans = liveTspans.length ? liveTspans : [live];
|
|
1266
|
+
const srcs = srcTspans.length ? srcTspans : [src];
|
|
1267
|
+
for (let j = 0; j < tspans.length; j++) {
|
|
1268
|
+
const ln = tspans[j];
|
|
1269
|
+
const sn = srcs[j];
|
|
1270
|
+
const text = ln.textContent || "";
|
|
1271
|
+
const fam = (ln.getAttribute("font-family") || "").replace(/['"]/g, "").trim();
|
|
1272
|
+
const wt = ln.getAttribute("font-weight") || "400";
|
|
1273
|
+
const sty = ln.getAttribute("font-style") || "normal";
|
|
1274
|
+
const sz = parseFloat(ln.getAttribute("font-size") || src.getAttribute("font-size") || "16") || 16;
|
|
1275
|
+
let domX = null;
|
|
1276
|
+
let bboxW = null;
|
|
1277
|
+
try {
|
|
1278
|
+
if (ln.getNumberOfChars && ln.getNumberOfChars() > 0) {
|
|
1279
|
+
domX = ln.getStartPositionOfChar(0).x;
|
|
1280
|
+
}
|
|
1281
|
+
} catch {
|
|
1282
|
+
}
|
|
1283
|
+
try {
|
|
1284
|
+
bboxW = ((_b = ln.getBBox) == null ? void 0 : _b.call(ln).width) ?? null;
|
|
1285
|
+
} catch {
|
|
1286
|
+
}
|
|
1287
|
+
let canvasW = null;
|
|
1288
|
+
if (mctx) {
|
|
1289
|
+
mctx.font = `${sty} ${wt} ${sz}px "${fam}"`;
|
|
1290
|
+
try {
|
|
1291
|
+
canvasW = mctx.measureText(text).width;
|
|
1292
|
+
} catch {
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
rows.push({
|
|
1296
|
+
line: text.length > 40 ? text.slice(0, 37) + "..." : text,
|
|
1297
|
+
font: `${fam} ${wt} ${sty}`,
|
|
1298
|
+
size: sz,
|
|
1299
|
+
srcAnchor: sn.getAttribute("text-anchor") || ((_c = sn.parentElement) == null ? void 0 : _c.getAttribute("text-anchor")) || "",
|
|
1300
|
+
srcX: sn.getAttribute("x") || ((_d = sn.parentElement) == null ? void 0 : _d.getAttribute("x")) || "",
|
|
1301
|
+
domX: domX !== null ? +domX.toFixed(2) : null,
|
|
1302
|
+
bboxW: bboxW !== null ? +bboxW.toFixed(2) : null,
|
|
1303
|
+
measureCtxW: canvasW !== null ? +canvasW.toFixed(2) : null
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
if (rows.length > 0) {
|
|
1308
|
+
console.log("[PDF-DIAG] ===== text measurement diagnostic =====");
|
|
1309
|
+
console.log(
|
|
1310
|
+
"[PDF-DIAG] env=",
|
|
1311
|
+
typeof navigator !== "undefined" ? navigator.userAgent.slice(0, 80) : "n/a",
|
|
1312
|
+
"dpr=",
|
|
1313
|
+
window.devicePixelRatio,
|
|
1314
|
+
"fontsReady=",
|
|
1315
|
+
!!((_e = document.fonts) == null ? void 0 : _e.ready)
|
|
1316
|
+
);
|
|
1317
|
+
for (const r of rows) {
|
|
1318
|
+
console.log("[PDF-DIAG]", JSON.stringify(r));
|
|
1319
|
+
}
|
|
1320
|
+
console.log("[PDF-DIAG] ===== end =====");
|
|
1321
|
+
}
|
|
1322
|
+
} finally {
|
|
1323
|
+
try {
|
|
1324
|
+
document.body.removeChild(tempContainer);
|
|
1325
|
+
} catch {
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1230
1329
|
async function _convertTextDecorationsToLines_impl(svg) {
|
|
1231
1330
|
const doc = svg.ownerDocument;
|
|
1232
1331
|
if (!doc) return;
|
|
@@ -1677,6 +1776,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
|
|
|
1677
1776
|
}
|
|
1678
1777
|
sanitizeSvgTreeForPdf(svgToDraw);
|
|
1679
1778
|
try {
|
|
1779
|
+
await logTextMeasurementDiagnostic(svgToDraw);
|
|
1680
1780
|
await bakeTextAnchorPositionsFromLiveSvg(svgToDraw);
|
|
1681
1781
|
} catch (e) {
|
|
1682
1782
|
console.warn("[Vector PDF] anchor-bake pass failed (continuing):", e);
|
|
@@ -2267,7 +2367,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
|
|
|
2267
2367
|
async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
|
|
2268
2368
|
if (!colorMap || Object.keys(colorMap).length === 0) return null;
|
|
2269
2369
|
try {
|
|
2270
|
-
const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-
|
|
2370
|
+
const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-DVjmPr0D.cjs")).then((n) => n.canvasImageLoader);
|
|
2271
2371
|
return await getNormalizedSvgUrl(imageUrl, colorMap);
|
|
2272
2372
|
} catch {
|
|
2273
2373
|
return null;
|
|
@@ -3048,7 +3148,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
|
|
|
3048
3148
|
}
|
|
3049
3149
|
let fetchUrl = imageUrl;
|
|
3050
3150
|
if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
|
|
3051
|
-
const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-
|
|
3151
|
+
const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-DVjmPr0D.cjs")).then((n) => n.canvasImageLoader);
|
|
3052
3152
|
if (isPrivateUrl(imageUrl)) return null;
|
|
3053
3153
|
const proxyUrl = new URL(`${index.API_URL}/image-proxy`);
|
|
3054
3154
|
proxyUrl.searchParams.set("url", imageUrl);
|
|
@@ -5027,6 +5127,7 @@ exports.drawPreparedLiveCanvasSvgPageToPdf = drawPreparedLiveCanvasSvgPageToPdf;
|
|
|
5027
5127
|
exports.embedFontsForSvg = embedFontsForSvg;
|
|
5028
5128
|
exports.exportFabricCanvasToVectorPdf = exportFabricCanvasToVectorPdf;
|
|
5029
5129
|
exports.exportMultiPagePdf = exportMultiPagePdf;
|
|
5130
|
+
exports.logTextMeasurementDiagnostic = logTextMeasurementDiagnostic;
|
|
5030
5131
|
exports.preparePagesForExport = preparePagesForExport;
|
|
5031
5132
|
exports.rewriteSvgFontsForJsPDFWithSourceMeta = rewriteSvgFontsForJsPDFWithSourceMeta;
|
|
5032
|
-
//# sourceMappingURL=vectorPdfExport-
|
|
5133
|
+
//# sourceMappingURL=vectorPdfExport-C9jFFq3k.cjs.map
|