import { App , PJAX , HistoryManager , TransitionManager , PageManager , Router } from "@okikio/native" ; import { Navbar } from "./services/Navbar" ; import { themeSet , themeGet } from "./scripts/theme" ; import RegisterServiceWorker from "./register-sw" ; import * as Accordion from "./modules/accordion" ; import { animate } from "@okikio/animate" ; import type { ITransition , IHistoryItem } from "@okikio/native" ; try { let themeSwitch = Array . from ( document . querySelectorAll ( ".theme-options" ) ) as HTMLSelectElement [ ] ; if ( themeSwitch [ 0 ] ) { for ( let el of themeSwitch ) { el . value = themeGet ( ) ; el . addEventListener ( "change" , ( ) => { themeSet ( el . value ) ; el . value = themeGet ( ) ; } ) ; } } } catch ( e ) { console . warn ( "Theming seems to break on this browser." , e ) ; } let canScroll = true ; const navbar = document . querySelector ( ".navbar" ) as HTMLElement ; window . addEventListener ( "scroll" , ( ) => { if ( canScroll ) { canScroll = false ; requestAnimationFrame ( ( ) => { navbar . classList . toggle ( "shadow" , window . scrollY >= 5 ) ; canScroll = true ; } ) ; } } , { passive : true } ) ; let oldShareURL = new URL ( String ( document . location ) ) ; try { const app = new App ( ) ; const Fade = { name : "default" , out ( { from } ) { let fromWrapper = from . wrapper ; return animate ( { target : fromWrapper , opacity : [ 1 , 0 ] , duration : 500 , } ) ; } , async in ( { to , scroll } ) { let toWrapper = to . wrapper ; window . scroll ( scroll . x , scroll . y ) ; await animate ( { target : toWrapper , opacity : [ 0 , 1 ] , duration : 500 } ) ; } } ; app . add ( new Navbar ( ) ) . set ( "HistoryManager" , new HistoryManager ( ) ) . set ( "PageManager" , new PageManager ( ) ) . set ( "TransitionManager" , new TransitionManager ( [ [ "default" , Fade ] , ] ) ) . set ( "Router" , new Router ( ) ) . add ( new PJAX ( ) ) ; let indexRun = async ( ) => { const { build , InitialRender } = await import ( "./index" ) ; InitialRender ( oldShareURL ) ; build ( app ) ; } ; app . emitter . once ( "index" , async ( ) => { indexRun ( ) ; } ) ; if ( /^\/(\#.*)?(index)?(\.html)?$/ . test ( oldShareURL . toString ( ) ) ) app . emitter . emit ( "index" ) ; let router = app . get ( "Router" ) as Router ; router . add ( { path : /^\/(\#.*)?(index)?(\.html)?$/ , method ( ) { app . emitter . emit ( "index" ) ; } } ) ; app . boot ( ) ; if ( oldShareURL ) { let historyManager = app . get ( "HistoryManager" ) as HistoryManager ; let { last } = historyManager ; let state = { ... last , url : oldShareURL . toString ( ) } ; historyManager . states . pop ( ) ; historyManager . states . push ( { ... state } ) ; let item = { index : historyManager . pointer , states : [ ... historyManager . states ] } ; window . history . replaceState ( item , "" , state . url ) ; } } catch ( err ) { console . warn ( "[App] boot failed," , err ) ; } const offlineIcons = Array . from ( document . querySelectorAll ( ".offline-icon" ) ) ; const hasNetwork = ( online ) => { offlineIcons . forEach ( el => { el ?. classList ?. toggle ( "online" , online ) ; } ) ; } ; hasNetwork ( navigator . onLine ) ; window . addEventListener ( "load" , ( ) => { hasNetwork ( navigator . onLine ) ; window . addEventListener ( "online" , ( ) => { hasNetwork ( true ) ; } ) ; window . addEventListener ( "offline" , ( ) => { hasNetwork ( false ) ; } ) ; } ) ; Accordion . run ( ) ; RegisterServiceWorker ( ) ; export { } ;