@versa_ai/vmml-editor 1.0.41 → 1.0.42

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.41 build D:\code\work\vmml-player\packages\editor
2
+ > @versa_ai/vmml-editor@1.0.42 build D:\code\work\vmml-player\packages\editor
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: src/index.tsx
@@ -66,7 +66,6 @@ More info and automated migrator: https://sass-lang.com/d/slash-div [35
66
66
 
67
67
 
68
68
 
69
- DTS Build start
70
69
 
71
70
   WARN  ▲ [WARNING] Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.
72
71
 
@@ -124,12 +123,13 @@ More info and automated migrator: https://sass-lang.com/d/slash-div [35
124
123
 
125
124
 
126
125
 
127
- CJS dist\index.js 122.59 KB
128
- CJS dist\index.js.map 234.64 KB
129
- CJS ⚡️ Build success in 868ms
130
- ESM dist\index.mjs 120.90 KB
131
- ESM dist\index.mjs.map 234.34 KB
132
- ESM ⚡️ Build success in 868ms
133
- DTS ⚡️ Build success in 1828ms
126
+ DTS Build start
127
+ ESM dist\index.mjs 119.77 KB
128
+ ESM dist\index.mjs.map 233.03 KB
129
+ ESM ⚡️ Build success in 786ms
130
+ CJS dist\index.js 121.41 KB
131
+ CJS dist\index.js.map 233.32 KB
132
+ CJS ⚡️ Build success in 787ms
133
+ DTS ⚡️ Build success in 2403ms
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
@@ -638,6 +638,7 @@ var VmmlConverter = class {
638
638
  addTextClip(fObj) {
639
639
  console.log("addTextClip fObj", fObj);
640
640
  const posParam = this.setPosParam(fObj);
641
+ console.log(fObj, "fObj>>>>");
641
642
  const { clipData: { id, inPoint, text, textColor, bgColor } } = fObj;
642
643
  const { template: { duration } } = this.vmml;
643
644
  const clips = [];
@@ -750,6 +751,32 @@ var VmmlConverter = class {
750
751
  }
751
752
  }
752
753
  }
