@pixldocs/canvas-renderer 0.5.63 → 0.5.65
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 +25 -87
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +25 -87
- package/dist/index.js.map +1 -1
- package/package.json +1 -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.65";
|
|
258
258
|
|
|
259
259
|
export declare interface PageSettings {
|
|
260
260
|
backgroundColor?: string;
|
|
@@ -443,7 +443,6 @@ export declare class PixldocsRenderer {
|
|
|
443
443
|
* using the global __fabricCanvasRegistry (set by PageCanvas).
|
|
444
444
|
*/
|
|
445
445
|
private getFabricCanvasFromContainer;
|
|
446
|
-
private resyncTextMetricsForSvgExport;
|
|
447
446
|
private waitForStableTextMetrics;
|
|
448
447
|
}
|
|
449
448
|
|
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.65";
|
|
12546
12546
|
let __underlineFixInstalled = false;
|
|
12547
12547
|
function installUnderlineFix(fab) {
|
|
12548
12548
|
var _a;
|
|
@@ -13272,7 +13272,7 @@ class PixldocsRenderer {
|
|
|
13272
13272
|
}, 3e4);
|
|
13273
13273
|
let root = null;
|
|
13274
13274
|
let mountKey = 0;
|
|
13275
|
-
let
|
|
13275
|
+
let didPreviewParityRemount = false;
|
|
13276
13276
|
const cleanup = () => {
|
|
13277
13277
|
clearTimeout(timeout);
|
|
13278
13278
|
try {
|
|
@@ -13281,8 +13281,23 @@ class PixldocsRenderer {
|
|
|
13281
13281
|
}
|
|
13282
13282
|
container.remove();
|
|
13283
13283
|
};
|
|
13284
|
-
const
|
|
13285
|
-
|
|
13284
|
+
const mountPreview = (readyHandler) => {
|
|
13285
|
+
root = createRoot(container);
|
|
13286
|
+
root.render(
|
|
13287
|
+
createElement(PreviewCanvas2, {
|
|
13288
|
+
key: `svg-capture-${mountKey}`,
|
|
13289
|
+
config,
|
|
13290
|
+
pageIndex,
|
|
13291
|
+
zoom: 1,
|
|
13292
|
+
absoluteZoom: true,
|
|
13293
|
+
skipFontReadyWait: false,
|
|
13294
|
+
onReady: readyHandler
|
|
13295
|
+
})
|
|
13296
|
+
);
|
|
13297
|
+
};
|
|
13298
|
+
const remountForPreviewParity = async () => {
|
|
13299
|
+
if (didPreviewParityRemount) return;
|
|
13300
|
+
didPreviewParityRemount = true;
|
|
13286
13301
|
mountKey += 1;
|
|
13287
13302
|
try {
|
|
13288
13303
|
clearMeasurementCache();
|
|
@@ -13296,9 +13311,8 @@ class PixldocsRenderer {
|
|
|
13296
13311
|
root == null ? void 0 : root.unmount();
|
|
13297
13312
|
} catch {
|
|
13298
13313
|
}
|
|
13299
|
-
root = createRoot(container);
|
|
13300
13314
|
await new Promise((settle) => {
|
|
13301
|
-
|
|
13315
|
+
mountPreview(() => {
|
|
13302
13316
|
this.waitForCanvasScene(container, config, pageIndex).then(async () => {
|
|
13303
13317
|
const expectedImageCount = this.getExpectedImageCount(config, pageIndex);
|
|
13304
13318
|
await this.waitForCanvasImages(container, expectedImageCount);
|
|
@@ -13306,18 +13320,7 @@ class PixldocsRenderer {
|
|
|
13306
13320
|
await this.waitForCanvasScene(container, config, pageIndex);
|
|
13307
13321
|
settle();
|
|
13308
13322
|
}).catch(() => settle());
|
|
13309
|
-
};
|
|
13310
|
-
root.render(
|
|
13311
|
-
createElement(PreviewCanvas2, {
|
|
13312
|
-
key: `svg-auto-shrink-remount-${mountKey}`,
|
|
13313
|
-
config,
|
|
13314
|
-
pageIndex,
|
|
13315
|
-
zoom: 1,
|
|
13316
|
-
absoluteZoom: true,
|
|
13317
|
-
skipFontReadyWait: false,
|
|
13318
|
-
onReady: onReadyOnce
|
|
13319
|
-
})
|
|
13320
|
-
);
|
|
13323
|
+
});
|
|
13321
13324
|
});
|
|
13322
13325
|
};
|
|
13323
13326
|
const onReady = () => {
|
|
@@ -13328,9 +13331,9 @@ class PixldocsRenderer {
|
|
|
13328
13331
|
await this.waitForCanvasImages(container, expectedImageCount);
|
|
13329
13332
|
await this.waitForStableTextMetrics(container, config);
|
|
13330
13333
|
await this.waitForCanvasScene(container, config, pageIndex);
|
|
13331
|
-
if (hasAutoShrink && !
|
|
13332
|
-
console.log("[canvas-renderer][svg-parity] remounting
|
|
13333
|
-
await
|
|
13334
|
+
if (hasAutoShrink && !didPreviewParityRemount) {
|
|
13335
|
+
console.log("[canvas-renderer][svg-parity] remounting once to match PixldocsPreview auto-shrink stabilization");
|
|
13336
|
+
await remountForPreviewParity();
|
|
13334
13337
|
}
|
|
13335
13338
|
const fabricInstance = this.getFabricCanvasFromContainer(container);
|
|
13336
13339
|
if (!fabricInstance) {
|
|
@@ -13350,7 +13353,6 @@ class PixldocsRenderer {
|
|
|
13350
13353
|
{ width: canvasWidth, height: canvasHeight },
|
|
13351
13354
|
{ cssOnly: false, backstoreOnly: false }
|
|
13352
13355
|
);
|
|
13353
|
-
this.resyncTextMetricsForSvgExport(fabricInstance);
|
|
13354
13356
|
const rawSvgString = fabricInstance.toSVG();
|
|
13355
13357
|
const svgString = this.normalizeSvgDimensions(
|
|
13356
13358
|
rawSvgString,
|
|
@@ -13381,18 +13383,7 @@ class PixldocsRenderer {
|
|
|
13381
13383
|
}
|
|
13382
13384
|
});
|
|
13383
13385
|
};
|
|
13384
|
-
|
|
13385
|
-
root.render(
|
|
13386
|
-
createElement(PreviewCanvas2, {
|
|
13387
|
-
config,
|
|
13388
|
-
pageIndex,
|
|
13389
|
-
zoom: 1,
|
|
13390
|
-
// 1:1 — no UI scaling for SVG capture
|
|
13391
|
-
absoluteZoom: true,
|
|
13392
|
-
skipFontReadyWait: false,
|
|
13393
|
-
onReady
|
|
13394
|
-
})
|
|
13395
|
-
);
|
|
13386
|
+
mountPreview(onReady);
|
|
13396
13387
|
});
|
|
13397
13388
|
}
|
|
13398
13389
|
/**
|
|
@@ -13461,59 +13452,6 @@ class PixldocsRenderer {
|
|
|
13461
13452
|
}
|
|
13462
13453
|
return null;
|
|
13463
13454
|
}
|
|
13464
|
-
resyncTextMetricsForSvgExport(fabricInstance) {
|
|
13465
|
-
if (typeof document === "undefined" || !(fabricInstance == null ? void 0 : fabricInstance.getObjects)) return;
|
|
13466
|
-
const ctx = document.createElement("canvas").getContext("2d");
|
|
13467
|
-
if (!ctx) return;
|
|
13468
|
-
const syncTextbox = (textbox) => {
|
|
13469
|
-
const tb = textbox;
|
|
13470
|
-
const rawLines = tb._textLines ?? textbox.textLines ?? [];
|
|
13471
|
-
if (!Array.isArray(rawLines) || rawLines.length === 0) return;
|
|
13472
|
-
const nextCharBounds = [];
|
|
13473
|
-
const nextLineWidths = [];
|
|
13474
|
-
rawLines.forEach((rawLine, lineIndex) => {
|
|
13475
|
-
const graphemes = Array.isArray(rawLine) ? rawLine.map((part) => String(part ?? "")) : Array.from(String(rawLine ?? ""));
|
|
13476
|
-
const bounds = [];
|
|
13477
|
-
let left = 0;
|
|
13478
|
-
graphemes.forEach((grapheme, charIndex) => {
|
|
13479
|
-
var _a, _b, _c, _d, _e, _f;
|
|
13480
|
-
const fontSize = Number(((_a = tb.getValueOfPropertyAt) == null ? void 0 : _a.call(tb, lineIndex, charIndex, "fontSize")) ?? textbox.fontSize ?? 16);
|
|
13481
|
-
const fontStyle = String(((_b = tb.getValueOfPropertyAt) == null ? void 0 : _b.call(tb, lineIndex, charIndex, "fontStyle")) ?? textbox.fontStyle ?? "normal");
|
|
13482
|
-
const fontWeight = String(((_c = tb.getValueOfPropertyAt) == null ? void 0 : _c.call(tb, lineIndex, charIndex, "fontWeight")) ?? textbox.fontWeight ?? "400");
|
|
13483
|
-
const fontFamily = String(((_d = tb.getValueOfPropertyAt) == null ? void 0 : _d.call(tb, lineIndex, charIndex, "fontFamily")) ?? textbox.fontFamily ?? "sans-serif");
|
|
13484
|
-
const charSpacing = Number(((_e = tb.getValueOfPropertyAt) == null ? void 0 : _e.call(tb, lineIndex, charIndex, "charSpacing")) ?? textbox.charSpacing ?? 0);
|
|
13485
|
-
const deltaY = Number(((_f = tb.getValueOfPropertyAt) == null ? void 0 : _f.call(tb, lineIndex, charIndex, "deltaY")) ?? 0);
|
|
13486
|
-
ctx.font = `${fontStyle} normal ${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
13487
|
-
const charWidth = Math.max(0, ctx.measureText(grapheme).width);
|
|
13488
|
-
let kernedWidth = charWidth;
|
|
13489
|
-
const previous = charIndex > 0 ? graphemes[charIndex - 1] : "";
|
|
13490
|
-
if (previous) {
|
|
13491
|
-
const pairWidth = ctx.measureText(previous + grapheme).width;
|
|
13492
|
-
const previousWidth = ctx.measureText(previous).width;
|
|
13493
|
-
if (Number.isFinite(pairWidth) && Number.isFinite(previousWidth)) {
|
|
13494
|
-
kernedWidth = Math.max(0, pairWidth - previousWidth);
|
|
13495
|
-
}
|
|
13496
|
-
}
|
|
13497
|
-
if (charIndex < graphemes.length - 1 && charSpacing) {
|
|
13498
|
-
kernedWidth += charSpacing / 1e3 * fontSize;
|
|
13499
|
-
}
|
|
13500
|
-
bounds[charIndex] = { left, width: charWidth, kernedWidth, height: fontSize, deltaY };
|
|
13501
|
-
left += kernedWidth;
|
|
13502
|
-
});
|
|
13503
|
-
bounds[graphemes.length] = { left, width: 0, kernedWidth: 0, height: Number(textbox.fontSize ?? 16), deltaY: 0 };
|
|
13504
|
-
nextCharBounds[lineIndex] = bounds;
|
|
13505
|
-
nextLineWidths[lineIndex] = Math.max(0, left);
|
|
13506
|
-
});
|
|
13507
|
-
tb.__charBounds = nextCharBounds;
|
|
13508
|
-
tb.__lineWidths = nextLineWidths;
|
|
13509
|
-
textbox.dirty = true;
|
|
13510
|
-
};
|
|
13511
|
-
const visit = (obj) => {
|
|
13512
|
-
if (obj instanceof fabric.Textbox) syncTextbox(obj);
|
|
13513
|
-
else if (obj instanceof fabric.Group) obj.getObjects().forEach(visit);
|
|
13514
|
-
};
|
|
13515
|
-
fabricInstance.getObjects().forEach(visit);
|
|
13516
|
-
}
|
|
13517
13455
|
async waitForStableTextMetrics(container, config) {
|
|
13518
13456
|
var _a, _b, _c;
|
|
13519
13457
|
if (typeof document !== "undefined") {
|