import { Dynamic , val , applyOptions } from '../util' ; import { Base , BaseOptions } from './base' ; import { Visual , VisualOptions } from './visual' ; type Constructor < T > = new ( ... args ) => T ; interface VisualSource extends Base { readonly source : HTMLImageElement | HTMLVideoElement ; } interface VisualSourceOptions extends VisualOptions { source : HTMLImageElement | HTMLVideoElement ; /** What part of  source to render  sourceX ? : Dynamic < number > ; /** What part of  source to render  sourceY ? : Dynamic < number > ; /** What part of  source to render, or undefined for the entire width  sourceWidth ? : Dynamic < number > ; /** What part of  source to render, or undefined for the entire height  sourceHeight ? : Dynamic < number > ; /** Where to render  source onto the layer  destX ? : Dynamic < number > ; /** Where to render  source onto the layer  destY ? : Dynamic < number > ; /** Where to render  source onto the layer, or undefined to fill the layer's width  destWidth ? : Dynamic < number > ; /** Where to render  source onto the layer, or undefined to fill the layer's height  destHeight ? : Dynamic < number > ; } mixin function VisualSourceMixin < OptionsSuperclass extends BaseOptions > ( superclass ) { type MixedVisualSourceOptions = OptionsSuperclass & VisualSourceOptions ; class MixedVisualSource extends superclass { /**
         * The raw html media element
         */ readonly source : HTMLImageElement | HTMLVideoElement ; /** What part of  source to render  sourceX : Dynamic < number > ; /** What part of  source to render  sourceY : Dynamic < number > ; /** What part of  source to render, or undefined for the entire width  sourceWidth : Dynamic < number > ; /** What part of  source to render, or undefined for the entire height  sourceHeight : Dynamic < number > ; /** Where to render  source onto the layer  destX : Dynamic < number > ; /** Where to render  source onto the layer  destY : Dynamic < number > ; /** Where to render  source onto the layer, or undefined to fill the layer's width  destWidth : Dynamic < number > ; /** Where to render  source onto the layer, or undefined to fill the layer's height  destHeight : Dynamic < number > ; constructor ( options ) { super ( options ) ; applyOptions ( options , this ) ; } doRender ( ) { super . doRender ( ) ; this . cctx . drawImage ( this . source , val ( this , 'sourceX' , this . currentTime ) , val ( this , 'sourceY' , this . currentTime ) , val ( this , 'sourceWidth' , this . currentTime ) , val ( this , 'sourceHeight' , this . currentTime ) , val ( this , 'destX' , this . currentTime ) , val ( this , 'destY' , this . currentTime ) , val ( this , 'destWidth' , this . currentTime ) , val ( this , 'destHeight' , this . currentTime ) ) ; } getDefaultOptions ( ) { return { ... superclass . prototype . getDefaultOptions ( ) , source : undefined , sourceX : 0 , sourceY : 0 , sourceWidth : undefined , sourceHeight : undefined , destX : 0 , destY : 0 , destWidth : undefined , destHeight : undefined } ; } } MixedVisualSource . prototype . propertyFilters = { ... Visual . prototype . propertyFilters , sourceWidth : function ( sourceWidth ) { const width = this . source instanceof HTMLImageElement ? this . source . width : this . source . videoWidth ; return sourceWidth != undefined ? sourceWidth : width ; } , sourceHeight : function ( sourceHeight ) { const height = this . source instanceof HTMLImageElement ? this . source . height : this . source . videoHeight ; return sourceHeight != undefined ? sourceHeight : height ; } , destWidth : function ( destWidth ) { return destWidth != undefined ? destWidth : val ( this , 'sourceWidth' , this . currentTime ) ; } , destHeight : function ( destHeight ) { return destHeight != undefined ? destHeight : val ( this , 'sourceHeight' , this . currentTime ) ; } , width : function ( width ) { return width != undefined ? width : val ( this , 'destWidth' , this . currentTime ) ; } , height : function ( height ) { return height != undefined ? height : val ( this , 'destHeight' , this . currentTime ) ; } } ; return MixedVisualSource ; } export { VisualSource , VisualSourceOptions , VisualSourceMixin } ;