@pixldocs/canvas-renderer 0.5.60 → 0.5.62
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 +56 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +56 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/svgTextToPath-BP0Kppla.js +0 -1083
- package/dist/svgTextToPath-BP0Kppla.js.map +0 -1
- package/dist/svgTextToPath-BTHnqJpM.cjs +0 -1105
- package/dist/svgTextToPath-BTHnqJpM.cjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -254,7 +254,7 @@ export declare function normalizeFontFamily(fontStack: string): string;
|
|
|
254
254
|
* Package version banner. Bump alongside package.json so we can confirm
|
|
255
255
|
* (via browser:log) that the deployed bundle matches the expected build.
|
|
256
256
|
*/
|
|
257
|
-
export declare const PACKAGE_VERSION = "0.5.
|
|
257
|
+
export declare const PACKAGE_VERSION = "0.5.62";
|
|
258
258
|
|
|
259
259
|
export declare interface PageSettings {
|
|
260
260
|
backgroundColor?: string;
|
|
@@ -443,6 +443,7 @@ export declare class PixldocsRenderer {
|
|
|
443
443
|
* using the global __fabricCanvasRegistry (set by PageCanvas).
|
|
444
444
|
*/
|
|
445
445
|
private getFabricCanvasFromContainer;
|
|
446
|
+
private resyncTextMetricsForSvgExport;
|
|
446
447
|
private waitForStableTextMetrics;
|
|
447
448
|
}
|
|
448
449
|
|
package/dist/index.js
CHANGED
|
@@ -12542,7 +12542,7 @@ function PixldocsPreview(props) {
|
|
|
12542
12542
|
!canvasSettled && /* @__PURE__ */ jsx("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) })
|
|
12543
12543
|
] });
|
|
12544
12544
|
}
|
|
12545
|
-
const PACKAGE_VERSION = "0.5.
|
|
12545
|
+
const PACKAGE_VERSION = "0.5.62";
|
|
12546
12546
|
let __underlineFixInstalled = false;
|
|
12547
12547
|
function installUnderlineFix(fab) {
|
|
12548
12548
|
var _a;
|
|
@@ -13303,6 +13303,7 @@ class PixldocsRenderer {
|
|
|
13303
13303
|
{ width: canvasWidth, height: canvasHeight },
|
|
13304
13304
|
{ cssOnly: false, backstoreOnly: false }
|
|
13305
13305
|
);
|
|
13306
|
+
this.resyncTextMetricsForSvgExport(fabricInstance);
|
|
13306
13307
|
const rawSvgString = fabricInstance.toSVG();
|
|
13307
13308
|
const svgString = this.normalizeSvgDimensions(
|
|
13308
13309
|
rawSvgString,
|
|
@@ -13413,6 +13414,59 @@ class PixldocsRenderer {
|
|
|
13413
13414
|
}
|
|
13414
13415
|
return null;
|
|
13415
13416
|
}
|
|
13417
|
+
resyncTextMetricsForSvgExport(fabricInstance) {
|
|
13418
|
+
if (typeof document === "undefined" || !(fabricInstance == null ? void 0 : fabricInstance.getObjects)) return;
|
|
13419
|
+
const ctx = document.createElement("canvas").getContext("2d");
|
|
13420
|
+
if (!ctx) return;
|
|
13421
|
+
const syncTextbox = (textbox) => {
|
|
13422
|
+
const tb = textbox;
|
|
13423
|
+
const rawLines = tb._textLines ?? textbox.textLines ?? [];
|
|
13424
|
+
if (!Array.isArray(rawLines) || rawLines.length === 0) return;
|
|
13425
|
+
const nextCharBounds = [];
|
|
13426
|
+
const nextLineWidths = [];
|
|
13427
|
+
rawLines.forEach((rawLine, lineIndex) => {
|
|
13428
|
+
const graphemes = Array.isArray(rawLine) ? rawLine.map((part) => String(part ?? "")) : Array.from(String(rawLine ?? ""));
|
|
13429
|
+
const bounds = [];
|
|
13430
|
+
let left = 0;
|
|
13431
|
+
graphemes.forEach((grapheme, charIndex) => {
|
|
13432
|
+
var _a, _b, _c, _d, _e, _f;
|
|
13433
|
+
const fontSize = Number(((_a = tb.getValueOfPropertyAt) == null ? void 0 : _a.call(tb, lineIndex, charIndex, "fontSize")) ?? textbox.fontSize ?? 16);
|
|
13434
|
+
const fontStyle = String(((_b = tb.getValueOfPropertyAt) == null ? void 0 : _b.call(tb, lineIndex, charIndex, "fontStyle")) ?? textbox.fontStyle ?? "normal");
|
|
13435
|
+
const fontWeight = String(((_c = tb.getValueOfPropertyAt) == null ? void 0 : _c.call(tb, lineIndex, charIndex, "fontWeight")) ?? textbox.fontWeight ?? "400");
|
|
13436
|
+
const fontFamily = String(((_d = tb.getValueOfPropertyAt) == null ? void 0 : _d.call(tb, lineIndex, charIndex, "fontFamily")) ?? textbox.fontFamily ?? "sans-serif");
|
|
13437
|
+
const charSpacing = Number(((_e = tb.getValueOfPropertyAt) == null ? void 0 : _e.call(tb, lineIndex, charIndex, "charSpacing")) ?? textbox.charSpacing ?? 0);
|
|
13438
|
+
const deltaY = Number(((_f = tb.getValueOfPropertyAt) == null ? void 0 : _f.call(tb, lineIndex, charIndex, "deltaY")) ?? 0);
|
|
13439
|
+
ctx.font = `${fontStyle} normal ${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
13440
|
+
const charWidth = Math.max(0, ctx.measureText(grapheme).width);
|
|
13441
|
+
let kernedWidth = charWidth;
|
|
13442
|
+
const previous = charIndex > 0 ? graphemes[charIndex - 1] : "";
|
|
13443
|
+
if (previous) {
|
|
13444
|
+
const pairWidth = ctx.measureText(previous + grapheme).width;
|
|
13445
|
+
const previousWidth = ctx.measureText(previous).width;
|
|
13446
|
+
if (Number.isFinite(pairWidth) && Number.isFinite(previousWidth)) {
|
|
13447
|
+
kernedWidth = Math.max(0, pairWidth - previousWidth);
|
|
13448
|
+
}
|
|
13449
|
+
}
|
|
13450
|
+
if (charIndex < graphemes.length - 1 && charSpacing) {
|
|
13451
|
+
kernedWidth += charSpacing / 1e3 * fontSize;
|
|
13452
|
+
}
|
|
13453
|
+
bounds[charIndex] = { left, width: charWidth, kernedWidth, height: fontSize, deltaY };
|
|
13454
|
+
left += kernedWidth;
|
|
13455
|
+
});
|
|
13456
|
+
bounds[graphemes.length] = { left, width: 0, kernedWidth: 0, height: Number(textbox.fontSize ?? 16), deltaY: 0 };
|
|
13457
|
+
nextCharBounds[lineIndex] = bounds;
|
|
13458
|
+
nextLineWidths[lineIndex] = Math.max(0, left);
|
|
13459
|
+
});
|
|
13460
|
+
tb.__charBounds = nextCharBounds;
|
|
13461
|
+
tb.__lineWidths = nextLineWidths;
|
|
13462
|
+
textbox.dirty = true;
|
|
13463
|
+
};
|
|
13464
|
+
const visit = (obj) => {
|
|
13465
|
+
if (obj instanceof fabric.Textbox) syncTextbox(obj);
|
|
13466
|
+
else if (obj instanceof fabric.Group) obj.getObjects().forEach(visit);
|
|
13467
|
+
};
|
|
13468
|
+
fabricInstance.getObjects().forEach(visit);
|
|
13469
|
+
}
|
|
13416
13470
|
async waitForStableTextMetrics(container, config) {
|
|
13417
13471
|
var _a, _b, _c;
|
|
13418
13472
|
if (typeof document !== "undefined") {
|
|
@@ -15575,13 +15629,7 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
|
|
|
15575
15629
|
const hasGradient = !!((_b = (_a = page.backgroundGradient) == null ? void 0 : _a.stops) == null ? void 0 : _b.length);
|
|
15576
15630
|
drawPageBackground(pdf, i, page.width, page.height, page.backgroundColor, page.backgroundGradient);
|
|
15577
15631
|
const shouldStripBg = stripPageBackground ?? hasGradient;
|
|
15578
|
-
|
|
15579
|
-
try {
|
|
15580
|
-
const mod = await import("./svgTextToPath-BP0Kppla.js");
|
|
15581
|
-
pageSvg = await mod.convertAllTextToPath(pageSvg, fontBaseUrl);
|
|
15582
|
-
} catch (outlineErr) {
|
|
15583
|
-
console.warn(`[canvas-renderer pdf] page ${i + 1}: text outliner unavailable, continuing with text-as-text`, outlineErr);
|
|
15584
|
-
}
|
|
15632
|
+
const pageSvg = page.svg;
|
|
15585
15633
|
let processedSvg = await prepareLiveCanvasSvgForPdf(pageSvg, page.width, page.height, `page-${i + 1}`, {
|
|
15586
15634
|
stripPageBackground: shouldStripBg
|
|
15587
15635
|
});
|