diff --git a/dts.tsconfig.json b/dts.tsconfig.json
new file mode 100644
index 0000000..fcfb516
--- /dev/null
+++ b/dts.tsconfig.json
@@ -0,0 +1,21 @@
+{
+ "compilerOptions": {
+ "moduleResolution": "node",
+ "target": "ES2020",
+ "module": "ES2020",
+ "sourceMap": false,
+ "declaration": true,
+ "incremental": true,
+ "declarationDir": "lib/types",
+ "emitDeclarationOnly": true,
+ "isolatedModules": true,
+ "esModuleInterop": true
+ },
+ "include": [
+ "**/src/**/*"
+ ],
+ "exclude": [
+ "node_modules",
+ "**/tests/**/*"
+ ]
+}
diff --git a/package.json b/package.json
index 88d6564..1e56f74 100644
--- a/package.json
+++ b/package.json
@@ -6,20 +6,21 @@
"packages/*"
],
"scripts": {
- "build": "ultra -r build",
- "docs:build": "ultra -r docs:build",
- "docs:watch": "pnpm run --parallel -r docs:watch",
+ "build": "ultra --parallel -r build",
+ "docs:build": "pnpm --parallel -r docs:build",
+ "docs:watch": "ultra --parallel -r docs:watch",
+ "dts": "ultra -r --parallel --filter \"packages/*\" dts",
"test": "ultra -r test",
- "test:watch": "pnpm run --parallel -r test:watch",
- "prepublishOnly": "ultra -r pre-release",
- "release": "ultra prepublish && lerna version && pnpm -r publish --tag latest"
+ "test:watch": "ultra --parallel -r test:watch",
+ "pre-release": "ultra -r pre-release",
+ "release": "npm run pre-release && lerna version && pnpm -r publish --tag latest"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
- "@types/jest": "^26.0.16",
+ "@types/jest": "^26.0.18",
"browser-sync": "^2.26.13",
- "esbuild": "^0.8.20",
+ "esbuild": "^0.8.21",
"esbuild-jest": "^0.3.0",
"gulp": "^4.0.2",
"jest": "^26.6.3",
@@ -27,6 +28,7 @@
"lerna": "^3.22.1",
"merge-stream": "^2.0.0",
"pnpm": "^5.13.5",
+ "typescript": "^4.1.2",
"ultra-runner": "^3.6.0"
}
}
diff --git a/packages/animate/dts.tsconfig.json b/packages/animate/dts.tsconfig.json
new file mode 100644
index 0000000..e577d2b
--- /dev/null
+++ b/packages/animate/dts.tsconfig.json
@@ -0,0 +1,10 @@
+{
+ "extends": "../../dts.tsconfig.json",
+ "include": [
+ "**/src/**/*"
+ ],
+ "exclude": [
+ "node_modules",
+ "**/tests/**/*"
+ ]
+}
diff --git a/packages/animate/package.json b/packages/animate/package.json
index 035fee2..fa7a93e 100644
--- a/packages/animate/package.json
+++ b/packages/animate/package.json
@@ -5,11 +5,12 @@
"publishConfig": {
"access": "public",
"main": "lib/api.js",
- "types": "lib/api.d.ts",
+ "types": "lib/types/api.d.ts",
"browser": "lib/api.js",
"node": "lib/api.node.js",
"unpkg": "lib/api.js",
- "module": "lib/api.modern.js"
+ "module": "lib/api.modern.js",
+ "exports": "lib/api.modern.js"
},
"main": "src/api.ts",
"source": "src/api.ts",
@@ -23,9 +24,8 @@
"scripts": {
"build": "node ./build",
"watch": "node ./build --watch",
- "test": "jest --maxWorkers=1",
- "test:watch": "jest --maxWorkers=1 --watch --verbose false",
- "pre-release": "npm run build && ultra docs:build",
+ "dts": "tsc --project dts.tsconfig.json",
+ "pre-release": "npm run build && npm run dts && npm run docs:build",
"docs:build": "gulp build",
"docs:watch": "gulp default --watch"
},
@@ -53,18 +53,19 @@
},
"homepage": "https://github.com/okikio/native#readme",
"devDependencies": {
- "@types/jest": "^26.0.16",
+ "@types/jest": "^26.0.18",
"browser-sync": "^2.26.13",
- "esbuild": "^0.8.20",
+ "esbuild": "^0.8.21",
"esbuild-jest": "^0.3.0",
"eslint": "^7.15.0",
"gulp": "^4.0.2",
- "gulp-esbuild": "^0.3.2",
+ "gulp-esbuild": "^0.3.4",
"gulp-pug": "^4.0.1",
"gulp-sass": "^4.1.0",
"jest": "^26.6.3",
"jest-chain": "^1.1.5",
"merge-stream": "^2.0.0",
+ "typescript": "^4.1.2",
"ultra-runner": "^3.6.0"
},
"dependencies": {
diff --git a/packages/animate/tests/test.ts b/packages/animate/tests/test.ts
deleted file mode 100644
index 2209550..0000000
--- a/packages/animate/tests/test.ts
+++ /dev/null
@@ -1,84 +0,0 @@
-///
-import { Animate } from "../src/api";
-import "jest-chain";
-
-/*
- Find: @(returns|type) \{([\w_-{,<[\]\s>]+)\}
- Replace: @$1 $2
-*/
-
-describe("Animate", () => {
- let animation: Animate;
-
- // beforeEach(() => {
- // animation = new Animate({
- // target: ".div",
- // keyframes(index: number, total: number, element: HTMLElement) {
- // return [
- // { transform: "translateX(0px)", opacity: 0 },
- // { transform: "translateX(300px)", opacity: ((index + 1) / total) }
- // ]
- // },
- // transform: ["translateX(0px)", "translateX(300px)"],
- // easing: "out-cubic",
- // opacity(index: number, total: number, element: HTMLElement) {
- // return [0, ((index + 1) / total)];
- // },
- // duration(index: number) {
- // return (index + 1) * 500;
- // },
- // onfinish(element: HTMLElement, index: number, total: number) {
- // element.style.opacity = `${((index + 1) / total)}`;
- // element.style.transform = "translateX(300px)";
- // },
- // loop: 5,
- // speed: 1,
- // direction: "alternate",
- // delay(index: number) {
- // return index * 200;
- // },
- // autoplay: true,
- // endDelay: 500
- // });
- // });
-
- describe("#constructor()", () => {
- test("argument and options", () => {
- let div = {
- document: true
- };
- console.log(div);
- // expect(animation).toBeInstanceOf(Animate);
- // expect(animation.getOptions()).toEqual({
- // target: ".div",
- // keyframes(index: number, total: number, element: HTMLElement) {
- // return [
- // { transform: "translateX(0px)", opacity: 0 },
- // { transform: "translateX(300px)", opacity: ((index + 1) / total) }
- // ]
- // },
- // transform: ["translateX(0px)", "translateX(300px)"],
- // easing: "out-cubic",
- // opacity(index: number, total: number, element: HTMLElement) {
- // return [0, ((index + 1) / total)];
- // },
- // duration(index: number) {
- // return (index + 1) * 500;
- // },
- // onfinish(element: HTMLElement, index: number, total: number) {
- // element.style.opacity = `${((index + 1) / total)}`;
- // element.style.transform = "translateX(300px)";
- // },
- // loop: 5,
- // speed: 1,
- // direction: "alternate",
- // delay(index: number) {
- // return index * 200;
- // },
- // autoplay: true,
- // endDelay: 500
- // });
- });
- });
-
-});
diff --git a/packages/emitter/dts.tsconfig.json b/packages/emitter/dts.tsconfig.json
new file mode 100644
index 0000000..e577d2b
--- /dev/null
+++ b/packages/emitter/dts.tsconfig.json
@@ -0,0 +1,10 @@
+{
+ "extends": "../../dts.tsconfig.json",
+ "include": [
+ "**/src/**/*"
+ ],
+ "exclude": [
+ "node_modules",
+ "**/tests/**/*"
+ ]
+}
diff --git a/packages/emitter/package.json b/packages/emitter/package.json
index b32777a..376e492 100644
--- a/packages/emitter/package.json
+++ b/packages/emitter/package.json
@@ -5,11 +5,12 @@
"publishConfig": {
"access": "public",
"main": "lib/api.js",
- "types": "lib/api.d.ts",
+ "types": "lib/types/api.d.ts",
"browser": "lib/api.js",
"node": "lib/api.node.js",
"unpkg": "lib/api.js",
- "module": "lib/api.modern.js"
+ "module": "lib/api.modern.js",
+ "exports": "lib/api.modern.js"
},
"main": "src/api.ts",
"source": "src/api.ts",
@@ -25,7 +26,8 @@
"watch": "node ./build --watch",
"test": "jest --maxWorkers=1",
"test:watch": "jest --maxWorkers=1 --watch --verbose false",
- "pre-release": "npm run build && npm test"
+ "dts": "tsc --project dts.tsconfig.json",
+ "pre-release": "npm run build && npm test && npm run dts"
},
"repository": {
"type": "git",
@@ -50,13 +52,14 @@
},
"homepage": "https://github.com/okikio/native#readme",
"devDependencies": {
- "@types/jest": "^26.0.16",
+ "@types/jest": "^26.0.18",
"chokidar": "^3.4.3",
- "esbuild": "^0.8.20",
+ "esbuild": "^0.8.21",
"esbuild-jest": "^0.3.0",
"eslint": "^7.15.0",
"jest": "^26.6.3",
"jest-chain": "^1.1.5",
+ "typescript": "^4.1.2",
"ultra-runner": "^3.6.0"
},
"dependencies": {
diff --git a/packages/manager/dts.tsconfig.json b/packages/manager/dts.tsconfig.json
new file mode 100644
index 0000000..e577d2b
--- /dev/null
+++ b/packages/manager/dts.tsconfig.json
@@ -0,0 +1,10 @@
+{
+ "extends": "../../dts.tsconfig.json",
+ "include": [
+ "**/src/**/*"
+ ],
+ "exclude": [
+ "node_modules",
+ "**/tests/**/*"
+ ]
+}
diff --git a/packages/manager/package.json b/packages/manager/package.json
index c286784..e8c4e72 100644
--- a/packages/manager/package.json
+++ b/packages/manager/package.json
@@ -5,11 +5,12 @@
"publishConfig": {
"access": "public",
"main": "lib/api.js",
- "types": "lib/api.d.ts",
+ "types": "lib/types/api.d.ts",
"browser": "lib/api.js",
"node": "lib/api.node.js",
"unpkg": "lib/api.js",
- "module": "lib/api.modern.js"
+ "module": "lib/api.modern.js",
+ "exports": "lib/api.modern.js"
},
"main": "src/api.ts",
"source": "src/api.ts",
@@ -25,7 +26,8 @@
"watch": "node ./build --watch",
"test": "jest --maxWorkers=1",
"test:watch": "jest --maxWorkers=1 --watch --verbose false",
- "pre-release": "npm run build && npm test"
+ "dts": "tsc --project dts.tsconfig.json",
+ "pre-release": "npm run build && npm test && npm run dts"
},
"repository": {
"type": "git",
@@ -51,14 +53,15 @@
},
"homepage": "https://github.com/okikio/native#readme",
"devDependencies": {
- "@types/jest": "^26.0.16",
+ "@types/jest": "^26.0.18",
"chokidar": "^3.4.3",
- "esbuild": "^0.8.20",
+ "esbuild": "^0.8.21",
"esbuild-jest": "^0.3.0",
"eslint": "^7.15.0",
"jest": "^26.6.3",
"jest-chain": "^1.1.5",
"node-fetch": "^2.6.1",
+ "typescript": "^4.1.2",
"ultra-runner": "^3.6.0"
},
"gitHead": "ad422076cdb57d570426f786886129d5bca2f90f"
diff --git a/packages/native/build-src/ts/services/Splashscreen.ts b/packages/native/build-src/ts/services/Splashscreen.ts
index 2f68394..9ce46b1 100644
--- a/packages/native/build-src/ts/services/Splashscreen.ts
+++ b/packages/native/build-src/ts/services/Splashscreen.ts
@@ -27,14 +27,14 @@ export class Splashscreen extends Service {
}
public async hide() {
- await new Promise(resolve => {
+ await new Promise(resolve => {
window.setTimeout(() => {
this.emitter.emit("BEFORE_SPLASHSCREEN_HIDE");
resolve();
}, this.minimalDuration);
});
- await new Promise(async resolve => {
+ await new Promise(async resolve => {
animate({
target: this.innerEl,
opacity: [1, 0],
diff --git a/packages/native/build-src/ts/transitions/BigTransition.ts b/packages/native/build-src/ts/transitions/BigTransition.ts
index c390e93..fa06bfd 100644
--- a/packages/native/build-src/ts/transitions/BigTransition.ts
+++ b/packages/native/build-src/ts/transitions/BigTransition.ts
@@ -23,7 +23,7 @@ export const BigTransition: ITransition = {
// behavior: 'smooth' // 👈
// });
- return new Promise(async resolve => {
+ return new Promise(async resolve => {
animate({
target: fromWrapper,
opacity: [1, 0],
@@ -86,7 +86,7 @@ export const BigTransition: ITransition = {
window.scroll(scroll.x, scroll.y);
- return new Promise(async resolve => {
+ return new Promise(async resolve => {
animate({
target: toWrapper,
opacity: [0, 1],
diff --git a/packages/native/build-src/ts/transitions/Fade.ts b/packages/native/build-src/ts/transitions/Fade.ts
index 2a769f8..8dc9e75 100644
--- a/packages/native/build-src/ts/transitions/Fade.ts
+++ b/packages/native/build-src/ts/transitions/Fade.ts
@@ -9,7 +9,7 @@ export const Fade: ITransition = {
out({ from }: ITransitionData) {
let { duration } = this;
let fromWrapper = from.wrapper;
- return new Promise(async resolve => {
+ return new Promise(async resolve => {
await animate({
target: fromWrapper,
opacity: [1, 0],
diff --git a/packages/native/docs/js/main.js b/packages/native/docs/js/main.js
index 4eadb5f..1eeb648 100644
--- a/packages/native/docs/js/main.js
+++ b/packages/native/docs/js/main.js
@@ -1,3 +1,3 @@
-var pt={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},M=class{constructor(t){this.config=Object.assign({...pt},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 h=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()}},x=(r,t,...e)=>{r.forEach(i=>{i[t](...e)})},I=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}},v=class extends h{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}`,W=r=>r.toString().replace(/(\/#.*|\/|#.*)$/,""),C=(r,t)=>{let e=p(r),i=p(t);return W(e)===W(i)};var S=(r=window.scrollX,t=window.scrollY)=>({x:r,y:t}),k=(r={url:m(p()),index:0,transition:"default",data:{scroll:S(),trigger:"HistoryManager"}})=>r,F=class{constructor(){this.pointer=-1;this.states=[];let t=k();this.add(t,"replace")}get(t){return this.states[t]}add(t,e="push"){let i=k(t),n=this.length;this.states.push({...i}),this.pointer=n;let a={index:this.pointer,states:[...this.states]};return ct(e,i,a),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}},ct=(r,t,e)=>{let i=m(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 ut=new DOMParser,A=class extends I{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=ut.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}},D=class extends v{constructor(t){super(t);this.loading=new h;this.maxPages=5;let e=p().pathname;this.set(e,new A),e=void 0}async load(t=p()){let e=p(t),i=e.pathname,n,a;if(this.has(i))return n=this.get(i),Promise.resolve(n);this.loading.has(i)?a=this.loading.get(i):(a=this.request(i),this.loading.set(i,a));let o=await a;if(this.loading.delete(i),n=new A(e,o),this.set(i,n),this.size>this.maxPages){let s=p(),l=this.keys(),u=C(s,l[0])?l[1]:l[0],f=this.get(u);f.unregister(),f=void 0,l=void 0,s=void 0,u=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 a=new Error(n.statusText||""+n.status);throw a}catch(n){throw window.clearTimeout(i),n}}};var J=({callback:r=()=>{},scope:t=null,name:e="event"})=>({callback:r,scope:t,name:e}),L=class extends h{constructor(t="event"){super();this.name=t}},P=class extends h{constructor(){super()}getEvent(t){let e=this.get(t);return e instanceof L?e:(this.set(t,new L(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,a,o=typeof t=="object"&&!Array.isArray(t),s=o?e:i;return o||(a=e),Object.keys(t).forEach(l=>{o?(n=l,a=t[l]):n=t[l],this.newListener(n,a,s)},this),this}removeListener(t,e,i){let n=this.get(t);if(n instanceof L&&e){let a=J({name:t,callback:e,scope:i});n.forEach((o,s)=>{if(o.callback===a.callback&&o.scope===a.scope)return n.delete(s)})}return n}off(t,e,i){if(typeof t=="undefined")return this;typeof t=="string"&&(t=t.trim().split(/\s/g));let n,a,o=typeof t=="object"&&!Array.isArray(t),s=o?e:i;return o||(a=e),Object.keys(t).forEach(l=>{o?(n=l,a=t[l]):n=t[l],typeof a=="function"?this.removeListener(n,a,s):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 L&&n.forEach(a=>{let{callback:o,scope:s}=a;o.apply(s,e)})},this),this)}};var g=class extends I{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()}},_=class extends v{constructor(t){super(t)}init(){return x(this,"init",this.app),this}boot(){return x(this,"boot",this.app),this}stop(){return x(this,"stop",this.app),this}};var K=class extends g{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,a=!t||!i,o=e.metaKey||e.ctrlKey||e.shiftKey||e.altKey,s=t.hasAttribute("target")&&t.target==="_blank",l=t.protocol!==location.protocol||t.hostname!==location.hostname,u=typeof t.getAttribute("download")=="string",f=t.hasAttribute(this.config.getConfig("preventSelfAttr",!1)),w=Boolean(t.closest(this.config.getConfig("preventAllAttr"))),y=f&&w,O=m(p())===m(p(i));return!(a||n||o||s||l||u||y||O)}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},a=this.HistoryManager.current,o=a.url;if(C(o,t))return;let s;if(i&&i.state){this.emitter.emit("POPSTATE",i);let{state:l}=i,{index:u}=l,f=a.index,w=f-u;e=this.getDirection(w);let y=this.HistoryManager.get(this.HistoryManager.pointer);s=y.transition,n=y.data.scroll,this.HistoryManager.replace(l.states),this.HistoryManager.pointer=u,e==="back"?this.emitter.emit("POPSTATE_BACK",i):e==="forward"&&this.emitter.emit("POPSTATE_FORWARD",i)}else{s=this.getTransitionName(e)||"default",n=S();let l=k({url:t,transition:s,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:o,href:t,trigger:e,transitionName:s,scroll:n})}async load({oldHref:t,href:e,trigger:i,transitionName:n="default",scroll:a={x:0,y:0}}){try{let o=await this.PageManager.load(t);await o.build();let s;this.emitter.emit("PAGE_LOADING",{href:e,oldPage:o,trigger:i});try{try{s=await this.PageManager.load(e),await s.build(),this.transitionStart(),this.emitter.emit("PAGE_LOAD_COMPLETE",{newPage:s,oldPage:o,trigger:i})}catch(l){console.error(`[PJAX] page load error: ${l}`)}this.emitter.emit("NAVIGATION_START",{oldPage:o,newPage:s,trigger:i,transitionName:n});try{this.emitter.emit("TRANSITION_START",n);let l=await this.TransitionManager.boot(n,{oldPage:o,newPage:s,trigger:i,scroll:a});l.scrollable||(/back|popstate|forward/.test(i)||(a=z()),window.scroll(a.x,a.y)),this.emitter.emit("TRANSITION_END",{transition:l})}catch(l){console.error(`[PJAX] transition error: ${l}`)}this.emitter.emit("NAVIGATION_END",{oldPage:o,newPage:s,trigger:i,transitionName:n})}catch(l){throw this.transitionStop(),l}this.transitionStop()}catch(o){this.forceOnError?this.force(e):console.error(o)}}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(a){console.warn("[PJAX] prefetch error,",a)}}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)}},z=(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 S(e.offsetLeft,e.offsetTop)}}catch(t){console.warn("hashAction error",t)}return S(0,0)},q=class extends h{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 A)||!(e.newPage instanceof A))throw`[Page] either oldPage or newPage aren't instances of the Page Class.
- ${{newPage:e.newPage,oldPage:e.oldPage}}`;let a=e.oldPage.wrapper,o=e.newPage.wrapper;if(document.title=""+e.newPage.title,!(a 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==null||i.init(e)),this.emitter.emit("BEFORE_TRANSITION_OUT"),await new Promise(s=>{let l=i.out.call(i,{...e,from:e.oldPage,trigger:e.trigger,done:s});l.then&&l.then(s)}),this.emitter.emit("AFTER_TRANSITION_OUT"),await new Promise(s=>{a.insertAdjacentElement("beforebegin",o),this.emitter.emit("CONTENT_INSERT"),/back|popstate|forward/.test(e.trigger)||(n=z()),s()}),await new Promise(s=>{a.remove(),a=void 0,o=void 0,this.emitter.emit("CONTENT_REPLACED"),s()}),this.emitter.emit("BEFORE_TRANSITION_IN"),await new Promise(s=>{let l=i.in.call(i,{...e,from:e.oldPage,to:e.newPage,trigger:e.trigger,scroll:n,done:s});l.then&&l.then(s)}),this.emitter.emit("AFTER_TRANSITION_IN"),i}};var j=class{constructor(t={}){this.register(t)}register(t={}){this.config=t instanceof M?t:new M(t),this.emitter=new P,this.history=new F,this.pages=new D(this),this.transitions=new q(this),this.services=new _(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 U=class extends g{constructor(t=[]){super();this.routes=new h;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:a}=i;return{from:this.parsePath(n),to:this.parsePath(a)}}route(){let t=this.HistoryManager,e=m(p((t.length>1?t.previous:t.current).url)),i=m(p());this.routes.forEach((n,a)=>{let o=a.from,s=a.to;if(typeof o=="boolean"&&typeof s=="boolean")throw`[Router] path ({ from: ${o}, to: ${s} }) 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=o,u=s;o instanceof RegExp&&o.test(e)&&(l=o.exec(e)),s instanceof RegExp&&s.test(i)&&(u=s.exec(i)),(Array.isArray(u)&&Array.isArray(l)||Array.isArray(u)&&typeof l=="boolean"&&l||Array.isArray(l)&&typeof u=="boolean"&&u)&&n({from:l,to:u,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 ht=r=>typeof r=="string"?Array.from(document.querySelectorAll(r)):[r],mt=r=>Array.isArray(r)?r:typeof r=="string"||r instanceof Node?ht(r):r instanceof NodeList||r instanceof HTMLCollection?Array.from(r):[],Q=(r,t)=>typeof r=="function"?r(...t):r,Z=(r,t)=>{let e,i,n={},a=Object.keys(r);for(let o=0,s=a.length;o/^(ease|in|out)/.test(r)?gt[r]:r,dt={keyframes:[],loop:1,delay:0,speed:1,endDelay:0,easing:"ease",autoplay:!0,duration:1e3,onfinish(){},fillMode:"auto",direction:"normal"},tt=class{constructor(t={}){this.options={};this.targets=[];this.properties={};this.animations=new Map;this.duration=0;this.emitter=new P;let{options:e,...i}=t;this.options=Object.assign({},dt,e,i),this.loop=this.loop.bind(this);let{loop:n,delay:a,speed:o,easing:s,endDelay:l,duration:u,direction:f,fillMode:w,onfinish:y,target:O,keyframes:ot,autoplay:at,...lt}=this.options;this.mainElement=document.createElement("span"),this.targets=mt(O),this.properties=lt;let R;for(let d=0,T=this.targets.length;d0||(R=Z(R,[d,T,E]));let B=b.delay+b.duration*b.iterations+b.endDelay;this.duration{y(E,d,T)},this.animations.set(E,Y)}this.mainAnimation=this.mainElement.animate([{opacity:"0"},{opacity:"1"}],{duration:this.duration,easing:"linear"}),this.setSpeed(o),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()}},c=(r={})=>new tt(r);var V=class extends g{constructor(){super(...arguments);this.minimalDuration=1e3}init(){super.init(),this.rootElement=document.getElementById("splashscreen"),this.rootElement&&(this.innerEl=this.rootElement.querySelector(".splashscreen-inner"),this.bgEl=this.rootElement.querySelector(".splashscreen-bg")),this.rootElement.style.visibility="visible",this.rootElement.style.pointerEvents="auto"}boot(){this.rootElement&&this.hide()}async hide(){await new Promise(t=>{window.setTimeout(()=>{this.emitter.emit("BEFORE_SPLASHSCREEN_HIDE"),t()},this.minimalDuration)}),await new Promise(async t=>{c({target:this.innerEl,opacity:[1,0],autoplay:!0,duration:500,onfinish(e){e.style.opacity="0"}}),this.emitter.emit("START_SPLASHSCREEN_HIDE"),await this.show(),t()})}async show(){await c({target:this.rootElement,transform:["translateY(0%)","translateY(100%)"],duration:1200,easing:"in-out-cubic"}),this.rootElement.style.transform="translateY(100%)",this.rootElement.style.visibility="hidden",this.rootElement.style.pointerEvents="none"}},G=class extends g{init(){super.init(),this.elements=[...document.querySelectorAll(".intro-animation")]}newPage(){this.init(),this.prepareToShow()}initEvents(){this.emitter.on("BEFORE_SPLASHSCREEN_HIDE",this.prepareToShow,this),this.emitter.on("CONTENT_REPLACED",this.newPage,this),this.emitter.on("START_SPLASHSCREEN_HIDE BEFORE_TRANSITION_IN",this.show,this)}stopEvents(){this.emitter.off("BEFORE_SPLASHSCREEN_HIDE",this.prepareToShow,this),this.emitter.off("CONTENT_REPLACED",this.newPage,this),this.emitter.off("START_SPLASHSCREEN_HIDE BEFORE_TRANSITION_IN",this.show,this)}stop(){requestAnimationFrame(()=>{for(let t of this.elements)t.style.transform="translateY(0px)",t.style.opacity="1"}),super.stop()}prepareToShow(){requestAnimationFrame(()=>{for(let t of this.elements)t.style.transform="translateY(200px)",t.style.opacity="0"})}async show(){return await c({target:this.elements,keyframes:[{transform:"translateY(200px)",opacity:0},{transform:"translateY(0px)",opacity:1}],delay(t){return 300*(t+1)},onfinish(t){requestAnimationFrame(()=>{t.style.transform="translateY(0px)",t.style.opacity="1"})},easing:"out-cubic",duration:650})}},et={name:"default",duration:500,scrollable:!0,out({from:r}){let{duration:t}=this,e=r.wrapper;return new Promise(async i=>{await c({target:e,opacity:[1,0],duration:t,onfinish(n){requestAnimationFrame(()=>{n.style.opacity="0"})}}),i()})},in({to:r,scroll:t}){let{duration:e}=this,i=r.wrapper;return requestAnimationFrame(()=>{i.style.transform="translateX(0%)"}),window.scroll(t.x,t.y),c({target:i,opacity:[0,1],duration:e,onfinish(n){requestAnimationFrame(()=>{n.style.opacity="1",n.style={}})}})}},it={name:"big",delay:200,durationPerAnimation:700,scrollable:!0,init(){this.mainElement=document.getElementById("big-transition"),this.spinnerElement=this.mainElement.querySelector(".spinner"),this.horizontalElements=[...this.mainElement.querySelector("#big-transition-horizontal").querySelectorAll("div")],this.maxLength=this.horizontalElements.length},out({from:r}){let{durationPerAnimation:t,delay:e}=this,i=r.wrapper;return new Promise(async n=>{c({target:i,opacity:[1,0],duration:t,onfinish(s){s.style.opacity="0"}}),this.mainElement.style.opacity="1",this.mainElement.style.visibility="visible",await c({target:this.horizontalElements,keyframes:[{transform:"scaleX(0)"},{transform:"scaleX(1)"}],delay(s){return e*(s+1)},onfinish(s){s.style.transform="scaleX(1)"},easing:"out-cubic",duration:500});let a=500;this.spinnerElement.style.visibility="visible";let o=await c({target:this.spinnerElement,opacity:[0,1],duration:a,onfinish(s){s.style.opacity="1"}});await c({options:o,opacity:[1,0],onfinish(s){s.style.opacity="0"},delay:1500}),this.spinnerElement.style.visibility="hidden",n()})},in({to:r,scroll:t}){let{durationPerAnimation:e,delay:i}=this,n=r.wrapper;return n.style.transform="translateX(0%)",window.scroll(t.x,t.y),new Promise(async a=>{c({target:n,opacity:[0,1],onfinish(o){o.style.opacity="1"},duration:e}),await c({target:this.horizontalElements,keyframes:[{transform:"scaleX(1)"},{transform:"scaleX(0)"}],delay(o){return i*(o+1)},onfinish(o){o.style.transform="scaleX(0)"},easing:"out-cubic",duration:500}),this.mainElement.style.opacity="0",this.mainElement.style.visibility="hidden",a()})}},H={name:"slide",duration:500,direction:"right",scrollable:!0,init(r){let t=r.trigger;t instanceof Node&&t.hasAttribute("data-direction")?this.direction=t.getAttribute("data-direction"):this.direction="right"},out({from:r}){let{duration:t,direction:e}=this,i=r.wrapper;return c({target:i,keyframes:[{transform:"translateX(0%)",opacity:1},{transform:`translateX(${e==="left"?"-":""}25%)`,opacity:0}],duration:t,easing:"in-quint",onfinish:n=>{requestAnimationFrame(()=>{n.style.opacity="0",n.style.transform=`translateX(${e==="left"?"-":""}25%)`})}})},in({to:r,scroll:t}){let{duration:e}=this,i=r.wrapper;return window.scroll(t.x,t.y),c({target:i,keyframes:[{transform:`translateX(${this.direction==="right"?"-":""}25%)`,opacity:0},{transform:"translateX(0%)",opacity:1}],duration:e,easing:"out-quint",onfinish(n){requestAnimationFrame(()=>{n.style.opacity="1",n.style.transform="translateX(0%)"})}})}},rt={...H,name:"slide-left",direction:"left"},nt={...H,name:"slide-right",direction:"right"},X=new j,st,$,bt;X.add("service",new G).add("service",st=new V).setService("router",$=new U).add("service",bt=new K).setTransition("default",et).add("transition",it).add("transition",H).add("transition",rt).add("transition",nt);try{$=X.get("service","router");let r=document.querySelectorAll(".navbar .nav-link");for(let t of r){let e=t;$.add({path:e.getAttribute("data-path")||e.pathname,method(){let i=e.classList.contains("active");i||e.classList.add("active");for(let n of r)n!==e&&n.classList.remove("active")}})}X.boot()}catch(r){st.show(),console.warn("[App] boot failed,",r)}
+var pt={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},M=class{constructor(t){this.config=Object.assign({...pt},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 h=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()}},v=(r,t,...e)=>{r.forEach(i=>{i[t](...e)})},x=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}},I=class extends h{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}`,W=r=>r.toString().replace(/(\/#.*|\/|#.*)$/,""),C=(r,t)=>{let e=p(r),i=p(t);return W(e)===W(i)};var S=(r=window.scrollX,t=window.scrollY)=>({x:r,y:t}),k=(r={url:m(p()),index:0,transition:"default",data:{scroll:S(),trigger:"HistoryManager"}})=>r,F=class{constructor(){this.pointer=-1;this.states=[];let t=k();this.add(t,"replace")}get(t){return this.states[t]}add(t,e="push"){let i=k(t),n=this.length;this.states.push({...i}),this.pointer=n;let a={index:this.pointer,states:[...this.states]};return ct(e,i,a),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}},ct=(r,t,e)=>{let i=m(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 ut=new DOMParser,A=class extends x{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=ut.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}},D=class extends I{constructor(t){super(t);this.loading=new h;this.maxPages=5;let e=p().pathname;this.set(e,new A),e=void 0}async load(t=p()){let e=p(t),i=e.pathname,n,a;if(this.has(i))return n=this.get(i),Promise.resolve(n);this.loading.has(i)?a=this.loading.get(i):(a=this.request(i),this.loading.set(i,a));let o=await a;if(this.loading.delete(i),n=new A(e,o),this.set(i,n),this.size>this.maxPages){let s=p(),l=this.keys(),u=C(s,l[0])?l[1]:l[0],f=this.get(u);f.unregister(),f=void 0,l=void 0,s=void 0,u=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 a=new Error(n.statusText||""+n.status);throw a}catch(n){throw window.clearTimeout(i),n}}};var J=({callback:r=()=>{},scope:t=null,name:e="event"})=>({callback:r,scope:t,name:e}),L=class extends h{constructor(t="event"){super();this.name=t}},P=class extends h{constructor(){super()}getEvent(t){let e=this.get(t);return e instanceof L?e:(this.set(t,new L(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,a,o=typeof t=="object"&&!Array.isArray(t),s=o?e:i;return o||(a=e),Object.keys(t).forEach(l=>{o?(n=l,a=t[l]):n=t[l],this.newListener(n,a,s)},this),this}removeListener(t,e,i){let n=this.get(t);if(n instanceof L&&e){let a=J({name:t,callback:e,scope:i});n.forEach((o,s)=>{if(o.callback===a.callback&&o.scope===a.scope)return n.delete(s)})}return n}off(t,e,i){if(typeof t=="undefined")return this;typeof t=="string"&&(t=t.trim().split(/\s/g));let n,a,o=typeof t=="object"&&!Array.isArray(t),s=o?e:i;return o||(a=e),Object.keys(t).forEach(l=>{o?(n=l,a=t[l]):n=t[l],typeof a=="function"?this.removeListener(n,a,s):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 L&&n.forEach(a=>{let{callback:o,scope:s}=a;o.apply(s,e)})},this),this)}};var g=class extends x{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()}},_=class extends I{constructor(t){super(t)}init(){return v(this,"init",this.app),this}boot(){return v(this,"boot",this.app),this}stop(){return v(this,"stop",this.app),this}};var K=class extends g{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,a=!t||!i,o=e.metaKey||e.ctrlKey||e.shiftKey||e.altKey,s=t.hasAttribute("target")&&t.target==="_blank",l=t.protocol!==location.protocol||t.hostname!==location.hostname,u=typeof t.getAttribute("download")=="string",f=t.hasAttribute(this.config.getConfig("preventSelfAttr",!1)),w=Boolean(t.closest(this.config.getConfig("preventAllAttr"))),y=f&&w,O=m(p())===m(p(i));return!(a||n||o||s||l||u||y||O)}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},a=this.HistoryManager.current,o=a.url;if(C(o,t))return;let s;if(i&&i.state){this.emitter.emit("POPSTATE",i);let{state:l}=i,{index:u}=l,f=a.index,w=f-u;e=this.getDirection(w);let y=this.HistoryManager.get(this.HistoryManager.pointer);s=y.transition,n=y.data.scroll,this.HistoryManager.replace(l.states),this.HistoryManager.pointer=u,e==="back"?this.emitter.emit("POPSTATE_BACK",i):e==="forward"&&this.emitter.emit("POPSTATE_FORWARD",i)}else{s=this.getTransitionName(e)||"default",n=S();let l=k({url:t,transition:s,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:o,href:t,trigger:e,transitionName:s,scroll:n})}async load({oldHref:t,href:e,trigger:i,transitionName:n="default",scroll:a={x:0,y:0}}){try{let o=await this.PageManager.load(t);await o.build();let s;this.emitter.emit("PAGE_LOADING",{href:e,oldPage:o,trigger:i});try{try{s=await this.PageManager.load(e),await s.build(),this.transitionStart(),this.emitter.emit("PAGE_LOAD_COMPLETE",{newPage:s,oldPage:o,trigger:i})}catch(l){console.error(`[PJAX] page load error: ${l}`)}this.emitter.emit("NAVIGATION_START",{oldPage:o,newPage:s,trigger:i,transitionName:n});try{this.emitter.emit("TRANSITION_START",n);let l=await this.TransitionManager.boot(n,{oldPage:o,newPage:s,trigger:i,scroll:a});l.scrollable||(/back|popstate|forward/.test(i)||(a=z()),window.scroll(a.x,a.y)),this.emitter.emit("TRANSITION_END",{transition:l})}catch(l){console.error(`[PJAX] transition error: ${l}`)}this.emitter.emit("NAVIGATION_END",{oldPage:o,newPage:s,trigger:i,transitionName:n})}catch(l){throw this.transitionStop(),l}this.transitionStop()}catch(o){this.forceOnError?this.force(e):console.error(o)}}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(a){console.warn("[PJAX] prefetch error,",a)}}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)}},z=(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 S(e.offsetLeft,e.offsetTop)}}catch(t){console.warn("hashAction error",t)}return S(0,0)},q=class extends h{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 A)||!(e.newPage instanceof A))throw`[Page] either oldPage or newPage aren't instances of the Page Class.
+ ${{newPage:e.newPage,oldPage:e.oldPage}}`;let a=e.oldPage.wrapper,o=e.newPage.wrapper;if(document.title=""+e.newPage.title,!(a 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==null||i.init(e)),this.emitter.emit("BEFORE_TRANSITION_OUT"),await new Promise(s=>{let l=i.out.call(i,{...e,from:e.oldPage,trigger:e.trigger,done:s});l.then&&l.then(s)}),this.emitter.emit("AFTER_TRANSITION_OUT"),await new Promise(s=>{a.insertAdjacentElement("beforebegin",o),this.emitter.emit("CONTENT_INSERT"),/back|popstate|forward/.test(e.trigger)||(n=z()),s()}),await new Promise(s=>{a.remove(),a=void 0,o=void 0,this.emitter.emit("CONTENT_REPLACED"),s()}),this.emitter.emit("BEFORE_TRANSITION_IN"),await new Promise(async s=>{let l=i.in.call(i,{...e,from:e.oldPage,to:e.newPage,trigger:e.trigger,scroll:n,done:s});l.then&&l.then(s)}),this.emitter.emit("AFTER_TRANSITION_IN"),i}};var j=class{constructor(t={}){this.register(t)}register(t={}){this.config=t instanceof M?t:new M(t),this.emitter=new P,this.history=new F,this.pages=new D(this),this.transitions=new q(this),this.services=new _(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 U=class extends g{constructor(t=[]){super();this.routes=new h;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:a}=i;return{from:this.parsePath(n),to:this.parsePath(a)}}route(){let t=this.HistoryManager,e=m(p((t.length>1?t.previous:t.current).url)),i=m(p());this.routes.forEach((n,a)=>{let o=a.from,s=a.to;if(typeof o=="boolean"&&typeof s=="boolean")throw`[Router] path ({ from: ${o}, to: ${s} }) 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=o,u=s;o instanceof RegExp&&o.test(e)&&(l=o.exec(e)),s instanceof RegExp&&s.test(i)&&(u=s.exec(i)),(Array.isArray(u)&&Array.isArray(l)||Array.isArray(u)&&typeof l=="boolean"&&l||Array.isArray(l)&&typeof u=="boolean"&&u)&&n({from:l,to:u,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 ht=r=>typeof r=="string"?Array.from(document.querySelectorAll(r)):[r],mt=r=>Array.isArray(r)?r:typeof r=="string"||r instanceof Node?ht(r):r instanceof NodeList||r instanceof HTMLCollection?Array.from(r):[],Q=(r,t)=>typeof r=="function"?r(...t):r,Z=(r,t)=>{let e,i,n={},a=Object.keys(r);for(let o=0,s=a.length;o/^(ease|in|out)/.test(r)?gt[r]:r,dt={keyframes:[],loop:1,delay:0,speed:1,endDelay:0,easing:"ease",autoplay:!0,duration:1e3,onfinish(){},fillMode:"auto",direction:"normal"},tt=class{constructor(t={}){this.options={};this.targets=[];this.properties={};this.animations=new Map;this.duration=0;this.emitter=new P;let{options:e,...i}=t;this.options=Object.assign({},dt,e,i),this.loop=this.loop.bind(this);let{loop:n,delay:a,speed:o,easing:s,endDelay:l,duration:u,direction:f,fillMode:w,onfinish:y,target:O,keyframes:ot,autoplay:at,...lt}=this.options;this.mainElement=document.createElement("span"),this.targets=mt(O),this.properties=lt;let R;for(let d=0,T=this.targets.length;d0||(R=Z(R,[d,T,E]));let B=b.delay+b.duration*b.iterations+b.endDelay;this.duration{y(E,d,T)},this.animations.set(E,Y)}this.mainAnimation=this.mainElement.animate([{opacity:"0"},{opacity:"1"}],{duration:this.duration,easing:"linear"}),this.setSpeed(o),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()}},c=(r={})=>new tt(r);var V=class extends g{constructor(){super(...arguments);this.minimalDuration=1e3}init(){super.init(),this.rootElement=document.getElementById("splashscreen"),this.rootElement&&(this.innerEl=this.rootElement.querySelector(".splashscreen-inner"),this.bgEl=this.rootElement.querySelector(".splashscreen-bg")),this.rootElement.style.visibility="visible",this.rootElement.style.pointerEvents="auto"}boot(){this.rootElement&&this.hide()}async hide(){await new Promise(t=>{window.setTimeout(()=>{this.emitter.emit("BEFORE_SPLASHSCREEN_HIDE"),t()},this.minimalDuration)}),await new Promise(async t=>{c({target:this.innerEl,opacity:[1,0],autoplay:!0,duration:500,onfinish(e){e.style.opacity="0"}}),this.emitter.emit("START_SPLASHSCREEN_HIDE"),await this.show(),t()})}async show(){await c({target:this.rootElement,transform:["translateY(0%)","translateY(100%)"],duration:1200,easing:"in-out-cubic"}),this.rootElement.style.transform="translateY(100%)",this.rootElement.style.visibility="hidden",this.rootElement.style.pointerEvents="none"}},G=class extends g{init(){super.init(),this.elements=[...document.querySelectorAll(".intro-animation")]}newPage(){this.init(),this.prepareToShow()}initEvents(){this.emitter.on("BEFORE_SPLASHSCREEN_HIDE",this.prepareToShow,this),this.emitter.on("CONTENT_REPLACED",this.newPage,this),this.emitter.on("START_SPLASHSCREEN_HIDE BEFORE_TRANSITION_IN",this.show,this)}stopEvents(){this.emitter.off("BEFORE_SPLASHSCREEN_HIDE",this.prepareToShow,this),this.emitter.off("CONTENT_REPLACED",this.newPage,this),this.emitter.off("START_SPLASHSCREEN_HIDE BEFORE_TRANSITION_IN",this.show,this)}stop(){requestAnimationFrame(()=>{for(let t of this.elements)t.style.transform="translateY(0px)",t.style.opacity="1"}),super.stop()}prepareToShow(){requestAnimationFrame(()=>{for(let t of this.elements)t.style.transform="translateY(200px)",t.style.opacity="0"})}async show(){return await c({target:this.elements,keyframes:[{transform:"translateY(200px)",opacity:0},{transform:"translateY(0px)",opacity:1}],delay(t){return 300*(t+1)},onfinish(t){requestAnimationFrame(()=>{t.style.transform="translateY(0px)",t.style.opacity="1"})},easing:"out-cubic",duration:650})}},et={name:"default",duration:500,scrollable:!0,out({from:r}){let{duration:t}=this,e=r.wrapper;return new Promise(async i=>{await c({target:e,opacity:[1,0],duration:t,onfinish(n){requestAnimationFrame(()=>{n.style.opacity="0"})}}),i()})},in({to:r,scroll:t}){let{duration:e}=this,i=r.wrapper;return requestAnimationFrame(()=>{i.style.transform="translateX(0%)"}),window.scroll(t.x,t.y),c({target:i,opacity:[0,1],duration:e,onfinish(n){requestAnimationFrame(()=>{n.style.opacity="1",n.style={}})}})}},it={name:"big",delay:200,durationPerAnimation:700,scrollable:!0,init(){this.mainElement=document.getElementById("big-transition"),this.spinnerElement=this.mainElement.querySelector(".spinner"),this.horizontalElements=[...this.mainElement.querySelector("#big-transition-horizontal").querySelectorAll("div")],this.maxLength=this.horizontalElements.length},out({from:r}){let{durationPerAnimation:t,delay:e}=this,i=r.wrapper;return new Promise(async n=>{c({target:i,opacity:[1,0],duration:t,onfinish(s){s.style.opacity="0"}}),this.mainElement.style.opacity="1",this.mainElement.style.visibility="visible",await c({target:this.horizontalElements,keyframes:[{transform:"scaleX(0)"},{transform:"scaleX(1)"}],delay(s){return e*(s+1)},onfinish(s){s.style.transform="scaleX(1)"},easing:"out-cubic",duration:500});let a=500;this.spinnerElement.style.visibility="visible";let o=await c({target:this.spinnerElement,opacity:[0,1],duration:a,onfinish(s){s.style.opacity="1"}});await c({options:o,opacity:[1,0],onfinish(s){s.style.opacity="0"},delay:1500}),this.spinnerElement.style.visibility="hidden",n()})},in({to:r,scroll:t}){let{durationPerAnimation:e,delay:i}=this,n=r.wrapper;return n.style.transform="translateX(0%)",window.scroll(t.x,t.y),new Promise(async a=>{c({target:n,opacity:[0,1],onfinish(o){o.style.opacity="1"},duration:e}),await c({target:this.horizontalElements,keyframes:[{transform:"scaleX(1)"},{transform:"scaleX(0)"}],delay(o){return i*(o+1)},onfinish(o){o.style.transform="scaleX(0)"},easing:"out-cubic",duration:500}),this.mainElement.style.opacity="0",this.mainElement.style.visibility="hidden",a()})}},H={name:"slide",duration:500,direction:"right",scrollable:!0,init(r){let t=r.trigger;t instanceof Node&&t.hasAttribute("data-direction")?this.direction=t.getAttribute("data-direction"):this.direction="right"},out({from:r}){let{duration:t,direction:e}=this,i=r.wrapper;return c({target:i,keyframes:[{transform:"translateX(0%)",opacity:1},{transform:`translateX(${e==="left"?"-":""}25%)`,opacity:0}],duration:t,easing:"in-quint",onfinish:n=>{requestAnimationFrame(()=>{n.style.opacity="0",n.style.transform=`translateX(${e==="left"?"-":""}25%)`})}})},in({to:r,scroll:t}){let{duration:e}=this,i=r.wrapper;return window.scroll(t.x,t.y),c({target:i,keyframes:[{transform:`translateX(${this.direction==="right"?"-":""}25%)`,opacity:0},{transform:"translateX(0%)",opacity:1}],duration:e,easing:"out-quint",onfinish(n){requestAnimationFrame(()=>{n.style.opacity="1",n.style.transform="translateX(0%)"})}})}},rt={...H,name:"slide-left",direction:"left"},nt={...H,name:"slide-right",direction:"right"},X=new j,st,$,bt;X.add("service",new G).add("service",st=new V).setService("router",$=new U).add("service",bt=new K).setTransition("default",et).add("transition",it).add("transition",H).add("transition",rt).add("transition",nt);try{$=X.get("service","router");let r=document.querySelectorAll(".navbar .nav-link");for(let t of r){let e=t;$.add({path:e.getAttribute("data-path")||e.pathname,method(){let i=e.classList.contains("active");i||e.classList.add("active");for(let n of r)n!==e&&n.classList.remove("active")}})}X.boot()}catch(r){st.show(),console.warn("[App] boot failed,",r)}
//# sourceMappingURL=main.js.map
diff --git a/packages/native/docs/js/main.js.map b/packages/native/docs/js/main.js.map
index 7e8b0ce..dedf6c8 100644
--- a/packages/native/docs/js/main.js.map
+++ b/packages/native/docs/js/main.js.map
@@ -1,7 +1,7 @@
{
"version": 3,
"sources": ["src/config.ts", "../manager/src/api.ts", "src/manager.ts", "src/url.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", "build-src/ts/services/Splashscreen.ts", "build-src/ts/services/IntroAnimation.ts", "build-src/ts/transitions/Fade.ts", "build-src/ts/transitions/BigTransition.ts", "build-src/ts/transitions/Slide.ts", "build-src/ts/main.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", "/**\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", "import { Service, animate } from \"../../../src/api\";\r\n\r\nexport class Splashscreen extends Service {\r\n public rootElement: HTMLElement;\r\n public innerEl: HTMLElement;\r\n public bgEl: HTMLElement;\r\n public minimalDuration: number = 1000; // ms\r\n\r\n public init() {\r\n super.init();\r\n\r\n // Elements\r\n this.rootElement = document.getElementById('splashscreen');\r\n if (this.rootElement) {\r\n this.innerEl = this.rootElement.querySelector('.splashscreen-inner');\r\n this.bgEl = this.rootElement.querySelector('.splashscreen-bg');\r\n }\r\n\r\n this.rootElement.style.visibility = \"visible\";\r\n this.rootElement.style.pointerEvents = \"auto\";\r\n }\r\n\r\n public boot() {\r\n if (this.rootElement) {\r\n this.hide();\r\n }\r\n }\r\n\r\n public async hide() {\r\n await new Promise(resolve => {\r\n window.setTimeout(() => {\r\n this.emitter.emit(\"BEFORE_SPLASHSCREEN_HIDE\");\r\n resolve();\r\n }, this.minimalDuration);\r\n });\r\n\r\n await new Promise(async resolve => {\r\n animate({\r\n target: this.innerEl,\r\n opacity: [1, 0],\r\n autoplay: true,\r\n duration: 500,\r\n onfinish(el) {\r\n el.style.opacity = \"0\";\r\n }\r\n });\r\n\r\n this.emitter.emit(\"START_SPLASHSCREEN_HIDE\");\r\n\r\n await this.show();\r\n resolve();\r\n });\r\n }\r\n\r\n public async show() {\r\n await animate({\r\n target: this.rootElement,\r\n transform: [\"translateY(0%)\", \"translateY(100%)\"],\r\n duration: 1200,\r\n easing: \"in-out-cubic\" // in-out-cubic\r\n });\r\n\r\n this.rootElement.style.transform = \"translateY(100%)\";\r\n this.rootElement.style.visibility = \"hidden\";\r\n this.rootElement.style.pointerEvents = \"none\";\r\n }\r\n}\r\n", "import { Service, animate } from \"../../../src/api\";\r\n\r\nexport class IntroAnimation extends Service {\r\n public elements: Array;\r\n public rootElement: HTMLElement;\r\n\r\n public init() {\r\n super.init();\r\n\r\n // Elements\r\n this.elements = [...document.querySelectorAll('.intro-animation')];\r\n }\r\n\r\n public newPage() {\r\n this.init();\r\n this.prepareToShow();\r\n }\r\n\r\n public initEvents() {\r\n this.emitter.on(\"BEFORE_SPLASHSCREEN_HIDE\", this.prepareToShow, this);\r\n this.emitter.on(\"CONTENT_REPLACED\", this.newPage, this);\r\n this.emitter.on(\"START_SPLASHSCREEN_HIDE BEFORE_TRANSITION_IN\", this.show, this);\r\n }\r\n\r\n public stopEvents() {\r\n this.emitter.off(\"BEFORE_SPLASHSCREEN_HIDE\", this.prepareToShow, this);\r\n this.emitter.off(\"CONTENT_REPLACED\", this.newPage, this);\r\n this.emitter.off(\"START_SPLASHSCREEN_HIDE BEFORE_TRANSITION_IN\", this.show, this);\r\n }\r\n\r\n public stop() {\r\n requestAnimationFrame(() => {\r\n for (let el of this.elements) {\r\n (el as HTMLElement).style.transform = \"translateY(0px)\";\r\n (el as HTMLElement).style.opacity = '1';\r\n }\r\n });\r\n\r\n super.stop();\r\n }\r\n\r\n public prepareToShow() {\r\n requestAnimationFrame(() => {\r\n for (let el of this.elements) {\r\n (el as HTMLElement).style.transform = \"translateY(200px)\";\r\n (el as HTMLElement).style.opacity = '0';\r\n }\r\n });\r\n }\r\n\r\n public async show() {\r\n return await animate({\r\n target: (this.elements as HTMLElement[]),\r\n keyframes: [\r\n { transform: \"translateY(200px)\", opacity: 0 },\r\n { transform: \"translateY(0px)\", opacity: 1 },\r\n ],\r\n // @ts-ignore\r\n delay(i: number) {\r\n return 300 * (i + 1);\r\n },\r\n onfinish(el: { style: { transform: string; opacity: string; }; }) {\r\n requestAnimationFrame(() => {\r\n el.style.transform = \"translateY(0px)\";\r\n el.style.opacity = \"1\";\r\n });\r\n },\r\n easing: \"out-cubic\",\r\n duration: 650\r\n });\r\n }\r\n}\r\n// import { Block, IBlockInit, animate } from \"../../../src/api\";\r\n\r\n// //== Blocks\r\n// export class InViewBlock extends Block {\r\n// public observer: IntersectionObserver;\r\n// public observerOptions: { root: any; rootMargin: string; threshold?: number, thresholds?: Array; };\r\n// public imgs: HTMLElement[];\r\n// public direction: string;\r\n// public xPercent: number;\r\n// public inView: boolean = false;\r\n\r\n// public init(value: IBlockInit) {\r\n// super.init(value);\r\n\r\n// // Values\r\n// this.observerOptions = {\r\n// root: null,\r\n// rootMargin: '0px',\r\n// thresholds: Array.from(Array(20), (_nul, x) => (x + 1) / 20)\r\n// };\r\n\r\n// // Create observer\r\n// this.observer = new IntersectionObserver((entries: IntersectionObserverEntry[]) => {\r\n// this.onIntersectionCallback(entries);\r\n// }, this.observerOptions);\r\n\r\n// // Prepare values\r\n// this.imgs = [];\r\n// this.direction = \"right\";\r\n// this.xPercent = 30;\r\n\r\n// if (this.rootElement.hasAttribute('data-direction')) {\r\n// this.direction = this.rootElement.getAttribute('data-direction');\r\n// }\r\n\r\n// if (this.direction === 'left') {\r\n// this.xPercent = -this.xPercent;\r\n// }\r\n\r\n// // Find elements\r\n// this.imgs = [...this.rootElement.querySelectorAll('img')];\r\n\r\n// // Add block rootElement in the observer\r\n// this.observe();\r\n// }\r\n\r\n// public observe() {\r\n// this.observer.observe(this.rootElement);\r\n// }\r\n\r\n// public unobserve() {\r\n// this.observer.unobserve(this.rootElement);\r\n// }\r\n\r\n// public onScreen() {\r\n// animate({\r\n// target: this.rootElement,\r\n// transform: [`translateX(${this.xPercent}%)`, \"translateX(0%)\"],\r\n// opacity: [0, 1],\r\n// duration: 1500,\r\n// delay: 0.15,\r\n// easing: \"out-quint\",\r\n// onfinish(el) {\r\n// requestAnimationFrame(() => {\r\n// el.style.transform = \"translateX(0%)\";\r\n// el.style.opacity = \"1\";\r\n// });\r\n// },\r\n// });\r\n// }\r\n\r\n// public offScreen() {\r\n// requestAnimationFrame(() => {\r\n// this.rootElement.style.transform = `translateX(${this.xPercent}%)`;\r\n// this.rootElement.style.opacity = \"0\";\r\n// });\r\n// }\r\n\r\n// public onIntersectionCallback(entries: IntersectionObserverEntry[]) {\r\n// for (let entry of entries) {\r\n// if (entry.intersectionRatio > 0) {\r\n// this.onScreen();\r\n// } else {\r\n// this.offScreen();\r\n// }\r\n// }\r\n// }\r\n\r\n// public stopEvents() {\r\n// this.unobserve();\r\n// }\r\n// }\r\n", "import { ITransition, ITransitionData, animate, hashAction } from \"../../../src/api\";\r\n\r\n//== Transition\r\nexport const Fade: ITransition = {\r\n name: \"default\",\r\n duration: 500,\r\n scrollable: true,\r\n\r\n out({ from }: ITransitionData) {\r\n let { duration } = this;\r\n let fromWrapper = from.wrapper;\r\n return new Promise(async resolve => {\r\n await animate({\r\n target: fromWrapper,\r\n opacity: [1, 0],\r\n duration,\r\n onfinish(el: { style: { opacity: string } }) {\r\n requestAnimationFrame(() => {\r\n el.style.opacity = \"0\";\r\n });\r\n }\r\n });\r\n resolve();\r\n });\r\n },\r\n\r\n in({ to, scroll }: ITransitionData) {\r\n let { duration } = this;\r\n let toWrapper = to.wrapper;\r\n requestAnimationFrame(() => {\r\n toWrapper.style.transform = \"translateX(0%)\";\r\n });\r\n\r\n window.scroll(scroll.x, scroll.y);\r\n\r\n return animate({\r\n target: toWrapper,\r\n opacity: [0, 1],\r\n duration,\r\n onfinish(el: { style: { opacity?: string } }) {\r\n requestAnimationFrame(() => {\r\n el.style.opacity = \"1\";\r\n el.style = {};\r\n });\r\n }\r\n });\r\n }\r\n};\r\n// export class Fade extends Transition {\r\n// public name = \"default\";\r\n// public duration = 500;\r\n\r\n// out({ from }: ITransitionData) {\r\n// let { duration } = this;\r\n// let fromWrapper = from.wrapper;\r\n// return new Promise(async resolve => {\r\n// await animate({\r\n// target: fromWrapper,\r\n// opacity: [1, 0],\r\n// duration,\r\n// onfinish(el: { style: { opacity: string } }) {\r\n// requestAnimationFrame(() => {\r\n// el.style.opacity = \"0\";\r\n// });\r\n// }\r\n// });\r\n// resolve();\r\n// });\r\n// }\r\n\r\n// in({ to }: ITransitionData) {\r\n// let { duration } = this;\r\n// let toWrapper = to.wrapper;\r\n// requestAnimationFrame(() => {\r\n// toWrapper.style.transform = \"translateX(0%)\";\r\n// });\r\n\r\n// return animate({\r\n// target: toWrapper,\r\n// opacity: [0, 1],\r\n// duration,\r\n// onfinish(el: { style: { opacity?: string } }) {\r\n// requestAnimationFrame(() => {\r\n// el.style.opacity = \"1\";\r\n// el.style = {};\r\n// });\r\n// }\r\n// });\r\n// }\r\n// }\r\n", "import { ITransition, ITransitionData, animate, hashAction } from \"../../../src/api\";\r\n\r\n//== Transitions\r\nexport const BigTransition: ITransition = {\r\n name: \"big\",\r\n delay: 200,\r\n durationPerAnimation: 700,\r\n scrollable: true,\r\n\r\n init() {\r\n this.mainElement = document.getElementById('big-transition');\r\n this.spinnerElement = this.mainElement.querySelector('.spinner');\r\n this.horizontalElements = [...this.mainElement.querySelector('#big-transition-horizontal').querySelectorAll('div')];\r\n this.maxLength = this.horizontalElements.length;\r\n // console.log(this.mainElement);\r\n },\r\n\r\n out({ from }: ITransitionData) {\r\n let { durationPerAnimation: duration, delay } = this;\r\n let fromWrapper = from.wrapper;\r\n // window.scroll({\r\n // top: 0,\r\n // behavior: 'smooth' // \uD83D\uDC48\r\n // });\r\n\r\n return new Promise(async resolve => {\r\n animate({\r\n target: fromWrapper,\r\n opacity: [1, 0],\r\n duration,\r\n onfinish(el: { style: { opacity: string; }; }) {\r\n el.style.opacity = '0';\r\n }\r\n });\r\n\r\n this.mainElement.style.opacity = \"1\";\r\n this.mainElement.style.visibility = \"visible\";\r\n\r\n await animate({\r\n target: this.horizontalElements,\r\n keyframes: [\r\n { transform: \"scaleX(0)\" },\r\n { transform: \"scaleX(1)\" },\r\n ],\r\n // @ts-ignore\r\n delay(i: number) {\r\n return delay * (i + 1);\r\n },\r\n onfinish(el: { style: { transform: string; }; }) {\r\n el.style.transform = `scaleX(1)`;\r\n },\r\n easing: \"out-cubic\",\r\n duration: 500\r\n });\r\n\r\n let loaderDuration = 500;\r\n this.spinnerElement.style.visibility = \"visible\";\r\n\r\n let options = await animate({\r\n target: this.spinnerElement,\r\n opacity: [0, 1],\r\n duration: loaderDuration,\r\n onfinish(el: { style: { opacity: string; }; }) {\r\n el.style.opacity = `1`;\r\n },\r\n });\r\n\r\n await animate({\r\n options,\r\n opacity: [1, 0],\r\n onfinish(el: { style: { opacity: string; }; }) {\r\n el.style.opacity = `0`;\r\n },\r\n delay: 1500\r\n });\r\n\r\n this.spinnerElement.style.visibility = \"hidden\";\r\n resolve();\r\n });\r\n },\r\n\r\n in({ to, scroll }: ITransitionData) {\r\n let { durationPerAnimation: duration, delay } = this;\r\n let toWrapper = to.wrapper;\r\n toWrapper.style.transform = \"translateX(0%)\";\r\n\r\n window.scroll(scroll.x, scroll.y);\r\n\r\n return new Promise(async resolve => {\r\n animate({\r\n target: toWrapper,\r\n opacity: [0, 1],\r\n onfinish(el: { style: { opacity: string; }; }) {\r\n el.style.opacity = `1`;\r\n },\r\n duration\r\n });\r\n\r\n await animate({\r\n target: this.horizontalElements,\r\n keyframes: [\r\n { transform: \"scaleX(1)\" },\r\n { transform: \"scaleX(0)\" },\r\n ],\r\n // @ts-ignore\r\n delay(i: number) {\r\n return delay * (i + 1);\r\n },\r\n onfinish(el: { style: { transform: string; }; }) {\r\n el.style.transform = `scaleX(0)`;\r\n },\r\n easing: \"out-cubic\",\r\n duration: 500\r\n });\r\n\r\n this.mainElement.style.opacity = \"0\";\r\n this.mainElement.style.visibility = \"hidden\";\r\n resolve();\r\n });\r\n }\r\n}\r\n", "import { ITransition, ITransitionData, animate, hashAction } from \"../../../src/api\";\r\n\r\n//== Transitions\r\nexport const Slide: ITransition = {\r\n name: \"slide\",\r\n duration: 500,\r\n direction: \"right\",\r\n scrollable: true,\r\n\r\n init(data: ITransition) {\r\n let trigger = (data.trigger as HTMLElement);\r\n if (trigger instanceof Node && trigger.hasAttribute(\"data-direction\")) {\r\n this.direction = trigger.getAttribute(\"data-direction\");\r\n } else {\r\n this.direction = \"right\";\r\n }\r\n },\r\n\r\n out({ from }: ITransitionData) {\r\n let { duration, direction } = this;\r\n let fromWrapper = from.wrapper;\r\n\r\n return animate({\r\n target: fromWrapper,\r\n keyframes: [\r\n { transform: \"translateX(0%)\", opacity: 1 },\r\n { transform: `translateX(${direction === \"left\" ? \"-\" : \"\"}25%)`, opacity: 0 },\r\n ],\r\n duration,\r\n easing: \"in-quint\",\r\n onfinish: (el: { style: { opacity: string; transform: string; }; }) => {\r\n requestAnimationFrame(() => {\r\n el.style.opacity = '0';\r\n el.style.transform = `translateX(${direction === \"left\" ? \"-\" : \"\"}25%)`;\r\n });\r\n }\r\n });\r\n },\r\n\r\n in({ to, scroll }: ITransitionData) {\r\n let { duration } = this;\r\n let toWrapper = to.wrapper;\r\n\r\n window.scroll(scroll.x, scroll.y);\r\n\r\n return animate({\r\n target: toWrapper,\r\n keyframes: [\r\n { transform: `translateX(${this.direction === \"right\" ? \"-\" : \"\"}25%)`, opacity: 0 },\r\n { transform: \"translateX(0%)\", opacity: 1 },\r\n ],\r\n duration,\r\n easing: \"out-quint\",\r\n onfinish(el: { style: { opacity: string; transform: string; }; }) {\r\n requestAnimationFrame(() => {\r\n el.style.opacity = '1';\r\n el.style.transform = `translateX(0%)`;\r\n });\r\n }\r\n });\r\n }\r\n};\r\n\r\nexport const SlideLeft: ITransition = {\r\n ...Slide,\r\n\r\n name: \"slide-left\",\r\n direction: \"left\",\r\n};\r\n\r\nexport const SlideRight: ITransition = {\r\n ...Slide,\r\n\r\n name: \"slide-right\",\r\n direction: \"right\",\r\n};\r\n", "import { PJAX, App, Router } from \"../../src/api\";\r\n\r\nimport { Splashscreen } from \"./services/Splashscreen\";\r\nimport { IntroAnimation } from \"./services/IntroAnimation\";\r\n\r\nimport { Fade } from \"./transitions/Fade\";\r\nimport { BigTransition } from \"./transitions/BigTransition\";\r\nimport { Slide, SlideLeft, SlideRight } from \"./transitions/Slide\";\r\n\r\nconst app: App = new App();\r\nlet splashscreen: Splashscreen;\r\nlet router: Router, pjax: PJAX;\r\n\r\napp\r\n .add(\"service\", new IntroAnimation())\r\n .add(\"service\", splashscreen = new Splashscreen())\r\n .setService(\"router\", router = new Router())\r\n .add(\"service\", pjax = new PJAX())\r\n .setTransition(\"default\", Fade)\r\n .add(\"transition\", BigTransition)\r\n .add(\"transition\", Slide)\r\n .add(\"transition\", SlideLeft)\r\n .add(\"transition\", SlideRight);\r\n\r\ntry {\r\n router = app.get(\"service\", \"router\") as Router;\r\n\r\n // This isn't nessceary, but it changes the nav link in focus depending on the page\r\n let navLink = document.querySelectorAll(\".navbar .nav-link\");\r\n for (let item of navLink) {\r\n let navItem = (item as HTMLAnchorElement);\r\n router.add({\r\n path: navItem.getAttribute(\"data-path\") || navItem.pathname,\r\n method() {\r\n let isActive = navItem.classList.contains(\"active\");\r\n if (!isActive) navItem.classList.add(\"active\");\r\n for (let nav of navLink) {\r\n if (nav !== navItem)\r\n nav.classList.remove(\"active\");\r\n }\r\n }\r\n });\r\n }\r\n app.boot();\r\n} catch (err) {\r\n splashscreen.show();\r\n console.warn(\"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,KAClB,EAAG,MAAM,QAAU,IACnB,EAAG,MAAM,UAAY,2BAOH,IAC/B,EAEH,KAAM,aACN,UAAW,WAGwB,IAChC,EAEH,KAAM,cACN,UAAW,SCjET,EAAW,GAAI,WAIrB,EACK,IAAI,UAAW,GAAI,IACnB,IAAI,UAAW,GAAe,GAAI,IAClC,WAAW,SAAU,EAAS,GAAI,IAClC,IAAI,UAAW,GAAO,GAAI,IAC1B,cAAc,UAAW,IACzB,IAAI,aAAc,IAClB,IAAI,aAAc,GAClB,IAAI,aAAc,IAClB,IAAI,aAAc,IAEvB,IACI,EAAS,EAAI,IAAI,UAAW,UAG5B,MAAc,SAAS,iBAAiB,qBACxC,YAAiB,IACb,MAAe,EACf,EAAO,IAAI,CACP,KAAM,EAAQ,aAAa,cAAgB,EAAQ,SACnD,SACI,MAAe,EAAQ,UAAU,SAAS,UAC1C,AAAK,GAAU,EAAQ,UAAU,IAAI,UACrC,YAAgB,GACZ,AAAI,IAAQ,GACR,EAAI,UAAU,OAAO,aAKzC,EAAI,gBAEJ,GAAa,OACb,QAAQ,KAAK,qBAAsB",
+ "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", "/**\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(async (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", "import { Service, animate } from \"../../../src/api\";\r\n\r\nexport class Splashscreen extends Service {\r\n public rootElement: HTMLElement;\r\n public innerEl: HTMLElement;\r\n public bgEl: HTMLElement;\r\n public minimalDuration: number = 1000; // ms\r\n\r\n public init() {\r\n super.init();\r\n\r\n // Elements\r\n this.rootElement = document.getElementById('splashscreen');\r\n if (this.rootElement) {\r\n this.innerEl = this.rootElement.querySelector('.splashscreen-inner');\r\n this.bgEl = this.rootElement.querySelector('.splashscreen-bg');\r\n }\r\n\r\n this.rootElement.style.visibility = \"visible\";\r\n this.rootElement.style.pointerEvents = \"auto\";\r\n }\r\n\r\n public boot() {\r\n if (this.rootElement) {\r\n this.hide();\r\n }\r\n }\r\n\r\n public async hide() {\r\n await new Promise(resolve => {\r\n window.setTimeout(() => {\r\n this.emitter.emit(\"BEFORE_SPLASHSCREEN_HIDE\");\r\n resolve();\r\n }, this.minimalDuration);\r\n });\r\n\r\n await new Promise(async resolve => {\r\n animate({\r\n target: this.innerEl,\r\n opacity: [1, 0],\r\n autoplay: true,\r\n duration: 500,\r\n onfinish(el) {\r\n el.style.opacity = \"0\";\r\n }\r\n });\r\n\r\n this.emitter.emit(\"START_SPLASHSCREEN_HIDE\");\r\n\r\n await this.show();\r\n resolve();\r\n });\r\n }\r\n\r\n public async show() {\r\n await animate({\r\n target: this.rootElement,\r\n transform: [\"translateY(0%)\", \"translateY(100%)\"],\r\n duration: 1200,\r\n easing: \"in-out-cubic\" // in-out-cubic\r\n });\r\n\r\n this.rootElement.style.transform = \"translateY(100%)\";\r\n this.rootElement.style.visibility = \"hidden\";\r\n this.rootElement.style.pointerEvents = \"none\";\r\n }\r\n}\r\n", "import { Service, animate } from \"../../../src/api\";\r\n\r\nexport class IntroAnimation extends Service {\r\n public elements: Array;\r\n public rootElement: HTMLElement;\r\n\r\n public init() {\r\n super.init();\r\n\r\n // Elements\r\n this.elements = [...document.querySelectorAll('.intro-animation')];\r\n }\r\n\r\n public newPage() {\r\n this.init();\r\n this.prepareToShow();\r\n }\r\n\r\n public initEvents() {\r\n this.emitter.on(\"BEFORE_SPLASHSCREEN_HIDE\", this.prepareToShow, this);\r\n this.emitter.on(\"CONTENT_REPLACED\", this.newPage, this);\r\n this.emitter.on(\"START_SPLASHSCREEN_HIDE BEFORE_TRANSITION_IN\", this.show, this);\r\n }\r\n\r\n public stopEvents() {\r\n this.emitter.off(\"BEFORE_SPLASHSCREEN_HIDE\", this.prepareToShow, this);\r\n this.emitter.off(\"CONTENT_REPLACED\", this.newPage, this);\r\n this.emitter.off(\"START_SPLASHSCREEN_HIDE BEFORE_TRANSITION_IN\", this.show, this);\r\n }\r\n\r\n public stop() {\r\n requestAnimationFrame(() => {\r\n for (let el of this.elements) {\r\n (el as HTMLElement).style.transform = \"translateY(0px)\";\r\n (el as HTMLElement).style.opacity = '1';\r\n }\r\n });\r\n\r\n super.stop();\r\n }\r\n\r\n public prepareToShow() {\r\n requestAnimationFrame(() => {\r\n for (let el of this.elements) {\r\n (el as HTMLElement).style.transform = \"translateY(200px)\";\r\n (el as HTMLElement).style.opacity = '0';\r\n }\r\n });\r\n }\r\n\r\n public async show() {\r\n return await animate({\r\n target: (this.elements as HTMLElement[]),\r\n keyframes: [\r\n { transform: \"translateY(200px)\", opacity: 0 },\r\n { transform: \"translateY(0px)\", opacity: 1 },\r\n ],\r\n // @ts-ignore\r\n delay(i: number) {\r\n return 300 * (i + 1);\r\n },\r\n onfinish(el: { style: { transform: string; opacity: string; }; }) {\r\n requestAnimationFrame(() => {\r\n el.style.transform = \"translateY(0px)\";\r\n el.style.opacity = \"1\";\r\n });\r\n },\r\n easing: \"out-cubic\",\r\n duration: 650\r\n });\r\n }\r\n}\r\n// import { Block, IBlockInit, animate } from \"../../../src/api\";\r\n\r\n// //== Blocks\r\n// export class InViewBlock extends Block {\r\n// public observer: IntersectionObserver;\r\n// public observerOptions: { root: any; rootMargin: string; threshold?: number, thresholds?: Array; };\r\n// public imgs: HTMLElement[];\r\n// public direction: string;\r\n// public xPercent: number;\r\n// public inView: boolean = false;\r\n\r\n// public init(value: IBlockInit) {\r\n// super.init(value);\r\n\r\n// // Values\r\n// this.observerOptions = {\r\n// root: null,\r\n// rootMargin: '0px',\r\n// thresholds: Array.from(Array(20), (_nul, x) => (x + 1) / 20)\r\n// };\r\n\r\n// // Create observer\r\n// this.observer = new IntersectionObserver((entries: IntersectionObserverEntry[]) => {\r\n// this.onIntersectionCallback(entries);\r\n// }, this.observerOptions);\r\n\r\n// // Prepare values\r\n// this.imgs = [];\r\n// this.direction = \"right\";\r\n// this.xPercent = 30;\r\n\r\n// if (this.rootElement.hasAttribute('data-direction')) {\r\n// this.direction = this.rootElement.getAttribute('data-direction');\r\n// }\r\n\r\n// if (this.direction === 'left') {\r\n// this.xPercent = -this.xPercent;\r\n// }\r\n\r\n// // Find elements\r\n// this.imgs = [...this.rootElement.querySelectorAll('img')];\r\n\r\n// // Add block rootElement in the observer\r\n// this.observe();\r\n// }\r\n\r\n// public observe() {\r\n// this.observer.observe(this.rootElement);\r\n// }\r\n\r\n// public unobserve() {\r\n// this.observer.unobserve(this.rootElement);\r\n// }\r\n\r\n// public onScreen() {\r\n// animate({\r\n// target: this.rootElement,\r\n// transform: [`translateX(${this.xPercent}%)`, \"translateX(0%)\"],\r\n// opacity: [0, 1],\r\n// duration: 1500,\r\n// delay: 0.15,\r\n// easing: \"out-quint\",\r\n// onfinish(el) {\r\n// requestAnimationFrame(() => {\r\n// el.style.transform = \"translateX(0%)\";\r\n// el.style.opacity = \"1\";\r\n// });\r\n// },\r\n// });\r\n// }\r\n\r\n// public offScreen() {\r\n// requestAnimationFrame(() => {\r\n// this.rootElement.style.transform = `translateX(${this.xPercent}%)`;\r\n// this.rootElement.style.opacity = \"0\";\r\n// });\r\n// }\r\n\r\n// public onIntersectionCallback(entries: IntersectionObserverEntry[]) {\r\n// for (let entry of entries) {\r\n// if (entry.intersectionRatio > 0) {\r\n// this.onScreen();\r\n// } else {\r\n// this.offScreen();\r\n// }\r\n// }\r\n// }\r\n\r\n// public stopEvents() {\r\n// this.unobserve();\r\n// }\r\n// }\r\n", "import { ITransition, ITransitionData, animate, hashAction } from \"../../../src/api\";\r\n\r\n//== Transition\r\nexport const Fade: ITransition = {\r\n name: \"default\",\r\n duration: 500,\r\n scrollable: true,\r\n\r\n out({ from }: ITransitionData) {\r\n let { duration } = this;\r\n let fromWrapper = from.wrapper;\r\n return new Promise(async resolve => {\r\n await animate({\r\n target: fromWrapper,\r\n opacity: [1, 0],\r\n duration,\r\n onfinish(el: { style: { opacity: string } }) {\r\n requestAnimationFrame(() => {\r\n el.style.opacity = \"0\";\r\n });\r\n }\r\n });\r\n resolve();\r\n });\r\n },\r\n\r\n in({ to, scroll }: ITransitionData) {\r\n let { duration } = this;\r\n let toWrapper = to.wrapper;\r\n requestAnimationFrame(() => {\r\n toWrapper.style.transform = \"translateX(0%)\";\r\n });\r\n\r\n window.scroll(scroll.x, scroll.y);\r\n\r\n return animate({\r\n target: toWrapper,\r\n opacity: [0, 1],\r\n duration,\r\n onfinish(el: { style: { opacity?: string } }) {\r\n requestAnimationFrame(() => {\r\n el.style.opacity = \"1\";\r\n el.style = {};\r\n });\r\n }\r\n });\r\n }\r\n};\r\n// export class Fade extends Transition {\r\n// public name = \"default\";\r\n// public duration = 500;\r\n\r\n// out({ from }: ITransitionData) {\r\n// let { duration } = this;\r\n// let fromWrapper = from.wrapper;\r\n// return new Promise(async resolve => {\r\n// await animate({\r\n// target: fromWrapper,\r\n// opacity: [1, 0],\r\n// duration,\r\n// onfinish(el: { style: { opacity: string } }) {\r\n// requestAnimationFrame(() => {\r\n// el.style.opacity = \"0\";\r\n// });\r\n// }\r\n// });\r\n// resolve();\r\n// });\r\n// }\r\n\r\n// in({ to }: ITransitionData) {\r\n// let { duration } = this;\r\n// let toWrapper = to.wrapper;\r\n// requestAnimationFrame(() => {\r\n// toWrapper.style.transform = \"translateX(0%)\";\r\n// });\r\n\r\n// return animate({\r\n// target: toWrapper,\r\n// opacity: [0, 1],\r\n// duration,\r\n// onfinish(el: { style: { opacity?: string } }) {\r\n// requestAnimationFrame(() => {\r\n// el.style.opacity = \"1\";\r\n// el.style = {};\r\n// });\r\n// }\r\n// });\r\n// }\r\n// }\r\n", "import { ITransition, ITransitionData, animate, hashAction } from \"../../../src/api\";\r\n\r\n//== Transitions\r\nexport const BigTransition: ITransition = {\r\n name: \"big\",\r\n delay: 200,\r\n durationPerAnimation: 700,\r\n scrollable: true,\r\n\r\n init() {\r\n this.mainElement = document.getElementById('big-transition');\r\n this.spinnerElement = this.mainElement.querySelector('.spinner');\r\n this.horizontalElements = [...this.mainElement.querySelector('#big-transition-horizontal').querySelectorAll('div')];\r\n this.maxLength = this.horizontalElements.length;\r\n // console.log(this.mainElement);\r\n },\r\n\r\n out({ from }: ITransitionData) {\r\n let { durationPerAnimation: duration, delay } = this;\r\n let fromWrapper = from.wrapper;\r\n // window.scroll({\r\n // top: 0,\r\n // behavior: 'smooth' // \uD83D\uDC48\r\n // });\r\n\r\n return new Promise(async resolve => {\r\n animate({\r\n target: fromWrapper,\r\n opacity: [1, 0],\r\n duration,\r\n onfinish(el: { style: { opacity: string; }; }) {\r\n el.style.opacity = '0';\r\n }\r\n });\r\n\r\n this.mainElement.style.opacity = \"1\";\r\n this.mainElement.style.visibility = \"visible\";\r\n\r\n await animate({\r\n target: this.horizontalElements,\r\n keyframes: [\r\n { transform: \"scaleX(0)\" },\r\n { transform: \"scaleX(1)\" },\r\n ],\r\n // @ts-ignore\r\n delay(i: number) {\r\n return delay * (i + 1);\r\n },\r\n onfinish(el: { style: { transform: string; }; }) {\r\n el.style.transform = `scaleX(1)`;\r\n },\r\n easing: \"out-cubic\",\r\n duration: 500\r\n });\r\n\r\n let loaderDuration = 500;\r\n this.spinnerElement.style.visibility = \"visible\";\r\n\r\n let options = await animate({\r\n target: this.spinnerElement,\r\n opacity: [0, 1],\r\n duration: loaderDuration,\r\n onfinish(el: { style: { opacity: string; }; }) {\r\n el.style.opacity = `1`;\r\n },\r\n });\r\n\r\n await animate({\r\n options,\r\n opacity: [1, 0],\r\n onfinish(el: { style: { opacity: string; }; }) {\r\n el.style.opacity = `0`;\r\n },\r\n delay: 1500\r\n });\r\n\r\n this.spinnerElement.style.visibility = \"hidden\";\r\n resolve();\r\n });\r\n },\r\n\r\n in({ to, scroll }: ITransitionData) {\r\n let { durationPerAnimation: duration, delay } = this;\r\n let toWrapper = to.wrapper;\r\n toWrapper.style.transform = \"translateX(0%)\";\r\n\r\n window.scroll(scroll.x, scroll.y);\r\n\r\n return new Promise(async resolve => {\r\n animate({\r\n target: toWrapper,\r\n opacity: [0, 1],\r\n onfinish(el: { style: { opacity: string; }; }) {\r\n el.style.opacity = `1`;\r\n },\r\n duration\r\n });\r\n\r\n await animate({\r\n target: this.horizontalElements,\r\n keyframes: [\r\n { transform: \"scaleX(1)\" },\r\n { transform: \"scaleX(0)\" },\r\n ],\r\n // @ts-ignore\r\n delay(i: number) {\r\n return delay * (i + 1);\r\n },\r\n onfinish(el: { style: { transform: string; }; }) {\r\n el.style.transform = `scaleX(0)`;\r\n },\r\n easing: \"out-cubic\",\r\n duration: 500\r\n });\r\n\r\n this.mainElement.style.opacity = \"0\";\r\n this.mainElement.style.visibility = \"hidden\";\r\n resolve();\r\n });\r\n }\r\n}\r\n", "import { ITransition, ITransitionData, animate, hashAction } from \"../../../src/api\";\r\n\r\n//== Transitions\r\nexport const Slide: ITransition = {\r\n name: \"slide\",\r\n duration: 500,\r\n direction: \"right\",\r\n scrollable: true,\r\n\r\n init(data: ITransition) {\r\n let trigger = (data.trigger as HTMLElement);\r\n if (trigger instanceof Node && trigger.hasAttribute(\"data-direction\")) {\r\n this.direction = trigger.getAttribute(\"data-direction\");\r\n } else {\r\n this.direction = \"right\";\r\n }\r\n },\r\n\r\n out({ from }: ITransitionData) {\r\n let { duration, direction } = this;\r\n let fromWrapper = from.wrapper;\r\n\r\n return animate({\r\n target: fromWrapper,\r\n keyframes: [\r\n { transform: \"translateX(0%)\", opacity: 1 },\r\n { transform: `translateX(${direction === \"left\" ? \"-\" : \"\"}25%)`, opacity: 0 },\r\n ],\r\n duration,\r\n easing: \"in-quint\",\r\n onfinish: (el: { style: { opacity: string; transform: string; }; }) => {\r\n requestAnimationFrame(() => {\r\n el.style.opacity = '0';\r\n el.style.transform = `translateX(${direction === \"left\" ? \"-\" : \"\"}25%)`;\r\n });\r\n }\r\n });\r\n },\r\n\r\n in({ to, scroll }: ITransitionData) {\r\n let { duration } = this;\r\n let toWrapper = to.wrapper;\r\n\r\n window.scroll(scroll.x, scroll.y);\r\n\r\n return animate({\r\n target: toWrapper,\r\n keyframes: [\r\n { transform: `translateX(${this.direction === \"right\" ? \"-\" : \"\"}25%)`, opacity: 0 },\r\n { transform: \"translateX(0%)\", opacity: 1 },\r\n ],\r\n duration,\r\n easing: \"out-quint\",\r\n onfinish(el: { style: { opacity: string; transform: string; }; }) {\r\n requestAnimationFrame(() => {\r\n el.style.opacity = '1';\r\n el.style.transform = `translateX(0%)`;\r\n });\r\n }\r\n });\r\n }\r\n};\r\n\r\nexport const SlideLeft: ITransition = {\r\n ...Slide,\r\n\r\n name: \"slide-left\",\r\n direction: \"left\",\r\n};\r\n\r\nexport const SlideRight: ITransition = {\r\n ...Slide,\r\n\r\n name: \"slide-right\",\r\n direction: \"right\",\r\n};\r\n", "import { PJAX, App, Router } from \"../../src/api\";\r\n\r\nimport { Splashscreen } from \"./services/Splashscreen\";\r\nimport { IntroAnimation } from \"./services/IntroAnimation\";\r\n\r\nimport { Fade } from \"./transitions/Fade\";\r\nimport { BigTransition } from \"./transitions/BigTransition\";\r\nimport { Slide, SlideLeft, SlideRight } from \"./transitions/Slide\";\r\n\r\nconst app: App = new App();\r\nlet splashscreen: Splashscreen;\r\nlet router: Router, pjax: PJAX;\r\n\r\napp\r\n .add(\"service\", new IntroAnimation())\r\n .add(\"service\", splashscreen = new Splashscreen())\r\n .setService(\"router\", router = new Router())\r\n .add(\"service\", pjax = new PJAX())\r\n .setTransition(\"default\", Fade)\r\n .add(\"transition\", BigTransition)\r\n .add(\"transition\", Slide)\r\n .add(\"transition\", SlideLeft)\r\n .add(\"transition\", SlideRight);\r\n\r\ntry {\r\n router = app.get(\"service\", \"router\") as Router;\r\n\r\n // This isn't nessceary, but it changes the nav link in focus depending on the page\r\n let navLink = document.querySelectorAll(\".navbar .nav-link\");\r\n for (let item of navLink) {\r\n let navItem = (item as HTMLAnchorElement);\r\n router.add({\r\n path: navItem.getAttribute(\"data-path\") || navItem.pathname,\r\n method() {\r\n let isActive = navItem.classList.contains(\"active\");\r\n if (!isActive) navItem.classList.add(\"active\");\r\n for (let nav of navLink) {\r\n if (nav !== navItem)\r\n nav.classList.remove(\"active\");\r\n }\r\n }\r\n });\r\n }\r\n app.boot();\r\n} catch (err) {\r\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,OAAQ,YACR,YACI,sBAAsB,KAClB,EAAG,MAAM,QAAU,IACnB,EAAG,MAAM,UAAY,2BAOH,IAC/B,EAEH,KAAM,aACN,UAAW,WAGwB,IAChC,EAEH,KAAM,cACN,UAAW,SCjET,EAAW,GAAI,WAIrB,EACK,IAAI,UAAW,GAAI,IACnB,IAAI,UAAW,GAAe,GAAI,IAClC,WAAW,SAAU,EAAS,GAAI,IAClC,IAAI,UAAW,GAAO,GAAI,IAC1B,cAAc,UAAW,IACzB,IAAI,aAAc,IAClB,IAAI,aAAc,GAClB,IAAI,aAAc,IAClB,IAAI,aAAc,IAEvB,IACI,EAAS,EAAI,IAAI,UAAW,UAG5B,MAAc,SAAS,iBAAiB,qBACxC,YAAiB,IACb,MAAe,EACf,EAAO,IAAI,CACP,KAAM,EAAQ,aAAa,cAAgB,EAAQ,SACnD,SACI,MAAe,EAAQ,UAAU,SAAS,UAC1C,AAAK,GAAU,EAAQ,UAAU,IAAI,UACrC,YAAgB,GACZ,AAAI,IAAQ,GACR,EAAI,UAAU,OAAO,aAKzC,EAAI,gBAEJ,GAAa,OACb,QAAQ,KAAK,qBAAsB",
"names": []
}
diff --git a/packages/native/dts.tsconfig.json b/packages/native/dts.tsconfig.json
new file mode 100644
index 0000000..e577d2b
--- /dev/null
+++ b/packages/native/dts.tsconfig.json
@@ -0,0 +1,10 @@
+{
+ "extends": "../../dts.tsconfig.json",
+ "include": [
+ "**/src/**/*"
+ ],
+ "exclude": [
+ "node_modules",
+ "**/tests/**/*"
+ ]
+}
diff --git a/packages/native/lib/api.js b/packages/native/lib/api.js
index 142c88e..2b3c9bf 100644
--- a/packages/native/lib/api.js
+++ b/packages/native/lib/api.js
@@ -1,3 +1,3 @@
-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;})();
+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:()=>v,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 v=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 v{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"))),T=m&&R,U=h(p())===h(p(i));return!(o||n||s||a||l||c||T||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 T=this.HistoryManager.get(this.HistoryManager.pointer);a=T.transition,n=T.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(async 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 v{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:T,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{T(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 097f349..716a9c4 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/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