@versa_ai/vmml-editor 1.0.22 → 1.0.23
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/.turbo/turbo-build.log +9 -9
- package/dist/index.js +19 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/components/EditorCanvas.tsx +21 -3
package/dist/index.mjs
CHANGED
|
@@ -1405,9 +1405,10 @@ var EditorCanvas = forwardRef(
|
|
|
1405
1405
|
if (lower.includes(".ttf")) return "truetype";
|
|
1406
1406
|
return null;
|
|
1407
1407
|
};
|
|
1408
|
-
const embedFontInSVG = async (svgString, url) => {
|
|
1408
|
+
const embedFontInSVG = async (svgString, url, fontBase64) => {
|
|
1409
1409
|
if (url) {
|
|
1410
|
-
|
|
1410
|
+
let res = fontBase64;
|
|
1411
|
+
if (!res) await urlToBlob({ url });
|
|
1411
1412
|
const format = detectFontFormat(url);
|
|
1412
1413
|
const fontFamilyName = getFontFamilyName(url);
|
|
1413
1414
|
const srcValue = format ? `url('${res}') format('${format}')` : `url('${res}')`;
|
|
@@ -1423,7 +1424,22 @@ var EditorCanvas = forwardRef(
|
|
|
1423
1424
|
}
|
|
1424
1425
|
return svgString;
|
|
1425
1426
|
};
|
|
1427
|
+
const loadFont = async (url) => {
|
|
1428
|
+
if (!url) return null;
|
|
1429
|
+
try {
|
|
1430
|
+
const base64 = await urlToBlob({ url });
|
|
1431
|
+
const fontFamilyName = getFontFamilyName(url);
|
|
1432
|
+
const format = detectFontFormat(url);
|
|
1433
|
+
const fontFace = new FontFace(fontFamilyName, `url(${base64})${format ? ` format('${format}')` : ""}`);
|
|
1434
|
+
await fontFace.load();
|
|
1435
|
+
document.fonts.add(fontFace);
|
|
1436
|
+
return base64;
|
|
1437
|
+
} catch (e) {
|
|
1438
|
+
return null;
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1426
1441
|
const createTextImg = async ({ textContent, bgColor, textColor, stColor, strokeW, fontAssetUrl = null, textBasicInfo }) => {
|
|
1442
|
+
const fontBase64 = await loadFont(fontAssetUrl);
|
|
1427
1443
|
const container = document.createElement("div");
|
|
1428
1444
|
container.style.backgroundColor = bgColor;
|
|
1429
1445
|
container.style.boxSizing = "content-box";
|
|
@@ -1465,7 +1481,7 @@ var EditorCanvas = forwardRef(
|
|
|
1465
1481
|
const { width, height } = container == null ? void 0 : container.getBoundingClientRect();
|
|
1466
1482
|
const dataurl = await toSvg(container);
|
|
1467
1483
|
document.body.removeChild(container);
|
|
1468
|
-
const base64Image = await embedFontInSVG(dataurl, fontAssetUrl);
|
|
1484
|
+
const base64Image = await embedFontInSVG(dataurl, fontAssetUrl, fontBase64);
|
|
1469
1485
|
return { base64Image, height, width };
|
|
1470
1486
|
};
|
|
1471
1487
|
const createText = async ({ textContent, bgColor, textColor, position, textBasicInfo, id }, fc2) => {
|