From 69ba508a65155f129648f12702f4a3aecd4eba42 Mon Sep 17 00:00:00 2001 From: okikio Date: Wed, 9 Dec 2020 13:59:23 -0500 Subject: [PATCH] fix: :bug: fix scrolling bug that stops scrolling during transition, and popstate fix readme address bug, README's WIP, update src to fix scrolling bugs to access the scroll coords in transistions use the scroll parameter in the out method e.g. out({ ..., scroll }) {} --- packages/native/lib/api.js | 4 ++-- packages/native/lib/api.js.map | 6 +++--- packages/native/lib/api.modern.js | 4 ++-- packages/native/lib/api.modern.js.map | 6 +++--- packages/native/lib/api.node.js | 4 ++-- packages/native/lib/api.node.js.map | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/native/lib/api.js b/packages/native/lib/api.js index 9fc3f7e..142c88e 100644 --- a/packages/native/lib/api.js +++ b/packages/native/lib/api.js @@ -1,3 +1,3 @@ -var native=(()=>{var rt=Object.defineProperty,pt=r=>rt(r,"__esModule",{value:!0}),ct=(r,t)=>{pt(r);for(var e in t)rt(r,e,{get:t[e],enumerable:!0})},ut={};ct(ut,{AdvancedManager:()=>E,Animate:()=>j,App:()=>$,CONFIG:()=>L,CONFIG_DEFAULTS:()=>V,DefaultAnimationOptions:()=>tt,Event:()=>w,EventEmitter:()=>x,HistoryManager:()=>C,Manager:()=>u,ManagerItem:()=>A,PARSER:()=>q,PJAX:()=>B,Page:()=>g,PageManager:()=>k,Router:()=>Y,Service:()=>T,ServiceManager:()=>O,TransitionManager:()=>H,animate:()=>ot,asyncMethodCall:()=>G,clean:()=>F,computeValue:()=>D,easings:()=>Q,equal:()=>P,getEase:()=>Z,getElements:()=>J,getHash:()=>nt,getHashedPath:()=>h,getTargets:()=>X,hashAction:()=>W,mapObject:()=>_,methodCall:()=>y,newCoords:()=>R,newListener:()=>K,newState:()=>M,newURL:()=>p});var V={wrapperAttr:"wrapper",noAjaxLinkAttr:"no-ajax-link",noPrefetchAttr:"no-prefetch",headers:[["x-partial","true"]],preventSelfAttr:'prevent="self"',preventAllAttr:'prevent="all"',transitionAttr:"transition",blockAttr:"block",timeout:3e4},L=class{constructor(t){this.config=Object.assign({...V},t)}toAttr(t,e=!0){let{prefix:i}=this.config,n=`data${i?"-"+i:""}-${t}`;return e?`[${n}]`:n}getConfig(t,e=!0){if(typeof t!="string")return this.config;let i=this.config[t];return typeof i=="string"?this.toAttr(i,e):i}};var u=class{constructor(t){this.map=new Map(t)}getMap(){return this.map}get(t){return this.map.get(t)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(t,e){return this.map.set(t,e),this}add(t){let e=this.size,i=e;return this.set(i,t),this}get size(){return this.map.size}get length(){return this.map.size}last(t=1){let e=this.keys()[this.size-t];return this.get(e)}delete(t){return this.map.delete(t)}remove(t){return this.map.delete(t),this}clear(){return this.map.clear(),this}has(t){return this.map.has(t)}entries(){return this.map.entries()}forEach(t=(...i)=>{},e){return this.map.forEach(t,e),this}[Symbol.iterator](){return this.entries()}},y=(r,t,...e)=>{r.forEach(i=>{i[t](...e)})},G=async(r,t,...e)=>{for(let[,i]of r)await i[t](...e)},A=class{constructor(){}install(){}register(t,e){return this.manager=t,this.app=t.app,this.config=t.config,this.emitter=t.emitter,this.key=e,this.install(),this}uninstall(){}unregister(){this.uninstall(),this.manager.delete(this.key),this.key=void 0,this.manager=void 0,this.app=void 0,this.config=void 0,this.emitter=void 0}},E=class extends u{constructor(t){super();this.app=t,this.config=t.config,this.emitter=t.emitter}set(t,e){return super.set(t,e),e.register(this,t),this}};var p=(r=window.location.href)=>r instanceof URL?r:new URL(r,window.location.origin),h=r=>`${r.pathname}${r.hash}`,nt=r=>r.hash.slice(1),F=r=>r.toString().replace(/(\/#.*|\/|#.*)$/,""),P=(r,t)=>{let e=p(r),i=p(t);return F(e)===F(i)};var R=(r=window.scrollX,t=window.scrollY)=>({x:r,y:t}),M=(r={url:h(p()),index:0,transition:"default",data:{scroll:R(),trigger:"HistoryManager"}})=>r,C=class{constructor(){this.pointer=-1;this.states=[];let t=M();this.add(t,"replace")}get(t){return this.states[t]}add(t,e="push"){let i=M(t),n=this.length;this.states.push({...i}),this.pointer=n;let o={index:this.pointer,states:[...this.states]};return this.changeState(e,i,o),this}remove(t){return t?this.states.splice(t,1):this.states.pop(),this.pointer--,this}replace(t){return this.states=t,this}set(t,e){return this.states[t]=e}get current(){return this.get(this.pointer)}get last(){return this.get(this.length-1)}get previous(){return this.pointer<1?null:this.get(this.pointer-1)}get length(){return this.states.length}changeState(t,e,i){let n=h(p(e.url)),o=[i,"",n];if(window.history)switch(t){case"push":window.history.pushState.apply(window.history,o);break;case"replace":window.history.replaceState.apply(window.history,o);break}}};var q=new DOMParser,g=class extends A{constructor(t=p(),e=document){super();this.url=t,typeof e=="string"?this.data=e:this.dom=e||document}async build(){if(this.dom instanceof Node||(this.dom=q.parseFromString(this.data,"text/html")),!(this.body instanceof Node)){let{title:t,head:e,body:i}=this.dom;this.title=t,this.head=e,this.body=i,this.wrapper=this.body.querySelector(this.wrapperAttr)}}install(){this.wrapperAttr=this.config.getConfig("wrapperAttr")}uninstall(){this.url=void 0,this.title=void 0,this.head=void 0,this.body=void 0,this.dom=void 0,this.wrapper=void 0,this.data=void 0,this.wrapperAttr=void 0}},k=class extends E{constructor(t){super(t);this.loading=new u;this.maxPages=5;let e=p().pathname;this.set(e,new g),e=void 0}async load(t=p()){let e=p(t),i=e.pathname,n,o;if(this.has(i))return n=this.get(i),Promise.resolve(n);this.loading.has(i)?o=this.loading.get(i):(o=this.request(i),this.loading.set(i,o));let s=await o;if(this.loading.delete(i),n=new g(e,s),this.set(i,n),this.size>this.maxPages){let a=p(),l=this.keys(),c=P(a,l[0])?l[1]:l[0],m=this.get(c);m.unregister(),m=void 0,l=void 0,a=void 0,c=void 0}return n}async request(t){let e=new Headers(this.config.getConfig("headers")),i=window.setTimeout(()=>{throw window.clearTimeout(i),"Request Timed Out!"},this.config.getConfig("timeout"));try{let n=await fetch(t,{mode:"same-origin",method:"GET",headers:e,cache:"default",credentials:"same-origin"});if(window.clearTimeout(i),n.status>=200&&n.status<300)return await n.text();let o=new Error(n.statusText||""+n.status);throw o}catch(n){throw window.clearTimeout(i),n}}};var K=({callback:r=()=>{},scope:t=null,name:e="event"})=>({callback:r,scope:t,name:e}),w=class extends u{constructor(t="event"){super();this.name=t}},x=class extends u{constructor(){super()}getEvent(t){let e=this.get(t);return e instanceof w?e:(this.set(t,new w(t)),this.get(t))}newListener(t,e,i){let n=this.getEvent(t);return n.add(K({name:t,callback:e,scope:i})),n}on(t,e,i){if(typeof t=="undefined")return this;typeof t=="string"&&(t=t.trim().split(/\s/g));let n,o,s=typeof t=="object"&&!Array.isArray(t),a=s?e:i;return s||(o=e),Object.keys(t).forEach(l=>{s?(n=l,o=t[l]):n=t[l],this.newListener(n,o,a)},this),this}removeListener(t,e,i){let n=this.get(t);if(n instanceof w&&e){let o=K({name:t,callback:e,scope:i});n.forEach((s,a)=>{if(s.callback===o.callback&&s.scope===o.scope)return n.delete(a)})}return n}off(t,e,i){if(typeof t=="undefined")return this;typeof t=="string"&&(t=t.trim().split(/\s/g));let n,o,s=typeof t=="object"&&!Array.isArray(t),a=s?e:i;return s||(o=e),Object.keys(t).forEach(l=>{s?(n=l,o=t[l]):n=t[l],typeof o=="function"?this.removeListener(n,o,a):this.delete(n)},this),this}emit(t,...e){return typeof t=="undefined"?this:(typeof t=="string"&&(t=t.trim().split(/\s/g)),t.forEach(i=>{let n=this.get(i);n instanceof w&&n.forEach(o=>{let{callback:s,scope:a}=o;s.apply(a,e)})},this),this)}};var T=class extends A{install(){let{app:t}=this.manager;this.PageManager=t.pages,this.HistoryManager=t.history,this.ServiceManager=t.services,this.TransitionManager=t.transitions}init(...t){}boot(){this.initEvents()}initEvents(){}stopEvents(){}uninstall(){this.PageManager=void 0,this.HistoryManager=void 0,this.ServiceManager=void 0,this.TransitionManager=void 0}stop(){this.stopEvents(),this.unregister()}},O=class extends E{constructor(t){super(t)}init(){return y(this,"init",this.app),this}boot(){return y(this,"boot",this.app),this}stop(){return y(this,"stop",this.app),this}};var H=class extends u{constructor(t){super();this.app=t,this.config=t.config,this.emitter=t.emitter}async boot(t,e){let i=this.get(t);if(!(e.oldPage instanceof g)||!(e.newPage instanceof g))throw`[Page] either oldPage or newPage aren't instances of the Page Class. - ${{newPage:e.newPage,oldPage:e.oldPage}}`;let n=e.oldPage.wrapper,o=e.newPage.wrapper;if(document.title=""+e.newPage.title,!(n instanceof Node)||!(o instanceof Node))throw`[Wrapper] the wrapper from the ${o instanceof Node?"current":"next"} page cannot be found. The wrapper must be an element that has the attribute ${this.config.getConfig("wrapperAttr")}.`;return i.init&&i?.init(e),this.emitter.emit("BEFORE_TRANSITION_OUT"),await new Promise(s=>{let a=i.out.call(i,{from:e.oldPage,trigger:e.trigger,scroll,done:s});a.then&&a.then(s)}),this.emitter.emit("AFTER_TRANSITION_OUT"),await new Promise(s=>{n.insertAdjacentElement("beforebegin",o),this.emitter.emit("CONTENT_INSERT"),s()}),await new Promise(s=>{n.remove(),n=void 0,o=void 0,this.emitter.emit("CONTENT_REPLACED"),s()}),this.emitter.emit("BEFORE_TRANSITION_IN"),await new Promise(s=>{let a=i.in.call(i,{from:e.oldPage,to:e.newPage,trigger:e.trigger,scroll,done:s});a.then&&a.then(s)}),this.emitter.emit("AFTER_TRANSITION_IN"),i}};var $=class{constructor(t={}){this.register(t)}register(t={}){this.config=t instanceof L?t:new L(t),this.emitter=new x,this.history=new C,this.pages=new k(this),this.transitions=new H(this),this.services=new O(this);let e=(()=>{document.removeEventListener("DOMContentLoaded",e),window.removeEventListener("load",e),this.emitter.emit("READY ready")}).bind(this);return document.addEventListener("DOMContentLoaded",e),window.addEventListener("load",e),this}get(t,e){switch(t.toLowerCase()){case"service":return this.services.get(e);case"transition":return this.transitions.get(e);case"state":return this.history.get(e);default:throw`Error: can't get type '${t}', it is not a recognized type. Did you spell it correctly.`}}async load(t,e){switch(t.toLowerCase()){case"page":return await this.pages.load(e);default:return Promise.resolve(this.get(t,e))}}setService(t,e){return this.services.set(t,e),this}setTransition(t,e){return this.transitions.set(t,e),this}add(t,e){switch(t.toLowerCase()){case"service":this.services.add(e);break;case"transition":this.transitions.set(e.name,e);break;case"state":this.history.add(e);break;default:throw`Error: can't add type '${t}', it is not a recognized type. Did you spell it correctly.`}return this}boot(){return this.services.init(),this.services.boot(),this}stop(){return this.services.stop(),this}on(t,e){return this.emitter.on(t,e,this),this}off(t,e){return this.emitter.off(t,e,this),this}emit(t,...e){return this.emitter.emit(t,...e),this}};var B=class extends T{constructor(){super(...arguments);this.ignoreURLs=[];this.prefetchIgnore=!1;this.isTransitioning=!1;this.stopOnTransitioning=!1;this.stickyScroll=!1;this.forceOnError=!1;this.autoScrollOnHash=!0;this.dontScroll=!0}transitionStart(){this.isTransitioning=!0}transitionStop(){this.isTransitioning=!1}init(){super.init(),this.onHover=this.onHover.bind(this),this.onClick=this.onClick.bind(this),this.onStateChange=this.onStateChange.bind(this)}boot(){"scrollRestoration"in window.history&&(window.history.scrollRestoration="manual"),super.boot()}getTransitionName(t){if(!t||!t.getAttribute)return null;let e=t.getAttribute(this.config.getConfig("transitionAttr",!1));return typeof e=="string"?e:null}validLink(t,e,i){let n=!window.history.pushState,o=!t||!i,s=e.metaKey||e.ctrlKey||e.shiftKey||e.altKey,a=t.hasAttribute("target")&&t.target==="_blank",l=t.protocol!==location.protocol||t.hostname!==location.hostname,c=typeof t.getAttribute("download")=="string",m=t.hasAttribute(this.config.getConfig("preventSelfAttr",!1)),f=Boolean(t.closest(this.config.getConfig("preventAllAttr"))),v=m&&f,z=h(p())===h(p(i));return!(o||n||s||a||l||c||v||z)}getHref(t){return t&&t.tagName&&t.tagName.toLowerCase()==="a"&&typeof t.href=="string"?t.href:null}getLink(t){let e=t.target,i=this.getHref(e);for(;e&&!i;)e=e.parentNode,i=this.getHref(e);return!e||!this.validLink(e,t,i)?void 0:e}onClick(t){let e=this.getLink(t);if(!e)return;if(this.isTransitioning&&this.stopOnTransitioning){t.preventDefault(),t.stopPropagation();return}let i=this.getHref(e);this.emitter.emit("ANCHOR_CLICK CLICK",t),this.go({href:i,trigger:e,event:t})}getDirection(t){return Math.abs(t)>1?t>0?"forward":"back":t===0?"popstate":t>0?"back":"forward"}force(t){window.location.assign(t)}go({href:t,trigger:e="HistoryManager",event:i}){if(this.isTransitioning&&this.stopOnTransitioning){this.force(t);return}let n={x:0,y:0},o=this.HistoryManager.current,s=o.url;if(P(s,t))return;let a;if(i&&i.state){this.emitter.emit("POPSTATE",i);let{state:l}=i,{index:c}=l,m=o.index,f=m-c;e=this.getDirection(f),this.HistoryManager.replace(l.states),this.HistoryManager.pointer=c,e==="back"?this.emitter.emit("POPSTATE_BACK",i):e==="forward"&&this.emitter.emit("POPSTATE_FORWARD",i);let v=this.HistoryManager.get(c);a=v.transition,e!=="popstate"&&(n=v.data.scroll)}else{a=this.getTransitionName(e)||"default";let l=R();if(!this.dontScroll&&this.stickyScroll){let{x:m,y:f}=l;n={x:m,y:f}}else n={x:0,y:0};let c=M({url:t,transition:a,data:{scroll:l}});this.HistoryManager.add(c),this.emitter.emit("HISTORY_NEW_ITEM",i)}return i&&(i.stopPropagation(),i.preventDefault()),this.emitter.emit("GO",i),this.load({oldHref:s,href:t,trigger:e,transitionName:a,scroll:n})}async load({oldHref:t,href:e,trigger:i,transitionName:n="default",scroll:o={x:0,y:0}}){try{let s=await this.PageManager.load(t);await s.build();let a;this.emitter.emit("PAGE_LOADING",{href:e,oldPage:s,trigger:i});try{try{a=await this.PageManager.load(e),await a.build(),this.transitionStart(),this.emitter.emit("PAGE_LOAD_COMPLETE",{newPage:a,oldPage:s,trigger:i})}catch(l){console.error(`[PJAX] page load error: ${l}`)}this.emitter.emit("NAVIGATION_START",{oldPage:s,newPage:a,trigger:i,transitionName:n});try{this.emitter.emit("TRANSITION_START",n);let l=await this.TransitionManager.boot(n,{oldPage:s,newPage:a,trigger:i,scroll:o});l.scrollable||(/back|popstate|forward/.test(i)||(o=W(e)),window.scroll(o.x,o.y)),this.emitter.emit("TRANSITION_END",{transition:l})}catch(l){console.error(`[PJAX] transition error: ${l}`)}this.emitter.emit("NAVIGATION_END",{oldPage:s,newPage:a,trigger:i,transitionName:n})}catch(l){throw this.transitionStop(),l}this.transitionStop()}catch(s){this.forceOnError?this.force(e):console.error(s)}}ignoredURL({pathname:t}){return this.ignoreURLs.length&&this.ignoreURLs.some(e=>typeof e=="string"?e===t:e.exec(t)!==null)}onHover(t){let e=this.getLink(t);if(!e)return;let i=p(this.getHref(e)),n=i.pathname;if(this.ignoredURL(i)||this.PageManager.has(n))return;this.emitter.emit("ANCHOR_HOVER HOVER",t);try{this.PageManager.load(i)}catch(o){console.warn("[PJAX] prefetch error,",o)}}onStateChange(t){this.go({href:window.location.href,trigger:"popstate",event:t})}initEvents(){this.prefetchIgnore!==!0&&(document.addEventListener("mouseover",this.onHover),document.addEventListener("touchstart",this.onHover)),document.addEventListener("click",this.onClick),window.addEventListener("popstate",this.onStateChange)}stopEvents(){this.prefetchIgnore!==!0&&(document.removeEventListener("mouseover",this.onHover),document.removeEventListener("touchstart",this.onHover)),document.removeEventListener("click",this.onClick),window.removeEventListener("popstate",this.onStateChange)}},W=(r=window.location.hash)=>{try{let t=r[0]=="#"?r:p(r).hash;if(t.length>1){let e=document.querySelector(t);if(e)return{x:e.offsetLeft,y:e.offsetTop}}}catch(t){console.warn("hashAction error",t)}return{x:0,y:0}};var Y=class extends T{constructor(t=[]){super();this.routes=new u;for(let e of t)this.add(e)}add({path:t,method:e}){let i=this.parse(t);return this.routes.set(i,e),this}parsePath(t){if(typeof t=="string")return new RegExp(t,"i");if(t instanceof RegExp||typeof t=="boolean")return t;throw"[Router] only regular expressions, strings and booleans are accepted as paths."}isPath(t){return typeof t=="string"||t instanceof RegExp||typeof t=="boolean"}parse(t){let e=t,i={from:/(.*)/g,to:/(.*)/g};if(this.isPath(t))i={from:!0,to:t};else if(this.isPath(e.from)&&this.isPath(e.to))i=e;else throw"[Router] path is neither a string, regular expression, or a { from, to } object.";let{from:n,to:o}=i;return{from:this.parsePath(n),to:this.parsePath(o)}}route(){let t=this.HistoryManager,e=h(p((t.length>1?t.previous:t.current).url)),i=h(p());this.routes.forEach((n,o)=>{let s=o.from,a=o.to;if(typeof s=="boolean"&&typeof a=="boolean")throw`[Router] path ({ from: ${s}, to: ${a} }) is not valid, remember paths can only be strings, regular expressions, or a boolean; however, both the from and to paths cannot be both booleans.`;let l=s,c=a;s instanceof RegExp&&s.test(e)&&(l=s.exec(e)),a instanceof RegExp&&a.test(i)&&(c=a.exec(i)),(Array.isArray(c)&&Array.isArray(l)||Array.isArray(c)&&typeof l=="boolean"&&l||Array.isArray(l)&&typeof c=="boolean"&&c)&&n({from:l,to:c,path:{from:e,to:i}})})}initEvents(){this.emitter.on("READY",this.route,this),this.emitter.on("CONTENT_REPLACED",this.route,this)}stopEvents(){this.emitter.off("READY",this.route,this),this.emitter.off("CONTENT_REPLACED",this.route,this)}};var J=r=>typeof r=="string"?Array.from(document.querySelectorAll(r)):[r],X=r=>Array.isArray(r)?r:typeof r=="string"||r instanceof Node?J(r):r instanceof NodeList||r instanceof HTMLCollection?Array.from(r):[],D=(r,t)=>typeof r=="function"?r(...t):r,_=(r,t)=>{let e,i,n={},o=Object.keys(r);for(let s=0,a=o.length;s/^(ease|in|out)/.test(r)?Q[r]:r,tt={keyframes:[],loop:1,delay:0,speed:1,endDelay:0,easing:"ease",autoplay:!0,duration:1e3,onfinish(){},fillMode:"auto",direction:"normal"},j=class{constructor(t={}){this.options={};this.targets=[];this.properties={};this.animations=new Map;this.duration=0;this.emitter=new x;let{options:e,...i}=t;this.options=Object.assign({},tt,e,i),this.loop=this.loop.bind(this);let{loop:n,delay:o,speed:s,easing:a,endDelay:l,duration:c,direction:m,fillMode:f,onfinish:v,target:z,keyframes:st,autoplay:at,...lt}=this.options;this.mainElement=document.createElement("span"),this.targets=X(z),this.properties=lt;let N;for(let b=0,S=this.targets.length;b0||(N=_(N,[b,S,I]));let et=d.delay+d.duration*d.iterations+d.endDelay;this.duration{v(I,b,S)},this.animations.set(I,it)}this.mainAnimation=this.mainElement.animate([{opacity:"0"},{opacity:"1"}],{duration:this.duration,easing:"linear"}),this.setSpeed(s),at?this.play():this.pause(),this.promise=this.newPromise(),this.mainAnimation.onfinish=()=>{this.finish(this.options),window.cancelAnimationFrame(this.animationFrame)}}getTargets(){return this.targets}newPromise(){return new Promise((t,e)=>{try{this.finish=i=>(this.emit("finish",i),t(i))}catch(i){e(i)}})}then(t,e){return this.promise.then(t,e)}catch(t){return this.promise.catch(t)}finally(t){return this.promise.finally(t)}loop(){this.animationFrame=window.requestAnimationFrame(this.loop),this.emit("tick change",this.getCurrentTime())}on(t,e,i){return this.emitter.on(t,e,i),this}off(t,e,i){return this.emitter.off(t,e,i),this}emit(t,...e){return this.emitter.emit(t,...e),this}getAnimation(t){return this.animations.get(t)}play(){return this.mainAnimation.playState!=="finished"&&(this.mainAnimation.play(),this.animationFrame=requestAnimationFrame(this.loop),this.animations.forEach(t=>{t.playState!=="finished"&&t.play()}),this.emit("play")),this}pause(){return this.mainAnimation.playState!=="finished"&&(this.mainAnimation.pause(),window.cancelAnimationFrame(this.animationFrame),this.animations.forEach(t=>{t.playState!=="finished"&&t.pause()}),this.emit("pause")),this}getDuration(){return this.duration}getCurrentTime(){return this.mainAnimation.currentTime}setCurrentTime(t){return this.mainAnimation.currentTime=t,this.animations.forEach(e=>{e.currentTime=t}),this}getProgress(){return this.getCurrentTime()/this.duration}setProgress(t){return this.mainAnimation.currentTime=t*this.duration,this.animations.forEach(e=>{e.currentTime=t*this.duration}),this}getSpeed(){return this.mainAnimation.playbackRate}setSpeed(t=1){return this.mainAnimation.playbackRate=t,this.animations.forEach(e=>{e.playbackRate=t}),this}reset(){this.setCurrentTime(0),this.promise=this.newPromise(),this.options.autoplay?this.play():this.pause()}getPlayState(){return this.mainAnimation.playState}getOptions(){return this.options}toJSON(){return this.getOptions()}},ot=(r={})=>new j(r);return ut;})(); +var native=(()=>{var nt=Object.defineProperty,ct=r=>nt(r,"__esModule",{value:!0}),ut=(r,t)=>{ct(r);for(var e in t)nt(r,e,{get:t[e],enumerable:!0})},ht={};ut(ht,{AdvancedManager:()=>A,Animate:()=>z,App:()=>Y,CONFIG:()=>L,CONFIG_DEFAULTS:()=>G,DefaultAnimationOptions:()=>et,Event:()=>w,EventEmitter:()=>x,HistoryManager:()=>C,Manager:()=>u,ManagerItem:()=>y,PARSER:()=>B,PJAX:()=>W,Page:()=>g,PageManager:()=>k,Router:()=>J,Service:()=>T,ServiceManager:()=>O,TransitionManager:()=>N,animate:()=>st,asyncMethodCall:()=>q,changeState:()=>$,clean:()=>K,computeValue:()=>_,easings:()=>Z,equal:()=>M,getEase:()=>tt,getElements:()=>X,getHash:()=>ot,getHashedPath:()=>h,getTargets:()=>Q,hashAction:()=>H,mapObject:()=>j,methodCall:()=>d,newCoords:()=>E,newListener:()=>D,newState:()=>P,newURL:()=>p});var G={wrapperAttr:"wrapper",noAjaxLinkAttr:"no-ajax-link",noPrefetchAttr:"no-prefetch",headers:[["x-partial","true"]],preventSelfAttr:'prevent="self"',preventAllAttr:'prevent="all"',transitionAttr:"transition",blockAttr:"block",timeout:3e4},L=class{constructor(t){this.config=Object.assign({...G},t)}toAttr(t,e=!0){let{prefix:i}=this.config,n=`data${i?"-"+i:""}-${t}`;return e?`[${n}]`:n}getConfig(t,e=!0){if(typeof t!="string")return this.config;let i=this.config[t];return typeof i=="string"?this.toAttr(i,e):i}};var u=class{constructor(t){this.map=new Map(t)}getMap(){return this.map}get(t){return this.map.get(t)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(t,e){return this.map.set(t,e),this}add(t){let e=this.size,i=e;return this.set(i,t),this}get size(){return this.map.size}get length(){return this.map.size}last(t=1){let e=this.keys()[this.size-t];return this.get(e)}delete(t){return this.map.delete(t)}remove(t){return this.map.delete(t),this}clear(){return this.map.clear(),this}has(t){return this.map.has(t)}entries(){return this.map.entries()}forEach(t=(...i)=>{},e){return this.map.forEach(t,e),this}[Symbol.iterator](){return this.entries()}},d=(r,t,...e)=>{r.forEach(i=>{i[t](...e)})},q=async(r,t,...e)=>{for(let[,i]of r)await i[t](...e)},y=class{constructor(){}install(){}register(t,e){return this.manager=t,this.app=t.app,this.config=t.config,this.emitter=t.emitter,this.key=e,this.install(),this}uninstall(){}unregister(){this.uninstall(),this.manager.delete(this.key),this.key=void 0,this.manager=void 0,this.app=void 0,this.config=void 0,this.emitter=void 0}},A=class extends u{constructor(t){super();this.app=t,this.config=t.config,this.emitter=t.emitter}set(t,e){return super.set(t,e),e.register(this,t),this}};var p=(r=window.location.href)=>r instanceof URL?r:new URL(r,window.location.origin),h=r=>`${r.pathname}${r.hash}`,ot=r=>r.hash.slice(1),K=r=>r.toString().replace(/(\/#.*|\/|#.*)$/,""),M=(r,t)=>{let e=p(r),i=p(t);return K(e)===K(i)};var E=(r=window.scrollX,t=window.scrollY)=>({x:r,y:t}),P=(r={url:h(p()),index:0,transition:"default",data:{scroll:E(),trigger:"HistoryManager"}})=>r,C=class{constructor(){this.pointer=-1;this.states=[];let t=P();this.add(t,"replace")}get(t){return this.states[t]}add(t,e="push"){let i=P(t),n=this.length;this.states.push({...i}),this.pointer=n;let o={index:this.pointer,states:[...this.states]};return $(e,i,o),this}remove(t){return t?this.states.splice(t,1):this.states.pop(),this.pointer--,this}replace(t){return this.states=t,this}set(t,e){return this.states[t]=e}get current(){return this.get(this.pointer)}get last(){return this.get(this.length-1)}get previous(){return this.pointer<1?null:this.get(this.pointer-1)}get length(){return this.states.length}},$=(r,t,e)=>{let i=h(p(t.url)),n=[e,"",i];if(window.history)switch(r){case"push":window.history.pushState.apply(window.history,n);break;case"replace":window.history.replaceState.apply(window.history,n);break}};var B=new DOMParser,g=class extends y{constructor(t=p(),e=document){super();this.url=t,typeof e=="string"?this.data=e:this.dom=e||document}async build(){if(this.dom instanceof Node||(this.dom=B.parseFromString(this.data,"text/html")),!(this.body instanceof Node)){let{title:t,head:e,body:i}=this.dom;this.title=t,this.head=e,this.body=i,this.wrapper=this.body.querySelector(this.wrapperAttr)}}install(){this.wrapperAttr=this.config.getConfig("wrapperAttr")}uninstall(){this.url=void 0,this.title=void 0,this.head=void 0,this.body=void 0,this.dom=void 0,this.wrapper=void 0,this.data=void 0,this.wrapperAttr=void 0}},k=class extends A{constructor(t){super(t);this.loading=new u;this.maxPages=5;let e=p().pathname;this.set(e,new g),e=void 0}async load(t=p()){let e=p(t),i=e.pathname,n,o;if(this.has(i))return n=this.get(i),Promise.resolve(n);this.loading.has(i)?o=this.loading.get(i):(o=this.request(i),this.loading.set(i,o));let s=await o;if(this.loading.delete(i),n=new g(e,s),this.set(i,n),this.size>this.maxPages){let a=p(),l=this.keys(),c=M(a,l[0])?l[1]:l[0],m=this.get(c);m.unregister(),m=void 0,l=void 0,a=void 0,c=void 0}return n}async request(t){let e=new Headers(this.config.getConfig("headers")),i=window.setTimeout(()=>{throw window.clearTimeout(i),"Request Timed Out!"},this.config.getConfig("timeout"));try{let n=await fetch(t,{mode:"same-origin",method:"GET",headers:e,cache:"default",credentials:"same-origin"});if(window.clearTimeout(i),n.status>=200&&n.status<300)return await n.text();let o=new Error(n.statusText||""+n.status);throw o}catch(n){throw window.clearTimeout(i),n}}};var D=({callback:r=()=>{},scope:t=null,name:e="event"})=>({callback:r,scope:t,name:e}),w=class extends u{constructor(t="event"){super();this.name=t}},x=class extends u{constructor(){super()}getEvent(t){let e=this.get(t);return e instanceof w?e:(this.set(t,new w(t)),this.get(t))}newListener(t,e,i){let n=this.getEvent(t);return n.add(D({name:t,callback:e,scope:i})),n}on(t,e,i){if(typeof t=="undefined")return this;typeof t=="string"&&(t=t.trim().split(/\s/g));let n,o,s=typeof t=="object"&&!Array.isArray(t),a=s?e:i;return s||(o=e),Object.keys(t).forEach(l=>{s?(n=l,o=t[l]):n=t[l],this.newListener(n,o,a)},this),this}removeListener(t,e,i){let n=this.get(t);if(n instanceof w&&e){let o=D({name:t,callback:e,scope:i});n.forEach((s,a)=>{if(s.callback===o.callback&&s.scope===o.scope)return n.delete(a)})}return n}off(t,e,i){if(typeof t=="undefined")return this;typeof t=="string"&&(t=t.trim().split(/\s/g));let n,o,s=typeof t=="object"&&!Array.isArray(t),a=s?e:i;return s||(o=e),Object.keys(t).forEach(l=>{s?(n=l,o=t[l]):n=t[l],typeof o=="function"?this.removeListener(n,o,a):this.delete(n)},this),this}emit(t,...e){return typeof t=="undefined"?this:(typeof t=="string"&&(t=t.trim().split(/\s/g)),t.forEach(i=>{let n=this.get(i);n instanceof w&&n.forEach(o=>{let{callback:s,scope:a}=o;s.apply(a,e)})},this),this)}};var T=class extends y{install(){let{app:t}=this.manager;this.PageManager=t.pages,this.HistoryManager=t.history,this.ServiceManager=t.services,this.TransitionManager=t.transitions}init(...t){}boot(){this.initEvents()}initEvents(){}stopEvents(){}uninstall(){this.PageManager=void 0,this.HistoryManager=void 0,this.ServiceManager=void 0,this.TransitionManager=void 0}stop(){this.stopEvents(),this.unregister()}},O=class extends A{constructor(t){super(t)}init(){return d(this,"init",this.app),this}boot(){return d(this,"boot",this.app),this}stop(){return d(this,"stop",this.app),this}};var W=class extends T{constructor(){super(...arguments);this.ignoreURLs=[];this.prefetchIgnore=!1;this.isTransitioning=!1;this.stopOnTransitioning=!1;this.stickyScroll=!1;this.forceOnError=!1;this.autoScrollOnHash=!0;this.dontScroll=!1}transitionStart(){this.isTransitioning=!0}transitionStop(){this.isTransitioning=!1}init(){super.init(),this.onHover=this.onHover.bind(this),this.onClick=this.onClick.bind(this),this.onStateChange=this.onStateChange.bind(this)}boot(){"scrollRestoration"in window.history&&(window.history.scrollRestoration="manual"),super.boot()}getTransitionName(t){if(!t||!t.getAttribute)return null;let e=t.getAttribute(this.config.getConfig("transitionAttr",!1));return typeof e=="string"?e:null}validLink(t,e,i){let n=!window.history.pushState,o=!t||!i,s=e.metaKey||e.ctrlKey||e.shiftKey||e.altKey,a=t.hasAttribute("target")&&t.target==="_blank",l=t.protocol!==location.protocol||t.hostname!==location.hostname,c=typeof t.getAttribute("download")=="string",m=t.hasAttribute(this.config.getConfig("preventSelfAttr",!1)),R=Boolean(t.closest(this.config.getConfig("preventAllAttr"))),v=m&&R,U=h(p())===h(p(i));return!(o||n||s||a||l||c||v||U)}getHref(t){return t&&t.tagName&&t.tagName.toLowerCase()==="a"&&typeof t.href=="string"?t.href:null}getLink(t){let e=t.target,i=this.getHref(e);for(;e&&!i;)e=e.parentNode,i=this.getHref(e);return!e||!this.validLink(e,t,i)?void 0:e}onClick(t){let e=this.getLink(t);if(!e)return;if(this.isTransitioning&&this.stopOnTransitioning){t.preventDefault(),t.stopPropagation();return}let i=this.getHref(e);this.emitter.emit("ANCHOR_CLICK CLICK",t),this.go({href:i,trigger:e,event:t})}getDirection(t){return Math.abs(t)>1?t>0?"forward":"back":t===0?"popstate":t>0?"back":"forward"}force(t){window.location.assign(t)}go({href:t,trigger:e="HistoryManager",event:i}){if(this.isTransitioning&&this.stopOnTransitioning){this.force(t);return}let n={x:0,y:0},o=this.HistoryManager.current,s=o.url;if(M(s,t))return;let a;if(i&&i.state){this.emitter.emit("POPSTATE",i);let{state:l}=i,{index:c}=l,m=o.index,R=m-c;e=this.getDirection(R);let v=this.HistoryManager.get(this.HistoryManager.pointer);a=v.transition,n=v.data.scroll,this.HistoryManager.replace(l.states),this.HistoryManager.pointer=c,e==="back"?this.emitter.emit("POPSTATE_BACK",i):e==="forward"&&this.emitter.emit("POPSTATE_FORWARD",i)}else{a=this.getTransitionName(e)||"default",n=E();let l=P({url:t,transition:a,data:{scroll:n}});this.HistoryManager.add(l),this.emitter.emit("HISTORY_NEW_ITEM",i)}return i&&(i.stopPropagation(),i.preventDefault()),this.emitter.emit("GO",i),this.load({oldHref:s,href:t,trigger:e,transitionName:a,scroll:n})}async load({oldHref:t,href:e,trigger:i,transitionName:n="default",scroll:o={x:0,y:0}}){try{let s=await this.PageManager.load(t);await s.build();let a;this.emitter.emit("PAGE_LOADING",{href:e,oldPage:s,trigger:i});try{try{a=await this.PageManager.load(e),await a.build(),this.transitionStart(),this.emitter.emit("PAGE_LOAD_COMPLETE",{newPage:a,oldPage:s,trigger:i})}catch(l){console.error(`[PJAX] page load error: ${l}`)}this.emitter.emit("NAVIGATION_START",{oldPage:s,newPage:a,trigger:i,transitionName:n});try{this.emitter.emit("TRANSITION_START",n);let l=await this.TransitionManager.boot(n,{oldPage:s,newPage:a,trigger:i,scroll:o});l.scrollable||(/back|popstate|forward/.test(i)||(o=H()),window.scroll(o.x,o.y)),this.emitter.emit("TRANSITION_END",{transition:l})}catch(l){console.error(`[PJAX] transition error: ${l}`)}this.emitter.emit("NAVIGATION_END",{oldPage:s,newPage:a,trigger:i,transitionName:n})}catch(l){throw this.transitionStop(),l}this.transitionStop()}catch(s){this.forceOnError?this.force(e):console.error(s)}}ignoredURL({pathname:t}){return this.ignoreURLs.length&&this.ignoreURLs.some(e=>typeof e=="string"?e===t:e.exec(t)!==null)}onHover(t){let e=this.getLink(t);if(!e)return;let i=p(this.getHref(e)),n=i.pathname;if(this.ignoredURL(i)||this.PageManager.has(n))return;this.emitter.emit("ANCHOR_HOVER HOVER",t);try{this.PageManager.load(i)}catch(o){console.warn("[PJAX] prefetch error,",o)}}onStateChange(t){this.go({href:window.location.href,trigger:"popstate",event:t})}initEvents(){this.prefetchIgnore!==!0&&(document.addEventListener("mouseover",this.onHover),document.addEventListener("touchstart",this.onHover)),document.addEventListener("click",this.onClick),window.addEventListener("popstate",this.onStateChange)}stopEvents(){this.prefetchIgnore!==!0&&(document.removeEventListener("mouseover",this.onHover),document.removeEventListener("touchstart",this.onHover)),document.removeEventListener("click",this.onClick),window.removeEventListener("popstate",this.onStateChange)}},H=(r=window.location.hash)=>{try{let t=r[0]=="#"?r:p(r).hash;if(t.length>1){let e=document.getElementById(t.slice(1));if(e)return E(e.offsetLeft,e.offsetTop)}}catch(t){console.warn("hashAction error",t)}return E(0,0)},N=class extends u{constructor(t){super();this.app=t,this.config=t.config,this.emitter=t.emitter}async boot(t,e){let i=this.get(t),n=e.scroll;if(!(e.oldPage instanceof g)||!(e.newPage instanceof g))throw`[Page] either oldPage or newPage aren't instances of the Page Class. + ${{newPage:e.newPage,oldPage:e.oldPage}}`;let o=e.oldPage.wrapper,s=e.newPage.wrapper;if(document.title=""+e.newPage.title,!(o instanceof Node)||!(s instanceof Node))throw`[Wrapper] the wrapper from the ${s instanceof Node?"current":"next"} page cannot be found. The wrapper must be an element that has the attribute ${this.config.getConfig("wrapperAttr")}.`;return i.init&&i?.init(e),this.emitter.emit("BEFORE_TRANSITION_OUT"),await new Promise(a=>{let l=i.out.call(i,{...e,from:e.oldPage,trigger:e.trigger,done:a});l.then&&l.then(a)}),this.emitter.emit("AFTER_TRANSITION_OUT"),await new Promise(a=>{o.insertAdjacentElement("beforebegin",s),this.emitter.emit("CONTENT_INSERT"),/back|popstate|forward/.test(e.trigger)||(n=H()),a()}),await new Promise(a=>{o.remove(),o=void 0,s=void 0,this.emitter.emit("CONTENT_REPLACED"),a()}),this.emitter.emit("BEFORE_TRANSITION_IN"),await new Promise(a=>{let l=i.in.call(i,{...e,from:e.oldPage,to:e.newPage,trigger:e.trigger,scroll:n,done:a});l.then&&l.then(a)}),this.emitter.emit("AFTER_TRANSITION_IN"),i}};var Y=class{constructor(t={}){this.register(t)}register(t={}){this.config=t instanceof L?t:new L(t),this.emitter=new x,this.history=new C,this.pages=new k(this),this.transitions=new N(this),this.services=new O(this);let e=(()=>{document.removeEventListener("DOMContentLoaded",e),window.removeEventListener("load",e),this.emitter.emit("READY ready")}).bind(this);return document.addEventListener("DOMContentLoaded",e),window.addEventListener("load",e),this}get(t,e){switch(t.toLowerCase()){case"service":return this.services.get(e);case"transition":return this.transitions.get(e);case"state":return this.history.get(e);default:throw`Error: can't get type '${t}', it is not a recognized type. Did you spell it correctly.`}}async load(t,e){switch(t.toLowerCase()){case"page":return await this.pages.load(e);default:return Promise.resolve(this.get(t,e))}}setService(t,e){return this.services.set(t,e),this}setTransition(t,e){return this.transitions.set(t,e),this}add(t,e){switch(t.toLowerCase()){case"service":this.services.add(e);break;case"transition":this.transitions.set(e.name,e);break;case"state":this.history.add(e);break;default:throw`Error: can't add type '${t}', it is not a recognized type. Did you spell it correctly.`}return this}boot(){return this.services.init(),this.services.boot(),this}stop(){return this.services.stop(),this}on(t,e){return this.emitter.on(t,e,this),this}off(t,e){return this.emitter.off(t,e,this),this}emit(t,...e){return this.emitter.emit(t,...e),this}};var J=class extends T{constructor(t=[]){super();this.routes=new u;for(let e of t)this.add(e)}add({path:t,method:e}){let i=this.parse(t);return this.routes.set(i,e),this}parsePath(t){if(typeof t=="string")return new RegExp(t,"i");if(t instanceof RegExp||typeof t=="boolean")return t;throw"[Router] only regular expressions, strings and booleans are accepted as paths."}isPath(t){return typeof t=="string"||t instanceof RegExp||typeof t=="boolean"}parse(t){let e=t,i={from:/(.*)/g,to:/(.*)/g};if(this.isPath(t))i={from:!0,to:t};else if(this.isPath(e.from)&&this.isPath(e.to))i=e;else throw"[Router] path is neither a string, regular expression, or a { from, to } object.";let{from:n,to:o}=i;return{from:this.parsePath(n),to:this.parsePath(o)}}route(){let t=this.HistoryManager,e=h(p((t.length>1?t.previous:t.current).url)),i=h(p());this.routes.forEach((n,o)=>{let s=o.from,a=o.to;if(typeof s=="boolean"&&typeof a=="boolean")throw`[Router] path ({ from: ${s}, to: ${a} }) is not valid, remember paths can only be strings, regular expressions, or a boolean; however, both the from and to paths cannot be both booleans.`;let l=s,c=a;s instanceof RegExp&&s.test(e)&&(l=s.exec(e)),a instanceof RegExp&&a.test(i)&&(c=a.exec(i)),(Array.isArray(c)&&Array.isArray(l)||Array.isArray(c)&&typeof l=="boolean"&&l||Array.isArray(l)&&typeof c=="boolean"&&c)&&n({from:l,to:c,path:{from:e,to:i}})})}initEvents(){this.emitter.on("READY",this.route,this),this.emitter.on("CONTENT_REPLACED",this.route,this)}stopEvents(){this.emitter.off("READY",this.route,this),this.emitter.off("CONTENT_REPLACED",this.route,this)}};var X=r=>typeof r=="string"?Array.from(document.querySelectorAll(r)):[r],Q=r=>Array.isArray(r)?r:typeof r=="string"||r instanceof Node?X(r):r instanceof NodeList||r instanceof HTMLCollection?Array.from(r):[],_=(r,t)=>typeof r=="function"?r(...t):r,j=(r,t)=>{let e,i,n={},o=Object.keys(r);for(let s=0,a=o.length;s/^(ease|in|out)/.test(r)?Z[r]:r,et={keyframes:[],loop:1,delay:0,speed:1,endDelay:0,easing:"ease",autoplay:!0,duration:1e3,onfinish(){},fillMode:"auto",direction:"normal"},z=class{constructor(t={}){this.options={};this.targets=[];this.properties={};this.animations=new Map;this.duration=0;this.emitter=new x;let{options:e,...i}=t;this.options=Object.assign({},et,e,i),this.loop=this.loop.bind(this);let{loop:n,delay:o,speed:s,easing:a,endDelay:l,duration:c,direction:m,fillMode:R,onfinish:v,target:U,keyframes:at,autoplay:lt,...pt}=this.options;this.mainElement=document.createElement("span"),this.targets=Q(U),this.properties=pt;let F;for(let f=0,S=this.targets.length;f0||(F=j(F,[f,S,I]));let it=b.delay+b.duration*b.iterations+b.endDelay;this.duration{v(I,f,S)},this.animations.set(I,rt)}this.mainAnimation=this.mainElement.animate([{opacity:"0"},{opacity:"1"}],{duration:this.duration,easing:"linear"}),this.setSpeed(s),lt?this.play():this.pause(),this.promise=this.newPromise(),this.mainAnimation.onfinish=()=>{this.finish(this.options),window.cancelAnimationFrame(this.animationFrame)}}getTargets(){return this.targets}newPromise(){return new Promise((t,e)=>{try{this.finish=i=>(this.emit("finish",i),t(i))}catch(i){e(i)}})}then(t,e){return this.promise.then(t,e)}catch(t){return this.promise.catch(t)}finally(t){return this.promise.finally(t)}loop(){this.animationFrame=window.requestAnimationFrame(this.loop),this.emit("tick change",this.getCurrentTime())}on(t,e,i){return this.emitter.on(t,e,i),this}off(t,e,i){return this.emitter.off(t,e,i),this}emit(t,...e){return this.emitter.emit(t,...e),this}getAnimation(t){return this.animations.get(t)}play(){return this.mainAnimation.playState!=="finished"&&(this.mainAnimation.play(),this.animationFrame=requestAnimationFrame(this.loop),this.animations.forEach(t=>{t.playState!=="finished"&&t.play()}),this.emit("play")),this}pause(){return this.mainAnimation.playState!=="finished"&&(this.mainAnimation.pause(),window.cancelAnimationFrame(this.animationFrame),this.animations.forEach(t=>{t.playState!=="finished"&&t.pause()}),this.emit("pause")),this}getDuration(){return this.duration}getCurrentTime(){return this.mainAnimation.currentTime}setCurrentTime(t){return this.mainAnimation.currentTime=t,this.animations.forEach(e=>{e.currentTime=t}),this}getProgress(){return this.getCurrentTime()/this.duration}setProgress(t){return this.mainAnimation.currentTime=t*this.duration,this.animations.forEach(e=>{e.currentTime=t*this.duration}),this}getSpeed(){return this.mainAnimation.playbackRate}setSpeed(t=1){return this.mainAnimation.playbackRate=t,this.animations.forEach(e=>{e.playbackRate=t}),this}reset(){this.setCurrentTime(0),this.promise=this.newPromise(),this.options.autoplay?this.play():this.pause()}getPlayState(){return this.mainAnimation.playState}getOptions(){return this.options}toJSON(){return this.getOptions()}},st=(r={})=>new z(r);return ht;})(); //# sourceMappingURL=api.js.map diff --git a/packages/native/lib/api.js.map b/packages/native/lib/api.js.map index 19e314e..097f349 100644 --- a/packages/native/lib/api.js.map +++ b/packages/native/lib/api.js.map @@ -1,7 +1,7 @@ { "version": 3, - "sources": ["../src/api.ts", "../src/config.ts", "../../manager/src/api.ts", "../src/manager.ts", "../src/url.ts", "../src/history.ts", "../src/page.ts", "../../emitter/src/api.ts", "../src/service.ts", "../src/transition.ts", "../src/app.ts", "../src/pjax.ts", "../src/route.ts", "../../animate/src/api.ts"], - "sourcesContent": ["export * from \"./config\";\r\nexport * from \"./manager\";\r\nexport * from \"./url\";\r\n\r\nexport * from \"./history\";\r\nexport * from \"./page\";\r\n\r\nexport * from \"./emitter\";\r\nexport * from \"./service\";\r\n\r\nexport * from \"./transition\";\r\n\r\nexport * from \"./app\";\r\nexport * from \"./pjax\";\r\nexport * from \"./route\";\r\n\r\nexport * from \"@okikio/animate\";\r\n", "// The config variables\r\nexport interface ICONFIG {\r\n prefix?: string;\r\n wrapperAttr?: string;\r\n noAjaxLinkAttr?: string;\r\n noPrefetchAttr?: \"no-prefetch\";\r\n headers?: string[][];\r\n preventSelfAttr?: string;\r\n preventAllAttr?: string;\r\n transitionAttr?: string;\r\n blockAttr?: string;\r\n timeout?: number\r\n}\r\n\r\nexport const CONFIG_DEFAULTS: ICONFIG = {\r\n wrapperAttr: \"wrapper\",\r\n noAjaxLinkAttr: \"no-ajax-link\",\r\n noPrefetchAttr: \"no-prefetch\",\r\n headers: [\r\n [\"x-partial\", \"true\"]\r\n ],\r\n preventSelfAttr: `prevent=\"self\"`,\r\n preventAllAttr: `prevent=\"all\"`,\r\n transitionAttr: \"transition\",\r\n blockAttr: `block`,\r\n timeout: 30000\r\n};\r\n\r\nexport type ConfigKeys = keyof ICONFIG;\r\n\r\n/**\r\n * The Config class\r\n *\r\n * @export\r\n * @class CONFIG\r\n */\r\nexport class CONFIG {\r\n /**\r\n * The current Configuration\r\n *\r\n * @public\r\n * @type ICONFIG\r\n * @memberof CONFIG\r\n */\r\n public config: ICONFIG;\r\n\r\n /**\r\n * Creates an instance of CONFIG.\r\n *\r\n * @param {ICONFIG} config\r\n * @memberof CONFIG\r\n */\r\n constructor(config: ICONFIG) {\r\n this.config = Object.assign({ ...CONFIG_DEFAULTS }, config);\r\n }\r\n\r\n /**\r\n * Converts string into data attributes\r\n *\r\n * @param {string} value\r\n * @param {boolean} brackets [brackets=true]\r\n * @returns string\r\n * @memberof CONFIG\r\n */\r\n public toAttr(value: string, brackets: boolean = true): string {\r\n let { prefix } = this.config;\r\n let attr = `data${prefix ? \"-\" + prefix : \"\"}-${value}`;\r\n return brackets ? `[${attr}]` : attr;\r\n }\r\n\r\n /**\r\n * Selects config vars, and formats them for use, or simply returns the current configurations for the framework\r\n *\r\n * @param {ConfigKeys} value\r\n * @param {boolean} [brackets=true]\r\n * @returns any\r\n * @memberof CONFIG\r\n */\r\n public getConfig(value?: ConfigKeys, brackets: boolean = true): any {\r\n if (typeof value !== \"string\")\r\n return this.config;\r\n\r\n let config = this.config[value];\r\n if (typeof config === \"string\")\r\n return this.toAttr(config, brackets);\r\n return config;\r\n }\r\n}\r\n", "/**\r\n * Manages complex lists of named data, eg. A page can be stored in a list by of other pages with the url being how the page is stored in the list. Managers use Maps to store data.\r\n *\r\n * @export\r\n * @class Manager\r\n * @template K\r\n * @template V\r\n */\r\nexport class Manager {\r\n\t/**\r\n\t * The complex list of named data, to which the Manager controls\r\n\t *\r\n\t * @public\r\n\t * @type Map\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic map: Map;\r\n\r\n\t/**\r\n\t * Creates an instance of Manager.\r\n\t *\r\n\t * @param {Array<[K, V]>} [value]\r\n\t * @memberof Manager\r\n\t */\r\n\tconstructor(value?: Array<[K, V]>) {\r\n\t\tthis.map = new Map(value);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the Manager class's list\r\n\t *\r\n\t * @returns Map\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic getMap(): Map {\r\n\t\treturn this.map;\r\n\t}\r\n\r\n\t/**\r\n\t * Get a value stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key to find in the Manager's list\r\n\t * @returns V\r\n\t */\r\n\tpublic get(key: K): V {\r\n\t\treturn this.map.get(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the keys of all items stored in the Manager as an Array\r\n\t *\r\n\t * @returns Array\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic keys(): Array {\r\n\t\treturn Array.from(this.map.keys());\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the values of all items stored in the Manager as an Array\r\n\t *\r\n\t * @returns Array\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic values(): Array {\r\n\t\treturn Array.from(this.map.values());\r\n\t}\r\n\r\n\t/**\r\n\t * Set a value stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key where the value will be stored\r\n\t * @param {V} value - The value to store\r\n\t * @returns Manager\r\n\t */\r\n\tpublic set(key: K, value: V): Manager {\r\n\t\tthis.map.set(key, value);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Adds a value to Manager, and uses the current size of the Manager as it's key, it works best when all the key in the Manager are numbers\r\n\t *\r\n\t * @public\r\n\t * @param {V} value\r\n\t * @returns Manager\r\n\t */\r\n\tpublic add(value: V): Manager {\r\n\t\tlet size = this.size;\r\n\t\t// @ts-ignore\r\n\t\tlet num: K = size as K;\r\n\t\tthis.set(num, value);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the total number of items stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @returns Number\r\n\t */\r\n\tpublic get size(): number {\r\n\t\treturn this.map.size;\r\n\t}\r\n\r\n\tpublic get length(): number {\r\n\t\treturn this.map.size;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the last item in the Manager who's index is a certain distance from the last item in the Manager\r\n\t *\r\n\t * @param {number} [distance=1]\r\n\t * @returns V | undefined\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic last(distance: number = 1): V | undefined {\r\n\t\tlet key = this.keys()[this.size - distance];\r\n\t\treturn this.get(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Removes a value stored in the Manager, via the key, returns true if an element in the Map object existed and has been removed, or false if the element does not exist.\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key for the key value pair to be removed\r\n\t * @returns boolean\r\n\t */\r\n\tpublic delete(key: K): boolean {\r\n\t\treturn this.map.delete(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Removes a value stored in the Manager, via the key, returns the Manager class, allowing for chains\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key for the key value pair to be removed\r\n\t * @returns Manager\r\n\t */\r\n\tpublic remove(key: K): Manager {\r\n\t\tthis.map.delete(key);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Clear the Manager of all its contents\r\n\t *\r\n\t * @public\r\n\t * @returns Manager\r\n\t */\r\n\tpublic clear(): Manager {\r\n\t\tthis.map.clear();\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Checks if the Manager contains a certain key\r\n\t *\r\n\t * @public\r\n\t * @param {K} key\r\n\t * @returns boolean\r\n\t */\r\n\tpublic has(key: K): boolean {\r\n\t\treturn this.map.has(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a new Iterator object that contains an array of [key, value] for each element in the Map object in insertion order.\r\n\t *\r\n\t * @public\r\n\t * @returns IterableIterator<[K, V]>\r\n\t */\r\n\tpublic entries(): IterableIterator<[K, V]> {\r\n\t\treturn this.map.entries();\r\n\t}\r\n\r\n\t/**\r\n\t * Iterates through the Managers contents, calling a callback function every iteration\r\n\t *\r\n\t * @param {*} [callback=(...args: any): void => { }]\r\n\t * @param {object} context\r\n\t * @returns Manager\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic forEach(\r\n\t\tcallback: any = (...args: any): void => { },\r\n\t\tcontext?: object\r\n\t): Manager {\r\n\t\tthis.map.forEach(callback, context);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Allows iteration via the for..of, learn more: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators]\r\n\t *\r\n\t * @returns IterableIterator<[K, V]>\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic [Symbol.iterator](): IterableIterator<[K, V]> {\r\n\t\treturn this.entries();\r\n\t}\r\n}\r\n\r\n/**\r\n * Calls the method of a certain name for all items that are currently installed\r\n *\r\n * @param {Manager} manager\r\n * @param {string} method\r\n * @param {Array} [args=[]]\r\n */\r\nexport const methodCall = (manager: Manager, method: string, ...args: any): void => {\r\n\tmanager.forEach((item) => {\r\n\t\t// @ts-ignore\r\n\t\titem[method](...args);\r\n\t});\r\n};\r\n\r\n/**\r\n * Asynchronously calls the method of a certain name for all items that are currently installed, similar to methodCall\r\n *\r\n * @param {Manager} manager\r\n * @param {string} method\r\n * @param {Array} [args=[]]\r\n */\r\nexport const asyncMethodCall = async (manager: Manager, method: string, ...args: any): Promise => {\r\n\tfor (let [, item] of manager) {\r\n\t\t// @ts-ignore\r\n\t\tawait item[method](...args);\r\n\t}\r\n};\r\n\r\nexport default Manager;\r\n", "import { Manager, methodCall, asyncMethodCall } from \"@okikio/manager\";\r\nimport { CONFIG } from \"./config\";\r\nimport { App } from \"./app\";\r\nimport EventEmitter from \"@okikio/emitter\";\r\n\r\nexport type IAdvancedManager = AdvancedManager;\r\n\r\n/**\r\n * The base class for all AdvancedManager and AdvancedStorage items\r\n *\r\n * @export\r\n * @class ManagerItem\r\n */\r\nexport class ManagerItem {\r\n /**\r\n * The AdvancedManager the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type IAdvancedManager\r\n * @memberof ManagerItem\r\n */\r\n public manager: IAdvancedManager;\r\n\r\n /**\r\n * The App the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type App\r\n * @memberof ManagerItem\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof ManagerItem\r\n */\r\n public config: CONFIG;\r\n public emitter: EventEmitter;\r\n public key: any;\r\n\r\n /**\r\n * Creates an instance of ManagerItem.\r\n *\r\n * @memberof ManagerItem\r\n */\r\n constructor() { }\r\n\r\n /**\r\n * Run after the Manager Item has been registered\r\n *\r\n * @returns any\r\n * @memberof ManagerItem\r\n */\r\n public install(): any { }\r\n\r\n /**\r\n * Register the current Manager Item's manager\r\n *\r\n * @param {IAdvancedManager} manager\r\n * @returns ManagerItem\r\n * @memberof ManagerItem\r\n */\r\n public register(manager: IAdvancedManager, key: any): ManagerItem {\r\n this.manager = manager;\r\n this.app = manager.app;\r\n this.config = manager.config;\r\n this.emitter = manager.emitter;\r\n this.key = key;\r\n this.install();\r\n return this;\r\n }\r\n\r\n public uninstall(): any { }\r\n\r\n public unregister() {\r\n this.uninstall();\r\n\r\n this.manager.delete(this.key);\r\n this.key = undefined;\r\n this.manager = undefined;\r\n this.app = undefined;\r\n this.config = undefined;\r\n this.emitter = undefined;\r\n }\r\n}\r\n\r\n/**\r\n * A tweak to the Manager class that makes it self aware of the App class it's instantiated in\r\n *\r\n * @export\r\n * @class AdvancedManager\r\n * @extends {Manager}\r\n * @template K\r\n * @template V\r\n */\r\nexport class AdvancedManager extends Manager {\r\n /**\r\n * The instance of the App class, the Manager is instantiated in\r\n *\r\n * @type App\r\n * @memberof AdvancedManager\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof AdvancedManager\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * The EventEmitter class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof AdvancedManager\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * Creates an instance of AdvancedManager.\r\n *\r\n * @param {App} app - The instance of the App class, the Manager is instantiated in\r\n * @memberof AdvancedManager\r\n */\r\n constructor(app: App) {\r\n super();\r\n this.app = app;\r\n this.config = app.config;\r\n this.emitter = app.emitter;\r\n }\r\n\r\n /**\r\n * Set a value stored in the Manager\r\n *\r\n * @public\r\n * @param {K} key - The key where the value will be stored\r\n * @param {V} value - The value to store\r\n * @returns AdvancedManager\r\n */\r\n public set(key: K, value: V) {\r\n super.set(key, value);\r\n value.register(this, key);\r\n return this;\r\n }\r\n}\r\n\r\nexport { Manager, methodCall, asyncMethodCall };\r\n", "/**\r\n * Adds new methods to the native URL Object; it seemed cleaner than using a custom method or editing the prototype.\r\n *\r\n * This doesn't extend the **Class** object because it's meant to be a small extension of the native URL class.\r\n *\r\n * @export\r\n * @class URL\r\n * @extends {URL}\r\n */\r\n// Read up on the native URL class [devdocs.io/dom/url]\r\n/**\r\n * Creates an instance of URL.\r\n *\r\n * @param {(string | URL | Location)} [url=window.location.pathname]\r\n * @return URL\r\n */\r\nexport const newURL = (url: string | URL | Location = window.location.href): URL => {\r\n return url instanceof URL ? url : new URL(url as unknown as string, window.location.origin);\r\n};\r\n\r\n/**\r\n * Returns the pathname with the hash\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const getHashedPath = (url: URL): string => (`${url.pathname}${url.hash}`);\r\n\r\n/**\r\n * Returns the actual hash without the hashtag\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const getHash = (url: URL): string => (url.hash.slice(1));\r\n\r\n/**\r\n * Removes the hash from the full URL for a clean URL string\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const clean = (url: URL): string => (url.toString().replace(/(\\/#.*|\\/|#.*)$/, ''));\r\n\r\n/**\r\n * Compares two URLs to each other\r\n *\r\n * @param {URL} a\r\n * @param {URL} b\r\n * @returns boolean\r\n */\r\nexport const equal = (a: URL | string, b: URL | string): boolean => {\r\n let urlA = newURL(a);\r\n let urlB = newURL(b);\r\n return clean(urlA) === clean(urlB);\r\n};\r\n", "import { getHashedPath, newURL } from \"./url\";\r\n\r\nexport type Trigger = HTMLAnchorElement | \"HistoryManager\" | \"popstate\" | \"back\" | \"forward\";\r\nexport interface ICoords {\r\n\treadonly x: number;\r\n\treadonly y: number;\r\n}\r\n\r\nexport interface IStateData {\r\n\tscroll: ICoords;\r\n\t[key: string]: any;\r\n}\r\n\r\nexport interface IState {\r\n\turl: string;\r\n\tindex?: number;\r\n\ttransition: string;\r\n\tdata: IStateData;\r\n}\r\n\r\nexport interface IHistoryItem {\r\n\tindex: number;\r\n\tstates: IState[];\r\n}\r\n\r\n/**\r\n * A quick snapshot of page coordinates, e.g. scroll positions\r\n *\r\n * @export\r\n * @param {number} [x=window.scrollX]\r\n * @param {number} [y=window.scrollY]\r\n */\r\nexport const newCoords = (x: number = window.scrollX, y: number = window.scrollY): ICoords => ({ x, y });\r\n\r\n/**\r\n * Represents the current status of the page consisting of properties like: url, transition, and data\r\n *\r\n * @export\r\n * @param {IState} {\r\n * url = getHashedPath(newURL()),\r\n * index = 0,\r\n * transition = \"default\",\r\n * data = {\r\n * scroll: newCoords(),\r\n * trigger: \"HistoryManager\"\r\n * }\r\n * }\r\n * @memberof State\r\n*/\r\nexport const newState = (state: IState = {\r\n\turl: getHashedPath(newURL()),\r\n\tindex: 0,\r\n\ttransition: \"default\",\r\n\tdata: {\r\n\t\tscroll: newCoords(),\r\n\t\ttrigger: \"HistoryManager\"\r\n\t}\r\n}): IState => (state);\r\n\r\n\r\n/**\r\n * History of the site, stores only the State class\r\n *\r\n * @export\r\n * @class HistoryManager\r\n * @extends {Manager}\r\n */\r\nexport class HistoryManager {\r\n\tpublic states: IState[];\r\n\tpublic pointer = -1;\r\n\r\n\t/**\r\n\t * Creates an instance of the HistoryManager class, which inherits properties and methods from the Storage class.\r\n\t *\r\n\t * @memberof HistoryManager\r\n\t * @constructor\r\n\t */\r\n\tconstructor() {\r\n\t\tthis.states = [];\r\n\r\n\t\tlet state = newState();\r\n\t\tthis.add(state, \"replace\");\r\n\t}\r\n\r\n\tpublic get(index: number) {\r\n\t\treturn this.states[index];\r\n\t}\r\n\r\n\t/**\r\n\t * Sets the index of the state before adding to HistoryManager\r\n\t *\r\n\t * @param {IState} value\r\n\t * @returns HistoryManager\r\n\t */\r\n\tpublic add(value?: IState, historyAction: \"replace\" | \"push\" = \"push\"): HistoryManager {\r\n\t\tlet state = newState(value);\r\n\t\tlet len = this.length;\r\n\t\tthis.states.push({ ...state });\r\n\t\tthis.pointer = len;\r\n\r\n\t\tlet item: IHistoryItem = {\r\n\t\t\tindex: this.pointer,\r\n\t\t\tstates: [...this.states]\r\n\t\t};\r\n\t\tthis.changeState(historyAction, state, item);\r\n\t\treturn this;\r\n\t}\r\n\r\n\tpublic remove(index?: number) {\r\n\t\tif (index) {\r\n\t\t\tthis.states.splice(index, 1);\r\n\t\t} else {\r\n\t\t\tthis.states.pop();\r\n\t\t}\r\n\r\n\t\tthis.pointer--;\r\n\t\treturn this;\r\n\t}\r\n\r\n\tpublic replace(newStates: IState[]) {\r\n\t\tthis.states = newStates;\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Set state by index.\r\n\t */\r\n\tpublic set(i: number, state: IState) {\r\n\t\treturn (this.states[i] = state);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the current state.\r\n\t */\r\n\tget current(): IState {\r\n\t\treturn this.get(this.pointer);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the last state (top of the history stack).\r\n\t */\r\n\tget last(): IState {\r\n\t\treturn this.get(this.length - 1);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the previous state.\r\n\t */\r\n\tget previous(): IState | null {\r\n\t\treturn this.pointer < 1 ? null : this.get(this.pointer - 1);\r\n\t}\r\n\r\n\tget length() {\r\n\t\treturn this.states.length;\r\n\t}\r\n\r\n\t/**\r\n\t * Either push or replace history state\r\n\t *\r\n\t * @param {(\"push\" | \"replace\")} action\r\n\t * @param {IState} state\r\n\t * @param {_URL} url\r\n\t * @memberof PJAX\r\n\t */\r\n\tpublic changeState(action: \"push\" | \"replace\", state: IState, item: object) {\r\n\t\tlet href = getHashedPath(newURL(state.url));\r\n\t\tlet args = [item, \"\", href];\r\n\t\tif (window.history) {\r\n\t\t\tswitch (action) {\r\n\t\t\t\tcase \"push\":\r\n\t\t\t\t\twindow.history.pushState.apply(window.history, args);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"replace\":\r\n\t\t\t\t\twindow.history.replaceState.apply(window.history, args);\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n", "import { Manager, ManagerItem, AdvancedManager } from \"./manager\";\r\nimport { equal, newURL } from \"./url\";\r\nimport { App } from \"./app\";\r\n\r\n/**\r\n * Parses strings to DOM\r\n */\r\nexport const PARSER: DOMParser = new DOMParser();\r\n\r\n/**\r\n * A page represents the DOM elements that create each page\r\n *\r\n * @export\r\n * @class Page\r\n */\r\nexport class Page extends ManagerItem {\r\n /**\r\n * Holds the DOM of the current page\r\n *\r\n * @public\r\n * @type Document\r\n * @memberof Page\r\n */\r\n public dom: Document;\r\n\r\n /**\r\n * Holds the wrapper element to be swapped out of each Page\r\n *\r\n * @public\r\n * @type HTMLElement\r\n * @memberof Page\r\n */\r\n public wrapper: HTMLElement;\r\n\r\n /**\r\n * Holds the title of each page\r\n *\r\n * @public\r\n * @type string\r\n * @memberof Page\r\n */\r\n public title: string;\r\n\r\n /**\r\n * Holds the head element of each page\r\n *\r\n * @public\r\n * @type Element\r\n * @memberof Page\r\n */\r\n public head: Element;\r\n\r\n /**\r\n * Holds the body element of each page\r\n *\r\n * @public\r\n * @type Element\r\n * @memberof Page\r\n */\r\n public body: Element;\r\n\r\n /**\r\n * The URL of the current page\r\n *\r\n * @public\r\n * @type URL\r\n * @memberof Page\r\n */\r\n public url: URL;\r\n public data: string;\r\n public wrapperAttr: string;\r\n\r\n /**\r\n * Creates an instance of Page, it also creates a new page from response text, or a Document Object\r\n *\r\n * @param {URL} [url = newURL()]\r\n * @param {(string | Document)} [dom=document]\r\n * @memberof Page\r\n */\r\n constructor(url: URL = newURL(), dom: string | Document = document) {\r\n super();\r\n this.url = url;\r\n\r\n if (typeof dom === \"string\") {\r\n this.data = dom;\r\n } else this.dom = dom || document;\r\n }\r\n\r\n public async build() {\r\n if (!(this.dom instanceof Node)) {\r\n this.dom = PARSER.parseFromString(this.data, \"text/html\");\r\n }\r\n\r\n if (!(this.body instanceof Node)) {\r\n let { title, head, body } = this.dom;\r\n this.title = title;\r\n this.head = head;\r\n this.body = body;\r\n this.wrapper = this.body.querySelector(this.wrapperAttr);\r\n }\r\n }\r\n\r\n /**\r\n * Runs once the the manager and config have been registered\r\n *\r\n * @returns void\r\n * @memberof Page\r\n */\r\n public install(): void {\r\n this.wrapperAttr = this.config.getConfig(\"wrapperAttr\");\r\n }\r\n\r\n public uninstall() {\r\n this.url = undefined;\r\n this.title = undefined;\r\n this.head = undefined;\r\n this.body = undefined;\r\n this.dom = undefined;\r\n this.wrapper = undefined;\r\n this.data = undefined;\r\n this.wrapperAttr = undefined;\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Controls which page to be load\r\n *\r\n * @export\r\n * @class PageManager\r\n * @extends {AdvancedManager}\r\n */\r\nexport class PageManager extends AdvancedManager {\r\n /**\r\n * Stores all URLs that are currently loading\r\n *\r\n * @public\r\n * @type Manager>\r\n * @memberof PageManager\r\n */\r\n public loading: Manager> = new Manager();\r\n public maxPages = 5;\r\n\r\n /**\r\n * Creates an instance of the PageManager\r\n *\r\n * @param {App} app\r\n * @memberof PageManager\r\n */\r\n constructor(app: App) {\r\n super(app);\r\n let URLString = newURL().pathname;\r\n this.set(URLString, new Page());\r\n URLString = undefined;\r\n }\r\n\r\n /**\r\n * Load from cache or by requesting URL via a fetch request, avoid requesting for the same thing twice by storing the fetch request in \"this.loading\"\r\n *\r\n * @param {(URL | string)} [_url=newURL()]\r\n * @returns Promise\r\n * @memberof PageManager\r\n */\r\n public async load(_url: URL | string = newURL()): Promise {\r\n let url: URL = newURL(_url);\r\n let urlString: string = url.pathname;\r\n let page: Page, request: Promise;\r\n if (this.has(urlString)) {\r\n page = this.get(urlString);\r\n return Promise.resolve(page);\r\n }\r\n\r\n if (!this.loading.has(urlString)) {\r\n request = this.request(urlString);\r\n this.loading.set(urlString, request);\r\n } else request = this.loading.get(urlString);\r\n\r\n let response = await request;\r\n this.loading.delete(urlString);\r\n\r\n page = new Page(url, response);\r\n this.set(urlString, page);\r\n\r\n if (this.size > this.maxPages) {\r\n let currentUrl = newURL();\r\n let keys = this.keys();\r\n let first = equal(currentUrl, keys[0]) ? keys[1] : keys[0];\r\n let page = this.get(first);\r\n page.unregister();\r\n page = undefined;\r\n keys = undefined;\r\n currentUrl = undefined;\r\n first = undefined;\r\n }\r\n return page;\r\n }\r\n\r\n /**\r\n * Starts a fetch request\r\n *\r\n * @param {string} url\r\n * @returns Promise\r\n * @memberof PageManager\r\n */\r\n public async request(url: string): Promise {\r\n const headers = new Headers(this.config.getConfig(\"headers\"));\r\n const timeout = window.setTimeout(() => {\r\n window.clearTimeout(timeout);\r\n throw \"Request Timed Out!\";\r\n }, this.config.getConfig(\"timeout\"));\r\n\r\n try {\r\n let response = await fetch(url, {\r\n mode: 'same-origin',\r\n method: \"GET\",\r\n headers,\r\n cache: \"default\",\r\n credentials: \"same-origin\",\r\n });\r\n\r\n window.clearTimeout(timeout);\r\n if (response.status >= 200 && response.status < 300) {\r\n return await response.text();\r\n }\r\n\r\n const err = new Error(response.statusText || \"\" + response.status);\r\n throw err;\r\n } catch (err) {\r\n window.clearTimeout(timeout);\r\n throw err;\r\n }\r\n }\r\n}\r\n", "import { Manager } from \"@okikio/manager\";\r\n\r\nexport type ListenerCallback = ((...args: any) => void);\r\nexport interface IListener {\r\n readonly callback: ListenerCallback;\r\n readonly scope: object;\r\n readonly name: string;\r\n}\r\n\r\n/**\r\n * Represents a new event listener consisting of properties like: callback, scope, name\r\n *\r\n * @export\r\n */\r\nexport const newListener = ({\r\n callback = () => { },\r\n scope = null,\r\n name = \"event\",\r\n}: IListener): IListener => ({ callback, scope, name });\r\n\r\n/**\r\n * Represents a new event listener consisting of properties like: callback, scope, name\r\n *\r\n * @export\r\n * @class Event\r\n * @extends {Manager}\r\n */\r\nexport class Event extends Manager {\r\n /**\r\n * The name of the event\r\n *\r\n * @public\r\n * @type string\r\n * @memberof Event\r\n */\r\n public name: string;\r\n\r\n /**\r\n * Creates an instance of Event.\r\n *\r\n * @param {string} [name=\"event\"]\r\n * @memberof Event\r\n */\r\n constructor(name: string = \"event\") {\r\n super();\r\n this.name = name;\r\n }\r\n}\r\n\r\nexport type EventInput = string | object | Array;\r\n\r\n/**\r\n * An event emitter\r\n *\r\n * @export\r\n * @class EventEmitter\r\n * @extends {Manager}\r\n */\r\nexport class EventEmitter extends Manager {\r\n /**\r\n * Creates an instance of EventEmitter.\r\n *\r\n * @memberof EventEmitter\r\n */\r\n constructor() {\r\n super();\r\n }\r\n\r\n /**\r\n * Gets events, if event doesn't exist create a new Event\r\n *\r\n * @param {string} name\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public getEvent(name: string): Event {\r\n let event = this.get(name);\r\n if (!(event instanceof Event)) {\r\n this.set(name, new Event(name));\r\n return this.get(name);\r\n }\r\n\r\n return event;\r\n }\r\n /**\r\n * Creates a new listener and adds it to the event\r\n *\r\n * @param {string} name\r\n * @param {ListenerCallback} callback\r\n * @param {object} scope\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public newListener(\r\n name: string,\r\n callback: ListenerCallback,\r\n scope: object\r\n ): Event {\r\n let event = this.getEvent(name);\r\n event.add(newListener({ name, callback, scope }));\r\n return event;\r\n }\r\n\r\n /**\r\n * Adds a listener for a given event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback | object} callback\r\n * @param {object} scope\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public on(\r\n events: EventInput,\r\n callback?: ListenerCallback | object,\r\n scope?: object\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n let _name: string;\r\n let _callback: ListenerCallback;\r\n let isObject = typeof events == \"object\" && !Array.isArray(events);\r\n\r\n let _scope: object = isObject ? callback : scope;\r\n if (!isObject) _callback = (callback as ListenerCallback);\r\n\r\n // Loop through the list of events\r\n Object.keys(events).forEach(key => {\r\n // Select the name of the event from the list\r\n // Remember events can be {String | Object | Array}\r\n\r\n // Check If events is an Object (JSON like Object, and not an Array)\r\n if (isObject) {\r\n _name = key;\r\n _callback = events[key];\r\n } else {\r\n _name = events[key];\r\n }\r\n\r\n this.newListener(_name, _callback, _scope);\r\n }, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes a listener from an event\r\n *\r\n * @param {string} name\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public removeListener(\r\n name: string,\r\n callback: ListenerCallback,\r\n scope: object\r\n ): Event {\r\n let event: Event = this.get(name);\r\n if (event instanceof Event && callback) {\r\n let listener = newListener({ name, callback, scope });\r\n\r\n event.forEach((value: IListener, i: number) => {\r\n if (\r\n value.callback === listener.callback &&\r\n value.scope === listener.scope\r\n ) {\r\n return event.delete(i);\r\n }\r\n });\r\n }\r\n\r\n return event;\r\n }\r\n\r\n /**\r\n * Removes a listener from a given event, or it just completely removes an event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback | object} [callback]\r\n * @param {object} [scope]\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public off(\r\n events: EventInput,\r\n callback?: ListenerCallback | object,\r\n scope?: object\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n let _name: string;\r\n let _callback: ListenerCallback;\r\n let isObject = typeof events == \"object\" && !Array.isArray(events);\r\n\r\n let _scope: object = isObject ? callback : scope;\r\n if (!isObject) _callback = (callback as ListenerCallback);\r\n\r\n // Loop through the list of events\r\n Object.keys(events).forEach(key => {\r\n // Select the name of the event from the list\r\n // Remember events can be {String | Object | Array}\r\n\r\n // Check If events is an Object (JSON like Object, and not an Array)\r\n if (isObject) {\r\n _name = key;\r\n _callback = events[key];\r\n } else {\r\n _name = events[key];\r\n }\r\n\r\n if (typeof _callback === \"function\") {\r\n this.removeListener(_name, _callback, _scope);\r\n } else this.delete(_name);\r\n }, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Call all listeners within an event\r\n *\r\n * @param {(string | Array)} events\r\n * @param {...any} args\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public emit(\r\n events: string | Array,\r\n ...args: any\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n // Loop through the list of events\r\n events.forEach((event: string) => {\r\n let _event: Event = this.get(event);\r\n\r\n if (_event instanceof Event) {\r\n _event.forEach((listener: IListener) => {\r\n let { callback, scope } = listener;\r\n callback.apply(scope, args);\r\n });\r\n }\r\n }, this);\r\n return this;\r\n }\r\n}\r\n\r\nexport default EventEmitter;\r\n", "import { AdvancedManager, ManagerItem, methodCall } from \"./manager\";\r\nimport { TransitionManager } from \"./transition\";\r\nimport { HistoryManager } from \"./history\";\r\nimport { EventEmitter } from \"./emitter\";\r\nimport { PageManager } from \"./page\";\r\nimport { App } from \"./app\";\r\n\r\n/**\r\n * Controls specific kinds of actions that require JS\r\n *\r\n * @export\r\n * @class Service\r\n */\r\nexport class Service extends ManagerItem {\r\n\t/**\r\n\t * Stores access to the App class's EventEmitter\r\n\t *\r\n\t * @public\r\n\t * @type EventEmitter\r\n\t * @memberof Service\r\n\t */\r\n\tpublic emitter: EventEmitter;\r\n\r\n\t/**\r\n\t * Stores access to the App class's PageManager\r\n\t *\r\n\t * @public\r\n\t * @type PageManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic PageManager: PageManager;\r\n\r\n\t/**\r\n\t * Stores access to the App class's HistoryManager\r\n\t *\r\n\t * @public\r\n\t * @type HistoryManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic HistoryManager: HistoryManager;\r\n\r\n\t/**\r\n\t * Stores the ServiceManager the service is install on\r\n\t *\r\n\t * @public\r\n\t * @type ServiceManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic ServiceManager: ServiceManager;\r\n\r\n\t/**\r\n\t * Stores access to the App's TransitionManager\r\n\t *\r\n\t * @public\r\n\t * @type TransitionManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic TransitionManager: TransitionManager;\r\n\r\n\t/**\r\n\t * Method is run once when Service is installed on a ServiceManager\r\n\t *\r\n\t * @memberof Service\r\n\t */\r\n\tpublic install(): void {\r\n\t\tlet { app } = this.manager;\r\n\t\tthis.PageManager = app.pages;\r\n\t\tthis.HistoryManager = app.history;\r\n\t\tthis.ServiceManager = app.services;\r\n\t\tthis.TransitionManager = app.transitions;\r\n\t}\r\n\r\n\t// Called before the start of a Service, represents a constructor of sorts\r\n\tpublic init(...args: any): void { }\r\n\r\n\t// Called on start of Service\r\n\tpublic boot(): void {\r\n\t\tthis.initEvents();\r\n\t}\r\n\r\n\t// Initialize events\r\n\tpublic initEvents(): void { }\r\n\r\n\t// Stop events\r\n\tpublic stopEvents(): void { }\r\n\r\n\tpublic uninstall() {\r\n\t\tthis.PageManager = undefined;\r\n\t\tthis.HistoryManager = undefined;\r\n\t\tthis.ServiceManager = undefined;\r\n\t\tthis.TransitionManager = undefined;\r\n\t}\r\n\r\n\t// Stop services\r\n\tpublic stop(): void {\r\n\t\tthis.stopEvents();\r\n\t\tthis.unregister();\r\n\t}\r\n}\r\n\r\n/**\r\n * The Service Manager controls the lifecycle of all services in an App\r\n *\r\n * @export\r\n * @class ServiceManager\r\n * @extends {AdvancedManager}\r\n */\r\nexport class ServiceManager extends AdvancedManager {\r\n\t/**\r\n\t * Creates an instance of ServiceManager.\r\n\t *\r\n\t * @param {App} app\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tconstructor(app: App) {\r\n\t\tsuper(app);\r\n\t}\r\n\r\n\t/**\r\n\t * Call the init method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic init(): ServiceManager {\r\n\t\tmethodCall(this, \"init\", this.app);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Call the boot method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic boot(): ServiceManager {\r\n\t\tmethodCall(this, \"boot\", this.app);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Call the stop method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic stop(): ServiceManager {\r\n\t\tmethodCall(this, \"stop\", this.app);\r\n\t\treturn this;\r\n\t}\r\n}\r\n", "import { Manager } from \"./manager\";\r\nimport { EventEmitter } from \"./emitter\";\r\nimport { ICoords, Trigger } from \"./history\";\r\nimport { Page } from \"./page\";\r\nimport { App } from \"./app\";\r\nimport { CONFIG } from \"./config\";\r\n\r\n/**\r\n * The async function type, allows for smooth transition between Promises\r\n */\r\nexport type asyncFn = (err?: any, value?: any) => void;\r\nexport interface ITransition {\r\n oldPage?: Page;\r\n newPage?: Page;\r\n trigger?: Trigger;\r\n scroll?: { x: number; y: number };\r\n scrollable?: boolean;\r\n in: (data: ITransitionData) => any;\r\n out: (data: ITransitionData) => any;\r\n [key: string]: any;\r\n}\r\nexport interface ITransitionData {\r\n from?: Page;\r\n to?: Page;\r\n trigger?: Trigger;\r\n scroll?: ICoords;\r\n done: asyncFn;\r\n}\r\n\r\n/**\r\n * Controls which animation between pages to use\r\n *\r\n * @export\r\n * @class TransitionManager\r\n * @extends {Manager}\r\n */\r\nexport class TransitionManager extends Manager {\r\n /**\r\n * The instance of the App class, the Manager is instantiated in\r\n *\r\n * @type App\r\n * @memberof AdvancedManager\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof AdvancedManager\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * The EventEmitter class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof AdvancedManager\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * Creates an instance of the TransitionManager\r\n *\r\n * @param {App} app\r\n * @memberof TransitionManager\r\n */\r\n constructor(app: App) {\r\n super();\r\n this.app = app;\r\n this.config = app.config;\r\n this.emitter = app.emitter;\r\n }\r\n\r\n /**\r\n * Runs a transition\r\n *\r\n * @param {{ name: string, oldPage: Page, newPage: Page, trigger: Trigger }} data\r\n * @returns Promise\r\n * @memberof TransitionManager\r\n */\r\n public async boot(name: string, data: { oldPage: Page, newPage: Page, trigger: Trigger, scroll: ICoords }): Promise {\r\n let transition: ITransition = this.get(name);\r\n if (!(data.oldPage instanceof Page) || !(data.newPage instanceof Page))\r\n throw `[Page] either oldPage or newPage aren't instances of the Page Class.\\n ${{\r\n newPage: data.newPage,\r\n oldPage: data.oldPage,\r\n }}`;\r\n\r\n let fromWrapper = data.oldPage.wrapper;\r\n let toWrapper = data.newPage.wrapper;\r\n document.title = `` + data.newPage.title;\r\n\r\n if (!(fromWrapper instanceof Node) || !(toWrapper instanceof Node))\r\n throw `[Wrapper] the wrapper from the ${!(toWrapper instanceof Node) ? \"next\" : \"current\"\r\n } page cannot be found. The wrapper must be an element that has the attribute ${this.config.getConfig(\r\n \"wrapperAttr\"\r\n )}.`;\r\n transition.init && transition?.init(data);\r\n\r\n this.emitter.emit(\"BEFORE_TRANSITION_OUT\");\r\n await new Promise((done) => {\r\n let outMethod: Promise = transition.out.call(transition, {\r\n from: data.oldPage,\r\n trigger: data.trigger,\r\n scroll,\r\n done,\r\n });\r\n\r\n if (outMethod.then) outMethod.then(done);\r\n });\r\n\r\n this.emitter.emit(\"AFTER_TRANSITION_OUT\");\r\n await new Promise((done) => {\r\n fromWrapper.insertAdjacentElement(\"beforebegin\", toWrapper);\r\n this.emitter.emit(\"CONTENT_INSERT\");\r\n done();\r\n });\r\n\r\n await new Promise((done) => {\r\n fromWrapper.remove();\r\n fromWrapper = undefined;\r\n toWrapper = undefined;\r\n this.emitter.emit(\"CONTENT_REPLACED\");\r\n done();\r\n });\r\n\r\n this.emitter.emit(\"BEFORE_TRANSITION_IN\");\r\n\r\n await new Promise((done) => {\r\n let inMethod: Promise = transition.in.call(transition, {\r\n from: data.oldPage,\r\n to: data.newPage,\r\n trigger: data.trigger,\r\n scroll,\r\n done,\r\n });\r\n\r\n if (inMethod.then) inMethod.then(done);\r\n });\r\n\r\n this.emitter.emit(\"AFTER_TRANSITION_IN\");\r\n return transition;\r\n }\r\n}\r\n", "import { EventEmitter, ListenerCallback, EventInput } from \"./emitter\";\r\nimport { ITransition, TransitionManager } from \"./transition\";\r\nimport { HistoryManager, IState } from \"./history\";\r\nimport { ServiceManager, Service } from \"./service\";\r\nimport { PageManager } from \"./page\";\r\nimport { CONFIG, ICONFIG } from \"./config\";\r\n\r\n/**\r\n * The App class starts the entire process, it controls all managers and all services\r\n *\r\n * @export\r\n * @class App\r\n */\r\nexport class App {\r\n /**\r\n * A new instance of the HistoryManager\r\n *\r\n * @public\r\n * @type HistoryManager\r\n * @memberof App\r\n */\r\n public history: HistoryManager;\r\n\r\n /**\r\n * A new instance of the TransitionManager\r\n *\r\n * @public\r\n * @type TransitionManager\r\n * @memberof App\r\n */\r\n public transitions: TransitionManager;\r\n\r\n /**\r\n * A new instance of the ServiceManager\r\n *\r\n * @public\r\n * @type ServiceManager\r\n * @memberof App\r\n */\r\n public services: ServiceManager;\r\n\r\n /**\r\n * A new instance of an EventEmitter\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof App\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * A new instance of the PageManager\r\n *\r\n * @public\r\n * @type PageManager\r\n * @memberof App\r\n */\r\n public pages: PageManager;\r\n\r\n /**\r\n * The current Configuration's for the framework\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof App\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * Creates an instance of App.\r\n *\r\n * @param {(ICONFIG | CONFIG)} [config={}]\r\n * @memberof App\r\n */\r\n constructor(config: object = {}) {\r\n this.register(config);\r\n }\r\n\r\n /**\r\n * For registering all managers and the configurations\r\n *\r\n * @param {(ICONFIG | CONFIG)} [config={}]\r\n * @returns App\r\n * @memberof App\r\n */\r\n public register(config: ICONFIG | CONFIG = {}): App {\r\n this.config = config instanceof CONFIG ? config : new CONFIG(config);\r\n this.emitter = new EventEmitter();\r\n this.history = new HistoryManager();\r\n this.pages = new PageManager(this);\r\n this.transitions = new TransitionManager(this);\r\n this.services = new ServiceManager(this);\r\n\r\n let handler = (() => {\r\n document.removeEventListener(\"DOMContentLoaded\", handler);\r\n window.removeEventListener(\"load\", handler);\r\n this.emitter.emit(\"READY ready\");\r\n }).bind(this);\r\n\r\n document.addEventListener(\"DOMContentLoaded\", handler);\r\n window.addEventListener(\"load\", handler);\r\n return this;\r\n }\r\n\r\n /**\r\n * Based on the type, it will return either a Transition, a Service, or a State from their respective Managers\r\n *\r\n * @param {(\"service\" | \"transition\" | \"state\" | string)} type\r\n * @param {any} key\r\n * @returns Service | Transition | State\r\n * @memberof App\r\n */\r\n public get(type: \"service\" | \"transition\" | \"state\" | string, key: any): Service | ITransition | IState {\r\n switch (type.toLowerCase()) {\r\n case \"service\":\r\n return this.services.get(key);\r\n case \"transition\":\r\n return this.transitions.get(key);\r\n case \"state\":\r\n return this.history.get(key);\r\n default:\r\n throw `Error: can't get type '${type}', it is not a recognized type. Did you spell it correctly.`;\r\n }\r\n }\r\n\r\n /**\r\n * Based on the type, it will return load either Page a Transition, a Service, a State, or a Page from their respective Managers\r\n *\r\n * @param {(\"page\" | string)} type\r\n * @param {any} key\r\n * @returns App\r\n * @memberof App\r\n */\r\n public async load(type: \"page\" | string, key: any): Promise {\r\n switch (type.toLowerCase()) {\r\n case \"page\":\r\n return await this.pages.load(key);\r\n default:\r\n return Promise.resolve(this.get(type, key));\r\n }\r\n }\r\n\r\n /**\r\n * Adds a Service to the App's instance of the ServiceManager, with a name\r\n *\r\n * @param {string} key\r\n * @param {Service} service\r\n * @returns App\r\n * @memberof App\r\n */\r\n public setService(key: string, service: Service): App {\r\n this.services.set(key, service);\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a Service to the App's instance of the ServiceManager, with a name\r\n *\r\n * @param {string} key\r\n * @param {ITransition} tranisition\r\n * @returns App\r\n * @memberof App\r\n */\r\n public setTransition(key: string, transition: ITransition): App {\r\n this.transitions.set(key, transition);\r\n return this;\r\n }\r\n\r\n /**\r\n * Based on the type, it will add either a Transition, a Service, or a State to their respective Managers\r\n *\r\n * @param {(\"service\" | \"transition\" | \"state\")} type\r\n * @param {any} value\r\n * @returns App\r\n * @memberof App\r\n */\r\n public add(type: \"service\" | \"transition\" | \"state\", value: any): App {\r\n switch (type.toLowerCase()) {\r\n case \"service\":\r\n this.services.add(value);\r\n break;\r\n case \"transition\":\r\n this.transitions.set(value.name, value);\r\n break;\r\n case \"state\":\r\n this.history.add(value);\r\n break;\r\n default:\r\n throw `Error: can't add type '${type}', it is not a recognized type. Did you spell it correctly.`;\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Start the App and the ServiceManager\r\n *\r\n * @returns App\r\n * @memberof App\r\n */\r\n public boot(): App {\r\n this.services.init();\r\n this.services.boot();\r\n return this;\r\n }\r\n\r\n /**\r\n * Stop the App and the ServiceManager\r\n *\r\n * @returns App\r\n * @memberof App\r\n */\r\n public stop(): App {\r\n this.services.stop();\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter on method\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} callback\r\n * @returns App\r\n * @memberof App\r\n */\r\n public on(events: EventInput, callback?: ListenerCallback): App {\r\n this.emitter.on(events, callback, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter off method\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} callback\r\n * @returns App\r\n * @memberof App\r\n */\r\n public off(events: EventInput, callback?: ListenerCallback): App {\r\n this.emitter.off(events, callback, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter emit method\r\n *\r\n * @param {(string | any[])} events\r\n * @param {...any} args\r\n * @returns App\r\n * @memberof App\r\n */\r\n public emit(events: string | any[], ...args: any): App {\r\n this.emitter.emit(events, ...args);\r\n return this;\r\n }\r\n}\r\n", "import { newState, Trigger, IState, newCoords, IHistoryItem } from \"./history\";\r\nimport { Service } from \"./service\";\r\nimport { Page } from \"./page\";\r\nimport { newURL, getHashedPath, equal } from \"./url\";\r\n\r\nexport type LinkEvent = MouseEvent | TouchEvent;\r\nexport type StateEvent = LinkEvent | PopStateEvent;\r\nexport type IgnoreURLsList = Array;\r\n\r\n/**\r\n * Creates a Barba JS like PJAX Service, for the Framework\r\n *\r\n * @export\r\n * @class PJAX\r\n * @extends {Service}\r\n */\r\n// Based on Barba JS and StartingBlocks\r\nexport class PJAX extends Service {\r\n /**\r\n * URLs to ignore when prefetching\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected ignoreURLs: IgnoreURLsList = [];\r\n\r\n /**\r\n * Whether or not to disable prefetching\r\n *\r\n * @private\r\n *\r\n * @memberof PJAX\r\n */\r\n protected prefetchIgnore: boolean = false;\r\n\r\n /**\r\n * Current state or transitions\r\n *\r\n * @public\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n public isTransitioning: boolean = false;\r\n\r\n /**\r\n * Ignore extra clicks of an anchor element if a transition has already started\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected stopOnTransitioning: boolean = false;\r\n\r\n /**\r\n * On page change (excluding popstate event) keep current scroll position\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected stickyScroll: boolean = false;\r\n\r\n /**\r\n * Force load a page if an error occurs\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected forceOnError: boolean = false;\r\n\r\n /**\r\n * Dictates whether to auto scroll if an hash is present in the window URL\r\n *\r\n * @protected\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected autoScrollOnHash: boolean = true;\r\n\r\n /**\r\n * Disables all extra scroll effects of PJAX, however, it won't affect scroll on hash,\r\n * since scrolling when an hash is in the URL is the default behavior\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected dontScroll: boolean = true;\r\n\r\n /**\r\n * Sets the transition state, sets isTransitioning to true\r\n *\r\n * @private\r\n * @memberof PJAX\r\n */\r\n private transitionStart() {\r\n this.isTransitioning = true;\r\n }\r\n\r\n /**\r\n * Sets the transition state, sets isTransitioning to false\r\n *\r\n * @private\r\n * @memberof PJAX\r\n */\r\n private transitionStop() {\r\n this.isTransitioning = false;\r\n }\r\n\r\n public init() {\r\n super.init();\r\n\r\n /**\r\n * Bind the event listeners to the PJAX class\r\n *\r\n * @memberof PJAX\r\n */\r\n this.onHover = this.onHover.bind(this);\r\n this.onClick = this.onClick.bind(this);\r\n this.onStateChange = this.onStateChange.bind(this);\r\n }\r\n\r\n /**\r\n * Starts the PJAX Service\r\n *\r\n * @memberof PJAX\r\n */\r\n public boot() {\r\n if (\"scrollRestoration\" in window.history) {\r\n // Back off, browser, I got this...\r\n window.history.scrollRestoration = \"manual\";\r\n }\r\n\r\n super.boot();\r\n }\r\n\r\n /**\r\n * Gets the transition to use for a certain anchor\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @returns {(string | null)}\r\n * @memberof PJAX\r\n */\r\n public getTransitionName(el: HTMLAnchorElement): string | null {\r\n if (!el || !el.getAttribute) return null;\r\n let transitionAttr = el.getAttribute(\r\n this.config.getConfig(\"transitionAttr\", false)\r\n );\r\n if (typeof transitionAttr === \"string\") return transitionAttr;\r\n return null;\r\n }\r\n\r\n /**\r\n * Checks to see if the anchor is valid\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @param {(LinkEvent | KeyboardEvent)} event\r\n * @param {string} href\r\n *\r\n * @memberof PJAX\r\n */\r\n public validLink(\r\n el: HTMLAnchorElement,\r\n event: LinkEvent | KeyboardEvent,\r\n href: string\r\n ): boolean {\r\n let pushStateSupport = !window.history.pushState;\r\n let exists = !el || !href;\r\n let eventMutate =\r\n (event as KeyboardEvent).metaKey ||\r\n (event as KeyboardEvent).ctrlKey ||\r\n (event as KeyboardEvent).shiftKey ||\r\n (event as KeyboardEvent).altKey;\r\n let newTab =\r\n el.hasAttribute(\"target\") &&\r\n (el as HTMLAnchorElement).target === \"_blank\";\r\n let crossOrigin =\r\n (el as HTMLAnchorElement).protocol !== location.protocol ||\r\n (el as HTMLAnchorElement).hostname !== location.hostname;\r\n let download = typeof el.getAttribute(\"download\") === \"string\";\r\n let preventSelf = el.hasAttribute(this.config.getConfig(\"preventSelfAttr\", false));\r\n let preventAll = Boolean(\r\n el.closest(this.config.getConfig(\"preventAllAttr\"))\r\n );\r\n let prevent = preventSelf && preventAll;\r\n let sameURL = getHashedPath(newURL()) === getHashedPath(newURL(href));\r\n return !(\r\n exists ||\r\n pushStateSupport ||\r\n eventMutate ||\r\n newTab ||\r\n crossOrigin ||\r\n download ||\r\n prevent ||\r\n sameURL\r\n );\r\n }\r\n\r\n /**\r\n * Returns the href or an Anchor element\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @returns {(string | null)}\r\n * @memberof PJAX\r\n */\r\n public getHref(el: HTMLAnchorElement): string | null {\r\n if (\r\n el &&\r\n el.tagName &&\r\n el.tagName.toLowerCase() === \"a\" &&\r\n typeof el.href === \"string\"\r\n )\r\n return el.href;\r\n return null;\r\n }\r\n\r\n /**\r\n * Check if event target is a valid anchor with an href, if so, return the link\r\n *\r\n * @param {LinkEvent} event\r\n *\r\n * @memberof PJAX\r\n */\r\n public getLink(event: LinkEvent): HTMLAnchorElement {\r\n let el = event.target as HTMLAnchorElement;\r\n let href: string = this.getHref(el);\r\n\r\n while (el && !href) {\r\n el = (el as HTMLElement).parentNode as HTMLAnchorElement;\r\n href = this.getHref(el);\r\n }\r\n\r\n // Check for a valid link\r\n if (!el || !this.validLink(el, event, href)) return;\r\n return el;\r\n }\r\n\r\n /**\r\n * When an element is clicked.\r\n *\r\n * Get valid anchor element.\r\n * Go for a transition.\r\n *\r\n * @param {LinkEvent} event\r\n * @returns\r\n * @memberof PJAX\r\n */\r\n public onClick(event: LinkEvent) {\r\n let el = this.getLink(event);\r\n if (!el) return;\r\n\r\n if (this.isTransitioning && this.stopOnTransitioning) {\r\n event.preventDefault();\r\n event.stopPropagation();\r\n return;\r\n }\r\n\r\n let href = this.getHref(el);\r\n this.emitter.emit(\"ANCHOR_CLICK CLICK\", event);\r\n this.go({ href, trigger: el, event });\r\n }\r\n\r\n /**\r\n * Returns the direction of the State change as a String, either the Back button or the Forward button\r\n *\r\n * @param {number} value\r\n *\r\n * @memberof PJAX\r\n */\r\n public getDirection(value: number): Trigger {\r\n if (Math.abs(value) > 1) {\r\n // Ex 6-0 > 0 -> forward, 0-6 < 0 -> back\r\n return value > 0 ? \"forward\" : \"back\";\r\n } else {\r\n if (value === 0) {\r\n return \"popstate\";\r\n } else {\r\n // Ex 6-5 > 0 -> back, 5-6 < 0 -> forward\r\n return value > 0 ? \"back\" : \"forward\";\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Force a page to go to a certain URL\r\n *\r\n * @param {string} href\r\n * @memberof PJAX\r\n */\r\n public force(href: string): void {\r\n window.location.assign(href);\r\n }\r\n\r\n /**\r\n * If transition is running force load page.\r\n * Stop if currentURL is the same as new url.\r\n * On state change, change the current state history,\r\n * to reflect the direction of said state change\r\n * Load page and page transition.\r\n *\r\n * @param {string} href\r\n * @param {Trigger} [trigger='HistoryManager']\r\n * @param {StateEvent} [event]\r\n * @memberof PJAX\r\n */\r\n public go({\r\n href,\r\n trigger = \"HistoryManager\",\r\n event,\r\n }: {\r\n href: string;\r\n trigger?: Trigger;\r\n event?: StateEvent;\r\n }): Promise {\r\n // If transition is already running and the go method is called again, force load page\r\n if (this.isTransitioning && this.stopOnTransitioning) {\r\n this.force(href);\r\n return;\r\n }\r\n\r\n let scroll = { x: 0, y: 0 };\r\n let currentState = this.HistoryManager.current;\r\n let currentURL = currentState.url;\r\n if (equal(currentURL, href)) {\r\n return;\r\n }\r\n\r\n let transitionName: string;\r\n if (event && (event as PopStateEvent).state) {\r\n this.emitter.emit(\"POPSTATE\", event);\r\n\r\n // If popstate, get back/forward direction.\r\n let { state }: { state: IHistoryItem } = event as PopStateEvent;\r\n let { index } = state;\r\n let currentIndex = currentState.index;\r\n let difference = currentIndex - index;\r\n\r\n trigger = this.getDirection(difference);\r\n\r\n // Based on the direction of the state change either remove or add a state\r\n this.HistoryManager.replace(state.states);\r\n this.HistoryManager.pointer = index;\r\n if (trigger === \"back\") {\r\n // this.HistoryManager.remove(currentIndex);\r\n this.emitter.emit(`POPSTATE_BACK`, event);\r\n } else if (trigger === \"forward\") {\r\n // this.HistoryManager.add({ url: href, transition, data });\r\n this.emitter.emit(`POPSTATE_FORWARD`, event);\r\n }\r\n\r\n let _state = this.HistoryManager.get(index);\r\n transitionName = _state.transition;\r\n\r\n // If the page remains on the same history state DO NOT scroll, it's pointless\r\n if (trigger !== \"popstate\") {\r\n // Keep scroll position\r\n scroll = _state.data.scroll;\r\n }\r\n } else {\r\n // Add new state\r\n transitionName = this.getTransitionName(trigger as HTMLAnchorElement) ||\r\n \"default\";\r\n let scrollCoords = newCoords();\r\n\r\n if (!this.dontScroll && this.stickyScroll) {\r\n // Keep scroll position\r\n let { x, y } = scrollCoords;\r\n scroll = { x, y };\r\n } else {\r\n scroll = {\r\n x: 0,\r\n y: 0\r\n };\r\n }\r\n\r\n let state = newState({\r\n url: href,\r\n transition: transitionName,\r\n data: { scroll: scrollCoords },\r\n });\r\n\r\n this.HistoryManager.add(state);\r\n this.emitter.emit(\"HISTORY_NEW_ITEM\", event);\r\n }\r\n\r\n if (event) {\r\n event.stopPropagation();\r\n event.preventDefault();\r\n }\r\n\r\n this.emitter.emit(\"GO\", event);\r\n return this.load({\r\n oldHref: currentURL,\r\n href,\r\n trigger,\r\n transitionName,\r\n scroll,\r\n });\r\n }\r\n\r\n /**\r\n * Load the new Page as well as a Transition; run the Transition\r\n *\r\n * @param {string} oldHref\r\n * @param {string} href\r\n * @param {Trigger} trigger\r\n * @param {string} [transitionName=\"default\"]\r\n *\r\n * @memberof PJAX\r\n */\r\n public async load({\r\n oldHref,\r\n href,\r\n trigger,\r\n transitionName = \"default\",\r\n scroll = { x: 0, y: 0 },\r\n }: {\r\n oldHref: string;\r\n href: string;\r\n trigger: Trigger;\r\n transitionName?: string;\r\n scroll: { x: number; y: number };\r\n }): Promise {\r\n try {\r\n let oldPage = await this.PageManager.load(oldHref);\r\n await oldPage.build();\r\n let newPage: Page;\r\n\r\n this.emitter.emit(\"PAGE_LOADING\", { href, oldPage, trigger });\r\n try {\r\n try {\r\n newPage = await this.PageManager.load(href);\r\n await newPage.build();\r\n this.transitionStart();\r\n this.emitter.emit(\"PAGE_LOAD_COMPLETE\", {\r\n newPage,\r\n oldPage,\r\n trigger,\r\n });\r\n } catch (err) {\r\n console.error(`[PJAX] page load error: ${err}`);\r\n }\r\n\r\n // --\r\n // --\r\n\r\n this.emitter.emit(\"NAVIGATION_START\", {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n transitionName,\r\n });\r\n\r\n try {\r\n this.emitter.emit(\"TRANSITION_START\", transitionName);\r\n let transition = await this.TransitionManager.boot(transitionName, {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n scroll,\r\n });\r\n\r\n if (!transition.scrollable) {\r\n if (!/back|popstate|forward/.test(trigger as string)) scroll = hashAction(href);\r\n window.scroll(scroll.x, scroll.y);\r\n }\r\n\r\n this.emitter.emit(\"TRANSITION_END\", { transition });\r\n\r\n } catch (err) {\r\n console.error(`[PJAX] transition error: ${err}`);\r\n }\r\n\r\n this.emitter.emit(\"NAVIGATION_END\", {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n transitionName,\r\n });\r\n } catch (err) {\r\n this.transitionStop();\r\n throw err;\r\n }\r\n\r\n this.transitionStop(); // Sets isTransitioning to false\r\n } catch (err) {\r\n if (this.forceOnError) this.force(href);\r\n else console.error(err);\r\n }\r\n }\r\n\r\n /**\r\n * Check to see if the URL is to be ignored, uses either RegExp of Strings to check\r\n *\r\n * @param {URL} { pathname }\r\n *\r\n * @memberof PJAX\r\n */\r\n public ignoredURL({ pathname }: URL): boolean {\r\n return (\r\n this.ignoreURLs.length &&\r\n this.ignoreURLs.some((url) => {\r\n return typeof url === \"string\"\r\n ? url === pathname\r\n : (url as RegExp).exec(pathname) !== null;\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * When you hover over an anchor, prefetch the event target's href\r\n *\r\n * @param {LinkEvent} event\r\n * @memberof PJAX\r\n */\r\n public onHover(event: LinkEvent): Promise {\r\n let el = this.getLink(event);\r\n if (!el) return;\r\n\r\n let url = newURL(this.getHref(el));\r\n let urlString: string = url.pathname;\r\n // If Url is ignored or already in cache, don't do any think\r\n if (this.ignoredURL(url) || this.PageManager.has(urlString)) return;\r\n this.emitter.emit(\"ANCHOR_HOVER HOVER\", event);\r\n\r\n try {\r\n this.PageManager.load(url);\r\n } catch (err) {\r\n console.warn(\"[PJAX] prefetch error,\", err);\r\n }\r\n }\r\n\r\n /**\r\n * When History state changes.\r\n *\r\n * Get url from State\r\n * Go for a Barba transition.\r\n *\r\n * @param {PopStateEvent} event\r\n * @memberof PJAX\r\n */\r\n public onStateChange(event: PopStateEvent): void {\r\n this.go({ href: window.location.href, trigger: \"popstate\", event });\r\n }\r\n\r\n /**\r\n * Initialize DOM Events\r\n *\r\n * @memberof PJAX\r\n */\r\n public initEvents() {\r\n if (this.prefetchIgnore !== true) {\r\n document.addEventListener(\"mouseover\", this.onHover);\r\n document.addEventListener(\"touchstart\", this.onHover);\r\n }\r\n\r\n document.addEventListener(\"click\", this.onClick);\r\n window.addEventListener(\"popstate\", this.onStateChange);\r\n }\r\n\r\n /**\r\n * Stop DOM Events\r\n *\r\n * @memberof PJAX\r\n */\r\n public stopEvents() {\r\n if (this.prefetchIgnore !== true) {\r\n document.removeEventListener(\"mouseover\", this.onHover);\r\n document.removeEventListener(\"touchstart\", this.onHover);\r\n }\r\n\r\n document.removeEventListener(\"click\", this.onClick);\r\n window.removeEventListener(\"popstate\", this.onStateChange);\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Auto scrolls to an elements position if the element has an hash\r\n *\r\n * @param {string} [hash=window.location.hash]\r\n * @memberof PJAX\r\n */\r\nexport const hashAction = (hash: string = window.location.hash) => {\r\n try {\r\n let _hash = hash[0] == \"#\" ? hash : newURL(hash).hash;\r\n if (_hash.length > 1) {\r\n let el = document.querySelector(_hash) as HTMLElement;\r\n\r\n if (el) {\r\n return { x: el.offsetLeft, y: el.offsetTop };\r\n }\r\n }\r\n } catch (e) {\r\n console.warn(\"hashAction error\", e);\r\n }\r\n\r\n return { x: 0, y: 0 };\r\n};\r\n", "import { Service } from \"./service\";\r\nimport { Manager } from \"./manager\";\r\nimport { newURL, getHashedPath } from \"./url\";\r\n\r\nexport type RouteMethod = (...args: any) => any;\r\nexport type RouteStyle = string | RegExp | boolean;\r\nexport interface IRouteToFrom {\r\n to: RouteStyle,\r\n from: RouteStyle\r\n}\r\nexport type RoutePath = IRouteToFrom | RouteStyle;\r\nexport interface IRoute {\r\n path: RoutePath,\r\n method: RouteMethod\r\n}\r\n\r\n/**\r\n * Controls what happens when certain url paths match a set of criteria\r\n *\r\n * @export\r\n * @class Router\r\n * @extends {Service}\r\n */\r\nexport class Router extends Service {\r\n /**\r\n * List of routes inputted\r\n *\r\n * @protected\r\n * @type {Manager}\r\n * @memberof Router\r\n */\r\n protected routes: Manager;\r\n\r\n /**\r\n * Creates an instance of Router.\r\n *\r\n * @param {Array} [routes=[]]\r\n * @memberof Router\r\n */\r\n constructor(routes: IRoute[] = []) {\r\n super();\r\n this.routes = new Manager();\r\n for (let route of routes) {\r\n this.add(route);\r\n }\r\n }\r\n\r\n /**\r\n * Add a new route to watch for\r\n *\r\n * @param {IRoute} { path, method }\r\n * @returns {Router}\r\n * @memberof Router\r\n */\r\n public add({ path, method }: IRoute): Router {\r\n let key = this.parse(path);\r\n this.routes.set(key, method);\r\n return this;\r\n }\r\n\r\n /**\r\n * Convert strings into path match functions\r\n *\r\n * @param {RouteStyle} path\r\n * @returns {RegExp | boolean}\r\n * @memberof Router\r\n */\r\n public parsePath(path: RouteStyle): RegExp | boolean {\r\n if (typeof path === \"string\") return new RegExp(path, \"i\");\r\n else if (path instanceof RegExp || typeof path === \"boolean\")\r\n return path;\r\n throw \"[Router] only regular expressions, strings and booleans are accepted as paths.\";\r\n }\r\n\r\n /**\r\n * Determines if a strings counts has a path\r\n *\r\n * @param {RouteStyle} input\r\n * @returns boolean\r\n * @memberof Router\r\n */\r\n public isPath(input: RouteStyle): boolean {\r\n return (\r\n typeof input === \"string\" ||\r\n input instanceof RegExp ||\r\n typeof input === \"boolean\"\r\n );\r\n }\r\n\r\n /**\r\n * Parse the multiple different formats for paths, into a { from, to } object\r\n *\r\n * @param {RouteStyle} input\r\n * @returns {IRouteToFrom}\r\n * @memberof Router\r\n */\r\n public parse(input: RoutePath): IRouteToFrom {\r\n let route = input as IRouteToFrom;\r\n let toFromPath: IRouteToFrom = {\r\n from: /(.*)/g,\r\n to: /(.*)/g,\r\n };\r\n\r\n if (this.isPath(input as RouteStyle))\r\n toFromPath = {\r\n from: true,\r\n to: input as RouteStyle,\r\n };\r\n else if (this.isPath(route.from) && this.isPath(route.to as RouteStyle))\r\n toFromPath = route;\r\n else\r\n throw \"[Router] path is neither a string, regular expression, or a { from, to } object.\";\r\n\r\n let { from, to } = toFromPath;\r\n return {\r\n from: this.parsePath(from),\r\n to: this.parsePath(to),\r\n };\r\n }\r\n\r\n /**\r\n * Test if route paths are true, if so run their methods\r\n *\r\n * @memberof Router\r\n */\r\n public route() {\r\n let history = this.HistoryManager;\r\n let from: string = getHashedPath(newURL((history.length > 1 ? history.previous : history.current).url));\r\n let to: string = getHashedPath(newURL());\r\n\r\n this.routes.forEach((method: RouteMethod, path: IRouteToFrom) => {\r\n let fromRegExp = path.from as RegExp | boolean;\r\n let toRegExp = path.to as RegExp | boolean;\r\n\r\n if (\r\n typeof fromRegExp === \"boolean\" &&\r\n typeof toRegExp === \"boolean\"\r\n ) {\r\n throw `[Router] path ({ from: ${fromRegExp}, to: ${toRegExp} }) is not valid, remember paths can only be strings, regular expressions, or a boolean; however, both the from and to paths cannot be both booleans.`;\r\n }\r\n\r\n let fromParam: RegExpExecArray | RegExp | boolean = fromRegExp;\r\n let toParam: RegExpExecArray | RegExp | boolean = toRegExp;\r\n\r\n if (fromRegExp instanceof RegExp && fromRegExp.test(from))\r\n fromParam = fromRegExp.exec(from);\r\n if (toRegExp instanceof RegExp && toRegExp.test(to))\r\n toParam = toRegExp.exec(to);\r\n\r\n if (\r\n (Array.isArray(toParam) && Array.isArray(fromParam)) ||\r\n (Array.isArray(toParam) &&\r\n typeof fromParam == \"boolean\" &&\r\n fromParam) ||\r\n (Array.isArray(fromParam) &&\r\n typeof toParam == \"boolean\" &&\r\n toParam)\r\n )\r\n method({ from: fromParam, to: toParam, path: { from, to } });\r\n });\r\n }\r\n\r\n /**\r\n * Add listeners for PJAX Events\r\n *\r\n * @memberof Router\r\n */\r\n public initEvents() {\r\n this.emitter.on(\"READY\", this.route, this);\r\n this.emitter.on(\"CONTENT_REPLACED\", this.route, this);\r\n }\r\n\r\n /**\r\n * Remove listeners for PJAX Events\r\n *\r\n * @memberof Router\r\n */\r\n public stopEvents() {\r\n this.emitter.off(\"READY\", this.route, this);\r\n this.emitter.off(\"CONTENT_REPLACED\", this.route, this);\r\n }\r\n}\r\n", "import { EventEmitter, EventInput, ListenerCallback } from \"@okikio/emitter\";\r\n\r\n// DOM\r\nexport type AnimationTarget = string | Node | NodeList | HTMLCollection | HTMLElement[] | any[];\r\nexport const getElements = (selector: string | Node): Node[] => {\r\n return typeof selector === \"string\" ? Array.from(document.querySelectorAll(selector as string)) : [selector];\r\n};\r\n\r\nexport const getTargets = (targets: AnimationTarget): Node[] => {\r\n if (Array.isArray(targets)) return targets;\r\n if (typeof targets == \"string\" || targets instanceof Node)\r\n return getElements(targets);\r\n if (targets instanceof NodeList || targets instanceof HTMLCollection)\r\n return Array.from(targets);\r\n return [];\r\n};\r\n\r\n// VALUES\r\nexport type closureArgs = [number, number, HTMLElement];\r\nexport type closure = ((index?: number, total?: number, element?: HTMLElement) => any) | any;\r\nexport const computeValue = (value: closure, args: closureArgs) => {\r\n if (typeof value === \"function\") {\r\n return value(...args);\r\n } else { return value; }\r\n};\r\n\r\nexport const mapObject = (obj: object, args: closureArgs): any => {\r\n let key, value, result = {};\r\n let keys = Object.keys(obj);\r\n for (let i = 0, len = keys.length; i < len; i++) {\r\n key = keys[i];\r\n value = obj[key];\r\n result[key] = computeValue(value, args);\r\n }\r\n\r\n return result;\r\n};\r\n\r\n// From: [https://easings.net]\r\nexport const easings = {\r\n \"ease\": \"ease\",\r\n \"in\": \"ease-in\",\r\n \"out\": \"ease-out\",\r\n \"in-out\": \"ease-in-out\",\r\n\r\n // Sine\r\n \"in-sine\": \"cubic-bezier(0.47, 0, 0.745, 0.715)\",\r\n \"out-sine\": \"cubic-bezier(0.39, 0.575, 0.565, 1)\",\r\n \"in-out-sine\": \"cubic-bezier(0.445, 0.05, 0.55, 0.95)\",\r\n\r\n // Quad\r\n \"in-quad\": \"cubic-bezier(0.55, 0.085, 0.68, 0.53)\",\r\n \"out-quad\": \"cubic-bezier(0.25, 0.46, 0.45, 0.94)\",\r\n \"in-out-quad\": \"cubic-bezier(0.455, 0.03, 0.515, 0.955)\",\r\n\r\n // Cubic\r\n \"in-cubic\": \"cubic-bezier(0.55, 0.055, 0.675, 0.19)\",\r\n \"out-cubic\": \"cubic-bezier(0.215, 0.61, 0.355, 1)\",\r\n \"in-out-cubic\": \"cubic-bezier(0.645, 0.045, 0.355, 1)\",\r\n\r\n // Quart\r\n \"in-quart\": \"cubic-bezier(0.895, 0.03, 0.685, 0.22)\",\r\n \"out-quart\": \"cubic-bezier(0.165, 0.84, 0.44, 1)\",\r\n \"in-out-quart\": \"cubic-bezier(0.77, 0, 0.175, 1)\",\r\n\r\n // Quint\r\n \"in-quint\": \"cubic-bezier(0.755, 0.05, 0.855, 0.06)\",\r\n \"out-quint\": \"cubic-bezier(0.23, 1, 0.32, 1)\",\r\n \"in-out-quint\": \"cubic-bezier(0.86, 0, 0.07, 1)\",\r\n\r\n // Expo\r\n \"in-expo\": \"cubic-bezier(0.95, 0.05, 0.795, 0.035)\",\r\n \"out-expo\": \"cubic-bezier(0.19, 1, 0.22, 1)\",\r\n \"in-out-expo\": \"cubic-bezier(1, 0, 0, 1)\",\r\n\r\n // Circ\r\n \"in-circ\": \"cubic-bezier(0.6, 0.04, 0.98, 0.335)\",\r\n \"out-circ\": \"cubic-bezier(0.075, 0.82, 0.165, 1)\",\r\n \"in-out-circ\": \"cubic-bezier(0.785, 0.135, 0.15, 0.86)\",\r\n\r\n // Back\r\n \"in-back\": \"cubic-bezier(0.6, -0.28, 0.735, 0.045)\",\r\n \"out-back\": \"cubic-bezier(0.175, 0.885, 0.32, 1.275)\",\r\n \"in-out-back\": \"cubic-bezier(0.68, -0.55, 0.265, 1.55)\"\r\n};\r\nexport const getEase = (ease: string) => {\r\n return /^(ease|in|out)/.test(ease) ? easings[ease] : ease;\r\n};\r\n\r\nexport interface AnimationOptions {\r\n target?: AnimationTarget,\r\n\r\n speed?: number | closure,\r\n delay?: number | closure,\r\n easing?: string | closure,\r\n endDelay?: number | closure,\r\n duration?: number | closure,\r\n autoplay?: boolean | closure,\r\n keyframes?: object[] | closure,\r\n loop?: number | boolean | closure, // iterations: number,\r\n options?: AnimationOptions | closure,\r\n onfinish?: (element?: HTMLElement, index?: number, total?: number) => any,\r\n fillMode?: \"none\" | \"forwards\" | \"backwards\" | \"both\" | \"auto\" | closure,\r\n direction?: \"normal\" | \"reverse\" | \"alternate\" | \"alternate-reverse\" | closure,\r\n [property: string]: closure | boolean | object | string | string[] | number | null | (number | null)[] | undefined;\r\n};\r\n\r\nexport const DefaultAnimationOptions: AnimationOptions = {\r\n keyframes: [],\r\n\r\n loop: 1, // iterations: number,\r\n delay: 0,\r\n speed: 1,\r\n endDelay: 0,\r\n easing: \"ease\",\r\n autoplay: true,\r\n duration: 1000,\r\n onfinish() { },\r\n fillMode: \"auto\",\r\n direction: \"normal\",\r\n};\r\n\r\n// You can check it out here: https://codepen.io/okikio/pen/qBbdGaW?editors=0011\r\nexport class Animate {\r\n /**\r\n * Stores the options for the current animation\r\n *\r\n * @public\r\n * @type AnimationOptions\r\n * @memberof Animate\r\n */\r\n public options: AnimationOptions = {};\r\n\r\n /**\r\n * The Array of Elements to Animate\r\n *\r\n * @public\r\n * @type {Node[]}\r\n * @memberof Animate\r\n */\r\n public targets: Node[] = [];\r\n\r\n /**\r\n * The properties to animate\r\n *\r\n * @public\r\n * @type {object}\r\n * @memberof Animate\r\n */\r\n public properties: object = {};\r\n\r\n /**\r\n * A Set of Animations\r\n *\r\n * @public\r\n * @type {Map}\r\n * @memberof Animate\r\n */\r\n public animations: Map = new Map();\r\n\r\n /**\r\n * The total duration of all Animation's\r\n *\r\n * @public\r\n * @type {number}\r\n * @memberof Animate\r\n */\r\n public duration: number = 0;\r\n\r\n /**\r\n * The Element the main animation uses\r\n *\r\n * @public\r\n * @type {HTMLElement}\r\n * @memberof Animate\r\n */\r\n public mainElement: HTMLElement;\r\n\r\n /**\r\n * Stores an animation that runs on the total duration of the all other Animations, and as such it's the main Animation\r\n *\r\n * @public\r\n * @type {Animation}\r\n * @memberof Animate\r\n */\r\n public mainAnimation: Animation;\r\n\r\n /**\r\n * Stores request frame calls\r\n *\r\n * @public\r\n * @type {number}\r\n * @memberof Animate\r\n */\r\n public animationFrame: number;\r\n\r\n /**\r\n * An event emitter\r\n *\r\n * @public\r\n * @type {EventEmitter}\r\n * @memberof Animate\r\n */\r\n public emitter: EventEmitter = new EventEmitter();\r\n\r\n /**\r\n * The finish method, is called when the main animation has finished\r\n *\r\n * @public\r\n * @type {*}\r\n * @memberof Animate\r\n */\r\n public finish: any;\r\n\r\n /**\r\n * Returns a promise that is fulfilled when the mainAnimation is finished\r\n *\r\n * @public\r\n * @type {Promise}\r\n * @memberof Animate\r\n */\r\n public promise: Promise;\r\n\r\n /**\r\n * Creates an instance of Animate.\r\n *\r\n * @param {AnimationOptions} options\r\n * @memberof Animate\r\n */\r\n constructor(options: AnimationOptions = {}) {\r\n let { options: animation, ...rest } = options;\r\n this.options = Object.assign({}, DefaultAnimationOptions, animation, rest);\r\n this.loop = this.loop.bind(this);\r\n\r\n let {\r\n loop,\r\n delay,\r\n speed,\r\n easing,\r\n endDelay,\r\n duration,\r\n direction,\r\n fillMode,\r\n onfinish,\r\n target,\r\n keyframes,\r\n autoplay,\r\n ...properties\r\n } = this.options;\r\n\r\n this.mainElement = document.createElement(\"span\");\r\n this.targets = getTargets(target);\r\n this.properties = properties;\r\n\r\n let animationKeyframe: Keyframe[] | PropertyIndexedKeyframes;\r\n for (let i = 0, len = this.targets.length; i < len; i++) {\r\n let target = this.targets[i] as HTMLElement;\r\n let animationOptions = {\r\n easing: getEase(easing),\r\n iterations: loop === true ? Infinity : (loop as number),\r\n direction,\r\n endDelay,\r\n duration,\r\n delay,\r\n fill: fillMode,\r\n };\r\n\r\n // Accept keyframes as a keyframes Object, or a method,\r\n // if there are no animations in the keyframes array,\r\n // uses css properties from the options object\r\n let arrKeyframes = computeValue((keyframes as Keyframe[]), [i, len, target]);\r\n animationKeyframe = arrKeyframes.length ? arrKeyframes :\r\n (this.properties as PropertyIndexedKeyframes);\r\n\r\n // Allows the use of functions as the values, for both the keyframes and the animation object\r\n // It adds the capability of advanced stagger animation, similar to the anime js stagger functions\r\n animationOptions = mapObject(animationOptions, [i, len, target]);\r\n if (!(arrKeyframes.length > 0))\r\n animationKeyframe = mapObject(animationKeyframe, [i, len, target]);\r\n\r\n // Set the Animate classes duration to be the Animation with the largest totalDuration\r\n let tempDuration: number =\r\n animationOptions.delay +\r\n (animationOptions.duration * animationOptions.iterations) +\r\n animationOptions.endDelay;\r\n if (this.duration < tempDuration) this.duration = tempDuration;\r\n\r\n // Add animation to the Animations Set\r\n let animation = target.animate(animationKeyframe, animationOptions);\r\n animation.onfinish = () => {\r\n onfinish(target, i, len);\r\n };\r\n this.animations.set(target, animation);\r\n }\r\n\r\n this.mainAnimation = this.mainElement.animate([\r\n { opacity: \"0\" },\r\n { opacity: \"1\" }\r\n ], {\r\n duration: this.duration,\r\n easing: \"linear\"\r\n });\r\n\r\n this.setSpeed(speed);\r\n if (autoplay) this.play();\r\n else this.pause();\r\n\r\n this.promise = this.newPromise();\r\n this.mainAnimation.onfinish = () => {\r\n this.finish(this.options);\r\n window.cancelAnimationFrame(this.animationFrame);\r\n };\r\n }\r\n\r\n /**\r\n * Returns the Array of targets\r\n *\r\n * @returns {Node[]}\r\n * @memberof Animate\r\n */\r\n public getTargets(): Node[] {\r\n return this.targets;\r\n }\r\n\r\n /**\r\n * Returns a new Promise that is resolve when this.finish is called\r\n *\r\n * @public\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public newPromise(): Promise {\r\n return new Promise((resolve, reject) => {\r\n try {\r\n this.finish = (options: AnimationOptions) => {\r\n this.emit(\"finish\", options);\r\n return resolve(options);\r\n };\r\n } catch (err) { reject(err); }\r\n });\r\n }\r\n\r\n /**\r\n * Fulfills the this.promise Promise\r\n *\r\n * @param {(value?: any) => any} [onFulfilled]\r\n * @param {(reason?: any) => any} [onRejected]\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public then(\r\n onFulfilled?: (value?: any) => any,\r\n onRejected?: (reason?: any) => any\r\n ): Promise {\r\n return this.promise.then(onFulfilled, onRejected);\r\n }\r\n\r\n /**\r\n * Catches error that occur in the this.promise Promise\r\n *\r\n * @param {(reason?: any) => any} onRejected\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public catch(onRejected: (reason?: any) => any): Promise {\r\n return this.promise.catch(onRejected);\r\n }\r\n\r\n /**\r\n * If you don't care if the this.promise Promise has either been rejected or resolved\r\n *\r\n * @param {() => any} onFinally\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public finally(onFinally: () => any): Promise {\r\n return this.promise.finally(onFinally);\r\n }\r\n\r\n /**\r\n * Represents an Animation Frame Loop\r\n *\r\n * @public\r\n * @memberof Animate\r\n */\r\n public loop(): void {\r\n this.animationFrame = window.requestAnimationFrame(this.loop);\r\n this.emit(\"tick change\", this.getCurrentTime());\r\n }\r\n\r\n /**\r\n * Adds a listener for a given event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public on(events: EventInput, callback?: ListenerCallback, scope?: object): Animate {\r\n this.emitter.on(events, callback, scope);\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes a listener from an event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public off(events: EventInput, callback?: ListenerCallback, scope?: object): Animate {\r\n this.emitter.off(events, callback, scope);\r\n return this;\r\n }\r\n\r\n /**\r\n * Call all listeners within an event\r\n *\r\n * @param {(string | any[])} events\r\n * @param {...any} args\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public emit(events: string | any[], ...args: any): Animate {\r\n this.emitter.emit(events, ...args);\r\n return this;\r\n }\r\n\r\n /**\r\n * Get a specific Animation from an Animate instance\r\n *\r\n * @param {HTMLElement} element\r\n * @returns {Animation}\r\n * @memberof Animate\r\n */\r\n public getAnimation(element: HTMLElement): Animation {\r\n return this.animations.get(element);\r\n }\r\n\r\n /**\r\n * Play Animation's\r\n *\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public play(): Animate {\r\n // Once the animation is done, it's done, it can only be paused by the reset method\r\n if (this.mainAnimation.playState !== \"finished\") {\r\n this.mainAnimation.play();\r\n this.animationFrame = requestAnimationFrame(this.loop);\r\n this.animations.forEach(animation => {\r\n if (animation.playState !== \"finished\") animation.play();\r\n });\r\n this.emit(\"play\");\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Pause Animation's\r\n *\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public pause(): Animate {\r\n // Once the animation is done, it's done, it can only be reset by the reset method\r\n if (this.mainAnimation.playState !== \"finished\") {\r\n this.mainAnimation.pause();\r\n window.cancelAnimationFrame(this.animationFrame);\r\n this.animations.forEach(animation => {\r\n if (animation.playState !== \"finished\") animation.pause();\r\n });\r\n this.emit(\"pause\");\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the total duration of all Animations\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getDuration(): number {\r\n return this.duration;\r\n }\r\n\r\n /**\r\n * Returns the current time of the Main Animation\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getCurrentTime(): number {\r\n return this.mainAnimation.currentTime;\r\n }\r\n\r\n /**\r\n * Set the current time of the Main Animation\r\n *\r\n * @param {number} time\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setCurrentTime(time: number): Animate {\r\n this.mainAnimation.currentTime = time;\r\n this.animations.forEach(animation => {\r\n animation.currentTime = time;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the Animation progress as a fraction of the current time / duration\r\n *\r\n * @returns\r\n * @memberof Animate\r\n */\r\n public getProgress() {\r\n return this.getCurrentTime() / this.duration;\r\n }\r\n\r\n /**\r\n * Set the Animation progress as a fraction of the current time / duration\r\n *\r\n * @param {number} percent\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setProgress(percent: number): Animate {\r\n this.mainAnimation.currentTime = percent * this.duration;\r\n this.animations.forEach(animation => {\r\n animation.currentTime = percent * this.duration;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Return the playback speed of the animation\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getSpeed(): number {\r\n return this.mainAnimation.playbackRate;\r\n }\r\n\r\n /**\r\n * Set the playback speed of an Animation\r\n *\r\n * @param {number} [speed=1]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setSpeed(speed: number = 1): Animate {\r\n this.mainAnimation.playbackRate = speed;\r\n this.animations.forEach(animation => {\r\n animation.playbackRate = speed;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Reset all Animations\r\n *\r\n * @memberof Animate\r\n */\r\n public reset() {\r\n this.setCurrentTime(0);\r\n this.promise = this.newPromise();\r\n\r\n if (this.options.autoplay) this.play();\r\n else this.pause();\r\n }\r\n\r\n /**\r\n * Returns the current playing state\r\n *\r\n * @returns {(\"idle\" | \"running\" | \"paused\" | \"finished\")}\r\n * @memberof Animate\r\n */\r\n public getPlayState(): \"idle\" | \"running\" | \"paused\" | \"finished\" {\r\n return this.mainAnimation.playState;\r\n }\r\n\r\n /**\r\n * Get the options of an Animate instance\r\n *\r\n * @returns {AnimationOptions}\r\n * @memberof Animate\r\n */\r\n public getOptions(): AnimationOptions {\r\n return this.options;\r\n }\r\n\r\n // Returns the Animate options, as JSON\r\n public toJSON(): AnimationOptions {\r\n return this.getOptions();\r\n }\r\n}\r\n\r\n// Creates a new Animate instance\r\nexport const animate = (options: AnimationOptions = {}): Animate => {\r\n return new Animate(options);\r\n};\r\n\r\nexport default animate;\r\n"], - "mappings": "oJAAA,knBCcO,IAAM,EAA2B,CACpC,YAAa,UACb,eAAgB,eAChB,eAAgB,cAChB,QAAS,CACL,CAAC,YAAa,SAElB,gBAAiB,iBACjB,eAAgB,gBAChB,eAAgB,aAChB,UAAW,QACX,QAAS,OAzBb,MAoDI,eACI,KAAK,OAAS,OAAO,OAAO,IAAK,GAAmB,GAWjD,WAA0C,IAC7C,IAAM,UAAW,KAAK,SACX,OAAO,EAAS,IAAM,EAAS,MAAM,IAChD,MAAO,GAAW,IAAI,KAAU,EAW7B,cAAkD,IACrD,GAAI,MAAO,IAAU,SACjB,MAAO,MAAK,OAEhB,MAAa,KAAK,OAAO,GACzB,MAAI,OAAO,IAAW,SACX,KAAK,OAAO,EAAQ,GACxB,ICrFf,IAAA,QAwBC,eACC,KAAK,IAAM,GAAI,KAAI,GASb,SACN,MAAO,MAAK,IAUN,OACN,MAAO,MAAK,IAAI,IAAI,GASd,OACN,MAAO,OAAM,KAAK,KAAK,IAAI,QASrB,SACN,MAAO,OAAM,KAAK,KAAK,IAAI,UAWrB,SACN,YAAK,IAAI,IAAI,EAAK,GACX,KAUD,OACN,MAAW,KAAK,OAEH,E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,IACpB,EAAU,aAAe,IAEtB,KAQJ,QACH,KAAK,eAAe,GACpB,KAAK,QAAU,KAAK,aAEpB,AAAI,KAAK,QAAQ,SAAU,KAAK,OAC3B,KAAK,QASP,eACH,MAAO,MAAK,cAAc,UASvB,aACH,MAAO,MAAK,QAIT,SACH,MAAO,MAAK,kBAKG,GAA6B,KACzC,GAAI,GAAQ", + "sources": ["../src/api.ts", "../src/config.ts", "../../manager/src/api.ts", "../src/manager.ts", "../src/url.ts", "../src/history.ts", "../src/page.ts", "../../emitter/src/api.ts", "../src/service.ts", "../src/pjax.ts", "../src/transition.ts", "../src/app.ts", "../src/route.ts", "../../animate/src/api.ts"], + "sourcesContent": ["export * from \"./config\";\r\nexport * from \"./manager\";\r\nexport * from \"./url\";\r\n\r\nexport * from \"./history\";\r\nexport * from \"./page\";\r\n\r\nexport * from \"./emitter\";\r\nexport * from \"./service\";\r\n\r\nexport * from \"./transition\";\r\n\r\nexport * from \"./app\";\r\nexport * from \"./pjax\";\r\nexport * from \"./route\";\r\n\r\nexport * from \"@okikio/animate\";\r\n", "// The config variables\r\nexport interface ICONFIG {\r\n prefix?: string;\r\n wrapperAttr?: string;\r\n noAjaxLinkAttr?: string;\r\n noPrefetchAttr?: \"no-prefetch\";\r\n headers?: string[][];\r\n preventSelfAttr?: string;\r\n preventAllAttr?: string;\r\n transitionAttr?: string;\r\n blockAttr?: string;\r\n timeout?: number\r\n}\r\n\r\nexport const CONFIG_DEFAULTS: ICONFIG = {\r\n wrapperAttr: \"wrapper\",\r\n noAjaxLinkAttr: \"no-ajax-link\",\r\n noPrefetchAttr: \"no-prefetch\",\r\n headers: [\r\n [\"x-partial\", \"true\"]\r\n ],\r\n preventSelfAttr: `prevent=\"self\"`,\r\n preventAllAttr: `prevent=\"all\"`,\r\n transitionAttr: \"transition\",\r\n blockAttr: `block`,\r\n timeout: 30000\r\n};\r\n\r\nexport type ConfigKeys = keyof ICONFIG;\r\n\r\n/**\r\n * The Config class\r\n *\r\n * @export\r\n * @class CONFIG\r\n */\r\nexport class CONFIG {\r\n /**\r\n * The current Configuration\r\n *\r\n * @public\r\n * @type ICONFIG\r\n * @memberof CONFIG\r\n */\r\n public config: ICONFIG;\r\n\r\n /**\r\n * Creates an instance of CONFIG.\r\n *\r\n * @param {ICONFIG} config\r\n * @memberof CONFIG\r\n */\r\n constructor(config: ICONFIG) {\r\n this.config = Object.assign({ ...CONFIG_DEFAULTS }, config);\r\n }\r\n\r\n /**\r\n * Converts string into data attributes\r\n *\r\n * @param {string} value\r\n * @param {boolean} brackets [brackets=true]\r\n * @returns string\r\n * @memberof CONFIG\r\n */\r\n public toAttr(value: string, brackets: boolean = true): string {\r\n let { prefix } = this.config;\r\n let attr = `data${prefix ? \"-\" + prefix : \"\"}-${value}`;\r\n return brackets ? `[${attr}]` : attr;\r\n }\r\n\r\n /**\r\n * Selects config vars, and formats them for use, or simply returns the current configurations for the framework\r\n *\r\n * @param {ConfigKeys} value\r\n * @param {boolean} [brackets=true]\r\n * @returns any\r\n * @memberof CONFIG\r\n */\r\n public getConfig(value?: ConfigKeys, brackets: boolean = true): any {\r\n if (typeof value !== \"string\")\r\n return this.config;\r\n\r\n let config = this.config[value];\r\n if (typeof config === \"string\")\r\n return this.toAttr(config, brackets);\r\n return config;\r\n }\r\n}\r\n", "/**\r\n * Manages complex lists of named data, eg. A page can be stored in a list by of other pages with the url being how the page is stored in the list. Managers use Maps to store data.\r\n *\r\n * @export\r\n * @class Manager\r\n * @template K\r\n * @template V\r\n */\r\nexport class Manager {\r\n\t/**\r\n\t * The complex list of named data, to which the Manager controls\r\n\t *\r\n\t * @public\r\n\t * @type Map\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic map: Map;\r\n\r\n\t/**\r\n\t * Creates an instance of Manager.\r\n\t *\r\n\t * @param {Array<[K, V]>} [value]\r\n\t * @memberof Manager\r\n\t */\r\n\tconstructor(value?: Array<[K, V]>) {\r\n\t\tthis.map = new Map(value);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the Manager class's list\r\n\t *\r\n\t * @returns Map\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic getMap(): Map {\r\n\t\treturn this.map;\r\n\t}\r\n\r\n\t/**\r\n\t * Get a value stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key to find in the Manager's list\r\n\t * @returns V\r\n\t */\r\n\tpublic get(key: K): V {\r\n\t\treturn this.map.get(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the keys of all items stored in the Manager as an Array\r\n\t *\r\n\t * @returns Array\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic keys(): Array {\r\n\t\treturn Array.from(this.map.keys());\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the values of all items stored in the Manager as an Array\r\n\t *\r\n\t * @returns Array\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic values(): Array {\r\n\t\treturn Array.from(this.map.values());\r\n\t}\r\n\r\n\t/**\r\n\t * Set a value stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key where the value will be stored\r\n\t * @param {V} value - The value to store\r\n\t * @returns Manager\r\n\t */\r\n\tpublic set(key: K, value: V): Manager {\r\n\t\tthis.map.set(key, value);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Adds a value to Manager, and uses the current size of the Manager as it's key, it works best when all the key in the Manager are numbers\r\n\t *\r\n\t * @public\r\n\t * @param {V} value\r\n\t * @returns Manager\r\n\t */\r\n\tpublic add(value: V): Manager {\r\n\t\tlet size = this.size;\r\n\t\t// @ts-ignore\r\n\t\tlet num: K = size as K;\r\n\t\tthis.set(num, value);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the total number of items stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @returns Number\r\n\t */\r\n\tpublic get size(): number {\r\n\t\treturn this.map.size;\r\n\t}\r\n\r\n\tpublic get length(): number {\r\n\t\treturn this.map.size;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the last item in the Manager who's index is a certain distance from the last item in the Manager\r\n\t *\r\n\t * @param {number} [distance=1]\r\n\t * @returns V | undefined\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic last(distance: number = 1): V | undefined {\r\n\t\tlet key = this.keys()[this.size - distance];\r\n\t\treturn this.get(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Removes a value stored in the Manager, via the key, returns true if an element in the Map object existed and has been removed, or false if the element does not exist.\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key for the key value pair to be removed\r\n\t * @returns boolean\r\n\t */\r\n\tpublic delete(key: K): boolean {\r\n\t\treturn this.map.delete(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Removes a value stored in the Manager, via the key, returns the Manager class, allowing for chains\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key for the key value pair to be removed\r\n\t * @returns Manager\r\n\t */\r\n\tpublic remove(key: K): Manager {\r\n\t\tthis.map.delete(key);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Clear the Manager of all its contents\r\n\t *\r\n\t * @public\r\n\t * @returns Manager\r\n\t */\r\n\tpublic clear(): Manager {\r\n\t\tthis.map.clear();\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Checks if the Manager contains a certain key\r\n\t *\r\n\t * @public\r\n\t * @param {K} key\r\n\t * @returns boolean\r\n\t */\r\n\tpublic has(key: K): boolean {\r\n\t\treturn this.map.has(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a new Iterator object that contains an array of [key, value] for each element in the Map object in insertion order.\r\n\t *\r\n\t * @public\r\n\t * @returns IterableIterator<[K, V]>\r\n\t */\r\n\tpublic entries(): IterableIterator<[K, V]> {\r\n\t\treturn this.map.entries();\r\n\t}\r\n\r\n\t/**\r\n\t * Iterates through the Managers contents, calling a callback function every iteration\r\n\t *\r\n\t * @param {*} [callback=(...args: any): void => { }]\r\n\t * @param {object} context\r\n\t * @returns Manager\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic forEach(\r\n\t\tcallback: any = (...args: any): void => { },\r\n\t\tcontext?: object\r\n\t): Manager {\r\n\t\tthis.map.forEach(callback, context);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Allows iteration via the for..of, learn more: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators]\r\n\t *\r\n\t * @returns IterableIterator<[K, V]>\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic [Symbol.iterator](): IterableIterator<[K, V]> {\r\n\t\treturn this.entries();\r\n\t}\r\n}\r\n\r\n/**\r\n * Calls the method of a certain name for all items that are currently installed\r\n *\r\n * @param {Manager} manager\r\n * @param {string} method\r\n * @param {Array} [args=[]]\r\n */\r\nexport const methodCall = (manager: Manager, method: string, ...args: any): void => {\r\n\tmanager.forEach((item) => {\r\n\t\t// @ts-ignore\r\n\t\titem[method](...args);\r\n\t});\r\n};\r\n\r\n/**\r\n * Asynchronously calls the method of a certain name for all items that are currently installed, similar to methodCall\r\n *\r\n * @param {Manager} manager\r\n * @param {string} method\r\n * @param {Array} [args=[]]\r\n */\r\nexport const asyncMethodCall = async (manager: Manager, method: string, ...args: any): Promise => {\r\n\tfor (let [, item] of manager) {\r\n\t\t// @ts-ignore\r\n\t\tawait item[method](...args);\r\n\t}\r\n};\r\n\r\nexport default Manager;\r\n", "import { Manager, methodCall, asyncMethodCall } from \"@okikio/manager\";\r\nimport { CONFIG } from \"./config\";\r\nimport { App } from \"./app\";\r\nimport EventEmitter from \"@okikio/emitter\";\r\n\r\nexport type IAdvancedManager = AdvancedManager;\r\n\r\n/**\r\n * The base class for all AdvancedManager and AdvancedStorage items\r\n *\r\n * @export\r\n * @class ManagerItem\r\n */\r\nexport class ManagerItem {\r\n /**\r\n * The AdvancedManager the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type IAdvancedManager\r\n * @memberof ManagerItem\r\n */\r\n public manager: IAdvancedManager;\r\n\r\n /**\r\n * The App the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type App\r\n * @memberof ManagerItem\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof ManagerItem\r\n */\r\n public config: CONFIG;\r\n public emitter: EventEmitter;\r\n public key: any;\r\n\r\n /**\r\n * Creates an instance of ManagerItem.\r\n *\r\n * @memberof ManagerItem\r\n */\r\n constructor() { }\r\n\r\n /**\r\n * Run after the Manager Item has been registered\r\n *\r\n * @returns any\r\n * @memberof ManagerItem\r\n */\r\n public install(): any { }\r\n\r\n /**\r\n * Register the current Manager Item's manager\r\n *\r\n * @param {IAdvancedManager} manager\r\n * @returns ManagerItem\r\n * @memberof ManagerItem\r\n */\r\n public register(manager: IAdvancedManager, key: any): ManagerItem {\r\n this.manager = manager;\r\n this.app = manager.app;\r\n this.config = manager.config;\r\n this.emitter = manager.emitter;\r\n this.key = key;\r\n this.install();\r\n return this;\r\n }\r\n\r\n public uninstall(): any { }\r\n\r\n public unregister() {\r\n this.uninstall();\r\n\r\n this.manager.delete(this.key);\r\n this.key = undefined;\r\n this.manager = undefined;\r\n this.app = undefined;\r\n this.config = undefined;\r\n this.emitter = undefined;\r\n }\r\n}\r\n\r\n/**\r\n * A tweak to the Manager class that makes it self aware of the App class it's instantiated in\r\n *\r\n * @export\r\n * @class AdvancedManager\r\n * @extends {Manager}\r\n * @template K\r\n * @template V\r\n */\r\nexport class AdvancedManager extends Manager {\r\n /**\r\n * The instance of the App class, the Manager is instantiated in\r\n *\r\n * @type App\r\n * @memberof AdvancedManager\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof AdvancedManager\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * The EventEmitter class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof AdvancedManager\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * Creates an instance of AdvancedManager.\r\n *\r\n * @param {App} app - The instance of the App class, the Manager is instantiated in\r\n * @memberof AdvancedManager\r\n */\r\n constructor(app: App) {\r\n super();\r\n this.app = app;\r\n this.config = app.config;\r\n this.emitter = app.emitter;\r\n }\r\n\r\n /**\r\n * Set a value stored in the Manager\r\n *\r\n * @public\r\n * @param {K} key - The key where the value will be stored\r\n * @param {V} value - The value to store\r\n * @returns AdvancedManager\r\n */\r\n public set(key: K, value: V) {\r\n super.set(key, value);\r\n value.register(this, key);\r\n return this;\r\n }\r\n}\r\n\r\nexport { Manager, methodCall, asyncMethodCall };\r\n", "/**\r\n * Adds new methods to the native URL Object; it seemed cleaner than using a custom method or editing the prototype.\r\n *\r\n * This doesn't extend the **Class** object because it's meant to be a small extension of the native URL class.\r\n *\r\n * @export\r\n * @class URL\r\n * @extends {URL}\r\n */\r\n// Read up on the native URL class [devdocs.io/dom/url]\r\n/**\r\n * Creates an instance of URL.\r\n *\r\n * @param {(string | URL | Location)} [url=window.location.pathname]\r\n * @return URL\r\n */\r\nexport const newURL = (url: string | URL | Location = window.location.href): URL => {\r\n return url instanceof URL ? url : new URL(url as unknown as string, window.location.origin);\r\n};\r\n\r\n/**\r\n * Returns the pathname with the hash\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const getHashedPath = (url: URL): string => (`${url.pathname}${url.hash}`);\r\n\r\n/**\r\n * Returns the actual hash without the hashtag\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const getHash = (url: URL): string => (url.hash.slice(1));\r\n\r\n/**\r\n * Removes the hash from the full URL for a clean URL string\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const clean = (url: URL): string => (url.toString().replace(/(\\/#.*|\\/|#.*)$/, ''));\r\n\r\n/**\r\n * Compares two URLs to each other\r\n *\r\n * @param {URL} a\r\n * @param {URL} b\r\n * @returns boolean\r\n */\r\nexport const equal = (a: URL | string, b: URL | string): boolean => {\r\n let urlA = newURL(a);\r\n let urlB = newURL(b);\r\n return clean(urlA) === clean(urlB);\r\n};\r\n", "import { getHashedPath, newURL } from \"./url\";\r\n\r\nexport type Trigger = HTMLAnchorElement | \"HistoryManager\" | \"popstate\" | \"back\" | \"forward\";\r\nexport interface ICoords {\r\n\treadonly x: number;\r\n\treadonly y: number;\r\n}\r\n\r\nexport interface IStateData {\r\n\tscroll: ICoords;\r\n\t[key: string]: any;\r\n}\r\n\r\nexport interface IState {\r\n\turl: string;\r\n\tindex?: number;\r\n\ttransition: string;\r\n\tdata: IStateData;\r\n}\r\n\r\nexport interface IHistoryItem {\r\n\tindex: number;\r\n\tstates: IState[];\r\n}\r\n\r\n/**\r\n * A quick snapshot of page coordinates, e.g. scroll positions\r\n *\r\n * @export\r\n * @param {number} [x=window.scrollX]\r\n * @param {number} [y=window.scrollY]\r\n */\r\nexport const newCoords = (x: number = window.scrollX, y: number = window.scrollY): ICoords => ({ x, y });\r\n\r\n/**\r\n * Represents the current status of the page consisting of properties like: url, transition, and data\r\n *\r\n * @export\r\n * @param {IState} {\r\n * url = getHashedPath(newURL()),\r\n * index = 0,\r\n * transition = \"default\",\r\n * data = {\r\n * scroll: newCoords(),\r\n * trigger: \"HistoryManager\"\r\n * }\r\n * }\r\n * @memberof State\r\n*/\r\nexport const newState = (state: IState = {\r\n\turl: getHashedPath(newURL()),\r\n\tindex: 0,\r\n\ttransition: \"default\",\r\n\tdata: {\r\n\t\tscroll: newCoords(),\r\n\t\ttrigger: \"HistoryManager\"\r\n\t}\r\n}): IState => (state);\r\n\r\n\r\n/**\r\n * History of the site, stores only the State class\r\n *\r\n * @export\r\n * @class HistoryManager\r\n * @extends {Manager}\r\n */\r\nexport class HistoryManager {\r\n\tpublic states: IState[];\r\n\tpublic pointer = -1;\r\n\r\n\t/**\r\n\t * Creates an instance of the HistoryManager class, which inherits properties and methods from the Storage class.\r\n\t *\r\n\t * @memberof HistoryManager\r\n\t * @constructor\r\n\t */\r\n\tconstructor() {\r\n\t\tthis.states = [];\r\n\r\n\t\tlet state = newState();\r\n\t\tthis.add(state, \"replace\");\r\n\t}\r\n\r\n\tpublic get(index: number) {\r\n\t\treturn this.states[index];\r\n\t}\r\n\r\n\t/**\r\n\t * Sets the index of the state before adding to HistoryManager\r\n\t *\r\n\t * @param {IState} value\r\n\t * @returns HistoryManager\r\n\t */\r\n\tpublic add(value?: IState, historyAction: \"replace\" | \"push\" = \"push\"): HistoryManager {\r\n\t\tlet state = newState(value);\r\n\t\tlet len = this.length;\r\n\t\tthis.states.push({ ...state });\r\n\t\tthis.pointer = len;\r\n\r\n\t\tlet item: IHistoryItem = {\r\n\t\t\tindex: this.pointer,\r\n\t\t\tstates: [...this.states]\r\n\t\t};\r\n\t\tchangeState(historyAction, state, item);\r\n\t\treturn this;\r\n\t}\r\n\r\n\tpublic remove(index?: number) {\r\n\t\tif (index) {\r\n\t\t\tthis.states.splice(index, 1);\r\n\t\t} else {\r\n\t\t\tthis.states.pop();\r\n\t\t}\r\n\r\n\t\tthis.pointer--;\r\n\t\treturn this;\r\n\t}\r\n\r\n\tpublic replace(newStates: IState[]) {\r\n\t\tthis.states = newStates;\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Set state by index.\r\n\t */\r\n\tpublic set(i: number, state: IState) {\r\n\t\treturn (this.states[i] = state);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the current state.\r\n\t */\r\n\tget current(): IState {\r\n\t\treturn this.get(this.pointer);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the last state (top of the history stack).\r\n\t */\r\n\tget last(): IState {\r\n\t\treturn this.get(this.length - 1);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the previous state.\r\n\t */\r\n\tget previous(): IState | null {\r\n\t\treturn this.pointer < 1 ? null : this.get(this.pointer - 1);\r\n\t}\r\n\r\n\tget length() {\r\n\t\treturn this.states.length;\r\n\t}\r\n\r\n}\r\n\r\n/**\r\n * Either push or replace history state\r\n *\r\n * @param {(\"push\" | \"replace\")} action\r\n * @param {IState} state\r\n * @param {_URL} url\r\n * @memberof PJAX\r\n */\r\nexport const changeState = (action: \"push\" | \"replace\", state: IState, item: object) => {\r\n\tlet href = getHashedPath(newURL(state.url));\r\n\tlet args = [item, \"\", href];\r\n\tif (window.history) {\r\n\t\tswitch (action) {\r\n\t\t\tcase \"push\":\r\n\t\t\t\twindow.history.pushState.apply(window.history, args);\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"replace\":\r\n\t\t\t\twindow.history.replaceState.apply(window.history, args);\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n", "import { Manager, ManagerItem, AdvancedManager } from \"./manager\";\r\nimport { equal, newURL } from \"./url\";\r\nimport { App } from \"./app\";\r\n\r\n/**\r\n * Parses strings to DOM\r\n */\r\nexport const PARSER: DOMParser = new DOMParser();\r\n\r\n/**\r\n * A page represents the DOM elements that create each page\r\n *\r\n * @export\r\n * @class Page\r\n */\r\nexport class Page extends ManagerItem {\r\n /**\r\n * Holds the DOM of the current page\r\n *\r\n * @public\r\n * @type Document\r\n * @memberof Page\r\n */\r\n public dom: Document;\r\n\r\n /**\r\n * Holds the wrapper element to be swapped out of each Page\r\n *\r\n * @public\r\n * @type HTMLElement\r\n * @memberof Page\r\n */\r\n public wrapper: HTMLElement;\r\n\r\n /**\r\n * Holds the title of each page\r\n *\r\n * @public\r\n * @type string\r\n * @memberof Page\r\n */\r\n public title: string;\r\n\r\n /**\r\n * Holds the head element of each page\r\n *\r\n * @public\r\n * @type Element\r\n * @memberof Page\r\n */\r\n public head: Element;\r\n\r\n /**\r\n * Holds the body element of each page\r\n *\r\n * @public\r\n * @type Element\r\n * @memberof Page\r\n */\r\n public body: Element;\r\n\r\n /**\r\n * The URL of the current page\r\n *\r\n * @public\r\n * @type URL\r\n * @memberof Page\r\n */\r\n public url: URL;\r\n public data: string;\r\n public wrapperAttr: string;\r\n\r\n /**\r\n * Creates an instance of Page, it also creates a new page from response text, or a Document Object\r\n *\r\n * @param {URL} [url = newURL()]\r\n * @param {(string | Document)} [dom=document]\r\n * @memberof Page\r\n */\r\n constructor(url: URL = newURL(), dom: string | Document = document) {\r\n super();\r\n this.url = url;\r\n\r\n if (typeof dom === \"string\") {\r\n this.data = dom;\r\n } else this.dom = dom || document;\r\n }\r\n\r\n public async build() {\r\n if (!(this.dom instanceof Node)) {\r\n this.dom = PARSER.parseFromString(this.data, \"text/html\");\r\n }\r\n\r\n if (!(this.body instanceof Node)) {\r\n let { title, head, body } = this.dom;\r\n this.title = title;\r\n this.head = head;\r\n this.body = body;\r\n this.wrapper = this.body.querySelector(this.wrapperAttr);\r\n }\r\n }\r\n\r\n /**\r\n * Runs once the the manager and config have been registered\r\n *\r\n * @returns void\r\n * @memberof Page\r\n */\r\n public install(): void {\r\n this.wrapperAttr = this.config.getConfig(\"wrapperAttr\");\r\n }\r\n\r\n public uninstall() {\r\n this.url = undefined;\r\n this.title = undefined;\r\n this.head = undefined;\r\n this.body = undefined;\r\n this.dom = undefined;\r\n this.wrapper = undefined;\r\n this.data = undefined;\r\n this.wrapperAttr = undefined;\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Controls which page to be load\r\n *\r\n * @export\r\n * @class PageManager\r\n * @extends {AdvancedManager}\r\n */\r\nexport class PageManager extends AdvancedManager {\r\n /**\r\n * Stores all URLs that are currently loading\r\n *\r\n * @public\r\n * @type Manager>\r\n * @memberof PageManager\r\n */\r\n public loading: Manager> = new Manager();\r\n public maxPages = 5;\r\n\r\n /**\r\n * Creates an instance of the PageManager\r\n *\r\n * @param {App} app\r\n * @memberof PageManager\r\n */\r\n constructor(app: App) {\r\n super(app);\r\n let URLString = newURL().pathname;\r\n this.set(URLString, new Page());\r\n URLString = undefined;\r\n }\r\n\r\n /**\r\n * Load from cache or by requesting URL via a fetch request, avoid requesting for the same thing twice by storing the fetch request in \"this.loading\"\r\n *\r\n * @param {(URL | string)} [_url=newURL()]\r\n * @returns Promise\r\n * @memberof PageManager\r\n */\r\n public async load(_url: URL | string = newURL()): Promise {\r\n let url: URL = newURL(_url);\r\n let urlString: string = url.pathname;\r\n let page: Page, request: Promise;\r\n if (this.has(urlString)) {\r\n page = this.get(urlString);\r\n return Promise.resolve(page);\r\n }\r\n\r\n if (!this.loading.has(urlString)) {\r\n request = this.request(urlString);\r\n this.loading.set(urlString, request);\r\n } else request = this.loading.get(urlString);\r\n\r\n let response = await request;\r\n this.loading.delete(urlString);\r\n\r\n page = new Page(url, response);\r\n this.set(urlString, page);\r\n\r\n if (this.size > this.maxPages) {\r\n let currentUrl = newURL();\r\n let keys = this.keys();\r\n let first = equal(currentUrl, keys[0]) ? keys[1] : keys[0];\r\n let page = this.get(first);\r\n page.unregister();\r\n page = undefined;\r\n keys = undefined;\r\n currentUrl = undefined;\r\n first = undefined;\r\n }\r\n return page;\r\n }\r\n\r\n /**\r\n * Starts a fetch request\r\n *\r\n * @param {string} url\r\n * @returns Promise\r\n * @memberof PageManager\r\n */\r\n public async request(url: string): Promise {\r\n const headers = new Headers(this.config.getConfig(\"headers\"));\r\n const timeout = window.setTimeout(() => {\r\n window.clearTimeout(timeout);\r\n throw \"Request Timed Out!\";\r\n }, this.config.getConfig(\"timeout\"));\r\n\r\n try {\r\n let response = await fetch(url, {\r\n mode: 'same-origin',\r\n method: \"GET\",\r\n headers,\r\n cache: \"default\",\r\n credentials: \"same-origin\",\r\n });\r\n\r\n window.clearTimeout(timeout);\r\n if (response.status >= 200 && response.status < 300) {\r\n return await response.text();\r\n }\r\n\r\n const err = new Error(response.statusText || \"\" + response.status);\r\n throw err;\r\n } catch (err) {\r\n window.clearTimeout(timeout);\r\n throw err;\r\n }\r\n }\r\n}\r\n", "import { Manager } from \"@okikio/manager\";\r\n\r\nexport type ListenerCallback = ((...args: any) => void);\r\nexport interface IListener {\r\n readonly callback: ListenerCallback;\r\n readonly scope: object;\r\n readonly name: string;\r\n}\r\n\r\n/**\r\n * Represents a new event listener consisting of properties like: callback, scope, name\r\n *\r\n * @export\r\n */\r\nexport const newListener = ({\r\n callback = () => { },\r\n scope = null,\r\n name = \"event\",\r\n}: IListener): IListener => ({ callback, scope, name });\r\n\r\n/**\r\n * Represents a new event listener consisting of properties like: callback, scope, name\r\n *\r\n * @export\r\n * @class Event\r\n * @extends {Manager}\r\n */\r\nexport class Event extends Manager {\r\n /**\r\n * The name of the event\r\n *\r\n * @public\r\n * @type string\r\n * @memberof Event\r\n */\r\n public name: string;\r\n\r\n /**\r\n * Creates an instance of Event.\r\n *\r\n * @param {string} [name=\"event\"]\r\n * @memberof Event\r\n */\r\n constructor(name: string = \"event\") {\r\n super();\r\n this.name = name;\r\n }\r\n}\r\n\r\nexport type EventInput = string | object | Array;\r\n\r\n/**\r\n * An event emitter\r\n *\r\n * @export\r\n * @class EventEmitter\r\n * @extends {Manager}\r\n */\r\nexport class EventEmitter extends Manager {\r\n /**\r\n * Creates an instance of EventEmitter.\r\n *\r\n * @memberof EventEmitter\r\n */\r\n constructor() {\r\n super();\r\n }\r\n\r\n /**\r\n * Gets events, if event doesn't exist create a new Event\r\n *\r\n * @param {string} name\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public getEvent(name: string): Event {\r\n let event = this.get(name);\r\n if (!(event instanceof Event)) {\r\n this.set(name, new Event(name));\r\n return this.get(name);\r\n }\r\n\r\n return event;\r\n }\r\n /**\r\n * Creates a new listener and adds it to the event\r\n *\r\n * @param {string} name\r\n * @param {ListenerCallback} callback\r\n * @param {object} scope\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public newListener(\r\n name: string,\r\n callback: ListenerCallback,\r\n scope: object\r\n ): Event {\r\n let event = this.getEvent(name);\r\n event.add(newListener({ name, callback, scope }));\r\n return event;\r\n }\r\n\r\n /**\r\n * Adds a listener for a given event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback | object} callback\r\n * @param {object} scope\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public on(\r\n events: EventInput,\r\n callback?: ListenerCallback | object,\r\n scope?: object\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n let _name: string;\r\n let _callback: ListenerCallback;\r\n let isObject = typeof events == \"object\" && !Array.isArray(events);\r\n\r\n let _scope: object = isObject ? callback : scope;\r\n if (!isObject) _callback = (callback as ListenerCallback);\r\n\r\n // Loop through the list of events\r\n Object.keys(events).forEach(key => {\r\n // Select the name of the event from the list\r\n // Remember events can be {String | Object | Array}\r\n\r\n // Check If events is an Object (JSON like Object, and not an Array)\r\n if (isObject) {\r\n _name = key;\r\n _callback = events[key];\r\n } else {\r\n _name = events[key];\r\n }\r\n\r\n this.newListener(_name, _callback, _scope);\r\n }, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes a listener from an event\r\n *\r\n * @param {string} name\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public removeListener(\r\n name: string,\r\n callback: ListenerCallback,\r\n scope: object\r\n ): Event {\r\n let event: Event = this.get(name);\r\n if (event instanceof Event && callback) {\r\n let listener = newListener({ name, callback, scope });\r\n\r\n event.forEach((value: IListener, i: number) => {\r\n if (\r\n value.callback === listener.callback &&\r\n value.scope === listener.scope\r\n ) {\r\n return event.delete(i);\r\n }\r\n });\r\n }\r\n\r\n return event;\r\n }\r\n\r\n /**\r\n * Removes a listener from a given event, or it just completely removes an event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback | object} [callback]\r\n * @param {object} [scope]\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public off(\r\n events: EventInput,\r\n callback?: ListenerCallback | object,\r\n scope?: object\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n let _name: string;\r\n let _callback: ListenerCallback;\r\n let isObject = typeof events == \"object\" && !Array.isArray(events);\r\n\r\n let _scope: object = isObject ? callback : scope;\r\n if (!isObject) _callback = (callback as ListenerCallback);\r\n\r\n // Loop through the list of events\r\n Object.keys(events).forEach(key => {\r\n // Select the name of the event from the list\r\n // Remember events can be {String | Object | Array}\r\n\r\n // Check If events is an Object (JSON like Object, and not an Array)\r\n if (isObject) {\r\n _name = key;\r\n _callback = events[key];\r\n } else {\r\n _name = events[key];\r\n }\r\n\r\n if (typeof _callback === \"function\") {\r\n this.removeListener(_name, _callback, _scope);\r\n } else this.delete(_name);\r\n }, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Call all listeners within an event\r\n *\r\n * @param {(string | Array)} events\r\n * @param {...any} args\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public emit(\r\n events: string | Array,\r\n ...args: any\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n // Loop through the list of events\r\n events.forEach((event: string) => {\r\n let _event: Event = this.get(event);\r\n\r\n if (_event instanceof Event) {\r\n _event.forEach((listener: IListener) => {\r\n let { callback, scope } = listener;\r\n callback.apply(scope, args);\r\n });\r\n }\r\n }, this);\r\n return this;\r\n }\r\n}\r\n\r\nexport default EventEmitter;\r\n", "import { AdvancedManager, ManagerItem, methodCall } from \"./manager\";\r\nimport { TransitionManager } from \"./transition\";\r\nimport { HistoryManager } from \"./history\";\r\nimport { EventEmitter } from \"./emitter\";\r\nimport { PageManager } from \"./page\";\r\nimport { App } from \"./app\";\r\n\r\n/**\r\n * Controls specific kinds of actions that require JS\r\n *\r\n * @export\r\n * @class Service\r\n */\r\nexport class Service extends ManagerItem {\r\n\t/**\r\n\t * Stores access to the App class's EventEmitter\r\n\t *\r\n\t * @public\r\n\t * @type EventEmitter\r\n\t * @memberof Service\r\n\t */\r\n\tpublic emitter: EventEmitter;\r\n\r\n\t/**\r\n\t * Stores access to the App class's PageManager\r\n\t *\r\n\t * @public\r\n\t * @type PageManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic PageManager: PageManager;\r\n\r\n\t/**\r\n\t * Stores access to the App class's HistoryManager\r\n\t *\r\n\t * @public\r\n\t * @type HistoryManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic HistoryManager: HistoryManager;\r\n\r\n\t/**\r\n\t * Stores the ServiceManager the service is install on\r\n\t *\r\n\t * @public\r\n\t * @type ServiceManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic ServiceManager: ServiceManager;\r\n\r\n\t/**\r\n\t * Stores access to the App's TransitionManager\r\n\t *\r\n\t * @public\r\n\t * @type TransitionManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic TransitionManager: TransitionManager;\r\n\r\n\t/**\r\n\t * Method is run once when Service is installed on a ServiceManager\r\n\t *\r\n\t * @memberof Service\r\n\t */\r\n\tpublic install(): void {\r\n\t\tlet { app } = this.manager;\r\n\t\tthis.PageManager = app.pages;\r\n\t\tthis.HistoryManager = app.history;\r\n\t\tthis.ServiceManager = app.services;\r\n\t\tthis.TransitionManager = app.transitions;\r\n\t}\r\n\r\n\t// Called before the start of a Service, represents a constructor of sorts\r\n\tpublic init(...args: any): void { }\r\n\r\n\t// Called on start of Service\r\n\tpublic boot(): void {\r\n\t\tthis.initEvents();\r\n\t}\r\n\r\n\t// Initialize events\r\n\tpublic initEvents(): void { }\r\n\r\n\t// Stop events\r\n\tpublic stopEvents(): void { }\r\n\r\n\tpublic uninstall() {\r\n\t\tthis.PageManager = undefined;\r\n\t\tthis.HistoryManager = undefined;\r\n\t\tthis.ServiceManager = undefined;\r\n\t\tthis.TransitionManager = undefined;\r\n\t}\r\n\r\n\t// Stop services\r\n\tpublic stop(): void {\r\n\t\tthis.stopEvents();\r\n\t\tthis.unregister();\r\n\t}\r\n}\r\n\r\n/**\r\n * The Service Manager controls the lifecycle of all services in an App\r\n *\r\n * @export\r\n * @class ServiceManager\r\n * @extends {AdvancedManager}\r\n */\r\nexport class ServiceManager extends AdvancedManager {\r\n\t/**\r\n\t * Creates an instance of ServiceManager.\r\n\t *\r\n\t * @param {App} app\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tconstructor(app: App) {\r\n\t\tsuper(app);\r\n\t}\r\n\r\n\t/**\r\n\t * Call the init method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic init(): ServiceManager {\r\n\t\tmethodCall(this, \"init\", this.app);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Call the boot method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic boot(): ServiceManager {\r\n\t\tmethodCall(this, \"boot\", this.app);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Call the stop method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic stop(): ServiceManager {\r\n\t\tmethodCall(this, \"stop\", this.app);\r\n\t\treturn this;\r\n\t}\r\n}\r\n", "import { newState, Trigger, IState, newCoords, IHistoryItem, changeState } from \"./history\";\r\nimport { Service } from \"./service\";\r\nimport { Page } from \"./page\";\r\nimport { newURL, getHashedPath, equal } from \"./url\";\r\n\r\nexport type LinkEvent = MouseEvent | TouchEvent;\r\nexport type StateEvent = LinkEvent | PopStateEvent;\r\nexport type IgnoreURLsList = Array;\r\n\r\n/**\r\n * Creates a Barba JS like PJAX Service, for the Framework\r\n *\r\n * @export\r\n * @class PJAX\r\n * @extends {Service}\r\n */\r\n// Based on Barba JS and StartingBlocks\r\nexport class PJAX extends Service {\r\n /**\r\n * URLs to ignore when prefetching\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected ignoreURLs: IgnoreURLsList = [];\r\n\r\n /**\r\n * Whether or not to disable prefetching\r\n *\r\n * @private\r\n *\r\n * @memberof PJAX\r\n */\r\n protected prefetchIgnore: boolean = false;\r\n\r\n /**\r\n * Current state or transitions\r\n *\r\n * @public\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n public isTransitioning: boolean = false;\r\n\r\n /**\r\n * Ignore extra clicks of an anchor element if a transition has already started\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected stopOnTransitioning: boolean = false;\r\n\r\n /**\r\n * On page change (excluding popstate event) keep current scroll position\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected stickyScroll: boolean = false;\r\n\r\n /**\r\n * Force load a page if an error occurs\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected forceOnError: boolean = false;\r\n\r\n /**\r\n * Dictates whether to auto scroll if an hash is present in the window URL\r\n *\r\n * @protected\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected autoScrollOnHash: boolean = true;\r\n\r\n /**\r\n * Disables all extra scroll effects of PJAX\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected dontScroll: boolean = false;\r\n\r\n /**\r\n * Sets the transition state, sets isTransitioning to true\r\n *\r\n * @private\r\n * @memberof PJAX\r\n */\r\n private transitionStart() {\r\n this.isTransitioning = true;\r\n }\r\n\r\n /**\r\n * Sets the transition state, sets isTransitioning to false\r\n *\r\n * @private\r\n * @memberof PJAX\r\n */\r\n private transitionStop() {\r\n this.isTransitioning = false;\r\n }\r\n\r\n public init() {\r\n super.init();\r\n\r\n /**\r\n * Bind the event listeners to the PJAX class\r\n *\r\n * @memberof PJAX\r\n */\r\n this.onHover = this.onHover.bind(this);\r\n this.onClick = this.onClick.bind(this);\r\n this.onStateChange = this.onStateChange.bind(this);\r\n }\r\n\r\n /**\r\n * Starts the PJAX Service\r\n *\r\n * @memberof PJAX\r\n */\r\n public boot() {\r\n if (\"scrollRestoration\" in window.history) {\r\n // Back off, browser, I got this...\r\n window.history.scrollRestoration = \"manual\";\r\n }\r\n\r\n super.boot();\r\n }\r\n\r\n /**\r\n * Gets the transition to use for a certain anchor\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @returns {(string | null)}\r\n * @memberof PJAX\r\n */\r\n public getTransitionName(el: HTMLAnchorElement): string | null {\r\n if (!el || !el.getAttribute) return null;\r\n let transitionAttr = el.getAttribute(\r\n this.config.getConfig(\"transitionAttr\", false)\r\n );\r\n if (typeof transitionAttr === \"string\") return transitionAttr;\r\n return null;\r\n }\r\n\r\n /**\r\n * Checks to see if the anchor is valid\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @param {(LinkEvent | KeyboardEvent)} event\r\n * @param {string} href\r\n *\r\n * @memberof PJAX\r\n */\r\n public validLink(\r\n el: HTMLAnchorElement,\r\n event: LinkEvent | KeyboardEvent,\r\n href: string\r\n ): boolean {\r\n let pushStateSupport = !window.history.pushState;\r\n let exists = !el || !href;\r\n let eventMutate =\r\n (event as KeyboardEvent).metaKey ||\r\n (event as KeyboardEvent).ctrlKey ||\r\n (event as KeyboardEvent).shiftKey ||\r\n (event as KeyboardEvent).altKey;\r\n let newTab =\r\n el.hasAttribute(\"target\") &&\r\n (el as HTMLAnchorElement).target === \"_blank\";\r\n let crossOrigin =\r\n (el as HTMLAnchorElement).protocol !== location.protocol ||\r\n (el as HTMLAnchorElement).hostname !== location.hostname;\r\n let download = typeof el.getAttribute(\"download\") === \"string\";\r\n let preventSelf = el.hasAttribute(this.config.getConfig(\"preventSelfAttr\", false));\r\n let preventAll = Boolean(\r\n el.closest(this.config.getConfig(\"preventAllAttr\"))\r\n );\r\n let prevent = preventSelf && preventAll;\r\n let sameURL = getHashedPath(newURL()) === getHashedPath(newURL(href));\r\n return !(\r\n exists ||\r\n pushStateSupport ||\r\n eventMutate ||\r\n newTab ||\r\n crossOrigin ||\r\n download ||\r\n prevent ||\r\n sameURL\r\n );\r\n }\r\n\r\n /**\r\n * Returns the href or an Anchor element\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @returns {(string | null)}\r\n * @memberof PJAX\r\n */\r\n public getHref(el: HTMLAnchorElement): string | null {\r\n if (\r\n el &&\r\n el.tagName &&\r\n el.tagName.toLowerCase() === \"a\" &&\r\n typeof el.href === \"string\"\r\n )\r\n return el.href;\r\n return null;\r\n }\r\n\r\n /**\r\n * Check if event target is a valid anchor with an href, if so, return the link\r\n *\r\n * @param {LinkEvent} event\r\n *\r\n * @memberof PJAX\r\n */\r\n public getLink(event: LinkEvent): HTMLAnchorElement {\r\n let el = event.target as HTMLAnchorElement;\r\n let href: string = this.getHref(el);\r\n\r\n while (el && !href) {\r\n el = (el as HTMLElement).parentNode as HTMLAnchorElement;\r\n href = this.getHref(el);\r\n }\r\n\r\n // Check for a valid link\r\n if (!el || !this.validLink(el, event, href)) return;\r\n return el;\r\n }\r\n\r\n /**\r\n * When an element is clicked.\r\n *\r\n * Get valid anchor element.\r\n * Go for a transition.\r\n *\r\n * @param {LinkEvent} event\r\n * @returns\r\n * @memberof PJAX\r\n */\r\n public onClick(event: LinkEvent) {\r\n let el = this.getLink(event);\r\n if (!el) return;\r\n\r\n if (this.isTransitioning && this.stopOnTransitioning) {\r\n event.preventDefault();\r\n event.stopPropagation();\r\n return;\r\n }\r\n\r\n let href = this.getHref(el);\r\n this.emitter.emit(\"ANCHOR_CLICK CLICK\", event);\r\n this.go({ href, trigger: el, event });\r\n }\r\n\r\n /**\r\n * Returns the direction of the State change as a String, either the Back button or the Forward button\r\n *\r\n * @param {number} value\r\n *\r\n * @memberof PJAX\r\n */\r\n public getDirection(value: number): Trigger {\r\n if (Math.abs(value) > 1) {\r\n // Ex 6-0 > 0 -> forward, 0-6 < 0 -> back\r\n return value > 0 ? \"forward\" : \"back\";\r\n } else {\r\n if (value === 0) {\r\n return \"popstate\";\r\n } else {\r\n // Ex 6-5 > 0 -> back, 5-6 < 0 -> forward\r\n return value > 0 ? \"back\" : \"forward\";\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Force a page to go to a certain URL\r\n *\r\n * @param {string} href\r\n * @memberof PJAX\r\n */\r\n public force(href: string): void {\r\n window.location.assign(href);\r\n }\r\n\r\n /**\r\n * If transition is running force load page.\r\n * Stop if currentURL is the same as new url.\r\n * On state change, change the current state history,\r\n * to reflect the direction of said state change\r\n * Load page and page transition.\r\n *\r\n * @param {string} href\r\n * @param {Trigger} [trigger='HistoryManager']\r\n * @param {StateEvent} [event]\r\n * @memberof PJAX\r\n */\r\n public go({\r\n href,\r\n trigger = \"HistoryManager\",\r\n event,\r\n }: {\r\n href: string;\r\n trigger?: Trigger;\r\n event?: StateEvent;\r\n }): Promise {\r\n // If transition is already running and the go method is called again, force load page\r\n if (this.isTransitioning && this.stopOnTransitioning) {\r\n this.force(href);\r\n return;\r\n }\r\n\r\n let scroll = { x: 0, y: 0 };\r\n let currentState = this.HistoryManager.current;\r\n let currentURL = currentState.url;\r\n if (equal(currentURL, href)) {\r\n return;\r\n }\r\n\r\n let transitionName: string;\r\n if (event && (event as PopStateEvent).state) {\r\n this.emitter.emit(\"POPSTATE\", event);\r\n\r\n // If popstate, get back/forward direction.\r\n let { state }: { state: IHistoryItem } = event as PopStateEvent;\r\n let { index } = state;\r\n let currentIndex = currentState.index;\r\n let difference = currentIndex - index;\r\n\r\n trigger = this.getDirection(difference);\r\n\r\n let _state = this.HistoryManager.get(this.HistoryManager.pointer);\r\n transitionName = _state.transition;\r\n scroll = _state.data.scroll;\r\n\r\n // Based on the direction of the state change either remove or add a state\r\n this.HistoryManager.replace(state.states);\r\n this.HistoryManager.pointer = index;\r\n if (trigger === \"back\") {\r\n // this.HistoryManager.remove(currentIndex);\r\n this.emitter.emit(`POPSTATE_BACK`, event);\r\n } else if (trigger === \"forward\") {\r\n // this.HistoryManager.add({ url: href, transition, data });\r\n this.emitter.emit(`POPSTATE_FORWARD`, event);\r\n }\r\n\r\n } else {\r\n // Add new state\r\n transitionName = this.getTransitionName(trigger as HTMLAnchorElement) ||\r\n \"default\";\r\n\r\n scroll = newCoords();\r\n\r\n let state = newState({\r\n url: href,\r\n transition: transitionName,\r\n data: { scroll },\r\n });\r\n\r\n this.HistoryManager.add(state);\r\n this.emitter.emit(\"HISTORY_NEW_ITEM\", event);\r\n }\r\n\r\n if (event) {\r\n event.stopPropagation();\r\n event.preventDefault();\r\n }\r\n\r\n this.emitter.emit(\"GO\", event);\r\n return this.load({\r\n oldHref: currentURL,\r\n href,\r\n trigger,\r\n transitionName,\r\n scroll,\r\n });\r\n }\r\n\r\n /**\r\n * Load the new Page as well as a Transition; run the Transition\r\n *\r\n * @param {string} oldHref\r\n * @param {string} href\r\n * @param {Trigger} trigger\r\n * @param {string} [transitionName=\"default\"]\r\n *\r\n * @memberof PJAX\r\n */\r\n public async load({\r\n oldHref,\r\n href,\r\n trigger,\r\n transitionName = \"default\",\r\n scroll = { x: 0, y: 0 },\r\n }: {\r\n oldHref: string;\r\n href: string;\r\n trigger: Trigger;\r\n transitionName?: string;\r\n scroll: { x: number; y: number };\r\n }): Promise {\r\n try {\r\n let oldPage = await this.PageManager.load(oldHref);\r\n await oldPage.build();\r\n let newPage: Page;\r\n\r\n this.emitter.emit(\"PAGE_LOADING\", { href, oldPage, trigger });\r\n try {\r\n try {\r\n newPage = await this.PageManager.load(href);\r\n await newPage.build();\r\n this.transitionStart();\r\n this.emitter.emit(\"PAGE_LOAD_COMPLETE\", {\r\n newPage,\r\n oldPage,\r\n trigger,\r\n });\r\n } catch (err) {\r\n console.error(`[PJAX] page load error: ${err}`);\r\n }\r\n\r\n // --\r\n // --\r\n\r\n this.emitter.emit(\"NAVIGATION_START\", {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n transitionName,\r\n });\r\n\r\n try {\r\n this.emitter.emit(\"TRANSITION_START\", transitionName);\r\n\r\n let transition = await this.TransitionManager.boot(transitionName, {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n scroll,\r\n });\r\n\r\n if (!transition.scrollable) {\r\n if (!/back|popstate|forward/.test(trigger as string)) {\r\n scroll = hashAction();\r\n }\r\n\r\n window.scroll(scroll.x, scroll.y);\r\n }\r\n\r\n this.emitter.emit(\"TRANSITION_END\", { transition });\r\n\r\n } catch (err) {\r\n console.error(`[PJAX] transition error: ${err}`);\r\n }\r\n\r\n this.emitter.emit(\"NAVIGATION_END\", {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n transitionName,\r\n });\r\n } catch (err) {\r\n this.transitionStop();\r\n throw err;\r\n }\r\n\r\n this.transitionStop(); // Sets isTransitioning to false\r\n } catch (err) {\r\n if (this.forceOnError) this.force(href);\r\n else console.error(err);\r\n }\r\n }\r\n\r\n /**\r\n * Check to see if the URL is to be ignored, uses either RegExp of Strings to check\r\n *\r\n * @param {URL} { pathname }\r\n *\r\n * @memberof PJAX\r\n */\r\n public ignoredURL({ pathname }: URL): boolean {\r\n return (\r\n this.ignoreURLs.length &&\r\n this.ignoreURLs.some((url) => {\r\n return typeof url === \"string\"\r\n ? url === pathname\r\n : (url as RegExp).exec(pathname) !== null;\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * When you hover over an anchor, prefetch the event target's href\r\n *\r\n * @param {LinkEvent} event\r\n * @memberof PJAX\r\n */\r\n public onHover(event: LinkEvent): Promise {\r\n let el = this.getLink(event);\r\n if (!el) return;\r\n\r\n let url = newURL(this.getHref(el));\r\n let urlString: string = url.pathname;\r\n // If Url is ignored or already in cache, don't do any think\r\n if (this.ignoredURL(url) || this.PageManager.has(urlString)) return;\r\n this.emitter.emit(\"ANCHOR_HOVER HOVER\", event);\r\n\r\n try {\r\n this.PageManager.load(url);\r\n } catch (err) {\r\n console.warn(\"[PJAX] prefetch error,\", err);\r\n }\r\n }\r\n\r\n /**\r\n * When History state changes.\r\n *\r\n * Get url from State\r\n * Go for a Barba transition.\r\n *\r\n * @param {PopStateEvent} event\r\n * @memberof PJAX\r\n */\r\n public onStateChange(event: PopStateEvent): void {\r\n this.go({ href: window.location.href, trigger: \"popstate\", event });\r\n }\r\n\r\n /**\r\n * Initialize DOM Events\r\n *\r\n * @memberof PJAX\r\n */\r\n public initEvents() {\r\n if (this.prefetchIgnore !== true) {\r\n document.addEventListener(\"mouseover\", this.onHover);\r\n document.addEventListener(\"touchstart\", this.onHover);\r\n }\r\n\r\n document.addEventListener(\"click\", this.onClick);\r\n window.addEventListener(\"popstate\", this.onStateChange);\r\n }\r\n\r\n /**\r\n * Stop DOM Events\r\n *\r\n * @memberof PJAX\r\n */\r\n public stopEvents() {\r\n if (this.prefetchIgnore !== true) {\r\n document.removeEventListener(\"mouseover\", this.onHover);\r\n document.removeEventListener(\"touchstart\", this.onHover);\r\n }\r\n\r\n document.removeEventListener(\"click\", this.onClick);\r\n window.removeEventListener(\"popstate\", this.onStateChange);\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Auto scrolls to an elements position if the element has an hash\r\n *\r\n * @param {string} [hash=window.location.hash]\r\n * @memberof PJAX\r\n */\r\nexport const hashAction = (hash: string = window.location.hash) => {\r\n try {\r\n\r\n let _hash = hash[0] == \"#\" ? hash : newURL(hash).hash;\r\n if (_hash.length > 1) {\r\n let el = document.getElementById(_hash.slice(1)) as HTMLElement;\r\n\r\n if (el) {\r\n return newCoords(el.offsetLeft, el.offsetTop);\r\n }\r\n }\r\n } catch (e) {\r\n console.warn(\"hashAction error\", e);\r\n }\r\n\r\n return newCoords(0, 0);\r\n};\r\n", "import { Manager } from \"./manager\";\r\nimport { EventEmitter } from \"./emitter\";\r\nimport { ICoords, Trigger } from \"./history\";\r\nimport { Page } from \"./page\";\r\nimport { App } from \"./app\";\r\nimport { CONFIG } from \"./config\";\r\nimport { hashAction } from \"./pjax\";\r\n\r\n/**\r\n * The async function type, allows for smooth transition between Promises\r\n */\r\nexport type asyncFn = (err?: any, value?: any) => void;\r\nexport interface ITransition {\r\n oldPage?: Page;\r\n newPage?: Page;\r\n trigger?: Trigger;\r\n scroll?: { x: number; y: number };\r\n scrollable?: boolean;\r\n in: (data: ITransitionData) => any;\r\n out: (data: ITransitionData) => any;\r\n [key: string]: any;\r\n}\r\nexport interface ITransitionData {\r\n from?: Page;\r\n to?: Page;\r\n trigger?: Trigger;\r\n scroll?: ICoords;\r\n done: asyncFn;\r\n}\r\n\r\n/**\r\n * Controls which animation between pages to use\r\n *\r\n * @export\r\n * @class TransitionManager\r\n * @extends {Manager}\r\n */\r\nexport class TransitionManager extends Manager {\r\n /**\r\n * The instance of the App class, the Manager is instantiated in\r\n *\r\n * @type App\r\n * @memberof AdvancedManager\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof AdvancedManager\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * The EventEmitter class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof AdvancedManager\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * Creates an instance of the TransitionManager\r\n *\r\n * @param {App} app\r\n * @memberof TransitionManager\r\n */\r\n constructor(app: App) {\r\n super();\r\n this.app = app;\r\n this.config = app.config;\r\n this.emitter = app.emitter;\r\n }\r\n\r\n /**\r\n * Runs a transition\r\n *\r\n * @param {{ name: string, oldPage: Page, newPage: Page, trigger: Trigger }} data\r\n * @returns Promise\r\n * @memberof TransitionManager\r\n */\r\n public async boot(name: string, data: any): Promise {\r\n let transition: ITransition = this.get(name);\r\n let scroll = data.scroll;\r\n if (!(data.oldPage instanceof Page) || !(data.newPage instanceof Page))\r\n throw `[Page] either oldPage or newPage aren't instances of the Page Class.\\n ${{\r\n newPage: data.newPage,\r\n oldPage: data.oldPage,\r\n }}`;\r\n\r\n let fromWrapper = data.oldPage.wrapper;\r\n let toWrapper = data.newPage.wrapper;\r\n document.title = `` + data.newPage.title;\r\n\r\n if (!(fromWrapper instanceof Node) || !(toWrapper instanceof Node))\r\n throw `[Wrapper] the wrapper from the ${!(toWrapper instanceof Node) ? \"next\" : \"current\"\r\n } page cannot be found. The wrapper must be an element that has the attribute ${this.config.getConfig(\r\n \"wrapperAttr\"\r\n )}.`;\r\n transition.init && transition?.init(data);\r\n\r\n this.emitter.emit(\"BEFORE_TRANSITION_OUT\");\r\n await new Promise((done) => {\r\n let outMethod: Promise = transition.out.call(transition, {\r\n ...data,\r\n from: data.oldPage,\r\n trigger: data.trigger,\r\n done,\r\n });\r\n\r\n if (outMethod.then) outMethod.then(done);\r\n });\r\n\r\n this.emitter.emit(\"AFTER_TRANSITION_OUT\");\r\n await new Promise((done) => {\r\n fromWrapper.insertAdjacentElement(\"beforebegin\", toWrapper);\r\n this.emitter.emit(\"CONTENT_INSERT\");\r\n\r\n if (!/back|popstate|forward/.test(data.trigger as string)) {\r\n scroll = hashAction();\r\n }\r\n done();\r\n });\r\n\r\n await new Promise((done) => {\r\n fromWrapper.remove();\r\n fromWrapper = undefined;\r\n toWrapper = undefined;\r\n this.emitter.emit(\"CONTENT_REPLACED\");\r\n done();\r\n });\r\n\r\n this.emitter.emit(\"BEFORE_TRANSITION_IN\");\r\n\r\n await new Promise((done) => {\r\n let inMethod: Promise = transition.in.call(transition, {\r\n ...data,\r\n from: data.oldPage,\r\n to: data.newPage,\r\n trigger: data.trigger,\r\n scroll,\r\n done,\r\n });\r\n\r\n if (inMethod.then) inMethod.then(done);\r\n });\r\n\r\n this.emitter.emit(\"AFTER_TRANSITION_IN\");\r\n return transition;\r\n }\r\n}\r\n", "import { EventEmitter, ListenerCallback, EventInput } from \"./emitter\";\r\nimport { ITransition, TransitionManager } from \"./transition\";\r\nimport { HistoryManager, IState } from \"./history\";\r\nimport { ServiceManager, Service } from \"./service\";\r\nimport { PageManager } from \"./page\";\r\nimport { CONFIG, ICONFIG } from \"./config\";\r\n\r\n/**\r\n * The App class starts the entire process, it controls all managers and all services\r\n *\r\n * @export\r\n * @class App\r\n */\r\nexport class App {\r\n /**\r\n * A new instance of the HistoryManager\r\n *\r\n * @public\r\n * @type HistoryManager\r\n * @memberof App\r\n */\r\n public history: HistoryManager;\r\n\r\n /**\r\n * A new instance of the TransitionManager\r\n *\r\n * @public\r\n * @type TransitionManager\r\n * @memberof App\r\n */\r\n public transitions: TransitionManager;\r\n\r\n /**\r\n * A new instance of the ServiceManager\r\n *\r\n * @public\r\n * @type ServiceManager\r\n * @memberof App\r\n */\r\n public services: ServiceManager;\r\n\r\n /**\r\n * A new instance of an EventEmitter\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof App\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * A new instance of the PageManager\r\n *\r\n * @public\r\n * @type PageManager\r\n * @memberof App\r\n */\r\n public pages: PageManager;\r\n\r\n /**\r\n * The current Configuration's for the framework\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof App\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * Creates an instance of App.\r\n *\r\n * @param {(ICONFIG | CONFIG)} [config={}]\r\n * @memberof App\r\n */\r\n constructor(config: object = {}) {\r\n this.register(config);\r\n }\r\n\r\n /**\r\n * For registering all managers and the configurations\r\n *\r\n * @param {(ICONFIG | CONFIG)} [config={}]\r\n * @returns App\r\n * @memberof App\r\n */\r\n public register(config: ICONFIG | CONFIG = {}): App {\r\n this.config = config instanceof CONFIG ? config : new CONFIG(config);\r\n this.emitter = new EventEmitter();\r\n this.history = new HistoryManager();\r\n this.pages = new PageManager(this);\r\n this.transitions = new TransitionManager(this);\r\n this.services = new ServiceManager(this);\r\n\r\n let handler = (() => {\r\n document.removeEventListener(\"DOMContentLoaded\", handler);\r\n window.removeEventListener(\"load\", handler);\r\n this.emitter.emit(\"READY ready\");\r\n }).bind(this);\r\n\r\n document.addEventListener(\"DOMContentLoaded\", handler);\r\n window.addEventListener(\"load\", handler);\r\n return this;\r\n }\r\n\r\n /**\r\n * Based on the type, it will return either a Transition, a Service, or a State from their respective Managers\r\n *\r\n * @param {(\"service\" | \"transition\" | \"state\" | string)} type\r\n * @param {any} key\r\n * @returns Service | Transition | State\r\n * @memberof App\r\n */\r\n public get(type: \"service\" | \"transition\" | \"state\" | string, key: any): Service | ITransition | IState {\r\n switch (type.toLowerCase()) {\r\n case \"service\":\r\n return this.services.get(key);\r\n case \"transition\":\r\n return this.transitions.get(key);\r\n case \"state\":\r\n return this.history.get(key);\r\n default:\r\n throw `Error: can't get type '${type}', it is not a recognized type. Did you spell it correctly.`;\r\n }\r\n }\r\n\r\n /**\r\n * Based on the type, it will return load either Page a Transition, a Service, a State, or a Page from their respective Managers\r\n *\r\n * @param {(\"page\" | string)} type\r\n * @param {any} key\r\n * @returns App\r\n * @memberof App\r\n */\r\n public async load(type: \"page\" | string, key: any): Promise {\r\n switch (type.toLowerCase()) {\r\n case \"page\":\r\n return await this.pages.load(key);\r\n default:\r\n return Promise.resolve(this.get(type, key));\r\n }\r\n }\r\n\r\n /**\r\n * Adds a Service to the App's instance of the ServiceManager, with a name\r\n *\r\n * @param {string} key\r\n * @param {Service} service\r\n * @returns App\r\n * @memberof App\r\n */\r\n public setService(key: string, service: Service): App {\r\n this.services.set(key, service);\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a Service to the App's instance of the ServiceManager, with a name\r\n *\r\n * @param {string} key\r\n * @param {ITransition} tranisition\r\n * @returns App\r\n * @memberof App\r\n */\r\n public setTransition(key: string, transition: ITransition): App {\r\n this.transitions.set(key, transition);\r\n return this;\r\n }\r\n\r\n /**\r\n * Based on the type, it will add either a Transition, a Service, or a State to their respective Managers\r\n *\r\n * @param {(\"service\" | \"transition\" | \"state\")} type\r\n * @param {any} value\r\n * @returns App\r\n * @memberof App\r\n */\r\n public add(type: \"service\" | \"transition\" | \"state\", value: any): App {\r\n switch (type.toLowerCase()) {\r\n case \"service\":\r\n this.services.add(value);\r\n break;\r\n case \"transition\":\r\n this.transitions.set(value.name, value);\r\n break;\r\n case \"state\":\r\n this.history.add(value);\r\n break;\r\n default:\r\n throw `Error: can't add type '${type}', it is not a recognized type. Did you spell it correctly.`;\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Start the App and the ServiceManager\r\n *\r\n * @returns App\r\n * @memberof App\r\n */\r\n public boot(): App {\r\n this.services.init();\r\n this.services.boot();\r\n return this;\r\n }\r\n\r\n /**\r\n * Stop the App and the ServiceManager\r\n *\r\n * @returns App\r\n * @memberof App\r\n */\r\n public stop(): App {\r\n this.services.stop();\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter on method\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} callback\r\n * @returns App\r\n * @memberof App\r\n */\r\n public on(events: EventInput, callback?: ListenerCallback): App {\r\n this.emitter.on(events, callback, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter off method\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} callback\r\n * @returns App\r\n * @memberof App\r\n */\r\n public off(events: EventInput, callback?: ListenerCallback): App {\r\n this.emitter.off(events, callback, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter emit method\r\n *\r\n * @param {(string | any[])} events\r\n * @param {...any} args\r\n * @returns App\r\n * @memberof App\r\n */\r\n public emit(events: string | any[], ...args: any): App {\r\n this.emitter.emit(events, ...args);\r\n return this;\r\n }\r\n}\r\n", "import { Service } from \"./service\";\r\nimport { Manager } from \"./manager\";\r\nimport { newURL, getHashedPath } from \"./url\";\r\n\r\nexport type RouteMethod = (...args: any) => any;\r\nexport type RouteStyle = string | RegExp | boolean;\r\nexport interface IRouteToFrom {\r\n to: RouteStyle,\r\n from: RouteStyle\r\n}\r\nexport type RoutePath = IRouteToFrom | RouteStyle;\r\nexport interface IRoute {\r\n path: RoutePath,\r\n method: RouteMethod\r\n}\r\n\r\n/**\r\n * Controls what happens when certain url paths match a set of criteria\r\n *\r\n * @export\r\n * @class Router\r\n * @extends {Service}\r\n */\r\nexport class Router extends Service {\r\n /**\r\n * List of routes inputted\r\n *\r\n * @protected\r\n * @type {Manager}\r\n * @memberof Router\r\n */\r\n protected routes: Manager;\r\n\r\n /**\r\n * Creates an instance of Router.\r\n *\r\n * @param {Array} [routes=[]]\r\n * @memberof Router\r\n */\r\n constructor(routes: IRoute[] = []) {\r\n super();\r\n this.routes = new Manager();\r\n for (let route of routes) {\r\n this.add(route);\r\n }\r\n }\r\n\r\n /**\r\n * Add a new route to watch for\r\n *\r\n * @param {IRoute} { path, method }\r\n * @returns {Router}\r\n * @memberof Router\r\n */\r\n public add({ path, method }: IRoute): Router {\r\n let key = this.parse(path);\r\n this.routes.set(key, method);\r\n return this;\r\n }\r\n\r\n /**\r\n * Convert strings into path match functions\r\n *\r\n * @param {RouteStyle} path\r\n * @returns {RegExp | boolean}\r\n * @memberof Router\r\n */\r\n public parsePath(path: RouteStyle): RegExp | boolean {\r\n if (typeof path === \"string\") return new RegExp(path, \"i\");\r\n else if (path instanceof RegExp || typeof path === \"boolean\")\r\n return path;\r\n throw \"[Router] only regular expressions, strings and booleans are accepted as paths.\";\r\n }\r\n\r\n /**\r\n * Determines if a strings counts has a path\r\n *\r\n * @param {RouteStyle} input\r\n * @returns boolean\r\n * @memberof Router\r\n */\r\n public isPath(input: RouteStyle): boolean {\r\n return (\r\n typeof input === \"string\" ||\r\n input instanceof RegExp ||\r\n typeof input === \"boolean\"\r\n );\r\n }\r\n\r\n /**\r\n * Parse the multiple different formats for paths, into a { from, to } object\r\n *\r\n * @param {RouteStyle} input\r\n * @returns {IRouteToFrom}\r\n * @memberof Router\r\n */\r\n public parse(input: RoutePath): IRouteToFrom {\r\n let route = input as IRouteToFrom;\r\n let toFromPath: IRouteToFrom = {\r\n from: /(.*)/g,\r\n to: /(.*)/g,\r\n };\r\n\r\n if (this.isPath(input as RouteStyle))\r\n toFromPath = {\r\n from: true,\r\n to: input as RouteStyle,\r\n };\r\n else if (this.isPath(route.from) && this.isPath(route.to as RouteStyle))\r\n toFromPath = route;\r\n else\r\n throw \"[Router] path is neither a string, regular expression, or a { from, to } object.\";\r\n\r\n let { from, to } = toFromPath;\r\n return {\r\n from: this.parsePath(from),\r\n to: this.parsePath(to),\r\n };\r\n }\r\n\r\n /**\r\n * Test if route paths are true, if so run their methods\r\n *\r\n * @memberof Router\r\n */\r\n public route() {\r\n let history = this.HistoryManager;\r\n let from: string = getHashedPath(newURL((history.length > 1 ? history.previous : history.current).url));\r\n let to: string = getHashedPath(newURL());\r\n\r\n this.routes.forEach((method: RouteMethod, path: IRouteToFrom) => {\r\n let fromRegExp = path.from as RegExp | boolean;\r\n let toRegExp = path.to as RegExp | boolean;\r\n\r\n if (\r\n typeof fromRegExp === \"boolean\" &&\r\n typeof toRegExp === \"boolean\"\r\n ) {\r\n throw `[Router] path ({ from: ${fromRegExp}, to: ${toRegExp} }) is not valid, remember paths can only be strings, regular expressions, or a boolean; however, both the from and to paths cannot be both booleans.`;\r\n }\r\n\r\n let fromParam: RegExpExecArray | RegExp | boolean = fromRegExp;\r\n let toParam: RegExpExecArray | RegExp | boolean = toRegExp;\r\n\r\n if (fromRegExp instanceof RegExp && fromRegExp.test(from))\r\n fromParam = fromRegExp.exec(from);\r\n if (toRegExp instanceof RegExp && toRegExp.test(to))\r\n toParam = toRegExp.exec(to);\r\n\r\n if (\r\n (Array.isArray(toParam) && Array.isArray(fromParam)) ||\r\n (Array.isArray(toParam) &&\r\n typeof fromParam == \"boolean\" &&\r\n fromParam) ||\r\n (Array.isArray(fromParam) &&\r\n typeof toParam == \"boolean\" &&\r\n toParam)\r\n )\r\n method({ from: fromParam, to: toParam, path: { from, to } });\r\n });\r\n }\r\n\r\n /**\r\n * Add listeners for PJAX Events\r\n *\r\n * @memberof Router\r\n */\r\n public initEvents() {\r\n this.emitter.on(\"READY\", this.route, this);\r\n this.emitter.on(\"CONTENT_REPLACED\", this.route, this);\r\n }\r\n\r\n /**\r\n * Remove listeners for PJAX Events\r\n *\r\n * @memberof Router\r\n */\r\n public stopEvents() {\r\n this.emitter.off(\"READY\", this.route, this);\r\n this.emitter.off(\"CONTENT_REPLACED\", this.route, this);\r\n }\r\n}\r\n", "import { EventEmitter, EventInput, ListenerCallback } from \"@okikio/emitter\";\r\n\r\n// DOM\r\nexport type AnimationTarget = string | Node | NodeList | HTMLCollection | HTMLElement[] | any[];\r\nexport const getElements = (selector: string | Node): Node[] => {\r\n return typeof selector === \"string\" ? Array.from(document.querySelectorAll(selector as string)) : [selector];\r\n};\r\n\r\nexport const getTargets = (targets: AnimationTarget): Node[] => {\r\n if (Array.isArray(targets)) return targets;\r\n if (typeof targets == \"string\" || targets instanceof Node)\r\n return getElements(targets);\r\n if (targets instanceof NodeList || targets instanceof HTMLCollection)\r\n return Array.from(targets);\r\n return [];\r\n};\r\n\r\n// VALUES\r\nexport type closureArgs = [number, number, HTMLElement];\r\nexport type closure = ((index?: number, total?: number, element?: HTMLElement) => any) | any;\r\nexport const computeValue = (value: closure, args: closureArgs) => {\r\n if (typeof value === \"function\") {\r\n return value(...args);\r\n } else { return value; }\r\n};\r\n\r\nexport const mapObject = (obj: object, args: closureArgs): any => {\r\n let key, value, result = {};\r\n let keys = Object.keys(obj);\r\n for (let i = 0, len = keys.length; i < len; i++) {\r\n key = keys[i];\r\n value = obj[key];\r\n result[key] = computeValue(value, args);\r\n }\r\n\r\n return result;\r\n};\r\n\r\n// From: [https://easings.net]\r\nexport const easings = {\r\n \"ease\": \"ease\",\r\n \"in\": \"ease-in\",\r\n \"out\": \"ease-out\",\r\n \"in-out\": \"ease-in-out\",\r\n\r\n // Sine\r\n \"in-sine\": \"cubic-bezier(0.47, 0, 0.745, 0.715)\",\r\n \"out-sine\": \"cubic-bezier(0.39, 0.575, 0.565, 1)\",\r\n \"in-out-sine\": \"cubic-bezier(0.445, 0.05, 0.55, 0.95)\",\r\n\r\n // Quad\r\n \"in-quad\": \"cubic-bezier(0.55, 0.085, 0.68, 0.53)\",\r\n \"out-quad\": \"cubic-bezier(0.25, 0.46, 0.45, 0.94)\",\r\n \"in-out-quad\": \"cubic-bezier(0.455, 0.03, 0.515, 0.955)\",\r\n\r\n // Cubic\r\n \"in-cubic\": \"cubic-bezier(0.55, 0.055, 0.675, 0.19)\",\r\n \"out-cubic\": \"cubic-bezier(0.215, 0.61, 0.355, 1)\",\r\n \"in-out-cubic\": \"cubic-bezier(0.645, 0.045, 0.355, 1)\",\r\n\r\n // Quart\r\n \"in-quart\": \"cubic-bezier(0.895, 0.03, 0.685, 0.22)\",\r\n \"out-quart\": \"cubic-bezier(0.165, 0.84, 0.44, 1)\",\r\n \"in-out-quart\": \"cubic-bezier(0.77, 0, 0.175, 1)\",\r\n\r\n // Quint\r\n \"in-quint\": \"cubic-bezier(0.755, 0.05, 0.855, 0.06)\",\r\n \"out-quint\": \"cubic-bezier(0.23, 1, 0.32, 1)\",\r\n \"in-out-quint\": \"cubic-bezier(0.86, 0, 0.07, 1)\",\r\n\r\n // Expo\r\n \"in-expo\": \"cubic-bezier(0.95, 0.05, 0.795, 0.035)\",\r\n \"out-expo\": \"cubic-bezier(0.19, 1, 0.22, 1)\",\r\n \"in-out-expo\": \"cubic-bezier(1, 0, 0, 1)\",\r\n\r\n // Circ\r\n \"in-circ\": \"cubic-bezier(0.6, 0.04, 0.98, 0.335)\",\r\n \"out-circ\": \"cubic-bezier(0.075, 0.82, 0.165, 1)\",\r\n \"in-out-circ\": \"cubic-bezier(0.785, 0.135, 0.15, 0.86)\",\r\n\r\n // Back\r\n \"in-back\": \"cubic-bezier(0.6, -0.28, 0.735, 0.045)\",\r\n \"out-back\": \"cubic-bezier(0.175, 0.885, 0.32, 1.275)\",\r\n \"in-out-back\": \"cubic-bezier(0.68, -0.55, 0.265, 1.55)\"\r\n};\r\nexport const getEase = (ease: string) => {\r\n return /^(ease|in|out)/.test(ease) ? easings[ease] : ease;\r\n};\r\n\r\nexport interface AnimationOptions {\r\n target?: AnimationTarget,\r\n\r\n speed?: number | closure,\r\n delay?: number | closure,\r\n easing?: string | closure,\r\n endDelay?: number | closure,\r\n duration?: number | closure,\r\n autoplay?: boolean | closure,\r\n keyframes?: object[] | closure,\r\n loop?: number | boolean | closure, // iterations: number,\r\n options?: AnimationOptions | closure,\r\n onfinish?: (element?: HTMLElement, index?: number, total?: number) => any,\r\n fillMode?: \"none\" | \"forwards\" | \"backwards\" | \"both\" | \"auto\" | closure,\r\n direction?: \"normal\" | \"reverse\" | \"alternate\" | \"alternate-reverse\" | closure,\r\n [property: string]: closure | boolean | object | string | string[] | number | null | (number | null)[] | undefined;\r\n};\r\n\r\nexport const DefaultAnimationOptions: AnimationOptions = {\r\n keyframes: [],\r\n\r\n loop: 1, // iterations: number,\r\n delay: 0,\r\n speed: 1,\r\n endDelay: 0,\r\n easing: \"ease\",\r\n autoplay: true,\r\n duration: 1000,\r\n onfinish() { },\r\n fillMode: \"auto\",\r\n direction: \"normal\",\r\n};\r\n\r\n// You can check it out here: https://codepen.io/okikio/pen/qBbdGaW?editors=0011\r\nexport class Animate {\r\n /**\r\n * Stores the options for the current animation\r\n *\r\n * @public\r\n * @type AnimationOptions\r\n * @memberof Animate\r\n */\r\n public options: AnimationOptions = {};\r\n\r\n /**\r\n * The Array of Elements to Animate\r\n *\r\n * @public\r\n * @type {Node[]}\r\n * @memberof Animate\r\n */\r\n public targets: Node[] = [];\r\n\r\n /**\r\n * The properties to animate\r\n *\r\n * @public\r\n * @type {object}\r\n * @memberof Animate\r\n */\r\n public properties: object = {};\r\n\r\n /**\r\n * A Set of Animations\r\n *\r\n * @public\r\n * @type {Map}\r\n * @memberof Animate\r\n */\r\n public animations: Map = new Map();\r\n\r\n /**\r\n * The total duration of all Animation's\r\n *\r\n * @public\r\n * @type {number}\r\n * @memberof Animate\r\n */\r\n public duration: number = 0;\r\n\r\n /**\r\n * The Element the main animation uses\r\n *\r\n * @public\r\n * @type {HTMLElement}\r\n * @memberof Animate\r\n */\r\n public mainElement: HTMLElement;\r\n\r\n /**\r\n * Stores an animation that runs on the total duration of the all other Animations, and as such it's the main Animation\r\n *\r\n * @public\r\n * @type {Animation}\r\n * @memberof Animate\r\n */\r\n public mainAnimation: Animation;\r\n\r\n /**\r\n * Stores request frame calls\r\n *\r\n * @public\r\n * @type {number}\r\n * @memberof Animate\r\n */\r\n public animationFrame: number;\r\n\r\n /**\r\n * An event emitter\r\n *\r\n * @public\r\n * @type {EventEmitter}\r\n * @memberof Animate\r\n */\r\n public emitter: EventEmitter = new EventEmitter();\r\n\r\n /**\r\n * The finish method, is called when the main animation has finished\r\n *\r\n * @public\r\n * @type {*}\r\n * @memberof Animate\r\n */\r\n public finish: any;\r\n\r\n /**\r\n * Returns a promise that is fulfilled when the mainAnimation is finished\r\n *\r\n * @public\r\n * @type {Promise}\r\n * @memberof Animate\r\n */\r\n public promise: Promise;\r\n\r\n /**\r\n * Creates an instance of Animate.\r\n *\r\n * @param {AnimationOptions} options\r\n * @memberof Animate\r\n */\r\n constructor(options: AnimationOptions = {}) {\r\n let { options: animation, ...rest } = options;\r\n this.options = Object.assign({}, DefaultAnimationOptions, animation, rest);\r\n this.loop = this.loop.bind(this);\r\n\r\n let {\r\n loop,\r\n delay,\r\n speed,\r\n easing,\r\n endDelay,\r\n duration,\r\n direction,\r\n fillMode,\r\n onfinish,\r\n target,\r\n keyframes,\r\n autoplay,\r\n ...properties\r\n } = this.options;\r\n\r\n this.mainElement = document.createElement(\"span\");\r\n this.targets = getTargets(target);\r\n this.properties = properties;\r\n\r\n let animationKeyframe: Keyframe[] | PropertyIndexedKeyframes;\r\n for (let i = 0, len = this.targets.length; i < len; i++) {\r\n let target = this.targets[i] as HTMLElement;\r\n let animationOptions = {\r\n easing: getEase(easing),\r\n iterations: loop === true ? Infinity : (loop as number),\r\n direction,\r\n endDelay,\r\n duration,\r\n delay,\r\n fill: fillMode,\r\n };\r\n\r\n // Accept keyframes as a keyframes Object, or a method,\r\n // if there are no animations in the keyframes array,\r\n // uses css properties from the options object\r\n let arrKeyframes = computeValue((keyframes as Keyframe[]), [i, len, target]);\r\n animationKeyframe = arrKeyframes.length ? arrKeyframes :\r\n (this.properties as PropertyIndexedKeyframes);\r\n\r\n // Allows the use of functions as the values, for both the keyframes and the animation object\r\n // It adds the capability of advanced stagger animation, similar to the anime js stagger functions\r\n animationOptions = mapObject(animationOptions, [i, len, target]);\r\n if (!(arrKeyframes.length > 0))\r\n animationKeyframe = mapObject(animationKeyframe, [i, len, target]);\r\n\r\n // Set the Animate classes duration to be the Animation with the largest totalDuration\r\n let tempDuration: number =\r\n animationOptions.delay +\r\n (animationOptions.duration * animationOptions.iterations) +\r\n animationOptions.endDelay;\r\n if (this.duration < tempDuration) this.duration = tempDuration;\r\n\r\n // Add animation to the Animations Set\r\n let animation = target.animate(animationKeyframe, animationOptions);\r\n animation.onfinish = () => {\r\n onfinish(target, i, len);\r\n };\r\n this.animations.set(target, animation);\r\n }\r\n\r\n this.mainAnimation = this.mainElement.animate([\r\n { opacity: \"0\" },\r\n { opacity: \"1\" }\r\n ], {\r\n duration: this.duration,\r\n easing: \"linear\"\r\n });\r\n\r\n this.setSpeed(speed);\r\n if (autoplay) this.play();\r\n else this.pause();\r\n\r\n this.promise = this.newPromise();\r\n this.mainAnimation.onfinish = () => {\r\n this.finish(this.options);\r\n window.cancelAnimationFrame(this.animationFrame);\r\n };\r\n }\r\n\r\n /**\r\n * Returns the Array of targets\r\n *\r\n * @returns {Node[]}\r\n * @memberof Animate\r\n */\r\n public getTargets(): Node[] {\r\n return this.targets;\r\n }\r\n\r\n /**\r\n * Returns a new Promise that is resolve when this.finish is called\r\n *\r\n * @public\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public newPromise(): Promise {\r\n return new Promise((resolve, reject) => {\r\n try {\r\n this.finish = (options: AnimationOptions) => {\r\n this.emit(\"finish\", options);\r\n return resolve(options);\r\n };\r\n } catch (err) { reject(err); }\r\n });\r\n }\r\n\r\n /**\r\n * Fulfills the this.promise Promise\r\n *\r\n * @param {(value?: any) => any} [onFulfilled]\r\n * @param {(reason?: any) => any} [onRejected]\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public then(\r\n onFulfilled?: (value?: any) => any,\r\n onRejected?: (reason?: any) => any\r\n ): Promise {\r\n return this.promise.then(onFulfilled, onRejected);\r\n }\r\n\r\n /**\r\n * Catches error that occur in the this.promise Promise\r\n *\r\n * @param {(reason?: any) => any} onRejected\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public catch(onRejected: (reason?: any) => any): Promise {\r\n return this.promise.catch(onRejected);\r\n }\r\n\r\n /**\r\n * If you don't care if the this.promise Promise has either been rejected or resolved\r\n *\r\n * @param {() => any} onFinally\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public finally(onFinally: () => any): Promise {\r\n return this.promise.finally(onFinally);\r\n }\r\n\r\n /**\r\n * Represents an Animation Frame Loop\r\n *\r\n * @public\r\n * @memberof Animate\r\n */\r\n public loop(): void {\r\n this.animationFrame = window.requestAnimationFrame(this.loop);\r\n this.emit(\"tick change\", this.getCurrentTime());\r\n }\r\n\r\n /**\r\n * Adds a listener for a given event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public on(events: EventInput, callback?: ListenerCallback, scope?: object): Animate {\r\n this.emitter.on(events, callback, scope);\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes a listener from an event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public off(events: EventInput, callback?: ListenerCallback, scope?: object): Animate {\r\n this.emitter.off(events, callback, scope);\r\n return this;\r\n }\r\n\r\n /**\r\n * Call all listeners within an event\r\n *\r\n * @param {(string | any[])} events\r\n * @param {...any} args\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public emit(events: string | any[], ...args: any): Animate {\r\n this.emitter.emit(events, ...args);\r\n return this;\r\n }\r\n\r\n /**\r\n * Get a specific Animation from an Animate instance\r\n *\r\n * @param {HTMLElement} element\r\n * @returns {Animation}\r\n * @memberof Animate\r\n */\r\n public getAnimation(element: HTMLElement): Animation {\r\n return this.animations.get(element);\r\n }\r\n\r\n /**\r\n * Play Animation's\r\n *\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public play(): Animate {\r\n // Once the animation is done, it's done, it can only be paused by the reset method\r\n if (this.mainAnimation.playState !== \"finished\") {\r\n this.mainAnimation.play();\r\n this.animationFrame = requestAnimationFrame(this.loop);\r\n this.animations.forEach(animation => {\r\n if (animation.playState !== \"finished\") animation.play();\r\n });\r\n this.emit(\"play\");\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Pause Animation's\r\n *\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public pause(): Animate {\r\n // Once the animation is done, it's done, it can only be reset by the reset method\r\n if (this.mainAnimation.playState !== \"finished\") {\r\n this.mainAnimation.pause();\r\n window.cancelAnimationFrame(this.animationFrame);\r\n this.animations.forEach(animation => {\r\n if (animation.playState !== \"finished\") animation.pause();\r\n });\r\n this.emit(\"pause\");\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the total duration of all Animations\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getDuration(): number {\r\n return this.duration;\r\n }\r\n\r\n /**\r\n * Returns the current time of the Main Animation\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getCurrentTime(): number {\r\n return this.mainAnimation.currentTime;\r\n }\r\n\r\n /**\r\n * Set the current time of the Main Animation\r\n *\r\n * @param {number} time\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setCurrentTime(time: number): Animate {\r\n this.mainAnimation.currentTime = time;\r\n this.animations.forEach(animation => {\r\n animation.currentTime = time;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the Animation progress as a fraction of the current time / duration\r\n *\r\n * @returns\r\n * @memberof Animate\r\n */\r\n public getProgress() {\r\n return this.getCurrentTime() / this.duration;\r\n }\r\n\r\n /**\r\n * Set the Animation progress as a fraction of the current time / duration\r\n *\r\n * @param {number} percent\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setProgress(percent: number): Animate {\r\n this.mainAnimation.currentTime = percent * this.duration;\r\n this.animations.forEach(animation => {\r\n animation.currentTime = percent * this.duration;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Return the playback speed of the animation\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getSpeed(): number {\r\n return this.mainAnimation.playbackRate;\r\n }\r\n\r\n /**\r\n * Set the playback speed of an Animation\r\n *\r\n * @param {number} [speed=1]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setSpeed(speed: number = 1): Animate {\r\n this.mainAnimation.playbackRate = speed;\r\n this.animations.forEach(animation => {\r\n animation.playbackRate = speed;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Reset all Animations\r\n *\r\n * @memberof Animate\r\n */\r\n public reset() {\r\n this.setCurrentTime(0);\r\n this.promise = this.newPromise();\r\n\r\n if (this.options.autoplay) this.play();\r\n else this.pause();\r\n }\r\n\r\n /**\r\n * Returns the current playing state\r\n *\r\n * @returns {(\"idle\" | \"running\" | \"paused\" | \"finished\")}\r\n * @memberof Animate\r\n */\r\n public getPlayState(): \"idle\" | \"running\" | \"paused\" | \"finished\" {\r\n return this.mainAnimation.playState;\r\n }\r\n\r\n /**\r\n * Get the options of an Animate instance\r\n *\r\n * @returns {AnimationOptions}\r\n * @memberof Animate\r\n */\r\n public getOptions(): AnimationOptions {\r\n return this.options;\r\n }\r\n\r\n // Returns the Animate options, as JSON\r\n public toJSON(): AnimationOptions {\r\n return this.getOptions();\r\n }\r\n}\r\n\r\n// Creates a new Animate instance\r\nexport const animate = (options: AnimationOptions = {}): Animate => {\r\n return new Animate(options);\r\n};\r\n\r\nexport default animate;\r\n"], + "mappings": "oJAAA,qoBCcO,IAAM,EAA2B,CACpC,YAAa,UACb,eAAgB,eAChB,eAAgB,cAChB,QAAS,CACL,CAAC,YAAa,SAElB,gBAAiB,iBACjB,eAAgB,gBAChB,eAAgB,aAChB,UAAW,QACX,QAAS,OAzBb,M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KAAK,WAAW,QAAQ,IACpB,AAAI,EAAU,YAAc,YAAY,EAAU,UAEtD,KAAK,KAAK,UAEP,KASJ,cACH,MAAO,MAAK,SAST,iBACH,MAAO,MAAK,cAAc,YAUvB,kBACH,YAAK,cAAc,YAAc,EACjC,KAAK,WAAW,QAAQ,IACpB,EAAU,YAAc,IAErB,KASJ,cACH,MAAO,MAAK,iBAAmB,KAAK,SAUjC,eACH,YAAK,cAAc,YAAc,EAAU,KAAK,SAChD,KAAK,WAAW,QAAQ,IACpB,EAAU,YAAc,EAAU,KAAK,WAEpC,KASJ,WACH,MAAO,MAAK,cAAc,aAUvB,WAAyB,GAC5B,YAAK,cAAc,aAAe,EAClC,KAAK,WAAW,QAAQ,IACpB,EAAU,aAAe,IAEtB,KAQJ,QACH,KAAK,eAAe,GACpB,KAAK,QAAU,KAAK,aAEpB,AAAI,KAAK,QAAQ,SAAU,KAAK,OAC3B,KAAK,QASP,eACH,MAAO,MAAK,cAAc,UASvB,aACH,MAAO,MAAK,QAIT,SACH,MAAO,MAAK,kBAKG,GAA6B,KACzC,GAAI,GAAQ", "names": [] } diff --git a/packages/native/lib/api.modern.js b/packages/native/lib/api.modern.js index 90181c6..53bf66f 100644 --- a/packages/native/lib/api.modern.js +++ b/packages/native/lib/api.modern.js @@ -1,3 +1,3 @@ -var q={wrapperAttr:"wrapper",noAjaxLinkAttr:"no-ajax-link",noPrefetchAttr:"no-prefetch",headers:[["x-partial","true"]],preventSelfAttr:'prevent="self"',preventAllAttr:'prevent="all"',transitionAttr:"transition",blockAttr:"block",timeout:3e4},P=class{constructor(t){this.config=Object.assign({...q},t)}toAttr(t,e=!0){let{prefix:i}=this.config,r=`data${i?"-"+i:""}-${t}`;return e?`[${r}]`:r}getConfig(t,e=!0){if(typeof t!="string")return this.config;let i=this.config[t];return typeof i=="string"?this.toAttr(i,e):i}};var u=class{constructor(t){this.map=new Map(t)}getMap(){return this.map}get(t){return this.map.get(t)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(t,e){return this.map.set(t,e),this}add(t){let e=this.size,i=e;return this.set(i,t),this}get size(){return this.map.size}get length(){return this.map.size}last(t=1){let e=this.keys()[this.size-t];return this.get(e)}delete(t){return this.map.delete(t)}remove(t){return this.map.delete(t),this}clear(){return this.map.clear(),this}has(t){return this.map.has(t)}entries(){return this.map.entries()}forEach(t=(...i)=>{},e){return this.map.forEach(t,e),this}[Symbol.iterator](){return this.entries()}},E=(n,t,...e)=>{n.forEach(i=>{i[t](...e)})},$=async(n,t,...e)=>{for(let[,i]of n)await i[t](...e)},w=class{constructor(){}install(){}register(t,e){return this.manager=t,this.app=t.app,this.config=t.config,this.emitter=t.emitter,this.key=e,this.install(),this}uninstall(){}unregister(){this.uninstall(),this.manager.delete(this.key),this.key=void 0,this.manager=void 0,this.app=void 0,this.config=void 0,this.emitter=void 0}},x=class extends u{constructor(t){super();this.app=t,this.config=t.config,this.emitter=t.emitter}set(t,e){return super.set(t,e),e.register(this,t),this}};var p=(n=window.location.href)=>n instanceof URL?n:new URL(n,window.location.origin),m=n=>`${n.pathname}${n.hash}`,st=n=>n.hash.slice(1),D=n=>n.toString().replace(/(\/#.*|\/|#.*)$/,""),M=(n,t)=>{let e=p(n),i=p(t);return D(e)===D(i)};var C=(n=window.scrollX,t=window.scrollY)=>({x:n,y:t}),S=(n={url:m(p()),index:0,transition:"default",data:{scroll:C(),trigger:"HistoryManager"}})=>n,k=class{constructor(){this.pointer=-1;this.states=[];let t=S();this.add(t,"replace")}get(t){return this.states[t]}add(t,e="push"){let i=S(t),r=this.length;this.states.push({...i}),this.pointer=r;let o={index:this.pointer,states:[...this.states]};return this.changeState(e,i,o),this}remove(t){return t?this.states.splice(t,1):this.states.pop(),this.pointer--,this}replace(t){return this.states=t,this}set(t,e){return this.states[t]=e}get current(){return this.get(this.pointer)}get last(){return this.get(this.length-1)}get previous(){return this.pointer<1?null:this.get(this.pointer-1)}get length(){return this.states.length}changeState(t,e,i){let r=m(p(e.url)),o=[i,"",r];if(window.history)switch(t){case"push":window.history.pushState.apply(window.history,o);break;case"replace":window.history.replaceState.apply(window.history,o);break}}};var B=new DOMParser,d=class extends w{constructor(t=p(),e=document){super();this.url=t,typeof e=="string"?this.data=e:this.dom=e||document}async build(){if(this.dom instanceof Node||(this.dom=B.parseFromString(this.data,"text/html")),!(this.body instanceof Node)){let{title:t,head:e,body:i}=this.dom;this.title=t,this.head=e,this.body=i,this.wrapper=this.body.querySelector(this.wrapperAttr)}}install(){this.wrapperAttr=this.config.getConfig("wrapperAttr")}uninstall(){this.url=void 0,this.title=void 0,this.head=void 0,this.body=void 0,this.dom=void 0,this.wrapper=void 0,this.data=void 0,this.wrapperAttr=void 0}},O=class extends x{constructor(t){super(t);this.loading=new u;this.maxPages=5;let e=p().pathname;this.set(e,new d),e=void 0}async load(t=p()){let e=p(t),i=e.pathname,r,o;if(this.has(i))return r=this.get(i),Promise.resolve(r);this.loading.has(i)?o=this.loading.get(i):(o=this.request(i),this.loading.set(i,o));let s=await o;if(this.loading.delete(i),r=new d(e,s),this.set(i,r),this.size>this.maxPages){let a=p(),l=this.keys(),c=M(a,l[0])?l[1]:l[0],h=this.get(c);h.unregister(),h=void 0,l=void 0,a=void 0,c=void 0}return r}async request(t){let e=new Headers(this.config.getConfig("headers")),i=window.setTimeout(()=>{throw window.clearTimeout(i),"Request Timed Out!"},this.config.getConfig("timeout"));try{let r=await fetch(t,{mode:"same-origin",method:"GET",headers:e,cache:"default",credentials:"same-origin"});if(window.clearTimeout(i),r.status>=200&&r.status<300)return await r.text();let o=new Error(r.statusText||""+r.status);throw o}catch(r){throw window.clearTimeout(i),r}}};var _=({callback:n=()=>{},scope:t=null,name:e="event"})=>({callback:n,scope:t,name:e}),T=class extends u{constructor(t="event"){super();this.name=t}},v=class extends u{constructor(){super()}getEvent(t){let e=this.get(t);return e instanceof T?e:(this.set(t,new T(t)),this.get(t))}newListener(t,e,i){let r=this.getEvent(t);return r.add(_({name:t,callback:e,scope:i})),r}on(t,e,i){if(typeof t=="undefined")return this;typeof t=="string"&&(t=t.trim().split(/\s/g));let r,o,s=typeof t=="object"&&!Array.isArray(t),a=s?e:i;return s||(o=e),Object.keys(t).forEach(l=>{s?(r=l,o=t[l]):r=t[l],this.newListener(r,o,a)},this),this}removeListener(t,e,i){let r=this.get(t);if(r instanceof T&&e){let o=_({name:t,callback:e,scope:i});r.forEach((s,a)=>{if(s.callback===o.callback&&s.scope===o.scope)return r.delete(a)})}return r}off(t,e,i){if(typeof t=="undefined")return this;typeof t=="string"&&(t=t.trim().split(/\s/g));let r,o,s=typeof t=="object"&&!Array.isArray(t),a=s?e:i;return s||(o=e),Object.keys(t).forEach(l=>{s?(r=l,o=t[l]):r=t[l],typeof o=="function"?this.removeListener(r,o,a):this.delete(r)},this),this}emit(t,...e){return typeof t=="undefined"?this:(typeof t=="string"&&(t=t.trim().split(/\s/g)),t.forEach(i=>{let r=this.get(i);r instanceof T&&r.forEach(o=>{let{callback:s,scope:a}=o;s.apply(a,e)})},this),this)}};var I=class extends w{install(){let{app:t}=this.manager;this.PageManager=t.pages,this.HistoryManager=t.history,this.ServiceManager=t.services,this.TransitionManager=t.transitions}init(...t){}boot(){this.initEvents()}initEvents(){}stopEvents(){}uninstall(){this.PageManager=void 0,this.HistoryManager=void 0,this.ServiceManager=void 0,this.TransitionManager=void 0}stop(){this.stopEvents(),this.unregister()}},H=class extends x{constructor(t){super(t)}init(){return E(this,"init",this.app),this}boot(){return E(this,"boot",this.app),this}stop(){return E(this,"stop",this.app),this}};var N=class extends u{constructor(t){super();this.app=t,this.config=t.config,this.emitter=t.emitter}async boot(t,e){let i=this.get(t);if(!(e.oldPage instanceof d)||!(e.newPage instanceof d))throw`[Page] either oldPage or newPage aren't instances of the Page Class. - ${{newPage:e.newPage,oldPage:e.oldPage}}`;let r=e.oldPage.wrapper,o=e.newPage.wrapper;if(document.title=""+e.newPage.title,!(r instanceof Node)||!(o instanceof Node))throw`[Wrapper] the wrapper from the ${o instanceof Node?"current":"next"} page cannot be found. The wrapper must be an element that has the attribute ${this.config.getConfig("wrapperAttr")}.`;return i.init&&i?.init(e),this.emitter.emit("BEFORE_TRANSITION_OUT"),await new Promise(s=>{let a=i.out.call(i,{from:e.oldPage,trigger:e.trigger,scroll,done:s});a.then&&a.then(s)}),this.emitter.emit("AFTER_TRANSITION_OUT"),await new Promise(s=>{r.insertAdjacentElement("beforebegin",o),this.emitter.emit("CONTENT_INSERT"),s()}),await new Promise(s=>{r.remove(),r=void 0,o=void 0,this.emitter.emit("CONTENT_REPLACED"),s()}),this.emitter.emit("BEFORE_TRANSITION_IN"),await new Promise(s=>{let a=i.in.call(i,{from:e.oldPage,to:e.newPage,trigger:e.trigger,scroll,done:s});a.then&&a.then(s)}),this.emitter.emit("AFTER_TRANSITION_IN"),i}};var W=class{constructor(t={}){this.register(t)}register(t={}){this.config=t instanceof P?t:new P(t),this.emitter=new v,this.history=new k,this.pages=new O(this),this.transitions=new N(this),this.services=new H(this);let e=(()=>{document.removeEventListener("DOMContentLoaded",e),window.removeEventListener("load",e),this.emitter.emit("READY ready")}).bind(this);return document.addEventListener("DOMContentLoaded",e),window.addEventListener("load",e),this}get(t,e){switch(t.toLowerCase()){case"service":return this.services.get(e);case"transition":return this.transitions.get(e);case"state":return this.history.get(e);default:throw`Error: can't get type '${t}', it is not a recognized type. Did you spell it correctly.`}}async load(t,e){switch(t.toLowerCase()){case"page":return await this.pages.load(e);default:return Promise.resolve(this.get(t,e))}}setService(t,e){return this.services.set(t,e),this}setTransition(t,e){return this.transitions.set(t,e),this}add(t,e){switch(t.toLowerCase()){case"service":this.services.add(e);break;case"transition":this.transitions.set(e.name,e);break;case"state":this.history.add(e);break;default:throw`Error: can't add type '${t}', it is not a recognized type. Did you spell it correctly.`}return this}boot(){return this.services.init(),this.services.boot(),this}stop(){return this.services.stop(),this}on(t,e){return this.emitter.on(t,e,this),this}off(t,e){return this.emitter.off(t,e,this),this}emit(t,...e){return this.emitter.emit(t,...e),this}};var Y=class extends I{constructor(){super(...arguments);this.ignoreURLs=[];this.prefetchIgnore=!1;this.isTransitioning=!1;this.stopOnTransitioning=!1;this.stickyScroll=!1;this.forceOnError=!1;this.autoScrollOnHash=!0;this.dontScroll=!0}transitionStart(){this.isTransitioning=!0}transitionStop(){this.isTransitioning=!1}init(){super.init(),this.onHover=this.onHover.bind(this),this.onClick=this.onClick.bind(this),this.onStateChange=this.onStateChange.bind(this)}boot(){"scrollRestoration"in window.history&&(window.history.scrollRestoration="manual"),super.boot()}getTransitionName(t){if(!t||!t.getAttribute)return null;let e=t.getAttribute(this.config.getConfig("transitionAttr",!1));return typeof e=="string"?e:null}validLink(t,e,i){let r=!window.history.pushState,o=!t||!i,s=e.metaKey||e.ctrlKey||e.shiftKey||e.altKey,a=t.hasAttribute("target")&&t.target==="_blank",l=t.protocol!==location.protocol||t.hostname!==location.hostname,c=typeof t.getAttribute("download")=="string",h=t.hasAttribute(this.config.getConfig("preventSelfAttr",!1)),g=Boolean(t.closest(this.config.getConfig("preventAllAttr"))),y=h&&g,F=m(p())===m(p(i));return!(o||r||s||a||l||c||y||F)}getHref(t){return t&&t.tagName&&t.tagName.toLowerCase()==="a"&&typeof t.href=="string"?t.href:null}getLink(t){let e=t.target,i=this.getHref(e);for(;e&&!i;)e=e.parentNode,i=this.getHref(e);return!e||!this.validLink(e,t,i)?void 0:e}onClick(t){let e=this.getLink(t);if(!e)return;if(this.isTransitioning&&this.stopOnTransitioning){t.preventDefault(),t.stopPropagation();return}let i=this.getHref(e);this.emitter.emit("ANCHOR_CLICK CLICK",t),this.go({href:i,trigger:e,event:t})}getDirection(t){return Math.abs(t)>1?t>0?"forward":"back":t===0?"popstate":t>0?"back":"forward"}force(t){window.location.assign(t)}go({href:t,trigger:e="HistoryManager",event:i}){if(this.isTransitioning&&this.stopOnTransitioning){this.force(t);return}let r={x:0,y:0},o=this.HistoryManager.current,s=o.url;if(M(s,t))return;let a;if(i&&i.state){this.emitter.emit("POPSTATE",i);let{state:l}=i,{index:c}=l,h=o.index,g=h-c;e=this.getDirection(g),this.HistoryManager.replace(l.states),this.HistoryManager.pointer=c,e==="back"?this.emitter.emit("POPSTATE_BACK",i):e==="forward"&&this.emitter.emit("POPSTATE_FORWARD",i);let y=this.HistoryManager.get(c);a=y.transition,e!=="popstate"&&(r=y.data.scroll)}else{a=this.getTransitionName(e)||"default";let l=C();if(!this.dontScroll&&this.stickyScroll){let{x:h,y:g}=l;r={x:h,y:g}}else r={x:0,y:0};let c=S({url:t,transition:a,data:{scroll:l}});this.HistoryManager.add(c),this.emitter.emit("HISTORY_NEW_ITEM",i)}return i&&(i.stopPropagation(),i.preventDefault()),this.emitter.emit("GO",i),this.load({oldHref:s,href:t,trigger:e,transitionName:a,scroll:r})}async load({oldHref:t,href:e,trigger:i,transitionName:r="default",scroll:o={x:0,y:0}}){try{let s=await this.PageManager.load(t);await s.build();let a;this.emitter.emit("PAGE_LOADING",{href:e,oldPage:s,trigger:i});try{try{a=await this.PageManager.load(e),await a.build(),this.transitionStart(),this.emitter.emit("PAGE_LOAD_COMPLETE",{newPage:a,oldPage:s,trigger:i})}catch(l){console.error(`[PJAX] page load error: ${l}`)}this.emitter.emit("NAVIGATION_START",{oldPage:s,newPage:a,trigger:i,transitionName:r});try{this.emitter.emit("TRANSITION_START",r);let l=await this.TransitionManager.boot(r,{oldPage:s,newPage:a,trigger:i,scroll:o});l.scrollable||(/back|popstate|forward/.test(i)||(o=J(e)),window.scroll(o.x,o.y)),this.emitter.emit("TRANSITION_END",{transition:l})}catch(l){console.error(`[PJAX] transition error: ${l}`)}this.emitter.emit("NAVIGATION_END",{oldPage:s,newPage:a,trigger:i,transitionName:r})}catch(l){throw this.transitionStop(),l}this.transitionStop()}catch(s){this.forceOnError?this.force(e):console.error(s)}}ignoredURL({pathname:t}){return this.ignoreURLs.length&&this.ignoreURLs.some(e=>typeof e=="string"?e===t:e.exec(t)!==null)}onHover(t){let e=this.getLink(t);if(!e)return;let i=p(this.getHref(e)),r=i.pathname;if(this.ignoredURL(i)||this.PageManager.has(r))return;this.emitter.emit("ANCHOR_HOVER HOVER",t);try{this.PageManager.load(i)}catch(o){console.warn("[PJAX] prefetch error,",o)}}onStateChange(t){this.go({href:window.location.href,trigger:"popstate",event:t})}initEvents(){this.prefetchIgnore!==!0&&(document.addEventListener("mouseover",this.onHover),document.addEventListener("touchstart",this.onHover)),document.addEventListener("click",this.onClick),window.addEventListener("popstate",this.onStateChange)}stopEvents(){this.prefetchIgnore!==!0&&(document.removeEventListener("mouseover",this.onHover),document.removeEventListener("touchstart",this.onHover)),document.removeEventListener("click",this.onClick),window.removeEventListener("popstate",this.onStateChange)}},J=(n=window.location.hash)=>{try{let t=n[0]=="#"?n:p(n).hash;if(t.length>1){let e=document.querySelector(t);if(e)return{x:e.offsetLeft,y:e.offsetTop}}}catch(t){console.warn("hashAction error",t)}return{x:0,y:0}};var X=class extends I{constructor(t=[]){super();this.routes=new u;for(let e of t)this.add(e)}add({path:t,method:e}){let i=this.parse(t);return this.routes.set(i,e),this}parsePath(t){if(typeof t=="string")return new RegExp(t,"i");if(t instanceof RegExp||typeof t=="boolean")return t;throw"[Router] only regular expressions, strings and booleans are accepted as paths."}isPath(t){return typeof t=="string"||t instanceof RegExp||typeof t=="boolean"}parse(t){let e=t,i={from:/(.*)/g,to:/(.*)/g};if(this.isPath(t))i={from:!0,to:t};else if(this.isPath(e.from)&&this.isPath(e.to))i=e;else throw"[Router] path is neither a string, regular expression, or a { from, to } object.";let{from:r,to:o}=i;return{from:this.parsePath(r),to:this.parsePath(o)}}route(){let t=this.HistoryManager,e=m(p((t.length>1?t.previous:t.current).url)),i=m(p());this.routes.forEach((r,o)=>{let s=o.from,a=o.to;if(typeof s=="boolean"&&typeof a=="boolean")throw`[Router] path ({ from: ${s}, to: ${a} }) is not valid, remember paths can only be strings, regular expressions, or a boolean; however, both the from and to paths cannot be both booleans.`;let l=s,c=a;s instanceof RegExp&&s.test(e)&&(l=s.exec(e)),a instanceof RegExp&&a.test(i)&&(c=a.exec(i)),(Array.isArray(c)&&Array.isArray(l)||Array.isArray(c)&&typeof l=="boolean"&&l||Array.isArray(l)&&typeof c=="boolean"&&c)&&r({from:l,to:c,path:{from:e,to:i}})})}initEvents(){this.emitter.on("READY",this.route,this),this.emitter.on("CONTENT_REPLACED",this.route,this)}stopEvents(){this.emitter.off("READY",this.route,this),this.emitter.off("CONTENT_REPLACED",this.route,this)}};var Q=n=>typeof n=="string"?Array.from(document.querySelectorAll(n)):[n],Z=n=>Array.isArray(n)?n:typeof n=="string"||n instanceof Node?Q(n):n instanceof NodeList||n instanceof HTMLCollection?Array.from(n):[],j=(n,t)=>typeof n=="function"?n(...t):n,z=(n,t)=>{let e,i,r={},o=Object.keys(n);for(let s=0,a=o.length;s/^(ease|in|out)/.test(n)?tt[n]:n,it={keyframes:[],loop:1,delay:0,speed:1,endDelay:0,easing:"ease",autoplay:!0,duration:1e3,onfinish(){},fillMode:"auto",direction:"normal"},U=class{constructor(t={}){this.options={};this.targets=[];this.properties={};this.animations=new Map;this.duration=0;this.emitter=new v;let{options:e,...i}=t;this.options=Object.assign({},it,e,i),this.loop=this.loop.bind(this);let{loop:r,delay:o,speed:s,easing:a,endDelay:l,duration:c,direction:h,fillMode:g,onfinish:y,target:F,keyframes:rt,autoplay:nt,...ot}=this.options;this.mainElement=document.createElement("span"),this.targets=Z(F),this.properties=ot;let R;for(let f=0,L=this.targets.length;f0||(R=z(R,[f,L,A]));let V=b.delay+b.duration*b.iterations+b.endDelay;this.duration{y(A,f,L)},this.animations.set(A,G)}this.mainAnimation=this.mainElement.animate([{opacity:"0"},{opacity:"1"}],{duration:this.duration,easing:"linear"}),this.setSpeed(s),nt?this.play():this.pause(),this.promise=this.newPromise(),this.mainAnimation.onfinish=()=>{this.finish(this.options),window.cancelAnimationFrame(this.animationFrame)}}getTargets(){return this.targets}newPromise(){return new Promise((t,e)=>{try{this.finish=i=>(this.emit("finish",i),t(i))}catch(i){e(i)}})}then(t,e){return this.promise.then(t,e)}catch(t){return this.promise.catch(t)}finally(t){return this.promise.finally(t)}loop(){this.animationFrame=window.requestAnimationFrame(this.loop),this.emit("tick change",this.getCurrentTime())}on(t,e,i){return this.emitter.on(t,e,i),this}off(t,e,i){return this.emitter.off(t,e,i),this}emit(t,...e){return this.emitter.emit(t,...e),this}getAnimation(t){return this.animations.get(t)}play(){return this.mainAnimation.playState!=="finished"&&(this.mainAnimation.play(),this.animationFrame=requestAnimationFrame(this.loop),this.animations.forEach(t=>{t.playState!=="finished"&&t.play()}),this.emit("play")),this}pause(){return this.mainAnimation.playState!=="finished"&&(this.mainAnimation.pause(),window.cancelAnimationFrame(this.animationFrame),this.animations.forEach(t=>{t.playState!=="finished"&&t.pause()}),this.emit("pause")),this}getDuration(){return this.duration}getCurrentTime(){return this.mainAnimation.currentTime}setCurrentTime(t){return this.mainAnimation.currentTime=t,this.animations.forEach(e=>{e.currentTime=t}),this}getProgress(){return this.getCurrentTime()/this.duration}setProgress(t){return this.mainAnimation.currentTime=t*this.duration,this.animations.forEach(e=>{e.currentTime=t*this.duration}),this}getSpeed(){return this.mainAnimation.playbackRate}setSpeed(t=1){return this.mainAnimation.playbackRate=t,this.animations.forEach(e=>{e.playbackRate=t}),this}reset(){this.setCurrentTime(0),this.promise=this.newPromise(),this.options.autoplay?this.play():this.pause()}getPlayState(){return this.mainAnimation.playState}getOptions(){return this.options}toJSON(){return this.getOptions()}},at=(n={})=>new U(n);export{x as AdvancedManager,U as Animate,W as App,P as CONFIG,q as CONFIG_DEFAULTS,it as DefaultAnimationOptions,T as Event,v as EventEmitter,k as HistoryManager,u as Manager,w as ManagerItem,B as PARSER,Y as PJAX,d as Page,O as PageManager,X as Router,I as Service,H as ServiceManager,N as TransitionManager,at as animate,$ as asyncMethodCall,D as clean,j as computeValue,tt as easings,M as equal,et as getEase,Q as getElements,st as getHash,m as getHashedPath,Z as getTargets,J as hashAction,z as mapObject,E as methodCall,C as newCoords,_ as newListener,S as newState,p as newURL}; +var $={wrapperAttr:"wrapper",noAjaxLinkAttr:"no-ajax-link",noPrefetchAttr:"no-prefetch",headers:[["x-partial","true"]],preventSelfAttr:'prevent="self"',preventAllAttr:'prevent="all"',transitionAttr:"transition",blockAttr:"block",timeout:3e4},P=class{constructor(t){this.config=Object.assign({...$},t)}toAttr(t,e=!0){let{prefix:i}=this.config,n=`data${i?"-"+i:""}-${t}`;return e?`[${n}]`:n}getConfig(t,e=!0){if(typeof t!="string")return this.config;let i=this.config[t];return typeof i=="string"?this.toAttr(i,e):i}};var u=class{constructor(t){this.map=new Map(t)}getMap(){return this.map}get(t){return this.map.get(t)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(t,e){return this.map.set(t,e),this}add(t){let e=this.size,i=e;return this.set(i,t),this}get size(){return this.map.size}get length(){return this.map.size}last(t=1){let e=this.keys()[this.size-t];return this.get(e)}delete(t){return this.map.delete(t)}remove(t){return this.map.delete(t),this}clear(){return this.map.clear(),this}has(t){return this.map.has(t)}entries(){return this.map.entries()}forEach(t=(...i)=>{},e){return this.map.forEach(t,e),this}[Symbol.iterator](){return this.entries()}},A=(r,t,...e)=>{r.forEach(i=>{i[t](...e)})},B=async(r,t,...e)=>{for(let[,i]of r)await i[t](...e)},E=class{constructor(){}install(){}register(t,e){return this.manager=t,this.app=t.app,this.config=t.config,this.emitter=t.emitter,this.key=e,this.install(),this}uninstall(){}unregister(){this.uninstall(),this.manager.delete(this.key),this.key=void 0,this.manager=void 0,this.app=void 0,this.config=void 0,this.emitter=void 0}},w=class extends u{constructor(t){super();this.app=t,this.config=t.config,this.emitter=t.emitter}set(t,e){return super.set(t,e),e.register(this,t),this}};var p=(r=window.location.href)=>r instanceof URL?r:new URL(r,window.location.origin),h=r=>`${r.pathname}${r.hash}`,at=r=>r.hash.slice(1),_=r=>r.toString().replace(/(\/#.*|\/|#.*)$/,""),R=(r,t)=>{let e=p(r),i=p(t);return _(e)===_(i)};var x=(r=window.scrollX,t=window.scrollY)=>({x:r,y:t}),S=(r={url:h(p()),index:0,transition:"default",data:{scroll:x(),trigger:"HistoryManager"}})=>r,k=class{constructor(){this.pointer=-1;this.states=[];let t=S();this.add(t,"replace")}get(t){return this.states[t]}add(t,e="push"){let i=S(t),n=this.length;this.states.push({...i}),this.pointer=n;let o={index:this.pointer,states:[...this.states]};return W(e,i,o),this}remove(t){return t?this.states.splice(t,1):this.states.pop(),this.pointer--,this}replace(t){return this.states=t,this}set(t,e){return this.states[t]=e}get current(){return this.get(this.pointer)}get last(){return this.get(this.length-1)}get previous(){return this.pointer<1?null:this.get(this.pointer-1)}get length(){return this.states.length}},W=(r,t,e)=>{let i=h(p(t.url)),n=[e,"",i];if(window.history)switch(r){case"push":window.history.pushState.apply(window.history,n);break;case"replace":window.history.replaceState.apply(window.history,n);break}};var Y=new DOMParser,b=class extends E{constructor(t=p(),e=document){super();this.url=t,typeof e=="string"?this.data=e:this.dom=e||document}async build(){if(this.dom instanceof Node||(this.dom=Y.parseFromString(this.data,"text/html")),!(this.body instanceof Node)){let{title:t,head:e,body:i}=this.dom;this.title=t,this.head=e,this.body=i,this.wrapper=this.body.querySelector(this.wrapperAttr)}}install(){this.wrapperAttr=this.config.getConfig("wrapperAttr")}uninstall(){this.url=void 0,this.title=void 0,this.head=void 0,this.body=void 0,this.dom=void 0,this.wrapper=void 0,this.data=void 0,this.wrapperAttr=void 0}},O=class extends w{constructor(t){super(t);this.loading=new u;this.maxPages=5;let e=p().pathname;this.set(e,new b),e=void 0}async load(t=p()){let e=p(t),i=e.pathname,n,o;if(this.has(i))return n=this.get(i),Promise.resolve(n);this.loading.has(i)?o=this.loading.get(i):(o=this.request(i),this.loading.set(i,o));let s=await o;if(this.loading.delete(i),n=new b(e,s),this.set(i,n),this.size>this.maxPages){let a=p(),l=this.keys(),c=R(a,l[0])?l[1]:l[0],m=this.get(c);m.unregister(),m=void 0,l=void 0,a=void 0,c=void 0}return n}async request(t){let e=new Headers(this.config.getConfig("headers")),i=window.setTimeout(()=>{throw window.clearTimeout(i),"Request Timed Out!"},this.config.getConfig("timeout"));try{let n=await fetch(t,{mode:"same-origin",method:"GET",headers:e,cache:"default",credentials:"same-origin"});if(window.clearTimeout(i),n.status>=200&&n.status<300)return await n.text();let o=new Error(n.statusText||""+n.status);throw o}catch(n){throw window.clearTimeout(i),n}}};var j=({callback:r=()=>{},scope:t=null,name:e="event"})=>({callback:r,scope:t,name:e}),T=class extends u{constructor(t="event"){super();this.name=t}},v=class extends u{constructor(){super()}getEvent(t){let e=this.get(t);return e instanceof T?e:(this.set(t,new T(t)),this.get(t))}newListener(t,e,i){let n=this.getEvent(t);return n.add(j({name:t,callback:e,scope:i})),n}on(t,e,i){if(typeof t=="undefined")return this;typeof t=="string"&&(t=t.trim().split(/\s/g));let n,o,s=typeof t=="object"&&!Array.isArray(t),a=s?e:i;return s||(o=e),Object.keys(t).forEach(l=>{s?(n=l,o=t[l]):n=t[l],this.newListener(n,o,a)},this),this}removeListener(t,e,i){let n=this.get(t);if(n instanceof T&&e){let o=j({name:t,callback:e,scope:i});n.forEach((s,a)=>{if(s.callback===o.callback&&s.scope===o.scope)return n.delete(a)})}return n}off(t,e,i){if(typeof t=="undefined")return this;typeof t=="string"&&(t=t.trim().split(/\s/g));let n,o,s=typeof t=="object"&&!Array.isArray(t),a=s?e:i;return s||(o=e),Object.keys(t).forEach(l=>{s?(n=l,o=t[l]):n=t[l],typeof o=="function"?this.removeListener(n,o,a):this.delete(n)},this),this}emit(t,...e){return typeof t=="undefined"?this:(typeof t=="string"&&(t=t.trim().split(/\s/g)),t.forEach(i=>{let n=this.get(i);n instanceof T&&n.forEach(o=>{let{callback:s,scope:a}=o;s.apply(a,e)})},this),this)}};var I=class extends E{install(){let{app:t}=this.manager;this.PageManager=t.pages,this.HistoryManager=t.history,this.ServiceManager=t.services,this.TransitionManager=t.transitions}init(...t){}boot(){this.initEvents()}initEvents(){}stopEvents(){}uninstall(){this.PageManager=void 0,this.HistoryManager=void 0,this.ServiceManager=void 0,this.TransitionManager=void 0}stop(){this.stopEvents(),this.unregister()}},H=class extends w{constructor(t){super(t)}init(){return A(this,"init",this.app),this}boot(){return A(this,"boot",this.app),this}stop(){return A(this,"stop",this.app),this}};var J=class extends I{constructor(){super(...arguments);this.ignoreURLs=[];this.prefetchIgnore=!1;this.isTransitioning=!1;this.stopOnTransitioning=!1;this.stickyScroll=!1;this.forceOnError=!1;this.autoScrollOnHash=!0;this.dontScroll=!1}transitionStart(){this.isTransitioning=!0}transitionStop(){this.isTransitioning=!1}init(){super.init(),this.onHover=this.onHover.bind(this),this.onClick=this.onClick.bind(this),this.onStateChange=this.onStateChange.bind(this)}boot(){"scrollRestoration"in window.history&&(window.history.scrollRestoration="manual"),super.boot()}getTransitionName(t){if(!t||!t.getAttribute)return null;let e=t.getAttribute(this.config.getConfig("transitionAttr",!1));return typeof e=="string"?e:null}validLink(t,e,i){let n=!window.history.pushState,o=!t||!i,s=e.metaKey||e.ctrlKey||e.shiftKey||e.altKey,a=t.hasAttribute("target")&&t.target==="_blank",l=t.protocol!==location.protocol||t.hostname!==location.hostname,c=typeof t.getAttribute("download")=="string",m=t.hasAttribute(this.config.getConfig("preventSelfAttr",!1)),L=Boolean(t.closest(this.config.getConfig("preventAllAttr"))),d=m&&L,K=h(p())===h(p(i));return!(o||n||s||a||l||c||d||K)}getHref(t){return t&&t.tagName&&t.tagName.toLowerCase()==="a"&&typeof t.href=="string"?t.href:null}getLink(t){let e=t.target,i=this.getHref(e);for(;e&&!i;)e=e.parentNode,i=this.getHref(e);return!e||!this.validLink(e,t,i)?void 0:e}onClick(t){let e=this.getLink(t);if(!e)return;if(this.isTransitioning&&this.stopOnTransitioning){t.preventDefault(),t.stopPropagation();return}let i=this.getHref(e);this.emitter.emit("ANCHOR_CLICK CLICK",t),this.go({href:i,trigger:e,event:t})}getDirection(t){return Math.abs(t)>1?t>0?"forward":"back":t===0?"popstate":t>0?"back":"forward"}force(t){window.location.assign(t)}go({href:t,trigger:e="HistoryManager",event:i}){if(this.isTransitioning&&this.stopOnTransitioning){this.force(t);return}let n={x:0,y:0},o=this.HistoryManager.current,s=o.url;if(R(s,t))return;let a;if(i&&i.state){this.emitter.emit("POPSTATE",i);let{state:l}=i,{index:c}=l,m=o.index,L=m-c;e=this.getDirection(L);let d=this.HistoryManager.get(this.HistoryManager.pointer);a=d.transition,n=d.data.scroll,this.HistoryManager.replace(l.states),this.HistoryManager.pointer=c,e==="back"?this.emitter.emit("POPSTATE_BACK",i):e==="forward"&&this.emitter.emit("POPSTATE_FORWARD",i)}else{a=this.getTransitionName(e)||"default",n=x();let l=S({url:t,transition:a,data:{scroll:n}});this.HistoryManager.add(l),this.emitter.emit("HISTORY_NEW_ITEM",i)}return i&&(i.stopPropagation(),i.preventDefault()),this.emitter.emit("GO",i),this.load({oldHref:s,href:t,trigger:e,transitionName:a,scroll:n})}async load({oldHref:t,href:e,trigger:i,transitionName:n="default",scroll:o={x:0,y:0}}){try{let s=await this.PageManager.load(t);await s.build();let a;this.emitter.emit("PAGE_LOADING",{href:e,oldPage:s,trigger:i});try{try{a=await this.PageManager.load(e),await a.build(),this.transitionStart(),this.emitter.emit("PAGE_LOAD_COMPLETE",{newPage:a,oldPage:s,trigger:i})}catch(l){console.error(`[PJAX] page load error: ${l}`)}this.emitter.emit("NAVIGATION_START",{oldPage:s,newPage:a,trigger:i,transitionName:n});try{this.emitter.emit("TRANSITION_START",n);let l=await this.TransitionManager.boot(n,{oldPage:s,newPage:a,trigger:i,scroll:o});l.scrollable||(/back|popstate|forward/.test(i)||(o=N()),window.scroll(o.x,o.y)),this.emitter.emit("TRANSITION_END",{transition:l})}catch(l){console.error(`[PJAX] transition error: ${l}`)}this.emitter.emit("NAVIGATION_END",{oldPage:s,newPage:a,trigger:i,transitionName:n})}catch(l){throw this.transitionStop(),l}this.transitionStop()}catch(s){this.forceOnError?this.force(e):console.error(s)}}ignoredURL({pathname:t}){return this.ignoreURLs.length&&this.ignoreURLs.some(e=>typeof e=="string"?e===t:e.exec(t)!==null)}onHover(t){let e=this.getLink(t);if(!e)return;let i=p(this.getHref(e)),n=i.pathname;if(this.ignoredURL(i)||this.PageManager.has(n))return;this.emitter.emit("ANCHOR_HOVER HOVER",t);try{this.PageManager.load(i)}catch(o){console.warn("[PJAX] prefetch error,",o)}}onStateChange(t){this.go({href:window.location.href,trigger:"popstate",event:t})}initEvents(){this.prefetchIgnore!==!0&&(document.addEventListener("mouseover",this.onHover),document.addEventListener("touchstart",this.onHover)),document.addEventListener("click",this.onClick),window.addEventListener("popstate",this.onStateChange)}stopEvents(){this.prefetchIgnore!==!0&&(document.removeEventListener("mouseover",this.onHover),document.removeEventListener("touchstart",this.onHover)),document.removeEventListener("click",this.onClick),window.removeEventListener("popstate",this.onStateChange)}},N=(r=window.location.hash)=>{try{let t=r[0]=="#"?r:p(r).hash;if(t.length>1){let e=document.getElementById(t.slice(1));if(e)return x(e.offsetLeft,e.offsetTop)}}catch(t){console.warn("hashAction error",t)}return x(0,0)},F=class extends u{constructor(t){super();this.app=t,this.config=t.config,this.emitter=t.emitter}async boot(t,e){let i=this.get(t),n=e.scroll;if(!(e.oldPage instanceof b)||!(e.newPage instanceof b))throw`[Page] either oldPage or newPage aren't instances of the Page Class. + ${{newPage:e.newPage,oldPage:e.oldPage}}`;let o=e.oldPage.wrapper,s=e.newPage.wrapper;if(document.title=""+e.newPage.title,!(o instanceof Node)||!(s instanceof Node))throw`[Wrapper] the wrapper from the ${s instanceof Node?"current":"next"} page cannot be found. The wrapper must be an element that has the attribute ${this.config.getConfig("wrapperAttr")}.`;return i.init&&i?.init(e),this.emitter.emit("BEFORE_TRANSITION_OUT"),await new Promise(a=>{let l=i.out.call(i,{...e,from:e.oldPage,trigger:e.trigger,done:a});l.then&&l.then(a)}),this.emitter.emit("AFTER_TRANSITION_OUT"),await new Promise(a=>{o.insertAdjacentElement("beforebegin",s),this.emitter.emit("CONTENT_INSERT"),/back|popstate|forward/.test(e.trigger)||(n=N()),a()}),await new Promise(a=>{o.remove(),o=void 0,s=void 0,this.emitter.emit("CONTENT_REPLACED"),a()}),this.emitter.emit("BEFORE_TRANSITION_IN"),await new Promise(a=>{let l=i.in.call(i,{...e,from:e.oldPage,to:e.newPage,trigger:e.trigger,scroll:n,done:a});l.then&&l.then(a)}),this.emitter.emit("AFTER_TRANSITION_IN"),i}};var X=class{constructor(t={}){this.register(t)}register(t={}){this.config=t instanceof P?t:new P(t),this.emitter=new v,this.history=new k,this.pages=new O(this),this.transitions=new F(this),this.services=new H(this);let e=(()=>{document.removeEventListener("DOMContentLoaded",e),window.removeEventListener("load",e),this.emitter.emit("READY ready")}).bind(this);return document.addEventListener("DOMContentLoaded",e),window.addEventListener("load",e),this}get(t,e){switch(t.toLowerCase()){case"service":return this.services.get(e);case"transition":return this.transitions.get(e);case"state":return this.history.get(e);default:throw`Error: can't get type '${t}', it is not a recognized type. Did you spell it correctly.`}}async load(t,e){switch(t.toLowerCase()){case"page":return await this.pages.load(e);default:return Promise.resolve(this.get(t,e))}}setService(t,e){return this.services.set(t,e),this}setTransition(t,e){return this.transitions.set(t,e),this}add(t,e){switch(t.toLowerCase()){case"service":this.services.add(e);break;case"transition":this.transitions.set(e.name,e);break;case"state":this.history.add(e);break;default:throw`Error: can't add type '${t}', it is not a recognized type. Did you spell it correctly.`}return this}boot(){return this.services.init(),this.services.boot(),this}stop(){return this.services.stop(),this}on(t,e){return this.emitter.on(t,e,this),this}off(t,e){return this.emitter.off(t,e,this),this}emit(t,...e){return this.emitter.emit(t,...e),this}};var Q=class extends I{constructor(t=[]){super();this.routes=new u;for(let e of t)this.add(e)}add({path:t,method:e}){let i=this.parse(t);return this.routes.set(i,e),this}parsePath(t){if(typeof t=="string")return new RegExp(t,"i");if(t instanceof RegExp||typeof t=="boolean")return t;throw"[Router] only regular expressions, strings and booleans are accepted as paths."}isPath(t){return typeof t=="string"||t instanceof RegExp||typeof t=="boolean"}parse(t){let e=t,i={from:/(.*)/g,to:/(.*)/g};if(this.isPath(t))i={from:!0,to:t};else if(this.isPath(e.from)&&this.isPath(e.to))i=e;else throw"[Router] path is neither a string, regular expression, or a { from, to } object.";let{from:n,to:o}=i;return{from:this.parsePath(n),to:this.parsePath(o)}}route(){let t=this.HistoryManager,e=h(p((t.length>1?t.previous:t.current).url)),i=h(p());this.routes.forEach((n,o)=>{let s=o.from,a=o.to;if(typeof s=="boolean"&&typeof a=="boolean")throw`[Router] path ({ from: ${s}, to: ${a} }) is not valid, remember paths can only be strings, regular expressions, or a boolean; however, both the from and to paths cannot be both booleans.`;let l=s,c=a;s instanceof RegExp&&s.test(e)&&(l=s.exec(e)),a instanceof RegExp&&a.test(i)&&(c=a.exec(i)),(Array.isArray(c)&&Array.isArray(l)||Array.isArray(c)&&typeof l=="boolean"&&l||Array.isArray(l)&&typeof c=="boolean"&&c)&&n({from:l,to:c,path:{from:e,to:i}})})}initEvents(){this.emitter.on("READY",this.route,this),this.emitter.on("CONTENT_REPLACED",this.route,this)}stopEvents(){this.emitter.off("READY",this.route,this),this.emitter.off("CONTENT_REPLACED",this.route,this)}};var Z=r=>typeof r=="string"?Array.from(document.querySelectorAll(r)):[r],tt=r=>Array.isArray(r)?r:typeof r=="string"||r instanceof Node?Z(r):r instanceof NodeList||r instanceof HTMLCollection?Array.from(r):[],z=(r,t)=>typeof r=="function"?r(...t):r,U=(r,t)=>{let e,i,n={},o=Object.keys(r);for(let s=0,a=o.length;s/^(ease|in|out)/.test(r)?et[r]:r,rt={keyframes:[],loop:1,delay:0,speed:1,endDelay:0,easing:"ease",autoplay:!0,duration:1e3,onfinish(){},fillMode:"auto",direction:"normal"},V=class{constructor(t={}){this.options={};this.targets=[];this.properties={};this.animations=new Map;this.duration=0;this.emitter=new v;let{options:e,...i}=t;this.options=Object.assign({},rt,e,i),this.loop=this.loop.bind(this);let{loop:n,delay:o,speed:s,easing:a,endDelay:l,duration:c,direction:m,fillMode:L,onfinish:d,target:K,keyframes:nt,autoplay:ot,...st}=this.options;this.mainElement=document.createElement("span"),this.targets=tt(K),this.properties=st;let C;for(let g=0,M=this.targets.length;g0||(C=U(C,[g,M,y]));let G=f.delay+f.duration*f.iterations+f.endDelay;this.duration{d(y,g,M)},this.animations.set(y,q)}this.mainAnimation=this.mainElement.animate([{opacity:"0"},{opacity:"1"}],{duration:this.duration,easing:"linear"}),this.setSpeed(s),ot?this.play():this.pause(),this.promise=this.newPromise(),this.mainAnimation.onfinish=()=>{this.finish(this.options),window.cancelAnimationFrame(this.animationFrame)}}getTargets(){return this.targets}newPromise(){return new Promise((t,e)=>{try{this.finish=i=>(this.emit("finish",i),t(i))}catch(i){e(i)}})}then(t,e){return this.promise.then(t,e)}catch(t){return this.promise.catch(t)}finally(t){return this.promise.finally(t)}loop(){this.animationFrame=window.requestAnimationFrame(this.loop),this.emit("tick change",this.getCurrentTime())}on(t,e,i){return this.emitter.on(t,e,i),this}off(t,e,i){return this.emitter.off(t,e,i),this}emit(t,...e){return this.emitter.emit(t,...e),this}getAnimation(t){return this.animations.get(t)}play(){return this.mainAnimation.playState!=="finished"&&(this.mainAnimation.play(),this.animationFrame=requestAnimationFrame(this.loop),this.animations.forEach(t=>{t.playState!=="finished"&&t.play()}),this.emit("play")),this}pause(){return this.mainAnimation.playState!=="finished"&&(this.mainAnimation.pause(),window.cancelAnimationFrame(this.animationFrame),this.animations.forEach(t=>{t.playState!=="finished"&&t.pause()}),this.emit("pause")),this}getDuration(){return this.duration}getCurrentTime(){return this.mainAnimation.currentTime}setCurrentTime(t){return this.mainAnimation.currentTime=t,this.animations.forEach(e=>{e.currentTime=t}),this}getProgress(){return this.getCurrentTime()/this.duration}setProgress(t){return this.mainAnimation.currentTime=t*this.duration,this.animations.forEach(e=>{e.currentTime=t*this.duration}),this}getSpeed(){return this.mainAnimation.playbackRate}setSpeed(t=1){return this.mainAnimation.playbackRate=t,this.animations.forEach(e=>{e.playbackRate=t}),this}reset(){this.setCurrentTime(0),this.promise=this.newPromise(),this.options.autoplay?this.play():this.pause()}getPlayState(){return this.mainAnimation.playState}getOptions(){return this.options}toJSON(){return this.getOptions()}},lt=(r={})=>new V(r);export{w as AdvancedManager,V as Animate,X as App,P as CONFIG,$ as CONFIG_DEFAULTS,rt as DefaultAnimationOptions,T as Event,v as EventEmitter,k as HistoryManager,u as Manager,E as ManagerItem,Y as PARSER,J as PJAX,b as Page,O as PageManager,Q as Router,I as Service,H as ServiceManager,F as TransitionManager,lt as animate,B as asyncMethodCall,W as changeState,_ as clean,z as computeValue,et as easings,R as equal,it as getEase,Z as getElements,at as getHash,h as getHashedPath,tt as getTargets,N as hashAction,U as mapObject,A as methodCall,x as newCoords,j as newListener,S as newState,p as newURL}; //# sourceMappingURL=api.modern.js.map diff --git a/packages/native/lib/api.modern.js.map b/packages/native/lib/api.modern.js.map index 7751b02..ad2dd84 100644 --- a/packages/native/lib/api.modern.js.map +++ b/packages/native/lib/api.modern.js.map @@ -1,7 +1,7 @@ { "version": 3, - "sources": ["../src/config.ts", "../../manager/src/api.ts", "../src/manager.ts", "../src/url.ts", "../src/history.ts", "../src/page.ts", "../../emitter/src/api.ts", "../src/service.ts", "../src/transition.ts", "../src/app.ts", "../src/pjax.ts", "../src/route.ts", "../../animate/src/api.ts"], - "sourcesContent": ["// The config variables\r\nexport interface ICONFIG {\r\n prefix?: string;\r\n wrapperAttr?: string;\r\n noAjaxLinkAttr?: string;\r\n noPrefetchAttr?: \"no-prefetch\";\r\n headers?: string[][];\r\n preventSelfAttr?: string;\r\n preventAllAttr?: string;\r\n transitionAttr?: string;\r\n blockAttr?: string;\r\n timeout?: number\r\n}\r\n\r\nexport const CONFIG_DEFAULTS: ICONFIG = {\r\n wrapperAttr: \"wrapper\",\r\n noAjaxLinkAttr: \"no-ajax-link\",\r\n noPrefetchAttr: \"no-prefetch\",\r\n headers: [\r\n [\"x-partial\", \"true\"]\r\n ],\r\n preventSelfAttr: `prevent=\"self\"`,\r\n preventAllAttr: `prevent=\"all\"`,\r\n transitionAttr: \"transition\",\r\n blockAttr: `block`,\r\n timeout: 30000\r\n};\r\n\r\nexport type ConfigKeys = keyof ICONFIG;\r\n\r\n/**\r\n * The Config class\r\n *\r\n * @export\r\n * @class CONFIG\r\n */\r\nexport class CONFIG {\r\n /**\r\n * The current Configuration\r\n *\r\n * @public\r\n * @type ICONFIG\r\n * @memberof CONFIG\r\n */\r\n public config: ICONFIG;\r\n\r\n /**\r\n * Creates an instance of CONFIG.\r\n *\r\n * @param {ICONFIG} config\r\n * @memberof CONFIG\r\n */\r\n constructor(config: ICONFIG) {\r\n this.config = Object.assign({ ...CONFIG_DEFAULTS }, config);\r\n }\r\n\r\n /**\r\n * Converts string into data attributes\r\n *\r\n * @param {string} value\r\n * @param {boolean} brackets [brackets=true]\r\n * @returns string\r\n * @memberof CONFIG\r\n */\r\n public toAttr(value: string, brackets: boolean = true): string {\r\n let { prefix } = this.config;\r\n let attr = `data${prefix ? \"-\" + prefix : \"\"}-${value}`;\r\n return brackets ? `[${attr}]` : attr;\r\n }\r\n\r\n /**\r\n * Selects config vars, and formats them for use, or simply returns the current configurations for the framework\r\n *\r\n * @param {ConfigKeys} value\r\n * @param {boolean} [brackets=true]\r\n * @returns any\r\n * @memberof CONFIG\r\n */\r\n public getConfig(value?: ConfigKeys, brackets: boolean = true): any {\r\n if (typeof value !== \"string\")\r\n return this.config;\r\n\r\n let config = this.config[value];\r\n if (typeof config === \"string\")\r\n return this.toAttr(config, brackets);\r\n return config;\r\n }\r\n}\r\n", "/**\r\n * Manages complex lists of named data, eg. A page can be stored in a list by of other pages with the url being how the page is stored in the list. Managers use Maps to store data.\r\n *\r\n * @export\r\n * @class Manager\r\n * @template K\r\n * @template V\r\n */\r\nexport class Manager {\r\n\t/**\r\n\t * The complex list of named data, to which the Manager controls\r\n\t *\r\n\t * @public\r\n\t * @type Map\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic map: Map;\r\n\r\n\t/**\r\n\t * Creates an instance of Manager.\r\n\t *\r\n\t * @param {Array<[K, V]>} [value]\r\n\t * @memberof Manager\r\n\t */\r\n\tconstructor(value?: Array<[K, V]>) {\r\n\t\tthis.map = new Map(value);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the Manager class's list\r\n\t *\r\n\t * @returns Map\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic getMap(): Map {\r\n\t\treturn this.map;\r\n\t}\r\n\r\n\t/**\r\n\t * Get a value stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key to find in the Manager's list\r\n\t * @returns V\r\n\t */\r\n\tpublic get(key: K): V {\r\n\t\treturn this.map.get(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the keys of all items stored in the Manager as an Array\r\n\t *\r\n\t * @returns Array\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic keys(): Array {\r\n\t\treturn Array.from(this.map.keys());\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the values of all items stored in the Manager as an Array\r\n\t *\r\n\t * @returns Array\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic values(): Array {\r\n\t\treturn Array.from(this.map.values());\r\n\t}\r\n\r\n\t/**\r\n\t * Set a value stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key where the value will be stored\r\n\t * @param {V} value - The value to store\r\n\t * @returns Manager\r\n\t */\r\n\tpublic set(key: K, value: V): Manager {\r\n\t\tthis.map.set(key, value);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Adds a value to Manager, and uses the current size of the Manager as it's key, it works best when all the key in the Manager are numbers\r\n\t *\r\n\t * @public\r\n\t * @param {V} value\r\n\t * @returns Manager\r\n\t */\r\n\tpublic add(value: V): Manager {\r\n\t\tlet size = this.size;\r\n\t\t// @ts-ignore\r\n\t\tlet num: K = size as K;\r\n\t\tthis.set(num, value);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the total number of items stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @returns Number\r\n\t */\r\n\tpublic get size(): number {\r\n\t\treturn this.map.size;\r\n\t}\r\n\r\n\tpublic get length(): number {\r\n\t\treturn this.map.size;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the last item in the Manager who's index is a certain distance from the last item in the Manager\r\n\t *\r\n\t * @param {number} [distance=1]\r\n\t * @returns V | undefined\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic last(distance: number = 1): V | undefined {\r\n\t\tlet key = this.keys()[this.size - distance];\r\n\t\treturn this.get(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Removes a value stored in the Manager, via the key, returns true if an element in the Map object existed and has been removed, or false if the element does not exist.\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key for the key value pair to be removed\r\n\t * @returns boolean\r\n\t */\r\n\tpublic delete(key: K): boolean {\r\n\t\treturn this.map.delete(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Removes a value stored in the Manager, via the key, returns the Manager class, allowing for chains\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key for the key value pair to be removed\r\n\t * @returns Manager\r\n\t */\r\n\tpublic remove(key: K): Manager {\r\n\t\tthis.map.delete(key);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Clear the Manager of all its contents\r\n\t *\r\n\t * @public\r\n\t * @returns Manager\r\n\t */\r\n\tpublic clear(): Manager {\r\n\t\tthis.map.clear();\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Checks if the Manager contains a certain key\r\n\t *\r\n\t * @public\r\n\t * @param {K} key\r\n\t * @returns boolean\r\n\t */\r\n\tpublic has(key: K): boolean {\r\n\t\treturn this.map.has(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a new Iterator object that contains an array of [key, value] for each element in the Map object in insertion order.\r\n\t *\r\n\t * @public\r\n\t * @returns IterableIterator<[K, V]>\r\n\t */\r\n\tpublic entries(): IterableIterator<[K, V]> {\r\n\t\treturn this.map.entries();\r\n\t}\r\n\r\n\t/**\r\n\t * Iterates through the Managers contents, calling a callback function every iteration\r\n\t *\r\n\t * @param {*} [callback=(...args: any): void => { }]\r\n\t * @param {object} context\r\n\t * @returns Manager\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic forEach(\r\n\t\tcallback: any = (...args: any): void => { },\r\n\t\tcontext?: object\r\n\t): Manager {\r\n\t\tthis.map.forEach(callback, context);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Allows iteration via the for..of, learn more: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators]\r\n\t *\r\n\t * @returns IterableIterator<[K, V]>\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic [Symbol.iterator](): IterableIterator<[K, V]> {\r\n\t\treturn this.entries();\r\n\t}\r\n}\r\n\r\n/**\r\n * Calls the method of a certain name for all items that are currently installed\r\n *\r\n * @param {Manager} manager\r\n * @param {string} method\r\n * @param {Array} [args=[]]\r\n */\r\nexport const methodCall = (manager: Manager, method: string, ...args: any): void => {\r\n\tmanager.forEach((item) => {\r\n\t\t// @ts-ignore\r\n\t\titem[method](...args);\r\n\t});\r\n};\r\n\r\n/**\r\n * Asynchronously calls the method of a certain name for all items that are currently installed, similar to methodCall\r\n *\r\n * @param {Manager} manager\r\n * @param {string} method\r\n * @param {Array} [args=[]]\r\n */\r\nexport const asyncMethodCall = async (manager: Manager, method: string, ...args: any): Promise => {\r\n\tfor (let [, item] of manager) {\r\n\t\t// @ts-ignore\r\n\t\tawait item[method](...args);\r\n\t}\r\n};\r\n\r\nexport default Manager;\r\n", "import { Manager, methodCall, asyncMethodCall } from \"@okikio/manager\";\r\nimport { CONFIG } from \"./config\";\r\nimport { App } from \"./app\";\r\nimport EventEmitter from \"@okikio/emitter\";\r\n\r\nexport type IAdvancedManager = AdvancedManager;\r\n\r\n/**\r\n * The base class for all AdvancedManager and AdvancedStorage items\r\n *\r\n * @export\r\n * @class ManagerItem\r\n */\r\nexport class ManagerItem {\r\n /**\r\n * The AdvancedManager the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type IAdvancedManager\r\n * @memberof ManagerItem\r\n */\r\n public manager: IAdvancedManager;\r\n\r\n /**\r\n * The App the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type App\r\n * @memberof ManagerItem\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof ManagerItem\r\n */\r\n public config: CONFIG;\r\n public emitter: EventEmitter;\r\n public key: any;\r\n\r\n /**\r\n * Creates an instance of ManagerItem.\r\n *\r\n * @memberof ManagerItem\r\n */\r\n constructor() { }\r\n\r\n /**\r\n * Run after the Manager Item has been registered\r\n *\r\n * @returns any\r\n * @memberof ManagerItem\r\n */\r\n public install(): any { }\r\n\r\n /**\r\n * Register the current Manager Item's manager\r\n *\r\n * @param {IAdvancedManager} manager\r\n * @returns ManagerItem\r\n * @memberof ManagerItem\r\n */\r\n public register(manager: IAdvancedManager, key: any): ManagerItem {\r\n this.manager = manager;\r\n this.app = manager.app;\r\n this.config = manager.config;\r\n this.emitter = manager.emitter;\r\n this.key = key;\r\n this.install();\r\n return this;\r\n }\r\n\r\n public uninstall(): any { }\r\n\r\n public unregister() {\r\n this.uninstall();\r\n\r\n this.manager.delete(this.key);\r\n this.key = undefined;\r\n this.manager = undefined;\r\n this.app = undefined;\r\n this.config = undefined;\r\n this.emitter = undefined;\r\n }\r\n}\r\n\r\n/**\r\n * A tweak to the Manager class that makes it self aware of the App class it's instantiated in\r\n *\r\n * @export\r\n * @class AdvancedManager\r\n * @extends {Manager}\r\n * @template K\r\n * @template V\r\n */\r\nexport class AdvancedManager extends Manager {\r\n /**\r\n * The instance of the App class, the Manager is instantiated in\r\n *\r\n * @type App\r\n * @memberof AdvancedManager\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof AdvancedManager\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * The EventEmitter class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof AdvancedManager\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * Creates an instance of AdvancedManager.\r\n *\r\n * @param {App} app - The instance of the App class, the Manager is instantiated in\r\n * @memberof AdvancedManager\r\n */\r\n constructor(app: App) {\r\n super();\r\n this.app = app;\r\n this.config = app.config;\r\n this.emitter = app.emitter;\r\n }\r\n\r\n /**\r\n * Set a value stored in the Manager\r\n *\r\n * @public\r\n * @param {K} key - The key where the value will be stored\r\n * @param {V} value - The value to store\r\n * @returns AdvancedManager\r\n */\r\n public set(key: K, value: V) {\r\n super.set(key, value);\r\n value.register(this, key);\r\n return this;\r\n }\r\n}\r\n\r\nexport { Manager, methodCall, asyncMethodCall };\r\n", "/**\r\n * Adds new methods to the native URL Object; it seemed cleaner than using a custom method or editing the prototype.\r\n *\r\n * This doesn't extend the **Class** object because it's meant to be a small extension of the native URL class.\r\n *\r\n * @export\r\n * @class URL\r\n * @extends {URL}\r\n */\r\n// Read up on the native URL class [devdocs.io/dom/url]\r\n/**\r\n * Creates an instance of URL.\r\n *\r\n * @param {(string | URL | Location)} [url=window.location.pathname]\r\n * @return URL\r\n */\r\nexport const newURL = (url: string | URL | Location = window.location.href): URL => {\r\n return url instanceof URL ? url : new URL(url as unknown as string, window.location.origin);\r\n};\r\n\r\n/**\r\n * Returns the pathname with the hash\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const getHashedPath = (url: URL): string => (`${url.pathname}${url.hash}`);\r\n\r\n/**\r\n * Returns the actual hash without the hashtag\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const getHash = (url: URL): string => (url.hash.slice(1));\r\n\r\n/**\r\n * Removes the hash from the full URL for a clean URL string\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const clean = (url: URL): string => (url.toString().replace(/(\\/#.*|\\/|#.*)$/, ''));\r\n\r\n/**\r\n * Compares two URLs to each other\r\n *\r\n * @param {URL} a\r\n * @param {URL} b\r\n * @returns boolean\r\n */\r\nexport const equal = (a: URL | string, b: URL | string): boolean => {\r\n let urlA = newURL(a);\r\n let urlB = newURL(b);\r\n return clean(urlA) === clean(urlB);\r\n};\r\n", "import { getHashedPath, newURL } from \"./url\";\r\n\r\nexport type Trigger = HTMLAnchorElement | \"HistoryManager\" | \"popstate\" | \"back\" | \"forward\";\r\nexport interface ICoords {\r\n\treadonly x: number;\r\n\treadonly y: number;\r\n}\r\n\r\nexport interface IStateData {\r\n\tscroll: ICoords;\r\n\t[key: string]: any;\r\n}\r\n\r\nexport interface IState {\r\n\turl: string;\r\n\tindex?: number;\r\n\ttransition: string;\r\n\tdata: IStateData;\r\n}\r\n\r\nexport interface IHistoryItem {\r\n\tindex: number;\r\n\tstates: IState[];\r\n}\r\n\r\n/**\r\n * A quick snapshot of page coordinates, e.g. scroll positions\r\n *\r\n * @export\r\n * @param {number} [x=window.scrollX]\r\n * @param {number} [y=window.scrollY]\r\n */\r\nexport const newCoords = (x: number = window.scrollX, y: number = window.scrollY): ICoords => ({ x, y });\r\n\r\n/**\r\n * Represents the current status of the page consisting of properties like: url, transition, and data\r\n *\r\n * @export\r\n * @param {IState} {\r\n * url = getHashedPath(newURL()),\r\n * index = 0,\r\n * transition = \"default\",\r\n * data = {\r\n * scroll: newCoords(),\r\n * trigger: \"HistoryManager\"\r\n * }\r\n * }\r\n * @memberof State\r\n*/\r\nexport const newState = (state: IState = {\r\n\turl: getHashedPath(newURL()),\r\n\tindex: 0,\r\n\ttransition: \"default\",\r\n\tdata: {\r\n\t\tscroll: newCoords(),\r\n\t\ttrigger: \"HistoryManager\"\r\n\t}\r\n}): IState => (state);\r\n\r\n\r\n/**\r\n * History of the site, stores only the State class\r\n *\r\n * @export\r\n * @class HistoryManager\r\n * @extends {Manager}\r\n */\r\nexport class HistoryManager {\r\n\tpublic states: IState[];\r\n\tpublic pointer = -1;\r\n\r\n\t/**\r\n\t * Creates an instance of the HistoryManager class, which inherits properties and methods from the Storage class.\r\n\t *\r\n\t * @memberof HistoryManager\r\n\t * @constructor\r\n\t */\r\n\tconstructor() {\r\n\t\tthis.states = [];\r\n\r\n\t\tlet state = newState();\r\n\t\tthis.add(state, \"replace\");\r\n\t}\r\n\r\n\tpublic get(index: number) {\r\n\t\treturn this.states[index];\r\n\t}\r\n\r\n\t/**\r\n\t * Sets the index of the state before adding to HistoryManager\r\n\t *\r\n\t * @param {IState} value\r\n\t * @returns HistoryManager\r\n\t */\r\n\tpublic add(value?: IState, historyAction: \"replace\" | \"push\" = \"push\"): HistoryManager {\r\n\t\tlet state = newState(value);\r\n\t\tlet len = this.length;\r\n\t\tthis.states.push({ ...state });\r\n\t\tthis.pointer = len;\r\n\r\n\t\tlet item: IHistoryItem = {\r\n\t\t\tindex: this.pointer,\r\n\t\t\tstates: [...this.states]\r\n\t\t};\r\n\t\tthis.changeState(historyAction, state, item);\r\n\t\treturn this;\r\n\t}\r\n\r\n\tpublic remove(index?: number) {\r\n\t\tif (index) {\r\n\t\t\tthis.states.splice(index, 1);\r\n\t\t} else {\r\n\t\t\tthis.states.pop();\r\n\t\t}\r\n\r\n\t\tthis.pointer--;\r\n\t\treturn this;\r\n\t}\r\n\r\n\tpublic replace(newStates: IState[]) {\r\n\t\tthis.states = newStates;\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Set state by index.\r\n\t */\r\n\tpublic set(i: number, state: IState) {\r\n\t\treturn (this.states[i] = state);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the current state.\r\n\t */\r\n\tget current(): IState {\r\n\t\treturn this.get(this.pointer);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the last state (top of the history stack).\r\n\t */\r\n\tget last(): IState {\r\n\t\treturn this.get(this.length - 1);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the previous state.\r\n\t */\r\n\tget previous(): IState | null {\r\n\t\treturn this.pointer < 1 ? null : this.get(this.pointer - 1);\r\n\t}\r\n\r\n\tget length() {\r\n\t\treturn this.states.length;\r\n\t}\r\n\r\n\t/**\r\n\t * Either push or replace history state\r\n\t *\r\n\t * @param {(\"push\" | \"replace\")} action\r\n\t * @param {IState} state\r\n\t * @param {_URL} url\r\n\t * @memberof PJAX\r\n\t */\r\n\tpublic changeState(action: \"push\" | \"replace\", state: IState, item: object) {\r\n\t\tlet href = getHashedPath(newURL(state.url));\r\n\t\tlet args = [item, \"\", href];\r\n\t\tif (window.history) {\r\n\t\t\tswitch (action) {\r\n\t\t\t\tcase \"push\":\r\n\t\t\t\t\twindow.history.pushState.apply(window.history, args);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"replace\":\r\n\t\t\t\t\twindow.history.replaceState.apply(window.history, args);\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n", "import { Manager, ManagerItem, AdvancedManager } from \"./manager\";\r\nimport { equal, newURL } from \"./url\";\r\nimport { App } from \"./app\";\r\n\r\n/**\r\n * Parses strings to DOM\r\n */\r\nexport const PARSER: DOMParser = new DOMParser();\r\n\r\n/**\r\n * A page represents the DOM elements that create each page\r\n *\r\n * @export\r\n * @class Page\r\n */\r\nexport class Page extends ManagerItem {\r\n /**\r\n * Holds the DOM of the current page\r\n *\r\n * @public\r\n * @type Document\r\n * @memberof Page\r\n */\r\n public dom: Document;\r\n\r\n /**\r\n * Holds the wrapper element to be swapped out of each Page\r\n *\r\n * @public\r\n * @type HTMLElement\r\n * @memberof Page\r\n */\r\n public wrapper: HTMLElement;\r\n\r\n /**\r\n * Holds the title of each page\r\n *\r\n * @public\r\n * @type string\r\n * @memberof Page\r\n */\r\n public title: string;\r\n\r\n /**\r\n * Holds the head element of each page\r\n *\r\n * @public\r\n * @type Element\r\n * @memberof Page\r\n */\r\n public head: Element;\r\n\r\n /**\r\n * Holds the body element of each page\r\n *\r\n * @public\r\n * @type Element\r\n * @memberof Page\r\n */\r\n public body: Element;\r\n\r\n /**\r\n * The URL of the current page\r\n *\r\n * @public\r\n * @type URL\r\n * @memberof Page\r\n */\r\n public url: URL;\r\n public data: string;\r\n public wrapperAttr: string;\r\n\r\n /**\r\n * Creates an instance of Page, it also creates a new page from response text, or a Document Object\r\n *\r\n * @param {URL} [url = newURL()]\r\n * @param {(string | Document)} [dom=document]\r\n * @memberof Page\r\n */\r\n constructor(url: URL = newURL(), dom: string | Document = document) {\r\n super();\r\n this.url = url;\r\n\r\n if (typeof dom === \"string\") {\r\n this.data = dom;\r\n } else this.dom = dom || document;\r\n }\r\n\r\n public async build() {\r\n if (!(this.dom instanceof Node)) {\r\n this.dom = PARSER.parseFromString(this.data, \"text/html\");\r\n }\r\n\r\n if (!(this.body instanceof Node)) {\r\n let { title, head, body } = this.dom;\r\n this.title = title;\r\n this.head = head;\r\n this.body = body;\r\n this.wrapper = this.body.querySelector(this.wrapperAttr);\r\n }\r\n }\r\n\r\n /**\r\n * Runs once the the manager and config have been registered\r\n *\r\n * @returns void\r\n * @memberof Page\r\n */\r\n public install(): void {\r\n this.wrapperAttr = this.config.getConfig(\"wrapperAttr\");\r\n }\r\n\r\n public uninstall() {\r\n this.url = undefined;\r\n this.title = undefined;\r\n this.head = undefined;\r\n this.body = undefined;\r\n this.dom = undefined;\r\n this.wrapper = undefined;\r\n this.data = undefined;\r\n this.wrapperAttr = undefined;\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Controls which page to be load\r\n *\r\n * @export\r\n * @class PageManager\r\n * @extends {AdvancedManager}\r\n */\r\nexport class PageManager extends AdvancedManager {\r\n /**\r\n * Stores all URLs that are currently loading\r\n *\r\n * @public\r\n * @type Manager>\r\n * @memberof PageManager\r\n */\r\n public loading: Manager> = new Manager();\r\n public maxPages = 5;\r\n\r\n /**\r\n * Creates an instance of the PageManager\r\n *\r\n * @param {App} app\r\n * @memberof PageManager\r\n */\r\n constructor(app: App) {\r\n super(app);\r\n let URLString = newURL().pathname;\r\n this.set(URLString, new Page());\r\n URLString = undefined;\r\n }\r\n\r\n /**\r\n * Load from cache or by requesting URL via a fetch request, avoid requesting for the same thing twice by storing the fetch request in \"this.loading\"\r\n *\r\n * @param {(URL | string)} [_url=newURL()]\r\n * @returns Promise\r\n * @memberof PageManager\r\n */\r\n public async load(_url: URL | string = newURL()): Promise {\r\n let url: URL = newURL(_url);\r\n let urlString: string = url.pathname;\r\n let page: Page, request: Promise;\r\n if (this.has(urlString)) {\r\n page = this.get(urlString);\r\n return Promise.resolve(page);\r\n }\r\n\r\n if (!this.loading.has(urlString)) {\r\n request = this.request(urlString);\r\n this.loading.set(urlString, request);\r\n } else request = this.loading.get(urlString);\r\n\r\n let response = await request;\r\n this.loading.delete(urlString);\r\n\r\n page = new Page(url, response);\r\n this.set(urlString, page);\r\n\r\n if (this.size > this.maxPages) {\r\n let currentUrl = newURL();\r\n let keys = this.keys();\r\n let first = equal(currentUrl, keys[0]) ? keys[1] : keys[0];\r\n let page = this.get(first);\r\n page.unregister();\r\n page = undefined;\r\n keys = undefined;\r\n currentUrl = undefined;\r\n first = undefined;\r\n }\r\n return page;\r\n }\r\n\r\n /**\r\n * Starts a fetch request\r\n *\r\n * @param {string} url\r\n * @returns Promise\r\n * @memberof PageManager\r\n */\r\n public async request(url: string): Promise {\r\n const headers = new Headers(this.config.getConfig(\"headers\"));\r\n const timeout = window.setTimeout(() => {\r\n window.clearTimeout(timeout);\r\n throw \"Request Timed Out!\";\r\n }, this.config.getConfig(\"timeout\"));\r\n\r\n try {\r\n let response = await fetch(url, {\r\n mode: 'same-origin',\r\n method: \"GET\",\r\n headers,\r\n cache: \"default\",\r\n credentials: \"same-origin\",\r\n });\r\n\r\n window.clearTimeout(timeout);\r\n if (response.status >= 200 && response.status < 300) {\r\n return await response.text();\r\n }\r\n\r\n const err = new Error(response.statusText || \"\" + response.status);\r\n throw err;\r\n } catch (err) {\r\n window.clearTimeout(timeout);\r\n throw err;\r\n }\r\n }\r\n}\r\n", "import { Manager } from \"@okikio/manager\";\r\n\r\nexport type ListenerCallback = ((...args: any) => void);\r\nexport interface IListener {\r\n readonly callback: ListenerCallback;\r\n readonly scope: object;\r\n readonly name: string;\r\n}\r\n\r\n/**\r\n * Represents a new event listener consisting of properties like: callback, scope, name\r\n *\r\n * @export\r\n */\r\nexport const newListener = ({\r\n callback = () => { },\r\n scope = null,\r\n name = \"event\",\r\n}: IListener): IListener => ({ callback, scope, name });\r\n\r\n/**\r\n * Represents a new event listener consisting of properties like: callback, scope, name\r\n *\r\n * @export\r\n * @class Event\r\n * @extends {Manager}\r\n */\r\nexport class Event extends Manager {\r\n /**\r\n * The name of the event\r\n *\r\n * @public\r\n * @type string\r\n * @memberof Event\r\n */\r\n public name: string;\r\n\r\n /**\r\n * Creates an instance of Event.\r\n *\r\n * @param {string} [name=\"event\"]\r\n * @memberof Event\r\n */\r\n constructor(name: string = \"event\") {\r\n super();\r\n this.name = name;\r\n }\r\n}\r\n\r\nexport type EventInput = string | object | Array;\r\n\r\n/**\r\n * An event emitter\r\n *\r\n * @export\r\n * @class EventEmitter\r\n * @extends {Manager}\r\n */\r\nexport class EventEmitter extends Manager {\r\n /**\r\n * Creates an instance of EventEmitter.\r\n *\r\n * @memberof EventEmitter\r\n */\r\n constructor() {\r\n super();\r\n }\r\n\r\n /**\r\n * Gets events, if event doesn't exist create a new Event\r\n *\r\n * @param {string} name\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public getEvent(name: string): Event {\r\n let event = this.get(name);\r\n if (!(event instanceof Event)) {\r\n this.set(name, new Event(name));\r\n return this.get(name);\r\n }\r\n\r\n return event;\r\n }\r\n /**\r\n * Creates a new listener and adds it to the event\r\n *\r\n * @param {string} name\r\n * @param {ListenerCallback} callback\r\n * @param {object} scope\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public newListener(\r\n name: string,\r\n callback: ListenerCallback,\r\n scope: object\r\n ): Event {\r\n let event = this.getEvent(name);\r\n event.add(newListener({ name, callback, scope }));\r\n return event;\r\n }\r\n\r\n /**\r\n * Adds a listener for a given event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback | object} callback\r\n * @param {object} scope\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public on(\r\n events: EventInput,\r\n callback?: ListenerCallback | object,\r\n scope?: object\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n let _name: string;\r\n let _callback: ListenerCallback;\r\n let isObject = typeof events == \"object\" && !Array.isArray(events);\r\n\r\n let _scope: object = isObject ? callback : scope;\r\n if (!isObject) _callback = (callback as ListenerCallback);\r\n\r\n // Loop through the list of events\r\n Object.keys(events).forEach(key => {\r\n // Select the name of the event from the list\r\n // Remember events can be {String | Object | Array}\r\n\r\n // Check If events is an Object (JSON like Object, and not an Array)\r\n if (isObject) {\r\n _name = key;\r\n _callback = events[key];\r\n } else {\r\n _name = events[key];\r\n }\r\n\r\n this.newListener(_name, _callback, _scope);\r\n }, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes a listener from an event\r\n *\r\n * @param {string} name\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public removeListener(\r\n name: string,\r\n callback: ListenerCallback,\r\n scope: object\r\n ): Event {\r\n let event: Event = this.get(name);\r\n if (event instanceof Event && callback) {\r\n let listener = newListener({ name, callback, scope });\r\n\r\n event.forEach((value: IListener, i: number) => {\r\n if (\r\n value.callback === listener.callback &&\r\n value.scope === listener.scope\r\n ) {\r\n return event.delete(i);\r\n }\r\n });\r\n }\r\n\r\n return event;\r\n }\r\n\r\n /**\r\n * Removes a listener from a given event, or it just completely removes an event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback | object} [callback]\r\n * @param {object} [scope]\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public off(\r\n events: EventInput,\r\n callback?: ListenerCallback | object,\r\n scope?: object\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n let _name: string;\r\n let _callback: ListenerCallback;\r\n let isObject = typeof events == \"object\" && !Array.isArray(events);\r\n\r\n let _scope: object = isObject ? callback : scope;\r\n if (!isObject) _callback = (callback as ListenerCallback);\r\n\r\n // Loop through the list of events\r\n Object.keys(events).forEach(key => {\r\n // Select the name of the event from the list\r\n // Remember events can be {String | Object | Array}\r\n\r\n // Check If events is an Object (JSON like Object, and not an Array)\r\n if (isObject) {\r\n _name = key;\r\n _callback = events[key];\r\n } else {\r\n _name = events[key];\r\n }\r\n\r\n if (typeof _callback === \"function\") {\r\n this.removeListener(_name, _callback, _scope);\r\n } else this.delete(_name);\r\n }, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Call all listeners within an event\r\n *\r\n * @param {(string | Array)} events\r\n * @param {...any} args\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public emit(\r\n events: string | Array,\r\n ...args: any\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n // Loop through the list of events\r\n events.forEach((event: string) => {\r\n let _event: Event = this.get(event);\r\n\r\n if (_event instanceof Event) {\r\n _event.forEach((listener: IListener) => {\r\n let { callback, scope } = listener;\r\n callback.apply(scope, args);\r\n });\r\n }\r\n }, this);\r\n return this;\r\n }\r\n}\r\n\r\nexport default EventEmitter;\r\n", "import { AdvancedManager, ManagerItem, methodCall } from \"./manager\";\r\nimport { TransitionManager } from \"./transition\";\r\nimport { HistoryManager } from \"./history\";\r\nimport { EventEmitter } from \"./emitter\";\r\nimport { PageManager } from \"./page\";\r\nimport { App } from \"./app\";\r\n\r\n/**\r\n * Controls specific kinds of actions that require JS\r\n *\r\n * @export\r\n * @class Service\r\n */\r\nexport class Service extends ManagerItem {\r\n\t/**\r\n\t * Stores access to the App class's EventEmitter\r\n\t *\r\n\t * @public\r\n\t * @type EventEmitter\r\n\t * @memberof Service\r\n\t */\r\n\tpublic emitter: EventEmitter;\r\n\r\n\t/**\r\n\t * Stores access to the App class's PageManager\r\n\t *\r\n\t * @public\r\n\t * @type PageManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic PageManager: PageManager;\r\n\r\n\t/**\r\n\t * Stores access to the App class's HistoryManager\r\n\t *\r\n\t * @public\r\n\t * @type HistoryManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic HistoryManager: HistoryManager;\r\n\r\n\t/**\r\n\t * Stores the ServiceManager the service is install on\r\n\t *\r\n\t * @public\r\n\t * @type ServiceManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic ServiceManager: ServiceManager;\r\n\r\n\t/**\r\n\t * Stores access to the App's TransitionManager\r\n\t *\r\n\t * @public\r\n\t * @type TransitionManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic TransitionManager: TransitionManager;\r\n\r\n\t/**\r\n\t * Method is run once when Service is installed on a ServiceManager\r\n\t *\r\n\t * @memberof Service\r\n\t */\r\n\tpublic install(): void {\r\n\t\tlet { app } = this.manager;\r\n\t\tthis.PageManager = app.pages;\r\n\t\tthis.HistoryManager = app.history;\r\n\t\tthis.ServiceManager = app.services;\r\n\t\tthis.TransitionManager = app.transitions;\r\n\t}\r\n\r\n\t// Called before the start of a Service, represents a constructor of sorts\r\n\tpublic init(...args: any): void { }\r\n\r\n\t// Called on start of Service\r\n\tpublic boot(): void {\r\n\t\tthis.initEvents();\r\n\t}\r\n\r\n\t// Initialize events\r\n\tpublic initEvents(): void { }\r\n\r\n\t// Stop events\r\n\tpublic stopEvents(): void { }\r\n\r\n\tpublic uninstall() {\r\n\t\tthis.PageManager = undefined;\r\n\t\tthis.HistoryManager = undefined;\r\n\t\tthis.ServiceManager = undefined;\r\n\t\tthis.TransitionManager = undefined;\r\n\t}\r\n\r\n\t// Stop services\r\n\tpublic stop(): void {\r\n\t\tthis.stopEvents();\r\n\t\tthis.unregister();\r\n\t}\r\n}\r\n\r\n/**\r\n * The Service Manager controls the lifecycle of all services in an App\r\n *\r\n * @export\r\n * @class ServiceManager\r\n * @extends {AdvancedManager}\r\n */\r\nexport class ServiceManager extends AdvancedManager {\r\n\t/**\r\n\t * Creates an instance of ServiceManager.\r\n\t *\r\n\t * @param {App} app\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tconstructor(app: App) {\r\n\t\tsuper(app);\r\n\t}\r\n\r\n\t/**\r\n\t * Call the init method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic init(): ServiceManager {\r\n\t\tmethodCall(this, \"init\", this.app);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Call the boot method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic boot(): ServiceManager {\r\n\t\tmethodCall(this, \"boot\", this.app);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Call the stop method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic stop(): ServiceManager {\r\n\t\tmethodCall(this, \"stop\", this.app);\r\n\t\treturn this;\r\n\t}\r\n}\r\n", "import { Manager } from \"./manager\";\r\nimport { EventEmitter } from \"./emitter\";\r\nimport { ICoords, Trigger } from \"./history\";\r\nimport { Page } from \"./page\";\r\nimport { App } from \"./app\";\r\nimport { CONFIG } from \"./config\";\r\n\r\n/**\r\n * The async function type, allows for smooth transition between Promises\r\n */\r\nexport type asyncFn = (err?: any, value?: any) => void;\r\nexport interface ITransition {\r\n oldPage?: Page;\r\n newPage?: Page;\r\n trigger?: Trigger;\r\n scroll?: { x: number; y: number };\r\n scrollable?: boolean;\r\n in: (data: ITransitionData) => any;\r\n out: (data: ITransitionData) => any;\r\n [key: string]: any;\r\n}\r\nexport interface ITransitionData {\r\n from?: Page;\r\n to?: Page;\r\n trigger?: Trigger;\r\n scroll?: ICoords;\r\n done: asyncFn;\r\n}\r\n\r\n/**\r\n * Controls which animation between pages to use\r\n *\r\n * @export\r\n * @class TransitionManager\r\n * @extends {Manager}\r\n */\r\nexport class TransitionManager extends Manager {\r\n /**\r\n * The instance of the App class, the Manager is instantiated in\r\n *\r\n * @type App\r\n * @memberof AdvancedManager\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof AdvancedManager\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * The EventEmitter class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof AdvancedManager\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * Creates an instance of the TransitionManager\r\n *\r\n * @param {App} app\r\n * @memberof TransitionManager\r\n */\r\n constructor(app: App) {\r\n super();\r\n this.app = app;\r\n this.config = app.config;\r\n this.emitter = app.emitter;\r\n }\r\n\r\n /**\r\n * Runs a transition\r\n *\r\n * @param {{ name: string, oldPage: Page, newPage: Page, trigger: Trigger }} data\r\n * @returns Promise\r\n * @memberof TransitionManager\r\n */\r\n public async boot(name: string, data: { oldPage: Page, newPage: Page, trigger: Trigger, scroll: ICoords }): Promise {\r\n let transition: ITransition = this.get(name);\r\n if (!(data.oldPage instanceof Page) || !(data.newPage instanceof Page))\r\n throw `[Page] either oldPage or newPage aren't instances of the Page Class.\\n ${{\r\n newPage: data.newPage,\r\n oldPage: data.oldPage,\r\n }}`;\r\n\r\n let fromWrapper = data.oldPage.wrapper;\r\n let toWrapper = data.newPage.wrapper;\r\n document.title = `` + data.newPage.title;\r\n\r\n if (!(fromWrapper instanceof Node) || !(toWrapper instanceof Node))\r\n throw `[Wrapper] the wrapper from the ${!(toWrapper instanceof Node) ? \"next\" : \"current\"\r\n } page cannot be found. The wrapper must be an element that has the attribute ${this.config.getConfig(\r\n \"wrapperAttr\"\r\n )}.`;\r\n transition.init && transition?.init(data);\r\n\r\n this.emitter.emit(\"BEFORE_TRANSITION_OUT\");\r\n await new Promise((done) => {\r\n let outMethod: Promise = transition.out.call(transition, {\r\n from: data.oldPage,\r\n trigger: data.trigger,\r\n scroll,\r\n done,\r\n });\r\n\r\n if (outMethod.then) outMethod.then(done);\r\n });\r\n\r\n this.emitter.emit(\"AFTER_TRANSITION_OUT\");\r\n await new Promise((done) => {\r\n fromWrapper.insertAdjacentElement(\"beforebegin\", toWrapper);\r\n this.emitter.emit(\"CONTENT_INSERT\");\r\n done();\r\n });\r\n\r\n await new Promise((done) => {\r\n fromWrapper.remove();\r\n fromWrapper = undefined;\r\n toWrapper = undefined;\r\n this.emitter.emit(\"CONTENT_REPLACED\");\r\n done();\r\n });\r\n\r\n this.emitter.emit(\"BEFORE_TRANSITION_IN\");\r\n\r\n await new Promise((done) => {\r\n let inMethod: Promise = transition.in.call(transition, {\r\n from: data.oldPage,\r\n to: data.newPage,\r\n trigger: data.trigger,\r\n scroll,\r\n done,\r\n });\r\n\r\n if (inMethod.then) inMethod.then(done);\r\n });\r\n\r\n this.emitter.emit(\"AFTER_TRANSITION_IN\");\r\n return transition;\r\n }\r\n}\r\n", "import { EventEmitter, ListenerCallback, EventInput } from \"./emitter\";\r\nimport { ITransition, TransitionManager } from \"./transition\";\r\nimport { HistoryManager, IState } from \"./history\";\r\nimport { ServiceManager, Service } from \"./service\";\r\nimport { PageManager } from \"./page\";\r\nimport { CONFIG, ICONFIG } from \"./config\";\r\n\r\n/**\r\n * The App class starts the entire process, it controls all managers and all services\r\n *\r\n * @export\r\n * @class App\r\n */\r\nexport class App {\r\n /**\r\n * A new instance of the HistoryManager\r\n *\r\n * @public\r\n * @type HistoryManager\r\n * @memberof App\r\n */\r\n public history: HistoryManager;\r\n\r\n /**\r\n * A new instance of the TransitionManager\r\n *\r\n * @public\r\n * @type TransitionManager\r\n * @memberof App\r\n */\r\n public transitions: TransitionManager;\r\n\r\n /**\r\n * A new instance of the ServiceManager\r\n *\r\n * @public\r\n * @type ServiceManager\r\n * @memberof App\r\n */\r\n public services: ServiceManager;\r\n\r\n /**\r\n * A new instance of an EventEmitter\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof App\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * A new instance of the PageManager\r\n *\r\n * @public\r\n * @type PageManager\r\n * @memberof App\r\n */\r\n public pages: PageManager;\r\n\r\n /**\r\n * The current Configuration's for the framework\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof App\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * Creates an instance of App.\r\n *\r\n * @param {(ICONFIG | CONFIG)} [config={}]\r\n * @memberof App\r\n */\r\n constructor(config: object = {}) {\r\n this.register(config);\r\n }\r\n\r\n /**\r\n * For registering all managers and the configurations\r\n *\r\n * @param {(ICONFIG | CONFIG)} [config={}]\r\n * @returns App\r\n * @memberof App\r\n */\r\n public register(config: ICONFIG | CONFIG = {}): App {\r\n this.config = config instanceof CONFIG ? config : new CONFIG(config);\r\n this.emitter = new EventEmitter();\r\n this.history = new HistoryManager();\r\n this.pages = new PageManager(this);\r\n this.transitions = new TransitionManager(this);\r\n this.services = new ServiceManager(this);\r\n\r\n let handler = (() => {\r\n document.removeEventListener(\"DOMContentLoaded\", handler);\r\n window.removeEventListener(\"load\", handler);\r\n this.emitter.emit(\"READY ready\");\r\n }).bind(this);\r\n\r\n document.addEventListener(\"DOMContentLoaded\", handler);\r\n window.addEventListener(\"load\", handler);\r\n return this;\r\n }\r\n\r\n /**\r\n * Based on the type, it will return either a Transition, a Service, or a State from their respective Managers\r\n *\r\n * @param {(\"service\" | \"transition\" | \"state\" | string)} type\r\n * @param {any} key\r\n * @returns Service | Transition | State\r\n * @memberof App\r\n */\r\n public get(type: \"service\" | \"transition\" | \"state\" | string, key: any): Service | ITransition | IState {\r\n switch (type.toLowerCase()) {\r\n case \"service\":\r\n return this.services.get(key);\r\n case \"transition\":\r\n return this.transitions.get(key);\r\n case \"state\":\r\n return this.history.get(key);\r\n default:\r\n throw `Error: can't get type '${type}', it is not a recognized type. Did you spell it correctly.`;\r\n }\r\n }\r\n\r\n /**\r\n * Based on the type, it will return load either Page a Transition, a Service, a State, or a Page from their respective Managers\r\n *\r\n * @param {(\"page\" | string)} type\r\n * @param {any} key\r\n * @returns App\r\n * @memberof App\r\n */\r\n public async load(type: \"page\" | string, key: any): Promise {\r\n switch (type.toLowerCase()) {\r\n case \"page\":\r\n return await this.pages.load(key);\r\n default:\r\n return Promise.resolve(this.get(type, key));\r\n }\r\n }\r\n\r\n /**\r\n * Adds a Service to the App's instance of the ServiceManager, with a name\r\n *\r\n * @param {string} key\r\n * @param {Service} service\r\n * @returns App\r\n * @memberof App\r\n */\r\n public setService(key: string, service: Service): App {\r\n this.services.set(key, service);\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a Service to the App's instance of the ServiceManager, with a name\r\n *\r\n * @param {string} key\r\n * @param {ITransition} tranisition\r\n * @returns App\r\n * @memberof App\r\n */\r\n public setTransition(key: string, transition: ITransition): App {\r\n this.transitions.set(key, transition);\r\n return this;\r\n }\r\n\r\n /**\r\n * Based on the type, it will add either a Transition, a Service, or a State to their respective Managers\r\n *\r\n * @param {(\"service\" | \"transition\" | \"state\")} type\r\n * @param {any} value\r\n * @returns App\r\n * @memberof App\r\n */\r\n public add(type: \"service\" | \"transition\" | \"state\", value: any): App {\r\n switch (type.toLowerCase()) {\r\n case \"service\":\r\n this.services.add(value);\r\n break;\r\n case \"transition\":\r\n this.transitions.set(value.name, value);\r\n break;\r\n case \"state\":\r\n this.history.add(value);\r\n break;\r\n default:\r\n throw `Error: can't add type '${type}', it is not a recognized type. Did you spell it correctly.`;\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Start the App and the ServiceManager\r\n *\r\n * @returns App\r\n * @memberof App\r\n */\r\n public boot(): App {\r\n this.services.init();\r\n this.services.boot();\r\n return this;\r\n }\r\n\r\n /**\r\n * Stop the App and the ServiceManager\r\n *\r\n * @returns App\r\n * @memberof App\r\n */\r\n public stop(): App {\r\n this.services.stop();\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter on method\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} callback\r\n * @returns App\r\n * @memberof App\r\n */\r\n public on(events: EventInput, callback?: ListenerCallback): App {\r\n this.emitter.on(events, callback, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter off method\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} callback\r\n * @returns App\r\n * @memberof App\r\n */\r\n public off(events: EventInput, callback?: ListenerCallback): App {\r\n this.emitter.off(events, callback, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter emit method\r\n *\r\n * @param {(string | any[])} events\r\n * @param {...any} args\r\n * @returns App\r\n * @memberof App\r\n */\r\n public emit(events: string | any[], ...args: any): App {\r\n this.emitter.emit(events, ...args);\r\n return this;\r\n }\r\n}\r\n", "import { newState, Trigger, IState, newCoords, IHistoryItem } from \"./history\";\r\nimport { Service } from \"./service\";\r\nimport { Page } from \"./page\";\r\nimport { newURL, getHashedPath, equal } from \"./url\";\r\n\r\nexport type LinkEvent = MouseEvent | TouchEvent;\r\nexport type StateEvent = LinkEvent | PopStateEvent;\r\nexport type IgnoreURLsList = Array;\r\n\r\n/**\r\n * Creates a Barba JS like PJAX Service, for the Framework\r\n *\r\n * @export\r\n * @class PJAX\r\n * @extends {Service}\r\n */\r\n// Based on Barba JS and StartingBlocks\r\nexport class PJAX extends Service {\r\n /**\r\n * URLs to ignore when prefetching\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected ignoreURLs: IgnoreURLsList = [];\r\n\r\n /**\r\n * Whether or not to disable prefetching\r\n *\r\n * @private\r\n *\r\n * @memberof PJAX\r\n */\r\n protected prefetchIgnore: boolean = false;\r\n\r\n /**\r\n * Current state or transitions\r\n *\r\n * @public\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n public isTransitioning: boolean = false;\r\n\r\n /**\r\n * Ignore extra clicks of an anchor element if a transition has already started\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected stopOnTransitioning: boolean = false;\r\n\r\n /**\r\n * On page change (excluding popstate event) keep current scroll position\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected stickyScroll: boolean = false;\r\n\r\n /**\r\n * Force load a page if an error occurs\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected forceOnError: boolean = false;\r\n\r\n /**\r\n * Dictates whether to auto scroll if an hash is present in the window URL\r\n *\r\n * @protected\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected autoScrollOnHash: boolean = true;\r\n\r\n /**\r\n * Disables all extra scroll effects of PJAX, however, it won't affect scroll on hash,\r\n * since scrolling when an hash is in the URL is the default behavior\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected dontScroll: boolean = true;\r\n\r\n /**\r\n * Sets the transition state, sets isTransitioning to true\r\n *\r\n * @private\r\n * @memberof PJAX\r\n */\r\n private transitionStart() {\r\n this.isTransitioning = true;\r\n }\r\n\r\n /**\r\n * Sets the transition state, sets isTransitioning to false\r\n *\r\n * @private\r\n * @memberof PJAX\r\n */\r\n private transitionStop() {\r\n this.isTransitioning = false;\r\n }\r\n\r\n public init() {\r\n super.init();\r\n\r\n /**\r\n * Bind the event listeners to the PJAX class\r\n *\r\n * @memberof PJAX\r\n */\r\n this.onHover = this.onHover.bind(this);\r\n this.onClick = this.onClick.bind(this);\r\n this.onStateChange = this.onStateChange.bind(this);\r\n }\r\n\r\n /**\r\n * Starts the PJAX Service\r\n *\r\n * @memberof PJAX\r\n */\r\n public boot() {\r\n if (\"scrollRestoration\" in window.history) {\r\n // Back off, browser, I got this...\r\n window.history.scrollRestoration = \"manual\";\r\n }\r\n\r\n super.boot();\r\n }\r\n\r\n /**\r\n * Gets the transition to use for a certain anchor\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @returns {(string | null)}\r\n * @memberof PJAX\r\n */\r\n public getTransitionName(el: HTMLAnchorElement): string | null {\r\n if (!el || !el.getAttribute) return null;\r\n let transitionAttr = el.getAttribute(\r\n this.config.getConfig(\"transitionAttr\", false)\r\n );\r\n if (typeof transitionAttr === \"string\") return transitionAttr;\r\n return null;\r\n }\r\n\r\n /**\r\n * Checks to see if the anchor is valid\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @param {(LinkEvent | KeyboardEvent)} event\r\n * @param {string} href\r\n *\r\n * @memberof PJAX\r\n */\r\n public validLink(\r\n el: HTMLAnchorElement,\r\n event: LinkEvent | KeyboardEvent,\r\n href: string\r\n ): boolean {\r\n let pushStateSupport = !window.history.pushState;\r\n let exists = !el || !href;\r\n let eventMutate =\r\n (event as KeyboardEvent).metaKey ||\r\n (event as KeyboardEvent).ctrlKey ||\r\n (event as KeyboardEvent).shiftKey ||\r\n (event as KeyboardEvent).altKey;\r\n let newTab =\r\n el.hasAttribute(\"target\") &&\r\n (el as HTMLAnchorElement).target === \"_blank\";\r\n let crossOrigin =\r\n (el as HTMLAnchorElement).protocol !== location.protocol ||\r\n (el as HTMLAnchorElement).hostname !== location.hostname;\r\n let download = typeof el.getAttribute(\"download\") === \"string\";\r\n let preventSelf = el.hasAttribute(this.config.getConfig(\"preventSelfAttr\", false));\r\n let preventAll = Boolean(\r\n el.closest(this.config.getConfig(\"preventAllAttr\"))\r\n );\r\n let prevent = preventSelf && preventAll;\r\n let sameURL = getHashedPath(newURL()) === getHashedPath(newURL(href));\r\n return !(\r\n exists ||\r\n pushStateSupport ||\r\n eventMutate ||\r\n newTab ||\r\n crossOrigin ||\r\n download ||\r\n prevent ||\r\n sameURL\r\n );\r\n }\r\n\r\n /**\r\n * Returns the href or an Anchor element\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @returns {(string | null)}\r\n * @memberof PJAX\r\n */\r\n public getHref(el: HTMLAnchorElement): string | null {\r\n if (\r\n el &&\r\n el.tagName &&\r\n el.tagName.toLowerCase() === \"a\" &&\r\n typeof el.href === \"string\"\r\n )\r\n return el.href;\r\n return null;\r\n }\r\n\r\n /**\r\n * Check if event target is a valid anchor with an href, if so, return the link\r\n *\r\n * @param {LinkEvent} event\r\n *\r\n * @memberof PJAX\r\n */\r\n public getLink(event: LinkEvent): HTMLAnchorElement {\r\n let el = event.target as HTMLAnchorElement;\r\n let href: string = this.getHref(el);\r\n\r\n while (el && !href) {\r\n el = (el as HTMLElement).parentNode as HTMLAnchorElement;\r\n href = this.getHref(el);\r\n }\r\n\r\n // Check for a valid link\r\n if (!el || !this.validLink(el, event, href)) return;\r\n return el;\r\n }\r\n\r\n /**\r\n * When an element is clicked.\r\n *\r\n * Get valid anchor element.\r\n * Go for a transition.\r\n *\r\n * @param {LinkEvent} event\r\n * @returns\r\n * @memberof PJAX\r\n */\r\n public onClick(event: LinkEvent) {\r\n let el = this.getLink(event);\r\n if (!el) return;\r\n\r\n if (this.isTransitioning && this.stopOnTransitioning) {\r\n event.preventDefault();\r\n event.stopPropagation();\r\n return;\r\n }\r\n\r\n let href = this.getHref(el);\r\n this.emitter.emit(\"ANCHOR_CLICK CLICK\", event);\r\n this.go({ href, trigger: el, event });\r\n }\r\n\r\n /**\r\n * Returns the direction of the State change as a String, either the Back button or the Forward button\r\n *\r\n * @param {number} value\r\n *\r\n * @memberof PJAX\r\n */\r\n public getDirection(value: number): Trigger {\r\n if (Math.abs(value) > 1) {\r\n // Ex 6-0 > 0 -> forward, 0-6 < 0 -> back\r\n return value > 0 ? \"forward\" : \"back\";\r\n } else {\r\n if (value === 0) {\r\n return \"popstate\";\r\n } else {\r\n // Ex 6-5 > 0 -> back, 5-6 < 0 -> forward\r\n return value > 0 ? \"back\" : \"forward\";\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Force a page to go to a certain URL\r\n *\r\n * @param {string} href\r\n * @memberof PJAX\r\n */\r\n public force(href: string): void {\r\n window.location.assign(href);\r\n }\r\n\r\n /**\r\n * If transition is running force load page.\r\n * Stop if currentURL is the same as new url.\r\n * On state change, change the current state history,\r\n * to reflect the direction of said state change\r\n * Load page and page transition.\r\n *\r\n * @param {string} href\r\n * @param {Trigger} [trigger='HistoryManager']\r\n * @param {StateEvent} [event]\r\n * @memberof PJAX\r\n */\r\n public go({\r\n href,\r\n trigger = \"HistoryManager\",\r\n event,\r\n }: {\r\n href: string;\r\n trigger?: Trigger;\r\n event?: StateEvent;\r\n }): Promise {\r\n // If transition is already running and the go method is called again, force load page\r\n if (this.isTransitioning && this.stopOnTransitioning) {\r\n this.force(href);\r\n return;\r\n }\r\n\r\n let scroll = { x: 0, y: 0 };\r\n let currentState = this.HistoryManager.current;\r\n let currentURL = currentState.url;\r\n if (equal(currentURL, href)) {\r\n return;\r\n }\r\n\r\n let transitionName: string;\r\n if (event && (event as PopStateEvent).state) {\r\n this.emitter.emit(\"POPSTATE\", event);\r\n\r\n // If popstate, get back/forward direction.\r\n let { state }: { state: IHistoryItem } = event as PopStateEvent;\r\n let { index } = state;\r\n let currentIndex = currentState.index;\r\n let difference = currentIndex - index;\r\n\r\n trigger = this.getDirection(difference);\r\n\r\n // Based on the direction of the state change either remove or add a state\r\n this.HistoryManager.replace(state.states);\r\n this.HistoryManager.pointer = index;\r\n if (trigger === \"back\") {\r\n // this.HistoryManager.remove(currentIndex);\r\n this.emitter.emit(`POPSTATE_BACK`, event);\r\n } else if (trigger === \"forward\") {\r\n // this.HistoryManager.add({ url: href, transition, data });\r\n this.emitter.emit(`POPSTATE_FORWARD`, event);\r\n }\r\n\r\n let _state = this.HistoryManager.get(index);\r\n transitionName = _state.transition;\r\n\r\n // If the page remains on the same history state DO NOT scroll, it's pointless\r\n if (trigger !== \"popstate\") {\r\n // Keep scroll position\r\n scroll = _state.data.scroll;\r\n }\r\n } else {\r\n // Add new state\r\n transitionName = this.getTransitionName(trigger as HTMLAnchorElement) ||\r\n \"default\";\r\n let scrollCoords = newCoords();\r\n\r\n if (!this.dontScroll && this.stickyScroll) {\r\n // Keep scroll position\r\n let { x, y } = scrollCoords;\r\n scroll = { x, y };\r\n } else {\r\n scroll = {\r\n x: 0,\r\n y: 0\r\n };\r\n }\r\n\r\n let state = newState({\r\n url: href,\r\n transition: transitionName,\r\n data: { scroll: scrollCoords },\r\n });\r\n\r\n this.HistoryManager.add(state);\r\n this.emitter.emit(\"HISTORY_NEW_ITEM\", event);\r\n }\r\n\r\n if (event) {\r\n event.stopPropagation();\r\n event.preventDefault();\r\n }\r\n\r\n this.emitter.emit(\"GO\", event);\r\n return this.load({\r\n oldHref: currentURL,\r\n href,\r\n trigger,\r\n transitionName,\r\n scroll,\r\n });\r\n }\r\n\r\n /**\r\n * Load the new Page as well as a Transition; run the Transition\r\n *\r\n * @param {string} oldHref\r\n * @param {string} href\r\n * @param {Trigger} trigger\r\n * @param {string} [transitionName=\"default\"]\r\n *\r\n * @memberof PJAX\r\n */\r\n public async load({\r\n oldHref,\r\n href,\r\n trigger,\r\n transitionName = \"default\",\r\n scroll = { x: 0, y: 0 },\r\n }: {\r\n oldHref: string;\r\n href: string;\r\n trigger: Trigger;\r\n transitionName?: string;\r\n scroll: { x: number; y: number };\r\n }): Promise {\r\n try {\r\n let oldPage = await this.PageManager.load(oldHref);\r\n await oldPage.build();\r\n let newPage: Page;\r\n\r\n this.emitter.emit(\"PAGE_LOADING\", { href, oldPage, trigger });\r\n try {\r\n try {\r\n newPage = await this.PageManager.load(href);\r\n await newPage.build();\r\n this.transitionStart();\r\n this.emitter.emit(\"PAGE_LOAD_COMPLETE\", {\r\n newPage,\r\n oldPage,\r\n trigger,\r\n });\r\n } catch (err) {\r\n console.error(`[PJAX] page load error: ${err}`);\r\n }\r\n\r\n // --\r\n // --\r\n\r\n this.emitter.emit(\"NAVIGATION_START\", {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n transitionName,\r\n });\r\n\r\n try {\r\n this.emitter.emit(\"TRANSITION_START\", transitionName);\r\n let transition = await this.TransitionManager.boot(transitionName, {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n scroll,\r\n });\r\n\r\n if (!transition.scrollable) {\r\n if (!/back|popstate|forward/.test(trigger as string)) scroll = hashAction(href);\r\n window.scroll(scroll.x, scroll.y);\r\n }\r\n\r\n this.emitter.emit(\"TRANSITION_END\", { transition });\r\n\r\n } catch (err) {\r\n console.error(`[PJAX] transition error: ${err}`);\r\n }\r\n\r\n this.emitter.emit(\"NAVIGATION_END\", {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n transitionName,\r\n });\r\n } catch (err) {\r\n this.transitionStop();\r\n throw err;\r\n }\r\n\r\n this.transitionStop(); // Sets isTransitioning to false\r\n } catch (err) {\r\n if (this.forceOnError) this.force(href);\r\n else console.error(err);\r\n }\r\n }\r\n\r\n /**\r\n * Check to see if the URL is to be ignored, uses either RegExp of Strings to check\r\n *\r\n * @param {URL} { pathname }\r\n *\r\n * @memberof PJAX\r\n */\r\n public ignoredURL({ pathname }: URL): boolean {\r\n return (\r\n this.ignoreURLs.length &&\r\n this.ignoreURLs.some((url) => {\r\n return typeof url === \"string\"\r\n ? url === pathname\r\n : (url as RegExp).exec(pathname) !== null;\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * When you hover over an anchor, prefetch the event target's href\r\n *\r\n * @param {LinkEvent} event\r\n * @memberof PJAX\r\n */\r\n public onHover(event: LinkEvent): Promise {\r\n let el = this.getLink(event);\r\n if (!el) return;\r\n\r\n let url = newURL(this.getHref(el));\r\n let urlString: string = url.pathname;\r\n // If Url is ignored or already in cache, don't do any think\r\n if (this.ignoredURL(url) || this.PageManager.has(urlString)) return;\r\n this.emitter.emit(\"ANCHOR_HOVER HOVER\", event);\r\n\r\n try {\r\n this.PageManager.load(url);\r\n } catch (err) {\r\n console.warn(\"[PJAX] prefetch error,\", err);\r\n }\r\n }\r\n\r\n /**\r\n * When History state changes.\r\n *\r\n * Get url from State\r\n * Go for a Barba transition.\r\n *\r\n * @param {PopStateEvent} event\r\n * @memberof PJAX\r\n */\r\n public onStateChange(event: PopStateEvent): void {\r\n this.go({ href: window.location.href, trigger: \"popstate\", event });\r\n }\r\n\r\n /**\r\n * Initialize DOM Events\r\n *\r\n * @memberof PJAX\r\n */\r\n public initEvents() {\r\n if (this.prefetchIgnore !== true) {\r\n document.addEventListener(\"mouseover\", this.onHover);\r\n document.addEventListener(\"touchstart\", this.onHover);\r\n }\r\n\r\n document.addEventListener(\"click\", this.onClick);\r\n window.addEventListener(\"popstate\", this.onStateChange);\r\n }\r\n\r\n /**\r\n * Stop DOM Events\r\n *\r\n * @memberof PJAX\r\n */\r\n public stopEvents() {\r\n if (this.prefetchIgnore !== true) {\r\n document.removeEventListener(\"mouseover\", this.onHover);\r\n document.removeEventListener(\"touchstart\", this.onHover);\r\n }\r\n\r\n document.removeEventListener(\"click\", this.onClick);\r\n window.removeEventListener(\"popstate\", this.onStateChange);\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Auto scrolls to an elements position if the element has an hash\r\n *\r\n * @param {string} [hash=window.location.hash]\r\n * @memberof PJAX\r\n */\r\nexport const hashAction = (hash: string = window.location.hash) => {\r\n try {\r\n let _hash = hash[0] == \"#\" ? hash : newURL(hash).hash;\r\n if (_hash.length > 1) {\r\n let el = document.querySelector(_hash) as HTMLElement;\r\n\r\n if (el) {\r\n return { x: el.offsetLeft, y: el.offsetTop };\r\n }\r\n }\r\n } catch (e) {\r\n console.warn(\"hashAction error\", e);\r\n }\r\n\r\n return { x: 0, y: 0 };\r\n};\r\n", "import { Service } from \"./service\";\r\nimport { Manager } from \"./manager\";\r\nimport { newURL, getHashedPath } from \"./url\";\r\n\r\nexport type RouteMethod = (...args: any) => any;\r\nexport type RouteStyle = string | RegExp | boolean;\r\nexport interface IRouteToFrom {\r\n to: RouteStyle,\r\n from: RouteStyle\r\n}\r\nexport type RoutePath = IRouteToFrom | RouteStyle;\r\nexport interface IRoute {\r\n path: RoutePath,\r\n method: RouteMethod\r\n}\r\n\r\n/**\r\n * Controls what happens when certain url paths match a set of criteria\r\n *\r\n * @export\r\n * @class Router\r\n * @extends {Service}\r\n */\r\nexport class Router extends Service {\r\n /**\r\n * List of routes inputted\r\n *\r\n * @protected\r\n * @type {Manager}\r\n * @memberof Router\r\n */\r\n protected routes: Manager;\r\n\r\n /**\r\n * Creates an instance of Router.\r\n *\r\n * @param {Array} [routes=[]]\r\n * @memberof Router\r\n */\r\n constructor(routes: IRoute[] = []) {\r\n super();\r\n this.routes = new Manager();\r\n for (let route of routes) {\r\n this.add(route);\r\n }\r\n }\r\n\r\n /**\r\n * Add a new route to watch for\r\n *\r\n * @param {IRoute} { path, method }\r\n * @returns {Router}\r\n * @memberof Router\r\n */\r\n public add({ path, method }: IRoute): Router {\r\n let key = this.parse(path);\r\n this.routes.set(key, method);\r\n return this;\r\n }\r\n\r\n /**\r\n * Convert strings into path match functions\r\n *\r\n * @param {RouteStyle} path\r\n * @returns {RegExp | boolean}\r\n * @memberof Router\r\n */\r\n public parsePath(path: RouteStyle): RegExp | boolean {\r\n if (typeof path === \"string\") return new RegExp(path, \"i\");\r\n else if (path instanceof RegExp || typeof path === \"boolean\")\r\n return path;\r\n throw \"[Router] only regular expressions, strings and booleans are accepted as paths.\";\r\n }\r\n\r\n /**\r\n * Determines if a strings counts has a path\r\n *\r\n * @param {RouteStyle} input\r\n * @returns boolean\r\n * @memberof Router\r\n */\r\n public isPath(input: RouteStyle): boolean {\r\n return (\r\n typeof input === \"string\" ||\r\n input instanceof RegExp ||\r\n typeof input === \"boolean\"\r\n );\r\n }\r\n\r\n /**\r\n * Parse the multiple different formats for paths, into a { from, to } object\r\n *\r\n * @param {RouteStyle} input\r\n * @returns {IRouteToFrom}\r\n * @memberof Router\r\n */\r\n public parse(input: RoutePath): IRouteToFrom {\r\n let route = input as IRouteToFrom;\r\n let toFromPath: IRouteToFrom = {\r\n from: /(.*)/g,\r\n to: /(.*)/g,\r\n };\r\n\r\n if (this.isPath(input as RouteStyle))\r\n toFromPath = {\r\n from: true,\r\n to: input as RouteStyle,\r\n };\r\n else if (this.isPath(route.from) && this.isPath(route.to as RouteStyle))\r\n toFromPath = route;\r\n else\r\n throw \"[Router] path is neither a string, regular expression, or a { from, to } object.\";\r\n\r\n let { from, to } = toFromPath;\r\n return {\r\n from: this.parsePath(from),\r\n to: this.parsePath(to),\r\n };\r\n }\r\n\r\n /**\r\n * Test if route paths are true, if so run their methods\r\n *\r\n * @memberof Router\r\n */\r\n public route() {\r\n let history = this.HistoryManager;\r\n let from: string = getHashedPath(newURL((history.length > 1 ? history.previous : history.current).url));\r\n let to: string = getHashedPath(newURL());\r\n\r\n this.routes.forEach((method: RouteMethod, path: IRouteToFrom) => {\r\n let fromRegExp = path.from as RegExp | boolean;\r\n let toRegExp = path.to as RegExp | boolean;\r\n\r\n if (\r\n typeof fromRegExp === \"boolean\" &&\r\n typeof toRegExp === \"boolean\"\r\n ) {\r\n throw `[Router] path ({ from: ${fromRegExp}, to: ${toRegExp} }) is not valid, remember paths can only be strings, regular expressions, or a boolean; however, both the from and to paths cannot be both booleans.`;\r\n }\r\n\r\n let fromParam: RegExpExecArray | RegExp | boolean = fromRegExp;\r\n let toParam: RegExpExecArray | RegExp | boolean = toRegExp;\r\n\r\n if (fromRegExp instanceof RegExp && fromRegExp.test(from))\r\n fromParam = fromRegExp.exec(from);\r\n if (toRegExp instanceof RegExp && toRegExp.test(to))\r\n toParam = toRegExp.exec(to);\r\n\r\n if (\r\n (Array.isArray(toParam) && Array.isArray(fromParam)) ||\r\n (Array.isArray(toParam) &&\r\n typeof fromParam == \"boolean\" &&\r\n fromParam) ||\r\n (Array.isArray(fromParam) &&\r\n typeof toParam == \"boolean\" &&\r\n toParam)\r\n )\r\n method({ from: fromParam, to: toParam, path: { from, to } });\r\n });\r\n }\r\n\r\n /**\r\n * Add listeners for PJAX Events\r\n *\r\n * @memberof Router\r\n */\r\n public initEvents() {\r\n this.emitter.on(\"READY\", this.route, this);\r\n this.emitter.on(\"CONTENT_REPLACED\", this.route, this);\r\n }\r\n\r\n /**\r\n * Remove listeners for PJAX Events\r\n *\r\n * @memberof Router\r\n */\r\n public stopEvents() {\r\n this.emitter.off(\"READY\", this.route, this);\r\n this.emitter.off(\"CONTENT_REPLACED\", this.route, this);\r\n }\r\n}\r\n", "import { EventEmitter, EventInput, ListenerCallback } from \"@okikio/emitter\";\r\n\r\n// DOM\r\nexport type AnimationTarget = string | Node | NodeList | HTMLCollection | HTMLElement[] | any[];\r\nexport const getElements = (selector: string | Node): Node[] => {\r\n return typeof selector === \"string\" ? Array.from(document.querySelectorAll(selector as string)) : [selector];\r\n};\r\n\r\nexport const getTargets = (targets: AnimationTarget): Node[] => {\r\n if (Array.isArray(targets)) return targets;\r\n if (typeof targets == \"string\" || targets instanceof Node)\r\n return getElements(targets);\r\n if (targets instanceof NodeList || targets instanceof HTMLCollection)\r\n return Array.from(targets);\r\n return [];\r\n};\r\n\r\n// VALUES\r\nexport type closureArgs = [number, number, HTMLElement];\r\nexport type closure = ((index?: number, total?: number, element?: HTMLElement) => any) | any;\r\nexport const computeValue = (value: closure, args: closureArgs) => {\r\n if (typeof value === \"function\") {\r\n return value(...args);\r\n } else { return value; }\r\n};\r\n\r\nexport const mapObject = (obj: object, args: closureArgs): any => {\r\n let key, value, result = {};\r\n let keys = Object.keys(obj);\r\n for (let i = 0, len = keys.length; i < len; i++) {\r\n key = keys[i];\r\n value = obj[key];\r\n result[key] = computeValue(value, args);\r\n }\r\n\r\n return result;\r\n};\r\n\r\n// From: [https://easings.net]\r\nexport const easings = {\r\n \"ease\": \"ease\",\r\n \"in\": \"ease-in\",\r\n \"out\": \"ease-out\",\r\n \"in-out\": \"ease-in-out\",\r\n\r\n // Sine\r\n \"in-sine\": \"cubic-bezier(0.47, 0, 0.745, 0.715)\",\r\n \"out-sine\": \"cubic-bezier(0.39, 0.575, 0.565, 1)\",\r\n \"in-out-sine\": \"cubic-bezier(0.445, 0.05, 0.55, 0.95)\",\r\n\r\n // Quad\r\n \"in-quad\": \"cubic-bezier(0.55, 0.085, 0.68, 0.53)\",\r\n \"out-quad\": \"cubic-bezier(0.25, 0.46, 0.45, 0.94)\",\r\n \"in-out-quad\": \"cubic-bezier(0.455, 0.03, 0.515, 0.955)\",\r\n\r\n // Cubic\r\n \"in-cubic\": \"cubic-bezier(0.55, 0.055, 0.675, 0.19)\",\r\n \"out-cubic\": \"cubic-bezier(0.215, 0.61, 0.355, 1)\",\r\n \"in-out-cubic\": \"cubic-bezier(0.645, 0.045, 0.355, 1)\",\r\n\r\n // Quart\r\n \"in-quart\": \"cubic-bezier(0.895, 0.03, 0.685, 0.22)\",\r\n \"out-quart\": \"cubic-bezier(0.165, 0.84, 0.44, 1)\",\r\n \"in-out-quart\": \"cubic-bezier(0.77, 0, 0.175, 1)\",\r\n\r\n // Quint\r\n \"in-quint\": \"cubic-bezier(0.755, 0.05, 0.855, 0.06)\",\r\n \"out-quint\": \"cubic-bezier(0.23, 1, 0.32, 1)\",\r\n \"in-out-quint\": \"cubic-bezier(0.86, 0, 0.07, 1)\",\r\n\r\n // Expo\r\n \"in-expo\": \"cubic-bezier(0.95, 0.05, 0.795, 0.035)\",\r\n \"out-expo\": \"cubic-bezier(0.19, 1, 0.22, 1)\",\r\n \"in-out-expo\": \"cubic-bezier(1, 0, 0, 1)\",\r\n\r\n // Circ\r\n \"in-circ\": \"cubic-bezier(0.6, 0.04, 0.98, 0.335)\",\r\n \"out-circ\": \"cubic-bezier(0.075, 0.82, 0.165, 1)\",\r\n \"in-out-circ\": \"cubic-bezier(0.785, 0.135, 0.15, 0.86)\",\r\n\r\n // Back\r\n \"in-back\": \"cubic-bezier(0.6, -0.28, 0.735, 0.045)\",\r\n \"out-back\": \"cubic-bezier(0.175, 0.885, 0.32, 1.275)\",\r\n \"in-out-back\": \"cubic-bezier(0.68, -0.55, 0.265, 1.55)\"\r\n};\r\nexport const getEase = (ease: string) => {\r\n return /^(ease|in|out)/.test(ease) ? easings[ease] : ease;\r\n};\r\n\r\nexport interface AnimationOptions {\r\n target?: AnimationTarget,\r\n\r\n speed?: number | closure,\r\n delay?: number | closure,\r\n easing?: string | closure,\r\n endDelay?: number | closure,\r\n duration?: number | closure,\r\n autoplay?: boolean | closure,\r\n keyframes?: object[] | closure,\r\n loop?: number | boolean | closure, // iterations: number,\r\n options?: AnimationOptions | closure,\r\n onfinish?: (element?: HTMLElement, index?: number, total?: number) => any,\r\n fillMode?: \"none\" | \"forwards\" | \"backwards\" | \"both\" | \"auto\" | closure,\r\n direction?: \"normal\" | \"reverse\" | \"alternate\" | \"alternate-reverse\" | closure,\r\n [property: string]: closure | boolean | object | string | string[] | number | null | (number | null)[] | undefined;\r\n};\r\n\r\nexport const DefaultAnimationOptions: AnimationOptions = {\r\n keyframes: [],\r\n\r\n loop: 1, // iterations: number,\r\n delay: 0,\r\n speed: 1,\r\n endDelay: 0,\r\n easing: \"ease\",\r\n autoplay: true,\r\n duration: 1000,\r\n onfinish() { },\r\n fillMode: \"auto\",\r\n direction: \"normal\",\r\n};\r\n\r\n// You can check it out here: https://codepen.io/okikio/pen/qBbdGaW?editors=0011\r\nexport class Animate {\r\n /**\r\n * Stores the options for the current animation\r\n *\r\n * @public\r\n * @type AnimationOptions\r\n * @memberof Animate\r\n */\r\n public options: AnimationOptions = {};\r\n\r\n /**\r\n * The Array of Elements to Animate\r\n *\r\n * @public\r\n * @type {Node[]}\r\n * @memberof Animate\r\n */\r\n public targets: Node[] = [];\r\n\r\n /**\r\n * The properties to animate\r\n *\r\n * @public\r\n * @type {object}\r\n * @memberof Animate\r\n */\r\n public properties: object = {};\r\n\r\n /**\r\n * A Set of Animations\r\n *\r\n * @public\r\n * @type {Map}\r\n * @memberof Animate\r\n */\r\n public animations: Map = new Map();\r\n\r\n /**\r\n * The total duration of all Animation's\r\n *\r\n * @public\r\n * @type {number}\r\n * @memberof Animate\r\n */\r\n public duration: number = 0;\r\n\r\n /**\r\n * The Element the main animation uses\r\n *\r\n * @public\r\n * @type {HTMLElement}\r\n * @memberof Animate\r\n */\r\n public mainElement: HTMLElement;\r\n\r\n /**\r\n * Stores an animation that runs on the total duration of the all other Animations, and as such it's the main Animation\r\n *\r\n * @public\r\n * @type {Animation}\r\n * @memberof Animate\r\n */\r\n public mainAnimation: Animation;\r\n\r\n /**\r\n * Stores request frame calls\r\n *\r\n * @public\r\n * @type {number}\r\n * @memberof Animate\r\n */\r\n public animationFrame: number;\r\n\r\n /**\r\n * An event emitter\r\n *\r\n * @public\r\n * @type {EventEmitter}\r\n * @memberof Animate\r\n */\r\n public emitter: EventEmitter = new EventEmitter();\r\n\r\n /**\r\n * The finish method, is called when the main animation has finished\r\n *\r\n * @public\r\n * @type {*}\r\n * @memberof Animate\r\n */\r\n public finish: any;\r\n\r\n /**\r\n * Returns a promise that is fulfilled when the mainAnimation is finished\r\n *\r\n * @public\r\n * @type {Promise}\r\n * @memberof Animate\r\n */\r\n public promise: Promise;\r\n\r\n /**\r\n * Creates an instance of Animate.\r\n *\r\n * @param {AnimationOptions} options\r\n * @memberof Animate\r\n */\r\n constructor(options: AnimationOptions = {}) {\r\n let { options: animation, ...rest } = options;\r\n this.options = Object.assign({}, DefaultAnimationOptions, animation, rest);\r\n this.loop = this.loop.bind(this);\r\n\r\n let {\r\n loop,\r\n delay,\r\n speed,\r\n easing,\r\n endDelay,\r\n duration,\r\n direction,\r\n fillMode,\r\n onfinish,\r\n target,\r\n keyframes,\r\n autoplay,\r\n ...properties\r\n } = this.options;\r\n\r\n this.mainElement = document.createElement(\"span\");\r\n this.targets = getTargets(target);\r\n this.properties = properties;\r\n\r\n let animationKeyframe: Keyframe[] | PropertyIndexedKeyframes;\r\n for (let i = 0, len = this.targets.length; i < len; i++) {\r\n let target = this.targets[i] as HTMLElement;\r\n let animationOptions = {\r\n easing: getEase(easing),\r\n iterations: loop === true ? Infinity : (loop as number),\r\n direction,\r\n endDelay,\r\n duration,\r\n delay,\r\n fill: fillMode,\r\n };\r\n\r\n // Accept keyframes as a keyframes Object, or a method,\r\n // if there are no animations in the keyframes array,\r\n // uses css properties from the options object\r\n let arrKeyframes = computeValue((keyframes as Keyframe[]), [i, len, target]);\r\n animationKeyframe = arrKeyframes.length ? arrKeyframes :\r\n (this.properties as PropertyIndexedKeyframes);\r\n\r\n // Allows the use of functions as the values, for both the keyframes and the animation object\r\n // It adds the capability of advanced stagger animation, similar to the anime js stagger functions\r\n animationOptions = mapObject(animationOptions, [i, len, target]);\r\n if (!(arrKeyframes.length > 0))\r\n animationKeyframe = mapObject(animationKeyframe, [i, len, target]);\r\n\r\n // Set the Animate classes duration to be the Animation with the largest totalDuration\r\n let tempDuration: number =\r\n animationOptions.delay +\r\n (animationOptions.duration * animationOptions.iterations) +\r\n animationOptions.endDelay;\r\n if (this.duration < tempDuration) this.duration = tempDuration;\r\n\r\n // Add animation to the Animations Set\r\n let animation = target.animate(animationKeyframe, animationOptions);\r\n animation.onfinish = () => {\r\n onfinish(target, i, len);\r\n };\r\n this.animations.set(target, animation);\r\n }\r\n\r\n this.mainAnimation = this.mainElement.animate([\r\n { opacity: \"0\" },\r\n { opacity: \"1\" }\r\n ], {\r\n duration: this.duration,\r\n easing: \"linear\"\r\n });\r\n\r\n this.setSpeed(speed);\r\n if (autoplay) this.play();\r\n else this.pause();\r\n\r\n this.promise = this.newPromise();\r\n this.mainAnimation.onfinish = () => {\r\n this.finish(this.options);\r\n window.cancelAnimationFrame(this.animationFrame);\r\n };\r\n }\r\n\r\n /**\r\n * Returns the Array of targets\r\n *\r\n * @returns {Node[]}\r\n * @memberof Animate\r\n */\r\n public getTargets(): Node[] {\r\n return this.targets;\r\n }\r\n\r\n /**\r\n * Returns a new Promise that is resolve when this.finish is called\r\n *\r\n * @public\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public newPromise(): Promise {\r\n return new Promise((resolve, reject) => {\r\n try {\r\n this.finish = (options: AnimationOptions) => {\r\n this.emit(\"finish\", options);\r\n return resolve(options);\r\n };\r\n } catch (err) { reject(err); }\r\n });\r\n }\r\n\r\n /**\r\n * Fulfills the this.promise Promise\r\n *\r\n * @param {(value?: any) => any} [onFulfilled]\r\n * @param {(reason?: any) => any} [onRejected]\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public then(\r\n onFulfilled?: (value?: any) => any,\r\n onRejected?: (reason?: any) => any\r\n ): Promise {\r\n return this.promise.then(onFulfilled, onRejected);\r\n }\r\n\r\n /**\r\n * Catches error that occur in the this.promise Promise\r\n *\r\n * @param {(reason?: any) => any} onRejected\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public catch(onRejected: (reason?: any) => any): Promise {\r\n return this.promise.catch(onRejected);\r\n }\r\n\r\n /**\r\n * If you don't care if the this.promise Promise has either been rejected or resolved\r\n *\r\n * @param {() => any} onFinally\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public finally(onFinally: () => any): Promise {\r\n return this.promise.finally(onFinally);\r\n }\r\n\r\n /**\r\n * Represents an Animation Frame Loop\r\n *\r\n * @public\r\n * @memberof Animate\r\n */\r\n public loop(): void {\r\n this.animationFrame = window.requestAnimationFrame(this.loop);\r\n this.emit(\"tick change\", this.getCurrentTime());\r\n }\r\n\r\n /**\r\n * Adds a listener for a given event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public on(events: EventInput, callback?: ListenerCallback, scope?: object): Animate {\r\n this.emitter.on(events, callback, scope);\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes a listener from an event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public off(events: EventInput, callback?: ListenerCallback, scope?: object): Animate {\r\n this.emitter.off(events, callback, scope);\r\n return this;\r\n }\r\n\r\n /**\r\n * Call all listeners within an event\r\n *\r\n * @param {(string | any[])} events\r\n * @param {...any} args\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public emit(events: string | any[], ...args: any): Animate {\r\n this.emitter.emit(events, ...args);\r\n return this;\r\n }\r\n\r\n /**\r\n * Get a specific Animation from an Animate instance\r\n *\r\n * @param {HTMLElement} element\r\n * @returns {Animation}\r\n * @memberof Animate\r\n */\r\n public getAnimation(element: HTMLElement): Animation {\r\n return this.animations.get(element);\r\n }\r\n\r\n /**\r\n * Play Animation's\r\n *\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public play(): Animate {\r\n // Once the animation is done, it's done, it can only be paused by the reset method\r\n if (this.mainAnimation.playState !== \"finished\") {\r\n this.mainAnimation.play();\r\n this.animationFrame = requestAnimationFrame(this.loop);\r\n this.animations.forEach(animation => {\r\n if (animation.playState !== \"finished\") animation.play();\r\n });\r\n this.emit(\"play\");\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Pause Animation's\r\n *\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public pause(): Animate {\r\n // Once the animation is done, it's done, it can only be reset by the reset method\r\n if (this.mainAnimation.playState !== \"finished\") {\r\n this.mainAnimation.pause();\r\n window.cancelAnimationFrame(this.animationFrame);\r\n this.animations.forEach(animation => {\r\n if (animation.playState !== \"finished\") animation.pause();\r\n });\r\n this.emit(\"pause\");\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the total duration of all Animations\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getDuration(): number {\r\n return this.duration;\r\n }\r\n\r\n /**\r\n * Returns the current time of the Main Animation\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getCurrentTime(): number {\r\n return this.mainAnimation.currentTime;\r\n }\r\n\r\n /**\r\n * Set the current time of the Main Animation\r\n *\r\n * @param {number} time\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setCurrentTime(time: number): Animate {\r\n this.mainAnimation.currentTime = time;\r\n this.animations.forEach(animation => {\r\n animation.currentTime = time;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the Animation progress as a fraction of the current time / duration\r\n *\r\n * @returns\r\n * @memberof Animate\r\n */\r\n public getProgress() {\r\n return this.getCurrentTime() / this.duration;\r\n }\r\n\r\n /**\r\n * Set the Animation progress as a fraction of the current time / duration\r\n *\r\n * @param {number} percent\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setProgress(percent: number): Animate {\r\n this.mainAnimation.currentTime = percent * this.duration;\r\n this.animations.forEach(animation => {\r\n animation.currentTime = percent * this.duration;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Return the playback speed of the animation\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getSpeed(): number {\r\n return this.mainAnimation.playbackRate;\r\n }\r\n\r\n /**\r\n * Set the playback speed of an Animation\r\n *\r\n * @param {number} [speed=1]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setSpeed(speed: number = 1): Animate {\r\n this.mainAnimation.playbackRate = speed;\r\n this.animations.forEach(animation => {\r\n animation.playbackRate = speed;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Reset all Animations\r\n *\r\n * @memberof Animate\r\n */\r\n public reset() {\r\n this.setCurrentTime(0);\r\n this.promise = this.newPromise();\r\n\r\n if (this.options.autoplay) this.play();\r\n else this.pause();\r\n }\r\n\r\n /**\r\n * Returns the current playing state\r\n *\r\n * @returns {(\"idle\" | \"running\" | \"paused\" | \"finished\")}\r\n * @memberof Animate\r\n */\r\n public getPlayState(): \"idle\" | \"running\" | \"paused\" | \"finished\" {\r\n return this.mainAnimation.playState;\r\n }\r\n\r\n /**\r\n * Get the options of an Animate instance\r\n *\r\n * @returns {AnimationOptions}\r\n * @memberof Animate\r\n */\r\n public getOptions(): AnimationOptions {\r\n return this.options;\r\n }\r\n\r\n // Returns the Animate options, as JSON\r\n public toJSON(): AnimationOptions {\r\n return this.getOptions();\r\n }\r\n}\r\n\r\n// Creates a new Animate instance\r\nexport const animate = (options: AnimationOptions =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AK,EAAQ,GAAG,GACtB,KAUJ,gBACH,MAAO,MAAK,WAAW,IAAI,GASxB,OAEH,MAAI,MAAK,cAAc,YAAc,YACjC,MAAK,cAAc,OACnB,KAAK,eAAiB,sBAAsB,KAAK,MACjD,KAAK,WAAW,QAAQ,IACpB,AAAI,EAAU,YAAc,YAAY,EAAU,SAEtD,KAAK,KAAK,SAEP,KASJ,QAEH,MAAI,MAAK,cAAc,YAAc,YACjC,MAAK,cAAc,QACnB,OAAO,qBAAqB,KAAK,gBACjC,KAAK,WAAW,QAAQ,IACpB,AAAI,EAAU,YAAc,YAAY,EAAU,UAEtD,KAAK,KAAK,UAEP,KASJ,cACH,MAAO,MAAK,SAST,iBACH,MAAO,MAAK,cAAc,YAUvB,kBACH,YAAK,cAAc,YAAc,EACjC,KAAK,WAAW,QAAQ,IACpB,EAAU,YAAc,IAErB,KASJ,cACH,MAAO,MAAK,iBAAmB,KAAK,SAUjC,eACH,YAAK,cAAc,YAAc,EAAU,KAAK,SAChD,KAAK,WAAW,QAAQ,IACpB,EAAU,YAAc,EAAU,KAAK,WAEpC,KASJ,WACH,MAAO,MAAK,cAAc,aAUvB,WAAyB,GAC5B,YAAK,cAAc,aAAe,EAClC,KAAK,WAAW,QAAQ,IACpB,EAAU,aAAe,IAEtB,KAQJ,QACH,KAAK,eAAe,GACpB,KAAK,QAAU,KAAK,aAEpB,AAAI,KAAK,QAAQ,SAAU,KAAK,OAC3B,KAAK,QASP,eACH,MAAO,MAAK,cAAc,UASvB,aACH,MAAO,MAAK,QAIT,SACH,MAAO,MAAK,kBAKG,GAA6B,KACzC,GAAI,GAAQ", + "sources": ["../src/config.ts", "../../manager/src/api.ts", "../src/manager.ts", "../src/url.ts", "../src/history.ts", "../src/page.ts", "../../emitter/src/api.ts", "../src/service.ts", "../src/pjax.ts", "../src/transition.ts", "../src/app.ts", "../src/route.ts", "../../animate/src/api.ts"], + "sourcesContent": ["// The config variables\r\nexport interface ICONFIG {\r\n prefix?: string;\r\n wrapperAttr?: string;\r\n noAjaxLinkAttr?: string;\r\n noPrefetchAttr?: \"no-prefetch\";\r\n headers?: string[][];\r\n preventSelfAttr?: string;\r\n preventAllAttr?: string;\r\n transitionAttr?: string;\r\n blockAttr?: string;\r\n timeout?: number\r\n}\r\n\r\nexport const CONFIG_DEFAULTS: ICONFIG = {\r\n wrapperAttr: \"wrapper\",\r\n noAjaxLinkAttr: \"no-ajax-link\",\r\n noPrefetchAttr: \"no-prefetch\",\r\n headers: [\r\n [\"x-partial\", \"true\"]\r\n ],\r\n preventSelfAttr: `prevent=\"self\"`,\r\n preventAllAttr: `prevent=\"all\"`,\r\n transitionAttr: \"transition\",\r\n blockAttr: `block`,\r\n timeout: 30000\r\n};\r\n\r\nexport type ConfigKeys = keyof ICONFIG;\r\n\r\n/**\r\n * The Config class\r\n *\r\n * @export\r\n * @class CONFIG\r\n */\r\nexport class CONFIG {\r\n /**\r\n * The current Configuration\r\n *\r\n * @public\r\n * @type ICONFIG\r\n * @memberof CONFIG\r\n */\r\n public config: ICONFIG;\r\n\r\n /**\r\n * Creates an instance of CONFIG.\r\n *\r\n * @param {ICONFIG} config\r\n * @memberof CONFIG\r\n */\r\n constructor(config: ICONFIG) {\r\n this.config = Object.assign({ ...CONFIG_DEFAULTS }, config);\r\n }\r\n\r\n /**\r\n * Converts string into data attributes\r\n *\r\n * @param {string} value\r\n * @param {boolean} brackets [brackets=true]\r\n * @returns string\r\n * @memberof CONFIG\r\n */\r\n public toAttr(value: string, brackets: boolean = true): string {\r\n let { prefix } = this.config;\r\n let attr = `data${prefix ? \"-\" + prefix : \"\"}-${value}`;\r\n return brackets ? `[${attr}]` : attr;\r\n }\r\n\r\n /**\r\n * Selects config vars, and formats them for use, or simply returns the current configurations for the framework\r\n *\r\n * @param {ConfigKeys} value\r\n * @param {boolean} [brackets=true]\r\n * @returns any\r\n * @memberof CONFIG\r\n */\r\n public getConfig(value?: ConfigKeys, brackets: boolean = true): any {\r\n if (typeof value !== \"string\")\r\n return this.config;\r\n\r\n let config = this.config[value];\r\n if (typeof config === \"string\")\r\n return this.toAttr(config, brackets);\r\n return config;\r\n }\r\n}\r\n", "/**\r\n * Manages complex lists of named data, eg. A page can be stored in a list by of other pages with the url being how the page is stored in the list. Managers use Maps to store data.\r\n *\r\n * @export\r\n * @class Manager\r\n * @template K\r\n * @template V\r\n */\r\nexport class Manager {\r\n\t/**\r\n\t * The complex list of named data, to which the Manager controls\r\n\t *\r\n\t * @public\r\n\t * @type Map\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic map: Map;\r\n\r\n\t/**\r\n\t * Creates an instance of Manager.\r\n\t *\r\n\t * @param {Array<[K, V]>} [value]\r\n\t * @memberof Manager\r\n\t */\r\n\tconstructor(value?: Array<[K, V]>) {\r\n\t\tthis.map = new Map(value);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the Manager class's list\r\n\t *\r\n\t * @returns Map\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic getMap(): Map {\r\n\t\treturn this.map;\r\n\t}\r\n\r\n\t/**\r\n\t * Get a value stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key to find in the Manager's list\r\n\t * @returns V\r\n\t */\r\n\tpublic get(key: K): V {\r\n\t\treturn this.map.get(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the keys of all items stored in the Manager as an Array\r\n\t *\r\n\t * @returns Array\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic keys(): Array {\r\n\t\treturn Array.from(this.map.keys());\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the values of all items stored in the Manager as an Array\r\n\t *\r\n\t * @returns Array\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic values(): Array {\r\n\t\treturn Array.from(this.map.values());\r\n\t}\r\n\r\n\t/**\r\n\t * Set a value stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key where the value will be stored\r\n\t * @param {V} value - The value to store\r\n\t * @returns Manager\r\n\t */\r\n\tpublic set(key: K, value: V): Manager {\r\n\t\tthis.map.set(key, value);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Adds a value to Manager, and uses the current size of the Manager as it's key, it works best when all the key in the Manager are numbers\r\n\t *\r\n\t * @public\r\n\t * @param {V} value\r\n\t * @returns Manager\r\n\t */\r\n\tpublic add(value: V): Manager {\r\n\t\tlet size = this.size;\r\n\t\t// @ts-ignore\r\n\t\tlet num: K = size as K;\r\n\t\tthis.set(num, value);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the total number of items stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @returns Number\r\n\t */\r\n\tpublic get size(): number {\r\n\t\treturn this.map.size;\r\n\t}\r\n\r\n\tpublic get length(): number {\r\n\t\treturn this.map.size;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the last item in the Manager who's index is a certain distance from the last item in the Manager\r\n\t *\r\n\t * @param {number} [distance=1]\r\n\t * @returns V | undefined\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic last(distance: number = 1): V | undefined {\r\n\t\tlet key = this.keys()[this.size - distance];\r\n\t\treturn this.get(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Removes a value stored in the Manager, via the key, returns true if an element in the Map object existed and has been removed, or false if the element does not exist.\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key for the key value pair to be removed\r\n\t * @returns boolean\r\n\t */\r\n\tpublic delete(key: K): boolean {\r\n\t\treturn this.map.delete(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Removes a value stored in the Manager, via the key, returns the Manager class, allowing for chains\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key for the key value pair to be removed\r\n\t * @returns Manager\r\n\t */\r\n\tpublic remove(key: K): Manager {\r\n\t\tthis.map.delete(key);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Clear the Manager of all its contents\r\n\t *\r\n\t * @public\r\n\t * @returns Manager\r\n\t */\r\n\tpublic clear(): Manager {\r\n\t\tthis.map.clear();\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Checks if the Manager contains a certain key\r\n\t *\r\n\t * @public\r\n\t * @param {K} key\r\n\t * @returns boolean\r\n\t */\r\n\tpublic has(key: K): boolean {\r\n\t\treturn this.map.has(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a new Iterator object that contains an array of [key, value] for each element in the Map object in insertion order.\r\n\t *\r\n\t * @public\r\n\t * @returns IterableIterator<[K, V]>\r\n\t */\r\n\tpublic entries(): IterableIterator<[K, V]> {\r\n\t\treturn this.map.entries();\r\n\t}\r\n\r\n\t/**\r\n\t * Iterates through the Managers contents, calling a callback function every iteration\r\n\t *\r\n\t * @param {*} [callback=(...args: any): void => { }]\r\n\t * @param {object} context\r\n\t * @returns Manager\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic forEach(\r\n\t\tcallback: any = (...args: any): void => { },\r\n\t\tcontext?: object\r\n\t): Manager {\r\n\t\tthis.map.forEach(callback, context);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Allows iteration via the for..of, learn more: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators]\r\n\t *\r\n\t * @returns IterableIterator<[K, V]>\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic [Symbol.iterator](): IterableIterator<[K, V]> {\r\n\t\treturn this.entries();\r\n\t}\r\n}\r\n\r\n/**\r\n * Calls the method of a certain name for all items that are currently installed\r\n *\r\n * @param {Manager} manager\r\n * @param {string} method\r\n * @param {Array} [args=[]]\r\n */\r\nexport const methodCall = (manager: Manager, method: string, ...args: any): void => {\r\n\tmanager.forEach((item) => {\r\n\t\t// @ts-ignore\r\n\t\titem[method](...args);\r\n\t});\r\n};\r\n\r\n/**\r\n * Asynchronously calls the method of a certain name for all items that are currently installed, similar to methodCall\r\n *\r\n * @param {Manager} manager\r\n * @param {string} method\r\n * @param {Array} [args=[]]\r\n */\r\nexport const asyncMethodCall = async (manager: Manager, method: string, ...args: any): Promise => {\r\n\tfor (let [, item] of manager) {\r\n\t\t// @ts-ignore\r\n\t\tawait item[method](...args);\r\n\t}\r\n};\r\n\r\nexport default Manager;\r\n", "import { Manager, methodCall, asyncMethodCall } from \"@okikio/manager\";\r\nimport { CONFIG } from \"./config\";\r\nimport { App } from \"./app\";\r\nimport EventEmitter from \"@okikio/emitter\";\r\n\r\nexport type IAdvancedManager = AdvancedManager;\r\n\r\n/**\r\n * The base class for all AdvancedManager and AdvancedStorage items\r\n *\r\n * @export\r\n * @class ManagerItem\r\n */\r\nexport class ManagerItem {\r\n /**\r\n * The AdvancedManager the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type IAdvancedManager\r\n * @memberof ManagerItem\r\n */\r\n public manager: IAdvancedManager;\r\n\r\n /**\r\n * The App the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type App\r\n * @memberof ManagerItem\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof ManagerItem\r\n */\r\n public config: CONFIG;\r\n public emitter: EventEmitter;\r\n public key: any;\r\n\r\n /**\r\n * Creates an instance of ManagerItem.\r\n *\r\n * @memberof ManagerItem\r\n */\r\n constructor() { }\r\n\r\n /**\r\n * Run after the Manager Item has been registered\r\n *\r\n * @returns any\r\n * @memberof ManagerItem\r\n */\r\n public install(): any { }\r\n\r\n /**\r\n * Register the current Manager Item's manager\r\n *\r\n * @param {IAdvancedManager} manager\r\n * @returns ManagerItem\r\n * @memberof ManagerItem\r\n */\r\n public register(manager: IAdvancedManager, key: any): ManagerItem {\r\n this.manager = manager;\r\n this.app = manager.app;\r\n this.config = manager.config;\r\n this.emitter = manager.emitter;\r\n this.key = key;\r\n this.install();\r\n return this;\r\n }\r\n\r\n public uninstall(): any { }\r\n\r\n public unregister() {\r\n this.uninstall();\r\n\r\n this.manager.delete(this.key);\r\n this.key = undefined;\r\n this.manager = undefined;\r\n this.app = undefined;\r\n this.config = undefined;\r\n this.emitter = undefined;\r\n }\r\n}\r\n\r\n/**\r\n * A tweak to the Manager class that makes it self aware of the App class it's instantiated in\r\n *\r\n * @export\r\n * @class AdvancedManager\r\n * @extends {Manager}\r\n * @template K\r\n * @template V\r\n */\r\nexport class AdvancedManager extends Manager {\r\n /**\r\n * The instance of the App class, the Manager is instantiated in\r\n *\r\n * @type App\r\n * @memberof AdvancedManager\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof AdvancedManager\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * The EventEmitter class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof AdvancedManager\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * Creates an instance of AdvancedManager.\r\n *\r\n * @param {App} app - The instance of the App class, the Manager is instantiated in\r\n * @memberof AdvancedManager\r\n */\r\n constructor(app: App) {\r\n super();\r\n this.app = app;\r\n this.config = app.config;\r\n this.emitter = app.emitter;\r\n }\r\n\r\n /**\r\n * Set a value stored in the Manager\r\n *\r\n * @public\r\n * @param {K} key - The key where the value will be stored\r\n * @param {V} value - The value to store\r\n * @returns AdvancedManager\r\n */\r\n public set(key: K, value: V) {\r\n super.set(key, value);\r\n value.register(this, key);\r\n return this;\r\n }\r\n}\r\n\r\nexport { Manager, methodCall, asyncMethodCall };\r\n", "/**\r\n * Adds new methods to the native URL Object; it seemed cleaner than using a custom method or editing the prototype.\r\n *\r\n * This doesn't extend the **Class** object because it's meant to be a small extension of the native URL class.\r\n *\r\n * @export\r\n * @class URL\r\n * @extends {URL}\r\n */\r\n// Read up on the native URL class [devdocs.io/dom/url]\r\n/**\r\n * Creates an instance of URL.\r\n *\r\n * @param {(string | URL | Location)} [url=window.location.pathname]\r\n * @return URL\r\n */\r\nexport const newURL = (url: string | URL | Location = window.location.href): URL => {\r\n return url instanceof URL ? url : new URL(url as unknown as string, window.location.origin);\r\n};\r\n\r\n/**\r\n * Returns the pathname with the hash\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const getHashedPath = (url: URL): string => (`${url.pathname}${url.hash}`);\r\n\r\n/**\r\n * Returns the actual hash without the hashtag\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const getHash = (url: URL): string => (url.hash.slice(1));\r\n\r\n/**\r\n * Removes the hash from the full URL for a clean URL string\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const clean = (url: URL): string => (url.toString().replace(/(\\/#.*|\\/|#.*)$/, ''));\r\n\r\n/**\r\n * Compares two URLs to each other\r\n *\r\n * @param {URL} a\r\n * @param {URL} b\r\n * @returns boolean\r\n */\r\nexport const equal = (a: URL | string, b: URL | string): boolean => {\r\n let urlA = newURL(a);\r\n let urlB = newURL(b);\r\n return clean(urlA) === clean(urlB);\r\n};\r\n", "import { getHashedPath, newURL } from \"./url\";\r\n\r\nexport type Trigger = HTMLAnchorElement | \"HistoryManager\" | \"popstate\" | \"back\" | \"forward\";\r\nexport interface ICoords {\r\n\treadonly x: number;\r\n\treadonly y: number;\r\n}\r\n\r\nexport interface IStateData {\r\n\tscroll: ICoords;\r\n\t[key: string]: any;\r\n}\r\n\r\nexport interface IState {\r\n\turl: string;\r\n\tindex?: number;\r\n\ttransition: string;\r\n\tdata: IStateData;\r\n}\r\n\r\nexport interface IHistoryItem {\r\n\tindex: number;\r\n\tstates: IState[];\r\n}\r\n\r\n/**\r\n * A quick snapshot of page coordinates, e.g. scroll positions\r\n *\r\n * @export\r\n * @param {number} [x=window.scrollX]\r\n * @param {number} [y=window.scrollY]\r\n */\r\nexport const newCoords = (x: number = window.scrollX, y: number = window.scrollY): ICoords => ({ x, y });\r\n\r\n/**\r\n * Represents the current status of the page consisting of properties like: url, transition, and data\r\n *\r\n * @export\r\n * @param {IState} {\r\n * url = getHashedPath(newURL()),\r\n * index = 0,\r\n * transition = \"default\",\r\n * data = {\r\n * scroll: newCoords(),\r\n * trigger: \"HistoryManager\"\r\n * }\r\n * }\r\n * @memberof State\r\n*/\r\nexport const newState = (state: IState = {\r\n\turl: getHashedPath(newURL()),\r\n\tindex: 0,\r\n\ttransition: \"default\",\r\n\tdata: {\r\n\t\tscroll: newCoords(),\r\n\t\ttrigger: \"HistoryManager\"\r\n\t}\r\n}): IState => (state);\r\n\r\n\r\n/**\r\n * History of the site, stores only the State class\r\n *\r\n * @export\r\n * @class HistoryManager\r\n * @extends {Manager}\r\n */\r\nexport class HistoryManager {\r\n\tpublic states: IState[];\r\n\tpublic pointer = -1;\r\n\r\n\t/**\r\n\t * Creates an instance of the HistoryManager class, which inherits properties and methods from the Storage class.\r\n\t *\r\n\t * @memberof HistoryManager\r\n\t * @constructor\r\n\t */\r\n\tconstructor() {\r\n\t\tthis.states = [];\r\n\r\n\t\tlet state = newState();\r\n\t\tthis.add(state, \"replace\");\r\n\t}\r\n\r\n\tpublic get(index: number) {\r\n\t\treturn this.states[index];\r\n\t}\r\n\r\n\t/**\r\n\t * Sets the index of the state before adding to HistoryManager\r\n\t *\r\n\t * @param {IState} value\r\n\t * @returns HistoryManager\r\n\t */\r\n\tpublic add(value?: IState, historyAction: \"replace\" | \"push\" = \"push\"): HistoryManager {\r\n\t\tlet state = newState(value);\r\n\t\tlet len = this.length;\r\n\t\tthis.states.push({ ...state });\r\n\t\tthis.pointer = len;\r\n\r\n\t\tlet item: IHistoryItem = {\r\n\t\t\tindex: this.pointer,\r\n\t\t\tstates: [...this.states]\r\n\t\t};\r\n\t\tchangeState(historyAction, state, item);\r\n\t\treturn this;\r\n\t}\r\n\r\n\tpublic remove(index?: number) {\r\n\t\tif (index) {\r\n\t\t\tthis.states.splice(index, 1);\r\n\t\t} else {\r\n\t\t\tthis.states.pop();\r\n\t\t}\r\n\r\n\t\tthis.pointer--;\r\n\t\treturn this;\r\n\t}\r\n\r\n\tpublic replace(newStates: IState[]) {\r\n\t\tthis.states = newStates;\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Set state by index.\r\n\t */\r\n\tpublic set(i: number, state: IState) {\r\n\t\treturn (this.states[i] = state);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the current state.\r\n\t */\r\n\tget current(): IState {\r\n\t\treturn this.get(this.pointer);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the last state (top of the history stack).\r\n\t */\r\n\tget last(): IState {\r\n\t\treturn this.get(this.length - 1);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the previous state.\r\n\t */\r\n\tget previous(): IState | null {\r\n\t\treturn this.pointer < 1 ? null : this.get(this.pointer - 1);\r\n\t}\r\n\r\n\tget length() {\r\n\t\treturn this.states.length;\r\n\t}\r\n\r\n}\r\n\r\n/**\r\n * Either push or replace history state\r\n *\r\n * @param {(\"push\" | \"replace\")} action\r\n * @param {IState} state\r\n * @param {_URL} url\r\n * @memberof PJAX\r\n */\r\nexport const changeState = (action: \"push\" | \"replace\", state: IState, item: object) => {\r\n\tlet href = getHashedPath(newURL(state.url));\r\n\tlet args = [item, \"\", href];\r\n\tif (window.history) {\r\n\t\tswitch (action) {\r\n\t\t\tcase \"push\":\r\n\t\t\t\twindow.history.pushState.apply(window.history, args);\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"replace\":\r\n\t\t\t\twindow.history.replaceState.apply(window.history, args);\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n", "import { Manager, ManagerItem, AdvancedManager } from \"./manager\";\r\nimport { equal, newURL } from \"./url\";\r\nimport { App } from \"./app\";\r\n\r\n/**\r\n * Parses strings to DOM\r\n */\r\nexport const PARSER: DOMParser = new DOMParser();\r\n\r\n/**\r\n * A page represents the DOM elements that create each page\r\n *\r\n * @export\r\n * @class Page\r\n */\r\nexport class Page extends ManagerItem {\r\n /**\r\n * Holds the DOM of the current page\r\n *\r\n * @public\r\n * @type Document\r\n * @memberof Page\r\n */\r\n public dom: Document;\r\n\r\n /**\r\n * Holds the wrapper element to be swapped out of each Page\r\n *\r\n * @public\r\n * @type HTMLElement\r\n * @memberof Page\r\n */\r\n public wrapper: HTMLElement;\r\n\r\n /**\r\n * Holds the title of each page\r\n *\r\n * @public\r\n * @type string\r\n * @memberof Page\r\n */\r\n public title: string;\r\n\r\n /**\r\n * Holds the head element of each page\r\n *\r\n * @public\r\n * @type Element\r\n * @memberof Page\r\n */\r\n public head: Element;\r\n\r\n /**\r\n * Holds the body element of each page\r\n *\r\n * @public\r\n * @type Element\r\n * @memberof Page\r\n */\r\n public body: Element;\r\n\r\n /**\r\n * The URL of the current page\r\n *\r\n * @public\r\n * @type URL\r\n * @memberof Page\r\n */\r\n public url: URL;\r\n public data: string;\r\n public wrapperAttr: string;\r\n\r\n /**\r\n * Creates an instance of Page, it also creates a new page from response text, or a Document Object\r\n *\r\n * @param {URL} [url = newURL()]\r\n * @param {(string | Document)} [dom=document]\r\n * @memberof Page\r\n */\r\n constructor(url: URL = newURL(), dom: string | Document = document) {\r\n super();\r\n this.url = url;\r\n\r\n if (typeof dom === \"string\") {\r\n this.data = dom;\r\n } else this.dom = dom || document;\r\n }\r\n\r\n public async build() {\r\n if (!(this.dom instanceof Node)) {\r\n this.dom = PARSER.parseFromString(this.data, \"text/html\");\r\n }\r\n\r\n if (!(this.body instanceof Node)) {\r\n let { title, head, body } = this.dom;\r\n this.title = title;\r\n this.head = head;\r\n this.body = body;\r\n this.wrapper = this.body.querySelector(this.wrapperAttr);\r\n }\r\n }\r\n\r\n /**\r\n * Runs once the the manager and config have been registered\r\n *\r\n * @returns void\r\n * @memberof Page\r\n */\r\n public install(): void {\r\n this.wrapperAttr = this.config.getConfig(\"wrapperAttr\");\r\n }\r\n\r\n public uninstall() {\r\n this.url = undefined;\r\n this.title = undefined;\r\n this.head = undefined;\r\n this.body = undefined;\r\n this.dom = undefined;\r\n this.wrapper = undefined;\r\n this.data = undefined;\r\n this.wrapperAttr = undefined;\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Controls which page to be load\r\n *\r\n * @export\r\n * @class PageManager\r\n * @extends {AdvancedManager}\r\n */\r\nexport class PageManager extends AdvancedManager {\r\n /**\r\n * Stores all URLs that are currently loading\r\n *\r\n * @public\r\n * @type Manager>\r\n * @memberof PageManager\r\n */\r\n public loading: Manager> = new Manager();\r\n public maxPages = 5;\r\n\r\n /**\r\n * Creates an instance of the PageManager\r\n *\r\n * @param {App} app\r\n * @memberof PageManager\r\n */\r\n constructor(app: App) {\r\n super(app);\r\n let URLString = newURL().pathname;\r\n this.set(URLString, new Page());\r\n URLString = undefined;\r\n }\r\n\r\n /**\r\n * Load from cache or by requesting URL via a fetch request, avoid requesting for the same thing twice by storing the fetch request in \"this.loading\"\r\n *\r\n * @param {(URL | string)} [_url=newURL()]\r\n * @returns Promise\r\n * @memberof PageManager\r\n */\r\n public async load(_url: URL | string = newURL()): Promise {\r\n let url: URL = newURL(_url);\r\n let urlString: string = url.pathname;\r\n let page: Page, request: Promise;\r\n if (this.has(urlString)) {\r\n page = this.get(urlString);\r\n return Promise.resolve(page);\r\n }\r\n\r\n if (!this.loading.has(urlString)) {\r\n request = this.request(urlString);\r\n this.loading.set(urlString, request);\r\n } else request = this.loading.get(urlString);\r\n\r\n let response = await request;\r\n this.loading.delete(urlString);\r\n\r\n page = new Page(url, response);\r\n this.set(urlString, page);\r\n\r\n if (this.size > this.maxPages) {\r\n let currentUrl = newURL();\r\n let keys = this.keys();\r\n let first = equal(currentUrl, keys[0]) ? keys[1] : keys[0];\r\n let page = this.get(first);\r\n page.unregister();\r\n page = undefined;\r\n keys = undefined;\r\n currentUrl = undefined;\r\n first = undefined;\r\n }\r\n return page;\r\n }\r\n\r\n /**\r\n * Starts a fetch request\r\n *\r\n * @param {string} url\r\n * @returns Promise\r\n * @memberof PageManager\r\n */\r\n public async request(url: string): Promise {\r\n const headers = new Headers(this.config.getConfig(\"headers\"));\r\n const timeout = window.setTimeout(() => {\r\n window.clearTimeout(timeout);\r\n throw \"Request Timed Out!\";\r\n }, this.config.getConfig(\"timeout\"));\r\n\r\n try {\r\n let response = await fetch(url, {\r\n mode: 'same-origin',\r\n method: \"GET\",\r\n headers,\r\n cache: \"default\",\r\n credentials: \"same-origin\",\r\n });\r\n\r\n window.clearTimeout(timeout);\r\n if (response.status >= 200 && response.status < 300) {\r\n return await response.text();\r\n }\r\n\r\n const err = new Error(response.statusText || \"\" + response.status);\r\n throw err;\r\n } catch (err) {\r\n window.clearTimeout(timeout);\r\n throw err;\r\n }\r\n }\r\n}\r\n", "import { Manager } from \"@okikio/manager\";\r\n\r\nexport type ListenerCallback = ((...args: any) => void);\r\nexport interface IListener {\r\n readonly callback: ListenerCallback;\r\n readonly scope: object;\r\n readonly name: string;\r\n}\r\n\r\n/**\r\n * Represents a new event listener consisting of properties like: callback, scope, name\r\n *\r\n * @export\r\n */\r\nexport const newListener = ({\r\n callback = () => { },\r\n scope = null,\r\n name = \"event\",\r\n}: IListener): IListener => ({ callback, scope, name });\r\n\r\n/**\r\n * Represents a new event listener consisting of properties like: callback, scope, name\r\n *\r\n * @export\r\n * @class Event\r\n * @extends {Manager}\r\n */\r\nexport class Event extends Manager {\r\n /**\r\n * The name of the event\r\n *\r\n * @public\r\n * @type string\r\n * @memberof Event\r\n */\r\n public name: string;\r\n\r\n /**\r\n * Creates an instance of Event.\r\n *\r\n * @param {string} [name=\"event\"]\r\n * @memberof Event\r\n */\r\n constructor(name: string = \"event\") {\r\n super();\r\n this.name = name;\r\n }\r\n}\r\n\r\nexport type EventInput = string | object | Array;\r\n\r\n/**\r\n * An event emitter\r\n *\r\n * @export\r\n * @class EventEmitter\r\n * @extends {Manager}\r\n */\r\nexport class EventEmitter extends Manager {\r\n /**\r\n * Creates an instance of EventEmitter.\r\n *\r\n * @memberof EventEmitter\r\n */\r\n constructor() {\r\n super();\r\n }\r\n\r\n /**\r\n * Gets events, if event doesn't exist create a new Event\r\n *\r\n * @param {string} name\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public getEvent(name: string): Event {\r\n let event = this.get(name);\r\n if (!(event instanceof Event)) {\r\n this.set(name, new Event(name));\r\n return this.get(name);\r\n }\r\n\r\n return event;\r\n }\r\n /**\r\n * Creates a new listener and adds it to the event\r\n *\r\n * @param {string} name\r\n * @param {ListenerCallback} callback\r\n * @param {object} scope\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public newListener(\r\n name: string,\r\n callback: ListenerCallback,\r\n scope: object\r\n ): Event {\r\n let event = this.getEvent(name);\r\n event.add(newListener({ name, callback, scope }));\r\n return event;\r\n }\r\n\r\n /**\r\n * Adds a listener for a given event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback | object} callback\r\n * @param {object} scope\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public on(\r\n events: EventInput,\r\n callback?: ListenerCallback | object,\r\n scope?: object\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n let _name: string;\r\n let _callback: ListenerCallback;\r\n let isObject = typeof events == \"object\" && !Array.isArray(events);\r\n\r\n let _scope: object = isObject ? callback : scope;\r\n if (!isObject) _callback = (callback as ListenerCallback);\r\n\r\n // Loop through the list of events\r\n Object.keys(events).forEach(key => {\r\n // Select the name of the event from the list\r\n // Remember events can be {String | Object | Array}\r\n\r\n // Check If events is an Object (JSON like Object, and not an Array)\r\n if (isObject) {\r\n _name = key;\r\n _callback = events[key];\r\n } else {\r\n _name = events[key];\r\n }\r\n\r\n this.newListener(_name, _callback, _scope);\r\n }, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes a listener from an event\r\n *\r\n * @param {string} name\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public removeListener(\r\n name: string,\r\n callback: ListenerCallback,\r\n scope: object\r\n ): Event {\r\n let event: Event = this.get(name);\r\n if (event instanceof Event && callback) {\r\n let listener = newListener({ name, callback, scope });\r\n\r\n event.forEach((value: IListener, i: number) => {\r\n if (\r\n value.callback === listener.callback &&\r\n value.scope === listener.scope\r\n ) {\r\n return event.delete(i);\r\n }\r\n });\r\n }\r\n\r\n return event;\r\n }\r\n\r\n /**\r\n * Removes a listener from a given event, or it just completely removes an event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback | object} [callback]\r\n * @param {object} [scope]\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public off(\r\n events: EventInput,\r\n callback?: ListenerCallback | object,\r\n scope?: object\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n let _name: string;\r\n let _callback: ListenerCallback;\r\n let isObject = typeof events == \"object\" && !Array.isArray(events);\r\n\r\n let _scope: object = isObject ? callback : scope;\r\n if (!isObject) _callback = (callback as ListenerCallback);\r\n\r\n // Loop through the list of events\r\n Object.keys(events).forEach(key => {\r\n // Select the name of the event from the list\r\n // Remember events can be {String | Object | Array}\r\n\r\n // Check If events is an Object (JSON like Object, and not an Array)\r\n if (isObject) {\r\n _name = key;\r\n _callback = events[key];\r\n } else {\r\n _name = events[key];\r\n }\r\n\r\n if (typeof _callback === \"function\") {\r\n this.removeListener(_name, _callback, _scope);\r\n } else this.delete(_name);\r\n }, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Call all listeners within an event\r\n *\r\n * @param {(string | Array)} events\r\n * @param {...any} args\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public emit(\r\n events: string | Array,\r\n ...args: any\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n // Loop through the list of events\r\n events.forEach((event: string) => {\r\n let _event: Event = this.get(event);\r\n\r\n if (_event instanceof Event) {\r\n _event.forEach((listener: IListener) => {\r\n let { callback, scope } = listener;\r\n callback.apply(scope, args);\r\n });\r\n }\r\n }, this);\r\n return this;\r\n }\r\n}\r\n\r\nexport default EventEmitter;\r\n", "import { AdvancedManager, ManagerItem, methodCall } from \"./manager\";\r\nimport { TransitionManager } from \"./transition\";\r\nimport { HistoryManager } from \"./history\";\r\nimport { EventEmitter } from \"./emitter\";\r\nimport { PageManager } from \"./page\";\r\nimport { App } from \"./app\";\r\n\r\n/**\r\n * Controls specific kinds of actions that require JS\r\n *\r\n * @export\r\n * @class Service\r\n */\r\nexport class Service extends ManagerItem {\r\n\t/**\r\n\t * Stores access to the App class's EventEmitter\r\n\t *\r\n\t * @public\r\n\t * @type EventEmitter\r\n\t * @memberof Service\r\n\t */\r\n\tpublic emitter: EventEmitter;\r\n\r\n\t/**\r\n\t * Stores access to the App class's PageManager\r\n\t *\r\n\t * @public\r\n\t * @type PageManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic PageManager: PageManager;\r\n\r\n\t/**\r\n\t * Stores access to the App class's HistoryManager\r\n\t *\r\n\t * @public\r\n\t * @type HistoryManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic HistoryManager: HistoryManager;\r\n\r\n\t/**\r\n\t * Stores the ServiceManager the service is install on\r\n\t *\r\n\t * @public\r\n\t * @type ServiceManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic ServiceManager: ServiceManager;\r\n\r\n\t/**\r\n\t * Stores access to the App's TransitionManager\r\n\t *\r\n\t * @public\r\n\t * @type TransitionManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic TransitionManager: TransitionManager;\r\n\r\n\t/**\r\n\t * Method is run once when Service is installed on a ServiceManager\r\n\t *\r\n\t * @memberof Service\r\n\t */\r\n\tpublic install(): void {\r\n\t\tlet { app } = this.manager;\r\n\t\tthis.PageManager = app.pages;\r\n\t\tthis.HistoryManager = app.history;\r\n\t\tthis.ServiceManager = app.services;\r\n\t\tthis.TransitionManager = app.transitions;\r\n\t}\r\n\r\n\t// Called before the start of a Service, represents a constructor of sorts\r\n\tpublic init(...args: any): void { }\r\n\r\n\t// Called on start of Service\r\n\tpublic boot(): void {\r\n\t\tthis.initEvents();\r\n\t}\r\n\r\n\t// Initialize events\r\n\tpublic initEvents(): void { }\r\n\r\n\t// Stop events\r\n\tpublic stopEvents(): void { }\r\n\r\n\tpublic uninstall() {\r\n\t\tthis.PageManager = undefined;\r\n\t\tthis.HistoryManager = undefined;\r\n\t\tthis.ServiceManager = undefined;\r\n\t\tthis.TransitionManager = undefined;\r\n\t}\r\n\r\n\t// Stop services\r\n\tpublic stop(): void {\r\n\t\tthis.stopEvents();\r\n\t\tthis.unregister();\r\n\t}\r\n}\r\n\r\n/**\r\n * The Service Manager controls the lifecycle of all services in an App\r\n *\r\n * @export\r\n * @class ServiceManager\r\n * @extends {AdvancedManager}\r\n */\r\nexport class ServiceManager extends AdvancedManager {\r\n\t/**\r\n\t * Creates an instance of ServiceManager.\r\n\t *\r\n\t * @param {App} app\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tconstructor(app: App) {\r\n\t\tsuper(app);\r\n\t}\r\n\r\n\t/**\r\n\t * Call the init method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic init(): ServiceManager {\r\n\t\tmethodCall(this, \"init\", this.app);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Call the boot method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic boot(): ServiceManager {\r\n\t\tmethodCall(this, \"boot\", this.app);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Call the stop method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic stop(): ServiceManager {\r\n\t\tmethodCall(this, \"stop\", this.app);\r\n\t\treturn this;\r\n\t}\r\n}\r\n", "import { newState, Trigger, IState, newCoords, IHistoryItem, changeState } from \"./history\";\r\nimport { Service } from \"./service\";\r\nimport { Page } from \"./page\";\r\nimport { newURL, getHashedPath, equal } from \"./url\";\r\n\r\nexport type LinkEvent = MouseEvent | TouchEvent;\r\nexport type StateEvent = LinkEvent | PopStateEvent;\r\nexport type IgnoreURLsList = Array;\r\n\r\n/**\r\n * Creates a Barba JS like PJAX Service, for the Framework\r\n *\r\n * @export\r\n * @class PJAX\r\n * @extends {Service}\r\n */\r\n// Based on Barba JS and StartingBlocks\r\nexport class PJAX extends Service {\r\n /**\r\n * URLs to ignore when prefetching\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected ignoreURLs: IgnoreURLsList = [];\r\n\r\n /**\r\n * Whether or not to disable prefetching\r\n *\r\n * @private\r\n *\r\n * @memberof PJAX\r\n */\r\n protected prefetchIgnore: boolean = false;\r\n\r\n /**\r\n * Current state or transitions\r\n *\r\n * @public\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n public isTransitioning: boolean = false;\r\n\r\n /**\r\n * Ignore extra clicks of an anchor element if a transition has already started\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected stopOnTransitioning: boolean = false;\r\n\r\n /**\r\n * On page change (excluding popstate event) keep current scroll position\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected stickyScroll: boolean = false;\r\n\r\n /**\r\n * Force load a page if an error occurs\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected forceOnError: boolean = false;\r\n\r\n /**\r\n * Dictates whether to auto scroll if an hash is present in the window URL\r\n *\r\n * @protected\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected autoScrollOnHash: boolean = true;\r\n\r\n /**\r\n * Disables all extra scroll effects of PJAX\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected dontScroll: boolean = false;\r\n\r\n /**\r\n * Sets the transition state, sets isTransitioning to true\r\n *\r\n * @private\r\n * @memberof PJAX\r\n */\r\n private transitionStart() {\r\n this.isTransitioning = true;\r\n }\r\n\r\n /**\r\n * Sets the transition state, sets isTransitioning to false\r\n *\r\n * @private\r\n * @memberof PJAX\r\n */\r\n private transitionStop() {\r\n this.isTransitioning = false;\r\n }\r\n\r\n public init() {\r\n super.init();\r\n\r\n /**\r\n * Bind the event listeners to the PJAX class\r\n *\r\n * @memberof PJAX\r\n */\r\n this.onHover = this.onHover.bind(this);\r\n this.onClick = this.onClick.bind(this);\r\n this.onStateChange = this.onStateChange.bind(this);\r\n }\r\n\r\n /**\r\n * Starts the PJAX Service\r\n *\r\n * @memberof PJAX\r\n */\r\n public boot() {\r\n if (\"scrollRestoration\" in window.history) {\r\n // Back off, browser, I got this...\r\n window.history.scrollRestoration = \"manual\";\r\n }\r\n\r\n super.boot();\r\n }\r\n\r\n /**\r\n * Gets the transition to use for a certain anchor\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @returns {(string | null)}\r\n * @memberof PJAX\r\n */\r\n public getTransitionName(el: HTMLAnchorElement): string | null {\r\n if (!el || !el.getAttribute) return null;\r\n let transitionAttr = el.getAttribute(\r\n this.config.getConfig(\"transitionAttr\", false)\r\n );\r\n if (typeof transitionAttr === \"string\") return transitionAttr;\r\n return null;\r\n }\r\n\r\n /**\r\n * Checks to see if the anchor is valid\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @param {(LinkEvent | KeyboardEvent)} event\r\n * @param {string} href\r\n *\r\n * @memberof PJAX\r\n */\r\n public validLink(\r\n el: HTMLAnchorElement,\r\n event: LinkEvent | KeyboardEvent,\r\n href: string\r\n ): boolean {\r\n let pushStateSupport = !window.history.pushState;\r\n let exists = !el || !href;\r\n let eventMutate =\r\n (event as KeyboardEvent).metaKey ||\r\n (event as KeyboardEvent).ctrlKey ||\r\n (event as KeyboardEvent).shiftKey ||\r\n (event as KeyboardEvent).altKey;\r\n let newTab =\r\n el.hasAttribute(\"target\") &&\r\n (el as HTMLAnchorElement).target === \"_blank\";\r\n let crossOrigin =\r\n (el as HTMLAnchorElement).protocol !== location.protocol ||\r\n (el as HTMLAnchorElement).hostname !== location.hostname;\r\n let download = typeof el.getAttribute(\"download\") === \"string\";\r\n let preventSelf = el.hasAttribute(this.config.getConfig(\"preventSelfAttr\", false));\r\n let preventAll = Boolean(\r\n el.closest(this.config.getConfig(\"preventAllAttr\"))\r\n );\r\n let prevent = preventSelf && preventAll;\r\n let sameURL = getHashedPath(newURL()) === getHashedPath(newURL(href));\r\n return !(\r\n exists ||\r\n pushStateSupport ||\r\n eventMutate ||\r\n newTab ||\r\n crossOrigin ||\r\n download ||\r\n prevent ||\r\n sameURL\r\n );\r\n }\r\n\r\n /**\r\n * Returns the href or an Anchor element\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @returns {(string | null)}\r\n * @memberof PJAX\r\n */\r\n public getHref(el: HTMLAnchorElement): string | null {\r\n if (\r\n el &&\r\n el.tagName &&\r\n el.tagName.toLowerCase() === \"a\" &&\r\n typeof el.href === \"string\"\r\n )\r\n return el.href;\r\n return null;\r\n }\r\n\r\n /**\r\n * Check if event target is a valid anchor with an href, if so, return the link\r\n *\r\n * @param {LinkEvent} event\r\n *\r\n * @memberof PJAX\r\n */\r\n public getLink(event: LinkEvent): HTMLAnchorElement {\r\n let el = event.target as HTMLAnchorElement;\r\n let href: string = this.getHref(el);\r\n\r\n while (el && !href) {\r\n el = (el as HTMLElement).parentNode as HTMLAnchorElement;\r\n href = this.getHref(el);\r\n }\r\n\r\n // Check for a valid link\r\n if (!el || !this.validLink(el, event, href)) return;\r\n return el;\r\n }\r\n\r\n /**\r\n * When an element is clicked.\r\n *\r\n * Get valid anchor element.\r\n * Go for a transition.\r\n *\r\n * @param {LinkEvent} event\r\n * @returns\r\n * @memberof PJAX\r\n */\r\n public onClick(event: LinkEvent) {\r\n let el = this.getLink(event);\r\n if (!el) return;\r\n\r\n if (this.isTransitioning && this.stopOnTransitioning) {\r\n event.preventDefault();\r\n event.stopPropagation();\r\n return;\r\n }\r\n\r\n let href = this.getHref(el);\r\n this.emitter.emit(\"ANCHOR_CLICK CLICK\", event);\r\n this.go({ href, trigger: el, event });\r\n }\r\n\r\n /**\r\n * Returns the direction of the State change as a String, either the Back button or the Forward button\r\n *\r\n * @param {number} value\r\n *\r\n * @memberof PJAX\r\n */\r\n public getDirection(value: number): Trigger {\r\n if (Math.abs(value) > 1) {\r\n // Ex 6-0 > 0 -> forward, 0-6 < 0 -> back\r\n return value > 0 ? \"forward\" : \"back\";\r\n } else {\r\n if (value === 0) {\r\n return \"popstate\";\r\n } else {\r\n // Ex 6-5 > 0 -> back, 5-6 < 0 -> forward\r\n return value > 0 ? \"back\" : \"forward\";\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Force a page to go to a certain URL\r\n *\r\n * @param {string} href\r\n * @memberof PJAX\r\n */\r\n public force(href: string): void {\r\n window.location.assign(href);\r\n }\r\n\r\n /**\r\n * If transition is running force load page.\r\n * Stop if currentURL is the same as new url.\r\n * On state change, change the current state history,\r\n * to reflect the direction of said state change\r\n * Load page and page transition.\r\n *\r\n * @param {string} href\r\n * @param {Trigger} [trigger='HistoryManager']\r\n * @param {StateEvent} [event]\r\n * @memberof PJAX\r\n */\r\n public go({\r\n href,\r\n trigger = \"HistoryManager\",\r\n event,\r\n }: {\r\n href: string;\r\n trigger?: Trigger;\r\n event?: StateEvent;\r\n }): Promise {\r\n // If transition is already running and the go method is called again, force load page\r\n if (this.isTransitioning && this.stopOnTransitioning) {\r\n this.force(href);\r\n return;\r\n }\r\n\r\n let scroll = { x: 0, y: 0 };\r\n let currentState = this.HistoryManager.current;\r\n let currentURL = currentState.url;\r\n if (equal(currentURL, href)) {\r\n return;\r\n }\r\n\r\n let transitionName: string;\r\n if (event && (event as PopStateEvent).state) {\r\n this.emitter.emit(\"POPSTATE\", event);\r\n\r\n // If popstate, get back/forward direction.\r\n let { state }: { state: IHistoryItem } = event as PopStateEvent;\r\n let { index } = state;\r\n let currentIndex = currentState.index;\r\n let difference = currentIndex - index;\r\n\r\n trigger = this.getDirection(difference);\r\n\r\n let _state = this.HistoryManager.get(this.HistoryManager.pointer);\r\n transitionName = _state.transition;\r\n scroll = _state.data.scroll;\r\n\r\n // Based on the direction of the state change either remove or add a state\r\n this.HistoryManager.replace(state.states);\r\n this.HistoryManager.pointer = index;\r\n if (trigger === \"back\") {\r\n // this.HistoryManager.remove(currentIndex);\r\n this.emitter.emit(`POPSTATE_BACK`, event);\r\n } else if (trigger === \"forward\") {\r\n // this.HistoryManager.add({ url: href, transition, data });\r\n this.emitter.emit(`POPSTATE_FORWARD`, event);\r\n }\r\n\r\n } else {\r\n // Add new state\r\n transitionName = this.getTransitionName(trigger as HTMLAnchorElement) ||\r\n \"default\";\r\n\r\n scroll = newCoords();\r\n\r\n let state = newState({\r\n url: href,\r\n transition: transitionName,\r\n data: { scroll },\r\n });\r\n\r\n this.HistoryManager.add(state);\r\n this.emitter.emit(\"HISTORY_NEW_ITEM\", event);\r\n }\r\n\r\n if (event) {\r\n event.stopPropagation();\r\n event.preventDefault();\r\n }\r\n\r\n this.emitter.emit(\"GO\", event);\r\n return this.load({\r\n oldHref: currentURL,\r\n href,\r\n trigger,\r\n transitionName,\r\n scroll,\r\n });\r\n }\r\n\r\n /**\r\n * Load the new Page as well as a Transition; run the Transition\r\n *\r\n * @param {string} oldHref\r\n * @param {string} href\r\n * @param {Trigger} trigger\r\n * @param {string} [transitionName=\"default\"]\r\n *\r\n * @memberof PJAX\r\n */\r\n public async load({\r\n oldHref,\r\n href,\r\n trigger,\r\n transitionName = \"default\",\r\n scroll = { x: 0, y: 0 },\r\n }: {\r\n oldHref: string;\r\n href: string;\r\n trigger: Trigger;\r\n transitionName?: string;\r\n scroll: { x: number; y: number };\r\n }): Promise {\r\n try {\r\n let oldPage = await this.PageManager.load(oldHref);\r\n await oldPage.build();\r\n let newPage: Page;\r\n\r\n this.emitter.emit(\"PAGE_LOADING\", { href, oldPage, trigger });\r\n try {\r\n try {\r\n newPage = await this.PageManager.load(href);\r\n await newPage.build();\r\n this.transitionStart();\r\n this.emitter.emit(\"PAGE_LOAD_COMPLETE\", {\r\n newPage,\r\n oldPage,\r\n trigger,\r\n });\r\n } catch (err) {\r\n console.error(`[PJAX] page load error: ${err}`);\r\n }\r\n\r\n // --\r\n // --\r\n\r\n this.emitter.emit(\"NAVIGATION_START\", {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n transitionName,\r\n });\r\n\r\n try {\r\n this.emitter.emit(\"TRANSITION_START\", transitionName);\r\n\r\n let transition = await this.TransitionManager.boot(transitionName, {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n scroll,\r\n });\r\n\r\n if (!transition.scrollable) {\r\n if (!/back|popstate|forward/.test(trigger as string)) {\r\n scroll = hashAction();\r\n }\r\n\r\n window.scroll(scroll.x, scroll.y);\r\n }\r\n\r\n this.emitter.emit(\"TRANSITION_END\", { transition });\r\n\r\n } catch (err) {\r\n console.error(`[PJAX] transition error: ${err}`);\r\n }\r\n\r\n this.emitter.emit(\"NAVIGATION_END\", {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n transitionName,\r\n });\r\n } catch (err) {\r\n this.transitionStop();\r\n throw err;\r\n }\r\n\r\n this.transitionStop(); // Sets isTransitioning to false\r\n } catch (err) {\r\n if (this.forceOnError) this.force(href);\r\n else console.error(err);\r\n }\r\n }\r\n\r\n /**\r\n * Check to see if the URL is to be ignored, uses either RegExp of Strings to check\r\n *\r\n * @param {URL} { pathname }\r\n *\r\n * @memberof PJAX\r\n */\r\n public ignoredURL({ pathname }: URL): boolean {\r\n return (\r\n this.ignoreURLs.length &&\r\n this.ignoreURLs.some((url) => {\r\n return typeof url === \"string\"\r\n ? url === pathname\r\n : (url as RegExp).exec(pathname) !== null;\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * When you hover over an anchor, prefetch the event target's href\r\n *\r\n * @param {LinkEvent} event\r\n * @memberof PJAX\r\n */\r\n public onHover(event: LinkEvent): Promise {\r\n let el = this.getLink(event);\r\n if (!el) return;\r\n\r\n let url = newURL(this.getHref(el));\r\n let urlString: string = url.pathname;\r\n // If Url is ignored or already in cache, don't do any think\r\n if (this.ignoredURL(url) || this.PageManager.has(urlString)) return;\r\n this.emitter.emit(\"ANCHOR_HOVER HOVER\", event);\r\n\r\n try {\r\n this.PageManager.load(url);\r\n } catch (err) {\r\n console.warn(\"[PJAX] prefetch error,\", err);\r\n }\r\n }\r\n\r\n /**\r\n * When History state changes.\r\n *\r\n * Get url from State\r\n * Go for a Barba transition.\r\n *\r\n * @param {PopStateEvent} event\r\n * @memberof PJAX\r\n */\r\n public onStateChange(event: PopStateEvent): void {\r\n this.go({ href: window.location.href, trigger: \"popstate\", event });\r\n }\r\n\r\n /**\r\n * Initialize DOM Events\r\n *\r\n * @memberof PJAX\r\n */\r\n public initEvents() {\r\n if (this.prefetchIgnore !== true) {\r\n document.addEventListener(\"mouseover\", this.onHover);\r\n document.addEventListener(\"touchstart\", this.onHover);\r\n }\r\n\r\n document.addEventListener(\"click\", this.onClick);\r\n window.addEventListener(\"popstate\", this.onStateChange);\r\n }\r\n\r\n /**\r\n * Stop DOM Events\r\n *\r\n * @memberof PJAX\r\n */\r\n public stopEvents() {\r\n if (this.prefetchIgnore !== true) {\r\n document.removeEventListener(\"mouseover\", this.onHover);\r\n document.removeEventListener(\"touchstart\", this.onHover);\r\n }\r\n\r\n document.removeEventListener(\"click\", this.onClick);\r\n window.removeEventListener(\"popstate\", this.onStateChange);\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Auto scrolls to an elements position if the element has an hash\r\n *\r\n * @param {string} [hash=window.location.hash]\r\n * @memberof PJAX\r\n */\r\nexport const hashAction = (hash: string = window.location.hash) => {\r\n try {\r\n\r\n let _hash = hash[0] == \"#\" ? hash : newURL(hash).hash;\r\n if (_hash.length > 1) {\r\n let el = document.getElementById(_hash.slice(1)) as HTMLElement;\r\n\r\n if (el) {\r\n return newCoords(el.offsetLeft, el.offsetTop);\r\n }\r\n }\r\n } catch (e) {\r\n console.warn(\"hashAction error\", e);\r\n }\r\n\r\n return newCoords(0, 0);\r\n};\r\n", "import { Manager } from \"./manager\";\r\nimport { EventEmitter } from \"./emitter\";\r\nimport { ICoords, Trigger } from \"./history\";\r\nimport { Page } from \"./page\";\r\nimport { App } from \"./app\";\r\nimport { CONFIG } from \"./config\";\r\nimport { hashAction } from \"./pjax\";\r\n\r\n/**\r\n * The async function type, allows for smooth transition between Promises\r\n */\r\nexport type asyncFn = (err?: any, value?: any) => void;\r\nexport interface ITransition {\r\n oldPage?: Page;\r\n newPage?: Page;\r\n trigger?: Trigger;\r\n scroll?: { x: number; y: number };\r\n scrollable?: boolean;\r\n in: (data: ITransitionData) => any;\r\n out: (data: ITransitionData) => any;\r\n [key: string]: any;\r\n}\r\nexport interface ITransitionData {\r\n from?: Page;\r\n to?: Page;\r\n trigger?: Trigger;\r\n scroll?: ICoords;\r\n done: asyncFn;\r\n}\r\n\r\n/**\r\n * Controls which animation between pages to use\r\n *\r\n * @export\r\n * @class TransitionManager\r\n * @extends {Manager}\r\n */\r\nexport class TransitionManager extends Manager {\r\n /**\r\n * The instance of the App class, the Manager is instantiated in\r\n *\r\n * @type App\r\n * @memberof AdvancedManager\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof AdvancedManager\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * The EventEmitter class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof AdvancedManager\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * Creates an instance of the TransitionManager\r\n *\r\n * @param {App} app\r\n * @memberof TransitionManager\r\n */\r\n constructor(app: App) {\r\n super();\r\n this.app = app;\r\n this.config = app.config;\r\n this.emitter = app.emitter;\r\n }\r\n\r\n /**\r\n * Runs a transition\r\n *\r\n * @param {{ name: string, oldPage: Page, newPage: Page, trigger: Trigger }} data\r\n * @returns Promise\r\n * @memberof TransitionManager\r\n */\r\n public async boot(name: string, data: any): Promise {\r\n let transition: ITransition = this.get(name);\r\n let scroll = data.scroll;\r\n if (!(data.oldPage instanceof Page) || !(data.newPage instanceof Page))\r\n throw `[Page] either oldPage or newPage aren't instances of the Page Class.\\n ${{\r\n newPage: data.newPage,\r\n oldPage: data.oldPage,\r\n }}`;\r\n\r\n let fromWrapper = data.oldPage.wrapper;\r\n let toWrapper = data.newPage.wrapper;\r\n document.title = `` + data.newPage.title;\r\n\r\n if (!(fromWrapper instanceof Node) || !(toWrapper instanceof Node))\r\n throw `[Wrapper] the wrapper from the ${!(toWrapper instanceof Node) ? \"next\" : \"current\"\r\n } page cannot be found. The wrapper must be an element that has the attribute ${this.config.getConfig(\r\n \"wrapperAttr\"\r\n )}.`;\r\n transition.init && transition?.init(data);\r\n\r\n this.emitter.emit(\"BEFORE_TRANSITION_OUT\");\r\n await new Promise((done) => {\r\n let outMethod: Promise = transition.out.call(transition, {\r\n ...data,\r\n from: data.oldPage,\r\n trigger: data.trigger,\r\n done,\r\n });\r\n\r\n if (outMethod.then) outMethod.then(done);\r\n });\r\n\r\n this.emitter.emit(\"AFTER_TRANSITION_OUT\");\r\n await new Promise((done) => {\r\n fromWrapper.insertAdjacentElement(\"beforebegin\", toWrapper);\r\n this.emitter.emit(\"CONTENT_INSERT\");\r\n\r\n if (!/back|popstate|forward/.test(data.trigger as string)) {\r\n scroll = hashAction();\r\n }\r\n done();\r\n });\r\n\r\n await new Promise((done) => {\r\n fromWrapper.remove();\r\n fromWrapper = undefined;\r\n toWrapper = undefined;\r\n this.emitter.emit(\"CONTENT_REPLACED\");\r\n done();\r\n });\r\n\r\n this.emitter.emit(\"BEFORE_TRANSITION_IN\");\r\n\r\n await new Promise((done) => {\r\n let inMethod: Promise = transition.in.call(transition, {\r\n ...data,\r\n from: data.oldPage,\r\n to: data.newPage,\r\n trigger: data.trigger,\r\n scroll,\r\n done,\r\n });\r\n\r\n if (inMethod.then) inMethod.then(done);\r\n });\r\n\r\n this.emitter.emit(\"AFTER_TRANSITION_IN\");\r\n return transition;\r\n }\r\n}\r\n", "import { EventEmitter, ListenerCallback, EventInput } from \"./emitter\";\r\nimport { ITransition, TransitionManager } from \"./transition\";\r\nimport { HistoryManager, IState } from \"./history\";\r\nimport { ServiceManager, Service } from \"./service\";\r\nimport { PageManager } from \"./page\";\r\nimport { CONFIG, ICONFIG } from \"./config\";\r\n\r\n/**\r\n * The App class starts the entire process, it controls all managers and all services\r\n *\r\n * @export\r\n * @class App\r\n */\r\nexport class App {\r\n /**\r\n * A new instance of the HistoryManager\r\n *\r\n * @public\r\n * @type HistoryManager\r\n * @memberof App\r\n */\r\n public history: HistoryManager;\r\n\r\n /**\r\n * A new instance of the TransitionManager\r\n *\r\n * @public\r\n * @type TransitionManager\r\n * @memberof App\r\n */\r\n public transitions: TransitionManager;\r\n\r\n /**\r\n * A new instance of the ServiceManager\r\n *\r\n * @public\r\n * @type ServiceManager\r\n * @memberof App\r\n */\r\n public services: ServiceManager;\r\n\r\n /**\r\n * A new instance of an EventEmitter\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof App\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * A new instance of the PageManager\r\n *\r\n * @public\r\n * @type PageManager\r\n * @memberof App\r\n */\r\n public pages: PageManager;\r\n\r\n /**\r\n * The current Configuration's for the framework\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof App\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * Creates an instance of App.\r\n *\r\n * @param {(ICONFIG | CONFIG)} [config={}]\r\n * @memberof App\r\n */\r\n constructor(config: object = {}) {\r\n this.register(config);\r\n }\r\n\r\n /**\r\n * For registering all managers and the configurations\r\n *\r\n * @param {(ICONFIG | CONFIG)} [config={}]\r\n * @returns App\r\n * @memberof App\r\n */\r\n public register(config: ICONFIG | CONFIG = {}): App {\r\n this.config = config instanceof CONFIG ? config : new CONFIG(config);\r\n this.emitter = new EventEmitter();\r\n this.history = new HistoryManager();\r\n this.pages = new PageManager(this);\r\n this.transitions = new TransitionManager(this);\r\n this.services = new ServiceManager(this);\r\n\r\n let handler = (() => {\r\n document.removeEventListener(\"DOMContentLoaded\", handler);\r\n window.removeEventListener(\"load\", handler);\r\n this.emitter.emit(\"READY ready\");\r\n }).bind(this);\r\n\r\n document.addEventListener(\"DOMContentLoaded\", handler);\r\n window.addEventListener(\"load\", handler);\r\n return this;\r\n }\r\n\r\n /**\r\n * Based on the type, it will return either a Transition, a Service, or a State from their respective Managers\r\n *\r\n * @param {(\"service\" | \"transition\" | \"state\" | string)} type\r\n * @param {any} key\r\n * @returns Service | Transition | State\r\n * @memberof App\r\n */\r\n public get(type: \"service\" | \"transition\" | \"state\" | string, key: any): Service | ITransition | IState {\r\n switch (type.toLowerCase()) {\r\n case \"service\":\r\n return this.services.get(key);\r\n case \"transition\":\r\n return this.transitions.get(key);\r\n case \"state\":\r\n return this.history.get(key);\r\n default:\r\n throw `Error: can't get type '${type}', it is not a recognized type. Did you spell it correctly.`;\r\n }\r\n }\r\n\r\n /**\r\n * Based on the type, it will return load either Page a Transition, a Service, a State, or a Page from their respective Managers\r\n *\r\n * @param {(\"page\" | string)} type\r\n * @param {any} key\r\n * @returns App\r\n * @memberof App\r\n */\r\n public async load(type: \"page\" | string, key: any): Promise {\r\n switch (type.toLowerCase()) {\r\n case \"page\":\r\n return await this.pages.load(key);\r\n default:\r\n return Promise.resolve(this.get(type, key));\r\n }\r\n }\r\n\r\n /**\r\n * Adds a Service to the App's instance of the ServiceManager, with a name\r\n *\r\n * @param {string} key\r\n * @param {Service} service\r\n * @returns App\r\n * @memberof App\r\n */\r\n public setService(key: string, service: Service): App {\r\n this.services.set(key, service);\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a Service to the App's instance of the ServiceManager, with a name\r\n *\r\n * @param {string} key\r\n * @param {ITransition} tranisition\r\n * @returns App\r\n * @memberof App\r\n */\r\n public setTransition(key: string, transition: ITransition): App {\r\n this.transitions.set(key, transition);\r\n return this;\r\n }\r\n\r\n /**\r\n * Based on the type, it will add either a Transition, a Service, or a State to their respective Managers\r\n *\r\n * @param {(\"service\" | \"transition\" | \"state\")} type\r\n * @param {any} value\r\n * @returns App\r\n * @memberof App\r\n */\r\n public add(type: \"service\" | \"transition\" | \"state\", value: any): App {\r\n switch (type.toLowerCase()) {\r\n case \"service\":\r\n this.services.add(value);\r\n break;\r\n case \"transition\":\r\n this.transitions.set(value.name, value);\r\n break;\r\n case \"state\":\r\n this.history.add(value);\r\n break;\r\n default:\r\n throw `Error: can't add type '${type}', it is not a recognized type. Did you spell it correctly.`;\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Start the App and the ServiceManager\r\n *\r\n * @returns App\r\n * @memberof App\r\n */\r\n public boot(): App {\r\n this.services.init();\r\n this.services.boot();\r\n return this;\r\n }\r\n\r\n /**\r\n * Stop the App and the ServiceManager\r\n *\r\n * @returns App\r\n * @memberof App\r\n */\r\n public stop(): App {\r\n this.services.stop();\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter on method\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} callback\r\n * @returns App\r\n * @memberof App\r\n */\r\n public on(events: EventInput, callback?: ListenerCallback): App {\r\n this.emitter.on(events, callback, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter off method\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} callback\r\n * @returns App\r\n * @memberof App\r\n */\r\n public off(events: EventInput, callback?: ListenerCallback): App {\r\n this.emitter.off(events, callback, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter emit method\r\n *\r\n * @param {(string | any[])} events\r\n * @param {...any} args\r\n * @returns App\r\n * @memberof App\r\n */\r\n public emit(events: string | any[], ...args: any): App {\r\n this.emitter.emit(events, ...args);\r\n return this;\r\n }\r\n}\r\n", "import { Service } from \"./service\";\r\nimport { Manager } from \"./manager\";\r\nimport { newURL, getHashedPath } from \"./url\";\r\n\r\nexport type RouteMethod = (...args: any) => any;\r\nexport type RouteStyle = string | RegExp | boolean;\r\nexport interface IRouteToFrom {\r\n to: RouteStyle,\r\n from: RouteStyle\r\n}\r\nexport type RoutePath = IRouteToFrom | RouteStyle;\r\nexport interface IRoute {\r\n path: RoutePath,\r\n method: RouteMethod\r\n}\r\n\r\n/**\r\n * Controls what happens when certain url paths match a set of criteria\r\n *\r\n * @export\r\n * @class Router\r\n * @extends {Service}\r\n */\r\nexport class Router extends Service {\r\n /**\r\n * List of routes inputted\r\n *\r\n * @protected\r\n * @type {Manager}\r\n * @memberof Router\r\n */\r\n protected routes: Manager;\r\n\r\n /**\r\n * Creates an instance of Router.\r\n *\r\n * @param {Array} [routes=[]]\r\n * @memberof Router\r\n */\r\n constructor(routes: IRoute[] = []) {\r\n super();\r\n this.routes = new Manager();\r\n for (let route of routes) {\r\n this.add(route);\r\n }\r\n }\r\n\r\n /**\r\n * Add a new route to watch for\r\n *\r\n * @param {IRoute} { path, method }\r\n * @returns {Router}\r\n * @memberof Router\r\n */\r\n public add({ path, method }: IRoute): Router {\r\n let key = this.parse(path);\r\n this.routes.set(key, method);\r\n return this;\r\n }\r\n\r\n /**\r\n * Convert strings into path match functions\r\n *\r\n * @param {RouteStyle} path\r\n * @returns {RegExp | boolean}\r\n * @memberof Router\r\n */\r\n public parsePath(path: RouteStyle): RegExp | boolean {\r\n if (typeof path === \"string\") return new RegExp(path, \"i\");\r\n else if (path instanceof RegExp || typeof path === \"boolean\")\r\n return path;\r\n throw \"[Router] only regular expressions, strings and booleans are accepted as paths.\";\r\n }\r\n\r\n /**\r\n * Determines if a strings counts has a path\r\n *\r\n * @param {RouteStyle} input\r\n * @returns boolean\r\n * @memberof Router\r\n */\r\n public isPath(input: RouteStyle): boolean {\r\n return (\r\n typeof input === \"string\" ||\r\n input instanceof RegExp ||\r\n typeof input === \"boolean\"\r\n );\r\n }\r\n\r\n /**\r\n * Parse the multiple different formats for paths, into a { from, to } object\r\n *\r\n * @param {RouteStyle} input\r\n * @returns {IRouteToFrom}\r\n * @memberof Router\r\n */\r\n public parse(input: RoutePath): IRouteToFrom {\r\n let route = input as IRouteToFrom;\r\n let toFromPath: IRouteToFrom = {\r\n from: /(.*)/g,\r\n to: /(.*)/g,\r\n };\r\n\r\n if (this.isPath(input as RouteStyle))\r\n toFromPath = {\r\n from: true,\r\n to: input as RouteStyle,\r\n };\r\n else if (this.isPath(route.from) && this.isPath(route.to as RouteStyle))\r\n toFromPath = route;\r\n else\r\n throw \"[Router] path is neither a string, regular expression, or a { from, to } object.\";\r\n\r\n let { from, to } = toFromPath;\r\n return {\r\n from: this.parsePath(from),\r\n to: this.parsePath(to),\r\n };\r\n }\r\n\r\n /**\r\n * Test if route paths are true, if so run their methods\r\n *\r\n * @memberof Router\r\n */\r\n public route() {\r\n let history = this.HistoryManager;\r\n let from: string = getHashedPath(newURL((history.length > 1 ? history.previous : history.current).url));\r\n let to: string = getHashedPath(newURL());\r\n\r\n this.routes.forEach((method: RouteMethod, path: IRouteToFrom) => {\r\n let fromRegExp = path.from as RegExp | boolean;\r\n let toRegExp = path.to as RegExp | boolean;\r\n\r\n if (\r\n typeof fromRegExp === \"boolean\" &&\r\n typeof toRegExp === \"boolean\"\r\n ) {\r\n throw `[Router] path ({ from: ${fromRegExp}, to: ${toRegExp} }) is not valid, remember paths can only be strings, regular expressions, or a boolean; however, both the from and to paths cannot be both booleans.`;\r\n }\r\n\r\n let fromParam: RegExpExecArray | RegExp | boolean = fromRegExp;\r\n let toParam: RegExpExecArray | RegExp | boolean = toRegExp;\r\n\r\n if (fromRegExp instanceof RegExp && fromRegExp.test(from))\r\n fromParam = fromRegExp.exec(from);\r\n if (toRegExp instanceof RegExp && toRegExp.test(to))\r\n toParam = toRegExp.exec(to);\r\n\r\n if (\r\n (Array.isArray(toParam) && Array.isArray(fromParam)) ||\r\n (Array.isArray(toParam) &&\r\n typeof fromParam == \"boolean\" &&\r\n fromParam) ||\r\n (Array.isArray(fromParam) &&\r\n typeof toParam == \"boolean\" &&\r\n toParam)\r\n )\r\n method({ from: fromParam, to: toParam, path: { from, to } });\r\n });\r\n }\r\n\r\n /**\r\n * Add listeners for PJAX Events\r\n *\r\n * @memberof Router\r\n */\r\n public initEvents() {\r\n this.emitter.on(\"READY\", this.route, this);\r\n this.emitter.on(\"CONTENT_REPLACED\", this.route, this);\r\n }\r\n\r\n /**\r\n * Remove listeners for PJAX Events\r\n *\r\n * @memberof Router\r\n */\r\n public stopEvents() {\r\n this.emitter.off(\"READY\", this.route, this);\r\n this.emitter.off(\"CONTENT_REPLACED\", this.route, this);\r\n }\r\n}\r\n", "import { EventEmitter, EventInput, ListenerCallback } from \"@okikio/emitter\";\r\n\r\n// DOM\r\nexport type AnimationTarget = string | Node | NodeList | HTMLCollection | HTMLElement[] | any[];\r\nexport const getElements = (selector: string | Node): Node[] => {\r\n return typeof selector === \"string\" ? Array.from(document.querySelectorAll(selector as string)) : [selector];\r\n};\r\n\r\nexport const getTargets = (targets: AnimationTarget): Node[] => {\r\n if (Array.isArray(targets)) return targets;\r\n if (typeof targets == \"string\" || targets instanceof Node)\r\n return getElements(targets);\r\n if (targets instanceof NodeList || targets instanceof HTMLCollection)\r\n return Array.from(targets);\r\n return [];\r\n};\r\n\r\n// VALUES\r\nexport type closureArgs = [number, number, HTMLElement];\r\nexport type closure = ((index?: number, total?: number, element?: HTMLElement) => any) | any;\r\nexport const computeValue = (value: closure, args: closureArgs) => {\r\n if (typeof value === \"function\") {\r\n return value(...args);\r\n } else { return value; }\r\n};\r\n\r\nexport const mapObject = (obj: object, args: closureArgs): any => {\r\n let key, value, result = {};\r\n let keys = Object.keys(obj);\r\n for (let i = 0, len = keys.length; i < len; i++) {\r\n key = keys[i];\r\n value = obj[key];\r\n result[key] = computeValue(value, args);\r\n }\r\n\r\n return result;\r\n};\r\n\r\n// From: [https://easings.net]\r\nexport const easings = {\r\n \"ease\": \"ease\",\r\n \"in\": \"ease-in\",\r\n \"out\": \"ease-out\",\r\n \"in-out\": \"ease-in-out\",\r\n\r\n // Sine\r\n \"in-sine\": \"cubic-bezier(0.47, 0, 0.745, 0.715)\",\r\n \"out-sine\": \"cubic-bezier(0.39, 0.575, 0.565, 1)\",\r\n \"in-out-sine\": \"cubic-bezier(0.445, 0.05, 0.55, 0.95)\",\r\n\r\n // Quad\r\n \"in-quad\": \"cubic-bezier(0.55, 0.085, 0.68, 0.53)\",\r\n \"out-quad\": \"cubic-bezier(0.25, 0.46, 0.45, 0.94)\",\r\n \"in-out-quad\": \"cubic-bezier(0.455, 0.03, 0.515, 0.955)\",\r\n\r\n // Cubic\r\n \"in-cubic\": \"cubic-bezier(0.55, 0.055, 0.675, 0.19)\",\r\n \"out-cubic\": \"cubic-bezier(0.215, 0.61, 0.355, 1)\",\r\n \"in-out-cubic\": \"cubic-bezier(0.645, 0.045, 0.355, 1)\",\r\n\r\n // Quart\r\n \"in-quart\": \"cubic-bezier(0.895, 0.03, 0.685, 0.22)\",\r\n \"out-quart\": \"cubic-bezier(0.165, 0.84, 0.44, 1)\",\r\n \"in-out-quart\": \"cubic-bezier(0.77, 0, 0.175, 1)\",\r\n\r\n // Quint\r\n \"in-quint\": \"cubic-bezier(0.755, 0.05, 0.855, 0.06)\",\r\n \"out-quint\": \"cubic-bezier(0.23, 1, 0.32, 1)\",\r\n \"in-out-quint\": \"cubic-bezier(0.86, 0, 0.07, 1)\",\r\n\r\n // Expo\r\n \"in-expo\": \"cubic-bezier(0.95, 0.05, 0.795, 0.035)\",\r\n \"out-expo\": \"cubic-bezier(0.19, 1, 0.22, 1)\",\r\n \"in-out-expo\": \"cubic-bezier(1, 0, 0, 1)\",\r\n\r\n // Circ\r\n \"in-circ\": \"cubic-bezier(0.6, 0.04, 0.98, 0.335)\",\r\n \"out-circ\": \"cubic-bezier(0.075, 0.82, 0.165, 1)\",\r\n \"in-out-circ\": \"cubic-bezier(0.785, 0.135, 0.15, 0.86)\",\r\n\r\n // Back\r\n \"in-back\": \"cubic-bezier(0.6, -0.28, 0.735, 0.045)\",\r\n \"out-back\": \"cubic-bezier(0.175, 0.885, 0.32, 1.275)\",\r\n \"in-out-back\": \"cubic-bezier(0.68, -0.55, 0.265, 1.55)\"\r\n};\r\nexport const getEase = (ease: string) => {\r\n return /^(ease|in|out)/.test(ease) ? easings[ease] : ease;\r\n};\r\n\r\nexport interface AnimationOptions {\r\n target?: AnimationTarget,\r\n\r\n speed?: number | closure,\r\n delay?: number | closure,\r\n easing?: string | closure,\r\n endDelay?: number | closure,\r\n duration?: number | closure,\r\n autoplay?: boolean | closure,\r\n keyframes?: object[] | closure,\r\n loop?: number | boolean | closure, // iterations: number,\r\n options?: AnimationOptions | closure,\r\n onfinish?: (element?: HTMLElement, index?: number, total?: number) => any,\r\n fillMode?: \"none\" | \"forwards\" | \"backwards\" | \"both\" | \"auto\" | closure,\r\n direction?: \"normal\" | \"reverse\" | \"alternate\" | \"alternate-reverse\" | closure,\r\n [property: string]: closure | boolean | object | string | string[] | number | null | (number | null)[] | undefined;\r\n};\r\n\r\nexport const DefaultAnimationOptions: AnimationOptions = {\r\n keyframes: [],\r\n\r\n loop: 1, // iterations: number,\r\n delay: 0,\r\n speed: 1,\r\n endDelay: 0,\r\n easing: \"ease\",\r\n autoplay: true,\r\n duration: 1000,\r\n onfinish() { },\r\n fillMode: \"auto\",\r\n direction: \"normal\",\r\n};\r\n\r\n// You can check it out here: https://codepen.io/okikio/pen/qBbdGaW?editors=0011\r\nexport class Animate {\r\n /**\r\n * Stores the options for the current animation\r\n *\r\n * @public\r\n * @type AnimationOptions\r\n * @memberof Animate\r\n */\r\n public options: AnimationOptions = {};\r\n\r\n /**\r\n * The Array of Elements to Animate\r\n *\r\n * @public\r\n * @type {Node[]}\r\n * @memberof Animate\r\n */\r\n public targets: Node[] = [];\r\n\r\n /**\r\n * The properties to animate\r\n *\r\n * @public\r\n * @type {object}\r\n * @memberof Animate\r\n */\r\n public properties: object = {};\r\n\r\n /**\r\n * A Set of Animations\r\n *\r\n * @public\r\n * @type {Map}\r\n * @memberof Animate\r\n */\r\n public animations: Map = new Map();\r\n\r\n /**\r\n * The total duration of all Animation's\r\n *\r\n * @public\r\n * @type {number}\r\n * @memberof Animate\r\n */\r\n public duration: number = 0;\r\n\r\n /**\r\n * The Element the main animation uses\r\n *\r\n * @public\r\n * @type {HTMLElement}\r\n * @memberof Animate\r\n */\r\n public mainElement: HTMLElement;\r\n\r\n /**\r\n * Stores an animation that runs on the total duration of the all other Animations, and as such it's the main Animation\r\n *\r\n * @public\r\n * @type {Animation}\r\n * @memberof Animate\r\n */\r\n public mainAnimation: Animation;\r\n\r\n /**\r\n * Stores request frame calls\r\n *\r\n * @public\r\n * @type {number}\r\n * @memberof Animate\r\n */\r\n public animationFrame: number;\r\n\r\n /**\r\n * An event emitter\r\n *\r\n * @public\r\n * @type {EventEmitter}\r\n * @memberof Animate\r\n */\r\n public emitter: EventEmitter = new EventEmitter();\r\n\r\n /**\r\n * The finish method, is called when the main animation has finished\r\n *\r\n * @public\r\n * @type {*}\r\n * @memberof Animate\r\n */\r\n public finish: any;\r\n\r\n /**\r\n * Returns a promise that is fulfilled when the mainAnimation is finished\r\n *\r\n * @public\r\n * @type {Promise}\r\n * @memberof Animate\r\n */\r\n public promise: Promise;\r\n\r\n /**\r\n * Creates an instance of Animate.\r\n *\r\n * @param {AnimationOptions} options\r\n * @memberof Animate\r\n */\r\n constructor(options: AnimationOptions = {}) {\r\n let { options: animation, ...rest } = options;\r\n this.options = Object.assign({}, DefaultAnimationOptions, animation, rest);\r\n this.loop = this.loop.bind(this);\r\n\r\n let {\r\n loop,\r\n delay,\r\n speed,\r\n easing,\r\n endDelay,\r\n duration,\r\n direction,\r\n fillMode,\r\n onfinish,\r\n target,\r\n keyframes,\r\n autoplay,\r\n ...properties\r\n } = this.options;\r\n\r\n this.mainElement = document.createElement(\"span\");\r\n this.targets = getTargets(target);\r\n this.properties = properties;\r\n\r\n let animationKeyframe: Keyframe[] | PropertyIndexedKeyframes;\r\n for (let i = 0, len = this.targets.length; i < len; i++) {\r\n let target = this.targets[i] as HTMLElement;\r\n let animationOptions = {\r\n easing: getEase(easing),\r\n iterations: loop === true ? Infinity : (loop as number),\r\n direction,\r\n endDelay,\r\n duration,\r\n delay,\r\n fill: fillMode,\r\n };\r\n\r\n // Accept keyframes as a keyframes Object, or a method,\r\n // if there are no animations in the keyframes array,\r\n // uses css properties from the options object\r\n let arrKeyframes = computeValue((keyframes as Keyframe[]), [i, len, target]);\r\n animationKeyframe = arrKeyframes.length ? arrKeyframes :\r\n (this.properties as PropertyIndexedKeyframes);\r\n\r\n // Allows the use of functions as the values, for both the keyframes and the animation object\r\n // It adds the capability of advanced stagger animation, similar to the anime js stagger functions\r\n animationOptions = mapObject(animationOptions, [i, len, target]);\r\n if (!(arrKeyframes.length > 0))\r\n animationKeyframe = mapObject(animationKeyframe, [i, len, target]);\r\n\r\n // Set the Animate classes duration to be the Animation with the largest totalDuration\r\n let tempDuration: number =\r\n animationOptions.delay +\r\n (animationOptions.duration * animationOptions.iterations) +\r\n animationOptions.endDelay;\r\n if (this.duration < tempDuration) this.duration = tempDuration;\r\n\r\n // Add animation to the Animations Set\r\n let animation = target.animate(animationKeyframe, animationOptions);\r\n animation.onfinish = () => {\r\n onfinish(target, i, len);\r\n };\r\n this.animations.set(target, animation);\r\n }\r\n\r\n this.mainAnimation = this.mainElement.animate([\r\n { opacity: \"0\" },\r\n { opacity: \"1\" }\r\n ], {\r\n duration: this.duration,\r\n easing: \"linear\"\r\n });\r\n\r\n this.setSpeed(speed);\r\n if (autoplay) this.play();\r\n else this.pause();\r\n\r\n this.promise = this.newPromise();\r\n this.mainAnimation.onfinish = () => {\r\n this.finish(this.options);\r\n window.cancelAnimationFrame(this.animationFrame);\r\n };\r\n }\r\n\r\n /**\r\n * Returns the Array of targets\r\n *\r\n * @returns {Node[]}\r\n * @memberof Animate\r\n */\r\n public getTargets(): Node[] {\r\n return this.targets;\r\n }\r\n\r\n /**\r\n * Returns a new Promise that is resolve when this.finish is called\r\n *\r\n * @public\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public newPromise(): Promise {\r\n return new Promise((resolve, reject) => {\r\n try {\r\n this.finish = (options: AnimationOptions) => {\r\n this.emit(\"finish\", options);\r\n return resolve(options);\r\n };\r\n } catch (err) { reject(err); }\r\n });\r\n }\r\n\r\n /**\r\n * Fulfills the this.promise Promise\r\n *\r\n * @param {(value?: any) => any} [onFulfilled]\r\n * @param {(reason?: any) => any} [onRejected]\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public then(\r\n onFulfilled?: (value?: any) => any,\r\n onRejected?: (reason?: any) => any\r\n ): Promise {\r\n return this.promise.then(onFulfilled, onRejected);\r\n }\r\n\r\n /**\r\n * Catches error that occur in the this.promise Promise\r\n *\r\n * @param {(reason?: any) => any} onRejected\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public catch(onRejected: (reason?: any) => any): Promise {\r\n return this.promise.catch(onRejected);\r\n }\r\n\r\n /**\r\n * If you don't care if the this.promise Promise has either been rejected or resolved\r\n *\r\n * @param {() => any} onFinally\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public finally(onFinally: () => any): Promise {\r\n return this.promise.finally(onFinally);\r\n }\r\n\r\n /**\r\n * Represents an Animation Frame Loop\r\n *\r\n * @public\r\n * @memberof Animate\r\n */\r\n public loop(): void {\r\n this.animationFrame = window.requestAnimationFrame(this.loop);\r\n this.emit(\"tick change\", this.getCurrentTime());\r\n }\r\n\r\n /**\r\n * Adds a listener for a given event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public on(events: EventInput, callback?: ListenerCallback, scope?: object): Animate {\r\n this.emitter.on(events, callback, scope);\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes a listener from an event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public off(events: EventInput, callback?: ListenerCallback, scope?: object): Animate {\r\n this.emitter.off(events, callback, scope);\r\n return this;\r\n }\r\n\r\n /**\r\n * Call all listeners within an event\r\n *\r\n * @param {(string | any[])} events\r\n * @param {...any} args\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public emit(events: string | any[], ...args: any): Animate {\r\n this.emitter.emit(events, ...args);\r\n return this;\r\n }\r\n\r\n /**\r\n * Get a specific Animation from an Animate instance\r\n *\r\n * @param {HTMLElement} element\r\n * @returns {Animation}\r\n * @memberof Animate\r\n */\r\n public getAnimation(element: HTMLElement): Animation {\r\n return this.animations.get(element);\r\n }\r\n\r\n /**\r\n * Play Animation's\r\n *\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public play(): Animate {\r\n // Once the animation is done, it's done, it can only be paused by the reset method\r\n if (this.mainAnimation.playState !== \"finished\") {\r\n this.mainAnimation.play();\r\n this.animationFrame = requestAnimationFrame(this.loop);\r\n this.animations.forEach(animation => {\r\n if (animation.playState !== \"finished\") animation.play();\r\n });\r\n this.emit(\"play\");\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Pause Animation's\r\n *\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public pause(): Animate {\r\n // Once the animation is done, it's done, it can only be reset by the reset method\r\n if (this.mainAnimation.playState !== \"finished\") {\r\n this.mainAnimation.pause();\r\n window.cancelAnimationFrame(this.animationFrame);\r\n this.animations.forEach(animation => {\r\n if (animation.playState !== \"finished\") animation.pause();\r\n });\r\n this.emit(\"pause\");\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the total duration of all Animations\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getDuration(): number {\r\n return this.duration;\r\n }\r\n\r\n /**\r\n * Returns the current time of the Main Animation\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getCurrentTime(): number {\r\n return this.mainAnimation.currentTime;\r\n }\r\n\r\n /**\r\n * Set the current time of the Main Animation\r\n *\r\n * @param {number} time\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setCurrentTime(time: number): Animate {\r\n this.mainAnimation.currentTime = time;\r\n this.animations.forEach(animation => {\r\n animation.currentTime = time;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the Animation progress as a fraction of the current time / duration\r\n *\r\n * @returns\r\n * @memberof Animate\r\n */\r\n public getProgress() {\r\n return this.getCurrentTime() / this.duration;\r\n }\r\n\r\n /**\r\n * Set the Animation progress as a fraction of the current time / duration\r\n *\r\n * @param {number} percent\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setProgress(percent: number): Animate {\r\n this.mainAnimation.currentTime = percent * this.duration;\r\n this.animations.forEach(animation => {\r\n animation.currentTime = percent * this.duration;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Return the playback speed of the animation\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getSpeed(): number {\r\n return this.mainAnimation.playbackRate;\r\n }\r\n\r\n /**\r\n * Set the playback speed of an Animation\r\n *\r\n * @param {number} [speed=1]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setSpeed(speed: number = 1): Animate {\r\n this.mainAnimation.playbackRate = speed;\r\n this.animations.forEach(animation => {\r\n animation.playbackRate = speed;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Reset all Animations\r\n *\r\n * @memberof Animate\r\n */\r\n public reset() {\r\n this.setCurrentTime(0);\r\n this.promise = this.newPromise();\r\n\r\n if (this.options.autoplay) this.play();\r\n else this.pause();\r\n }\r\n\r\n /**\r\n * Returns the current playing state\r\n *\r\n * @returns {(\"idle\" | \"running\" | \"paused\" | \"finished\")}\r\n * @memberof Animate\r\n */\r\n public getPlayState(): \"idle\" | \"running\" | \"paused\" | \"finished\" {\r\n return this.mainAnimation.playState;\r\n }\r\n\r\n /**\r\n * Get the options of an Animate instance\r\n *\r\n * @returns {AnimationOptions}\r\n * @memberof Animate\r\n */\r\n public getOptions(): AnimationOptions {\r\n return this.options;\r\n }\r\n\r\n // Returns the Animate options, as JSON\r\n public toJSON(): AnimationOptions {\r\n return this.getOptions();\r\n }\r\n}\r\n\r\n// Creates a new Animate instance\r\nexport const animate = (options: AnimationOptions = {}): Animate => {\r\n return new Animate(options);\r\n};\r\n\r\nexport default animate;\r\n"], + "mappings": "AAcO,IAAM,EAA2B,CACpC,YAAa,UACb,eAAgB,eAChB,eAAgB,cAChB,QAAS,CACL,CAAC,YAAa,SAElB,gBAAiB,iBACjB,eAAgB,gBAChB,eAAgB,aAChB,UAAW,QACX,QAAS,OAzBb,MAoDI,eACI,KAAK,OAAS,OAAO,OAAO,IAAK,GAAmB,GAWjD,WAA0C,IAC7C,IAAM,UAAW,KAAK,SACX,OAAO,EAAS,IAAM,EAAS,MAAM,IAChD,MAAO,GAAW,IAAI,KAAU,EAW7B,cAAkD,IACrD,GAAI,MAAO,IAAU,SACjB,MAAO,MAAK,OAEhB,MAAa,KAAK,OAAO,GACzB,MAAI,OAAO,IAAW,SACX,KAAK,OAAO,EAAQ,GACxB,ICrFf,IAAA,QAwBC,eACC,KAAK,IAAM,GAAI,KAAI,GASb,SACN,MAAO,MAAK,IAUN,OACN,MAAO,MAAK,IAAI,IAAI,GASd,OACN,MAAO,OAAM,KAAK,KAAK,IAAI,QASrB,SACN,MAAO,OAAM,KAAK,KAAK,IAAI,UAWrB,SACN,YAAK,IAAI,IAAI,EAAK,GACX,KAUD,OACN,MAAW,KAAK,OAEH,EACb,YAAK,IAAI,EAAK,GACP,QASG,QACV,MAAO,MAAK,IAAI,QAGN,UACV,MAAO,MAAK,IAAI,KAUV,OAAwB,GAC9B,MAAU,KAAK,OAAO,KAAK,KAAO,GAClC,MAAO,MAAK,IAAI,GAUV,UACN,MAAO,MAA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.node.js index a5aefe6..bc358e0 100644 --- a/packages/native/lib/api.node.js +++ b/packages/native/lib/api.node.js @@ -1,3 +1,3 @@ -var q=Object.defineProperty,at=r=>q(r,"__esModule",{value:!0}),lt=(r,t)=>{at(r);for(var e in t)q(r,e,{get:t[e],enumerable:!0})};lt(exports,{AdvancedManager:()=>x,Animate:()=>U,App:()=>Y,CONFIG:()=>P,CONFIG_DEFAULTS:()=>$,DefaultAnimationOptions:()=>rt,Event:()=>T,EventEmitter:()=>v,HistoryManager:()=>k,Manager:()=>u,ManagerItem:()=>w,PARSER:()=>W,PJAX:()=>J,Page:()=>d,PageManager:()=>O,Router:()=>Q,Service:()=>I,ServiceManager:()=>H,TransitionManager:()=>N,animate:()=>ct,asyncMethodCall:()=>B,clean:()=>D,computeValue:()=>j,easings:()=>et,equal:()=>M,getEase:()=>it,getElements:()=>Z,getHash:()=>pt,getHashedPath:()=>m,getTargets:()=>tt,hashAction:()=>X,mapObject:()=>z,methodCall:()=>E,newCoords:()=>C,newListener:()=>_,newState:()=>S,newURL:()=>p});var $={wrapperAttr:"wrapper",noAjaxLinkAttr:"no-ajax-link",noPrefetchAttr:"no-prefetch",headers:[["x-partial","true"]],preventSelfAttr:'prevent="self"',preventAllAttr:'prevent="all"',transitionAttr:"transition",blockAttr:"block",timeout:3e4},P=class{constructor(t){this.config=Object.assign({...$},t)}toAttr(t,e=!0){let{prefix:i}=this.config,n=`data${i?"-"+i:""}-${t}`;return e?`[${n}]`:n}getConfig(t,e=!0){if(typeof t!="string")return this.config;let i=this.config[t];return typeof i=="string"?this.toAttr(i,e):i}};var u=class{constructor(t){this.map=new Map(t)}getMap(){return this.map}get(t){return this.map.get(t)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(t,e){return this.map.set(t,e),this}add(t){let e=this.size,i=e;return this.set(i,t),this}get size(){return this.map.size}get length(){return this.map.size}last(t=1){let e=this.keys()[this.size-t];return this.get(e)}delete(t){return this.map.delete(t)}remove(t){return this.map.delete(t),this}clear(){return this.map.clear(),this}has(t){return this.map.has(t)}entries(){return this.map.entries()}forEach(t=(...i)=>{},e){return this.map.forEach(t,e),this}[Symbol.iterator](){return this.entries()}},E=(r,t,...e)=>{r.forEach(i=>{i[t](...e)})},B=async(r,t,...e)=>{for(let[,i]of r)await i[t](...e)},w=class{constructor(){}install(){}register(t,e){return this.manager=t,this.app=t.app,this.config=t.config,this.emitter=t.emitter,this.key=e,this.install(),this}uninstall(){}unregister(){this.uninstall(),this.manager.delete(this.key),this.key=void 0,this.manager=void 0,this.app=void 0,this.config=void 0,this.emitter=void 0}},x=class extends u{constructor(t){super();this.app=t,this.config=t.config,this.emitter=t.emitter}set(t,e){return super.set(t,e),e.register(this,t),this}};var p=(r=window.location.href)=>r instanceof URL?r:new URL(r,window.location.origin),m=r=>`${r.pathname}${r.hash}`,pt=r=>r.hash.slice(1),D=r=>r.toString().replace(/(\/#.*|\/|#.*)$/,""),M=(r,t)=>{let e=p(r),i=p(t);return D(e)===D(i)};var C=(r=window.scrollX,t=window.scrollY)=>({x:r,y:t}),S=(r={url:m(p()),index:0,transition:"default",data:{scroll:C(),trigger:"HistoryManager"}})=>r,k=class{constructor(){this.pointer=-1;this.states=[];let t=S();this.add(t,"replace")}get(t){return this.states[t]}add(t,e="push"){let i=S(t),n=this.length;this.states.push({...i}),this.pointer=n;let o={index:this.pointer,states:[...this.states]};return this.changeState(e,i,o),this}remove(t){return t?this.states.splice(t,1):this.states.pop(),this.pointer--,this}replace(t){return this.states=t,this}set(t,e){return this.states[t]=e}get current(){return this.get(this.pointer)}get last(){return this.get(this.length-1)}get previous(){return this.pointer<1?null:this.get(this.pointer-1)}get length(){return this.states.length}changeState(t,e,i){let n=m(p(e.url)),o=[i,"",n];if(window.history)switch(t){case"push":window.history.pushState.apply(window.history,o);break;case"replace":window.history.replaceState.apply(window.history,o);break}}};var W=new DOMParser,d=class extends w{constructor(t=p(),e=document){super();this.url=t,typeof e=="string"?this.data=e:this.dom=e||document}async build(){if(this.dom instanceof Node||(this.dom=W.parseFromString(this.data,"text/html")),!(this.body instanceof Node)){let{title:t,head:e,body:i}=this.dom;this.title=t,this.head=e,this.body=i,this.wrapper=this.body.querySelector(this.wrapperAttr)}}install(){this.wrapperAttr=this.config.getConfig("wrapperAttr")}uninstall(){this.url=void 0,this.title=void 0,this.head=void 0,this.body=void 0,this.dom=void 0,this.wrapper=void 0,this.data=void 0,this.wrapperAttr=void 0}},O=class extends x{constructor(t){super(t);this.loading=new u;this.maxPages=5;let e=p().pathname;this.set(e,new d),e=void 0}async load(t=p()){let e=p(t),i=e.pathname,n,o;if(this.has(i))return n=this.get(i),Promise.resolve(n);this.loading.has(i)?o=this.loading.get(i):(o=this.request(i),this.loading.set(i,o));let s=await o;if(this.loading.delete(i),n=new d(e,s),this.set(i,n),this.size>this.maxPages){let a=p(),l=this.keys(),c=M(a,l[0])?l[1]:l[0],h=this.get(c);h.unregister(),h=void 0,l=void 0,a=void 0,c=void 0}return n}async request(t){let e=new Headers(this.config.getConfig("headers")),i=window.setTimeout(()=>{throw window.clearTimeout(i),"Request Timed Out!"},this.config.getConfig("timeout"));try{let n=await fetch(t,{mode:"same-origin",method:"GET",headers:e,cache:"default",credentials:"same-origin"});if(window.clearTimeout(i),n.status>=200&&n.status<300)return await n.text();let o=new Error(n.statusText||""+n.status);throw o}catch(n){throw window.clearTimeout(i),n}}};var _=({callback:r=()=>{},scope:t=null,name:e="event"})=>({callback:r,scope:t,name:e}),T=class extends u{constructor(t="event"){super();this.name=t}},v=class extends u{constructor(){super()}getEvent(t){let e=this.get(t);return e instanceof T?e:(this.set(t,new T(t)),this.get(t))}newListener(t,e,i){let n=this.getEvent(t);return n.add(_({name:t,callback:e,scope:i})),n}on(t,e,i){if(typeof t=="undefined")return this;typeof t=="string"&&(t=t.trim().split(/\s/g));let n,o,s=typeof t=="object"&&!Array.isArray(t),a=s?e:i;return s||(o=e),Object.keys(t).forEach(l=>{s?(n=l,o=t[l]):n=t[l],this.newListener(n,o,a)},this),this}removeListener(t,e,i){let n=this.get(t);if(n instanceof T&&e){let o=_({name:t,callback:e,scope:i});n.forEach((s,a)=>{if(s.callback===o.callback&&s.scope===o.scope)return n.delete(a)})}return n}off(t,e,i){if(typeof t=="undefined")return this;typeof t=="string"&&(t=t.trim().split(/\s/g));let n,o,s=typeof t=="object"&&!Array.isArray(t),a=s?e:i;return s||(o=e),Object.keys(t).forEach(l=>{s?(n=l,o=t[l]):n=t[l],typeof o=="function"?this.removeListener(n,o,a):this.delete(n)},this),this}emit(t,...e){return typeof t=="undefined"?this:(typeof t=="string"&&(t=t.trim().split(/\s/g)),t.forEach(i=>{let n=this.get(i);n instanceof T&&n.forEach(o=>{let{callback:s,scope:a}=o;s.apply(a,e)})},this),this)}};var I=class extends w{install(){let{app:t}=this.manager;this.PageManager=t.pages,this.HistoryManager=t.history,this.ServiceManager=t.services,this.TransitionManager=t.transitions}init(...t){}boot(){this.initEvents()}initEvents(){}stopEvents(){}uninstall(){this.PageManager=void 0,this.HistoryManager=void 0,this.ServiceManager=void 0,this.TransitionManager=void 0}stop(){this.stopEvents(),this.unregister()}},H=class extends x{constructor(t){super(t)}init(){return E(this,"init",this.app),this}boot(){return E(this,"boot",this.app),this}stop(){return E(this,"stop",this.app),this}};var N=class extends u{constructor(t){super();this.app=t,this.config=t.config,this.emitter=t.emitter}async boot(t,e){let i=this.get(t);if(!(e.oldPage instanceof d)||!(e.newPage instanceof d))throw`[Page] either oldPage or newPage aren't instances of the Page Class. - ${{newPage:e.newPage,oldPage:e.oldPage}}`;let n=e.oldPage.wrapper,o=e.newPage.wrapper;if(document.title=""+e.newPage.title,!(n instanceof Node)||!(o instanceof Node))throw`[Wrapper] the wrapper from the ${o instanceof Node?"current":"next"} page cannot be found. The wrapper must be an element that has the attribute ${this.config.getConfig("wrapperAttr")}.`;return i.init&&i?.init(e),this.emitter.emit("BEFORE_TRANSITION_OUT"),await new Promise(s=>{let a=i.out.call(i,{from:e.oldPage,trigger:e.trigger,scroll,done:s});a.then&&a.then(s)}),this.emitter.emit("AFTER_TRANSITION_OUT"),await new Promise(s=>{n.insertAdjacentElement("beforebegin",o),this.emitter.emit("CONTENT_INSERT"),s()}),await new Promise(s=>{n.remove(),n=void 0,o=void 0,this.emitter.emit("CONTENT_REPLACED"),s()}),this.emitter.emit("BEFORE_TRANSITION_IN"),await new Promise(s=>{let a=i.in.call(i,{from:e.oldPage,to:e.newPage,trigger:e.trigger,scroll,done:s});a.then&&a.then(s)}),this.emitter.emit("AFTER_TRANSITION_IN"),i}};var Y=class{constructor(t={}){this.register(t)}register(t={}){this.config=t instanceof P?t:new P(t),this.emitter=new v,this.history=new k,this.pages=new O(this),this.transitions=new N(this),this.services=new H(this);let e=(()=>{document.removeEventListener("DOMContentLoaded",e),window.removeEventListener("load",e),this.emitter.emit("READY ready")}).bind(this);return document.addEventListener("DOMContentLoaded",e),window.addEventListener("load",e),this}get(t,e){switch(t.toLowerCase()){case"service":return this.services.get(e);case"transition":return this.transitions.get(e);case"state":return this.history.get(e);default:throw`Error: can't get type '${t}', it is not a recognized type. Did you spell it correctly.`}}async load(t,e){switch(t.toLowerCase()){case"page":return await this.pages.load(e);default:return Promise.resolve(this.get(t,e))}}setService(t,e){return this.services.set(t,e),this}setTransition(t,e){return this.transitions.set(t,e),this}add(t,e){switch(t.toLowerCase()){case"service":this.services.add(e);break;case"transition":this.transitions.set(e.name,e);break;case"state":this.history.add(e);break;default:throw`Error: can't add type '${t}', it is not a recognized type. Did you spell it correctly.`}return this}boot(){return this.services.init(),this.services.boot(),this}stop(){return this.services.stop(),this}on(t,e){return this.emitter.on(t,e,this),this}off(t,e){return this.emitter.off(t,e,this),this}emit(t,...e){return this.emitter.emit(t,...e),this}};var J=class extends I{constructor(){super(...arguments);this.ignoreURLs=[];this.prefetchIgnore=!1;this.isTransitioning=!1;this.stopOnTransitioning=!1;this.stickyScroll=!1;this.forceOnError=!1;this.autoScrollOnHash=!0;this.dontScroll=!0}transitionStart(){this.isTransitioning=!0}transitionStop(){this.isTransitioning=!1}init(){super.init(),this.onHover=this.onHover.bind(this),this.onClick=this.onClick.bind(this),this.onStateChange=this.onStateChange.bind(this)}boot(){"scrollRestoration"in window.history&&(window.history.scrollRestoration="manual"),super.boot()}getTransitionName(t){if(!t||!t.getAttribute)return null;let e=t.getAttribute(this.config.getConfig("transitionAttr",!1));return typeof e=="string"?e:null}validLink(t,e,i){let n=!window.history.pushState,o=!t||!i,s=e.metaKey||e.ctrlKey||e.shiftKey||e.altKey,a=t.hasAttribute("target")&&t.target==="_blank",l=t.protocol!==location.protocol||t.hostname!==location.hostname,c=typeof t.getAttribute("download")=="string",h=t.hasAttribute(this.config.getConfig("preventSelfAttr",!1)),g=Boolean(t.closest(this.config.getConfig("preventAllAttr"))),y=h&&g,F=m(p())===m(p(i));return!(o||n||s||a||l||c||y||F)}getHref(t){return t&&t.tagName&&t.tagName.toLowerCase()==="a"&&typeof t.href=="string"?t.href:null}getLink(t){let e=t.target,i=this.getHref(e);for(;e&&!i;)e=e.parentNode,i=this.getHref(e);return!e||!this.validLink(e,t,i)?void 0:e}onClick(t){let e=this.getLink(t);if(!e)return;if(this.isTransitioning&&this.stopOnTransitioning){t.preventDefault(),t.stopPropagation();return}let i=this.getHref(e);this.emitter.emit("ANCHOR_CLICK CLICK",t),this.go({href:i,trigger:e,event:t})}getDirection(t){return Math.abs(t)>1?t>0?"forward":"back":t===0?"popstate":t>0?"back":"forward"}force(t){window.location.assign(t)}go({href:t,trigger:e="HistoryManager",event:i}){if(this.isTransitioning&&this.stopOnTransitioning){this.force(t);return}let n={x:0,y:0},o=this.HistoryManager.current,s=o.url;if(M(s,t))return;let a;if(i&&i.state){this.emitter.emit("POPSTATE",i);let{state:l}=i,{index:c}=l,h=o.index,g=h-c;e=this.getDirection(g),this.HistoryManager.replace(l.states),this.HistoryManager.pointer=c,e==="back"?this.emitter.emit("POPSTATE_BACK",i):e==="forward"&&this.emitter.emit("POPSTATE_FORWARD",i);let y=this.HistoryManager.get(c);a=y.transition,e!=="popstate"&&(n=y.data.scroll)}else{a=this.getTransitionName(e)||"default";let l=C();if(!this.dontScroll&&this.stickyScroll){let{x:h,y:g}=l;n={x:h,y:g}}else n={x:0,y:0};let c=S({url:t,transition:a,data:{scroll:l}});this.HistoryManager.add(c),this.emitter.emit("HISTORY_NEW_ITEM",i)}return i&&(i.stopPropagation(),i.preventDefault()),this.emitter.emit("GO",i),this.load({oldHref:s,href:t,trigger:e,transitionName:a,scroll:n})}async load({oldHref:t,href:e,trigger:i,transitionName:n="default",scroll:o={x:0,y:0}}){try{let s=await this.PageManager.load(t);await s.build();let a;this.emitter.emit("PAGE_LOADING",{href:e,oldPage:s,trigger:i});try{try{a=await this.PageManager.load(e),await a.build(),this.transitionStart(),this.emitter.emit("PAGE_LOAD_COMPLETE",{newPage:a,oldPage:s,trigger:i})}catch(l){console.error(`[PJAX] page load error: ${l}`)}this.emitter.emit("NAVIGATION_START",{oldPage:s,newPage:a,trigger:i,transitionName:n});try{this.emitter.emit("TRANSITION_START",n);let l=await this.TransitionManager.boot(n,{oldPage:s,newPage:a,trigger:i,scroll:o});l.scrollable||(/back|popstate|forward/.test(i)||(o=X(e)),window.scroll(o.x,o.y)),this.emitter.emit("TRANSITION_END",{transition:l})}catch(l){console.error(`[PJAX] transition error: ${l}`)}this.emitter.emit("NAVIGATION_END",{oldPage:s,newPage:a,trigger:i,transitionName:n})}catch(l){throw this.transitionStop(),l}this.transitionStop()}catch(s){this.forceOnError?this.force(e):console.error(s)}}ignoredURL({pathname:t}){return this.ignoreURLs.length&&this.ignoreURLs.some(e=>typeof e=="string"?e===t:e.exec(t)!==null)}onHover(t){let e=this.getLink(t);if(!e)return;let i=p(this.getHref(e)),n=i.pathname;if(this.ignoredURL(i)||this.PageManager.has(n))return;this.emitter.emit("ANCHOR_HOVER HOVER",t);try{this.PageManager.load(i)}catch(o){console.warn("[PJAX] prefetch error,",o)}}onStateChange(t){this.go({href:window.location.href,trigger:"popstate",event:t})}initEvents(){this.prefetchIgnore!==!0&&(document.addEventListener("mouseover",this.onHover),document.addEventListener("touchstart",this.onHover)),document.addEventListener("click",this.onClick),window.addEventListener("popstate",this.onStateChange)}stopEvents(){this.prefetchIgnore!==!0&&(document.removeEventListener("mouseover",this.onHover),document.removeEventListener("touchstart",this.onHover)),document.removeEventListener("click",this.onClick),window.removeEventListener("popstate",this.onStateChange)}},X=(r=window.location.hash)=>{try{let t=r[0]=="#"?r:p(r).hash;if(t.length>1){let e=document.querySelector(t);if(e)return{x:e.offsetLeft,y:e.offsetTop}}}catch(t){console.warn("hashAction error",t)}return{x:0,y:0}};var Q=class extends I{constructor(t=[]){super();this.routes=new u;for(let e of t)this.add(e)}add({path:t,method:e}){let i=this.parse(t);return this.routes.set(i,e),this}parsePath(t){if(typeof t=="string")return new RegExp(t,"i");if(t instanceof RegExp||typeof t=="boolean")return t;throw"[Router] only regular expressions, strings and booleans are accepted as paths."}isPath(t){return typeof t=="string"||t instanceof RegExp||typeof t=="boolean"}parse(t){let e=t,i={from:/(.*)/g,to:/(.*)/g};if(this.isPath(t))i={from:!0,to:t};else if(this.isPath(e.from)&&this.isPath(e.to))i=e;else throw"[Router] path is neither a string, regular expression, or a { from, to } object.";let{from:n,to:o}=i;return{from:this.parsePath(n),to:this.parsePath(o)}}route(){let t=this.HistoryManager,e=m(p((t.length>1?t.previous:t.current).url)),i=m(p());this.routes.forEach((n,o)=>{let s=o.from,a=o.to;if(typeof s=="boolean"&&typeof a=="boolean")throw`[Router] path ({ from: ${s}, to: ${a} }) is not valid, remember paths can only be strings, regular expressions, or a boolean; however, both the from and to paths cannot be both booleans.`;let l=s,c=a;s instanceof RegExp&&s.test(e)&&(l=s.exec(e)),a instanceof RegExp&&a.test(i)&&(c=a.exec(i)),(Array.isArray(c)&&Array.isArray(l)||Array.isArray(c)&&typeof l=="boolean"&&l||Array.isArray(l)&&typeof c=="boolean"&&c)&&n({from:l,to:c,path:{from:e,to:i}})})}initEvents(){this.emitter.on("READY",this.route,this),this.emitter.on("CONTENT_REPLACED",this.route,this)}stopEvents(){this.emitter.off("READY",this.route,this),this.emitter.off("CONTENT_REPLACED",this.route,this)}};var Z=r=>typeof r=="string"?Array.from(document.querySelectorAll(r)):[r],tt=r=>Array.isArray(r)?r:typeof r=="string"||r instanceof Node?Z(r):r instanceof NodeList||r instanceof HTMLCollection?Array.from(r):[],j=(r,t)=>typeof r=="function"?r(...t):r,z=(r,t)=>{let e,i,n={},o=Object.keys(r);for(let s=0,a=o.length;s/^(ease|in|out)/.test(r)?et[r]:r,rt={keyframes:[],loop:1,delay:0,speed:1,endDelay:0,easing:"ease",autoplay:!0,duration:1e3,onfinish(){},fillMode:"auto",direction:"normal"},U=class{constructor(t={}){this.options={};this.targets=[];this.properties={};this.animations=new Map;this.duration=0;this.emitter=new v;let{options:e,...i}=t;this.options=Object.assign({},rt,e,i),this.loop=this.loop.bind(this);let{loop:n,delay:o,speed:s,easing:a,endDelay:l,duration:c,direction:h,fillMode:g,onfinish:y,target:F,keyframes:nt,autoplay:ot,...st}=this.options;this.mainElement=document.createElement("span"),this.targets=tt(F),this.properties=st;let R;for(let f=0,L=this.targets.length;f0||(R=z(R,[f,L,A]));let V=b.delay+b.duration*b.iterations+b.endDelay;this.duration{y(A,f,L)},this.animations.set(A,G)}this.mainAnimation=this.mainElement.animate([{opacity:"0"},{opacity:"1"}],{duration:this.duration,easing:"linear"}),this.setSpeed(s),ot?this.play():this.pause(),this.promise=this.newPromise(),this.mainAnimation.onfinish=()=>{this.finish(this.options),window.cancelAnimationFrame(this.animationFrame)}}getTargets(){return this.targets}newPromise(){return new Promise((t,e)=>{try{this.finish=i=>(this.emit("finish",i),t(i))}catch(i){e(i)}})}then(t,e){return this.promise.then(t,e)}catch(t){return this.promise.catch(t)}finally(t){return this.promise.finally(t)}loop(){this.animationFrame=window.requestAnimationFrame(this.loop),this.emit("tick change",this.getCurrentTime())}on(t,e,i){return this.emitter.on(t,e,i),this}off(t,e,i){return this.emitter.off(t,e,i),this}emit(t,...e){return this.emitter.emit(t,...e),this}getAnimation(t){return this.animations.get(t)}play(){return this.mainAnimation.playState!=="finished"&&(this.mainAnimation.play(),this.animationFrame=requestAnimationFrame(this.loop),this.animations.forEach(t=>{t.playState!=="finished"&&t.play()}),this.emit("play")),this}pause(){return this.mainAnimation.playState!=="finished"&&(this.mainAnimation.pause(),window.cancelAnimationFrame(this.animationFrame),this.animations.forEach(t=>{t.playState!=="finished"&&t.pause()}),this.emit("pause")),this}getDuration(){return this.duration}getCurrentTime(){return this.mainAnimation.currentTime}setCurrentTime(t){return this.mainAnimation.currentTime=t,this.animations.forEach(e=>{e.currentTime=t}),this}getProgress(){return this.getCurrentTime()/this.duration}setProgress(t){return this.mainAnimation.currentTime=t*this.duration,this.animations.forEach(e=>{e.currentTime=t*this.duration}),this}getSpeed(){return this.mainAnimation.playbackRate}setSpeed(t=1){return this.mainAnimation.playbackRate=t,this.animations.forEach(e=>{e.playbackRate=t}),this}reset(){this.setCurrentTime(0),this.promise=this.newPromise(),this.options.autoplay?this.play():this.pause()}getPlayState(){return this.mainAnimation.playState}getOptions(){return this.options}toJSON(){return this.getOptions()}},ct=(r={})=>new U(r); +var $=Object.defineProperty,lt=r=>$(r,"__esModule",{value:!0}),pt=(r,t)=>{lt(r);for(var e in t)$(r,e,{get:t[e],enumerable:!0})};pt(exports,{AdvancedManager:()=>w,Animate:()=>V,App:()=>Q,CONFIG:()=>P,CONFIG_DEFAULTS:()=>B,DefaultAnimationOptions:()=>nt,Event:()=>T,EventEmitter:()=>v,HistoryManager:()=>k,Manager:()=>u,ManagerItem:()=>E,PARSER:()=>J,PJAX:()=>X,Page:()=>b,PageManager:()=>O,Router:()=>Z,Service:()=>I,ServiceManager:()=>H,TransitionManager:()=>F,animate:()=>ut,asyncMethodCall:()=>W,changeState:()=>Y,clean:()=>_,computeValue:()=>z,easings:()=>it,equal:()=>R,getEase:()=>rt,getElements:()=>tt,getHash:()=>ct,getHashedPath:()=>h,getTargets:()=>et,hashAction:()=>N,mapObject:()=>U,methodCall:()=>A,newCoords:()=>x,newListener:()=>j,newState:()=>S,newURL:()=>p});var B={wrapperAttr:"wrapper",noAjaxLinkAttr:"no-ajax-link",noPrefetchAttr:"no-prefetch",headers:[["x-partial","true"]],preventSelfAttr:'prevent="self"',preventAllAttr:'prevent="all"',transitionAttr:"transition",blockAttr:"block",timeout:3e4},P=class{constructor(t){this.config=Object.assign({...B},t)}toAttr(t,e=!0){let{prefix:i}=this.config,n=`data${i?"-"+i:""}-${t}`;return e?`[${n}]`:n}getConfig(t,e=!0){if(typeof t!="string")return this.config;let i=this.config[t];return typeof i=="string"?this.toAttr(i,e):i}};var u=class{constructor(t){this.map=new Map(t)}getMap(){return this.map}get(t){return this.map.get(t)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(t,e){return this.map.set(t,e),this}add(t){let e=this.size,i=e;return this.set(i,t),this}get size(){return this.map.size}get length(){return this.map.size}last(t=1){let e=this.keys()[this.size-t];return this.get(e)}delete(t){return this.map.delete(t)}remove(t){return this.map.delete(t),this}clear(){return this.map.clear(),this}has(t){return this.map.has(t)}entries(){return this.map.entries()}forEach(t=(...i)=>{},e){return this.map.forEach(t,e),this}[Symbol.iterator](){return this.entries()}},A=(r,t,...e)=>{r.forEach(i=>{i[t](...e)})},W=async(r,t,...e)=>{for(let[,i]of r)await i[t](...e)},E=class{constructor(){}install(){}register(t,e){return this.manager=t,this.app=t.app,this.config=t.config,this.emitter=t.emitter,this.key=e,this.install(),this}uninstall(){}unregister(){this.uninstall(),this.manager.delete(this.key),this.key=void 0,this.manager=void 0,this.app=void 0,this.config=void 0,this.emitter=void 0}},w=class extends u{constructor(t){super();this.app=t,this.config=t.config,this.emitter=t.emitter}set(t,e){return super.set(t,e),e.register(this,t),this}};var p=(r=window.location.href)=>r instanceof URL?r:new URL(r,window.location.origin),h=r=>`${r.pathname}${r.hash}`,ct=r=>r.hash.slice(1),_=r=>r.toString().replace(/(\/#.*|\/|#.*)$/,""),R=(r,t)=>{let e=p(r),i=p(t);return _(e)===_(i)};var x=(r=window.scrollX,t=window.scrollY)=>({x:r,y:t}),S=(r={url:h(p()),index:0,transition:"default",data:{scroll:x(),trigger:"HistoryManager"}})=>r,k=class{constructor(){this.pointer=-1;this.states=[];let t=S();this.add(t,"replace")}get(t){return this.states[t]}add(t,e="push"){let i=S(t),n=this.length;this.states.push({...i}),this.pointer=n;let o={index:this.pointer,states:[...this.states]};return Y(e,i,o),this}remove(t){return t?this.states.splice(t,1):this.states.pop(),this.pointer--,this}replace(t){return this.states=t,this}set(t,e){return this.states[t]=e}get current(){return this.get(this.pointer)}get last(){return this.get(this.length-1)}get previous(){return this.pointer<1?null:this.get(this.pointer-1)}get length(){return this.states.length}},Y=(r,t,e)=>{let i=h(p(t.url)),n=[e,"",i];if(window.history)switch(r){case"push":window.history.pushState.apply(window.history,n);break;case"replace":window.history.replaceState.apply(window.history,n);break}};var J=new DOMParser,b=class extends E{constructor(t=p(),e=document){super();this.url=t,typeof e=="string"?this.data=e:this.dom=e||document}async build(){if(this.dom instanceof Node||(this.dom=J.parseFromString(this.data,"text/html")),!(this.body instanceof Node)){let{title:t,head:e,body:i}=this.dom;this.title=t,this.head=e,this.body=i,this.wrapper=this.body.querySelector(this.wrapperAttr)}}install(){this.wrapperAttr=this.config.getConfig("wrapperAttr")}uninstall(){this.url=void 0,this.title=void 0,this.head=void 0,this.body=void 0,this.dom=void 0,this.wrapper=void 0,this.data=void 0,this.wrapperAttr=void 0}},O=class extends w{constructor(t){super(t);this.loading=new u;this.maxPages=5;let e=p().pathname;this.set(e,new b),e=void 0}async load(t=p()){let e=p(t),i=e.pathname,n,o;if(this.has(i))return n=this.get(i),Promise.resolve(n);this.loading.has(i)?o=this.loading.get(i):(o=this.request(i),this.loading.set(i,o));let s=await o;if(this.loading.delete(i),n=new b(e,s),this.set(i,n),this.size>this.maxPages){let a=p(),l=this.keys(),c=R(a,l[0])?l[1]:l[0],m=this.get(c);m.unregister(),m=void 0,l=void 0,a=void 0,c=void 0}return n}async request(t){let e=new Headers(this.config.getConfig("headers")),i=window.setTimeout(()=>{throw window.clearTimeout(i),"Request Timed Out!"},this.config.getConfig("timeout"));try{let n=await fetch(t,{mode:"same-origin",method:"GET",headers:e,cache:"default",credentials:"same-origin"});if(window.clearTimeout(i),n.status>=200&&n.status<300)return await n.text();let o=new Error(n.statusText||""+n.status);throw o}catch(n){throw window.clearTimeout(i),n}}};var j=({callback:r=()=>{},scope:t=null,name:e="event"})=>({callback:r,scope:t,name:e}),T=class extends u{constructor(t="event"){super();this.name=t}},v=class extends u{constructor(){super()}getEvent(t){let e=this.get(t);return e instanceof T?e:(this.set(t,new T(t)),this.get(t))}newListener(t,e,i){let n=this.getEvent(t);return n.add(j({name:t,callback:e,scope:i})),n}on(t,e,i){if(typeof t=="undefined")return this;typeof t=="string"&&(t=t.trim().split(/\s/g));let n,o,s=typeof t=="object"&&!Array.isArray(t),a=s?e:i;return s||(o=e),Object.keys(t).forEach(l=>{s?(n=l,o=t[l]):n=t[l],this.newListener(n,o,a)},this),this}removeListener(t,e,i){let n=this.get(t);if(n instanceof T&&e){let o=j({name:t,callback:e,scope:i});n.forEach((s,a)=>{if(s.callback===o.callback&&s.scope===o.scope)return n.delete(a)})}return n}off(t,e,i){if(typeof t=="undefined")return this;typeof t=="string"&&(t=t.trim().split(/\s/g));let n,o,s=typeof t=="object"&&!Array.isArray(t),a=s?e:i;return s||(o=e),Object.keys(t).forEach(l=>{s?(n=l,o=t[l]):n=t[l],typeof o=="function"?this.removeListener(n,o,a):this.delete(n)},this),this}emit(t,...e){return typeof t=="undefined"?this:(typeof t=="string"&&(t=t.trim().split(/\s/g)),t.forEach(i=>{let n=this.get(i);n instanceof T&&n.forEach(o=>{let{callback:s,scope:a}=o;s.apply(a,e)})},this),this)}};var I=class extends E{install(){let{app:t}=this.manager;this.PageManager=t.pages,this.HistoryManager=t.history,this.ServiceManager=t.services,this.TransitionManager=t.transitions}init(...t){}boot(){this.initEvents()}initEvents(){}stopEvents(){}uninstall(){this.PageManager=void 0,this.HistoryManager=void 0,this.ServiceManager=void 0,this.TransitionManager=void 0}stop(){this.stopEvents(),this.unregister()}},H=class extends w{constructor(t){super(t)}init(){return A(this,"init",this.app),this}boot(){return A(this,"boot",this.app),this}stop(){return A(this,"stop",this.app),this}};var X=class extends I{constructor(){super(...arguments);this.ignoreURLs=[];this.prefetchIgnore=!1;this.isTransitioning=!1;this.stopOnTransitioning=!1;this.stickyScroll=!1;this.forceOnError=!1;this.autoScrollOnHash=!0;this.dontScroll=!1}transitionStart(){this.isTransitioning=!0}transitionStop(){this.isTransitioning=!1}init(){super.init(),this.onHover=this.onHover.bind(this),this.onClick=this.onClick.bind(this),this.onStateChange=this.onStateChange.bind(this)}boot(){"scrollRestoration"in window.history&&(window.history.scrollRestoration="manual"),super.boot()}getTransitionName(t){if(!t||!t.getAttribute)return null;let e=t.getAttribute(this.config.getConfig("transitionAttr",!1));return typeof e=="string"?e:null}validLink(t,e,i){let n=!window.history.pushState,o=!t||!i,s=e.metaKey||e.ctrlKey||e.shiftKey||e.altKey,a=t.hasAttribute("target")&&t.target==="_blank",l=t.protocol!==location.protocol||t.hostname!==location.hostname,c=typeof t.getAttribute("download")=="string",m=t.hasAttribute(this.config.getConfig("preventSelfAttr",!1)),L=Boolean(t.closest(this.config.getConfig("preventAllAttr"))),d=m&&L,K=h(p())===h(p(i));return!(o||n||s||a||l||c||d||K)}getHref(t){return t&&t.tagName&&t.tagName.toLowerCase()==="a"&&typeof t.href=="string"?t.href:null}getLink(t){let e=t.target,i=this.getHref(e);for(;e&&!i;)e=e.parentNode,i=this.getHref(e);return!e||!this.validLink(e,t,i)?void 0:e}onClick(t){let e=this.getLink(t);if(!e)return;if(this.isTransitioning&&this.stopOnTransitioning){t.preventDefault(),t.stopPropagation();return}let i=this.getHref(e);this.emitter.emit("ANCHOR_CLICK CLICK",t),this.go({href:i,trigger:e,event:t})}getDirection(t){return Math.abs(t)>1?t>0?"forward":"back":t===0?"popstate":t>0?"back":"forward"}force(t){window.location.assign(t)}go({href:t,trigger:e="HistoryManager",event:i}){if(this.isTransitioning&&this.stopOnTransitioning){this.force(t);return}let n={x:0,y:0},o=this.HistoryManager.current,s=o.url;if(R(s,t))return;let a;if(i&&i.state){this.emitter.emit("POPSTATE",i);let{state:l}=i,{index:c}=l,m=o.index,L=m-c;e=this.getDirection(L);let d=this.HistoryManager.get(this.HistoryManager.pointer);a=d.transition,n=d.data.scroll,this.HistoryManager.replace(l.states),this.HistoryManager.pointer=c,e==="back"?this.emitter.emit("POPSTATE_BACK",i):e==="forward"&&this.emitter.emit("POPSTATE_FORWARD",i)}else{a=this.getTransitionName(e)||"default",n=x();let l=S({url:t,transition:a,data:{scroll:n}});this.HistoryManager.add(l),this.emitter.emit("HISTORY_NEW_ITEM",i)}return i&&(i.stopPropagation(),i.preventDefault()),this.emitter.emit("GO",i),this.load({oldHref:s,href:t,trigger:e,transitionName:a,scroll:n})}async load({oldHref:t,href:e,trigger:i,transitionName:n="default",scroll:o={x:0,y:0}}){try{let s=await this.PageManager.load(t);await s.build();let a;this.emitter.emit("PAGE_LOADING",{href:e,oldPage:s,trigger:i});try{try{a=await this.PageManager.load(e),await a.build(),this.transitionStart(),this.emitter.emit("PAGE_LOAD_COMPLETE",{newPage:a,oldPage:s,trigger:i})}catch(l){console.error(`[PJAX] page load error: ${l}`)}this.emitter.emit("NAVIGATION_START",{oldPage:s,newPage:a,trigger:i,transitionName:n});try{this.emitter.emit("TRANSITION_START",n);let l=await this.TransitionManager.boot(n,{oldPage:s,newPage:a,trigger:i,scroll:o});l.scrollable||(/back|popstate|forward/.test(i)||(o=N()),window.scroll(o.x,o.y)),this.emitter.emit("TRANSITION_END",{transition:l})}catch(l){console.error(`[PJAX] transition error: ${l}`)}this.emitter.emit("NAVIGATION_END",{oldPage:s,newPage:a,trigger:i,transitionName:n})}catch(l){throw this.transitionStop(),l}this.transitionStop()}catch(s){this.forceOnError?this.force(e):console.error(s)}}ignoredURL({pathname:t}){return this.ignoreURLs.length&&this.ignoreURLs.some(e=>typeof e=="string"?e===t:e.exec(t)!==null)}onHover(t){let e=this.getLink(t);if(!e)return;let i=p(this.getHref(e)),n=i.pathname;if(this.ignoredURL(i)||this.PageManager.has(n))return;this.emitter.emit("ANCHOR_HOVER HOVER",t);try{this.PageManager.load(i)}catch(o){console.warn("[PJAX] prefetch error,",o)}}onStateChange(t){this.go({href:window.location.href,trigger:"popstate",event:t})}initEvents(){this.prefetchIgnore!==!0&&(document.addEventListener("mouseover",this.onHover),document.addEventListener("touchstart",this.onHover)),document.addEventListener("click",this.onClick),window.addEventListener("popstate",this.onStateChange)}stopEvents(){this.prefetchIgnore!==!0&&(document.removeEventListener("mouseover",this.onHover),document.removeEventListener("touchstart",this.onHover)),document.removeEventListener("click",this.onClick),window.removeEventListener("popstate",this.onStateChange)}},N=(r=window.location.hash)=>{try{let t=r[0]=="#"?r:p(r).hash;if(t.length>1){let e=document.getElementById(t.slice(1));if(e)return x(e.offsetLeft,e.offsetTop)}}catch(t){console.warn("hashAction error",t)}return x(0,0)},F=class extends u{constructor(t){super();this.app=t,this.config=t.config,this.emitter=t.emitter}async boot(t,e){let i=this.get(t),n=e.scroll;if(!(e.oldPage instanceof b)||!(e.newPage instanceof b))throw`[Page] either oldPage or newPage aren't instances of the Page Class. + ${{newPage:e.newPage,oldPage:e.oldPage}}`;let o=e.oldPage.wrapper,s=e.newPage.wrapper;if(document.title=""+e.newPage.title,!(o instanceof Node)||!(s instanceof Node))throw`[Wrapper] the wrapper from the ${s instanceof Node?"current":"next"} page cannot be found. The wrapper must be an element that has the attribute ${this.config.getConfig("wrapperAttr")}.`;return i.init&&i?.init(e),this.emitter.emit("BEFORE_TRANSITION_OUT"),await new Promise(a=>{let l=i.out.call(i,{...e,from:e.oldPage,trigger:e.trigger,done:a});l.then&&l.then(a)}),this.emitter.emit("AFTER_TRANSITION_OUT"),await new Promise(a=>{o.insertAdjacentElement("beforebegin",s),this.emitter.emit("CONTENT_INSERT"),/back|popstate|forward/.test(e.trigger)||(n=N()),a()}),await new Promise(a=>{o.remove(),o=void 0,s=void 0,this.emitter.emit("CONTENT_REPLACED"),a()}),this.emitter.emit("BEFORE_TRANSITION_IN"),await new Promise(a=>{let l=i.in.call(i,{...e,from:e.oldPage,to:e.newPage,trigger:e.trigger,scroll:n,done:a});l.then&&l.then(a)}),this.emitter.emit("AFTER_TRANSITION_IN"),i}};var Q=class{constructor(t={}){this.register(t)}register(t={}){this.config=t instanceof P?t:new P(t),this.emitter=new v,this.history=new k,this.pages=new O(this),this.transitions=new F(this),this.services=new H(this);let e=(()=>{document.removeEventListener("DOMContentLoaded",e),window.removeEventListener("load",e),this.emitter.emit("READY ready")}).bind(this);return document.addEventListener("DOMContentLoaded",e),window.addEventListener("load",e),this}get(t,e){switch(t.toLowerCase()){case"service":return this.services.get(e);case"transition":return this.transitions.get(e);case"state":return this.history.get(e);default:throw`Error: can't get type '${t}', it is not a recognized type. Did you spell it correctly.`}}async load(t,e){switch(t.toLowerCase()){case"page":return await this.pages.load(e);default:return Promise.resolve(this.get(t,e))}}setService(t,e){return this.services.set(t,e),this}setTransition(t,e){return this.transitions.set(t,e),this}add(t,e){switch(t.toLowerCase()){case"service":this.services.add(e);break;case"transition":this.transitions.set(e.name,e);break;case"state":this.history.add(e);break;default:throw`Error: can't add type '${t}', it is not a recognized type. Did you spell it correctly.`}return this}boot(){return this.services.init(),this.services.boot(),this}stop(){return this.services.stop(),this}on(t,e){return this.emitter.on(t,e,this),this}off(t,e){return this.emitter.off(t,e,this),this}emit(t,...e){return this.emitter.emit(t,...e),this}};var Z=class extends I{constructor(t=[]){super();this.routes=new u;for(let e of t)this.add(e)}add({path:t,method:e}){let i=this.parse(t);return this.routes.set(i,e),this}parsePath(t){if(typeof t=="string")return new RegExp(t,"i");if(t instanceof RegExp||typeof t=="boolean")return t;throw"[Router] only regular expressions, strings and booleans are accepted as paths."}isPath(t){return typeof t=="string"||t instanceof RegExp||typeof t=="boolean"}parse(t){let e=t,i={from:/(.*)/g,to:/(.*)/g};if(this.isPath(t))i={from:!0,to:t};else if(this.isPath(e.from)&&this.isPath(e.to))i=e;else throw"[Router] path is neither a string, regular expression, or a { from, to } object.";let{from:n,to:o}=i;return{from:this.parsePath(n),to:this.parsePath(o)}}route(){let t=this.HistoryManager,e=h(p((t.length>1?t.previous:t.current).url)),i=h(p());this.routes.forEach((n,o)=>{let s=o.from,a=o.to;if(typeof s=="boolean"&&typeof a=="boolean")throw`[Router] path ({ from: ${s}, to: ${a} }) is not valid, remember paths can only be strings, regular expressions, or a boolean; however, both the from and to paths cannot be both booleans.`;let l=s,c=a;s instanceof RegExp&&s.test(e)&&(l=s.exec(e)),a instanceof RegExp&&a.test(i)&&(c=a.exec(i)),(Array.isArray(c)&&Array.isArray(l)||Array.isArray(c)&&typeof l=="boolean"&&l||Array.isArray(l)&&typeof c=="boolean"&&c)&&n({from:l,to:c,path:{from:e,to:i}})})}initEvents(){this.emitter.on("READY",this.route,this),this.emitter.on("CONTENT_REPLACED",this.route,this)}stopEvents(){this.emitter.off("READY",this.route,this),this.emitter.off("CONTENT_REPLACED",this.route,this)}};var tt=r=>typeof r=="string"?Array.from(document.querySelectorAll(r)):[r],et=r=>Array.isArray(r)?r:typeof r=="string"||r instanceof Node?tt(r):r instanceof NodeList||r instanceof HTMLCollection?Array.from(r):[],z=(r,t)=>typeof r=="function"?r(...t):r,U=(r,t)=>{let e,i,n={},o=Object.keys(r);for(let s=0,a=o.length;s/^(ease|in|out)/.test(r)?it[r]:r,nt={keyframes:[],loop:1,delay:0,speed:1,endDelay:0,easing:"ease",autoplay:!0,duration:1e3,onfinish(){},fillMode:"auto",direction:"normal"},V=class{constructor(t={}){this.options={};this.targets=[];this.properties={};this.animations=new Map;this.duration=0;this.emitter=new v;let{options:e,...i}=t;this.options=Object.assign({},nt,e,i),this.loop=this.loop.bind(this);let{loop:n,delay:o,speed:s,easing:a,endDelay:l,duration:c,direction:m,fillMode:L,onfinish:d,target:K,keyframes:ot,autoplay:st,...at}=this.options;this.mainElement=document.createElement("span"),this.targets=et(K),this.properties=at;let C;for(let g=0,M=this.targets.length;g0||(C=U(C,[g,M,y]));let G=f.delay+f.duration*f.iterations+f.endDelay;this.duration{d(y,g,M)},this.animations.set(y,q)}this.mainAnimation=this.mainElement.animate([{opacity:"0"},{opacity:"1"}],{duration:this.duration,easing:"linear"}),this.setSpeed(s),st?this.play():this.pause(),this.promise=this.newPromise(),this.mainAnimation.onfinish=()=>{this.finish(this.options),window.cancelAnimationFrame(this.animationFrame)}}getTargets(){return this.targets}newPromise(){return new Promise((t,e)=>{try{this.finish=i=>(this.emit("finish",i),t(i))}catch(i){e(i)}})}then(t,e){return this.promise.then(t,e)}catch(t){return this.promise.catch(t)}finally(t){return this.promise.finally(t)}loop(){this.animationFrame=window.requestAnimationFrame(this.loop),this.emit("tick change",this.getCurrentTime())}on(t,e,i){return this.emitter.on(t,e,i),this}off(t,e,i){return this.emitter.off(t,e,i),this}emit(t,...e){return this.emitter.emit(t,...e),this}getAnimation(t){return this.animations.get(t)}play(){return this.mainAnimation.playState!=="finished"&&(this.mainAnimation.play(),this.animationFrame=requestAnimationFrame(this.loop),this.animations.forEach(t=>{t.playState!=="finished"&&t.play()}),this.emit("play")),this}pause(){return this.mainAnimation.playState!=="finished"&&(this.mainAnimation.pause(),window.cancelAnimationFrame(this.animationFrame),this.animations.forEach(t=>{t.playState!=="finished"&&t.pause()}),this.emit("pause")),this}getDuration(){return this.duration}getCurrentTime(){return this.mainAnimation.currentTime}setCurrentTime(t){return this.mainAnimation.currentTime=t,this.animations.forEach(e=>{e.currentTime=t}),this}getProgress(){return this.getCurrentTime()/this.duration}setProgress(t){return this.mainAnimation.currentTime=t*this.duration,this.animations.forEach(e=>{e.currentTime=t*this.duration}),this}getSpeed(){return this.mainAnimation.playbackRate}setSpeed(t=1){return this.mainAnimation.playbackRate=t,this.animations.forEach(e=>{e.playbackRate=t}),this}reset(){this.setCurrentTime(0),this.promise=this.newPromise(),this.options.autoplay?this.play():this.pause()}getPlayState(){return this.mainAnimation.playState}getOptions(){return this.options}toJSON(){return this.getOptions()}},ut=(r={})=>new V(r); //# sourceMappingURL=api.node.js.map diff --git a/packages/native/lib/api.node.js.map b/packages/native/lib/api.node.js.map index 043f543..a00268d 100644 --- a/packages/native/lib/api.node.js.map +++ b/packages/native/lib/api.node.js.map @@ -1,7 +1,7 @@ { "version": 3, - "sources": ["../src/api.ts", "../src/config.ts", "../../manager/src/api.ts", "../src/manager.ts", "../src/url.ts", "../src/history.ts", "../src/page.ts", "../../emitter/src/api.ts", "../src/service.ts", "../src/transition.ts", "../src/app.ts", "../src/pjax.ts", "../src/route.ts", "../../animate/src/api.ts"], - "sourcesContent": ["export * from \"./config\";\r\nexport * from \"./manager\";\r\nexport * from \"./url\";\r\n\r\nexport * from \"./history\";\r\nexport * from \"./page\";\r\n\r\nexport * from \"./emitter\";\r\nexport * from \"./service\";\r\n\r\nexport * from \"./transition\";\r\n\r\nexport * from \"./app\";\r\nexport * from \"./pjax\";\r\nexport * from \"./route\";\r\n\r\nexport * from \"@okikio/animate\";\r\n", "// The config variables\r\nexport interface ICONFIG {\r\n prefix?: string;\r\n wrapperAttr?: string;\r\n noAjaxLinkAttr?: string;\r\n noPrefetchAttr?: \"no-prefetch\";\r\n headers?: string[][];\r\n preventSelfAttr?: string;\r\n preventAllAttr?: string;\r\n transitionAttr?: string;\r\n blockAttr?: string;\r\n timeout?: number\r\n}\r\n\r\nexport const CONFIG_DEFAULTS: ICONFIG = {\r\n wrapperAttr: \"wrapper\",\r\n noAjaxLinkAttr: \"no-ajax-link\",\r\n noPrefetchAttr: \"no-prefetch\",\r\n headers: [\r\n [\"x-partial\", \"true\"]\r\n ],\r\n preventSelfAttr: `prevent=\"self\"`,\r\n preventAllAttr: `prevent=\"all\"`,\r\n transitionAttr: \"transition\",\r\n blockAttr: `block`,\r\n timeout: 30000\r\n};\r\n\r\nexport type ConfigKeys = keyof ICONFIG;\r\n\r\n/**\r\n * The Config class\r\n *\r\n * @export\r\n * @class CONFIG\r\n */\r\nexport class CONFIG {\r\n /**\r\n * The current Configuration\r\n *\r\n * @public\r\n * @type ICONFIG\r\n * @memberof CONFIG\r\n */\r\n public config: ICONFIG;\r\n\r\n /**\r\n * Creates an instance of CONFIG.\r\n *\r\n * @param {ICONFIG} config\r\n * @memberof CONFIG\r\n */\r\n constructor(config: ICONFIG) {\r\n this.config = Object.assign({ ...CONFIG_DEFAULTS }, config);\r\n }\r\n\r\n /**\r\n * Converts string into data attributes\r\n *\r\n * @param {string} value\r\n * @param {boolean} brackets [brackets=true]\r\n * @returns string\r\n * @memberof CONFIG\r\n */\r\n public toAttr(value: string, brackets: boolean = true): string {\r\n let { prefix } = this.config;\r\n let attr = `data${prefix ? \"-\" + prefix : \"\"}-${value}`;\r\n return brackets ? `[${attr}]` : attr;\r\n }\r\n\r\n /**\r\n * Selects config vars, and formats them for use, or simply returns the current configurations for the framework\r\n *\r\n * @param {ConfigKeys} value\r\n * @param {boolean} [brackets=true]\r\n * @returns any\r\n * @memberof CONFIG\r\n */\r\n public getConfig(value?: ConfigKeys, brackets: boolean = true): any {\r\n if (typeof value !== \"string\")\r\n return this.config;\r\n\r\n let config = this.config[value];\r\n if (typeof config === \"string\")\r\n return this.toAttr(config, brackets);\r\n return config;\r\n }\r\n}\r\n", "/**\r\n * Manages complex lists of named data, eg. A page can be stored in a list by of other pages with the url being how the page is stored in the list. Managers use Maps to store data.\r\n *\r\n * @export\r\n * @class Manager\r\n * @template K\r\n * @template V\r\n */\r\nexport class Manager {\r\n\t/**\r\n\t * The complex list of named data, to which the Manager controls\r\n\t *\r\n\t * @public\r\n\t * @type Map\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic map: Map;\r\n\r\n\t/**\r\n\t * Creates an instance of Manager.\r\n\t *\r\n\t * @param {Array<[K, V]>} [value]\r\n\t * @memberof Manager\r\n\t */\r\n\tconstructor(value?: Array<[K, V]>) {\r\n\t\tthis.map = new Map(value);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the Manager class's list\r\n\t *\r\n\t * @returns Map\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic getMap(): Map {\r\n\t\treturn this.map;\r\n\t}\r\n\r\n\t/**\r\n\t * Get a value stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key to find in the Manager's list\r\n\t * @returns V\r\n\t */\r\n\tpublic get(key: K): V {\r\n\t\treturn this.map.get(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the keys of all items stored in the Manager as an Array\r\n\t *\r\n\t * @returns Array\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic keys(): Array {\r\n\t\treturn Array.from(this.map.keys());\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the values of all items stored in the Manager as an Array\r\n\t *\r\n\t * @returns Array\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic values(): Array {\r\n\t\treturn Array.from(this.map.values());\r\n\t}\r\n\r\n\t/**\r\n\t * Set a value stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key where the value will be stored\r\n\t * @param {V} value - The value to store\r\n\t * @returns Manager\r\n\t */\r\n\tpublic set(key: K, value: V): Manager {\r\n\t\tthis.map.set(key, value);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Adds a value to Manager, and uses the current size of the Manager as it's key, it works best when all the key in the Manager are numbers\r\n\t *\r\n\t * @public\r\n\t * @param {V} value\r\n\t * @returns Manager\r\n\t */\r\n\tpublic add(value: V): Manager {\r\n\t\tlet size = this.size;\r\n\t\t// @ts-ignore\r\n\t\tlet num: K = size as K;\r\n\t\tthis.set(num, value);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the total number of items stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @returns Number\r\n\t */\r\n\tpublic get size(): number {\r\n\t\treturn this.map.size;\r\n\t}\r\n\r\n\tpublic get length(): number {\r\n\t\treturn this.map.size;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the last item in the Manager who's index is a certain distance from the last item in the Manager\r\n\t *\r\n\t * @param {number} [distance=1]\r\n\t * @returns V | undefined\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic last(distance: number = 1): V | undefined {\r\n\t\tlet key = this.keys()[this.size - distance];\r\n\t\treturn this.get(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Removes a value stored in the Manager, via the key, returns true if an element in the Map object existed and has been removed, or false if the element does not exist.\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key for the key value pair to be removed\r\n\t * @returns boolean\r\n\t */\r\n\tpublic delete(key: K): boolean {\r\n\t\treturn this.map.delete(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Removes a value stored in the Manager, via the key, returns the Manager class, allowing for chains\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key for the key value pair to be removed\r\n\t * @returns Manager\r\n\t */\r\n\tpublic remove(key: K): Manager {\r\n\t\tthis.map.delete(key);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Clear the Manager of all its contents\r\n\t *\r\n\t * @public\r\n\t * @returns Manager\r\n\t */\r\n\tpublic clear(): Manager {\r\n\t\tthis.map.clear();\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Checks if the Manager contains a certain key\r\n\t *\r\n\t * @public\r\n\t * @param {K} key\r\n\t * @returns boolean\r\n\t */\r\n\tpublic has(key: K): boolean {\r\n\t\treturn this.map.has(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a new Iterator object that contains an array of [key, value] for each element in the Map object in insertion order.\r\n\t *\r\n\t * @public\r\n\t * @returns IterableIterator<[K, V]>\r\n\t */\r\n\tpublic entries(): IterableIterator<[K, V]> {\r\n\t\treturn this.map.entries();\r\n\t}\r\n\r\n\t/**\r\n\t * Iterates through the Managers contents, calling a callback function every iteration\r\n\t *\r\n\t * @param {*} [callback=(...args: any): void => { }]\r\n\t * @param {object} context\r\n\t * @returns Manager\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic forEach(\r\n\t\tcallback: any = (...args: any): void => { },\r\n\t\tcontext?: object\r\n\t): Manager {\r\n\t\tthis.map.forEach(callback, context);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Allows iteration via the for..of, learn more: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators]\r\n\t *\r\n\t * @returns IterableIterator<[K, V]>\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic [Symbol.iterator](): IterableIterator<[K, V]> {\r\n\t\treturn this.entries();\r\n\t}\r\n}\r\n\r\n/**\r\n * Calls the method of a certain name for all items that are currently installed\r\n *\r\n * @param {Manager} manager\r\n * @param {string} method\r\n * @param {Array} [args=[]]\r\n */\r\nexport const methodCall = (manager: Manager, method: string, ...args: any): void => {\r\n\tmanager.forEach((item) => {\r\n\t\t// @ts-ignore\r\n\t\titem[method](...args);\r\n\t});\r\n};\r\n\r\n/**\r\n * Asynchronously calls the method of a certain name for all items that are currently installed, similar to methodCall\r\n *\r\n * @param {Manager} manager\r\n * @param {string} method\r\n * @param {Array} [args=[]]\r\n */\r\nexport const asyncMethodCall = async (manager: Manager, method: string, ...args: any): Promise => {\r\n\tfor (let [, item] of manager) {\r\n\t\t// @ts-ignore\r\n\t\tawait item[method](...args);\r\n\t}\r\n};\r\n\r\nexport default Manager;\r\n", "import { Manager, methodCall, asyncMethodCall } from \"@okikio/manager\";\r\nimport { CONFIG } from \"./config\";\r\nimport { App } from \"./app\";\r\nimport EventEmitter from \"@okikio/emitter\";\r\n\r\nexport type IAdvancedManager = AdvancedManager;\r\n\r\n/**\r\n * The base class for all AdvancedManager and AdvancedStorage items\r\n *\r\n * @export\r\n * @class ManagerItem\r\n */\r\nexport class ManagerItem {\r\n /**\r\n * The AdvancedManager the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type IAdvancedManager\r\n * @memberof ManagerItem\r\n */\r\n public manager: IAdvancedManager;\r\n\r\n /**\r\n * The App the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type App\r\n * @memberof ManagerItem\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof ManagerItem\r\n */\r\n public config: CONFIG;\r\n public emitter: EventEmitter;\r\n public key: any;\r\n\r\n /**\r\n * Creates an instance of ManagerItem.\r\n *\r\n * @memberof ManagerItem\r\n */\r\n constructor() { }\r\n\r\n /**\r\n * Run after the Manager Item has been registered\r\n *\r\n * @returns any\r\n * @memberof ManagerItem\r\n */\r\n public install(): any { }\r\n\r\n /**\r\n * Register the current Manager Item's manager\r\n *\r\n * @param {IAdvancedManager} manager\r\n * @returns ManagerItem\r\n * @memberof ManagerItem\r\n */\r\n public register(manager: IAdvancedManager, key: any): ManagerItem {\r\n this.manager = manager;\r\n this.app = manager.app;\r\n this.config = manager.config;\r\n this.emitter = manager.emitter;\r\n this.key = key;\r\n this.install();\r\n return this;\r\n }\r\n\r\n public uninstall(): any { }\r\n\r\n public unregister() {\r\n this.uninstall();\r\n\r\n this.manager.delete(this.key);\r\n this.key = undefined;\r\n this.manager = undefined;\r\n this.app = undefined;\r\n this.config = undefined;\r\n this.emitter = undefined;\r\n }\r\n}\r\n\r\n/**\r\n * A tweak to the Manager class that makes it self aware of the App class it's instantiated in\r\n *\r\n * @export\r\n * @class AdvancedManager\r\n * @extends {Manager}\r\n * @template K\r\n * @template V\r\n */\r\nexport class AdvancedManager extends Manager {\r\n /**\r\n * The instance of the App class, the Manager is instantiated in\r\n *\r\n * @type App\r\n * @memberof AdvancedManager\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof AdvancedManager\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * The EventEmitter class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof AdvancedManager\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * Creates an instance of AdvancedManager.\r\n *\r\n * @param {App} app - The instance of the App class, the Manager is instantiated in\r\n * @memberof AdvancedManager\r\n */\r\n constructor(app: App) {\r\n super();\r\n this.app = app;\r\n this.config = app.config;\r\n this.emitter = app.emitter;\r\n }\r\n\r\n /**\r\n * Set a value stored in the Manager\r\n *\r\n * @public\r\n * @param {K} key - The key where the value will be stored\r\n * @param {V} value - The value to store\r\n * @returns AdvancedManager\r\n */\r\n public set(key: K, value: V) {\r\n super.set(key, value);\r\n value.register(this, key);\r\n return this;\r\n }\r\n}\r\n\r\nexport { Manager, methodCall, asyncMethodCall };\r\n", "/**\r\n * Adds new methods to the native URL Object; it seemed cleaner than using a custom method or editing the prototype.\r\n *\r\n * This doesn't extend the **Class** object because it's meant to be a small extension of the native URL class.\r\n *\r\n * @export\r\n * @class URL\r\n * @extends {URL}\r\n */\r\n// Read up on the native URL class [devdocs.io/dom/url]\r\n/**\r\n * Creates an instance of URL.\r\n *\r\n * @param {(string | URL | Location)} [url=window.location.pathname]\r\n * @return URL\r\n */\r\nexport const newURL = (url: string | URL | Location = window.location.href): URL => {\r\n return url instanceof URL ? url : new URL(url as unknown as string, window.location.origin);\r\n};\r\n\r\n/**\r\n * Returns the pathname with the hash\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const getHashedPath = (url: URL): string => (`${url.pathname}${url.hash}`);\r\n\r\n/**\r\n * Returns the actual hash without the hashtag\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const getHash = (url: URL): string => (url.hash.slice(1));\r\n\r\n/**\r\n * Removes the hash from the full URL for a clean URL string\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const clean = (url: URL): string => (url.toString().replace(/(\\/#.*|\\/|#.*)$/, ''));\r\n\r\n/**\r\n * Compares two URLs to each other\r\n *\r\n * @param {URL} a\r\n * @param {URL} b\r\n * @returns boolean\r\n */\r\nexport const equal = (a: URL | string, b: URL | string): boolean => {\r\n let urlA = newURL(a);\r\n let urlB = newURL(b);\r\n return clean(urlA) === clean(urlB);\r\n};\r\n", "import { getHashedPath, newURL } from \"./url\";\r\n\r\nexport type Trigger = HTMLAnchorElement | \"HistoryManager\" | \"popstate\" | \"back\" | \"forward\";\r\nexport interface ICoords {\r\n\treadonly x: number;\r\n\treadonly y: number;\r\n}\r\n\r\nexport interface IStateData {\r\n\tscroll: ICoords;\r\n\t[key: string]: any;\r\n}\r\n\r\nexport interface IState {\r\n\turl: string;\r\n\tindex?: number;\r\n\ttransition: string;\r\n\tdata: IStateData;\r\n}\r\n\r\nexport interface IHistoryItem {\r\n\tindex: number;\r\n\tstates: IState[];\r\n}\r\n\r\n/**\r\n * A quick snapshot of page coordinates, e.g. scroll positions\r\n *\r\n * @export\r\n * @param {number} [x=window.scrollX]\r\n * @param {number} [y=window.scrollY]\r\n */\r\nexport const newCoords = (x: number = window.scrollX, y: number = window.scrollY): ICoords => ({ x, y });\r\n\r\n/**\r\n * Represents the current status of the page consisting of properties like: url, transition, and data\r\n *\r\n * @export\r\n * @param {IState} {\r\n * url = getHashedPath(newURL()),\r\n * index = 0,\r\n * transition = \"default\",\r\n * data = {\r\n * scroll: newCoords(),\r\n * trigger: \"HistoryManager\"\r\n * }\r\n * }\r\n * @memberof State\r\n*/\r\nexport const newState = (state: IState = {\r\n\turl: getHashedPath(newURL()),\r\n\tindex: 0,\r\n\ttransition: \"default\",\r\n\tdata: {\r\n\t\tscroll: newCoords(),\r\n\t\ttrigger: \"HistoryManager\"\r\n\t}\r\n}): IState => (state);\r\n\r\n\r\n/**\r\n * History of the site, stores only the State class\r\n *\r\n * @export\r\n * @class HistoryManager\r\n * @extends {Manager}\r\n */\r\nexport class HistoryManager {\r\n\tpublic states: IState[];\r\n\tpublic pointer = -1;\r\n\r\n\t/**\r\n\t * Creates an instance of the HistoryManager class, which inherits properties and methods from the Storage class.\r\n\t *\r\n\t * @memberof HistoryManager\r\n\t * @constructor\r\n\t */\r\n\tconstructor() {\r\n\t\tthis.states = [];\r\n\r\n\t\tlet state = newState();\r\n\t\tthis.add(state, \"replace\");\r\n\t}\r\n\r\n\tpublic get(index: number) {\r\n\t\treturn this.states[index];\r\n\t}\r\n\r\n\t/**\r\n\t * Sets the index of the state before adding to HistoryManager\r\n\t *\r\n\t * @param {IState} value\r\n\t * @returns HistoryManager\r\n\t */\r\n\tpublic add(value?: IState, historyAction: \"replace\" | \"push\" = \"push\"): HistoryManager {\r\n\t\tlet state = newState(value);\r\n\t\tlet len = this.length;\r\n\t\tthis.states.push({ ...state });\r\n\t\tthis.pointer = len;\r\n\r\n\t\tlet item: IHistoryItem = {\r\n\t\t\tindex: this.pointer,\r\n\t\t\tstates: [...this.states]\r\n\t\t};\r\n\t\tthis.changeState(historyAction, state, item);\r\n\t\treturn this;\r\n\t}\r\n\r\n\tpublic remove(index?: number) {\r\n\t\tif (index) {\r\n\t\t\tthis.states.splice(index, 1);\r\n\t\t} else {\r\n\t\t\tthis.states.pop();\r\n\t\t}\r\n\r\n\t\tthis.pointer--;\r\n\t\treturn this;\r\n\t}\r\n\r\n\tpublic replace(newStates: IState[]) {\r\n\t\tthis.states = newStates;\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Set state by index.\r\n\t */\r\n\tpublic set(i: number, state: IState) {\r\n\t\treturn (this.states[i] = state);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the current state.\r\n\t */\r\n\tget current(): IState {\r\n\t\treturn this.get(this.pointer);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the last state (top of the history stack).\r\n\t */\r\n\tget last(): IState {\r\n\t\treturn this.get(this.length - 1);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the previous state.\r\n\t */\r\n\tget previous(): IState | null {\r\n\t\treturn this.pointer < 1 ? null : this.get(this.pointer - 1);\r\n\t}\r\n\r\n\tget length() {\r\n\t\treturn this.states.length;\r\n\t}\r\n\r\n\t/**\r\n\t * Either push or replace history state\r\n\t *\r\n\t * @param {(\"push\" | \"replace\")} action\r\n\t * @param {IState} state\r\n\t * @param {_URL} url\r\n\t * @memberof PJAX\r\n\t */\r\n\tpublic changeState(action: \"push\" | \"replace\", state: IState, item: object) {\r\n\t\tlet href = getHashedPath(newURL(state.url));\r\n\t\tlet args = [item, \"\", href];\r\n\t\tif (window.history) {\r\n\t\t\tswitch (action) {\r\n\t\t\t\tcase \"push\":\r\n\t\t\t\t\twindow.history.pushState.apply(window.history, args);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"replace\":\r\n\t\t\t\t\twindow.history.replaceState.apply(window.history, args);\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n", "import { Manager, ManagerItem, AdvancedManager } from \"./manager\";\r\nimport { equal, newURL } from \"./url\";\r\nimport { App } from \"./app\";\r\n\r\n/**\r\n * Parses strings to DOM\r\n */\r\nexport const PARSER: DOMParser = new DOMParser();\r\n\r\n/**\r\n * A page represents the DOM elements that create each page\r\n *\r\n * @export\r\n * @class Page\r\n */\r\nexport class Page extends ManagerItem {\r\n /**\r\n * Holds the DOM of the current page\r\n *\r\n * @public\r\n * @type Document\r\n * @memberof Page\r\n */\r\n public dom: Document;\r\n\r\n /**\r\n * Holds the wrapper element to be swapped out of each Page\r\n *\r\n * @public\r\n * @type HTMLElement\r\n * @memberof Page\r\n */\r\n public wrapper: HTMLElement;\r\n\r\n /**\r\n * Holds the title of each page\r\n *\r\n * @public\r\n * @type string\r\n * @memberof Page\r\n */\r\n public title: string;\r\n\r\n /**\r\n * Holds the head element of each page\r\n *\r\n * @public\r\n * @type Element\r\n * @memberof Page\r\n */\r\n public head: Element;\r\n\r\n /**\r\n * Holds the body element of each page\r\n *\r\n * @public\r\n * @type Element\r\n * @memberof Page\r\n */\r\n public body: Element;\r\n\r\n /**\r\n * The URL of the current page\r\n *\r\n * @public\r\n * @type URL\r\n * @memberof Page\r\n */\r\n public url: URL;\r\n public data: string;\r\n public wrapperAttr: string;\r\n\r\n /**\r\n * Creates an instance of Page, it also creates a new page from response text, or a Document Object\r\n *\r\n * @param {URL} [url = newURL()]\r\n * @param {(string | Document)} [dom=document]\r\n * @memberof Page\r\n */\r\n constructor(url: URL = newURL(), dom: string | Document = document) {\r\n super();\r\n this.url = url;\r\n\r\n if (typeof dom === \"string\") {\r\n this.data = dom;\r\n } else this.dom = dom || document;\r\n }\r\n\r\n public async build() {\r\n if (!(this.dom instanceof Node)) {\r\n this.dom = PARSER.parseFromString(this.data, \"text/html\");\r\n }\r\n\r\n if (!(this.body instanceof Node)) {\r\n let { title, head, body } = this.dom;\r\n this.title = title;\r\n this.head = head;\r\n this.body = body;\r\n this.wrapper = this.body.querySelector(this.wrapperAttr);\r\n }\r\n }\r\n\r\n /**\r\n * Runs once the the manager and config have been registered\r\n *\r\n * @returns void\r\n * @memberof Page\r\n */\r\n public install(): void {\r\n this.wrapperAttr = this.config.getConfig(\"wrapperAttr\");\r\n }\r\n\r\n public uninstall() {\r\n this.url = undefined;\r\n this.title = undefined;\r\n this.head = undefined;\r\n this.body = undefined;\r\n this.dom = undefined;\r\n this.wrapper = undefined;\r\n this.data = undefined;\r\n this.wrapperAttr = undefined;\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Controls which page to be load\r\n *\r\n * @export\r\n * @class PageManager\r\n * @extends {AdvancedManager}\r\n */\r\nexport class PageManager extends AdvancedManager {\r\n /**\r\n * Stores all URLs that are currently loading\r\n *\r\n * @public\r\n * @type Manager>\r\n * @memberof PageManager\r\n */\r\n public loading: Manager> = new Manager();\r\n public maxPages = 5;\r\n\r\n /**\r\n * Creates an instance of the PageManager\r\n *\r\n * @param {App} app\r\n * @memberof PageManager\r\n */\r\n constructor(app: App) {\r\n super(app);\r\n let URLString = newURL().pathname;\r\n this.set(URLString, new Page());\r\n URLString = undefined;\r\n }\r\n\r\n /**\r\n * Load from cache or by requesting URL via a fetch request, avoid requesting for the same thing twice by storing the fetch request in \"this.loading\"\r\n *\r\n * @param {(URL | string)} [_url=newURL()]\r\n * @returns Promise\r\n * @memberof PageManager\r\n */\r\n public async load(_url: URL | string = newURL()): Promise {\r\n let url: URL = newURL(_url);\r\n let urlString: string = url.pathname;\r\n let page: Page, request: Promise;\r\n if (this.has(urlString)) {\r\n page = this.get(urlString);\r\n return Promise.resolve(page);\r\n }\r\n\r\n if (!this.loading.has(urlString)) {\r\n request = this.request(urlString);\r\n this.loading.set(urlString, request);\r\n } else request = this.loading.get(urlString);\r\n\r\n let response = await request;\r\n this.loading.delete(urlString);\r\n\r\n page = new Page(url, response);\r\n this.set(urlString, page);\r\n\r\n if (this.size > this.maxPages) {\r\n let currentUrl = newURL();\r\n let keys = this.keys();\r\n let first = equal(currentUrl, keys[0]) ? keys[1] : keys[0];\r\n let page = this.get(first);\r\n page.unregister();\r\n page = undefined;\r\n keys = undefined;\r\n currentUrl = undefined;\r\n first = undefined;\r\n }\r\n return page;\r\n }\r\n\r\n /**\r\n * Starts a fetch request\r\n *\r\n * @param {string} url\r\n * @returns Promise\r\n * @memberof PageManager\r\n */\r\n public async request(url: string): Promise {\r\n const headers = new Headers(this.config.getConfig(\"headers\"));\r\n const timeout = window.setTimeout(() => {\r\n window.clearTimeout(timeout);\r\n throw \"Request Timed Out!\";\r\n }, this.config.getConfig(\"timeout\"));\r\n\r\n try {\r\n let response = await fetch(url, {\r\n mode: 'same-origin',\r\n method: \"GET\",\r\n headers,\r\n cache: \"default\",\r\n credentials: \"same-origin\",\r\n });\r\n\r\n window.clearTimeout(timeout);\r\n if (response.status >= 200 && response.status < 300) {\r\n return await response.text();\r\n }\r\n\r\n const err = new Error(response.statusText || \"\" + response.status);\r\n throw err;\r\n } catch (err) {\r\n window.clearTimeout(timeout);\r\n throw err;\r\n }\r\n }\r\n}\r\n", "import { Manager } from \"@okikio/manager\";\r\n\r\nexport type ListenerCallback = ((...args: any) => void);\r\nexport interface IListener {\r\n readonly callback: ListenerCallback;\r\n readonly scope: object;\r\n readonly name: string;\r\n}\r\n\r\n/**\r\n * Represents a new event listener consisting of properties like: callback, scope, name\r\n *\r\n * @export\r\n */\r\nexport const newListener = ({\r\n callback = () => { },\r\n scope = null,\r\n name = \"event\",\r\n}: IListener): IListener => ({ callback, scope, name });\r\n\r\n/**\r\n * Represents a new event listener consisting of properties like: callback, scope, name\r\n *\r\n * @export\r\n * @class Event\r\n * @extends {Manager}\r\n */\r\nexport class Event extends Manager {\r\n /**\r\n * The name of the event\r\n *\r\n * @public\r\n * @type string\r\n * @memberof Event\r\n */\r\n public name: string;\r\n\r\n /**\r\n * Creates an instance of Event.\r\n *\r\n * @param {string} [name=\"event\"]\r\n * @memberof Event\r\n */\r\n constructor(name: string = \"event\") {\r\n super();\r\n this.name = name;\r\n }\r\n}\r\n\r\nexport type EventInput = string | object | Array;\r\n\r\n/**\r\n * An event emitter\r\n *\r\n * @export\r\n * @class EventEmitter\r\n * @extends {Manager}\r\n */\r\nexport class EventEmitter extends Manager {\r\n /**\r\n * Creates an instance of EventEmitter.\r\n *\r\n * @memberof EventEmitter\r\n */\r\n constructor() {\r\n super();\r\n }\r\n\r\n /**\r\n * Gets events, if event doesn't exist create a new Event\r\n *\r\n * @param {string} name\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public getEvent(name: string): Event {\r\n let event = this.get(name);\r\n if (!(event instanceof Event)) {\r\n this.set(name, new Event(name));\r\n return this.get(name);\r\n }\r\n\r\n return event;\r\n }\r\n /**\r\n * Creates a new listener and adds it to the event\r\n *\r\n * @param {string} name\r\n * @param {ListenerCallback} callback\r\n * @param {object} scope\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public newListener(\r\n name: string,\r\n callback: ListenerCallback,\r\n scope: object\r\n ): Event {\r\n let event = this.getEvent(name);\r\n event.add(newListener({ name, callback, scope }));\r\n return event;\r\n }\r\n\r\n /**\r\n * Adds a listener for a given event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback | object} callback\r\n * @param {object} scope\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public on(\r\n events: EventInput,\r\n callback?: ListenerCallback | object,\r\n scope?: object\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n let _name: string;\r\n let _callback: ListenerCallback;\r\n let isObject = typeof events == \"object\" && !Array.isArray(events);\r\n\r\n let _scope: object = isObject ? callback : scope;\r\n if (!isObject) _callback = (callback as ListenerCallback);\r\n\r\n // Loop through the list of events\r\n Object.keys(events).forEach(key => {\r\n // Select the name of the event from the list\r\n // Remember events can be {String | Object | Array}\r\n\r\n // Check If events is an Object (JSON like Object, and not an Array)\r\n if (isObject) {\r\n _name = key;\r\n _callback = events[key];\r\n } else {\r\n _name = events[key];\r\n }\r\n\r\n this.newListener(_name, _callback, _scope);\r\n }, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes a listener from an event\r\n *\r\n * @param {string} name\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public removeListener(\r\n name: string,\r\n callback: ListenerCallback,\r\n scope: object\r\n ): Event {\r\n let event: Event = this.get(name);\r\n if (event instanceof Event && callback) {\r\n let listener = newListener({ name, callback, scope });\r\n\r\n event.forEach((value: IListener, i: number) => {\r\n if (\r\n value.callback === listener.callback &&\r\n value.scope === listener.scope\r\n ) {\r\n return event.delete(i);\r\n }\r\n });\r\n }\r\n\r\n return event;\r\n }\r\n\r\n /**\r\n * Removes a listener from a given event, or it just completely removes an event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback | object} [callback]\r\n * @param {object} [scope]\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public off(\r\n events: EventInput,\r\n callback?: ListenerCallback | object,\r\n scope?: object\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n let _name: string;\r\n let _callback: ListenerCallback;\r\n let isObject = typeof events == \"object\" && !Array.isArray(events);\r\n\r\n let _scope: object = isObject ? callback : scope;\r\n if (!isObject) _callback = (callback as ListenerCallback);\r\n\r\n // Loop through the list of events\r\n Object.keys(events).forEach(key => {\r\n // Select the name of the event from the list\r\n // Remember events can be {String | Object | Array}\r\n\r\n // Check If events is an Object (JSON like Object, and not an Array)\r\n if (isObject) {\r\n _name = key;\r\n _callback = events[key];\r\n } else {\r\n _name = events[key];\r\n }\r\n\r\n if (typeof _callback === \"function\") {\r\n this.removeListener(_name, _callback, _scope);\r\n } else this.delete(_name);\r\n }, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Call all listeners within an event\r\n *\r\n * @param {(string | Array)} events\r\n * @param {...any} args\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public emit(\r\n events: string | Array,\r\n ...args: any\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n // Loop through the list of events\r\n events.forEach((event: string) => {\r\n let _event: Event = this.get(event);\r\n\r\n if (_event instanceof Event) {\r\n _event.forEach((listener: IListener) => {\r\n let { callback, scope } = listener;\r\n callback.apply(scope, args);\r\n });\r\n }\r\n }, this);\r\n return this;\r\n }\r\n}\r\n\r\nexport default EventEmitter;\r\n", "import { AdvancedManager, ManagerItem, methodCall } from \"./manager\";\r\nimport { TransitionManager } from \"./transition\";\r\nimport { HistoryManager } from \"./history\";\r\nimport { EventEmitter } from \"./emitter\";\r\nimport { PageManager } from \"./page\";\r\nimport { App } from \"./app\";\r\n\r\n/**\r\n * Controls specific kinds of actions that require JS\r\n *\r\n * @export\r\n * @class Service\r\n */\r\nexport class Service extends ManagerItem {\r\n\t/**\r\n\t * Stores access to the App class's EventEmitter\r\n\t *\r\n\t * @public\r\n\t * @type EventEmitter\r\n\t * @memberof Service\r\n\t */\r\n\tpublic emitter: EventEmitter;\r\n\r\n\t/**\r\n\t * Stores access to the App class's PageManager\r\n\t *\r\n\t * @public\r\n\t * @type PageManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic PageManager: PageManager;\r\n\r\n\t/**\r\n\t * Stores access to the App class's HistoryManager\r\n\t *\r\n\t * @public\r\n\t * @type HistoryManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic HistoryManager: HistoryManager;\r\n\r\n\t/**\r\n\t * Stores the ServiceManager the service is install on\r\n\t *\r\n\t * @public\r\n\t * @type ServiceManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic ServiceManager: ServiceManager;\r\n\r\n\t/**\r\n\t * Stores access to the App's TransitionManager\r\n\t *\r\n\t * @public\r\n\t * @type TransitionManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic TransitionManager: TransitionManager;\r\n\r\n\t/**\r\n\t * Method is run once when Service is installed on a ServiceManager\r\n\t *\r\n\t * @memberof Service\r\n\t */\r\n\tpublic install(): void {\r\n\t\tlet { app } = this.manager;\r\n\t\tthis.PageManager = app.pages;\r\n\t\tthis.HistoryManager = app.history;\r\n\t\tthis.ServiceManager = app.services;\r\n\t\tthis.TransitionManager = app.transitions;\r\n\t}\r\n\r\n\t// Called before the start of a Service, represents a constructor of sorts\r\n\tpublic init(...args: any): void { }\r\n\r\n\t// Called on start of Service\r\n\tpublic boot(): void {\r\n\t\tthis.initEvents();\r\n\t}\r\n\r\n\t// Initialize events\r\n\tpublic initEvents(): void { }\r\n\r\n\t// Stop events\r\n\tpublic stopEvents(): void { }\r\n\r\n\tpublic uninstall() {\r\n\t\tthis.PageManager = undefined;\r\n\t\tthis.HistoryManager = undefined;\r\n\t\tthis.ServiceManager = undefined;\r\n\t\tthis.TransitionManager = undefined;\r\n\t}\r\n\r\n\t// Stop services\r\n\tpublic stop(): void {\r\n\t\tthis.stopEvents();\r\n\t\tthis.unregister();\r\n\t}\r\n}\r\n\r\n/**\r\n * The Service Manager controls the lifecycle of all services in an App\r\n *\r\n * @export\r\n * @class ServiceManager\r\n * @extends {AdvancedManager}\r\n */\r\nexport class ServiceManager extends AdvancedManager {\r\n\t/**\r\n\t * Creates an instance of ServiceManager.\r\n\t *\r\n\t * @param {App} app\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tconstructor(app: App) {\r\n\t\tsuper(app);\r\n\t}\r\n\r\n\t/**\r\n\t * Call the init method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic init(): ServiceManager {\r\n\t\tmethodCall(this, \"init\", this.app);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Call the boot method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic boot(): ServiceManager {\r\n\t\tmethodCall(this, \"boot\", this.app);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Call the stop method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic stop(): ServiceManager {\r\n\t\tmethodCall(this, \"stop\", this.app);\r\n\t\treturn this;\r\n\t}\r\n}\r\n", "import { Manager } from \"./manager\";\r\nimport { EventEmitter } from \"./emitter\";\r\nimport { ICoords, Trigger } from \"./history\";\r\nimport { Page } from \"./page\";\r\nimport { App } from \"./app\";\r\nimport { CONFIG } from \"./config\";\r\n\r\n/**\r\n * The async function type, allows for smooth transition between Promises\r\n */\r\nexport type asyncFn = (err?: any, value?: any) => void;\r\nexport interface ITransition {\r\n oldPage?: Page;\r\n newPage?: Page;\r\n trigger?: Trigger;\r\n scroll?: { x: number; y: number };\r\n scrollable?: boolean;\r\n in: (data: ITransitionData) => any;\r\n out: (data: ITransitionData) => any;\r\n [key: string]: any;\r\n}\r\nexport interface ITransitionData {\r\n from?: Page;\r\n to?: Page;\r\n trigger?: Trigger;\r\n scroll?: ICoords;\r\n done: asyncFn;\r\n}\r\n\r\n/**\r\n * Controls which animation between pages to use\r\n *\r\n * @export\r\n * @class TransitionManager\r\n * @extends {Manager}\r\n */\r\nexport class TransitionManager extends Manager {\r\n /**\r\n * The instance of the App class, the Manager is instantiated in\r\n *\r\n * @type App\r\n * @memberof AdvancedManager\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof AdvancedManager\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * The EventEmitter class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof AdvancedManager\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * Creates an instance of the TransitionManager\r\n *\r\n * @param {App} app\r\n * @memberof TransitionManager\r\n */\r\n constructor(app: App) {\r\n super();\r\n this.app = app;\r\n this.config = app.config;\r\n this.emitter = app.emitter;\r\n }\r\n\r\n /**\r\n * Runs a transition\r\n *\r\n * @param {{ name: string, oldPage: Page, newPage: Page, trigger: Trigger }} data\r\n * @returns Promise\r\n * @memberof TransitionManager\r\n */\r\n public async boot(name: string, data: { oldPage: Page, newPage: Page, trigger: Trigger, scroll: ICoords }): Promise {\r\n let transition: ITransition = this.get(name);\r\n if (!(data.oldPage instanceof Page) || !(data.newPage instanceof Page))\r\n throw `[Page] either oldPage or newPage aren't instances of the Page Class.\\n ${{\r\n newPage: data.newPage,\r\n oldPage: data.oldPage,\r\n }}`;\r\n\r\n let fromWrapper = data.oldPage.wrapper;\r\n let toWrapper = data.newPage.wrapper;\r\n document.title = `` + data.newPage.title;\r\n\r\n if (!(fromWrapper instanceof Node) || !(toWrapper instanceof Node))\r\n throw `[Wrapper] the wrapper from the ${!(toWrapper instanceof Node) ? \"next\" : \"current\"\r\n } page cannot be found. The wrapper must be an element that has the attribute ${this.config.getConfig(\r\n \"wrapperAttr\"\r\n )}.`;\r\n transition.init && transition?.init(data);\r\n\r\n this.emitter.emit(\"BEFORE_TRANSITION_OUT\");\r\n await new Promise((done) => {\r\n let outMethod: Promise = transition.out.call(transition, {\r\n from: data.oldPage,\r\n trigger: data.trigger,\r\n scroll,\r\n done,\r\n });\r\n\r\n if (outMethod.then) outMethod.then(done);\r\n });\r\n\r\n this.emitter.emit(\"AFTER_TRANSITION_OUT\");\r\n await new Promise((done) => {\r\n fromWrapper.insertAdjacentElement(\"beforebegin\", toWrapper);\r\n this.emitter.emit(\"CONTENT_INSERT\");\r\n done();\r\n });\r\n\r\n await new Promise((done) => {\r\n fromWrapper.remove();\r\n fromWrapper = undefined;\r\n toWrapper = undefined;\r\n this.emitter.emit(\"CONTENT_REPLACED\");\r\n done();\r\n });\r\n\r\n this.emitter.emit(\"BEFORE_TRANSITION_IN\");\r\n\r\n await new Promise((done) => {\r\n let inMethod: Promise = transition.in.call(transition, {\r\n from: data.oldPage,\r\n to: data.newPage,\r\n trigger: data.trigger,\r\n scroll,\r\n done,\r\n });\r\n\r\n if (inMethod.then) inMethod.then(done);\r\n });\r\n\r\n this.emitter.emit(\"AFTER_TRANSITION_IN\");\r\n return transition;\r\n }\r\n}\r\n", "import { EventEmitter, ListenerCallback, EventInput } from \"./emitter\";\r\nimport { ITransition, TransitionManager } from \"./transition\";\r\nimport { HistoryManager, IState } from \"./history\";\r\nimport { ServiceManager, Service } from \"./service\";\r\nimport { PageManager } from \"./page\";\r\nimport { CONFIG, ICONFIG } from \"./config\";\r\n\r\n/**\r\n * The App class starts the entire process, it controls all managers and all services\r\n *\r\n * @export\r\n * @class App\r\n */\r\nexport class App {\r\n /**\r\n * A new instance of the HistoryManager\r\n *\r\n * @public\r\n * @type HistoryManager\r\n * @memberof App\r\n */\r\n public history: HistoryManager;\r\n\r\n /**\r\n * A new instance of the TransitionManager\r\n *\r\n * @public\r\n * @type TransitionManager\r\n * @memberof App\r\n */\r\n public transitions: TransitionManager;\r\n\r\n /**\r\n * A new instance of the ServiceManager\r\n *\r\n * @public\r\n * @type ServiceManager\r\n * @memberof App\r\n */\r\n public services: ServiceManager;\r\n\r\n /**\r\n * A new instance of an EventEmitter\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof App\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * A new instance of the PageManager\r\n *\r\n * @public\r\n * @type PageManager\r\n * @memberof App\r\n */\r\n public pages: PageManager;\r\n\r\n /**\r\n * The current Configuration's for the framework\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof App\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * Creates an instance of App.\r\n *\r\n * @param {(ICONFIG | CONFIG)} [config={}]\r\n * @memberof App\r\n */\r\n constructor(config: object = {}) {\r\n this.register(config);\r\n }\r\n\r\n /**\r\n * For registering all managers and the configurations\r\n *\r\n * @param {(ICONFIG | CONFIG)} [config={}]\r\n * @returns App\r\n * @memberof App\r\n */\r\n public register(config: ICONFIG | CONFIG = {}): App {\r\n this.config = config instanceof CONFIG ? config : new CONFIG(config);\r\n this.emitter = new EventEmitter();\r\n this.history = new HistoryManager();\r\n this.pages = new PageManager(this);\r\n this.transitions = new TransitionManager(this);\r\n this.services = new ServiceManager(this);\r\n\r\n let handler = (() => {\r\n document.removeEventListener(\"DOMContentLoaded\", handler);\r\n window.removeEventListener(\"load\", handler);\r\n this.emitter.emit(\"READY ready\");\r\n }).bind(this);\r\n\r\n document.addEventListener(\"DOMContentLoaded\", handler);\r\n window.addEventListener(\"load\", handler);\r\n return this;\r\n }\r\n\r\n /**\r\n * Based on the type, it will return either a Transition, a Service, or a State from their respective Managers\r\n *\r\n * @param {(\"service\" | \"transition\" | \"state\" | string)} type\r\n * @param {any} key\r\n * @returns Service | Transition | State\r\n * @memberof App\r\n */\r\n public get(type: \"service\" | \"transition\" | \"state\" | string, key: any): Service | ITransition | IState {\r\n switch (type.toLowerCase()) {\r\n case \"service\":\r\n return this.services.get(key);\r\n case \"transition\":\r\n return this.transitions.get(key);\r\n case \"state\":\r\n return this.history.get(key);\r\n default:\r\n throw `Error: can't get type '${type}', it is not a recognized type. Did you spell it correctly.`;\r\n }\r\n }\r\n\r\n /**\r\n * Based on the type, it will return load either Page a Transition, a Service, a State, or a Page from their respective Managers\r\n *\r\n * @param {(\"page\" | string)} type\r\n * @param {any} key\r\n * @returns App\r\n * @memberof App\r\n */\r\n public async load(type: \"page\" | string, key: any): Promise {\r\n switch (type.toLowerCase()) {\r\n case \"page\":\r\n return await this.pages.load(key);\r\n default:\r\n return Promise.resolve(this.get(type, key));\r\n }\r\n }\r\n\r\n /**\r\n * Adds a Service to the App's instance of the ServiceManager, with a name\r\n *\r\n * @param {string} key\r\n * @param {Service} service\r\n * @returns App\r\n * @memberof App\r\n */\r\n public setService(key: string, service: Service): App {\r\n this.services.set(key, service);\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a Service to the App's instance of the ServiceManager, with a name\r\n *\r\n * @param {string} key\r\n * @param {ITransition} tranisition\r\n * @returns App\r\n * @memberof App\r\n */\r\n public setTransition(key: string, transition: ITransition): App {\r\n this.transitions.set(key, transition);\r\n return this;\r\n }\r\n\r\n /**\r\n * Based on the type, it will add either a Transition, a Service, or a State to their respective Managers\r\n *\r\n * @param {(\"service\" | \"transition\" | \"state\")} type\r\n * @param {any} value\r\n * @returns App\r\n * @memberof App\r\n */\r\n public add(type: \"service\" | \"transition\" | \"state\", value: any): App {\r\n switch (type.toLowerCase()) {\r\n case \"service\":\r\n this.services.add(value);\r\n break;\r\n case \"transition\":\r\n this.transitions.set(value.name, value);\r\n break;\r\n case \"state\":\r\n this.history.add(value);\r\n break;\r\n default:\r\n throw `Error: can't add type '${type}', it is not a recognized type. Did you spell it correctly.`;\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Start the App and the ServiceManager\r\n *\r\n * @returns App\r\n * @memberof App\r\n */\r\n public boot(): App {\r\n this.services.init();\r\n this.services.boot();\r\n return this;\r\n }\r\n\r\n /**\r\n * Stop the App and the ServiceManager\r\n *\r\n * @returns App\r\n * @memberof App\r\n */\r\n public stop(): App {\r\n this.services.stop();\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter on method\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} callback\r\n * @returns App\r\n * @memberof App\r\n */\r\n public on(events: EventInput, callback?: ListenerCallback): App {\r\n this.emitter.on(events, callback, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter off method\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} callback\r\n * @returns App\r\n * @memberof App\r\n */\r\n public off(events: EventInput, callback?: ListenerCallback): App {\r\n this.emitter.off(events, callback, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter emit method\r\n *\r\n * @param {(string | any[])} events\r\n * @param {...any} args\r\n * @returns App\r\n * @memberof App\r\n */\r\n public emit(events: string | any[], ...args: any): App {\r\n this.emitter.emit(events, ...args);\r\n return this;\r\n }\r\n}\r\n", "import { newState, Trigger, IState, newCoords, IHistoryItem } from \"./history\";\r\nimport { Service } from \"./service\";\r\nimport { Page } from \"./page\";\r\nimport { newURL, getHashedPath, equal } from \"./url\";\r\n\r\nexport type LinkEvent = MouseEvent | TouchEvent;\r\nexport type StateEvent = LinkEvent | PopStateEvent;\r\nexport type IgnoreURLsList = Array;\r\n\r\n/**\r\n * Creates a Barba JS like PJAX Service, for the Framework\r\n *\r\n * @export\r\n * @class PJAX\r\n * @extends {Service}\r\n */\r\n// Based on Barba JS and StartingBlocks\r\nexport class PJAX extends Service {\r\n /**\r\n * URLs to ignore when prefetching\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected ignoreURLs: IgnoreURLsList = [];\r\n\r\n /**\r\n * Whether or not to disable prefetching\r\n *\r\n * @private\r\n *\r\n * @memberof PJAX\r\n */\r\n protected prefetchIgnore: boolean = false;\r\n\r\n /**\r\n * Current state or transitions\r\n *\r\n * @public\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n public isTransitioning: boolean = false;\r\n\r\n /**\r\n * Ignore extra clicks of an anchor element if a transition has already started\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected stopOnTransitioning: boolean = false;\r\n\r\n /**\r\n * On page change (excluding popstate event) keep current scroll position\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected stickyScroll: boolean = false;\r\n\r\n /**\r\n * Force load a page if an error occurs\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected forceOnError: boolean = false;\r\n\r\n /**\r\n * Dictates whether to auto scroll if an hash is present in the window URL\r\n *\r\n * @protected\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected autoScrollOnHash: boolean = true;\r\n\r\n /**\r\n * Disables all extra scroll effects of PJAX, however, it won't affect scroll on hash,\r\n * since scrolling when an hash is in the URL is the default behavior\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected dontScroll: boolean = true;\r\n\r\n /**\r\n * Sets the transition state, sets isTransitioning to true\r\n *\r\n * @private\r\n * @memberof PJAX\r\n */\r\n private transitionStart() {\r\n this.isTransitioning = true;\r\n }\r\n\r\n /**\r\n * Sets the transition state, sets isTransitioning to false\r\n *\r\n * @private\r\n * @memberof PJAX\r\n */\r\n private transitionStop() {\r\n this.isTransitioning = false;\r\n }\r\n\r\n public init() {\r\n super.init();\r\n\r\n /**\r\n * Bind the event listeners to the PJAX class\r\n *\r\n * @memberof PJAX\r\n */\r\n this.onHover = this.onHover.bind(this);\r\n this.onClick = this.onClick.bind(this);\r\n this.onStateChange = this.onStateChange.bind(this);\r\n }\r\n\r\n /**\r\n * Starts the PJAX Service\r\n *\r\n * @memberof PJAX\r\n */\r\n public boot() {\r\n if (\"scrollRestoration\" in window.history) {\r\n // Back off, browser, I got this...\r\n window.history.scrollRestoration = \"manual\";\r\n }\r\n\r\n super.boot();\r\n }\r\n\r\n /**\r\n * Gets the transition to use for a certain anchor\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @returns {(string | null)}\r\n * @memberof PJAX\r\n */\r\n public getTransitionName(el: HTMLAnchorElement): string | null {\r\n if (!el || !el.getAttribute) return null;\r\n let transitionAttr = el.getAttribute(\r\n this.config.getConfig(\"transitionAttr\", false)\r\n );\r\n if (typeof transitionAttr === \"string\") return transitionAttr;\r\n return null;\r\n }\r\n\r\n /**\r\n * Checks to see if the anchor is valid\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @param {(LinkEvent | KeyboardEvent)} event\r\n * @param {string} href\r\n *\r\n * @memberof PJAX\r\n */\r\n public validLink(\r\n el: HTMLAnchorElement,\r\n event: LinkEvent | KeyboardEvent,\r\n href: string\r\n ): boolean {\r\n let pushStateSupport = !window.history.pushState;\r\n let exists = !el || !href;\r\n let eventMutate =\r\n (event as KeyboardEvent).metaKey ||\r\n (event as KeyboardEvent).ctrlKey ||\r\n (event as KeyboardEvent).shiftKey ||\r\n (event as KeyboardEvent).altKey;\r\n let newTab =\r\n el.hasAttribute(\"target\") &&\r\n (el as HTMLAnchorElement).target === \"_blank\";\r\n let crossOrigin =\r\n (el as HTMLAnchorElement).protocol !== location.protocol ||\r\n (el as HTMLAnchorElement).hostname !== location.hostname;\r\n let download = typeof el.getAttribute(\"download\") === \"string\";\r\n let preventSelf = el.hasAttribute(this.config.getConfig(\"preventSelfAttr\", false));\r\n let preventAll = Boolean(\r\n el.closest(this.config.getConfig(\"preventAllAttr\"))\r\n );\r\n let prevent = preventSelf && preventAll;\r\n let sameURL = getHashedPath(newURL()) === getHashedPath(newURL(href));\r\n return !(\r\n exists ||\r\n pushStateSupport ||\r\n eventMutate ||\r\n newTab ||\r\n crossOrigin ||\r\n download ||\r\n prevent ||\r\n sameURL\r\n );\r\n }\r\n\r\n /**\r\n * Returns the href or an Anchor element\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @returns {(string | null)}\r\n * @memberof PJAX\r\n */\r\n public getHref(el: HTMLAnchorElement): string | null {\r\n if (\r\n el &&\r\n el.tagName &&\r\n el.tagName.toLowerCase() === \"a\" &&\r\n typeof el.href === \"string\"\r\n )\r\n return el.href;\r\n return null;\r\n }\r\n\r\n /**\r\n * Check if event target is a valid anchor with an href, if so, return the link\r\n *\r\n * @param {LinkEvent} event\r\n *\r\n * @memberof PJAX\r\n */\r\n public getLink(event: LinkEvent): HTMLAnchorElement {\r\n let el = event.target as HTMLAnchorElement;\r\n let href: string = this.getHref(el);\r\n\r\n while (el && !href) {\r\n el = (el as HTMLElement).parentNode as HTMLAnchorElement;\r\n href = this.getHref(el);\r\n }\r\n\r\n // Check for a valid link\r\n if (!el || !this.validLink(el, event, href)) return;\r\n return el;\r\n }\r\n\r\n /**\r\n * When an element is clicked.\r\n *\r\n * Get valid anchor element.\r\n * Go for a transition.\r\n *\r\n * @param {LinkEvent} event\r\n * @returns\r\n * @memberof PJAX\r\n */\r\n public onClick(event: LinkEvent) {\r\n let el = this.getLink(event);\r\n if (!el) return;\r\n\r\n if (this.isTransitioning && this.stopOnTransitioning) {\r\n event.preventDefault();\r\n event.stopPropagation();\r\n return;\r\n }\r\n\r\n let href = this.getHref(el);\r\n this.emitter.emit(\"ANCHOR_CLICK CLICK\", event);\r\n this.go({ href, trigger: el, event });\r\n }\r\n\r\n /**\r\n * Returns the direction of the State change as a String, either the Back button or the Forward button\r\n *\r\n * @param {number} value\r\n *\r\n * @memberof PJAX\r\n */\r\n public getDirection(value: number): Trigger {\r\n if (Math.abs(value) > 1) {\r\n // Ex 6-0 > 0 -> forward, 0-6 < 0 -> back\r\n return value > 0 ? \"forward\" : \"back\";\r\n } else {\r\n if (value === 0) {\r\n return \"popstate\";\r\n } else {\r\n // Ex 6-5 > 0 -> back, 5-6 < 0 -> forward\r\n return value > 0 ? \"back\" : \"forward\";\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Force a page to go to a certain URL\r\n *\r\n * @param {string} href\r\n * @memberof PJAX\r\n */\r\n public force(href: string): void {\r\n window.location.assign(href);\r\n }\r\n\r\n /**\r\n * If transition is running force load page.\r\n * Stop if currentURL is the same as new url.\r\n * On state change, change the current state history,\r\n * to reflect the direction of said state change\r\n * Load page and page transition.\r\n *\r\n * @param {string} href\r\n * @param {Trigger} [trigger='HistoryManager']\r\n * @param {StateEvent} [event]\r\n * @memberof PJAX\r\n */\r\n public go({\r\n href,\r\n trigger = \"HistoryManager\",\r\n event,\r\n }: {\r\n href: string;\r\n trigger?: Trigger;\r\n event?: StateEvent;\r\n }): Promise {\r\n // If transition is already running and the go method is called again, force load page\r\n if (this.isTransitioning && this.stopOnTransitioning) {\r\n this.force(href);\r\n return;\r\n }\r\n\r\n let scroll = { x: 0, y: 0 };\r\n let currentState = this.HistoryManager.current;\r\n let currentURL = currentState.url;\r\n if (equal(currentURL, href)) {\r\n return;\r\n }\r\n\r\n let transitionName: string;\r\n if (event && (event as PopStateEvent).state) {\r\n this.emitter.emit(\"POPSTATE\", event);\r\n\r\n // If popstate, get back/forward direction.\r\n let { state }: { state: IHistoryItem } = event as PopStateEvent;\r\n let { index } = state;\r\n let currentIndex = currentState.index;\r\n let difference = currentIndex - index;\r\n\r\n trigger = this.getDirection(difference);\r\n\r\n // Based on the direction of the state change either remove or add a state\r\n this.HistoryManager.replace(state.states);\r\n this.HistoryManager.pointer = index;\r\n if (trigger === \"back\") {\r\n // this.HistoryManager.remove(currentIndex);\r\n this.emitter.emit(`POPSTATE_BACK`, event);\r\n } else if (trigger === \"forward\") {\r\n // this.HistoryManager.add({ url: href, transition, data });\r\n this.emitter.emit(`POPSTATE_FORWARD`, event);\r\n }\r\n\r\n let _state = this.HistoryManager.get(index);\r\n transitionName = _state.transition;\r\n\r\n // If the page remains on the same history state DO NOT scroll, it's pointless\r\n if (trigger !== \"popstate\") {\r\n // Keep scroll position\r\n scroll = _state.data.scroll;\r\n }\r\n } else {\r\n // Add new state\r\n transitionName = this.getTransitionName(trigger as HTMLAnchorElement) ||\r\n \"default\";\r\n let scrollCoords = newCoords();\r\n\r\n if (!this.dontScroll && this.stickyScroll) {\r\n // Keep scroll position\r\n let { x, y } = scrollCoords;\r\n scroll = { x, y };\r\n } else {\r\n scroll = {\r\n x: 0,\r\n y: 0\r\n };\r\n }\r\n\r\n let state = newState({\r\n url: href,\r\n transition: transitionName,\r\n data: { scroll: scrollCoords },\r\n });\r\n\r\n this.HistoryManager.add(state);\r\n this.emitter.emit(\"HISTORY_NEW_ITEM\", event);\r\n }\r\n\r\n if (event) {\r\n event.stopPropagation();\r\n event.preventDefault();\r\n }\r\n\r\n this.emitter.emit(\"GO\", event);\r\n return this.load({\r\n oldHref: currentURL,\r\n href,\r\n trigger,\r\n transitionName,\r\n scroll,\r\n });\r\n }\r\n\r\n /**\r\n * Load the new Page as well as a Transition; run the Transition\r\n *\r\n * @param {string} oldHref\r\n * @param {string} href\r\n * @param {Trigger} trigger\r\n * @param {string} [transitionName=\"default\"]\r\n *\r\n * @memberof PJAX\r\n */\r\n public async load({\r\n oldHref,\r\n href,\r\n trigger,\r\n transitionName = \"default\",\r\n scroll = { x: 0, y: 0 },\r\n }: {\r\n oldHref: string;\r\n href: string;\r\n trigger: Trigger;\r\n transitionName?: string;\r\n scroll: { x: number; y: number };\r\n }): Promise {\r\n try {\r\n let oldPage = await this.PageManager.load(oldHref);\r\n await oldPage.build();\r\n let newPage: Page;\r\n\r\n this.emitter.emit(\"PAGE_LOADING\", { href, oldPage, trigger });\r\n try {\r\n try {\r\n newPage = await this.PageManager.load(href);\r\n await newPage.build();\r\n this.transitionStart();\r\n this.emitter.emit(\"PAGE_LOAD_COMPLETE\", {\r\n newPage,\r\n oldPage,\r\n trigger,\r\n });\r\n } catch (err) {\r\n console.error(`[PJAX] page load error: ${err}`);\r\n }\r\n\r\n // --\r\n // --\r\n\r\n this.emitter.emit(\"NAVIGATION_START\", {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n transitionName,\r\n });\r\n\r\n try {\r\n this.emitter.emit(\"TRANSITION_START\", transitionName);\r\n let transition = await this.TransitionManager.boot(transitionName, {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n scroll,\r\n });\r\n\r\n if (!transition.scrollable) {\r\n if (!/back|popstate|forward/.test(trigger as string)) scroll = hashAction(href);\r\n window.scroll(scroll.x, scroll.y);\r\n }\r\n\r\n this.emitter.emit(\"TRANSITION_END\", { transition });\r\n\r\n } catch (err) {\r\n console.error(`[PJAX] transition error: ${err}`);\r\n }\r\n\r\n this.emitter.emit(\"NAVIGATION_END\", {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n transitionName,\r\n });\r\n } catch (err) {\r\n this.transitionStop();\r\n throw err;\r\n }\r\n\r\n this.transitionStop(); // Sets isTransitioning to false\r\n } catch (err) {\r\n if (this.forceOnError) this.force(href);\r\n else console.error(err);\r\n }\r\n }\r\n\r\n /**\r\n * Check to see if the URL is to be ignored, uses either RegExp of Strings to check\r\n *\r\n * @param {URL} { pathname }\r\n *\r\n * @memberof PJAX\r\n */\r\n public ignoredURL({ pathname }: URL): boolean {\r\n return (\r\n this.ignoreURLs.length &&\r\n this.ignoreURLs.some((url) => {\r\n return typeof url === \"string\"\r\n ? url === pathname\r\n : (url as RegExp).exec(pathname) !== null;\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * When you hover over an anchor, prefetch the event target's href\r\n *\r\n * @param {LinkEvent} event\r\n * @memberof PJAX\r\n */\r\n public onHover(event: LinkEvent): Promise {\r\n let el = this.getLink(event);\r\n if (!el) return;\r\n\r\n let url = newURL(this.getHref(el));\r\n let urlString: string = url.pathname;\r\n // If Url is ignored or already in cache, don't do any think\r\n if (this.ignoredURL(url) || this.PageManager.has(urlString)) return;\r\n this.emitter.emit(\"ANCHOR_HOVER HOVER\", event);\r\n\r\n try {\r\n this.PageManager.load(url);\r\n } catch (err) {\r\n console.warn(\"[PJAX] prefetch error,\", err);\r\n }\r\n }\r\n\r\n /**\r\n * When History state changes.\r\n *\r\n * Get url from State\r\n * Go for a Barba transition.\r\n *\r\n * @param {PopStateEvent} event\r\n * @memberof PJAX\r\n */\r\n public onStateChange(event: PopStateEvent): void {\r\n this.go({ href: window.location.href, trigger: \"popstate\", event });\r\n }\r\n\r\n /**\r\n * Initialize DOM Events\r\n *\r\n * @memberof PJAX\r\n */\r\n public initEvents() {\r\n if (this.prefetchIgnore !== true) {\r\n document.addEventListener(\"mouseover\", this.onHover);\r\n document.addEventListener(\"touchstart\", this.onHover);\r\n }\r\n\r\n document.addEventListener(\"click\", this.onClick);\r\n window.addEventListener(\"popstate\", this.onStateChange);\r\n }\r\n\r\n /**\r\n * Stop DOM Events\r\n *\r\n * @memberof PJAX\r\n */\r\n public stopEvents() {\r\n if (this.prefetchIgnore !== true) {\r\n document.removeEventListener(\"mouseover\", this.onHover);\r\n document.removeEventListener(\"touchstart\", this.onHover);\r\n }\r\n\r\n document.removeEventListener(\"click\", this.onClick);\r\n window.removeEventListener(\"popstate\", this.onStateChange);\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Auto scrolls to an elements position if the element has an hash\r\n *\r\n * @param {string} [hash=window.location.hash]\r\n * @memberof PJAX\r\n */\r\nexport const hashAction = (hash: string = window.location.hash) => {\r\n try {\r\n let _hash = hash[0] == \"#\" ? hash : newURL(hash).hash;\r\n if (_hash.length > 1) {\r\n let el = document.querySelector(_hash) as HTMLElement;\r\n\r\n if (el) {\r\n return { x: el.offsetLeft, y: el.offsetTop };\r\n }\r\n }\r\n } catch (e) {\r\n console.warn(\"hashAction error\", e);\r\n }\r\n\r\n return { x: 0, y: 0 };\r\n};\r\n", "import { Service } from \"./service\";\r\nimport { Manager } from \"./manager\";\r\nimport { newURL, getHashedPath } from \"./url\";\r\n\r\nexport type RouteMethod = (...args: any) => any;\r\nexport type RouteStyle = string | RegExp | boolean;\r\nexport interface IRouteToFrom {\r\n to: RouteStyle,\r\n from: RouteStyle\r\n}\r\nexport type RoutePath = IRouteToFrom | RouteStyle;\r\nexport interface IRoute {\r\n path: RoutePath,\r\n method: RouteMethod\r\n}\r\n\r\n/**\r\n * Controls what happens when certain url paths match a set of criteria\r\n *\r\n * @export\r\n * @class Router\r\n * @extends {Service}\r\n */\r\nexport class Router extends Service {\r\n /**\r\n * List of routes inputted\r\n *\r\n * @protected\r\n * @type {Manager}\r\n * @memberof Router\r\n */\r\n protected routes: Manager;\r\n\r\n /**\r\n * Creates an instance of Router.\r\n *\r\n * @param {Array} [routes=[]]\r\n * @memberof Router\r\n */\r\n constructor(routes: IRoute[] = []) {\r\n super();\r\n this.routes = new Manager();\r\n for (let route of routes) {\r\n this.add(route);\r\n }\r\n }\r\n\r\n /**\r\n * Add a new route to watch for\r\n *\r\n * @param {IRoute} { path, method }\r\n * @returns {Router}\r\n * @memberof Router\r\n */\r\n public add({ path, method }: IRoute): Router {\r\n let key = this.parse(path);\r\n this.routes.set(key, method);\r\n return this;\r\n }\r\n\r\n /**\r\n * Convert strings into path match functions\r\n *\r\n * @param {RouteStyle} path\r\n * @returns {RegExp | boolean}\r\n * @memberof Router\r\n */\r\n public parsePath(path: RouteStyle): RegExp | boolean {\r\n if (typeof path === \"string\") return new RegExp(path, \"i\");\r\n else if (path instanceof RegExp || typeof path === \"boolean\")\r\n return path;\r\n throw \"[Router] only regular expressions, strings and booleans are accepted as paths.\";\r\n }\r\n\r\n /**\r\n * Determines if a strings counts has a path\r\n *\r\n * @param {RouteStyle} input\r\n * @returns boolean\r\n * @memberof Router\r\n */\r\n public isPath(input: RouteStyle): boolean {\r\n return (\r\n typeof input === \"string\" ||\r\n input instanceof RegExp ||\r\n typeof input === \"boolean\"\r\n );\r\n }\r\n\r\n /**\r\n * Parse the multiple different formats for paths, into a { from, to } object\r\n *\r\n * @param {RouteStyle} input\r\n * @returns {IRouteToFrom}\r\n * @memberof Router\r\n */\r\n public parse(input: RoutePath): IRouteToFrom {\r\n let route = input as IRouteToFrom;\r\n let toFromPath: IRouteToFrom = {\r\n from: /(.*)/g,\r\n to: /(.*)/g,\r\n };\r\n\r\n if (this.isPath(input as RouteStyle))\r\n toFromPath = {\r\n from: true,\r\n to: input as RouteStyle,\r\n };\r\n else if (this.isPath(route.from) && this.isPath(route.to as RouteStyle))\r\n toFromPath = route;\r\n else\r\n throw \"[Router] path is neither a string, regular expression, or a { from, to } object.\";\r\n\r\n let { from, to } = toFromPath;\r\n return {\r\n from: this.parsePath(from),\r\n to: this.parsePath(to),\r\n };\r\n }\r\n\r\n /**\r\n * Test if route paths are true, if so run their methods\r\n *\r\n * @memberof Router\r\n */\r\n public route() {\r\n let history = this.HistoryManager;\r\n let from: string = getHashedPath(newURL((history.length > 1 ? history.previous : history.current).url));\r\n let to: string = getHashedPath(newURL());\r\n\r\n this.routes.forEach((method: RouteMethod, path: IRouteToFrom) => {\r\n let fromRegExp = path.from as RegExp | boolean;\r\n let toRegExp = path.to as RegExp | boolean;\r\n\r\n if (\r\n typeof fromRegExp === \"boolean\" &&\r\n typeof toRegExp === \"boolean\"\r\n ) {\r\n throw `[Router] path ({ from: ${fromRegExp}, to: ${toRegExp} }) is not valid, remember paths can only be strings, regular expressions, or a boolean; however, both the from and to paths cannot be both booleans.`;\r\n }\r\n\r\n let fromParam: RegExpExecArray | RegExp | boolean = fromRegExp;\r\n let toParam: RegExpExecArray | RegExp | boolean = toRegExp;\r\n\r\n if (fromRegExp instanceof RegExp && fromRegExp.test(from))\r\n fromParam = fromRegExp.exec(from);\r\n if (toRegExp instanceof RegExp && toRegExp.test(to))\r\n toParam = toRegExp.exec(to);\r\n\r\n if (\r\n (Array.isArray(toParam) && Array.isArray(fromParam)) ||\r\n (Array.isArray(toParam) &&\r\n typeof fromParam == \"boolean\" &&\r\n fromParam) ||\r\n (Array.isArray(fromParam) &&\r\n typeof toParam == \"boolean\" &&\r\n toParam)\r\n )\r\n method({ from: fromParam, to: toParam, path: { from, to } });\r\n });\r\n }\r\n\r\n /**\r\n * Add listeners for PJAX Events\r\n *\r\n * @memberof Router\r\n */\r\n public initEvents() {\r\n this.emitter.on(\"READY\", this.route, this);\r\n this.emitter.on(\"CONTENT_REPLACED\", this.route, this);\r\n }\r\n\r\n /**\r\n * Remove listeners for PJAX Events\r\n *\r\n * @memberof Router\r\n */\r\n public stopEvents() {\r\n this.emitter.off(\"READY\", this.route, this);\r\n this.emitter.off(\"CONTENT_REPLACED\", this.route, this);\r\n }\r\n}\r\n", "import { EventEmitter, EventInput, ListenerCallback } from \"@okikio/emitter\";\r\n\r\n// DOM\r\nexport type AnimationTarget = string | Node | NodeList | HTMLCollection | HTMLElement[] | any[];\r\nexport const getElements = (selector: string | Node): Node[] => {\r\n return typeof selector === \"string\" ? Array.from(document.querySelectorAll(selector as string)) : [selector];\r\n};\r\n\r\nexport const getTargets = (targets: AnimationTarget): Node[] => {\r\n if (Array.isArray(targets)) return targets;\r\n if (typeof targets == \"string\" || targets instanceof Node)\r\n return getElements(targets);\r\n if (targets instanceof NodeList || targets instanceof HTMLCollection)\r\n return Array.from(targets);\r\n return [];\r\n};\r\n\r\n// VALUES\r\nexport type closureArgs = [number, number, HTMLElement];\r\nexport type closure = ((index?: number, total?: number, element?: HTMLElement) => any) | any;\r\nexport const computeValue = (value: closure, args: closureArgs) => {\r\n if (typeof value === \"function\") {\r\n return value(...args);\r\n } else { return value; }\r\n};\r\n\r\nexport const mapObject = (obj: object, args: closureArgs): any => {\r\n let key, value, result = {};\r\n let keys = Object.keys(obj);\r\n for (let i = 0, len = keys.length; i < len; i++) {\r\n key = keys[i];\r\n value = obj[key];\r\n result[key] = computeValue(value, args);\r\n }\r\n\r\n return result;\r\n};\r\n\r\n// From: [https://easings.net]\r\nexport const easings = {\r\n \"ease\": \"ease\",\r\n \"in\": \"ease-in\",\r\n \"out\": \"ease-out\",\r\n \"in-out\": \"ease-in-out\",\r\n\r\n // Sine\r\n \"in-sine\": \"cubic-bezier(0.47, 0, 0.745, 0.715)\",\r\n \"out-sine\": \"cubic-bezier(0.39, 0.575, 0.565, 1)\",\r\n \"in-out-sine\": \"cubic-bezier(0.445, 0.05, 0.55, 0.95)\",\r\n\r\n // Quad\r\n \"in-quad\": \"cubic-bezier(0.55, 0.085, 0.68, 0.53)\",\r\n \"out-quad\": \"cubic-bezier(0.25, 0.46, 0.45, 0.94)\",\r\n \"in-out-quad\": \"cubic-bezier(0.455, 0.03, 0.515, 0.955)\",\r\n\r\n // Cubic\r\n \"in-cubic\": \"cubic-bezier(0.55, 0.055, 0.675, 0.19)\",\r\n \"out-cubic\": \"cubic-bezier(0.215, 0.61, 0.355, 1)\",\r\n \"in-out-cubic\": \"cubic-bezier(0.645, 0.045, 0.355, 1)\",\r\n\r\n // Quart\r\n \"in-quart\": \"cubic-bezier(0.895, 0.03, 0.685, 0.22)\",\r\n \"out-quart\": \"cubic-bezier(0.165, 0.84, 0.44, 1)\",\r\n \"in-out-quart\": \"cubic-bezier(0.77, 0, 0.175, 1)\",\r\n\r\n // Quint\r\n \"in-quint\": \"cubic-bezier(0.755, 0.05, 0.855, 0.06)\",\r\n \"out-quint\": \"cubic-bezier(0.23, 1, 0.32, 1)\",\r\n \"in-out-quint\": \"cubic-bezier(0.86, 0, 0.07, 1)\",\r\n\r\n // Expo\r\n \"in-expo\": \"cubic-bezier(0.95, 0.05, 0.795, 0.035)\",\r\n \"out-expo\": \"cubic-bezier(0.19, 1, 0.22, 1)\",\r\n \"in-out-expo\": \"cubic-bezier(1, 0, 0, 1)\",\r\n\r\n // Circ\r\n \"in-circ\": \"cubic-bezier(0.6, 0.04, 0.98, 0.335)\",\r\n \"out-circ\": \"cubic-bezier(0.075, 0.82, 0.165, 1)\",\r\n \"in-out-circ\": \"cubic-bezier(0.785, 0.135, 0.15, 0.86)\",\r\n\r\n // Back\r\n \"in-back\": \"cubic-bezier(0.6, -0.28, 0.735, 0.045)\",\r\n \"out-back\": \"cubic-bezier(0.175, 0.885, 0.32, 1.275)\",\r\n \"in-out-back\": \"cubic-bezier(0.68, -0.55, 0.265, 1.55)\"\r\n};\r\nexport const getEase = (ease: string) => {\r\n return /^(ease|in|out)/.test(ease) ? easings[ease] : ease;\r\n};\r\n\r\nexport interface AnimationOptions {\r\n target?: AnimationTarget,\r\n\r\n speed?: number | closure,\r\n delay?: number | closure,\r\n easing?: string | closure,\r\n endDelay?: number | closure,\r\n duration?: number | closure,\r\n autoplay?: boolean | closure,\r\n keyframes?: object[] | closure,\r\n loop?: number | boolean | closure, // iterations: number,\r\n options?: AnimationOptions | closure,\r\n onfinish?: (element?: HTMLElement, index?: number, total?: number) => any,\r\n fillMode?: \"none\" | \"forwards\" | \"backwards\" | \"both\" | \"auto\" | closure,\r\n direction?: \"normal\" | \"reverse\" | \"alternate\" | \"alternate-reverse\" | closure,\r\n [property: string]: closure | boolean | object | string | string[] | number | null | (number | null)[] | undefined;\r\n};\r\n\r\nexport const DefaultAnimationOptions: AnimationOptions = {\r\n keyframes: [],\r\n\r\n loop: 1, // iterations: number,\r\n delay: 0,\r\n speed: 1,\r\n endDelay: 0,\r\n easing: \"ease\",\r\n autoplay: true,\r\n duration: 1000,\r\n onfinish() { },\r\n fillMode: \"auto\",\r\n direction: \"normal\",\r\n};\r\n\r\n// You can check it out here: https://codepen.io/okikio/pen/qBbdGaW?editors=0011\r\nexport class Animate {\r\n /**\r\n * Stores the options for the current animation\r\n *\r\n * @public\r\n * @type AnimationOptions\r\n * @memberof Animate\r\n */\r\n public options: AnimationOptions = {};\r\n\r\n /**\r\n * The Array of Elements to Animate\r\n *\r\n * @public\r\n * @type {Node[]}\r\n * @memberof Animate\r\n */\r\n public targets: Node[] = [];\r\n\r\n /**\r\n * The properties to animate\r\n *\r\n * @public\r\n * @type {object}\r\n * @memberof Animate\r\n */\r\n public properties: object = {};\r\n\r\n /**\r\n * A Set of Animations\r\n *\r\n * @public\r\n * @type {Map}\r\n * @memberof Animate\r\n */\r\n public animations: Map = new Map();\r\n\r\n /**\r\n * The total duration of all Animation's\r\n *\r\n * @public\r\n * @type {number}\r\n * @memberof Animate\r\n */\r\n public duration: number = 0;\r\n\r\n /**\r\n * The Element the main animation uses\r\n *\r\n * @public\r\n * @type {HTMLElement}\r\n * @memberof Animate\r\n */\r\n public mainElement: HTMLElement;\r\n\r\n /**\r\n * Stores an animation that runs on the total duration of the all other Animations, and as such it's the main Animation\r\n *\r\n * @public\r\n * @type {Animation}\r\n * @memberof Animate\r\n */\r\n public mainAnimation: Animation;\r\n\r\n /**\r\n * Stores request frame calls\r\n *\r\n * @public\r\n * @type {number}\r\n * @memberof Animate\r\n */\r\n public animationFrame: number;\r\n\r\n /**\r\n * An event emitter\r\n *\r\n * @public\r\n * @type {EventEmitter}\r\n * @memberof Animate\r\n */\r\n public emitter: EventEmitter = new EventEmitter();\r\n\r\n /**\r\n * The finish method, is called when the main animation has finished\r\n *\r\n * @public\r\n * @type {*}\r\n * @memberof Animate\r\n */\r\n public finish: any;\r\n\r\n /**\r\n * Returns a promise that is fulfilled when the mainAnimation is finished\r\n *\r\n * @public\r\n * @type {Promise}\r\n * @memberof Animate\r\n */\r\n public promise: Promise;\r\n\r\n /**\r\n * Creates an instance of Animate.\r\n *\r\n * @param {AnimationOptions} options\r\n * @memberof Animate\r\n */\r\n constructor(options: AnimationOptions = {}) {\r\n let { options: animation, ...rest } = options;\r\n this.options = Object.assign({}, DefaultAnimationOptions, animation, rest);\r\n this.loop = this.loop.bind(this);\r\n\r\n let {\r\n loop,\r\n delay,\r\n speed,\r\n easing,\r\n endDelay,\r\n duration,\r\n direction,\r\n fillMode,\r\n onfinish,\r\n target,\r\n keyframes,\r\n autoplay,\r\n ...properties\r\n } = this.options;\r\n\r\n this.mainElement = document.createElement(\"span\");\r\n this.targets = getTargets(target);\r\n this.properties = properties;\r\n\r\n let animationKeyframe: Keyframe[] | PropertyIndexedKeyframes;\r\n for (let i = 0, len = this.targets.length; i < len; i++) {\r\n let target = this.targets[i] as HTMLElement;\r\n let animationOptions = {\r\n easing: getEase(easing),\r\n iterations: loop === true ? Infinity : (loop as number),\r\n direction,\r\n endDelay,\r\n duration,\r\n delay,\r\n fill: fillMode,\r\n };\r\n\r\n // Accept keyframes as a keyframes Object, or a method,\r\n // if there are no animations in the keyframes array,\r\n // uses css properties from the options object\r\n let arrKeyframes = computeValue((keyframes as Keyframe[]), [i, len, target]);\r\n animationKeyframe = arrKeyframes.length ? arrKeyframes :\r\n (this.properties as PropertyIndexedKeyframes);\r\n\r\n // Allows the use of functions as the values, for both the keyframes and the animation object\r\n // It adds the capability of advanced stagger animation, similar to the anime js stagger functions\r\n animationOptions = mapObject(animationOptions, [i, len, target]);\r\n if (!(arrKeyframes.length > 0))\r\n animationKeyframe = mapObject(animationKeyframe, [i, len, target]);\r\n\r\n // Set the Animate classes duration to be the Animation with the largest totalDuration\r\n let tempDuration: number =\r\n animationOptions.delay +\r\n (animationOptions.duration * animationOptions.iterations) +\r\n animationOptions.endDelay;\r\n if (this.duration < tempDuration) this.duration = tempDuration;\r\n\r\n // Add animation to the Animations Set\r\n let animation = target.animate(animationKeyframe, animationOptions);\r\n animation.onfinish = () => {\r\n onfinish(target, i, len);\r\n };\r\n this.animations.set(target, animation);\r\n }\r\n\r\n this.mainAnimation = this.mainElement.animate([\r\n { opacity: \"0\" },\r\n { opacity: \"1\" }\r\n ], {\r\n duration: this.duration,\r\n easing: \"linear\"\r\n });\r\n\r\n this.setSpeed(speed);\r\n if (autoplay) this.play();\r\n else this.pause();\r\n\r\n this.promise = this.newPromise();\r\n this.mainAnimation.onfinish = () => {\r\n this.finish(this.options);\r\n window.cancelAnimationFrame(this.animationFrame);\r\n };\r\n }\r\n\r\n /**\r\n * Returns the Array of targets\r\n *\r\n * @returns {Node[]}\r\n * @memberof Animate\r\n */\r\n public getTargets(): Node[] {\r\n return this.targets;\r\n }\r\n\r\n /**\r\n * Returns a new Promise that is resolve when this.finish is called\r\n *\r\n * @public\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public newPromise(): Promise {\r\n return new Promise((resolve, reject) => {\r\n try {\r\n this.finish = (options: AnimationOptions) => {\r\n this.emit(\"finish\", options);\r\n return resolve(options);\r\n };\r\n } catch (err) { reject(err); }\r\n });\r\n }\r\n\r\n /**\r\n * Fulfills the this.promise Promise\r\n *\r\n * @param {(value?: any) => any} [onFulfilled]\r\n * @param {(reason?: any) => any} [onRejected]\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public then(\r\n onFulfilled?: (value?: any) => any,\r\n onRejected?: (reason?: any) => any\r\n ): Promise {\r\n return this.promise.then(onFulfilled, onRejected);\r\n }\r\n\r\n /**\r\n * Catches error that occur in the this.promise Promise\r\n *\r\n * @param {(reason?: any) => any} onRejected\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public catch(onRejected: (reason?: any) => any): Promise {\r\n return this.promise.catch(onRejected);\r\n }\r\n\r\n /**\r\n * If you don't care if the this.promise Promise has either been rejected or resolved\r\n *\r\n * @param {() => any} onFinally\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public finally(onFinally: () => any): Promise {\r\n return this.promise.finally(onFinally);\r\n }\r\n\r\n /**\r\n * Represents an Animation Frame Loop\r\n *\r\n * @public\r\n * @memberof Animate\r\n */\r\n public loop(): void {\r\n this.animationFrame = window.requestAnimationFrame(this.loop);\r\n this.emit(\"tick change\", this.getCurrentTime());\r\n }\r\n\r\n /**\r\n * Adds a listener for a given event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public on(events: EventInput, callback?: ListenerCallback, scope?: object): Animate {\r\n this.emitter.on(events, callback, scope);\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes a listener from an event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public off(events: EventInput, callback?: ListenerCallback, scope?: object): Animate {\r\n this.emitter.off(events, callback, scope);\r\n return this;\r\n }\r\n\r\n /**\r\n * Call all listeners within an event\r\n *\r\n * @param {(string | any[])} events\r\n * @param {...any} args\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public emit(events: string | any[], ...args: any): Animate {\r\n this.emitter.emit(events, ...args);\r\n return this;\r\n }\r\n\r\n /**\r\n * Get a specific Animation from an Animate instance\r\n *\r\n * @param {HTMLElement} element\r\n * @returns {Animation}\r\n * @memberof Animate\r\n */\r\n public getAnimation(element: HTMLElement): Animation {\r\n return this.animations.get(element);\r\n }\r\n\r\n /**\r\n * Play Animation's\r\n *\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public play(): Animate {\r\n // Once the animation is done, it's done, it can only be paused by the reset method\r\n if (this.mainAnimation.playState !== \"finished\") {\r\n this.mainAnimation.play();\r\n this.animationFrame = requestAnimationFrame(this.loop);\r\n this.animations.forEach(animation => {\r\n if (animation.playState !== \"finished\") animation.play();\r\n });\r\n this.emit(\"play\");\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Pause Animation's\r\n *\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public pause(): Animate {\r\n // Once the animation is done, it's done, it can only be reset by the reset method\r\n if (this.mainAnimation.playState !== \"finished\") {\r\n this.mainAnimation.pause();\r\n window.cancelAnimationFrame(this.animationFrame);\r\n this.animations.forEach(animation => {\r\n if (animation.playState !== \"finished\") animation.pause();\r\n });\r\n this.emit(\"pause\");\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the total duration of all Animations\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getDuration(): number {\r\n return this.duration;\r\n }\r\n\r\n /**\r\n * Returns the current time of the Main Animation\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getCurrentTime(): number {\r\n return this.mainAnimation.currentTime;\r\n }\r\n\r\n /**\r\n * Set the current time of the Main Animation\r\n *\r\n * @param {number} time\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setCurrentTime(time: number): Animate {\r\n this.mainAnimation.currentTime = time;\r\n this.animations.forEach(animation => {\r\n animation.currentTime = time;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the Animation progress as a fraction of the current time / duration\r\n *\r\n * @returns\r\n * @memberof Animate\r\n */\r\n public getProgress() {\r\n return this.getCurrentTime() / this.duration;\r\n }\r\n\r\n /**\r\n * Set the Animation progress as a fraction of the current time / duration\r\n *\r\n * @param {number} percent\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setProgress(percent: number): Animate {\r\n this.mainAnimation.currentTime = percent * this.duration;\r\n this.animations.forEach(animation => {\r\n animation.currentTime = percent * this.duration;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Return the playback speed of the animation\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getSpeed(): number {\r\n return this.mainAnimation.playbackRate;\r\n }\r\n\r\n /**\r\n * Set the playback speed of an Animation\r\n *\r\n * @param {number} [speed=1]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setSpeed(speed: number = 1): Animate {\r\n this.mainAnimation.playbackRate = speed;\r\n this.animations.forEach(animation => {\r\n animation.playbackRate = speed;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Reset all Animations\r\n *\r\n * @memberof Animate\r\n */\r\n public reset() {\r\n this.setCurrentTime(0);\r\n this.promise = this.newPromise();\r\n\r\n if (this.options.autoplay) this.play();\r\n else this.pause();\r\n }\r\n\r\n /**\r\n * Returns the current playing state\r\n *\r\n * @returns {(\"idle\" | \"running\" | \"paused\" | \"finished\")}\r\n * @memberof Animate\r\n */\r\n public getPlayState(): \"idle\" | \"running\" | \"paused\" | \"finished\" {\r\n return this.mainAnimation.playState;\r\n }\r\n\r\n /**\r\n * Get the options of an Animate instance\r\n *\r\n * @returns {AnimationOptions}\r\n * @memberof Animate\r\n */\r\n public getOptions(): AnimationOptions {\r\n return this.options;\r\n }\r\n\r\n // Returns the Animate options, as JSON\r\n public toJSON(): AnimationOptions {\r\n return this.getOptions();\r\n }\r\n}\r\n\r\n// Creates a new Animate instance\r\nexport const animate = (options: AnimationOptions = {}): Animate => {\r\n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AQ,GAAG,GACtB,KAUJ,gBACH,MAAO,MAAK,WAAW,IAAI,GASxB,OAEH,MAAI,MAAK,cAAc,YAAc,YACjC,MAAK,cAAc,OACnB,KAAK,eAAiB,sBAAsB,KAAK,MACjD,KAAK,WAAW,QAAQ,IACpB,AAAI,EAAU,YAAc,YAAY,EAAU,SAEtD,KAAK,KAAK,SAEP,KASJ,QAEH,MAAI,MAAK,cAAc,YAAc,YACjC,MAAK,cAAc,QACnB,OAAO,qBAAqB,KAAK,gBACjC,KAAK,WAAW,QAAQ,IACpB,AAAI,EAAU,YAAc,YAAY,EAAU,UAEtD,KAAK,KAAK,UAEP,KASJ,cACH,MAAO,MAAK,SAST,iBACH,MAAO,MAAK,cAAc,YAUvB,kBACH,YAAK,cAAc,YAAc,EACjC,KAAK,WAAW,QAAQ,IACpB,EAAU,YAAc,IAErB,KASJ,cACH,MAAO,MAAK,iBAAmB,KAAK,SAUjC,eACH,YAAK,cAAc,YAAc,EAAU,KAAK,SAChD,KAAK,WAAW,QAAQ,IACpB,EAAU,YAAc,EAAU,KAAK,WAEpC,KASJ,WACH,MAAO,MAAK,cAAc,aAUvB,WAAyB,GAC5B,YAAK,cAAc,aAAe,EAClC,KAAK,WAAW,QAAQ,IACpB,EAAU,aAAe,IAEtB,KAQJ,QACH,KAAK,eAAe,GACpB,KAAK,QAAU,KAAK,aAEpB,AAAI,KAAK,QAAQ,SAAU,KAAK,OAC3B,KAAK,QASP,eACH,MAAO,MAAK,cAAc,UASvB,aACH,MAAO,MAAK,QAIT,SACH,MAAO,MAAK,kBAKG,GAA6B,KACzC,GAAI,GAAQ", + "sources": ["../src/api.ts", "../src/config.ts", "../../manager/src/api.ts", "../src/manager.ts", "../src/url.ts", "../src/history.ts", "../src/page.ts", "../../emitter/src/api.ts", "../src/service.ts", "../src/pjax.ts", "../src/transition.ts", "../src/app.ts", "../src/route.ts", "../../animate/src/api.ts"], + "sourcesContent": ["export * from \"./config\";\r\nexport * from \"./manager\";\r\nexport * from \"./url\";\r\n\r\nexport * from \"./history\";\r\nexport * from \"./page\";\r\n\r\nexport * from \"./emitter\";\r\nexport * from \"./service\";\r\n\r\nexport * from \"./transition\";\r\n\r\nexport * from \"./app\";\r\nexport * from \"./pjax\";\r\nexport * from \"./route\";\r\n\r\nexport * from \"@okikio/animate\";\r\n", "// The config variables\r\nexport interface ICONFIG {\r\n prefix?: string;\r\n wrapperAttr?: string;\r\n noAjaxLinkAttr?: string;\r\n noPrefetchAttr?: \"no-prefetch\";\r\n headers?: string[][];\r\n preventSelfAttr?: string;\r\n preventAllAttr?: string;\r\n transitionAttr?: string;\r\n blockAttr?: string;\r\n timeout?: number\r\n}\r\n\r\nexport const CONFIG_DEFAULTS: ICONFIG = {\r\n wrapperAttr: \"wrapper\",\r\n noAjaxLinkAttr: \"no-ajax-link\",\r\n noPrefetchAttr: \"no-prefetch\",\r\n headers: [\r\n [\"x-partial\", \"true\"]\r\n ],\r\n preventSelfAttr: `prevent=\"self\"`,\r\n preventAllAttr: `prevent=\"all\"`,\r\n transitionAttr: \"transition\",\r\n blockAttr: `block`,\r\n timeout: 30000\r\n};\r\n\r\nexport type ConfigKeys = keyof ICONFIG;\r\n\r\n/**\r\n * The Config class\r\n *\r\n * @export\r\n * @class CONFIG\r\n */\r\nexport class CONFIG {\r\n /**\r\n * The current Configuration\r\n *\r\n * @public\r\n * @type ICONFIG\r\n * @memberof CONFIG\r\n */\r\n public config: ICONFIG;\r\n\r\n /**\r\n * Creates an instance of CONFIG.\r\n *\r\n * @param {ICONFIG} config\r\n * @memberof CONFIG\r\n */\r\n constructor(config: ICONFIG) {\r\n this.config = Object.assign({ ...CONFIG_DEFAULTS }, config);\r\n }\r\n\r\n /**\r\n * Converts string into data attributes\r\n *\r\n * @param {string} value\r\n * @param {boolean} brackets [brackets=true]\r\n * @returns string\r\n * @memberof CONFIG\r\n */\r\n public toAttr(value: string, brackets: boolean = true): string {\r\n let { prefix } = this.config;\r\n let attr = `data${prefix ? \"-\" + prefix : \"\"}-${value}`;\r\n return brackets ? `[${attr}]` : attr;\r\n }\r\n\r\n /**\r\n * Selects config vars, and formats them for use, or simply returns the current configurations for the framework\r\n *\r\n * @param {ConfigKeys} value\r\n * @param {boolean} [brackets=true]\r\n * @returns any\r\n * @memberof CONFIG\r\n */\r\n public getConfig(value?: ConfigKeys, brackets: boolean = true): any {\r\n if (typeof value !== \"string\")\r\n return this.config;\r\n\r\n let config = this.config[value];\r\n if (typeof config === \"string\")\r\n return this.toAttr(config, brackets);\r\n return config;\r\n }\r\n}\r\n", "/**\r\n * Manages complex lists of named data, eg. A page can be stored in a list by of other pages with the url being how the page is stored in the list. Managers use Maps to store data.\r\n *\r\n * @export\r\n * @class Manager\r\n * @template K\r\n * @template V\r\n */\r\nexport class Manager {\r\n\t/**\r\n\t * The complex list of named data, to which the Manager controls\r\n\t *\r\n\t * @public\r\n\t * @type Map\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic map: Map;\r\n\r\n\t/**\r\n\t * Creates an instance of Manager.\r\n\t *\r\n\t * @param {Array<[K, V]>} [value]\r\n\t * @memberof Manager\r\n\t */\r\n\tconstructor(value?: Array<[K, V]>) {\r\n\t\tthis.map = new Map(value);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the Manager class's list\r\n\t *\r\n\t * @returns Map\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic getMap(): Map {\r\n\t\treturn this.map;\r\n\t}\r\n\r\n\t/**\r\n\t * Get a value stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key to find in the Manager's list\r\n\t * @returns V\r\n\t */\r\n\tpublic get(key: K): V {\r\n\t\treturn this.map.get(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the keys of all items stored in the Manager as an Array\r\n\t *\r\n\t * @returns Array\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic keys(): Array {\r\n\t\treturn Array.from(this.map.keys());\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the values of all items stored in the Manager as an Array\r\n\t *\r\n\t * @returns Array\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic values(): Array {\r\n\t\treturn Array.from(this.map.values());\r\n\t}\r\n\r\n\t/**\r\n\t * Set a value stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key where the value will be stored\r\n\t * @param {V} value - The value to store\r\n\t * @returns Manager\r\n\t */\r\n\tpublic set(key: K, value: V): Manager {\r\n\t\tthis.map.set(key, value);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Adds a value to Manager, and uses the current size of the Manager as it's key, it works best when all the key in the Manager are numbers\r\n\t *\r\n\t * @public\r\n\t * @param {V} value\r\n\t * @returns Manager\r\n\t */\r\n\tpublic add(value: V): Manager {\r\n\t\tlet size = this.size;\r\n\t\t// @ts-ignore\r\n\t\tlet num: K = size as K;\r\n\t\tthis.set(num, value);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the total number of items stored in the Manager\r\n\t *\r\n\t * @public\r\n\t * @returns Number\r\n\t */\r\n\tpublic get size(): number {\r\n\t\treturn this.map.size;\r\n\t}\r\n\r\n\tpublic get length(): number {\r\n\t\treturn this.map.size;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the last item in the Manager who's index is a certain distance from the last item in the Manager\r\n\t *\r\n\t * @param {number} [distance=1]\r\n\t * @returns V | undefined\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic last(distance: number = 1): V | undefined {\r\n\t\tlet key = this.keys()[this.size - distance];\r\n\t\treturn this.get(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Removes a value stored in the Manager, via the key, returns true if an element in the Map object existed and has been removed, or false if the element does not exist.\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key for the key value pair to be removed\r\n\t * @returns boolean\r\n\t */\r\n\tpublic delete(key: K): boolean {\r\n\t\treturn this.map.delete(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Removes a value stored in the Manager, via the key, returns the Manager class, allowing for chains\r\n\t *\r\n\t * @public\r\n\t * @param {K} key - The key for the key value pair to be removed\r\n\t * @returns Manager\r\n\t */\r\n\tpublic remove(key: K): Manager {\r\n\t\tthis.map.delete(key);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Clear the Manager of all its contents\r\n\t *\r\n\t * @public\r\n\t * @returns Manager\r\n\t */\r\n\tpublic clear(): Manager {\r\n\t\tthis.map.clear();\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Checks if the Manager contains a certain key\r\n\t *\r\n\t * @public\r\n\t * @param {K} key\r\n\t * @returns boolean\r\n\t */\r\n\tpublic has(key: K): boolean {\r\n\t\treturn this.map.has(key);\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a new Iterator object that contains an array of [key, value] for each element in the Map object in insertion order.\r\n\t *\r\n\t * @public\r\n\t * @returns IterableIterator<[K, V]>\r\n\t */\r\n\tpublic entries(): IterableIterator<[K, V]> {\r\n\t\treturn this.map.entries();\r\n\t}\r\n\r\n\t/**\r\n\t * Iterates through the Managers contents, calling a callback function every iteration\r\n\t *\r\n\t * @param {*} [callback=(...args: any): void => { }]\r\n\t * @param {object} context\r\n\t * @returns Manager\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic forEach(\r\n\t\tcallback: any = (...args: any): void => { },\r\n\t\tcontext?: object\r\n\t): Manager {\r\n\t\tthis.map.forEach(callback, context);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Allows iteration via the for..of, learn more: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators]\r\n\t *\r\n\t * @returns IterableIterator<[K, V]>\r\n\t * @memberof Manager\r\n\t */\r\n\tpublic [Symbol.iterator](): IterableIterator<[K, V]> {\r\n\t\treturn this.entries();\r\n\t}\r\n}\r\n\r\n/**\r\n * Calls the method of a certain name for all items that are currently installed\r\n *\r\n * @param {Manager} manager\r\n * @param {string} method\r\n * @param {Array} [args=[]]\r\n */\r\nexport const methodCall = (manager: Manager, method: string, ...args: any): void => {\r\n\tmanager.forEach((item) => {\r\n\t\t// @ts-ignore\r\n\t\titem[method](...args);\r\n\t});\r\n};\r\n\r\n/**\r\n * Asynchronously calls the method of a certain name for all items that are currently installed, similar to methodCall\r\n *\r\n * @param {Manager} manager\r\n * @param {string} method\r\n * @param {Array} [args=[]]\r\n */\r\nexport const asyncMethodCall = async (manager: Manager, method: string, ...args: any): Promise => {\r\n\tfor (let [, item] of manager) {\r\n\t\t// @ts-ignore\r\n\t\tawait item[method](...args);\r\n\t}\r\n};\r\n\r\nexport default Manager;\r\n", "import { Manager, methodCall, asyncMethodCall } from \"@okikio/manager\";\r\nimport { CONFIG } from \"./config\";\r\nimport { App } from \"./app\";\r\nimport EventEmitter from \"@okikio/emitter\";\r\n\r\nexport type IAdvancedManager = AdvancedManager;\r\n\r\n/**\r\n * The base class for all AdvancedManager and AdvancedStorage items\r\n *\r\n * @export\r\n * @class ManagerItem\r\n */\r\nexport class ManagerItem {\r\n /**\r\n * The AdvancedManager the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type IAdvancedManager\r\n * @memberof ManagerItem\r\n */\r\n public manager: IAdvancedManager;\r\n\r\n /**\r\n * The App the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type App\r\n * @memberof ManagerItem\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the ManagerItem is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof ManagerItem\r\n */\r\n public config: CONFIG;\r\n public emitter: EventEmitter;\r\n public key: any;\r\n\r\n /**\r\n * Creates an instance of ManagerItem.\r\n *\r\n * @memberof ManagerItem\r\n */\r\n constructor() { }\r\n\r\n /**\r\n * Run after the Manager Item has been registered\r\n *\r\n * @returns any\r\n * @memberof ManagerItem\r\n */\r\n public install(): any { }\r\n\r\n /**\r\n * Register the current Manager Item's manager\r\n *\r\n * @param {IAdvancedManager} manager\r\n * @returns ManagerItem\r\n * @memberof ManagerItem\r\n */\r\n public register(manager: IAdvancedManager, key: any): ManagerItem {\r\n this.manager = manager;\r\n this.app = manager.app;\r\n this.config = manager.config;\r\n this.emitter = manager.emitter;\r\n this.key = key;\r\n this.install();\r\n return this;\r\n }\r\n\r\n public uninstall(): any { }\r\n\r\n public unregister() {\r\n this.uninstall();\r\n\r\n this.manager.delete(this.key);\r\n this.key = undefined;\r\n this.manager = undefined;\r\n this.app = undefined;\r\n this.config = undefined;\r\n this.emitter = undefined;\r\n }\r\n}\r\n\r\n/**\r\n * A tweak to the Manager class that makes it self aware of the App class it's instantiated in\r\n *\r\n * @export\r\n * @class AdvancedManager\r\n * @extends {Manager}\r\n * @template K\r\n * @template V\r\n */\r\nexport class AdvancedManager extends Manager {\r\n /**\r\n * The instance of the App class, the Manager is instantiated in\r\n *\r\n * @type App\r\n * @memberof AdvancedManager\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof AdvancedManager\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * The EventEmitter class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof AdvancedManager\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * Creates an instance of AdvancedManager.\r\n *\r\n * @param {App} app - The instance of the App class, the Manager is instantiated in\r\n * @memberof AdvancedManager\r\n */\r\n constructor(app: App) {\r\n super();\r\n this.app = app;\r\n this.config = app.config;\r\n this.emitter = app.emitter;\r\n }\r\n\r\n /**\r\n * Set a value stored in the Manager\r\n *\r\n * @public\r\n * @param {K} key - The key where the value will be stored\r\n * @param {V} value - The value to store\r\n * @returns AdvancedManager\r\n */\r\n public set(key: K, value: V) {\r\n super.set(key, value);\r\n value.register(this, key);\r\n return this;\r\n }\r\n}\r\n\r\nexport { Manager, methodCall, asyncMethodCall };\r\n", "/**\r\n * Adds new methods to the native URL Object; it seemed cleaner than using a custom method or editing the prototype.\r\n *\r\n * This doesn't extend the **Class** object because it's meant to be a small extension of the native URL class.\r\n *\r\n * @export\r\n * @class URL\r\n * @extends {URL}\r\n */\r\n// Read up on the native URL class [devdocs.io/dom/url]\r\n/**\r\n * Creates an instance of URL.\r\n *\r\n * @param {(string | URL | Location)} [url=window.location.pathname]\r\n * @return URL\r\n */\r\nexport const newURL = (url: string | URL | Location = window.location.href): URL => {\r\n return url instanceof URL ? url : new URL(url as unknown as string, window.location.origin);\r\n};\r\n\r\n/**\r\n * Returns the pathname with the hash\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const getHashedPath = (url: URL): string => (`${url.pathname}${url.hash}`);\r\n\r\n/**\r\n * Returns the actual hash without the hashtag\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const getHash = (url: URL): string => (url.hash.slice(1));\r\n\r\n/**\r\n * Removes the hash from the full URL for a clean URL string\r\n *\r\n * @param {URL} url\r\n * @returns string\r\n */\r\nexport const clean = (url: URL): string => (url.toString().replace(/(\\/#.*|\\/|#.*)$/, ''));\r\n\r\n/**\r\n * Compares two URLs to each other\r\n *\r\n * @param {URL} a\r\n * @param {URL} b\r\n * @returns boolean\r\n */\r\nexport const equal = (a: URL | string, b: URL | string): boolean => {\r\n let urlA = newURL(a);\r\n let urlB = newURL(b);\r\n return clean(urlA) === clean(urlB);\r\n};\r\n", "import { getHashedPath, newURL } from \"./url\";\r\n\r\nexport type Trigger = HTMLAnchorElement | \"HistoryManager\" | \"popstate\" | \"back\" | \"forward\";\r\nexport interface ICoords {\r\n\treadonly x: number;\r\n\treadonly y: number;\r\n}\r\n\r\nexport interface IStateData {\r\n\tscroll: ICoords;\r\n\t[key: string]: any;\r\n}\r\n\r\nexport interface IState {\r\n\turl: string;\r\n\tindex?: number;\r\n\ttransition: string;\r\n\tdata: IStateData;\r\n}\r\n\r\nexport interface IHistoryItem {\r\n\tindex: number;\r\n\tstates: IState[];\r\n}\r\n\r\n/**\r\n * A quick snapshot of page coordinates, e.g. scroll positions\r\n *\r\n * @export\r\n * @param {number} [x=window.scrollX]\r\n * @param {number} [y=window.scrollY]\r\n */\r\nexport const newCoords = (x: number = window.scrollX, y: number = window.scrollY): ICoords => ({ x, y });\r\n\r\n/**\r\n * Represents the current status of the page consisting of properties like: url, transition, and data\r\n *\r\n * @export\r\n * @param {IState} {\r\n * url = getHashedPath(newURL()),\r\n * index = 0,\r\n * transition = \"default\",\r\n * data = {\r\n * scroll: newCoords(),\r\n * trigger: \"HistoryManager\"\r\n * }\r\n * }\r\n * @memberof State\r\n*/\r\nexport const newState = (state: IState = {\r\n\turl: getHashedPath(newURL()),\r\n\tindex: 0,\r\n\ttransition: \"default\",\r\n\tdata: {\r\n\t\tscroll: newCoords(),\r\n\t\ttrigger: \"HistoryManager\"\r\n\t}\r\n}): IState => (state);\r\n\r\n\r\n/**\r\n * History of the site, stores only the State class\r\n *\r\n * @export\r\n * @class HistoryManager\r\n * @extends {Manager}\r\n */\r\nexport class HistoryManager {\r\n\tpublic states: IState[];\r\n\tpublic pointer = -1;\r\n\r\n\t/**\r\n\t * Creates an instance of the HistoryManager class, which inherits properties and methods from the Storage class.\r\n\t *\r\n\t * @memberof HistoryManager\r\n\t * @constructor\r\n\t */\r\n\tconstructor() {\r\n\t\tthis.states = [];\r\n\r\n\t\tlet state = newState();\r\n\t\tthis.add(state, \"replace\");\r\n\t}\r\n\r\n\tpublic get(index: number) {\r\n\t\treturn this.states[index];\r\n\t}\r\n\r\n\t/**\r\n\t * Sets the index of the state before adding to HistoryManager\r\n\t *\r\n\t * @param {IState} value\r\n\t * @returns HistoryManager\r\n\t */\r\n\tpublic add(value?: IState, historyAction: \"replace\" | \"push\" = \"push\"): HistoryManager {\r\n\t\tlet state = newState(value);\r\n\t\tlet len = this.length;\r\n\t\tthis.states.push({ ...state });\r\n\t\tthis.pointer = len;\r\n\r\n\t\tlet item: IHistoryItem = {\r\n\t\t\tindex: this.pointer,\r\n\t\t\tstates: [...this.states]\r\n\t\t};\r\n\t\tchangeState(historyAction, state, item);\r\n\t\treturn this;\r\n\t}\r\n\r\n\tpublic remove(index?: number) {\r\n\t\tif (index) {\r\n\t\t\tthis.states.splice(index, 1);\r\n\t\t} else {\r\n\t\t\tthis.states.pop();\r\n\t\t}\r\n\r\n\t\tthis.pointer--;\r\n\t\treturn this;\r\n\t}\r\n\r\n\tpublic replace(newStates: IState[]) {\r\n\t\tthis.states = newStates;\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Set state by index.\r\n\t */\r\n\tpublic set(i: number, state: IState) {\r\n\t\treturn (this.states[i] = state);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the current state.\r\n\t */\r\n\tget current(): IState {\r\n\t\treturn this.get(this.pointer);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the last state (top of the history stack).\r\n\t */\r\n\tget last(): IState {\r\n\t\treturn this.get(this.length - 1);\r\n\t}\r\n\r\n\t/**\r\n\t * Get the previous state.\r\n\t */\r\n\tget previous(): IState | null {\r\n\t\treturn this.pointer < 1 ? null : this.get(this.pointer - 1);\r\n\t}\r\n\r\n\tget length() {\r\n\t\treturn this.states.length;\r\n\t}\r\n\r\n}\r\n\r\n/**\r\n * Either push or replace history state\r\n *\r\n * @param {(\"push\" | \"replace\")} action\r\n * @param {IState} state\r\n * @param {_URL} url\r\n * @memberof PJAX\r\n */\r\nexport const changeState = (action: \"push\" | \"replace\", state: IState, item: object) => {\r\n\tlet href = getHashedPath(newURL(state.url));\r\n\tlet args = [item, \"\", href];\r\n\tif (window.history) {\r\n\t\tswitch (action) {\r\n\t\t\tcase \"push\":\r\n\t\t\t\twindow.history.pushState.apply(window.history, args);\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"replace\":\r\n\t\t\t\twindow.history.replaceState.apply(window.history, args);\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n};\r\n", "import { Manager, ManagerItem, AdvancedManager } from \"./manager\";\r\nimport { equal, newURL } from \"./url\";\r\nimport { App } from \"./app\";\r\n\r\n/**\r\n * Parses strings to DOM\r\n */\r\nexport const PARSER: DOMParser = new DOMParser();\r\n\r\n/**\r\n * A page represents the DOM elements that create each page\r\n *\r\n * @export\r\n * @class Page\r\n */\r\nexport class Page extends ManagerItem {\r\n /**\r\n * Holds the DOM of the current page\r\n *\r\n * @public\r\n * @type Document\r\n * @memberof Page\r\n */\r\n public dom: Document;\r\n\r\n /**\r\n * Holds the wrapper element to be swapped out of each Page\r\n *\r\n * @public\r\n * @type HTMLElement\r\n * @memberof Page\r\n */\r\n public wrapper: HTMLElement;\r\n\r\n /**\r\n * Holds the title of each page\r\n *\r\n * @public\r\n * @type string\r\n * @memberof Page\r\n */\r\n public title: string;\r\n\r\n /**\r\n * Holds the head element of each page\r\n *\r\n * @public\r\n * @type Element\r\n * @memberof Page\r\n */\r\n public head: Element;\r\n\r\n /**\r\n * Holds the body element of each page\r\n *\r\n * @public\r\n * @type Element\r\n * @memberof Page\r\n */\r\n public body: Element;\r\n\r\n /**\r\n * The URL of the current page\r\n *\r\n * @public\r\n * @type URL\r\n * @memberof Page\r\n */\r\n public url: URL;\r\n public data: string;\r\n public wrapperAttr: string;\r\n\r\n /**\r\n * Creates an instance of Page, it also creates a new page from response text, or a Document Object\r\n *\r\n * @param {URL} [url = newURL()]\r\n * @param {(string | Document)} [dom=document]\r\n * @memberof Page\r\n */\r\n constructor(url: URL = newURL(), dom: string | Document = document) {\r\n super();\r\n this.url = url;\r\n\r\n if (typeof dom === \"string\") {\r\n this.data = dom;\r\n } else this.dom = dom || document;\r\n }\r\n\r\n public async build() {\r\n if (!(this.dom instanceof Node)) {\r\n this.dom = PARSER.parseFromString(this.data, \"text/html\");\r\n }\r\n\r\n if (!(this.body instanceof Node)) {\r\n let { title, head, body } = this.dom;\r\n this.title = title;\r\n this.head = head;\r\n this.body = body;\r\n this.wrapper = this.body.querySelector(this.wrapperAttr);\r\n }\r\n }\r\n\r\n /**\r\n * Runs once the the manager and config have been registered\r\n *\r\n * @returns void\r\n * @memberof Page\r\n */\r\n public install(): void {\r\n this.wrapperAttr = this.config.getConfig(\"wrapperAttr\");\r\n }\r\n\r\n public uninstall() {\r\n this.url = undefined;\r\n this.title = undefined;\r\n this.head = undefined;\r\n this.body = undefined;\r\n this.dom = undefined;\r\n this.wrapper = undefined;\r\n this.data = undefined;\r\n this.wrapperAttr = undefined;\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Controls which page to be load\r\n *\r\n * @export\r\n * @class PageManager\r\n * @extends {AdvancedManager}\r\n */\r\nexport class PageManager extends AdvancedManager {\r\n /**\r\n * Stores all URLs that are currently loading\r\n *\r\n * @public\r\n * @type Manager>\r\n * @memberof PageManager\r\n */\r\n public loading: Manager> = new Manager();\r\n public maxPages = 5;\r\n\r\n /**\r\n * Creates an instance of the PageManager\r\n *\r\n * @param {App} app\r\n * @memberof PageManager\r\n */\r\n constructor(app: App) {\r\n super(app);\r\n let URLString = newURL().pathname;\r\n this.set(URLString, new Page());\r\n URLString = undefined;\r\n }\r\n\r\n /**\r\n * Load from cache or by requesting URL via a fetch request, avoid requesting for the same thing twice by storing the fetch request in \"this.loading\"\r\n *\r\n * @param {(URL | string)} [_url=newURL()]\r\n * @returns Promise\r\n * @memberof PageManager\r\n */\r\n public async load(_url: URL | string = newURL()): Promise {\r\n let url: URL = newURL(_url);\r\n let urlString: string = url.pathname;\r\n let page: Page, request: Promise;\r\n if (this.has(urlString)) {\r\n page = this.get(urlString);\r\n return Promise.resolve(page);\r\n }\r\n\r\n if (!this.loading.has(urlString)) {\r\n request = this.request(urlString);\r\n this.loading.set(urlString, request);\r\n } else request = this.loading.get(urlString);\r\n\r\n let response = await request;\r\n this.loading.delete(urlString);\r\n\r\n page = new Page(url, response);\r\n this.set(urlString, page);\r\n\r\n if (this.size > this.maxPages) {\r\n let currentUrl = newURL();\r\n let keys = this.keys();\r\n let first = equal(currentUrl, keys[0]) ? keys[1] : keys[0];\r\n let page = this.get(first);\r\n page.unregister();\r\n page = undefined;\r\n keys = undefined;\r\n currentUrl = undefined;\r\n first = undefined;\r\n }\r\n return page;\r\n }\r\n\r\n /**\r\n * Starts a fetch request\r\n *\r\n * @param {string} url\r\n * @returns Promise\r\n * @memberof PageManager\r\n */\r\n public async request(url: string): Promise {\r\n const headers = new Headers(this.config.getConfig(\"headers\"));\r\n const timeout = window.setTimeout(() => {\r\n window.clearTimeout(timeout);\r\n throw \"Request Timed Out!\";\r\n }, this.config.getConfig(\"timeout\"));\r\n\r\n try {\r\n let response = await fetch(url, {\r\n mode: 'same-origin',\r\n method: \"GET\",\r\n headers,\r\n cache: \"default\",\r\n credentials: \"same-origin\",\r\n });\r\n\r\n window.clearTimeout(timeout);\r\n if (response.status >= 200 && response.status < 300) {\r\n return await response.text();\r\n }\r\n\r\n const err = new Error(response.statusText || \"\" + response.status);\r\n throw err;\r\n } catch (err) {\r\n window.clearTimeout(timeout);\r\n throw err;\r\n }\r\n }\r\n}\r\n", "import { Manager } from \"@okikio/manager\";\r\n\r\nexport type ListenerCallback = ((...args: any) => void);\r\nexport interface IListener {\r\n readonly callback: ListenerCallback;\r\n readonly scope: object;\r\n readonly name: string;\r\n}\r\n\r\n/**\r\n * Represents a new event listener consisting of properties like: callback, scope, name\r\n *\r\n * @export\r\n */\r\nexport const newListener = ({\r\n callback = () => { },\r\n scope = null,\r\n name = \"event\",\r\n}: IListener): IListener => ({ callback, scope, name });\r\n\r\n/**\r\n * Represents a new event listener consisting of properties like: callback, scope, name\r\n *\r\n * @export\r\n * @class Event\r\n * @extends {Manager}\r\n */\r\nexport class Event extends Manager {\r\n /**\r\n * The name of the event\r\n *\r\n * @public\r\n * @type string\r\n * @memberof Event\r\n */\r\n public name: string;\r\n\r\n /**\r\n * Creates an instance of Event.\r\n *\r\n * @param {string} [name=\"event\"]\r\n * @memberof Event\r\n */\r\n constructor(name: string = \"event\") {\r\n super();\r\n this.name = name;\r\n }\r\n}\r\n\r\nexport type EventInput = string | object | Array;\r\n\r\n/**\r\n * An event emitter\r\n *\r\n * @export\r\n * @class EventEmitter\r\n * @extends {Manager}\r\n */\r\nexport class EventEmitter extends Manager {\r\n /**\r\n * Creates an instance of EventEmitter.\r\n *\r\n * @memberof EventEmitter\r\n */\r\n constructor() {\r\n super();\r\n }\r\n\r\n /**\r\n * Gets events, if event doesn't exist create a new Event\r\n *\r\n * @param {string} name\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public getEvent(name: string): Event {\r\n let event = this.get(name);\r\n if (!(event instanceof Event)) {\r\n this.set(name, new Event(name));\r\n return this.get(name);\r\n }\r\n\r\n return event;\r\n }\r\n /**\r\n * Creates a new listener and adds it to the event\r\n *\r\n * @param {string} name\r\n * @param {ListenerCallback} callback\r\n * @param {object} scope\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public newListener(\r\n name: string,\r\n callback: ListenerCallback,\r\n scope: object\r\n ): Event {\r\n let event = this.getEvent(name);\r\n event.add(newListener({ name, callback, scope }));\r\n return event;\r\n }\r\n\r\n /**\r\n * Adds a listener for a given event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback | object} callback\r\n * @param {object} scope\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public on(\r\n events: EventInput,\r\n callback?: ListenerCallback | object,\r\n scope?: object\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n let _name: string;\r\n let _callback: ListenerCallback;\r\n let isObject = typeof events == \"object\" && !Array.isArray(events);\r\n\r\n let _scope: object = isObject ? callback : scope;\r\n if (!isObject) _callback = (callback as ListenerCallback);\r\n\r\n // Loop through the list of events\r\n Object.keys(events).forEach(key => {\r\n // Select the name of the event from the list\r\n // Remember events can be {String | Object | Array}\r\n\r\n // Check If events is an Object (JSON like Object, and not an Array)\r\n if (isObject) {\r\n _name = key;\r\n _callback = events[key];\r\n } else {\r\n _name = events[key];\r\n }\r\n\r\n this.newListener(_name, _callback, _scope);\r\n }, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes a listener from an event\r\n *\r\n * @param {string} name\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns Event\r\n * @memberof EventEmitter\r\n */\r\n public removeListener(\r\n name: string,\r\n callback: ListenerCallback,\r\n scope: object\r\n ): Event {\r\n let event: Event = this.get(name);\r\n if (event instanceof Event && callback) {\r\n let listener = newListener({ name, callback, scope });\r\n\r\n event.forEach((value: IListener, i: number) => {\r\n if (\r\n value.callback === listener.callback &&\r\n value.scope === listener.scope\r\n ) {\r\n return event.delete(i);\r\n }\r\n });\r\n }\r\n\r\n return event;\r\n }\r\n\r\n /**\r\n * Removes a listener from a given event, or it just completely removes an event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback | object} [callback]\r\n * @param {object} [scope]\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public off(\r\n events: EventInput,\r\n callback?: ListenerCallback | object,\r\n scope?: object\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n let _name: string;\r\n let _callback: ListenerCallback;\r\n let isObject = typeof events == \"object\" && !Array.isArray(events);\r\n\r\n let _scope: object = isObject ? callback : scope;\r\n if (!isObject) _callback = (callback as ListenerCallback);\r\n\r\n // Loop through the list of events\r\n Object.keys(events).forEach(key => {\r\n // Select the name of the event from the list\r\n // Remember events can be {String | Object | Array}\r\n\r\n // Check If events is an Object (JSON like Object, and not an Array)\r\n if (isObject) {\r\n _name = key;\r\n _callback = events[key];\r\n } else {\r\n _name = events[key];\r\n }\r\n\r\n if (typeof _callback === \"function\") {\r\n this.removeListener(_name, _callback, _scope);\r\n } else this.delete(_name);\r\n }, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Call all listeners within an event\r\n *\r\n * @param {(string | Array)} events\r\n * @param {...any} args\r\n * @returns EventEmitter\r\n * @memberof EventEmitter\r\n */\r\n public emit(\r\n events: string | Array,\r\n ...args: any\r\n ): EventEmitter {\r\n // If there is no event break\r\n if (typeof events == \"undefined\") return this;\r\n\r\n // Create a new event every space\r\n if (typeof events == \"string\") events = events.trim().split(/\\s/g);\r\n\r\n // Loop through the list of events\r\n events.forEach((event: string) => {\r\n let _event: Event = this.get(event);\r\n\r\n if (_event instanceof Event) {\r\n _event.forEach((listener: IListener) => {\r\n let { callback, scope } = listener;\r\n callback.apply(scope, args);\r\n });\r\n }\r\n }, this);\r\n return this;\r\n }\r\n}\r\n\r\nexport default EventEmitter;\r\n", "import { AdvancedManager, ManagerItem, methodCall } from \"./manager\";\r\nimport { TransitionManager } from \"./transition\";\r\nimport { HistoryManager } from \"./history\";\r\nimport { EventEmitter } from \"./emitter\";\r\nimport { PageManager } from \"./page\";\r\nimport { App } from \"./app\";\r\n\r\n/**\r\n * Controls specific kinds of actions that require JS\r\n *\r\n * @export\r\n * @class Service\r\n */\r\nexport class Service extends ManagerItem {\r\n\t/**\r\n\t * Stores access to the App class's EventEmitter\r\n\t *\r\n\t * @public\r\n\t * @type EventEmitter\r\n\t * @memberof Service\r\n\t */\r\n\tpublic emitter: EventEmitter;\r\n\r\n\t/**\r\n\t * Stores access to the App class's PageManager\r\n\t *\r\n\t * @public\r\n\t * @type PageManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic PageManager: PageManager;\r\n\r\n\t/**\r\n\t * Stores access to the App class's HistoryManager\r\n\t *\r\n\t * @public\r\n\t * @type HistoryManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic HistoryManager: HistoryManager;\r\n\r\n\t/**\r\n\t * Stores the ServiceManager the service is install on\r\n\t *\r\n\t * @public\r\n\t * @type ServiceManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic ServiceManager: ServiceManager;\r\n\r\n\t/**\r\n\t * Stores access to the App's TransitionManager\r\n\t *\r\n\t * @public\r\n\t * @type TransitionManager\r\n\t * @memberof Service\r\n\t */\r\n\tpublic TransitionManager: TransitionManager;\r\n\r\n\t/**\r\n\t * Method is run once when Service is installed on a ServiceManager\r\n\t *\r\n\t * @memberof Service\r\n\t */\r\n\tpublic install(): void {\r\n\t\tlet { app } = this.manager;\r\n\t\tthis.PageManager = app.pages;\r\n\t\tthis.HistoryManager = app.history;\r\n\t\tthis.ServiceManager = app.services;\r\n\t\tthis.TransitionManager = app.transitions;\r\n\t}\r\n\r\n\t// Called before the start of a Service, represents a constructor of sorts\r\n\tpublic init(...args: any): void { }\r\n\r\n\t// Called on start of Service\r\n\tpublic boot(): void {\r\n\t\tthis.initEvents();\r\n\t}\r\n\r\n\t// Initialize events\r\n\tpublic initEvents(): void { }\r\n\r\n\t// Stop events\r\n\tpublic stopEvents(): void { }\r\n\r\n\tpublic uninstall() {\r\n\t\tthis.PageManager = undefined;\r\n\t\tthis.HistoryManager = undefined;\r\n\t\tthis.ServiceManager = undefined;\r\n\t\tthis.TransitionManager = undefined;\r\n\t}\r\n\r\n\t// Stop services\r\n\tpublic stop(): void {\r\n\t\tthis.stopEvents();\r\n\t\tthis.unregister();\r\n\t}\r\n}\r\n\r\n/**\r\n * The Service Manager controls the lifecycle of all services in an App\r\n *\r\n * @export\r\n * @class ServiceManager\r\n * @extends {AdvancedManager}\r\n */\r\nexport class ServiceManager extends AdvancedManager {\r\n\t/**\r\n\t * Creates an instance of ServiceManager.\r\n\t *\r\n\t * @param {App} app\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tconstructor(app: App) {\r\n\t\tsuper(app);\r\n\t}\r\n\r\n\t/**\r\n\t * Call the init method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic init(): ServiceManager {\r\n\t\tmethodCall(this, \"init\", this.app);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Call the boot method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic boot(): ServiceManager {\r\n\t\tmethodCall(this, \"boot\", this.app);\r\n\t\treturn this;\r\n\t}\r\n\r\n\t/**\r\n\t * Call the stop method for all Services\r\n\t *\r\n\t * @returns ServiceManager\r\n\t * @memberof ServiceManager\r\n\t */\r\n\tpublic stop(): ServiceManager {\r\n\t\tmethodCall(this, \"stop\", this.app);\r\n\t\treturn this;\r\n\t}\r\n}\r\n", "import { newState, Trigger, IState, newCoords, IHistoryItem, changeState } from \"./history\";\r\nimport { Service } from \"./service\";\r\nimport { Page } from \"./page\";\r\nimport { newURL, getHashedPath, equal } from \"./url\";\r\n\r\nexport type LinkEvent = MouseEvent | TouchEvent;\r\nexport type StateEvent = LinkEvent | PopStateEvent;\r\nexport type IgnoreURLsList = Array;\r\n\r\n/**\r\n * Creates a Barba JS like PJAX Service, for the Framework\r\n *\r\n * @export\r\n * @class PJAX\r\n * @extends {Service}\r\n */\r\n// Based on Barba JS and StartingBlocks\r\nexport class PJAX extends Service {\r\n /**\r\n * URLs to ignore when prefetching\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected ignoreURLs: IgnoreURLsList = [];\r\n\r\n /**\r\n * Whether or not to disable prefetching\r\n *\r\n * @private\r\n *\r\n * @memberof PJAX\r\n */\r\n protected prefetchIgnore: boolean = false;\r\n\r\n /**\r\n * Current state or transitions\r\n *\r\n * @public\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n public isTransitioning: boolean = false;\r\n\r\n /**\r\n * Ignore extra clicks of an anchor element if a transition has already started\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected stopOnTransitioning: boolean = false;\r\n\r\n /**\r\n * On page change (excluding popstate event) keep current scroll position\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected stickyScroll: boolean = false;\r\n\r\n /**\r\n * Force load a page if an error occurs\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected forceOnError: boolean = false;\r\n\r\n /**\r\n * Dictates whether to auto scroll if an hash is present in the window URL\r\n *\r\n * @protected\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected autoScrollOnHash: boolean = true;\r\n\r\n /**\r\n * Disables all extra scroll effects of PJAX\r\n *\r\n * @private\r\n * @type boolean\r\n * @memberof PJAX\r\n */\r\n protected dontScroll: boolean = false;\r\n\r\n /**\r\n * Sets the transition state, sets isTransitioning to true\r\n *\r\n * @private\r\n * @memberof PJAX\r\n */\r\n private transitionStart() {\r\n this.isTransitioning = true;\r\n }\r\n\r\n /**\r\n * Sets the transition state, sets isTransitioning to false\r\n *\r\n * @private\r\n * @memberof PJAX\r\n */\r\n private transitionStop() {\r\n this.isTransitioning = false;\r\n }\r\n\r\n public init() {\r\n super.init();\r\n\r\n /**\r\n * Bind the event listeners to the PJAX class\r\n *\r\n * @memberof PJAX\r\n */\r\n this.onHover = this.onHover.bind(this);\r\n this.onClick = this.onClick.bind(this);\r\n this.onStateChange = this.onStateChange.bind(this);\r\n }\r\n\r\n /**\r\n * Starts the PJAX Service\r\n *\r\n * @memberof PJAX\r\n */\r\n public boot() {\r\n if (\"scrollRestoration\" in window.history) {\r\n // Back off, browser, I got this...\r\n window.history.scrollRestoration = \"manual\";\r\n }\r\n\r\n super.boot();\r\n }\r\n\r\n /**\r\n * Gets the transition to use for a certain anchor\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @returns {(string | null)}\r\n * @memberof PJAX\r\n */\r\n public getTransitionName(el: HTMLAnchorElement): string | null {\r\n if (!el || !el.getAttribute) return null;\r\n let transitionAttr = el.getAttribute(\r\n this.config.getConfig(\"transitionAttr\", false)\r\n );\r\n if (typeof transitionAttr === \"string\") return transitionAttr;\r\n return null;\r\n }\r\n\r\n /**\r\n * Checks to see if the anchor is valid\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @param {(LinkEvent | KeyboardEvent)} event\r\n * @param {string} href\r\n *\r\n * @memberof PJAX\r\n */\r\n public validLink(\r\n el: HTMLAnchorElement,\r\n event: LinkEvent | KeyboardEvent,\r\n href: string\r\n ): boolean {\r\n let pushStateSupport = !window.history.pushState;\r\n let exists = !el || !href;\r\n let eventMutate =\r\n (event as KeyboardEvent).metaKey ||\r\n (event as KeyboardEvent).ctrlKey ||\r\n (event as KeyboardEvent).shiftKey ||\r\n (event as KeyboardEvent).altKey;\r\n let newTab =\r\n el.hasAttribute(\"target\") &&\r\n (el as HTMLAnchorElement).target === \"_blank\";\r\n let crossOrigin =\r\n (el as HTMLAnchorElement).protocol !== location.protocol ||\r\n (el as HTMLAnchorElement).hostname !== location.hostname;\r\n let download = typeof el.getAttribute(\"download\") === \"string\";\r\n let preventSelf = el.hasAttribute(this.config.getConfig(\"preventSelfAttr\", false));\r\n let preventAll = Boolean(\r\n el.closest(this.config.getConfig(\"preventAllAttr\"))\r\n );\r\n let prevent = preventSelf && preventAll;\r\n let sameURL = getHashedPath(newURL()) === getHashedPath(newURL(href));\r\n return !(\r\n exists ||\r\n pushStateSupport ||\r\n eventMutate ||\r\n newTab ||\r\n crossOrigin ||\r\n download ||\r\n prevent ||\r\n sameURL\r\n );\r\n }\r\n\r\n /**\r\n * Returns the href or an Anchor element\r\n *\r\n * @param {HTMLAnchorElement} el\r\n * @returns {(string | null)}\r\n * @memberof PJAX\r\n */\r\n public getHref(el: HTMLAnchorElement): string | null {\r\n if (\r\n el &&\r\n el.tagName &&\r\n el.tagName.toLowerCase() === \"a\" &&\r\n typeof el.href === \"string\"\r\n )\r\n return el.href;\r\n return null;\r\n }\r\n\r\n /**\r\n * Check if event target is a valid anchor with an href, if so, return the link\r\n *\r\n * @param {LinkEvent} event\r\n *\r\n * @memberof PJAX\r\n */\r\n public getLink(event: LinkEvent): HTMLAnchorElement {\r\n let el = event.target as HTMLAnchorElement;\r\n let href: string = this.getHref(el);\r\n\r\n while (el && !href) {\r\n el = (el as HTMLElement).parentNode as HTMLAnchorElement;\r\n href = this.getHref(el);\r\n }\r\n\r\n // Check for a valid link\r\n if (!el || !this.validLink(el, event, href)) return;\r\n return el;\r\n }\r\n\r\n /**\r\n * When an element is clicked.\r\n *\r\n * Get valid anchor element.\r\n * Go for a transition.\r\n *\r\n * @param {LinkEvent} event\r\n * @returns\r\n * @memberof PJAX\r\n */\r\n public onClick(event: LinkEvent) {\r\n let el = this.getLink(event);\r\n if (!el) return;\r\n\r\n if (this.isTransitioning && this.stopOnTransitioning) {\r\n event.preventDefault();\r\n event.stopPropagation();\r\n return;\r\n }\r\n\r\n let href = this.getHref(el);\r\n this.emitter.emit(\"ANCHOR_CLICK CLICK\", event);\r\n this.go({ href, trigger: el, event });\r\n }\r\n\r\n /**\r\n * Returns the direction of the State change as a String, either the Back button or the Forward button\r\n *\r\n * @param {number} value\r\n *\r\n * @memberof PJAX\r\n */\r\n public getDirection(value: number): Trigger {\r\n if (Math.abs(value) > 1) {\r\n // Ex 6-0 > 0 -> forward, 0-6 < 0 -> back\r\n return value > 0 ? \"forward\" : \"back\";\r\n } else {\r\n if (value === 0) {\r\n return \"popstate\";\r\n } else {\r\n // Ex 6-5 > 0 -> back, 5-6 < 0 -> forward\r\n return value > 0 ? \"back\" : \"forward\";\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Force a page to go to a certain URL\r\n *\r\n * @param {string} href\r\n * @memberof PJAX\r\n */\r\n public force(href: string): void {\r\n window.location.assign(href);\r\n }\r\n\r\n /**\r\n * If transition is running force load page.\r\n * Stop if currentURL is the same as new url.\r\n * On state change, change the current state history,\r\n * to reflect the direction of said state change\r\n * Load page and page transition.\r\n *\r\n * @param {string} href\r\n * @param {Trigger} [trigger='HistoryManager']\r\n * @param {StateEvent} [event]\r\n * @memberof PJAX\r\n */\r\n public go({\r\n href,\r\n trigger = \"HistoryManager\",\r\n event,\r\n }: {\r\n href: string;\r\n trigger?: Trigger;\r\n event?: StateEvent;\r\n }): Promise {\r\n // If transition is already running and the go method is called again, force load page\r\n if (this.isTransitioning && this.stopOnTransitioning) {\r\n this.force(href);\r\n return;\r\n }\r\n\r\n let scroll = { x: 0, y: 0 };\r\n let currentState = this.HistoryManager.current;\r\n let currentURL = currentState.url;\r\n if (equal(currentURL, href)) {\r\n return;\r\n }\r\n\r\n let transitionName: string;\r\n if (event && (event as PopStateEvent).state) {\r\n this.emitter.emit(\"POPSTATE\", event);\r\n\r\n // If popstate, get back/forward direction.\r\n let { state }: { state: IHistoryItem } = event as PopStateEvent;\r\n let { index } = state;\r\n let currentIndex = currentState.index;\r\n let difference = currentIndex - index;\r\n\r\n trigger = this.getDirection(difference);\r\n\r\n let _state = this.HistoryManager.get(this.HistoryManager.pointer);\r\n transitionName = _state.transition;\r\n scroll = _state.data.scroll;\r\n\r\n // Based on the direction of the state change either remove or add a state\r\n this.HistoryManager.replace(state.states);\r\n this.HistoryManager.pointer = index;\r\n if (trigger === \"back\") {\r\n // this.HistoryManager.remove(currentIndex);\r\n this.emitter.emit(`POPSTATE_BACK`, event);\r\n } else if (trigger === \"forward\") {\r\n // this.HistoryManager.add({ url: href, transition, data });\r\n this.emitter.emit(`POPSTATE_FORWARD`, event);\r\n }\r\n\r\n } else {\r\n // Add new state\r\n transitionName = this.getTransitionName(trigger as HTMLAnchorElement) ||\r\n \"default\";\r\n\r\n scroll = newCoords();\r\n\r\n let state = newState({\r\n url: href,\r\n transition: transitionName,\r\n data: { scroll },\r\n });\r\n\r\n this.HistoryManager.add(state);\r\n this.emitter.emit(\"HISTORY_NEW_ITEM\", event);\r\n }\r\n\r\n if (event) {\r\n event.stopPropagation();\r\n event.preventDefault();\r\n }\r\n\r\n this.emitter.emit(\"GO\", event);\r\n return this.load({\r\n oldHref: currentURL,\r\n href,\r\n trigger,\r\n transitionName,\r\n scroll,\r\n });\r\n }\r\n\r\n /**\r\n * Load the new Page as well as a Transition; run the Transition\r\n *\r\n * @param {string} oldHref\r\n * @param {string} href\r\n * @param {Trigger} trigger\r\n * @param {string} [transitionName=\"default\"]\r\n *\r\n * @memberof PJAX\r\n */\r\n public async load({\r\n oldHref,\r\n href,\r\n trigger,\r\n transitionName = \"default\",\r\n scroll = { x: 0, y: 0 },\r\n }: {\r\n oldHref: string;\r\n href: string;\r\n trigger: Trigger;\r\n transitionName?: string;\r\n scroll: { x: number; y: number };\r\n }): Promise {\r\n try {\r\n let oldPage = await this.PageManager.load(oldHref);\r\n await oldPage.build();\r\n let newPage: Page;\r\n\r\n this.emitter.emit(\"PAGE_LOADING\", { href, oldPage, trigger });\r\n try {\r\n try {\r\n newPage = await this.PageManager.load(href);\r\n await newPage.build();\r\n this.transitionStart();\r\n this.emitter.emit(\"PAGE_LOAD_COMPLETE\", {\r\n newPage,\r\n oldPage,\r\n trigger,\r\n });\r\n } catch (err) {\r\n console.error(`[PJAX] page load error: ${err}`);\r\n }\r\n\r\n // --\r\n // --\r\n\r\n this.emitter.emit(\"NAVIGATION_START\", {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n transitionName,\r\n });\r\n\r\n try {\r\n this.emitter.emit(\"TRANSITION_START\", transitionName);\r\n\r\n let transition = await this.TransitionManager.boot(transitionName, {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n scroll,\r\n });\r\n\r\n if (!transition.scrollable) {\r\n if (!/back|popstate|forward/.test(trigger as string)) {\r\n scroll = hashAction();\r\n }\r\n\r\n window.scroll(scroll.x, scroll.y);\r\n }\r\n\r\n this.emitter.emit(\"TRANSITION_END\", { transition });\r\n\r\n } catch (err) {\r\n console.error(`[PJAX] transition error: ${err}`);\r\n }\r\n\r\n this.emitter.emit(\"NAVIGATION_END\", {\r\n oldPage,\r\n newPage,\r\n trigger,\r\n transitionName,\r\n });\r\n } catch (err) {\r\n this.transitionStop();\r\n throw err;\r\n }\r\n\r\n this.transitionStop(); // Sets isTransitioning to false\r\n } catch (err) {\r\n if (this.forceOnError) this.force(href);\r\n else console.error(err);\r\n }\r\n }\r\n\r\n /**\r\n * Check to see if the URL is to be ignored, uses either RegExp of Strings to check\r\n *\r\n * @param {URL} { pathname }\r\n *\r\n * @memberof PJAX\r\n */\r\n public ignoredURL({ pathname }: URL): boolean {\r\n return (\r\n this.ignoreURLs.length &&\r\n this.ignoreURLs.some((url) => {\r\n return typeof url === \"string\"\r\n ? url === pathname\r\n : (url as RegExp).exec(pathname) !== null;\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * When you hover over an anchor, prefetch the event target's href\r\n *\r\n * @param {LinkEvent} event\r\n * @memberof PJAX\r\n */\r\n public onHover(event: LinkEvent): Promise {\r\n let el = this.getLink(event);\r\n if (!el) return;\r\n\r\n let url = newURL(this.getHref(el));\r\n let urlString: string = url.pathname;\r\n // If Url is ignored or already in cache, don't do any think\r\n if (this.ignoredURL(url) || this.PageManager.has(urlString)) return;\r\n this.emitter.emit(\"ANCHOR_HOVER HOVER\", event);\r\n\r\n try {\r\n this.PageManager.load(url);\r\n } catch (err) {\r\n console.warn(\"[PJAX] prefetch error,\", err);\r\n }\r\n }\r\n\r\n /**\r\n * When History state changes.\r\n *\r\n * Get url from State\r\n * Go for a Barba transition.\r\n *\r\n * @param {PopStateEvent} event\r\n * @memberof PJAX\r\n */\r\n public onStateChange(event: PopStateEvent): void {\r\n this.go({ href: window.location.href, trigger: \"popstate\", event });\r\n }\r\n\r\n /**\r\n * Initialize DOM Events\r\n *\r\n * @memberof PJAX\r\n */\r\n public initEvents() {\r\n if (this.prefetchIgnore !== true) {\r\n document.addEventListener(\"mouseover\", this.onHover);\r\n document.addEventListener(\"touchstart\", this.onHover);\r\n }\r\n\r\n document.addEventListener(\"click\", this.onClick);\r\n window.addEventListener(\"popstate\", this.onStateChange);\r\n }\r\n\r\n /**\r\n * Stop DOM Events\r\n *\r\n * @memberof PJAX\r\n */\r\n public stopEvents() {\r\n if (this.prefetchIgnore !== true) {\r\n document.removeEventListener(\"mouseover\", this.onHover);\r\n document.removeEventListener(\"touchstart\", this.onHover);\r\n }\r\n\r\n document.removeEventListener(\"click\", this.onClick);\r\n window.removeEventListener(\"popstate\", this.onStateChange);\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Auto scrolls to an elements position if the element has an hash\r\n *\r\n * @param {string} [hash=window.location.hash]\r\n * @memberof PJAX\r\n */\r\nexport const hashAction = (hash: string = window.location.hash) => {\r\n try {\r\n\r\n let _hash = hash[0] == \"#\" ? hash : newURL(hash).hash;\r\n if (_hash.length > 1) {\r\n let el = document.getElementById(_hash.slice(1)) as HTMLElement;\r\n\r\n if (el) {\r\n return newCoords(el.offsetLeft, el.offsetTop);\r\n }\r\n }\r\n } catch (e) {\r\n console.warn(\"hashAction error\", e);\r\n }\r\n\r\n return newCoords(0, 0);\r\n};\r\n", "import { Manager } from \"./manager\";\r\nimport { EventEmitter } from \"./emitter\";\r\nimport { ICoords, Trigger } from \"./history\";\r\nimport { Page } from \"./page\";\r\nimport { App } from \"./app\";\r\nimport { CONFIG } from \"./config\";\r\nimport { hashAction } from \"./pjax\";\r\n\r\n/**\r\n * The async function type, allows for smooth transition between Promises\r\n */\r\nexport type asyncFn = (err?: any, value?: any) => void;\r\nexport interface ITransition {\r\n oldPage?: Page;\r\n newPage?: Page;\r\n trigger?: Trigger;\r\n scroll?: { x: number; y: number };\r\n scrollable?: boolean;\r\n in: (data: ITransitionData) => any;\r\n out: (data: ITransitionData) => any;\r\n [key: string]: any;\r\n}\r\nexport interface ITransitionData {\r\n from?: Page;\r\n to?: Page;\r\n trigger?: Trigger;\r\n scroll?: ICoords;\r\n done: asyncFn;\r\n}\r\n\r\n/**\r\n * Controls which animation between pages to use\r\n *\r\n * @export\r\n * @class TransitionManager\r\n * @extends {Manager}\r\n */\r\nexport class TransitionManager extends Manager {\r\n /**\r\n * The instance of the App class, the Manager is instantiated in\r\n *\r\n * @type App\r\n * @memberof AdvancedManager\r\n */\r\n public app: App;\r\n\r\n /**\r\n * The Config class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof AdvancedManager\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * The EventEmitter class of the App the AdvancedManager is attached to\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof AdvancedManager\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * Creates an instance of the TransitionManager\r\n *\r\n * @param {App} app\r\n * @memberof TransitionManager\r\n */\r\n constructor(app: App) {\r\n super();\r\n this.app = app;\r\n this.config = app.config;\r\n this.emitter = app.emitter;\r\n }\r\n\r\n /**\r\n * Runs a transition\r\n *\r\n * @param {{ name: string, oldPage: Page, newPage: Page, trigger: Trigger }} data\r\n * @returns Promise\r\n * @memberof TransitionManager\r\n */\r\n public async boot(name: string, data: any): Promise {\r\n let transition: ITransition = this.get(name);\r\n let scroll = data.scroll;\r\n if (!(data.oldPage instanceof Page) || !(data.newPage instanceof Page))\r\n throw `[Page] either oldPage or newPage aren't instances of the Page Class.\\n ${{\r\n newPage: data.newPage,\r\n oldPage: data.oldPage,\r\n }}`;\r\n\r\n let fromWrapper = data.oldPage.wrapper;\r\n let toWrapper = data.newPage.wrapper;\r\n document.title = `` + data.newPage.title;\r\n\r\n if (!(fromWrapper instanceof Node) || !(toWrapper instanceof Node))\r\n throw `[Wrapper] the wrapper from the ${!(toWrapper instanceof Node) ? \"next\" : \"current\"\r\n } page cannot be found. The wrapper must be an element that has the attribute ${this.config.getConfig(\r\n \"wrapperAttr\"\r\n )}.`;\r\n transition.init && transition?.init(data);\r\n\r\n this.emitter.emit(\"BEFORE_TRANSITION_OUT\");\r\n await new Promise((done) => {\r\n let outMethod: Promise = transition.out.call(transition, {\r\n ...data,\r\n from: data.oldPage,\r\n trigger: data.trigger,\r\n done,\r\n });\r\n\r\n if (outMethod.then) outMethod.then(done);\r\n });\r\n\r\n this.emitter.emit(\"AFTER_TRANSITION_OUT\");\r\n await new Promise((done) => {\r\n fromWrapper.insertAdjacentElement(\"beforebegin\", toWrapper);\r\n this.emitter.emit(\"CONTENT_INSERT\");\r\n\r\n if (!/back|popstate|forward/.test(data.trigger as string)) {\r\n scroll = hashAction();\r\n }\r\n done();\r\n });\r\n\r\n await new Promise((done) => {\r\n fromWrapper.remove();\r\n fromWrapper = undefined;\r\n toWrapper = undefined;\r\n this.emitter.emit(\"CONTENT_REPLACED\");\r\n done();\r\n });\r\n\r\n this.emitter.emit(\"BEFORE_TRANSITION_IN\");\r\n\r\n await new Promise((done) => {\r\n let inMethod: Promise = transition.in.call(transition, {\r\n ...data,\r\n from: data.oldPage,\r\n to: data.newPage,\r\n trigger: data.trigger,\r\n scroll,\r\n done,\r\n });\r\n\r\n if (inMethod.then) inMethod.then(done);\r\n });\r\n\r\n this.emitter.emit(\"AFTER_TRANSITION_IN\");\r\n return transition;\r\n }\r\n}\r\n", "import { EventEmitter, ListenerCallback, EventInput } from \"./emitter\";\r\nimport { ITransition, TransitionManager } from \"./transition\";\r\nimport { HistoryManager, IState } from \"./history\";\r\nimport { ServiceManager, Service } from \"./service\";\r\nimport { PageManager } from \"./page\";\r\nimport { CONFIG, ICONFIG } from \"./config\";\r\n\r\n/**\r\n * The App class starts the entire process, it controls all managers and all services\r\n *\r\n * @export\r\n * @class App\r\n */\r\nexport class App {\r\n /**\r\n * A new instance of the HistoryManager\r\n *\r\n * @public\r\n * @type HistoryManager\r\n * @memberof App\r\n */\r\n public history: HistoryManager;\r\n\r\n /**\r\n * A new instance of the TransitionManager\r\n *\r\n * @public\r\n * @type TransitionManager\r\n * @memberof App\r\n */\r\n public transitions: TransitionManager;\r\n\r\n /**\r\n * A new instance of the ServiceManager\r\n *\r\n * @public\r\n * @type ServiceManager\r\n * @memberof App\r\n */\r\n public services: ServiceManager;\r\n\r\n /**\r\n * A new instance of an EventEmitter\r\n *\r\n * @public\r\n * @type EventEmitter\r\n * @memberof App\r\n */\r\n public emitter: EventEmitter;\r\n\r\n /**\r\n * A new instance of the PageManager\r\n *\r\n * @public\r\n * @type PageManager\r\n * @memberof App\r\n */\r\n public pages: PageManager;\r\n\r\n /**\r\n * The current Configuration's for the framework\r\n *\r\n * @public\r\n * @type CONFIG\r\n * @memberof App\r\n */\r\n public config: CONFIG;\r\n\r\n /**\r\n * Creates an instance of App.\r\n *\r\n * @param {(ICONFIG | CONFIG)} [config={}]\r\n * @memberof App\r\n */\r\n constructor(config: object = {}) {\r\n this.register(config);\r\n }\r\n\r\n /**\r\n * For registering all managers and the configurations\r\n *\r\n * @param {(ICONFIG | CONFIG)} [config={}]\r\n * @returns App\r\n * @memberof App\r\n */\r\n public register(config: ICONFIG | CONFIG = {}): App {\r\n this.config = config instanceof CONFIG ? config : new CONFIG(config);\r\n this.emitter = new EventEmitter();\r\n this.history = new HistoryManager();\r\n this.pages = new PageManager(this);\r\n this.transitions = new TransitionManager(this);\r\n this.services = new ServiceManager(this);\r\n\r\n let handler = (() => {\r\n document.removeEventListener(\"DOMContentLoaded\", handler);\r\n window.removeEventListener(\"load\", handler);\r\n this.emitter.emit(\"READY ready\");\r\n }).bind(this);\r\n\r\n document.addEventListener(\"DOMContentLoaded\", handler);\r\n window.addEventListener(\"load\", handler);\r\n return this;\r\n }\r\n\r\n /**\r\n * Based on the type, it will return either a Transition, a Service, or a State from their respective Managers\r\n *\r\n * @param {(\"service\" | \"transition\" | \"state\" | string)} type\r\n * @param {any} key\r\n * @returns Service | Transition | State\r\n * @memberof App\r\n */\r\n public get(type: \"service\" | \"transition\" | \"state\" | string, key: any): Service | ITransition | IState {\r\n switch (type.toLowerCase()) {\r\n case \"service\":\r\n return this.services.get(key);\r\n case \"transition\":\r\n return this.transitions.get(key);\r\n case \"state\":\r\n return this.history.get(key);\r\n default:\r\n throw `Error: can't get type '${type}', it is not a recognized type. Did you spell it correctly.`;\r\n }\r\n }\r\n\r\n /**\r\n * Based on the type, it will return load either Page a Transition, a Service, a State, or a Page from their respective Managers\r\n *\r\n * @param {(\"page\" | string)} type\r\n * @param {any} key\r\n * @returns App\r\n * @memberof App\r\n */\r\n public async load(type: \"page\" | string, key: any): Promise {\r\n switch (type.toLowerCase()) {\r\n case \"page\":\r\n return await this.pages.load(key);\r\n default:\r\n return Promise.resolve(this.get(type, key));\r\n }\r\n }\r\n\r\n /**\r\n * Adds a Service to the App's instance of the ServiceManager, with a name\r\n *\r\n * @param {string} key\r\n * @param {Service} service\r\n * @returns App\r\n * @memberof App\r\n */\r\n public setService(key: string, service: Service): App {\r\n this.services.set(key, service);\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a Service to the App's instance of the ServiceManager, with a name\r\n *\r\n * @param {string} key\r\n * @param {ITransition} tranisition\r\n * @returns App\r\n * @memberof App\r\n */\r\n public setTransition(key: string, transition: ITransition): App {\r\n this.transitions.set(key, transition);\r\n return this;\r\n }\r\n\r\n /**\r\n * Based on the type, it will add either a Transition, a Service, or a State to their respective Managers\r\n *\r\n * @param {(\"service\" | \"transition\" | \"state\")} type\r\n * @param {any} value\r\n * @returns App\r\n * @memberof App\r\n */\r\n public add(type: \"service\" | \"transition\" | \"state\", value: any): App {\r\n switch (type.toLowerCase()) {\r\n case \"service\":\r\n this.services.add(value);\r\n break;\r\n case \"transition\":\r\n this.transitions.set(value.name, value);\r\n break;\r\n case \"state\":\r\n this.history.add(value);\r\n break;\r\n default:\r\n throw `Error: can't add type '${type}', it is not a recognized type. Did you spell it correctly.`;\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Start the App and the ServiceManager\r\n *\r\n * @returns App\r\n * @memberof App\r\n */\r\n public boot(): App {\r\n this.services.init();\r\n this.services.boot();\r\n return this;\r\n }\r\n\r\n /**\r\n * Stop the App and the ServiceManager\r\n *\r\n * @returns App\r\n * @memberof App\r\n */\r\n public stop(): App {\r\n this.services.stop();\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter on method\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} callback\r\n * @returns App\r\n * @memberof App\r\n */\r\n public on(events: EventInput, callback?: ListenerCallback): App {\r\n this.emitter.on(events, callback, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter off method\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} callback\r\n * @returns App\r\n * @memberof App\r\n */\r\n public off(events: EventInput, callback?: ListenerCallback): App {\r\n this.emitter.off(events, callback, this);\r\n return this;\r\n }\r\n\r\n /**\r\n * A shortcut to the App EventEmitter emit method\r\n *\r\n * @param {(string | any[])} events\r\n * @param {...any} args\r\n * @returns App\r\n * @memberof App\r\n */\r\n public emit(events: string | any[], ...args: any): App {\r\n this.emitter.emit(events, ...args);\r\n return this;\r\n }\r\n}\r\n", "import { Service } from \"./service\";\r\nimport { Manager } from \"./manager\";\r\nimport { newURL, getHashedPath } from \"./url\";\r\n\r\nexport type RouteMethod = (...args: any) => any;\r\nexport type RouteStyle = string | RegExp | boolean;\r\nexport interface IRouteToFrom {\r\n to: RouteStyle,\r\n from: RouteStyle\r\n}\r\nexport type RoutePath = IRouteToFrom | RouteStyle;\r\nexport interface IRoute {\r\n path: RoutePath,\r\n method: RouteMethod\r\n}\r\n\r\n/**\r\n * Controls what happens when certain url paths match a set of criteria\r\n *\r\n * @export\r\n * @class Router\r\n * @extends {Service}\r\n */\r\nexport class Router extends Service {\r\n /**\r\n * List of routes inputted\r\n *\r\n * @protected\r\n * @type {Manager}\r\n * @memberof Router\r\n */\r\n protected routes: Manager;\r\n\r\n /**\r\n * Creates an instance of Router.\r\n *\r\n * @param {Array} [routes=[]]\r\n * @memberof Router\r\n */\r\n constructor(routes: IRoute[] = []) {\r\n super();\r\n this.routes = new Manager();\r\n for (let route of routes) {\r\n this.add(route);\r\n }\r\n }\r\n\r\n /**\r\n * Add a new route to watch for\r\n *\r\n * @param {IRoute} { path, method }\r\n * @returns {Router}\r\n * @memberof Router\r\n */\r\n public add({ path, method }: IRoute): Router {\r\n let key = this.parse(path);\r\n this.routes.set(key, method);\r\n return this;\r\n }\r\n\r\n /**\r\n * Convert strings into path match functions\r\n *\r\n * @param {RouteStyle} path\r\n * @returns {RegExp | boolean}\r\n * @memberof Router\r\n */\r\n public parsePath(path: RouteStyle): RegExp | boolean {\r\n if (typeof path === \"string\") return new RegExp(path, \"i\");\r\n else if (path instanceof RegExp || typeof path === \"boolean\")\r\n return path;\r\n throw \"[Router] only regular expressions, strings and booleans are accepted as paths.\";\r\n }\r\n\r\n /**\r\n * Determines if a strings counts has a path\r\n *\r\n * @param {RouteStyle} input\r\n * @returns boolean\r\n * @memberof Router\r\n */\r\n public isPath(input: RouteStyle): boolean {\r\n return (\r\n typeof input === \"string\" ||\r\n input instanceof RegExp ||\r\n typeof input === \"boolean\"\r\n );\r\n }\r\n\r\n /**\r\n * Parse the multiple different formats for paths, into a { from, to } object\r\n *\r\n * @param {RouteStyle} input\r\n * @returns {IRouteToFrom}\r\n * @memberof Router\r\n */\r\n public parse(input: RoutePath): IRouteToFrom {\r\n let route = input as IRouteToFrom;\r\n let toFromPath: IRouteToFrom = {\r\n from: /(.*)/g,\r\n to: /(.*)/g,\r\n };\r\n\r\n if (this.isPath(input as RouteStyle))\r\n toFromPath = {\r\n from: true,\r\n to: input as RouteStyle,\r\n };\r\n else if (this.isPath(route.from) && this.isPath(route.to as RouteStyle))\r\n toFromPath = route;\r\n else\r\n throw \"[Router] path is neither a string, regular expression, or a { from, to } object.\";\r\n\r\n let { from, to } = toFromPath;\r\n return {\r\n from: this.parsePath(from),\r\n to: this.parsePath(to),\r\n };\r\n }\r\n\r\n /**\r\n * Test if route paths are true, if so run their methods\r\n *\r\n * @memberof Router\r\n */\r\n public route() {\r\n let history = this.HistoryManager;\r\n let from: string = getHashedPath(newURL((history.length > 1 ? history.previous : history.current).url));\r\n let to: string = getHashedPath(newURL());\r\n\r\n this.routes.forEach((method: RouteMethod, path: IRouteToFrom) => {\r\n let fromRegExp = path.from as RegExp | boolean;\r\n let toRegExp = path.to as RegExp | boolean;\r\n\r\n if (\r\n typeof fromRegExp === \"boolean\" &&\r\n typeof toRegExp === \"boolean\"\r\n ) {\r\n throw `[Router] path ({ from: ${fromRegExp}, to: ${toRegExp} }) is not valid, remember paths can only be strings, regular expressions, or a boolean; however, both the from and to paths cannot be both booleans.`;\r\n }\r\n\r\n let fromParam: RegExpExecArray | RegExp | boolean = fromRegExp;\r\n let toParam: RegExpExecArray | RegExp | boolean = toRegExp;\r\n\r\n if (fromRegExp instanceof RegExp && fromRegExp.test(from))\r\n fromParam = fromRegExp.exec(from);\r\n if (toRegExp instanceof RegExp && toRegExp.test(to))\r\n toParam = toRegExp.exec(to);\r\n\r\n if (\r\n (Array.isArray(toParam) && Array.isArray(fromParam)) ||\r\n (Array.isArray(toParam) &&\r\n typeof fromParam == \"boolean\" &&\r\n fromParam) ||\r\n (Array.isArray(fromParam) &&\r\n typeof toParam == \"boolean\" &&\r\n toParam)\r\n )\r\n method({ from: fromParam, to: toParam, path: { from, to } });\r\n });\r\n }\r\n\r\n /**\r\n * Add listeners for PJAX Events\r\n *\r\n * @memberof Router\r\n */\r\n public initEvents() {\r\n this.emitter.on(\"READY\", this.route, this);\r\n this.emitter.on(\"CONTENT_REPLACED\", this.route, this);\r\n }\r\n\r\n /**\r\n * Remove listeners for PJAX Events\r\n *\r\n * @memberof Router\r\n */\r\n public stopEvents() {\r\n this.emitter.off(\"READY\", this.route, this);\r\n this.emitter.off(\"CONTENT_REPLACED\", this.route, this);\r\n }\r\n}\r\n", "import { EventEmitter, EventInput, ListenerCallback } from \"@okikio/emitter\";\r\n\r\n// DOM\r\nexport type AnimationTarget = string | Node | NodeList | HTMLCollection | HTMLElement[] | any[];\r\nexport const getElements = (selector: string | Node): Node[] => {\r\n return typeof selector === \"string\" ? Array.from(document.querySelectorAll(selector as string)) : [selector];\r\n};\r\n\r\nexport const getTargets = (targets: AnimationTarget): Node[] => {\r\n if (Array.isArray(targets)) return targets;\r\n if (typeof targets == \"string\" || targets instanceof Node)\r\n return getElements(targets);\r\n if (targets instanceof NodeList || targets instanceof HTMLCollection)\r\n return Array.from(targets);\r\n return [];\r\n};\r\n\r\n// VALUES\r\nexport type closureArgs = [number, number, HTMLElement];\r\nexport type closure = ((index?: number, total?: number, element?: HTMLElement) => any) | any;\r\nexport const computeValue = (value: closure, args: closureArgs) => {\r\n if (typeof value === \"function\") {\r\n return value(...args);\r\n } else { return value; }\r\n};\r\n\r\nexport const mapObject = (obj: object, args: closureArgs): any => {\r\n let key, value, result = {};\r\n let keys = Object.keys(obj);\r\n for (let i = 0, len = keys.length; i < len; i++) {\r\n key = keys[i];\r\n value = obj[key];\r\n result[key] = computeValue(value, args);\r\n }\r\n\r\n return result;\r\n};\r\n\r\n// From: [https://easings.net]\r\nexport const easings = {\r\n \"ease\": \"ease\",\r\n \"in\": \"ease-in\",\r\n \"out\": \"ease-out\",\r\n \"in-out\": \"ease-in-out\",\r\n\r\n // Sine\r\n \"in-sine\": \"cubic-bezier(0.47, 0, 0.745, 0.715)\",\r\n \"out-sine\": \"cubic-bezier(0.39, 0.575, 0.565, 1)\",\r\n \"in-out-sine\": \"cubic-bezier(0.445, 0.05, 0.55, 0.95)\",\r\n\r\n // Quad\r\n \"in-quad\": \"cubic-bezier(0.55, 0.085, 0.68, 0.53)\",\r\n \"out-quad\": \"cubic-bezier(0.25, 0.46, 0.45, 0.94)\",\r\n \"in-out-quad\": \"cubic-bezier(0.455, 0.03, 0.515, 0.955)\",\r\n\r\n // Cubic\r\n \"in-cubic\": \"cubic-bezier(0.55, 0.055, 0.675, 0.19)\",\r\n \"out-cubic\": \"cubic-bezier(0.215, 0.61, 0.355, 1)\",\r\n \"in-out-cubic\": \"cubic-bezier(0.645, 0.045, 0.355, 1)\",\r\n\r\n // Quart\r\n \"in-quart\": \"cubic-bezier(0.895, 0.03, 0.685, 0.22)\",\r\n \"out-quart\": \"cubic-bezier(0.165, 0.84, 0.44, 1)\",\r\n \"in-out-quart\": \"cubic-bezier(0.77, 0, 0.175, 1)\",\r\n\r\n // Quint\r\n \"in-quint\": \"cubic-bezier(0.755, 0.05, 0.855, 0.06)\",\r\n \"out-quint\": \"cubic-bezier(0.23, 1, 0.32, 1)\",\r\n \"in-out-quint\": \"cubic-bezier(0.86, 0, 0.07, 1)\",\r\n\r\n // Expo\r\n \"in-expo\": \"cubic-bezier(0.95, 0.05, 0.795, 0.035)\",\r\n \"out-expo\": \"cubic-bezier(0.19, 1, 0.22, 1)\",\r\n \"in-out-expo\": \"cubic-bezier(1, 0, 0, 1)\",\r\n\r\n // Circ\r\n \"in-circ\": \"cubic-bezier(0.6, 0.04, 0.98, 0.335)\",\r\n \"out-circ\": \"cubic-bezier(0.075, 0.82, 0.165, 1)\",\r\n \"in-out-circ\": \"cubic-bezier(0.785, 0.135, 0.15, 0.86)\",\r\n\r\n // Back\r\n \"in-back\": \"cubic-bezier(0.6, -0.28, 0.735, 0.045)\",\r\n \"out-back\": \"cubic-bezier(0.175, 0.885, 0.32, 1.275)\",\r\n \"in-out-back\": \"cubic-bezier(0.68, -0.55, 0.265, 1.55)\"\r\n};\r\nexport const getEase = (ease: string) => {\r\n return /^(ease|in|out)/.test(ease) ? easings[ease] : ease;\r\n};\r\n\r\nexport interface AnimationOptions {\r\n target?: AnimationTarget,\r\n\r\n speed?: number | closure,\r\n delay?: number | closure,\r\n easing?: string | closure,\r\n endDelay?: number | closure,\r\n duration?: number | closure,\r\n autoplay?: boolean | closure,\r\n keyframes?: object[] | closure,\r\n loop?: number | boolean | closure, // iterations: number,\r\n options?: AnimationOptions | closure,\r\n onfinish?: (element?: HTMLElement, index?: number, total?: number) => any,\r\n fillMode?: \"none\" | \"forwards\" | \"backwards\" | \"both\" | \"auto\" | closure,\r\n direction?: \"normal\" | \"reverse\" | \"alternate\" | \"alternate-reverse\" | closure,\r\n [property: string]: closure | boolean | object | string | string[] | number | null | (number | null)[] | undefined;\r\n};\r\n\r\nexport const DefaultAnimationOptions: AnimationOptions = {\r\n keyframes: [],\r\n\r\n loop: 1, // iterations: number,\r\n delay: 0,\r\n speed: 1,\r\n endDelay: 0,\r\n easing: \"ease\",\r\n autoplay: true,\r\n duration: 1000,\r\n onfinish() { },\r\n fillMode: \"auto\",\r\n direction: \"normal\",\r\n};\r\n\r\n// You can check it out here: https://codepen.io/okikio/pen/qBbdGaW?editors=0011\r\nexport class Animate {\r\n /**\r\n * Stores the options for the current animation\r\n *\r\n * @public\r\n * @type AnimationOptions\r\n * @memberof Animate\r\n */\r\n public options: AnimationOptions = {};\r\n\r\n /**\r\n * The Array of Elements to Animate\r\n *\r\n * @public\r\n * @type {Node[]}\r\n * @memberof Animate\r\n */\r\n public targets: Node[] = [];\r\n\r\n /**\r\n * The properties to animate\r\n *\r\n * @public\r\n * @type {object}\r\n * @memberof Animate\r\n */\r\n public properties: object = {};\r\n\r\n /**\r\n * A Set of Animations\r\n *\r\n * @public\r\n * @type {Map}\r\n * @memberof Animate\r\n */\r\n public animations: Map = new Map();\r\n\r\n /**\r\n * The total duration of all Animation's\r\n *\r\n * @public\r\n * @type {number}\r\n * @memberof Animate\r\n */\r\n public duration: number = 0;\r\n\r\n /**\r\n * The Element the main animation uses\r\n *\r\n * @public\r\n * @type {HTMLElement}\r\n * @memberof Animate\r\n */\r\n public mainElement: HTMLElement;\r\n\r\n /**\r\n * Stores an animation that runs on the total duration of the all other Animations, and as such it's the main Animation\r\n *\r\n * @public\r\n * @type {Animation}\r\n * @memberof Animate\r\n */\r\n public mainAnimation: Animation;\r\n\r\n /**\r\n * Stores request frame calls\r\n *\r\n * @public\r\n * @type {number}\r\n * @memberof Animate\r\n */\r\n public animationFrame: number;\r\n\r\n /**\r\n * An event emitter\r\n *\r\n * @public\r\n * @type {EventEmitter}\r\n * @memberof Animate\r\n */\r\n public emitter: EventEmitter = new EventEmitter();\r\n\r\n /**\r\n * The finish method, is called when the main animation has finished\r\n *\r\n * @public\r\n * @type {*}\r\n * @memberof Animate\r\n */\r\n public finish: any;\r\n\r\n /**\r\n * Returns a promise that is fulfilled when the mainAnimation is finished\r\n *\r\n * @public\r\n * @type {Promise}\r\n * @memberof Animate\r\n */\r\n public promise: Promise;\r\n\r\n /**\r\n * Creates an instance of Animate.\r\n *\r\n * @param {AnimationOptions} options\r\n * @memberof Animate\r\n */\r\n constructor(options: AnimationOptions = {}) {\r\n let { options: animation, ...rest } = options;\r\n this.options = Object.assign({}, DefaultAnimationOptions, animation, rest);\r\n this.loop = this.loop.bind(this);\r\n\r\n let {\r\n loop,\r\n delay,\r\n speed,\r\n easing,\r\n endDelay,\r\n duration,\r\n direction,\r\n fillMode,\r\n onfinish,\r\n target,\r\n keyframes,\r\n autoplay,\r\n ...properties\r\n } = this.options;\r\n\r\n this.mainElement = document.createElement(\"span\");\r\n this.targets = getTargets(target);\r\n this.properties = properties;\r\n\r\n let animationKeyframe: Keyframe[] | PropertyIndexedKeyframes;\r\n for (let i = 0, len = this.targets.length; i < len; i++) {\r\n let target = this.targets[i] as HTMLElement;\r\n let animationOptions = {\r\n easing: getEase(easing),\r\n iterations: loop === true ? Infinity : (loop as number),\r\n direction,\r\n endDelay,\r\n duration,\r\n delay,\r\n fill: fillMode,\r\n };\r\n\r\n // Accept keyframes as a keyframes Object, or a method,\r\n // if there are no animations in the keyframes array,\r\n // uses css properties from the options object\r\n let arrKeyframes = computeValue((keyframes as Keyframe[]), [i, len, target]);\r\n animationKeyframe = arrKeyframes.length ? arrKeyframes :\r\n (this.properties as PropertyIndexedKeyframes);\r\n\r\n // Allows the use of functions as the values, for both the keyframes and the animation object\r\n // It adds the capability of advanced stagger animation, similar to the anime js stagger functions\r\n animationOptions = mapObject(animationOptions, [i, len, target]);\r\n if (!(arrKeyframes.length > 0))\r\n animationKeyframe = mapObject(animationKeyframe, [i, len, target]);\r\n\r\n // Set the Animate classes duration to be the Animation with the largest totalDuration\r\n let tempDuration: number =\r\n animationOptions.delay +\r\n (animationOptions.duration * animationOptions.iterations) +\r\n animationOptions.endDelay;\r\n if (this.duration < tempDuration) this.duration = tempDuration;\r\n\r\n // Add animation to the Animations Set\r\n let animation = target.animate(animationKeyframe, animationOptions);\r\n animation.onfinish = () => {\r\n onfinish(target, i, len);\r\n };\r\n this.animations.set(target, animation);\r\n }\r\n\r\n this.mainAnimation = this.mainElement.animate([\r\n { opacity: \"0\" },\r\n { opacity: \"1\" }\r\n ], {\r\n duration: this.duration,\r\n easing: \"linear\"\r\n });\r\n\r\n this.setSpeed(speed);\r\n if (autoplay) this.play();\r\n else this.pause();\r\n\r\n this.promise = this.newPromise();\r\n this.mainAnimation.onfinish = () => {\r\n this.finish(this.options);\r\n window.cancelAnimationFrame(this.animationFrame);\r\n };\r\n }\r\n\r\n /**\r\n * Returns the Array of targets\r\n *\r\n * @returns {Node[]}\r\n * @memberof Animate\r\n */\r\n public getTargets(): Node[] {\r\n return this.targets;\r\n }\r\n\r\n /**\r\n * Returns a new Promise that is resolve when this.finish is called\r\n *\r\n * @public\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public newPromise(): Promise {\r\n return new Promise((resolve, reject) => {\r\n try {\r\n this.finish = (options: AnimationOptions) => {\r\n this.emit(\"finish\", options);\r\n return resolve(options);\r\n };\r\n } catch (err) { reject(err); }\r\n });\r\n }\r\n\r\n /**\r\n * Fulfills the this.promise Promise\r\n *\r\n * @param {(value?: any) => any} [onFulfilled]\r\n * @param {(reason?: any) => any} [onRejected]\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public then(\r\n onFulfilled?: (value?: any) => any,\r\n onRejected?: (reason?: any) => any\r\n ): Promise {\r\n return this.promise.then(onFulfilled, onRejected);\r\n }\r\n\r\n /**\r\n * Catches error that occur in the this.promise Promise\r\n *\r\n * @param {(reason?: any) => any} onRejected\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public catch(onRejected: (reason?: any) => any): Promise {\r\n return this.promise.catch(onRejected);\r\n }\r\n\r\n /**\r\n * If you don't care if the this.promise Promise has either been rejected or resolved\r\n *\r\n * @param {() => any} onFinally\r\n * @returns {Promise}\r\n * @memberof Animate\r\n */\r\n public finally(onFinally: () => any): Promise {\r\n return this.promise.finally(onFinally);\r\n }\r\n\r\n /**\r\n * Represents an Animation Frame Loop\r\n *\r\n * @public\r\n * @memberof Animate\r\n */\r\n public loop(): void {\r\n this.animationFrame = window.requestAnimationFrame(this.loop);\r\n this.emit(\"tick change\", this.getCurrentTime());\r\n }\r\n\r\n /**\r\n * Adds a listener for a given event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public on(events: EventInput, callback?: ListenerCallback, scope?: object): Animate {\r\n this.emitter.on(events, callback, scope);\r\n return this;\r\n }\r\n\r\n /**\r\n * Removes a listener from an event\r\n *\r\n * @param {EventInput} events\r\n * @param {ListenerCallback} [callback]\r\n * @param {object} [scope]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public off(events: EventInput, callback?: ListenerCallback, scope?: object): Animate {\r\n this.emitter.off(events, callback, scope);\r\n return this;\r\n }\r\n\r\n /**\r\n * Call all listeners within an event\r\n *\r\n * @param {(string | any[])} events\r\n * @param {...any} args\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public emit(events: string | any[], ...args: any): Animate {\r\n this.emitter.emit(events, ...args);\r\n return this;\r\n }\r\n\r\n /**\r\n * Get a specific Animation from an Animate instance\r\n *\r\n * @param {HTMLElement} element\r\n * @returns {Animation}\r\n * @memberof Animate\r\n */\r\n public getAnimation(element: HTMLElement): Animation {\r\n return this.animations.get(element);\r\n }\r\n\r\n /**\r\n * Play Animation's\r\n *\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public play(): Animate {\r\n // Once the animation is done, it's done, it can only be paused by the reset method\r\n if (this.mainAnimation.playState !== \"finished\") {\r\n this.mainAnimation.play();\r\n this.animationFrame = requestAnimationFrame(this.loop);\r\n this.animations.forEach(animation => {\r\n if (animation.playState !== \"finished\") animation.play();\r\n });\r\n this.emit(\"play\");\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Pause Animation's\r\n *\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public pause(): Animate {\r\n // Once the animation is done, it's done, it can only be reset by the reset method\r\n if (this.mainAnimation.playState !== \"finished\") {\r\n this.mainAnimation.pause();\r\n window.cancelAnimationFrame(this.animationFrame);\r\n this.animations.forEach(animation => {\r\n if (animation.playState !== \"finished\") animation.pause();\r\n });\r\n this.emit(\"pause\");\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the total duration of all Animations\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getDuration(): number {\r\n return this.duration;\r\n }\r\n\r\n /**\r\n * Returns the current time of the Main Animation\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getCurrentTime(): number {\r\n return this.mainAnimation.currentTime;\r\n }\r\n\r\n /**\r\n * Set the current time of the Main Animation\r\n *\r\n * @param {number} time\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setCurrentTime(time: number): Animate {\r\n this.mainAnimation.currentTime = time;\r\n this.animations.forEach(animation => {\r\n animation.currentTime = time;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the Animation progress as a fraction of the current time / duration\r\n *\r\n * @returns\r\n * @memberof Animate\r\n */\r\n public getProgress() {\r\n return this.getCurrentTime() / this.duration;\r\n }\r\n\r\n /**\r\n * Set the Animation progress as a fraction of the current time / duration\r\n *\r\n * @param {number} percent\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setProgress(percent: number): Animate {\r\n this.mainAnimation.currentTime = percent * this.duration;\r\n this.animations.forEach(animation => {\r\n animation.currentTime = percent * this.duration;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Return the playback speed of the animation\r\n *\r\n * @returns {number}\r\n * @memberof Animate\r\n */\r\n public getSpeed(): number {\r\n return this.mainAnimation.playbackRate;\r\n }\r\n\r\n /**\r\n * Set the playback speed of an Animation\r\n *\r\n * @param {number} [speed=1]\r\n * @returns {Animate}\r\n * @memberof Animate\r\n */\r\n public setSpeed(speed: number = 1): Animate {\r\n this.mainAnimation.playbackRate = speed;\r\n this.animations.forEach(animation => {\r\n animation.playbackRate = speed;\r\n });\r\n return this;\r\n }\r\n\r\n /**\r\n * Reset all Animations\r\n *\r\n * @memberof Animate\r\n */\r\n public reset() {\r\n this.setCurrentTime(0);\r\n this.promise = this.newPromise();\r\n\r\n if (this.options.autoplay) this.play();\r\n else this.pause();\r\n }\r\n\r\n /**\r\n * Returns the current playing state\r\n *\r\n * @returns {(\"idle\" | \"running\" | \"paused\" | \"finished\")}\r\n * @memberof Animate\r\n */\r\n public getPlayState(): \"idle\" | \"running\" | \"paused\" | \"finished\" {\r\n return this.mainAnimation.playState;\r\n }\r\n\r\n /**\r\n * Get the options of an Animate instance\r\n *\r\n * @returns {AnimationOptions}\r\n * @memberof Animate\r\n */\r\n public getOptions(): AnimationOptions {\r\n return this.options;\r\n }\r\n\r\n // Returns the Animate options, as JSON\r\n public toJSON(): AnimationOptions {\r\n return this.getOptions();\r\n }\r\n}\r\n\r\n// Creates a new Animate instance\r\nexport const animate = (options: AnimationOptions = {}): Animate => {\r\n return new Animate(options);\r\n};\r\n\r\nexport default animate;\r\n"], + "mappings": "gIAAA,uoBCcO,IAAM,EAA2B,CACpC,YAAa,UACb,eAAgB,eAChB,eAAgB,cAChB,QAAS,CACL,CAAC,YAAa,SAElB,gBAAiB,iBACjB,eAAgB,gBAChB,eAAgB,aAChB,UAAW,QACX,QAAS,OAzBb,MAoDI,eACI,KAAK,OAAS,OAAO,OAAO,IAAK,GAAmB,GAWjD,WAA0C,IAC7C,IAAM,UAAW,KAAK,SACX,OAAO,EAAS,IAAM,EAAS,MAAM,IAChD,MAAO,GAAW,IAAI,KAAU,EAW7B,cAAkD,IACrD,GAAI,MAAO,IAAU,SACjB,MAAO,MAAK,OAEhB,MAAa,KAAK,OAAO,GACzB,MAAI,OAAO,IAAW,SACX,KAAK,OAAO,EAAQ,GACxB,ICrFf,IAAA,QAwBC,eACC,KAAK,IAAM,GAAI,KAAI,GASb,SACN,MAAO,MAAK,IAUN,OACN,MAAO,MAAK,IAAI,IAAI,GASd,OACN,MAAO,OAAM,KAAK,KAAK,IAAI,QASrB,SACN,MAAO,OAAM,KAAK,KAAK,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