@versa_ai/vmml-editor 1.0.44 → 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 -138
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -138
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/components/EditorCanvas.tsx +44 -137
- package/src/index.tsx +2 -2
- package/src/utils/VmmlConverter.ts +6 -10
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @versa_ai/vmml-editor@1.0.
|
|
2
|
+
> @versa_ai/vmml-editor@1.0.47 build D:\code\work\vmml-player\packages\editor
|
|
3
3
|
> tsup
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.tsx
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
[34mCLI[39m Target: node16
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
11
|
[34mESM[39m Build start
|
|
12
|
+
[34mDTS[39m Build start
|
|
12
13
|
|
|
13
14
|
[43m[30m WARN [39m[49m [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mUsing / 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[0m [1m[35
|
|
|
66
67
|
|
|
67
68
|
|
|
68
69
|
|
|
69
|
-
[34mDTS[39m Build start
|
|
70
70
|
|
|
71
71
|
[43m[30m WARN [39m[49m [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mUsing / 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[0m [1m[35
|
|
|
124
124
|
|
|
125
125
|
|
|
126
126
|
|
|
127
|
-
[
|
|
128
|
-
[
|
|
129
|
-
[
|
|
130
|
-
[
|
|
131
|
-
[
|
|
132
|
-
[
|
|
133
|
-
[32mDTS[39m ⚡️ Build success in
|
|
127
|
+
[32mESM[39m [1mdist\index.mjs [22m[32m115.63 KB[39m
|
|
128
|
+
[32mESM[39m [1mdist\index.mjs.map [22m[32m224.90 KB[39m
|
|
129
|
+
[32mESM[39m ⚡️ Build success in 918ms
|
|
130
|
+
[32mCJS[39m [1mdist\index.js [22m[32m117.40 KB[39m
|
|
131
|
+
[32mCJS[39m [1mdist\index.js.map [22m[32m225.19 KB[39m
|
|
132
|
+
[32mCJS[39m ⚡️ Build success in 918ms
|
|
133
|
+
[32mDTS[39m ⚡️ Build success in 2182ms
|
|
134
134
|
[32mDTS[39m [1mdist\index.d.ts [22m[32m158.00 B[39m
|
|
135
135
|
[32mDTS[39m [1mdist\index.d.mts [22m[32m158.00 B[39m
|
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
|
|
|
@@ -641,7 +640,6 @@ var VmmlConverter = class {
|
|
|
641
640
|
* @param fObj - 画布fObj
|
|
642
641
|
*/
|
|
643
642
|
addTextClip(fObj) {
|
|
644
|
-
console.log("addTextClip fObj", fObj);
|
|
645
643
|
const posParam = this.setPosParam(fObj);
|
|
646
644
|
const { clipData: { id, inPoint, text, textColor, bgColor } } = fObj;
|
|
647
645
|
const { template: { duration } } = this.vmml;
|
|
@@ -684,14 +682,12 @@ var VmmlConverter = class {
|
|
|
684
682
|
} else {
|
|
685
683
|
editorTrack.clips.push(tClipData);
|
|
686
684
|
}
|
|
687
|
-
console.log("addTextClip \u6700\u7EC8vmml", this.vmml);
|
|
688
685
|
}
|
|
689
686
|
/**
|
|
690
687
|
* 转换 VideoClip
|
|
691
688
|
* @param fObj - 画布fObj
|
|
692
689
|
*/
|
|
693
690
|
addVideoClip(fObj) {
|
|
694
|
-
console.log("addVideoClip fObj", fObj);
|
|
695
691
|
const clips = [];
|
|
696
692
|
const editorTrack = this.tracks.find((track) => track.editorType === "\u8868\u60C5\u5305");
|
|
697
693
|
const clipData = this.loadClipData(fObj);
|
|
@@ -721,14 +717,12 @@ var VmmlConverter = class {
|
|
|
721
717
|
}
|
|
722
718
|
}
|
|
723
719
|
}
|
|
724
|
-
console.log("addVideoClip \u6700\u7EC8vmml", this.vmml);
|
|
725
720
|
}
|
|
726
721
|
/**
|
|
727
722
|
* 更新 clip
|
|
728
723
|
* @param fObj - 画布fObj
|
|
729
724
|
*/
|
|
730
725
|
updateClip(fObj) {
|
|
731
|
-
console.log("updateClip fObj", fObj, this.tracks);
|
|
732
726
|
const posParam = this.setPosParam(fObj);
|
|
733
727
|
const {
|
|
734
728
|
clipData: { id, type, lineSpacing, originClip }
|
|
@@ -756,7 +750,6 @@ var VmmlConverter = class {
|
|
|
756
750
|
}
|
|
757
751
|
}
|
|
758
752
|
updateTextClip(fObj, duration) {
|
|
759
|
-
console.log("updateClip fObj", fObj, this.tracks);
|
|
760
753
|
const posParam = this.setPosParam(fObj);
|
|
761
754
|
const {
|
|
762
755
|
clipData: { id }
|
|
@@ -766,7 +759,6 @@ var VmmlConverter = class {
|
|
|
766
759
|
const { clipData: { text, textColor, bgColor } } = fObj;
|
|
767
760
|
const scale = this.fontSize / 22;
|
|
768
761
|
existClip.duration = duration;
|
|
769
|
-
console.log(bgColor, "bgColor>>>");
|
|
770
762
|
existClip.textClip = {
|
|
771
763
|
...existClip.textClip,
|
|
772
764
|
posParam,
|
|
@@ -779,7 +771,6 @@ var VmmlConverter = class {
|
|
|
779
771
|
}
|
|
780
772
|
};
|
|
781
773
|
}
|
|
782
|
-
console.log(this.vmml, "updateText>>>");
|
|
783
774
|
}
|
|
784
775
|
/**
|
|
785
776
|
* 删除 Clip
|
|
@@ -807,7 +798,6 @@ var VmmlConverter = class {
|
|
|
807
798
|
}
|
|
808
799
|
}
|
|
809
800
|
}
|
|
810
|
-
console.log("\u5220\u9664\u4E4B\u540E\u7684vmml", this.vmml);
|
|
811
801
|
}
|
|
812
802
|
changeVmml(newVmml) {
|
|
813
803
|
this.vmml = newVmml;
|
|
@@ -824,7 +814,6 @@ var VmmlConverter = class {
|
|
|
824
814
|
editorTrack.clips[index + 1].audioClip.volume = volume;
|
|
825
815
|
}
|
|
826
816
|
}
|
|
827
|
-
console.log("changeMute \u6700\u7EC8Vmml", this.vmml);
|
|
828
817
|
}
|
|
829
818
|
//加载clip数据
|
|
830
819
|
loadClipData(fObj) {
|
|
@@ -1510,25 +1499,6 @@ var EditorCanvas = react.forwardRef(
|
|
|
1510
1499
|
if (lower.includes(".ttf")) return "truetype";
|
|
1511
1500
|
return null;
|
|
1512
1501
|
};
|
|
1513
|
-
const embedFontInSVG = async (svgString, url, fontBase64) => {
|
|
1514
|
-
if (url) {
|
|
1515
|
-
let res = fontBase64;
|
|
1516
|
-
if (!res) await vmmlUtils.urlToBlob({ url });
|
|
1517
|
-
const format = detectFontFormat(url);
|
|
1518
|
-
const fontFamilyName = getFontFamilyName(url);
|
|
1519
|
-
const srcValue = format ? `url('${res}') format('${format}')` : `url('${res}')`;
|
|
1520
|
-
const fontFace = `
|
|
1521
|
-
@font-face {
|
|
1522
|
-
font-family: '${fontFamilyName}';
|
|
1523
|
-
src: ${srcValue};
|
|
1524
|
-
}
|
|
1525
|
-
`;
|
|
1526
|
-
const styleElement = `<style type="text/css"><![CDATA[${fontFace}]]></style>`;
|
|
1527
|
-
const result = svgString.replace("</svg>", `${styleElement}</svg>`);
|
|
1528
|
-
return result;
|
|
1529
|
-
}
|
|
1530
|
-
return svgString;
|
|
1531
|
-
};
|
|
1532
1502
|
const loadFont = async (url) => {
|
|
1533
1503
|
if (!url) return null;
|
|
1534
1504
|
if (fontCacheRef.current.has(url)) {
|
|
@@ -1551,117 +1521,50 @@ var EditorCanvas = react.forwardRef(
|
|
|
1551
1521
|
fontCacheRef.current.set(url, loadPromise);
|
|
1552
1522
|
return loadPromise;
|
|
1553
1523
|
};
|
|
1554
|
-
const setTextAlign = (p, stroke, direction) => {
|
|
1555
|
-
if (direction === "center") {
|
|
1556
|
-
p.style.justifyContent = "center";
|
|
1557
|
-
stroke.style.left = "50%";
|
|
1558
|
-
stroke.style.top = "50%";
|
|
1559
|
-
stroke.style.transform = "translate(-50%, -50%)";
|
|
1560
|
-
}
|
|
1561
|
-
if (direction === "left") {
|
|
1562
|
-
stroke.style.left = "0";
|
|
1563
|
-
stroke.style.top = "0";
|
|
1564
|
-
stroke.style.transform = "none";
|
|
1565
|
-
}
|
|
1566
|
-
if (direction === "right") {
|
|
1567
|
-
p.style.justifyContent = "flex-end";
|
|
1568
|
-
stroke.style.right = "0";
|
|
1569
|
-
stroke.style.top = "50%";
|
|
1570
|
-
stroke.style.transform = "translateY(-50%)";
|
|
1571
|
-
}
|
|
1572
|
-
};
|
|
1573
|
-
const createTextImg = async ({ textContent, bgColor, textColor, stColor, strokeW, fontAssetUrl = null, textBasicInfo, letterSpacing }) => {
|
|
1574
|
-
const fontBase64 = await loadFont(fontAssetUrl);
|
|
1575
|
-
const container = document.createElement("div");
|
|
1576
|
-
container.style.backgroundColor = bgColor;
|
|
1577
|
-
container.style.boxSizing = "content-box";
|
|
1578
|
-
container.style.display = "inline-block";
|
|
1579
|
-
container.style.textAlign = textBasicInfo.textAlign || "left";
|
|
1580
|
-
const lines = textContent.split("\n");
|
|
1581
|
-
const fontFamily = fontAssetUrl ? getFontFamilyName(fontAssetUrl) : "sansMedium";
|
|
1582
|
-
lines.forEach((line) => {
|
|
1583
|
-
const p = document.createElement("p");
|
|
1584
|
-
p.style.position = "relative";
|
|
1585
|
-
p.style.display = "flex";
|
|
1586
|
-
p.style.fontSize = "22px";
|
|
1587
|
-
p.style.lineHeight = "22px";
|
|
1588
|
-
p.style.fontFamily = fontFamily;
|
|
1589
|
-
p.style.whiteSpace = "nowrap";
|
|
1590
|
-
p.style.margin = "0";
|
|
1591
|
-
p.style.padding = "0";
|
|
1592
|
-
if (letterSpacing) p.style.letterSpacing = `${letterSpacing}px`;
|
|
1593
|
-
p.style.zIndex = "2";
|
|
1594
|
-
const fill = document.createElement("span");
|
|
1595
|
-
fill.textContent = line || " ";
|
|
1596
|
-
fill.style.color = textColor;
|
|
1597
|
-
fill.style.position = "relative";
|
|
1598
|
-
fill.style.zIndex = "1";
|
|
1599
|
-
const stroke = document.createElement("span");
|
|
1600
|
-
stroke.textContent = line || " ";
|
|
1601
|
-
stroke.style.position = "absolute";
|
|
1602
|
-
stroke.style.color = "transparent";
|
|
1603
|
-
stroke.style.webkitTextStrokeWidth = `${strokeW}px`;
|
|
1604
|
-
stroke.style.webkitTextStrokeColor = stColor;
|
|
1605
|
-
let dr = textBasicInfo.textAlign || "left";
|
|
1606
|
-
if (textWarapCenter) dr = "center";
|
|
1607
|
-
setTextAlign(p, stroke, dr);
|
|
1608
|
-
p.appendChild(fill);
|
|
1609
|
-
p.appendChild(stroke);
|
|
1610
|
-
container.appendChild(p);
|
|
1611
|
-
});
|
|
1612
|
-
container.style.padding = "6.5px 7px 6.5px 7px";
|
|
1613
|
-
container.style.borderRadius = "5px";
|
|
1614
|
-
document.body.appendChild(container);
|
|
1615
|
-
const { width, height } = container == null ? void 0 : container.getBoundingClientRect();
|
|
1616
|
-
const dataurl = await domToImage.toSvg(container);
|
|
1617
|
-
document.body.removeChild(container);
|
|
1618
|
-
const base64Image = await embedFontInSVG(dataurl, fontAssetUrl, fontBase64);
|
|
1619
|
-
return { base64Image, height, width };
|
|
1620
|
-
};
|
|
1621
1524
|
const createText = async ({ textContent, bgColor, textColor, position, textBasicInfo, id }, fc2) => {
|
|
1622
1525
|
const canvas = fc || fc2;
|
|
1623
1526
|
const { left, top, angle, scaleX, scaleY, zoomX, zoomY } = position;
|
|
1624
|
-
const
|
|
1527
|
+
const { objects } = await createTextObjs({ strokeW: 0, stColor: "", fontAssetUrl: null, letterSpace: 0, bgColor, textContent, textBasicInfo, textColor });
|
|
1625
1528
|
return new Promise((resolve, reject) => {
|
|
1626
|
-
fabric.fabric.
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
onVideoChange(imgData.clipData);
|
|
1662
|
-
vmmlConverterRef.current.addTextClip(convertToJSON(imgData));
|
|
1663
|
-
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();
|
|
1664
1564
|
});
|
|
1565
|
+
onVideoChange((group == null ? void 0 : group.clipData) ?? null);
|
|
1566
|
+
vmmlConverterRef.current.addTextClip(convertToJSON(group));
|
|
1567
|
+
resolve(true);
|
|
1665
1568
|
});
|
|
1666
1569
|
};
|
|
1667
1570
|
const updateText = async ({ id, textContent, bgColor, textColor, textBasicInfo, fontAssetUrl }) => {
|
|
@@ -2869,7 +2772,7 @@ var EditorFn = ({
|
|
|
2869
2772
|
if (editableArray.length && (vmmlState == null ? void 0 : vmmlState.template)) {
|
|
2870
2773
|
initCanEditClips(vmmlState.template.tracks);
|
|
2871
2774
|
}
|
|
2872
|
-
}, [editableArray,
|
|
2775
|
+
}, [editableArray, vmmlState]);
|
|
2873
2776
|
react.useEffect(() => {
|
|
2874
2777
|
if (vmmlState) {
|
|
2875
2778
|
initFcObjects(vmmlState.template.tracks);
|
|
@@ -2928,7 +2831,6 @@ var EditorFn = ({
|
|
|
2928
2831
|
setFrame(currentFrame);
|
|
2929
2832
|
const convertedVmml = v;
|
|
2930
2833
|
const isSame = JSON.stringify(convertedVmml) == JSON.stringify(vmmlState);
|
|
2931
|
-
console.log(isSame, "isSamew>>>");
|
|
2932
2834
|
if (!isSame) {
|
|
2933
2835
|
const currentV = cloneDeep__default.default(convertedVmml);
|
|
2934
2836
|
(_e = (_d = canvasCurrent == null ? void 0 : canvasCurrent.getCanvasCtx()) == null ? void 0 : _d.clear) == null ? void 0 : _e.call(_d);
|