@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versa_ai/vmml-editor",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "module": "dist/index.mjs",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.mts",
@@ -16,7 +16,7 @@
16
16
  "remotion": "4.0.166",
17
17
  "uuid": "^10.0.0",
18
18
  "zod": "^3.23.8",
19
- "@versa_ai/vmml-player": "1.1.19",
19
+ "@versa_ai/vmml-player": "1.1.20",
20
20
  "@versa_ai/vmml-utils": "1.0.15"
21
21
  },
22
22
  "devDependencies": {
@@ -427,9 +427,10 @@ const EditorCanvas = forwardRef(
427
427
  return null;
428
428
  };
429
429
 
430
- const embedFontInSVG = async (svgString: string, url: string) => {
430
+ const embedFontInSVG = async (svgString: string, url: string, fontBase64?: any) => {
431
431
  if (url) {
432
- const res = await urlToBlob({ url });
432
+ let res = fontBase64;
433
+ if (!res) await urlToBlob({ url });
433
434
  const format = detectFontFormat(url);
434
435
  const fontFamilyName = getFontFamilyName(url);
435
436
  const srcValue = format ? `url('${res}') format('${format}')` : `url('${res}')`;
@@ -446,8 +447,25 @@ const EditorCanvas = forwardRef(
446
447
  return svgString
447
448
  }
448
449
 
450
+ const loadFont = async (url: any) => {
451
+ if (!url) return null
452
+ try {
453
+ const base64 = await urlToBlob({ url });
454
+ const fontFamilyName = getFontFamilyName(url);
455
+ const format = detectFontFormat(url);
456
+
457
+ const fontFace = new FontFace(fontFamilyName, `url(${base64})${format ? ` format('${format}')` : ''}`);
458
+ await fontFace.load();
459
+ (document.fonts as any).add(fontFace);
460
+ return base64
461
+ } catch (e) {
462
+ return null
463
+ }
464
+ }
465
+
449
466
  //文字转图片
450
467
  const createTextImg = async ({ textContent, bgColor, textColor, stColor, strokeW, fontAssetUrl = null, textBasicInfo }: any) => {
468
+ const fontBase64 = await loadFont(fontAssetUrl)
451
469
  const container = document.createElement('div');
452
470
  container.style.backgroundColor = bgColor
453
471
  // container.style.width = `fit-content`
@@ -495,7 +513,7 @@ const EditorCanvas = forwardRef(
495
513
  const { width, height } = container?.getBoundingClientRect() as any;
496
514
  const dataurl = await toSvg(container);
497
515
  document.body.removeChild(container);
498
- const base64Image = await embedFontInSVG(dataurl, fontAssetUrl);
516
+ const base64Image = await embedFontInSVG(dataurl, fontAssetUrl, fontBase64);
499
517
  return { base64Image, height, width };
500
518
  }
501
519
  const createText = async ({ textContent, bgColor, textColor, position, textBasicInfo, id }: any, fc2: any) => {