swup 4.2.0 → 4.3.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 (65) 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 +119 -119
  10. package/dist/types/__test__/index.test.d.ts +1 -1
  11. package/dist/types/config/version.d.ts +5 -5
  12. package/dist/types/helpers/Location.d.ts +24 -24
  13. package/dist/types/helpers/__test__/matchPath.test.d.ts +1 -1
  14. package/dist/types/helpers/classify.d.ts +2 -2
  15. package/dist/types/helpers/createHistoryRecord.d.ts +9 -2
  16. package/dist/types/helpers/delegateEvent.d.ts +7 -7
  17. package/dist/types/helpers/getCurrentUrl.d.ts +4 -4
  18. package/dist/types/helpers/matchPath.d.ts +4 -4
  19. package/dist/types/helpers/updateHistoryRecord.d.ts +2 -2
  20. package/dist/types/helpers.d.ts +7 -7
  21. package/dist/types/index.d.ts +14 -14
  22. package/dist/types/modules/Cache.d.ts +34 -34
  23. package/dist/types/modules/Classes.d.ts +13 -13
  24. package/dist/types/modules/Hooks.d.ts +268 -250
  25. package/dist/types/modules/Visit.d.ts +85 -77
  26. package/dist/types/modules/__test__/cache.test.d.ts +1 -1
  27. package/dist/types/modules/__test__/{delegateEvent.d.ts → delegateEvent.test.d.ts} +1 -1
  28. package/dist/types/modules/__test__/hooks.test.d.ts +1 -1
  29. package/dist/types/modules/__test__/plugins.test.d.ts +1 -1
  30. package/dist/types/modules/__test__/replaceContent.test.d.ts +1 -1
  31. package/dist/types/modules/animatePageIn.d.ts +6 -6
  32. package/dist/types/modules/animatePageOut.d.ts +6 -6
  33. package/dist/types/modules/awaitAnimations.d.ts +19 -19
  34. package/dist/types/modules/fetchPage.d.ts +27 -29
  35. package/dist/types/modules/getAnchorElement.d.ts +9 -9
  36. package/dist/types/modules/navigate.d.ts +41 -35
  37. package/dist/types/modules/plugins.d.ts +26 -26
  38. package/dist/types/modules/renderPage.d.ts +7 -7
  39. package/dist/types/modules/replaceContent.d.ts +13 -13
  40. package/dist/types/modules/resolveUrl.d.ts +14 -14
  41. package/dist/types/modules/scrollToContent.d.ts +6 -6
  42. package/dist/types/utils/index.d.ts +20 -20
  43. package/dist/types/utils.d.ts +1 -1
  44. package/package.json +9 -3
  45. package/src/Swup.ts +7 -6
  46. package/src/config/version.ts +1 -2
  47. package/src/helpers/createHistoryRecord.ts +9 -1
  48. package/src/helpers/matchPath.ts +1 -1
  49. package/src/helpers/updateHistoryRecord.ts +4 -2
  50. package/src/modules/Cache.ts +2 -2
  51. package/src/modules/Classes.ts +1 -1
  52. package/src/modules/Hooks.ts +91 -39
  53. package/src/modules/Visit.ts +13 -0
  54. package/src/modules/__test__/cache.test.ts +3 -3
  55. package/src/modules/__test__/hooks.test.ts +12 -13
  56. package/src/modules/animatePageIn.ts +1 -1
  57. package/src/modules/animatePageOut.ts +2 -2
  58. package/src/modules/awaitAnimations.ts +1 -1
  59. package/src/modules/fetchPage.ts +7 -5
  60. package/src/modules/navigate.ts +23 -4
  61. package/src/modules/plugins.ts +3 -3
  62. package/src/modules/renderPage.ts +1 -5
  63. package/src/modules/replaceContent.ts +13 -0
  64. package/src/utils/index.ts +5 -4
  65. /package/src/modules/__test__/{delegateEvent.ts → delegateEvent.test.ts} +0 -0
