@versa_ai/vmml-editor 1.0.51 → 1.0.53

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versa_ai/vmml-editor",
3
- "version": "1.0.51",
3
+ "version": "1.0.53",
4
4
  "module": "dist/index.mjs",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.mts",
@@ -7,7 +7,7 @@ import VmmlConverter from "../utils/VmmlConverter";
7
7
  import { usePeekControl } from "../utils/usePeekControl";
8
8
 
9
9
  const EditorCanvas = forwardRef(
10
- ({ previewState, showCanvas, canvasSize, enterPreview, intoTextEdit, frame, vmml, dragState, initFcObjs, editClips = [], onVideoChange, isBatchModify, hideConfig, textWarapCenter }: any, ref: any) => {
10
+ ({ previewState, showCanvas, canvasSize, enterPreview, intoTextEdit, frame, vmml, dragState, initFcObjs, editClips = [], onVideoChange, isBatchModify, hideConfig, textWarapCenter, updateVmml }: any, ref: any) => {
11
11
  const [fc, setFc] = useState<any>(null);
12
12
  const [history, setHistory] = useState<any>(null);
13
13
  const [canvasReady, setCanvasReady] = useState(false);
@@ -44,6 +44,7 @@ const EditorCanvas = forwardRef(
44
44
  item.on('modified', () => {
45
45
  const fObj = convertToJSON(item)
46
46
  vmmlConverterRef.current.updateClip(fObj);
47
+ updateVmml(vmmlConverterRef.current.vmml)
47
48
  });
48
49
  item.set("visible", ns >= item.clipData.inPoint);
49
50
  canvas.add(item);
@@ -288,6 +289,7 @@ const EditorCanvas = forwardRef(
288
289
  const fObj = convertToJSON(img);
289
290
  fObj.src = "";
290
291
  vmmlConverterRef.current.updateClip(fObj);
292
+ updateVmml(vmmlConverterRef.current.vmml)
291
293
  });
292
294
  resolve(img);
293
295
  });
@@ -320,6 +322,7 @@ const EditorCanvas = forwardRef(
320
322
  vmmlConverterRef.current.updateClip(updatedFObj);
321
323
  });
322
324
  canvas.renderAll();
325
+ updateVmml(vmmlConverterRef.current?.vmml)
323
326
  const event = new CustomEvent('editor-vmml-batch-change', {
324
327
  detail: {
325
328
  vmml: vmmlConverterRef.current?.vmml ?? null
@@ -501,6 +504,7 @@ const EditorCanvas = forwardRef(
501
504
  onBatchModify(fObj, canvas)
502
505
  } else {
503
506
  vmmlConverterRef.current.updateClip(fObj);
507
+ updateVmml(vmmlConverterRef.current?.vmml)
504
508
  }
505
509
  });
506
510
 
@@ -589,6 +593,7 @@ const EditorCanvas = forwardRef(
589
593
  group.on('modified', () => {
590
594
  const fObj = convertToJSON(group)
591
595
  vmmlConverterRef.current.updateClip(fObj);
596
+ updateVmml(vmmlConverterRef.current?.vmml)
592
597
  });
593
598
  canvas.centerObject(group);
594
599
  canvas.add(group)
@@ -671,6 +676,7 @@ const EditorCanvas = forwardRef(
671
676
  target.setCoords();
672
677
  fc?.requestRenderAll();
673
678
  vmmlConverterRef.current.updateClip(convertToJSON(target));
679
+ updateVmml(vmmlConverterRef.current?.vmml)
674
680
  }
675
681
  }
676
682
  const changeObjectVisible = (id: string, visible: boolean = true) => {
package/src/index.tsx CHANGED
@@ -125,14 +125,19 @@ const EditorFn = <Schema extends AnyZodObject, Props>(
125
125
  };
126
126
 
127
127
  const onControlsClick = () => {
128
+ const { current }: any = vmmlPlayerRef;
129
+ current.unmute();
130
+ current.play();
128
131
  setPreviewState(true);
129
- if (previewState) {
130
- const { current }: any = vmmlPlayerRef;
131
- current.unmute();
132
- current.play();
133
- } else {
134
- setMenuState("");
135
- }
132
+ setMenuState("");
133
+ // if (previewState) {
134
+ // const { current }: any = vmmlPlayerRef;
135
+ // current.unmute();
136
+ // current.play();
137
+ // } else {
138
+ // setPreviewState(true);
139
+ // setMenuState("");
140
+ // }
136
141
  }
137
142
 
138
143
  // 点击底部菜单
@@ -357,12 +362,18 @@ const EditorFn = <Schema extends AnyZodObject, Props>(
357
362
  }
358
363
  }, [menuState]);
