@versa_ai/vmml-editor 1.0.39 → 1.0.41

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.39",
3
+ "version": "1.0.41",
4
4
  "module": "dist/index.mjs",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.mts",
@@ -57,12 +57,11 @@ const EditorCanvas = forwardRef(
57
57
  if (fc) {
58
58
  const ns = Math.floor(((f ?? frame) / 30) * 1000000);
59
59
  const objects = fc.getObjects();
60
- console.log(objects, 'fc>>>>>>>>>>>>>>>>', frame)
61
60
  objects.forEach((item: any) => {
62
61
  if (item?.clipData?.type === "文字") {
63
- item.set("visible", ns >= item.clipData.inPoint && ns < item.clipData.inPoint + (item.clipData.duration || vmml.template.duration));
62
+ item.set("visible", item.clipData.duration >0 && ns >= item.clipData.inPoint && ns < item.clipData.inPoint + (item.clipData.duration || vmml.template.duration));
64
63
  } else {
65
- item.set("visible", ns >= item.clipData.inPoint && ns < item.clipData.inPoint + item.clipData?.fileUrl?.duration);
64
+ item.set("visible", item.clipData.duration >0 && ns >= item.clipData.inPoint && ns < item.clipData.inPoint + item.clipData?.fileUrl?.duration);
66
65
  }
67
66
  });
68
67
  fc.discardActiveObject();
@@ -359,8 +358,7 @@ const EditorCanvas = forwardRef(
359
358
  await document.fonts.ready;
360
359
  }
361
360
  }
362
-
363
- const lines = textContent.split('\n');
361
+ const lines = textContent.split('\n').filter((item: string) => item);
364
362
  const lineHeight = 22 + strokeW; // 行高
365
363
  const textHeight = lines.length * lineHeight;
366
364
  const groupWidth = Math.max(...lines.map((l: any) => {
@@ -833,8 +831,12 @@ const EditorCanvas = forwardRef(
833
831
  }, [fc, dragState])
834
832
 
835
833
  useEffect(() => {
836
- if (canvasSize.width && canvasSize.height && !vmmlConverterRef.current) {
837
- vmmlConverterRef.current = new VmmlConverter({ vmml, canvasSize });
834
+ if (canvasSize.width && canvasSize.height) {
835
+ if (vmmlConverterRef.current) {
836
+ vmmlConverterRef.current.changeVmml(vmml)
837
+ } else {
838
+ vmmlConverterRef.current = new VmmlConverter({ vmml, canvasSize });
839
+ }
838
840
  }
839
841
  }, [canvasSize, vmml]);
840
842
 
@@ -74,6 +74,21 @@ class VmmlConverter {
74
74
  };
75
75
  }
76
76
 
77
+ findClip (id: string | Array<string>) {
78
+ const tracks = this.vmml.template.tracks || [];
79
+ const isString = typeof id === 'string'
80
+ const ids = isString ? [id] : id;
81
+ const list: any = [];
82
+ tracks.forEach((track: any) => {
83
+ track.clips.forEach((clip: any) => {
84
+ if (ids?.includes(clip.id)) {
85
+ list.push(clip);
86
+ }
87
+ })
88
+ });
89
+ return list
90
+ }
91
+
77
92
  /**
78
93
  * 转换 TextClip
79
94
  * @param fObj - 画布fObj
@@ -176,26 +191,18 @@ class VmmlConverter {
176
191
  * @param fObj - 画布fObj
177
192
  */
178
193
  public updateClip(fObj: any) {
179
- console.log("updateClip fObj", fObj);
194
+ console.log("updateClip fObj", fObj, this.tracks);
180
195
  const posParam = this.setPosParam(fObj);
181
196
  const {
182
- // clipData: { id, type, lineSpacing },
183
197
  clipData: { id, type, lineSpacing, originClip },
184
198
  } = fObj;
185
- let existClip = null;
186
- // 模板内可编辑的clip
187
- if (originClip) {
188
- existClip = originClip;
189
- } else {
190
- const editorTrack = this.tracks.find((track: any) => track.editorType === type);
191
- existClip = (editorTrack?.clips || []).find((clip: any) => clip.id === id);
192
- }
199
+ const [existClip] = this.findClip(id);
193
200
 
194
201
  if (existClip) {
195
202
  //修改现有clip的代码
196
203
  !originClip && (existClip.fObj = fObj);
197
204
  if (type === "表情包") {
198
- existClip.videoClip.posParam = posParam;
205
+ existClip.videoClip.posParam = posParam;
199
206
  } else if (type === "文字") {
200
207
  const { clipData: { text, textColor, bgColor}} = fObj;
201
208
  const scale = this.fontSize / 22;
@@ -213,7 +220,7 @@ class VmmlConverter {
213
220
  }
214
221
  }
215
222
 
216
- console.log("updateClip 最终vmml", this.vmml);
223
+ // console.log("updateClip 最终vmml", this.vmml);
217
224
  }
218
225
 
219
226
  /**
@@ -222,13 +229,18 @@ class VmmlConverter {
222
229
  * @param type - 实例 类型
223
230
  */
224
231
  public deleteClip({ id, type, originClip }: { id: string; type: string, originClip: any }): void {
225
- // 模板内的可编辑clip
226
232
  if (originClip) {
227
- originClip.duration = 0;
233
+ for (const track of this.tracks) {
234
+ const clip = (track.clips || []).find((c: any) => c.id === originClip.id);
235
+ if (clip) {
236
+ clip.duration = 0;
237
+ break;
238
+ }
239
+ }
228
240
  } else {
229
241
  const editorTrack = this.tracks.find((track: any) => track.editorType === type);
230
242
  const index = editorTrack.clips.findIndex((item: any) => item.id === id);
231
-
243
+
232
244
  if (index !== -1) {
233
245
  if (editorTrack.clips[index + 1] && editorTrack.clips[index + 1].audioClip) {
234
246
  editorTrack.clips.splice(index, 2); // 删除当前元素及下一个 audio 元素
@@ -244,8 +256,10 @@ class VmmlConverter {
244
256
  }
245
257
  }
246
258
  }
259
+ }
247
260
 
248
- console.log("deleteClip 最终Vmml", this.vmml);
261
+ changeVmml (newVmml: any) {
262
+ this.vmml = newVmml;
249
263
  }
250
264
 
251
265
  //切换静音 视频/音频