@pixldocs/canvas-renderer 0.5.15 → 0.5.16
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 +19 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +19 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2703,12 +2703,10 @@ const waitForFontsReady = async () => {
|
|
|
2703
2703
|
if (!document.fonts) return;
|
|
2704
2704
|
await withFontTimeout(document.fonts.ready, 2500);
|
|
2705
2705
|
};
|
|
2706
|
-
const DEFAULT_FONT_CHECK_TIMEOUT_MS = 3500;
|
|
2707
|
-
const FONT_CHECK_POLL_MS = 60;
|
|
2708
2706
|
const waitUntilFontsAvailable = async (fontFamilies, options) => {
|
|
2709
2707
|
if (!document.fonts || fontFamilies.length === 0) return;
|
|
2710
|
-
const timeoutMs =
|
|
2711
|
-
const pollMs =
|
|
2708
|
+
const timeoutMs = options == null ? void 0 : options.timeoutMs;
|
|
2709
|
+
const pollMs = options == null ? void 0 : options.pollIntervalMs;
|
|
2712
2710
|
const deadline = Date.now() + timeoutMs;
|
|
2713
2711
|
const check = () => fontFamilies.every(
|
|
2714
2712
|
(f) => document.fonts.check(`16px "${f}"`) && document.fonts.check(`bold 16px "${f}"`)
|
|
@@ -11707,18 +11705,16 @@ function normalizeFontFamily(fontStack) {
|
|
|
11707
11705
|
}
|
|
11708
11706
|
const loadedFonts = /* @__PURE__ */ new Set();
|
|
11709
11707
|
const loadingPromises = /* @__PURE__ */ new Map();
|
|
11710
|
-
|
|
11708
|
+
function withTimeout(promise, timeoutMs = 4e3) {
|
|
11711
11709
|
let timeoutId;
|
|
11712
|
-
|
|
11713
|
-
|
|
11714
|
-
|
|
11715
|
-
|
|
11716
|
-
|
|
11717
|
-
|
|
11718
|
-
]);
|
|
11719
|
-
} finally {
|
|
11710
|
+
return Promise.race([
|
|
11711
|
+
promise,
|
|
11712
|
+
new Promise((resolve) => {
|
|
11713
|
+
timeoutId = setTimeout(resolve, timeoutMs);
|
|
11714
|
+
})
|
|
11715
|
+
]).finally(() => {
|
|
11720
11716
|
if (timeoutId) clearTimeout(timeoutId);
|
|
11721
|
-
}
|
|
11717
|
+
});
|
|
11722
11718
|
}
|
|
11723
11719
|
async function loadGoogleFontCSS(rawFontFamily) {
|
|
11724
11720
|
if (!rawFontFamily || typeof document === "undefined") return;
|
|
@@ -11740,10 +11736,6 @@ async function loadGoogleFontCSS(rawFontFamily) {
|
|
|
11740
11736
|
link.onerror = () => reject(new Error(`Failed to load font: ${fontFamily}`));
|
|
11741
11737
|
document.head.appendChild(link);
|
|
11742
11738
|
});
|
|
11743
|
-
if (document.fonts) {
|
|
11744
|
-
await withTimeout(document.fonts.load(`16px "${fontFamily}"`), 2500);
|
|
11745
|
-
await withTimeout(document.fonts.ready, 2500);
|
|
11746
|
-
}
|
|
11747
11739
|
loadedFonts.add(fontFamily);
|
|
11748
11740
|
} catch (e) {
|
|
11749
11741
|
console.warn(`[@pixldocs/canvas-renderer] Font load failed: ${fontFamily}`, e);
|
|
@@ -11855,17 +11847,15 @@ async function ensureFontsForResolvedConfig(config) {
|
|
|
11855
11847
|
if (typeof document === "undefined") return;
|
|
11856
11848
|
const descriptors = collectFontDescriptorsFromConfig(config);
|
|
11857
11849
|
const families = new Set(descriptors.map((d) => d.family));
|
|
11858
|
-
|
|
11850
|
+
void withTimeout(Promise.all([...families].map((f) => loadGoogleFontCSS(f))), 2500);
|
|
11859
11851
|
if (document.fonts) {
|
|
11860
|
-
|
|
11852
|
+
descriptors.forEach((d) => {
|
|
11861
11853
|
const stylePrefix = d.style === "italic" ? "italic " : "";
|
|
11862
11854
|
const weightStr = String(d.weight);
|
|
11863
11855
|
const spec = `${stylePrefix}${weightStr} 16px "${d.family}"`;
|
|
11864
|
-
|
|
11856
|
+
document.fonts.load(spec).catch(() => {
|
|
11865
11857
|
});
|
|
11866
11858
|
});
|
|
11867
|
-
await withTimeout(Promise.all(loadPromises), 8e3);
|
|
11868
|
-
await withTimeout(document.fonts.ready, 2500);
|
|
11869
11859
|
}
|
|
11870
11860
|
}
|
|
11871
11861
|
function PixldocsPreview(props) {
|
|
@@ -12649,14 +12639,8 @@ class PixldocsRenderer {
|
|
|
12649
12639
|
return null;
|
|
12650
12640
|
}
|
|
12651
12641
|
async waitForStableTextMetrics(container, config) {
|
|
12652
|
-
var _a;
|
|
12653
12642
|
if (typeof document !== "undefined") {
|
|
12654
12643
|
await ensureFontsForResolvedConfig(config);
|
|
12655
|
-
await ((_a = document.fonts) == null ? void 0 : _a.ready);
|
|
12656
|
-
const fontFamilies = [...collectFontsFromConfig(config)].filter(Boolean);
|
|
12657
|
-
if (fontFamilies.length > 0) {
|
|
12658
|
-
await waitUntilFontsAvailable(fontFamilies, { timeoutMs: 4e3, pollIntervalMs: 50 });
|
|
12659
|
-
}
|
|
12660
12644
|
}
|
|
12661
12645
|
const fabricInstance = this.getFabricCanvasFromContainer(container);
|
|
12662
12646
|
if (!(fabricInstance == null ? void 0 : fabricInstance.getObjects)) return;
|
|
@@ -12666,9 +12650,9 @@ class PixldocsRenderer {
|
|
|
12666
12650
|
clearMeasurementCache();
|
|
12667
12651
|
};
|
|
12668
12652
|
const reflowTextboxes = () => {
|
|
12669
|
-
var
|
|
12653
|
+
var _a, _b, _c;
|
|
12670
12654
|
const walk = (obj) => {
|
|
12671
|
-
var
|
|
12655
|
+
var _a2, _b2, _c2, _d;
|
|
12672
12656
|
if (!obj) return;
|
|
12673
12657
|
const children = Array.isArray(obj._objects) ? obj._objects : Array.isArray(obj.objects) ? obj.objects : [];
|
|
12674
12658
|
if (children.length) children.forEach(walk);
|
|
@@ -12680,8 +12664,8 @@ class PixldocsRenderer {
|
|
|
12680
12664
|
scaleY: obj.scaleY
|
|
12681
12665
|
};
|
|
12682
12666
|
const resetTextboxLayoutInternals = () => {
|
|
12683
|
-
var
|
|
12684
|
-
(
|
|
12667
|
+
var _a3;
|
|
12668
|
+
(_a3 = obj._clearCache) == null ? void 0 : _a3.call(obj);
|
|
12685
12669
|
obj.__charBounds = [];
|
|
12686
12670
|
obj.__lineWidths = [];
|
|
12687
12671
|
obj.__lineHeights = [];
|
|
@@ -12695,7 +12679,7 @@ class PixldocsRenderer {
|
|
|
12695
12679
|
resetTextboxLayoutInternals();
|
|
12696
12680
|
obj.initDimensions();
|
|
12697
12681
|
if (saved.width != null) {
|
|
12698
|
-
(
|
|
12682
|
+
(_a2 = obj.set) == null ? void 0 : _a2.call(obj, {
|
|
12699
12683
|
width: saved.width,
|
|
12700
12684
|
scaleX: saved.scaleX,
|
|
12701
12685
|
scaleY: saved.scaleY
|
|
@@ -12714,7 +12698,7 @@ class PixldocsRenderer {
|
|
|
12714
12698
|
}
|
|
12715
12699
|
};
|
|
12716
12700
|
fabricInstance.getObjects().forEach(walk);
|
|
12717
|
-
(
|
|
12701
|
+
(_a = fabricInstance.calcOffset) == null ? void 0 : _a.call(fabricInstance);
|
|
12718
12702
|
(_b = fabricInstance.renderAll) == null ? void 0 : _b.call(fabricInstance);
|
|
12719
12703
|
(_c = fabricInstance.requestRenderAll) == null ? void 0 : _c.call(fabricInstance);
|
|
12720
12704
|
};
|