@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.
- package/.turbo/turbo-build.log +9 -9
- package/dist/index.js +40 -127
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -127
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/components/EditorCanvas.tsx +44 -137
- package/src/index.tsx +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,6 @@ import { interpolate } from 'remotion';
|
|
|
6
6
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
7
|
import { fabric } from 'fabric';
|
|
8
8
|
import { v4 } from 'uuid';
|
|
9
|
-
import { toSvg } from 'dom-to-image';
|
|
10
9
|
|
|
11
10
|
// src/index.tsx
|
|
12
11
|
|
|
@@ -1494,25 +1493,6 @@ var EditorCanvas = forwardRef(
|
|
|
1494
1493
|
if (lower.includes(".ttf")) return "truetype";
|
|
1495
1494
|
return null;
|
|
1496
1495
|
};
|
|
1497
|
-
const embedFontInSVG = async (svgString, url, fontBase64) => {
|
|
1498
|
-
if (url) {
|
|
1499
|
-
let res = fontBase64;
|
|
1500
|
-
if (!res) await urlToBlob({ url });
|
|
1501
|
-
const format = detectFontFormat(url);
|
|
1502
|
-
const fontFamilyName = getFontFamilyName(url);
|
|
1503
|
-
const srcValue = format ? `url('${res}') format('${format}')` : `url('${res}')`;
|
|
1504
|
-
const fontFace = `
|
|
1505
|
-
@font-face {
|
|
1506
|
-
font-family: '${fontFamilyName}';
|
|
1507
|
-
src: ${srcValue};
|
|
1508
|
-
}
|
|
1509
|
-
`;
|
|
1510
|
-
const styleElement = `<style type="text/css"><![CDATA[${fontFace}]]></style>`;
|
|
1511
|
-
const result = svgString.replace("</svg>", `${styleElement}</svg>`);
|
|
1512
|
-
return result;
|
|
1513
|
-
}
|
|
1514
|
-
return svgString;
|
|
1515
|
-
};
|
|
1516
1496
|
const loadFont = async (url) => {
|
|
1517
1497
|
if (!url) return null;
|
|
1518
1498
|
if (fontCacheRef.current.has(url)) {
|
|
@@ -1535,117 +1515,50 @@ var EditorCanvas = forwardRef(
|
|
|
1535
1515
|
fontCacheRef.current.set(url, loadPromise);
|
|
1536
1516
|
return loadPromise;
|
|
1537
1517
|
};
|
|
1538
|
-
const setTextAlign = (p, stroke, direction) => {
|
|
1539
|
-
if (direction === "center") {
|
|
1540
|
-
p.style.justifyContent = "center";
|
|
1541
|
-
stroke.style.left = "50%";
|
|
1542
|
-
stroke.style.top = "50%";
|
|
1543
|
-
stroke.style.transform = "translate(-50%, -50%)";
|
|
1544
|
-
}
|
|
1545
|
-
if (direction === "left") {
|
|
1546
|
-
stroke.style.left = "0";
|
|
1547
|
-
stroke.style.top = "0";
|
|
1548
|
-
stroke.style.transform = "none";
|
|
1549
|
-
}
|
|
1550
|
-
if (direction === "right") {
|
|
1551
|
-
p.style.justifyContent = "flex-end";
|
|
1552
|
-
stroke.style.right = "0";
|
|
1553
|
-
stroke.style.top = "50%";
|
|
1554
|
-
stroke.style.transform = "translateY(-50%)";
|
|
1555
|
-
}
|
|
1556
|
-
};
|
|
1557
|
-
const createTextImg = async ({ textContent, bgColor, textColor, stColor, strokeW, fontAssetUrl = null, textBasicInfo, letterSpacing }) => {
|
|
1558
|
-
const fontBase64 = await loadFont(fontAssetUrl);
|
|
1559
|
-
const container = document.createElement("div");
|
|
1560
|
-
container.style.backgroundColor = bgColor;
|
|
1561
|
-
container.style.boxSizing = "content-box";
|
|
1562
|
-
container.style.display = "inline-block";
|
|
1563
|
-
container.style.textAlign = textBasicInfo.textAlign || "left";
|
|
1564
|
-
const lines = textContent.split("\n");
|
|
1565
|
-
const fontFamily = fontAssetUrl ? getFontFamilyName(fontAssetUrl) : "sansMedium";
|
|
1566
|
-
lines.forEach((line) => {
|
|
1567
|
-
const p = document.createElement("p");
|
|
1568
|
-
p.style.position = "relative";
|
|
1569
|
-
p.style.display = "flex";
|
|
1570
|
-
p.style.fontSize = "22px";
|
|
1571
|
-
p.style.lineHeight = "22px";
|
|
1572
|
-
p.style.fontFamily = fontFamily;
|
|
1573
|
-
p.style.whiteSpace = "nowrap";
|
|
1574
|
-
p.style.margin = "0";
|
|
1575
|
-
p.style.padding = "0";
|
|
1576
|
-
if (letterSpacing) p.style.letterSpacing = `${letterSpacing}px`;
|
|
1577
|
-
p.style.zIndex = "2";
|
|
1578
|
-
const fill = document.createElement("span");
|
|
1579
|
-
fill.textContent = line || " ";
|
|
1580
|
-
fill.style.color = textColor;
|
|
1581
|
-
fill.style.position = "relative";
|
|
1582
|
-
fill.style.zIndex = "1";
|
|
1583
|
-
const stroke = document.createElement("span");
|
|
1584
|
-
stroke.textContent = line || " ";
|
|
1585
|
-
stroke.style.position = "absolute";
|
|
1586
|
-
stroke.style.color = "transparent";
|
|
1587
|
-
stroke.style.webkitTextStrokeWidth = `${strokeW}px`;
|
|
1588
|
-
stroke.style.webkitTextStrokeColor = stColor;
|
|
1589
|
-
let dr = textBasicInfo.textAlign || "left";
|
|
1590
|
-
if (textWarapCenter) dr = "center";
|
|
1591
|
-
setTextAlign(p, stroke, dr);
|
|
1592
|
-
p.appendChild(fill);
|
|
1593
|
-
p.appendChild(stroke);
|
|
1594
|
-
container.appendChild(p);
|
|
1595
|
-
});
|
|
1596
|
-
container.style.padding = "6.5px 7px 6.5px 7px";
|
|
1597
|
-
container.style.borderRadius = "5px";
|
|
1598
|
-
document.body.appendChild(container);
|
|
1599
|
-
const { width, height } = container == null ? void 0 : container.getBoundingClientRect();
|
|
1600
|
-
const dataurl = await toSvg(container);
|
|
1601
|
-
document.body.removeChild(container);
|
|
1602
|
-
const base64Image = await embedFontInSVG(dataurl, fontAssetUrl, fontBase64);
|
|
1603
|
-
return { base64Image, height, width };
|
|
1604
|
-
};
|
|
1605
1518
|
const createText = async ({ textContent, bgColor, textColor, position, textBasicInfo, id }, fc2) => {
|
|
1606
1519
|
const canvas = fc || fc2;
|
|
1607
1520
|
const { left, top, angle, scaleX, scaleY, zoomX, zoomY } = position;
|
|
1608
|
-
const
|
|
1521
|
+
const { objects } = await createTextObjs({ strokeW: 0, stColor: "", fontAssetUrl: null, letterSpace: 0, bgColor, textContent, textBasicInfo, textColor });
|
|
1609
1522
|
return new Promise((resolve, reject) => {
|
|
1610
|
-
fabric.
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
onVideoChange(imgData.clipData);
|
|
1646
|
-
vmmlConverterRef.current.addTextClip(convertToJSON(imgData));
|
|
1647
|
-
resolve(true);
|
|
1523
|
+
const group = new fabric.Group([...objects], {
|
|
1524
|
+
left,
|
|
1525
|
+
top,
|
|
1526
|
+
scaleX,
|
|
1527
|
+
scaleY,
|
|
1528
|
+
angle,
|
|
1529
|
+
originX: "center",
|
|
1530
|
+
originY: "center",
|
|
1531
|
+
clipData: {
|
|
1532
|
+
duration: vmmlConverterRef.current.vmml.template.duration,
|
|
1533
|
+
id: v4(),
|
|
1534
|
+
inPoint: Math.floor(frame / 30 * 1e6),
|
|
1535
|
+
inFrame: frame,
|
|
1536
|
+
type: "\u6587\u5B57",
|
|
1537
|
+
textBasicInfo,
|
|
1538
|
+
textColor,
|
|
1539
|
+
text: textContent,
|
|
1540
|
+
bgColor,
|
|
1541
|
+
visible: true
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
1544
|
+
group.on("selected", (options) => {
|
|
1545
|
+
options.target.isSelected = -1;
|
|
1546
|
+
});
|
|
1547
|
+
group.on("moving", (options) => {
|
|
1548
|
+
options.transform.target.isSelected = 0;
|
|
1549
|
+
});
|
|
1550
|
+
group.on("modified", () => {
|
|
1551
|
+
const fObj = convertToJSON(group);
|
|
1552
|
+
vmmlConverterRef.current.updateClip(fObj);
|
|
1553
|
+
});
|
|
1554
|
+
canvas.centerObject(group);
|
|
1555
|
+
canvas.add(group);
|
|
1556
|
+
setTimeout(() => {
|
|
1557
|
+
canvas.renderAll();
|
|
1648
1558
|
});
|
|
1559
|
+
onVideoChange((group == null ? void 0 : group.clipData) ?? null);
|
|
1560
|
+
vmmlConverterRef.current.addTextClip(convertToJSON(group));
|
|
1561
|
+
resolve(true);
|
|
1649
1562
|
});
|
|
1650
1563
|
};
|
|
1651
1564
|
const updateText = async ({ id, textContent, bgColor, textColor, textBasicInfo, fontAssetUrl }) => {
|
|
@@ -2853,7 +2766,7 @@ var EditorFn = ({
|
|
|
2853
2766
|
if (editableArray.length && (vmmlState == null ? void 0 : vmmlState.template)) {
|
|
2854
2767
|
initCanEditClips(vmmlState.template.tracks);
|
|
2855
2768
|
}
|
|
2856
|
-
}, [editableArray,
|
|
2769
|
+
}, [editableArray, vmmlState]);
|
|
2857
2770
|
useEffect(() => {
|
|
2858
2771
|
if (vmmlState) {
|
|
2859
2772
|
initFcObjects(vmmlState.template.tracks);
|