11import { Action } from "../../internal/Action.js" ;
22import { Qualifier } from "../../internal/qualifier/Qualifier.js" ;
3+ import { ITrimActionModel } from "../../internal/models/ITrimActionModel.js" ;
4+ import { IActionModel } from "../../internal/models/IActionModel.js" ;
35
46/**
57 * @description Class for shortening a video to the specified range.
@@ -8,8 +10,13 @@ import {Qualifier} from "../../internal/qualifier/Qualifier.js";
810 * @see Visit {@link Actions.VideoEdit|VideoEdit} for an example
911 */
1012class TrimAction extends Action {
13+ protected _actionModel : ITrimActionModel ;
14+
1115 constructor ( ) {
1216 super ( ) ;
17+ this . _actionModel = {
18+ actionType : 'trimVideo'
19+ } ;
1320 }
1421
1522 /**
@@ -32,6 +39,7 @@ class TrimAction extends Action {
3239 * @return {this }
3340 */
3441 startOffset ( offset : string | number ) : this {
42+ this . _actionModel . startOffset = + offset ;
3543 return this . addQualifier ( new Qualifier ( 'so' , this . parseVal ( offset ) ) ) ;
3644 }
3745
@@ -44,6 +52,7 @@ class TrimAction extends Action {
4452 * @return {this }
4553 */
4654 endOffset ( offset : string | number ) : this {
55+ this . _actionModel . endOffset = + offset ;
4756 return this . addQualifier ( new Qualifier ( 'eo' , this . parseVal ( offset ) ) ) ;
4857 }
4958
@@ -56,8 +65,29 @@ class TrimAction extends Action {
5665 * @return {this }
5766 */
5867 duration ( duration : string | number ) : this {
68+ this . _actionModel . duration = duration ;
5969 return this . addQualifier ( new Qualifier ( 'du' , this . parseVal ( duration ) ) ) ;
6070 }
71+
72+ static fromJson ( actionModel : IActionModel ) : TrimAction {
73+ const { duration, startOffset, endOffset} = ( actionModel as ITrimActionModel ) ;
74+ // We are using this() to allow inheriting classes to use super.fromJson.apply(this, [actionModel])
75+ // This allows the inheriting classes to determine the class to be created
76+ const result = new this ( ) ;
77+ if ( duration != null ) {
78+ result . duration ( duration ) ;
79+ }
80+
81+ if ( startOffset != null ) {
82+ result . startOffset ( startOffset ) ;
83+ }
84+
85+ if ( endOffset != null ) {
86+ result . endOffset ( endOffset ) ;
87+ }
88+
89+ return result ;
90+ }
6191}
6292
6393export default TrimAction ;
0 commit comments