@versa_ai/vmml-editor 1.0.20 → 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.20 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
@@ -124,12 +124,12 @@ More info and automated migrator: https://sass-lang.com/d/slash-div [35
124
124
 
125
125
 
126
126
 
127
- CJS dist\index.js 113.85 KB
128
- CJS dist\index.js.map 215.74 KB
129
- CJS ⚡️ Build success in 1007ms
130
- ESM dist\index.mjs 112.22 KB
131
- ESM dist\index.mjs.map 215.45 KB
132
- ESM ⚡️ Build success in 1007ms
133
- DTS ⚡️ Build success in 2220ms
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
@@ -1323,7 +1323,7 @@ var EditorCanvas = react.forwardRef(
1323
1323
  const { textContent, backgroundColor, textColor, posParam, fontAssetUrl, alignType, strokeColor, strokeWidth } = clip.textClip;
1324
1324
  const scaleX = posParam.scaleX * fontSize / 22 / widthScaleRef.current;
1325
1325
  const scaleY = posParam.scaleY * fontSize / 22 / heightScaleRef.current;
1326
- const strokeW = strokeWidth ? strokeWidth * 22 / fontSize : 0;
1326
+ const strokeW = strokeWidth * 26 * 1.5 / fontSize;
1327
1327
  const left = canvasSize.width * posParam.centerX;
1328
1328
  const top = canvasSize.height * posParam.centerY;
1329
1329
  const bgColor = backgroundColor ? vmmlUtils.argbToRgba(backgroundColor) : "transparent";
@@ -1356,6 +1356,7 @@ var EditorCanvas = react.forwardRef(
1356
1356
  angle: posParam.rotationZ,
1357
1357
  originX: "center",
1358
1358
  originY: "center",
1359
+ objectCaching: false,
1359
1360
  clipData: {
1360
1361
  id: clip.id,
1361
1362
  inPoint: clip.inPoint,
@@ -1406,9 +1407,10 @@ var EditorCanvas = react.forwardRef(
1406
1407
  if (lower.includes(".ttf")) return "truetype";
1407
1408
  return null;
1408
1409
  };
1409
- const embedFontInSVG = async (svgString, url) => {
1410
+ const embedFontInSVG = async (svgString, url, fontBase64) => {
1410
1411
  if (url) {
1411
- const res = await vmmlUtils.urlToBlob({ url });
1412
+ let res = fontBase64;
1413
+ if (!res) await vmmlUtils.urlToBlob({ url });
1412
1414
  const format = detectFontFormat(url);
1413
1415
  const fontFamilyName = getFontFamilyName(url);
1414
1416
  const srcValue = format ? `url('${res}') format('${format}')` : `url('${res}')`;
@@ -1424,7 +1426,22 @@ var EditorCanvas = react.forwardRef(
1424
1426
  }
1425
1427
  return svgString;
1426
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
+ };
1427
1443
  const createTextImg = async ({ textContent, bgColor, textColor, stColor, strokeW, fontAssetUrl = null, textBasicInfo }) => {
1444
+ const fontBase64 = await loadFont(fontAssetUrl);
1428
1445
  const container = document.createElement("div");
1429
1446
  container.style.backgroundColor = bgColor;
1430
1447
  container.style.boxSizing = "content-box";
@@ -1434,16 +1451,30 @@ var EditorCanvas = react.forwardRef(
1434
1451
  const fontFamily = fontAssetUrl ? getFontFamilyName(fontAssetUrl) : "sansMedium";
1435
1452
  lines.forEach((line) => {
1436
1453
  const p = document.createElement("p");
1437
- p.style.color = textColor;
1454
+ p.style.position = "relative";
1438
1455
  p.style.fontSize = "22px";
1439
1456
  p.style.lineHeight = "22px";
1440
1457
  p.style.fontFamily = fontFamily;
1441
1458
  p.style.whiteSpace = "nowrap";
1442
- p.style.padding = "0";
1443
1459
  p.style.margin = "0";
1444
- p.style.webkitTextStrokeWidth = `${strokeW ?? 0}px`;
1445
- p.style.webkitTextStrokeColor = stColor;
1446
- p.textContent = line || " ";
1460
+ p.style.padding = "0";
1461
+ p.style.zIndex = "2";
1462
+ const fill = document.createElement("span");
1463
+ fill.textContent = line || " ";
1464
+ fill.style.color = textColor;
1465
+ fill.style.position = "relative";
1466
+ fill.style.zIndex = "1";
1467
+ const stroke = document.createElement("span");
1468
+ stroke.textContent = line || " ";
1469
+ stroke.style.position = "absolute";
1470
+ stroke.style.left = "0";
1471
+ stroke.style.top = "0";
1472
+ stroke.style.color = "transparent";
1473
+ stroke.style.webkitTextStrokeWidth = `${strokeW}px`;
1474
+ stroke.style.webkitTextStrokeColor = stColor;
1475
+ stroke.style.zIndex = "-1";
1476
+ p.appendChild(fill);
1477
+ p.appendChild(stroke);
1447
1478
  container.appendChild(p);
1448
1479
  });
1449
1480
  container.style.padding = "6.5px 7px 6.5px 7px";
@@ -1452,7 +1483,7 @@ var EditorCanvas = react.forwardRef(
1452
1483
  const { width, height } = container == null ? void 0 : container.getBoundingClientRect();
1453
1484
  const dataurl = await domToImage.toSvg(container);
1454
1485
  document.body.removeChild(container);
1455
- const base64Image = await embedFontInSVG(dataurl, fontAssetUrl);
1486
+ const base64Image = await embedFontInSVG(dataurl, fontAssetUrl, fontBase64);
1456
1487
  return { base64Image, height, width };
1457
1488
  };
1458
1489
  const createText = async ({ textContent, bgColor, textColor, position, textBasicInfo, id }, fc2) => {