Comparing version 4.4.0 to 4.4.1
@@ -1,2 +0,2 @@ | ||
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 "${String(t)}":\n${String(e)}`)}};class c{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,s)=>{t.set(s,i({},e))}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?i({},e):e}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);const s=i({},this.get(t),e,{url:t});this.pages.set(t,s)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0)}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),d=(t,e=document)=>Array.from(e.querySelectorAll(t)),p=()=>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()?d(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,el:s,event:n}){return{id:Math.random(),from:{url:e},to:{url:t,hash:i},containers:this.options.containers,animation:{animate:!0,wait:!1,name:void 0,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:s,event:n},cache:{read:this.options.cache,write:this.options.cache},history:{action:"push",popstate:!1,direction:void 0},scroll:{reset:!0,target:void 0}}}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","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","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=Array.from(i.values()),n=this.sortRegistrations,o=s.filter(({before:t,replace:e})=>t&&!e).sort(n),r=s.filter(({replace:t})=>t).filter(t=>!0).sort(n),a=s.filter(({before:t,replace:e})=>!t&&!e).sort(n),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},E="transition",P="animation";async function U({elements:t,selector:e}){if(!1===e&&!t)return;let i=[];if(t)i=Array.from(t);else if(e&&(i=d(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,`${E}Delay`),n=C(i,`${E}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?E:P:null,u=h?h===E?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[`${E}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("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");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(e)}async function H(t={}){const e=this.visit,{el:i}=e.trigger;t.referrer=t.referrer||this.currentPageUrl,!1===t.animate&&(e.animation.animate=!1),e.animation.animate||this.classes.clear();const s=t.history||(null==i?void 0:i.getAttribute("data-swup-history"))||void 0;s&&["push","replace"].includes(s)&&(e.history.action=s);const a=t.animation||(null==i?void 0:i.getAttribute("data-swup-animation"))||void 0;var l,h;a&&(e.animation.name=a),"object"==typeof t.cache?(e.cache.read=null!=(l=t.cache.read)?l:e.cache.read,e.cache.write=null!=(h=t.cache.write)?h:e.cache.write):void 0!==t.cache&&(e.cache={read:!!t.cache,write:!!t.cache}),delete t.cache;try{await this.hooks.call("visit:start",void 0);const i=this.hooks.call("page:load",{options:t},async(t,e)=>{let i;return t.cache.read&&(i=this.cache.get(t.to.url)),e.page=i||await this.fetchPage(t.to.url,e.options),e.cache=!!i,e.page});if(!e.history.popstate){const t=e.to.url+e.to.hash;"replace"===e.history.action||e.to.url===this.currentPageUrl?r(t):(this.currentHistoryIndex++,o(t,{index:this.currentHistoryIndex}))}if(this.currentPageUrl=n(),e.animation.wait){const{html:t}=await i;e.to.html=t}await this.hooks.call("visit:transition",void 0,async t=>{const e=this.animatePageOut(),[s]=await Promise.all([i,e]);return t.id===this.visit.id&&(await this.renderPage(s),await this.animatePageIn(),!0)}),await this.hooks.call("visit:end",void 0,()=>this.classes.clear())}catch(t){if(!t||null!=t&&t.aborted)return;console.error(t),this.options.skipPopStateHandling=()=>(window.location.href=e.to.url+e.to.hash,!0),window.history.go(-1)}}class A extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}async function q(t,e={}){var s;t=l.fromUrl(t).url;const n=i({},this.options.requestHeaders,e.headers),o=null!=(s=e.timeout)?s:this.options.timeout,r=new AbortController,{signal:a}=r;e=i({},e,{headers:n,signal:a});let h,c=!1,u=null;o&&o>0&&(u=setTimeout(()=>{c=!0,r.abort("timeout")},o));try{h=await this.hooks.call("fetch:request",{url:t,options:e},(t,{url:e,options:i})=>fetch(e,i)),u&&clearTimeout(u)}catch(e){if(c)throw this.hooks.call("fetch:timeout",{url:t}),new A(`Request timed out: ${t}`,{url:t,timedOut:c});if("AbortError"===(null==e?void 0:e.name)||a.aborted)throw new A(`Request aborted: ${t}`,{url:t,aborted:!0});throw e}const{status:d,url:p}=h,m=await h.text();if(500===d)throw this.hooks.call("fetch:error",{status:d,response:h,url:p}),new A(`Server error: ${p}`,{status:d,url:p});if(!m)throw new A(`Empty response: ${p}`,{status:d,url:p});const{url:g}=l.fromUrl(p),f={url:g,html:m};return!this.visit.cache.write||e.method&&"GET"!==e.method||t!==g||this.cache.set(f.url,f),f}const I=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",void 0)):await this.hooks.call("animation:skip",void 0)},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)||"";document.title=n;const o=d('[data-swup-persist]:not([data-swup-persist=""])'),r=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);return o.forEach(t=>{const e=t.getAttribute("data-swup-persist"),i=u(`[data-swup-persist="${e}"]`);i&&i!==t&&i.replaceWith(t)}),r.length===e.length},L=function(){const t={behavior:"auto"},{target:e,reset:s}=this.visit.scroll,n=null!=e?e:this.visit.to.hash;let o=!1;return n&&(o=this.hooks.callSync("scroll:anchor",{hash:n,options:t},(t,{hash:e,options:i})=>{const s=this.getAnchorElement(e);return s&&s.scrollIntoView(i),!!s})),s&&!o&&(o=this.hooks.callSync("scroll:top",{options:t},(t,{options:e})=>(window.scrollTo(i({top:0,left:0},e)),!0))),o},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 p(),await this.hooks.call("animation:in:start",void 0,()=>{this.classes.remove("is-animating")}),await t,await this.hooks.call("animation:in:end",void 0)},T=async function(t){const{url:e,html:i}=t;this.classes.remove("is-leaving"),this.isSameResolvedUrl(n(),e)||(r(e),this.currentPageUrl=n(),this.visit.to.url=this.currentPageUrl),this.visit.animation.animate&&this.classes.add("is-rendering"),this.visit.to.html=i,await this.hooks.call("content:replace",{page:t},(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})},O=function(t){var e;if(e=t,Boolean(null==e?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 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${String(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)}const B={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]",linkToSelf:"scroll",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)},timeout:0};class _{constructor(t={}){var e,s;this.version="4.4.0",this.options=void 0,this.defaults=B,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.currentPageUrl=n(),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.use=O,this.unuse=D,this.findPlugin=M,this.log=()=>{},this.navigate=x,this.performNavigation=H,this.createVisit=k,this.delegateEvent=a,this.fetchPage=q,this.awaitAnimations=U,this.renderPage=T,this.replaceContent=R,this.animatePageIn=N,this.animatePageOut=I,this.scrollToContent=L,this.getAnchorElement=b,this.getCurrentUrl=n,this.resolveUrl=V,this.isSameResolvedUrl=W,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:""}),this.currentHistoryIndex=null!=(e=null==(s=history.state)?void 0:s.index)?e:1,this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}async enable(){var t;const{linkSelector:e}=this.options;this.clickDelegate=this.delegateEvent(e,"click",this.handleLinkClick),window.addEventListener("popstate",this.handlePopState),this.options.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),this.options.plugins.forEach(t=>this.use(t)),"swup"!==(null==(t=history.state)?void 0:t.source)&&r(null,{index:this.currentHistoryIndex}),await p(),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():n?this.hooks.callSync("link:anchor",{hash:n},()=>{r(s+n),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>"navigate"===this.options.linkToSelf?this.performNavigation():(r(s),this.scrollToContent()))}))}handlePopState(t){var e,i,s,o;const r=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;const{url:a,hash:h}=l.fromUrl(r);this.visit=this.createVisit({to:a,hash:h,event:t}),this.visit.history.popstate=!0;const c=null!=(s=null==(o=t.state)?void 0:o.index)?s:0;c&&c!==this.currentHistoryIndex&&(this.visit.history.direction=c-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=c),this.visit.animation.animate=!1,this.visit.scroll.reset=!1,this.visit.scroll.target=!1,this.options.animateHistoryBrowsing&&(this.visit.animation.animate=!0,this.visit.scroll.reset=!0),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation()})}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,p as nextTick,u as query,d as queryAll,g as runAsPromise,v as toMs,r as updateHistoryRecord}; | ||
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 "${String(t)}":\n${String(e)}`)}};class c extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}async function u(t,e={}){var s;t=l.fromUrl(t).url;const n=i({},this.options.requestHeaders,e.headers),o=null!=(s=e.timeout)?s:this.options.timeout,r=new AbortController,{signal:a}=r;e=i({},e,{headers:n,signal:a});let h,u=!1,d=null;o&&o>0&&(d=setTimeout(()=>{u=!0,r.abort("timeout")},o));try{h=await this.hooks.call("fetch:request",{url:t,options:e},(t,{url:e,options:i})=>fetch(e,i)),d&&clearTimeout(d)}catch(e){if(u)throw this.hooks.call("fetch:timeout",{url:t}),new c(`Request timed out: ${t}`,{url:t,timedOut:u});if("AbortError"===(null==e?void 0:e.name)||a.aborted)throw new c(`Request aborted: ${t}`,{url:t,aborted:!0});throw e}const{status:p,url:m}=h,g=await h.text();if(500===p)throw this.hooks.call("fetch:error",{status:p,response:h,url:m}),new c(`Server error: ${m}`,{status:p,url:m});if(!g)throw new c(`Empty response: ${m}`,{status:p,url:m});const{url:f}=l.fromUrl(m),w={url:f,html:g};return!this.visit.cache.write||e.method&&"GET"!==e.method||t!==f||this.cache.set(w.url,w),w}class d{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,s)=>{t.set(s,i({},e))}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?i({},e):e}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);const s=i({},this.get(t),e,{url:t});this.pages.set(t,s)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0)}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 p=(t,e=document)=>e.querySelector(t),m=(t,e=document)=>Array.from(e.querySelectorAll(t)),g=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function f(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function w(t,e=[]){return new Promise((i,s)=>{const n=t(...e);f(n)?n.then(i,s):i(n)})}function v(t){var e;return null==(e=t=t||document.body)?void 0:e.offsetHeight}const y=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,k=t=>1e3*Number(t.slice(0,-1).replace(",","."));class S{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(...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 b({to:t,from:e=this.currentPageUrl,hash:i,el:s,event:n}){return{id:Math.random(),from:{url:e},to:{url:t,hash:i},containers:this.options.containers,animation:{animate:!0,wait:!1,name:void 0,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:s,event:n},cache:{read:this.options.cache,write:this.options.cache},history:{action:"push",popstate:!1,direction:void 0},scroll:{reset:!0,target:void 0}}}class E{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","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","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 w(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),f(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=Array.from(i.values()),n=this.sortRegistrations,o=s.filter(({before:t,replace:e})=>t&&!e).sort(n),r=s.filter(({replace:t})=>t).filter(t=>!0).sort(n),a=s.filter(({before:t,replace:e})=>!t&&!e).sort(n),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 P=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)||p(`a[name='${y(t)}']`)||p(`a[name='${y(e)}']`);return i||"top"!==t||(i=document.body),i},U="transition",C="animation";async function $({elements:t,selector:e}){if(!1===e&&!t)return;let i=[];if(t)i=Array.from(t);else if(e&&(i=m(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=x(i,`${U}Delay`),n=x(i,`${U}Duration`),o=H(s,n),r=x(i,`${C}Delay`),a=x(i,`${C}Duration`),l=H(r,a);let h=null,c=0,u=0;return c=Math.max(o,l),h=c>0?o>l?U:C: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`,`${C}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 x(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,i)=>k(e)+k(t[i])))}function A(t,e={},s={}){if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");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(e)}async function q(t={}){this.navigating=!0;const e=this.visit,{el:i}=e.trigger;t.referrer=t.referrer||this.currentPageUrl,!1===t.animate&&(e.animation.animate=!1),e.animation.animate||this.classes.clear();const s=t.history||(null==i?void 0:i.getAttribute("data-swup-history"))||void 0;s&&["push","replace"].includes(s)&&(e.history.action=s);const a=t.animation||(null==i?void 0:i.getAttribute("data-swup-animation"))||void 0;var l,h;a&&(e.animation.name=a),"object"==typeof t.cache?(e.cache.read=null!=(l=t.cache.read)?l:e.cache.read,e.cache.write=null!=(h=t.cache.write)?h:e.cache.write):void 0!==t.cache&&(e.cache={read:!!t.cache,write:!!t.cache}),delete t.cache;try{await this.hooks.call("visit:start",void 0);const i=this.hooks.call("page:load",{options:t},async(t,e)=>{let i;return t.cache.read&&(i=this.cache.get(t.to.url)),e.page=i||await this.fetchPage(t.to.url,e.options),e.cache=!!i,e.page});if(!e.history.popstate){const t=e.to.url+e.to.hash;"replace"===e.history.action||e.to.url===this.currentPageUrl?r(t):(this.currentHistoryIndex++,o(t,{index:this.currentHistoryIndex}))}if(this.currentPageUrl=n(),e.animation.wait){const{html:t}=await i;e.to.html=t}await this.hooks.call("visit:transition",void 0,async t=>{const e=this.animatePageOut(),[s]=await Promise.all([i,e]);return t.id===this.visit.id&&(await this.renderPage(s),await this.animatePageIn(),!0)}),await this.hooks.call("visit:end",void 0,()=>this.classes.clear()),this.navigating=!1}catch(t){if(!t||null!=t&&t.aborted)return;console.error(t),this.options.skipPopStateHandling=()=>(window.location.href=e.to.url+e.to.hash,!0),window.history.go(-1)}}const I=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",void 0)):await this.hooks.call("animation:skip",void 0)},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)||"";document.title=n;const o=m('[data-swup-persist]:not([data-swup-persist=""])'),r=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);return o.forEach(t=>{const e=t.getAttribute("data-swup-persist"),i=p(`[data-swup-persist="${e}"]`);i&&i!==t&&i.replaceWith(t)}),r.length===e.length},L=function(){const t={behavior:"auto"},{target:e,reset:s}=this.visit.scroll,n=null!=e?e:this.visit.to.hash;let o=!1;return n&&(o=this.hooks.callSync("scroll:anchor",{hash:n,options:t},(t,{hash:e,options:i})=>{const s=this.getAnchorElement(e);return s&&s.scrollIntoView(i),!!s})),s&&!o&&(o=this.hooks.callSync("scroll:top",{options:t},(t,{options:e})=>(window.scrollTo(i({top:0,left:0},e)),!0))),o},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 g(),await this.hooks.call("animation:in:start",void 0,()=>{this.classes.remove("is-animating")}),await t,await this.hooks.call("animation:in:end",void 0)},T=async function(t){const{url:e,html:i}=t;this.classes.remove("is-leaving"),this.isSameResolvedUrl(n(),e)||(r(e),this.currentPageUrl=n(),this.visit.to.url=this.currentPageUrl),this.visit.animation.animate&&this.classes.add("is-rendering"),this.visit.to.html=i,await this.hooks.call("content:replace",{page:t},(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})},D=function(t){var e;if(e=t,Boolean(null==e?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 O(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${String(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)}const B={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]",linkToSelf:"scroll",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)},timeout:0};class _{constructor(t={}){var e,s;this.version="4.4.1",this.options=void 0,this.defaults=B,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.currentPageUrl=n(),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.navigating=!1,this.use=D,this.unuse=O,this.findPlugin=M,this.log=()=>{},this.navigate=A,this.performNavigation=q,this.createVisit=b,this.delegateEvent=a,this.fetchPage=u,this.awaitAnimations=$,this.renderPage=T,this.replaceContent=R,this.animatePageIn=N,this.animatePageOut=I,this.scrollToContent=L,this.getAnchorElement=P,this.getCurrentUrl=n,this.resolveUrl=V,this.isSameResolvedUrl=W,this.options=i({},this.defaults,t),this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new d(this),this.classes=new S(this),this.hooks=new E(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=null!=(e=null==(s=history.state)?void 0:s.index)?e:1,this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}async enable(){var t;const{linkSelector:e}=this.options;this.clickDelegate=this.delegateEvent(e,"click",this.handleLinkClick),window.addEventListener("popstate",this.handlePopState),this.options.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),this.options.plugins.forEach(t=>this.use(t)),"swup"!==(null==(t=history.state)?void 0:t.source)&&r(null,{index:this.currentHistoryIndex}),await g(),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.navigating&&s===this.visit.to.url?t.preventDefault():(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():n?this.hooks.callSync("link:anchor",{hash:n},()=>{r(s+n),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>"navigate"===this.options.linkToSelf?this.performNavigation():(r(s),this.scrollToContent()))})))}handlePopState(t){var e,i,s,o;const r=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;const{url:a,hash:h}=l.fromUrl(r);this.visit=this.createVisit({to:a,hash:h,event:t}),this.visit.history.popstate=!0;const c=null!=(s=null==(o=t.state)?void 0:o.index)?s:0;c&&c!==this.currentHistoryIndex&&(this.visit.history.direction=c-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=c),this.visit.animation.animate=!1,this.visit.scroll.reset=!1,this.visit.scroll.target=!1,this.options.animateHistoryBrowsing&&(this.visit.animation.animate=!0,this.visit.scroll.reset=!0),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation()})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}export{l as Location,s as classify,o as createHistoryRecord,_ as default,a as delegateEvent,y as escapeCssIdentifier,v as forceReflow,n as getCurrentUrl,f as isPromise,h as matchPath,g as nextTick,p as query,m as queryAll,w as runAsPromise,k as toMs,r as updateHistoryRecord}; | ||
//# sourceMappingURL=Swup.modern.js.map |
@@ -1,2 +0,2 @@ | ||
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 c=(t,n)=>{try{return e(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${String(t)}":\n${String(e)}`)}};class l{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,n)=>{t.set(n,{...e})}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?{...e}:e}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);const n={...this.get(t),...e,url:t};this.pages.set(t,n)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0)}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))},d=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function m(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);m(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,el:o,event:i}=t;return{id:Math.random(),from:{url:n},to:{url:e,hash:r},containers:this.options.containers,animation:{animate:!0,wait:!1,name:void 0,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:o,event:i},cache:{read:this.options.cache,write:this.options.cache},history:{action:"push",popstate:!1,direction:void 0},scroll:{reset:!0,target:void 0}}}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 E{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","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","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 c=[],l=0;l<t.length;l++)c.push(t[l]);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}(c,function(t){return e(c[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),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=Array.from(n.values()),o=this.sortRegistrations,i=r.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(o),s=r.filter(t=>{let{replace:e}=t;return e}).filter(t=>!0).sort(o),a=r.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(o),c=s.length>0;let l=[];if(e&&(l=[{id:0,hook:t,handler:e}],c)){const n=s.length-1,r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};l=[{id:0,hook:t,handler:s[n].handler,defaultHandler:r(n)}]}return{found:!0,before:i,handler:l,after:a,replaced:c}}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 U=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=H(n,`${$}Delay`),o=H(n,`${$}Duration`),i=A(r,o),s=H(n,`${x}Delay`),a=H(n,`${x}Duration`),c=A(s,a);let l=null,h=0,u=0;return e===$?i>0&&(l=$,h=i,u=o.length):e===x?c>0&&(l=x,h=c,u=a.length):(h=Math.max(i,c),l=h>0?i>c?$:x:null,u=l?l===$?o.length:a.length:0),{type:l,timeout:h,propCount:u}}(t);return!(!e||!n)&&new Promise(o=>{const i=`${e}end`,s=performance.now();let a=0;const c=()=>{t.removeEventListener(i,l),o()},l=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&&c()}};setTimeout(()=>{a<r&&c()},n+1),t.addEventListener(i,l)})}(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 H(t,e){return(t[e]||"").split(", ")}function A(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){void 0===t&&(t={});try{const e=this,n=e.visit,{el:s}=n.trigger;t.referrer=t.referrer||e.currentPageUrl,!1===t.animate&&(n.animation.animate=!1),n.animation.animate||e.classes.clear();const a=t.history||s?.getAttribute("data-swup-history")||void 0;a&&["push","replace"].includes(a)&&(n.history.action=a);const c=t.animation||s?.getAttribute("data-swup-animation")||void 0;return c&&(n.animation.name=c),"object"==typeof t.cache?(n.cache.read=t.cache.read??n.cache.read,n.cache.write=t.cache.write??n.cache.write):void 0!==t.cache&&(n.cache={read:!!t.cache,write:!!t.cache}),delete t.cache,Promise.resolve(function(s,a){try{var c=Promise.resolve(e.hooks.call("visit:start",void 0)).then(function(){function s(){return Promise.resolve(e.hooks.call("visit:transition",void 0,function(t){try{const n=e.animatePageOut();return Promise.resolve(Promise.all([a,n])).then(function(n){let[r]=n;return t.id===e.visit.id&&Promise.resolve(e.renderPage(r)).then(function(){return Promise.resolve(e.animatePageIn()).then(function(){return!0})})})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(e.hooks.call("visit:end",void 0,()=>e.classes.clear())).then(function(){})})}const a=e.hooks.call("page:load",{options:t},function(t,n){try{function r(t){return n.page=t,n.cache=!!o,n.page}let o;return t.cache.read&&(o=e.cache.get(t.to.url)),Promise.resolve(o?r(o):Promise.resolve(e.fetchPage(t.to.url,n.options)).then(r))}catch(i){return Promise.reject(i)}});if(!n.history.popstate){const t=n.to.url+n.to.hash;"replace"===n.history.action||n.to.url===e.currentPageUrl?i(t):(e.currentHistoryIndex++,o(t,{index:e.currentHistoryIndex}))}e.currentPageUrl=r();const c=function(){if(n.animation.wait)return Promise.resolve(a).then(function(t){let{html:e}=t;n.to.html=e})}();return c&&c.then?c.then(s):s()})}catch(t){return a(t)}return c&&c.then?c.then(void 0,a):c}(0,function(t){t&&!t?.aborted&&(console.error(t),e.options.skipPopStateHandling=()=>(window.location.href=n.to.url+n.to.hash,!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={}),"string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");if(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(e)}const I=function(t,e){void 0===e&&(e={});try{const r=this;function n(n){const{status:o,url:i}=l;return Promise.resolve(l.text()).then(function(n){if(500===o)throw r.hooks.call("fetch:error",{status:o,response:l,url:i}),new R(`Server error: ${i}`,{status:o,url:i});if(!n)throw new R(`Empty response: ${i}`,{status:o,url:i});const{url:s}=a.fromUrl(i),c={url:s,html:n};return!r.visit.cache.write||e.method&&"GET"!==e.method||t!==s||r.cache.set(c.url,c),c})}t=a.fromUrl(t).url;const o={...r.options.requestHeaders,...e.headers},i=e.timeout??r.options.timeout,s=new AbortController,{signal:c}=s;e={...e,headers:o,signal:c};let l,h=!1,u=null;i&&i>0&&(u=setTimeout(()=>{h=!0,s.abort("timeout")},i));const d=function(n,o){try{var i=Promise.resolve(r.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(t){l=t,u&&clearTimeout(u)})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(h)throw r.hooks.call("fetch:timeout",{url:t}),new R(`Request timed out: ${t}`,{url:t,timedOut:h});if("AbortError"===e?.name||c.aborted)throw new R(`Request aborted: ${t}`,{url:t,aborted:!0});throw e});return Promise.resolve(d&&d.then?d.then(n):n())}catch(m){return Promise.reject(m)}};class R extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}const L=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",void 0)).then(function(){})})})}const o=function(){if(!r.visit.animation.animate)return Promise.resolve(r.hooks.call("animation:skip",void 0)).then(function(){e=1})}();return Promise.resolve(o&&o.then?o.then(t):t(o))}catch(i){return Promise.reject(i)}},T=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||"";document.title=i;const s=u('[data-swup-persist]:not([data-swup-persist=""])'),a=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);return s.forEach(t=>{const e=t.getAttribute("data-swup-persist"),n=h(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),a.length===r.length},N=function(){const t={behavior:"auto"},{target:e,reset:n}=this.visit.scroll,r=e??this.visit.to.hash;let o=!1;return r&&(o=this.hooks.callSync("scroll:anchor",{hash:r,options:t},(t,e)=>{let{hash:n,options:r}=e;const o=this.getAnchorElement(n);return o&&o.scrollIntoView(r),!!o})),n&&!o&&(o=this.hooks.callSync("scroll:top",{options:t},(t,e)=>{let{options:n}=e;return window.scrollTo({top:0,left:0,...n}),!0})),o},D=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(d()).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",void 0)).then(function(){})})})})}catch(t){return Promise.reject(t)}},M=function(t){try{const e=this,{url:o,html:s}=t;return e.classes.remove("is-leaving"),e.isSameResolvedUrl(r(),o)||(i(o),e.currentPageUrl=r(),e.visit.to.url=e.currentPageUrl),e.visit.animation.animate&&e.classes.add("is-rendering"),e.visit.to.html=s,Promise.resolve(e.hooks.call("content:replace",{page:t},(t,r)=>{let{page:o}=r;if(!e.replaceContent(o,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(e.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&e.classes.add(`to-${n(t.animation.name)}`))})).then(function(){return Promise.resolve(e.hooks.call("content:scroll",void 0,()=>e.scrollToContent())).then(function(){return Promise.resolve(e.hooks.call("page:view",{url:e.currentPageUrl,title:document.title})).then(function(){})})})}catch(t){return Promise.reject(t)}},V=function(t){var e;if(e=t,Boolean(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 O(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 W(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${String(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 _(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}const F={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]",linkToSelf:"scroll",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source,timeout:0};class K{constructor(t){void 0===t&&(t={}),this.version="4.4.0",this.options=void 0,this.defaults=F,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.currentPageUrl=r(),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.use=V,this.unuse=O,this.findPlugin=W,this.log=()=>{},this.navigate=j,this.performNavigation=q,this.createVisit=y,this.delegateEvent=s,this.fetchPage=I,this.awaitAnimations=C,this.renderPage=M,this.replaceContent=T,this.animatePageIn=D,this.animatePageOut=L,this.scrollToContent=N,this.getAnchorElement=U,this.getCurrentUrl=r,this.resolveUrl=B,this.isSameResolvedUrl=_,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 w(this),this.hooks=new E(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=history.state?.index??1,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.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),t.options.plugins.forEach(e=>t.use(e)),"swup"!==history.state?.source&&i(null,{index:t.currentHistoryIndex}),Promise.resolve(d()).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():o?this.hooks.callSync("link:anchor",{hash:o},()=>{i(r+o),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>"navigate"===this.options.linkToSelf?this.performNavigation():(i(r),this.scrollToContent()))}))}handlePopState(t){const e=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(r(),this.currentPageUrl))return;const{url:n,hash:o}=a.fromUrl(e);this.visit=this.createVisit({to:n,hash:o,event:t}),this.visit.history.popstate=!0;const i=t.state?.index??0;i&&i!==this.currentHistoryIndex&&(this.visit.history.direction=i-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=i),this.visit.animation.animate=!1,this.visit.scroll.reset=!1,this.visit.scroll.target=!1,this.options.animateHistoryBrowsing&&(this.visit.animation.animate=!0,this.visit.scroll.reset=!0),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation()})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}export{a as Location,n as classify,o as createHistoryRecord,K as default,s as delegateEvent,v as escapeCssIdentifier,p as forceReflow,r as getCurrentUrl,m as isPromise,c as matchPath,d as nextTick,h as query,u as queryAll,f as runAsPromise,g as toMs,i as updateHistoryRecord}; | ||
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:"")},i=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)},o=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,i)=>{const o=new AbortController;return i={...i,signal:o.signal},t(e,n,r,i),{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)}}const c=(t,n)=>{try{return e(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${String(t)}":\n${String(e)}`)}},l=function(t,e){void 0===e&&(e={});try{const r=this;function n(n){const{status:i,url:o}=l;return Promise.resolve(l.text()).then(function(n){if(500===i)throw r.hooks.call("fetch:error",{status:i,response:l,url:o}),new h(`Server error: ${o}`,{status:i,url:o});if(!n)throw new h(`Empty response: ${o}`,{status:i,url:o});const{url:s}=a.fromUrl(o),c={url:s,html:n};return!r.visit.cache.write||e.method&&"GET"!==e.method||t!==s||r.cache.set(c.url,c),c})}t=a.fromUrl(t).url;const i={...r.options.requestHeaders,...e.headers},o=e.timeout??r.options.timeout,s=new AbortController,{signal:c}=s;e={...e,headers:i,signal:c};let l,u=!1,d=null;o&&o>0&&(d=setTimeout(()=>{u=!0,s.abort("timeout")},o));const m=function(n,i){try{var o=Promise.resolve(r.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(t){l=t,d&&clearTimeout(d)})}catch(t){return i(t)}return o&&o.then?o.then(void 0,i):o}(0,function(e){if(u)throw r.hooks.call("fetch:timeout",{url:t}),new h(`Request timed out: ${t}`,{url:t,timedOut:u});if("AbortError"===e?.name||c.aborted)throw new h(`Request aborted: ${t}`,{url:t,aborted:!0});throw e});return Promise.resolve(m&&m.then?m.then(n):n())}catch(f){return Promise.reject(f)}};class h extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}class u{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,n)=>{t.set(n,{...e})}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?{...e}:e}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);const n={...this.get(t),...e,url:t};this.pages.set(t,n)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0)}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 d=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))},f=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function p(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function v(t,e){return void 0===e&&(e=[]),new Promise((n,r)=>{const i=t(...e);p(i)?i.then(n,r):n(i)})}function g(t){return t=t||document.body,t?.offsetHeight}const w=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,y=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()?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 k(t){let{to:e,from:n=this.currentPageUrl,hash:r,el:i,event:o}=t;return{id:Math.random(),from:{url:n},to:{url:e,hash:r},containers:this.options.containers,animation:{animate:!0,wait:!1,name:void 0,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:i,event:o},cache:{read:this.options.cache,write:this.options.cache},history:{action:"push",popstate:!1,direction:void 0},scroll:{reset:!0,target:void 0}}}const S="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function b(t,e,n){if(!t.s){if(n instanceof E){if(!n.s)return void(n.o=b.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(b.bind(null,t,e),b.bind(null,t,2));t.s=e,t.v=n;const r=t.o;r&&r(t)}}const E=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const r=new t,i=this.s;if(i){const t=1&i?e:n;if(t){try{b(r,1,t(this.v))}catch(t){b(r,2,t)}return r}return this}return this.o=function(t){try{const i=t.v;1&t.s?b(r,1,e?e(i):i):n?b(r,1,n(i)):b(r,2,i)}catch(t){b(r,2,t)}},r},t}();function U(t){return t instanceof E&&1&t.s}class C{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","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","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 i=r.size+1,o={...n,id:i,hook:t,handler:e};return r.set(e,o),()=>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:i,handler:o,after:s}=r.getHandlers(t,n);return Promise.resolve(r.run(i,e)).then(function(){return Promise.resolve(r.run(o,e)).then(function(n){let[i]=n;return Promise.resolve(r.run(s,e)).then(function(){return r.dispatchDomEvent(t,e),i})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n){const{before:r,handler:i,after:o}=this.getHandlers(t,n);this.runSync(r,e);const[s]=this.runSync(i,e);return this.runSync(o,e),this.dispatchDomEvent(t,e),s}run(t,e){try{const n=this,r=[],i=function(t,e,n){if("function"==typeof t[S]){var r,i,o,s=t[S]();if(function t(n){try{for(;!(r=s.next()).done;)if((n=e(r.value))&&n.then){if(!U(n))return void n.then(t,o||(o=b.bind(null,i=new E,2)));n=n.v}i?b(i,1,n):i=n}catch(t){b(i||(i=new E),2,t)}}(),s.return){var a=function(t){try{r.done||s.return()}catch(t){}return t};if(i&&i.then)return i.then(a,function(t){throw a(t)});a()}return i}if(!("length"in t))throw new TypeError("Object is not iterable");for(var c=[],l=0;l<t.length;l++)c.push(t[l]);return function(t,e,n){var r,i,o=-1;return function n(s){try{for(;++o<t.length;)if((s=e(o))&&s.then){if(!U(s))return void s.then(n,i||(i=b.bind(null,r=new E,2)));s=s.v}r?b(r,1,s):r=s}catch(t){b(r||(r=new E),2,t)}}(),r}(c,function(t){return e(c[t])})}(t,function(t){let{hook:i,handler:o,defaultHandler:s,once:a}=t;return Promise.resolve(v(o,[n.swup.visit,e,s])).then(function(t){r.push(t),a&&n.off(i,o)})});return Promise.resolve(i&&i.then?i.then(function(){return r}):r)}catch(t){return Promise.reject(t)}}runSync(t,e){const n=[];for(const{hook:r,handler:i,defaultHandler:o,once:s}of t){const t=i(this.swup.visit,e,o);n.push(t),p(t)&&console.warn(`Promise returned from handler for synchronous hook '${r}'.Swup will not wait for it to resolve.`),s&&this.off(r,i)}return n}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const r=Array.from(n.values()),i=this.sortRegistrations,o=r.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(i),s=r.filter(t=>{let{replace:e}=t;return e}).filter(t=>!0).sort(i),a=r.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(i),c=s.length>0;let l=[];if(e&&(l=[{id:0,hook:t,handler:e}],c)){const n=s.length-1,r=t=>{const n=s[t-1];return n?(e,i)=>n.handler(e,i,r(t-1)):e};l=[{id:0,hook:t,handler:s[n].handler,defaultHandler:r(n)}]}return{found:!0,before:o,handler:l,after:a,replaced:c}}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 $=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)||d(`a[name='${w(t)}']`)||d(`a[name='${w(e)}']`);return n||"top"!==t||(n=document.body),n},x=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=q(n,`${H}Delay`),i=q(n,`${H}Duration`),o=j(r,i),s=q(n,`${A}Delay`),a=q(n,`${A}Duration`),c=j(s,a);let l=null,h=0,u=0;return e===H?o>0&&(l=H,h=o,u=i.length):e===A?c>0&&(l=A,h=c,u=a.length):(h=Math.max(o,c),l=h>0?o>c?H:A:null,u=l?l===H?i.length:a.length:0),{type:l,timeout:h,propCount:u}}(t);return!(!e||!n)&&new Promise(i=>{const o=`${e}end`,s=performance.now();let a=0;const c=()=>{t.removeEventListener(o,l),i()},l=e=>{if(e.target===t){if(!function(t){return[`${H}end`,`${A}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-s)/1e3<e.elapsedTime||++a>=r&&c()}};setTimeout(()=>{a<r&&c()},n+1),t.addEventListener(o,l)})}(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)}},H="transition",A="animation";function q(t,e){return(t[e]||"").split(", ")}function j(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>y(e)+y(t[n])))}const I=function(t){void 0===t&&(t={});try{const e=this;e.navigating=!0;const n=e.visit,{el:s}=n.trigger;t.referrer=t.referrer||e.currentPageUrl,!1===t.animate&&(n.animation.animate=!1),n.animation.animate||e.classes.clear();const a=t.history||s?.getAttribute("data-swup-history")||void 0;a&&["push","replace"].includes(a)&&(n.history.action=a);const c=t.animation||s?.getAttribute("data-swup-animation")||void 0;return c&&(n.animation.name=c),"object"==typeof t.cache?(n.cache.read=t.cache.read??n.cache.read,n.cache.write=t.cache.write??n.cache.write):void 0!==t.cache&&(n.cache={read:!!t.cache,write:!!t.cache}),delete t.cache,Promise.resolve(function(s,a){try{var c=Promise.resolve(e.hooks.call("visit:start",void 0)).then(function(){function s(){return Promise.resolve(e.hooks.call("visit:transition",void 0,function(t){try{const n=e.animatePageOut();return Promise.resolve(Promise.all([a,n])).then(function(n){let[r]=n;return t.id===e.visit.id&&Promise.resolve(e.renderPage(r)).then(function(){return Promise.resolve(e.animatePageIn()).then(function(){return!0})})})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(e.hooks.call("visit:end",void 0,()=>e.classes.clear())).then(function(){e.navigating=!1})})}const a=e.hooks.call("page:load",{options:t},function(t,n){try{function r(t){return n.page=t,n.cache=!!i,n.page}let i;return t.cache.read&&(i=e.cache.get(t.to.url)),Promise.resolve(i?r(i):Promise.resolve(e.fetchPage(t.to.url,n.options)).then(r))}catch(o){return Promise.reject(o)}});if(!n.history.popstate){const t=n.to.url+n.to.hash;"replace"===n.history.action||n.to.url===e.currentPageUrl?o(t):(e.currentHistoryIndex++,i(t,{index:e.currentHistoryIndex}))}e.currentPageUrl=r();const c=function(){if(n.animation.wait)return Promise.resolve(a).then(function(t){let{html:e}=t;n.to.html=e})}();return c&&c.then?c.then(s):s()})}catch(t){return a(t)}return c&&c.then?c.then(void 0,a):c}(0,function(t){t&&!t?.aborted&&(console.error(t),e.options.skipPopStateHandling=()=>(window.location.href=n.to.url+n.to.hash,!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={}),"string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");if(this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void(window.location.href=t);const{url:r,hash:i}=a.fromUrl(t);this.visit=this.createVisit({...n,to:r,hash:i}),this.performNavigation(e)}const L=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",void 0)).then(function(){})})})}const i=function(){if(!r.visit.animation.animate)return Promise.resolve(r.hooks.call("animation:skip",void 0)).then(function(){e=1})}();return Promise.resolve(i&&i.then?i.then(t):t(i))}catch(o){return Promise.reject(o)}},T=function(t,e){let{html:n}=t,{containers:r}=void 0===e?this.options:e;const i=(new DOMParser).parseFromString(n,"text/html"),o=i.querySelector("title")?.innerText||"";document.title=o;const s=m('[data-swup-persist]:not([data-swup-persist=""])'),a=r.map(t=>{const e=document.querySelector(t),n=i.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);return s.forEach(t=>{const e=t.getAttribute("data-swup-persist"),n=d(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),a.length===r.length},N=function(){const t={behavior:"auto"},{target:e,reset:n}=this.visit.scroll,r=e??this.visit.to.hash;let i=!1;return r&&(i=this.hooks.callSync("scroll:anchor",{hash:r,options:t},(t,e)=>{let{hash:n,options:r}=e;const i=this.getAnchorElement(n);return i&&i.scrollIntoView(r),!!i})),n&&!i&&(i=this.hooks.callSync("scroll:top",{options:t},(t,e)=>{let{options:n}=e;return window.scrollTo({top:0,left:0,...n}),!0})),i},D=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(f()).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",void 0)).then(function(){})})})})}catch(t){return Promise.reject(t)}},M=function(t){try{const e=this,{url:i,html:s}=t;return e.classes.remove("is-leaving"),e.isSameResolvedUrl(r(),i)||(o(i),e.currentPageUrl=r(),e.visit.to.url=e.currentPageUrl),e.visit.animation.animate&&e.classes.add("is-rendering"),e.visit.to.html=s,Promise.resolve(e.hooks.call("content:replace",{page:t},(t,r)=>{let{page:i}=r;if(!e.replaceContent(i,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(e.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&e.classes.add(`to-${n(t.animation.name)}`))})).then(function(){return Promise.resolve(e.hooks.call("content:scroll",void 0,()=>e.scrollToContent())).then(function(){return Promise.resolve(e.hooks.call("page:view",{url:e.currentPageUrl,title:document.title})).then(function(){})})})}catch(t){return Promise.reject(t)}},V=function(t){var e;if(e=t,Boolean(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 O(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 W(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${String(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 _(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}const F={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]",linkToSelf:"scroll",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source,timeout:0};class K{constructor(t){void 0===t&&(t={}),this.version="4.4.1",this.options=void 0,this.defaults=F,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.currentPageUrl=r(),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.navigating=!1,this.use=V,this.unuse=O,this.findPlugin=W,this.log=()=>{},this.navigate=R,this.performNavigation=I,this.createVisit=k,this.delegateEvent=s,this.fetchPage=l,this.awaitAnimations=x,this.renderPage=M,this.replaceContent=T,this.animatePageIn=D,this.animatePageOut=L,this.scrollToContent=N,this.getAnchorElement=$,this.getCurrentUrl=r,this.resolveUrl=B,this.isSameResolvedUrl=_,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 P(this),this.hooks=new C(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=history.state?.index??1,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.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),t.options.plugins.forEach(e=>t.use(e)),"swup"!==history.state?.source&&o(null,{index:t.currentHistoryIndex}),Promise.resolve(f()).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:i,url:o,hash:s}=a.fromUrl(t);return i!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(o+s,{el:n,event:r})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:r,hash:i}=a.fromElement(e);this.shouldIgnoreVisit(n,{el:e,event:t})||(this.navigating&&r===this.visit.to.url?t.preventDefault():(this.visit=this.createVisit({to:r,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(),r&&r!==e?this.isSameResolvedUrl(r,e)||this.performNavigation():i?this.hooks.callSync("link:anchor",{hash:i},()=>{o(r+i),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>"navigate"===this.options.linkToSelf?this.performNavigation():(o(r),this.scrollToContent()))})))}handlePopState(t){const e=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(r(),this.currentPageUrl))return;const{url:n,hash:i}=a.fromUrl(e);this.visit=this.createVisit({to:n,hash:i,event:t}),this.visit.history.popstate=!0;const o=t.state?.index??0;o&&o!==this.currentHistoryIndex&&(this.visit.history.direction=o-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=o),this.visit.animation.animate=!1,this.visit.scroll.reset=!1,this.visit.scroll.target=!1,this.options.animateHistoryBrowsing&&(this.visit.animation.animate=!0,this.visit.scroll.reset=!0),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation()})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}export{a as Location,n as classify,i as createHistoryRecord,K as default,s as delegateEvent,w as escapeCssIdentifier,g as forceReflow,r as getCurrentUrl,p as isPromise,c as matchPath,f as nextTick,d as query,m as queryAll,v as runAsPromise,y as toMs,o as updateHistoryRecord}; | ||
//# sourceMappingURL=Swup.module.js.map |
@@ -1,2 +0,2 @@ | ||
!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,...c}=r,l=s instanceof Document?s.documentElement:s,h=Boolean("object"==typeof r?r.capture:r),u=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(l,t),a&&(l.removeEventListener(e,u,c),i(!1,l,n,d))}},d=JSON.stringify({selector:t,type:e,capture:h});i(!0,l,n,d)||l.addEventListener(e,u,c),o?.addEventListener("abort",()=>{i(!1,l,n,d)})}(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 c{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,n)=>{t.set(n,{...e})}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?{...e}:e}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);const n={...this.get(t),...e,url:t};this.pages.set(t,n)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0)}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 l=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},h=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},u=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function d(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}const m=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,f=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()?h(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,el:o,event:i}=t;return{id:Math.random(),from:{url:n},to:{url:e,hash:r},containers:this.options.containers,animation:{animate:!0,wait:!1,name:void 0,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:o,event:i},cache:{read:this.options.cache,write:this.options.cache},history:{action:"push",popstate:!1,direction:void 0},scroll:{reset:!0,target:void 0}}}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","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","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 c=[],l=0;l<t.length;l++)c.push(t[l]);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}(c,function(t){return e(c[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);d(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),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=Array.from(n.values()),o=this.sortRegistrations,i=r.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(o),s=r.filter(t=>{let{replace:e}=t;return e}).filter(t=>!0).sort(o),a=r.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(o),c=s.length>0;let l=[];if(e&&(l=[{id:0,hook:t,handler:e}],c)){const n=s.length-1,r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};l=[{id:0,hook:t,handler:s[n].handler,defaultHandler:r(n)}]}return{found:!0,before:i,handler:l,after:a,replaced:c}}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 b=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)||l(`a[name='${m(t)}']`)||l(`a[name='${m(e)}']`);return n||"top"!==t||(n=document.body),n},S=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=h(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=x(r,o),s=C(n,`${U}Delay`),a=C(n,`${U}Duration`),c=x(s,a);let l=null,h=0,u=0;return e===E?i>0&&(l=E,h=i,u=o.length):e===U?c>0&&(l=U,h=c,u=a.length):(h=Math.max(i,c),l=h>0?i>c?E:U:null,u=l?l===E?o.length:a.length:0),{type:l,timeout:h,propCount:u}}(t);return!(!e||!n)&&new Promise(o=>{const i=`${e}end`,s=performance.now();let a=0;const c=()=>{t.removeEventListener(i,l),o()},l=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&&c()}};setTimeout(()=>{a<r&&c()},n+1),t.addEventListener(i,l)})}(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 x(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>f(e)+f(t[n])))}const $=function(t){void 0===t&&(t={});try{const o=this,i=o.visit,{el:s}=i.trigger;t.referrer=t.referrer||o.currentPageUrl,!1===t.animate&&(i.animation.animate=!1),i.animation.animate||o.classes.clear();const a=t.history||s?.getAttribute("data-swup-history")||void 0;a&&["push","replace"].includes(a)&&(i.history.action=a);const c=t.animation||s?.getAttribute("data-swup-animation")||void 0;return c&&(i.animation.name=c),"object"==typeof t.cache?(i.cache.read=t.cache.read??i.cache.read,i.cache.write=t.cache.write??i.cache.write):void 0!==t.cache&&(i.cache={read:!!t.cache,write:!!t.cache}),delete t.cache,Promise.resolve(function(s,a){try{var c=Promise.resolve(o.hooks.call("visit:start",void 0)).then(function(){function s(){return Promise.resolve(o.hooks.call("visit:transition",void 0,function(t){try{const e=o.animatePageOut();return Promise.resolve(Promise.all([a,e])).then(function(e){let[n]=e;return t.id===o.visit.id&&Promise.resolve(o.renderPage(n)).then(function(){return Promise.resolve(o.animatePageIn()).then(function(){return!0})})})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(o.hooks.call("visit:end",void 0,()=>o.classes.clear())).then(function(){})})}const a=o.hooks.call("page:load",{options:t},function(t,e){try{function n(t){return e.page=t,e.cache=!!r,e.page}let r;return t.cache.read&&(r=o.cache.get(t.to.url)),Promise.resolve(r?n(r):Promise.resolve(o.fetchPage(t.to.url,e.options)).then(n))}catch(i){return Promise.reject(i)}});if(!i.history.popstate){const t=i.to.url+i.to.hash;"replace"===i.history.action||i.to.url===o.currentPageUrl?r(t):(o.currentHistoryIndex++,n(t,{index:o.currentHistoryIndex}))}o.currentPageUrl=e();const c=function(){if(i.animation.wait)return Promise.resolve(a).then(function(t){let{html:e}=t;i.to.html=e})}();return c&&c.then?c.then(s):s()})}catch(t){return a(t)}return c&&c.then?c.then(void 0,a):c}(0,function(t){t&&!t?.aborted&&(console.error(t),o.options.skipPopStateHandling=()=>(window.location.href=i.to.url+i.to.hash,!0),window.history.go(-1))}))}catch(t){return Promise.reject(t)}};function H(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),"string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");if(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(e)}const A=function(t,e){void 0===e&&(e={});try{const r=this;function n(n){const{status:o,url:i}=l;return Promise.resolve(l.text()).then(function(n){if(500===o)throw r.hooks.call("fetch:error",{status:o,response:l,url:i}),new j(`Server error: ${i}`,{status:o,url:i});if(!n)throw new j(`Empty response: ${i}`,{status:o,url:i});const{url:s}=a.fromUrl(i),c={url:s,html:n};return!r.visit.cache.write||e.method&&"GET"!==e.method||t!==s||r.cache.set(c.url,c),c})}t=a.fromUrl(t).url;const o={...r.options.requestHeaders,...e.headers},i=e.timeout??r.options.timeout,s=new AbortController,{signal:c}=s;e={...e,headers:o,signal:c};let l,h=!1,u=null;i&&i>0&&(u=setTimeout(()=>{h=!0,s.abort("timeout")},i));const d=function(n,o){try{var i=Promise.resolve(r.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(t){l=t,u&&clearTimeout(u)})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(h)throw r.hooks.call("fetch:timeout",{url:t}),new j(`Request timed out: ${t}`,{url:t,timedOut:h});if("AbortError"===e?.name||c.aborted)throw new j(`Request aborted: ${t}`,{url:t,aborted:!0});throw e});return Promise.resolve(d&&d.then?d.then(n):n())}catch(m){return Promise.reject(m)}};class j extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}const T=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",void 0)).then(function(){})})})}const o=function(){if(!r.visit.animation.animate)return Promise.resolve(r.hooks.call("animation:skip",void 0)).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||"";document.title=i;const s=h('[data-swup-persist]:not([data-swup-persist=""])'),a=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);return s.forEach(t=>{const e=t.getAttribute("data-swup-persist"),n=l(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),a.length===r.length},L=function(){const t={behavior:"auto"},{target:e,reset:n}=this.visit.scroll,r=e??this.visit.to.hash;let o=!1;return r&&(o=this.hooks.callSync("scroll:anchor",{hash:r,options:t},(t,e)=>{let{hash:n,options:r}=e;const o=this.getAnchorElement(n);return o&&o.scrollIntoView(r),!!o})),n&&!o&&(o=this.hooks.callSync("scroll:top",{options:t},(t,e)=>{let{options:n}=e;return window.scrollTo({top:0,left:0,...n}),!0})),o},I=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(u()).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",void 0)).then(function(){})})})})}catch(t){return Promise.reject(t)}},R=function(n){try{const o=this,{url:i,html:s}=n;return o.classes.remove("is-leaving"),o.isSameResolvedUrl(e(),i)||(r(i),o.currentPageUrl=e(),o.visit.to.url=o.currentPageUrl),o.visit.animation.animate&&o.classes.add("is-rendering"),o.visit.to.html=s,Promise.resolve(o.hooks.call("content:replace",{page:n},(e,n)=>{let{page:r}=n;if(!o.replaceContent(r,{containers:e.containers}))throw new Error("[swup] Container mismatch, aborting");e.animation.animate&&(o.classes.add("is-animating","is-changing","is-rendering"),e.animation.name&&o.classes.add(`to-${t(e.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(){})})})}catch(t){return Promise.reject(t)}},N=function(t){var e;if(e=t,Boolean(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 D(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${String(t)}`)}function O(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)}const V={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]",linkToSelf:"scroll",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source,timeout:0};return class{constructor(t){void 0===t&&(t={}),this.version="4.4.0",this.options=void 0,this.defaults=V,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.currentPageUrl=e(),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.use=N,this.unuse=M,this.findPlugin=D,this.log=()=>{},this.navigate=H,this.performNavigation=$,this.createVisit=v,this.delegateEvent=s,this.fetchPage=A,this.awaitAnimations=S,this.renderPage=R,this.replaceContent=q,this.animatePageIn=I,this.animatePageOut=T,this.scrollToContent=L,this.getAnchorElement=b,this.getCurrentUrl=e,this.resolveUrl=O,this.isSameResolvedUrl=W,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 p(this),this.hooks=new k(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=history.state?.index??1,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.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),t.options.plugins.forEach(e=>t.use(e)),"swup"!==history.state?.source&&r(null,{index:t.currentHistoryIndex}),Promise.resolve(u()).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():i?this.hooks.callSync("link:anchor",{hash:i},()=>{r(o+i),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>"navigate"===this.options.linkToSelf?this.performNavigation():(r(o),this.scrollToContent()))}))}handlePopState(t){const n=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(e(),this.currentPageUrl))return;const{url:r,hash:o}=a.fromUrl(n);this.visit=this.createVisit({to:r,hash:o,event:t}),this.visit.history.popstate=!0;const i=t.state?.index??0;i&&i!==this.currentHistoryIndex&&(this.visit.history.direction=i-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=i),this.visit.animation.animate=!1,this.visit.scroll.reset=!1,this.visit.scroll.target=!1,this.options.animateHistoryBrowsing&&(this.visit.animation.animate=!0,this.visit.scroll.reset=!0),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation()})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}}); | ||
!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=new WeakMap;function e(e,n,r,o){if(!e&&!t.has(n))return!1;const i=t.get(n)??new WeakMap;t.set(n,i);const s=i.get(r)??new Set;i.set(r,s);const a=s.has(o);return e?s.add(o):s.delete(o),a&&e}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=(t,n,r,o)=>{const i=new AbortController;return function(t,n,r,o={}){const{signal:i,base:s=document}=o;if(i?.aborted)return;const{once:a,...c}=o,l=s instanceof Document?s.documentElement:s,h=Boolean("object"==typeof o?o.capture:o),u=o=>{const i=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}}(o,t);if(i){const t=Object.assign(o,{delegateTarget:i});r.call(l,t),a&&(l.removeEventListener(n,u,c),e(!1,l,r,d))}},d=JSON.stringify({selector:t,type:n,capture:h});e(!0,l,r,d)||l.addEventListener(n,u,c),i?.addEventListener("abort",()=>{e(!1,l,r,d)})}(t,n,r,o={...o,signal:i.signal}),{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 c=function(t,e){void 0===e&&(e={});try{const r=this;function n(n){const{status:o,url:i}=h;return Promise.resolve(h.text()).then(function(n){if(500===o)throw r.hooks.call("fetch:error",{status:o,response:h,url:i}),new l(`Server error: ${i}`,{status:o,url:i});if(!n)throw new l(`Empty response: ${i}`,{status:o,url:i});const{url:s}=a.fromUrl(i),c={url:s,html:n};return!r.visit.cache.write||e.method&&"GET"!==e.method||t!==s||r.cache.set(c.url,c),c})}t=a.fromUrl(t).url;const o={...r.options.requestHeaders,...e.headers},i=e.timeout??r.options.timeout,s=new AbortController,{signal:c}=s;e={...e,headers:o,signal:c};let h,u=!1,d=null;i&&i>0&&(d=setTimeout(()=>{u=!0,s.abort("timeout")},i));const m=function(n,o){try{var i=Promise.resolve(r.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(t){h=t,d&&clearTimeout(d)})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(u)throw r.hooks.call("fetch:timeout",{url:t}),new l(`Request timed out: ${t}`,{url:t,timedOut:u});if("AbortError"===e?.name||c.aborted)throw new l(`Request aborted: ${t}`,{url:t,aborted:!0});throw e});return Promise.resolve(m&&m.then?m.then(n):n())}catch(f){return Promise.reject(f)}};class l extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}class h{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,n)=>{t.set(n,{...e})}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?{...e}:e}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);const n={...this.get(t),...e,url:t};this.pages.set(t,n)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0)}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 u=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},d=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},m=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function f(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}const p=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,v=t=>1e3*Number(t.slice(0,-1).replace(",","."));class g{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()?d(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 w(t){let{to:e,from:n=this.currentPageUrl,hash:r,el:o,event:i}=t;return{id:Math.random(),from:{url:n},to:{url:e,hash:r},containers:this.options.containers,animation:{animate:!0,wait:!1,name:void 0,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:o,event:i},cache:{read:this.options.cache,write:this.options.cache},history:{action:"push",popstate:!1,direction:void 0},scroll:{reset:!0,target:void 0}}}const y="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function P(t,e,n){if(!t.s){if(n instanceof k){if(!n.s)return void(n.o=P.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(P.bind(null,t,e),P.bind(null,t,2));t.s=e,t.v=n;const r=t.o;r&&r(t)}}const k=/*#__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{P(r,1,t(this.v))}catch(t){P(r,2,t)}return r}return this}return this.o=function(t){try{const o=t.v;1&t.s?P(r,1,e?e(o):o):n?P(r,1,n(o)):P(r,2,o)}catch(t){P(r,2,t)}},r},t}();function b(t){return t instanceof k&&1&t.s}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","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","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[y]){var r,o,i,s=t[y]();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=P.bind(null,o=new k,2)));n=n.v}o?P(o,1,n):o=n}catch(t){P(o||(o=new k),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 c=[],l=0;l<t.length;l++)c.push(t[l]);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=P.bind(null,r=new k,2)));s=s.v}r?P(r,1,s):r=s}catch(t){P(r||(r=new k),2,t)}}(),r}(c,function(t){return e(c[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);f(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),f(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=Array.from(n.values()),o=this.sortRegistrations,i=r.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(o),s=r.filter(t=>{let{replace:e}=t;return e}).filter(t=>!0).sort(o),a=r.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(o),c=s.length>0;let l=[];if(e&&(l=[{id:0,hook:t,handler:e}],c)){const n=s.length-1,r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};l=[{id:0,hook:t,handler:s[n].handler,defaultHandler:r(n)}]}return{found:!0,before:i,handler:l,after:a,replaced:c}}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)||u(`a[name='${p(t)}']`)||u(`a[name='${p(e)}']`);return n||"top"!==t||(n=document.body),n},U=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=d(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=$(n,`${C}Delay`),o=$(n,`${C}Duration`),i=H(r,o),s=$(n,`${x}Delay`),a=$(n,`${x}Duration`),c=H(s,a);let l=null,h=0,u=0;return e===C?i>0&&(l=C,h=i,u=o.length):e===x?c>0&&(l=x,h=c,u=a.length):(h=Math.max(i,c),l=h>0?i>c?C:x:null,u=l?l===C?o.length:a.length:0),{type:l,timeout:h,propCount:u}}(t);return!(!e||!n)&&new Promise(o=>{const i=`${e}end`,s=performance.now();let a=0;const c=()=>{t.removeEventListener(i,l),o()},l=e=>{if(e.target===t){if(!function(t){return[`${C}end`,`${x}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-s)/1e3<e.elapsedTime||++a>=r&&c()}};setTimeout(()=>{a<r&&c()},n+1),t.addEventListener(i,l)})}(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",x="animation";function $(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)=>v(e)+v(t[n])))}const A=function(t){void 0===t&&(t={});try{const e=this;e.navigating=!0;const n=e.visit,{el:s}=n.trigger;t.referrer=t.referrer||e.currentPageUrl,!1===t.animate&&(n.animation.animate=!1),n.animation.animate||e.classes.clear();const a=t.history||s?.getAttribute("data-swup-history")||void 0;a&&["push","replace"].includes(a)&&(n.history.action=a);const c=t.animation||s?.getAttribute("data-swup-animation")||void 0;return c&&(n.animation.name=c),"object"==typeof t.cache?(n.cache.read=t.cache.read??n.cache.read,n.cache.write=t.cache.write??n.cache.write):void 0!==t.cache&&(n.cache={read:!!t.cache,write:!!t.cache}),delete t.cache,Promise.resolve(function(s,a){try{var c=Promise.resolve(e.hooks.call("visit:start",void 0)).then(function(){function s(){return Promise.resolve(e.hooks.call("visit:transition",void 0,function(t){try{const n=e.animatePageOut();return Promise.resolve(Promise.all([a,n])).then(function(n){let[r]=n;return t.id===e.visit.id&&Promise.resolve(e.renderPage(r)).then(function(){return Promise.resolve(e.animatePageIn()).then(function(){return!0})})})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(e.hooks.call("visit:end",void 0,()=>e.classes.clear())).then(function(){e.navigating=!1})})}const a=e.hooks.call("page:load",{options:t},function(t,n){try{function r(t){return n.page=t,n.cache=!!o,n.page}let o;return t.cache.read&&(o=e.cache.get(t.to.url)),Promise.resolve(o?r(o):Promise.resolve(e.fetchPage(t.to.url,n.options)).then(r))}catch(i){return Promise.reject(i)}});if(!n.history.popstate){const t=n.to.url+n.to.hash;"replace"===n.history.action||n.to.url===e.currentPageUrl?i(t):(e.currentHistoryIndex++,o(t,{index:e.currentHistoryIndex}))}e.currentPageUrl=r();const c=function(){if(n.animation.wait)return Promise.resolve(a).then(function(t){let{html:e}=t;n.to.html=e})}();return c&&c.then?c.then(s):s()})}catch(t){return a(t)}return c&&c.then?c.then(void 0,a):c}(0,function(t){t&&!t?.aborted&&(console.error(t),e.options.skipPopStateHandling=()=>(window.location.href=n.to.url+n.to.hash,!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={}),"string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");if(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(e)}const T=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",void 0)).then(function(){})})})}const o=function(){if(!r.visit.animation.animate)return Promise.resolve(r.hooks.call("animation:skip",void 0)).then(function(){e=1})}();return Promise.resolve(o&&o.then?o.then(t):t(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||"";document.title=i;const s=d('[data-swup-persist]:not([data-swup-persist=""])'),a=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);return s.forEach(t=>{const e=t.getAttribute("data-swup-persist"),n=u(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),a.length===r.length},L=function(){const t={behavior:"auto"},{target:e,reset:n}=this.visit.scroll,r=e??this.visit.to.hash;let o=!1;return r&&(o=this.hooks.callSync("scroll:anchor",{hash:r,options:t},(t,e)=>{let{hash:n,options:r}=e;const o=this.getAnchorElement(n);return o&&o.scrollIntoView(r),!!o})),n&&!o&&(o=this.hooks.callSync("scroll:top",{options:t},(t,e)=>{let{options:n}=e;return window.scrollTo({top:0,left:0,...n}),!0})),o},I=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",void 0)).then(function(){})})})})}catch(t){return Promise.reject(t)}},R=function(t){try{const e=this,{url:o,html:s}=t;return e.classes.remove("is-leaving"),e.isSameResolvedUrl(r(),o)||(i(o),e.currentPageUrl=r(),e.visit.to.url=e.currentPageUrl),e.visit.animation.animate&&e.classes.add("is-rendering"),e.visit.to.html=s,Promise.resolve(e.hooks.call("content:replace",{page:t},(t,r)=>{let{page:o}=r;if(!e.replaceContent(o,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(e.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&e.classes.add(`to-${n(t.animation.name)}`))})).then(function(){return Promise.resolve(e.hooks.call("content:scroll",void 0,()=>e.scrollToContent())).then(function(){return Promise.resolve(e.hooks.call("page:view",{url:e.currentPageUrl,title:document.title})).then(function(){})})})}catch(t){return Promise.reject(t)}},N=function(t){var e;if(e=t,Boolean(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${String(t)}`)}function O(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)}const V={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]",linkToSelf:"scroll",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source,timeout:0};return class{constructor(t){void 0===t&&(t={}),this.version="4.4.1",this.options=void 0,this.defaults=V,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.currentPageUrl=r(),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.navigating=!1,this.use=N,this.unuse=D,this.findPlugin=M,this.log=()=>{},this.navigate=j,this.performNavigation=A,this.createVisit=w,this.delegateEvent=s,this.fetchPage=c,this.awaitAnimations=U,this.renderPage=R,this.replaceContent=q,this.animatePageIn=I,this.animatePageOut=T,this.scrollToContent=L,this.getAnchorElement=E,this.getCurrentUrl=r,this.resolveUrl=O,this.isSameResolvedUrl=W,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new h(this),this.classes=new g(this),this.hooks=new S(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=history.state?.index??1,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.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),t.options.plugins.forEach(e=>t.use(e)),"swup"!==history.state?.source&&i(null,{index:t.currentHistoryIndex}),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.navigating&&r===this.visit.to.url?t.preventDefault():(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():o?this.hooks.callSync("link:anchor",{hash:o},()=>{i(r+o),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>"navigate"===this.options.linkToSelf?this.performNavigation():(i(r),this.scrollToContent()))})))}handlePopState(t){const e=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(r(),this.currentPageUrl))return;const{url:n,hash:o}=a.fromUrl(e);this.visit=this.createVisit({to:n,hash:o,event:t}),this.visit.history.popstate=!0;const i=t.state?.index??0;i&&i!==this.currentHistoryIndex&&(this.visit.history.direction=i-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=i),this.visit.animation.animate=!1,this.visit.scroll.reset=!1,this.visit.scroll.target=!1,this.options.animateHistoryBrowsing&&(this.visit.animation.animate=!0,this.visit.scroll.reset=!0),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation()})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}}); | ||
//# sourceMappingURL=Swup.umd.js.map |
@@ -6,1 +6,2 @@ /** | ||
export default _default; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -8,1 +8,2 @@ export { classify } from './helpers/classify.js'; | ||
export { matchPath } from './helpers/matchPath.js'; | ||
//# sourceMappingURL=helpers.d.ts.map |
/** Turn a string into a slug by lowercasing and replacing whitespace. */ | ||
export declare const classify: (text: string, fallback?: string) => string; | ||
//# sourceMappingURL=classify.d.ts.map |
@@ -10,1 +10,2 @@ export interface HistoryState { | ||
export declare const createHistoryRecord: (url: string, customData?: Record<string, unknown>) => void; | ||
//# sourceMappingURL=createHistoryRecord.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { DelegateEventHandler, DelegateOptions } from 'delegate-it'; | ||
import { ParseSelector } from 'typed-query-selector/parser.js'; | ||
import { type DelegateEventHandler, type DelegateOptions } from 'delegate-it'; | ||
import type { ParseSelector } from 'typed-query-selector/parser.js'; | ||
export type DelegateEventUnsubscribe = { | ||
@@ -8,1 +8,2 @@ destroy: () => void; | ||
export declare const delegateEvent: <Selector extends string, TElement extends Element = ParseSelector<Selector, HTMLElement>, TEvent extends keyof GlobalEventHandlersEventMap = keyof GlobalEventHandlersEventMap>(selector: Selector, type: TEvent, callback: DelegateEventHandler<GlobalEventHandlersEventMap[TEvent], TElement>, options?: DelegateOptions) => DelegateEventUnsubscribe; | ||
//# sourceMappingURL=delegateEvent.d.ts.map |
@@ -5,1 +5,2 @@ /** Get the current page URL: path name + query params. Optionally including hash. */ | ||
}) => string; | ||
//# sourceMappingURL=getCurrentUrl.d.ts.map |
@@ -25,1 +25,2 @@ /** | ||
} | ||
//# sourceMappingURL=Location.d.ts.map |
import type { Path, ParseOptions, TokensToRegexpOptions, RegexpToFunctionOptions, MatchFunction } from 'path-to-regexp'; | ||
export { Path }; | ||
export { type Path }; | ||
/** Create a match function from a path pattern that checks if a URLs matches it. */ | ||
export declare const matchPath: <P extends object = object>(path: Path, options?: ParseOptions & TokensToRegexpOptions & RegexpToFunctionOptions) => MatchFunction<P>; | ||
//# sourceMappingURL=matchPath.d.ts.map |
/** Update the current history record with a custom swup identifier. */ | ||
export declare const updateHistoryRecord: (url?: string | null, customData?: Record<string, unknown>) => void; | ||
//# sourceMappingURL=updateHistoryRecord.d.ts.map |
@@ -15,1 +15,2 @@ import type { Path } from 'path-to-regexp'; | ||
export type { Swup, Options, Plugin, CacheData, PageData, Visit, VisitFrom, VisitTo, VisitAnimation, VisitScroll, VisitHistory, HookArguments, HookDefinitions, HookName, HookOptions, HookUnregister, Handler, Path, DelegateEvent, DelegateEventHandler, DelegateEventUnsubscribe }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
/** | ||
@@ -7,1 +7,2 @@ * Perform the in/enter animation of the next page. | ||
export declare const animatePageIn: (this: Swup) => Promise<void>; | ||
//# sourceMappingURL=animatePageIn.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
/** | ||
@@ -7,1 +7,2 @@ * Perform the out/leave animation of the current page. | ||
export declare const animatePageOut: (this: Swup) => Promise<void>; | ||
//# sourceMappingURL=animatePageOut.d.ts.map |
@@ -1,2 +0,3 @@ | ||
import Swup, { Options } from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
import type { Options } from '../Swup.js'; | ||
declare const TRANSITION = "transition"; | ||
@@ -20,1 +21,2 @@ declare const ANIMATION = "animation"; | ||
export {}; | ||
//# sourceMappingURL=awaitAnimations.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import Swup from '../Swup.js'; | ||
import { PageData } from './fetchPage.js'; | ||
import type Swup from '../Swup.js'; | ||
import { type PageData } from './fetchPage.js'; | ||
export interface CacheData extends PageData { | ||
@@ -35,1 +35,2 @@ } | ||
} | ||
//# sourceMappingURL=Cache.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
export declare class Classes { | ||
@@ -14,1 +14,2 @@ protected swup: Swup; | ||
} | ||
//# sourceMappingURL=Classes.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
/** A page object as used by swup and its cache. */ | ||
@@ -34,1 +34,2 @@ export interface PageData { | ||
export declare function fetchPage(this: Swup, url: URL | string, options?: FetchOptions): Promise<PageData>; | ||
//# sourceMappingURL=fetchPage.d.ts.map |
@@ -10,1 +10,2 @@ /** | ||
export declare const getAnchorElement: (hash?: string) => Element | null; | ||
//# sourceMappingURL=getAnchorElement.d.ts.map |
@@ -1,5 +0,5 @@ | ||
import { DelegateEvent } from 'delegate-it'; | ||
import Swup from '../Swup.js'; | ||
import { Visit } from './Visit.js'; | ||
import { FetchOptions, PageData } from './fetchPage.js'; | ||
import type { DelegateEvent } from 'delegate-it'; | ||
import type Swup from '../Swup.js'; | ||
import type { Visit } from './Visit.js'; | ||
import type { FetchOptions, PageData } from './fetchPage.js'; | ||
export interface HookDefinitions { | ||
@@ -274,1 +274,2 @@ 'animation:out:start': undefined; | ||
export {}; | ||
//# sourceMappingURL=Hooks.d.ts.map |
@@ -1,4 +0,4 @@ | ||
import Swup from '../Swup.js'; | ||
import { FetchOptions } from './fetchPage.js'; | ||
import { VisitInitOptions } from './Visit.js'; | ||
import type Swup from '../Swup.js'; | ||
import { type FetchOptions } from './fetchPage.js'; | ||
import type { VisitInitOptions } from './Visit.js'; | ||
export type HistoryAction = 'push' | 'replace'; | ||
@@ -42,1 +42,2 @@ export type HistoryDirection = 'forwards' | 'backwards'; | ||
export {}; | ||
//# sourceMappingURL=navigate.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
export type Plugin = { | ||
@@ -27,1 +27,2 @@ /** Identify as a swup plugin */ | ||
export declare function findPlugin(this: Swup, pluginOrName: Plugin | string): Plugin | undefined; | ||
//# sourceMappingURL=plugins.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import Swup from '../Swup.js'; | ||
import { PageData } from './fetchPage.js'; | ||
import type Swup from '../Swup.js'; | ||
import type { PageData } from './fetchPage.js'; | ||
/** | ||
@@ -7,1 +7,2 @@ * Render the next page: replace the content and update scroll position. | ||
export declare const renderPage: (this: Swup, page: PageData) => Promise<void>; | ||
//# sourceMappingURL=renderPage.d.ts.map |
@@ -1,3 +0,4 @@ | ||
import Swup, { Options } from '../Swup.js'; | ||
import { PageData } from './fetchPage.js'; | ||
import type Swup from '../Swup.js'; | ||
import type { Options } from '../Swup.js'; | ||
import type { PageData } from './fetchPage.js'; | ||
/** | ||
@@ -14,1 +15,2 @@ * Perform the replacement of content after loading a page. | ||
}) => boolean; | ||
//# sourceMappingURL=replaceContent.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
/** | ||
@@ -15,1 +15,2 @@ * Utility function to validate and run the global option 'resolveUrl' | ||
export declare function isSameResolvedUrl(this: Swup, url1: string, url2: string): boolean; | ||
//# sourceMappingURL=resolveUrl.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
/** | ||
@@ -7,1 +7,2 @@ * Update the scroll position after page render. | ||
export declare const scrollToContent: (this: Swup) => boolean; | ||
//# sourceMappingURL=scrollToContent.d.ts.map |
@@ -1,3 +0,4 @@ | ||
import Swup, { Options } from '../Swup.js'; | ||
import { HistoryAction, HistoryDirection } from './navigate.js'; | ||
import type Swup from '../Swup.js'; | ||
import type { Options } from '../Swup.js'; | ||
import type { HistoryAction, HistoryDirection } from './navigate.js'; | ||
/** An object holding details about the current visit. */ | ||
@@ -83,1 +84,2 @@ export interface Visit { | ||
export declare function createVisit(this: Swup, { to, from, hash, el, event }: VisitInitOptions): Visit; | ||
//# sourceMappingURL=Visit.d.ts.map |
@@ -1,11 +0,11 @@ | ||
import { DelegateEvent } from 'delegate-it'; | ||
import { DelegateEventUnsubscribe } from './helpers/delegateEvent.js'; | ||
import { type DelegateEvent } from 'delegate-it'; | ||
import { type DelegateEventUnsubscribe } from './helpers/delegateEvent.js'; | ||
import { Cache } from './modules/Cache.js'; | ||
import { Classes } from './modules/Classes.js'; | ||
import { Visit, createVisit } from './modules/Visit.js'; | ||
import { type Visit, createVisit } from './modules/Visit.js'; | ||
import { Hooks } from './modules/Hooks.js'; | ||
import { awaitAnimations } from './modules/awaitAnimations.js'; | ||
import { navigate, performNavigation, NavigationToSelfAction } from './modules/navigate.js'; | ||
import { navigate, performNavigation, type NavigationToSelfAction } from './modules/navigate.js'; | ||
import { fetchPage } from './modules/fetchPage.js'; | ||
import { unuse, findPlugin, Plugin } from './modules/plugins.js'; | ||
import { unuse, findPlugin, type Plugin } from './modules/plugins.js'; | ||
import { isSameResolvedUrl, resolveUrl } from './modules/resolveUrl.js'; | ||
@@ -68,2 +68,4 @@ /** Options for customizing swup's behavior. */ | ||
protected clickDelegate?: DelegateEventUnsubscribe; | ||
/** Navigation status */ | ||
protected navigating: boolean; | ||
/** Install a plugin */ | ||
@@ -123,1 +125,2 @@ use: (this: Swup, plugin: unknown) => Plugin[] | undefined; | ||
} | ||
//# sourceMappingURL=Swup.d.ts.map |
export * from './utils/index.js'; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -21,1 +21,2 @@ /** Find an element by selector. */ | ||
export declare const toMs: (s: string) => number; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "swup", | ||
"amdName": "Swup", | ||
"version": "4.4.0", | ||
"version": "4.4.1", | ||
"description": "Versatile and extensible page transition library for server-rendered websites", | ||
@@ -83,2 +83,3 @@ "type": "module", | ||
"serve": "^14.2.1", | ||
"typed-query-selector": "^2.11.0", | ||
"vitest": "^0.34.3" | ||
@@ -85,0 +86,0 @@ }, |
@@ -1,3 +0,7 @@ | ||
import delegate, { DelegateEventHandler, DelegateOptions, EventType } from 'delegate-it'; | ||
import { ParseSelector } from 'typed-query-selector/parser.js'; | ||
import delegate, { | ||
type DelegateEventHandler, | ||
type DelegateOptions, | ||
type EventType | ||
} from 'delegate-it'; | ||
import type { ParseSelector } from 'typed-query-selector/parser.js'; | ||
@@ -4,0 +8,0 @@ export type DelegateEventUnsubscribe = { |
@@ -11,3 +11,3 @@ import { match } from 'path-to-regexp'; | ||
export { Path }; | ||
export { type Path }; | ||
@@ -14,0 +14,0 @@ /** Create a match function from a path pattern that checks if a URLs matches it. */ |
@@ -1,2 +0,2 @@ | ||
import { HistoryState } from './createHistoryRecord.js'; | ||
import type { HistoryState } from './createHistoryRecord.js'; | ||
import { getCurrentUrl } from './getCurrentUrl.js'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
import { nextTick } from '../utils.js'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
import { classify } from '../helpers.js'; | ||
@@ -3,0 +3,0 @@ |
import { queryAll, toMs } from '../utils.js'; | ||
import Swup, { Options } from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
import type { Options } from '../Swup.js'; | ||
@@ -4,0 +5,0 @@ const TRANSITION = 'transition'; |
@@ -1,4 +0,4 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
import { Location } from '../helpers.js'; | ||
import { PageData } from './fetchPage.js'; | ||
import { type PageData } from './fetchPage.js'; | ||
@@ -5,0 +5,0 @@ export interface CacheData extends PageData {} |
@@ -1,2 +0,2 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
import { queryAll } from '../utils.js'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
import { Location } from '../helpers.js'; | ||
@@ -3,0 +3,0 @@ |
@@ -1,7 +0,7 @@ | ||
import { DelegateEvent } from 'delegate-it'; | ||
import type { DelegateEvent } from 'delegate-it'; | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
import { isPromise, runAsPromise } from '../utils.js'; | ||
import { Visit } from './Visit.js'; | ||
import { FetchOptions, PageData } from './fetchPage.js'; | ||
import type { Visit } from './Visit.js'; | ||
import type { FetchOptions, PageData } from './fetchPage.js'; | ||
@@ -8,0 +8,0 @@ export interface HookDefinitions { |
@@ -1,5 +0,5 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
import { createHistoryRecord, updateHistoryRecord, getCurrentUrl, Location } from '../helpers.js'; | ||
import { FetchError, FetchOptions, PageData } from './fetchPage.js'; | ||
import { VisitInitOptions } from './Visit.js'; | ||
import { FetchError, type FetchOptions, type PageData } from './fetchPage.js'; | ||
import type { VisitInitOptions } from './Visit.js'; | ||
@@ -65,2 +65,3 @@ export type HistoryAction = 'push' | 'replace'; | ||
): Promise<void> { | ||
this.navigating = true; | ||
// Save this localy to a) allow ignoring the visit if a new one was started in the meantime | ||
@@ -170,2 +171,3 @@ // and b) avoid unintended modifications to any newer visits | ||
// } | ||
this.navigating = false; | ||
} catch (error) { | ||
@@ -172,0 +174,0 @@ // Return early if error is undefined or signals an aborted request |
@@ -1,2 +0,2 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
@@ -3,0 +3,0 @@ export type Plugin = { |
import { updateHistoryRecord, getCurrentUrl, classify } from '../helpers.js'; | ||
import Swup from '../Swup.js'; | ||
import { PageData } from './fetchPage.js'; | ||
import type Swup from '../Swup.js'; | ||
import type { PageData } from './fetchPage.js'; | ||
@@ -5,0 +5,0 @@ /** |
@@ -1,4 +0,5 @@ | ||
import Swup, { Options } from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
import type { Options } from '../Swup.js'; | ||
import { query, queryAll } from '../utils.js'; | ||
import { PageData } from './fetchPage.js'; | ||
import type { PageData } from './fetchPage.js'; | ||
@@ -5,0 +6,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
@@ -3,0 +3,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import Swup from '../Swup.js'; | ||
import type Swup from '../Swup.js'; | ||
@@ -3,0 +3,0 @@ /** |
@@ -1,3 +0,4 @@ | ||
import Swup, { Options } from '../Swup.js'; | ||
import { HistoryAction, HistoryDirection } from './navigate.js'; | ||
import type Swup from '../Swup.js'; | ||
import type { Options } from '../Swup.js'; | ||
import type { HistoryAction, HistoryDirection } from './navigate.js'; | ||
@@ -4,0 +5,0 @@ /** An object holding details about the current visit. */ |
@@ -1,2 +0,2 @@ | ||
import { DelegateEvent } from 'delegate-it'; | ||
import { type DelegateEvent } from 'delegate-it'; | ||
@@ -6,11 +6,11 @@ import version from './config/version.js'; | ||
import { delegateEvent, getCurrentUrl, Location, updateHistoryRecord } from './helpers.js'; | ||
import { DelegateEventUnsubscribe } from './helpers/delegateEvent.js'; | ||
import { type DelegateEventUnsubscribe } from './helpers/delegateEvent.js'; | ||
import { Cache } from './modules/Cache.js'; | ||
import { Classes } from './modules/Classes.js'; | ||
import { Visit, createVisit } from './modules/Visit.js'; | ||
import { type Visit, createVisit } from './modules/Visit.js'; | ||
import { Hooks } from './modules/Hooks.js'; | ||
import { getAnchorElement } from './modules/getAnchorElement.js'; | ||
import { awaitAnimations } from './modules/awaitAnimations.js'; | ||
import { navigate, performNavigation, NavigationToSelfAction } from './modules/navigate.js'; | ||
import { navigate, performNavigation, type NavigationToSelfAction } from './modules/navigate.js'; | ||
import { fetchPage } from './modules/fetchPage.js'; | ||
@@ -22,6 +22,6 @@ import { animatePageOut } from './modules/animatePageOut.js'; | ||
import { renderPage } from './modules/renderPage.js'; | ||
import { use, unuse, findPlugin, Plugin } from './modules/plugins.js'; | ||
import { use, unuse, findPlugin, type Plugin } from './modules/plugins.js'; | ||
import { isSameResolvedUrl, resolveUrl } from './modules/resolveUrl.js'; | ||
import { nextTick } from './utils.js'; | ||
import { HistoryState } from './helpers/createHistoryRecord.js'; | ||
import { type HistoryState } from './helpers/createHistoryRecord.js'; | ||
@@ -101,2 +101,4 @@ /** Options for customizing swup's behavior. */ | ||
protected clickDelegate?: DelegateEventUnsubscribe; | ||
/** Navigation status */ | ||
protected navigating: boolean = false; | ||
@@ -263,2 +265,8 @@ /** Install a plugin */ | ||
// Ignore if swup is currently navigating towards the link's URL | ||
if (this.navigating && url === this.visit.to.url) { | ||
event.preventDefault(); | ||
return; | ||
} | ||
this.visit = this.createVisit({ to: url, hash, el, event }); | ||
@@ -265,0 +273,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
631231
95
3122
19