@pixldocs/canvas-renderer 0.5.20 → 0.5.22
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 +12 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -11852,35 +11852,19 @@ async function ensureFontsForResolvedConfig(config) {
|
|
|
11852
11852
|
if (typeof document === "undefined") return;
|
|
11853
11853
|
const descriptors = collectFontDescriptorsFromConfig(config);
|
|
11854
11854
|
const families = new Set(descriptors.map((d) => d.family));
|
|
11855
|
-
|
|
11855
|
+
await withTimeout(Promise.all([...families].map((f) => loadGoogleFontCSS(f))), 6e3);
|
|
11856
11856
|
if (document.fonts) {
|
|
11857
|
-
descriptors.
|
|
11857
|
+
await withTimeout(Promise.all(descriptors.map((d) => {
|
|
11858
11858
|
const stylePrefix = d.style === "italic" ? "italic " : "";
|
|
11859
11859
|
const weightStr = String(d.weight);
|
|
11860
11860
|
const spec = `${stylePrefix}${weightStr} 16px "${d.family}"`;
|
|
11861
|
-
document.fonts.load(spec).catch(() => {
|
|
11861
|
+
return document.fonts.load(spec).catch(() => {
|
|
11862
11862
|
});
|
|
11863
|
-
});
|
|
11863
|
+
})), 6e3);
|
|
11864
|
+
await withTimeout(document.fonts.ready, 6e3);
|
|
11864
11865
|
}
|
|
11865
11866
|
}
|
|
11866
11867
|
const TEXT_TYPES = /* @__PURE__ */ new Set(["textbox", "text", "i-text"]);
|
|
11867
|
-
function getTextLines(obj) {
|
|
11868
|
-
const lines = Array.isArray(obj.textLines) && obj.textLines.length ? obj.textLines : String(obj.text || "").split("\n");
|
|
11869
|
-
return lines.map((line) => Array.isArray(line) ? line.join("") : String(line ?? ""));
|
|
11870
|
-
}
|
|
11871
|
-
function measureLineWidth(obj, line) {
|
|
11872
|
-
if (typeof document === "undefined") return 0;
|
|
11873
|
-
const canvas = document.createElement("canvas");
|
|
11874
|
-
const ctx = canvas.getContext("2d");
|
|
11875
|
-
if (!ctx) return 0;
|
|
11876
|
-
const fontStyle = obj.fontStyle || "normal";
|
|
11877
|
-
const fontWeight = obj.fontWeight || 400;
|
|
11878
|
-
const fontSize = obj.fontSize || 16;
|
|
11879
|
-
const fontFamily = obj.fontFamily || "sans-serif";
|
|
11880
|
-
ctx.font = `${fontStyle} ${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
11881
|
-
const charSpacing = Number(obj.charSpacing || 0) / 1e3 * fontSize;
|
|
11882
|
-
return ctx.measureText(line).width + Math.max(0, line.length - 1) * charSpacing;
|
|
11883
|
-
}
|
|
11884
11868
|
function getFabricCanvasFromContainer(container) {
|
|
11885
11869
|
const registry2 = window.__fabricCanvasRegistry;
|
|
11886
11870
|
if (registry2 instanceof Map) {
|
|
@@ -11927,10 +11911,6 @@ function stabilizeFabricTextObjects(fabricInstance) {
|
|
|
11927
11911
|
obj.initDimensions();
|
|
11928
11912
|
(_b2 = obj.set) == null ? void 0 : _b2.call(obj, { width: saved.width, scaleX: saved.scaleX, scaleY: saved.scaleY });
|
|
11929
11913
|
}
|
|
11930
|
-
if (obj.underline || obj.linethrough) {
|
|
11931
|
-
const lineWidths = Array.isArray(obj.__lineWidths) ? obj.__lineWidths : [];
|
|
11932
|
-
obj.__lineWidths = getTextLines(obj).map((line, index) => Math.max(lineWidths[index] || 0, measureLineWidth(obj, line)));
|
|
11933
|
-
}
|
|
11934
11914
|
obj.dirty = true;
|
|
11935
11915
|
(_c2 = obj._clearCache) == null ? void 0 : _c2.call(obj);
|
|
11936
11916
|
(_d = obj.setCoords) == null ? void 0 : _d.call(obj);
|
|
@@ -12576,7 +12556,7 @@ class PixldocsRenderer {
|
|
|
12576
12556
|
container.style.cssText = `
|
|
12577
12557
|
position: fixed; left: -99999px; top: -99999px;
|
|
12578
12558
|
width: ${canvasWidth}px; height: ${canvasHeight}px;
|
|
12579
|
-
overflow: hidden; pointer-events: none;
|
|
12559
|
+
overflow: hidden; pointer-events: none; visibility: hidden;
|
|
12580
12560
|
`;
|
|
12581
12561
|
document.body.appendChild(container);
|
|
12582
12562
|
const timeout = setTimeout(() => {
|
|
@@ -12597,7 +12577,7 @@ class PixldocsRenderer {
|
|
|
12597
12577
|
finished = true;
|
|
12598
12578
|
this.waitForCanvasScene(container, config, pageIndex).then(async () => {
|
|
12599
12579
|
try {
|
|
12600
|
-
await this.waitForStableTextMetrics(container, config);
|
|
12580
|
+
await this.waitForStableTextMetrics(container, config, true);
|
|
12601
12581
|
await this.waitForCanvasScene(container, config, pageIndex, 2500, 50);
|
|
12602
12582
|
const fabricInstance = this.getFabricCanvasFromContainer(container);
|
|
12603
12583
|
const expectedImageCount = this.getExpectedImageCount(config, pageIndex);
|
|
@@ -12640,7 +12620,6 @@ class PixldocsRenderer {
|
|
|
12640
12620
|
pageIndex,
|
|
12641
12621
|
zoom: pixelRatio,
|
|
12642
12622
|
absoluteZoom: true,
|
|
12643
|
-
skipFontReadyWait: true,
|
|
12644
12623
|
onReady
|
|
12645
12624
|
})
|
|
12646
12625
|
);
|
|
@@ -12662,7 +12641,7 @@ class PixldocsRenderer {
|
|
|
12662
12641
|
container.style.cssText = `
|
|
12663
12642
|
position: fixed; left: -99999px; top: -99999px;
|
|
12664
12643
|
width: ${canvasWidth}px; height: ${canvasHeight}px;
|
|
12665
|
-
overflow: hidden; pointer-events: none;
|
|
12644
|
+
overflow: hidden; pointer-events: none; visibility: hidden;
|
|
12666
12645
|
`;
|
|
12667
12646
|
document.body.appendChild(container);
|
|
12668
12647
|
const timeout = setTimeout(() => {
|
|
@@ -12684,7 +12663,7 @@ class PixldocsRenderer {
|
|
|
12684
12663
|
this.waitForCanvasScene(container, config, pageIndex).then(async () => {
|
|
12685
12664
|
var _a, _b;
|
|
12686
12665
|
try {
|
|
12687
|
-
await this.waitForStableTextMetrics(container, config);
|
|
12666
|
+
await this.waitForStableTextMetrics(container, config, true);
|
|
12688
12667
|
await this.waitForCanvasScene(container, config, pageIndex, 2500, 50);
|
|
12689
12668
|
const fabricInstance = this.getFabricCanvasFromContainer(container);
|
|
12690
12669
|
if (!fabricInstance) {
|
|
@@ -12744,7 +12723,6 @@ class PixldocsRenderer {
|
|
|
12744
12723
|
zoom: 1,
|
|
12745
12724
|
// 1:1 — no UI scaling for SVG capture
|
|
12746
12725
|
absoluteZoom: true,
|
|
12747
|
-
skipFontReadyWait: true,
|
|
12748
12726
|
onReady
|
|
12749
12727
|
})
|
|
12750
12728
|
);
|
|
@@ -12807,10 +12785,10 @@ class PixldocsRenderer {
|
|
|
12807
12785
|
getFabricCanvasFromContainer(container) {
|
|
12808
12786
|
return getFabricCanvasFromContainer(container);
|
|
12809
12787
|
}
|
|
12810
|
-
async waitForStableTextMetrics(container, config) {
|
|
12788
|
+
async waitForStableTextMetrics(container, config, strictFontWait = false) {
|
|
12811
12789
|
if (typeof document !== "undefined") {
|
|
12812
|
-
|
|
12813
|
-
await this.waitForRelevantFonts(config);
|
|
12790
|
+
await ensureFontsForResolvedConfig(config);
|
|
12791
|
+
await this.waitForRelevantFonts(config, strictFontWait ? 6e3 : 1800);
|
|
12814
12792
|
}
|
|
12815
12793
|
const fabricInstance = this.getFabricCanvasFromContainer(container);
|
|
12816
12794
|
if (!(fabricInstance == null ? void 0 : fabricInstance.getObjects)) return;
|