package/dist/Swup.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var t=require("delegate-it"),e=require("path-to-regexp");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=/*#__PURE__*/n(t);const o=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",i=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},s=function(t,e){void 0===e&&(e={});const n={url:t=t||i({hash:!0}),random:Math.random(),source:"swup",...e};history.pushState(n,"",t)},a=function(t,e){void 0===t&&(t=null),void 0===e&&(e={}),t=t||i({hash:!0});const n={...history.state,url:t,random:Math.random(),source:"swup",...e};history.replaceState(n,"",t)},l=(t,e,n,o)=>{const i=new AbortController;return o={...o,signal:i.signal},r.default(t,e,n,o),{destroy:()=>i.abort()}};class c extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new c(e)}static fromUrl(t){return new c(t)}}class 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")}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=c.fromUrl(t);return this.swup.resolveUrl(e)}}const u=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},m=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},p=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function f(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function d(t,e){return void 0===e&&(e=[]),new Promise((n,r)=>{const o=t(...e);f(o)?o.then(n,r):n(o)})}const v=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,g=t=>1e3*Number(t.slice(0,-1).replace(",","."));class w{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?m(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}function y(t){let{to:e,from:n=this.currentPageUrl,hash:r,animate:o=!0,animation:i,el:s,event:a,action:l="push",resetScroll:c=!0}=t;return{from:{url:n},to:{url:e,hash:r},containers:this.options.containers,animation:{animate:o,wait:!1,name:i,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:s,event:a},history:{action:l,popstate:!1,direction:void 0},scroll:{reset:c,target: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 U{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:end"],this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n){void 0===n&&(n={});const r=this.get(t);if(!r)return console.warn(`Hook '${t}' not found.`),()=>{};const o=r.size+1,i={...n,id:o,hook:t,handler:e};return r.set(e,i),()=>this.off(t,e)}before(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,before:!0})}replace(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,replace:!0})}once(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n){try{const r=this,{before:o,handler:i,after:s}=r.getHandlers(t,n);return Promise.resolve(r.run(o,e)).then(function(){return Promise.resolve(r.run(i,e)).then(function(n){let[o]=n;return Promise.resolve(r.run(s,e)).then(function(){return r.dispatchDomEvent(t,e),o})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n){const{before:r,handler:o,after:i}=this.getHandlers(t,n);this.runSync(r,e);const[s]=this.runSync(o,e);return this.runSync(i,e),this.dispatchDomEvent(t,e),s}run(t,e){try{const n=this,r=[],o=function(t,e,n){if("function"==typeof t[P]){var r,o,i,s=t[P]();if(function t(n){try{for(;!(r=s.next()).done;)if((n=e(r.value))&&n.then){if(!b(n))return void n.then(t,i||(i=k.bind(null,o=new S,2)));n=n.v}o?k(o,1,n):o=n}catch(t){k(o||(o=new S),2,t)}}(),s.return){var a=function(t){try{r.done||s.return()}catch(t){}return t};if(o&&o.then)return o.then(a,function(t){throw a(t)});a()}return o}if(!("length"in t))throw new TypeError("Object is not iterable");for(var l=[],c=0;c<t.length;c++)l.push(t[c]);return function(t,e,n){var r,o,i=-1;return function n(s){try{for(;++i<t.length;)if((s=e(i))&&s.then){if(!b(s))return void s.then(n,o||(o=k.bind(null,r=new S,2)));s=s.v}r?k(r,1,s):r=s}catch(t){k(r||(r=new S),2,t)}}(),r}(l,function(t){return e(l[t])})}(t,function(t){let{hook:o,handler:i,defaultHandler:s,once:a}=t;return Promise.resolve(d(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=this.sortRegistrations,o=Array.from(n.values()),i=o.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(r),s=o.filter(t=>{let{replace:e}=t;return e}).sort(r),a=o.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(r),l=s.length>0;let c=[];if(e&&(c=[{id:0,hook:t,handler:e}],l)){const n=s.length-1,r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};c=[{id:0,hook:t,handler:s[n].handler,defaultHandler:r(n)}]}return{found:!0,before:i,handler:c,after:a,replaced:l}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e){document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:{hook:t,args:e,visit:this.swup.visit}}))}}const x=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||u(`a[name='${v(t)}']`)||u(`a[name='${v(e)}']`);return n||"top"!==t||(n=document.body),n},E=function(t){let{elements:e,selector:n}=t;try{if(!1===n&&!e)return Promise.resolve();let t=[];if(e)t=Array.from(e);else if(n&&(t=m(n,document.body),!t.length))return console.warn(`[swup] No elements found matching animationSelector \`${n}\``),Promise.resolve();const r=t.map(t=>function(t){const{type:e,timeout:n,propCount:r}=function(t,e){const n=window.getComputedStyle(t),r=A(n,`${C}Delay`),o=A(n,`${C}Duration`),i=H(r,o),s=A(n,`${$}Delay`),a=A(n,`${$}Duration`),l=H(s,a);let c=null,h=0,u=0;return e===C?i>0&&(c=C,h=i,u=o.length):e===$?l>0&&(c=$,h=l,u=a.length):(h=Math.max(i,l),c=h>0?i>l?C:$:null,u=c?c===C?o.length:a.length:0),{type:c,timeout:h,propCount:u}}(t);return!(!e||!n)&&new Promise(o=>{const i=`${e}end`,s=performance.now();let a=0;const l=()=>{t.removeEventListener(i,c),o()},c=e=>{if(e.target===t){if(!function(t){return[`${C}end`,`${$}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-s)/1e3<e.elapsedTime||++a>=r&&l()}};setTimeout(()=>{a<r&&l()},n+1),t.addEventListener(i,c)})}(t));return r.filter(Boolean).length>0?Promise.resolve(Promise.all(r)).then(function(){}):(n&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${n}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},C="transition",$="animation";function A(t,e){return(t[e]||"").split(", ")}function H(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>g(e)+g(t[n])))}const q=function(t){void 0===t&&(t={});try{const e=this,{el:n}=e.visit.trigger;t.referrer=t.referrer||e.currentPageUrl,!1===t.animate&&(e.visit.animation.animate=!1),e.visit.animation.animate||e.classes.clear();const r=t.history||n?.getAttribute("data-swup-history")||void 0;r&&["push","replace"].includes(r)&&(e.visit.history.action=r);const o=t.animation||n?.getAttribute("data-swup-animation")||void 0;return o&&(e.visit.animation.name=o),Promise.resolve(function(n,r){try{var o=Promise.resolve(e.hooks.call("visit:start")).then(function(){function n(){const t=e.animatePageOut();return Promise.resolve(Promise.all([r,t])).then(function(t){let[n]=t;return Promise.resolve(e.renderPage(e.visit.to.url,n)).then(function(){return Promise.resolve(e.animatePageIn()).then(function(){return Promise.resolve(e.hooks.call("visit:end",void 0,()=>e.classes.clear())).then(function(){})})})})}const r=e.hooks.call("page:load",{options:t},function(t,n){try{function r(t){return n.page=t,n.cache=!!o,n.page}const o=e.cache.get(t.to.url);return Promise.resolve(o?r(o):Promise.resolve(e.fetchPage(t.to.url,n.options)).then(r))}catch(i){return Promise.reject(i)}});if(!e.visit.history.popstate){const t=e.visit.to.url+e.visit.to.hash;"replace"===e.visit.history.action||e.visit.to.url===e.currentPageUrl?a(t):s(t,{index:e.currentHistoryIndex+1})}e.currentPageUrl=i();const o=function(){if(e.visit.animation.wait)return Promise.resolve(r).then(function(t){let{html:n}=t;e.visit.to.html=n})}();return o&&o.then?o.then(n):n()})}catch(t){return r(t)}return o&&o.then?o.then(void 0,r):o}(0,function(t){t&&(console.error(t),e.options.skipPopStateHandling=()=>(window.location.href=e.visit.to.url+e.visit.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:o}=c.fromUrl(t);this.visit=this.createVisit({...n,to:r,hash:o}),this.performNavigation(e)}const j=function(t,e){void 0===e&&(e={});try{const n=this;t=c.fromUrl(t).url;const r={...n.options.requestHeaders,...e.headers};return e={...e,headers:r},Promise.resolve(n.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(e){const{status:r,url:o}=e;return Promise.resolve(e.text()).then(function(i){if(500===r)throw n.hooks.call("fetch:error",{status:r,response:e,url:o}),new L(`Server error: ${o}`,{status:r,url:o});if(!i)throw new L(`Empty response: ${o}`,{status:r,url:o});const{url:s}=c.fromUrl(o),a={url:s,html:i};return t===s&&n.cache.set(a.url,a),a})})}catch(t){return Promise.reject(t)}};class L extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.name="FetchError",this.url=e.url,this.status=e.status}}const N=function(){try{let e;const n=this;function t(t){return e?t:Promise.resolve(n.hooks.call("animation:out:start",void 0,t=>{n.classes.add("is-changing","is-leaving","is-animating"),t.history.popstate&&n.classes.add("is-popstate"),t.animation.name&&n.classes.add(`to-${o(t.animation.name)}`)})).then(function(){return Promise.resolve(n.hooks.call("animation:out:await",{skip:!1},function(t,e){let{skip:r}=e;try{return r?Promise.resolve():Promise.resolve(n.awaitAnimations({selector:t.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(n.hooks.call("animation:out:end")).then(function(){})})})}const r=function(){if(!n.visit.animation.animate)return Promise.resolve(n.hooks.call("animation:skip")).then(function(){e=1})}();return Promise.resolve(r&&r.then?r.then(t):t(r))}catch(i){return Promise.reject(i)}},I=function(t,e){let{html:n}=t,{containers:r}=void 0===e?this.options:e;const o=(new DOMParser).parseFromString(n,"text/html"),i=o.querySelector("title")?.innerText||"";return document.title=i,r.map(t=>{const e=document.querySelector(t),n=o.querySelector(t);return e&&n?(e.replaceWith(n),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),n||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean).length===r.length},T=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(p()).then(function(){return Promise.resolve(t.hooks.call("animation:in:start",void 0,()=>{t.classes.remove("is-animating")})).then(function(){return Promise.resolve(e).then(function(){return Promise.resolve(t.hooks.call("animation:in:end")).then(function(){})})})})}catch(t){return Promise.reject(t)}},M=function(t,e){try{const n=this,{url:r,html:s}=e;return n.classes.remove("is-leaving"),n.isSameResolvedUrl(i(),t)?(n.isSameResolvedUrl(i(),r)||(a(r),n.currentPageUrl=i(),n.visit.to.url=n.currentPageUrl),n.visit.animation.animate&&n.classes.add("is-rendering"),n.visit.to.html=s,Promise.resolve(n.hooks.call("content:replace",{page:e},(t,e)=>{let{page:r}=e;if(!n.replaceContent(r,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(n.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&n.classes.add(`to-${o(t.animation.name)}`))})).then(function(){return Promise.resolve(n.hooks.call("content:scroll",void 0,()=>n.scrollToContent())).then(function(){return Promise.resolve(n.hooks.call("page:view",{url:n.currentPageUrl,title:document.title})).then(function(){n.options.cache||n.cache.clear()})})})):Promise.resolve()}catch(t){return Promise.reject(t)}},V=function(t){var e;if(e=t,e?.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function W(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function _(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${t}`)}function B(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function O(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}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};exports.Location=c,exports.classify=o,exports.createHistoryRecord=s,exports.default=class{constructor(t){void 0===t&&(t={}),this.version="4.2.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=i(),this.currentHistoryIndex=1,this.clickDelegate=void 0,this.use=V,this.unuse=W,this.findPlugin=_,this.log=()=>{},this.navigate=R,this.performNavigation=q,this.createVisit=y,this.delegateEvent=l,this.fetchPage=j,this.awaitAnimations=E,this.renderPage=M,this.replaceContent=I,this.animatePageIn=D,this.animatePageOut=N,this.scrollToContent=T,this.getAnchorElement=x,this.getCurrentUrl=i,this.resolveUrl=B,this.isSameResolvedUrl=O,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 w(this),this.hooks=new U(this),this.visit=this.createVisit({to:""}),this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}enable(){try{const t=this,{linkSelector:e}=t.options;return t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.plugins.forEach(e=>t.use(e)),a(null,{index:1}),Promise.resolve(p()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.options.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,e){let{el:n,event:r}=void 0===e?{}:e;const{origin:o,url:i,hash:s}=c.fromUrl(t);return o!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(i+s,{el:n,event:r})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:r,hash:o}=c.fromElement(e);this.shouldIgnoreVisit(n,{el:e,event:t})||(this.visit=this.createVisit({to:r,hash:o,el:e,event:t}),t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.call("link:newtab",{href:n}):0===t.button&&this.hooks.callSync("link:click",{el:e,event:t},()=>{const e=this.visit.from.url??"";t.preventDefault(),r&&r!==e?this.isSameResolvedUrl(r,e)||this.performNavigation():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():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}=c.fromUrl(e);this.visit=this.createVisit({to:n,hash:r,event:t,animate:this.options.animateHistoryBrowsing,resetScroll:this.options.animateHistoryBrowsing}),this.visit.history.popstate=!0;const o=Number(t.state?.index);o&&(this.visit.history.direction=o-this.currentHistoryIndex>0?"forwards":"backwards"),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation()})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}},exports.delegateEvent=l,exports.escapeCssIdentifier=v,exports.forceReflow=function(t){return t=t||document.body,t?.offsetHeight},exports.getCurrentUrl=i,exports.isPromise=f,exports.matchPath=(t,n)=>{try{return e.match(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${t}":\n${e}`)}},exports.nextTick=p,exports.query=u,exports.queryAll=m,exports.runAsPromise=d,exports.toMs=g,exports.updateHistoryRecord=a;
1
+ var t=require("delegate-it"),e=require("path-to-regexp");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=/*#__PURE__*/n(t);const i=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",o=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},s=function(t,e){void 0===e&&(e={});const n={url:t=t||o({hash:!0}),random:Math.random(),source:"swup",...e};history.pushState(n,"",t)},a=function(t,e){void 0===t&&(t=null),void 0===e&&(e={}),t=t||o({hash:!0});const n={...history.state||{},url:t,random:Math.random(),source:"swup",...e};history.replaceState(n,"",t)},c=(t,e,n,i)=>{const o=new AbortController;return i={...i,signal:o.signal},r.default(t,e,n,i),{destroy:()=>o.abort()}};class l 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 l(e)}static fromUrl(t){return new l(t)}}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}=l.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))},p=()=>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 i=t(...e);m(i)?i.then(n,r):n(i)})}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()?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 y(t){let{to:e,from:n=this.currentPageUrl,hash:r,animate:i=!0,animation:o,el:s,event:a,action:c="push",resetScroll:l=!0}=t;return{from:{url:n},to:{url:e,hash:r},containers:this.options.containers,animation:{animate:i,wait:!1,name:o,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:s,event:a},cache:{read:this.options.cache,write:this.options.cache},history:{action:c,popstate:!1,direction:void 0},scroll:{reset:l,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,i=this.s;if(i){const t=1&i?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 i=t.v;1&t.s?k(r,1,e?e(i):i):n?k(r,1,n(i)):k(r,2,i)}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","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:end"],this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n){void 0===n&&(n={});const r=this.get(t);if(!r)return console.warn(`Hook '${t}' not found.`),()=>{};const 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[P]){var r,i,o,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,o||(o=k.bind(null,i=new S,2)));n=n.v}i?k(i,1,n):i=n}catch(t){k(i||(i=new S),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(!b(s))return void s.then(n,i||(i=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:i,handler:o,defaultHandler:s,once:a}=t;return Promise.resolve(f(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),m(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 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)||u(`a[name='${v(t)}']`)||u(`a[name='${v(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=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=A(n,`${C}Delay`),i=A(n,`${C}Duration`),o=H(r,i),s=A(n,`${$}Delay`),a=A(n,`${$}Duration`),c=H(s,a);let l=null,h=0,u=0;return e===C?o>0&&(l=C,h=o,u=i.length):e===$?c>0&&(l=$,h=c,u=a.length):(h=Math.max(o,c),l=h>0?o>c?C:$:null,u=l?l===C?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[`${C}end`,`${$}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)}},C="transition",$="animation";function A(t,e){return(t[e]||"").split(", ")}function H(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>g(e)+g(t[n])))}const q=function(t){void 0===t&&(t={});try{const e=this,{el:n}=e.visit.trigger;t.referrer=t.referrer||e.currentPageUrl,!1===t.animate&&(e.visit.animation.animate=!1),e.visit.animation.animate||e.classes.clear();const r=t.history||n?.getAttribute("data-swup-history")||void 0;r&&["push","replace"].includes(r)&&(e.visit.history.action=r);const i=t.animation||n?.getAttribute("data-swup-animation")||void 0;return i&&(e.visit.animation.name=i),"object"==typeof t.cache?(e.visit.cache.read=t.cache.read??e.visit.cache.read,e.visit.cache.write=t.cache.write??e.visit.cache.write):void 0!==t.cache&&(e.visit.cache={read:!!t.cache,write:!!t.cache}),delete t.cache,Promise.resolve(function(n,r){try{var i=Promise.resolve(e.hooks.call("visit:start",void 0)).then(function(){function n(){const t=e.animatePageOut();return Promise.resolve(Promise.all([r,t])).then(function(t){let[n]=t;return Promise.resolve(e.renderPage(e.visit.to.url,n)).then(function(){return Promise.resolve(e.animatePageIn()).then(function(){return Promise.resolve(e.hooks.call("visit:end",void 0,()=>e.classes.clear())).then(function(){})})})})}const r=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 e.visit.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(!e.visit.history.popstate){const t=e.visit.to.url+e.visit.to.hash;"replace"===e.visit.history.action||e.visit.to.url===e.currentPageUrl?a(t):s(t,{index:e.currentHistoryIndex+1})}e.currentPageUrl=o();const i=function(){if(e.visit.animation.wait)return Promise.resolve(r).then(function(t){let{html:n}=t;e.visit.to.html=n})}();return i&&i.then?i.then(n):n()})}catch(t){return r(t)}return i&&i.then?i.then(void 0,r):i}(0,function(t){t&&(console.error(t),e.options.skipPopStateHandling=()=>(window.location.href=e.visit.to.url+e.visit.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}=l.fromUrl(t);this.visit=this.createVisit({...n,to:r,hash:i}),this.performNavigation(e)}const j=function(t,e){void 0===e&&(e={});try{const n=this;t=l.fromUrl(t).url;const r={...n.options.requestHeaders,...e.headers};return e={...e,headers:r},Promise.resolve(n.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(r){const{status:i,url:o}=r;return Promise.resolve(r.text()).then(function(s){if(500===i)throw n.hooks.call("fetch:error",{status:i,response:r,url:o}),new L(`Server error: ${o}`,{status:i,url:o});if(!s)throw new L(`Empty response: ${o}`,{status:i,url:o});const{url:a}=l.fromUrl(o),c={url:a,html:s};return!n.visit.cache.write||e.method&&"GET"!==e.method||t!==a||n.cache.set(c.url,c),c})})}catch(t){return Promise.reject(t)}};class L extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.name="FetchError",this.url=e.url,this.status=e.status}}const N=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-${i(t.animation.name)}`)})).then(function(){return Promise.resolve(n.hooks.call("animation:out:await",{skip:!1},function(t,e){let{skip:r}=e;try{return r?Promise.resolve():Promise.resolve(n.awaitAnimations({selector:t.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(n.hooks.call("animation:out:end",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(o){return Promise.reject(o)}},I=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=d('[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=u(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),a.length===r.length},T=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(p()).then(function(){return Promise.resolve(t.hooks.call("animation:in:start",void 0,()=>{t.classes.remove("is-animating")})).then(function(){return Promise.resolve(e).then(function(){return Promise.resolve(t.hooks.call("animation:in:end",void 0)).then(function(){})})})})}catch(t){return Promise.reject(t)}},M=function(t,e){try{const n=this,{url:r,html:s}=e;return n.classes.remove("is-leaving"),n.isSameResolvedUrl(o(),t)?(n.isSameResolvedUrl(o(),r)||(a(r),n.currentPageUrl=o(),n.visit.to.url=n.currentPageUrl),n.visit.animation.animate&&n.classes.add("is-rendering"),n.visit.to.html=s,Promise.resolve(n.hooks.call("content:replace",{page:e},(t,e)=>{let{page:r}=e;if(!n.replaceContent(r,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(n.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&n.classes.add(`to-${i(t.animation.name)}`))})).then(function(){return Promise.resolve(n.hooks.call("content:scroll",void 0,()=>n.scrollToContent())).then(function(){return Promise.resolve(n.hooks.call("page:view",{url:n.currentPageUrl,title:document.title})).then(function(){})})})):Promise.resolve()}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 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 O(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};exports.Location=l,exports.classify=i,exports.createHistoryRecord=s,exports.default=class{constructor(t){void 0===t&&(t={}),this.version="4.3.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=o(),this.currentHistoryIndex=1,this.clickDelegate=void 0,this.use=V,this.unuse=W,this.findPlugin=B,this.log=()=>{},this.navigate=R,this.performNavigation=q,this.createVisit=y,this.delegateEvent=c,this.fetchPage=j,this.awaitAnimations=x,this.renderPage=M,this.replaceContent=I,this.animatePageIn=D,this.animatePageOut=N,this.scrollToContent=T,this.getAnchorElement=U,this.getCurrentUrl=o,this.resolveUrl=_,this.isSameResolvedUrl=O,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 w(this),this.hooks=new E(this),this.visit=this.createVisit({to:""}),this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}enable(){try{const t=this,{linkSelector:e}=t.options;return t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.plugins.forEach(e=>t.use(e)),a(null,{index:1}),Promise.resolve(p()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.options.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,e){let{el:n,event:r}=void 0===e?{}:e;const{origin:i,url:o,hash:s}=l.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}=l.fromElement(e);this.shouldIgnoreVisit(n,{el:e,event:t})||(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},()=>{a(r+i),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>"navigate"===this.options.linkToSelf?this.performNavigation():this.scrollToContent())}))}handlePopState(t){const e=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(o(),this.currentPageUrl))return;const{url:n,hash:r}=l.fromUrl(e);this.visit=this.createVisit({to:n,hash:r,event:t,animate:this.options.animateHistoryBrowsing,resetScroll:this.options.animateHistoryBrowsing}),this.visit.history.popstate=!0;const i=Number(t.state?.index);i&&(this.visit.history.direction=i-this.currentHistoryIndex>0?"forwards":"backwards"),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation()})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}},exports.delegateEvent=c,exports.escapeCssIdentifier=v,exports.forceReflow=function(t){return t=t||document.body,t?.offsetHeight},exports.getCurrentUrl=o,exports.isPromise=m,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=u,exports.queryAll=d,exports.runAsPromise=f,exports.toMs=g,exports.updateHistoryRecord=a;
2
2
  //# sourceMappingURL=Swup.cjs.map