@unseenco/taxi
Advanced tools
Comparing version 1.1.0 to 1.2.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 r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},e.apply(this,arguments)}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function n(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 i=new DOMParser;function o(t){var e=new URL(t,window.location.origin),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 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"),r=0;r<t.attributes.length;r++){var n=t.attributes[r];e.setAttribute(n.nodeName,n.nodeValue)}return t.innerHTML&&(e.innerHTML=t.innerHTML),e}var h=/*#__PURE__*/function(){function t(t){this.wrapper=t.wrapper}var r=t.prototype;return r.leave=function(t){var r=this;return new Promise(function(n){r.onLeave(e({},t,{done:n}))})},r.enter=function(t){var r=this;return new Promise(function(n){r.onEnter(e({},t,{done:n}))})},r.onLeave=function(t){(0,t.done)()},r.onEnter=function(t){(0,t.done)()},t}(),s=/*#__PURE__*/function(){function t(t){var e=t.page,r=t.title,n=t.wrapper;this._contentString=t.content.outerHTML,this._DOM=null,this.page=e,this.title=r,this.wrapper=n,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.appendChild(this._DOM.firstElementChild),this.content=this.wrapper.lastElementChild,this._DOM=null},e.createDom=function(){this._DOM||(this._DOM=document.createElement("div"),this._DOM.innerHTML=this._contentString)},e.remove=function(){this.wrapper.firstElementChild.remove()},e.enter=function(t,e){var r=this;return new Promise(function(n){r.onEnter(),t.enter({trigger:e,to:r.content}).then(function(){r.onEnterCompleted(),n()})})},e.leave=function(t,e,r){var n=this;return new Promise(function(i){n.onLeave(),t.leave({trigger:e,from:n.content}).then(function(){r&&n.remove(),n.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,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+"$"))},e.findMatch=function(t,e){for(var r,i=n(this.data);!(r=i()).done;){var o=r.value,a=o[1];if(t.pathname.match(this.regexCache.get(o[0]))){for(var c,h=n(a);!(c=h()).done;){var s=c.value,u=s[1];if(e.pathname.match(this.regexCache.get(s[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 r=o(t.currentTarget.href);if(e.currentLocation=o(window.location.href),e.currentLocation.host!==r.host)return;if(e.currentLocation.href!==r.href||e.currentLocation.hasHash&&!r.hasHash)return t.preventDefault(),void e.navigateTo(r.raw,t.currentTarget.dataset.transition||!1,t.currentTarget).catch(function(t){return console.warn(t)});e.currentLocation.hasHash||r.hasHash||t.preventDefault()}},this.onPreload=function(t){var r=o(t.currentTarget.href);e.currentLocation.host===r.host&&e.preload(t.currentTarget.href)},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 r=t.links,n=void 0===r?"a:not([target]):not([href^=\\#]):not([data-taxi-ignore])":r,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:h}:d,g=t.reloadJsFilter,v=void 0===g?function(t){return void 0!==t.dataset.taxiReload}:g;this.renderers=void 0===l?{default:s}:l,this.transitions=p,this.defaultRenderer=this.renderers.default||s,this.defaultTransition=this.transitions.default||h,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=v,this.removeOldContent=a,this.allowInterruption=u,this.cache=new Map,this.isPopping=!1,this.attachEvents(n),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 r=e.prototype;return r.setDefaultRenderer=function(t){this.defaultRenderer=this.renderers[t]},r.setDefaultTransition=function(t){this.defaultTransition=this.transitions[t]},r.addRoute=function(t,e,r){this.router||(this.router=new u),this.router.add(t,e,r)},r.preload=function(t,e){var r=this;return void 0===e&&(e=!1),t=o(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t,!1).then(function(n){try{return r.cache.set(t,r.createCacheEntry(n)),e&&r.cache.get(t).renderer.createDom(),Promise.resolve()}catch(t){return Promise.reject(t)}})},r.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))))},r.clearCache=function(t){var e=o(t||window.location.href).href;this.cache.has(e)&&this.cache.delete(e)},r.navigateTo=function(t,e,r){var n=this;return void 0===e&&(e=!1),void 0===r&&(r=!1),new Promise(function(i,a){if(n.allowInterruption||!n.isTransitioning){n.isTransitioning=!0,n.isPopping=!0,n.targetLocation=o(t),n.popTarget=window.location.href;var c,h=new(n.chooseTransition(e))({wrapper:n.wrapper});if(n.cache.has(n.targetLocation.href))n.cache.get(n.targetLocation.href).renderer.createDom(),c=n.beforeFetch(n.targetLocation,h,r).then(function(){try{return Promise.resolve(n.afterFetch(n.targetLocation,h,n.cache.get(n.targetLocation.href),r))}catch(t){return Promise.reject(t)}});else{var s=n.fetch(n.targetLocation.raw).then(function(t){n.cache.set(n.targetLocation.href,n.createCacheEntry(t)),n.cache.get(n.targetLocation.href).renderer.createDom()});c=n.beforeFetch(n.targetLocation,h,r).then(function(){try{return Promise.resolve(s.then(function(t){try{return Promise.resolve(n.afterFetch(n.targetLocation,h,n.cache.get(n.targetLocation.href),r))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}})}c.then(function(){i()})}else a(new Error(f))})},r.on=function(e,r){t.on(e,r)},r.off=function(e,r){t.off(e,r)},r.beforeFetch=function(e,r,n){var i=this;return t.emit("NAVIGATE_OUT",{from:this.currentCacheEntry,trigger:n}),new Promise(function(t){i.currentCacheEntry.renderer.leave(r,n,i.removeOldContent).then(function(){"popstate"!==n&&window.history.pushState({},"",e.raw),t()})})},r.afterFetch=function(e,r,n,i){var o=this;return this.cache.has(e.href)||this.cache.set(e.href,n),this.currentLocation=e,this.popTarget=this.currentLocation.href,new Promise(function(e){n.renderer.update(),t.emit("NAVIGATE_IN",{from:o.currentCacheEntry,to:n,trigger:i}),o.reloadJsFilter&&o.loadScripts(n.scripts),n.renderer.enter(r,i).then(function(){t.emit("NAVIGATE_END",{from:o.currentCacheEntry,to:n,trigger:i}),o.currentCacheEntry=n,o.isTransitioning=!1,o.isPopping=!1,e()})})},r.loadScripts=function(t){for(var e,r=[].concat(t),i=Array.from(document.querySelectorAll("script")).filter(this.reloadJsFilter),o=0;o<i.length;o++)for(var h=0;h<r.length;h++)if(i[o].outerHTML===r[h].outerHTML){(e=i[o]).parentNode.replaceChild(c(e),e),r.splice(h,1);break}for(var s,u=n(r);!(s=u()).done;)a(s.value)},r.attachEvents=function(e){t.delegate("click",e,this.onClick),t.delegate("mouseenter focus",e,this.onPreload),t.on("popstate",window,this.onPopstate)},r.fetch=function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}(function(t,e){return void 0===e&&(e=!0),new Promise(function(r,n){fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(function(r){return r.ok||(n("Taxi encountered a non 2xx HTTP status code"),e&&(window.location.href=t)),r.text()}).then(function(t){var e;r("string"==typeof(e=t)?i.parseFromString(e,"text/html"):e)}).catch(function(r){n(r),e&&(window.location.href=t)})})}),r.chooseTransition=function(t){var e;if(t)return this.transitions[t];var r=null==(e=this.router)?void 0:e.findMatch(this.currentLocation,this.targetLocation);return r?this.transitions[r]:this.defaultTransition},r.createCacheEntry=function(t){var 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?Array.from(t.querySelectorAll("script")).filter(this.reloadJsFilter):[],title:t.title,renderer:new r({wrapper:this.wrapper,title:t.title,content:e,page:t})}},e}();export{l as Core,s as Renderer,h 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._DOM=null,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.appendChild(this._DOM.firstElementChild),this.content=this.wrapper.lastElementChild,this._DOM=null},e.createDom=function(){this._DOM||(this._DOM=document.createElement("div"),this._DOM.innerHTML=this._contentString)},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.bypassCache,d=void 0!==l&&l,p=t.renderers,g=t.transitions,v=void 0===g?{default:s}:g,m=t.reloadJsFilter,w=void 0===m?function(t){return void 0!==t.dataset.taxiReload}:m;this.renderers=void 0===p?{default:h}:p,this.transitions=v,this.defaultRenderer=this.renderers.default||h,this.defaultTransition=this.transitions.default||s,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=w,this.removeOldContent=a,this.allowInterruption=u,this.bypassCache=d,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,e){var n=this;return void 0===e&&(e=!1),t=o(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t,!1).then(function(r){try{return n.cache.set(t,n.createCacheEntry(r)),e&&n.cache.get(t).renderer.createDom(),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.isPopping=!0,r.targetLocation=o(t),r.popTarget=window.location.href;var c,s=new(r.chooseTransition(e))({wrapper:r.wrapper});if(r.bypassCache||!r.cache.has(r.targetLocation.href)||r.cache.get(r.targetLocation.href).skipCache){var h=r.fetch(r.targetLocation.raw).then(function(t){r.cache.set(r.targetLocation.href,r.createCacheEntry(t)),r.cache.get(r.targetLocation.href).renderer.createDom()});c=r.beforeFetch(r.targetLocation,s,n).then(function(){try{return Promise.resolve(h.then(function(t){try{return Promise.resolve(r.afterFetch(r.targetLocation,s,r.cache.get(r.targetLocation.href),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}})}else r.cache.get(r.targetLocation.href).renderer.createDom(),c=r.beforeFetch(r.targetLocation,s,n).then(function(){try{return Promise.resolve(r.afterFetch(r.targetLocation,s,r.cache.get(r.targetLocation.href),n))}catch(t){return Promise.reject(t)}});c.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.currentLocation=e,this.popTarget=this.currentLocation.href,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=Array.from(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,e){return void 0===e&&(e=!0),new Promise(function(n,r){fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(function(n){return n.ok||(r("Taxi encountered a non 2xx HTTP status code"),e&&(window.location.href=t)),n.text()}).then(function(t){var e;n("string"==typeof(e=t)?i.parseFromString(e,"text/html"):e)}).catch(function(n){r(n),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,skipCache:e.hasAttribute("data-taxi-nocache"),scripts:this.reloadJsFilter?Array.from(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 r(){return r=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},r.apply(this,arguments)}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function i(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 o=new DOMParser;function a(t){var e=new URL(t,window.location.origin),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 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"),r=0;r<t.attributes.length;r++){var n=t.attributes[r];e.setAttribute(n.nodeName,n.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(n){e.onLeave(r({},t,{done:n}))})},e.enter=function(t){var e=this;return new Promise(function(n){e.onEnter(r({},t,{done:n}))})},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,r=t.title,n=t.wrapper;this._contentString=t.content.outerHTML,this._DOM=null,this.page=e,this.title=r,this.wrapper=n,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.appendChild(this._DOM.firstElementChild),this.content=this.wrapper.lastElementChild,this._DOM=null},e.createDom=function(){this._DOM||(this._DOM=document.createElement("div"),this._DOM.innerHTML=this._contentString)},e.remove=function(){this.wrapper.firstElementChild.remove()},e.enter=function(t,e){var r=this;return new Promise(function(n){r.onEnter(),t.enter({trigger:e,to:r.content}).then(function(){r.onEnterCompleted(),n()})})},e.leave=function(t,e,r){var n=this;return new Promise(function(i){n.onLeave(),t.leave({trigger:e,from:n.content}).then(function(){r&&n.remove(),n.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,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+"$"))},e.findMatch=function(t,e){for(var r,n=i(this.data);!(r=n()).done;){var o=r.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 r=a(t.currentTarget.href);if(e.currentLocation=a(window.location.href),e.currentLocation.host!==r.host)return;if(e.currentLocation.href!==r.href||e.currentLocation.hasHash&&!r.hasHash)return t.preventDefault(),void e.navigateTo(r.raw,t.currentTarget.dataset.transition||!1,t.currentTarget).catch(function(t){return console.warn(t)});e.currentLocation.hasHash||r.hasHash||t.preventDefault()}},this.onPreload=function(t){var r=a(t.currentTarget.href);e.currentLocation.host===r.host&&e.preload(t.currentTarget.href)},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 r=t.links,n=void 0===r?"a:not([target]):not([href^=\\#]):not([data-taxi-ignore])":r,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,g=t.reloadJsFilter,v=void 0===g?function(t){return void 0!==t.dataset.taxiReload}:g;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=v,this.removeOldContent=o,this.allowInterruption=s,this.cache=new Map,this.isPopping=!1,this.attachEvents(n),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 r=t.prototype;return r.setDefaultRenderer=function(t){this.defaultRenderer=this.renderers[t]},r.setDefaultTransition=function(t){this.defaultTransition=this.transitions[t]},r.addRoute=function(t,e,r){this.router||(this.router=new f),this.router.add(t,e,r)},r.preload=function(t,e){var r=this;return void 0===e&&(e=!1),t=a(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t,!1).then(function(n){try{return r.cache.set(t,r.createCacheEntry(n)),e&&r.cache.get(t).renderer.createDom(),Promise.resolve()}catch(t){return Promise.reject(t)}})},r.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))))},r.clearCache=function(t){var e=a(t||window.location.href).href;this.cache.has(e)&&this.cache.delete(e)},r.navigateTo=function(t,e,r){var n=this;return void 0===e&&(e=!1),void 0===r&&(r=!1),new Promise(function(i,o){if(n.allowInterruption||!n.isTransitioning){n.isTransitioning=!0,n.isPopping=!0,n.targetLocation=a(t),n.popTarget=window.location.href;var c,s=new(n.chooseTransition(e))({wrapper:n.wrapper});if(n.cache.has(n.targetLocation.href))n.cache.get(n.targetLocation.href).renderer.createDom(),c=n.beforeFetch(n.targetLocation,s,r).then(function(){try{return Promise.resolve(n.afterFetch(n.targetLocation,s,n.cache.get(n.targetLocation.href),r))}catch(t){return Promise.reject(t)}});else{var h=n.fetch(n.targetLocation.raw).then(function(t){n.cache.set(n.targetLocation.href,n.createCacheEntry(t)),n.cache.get(n.targetLocation.href).renderer.createDom()});c=n.beforeFetch(n.targetLocation,s,r).then(function(){try{return Promise.resolve(h.then(function(t){try{return Promise.resolve(n.afterFetch(n.targetLocation,s,n.cache.get(n.targetLocation.href),r))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}})}c.then(function(){i()})}else o(new Error(l))})},r.on=function(t,r){e.default.on(t,r)},r.off=function(t,r){e.default.off(t,r)},r.beforeFetch=function(t,r,n){var i=this;return e.default.emit("NAVIGATE_OUT",{from:this.currentCacheEntry,trigger:n}),new Promise(function(e){i.currentCacheEntry.renderer.leave(r,n,i.removeOldContent).then(function(){"popstate"!==n&&window.history.pushState({},"",t.raw),e()})})},r.afterFetch=function(t,r,n,i){var o=this;return this.cache.has(t.href)||this.cache.set(t.href,n),this.currentLocation=t,this.popTarget=this.currentLocation.href,new Promise(function(t){n.renderer.update(),e.default.emit("NAVIGATE_IN",{from:o.currentCacheEntry,to:n,trigger:i}),o.reloadJsFilter&&o.loadScripts(n.scripts),n.renderer.enter(r,i).then(function(){e.default.emit("NAVIGATE_END",{from:o.currentCacheEntry,to:n,trigger:i}),o.currentCacheEntry=n,o.isTransitioning=!1,o.isPopping=!1,t()})})},r.loadScripts=function(t){for(var e,r=[].concat(t),n=Array.from(document.querySelectorAll("script")).filter(this.reloadJsFilter),o=0;o<n.length;o++)for(var a=0;a<r.length;a++)if(n[o].outerHTML===r[a].outerHTML){(e=n[o]).parentNode.replaceChild(s(e),e),r.splice(a,1);break}for(var h,u=i(r);!(h=u()).done;)c(h.value)},r.attachEvents=function(t){e.default.delegate("click",t,this.onClick),e.default.delegate("mouseenter focus",t,this.onPreload),e.default.on("popstate",window,this.onPopstate)},r.fetch=function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}(function(t,e){return void 0===e&&(e=!0),new Promise(function(r,n){fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(function(r){return r.ok||(n("Taxi encountered a non 2xx HTTP status code"),e&&(window.location.href=t)),r.text()}).then(function(t){var e;r("string"==typeof(e=t)?o.parseFromString(e,"text/html"):e)}).catch(function(r){n(r),e&&(window.location.href=t)})})}),r.chooseTransition=function(t){var e;if(t)return this.transitions[t];var r=null==(e=this.router)?void 0:e.findMatch(this.currentLocation,this.targetLocation);return r?this.transitions[r]:this.defaultTransition},r.createCacheEntry=function(t){var 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?Array.from(t.querySelectorAll("script")).filter(this.reloadJsFilter):[],title:t.title,renderer:new r({wrapper:this.wrapper,title:t.title,content:e,page:t})}},t}();exports.Core=d,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._DOM=null,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.appendChild(this._DOM.firstElementChild),this.content=this.wrapper.lastElementChild,this._DOM=null},e.createDom=function(){this._DOM||(this._DOM=document.createElement("div"),this._DOM.innerHTML=this._contentString)},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.bypassCache,d=void 0!==f&&f,p=t.renderers,v=t.transitions,g=void 0===v?{default:h}:v,m=t.reloadJsFilter,w=void 0===m?function(t){return void 0!==t.dataset.taxiReload}:m;this.renderers=void 0===p?{default:u}:p,this.transitions=g,this.defaultRenderer=this.renderers.default||u,this.defaultTransition=this.transitions.default||h,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=w,this.removeOldContent=o,this.allowInterruption=s,this.bypassCache=d,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,e){var n=this;return void 0===e&&(e=!1),t=a(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t,!1).then(function(r){try{return n.cache.set(t,n.createCacheEntry(r)),e&&n.cache.get(t).renderer.createDom(),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.isPopping=!0,r.targetLocation=a(t),r.popTarget=window.location.href;var c,s=new(r.chooseTransition(e))({wrapper:r.wrapper});if(r.bypassCache||!r.cache.has(r.targetLocation.href)||r.cache.get(r.targetLocation.href).skipCache){var h=r.fetch(r.targetLocation.raw).then(function(t){r.cache.set(r.targetLocation.href,r.createCacheEntry(t)),r.cache.get(r.targetLocation.href).renderer.createDom()});c=r.beforeFetch(r.targetLocation,s,n).then(function(){try{return Promise.resolve(h.then(function(t){try{return Promise.resolve(r.afterFetch(r.targetLocation,s,r.cache.get(r.targetLocation.href),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}})}else r.cache.get(r.targetLocation.href).renderer.createDom(),c=r.beforeFetch(r.targetLocation,s,n).then(function(){try{return Promise.resolve(r.afterFetch(r.targetLocation,s,r.cache.get(r.targetLocation.href),n))}catch(t){return Promise.reject(t)}});c.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.currentLocation=t,this.popTarget=this.currentLocation.href,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=Array.from(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,e){return void 0===e&&(e=!0),new Promise(function(n,r){fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(function(n){return n.ok||(r("Taxi encountered a non 2xx HTTP status code"),e&&(window.location.href=t)),n.text()}).then(function(t){var e;n("string"==typeof(e=t)?o.parseFromString(e,"text/html"):e)}).catch(function(n){r(n),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,skipCache:e.hasAttribute("data-taxi-nocache"),scripts:this.reloadJsFilter?Array.from(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._DOM=null,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.appendChild(this._DOM.firstElementChild),this.content=this.wrapper.lastElementChild,this._DOM=null}createDom(){this._DOM||(this._DOM=document.createElement("div"),this._DOM.innerHTML=this._contentString)}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.onPreload=t=>{const e=r(t.currentTarget.href);this.currentLocation.host===e.host&&this.preload(t.currentTarget.href)},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,e=!1){var n=this;return t=r(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t,!1).then(async function(r){n.cache.set(t,n.createCacheEntry(r)),e&&n.cache.get(t).renderer.createDom()})}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.isPopping=!0,this.targetLocation=r(t),this.popTarget=window.location.href;const s=new(this.chooseTransition(e))({wrapper:this.wrapper});let h;if(this.cache.has(this.targetLocation.href))this.cache.get(this.targetLocation.href).renderer.createDom(),h=this.beforeFetch(this.targetLocation,s,n).then(async function(){return await i.afterFetch(i.targetLocation,s,i.cache.get(i.targetLocation.href),n)});else{const t=this.fetch(this.targetLocation.raw).then(t=>{this.cache.set(this.targetLocation.href,this.createCacheEntry(t)),this.cache.get(this.targetLocation.href).renderer.createDom()});h=this.beforeFetch(this.targetLocation,s,n).then(async function(){return t.then(async function(t){return await i.afterFetch(i.targetLocation,s,i.cache.get(i.targetLocation.href),n)})})}h.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,this.popTarget=this.currentLocation.href,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=Array.from(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.delegate("mouseenter focus",e,this.onPreload),t.on("popstate",window,this.onPopstate)}fetch(t,r=!0){return new Promise((n,i)=>{fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(e=>(e.ok||(i("Taxi encountered a non 2xx HTTP status code"),r&&(window.location.href=t)),e.text())).then(t=>{var r;n("string"==typeof(r=t)?e.parseFromString(r,"text/html"):r)}).catch(e=>{i(e),r&&(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?Array.from(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}; | ||
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._DOM=null,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.appendChild(this._DOM.firstElementChild),this.content=this.wrapper.lastElementChild,this._DOM=null}createDom(){this._DOM||(this._DOM=document.createElement("div"),this._DOM.innerHTML=this._contentString)}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,bypassCache:a=!1,renderers:h={default:s},transitions:l={default:o},reloadJsFilter:d=(t=>void 0!==t.dataset.taxiReload)}=t;this.renderers=h,this.transitions=l,this.defaultRenderer=this.renderers.default||s,this.defaultTransition=this.transitions.default||o,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=d,this.removeOldContent=n,this.allowInterruption=i,this.bypassCache=a,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,e=!1){var n=this;return t=r(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t,!1).then(async function(r){n.cache.set(t,n.createCacheEntry(r)),e&&n.cache.get(t).renderer.createDom()})}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.isPopping=!0,this.targetLocation=r(t),this.popTarget=window.location.href;const s=new(this.chooseTransition(e))({wrapper:this.wrapper});let h;if(this.bypassCache||!this.cache.has(this.targetLocation.href)||this.cache.get(this.targetLocation.href).skipCache){const t=this.fetch(this.targetLocation.raw).then(t=>{this.cache.set(this.targetLocation.href,this.createCacheEntry(t)),this.cache.get(this.targetLocation.href).renderer.createDom()});h=this.beforeFetch(this.targetLocation,s,n).then(async function(){return t.then(async function(t){return await i.afterFetch(i.targetLocation,s,i.cache.get(i.targetLocation.href),n)})})}else this.cache.get(this.targetLocation.href).renderer.createDom(),h=this.beforeFetch(this.targetLocation,s,n).then(async function(){return await i.afterFetch(i.targetLocation,s,i.cache.get(i.targetLocation.href),n)});h.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.currentLocation=e,this.popTarget=this.currentLocation.href,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=Array.from(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,r=!0){return new Promise((n,i)=>{fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(e=>(e.ok||(i("Taxi encountered a non 2xx HTTP status code"),r&&(window.location.href=t)),e.text())).then(t=>{var r;n("string"==typeof(r=t)?e.parseFromString(r,"text/html"):r)}).catch(e=>{i(e),r&&(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,skipCache:e.hasAttribute("data-taxi-nocache"),scripts:this.reloadJsFilter?Array.from(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._DOM=null,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.appendChild(this._DOM.firstElementChild),this.content=this.wrapper.lastElementChild,this._DOM=null},e.createDom=function(){this._DOM||(this._DOM=document.createElement("div"),this._DOM.innerHTML=this._contentString)},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",g=/*#__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.onPreload=function(t){var n=s(t.currentTarget.href);e.currentLocation.host===n.host&&e.preload(t.currentTarget.href)},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,g=t.reloadJsFilter,v=void 0===g?function(t){return void 0!==t.dataset.taxiReload}:g;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.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,e){var n=this;return void 0===e&&(e=!1),t=s(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t,!1).then(function(r){try{return n.cache.set(t,n.createCacheEntry(r)),e&&n.cache.get(t).renderer.createDom(),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.isPopping=!0,r.targetLocation=s(t),r.popTarget=window.location.href;var a,c=new(r.chooseTransition(e))({wrapper:r.wrapper});if(r.cache.has(r.targetLocation.href))r.cache.get(r.targetLocation.href).renderer.createDom(),a=r.beforeFetch(r.targetLocation,c,n).then(function(){try{return Promise.resolve(r.afterFetch(r.targetLocation,c,r.cache.get(r.targetLocation.href),n))}catch(t){return Promise.reject(t)}});else{var h=r.fetch(r.targetLocation.raw).then(function(t){r.cache.set(r.targetLocation.href,r.createCacheEntry(t)),r.cache.get(r.targetLocation.href).renderer.createDom()});a=r.beforeFetch(r.targetLocation,c,n).then(function(){try{return Promise.resolve(h.then(function(t){try{return Promise.resolve(r.afterFetch(r.targetLocation,c,r.cache.get(r.targetLocation.href),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}})}a.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,this.popTarget=this.currentLocation.href,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=Array.from(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.delegate("mouseenter focus",t,this.onPreload),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,e){return void 0===e&&(e=!0),new Promise(function(n,r){fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(function(n){return n.ok||(r("Taxi encountered a non 2xx HTTP status code"),e&&(window.location.href=t)),n.text()}).then(function(t){var e;n("string"==typeof(e=t)?c.parseFromString(e,"text/html"):e)}).catch(function(n){r(n),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?Array.from(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=g,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._DOM=null,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.appendChild(this._DOM.firstElementChild),this.content=this.wrapper.lastElementChild,this._DOM=null},e.createDom=function(){this._DOM||(this._DOM=document.createElement("div"),this._DOM.innerHTML=this._contentString)},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",g=/*#__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.bypassCache,u=void 0!==h&&h,d=t.renderers,g=t.transitions,v=void 0===g?{default:f}:g,m=t.reloadJsFilter,w=void 0===m?function(t){return void 0!==t.dataset.taxiReload}:m;this.renderers=void 0===d?{default:l}:d,this.transitions=v,this.defaultRenderer=this.renderers.default||l,this.defaultTransition=this.transitions.default||f,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=w,this.removeOldContent=o,this.allowInterruption=c,this.bypassCache=u,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,e){var n=this;return void 0===e&&(e=!1),t=s(t).href,this.cache.has(t)?Promise.resolve():this.fetch(t,!1).then(function(r){try{return n.cache.set(t,n.createCacheEntry(r)),e&&n.cache.get(t).renderer.createDom(),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.isPopping=!0,r.targetLocation=s(t),r.popTarget=window.location.href;var a,c=new(r.chooseTransition(e))({wrapper:r.wrapper});if(r.bypassCache||!r.cache.has(r.targetLocation.href)||r.cache.get(r.targetLocation.href).skipCache){var h=r.fetch(r.targetLocation.raw).then(function(t){r.cache.set(r.targetLocation.href,r.createCacheEntry(t)),r.cache.get(r.targetLocation.href).renderer.createDom()});a=r.beforeFetch(r.targetLocation,c,n).then(function(){try{return Promise.resolve(h.then(function(t){try{return Promise.resolve(r.afterFetch(r.targetLocation,c,r.cache.get(r.targetLocation.href),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}})}else r.cache.get(r.targetLocation.href).renderer.createDom(),a=r.beforeFetch(r.targetLocation,c,n).then(function(){try{return Promise.resolve(r.afterFetch(r.targetLocation,c,r.cache.get(r.targetLocation.href),n))}catch(t){return Promise.reject(t)}});a.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.currentLocation=t,this.popTarget=this.currentLocation.href,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=Array.from(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,e){return void 0===e&&(e=!0),new Promise(function(n,r){fetch(t,{mode:"same-origin",method:"GET",headers:{"X-Requested-With":"Taxi"},credentials:"same-origin"}).then(function(n){return n.ok||(r("Taxi encountered a non 2xx HTTP status code"),e&&(window.location.href=t)),n.text()}).then(function(t){var e;n("string"==typeof(e=t)?c.parseFromString(e,"text/html"):e)}).catch(function(n){r(n),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,skipCache:e.hasAttribute("data-taxi-nocache"),scripts:this.reloadJsFilter?Array.from(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=g,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.1.0", | ||
"version": "1.2.0", | ||
"license": "GPL-3.0-or-later", | ||
@@ -6,0 +6,0 @@ "source": "src/taxi.js", |
@@ -7,2 +7,3 @@ /** | ||
* @property {array} scripts | ||
* @property {boolean} skipCache | ||
* @property {string} title | ||
@@ -17,2 +18,3 @@ * @property {HTMLElement|Element} content | ||
* allowInterruption?: boolean, | ||
* bypassCache?: boolean, | ||
* renderers?: Object.<string, Renderer>, | ||
@@ -27,2 +29,3 @@ * transitions?: Object.<string, Transition>, | ||
allowInterruption?: boolean; | ||
bypassCache?: boolean; | ||
renderers?: { | ||
@@ -61,2 +64,3 @@ [x: string]: Renderer; | ||
allowInterruption: boolean; | ||
bypassCache: boolean; | ||
isPopping: boolean; | ||
@@ -167,3 +171,2 @@ currentLocation: { | ||
private onClick; | ||
onPreload: (e: any) => void; | ||
/** | ||
@@ -198,2 +201,3 @@ * @private | ||
scripts: any[]; | ||
skipCache: boolean; | ||
title: string; | ||
@@ -200,0 +204,0 @@ content: HTMLElement | Element; |
@@ -15,2 +15,3 @@ import E from '@unseenco/e' | ||
* @property {array} scripts | ||
* @property {boolean} skipCache | ||
* @property {string} title | ||
@@ -38,2 +39,3 @@ * @property {HTMLElement|Element} content | ||
* allowInterruption?: boolean, | ||
* bypassCache?: boolean, | ||
* renderers?: Object.<string, Renderer>, | ||
@@ -49,2 +51,3 @@ * transitions?: Object.<string, Transition>, | ||
allowInterruption = false, | ||
bypassCache = false, | ||
renderers = { | ||
@@ -67,2 +70,3 @@ default: Renderer | ||
this.allowInterruption = allowInterruption | ||
this.bypassCache = bypassCache | ||
this.cache = new Map() | ||
@@ -188,3 +192,3 @@ this.isPopping = false | ||
if (!this.cache.has(this.targetLocation.href)) { | ||
if (this.bypassCache || !this.cache.has(this.targetLocation.href) || this.cache.get(this.targetLocation.href).skipCache) { | ||
const fetched = this.fetch(this.targetLocation.raw) | ||
@@ -269,7 +273,2 @@ .then((newPage) => { | ||
afterFetch(url, TransitionClass, entry, trigger) { | ||
// add this page to cache | ||
if (!this.cache.has(url.href)) { | ||
this.cache.set(url.href, entry) | ||
} | ||
this.currentLocation = url | ||
@@ -338,3 +337,2 @@ this.popTarget = this.currentLocation.href | ||
E.delegate('click', links, this.onClick) | ||
E.delegate('mouseenter focus', links, this.onPreload) | ||
E.on('popstate', window, this.onPopstate) | ||
@@ -371,12 +369,2 @@ } | ||
onPreload = (e) => { | ||
const target = processUrl(e.currentTarget.href) | ||
if (this.currentLocation.host !== target.host) { | ||
return | ||
} | ||
this.preload(e.currentTarget.href) | ||
} | ||
/** | ||
@@ -478,2 +466,3 @@ * @private | ||
content, | ||
skipCache: content.hasAttribute('data-taxi-nocache'), | ||
scripts: this.reloadJsFilter ? Array.from(page.querySelectorAll('script')).filter(this.reloadJsFilter) : [], | ||
@@ -480,0 +469,0 @@ title: page.title, |
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
196817
1152