@newtonedev/components 0.1.9 → 0.1.10
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/fonts/measureFont.d.ts +2 -1
- package/dist/fonts/measureFont.d.ts.map +1 -1
- package/dist/index.cjs +11 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/fonts/measureFont.ts +15 -2
package/dist/index.js
CHANGED
|
@@ -835,10 +835,20 @@ function Icon({
|
|
|
835
835
|
|
|
836
836
|
// src/fonts/measureFont.ts
|
|
837
837
|
var REF_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
|
|
838
|
+
function withTimeout(promise, ms, fallback) {
|
|
839
|
+
return Promise.race([
|
|
840
|
+
promise,
|
|
841
|
+
new Promise((resolve) => setTimeout(() => resolve(fallback), ms))
|
|
842
|
+
]);
|
|
843
|
+
}
|
|
838
844
|
async function measureAvgCharWidth(fontFamily, fontWeight, fallback, fontSize = 16) {
|
|
839
845
|
if (typeof document === "undefined") return 0.55;
|
|
840
846
|
try {
|
|
841
|
-
await
|
|
847
|
+
await withTimeout(
|
|
848
|
+
document.fonts.load(`${fontWeight} ${fontSize}px "${fontFamily}"`),
|
|
849
|
+
3e3,
|
|
850
|
+
[]
|
|
851
|
+
);
|
|
842
852
|
const canvas = document.createElement("canvas");
|
|
843
853
|
const ctx = canvas.getContext("2d");
|
|
844
854
|
if (!ctx) return 0.55;
|