@versa_ai/vmml-editor 1.0.15 → 1.0.16
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 +8 -8
- package/dist/index.js +120 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +120 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/EditorCanvas.tsx +145 -95
- package/src/index.tsx +74 -46
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.16 build D:\code\work\vmml-player\packages\editor
|
|
3
3
|
> tsup
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.tsx
|
|
@@ -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[32m111.04 KB[39m
|
|
128
|
+
[32mESM[39m [1mdist\index.mjs.map [22m[32m213.31 KB[39m
|
|
129
|
+
[32mESM[39m ⚡️ Build success in 1139ms
|
|
130
|
+
[32mCJS[39m [1mdist\index.js [22m[32m112.66 KB[39m
|
|
131
|
+
[32mCJS[39m [1mdist\index.js.map [22m[32m213.61 KB[39m
|
|
132
|
+
[32mCJS[39m ⚡️ Build success in 1141ms
|
|
133
|
+
[32mDTS[39m ⚡️ Build success in 2678ms
|
|
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
|
@@ -1000,9 +1000,11 @@ function usePeekControl(canvas, hideConfig) {
|
|
|
1000
1000
|
return canvas;
|
|
1001
1001
|
}
|
|
1002
1002
|
var EditorCanvas = react.forwardRef(
|
|
1003
|
-
({ previewState, showCanvas, canvasSize, enterPreview, intoTextEdit, frame, vmml, dragState, initFcObjs, onVideoChange, isBatchModify, hideConfig }, ref) => {
|
|
1003
|
+
({ previewState, showCanvas, canvasSize, enterPreview, intoTextEdit, frame, vmml, dragState, initFcObjs, editClips = [], onVideoChange, isBatchModify, hideConfig }, ref) => {
|
|
1004
1004
|
const [fc, setFc] = react.useState(null);
|
|
1005
1005
|
const [history, setHistory] = react.useState(null);
|
|
1006
|
+
const [canvasReady, setCanvasReady] = react.useState(false);
|
|
1007
|
+
const editRenderTime = react.useRef(0);
|
|
1006
1008
|
const waitFcTasks = react.useRef([]);
|
|
1007
1009
|
const vmmlConverterRef = react.useRef(null);
|
|
1008
1010
|
const heightScaleRef = react.useRef(1);
|
|
@@ -1022,6 +1024,7 @@ var EditorCanvas = react.forwardRef(
|
|
|
1022
1024
|
setFc(canvas);
|
|
1023
1025
|
initCanvasEvent(canvas);
|
|
1024
1026
|
usePeekControl(canvas, hideConfig);
|
|
1027
|
+
setCanvasReady(true);
|
|
1025
1028
|
};
|
|
1026
1029
|
const createFcObjs = (canvas) => {
|
|
1027
1030
|
const ns = Math.floor(frame / 30 * 1e6);
|
|
@@ -1193,9 +1196,42 @@ var EditorCanvas = react.forwardRef(
|
|
|
1193
1196
|
waitFcTasks.current.push(updateImage.bind(void 0, id, base64));
|
|
1194
1197
|
}
|
|
1195
1198
|
};
|
|
1199
|
+
const createEditObjes = async (canvas, time) => {
|
|
1200
|
+
const allObjects = canvas.getObjects();
|
|
1201
|
+
const toRemove = [];
|
|
1202
|
+
allObjects.forEach((obj) => {
|
|
1203
|
+
var _a;
|
|
1204
|
+
if ((_a = obj == null ? void 0 : obj.clipData) == null ? void 0 : _a.originClip) {
|
|
1205
|
+
toRemove.push(obj);
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
1208
|
+
toRemove.forEach((obj) => canvas.remove(obj));
|
|
1209
|
+
const promises = editClips.map((clip) => {
|
|
1210
|
+
if (clip.videoClip) {
|
|
1211
|
+
return createImageFromClip(clip);
|
|
1212
|
+
}
|
|
1213
|
+
if (clip.textClip && !clip.audioClip) {
|
|
1214
|
+
return createTextFromClip(clip);
|
|
1215
|
+
}
|
|
1216
|
+
});
|
|
1217
|
+
const res = await Promise.allSettled(promises);
|
|
1218
|
+
const objects = [];
|
|
1219
|
+
res.forEach((item) => {
|
|
1220
|
+
if (item.status === "fulfilled" && item.value) {
|
|
1221
|
+
objects.push(item.value);
|
|
1222
|
+
}
|
|
1223
|
+
});
|
|
1224
|
+
if (editRenderTime.current === time) {
|
|
1225
|
+
canvas.add(...objects).renderAll();
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1196
1228
|
const createImageFromClip = (clip, fc2) => {
|
|
1197
|
-
|
|
1198
|
-
|
|
1229
|
+
return new Promise((resolve) => {
|
|
1230
|
+
const canvas = fc || fc2;
|
|
1231
|
+
if (!canvas || !canvasSize.width) {
|
|
1232
|
+
resolve(null);
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1199
1235
|
const url = /video/g.test(clip.videoClip.mimeType) ? "" : clip.videoClip.sourceUrl;
|
|
1200
1236
|
fabric.fabric.Image.fromURL(url, (img) => {
|
|
1201
1237
|
const { dimension, posParam } = clip.videoClip;
|
|
@@ -1229,16 +1265,14 @@ var EditorCanvas = react.forwardRef(
|
|
|
1229
1265
|
},
|
|
1230
1266
|
visible: frame >= inFrame && frame < inFrame + durationFrame
|
|
1231
1267
|
});
|
|
1232
|
-
canvas.add(img);
|
|
1233
1268
|
img.on("modified", () => {
|
|
1234
1269
|
const fObj = convertToJSON(img);
|
|
1235
1270
|
fObj.src = "";
|
|
1236
1271
|
vmmlConverterRef.current.updateClip(fObj);
|
|
1237
1272
|
});
|
|
1273
|
+
resolve(img);
|
|
1238
1274
|
});
|
|
1239
|
-
}
|
|
1240
|
-
waitFcTasks.current.push(createImageFromClip.bind(void 0, clip));
|
|
1241
|
-
}
|
|
1275
|
+
});
|
|
1242
1276
|
};
|
|
1243
1277
|
const handleRedo = () => {
|
|
1244
1278
|
history.redo();
|
|
@@ -1247,11 +1281,11 @@ var EditorCanvas = react.forwardRef(
|
|
|
1247
1281
|
history.undo();
|
|
1248
1282
|
};
|
|
1249
1283
|
const onBatchModify = (fObj, canvas) => {
|
|
1250
|
-
|
|
1284
|
+
var _a;
|
|
1251
1285
|
if (!canvas) return;
|
|
1252
1286
|
const textObjects = canvas.getObjects().filter((item) => {
|
|
1253
|
-
var
|
|
1254
|
-
return ((
|
|
1287
|
+
var _a2;
|
|
1288
|
+
return ((_a2 = item == null ? void 0 : item.clipData) == null ? void 0 : _a2.type) === "\u6587\u5B57";
|
|
1255
1289
|
});
|
|
1256
1290
|
const { left, top, scaleX, scaleY, angle } = fObj;
|
|
1257
1291
|
textObjects.forEach((textObj) => {
|
|
@@ -1267,10 +1301,20 @@ var EditorCanvas = react.forwardRef(
|
|
|
1267
1301
|
vmmlConverterRef.current.updateClip(updatedFObj);
|
|
1268
1302
|
});
|
|
1269
1303
|
canvas.renderAll();
|
|
1304
|
+
const event = new CustomEvent("editor-vmml-batch-change", {
|
|
1305
|
+
detail: {
|
|
1306
|
+
vmml: ((_a = vmmlConverterRef.current) == null ? void 0 : _a.vmml) ?? null
|
|
1307
|
+
}
|
|
1308
|
+
});
|
|
1309
|
+
window.dispatchEvent(event);
|
|
1270
1310
|
};
|
|
1271
1311
|
const createTextFromClip = async (clip, fc2) => {
|
|
1272
|
-
|
|
1273
|
-
|
|
1312
|
+
return new Promise(async (resolve) => {
|
|
1313
|
+
const canvas = fc || fc2;
|
|
1314
|
+
if (!canvas) {
|
|
1315
|
+
resolve(null);
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1274
1318
|
const { width, height } = vmml.template.dimension;
|
|
1275
1319
|
const fontSize = vmmlUtils.getFontSize(width, height);
|
|
1276
1320
|
const { textContent, backgroundColor, textColor, posParam, fontAssetUrl, alignType } = clip.textClip;
|
|
@@ -1308,7 +1352,7 @@ var EditorCanvas = react.forwardRef(
|
|
|
1308
1352
|
originX: "center",
|
|
1309
1353
|
originY: "center",
|
|
1310
1354
|
clipData: {
|
|
1311
|
-
id:
|
|
1355
|
+
id: clip.id,
|
|
1312
1356
|
inPoint: clip.inPoint,
|
|
1313
1357
|
inFrame: vmmlUtils.getFrames(clip.inPoint, 30),
|
|
1314
1358
|
type: "\u6587\u5B57",
|
|
@@ -1340,11 +1384,9 @@ var EditorCanvas = react.forwardRef(
|
|
|
1340
1384
|
vmmlConverterRef.current.updateClip(fObj);
|
|
1341
1385
|
}
|
|
1342
1386
|
});
|
|
1343
|
-
|
|
1387
|
+
resolve(imgData);
|
|
1344
1388
|
});
|
|
1345
|
-
}
|
|
1346
|
-
waitFcTasks.current.push(createTextFromClip.bind(void 0, clip));
|
|
1347
|
-
}
|
|
1389
|
+
});
|
|
1348
1390
|
};
|
|
1349
1391
|
const getFontFamilyName = (url) => {
|
|
1350
1392
|
const filename = url.split("/").pop() || "";
|
|
@@ -1523,6 +1565,12 @@ var EditorCanvas = react.forwardRef(
|
|
|
1523
1565
|
vmmlConverterRef.current = new VmmlConverter_default({ vmml, canvasSize });
|
|
1524
1566
|
}
|
|
1525
1567
|
}, [canvasSize, vmml]);
|
|
1568
|
+
react.useEffect(() => {
|
|
1569
|
+
if (editClips.length && canvasReady && fc) {
|
|
1570
|
+
editRenderTime.current = Date.now();
|
|
1571
|
+
createEditObjes(fc, editRenderTime.current);
|
|
1572
|
+
}
|
|
1573
|
+
}, [editClips, canvasReady]);
|
|
1526
1574
|
react.useEffect(() => {
|
|
1527
1575
|
if (fc) {
|
|
1528
1576
|
const historyClass2 = new HistoryClass(fc);
|
|
@@ -2313,7 +2361,7 @@ var VideoMenu = ({ createImage, videoMenus, menuState }) => {
|
|
|
2313
2361
|
var VideoMenu_default = VideoMenu;
|
|
2314
2362
|
var historyClass = new HistoryClass();
|
|
2315
2363
|
var EditorFn = ({
|
|
2316
|
-
vmml,
|
|
2364
|
+
vmml: propVmml,
|
|
2317
2365
|
pauseFrame = 0,
|
|
2318
2366
|
maxText = 10,
|
|
2319
2367
|
maxVideo = 5,
|
|
@@ -2330,7 +2378,7 @@ var EditorFn = ({
|
|
|
2330
2378
|
// { hideDelete: false, hideEdit: false, hideMute: false, hideVolume: false }
|
|
2331
2379
|
}, ref) => {
|
|
2332
2380
|
var _a;
|
|
2333
|
-
|
|
2381
|
+
const [vmmlState, setVmmlState] = react.useState(() => vmmlUtils.convertVmmlTextScaleByForbidden(propVmml));
|
|
2334
2382
|
const textMenuRef = react.useRef(null);
|
|
2335
2383
|
const vmmlPlayerRef = react.useRef();
|
|
2336
2384
|
const canvasRef = react.useRef();
|
|
@@ -2342,7 +2390,7 @@ var EditorFn = ({
|
|
|
2342
2390
|
const [isPlaying, setIsPlaying] = react.useState(false);
|
|
2343
2391
|
const [showCanvas, setShowCanvas] = react.useState(false);
|
|
2344
2392
|
const [filterIds, setFilterIds] = react.useState([]);
|
|
2345
|
-
const [durationInFrames, setDurationInFrames] = react.useState(vmmlUtils.getFrames(((_a =
|
|
2393
|
+
const [durationInFrames, setDurationInFrames] = react.useState(vmmlUtils.getFrames(((_a = vmmlState == null ? void 0 : vmmlState.template) == null ? void 0 : _a.duration) || 1, fps));
|
|
2346
2394
|
const [previewState, setPreviewState] = react.useState(true);
|
|
2347
2395
|
const [menuState, setMenuState] = react.useState("");
|
|
2348
2396
|
const [canvasSize, setCanvasSize] = react.useState({ width: 0, height: 0, top: 0 });
|
|
@@ -2355,15 +2403,17 @@ var EditorFn = ({
|
|
|
2355
2403
|
const [dragState, setDragState] = react.useState(0);
|
|
2356
2404
|
const vmmlConverterRef = react.useRef(null);
|
|
2357
2405
|
const [initFcObjs, setInitFcObjs] = react.useState([]);
|
|
2406
|
+
const [editClips, setEditClips] = react.useState([]);
|
|
2407
|
+
const [refreshEdit, setRefreshEdit] = react.useState(0);
|
|
2358
2408
|
const vmmlFlag = react.useRef(false);
|
|
2359
2409
|
const needPlay = react.useRef(true);
|
|
2360
2410
|
const setVmml = () => {
|
|
2361
2411
|
const { current } = vmmlPlayerRef;
|
|
2362
2412
|
if (!current) return;
|
|
2363
2413
|
if (!once.current) {
|
|
2364
|
-
current.setVmml(
|
|
2414
|
+
current.setVmml(vmmlState, pauseFrame);
|
|
2365
2415
|
} else {
|
|
2366
|
-
current.setVmml(
|
|
2416
|
+
current.setVmml(vmmlState, frame);
|
|
2367
2417
|
}
|
|
2368
2418
|
};
|
|
2369
2419
|
const onPlayerReady = () => {
|
|
@@ -2537,18 +2587,9 @@ var EditorFn = ({
|
|
|
2537
2587
|
setBuffering(false);
|
|
2538
2588
|
};
|
|
2539
2589
|
const initCanEditClips = (tracks = []) => {
|
|
2540
|
-
if (editableArray.length) {
|
|
2590
|
+
if (editableArray.length && tracks.length) {
|
|
2541
2591
|
const list = findEditClips(tracks);
|
|
2542
|
-
|
|
2543
|
-
const { current } = canvasRef;
|
|
2544
|
-
list.forEach((clip) => {
|
|
2545
|
-
if (clip.videoClip) {
|
|
2546
|
-
current.createImageFromClip(clip);
|
|
2547
|
-
} else {
|
|
2548
|
-
if (!clip.audioClip) current.createTextFromClip(clip);
|
|
2549
|
-
}
|
|
2550
|
-
});
|
|
2551
|
-
}
|
|
2592
|
+
setEditClips(list);
|
|
2552
2593
|
}
|
|
2553
2594
|
};
|
|
2554
2595
|
const findEditClips = (tracks = []) => {
|
|
@@ -2576,7 +2617,7 @@ var EditorFn = ({
|
|
|
2576
2617
|
};
|
|
2577
2618
|
const getVmml = () => {
|
|
2578
2619
|
try {
|
|
2579
|
-
const tracks =
|
|
2620
|
+
const tracks = vmmlState.template.tracks.filter((item) => item.editorType === "\u6587\u5B57");
|
|
2580
2621
|
tracks.forEach((track) => {
|
|
2581
2622
|
track.clips.forEach((clip) => {
|
|
2582
2623
|
clip.fObj.src = "";
|
|
@@ -2585,7 +2626,7 @@ var EditorFn = ({
|
|
|
2585
2626
|
} catch {
|
|
2586
2627
|
console.log("\u51FA\u9519\u4E86");
|
|
2587
2628
|
}
|
|
2588
|
-
return
|
|
2629
|
+
return vmmlState;
|
|
2589
2630
|
};
|
|
2590
2631
|
const getPlayer = () => {
|
|
2591
2632
|
return player;
|
|
@@ -2602,18 +2643,33 @@ var EditorFn = ({
|
|
|
2602
2643
|
}
|
|
2603
2644
|
}, [previewState]);
|
|
2604
2645
|
react.useEffect(() => {
|
|
2605
|
-
if (canvasSize.width && canvasSize.height &&
|
|
2606
|
-
vmmlConverterRef.current
|
|
2646
|
+
if (canvasSize.width && canvasSize.height && vmmlState) {
|
|
2647
|
+
if (!vmmlConverterRef.current) {
|
|
2648
|
+
vmmlConverterRef.current = new VmmlConverter_default({ vmml: vmmlState, canvasSize });
|
|
2649
|
+
} else {
|
|
2650
|
+
vmmlConverterRef.current.vmml = vmmlState;
|
|
2651
|
+
}
|
|
2607
2652
|
}
|
|
2608
|
-
|
|
2609
|
-
|
|
2653
|
+
}, [canvasSize, vmmlState]);
|
|
2654
|
+
react.useEffect(() => {
|
|
2655
|
+
if (editableArray.length && (vmmlState == null ? void 0 : vmmlState.template)) {
|
|
2656
|
+
initCanEditClips(vmmlState.template.tracks);
|
|
2610
2657
|
}
|
|
2611
|
-
}, [
|
|
2658
|
+
}, [editableArray, refreshEdit]);
|
|
2659
|
+
react.useEffect(() => {
|
|
2660
|
+
var _a2;
|
|
2661
|
+
if (propVmml) {
|
|
2662
|
+
const convertedVmml = vmmlUtils.convertVmmlTextScaleByForbidden(propVmml);
|
|
2663
|
+
setVmmlState(convertedVmml);
|
|
2664
|
+
setDurationInFrames(vmmlUtils.getFrames(((_a2 = propVmml == null ? void 0 : propVmml.template) == null ? void 0 : _a2.duration) || 1, fps));
|
|
2665
|
+
setRefreshEdit(Date.now());
|
|
2666
|
+
}
|
|
2667
|
+
}, [propVmml]);
|
|
2612
2668
|
react.useEffect(() => {
|
|
2613
|
-
if (
|
|
2614
|
-
initFcObjects(
|
|
2669
|
+
if (vmmlState) {
|
|
2670
|
+
initFcObjects(vmmlState.template.tracks);
|
|
2615
2671
|
}
|
|
2616
|
-
}, [
|
|
2672
|
+
}, [vmmlState]);
|
|
2617
2673
|
react.useEffect(() => {
|
|
2618
2674
|
if (player) {
|
|
2619
2675
|
const parent = player.getContainerNode();
|
|
@@ -2648,7 +2704,7 @@ var EditorFn = ({
|
|
|
2648
2704
|
if (dragState === 2) {
|
|
2649
2705
|
needPlay.current = false;
|
|
2650
2706
|
const { current } = vmmlPlayerRef;
|
|
2651
|
-
current.setVmml(
|
|
2707
|
+
current.setVmml(vmmlState, frame, false);
|
|
2652
2708
|
setShowCanvas(false);
|
|
2653
2709
|
}
|
|
2654
2710
|
if (dragState === 3 || dragState === 4) {
|
|
@@ -2656,6 +2712,20 @@ var EditorFn = ({
|
|
|
2656
2712
|
setPreviewState(false);
|
|
2657
2713
|
}
|
|
2658
2714
|
}, [dragState]);
|
|
2715
|
+
const updateVmml = (v) => {
|
|
2716
|
+
var _a2;
|
|
2717
|
+
const { current: playerCurrent } = vmmlPlayerRef;
|
|
2718
|
+
const { current: canvasCurrent } = canvasRef;
|
|
2719
|
+
if (!playerCurrent) return;
|
|
2720
|
+
const convertedVmml = vmmlUtils.convertVmmlTextScaleByForbidden(v);
|
|
2721
|
+
setVmmlState(convertedVmml);
|
|
2722
|
+
setDurationInFrames(vmmlUtils.getFrames(((_a2 = v == null ? void 0 : v.template) == null ? void 0 : _a2.duration) || 1, fps));
|
|
2723
|
+
playerCurrent.setVmml(convertedVmml, pauseFrame);
|
|
2724
|
+
setRefreshEdit(Date.now());
|
|
2725
|
+
if (canvasCurrent) {
|
|
2726
|
+
canvasCurrent.checkObjectInPoint(pauseFrame);
|
|
2727
|
+
}
|
|
2728
|
+
};
|
|
2659
2729
|
react.useImperativeHandle(
|
|
2660
2730
|
ref,
|
|
2661
2731
|
() => ({
|
|
@@ -2664,9 +2734,10 @@ var EditorFn = ({
|
|
|
2664
2734
|
getVmml,
|
|
2665
2735
|
getPlayer,
|
|
2666
2736
|
texteditClose,
|
|
2667
|
-
textFinish
|
|
2737
|
+
textFinish,
|
|
2738
|
+
updateVmml
|
|
2668
2739
|
}),
|
|
2669
|
-
[
|
|
2740
|
+
[vmmlState, player]
|
|
2670
2741
|
);
|
|
2671
2742
|
const texteditClose = () => {
|
|
2672
2743
|
if (textMenuRef) {
|
|
@@ -2696,7 +2767,7 @@ var EditorFn = ({
|
|
|
2696
2767
|
vmmlPlayer.VmmlPlayer,
|
|
2697
2768
|
{
|
|
2698
2769
|
ref: vmmlPlayerRef,
|
|
2699
|
-
vmml,
|
|
2770
|
+
vmml: vmmlState,
|
|
2700
2771
|
existenceBorderRadio: true,
|
|
2701
2772
|
moveToBeginningWhenEnded: true,
|
|
2702
2773
|
muted: true,
|
|
@@ -2717,9 +2788,10 @@ var EditorFn = ({
|
|
|
2717
2788
|
enterPreview,
|
|
2718
2789
|
intoTextEdit,
|
|
2719
2790
|
frame,
|
|
2720
|
-
vmml,
|
|
2791
|
+
vmml: vmmlState,
|
|
2721
2792
|
dragState,
|
|
2722
2793
|
initFcObjs,
|
|
2794
|
+
editClips,
|
|
2723
2795
|
onVideoChange,
|
|
2724
2796
|
isBatchModify,
|
|
2725
2797
|
hideConfig
|