diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5777c1e..9938441 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## [4.0.3] - 2024-01-03
+
+### Fixed
+
+- Fixed handlers not having access to `this` context when the handler is in an Alpine component.
+
## [4.0.2] - 2023-12-23
### Fixed
@@ -265,4 +271,5 @@ It's mostly backward compatible but need a few tweaks:
[3.1.2]: https://github.com/pinecone-router/router/compare/3.1.1..3.1.2
[4.0.0]: https://github.com/pinecone-router/router/compare/3.1.2..4.0.0
[4.0.1]: https://github.com/pinecone-router/router/compare/4.0.0..4.0.1
-[4.0.1]: https://github.com/pinecone-router/router/compare/4.0.1..4.0.2
+[4.0.2]: https://github.com/pinecone-router/router/compare/4.0.1..4.0.2
+[4.0.3]: https://github.com/pinecone-router/router/compare/4.0.2..4.0.3
diff --git a/README.md b/README.md
index 3f53858..74ed565 100644
--- a/README.md
+++ b/README.md
@@ -2,8 +2,8 @@
-[![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/pinecone-router/router?color=%2337C8AB&label=version&sort=semver)](https://github.com/pinecone-router/router/tree/4.0.2)
-[![npm bundle size](https://img.shields.io/bundlephobia/minzip/pinecone-router?color=37C8AB)](https://bundlephobia.com/result?p=pinecone-router@4.0.2)
+[![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/pinecone-router/router?color=%2337C8AB&label=version&sort=semver)](https://github.com/pinecone-router/router/tree/4.0.3)
+[![npm bundle size](https://img.shields.io/bundlephobia/minzip/pinecone-router?color=37C8AB)](https://bundlephobia.com/result?p=pinecone-router@4.0.3)
[![Downloads from JSDelivr](https://data.jsdelivr.com/v1/package/npm/pinecone-router/badge?style=rounded)](https://www.jsdelivr.com/package/npm/pinecone-router)
[![npm](https://img.shields.io/npm/dm/pinecone-router?color=37C8AB&label=npm&logo=npm&logoColor=37C8AB)](https://npmjs.com/package/pinecone-router)
[![Changelog](https://img.shields.io/badge/change-log-%2337C8AB)](/CHANGELOG.md)
diff --git a/dist/router.esm.js b/dist/router.esm.js
index 93e9f18..02cc22b 100644
--- a/dist/router.esm.js
+++ b/dist/router.esm.js
@@ -1,2 +1,2 @@
-var A=class{constructor(e,a={}){this.params={};this.handlers=[];this.handlersDone=!1;this.path=e,Object.keys(a).forEach(u=>{this[u]=a[u]})}},M=A;var I=window.location;function C(o){return o.replace(/(^\/+|\/+$)/g,"").split("/")}function S(o,e){let a=/(?:\?([^#]*))?(#.*)?$/,u=o.match(a),v={},x;if(u&&u[1]){let d=u[1].split("&");for(let w=0;w-1||(u?o.target.baseVal:o.target)||!u&&!N(o.href)||(a.valid=!0),a}function P(o,...e){if(!!window.PineconeRouterMiddlewares)for(let a in window.PineconeRouterMiddlewares){let u=window.PineconeRouterMiddlewares[a];if(u[o]==null)return;if(u[o](...e)=="stop")return"stop"}}function $(o){document.dispatchEvent(new CustomEvent("fetch-error",{detail:o}))}function D(o){let e=o.reactive({version:"4.0.2",name:"pinecone-router",settings:{hash:!1,basePath:"/",templateTargetId:null},notfound:new M("notfound"),routes:[],context:{route:"",path:"",params:{},query:window.location.search.substring(1),hash:window.location.hash.substring(1),redirect(t){return c(t),"stop"},navigate(t){c(t)}},add(t,r){if(this.routes.find(i=>i.path==t)!=null)throw new Error("Pinecone Router: route already exist");return this.routes.push(new M(t,r))-1},remove(t){this.routes=this.routes.filter(r=>r.path!=t)},loadStart:new Event("pinecone-start"),loadEnd:new Event("pinecone-end")});window.PineconeRouter=e;var a={},u={};let v=(t,r,i)=>(a[r]?a[r].then(n=>{i==null&&(t.innerHTML=n)}):a[r]=fetch(r).then(n=>{if(n.ok)return n.text();throw new Error(String(n.status))}).then(n=>(u[r]=n,i==null&&(t.innerHTML=n),n)).catch(n=>($(n),null)),a[r]),x=(t,r,i)=>{let n=r!=null?`PineconeRouter.routes[${r}]`:"PineconeRouter.notfound",s=`$router.route == "${i}" && ${n}.handlersDone`;t.hasAttribute("x-if")||(t.setAttribute("x-if",s),d())},b=t=>{!t.hasAttribute("x-if")||t.removeAttribute("x-if")},p=(t,r)=>{d(),t.innerHTML=u[r]},T=()=>{document.dispatchEvent(e.loadStart)},d=()=>{document.dispatchEvent(e.loadEnd)},w=t=>!e.settings.hash&&e.settings.basePath!="/"?e.settings.basePath+t:t,m=t=>e.routes.findIndex(r=>r.path==t);o.directive("route",(t,{expression:r},{cleanup:i})=>{let n=r;if(P("onBeforeRouteProcessed",t,n),n.indexOf("#")>-1)throw new Error("Pinecone Router: A route's path may not have a hash character.");let s=null;if(n!="notfound"&&(n=w(n),s=e.add(n)),t.content.firstElementChild!=null){let l=e.routes[s]??e.notfound;x(t,s,n)}P("onAfterRouteProcessed",t,n),i(()=>{e.remove(n),b(t)})}),o.directive("handler",(t,{expression:r},{evaluate:i,cleanup:n})=>{if(!t.hasAttribute("x-route"))throw new Error("Pinecone Router: x-handler must be set on the same element as x-route.");let s;!(r.startsWith("[")&&r.endsWith("]"))&&!(r.startsWith("Array(")&&r.endsWith(")"))&&(r=`[${r}]`);let l=i(r),h=t.getAttribute("x-route");if(typeof l=="object")s=l;else throw new Error(`Pinecone Router: Invalid handler type: ${typeof l}.`);let f;if(h=="notfound")f=e.notfound;else{h=w(h);let g=m(h);f=e.routes[g]}f.handlers=s,n(()=>{f.handlers=[],f.handlersDone=!0})}),o.directive("template",(t,{modifiers:r,expression:i},{Alpine:n,effect:s,cleanup:l})=>{if(!t.hasAttribute("x-route"))throw new Error("Pinecone Router: x-template must be used on the same element as x-route.");var h;let f=i,g=O(r,"target",null)??window.PineconeRouter.settings.templateTargetId,k=document.getElementById(g);if(g&&!k)throw new Error("Pinecone Router: Can't find an element with the suplied x-template target ID ("+g+")");r.includes("preload")&&(h=v(t,f,g).finally(()=>{h=!1,u[f]!=null&&(g||x(t,R,E))}));let E=t.getAttribute("x-route"),y,R;E=="notfound"?(e.notfound.template=f,y=e.notfound):(E=w(E),R=m(E),e.routes[R].template=f,y=e.routes[R]),n.nextTick(()=>{s(()=>{if(y.handlersDone&&e.context.route==E)if(u[f]!=null)if(g)p(k,f);else{if(d(),t.content.firstElementChild)return;t.innerHTML=u[f]}else h?h.finally(()=>{u[f]!=null&&g&&p(k,f)}):v(t,f,g).finally(()=>{u[f]!=null&&(g?p(k,f):x(t,R,E))})})}),l(()=>{delete u[y.template],y.template="",b(t)})}),o.$router=e.context,o.magic("router",()=>e.context),document.addEventListener("alpine:initialized",()=>{P("init"),e.settings.hash?c(location.hash.substring(1),!1,!0):c(location.pathname,!1,!0)}),window.addEventListener("popstate",()=>{e.settings.hash?window.location.hash!=""&&c(window.location.hash.substring(1),!0):c(window.location.pathname,!0)}),H();function H(){window.document.body.addEventListener(document.ontouchstart?"touchstart":"click",function(t){if(t.metaKey||t.ctrlKey||t.shiftKey||t.defaultPrevented)return;let r=t.target,i=t.composedPath();if(i){for(let l=0;l{let h=S(t,l.path);return l.params=h!=!1?h:{},h!=!1})??e.notfound;n.handlersDone=!n.handlers.length,(n.handlers.length||n.template)&&T();let s=L(n.path,t,n.params);if(e.context=s,P("onBeforeHandlersExecuted",n,t,i)=="stop"){d();return}if(!r){let l="";if(e.settings.hash?(l="#",l+=window.location.search+t):l=t+window.location.search+window.location.hash,!i)history.pushState({path:l},"",l);else if(e.settings.hash&&t=="/")return e.context=s,c("/",!1,!1)}if(n&&n.handlers.length){if(n.cancelHandlers=!1,!await W(n.handlers,s)){d();return}n.handlersDone=!0,n.template||d()}P("onHandlersExecuted",n,t,i)}function L(t,r,i){return{route:t,path:r,params:i,query:window.location.search.substring(1),hash:window.location.hash.substring(1),redirect(n){return c(n),"stop"},navigate(n){c(n)}}}function O(t,r,i){if(t.indexOf(r)===-1)return i;let n=t[t.indexOf(r)+1];if(!n)return i;if(r==="target"){let s=n.match(/([a-z0-9_-]+)/);if(s)return s[1]}return n}async function W(t,r){for(let i=0;i{this[u]=a[u]})}},A=M;var I=window.location;function C(o){return o.replace(/(^\/+|\/+$)/g,"").split("/")}function S(o,e){let a=/(?:\?([^#]*))?(#.*)?$/,u=o.match(a),x={},v;if(u&&u[1]){let d=u[1].split("&");for(let w=0;w-1||(u?o.target.baseVal:o.target)||!u&&!N(o.href)||(a.valid=!0),a}function P(o,...e){if(!!window.PineconeRouterMiddlewares)for(let a in window.PineconeRouterMiddlewares){let u=window.PineconeRouterMiddlewares[a];if(u[o]==null)return;if(u[o](...e)=="stop")return"stop"}}function U(o){document.dispatchEvent(new CustomEvent("fetch-error",{detail:o}))}function D(o){let e=o.reactive({version:"4.0.3",name:"pinecone-router",settings:{hash:!1,basePath:"/",templateTargetId:null},notfound:new A("notfound"),routes:[],context:{route:"",path:"",params:{},query:window.location.search.substring(1),hash:window.location.hash.substring(1),redirect(t){return h(t),"stop"},navigate(t){h(t)}},add(t,r){if(this.routes.find(i=>i.path==t)!=null)throw new Error("Pinecone Router: route already exist");return this.routes.push(new A(t,r))-1},remove(t){this.routes=this.routes.filter(r=>r.path!=t)},loadStart:new Event("pinecone-start"),loadEnd:new Event("pinecone-end")});window.PineconeRouter=e;var a={},u={};let x=(t,r,i)=>(a[r]?a[r].then(n=>{i==null&&(t.innerHTML=n)}):a[r]=fetch(r).then(n=>{if(n.ok)return n.text();throw new Error(String(n.status))}).then(n=>(u[r]=n,i==null&&(t.innerHTML=n),n)).catch(n=>(U(n),null)),a[r]),v=(t,r,i)=>{let n=r!=null?`PineconeRouter.routes[${r}]`:"PineconeRouter.notfound",s=`$router.route == "${i}" && ${n}.handlersDone`;t.hasAttribute("x-if")||(t.setAttribute("x-if",s),d())},b=t=>{!t.hasAttribute("x-if")||t.removeAttribute("x-if")},p=(t,r)=>{d(),t.innerHTML=u[r]},T=()=>{document.dispatchEvent(e.loadStart)},d=()=>{document.dispatchEvent(e.loadEnd)},w=t=>!e.settings.hash&&e.settings.basePath!="/"?e.settings.basePath+t:t,g=t=>e.routes.findIndex(r=>r.path==t);o.directive("route",(t,{expression:r},{cleanup:i})=>{let n=r;if(P("onBeforeRouteProcessed",t,n),n.indexOf("#")>-1)throw new Error("Pinecone Router: A route's path may not have a hash character.");let s=null;if(n!="notfound"&&(n=w(n),s=e.add(n)),t.content.firstElementChild!=null){let l=e.routes[s]??e.notfound;v(t,s,n)}P("onAfterRouteProcessed",t,n),i(()=>{e.remove(n),b(t)})}),o.directive("handler",(t,{expression:r},{evaluate:i,cleanup:n})=>{if(!t.hasAttribute("x-route"))throw new Error("Pinecone Router: x-handler must be set on the same element as x-route.");let s;!(r.startsWith("[")&&r.endsWith("]"))&&!(r.startsWith("Array(")&&r.endsWith(")"))&&(r=`[${r}]`);let l=i(r),m=t.getAttribute("x-route");if(typeof l=="object")s=l;else throw new Error(`Pinecone Router: Invalid handler type: ${typeof l}.`);for(let c=0;c{f.handlers=[],f.handlersDone=!0})}),o.directive("template",(t,{modifiers:r,expression:i},{Alpine:n,effect:s,cleanup:l})=>{if(!t.hasAttribute("x-route"))throw new Error("Pinecone Router: x-template must be used on the same element as x-route.");var m;let f=i,c=O(r,"target",null)??window.PineconeRouter.settings.templateTargetId,k=document.getElementById(c);if(c&&!k)throw new Error("Pinecone Router: Can't find an element with the suplied x-template target ID ("+c+")");r.includes("preload")&&(m=x(t,f,c).finally(()=>{m=!1,u[f]!=null&&(c||v(t,R,E))}));let E=t.getAttribute("x-route"),y,R;E=="notfound"?(e.notfound.template=f,y=e.notfound):(E=w(E),R=g(E),e.routes[R].template=f,y=e.routes[R]),n.nextTick(()=>{s(()=>{if(y.handlersDone&&e.context.route==E)if(u[f]!=null)if(c)p(k,f);else{if(d(),t.content.firstElementChild)return;t.innerHTML=u[f]}else m?m.finally(()=>{u[f]!=null&&c&&p(k,f)}):x(t,f,c).finally(()=>{u[f]!=null&&(c?p(k,f):v(t,R,E))})})}),l(()=>{delete u[y.template],y.template="",b(t)})}),o.$router=e.context,o.magic("router",()=>e.context),document.addEventListener("alpine:initialized",()=>{P("init"),e.settings.hash?h(location.hash.substring(1),!1,!0):h(location.pathname,!1,!0)}),window.addEventListener("popstate",()=>{e.settings.hash?window.location.hash!=""&&h(window.location.hash.substring(1),!0):h(window.location.pathname,!0)}),H();function H(){window.document.body.addEventListener(document.ontouchstart?"touchstart":"click",function(t){if(t.metaKey||t.ctrlKey||t.shiftKey||t.defaultPrevented)return;let r=t.target,i=t.composedPath();if(i){for(let l=0;l{let m=S(t,l.path);return l.params=m!=!1?m:{},m!=!1})??e.notfound;n.handlersDone=!n.handlers.length,(n.handlers.length||n.template)&&T();let s=L(n.path,t,n.params);if(e.context=s,P("onBeforeHandlersExecuted",n,t,i)=="stop"){d();return}if(!r){let l="";if(e.settings.hash?(l="#",l+=window.location.search+t):l=t+window.location.search+window.location.hash,!i)history.pushState({path:l},"",l);else if(e.settings.hash&&t=="/")return e.context=s,h("/",!1,!1)}if(n&&n.handlers.length){if(n.cancelHandlers=!1,!await W(n.handlers,s)){d();return}n.handlersDone=!0,n.template||d()}P("onHandlersExecuted",n,t,i)}function L(t,r,i){return{route:t,path:r,params:i,query:window.location.search.substring(1),hash:window.location.hash.substring(1),redirect(n){return h(n),"stop"},navigate(n){h(n)}}}function O(t,r,i){if(t.indexOf(r)===-1)return i;let n=t[t.indexOf(r)+1];if(!n)return i;if(r==="target"){let s=n.match(/([a-z0-9_-]+)/);if(s)return s[1]}return n}async function W(t,r){for(let i=0;i {\r\n\t\t\tthis[opt] = options[opt]\r\n\t\t})\r\n\t}\r\n\ttemplate: ''\r\n\thandlersDone: boolean = false\r\n\tcancelHandlers: boolean\r\n}\r\n\r\nexport default Route\r\n", "var isLocation = window.location\r\n\r\n/**\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param url url to segmentize\r\n * @returns\r\n */\r\nfunction segmentize(url: string): string[] {\r\n\treturn url.replace(/(^\\/+|\\/+$)/g, '').split('/')\r\n}\r\n\r\n/**\r\n * check if a path match with this route\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param path {string}\r\n * @param routePath {string}\r\n * @returns {false|object}\r\n */\r\nexport function match(url: string, routePath: string): false | object {\r\n\tlet reg = /(?:\\?([^#]*))?(#.*)?$/,\r\n\t\tc = url.match(reg),\r\n\t\tmatches: any = {},\r\n\t\tret\r\n\tif (c && c[1]) {\r\n\t\tlet p = c[1].split('&')\r\n\t\tfor (let i = 0; i < p.length; i++) {\r\n\t\t\tlet r = p[i].split('=')\r\n\t\t\tmatches[decodeURIComponent(r[0])] = decodeURIComponent(\r\n\t\t\t\tr.slice(1).join('=')\r\n\t\t\t)\r\n\t\t}\r\n\t}\r\n\tlet urlSeg = segmentize(url.replace(reg, '')),\r\n\t\troute: string[] = segmentize(routePath || ''),\r\n\t\tmax = Math.max(urlSeg.length, route.length)\r\n\tfor (let i = 0; i < max; i++) {\r\n\t\tif (route[i] && route[i].charAt(0) === ':') {\r\n\t\t\tlet param: string = route[i].replace(/(^:|[+*?]+$)/g, ''),\r\n\t\t\t\tflags: string = (route[i].match(/[+*?]+$/) || {}).toString()[0],\r\n\t\t\t\tplus = ~flags.indexOf('+'),\r\n\t\t\t\tstar = ~flags.indexOf('*'),\r\n\t\t\t\tval = urlSeg[i] || ''\r\n\t\t\tif (!val && !star && (flags.indexOf('?') < 0 || plus)) {\r\n\t\t\t\tret = false\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\tmatches[param] = decodeURIComponent(val)\r\n\t\t\tif (plus || star) {\r\n\t\t\t\tmatches[param] = urlSeg\r\n\t\t\t\t\t.slice(i)\r\n\t\t\t\t\t.map(decodeURIComponent)\r\n\t\t\t\t\t.join('/')\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t} else if (route[i] !== urlSeg[i]) {\r\n\t\t\tret = false\r\n\t\t\tbreak\r\n\t\t}\r\n\t}\r\n\tif (ret === false) return false\r\n\treturn matches\r\n}\r\n\r\n/**\r\n * Convert to a URL object\r\n * https://github.com/visionmedia/page.js/blob/4f9991658f9b9e3de9b6059bade93693af24d6bd/page.js#L888\r\n */\r\nfunction toURL(href: string): URL | HTMLAnchorElement {\r\n\tif (typeof URL === 'function' && isLocation) {\r\n\t\treturn new URL(href, window.location.toString())\r\n\t} else {\r\n\t\tvar anc = window.document.createElement('a')\r\n\t\tanc.href = href\r\n\t\treturn anc\r\n\t}\r\n}\r\n\r\n/**\r\n * Check if `href` is the same origin.\r\n * https://github.com/visionmedia/page.js/blob/4f9991658f9b9e3de9b6059bade93693af24d6bd/page.js#L888\r\n */\r\nexport function sameOrigin(href: string) {\r\n\tif (!href || !isLocation) return false\r\n\r\n\tvar url = toURL(href)\r\n\tvar loc = window.location\r\n\r\n\t/*\r\n\tWhen the port is the default http port 80 for http, or 443 for\r\n\thttps, internet explorer 11 returns an empty string for loc.port,\r\n\tso we need to compare loc.port with an empty string if url.port\r\n\tis the default port 80 or 443.\r\n\tAlso the comparison with `port` is changed from `===` to `==` because\r\n\t`port` can be a string sometimes. This only applies to ie11.\r\n\t*/\r\n\treturn (\r\n\t\tloc.protocol === url.protocol &&\r\n\t\tloc.hostname === url.hostname &&\r\n\t\t(loc.port === url.port ||\r\n\t\t\t(loc.port === '' && (url.port == '80' || url.port == '443')))\r\n\t) // jshint ignore:line\r\n}\r\n\r\nexport function samePath(url: any) {\r\n\tif (!isLocation) return false\r\n\tvar loc = window.location\r\n\treturn url.pathname === loc.pathname && url.search === loc.search\r\n}\r\n\r\n/**\r\n * Check if the anchor element point to a navigation route.\r\n * @param {any} el The anchor element or Event target\r\n * @param {boolean} hash Set to true when using hash routing\r\n * @returns {object} {valid: boolean, link: string}\r\n */\r\nexport function validLink(\r\n\tel: any,\r\n\thash: boolean\r\n): { valid: boolean; link: string } {\r\n\t// the object we'll return\r\n\tlet ret = { valid: false, link: '' }\r\n\r\n\t// The checks in this block are taken from\r\n\t// https://github.com/visionmedia/page.js/blob/master/index.js#L370\r\n\r\n\t// continue ensure link\r\n\r\n\t// el.nodeName for svg links are 'a' instead of 'A'\r\n\t// traverse up till we find an anchor tag, since clicks\r\n\t// on image links for example set the target as img instead of a.\r\n\twhile (el && 'A' !== el.nodeName.toUpperCase()) el = el.parentNode\r\n\tif (!el || 'A' !== el.nodeName.toUpperCase()) return ret\r\n\r\n\t// check if link is inside an svg\r\n\t// in this case, both href and target are always inside an object\r\n\tvar svg =\r\n\t\ttypeof el.href === 'object' &&\r\n\t\tel.href.constructor.name === 'SVGAnimatedString'\r\n\r\n\t// Ignore if tag has\r\n\t// 1. \"download\" attribute\r\n\t// 2. rel=\"external\" attribute\r\n\tif (el.hasAttribute('download') || el.getAttribute('rel') === 'external') {\r\n\t\treturn ret\r\n\t}\r\n\r\n\t// ensure non-hash for the same path\r\n\tret.link = el.getAttribute('href') ?? ''\r\n\tif (!hash && samePath(el) && (el.hash || '#' === ret.link)) {\r\n\t\treturn ret\r\n\t}\r\n\r\n\t// Check for mailto: in the href\r\n\tif (ret.link && ret.link.indexOf('mailto:') > -1) return ret\r\n\r\n\t// check target\r\n\t// svg target is an object and its desired value is in .baseVal property\r\n\tif (svg ? el.target.baseVal : el.target) return ret\r\n\r\n\t// x-origin\r\n\t// note: svg links that are not relative don't call click events (and skip page.js)\r\n\t// consequently, all svg links tested inside page.js are relative and in the same origin\r\n\tif (!svg && !sameOrigin(el.href)) return ret\r\n\r\n\tret.valid = true\r\n\treturn ret\r\n}\r\n\r\n/**\r\n * Call a function on all middlewares loaded, if any.\r\n * @param {string} func middleware function to call.\r\n * @param {any} args arguments to pass to the function.\r\n * @returns {boolean} false if the middleware function return false, i.e. it want to stop execution of the function and return.\r\n */\r\nexport function middleware(func: string, ...args: any): string | undefined {\r\n\tif (!window.PineconeRouterMiddlewares) return\r\n\tfor (const i in window.PineconeRouterMiddlewares) {\r\n\t\tlet plugin: any = window.PineconeRouterMiddlewares[i]\r\n\t\tif (plugin[func] == null) return\r\n\t\tlet ret = plugin[func](...args)\r\n\t\t// the return of the function will only be 'stop'\r\n\t\t// if the middleware request stopping the navigate function.\r\n\t\tif (ret == 'stop') return 'stop'\r\n\t}\r\n}\r\n\r\nexport function fetchError(error: string) {\r\n\tdocument.dispatchEvent(\r\n\t\tnew CustomEvent('fetch-error', { detail: error })\r\n\t)\r\n}", "import Route from './route'\r\nimport type { Settings, Context, Middleware, Handler } from './types'\r\nimport { fetchError, match, middleware, validLink } from './utils'\r\n\r\n\r\ndeclare global {\r\n\tinterface Window {\r\n\t\tPineconeRouter: {\r\n\t\t\tversion: string\r\n\t\t\tname: string\r\n\t\t\tsettings: Settings\r\n\t\t\tnotfound: Route\r\n\t\t\troutes: Route[]\r\n\t\t\tcontext: Context\r\n\t\t\tloadStart: Event\r\n\t\t\tloadEnd: Event\r\n\t\t\tadd: (path: string, options?: {}) => number\r\n\t\t\tremove: (path: string) => void\r\n\t\t}\r\n\t\tPineconeRouterMiddlewares: Array\r\n\t}\r\n}\r\n\r\nexport default function (Alpine) {\r\n\r\n\tconst PineconeRouter = Alpine.reactive({\r\n\t\tversion: '4.0.2',\r\n\t\tname: 'pinecone-router',\r\n\r\n\t\tsettings: {\r\n\t\t\thash: false,\r\n\t\t\tbasePath: '/',\r\n\t\t\ttemplateTargetId: null\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * @description The handler for 404 pages, can be overwritten by a notfound route\r\n\t\t */\r\n\t\tnotfound: new Route('notfound'),\r\n\r\n\t\t/**\r\n\t\t * @type Route[]\r\n\t\t * @summary array of routes instantiated from the Route class.\r\n\t\t */\r\n\t\troutes: [],\r\n\r\n\t\t/**\r\n\t\t * @type {Context}\r\n\t\t * @summary The context object for current path.\r\n\t\t */\r\n\t\tcontext: {\r\n\t\t\troute: '',\r\n\t\t\tpath: '',\r\n\t\t\tparams: {},\r\n\t\t\tquery: window.location.search.substring(1),\r\n\t\t\thash: window.location.hash.substring(1),\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Add a new route\r\n\t\t */\r\n\t\tadd(path: string, options?: {}) {\r\n\t\t\t// check if the route was registered on the same router.\r\n\t\t\tif (this.routes.find((r: Route) => r.path == path) != null) {\r\n\t\t\t\tthrow new Error('Pinecone Router: route already exist')\r\n\t\t\t}\r\n\r\n\t\t\treturn this.routes.push(new Route(path, options)) - 1\r\n\t\t},\r\n\t\t/**\r\n\t\t * Remove a route\r\n\t\t */\r\n\t\tremove(path: string) {\r\n\t\t\tthis.routes = this.routes.filter((r: Route) => r.path != path)\r\n\t\t},\r\n\t\t/**\r\n\t\t * @event pinecone-start\r\n\t\t * @summary be dispatched to the window after before page start loading.\r\n\t\t */\r\n\t\tloadStart: new Event('pinecone-start'),\r\n\r\n\t\t/**\r\n\t\t * @event pinecone-end\r\n\t\t * @summary will be dispatched to the window after the views are fetched\r\n\t\t */\r\n\t\tloadEnd: new Event('pinecone-end'),\r\n\t})\r\n\r\n\twindow.PineconeRouter = PineconeRouter\r\n\r\n\tvar loadingTemplates: { [key: string]: Promise } = {}\r\n\tvar cachedTemplates: { [key: string]: string } = {}\r\n\r\n\tconst loadTemplate = (el: HTMLElement, url: string, target: string | null): Promise => {\r\n\t\tif (loadingTemplates[url]) {\r\n\t\t\tloadingTemplates[url].then(html => {\r\n\t\t\t\tif (target == null) {\r\n\t\t\t\t\tel.innerHTML = html\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t\t} else {\r\n\t\t\tloadingTemplates[url] = fetch(url).then(r => {\r\n\t\t\t\tif (r.ok) return r.text()\r\n\t\t\t\tthrow new Error(String(r.status))\r\n\t\t\t}).then(html => {\r\n\t\t\t\tcachedTemplates[url] = html\r\n\t\t\t\tif (target == null) {\r\n\t\t\t\t\tel.innerHTML = html\r\n\t\t\t\t}\r\n\t\t\t\treturn html\r\n\t\t\t}).catch(err => {\r\n\t\t\t\tfetchError(err)\r\n\t\t\t\t// returning a value is a must because we are assigning returned value to loadingTemplates[url]\r\n\t\t\t\t// by returning a null it will refetch again when the route is (re)visited\r\n\t\t\t\treturn null\r\n\t\t\t})\r\n\t\t}\r\n\t\treturn loadingTemplates[url]\r\n\t}\r\n\r\n\tconst addIf = (el: HTMLElement, routeIndex, path) => {\r\n\t\t// this make sure inline templates dont render until handlers are done\r\n\t\tlet route_expression = (routeIndex != null) ? `PineconeRouter.routes[${routeIndex}]` : 'PineconeRouter.notfound'\r\n\t\tlet expression = `$router.route == \"${path}\" && ${route_expression}.handlersDone`\r\n\t\tif (el.hasAttribute(\"x-if\")) return\r\n\t\tel.setAttribute(\"x-if\", expression)\r\n\t\tendLoading()\r\n\t}\r\n\r\n\tconst removeIf = (el: HTMLElement) => {\r\n\t\tif (!el.hasAttribute(\"x-if\")) return\r\n\t\tel.removeAttribute(\"x-if\")\r\n\t}\r\n\r\n\tconst insertHtmlInTarget = (targetEl: HTMLElement, url: string) => {\r\n\t\tendLoading()\r\n\t\ttargetEl.innerHTML = cachedTemplates[url]\r\n\t}\r\n\r\n\tconst startLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadStart)\r\n\t}\r\n\r\n\tconst endLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadEnd)\r\n\t}\r\n\r\n\tconst addBasePath = (path) => {\r\n\t\tif (!PineconeRouter.settings.hash && PineconeRouter.settings.basePath != '/') {\r\n\t\t\treturn PineconeRouter.settings.basePath + path\r\n\t\t} return path\r\n\t}\r\n\r\n\tconst findRouteIndex = (path) => {\r\n\t\treturn PineconeRouter.routes.findIndex(\r\n\t\t\t(r) => r.path == path\r\n\t\t)\r\n\t}\r\n\r\n\tAlpine.directive(\r\n\t\t'route',\r\n\t\t(el: HTMLTemplateElement, { expression }, { cleanup }) => {\r\n\t\t\tlet path = expression\r\n\r\n\t\t\tmiddleware('onBeforeRouteProcessed', el, path)\r\n\r\n\t\t\tif (path.indexOf('#') > -1) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: A route's path may not have a hash character.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\r\n\t\t\tlet routeIndex = null\r\n\r\n\t\t\tif (path != 'notfound') {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// register the new route if possible\r\n\t\t\t\trouteIndex = PineconeRouter.add(path)\r\n\t\t\t}\r\n\r\n\t\t\t// add if statement for inline template\r\n\t\t\tif (el.content.firstElementChild != null) {\r\n\t\t\t\tlet route = PineconeRouter.routes[routeIndex] ?? PineconeRouter.notfound\r\n\t\t\t\taddIf(el, routeIndex, path)\r\n\t\t\t}\r\n\r\n\t\t\tmiddleware('onAfterRouteProcessed', el, path)\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tPineconeRouter.remove(path)\r\n\t\t\t\tremoveIf(el)\r\n\t\t\t})\r\n\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'handler',\r\n\t\t(\r\n\t\t\tel,\r\n\t\t\t{ expression },\r\n\t\t\t{ evaluate, cleanup }\r\n\t\t) => {\r\n\t\t\tif (!el.hasAttribute('x-route')) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: x-handler must be set on the same element as x-route.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\tlet handlers\r\n\r\n\t\t\t// check if the handlers expression is an array\r\n\t\t\t// if not make it one\r\n\t\t\tif (\r\n\t\t\t\t!(expression.startsWith('[') && expression.endsWith(']')) &&\r\n\t\t\t\t!(expression.startsWith('Array(') && expression.endsWith(')'))\r\n\t\t\t) {\r\n\t\t\t\texpression = `[${expression}]`\r\n\t\t\t}\r\n\r\n\t\t\tlet evaluatedExpression = evaluate(expression)\r\n\t\t\tlet path = el.getAttribute('x-route')\r\n\r\n\t\t\tif (typeof evaluatedExpression == 'object')\r\n\t\t\t\thandlers = evaluatedExpression\r\n\t\t\telse {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: Invalid handler type: ${typeof evaluatedExpression}.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\tlet route\r\n\r\n\t\t\tif (path == 'notfound')\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\telse {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// add handlers to the route\r\n\t\t\t\tlet i = findRouteIndex(path)\r\n\t\t\t\troute = PineconeRouter.routes[i]\r\n\t\t\t}\r\n\t\t\troute.handlers = handlers\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\troute.handlers = []\r\n\t\t\t\troute.handlersDone = true\r\n\t\t\t})\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'template',\r\n\t\t(el: HTMLTemplateElement, { modifiers, expression }, { Alpine, effect, cleanup }) => {\r\n\r\n\t\t\tif (!el.hasAttribute(\"x-route\")) throw new Error(\"Pinecone Router: x-template must be used on the same element as x-route.\")\r\n\r\n\t\t\tvar isPreloading: any\r\n\t\t\tlet url: string = expression\r\n\r\n\t\t\tlet target = modifierValue(modifiers, 'target', null) ?? window.PineconeRouter.settings.templateTargetId\r\n\t\t\tlet targetEl = document.getElementById(target)\r\n\r\n\t\t\tif (target && !targetEl)\r\n\t\t\t\tthrow new Error(\"Pinecone Router: Can't find an element with the suplied x-template target ID (\" + target + \")\")\r\n\r\n\t\t\tif (modifiers.includes(\"preload\")) {\r\n\t\t\t\tisPreloading = loadTemplate(el, url, target).finally(() => {\r\n\t\t\t\t\tisPreloading = false\r\n\t\t\t\t\t// In case of failed fetch the template wont be cached\r\n\t\t\t\t\t// therefore we check for it and not add anything if it's null\r\n\t\t\t\t\tif (cachedTemplates[url] == null) return\r\n\t\t\t\t\tif (!target) addIf(el, routeIndex, path);\r\n\t\t\t\t})\r\n\t\t\t}\r\n\r\n\t\t\tlet path = el.getAttribute(\"x-route\")\r\n\t\t\tlet route;\r\n\t\t\tlet routeIndex\r\n\t\t\tif (path == 'notfound') {\r\n\t\t\t\tPineconeRouter.notfound.template = url\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\trouteIndex = findRouteIndex(path)\r\n\t\t\t\tPineconeRouter.routes[routeIndex].template = url\r\n\t\t\t\troute = PineconeRouter.routes[routeIndex]\r\n\t\t\t}\r\n\r\n\r\n\t\t\tAlpine.nextTick(() => {\r\n\t\t\t\teffect(() => {\r\n\t\t\t\t\tif (route.handlersDone && PineconeRouter.context.route == path) {\r\n\t\t\t\t\t\tif (cachedTemplates[url] != null) {\r\n\t\t\t\t\t\t\tif (!target) {\r\n\t\t\t\t\t\t\t\tendLoading()\r\n\t\t\t\t\t\t\t\tif (el.content.firstElementChild) return\r\n\t\t\t\t\t\t\t\tel.innerHTML = cachedTemplates[url]\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse insertHtmlInTarget(targetEl, url)\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tif (!isPreloading) {\r\n\t\t\t\t\t\t\t\tloadTemplate(el, url, target).finally(() => {\r\n\t\t\t\t\t\t\t\t\tif (cachedTemplates[url] == null) return\r\n\t\t\t\t\t\t\t\t\tif (!target) addIf(el, routeIndex, path)\r\n\t\t\t\t\t\t\t\t\telse insertHtmlInTarget(targetEl, url)\r\n\t\t\t\t\t\t\t\t})\r\n\t\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t\tisPreloading.finally(() => {\r\n\t\t\t\t\t\t\t\t\tif (cachedTemplates[url] == null) return\r\n\t\t\t\t\t\t\t\t\tif (target) {\r\n\t\t\t\t\t\t\t\t\t\tinsertHtmlInTarget(targetEl, url)\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t})\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t})\r\n\r\n\t\t\t})\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tdelete cachedTemplates[route.template]\r\n\t\t\t\troute.template = ''\r\n\t\t\t\tremoveIf(el)\r\n\t\t\t})\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.$router = PineconeRouter.context\r\n\tAlpine.magic('router', () => PineconeRouter.context)\r\n\r\n\tdocument.addEventListener('alpine:initialized', () => {\r\n\t\tmiddleware('init')\r\n\t\t// virtually navigate the path on the first page load\r\n\t\t// this will register the path in history and sets the pathvariable\r\n\t\t// navigate(window.location.pathname, false, true)\r\n\t\tif (!PineconeRouter.settings.hash) {\r\n\t\t\t// navigate to the current page to handle it\r\n\t\t\t// ONLY if we not using hash routing for the default router\r\n\t\t\tnavigate(location.pathname, false, true)\r\n\t\t} else {\r\n\t\t\tnavigate(location.hash.substring(1), false, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// handle navigation events not emitted by links, for example, back button.\r\n\twindow.addEventListener('popstate', () => {\r\n\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\tif (window.location.hash != '') {\r\n\t\t\t\tnavigate(window.location.hash.substring(1), true)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tnavigate(window.location.pathname, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// intercept click event in links\r\n\tinterceptLinks()\r\n\r\n\t/**\r\n\t * @description Add a handler to click events on all valid links\r\n\t */\r\n\tfunction interceptLinks() {\r\n\t\twindow.document.body.addEventListener(\r\n\t\t\tdocument.ontouchstart ? 'touchstart' : 'click',\r\n\t\t\tfunction (e) {\r\n\t\t\t\tif (\r\n\t\t\t\t\te.metaKey ||\r\n\t\t\t\t\te.ctrlKey ||\r\n\t\t\t\t\te.shiftKey ||\r\n\t\t\t\t\te.defaultPrevented\r\n\t\t\t\t) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// ensure link\r\n\t\t\t\t// use shadow dom when available if not, fall back to composedPath()\r\n\t\t\t\t// for browsers that only have shady\r\n\t\t\t\tlet el = e.target\r\n\r\n\t\t\t\tlet eventPath: any = e.composedPath()\r\n\t\t\t\tif (eventPath) {\r\n\t\t\t\t\tfor (let i = 0; i < eventPath.length; i++) {\r\n\t\t\t\t\t\tif (!eventPath[i].nodeName) continue\r\n\t\t\t\t\t\tif (eventPath[i].nodeName.toUpperCase() !== 'A') continue\r\n\t\t\t\t\t\tif (!eventPath[i].href) continue\r\n\r\n\t\t\t\t\t\tel = eventPath[i]\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (el == null) return\r\n\t\t\t\t// allow skipping link\r\n\t\t\t\t// @ts-ignore\r\n\t\t\t\tif (el.hasAttribute('native')) return\r\n\r\n\t\t\t\tlet ret = validLink(el, PineconeRouter.settings.hash)\r\n\r\n\t\t\t\tif (!ret.valid) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\r\n\t\t\t\tlet route = PineconeRouter.routes[findRouteIndex(PineconeRouter.context.route)] ?? PineconeRouter.notfound\r\n\r\n\t\t\t\t// stop handlers in progress before navigating to the next page\r\n\t\t\t\tif (!route.handlersDone) {\r\n\t\t\t\t\troute.cancelHandlers = true\r\n\t\t\t\t\tendLoading()\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// prevent default behavior.\r\n\t\t\t\tif (e.stopImmediatePropagation) e.stopImmediatePropagation()\r\n\t\t\t\tif (e.stopPropagation) e.stopPropagation()\r\n\t\t\t\te.preventDefault()\r\n\t\t\t\tnavigate(ret.link)\r\n\t\t\t}\r\n\t\t)\r\n\t}\r\n\r\n\t/**\r\n\t * Go to the specified path without reloading\r\n\t * @param {string} path the path with no hash even if using hash routing\r\n\t * @param {boolean} fromPopState this will be set to true if called from window.onpopstate event\r\n\t * @param {boolean} firstLoad this will be set to true if this is the first page loaded, also from page reload\r\n\t */\r\n\tasync function navigate(path, fromPopState = false, firstLoad = false) {\r\n\t\tif (!path) path = '/'\r\n\t\tPineconeRouter.context.path = path\r\n\r\n\t\t// only add basePath if it was set\r\n\t\t// if not using hash routing\r\n\t\t// and if it wasn't added already\r\n\t\tif (!PineconeRouter.settings.hash) {\r\n\t\t\tif (\r\n\t\t\t\tPineconeRouter.settings.basePath != '/' &&\r\n\t\t\t\t!path.startsWith(PineconeRouter.settings.basePath)\r\n\t\t\t) {\r\n\t\t\t\tpath = PineconeRouter.settings.basePath + path\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\tpath == PineconeRouter.settings.basePath &&\r\n\t\t\t\t!path.endsWith('/')\r\n\t\t\t) {\r\n\t\t\t\tpath += '/'\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst route: Route = PineconeRouter.routes.find(\r\n\t\t\t(route: Route) => {\r\n\t\t\t\tlet m = match(path, route.path)\r\n\t\t\t\troute.params = m != false ? m : {}\r\n\t\t\t\treturn m != false\r\n\t\t\t}\r\n\t\t) ?? PineconeRouter.notfound\r\n\r\n\t\t// if the route has handlres, it will mark them unhandled\r\n\t\t// this is so templates wont render till then.\r\n\t\troute.handlersDone = !route.handlers.length\r\n\r\n\t\tif (route.handlers.length || route.template) {\r\n\t\t\tstartLoading()\r\n\t\t}\r\n\r\n\t\tlet context = buildContext(route.path, path, route.params)\r\n\r\n\t\tPineconeRouter.context = context\r\n\r\n\t\t// the middleware may return 'stop' to stop execution of this function\r\n\t\tif (\r\n\t\t\tmiddleware('onBeforeHandlersExecuted', route, path, firstLoad) == 'stop'\r\n\t\t) {\r\n\t\t\tendLoading()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\r\n\t\t// do not call pushstate from popstate event https://stackoverflow.com/a/50830905\r\n\t\tif (!fromPopState) {\r\n\t\t\tlet fullPath = ''\r\n\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\tfullPath = '#'\r\n\t\t\t\tfullPath += window.location.search + path\r\n\t\t\t} else {\r\n\t\t\t\tfullPath = path + window.location.search + window.location.hash\r\n\t\t\t}\r\n\t\t\t// don't create duplicate history entry on first page load\r\n\t\t\tif (!firstLoad) history.pushState({ path: fullPath }, '', fullPath)\r\n\t\t\telse {\r\n\t\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\t\tif (path == '/') {\r\n\t\t\t\t\t\tPineconeRouter.context = context\r\n\t\t\t\t\t\treturn navigate('/', false, false)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (\r\n\t\t\t(route && route.handlers.length)\r\n\t\t) {\r\n\t\t\troute.cancelHandlers = false\r\n\t\t\tlet ok = await handle(route.handlers, context)\r\n\t\t\tif (!ok) {\r\n\t\t\t\tendLoading()\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\troute.handlersDone = true\r\n\t\t\tif (!route.template) endLoading()\r\n\t\t}\r\n\r\n\r\n\t\tmiddleware('onHandlersExecuted', route, path, firstLoad)\r\n\t}\r\n\r\n\tfunction buildContext(route: string, path: string, params: {}): Context {\r\n\t\treturn {\r\n\t\t\troute: route,\r\n\t\t\tpath: path,\r\n\t\t\tparams: params,\r\n\t\t\tquery: window.location.search.substring(1), // query w/out leading '?'\r\n\t\t\thash: window.location.hash.substring(1), // hash without leading '#'\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction modifierValue(modifiers, key, fallback) {\r\n\t\t// If the modifier isn't present, use the default.\r\n\t\tif (modifiers.indexOf(key) === -1) return fallback\r\n\r\n\t\t// If it IS present, grab the value after it\r\n\t\tconst rawValue = modifiers[modifiers.indexOf(key) + 1]\r\n\r\n\t\tif (!rawValue) return fallback\r\n\r\n\t\tif (key === 'target') {\r\n\t\t\tlet match = rawValue.match(/([a-z0-9_-]+)/)\r\n\t\t\tif (match) return match[1]\r\n\t\t}\r\n\t\treturn rawValue\r\n\t}\r\n\t/**\r\n\t * execute the handlers of routes that are given passing them the context.\r\n\t */\r\n\tasync function handle(handlers, context) {\r\n\t\tfor (let i = 0; i < handlers.length; i++) {\r\n\t\t\tif (typeof handlers[i] == 'function') {\r\n\t\t\t\t// stop if the handlers were canceled for example the user clicked a link\r\n\t\t\t\tlet route = PineconeRouter.routes[findRouteIndex(context.route)] ?? PineconeRouter.notfound\r\n\t\t\t\tif (route.cancelHandlers) {\r\n\t\t\t\t\troute.cancelHandlers = false\r\n\t\t\t\t\treturn false\r\n\t\t\t\t}\r\n\t\t\t\tlet result\r\n\t\t\t\tif (handlers[i].constructor.name === 'AsyncFunction')\r\n\t\t\t\t\tresult = await handlers[i](context)\r\n\t\t\t\telse\r\n\t\t\t\t\tresult = handlers[i](context)\r\n\t\t\t\t// if the handler redirected, return\r\n\t\t\t\tif (result == 'stop') return false\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n}\r\n\r\n", "import magic from '../src/index.js'\r\n\r\nexport default magic\r\n"],
- "mappings": "AAEA,IAAMA,EAAN,KAAY,CAIX,YAAYC,EAAcC,EAAU,CAAC,EAAG,CAHxC,YAAiC,CAAC,EAElC,cAAsB,CAAC,EAQvB,kBAAwB,GANvB,KAAK,KAAOD,EACZ,OAAO,KAAKC,CAAO,EAAE,QAASC,GAAQ,CACrC,KAAKA,GAAOD,EAAQC,EACrB,CAAC,CACF,CAID,EAEOC,EAAQJ,ECjBf,IAAIK,EAAa,OAAO,SAQxB,SAASC,EAAWC,EAAuB,CAC1C,OAAOA,EAAI,QAAQ,eAAgB,EAAE,EAAE,MAAM,GAAG,CACjD,CAUO,SAASC,EAAMD,EAAaE,EAAmC,CACrE,IAAIC,EAAM,wBACTC,EAAIJ,EAAI,MAAMG,CAAG,EACjBE,EAAe,CAAC,EAChBC,EACD,GAAIF,GAAKA,EAAE,GAAI,CACd,IAAIG,EAAIH,EAAE,GAAG,MAAM,GAAG,EACtB,QAASI,EAAI,EAAGA,EAAID,EAAE,OAAQC,IAAK,CAClC,IAAIC,EAAIF,EAAEC,GAAG,MAAM,GAAG,EACtBH,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S,EAAM,aAAe,GAChBA,EAAM,UAAUT,EAAW,CACjC,CAGAQ,EAAW,qBAAsBC,EAAO1B,EAAMyC,CAAS,CACxD,CAEA,SAASI,EAAanB,EAAe1B,EAAcgD,EAAqB,CACvE,MAAO,CACN,MAAOtB,EACP,KAAM1B,EACN,OAAQgD,EACR,MAAO,OAAO,SAAS,OAAO,UAAU,CAAC,EACzC,KAAM,OAAO,SAAS,KAAK,UAAU,CAAC,EACtC,SAAShD,EAAM,CACd,OAAAC,EAASD,CAAI,EACN,MACR,EACA,SAASA,EAAM,CACdC,EAASD,CAAI,CACd,CACD,CACD,CAEA,SAASkC,EAAcH,EAAWkB,EAAKC,EAAU,CAEhD,GAAInB,EAAU,QAAQkB,CAAG,IAAM,GAAI,OAAOC,EAG1C,IAAMC,EAAWpB,EAAUA,EAAU,QAAQkB,CAAG,EAAI,GAEpD,GAAI,CAACE,EAAU,OAAOD,EAEtB,GAAID,IAAQ,SAAU,CACrB,IAAIN,EAAQQ,EAAS,MAAM,eAAe,EAC1C,GAAIR,EAAO,OAAOA,EAAM,EACzB,CACA,OAAOQ,CACR,CAIA,eAAeJ,EAAOnB,EAAUgB,EAAS,CACxC,QAAS,EAAI,EAAG,EAAIhB,EAAS,OAAQ,IACpC,GAAI,OAAOA,EAAS,IAAM,WAAY,CAErC,IAAIF,EAAQ5B,EAAe,OAAOyB,EAAeqB,EAAQ,KAAK,IAAM9C,EAAe,SACnF,GAAI4B,EAAM,eACT,OAAAA,EAAM,eAAiB,GAChB,GAER,IAAI0B,EAMJ,GALIxB,EAAS,GAAG,YAAY,OAAS,gBACpCwB,EAAS,MAAMxB,EAAS,GAAGgB,CAAO,EAElCQ,EAASxB,EAAS,GAAGgB,CAAO,EAEzBQ,GAAU,OAAQ,MAAO,EAC9B,CAED,MAAO,EACR,CACD,CClkBA,IAAOC,EAAQC",
- "names": ["Route", "path", "options", "opt", "route_default", "isLocation", "segmentize", "url", "match", "routePath", "reg", "c", "matches", "ret", "p", "i", "r", "urlSeg", "route", "max", "param", "flags", "plus", "star", "val", "toURL", "href", "anc", "sameOrigin", "loc", "samePath", "validLink", "el", "hash", "svg", "middleware", "func", "args", "plugin", "fetchError", "error", "src_default", "Alpine", "PineconeRouter", "route_default", "path", "navigate", "options", "r", "loadingTemplates", "cachedTemplates", "loadTemplate", "el", "url", "target", "html", "err", "fetchError", "addIf", "routeIndex", "route_expression", "expression", "endLoading", "removeIf", "insertHtmlInTarget", "targetEl", "startLoading", "addBasePath", "findRouteIndex", "cleanup", "middleware", "route", "evaluate", "handlers", "evaluatedExpression", "i", "modifiers", "effect", "isPreloading", "modifierValue", "interceptLinks", "e", "eventPath", "ret", "validLink", "fromPopState", "firstLoad", "m", "match", "context", "buildContext", "fullPath", "handle", "params", "key", "fallback", "rawValue", "result", "module_default", "src_default"]
+ "sourcesContent": ["import type { Handler } from './types'\r\n\r\nclass Route {\r\n\tparams: { [key: string]: any } = {}\r\n\tpath: string\r\n\thandlers: Handler[] = []\r\n\tconstructor(path: string, options = {}) {\r\n\t\tthis.path = path\r\n\t\tObject.keys(options).forEach((opt) => {\r\n\t\t\tthis[opt] = options[opt]\r\n\t\t})\r\n\t}\r\n\ttemplate: ''\r\n\thandlersDone: boolean = false\r\n\tcancelHandlers: boolean\r\n}\r\n\r\nexport default Route\r\n", "var isLocation = window.location\r\n\r\n/**\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param url url to segmentize\r\n * @returns\r\n */\r\nfunction segmentize(url: string): string[] {\r\n\treturn url.replace(/(^\\/+|\\/+$)/g, '').split('/')\r\n}\r\n\r\n/**\r\n * check if a path match with this route\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param path {string}\r\n * @param routePath {string}\r\n * @returns {false|object}\r\n */\r\nexport function match(url: string, routePath: string): false | object {\r\n\tlet reg = /(?:\\?([^#]*))?(#.*)?$/,\r\n\t\tc = url.match(reg),\r\n\t\tmatches: any = {},\r\n\t\tret\r\n\tif (c && c[1]) {\r\n\t\tlet p = c[1].split('&')\r\n\t\tfor (let i = 0; i < p.length; i++) {\r\n\t\t\tlet r = p[i].split('=')\r\n\t\t\tmatches[decodeURIComponent(r[0])] = decodeURIComponent(\r\n\t\t\t\tr.slice(1).join('=')\r\n\t\t\t)\r\n\t\t}\r\n\t}\r\n\tlet urlSeg = segmentize(url.replace(reg, '')),\r\n\t\troute: string[] = segmentize(routePath || ''),\r\n\t\tmax = Math.max(urlSeg.length, route.length)\r\n\tfor (let i = 0; i < max; i++) {\r\n\t\tif (route[i] && route[i].charAt(0) === ':') {\r\n\t\t\tlet param: string = route[i].replace(/(^:|[+*?]+$)/g, ''),\r\n\t\t\t\tflags: string = (route[i].match(/[+*?]+$/) || {}).toString()[0],\r\n\t\t\t\tplus = ~flags.indexOf('+'),\r\n\t\t\t\tstar = ~flags.indexOf('*'),\r\n\t\t\t\tval = urlSeg[i] || ''\r\n\t\t\tif (!val && !star && (flags.indexOf('?') < 0 || plus)) {\r\n\t\t\t\tret = false\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\tmatches[param] = decodeURIComponent(val)\r\n\t\t\tif (plus || star) {\r\n\t\t\t\tmatches[param] = urlSeg\r\n\t\t\t\t\t.slice(i)\r\n\t\t\t\t\t.map(decodeURIComponent)\r\n\t\t\t\t\t.join('/')\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t} else if (route[i] !== urlSeg[i]) {\r\n\t\t\tret = false\r\n\t\t\tbreak\r\n\t\t}\r\n\t}\r\n\tif (ret === false) return false\r\n\treturn matches\r\n}\r\n\r\n/**\r\n * Convert to a URL object\r\n * https://github.com/visionmedia/page.js/blob/4f9991658f9b9e3de9b6059bade93693af24d6bd/page.js#L888\r\n */\r\nfunction toURL(href: string): URL | HTMLAnchorElement {\r\n\tif (typeof URL === 'function' && isLocation) {\r\n\t\treturn new URL(href, window.location.toString())\r\n\t} else {\r\n\t\tvar anc = window.document.createElement('a')\r\n\t\tanc.href = href\r\n\t\treturn anc\r\n\t}\r\n}\r\n\r\n/**\r\n * Check if `href` is the same origin.\r\n * https://github.com/visionmedia/page.js/blob/4f9991658f9b9e3de9b6059bade93693af24d6bd/page.js#L888\r\n */\r\nexport function sameOrigin(href: string) {\r\n\tif (!href || !isLocation) return false\r\n\r\n\tvar url = toURL(href)\r\n\tvar loc = window.location\r\n\r\n\t/*\r\n\tWhen the port is the default http port 80 for http, or 443 for\r\n\thttps, internet explorer 11 returns an empty string for loc.port,\r\n\tso we need to compare loc.port with an empty string if url.port\r\n\tis the default port 80 or 443.\r\n\tAlso the comparison with `port` is changed from `===` to `==` because\r\n\t`port` can be a string sometimes. This only applies to ie11.\r\n\t*/\r\n\treturn (\r\n\t\tloc.protocol === url.protocol &&\r\n\t\tloc.hostname === url.hostname &&\r\n\t\t(loc.port === url.port ||\r\n\t\t\t(loc.port === '' && (url.port == '80' || url.port == '443')))\r\n\t) // jshint ignore:line\r\n}\r\n\r\nexport function samePath(url: any) {\r\n\tif (!isLocation) return false\r\n\tvar loc = window.location\r\n\treturn url.pathname === loc.pathname && url.search === loc.search\r\n}\r\n\r\n/**\r\n * Check if the anchor element point to a navigation route.\r\n * @param {any} el The anchor element or Event target\r\n * @param {boolean} hash Set to true when using hash routing\r\n * @returns {object} {valid: boolean, link: string}\r\n */\r\nexport function validLink(\r\n\tel: any,\r\n\thash: boolean\r\n): { valid: boolean; link: string } {\r\n\t// the object we'll return\r\n\tlet ret = { valid: false, link: '' }\r\n\r\n\t// The checks in this block are taken from\r\n\t// https://github.com/visionmedia/page.js/blob/master/index.js#L370\r\n\r\n\t// continue ensure link\r\n\r\n\t// el.nodeName for svg links are 'a' instead of 'A'\r\n\t// traverse up till we find an anchor tag, since clicks\r\n\t// on image links for example set the target as img instead of a.\r\n\twhile (el && 'A' !== el.nodeName.toUpperCase()) el = el.parentNode\r\n\tif (!el || 'A' !== el.nodeName.toUpperCase()) return ret\r\n\r\n\t// check if link is inside an svg\r\n\t// in this case, both href and target are always inside an object\r\n\tvar svg =\r\n\t\ttypeof el.href === 'object' &&\r\n\t\tel.href.constructor.name === 'SVGAnimatedString'\r\n\r\n\t// Ignore if tag has\r\n\t// 1. \"download\" attribute\r\n\t// 2. rel=\"external\" attribute\r\n\tif (el.hasAttribute('download') || el.getAttribute('rel') === 'external') {\r\n\t\treturn ret\r\n\t}\r\n\r\n\t// ensure non-hash for the same path\r\n\tret.link = el.getAttribute('href') ?? ''\r\n\tif (!hash && samePath(el) && (el.hash || '#' === ret.link)) {\r\n\t\treturn ret\r\n\t}\r\n\r\n\t// Check for mailto: in the href\r\n\tif (ret.link && ret.link.indexOf('mailto:') > -1) return ret\r\n\r\n\t// check target\r\n\t// svg target is an object and its desired value is in .baseVal property\r\n\tif (svg ? el.target.baseVal : el.target) return ret\r\n\r\n\t// x-origin\r\n\t// note: svg links that are not relative don't call click events (and skip page.js)\r\n\t// consequently, all svg links tested inside page.js are relative and in the same origin\r\n\tif (!svg && !sameOrigin(el.href)) return ret\r\n\r\n\tret.valid = true\r\n\treturn ret\r\n}\r\n\r\n/**\r\n * Call a function on all middlewares loaded, if any.\r\n * @param {string} func middleware function to call.\r\n * @param {any} args arguments to pass to the function.\r\n * @returns {boolean} false if the middleware function return false, i.e. it want to stop execution of the function and return.\r\n */\r\nexport function middleware(func: string, ...args: any): string | undefined {\r\n\tif (!window.PineconeRouterMiddlewares) return\r\n\tfor (const i in window.PineconeRouterMiddlewares) {\r\n\t\tlet plugin: any = window.PineconeRouterMiddlewares[i]\r\n\t\tif (plugin[func] == null) return\r\n\t\tlet ret = plugin[func](...args)\r\n\t\t// the return of the function will only be 'stop'\r\n\t\t// if the middleware request stopping the navigate function.\r\n\t\tif (ret == 'stop') return 'stop'\r\n\t}\r\n}\r\n\r\nexport function fetchError(error: string) {\r\n\tdocument.dispatchEvent(\r\n\t\tnew CustomEvent('fetch-error', { detail: error })\r\n\t)\r\n}", "import Route from './route'\r\nimport type { Settings, Context, Middleware, Handler } from './types'\r\nimport { fetchError, match, middleware, validLink } from './utils'\r\n\r\n\r\ndeclare global {\r\n\tinterface Window {\r\n\t\tPineconeRouter: {\r\n\t\t\tversion: string\r\n\t\t\tname: string\r\n\t\t\tsettings: Settings\r\n\t\t\tnotfound: Route\r\n\t\t\troutes: Route[]\r\n\t\t\tcontext: Context\r\n\t\t\tloadStart: Event\r\n\t\t\tloadEnd: Event\r\n\t\t\tadd: (path: string, options?: {}) => number\r\n\t\t\tremove: (path: string) => void\r\n\t\t}\r\n\t\tPineconeRouterMiddlewares: Array\r\n\t}\r\n}\r\n\r\nexport default function (Alpine) {\r\n\r\n\tconst PineconeRouter = Alpine.reactive({\r\n\t\tversion: '4.0.3',\r\n\t\tname: 'pinecone-router',\r\n\r\n\t\tsettings: {\r\n\t\t\thash: false,\r\n\t\t\tbasePath: '/',\r\n\t\t\ttemplateTargetId: null\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * @description The handler for 404 pages, can be overwritten by a notfound route\r\n\t\t */\r\n\t\tnotfound: new Route('notfound'),\r\n\r\n\t\t/**\r\n\t\t * @type Route[]\r\n\t\t * @summary array of routes instantiated from the Route class.\r\n\t\t */\r\n\t\troutes: [],\r\n\r\n\t\t/**\r\n\t\t * @type {Context}\r\n\t\t * @summary The context object for current path.\r\n\t\t */\r\n\t\tcontext: {\r\n\t\t\troute: '',\r\n\t\t\tpath: '',\r\n\t\t\tparams: {},\r\n\t\t\tquery: window.location.search.substring(1),\r\n\t\t\thash: window.location.hash.substring(1),\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Add a new route\r\n\t\t */\r\n\t\tadd(path: string, options?: {}) {\r\n\t\t\t// check if the route was registered on the same router.\r\n\t\t\tif (this.routes.find((r: Route) => r.path == path) != null) {\r\n\t\t\t\tthrow new Error('Pinecone Router: route already exist')\r\n\t\t\t}\r\n\r\n\t\t\treturn this.routes.push(new Route(path, options)) - 1\r\n\t\t},\r\n\t\t/**\r\n\t\t * Remove a route\r\n\t\t */\r\n\t\tremove(path: string) {\r\n\t\t\tthis.routes = this.routes.filter((r: Route) => r.path != path)\r\n\t\t},\r\n\t\t/**\r\n\t\t * @event pinecone-start\r\n\t\t * @summary be dispatched to the window after before page start loading.\r\n\t\t */\r\n\t\tloadStart: new Event('pinecone-start'),\r\n\r\n\t\t/**\r\n\t\t * @event pinecone-end\r\n\t\t * @summary will be dispatched to the window after the views are fetched\r\n\t\t */\r\n\t\tloadEnd: new Event('pinecone-end'),\r\n\t})\r\n\r\n\twindow.PineconeRouter = PineconeRouter\r\n\r\n\tvar loadingTemplates: { [key: string]: Promise } = {}\r\n\tvar cachedTemplates: { [key: string]: string } = {}\r\n\r\n\tconst loadTemplate = (el: HTMLElement, url: string, target: string | null): Promise => {\r\n\t\tif (loadingTemplates[url]) {\r\n\t\t\tloadingTemplates[url].then(html => {\r\n\t\t\t\tif (target == null) {\r\n\t\t\t\t\tel.innerHTML = html\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t\t} else {\r\n\t\t\tloadingTemplates[url] = fetch(url).then(r => {\r\n\t\t\t\tif (r.ok) return r.text()\r\n\t\t\t\tthrow new Error(String(r.status))\r\n\t\t\t}).then(html => {\r\n\t\t\t\tcachedTemplates[url] = html\r\n\t\t\t\tif (target == null) {\r\n\t\t\t\t\tel.innerHTML = html\r\n\t\t\t\t}\r\n\t\t\t\treturn html\r\n\t\t\t}).catch(err => {\r\n\t\t\t\tfetchError(err)\r\n\t\t\t\t// returning a value is a must because we are assigning returned value to loadingTemplates[url]\r\n\t\t\t\t// by returning a null it will refetch again when the route is (re)visited\r\n\t\t\t\treturn null\r\n\t\t\t})\r\n\t\t}\r\n\t\treturn loadingTemplates[url]\r\n\t}\r\n\r\n\tconst addIf = (el: HTMLElement, routeIndex, path) => {\r\n\t\t// this make sure inline templates dont render until handlers are done\r\n\t\tlet route_expression = (routeIndex != null) ? `PineconeRouter.routes[${routeIndex}]` : 'PineconeRouter.notfound'\r\n\t\tlet expression = `$router.route == \"${path}\" && ${route_expression}.handlersDone`\r\n\t\tif (el.hasAttribute(\"x-if\")) return\r\n\t\tel.setAttribute(\"x-if\", expression)\r\n\t\tendLoading()\r\n\t}\r\n\r\n\tconst removeIf = (el: HTMLElement) => {\r\n\t\tif (!el.hasAttribute(\"x-if\")) return\r\n\t\tel.removeAttribute(\"x-if\")\r\n\t}\r\n\r\n\tconst insertHtmlInTarget = (targetEl: HTMLElement, url: string) => {\r\n\t\tendLoading()\r\n\t\ttargetEl.innerHTML = cachedTemplates[url]\r\n\t}\r\n\r\n\tconst startLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadStart)\r\n\t}\r\n\r\n\tconst endLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadEnd)\r\n\t}\r\n\r\n\tconst addBasePath = (path) => {\r\n\t\tif (!PineconeRouter.settings.hash && PineconeRouter.settings.basePath != '/') {\r\n\t\t\treturn PineconeRouter.settings.basePath + path\r\n\t\t} return path\r\n\t}\r\n\r\n\tconst findRouteIndex = (path) => {\r\n\t\treturn PineconeRouter.routes.findIndex(\r\n\t\t\t(r) => r.path == path\r\n\t\t)\r\n\t}\r\n\r\n\tAlpine.directive(\r\n\t\t'route',\r\n\t\t(el: HTMLTemplateElement, { expression }, { cleanup }) => {\r\n\t\t\tlet path = expression\r\n\r\n\t\t\tmiddleware('onBeforeRouteProcessed', el, path)\r\n\r\n\t\t\tif (path.indexOf('#') > -1) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: A route's path may not have a hash character.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\r\n\t\t\tlet routeIndex = null\r\n\r\n\t\t\tif (path != 'notfound') {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// register the new route if possible\r\n\t\t\t\trouteIndex = PineconeRouter.add(path)\r\n\t\t\t}\r\n\r\n\t\t\t// add if statement for inline template\r\n\t\t\tif (el.content.firstElementChild != null) {\r\n\t\t\t\tlet route = PineconeRouter.routes[routeIndex] ?? PineconeRouter.notfound\r\n\t\t\t\taddIf(el, routeIndex, path)\r\n\t\t\t}\r\n\r\n\t\t\tmiddleware('onAfterRouteProcessed', el, path)\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tPineconeRouter.remove(path)\r\n\t\t\t\tremoveIf(el)\r\n\t\t\t})\r\n\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'handler',\r\n\t\t(\r\n\t\t\tel,\r\n\t\t\t{ expression },\r\n\t\t\t{ evaluate, cleanup }\r\n\t\t) => {\r\n\t\t\tif (!el.hasAttribute('x-route')) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: x-handler must be set on the same element as x-route.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\tlet handlers\r\n\r\n\t\t\t// check if the handlers expression is an array\r\n\t\t\t// if not make it one\r\n\t\t\tif (\r\n\t\t\t\t!(expression.startsWith('[') && expression.endsWith(']')) &&\r\n\t\t\t\t!(expression.startsWith('Array(') && expression.endsWith(')'))\r\n\t\t\t) {\r\n\t\t\t\texpression = `[${expression}]`\r\n\t\t\t}\r\n\r\n\t\t\tlet evaluatedExpression = evaluate(expression)\r\n\t\t\tlet path = el.getAttribute('x-route')\r\n\r\n\t\t\tif (typeof evaluatedExpression == 'object')\r\n\t\t\t\thandlers = evaluatedExpression\r\n\t\t\telse {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: Invalid handler type: ${typeof evaluatedExpression}.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\t// add `this` context for handlers inside an Alpine.component\r\n\t\t\tfor (let index = 0; index < handlers.length; index++) {\r\n\t\t\t\thandlers[index] = handlers[index].bind(Alpine.$data(el))\r\n\t\t\t}\r\n\r\n\t\t\tlet route\r\n\r\n\t\t\tif (path == 'notfound')\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\telse {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// add handlers to the route\r\n\t\t\t\tlet i = findRouteIndex(path)\r\n\t\t\t\troute = PineconeRouter.routes[i]\r\n\t\t\t}\r\n\t\t\troute.handlers = handlers\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\troute.handlers = []\r\n\t\t\t\troute.handlersDone = true\r\n\t\t\t})\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'template',\r\n\t\t(el: HTMLTemplateElement, { modifiers, expression }, { Alpine, effect, cleanup }) => {\r\n\r\n\t\t\tif (!el.hasAttribute(\"x-route\")) throw new Error(\"Pinecone Router: x-template must be used on the same element as x-route.\")\r\n\r\n\t\t\tvar isPreloading: any\r\n\t\t\tlet url: string = expression\r\n\r\n\t\t\tlet target = modifierValue(modifiers, 'target', null) ?? window.PineconeRouter.settings.templateTargetId\r\n\t\t\tlet targetEl = document.getElementById(target)\r\n\r\n\t\t\tif (target && !targetEl)\r\n\t\t\t\tthrow new Error(\"Pinecone Router: Can't find an element with the suplied x-template target ID (\" + target + \")\")\r\n\r\n\t\t\tif (modifiers.includes(\"preload\")) {\r\n\t\t\t\tisPreloading = loadTemplate(el, url, target).finally(() => {\r\n\t\t\t\t\tisPreloading = false\r\n\t\t\t\t\t// In case of failed fetch the template wont be cached\r\n\t\t\t\t\t// therefore we check for it and not add anything if it's null\r\n\t\t\t\t\tif (cachedTemplates[url] == null) return\r\n\t\t\t\t\tif (!target) addIf(el, routeIndex, path);\r\n\t\t\t\t})\r\n\t\t\t}\r\n\r\n\t\t\tlet path = el.getAttribute(\"x-route\")\r\n\t\t\tlet route;\r\n\t\t\tlet routeIndex\r\n\t\t\tif (path == 'notfound') {\r\n\t\t\t\tPineconeRouter.notfound.template = url\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\trouteIndex = findRouteIndex(path)\r\n\t\t\t\tPineconeRouter.routes[routeIndex].template = url\r\n\t\t\t\troute = PineconeRouter.routes[routeIndex]\r\n\t\t\t}\r\n\r\n\r\n\t\t\tAlpine.nextTick(() => {\r\n\t\t\t\teffect(() => {\r\n\t\t\t\t\tif (route.handlersDone && PineconeRouter.context.route == path) {\r\n\t\t\t\t\t\tif (cachedTemplates[url] != null) {\r\n\t\t\t\t\t\t\tif (!target) {\r\n\t\t\t\t\t\t\t\tendLoading()\r\n\t\t\t\t\t\t\t\tif (el.content.firstElementChild) return\r\n\t\t\t\t\t\t\t\tel.innerHTML = cachedTemplates[url]\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse insertHtmlInTarget(targetEl, url)\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tif (!isPreloading) {\r\n\t\t\t\t\t\t\t\tloadTemplate(el, url, target).finally(() => {\r\n\t\t\t\t\t\t\t\t\tif (cachedTemplates[url] == null) return\r\n\t\t\t\t\t\t\t\t\tif (!target) addIf(el, routeIndex, path)\r\n\t\t\t\t\t\t\t\t\telse insertHtmlInTarget(targetEl, url)\r\n\t\t\t\t\t\t\t\t})\r\n\t\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t\tisPreloading.finally(() => {\r\n\t\t\t\t\t\t\t\t\tif (cachedTemplates[url] == null) return\r\n\t\t\t\t\t\t\t\t\tif (target) {\r\n\t\t\t\t\t\t\t\t\t\tinsertHtmlInTarget(targetEl, url)\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t})\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t})\r\n\r\n\t\t\t})\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tdelete cachedTemplates[route.template]\r\n\t\t\t\troute.template = ''\r\n\t\t\t\tremoveIf(el)\r\n\t\t\t})\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.$router = PineconeRouter.context\r\n\tAlpine.magic('router', () => PineconeRouter.context)\r\n\r\n\tdocument.addEventListener('alpine:initialized', () => {\r\n\t\tmiddleware('init')\r\n\t\t// virtually navigate the path on the first page load\r\n\t\t// this will register the path in history and sets the pathvariable\r\n\t\t// navigate(window.location.pathname, false, true)\r\n\t\tif (!PineconeRouter.settings.hash) {\r\n\t\t\t// navigate to the current page to handle it\r\n\t\t\t// ONLY if we not using hash routing for the default router\r\n\t\t\tnavigate(location.pathname, false, true)\r\n\t\t} else {\r\n\t\t\tnavigate(location.hash.substring(1), false, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// handle navigation events not emitted by links, for example, back button.\r\n\twindow.addEventListener('popstate', () => {\r\n\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\tif (window.location.hash != '') {\r\n\t\t\t\tnavigate(window.location.hash.substring(1), true)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tnavigate(window.location.pathname, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// intercept click event in links\r\n\tinterceptLinks()\r\n\r\n\t/**\r\n\t * @description Add a handler to click events on all valid links\r\n\t */\r\n\tfunction interceptLinks() {\r\n\t\twindow.document.body.addEventListener(\r\n\t\t\tdocument.ontouchstart ? 'touchstart' : 'click',\r\n\t\t\tfunction (e) {\r\n\t\t\t\tif (\r\n\t\t\t\t\te.metaKey ||\r\n\t\t\t\t\te.ctrlKey ||\r\n\t\t\t\t\te.shiftKey ||\r\n\t\t\t\t\te.defaultPrevented\r\n\t\t\t\t) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// ensure link\r\n\t\t\t\t// use shadow dom when available if not, fall back to composedPath()\r\n\t\t\t\t// for browsers that only have shady\r\n\t\t\t\tlet el = e.target\r\n\r\n\t\t\t\tlet eventPath: any = e.composedPath()\r\n\t\t\t\tif (eventPath) {\r\n\t\t\t\t\tfor (let i = 0; i < eventPath.length; i++) {\r\n\t\t\t\t\t\tif (!eventPath[i].nodeName) continue\r\n\t\t\t\t\t\tif (eventPath[i].nodeName.toUpperCase() !== 'A') continue\r\n\t\t\t\t\t\tif (!eventPath[i].href) continue\r\n\r\n\t\t\t\t\t\tel = eventPath[i]\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (el == null) return\r\n\t\t\t\t// allow skipping link\r\n\t\t\t\t// @ts-ignore\r\n\t\t\t\tif (el.hasAttribute('native')) return\r\n\r\n\t\t\t\tlet ret = validLink(el, PineconeRouter.settings.hash)\r\n\r\n\t\t\t\tif (!ret.valid) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\r\n\t\t\t\tlet route = PineconeRouter.routes[findRouteIndex(PineconeRouter.context.route)] ?? PineconeRouter.notfound\r\n\r\n\t\t\t\t// stop handlers in progress before navigating to the next page\r\n\t\t\t\tif (!route.handlersDone) {\r\n\t\t\t\t\troute.cancelHandlers = true\r\n\t\t\t\t\tendLoading()\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// prevent default behavior.\r\n\t\t\t\tif (e.stopImmediatePropagation) e.stopImmediatePropagation()\r\n\t\t\t\tif (e.stopPropagation) e.stopPropagation()\r\n\t\t\t\te.preventDefault()\r\n\t\t\t\tnavigate(ret.link)\r\n\t\t\t}\r\n\t\t)\r\n\t}\r\n\r\n\t/**\r\n\t * Go to the specified path without reloading\r\n\t * @param {string} path the path with no hash even if using hash routing\r\n\t * @param {boolean} fromPopState this will be set to true if called from window.onpopstate event\r\n\t * @param {boolean} firstLoad this will be set to true if this is the first page loaded, also from page reload\r\n\t */\r\n\tasync function navigate(path, fromPopState = false, firstLoad = false) {\r\n\t\tif (!path) path = '/'\r\n\t\tPineconeRouter.context.path = path\r\n\r\n\t\t// only add basePath if it was set\r\n\t\t// if not using hash routing\r\n\t\t// and if it wasn't added already\r\n\t\tif (!PineconeRouter.settings.hash) {\r\n\t\t\tif (\r\n\t\t\t\tPineconeRouter.settings.basePath != '/' &&\r\n\t\t\t\t!path.startsWith(PineconeRouter.settings.basePath)\r\n\t\t\t) {\r\n\t\t\t\tpath = PineconeRouter.settings.basePath + path\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\tpath == PineconeRouter.settings.basePath &&\r\n\t\t\t\t!path.endsWith('/')\r\n\t\t\t) {\r\n\t\t\t\tpath += '/'\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst route: Route = PineconeRouter.routes.find(\r\n\t\t\t(route: Route) => {\r\n\t\t\t\tlet m = match(path, route.path)\r\n\t\t\t\troute.params = m != false ? m : {}\r\n\t\t\t\treturn m != false\r\n\t\t\t}\r\n\t\t) ?? PineconeRouter.notfound\r\n\r\n\t\t// if the route has handlres, it will mark them unhandled\r\n\t\t// this is so templates wont render till then.\r\n\t\troute.handlersDone = !route.handlers.length\r\n\r\n\t\tif (route.handlers.length || route.template) {\r\n\t\t\tstartLoading()\r\n\t\t}\r\n\r\n\t\tlet context = buildContext(route.path, path, route.params)\r\n\r\n\t\tPineconeRouter.context = context\r\n\r\n\t\t// the middleware may return 'stop' to stop execution of this function\r\n\t\tif (\r\n\t\t\tmiddleware('onBeforeHandlersExecuted', route, path, firstLoad) == 'stop'\r\n\t\t) {\r\n\t\t\tendLoading()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\r\n\t\t// do not call pushstate from popstate event https://stackoverflow.com/a/50830905\r\n\t\tif (!fromPopState) {\r\n\t\t\tlet fullPath = ''\r\n\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\tfullPath = '#'\r\n\t\t\t\tfullPath += window.location.search + path\r\n\t\t\t} else {\r\n\t\t\t\tfullPath = path + window.location.search + window.location.hash\r\n\t\t\t}\r\n\t\t\t// don't create duplicate history entry on first page load\r\n\t\t\tif (!firstLoad) history.pushState({ path: fullPath }, '', fullPath)\r\n\t\t\telse {\r\n\t\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\t\tif (path == '/') {\r\n\t\t\t\t\t\tPineconeRouter.context = context\r\n\t\t\t\t\t\treturn navigate('/', false, false)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (\r\n\t\t\t(route && route.handlers.length)\r\n\t\t) {\r\n\t\t\troute.cancelHandlers = false\r\n\t\t\tlet ok = await handle(route.handlers, context)\r\n\t\t\tif (!ok) {\r\n\t\t\t\tendLoading()\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\troute.handlersDone = true\r\n\t\t\tif (!route.template) endLoading()\r\n\t\t}\r\n\r\n\r\n\t\tmiddleware('onHandlersExecuted', route, path, firstLoad)\r\n\t}\r\n\r\n\tfunction buildContext(route: string, path: string, params: {}): Context {\r\n\t\treturn {\r\n\t\t\troute: route,\r\n\t\t\tpath: path,\r\n\t\t\tparams: params,\r\n\t\t\tquery: window.location.search.substring(1), // query w/out leading '?'\r\n\t\t\thash: window.location.hash.substring(1), // hash without leading '#'\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction modifierValue(modifiers, key, fallback) {\r\n\t\t// If the modifier isn't present, use the default.\r\n\t\tif (modifiers.indexOf(key) === -1) return fallback\r\n\r\n\t\t// If it IS present, grab the value after it\r\n\t\tconst rawValue = modifiers[modifiers.indexOf(key) + 1]\r\n\r\n\t\tif (!rawValue) return fallback\r\n\r\n\t\tif (key === 'target') {\r\n\t\t\tlet match = rawValue.match(/([a-z0-9_-]+)/)\r\n\t\t\tif (match) return match[1]\r\n\t\t}\r\n\t\treturn rawValue\r\n\t}\r\n\t/**\r\n\t * execute the handlers of routes that are given passing them the context.\r\n\t */\r\n\tasync function handle(handlers, context) {\r\n\t\tfor (let i = 0; i < handlers.length; i++) {\r\n\t\t\tif (typeof handlers[i] == 'function') {\r\n\t\t\t\t// stop if the handlers were canceled for example the user clicked a link\r\n\t\t\t\tlet route = PineconeRouter.routes[findRouteIndex(context.route)] ?? PineconeRouter.notfound\r\n\t\t\t\tif (route.cancelHandlers) {\r\n\t\t\t\t\troute.cancelHandlers = false\r\n\t\t\t\t\treturn false\r\n\t\t\t\t}\r\n\t\t\t\tlet result\r\n\t\t\t\tif (handlers[i].constructor.name === 'AsyncFunction')\r\n\t\t\t\t\tresult = await handlers[i](context)\r\n\t\t\t\telse\r\n\t\t\t\t\tresult = handlers[i](context)\r\n\t\t\t\t// if the handler redirected, return\r\n\t\t\t\tif (result == 'stop') return false\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n}\r\n\r\n", "import magic from '../src/index.js'\r\n\r\nexport default magic\r\n"],
+ "mappings": "AAEA,IAAMA,EAAN,KAAY,CAIX,YAAYC,EAAcC,EAAU,CAAC,EAAG,CAHxC,YAAiC,CAAC,EAElC,cAAsB,CAAC,EAQvB,kBAAwB,GANvB,KAAK,KAAOD,EACZ,OAAO,KAAKC,CAAO,EAAE,QAASC,GAAQ,CACrC,KAAKA,GAAOD,EAAQC,EACrB,CAAC,CACF,CAID,EAEOC,EAAQJ,ECjBf,IAAIK,EAAa,OAAO,SAQxB,SAASC,EAAWC,EAAuB,CAC1C,OAAOA,EAAI,QAAQ,eAAgB,EAAE,EAAE,MAAM,GAAG,CACjD,CAUO,SAASC,EAAMD,EAAaE,EAAmC,CACrE,IAAIC,EAAM,wBACTC,EAAIJ,EAAI,MAAMG,CAAG,EACjBE,EAAe,CAAC,EAChBC,EACD,GAAIF,GAAKA,EAAE,GAAI,CACd,IAAIG,EAAIH,EAAE,GAAG,MAAM,GAAG,EACtB,QAASI,EAAI,EAAGA,EAAID,EAAE,OAAQC,IAAK,CAClC,IAAIC,EAAIF,EAAEC,GAAG,MAA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CAED,MAAO,EACR,CACD,CCvkBA,IAAOC,EAAQC",
+ "names": ["Route", "path", "options", "opt", "route_default", "isLocation", "segmentize", "url", "match", "routePath", "reg", "c", "matches", "ret", "p", "i", "r", "urlSeg", "route", "max", "param", "flags", "plus", "star", "val", "toURL", "href", "anc", "sameOrigin", "loc", "samePath", "validLink", "el", "hash", "svg", "middleware", "func", "args", "plugin", "fetchError", "error", "src_default", "Alpine", "PineconeRouter", "route_default", "path", "navigate", "options", "r", "loadingTemplates", "cachedTemplates", "loadTemplate", "el", "url", "target", "html", "err", "fetchError", "addIf", "routeIndex", "route_expression", "expression", "endLoading", "removeIf", "insertHtmlInTarget", "targetEl", "startLoading", "addBasePath", "findRouteIndex", "cleanup", "middleware", "route", "evaluate", "handlers", "evaluatedExpression", "index", "i", "modifiers", "effect", "isPreloading", "modifierValue", "interceptLinks", "e", "eventPath", "ret", "validLink", "fromPopState", "firstLoad", "match", "context", "buildContext", "fullPath", "handle", "params", "key", "fallback", "rawValue", "result", "module_default", "src_default"]
}
diff --git a/dist/router.min.js b/dist/router.min.js
index 286af2d..0998d3f 100644
--- a/dist/router.min.js
+++ b/dist/router.min.js
@@ -1,2 +1,2 @@
-(()=>{var A=class{constructor(t,a={}){this.params={};this.handlers=[];this.handlersDone=!1;this.path=t,Object.keys(a).forEach(u=>{this[u]=a[u]})}},M=A;var I=window.location;function C(o){return o.replace(/(^\/+|\/+$)/g,"").split("/")}function S(o,t){let a=/(?:\?([^#]*))?(#.*)?$/,u=o.match(a),v={},x;if(u&&u[1]){let d=u[1].split("&");for(let w=0;w-1||(u?o.target.baseVal:o.target)||!u&&!N(o.href)||(a.valid=!0),a}function P(o,...t){if(!!window.PineconeRouterMiddlewares)for(let a in window.PineconeRouterMiddlewares){let u=window.PineconeRouterMiddlewares[a];if(u[o]==null)return;if(u[o](...t)=="stop")return"stop"}}function $(o){document.dispatchEvent(new CustomEvent("fetch-error",{detail:o}))}function D(o){let t=o.reactive({version:"4.0.2",name:"pinecone-router",settings:{hash:!1,basePath:"/",templateTargetId:null},notfound:new M("notfound"),routes:[],context:{route:"",path:"",params:{},query:window.location.search.substring(1),hash:window.location.hash.substring(1),redirect(e){return c(e),"stop"},navigate(e){c(e)}},add(e,r){if(this.routes.find(i=>i.path==e)!=null)throw new Error("Pinecone Router: route already exist");return this.routes.push(new M(e,r))-1},remove(e){this.routes=this.routes.filter(r=>r.path!=e)},loadStart:new Event("pinecone-start"),loadEnd:new Event("pinecone-end")});window.PineconeRouter=t;var a={},u={};let v=(e,r,i)=>(a[r]?a[r].then(n=>{i==null&&(e.innerHTML=n)}):a[r]=fetch(r).then(n=>{if(n.ok)return n.text();throw new Error(String(n.status))}).then(n=>(u[r]=n,i==null&&(e.innerHTML=n),n)).catch(n=>($(n),null)),a[r]),x=(e,r,i)=>{let n=r!=null?`PineconeRouter.routes[${r}]`:"PineconeRouter.notfound",s=`$router.route == "${i}" && ${n}.handlersDone`;e.hasAttribute("x-if")||(e.setAttribute("x-if",s),d())},b=e=>{!e.hasAttribute("x-if")||e.removeAttribute("x-if")},p=(e,r)=>{d(),e.innerHTML=u[r]},T=()=>{document.dispatchEvent(t.loadStart)},d=()=>{document.dispatchEvent(t.loadEnd)},w=e=>!t.settings.hash&&t.settings.basePath!="/"?t.settings.basePath+e:e,m=e=>t.routes.findIndex(r=>r.path==e);o.directive("route",(e,{expression:r},{cleanup:i})=>{let n=r;if(P("onBeforeRouteProcessed",e,n),n.indexOf("#")>-1)throw new Error("Pinecone Router: A route's path may not have a hash character.");let s=null;if(n!="notfound"&&(n=w(n),s=t.add(n)),e.content.firstElementChild!=null){let l=t.routes[s]??t.notfound;x(e,s,n)}P("onAfterRouteProcessed",e,n),i(()=>{t.remove(n),b(e)})}),o.directive("handler",(e,{expression:r},{evaluate:i,cleanup:n})=>{if(!e.hasAttribute("x-route"))throw new Error("Pinecone Router: x-handler must be set on the same element as x-route.");let s;!(r.startsWith("[")&&r.endsWith("]"))&&!(r.startsWith("Array(")&&r.endsWith(")"))&&(r=`[${r}]`);let l=i(r),h=e.getAttribute("x-route");if(typeof l=="object")s=l;else throw new Error(`Pinecone Router: Invalid handler type: ${typeof l}.`);let f;if(h=="notfound")f=t.notfound;else{h=w(h);let g=m(h);f=t.routes[g]}f.handlers=s,n(()=>{f.handlers=[],f.handlersDone=!0})}),o.directive("template",(e,{modifiers:r,expression:i},{Alpine:n,effect:s,cleanup:l})=>{if(!e.hasAttribute("x-route"))throw new Error("Pinecone Router: x-template must be used on the same element as x-route.");var h;let f=i,g=O(r,"target",null)??window.PineconeRouter.settings.templateTargetId,k=document.getElementById(g);if(g&&!k)throw new Error("Pinecone Router: Can't find an element with the suplied x-template target ID ("+g+")");r.includes("preload")&&(h=v(e,f,g).finally(()=>{h=!1,u[f]!=null&&(g||x(e,R,E))}));let E=e.getAttribute("x-route"),y,R;E=="notfound"?(t.notfound.template=f,y=t.notfound):(E=w(E),R=m(E),t.routes[R].template=f,y=t.routes[R]),n.nextTick(()=>{s(()=>{if(y.handlersDone&&t.context.route==E)if(u[f]!=null)if(g)p(k,f);else{if(d(),e.content.firstElementChild)return;e.innerHTML=u[f]}else h?h.finally(()=>{u[f]!=null&&g&&p(k,f)}):v(e,f,g).finally(()=>{u[f]!=null&&(g?p(k,f):x(e,R,E))})})}),l(()=>{delete u[y.template],y.template="",b(e)})}),o.$router=t.context,o.magic("router",()=>t.context),document.addEventListener("alpine:initialized",()=>{P("init"),t.settings.hash?c(location.hash.substring(1),!1,!0):c(location.pathname,!1,!0)}),window.addEventListener("popstate",()=>{t.settings.hash?window.location.hash!=""&&c(window.location.hash.substring(1),!0):c(window.location.pathname,!0)}),L();function L(){window.document.body.addEventListener(document.ontouchstart?"touchstart":"click",function(e){if(e.metaKey||e.ctrlKey||e.shiftKey||e.defaultPrevented)return;let r=e.target,i=e.composedPath();if(i){for(let l=0;l{let h=S(e,l.path);return l.params=h!=!1?h:{},h!=!1})??t.notfound;n.handlersDone=!n.handlers.length,(n.handlers.length||n.template)&&T();let s=H(n.path,e,n.params);if(t.context=s,P("onBeforeHandlersExecuted",n,e,i)=="stop"){d();return}if(!r){let l="";if(t.settings.hash?(l="#",l+=window.location.search+e):l=e+window.location.search+window.location.hash,!i)history.pushState({path:l},"",l);else if(t.settings.hash&&e=="/")return t.context=s,c("/",!1,!1)}if(n&&n.handlers.length){if(n.cancelHandlers=!1,!await W(n.handlers,s)){d();return}n.handlersDone=!0,n.template||d()}P("onHandlersExecuted",n,e,i)}function H(e,r,i){return{route:e,path:r,params:i,query:window.location.search.substring(1),hash:window.location.hash.substring(1),redirect(n){return c(n),"stop"},navigate(n){c(n)}}}function O(e,r,i){if(e.indexOf(r)===-1)return i;let n=e[e.indexOf(r)+1];if(!n)return i;if(r==="target"){let s=n.match(/([a-z0-9_-]+)/);if(s)return s[1]}return n}async function W(e,r){for(let i=0;i{window.Alpine.plugin(D)});})();
+(()=>{var A=class{constructor(e,a={}){this.params={};this.handlers=[];this.handlersDone=!1;this.path=e,Object.keys(a).forEach(u=>{this[u]=a[u]})}},M=A;var I=window.location;function C(o){return o.replace(/(^\/+|\/+$)/g,"").split("/")}function S(o,e){let a=/(?:\?([^#]*))?(#.*)?$/,u=o.match(a),v={},x;if(u&&u[1]){let d=u[1].split("&");for(let w=0;w-1||(u?o.target.baseVal:o.target)||!u&&!N(o.href)||(a.valid=!0),a}function P(o,...e){if(!!window.PineconeRouterMiddlewares)for(let a in window.PineconeRouterMiddlewares){let u=window.PineconeRouterMiddlewares[a];if(u[o]==null)return;if(u[o](...e)=="stop")return"stop"}}function U(o){document.dispatchEvent(new CustomEvent("fetch-error",{detail:o}))}function D(o){let e=o.reactive({version:"4.0.3",name:"pinecone-router",settings:{hash:!1,basePath:"/",templateTargetId:null},notfound:new M("notfound"),routes:[],context:{route:"",path:"",params:{},query:window.location.search.substring(1),hash:window.location.hash.substring(1),redirect(t){return h(t),"stop"},navigate(t){h(t)}},add(t,r){if(this.routes.find(i=>i.path==t)!=null)throw new Error("Pinecone Router: route already exist");return this.routes.push(new M(t,r))-1},remove(t){this.routes=this.routes.filter(r=>r.path!=t)},loadStart:new Event("pinecone-start"),loadEnd:new Event("pinecone-end")});window.PineconeRouter=e;var a={},u={};let v=(t,r,i)=>(a[r]?a[r].then(n=>{i==null&&(t.innerHTML=n)}):a[r]=fetch(r).then(n=>{if(n.ok)return n.text();throw new Error(String(n.status))}).then(n=>(u[r]=n,i==null&&(t.innerHTML=n),n)).catch(n=>(U(n),null)),a[r]),x=(t,r,i)=>{let n=r!=null?`PineconeRouter.routes[${r}]`:"PineconeRouter.notfound",s=`$router.route == "${i}" && ${n}.handlersDone`;t.hasAttribute("x-if")||(t.setAttribute("x-if",s),d())},b=t=>{!t.hasAttribute("x-if")||t.removeAttribute("x-if")},p=(t,r)=>{d(),t.innerHTML=u[r]},T=()=>{document.dispatchEvent(e.loadStart)},d=()=>{document.dispatchEvent(e.loadEnd)},w=t=>!e.settings.hash&&e.settings.basePath!="/"?e.settings.basePath+t:t,g=t=>e.routes.findIndex(r=>r.path==t);o.directive("route",(t,{expression:r},{cleanup:i})=>{let n=r;if(P("onBeforeRouteProcessed",t,n),n.indexOf("#")>-1)throw new Error("Pinecone Router: A route's path may not have a hash character.");let s=null;if(n!="notfound"&&(n=w(n),s=e.add(n)),t.content.firstElementChild!=null){let l=e.routes[s]??e.notfound;x(t,s,n)}P("onAfterRouteProcessed",t,n),i(()=>{e.remove(n),b(t)})}),o.directive("handler",(t,{expression:r},{evaluate:i,cleanup:n})=>{if(!t.hasAttribute("x-route"))throw new Error("Pinecone Router: x-handler must be set on the same element as x-route.");let s;!(r.startsWith("[")&&r.endsWith("]"))&&!(r.startsWith("Array(")&&r.endsWith(")"))&&(r=`[${r}]`);let l=i(r),m=t.getAttribute("x-route");if(typeof l=="object")s=l;else throw new Error(`Pinecone Router: Invalid handler type: ${typeof l}.`);for(let c=0;c{f.handlers=[],f.handlersDone=!0})}),o.directive("template",(t,{modifiers:r,expression:i},{Alpine:n,effect:s,cleanup:l})=>{if(!t.hasAttribute("x-route"))throw new Error("Pinecone Router: x-template must be used on the same element as x-route.");var m;let f=i,c=O(r,"target",null)??window.PineconeRouter.settings.templateTargetId,k=document.getElementById(c);if(c&&!k)throw new Error("Pinecone Router: Can't find an element with the suplied x-template target ID ("+c+")");r.includes("preload")&&(m=v(t,f,c).finally(()=>{m=!1,u[f]!=null&&(c||x(t,R,E))}));let E=t.getAttribute("x-route"),y,R;E=="notfound"?(e.notfound.template=f,y=e.notfound):(E=w(E),R=g(E),e.routes[R].template=f,y=e.routes[R]),n.nextTick(()=>{s(()=>{if(y.handlersDone&&e.context.route==E)if(u[f]!=null)if(c)p(k,f);else{if(d(),t.content.firstElementChild)return;t.innerHTML=u[f]}else m?m.finally(()=>{u[f]!=null&&c&&p(k,f)}):v(t,f,c).finally(()=>{u[f]!=null&&(c?p(k,f):x(t,R,E))})})}),l(()=>{delete u[y.template],y.template="",b(t)})}),o.$router=e.context,o.magic("router",()=>e.context),document.addEventListener("alpine:initialized",()=>{P("init"),e.settings.hash?h(location.hash.substring(1),!1,!0):h(location.pathname,!1,!0)}),window.addEventListener("popstate",()=>{e.settings.hash?window.location.hash!=""&&h(window.location.hash.substring(1),!0):h(window.location.pathname,!0)}),L();function L(){window.document.body.addEventListener(document.ontouchstart?"touchstart":"click",function(t){if(t.metaKey||t.ctrlKey||t.shiftKey||t.defaultPrevented)return;let r=t.target,i=t.composedPath();if(i){for(let l=0;l{let m=S(t,l.path);return l.params=m!=!1?m:{},m!=!1})??e.notfound;n.handlersDone=!n.handlers.length,(n.handlers.length||n.template)&&T();let s=H(n.path,t,n.params);if(e.context=s,P("onBeforeHandlersExecuted",n,t,i)=="stop"){d();return}if(!r){let l="";if(e.settings.hash?(l="#",l+=window.location.search+t):l=t+window.location.search+window.location.hash,!i)history.pushState({path:l},"",l);else if(e.settings.hash&&t=="/")return e.context=s,h("/",!1,!1)}if(n&&n.handlers.length){if(n.cancelHandlers=!1,!await W(n.handlers,s)){d();return}n.handlersDone=!0,n.template||d()}P("onHandlersExecuted",n,t,i)}function H(t,r,i){return{route:t,path:r,params:i,query:window.location.search.substring(1),hash:window.location.hash.substring(1),redirect(n){return h(n),"stop"},navigate(n){h(n)}}}function O(t,r,i){if(t.indexOf(r)===-1)return i;let n=t[t.indexOf(r)+1];if(!n)return i;if(r==="target"){let s=n.match(/([a-z0-9_-]+)/);if(s)return s[1]}return n}async function W(t,r){for(let i=0;i{window.Alpine.plugin(D)});})();
//# sourceMappingURL=router.min.js.map
diff --git a/dist/router.min.js.map b/dist/router.min.js.map
index 6ebe5ff..d6ff4f6 100644
--- a/dist/router.min.js.map
+++ b/dist/router.min.js.map
@@ -1,7 +1,7 @@
{
"version": 3,
"sources": ["../src/route.ts", "../src/utils.ts", "../src/index.ts", "../builds/cdn.js"],
- "sourcesContent": ["import type { Handler } from './types'\r\n\r\nclass Route {\r\n\tparams: { [key: string]: any } = {}\r\n\tpath: string\r\n\thandlers: Handler[] = []\r\n\tconstructor(path: string, options = {}) {\r\n\t\tthis.path = path\r\n\t\tObject.keys(options).forEach((opt) => {\r\n\t\t\tthis[opt] = options[opt]\r\n\t\t})\r\n\t}\r\n\ttemplate: ''\r\n\thandlersDone: boolean = false\r\n\tcancelHandlers: boolean\r\n}\r\n\r\nexport default Route\r\n", "var isLocation = window.location\r\n\r\n/**\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param url url to segmentize\r\n * @returns\r\n */\r\nfunction segmentize(url: string): string[] {\r\n\treturn url.replace(/(^\\/+|\\/+$)/g, '').split('/')\r\n}\r\n\r\n/**\r\n * check if a path match with this route\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param path {string}\r\n * @param routePath {string}\r\n * @returns {false|object}\r\n */\r\nexport function match(url: string, routePath: string): false | object {\r\n\tlet reg = /(?:\\?([^#]*))?(#.*)?$/,\r\n\t\tc = url.match(reg),\r\n\t\tmatches: any = {},\r\n\t\tret\r\n\tif (c && c[1]) {\r\n\t\tlet p = c[1].split('&')\r\n\t\tfor (let i = 0; i < p.length; i++) {\r\n\t\t\tlet r = p[i].split('=')\r\n\t\t\tmatches[decodeURIComponent(r[0])] = decodeURIComponent(\r\n\t\t\t\tr.slice(1).join('=')\r\n\t\t\t)\r\n\t\t}\r\n\t}\r\n\tlet urlSeg = segmentize(url.replace(reg, '')),\r\n\t\troute: string[] = segmentize(routePath || ''),\r\n\t\tmax = Math.max(urlSeg.length, route.length)\r\n\tfor (let i = 0; i < max; i++) {\r\n\t\tif (route[i] && route[i].charAt(0) === ':') {\r\n\t\t\tlet param: string = route[i].replace(/(^:|[+*?]+$)/g, ''),\r\n\t\t\t\tflags: string = (route[i].match(/[+*?]+$/) || {}).toString()[0],\r\n\t\t\t\tplus = ~flags.indexOf('+'),\r\n\t\t\t\tstar = ~flags.indexOf('*'),\r\n\t\t\t\tval = urlSeg[i] || ''\r\n\t\t\tif (!val && !star && (flags.indexOf('?') < 0 || plus)) {\r\n\t\t\t\tret = false\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\tmatches[param] = decodeURIComponent(val)\r\n\t\t\tif (plus || star) {\r\n\t\t\t\tmatches[param] = urlSeg\r\n\t\t\t\t\t.slice(i)\r\n\t\t\t\t\t.map(decodeURIComponent)\r\n\t\t\t\t\t.join('/')\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t} else if (route[i] !== urlSeg[i]) {\r\n\t\t\tret = false\r\n\t\t\tbreak\r\n\t\t}\r\n\t}\r\n\tif (ret === false) return false\r\n\treturn matches\r\n}\r\n\r\n/**\r\n * Convert to a URL object\r\n * https://github.com/visionmedia/page.js/blob/4f9991658f9b9e3de9b6059bade93693af24d6bd/page.js#L888\r\n */\r\nfunction toURL(href: string): URL | HTMLAnchorElement {\r\n\tif (typeof URL === 'function' && isLocation) {\r\n\t\treturn new URL(href, window.location.toString())\r\n\t} else {\r\n\t\tvar anc = window.document.createElement('a')\r\n\t\tanc.href = href\r\n\t\treturn anc\r\n\t}\r\n}\r\n\r\n/**\r\n * Check if `href` is the same origin.\r\n * https://github.com/visionmedia/page.js/blob/4f9991658f9b9e3de9b6059bade93693af24d6bd/page.js#L888\r\n */\r\nexport function sameOrigin(href: string) {\r\n\tif (!href || !isLocation) return false\r\n\r\n\tvar url = toURL(href)\r\n\tvar loc = window.location\r\n\r\n\t/*\r\n\tWhen the port is the default http port 80 for http, or 443 for\r\n\thttps, internet explorer 11 returns an empty string for loc.port,\r\n\tso we need to compare loc.port with an empty string if url.port\r\n\tis the default port 80 or 443.\r\n\tAlso the comparison with `port` is changed from `===` to `==` because\r\n\t`port` can be a string sometimes. This only applies to ie11.\r\n\t*/\r\n\treturn (\r\n\t\tloc.protocol === url.protocol &&\r\n\t\tloc.hostname === url.hostname &&\r\n\t\t(loc.port === url.port ||\r\n\t\t\t(loc.port === '' && (url.port == '80' || url.port == '443')))\r\n\t) // jshint ignore:line\r\n}\r\n\r\nexport function samePath(url: any) {\r\n\tif (!isLocation) return false\r\n\tvar loc = window.location\r\n\treturn url.pathname === loc.pathname && url.search === loc.search\r\n}\r\n\r\n/**\r\n * Check if the anchor element point to a navigation route.\r\n * @param {any} el The anchor element or Event target\r\n * @param {boolean} hash Set to true when using hash routing\r\n * @returns {object} {valid: boolean, link: string}\r\n */\r\nexport function validLink(\r\n\tel: any,\r\n\thash: boolean\r\n): { valid: boolean; link: string } {\r\n\t// the object we'll return\r\n\tlet ret = { valid: false, link: '' }\r\n\r\n\t// The checks in this block are taken from\r\n\t// https://github.com/visionmedia/page.js/blob/master/index.js#L370\r\n\r\n\t// continue ensure link\r\n\r\n\t// el.nodeName for svg links are 'a' instead of 'A'\r\n\t// traverse up till we find an anchor tag, since clicks\r\n\t// on image links for example set the target as img instead of a.\r\n\twhile (el && 'A' !== el.nodeName.toUpperCase()) el = el.parentNode\r\n\tif (!el || 'A' !== el.nodeName.toUpperCase()) return ret\r\n\r\n\t// check if link is inside an svg\r\n\t// in this case, both href and target are always inside an object\r\n\tvar svg =\r\n\t\ttypeof el.href === 'object' &&\r\n\t\tel.href.constructor.name === 'SVGAnimatedString'\r\n\r\n\t// Ignore if tag has\r\n\t// 1. \"download\" attribute\r\n\t// 2. rel=\"external\" attribute\r\n\tif (el.hasAttribute('download') || el.getAttribute('rel') === 'external') {\r\n\t\treturn ret\r\n\t}\r\n\r\n\t// ensure non-hash for the same path\r\n\tret.link = el.getAttribute('href') ?? ''\r\n\tif (!hash && samePath(el) && (el.hash || '#' === ret.link)) {\r\n\t\treturn ret\r\n\t}\r\n\r\n\t// Check for mailto: in the href\r\n\tif (ret.link && ret.link.indexOf('mailto:') > -1) return ret\r\n\r\n\t// check target\r\n\t// svg target is an object and its desired value is in .baseVal property\r\n\tif (svg ? el.target.baseVal : el.target) return ret\r\n\r\n\t// x-origin\r\n\t// note: svg links that are not relative don't call click events (and skip page.js)\r\n\t// consequently, all svg links tested inside page.js are relative and in the same origin\r\n\tif (!svg && !sameOrigin(el.href)) return ret\r\n\r\n\tret.valid = true\r\n\treturn ret\r\n}\r\n\r\n/**\r\n * Call a function on all middlewares loaded, if any.\r\n * @param {string} func middleware function to call.\r\n * @param {any} args arguments to pass to the function.\r\n * @returns {boolean} false if the middleware function return false, i.e. it want to stop execution of the function and return.\r\n */\r\nexport function middleware(func: string, ...args: any): string | undefined {\r\n\tif (!window.PineconeRouterMiddlewares) return\r\n\tfor (const i in window.PineconeRouterMiddlewares) {\r\n\t\tlet plugin: any = window.PineconeRouterMiddlewares[i]\r\n\t\tif (plugin[func] == null) return\r\n\t\tlet ret = plugin[func](...args)\r\n\t\t// the return of the function will only be 'stop'\r\n\t\t// if the middleware request stopping the navigate function.\r\n\t\tif (ret == 'stop') return 'stop'\r\n\t}\r\n}\r\n\r\nexport function fetchError(error: string) {\r\n\tdocument.dispatchEvent(\r\n\t\tnew CustomEvent('fetch-error', { detail: error })\r\n\t)\r\n}", "import Route from './route'\r\nimport type { Settings, Context, Middleware, Handler } from './types'\r\nimport { fetchError, match, middleware, validLink } from './utils'\r\n\r\n\r\ndeclare global {\r\n\tinterface Window {\r\n\t\tPineconeRouter: {\r\n\t\t\tversion: string\r\n\t\t\tname: string\r\n\t\t\tsettings: Settings\r\n\t\t\tnotfound: Route\r\n\t\t\troutes: Route[]\r\n\t\t\tcontext: Context\r\n\t\t\tloadStart: Event\r\n\t\t\tloadEnd: Event\r\n\t\t\tadd: (path: string, options?: {}) => number\r\n\t\t\tremove: (path: string) => void\r\n\t\t}\r\n\t\tPineconeRouterMiddlewares: Array\r\n\t}\r\n}\r\n\r\nexport default function (Alpine) {\r\n\r\n\tconst PineconeRouter = Alpine.reactive({\r\n\t\tversion: '4.0.2',\r\n\t\tname: 'pinecone-router',\r\n\r\n\t\tsettings: {\r\n\t\t\thash: false,\r\n\t\t\tbasePath: '/',\r\n\t\t\ttemplateTargetId: null\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * @description The handler for 404 pages, can be overwritten by a notfound route\r\n\t\t */\r\n\t\tnotfound: new Route('notfound'),\r\n\r\n\t\t/**\r\n\t\t * @type Route[]\r\n\t\t * @summary array of routes instantiated from the Route class.\r\n\t\t */\r\n\t\troutes: [],\r\n\r\n\t\t/**\r\n\t\t * @type {Context}\r\n\t\t * @summary The context object for current path.\r\n\t\t */\r\n\t\tcontext: {\r\n\t\t\troute: '',\r\n\t\t\tpath: '',\r\n\t\t\tparams: {},\r\n\t\t\tquery: window.location.search.substring(1),\r\n\t\t\thash: window.location.hash.substring(1),\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Add a new route\r\n\t\t */\r\n\t\tadd(path: string, options?: {}) {\r\n\t\t\t// check if the route was registered on the same router.\r\n\t\t\tif (this.routes.find((r: Route) => r.path == path) != null) {\r\n\t\t\t\tthrow new Error('Pinecone Router: route already exist')\r\n\t\t\t}\r\n\r\n\t\t\treturn this.routes.push(new Route(path, options)) - 1\r\n\t\t},\r\n\t\t/**\r\n\t\t * Remove a route\r\n\t\t */\r\n\t\tremove(path: string) {\r\n\t\t\tthis.routes = this.routes.filter((r: Route) => r.path != path)\r\n\t\t},\r\n\t\t/**\r\n\t\t * @event pinecone-start\r\n\t\t * @summary be dispatched to the window after before page start loading.\r\n\t\t */\r\n\t\tloadStart: new Event('pinecone-start'),\r\n\r\n\t\t/**\r\n\t\t * @event pinecone-end\r\n\t\t * @summary will be dispatched to the window after the views are fetched\r\n\t\t */\r\n\t\tloadEnd: new Event('pinecone-end'),\r\n\t})\r\n\r\n\twindow.PineconeRouter = PineconeRouter\r\n\r\n\tvar loadingTemplates: { [key: string]: Promise } = {}\r\n\tvar cachedTemplates: { [key: string]: string } = {}\r\n\r\n\tconst loadTemplate = (el: HTMLElement, url: string, target: string | null): Promise => {\r\n\t\tif (loadingTemplates[url]) {\r\n\t\t\tloadingTemplates[url].then(html => {\r\n\t\t\t\tif (target == null) {\r\n\t\t\t\t\tel.innerHTML = html\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t\t} else {\r\n\t\t\tloadingTemplates[url] = fetch(url).then(r => {\r\n\t\t\t\tif (r.ok) return r.text()\r\n\t\t\t\tthrow new Error(String(r.status))\r\n\t\t\t}).then(html => {\r\n\t\t\t\tcachedTemplates[url] = html\r\n\t\t\t\tif (target == null) {\r\n\t\t\t\t\tel.innerHTML = html\r\n\t\t\t\t}\r\n\t\t\t\treturn html\r\n\t\t\t}).catch(err => {\r\n\t\t\t\tfetchError(err)\r\n\t\t\t\t// returning a value is a must because we are assigning returned value to loadingTemplates[url]\r\n\t\t\t\t// by returning a null it will refetch again when the route is (re)visited\r\n\t\t\t\treturn null\r\n\t\t\t})\r\n\t\t}\r\n\t\treturn loadingTemplates[url]\r\n\t}\r\n\r\n\tconst addIf = (el: HTMLElement, routeIndex, path) => {\r\n\t\t// this make sure inline templates dont render until handlers are done\r\n\t\tlet route_expression = (routeIndex != null) ? `PineconeRouter.routes[${routeIndex}]` : 'PineconeRouter.notfound'\r\n\t\tlet expression = `$router.route == \"${path}\" && ${route_expression}.handlersDone`\r\n\t\tif (el.hasAttribute(\"x-if\")) return\r\n\t\tel.setAttribute(\"x-if\", expression)\r\n\t\tendLoading()\r\n\t}\r\n\r\n\tconst removeIf = (el: HTMLElement) => {\r\n\t\tif (!el.hasAttribute(\"x-if\")) return\r\n\t\tel.removeAttribute(\"x-if\")\r\n\t}\r\n\r\n\tconst insertHtmlInTarget = (targetEl: HTMLElement, url: string) => {\r\n\t\tendLoading()\r\n\t\ttargetEl.innerHTML = cachedTemplates[url]\r\n\t}\r\n\r\n\tconst startLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadStart)\r\n\t}\r\n\r\n\tconst endLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadEnd)\r\n\t}\r\n\r\n\tconst addBasePath = (path) => {\r\n\t\tif (!PineconeRouter.settings.hash && PineconeRouter.settings.basePath != '/') {\r\n\t\t\treturn PineconeRouter.settings.basePath + path\r\n\t\t} return path\r\n\t}\r\n\r\n\tconst findRouteIndex = (path) => {\r\n\t\treturn PineconeRouter.routes.findIndex(\r\n\t\t\t(r) => r.path == path\r\n\t\t)\r\n\t}\r\n\r\n\tAlpine.directive(\r\n\t\t'route',\r\n\t\t(el: HTMLTemplateElement, { expression }, { cleanup }) => {\r\n\t\t\tlet path = expression\r\n\r\n\t\t\tmiddleware('onBeforeRouteProcessed', el, path)\r\n\r\n\t\t\tif (path.indexOf('#') > -1) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: A route's path may not have a hash character.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\r\n\t\t\tlet routeIndex = null\r\n\r\n\t\t\tif (path != 'notfound') {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// register the new route if possible\r\n\t\t\t\trouteIndex = PineconeRouter.add(path)\r\n\t\t\t}\r\n\r\n\t\t\t// add if statement for inline template\r\n\t\t\tif (el.content.firstElementChild != null) {\r\n\t\t\t\tlet route = PineconeRouter.routes[routeIndex] ?? PineconeRouter.notfound\r\n\t\t\t\taddIf(el, routeIndex, path)\r\n\t\t\t}\r\n\r\n\t\t\tmiddleware('onAfterRouteProcessed', el, path)\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tPineconeRouter.remove(path)\r\n\t\t\t\tremoveIf(el)\r\n\t\t\t})\r\n\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'handler',\r\n\t\t(\r\n\t\t\tel,\r\n\t\t\t{ expression },\r\n\t\t\t{ evaluate, cleanup }\r\n\t\t) => {\r\n\t\t\tif (!el.hasAttribute('x-route')) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: x-handler must be set on the same element as x-route.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\tlet handlers\r\n\r\n\t\t\t// check if the handlers expression is an array\r\n\t\t\t// if not make it one\r\n\t\t\tif (\r\n\t\t\t\t!(expression.startsWith('[') && expression.endsWith(']')) &&\r\n\t\t\t\t!(expression.startsWith('Array(') && expression.endsWith(')'))\r\n\t\t\t) {\r\n\t\t\t\texpression = `[${expression}]`\r\n\t\t\t}\r\n\r\n\t\t\tlet evaluatedExpression = evaluate(expression)\r\n\t\t\tlet path = el.getAttribute('x-route')\r\n\r\n\t\t\tif (typeof evaluatedExpression == 'object')\r\n\t\t\t\thandlers = evaluatedExpression\r\n\t\t\telse {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: Invalid handler type: ${typeof evaluatedExpression}.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\tlet route\r\n\r\n\t\t\tif (path == 'notfound')\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\telse {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// add handlers to the route\r\n\t\t\t\tlet i = findRouteIndex(path)\r\n\t\t\t\troute = PineconeRouter.routes[i]\r\n\t\t\t}\r\n\t\t\troute.handlers = handlers\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\troute.handlers = []\r\n\t\t\t\troute.handlersDone = true\r\n\t\t\t})\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'template',\r\n\t\t(el: HTMLTemplateElement, { modifiers, expression }, { Alpine, effect, cleanup }) => {\r\n\r\n\t\t\tif (!el.hasAttribute(\"x-route\")) throw new Error(\"Pinecone Router: x-template must be used on the same element as x-route.\")\r\n\r\n\t\t\tvar isPreloading: any\r\n\t\t\tlet url: string = expression\r\n\r\n\t\t\tlet target = modifierValue(modifiers, 'target', null) ?? window.PineconeRouter.settings.templateTargetId\r\n\t\t\tlet targetEl = document.getElementById(target)\r\n\r\n\t\t\tif (target && !targetEl)\r\n\t\t\t\tthrow new Error(\"Pinecone Router: Can't find an element with the suplied x-template target ID (\" + target + \")\")\r\n\r\n\t\t\tif (modifiers.includes(\"preload\")) {\r\n\t\t\t\tisPreloading = loadTemplate(el, url, target).finally(() => {\r\n\t\t\t\t\tisPreloading = false\r\n\t\t\t\t\t// In case of failed fetch the template wont be cached\r\n\t\t\t\t\t// therefore we check for it and not add anything if it's null\r\n\t\t\t\t\tif (cachedTemplates[url] == null) return\r\n\t\t\t\t\tif (!target) addIf(el, routeIndex, path);\r\n\t\t\t\t})\r\n\t\t\t}\r\n\r\n\t\t\tlet path = el.getAttribute(\"x-route\")\r\n\t\t\tlet route;\r\n\t\t\tlet routeIndex\r\n\t\t\tif (path == 'notfound') {\r\n\t\t\t\tPineconeRouter.notfound.template = url\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\trouteIndex = findRouteIndex(path)\r\n\t\t\t\tPineconeRouter.routes[routeIndex].template = url\r\n\t\t\t\troute = PineconeRouter.routes[routeIndex]\r\n\t\t\t}\r\n\r\n\r\n\t\t\tAlpine.nextTick(() => {\r\n\t\t\t\teffect(() => {\r\n\t\t\t\t\tif (route.handlersDone && PineconeRouter.context.route == path) {\r\n\t\t\t\t\t\tif (cachedTemplates[url] != null) {\r\n\t\t\t\t\t\t\tif (!target) {\r\n\t\t\t\t\t\t\t\tendLoading()\r\n\t\t\t\t\t\t\t\tif (el.content.firstElementChild) return\r\n\t\t\t\t\t\t\t\tel.innerHTML = cachedTemplates[url]\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse insertHtmlInTarget(targetEl, url)\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tif (!isPreloading) {\r\n\t\t\t\t\t\t\t\tloadTemplate(el, url, target).finally(() => {\r\n\t\t\t\t\t\t\t\t\tif (cachedTemplates[url] == null) return\r\n\t\t\t\t\t\t\t\t\tif (!target) addIf(el, routeIndex, path)\r\n\t\t\t\t\t\t\t\t\telse insertHtmlInTarget(targetEl, url)\r\n\t\t\t\t\t\t\t\t})\r\n\t\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t\tisPreloading.finally(() => {\r\n\t\t\t\t\t\t\t\t\tif (cachedTemplates[url] == null) return\r\n\t\t\t\t\t\t\t\t\tif (target) {\r\n\t\t\t\t\t\t\t\t\t\tinsertHtmlInTarget(targetEl, url)\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t})\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t})\r\n\r\n\t\t\t})\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tdelete cachedTemplates[route.template]\r\n\t\t\t\troute.template = ''\r\n\t\t\t\tremoveIf(el)\r\n\t\t\t})\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.$router = PineconeRouter.context\r\n\tAlpine.magic('router', () => PineconeRouter.context)\r\n\r\n\tdocument.addEventListener('alpine:initialized', () => {\r\n\t\tmiddleware('init')\r\n\t\t// virtually navigate the path on the first page load\r\n\t\t// this will register the path in history and sets the pathvariable\r\n\t\t// navigate(window.location.pathname, false, true)\r\n\t\tif (!PineconeRouter.settings.hash) {\r\n\t\t\t// navigate to the current page to handle it\r\n\t\t\t// ONLY if we not using hash routing for the default router\r\n\t\t\tnavigate(location.pathname, false, true)\r\n\t\t} else {\r\n\t\t\tnavigate(location.hash.substring(1), false, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// handle navigation events not emitted by links, for example, back button.\r\n\twindow.addEventListener('popstate', () => {\r\n\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\tif (window.location.hash != '') {\r\n\t\t\t\tnavigate(window.location.hash.substring(1), true)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tnavigate(window.location.pathname, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// intercept click event in links\r\n\tinterceptLinks()\r\n\r\n\t/**\r\n\t * @description Add a handler to click events on all valid links\r\n\t */\r\n\tfunction interceptLinks() {\r\n\t\twindow.document.body.addEventListener(\r\n\t\t\tdocument.ontouchstart ? 'touchstart' : 'click',\r\n\t\t\tfunction (e) {\r\n\t\t\t\tif (\r\n\t\t\t\t\te.metaKey ||\r\n\t\t\t\t\te.ctrlKey ||\r\n\t\t\t\t\te.shiftKey ||\r\n\t\t\t\t\te.defaultPrevented\r\n\t\t\t\t) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// ensure link\r\n\t\t\t\t// use shadow dom when available if not, fall back to composedPath()\r\n\t\t\t\t// for browsers that only have shady\r\n\t\t\t\tlet el = e.target\r\n\r\n\t\t\t\tlet eventPath: any = e.composedPath()\r\n\t\t\t\tif (eventPath) {\r\n\t\t\t\t\tfor (let i = 0; i < eventPath.length; i++) {\r\n\t\t\t\t\t\tif (!eventPath[i].nodeName) continue\r\n\t\t\t\t\t\tif (eventPath[i].nodeName.toUpperCase() !== 'A') continue\r\n\t\t\t\t\t\tif (!eventPath[i].href) continue\r\n\r\n\t\t\t\t\t\tel = eventPath[i]\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (el == null) return\r\n\t\t\t\t// allow skipping link\r\n\t\t\t\t// @ts-ignore\r\n\t\t\t\tif (el.hasAttribute('native')) return\r\n\r\n\t\t\t\tlet ret = validLink(el, PineconeRouter.settings.hash)\r\n\r\n\t\t\t\tif (!ret.valid) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\r\n\t\t\t\tlet route = PineconeRouter.routes[findRouteIndex(PineconeRouter.context.route)] ?? PineconeRouter.notfound\r\n\r\n\t\t\t\t// stop handlers in progress before navigating to the next page\r\n\t\t\t\tif (!route.handlersDone) {\r\n\t\t\t\t\troute.cancelHandlers = true\r\n\t\t\t\t\tendLoading()\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// prevent default behavior.\r\n\t\t\t\tif (e.stopImmediatePropagation) e.stopImmediatePropagation()\r\n\t\t\t\tif (e.stopPropagation) e.stopPropagation()\r\n\t\t\t\te.preventDefault()\r\n\t\t\t\tnavigate(ret.link)\r\n\t\t\t}\r\n\t\t)\r\n\t}\r\n\r\n\t/**\r\n\t * Go to the specified path without reloading\r\n\t * @param {string} path the path with no hash even if using hash routing\r\n\t * @param {boolean} fromPopState this will be set to true if called from window.onpopstate event\r\n\t * @param {boolean} firstLoad this will be set to true if this is the first page loaded, also from page reload\r\n\t */\r\n\tasync function navigate(path, fromPopState = false, firstLoad = false) {\r\n\t\tif (!path) path = '/'\r\n\t\tPineconeRouter.context.path = path\r\n\r\n\t\t// only add basePath if it was set\r\n\t\t// if not using hash routing\r\n\t\t// and if it wasn't added already\r\n\t\tif (!PineconeRouter.settings.hash) {\r\n\t\t\tif (\r\n\t\t\t\tPineconeRouter.settings.basePath != '/' &&\r\n\t\t\t\t!path.startsWith(PineconeRouter.settings.basePath)\r\n\t\t\t) {\r\n\t\t\t\tpath = PineconeRouter.settings.basePath + path\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\tpath == PineconeRouter.settings.basePath &&\r\n\t\t\t\t!path.endsWith('/')\r\n\t\t\t) {\r\n\t\t\t\tpath += '/'\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst route: Route = PineconeRouter.routes.find(\r\n\t\t\t(route: Route) => {\r\n\t\t\t\tlet m = match(path, route.path)\r\n\t\t\t\troute.params = m != false ? m : {}\r\n\t\t\t\treturn m != false\r\n\t\t\t}\r\n\t\t) ?? PineconeRouter.notfound\r\n\r\n\t\t// if the route has handlres, it will mark them unhandled\r\n\t\t// this is so templates wont render till then.\r\n\t\troute.handlersDone = !route.handlers.length\r\n\r\n\t\tif (route.handlers.length || route.template) {\r\n\t\t\tstartLoading()\r\n\t\t}\r\n\r\n\t\tlet context = buildContext(route.path, path, route.params)\r\n\r\n\t\tPineconeRouter.context = context\r\n\r\n\t\t// the middleware may return 'stop' to stop execution of this function\r\n\t\tif (\r\n\t\t\tmiddleware('onBeforeHandlersExecuted', route, path, firstLoad) == 'stop'\r\n\t\t) {\r\n\t\t\tendLoading()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\r\n\t\t// do not call pushstate from popstate event https://stackoverflow.com/a/50830905\r\n\t\tif (!fromPopState) {\r\n\t\t\tlet fullPath = ''\r\n\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\tfullPath = '#'\r\n\t\t\t\tfullPath += window.location.search + path\r\n\t\t\t} else {\r\n\t\t\t\tfullPath = path + window.location.search + window.location.hash\r\n\t\t\t}\r\n\t\t\t// don't create duplicate history entry on first page load\r\n\t\t\tif (!firstLoad) history.pushState({ path: fullPath }, '', fullPath)\r\n\t\t\telse {\r\n\t\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\t\tif (path == '/') {\r\n\t\t\t\t\t\tPineconeRouter.context = context\r\n\t\t\t\t\t\treturn navigate('/', false, false)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (\r\n\t\t\t(route && route.handlers.length)\r\n\t\t) {\r\n\t\t\troute.cancelHandlers = false\r\n\t\t\tlet ok = await handle(route.handlers, context)\r\n\t\t\tif (!ok) {\r\n\t\t\t\tendLoading()\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\troute.handlersDone = true\r\n\t\t\tif (!route.template) endLoading()\r\n\t\t}\r\n\r\n\r\n\t\tmiddleware('onHandlersExecuted', route, path, firstLoad)\r\n\t}\r\n\r\n\tfunction buildContext(route: string, path: string, params: {}): Context {\r\n\t\treturn {\r\n\t\t\troute: route,\r\n\t\t\tpath: path,\r\n\t\t\tparams: params,\r\n\t\t\tquery: window.location.search.substring(1), // query w/out leading '?'\r\n\t\t\thash: window.location.hash.substring(1), // hash without leading '#'\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction modifierValue(modifiers, key, fallback) {\r\n\t\t// If the modifier isn't present, use the default.\r\n\t\tif (modifiers.indexOf(key) === -1) return fallback\r\n\r\n\t\t// If it IS present, grab the value after it\r\n\t\tconst rawValue = modifiers[modifiers.indexOf(key) + 1]\r\n\r\n\t\tif (!rawValue) return fallback\r\n\r\n\t\tif (key === 'target') {\r\n\t\t\tlet match = rawValue.match(/([a-z0-9_-]+)/)\r\n\t\t\tif (match) return match[1]\r\n\t\t}\r\n\t\treturn rawValue\r\n\t}\r\n\t/**\r\n\t * execute the handlers of routes that are given passing them the context.\r\n\t */\r\n\tasync function handle(handlers, context) {\r\n\t\tfor (let i = 0; i < handlers.length; i++) {\r\n\t\t\tif (typeof handlers[i] == 'function') {\r\n\t\t\t\t// stop if the handlers were canceled for example the user clicked a link\r\n\t\t\t\tlet route = PineconeRouter.routes[findRouteIndex(context.route)] ?? PineconeRouter.notfound\r\n\t\t\t\tif (route.cancelHandlers) {\r\n\t\t\t\t\troute.cancelHandlers = false\r\n\t\t\t\t\treturn false\r\n\t\t\t\t}\r\n\t\t\t\tlet result\r\n\t\t\t\tif (handlers[i].constructor.name === 'AsyncFunction')\r\n\t\t\t\t\tresult = await handlers[i](context)\r\n\t\t\t\telse\r\n\t\t\t\t\tresult = handlers[i](context)\r\n\t\t\t\t// if the handler redirected, return\r\n\t\t\t\tif (result == 'stop') return false\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n}\r\n\r\n", "import magic from '../src/index.js'\r\n\r\ndocument.addEventListener('alpine:init', () => {\r\n window.Alpine.plugin(magic)\r\n})\r\n"],
- "mappings": "MAEA,IAAMA,EAAN,KAAY,CAIX,YAAYC,EAAcC,EAAU,CAAC,EAAG,CAHxC,YAAiC,CAAC,EAElC,cAAsB,CAAC,EAQvB,kBAAwB,GANvB,KAAK,KAAOD,EACZ,OAAO,KAAKC,CAAO,EAAE,QAASC,GAAQ,CACrC,KAAKA,GAAOD,EAAQC,EACrB,CAAC,CACF,CAID,EAEOC,EAAQJ,ECjBf,IAAIK,EAAa,OAAO,SAQxB,SAASC,EAAWC,EAAuB,CAC1C,OAAOA,EAAI,QAAQ,eAAgB,EAAE,EAAE,MAAM,GAAG,CACjD,CAUO,SAASC,EAAMD,EAAaE,EAAmC,CACrE,IAAIC,EAAM,wBACTC,EAAIJ,EAAI,MAAMG,CAAG,EACjBE,EAAe,CAAC,EAChBC,EACD,GAAIF,GAAKA,EAAE,GAAI,CACd,IAAIG,EAAIH,EAAE,GAAG,MAAM,GAAG,EACtB,QAASI,EAAI,EAAGA,EAAID,EAAE,OAAQC,IAAK,CAClC,IAAIC,EAAIF,EAAEC,GAAG,MAAM,GAAG,EACtBH,EAAQ,mBAAmBI,EAAE,EAAE,GAAK,mBACnCA,EAAE,MAAM,CAAC,EAAE,KAAK,GAAG,CACpB,CACD,CACD,CACA,IAA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1B,EAAc+C,EAAqB,CACvE,MAAO,CACN,MAAOrB,EACP,KAAM1B,EACN,OAAQ+C,EACR,MAAO,OAAO,SAAS,OAAO,UAAU,CAAC,EACzC,KAAM,OAAO,SAAS,KAAK,UAAU,CAAC,EACtC,SAAS/C,EAAM,CACd,OAAAC,EAASD,CAAI,EACN,MACR,EACA,SAASA,EAAM,CACdC,EAASD,CAAI,CACd,CACD,CACD,CAEA,SAASkC,EAAcH,EAAWiB,EAAKC,EAAU,CAEhD,GAAIlB,EAAU,QAAQiB,CAAG,IAAM,GAAI,OAAOC,EAG1C,IAAMC,EAAWnB,EAAUA,EAAU,QAAQiB,CAAG,EAAI,GAEpD,GAAI,CAACE,EAAU,OAAOD,EAEtB,GAAID,IAAQ,SAAU,CACrB,IAAIN,EAAQQ,EAAS,MAAM,eAAe,EAC1C,GAAIR,EAAO,OAAOA,EAAM,EACzB,CACA,OAAOQ,CACR,CAIA,eAAeJ,EAAOlB,EAAUe,EAAS,CACxC,QAAS,EAAI,EAAG,EAAIf,EAAS,OAAQ,IACpC,GAAI,OAAOA,EAAS,IAAM,WAAY,CAErC,IAAIF,EAAQ5B,EAAe,OAAOyB,EAAeoB,EAAQ,KAAK,IAAM7C,EAAe,SACnF,GAAI4B,EAAM,eACT,OAAAA,EAAM,eAAiB,GAChB,GAER,IAAIyB,EAMJ,GALIvB,EAAS,GAAG,YAAY,OAAS,gBACpCuB,EAAS,MAAMvB,EAAS,GAAGe,CAAO,EAElCQ,EAASvB,EAAS,GAAGe,CAAO,EAEzBQ,GAAU,OAAQ,MAAO,EAC9B,CAED,MAAO,EACR,CACD,CClkBA,SAAS,iBAAiB,cAAe,IAAM,CAC7C,OAAO,OAAO,OAAOC,CAAK,CAC5B,CAAC",
- "names": ["Route", "path", "options", "opt", "route_default", "isLocation", "segmentize", "url", "match", "routePath", "reg", "c", "matches", "ret", "p", "i", "r", "urlSeg", "route", "max", "param", "flags", "plus", "star", "val", "toURL", "href", "anc", "sameOrigin", "loc", "samePath", "validLink", "el", "hash", "svg", "middleware", "func", "args", "plugin", "fetchError", "error", "src_default", "Alpine", "PineconeRouter", "route_default", "path", "navigate", "options", "r", "loadingTemplates", "cachedTemplates", "loadTemplate", "el", "url", "target", "html", "err", "fetchError", "addIf", "routeIndex", "route_expression", "expression", "endLoading", "removeIf", "insertHtmlInTarget", "targetEl", "startLoading", "addBasePath", "findRouteIndex", "cleanup", "middleware", "route", "evaluate", "handlers", "evaluatedExpression", "i", "modifiers", "effect", "isPreloading", "modifierValue", "interceptLinks", "eventPath", "ret", "validLink", "fromPopState", "firstLoad", "m", "match", "context", "buildContext", "fullPath", "handle", "params", "key", "fallback", "rawValue", "result", "src_default"]
+ "sourcesContent": ["import type { Handler } from './types'\r\n\r\nclass Route {\r\n\tparams: { [key: string]: any } = {}\r\n\tpath: string\r\n\thandlers: Handler[] = []\r\n\tconstructor(path: string, options = {}) {\r\n\t\tthis.path = path\r\n\t\tObject.keys(options).forEach((opt) => {\r\n\t\t\tthis[opt] = options[opt]\r\n\t\t})\r\n\t}\r\n\ttemplate: ''\r\n\thandlersDone: boolean = false\r\n\tcancelHandlers: boolean\r\n}\r\n\r\nexport default Route\r\n", "var isLocation = window.location\r\n\r\n/**\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param url url to segmentize\r\n * @returns\r\n */\r\nfunction segmentize(url: string): string[] {\r\n\treturn url.replace(/(^\\/+|\\/+$)/g, '').split('/')\r\n}\r\n\r\n/**\r\n * check if a path match with this route\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param path {string}\r\n * @param routePath {string}\r\n * @returns {false|object}\r\n */\r\nexport function match(url: string, routePath: string): false | object {\r\n\tlet reg = /(?:\\?([^#]*))?(#.*)?$/,\r\n\t\tc = url.match(reg),\r\n\t\tmatches: any = {},\r\n\t\tret\r\n\tif (c && c[1]) {\r\n\t\tlet p = c[1].split('&')\r\n\t\tfor (let i = 0; i < p.length; i++) {\r\n\t\t\tlet r = p[i].split('=')\r\n\t\t\tmatches[decodeURIComponent(r[0])] = decodeURIComponent(\r\n\t\t\t\tr.slice(1).join('=')\r\n\t\t\t)\r\n\t\t}\r\n\t}\r\n\tlet urlSeg = segmentize(url.replace(reg, '')),\r\n\t\troute: string[] = segmentize(routePath || ''),\r\n\t\tmax = Math.max(urlSeg.length, route.length)\r\n\tfor (let i = 0; i < max; i++) {\r\n\t\tif (route[i] && route[i].charAt(0) === ':') {\r\n\t\t\tlet param: string = route[i].replace(/(^:|[+*?]+$)/g, ''),\r\n\t\t\t\tflags: string = (route[i].match(/[+*?]+$/) || {}).toString()[0],\r\n\t\t\t\tplus = ~flags.indexOf('+'),\r\n\t\t\t\tstar = ~flags.indexOf('*'),\r\n\t\t\t\tval = urlSeg[i] || ''\r\n\t\t\tif (!val && !star && (flags.indexOf('?') < 0 || plus)) {\r\n\t\t\t\tret = false\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\tmatches[param] = decodeURIComponent(val)\r\n\t\t\tif (plus || star) {\r\n\t\t\t\tmatches[param] = urlSeg\r\n\t\t\t\t\t.slice(i)\r\n\t\t\t\t\t.map(decodeURIComponent)\r\n\t\t\t\t\t.join('/')\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t} else if (route[i] !== urlSeg[i]) {\r\n\t\t\tret = false\r\n\t\t\tbreak\r\n\t\t}\r\n\t}\r\n\tif (ret === false) return false\r\n\treturn matches\r\n}\r\n\r\n/**\r\n * Convert to a URL object\r\n * https://github.com/visionmedia/page.js/blob/4f9991658f9b9e3de9b6059bade93693af24d6bd/page.js#L888\r\n */\r\nfunction toURL(href: string): URL | HTMLAnchorElement {\r\n\tif (typeof URL === 'function' && isLocation) {\r\n\t\treturn new URL(href, window.location.toString())\r\n\t} else {\r\n\t\tvar anc = window.document.createElement('a')\r\n\t\tanc.href = href\r\n\t\treturn anc\r\n\t}\r\n}\r\n\r\n/**\r\n * Check if `href` is the same origin.\r\n * https://github.com/visionmedia/page.js/blob/4f9991658f9b9e3de9b6059bade93693af24d6bd/page.js#L888\r\n */\r\nexport function sameOrigin(href: string) {\r\n\tif (!href || !isLocation) return false\r\n\r\n\tvar url = toURL(href)\r\n\tvar loc = window.location\r\n\r\n\t/*\r\n\tWhen the port is the default http port 80 for http, or 443 for\r\n\thttps, internet explorer 11 returns an empty string for loc.port,\r\n\tso we need to compare loc.port with an empty string if url.port\r\n\tis the default port 80 or 443.\r\n\tAlso the comparison with `port` is changed from `===` to `==` because\r\n\t`port` can be a string sometimes. This only applies to ie11.\r\n\t*/\r\n\treturn (\r\n\t\tloc.protocol === url.protocol &&\r\n\t\tloc.hostname === url.hostname &&\r\n\t\t(loc.port === url.port ||\r\n\t\t\t(loc.port === '' && (url.port == '80' || url.port == '443')))\r\n\t) // jshint ignore:line\r\n}\r\n\r\nexport function samePath(url: any) {\r\n\tif (!isLocation) return false\r\n\tvar loc = window.location\r\n\treturn url.pathname === loc.pathname && url.search === loc.search\r\n}\r\n\r\n/**\r\n * Check if the anchor element point to a navigation route.\r\n * @param {any} el The anchor element or Event target\r\n * @param {boolean} hash Set to true when using hash routing\r\n * @returns {object} {valid: boolean, link: string}\r\n */\r\nexport function validLink(\r\n\tel: any,\r\n\thash: boolean\r\n): { valid: boolean; link: string } {\r\n\t// the object we'll return\r\n\tlet ret = { valid: false, link: '' }\r\n\r\n\t// The checks in this block are taken from\r\n\t// https://github.com/visionmedia/page.js/blob/master/index.js#L370\r\n\r\n\t// continue ensure link\r\n\r\n\t// el.nodeName for svg links are 'a' instead of 'A'\r\n\t// traverse up till we find an anchor tag, since clicks\r\n\t// on image links for example set the target as img instead of a.\r\n\twhile (el && 'A' !== el.nodeName.toUpperCase()) el = el.parentNode\r\n\tif (!el || 'A' !== el.nodeName.toUpperCase()) return ret\r\n\r\n\t// check if link is inside an svg\r\n\t// in this case, both href and target are always inside an object\r\n\tvar svg =\r\n\t\ttypeof el.href === 'object' &&\r\n\t\tel.href.constructor.name === 'SVGAnimatedString'\r\n\r\n\t// Ignore if tag has\r\n\t// 1. \"download\" attribute\r\n\t// 2. rel=\"external\" attribute\r\n\tif (el.hasAttribute('download') || el.getAttribute('rel') === 'external') {\r\n\t\treturn ret\r\n\t}\r\n\r\n\t// ensure non-hash for the same path\r\n\tret.link = el.getAttribute('href') ?? ''\r\n\tif (!hash && samePath(el) && (el.hash || '#' === ret.link)) {\r\n\t\treturn ret\r\n\t}\r\n\r\n\t// Check for mailto: in the href\r\n\tif (ret.link && ret.link.indexOf('mailto:') > -1) return ret\r\n\r\n\t// check target\r\n\t// svg target is an object and its desired value is in .baseVal property\r\n\tif (svg ? el.target.baseVal : el.target) return ret\r\n\r\n\t// x-origin\r\n\t// note: svg links that are not relative don't call click events (and skip page.js)\r\n\t// consequently, all svg links tested inside page.js are relative and in the same origin\r\n\tif (!svg && !sameOrigin(el.href)) return ret\r\n\r\n\tret.valid = true\r\n\treturn ret\r\n}\r\n\r\n/**\r\n * Call a function on all middlewares loaded, if any.\r\n * @param {string} func middleware function to call.\r\n * @param {any} args arguments to pass to the function.\r\n * @returns {boolean} false if the middleware function return false, i.e. it want to stop execution of the function and return.\r\n */\r\nexport function middleware(func: string, ...args: any): string | undefined {\r\n\tif (!window.PineconeRouterMiddlewares) return\r\n\tfor (const i in window.PineconeRouterMiddlewares) {\r\n\t\tlet plugin: any = window.PineconeRouterMiddlewares[i]\r\n\t\tif (plugin[func] == null) return\r\n\t\tlet ret = plugin[func](...args)\r\n\t\t// the return of the function will only be 'stop'\r\n\t\t// if the middleware request stopping the navigate function.\r\n\t\tif (ret == 'stop') return 'stop'\r\n\t}\r\n}\r\n\r\nexport function fetchError(error: string) {\r\n\tdocument.dispatchEvent(\r\n\t\tnew CustomEvent('fetch-error', { detail: error })\r\n\t)\r\n}", "import Route from './route'\r\nimport type { Settings, Context, Middleware, Handler } from './types'\r\nimport { fetchError, match, middleware, validLink } from './utils'\r\n\r\n\r\ndeclare global {\r\n\tinterface Window {\r\n\t\tPineconeRouter: {\r\n\t\t\tversion: string\r\n\t\t\tname: string\r\n\t\t\tsettings: Settings\r\n\t\t\tnotfound: Route\r\n\t\t\troutes: Route[]\r\n\t\t\tcontext: Context\r\n\t\t\tloadStart: Event\r\n\t\t\tloadEnd: Event\r\n\t\t\tadd: (path: string, options?: {}) => number\r\n\t\t\tremove: (path: string) => void\r\n\t\t}\r\n\t\tPineconeRouterMiddlewares: Array\r\n\t}\r\n}\r\n\r\nexport default function (Alpine) {\r\n\r\n\tconst PineconeRouter = Alpine.reactive({\r\n\t\tversion: '4.0.3',\r\n\t\tname: 'pinecone-router',\r\n\r\n\t\tsettings: {\r\n\t\t\thash: false,\r\n\t\t\tbasePath: '/',\r\n\t\t\ttemplateTargetId: null\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * @description The handler for 404 pages, can be overwritten by a notfound route\r\n\t\t */\r\n\t\tnotfound: new Route('notfound'),\r\n\r\n\t\t/**\r\n\t\t * @type Route[]\r\n\t\t * @summary array of routes instantiated from the Route class.\r\n\t\t */\r\n\t\troutes: [],\r\n\r\n\t\t/**\r\n\t\t * @type {Context}\r\n\t\t * @summary The context object for current path.\r\n\t\t */\r\n\t\tcontext: {\r\n\t\t\troute: '',\r\n\t\t\tpath: '',\r\n\t\t\tparams: {},\r\n\t\t\tquery: window.location.search.substring(1),\r\n\t\t\thash: window.location.hash.substring(1),\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Add a new route\r\n\t\t */\r\n\t\tadd(path: string, options?: {}) {\r\n\t\t\t// check if the route was registered on the same router.\r\n\t\t\tif (this.routes.find((r: Route) => r.path == path) != null) {\r\n\t\t\t\tthrow new Error('Pinecone Router: route already exist')\r\n\t\t\t}\r\n\r\n\t\t\treturn this.routes.push(new Route(path, options)) - 1\r\n\t\t},\r\n\t\t/**\r\n\t\t * Remove a route\r\n\t\t */\r\n\t\tremove(path: string) {\r\n\t\t\tthis.routes = this.routes.filter((r: Route) => r.path != path)\r\n\t\t},\r\n\t\t/**\r\n\t\t * @event pinecone-start\r\n\t\t * @summary be dispatched to the window after before page start loading.\r\n\t\t */\r\n\t\tloadStart: new Event('pinecone-start'),\r\n\r\n\t\t/**\r\n\t\t * @event pinecone-end\r\n\t\t * @summary will be dispatched to the window after the views are fetched\r\n\t\t */\r\n\t\tloadEnd: new Event('pinecone-end'),\r\n\t})\r\n\r\n\twindow.PineconeRouter = PineconeRouter\r\n\r\n\tvar loadingTemplates: { [key: string]: Promise } = {}\r\n\tvar cachedTemplates: { [key: string]: string } = {}\r\n\r\n\tconst loadTemplate = (el: HTMLElement, url: string, target: string | null): Promise => {\r\n\t\tif (loadingTemplates[url]) {\r\n\t\t\tloadingTemplates[url].then(html => {\r\n\t\t\t\tif (target == null) {\r\n\t\t\t\t\tel.innerHTML = html\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t\t} else {\r\n\t\t\tloadingTemplates[url] = fetch(url).then(r => {\r\n\t\t\t\tif (r.ok) return r.text()\r\n\t\t\t\tthrow new Error(String(r.status))\r\n\t\t\t}).then(html => {\r\n\t\t\t\tcachedTemplates[url] = html\r\n\t\t\t\tif (target == null) {\r\n\t\t\t\t\tel.innerHTML = html\r\n\t\t\t\t}\r\n\t\t\t\treturn html\r\n\t\t\t}).catch(err => {\r\n\t\t\t\tfetchError(err)\r\n\t\t\t\t// returning a value is a must because we are assigning returned value to loadingTemplates[url]\r\n\t\t\t\t// by returning a null it will refetch again when the route is (re)visited\r\n\t\t\t\treturn null\r\n\t\t\t})\r\n\t\t}\r\n\t\treturn loadingTemplates[url]\r\n\t}\r\n\r\n\tconst addIf = (el: HTMLElement, routeIndex, path) => {\r\n\t\t// this make sure inline templates dont render until handlers are done\r\n\t\tlet route_expression = (routeIndex != null) ? `PineconeRouter.routes[${routeIndex}]` : 'PineconeRouter.notfound'\r\n\t\tlet expression = `$router.route == \"${path}\" && ${route_expression}.handlersDone`\r\n\t\tif (el.hasAttribute(\"x-if\")) return\r\n\t\tel.setAttribute(\"x-if\", expression)\r\n\t\tendLoading()\r\n\t}\r\n\r\n\tconst removeIf = (el: HTMLElement) => {\r\n\t\tif (!el.hasAttribute(\"x-if\")) return\r\n\t\tel.removeAttribute(\"x-if\")\r\n\t}\r\n\r\n\tconst insertHtmlInTarget = (targetEl: HTMLElement, url: string) => {\r\n\t\tendLoading()\r\n\t\ttargetEl.innerHTML = cachedTemplates[url]\r\n\t}\r\n\r\n\tconst startLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadStart)\r\n\t}\r\n\r\n\tconst endLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadEnd)\r\n\t}\r\n\r\n\tconst addBasePath = (path) => {\r\n\t\tif (!PineconeRouter.settings.hash && PineconeRouter.settings.basePath != '/') {\r\n\t\t\treturn PineconeRouter.settings.basePath + path\r\n\t\t} return path\r\n\t}\r\n\r\n\tconst findRouteIndex = (path) => {\r\n\t\treturn PineconeRouter.routes.findIndex(\r\n\t\t\t(r) => r.path == path\r\n\t\t)\r\n\t}\r\n\r\n\tAlpine.directive(\r\n\t\t'route',\r\n\t\t(el: HTMLTemplateElement, { expression }, { cleanup }) => {\r\n\t\t\tlet path = expression\r\n\r\n\t\t\tmiddleware('onBeforeRouteProcessed', el, path)\r\n\r\n\t\t\tif (path.indexOf('#') > -1) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: A route's path may not have a hash character.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\r\n\t\t\tlet routeIndex = null\r\n\r\n\t\t\tif (path != 'notfound') {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// register the new route if possible\r\n\t\t\t\trouteIndex = PineconeRouter.add(path)\r\n\t\t\t}\r\n\r\n\t\t\t// add if statement for inline template\r\n\t\t\tif (el.content.firstElementChild != null) {\r\n\t\t\t\tlet route = PineconeRouter.routes[routeIndex] ?? PineconeRouter.notfound\r\n\t\t\t\taddIf(el, routeIndex, path)\r\n\t\t\t}\r\n\r\n\t\t\tmiddleware('onAfterRouteProcessed', el, path)\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tPineconeRouter.remove(path)\r\n\t\t\t\tremoveIf(el)\r\n\t\t\t})\r\n\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'handler',\r\n\t\t(\r\n\t\t\tel,\r\n\t\t\t{ expression },\r\n\t\t\t{ evaluate, cleanup }\r\n\t\t) => {\r\n\t\t\tif (!el.hasAttribute('x-route')) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: x-handler must be set on the same element as x-route.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\tlet handlers\r\n\r\n\t\t\t// check if the handlers expression is an array\r\n\t\t\t// if not make it one\r\n\t\t\tif (\r\n\t\t\t\t!(expression.startsWith('[') && expression.endsWith(']')) &&\r\n\t\t\t\t!(expression.startsWith('Array(') && expression.endsWith(')'))\r\n\t\t\t) {\r\n\t\t\t\texpression = `[${expression}]`\r\n\t\t\t}\r\n\r\n\t\t\tlet evaluatedExpression = evaluate(expression)\r\n\t\t\tlet path = el.getAttribute('x-route')\r\n\r\n\t\t\tif (typeof evaluatedExpression == 'object')\r\n\t\t\t\thandlers = evaluatedExpression\r\n\t\t\telse {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: Invalid handler type: ${typeof evaluatedExpression}.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\t// add `this` context for handlers inside an Alpine.component\r\n\t\t\tfor (let index = 0; index < handlers.length; index++) {\r\n\t\t\t\thandlers[index] = handlers[index].bind(Alpine.$data(el))\r\n\t\t\t}\r\n\r\n\t\t\tlet route\r\n\r\n\t\t\tif (path == 'notfound')\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\telse {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// add handlers to the route\r\n\t\t\t\tlet i = findRouteIndex(path)\r\n\t\t\t\troute = PineconeRouter.routes[i]\r\n\t\t\t}\r\n\t\t\troute.handlers = handlers\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\troute.handlers = []\r\n\t\t\t\troute.handlersDone = true\r\n\t\t\t})\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'template',\r\n\t\t(el: HTMLTemplateElement, { modifiers, expression }, { Alpine, effect, cleanup }) => {\r\n\r\n\t\t\tif (!el.hasAttribute(\"x-route\")) throw new Error(\"Pinecone Router: x-template must be used on the same element as x-route.\")\r\n\r\n\t\t\tvar isPreloading: any\r\n\t\t\tlet url: string = expression\r\n\r\n\t\t\tlet target = modifierValue(modifiers, 'target', null) ?? window.PineconeRouter.settings.templateTargetId\r\n\t\t\tlet targetEl = document.getElementById(target)\r\n\r\n\t\t\tif (target && !targetEl)\r\n\t\t\t\tthrow new Error(\"Pinecone Router: Can't find an element with the suplied x-template target ID (\" + target + \")\")\r\n\r\n\t\t\tif (modifiers.includes(\"preload\")) {\r\n\t\t\t\tisPreloading = loadTemplate(el, url, target).finally(() => {\r\n\t\t\t\t\tisPreloading = false\r\n\t\t\t\t\t// In case of failed fetch the template wont be cached\r\n\t\t\t\t\t// therefore we check for it and not add anything if it's null\r\n\t\t\t\t\tif (cachedTemplates[url] == null) return\r\n\t\t\t\t\tif (!target) addIf(el, routeIndex, path);\r\n\t\t\t\t})\r\n\t\t\t}\r\n\r\n\t\t\tlet path = el.getAttribute(\"x-route\")\r\n\t\t\tlet route;\r\n\t\t\tlet routeIndex\r\n\t\t\tif (path == 'notfound') {\r\n\t\t\t\tPineconeRouter.notfound.template = url\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\trouteIndex = findRouteIndex(path)\r\n\t\t\t\tPineconeRouter.routes[routeIndex].template = url\r\n\t\t\t\troute = PineconeRouter.routes[routeIndex]\r\n\t\t\t}\r\n\r\n\r\n\t\t\tAlpine.nextTick(() => {\r\n\t\t\t\teffect(() => {\r\n\t\t\t\t\tif (route.handlersDone && PineconeRouter.context.route == path) {\r\n\t\t\t\t\t\tif (cachedTemplates[url] != null) {\r\n\t\t\t\t\t\t\tif (!target) {\r\n\t\t\t\t\t\t\t\tendLoading()\r\n\t\t\t\t\t\t\t\tif (el.content.firstElementChild) return\r\n\t\t\t\t\t\t\t\tel.innerHTML = cachedTemplates[url]\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse insertHtmlInTarget(targetEl, url)\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tif (!isPreloading) {\r\n\t\t\t\t\t\t\t\tloadTemplate(el, url, target).finally(() => {\r\n\t\t\t\t\t\t\t\t\tif (cachedTemplates[url] == null) return\r\n\t\t\t\t\t\t\t\t\tif (!target) addIf(el, routeIndex, path)\r\n\t\t\t\t\t\t\t\t\telse insertHtmlInTarget(targetEl, url)\r\n\t\t\t\t\t\t\t\t})\r\n\t\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t\tisPreloading.finally(() => {\r\n\t\t\t\t\t\t\t\t\tif (cachedTemplates[url] == null) return\r\n\t\t\t\t\t\t\t\t\tif (target) {\r\n\t\t\t\t\t\t\t\t\t\tinsertHtmlInTarget(targetEl, url)\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t})\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t})\r\n\r\n\t\t\t})\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tdelete cachedTemplates[route.template]\r\n\t\t\t\troute.template = ''\r\n\t\t\t\tremoveIf(el)\r\n\t\t\t})\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.$router = PineconeRouter.context\r\n\tAlpine.magic('router', () => PineconeRouter.context)\r\n\r\n\tdocument.addEventListener('alpine:initialized', () => {\r\n\t\tmiddleware('init')\r\n\t\t// virtually navigate the path on the first page load\r\n\t\t// this will register the path in history and sets the pathvariable\r\n\t\t// navigate(window.location.pathname, false, true)\r\n\t\tif (!PineconeRouter.settings.hash) {\r\n\t\t\t// navigate to the current page to handle it\r\n\t\t\t// ONLY if we not using hash routing for the default router\r\n\t\t\tnavigate(location.pathname, false, true)\r\n\t\t} else {\r\n\t\t\tnavigate(location.hash.substring(1), false, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// handle navigation events not emitted by links, for example, back button.\r\n\twindow.addEventListener('popstate', () => {\r\n\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\tif (window.location.hash != '') {\r\n\t\t\t\tnavigate(window.location.hash.substring(1), true)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tnavigate(window.location.pathname, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// intercept click event in links\r\n\tinterceptLinks()\r\n\r\n\t/**\r\n\t * @description Add a handler to click events on all valid links\r\n\t */\r\n\tfunction interceptLinks() {\r\n\t\twindow.document.body.addEventListener(\r\n\t\t\tdocument.ontouchstart ? 'touchstart' : 'click',\r\n\t\t\tfunction (e) {\r\n\t\t\t\tif (\r\n\t\t\t\t\te.metaKey ||\r\n\t\t\t\t\te.ctrlKey ||\r\n\t\t\t\t\te.shiftKey ||\r\n\t\t\t\t\te.defaultPrevented\r\n\t\t\t\t) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// ensure link\r\n\t\t\t\t// use shadow dom when available if not, fall back to composedPath()\r\n\t\t\t\t// for browsers that only have shady\r\n\t\t\t\tlet el = e.target\r\n\r\n\t\t\t\tlet eventPath: any = e.composedPath()\r\n\t\t\t\tif (eventPath) {\r\n\t\t\t\t\tfor (let i = 0; i < eventPath.length; i++) {\r\n\t\t\t\t\t\tif (!eventPath[i].nodeName) continue\r\n\t\t\t\t\t\tif (eventPath[i].nodeName.toUpperCase() !== 'A') continue\r\n\t\t\t\t\t\tif (!eventPath[i].href) continue\r\n\r\n\t\t\t\t\t\tel = eventPath[i]\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (el == null) return\r\n\t\t\t\t// allow skipping link\r\n\t\t\t\t// @ts-ignore\r\n\t\t\t\tif (el.hasAttribute('native')) return\r\n\r\n\t\t\t\tlet ret = validLink(el, PineconeRouter.settings.hash)\r\n\r\n\t\t\t\tif (!ret.valid) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\r\n\t\t\t\tlet route = PineconeRouter.routes[findRouteIndex(PineconeRouter.context.route)] ?? PineconeRouter.notfound\r\n\r\n\t\t\t\t// stop handlers in progress before navigating to the next page\r\n\t\t\t\tif (!route.handlersDone) {\r\n\t\t\t\t\troute.cancelHandlers = true\r\n\t\t\t\t\tendLoading()\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// prevent default behavior.\r\n\t\t\t\tif (e.stopImmediatePropagation) e.stopImmediatePropagation()\r\n\t\t\t\tif (e.stopPropagation) e.stopPropagation()\r\n\t\t\t\te.preventDefault()\r\n\t\t\t\tnavigate(ret.link)\r\n\t\t\t}\r\n\t\t)\r\n\t}\r\n\r\n\t/**\r\n\t * Go to the specified path without reloading\r\n\t * @param {string} path the path with no hash even if using hash routing\r\n\t * @param {boolean} fromPopState this will be set to true if called from window.onpopstate event\r\n\t * @param {boolean} firstLoad this will be set to true if this is the first page loaded, also from page reload\r\n\t */\r\n\tasync function navigate(path, fromPopState = false, firstLoad = false) {\r\n\t\tif (!path) path = '/'\r\n\t\tPineconeRouter.context.path = path\r\n\r\n\t\t// only add basePath if it was set\r\n\t\t// if not using hash routing\r\n\t\t// and if it wasn't added already\r\n\t\tif (!PineconeRouter.settings.hash) {\r\n\t\t\tif (\r\n\t\t\t\tPineconeRouter.settings.basePath != '/' &&\r\n\t\t\t\t!path.startsWith(PineconeRouter.settings.basePath)\r\n\t\t\t) {\r\n\t\t\t\tpath = PineconeRouter.settings.basePath + path\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\tpath == PineconeRouter.settings.basePath &&\r\n\t\t\t\t!path.endsWith('/')\r\n\t\t\t) {\r\n\t\t\t\tpath += '/'\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst route: Route = PineconeRouter.routes.find(\r\n\t\t\t(route: Route) => {\r\n\t\t\t\tlet m = match(path, route.path)\r\n\t\t\t\troute.params = m != false ? m : {}\r\n\t\t\t\treturn m != false\r\n\t\t\t}\r\n\t\t) ?? PineconeRouter.notfound\r\n\r\n\t\t// if the route has handlres, it will mark them unhandled\r\n\t\t// this is so templates wont render till then.\r\n\t\troute.handlersDone = !route.handlers.length\r\n\r\n\t\tif (route.handlers.length || route.template) {\r\n\t\t\tstartLoading()\r\n\t\t}\r\n\r\n\t\tlet context = buildContext(route.path, path, route.params)\r\n\r\n\t\tPineconeRouter.context = context\r\n\r\n\t\t// the middleware may return 'stop' to stop execution of this function\r\n\t\tif (\r\n\t\t\tmiddleware('onBeforeHandlersExecuted', route, path, firstLoad) == 'stop'\r\n\t\t) {\r\n\t\t\tendLoading()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\r\n\t\t// do not call pushstate from popstate event https://stackoverflow.com/a/50830905\r\n\t\tif (!fromPopState) {\r\n\t\t\tlet fullPath = ''\r\n\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\tfullPath = '#'\r\n\t\t\t\tfullPath += window.location.search + path\r\n\t\t\t} else {\r\n\t\t\t\tfullPath = path + window.location.search + window.location.hash\r\n\t\t\t}\r\n\t\t\t// don't create duplicate history entry on first page load\r\n\t\t\tif (!firstLoad) history.pushState({ path: fullPath }, '', fullPath)\r\n\t\t\telse {\r\n\t\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\t\tif (path == '/') {\r\n\t\t\t\t\t\tPineconeRouter.context = context\r\n\t\t\t\t\t\treturn navigate('/', false, false)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (\r\n\t\t\t(route && route.handlers.length)\r\n\t\t) {\r\n\t\t\troute.cancelHandlers = false\r\n\t\t\tlet ok = await handle(route.handlers, context)\r\n\t\t\tif (!ok) {\r\n\t\t\t\tendLoading()\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\troute.handlersDone = true\r\n\t\t\tif (!route.template) endLoading()\r\n\t\t}\r\n\r\n\r\n\t\tmiddleware('onHandlersExecuted', route, path, firstLoad)\r\n\t}\r\n\r\n\tfunction buildContext(route: string, path: string, params: {}): Context {\r\n\t\treturn {\r\n\t\t\troute: route,\r\n\t\t\tpath: path,\r\n\t\t\tparams: params,\r\n\t\t\tquery: window.location.search.substring(1), // query w/out leading '?'\r\n\t\t\thash: window.location.hash.substring(1), // hash without leading '#'\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction modifierValue(modifiers, key, fallback) {\r\n\t\t// If the modifier isn't present, use the default.\r\n\t\tif (modifiers.indexOf(key) === -1) return fallback\r\n\r\n\t\t// If it IS present, grab the value after it\r\n\t\tconst rawValue = modifiers[modifiers.indexOf(key) + 1]\r\n\r\n\t\tif (!rawValue) return fallback\r\n\r\n\t\tif (key === 'target') {\r\n\t\t\tlet match = rawValue.match(/([a-z0-9_-]+)/)\r\n\t\t\tif (match) return match[1]\r\n\t\t}\r\n\t\treturn rawValue\r\n\t}\r\n\t/**\r\n\t * execute the handlers of routes that are given passing them the context.\r\n\t */\r\n\tasync function handle(handlers, context) {\r\n\t\tfor (let i = 0; i < handlers.length; i++) {\r\n\t\t\tif (typeof handlers[i] == 'function') {\r\n\t\t\t\t// stop if the handlers were canceled for example the user clicked a link\r\n\t\t\t\tlet route = PineconeRouter.routes[findRouteIndex(context.route)] ?? PineconeRouter.notfound\r\n\t\t\t\tif (route.cancelHandlers) {\r\n\t\t\t\t\troute.cancelHandlers = false\r\n\t\t\t\t\treturn false\r\n\t\t\t\t}\r\n\t\t\t\tlet result\r\n\t\t\t\tif (handlers[i].constructor.name === 'AsyncFunction')\r\n\t\t\t\t\tresult = await handlers[i](context)\r\n\t\t\t\telse\r\n\t\t\t\t\tresult = handlers[i](context)\r\n\t\t\t\t// if the handler redirected, return\r\n\t\t\t\tif (result == 'stop') return false\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n}\r\n\r\n", "import magic from '../src/index.js'\r\n\r\ndocument.addEventListener('alpine:init', () => {\r\n window.Alpine.plugin(magic)\r\n})\r\n"],
+ "mappings": "MAEA,IAAMA,EAAN,KAAY,CAIX,YAAYC,EAAcC,EAAU,CAAC,EAAG,CAHxC,YAAiC,CAAC,EAElC,cAAsB,CAAC,EAQvB,kBAAwB,GANvB,KAAK,KAAOD,EACZ,OAAO,KAAKC,CAAO,EAAE,QAASC,GAAQ,CACrC,KAAKA,GAAOD,EAAQC,EACrB,CAAC,CACF,CAID,EAEOC,EAAQJ,ECjBf,IAAIK,EAAa,OAAO,SAQxB,SAASC,EAAWC,EAAuB,CAC1C,OAAOA,EAAI,QAAQ,eAAgB,EAAE,EAAE,MAAM,GAAG,CACjD,CAUO,SAASC,EAAMD,EAAaE,EAAmC,CACrE,IAAIC,EAAM,wBACTC,EAAIJ,EAAI,MAAMG,CAAG,EACjBE,EAAe,CAAC,EAChBC,EACD,GAAIF,GAAKA,EAAE,GAAI,CACd,IAAIG,EAAIH,EAAE,GAAG,MAAM,GAAG,EACtB,QAASI,EAAI,EAAGA,EAAID,EAAE,OAAQC,IAAK,CAClC,IAAIC,EAAIF,EAAEC,GAAG,MAAM,GAAG,EACtBH,EAAQ,mBAAmBI,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S,iBAAiB,cAAe,IAAM,CAC7C,OAAO,OAAO,OAAOC,CAAK,CAC5B,CAAC",
+ "names": ["Route", "path", "options", "opt", "route_default", "isLocation", "segmentize", "url", "match", "routePath", "reg", "c", "matches", "ret", "p", "i", "r", "urlSeg", "route", "max", "param", "flags", "plus", "star", "val", "toURL", "href", "anc", "sameOrigin", "loc", "samePath", "validLink", "el", "hash", "svg", "middleware", "func", "args", "plugin", "fetchError", "error", "src_default", "Alpine", "PineconeRouter", "route_default", "path", "navigate", "options", "r", "loadingTemplates", "cachedTemplates", "loadTemplate", "el", "url", "target", "html", "err", "fetchError", "addIf", "routeIndex", "route_expression", "expression", "endLoading", "removeIf", "insertHtmlInTarget", "targetEl", "startLoading", "addBasePath", "findRouteIndex", "cleanup", "middleware", "route", "evaluate", "handlers", "evaluatedExpression", "index", "i", "modifiers", "effect", "isPreloading", "modifierValue", "interceptLinks", "e", "eventPath", "ret", "validLink", "fromPopState", "firstLoad", "match", "context", "buildContext", "fullPath", "handle", "params", "key", "fallback", "rawValue", "result", "src_default"]
}
diff --git a/package.json b/package.json
index 9c4b571..efafd07 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,7 @@
"description": "The extendable client-side router for Alpine.js.",
"license": "MIT",
"author": "Rafik El Hadi Houari ",
- "version": "4.0.2",
+ "version": "4.0.3",
"repository": {
"type": "git",
"url": "https://github.com/pinecone-router/router"
diff --git a/src/index.ts b/src/index.ts
index 8ce07cd..de3b401 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -24,7 +24,7 @@ declare global {
export default function (Alpine) {
const PineconeRouter = Alpine.reactive({
- version: '4.0.2',
+ version: '4.0.3',
name: 'pinecone-router',
settings: {
@@ -238,6 +238,11 @@ export default function (Alpine) {
)
}
+ // add `this` context for handlers inside an Alpine.component
+ for (let index = 0; index < handlers.length; index++) {
+ handlers[index] = handlers[index].bind(Alpine.$data(el))
+ }
+
let route
if (path == 'notfound')