11/**
22 * Copyright (c) 2024 The Diffusion Studio Authors
33 *
4- * This Source Code Form is subject to the terms of the Mozilla
4+ * This Source Code Form is subject to the terms of the Mozilla
55 * Public License, v. 2.0 that can be found in the LICENSE file.
66 */
77
88import { Timestamp , Transcript } from '../../models' ;
99import { AudioSource } from '../../sources' ;
1010import { RangeDeserializer } from './media.deserializer' ;
11- import { serializable , } from '../../services' ;
11+ import { serializable } from '../../services' ;
1212import { replaceKeyframes } from '../clip/clip.utils' ;
1313import { ReferenceError , ValidationError } from '../../errors' ;
1414import { Clip } from '../clip' ;
@@ -17,7 +17,6 @@ import type { CaptionPresetStrategy, CaptionTrack } from '../../tracks';
1717import type { float , frame } from '../../types' ;
1818import type { MediaClipProps } from './media.interfaces' ;
1919
20-
2120export class MediaClip < Props extends MediaClipProps = MediaClipProps > extends Clip < MediaClipProps > {
2221 public source = new AudioSource ( ) ;
2322 public declare element ?: HTMLAudioElement | HTMLVideoElement ;
@@ -54,7 +53,7 @@ export class MediaClip<Props extends MediaClipProps = MediaClipProps> extends Cl
5453 @serializable ( Transcript )
5554 public get transcript ( ) : Transcript | undefined {
5655 return this . source . transcript ;
57- } ;
56+ }
5857
5958 public set transcript ( transcript : Transcript | undefined ) {
6059 this . source . transcript = transcript ;
@@ -170,10 +169,12 @@ export class MediaClip<Props extends MediaClipProps = MediaClipProps> extends Cl
170169 public seek ( time : Timestamp ) : Promise < void > {
171170 return new Promise ( ( resolve , reject ) => {
172171 if ( ! this . element ) {
173- return reject ( new ReferenceError ( {
174- code : 'elementNotDefined' ,
175- message : 'Cannot seek on undefined element' ,
176- } ) ) ;
172+ return reject (
173+ new ReferenceError ( {
174+ code : 'elementNotDefined' ,
175+ message : 'Cannot seek on undefined element' ,
176+ } ) ,
177+ ) ;
177178 }
178179 if ( time . millis < this . start . millis || time . millis > this . stop . millis ) {
179180 time = this . start ;
@@ -205,7 +206,7 @@ export class MediaClip<Props extends MediaClipProps = MediaClipProps> extends Cl
205206 if ( start . millis >= stop . millis ) {
206207 throw new ValidationError ( {
207208 code : 'invalidKeyframe' ,
208- message : "Start can't lower than or equal the stop"
209+ message : "Start can't lower than or equal the stop" ,
209210 } ) ;
210211 }
211212 // start and/or stop are out of bounds
@@ -285,18 +286,17 @@ export class MediaClip<Props extends MediaClipProps = MediaClipProps> extends Cl
285286 * Generates a new caption track for the current clip using the specified captioning strategy.
286287 * @param strategy An optional CaptionPresetStrategy to define how captions should be generated.
287288 */
288- public async addCaptions ( strategy ?: CaptionPresetStrategy | ( new ( ) => CaptionPresetStrategy ) ) : Promise < CaptionTrack > {
289+ public async addCaptions (
290+ strategy ?: CaptionPresetStrategy | ( new ( ) => CaptionPresetStrategy ) ,
291+ ) : Promise < CaptionTrack > {
289292 if ( ! this . track ?. composition ) {
290293 throw new ValidationError ( {
291294 code : 'compositionNotDefined' ,
292295 message : 'Captions can only be generated after the clip has been added to the composition' ,
293296 } ) ;
294297 }
295298
296- const track = await this . track . composition
297- . createTrack ( 'caption' )
298- . from ( this )
299- . generate ( strategy ) ;
299+ const track = await this . track . composition . createTrack ( 'caption' ) . from ( this ) . generate ( strategy ) ;
300300
301301 return track ;
302302 }
@@ -308,7 +308,9 @@ export class MediaClip<Props extends MediaClipProps = MediaClipProps> extends Cl
308308 /**
309309 * @deprecated use `addCaptions` instead
310310 */
311- public async generateCaptions ( strategy ?: CaptionPresetStrategy | ( new ( ) => CaptionPresetStrategy ) ) {
311+ public async generateCaptions (
312+ strategy ?: CaptionPresetStrategy | ( new ( ) => CaptionPresetStrategy ) ,
313+ ) {
312314 return this . addCaptions ( strategy ) ;
313315 }
314316}
0 commit comments