@versa_ai/vmml-editor 1.0.45 → 1.0.47

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.47 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
 
@@ -66,7 +67,6 @@ More info and automated migrator: https://sass-lang.com/d/slash-div [35
66
67
 
67
68
 
68
69
 
69
- DTS Build start
70
70
 
71
71
   WARN  ▲ [WARNING] Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.
72
72
 
@@ -124,12 +124,12 @@ More info and automated migrator: https://sass-lang.com/d/slash-div [35
124
124
 
125
125
 
126
126
 
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
127
+ ESM dist\index.mjs 115.63 KB
128
+ ESM dist\index.mjs.map 224.90 KB
129
+ ESM ⚡️ Build success in 918ms
130
+ CJS dist\index.js 117.40 KB
131
+ CJS dist\index.js.map 225.19 KB
132
+ CJS ⚡️ Build success in 918ms
133
+ DTS ⚡️ Build success in 2182ms
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
@@ -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
 
@@ -1500,25 +1499,6 @@ var EditorCanvas = react.forwardRef(
1500
1499
  if (lower.includes(".ttf")) return "truetype";
1501
1500
  return null;
1502
1501
  };
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
1502
  const loadFont = async (url) => {
1523
1503
  if (!url) return null;
1524
1504
  if (fontCacheRef.current.has(url)) {
@@ -1541,117 +1521,50 @@ var EditorCanvas = react.forwardRef(
1541
1521
  fontCacheRef.current.set(url, loadPromise);
1542
1522
  return loadPromise;
1543
1523
  };
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
1524
  const createText = async ({ textContent, bgColor, textColor, position, textBasicInfo, id }, fc2) => {
1612
1525
  const canvas = fc || fc2;
1613
1526
  const { left, top, angle, scaleX, scaleY, zoomX, zoomY } = position;
1614
- const textImgData = await createTextImg({ textContent, bgColor, textColor, textBasicInfo });
1527
+ const { objects } = await createTextObjs({ strokeW: 0, stColor: "", fontAssetUrl: null, letterSpace: 0, bgColor, textContent, textBasicInfo, textColor });
1615
1528
  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);
1529
+ const group = new fabric.fabric.Group([...objects], {
1530
+ left,
1531
+ top,
1532
+ scaleX,
1533
+ scaleY,
1534
+ angle,
1535
+ originX: "center",
1536
+ originY: "center",
1537
+ clipData: {
1538
+ duration: vmmlConverterRef.current.vmml.template.duration,
1539
+ id: uuid.v4(),
1540
+ inPoint: Math.floor(frame / 30 * 1e6),
1541
+ inFrame: frame,
1542
+ type: "\u6587\u5B57",
1543
+ textBasicInfo,
1544
+ textColor,
1545
+ text: textContent,
1546
+ bgColor,
1547
+ visible: true
1548
+ }
1549
+ });
1550
+ group.on("selected", (options) => {
1551
+ options.target.isSelected = -1;
1552
+ });
1553
+ group.on("moving", (options) => {
1554
+ options.transform.target.isSelected = 0;
1555
+ });
1556
+ group.on("modified", () => {
1557
+ const fObj = convertToJSON(group);
1558
+ vmmlConverterRef.current.updateClip(fObj);
1559
+ });
1560
+ canvas.centerObject(group);
1561
+ canvas.add(group);
1562
+ setTimeout(() => {
1563
+ canvas.renderAll();
1654
1564
  });
1565
+ onVideoChange((group == null ? void 0 : group.clipData) ?? null);
1566
+ vmmlConverterRef.current.addTextClip(convertToJSON(group));
1567
+ resolve(true);
1655
1568
  });
1656
1569
  };
1657
1570
  const updateText = async ({ id, textContent, bgColor, textColor, textBasicInfo, fontAssetUrl }) => {
@@ -2859,7 +2772,7 @@ var EditorFn = ({
2859
2772
  if (editableArray.length && (vmmlState == null ? void 0 : vmmlState.template)) {
2860
2773
  initCanEditClips(vmmlState.template.tracks);
2861
2774
  }
2862
- }, [editableArray, refreshEdit, vmmlState]);
2775
+ }, [editableArray, vmmlState]);
2863
2776
  react.useEffect(() => {
2864
2777
  if (vmmlState) {
2865
2778
  initFcObjects(vmmlState.template.tracks);