@versa_ai/vmml-editor 1.0.39 → 1.0.40

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.40",
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
+
837
+ } else {
838
+ vmmlConverterRef.current = new VmmlConverter({ vmml, canvasSize });
839
+ }
838
840
  }
839
841
  }, [canvasSize, vmml]);
840
842
 
@@ -176,26 +176,30 @@ class VmmlConverter {
176
176
  * @param fObj - 画布fObj
177
177
  */
178
178
  public updateClip(fObj: any) {
179
- console.log("updateClip fObj", fObj);
179
+ console.log("updateClip fObj", fObj, this.tracks);
180
180
  const posParam = this.setPosParam(fObj);
181
181
  const {
182
- // clipData: { id, type, lineSpacing },
183
182
  clipData: { id, type, lineSpacing, originClip },
184
183
  } = 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);
184
+ let existClip = null;
185
+ if (originClip) {
186
+ for (const track of this.tracks) {
187
+ const clip = (track.clips || []).find((c: any) => c.id === originClip.id);
188
+ if (clip) {
189
+ existClip = clip;
190
+ break;
191
+ }
192
192
  }
193
+ } else {
194
+ const editorTrack = this.tracks.find((track: any) => track.editorType === type);
195
+ existClip = (editorTrack?.clips || []).find((clip: any) => clip.id === id);
196
+ }
193
197
 
194
198
  if (existClip) {
195
199
  //修改现有clip的代码
196
200
  !originClip && (existClip.fObj = fObj);
197
201
  if (type === "表情包") {
198
- existClip.videoClip.posParam = posParam;
202
+ existClip.videoClip.posParam = posParam;
199
203
  } else if (type === "文字") {
200
204
  const { clipData: { text, textColor, bgColor}} = fObj;
201
205
  const scale = this.fontSize / 22;
@@ -213,7 +217,7 @@ class VmmlConverter {
213
217
  }
214
218
  }
215
219
 
216
- console.log("updateClip 最终vmml", this.vmml);
220
+ // console.log("updateClip 最终vmml", this.vmml);
217
221
  }
218
222
 
219
223
  /**
@@ -222,13 +226,18 @@ class VmmlConverter {
222
226
  * @param type - 实例 类型
223
227
  */
224
228
  public deleteClip({ id, type, originClip }: { id: string; type: string, originClip: any }): void {
225
- // 模板内的可编辑clip
226
229
  if (originClip) {
227
- originClip.duration = 0;
230
+ for (const track of this.tracks) {
231
+ const clip = (track.clips || []).find((c: any) => c.id === originClip.id);
232
+ if (clip) {
233
+ clip.duration = 0;
234
+ break;
235
+ }
236
+ }
228
237
  } else {
229
238
  const editorTrack = this.tracks.find((track: any) => track.editorType === type);
230
239
  const index = editorTrack.clips.findIndex((item: any) => item.id === id);
231
-
240
+
232
241
  if (index !== -1) {
233
242
  if (editorTrack.clips[index + 1] && editorTrack.clips[index + 1].audioClip) {
234
243
  editorTrack.clips.splice(index, 2); // 删除当前元素及下一个 audio 元素
@@ -244,8 +253,10 @@ class VmmlConverter {
244
253
  }
245
254
  }
246
255
  }
256
+ }
247
257
 
248
- console.log("deleteClip 最终Vmml", this.vmml);
258
+ changeVmml (newVmml: any) {
259
+ this.vmml = newVmml;
249
260
  }
250
261
 
251
262
  //切换静音 视频/音频