@versa_ai/vmml-editor 1.0.45 → 1.0.48

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.45 build D:\code\work\vmml-player\packages\editor
2
+ > @versa_ai/vmml-editor@1.0.48 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
- ESM dist\index.mjs 119.17 KB
128
- ESM dist\index.mjs.map 232.29 KB
129
- ESM ⚡️ Build success in 1010ms
130
- CJS dist\index.js 120.97 KB
131
- CJS dist\index.js.map 232.60 KB
132
- CJS ⚡️ Build success in 1012ms
133
- DTS ⚡️ Build success in 2343ms
126
+ DTS Build start
127
+ ESM dist\index.mjs 115.85 KB
128
+ ESM dist\index.mjs.map 225.42 KB
129
+ ESM ⚡️ Build success in 914ms
130
+ CJS dist\index.js 117.63 KB
131
+ CJS dist\index.js.map 225.71 KB
132
+ CJS ⚡️ Build success in 915ms
133
+ DTS ⚡️ Build success in 1983ms
134
134
  DTS dist\index.d.ts 158.00 B
135
135
  DTS dist\index.d.mts 158.00 B
package/README.md CHANGED
@@ -1 +1 @@
1
- # `@versa_ai/vmml-editor`
1
+ # `@versa_ai/vmml-editor`
package/dist/index.js CHANGED
@@ -8,7 +8,6 @@ var remotion = require('remotion');
8
8
  var jsxRuntime = require('react/jsx-runtime');
9
9
  var fabric = require('fabric');
10
10
  var uuid = require('uuid');
11
- var domToImage = require('dom-to-image');
12
11
 
13
12
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
13
 
@@ -1345,6 +1344,8 @@ var EditorCanvas = react.forwardRef(
1345
1344
  window.dispatchEvent(event);
1346
1345
  };
