define(["exports","./../dom.js","./../common/querystring.js"],function(_exports,_dom,_querystring){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var prevContext,prevPageContext,base="",allRoutes=[];function page(path,routeInfo,fn){"function"==typeof fn?(page.callbacks[path.toUpperCase()]={routeInfo:routeInfo,fn:fn},allRoutes.push(routeInfo)):page.start(path)}page.getRoutes=function(){return allRoutes},page.callbacks={},page.current="",page.base=function(path){if(0===arguments.length)return base;base=path};var loaded="complete"===document.readyState;function onpopstate(e){var path;loaded&&!function(event){event=event.state||{};return!1!==previousPopState.navigate?(previousPopState=event,!1):(previousPopState=event,!0)}(e)&&(e.state?(path=e.state.path,page.replace(path,e.state,null,!0)):page.show(location.pathname+location.hash,void 0,void 0,!1,!0))}function decodeURLEncodedURIComponent(val){return"string"!=typeof val?val:decodeURIComponent(val.replace(/\+/g," "))}function Context(path,state){var i=(path="/"===path[0]&&0!==path.indexOf(base)?base+"#!"+path:path).indexOf("?");this.canonicalPath=path,this.path=path.replace(base,"")||"/",this.path=this.path.replace("#!","")||"/",this.title=document.title,this.state=state||{},this.state.path=path,this.querystring=~i?decodeURLEncodedURIComponent(path.slice(i+1)):"",this.params=this.querystring?_querystring.default.parse(this.querystring):{},this.pathname=decodeURLEncodedURIComponent(~i?path.slice(0,i):path),this.hash=""}loaded||_dom.default.addEventListener(window,"load",function onWindowLoad(){setTimeout(function(){loaded=!0},0),_dom.default.removeEventListener(window,"load",onWindowLoad,{once:!0})},{once:!0}),page.start=function(options){var url;!1!==(options=options||{}).popstate&&window.addEventListener("popstate",onpopstate,!1),~location.hash.indexOf("#!")?(url=location.hash.substr(2),(options=location.href.toString()).indexOf("?")>=options.indexOf("#!")&&(url+=location.search)):url=location.pathname+location.search+location.hash,page.replace(url,null,!0)},page.show=function(path,state,dispatch,push,isBack){path=new Context(path,state);return path.isBack=isBack,page.current=path.path,!1!==dispatch&&page.dispatch(path),!1!==path.handled&&!1!==push&&path.pushState(),path},page.restorePreviousState=function(){prevContext=prevPageContext,page.show(prevContext.pathname,prevContext.state,!1,!0,!1)},page.back=function(){history.back()},page.forward=function(){history.forward()},page.canGoBack=function(){return 1