swup 4.4.4 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/Swup.cjs +1 -1
  2. package/dist/Swup.cjs.map +1 -1
  3. package/dist/Swup.modern.js +1 -1
  4. package/dist/Swup.modern.js.map +1 -1
  5. package/dist/Swup.module.js +1 -1
  6. package/dist/Swup.module.js.map +1 -1
  7. package/dist/Swup.umd.js +1 -1
  8. package/dist/Swup.umd.js.map +1 -1
  9. package/dist/types/Swup.d.ts +8 -4
  10. package/dist/types/Swup.d.ts.map +1 -1
  11. package/dist/types/helpers/Location.d.ts.map +1 -1
  12. package/dist/types/helpers/history.d.ts +14 -0
  13. package/dist/types/helpers/history.d.ts.map +1 -0
  14. package/dist/types/helpers.d.ts +1 -2
  15. package/dist/types/helpers.d.ts.map +1 -1
  16. package/dist/types/modules/Classes.d.ts.map +1 -1
  17. package/dist/types/modules/Hooks.d.ts +16 -8
  18. package/dist/types/modules/Hooks.d.ts.map +1 -1
  19. package/dist/types/modules/Visit.d.ts +28 -22
  20. package/dist/types/modules/Visit.d.ts.map +1 -1
  21. package/dist/types/modules/animatePageIn.d.ts +2 -1
  22. package/dist/types/modules/animatePageIn.d.ts.map +1 -1
  23. package/dist/types/modules/animatePageOut.d.ts +2 -1
  24. package/dist/types/modules/animatePageOut.d.ts.map +1 -1
  25. package/dist/types/modules/fetchPage.d.ts.map +1 -1
  26. package/dist/types/modules/navigate.d.ts +2 -2
  27. package/dist/types/modules/navigate.d.ts.map +1 -1
  28. package/dist/types/modules/renderPage.d.ts +2 -1
  29. package/dist/types/modules/renderPage.d.ts.map +1 -1
  30. package/dist/types/modules/replaceContent.d.ts.map +1 -1
  31. package/dist/types/modules/scrollToContent.d.ts +2 -1
  32. package/dist/types/modules/scrollToContent.d.ts.map +1 -1
  33. package/package.json +2 -1
  34. package/src/Swup.ts +40 -37
  35. package/src/helpers/Location.ts +1 -0
  36. package/src/helpers/history.ts +37 -0
  37. package/src/helpers.ts +1 -2
  38. package/src/modules/Cache.ts +2 -2
  39. package/src/modules/Classes.ts +8 -1
  40. package/src/modules/Hooks.ts +77 -29
  41. package/src/modules/Visit.ts +86 -47
  42. package/src/modules/animatePageIn.ts +9 -8
  43. package/src/modules/animatePageOut.ts +7 -18
  44. package/src/modules/fetchPage.ts +9 -11
  45. package/src/modules/navigate.ts +78 -34
  46. package/src/modules/renderPage.ts +15 -13
  47. package/src/modules/replaceContent.ts +1 -0
  48. package/src/modules/scrollToContent.ts +6 -4
  49. package/dist/types/helpers/createHistoryRecord.d.ts +0 -10
  50. package/dist/types/helpers/createHistoryRecord.d.ts.map +0 -1
  51. package/dist/types/helpers/updateHistoryRecord.d.ts +0 -3
  52. package/dist/types/helpers/updateHistoryRecord.d.ts.map +0 -1
  53. package/src/helpers/createHistoryRecord.ts +0 -24
  54. package/src/helpers/updateHistoryRecord.ts +0 -19