1347
1346
  const createTextObjs = async ({ strokeW, stColor, fontAssetUrl = null, letterSpace, bgColor, textContent, textBasicInfo, textColor }) => {
1347
+ const { width, height } = vmml.template.dimension;
1348
+ const fontSize = vmmlUtils.getFontSize(width, height);
1348
1349
  let fontFamily = "sansMedium";
1349
1350
  if (fontAssetUrl) {
1350
1351
  const base64 = await loadFont(fontAssetUrl);
@@ -1355,7 +1356,9 @@ var EditorCanvas = react.forwardRef(
1355
1356
  }
1356
1357
  const lines = textContent.split("\n").filter((item) => item);
1357
1358
  const lineHeight = 22 + strokeW;
1358
- const paddingX = 7;
1359
+ const paddingX = 60 * 22 / fontSize;
1360
+ const paddingY = 50 * 22 / fontSize;
1361
+ const round = 40 * 22 / fontSize;
1359
1362
  const groupWidth = Math.max(...lines.map((l) => {
1360
1363
  let options = { fontSize: 22, fontFamily, strokeWidth: strokeW ?? 0 };
1361
1364
  if (letterSpace) options.charSpacing = letterSpace;
@@ -1407,13 +1410,13 @@ var EditorCanvas = react.forwardRef(
1407
1410
  });
1408
1411
  const bgRect = new fabric.fabric.Rect({
1409
1412
  width: groupWidth,
1410
- height: groupHeight + 13,
1413
+ height: groupHeight + paddingY * 2,
1411
1414
  // padddingY: 6.5
1412
1415
  fill: bgColor,
1413
1416
  originX: "left",
1414
1417
  originY: "center",
1415
- rx: 5,
1416
- ry: 5
1418
+ rx: round,
1419
+ ry: round
1417
1420
  });
1418
1421
  return {
1419
1422
  objects: [bgRect, ...textObjs],
@@ -1500,25 +1503,6 @@ var EditorCanvas = react.forwardRef(
1500
1503
  if (lower.includes(".ttf")) return "truetype";
1501
1504
  return null;
1502
1505
  };
1503
- const embedFontInSVG = async (svgString, url, fontBase64) => {
1504
- if (url) {
1505
- let res = fontBase64;
1506
- if (!res) await vmmlUtils.urlToBlob({ url });
1507
- const format = detectFontFormat(url);
1508
- const fontFamilyName = getFontFamilyName(url);
1509
- const srcValue = format ? `url('${res}') format('${format}')` : `url('${res}')`;
1510
- const fontFace = `
1511
- @font-face {
1512
- font-family: '${fontFamilyName}';
1513
- src: ${srcValue};
1514
- }
1515
- `;
1516
- const styleElement = `<style type="text/css"><![CDATA[${fontFace}]]></style>`;
1517
- const result = svgString.replace("</svg>", `${styleElement}</svg>`);
1518
- return result;
1519
- }
1520
- return svgString;
1521
- };
1522
1506
  const loadFont = async (url) => {
1523
1507
  if (!url) return null;
1524
1508
  if (fontCacheRef.current.has(url)) {
@@ -1541,117 +1525,50 @@ var EditorCanvas = react.forwardRef(
1541
1525
  fontCacheRef.current.set(url, loadPromise);
1542
1526
  return loadPromise;
1543
1527
  };
1544
- const setTextAlign = (p, stroke, direction) => {
1545
- if (direction === "center") {
1546
- p.style.justifyContent = "center";
1547
- stroke.style.left = "50%";
1548
- stroke.style.top = "50%";
1549
- stroke.style.transform = "translate(-50%, -50%)";
1550
- }
1551
- if (direction === "left") {
1552
- stroke.style.left = "0";
1553
- stroke.style.top = "0";
1554
- stroke.style.transform = "none";
1555
- }
1556
- if (direction === "right") {
1557
- p.style.justifyContent = "flex-end";
1558
- stroke.style.right = "0";
1559
- stroke.style.top = "50%";
1560
- stroke.style.transform = "translateY(-50%)";
1561
- }
1562
- };
1563
- const createTextImg = async ({ textContent, bgColor, textColor, stColor, strokeW, fontAssetUrl = null, textBasicInfo, letterSpacing }) => {
1564
- const fontBase64 = await loadFont(fontAssetUrl);
1565
- const container = document.createElement("div");
1566
- container.style.backgroundColor = bgColor;
1567
- container.style.boxSizing = "content-box";
1568
- container.style.display = "inline-block";
1569
- container.style.textAlign = textBasicInfo.textAlign || "left";
1570
- const lines = textContent.split("\n");
1571
- const fontFamily = fontAssetUrl ? getFontFamilyName(fontAssetUrl) : "sansMedium";
1572
- lines.forEach((line) => {
1573
- const p = document.createElement("p");
1574
- p.style.position = "relative";
1575
- p.style.display = "flex";
1576
- p.style.fontSize = "22px";
1577
- p.style.lineHeight = "22px";
1578
- p.style.fontFamily = fontFamily;
1579
- p.style.whiteSpace = "nowrap";
1580
- p.style.margin = "0";
1581
- p.style.padding = "0";
1582
- if (letterSpacing) p.style.letterSpacing = `${letterSpacing}px`;
1583
- p.style.zIndex = "2";
1584
- const fill = document.createElement("span");
1585
- fill.textContent = line || " ";
1586
- fill.style.color = textColor;
1587
- fill.style.position = "relative";
1588
- fill.style.zIndex = "1";
1589
- const stroke = document.createElement("span");
1590
- stroke.textContent = line || " ";
1591
- stroke.style.position = "absolute";
1592
- stroke.style.color = "transparent";
1593
- stroke.style.webkitTextStrokeWidth = `${strokeW}px`;
1594
- stroke.style.webkitTextStrokeColor = stColor;
1595
- let dr = textBasicInfo.textAlign || "left";
1596
- if (textWarapCenter) dr = "center";
1597
- setTextAlign(p, stroke, dr);
1598
- p.appendChild(fill);
1599
- p.appendChild(stroke);
1600
- container.appendChild(p);
1601
- });
1602
- container.style.padding = "6.5px 7px 6.5px 7px";
1603
- container.style.borderRadius = "5px";
1604
- document.body.appendChild(container);
1605
- const { width, height } = container == null ? void 0 : container.getBoundingClientRect();
1606
- const dataurl = await domToImage.toSvg(container);
1607
- document.body.removeChild(container);
1608
- const base64Image = await embedFontInSVG(dataurl, fontAssetUrl, fontBase64);
1609
- return { base64Image, height, width };
1610
- };
1611
1528
  const createText = async ({ textContent, bgColor, textColor, position, textBasicInfo, id }, fc2) => {
1612
1529
  const canvas = fc || fc2;
1613
1530
  const { left, top, angle, scaleX, scaleY, zoomX, zoomY } = position;
1614
- const textImgData = await createTextImg({ textContent, bgColor, textColor, textBasicInfo });
1531
+ const { objects } = await createTextObjs({ strokeW: 0, stColor: "", fontAssetUrl: null, letterSpace: 0, bgColor, textContent, textBasicInfo, textColor });
1615
1532
  return new Promise((resolve, reject) => {
1616
- fabric.fabric.Image.fromURL(textImgData.base64Image, (imgData) => {
1617
- imgData.set({
1618
- left,
1619
- top,
1620
- angle,
1621
- width: textImgData.width,
1622
- height: textImgData.height,
1623
- scaleX,
1624
- scaleY,
1625
- clipData: {
1626
- id: uuid.v4(),
1627
- inPoint: Math.floor(frame / 30 * 1e6),
1628
- inFrame: frame,
1629
- type: "\u6587\u5B57",
1630
- textBasicInfo,
1631
- textColor,
1632
- text: textContent,
1633
- bgColor
1634
- }
1635
- });
1636
- imgData.on("selected", (options) => {
1637
- options.target.isSelected = -1;
1638
- });
1639
- imgData.on("moving", (options) => {
1640
- options.transform.target.isSelected = 0;
1641
- });
1642
- imgData.on("modified", () => {
1643
- const fObj = convertToJSON(imgData);
1644
- vmmlConverterRef.current.updateClip(fObj);
1645
- });
1646
- canvas.centerObject(imgData);
1647
- canvas.add(imgData);
1648
- setTimeout(() => {
1649
- canvas.renderAll();
1650
- });
1651
- onVideoChange(imgData.clipData);
1652
- vmmlConverterRef.current.addTextClip(convertToJSON(imgData));
1653
- resolve(true);
1533
+ const group = new fabric.fabric.Group([...objects], {
1534
+ left,
1535
+ top,
1536
+ scaleX,
1537
+ scaleY,
1538
+ angle,
1539
+ originX: "center",
1540
+ originY: "center",
1541
+ clipData: {
1542
+ duration: vmmlConverterRef.current.vmml.template.duration,
1543
+ id: uuid.v4(),
1544
+ inPoint: Math.floor(frame / 30 * 1e6),
1545
+ inFrame: frame,
1546
+ type: "\u6587\u5B57",
1547
+ textBasicInfo,
1548
+ textColor,
1549
+ text: textContent,
1550
+ bgColor,
1551
+ visible: true
1552
+ }
1553
+ });
1554
+ group.on("selected", (options) => {
1555
+ options.target.isSelected = -1;
1556
+ });
1557
+ group.on("moving", (options) => {
1558
+ options.transform.target.isSelected = 0;
1559
+ });
1560
+ group.on("modified", () => {
1561
+ const fObj = convertToJSON(group);
1562
+ vmmlConverterRef.current.updateClip(fObj);
1563
+ });
1564
+ canvas.centerObject(group);
1565
+ canvas.add(group);
1566
+ setTimeout(() => {
1567
+ canvas.renderAll();
1654
1568
  });
1569
+ onVideoChange((group == null ? void 0 : group.clipData) ?? null);
1570
+ vmmlConverterRef.current.addTextClip(convertToJSON(group));
1571
+ resolve(true);
1655
1572
  });
1656
1573
  };
1657
1574
  const updateText = async ({ id, textContent, bgColor, textColor, textBasicInfo, fontAssetUrl }) => {
@@ -2859,7 +2776,7 @@ var EditorFn = ({
2859
2776
  if (editableArray.length && (vmmlState == null ? void 0 : vmmlState.template)) {
2860
2777
  initCanEditClips(vmmlState.template.tracks);
2861
2778
  }
2862
- }, [editableArray, refreshEdit, vmmlState]);
2779
+ }, [editableArray, vmmlState]);
2863
2780
  react.useEffect(() => {
2864
2781
  if (vmmlState) {
2865
2782
  initFcObjects(vmmlState.template.tracks);