@pixldocs/canvas-renderer 0.5.62 → 0.5.64
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 +8 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +8 -61
- 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.64";
|
|
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.64";
|
|
12546
12546
|
let __underlineFixInstalled = false;
|
|
12547
12547
|
function installUnderlineFix(fab) {
|
|
12548
12548
|
var _a;
|
|
@@ -13269,10 +13269,11 @@ class PixldocsRenderer {
|
|
|
13269
13269
|
cleanup();
|
|
13270
13270
|
reject(new Error("SVG render timeout (30s)"));
|
|
13271
13271
|
}, 3e4);
|
|
13272
|
+
let root = null;
|
|
13272
13273
|
const cleanup = () => {
|
|
13273
13274
|
clearTimeout(timeout);
|
|
13274
13275
|
try {
|
|
13275
|
-
root.unmount();
|
|
13276
|
+
root == null ? void 0 : root.unmount();
|
|
13276
13277
|
} catch {
|
|
13277
13278
|
}
|
|
13278
13279
|
container.remove();
|
|
@@ -13281,16 +13282,16 @@ class PixldocsRenderer {
|
|
|
13281
13282
|
this.waitForCanvasScene(container, config, pageIndex).then(async () => {
|
|
13282
13283
|
var _a, _b;
|
|
13283
13284
|
try {
|
|
13285
|
+
const expectedImageCount = this.getExpectedImageCount(config, pageIndex);
|
|
13286
|
+
await this.waitForCanvasImages(container, expectedImageCount);
|
|
13287
|
+
await this.waitForStableTextMetrics(container, config);
|
|
13288
|
+
await this.waitForCanvasScene(container, config, pageIndex);
|
|
13284
13289
|
const fabricInstance = this.getFabricCanvasFromContainer(container);
|
|
13285
13290
|
if (!fabricInstance) {
|
|
13286
13291
|
cleanup();
|
|
13287
13292
|
reject(new Error("No Fabric canvas instance found for SVG capture"));
|
|
13288
13293
|
return;
|
|
13289
13294
|
}
|
|
13290
|
-
const expectedImageCount = this.getExpectedImageCount(config, pageIndex);
|
|
13291
|
-
await this.waitForCanvasImages(container, expectedImageCount);
|
|
13292
|
-
await this.waitForStableTextMetrics(container, config);
|
|
13293
|
-
await this.waitForCanvasScene(container, config, pageIndex);
|
|
13294
13295
|
const prevVPT = fabricInstance.viewportTransform ? [...fabricInstance.viewportTransform] : void 0;
|
|
13295
13296
|
const prevSvgVPT = fabricInstance.svgViewportTransformation;
|
|
13296
13297
|
const prevRetina = fabricInstance.enableRetinaScaling;
|
|
@@ -13303,7 +13304,6 @@ class PixldocsRenderer {
|
|
|
13303
13304
|
{ width: canvasWidth, height: canvasHeight },
|
|
13304
13305
|
{ cssOnly: false, backstoreOnly: false }
|
|
13305
13306
|
);
|
|
13306
|
-
this.resyncTextMetricsForSvgExport(fabricInstance);
|
|
13307
13307
|
const rawSvgString = fabricInstance.toSVG();
|
|
13308
13308
|
const svgString = this.normalizeSvgDimensions(
|
|
13309
13309
|
rawSvgString,
|
|
@@ -13334,7 +13334,7 @@ class PixldocsRenderer {
|
|
|
13334
13334
|
}
|
|
13335
13335
|
});
|
|
13336
13336
|
};
|
|
13337
|
-
|
|
13337
|
+
root = createRoot(container);
|
|
13338
13338
|
root.render(
|
|
13339
13339
|
createElement(PreviewCanvas2, {
|
|
13340
13340
|
config,
|
|
@@ -13414,59 +13414,6 @@ class PixldocsRenderer {
|
|
|
13414
13414
|
}
|
|
13415
13415
|
return null;
|
|
13416
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
|
-
}
|
|
13470
13417
|
async waitForStableTextMetrics(container, config) {
|
|
13471
13418
|
var _a, _b, _c;
|
|
13472
13419
|
if (typeof document !== "undefined") {
|