import vivliostyle from "../models/vivliostyle" ; import DocumentOptions from "../models/document-options" ; import ViewerOptions from "../models/viewer-options" ; import messageQueue from "../models/message-queue" ; import Viewer from "./viewer" ; import Navigation from "./navigation" ; import SettingsPanel from "./settings-panel" ; import MessageDialog from "./message-dialog" ; import keyUtil from "../utils/key-util" ; import stringUtil from "../utils/string-util" ; import urlParameters from "../stores/url-parameters" ; function ViewerApp ( ) { this . documentOptions = new DocumentOptions ( ) ; this . viewerOptions = new ViewerOptions ( ) ; this . documentOptions . pageStyle . setViewerFontSizeObservable ( this . viewerOptions . fontSize ) ; if ( this . viewerOptions . profile ( ) ) { vivliostyle . profile . profiler . enable ( ) ; } this . isDebug = urlParameters . getParameter ( "debug" ) [ 0 ] === "true" ; this . viewerSettings = { userAgentRootURL : `${ urlParameters . getBaseURL ( ) }resources/` , viewportElement : document . getElementById ( "vivliostyle-viewer-viewport" ) , debug : this . isDebug } ; if ( urlParameters . getParameter ( "b" ) [ 0 ] ) { urlParameters . removeParameter ( "b" , true ) ; urlParameters . removeParameter ( "x" ) ; } urlParameters . removeParameter ( "f" , true ) ; urlParameters . removeParameter ( "spread" , true ) ; urlParameters . removeParameter ( "renderAllPages" , true ) ; urlParameters . removeParameter ( "fontSize" , true ) ; urlParameters . removeParameter ( "profile" , true ) ; urlParameters . removeParameter ( "debug" , true ) ; this . viewer = new Viewer ( this . viewerSettings , this . viewerOptions ) ; this . viewer . inputUrl . subscribe ( inputUrl => { if ( inputUrl != "" ) { if ( ! urlParameters . hasParameter ( "b" ) ) { if ( urlParameters . history . pushState ) urlParameters . history . pushState ( null , "" ) ; } if ( inputUrl . startsWith ( "<" ) ) { inputUrl = "data:," + stringUtil . percentEncodeForDataURI ( inputUrl ) ; } else { inputUrl = stringUtil . percentEncodeAmpersandAndUnencodedPercent ( inputUrl ) ; } urlParameters . setParameter ( "b" , inputUrl ) ; } else { urlParameters . removeParameter ( "b" ) ; } } ) ; this . messageDialog = new MessageDialog ( messageQueue ) ; const settingsPanelOptions = { disablePageStyleChange : false , disablePageViewModeChange : false , disableRenderAllPagesChange : false } ; this . settingsPanel = new SettingsPanel ( this . viewerOptions , this . documentOptions , this . viewer , this . messageDialog , settingsPanelOptions ) ; const navigationOptions = { disableTOCNavigation : false , disablePageNavigation : false , disableZoom : false , disableFontSizeChange : false } ; this . navigation = new Navigation ( this . viewerOptions , this . viewer , this . settingsPanel , navigationOptions ) ; this . handleKey = ( data , event ) => { const key = keyUtil . identifyKeyFromEvent ( event ) ; if ( document . activeElement . id === "vivliostyle-input-url" ) { if ( key === "Enter" && event . keyCode === 13 ) { this . documentOptions . bookUrl ( urlParameters . getParameter ( "b" ) [ 0 ] ) ; this . viewer . loadDocument ( this . documentOptions ) ; return false ; } return true ; } if ( ( ! ( key === "Home" || key === "End" ) && ( event . ctrlKey || event . metaKey ) ) || event . altKey || event . shiftKey ) { return true ; } let ret = this . settingsPanel . handleKey ( key ) ; if ( ret ) { ret = this . navigation . handleKey ( key ) ; } return ret ; } ; this . viewer . loadDocument ( this . documentOptions ) ; window . onhashchange = ( ) => { if ( window . location . href != urlParameters . storedUrl ) { window . location . reload ( ) ; } } ; } export default ViewerApp ;