754
+ updateTextClip(fObj, duration) {
755
+ console.log("updateClip fObj", fObj, this.tracks);
756
+ const posParam = this.setPosParam(fObj);
757
+ const {
758
+ clipData: { id }
759
+ } = fObj;
760
+ const [existClip] = this.findClip(id);
761
+ if (existClip) {
762
+ const { clipData: { text, textColor, bgColor } } = fObj;
763
+ const scale = this.fontSize / 22;
764
+ existClip.duration = duration;
765
+ console.log(bgColor, "bgColor>>>");
766
+ existClip.textClip = {
767
+ ...existClip.textClip,
768
+ posParam,
769
+ backgroundColor: this.toARGB(bgColor),
770
+ textContent: text,
771
+ textColor: this.toARGB(textColor),
772
+ dimension: {
773
+ width: Math.floor(fObj.width * scale),
774
+ height: Math.floor(fObj.height * scale)
775
+ }
776
+ };
777
+ }
778
+ console.log(this.vmml, "updateText>>>");
779
+ }
753
780
  /**
754
781
  * 删除 Clip
755
782
  * @param id - 实例 id
@@ -781,9 +808,11 @@ var VmmlConverter = class {
781
808
  }
782
809
  }
783
810
  }
811
+ console.log("\u5220\u9664\u4E4B\u540E\u7684vmml", this.vmml);
784
812
  }
785
813
  changeVmml(newVmml) {
786
814
  this.vmml = newVmml;
815
+ this.tracks = this.vmml.template.tracks;
787
816
  }
788
817
  //切换静音 视频/音频
789
818
  changeMute({ id, isMute }) {
@@ -1071,11 +1100,11 @@ var EditorCanvas = react.forwardRef(
1071
1100
  const ns = Math.floor((f ?? frame) / 30 * 1e6);
1072
1101
  const objects = fc.getObjects();
1073
1102
  objects.forEach((item) => {
1074
- var _a, _b, _c;
1103
+ var _a, _b, _c, _d, _e;
1075
1104
  if (((_a = item == null ? void 0 : item.clipData) == null ? void 0 : _a.type) === "\u6587\u5B57") {
1076
1105
  item.set("visible", item.clipData.duration > 0 && ns >= item.clipData.inPoint && ns < item.clipData.inPoint + (item.clipData.duration || vmml.template.duration));
1077
1106
  } else {
1078
- item.set("visible", item.clipData.duration > 0 && ns >= item.clipData.inPoint && ns < item.clipData.inPoint + ((_c = (_b = item.clipData) == null ? void 0 : _b.fileUrl) == null ? void 0 : _c.duration));
1107
+ item.set("visible", ((_c = (_b = item == null ? void 0 : item.clipData) == null ? void 0 : _b.fileUrl) == null ? void 0 : _c.duration) > 0 && ns >= item.clipData.inPoint && ns < item.clipData.inPoint + ((_e = (_d = item.clipData) == null ? void 0 : _d.fileUrl) == null ? void 0 : _e.duration));
1079
1108
  }
1080
1109
  });
1081
1110
  fc.discardActiveObject();
@@ -1238,7 +1267,6 @@ var EditorCanvas = react.forwardRef(
1238
1267
  objects.push(item.value);
1239
1268
  }
1240
1269
  });
1241
- console.log(editRenderTime.current === time, "editRenderTime.current === time");
1242
1270
  if (editRenderTime.current === time) {
1243
1271
  canvas.add(...objects).renderAll();
1244
1272
  checkObjectInPoint();
@@ -1327,91 +1355,104 @@ var EditorCanvas = react.forwardRef(
1327
1355
  });
1328
1356
  window.dispatchEvent(event);
1329
1357
  };
1358
+ const createTextObjs = async ({ strokeW, stColor, fontAssetUrl = null, letterSpace, bgColor, textContent, textBasicInfo, textColor }) => {
1359
+ let fontFamily = "sansMedium";
1360
+ if (fontAssetUrl) {
1361
+ const base64 = await loadFont(fontAssetUrl);
1362
+ if (base64) {
1363
+ fontFamily = getFontFamilyName(fontAssetUrl);
1364
+ await document.fonts.ready;
1365
+ }
1366
+ }
1367
+ const lines = textContent.split("\n").filter((item) => item);
1368
+ const lineHeight = 22 + strokeW;
1369
+ const paddingX = 7;
1370
+ const groupWidth = Math.max(...lines.map((l) => {
1371
+ const temp = new fabric.fabric.Text(l || " ", { fontSize: 22, fontFamily, charSpacing: letterSpace, strokeWidth: strokeW ?? 0 });
1372
+ return (temp == null ? void 0 : temp.width) ?? 0;
1373
+ })) + paddingX * 2;
1374
+ const groupHeight = lines.length * lineHeight;
1375
+ const textObjs = [];
1376
+ lines.forEach((line, idx) => {
1377
+ const y = -groupHeight / 2 + lineHeight / 2 + idx * lineHeight;
1378
+ let originX = "left";
1379
+ let left = paddingX;
1380
+ if (textBasicInfo.textAlign === "center") {
1381
+ originX = "center";
1382
+ left = 0;
1383
+ } else if (textBasicInfo.textAlign === "right") {
1384
+ originX = "right";
1385
+ left = groupWidth - paddingX;
1386
+ }
1387
+ const strokeText = new fabric.fabric.Text(line || " ", {
1388
+ fontFamily,
1389
+ fontSize: 22,
1390
+ fill: "transparent",
1391
+ stroke: stColor,
1392
+ strokeWidth: strokeW,
1393
+ originX,
1394
+ originY: "center",
1395
+ left,
1396
+ top: y,
1397
+ charSpacing: letterSpace,
1398
+ textAlign: "left",
1399
+ objectCaching: false
1400
+ });
1401
+ const fillText = new fabric.fabric.Text(line || " ", {
1402
+ fontFamily,
1403
+ fontSize: 22,
1404
+ fill: textColor,
1405
+ stroke: "transparent",
1406
+ originX,
1407
+ originY: "center",
1408
+ strokeWidth: 0,
1409
+ left,
1410
+ top: y,
1411
+ charSpacing: letterSpace,
1412
+ textAlign: "left",
1413
+ objectCaching: false
1414
+ });
1415
+ textObjs.push(strokeText, fillText);
1416
+ });
1417
+ const bgRect = new fabric.fabric.Rect({
1418
+ width: groupWidth,
1419
+ height: groupHeight + 13,
1420
+ // padddingY: 6.5
1421
+ fill: bgColor,
1422
+ originX: "center",
1423
+ originY: "center",
1424
+ rx: 5,
1425
+ ry: 5
1426
+ });
1427
+ return {
1428
+ objects: [bgRect, ...textObjs],
1429
+ fontFamily
1430
+ };
1431
+ };
1330
1432
  const createTextFromClipCanvas = async (clip, fc2) => {
1331
1433
  return new Promise(async (resolve) => {
1332
1434
  const canvas = fc || fc2;
1333
1435
  if (!canvas) return null;
1334
1436
  const { width, height } = vmml.template.dimension;
1335
1437
  const fontSize = vmmlUtils.getFontSize(width, height);
1336
- const { textContent, backgroundColor, textColor, posParam, fontAssetUrl, alignType, strokeColor, strokeWidth, letterSpacing } = clip.textClip;
1438
+ let { textContent, backgroundColor, textColor, posParam, fontAssetUrl, alignType, strokeColor, strokeWidth, letterSpacing } = clip.textClip;
1337
1439
  const scaleX = posParam.scaleX * fontSize / 22 / widthScaleRef.current;
1338
1440
  const scaleY = posParam.scaleY * fontSize / 22 / heightScaleRef.current;
1339
1441
  const left = canvasSize.width * posParam.centerX;
1340
1442
  const top = canvasSize.height * posParam.centerY;
1341
1443
  const bgColor = backgroundColor ? vmmlUtils.argbToRgba(backgroundColor) : "transparent";
1444
+ const strokeW = strokeColor && strokeWidth ? strokeWidth * 30 * 1.5 / fontSize : 0;
1342
1445
  const stColor = strokeColor ? vmmlUtils.argbToRgba(strokeColor) : "transparent";
1446
+ const letterSpace = letterSpacing * 22 / fontSize * 45;
1343
1447
  const textFill = vmmlUtils.argbToRgba(textColor || "#ffffffff");
1344
- const strokeW = strokeColor && strokeWidth ? strokeWidth * 26 * 1.5 / fontSize : 0;
1345
- const letterSpace = letterSpacing * 22 / fontSize;
1346
- let fontFamily = "sansMedium";
1347
- if (fontAssetUrl) {
1348
- const base64 = await loadFont(fontAssetUrl);
1349
- if (base64) {
1350
- fontFamily = getFontFamilyName(fontAssetUrl);
1351
- await document.fonts.ready;
1352
- }
1353
- }
1354
- const lines = textContent.split("\n").filter((item) => item);
1355
- const lineHeight = 22 + strokeW;
1356
- const textHeight = lines.length * lineHeight;
1357
- const groupWidth = Math.max(...lines.map((l) => {
1358
- const temp = new fabric.fabric.Text(l || " ", { fontSize: 22, fontFamily, charSpacing: (letterSpace || 0) * 50, strokeWidth: strokeW ?? 0 });
1359
- return (temp == null ? void 0 : temp.width) ?? 0;
1360
- })) + 14;
1361
- const groupHeight = textHeight + 13;
1362
- const textObjs = [];
1363
- lines.forEach((line, idx) => {
1364
- const y = (groupHeight - textHeight) / 2 + idx * lineHeight + lineHeight / 2 + 1;
1365
- const strokeText = new fabric.fabric.Text(line || " ", {
1366
- fontFamily,
1367
- fontSize: 22,
1368
- fill: "transparent",
1369
- stroke: stColor,
1370
- strokeWidth: strokeW,
1371
- originX: "center",
1372
- originY: "center",
1373
- left: groupWidth / 2,
1374
- // 水平居中
1375
- top: y,
1376
- charSpacing: (letterSpace || 0) * 50,
1377
- textAlign: alignType === 1 ? "center" : alignType === 2 ? "right" : "left",
1378
- objectCaching: false
1379
- });
1380
- const fillText = new fabric.fabric.Text(line || " ", {
1381
- fontFamily,
1382
- fontSize: 22,
1383
- fill: textFill,
1384
- stroke: "transparent",
1385
- originX: "center",
1386
- originY: "center",
1387
- strokeWidth: 0,
1388
- left: groupWidth / 2,
1389
- // 水平居中
1390
- top: y,
1391
- charSpacing: (letterSpace || 0) * 50,
1392
- textAlign: alignType === 1 ? "center" : alignType === 2 ? "right" : "left",
1393
- objectCaching: false
1394
- });
1395
- textObjs.push(strokeText, fillText);
1396
- });
1397
- const bgRect = new fabric.fabric.Rect({
1398
- width: groupWidth,
1399
- height: groupHeight,
1400
- fill: bgColor,
1401
- originX: "left",
1402
- originY: "top",
1403
- rx: 5,
1404
- ry: 5,
1405
- left: 0,
1406
- top: 0
1407
- });
1408
1448
  const textBasicInfo = {
1409
1449
  isBack: backgroundColor ? true : false,
1410
1450
  colorValue: textFill,
1411
1451
  colorName: "custom",
1412
1452
  textAlign: alignType === 1 ? "center" : alignType === 2 ? "right" : "left"
1413
1453
  };
1414
- const group = new fabric.fabric.Group([bgRect, ...textObjs], {
1454
+ const { fontFamily, objects } = await createTextObjs({ strokeW, stColor, fontAssetUrl, letterSpace, bgColor, textContent, textBasicInfo, textColor: textFill });
1455
+ const group = new fabric.fabric.Group([...objects], {
1415
1456
  left,
1416
1457
  top,
1417
1458
  scaleX,
@@ -1455,91 +1496,6 @@ var EditorCanvas = react.forwardRef(
1455
1496
  resolve(group);
1456
1497
  });
1457
1498
  };
1458
- const createTextFromClip = async (clip, fc2) => {
1459
- return new Promise(async (resolve) => {
1460
- const canvas = fc || fc2;
1461
- if (!canvas) {
1462
- resolve(null);
1463
- return;
1464
- }
1465
- const { width, height } = vmml.template.dimension;
1466
- const fontSize = vmmlUtils.getFontSize(width, height);
1467
- const { textContent, backgroundColor, textColor, posParam, fontAssetUrl, alignType, strokeColor, strokeWidth, letterSpacing } = clip.textClip;
1468
- const scaleX = posParam.scaleX * fontSize / 22 / widthScaleRef.current;
1469
- const scaleY = posParam.scaleY * fontSize / 22 / heightScaleRef.current;
1470
- const strokeW = strokeWidth * 26 * 1.5 / fontSize;
1471
- const letterSpace = letterSpacing * 22 / fontSize;
1472
- const left = canvasSize.width * posParam.centerX;
1473
- const top = canvasSize.height * posParam.centerY - 2;
1474
- const bgColor = backgroundColor ? vmmlUtils.argbToRgba(backgroundColor) : "transparent";
1475
- const stColor = strokeColor ? vmmlUtils.argbToRgba(strokeColor) : "transparent";
1476
- const isAiError = textContent === "\u8BF7\u8F93\u5165\u6587\u6848" && textColor === "#00000000";
1477
- const textFill = vmmlUtils.argbToRgba(isAiError ? "#ffffffff" : textColor || "#ffffffff");
1478
- const textBasicInfo = {
1479
- isBack: backgroundColor ? true : false,
1480
- colorValue: textFill,
1481
- colorName: "custom",
1482
- textAlign: alignType === 1 ? "center" : alignType === 2 ? "right" : "left"
1483
- };
1484
- const textImgData = await createTextImg({ textContent, bgColor, stColor, strokeW, textColor: textFill, fontAssetUrl, textBasicInfo, letterSpacing: letterSpace });
1485
- const fontJSON = localStorage.getItem("VMML_PLAYER_FONTSMAP");
1486
- let fontMap = {};
1487
- try {
1488
- fontMap = fontJSON ? JSON.parse(fontJSON) : {};
1489
- } catch {
1490
- fontMap = {};
1491
- }
1492
- const fontFamily = fontMap[fontAssetUrl] || "";
1493
- fabric.fabric.Image.fromURL(textImgData.base64Image, (imgData) => {
1494
- imgData.set({
1495
- left,
1496
- top,
1497
- width: textImgData.width,
1498
- height: textImgData.height,
1499
- scaleX,
1500
- scaleY,
1501
- angle: posParam.rotationZ,
1502
- originX: "center",
1503
- originY: "center",
1504
- objectCaching: false,
1505
- clipData: {
1506
- id: clip.id,
1507
- inPoint: clip.inPoint,
1508
- inFrame: vmmlUtils.getFrames(clip.inPoint, 30),
1509
- type: "\u6587\u5B57",
1510
- textColor: textFill,
1511
- text: textContent,
1512
- bgColor,
1513
- originClip: clip,
1514
- fontAssetUrl,
1515
- fontFamily,
1516
- textBasicInfo,
1517
- isAiError,
1518
- duration: clip.duration
1519
- }
1520
- });
1521
- imgData.on("selected", (options) => {
1522
- options.target.isSelected = -1;
1523
- });
1524
- imgData.on("moving", (options) => {
1525
- options.transform.target.isSelected = 0;
1526
- });
1527
- imgData.on("modified", () => {
1528
- const fObj = convertToJSON(imgData);
1529
- if (fObj.clipData.isAiError) {
1530
- fObj.clipData.textColor = "rgba(0, 0, 0, 0)";
1531
- }
1532
- if (isBatchModify) {
1533
- onBatchModify(fObj, canvas);
1534
- } else {
1535
- vmmlConverterRef.current.updateClip(fObj);
1536
- }
1537
- });
1538
- console.log("fabricjs>>>end>>>>>>>>>>>>");
1539
- resolve(imgData);
1540
- });
1541
- });
1542
- };
1543
1499
  const getFontFamilyName = (url) => {
1544
1500
  const filename = url.split("/").pop() || "";
1545
1501
  const name = filename.replace(/\.(ttf|otf|woff2?|eot)$/i, "");
@@ -1708,13 +1664,25 @@ var EditorCanvas = react.forwardRef(
1708
1664
  });
1709
1665
  };
1710
1666
  const updateText = async ({ id, textContent, bgColor, textColor, textBasicInfo, fontAssetUrl }) => {
1711
- const textImgData = await createTextImg({ textContent, bgColor, textColor, fontAssetUrl, textBasicInfo });
1712
- const target = fc.getObjects().find((item) => item.clipData.id === id);
1713
- target.setSrc(textImgData.base64Image, (img) => {
1714
- img.set({
1667
+ var _a;
1668
+ const target = fc.getObjects().find((item) => {
1669
+ var _a2;
1670
+ return ((_a2 = item.clipData) == null ? void 0 : _a2.id) === id;
1671
+ });
1672
+ const center = target.getCenterPoint();
1673
+ const originClip = (_a = target.clipData) == null ? void 0 : _a.originClip;
1674
+ if (originClip && (target == null ? void 0 : target.type) === "group") {
1675
+ const objects = target.getObjects();
1676
+ const strokeText = objects[1];
1677
+ target._objects.length = 0;
1678
+ const { objects: textObjects } = await createTextObjs({ strokeW: strokeText.strokeWidth, stColor: "", fontAssetUrl, letterSpace: strokeText.charSpacing, bgColor, textContent, textBasicInfo, textColor });
1679
+ textObjects.forEach((obj) => {
1680
+ target.addWithUpdate(obj);
1681
+ });
1682
+ target.set({
1715
1683
  visible: true,
1716
1684
  clipData: {
1717
- ...img.clipData,
1685
+ ...target.clipData,
1718
1686
  textBasicInfo,
1719
1687
  textColor,
1720
1688
  text: textContent,
@@ -1722,10 +1690,20 @@ var EditorCanvas = react.forwardRef(
1722
1690
  isAiError: false
1723
1691
  }
1724
1692
  });
1725
- img.setCoords();
1726
- fc.renderAll();
1727
- vmmlConverterRef.current.updateClip(convertToJSON(img));
1728
- });
1693
+ target._calcBounds();
1694
+ target._updateObjectsCoords();
1695
+ target.setPositionByOrigin(center, "center", "center");
1696
+ originClip.textClip = {
1697
+ ...originClip.textClip,
1698
+ textContent,
1699
+ backgroundColor: bgColor,
1700
+ textColor,
1701
+ strokeColor: ""
1702
+ };
1703
+ target.setCoords();
1704
+ fc == null ? void 0 : fc.requestRenderAll();
1705
+ vmmlConverterRef.current.updateClip(convertToJSON(target));
1706
+ }
1729
1707
  };
1730
1708
  const changeObjectVisible = (id, visible = true) => {
1731
1709
  const target = fc.getObjects().find((item) => item.clipData.id === id);
@@ -1749,7 +1727,7 @@ var EditorCanvas = react.forwardRef(
1749
1727
  top: canvasSize.top,
1750
1728
  display: showCanvas ? "block" : "none"
1751
1729
  };
1752
- }, [showCanvas]);
1730
+ }, [showCanvas, canvasSize]);
1753
1731
  react.useEffect(() => {
1754
1732
  if (!fc && canvasSize.width) {
1755
1733
  initCanvas();
@@ -1814,7 +1792,6 @@ var EditorCanvas = react.forwardRef(
1814
1792
  getfcObject,
1815
1793
  checkObjectInPoint,
1816
1794
  createImageFromClip,
1817
- createTextFromClip,
1818
1795
  changeObjectVisible,
1819
1796
  getCanvasCtx
1820
1797
  }), [fc, frame]);
@@ -2597,7 +2574,7 @@ var EditorFn = ({
2597
2574
  pauseWhenBuffering = false,
2598
2575
  isBatchModify = false,
2599
2576
  textWarapCenter = false,
2600
- hideConfig = null
2577
+ hideConfig = { hideDelete: false, hideEdit: false, hideMute: false, hideVolume: false }
2601
2578
  // { hideDelete: false, hideEdit: false, hideMute: false, hideVolume: false }
2602
2579
  }, ref) => {
2603
2580
  var _a;
@@ -2805,6 +2782,10 @@ var EditorFn = ({
2805
2782
  const onPause = () => {
2806
2783
  setShowCanvas(true);
2807
2784
  setIsPlaying(false);
2785
+ if (canvasRef.current) {
2786
+ const { current: canvasC } = canvasRef;
2787
+ canvasC.checkObjectInPoint();
2788
+ }
2808
2789
  };
2809
2790
  const onWaiting = () => {
2810
2791
  var _a2, _b;
@@ -2842,7 +2823,6 @@ var EditorFn = ({
2842
2823
  if (fcTracks.length) {
2843
2824
  const clips = fcTracks.map((item) => item.clips).flat().filter((item) => Reflect.has(item, "fObj"));
2844
2825
  const fObjs = clips.map((item) => item.fObj);
2845
- setInitFcObjs(fObjs);
2846
2826
  fObjs.forEach((item) => {
2847
2827
  onVideoChange(item.clipData);
2848
2828
  });