@unseenco/taxi
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -1,2 +0,2 @@ | ||
import t from"@unseenco/e";function e(){return e=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},e.apply(this,arguments)}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function r(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i=new DOMParser;function o(t){var e=new URL(t,window.location.origin),n=null;return e.hash.length&&(n=t.replace(e.hash,"")),{hasHash:e.hash.length>0,pathname:e.pathname,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(){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}(),h=/*#__PURE__*/function(){function e(t){var e=this;void 0===t&&(t={}),this.isTransitioning=!1,this.currentView=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.href!==n.href||e.currentLocation.hasHash&&!n.hasHash)return t.preventDefault(),void e.navigate(n.raw,t.currentTarget.dataset.taxiTransition||!1,t.currentTarget);e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return window.location.pathname!==e.currentLocation.pathname&&(e.isTransitioning?(window.history.pushState({},"",e.currentLocation.href),!1):void e.navigate(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.views,a=t.transitions,c=void 0===a?{default:u}:a,s=t.reloadJsFilter,h=void 0===s?function(t){return!("__bs_script__"===(null==t?void 0:t.id)||null!=t&&t.src.includes("browser-sync-client.js"))}:s;this.views=void 0===i?{default:f}:i,this.transitions=c,this.defaultView=this.views.default||f,this.defaultTransition=this.transitions.default||u,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=h,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.currentView=this.cache.get(this.currentLocation.href),this.currentView.view.initialLoad()}var n=e.prototype;return n.setDefaultView=function(t){this.defaultView=this.views[t]},n.setDefaultTransition=function(t){this.defaultTransition=this.transitions[t]},n.addRoute=function(t,e,n){this.router||(this.router=new s),this.router.add(t,e,n)},n.preload=function(t){var e=this;return t=o(t).href,this.cache.has(t)||this.fetch(t).then(function(n){try{return e.cache.set(t,e.createCacheEntry(n)),Promise.resolve()}catch(t){return Promise.reject(t)}}),this},n.navigate=function(t,e,n){var r=this;return void 0===e&&(e=!1),void 0===n&&(n=!1),this.targetLocation=o(t),new Promise(function(t,i){if(r.isTransitioning)i(new Error("A transition is currently in progress"));else{var o=new(r.chooseTransition(e))({wrapper:r.wrapper});r.beforeFetch(r.targetLocation,o,n).then(function(){try{return r.cache.has(r.targetLocation.href)?Promise.resolve(r.afterFetch(r.targetLocation,o,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,o,r.createCacheEntry(t),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}}).then(function(){t()})}})},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.currentView,trigger:r}),new Promise(function(t){i.currentView.view.leave(n,r).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,t.emit("NAVIGATE_IN",{from:this.currentView,to:r,trigger:i}),new Promise(function(e){r.view.update(),o.loadScripts(r.scripts),r.view.enter(n,i).then(function(){t.emit("NAVIGATE_END",{from:o.currentView,to:r,trigger:i}),o.currentView=r,o.isTransitioning=!1,e()})})},n.loadScripts=function(t){for(var e,n=[].concat(t),i=[].concat(document.querySelectorAll("script:not([data-no-reload])")).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.views[e.dataset.taxiView]:this.defaultView;return{page:t,content:e,scripts:[].concat(t.querySelectorAll("script:not([data-no-reload])")).filter(this.reloadJsFilter),title:t.title,view:new n({wrapper:this.wrapper,title:t.title,content:e,page:t})}},e}(),u=/*#__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}(),f=/*#__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){var n=this;return new Promise(function(r){n.onLeave(),t.leave({trigger:e,from:n.content}).then(function(){n.remove(),n.onLeaveCompleted(),r()})})},t}();export{h as Core,u as Transition,f as View}; | ||
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,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(){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}(),h=/*#__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.href!==n.href||e.currentLocation.hasHash&&!n.hasHash)return t.preventDefault(),void e.navigateTo(n.raw,t.currentTarget.dataset.taxiTransition||!1,t.currentTarget);e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return window.location.pathname!==e.currentLocation.pathname&&(e.isTransitioning?(window.history.pushState({},"",e.currentLocation.href),!1):void e.navigateTo(window.location.href,!1,"popstate"))};var n=t.links,r=void 0===n?"a:not([target]):not([href^=\\#]):not([data-taxi-ignore])":n,i=t.renderers,a=t.transitions,c=void 0===a?{default:u}:a,s=t.reloadJsFilter,h=void 0===s?function(t){return!("__bs_script__"===(null==t?void 0:t.id)||null!=t&&t.src.includes("browser-sync-client.js"))}:s;this.renderers=void 0===i?{default:f}:i,this.transitions=c,this.defaultRenderer=this.renderers.default||f,this.defaultTransition=this.transitions.default||u,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=h,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 s),this.router.add(t,e,n)},n.preload=function(t){var e=this;return t=o(t).href,this.cache.has(t)||this.fetch(t).then(function(n){try{return e.cache.set(t,e.createCacheEntry(n)),Promise.resolve()}catch(t){return Promise.reject(t)}}),this},n.navigateTo=function(t,e,n){var r=this;return void 0===e&&(e=!1),void 0===n&&(n=!1),this.targetLocation=o(t),new Promise(function(t,i){if(r.isTransitioning)i(new Error("A transition is currently in progress"));else{var o=new(r.chooseTransition(e))({wrapper:r.wrapper});r.beforeFetch(r.targetLocation,o,n).then(function(){try{return r.cache.has(r.targetLocation.href)?Promise.resolve(r.afterFetch(r.targetLocation,o,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,o,r.createCacheEntry(t),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}}).then(function(){t()})}})},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).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,t.emit("NAVIGATE_IN",{from:this.currentCacheEntry,to:r,trigger:i}),new Promise(function(e){r.renderer.update(),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:not([data-no-reload])")).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:[].concat(t.querySelectorAll("script:not([data-no-reload])")).filter(this.reloadJsFilter),title:t.title,renderer:new n({wrapper:this.wrapper,title:t.title,content:e,page:t})}},e}(),u=/*#__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}(),f=/*#__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){var n=this;return new Promise(function(r){n.onLeave(),t.leave({trigger:e,from:n.content}).then(function(){n.remove(),n.onLeaveCompleted(),r()})})},t}();export{h as Core,f as Renderer,u 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,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(){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}(),u=/*#__PURE__*/function(){function t(t){var e=this;void 0===t&&(t={}),this.isTransitioning=!1,this.currentView=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.href!==n.href||e.currentLocation.hasHash&&!n.hasHash)return t.preventDefault(),void e.navigate(n.raw,t.currentTarget.dataset.taxiTransition||!1,t.currentTarget);e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return window.location.pathname!==e.currentLocation.pathname&&(e.isTransitioning?(window.history.pushState({},"",e.currentLocation.href),!1):void e.navigate(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.views,o=t.transitions,c=void 0===o?{default:f}:o,s=t.reloadJsFilter,h=void 0===s?function(t){return!("__bs_script__"===(null==t?void 0:t.id)||null!=t&&t.src.includes("browser-sync-client.js"))}:s;this.views=void 0===i?{default:l}:i,this.transitions=c,this.defaultView=this.views.default||l,this.defaultTransition=this.transitions.default||f,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=h,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.currentView=this.cache.get(this.currentLocation.href),this.currentView.view.initialLoad()}var n=t.prototype;return n.setDefaultView=function(t){this.defaultView=this.views[t]},n.setDefaultTransition=function(t){this.defaultTransition=this.transitions[t]},n.addRoute=function(t,e,n){this.router||(this.router=new h),this.router.add(t,e,n)},n.preload=function(t){var e=this;return t=a(t).href,this.cache.has(t)||this.fetch(t).then(function(n){try{return e.cache.set(t,e.createCacheEntry(n)),Promise.resolve()}catch(t){return Promise.reject(t)}}),this},n.navigate=function(t,e,n){var r=this;return void 0===e&&(e=!1),void 0===n&&(n=!1),this.targetLocation=a(t),new Promise(function(t,i){if(r.isTransitioning)i(new Error("A transition is currently in progress"));else{var o=new(r.chooseTransition(e))({wrapper:r.wrapper});r.beforeFetch(r.targetLocation,o,n).then(function(){try{return r.cache.has(r.targetLocation.href)?Promise.resolve(r.afterFetch(r.targetLocation,o,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,o,r.createCacheEntry(t),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}}).then(function(){t()})}})},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.currentView,trigger:r}),new Promise(function(e){i.currentView.view.leave(n,r).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,e.default.emit("NAVIGATE_IN",{from:this.currentView,to:r,trigger:i}),new Promise(function(t){r.view.update(),o.loadScripts(r.scripts),r.view.enter(n,i).then(function(){e.default.emit("NAVIGATE_END",{from:o.currentView,to:r,trigger:i}),o.currentView=r,o.isTransitioning=!1,t()})})},n.loadScripts=function(t){for(var e,n=[].concat(t),r=[].concat(document.querySelectorAll("script:not([data-no-reload])")).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.views[e.dataset.taxiView]:this.defaultView;return{page:t,content:e,scripts:[].concat(t.querySelectorAll("script:not([data-no-reload])")).filter(this.reloadJsFilter),title:t.title,view:new n({wrapper:this.wrapper,title:t.title,content:e,page:t})}},t}(),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(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}(),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){var n=this;return new Promise(function(r){n.onLeave(),t.leave({trigger:e,from:n.content}).then(function(){n.remove(),n.onLeaveCompleted(),r()})})},t}();exports.Core=u,exports.Transition=f,exports.View=l; | ||
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,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(){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}(),u=/*#__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.href!==n.href||e.currentLocation.hasHash&&!n.hasHash)return t.preventDefault(),void e.navigateTo(n.raw,t.currentTarget.dataset.taxiTransition||!1,t.currentTarget);e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return window.location.pathname!==e.currentLocation.pathname&&(e.isTransitioning?(window.history.pushState({},"",e.currentLocation.href),!1):void e.navigateTo(window.location.href,!1,"popstate"))};var n=t.links,r=void 0===n?"a:not([target]):not([href^=\\#]):not([data-taxi-ignore])":n,i=t.renderers,o=t.transitions,c=void 0===o?{default:f}:o,s=t.reloadJsFilter,h=void 0===s?function(t){return!("__bs_script__"===(null==t?void 0:t.id)||null!=t&&t.src.includes("browser-sync-client.js"))}:s;this.renderers=void 0===i?{default:l}:i,this.transitions=c,this.defaultRenderer=this.renderers.default||l,this.defaultTransition=this.transitions.default||f,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=h,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 h),this.router.add(t,e,n)},n.preload=function(t){var e=this;return t=a(t).href,this.cache.has(t)||this.fetch(t).then(function(n){try{return e.cache.set(t,e.createCacheEntry(n)),Promise.resolve()}catch(t){return Promise.reject(t)}}),this},n.navigateTo=function(t,e,n){var r=this;return void 0===e&&(e=!1),void 0===n&&(n=!1),this.targetLocation=a(t),new Promise(function(t,i){if(r.isTransitioning)i(new Error("A transition is currently in progress"));else{var o=new(r.chooseTransition(e))({wrapper:r.wrapper});r.beforeFetch(r.targetLocation,o,n).then(function(){try{return r.cache.has(r.targetLocation.href)?Promise.resolve(r.afterFetch(r.targetLocation,o,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,o,r.createCacheEntry(t),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}}).then(function(){t()})}})},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).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,e.default.emit("NAVIGATE_IN",{from:this.currentCacheEntry,to:r,trigger:i}),new Promise(function(t){r.renderer.update(),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:not([data-no-reload])")).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:[].concat(t.querySelectorAll("script:not([data-no-reload])")).filter(this.reloadJsFilter),title:t.title,renderer:new n({wrapper:this.wrapper,title:t.title,content:e,page:t})}},t}(),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(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}(),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){var n=this;return new Promise(function(r){n.onLeave(),t.leave({trigger:e,from:n.content}).then(function(){n.remove(),n.onLeaveCompleted(),r()})})},t}();exports.Core=u,exports.Renderer=l,exports.Transition=f; | ||
//# sourceMappingURL=taxi.js.map |
@@ -1,2 +0,2 @@ | ||
import t from"@unseenco/e";const e=new DOMParser;function n(t){const e=new URL(t,window.location.origin);let n=null;return e.hash.length&&(n=t.replace(e.hash,"")),{hasHash:e.hash.length>0,pathname:e.pathname,raw:t,href:n||e.href}}function r(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 n=0;n<t.attributes.length;n++){const r=t.attributes[n];e.setAttribute(r.nodeName,r.nodeValue)}return t.innerHTML&&(e.innerHTML=t.innerHTML),e}class a{constructor(){this.data=new Map,this.regexCache=new Map}add(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}$`))}findMatch(t,e){for(const[n,r]of this.data)if(t.pathname.match(this.regexCache.get(n))){for(const[t,n]of r)if(e.pathname.match(this.regexCache.get(t)))return n;break}return null}}class o{constructor(t={}){this.isTransitioning=!1,this.currentView=null,this.cache=new Map,this.onClick=t=>{if(!t.metaKey&&!t.ctrlKey){const e=n(t.currentTarget.href);if(this.currentLocation=n(window.location.href),this.currentLocation.href!==e.href||this.currentLocation.hasHash&&!e.hasHash)return t.preventDefault(),void this.navigate(e.raw,t.currentTarget.dataset.taxiTransition||!1,t.currentTarget);this.currentLocation.hasHash||e.hasHash||t.preventDefault()}},this.onPopstate=()=>window.location.pathname!==this.currentLocation.pathname&&(this.isTransitioning?(window.history.pushState({},"",this.currentLocation.href),!1):void this.navigate(window.location.href,!1,"popstate"));const{links:e="a:not([target]):not([href^=\\#]):not([data-taxi-ignore])",views:r={default:c},transitions:i={default:h},reloadJsFilter:a=function(t){return!("__bs_script__"===(null==t?void 0:t.id)||null!=t&&t.src.includes("browser-sync-client.js"))}}=t;this.views=r,this.transitions=i,this.defaultView=this.views.default||c,this.defaultTransition=this.transitions.default||h,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=a,this.cache=new Map,this.attachEvents(e),this.currentLocation=n(window.location.href),this.cache.set(this.currentLocation.href,this.createCacheEntry(document.cloneNode(!0))),this.currentView=this.cache.get(this.currentLocation.href),this.currentView.view.initialLoad()}setDefaultView(t){this.defaultView=this.views[t]}setDefaultTransition(t){this.defaultTransition=this.transitions[t]}addRoute(t,e,n){this.router||(this.router=new a),this.router.add(t,e,n)}preload(t){var e=this;return t=n(t).href,this.cache.has(t)||this.fetch(t).then(async function(n){e.cache.set(t,e.createCacheEntry(n))}),this}navigate(t,e=!1,r=!1){var i=this;return this.targetLocation=n(t),new Promise((t,n)=>{if(this.isTransitioning)return void n(new Error("A transition is currently in progress"));const a=new(this.chooseTransition(e))({wrapper:this.wrapper});this.beforeFetch(this.targetLocation,a,r).then(async function(){return i.cache.has(i.targetLocation.href)?await i.afterFetch(i.targetLocation,a,i.cache.get(i.targetLocation.href),r):i.fetch(i.targetLocation.raw).then(async function(t){return await i.afterFetch(i.targetLocation,a,i.createCacheEntry(t),r)})}).then(()=>{t()})})}on(e,n){t.on(e,n)}off(e,n){t.off(e,n)}beforeFetch(e,n,r){return this.isTransitioning=!0,t.emit("NAVIGATE_OUT",{from:this.currentView,trigger:r}),new Promise(t=>{this.currentView.view.leave(n,r).then(()=>{"popstate"!==r&&window.history.pushState({},"",e.raw),t()})})}afterFetch(e,n,r,i){return this.cache.has(e.href)||this.cache.set(e.href,r),this.currentLocation=e,t.emit("NAVIGATE_IN",{from:this.currentView,to:r,trigger:i}),new Promise(e=>{r.view.update(),this.loadScripts(r.scripts),r.view.enter(n,i).then(()=>{t.emit("NAVIGATE_END",{from:this.currentView,to:r,trigger:i}),this.currentView=r,this.isTransitioning=!1,e()})})}loadScripts(t){const e=[...t],n=[...document.querySelectorAll("script:not([data-no-reload])")].filter(this.reloadJsFilter);for(let t=0;t<n.length;t++)for(let r=0;r<e.length;r++)if(n[t].outerHTML===e[r].outerHTML){(a=n[t]).parentNode.replaceChild(i(a),a),e.splice(r,1);break}var a;for(const t of e)r(t)}attachEvents(e){t.delegate("click",e,this.onClick),t.on("popstate",window,this.onPopstate)}fetch(t){return new Promise(n=>{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 r;n("string"==typeof(r=t)?e.parseFromString(r,"text/html"):r)}).catch(e=>{console.warn(e),window.location.href=t})})}chooseTransition(t){var e;if(t)return this.transitions[t];const n=null==(e=this.router)?void 0:e.findMatch(this.currentLocation,this.targetLocation);return n?this.transitions[n]:this.defaultTransition}createCacheEntry(t){const e=t.querySelector("[data-taxi-view]"),n=e.dataset.taxiView.length?this.views[e.dataset.taxiView]:this.defaultView;return{page:t,content:e,scripts:[...t.querySelectorAll("script:not([data-no-reload])")].filter(this.reloadJsFilter),title:t.title,view:new n({wrapper:this.wrapper,title:t.title,content:e,page:t})}}}function s(){return s=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},s.apply(this,arguments)}class h{constructor({wrapper:t}){this.wrapper=t}leave(t){return new Promise(e=>{this.onLeave(s({},t,{done:e}))})}enter(t){return new Promise(e=>{this.onEnter(s({},t,{done:e}))})}onLeave({done:t}){t()}onEnter({done:t}){t()}}class c{constructor({content:t,page:e,title:n,wrapper:r}){this._contentString=t.outerHTML,this.page=e,this.title=n,this.wrapper=r,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(n=>{this.onEnter(),t.enter({trigger:e,to:this.content}).then(()=>{this.onEnterCompleted(),n()})})}leave(t,e){return new Promise(n=>{this.onLeave(),t.leave({trigger:e,from:this.content}).then(()=>{this.remove(),this.onLeaveCompleted(),n()})})}}export{o as Core,h as Transition,c as View}; | ||
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,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}class a{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 o{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.href!==e.href||this.currentLocation.hasHash&&!e.hasHash)return t.preventDefault(),void this.navigateTo(e.raw,t.currentTarget.dataset.taxiTransition||!1,t.currentTarget);this.currentLocation.hasHash||e.hasHash||t.preventDefault()}},this.onPopstate=()=>window.location.pathname!==this.currentLocation.pathname&&(this.isTransitioning?(window.history.pushState({},"",this.currentLocation.href),!1):void this.navigateTo(window.location.href,!1,"popstate"));const{links:e="a:not([target]):not([href^=\\#]):not([data-taxi-ignore])",renderers:n={default:c},transitions:i={default:h},reloadJsFilter:a=function(t){return!("__bs_script__"===(null==t?void 0:t.id)||null!=t&&t.src.includes("browser-sync-client.js"))}}=t;this.renderers=n,this.transitions=i,this.defaultRenderer=this.renderers.default||c,this.defaultTransition=this.transitions.default||h,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=a,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 a),this.router.add(t,e,r)}preload(t){var e=this;return t=r(t).href,this.cache.has(t)||this.fetch(t).then(async function(r){e.cache.set(t,e.createCacheEntry(r))}),this}navigateTo(t,e=!1,n=!1){var i=this;return this.targetLocation=r(t),new Promise((t,r)=>{if(this.isTransitioning)return void r(new Error("A transition is currently in progress"));const a=new(this.chooseTransition(e))({wrapper:this.wrapper});this.beforeFetch(this.targetLocation,a,n).then(async function(){return i.cache.has(i.targetLocation.href)?await i.afterFetch(i.targetLocation,a,i.cache.get(i.targetLocation.href),n):i.fetch(i.targetLocation.raw).then(async function(t){return await i.afterFetch(i.targetLocation,a,i.createCacheEntry(t),n)})}).then(()=>{t()})})}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).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,t.emit("NAVIGATE_IN",{from:this.currentCacheEntry,to:n,trigger:i}),new Promise(e=>{n.renderer.update(),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:not([data-no-reload])")].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:[...t.querySelectorAll("script:not([data-no-reload])")].filter(this.reloadJsFilter),title:t.title,renderer:new r({wrapper:this.wrapper,title:t.title,content:e,page:t})}}}function s(){return s=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},s.apply(this,arguments)}class h{constructor({wrapper:t}){this.wrapper=t}leave(t){return new Promise(e=>{this.onLeave(s({},t,{done:e}))})}enter(t){return new Promise(e=>{this.onEnter(s({},t,{done:e}))})}onLeave({done:t}){t()}onEnter({done:t}){t()}}class c{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){return new Promise(r=>{this.onLeave(),t.leave({trigger:e,from:this.content}).then(()=>{this.remove(),this.onLeaveCompleted(),r()})})}}export{o as Core,c as Renderer,h 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,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(){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}(),l=/*#__PURE__*/function(){function t(t){var e=this;void 0===t&&(t={}),this.isTransitioning=!1,this.currentView=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.href!==n.href||e.currentLocation.hasHash&&!n.hasHash)return t.preventDefault(),void e.navigate(n.raw,t.currentTarget.dataset.taxiTransition||!1,t.currentTarget);e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return window.location.pathname!==e.currentLocation.pathname&&(e.isTransitioning?(window.history.pushState({},"",e.currentLocation.href),!1):void e.navigate(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.views,o=t.transitions,a=void 0===o?{default:d}:o,c=t.reloadJsFilter,h=void 0===c?function(t){return!("__bs_script__"===(null==t?void 0:t.id)||null!=t&&t.src.includes("browser-sync-client.js"))}:c;this.views=void 0===i?{default:p}:i,this.transitions=a,this.defaultView=this.views.default||p,this.defaultTransition=this.transitions.default||d,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=h,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.currentView=this.cache.get(this.currentLocation.href),this.currentView.view.initialLoad()}var e=t.prototype;return e.setDefaultView=function(t){this.defaultView=this.views[t]},e.setDefaultTransition=function(t){this.defaultTransition=this.transitions[t]},e.addRoute=function(t,e,n){this.router||(this.router=new f),this.router.add(t,e,n)},e.preload=function(t){var e=this;return t=s(t).href,this.cache.has(t)||this.fetch(t).then(function(n){try{return e.cache.set(t,e.createCacheEntry(n)),Promise.resolve()}catch(t){return Promise.reject(t)}}),this},e.navigate=function(t,e,n){var r=this;return void 0===e&&(e=!1),void 0===n&&(n=!1),this.targetLocation=s(t),new Promise(function(t,i){if(r.isTransitioning)i(new Error("A transition is currently in progress"));else{var o=new(r.chooseTransition(e))({wrapper:r.wrapper});r.beforeFetch(r.targetLocation,o,n).then(function(){try{return r.cache.has(r.targetLocation.href)?Promise.resolve(r.afterFetch(r.targetLocation,o,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,o,r.createCacheEntry(t),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}}).then(function(){t()})}})},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.currentView,trigger:n}),new Promise(function(r){i.currentView.view.leave(e,n).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,r.default.emit("NAVIGATE_IN",{from:this.currentView,to:n,trigger:i}),new Promise(function(t){n.view.update(),o.loadScripts(n.scripts),n.view.enter(e,i).then(function(){r.default.emit("NAVIGATE_END",{from:o.currentView,to:n,trigger:i}),o.currentView=n,o.isTransitioning=!1,t()})})},e.loadScripts=function(t){for(var e,n=[].concat(t),r=[].concat(document.querySelectorAll("script:not([data-no-reload])")).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.views[e.dataset.taxiView]:this.defaultView;return{page:t,content:e,scripts:[].concat(t.querySelectorAll("script:not([data-no-reload])")).filter(this.reloadJsFilter),title:t.title,view:new n({wrapper:this.wrapper,title:t.title,content:e,page:t})}},t}(),d=/*#__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}(),p=/*#__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){var n=this;return new Promise(function(r){n.onLeave(),t.leave({trigger:e,from:n.content}).then(function(){n.remove(),n.onLeaveCompleted(),r()})})},t}();t.Core=l,t.Transition=d,t.View=p}); | ||
!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,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(){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}(),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=s(t.currentTarget.href);if(e.currentLocation=s(window.location.href),e.currentLocation.href!==n.href||e.currentLocation.hasHash&&!n.hasHash)return t.preventDefault(),void e.navigateTo(n.raw,t.currentTarget.dataset.taxiTransition||!1,t.currentTarget);e.currentLocation.hasHash||n.hasHash||t.preventDefault()}},this.onPopstate=function(){return window.location.pathname!==e.currentLocation.pathname&&(e.isTransitioning?(window.history.pushState({},"",e.currentLocation.href),!1):void e.navigateTo(window.location.href,!1,"popstate"))};var n=t.links,r=void 0===n?"a:not([target]):not([href^=\\#]):not([data-taxi-ignore])":n,i=t.renderers,o=t.transitions,a=void 0===o?{default:d}:o,c=t.reloadJsFilter,h=void 0===c?function(t){return!("__bs_script__"===(null==t?void 0:t.id)||null!=t&&t.src.includes("browser-sync-client.js"))}:c;this.renderers=void 0===i?{default:p}:i,this.transitions=a,this.defaultRenderer=this.renderers.default||p,this.defaultTransition=this.transitions.default||d,this.wrapper=document.querySelector("[data-taxi]"),this.reloadJsFilter=h,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 f),this.router.add(t,e,n)},e.preload=function(t){var e=this;return t=s(t).href,this.cache.has(t)||this.fetch(t).then(function(n){try{return e.cache.set(t,e.createCacheEntry(n)),Promise.resolve()}catch(t){return Promise.reject(t)}}),this},e.navigateTo=function(t,e,n){var r=this;return void 0===e&&(e=!1),void 0===n&&(n=!1),this.targetLocation=s(t),new Promise(function(t,i){if(r.isTransitioning)i(new Error("A transition is currently in progress"));else{var o=new(r.chooseTransition(e))({wrapper:r.wrapper});r.beforeFetch(r.targetLocation,o,n).then(function(){try{return r.cache.has(r.targetLocation.href)?Promise.resolve(r.afterFetch(r.targetLocation,o,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,o,r.createCacheEntry(t),n))}catch(t){return Promise.reject(t)}}))}catch(t){return Promise.reject(t)}}).then(function(){t()})}})},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).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,r.default.emit("NAVIGATE_IN",{from:this.currentCacheEntry,to:n,trigger:i}),new Promise(function(t){n.renderer.update(),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:not([data-no-reload])")).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:[].concat(t.querySelectorAll("script:not([data-no-reload])")).filter(this.reloadJsFilter),title:t.title,renderer:new n({wrapper:this.wrapper,title:t.title,content:e,page:t})}},t}(),d=/*#__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}(),p=/*#__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){var n=this;return new Promise(function(r){n.onLeave(),t.leave({trigger:e,from:n.content}).then(function(){n.remove(),n.onLeaveCompleted(),r()})})},t}();t.Core=l,t.Renderer=p,t.Transition=d}); | ||
//# sourceMappingURL=taxi.umd.js.map |
{ | ||
"name": "@unseenco/taxi", | ||
"description": "A modern page transition library which supports routing, preloading, and additional script reloading.", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"license": "GPL-3.0-or-later", | ||
@@ -6,0 +6,0 @@ "source": "src/taxi.js", |
/** | ||
* @typedef CacheEntry | ||
* @type {object} | ||
* @property {View} view | ||
* @property {Renderer} renderer | ||
* @property {Document|Node} page | ||
@@ -13,3 +13,3 @@ * @property {array} scripts | ||
* @param {string} [parameters.links] Selector to select elements attach highway link events to | ||
* @param {Object.<string, View>} [parameters.views] All Views for the application | ||
* @param {Object.<string, Renderer>} [parameters.renderers] All Renderers for the application | ||
* @param {Object.<string, Transition>} [parameters.transitions] All Transitions for the application | ||
@@ -23,3 +23,3 @@ * @param {function(node: HTMLElement)} [parameters.reloadJsFilter] | ||
*/ | ||
currentView: CacheEntry | null; | ||
currentCacheEntry: CacheEntry | null; | ||
/** | ||
@@ -29,5 +29,5 @@ * @type {Map<string, CacheEntry>} | ||
cache: Map<string, CacheEntry>; | ||
views: any; | ||
renderers: any; | ||
transitions: any; | ||
defaultView: any; | ||
defaultRenderer: any; | ||
defaultTransition: any; | ||
@@ -43,5 +43,5 @@ wrapper: Element; | ||
/** | ||
* @param {string} view | ||
* @param {string} renderer | ||
*/ | ||
setDefaultView(view: string): void; | ||
setDefaultRenderer(renderer: string): void; | ||
/** | ||
@@ -66,3 +66,3 @@ * @param {string} transition | ||
*/ | ||
navigate(url: string, transition?: string | false, trigger?: string | false | HTMLElement): Promise<void | Error>; | ||
navigateTo(url: string, transition?: string | false, trigger?: string | false | HTMLElement): Promise<void | Error>; | ||
targetLocation: { | ||
@@ -144,3 +144,3 @@ raw: string; | ||
export type CacheEntry = { | ||
view: View; | ||
renderer: Renderer; | ||
page: Document | Node; | ||
@@ -152,2 +152,2 @@ scripts: any[]; | ||
import RouteStore from "./RouteStore"; | ||
import { View } from "./taxi"; | ||
import { Renderer } from "./taxi"; |
import E from '@unseenco/e' | ||
import { appendScript, parseDom, processUrl, reloadScript } from './helpers' | ||
import { Transition, View } from './taxi' | ||
import { Transition, Renderer } from './taxi' | ||
import RouteStore from './RouteStore' | ||
@@ -9,3 +9,3 @@ | ||
* @type {object} | ||
* @property {View} view | ||
* @property {Renderer} renderer | ||
* @property {Document|Node} page | ||
@@ -23,3 +23,3 @@ * @property {array} scripts | ||
*/ | ||
currentView = null | ||
currentCacheEntry = null | ||
@@ -33,3 +33,3 @@ /** | ||
* @param {string} [parameters.links] Selector to select elements attach highway link events to | ||
* @param {Object.<string, View>} [parameters.views] All Views for the application | ||
* @param {Object.<string, Renderer>} [parameters.renderers] All Renderers for the application | ||
* @param {Object.<string, Transition>} [parameters.transitions] All Transitions for the application | ||
@@ -41,4 +41,4 @@ * @param {function(node: HTMLElement)} [parameters.reloadJsFilter] | ||
links = 'a:not([target]):not([href^=\\#]):not([data-taxi-ignore])', | ||
views = { | ||
default: View | ||
renderers = { | ||
default: Renderer | ||
}, | ||
@@ -53,5 +53,5 @@ transitions = { | ||
this.views = views | ||
this.renderers = renderers | ||
this.transitions = transitions | ||
this.defaultView = this.views.default || View | ||
this.defaultRenderer = this.renderers.default || Renderer | ||
this.defaultTransition = this.transitions.default || Transition | ||
@@ -70,12 +70,12 @@ this.wrapper = document.querySelector('[data-taxi]') | ||
// fire the current view enter methods | ||
this.currentView = this.cache.get(this.currentLocation.href) | ||
this.currentView.view.initialLoad() | ||
// fire the current Renderer enter methods | ||
this.currentCacheEntry = this.cache.get(this.currentLocation.href) | ||
this.currentCacheEntry.renderer.initialLoad() | ||
} | ||
/** | ||
* @param {string} view | ||
* @param {string} renderer | ||
*/ | ||
setDefaultView(view) { | ||
this.defaultView = this.views[view] | ||
setDefaultRenderer(renderer) { | ||
this.defaultRenderer = this.renderers[renderer] | ||
} | ||
@@ -123,3 +123,3 @@ | ||
*/ | ||
navigate(url, transition = false, trigger = false) { | ||
navigateTo(url, transition = false, trigger = false) { | ||
this.targetLocation = processUrl(url) | ||
@@ -179,3 +179,3 @@ | ||
E.emit('NAVIGATE_OUT', { | ||
from: this.currentView, | ||
from: this.currentCacheEntry, | ||
trigger | ||
@@ -185,3 +185,3 @@ }) | ||
return new Promise((resolve) => { | ||
this.currentView.view.leave(TransitionClass, trigger) | ||
this.currentCacheEntry.renderer.leave(TransitionClass, trigger) | ||
.then(() => { | ||
@@ -214,3 +214,3 @@ if (trigger !== 'popstate') { | ||
E.emit('NAVIGATE_IN', { | ||
from: this.currentView, | ||
from: this.currentCacheEntry, | ||
to: entry, | ||
@@ -221,10 +221,10 @@ trigger | ||
return new Promise((resolve) => { | ||
entry.view.update() | ||
entry.renderer.update() | ||
this.loadScripts(entry.scripts) | ||
entry.view.enter(TransitionClass, trigger) | ||
entry.renderer.enter(TransitionClass, trigger) | ||
.then(() => { | ||
E.emit('NAVIGATE_END', { | ||
from: this.currentView, | ||
from: this.currentCacheEntry, | ||
to: entry, | ||
@@ -234,3 +234,3 @@ trigger | ||
this.currentView = entry | ||
this.currentCacheEntry = entry | ||
this.isTransitioning = false | ||
@@ -289,3 +289,3 @@ resolve() | ||
// noinspection JSIgnoredPromiseFromCall | ||
this.navigate(target.raw, e.currentTarget.dataset.taxiTransition || false, e.currentTarget) | ||
this.navigateTo(target.raw, e.currentTarget.dataset.taxiTransition || false, e.currentTarget) | ||
return | ||
@@ -318,3 +318,3 @@ } | ||
// noinspection JSIgnoredPromiseFromCall | ||
this.navigate(window.location.href, false, 'popstate') | ||
this.navigateTo(window.location.href, false, 'popstate') | ||
} | ||
@@ -379,3 +379,3 @@ | ||
const content = page.querySelector('[data-taxi-view]') | ||
const View = content.dataset.taxiView.length ? this.views[content.dataset.taxiView] : this.defaultView | ||
const Renderer = content.dataset.taxiView.length ? this.renderers[content.dataset.taxiView] : this.defaultRenderer | ||
@@ -387,3 +387,3 @@ return { | ||
title: page.title, | ||
view: new View({ | ||
renderer: new Renderer({ | ||
wrapper: this.wrapper, | ||
@@ -390,0 +390,0 @@ title: page.title, |
import Core from "./Core"; | ||
import View from "./View"; | ||
import Renderer from "./Renderer"; | ||
import Transition from "./Transition"; | ||
export { Core, View, Transition }; | ||
export { Core, Renderer, Transition }; |
import Core from "./Core" | ||
import View from "./View" | ||
import Renderer from "./Renderer" | ||
import Transition from "./Transition" | ||
@@ -7,4 +7,4 @@ | ||
Core, | ||
View, | ||
Renderer, | ||
Transition | ||
} |
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
158732
995