@unseenco/taxi
Advanced tools
Comparing version 0.6.0 to 1.0.0
@@ -1,2 +0,2 @@ | ||
import t from"@unseenco/e";function e(){return e=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},e.apply(this,arguments)}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function r(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i=new DOMParser;function o(t){var e=new URL(t,window.location.origin),n=null;return e.hash.length&&(n=t.replace(e.hash,"")),{hasHash:e.hash.length>0,pathname:e.pathname,host:e.host,raw:t,href:n||e.href}}function a(t){"HEAD"===t.parentNode.tagName?document.head.appendChild(c(t)):document.body.appendChild(c(t))}function c(t){for(var e=document.createElement("SCRIPT"),n=0;n<t.attributes.length;n++){var r=t.attributes[n];e.setAttribute(r.nodeName,r.nodeValue)}return t.innerHTML&&(e.innerHTML=t.innerHTML),e}var s=/*#__PURE__*/function(){function t(t){this.wrapper=t.wrapper}var n=t.prototype;return n.leave=function(t){var n=this;return new Promise(function(r){n.onLeave(e({},t,{done:r}))})},n.enter=function(t){var n=this;return new Promise(function(r){n.onEnter(e({},t,{done:r}))})},n.onLeave=function(t){(0,t.done)()},n.onEnter=function(t){(0,t.done)()},t}(),h=/*#__PURE__*/function(){function t(t){var e=t.page,n=t.title,r=t.wrapper;this._contentString=t.content.outerHTML,this.page=e,this.title=n,this.wrapper=r,this.content=this.wrapper.lastElementChild}var e=t.prototype;return e.onEnter=function(){},e.onEnterCompleted=function(){},e.onLeave=function(){},e.onLeaveCompleted=function(){},e.initialLoad=function(){this.onEnter(),this.onEnterCompleted()},e.update=function(){document.title=this.title,this.wrapper.insertAdjacentHTML("beforeend",this._contentString),this.content=this.wrapper.lastElementChild},e.remove=function(){this.wrapper.firstElementChild.remove()},e.enter=function(t,e){var n=this;return new Promise(function(r){n.onEnter(),t.enter({trigger:e,to:n.content}).then(function(){n.onEnterCompleted(),r()})})},e.leave=function(t,e,n){var r=this;return new Promise(function(i){r.onLeave(),t.leave({trigger:e,from:r.content}).then(function(){n&&r.remove(),r.onLeaveCompleted(),i()})})},t}(),u=/*#__PURE__*/function(){function t(){this.data=new Map,this.regexCache=new Map}var e=t.prototype;return e.add=function(t,e,n){this.data.has(t)||(this.data.set(t,new Map),this.regexCache.set(t,new RegExp("^"+t+"$"))),this.data.get(t).set(e,n),this.regexCache.set(e,new RegExp("^"+e+"$"))},e.findMatch=function(t,e){for(var n,i=r(this.data);!(n=i()).done;){var o=n.value,a=o[1];if(t.pathname.match(this.regexCache.get(o[0]))){for(var c,s=r(a);!(c=s()).done;){var h=c.value,u=h[1];if(e.pathname.match(this.regexCache.get(h[0])))return u}break}}return null},t}(),f=/*#__PURE__*/function(){function e(t){var e=this;void 0===t&&(t={}),this.isTransitioning=!1,this.currentCacheEntry=null,this.cache=new Map,this.onClick=function(t){if(!t.metaKey&&!t.ctrlKey){var n=o(t.currentTarget.href);if(e.currentLocation=o(window.location.href),e.currentLocation.host!==n.host)return;if(e.currentLocation.href!==n.href||e.currentLocation.hasHash&&!n.hasHash)return t.preventDefault(),void e.navigateTo(n.raw,t.currentTarget.dataset.transition||!1,t.currentTarget);e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return window.location.pathname!==e.currentLocation.pathname&&(e.isTransitioning?(window.history.pushState({},"",e.currentLocation.href),!1):void e.navigateTo(window.location.href,!1,"popstate"))};var n=t.links,r=void 0===n?"a:not([target]):not([href^=\\#]):not([data-taxi-ignore])":n,i=t.removeOldContent,a=void 0===i||i,c=t.renderers,u=t.transitions,f=void 0===u?{default:s}:u,l=t.reloadJsFilter,d=void 0===l?function(t){return void 0!==t.dataset.taxiReload}:l;this.renderers=void 0===c?{default:h}:c,this.transitions=f,this.defaultRenderer=this.renderers.default||h,this.defaultTransition=this.transitions.default||s,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=d,this.removeOldContent=a,this.cache=new Map,this.attachEvents(r),this.currentLocation=o(window.location.href),this.cache.set(this.currentLocation.href,this.createCacheEntry(document.cloneNode(!0))),this.currentCacheEntry=this.cache.get(this.currentLocation.href),this.currentCacheEntry.renderer.initialLoad()}var n=e.prototype;return n.setDefaultRenderer=function(t){this.defaultRenderer=this.renderers[t]},n.setDefaultTransition=function(t){this.defaultTransition=this.transitions[t]},n.addRoute=function(t,e,n){this.router||(this.router=new u),this.router.add(t,e,n)},n.preload=function(t){var e=this;return t=o(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t).then(function(n){try{return e.cache.set(t,e.createCacheEntry(n)),Promise.resolve()}catch(t){return Promise.reject(t)}})},n.updateCache=function(){var t=o(window.location.href).href;this.cache.has(t)&&(this.cache.delete(t),this.cache.set(t,this.createCacheEntry(document.cloneNode(!0))))},n.clearCache=function(t){var e=o(t||window.location.href).href;this.cache.has(e)&&this.cache.delete(e)},n.navigateTo=function(t,e,n){var r=this;return void 0===e&&(e=!1),void 0===n&&(n=!1),new Promise(function(i,a){if(r.isTransitioning)a(new Error("A transition is currently in progress"));else{r.targetLocation=o(t);var c=new(r.chooseTransition(e))({wrapper:r.wrapper});r.beforeFetch(r.targetLocation,c,n).then(function(){try{return r.cache.has(r.targetLocation.href)?Promise.resolve(r.afterFetch(r.targetLocation,c,r.cache.get(r.targetLocation.href),n)):Promise.resolve(r.fetch(r.targetLocation.raw).then(function(t){try{return Promise.resolve(r.afterFetch(r.targetLocation,c,r.createCacheEntry(t),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}}).then(function(){i()})}})},n.on=function(e,n){t.on(e,n)},n.off=function(e,n){t.off(e,n)},n.beforeFetch=function(e,n,r){var i=this;return this.isTransitioning=!0,t.emit("NAVIGATE_OUT",{from:this.currentCacheEntry,trigger:r}),new Promise(function(t){i.currentCacheEntry.renderer.leave(n,r,i.removeOldContent).then(function(){"popstate"!==r&&window.history.pushState({},"",e.raw),t()})})},n.afterFetch=function(e,n,r,i){var o=this;return this.cache.has(e.href)||this.cache.set(e.href,r),this.currentLocation=e,new Promise(function(e){r.renderer.update(),t.emit("NAVIGATE_IN",{from:o.currentCacheEntry,to:r,trigger:i}),o.reloadJsFilter&&o.loadScripts(r.scripts),r.renderer.enter(n,i).then(function(){t.emit("NAVIGATE_END",{from:o.currentCacheEntry,to:r,trigger:i}),o.currentCacheEntry=r,o.isTransitioning=!1,e()})})},n.loadScripts=function(t){for(var e,n=[].concat(t),i=[].concat(document.querySelectorAll("script")).filter(this.reloadJsFilter),o=0;o<i.length;o++)for(var s=0;s<n.length;s++)if(i[o].outerHTML===n[s].outerHTML){(e=i[o]).parentNode.replaceChild(c(e),e),n.splice(s,1);break}for(var h,u=r(n);!(h=u()).done;)a(h.value)},n.attachEvents=function(e){t.delegate("click",e,this.onClick),t.on("popstate",window,this.onPopstate)},n.fetch=function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}(function(t){return new Promise(function(e){fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(function(e){return e.ok||(console.warn("Taxi encountered a non 2xx HTTP status code"),window.location.href=t),e.text()}).then(function(t){var n;e("string"==typeof(n=t)?i.parseFromString(n,"text/html"):n)}).catch(function(e){console.warn(e),window.location.href=t})})}),n.chooseTransition=function(t){var e;if(t)return this.transitions[t];var n=null==(e=this.router)?void 0:e.findMatch(this.currentLocation,this.targetLocation);return n?this.transitions[n]:this.defaultTransition},n.createCacheEntry=function(t){var e=t.querySelector("[data-taxi-view]"),n=e.dataset.taxiView.length?this.renderers[e.dataset.taxiView]:this.defaultRenderer;return{page:t,content:e,scripts:this.reloadJsFilter?[].concat(t.querySelectorAll("script")).filter(this.reloadJsFilter):[],title:t.title,renderer:new n({wrapper:this.wrapper,title:t.title,content:e,page:t})}},e}();export{f as Core,h as Renderer,s as Transition}; | ||
import t from"@unseenco/e";function e(){return e=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},e.apply(this,arguments)}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function r(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i=new DOMParser;function o(t){var e=new URL(t,window.location.origin),n=null;return e.hash.length&&(n=t.replace(e.hash,"")),{hasHash:e.hash.length>0,pathname:e.pathname,host:e.host,raw:t,href:n||e.href}}function a(t){"HEAD"===t.parentNode.tagName?document.head.appendChild(c(t)):document.body.appendChild(c(t))}function c(t){for(var e=document.createElement("SCRIPT"),n=0;n<t.attributes.length;n++){var r=t.attributes[n];e.setAttribute(r.nodeName,r.nodeValue)}return t.innerHTML&&(e.innerHTML=t.innerHTML),e}var s=/*#__PURE__*/function(){function t(t){this.wrapper=t.wrapper}var n=t.prototype;return n.leave=function(t){var n=this;return new Promise(function(r){n.onLeave(e({},t,{done:r}))})},n.enter=function(t){var n=this;return new Promise(function(r){n.onEnter(e({},t,{done:r}))})},n.onLeave=function(t){(0,t.done)()},n.onEnter=function(t){(0,t.done)()},t}(),h=/*#__PURE__*/function(){function t(t){var e=t.page,n=t.title,r=t.wrapper;this._contentString=t.content.outerHTML,this.page=e,this.title=n,this.wrapper=r,this.content=this.wrapper.lastElementChild}var e=t.prototype;return e.onEnter=function(){},e.onEnterCompleted=function(){},e.onLeave=function(){},e.onLeaveCompleted=function(){},e.initialLoad=function(){this.onEnter(),this.onEnterCompleted()},e.update=function(){document.title=this.title,this.wrapper.insertAdjacentHTML("beforeend",this._contentString),this.content=this.wrapper.lastElementChild},e.remove=function(){this.wrapper.firstElementChild.remove()},e.enter=function(t,e){var n=this;return new Promise(function(r){n.onEnter(),t.enter({trigger:e,to:n.content}).then(function(){n.onEnterCompleted(),r()})})},e.leave=function(t,e,n){var r=this;return new Promise(function(i){r.onLeave(),t.leave({trigger:e,from:r.content}).then(function(){n&&r.remove(),r.onLeaveCompleted(),i()})})},t}(),u=/*#__PURE__*/function(){function t(){this.data=new Map,this.regexCache=new Map}var e=t.prototype;return e.add=function(t,e,n){this.data.has(t)||(this.data.set(t,new Map),this.regexCache.set(t,new RegExp("^"+t+"$"))),this.data.get(t).set(e,n),this.regexCache.set(e,new RegExp("^"+e+"$"))},e.findMatch=function(t,e){for(var n,i=r(this.data);!(n=i()).done;){var o=n.value,a=o[1];if(t.pathname.match(this.regexCache.get(o[0]))){for(var c,s=r(a);!(c=s()).done;){var h=c.value,u=h[1];if(e.pathname.match(this.regexCache.get(h[0])))return u}break}}return null},t}(),f=/*#__PURE__*/function(){function e(t){var e=this;void 0===t&&(t={}),this.isTransitioning=!1,this.currentCacheEntry=null,this.cache=new Map,this.onClick=function(t){if(!t.metaKey&&!t.ctrlKey){var n=o(t.currentTarget.href);if(e.currentLocation=o(window.location.href),e.currentLocation.host!==n.host)return;if(e.currentLocation.href!==n.href||e.currentLocation.hasHash&&!n.hasHash)return t.preventDefault(),void e.navigateTo(n.raw,t.currentTarget.dataset.transition||!1,t.currentTarget);e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return window.location.pathname!==e.currentLocation.pathname&&(!e.allowInterruption&&e.isTransitioning?(window.history.pushState({},"",e.currentLocation.href),!1):void e.navigateTo(window.location.href,!1,"popstate"))};var n=t.links,r=void 0===n?"a:not([target]):not([href^=\\#]):not([data-taxi-ignore])":n,i=t.removeOldContent,a=void 0===i||i,c=t.allowInterruption,u=void 0!==c&&c,f=t.renderers,l=t.transitions,d=void 0===l?{default:s}:l,p=t.reloadJsFilter,v=void 0===p?function(t){return void 0!==t.dataset.taxiReload}:p;this.renderers=void 0===f?{default:h}:f,this.transitions=d,this.defaultRenderer=this.renderers.default||h,this.defaultTransition=this.transitions.default||s,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=v,this.removeOldContent=a,this.allowInterruption=u,this.cache=new Map,this.attachEvents(r),this.currentLocation=o(window.location.href),this.cache.set(this.currentLocation.href,this.createCacheEntry(document.cloneNode(!0))),this.currentCacheEntry=this.cache.get(this.currentLocation.href),this.currentCacheEntry.renderer.initialLoad()}var n=e.prototype;return n.setDefaultRenderer=function(t){this.defaultRenderer=this.renderers[t]},n.setDefaultTransition=function(t){this.defaultTransition=this.transitions[t]},n.addRoute=function(t,e,n){this.router||(this.router=new u),this.router.add(t,e,n)},n.preload=function(t){var e=this;return t=o(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t).then(function(n){try{return e.cache.set(t,e.createCacheEntry(n)),Promise.resolve()}catch(t){return Promise.reject(t)}})},n.updateCache=function(){var t=o(window.location.href).href;this.cache.has(t)&&(this.cache.delete(t),this.cache.set(t,this.createCacheEntry(document.cloneNode(!0))))},n.clearCache=function(t){var e=o(t||window.location.href).href;this.cache.has(e)&&this.cache.delete(e)},n.navigateTo=function(t,e,n){var r=this;return void 0===e&&(e=!1),void 0===n&&(n=!1),new Promise(function(i,a){if(r.allowInterruption||!r.isTransitioning){r.targetLocation=o(t);var c=new(r.chooseTransition(e))({wrapper:r.wrapper});r.beforeFetch(r.targetLocation,c,n).then(function(){try{return r.cache.has(r.targetLocation.href)?Promise.resolve(r.afterFetch(r.targetLocation,c,r.cache.get(r.targetLocation.href),n)):Promise.resolve(r.fetch(r.targetLocation.raw).then(function(t){try{return Promise.resolve(r.afterFetch(r.targetLocation,c,r.createCacheEntry(t),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}}).then(function(){i()})}else a(new Error("A transition is currently in progress"))})},n.on=function(e,n){t.on(e,n)},n.off=function(e,n){t.off(e,n)},n.beforeFetch=function(e,n,r){var i=this;return this.isTransitioning=!0,t.emit("NAVIGATE_OUT",{from:this.currentCacheEntry,trigger:r}),new Promise(function(t){i.currentCacheEntry.renderer.leave(n,r,i.removeOldContent).then(function(){"popstate"!==r&&window.history.pushState({},"",e.raw),t()})})},n.afterFetch=function(e,n,r,i){var o=this;return this.cache.has(e.href)||this.cache.set(e.href,r),this.currentLocation=e,new Promise(function(e){r.renderer.update(),t.emit("NAVIGATE_IN",{from:o.currentCacheEntry,to:r,trigger:i}),o.reloadJsFilter&&o.loadScripts(r.scripts),r.renderer.enter(n,i).then(function(){t.emit("NAVIGATE_END",{from:o.currentCacheEntry,to:r,trigger:i}),o.currentCacheEntry=r,o.isTransitioning=!1,e()})})},n.loadScripts=function(t){for(var e,n=[].concat(t),i=[].concat(document.querySelectorAll("script")).filter(this.reloadJsFilter),o=0;o<i.length;o++)for(var s=0;s<n.length;s++)if(i[o].outerHTML===n[s].outerHTML){(e=i[o]).parentNode.replaceChild(c(e),e),n.splice(s,1);break}for(var h,u=r(n);!(h=u()).done;)a(h.value)},n.attachEvents=function(e){t.delegate("click",e,this.onClick),t.on("popstate",window,this.onPopstate)},n.fetch=function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}(function(t){return new Promise(function(e){fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(function(e){return e.ok||(console.warn("Taxi encountered a non 2xx HTTP status code"),window.location.href=t),e.text()}).then(function(t){var n;e("string"==typeof(n=t)?i.parseFromString(n,"text/html"):n)}).catch(function(e){console.warn(e),window.location.href=t})})}),n.chooseTransition=function(t){var e;if(t)return this.transitions[t];var n=null==(e=this.router)?void 0:e.findMatch(this.currentLocation,this.targetLocation);return n?this.transitions[n]:this.defaultTransition},n.createCacheEntry=function(t){var e=t.querySelector("[data-taxi-view]"),n=e.dataset.taxiView.length?this.renderers[e.dataset.taxiView]:this.defaultRenderer;return{page:t,content:e,scripts:this.reloadJsFilter?[].concat(t.querySelectorAll("script")).filter(this.reloadJsFilter):[],title:t.title,renderer:new n({wrapper:this.wrapper,title:t.title,content:e,page:t})}},e}();export{f as Core,h as Renderer,s as Transition}; | ||
//# sourceMappingURL=taxi.esm.js.map |
@@ -1,2 +0,2 @@ | ||
function t(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var e=/*#__PURE__*/t(require("@unseenco/e"));function n(){return n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},n.apply(this,arguments)}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function i(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o=new DOMParser;function a(t){var e=new URL(t,window.location.origin),n=null;return e.hash.length&&(n=t.replace(e.hash,"")),{hasHash:e.hash.length>0,pathname:e.pathname,host:e.host,raw:t,href:n||e.href}}function c(t){"HEAD"===t.parentNode.tagName?document.head.appendChild(s(t)):document.body.appendChild(s(t))}function s(t){for(var e=document.createElement("SCRIPT"),n=0;n<t.attributes.length;n++){var r=t.attributes[n];e.setAttribute(r.nodeName,r.nodeValue)}return t.innerHTML&&(e.innerHTML=t.innerHTML),e}var h=/*#__PURE__*/function(){function t(t){this.wrapper=t.wrapper}var e=t.prototype;return e.leave=function(t){var e=this;return new Promise(function(r){e.onLeave(n({},t,{done:r}))})},e.enter=function(t){var e=this;return new Promise(function(r){e.onEnter(n({},t,{done:r}))})},e.onLeave=function(t){(0,t.done)()},e.onEnter=function(t){(0,t.done)()},t}(),u=/*#__PURE__*/function(){function t(t){var e=t.page,n=t.title,r=t.wrapper;this._contentString=t.content.outerHTML,this.page=e,this.title=n,this.wrapper=r,this.content=this.wrapper.lastElementChild}var e=t.prototype;return e.onEnter=function(){},e.onEnterCompleted=function(){},e.onLeave=function(){},e.onLeaveCompleted=function(){},e.initialLoad=function(){this.onEnter(),this.onEnterCompleted()},e.update=function(){document.title=this.title,this.wrapper.insertAdjacentHTML("beforeend",this._contentString),this.content=this.wrapper.lastElementChild},e.remove=function(){this.wrapper.firstElementChild.remove()},e.enter=function(t,e){var n=this;return new Promise(function(r){n.onEnter(),t.enter({trigger:e,to:n.content}).then(function(){n.onEnterCompleted(),r()})})},e.leave=function(t,e,n){var r=this;return new Promise(function(i){r.onLeave(),t.leave({trigger:e,from:r.content}).then(function(){n&&r.remove(),r.onLeaveCompleted(),i()})})},t}(),f=/*#__PURE__*/function(){function t(){this.data=new Map,this.regexCache=new Map}var e=t.prototype;return e.add=function(t,e,n){this.data.has(t)||(this.data.set(t,new Map),this.regexCache.set(t,new RegExp("^"+t+"$"))),this.data.get(t).set(e,n),this.regexCache.set(e,new RegExp("^"+e+"$"))},e.findMatch=function(t,e){for(var n,r=i(this.data);!(n=r()).done;){var o=n.value,a=o[1];if(t.pathname.match(this.regexCache.get(o[0]))){for(var c,s=i(a);!(c=s()).done;){var h=c.value,u=h[1];if(e.pathname.match(this.regexCache.get(h[0])))return u}break}}return null},t}(),l=/*#__PURE__*/function(){function t(t){var e=this;void 0===t&&(t={}),this.isTransitioning=!1,this.currentCacheEntry=null,this.cache=new Map,this.onClick=function(t){if(!t.metaKey&&!t.ctrlKey){var n=a(t.currentTarget.href);if(e.currentLocation=a(window.location.href),e.currentLocation.host!==n.host)return;if(e.currentLocation.href!==n.href||e.currentLocation.hasHash&&!n.hasHash)return t.preventDefault(),void e.navigateTo(n.raw,t.currentTarget.dataset.transition||!1,t.currentTarget);e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return window.location.pathname!==e.currentLocation.pathname&&(e.isTransitioning?(window.history.pushState({},"",e.currentLocation.href),!1):void e.navigateTo(window.location.href,!1,"popstate"))};var n=t.links,r=void 0===n?"a:not([target]):not([href^=\\#]):not([data-taxi-ignore])":n,i=t.removeOldContent,o=void 0===i||i,c=t.renderers,s=t.transitions,f=void 0===s?{default:h}:s,l=t.reloadJsFilter,d=void 0===l?function(t){return void 0!==t.dataset.taxiReload}:l;this.renderers=void 0===c?{default:u}:c,this.transitions=f,this.defaultRenderer=this.renderers.default||u,this.defaultTransition=this.transitions.default||h,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=d,this.removeOldContent=o,this.cache=new Map,this.attachEvents(r),this.currentLocation=a(window.location.href),this.cache.set(this.currentLocation.href,this.createCacheEntry(document.cloneNode(!0))),this.currentCacheEntry=this.cache.get(this.currentLocation.href),this.currentCacheEntry.renderer.initialLoad()}var n=t.prototype;return n.setDefaultRenderer=function(t){this.defaultRenderer=this.renderers[t]},n.setDefaultTransition=function(t){this.defaultTransition=this.transitions[t]},n.addRoute=function(t,e,n){this.router||(this.router=new f),this.router.add(t,e,n)},n.preload=function(t){var e=this;return t=a(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t).then(function(n){try{return e.cache.set(t,e.createCacheEntry(n)),Promise.resolve()}catch(t){return Promise.reject(t)}})},n.updateCache=function(){var t=a(window.location.href).href;this.cache.has(t)&&(this.cache.delete(t),this.cache.set(t,this.createCacheEntry(document.cloneNode(!0))))},n.clearCache=function(t){var e=a(t||window.location.href).href;this.cache.has(e)&&this.cache.delete(e)},n.navigateTo=function(t,e,n){var r=this;return void 0===e&&(e=!1),void 0===n&&(n=!1),new Promise(function(i,o){if(r.isTransitioning)o(new Error("A transition is currently in progress"));else{r.targetLocation=a(t);var c=new(r.chooseTransition(e))({wrapper:r.wrapper});r.beforeFetch(r.targetLocation,c,n).then(function(){try{return r.cache.has(r.targetLocation.href)?Promise.resolve(r.afterFetch(r.targetLocation,c,r.cache.get(r.targetLocation.href),n)):Promise.resolve(r.fetch(r.targetLocation.raw).then(function(t){try{return Promise.resolve(r.afterFetch(r.targetLocation,c,r.createCacheEntry(t),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}}).then(function(){i()})}})},n.on=function(t,n){e.default.on(t,n)},n.off=function(t,n){e.default.off(t,n)},n.beforeFetch=function(t,n,r){var i=this;return this.isTransitioning=!0,e.default.emit("NAVIGATE_OUT",{from:this.currentCacheEntry,trigger:r}),new Promise(function(e){i.currentCacheEntry.renderer.leave(n,r,i.removeOldContent).then(function(){"popstate"!==r&&window.history.pushState({},"",t.raw),e()})})},n.afterFetch=function(t,n,r,i){var o=this;return this.cache.has(t.href)||this.cache.set(t.href,r),this.currentLocation=t,new Promise(function(t){r.renderer.update(),e.default.emit("NAVIGATE_IN",{from:o.currentCacheEntry,to:r,trigger:i}),o.reloadJsFilter&&o.loadScripts(r.scripts),r.renderer.enter(n,i).then(function(){e.default.emit("NAVIGATE_END",{from:o.currentCacheEntry,to:r,trigger:i}),o.currentCacheEntry=r,o.isTransitioning=!1,t()})})},n.loadScripts=function(t){for(var e,n=[].concat(t),r=[].concat(document.querySelectorAll("script")).filter(this.reloadJsFilter),o=0;o<r.length;o++)for(var a=0;a<n.length;a++)if(r[o].outerHTML===n[a].outerHTML){(e=r[o]).parentNode.replaceChild(s(e),e),n.splice(a,1);break}for(var h,u=i(n);!(h=u()).done;)c(h.value)},n.attachEvents=function(t){e.default.delegate("click",t,this.onClick),e.default.on("popstate",window,this.onPopstate)},n.fetch=function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}(function(t){return new Promise(function(e){fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(function(e){return e.ok||(console.warn("Taxi encountered a non 2xx HTTP status code"),window.location.href=t),e.text()}).then(function(t){var n;e("string"==typeof(n=t)?o.parseFromString(n,"text/html"):n)}).catch(function(e){console.warn(e),window.location.href=t})})}),n.chooseTransition=function(t){var e;if(t)return this.transitions[t];var n=null==(e=this.router)?void 0:e.findMatch(this.currentLocation,this.targetLocation);return n?this.transitions[n]:this.defaultTransition},n.createCacheEntry=function(t){var e=t.querySelector("[data-taxi-view]"),n=e.dataset.taxiView.length?this.renderers[e.dataset.taxiView]:this.defaultRenderer;return{page:t,content:e,scripts:this.reloadJsFilter?[].concat(t.querySelectorAll("script")).filter(this.reloadJsFilter):[],title:t.title,renderer:new n({wrapper:this.wrapper,title:t.title,content:e,page:t})}},t}();exports.Core=l,exports.Renderer=u,exports.Transition=h; | ||
function t(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var e=/*#__PURE__*/t(require("@unseenco/e"));function n(){return n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},n.apply(this,arguments)}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function i(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o=new DOMParser;function a(t){var e=new URL(t,window.location.origin),n=null;return e.hash.length&&(n=t.replace(e.hash,"")),{hasHash:e.hash.length>0,pathname:e.pathname,host:e.host,raw:t,href:n||e.href}}function c(t){"HEAD"===t.parentNode.tagName?document.head.appendChild(s(t)):document.body.appendChild(s(t))}function s(t){for(var e=document.createElement("SCRIPT"),n=0;n<t.attributes.length;n++){var r=t.attributes[n];e.setAttribute(r.nodeName,r.nodeValue)}return t.innerHTML&&(e.innerHTML=t.innerHTML),e}var h=/*#__PURE__*/function(){function t(t){this.wrapper=t.wrapper}var e=t.prototype;return e.leave=function(t){var e=this;return new Promise(function(r){e.onLeave(n({},t,{done:r}))})},e.enter=function(t){var e=this;return new Promise(function(r){e.onEnter(n({},t,{done:r}))})},e.onLeave=function(t){(0,t.done)()},e.onEnter=function(t){(0,t.done)()},t}(),u=/*#__PURE__*/function(){function t(t){var e=t.page,n=t.title,r=t.wrapper;this._contentString=t.content.outerHTML,this.page=e,this.title=n,this.wrapper=r,this.content=this.wrapper.lastElementChild}var e=t.prototype;return e.onEnter=function(){},e.onEnterCompleted=function(){},e.onLeave=function(){},e.onLeaveCompleted=function(){},e.initialLoad=function(){this.onEnter(),this.onEnterCompleted()},e.update=function(){document.title=this.title,this.wrapper.insertAdjacentHTML("beforeend",this._contentString),this.content=this.wrapper.lastElementChild},e.remove=function(){this.wrapper.firstElementChild.remove()},e.enter=function(t,e){var n=this;return new Promise(function(r){n.onEnter(),t.enter({trigger:e,to:n.content}).then(function(){n.onEnterCompleted(),r()})})},e.leave=function(t,e,n){var r=this;return new Promise(function(i){r.onLeave(),t.leave({trigger:e,from:r.content}).then(function(){n&&r.remove(),r.onLeaveCompleted(),i()})})},t}(),f=/*#__PURE__*/function(){function t(){this.data=new Map,this.regexCache=new Map}var e=t.prototype;return e.add=function(t,e,n){this.data.has(t)||(this.data.set(t,new Map),this.regexCache.set(t,new RegExp("^"+t+"$"))),this.data.get(t).set(e,n),this.regexCache.set(e,new RegExp("^"+e+"$"))},e.findMatch=function(t,e){for(var n,r=i(this.data);!(n=r()).done;){var o=n.value,a=o[1];if(t.pathname.match(this.regexCache.get(o[0]))){for(var c,s=i(a);!(c=s()).done;){var h=c.value,u=h[1];if(e.pathname.match(this.regexCache.get(h[0])))return u}break}}return null},t}(),l=/*#__PURE__*/function(){function t(t){var e=this;void 0===t&&(t={}),this.isTransitioning=!1,this.currentCacheEntry=null,this.cache=new Map,this.onClick=function(t){if(!t.metaKey&&!t.ctrlKey){var n=a(t.currentTarget.href);if(e.currentLocation=a(window.location.href),e.currentLocation.host!==n.host)return;if(e.currentLocation.href!==n.href||e.currentLocation.hasHash&&!n.hasHash)return t.preventDefault(),void e.navigateTo(n.raw,t.currentTarget.dataset.transition||!1,t.currentTarget);e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return window.location.pathname!==e.currentLocation.pathname&&(!e.allowInterruption&&e.isTransitioning?(window.history.pushState({},"",e.currentLocation.href),!1):void e.navigateTo(window.location.href,!1,"popstate"))};var n=t.links,r=void 0===n?"a:not([target]):not([href^=\\#]):not([data-taxi-ignore])":n,i=t.removeOldContent,o=void 0===i||i,c=t.allowInterruption,s=void 0!==c&&c,f=t.renderers,l=t.transitions,d=void 0===l?{default:h}:l,p=t.reloadJsFilter,v=void 0===p?function(t){return void 0!==t.dataset.taxiReload}:p;this.renderers=void 0===f?{default:u}:f,this.transitions=d,this.defaultRenderer=this.renderers.default||u,this.defaultTransition=this.transitions.default||h,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=v,this.removeOldContent=o,this.allowInterruption=s,this.cache=new Map,this.attachEvents(r),this.currentLocation=a(window.location.href),this.cache.set(this.currentLocation.href,this.createCacheEntry(document.cloneNode(!0))),this.currentCacheEntry=this.cache.get(this.currentLocation.href),this.currentCacheEntry.renderer.initialLoad()}var n=t.prototype;return n.setDefaultRenderer=function(t){this.defaultRenderer=this.renderers[t]},n.setDefaultTransition=function(t){this.defaultTransition=this.transitions[t]},n.addRoute=function(t,e,n){this.router||(this.router=new f),this.router.add(t,e,n)},n.preload=function(t){var e=this;return t=a(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t).then(function(n){try{return e.cache.set(t,e.createCacheEntry(n)),Promise.resolve()}catch(t){return Promise.reject(t)}})},n.updateCache=function(){var t=a(window.location.href).href;this.cache.has(t)&&(this.cache.delete(t),this.cache.set(t,this.createCacheEntry(document.cloneNode(!0))))},n.clearCache=function(t){var e=a(t||window.location.href).href;this.cache.has(e)&&this.cache.delete(e)},n.navigateTo=function(t,e,n){var r=this;return void 0===e&&(e=!1),void 0===n&&(n=!1),new Promise(function(i,o){if(r.allowInterruption||!r.isTransitioning){r.targetLocation=a(t);var c=new(r.chooseTransition(e))({wrapper:r.wrapper});r.beforeFetch(r.targetLocation,c,n).then(function(){try{return r.cache.has(r.targetLocation.href)?Promise.resolve(r.afterFetch(r.targetLocation,c,r.cache.get(r.targetLocation.href),n)):Promise.resolve(r.fetch(r.targetLocation.raw).then(function(t){try{return Promise.resolve(r.afterFetch(r.targetLocation,c,r.createCacheEntry(t),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}}).then(function(){i()})}else o(new Error("A transition is currently in progress"))})},n.on=function(t,n){e.default.on(t,n)},n.off=function(t,n){e.default.off(t,n)},n.beforeFetch=function(t,n,r){var i=this;return this.isTransitioning=!0,e.default.emit("NAVIGATE_OUT",{from:this.currentCacheEntry,trigger:r}),new Promise(function(e){i.currentCacheEntry.renderer.leave(n,r,i.removeOldContent).then(function(){"popstate"!==r&&window.history.pushState({},"",t.raw),e()})})},n.afterFetch=function(t,n,r,i){var o=this;return this.cache.has(t.href)||this.cache.set(t.href,r),this.currentLocation=t,new Promise(function(t){r.renderer.update(),e.default.emit("NAVIGATE_IN",{from:o.currentCacheEntry,to:r,trigger:i}),o.reloadJsFilter&&o.loadScripts(r.scripts),r.renderer.enter(n,i).then(function(){e.default.emit("NAVIGATE_END",{from:o.currentCacheEntry,to:r,trigger:i}),o.currentCacheEntry=r,o.isTransitioning=!1,t()})})},n.loadScripts=function(t){for(var e,n=[].concat(t),r=[].concat(document.querySelectorAll("script")).filter(this.reloadJsFilter),o=0;o<r.length;o++)for(var a=0;a<n.length;a++)if(r[o].outerHTML===n[a].outerHTML){(e=r[o]).parentNode.replaceChild(s(e),e),n.splice(a,1);break}for(var h,u=i(n);!(h=u()).done;)c(h.value)},n.attachEvents=function(t){e.default.delegate("click",t,this.onClick),e.default.on("popstate",window,this.onPopstate)},n.fetch=function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}(function(t){return new Promise(function(e){fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(function(e){return e.ok||(console.warn("Taxi encountered a non 2xx HTTP status code"),window.location.href=t),e.text()}).then(function(t){var n;e("string"==typeof(n=t)?o.parseFromString(n,"text/html"):n)}).catch(function(e){console.warn(e),window.location.href=t})})}),n.chooseTransition=function(t){var e;if(t)return this.transitions[t];var n=null==(e=this.router)?void 0:e.findMatch(this.currentLocation,this.targetLocation);return n?this.transitions[n]:this.defaultTransition},n.createCacheEntry=function(t){var e=t.querySelector("[data-taxi-view]"),n=e.dataset.taxiView.length?this.renderers[e.dataset.taxiView]:this.defaultRenderer;return{page:t,content:e,scripts:this.reloadJsFilter?[].concat(t.querySelectorAll("script")).filter(this.reloadJsFilter):[],title:t.title,renderer:new n({wrapper:this.wrapper,title:t.title,content:e,page:t})}},t}();exports.Core=l,exports.Renderer=u,exports.Transition=h; | ||
//# sourceMappingURL=taxi.js.map |
@@ -1,2 +0,2 @@ | ||
import t from"@unseenco/e";const e=new DOMParser;function r(t){const e=new URL(t,window.location.origin);let r=null;return e.hash.length&&(r=t.replace(e.hash,"")),{hasHash:e.hash.length>0,pathname:e.pathname,host:e.host,raw:t,href:r||e.href}}function n(t){"HEAD"===t.parentNode.tagName?document.head.appendChild(i(t)):document.body.appendChild(i(t))}function i(t){const e=document.createElement("SCRIPT");for(let r=0;r<t.attributes.length;r++){const n=t.attributes[r];e.setAttribute(n.nodeName,n.nodeValue)}return t.innerHTML&&(e.innerHTML=t.innerHTML),e}function a(){return a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},a.apply(this,arguments)}class o{constructor({wrapper:t}){this.wrapper=t}leave(t){return new Promise(e=>{this.onLeave(a({},t,{done:e}))})}enter(t){return new Promise(e=>{this.onEnter(a({},t,{done:e}))})}onLeave({done:t}){t()}onEnter({done:t}){t()}}class s{constructor({content:t,page:e,title:r,wrapper:n}){this._contentString=t.outerHTML,this.page=e,this.title=r,this.wrapper=n,this.content=this.wrapper.lastElementChild}onEnter(){}onEnterCompleted(){}onLeave(){}onLeaveCompleted(){}initialLoad(){this.onEnter(),this.onEnterCompleted()}update(){document.title=this.title,this.wrapper.insertAdjacentHTML("beforeend",this._contentString),this.content=this.wrapper.lastElementChild}remove(){this.wrapper.firstElementChild.remove()}enter(t,e){return new Promise(r=>{this.onEnter(),t.enter({trigger:e,to:this.content}).then(()=>{this.onEnterCompleted(),r()})})}leave(t,e,r){return new Promise(n=>{this.onLeave(),t.leave({trigger:e,from:this.content}).then(()=>{r&&this.remove(),this.onLeaveCompleted(),n()})})}}class h{constructor(){this.data=new Map,this.regexCache=new Map}add(t,e,r){this.data.has(t)||(this.data.set(t,new Map),this.regexCache.set(t,new RegExp(`^${t}$`))),this.data.get(t).set(e,r),this.regexCache.set(e,new RegExp(`^${e}$`))}findMatch(t,e){for(const[r,n]of this.data)if(t.pathname.match(this.regexCache.get(r))){for(const[t,r]of n)if(e.pathname.match(this.regexCache.get(t)))return r;break}return null}}class c{constructor(t={}){this.isTransitioning=!1,this.currentCacheEntry=null,this.cache=new Map,this.onClick=t=>{if(!t.metaKey&&!t.ctrlKey){const e=r(t.currentTarget.href);if(this.currentLocation=r(window.location.href),this.currentLocation.host!==e.host)return;if(this.currentLocation.href!==e.href||this.currentLocation.hasHash&&!e.hasHash)return t.preventDefault(),void this.navigateTo(e.raw,t.currentTarget.dataset.transition||!1,t.currentTarget);this.currentLocation.hasHash||e.hasHash||t.preventDefault()}},this.onPopstate=()=>window.location.pathname!==this.currentLocation.pathname&&(this.isTransitioning?(window.history.pushState({},"",this.currentLocation.href),!1):void this.navigateTo(window.location.href,!1,"popstate"));const{links:e="a:not([target]):not([href^=\\#]):not([data-taxi-ignore])",removeOldContent:n=!0,renderers:i={default:s},transitions:a={default:o},reloadJsFilter:h=(t=>void 0!==t.dataset.taxiReload)}=t;this.renderers=i,this.transitions=a,this.defaultRenderer=this.renderers.default||s,this.defaultTransition=this.transitions.default||o,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=h,this.removeOldContent=n,this.cache=new Map,this.attachEvents(e),this.currentLocation=r(window.location.href),this.cache.set(this.currentLocation.href,this.createCacheEntry(document.cloneNode(!0))),this.currentCacheEntry=this.cache.get(this.currentLocation.href),this.currentCacheEntry.renderer.initialLoad()}setDefaultRenderer(t){this.defaultRenderer=this.renderers[t]}setDefaultTransition(t){this.defaultTransition=this.transitions[t]}addRoute(t,e,r){this.router||(this.router=new h),this.router.add(t,e,r)}preload(t){var e=this;return t=r(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t).then(async function(r){e.cache.set(t,e.createCacheEntry(r))})}updateCache(){const t=r(window.location.href).href;this.cache.has(t)&&(this.cache.delete(t),this.cache.set(t,this.createCacheEntry(document.cloneNode(!0))))}clearCache(t){const e=r(t||window.location.href).href;this.cache.has(e)&&this.cache.delete(e)}navigateTo(t,e=!1,n=!1){var i=this;return new Promise((a,o)=>{if(this.isTransitioning)return void o(new Error("A transition is currently in progress"));this.targetLocation=r(t);const s=new(this.chooseTransition(e))({wrapper:this.wrapper});this.beforeFetch(this.targetLocation,s,n).then(async function(){return i.cache.has(i.targetLocation.href)?await i.afterFetch(i.targetLocation,s,i.cache.get(i.targetLocation.href),n):i.fetch(i.targetLocation.raw).then(async function(t){return await i.afterFetch(i.targetLocation,s,i.createCacheEntry(t),n)})}).then(()=>{a()})})}on(e,r){t.on(e,r)}off(e,r){t.off(e,r)}beforeFetch(e,r,n){return this.isTransitioning=!0,t.emit("NAVIGATE_OUT",{from:this.currentCacheEntry,trigger:n}),new Promise(t=>{this.currentCacheEntry.renderer.leave(r,n,this.removeOldContent).then(()=>{"popstate"!==n&&window.history.pushState({},"",e.raw),t()})})}afterFetch(e,r,n,i){return this.cache.has(e.href)||this.cache.set(e.href,n),this.currentLocation=e,new Promise(e=>{n.renderer.update(),t.emit("NAVIGATE_IN",{from:this.currentCacheEntry,to:n,trigger:i}),this.reloadJsFilter&&this.loadScripts(n.scripts),n.renderer.enter(r,i).then(()=>{t.emit("NAVIGATE_END",{from:this.currentCacheEntry,to:n,trigger:i}),this.currentCacheEntry=n,this.isTransitioning=!1,e()})})}loadScripts(t){const e=[...t],r=[...document.querySelectorAll("script")].filter(this.reloadJsFilter);for(let t=0;t<r.length;t++)for(let n=0;n<e.length;n++)if(r[t].outerHTML===e[n].outerHTML){(a=r[t]).parentNode.replaceChild(i(a),a),e.splice(n,1);break}var a;for(const t of e)n(t)}attachEvents(e){t.delegate("click",e,this.onClick),t.on("popstate",window,this.onPopstate)}fetch(t){return new Promise(r=>{fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(e=>(e.ok||(console.warn("Taxi encountered a non 2xx HTTP status code"),window.location.href=t),e.text())).then(t=>{var n;r("string"==typeof(n=t)?e.parseFromString(n,"text/html"):n)}).catch(e=>{console.warn(e),window.location.href=t})})}chooseTransition(t){var e;if(t)return this.transitions[t];const r=null==(e=this.router)?void 0:e.findMatch(this.currentLocation,this.targetLocation);return r?this.transitions[r]:this.defaultTransition}createCacheEntry(t){const e=t.querySelector("[data-taxi-view]"),r=e.dataset.taxiView.length?this.renderers[e.dataset.taxiView]:this.defaultRenderer;return{page:t,content:e,scripts:this.reloadJsFilter?[...t.querySelectorAll("script")].filter(this.reloadJsFilter):[],title:t.title,renderer:new r({wrapper:this.wrapper,title:t.title,content:e,page:t})}}}export{c as Core,s as Renderer,o as Transition}; | ||
import t from"@unseenco/e";const e=new DOMParser;function r(t){const e=new URL(t,window.location.origin);let r=null;return e.hash.length&&(r=t.replace(e.hash,"")),{hasHash:e.hash.length>0,pathname:e.pathname,host:e.host,raw:t,href:r||e.href}}function n(t){"HEAD"===t.parentNode.tagName?document.head.appendChild(i(t)):document.body.appendChild(i(t))}function i(t){const e=document.createElement("SCRIPT");for(let r=0;r<t.attributes.length;r++){const n=t.attributes[r];e.setAttribute(n.nodeName,n.nodeValue)}return t.innerHTML&&(e.innerHTML=t.innerHTML),e}function a(){return a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},a.apply(this,arguments)}class o{constructor({wrapper:t}){this.wrapper=t}leave(t){return new Promise(e=>{this.onLeave(a({},t,{done:e}))})}enter(t){return new Promise(e=>{this.onEnter(a({},t,{done:e}))})}onLeave({done:t}){t()}onEnter({done:t}){t()}}class s{constructor({content:t,page:e,title:r,wrapper:n}){this._contentString=t.outerHTML,this.page=e,this.title=r,this.wrapper=n,this.content=this.wrapper.lastElementChild}onEnter(){}onEnterCompleted(){}onLeave(){}onLeaveCompleted(){}initialLoad(){this.onEnter(),this.onEnterCompleted()}update(){document.title=this.title,this.wrapper.insertAdjacentHTML("beforeend",this._contentString),this.content=this.wrapper.lastElementChild}remove(){this.wrapper.firstElementChild.remove()}enter(t,e){return new Promise(r=>{this.onEnter(),t.enter({trigger:e,to:this.content}).then(()=>{this.onEnterCompleted(),r()})})}leave(t,e,r){return new Promise(n=>{this.onLeave(),t.leave({trigger:e,from:this.content}).then(()=>{r&&this.remove(),this.onLeaveCompleted(),n()})})}}class h{constructor(){this.data=new Map,this.regexCache=new Map}add(t,e,r){this.data.has(t)||(this.data.set(t,new Map),this.regexCache.set(t,new RegExp(`^${t}$`))),this.data.get(t).set(e,r),this.regexCache.set(e,new RegExp(`^${e}$`))}findMatch(t,e){for(const[r,n]of this.data)if(t.pathname.match(this.regexCache.get(r))){for(const[t,r]of n)if(e.pathname.match(this.regexCache.get(t)))return r;break}return null}}class c{constructor(t={}){this.isTransitioning=!1,this.currentCacheEntry=null,this.cache=new Map,this.onClick=t=>{if(!t.metaKey&&!t.ctrlKey){const e=r(t.currentTarget.href);if(this.currentLocation=r(window.location.href),this.currentLocation.host!==e.host)return;if(this.currentLocation.href!==e.href||this.currentLocation.hasHash&&!e.hasHash)return t.preventDefault(),void this.navigateTo(e.raw,t.currentTarget.dataset.transition||!1,t.currentTarget);this.currentLocation.hasHash||e.hasHash||t.preventDefault()}},this.onPopstate=()=>window.location.pathname!==this.currentLocation.pathname&&(!this.allowInterruption&&this.isTransitioning?(window.history.pushState({},"",this.currentLocation.href),!1):void this.navigateTo(window.location.href,!1,"popstate"));const{links:e="a:not([target]):not([href^=\\#]):not([data-taxi-ignore])",removeOldContent:n=!0,allowInterruption:i=!1,renderers:a={default:s},transitions:h={default:o},reloadJsFilter:c=(t=>void 0!==t.dataset.taxiReload)}=t;this.renderers=a,this.transitions=h,this.defaultRenderer=this.renderers.default||s,this.defaultTransition=this.transitions.default||o,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=c,this.removeOldContent=n,this.allowInterruption=i,this.cache=new Map,this.attachEvents(e),this.currentLocation=r(window.location.href),this.cache.set(this.currentLocation.href,this.createCacheEntry(document.cloneNode(!0))),this.currentCacheEntry=this.cache.get(this.currentLocation.href),this.currentCacheEntry.renderer.initialLoad()}setDefaultRenderer(t){this.defaultRenderer=this.renderers[t]}setDefaultTransition(t){this.defaultTransition=this.transitions[t]}addRoute(t,e,r){this.router||(this.router=new h),this.router.add(t,e,r)}preload(t){var e=this;return t=r(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t).then(async function(r){e.cache.set(t,e.createCacheEntry(r))})}updateCache(){const t=r(window.location.href).href;this.cache.has(t)&&(this.cache.delete(t),this.cache.set(t,this.createCacheEntry(document.cloneNode(!0))))}clearCache(t){const e=r(t||window.location.href).href;this.cache.has(e)&&this.cache.delete(e)}navigateTo(t,e=!1,n=!1){var i=this;return new Promise((a,o)=>{if(!this.allowInterruption&&this.isTransitioning)return void o(new Error("A transition is currently in progress"));this.targetLocation=r(t);const s=new(this.chooseTransition(e))({wrapper:this.wrapper});this.beforeFetch(this.targetLocation,s,n).then(async function(){return i.cache.has(i.targetLocation.href)?await i.afterFetch(i.targetLocation,s,i.cache.get(i.targetLocation.href),n):i.fetch(i.targetLocation.raw).then(async function(t){return await i.afterFetch(i.targetLocation,s,i.createCacheEntry(t),n)})}).then(()=>{a()})})}on(e,r){t.on(e,r)}off(e,r){t.off(e,r)}beforeFetch(e,r,n){return this.isTransitioning=!0,t.emit("NAVIGATE_OUT",{from:this.currentCacheEntry,trigger:n}),new Promise(t=>{this.currentCacheEntry.renderer.leave(r,n,this.removeOldContent).then(()=>{"popstate"!==n&&window.history.pushState({},"",e.raw),t()})})}afterFetch(e,r,n,i){return this.cache.has(e.href)||this.cache.set(e.href,n),this.currentLocation=e,new Promise(e=>{n.renderer.update(),t.emit("NAVIGATE_IN",{from:this.currentCacheEntry,to:n,trigger:i}),this.reloadJsFilter&&this.loadScripts(n.scripts),n.renderer.enter(r,i).then(()=>{t.emit("NAVIGATE_END",{from:this.currentCacheEntry,to:n,trigger:i}),this.currentCacheEntry=n,this.isTransitioning=!1,e()})})}loadScripts(t){const e=[...t],r=[...document.querySelectorAll("script")].filter(this.reloadJsFilter);for(let t=0;t<r.length;t++)for(let n=0;n<e.length;n++)if(r[t].outerHTML===e[n].outerHTML){(a=r[t]).parentNode.replaceChild(i(a),a),e.splice(n,1);break}var a;for(const t of e)n(t)}attachEvents(e){t.delegate("click",e,this.onClick),t.on("popstate",window,this.onPopstate)}fetch(t){return new Promise(r=>{fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(e=>(e.ok||(console.warn("Taxi encountered a non 2xx HTTP status code"),window.location.href=t),e.text())).then(t=>{var n;r("string"==typeof(n=t)?e.parseFromString(n,"text/html"):n)}).catch(e=>{console.warn(e),window.location.href=t})})}chooseTransition(t){var e;if(t)return this.transitions[t];const r=null==(e=this.router)?void 0:e.findMatch(this.currentLocation,this.targetLocation);return r?this.transitions[r]:this.defaultTransition}createCacheEntry(t){const e=t.querySelector("[data-taxi-view]"),r=e.dataset.taxiView.length?this.renderers[e.dataset.taxiView]:this.defaultRenderer;return{page:t,content:e,scripts:this.reloadJsFilter?[...t.querySelectorAll("script")].filter(this.reloadJsFilter):[],title:t.title,renderer:new r({wrapper:this.wrapper,title:t.title,content:e,page:t})}}}export{c as Core,s as Renderer,o as Transition}; | ||
//# sourceMappingURL=taxi.modern.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@unseenco/e")):"function"==typeof define&&define.amd?define(["exports","@unseenco/e"],e):e((t||self).taxi={},t.E)}(this,function(t,e){function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=/*#__PURE__*/n(e);function i(){return i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},i.apply(this,arguments)}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function a(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return o(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var c=new DOMParser;function s(t){var e=new URL(t,window.location.origin),n=null;return e.hash.length&&(n=t.replace(e.hash,"")),{hasHash:e.hash.length>0,pathname:e.pathname,host:e.host,raw:t,href:n||e.href}}function h(t){"HEAD"===t.parentNode.tagName?document.head.appendChild(u(t)):document.body.appendChild(u(t))}function u(t){for(var e=document.createElement("SCRIPT"),n=0;n<t.attributes.length;n++){var r=t.attributes[n];e.setAttribute(r.nodeName,r.nodeValue)}return t.innerHTML&&(e.innerHTML=t.innerHTML),e}var f=/*#__PURE__*/function(){function t(t){this.wrapper=t.wrapper}var e=t.prototype;return e.leave=function(t){var e=this;return new Promise(function(n){e.onLeave(i({},t,{done:n}))})},e.enter=function(t){var e=this;return new Promise(function(n){e.onEnter(i({},t,{done:n}))})},e.onLeave=function(t){(0,t.done)()},e.onEnter=function(t){(0,t.done)()},t}(),l=/*#__PURE__*/function(){function t(t){var e=t.page,n=t.title,r=t.wrapper;this._contentString=t.content.outerHTML,this.page=e,this.title=n,this.wrapper=r,this.content=this.wrapper.lastElementChild}var e=t.prototype;return e.onEnter=function(){},e.onEnterCompleted=function(){},e.onLeave=function(){},e.onLeaveCompleted=function(){},e.initialLoad=function(){this.onEnter(),this.onEnterCompleted()},e.update=function(){document.title=this.title,this.wrapper.insertAdjacentHTML("beforeend",this._contentString),this.content=this.wrapper.lastElementChild},e.remove=function(){this.wrapper.firstElementChild.remove()},e.enter=function(t,e){var n=this;return new Promise(function(r){n.onEnter(),t.enter({trigger:e,to:n.content}).then(function(){n.onEnterCompleted(),r()})})},e.leave=function(t,e,n){var r=this;return new Promise(function(i){r.onLeave(),t.leave({trigger:e,from:r.content}).then(function(){n&&r.remove(),r.onLeaveCompleted(),i()})})},t}(),d=/*#__PURE__*/function(){function t(){this.data=new Map,this.regexCache=new Map}var e=t.prototype;return e.add=function(t,e,n){this.data.has(t)||(this.data.set(t,new Map),this.regexCache.set(t,new RegExp("^"+t+"$"))),this.data.get(t).set(e,n),this.regexCache.set(e,new RegExp("^"+e+"$"))},e.findMatch=function(t,e){for(var n,r=a(this.data);!(n=r()).done;){var i=n.value,o=i[1];if(t.pathname.match(this.regexCache.get(i[0]))){for(var c,s=a(o);!(c=s()).done;){var h=c.value,u=h[1];if(e.pathname.match(this.regexCache.get(h[0])))return u}break}}return null},t}(),p=/*#__PURE__*/function(){function t(t){var e=this;void 0===t&&(t={}),this.isTransitioning=!1,this.currentCacheEntry=null,this.cache=new Map,this.onClick=function(t){if(!t.metaKey&&!t.ctrlKey){var n=s(t.currentTarget.href);if(e.currentLocation=s(window.location.href),e.currentLocation.host!==n.host)return;if(e.currentLocation.href!==n.href||e.currentLocation.hasHash&&!n.hasHash)return t.preventDefault(),void e.navigateTo(n.raw,t.currentTarget.dataset.transition||!1,t.currentTarget);e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return window.location.pathname!==e.currentLocation.pathname&&(e.isTransitioning?(window.history.pushState({},"",e.currentLocation.href),!1):void e.navigateTo(window.location.href,!1,"popstate"))};var n=t.links,r=void 0===n?"a:not([target]):not([href^=\\#]):not([data-taxi-ignore])":n,i=t.removeOldContent,o=void 0===i||i,a=t.renderers,c=t.transitions,h=void 0===c?{default:f}:c,u=t.reloadJsFilter,d=void 0===u?function(t){return void 0!==t.dataset.taxiReload}:u;this.renderers=void 0===a?{default:l}:a,this.transitions=h,this.defaultRenderer=this.renderers.default||l,this.defaultTransition=this.transitions.default||f,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=d,this.removeOldContent=o,this.cache=new Map,this.attachEvents(r),this.currentLocation=s(window.location.href),this.cache.set(this.currentLocation.href,this.createCacheEntry(document.cloneNode(!0))),this.currentCacheEntry=this.cache.get(this.currentLocation.href),this.currentCacheEntry.renderer.initialLoad()}var e=t.prototype;return e.setDefaultRenderer=function(t){this.defaultRenderer=this.renderers[t]},e.setDefaultTransition=function(t){this.defaultTransition=this.transitions[t]},e.addRoute=function(t,e,n){this.router||(this.router=new d),this.router.add(t,e,n)},e.preload=function(t){var e=this;return t=s(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t).then(function(n){try{return e.cache.set(t,e.createCacheEntry(n)),Promise.resolve()}catch(t){return Promise.reject(t)}})},e.updateCache=function(){var t=s(window.location.href).href;this.cache.has(t)&&(this.cache.delete(t),this.cache.set(t,this.createCacheEntry(document.cloneNode(!0))))},e.clearCache=function(t){var e=s(t||window.location.href).href;this.cache.has(e)&&this.cache.delete(e)},e.navigateTo=function(t,e,n){var r=this;return void 0===e&&(e=!1),void 0===n&&(n=!1),new Promise(function(i,o){if(r.isTransitioning)o(new Error("A transition is currently in progress"));else{r.targetLocation=s(t);var a=new(r.chooseTransition(e))({wrapper:r.wrapper});r.beforeFetch(r.targetLocation,a,n).then(function(){try{return r.cache.has(r.targetLocation.href)?Promise.resolve(r.afterFetch(r.targetLocation,a,r.cache.get(r.targetLocation.href),n)):Promise.resolve(r.fetch(r.targetLocation.raw).then(function(t){try{return Promise.resolve(r.afterFetch(r.targetLocation,a,r.createCacheEntry(t),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}}).then(function(){i()})}})},e.on=function(t,e){r.default.on(t,e)},e.off=function(t,e){r.default.off(t,e)},e.beforeFetch=function(t,e,n){var i=this;return this.isTransitioning=!0,r.default.emit("NAVIGATE_OUT",{from:this.currentCacheEntry,trigger:n}),new Promise(function(r){i.currentCacheEntry.renderer.leave(e,n,i.removeOldContent).then(function(){"popstate"!==n&&window.history.pushState({},"",t.raw),r()})})},e.afterFetch=function(t,e,n,i){var o=this;return this.cache.has(t.href)||this.cache.set(t.href,n),this.currentLocation=t,new Promise(function(t){n.renderer.update(),r.default.emit("NAVIGATE_IN",{from:o.currentCacheEntry,to:n,trigger:i}),o.reloadJsFilter&&o.loadScripts(n.scripts),n.renderer.enter(e,i).then(function(){r.default.emit("NAVIGATE_END",{from:o.currentCacheEntry,to:n,trigger:i}),o.currentCacheEntry=n,o.isTransitioning=!1,t()})})},e.loadScripts=function(t){for(var e,n=[].concat(t),r=[].concat(document.querySelectorAll("script")).filter(this.reloadJsFilter),i=0;i<r.length;i++)for(var o=0;o<n.length;o++)if(r[i].outerHTML===n[o].outerHTML){(e=r[i]).parentNode.replaceChild(u(e),e),n.splice(o,1);break}for(var c,s=a(n);!(c=s()).done;)h(c.value)},e.attachEvents=function(t){r.default.delegate("click",t,this.onClick),r.default.on("popstate",window,this.onPopstate)},e.fetch=function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}(function(t){return new Promise(function(e){fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(function(e){return e.ok||(console.warn("Taxi encountered a non 2xx HTTP status code"),window.location.href=t),e.text()}).then(function(t){var n;e("string"==typeof(n=t)?c.parseFromString(n,"text/html"):n)}).catch(function(e){console.warn(e),window.location.href=t})})}),e.chooseTransition=function(t){var e;if(t)return this.transitions[t];var n=null==(e=this.router)?void 0:e.findMatch(this.currentLocation,this.targetLocation);return n?this.transitions[n]:this.defaultTransition},e.createCacheEntry=function(t){var e=t.querySelector("[data-taxi-view]"),n=e.dataset.taxiView.length?this.renderers[e.dataset.taxiView]:this.defaultRenderer;return{page:t,content:e,scripts:this.reloadJsFilter?[].concat(t.querySelectorAll("script")).filter(this.reloadJsFilter):[],title:t.title,renderer:new n({wrapper:this.wrapper,title:t.title,content:e,page:t})}},t}();t.Core=p,t.Renderer=l,t.Transition=f}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@unseenco/e")):"function"==typeof define&&define.amd?define(["exports","@unseenco/e"],e):e((t||self).taxi={},t.E)}(this,function(t,e){function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=/*#__PURE__*/n(e);function i(){return i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},i.apply(this,arguments)}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function a(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return o(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var c=new DOMParser;function s(t){var e=new URL(t,window.location.origin),n=null;return e.hash.length&&(n=t.replace(e.hash,"")),{hasHash:e.hash.length>0,pathname:e.pathname,host:e.host,raw:t,href:n||e.href}}function h(t){"HEAD"===t.parentNode.tagName?document.head.appendChild(u(t)):document.body.appendChild(u(t))}function u(t){for(var e=document.createElement("SCRIPT"),n=0;n<t.attributes.length;n++){var r=t.attributes[n];e.setAttribute(r.nodeName,r.nodeValue)}return t.innerHTML&&(e.innerHTML=t.innerHTML),e}var f=/*#__PURE__*/function(){function t(t){this.wrapper=t.wrapper}var e=t.prototype;return e.leave=function(t){var e=this;return new Promise(function(n){e.onLeave(i({},t,{done:n}))})},e.enter=function(t){var e=this;return new Promise(function(n){e.onEnter(i({},t,{done:n}))})},e.onLeave=function(t){(0,t.done)()},e.onEnter=function(t){(0,t.done)()},t}(),l=/*#__PURE__*/function(){function t(t){var e=t.page,n=t.title,r=t.wrapper;this._contentString=t.content.outerHTML,this.page=e,this.title=n,this.wrapper=r,this.content=this.wrapper.lastElementChild}var e=t.prototype;return e.onEnter=function(){},e.onEnterCompleted=function(){},e.onLeave=function(){},e.onLeaveCompleted=function(){},e.initialLoad=function(){this.onEnter(),this.onEnterCompleted()},e.update=function(){document.title=this.title,this.wrapper.insertAdjacentHTML("beforeend",this._contentString),this.content=this.wrapper.lastElementChild},e.remove=function(){this.wrapper.firstElementChild.remove()},e.enter=function(t,e){var n=this;return new Promise(function(r){n.onEnter(),t.enter({trigger:e,to:n.content}).then(function(){n.onEnterCompleted(),r()})})},e.leave=function(t,e,n){var r=this;return new Promise(function(i){r.onLeave(),t.leave({trigger:e,from:r.content}).then(function(){n&&r.remove(),r.onLeaveCompleted(),i()})})},t}(),d=/*#__PURE__*/function(){function t(){this.data=new Map,this.regexCache=new Map}var e=t.prototype;return e.add=function(t,e,n){this.data.has(t)||(this.data.set(t,new Map),this.regexCache.set(t,new RegExp("^"+t+"$"))),this.data.get(t).set(e,n),this.regexCache.set(e,new RegExp("^"+e+"$"))},e.findMatch=function(t,e){for(var n,r=a(this.data);!(n=r()).done;){var i=n.value,o=i[1];if(t.pathname.match(this.regexCache.get(i[0]))){for(var c,s=a(o);!(c=s()).done;){var h=c.value,u=h[1];if(e.pathname.match(this.regexCache.get(h[0])))return u}break}}return null},t}(),p=/*#__PURE__*/function(){function t(t){var e=this;void 0===t&&(t={}),this.isTransitioning=!1,this.currentCacheEntry=null,this.cache=new Map,this.onClick=function(t){if(!t.metaKey&&!t.ctrlKey){var n=s(t.currentTarget.href);if(e.currentLocation=s(window.location.href),e.currentLocation.host!==n.host)return;if(e.currentLocation.href!==n.href||e.currentLocation.hasHash&&!n.hasHash)return t.preventDefault(),void e.navigateTo(n.raw,t.currentTarget.dataset.transition||!1,t.currentTarget);e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return window.location.pathname!==e.currentLocation.pathname&&(!e.allowInterruption&&e.isTransitioning?(window.history.pushState({},"",e.currentLocation.href),!1):void e.navigateTo(window.location.href,!1,"popstate"))};var n=t.links,r=void 0===n?"a:not([target]):not([href^=\\#]):not([data-taxi-ignore])":n,i=t.removeOldContent,o=void 0===i||i,a=t.allowInterruption,c=void 0!==a&&a,h=t.renderers,u=t.transitions,d=void 0===u?{default:f}:u,p=t.reloadJsFilter,v=void 0===p?function(t){return void 0!==t.dataset.taxiReload}:p;this.renderers=void 0===h?{default:l}:h,this.transitions=d,this.defaultRenderer=this.renderers.default||l,this.defaultTransition=this.transitions.default||f,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=v,this.removeOldContent=o,this.allowInterruption=c,this.cache=new Map,this.attachEvents(r),this.currentLocation=s(window.location.href),this.cache.set(this.currentLocation.href,this.createCacheEntry(document.cloneNode(!0))),this.currentCacheEntry=this.cache.get(this.currentLocation.href),this.currentCacheEntry.renderer.initialLoad()}var e=t.prototype;return e.setDefaultRenderer=function(t){this.defaultRenderer=this.renderers[t]},e.setDefaultTransition=function(t){this.defaultTransition=this.transitions[t]},e.addRoute=function(t,e,n){this.router||(this.router=new d),this.router.add(t,e,n)},e.preload=function(t){var e=this;return t=s(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t).then(function(n){try{return e.cache.set(t,e.createCacheEntry(n)),Promise.resolve()}catch(t){return Promise.reject(t)}})},e.updateCache=function(){var t=s(window.location.href).href;this.cache.has(t)&&(this.cache.delete(t),this.cache.set(t,this.createCacheEntry(document.cloneNode(!0))))},e.clearCache=function(t){var e=s(t||window.location.href).href;this.cache.has(e)&&this.cache.delete(e)},e.navigateTo=function(t,e,n){var r=this;return void 0===e&&(e=!1),void 0===n&&(n=!1),new Promise(function(i,o){if(r.allowInterruption||!r.isTransitioning){r.targetLocation=s(t);var a=new(r.chooseTransition(e))({wrapper:r.wrapper});r.beforeFetch(r.targetLocation,a,n).then(function(){try{return r.cache.has(r.targetLocation.href)?Promise.resolve(r.afterFetch(r.targetLocation,a,r.cache.get(r.targetLocation.href),n)):Promise.resolve(r.fetch(r.targetLocation.raw).then(function(t){try{return Promise.resolve(r.afterFetch(r.targetLocation,a,r.createCacheEntry(t),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}}).then(function(){i()})}else o(new Error("A transition is currently in progress"))})},e.on=function(t,e){r.default.on(t,e)},e.off=function(t,e){r.default.off(t,e)},e.beforeFetch=function(t,e,n){var i=this;return this.isTransitioning=!0,r.default.emit("NAVIGATE_OUT",{from:this.currentCacheEntry,trigger:n}),new Promise(function(r){i.currentCacheEntry.renderer.leave(e,n,i.removeOldContent).then(function(){"popstate"!==n&&window.history.pushState({},"",t.raw),r()})})},e.afterFetch=function(t,e,n,i){var o=this;return this.cache.has(t.href)||this.cache.set(t.href,n),this.currentLocation=t,new Promise(function(t){n.renderer.update(),r.default.emit("NAVIGATE_IN",{from:o.currentCacheEntry,to:n,trigger:i}),o.reloadJsFilter&&o.loadScripts(n.scripts),n.renderer.enter(e,i).then(function(){r.default.emit("NAVIGATE_END",{from:o.currentCacheEntry,to:n,trigger:i}),o.currentCacheEntry=n,o.isTransitioning=!1,t()})})},e.loadScripts=function(t){for(var e,n=[].concat(t),r=[].concat(document.querySelectorAll("script")).filter(this.reloadJsFilter),i=0;i<r.length;i++)for(var o=0;o<n.length;o++)if(r[i].outerHTML===n[o].outerHTML){(e=r[i]).parentNode.replaceChild(u(e),e),n.splice(o,1);break}for(var c,s=a(n);!(c=s()).done;)h(c.value)},e.attachEvents=function(t){r.default.delegate("click",t,this.onClick),r.default.on("popstate",window,this.onPopstate)},e.fetch=function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}(function(t){return new Promise(function(e){fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(function(e){return e.ok||(console.warn("Taxi encountered a non 2xx HTTP status code"),window.location.href=t),e.text()}).then(function(t){var n;e("string"==typeof(n=t)?c.parseFromString(n,"text/html"):n)}).catch(function(e){console.warn(e),window.location.href=t})})}),e.chooseTransition=function(t){var e;if(t)return this.transitions[t];var n=null==(e=this.router)?void 0:e.findMatch(this.currentLocation,this.targetLocation);return n?this.transitions[n]:this.defaultTransition},e.createCacheEntry=function(t){var e=t.querySelector("[data-taxi-view]"),n=e.dataset.taxiView.length?this.renderers[e.dataset.taxiView]:this.defaultRenderer;return{page:t,content:e,scripts:this.reloadJsFilter?[].concat(t.querySelectorAll("script")).filter(this.reloadJsFilter):[],title:t.title,renderer:new n({wrapper:this.wrapper,title:t.title,content:e,page:t})}},t}();t.Core=p,t.Renderer=l,t.Transition=f}); | ||
//# sourceMappingURL=taxi.umd.js.map |
{ | ||
"name": "@unseenco/taxi", | ||
"description": "A modern page transition library which supports routing, preloading, and additional script reloading.", | ||
"version": "0.6.0", | ||
"version": "1.0.0", | ||
"license": "GPL-3.0-or-later", | ||
@@ -31,7 +31,19 @@ "source": "src/taxi.js", | ||
"devDependencies": { | ||
"@11ty/eleventy": "^1.0.1", | ||
"@tailwindcss/typography": "^0.5.3", | ||
"browser-sync": "^2.27.7", | ||
"browser-sync-webpack-plugin": "^2.3.0", | ||
"cross-env": "^7.0.3", | ||
"gsap": "^3.10.2", | ||
"html-minifier": "^4.0.0", | ||
"laravel-mix": "^6.0.41", | ||
"markdown-it-anchor": "^8.6.4", | ||
"microbundle": "^0.14.2", | ||
"mix-tailwindcss": "^1.3.0", | ||
"npm-run-all": "^4.1.5", | ||
"prismjs": "^1.28.0", | ||
"resolve-url-loader": "^5.0.0", | ||
"sass": "^1.53.0", | ||
"sass-loader": "^12.1.0", | ||
"tailwindcss": "^3.1.5", | ||
"typescript": "^4.5.5" | ||
@@ -41,5 +53,10 @@ }, | ||
"build": "microbundle", | ||
"start": "npx mix watch", | ||
"ts": "tsc" | ||
"ts": "tsc", | ||
"start": "npm-run-all -p dev:*", | ||
"dev:eleventy": "eleventy --serve --quiet", | ||
"dev:mix": "mix watch", | ||
"docs": "npm-run-all -p docs:*", | ||
"docs:eleventy": "cross-env ENVIRONMENT=prod eleventy", | ||
"docs:mix": "mix --production" | ||
} | ||
} |
379
README.md
@@ -0,5 +1,8 @@ | ||
<p align="center"> | ||
<img width="380" src="https://user-images.githubusercontent.com/3481634/181377879-5f972dd8-ea10-4f5b-be44-5a23edfd3d5a.svg"> | ||
</p> | ||
<p align="center"><strong>Taxi.js is the spiritual successor to Highway.js.</strong></p> | ||
<p align="center">Full docs on the way!</p> | ||
<p align="center"><a href="https://taxi.js.org" target="_blank">Full Documentation</a></p> | ||
@@ -10,6 +13,4 @@ <p align="center"> | ||
---- | ||
![taxi-stripe](https://user-images.githubusercontent.com/3481634/164978156-352c3bf7-6dd1-4f45-9cee-039665cc3def.png) | ||
Taxi is a js library for adding AJAX navigation and beautiful transitions to your website. | ||
@@ -24,7 +25,6 @@ | ||
* Ability to preload URLs | ||
* Opt-in ability to stop navigation during an active transition | ||
* Blocks navigation during an active transition (can be opted out) | ||
* Auto runs javascript on the new page | ||
* Previous page's content is automatically removed (you can opt out of this if you like) | ||
* Click events on links can be intercepted via `stopPropagation` without hacks | ||
* No annoying messages in the console... | ||
@@ -41,367 +41,4 @@ | ||
---- | ||
![taxi-stripe-small](https://user-images.githubusercontent.com/3481634/164978141-8ec3aade-5a56-4986-93f7-05c971aeb940.png) | ||
# Table of Contents | ||
* [How to Use](#how-to-use) | ||
* [Parameters](#parameters) | ||
* [Navigation Lifecycle](#navigation-lifecycle) | ||
* [Renderers](#renderers) | ||
* [Running code on the initial visit to your site](#running-code-on-the-initial-visit-to-your-site) | ||
* [Transitions](#transitions) | ||
* [How transitions are chosen](#how-transitions-are-chosen) | ||
* [Routing](#routing) | ||
* [Running JS on New Pages](#running-js-on-new-pages) | ||
* [API](#api) | ||
* [Events](#events) | ||
![taxi-stripe-small](https://user-images.githubusercontent.com/3481634/164978141-8ec3aade-5a56-4986-93f7-05c971aeb940.png) | ||
# How to Use | ||
Simply import `Taxi.Core` into your code and create a new instance: | ||
```js | ||
import { Core } from '@unseenco/taxi' | ||
const Taxi = new Core({ ... }) | ||
``` | ||
Then amend your HTML so that `data-taxi` is added to the parent of the content you want to replace during a transition, and `data-taxi-view` is added to the element you are replacing. | ||
The `data-taxi-view` element **has to be the only child** of `data-taxi`. | ||
```html | ||
<main data-taxi> | ||
<article data-taxi-view> | ||
... | ||
</article> | ||
</main> | ||
``` | ||
Now when you navigate in your app, `data-taxi-view` will be replaced with the `data-taxi-view` from the target URL instead of the whole page loading 🥳 | ||
### Parameters | ||
When creating a new Taxi instance, you can pass an object of parameters into the constructor: | ||
| Param | Type | Default | Description | | ||
|---|---|---|---| | ||
| links | `string` | `'a:not([target]):not([href^= \\ #]):not([data-taxi-ignore])'` | Which links should Taxi intercept. | | ||
| removeOldContent | `boolean` | `true` | Taxi will remove the previous page's content after the Transition's `onLeave` method has finished. Set this to false to disable this behaviour. | | ||
| renderers | `Object.<string, Renderer>` | `{ default: Taxi.Renderer }` | All Renderers for the project. | | ||
| transitions | `Object.<string, Transition>` | `{ default: Taxi.Transition }` | All Transitions for the project. | | ||
| reloadJsFilter | `bool\|function(element: HTMLElement)` | `function` | See [running JS on new pages](#running-js-on-new-pages) for details. | | ||
![taxi-stripe-small](https://user-images.githubusercontent.com/3481634/164978141-8ec3aade-5a56-4986-93f7-05c971aeb940.png) | ||
# Navigation Lifecycle | ||
Now that we have explained Renderers and Transitions, how does it all fit together? Hopefully the below diagram should help! | ||
```mermaid | ||
graph TB | ||
subgraph Entering | ||
E(New Renderer enter) --> F(Transition enter) --> G(New Renderer enterCompleted) | ||
end | ||
D[fetch and swap content] | ||
subgraph Leaving | ||
A(Current Renderer leave)-->B(Transition leave)-->C(Current Renderer leaveCompleted) | ||
end | ||
``` | ||
Let's use a **real world example**. | ||
1. A user clicks a link in your app | ||
2. Taxi [checks to see which Transition](#transitions-and-routing) should be used | ||
3. The current Renderer's `onLeave` method is called | ||
4. Then the chosen Transition's `onLeave` | ||
5. Then the Renderer's `onLeaveCompleted` | ||
6. Next, Taxi will go and fetch the new page the user has requested, and swap the current page's content to this new content as soon as it's ready | ||
7. Taxi will look at the new page content and call the `onEnter` method of the Renderer set via the new page's `data-taxi-view` attribute, or the default if not defined | ||
8. Then call the Transition's `onEnter` method | ||
9. Finally when the transition is all finished, the new Renderer's `onEnterComplete` is called | ||
![taxi-stripe-small](https://user-images.githubusercontent.com/3481634/164978141-8ec3aade-5a56-4986-93f7-05c971aeb940.png) | ||
# Renderers | ||
A Renderer is run everytime a page is shown or hidden when using Taxi. They are an ideal place to init/destroy components on the page, or play intro animations. | ||
All Renderers should extend `@unseenco/taxi.Renderer` and look something like this: | ||
```js | ||
import { Renderer } from '@unseenco/taxi'; | ||
export default class CustomRenderer extends Renderer { | ||
onEnter() { | ||
// run after the new content has been added to the Taxi container | ||
} | ||
onEnterCompleted() { | ||
// run after the transition.onEnter has fully completed | ||
} | ||
onLeave() { | ||
// run before the transition.onLeave method is called | ||
} | ||
onLeaveCompleted() { | ||
// run after the transition.onleave has fully completed | ||
} | ||
} | ||
``` | ||
The following props are available within Renderer methods: | ||
* `this.page` : The entire document that is being rendered | ||
* `this.title` : The document.title of the page being rendered | ||
* `this.wrapper` : A reference to the current `data-taxi` main wrapper | ||
* `this.content` : A reference to the `data-taxi-view` which is being added to the DOM | ||
### Running code on the initial visit to your site | ||
Renderers are called whenever a navigation takes place, but the correct Renderer is also called when a user first visits your site. | ||
There may be things you want to setup at this time such as persistent components like navigation, or smoothscroll for example. | ||
To aid with this, Renderers also have an `initialLoad` method which is only run on a user's first visit. | ||
As no navigation has taken place, Taxi won't fire your Renderer's `onEnter` or `onEnterCompleted` methods, so we suggest running them here is a good idea: | ||
```js | ||
import { Renderer } from '@unseenco/taxi'; | ||
export default class CustomRenderer extends Renderer { | ||
initialLoad() { | ||
// run code that should only happen once for your site | ||
this.onEnter() | ||
this.onEnterCompleted() | ||
} | ||
// rest of your methods | ||
} | ||
``` | ||
![taxi-stripe-small](https://user-images.githubusercontent.com/3481634/164978141-8ec3aade-5a56-4986-93f7-05c971aeb940.png) | ||
# Transitions | ||
Whenever a user navigates on your site, a Transition class is run to provide the fancy animation between the two pages. | ||
A transition consists of an `onLeave` method called when leaving the current page, and an `onEnter` method which is called after the new content has been added to the DOM. | ||
Each method is passed an object containing the `done()` promise resolve function to call when your animation is finished, and the `trigger` that caused the navigation (either `'popstate'` for browser navigation, the `Element` if a link click, or `false` if the navigation was caused programmatically via `navigateTo`. | ||
The methods are also passed a reference to the active `data-taxi-view`: When leaving the current `data-taxi-view` is passed, and when entering the new `data-taxi-view` is passed instead: | ||
```js | ||
import { Transition } from '@unseenco/taxi' | ||
export default class DefaultTransition extends Transition { | ||
/** | ||
* Handle the transition leaving the previous page. | ||
* @param {{from: HTMLElement, trigger: string|HTMLElement|false, done: function}} props | ||
*/ | ||
onLeave({ from, trigger, done }) { | ||
done() | ||
} | ||
/** | ||
* Handle the transition entering the next page. | ||
* @param {{ to: HTMLElement, trigger: string|HTMLElement|false, done: function }} props | ||
*/ | ||
onEnter({ to, trigger, done }) { | ||
done() | ||
} | ||
} | ||
``` | ||
`this.wrapper` is also available, which is a reference to the main `data-taxi` container. | ||
### How transitions are chosen | ||
Taxi has a distinct hierarchy when it comes to choosing which transition to run during a navigation: | ||
```mermaid | ||
graph LR | ||
A(Check data-transition) --> B(Check router for match) --> C(Default Transition) | ||
``` | ||
#### 1. Explicit Transition | ||
If a user clicks a link with `data-transition="something"` present, then the "something" transition will be used. | ||
These are for special cases really, as browser navigation (back/forward buttons) will never trigger this. | ||
#### 2. Route Transition | ||
If there was no explicit transition, then Taxi will next check the [defined routes](#routing) to see if a contextual transition can be matched. | ||
#### 3. Default Transition | ||
As there was no explicit transition, and no matches from the router, finally the default transition will be used. | ||
![taxi-stripe-small](https://user-images.githubusercontent.com/3481634/164978141-8ec3aade-5a56-4986-93f7-05c971aeb940.png) | ||
# Routing | ||
Routes are defined in Taxi as a regex to run against the current URL, and one to run against the new URL after the navigation. | ||
### Route Ordering | ||
Routes are tested in **the same order they are declared**, and as soon as a match is found, that transition is chosen. | ||
Lost? Well consider the following: | ||
```js | ||
// bad | ||
taxi.addRoute('/pages/.*', '/', 'somethingElse') | ||
taxi.addRoute('/pages/specific', '/', 'something') | ||
// good | ||
taxi.addRoute('/pages/specific', '/', 'something') | ||
taxi.addRoute('/pages/.*', '/', 'somethingElse') | ||
``` | ||
In the above example, if the user was navigating from `/pages/specific` to the homepage, only the second example would match and run the "something" transition. | ||
This is because the first example registers the catch-all **before** the specific rule, so the specific one is never reached. | ||
**Please note:** Your regex is wrapped inside `^` and `$` automatically, so a regex of `/api` will match `/api` **but not** `/v2/api`. Keep this in mind when adding routing rules! | ||
![taxi-stripe-small](https://user-images.githubusercontent.com/3481634/164978141-8ec3aade-5a56-4986-93f7-05c971aeb940.png) | ||
## Running JS on New Pages | ||
Taxi allows automatic reload and running of js present on a fetched page during the navigation cycle. This is especially useful when working with traditional CMS's such as WordPress or Magento, or if you wanted to split your js if you have a particularly heavy page. | ||
It will also parse and execute inline js, allowing you to add data to the `window` object for example. | ||
If enabled, this feature will run just after the `NAVIGATE_IN` event, after the new content has been appended to the DOM, but before the `Renderer.onEnter` method is called. | ||
### Choosing which scripts are reloaded | ||
By default, only scripts with the `data-taxi-reload` attribute are reloaded after a navigation. | ||
```html | ||
<!-- reloaded --> | ||
<script src="/foo.js" data-taxi-reload /> | ||
<!-- this is not reloaded --> | ||
<script src="/bar.js" /> | ||
``` | ||
In certain situations, you may not have control over the `<script />` tags directly. Luckily `reloadJsFilter` accepts a callback function to filter scripts on the new page and decide which to load. | ||
Your callback is passed the `script` element, and must return a boolean indicating whether the script should be reloaded or not (you could check the src or id attributes for example). | ||
Here is the default callback for `reloadJsFilter`: | ||
```js | ||
(element) => element.dataset.taxiReload !== undefined | ||
``` | ||
and here is a custom example: | ||
```js | ||
import { Core } from '@unseenco/taxi' | ||
const Taxi = new Core({ | ||
reloadJsFilter: (element) => element.dataset.taxiReload !== undefined || element.src?.match('bar.js') | ||
}) | ||
``` | ||
### Disabling this feature | ||
Just set `reloadJsFilter` to false when initing Taxi: | ||
```js | ||
import { Core } from '@unseenco/taxi' | ||
const Taxi = new Core({ | ||
reloadJsFilter: false | ||
}) | ||
``` | ||
![taxi-stripe-small](https://user-images.githubusercontent.com/3481634/164978141-8ec3aade-5a56-4986-93f7-05c971aeb940.png) | ||
# API | ||
### `addRoute(fromPattern: string, toPattern: string, transition: string): void` | ||
Registers a route into the RouteStore. | ||
### `navigateTo(url: string, transition?: string = false): Promise` | ||
Perform a manual navigation to the provided URL. | ||
If a `transition` name is not provided then Taxi will try and find a match in the RouteStore, otherwise the default transition will be used. | ||
### `preload(url: string): Promise` | ||
prefetch the provided URL and add it to the cache ahead of any user navigation. | ||
### `updateCache(): void` | ||
Updates the HTML cache for the current URL. | ||
Useful when adding/removing content via AJAX such as a search page or infinite loader | ||
### `deleteCache(url?: string): void` | ||
Remove the cached HTML for the provided URL. If no URL provided, remove cache for the current URL. | ||
### `setDefaultRenderer(renderer: string): void` | ||
If you don't like "default" as the name of your default renderer, you can change the default renderer to be anything you like here. | ||
### `setDefaultTransition(renderer: string): void` | ||
Same as `setDefaultRenderer`, but for the transitions instead. | ||
### `on(event: string, callback: function): void` | ||
Add an [event listener](#events). | ||
### `off(event: string, callback?: function)` | ||
Remove an [event listener](#events). If no callback is supplied, then remove all listeners for the provided event. | ||
![taxi-stripe-small](https://user-images.githubusercontent.com/3481634/164978141-8ec3aade-5a56-4986-93f7-05c971aeb940.png) | ||
# Events | ||
Events are handled by [@unseenco/e](https://www.npmjs.com/package/@unseenco/e) and work as they did in Highway.js. | ||
### Adding Listeners | ||
```js | ||
import { Core } from '@unseenco/taxi' | ||
const Taxi = new Core({ ... }) | ||
// This event is sent everytime a `data-taxi-view` is added to the DOM | ||
Taxi.on('NAVIGATE_IN', ({ to, trigger, location }) => { | ||
// ... | ||
}); | ||
// This event is sent before the `onLeave()` method of a transition is run to hide a `data-router-view` | ||
Taxi.on('NAVIGATE_OUT', ({ from, trigger, location }) => { | ||
// ... | ||
}); | ||
// This event is sent everytime the `done()` method is called in the `onEnter()` method of a transition | ||
Taxi.on('NAVIGATE_END', ({ to, from, trigger, location }) => { | ||
// ... | ||
}); | ||
``` | ||
### Removing Listeners | ||
You can call `Taxi.off(event_name)` to remove all listeners for an event, or pass the callback to remove just that listener instead: | ||
```js | ||
function foo() { // ... } | ||
Taxi.on('NAVIGATE_OUT', foo) | ||
// Remove just the foo listener | ||
Taxi.off('NAVIGATE_OUT', foo) | ||
// remove all listeners | ||
Taxi.off('NAVIGATE_IN') | ||
``` | ||
<p align="center"><a href="https://taxi.js.org" target="_blank">Full Documentation</a></p> |
@@ -15,2 +15,3 @@ /** | ||
* removeOldContent?: boolean, | ||
* allowInterruption?: boolean, | ||
* renderers?: Object.<string, Renderer>, | ||
@@ -24,2 +25,3 @@ * transitions?: Object.<string, Transition>, | ||
removeOldContent?: boolean; | ||
allowInterruption?: boolean; | ||
renderers?: { | ||
@@ -57,2 +59,3 @@ [x: string]: Renderer; | ||
removeOldContent: boolean; | ||
allowInterruption: boolean; | ||
currentLocation: { | ||
@@ -59,0 +62,0 @@ raw: string; |
@@ -34,2 +34,3 @@ import E from '@unseenco/e' | ||
* removeOldContent?: boolean, | ||
* allowInterruption?: boolean, | ||
* renderers?: Object.<string, Renderer>, | ||
@@ -44,2 +45,3 @@ * transitions?: Object.<string, Transition>, | ||
removeOldContent = true, | ||
allowInterruption = false, | ||
renderers = { | ||
@@ -61,2 +63,3 @@ default: Renderer | ||
this.removeOldContent = removeOldContent | ||
this.allowInterruption = allowInterruption | ||
this.cache = new Map() | ||
@@ -162,3 +165,3 @@ | ||
// Don't allow multiple navigations to occur at once | ||
if (this.isTransitioning) { | ||
if (!this.allowInterruption && this.isTransitioning) { | ||
reject(new Error('A transition is currently in progress')) | ||
@@ -349,3 +352,3 @@ return | ||
if (this.isTransitioning) { | ||
if (!this.allowInterruption && this.isTransitioning) { | ||
// overwrite history state with current page if currently navigating | ||
@@ -352,0 +355,0 @@ window.history.pushState({}, '', this.currentLocation.href) |
@@ -0,0 +0,0 @@ const parser = new DOMParser() |
@@ -0,0 +0,0 @@ export default class RouteStore { |
@@ -0,0 +0,0 @@ import Core from "./Core" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1087
2
177610
18
42