import { Share } from './share' ; import { UserManager } from './UserManager' ; import { Layout } from './Layout' ; import { getCanvas , getContainer } from "./main" ; /**
 * this class handles the navigation in the board (halfpage by halfpage etc.)
 */ export class BoardNavigation { /**
     * initialize the navigation to be to the most-left part of the canvas (sometimes scrollLeft is not set to 0
     * because the browser stores its value)
     */ static init ( ) { BoardNavigation . setScroll ( 0 ) ; } static _rightExtendCanvasEnable = true ; returns static scrollQuantity ( ) { return 100 ; } private static _left ( x ) { if ( x <= 0 ) { BoardNavigation . showPageNumber ( 0 ) ; x = 0 ; } BoardNavigation . setScroll ( x ) ; } private static _right ( x ) { const MAXCANVASWIDTH = 32000 ; const container = getContainer ( ) ; const canvas = getCanvas ( ) ; document . getElementById ( "buttonLeft" ) . classList . remove ( "disabled" ) ; if ( container . scrollLeft >= MAXCANVASWIDTH - Layout . getWindowWidth ( ) ) { container . scrollLeft = MAXCANVASWIDTH - Layout . getWindowWidth ( ) ; return ; } if ( x >= canvas . width - Layout . getWindowWidth ( ) ) { if ( BoardNavigation . _rightExtendCanvasEnable ) { Share . execute ( "setWidthAtLeast" , [ ( ( canvas . width / Layout . scrollQuantityPage ( ) ) + 1 ) * Layout . scrollQuantityPage ( ) ] ) ; BoardNavigation . _rightExtendCanvasEnable = false ; setTimeout ( ( ) => { BoardNavigation . _rightExtendCanvasEnable = true ; } , 1000 ) ; } x = Math . min ( x , canvas . width - Layout . getWindowWidth ( ) ) ; } BoardNavigation . setScroll ( x ) ; } /**
   * go left
   */ static left ( ) { BoardNavigation . _left ( getContainer ( ) . scrollLeft - BoardNavigation . scrollQuantity ( ) ) ; } /**
     * go right (and extend the board if necessary)
     */ static right ( ) { const x = getContainer ( ) . scrollLeft + BoardNavigation . scrollQuantity ( ) ; BoardNavigation . _right ( x ) ; } static setScroll ( x ) { if ( x <= 0 ) document . getElementById ( "buttonLeft" ) . classList . add ( "disabled" ) ; getContainer ( ) . scrollTo ( { top : 0 , left : x , behavior : 'smooth' } ) ; setTimeout ( UserManager . setSymbolCursorPosition , 1000 ) ; } /**
 * go left
 */ static leftPreviousPage ( ) { const container = getContainer ( ) ; const xCorrected = Layout . isCalibratedHalfPage ( ) ? Math . max ( 0 , container . scrollLeft - Layout . scrollQuantityPage ( ) ) : Layout . correctOnLeft ( container . scrollLeft ) ; BoardNavigation . _left ( xCorrected ) ; BoardNavigation . showPageNumber ( xCorrected ) ; } /**
    * go right (and extend the board if necessary)
    */ static rightNextPage ( ) { const xCorrected = Layout . isCalibratedHalfPage ( ) ? getContainer ( ) . scrollLeft + Layout . scrollQuantityPage ( ) : Layout . correctOnRight ( getContainer ( ) . scrollLeft ) ; BoardNavigation . _right ( xCorrected ) ; BoardNavigation . showPageNumber ( xCorrected ) ; } static showPageNumber ( x ) { const pageNumber = document . getElementById ( "pageNumber" ) ; const canvas = getCanvas ( ) ; pageNumber . classList . remove ( "pageNumberHidden" ) ; pageNumber . classList . remove ( "pageNumber" ) ; setTimeout ( ( ) => { const n = Math . round ( x / Layout . scrollQuantityPage ( ) ) ; const total = Math . round ( canvas . width / Layout . scrollQuantityPage ( ) ) ; pageNumber . innerHTML = ( n + 1 ) + "/" + ( total ) ; pageNumber . classList . add ( "pageNumber" ) ; } , 300 ) ; } }