package/dist/Swup.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var t=require("delegate-it"),e=require("path-to-regexp");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=/*#__PURE__*/n(t);const o=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",i=({hash:t}={})=>location.pathname+location.search+(t?location.hash:""),s=(t,e={})=>{const n={url:t=t||i({hash:!0}),random:Math.random(),source:"swup",...e};history.pushState(n,"",t)},a=(t=null,e={})=>{t=t||i({hash:!0});const n={...history.state||{},url:t,random:Math.random(),source:"swup",...e};history.replaceState(n,"",t)},c=(t,e,n,o)=>{const i=new AbortController;return o={...o,signal:i.signal},r.default(t,e,n,o),{destroy:()=>i.abort()}};class l extends URL{constructor(t,e=document.baseURI){super(t.toString(),e),Object.setPrototypeOf(this,l.prototype)}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=function(t,e={}){try{const r=this;function n(n){const{status:o,url:i}=c;return Promise.resolve(c.text()).then(function(n){if(500===o)throw r.hooks.call("fetch:error",{status:o,response:c,url:i}),new u(`Server error: ${i}`,{status:o,url:i});if(!n)throw new u(`Empty response: ${i}`,{status:o,url:i});const{url:s}=l.fromUrl(i),a={url:s,html:n};return!r.visit.cache.write||e.method&&"GET"!==e.method||t!==s||r.cache.set(a.url,a),a})}t=l.fromUrl(t).url;const o={...r.options.requestHeaders,...e.headers},i=e.timeout??r.options.timeout,s=new AbortController,{signal:a}=s;e={...e,headers:o,signal:a};let c,h=!1,m=null;i&&i>0&&(m=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,{url:e,options:n})=>fetch(e,n))).then(function(t){c=t,m&&clearTimeout(m)})}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 u(`Request timed out: ${t}`,{url:t,timedOut:h});if("AbortError"===e?.name||a.aborted)throw new u(`Request aborted: ${t}`,{url:t,aborted:!0});throw e});return Promise.resolve(d&&d.then?d.then(n):n())}catch(p){return Promise.reject(p)}};class u 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 m{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}=l.fromUrl(t);return this.swup.resolveUrl(e)}}const d=(t,e=document)=>e.querySelector(t),p=(t,e=document)=>Array.from(e.querySelectorAll(t)),f=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function v(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function g(t,e=[]){return new Promise((n,r)=>{const o=t(...e);v(o)?o.then(n,r):n(o)})}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()?p(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({to:t,from:e=this.currentPageUrl,hash:n,el:r,event:o}){return{id:Math.random(),from:{url:e},to:{url:t,hash:n},containers:this.options.containers,animation:{animate:!0,wait:!1,name:void 0,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:r,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 b="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function S(t,e,n){if(!t.s){if(n instanceof x){if(!n.s)return void(n.o=S.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(S.bind(null,t,e),S.bind(null,t,2));t.s=e,t.v=n;const r=t.o;r&&r(t)}}const x=/*#__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{S(r,1,t(this.v))}catch(t){S(r,2,t)}return r}return this}return this.o=function(t){try{const o=t.v;1&t.s?S(r,1,e?e(o):o):n?S(r,1,n(o)):S(r,2,o)}catch(t){S(r,2,t)}},r},t}();function E(t){return t instanceof x&&1&t.s}class U{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","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={}){const r=this.get(t);if(!r)return console.warn(`Hook '${t}' not found.`),()=>{};const o={...n,id:r.size+1,hook:t,handler:e};return r.set(e,o),()=>this.off(t,e)}before(t,e,n={}){return this.on(t,e,{...n,before:!0})}replace(t,e,n={}){return this.on(t,e,{...n,replace:!0})}once(t,e,n={}){return 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]){return Promise.resolve(r.run(s,e)).then(function(){return r.dispatchDomEvent(t,e),n})})})}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[b]){var r,o,i,s=t[b]();if(function t(n){try{for(;!(r=s.next()).done;)if((n=e(r.value))&&n.then){if(!E(n))return void n.then(t,i||(i=S.bind(null,o=new x,2)));n=n.v}o?S(o,1,n):o=n}catch(t){S(o||(o=new x),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(!E(s))return void s.then(n,o||(o=S.bind(null,r=new x,2)));s=s.v}r?S(r,1,s):r=s}catch(t){S(r||(r=new x),2,t)}}(),r}(c,function(t){return e(c[t])})}(t,function({hook:t,handler:o,defaultHandler:i,once:s}){return Promise.resolve(g(o,[n.swup.visit,e,i])).then(function(e){r.push(e),s&&n.off(t,o)})});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),v(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(({before:t,replace:e})=>t&&!e).sort(o),s=r.filter(({replace:t})=>t).filter(t=>!0).sort(o),a=r.filter(({before:t,replace:e})=>!t&&!e).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){const n={hook:t,args:e,visit:this.swup.visit};document.dispatchEvent(new CustomEvent("swup:any",{detail:n,bubbles:!0})),document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:n,bubbles:!0}))}}const C=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},$=function({elements:t,selector:e}){try{if(!1===e&&!t)return Promise.resolve();let n=[];if(t)n=Array.from(t);else if(e&&(n=p(e,document.body),!n.length))return console.warn(`[swup] No elements found matching animationSelector \`${e}\``),Promise.resolve();const r=n.map(t=>function(t){const{type:e,timeout:n,propCount:r}=function(t,e){const n=window.getComputedStyle(t),r=q(n,`${H}Delay`),o=q(n,`${H}Duration`),i=R(r,o),s=q(n,`${A}Delay`),a=q(n,`${A}Duration`),c=R(s,a);let l=null,h=0,u=0;return e===H?i>0&&(l=H,h=i,u=o.length):e===A?c>0&&(l=A,h=c,u=a.length):(h=Math.max(i,c),l=h>0?i>c?H:A:null,u=l?l===H?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[`${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(i,l)})}(t));return r.filter(Boolean).length>0?Promise.resolve(Promise.all(r)).then(function(){}):(e&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${e}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},H="transition",A="animation";function q(t,e){return(t[e]||"").split(", ")}function R(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>y(e)+y(t[n])))}const j=function(t={}){try{const e=this;e.navigating=!0;const n=e.visit,{el:r}=n.trigger;t.referrer=t.referrer||e.currentPageUrl,!1===t.animate&&(n.animation.animate=!1),n.animation.animate||e.classes.clear();const o=t.history||r?.getAttribute("data-swup-history")||void 0;o&&["push","replace"].includes(o)&&(n.history.action=o);const c=t.animation||r?.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(r,o){try{var c=Promise.resolve(e.hooks.call("visit:start",void 0)).then(function(){function r(){return Promise.resolve(e.hooks.call("visit:transition",void 0,function(t){try{const n=e.animatePageOut();return Promise.resolve(Promise.all([o,n])).then(function([n]){return t.id===e.visit.id&&Promise.resolve(e.renderPage(n)).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 o=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?a(t):(e.currentHistoryIndex++,s(t,{index:e.currentHistoryIndex}))}e.currentPageUrl=i();const c=function(){if(n.animation.wait)return Promise.resolve(o).then(function({html:t}){n.to.html=t})}();return c&&c.then?c.then(r):r()})}catch(t){return o(t)}return c&&c.then?c.then(void 0,o):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 I(t,e={},n={}){if("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}=l.fromUrl(t);this.visit=this.createVisit({...n,to:r,hash:o}),this.performNavigation(e)}const L=function(){try{let e;const n=this;function t(t){return e?t:Promise.resolve(n.hooks.call("animation:out:start",void 0,t=>{n.classes.add("is-changing","is-leaving","is-animating"),t.history.popstate&&n.classes.add("is-popstate"),t.animation.name&&n.classes.add(`to-${o(t.animation.name)}`)})).then(function(){return Promise.resolve(n.hooks.call("animation:out:await",{skip:!1},function(t,{skip:e}){try{return e?Promise.resolve():Promise.resolve(n.awaitAnimations({selector:t.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(n.hooks.call("animation:out:end",void 0)).then(function(){})})})}const r=function(){if(!n.visit.animation.animate)return Promise.resolve(n.hooks.call("animation:skip",void 0)).then(function(){e=1})}();return Promise.resolve(r&&r.then?r.then(t):t(r))}catch(i){return Promise.reject(i)}},T=function({html:t},{containers:e}=this.options){const n=(new DOMParser).parseFromString(t,"text/html"),r=n.querySelector("title")?.innerText||"";document.title=r;const o=p('[data-swup-persist]:not([data-swup-persist=""])'),i=e.map(t=>{const e=document.querySelector(t),r=n.querySelector(t);return e&&r?(e.replaceWith(r),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),r||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean);return o.forEach(t=>{const e=t.getAttribute("data-swup-persist"),n=d(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),i.length===e.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,{hash:e,options:n})=>{const r=this.getAnchorElement(e);return r&&r.scrollIntoView(n),!!r})),n&&!o&&(o=this.hooks.callSync("scroll:top",{options:t},(t,{options:e})=>(window.scrollTo({top:0,left:0,...e}),!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,{skip:n}){try{return n?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:n,html:r}=t;return e.classes.remove("is-leaving"),e.isSameResolvedUrl(i(),n)||(a(n),e.currentPageUrl=i(),e.visit.to.url=e.currentPageUrl),e.visit.animation.animate&&e.classes.add("is-rendering"),e.visit.to.html=r,Promise.resolve(e.hooks.call("content:replace",{page:t},(t,{page:n})=>{if(!e.replaceContent(n,{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-${o(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)}},O=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 V(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:(t,{el: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=>"swup"!==t.state?.source,timeout:0};exports.Location=l,exports.classify=o,exports.createHistoryRecord=s,exports.default=class{constructor(t={}){this.version="4.4.4",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=i(),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.navigating=!1,this.use=O,this.unuse=V,this.findPlugin=W,this.log=()=>{},this.navigate=I,this.performNavigation=j,this.createVisit=k,this.delegateEvent=c,this.fetchPage=h,this.awaitAnimations=$,this.renderPage=M,this.replaceContent=T,this.animatePageIn=D,this.animatePageOut=L,this.scrollToContent=N,this.getAnchorElement=C,this.getCurrentUrl=i,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 m(this),this.classes=new P(this),this.hooks=new U(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&&a(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,{el:e,event:n}={}){const{origin:r,url:o,hash:i}=l.fromUrl(t);return r!==window.location.origin||!(!e||!this.triggerWillOpenNewWindow(e))||!!this.options.ignoreVisit(o+i,{el:e,event:n})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:r,hash:o}=l.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},()=>{a(r+o),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>"navigate"===this.options.linkToSelf?this.performNavigation():(a(r),this.scrollToContent()))})))}handlePopState(t){const e=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(i(),this.currentPageUrl))return;const{url:n,hash:r}=l.fromUrl(e);this.visit=this.createVisit({to:n,hash:r,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"]')}},exports.delegateEvent=c,exports.escapeCssIdentifier=w,exports.forceReflow=function(t){return t=t||document.body,t?.offsetHeight},exports.getCurrentUrl=i,exports.isPromise=v,exports.matchPath=(t,n)=>{try{return e.match(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${String(t)}":\n${String(e)}`)}},exports.nextTick=f,exports.query=d,exports.queryAll=p,exports.runAsPromise=g,exports.toMs=y,exports.updateHistoryRecord=a;
1
+ var t=require("delegate-it"),e=require("path-to-regexp");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=/*#__PURE__*/n(t);const o=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",i=({hash:t}={})=>location.pathname+location.search+(t?location.hash:""),s=(t,e={})=>{const n={url:t=t||i({hash:!0}),random:Math.random(),source:"swup",...e};history.pushState(n,"",t)},a=(t=null,e={})=>{t=t||i({hash:!0});const n={...history.state||{},url:t,random:Math.random(),source:"swup",...e};history.replaceState(n,"",t)},c=(t,e,n,o)=>{const i=new AbortController;return o={...o,signal:i.signal},r.default(t,e,n,o),{destroy:()=>i.abort()}};class l extends URL{constructor(t,e=document.baseURI){super(t.toString(),e),Object.setPrototypeOf(this,l.prototype)}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=function(t,e={}){try{const r=this;function n(n){const{status:i,url:s}=h;return Promise.resolve(h.text()).then(function(n){if(500===i)throw r.hooks.call("fetch:error",o,{status:i,response:h,url:s}),new u(`Server error: ${s}`,{status:i,url:s});if(!n)throw new u(`Empty response: ${s}`,{status:i,url:s});const{url:a}=l.fromUrl(s),c={url:a,html:n};return!o.cache.write||e.method&&"GET"!==e.method||t!==a||r.cache.set(c.url,c),c})}t=l.fromUrl(t).url;const{visit:o=r.visit}=e,i={...r.options.requestHeaders,...e.headers},s=e.timeout??r.options.timeout,a=new AbortController,{signal:c}=a;e={...e,headers:i,signal:c};let h,d=!1,m=null;s&&s>0&&(m=setTimeout(()=>{d=!0,a.abort("timeout")},s));const f=function(n,i){try{var s=Promise.resolve(r.hooks.call("fetch:request",o,{url:t,options:e},(t,{url:e,options:n})=>fetch(e,n))).then(function(t){h=t,m&&clearTimeout(m)})}catch(t){return i(t)}return s&&s.then?s.then(void 0,i):s}(0,function(e){if(d)throw r.hooks.call("fetch:timeout",o,{url:t}),new u(`Request timed out: ${t}`,{url:t,timedOut:d});if("AbortError"===e?.name||c.aborted)throw new u(`Request aborted: ${t}`,{url:t,aborted:!0});throw e});return Promise.resolve(f&&f.then?f.then(n):n())}catch(p){return Promise.reject(p)}};class u 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 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,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",void 0,{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,void 0)}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=l.fromUrl(t);return this.swup.resolveUrl(e)}}const m=(t,e=document)=>e.querySelector(t),f=(t,e=document)=>Array.from(e.querySelectorAll(t)),p=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function v(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function g(t,e=[]){return new Promise((n,r)=>{const o=t(...e);v(o)?o.then(n,r):n(o)})}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","is-leaving"],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()?f(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))}}class k{constructor(t,e){this.id=void 0,this.state=void 0,this.from=void 0,this.to=void 0,this.containers=void 0,this.animation=void 0,this.trigger=void 0,this.cache=void 0,this.history=void 0,this.scroll=void 0;const{to:n,from:r=t.currentPageUrl,hash:o,el:i,event:s}=e;this.id=Math.random(),this.state=1,this.from={url:r},this.to={url:n,hash:o},this.containers=t.options.containers,this.animation={animate:!0,wait:!1,name:void 0,native:t.options.native,scope:t.options.animationScope,selector:t.options.animationSelector},this.trigger={el:i,event:s},this.cache={read:t.options.cache,write:t.options.cache},this.history={action:"push",popstate:!1,direction:void 0},this.scroll={reset:!0,target:void 0}}advance(t){this.state<t&&(this.state=t)}abort(){this.state=8}get done(){return this.state>=7}}function b(t){return new k(this,t)}const S="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function E(t,e,n){if(!t.s){if(n instanceof x){if(!n.s)return void(n.o=E.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(E.bind(null,t,e),E.bind(null,t,2));t.s=e,t.v=n;const r=t.o;r&&r(t)}}const x=/*#__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{E(r,1,t(this.v))}catch(t){E(r,2,t)}return r}return this}return this.o=function(t){try{const o=t.v;1&t.s?E(r,1,e?e(o):o):n?E(r,1,n(o)):E(r,2,o)}catch(t){E(r,2,t)}},r},t}();function U(t){return t instanceof x&&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:abort","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={}){const r=this.get(t);if(!r)return console.warn(`Hook '${t}' not found.`),()=>{};const o={...n,id:r.size+1,hook:t,handler:e};return r.set(e,o),()=>this.off(t,e)}before(t,e,n={}){return this.on(t,e,{...n,before:!0})}replace(t,e,n={}){return this.on(t,e,{...n,replace:!0})}once(t,e,n={}){return 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,r){try{const o=this,[i,s,a]=o.parseCallArgs(t,e,n,r),{before:c,handler:l,after:h}=o.getHandlers(t,a);return Promise.resolve(o.run(c,i,s)).then(function(){return Promise.resolve(o.run(l,i,s)).then(function([e]){return Promise.resolve(o.run(h,i,s)).then(function(){return o.dispatchDomEvent(t,i,s),e})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n,r){const[o,i,s]=this.parseCallArgs(t,e,n,r),{before:a,handler:c,after:l}=this.getHandlers(t,s);this.runSync(a,o,i);const[h]=this.runSync(c,o,i);return this.runSync(l,o,i),this.dispatchDomEvent(t,o,i),h}parseCallArgs(t,e,n,r){return e instanceof k||"object"!=typeof e&&"function"!=typeof n?[e,n,r]:[void 0,e,n]}run(t,e,n){try{const r=this,o=[],i=function(t,e,n){if("function"==typeof t[S]){var r,o,i,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,i||(i=E.bind(null,o=new x,2)));n=n.v}o?E(o,1,n):o=n}catch(t){E(o||(o=new x),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(!U(s))return void s.then(n,o||(o=E.bind(null,r=new x,2)));s=s.v}r?E(r,1,s):r=s}catch(t){E(r||(r=new x),2,t)}}(),r}(c,function(t){return e(c[t])})}(t,function({hook:t,handler:i,defaultHandler:s,once:a}){if(!e?.done)return a&&r.off(t,i),Promise.resolve(g(i,[e||r.swup.visit,n,s])).then(function(t){o.push(t)})});return Promise.resolve(i&&i.then?i.then(function(){return o}):o)}catch(t){return Promise.reject(t)}}runSync(t,e,n){const r=[];for(const{hook:o,handler:i,defaultHandler:s,once:a}of t){if(e?.done)continue;a&&this.off(o,i);const t=i(e||this.swup.visit,n,s);r.push(t),v(t)&&console.warn(`Promise returned from handler for synchronous hook '${o}'.Swup will not wait for it to resolve.`)}return r}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(({before:t,replace:e})=>t&&!e).sort(o),s=r.filter(({replace:t})=>t).filter(t=>!0).sort(o),a=r.filter(({before:t,replace:e})=>!t&&!e).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,n){if(e?.done)return;const r={hook:t,args:n,visit:e||this.swup.visit};document.dispatchEvent(new CustomEvent("swup:any",{detail:r,bubbles:!0})),document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:r,bubbles:!0}))}}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)||m(`a[name='${w(t)}']`)||m(`a[name='${w(e)}']`);return n||"top"!==t||(n=document.body),n},A=function({elements:t,selector:e}){try{if(!1===e&&!t)return Promise.resolve();let n=[];if(t)n=Array.from(t);else if(e&&(n=f(e,document.body),!n.length))return console.warn(`[swup] No elements found matching animationSelector \`${e}\``),Promise.resolve();const r=n.map(t=>function(t){const{type:e,timeout:n,propCount:r}=function(t,e){const n=window.getComputedStyle(t),r=R(n,`${H}Delay`),o=R(n,`${H}Duration`),i=j(r,o),s=R(n,`${q}Delay`),a=R(n,`${q}Duration`),c=j(s,a);let l=null,h=0,u=0;return e===H?i>0&&(l=H,h=i,u=o.length):e===q?c>0&&(l=q,h=c,u=a.length):(h=Math.max(i,c),l=h>0?i>c?H:q:null,u=l?l===H?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[`${H}end`,`${q}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(){}):(e&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${e}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},H="transition",q="animation";function R(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,e={}){try{let r;const c=this;function n(n){if(r)return n;c.navigating=!0,c.visit=t;const{el:l}=t.trigger;e.referrer=e.referrer||c.currentPageUrl,!1===e.animate&&(t.animation.animate=!1),t.animation.animate||c.classes.clear();const h=e.history||l?.getAttribute("data-swup-history")||void 0;h&&["push","replace"].includes(h)&&(t.history.action=h);const u=e.animation||l?.getAttribute("data-swup-animation")||void 0;return u&&(t.animation.name=u),"object"==typeof e.cache?(t.cache.read=e.cache.read??t.cache.read,t.cache.write=e.cache.write??t.cache.write):void 0!==e.cache&&(t.cache={read:!!e.cache,write:!!e.cache}),delete e.cache,function(n,r){try{var l=Promise.resolve(c.hooks.call("visit:start",t,void 0)).then(function(){function n(){if(!t.done)return Promise.resolve(c.hooks.call("visit:transition",t,void 0,function(){try{let n;function e(e){return n?e:(t.advance(4),Promise.resolve(c.animatePageOut(t)).then(function(){function e(){return Promise.resolve(c.animatePageIn(t)).then(function(){})}const n=function(){if(t.animation.native&&document.startViewTransition)return Promise.resolve(document.startViewTransition(function(){try{const e=c.renderPage;return Promise.resolve(r).then(function(n){return Promise.resolve(e.call(c,t,n))})}catch(t){return Promise.reject(t)}}).finished).then(function(){});{const e=c.renderPage;return Promise.resolve(r).then(function(n){return Promise.resolve(e.call(c,t,n)).then(function(){})})}}();return n&&n.then?n.then(e):e()}))}const o=function(){if(!t.animation.animate)return Promise.resolve(c.hooks.call("animation:skip",void 0)).then(function(){const e=c.renderPage;return Promise.resolve(r).then(function(r){return Promise.resolve(e.call(c,t,r)).then(function(){n=1})})})}();return Promise.resolve(o&&o.then?o.then(e):e(o))}catch(i){return Promise.reject(i)}})).then(function(){if(!t.done)return Promise.resolve(c.hooks.call("visit:end",t,void 0,()=>c.classes.clear())).then(function(){t.state=7,c.navigating=!1,c.onVisitEnd&&(c.onVisitEnd(),c.onVisitEnd=void 0)})})}t.state=3;const r=c.hooks.call("page:load",t,{options:e},function(t,e){try{function n(t){return e.page=t,e.cache=!!r,e.page}let r;return t.cache.read&&(r=c.cache.get(t.to.url)),Promise.resolve(r?n(r):Promise.resolve(c.fetchPage(t.to.url,e.options)).then(n))}catch(o){return Promise.reject(o)}});if(r.then(({html:e})=>{t.advance(5),t.to.html=e}),!t.history.popstate){const e=t.to.url+t.to.hash;"replace"===t.history.action||t.to.url===c.currentPageUrl?a(e):(c.currentHistoryIndex++,s(e,{index:c.currentHistoryIndex}))}c.currentPageUrl=i(),t.history.popstate&&c.classes.add("is-popstate"),t.animation.name&&c.classes.add(`to-${o(t.animation.name)}`);const l=function(){if(t.animation.wait)return Promise.resolve(r).then(function(){})}();return l&&l.then?l.then(n):n()})}catch(t){return r(t)}return l&&l.then?l.then(void 0,r):l}(0,function(e){e&&!e?.aborted?(t.state=9,console.error(e),c.options.skipPopStateHandling=()=>(window.location.href=t.to.url+t.to.hash,!0),window.history.go(-1)):t.state=8})}const l=function(){if(c.navigating)return function(){if(!(c.visit.state>=6))return Promise.resolve(c.hooks.call("visit:abort",c.visit,void 0)).then(function(){c.visit.state=8});t.state=2,c.onVisitEnd=()=>c.performNavigation(t,e),r=1}()}();return Promise.resolve(l&&l.then?l.then(n):n(l))}catch(h){return Promise.reject(h)}};function L(t,e={},n={}){if("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}=l.fromUrl(t),i=this.createVisit({...n,to:r,hash:o});this.performNavigation(i,e)}const T=function(t){try{const e=this;return Promise.resolve(e.hooks.call("animation:out:start",t,void 0,()=>{e.classes.add("is-changing","is-animating","is-leaving")})).then(function(){return Promise.resolve(e.hooks.call("animation:out:await",t,{skip:!1},(t,{skip:n})=>{if(!n)return e.awaitAnimations({selector:t.animation.selector})})).then(function(){return Promise.resolve(e.hooks.call("animation:out:end",t,void 0)).then(function(){})})})}catch(t){return Promise.reject(t)}},V=function({html:t},{containers:e}=this.options){const n=(new DOMParser).parseFromString(t,"text/html"),r=n.querySelector("title")?.innerText||"";document.title=r;const o=f('[data-swup-persist]:not([data-swup-persist=""])'),i=e.map(t=>{const e=document.querySelector(t),r=n.querySelector(t);return e&&r?(e.replaceWith(r),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),r||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean);return o.forEach(t=>{const e=t.getAttribute("data-swup-persist"),n=m(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),i.length===e.length},N=function(t){const e={behavior:"auto"},{target:n,reset:r}=t.scroll,o=n??t.to.hash;let i=!1;return o&&(i=this.hooks.callSync("scroll:anchor",t,{hash:o,options:e},(t,{hash:e,options:n})=>{const r=this.getAnchorElement(e);return r&&r.scrollIntoView(n),!!r})),r&&!i&&(i=this.hooks.callSync("scroll:top",t,{options:e},(t,{options:e})=>(window.scrollTo({top:0,left:0,...e}),!0))),i},D=function(t){try{const e=this;if(t.done)return Promise.resolve();const n=e.hooks.call("animation:in:await",t,{skip:!1},(t,{skip:n})=>{if(!n)return e.awaitAnimations({selector:t.animation.selector})});return Promise.resolve(p()).then(function(){return Promise.resolve(e.hooks.call("animation:in:start",t,void 0,()=>{e.classes.remove("is-animating")})).then(function(){return Promise.resolve(n).then(function(){return Promise.resolve(e.hooks.call("animation:in:end",t,void 0)).then(function(){})})})})}catch(t){return Promise.reject(t)}},M=function(t,e){try{const n=this;if(t.done)return Promise.resolve();t.advance(6);const{url:r}=e;return n.classes.remove("is-leaving"),n.isSameResolvedUrl(i(),r)||(a(r),n.currentPageUrl=i(),t.to.url=n.currentPageUrl),t.animation.animate&&n.classes.add("is-rendering"),Promise.resolve(n.hooks.call("content:replace",t,{page:e},(t,{page:e})=>{if(!n.replaceContent(e,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(n.classes.add("is-changing","is-animating","is-rendering"),t.animation.name&&n.classes.add(`to-${o(t.animation.name)}`))})).then(function(){return Promise.resolve(n.hooks.call("content:scroll",t,void 0,()=>n.scrollToContent(t))).then(function(){return Promise.resolve(n.hooks.call("page:view",t,{url:n.currentPageUrl,title:document.title})).then(function(){})})})}catch(t){return Promise.reject(t)}},O=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 W(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function B(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${String(t)}`)}function _(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 F(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}const K={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],ignoreVisit:(t,{el:e}={})=>!!e?.closest("[data-no-swup]"),linkSelector:"a[href]",linkToSelf:"scroll",native:!1,plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source,timeout:0};exports.Location=l,exports.classify=o,exports.createHistoryRecord=s,exports.default=class{constructor(t={}){this.version="4.5.0",this.options=void 0,this.defaults=K,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.currentPageUrl=i(),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.navigating=!1,this.onVisitEnd=void 0,this.use=O,this.unuse=W,this.findPlugin=B,this.log=()=>{},this.navigate=L,this.performNavigation=I,this.createVisit=b,this.delegateEvent=c,this.fetchPage=h,this.awaitAnimations=A,this.renderPage=M,this.replaceContent=V,this.animatePageIn=D,this.animatePageOut=T,this.scrollToContent=N,this.getAnchorElement=$,this.getCurrentUrl=i,this.resolveUrl=_,this.isSameResolvedUrl=F,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new d(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.native=t.options.native&&!!document.startViewTransition,t.options.plugins.forEach(e=>t.use(e)),"swup"!==history.state?.source&&a(null,{index:t.currentHistoryIndex}),Promise.resolve(p()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,void 0,()=>{const e=document.documentElement;e.classList.add("swup-enabled"),e.classList.toggle("swup-native",t.options.native)})).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,void 0,()=>{const t=document.documentElement;t.classList.remove("swup-enabled"),t.classList.remove("swup-native")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,{el:e,event:n}={}){const{origin:r,url:o,hash:i}=l.fromUrl(t);return r!==window.location.origin||!(!e||!this.triggerWillOpenNewWindow(e))||!!this.options.ignoreVisit(o+i,{el:e,event:n})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:r,hash:o}=l.fromElement(e);if(this.shouldIgnoreVisit(n,{el:e,event:t}))return;if(this.navigating&&r===this.visit.to.url)return void t.preventDefault();const i=this.createVisit({to:r,hash:o,el:e,event:t});t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.callSync("link:newtab",i,{href:n}):0===t.button&&this.hooks.callSync("link:click",i,{el:e,event:t},()=>{const e=i.from.url??"";t.preventDefault(),r&&r!==e?this.isSameResolvedUrl(r,e)||this.performNavigation(i):o?this.hooks.callSync("link:anchor",i,{hash:o},()=>{a(r+o),this.scrollToContent(i)}):this.hooks.callSync("link:self",i,void 0,()=>{"navigate"===this.options.linkToSelf?this.performNavigation(i):(a(r),this.scrollToContent(i))})})}handlePopState(t){const e=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(i(),this.currentPageUrl))return;const{url:n,hash:r}=l.fromUrl(e),o=this.createVisit({to:n,hash:r,event:t});o.history.popstate=!0;const s=t.state?.index??0;s&&s!==this.currentHistoryIndex&&(o.history.direction=s-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=s),o.animation.animate=!1,o.scroll.reset=!1,o.scroll.target=!1,this.options.animateHistoryBrowsing&&(o.animation.animate=!0,o.scroll.reset=!0),this.hooks.callSync("history:popstate",o,{event:t},()=>{this.performNavigation(o)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}},exports.delegateEvent=c,exports.escapeCssIdentifier=w,exports.forceReflow=function(t){return t=t||document.body,t?.offsetHeight},exports.getCurrentUrl=i,exports.isPromise=v,exports.matchPath=(t,n)=>{try{return e.match(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${String(t)}":\n${String(e)}`)}},exports.nextTick=p,exports.query=m,exports.queryAll=f,exports.runAsPromise=g,exports.toMs=y,exports.updateHistoryRecord=a;
2
2
  //# sourceMappingURL=Swup.cjs.map