359
364
 
365
+ // useEffect(() => {
366
+ // if (previewState && !vmmlFlag.current) {
367
+ // vmmlFlag.current = true;
368
+ // setVmml();
369
+ // }
370
+ // }, [previewState]);
371
+
360
372
  useEffect(() => {
361
- if (previewState && !vmmlFlag.current) {
362
- vmmlFlag.current = true;
373
+ if (!vmmlFlag.current) {
363
374
  setVmml();
364
375
  }
365
- }, [previewState]);
376
+ }, []);
366
377
 
367
378
  useEffect(() => {
368
379
  if (canvasSize.width && canvasSize.height && vmmlState) {
@@ -555,6 +566,14 @@ const EditorFn = <Schema extends AnyZodObject, Props>(
555
566
  return {}
556
567
  }, [loading])
557
568
 
569
+ const updateVmml = (vmml: any) => {
570
+ const { current }: any = vmmlPlayerRef;
571
+ if (!current) return;
572
+ const playing = current?.playerRef?.isPlaying?.() ?? false
573
+ if (!playing) needPlay.current = false
574
+ current.setVmml(vmml, frame, false);
575
+ }
576
+
558
577
  return (
559
578
  <>
560
579
  <div className="editor" style={{ height }}>
@@ -597,7 +616,7 @@ const EditorFn = <Schema extends AnyZodObject, Props>(
597
616
  isBatchModify={isBatchModify}
598
617
  hideConfig={hideConfig}
599
618
  textWarapCenter={textWarapCenter}
600
- // textInfoReset={textInfoReset}
619
+ updateVmml={updateVmml}
601
620
  />
602
621
 
603
622
  <Loaidng show={loading} />
@@ -13,7 +13,7 @@ class VmmlConverter {
13
13
  * @param vmml - VMML 模板数据
14
14
  * @param canvasSize - 画布尺寸
15
15
  */
16
- constructor({ vmml, canvasSize }: { vmml: any; canvasSize: any }) {
16
+ constructor({ vmml, canvasSize }: { vmml: any; canvasSize: any}) {
17
17
  const { width, height } = vmml.template.dimension;
18
18
  this.vmml = vmml;
19
19
  this.canvasSize = canvasSize;
@@ -141,6 +141,7 @@ class VmmlConverter {
141
141
  editorTrack.clips.push(tClipData);
142
142
  }
143
143
 
144
+ this.updateVmml(this.vmml)
144
145
  // console.log("addTextClip 最终vmml", this.vmml);
145
146
  }
146
147
 
@@ -220,32 +221,6 @@ class VmmlConverter {
220
221
 
221
222
  // console.log("updateClip 最终vmml", this.vmml);
222
223
  }
223
- public updateTextClip(fObj: any, duration: number) {
224
- // console.log("updateClip fObj", fObj, this.tracks);
225
- const posParam = this.setPosParam(fObj);
226
- const {
227
- clipData: { id },
228
- } = fObj;
229
- const [existClip] = this.findClip(id);
230
-
231
- if (existClip) {
232
- const { clipData: { text, textColor, bgColor }} = fObj;
233
- const scale = this.fontSize / 22;
234
- existClip.duration = duration
235
- existClip.textClip = {
236
- ...existClip.textClip,
237
- posParam,
238
- backgroundColor: this.toARGB(bgColor),
239
- textContent: text,
240
- textColor: this.toARGB(textColor),
241
- dimension: {
242
- width: Math.floor(fObj.width * scale),
243
- height: Math.floor(fObj.height * scale),
244
- }
245
- };
246
- }
247
- // console.log(this.vmml, 'updateText>>>')
248
- }
249
224
 
250
225
  /**
251
226
  * 删除 Clip