import VidarObject from '../object' ; import { publish , subscribe } from '../event' ; import { watchPublic , applyOptions } from '../util' ; import { Movie } from '../movie' ; interface BaseOptions { /** The time in the movie at which this layer starts */ startTime : number ; duration : number ; } /**
 * A layer outputs content for the movie
 */ class Base implements VidarObject { type : string ; publicExcludes : string [ ] ; propertyFilters : Record < string , < T > ( value : T ) => T > ; enabled : boolean ; /**
     * If the attached movie's playback position is in this layer
     */ active : boolean ; /**
     * The number of times this layer has been attached to a movie minus the
     * number of times it's been detached. (Used for the movie's array proxy with
     * `unshift`)
     */ private _occurrenceCount : number ; private _startTime : number ; private _duration : number ; private _movie : Movie ; param options param options . startTime param options . duration constructor ( options ) { this . _startTime = options . startTime ; this . _duration = options . duration ; const newThis = watchPublic ( this ) as Base ; applyOptions ( options , this ) ; this . active = false ; this . enabled = true ; this . _occurrenceCount = 0 ; this . _movie = null ; subscribe ( newThis , 'layer.change' , event => { const typeOfChange = event . type . substring ( event . type . lastIndexOf ( '.' ) + 1 ) ; const type = `movie.change.layer.${ typeOfChange }` ; publish ( newThis . _movie , type , { ... event , target : newThis . _movie , type } ) ; } ) ; return newThis ; } ignore tryAttach ( movie ) { if ( this . _occurrenceCount === 0 ) this . attach ( movie ) ; this . _occurrenceCount ++ ; } attach ( movie ) { this . _movie = movie ; } ignore tryDetach ( ) { if ( this . movie === null ) throw new Error ( 'No movie to detach from' ) ; this . _occurrenceCount -- ; if ( this . _occurrenceCount === 0 ) this . detach ( ) ; } detach ( ) { this . _movie = null ; } /**
     * Called when the layer is activated
     */ start ( ) { } /**
     * Called when the movie renders and the layer is active
     */ render ( ) { } /**
    * Called when the layer is deactivated
     */ stop ( ) { } get parent ( ) : Movie { return this . _movie ; } /**
     */ get startTime ( ) : number { return this . _startTime ; } set startTime ( val ) { this . _startTime = val ; } /**
     * The current time of the movie relative to this layer
     */ get currentTime ( ) : number { return this . _movie ? this . _movie . currentTime - this . startTime : undefined ; } /**
     */ get duration ( ) : number { return this . _duration ; } set duration ( val ) { this . _duration = val ; } get movie ( ) : Movie { return this . _movie ; } getDefaultOptions ( ) { return { startTime : undefined , duration : undefined } ; } } Base . prototype . type = 'layer' ; Base . prototype . publicExcludes = [ ] ; Base . prototype . propertyFilters = { } ; export { Base , BaseOptions } ;