@pixldocs/canvas-renderer 0.5.147 → 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-NMZJF9C9.js → index-Bpxp8eDf.js} +5 -5
- package/dist/{index-NMZJF9C9.js.map → index-Bpxp8eDf.js.map} +1 -1
- package/dist/{index-D78ekQx5.cjs → index-C6IaOn7u.cjs} +5 -5
- package/dist/{index-D78ekQx5.cjs.map → index-C6IaOn7u.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{vectorPdfExport-_m5TiQjK.js → vectorPdfExport-DkZDHKeR.js} +79 -7
- package/dist/vectorPdfExport-DkZDHKeR.js.map +1 -0
- package/dist/{vectorPdfExport-DmFmkPUr.cjs → vectorPdfExport-FwEcQIPB.cjs} +79 -7
- package/dist/vectorPdfExport-FwEcQIPB.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/vectorPdfExport-DmFmkPUr.cjs.map +0 -1
- package/dist/vectorPdfExport-_m5TiQjK.js.map +0 -1
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-
|
|
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-
|
|
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-
|
|
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;
|
|
@@ -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"));
|
|
@@ -1196,9 +1234,37 @@ async function bakeTextAnchorPositionsFromLiveSvg(svg) {
|
|
|
1196
1234
|
if (cleaned) node.setAttribute("style", cleaned);
|
|
1197
1235
|
else node.removeAttribute("style");
|
|
1198
1236
|
};
|
|
1199
|
-
const
|
|
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) => {
|
|
1200
1250
|
const anchor = (anchorOverride || _resolveAnchor(srcNode)).trim().toLowerCase();
|
|
1201
1251
|
if (anchor !== "middle" && anchor !== "end") return;
|
|
1252
|
+
try {
|
|
1253
|
+
const content = srcNode.textContent || "";
|
|
1254
|
+
if (content.length > 0) {
|
|
1255
|
+
const width = _measureWidthCanvas(srcNode, content);
|
|
1256
|
+
const refX = Number.isFinite(refXOverride) ? refXOverride : readInheritedX(srcNode);
|
|
1257
|
+
if (width !== null && Number.isFinite(refX)) {
|
|
1258
|
+
const newX = anchor === "middle" ? refX - width / 2 : refX - width;
|
|
1259
|
+
srcNode.setAttribute("x", String(newX));
|
|
1260
|
+
srcNode.setAttribute("text-anchor", "start");
|
|
1261
|
+
stripTextAnchorStyle(srcNode);
|
|
1262
|
+
baked++;
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
} catch {
|
|
1267
|
+
}
|
|
1202
1268
|
try {
|
|
1203
1269
|
const n = typeof liveNode.getNumberOfChars === "function" ? liveNode.getNumberOfChars() : 0;
|
|
1204
1270
|
if (!n) return;
|
|
@@ -1214,9 +1280,15 @@ async function bakeTextAnchorPositionsFromLiveSvg(svg) {
|
|
|
1214
1280
|
if (srcTspans.length > 0) {
|
|
1215
1281
|
const parentAnchor = _resolveAnchor(srcText);
|
|
1216
1282
|
const tspanAnchors = srcTspans.map((tspan) => _resolveAnchor(tspan));
|
|
1217
|
-
|
|
1283
|
+
const parentRefX = readInheritedX(srcText);
|
|
1284
|
+
const tspanRefXs = srcTspans.map((tspan) => readInheritedX(tspan));
|
|
1218
1285
|
for (let j = 0; j < srcTspans.length; j++) {
|
|
1219
|
-
|
|
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);
|
|
1220
1292
|
}
|
|
1221
1293
|
} else {
|
|
1222
1294
|
bakeNode(srcText, liveText);
|
|
@@ -2386,7 +2458,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
|
|
|
2386
2458
|
async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
|
|
2387
2459
|
if (!colorMap || Object.keys(colorMap).length === 0) return null;
|
|
2388
2460
|
try {
|
|
2389
|
-
const { getNormalizedSvgUrl } = await import("./index-
|
|
2461
|
+
const { getNormalizedSvgUrl } = await import("./index-Bpxp8eDf.js").then((n) => n.$);
|
|
2390
2462
|
return await getNormalizedSvgUrl(imageUrl, colorMap);
|
|
2391
2463
|
} catch {
|
|
2392
2464
|
return null;
|
|
@@ -3167,7 +3239,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
|
|
|
3167
3239
|
}
|
|
3168
3240
|
let fetchUrl = imageUrl;
|
|
3169
3241
|
if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
|
|
3170
|
-
const { isPrivateUrl } = await import("./index-
|
|
3242
|
+
const { isPrivateUrl } = await import("./index-Bpxp8eDf.js").then((n) => n.$);
|
|
3171
3243
|
if (isPrivateUrl(imageUrl)) return null;
|
|
3172
3244
|
const proxyUrl = new URL(`${API_URL}/image-proxy`);
|
|
3173
3245
|
proxyUrl.searchParams.set("url", imageUrl);
|
|
@@ -5151,4 +5223,4 @@ export {
|
|
|
5151
5223
|
preparePagesForExport,
|
|
5152
5224
|
rewriteSvgFontsForJsPDFWithSourceMeta
|
|
5153
5225
|
};
|
|
5154
|
-
//# sourceMappingURL=vectorPdfExport-
|
|
5226
|
+
//# sourceMappingURL=vectorPdfExport-DkZDHKeR.js.map
|