@unseenco/taxi
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -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.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}; | ||
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="A transition is currently in progress",l=/*#__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).catch(function(t){return console.warn(t)});e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return!(window.location.pathname===e.currentLocation.pathname&&!e.isPopping)&&(e.allowInterruption||!e.isTransitioning&&!e.isPopping?(e.isPopping||(e.popTarget=window.location.href),e.isPopping=!0,void e.navigateTo(window.location.href,!1,"popstate")):(window.history.pushState({},"",e.popTarget),console.warn(f),!1))};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,l=t.renderers,d=t.transitions,p=void 0===d?{default:s}:d,v=t.reloadJsFilter,g=void 0===v?function(t){return void 0!==t.dataset.taxiReload}:v;this.renderers=void 0===l?{default:h}:l,this.transitions=p,this.defaultRenderer=this.renderers.default||h,this.defaultTransition=this.transitions.default||s,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=g,this.removeOldContent=a,this.allowInterruption=u,this.cache=new Map,this.isPopping=!1,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.isTransitioning=!0,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(f))})},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 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,o.isPopping=!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{l 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.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; | ||
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="A transition is currently in progress",d=/*#__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).catch(function(t){return console.warn(t)});e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return!(window.location.pathname===e.currentLocation.pathname&&!e.isPopping)&&(e.allowInterruption||!e.isTransitioning&&!e.isPopping?(e.isPopping||(e.popTarget=window.location.href),e.isPopping=!0,void e.navigateTo(window.location.href,!1,"popstate")):(window.history.pushState({},"",e.popTarget),console.warn(l),!1))};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,d=t.transitions,p=void 0===d?{default:h}:d,v=t.reloadJsFilter,g=void 0===v?function(t){return void 0!==t.dataset.taxiReload}:v;this.renderers=void 0===f?{default:u}:f,this.transitions=p,this.defaultRenderer=this.renderers.default||u,this.defaultTransition=this.transitions.default||h,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=g,this.removeOldContent=o,this.allowInterruption=s,this.cache=new Map,this.isPopping=!1,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.isTransitioning=!0,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(l))})},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 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,o.isPopping=!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=d,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.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}; | ||
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}}const c="A transition is currently in progress";class l{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).catch(t=>console.warn(t));this.currentLocation.hasHash||e.hasHash||t.preventDefault()}},this.onPopstate=()=>!(window.location.pathname===this.currentLocation.pathname&&!this.isPopping)&&(this.allowInterruption||!this.isTransitioning&&!this.isPopping?(this.isPopping||(this.popTarget=window.location.href),this.isPopping=!0,void this.navigateTo(window.location.href,!1,"popstate")):(window.history.pushState({},"",this.popTarget),console.warn(c),!1));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:l=(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=l,this.removeOldContent=n,this.allowInterruption=i,this.cache=new Map,this.isPopping=!1,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(c));this.isTransitioning=!0,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 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,this.isPopping=!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{l 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.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}); | ||
!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="A transition is currently in progress",v=/*#__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).catch(function(t){return console.warn(t)});e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return!(window.location.pathname===e.currentLocation.pathname&&!e.isPopping)&&(e.allowInterruption||!e.isTransitioning&&!e.isPopping?(e.isPopping||(e.popTarget=window.location.href),e.isPopping=!0,void e.navigateTo(window.location.href,!1,"popstate")):(window.history.pushState({},"",e.popTarget),console.warn(p),!1))};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,v=t.reloadJsFilter,g=void 0===v?function(t){return void 0!==t.dataset.taxiReload}:v;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=g,this.removeOldContent=o,this.allowInterruption=c,this.cache=new Map,this.isPopping=!1,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.isTransitioning=!0,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(p))})},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 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,o.isPopping=!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=v,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": "1.0.0", | ||
"version": "1.0.1", | ||
"license": "GPL-3.0-or-later", | ||
@@ -33,2 +33,3 @@ "source": "src/taxi.js", | ||
"@tailwindcss/typography": "^0.5.3", | ||
"babel-plugin-prismjs": "^2.1.0", | ||
"browser-sync": "^2.27.7", | ||
@@ -35,0 +36,0 @@ "browser-sync-webpack-plugin": "^2.3.0", |
@@ -11,2 +11,4 @@ <p align="center"> | ||
<code>npm i @unseenco/taxi</code> or <code>yarn add @unseenco/taxi</code> | ||
<br><br> | ||
<a href="https://www.npmjs.com/package/@unseenco/taxi" target="_blank"><img src="https://img.shields.io/npm/v/@unseenco/taxi?color=F4BA00&style=flat-square"></a> | ||
</p> | ||
@@ -34,3 +36,3 @@ | ||
* New methods and functionality | ||
* `data-taxi` and `data-taxi-view` are to be used instead of `data-router-wrapper` and `data-router-view` respectively. | ||
* `data-taxi`, `data-taxi-view`, `data-taxi-ignore` are to be used instead of `data-router-wrapper`, `data-router-view`, `data-router-disabled` respectively. | ||
* `attach` and `detach` are no longer methods - link clicks are listened to via delegation so these are no longer needed. | ||
@@ -40,2 +42,3 @@ * `redirect` is now `navigateTo` as "redirect" felt weird as a method name! | ||
* The params passed to renderers, transitions, and events are now a little different | ||
* Old content is automatically removed during a transition - so no need to manually call `from.remove()` in your transitions. | ||
@@ -42,0 +45,0 @@ ---- |
@@ -58,2 +58,3 @@ /** | ||
allowInterruption: boolean; | ||
isPopping: boolean; | ||
currentLocation: { | ||
@@ -163,5 +164,6 @@ raw: string; | ||
* @private | ||
* @return {boolean} | ||
* @return {void|boolean} | ||
*/ | ||
private onPopstate; | ||
popTarget: string; | ||
/** | ||
@@ -168,0 +170,0 @@ * @private |
@@ -7,2 +7,4 @@ import E from '@unseenco/e' | ||
const IN_PROGRESS = 'A transition is currently in progress' | ||
/** | ||
@@ -64,2 +66,3 @@ * @typedef CacheEntry | ||
this.cache = new Map() | ||
this.isPopping = false | ||
@@ -165,6 +168,8 @@ // Add delegated link events | ||
if (!this.allowInterruption && this.isTransitioning) { | ||
reject(new Error('A transition is currently in progress')) | ||
reject(new Error(IN_PROGRESS)) | ||
return | ||
} | ||
this.isTransitioning = true | ||
this.targetLocation = processUrl(url) | ||
@@ -216,4 +221,2 @@ | ||
beforeFetch(url, TransitionClass, trigger) { | ||
this.isTransitioning = true | ||
E.emit('NAVIGATE_OUT', { | ||
@@ -275,2 +278,3 @@ from: this.currentCacheEntry, | ||
this.isTransitioning = false | ||
this.isPopping = false | ||
resolve() | ||
@@ -332,3 +336,3 @@ }) | ||
// noinspection JSIgnoredPromiseFromCall | ||
this.navigateTo(target.raw, e.currentTarget.dataset.transition || false, e.currentTarget) | ||
this.navigateTo(target.raw, e.currentTarget.dataset.transition || false, e.currentTarget).catch(err => console.warn(err)) | ||
return | ||
@@ -346,16 +350,23 @@ } | ||
* @private | ||
* @return {boolean} | ||
* @return {void|boolean} | ||
*/ | ||
onPopstate = () => { | ||
// don't trigger for on-page anchors | ||
if (window.location.pathname === this.currentLocation.pathname) { | ||
if (window.location.pathname === this.currentLocation.pathname && !this.isPopping) { | ||
return false | ||
} | ||
if (!this.allowInterruption && this.isTransitioning) { | ||
if (!this.allowInterruption && (this.isTransitioning || this.isPopping)) { | ||
// overwrite history state with current page if currently navigating | ||
window.history.pushState({}, '', this.currentLocation.href) | ||
window.history.pushState({}, '', this.popTarget) | ||
console.warn(IN_PROGRESS) | ||
return false | ||
} | ||
if (!this.isPopping) { | ||
this.popTarget = window.location.href | ||
} | ||
this.isPopping = true | ||
// noinspection JSIgnoredPromiseFromCall | ||
@@ -362,0 +373,0 @@ this.navigateTo(window.location.href, false, 'popstate') |
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
182332
1100
45
19