import { PageCollection } from './Collection/PageCollection' ; import { ImagePageCollection } from './Collection/ImagePageCollection' ; import { HTMLPageCollection } from './Collection/HTMLPageCollection' ; import { PageRect , Point } from './BasicTypes' ; import { Flip , FlipCorner , FlippingState } from './Flip/Flip' ; import { Orientation , Render } from './Render/Render' ; import { CanvasRender } from './Render/CanvasRender' ; import { HTMLUI } from './UI/HTMLUI' ; import { CanvasUI } from './UI/CanvasUI' ; import { Helper } from './Helper' ; import { Page } from './Page/Page' ; import { EventObject } from './Event/EventObject' ; import { HTMLRender } from './Render/HTMLRender' ; import { FlipSetting , Settings } from './Settings' ; import { UI } from './UI/UI' ; import './Style/stPageFlip.css' ; extends EventObject export class PageFlip extends EventObject { private mousePosition : Point ; private isUserTouch = false ; private isUserMove = false ; private readonly setting : FlipSetting = null ; private readonly block : HTMLElement ; private pages : PageCollection = null ; private flipController : Flip ; private render : Render ; private ui : UI ; constructor param { HTMLElement } inBlock param { Object } setting constructor ( inBlock , setting ) { super ( ) ; this . setting = new Settings ( ) . getSettings ( setting ) ; this . block = inBlock ; } /**
     * Destructor. Remove a root HTML element and all event handlers
     */ public destroy ( ) { this . ui . destroy ( ) ; this . block . remove ( ) ; } /**
     * Update the render area. Re-show current page.
     */ public update ( ) { this . render . update ( ) ; this . pages . show ( ) ; } param { string [ ] } imagesHref public loadFromImages ( imagesHref ) { this . ui = new CanvasUI ( this . block , this , this . setting ) ; const canvas = ( this . ui as CanvasUI ) . getCanvas ( ) ; this . render = new CanvasRender ( this , this . setting , canvas ) ; this . flipController = new Flip ( this . render , this ) ; this . pages = new ImagePageCollection ( this , this . render , imagesHref ) ; this . pages . load ( ) ; this . render . start ( ) ; this . pages . show ( this . setting . startPage ) ; setTimeout ( ( ) => { this . ui . update ( ) ; this . trigger ( 'init' , this , { page : this . setting . startPage , mode : this . render . getOrientation ( ) , } ) ; } , 1 ) ; } param { ( NodeListOf < HTMLElement > | HTMLElement [ ] ) } items public loadFromHTML ( items ) { this . ui = new HTMLUI ( this . block , this , this . setting , items ) ; this . render = new HTMLRender ( this , this . setting , this . ui . getDistElement ( ) ) ; this . flipController = new Flip ( this . render , this ) ; this . pages = new HTMLPageCollection ( this , this . render , this . ui . getDistElement ( ) , items ) ; this . pages . load ( ) ; this . render . start ( ) ; this . pages . show ( this . setting . startPage ) ; setTimeout ( ( ) => { this . ui . update ( ) ; this . trigger ( 'init' , this , { page : this . setting . startPage , mode : this . render . getOrientation ( ) , } ) ; } , 1 ) ; } param { string [ ] } imagesHref public updateFromImages ( imagesHref ) { const current = this . pages . getCurrentPageIndex ( ) ; this . pages . destroy ( ) ; this . pages = new ImagePageCollection ( this , this . render , imagesHref ) ; this . pages . load ( ) ; this . pages . show ( current ) ; this . trigger ( 'update' , this , { page : current , mode : this . render . getOrientation ( ) , } ) ; } param { ( NodeListOf < HTMLElement > | HTMLElement [ ] ) } items public updateFromHtml ( items ) { const current = this . pages . getCurrentPageIndex ( ) ; this . pages . destroy ( ) ; this . pages = new HTMLPageCollection ( this , this . render , this . ui . getDistElement ( ) , items ) ; this . pages . load ( ) ; ( this . ui as HTMLUI ) . updateItems ( items ) ; this . render . reload ( ) ; this . pages . show ( current ) ; this . trigger ( 'update' , this , { page : current , mode : this . render . getOrientation ( ) , } ) ; } /**
     * Clear pages from HTML (remove to initinalState)
     */ public clear ( ) { this . pages . destroy ( ) ; ( this . ui as HTMLUI ) . clear ( ) ; } /**
     * Turn to the previous page (without animation)
     */ public turnToPrevPage ( ) { this . pages . showPrev ( ) ; } /**
     * Turn to the next page (without animation)
     */ public turnToNextPage ( ) { this . pages . showNext ( ) ; } param { number } page public turnToPage ( page ) { this . pages . show ( page ) ; } param { FlipCorner } corner public flipNext ( corner = FlipCorner . TOP ) { this . flipController . flipNext ( corner ) ; } param { FlipCorner } corner public flipPrev ( corner = FlipCorner . TOP ) { this . flipController . flipPrev ( corner ) ; } param { number } page param { FlipCorner } corner public flip ( page , corner = FlipCorner . TOP ) { this . flipController . flipToPage ( page , corner ) ; } param { FlippingState } newState public updateState ( newState ) { this . trigger ( 'changeState' , this , newState ) ; } param { number } newPage public updatePageIndex ( newPage ) { this . trigger ( 'flip' , this , newPage ) ; } param { Orientation } newOrientation public updateOrientation ( newOrientation ) { this . ui . setOrientationStyle ( newOrientation ) ; this . update ( ) ; this . trigger ( 'changeOrientation' , this , newOrientation ) ; } returns { number } public getPageCount ( ) { return this . pages . getPageCount ( ) ; } returns { number } public getCurrentPageIndex ( ) { return this . pages . getCurrentPageIndex ( ) ; } param { number } pageIndex returns { Page } public getPage ( pageIndex ) { return this . pages . getPage ( pageIndex ) ; } returns { Render } public getRender ( ) { return this . render ; } returns { Flip } public getFlipController ( ) { return this . flipController ; } returns { Orientation } public getOrientation ( ) { return this . render . getOrientation ( ) ; } returns { PageRect } public getBoundsRect ( ) { return this . render . getRect ( ) ; } returns { FlipSetting } public getSettings ( ) { return this . setting ; } returns { UI } public getUI ( ) { return this . ui ; } returns { FlippingState } public getState ( ) { return this . flipController . getState ( ) ; } returns { PageCollection } public getPageCollection ( ) { return this . pages ; } param { Point } pos public startUserTouch ( pos ) { this . mousePosition = pos ; this . isUserTouch = true ; this . isUserMove = false ; } param { Point } pos param { boolean } isTouch public userMove ( pos , isTouch ) { if ( ! this . isUserTouch && ! isTouch && this . setting . showPageCorners ) { this . flipController . showCorner ( pos ) ; } else if ( this . isUserTouch ) { if ( Helper . GetDistanceBetweenTwoPoint ( this . mousePosition , pos ) > 5 ) { this . isUserMove = true ; this . flipController . fold ( pos ) ; } } } param { Point } pos param { boolean } isSwipe public userStop ( pos , isSwipe = false ) { if ( this . isUserTouch ) { this . isUserTouch = false ; if ( ! isSwipe ) { if ( ! this . isUserMove ) this . flipController . flip ( pos ) ; else this . flipController . stopMove ( ) ; } } } }