@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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @versa_ai/vmml-editor@1.0.22 build D:\code\work\vmml-player\packages\editor
2
+ > @versa_ai/vmml-editor@1.0.23 build D:\code\work\vmml-player\packages\editor
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: src/index.tsx
@@ -9,6 +9,7 @@
9
9
  CLI Target: node16
10
10
  CJS Build start
11
11
  ESM Build start
12
+ DTS Build start
12
13
 
13
14
   WARN  ▲ [WARNING] Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.
14
15
 
@@ -123,13 +124,12 @@ More info and automated migrator: https://sass-lang.com/d/slash-div [35
123
124
 
124
125
 
125
126
 
126
- DTS Build start
127
- CJS dist\index.js 114.41 KB
128
- CJS dist\index.js.map 216.82 KB
129
- CJS ⚡️ Build success in 685ms
130
- ESM dist\index.mjs 112.78 KB
131
- ESM dist\index.mjs.map 216.53 KB
132
- ESM ⚡️ Build success in 685ms
133
- DTS ⚡️ Build success in 2259ms
127
+ ESM dist\index.mjs 113.36 KB
128
+ ESM dist\index.mjs.map 217.80 KB
129
+ ESM ⚡️ Build success in 820ms
130
+ CJS dist\index.js 115.00 KB
131
+ CJS dist\index.js.map 218.10 KB
132
+ CJS ⚡️ Build success in 821ms
133
+ DTS ⚡️ Build success in 2291ms
134
134
  DTS dist\index.d.ts 158.00 B
135
135
  DTS dist\index.d.mts 158.00 B
package/dist/index.js CHANGED
@@ -1407,9 +1407,10 @@ var EditorCanvas = react.forwardRef(
1407
1407
  if (lower.includes(".ttf")) return "truetype";
1408
1408
  return null;
1409
1409
  };
1410
- const embedFontInSVG = async (svgString, url) => {
1410
+ const embedFontInSVG = async (svgString, url, fontBase64) => {
1411
1411
  if (url) {
1412
- const res = await vmmlUtils.urlToBlob({ url });
1412
+ let res = fontBase64;
1413
+ if (!res) await vmmlUtils.urlToBlob({ url });
1413
1414
  const format = detectFontFormat(url);
1414
1415
  const fontFamilyName = getFontFamilyName(url);
1415
1416
  const srcValue = format ? `url('${res}') format('${format}')` : `url('${res}')`;
@@ -1425,7 +1426,22 @@ var EditorCanvas = react.forwardRef(
1425
1426
  }
1426
1427
  return svgString;
1427
1428
  };
1429
+ const loadFont = async (url) => {
1430
+ if (!url) return null;
1431
+ try {
1432
+ const base64 = await vmmlUtils.urlToBlob({ url });
1433
+ const fontFamilyName = getFontFamilyName(url);
1434
+ const format = detectFontFormat(url);
1435
+ const fontFace = new FontFace(fontFamilyName, `url(${base64})${format ? ` format('${format}')` : ""}`);
1436
+ await fontFace.load();
1437
+ document.fonts.add(fontFace);
1438
+ return base64;
1439
+ } catch (e) {
1440
+ return null;
1441
+ }
1442
+ };
1428
1443
  const createTextImg = async ({ textContent, bgColor, textColor, stColor, strokeW, fontAssetUrl = null, textBasicInfo }) => {
1444
+ const fontBase64 = await loadFont(fontAssetUrl);
1429
1445
  const container = document.createElement("div");
1430
1446
  container.style.backgroundColor = bgColor;
1431
1447
  container.style.boxSizing = "content-box";
@@ -1467,7 +1483,7 @@ var EditorCanvas = react.forwardRef(
1467
1483
  const { width, height } = container == null ? void 0 : container.getBoundingClientRect();
1468
1484
  const dataurl = await domToImage.toSvg(container);
1469
1485
  document.body.removeChild(container);
1470
- const base64Image = await embedFontInSVG(dataurl, fontAssetUrl);
1486
+ const base64Image = await embedFontInSVG(dataurl, fontAssetUrl, fontBase64);
1471
1487
  return { base64Image, height, width };
1472
1488
  };
1473
1489
  const createText = async ({ textContent, bgColor, textColor, position, textBasicInfo, id }, fc2) => {