import { Ticker24 } from "./core/Ticker24" ; import { Ease24 } from "./Ease24" ; import { Tween24Event } from "./core/Tween24Event" ; import { Updater } from "./core/updaters/Updater" ; import { ObjectUpdater } from "./core/updaters/ObjectUpdater" ; import { TransformUpdater } from "./core/updaters/TransformUpdater" ; import { FunctionExecuter } from "./core/FunctionExecuter" ; import { StyleUpdater } from "./core/updaters/StyleUpdater" ; import { MultiUpdater } from "./core/updaters/MultiUpdater" ; import { ArrayUtil } from "./utils/ArrayUtil" ; import { ClassUtil } from "./utils/ClassUtil" ; import { HTMLUtil } from "./utils/HTMLUtil" ; import { StringUtil } from "./utils/StringUtil" ; import { Sort24 } from "./index" ; import { Text24 } from "./utils/Text24" ; import { Event24 } from "./Event24" ; export class Tween24 { static readonly VERSION : string = "0.9.11" ; private static readonly _TYPE_TWEEN : string = "tween" ; private static readonly _TYPE_TWEEN_VELOCITY : string = "tween_velocity" ; private static readonly _TYPE_TWEEN_TEXT : string = "tween_text" ; private static readonly _TYPE_TWEEN_TEXT_VELOCITY : string = "tween_text_velocity" ; private static readonly _TYPE_PROP : string = "prop" ; private static readonly _TYPE_PROP_TEXT : string = "prop_text" ; private static readonly _TYPE_WAIT : string = "wait" ; private static readonly _TYPE_WAIT_EVENT : string = "wait_event" ; private static readonly _TYPE_WAIT_EVENT_AND_FUNC : string = "wait_event_and_func" ; private static readonly _TYPE_SERIAL : string = "serial" ; private static readonly _TYPE_PARALLEL : string = "parallel" ; private static readonly _TYPE_LAG : string = "lag" ; private static readonly _TYPE_LOOP : string = "loop" ; private static readonly _TYPE_FUNC : string = "func" ; private static readonly _TYPE_IF_CASE : string = "if_case" ; private static readonly _TYPE_IF_CASE_BY_FUNC : string = "if_case_by_func" ; static ticker : Ticker24 ; static ease : Ease24 ; private static _playingTweens : Tween24 [ ] ; private static _manualPlayingTweens : Tween24 [ ] ; private static _playingTweensByTarget : Map < any , Tween24 [ ] > ; private static _tweensById : Map < string , Tween24 > ; private static _tweensByGroupId : Map < string , Tween24 [ ] > ; private static _defaultEasing : Function = Ease24 . _Linear ; private static _debugMode : boolean = false ; private static _numCreateTween : number = 0 ; private _singleTarget : any | null = null ; private _multiTarget : any [ ] | null = null ; private _easing : Function | null = null ; private _type : string = "" ; private _time : number = NaN ; private _velocity : number = NaN ; private _delayTime : number = NaN ; private _startTime : number = NaN ; private _progress : number = 0 ; private _debugMode : boolean = false ; private _numLayers : number = 0 ; private _serialNumber : number = 0 ; private _tweenId : string = "" ; private _tweenGroupId : string = "" ; private _targetString : string = "" ; private _targetQuery : string | null = null ; private _useWillChange : boolean = false ; private _objectUpdater : ObjectUpdater | null = null ; private _objectMultiUpdater : MultiUpdater | null = null ; private _transformUpdater : TransformUpdater | null = null ; private _transformMultiUpdater : MultiUpdater | null = null ; private _styleUpdater : StyleUpdater | null = null ; private _styleMultiUpdater : MultiUpdater | null = null ; private _allUpdaters : Updater [ ] | null = null ; private _root : Tween24 | null = null ; private _parent : Tween24 | null = null ; private _next : Tween24 | null = null ; private _isDOM : boolean = false ; private _isRoot : boolean = false ; private _isManual : boolean = false ; private _isTrigger : boolean = false ; private _inited : boolean = false ; private _played : boolean = false ; private _paused : boolean = false ; private _skiped : boolean = false ; private _eventWaiting : boolean = false ; private _firstUpdated : boolean = false ; private _isContainerTween : boolean = false ; private _createdBasicUpdater : boolean = false ; private _functionExecuters : { [ key ] : FunctionExecuter ; } | null = null ; private _firstTween : Tween24 | null = null ; private _childTween : Tween24 [ ] | null = null ; private _playingChildTween : Tween24 [ ] | null = null ; private _originalChildTween : Tween24 [ ] | null = null ; private _numChildren : number = 0 ; private _numCompleteChildren : number = 0 ; private _lagTime : number = NaN ; private _totalLagTime : number = NaN ; private _lagSort : Function | null = null ; private _lagEasing : Function | null = null ; private _numLoops : number = NaN ; private _currentLoops : number = NaN ; private _ifFunc : Function | null = null ; private _trueTween : Tween24 | null = null ; private _falseTween : Tween24 | null = null ; private _dispatchEventTarget : any ; private _dispatchEventType : string | null = null ; private _triggered : boolean = false ; private _jumped : boolean = false ; private _jumpProg : number = NaN ; __fps : number = 0 ; __beforeTime : number = 0 ; constructor ( ) { Tween24 . ease ||= new Ease24 ( ) ; Tween24 . ticker ||= new Ticker24 ( ) ; Tween24 . _playingTweens ||= [ ] ; Tween24 . _playingTweensByTarget ||= new Map < any , Tween24 [ ] > ( ) ; } memberof play = ( ) => { this . _commonRootPlay ( ) ; } ; memberof manualPlay = ( ) => { Tween24 . _manualPlayingTweens ||= [ ] ; this . _isManual = true ; this . _commonRootPlay ( ) ; } ; private _commonRootPlay ( ) { if ( ! this . _paused ) { if ( ! this . _played ) { this . _root = this ; this . _isRoot = true ; this . _inited = false ; this . _firstUpdated = false ; this . _play ( ) ; if ( ! this . _isManual ) Tween24 . ticker . add ( this ) ; else Tween24 . _manualPlayingTweens . push ( this ) ; this . _functionExecute ( Tween24Event . PLAY ) ; } } else { this . _resume ( ) ; this . _paused = false ; if ( ! this . _isManual ) Tween24 . ticker . add ( this ) ; else Tween24 . _manualPlayingTweens . push ( this ) ; this . _functionExecute ( Tween24Event . RESUME ) ; } } private _play ( ) { if ( this . _isRoot ) { this . _numLayers = 0 ; } else { this . _root = this . _parent ?. _root || this . _parent ; this . _numLayers = this . _parent ? this . _parent . _numLayers + 1 : 1 ; } this . _played = true ; this . _startTime = Ticker24 . getTime ( ) + this . _delayTime * 1000 ; if ( this . _type == Tween24 . _TYPE_TWEEN_VELOCITY || this . _type == Tween24 . _TYPE_TWEEN_TEXT_VELOCITY ) { const deltas = [ 0 ] ; if ( this . _allUpdaters ?. length ) { for ( const updater of this . _allUpdaters ) { updater . init ( false ) ; deltas . push ( updater . getMaxAbsDelta ( ) ) ; } } this . _time = Math . max ( ... deltas ) / this . _velocity ; } Tween24 . _playingTweens . push ( this ) ; if ( this . _root ?. _skiped || this . _parent ?. _skiped ) this . _skip ( ) ; this . _debugLog ( "play" ) ; } private _resume ( ) { this . _played = true ; const nowTime = Ticker24 . getTime ( ) ; this . _startTime = nowTime - this . _time * 1000 * this . _progress ; if ( this . _playingChildTween ) { for ( const tween of this . _playingChildTween ) { if ( tween . _playingChildTween ) tween . _resume ( ) ; else tween . _startTime = nowTime - tween . _time * 1000 * tween . _progress ; } } Tween24 . _playingTweens . push ( this ) ; } memberof pause = ( ) => { if ( this . _isRoot ) { this . _played = false ; this . _paused = true ; if ( this . _isManual ) ArrayUtil . removeItemFromArray ( Tween24 . _manualPlayingTweens , this ) ; else Tween24 . ticker . remove ( this ) ; ArrayUtil . removeItemFromArray ( Tween24 . _playingTweens , this ) ; this . _functionExecute ( Tween24Event . PAUSE ) ; } } ; memberof skip = ( ) => { this . _skip ( ) ; } ; private _skip ( ) { this . _skiped = true ; if ( this . _playingChildTween ) { for ( const tween of this . _playingChildTween . concat ( ) ) { tween . _skip ( ) ; } } this . __update ( 0 ) ; } memberof stop = ( ) => { this . _stop ( ) ; this . _functionExecute ( Tween24Event . STOP ) ; } ; private _stop ( ) { this . _tweenStop ( ) ; if ( this . _childTween ) { for ( const tween of this . _childTween ) { if ( tween . _childTween ) tween . _stop ( ) ; else tween . _tweenStop ( ) ; } } } private _initParam ( ) { if ( this . _isDOM && this . _targetQuery && HTMLUtil . isPseudoQuery ( this . _targetQuery ) ) HTMLUtil . setTweenElementQuery ( this . _singleTarget || this . _multiTarget , this . _targetQuery ) ; if ( this . _allUpdaters ?. length ) { for ( const updater of this . _allUpdaters ) { updater . init ( this . _root ?. _useWillChange || this . _parent ?. _useWillChange || this . _useWillChange ) ; } } if ( this . _singleTarget ) this . _overwrite ( this . _singleTarget ) ; else if ( this . _multiTarget ) { for ( const target of this . _multiTarget ) { this . _overwrite ( target ) ; } } } private _overwrite ( target ) { let tweens = Tween24 . _playingTweensByTarget . get ( target ) ; if ( tweens ) { for ( const tween of tweens ) { if ( this !== tween ) { if ( this . _singleTarget ) { if ( this . _objectUpdater ) ( tween . _objectMultiUpdater || tween . _objectUpdater ) ?. overwrite ( this . _objectUpdater ) ; if ( this . _transformUpdater ) ( tween . _transformMultiUpdater || tween . _transformUpdater ) ?. overwrite ( this . _transformUpdater ) ; if ( this . _styleUpdater ) ( tween . _styleMultiUpdater || tween . _styleUpdater ) ?. overwrite ( this . _styleUpdater ) ; } else if ( this . _multiTarget ) { if ( tween . _objectMultiUpdater ) this . _objectMultiUpdater ?. overwriteMultiTo ( tween . _objectMultiUpdater ) ; else if ( tween . _objectUpdater ) this . _objectMultiUpdater ?. overwriteTo ( tween . _objectUpdater ) ; if ( tween . _transformMultiUpdater ) this . _transformMultiUpdater ?. overwriteMultiTo ( tween . _transformMultiUpdater ) ; else if ( tween . _transformUpdater ) this . _transformMultiUpdater ?. overwriteTo ( tween . _transformUpdater ) ; if ( tween . _styleMultiUpdater ) this . _styleMultiUpdater ?. overwriteMultiTo ( tween . _styleMultiUpdater ) ; else if ( tween . _styleUpdater ) this . _styleMultiUpdater ?. overwriteTo ( tween . _styleUpdater ) ; } } } tweens . push ( this ) ; } else { Tween24 . _playingTweensByTarget . set ( target , [ this ] ) ; } } private _setIfCaseTween ( flag ) { if ( this . _childTween ) this . _childTween . length = 0 ; else this . _childTween = [ ] ; if ( flag && this . _trueTween ) this . _childTween = [ this . _trueTween ] ; else if ( this . _falseTween ) this . _childTween = [ this . _falseTween ] ; else this . _childTween = [ ] ; this . _numChildren = this . _childTween . length ; } manualUpdate = ( ) => { this . __update ( Ticker24 . getTime ( ) ) ; } ; public __update ( nowTime ) { this . _updateProgress ( this . _time , this . _startTime , nowTime ) ; if ( this . _progress < 0 ) return ; if ( ! this . _inited ) { this . _inited = true ; this . _initParam ( ) ; this . _functionExecute ( Tween24Event . INIT ) ; } if ( this . _isContainerTween ) { if ( this . _firstUpdated == false ) { this . _firstUpdated = true ; if ( this . _type == Tween24 . _TYPE_IF_CASE_BY_FUNC ) { this . _setIfCaseTween ( this . _ifFunc ? Boolean ( this . _ifFunc ( ) ) : false ) ; } switch ( this . _type ) { case Tween24 . _TYPE_SERIAL : if ( this . _firstTween ) { this . _playingChildTween ?. push ( this . _firstTween ) ; this . _firstTween . _play ( ) ; } break ; case Tween24 . _TYPE_PARALLEL : case Tween24 . _TYPE_LAG : case Tween24 . _TYPE_LOOP : case Tween24 . _TYPE_IF_CASE : case Tween24 . _TYPE_IF_CASE_BY_FUNC : if ( this . _childTween ) { for ( const tween of this . _childTween ) { this . _playingChildTween ?. push ( tween ) ; tween . _play ( ) ; } } break ; } } if ( this . _playingChildTween ) { for ( const tween of this . _playingChildTween ) { tween . __update ( nowTime ) ; } } this . _functionExecute ( Tween24Event . UPDATE ) ; if ( this . _numChildren == this . _numCompleteChildren ) this . _complete ( ) ; } else { this . _firstUpdated = true ; if ( this . _singleTarget || this . _multiTarget ) { var prog = this . _easing ? this . _easing ( this . _progress , 0 , 1 , 1 ) : this . _progress ; if ( this . _allUpdaters ?. length ) { for ( const updater of this . _allUpdaters ) { updater . update ( prog ) ; } } this . _functionExecute ( Tween24Event . UPDATE ) ; } else { this . _functionExecute ( Tween24Event . UPDATE ) ; } if ( ! Number . isNaN ( this . _jumpProg ) && ! this . _jumped && this . _progress >= this . _jumpProg ) { this . _jumped = true ; this . _parent ?. _playNextTween ( this ) ; } if ( this . _progress >= 1 ) { if ( ( this . _type == Tween24 . _TYPE_WAIT_EVENT || this . _type == Tween24 . _TYPE_WAIT_EVENT_AND_FUNC ) && this . _dispatchEventTarget && this . _dispatchEventType ) { if ( this . _eventWaiting == false ) { this . _eventWaiting = true ; const waitHandler = ( ) => { this . _eventWaiting = false ; if ( this . _dispatchEventType ) Event24 . remove ( this . _dispatchEventTarget , this . _dispatchEventType ) ; this . _complete ( ) ; } ; Event24 . __addCallback ( this . _dispatchEventTarget , this . _dispatchEventType , waitHandler ) ; if ( this . _type == Tween24 . _TYPE_WAIT_EVENT_AND_FUNC ) this . _functionExecute ( Tween24 . _TYPE_WAIT_EVENT_AND_FUNC ) ; } } else { if ( this . _type == Tween24 . _TYPE_FUNC ) { this . _functionExecute ( Tween24 . _TYPE_FUNC ) ; } this . _complete ( ) ; } } } } private _complete ( ) { this . _debugLog ( "complete" ) ; if ( this . _type == Tween24 . _TYPE_LOOP ) { this . _currentLoops ++ ; if ( this . _numLoops == 0 || this . _numLoops > this . _currentLoops ) { this . _numCompleteChildren = 0 ; this . _play ( ) ; return ; } } if ( this . _parent ) this . _parent . _completeChildTween ( this ) ; this . _functionExecute ( Tween24Event . COMPLATE ) ; this . _tweenStop ( ) ; } private _tweenStop ( ) { if ( this . _isRoot ) Tween24 . ticker . remove ( this ) ; if ( this . _playingChildTween ) this . _playingChildTween . length = 0 ; this . _numCompleteChildren = 0 ; this . _played = false ; this . _inited = false ; this . _jumped = false ; this . _skiped = false ; this . _triggered = false ; this . _firstUpdated = false ; ArrayUtil . removeItemFromArray ( Tween24 . _playingTweensByTarget . get ( this . _singleTarget ) , this ) ; ArrayUtil . removeItemFromArray ( Tween24 . _playingTweens , this ) ; if ( this . _isManual ) ArrayUtil . removeItemFromArray ( Tween24 . _manualPlayingTweens , this ) ; } private _completeChildTween ( tween ) { this . _numCompleteChildren ++ ; if ( ! this . _triggered && tween . _isTrigger ) { if ( this . _parent ) { this . _triggered = true ; this . _parent . _playNextTween ( this ) ; } } if ( this . _numChildren == this . _numCompleteChildren ) { this . _complete ( ) ; } else if ( this . _playingChildTween ) { ArrayUtil . removeItemFromArray ( this . _playingChildTween , tween ) ; if ( ! tween . _triggered && ! tween . _jumped ) { this . _playNextTween ( tween ) ; } } } private _playNextTween ( childTween ) { var next = childTween . _next ; if ( this . _playingChildTween && next ) { this . _playingChildTween . push ( next ) ; next . _play ( ) ; } } private _updateProgress ( time , startTime , nowTime ) { if ( this . _skiped ) this . _progress = 1 ; else if ( nowTime < startTime ) this . _progress = - 1 ; else if ( time == 0 ) this . _progress = 1 ; else { this . _progress = ( nowTime - startTime ) / ( time * 1000 ) ; this . _progress = ( this . _progress > 1 ) ? 1 : this . _progress ; } return this . _progress ; } param { number | string } value return { Tween24 } memberof x ( value ) { return ClassUtil . isNumber ( value ) ? this . _setPropety ( "x" , parseFloat ( value as string ) ) : this . _setPropetyStr ( "x" , value as string ) ; } param { number | string } value return { Tween24 } memberof y ( value ) { return ClassUtil . isNumber ( value ) ? this . _setPropety ( "y" , parseFloat ( value as string ) ) : this . _setPropetyStr ( "y" , value as string ) ; } param { number | string } x param { number | string } y return { Tween24 } memberof xy ( x , y ) { return this . x ( x ) . y ( y ) ; } param { number } value return { Tween24 } memberof alpha ( value ) { return this . _isDOM ? this . _setStyle ( "opacity" , value ) : this . _setPropety ( "alpha" , value ) ; } param { number } value return { Tween24 } memberof opacity ( value ) { return this . _isDOM ? this . _setStyle ( "opacity" , value ) : this . _setPropety ( "opacity" , value ) ; } param { number } value return { Tween24 } memberof scaleX ( value ) { return this . _setPropety ( "scaleX" , value ) ; } param { number } value return { Tween24 } memberof scaleY ( value ) { return this . _setPropety ( "scaleY" , value ) ; } param { number } value return { Tween24 } memberof scale ( value ) { return this . _setPropety ( "scaleX" , value ) . _setPropety ( "scaleY" , value ) ; } param { number } scaleX param { number } scaleY return { Tween24 } memberof scaleXY ( scaleX , scaleY ) { return this . _setPropety ( "scaleX" , scaleX ) . _setPropety ( "scaleY" , scaleY ) ; } param { number } value return { Tween24 } memberof skewX ( value ) { return this . _setPropety ( "skewX" , value ) ; } param { number } value return { Tween24 } memberof skewY ( value ) { return this . _setPropety ( "skewY" , value ) ; } param { number } value return { Tween24 } memberof skew ( value ) { return this . _setPropety ( "skewX" , value ) . _setPropety ( "skewY" , value ) ; } param { number } skewX param { number } skewY return { Tween24 } memberof skewXY ( skewX , skewY ) { return this . _setPropety ( "skewX" , skewX ) . _setPropety ( "skewY" , skewY ) ; } param { number } value return { Tween24 } memberof rotation ( value ) { return this . _setPropety ( "rotation" , value ) ; } param { number } value return { Tween24 } memberof angle ( value ) { return this . _isDOM ? this . _setStyle ( "rotation" , value ) : this . _setPropety ( "angle" , value ) ; } param { number | string } 上からの配置位置 return { Tween24 } memberof top ( value ) { return this . _setStyle ( "top" , StringUtil . addUnit ( value ) ) ; } param { number | string } 右からの配置位置 return { Tween24 } memberof right ( value ) { return this . _setStyle ( "right" , StringUtil . addUnit ( value ) ) ; } param { number | string } value return { Tween24 } memberof bottom ( value ) { return this . _setStyle ( "bottom" , StringUtil . addUnit ( value ) ) ; } param { number | string } value return { Tween24 } memberof left ( value ) { return this . _setStyle ( "left" , StringUtil . addUnit ( value ) ) ; } param { number | string } value return { Tween24 } memberof width ( value ) { return this . _isDOM ? this . _setStyle ( "width" , StringUtil . addUnit ( value ) ) : this . _setPropety ( "width" , parseInt ( value as string ) ) ; } param { number | string } value return { Tween24 } memberof height ( value ) { return this . _isDOM ? this . _setStyle ( "height" , StringUtil . addUnit ( value ) ) : this . _setPropety ( "height" , parseInt ( value as string ) ) ; } param { string } colorCode return { Tween24 } memberof color ( colorCode ) { return this . _setStyle ( "color" , colorCode ) ; } param { string } colorCode return { Tween24 } memberof backgroundColor ( colorCode ) { return this . _setStyle ( "background-color" , colorCode ) ; } param { number | string } value return { Tween24 } memberof borderWidth ( value ) { return this . _setStyle ( "border-width" , StringUtil . addUnit ( value ) ) ; } param { number } colorCode return { Tween24 } memberof borderColor ( colorCode ) { return this . _setStyle ( "border-color" , colorCode ) ; } param { number | string } value return { Tween24 } memberof borderRadius ( value ) { return this . _setStyle ( "border-radius" , StringUtil . addUnit ( value ) ) ; } param { number | string } value return { Tween24 } memberof letterSpacing ( value ) { return this . _setStyle ( "letter-spacing" , StringUtil . addUnit ( value ) ) ; } param { number } value return { Tween24 } memberof delay ( value ) { this . _delayTime += value ; return this ; } param { string } name param { ( number | string ) } value return { Tween24 } memberof style ( name , value ) { return this . _setStyle ( name , value ) ; } param { boolean } use return { Tween24 } memberof willChange ( use = true ) { this . _useWillChange = use ; return this ; } return { Tween24 } memberof trigger ( ) { this . _isTrigger = true ; return this ; } param { number } progress return { Tween24 } memberof jump ( progress ) { this . _jumpProg = progress ; return this ; } param { number } fps return { Tween24 } memberof fps ( fps ) { this . __fps = fps ; return this ; } param { boolean } flag return { Tween24 } memberof debug ( flag = true ) { this . _debugMode = flag ; return this ; } private _setPropety ( key , value ) { this . createBasicUpdater ( ) ; if ( this . _singleTarget ) { if ( this . _objectUpdater ) this . _objectUpdater . addProp ( key , value ) ; else if ( this . _transformUpdater ) this . _transformUpdater . addProp ( key , value ) ; } else if ( this . _multiTarget ) { if ( this . _objectMultiUpdater ) this . _objectMultiUpdater . addProp ( key , value ) ; else if ( this . _transformMultiUpdater ) this . _transformMultiUpdater . addProp ( key , value ) ; } return this ; } private _setPropetyStr ( key , value ) { this . createBasicUpdater ( ) ; if ( this . _singleTarget ) { if ( this . _transformUpdater ) this . _transformUpdater . addPropStr ( key , value ) ; } else if ( this . _multiTarget ) { if ( this . _transformMultiUpdater ) this . _transformMultiUpdater . addPropStr ( key , value ) ; } return this ; } private _setStyle ( name , value ) { name = StringUtil . toKebab ( name ) ; if ( this . _singleTarget ) { if ( ! this . _styleUpdater ) { this . _styleUpdater = new StyleUpdater ( this . _singleTarget , this . _targetQuery ) ; this . _allUpdaters ?. push ( this . _styleUpdater ) ; } this . _styleUpdater . addPropStr ( name , value as string ) ; } else if ( this . _multiTarget ) { if ( ! this . _styleMultiUpdater ) { this . _styleMultiUpdater = new MultiUpdater ( this . _multiTarget , this . _targetQuery ) . setupByType ( StyleUpdater . className ) ; this . _allUpdaters ?. push ( this . _styleMultiUpdater ) ; } this . _styleMultiUpdater . addPropStr ( name , value as string ) ; } return this ; } private createBasicUpdater ( ) { if ( this . _createdBasicUpdater ) return ; this . _createdBasicUpdater = true ; let updater = null ; if ( this . _isDOM ) { if ( this . _singleTarget ) updater = this . _transformUpdater ||= new TransformUpdater ( this . _singleTarget , this . _targetQuery ) ; else if ( this . _multiTarget ) updater = this . _transformMultiUpdater ||= new MultiUpdater ( this . _multiTarget , this . _targetQuery ) . setupByType ( TransformUpdater . className ) ; } else { if ( this . _singleTarget ) updater = this . _objectUpdater ||= new ObjectUpdater ( this . _singleTarget ) ; else if ( this . _multiTarget ) updater = this . _objectMultiUpdater ||= new MultiUpdater ( this . _multiTarget , this . _targetQuery ) . setupByType ( ObjectUpdater . className ) ; } if ( updater ) this . _allUpdaters ?. push ( updater ) ; } param { Function } func param { ... any [ ] } args return { Tween24 } memberof onPlay ( func , ... args ) { return this . _setFunctionExecute ( Tween24Event . PLAY , func , func , args ) ; } param { Function } func param { ... any [ ] } args return { Tween24 } memberof onInit ( func , ... args ) { return this . _setFunctionExecute ( Tween24Event . INIT , func , func , args ) ; } param { Function } func param { ... any [ ] } args return { Tween24 } memberof onUpdate ( func , ... args ) { return this . _setFunctionExecute ( Tween24Event . UPDATE , func , func , args ) ; } param { Function } func param { ... any [ ] } args return { Tween24 } memberof onPause ( func , ... args ) { return this . _setFunctionExecute ( Tween24Event . PAUSE , func , func , args ) ; } param { Function } func param { ... any [ ] } args return { Tween24 } memberof onResume ( func , ... args ) { return this . _setFunctionExecute ( Tween24Event . RESUME , func , func , args ) ; } param { Function } func param { ... any [ ] } args return { Tween24 } memberof onStop ( func , ... args ) { return this . _setFunctionExecute ( Tween24Event . STOP , func , func , args ) ; } param { Function } func param { ... any [ ] } args return { Tween24 } memberof onComplete ( func , ... args ) { return this . _setFunctionExecute ( Tween24Event . COMPLATE , func , func , args ) ; } private _setFunctionExecute ( key , scope , func , args ) { this . _functionExecuters ||= { } ; this . _functionExecuters [ key ] = new FunctionExecuter ( scope , func , args ) ; return this ; } private _functionExecute ( key ) { if ( this . _functionExecuters ) { this . _functionExecuters [ key ] ?. execute ( ) ; } } static param { * } target param { number } time param { ( Function | null ) } easing param { ( { [ key : string ] : number } | null ) } params return { Tween24 } memberof static tween ( target , time , easing = null , params = null ) { return new Tween24 ( ) . _createChildTween ( Tween24 . _TYPE_TWEEN , target , time , easing , params ) ; } static param { * } target param { number } velocity param { ( Function | null ) } easing param { ( { [ key : string ] : number } | null ) } params return { Tween24 } memberof static tweenVelocity ( target , velocity , easing = null , params = null ) { return new Tween24 ( ) . _createChildTween ( Tween24 . _TYPE_TWEEN_VELOCITY , target , velocity , easing , params ) ; } static param { * } target param { ( { [ key : string ] : number } | null ) } params return { Tween24 } memberof static prop ( target , params = null ) { return new Tween24 ( ) . _createChildTween ( Tween24 . _TYPE_PROP , target , 0 , null , params ) ; } static param { string } targetQuery return { Tween24 } memberof static propText ( targetQuery ) { return Tween24 . _tweenText ( Tween24 . _TYPE_PROP_TEXT , targetQuery , 0 , null ) ; } static param { string } targetQuery param { number } time param { ( Function | null ) } easing return { Tween24 } memberof static tweenText ( targetQuery , time , easing = null ) { return Tween24 . _tweenText ( Tween24 . _TYPE_TWEEN_TEXT , targetQuery , time , easing ) ; } static param { string } targetQuery return { Tween24 } memberof static resetText ( targetQuery ) { return Tween24 . func ( Text24 . removeByTarget , targetQuery ) ; } static param { string } targetQuery param { number } velocity param { ( Function | null ) } easing return { Tween24 } memberof static tweenTextVelocity ( targetQuery , velocity , easing = null ) { return Tween24 . _tweenText ( Tween24 . _TYPE_TWEEN_VELOCITY , targetQuery , velocity , easing ) ; } private static _tweenText ( type , targetQuery , timeOrVelocity , easing = null ) { const targets = HTMLUtil . querySelectorAll ( targetQuery ) ; const textElements = [ ] ; for ( const target of targets ) { const text = Text24 . getInstance ( target ) ; if ( text ) { textElements . push ( ... text . targets ) ; } else { const text = new Text24 ( target , target . textContent ?. trim ( ) || "" , false , false ) ; textElements . push ( ... text . targets ) ; } } const tween = new Tween24 ( ) . _createChildTween ( type , textElements , timeOrVelocity , easing , null ) ; tween . _targetQuery = targetQuery + " span" ; return tween ; } static param { number } time return { Tween24 } memberof static wait ( time ) { return new Tween24 ( ) . _createChildTween ( Tween24 . _TYPE_WAIT , null , time , null , null ) ; } static param { Function } func param { ... any [ ] } args return { Tween24 } memberof static func ( func , ... args ) { return new Tween24 ( ) . _createActionTween ( Tween24 . _TYPE_FUNC ) . _setFunctionExecute ( Tween24 . _TYPE_FUNC , func , func , args ) ; } static param { * } target param { string } type return { Tween24 } memberof static waitEvent ( target , type ) { return new Tween24 ( ) . _createActionTween ( Tween24 . _TYPE_WAIT_EVENT ) . _setWaitEvent ( target , type ) ; } static param { * } target param { string } type param { Function } func param { ... any [ ] } args return { Tween24 } memberof static waitEventAndFunc ( target , type , func , ... args ) { return new Tween24 ( ) . _createActionTween ( Tween24 . _TYPE_WAIT_EVENT_AND_FUNC ) . _setWaitEvent ( target , type ) . _setFunctionExecute ( Tween24 . _TYPE_WAIT_EVENT_AND_FUNC , func , func , args ) ; } private _setWaitEvent ( target , type ) { this . _dispatchEventTarget = target ; this . _dispatchEventType = type ; return this ; } static param { ... any [ ] } message return { Tween24 } memberof static log ( ... message ) { return new Tween24 ( ) . _createActionTween ( Tween24 . _TYPE_FUNC ) . _setFunctionExecute ( Tween24 . _TYPE_FUNC , window , window . console . log , message ) ; } static param { ... Tween24 [ ] } childTween return { Tween24 } memberof static serial ( ... childTween ) { return new Tween24 ( ) . _createContainerTween ( Tween24 . _TYPE_SERIAL , childTween ) ; } static param { ... Tween24 [ ] } childTween return { Tween24 } memberof static parallel ( ... childTween ) { return new Tween24 ( ) . _createContainerTween ( Tween24 . _TYPE_PARALLEL , childTween ) ; } static param { number } lagTime param { ... Tween24 [ ] } childTween return { Tween24 } memberof static lag ( lagTime , ... childTween ) { return Tween24 . lagSort ( lagTime , Sort24 . _Normal , ... childTween ) ; } static param { number } lagTime param { Function } sort param { ... Tween24 [ ] } childTween return { Tween24 } memberof static lagSort ( lagTime , sort , ... childTween ) { const tweens = [ ] ; for ( const tween of childTween ) { if ( tween . _multiTarget ) { const targets = sort == Sort24 . _Normal ? tween . _multiTarget : sort ( tween . _multiTarget ) ; for ( let i = 0 ; i < targets . length ; i ++ ) { const t = targets [ i ] ; tweens . push ( tween . __clone ( t , tween . _targetQuery ) . delay ( lagTime * i ) ) ; } } else { tweens . push ( tween ) ; } } const tween = new Tween24 ( ) . _createContainerTween ( Tween24 . _TYPE_LAG , tweens ) ; tween . _lagTime = lagTime ; tween . _lagSort = sort ; tween . _originalChildTween = childTween ; return tween ; } static param { number } totalLagTime param { ... Tween24 [ ] } childTween return { Tween24 } memberof static lagTotal ( totalLagTime , ... childTween ) { return Tween24 . lagTotalSortEase ( totalLagTime , Sort24 . _Normal , Ease24 . _Linear , ... childTween ) ; } static param { number } totalLagTime param { Function } easing param { ... Tween24 [ ] } childTween return { Tween24 } memberof static lagTotalEase ( totalLagTime , easing , ... childTween ) { return Tween24 . lagTotalSortEase ( totalLagTime , Sort24 . _Normal , easing , ... childTween ) ; } static param { number } totalLagTime param { Function } sort param { ... Tween24 [ ] } childTween return { Tween24 } memberof static lagTotalSort ( totalLagTime , sort , ... childTween ) { return Tween24 . lagTotalSortEase ( totalLagTime , sort , Ease24 . _Linear , ... childTween ) ; } static param { number } totalLagTime param { Function } sort param { Function } easing param { ... Tween24 [ ] } childTween return { Tween24 } memberof static lagTotalSortEase ( totalLagTime , sort , easing , ... childTween ) { const tweens = [ ] ; for ( const tween of childTween ) { if ( tween . _multiTarget ) { const targets = sort == Sort24 . _Normal ? tween . _multiTarget : sort ( tween . _multiTarget ) ; const numTarget = targets . length ; for ( let i = 0 ; i < numTarget ; i ++ ) { const delay = easing ( ( i + 1 ) / numTarget , 0 , totalLagTime , 1 ) ; tweens . push ( tween . __clone ( targets [ i ] , tween . _targetQuery ) . delay ( delay ) ) ; } } else { tweens . push ( tween ) ; } } const tween = new Tween24 ( ) . _createContainerTween ( Tween24 . _TYPE_LAG , tweens ) ; tween . _totalLagTime = totalLagTime ; tween . _lagSort = sort ; tween . _lagEasing = easing ; tween . _originalChildTween = childTween ; return tween ; } static param { number } numLoops param { Tween24 } tween return { Tween24 } memberof static loop ( numLoops , tween ) { const loopTween = new Tween24 ( ) . _createContainerTween ( Tween24 . _TYPE_LOOP , [ tween ] ) ; loopTween . _numLoops = numLoops ; loopTween . _currentLoops = 0 ; return loopTween ; } static param { boolean | ( ( ) => boolean ) } flag param { Tween24 } trueTween param { ( Tween24 | null ) } falseTween return { Tween24 } memberof static ifCase ( flag , trueTween , falseTween = null ) { let tween ; if ( typeof ( flag ) == "function" ) { tween = new Tween24 ( ) . _createContainerTween ( Tween24 . _TYPE_IF_CASE_BY_FUNC , falseTween ? [ trueTween , falseTween ] : [ trueTween ] ) ; tween . _ifFunc = flag ; } else { tween = new Tween24 ( ) . _createContainerTween ( Tween24 . _TYPE_IF_CASE , flag ? [ trueTween ] : falseTween ? [ falseTween ] : [ ] ) ; } tween . _trueTween = trueTween ; tween . _falseTween = falseTween ; return tween ; } static param { ( ) => boolean } func param { Tween24 } trueTween param { ( Tween24 | null ) } falseTween return { Tween24 } memberof private _createChildTween ( type , target , timeOrVelocity , easing , params ) { this . _type = type ; this . _easing = easing || Tween24 . _defaultEasing ; this . _delayTime = 0 ; this . _startTime = 0 ; this . _allUpdaters = [ ] ; this . _isContainerTween = false ; if ( type == Tween24 . _TYPE_TWEEN_VELOCITY || type == Tween24 . _TYPE_TWEEN_TEXT_VELOCITY ) { this . _time = 0 ; this . _velocity = timeOrVelocity ; } else { this . _time = timeOrVelocity ; } this . _commonProcess ( ) ; if ( Array . isArray ( target ) ) { if ( ClassUtil . isString ( target [ 0 ] ) ) { this . _targetString = `[${ target . toString ( ) }]` ; this . _warningLog ( "Does not support array type queries." ) ; } else if ( target [ 0 ] instanceof HTMLElement ) { this . _isDOM = true ; this . _targetString = `[HTMLElements]` ; this . _multiTarget = target ; } else { this . _multiTarget = target ; } } else if ( ClassUtil . isString ( target ) ) { this . _isDOM = true ; this . _targetString = `${ target }` ; this . _targetQuery = target ; const t = HTMLUtil . querySelectorAll ( target ) ; if ( t . length <= 1 ) { this . _singleTarget = t [ 0 ] ; } else { this . _multiTarget = t ; } } else if ( target instanceof HTMLElement ) { this . _isDOM = true ; this . _singleTarget = target ; } else { this . _singleTarget = target ; } if ( params ) { for ( const key in params ) { this . _setPropety ( key , params [ key ] ) ; } } return this ; } private _createContainerTween ( type , childTween ) { this . _type = type ; this . _time = 0 ; this . _delayTime = 0 ; this . _childTween = childTween ; this . _firstTween = this . _childTween [ 0 ] ; this . _playingChildTween = [ ] ; this . _numChildren = childTween . length ; this . _numCompleteChildren = 0 ; this . _isContainerTween = true ; this . _commonProcess ( ) ; var prev = this . _firstTween ; var next ; if ( type == Tween24 . _TYPE_SERIAL ) { for ( var i = 0 ; i < this . _numChildren ; i ++ ) { next = this . _childTween [ i + 1 ] ; prev . _next = next ; prev . _parent = this ; prev = next ; } } else { for ( const tween of this . _childTween ) { tween . _parent = this ; } } return this ; } private _createActionTween ( type ) { this . _type = type ; this . _time = 0 ; this . _delayTime = 0 ; this . _startTime = 0 ; this . _isContainerTween = false ; this . _commonProcess ( ) ; return this ; } private _commonProcess ( ) { this . _serialNumber = ++ Tween24 . _numCreateTween ; } param { string } id return { Tween24 } memberof id ( id ) { return this . _setTweenId ( id ) ; } static param { string } id memberof static playById = ( id ) => { Tween24 . _controlTweens ( Tween24 . _getTweensById ( id ) , Tween24Event . PLAY ) ; } ; static param { string } id memberof static manualPlayById = ( id ) => { Tween24 . _controlTweens ( Tween24 . _getTweensById ( id ) , Tween24Event . MANUAL_PLAY ) ; } ; static param { string } id memberof static pauseById = ( id ) => { Tween24 . _controlTweens ( Tween24 . _getTweensById ( id ) , Tween24Event . PAUSE ) ; } ; static param { string } id memberof static skipById = ( id ) => { Tween24 . _controlTweens ( Tween24 . _getTweensById ( id ) , Tween24Event . SKIP ) ; } ; static param { string } id memberof static stopById = ( id ) => { Tween24 . _controlTweens ( Tween24 . _getTweensById ( id ) , Tween24Event . STOP ) ; } ; param { string } groupId return { Tween24 } memberof groupId ( groupId ) { return this . _setTweenGroupId ( groupId ) ; } static param { string } groupId memberof static playByGroupId = ( groupId ) => { Tween24 . _controlTweens ( Tween24 . _getTweensByGroupId ( groupId ) , Tween24Event . PLAY ) ; } ; static param { string } groupId memberof static manualPlayByGroupId = ( groupId ) => { Tween24 . _controlTweens ( Tween24 . _getTweensByGroupId ( groupId ) , Tween24Event . MANUAL_PLAY ) ; } ; static param { string } groupId memberof static pauseByGroupId = ( groupId ) => { Tween24 . _controlTweens ( Tween24 . _getTweensByGroupId ( groupId ) , Tween24Event . PAUSE ) ; } ; static param { string } groupId memberof static skipByGroupId = ( groupId ) => { Tween24 . _controlTweens ( Tween24 . _getTweensByGroupId ( groupId ) , Tween24Event . SKIP ) ; } ; static param { string } groupId memberof static stopByGroupId = ( groupId ) => { Tween24 . _controlTweens ( Tween24 . _getTweensByGroupId ( groupId ) , Tween24Event . STOP ) ; } ; private _setTweenId ( id ) { this . _tweenId = id ; Tween24 . _tweensById ||= new Map < string , Tween24 > ( ) ; Tween24 . _tweensById . set ( id , this ) ; return this ; } private _setTweenGroupId ( groupId ) { this . _tweenGroupId = groupId ; Tween24 . _tweensByGroupId ||= new Map < string , Tween24 [ ] > ( ) ; const groupTweens = Tween24 . _tweensByGroupId . get ( groupId ) || [ ] ; groupTweens . push ( this ) ; Tween24 . _tweensByGroupId . set ( groupId , groupTweens ) ; return this ; } private static _getTweensById ( id ) { const tween = Tween24 . _tweensById ?. get ( id ) ; return tween ? [ tween ] : undefined ; } private static _getTweensByGroupId ( groupId ) { return Tween24 . _tweensByGroupId ?. get ( groupId ) ; } private static _controlTweens ( tweens , event ) { if ( tweens ) { switch ( event ) { case Tween24Event . PLAY : tweens . forEach ( ( tween ) => { tween . play ( ) ; } ) ; break ; case Tween24Event . MANUAL_PLAY : tweens . forEach ( ( tween ) => { tween . manualPlay ( ) ; } ) ; break ; case Tween24Event . PAUSE : tweens . forEach ( ( tween ) => { tween . pause ( ) ; } ) ; break ; case Tween24Event . SKIP : tweens . forEach ( ( tween ) => { tween . skip ( ) ; } ) ; break ; case Tween24Event . STOP : tweens . forEach ( ( tween ) => { tween . stop ( ) ; } ) ; break ; } } } static param { number } fps memberof static setFPS = ( fps = 0 ) => { Tween24 . ticker . fps = fps ; } ; static param { Function } easing memberof static setDefaultEasing = ( easing = Ease24 . _Linear ) => { Tween24 . _defaultEasing = easing ; } ; static param { boolean } flag memberof static debugMode = ( flag ) => { Tween24 . _debugMode = flag ; } ; static manualAllUpdate = ( ) => { const nowTime = Ticker24 . getTime ( ) ; for ( const tween of Tween24 . _manualPlayingTweens ) { tween . __update ( nowTime ) ; } } ; __clone ( base , baseQuery ) { let copy = new Tween24 ( ) ; let target ; if ( this . _targetQuery && baseQuery ) { for ( const query of this . _targetQuery . split ( "," ) ) { if ( query == baseQuery ) { target = base ; } else { const reg = new RegExp ( "^" + baseQuery + " " ) ; if ( reg . test ( this . _targetQuery ) ) { target = HTMLUtil . querySelectorAllWithBase ( base , this . _targetQuery . replace ( reg , "" ) ) ; } else { target = this . _singleTarget || this . _multiTarget ; } } } } else { target = base ; } switch ( this . _type ) { case Tween24 . _TYPE_TWEEN : case Tween24 . _TYPE_TWEEN_VELOCITY : case Tween24 . _TYPE_TWEEN_TEXT : case Tween24 . _TYPE_TWEEN_TEXT_VELOCITY : case Tween24 . _TYPE_PROP : case Tween24 . _TYPE_PROP_TEXT : copy . _createChildTween ( this . _type , target , this . _velocity || this . _time , this . _easing , null ) ; copy . _targetQuery = this . _targetQuery ; if ( this . _allUpdaters ?. length ) { if ( this . _singleTarget && copy . _multiTarget ) { for ( const updater of this . _allUpdaters ) { copy . _allUpdaters ?. push ( new MultiUpdater ( copy . _multiTarget , this . _targetQuery ) . setupByUpdater ( updater ) ) ; } } else { for ( const updater of this . _allUpdaters ) { copy . _allUpdaters ?. push ( updater . clone ( copy . _singleTarget || copy . _multiTarget , this . _targetQuery ) ) ; } } } break ; case Tween24 . _TYPE_WAIT : copy . _createChildTween ( this . _type , target , this . _time , this . _easing , null ) ; break ; case Tween24 . _TYPE_SERIAL : case Tween24 . _TYPE_PARALLEL : case Tween24 . _TYPE_LOOP : const tweens = [ ] ; if ( this . _childTween ) { for ( const tween of this . _childTween ) { tweens . push ( tween . __clone ( base , baseQuery ) ) ; } } copy . _createContainerTween ( this . _type , tweens ) ; copy . _numLoops = this . _numLoops ; break ; case Tween24 . _TYPE_LAG : const lagTweens = [ ] ; if ( this . _originalChildTween ) { for ( const tween of this . _originalChildTween ) { lagTweens . push ( tween . __clone ( base , baseQuery ) ) ; } } if ( ! isNaN ( this . _lagTime ) ) { copy = Tween24 . lagSort ( this . _lagTime , this . _lagSort || Sort24 . _Normal , ... lagTweens ) ; } else { copy = Tween24 . lagTotalSortEase ( this . _totalLagTime , this . _lagSort || Sort24 . _Normal , this . _lagEasing || Ease24 . _Linear , ... lagTweens ) ; } break ; case Tween24 . _TYPE_FUNC : copy . _type = this . _type ; copy . _time = copy . _delayTime = copy . _startTime = 0 ; copy . _isContainerTween = false ; break ; } if ( this . _functionExecuters ) { copy . _functionExecuters = { } ; for ( const key in this . _functionExecuters ) { copy . _functionExecuters [ key ] = this . _functionExecuters [ key ] . clone ( ) ; } } copy . willChange ( this . _useWillChange ) ; copy . delay ( this . _delayTime ) . fps ( this . __fps ) . debug ( this . _debugMode ) ; return copy ; } toString ( ) { return `Tween24 ${ this . getTweenTypeString ( ) } ${ this . getTweenParamString ( ) }` ; } private _debugLog ( message ) { if ( Tween24 . _debugMode || this . _debugMode || this . _root ?. _debugMode || this . _parent ?. _debugMode ) { const margin = "  " . repeat ( this . _numLayers ) ; console . log ( `${ margin }${ this . getTweenTypeString ( ) } ${ message } ${ this . getTweenParamString ( ) }` ) ; } } private _warningLog ( message ) { console . log ( `Tween24 Warning: ${ message }\n - ${ this . toString ( ) }` ) ; } private getTweenTypeString ( ) { let type = "" ; type += this . _parent ? `${ this . _parent . _type }/` : "" ; type += this . _type ; return `[${ type }]` ; } private getTweenParamString ( ) { let param = "" ; param += this . _targetString ? `target:${ this . _targetString }` : ( `id:${ this . _tweenId || this . _serialNumber }` ) ; switch ( this . _type ) { case Tween24 . _TYPE_TWEEN : case Tween24 . _TYPE_WAIT : case Tween24 . _TYPE_TWEEN_TEXT : param += " time:" + this . _time + " " ; break ; case Tween24 . _TYPE_TWEEN_VELOCITY : case Tween24 . _TYPE_TWEEN_TEXT_VELOCITY : param += " velocity:" + this . _velocity + " " ; break ; } if ( this . _delayTime ) { param += " delay:" + this . _delayTime + " " ; } if ( this . _allUpdaters ) { for ( const updater of this . _allUpdaters ) { param += updater . toString ( ) + " " ; } } return `{${ param . replace ( /\s+/g , " " ) . trim ( ) }}` ; } }