swup 4.0.0-rc.28 → 4.0.0-rc.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Swup.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var t=require("delegate-it"),e=require("path-to-regexp");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=/*#__PURE__*/n(t);const o=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",i=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},s=function(t,e){void 0===e&&(e={});const n={url:t=t||i({hash:!0}),random:Math.random(),source:"swup",...e};history.pushState(n,"",t)},a=function(t,e){void 0===t&&(t=null),void 0===e&&(e={}),t=t||i({hash:!0});const n={...history.state,url:t,random:Math.random(),source:"swup",...e};history.replaceState(n,"",t)},l=(t,e,n,o)=>{const i=new AbortController;return o={...o,signal:i.signal},r.default(t,e,n,o),{destroy:()=>i.abort()}};class c extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new c(e)}static fromUrl(t){return new c(t)}}class u{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){return this.pages}has(t){return this.pages.has(this.resolve(t))}get(t){return this.pages.get(this.resolve(t))}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",{page:e})}update(t,e){t=this.resolve(t),e={...this.get(t),...e,url:t},this.pages.set(t,e)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear")}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=c.fromUrl(t);return this.swup.resolveUrl(e)}}const h=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},m=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},p=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function d(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function f(t,e){return void 0===e&&(e=[]),new Promise((n,r)=>{const o=t(...e);d(o)?o.then(n,r):n(o)})}const v=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,g=t=>1e3*Number(t.slice(0,-1).replace(",","."));class w{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?m(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}function y(t){let{to:e,from:n=this.currentPageUrl,hash:r,animate:o=!0,animation:i,el:s,event:a,action:l="push",resetScroll:c=!0}=t;return{from:{url:n},to:{url:e},containers:this.options.containers,animation:{animate:o,wait:!1,name:i,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:s,event:a},history:{action:l,popstate:!1,direction:void 0},scroll:{reset:c,target:r}}}const P="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function k(t,e,n){if(!t.s){if(n instanceof S){if(!n.s)return void(n.o=k.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(k.bind(null,t,e),k.bind(null,t,2));t.s=e,t.v=n;const r=t.o;r&&r(t)}}const S=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const r=new t,o=this.s;if(o){const t=1&o?e:n;if(t){try{k(r,1,t(this.v))}catch(t){k(r,2,t)}return r}return this}return this.o=function(t){try{const o=t.v;1&t.s?k(r,1,e?e(o):o):n?k(r,1,n(o)):k(r,2,o)}catch(t){k(r,2,t)}},r},t}();function b(t){return t instanceof S&&1&t.s}class U{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:end"],this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n){void 0===n&&(n={});const r=this.get(t);if(!r)return console.warn(`Hook '${t}' not found.`),()=>{};const o=r.size+1,i={...n,id:o,hook:t,handler:e};return r.set(e,i),()=>this.off(t,e)}before(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,before:!0})}replace(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,replace:!0})}once(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n){try{const r=this,{before:o,handler:i,after:s}=r.getHandlers(t,n);return Promise.resolve(r.run(o,e)).then(function(){return Promise.resolve(r.run(i,e)).then(function(n){let[o]=n;return Promise.resolve(r.run(s,e)).then(function(){return r.dispatchDomEvent(t,e),o})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n){const{before:r,handler:o,after:i}=this.getHandlers(t,n);this.runSync(r,e);const[s]=this.runSync(o,e);return this.runSync(i,e),this.dispatchDomEvent(t,e),s}run(t,e){try{const n=this,r=[],o=function(t,e,n){if("function"==typeof t[P]){var r,o,i,s=t[P]();if(function t(n){try{for(;!(r=s.next()).done;)if((n=e(r.value))&&n.then){if(!b(n))return void n.then(t,i||(i=k.bind(null,o=new S,2)));n=n.v}o?k(o,1,n):o=n}catch(t){k(o||(o=new S),2,t)}}(),s.return){var a=function(t){try{r.done||s.return()}catch(t){}return t};if(o&&o.then)return o.then(a,function(t){throw a(t)});a()}return o}if(!("length"in t))throw new TypeError("Object is not iterable");for(var l=[],c=0;c<t.length;c++)l.push(t[c]);return function(t,e,n){var r,o,i=-1;return function n(s){try{for(;++i<t.length;)if((s=e(i))&&s.then){if(!b(s))return void s.then(n,o||(o=k.bind(null,r=new S,2)));s=s.v}r?k(r,1,s):r=s}catch(t){k(r||(r=new S),2,t)}}(),r}(l,function(t){return e(l[t])})}(t,function(t){let{hook:o,handler:i,defaultHandler:s,once:a}=t;return Promise.resolve(f(i,[n.swup.visit,e,s])).then(function(t){r.push(t),a&&n.off(o,i)})});return Promise.resolve(o&&o.then?o.then(function(){return r}):r)}catch(t){return Promise.reject(t)}}runSync(t,e){const n=[];for(const{hook:r,handler:o,defaultHandler:i,once:s}of t){const t=o(this.swup.visit,e,i);n.push(t),d(t)&&console.warn(`Promise returned from handler for synchronous hook '${r}'.Swup will not wait for it to resolve.`),s&&this.off(r,o)}return n}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const r=this.sortRegistrations,o=Array.from(n.values()),i=o.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(r),s=o.filter(t=>{let{replace:e}=t;return e}).sort(r),a=o.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(r),l=s.length>0;let c=[];if(e&&(c=[{id:0,hook:t,handler:e}],l)){const n=s.length-1,r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};c=[{id:0,hook:t,handler:s[n].handler,defaultHandler:r(n)}]}return{found:!0,before:i,handler:c,after:a,replaced:l}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e){document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:{hook:t,args:e,visit:this.swup.visit}}))}}const x=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||h(`a[name='${v(t)}']`)||h(`a[name='${v(e)}']`);return n||"top"!==t||(n=document.body),n},E=function(t){let{elements:e,selector:n}=t;try{if(!1===n&&!e)return Promise.resolve();let t=[];if(e)t=Array.from(e);else if(n&&(t=m(n,document.body),!t.length))return console.warn(`[swup] No elements found matching animationSelector \`${n}\``),Promise.resolve();const r=t.map(t=>function(t){const{type:e,timeout:n,propCount:r}=function(t,e){const n=window.getComputedStyle(t),r=A(n,`${C}Delay`),o=A(n,`${C}Duration`),i=H(r,o),s=A(n,`${$}Delay`),a=A(n,`${$}Duration`),l=H(s,a);let c=null,u=0,h=0;return e===C?i>0&&(c=C,u=i,h=o.length):e===$?l>0&&(c=$,u=l,h=a.length):(u=Math.max(i,l),c=u>0?i>l?C:$:null,h=c?c===C?o.length:a.length:0),{type:c,timeout:u,propCount:h}}(t);return!(!e||!n)&&new Promise(o=>{const i=`${e}end`,s=performance.now();let a=0;const l=()=>{t.removeEventListener(i,c),o()},c=e=>{if(e.target===t){if(!function(t){return[`${C}end`,`${$}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-s)/1e3<e.elapsedTime||++a>=r&&l()}};setTimeout(()=>{a<r&&l()},n+1),t.addEventListener(i,c)})}(t));return r.filter(Boolean).length>0?Promise.resolve(Promise.all(r)).then(function(){}):(n&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${n}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},C="transition",$="animation";function A(t,e){return(t[e]||"").split(", ")}function H(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>g(e)+g(t[n])))}const q=function(t,e){void 0===e&&(e={});try{const n=this;if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");const{el:r}=n.visit.trigger;n.visit.to.url=c.fromUrl(t).url,e.referrer=e.referrer||n.currentPageUrl,!1===e.animate&&(n.visit.animation.animate=!1),n.visit.animation.animate||n.classes.clear();const o=e.history||r?.getAttribute("data-swup-history")||void 0;o&&["push","replace"].includes(o)&&(n.visit.history.action=o);const l=e.animation||r?.getAttribute("data-swup-animation")||void 0;return l&&(n.visit.animation.name=l),Promise.resolve(function(r,o){try{var l=Promise.resolve(n.hooks.call("visit:start")).then(function(){function r(){const t=n.animatePageOut();return Promise.resolve(Promise.all([o,t])).then(function(t){let[e]=t;return Promise.resolve(n.renderPage(n.visit.to.url,e)).then(function(){return Promise.resolve(n.animatePageIn()).then(function(){return Promise.resolve(n.hooks.call("visit:end",void 0,()=>n.classes.clear())).then(function(){})})})})}const o=n.hooks.call("page:load",{options:e},function(t,e){try{function r(t){return e.page=t,e.cache=!!o,e.page}const o=n.cache.get(t.to.url);return Promise.resolve(o?r(o):Promise.resolve(n.fetchPage(t.to.url,e.options)).then(r))}catch(i){return Promise.reject(i)}});if(!n.visit.history.popstate){const e=t+(n.visit.scroll.target||"");"replace"===n.visit.history.action?a(e):s(e,{index:n.currentHistoryIndex+1})}n.currentPageUrl=i();const l=function(){if(n.visit.animation.wait)return Promise.resolve(o).then(function(t){let{html:e}=t;n.visit.to.html=e})}();return l&&l.then?l.then(r):r()})}catch(t){return o(t)}return l&&l.then?l.then(void 0,o):l}(0,function(t){t&&(console.error(t),n.options.skipPopStateHandling=()=>(window.location.href=n.visit.to.url,!0),window.history.go(-1))}))}catch(t){return Promise.reject(t)}};function R(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void(window.location.href=t);const{url:r,hash:o}=c.fromUrl(t);this.visit=this.createVisit({...n,to:r,hash:o}),this.performNavigation(r,e)}const j=function(t,e){void 0===e&&(e={});try{const n=this;t=c.fromUrl(t).url;const r={...n.options.requestHeaders,...e.headers};return e={...e,headers:r},Promise.resolve(n.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(e){const{status:r,url:o}=e;return Promise.resolve(e.text()).then(function(i){if(500===r)throw n.hooks.call("fetch:error",{status:r,response:e,url:o}),new L(`Server error: ${o}`,{status:r,url:o});if(!i)throw new L(`Empty response: ${o}`,{status:r,url:o});const{url:s}=c.fromUrl(o),a={url:s,html:i};return t===s&&n.cache.set(a.url,a),a})})}catch(t){return Promise.reject(t)}};class L extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.name="FetchError",this.url=e.url,this.status=e.status}}const I=function(){try{let e;const n=this;function t(t){return e?t:Promise.resolve(n.hooks.call("animation:out:start",void 0,t=>{n.classes.add("is-changing","is-leaving","is-animating"),t.history.popstate&&n.classes.add("is-popstate"),t.animation.name&&n.classes.add(`to-${o(t.animation.name)}`)})).then(function(){return Promise.resolve(n.hooks.call("animation:out:await",{skip:!1},function(t,e){let{skip:r}=e;try{return r?Promise.resolve():Promise.resolve(n.awaitAnimations({selector:t.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(n.hooks.call("animation:out:end")).then(function(){})})})}const r=function(){if(!n.visit.animation.animate)return Promise.resolve(n.hooks.call("animation:skip")).then(function(){e=1})}();return Promise.resolve(r&&r.then?r.then(t):t(r))}catch(i){return Promise.reject(i)}},N=function(t,e){let{html:n}=t,{containers:r}=void 0===e?this.options:e;const o=(new DOMParser).parseFromString(n,"text/html"),i=o.querySelector("title")?.innerText||"";return document.title=i,r.map(t=>{const e=document.querySelector(t),n=o.querySelector(t);return e&&n?(e.replaceWith(n),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),n||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean).length===r.length},D=function(){const t={behavior:"auto"},{target:e,reset:n}=this.visit.scroll;let r=!1;return e&&(r=this.hooks.callSync("scroll:anchor",{hash:e,options:t},(t,e)=>{let{hash:n,options:r}=e;const o=this.getAnchorElement(n||"");return o&&o.scrollIntoView(r),!!o})),n&&!r&&(r=this.hooks.callSync("scroll:top",{options:t},(t,e)=>{let{options:n}=e;return window.scrollTo({top:0,left:0,...n}),!0})),r},V=function(){try{const t=this;if(!t.visit.animation.animate)return Promise.resolve();const e=t.hooks.call("animation:in:await",{skip:!1},function(e,n){let{skip:r}=n;try{return r?Promise.resolve():Promise.resolve(t.awaitAnimations({selector:e.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}});return Promise.resolve(p()).then(function(){return Promise.resolve(t.hooks.call("animation:in:start",void 0,()=>{t.classes.remove("is-animating")})).then(function(){return Promise.resolve(e).then(function(){return Promise.resolve(t.hooks.call("animation:in:end")).then(function(){})})})})}catch(t){return Promise.reject(t)}},M=function(t,e){try{const n=this,{url:r,html:s}=e;return n.classes.remove("is-leaving"),n.isSameResolvedUrl(i(),t)?(n.isSameResolvedUrl(i(),r)||(a(r),n.currentPageUrl=i(),n.visit.to.url=n.currentPageUrl),n.visit.animation.animate&&n.classes.add("is-rendering"),n.visit.to.html=s,Promise.resolve(n.hooks.call("content:replace",{page:e},(t,e)=>{let{page:r}=e;if(!n.replaceContent(r,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(n.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&n.classes.add(`to-${o(t.animation.name)}`))})).then(function(){return Promise.resolve(n.hooks.call("content:scroll",void 0,()=>n.scrollToContent())).then(function(){return Promise.resolve(n.hooks.call("page:view",{url:n.currentPageUrl,title:document.title})).then(function(){n.options.cache||n.cache.clear()})})})):Promise.resolve()}catch(t){return Promise.reject(t)}},T=function(t){var e;if(e=t,e?.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function W(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function _(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${t}`)}function B(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function O(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}exports.Location=c,exports.classify=o,exports.createHistoryRecord=s,exports.default=class{constructor(t){void 0===t&&(t={}),this.version="4.0.0-rc.28",this.options=void 0,this.plugins=[],this.cache=void 0,this.hooks=void 0,this.visit=void 0,this.classes=void 0,this.currentPageUrl=i(),this.getCurrentUrl=i,this.use=T,this.unuse=W,this.findPlugin=_,this.log=()=>{},this.getAnchorElement=x,this.navigate=R,this.performNavigation=q,this.delegateEvent=l,this.fetchPage=j,this.awaitAnimations=E,this.renderPage=M,this.replaceContent=N,this.animatePageIn=V,this.animatePageOut=I,this.scrollToContent=D,this.createVisit=y,this.resolveUrl=B,this.isSameResolvedUrl=O,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],ignoreVisit:function(t,e){let{el:n}=void 0===e?{}:e;return!!n?.closest("[data-no-swup]")},linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source},this.currentHistoryIndex=1,this.clickDelegate=void 0,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new u(this),this.classes=new w(this),this.hooks=new U(this),this.visit=this.createVisit({to:void 0}),this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}enable(){try{const t=this,{linkSelector:e}=t.options;return t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.plugins.forEach(e=>t.use(e)),a(null,{index:1}),Promise.resolve(p()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.options.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,e){let{el:n,event:r}=void 0===e?{}:e;const{origin:o,url:i,hash:s}=c.fromUrl(t);return o!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(i+s,{el:n,event:r})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:r,hash:o}=c.fromElement(e);this.shouldIgnoreVisit(n,{el:e,event:t})||(this.visit=this.createVisit({to:r,hash:o,el:e,event:t}),t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.call("link:newtab",{href:n}):0===t.button&&this.hooks.callSync("link:click",{el:e,event:t},()=>{const e=this.visit.from.url??"";t.preventDefault(),r&&r!==e?this.isSameResolvedUrl(r,e)||this.performNavigation(r):o?this.hooks.callSync("link:anchor",{hash:o},()=>{a(r+o),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>{this.scrollToContent()})}))}handlePopState(t){const e=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(i(),this.currentPageUrl))return;if(this.shouldIgnoreVisit(e,{event:t}))return;const{url:n,hash:r}=c.fromUrl(e);this.visit=this.createVisit({to:n,hash:r,event:t,animate:this.options.animateHistoryBrowsing,resetScroll:this.options.animateHistoryBrowsing}),this.visit.history.popstate=!0;const o=Number(t.state?.index);o&&(this.visit.history.direction=o-this.currentHistoryIndex>0?"forwards":"backwards"),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation(n)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}},exports.delegateEvent=l,exports.escapeCssIdentifier=v,exports.forceReflow=function(t){return t=t||document.body,t?.offsetHeight},exports.getCurrentUrl=i,exports.isPromise=d,exports.matchPath=(t,n)=>{try{return e.match(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${t}":\n${e}`)}},exports.nextTick=p,exports.query=h,exports.queryAll=m,exports.runAsPromise=f,exports.toMs=g,exports.updateHistoryRecord=a;
1
+ var t=require("delegate-it"),e=require("path-to-regexp");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=/*#__PURE__*/n(t);const o=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",i=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},s=function(t,e){void 0===e&&(e={});const n={url:t=t||i({hash:!0}),random:Math.random(),source:"swup",...e};history.pushState(n,"",t)},a=function(t,e){void 0===t&&(t=null),void 0===e&&(e={}),t=t||i({hash:!0});const n={...history.state,url:t,random:Math.random(),source:"swup",...e};history.replaceState(n,"",t)},l=(t,e,n,o)=>{const i=new AbortController;return o={...o,signal:i.signal},r.default(t,e,n,o),{destroy:()=>i.abort()}};class c extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new c(e)}static fromUrl(t){return new c(t)}}class u{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){return this.pages}has(t){return this.pages.has(this.resolve(t))}get(t){return this.pages.get(this.resolve(t))}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",{page:e})}update(t,e){t=this.resolve(t),e={...this.get(t),...e,url:t},this.pages.set(t,e)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear")}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=c.fromUrl(t);return this.swup.resolveUrl(e)}}const h=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},m=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},p=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function d(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function f(t,e){return void 0===e&&(e=[]),new Promise((n,r)=>{const o=t(...e);d(o)?o.then(n,r):n(o)})}const v=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,g=t=>1e3*Number(t.slice(0,-1).replace(",","."));class w{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?m(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}function y(t){let{to:e,from:n=this.currentPageUrl,hash:r,animate:o=!0,animation:i,el:s,event:a,action:l="push",resetScroll:c=!0}=t;return{from:{url:n},to:{url:e},containers:this.options.containers,animation:{animate:o,wait:!1,name:i,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:s,event:a},history:{action:l,popstate:!1,direction:void 0},scroll:{reset:c,target:r}}}const P="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function k(t,e,n){if(!t.s){if(n instanceof S){if(!n.s)return void(n.o=k.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(k.bind(null,t,e),k.bind(null,t,2));t.s=e,t.v=n;const r=t.o;r&&r(t)}}const S=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const r=new t,o=this.s;if(o){const t=1&o?e:n;if(t){try{k(r,1,t(this.v))}catch(t){k(r,2,t)}return r}return this}return this.o=function(t){try{const o=t.v;1&t.s?k(r,1,e?e(o):o):n?k(r,1,n(o)):k(r,2,o)}catch(t){k(r,2,t)}},r},t}();function b(t){return t instanceof S&&1&t.s}class U{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:end"],this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n){void 0===n&&(n={});const r=this.get(t);if(!r)return console.warn(`Hook '${t}' not found.`),()=>{};const o=r.size+1,i={...n,id:o,hook:t,handler:e};return r.set(e,i),()=>this.off(t,e)}before(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,before:!0})}replace(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,replace:!0})}once(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n){try{const r=this,{before:o,handler:i,after:s}=r.getHandlers(t,n);return Promise.resolve(r.run(o,e)).then(function(){return Promise.resolve(r.run(i,e)).then(function(n){let[o]=n;return Promise.resolve(r.run(s,e)).then(function(){return r.dispatchDomEvent(t,e),o})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n){const{before:r,handler:o,after:i}=this.getHandlers(t,n);this.runSync(r,e);const[s]=this.runSync(o,e);return this.runSync(i,e),this.dispatchDomEvent(t,e),s}run(t,e){try{const n=this,r=[],o=function(t,e,n){if("function"==typeof t[P]){var r,o,i,s=t[P]();if(function t(n){try{for(;!(r=s.next()).done;)if((n=e(r.value))&&n.then){if(!b(n))return void n.then(t,i||(i=k.bind(null,o=new S,2)));n=n.v}o?k(o,1,n):o=n}catch(t){k(o||(o=new S),2,t)}}(),s.return){var a=function(t){try{r.done||s.return()}catch(t){}return t};if(o&&o.then)return o.then(a,function(t){throw a(t)});a()}return o}if(!("length"in t))throw new TypeError("Object is not iterable");for(var l=[],c=0;c<t.length;c++)l.push(t[c]);return function(t,e,n){var r,o,i=-1;return function n(s){try{for(;++i<t.length;)if((s=e(i))&&s.then){if(!b(s))return void s.then(n,o||(o=k.bind(null,r=new S,2)));s=s.v}r?k(r,1,s):r=s}catch(t){k(r||(r=new S),2,t)}}(),r}(l,function(t){return e(l[t])})}(t,function(t){let{hook:o,handler:i,defaultHandler:s,once:a}=t;return Promise.resolve(f(i,[n.swup.visit,e,s])).then(function(t){r.push(t),a&&n.off(o,i)})});return Promise.resolve(o&&o.then?o.then(function(){return r}):r)}catch(t){return Promise.reject(t)}}runSync(t,e){const n=[];for(const{hook:r,handler:o,defaultHandler:i,once:s}of t){const t=o(this.swup.visit,e,i);n.push(t),d(t)&&console.warn(`Promise returned from handler for synchronous hook '${r}'.Swup will not wait for it to resolve.`),s&&this.off(r,o)}return n}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const r=this.sortRegistrations,o=Array.from(n.values()),i=o.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(r),s=o.filter(t=>{let{replace:e}=t;return e}).sort(r),a=o.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(r),l=s.length>0;let c=[];if(e&&(c=[{id:0,hook:t,handler:e}],l)){const n=s.length-1,r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};c=[{id:0,hook:t,handler:s[n].handler,defaultHandler:r(n)}]}return{found:!0,before:i,handler:c,after:a,replaced:l}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e){document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:{hook:t,args:e,visit:this.swup.visit}}))}}const x=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||h(`a[name='${v(t)}']`)||h(`a[name='${v(e)}']`);return n||"top"!==t||(n=document.body),n},E=function(t){let{elements:e,selector:n}=t;try{if(!1===n&&!e)return Promise.resolve();let t=[];if(e)t=Array.from(e);else if(n&&(t=m(n,document.body),!t.length))return console.warn(`[swup] No elements found matching animationSelector \`${n}\``),Promise.resolve();const r=t.map(t=>function(t){const{type:e,timeout:n,propCount:r}=function(t,e){const n=window.getComputedStyle(t),r=A(n,`${C}Delay`),o=A(n,`${C}Duration`),i=H(r,o),s=A(n,`${$}Delay`),a=A(n,`${$}Duration`),l=H(s,a);let c=null,u=0,h=0;return e===C?i>0&&(c=C,u=i,h=o.length):e===$?l>0&&(c=$,u=l,h=a.length):(u=Math.max(i,l),c=u>0?i>l?C:$:null,h=c?c===C?o.length:a.length:0),{type:c,timeout:u,propCount:h}}(t);return!(!e||!n)&&new Promise(o=>{const i=`${e}end`,s=performance.now();let a=0;const l=()=>{t.removeEventListener(i,c),o()},c=e=>{if(e.target===t){if(!function(t){return[`${C}end`,`${$}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-s)/1e3<e.elapsedTime||++a>=r&&l()}};setTimeout(()=>{a<r&&l()},n+1),t.addEventListener(i,c)})}(t));return r.filter(Boolean).length>0?Promise.resolve(Promise.all(r)).then(function(){}):(n&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${n}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},C="transition",$="animation";function A(t,e){return(t[e]||"").split(", ")}function H(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>g(e)+g(t[n])))}const q=function(t,e){void 0===e&&(e={});try{const n=this;if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");const{el:r}=n.visit.trigger;n.visit.to.url=c.fromUrl(t).url,e.referrer=e.referrer||n.currentPageUrl,!1===e.animate&&(n.visit.animation.animate=!1),n.visit.animation.animate||n.classes.clear();const o=e.history||r?.getAttribute("data-swup-history")||void 0;o&&["push","replace"].includes(o)&&(n.visit.history.action=o);const l=e.animation||r?.getAttribute("data-swup-animation")||void 0;return l&&(n.visit.animation.name=l),Promise.resolve(function(r,o){try{var l=Promise.resolve(n.hooks.call("visit:start")).then(function(){function r(){const t=n.animatePageOut();return Promise.resolve(Promise.all([o,t])).then(function(t){let[e]=t;return Promise.resolve(n.renderPage(n.visit.to.url,e)).then(function(){return Promise.resolve(n.animatePageIn()).then(function(){return Promise.resolve(n.hooks.call("visit:end",void 0,()=>n.classes.clear())).then(function(){})})})})}const o=n.hooks.call("page:load",{options:e},function(t,e){try{function r(t){return e.page=t,e.cache=!!o,e.page}const o=n.cache.get(t.to.url);return Promise.resolve(o?r(o):Promise.resolve(n.fetchPage(t.to.url,e.options)).then(r))}catch(i){return Promise.reject(i)}});if(!n.visit.history.popstate){const e=t+(n.visit.scroll.target||"");"replace"===n.visit.history.action?a(e):s(e,{index:n.currentHistoryIndex+1})}n.currentPageUrl=i();const l=function(){if(n.visit.animation.wait)return Promise.resolve(o).then(function(t){let{html:e}=t;n.visit.to.html=e})}();return l&&l.then?l.then(r):r()})}catch(t){return o(t)}return l&&l.then?l.then(void 0,o):l}(0,function(t){t&&(console.error(t),n.options.skipPopStateHandling=()=>(window.location.href=n.visit.to.url,!0),window.history.go(-1))}))}catch(t){return Promise.reject(t)}};function R(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void(window.location.href=t);const{url:r,hash:o}=c.fromUrl(t);this.visit=this.createVisit({...n,to:r,hash:o}),this.performNavigation(r,e)}const j=function(t,e){void 0===e&&(e={});try{const n=this;t=c.fromUrl(t).url;const r={...n.options.requestHeaders,...e.headers};return e={...e,headers:r},Promise.resolve(n.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(e){const{status:r,url:o}=e;return Promise.resolve(e.text()).then(function(i){if(500===r)throw n.hooks.call("fetch:error",{status:r,response:e,url:o}),new L(`Server error: ${o}`,{status:r,url:o});if(!i)throw new L(`Empty response: ${o}`,{status:r,url:o});const{url:s}=c.fromUrl(o),a={url:s,html:i};return t===s&&n.cache.set(a.url,a),a})})}catch(t){return Promise.reject(t)}};class L extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.name="FetchError",this.url=e.url,this.status=e.status}}const I=function(){try{let e;const n=this;function t(t){return e?t:Promise.resolve(n.hooks.call("animation:out:start",void 0,t=>{n.classes.add("is-changing","is-leaving","is-animating"),t.history.popstate&&n.classes.add("is-popstate"),t.animation.name&&n.classes.add(`to-${o(t.animation.name)}`)})).then(function(){return Promise.resolve(n.hooks.call("animation:out:await",{skip:!1},function(t,e){let{skip:r}=e;try{return r?Promise.resolve():Promise.resolve(n.awaitAnimations({selector:t.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(n.hooks.call("animation:out:end")).then(function(){})})})}const r=function(){if(!n.visit.animation.animate)return Promise.resolve(n.hooks.call("animation:skip")).then(function(){e=1})}();return Promise.resolve(r&&r.then?r.then(t):t(r))}catch(i){return Promise.reject(i)}},N=function(t,e){let{html:n}=t,{containers:r}=void 0===e?this.options:e;const o=(new DOMParser).parseFromString(n,"text/html"),i=o.querySelector("title")?.innerText||"";return document.title=i,r.map(t=>{const e=document.querySelector(t),n=o.querySelector(t);return e&&n?(e.replaceWith(n),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),n||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean).length===r.length},D=function(){const t={behavior:"auto"},{target:e,reset:n}=this.visit.scroll;let r=!1;return e&&(r=this.hooks.callSync("scroll:anchor",{hash:e,options:t},(t,e)=>{let{hash:n,options:r}=e;const o=this.getAnchorElement(n||"");return o&&o.scrollIntoView(r),!!o})),n&&!r&&(r=this.hooks.callSync("scroll:top",{options:t},(t,e)=>{let{options:n}=e;return window.scrollTo({top:0,left:0,...n}),!0})),r},V=function(){try{const t=this;if(!t.visit.animation.animate)return Promise.resolve();const e=t.hooks.call("animation:in:await",{skip:!1},function(e,n){let{skip:r}=n;try{return r?Promise.resolve():Promise.resolve(t.awaitAnimations({selector:e.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}});return Promise.resolve(p()).then(function(){return Promise.resolve(t.hooks.call("animation:in:start",void 0,()=>{t.classes.remove("is-animating")})).then(function(){return Promise.resolve(e).then(function(){return Promise.resolve(t.hooks.call("animation:in:end")).then(function(){})})})})}catch(t){return Promise.reject(t)}},M=function(t,e){try{const n=this,{url:r,html:s}=e;return n.classes.remove("is-leaving"),n.isSameResolvedUrl(i(),t)?(n.isSameResolvedUrl(i(),r)||(a(r),n.currentPageUrl=i(),n.visit.to.url=n.currentPageUrl),n.visit.animation.animate&&n.classes.add("is-rendering"),n.visit.to.html=s,Promise.resolve(n.hooks.call("content:replace",{page:e},(t,e)=>{let{page:r}=e;if(!n.replaceContent(r,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(n.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&n.classes.add(`to-${o(t.animation.name)}`))})).then(function(){return Promise.resolve(n.hooks.call("content:scroll",void 0,()=>n.scrollToContent())).then(function(){return Promise.resolve(n.hooks.call("page:view",{url:n.currentPageUrl,title:document.title})).then(function(){n.options.cache||n.cache.clear()})})})):Promise.resolve()}catch(t){return Promise.reject(t)}},T=function(t){var e;if(e=t,e?.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function W(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function _(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${t}`)}function B(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function O(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}exports.Location=c,exports.classify=o,exports.createHistoryRecord=s,exports.default=class{constructor(t){void 0===t&&(t={}),this.version="4.0.0-rc.30",this.options=void 0,this.plugins=[],this.cache=void 0,this.hooks=void 0,this.visit=void 0,this.classes=void 0,this.currentPageUrl=i(),this.getCurrentUrl=i,this.use=T,this.unuse=W,this.findPlugin=_,this.log=()=>{},this.getAnchorElement=x,this.navigate=R,this.performNavigation=q,this.delegateEvent=l,this.fetchPage=j,this.awaitAnimations=E,this.renderPage=M,this.replaceContent=N,this.animatePageIn=V,this.animatePageOut=I,this.scrollToContent=D,this.createVisit=y,this.resolveUrl=B,this.isSameResolvedUrl=O,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],ignoreVisit:function(t,e){let{el:n}=void 0===e?{}:e;return!!n?.closest("[data-no-swup]")},linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source},this.currentHistoryIndex=1,this.clickDelegate=void 0,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new u(this),this.classes=new w(this),this.hooks=new U(this),this.visit=this.createVisit({to:void 0}),this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}enable(){try{const t=this,{linkSelector:e}=t.options;return t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.plugins.forEach(e=>t.use(e)),a(null,{index:1}),Promise.resolve(p()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.options.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,e){let{el:n,event:r}=void 0===e?{}:e;const{origin:o,url:i,hash:s}=c.fromUrl(t);return o!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(i+s,{el:n,event:r})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:r,hash:o}=c.fromElement(e);this.shouldIgnoreVisit(n,{el:e,event:t})||(this.visit=this.createVisit({to:r,hash:o,el:e,event:t}),t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.call("link:newtab",{href:n}):0===t.button&&this.hooks.callSync("link:click",{el:e,event:t},()=>{const e=this.visit.from.url??"";t.preventDefault(),r&&r!==e?this.isSameResolvedUrl(r,e)||this.performNavigation(r):o?this.hooks.callSync("link:anchor",{hash:o},()=>{a(r+o),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>{this.scrollToContent()})}))}handlePopState(t){const e=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(i(),this.currentPageUrl))return;if(this.shouldIgnoreVisit(e,{event:t}))return;const{url:n,hash:r}=c.fromUrl(e);this.visit=this.createVisit({to:n,hash:r,event:t,animate:this.options.animateHistoryBrowsing,resetScroll:this.options.animateHistoryBrowsing}),this.visit.history.popstate=!0;const o=Number(t.state?.index);o&&(this.visit.history.direction=o-this.currentHistoryIndex>0?"forwards":"backwards"),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation(n)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}},exports.delegateEvent=l,exports.escapeCssIdentifier=v,exports.forceReflow=function(t){return t=t||document.body,t?.offsetHeight},exports.getCurrentUrl=i,exports.isPromise=d,exports.matchPath=(t,n)=>{try{return e.match(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${t}":\n${e}`)}},exports.nextTick=p,exports.query=h,exports.queryAll=m,exports.runAsPromise=f,exports.toMs=g,exports.updateHistoryRecord=a;
2
2
  //# sourceMappingURL=Swup.cjs.map
@@ -1,2 +1,2 @@
1
- import t from"delegate-it";import{match as e}from"path-to-regexp";function i(){return i=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},i.apply(this,arguments)}const s=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",n=({hash:t}={})=>location.pathname+location.search+(t?location.hash:""),o=(t,e={})=>{const s=i({url:t=t||n({hash:!0}),random:Math.random(),source:"swup"},e);history.pushState(s,"",t)},r=(t=null,e={})=>{t=t||n({hash:!0});const s=i({},history.state,{url:t,random:Math.random(),source:"swup"},e);history.replaceState(s,"",t)},a=(e,s,n,o)=>{const r=new AbortController;return o=i({},o,{signal:r.signal}),t(e,s,n,o),{destroy:()=>r.abort()}};class l extends URL{constructor(t,e=document.baseURI){super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new l(e)}static fromUrl(t){return new l(t)}}const h=(t,i)=>{try{return e(t,i)}catch(e){throw new Error(`[swup] Error parsing path "${t}":\n${e}`)}};class c{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){return this.pages}has(t){return this.pages.has(this.resolve(t))}get(t){return this.pages.get(this.resolve(t))}set(t,e){e=i({},e,{url:t=this.resolve(t)}),this.pages.set(t,e),this.swup.hooks.callSync("cache:set",{page:e})}update(t,e){t=this.resolve(t),e=i({},this.get(t),e,{url:t}),this.pages.set(t,e)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear")}prune(t){this.pages.forEach((e,i)=>{t(i,e)&&this.delete(i)})}resolve(t){const{url:e}=l.fromUrl(t);return this.swup.resolveUrl(e)}}const u=(t,e=document)=>e.querySelector(t),p=(t,e=document)=>Array.from(e.querySelectorAll(t)),d=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function m(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function g(t,e=[]){return new Promise((i,s)=>{const n=t(...e);m(n)?n.then(i,s):i(n)})}function f(t){var e;return null==(e=t=t||document.body)?void 0:e.offsetHeight}const w=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,v=t=>1e3*Number(t.slice(0,-1).replace(",","."));class y{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?p(this.selector):[]}add(...t){this.targets.forEach(e=>e.classList.add(...t))}remove(...t){this.targets.forEach(e=>e.classList.remove(...t))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}function k({to:t,from:e=this.currentPageUrl,hash:i,animate:s=!0,animation:n,el:o,event:r,action:a="push",resetScroll:l=!0}){return{from:{url:e},to:{url:t},containers:this.options.containers,animation:{animate:s,wait:!1,name:n,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:o,event:r},history:{action:a,popstate:!1,direction:void 0},scroll:{reset:l,target:i}}}class S{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:end"],this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,s={}){const n=this.get(t);if(!n)return console.warn(`Hook '${t}' not found.`),()=>{};const o=i({},s,{id:n.size+1,hook:t,handler:e});return n.set(e,o),()=>this.off(t,e)}before(t,e,s={}){return this.on(t,e,i({},s,{before:!0}))}replace(t,e,s={}){return this.on(t,e,i({},s,{replace:!0}))}once(t,e,s={}){return this.on(t,e,i({},s,{once:!0}))}off(t,e){const i=this.get(t);i&&e?i.delete(e)||console.warn(`Handler for hook '${t}' not found.`):i&&i.clear()}async call(t,e,i){const{before:s,handler:n,after:o}=this.getHandlers(t,i);await this.run(s,e);const[r]=await this.run(n,e);return await this.run(o,e),this.dispatchDomEvent(t,e),r}callSync(t,e,i){const{before:s,handler:n,after:o}=this.getHandlers(t,i);this.runSync(s,e);const[r]=this.runSync(n,e);return this.runSync(o,e),this.dispatchDomEvent(t,e),r}async run(t,e){const i=[];for(const{hook:s,handler:n,defaultHandler:o,once:r}of t){const t=await g(n,[this.swup.visit,e,o]);i.push(t),r&&this.off(s,n)}return i}runSync(t,e){const i=[];for(const{hook:s,handler:n,defaultHandler:o,once:r}of t){const t=n(this.swup.visit,e,o);i.push(t),m(t)&&console.warn(`Promise returned from handler for synchronous hook '${s}'.Swup will not wait for it to resolve.`),r&&this.off(s,n)}return i}getHandlers(t,e){const i=this.get(t);if(!i)return{found:!1,before:[],handler:[],after:[],replaced:!1};const s=this.sortRegistrations,n=Array.from(i.values()),o=n.filter(({before:t,replace:e})=>t&&!e).sort(s),r=n.filter(({replace:t})=>t).sort(s),a=n.filter(({before:t,replace:e})=>!t&&!e).sort(s),l=r.length>0;let h=[];if(e&&(h=[{id:0,hook:t,handler:e}],l)){const i=r.length-1,s=t=>{const i=r[t-1];return i?(e,n)=>i.handler(e,n,s(t-1)):e};h=[{id:0,hook:t,handler:r[i].handler,defaultHandler:s(i)}]}return{found:!0,before:o,handler:h,after:a,replaced:l}}sortRegistrations(t,e){var i,s;return(null!=(i=t.priority)?i:0)-(null!=(s=e.priority)?s:0)||t.id-e.id||0}dispatchDomEvent(t,e){document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:{hook:t,args:e,visit:this.swup.visit}}))}}const b=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let i=document.getElementById(t)||document.getElementById(e)||u(`a[name='${w(t)}']`)||u(`a[name='${w(e)}']`);return i||"top"!==t||(i=document.body),i},U="transition",P="animation";async function E({elements:t,selector:e}){if(!1===e&&!t)return;let i=[];if(t)i=Array.from(t);else if(e&&(i=p(e,document.body),!i.length))return void console.warn(`[swup] No elements found matching animationSelector \`${e}\``);const s=i.map(t=>function(t){const{type:e,timeout:i,propCount:s}=function(t,e){const i=window.getComputedStyle(t),s=C(i,`${U}Delay`),n=C(i,`${U}Duration`),o=$(s,n),r=C(i,`${P}Delay`),a=C(i,`${P}Duration`),l=$(r,a);let h=null,c=0,u=0;return c=Math.max(o,l),h=c>0?o>l?U:P:null,u=h?h===U?n.length:a.length:0,{type:h,timeout:c,propCount:u}}(t);return!(!e||!i)&&new Promise(n=>{const o=`${e}end`,r=performance.now();let a=0;const l=()=>{t.removeEventListener(o,h),n()},h=e=>{if(e.target===t){if(!function(t){return[`${U}end`,`${P}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-r)/1e3<e.elapsedTime||++a>=s&&l()}};setTimeout(()=>{a<s&&l()},i+1),t.addEventListener(o,h)})}(t));s.filter(Boolean).length>0?await Promise.all(s):e&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${e}\``)}function C(t,e){return(t[e]||"").split(", ")}function $(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,i)=>v(e)+v(t[i])))}function x(t,e={},s={}){if(this.shouldIgnoreVisit(t,{el:s.el,event:s.event}))return void(window.location.href=t);const{url:n,hash:o}=l.fromUrl(t);this.visit=this.createVisit(i({},s,{to:n,hash:o})),this.performNavigation(n,e)}async function A(t,e={}){if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");const{el:i}=this.visit.trigger;this.visit.to.url=l.fromUrl(t).url,e.referrer=e.referrer||this.currentPageUrl,!1===e.animate&&(this.visit.animation.animate=!1),this.visit.animation.animate||this.classes.clear();const s=e.history||(null==i?void 0:i.getAttribute("data-swup-history"))||void 0;s&&["push","replace"].includes(s)&&(this.visit.history.action=s);const a=e.animation||(null==i?void 0:i.getAttribute("data-swup-animation"))||void 0;a&&(this.visit.animation.name=a);try{await this.hooks.call("visit:start");const i=this.hooks.call("page:load",{options:e},async(t,e)=>{const i=this.cache.get(t.to.url);return e.page=i||await this.fetchPage(t.to.url,e.options),e.cache=!!i,e.page});if(!this.visit.history.popstate){const e=t+(this.visit.scroll.target||"");"replace"===this.visit.history.action?r(e):o(e,{index:this.currentHistoryIndex+1})}if(this.currentPageUrl=n(),this.visit.animation.wait){const{html:t}=await i;this.visit.to.html=t}const s=this.animatePageOut(),[a]=await Promise.all([i,s]);await this.renderPage(this.visit.to.url,a),await this.animatePageIn(),await this.hooks.call("visit:end",void 0,()=>this.classes.clear())}catch(t){if(!t)return;console.error(t),this.options.skipPopStateHandling=()=>(window.location.href=this.visit.to.url,!0),window.history.go(-1)}}class H extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.name="FetchError",this.url=e.url,this.status=e.status}}async function q(t,e={}){t=l.fromUrl(t).url;const s=i({},this.options.requestHeaders,e.headers);e=i({},e,{headers:s});const n=await this.hooks.call("fetch:request",{url:t,options:e},(t,{url:e,options:i})=>fetch(e,i)),{status:o,url:r}=n,a=await n.text();if(500===o)throw this.hooks.call("fetch:error",{status:o,response:n,url:r}),new H(`Server error: ${r}`,{status:o,url:r});if(!a)throw new H(`Empty response: ${r}`,{status:o,url:r});const{url:h}=l.fromUrl(r),c={url:h,html:a};return t===h&&this.cache.set(c.url,c),c}const L=async function(){this.visit.animation.animate?(await this.hooks.call("animation:out:start",void 0,t=>{this.classes.add("is-changing","is-leaving","is-animating"),t.history.popstate&&this.classes.add("is-popstate"),t.animation.name&&this.classes.add(`to-${s(t.animation.name)}`)}),await this.hooks.call("animation:out:await",{skip:!1},async(t,{skip:e})=>{e||await this.awaitAnimations({selector:t.animation.selector})}),await this.hooks.call("animation:out:end")):await this.hooks.call("animation:skip")},R=function({html:t},{containers:e}=this.options){var i;const s=(new DOMParser).parseFromString(t,"text/html"),n=(null==(i=s.querySelector("title"))?void 0:i.innerText)||"";return document.title=n,e.map(t=>{const e=document.querySelector(t),i=s.querySelector(t);return e&&i?(e.replaceWith(i),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),i||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean).length===e.length},I=function(){const t={behavior:"auto"},{target:e,reset:s}=this.visit.scroll;let n=!1;return e&&(n=this.hooks.callSync("scroll:anchor",{hash:e,options:t},(t,{hash:e,options:i})=>{const s=this.getAnchorElement(e||"");return s&&s.scrollIntoView(i),!!s})),s&&!n&&(n=this.hooks.callSync("scroll:top",{options:t},(t,{options:e})=>(window.scrollTo(i({top:0,left:0},e)),!0))),n},N=async function(){if(!this.visit.animation.animate)return;const t=this.hooks.call("animation:in:await",{skip:!1},async(t,{skip:e})=>{e||await this.awaitAnimations({selector:t.animation.selector})});await d(),await this.hooks.call("animation:in:start",void 0,()=>{this.classes.remove("is-animating")}),await t,await this.hooks.call("animation:in:end")},D=async function(t,e){const{url:i,html:o}=e;this.classes.remove("is-leaving"),this.isSameResolvedUrl(n(),t)&&(this.isSameResolvedUrl(n(),i)||(r(i),this.currentPageUrl=n(),this.visit.to.url=this.currentPageUrl),this.visit.animation.animate&&this.classes.add("is-rendering"),this.visit.to.html=o,await this.hooks.call("content:replace",{page:e},(t,{page:e})=>{if(!this.replaceContent(e,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(this.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&this.classes.add(`to-${s(t.animation.name)}`))}),await this.hooks.call("content:scroll",void 0,()=>this.scrollToContent()),await this.hooks.call("page:view",{url:this.currentPageUrl,title:document.title}),this.options.cache||this.cache.clear())},V=function(t){var e;if(null==(e=t)?void 0:e.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function M(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function O(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${t}`)}function T(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function W(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}class _{constructor(t={}){this.version="4.0.0-rc.28",this.options=void 0,this.plugins=[],this.cache=void 0,this.hooks=void 0,this.visit=void 0,this.classes=void 0,this.currentPageUrl=n(),this.getCurrentUrl=n,this.use=V,this.unuse=M,this.findPlugin=O,this.log=()=>{},this.getAnchorElement=b,this.navigate=x,this.performNavigation=A,this.delegateEvent=a,this.fetchPage=q,this.awaitAnimations=E,this.renderPage=D,this.replaceContent=R,this.animatePageIn=N,this.animatePageOut=L,this.scrollToContent=I,this.createVisit=k,this.resolveUrl=T,this.isSameResolvedUrl=W,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],ignoreVisit:(t,{el:e}={})=>!(null==e||!e.closest("[data-no-swup]")),linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>{var e;return"swup"!==(null==(e=t.state)?void 0:e.source)}},this.currentHistoryIndex=1,this.clickDelegate=void 0,this.options=i({},this.defaults,t),this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new c(this),this.classes=new y(this),this.hooks=new S(this),this.visit=this.createVisit({to:void 0}),this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}async enable(){const{linkSelector:t}=this.options;this.clickDelegate=this.delegateEvent(t,"click",this.handleLinkClick),window.addEventListener("popstate",this.handlePopState),this.options.plugins.forEach(t=>this.use(t)),r(null,{index:1}),await d(),await this.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})}async destroy(){this.clickDelegate.destroy(),window.removeEventListener("popstate",this.handlePopState),this.cache.clear(),this.options.plugins.forEach(t=>this.unuse(t)),await this.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")}),this.hooks.clear()}shouldIgnoreVisit(t,{el:e,event:i}={}){const{origin:s,url:n,hash:o}=l.fromUrl(t);return s!==window.location.origin||!(!e||!this.triggerWillOpenNewWindow(e))||!!this.options.ignoreVisit(n+o,{el:e,event:i})}handleLinkClick(t){const e=t.delegateTarget,{href:i,url:s,hash:n}=l.fromElement(e);this.shouldIgnoreVisit(i,{el:e,event:t})||(this.visit=this.createVisit({to:s,hash:n,el:e,event:t}),t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.call("link:newtab",{href:i}):0===t.button&&this.hooks.callSync("link:click",{el:e,event:t},()=>{var e;const i=null!=(e=this.visit.from.url)?e:"";t.preventDefault(),s&&s!==i?this.isSameResolvedUrl(s,i)||this.performNavigation(s):n?this.hooks.callSync("link:anchor",{hash:n},()=>{r(s+n),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>{this.scrollToContent()})}))}handlePopState(t){var e,i,s;const o=null!=(e=null==(i=t.state)?void 0:i.url)?e:location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(n(),this.currentPageUrl))return;if(this.shouldIgnoreVisit(o,{event:t}))return;const{url:r,hash:a}=l.fromUrl(o);this.visit=this.createVisit({to:r,hash:a,event:t,animate:this.options.animateHistoryBrowsing,resetScroll:this.options.animateHistoryBrowsing}),this.visit.history.popstate=!0;const h=Number(null==(s=t.state)?void 0:s.index);h&&(this.visit.history.direction=h-this.currentHistoryIndex>0?"forwards":"backwards"),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation(r)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}export{l as Location,s as classify,o as createHistoryRecord,_ as default,a as delegateEvent,w as escapeCssIdentifier,f as forceReflow,n as getCurrentUrl,m as isPromise,h as matchPath,d as nextTick,u as query,p as queryAll,g as runAsPromise,v as toMs,r as updateHistoryRecord};
1
+ import t from"delegate-it";import{match as e}from"path-to-regexp";function i(){return i=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},i.apply(this,arguments)}const s=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",n=({hash:t}={})=>location.pathname+location.search+(t?location.hash:""),o=(t,e={})=>{const s=i({url:t=t||n({hash:!0}),random:Math.random(),source:"swup"},e);history.pushState(s,"",t)},r=(t=null,e={})=>{t=t||n({hash:!0});const s=i({},history.state,{url:t,random:Math.random(),source:"swup"},e);history.replaceState(s,"",t)},a=(e,s,n,o)=>{const r=new AbortController;return o=i({},o,{signal:r.signal}),t(e,s,n,o),{destroy:()=>r.abort()}};class l extends URL{constructor(t,e=document.baseURI){super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new l(e)}static fromUrl(t){return new l(t)}}const h=(t,i)=>{try{return e(t,i)}catch(e){throw new Error(`[swup] Error parsing path "${t}":\n${e}`)}};class c{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){return this.pages}has(t){return this.pages.has(this.resolve(t))}get(t){return this.pages.get(this.resolve(t))}set(t,e){e=i({},e,{url:t=this.resolve(t)}),this.pages.set(t,e),this.swup.hooks.callSync("cache:set",{page:e})}update(t,e){t=this.resolve(t),e=i({},this.get(t),e,{url:t}),this.pages.set(t,e)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear")}prune(t){this.pages.forEach((e,i)=>{t(i,e)&&this.delete(i)})}resolve(t){const{url:e}=l.fromUrl(t);return this.swup.resolveUrl(e)}}const u=(t,e=document)=>e.querySelector(t),p=(t,e=document)=>Array.from(e.querySelectorAll(t)),d=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function m(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function g(t,e=[]){return new Promise((i,s)=>{const n=t(...e);m(n)?n.then(i,s):i(n)})}function f(t){var e;return null==(e=t=t||document.body)?void 0:e.offsetHeight}const w=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,v=t=>1e3*Number(t.slice(0,-1).replace(",","."));class y{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?p(this.selector):[]}add(...t){this.targets.forEach(e=>e.classList.add(...t))}remove(...t){this.targets.forEach(e=>e.classList.remove(...t))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}function k({to:t,from:e=this.currentPageUrl,hash:i,animate:s=!0,animation:n,el:o,event:r,action:a="push",resetScroll:l=!0}){return{from:{url:e},to:{url:t},containers:this.options.containers,animation:{animate:s,wait:!1,name:n,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:o,event:r},history:{action:a,popstate:!1,direction:void 0},scroll:{reset:l,target:i}}}class S{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:end"],this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,s={}){const n=this.get(t);if(!n)return console.warn(`Hook '${t}' not found.`),()=>{};const o=i({},s,{id:n.size+1,hook:t,handler:e});return n.set(e,o),()=>this.off(t,e)}before(t,e,s={}){return this.on(t,e,i({},s,{before:!0}))}replace(t,e,s={}){return this.on(t,e,i({},s,{replace:!0}))}once(t,e,s={}){return this.on(t,e,i({},s,{once:!0}))}off(t,e){const i=this.get(t);i&&e?i.delete(e)||console.warn(`Handler for hook '${t}' not found.`):i&&i.clear()}async call(t,e,i){const{before:s,handler:n,after:o}=this.getHandlers(t,i);await this.run(s,e);const[r]=await this.run(n,e);return await this.run(o,e),this.dispatchDomEvent(t,e),r}callSync(t,e,i){const{before:s,handler:n,after:o}=this.getHandlers(t,i);this.runSync(s,e);const[r]=this.runSync(n,e);return this.runSync(o,e),this.dispatchDomEvent(t,e),r}async run(t,e){const i=[];for(const{hook:s,handler:n,defaultHandler:o,once:r}of t){const t=await g(n,[this.swup.visit,e,o]);i.push(t),r&&this.off(s,n)}return i}runSync(t,e){const i=[];for(const{hook:s,handler:n,defaultHandler:o,once:r}of t){const t=n(this.swup.visit,e,o);i.push(t),m(t)&&console.warn(`Promise returned from handler for synchronous hook '${s}'.Swup will not wait for it to resolve.`),r&&this.off(s,n)}return i}getHandlers(t,e){const i=this.get(t);if(!i)return{found:!1,before:[],handler:[],after:[],replaced:!1};const s=this.sortRegistrations,n=Array.from(i.values()),o=n.filter(({before:t,replace:e})=>t&&!e).sort(s),r=n.filter(({replace:t})=>t).sort(s),a=n.filter(({before:t,replace:e})=>!t&&!e).sort(s),l=r.length>0;let h=[];if(e&&(h=[{id:0,hook:t,handler:e}],l)){const i=r.length-1,s=t=>{const i=r[t-1];return i?(e,n)=>i.handler(e,n,s(t-1)):e};h=[{id:0,hook:t,handler:r[i].handler,defaultHandler:s(i)}]}return{found:!0,before:o,handler:h,after:a,replaced:l}}sortRegistrations(t,e){var i,s;return(null!=(i=t.priority)?i:0)-(null!=(s=e.priority)?s:0)||t.id-e.id||0}dispatchDomEvent(t,e){document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:{hook:t,args:e,visit:this.swup.visit}}))}}const b=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let i=document.getElementById(t)||document.getElementById(e)||u(`a[name='${w(t)}']`)||u(`a[name='${w(e)}']`);return i||"top"!==t||(i=document.body),i},U="transition",P="animation";async function E({elements:t,selector:e}){if(!1===e&&!t)return;let i=[];if(t)i=Array.from(t);else if(e&&(i=p(e,document.body),!i.length))return void console.warn(`[swup] No elements found matching animationSelector \`${e}\``);const s=i.map(t=>function(t){const{type:e,timeout:i,propCount:s}=function(t,e){const i=window.getComputedStyle(t),s=C(i,`${U}Delay`),n=C(i,`${U}Duration`),o=$(s,n),r=C(i,`${P}Delay`),a=C(i,`${P}Duration`),l=$(r,a);let h=null,c=0,u=0;return c=Math.max(o,l),h=c>0?o>l?U:P:null,u=h?h===U?n.length:a.length:0,{type:h,timeout:c,propCount:u}}(t);return!(!e||!i)&&new Promise(n=>{const o=`${e}end`,r=performance.now();let a=0;const l=()=>{t.removeEventListener(o,h),n()},h=e=>{if(e.target===t){if(!function(t){return[`${U}end`,`${P}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-r)/1e3<e.elapsedTime||++a>=s&&l()}};setTimeout(()=>{a<s&&l()},i+1),t.addEventListener(o,h)})}(t));s.filter(Boolean).length>0?await Promise.all(s):e&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${e}\``)}function C(t,e){return(t[e]||"").split(", ")}function $(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,i)=>v(e)+v(t[i])))}function x(t,e={},s={}){if(this.shouldIgnoreVisit(t,{el:s.el,event:s.event}))return void(window.location.href=t);const{url:n,hash:o}=l.fromUrl(t);this.visit=this.createVisit(i({},s,{to:n,hash:o})),this.performNavigation(n,e)}async function A(t,e={}){if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");const{el:i}=this.visit.trigger;this.visit.to.url=l.fromUrl(t).url,e.referrer=e.referrer||this.currentPageUrl,!1===e.animate&&(this.visit.animation.animate=!1),this.visit.animation.animate||this.classes.clear();const s=e.history||(null==i?void 0:i.getAttribute("data-swup-history"))||void 0;s&&["push","replace"].includes(s)&&(this.visit.history.action=s);const a=e.animation||(null==i?void 0:i.getAttribute("data-swup-animation"))||void 0;a&&(this.visit.animation.name=a);try{await this.hooks.call("visit:start");const i=this.hooks.call("page:load",{options:e},async(t,e)=>{const i=this.cache.get(t.to.url);return e.page=i||await this.fetchPage(t.to.url,e.options),e.cache=!!i,e.page});if(!this.visit.history.popstate){const e=t+(this.visit.scroll.target||"");"replace"===this.visit.history.action?r(e):o(e,{index:this.currentHistoryIndex+1})}if(this.currentPageUrl=n(),this.visit.animation.wait){const{html:t}=await i;this.visit.to.html=t}const s=this.animatePageOut(),[a]=await Promise.all([i,s]);await this.renderPage(this.visit.to.url,a),await this.animatePageIn(),await this.hooks.call("visit:end",void 0,()=>this.classes.clear())}catch(t){if(!t)return;console.error(t),this.options.skipPopStateHandling=()=>(window.location.href=this.visit.to.url,!0),window.history.go(-1)}}class H extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.name="FetchError",this.url=e.url,this.status=e.status}}async function q(t,e={}){t=l.fromUrl(t).url;const s=i({},this.options.requestHeaders,e.headers);e=i({},e,{headers:s});const n=await this.hooks.call("fetch:request",{url:t,options:e},(t,{url:e,options:i})=>fetch(e,i)),{status:o,url:r}=n,a=await n.text();if(500===o)throw this.hooks.call("fetch:error",{status:o,response:n,url:r}),new H(`Server error: ${r}`,{status:o,url:r});if(!a)throw new H(`Empty response: ${r}`,{status:o,url:r});const{url:h}=l.fromUrl(r),c={url:h,html:a};return t===h&&this.cache.set(c.url,c),c}const L=async function(){this.visit.animation.animate?(await this.hooks.call("animation:out:start",void 0,t=>{this.classes.add("is-changing","is-leaving","is-animating"),t.history.popstate&&this.classes.add("is-popstate"),t.animation.name&&this.classes.add(`to-${s(t.animation.name)}`)}),await this.hooks.call("animation:out:await",{skip:!1},async(t,{skip:e})=>{e||await this.awaitAnimations({selector:t.animation.selector})}),await this.hooks.call("animation:out:end")):await this.hooks.call("animation:skip")},R=function({html:t},{containers:e}=this.options){var i;const s=(new DOMParser).parseFromString(t,"text/html"),n=(null==(i=s.querySelector("title"))?void 0:i.innerText)||"";return document.title=n,e.map(t=>{const e=document.querySelector(t),i=s.querySelector(t);return e&&i?(e.replaceWith(i),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),i||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean).length===e.length},I=function(){const t={behavior:"auto"},{target:e,reset:s}=this.visit.scroll;let n=!1;return e&&(n=this.hooks.callSync("scroll:anchor",{hash:e,options:t},(t,{hash:e,options:i})=>{const s=this.getAnchorElement(e||"");return s&&s.scrollIntoView(i),!!s})),s&&!n&&(n=this.hooks.callSync("scroll:top",{options:t},(t,{options:e})=>(window.scrollTo(i({top:0,left:0},e)),!0))),n},N=async function(){if(!this.visit.animation.animate)return;const t=this.hooks.call("animation:in:await",{skip:!1},async(t,{skip:e})=>{e||await this.awaitAnimations({selector:t.animation.selector})});await d(),await this.hooks.call("animation:in:start",void 0,()=>{this.classes.remove("is-animating")}),await t,await this.hooks.call("animation:in:end")},D=async function(t,e){const{url:i,html:o}=e;this.classes.remove("is-leaving"),this.isSameResolvedUrl(n(),t)&&(this.isSameResolvedUrl(n(),i)||(r(i),this.currentPageUrl=n(),this.visit.to.url=this.currentPageUrl),this.visit.animation.animate&&this.classes.add("is-rendering"),this.visit.to.html=o,await this.hooks.call("content:replace",{page:e},(t,{page:e})=>{if(!this.replaceContent(e,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(this.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&this.classes.add(`to-${s(t.animation.name)}`))}),await this.hooks.call("content:scroll",void 0,()=>this.scrollToContent()),await this.hooks.call("page:view",{url:this.currentPageUrl,title:document.title}),this.options.cache||this.cache.clear())},V=function(t){var e;if(null==(e=t)?void 0:e.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function M(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function O(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${t}`)}function T(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function W(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}class _{constructor(t={}){this.version="4.0.0-rc.30",this.options=void 0,this.plugins=[],this.cache=void 0,this.hooks=void 0,this.visit=void 0,this.classes=void 0,this.currentPageUrl=n(),this.getCurrentUrl=n,this.use=V,this.unuse=M,this.findPlugin=O,this.log=()=>{},this.getAnchorElement=b,this.navigate=x,this.performNavigation=A,this.delegateEvent=a,this.fetchPage=q,this.awaitAnimations=E,this.renderPage=D,this.replaceContent=R,this.animatePageIn=N,this.animatePageOut=L,this.scrollToContent=I,this.createVisit=k,this.resolveUrl=T,this.isSameResolvedUrl=W,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],ignoreVisit:(t,{el:e}={})=>!(null==e||!e.closest("[data-no-swup]")),linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>{var e;return"swup"!==(null==(e=t.state)?void 0:e.source)}},this.currentHistoryIndex=1,this.clickDelegate=void 0,this.options=i({},this.defaults,t),this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new c(this),this.classes=new y(this),this.hooks=new S(this),this.visit=this.createVisit({to:void 0}),this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}async enable(){const{linkSelector:t}=this.options;this.clickDelegate=this.delegateEvent(t,"click",this.handleLinkClick),window.addEventListener("popstate",this.handlePopState),this.options.plugins.forEach(t=>this.use(t)),r(null,{index:1}),await d(),await this.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})}async destroy(){this.clickDelegate.destroy(),window.removeEventListener("popstate",this.handlePopState),this.cache.clear(),this.options.plugins.forEach(t=>this.unuse(t)),await this.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")}),this.hooks.clear()}shouldIgnoreVisit(t,{el:e,event:i}={}){const{origin:s,url:n,hash:o}=l.fromUrl(t);return s!==window.location.origin||!(!e||!this.triggerWillOpenNewWindow(e))||!!this.options.ignoreVisit(n+o,{el:e,event:i})}handleLinkClick(t){const e=t.delegateTarget,{href:i,url:s,hash:n}=l.fromElement(e);this.shouldIgnoreVisit(i,{el:e,event:t})||(this.visit=this.createVisit({to:s,hash:n,el:e,event:t}),t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.call("link:newtab",{href:i}):0===t.button&&this.hooks.callSync("link:click",{el:e,event:t},()=>{var e;const i=null!=(e=this.visit.from.url)?e:"";t.preventDefault(),s&&s!==i?this.isSameResolvedUrl(s,i)||this.performNavigation(s):n?this.hooks.callSync("link:anchor",{hash:n},()=>{r(s+n),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>{this.scrollToContent()})}))}handlePopState(t){var e,i,s;const o=null!=(e=null==(i=t.state)?void 0:i.url)?e:location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(n(),this.currentPageUrl))return;if(this.shouldIgnoreVisit(o,{event:t}))return;const{url:r,hash:a}=l.fromUrl(o);this.visit=this.createVisit({to:r,hash:a,event:t,animate:this.options.animateHistoryBrowsing,resetScroll:this.options.animateHistoryBrowsing}),this.visit.history.popstate=!0;const h=Number(null==(s=t.state)?void 0:s.index);h&&(this.visit.history.direction=h-this.currentHistoryIndex>0?"forwards":"backwards"),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation(r)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}export{l as Location,s as classify,o as createHistoryRecord,_ as default,a as delegateEvent,w as escapeCssIdentifier,f as forceReflow,n as getCurrentUrl,m as isPromise,h as matchPath,d as nextTick,u as query,p as queryAll,g as runAsPromise,v as toMs,r as updateHistoryRecord};
2
2
  //# sourceMappingURL=Swup.modern.js.map
@@ -1,2 +1,2 @@
1
- import t from"delegate-it";import{match as e}from"path-to-regexp";const n=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",r=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},o=function(t,e){void 0===e&&(e={});const n={url:t=t||r({hash:!0}),random:Math.random(),source:"swup",...e};history.pushState(n,"",t)},i=function(t,e){void 0===t&&(t=null),void 0===e&&(e={}),t=t||r({hash:!0});const n={...history.state,url:t,random:Math.random(),source:"swup",...e};history.replaceState(n,"",t)},s=(e,n,r,o)=>{const i=new AbortController;return o={...o,signal:i.signal},t(e,n,r,o),{destroy:()=>i.abort()}};class a extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new a(e)}static fromUrl(t){return new a(t)}}const l=(t,n)=>{try{return e(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${t}":\n${e}`)}};class c{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){return this.pages}has(t){return this.pages.has(this.resolve(t))}get(t){return this.pages.get(this.resolve(t))}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",{page:e})}update(t,e){t=this.resolve(t),e={...this.get(t),...e,url:t},this.pages.set(t,e)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear")}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=a.fromUrl(t);return this.swup.resolveUrl(e)}}const h=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},u=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},m=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function d(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function f(t,e){return void 0===e&&(e=[]),new Promise((n,r)=>{const o=t(...e);d(o)?o.then(n,r):n(o)})}function p(t){return t=t||document.body,t?.offsetHeight}const v=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,g=t=>1e3*Number(t.slice(0,-1).replace(",","."));class w{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?u(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}function y(t){let{to:e,from:n=this.currentPageUrl,hash:r,animate:o=!0,animation:i,el:s,event:a,action:l="push",resetScroll:c=!0}=t;return{from:{url:n},to:{url:e},containers:this.options.containers,animation:{animate:o,wait:!1,name:i,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:s,event:a},history:{action:l,popstate:!1,direction:void 0},scroll:{reset:c,target:r}}}const P="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function k(t,e,n){if(!t.s){if(n instanceof S){if(!n.s)return void(n.o=k.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(k.bind(null,t,e),k.bind(null,t,2));t.s=e,t.v=n;const r=t.o;r&&r(t)}}const S=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const r=new t,o=this.s;if(o){const t=1&o?e:n;if(t){try{k(r,1,t(this.v))}catch(t){k(r,2,t)}return r}return this}return this.o=function(t){try{const o=t.v;1&t.s?k(r,1,e?e(o):o):n?k(r,1,n(o)):k(r,2,o)}catch(t){k(r,2,t)}},r},t}();function b(t){return t instanceof S&&1&t.s}class U{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:end"],this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n){void 0===n&&(n={});const r=this.get(t);if(!r)return console.warn(`Hook '${t}' not found.`),()=>{};const o=r.size+1,i={...n,id:o,hook:t,handler:e};return r.set(e,i),()=>this.off(t,e)}before(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,before:!0})}replace(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,replace:!0})}once(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n){try{const r=this,{before:o,handler:i,after:s}=r.getHandlers(t,n);return Promise.resolve(r.run(o,e)).then(function(){return Promise.resolve(r.run(i,e)).then(function(n){let[o]=n;return Promise.resolve(r.run(s,e)).then(function(){return r.dispatchDomEvent(t,e),o})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n){const{before:r,handler:o,after:i}=this.getHandlers(t,n);this.runSync(r,e);const[s]=this.runSync(o,e);return this.runSync(i,e),this.dispatchDomEvent(t,e),s}run(t,e){try{const n=this,r=[],o=function(t,e,n){if("function"==typeof t[P]){var r,o,i,s=t[P]();if(function t(n){try{for(;!(r=s.next()).done;)if((n=e(r.value))&&n.then){if(!b(n))return void n.then(t,i||(i=k.bind(null,o=new S,2)));n=n.v}o?k(o,1,n):o=n}catch(t){k(o||(o=new S),2,t)}}(),s.return){var a=function(t){try{r.done||s.return()}catch(t){}return t};if(o&&o.then)return o.then(a,function(t){throw a(t)});a()}return o}if(!("length"in t))throw new TypeError("Object is not iterable");for(var l=[],c=0;c<t.length;c++)l.push(t[c]);return function(t,e,n){var r,o,i=-1;return function n(s){try{for(;++i<t.length;)if((s=e(i))&&s.then){if(!b(s))return void s.then(n,o||(o=k.bind(null,r=new S,2)));s=s.v}r?k(r,1,s):r=s}catch(t){k(r||(r=new S),2,t)}}(),r}(l,function(t){return e(l[t])})}(t,function(t){let{hook:o,handler:i,defaultHandler:s,once:a}=t;return Promise.resolve(f(i,[n.swup.visit,e,s])).then(function(t){r.push(t),a&&n.off(o,i)})});return Promise.resolve(o&&o.then?o.then(function(){return r}):r)}catch(t){return Promise.reject(t)}}runSync(t,e){const n=[];for(const{hook:r,handler:o,defaultHandler:i,once:s}of t){const t=o(this.swup.visit,e,i);n.push(t),d(t)&&console.warn(`Promise returned from handler for synchronous hook '${r}'.Swup will not wait for it to resolve.`),s&&this.off(r,o)}return n}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const r=this.sortRegistrations,o=Array.from(n.values()),i=o.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(r),s=o.filter(t=>{let{replace:e}=t;return e}).sort(r),a=o.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(r),l=s.length>0;let c=[];if(e&&(c=[{id:0,hook:t,handler:e}],l)){const n=s.length-1,r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};c=[{id:0,hook:t,handler:s[n].handler,defaultHandler:r(n)}]}return{found:!0,before:i,handler:c,after:a,replaced:l}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e){document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:{hook:t,args:e,visit:this.swup.visit}}))}}const E=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||h(`a[name='${v(t)}']`)||h(`a[name='${v(e)}']`);return n||"top"!==t||(n=document.body),n},C=function(t){let{elements:e,selector:n}=t;try{if(!1===n&&!e)return Promise.resolve();let t=[];if(e)t=Array.from(e);else if(n&&(t=u(n,document.body),!t.length))return console.warn(`[swup] No elements found matching animationSelector \`${n}\``),Promise.resolve();const r=t.map(t=>function(t){const{type:e,timeout:n,propCount:r}=function(t,e){const n=window.getComputedStyle(t),r=A(n,`${$}Delay`),o=A(n,`${$}Duration`),i=H(r,o),s=A(n,`${x}Delay`),a=A(n,`${x}Duration`),l=H(s,a);let c=null,h=0,u=0;return e===$?i>0&&(c=$,h=i,u=o.length):e===x?l>0&&(c=x,h=l,u=a.length):(h=Math.max(i,l),c=h>0?i>l?$:x:null,u=c?c===$?o.length:a.length:0),{type:c,timeout:h,propCount:u}}(t);return!(!e||!n)&&new Promise(o=>{const i=`${e}end`,s=performance.now();let a=0;const l=()=>{t.removeEventListener(i,c),o()},c=e=>{if(e.target===t){if(!function(t){return[`${$}end`,`${x}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-s)/1e3<e.elapsedTime||++a>=r&&l()}};setTimeout(()=>{a<r&&l()},n+1),t.addEventListener(i,c)})}(t));return r.filter(Boolean).length>0?Promise.resolve(Promise.all(r)).then(function(){}):(n&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${n}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},$="transition",x="animation";function A(t,e){return(t[e]||"").split(", ")}function H(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>g(e)+g(t[n])))}const q=function(t,e){void 0===e&&(e={});try{const n=this;if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");const{el:s}=n.visit.trigger;n.visit.to.url=a.fromUrl(t).url,e.referrer=e.referrer||n.currentPageUrl,!1===e.animate&&(n.visit.animation.animate=!1),n.visit.animation.animate||n.classes.clear();const l=e.history||s?.getAttribute("data-swup-history")||void 0;l&&["push","replace"].includes(l)&&(n.visit.history.action=l);const c=e.animation||s?.getAttribute("data-swup-animation")||void 0;return c&&(n.visit.animation.name=c),Promise.resolve(function(s,a){try{var l=Promise.resolve(n.hooks.call("visit:start")).then(function(){function s(){const t=n.animatePageOut();return Promise.resolve(Promise.all([a,t])).then(function(t){let[e]=t;return Promise.resolve(n.renderPage(n.visit.to.url,e)).then(function(){return Promise.resolve(n.animatePageIn()).then(function(){return Promise.resolve(n.hooks.call("visit:end",void 0,()=>n.classes.clear())).then(function(){})})})})}const a=n.hooks.call("page:load",{options:e},function(t,e){try{function r(t){return e.page=t,e.cache=!!o,e.page}const o=n.cache.get(t.to.url);return Promise.resolve(o?r(o):Promise.resolve(n.fetchPage(t.to.url,e.options)).then(r))}catch(i){return Promise.reject(i)}});if(!n.visit.history.popstate){const e=t+(n.visit.scroll.target||"");"replace"===n.visit.history.action?i(e):o(e,{index:n.currentHistoryIndex+1})}n.currentPageUrl=r();const l=function(){if(n.visit.animation.wait)return Promise.resolve(a).then(function(t){let{html:e}=t;n.visit.to.html=e})}();return l&&l.then?l.then(s):s()})}catch(t){return a(t)}return l&&l.then?l.then(void 0,a):l}(0,function(t){t&&(console.error(t),n.options.skipPopStateHandling=()=>(window.location.href=n.visit.to.url,!0),window.history.go(-1))}))}catch(t){return Promise.reject(t)}};function j(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void(window.location.href=t);const{url:r,hash:o}=a.fromUrl(t);this.visit=this.createVisit({...n,to:r,hash:o}),this.performNavigation(r,e)}const L=function(t,e){void 0===e&&(e={});try{const n=this;t=a.fromUrl(t).url;const r={...n.options.requestHeaders,...e.headers};return e={...e,headers:r},Promise.resolve(n.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(e){const{status:r,url:o}=e;return Promise.resolve(e.text()).then(function(i){if(500===r)throw n.hooks.call("fetch:error",{status:r,response:e,url:o}),new R(`Server error: ${o}`,{status:r,url:o});if(!i)throw new R(`Empty response: ${o}`,{status:r,url:o});const{url:s}=a.fromUrl(o),l={url:s,html:i};return t===s&&n.cache.set(l.url,l),l})})}catch(t){return Promise.reject(t)}};class R extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.name="FetchError",this.url=e.url,this.status=e.status}}const I=function(){try{let e;const r=this;function t(t){return e?t:Promise.resolve(r.hooks.call("animation:out:start",void 0,t=>{r.classes.add("is-changing","is-leaving","is-animating"),t.history.popstate&&r.classes.add("is-popstate"),t.animation.name&&r.classes.add(`to-${n(t.animation.name)}`)})).then(function(){return Promise.resolve(r.hooks.call("animation:out:await",{skip:!1},function(t,e){let{skip:n}=e;try{return n?Promise.resolve():Promise.resolve(r.awaitAnimations({selector:t.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(r.hooks.call("animation:out:end")).then(function(){})})})}const o=function(){if(!r.visit.animation.animate)return Promise.resolve(r.hooks.call("animation:skip")).then(function(){e=1})}();return Promise.resolve(o&&o.then?o.then(t):t(o))}catch(i){return Promise.reject(i)}},N=function(t,e){let{html:n}=t,{containers:r}=void 0===e?this.options:e;const o=(new DOMParser).parseFromString(n,"text/html"),i=o.querySelector("title")?.innerText||"";return document.title=i,r.map(t=>{const e=document.querySelector(t),n=o.querySelector(t);return e&&n?(e.replaceWith(n),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),n||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean).length===r.length},D=function(){const t={behavior:"auto"},{target:e,reset:n}=this.visit.scroll;let r=!1;return e&&(r=this.hooks.callSync("scroll:anchor",{hash:e,options:t},(t,e)=>{let{hash:n,options:r}=e;const o=this.getAnchorElement(n||"");return o&&o.scrollIntoView(r),!!o})),n&&!r&&(r=this.hooks.callSync("scroll:top",{options:t},(t,e)=>{let{options:n}=e;return window.scrollTo({top:0,left:0,...n}),!0})),r},V=function(){try{const t=this;if(!t.visit.animation.animate)return Promise.resolve();const e=t.hooks.call("animation:in:await",{skip:!1},function(e,n){let{skip:r}=n;try{return r?Promise.resolve():Promise.resolve(t.awaitAnimations({selector:e.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}});return Promise.resolve(m()).then(function(){return Promise.resolve(t.hooks.call("animation:in:start",void 0,()=>{t.classes.remove("is-animating")})).then(function(){return Promise.resolve(e).then(function(){return Promise.resolve(t.hooks.call("animation:in:end")).then(function(){})})})})}catch(t){return Promise.reject(t)}},M=function(t,e){try{const o=this,{url:s,html:a}=e;return o.classes.remove("is-leaving"),o.isSameResolvedUrl(r(),t)?(o.isSameResolvedUrl(r(),s)||(i(s),o.currentPageUrl=r(),o.visit.to.url=o.currentPageUrl),o.visit.animation.animate&&o.classes.add("is-rendering"),o.visit.to.html=a,Promise.resolve(o.hooks.call("content:replace",{page:e},(t,e)=>{let{page:r}=e;if(!o.replaceContent(r,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(o.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&o.classes.add(`to-${n(t.animation.name)}`))})).then(function(){return Promise.resolve(o.hooks.call("content:scroll",void 0,()=>o.scrollToContent())).then(function(){return Promise.resolve(o.hooks.call("page:view",{url:o.currentPageUrl,title:document.title})).then(function(){o.options.cache||o.cache.clear()})})})):Promise.resolve()}catch(t){return Promise.reject(t)}},T=function(t){var e;if(e=t,e?.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function W(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function _(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${t}`)}function B(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function O(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}class F{constructor(t){void 0===t&&(t={}),this.version="4.0.0-rc.28",this.options=void 0,this.plugins=[],this.cache=void 0,this.hooks=void 0,this.visit=void 0,this.classes=void 0,this.currentPageUrl=r(),this.getCurrentUrl=r,this.use=T,this.unuse=W,this.findPlugin=_,this.log=()=>{},this.getAnchorElement=E,this.navigate=j,this.performNavigation=q,this.delegateEvent=s,this.fetchPage=L,this.awaitAnimations=C,this.renderPage=M,this.replaceContent=N,this.animatePageIn=V,this.animatePageOut=I,this.scrollToContent=D,this.createVisit=y,this.resolveUrl=B,this.isSameResolvedUrl=O,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],ignoreVisit:function(t,e){let{el:n}=void 0===e?{}:e;return!!n?.closest("[data-no-swup]")},linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source},this.currentHistoryIndex=1,this.clickDelegate=void 0,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new c(this),this.classes=new w(this),this.hooks=new U(this),this.visit=this.createVisit({to:void 0}),this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}enable(){try{const t=this,{linkSelector:e}=t.options;return t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.plugins.forEach(e=>t.use(e)),i(null,{index:1}),Promise.resolve(m()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.options.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,e){let{el:n,event:r}=void 0===e?{}:e;const{origin:o,url:i,hash:s}=a.fromUrl(t);return o!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(i+s,{el:n,event:r})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:r,hash:o}=a.fromElement(e);this.shouldIgnoreVisit(n,{el:e,event:t})||(this.visit=this.createVisit({to:r,hash:o,el:e,event:t}),t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.call("link:newtab",{href:n}):0===t.button&&this.hooks.callSync("link:click",{el:e,event:t},()=>{const e=this.visit.from.url??"";t.preventDefault(),r&&r!==e?this.isSameResolvedUrl(r,e)||this.performNavigation(r):o?this.hooks.callSync("link:anchor",{hash:o},()=>{i(r+o),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>{this.scrollToContent()})}))}handlePopState(t){const e=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(r(),this.currentPageUrl))return;if(this.shouldIgnoreVisit(e,{event:t}))return;const{url:n,hash:o}=a.fromUrl(e);this.visit=this.createVisit({to:n,hash:o,event:t,animate:this.options.animateHistoryBrowsing,resetScroll:this.options.animateHistoryBrowsing}),this.visit.history.popstate=!0;const i=Number(t.state?.index);i&&(this.visit.history.direction=i-this.currentHistoryIndex>0?"forwards":"backwards"),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation(n)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}export{a as Location,n as classify,o as createHistoryRecord,F as default,s as delegateEvent,v as escapeCssIdentifier,p as forceReflow,r as getCurrentUrl,d as isPromise,l as matchPath,m as nextTick,h as query,u as queryAll,f as runAsPromise,g as toMs,i as updateHistoryRecord};
1
+ import t from"delegate-it";import{match as e}from"path-to-regexp";const n=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",r=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},o=function(t,e){void 0===e&&(e={});const n={url:t=t||r({hash:!0}),random:Math.random(),source:"swup",...e};history.pushState(n,"",t)},i=function(t,e){void 0===t&&(t=null),void 0===e&&(e={}),t=t||r({hash:!0});const n={...history.state,url:t,random:Math.random(),source:"swup",...e};history.replaceState(n,"",t)},s=(e,n,r,o)=>{const i=new AbortController;return o={...o,signal:i.signal},t(e,n,r,o),{destroy:()=>i.abort()}};class a extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new a(e)}static fromUrl(t){return new a(t)}}const l=(t,n)=>{try{return e(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${t}":\n${e}`)}};class c{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){return this.pages}has(t){return this.pages.has(this.resolve(t))}get(t){return this.pages.get(this.resolve(t))}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",{page:e})}update(t,e){t=this.resolve(t),e={...this.get(t),...e,url:t},this.pages.set(t,e)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear")}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=a.fromUrl(t);return this.swup.resolveUrl(e)}}const h=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},u=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},m=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function d(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function f(t,e){return void 0===e&&(e=[]),new Promise((n,r)=>{const o=t(...e);d(o)?o.then(n,r):n(o)})}function p(t){return t=t||document.body,t?.offsetHeight}const v=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,g=t=>1e3*Number(t.slice(0,-1).replace(",","."));class w{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?u(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}function y(t){let{to:e,from:n=this.currentPageUrl,hash:r,animate:o=!0,animation:i,el:s,event:a,action:l="push",resetScroll:c=!0}=t;return{from:{url:n},to:{url:e},containers:this.options.containers,animation:{animate:o,wait:!1,name:i,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:s,event:a},history:{action:l,popstate:!1,direction:void 0},scroll:{reset:c,target:r}}}const P="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function k(t,e,n){if(!t.s){if(n instanceof S){if(!n.s)return void(n.o=k.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(k.bind(null,t,e),k.bind(null,t,2));t.s=e,t.v=n;const r=t.o;r&&r(t)}}const S=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const r=new t,o=this.s;if(o){const t=1&o?e:n;if(t){try{k(r,1,t(this.v))}catch(t){k(r,2,t)}return r}return this}return this.o=function(t){try{const o=t.v;1&t.s?k(r,1,e?e(o):o):n?k(r,1,n(o)):k(r,2,o)}catch(t){k(r,2,t)}},r},t}();function b(t){return t instanceof S&&1&t.s}class U{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:end"],this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n){void 0===n&&(n={});const r=this.get(t);if(!r)return console.warn(`Hook '${t}' not found.`),()=>{};const o=r.size+1,i={...n,id:o,hook:t,handler:e};return r.set(e,i),()=>this.off(t,e)}before(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,before:!0})}replace(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,replace:!0})}once(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n){try{const r=this,{before:o,handler:i,after:s}=r.getHandlers(t,n);return Promise.resolve(r.run(o,e)).then(function(){return Promise.resolve(r.run(i,e)).then(function(n){let[o]=n;return Promise.resolve(r.run(s,e)).then(function(){return r.dispatchDomEvent(t,e),o})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n){const{before:r,handler:o,after:i}=this.getHandlers(t,n);this.runSync(r,e);const[s]=this.runSync(o,e);return this.runSync(i,e),this.dispatchDomEvent(t,e),s}run(t,e){try{const n=this,r=[],o=function(t,e,n){if("function"==typeof t[P]){var r,o,i,s=t[P]();if(function t(n){try{for(;!(r=s.next()).done;)if((n=e(r.value))&&n.then){if(!b(n))return void n.then(t,i||(i=k.bind(null,o=new S,2)));n=n.v}o?k(o,1,n):o=n}catch(t){k(o||(o=new S),2,t)}}(),s.return){var a=function(t){try{r.done||s.return()}catch(t){}return t};if(o&&o.then)return o.then(a,function(t){throw a(t)});a()}return o}if(!("length"in t))throw new TypeError("Object is not iterable");for(var l=[],c=0;c<t.length;c++)l.push(t[c]);return function(t,e,n){var r,o,i=-1;return function n(s){try{for(;++i<t.length;)if((s=e(i))&&s.then){if(!b(s))return void s.then(n,o||(o=k.bind(null,r=new S,2)));s=s.v}r?k(r,1,s):r=s}catch(t){k(r||(r=new S),2,t)}}(),r}(l,function(t){return e(l[t])})}(t,function(t){let{hook:o,handler:i,defaultHandler:s,once:a}=t;return Promise.resolve(f(i,[n.swup.visit,e,s])).then(function(t){r.push(t),a&&n.off(o,i)})});return Promise.resolve(o&&o.then?o.then(function(){return r}):r)}catch(t){return Promise.reject(t)}}runSync(t,e){const n=[];for(const{hook:r,handler:o,defaultHandler:i,once:s}of t){const t=o(this.swup.visit,e,i);n.push(t),d(t)&&console.warn(`Promise returned from handler for synchronous hook '${r}'.Swup will not wait for it to resolve.`),s&&this.off(r,o)}return n}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const r=this.sortRegistrations,o=Array.from(n.values()),i=o.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(r),s=o.filter(t=>{let{replace:e}=t;return e}).sort(r),a=o.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(r),l=s.length>0;let c=[];if(e&&(c=[{id:0,hook:t,handler:e}],l)){const n=s.length-1,r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};c=[{id:0,hook:t,handler:s[n].handler,defaultHandler:r(n)}]}return{found:!0,before:i,handler:c,after:a,replaced:l}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e){document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:{hook:t,args:e,visit:this.swup.visit}}))}}const E=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||h(`a[name='${v(t)}']`)||h(`a[name='${v(e)}']`);return n||"top"!==t||(n=document.body),n},C=function(t){let{elements:e,selector:n}=t;try{if(!1===n&&!e)return Promise.resolve();let t=[];if(e)t=Array.from(e);else if(n&&(t=u(n,document.body),!t.length))return console.warn(`[swup] No elements found matching animationSelector \`${n}\``),Promise.resolve();const r=t.map(t=>function(t){const{type:e,timeout:n,propCount:r}=function(t,e){const n=window.getComputedStyle(t),r=A(n,`${$}Delay`),o=A(n,`${$}Duration`),i=H(r,o),s=A(n,`${x}Delay`),a=A(n,`${x}Duration`),l=H(s,a);let c=null,h=0,u=0;return e===$?i>0&&(c=$,h=i,u=o.length):e===x?l>0&&(c=x,h=l,u=a.length):(h=Math.max(i,l),c=h>0?i>l?$:x:null,u=c?c===$?o.length:a.length:0),{type:c,timeout:h,propCount:u}}(t);return!(!e||!n)&&new Promise(o=>{const i=`${e}end`,s=performance.now();let a=0;const l=()=>{t.removeEventListener(i,c),o()},c=e=>{if(e.target===t){if(!function(t){return[`${$}end`,`${x}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-s)/1e3<e.elapsedTime||++a>=r&&l()}};setTimeout(()=>{a<r&&l()},n+1),t.addEventListener(i,c)})}(t));return r.filter(Boolean).length>0?Promise.resolve(Promise.all(r)).then(function(){}):(n&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${n}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},$="transition",x="animation";function A(t,e){return(t[e]||"").split(", ")}function H(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>g(e)+g(t[n])))}const q=function(t,e){void 0===e&&(e={});try{const n=this;if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");const{el:s}=n.visit.trigger;n.visit.to.url=a.fromUrl(t).url,e.referrer=e.referrer||n.currentPageUrl,!1===e.animate&&(n.visit.animation.animate=!1),n.visit.animation.animate||n.classes.clear();const l=e.history||s?.getAttribute("data-swup-history")||void 0;l&&["push","replace"].includes(l)&&(n.visit.history.action=l);const c=e.animation||s?.getAttribute("data-swup-animation")||void 0;return c&&(n.visit.animation.name=c),Promise.resolve(function(s,a){try{var l=Promise.resolve(n.hooks.call("visit:start")).then(function(){function s(){const t=n.animatePageOut();return Promise.resolve(Promise.all([a,t])).then(function(t){let[e]=t;return Promise.resolve(n.renderPage(n.visit.to.url,e)).then(function(){return Promise.resolve(n.animatePageIn()).then(function(){return Promise.resolve(n.hooks.call("visit:end",void 0,()=>n.classes.clear())).then(function(){})})})})}const a=n.hooks.call("page:load",{options:e},function(t,e){try{function r(t){return e.page=t,e.cache=!!o,e.page}const o=n.cache.get(t.to.url);return Promise.resolve(o?r(o):Promise.resolve(n.fetchPage(t.to.url,e.options)).then(r))}catch(i){return Promise.reject(i)}});if(!n.visit.history.popstate){const e=t+(n.visit.scroll.target||"");"replace"===n.visit.history.action?i(e):o(e,{index:n.currentHistoryIndex+1})}n.currentPageUrl=r();const l=function(){if(n.visit.animation.wait)return Promise.resolve(a).then(function(t){let{html:e}=t;n.visit.to.html=e})}();return l&&l.then?l.then(s):s()})}catch(t){return a(t)}return l&&l.then?l.then(void 0,a):l}(0,function(t){t&&(console.error(t),n.options.skipPopStateHandling=()=>(window.location.href=n.visit.to.url,!0),window.history.go(-1))}))}catch(t){return Promise.reject(t)}};function j(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void(window.location.href=t);const{url:r,hash:o}=a.fromUrl(t);this.visit=this.createVisit({...n,to:r,hash:o}),this.performNavigation(r,e)}const L=function(t,e){void 0===e&&(e={});try{const n=this;t=a.fromUrl(t).url;const r={...n.options.requestHeaders,...e.headers};return e={...e,headers:r},Promise.resolve(n.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(e){const{status:r,url:o}=e;return Promise.resolve(e.text()).then(function(i){if(500===r)throw n.hooks.call("fetch:error",{status:r,response:e,url:o}),new R(`Server error: ${o}`,{status:r,url:o});if(!i)throw new R(`Empty response: ${o}`,{status:r,url:o});const{url:s}=a.fromUrl(o),l={url:s,html:i};return t===s&&n.cache.set(l.url,l),l})})}catch(t){return Promise.reject(t)}};class R extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.name="FetchError",this.url=e.url,this.status=e.status}}const I=function(){try{let e;const r=this;function t(t){return e?t:Promise.resolve(r.hooks.call("animation:out:start",void 0,t=>{r.classes.add("is-changing","is-leaving","is-animating"),t.history.popstate&&r.classes.add("is-popstate"),t.animation.name&&r.classes.add(`to-${n(t.animation.name)}`)})).then(function(){return Promise.resolve(r.hooks.call("animation:out:await",{skip:!1},function(t,e){let{skip:n}=e;try{return n?Promise.resolve():Promise.resolve(r.awaitAnimations({selector:t.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(r.hooks.call("animation:out:end")).then(function(){})})})}const o=function(){if(!r.visit.animation.animate)return Promise.resolve(r.hooks.call("animation:skip")).then(function(){e=1})}();return Promise.resolve(o&&o.then?o.then(t):t(o))}catch(i){return Promise.reject(i)}},N=function(t,e){let{html:n}=t,{containers:r}=void 0===e?this.options:e;const o=(new DOMParser).parseFromString(n,"text/html"),i=o.querySelector("title")?.innerText||"";return document.title=i,r.map(t=>{const e=document.querySelector(t),n=o.querySelector(t);return e&&n?(e.replaceWith(n),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),n||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean).length===r.length},D=function(){const t={behavior:"auto"},{target:e,reset:n}=this.visit.scroll;let r=!1;return e&&(r=this.hooks.callSync("scroll:anchor",{hash:e,options:t},(t,e)=>{let{hash:n,options:r}=e;const o=this.getAnchorElement(n||"");return o&&o.scrollIntoView(r),!!o})),n&&!r&&(r=this.hooks.callSync("scroll:top",{options:t},(t,e)=>{let{options:n}=e;return window.scrollTo({top:0,left:0,...n}),!0})),r},V=function(){try{const t=this;if(!t.visit.animation.animate)return Promise.resolve();const e=t.hooks.call("animation:in:await",{skip:!1},function(e,n){let{skip:r}=n;try{return r?Promise.resolve():Promise.resolve(t.awaitAnimations({selector:e.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}});return Promise.resolve(m()).then(function(){return Promise.resolve(t.hooks.call("animation:in:start",void 0,()=>{t.classes.remove("is-animating")})).then(function(){return Promise.resolve(e).then(function(){return Promise.resolve(t.hooks.call("animation:in:end")).then(function(){})})})})}catch(t){return Promise.reject(t)}},M=function(t,e){try{const o=this,{url:s,html:a}=e;return o.classes.remove("is-leaving"),o.isSameResolvedUrl(r(),t)?(o.isSameResolvedUrl(r(),s)||(i(s),o.currentPageUrl=r(),o.visit.to.url=o.currentPageUrl),o.visit.animation.animate&&o.classes.add("is-rendering"),o.visit.to.html=a,Promise.resolve(o.hooks.call("content:replace",{page:e},(t,e)=>{let{page:r}=e;if(!o.replaceContent(r,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(o.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&o.classes.add(`to-${n(t.animation.name)}`))})).then(function(){return Promise.resolve(o.hooks.call("content:scroll",void 0,()=>o.scrollToContent())).then(function(){return Promise.resolve(o.hooks.call("page:view",{url:o.currentPageUrl,title:document.title})).then(function(){o.options.cache||o.cache.clear()})})})):Promise.resolve()}catch(t){return Promise.reject(t)}},T=function(t){var e;if(e=t,e?.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function W(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function _(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${t}`)}function B(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function O(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}class F{constructor(t){void 0===t&&(t={}),this.version="4.0.0-rc.30",this.options=void 0,this.plugins=[],this.cache=void 0,this.hooks=void 0,this.visit=void 0,this.classes=void 0,this.currentPageUrl=r(),this.getCurrentUrl=r,this.use=T,this.unuse=W,this.findPlugin=_,this.log=()=>{},this.getAnchorElement=E,this.navigate=j,this.performNavigation=q,this.delegateEvent=s,this.fetchPage=L,this.awaitAnimations=C,this.renderPage=M,this.replaceContent=N,this.animatePageIn=V,this.animatePageOut=I,this.scrollToContent=D,this.createVisit=y,this.resolveUrl=B,this.isSameResolvedUrl=O,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],ignoreVisit:function(t,e){let{el:n}=void 0===e?{}:e;return!!n?.closest("[data-no-swup]")},linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source},this.currentHistoryIndex=1,this.clickDelegate=void 0,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new c(this),this.classes=new w(this),this.hooks=new U(this),this.visit=this.createVisit({to:void 0}),this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}enable(){try{const t=this,{linkSelector:e}=t.options;return t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.plugins.forEach(e=>t.use(e)),i(null,{index:1}),Promise.resolve(m()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.options.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,e){let{el:n,event:r}=void 0===e?{}:e;const{origin:o,url:i,hash:s}=a.fromUrl(t);return o!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(i+s,{el:n,event:r})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:r,hash:o}=a.fromElement(e);this.shouldIgnoreVisit(n,{el:e,event:t})||(this.visit=this.createVisit({to:r,hash:o,el:e,event:t}),t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.call("link:newtab",{href:n}):0===t.button&&this.hooks.callSync("link:click",{el:e,event:t},()=>{const e=this.visit.from.url??"";t.preventDefault(),r&&r!==e?this.isSameResolvedUrl(r,e)||this.performNavigation(r):o?this.hooks.callSync("link:anchor",{hash:o},()=>{i(r+o),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>{this.scrollToContent()})}))}handlePopState(t){const e=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(r(),this.currentPageUrl))return;if(this.shouldIgnoreVisit(e,{event:t}))return;const{url:n,hash:o}=a.fromUrl(e);this.visit=this.createVisit({to:n,hash:o,event:t,animate:this.options.animateHistoryBrowsing,resetScroll:this.options.animateHistoryBrowsing}),this.visit.history.popstate=!0;const i=Number(t.state?.index);i&&(this.visit.history.direction=i-this.currentHistoryIndex>0?"forwards":"backwards"),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation(n)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}export{a as Location,n as classify,o as createHistoryRecord,F as default,s as delegateEvent,v as escapeCssIdentifier,p as forceReflow,r as getCurrentUrl,d as isPromise,l as matchPath,m as nextTick,h as query,u as queryAll,f as runAsPromise,g as toMs,i as updateHistoryRecord};
2
2
  //# sourceMappingURL=Swup.module.js.map
package/dist/Swup.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t||self).Swup=e()}(this,function(){const t=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",e=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},n=function(t,n){void 0===n&&(n={});const r={url:t=t||e({hash:!0}),random:Math.random(),source:"swup",...n};history.pushState(r,"",t)},r=function(t,n){void 0===t&&(t=null),void 0===n&&(n={}),t=t||e({hash:!0});const r={...history.state,url:t,random:Math.random(),source:"swup",...n};history.replaceState(r,"",t)},o=new WeakMap;function i(t,e,n,r){if(!t&&!o.has(e))return!1;const i=o.get(e)??new WeakMap;o.set(e,i);const s=i.get(n)??new Set;i.set(n,s);const a=s.has(r);return t?s.add(r):s.delete(r),a&&t}const s=(t,e,n,r)=>{const o=new AbortController;return function(t,e,n,r={}){const{signal:o,base:s=document}=r;if(o?.aborted)return;const{once:a,...l}=r,c=s instanceof Document?s.documentElement:s,u=Boolean("object"==typeof r?r.capture:r),h=r=>{const o=function(t,e){let n=t.target;if(n instanceof Text&&(n=n.parentElement),n instanceof Element&&t.currentTarget instanceof Element){const r=n.closest(e);if(r&&t.currentTarget.contains(r))return r}}(r,t);if(o){const t=Object.assign(r,{delegateTarget:o});n.call(c,t),a&&(c.removeEventListener(e,h,l),i(!1,c,n,m))}},m=JSON.stringify({selector:t,type:e,capture:u});i(!0,c,n,m)||c.addEventListener(e,h,l),o?.addEventListener("abort",()=>{i(!1,c,n,m)})}(t,e,n,r={...r,signal:o.signal}),{destroy:()=>o.abort()}};class a extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new a(e)}static fromUrl(t){return new a(t)}}class l{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){return this.pages}has(t){return this.pages.has(this.resolve(t))}get(t){return this.pages.get(this.resolve(t))}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",{page:e})}update(t,e){t=this.resolve(t),e={...this.get(t),...e,url:t},this.pages.set(t,e)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear")}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=a.fromUrl(t);return this.swup.resolveUrl(e)}}const c=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},u=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},h=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function m(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}const f=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,d=t=>1e3*Number(t.slice(0,-1).replace(",","."));class p{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?u(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}function v(t){let{to:e,from:n=this.currentPageUrl,hash:r,animate:o=!0,animation:i,el:s,event:a,action:l="push",resetScroll:c=!0}=t;return{from:{url:n},to:{url:e},containers:this.options.containers,animation:{animate:o,wait:!1,name:i,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:s,event:a},history:{action:l,popstate:!1,direction:void 0},scroll:{reset:c,target:r}}}const g="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function w(t,e,n){if(!t.s){if(n instanceof y){if(!n.s)return void(n.o=w.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(w.bind(null,t,e),w.bind(null,t,2));t.s=e,t.v=n;const r=t.o;r&&r(t)}}const y=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const r=new t,o=this.s;if(o){const t=1&o?e:n;if(t){try{w(r,1,t(this.v))}catch(t){w(r,2,t)}return r}return this}return this.o=function(t){try{const o=t.v;1&t.s?w(r,1,e?e(o):o):n?w(r,1,n(o)):w(r,2,o)}catch(t){w(r,2,t)}},r},t}();function P(t){return t instanceof y&&1&t.s}class k{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:end"],this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n){void 0===n&&(n={});const r=this.get(t);if(!r)return console.warn(`Hook '${t}' not found.`),()=>{};const o=r.size+1,i={...n,id:o,hook:t,handler:e};return r.set(e,i),()=>this.off(t,e)}before(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,before:!0})}replace(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,replace:!0})}once(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n){try{const r=this,{before:o,handler:i,after:s}=r.getHandlers(t,n);return Promise.resolve(r.run(o,e)).then(function(){return Promise.resolve(r.run(i,e)).then(function(n){let[o]=n;return Promise.resolve(r.run(s,e)).then(function(){return r.dispatchDomEvent(t,e),o})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n){const{before:r,handler:o,after:i}=this.getHandlers(t,n);this.runSync(r,e);const[s]=this.runSync(o,e);return this.runSync(i,e),this.dispatchDomEvent(t,e),s}run(t,e){try{const n=this,r=[],o=function(t,e,n){if("function"==typeof t[g]){var r,o,i,s=t[g]();if(function t(n){try{for(;!(r=s.next()).done;)if((n=e(r.value))&&n.then){if(!P(n))return void n.then(t,i||(i=w.bind(null,o=new y,2)));n=n.v}o?w(o,1,n):o=n}catch(t){w(o||(o=new y),2,t)}}(),s.return){var a=function(t){try{r.done||s.return()}catch(t){}return t};if(o&&o.then)return o.then(a,function(t){throw a(t)});a()}return o}if(!("length"in t))throw new TypeError("Object is not iterable");for(var l=[],c=0;c<t.length;c++)l.push(t[c]);return function(t,e,n){var r,o,i=-1;return function n(s){try{for(;++i<t.length;)if((s=e(i))&&s.then){if(!P(s))return void s.then(n,o||(o=w.bind(null,r=new y,2)));s=s.v}r?w(r,1,s):r=s}catch(t){w(r||(r=new y),2,t)}}(),r}(l,function(t){return e(l[t])})}(t,function(t){let{hook:o,handler:i,defaultHandler:s,once:a}=t;return Promise.resolve(function(t,e){return void 0===e&&(e=[]),new Promise((n,r)=>{const o=t(...e);m(o)?o.then(n,r):n(o)})}(i,[n.swup.visit,e,s])).then(function(t){r.push(t),a&&n.off(o,i)})});return Promise.resolve(o&&o.then?o.then(function(){return r}):r)}catch(t){return Promise.reject(t)}}runSync(t,e){const n=[];for(const{hook:r,handler:o,defaultHandler:i,once:s}of t){const t=o(this.swup.visit,e,i);n.push(t),m(t)&&console.warn(`Promise returned from handler for synchronous hook '${r}'.Swup will not wait for it to resolve.`),s&&this.off(r,o)}return n}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const r=this.sortRegistrations,o=Array.from(n.values()),i=o.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(r),s=o.filter(t=>{let{replace:e}=t;return e}).sort(r),a=o.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(r),l=s.length>0;let c=[];if(e&&(c=[{id:0,hook:t,handler:e}],l)){const n=s.length-1,r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};c=[{id:0,hook:t,handler:s[n].handler,defaultHandler:r(n)}]}return{found:!0,before:i,handler:c,after:a,replaced:l}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e){document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:{hook:t,args:e,visit:this.swup.visit}}))}}const S=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||c(`a[name='${f(t)}']`)||c(`a[name='${f(e)}']`);return n||"top"!==t||(n=document.body),n},b=function(t){let{elements:e,selector:n}=t;try{if(!1===n&&!e)return Promise.resolve();let t=[];if(e)t=Array.from(e);else if(n&&(t=u(n,document.body),!t.length))return console.warn(`[swup] No elements found matching animationSelector \`${n}\``),Promise.resolve();const r=t.map(t=>function(t){const{type:e,timeout:n,propCount:r}=function(t,e){const n=window.getComputedStyle(t),r=C(n,`${E}Delay`),o=C(n,`${E}Duration`),i=$(r,o),s=C(n,`${U}Delay`),a=C(n,`${U}Duration`),l=$(s,a);let c=null,u=0,h=0;return e===E?i>0&&(c=E,u=i,h=o.length):e===U?l>0&&(c=U,u=l,h=a.length):(u=Math.max(i,l),c=u>0?i>l?E:U:null,h=c?c===E?o.length:a.length:0),{type:c,timeout:u,propCount:h}}(t);return!(!e||!n)&&new Promise(o=>{const i=`${e}end`,s=performance.now();let a=0;const l=()=>{t.removeEventListener(i,c),o()},c=e=>{if(e.target===t){if(!function(t){return[`${E}end`,`${U}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-s)/1e3<e.elapsedTime||++a>=r&&l()}};setTimeout(()=>{a<r&&l()},n+1),t.addEventListener(i,c)})}(t));return r.filter(Boolean).length>0?Promise.resolve(Promise.all(r)).then(function(){}):(n&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${n}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},E="transition",U="animation";function C(t,e){return(t[e]||"").split(", ")}function $(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>d(e)+d(t[n])))}const x=function(t,o){void 0===o&&(o={});try{const i=this;if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");const{el:s}=i.visit.trigger;i.visit.to.url=a.fromUrl(t).url,o.referrer=o.referrer||i.currentPageUrl,!1===o.animate&&(i.visit.animation.animate=!1),i.visit.animation.animate||i.classes.clear();const l=o.history||s?.getAttribute("data-swup-history")||void 0;l&&["push","replace"].includes(l)&&(i.visit.history.action=l);const c=o.animation||s?.getAttribute("data-swup-animation")||void 0;return c&&(i.visit.animation.name=c),Promise.resolve(function(s,a){try{var l=Promise.resolve(i.hooks.call("visit:start")).then(function(){function s(){const t=i.animatePageOut();return Promise.resolve(Promise.all([a,t])).then(function(t){let[e]=t;return Promise.resolve(i.renderPage(i.visit.to.url,e)).then(function(){return Promise.resolve(i.animatePageIn()).then(function(){return Promise.resolve(i.hooks.call("visit:end",void 0,()=>i.classes.clear())).then(function(){})})})})}const a=i.hooks.call("page:load",{options:o},function(t,e){try{function n(t){return e.page=t,e.cache=!!r,e.page}const r=i.cache.get(t.to.url);return Promise.resolve(r?n(r):Promise.resolve(i.fetchPage(t.to.url,e.options)).then(n))}catch(o){return Promise.reject(o)}});if(!i.visit.history.popstate){const e=t+(i.visit.scroll.target||"");"replace"===i.visit.history.action?r(e):n(e,{index:i.currentHistoryIndex+1})}i.currentPageUrl=e();const l=function(){if(i.visit.animation.wait)return Promise.resolve(a).then(function(t){let{html:e}=t;i.visit.to.html=e})}();return l&&l.then?l.then(s):s()})}catch(t){return a(t)}return l&&l.then?l.then(void 0,a):l}(0,function(t){t&&(console.error(t),i.options.skipPopStateHandling=()=>(window.location.href=i.visit.to.url,!0),window.history.go(-1))}))}catch(t){return Promise.reject(t)}};function A(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void(window.location.href=t);const{url:r,hash:o}=a.fromUrl(t);this.visit=this.createVisit({...n,to:r,hash:o}),this.performNavigation(r,e)}const j=function(t,e){void 0===e&&(e={});try{const n=this;t=a.fromUrl(t).url;const r={...n.options.requestHeaders,...e.headers};return e={...e,headers:r},Promise.resolve(n.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(e){const{status:r,url:o}=e;return Promise.resolve(e.text()).then(function(i){if(500===r)throw n.hooks.call("fetch:error",{status:r,response:e,url:o}),new H(`Server error: ${o}`,{status:r,url:o});if(!i)throw new H(`Empty response: ${o}`,{status:r,url:o});const{url:s}=a.fromUrl(o),l={url:s,html:i};return t===s&&n.cache.set(l.url,l),l})})}catch(t){return Promise.reject(t)}};class H extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.name="FetchError",this.url=e.url,this.status=e.status}}const L=function(){try{let n;const r=this;function e(e){return n?e:Promise.resolve(r.hooks.call("animation:out:start",void 0,e=>{r.classes.add("is-changing","is-leaving","is-animating"),e.history.popstate&&r.classes.add("is-popstate"),e.animation.name&&r.classes.add(`to-${t(e.animation.name)}`)})).then(function(){return Promise.resolve(r.hooks.call("animation:out:await",{skip:!1},function(t,e){let{skip:n}=e;try{return n?Promise.resolve():Promise.resolve(r.awaitAnimations({selector:t.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(r.hooks.call("animation:out:end")).then(function(){})})})}const o=function(){if(!r.visit.animation.animate)return Promise.resolve(r.hooks.call("animation:skip")).then(function(){n=1})}();return Promise.resolve(o&&o.then?o.then(e):e(o))}catch(i){return Promise.reject(i)}},q=function(t,e){let{html:n}=t,{containers:r}=void 0===e?this.options:e;const o=(new DOMParser).parseFromString(n,"text/html"),i=o.querySelector("title")?.innerText||"";return document.title=i,r.map(t=>{const e=document.querySelector(t),n=o.querySelector(t);return e&&n?(e.replaceWith(n),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),n||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean).length===r.length},R=function(){const t={behavior:"auto"},{target:e,reset:n}=this.visit.scroll;let r=!1;return e&&(r=this.hooks.callSync("scroll:anchor",{hash:e,options:t},(t,e)=>{let{hash:n,options:r}=e;const o=this.getAnchorElement(n||"");return o&&o.scrollIntoView(r),!!o})),n&&!r&&(r=this.hooks.callSync("scroll:top",{options:t},(t,e)=>{let{options:n}=e;return window.scrollTo({top:0,left:0,...n}),!0})),r},T=function(){try{const t=this;if(!t.visit.animation.animate)return Promise.resolve();const e=t.hooks.call("animation:in:await",{skip:!1},function(e,n){let{skip:r}=n;try{return r?Promise.resolve():Promise.resolve(t.awaitAnimations({selector:e.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}});return Promise.resolve(h()).then(function(){return Promise.resolve(t.hooks.call("animation:in:start",void 0,()=>{t.classes.remove("is-animating")})).then(function(){return Promise.resolve(e).then(function(){return Promise.resolve(t.hooks.call("animation:in:end")).then(function(){})})})})}catch(t){return Promise.reject(t)}},N=function(n,o){try{const i=this,{url:s,html:a}=o;return i.classes.remove("is-leaving"),i.isSameResolvedUrl(e(),n)?(i.isSameResolvedUrl(e(),s)||(r(s),i.currentPageUrl=e(),i.visit.to.url=i.currentPageUrl),i.visit.animation.animate&&i.classes.add("is-rendering"),i.visit.to.html=a,Promise.resolve(i.hooks.call("content:replace",{page:o},(e,n)=>{let{page:r}=n;if(!i.replaceContent(r,{containers:e.containers}))throw new Error("[swup] Container mismatch, aborting");e.animation.animate&&(i.classes.add("is-animating","is-changing","is-rendering"),e.animation.name&&i.classes.add(`to-${t(e.animation.name)}`))})).then(function(){return Promise.resolve(i.hooks.call("content:scroll",void 0,()=>i.scrollToContent())).then(function(){return Promise.resolve(i.hooks.call("page:view",{url:i.currentPageUrl,title:document.title})).then(function(){i.options.cache||i.cache.clear()})})})):Promise.resolve()}catch(t){return Promise.reject(t)}},I=function(t){var e;if(e=t,e?.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function D(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function M(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${t}`)}function V(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function W(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}return class{constructor(t){void 0===t&&(t={}),this.version="4.0.0-rc.28",this.options=void 0,this.plugins=[],this.cache=void 0,this.hooks=void 0,this.visit=void 0,this.classes=void 0,this.currentPageUrl=e(),this.getCurrentUrl=e,this.use=I,this.unuse=D,this.findPlugin=M,this.log=()=>{},this.getAnchorElement=S,this.navigate=A,this.performNavigation=x,this.delegateEvent=s,this.fetchPage=j,this.awaitAnimations=b,this.renderPage=N,this.replaceContent=q,this.animatePageIn=T,this.animatePageOut=L,this.scrollToContent=R,this.createVisit=v,this.resolveUrl=V,this.isSameResolvedUrl=W,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],ignoreVisit:function(t,e){let{el:n}=void 0===e?{}:e;return!!n?.closest("[data-no-swup]")},linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source},this.currentHistoryIndex=1,this.clickDelegate=void 0,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new l(this),this.classes=new p(this),this.hooks=new k(this),this.visit=this.createVisit({to:void 0}),this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}enable(){try{const t=this,{linkSelector:e}=t.options;return t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.plugins.forEach(e=>t.use(e)),r(null,{index:1}),Promise.resolve(h()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.options.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,e){let{el:n,event:r}=void 0===e?{}:e;const{origin:o,url:i,hash:s}=a.fromUrl(t);return o!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(i+s,{el:n,event:r})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:o,hash:i}=a.fromElement(e);this.shouldIgnoreVisit(n,{el:e,event:t})||(this.visit=this.createVisit({to:o,hash:i,el:e,event:t}),t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.call("link:newtab",{href:n}):0===t.button&&this.hooks.callSync("link:click",{el:e,event:t},()=>{const e=this.visit.from.url??"";t.preventDefault(),o&&o!==e?this.isSameResolvedUrl(o,e)||this.performNavigation(o):i?this.hooks.callSync("link:anchor",{hash:i},()=>{r(o+i),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>{this.scrollToContent()})}))}handlePopState(t){const n=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(e(),this.currentPageUrl))return;if(this.shouldIgnoreVisit(n,{event:t}))return;const{url:r,hash:o}=a.fromUrl(n);this.visit=this.createVisit({to:r,hash:o,event:t,animate:this.options.animateHistoryBrowsing,resetScroll:this.options.animateHistoryBrowsing}),this.visit.history.popstate=!0;const i=Number(t.state?.index);i&&(this.visit.history.direction=i-this.currentHistoryIndex>0?"forwards":"backwards"),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation(r)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t||self).Swup=e()}(this,function(){const t=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",e=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},n=function(t,n){void 0===n&&(n={});const r={url:t=t||e({hash:!0}),random:Math.random(),source:"swup",...n};history.pushState(r,"",t)},r=function(t,n){void 0===t&&(t=null),void 0===n&&(n={}),t=t||e({hash:!0});const r={...history.state,url:t,random:Math.random(),source:"swup",...n};history.replaceState(r,"",t)},o=new WeakMap;function i(t,e,n,r){if(!t&&!o.has(e))return!1;const i=o.get(e)??new WeakMap;o.set(e,i);const s=i.get(n)??new Set;i.set(n,s);const a=s.has(r);return t?s.add(r):s.delete(r),a&&t}const s=(t,e,n,r)=>{const o=new AbortController;return function(t,e,n,r={}){const{signal:o,base:s=document}=r;if(o?.aborted)return;const{once:a,...l}=r,c=s instanceof Document?s.documentElement:s,u=Boolean("object"==typeof r?r.capture:r),h=r=>{const o=function(t,e){let n=t.target;if(n instanceof Text&&(n=n.parentElement),n instanceof Element&&t.currentTarget instanceof Element){const r=n.closest(e);if(r&&t.currentTarget.contains(r))return r}}(r,t);if(o){const t=Object.assign(r,{delegateTarget:o});n.call(c,t),a&&(c.removeEventListener(e,h,l),i(!1,c,n,m))}},m=JSON.stringify({selector:t,type:e,capture:u});i(!0,c,n,m)||c.addEventListener(e,h,l),o?.addEventListener("abort",()=>{i(!1,c,n,m)})}(t,e,n,r={...r,signal:o.signal}),{destroy:()=>o.abort()}};class a extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new a(e)}static fromUrl(t){return new a(t)}}class l{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){return this.pages}has(t){return this.pages.has(this.resolve(t))}get(t){return this.pages.get(this.resolve(t))}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",{page:e})}update(t,e){t=this.resolve(t),e={...this.get(t),...e,url:t},this.pages.set(t,e)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear")}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=a.fromUrl(t);return this.swup.resolveUrl(e)}}const c=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},u=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},h=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function m(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}const f=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,d=t=>1e3*Number(t.slice(0,-1).replace(",","."));class p{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?u(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}function v(t){let{to:e,from:n=this.currentPageUrl,hash:r,animate:o=!0,animation:i,el:s,event:a,action:l="push",resetScroll:c=!0}=t;return{from:{url:n},to:{url:e},containers:this.options.containers,animation:{animate:o,wait:!1,name:i,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:s,event:a},history:{action:l,popstate:!1,direction:void 0},scroll:{reset:c,target:r}}}const g="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function w(t,e,n){if(!t.s){if(n instanceof y){if(!n.s)return void(n.o=w.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(w.bind(null,t,e),w.bind(null,t,2));t.s=e,t.v=n;const r=t.o;r&&r(t)}}const y=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const r=new t,o=this.s;if(o){const t=1&o?e:n;if(t){try{w(r,1,t(this.v))}catch(t){w(r,2,t)}return r}return this}return this.o=function(t){try{const o=t.v;1&t.s?w(r,1,e?e(o):o):n?w(r,1,n(o)):w(r,2,o)}catch(t){w(r,2,t)}},r},t}();function P(t){return t instanceof y&&1&t.s}class k{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:end"],this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n){void 0===n&&(n={});const r=this.get(t);if(!r)return console.warn(`Hook '${t}' not found.`),()=>{};const o=r.size+1,i={...n,id:o,hook:t,handler:e};return r.set(e,i),()=>this.off(t,e)}before(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,before:!0})}replace(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,replace:!0})}once(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n){try{const r=this,{before:o,handler:i,after:s}=r.getHandlers(t,n);return Promise.resolve(r.run(o,e)).then(function(){return Promise.resolve(r.run(i,e)).then(function(n){let[o]=n;return Promise.resolve(r.run(s,e)).then(function(){return r.dispatchDomEvent(t,e),o})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n){const{before:r,handler:o,after:i}=this.getHandlers(t,n);this.runSync(r,e);const[s]=this.runSync(o,e);return this.runSync(i,e),this.dispatchDomEvent(t,e),s}run(t,e){try{const n=this,r=[],o=function(t,e,n){if("function"==typeof t[g]){var r,o,i,s=t[g]();if(function t(n){try{for(;!(r=s.next()).done;)if((n=e(r.value))&&n.then){if(!P(n))return void n.then(t,i||(i=w.bind(null,o=new y,2)));n=n.v}o?w(o,1,n):o=n}catch(t){w(o||(o=new y),2,t)}}(),s.return){var a=function(t){try{r.done||s.return()}catch(t){}return t};if(o&&o.then)return o.then(a,function(t){throw a(t)});a()}return o}if(!("length"in t))throw new TypeError("Object is not iterable");for(var l=[],c=0;c<t.length;c++)l.push(t[c]);return function(t,e,n){var r,o,i=-1;return function n(s){try{for(;++i<t.length;)if((s=e(i))&&s.then){if(!P(s))return void s.then(n,o||(o=w.bind(null,r=new y,2)));s=s.v}r?w(r,1,s):r=s}catch(t){w(r||(r=new y),2,t)}}(),r}(l,function(t){return e(l[t])})}(t,function(t){let{hook:o,handler:i,defaultHandler:s,once:a}=t;return Promise.resolve(function(t,e){return void 0===e&&(e=[]),new Promise((n,r)=>{const o=t(...e);m(o)?o.then(n,r):n(o)})}(i,[n.swup.visit,e,s])).then(function(t){r.push(t),a&&n.off(o,i)})});return Promise.resolve(o&&o.then?o.then(function(){return r}):r)}catch(t){return Promise.reject(t)}}runSync(t,e){const n=[];for(const{hook:r,handler:o,defaultHandler:i,once:s}of t){const t=o(this.swup.visit,e,i);n.push(t),m(t)&&console.warn(`Promise returned from handler for synchronous hook '${r}'.Swup will not wait for it to resolve.`),s&&this.off(r,o)}return n}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const r=this.sortRegistrations,o=Array.from(n.values()),i=o.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(r),s=o.filter(t=>{let{replace:e}=t;return e}).sort(r),a=o.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(r),l=s.length>0;let c=[];if(e&&(c=[{id:0,hook:t,handler:e}],l)){const n=s.length-1,r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};c=[{id:0,hook:t,handler:s[n].handler,defaultHandler:r(n)}]}return{found:!0,before:i,handler:c,after:a,replaced:l}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e){document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:{hook:t,args:e,visit:this.swup.visit}}))}}const S=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||c(`a[name='${f(t)}']`)||c(`a[name='${f(e)}']`);return n||"top"!==t||(n=document.body),n},b=function(t){let{elements:e,selector:n}=t;try{if(!1===n&&!e)return Promise.resolve();let t=[];if(e)t=Array.from(e);else if(n&&(t=u(n,document.body),!t.length))return console.warn(`[swup] No elements found matching animationSelector \`${n}\``),Promise.resolve();const r=t.map(t=>function(t){const{type:e,timeout:n,propCount:r}=function(t,e){const n=window.getComputedStyle(t),r=C(n,`${E}Delay`),o=C(n,`${E}Duration`),i=$(r,o),s=C(n,`${U}Delay`),a=C(n,`${U}Duration`),l=$(s,a);let c=null,u=0,h=0;return e===E?i>0&&(c=E,u=i,h=o.length):e===U?l>0&&(c=U,u=l,h=a.length):(u=Math.max(i,l),c=u>0?i>l?E:U:null,h=c?c===E?o.length:a.length:0),{type:c,timeout:u,propCount:h}}(t);return!(!e||!n)&&new Promise(o=>{const i=`${e}end`,s=performance.now();let a=0;const l=()=>{t.removeEventListener(i,c),o()},c=e=>{if(e.target===t){if(!function(t){return[`${E}end`,`${U}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-s)/1e3<e.elapsedTime||++a>=r&&l()}};setTimeout(()=>{a<r&&l()},n+1),t.addEventListener(i,c)})}(t));return r.filter(Boolean).length>0?Promise.resolve(Promise.all(r)).then(function(){}):(n&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${n}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},E="transition",U="animation";function C(t,e){return(t[e]||"").split(", ")}function $(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>d(e)+d(t[n])))}const x=function(t,o){void 0===o&&(o={});try{const i=this;if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");const{el:s}=i.visit.trigger;i.visit.to.url=a.fromUrl(t).url,o.referrer=o.referrer||i.currentPageUrl,!1===o.animate&&(i.visit.animation.animate=!1),i.visit.animation.animate||i.classes.clear();const l=o.history||s?.getAttribute("data-swup-history")||void 0;l&&["push","replace"].includes(l)&&(i.visit.history.action=l);const c=o.animation||s?.getAttribute("data-swup-animation")||void 0;return c&&(i.visit.animation.name=c),Promise.resolve(function(s,a){try{var l=Promise.resolve(i.hooks.call("visit:start")).then(function(){function s(){const t=i.animatePageOut();return Promise.resolve(Promise.all([a,t])).then(function(t){let[e]=t;return Promise.resolve(i.renderPage(i.visit.to.url,e)).then(function(){return Promise.resolve(i.animatePageIn()).then(function(){return Promise.resolve(i.hooks.call("visit:end",void 0,()=>i.classes.clear())).then(function(){})})})})}const a=i.hooks.call("page:load",{options:o},function(t,e){try{function n(t){return e.page=t,e.cache=!!r,e.page}const r=i.cache.get(t.to.url);return Promise.resolve(r?n(r):Promise.resolve(i.fetchPage(t.to.url,e.options)).then(n))}catch(o){return Promise.reject(o)}});if(!i.visit.history.popstate){const e=t+(i.visit.scroll.target||"");"replace"===i.visit.history.action?r(e):n(e,{index:i.currentHistoryIndex+1})}i.currentPageUrl=e();const l=function(){if(i.visit.animation.wait)return Promise.resolve(a).then(function(t){let{html:e}=t;i.visit.to.html=e})}();return l&&l.then?l.then(s):s()})}catch(t){return a(t)}return l&&l.then?l.then(void 0,a):l}(0,function(t){t&&(console.error(t),i.options.skipPopStateHandling=()=>(window.location.href=i.visit.to.url,!0),window.history.go(-1))}))}catch(t){return Promise.reject(t)}};function A(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void(window.location.href=t);const{url:r,hash:o}=a.fromUrl(t);this.visit=this.createVisit({...n,to:r,hash:o}),this.performNavigation(r,e)}const j=function(t,e){void 0===e&&(e={});try{const n=this;t=a.fromUrl(t).url;const r={...n.options.requestHeaders,...e.headers};return e={...e,headers:r},Promise.resolve(n.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(e){const{status:r,url:o}=e;return Promise.resolve(e.text()).then(function(i){if(500===r)throw n.hooks.call("fetch:error",{status:r,response:e,url:o}),new H(`Server error: ${o}`,{status:r,url:o});if(!i)throw new H(`Empty response: ${o}`,{status:r,url:o});const{url:s}=a.fromUrl(o),l={url:s,html:i};return t===s&&n.cache.set(l.url,l),l})})}catch(t){return Promise.reject(t)}};class H extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.name="FetchError",this.url=e.url,this.status=e.status}}const L=function(){try{let n;const r=this;function e(e){return n?e:Promise.resolve(r.hooks.call("animation:out:start",void 0,e=>{r.classes.add("is-changing","is-leaving","is-animating"),e.history.popstate&&r.classes.add("is-popstate"),e.animation.name&&r.classes.add(`to-${t(e.animation.name)}`)})).then(function(){return Promise.resolve(r.hooks.call("animation:out:await",{skip:!1},function(t,e){let{skip:n}=e;try{return n?Promise.resolve():Promise.resolve(r.awaitAnimations({selector:t.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(r.hooks.call("animation:out:end")).then(function(){})})})}const o=function(){if(!r.visit.animation.animate)return Promise.resolve(r.hooks.call("animation:skip")).then(function(){n=1})}();return Promise.resolve(o&&o.then?o.then(e):e(o))}catch(i){return Promise.reject(i)}},q=function(t,e){let{html:n}=t,{containers:r}=void 0===e?this.options:e;const o=(new DOMParser).parseFromString(n,"text/html"),i=o.querySelector("title")?.innerText||"";return document.title=i,r.map(t=>{const e=document.querySelector(t),n=o.querySelector(t);return e&&n?(e.replaceWith(n),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),n||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean).length===r.length},R=function(){const t={behavior:"auto"},{target:e,reset:n}=this.visit.scroll;let r=!1;return e&&(r=this.hooks.callSync("scroll:anchor",{hash:e,options:t},(t,e)=>{let{hash:n,options:r}=e;const o=this.getAnchorElement(n||"");return o&&o.scrollIntoView(r),!!o})),n&&!r&&(r=this.hooks.callSync("scroll:top",{options:t},(t,e)=>{let{options:n}=e;return window.scrollTo({top:0,left:0,...n}),!0})),r},T=function(){try{const t=this;if(!t.visit.animation.animate)return Promise.resolve();const e=t.hooks.call("animation:in:await",{skip:!1},function(e,n){let{skip:r}=n;try{return r?Promise.resolve():Promise.resolve(t.awaitAnimations({selector:e.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}});return Promise.resolve(h()).then(function(){return Promise.resolve(t.hooks.call("animation:in:start",void 0,()=>{t.classes.remove("is-animating")})).then(function(){return Promise.resolve(e).then(function(){return Promise.resolve(t.hooks.call("animation:in:end")).then(function(){})})})})}catch(t){return Promise.reject(t)}},N=function(n,o){try{const i=this,{url:s,html:a}=o;return i.classes.remove("is-leaving"),i.isSameResolvedUrl(e(),n)?(i.isSameResolvedUrl(e(),s)||(r(s),i.currentPageUrl=e(),i.visit.to.url=i.currentPageUrl),i.visit.animation.animate&&i.classes.add("is-rendering"),i.visit.to.html=a,Promise.resolve(i.hooks.call("content:replace",{page:o},(e,n)=>{let{page:r}=n;if(!i.replaceContent(r,{containers:e.containers}))throw new Error("[swup] Container mismatch, aborting");e.animation.animate&&(i.classes.add("is-animating","is-changing","is-rendering"),e.animation.name&&i.classes.add(`to-${t(e.animation.name)}`))})).then(function(){return Promise.resolve(i.hooks.call("content:scroll",void 0,()=>i.scrollToContent())).then(function(){return Promise.resolve(i.hooks.call("page:view",{url:i.currentPageUrl,title:document.title})).then(function(){i.options.cache||i.cache.clear()})})})):Promise.resolve()}catch(t){return Promise.reject(t)}},I=function(t){var e;if(e=t,e?.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function D(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function M(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${t}`)}function V(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function W(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}return class{constructor(t){void 0===t&&(t={}),this.version="4.0.0-rc.30",this.options=void 0,this.plugins=[],this.cache=void 0,this.hooks=void 0,this.visit=void 0,this.classes=void 0,this.currentPageUrl=e(),this.getCurrentUrl=e,this.use=I,this.unuse=D,this.findPlugin=M,this.log=()=>{},this.getAnchorElement=S,this.navigate=A,this.performNavigation=x,this.delegateEvent=s,this.fetchPage=j,this.awaitAnimations=b,this.renderPage=N,this.replaceContent=q,this.animatePageIn=T,this.animatePageOut=L,this.scrollToContent=R,this.createVisit=v,this.resolveUrl=V,this.isSameResolvedUrl=W,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],ignoreVisit:function(t,e){let{el:n}=void 0===e?{}:e;return!!n?.closest("[data-no-swup]")},linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source},this.currentHistoryIndex=1,this.clickDelegate=void 0,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new l(this),this.classes=new p(this),this.hooks=new k(this),this.visit=this.createVisit({to:void 0}),this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}enable(){try{const t=this,{linkSelector:e}=t.options;return t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.plugins.forEach(e=>t.use(e)),r(null,{index:1}),Promise.resolve(h()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.options.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,e){let{el:n,event:r}=void 0===e?{}:e;const{origin:o,url:i,hash:s}=a.fromUrl(t);return o!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(i+s,{el:n,event:r})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:o,hash:i}=a.fromElement(e);this.shouldIgnoreVisit(n,{el:e,event:t})||(this.visit=this.createVisit({to:o,hash:i,el:e,event:t}),t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.call("link:newtab",{href:n}):0===t.button&&this.hooks.callSync("link:click",{el:e,event:t},()=>{const e=this.visit.from.url??"";t.preventDefault(),o&&o!==e?this.isSameResolvedUrl(o,e)||this.performNavigation(o):i?this.hooks.callSync("link:anchor",{hash:i},()=>{r(o+i),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>{this.scrollToContent()})}))}handlePopState(t){const n=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(e(),this.currentPageUrl))return;if(this.shouldIgnoreVisit(n,{event:t}))return;const{url:r,hash:o}=a.fromUrl(n);this.visit=this.createVisit({to:r,hash:o,event:t,animate:this.options.animateHistoryBrowsing,resetScroll:this.options.animateHistoryBrowsing}),this.visit.history.popstate=!0;const i=Number(t.state?.index);i&&(this.visit.history.direction=i-this.currentHistoryIndex>0?"forwards":"backwards"),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation(r)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}});
2
2
  //# sourceMappingURL=Swup.umd.js.map
@@ -1,5 +1,6 @@
1
1
  import type { Path } from 'path-to-regexp';
2
- import Swup, { type SwupCore, type Options } from './Swup.js';
2
+ import Swup from './Swup.js';
3
+ import type { SwupCore, Options } from './Swup.js';
3
4
  import type { CacheData } from './modules/Cache.js';
4
5
  import type { Visit, VisitFrom, VisitTo, VisitAnimation, VisitScroll, VisitHistory } from './modules/Visit.js';
5
6
  import type { HookDefinitions, HookName, HookOptions, HookUnregister, Handler } from './modules/Hooks.js';
@@ -7,4 +8,4 @@ import type { Plugin } from './modules/plugins.js';
7
8
  export default Swup;
8
9
  export * from './helpers.js';
9
10
  export * from './utils.js';
10
- export type { SwupCore as Swup, Options, Plugin, CacheData, Visit, VisitFrom, VisitTo, VisitAnimation, VisitScroll, VisitHistory, HookDefinitions, HookName, HookOptions, HookUnregister, Handler, Path };
11
+ export { SwupCore, Options, Plugin, CacheData, Visit, VisitFrom, VisitTo, VisitAnimation, VisitScroll, VisitHistory, HookDefinitions, HookName, HookOptions, HookUnregister, Handler, Path };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "swup",
3
3
  "amdName": "Swup",
4
- "version": "4.0.0-rc.28",
4
+ "version": "4.0.0-rc.30",
5
5
  "description": "Versatile and extensible page transition library for server-rendered websites",
6
6
  "type": "module",
7
7
  "source": "./src/Swup.ts",
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Path } from 'path-to-regexp';
2
2
 
3
- import Swup, { type SwupCore, type Options } from './Swup.js';
3
+ import Swup from './Swup.js';
4
+ import type { SwupCore, Options } from './Swup.js';
4
5
  import type { CacheData } from './modules/Cache.js';
5
6
  import type {
6
7
  Visit,
@@ -20,12 +21,10 @@ import type {
20
21
  import type { Plugin } from './modules/plugins.js';
21
22
 
22
23
  export default Swup;
23
-
24
24
  export * from './helpers.js';
25
25
  export * from './utils.js';
26
-
27
- export type {
28
- SwupCore as Swup,
26
+ export {
27
+ SwupCore,
29
28
  Options,
30
29
  Plugin,
31
30
  CacheData,