Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swup

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swup - npm Package Compare versions

Comparing version 4.0.0-rc.27 to 4.0.0-rc.28

dist/types/modules/resolveUrl.d.ts

2

dist/Swup.modern.js

@@ -1,2 +0,2 @@

import t from"delegate-it";import{match as e}from"path-to-regexp";function s(){return s=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t},s.apply(this,arguments)}const i=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",n=({hash:t}={})=>location.pathname+location.search+(t?location.hash:""),o=(t,e={})=>{const i=s({url:t=t||n({hash:!0}),random:Math.random(),source:"swup"},e);history.pushState(i,"",t)},r=(t=null,e={})=>{t=t||n({hash:!0});const i=s({},history.state,{url:t,random:Math.random(),source:"swup"},e);history.replaceState(i,"",t)},a=(e,i,n,o)=>{const r=new AbortController;return o=s({},o,{signal:r.signal}),t(e,i,n,o),{destroy:()=>r.abort()}};class l extends URL{constructor(t,e=document.baseURI){super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new l(e)}static fromUrl(t){return new l(t)}}const h=(t,s)=>{try{return e(t,s)}catch(e){throw new Error(`[swup] Error parsing path "${t}":\n${e}`)}};class c{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){return this.pages}has(t){return this.pages.has(this.resolve(t))}get(t){return this.pages.get(this.resolve(t))}set(t,e){e=s({},e,{url:t=this.resolve(t)}),this.pages.set(t,e),this.swup.hooks.callSync("cache:set",{page:e})}update(t,e){t=this.resolve(t),e=s({},this.get(t),e,{url:t}),this.pages.set(t,e)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear")}prune(t){this.pages.forEach((e,s)=>{t(s,e)&&this.delete(s)})}resolve(t){const{url:e}=l.fromUrl(t);return this.swup.resolveUrl(e)}}const u=(t,e=document)=>e.querySelector(t),p=(t,e=document)=>Array.from(e.querySelectorAll(t)),d=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function m(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function g(t,e=[]){return new Promise((s,i)=>{const n=t(...e);m(n)?n.then(s,i):s(n)})}function f(t){var e;return null==(e=t=t||document.body)?void 0:e.offsetHeight}const w=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,v=t=>1e3*Number(t.slice(0,-1).replace(",","."));class y{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?p(this.selector):[]}add(...t){this.targets.forEach(e=>e.classList.add(...t))}remove(...t){this.targets.forEach(e=>e.classList.remove(...t))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}function k({to:t,from:e=this.currentPageUrl,hash:s,animate:i=!0,animation:n,el:o,event:r,action:a="push",resetScroll:l=!0}){return{from:{url:e},to:{url:t},containers:this.options.containers,animation:{animate:i,wait:!1,name:n,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:o,event:r},history:{action:a,popstate:!1,direction:void 0},scroll:{reset:l,target:s}}}class S{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","history:popstate","link:click","link:self","link:anchor","link:newtab","page:request","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,i={}){const n=this.get(t);if(!n)return console.warn(`Hook '${t}' not found.`),()=>{};const o=s({},i,{id:n.size+1,hook:t,handler:e});return n.set(e,o),()=>this.off(t,e)}before(t,e,i={}){return this.on(t,e,s({},i,{before:!0}))}replace(t,e,i={}){return this.on(t,e,s({},i,{replace:!0}))}once(t,e,i={}){return this.on(t,e,s({},i,{once:!0}))}off(t,e){const s=this.get(t);s&&e?s.delete(e)||console.warn(`Handler for hook '${t}' not found.`):s&&s.clear()}async call(t,e,s){const{before:i,handler:n,after:o}=this.getHandlers(t,s);await this.run(i,e);const[r]=await this.run(n,e);return await this.run(o,e),this.dispatchDomEvent(t,e),r}callSync(t,e,s){const{before:i,handler:n,after:o}=this.getHandlers(t,s);this.runSync(i,e);const[r]=this.runSync(n,e);return this.runSync(o,e),this.dispatchDomEvent(t,e),r}async run(t,e){const s=[];for(const{hook:i,handler:n,defaultHandler:o,once:r}of t){const t=await g(n,[this.swup.visit,e,o]);s.push(t),r&&this.off(i,n)}return s}runSync(t,e){const s=[];for(const{hook:i,handler:n,defaultHandler:o,once:r}of t){const t=n(this.swup.visit,e,o);s.push(t),m(t)&&console.warn(`Promise returned from handler for synchronous hook '${i}'.Swup will not wait for it to resolve.`),r&&this.off(i,n)}return s}getHandlers(t,e){const s=this.get(t);if(!s)return{found:!1,before:[],handler:[],after:[],replaced:!1};const i=this.sortRegistrations,n=Array.from(s.values()),o=n.filter(({before:t,replace:e})=>t&&!e).sort(i),r=n.filter(({replace:t})=>t).sort(i),a=n.filter(({before:t,replace:e})=>!t&&!e).sort(i),l=r.length>0;let h=[];if(e&&(h=[{id:0,hook:t,handler:e}],l)){const s=r.length-1,i=t=>{const s=r[t-1];return s?(e,n)=>s.handler(e,n,i(t-1)):e};h=[{id:0,hook:t,handler:r[s].handler,defaultHandler:i(s)}]}return{found:!0,before:o,handler:h,after:a,replaced:l}}sortRegistrations(t,e){var s,i;return(null!=(s=t.priority)?s:0)-(null!=(i=e.priority)?i:0)||t.id-e.id||0}dispatchDomEvent(t,e){document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:{hook:t,args:e,visit:this.swup.visit}}))}}const b=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let s=document.getElementById(t)||document.getElementById(e)||u(`a[name='${w(t)}']`)||u(`a[name='${w(e)}']`);return s||"top"!==t||(s=document.body),s},U="transition",E="animation";async function P({elements:t,selector:e}){if(!1===e&&!t)return;let s=[];if(t)s=Array.from(t);else if(e&&(s=p(e,document.body),!s.length))return void console.warn(`[swup] No elements found matching animationSelector \`${e}\``);const i=s.map(t=>function(t){const{type:e,timeout:s,propCount:i}=function(t,e){const s=window.getComputedStyle(t),i=H(s,`${U}Delay`),n=H(s,`${U}Duration`),o=C(i,n),r=H(s,`${E}Delay`),a=H(s,`${E}Duration`),l=C(r,a);let h=null,c=0,u=0;return c=Math.max(o,l),h=c>0?o>l?U:E:null,u=h?h===U?n.length:a.length:0,{type:h,timeout:c,propCount:u}}(t);return!(!e||!s)&&new Promise(n=>{const o=`${e}end`,r=performance.now();let a=0;const l=()=>{t.removeEventListener(o,h),n()},h=e=>{if(e.target===t){if(!function(t){return[`${U}end`,`${E}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-r)/1e3<e.elapsedTime||++a>=i&&l()}};setTimeout(()=>{a<i&&l()},s+1),t.addEventListener(o,h)})}(t));i.filter(Boolean).length>0?await Promise.all(i):e&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${e}\``)}function H(t,e){return(t[e]||"").split(", ")}function C(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,s)=>v(e)+v(t[s])))}function $(t,e={},i={}){if(this.shouldIgnoreVisit(t))return void(window.location.href=t);const{url:n,hash:o}=l.fromUrl(t);this.visit=this.createVisit(s({},i,{to:n,hash:o})),this.performNavigation(n,e)}async function x(t,e={}){if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");const{el:s}=this.visit.trigger;this.visit.to.url=l.fromUrl(t).url,e.referrer=e.referrer||this.currentPageUrl,!1===e.animate&&(this.visit.animation.animate=!1),this.visit.animation.animate||this.classes.clear();const i=e.history||(null==s?void 0:s.getAttribute("data-swup-history"))||void 0;i&&["push","replace"].includes(i)&&(this.visit.history.action=i);const a=e.animation||(null==s?void 0:s.getAttribute("data-swup-animation"))||void 0;a&&(this.visit.animation.name=a);try{await this.hooks.call("visit:start");const s=this.hooks.call("page:request",{url:this.visit.to.url,options:e},async(t,{options:e})=>await this.fetchPage(t.to.url,e));if(!this.visit.history.popstate){const e=t+(this.visit.scroll.target||"");"replace"===this.visit.history.action?r(e):o(e,{index:this.currentHistoryIndex+1})}if(this.currentPageUrl=n(),this.visit.animation.wait){const{html:t}=await s;this.visit.to.html=t}const i=this.animatePageOut(),[a]=await Promise.all([s,i]);await this.renderPage(this.visit.to.url,a),await this.animatePageIn(),await this.hooks.call("visit:end",void 0,()=>this.classes.clear())}catch(t){if(!t)return;console.error(t),this.options.skipPopStateHandling=()=>(window.location.href=this.visit.to.url,!0),window.history.go(-1)}}class A extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.name="FetchError",this.url=e.url,this.status=e.status}}async function q(t,e={}){if(t=l.fromUrl(t).url,this.cache.has(t)){const s=this.cache.get(t);return!1!==e.triggerHooks&&await this.hooks.call("page:load",{page:s,cache:!0}),s}const i=s({},this.options.requestHeaders,e.headers);e=s({},e,{headers:i});const n=await this.hooks.call("fetch:request",{url:t,options:e},(t,{url:e,options:s})=>fetch(e,s)),{status:o,url:r}=n,a=await n.text();if(500===o)throw this.hooks.call("fetch:error",{status:o,response:n,url:r}),new A(`Server error: ${r}`,{status:o,url:r});if(!a)throw new A(`Empty response: ${r}`,{status:o,url:r});const{url:h}=l.fromUrl(r),c={url:h,html:a};return t===h&&this.cache.set(c.url,c),!1!==e.triggerHooks&&await this.hooks.call("page:load",{page:c,cache:!1}),c}const R=async function(){this.visit.animation.animate?(await this.hooks.call("animation:out:start",void 0,t=>{this.classes.add("is-changing","is-leaving","is-animating"),t.history.popstate&&this.classes.add("is-popstate"),t.animation.name&&this.classes.add(`to-${i(t.animation.name)}`)}),await this.hooks.call("animation:out:await",{skip:!1},async(t,{skip:e})=>{e||await this.awaitAnimations({selector:t.animation.selector})}),await this.hooks.call("animation:out:end")):await this.hooks.call("animation:skip")},I=function({html:t},{containers:e}=this.options){var s;const i=(new DOMParser).parseFromString(t,"text/html"),n=(null==(s=i.querySelector("title"))?void 0:s.innerText)||"";return document.title=n,e.map(t=>{const e=document.querySelector(t),s=i.querySelector(t);return e&&s?(e.replaceWith(s),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),s||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean).length===e.length},N=function(){const t={behavior:"auto"},{target:e,reset:i}=this.visit.scroll;let n=!1;return e&&(n=this.hooks.callSync("scroll:anchor",{hash:e,options:t},(t,{hash:e,options:s})=>{const i=this.getAnchorElement(e||"");return i&&i.scrollIntoView(s),!!i})),i&&!n&&(n=this.hooks.callSync("scroll:top",{options:t},(t,{options:e})=>(window.scrollTo(s({top:0,left:0},e)),!0))),n},D=async function(){if(!this.visit.animation.animate)return;const t=this.hooks.call("animation:in:await",{skip:!1},async(t,{skip:e})=>{e||await this.awaitAnimations({selector:t.animation.selector})});await d(),await this.hooks.call("animation:in:start",void 0,()=>{this.classes.remove("is-animating")}),await t,await this.hooks.call("animation:in:end")},L=async function(t,e){const{url:s,html:o}=e;this.classes.remove("is-leaving"),this.isSameResolvedUrl(n(),t)&&(this.isSameResolvedUrl(n(),s)||(r(s),this.currentPageUrl=n(),this.visit.to.url=this.currentPageUrl),this.visit.animation.animate&&this.classes.add("is-rendering"),this.visit.to.html=o,await this.hooks.call("content:replace",{page:e},(t,{page:e})=>{if(!this.replaceContent(e,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(this.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&this.classes.add(`to-${i(t.animation.name)}`))}),await this.hooks.call("content:scroll",void 0,()=>this.scrollToContent()),await this.hooks.call("page:view",{url:this.currentPageUrl,title:document.title}),this.options.cache||this.cache.clear())},V=function(t){var e;if(null==(e=t)?void 0:e.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function M(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function O(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${t}`)}class T{constructor(t={}){this.version="4.0.0-rc.27",this.options=void 0,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.currentPageUrl=n(),this.currentHistoryIndex=1,this.clickDelegate=void 0,this.navigate=$,this.performNavigation=x,this.animatePageOut=R,this.renderPage=L,this.replaceContent=I,this.scrollToContent=N,this.animatePageIn=D,this.delegateEvent=a,this.fetchPage=q,this.awaitAnimations=P,this.getAnchorElement=b,this.use=V,this.unuse=M,this.findPlugin=O,this.getCurrentUrl=n,this.createVisit=k,this.log=()=>{},this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],ignoreVisit:(t,{el:e}={})=>!(null==e||!e.closest("[data-no-swup]")),linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>{var e;return"swup"!==(null==(e=t.state)?void 0:e.source)}},this.options=s({},this.defaults,t),this.linkClickHandler=this.linkClickHandler.bind(this),this.popStateHandler=this.popStateHandler.bind(this),this.cache=new c(this),this.classes=new y(this),this.hooks=new S(this),this.visit=this.createVisit({to:void 0}),this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}async enable(){const{linkSelector:t}=this.options;this.clickDelegate=this.delegateEvent(t,"click",this.linkClickHandler),window.addEventListener("popstate",this.popStateHandler),this.options.plugins.forEach(t=>this.use(t)),r(null,{index:1}),await d(),await this.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})}async destroy(){this.clickDelegate.destroy(),window.removeEventListener("popstate",this.popStateHandler),this.cache.clear(),this.options.plugins.forEach(t=>this.unuse(t)),await this.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")}),this.hooks.clear()}shouldIgnoreVisit(t,{el:e,event:s}={}){const{origin:i,url:n,hash:o}=l.fromUrl(t);return i!==window.location.origin||!(!e||!this.triggerWillOpenNewWindow(e))||!!this.options.ignoreVisit(n+o,{el:e,event:s})}linkClickHandler(t){const e=t.delegateTarget,{href:s,url:i,hash:n}=l.fromElement(e);this.shouldIgnoreVisit(s,{el:e,event:t})||(this.visit=this.createVisit({to:i,hash:n,el:e,event:t}),t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.call("link:newtab",{href:s}):0===t.button&&this.hooks.callSync("link:click",{el:e,event:t},()=>{var e;const s=null!=(e=this.visit.from.url)?e:"";t.preventDefault(),i&&i!==s?this.isSameResolvedUrl(i,s)||this.performNavigation(i):n?this.hooks.callSync("link:anchor",{hash:n},()=>{r(i+n),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>{this.scrollToContent()})}))}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}popStateHandler(t){var e,s,i;const o=null!=(e=null==(s=t.state)?void 0:s.url)?e:location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(n(),this.currentPageUrl))return;if(this.shouldIgnoreVisit(o,{event:t}))return;const{url:r,hash:a}=l.fromUrl(o);this.visit=this.createVisit({to:r,hash:a,event:t,animate:this.options.animateHistoryBrowsing,resetScroll:this.options.animateHistoryBrowsing}),this.visit.history.popstate=!0;const h=Number(null==(i=t.state)?void 0:i.index);h&&(this.visit.history.direction=h-this.currentHistoryIndex>0?"forwards":"backwards"),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation(r)})}resolveUrl(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)}isSameResolvedUrl(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}}export{l as Location,i as classify,o as createHistoryRecord,T as default,a as delegateEvent,w as escapeCssIdentifier,f as forceReflow,n as getCurrentUrl,m as isPromise,h as matchPath,d as nextTick,u as query,p as queryAll,g as runAsPromise,v as toMs,r as updateHistoryRecord};
import t from"delegate-it";import{match as e}from"path-to-regexp";function i(){return i=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},i.apply(this,arguments)}const s=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",n=({hash:t}={})=>location.pathname+location.search+(t?location.hash:""),o=(t,e={})=>{const s=i({url:t=t||n({hash:!0}),random:Math.random(),source:"swup"},e);history.pushState(s,"",t)},r=(t=null,e={})=>{t=t||n({hash:!0});const s=i({},history.state,{url:t,random:Math.random(),source:"swup"},e);history.replaceState(s,"",t)},a=(e,s,n,o)=>{const r=new AbortController;return o=i({},o,{signal:r.signal}),t(e,s,n,o),{destroy:()=>r.abort()}};class l extends URL{constructor(t,e=document.baseURI){super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new l(e)}static fromUrl(t){return new l(t)}}const h=(t,i)=>{try{return e(t,i)}catch(e){throw new Error(`[swup] Error parsing path "${t}":\n${e}`)}};class c{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){return this.pages}has(t){return this.pages.has(this.resolve(t))}get(t){return this.pages.get(this.resolve(t))}set(t,e){e=i({},e,{url:t=this.resolve(t)}),this.pages.set(t,e),this.swup.hooks.callSync("cache:set",{page:e})}update(t,e){t=this.resolve(t),e=i({},this.get(t),e,{url:t}),this.pages.set(t,e)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear")}prune(t){this.pages.forEach((e,i)=>{t(i,e)&&this.delete(i)})}resolve(t){const{url:e}=l.fromUrl(t);return this.swup.resolveUrl(e)}}const u=(t,e=document)=>e.querySelector(t),p=(t,e=document)=>Array.from(e.querySelectorAll(t)),d=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function m(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function g(t,e=[]){return new Promise((i,s)=>{const n=t(...e);m(n)?n.then(i,s):i(n)})}function f(t){var e;return null==(e=t=t||document.body)?void 0:e.offsetHeight}const w=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,v=t=>1e3*Number(t.slice(0,-1).replace(",","."));class y{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?p(this.selector):[]}add(...t){this.targets.forEach(e=>e.classList.add(...t))}remove(...t){this.targets.forEach(e=>e.classList.remove(...t))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}function k({to:t,from:e=this.currentPageUrl,hash:i,animate:s=!0,animation:n,el:o,event:r,action:a="push",resetScroll:l=!0}){return{from:{url:e},to:{url:t},containers:this.options.containers,animation:{animate:s,wait:!1,name:n,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:o,event:r},history:{action:a,popstate:!1,direction:void 0},scroll:{reset:l,target:i}}}class S{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:end"],this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,s={}){const n=this.get(t);if(!n)return console.warn(`Hook '${t}' not found.`),()=>{};const o=i({},s,{id:n.size+1,hook:t,handler:e});return n.set(e,o),()=>this.off(t,e)}before(t,e,s={}){return this.on(t,e,i({},s,{before:!0}))}replace(t,e,s={}){return this.on(t,e,i({},s,{replace:!0}))}once(t,e,s={}){return this.on(t,e,i({},s,{once:!0}))}off(t,e){const i=this.get(t);i&&e?i.delete(e)||console.warn(`Handler for hook '${t}' not found.`):i&&i.clear()}async call(t,e,i){const{before:s,handler:n,after:o}=this.getHandlers(t,i);await this.run(s,e);const[r]=await this.run(n,e);return await this.run(o,e),this.dispatchDomEvent(t,e),r}callSync(t,e,i){const{before:s,handler:n,after:o}=this.getHandlers(t,i);this.runSync(s,e);const[r]=this.runSync(n,e);return this.runSync(o,e),this.dispatchDomEvent(t,e),r}async run(t,e){const i=[];for(const{hook:s,handler:n,defaultHandler:o,once:r}of t){const t=await g(n,[this.swup.visit,e,o]);i.push(t),r&&this.off(s,n)}return i}runSync(t,e){const i=[];for(const{hook:s,handler:n,defaultHandler:o,once:r}of t){const t=n(this.swup.visit,e,o);i.push(t),m(t)&&console.warn(`Promise returned from handler for synchronous hook '${s}'.Swup will not wait for it to resolve.`),r&&this.off(s,n)}return i}getHandlers(t,e){const i=this.get(t);if(!i)return{found:!1,before:[],handler:[],after:[],replaced:!1};const s=this.sortRegistrations,n=Array.from(i.values()),o=n.filter(({before:t,replace:e})=>t&&!e).sort(s),r=n.filter(({replace:t})=>t).sort(s),a=n.filter(({before:t,replace:e})=>!t&&!e).sort(s),l=r.length>0;let h=[];if(e&&(h=[{id:0,hook:t,handler:e}],l)){const i=r.length-1,s=t=>{const i=r[t-1];return i?(e,n)=>i.handler(e,n,s(t-1)):e};h=[{id:0,hook:t,handler:r[i].handler,defaultHandler:s(i)}]}return{found:!0,before:o,handler:h,after:a,replaced:l}}sortRegistrations(t,e){var i,s;return(null!=(i=t.priority)?i:0)-(null!=(s=e.priority)?s:0)||t.id-e.id||0}dispatchDomEvent(t,e){document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:{hook:t,args:e,visit:this.swup.visit}}))}}const b=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let i=document.getElementById(t)||document.getElementById(e)||u(`a[name='${w(t)}']`)||u(`a[name='${w(e)}']`);return i||"top"!==t||(i=document.body),i},U="transition",P="animation";async function E({elements:t,selector:e}){if(!1===e&&!t)return;let i=[];if(t)i=Array.from(t);else if(e&&(i=p(e,document.body),!i.length))return void console.warn(`[swup] No elements found matching animationSelector \`${e}\``);const s=i.map(t=>function(t){const{type:e,timeout:i,propCount:s}=function(t,e){const i=window.getComputedStyle(t),s=C(i,`${U}Delay`),n=C(i,`${U}Duration`),o=$(s,n),r=C(i,`${P}Delay`),a=C(i,`${P}Duration`),l=$(r,a);let h=null,c=0,u=0;return c=Math.max(o,l),h=c>0?o>l?U:P:null,u=h?h===U?n.length:a.length:0,{type:h,timeout:c,propCount:u}}(t);return!(!e||!i)&&new Promise(n=>{const o=`${e}end`,r=performance.now();let a=0;const l=()=>{t.removeEventListener(o,h),n()},h=e=>{if(e.target===t){if(!function(t){return[`${U}end`,`${P}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-r)/1e3<e.elapsedTime||++a>=s&&l()}};setTimeout(()=>{a<s&&l()},i+1),t.addEventListener(o,h)})}(t));s.filter(Boolean).length>0?await Promise.all(s):e&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${e}\``)}function C(t,e){return(t[e]||"").split(", ")}function $(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,i)=>v(e)+v(t[i])))}function x(t,e={},s={}){if(this.shouldIgnoreVisit(t,{el:s.el,event:s.event}))return void(window.location.href=t);const{url:n,hash:o}=l.fromUrl(t);this.visit=this.createVisit(i({},s,{to:n,hash:o})),this.performNavigation(n,e)}async function A(t,e={}){if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");const{el:i}=this.visit.trigger;this.visit.to.url=l.fromUrl(t).url,e.referrer=e.referrer||this.currentPageUrl,!1===e.animate&&(this.visit.animation.animate=!1),this.visit.animation.animate||this.classes.clear();const s=e.history||(null==i?void 0:i.getAttribute("data-swup-history"))||void 0;s&&["push","replace"].includes(s)&&(this.visit.history.action=s);const a=e.animation||(null==i?void 0:i.getAttribute("data-swup-animation"))||void 0;a&&(this.visit.animation.name=a);try{await this.hooks.call("visit:start");const i=this.hooks.call("page:load",{options:e},async(t,e)=>{const i=this.cache.get(t.to.url);return e.page=i||await this.fetchPage(t.to.url,e.options),e.cache=!!i,e.page});if(!this.visit.history.popstate){const e=t+(this.visit.scroll.target||"");"replace"===this.visit.history.action?r(e):o(e,{index:this.currentHistoryIndex+1})}if(this.currentPageUrl=n(),this.visit.animation.wait){const{html:t}=await i;this.visit.to.html=t}const s=this.animatePageOut(),[a]=await Promise.all([i,s]);await this.renderPage(this.visit.to.url,a),await this.animatePageIn(),await this.hooks.call("visit:end",void 0,()=>this.classes.clear())}catch(t){if(!t)return;console.error(t),this.options.skipPopStateHandling=()=>(window.location.href=this.visit.to.url,!0),window.history.go(-1)}}class H extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.name="FetchError",this.url=e.url,this.status=e.status}}async function q(t,e={}){t=l.fromUrl(t).url;const s=i({},this.options.requestHeaders,e.headers);e=i({},e,{headers:s});const n=await this.hooks.call("fetch:request",{url:t,options:e},(t,{url:e,options:i})=>fetch(e,i)),{status:o,url:r}=n,a=await n.text();if(500===o)throw this.hooks.call("fetch:error",{status:o,response:n,url:r}),new H(`Server error: ${r}`,{status:o,url:r});if(!a)throw new H(`Empty response: ${r}`,{status:o,url:r});const{url:h}=l.fromUrl(r),c={url:h,html:a};return t===h&&this.cache.set(c.url,c),c}const L=async function(){this.visit.animation.animate?(await this.hooks.call("animation:out:start",void 0,t=>{this.classes.add("is-changing","is-leaving","is-animating"),t.history.popstate&&this.classes.add("is-popstate"),t.animation.name&&this.classes.add(`to-${s(t.animation.name)}`)}),await this.hooks.call("animation:out:await",{skip:!1},async(t,{skip:e})=>{e||await this.awaitAnimations({selector:t.animation.selector})}),await this.hooks.call("animation:out:end")):await this.hooks.call("animation:skip")},R=function({html:t},{containers:e}=this.options){var i;const s=(new DOMParser).parseFromString(t,"text/html"),n=(null==(i=s.querySelector("title"))?void 0:i.innerText)||"";return document.title=n,e.map(t=>{const e=document.querySelector(t),i=s.querySelector(t);return e&&i?(e.replaceWith(i),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),i||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean).length===e.length},I=function(){const t={behavior:"auto"},{target:e,reset:s}=this.visit.scroll;let n=!1;return e&&(n=this.hooks.callSync("scroll:anchor",{hash:e,options:t},(t,{hash:e,options:i})=>{const s=this.getAnchorElement(e||"");return s&&s.scrollIntoView(i),!!s})),s&&!n&&(n=this.hooks.callSync("scroll:top",{options:t},(t,{options:e})=>(window.scrollTo(i({top:0,left:0},e)),!0))),n},N=async function(){if(!this.visit.animation.animate)return;const t=this.hooks.call("animation:in:await",{skip:!1},async(t,{skip:e})=>{e||await this.awaitAnimations({selector:t.animation.selector})});await d(),await this.hooks.call("animation:in:start",void 0,()=>{this.classes.remove("is-animating")}),await t,await this.hooks.call("animation:in:end")},D=async function(t,e){const{url:i,html:o}=e;this.classes.remove("is-leaving"),this.isSameResolvedUrl(n(),t)&&(this.isSameResolvedUrl(n(),i)||(r(i),this.currentPageUrl=n(),this.visit.to.url=this.currentPageUrl),this.visit.animation.animate&&this.classes.add("is-rendering"),this.visit.to.html=o,await this.hooks.call("content:replace",{page:e},(t,{page:e})=>{if(!this.replaceContent(e,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(this.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&this.classes.add(`to-${s(t.animation.name)}`))}),await this.hooks.call("content:scroll",void 0,()=>this.scrollToContent()),await this.hooks.call("page:view",{url:this.currentPageUrl,title:document.title}),this.options.cache||this.cache.clear())},V=function(t){var e;if(null==(e=t)?void 0:e.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function M(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function O(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${t}`)}function T(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function W(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}class _{constructor(t={}){this.version="4.0.0-rc.28",this.options=void 0,this.plugins=[],this.cache=void 0,this.hooks=void 0,this.visit=void 0,this.classes=void 0,this.currentPageUrl=n(),this.getCurrentUrl=n,this.use=V,this.unuse=M,this.findPlugin=O,this.log=()=>{},this.getAnchorElement=b,this.navigate=x,this.performNavigation=A,this.delegateEvent=a,this.fetchPage=q,this.awaitAnimations=E,this.renderPage=D,this.replaceContent=R,this.animatePageIn=N,this.animatePageOut=L,this.scrollToContent=I,this.createVisit=k,this.resolveUrl=T,this.isSameResolvedUrl=W,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],ignoreVisit:(t,{el:e}={})=>!(null==e||!e.closest("[data-no-swup]")),linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>{var e;return"swup"!==(null==(e=t.state)?void 0:e.source)}},this.currentHistoryIndex=1,this.clickDelegate=void 0,this.options=i({},this.defaults,t),this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new c(this),this.classes=new y(this),this.hooks=new S(this),this.visit=this.createVisit({to:void 0}),this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}async enable(){const{linkSelector:t}=this.options;this.clickDelegate=this.delegateEvent(t,"click",this.handleLinkClick),window.addEventListener("popstate",this.handlePopState),this.options.plugins.forEach(t=>this.use(t)),r(null,{index:1}),await d(),await this.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})}async destroy(){this.clickDelegate.destroy(),window.removeEventListener("popstate",this.handlePopState),this.cache.clear(),this.options.plugins.forEach(t=>this.unuse(t)),await this.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")}),this.hooks.clear()}shouldIgnoreVisit(t,{el:e,event:i}={}){const{origin:s,url:n,hash:o}=l.fromUrl(t);return s!==window.location.origin||!(!e||!this.triggerWillOpenNewWindow(e))||!!this.options.ignoreVisit(n+o,{el:e,event:i})}handleLinkClick(t){const e=t.delegateTarget,{href:i,url:s,hash:n}=l.fromElement(e);this.shouldIgnoreVisit(i,{el:e,event:t})||(this.visit=this.createVisit({to:s,hash:n,el:e,event:t}),t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.call("link:newtab",{href:i}):0===t.button&&this.hooks.callSync("link:click",{el:e,event:t},()=>{var e;const i=null!=(e=this.visit.from.url)?e:"";t.preventDefault(),s&&s!==i?this.isSameResolvedUrl(s,i)||this.performNavigation(s):n?this.hooks.callSync("link:anchor",{hash:n},()=>{r(s+n),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>{this.scrollToContent()})}))}handlePopState(t){var e,i,s;const o=null!=(e=null==(i=t.state)?void 0:i.url)?e:location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(n(),this.currentPageUrl))return;if(this.shouldIgnoreVisit(o,{event:t}))return;const{url:r,hash:a}=l.fromUrl(o);this.visit=this.createVisit({to:r,hash:a,event:t,animate:this.options.animateHistoryBrowsing,resetScroll:this.options.animateHistoryBrowsing}),this.visit.history.popstate=!0;const h=Number(null==(s=t.state)?void 0:s.index);h&&(this.visit.history.direction=h-this.currentHistoryIndex>0?"forwards":"backwards"),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation(r)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}export{l as Location,s as classify,o as createHistoryRecord,_ as default,a as delegateEvent,w as escapeCssIdentifier,f as forceReflow,n as getCurrentUrl,m as isPromise,h as matchPath,d as nextTick,u as query,p as queryAll,g as runAsPromise,v as toMs,r as updateHistoryRecord};
//# sourceMappingURL=Swup.modern.js.map

@@ -1,2 +0,2 @@

import t from"delegate-it";import{match as e}from"path-to-regexp";const n=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",r=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},o=function(t,e){void 0===e&&(e={});const n={url:t=t||r({hash:!0}),random:Math.random(),source:"swup",...e};history.pushState(n,"",t)},i=function(t,e){void 0===t&&(t=null),void 0===e&&(e={}),t=t||r({hash:!0});const n={...history.state,url:t,random:Math.random(),source:"swup",...e};history.replaceState(n,"",t)},s=(e,n,r,o)=>{const i=new AbortController;return o={...o,signal:i.signal},t(e,n,r,o),{destroy:()=>i.abort()}};class a extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new a(e)}static fromUrl(t){return new a(t)}}const l=(t,n)=>{try{return e(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${t}":\n${e}`)}};class c{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){return this.pages}has(t){return this.pages.has(this.resolve(t))}get(t){return this.pages.get(this.resolve(t))}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",{page:e})}update(t,e){t=this.resolve(t),e={...this.get(t),...e,url:t},this.pages.set(t,e)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear")}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=a.fromUrl(t);return this.swup.resolveUrl(e)}}const u=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},h=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},m=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function d(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function f(t,e){return void 0===e&&(e=[]),new Promise((n,r)=>{const o=t(...e);d(o)?o.then(n,r):n(o)})}function p(t){var e;return null==(e=t=t||document.body)?void 0:e.offsetHeight}const v=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,g=t=>1e3*Number(t.slice(0,-1).replace(",","."));class w{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?h(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}function y(t){let{to:e,from:n=this.currentPageUrl,hash:r,animate:o=!0,animation:i,el:s,event:a,action:l="push",resetScroll:c=!0}=t;return{from:{url:n},to:{url:e},containers:this.options.containers,animation:{animate:o,wait:!1,name:i,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:s,event:a},history:{action:l,popstate:!1,direction:void 0},scroll:{reset:c,target:r}}}const k="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function P(t,e,n){if(!t.s){if(n instanceof S){if(!n.s)return void(n.o=P.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(P.bind(null,t,e),P.bind(null,t,2));t.s=e,t.v=n;const r=t.o;r&&r(t)}}const 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{P(r,1,t(this.v))}catch(t){P(r,2,t)}return r}return this}return this.o=function(t){try{const o=t.v;1&t.s?P(r,1,e?e(o):o):n?P(r,1,n(o)):P(r,2,o)}catch(t){P(r,2,t)}},r},t}();function b(t){return t instanceof 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:request","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[k]){var r,o,i,s=t[k]();if(function t(n){try{for(;!(r=s.next()).done;)if((n=e(r.value))&&n.then){if(!b(n))return void n.then(t,i||(i=P.bind(null,o=new S,2)));n=n.v}o?P(o,1,n):o=n}catch(t){P(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=P.bind(null,r=new S,2)));s=s.v}r?P(r,1,s):r=s}catch(t){P(r||(r=new S),2,t)}}(),r}(l,function(t){return e(l[t])})}(t,function(t){let{hook:o,handler:i,defaultHandler:s,once:a}=t;return Promise.resolve(f(i,[n.swup.visit,e,s])).then(function(t){r.push(t),a&&n.off(o,i)})});return Promise.resolve(o&&o.then?o.then(function(){return r}):r)}catch(t){return Promise.reject(t)}}runSync(t,e){const n=[];for(const{hook:r,handler:o,defaultHandler:i,once:s}of t){const t=o(this.swup.visit,e,i);n.push(t),d(t)&&console.warn(`Promise returned from handler for synchronous hook '${r}'.Swup will not wait for it to resolve.`),s&&this.off(r,o)}return n}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const r=this.sortRegistrations,o=Array.from(n.values()),i=o.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(r),s=o.filter(t=>{let{replace:e}=t;return e}).sort(r),a=o.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(r),l=s.length>0;let c=[];if(e&&(c=[{id:0,hook:t,handler:e}],l)){const n=s.length-1,r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};c=[{id:0,hook:t,handler:s[n].handler,defaultHandler:r(n)}]}return{found:!0,before:i,handler:c,after:a,replaced:l}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e){document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:{hook:t,args:e,visit:this.swup.visit}}))}}const E=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||u(`a[name='${v(t)}']`)||u(`a[name='${v(e)}']`);return n||"top"!==t||(n=document.body),n},H=function(t){let{elements:e,selector:n}=t;try{if(!1===n&&!e)return Promise.resolve();let t=[];if(e)t=Array.from(e);else if(n&&(t=h(n,document.body),!t.length))return console.warn(`[swup] No elements found matching animationSelector \`${n}\``),Promise.resolve();const r=t.map(t=>function(t){const{type:e,timeout:n,propCount:r}=function(t,e){const n=window.getComputedStyle(t),r=x(n,`${C}Delay`),o=x(n,`${C}Duration`),i=A(r,o),s=x(n,`${$}Delay`),a=x(n,`${$}Duration`),l=A(s,a);let c=null,u=0,h=0;return e===C?i>0&&(c=C,u=i,h=o.length):e===$?l>0&&(c=$,u=l,h=a.length):(u=Math.max(i,l),c=u>0?i>l?C:$:null,h=c?c===C?o.length:a.length:0),{type:c,timeout:u,propCount:h}}(t);return!(!e||!n)&&new Promise(o=>{const i=`${e}end`,s=performance.now();let a=0;const l=()=>{t.removeEventListener(i,c),o()},c=e=>{if(e.target===t){if(!function(t){return[`${C}end`,`${$}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-s)/1e3<e.elapsedTime||++a>=r&&l()}};setTimeout(()=>{a<r&&l()},n+1),t.addEventListener(i,c)})}(t));return r.filter(Boolean).length>0?Promise.resolve(Promise.all(r)).then(function(){}):(n&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${n}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},C="transition",$="animation";function x(t,e){return(t[e]||"").split(", ")}function A(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>g(e)+g(t[n])))}const q=function(t,e){void 0===e&&(e={});try{const n=this;if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");const{el:s}=n.visit.trigger;n.visit.to.url=a.fromUrl(t).url,e.referrer=e.referrer||n.currentPageUrl,!1===e.animate&&(n.visit.animation.animate=!1),n.visit.animation.animate||n.classes.clear();const l=e.history||(null==s?void 0:s.getAttribute("data-swup-history"))||void 0;l&&["push","replace"].includes(l)&&(n.visit.history.action=l);const c=e.animation||(null==s?void 0:s.getAttribute("data-swup-animation"))||void 0;return c&&(n.visit.animation.name=c),Promise.resolve(function(s,a){try{var l=Promise.resolve(n.hooks.call("visit:start")).then(function(){function s(){const t=n.animatePageOut();return Promise.resolve(Promise.all([a,t])).then(function(t){let[e]=t;return Promise.resolve(n.renderPage(n.visit.to.url,e)).then(function(){return Promise.resolve(n.animatePageIn()).then(function(){return Promise.resolve(n.hooks.call("visit:end",void 0,()=>n.classes.clear())).then(function(){})})})})}const a=n.hooks.call("page:request",{url:n.visit.to.url,options:e},function(t,e){let{options:r}=e;try{return Promise.resolve(n.fetchPage(t.to.url,r))}catch(t){return Promise.reject(t)}});if(!n.visit.history.popstate){const e=t+(n.visit.scroll.target||"");"replace"===n.visit.history.action?i(e):o(e,{index:n.currentHistoryIndex+1})}n.currentPageUrl=r();const l=function(){if(n.visit.animation.wait)return Promise.resolve(a).then(function(t){let{html:e}=t;n.visit.to.html=e})}();return l&&l.then?l.then(s):s()})}catch(t){return a(t)}return l&&l.then?l.then(void 0,a):l}(0,function(t){t&&(console.error(t),n.options.skipPopStateHandling=()=>(window.location.href=n.visit.to.url,!0),window.history.go(-1))}))}catch(t){return Promise.reject(t)}};function j(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),this.shouldIgnoreVisit(t))return void(window.location.href=t);const{url:r,hash:o}=a.fromUrl(t);this.visit=this.createVisit({...n,to:r,hash:o}),this.performNavigation(r,e)}const R=function(t,e){void 0===e&&(e={});try{let r;const o=this;function n(n){if(r)return n;const i={...o.options.requestHeaders,...e.headers};return e={...e,headers:i},Promise.resolve(o.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(n){const{status:r,url:i}=n;return Promise.resolve(n.text()).then(function(s){if(500===r)throw o.hooks.call("fetch:error",{status:r,response:n,url:i}),new I(`Server error: ${i}`,{status:r,url:i});if(!s)throw new I(`Empty response: ${i}`,{status:r,url:i});const{url:l}=a.fromUrl(i),c={url:l,html:s};t===l&&o.cache.set(c.url,c);const u=function(){if(!1!==e.triggerHooks)return Promise.resolve(o.hooks.call("page:load",{page:c,cache:!1})).then(function(){})}();return u&&u.then?u.then(function(){return c}):c})})}t=a.fromUrl(t).url;const i=function(){if(o.cache.has(t)){function n(){return r=1,i}const i=o.cache.get(t),s=function(){if(!1!==e.triggerHooks)return Promise.resolve(o.hooks.call("page:load",{page:i,cache:!0})).then(function(){})}();return s&&s.then?s.then(n):n()}}();return Promise.resolve(i&&i.then?i.then(n):n(i))}catch(s){return Promise.reject(s)}};class I 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 r=this;function t(t){return e?t:Promise.resolve(r.hooks.call("animation:out:start",void 0,t=>{r.classes.add("is-changing","is-leaving","is-animating"),t.history.popstate&&r.classes.add("is-popstate"),t.animation.name&&r.classes.add(`to-${n(t.animation.name)}`)})).then(function(){return Promise.resolve(r.hooks.call("animation:out:await",{skip:!1},function(t,e){let{skip:n}=e;try{return n?Promise.resolve():Promise.resolve(r.awaitAnimations({selector:t.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(r.hooks.call("animation:out:end")).then(function(){})})})}const o=function(){if(!r.visit.animation.animate)return Promise.resolve(r.hooks.call("animation:skip")).then(function(){e=1})}();return Promise.resolve(o&&o.then?o.then(t):t(o))}catch(i){return Promise.reject(i)}},D=function(t,e){var n;let{html:r}=t,{containers:o}=void 0===e?this.options:e;const i=(new DOMParser).parseFromString(r,"text/html"),s=(null==(n=i.querySelector("title"))?void 0:n.innerText)||"";return document.title=s,o.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).length===o.length},L=function(){const t={behavior:"auto"},{target:e,reset:n}=this.visit.scroll;let r=!1;return e&&(r=this.hooks.callSync("scroll:anchor",{hash:e,options:t},(t,e)=>{let{hash:n,options:r}=e;const o=this.getAnchorElement(n||"");return o&&o.scrollIntoView(r),!!o})),n&&!r&&(r=this.hooks.callSync("scroll:top",{options:t},(t,e)=>{let{options:n}=e;return window.scrollTo({top:0,left:0,...n}),!0})),r},V=function(){try{const t=this;if(!t.visit.animation.animate)return Promise.resolve();const e=t.hooks.call("animation:in:await",{skip:!1},function(e,n){let{skip:r}=n;try{return r?Promise.resolve():Promise.resolve(t.awaitAnimations({selector:e.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}});return Promise.resolve(m()).then(function(){return Promise.resolve(t.hooks.call("animation:in:start",void 0,()=>{t.classes.remove("is-animating")})).then(function(){return Promise.resolve(e).then(function(){return Promise.resolve(t.hooks.call("animation:in:end")).then(function(){})})})})}catch(t){return Promise.reject(t)}},M=function(t,e){try{const o=this,{url:s,html:a}=e;return o.classes.remove("is-leaving"),o.isSameResolvedUrl(r(),t)?(o.isSameResolvedUrl(r(),s)||(i(s),o.currentPageUrl=r(),o.visit.to.url=o.currentPageUrl),o.visit.animation.animate&&o.classes.add("is-rendering"),o.visit.to.html=a,Promise.resolve(o.hooks.call("content:replace",{page:e},(t,e)=>{let{page:r}=e;if(!o.replaceContent(r,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(o.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&o.classes.add(`to-${n(t.animation.name)}`))})).then(function(){return Promise.resolve(o.hooks.call("content:scroll",void 0,()=>o.scrollToContent())).then(function(){return Promise.resolve(o.hooks.call("page:view",{url:o.currentPageUrl,title:document.title})).then(function(){o.options.cache||o.cache.clear()})})})):Promise.resolve()}catch(t){return Promise.reject(t)}},T=function(t){var e;if(null==(e=t)?void 0:e.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function 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}`)}class B{constructor(t){void 0===t&&(t={}),this.version="4.0.0-rc.27",this.options=void 0,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.currentPageUrl=r(),this.currentHistoryIndex=1,this.clickDelegate=void 0,this.navigate=j,this.performNavigation=q,this.animatePageOut=N,this.renderPage=M,this.replaceContent=D,this.scrollToContent=L,this.animatePageIn=V,this.delegateEvent=s,this.fetchPage=R,this.awaitAnimations=H,this.getAnchorElement=E,this.use=T,this.unuse=W,this.findPlugin=_,this.getCurrentUrl=r,this.createVisit=y,this.log=()=>{},this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],ignoreVisit:function(t,e){let{el:n}=void 0===e?{}:e;return!(null==n||!n.closest("[data-no-swup]"))},linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>{var e;return"swup"!==(null==(e=t.state)?void 0:e.source)}},this.options={...this.defaults,...t},this.linkClickHandler=this.linkClickHandler.bind(this),this.popStateHandler=this.popStateHandler.bind(this),this.cache=new c(this),this.classes=new w(this),this.hooks=new U(this),this.visit=this.createVisit({to:void 0}),this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}enable(){try{const t=this,{linkSelector:e}=t.options;return t.clickDelegate=t.delegateEvent(e,"click",t.linkClickHandler),window.addEventListener("popstate",t.popStateHandler),t.options.plugins.forEach(e=>t.use(e)),i(null,{index:1}),Promise.resolve(m()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.popStateHandler),t.cache.clear(),t.options.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,e){let{el:n,event:r}=void 0===e?{}:e;const{origin:o,url:i,hash:s}=a.fromUrl(t);return o!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(i+s,{el:n,event:r})}linkClickHandler(t){const e=t.delegateTarget,{href:n,url:r,hash:o}=a.fromElement(e);this.shouldIgnoreVisit(n,{el:e,event:t})||(this.visit=this.createVisit({to:r,hash:o,el:e,event:t}),t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.call("link:newtab",{href:n}):0===t.button&&this.hooks.callSync("link:click",{el:e,event:t},()=>{const e=this.visit.from.url??"";t.preventDefault(),r&&r!==e?this.isSameResolvedUrl(r,e)||this.performNavigation(r):o?this.hooks.callSync("link:anchor",{hash:o},()=>{i(r+o),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>{this.scrollToContent()})}))}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}popStateHandler(t){var e,n;const o=(null==(e=t.state)?void 0:e.url)??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(r(),this.currentPageUrl))return;if(this.shouldIgnoreVisit(o,{event:t}))return;const{url:i,hash:s}=a.fromUrl(o);this.visit=this.createVisit({to:i,hash:s,event:t,animate:this.options.animateHistoryBrowsing,resetScroll:this.options.animateHistoryBrowsing}),this.visit.history.popstate=!0;const l=Number(null==(n=t.state)?void 0:n.index);l&&(this.visit.history.direction=l-this.currentHistoryIndex>0?"forwards":"backwards"),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation(i)})}resolveUrl(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)}isSameResolvedUrl(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}}export{a as Location,n as classify,o as createHistoryRecord,B as default,s as delegateEvent,v as escapeCssIdentifier,p as forceReflow,r as getCurrentUrl,d as isPromise,l as matchPath,m as nextTick,u as query,h as queryAll,f as runAsPromise,g as toMs,i as updateHistoryRecord};
import t from"delegate-it";import{match as e}from"path-to-regexp";const n=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",r=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},o=function(t,e){void 0===e&&(e={});const n={url:t=t||r({hash:!0}),random:Math.random(),source:"swup",...e};history.pushState(n,"",t)},i=function(t,e){void 0===t&&(t=null),void 0===e&&(e={}),t=t||r({hash:!0});const n={...history.state,url:t,random:Math.random(),source:"swup",...e};history.replaceState(n,"",t)},s=(e,n,r,o)=>{const i=new AbortController;return o={...o,signal:i.signal},t(e,n,r,o),{destroy:()=>i.abort()}};class a extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new a(e)}static fromUrl(t){return new a(t)}}const l=(t,n)=>{try{return e(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${t}":\n${e}`)}};class c{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){return this.pages}has(t){return this.pages.has(this.resolve(t))}get(t){return this.pages.get(this.resolve(t))}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",{page:e})}update(t,e){t=this.resolve(t),e={...this.get(t),...e,url:t},this.pages.set(t,e)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear")}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=a.fromUrl(t);return this.swup.resolveUrl(e)}}const h=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},u=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},m=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function d(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function f(t,e){return void 0===e&&(e=[]),new Promise((n,r)=>{const o=t(...e);d(o)?o.then(n,r):n(o)})}function p(t){return t=t||document.body,t?.offsetHeight}const v=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,g=t=>1e3*Number(t.slice(0,-1).replace(",","."));class w{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?u(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}function y(t){let{to:e,from:n=this.currentPageUrl,hash:r,animate:o=!0,animation:i,el:s,event:a,action:l="push",resetScroll:c=!0}=t;return{from:{url:n},to:{url:e},containers:this.options.containers,animation:{animate:o,wait:!1,name:i,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:s,event:a},history:{action:l,popstate:!1,direction:void 0},scroll:{reset:c,target:r}}}const P="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function k(t,e,n){if(!t.s){if(n instanceof S){if(!n.s)return void(n.o=k.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(k.bind(null,t,e),k.bind(null,t,2));t.s=e,t.v=n;const r=t.o;r&&r(t)}}const S=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const r=new t,o=this.s;if(o){const t=1&o?e:n;if(t){try{k(r,1,t(this.v))}catch(t){k(r,2,t)}return r}return this}return this.o=function(t){try{const o=t.v;1&t.s?k(r,1,e?e(o):o):n?k(r,1,n(o)):k(r,2,o)}catch(t){k(r,2,t)}},r},t}();function b(t){return t instanceof S&&1&t.s}class U{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:end"],this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n){void 0===n&&(n={});const r=this.get(t);if(!r)return console.warn(`Hook '${t}' not found.`),()=>{};const o=r.size+1,i={...n,id:o,hook:t,handler:e};return r.set(e,i),()=>this.off(t,e)}before(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,before:!0})}replace(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,replace:!0})}once(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n){try{const r=this,{before:o,handler:i,after:s}=r.getHandlers(t,n);return Promise.resolve(r.run(o,e)).then(function(){return Promise.resolve(r.run(i,e)).then(function(n){let[o]=n;return Promise.resolve(r.run(s,e)).then(function(){return r.dispatchDomEvent(t,e),o})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n){const{before:r,handler:o,after:i}=this.getHandlers(t,n);this.runSync(r,e);const[s]=this.runSync(o,e);return this.runSync(i,e),this.dispatchDomEvent(t,e),s}run(t,e){try{const n=this,r=[],o=function(t,e,n){if("function"==typeof t[P]){var r,o,i,s=t[P]();if(function t(n){try{for(;!(r=s.next()).done;)if((n=e(r.value))&&n.then){if(!b(n))return void n.then(t,i||(i=k.bind(null,o=new S,2)));n=n.v}o?k(o,1,n):o=n}catch(t){k(o||(o=new S),2,t)}}(),s.return){var a=function(t){try{r.done||s.return()}catch(t){}return t};if(o&&o.then)return o.then(a,function(t){throw a(t)});a()}return o}if(!("length"in t))throw new TypeError("Object is not iterable");for(var l=[],c=0;c<t.length;c++)l.push(t[c]);return function(t,e,n){var r,o,i=-1;return function n(s){try{for(;++i<t.length;)if((s=e(i))&&s.then){if(!b(s))return void s.then(n,o||(o=k.bind(null,r=new S,2)));s=s.v}r?k(r,1,s):r=s}catch(t){k(r||(r=new S),2,t)}}(),r}(l,function(t){return e(l[t])})}(t,function(t){let{hook:o,handler:i,defaultHandler:s,once:a}=t;return Promise.resolve(f(i,[n.swup.visit,e,s])).then(function(t){r.push(t),a&&n.off(o,i)})});return Promise.resolve(o&&o.then?o.then(function(){return r}):r)}catch(t){return Promise.reject(t)}}runSync(t,e){const n=[];for(const{hook:r,handler:o,defaultHandler:i,once:s}of t){const t=o(this.swup.visit,e,i);n.push(t),d(t)&&console.warn(`Promise returned from handler for synchronous hook '${r}'.Swup will not wait for it to resolve.`),s&&this.off(r,o)}return n}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const r=this.sortRegistrations,o=Array.from(n.values()),i=o.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(r),s=o.filter(t=>{let{replace:e}=t;return e}).sort(r),a=o.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(r),l=s.length>0;let c=[];if(e&&(c=[{id:0,hook:t,handler:e}],l)){const n=s.length-1,r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};c=[{id:0,hook:t,handler:s[n].handler,defaultHandler:r(n)}]}return{found:!0,before:i,handler:c,after:a,replaced:l}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e){document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:{hook:t,args:e,visit:this.swup.visit}}))}}const E=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||h(`a[name='${v(t)}']`)||h(`a[name='${v(e)}']`);return n||"top"!==t||(n=document.body),n},C=function(t){let{elements:e,selector:n}=t;try{if(!1===n&&!e)return Promise.resolve();let t=[];if(e)t=Array.from(e);else if(n&&(t=u(n,document.body),!t.length))return console.warn(`[swup] No elements found matching animationSelector \`${n}\``),Promise.resolve();const r=t.map(t=>function(t){const{type:e,timeout:n,propCount:r}=function(t,e){const n=window.getComputedStyle(t),r=A(n,`${$}Delay`),o=A(n,`${$}Duration`),i=H(r,o),s=A(n,`${x}Delay`),a=A(n,`${x}Duration`),l=H(s,a);let c=null,h=0,u=0;return e===$?i>0&&(c=$,h=i,u=o.length):e===x?l>0&&(c=x,h=l,u=a.length):(h=Math.max(i,l),c=h>0?i>l?$:x:null,u=c?c===$?o.length:a.length:0),{type:c,timeout:h,propCount:u}}(t);return!(!e||!n)&&new Promise(o=>{const i=`${e}end`,s=performance.now();let a=0;const l=()=>{t.removeEventListener(i,c),o()},c=e=>{if(e.target===t){if(!function(t){return[`${$}end`,`${x}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-s)/1e3<e.elapsedTime||++a>=r&&l()}};setTimeout(()=>{a<r&&l()},n+1),t.addEventListener(i,c)})}(t));return r.filter(Boolean).length>0?Promise.resolve(Promise.all(r)).then(function(){}):(n&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${n}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},$="transition",x="animation";function A(t,e){return(t[e]||"").split(", ")}function H(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>g(e)+g(t[n])))}const q=function(t,e){void 0===e&&(e={});try{const n=this;if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");const{el:s}=n.visit.trigger;n.visit.to.url=a.fromUrl(t).url,e.referrer=e.referrer||n.currentPageUrl,!1===e.animate&&(n.visit.animation.animate=!1),n.visit.animation.animate||n.classes.clear();const l=e.history||s?.getAttribute("data-swup-history")||void 0;l&&["push","replace"].includes(l)&&(n.visit.history.action=l);const c=e.animation||s?.getAttribute("data-swup-animation")||void 0;return c&&(n.visit.animation.name=c),Promise.resolve(function(s,a){try{var l=Promise.resolve(n.hooks.call("visit:start")).then(function(){function s(){const t=n.animatePageOut();return Promise.resolve(Promise.all([a,t])).then(function(t){let[e]=t;return Promise.resolve(n.renderPage(n.visit.to.url,e)).then(function(){return Promise.resolve(n.animatePageIn()).then(function(){return Promise.resolve(n.hooks.call("visit:end",void 0,()=>n.classes.clear())).then(function(){})})})})}const a=n.hooks.call("page:load",{options:e},function(t,e){try{function r(t){return e.page=t,e.cache=!!o,e.page}const o=n.cache.get(t.to.url);return Promise.resolve(o?r(o):Promise.resolve(n.fetchPage(t.to.url,e.options)).then(r))}catch(i){return Promise.reject(i)}});if(!n.visit.history.popstate){const e=t+(n.visit.scroll.target||"");"replace"===n.visit.history.action?i(e):o(e,{index:n.currentHistoryIndex+1})}n.currentPageUrl=r();const l=function(){if(n.visit.animation.wait)return Promise.resolve(a).then(function(t){let{html:e}=t;n.visit.to.html=e})}();return l&&l.then?l.then(s):s()})}catch(t){return a(t)}return l&&l.then?l.then(void 0,a):l}(0,function(t){t&&(console.error(t),n.options.skipPopStateHandling=()=>(window.location.href=n.visit.to.url,!0),window.history.go(-1))}))}catch(t){return Promise.reject(t)}};function j(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void(window.location.href=t);const{url:r,hash:o}=a.fromUrl(t);this.visit=this.createVisit({...n,to:r,hash:o}),this.performNavigation(r,e)}const L=function(t,e){void 0===e&&(e={});try{const n=this;t=a.fromUrl(t).url;const r={...n.options.requestHeaders,...e.headers};return e={...e,headers:r},Promise.resolve(n.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(e){const{status:r,url:o}=e;return Promise.resolve(e.text()).then(function(i){if(500===r)throw n.hooks.call("fetch:error",{status:r,response:e,url:o}),new R(`Server error: ${o}`,{status:r,url:o});if(!i)throw new R(`Empty response: ${o}`,{status:r,url:o});const{url:s}=a.fromUrl(o),l={url:s,html:i};return t===s&&n.cache.set(l.url,l),l})})}catch(t){return Promise.reject(t)}};class R extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.name="FetchError",this.url=e.url,this.status=e.status}}const I=function(){try{let e;const r=this;function t(t){return e?t:Promise.resolve(r.hooks.call("animation:out:start",void 0,t=>{r.classes.add("is-changing","is-leaving","is-animating"),t.history.popstate&&r.classes.add("is-popstate"),t.animation.name&&r.classes.add(`to-${n(t.animation.name)}`)})).then(function(){return Promise.resolve(r.hooks.call("animation:out:await",{skip:!1},function(t,e){let{skip:n}=e;try{return n?Promise.resolve():Promise.resolve(r.awaitAnimations({selector:t.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(r.hooks.call("animation:out:end")).then(function(){})})})}const o=function(){if(!r.visit.animation.animate)return Promise.resolve(r.hooks.call("animation:skip")).then(function(){e=1})}();return Promise.resolve(o&&o.then?o.then(t):t(o))}catch(i){return Promise.reject(i)}},N=function(t,e){let{html:n}=t,{containers:r}=void 0===e?this.options:e;const o=(new DOMParser).parseFromString(n,"text/html"),i=o.querySelector("title")?.innerText||"";return document.title=i,r.map(t=>{const e=document.querySelector(t),n=o.querySelector(t);return e&&n?(e.replaceWith(n),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),n||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean).length===r.length},D=function(){const t={behavior:"auto"},{target:e,reset:n}=this.visit.scroll;let r=!1;return e&&(r=this.hooks.callSync("scroll:anchor",{hash:e,options:t},(t,e)=>{let{hash:n,options:r}=e;const o=this.getAnchorElement(n||"");return o&&o.scrollIntoView(r),!!o})),n&&!r&&(r=this.hooks.callSync("scroll:top",{options:t},(t,e)=>{let{options:n}=e;return window.scrollTo({top:0,left:0,...n}),!0})),r},V=function(){try{const t=this;if(!t.visit.animation.animate)return Promise.resolve();const e=t.hooks.call("animation:in:await",{skip:!1},function(e,n){let{skip:r}=n;try{return r?Promise.resolve():Promise.resolve(t.awaitAnimations({selector:e.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}});return Promise.resolve(m()).then(function(){return Promise.resolve(t.hooks.call("animation:in:start",void 0,()=>{t.classes.remove("is-animating")})).then(function(){return Promise.resolve(e).then(function(){return Promise.resolve(t.hooks.call("animation:in:end")).then(function(){})})})})}catch(t){return Promise.reject(t)}},M=function(t,e){try{const o=this,{url:s,html:a}=e;return o.classes.remove("is-leaving"),o.isSameResolvedUrl(r(),t)?(o.isSameResolvedUrl(r(),s)||(i(s),o.currentPageUrl=r(),o.visit.to.url=o.currentPageUrl),o.visit.animation.animate&&o.classes.add("is-rendering"),o.visit.to.html=a,Promise.resolve(o.hooks.call("content:replace",{page:e},(t,e)=>{let{page:r}=e;if(!o.replaceContent(r,{containers:t.containers}))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(o.classes.add("is-animating","is-changing","is-rendering"),t.animation.name&&o.classes.add(`to-${n(t.animation.name)}`))})).then(function(){return Promise.resolve(o.hooks.call("content:scroll",void 0,()=>o.scrollToContent())).then(function(){return Promise.resolve(o.hooks.call("page:view",{url:o.currentPageUrl,title:document.title})).then(function(){o.options.cache||o.cache.clear()})})})):Promise.resolve()}catch(t){return Promise.reject(t)}},T=function(t){var e;if(e=t,e?.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function W(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function _(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${t}`)}function B(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function O(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}class F{constructor(t){void 0===t&&(t={}),this.version="4.0.0-rc.28",this.options=void 0,this.plugins=[],this.cache=void 0,this.hooks=void 0,this.visit=void 0,this.classes=void 0,this.currentPageUrl=r(),this.getCurrentUrl=r,this.use=T,this.unuse=W,this.findPlugin=_,this.log=()=>{},this.getAnchorElement=E,this.navigate=j,this.performNavigation=q,this.delegateEvent=s,this.fetchPage=L,this.awaitAnimations=C,this.renderPage=M,this.replaceContent=N,this.animatePageIn=V,this.animatePageOut=I,this.scrollToContent=D,this.createVisit=y,this.resolveUrl=B,this.isSameResolvedUrl=O,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],ignoreVisit:function(t,e){let{el:n}=void 0===e?{}:e;return!!n?.closest("[data-no-swup]")},linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source},this.currentHistoryIndex=1,this.clickDelegate=void 0,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new c(this),this.classes=new w(this),this.hooks=new U(this),this.visit=this.createVisit({to:void 0}),this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}enable(){try{const t=this,{linkSelector:e}=t.options;return t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.plugins.forEach(e=>t.use(e)),i(null,{index:1}),Promise.resolve(m()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.options.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,e){let{el:n,event:r}=void 0===e?{}:e;const{origin:o,url:i,hash:s}=a.fromUrl(t);return o!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(i+s,{el:n,event:r})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:r,hash:o}=a.fromElement(e);this.shouldIgnoreVisit(n,{el:e,event:t})||(this.visit=this.createVisit({to:r,hash:o,el:e,event:t}),t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.call("link:newtab",{href:n}):0===t.button&&this.hooks.callSync("link:click",{el:e,event:t},()=>{const e=this.visit.from.url??"";t.preventDefault(),r&&r!==e?this.isSameResolvedUrl(r,e)||this.performNavigation(r):o?this.hooks.callSync("link:anchor",{hash:o},()=>{i(r+o),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>{this.scrollToContent()})}))}handlePopState(t){const e=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(r(),this.currentPageUrl))return;if(this.shouldIgnoreVisit(e,{event:t}))return;const{url:n,hash:o}=a.fromUrl(e);this.visit=this.createVisit({to:n,hash:o,event:t,animate:this.options.animateHistoryBrowsing,resetScroll:this.options.animateHistoryBrowsing}),this.visit.history.popstate=!0;const i=Number(t.state?.index);i&&(this.visit.history.direction=i-this.currentHistoryIndex>0?"forwards":"backwards"),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation(n)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}export{a as Location,n as classify,o as createHistoryRecord,F as default,s as delegateEvent,v as escapeCssIdentifier,p as forceReflow,r as getCurrentUrl,d as isPromise,l as matchPath,m as nextTick,h as query,u as queryAll,f as runAsPromise,g as toMs,i as updateHistoryRecord};
//# sourceMappingURL=Swup.module.js.map

@@ -1,2 +0,2 @@

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

@@ -10,2 +10,2 @@ import type { Visit, VisitFrom, VisitTo, VisitAnimation, VisitScroll, VisitHistory } from './modules/Visit.js';

export * from './utils.js';
export type { Options, Plugin, CacheData, Visit, VisitFrom, VisitTo, VisitAnimation, VisitScroll, VisitHistory, HookDefinitions, HookName, HookOptions, HookUnregister, Handler, Path };
export type { SwupCore as Swup, Options, Plugin, CacheData, Visit, VisitFrom, VisitTo, VisitAnimation, VisitScroll, VisitHistory, HookDefinitions, HookName, HookOptions, HookUnregister, Handler, Path };

@@ -29,4 +29,2 @@ import Swup from '../Swup.js';

*/
export declare function fetchPage(this: Swup, url: URL | string, options?: FetchOptions & {
triggerHooks?: boolean;
}): Promise<PageData>;
export declare function fetchPage(this: Swup, url: URL | string, options?: FetchOptions): Promise<PageData>;

@@ -50,9 +50,6 @@ import { DelegateEvent } from 'delegate-it';

};
'page:request': {
url: string;
options: FetchOptions;
};
'page:load': {
page: PageData;
page?: PageData;
cache?: boolean;
options: FetchOptions;
};

@@ -59,0 +56,0 @@ 'page:view': {

import { DelegateEvent } from 'delegate-it';
import { delegateEvent, getCurrentUrl } from './helpers.js';
import { DelegateEventUnsubscribe } from './helpers/delegateEvent.js';

@@ -7,6 +8,9 @@ import { Cache } from './modules/Cache.js';

import { Hooks } from './modules/Hooks.js';
import { getAnchorElement } from './modules/getAnchorElement.js';
import { awaitAnimations } from './modules/awaitAnimations.js';
import { navigate, performNavigation } from './modules/navigate.js';
import { fetchPage } from './modules/fetchPage.js';
import { unuse, findPlugin, Plugin } from './modules/plugins.js';
import { replaceContent } from './modules/replaceContent.js';
import { use, unuse, findPlugin, Plugin } from './modules/plugins.js';
import { isSameResolvedUrl, resolveUrl } from './modules/resolveUrl.js';
/** Options for customizing swup's behavior. */

@@ -40,49 +44,91 @@ export type Options = {

};
/** Swup page transition library. */
export default class Swup {
/** Interface for Swup page transition library. */
export interface SwupCore {
/** Library version */
version: string;
readonly version: string;
/** Options passed into the instance */
options: Options;
/** Default options before merging user options */
readonly defaults: Readonly<Options>;
/** Registered plugin instances */
plugins: Plugin[];
readonly plugins: Plugin[];
/** Data about the current visit */
visit: Visit;
readonly visit: Visit;
/** Cache instance */
cache: Cache;
readonly cache: Cache;
/** Hook registry */
hooks: Hooks;
readonly hooks: Hooks;
/** Animation class manager */
classes: Classes;
readonly classes: Classes;
/** URL of the currently visible page */
currentPageUrl: string;
/** Index of the current history entry */
currentHistoryIndex: number;
/** Delegated event subscription handle */
private clickDelegate?;
/** Enable the instance */
enable(): Promise<void>;
/** Disable the instance and clean up */
destroy(): Promise<void>;
/** Install a plugin */
use: typeof use;
/** Uninstall a plugin */
unuse: typeof unuse;
/** Find a plugin by name or instance */
findPlugin: typeof findPlugin;
/** Log a message. Has no effect unless debug plugin is installed */
log: (message: string, context?: any) => void;
/** Navigate to a new URL */
navigate: typeof navigate;
performNavigation: typeof performNavigation;
animatePageOut: (this: Swup) => Promise<void>;
renderPage: (this: Swup, requestedUrl: string, page: import("./modules/fetchPage.js").PageData) => Promise<void>;
replaceContent: (this: Swup, { html }: import("./modules/fetchPage.js").PageData, { containers }?: {
containers: string[];
}) => boolean;
scrollToContent: (this: Swup) => boolean;
animatePageIn: (this: Swup) => Promise<void>;
delegateEvent: <Selector extends string, TEvent extends keyof GlobalEventHandlersEventMap>(selector: Selector, type: TEvent, callback: import("delegate-it").DelegateEventHandler<GlobalEventHandlersEventMap[TEvent], Element>, options?: import("delegate-it").DelegateOptions | undefined) => DelegateEventUnsubscribe;
/** Replace the content after page load */
replaceContent: typeof replaceContent;
/** Register a delegated event listener */
delegateEvent: typeof delegateEvent;
/** Fetch a page from the server */
fetchPage: typeof fetchPage;
/** Resolve when animations on the page finish */
awaitAnimations: typeof awaitAnimations;
getAnchorElement: (hash: string) => Element | null;
/** Find the anchor element for a given hash */
getAnchorElement: typeof getAnchorElement;
/** Get the current page URL */
getCurrentUrl: typeof getCurrentUrl;
/** Resolve a URL to its final location */
resolveUrl(url: string): string;
}
/** Swup page transition library. */
export default class Swup implements SwupCore {
version: string;
options: Options;
plugins: Plugin[];
cache: Cache;
hooks: Hooks;
visit: Visit;
classes: Classes;
currentPageUrl: string;
getCurrentUrl: ({ hash }?: {
hash?: boolean | undefined;
}) => string;
use: (this: Swup, plugin: unknown) => Plugin[] | undefined;
unuse: typeof unuse;
findPlugin: typeof findPlugin;
getCurrentUrl: ({ hash }?: {
hash?: boolean | undefined;
}) => string;
createVisit: typeof createVisit;
log: (message: string, context?: any) => void;
/** Default options before merging user options */
defaults: Options;
log: () => void;
getAnchorElement: (hash: string) => Element | null;
navigate: typeof navigate;
protected performNavigation: typeof performNavigation;
delegateEvent: <Selector extends string, TEvent extends keyof GlobalEventHandlersEventMap>(selector: Selector, type: TEvent, callback: import("delegate-it").DelegateEventHandler<GlobalEventHandlersEventMap[TEvent], Element>, options?: import("delegate-it").DelegateOptions | undefined) => DelegateEventUnsubscribe;
fetchPage: typeof fetchPage;
awaitAnimations: typeof awaitAnimations;
protected renderPage: (this: Swup, requestedUrl: string, page: import("./modules/fetchPage.js").PageData) => Promise<void>;
replaceContent: (this: Swup, { html }: import("./modules/fetchPage.js").PageData, { containers }?: {
containers: string[];
}) => boolean;
protected animatePageIn: (this: Swup) => Promise<void>;
protected animatePageOut: (this: Swup) => Promise<void>;
protected scrollToContent: (this: Swup) => boolean;
protected createVisit: typeof createVisit;
resolveUrl: typeof resolveUrl;
protected isSameResolvedUrl: typeof isSameResolvedUrl;
readonly defaults: Options;
/** Index of the current history entry */
protected currentHistoryIndex: number;
/** Delegated event subscription handle */
protected clickDelegate?: DelegateEventUnsubscribe;
constructor(options?: Partial<Options>);
checkRequirements(): boolean;
protected checkRequirements(): boolean;
/** Enable this instance, adding listeners and classnames. */

@@ -97,19 +143,6 @@ enable(): Promise<void>;

}): boolean;
linkClickHandler(event: DelegateEvent<MouseEvent>): void;
protected handleLinkClick(event: DelegateEvent<MouseEvent>): void;
protected handlePopState(event: PopStateEvent): void;
/** Determine whether an element will open a new tab when clicking/activating. */
triggerWillOpenNewWindow(triggerEl: Element): boolean;
popStateHandler(event: PopStateEvent): void;
/**
* Utility function to validate and run the global option 'resolveUrl'
* @param {string} url
* @returns {string} the resolved url
*/
resolveUrl(url: string): string;
/**
* Compares the resolved version of two paths and returns true if they are the same
* @param {string} url1
* @param {string} url2
* @returns {boolean}
*/
isSameResolvedUrl(url1: string, url2: string): boolean;
protected triggerWillOpenNewWindow(triggerEl: Element): boolean;
}
{
"name": "swup",
"amdName": "Swup",
"version": "4.0.0-rc.27",
"version": "4.0.0-rc.28",
"description": "Versatile and extensible page transition library for server-rendered websites",

@@ -6,0 +6,0 @@ "type": "module",

@@ -68,3 +68,3 @@ import { DelegateEvent } from 'delegate-it';

const swup = new Swup({ ignoreVisit });
swup.linkClickHandler(event);
swup.navigate(el.href, {}, { el, event });

@@ -71,0 +71,0 @@ expect(ignoreVisit.mock.calls).toHaveLength(1);

import type { Path } from 'path-to-regexp';
import Swup, { type Options } from './Swup.js';
import Swup, { type SwupCore, type Options } from './Swup.js';
import type { CacheData } from './modules/Cache.js';

@@ -28,2 +28,3 @@ import type {

export type {
SwupCore as Swup,
Options,

@@ -30,0 +31,0 @@ Plugin,

@@ -39,14 +39,6 @@ import Swup from '../Swup.js';

url: URL | string,
options: FetchOptions & { triggerHooks?: boolean } = {}
options: FetchOptions = {}
): Promise<PageData> {
url = Location.fromUrl(url).url;
if (this.cache.has(url)) {
const page = this.cache.get(url) as PageData;
if (options.triggerHooks !== false) {
await this.hooks.call('page:load', { page, cache: true });
}
return page;
}
const headers = { ...this.options.requestHeaders, ...options.headers };

@@ -83,7 +75,3 @@ options = { ...options, headers };

if (options.triggerHooks !== false) {
await this.hooks.call('page:load', { page, cache: false });
}
return page;
}

@@ -29,4 +29,3 @@ import { DelegateEvent } from 'delegate-it';

'link:newtab': { href: string };
'page:request': { url: string; options: FetchOptions };
'page:load': { page: PageData; cache?: boolean };
'page:load': { page?: PageData; cache?: boolean; options: FetchOptions };
'page:view': { url: string; title: string };

@@ -122,3 +121,2 @@ 'scroll:top': { options: ScrollIntoViewOptions };

'link:newtab',
'page:request',
'page:load',

@@ -125,0 +123,0 @@ 'page:view',

@@ -32,3 +32,3 @@ import Swup from '../Swup.js';

// Check if the visit should be ignored
if (this.shouldIgnoreVisit(url)) {
if (this.shouldIgnoreVisit(url, { el: init.el, event: init.event })) {
window.location.href = url;

@@ -91,8 +91,9 @@ return;

// Begin fetching page
const pagePromise = this.hooks.call(
'page:request',
{ url: this.visit.to.url, options },
async (visit, { options }) => await this.fetchPage(visit.to.url as string, options)
);
// Begin loading page
const pagePromise = this.hooks.call('page:load', { options }, async (visit, args) => {
const cachedPage = this.cache.get(visit.to.url!);
args.page = cachedPage || (await this.fetchPage(visit.to.url!, args.options));
args.cache = !!cachedPage;
return args.page;
});

@@ -99,0 +100,0 @@ // Create history record if this is not a popstate call (with or without anchor)

@@ -22,2 +22,3 @@ import { DelegateEvent } from 'delegate-it';

import { use, unuse, findPlugin, Plugin } from './modules/plugins.js';
import { isSameResolvedUrl, resolveUrl } from './modules/resolveUrl.js';
import { nextTick } from './utils.js';

@@ -51,45 +52,94 @@

/** Swup page transition library. */
export default class Swup {
/** Interface for Swup page transition library. */
export interface SwupCore {
/** Library version */
version: string = version;
readonly version: string;
/** Options passed into the instance */
options: Options;
/** Default options before merging user options */
readonly defaults: Readonly<Options>;
/** Registered plugin instances */
plugins: Plugin[] = [];
readonly plugins: Plugin[];
/** Data about the current visit */
visit: Visit;
readonly visit: Visit;
/** Cache instance */
readonly cache: Cache;
/** Hook registry */
readonly hooks: Hooks;
/** Animation class manager */
readonly classes: Classes;
/** URL of the currently visible page */
currentPageUrl: string;
/** Enable the instance */
enable(): Promise<void>;
/** Disable the instance and clean up */
destroy(): Promise<void>;
/** Install a plugin */
use: typeof use;
/** Uninstall a plugin */
unuse: typeof unuse;
/** Find a plugin by name or instance */
findPlugin: typeof findPlugin;
/** Log a message. Has no effect unless debug plugin is installed */
log: (message: string, context?: any) => void;
/** Navigate to a new URL */
navigate: typeof navigate;
/** Replace the content after page load */
replaceContent: typeof replaceContent;
/** Register a delegated event listener */
delegateEvent: typeof delegateEvent;
/** Fetch a page from the server */
fetchPage: typeof fetchPage;
/** Resolve when animations on the page finish */
awaitAnimations: typeof awaitAnimations;
/** Find the anchor element for a given hash */
getAnchorElement: typeof getAnchorElement;
/** Get the current page URL */
getCurrentUrl: typeof getCurrentUrl;
/** Resolve a URL to its final location */
resolveUrl(url: string): string;
}
/** Swup page transition library. */
export default class Swup implements SwupCore {
version = version;
options: Options;
plugins: Plugin[] = [];
cache: Cache;
/** Hook registry */
hooks: Hooks;
/** Animation class manager */
visit: Visit;
classes: Classes;
/** URL of the currently visible page */
currentPageUrl = getCurrentUrl();
/** Index of the current history entry */
currentHistoryIndex = 1;
/** Delegated event subscription handle */
private clickDelegate?: DelegateEventUnsubscribe;
getCurrentUrl = getCurrentUrl;
use = use;
unuse = unuse;
findPlugin = findPlugin;
log = () => {};
getAnchorElement = getAnchorElement;
navigate = navigate;
performNavigation = performNavigation;
animatePageOut = animatePageOut;
renderPage = renderPage;
replaceContent = replaceContent;
scrollToContent = scrollToContent;
animatePageIn = animatePageIn;
protected performNavigation = performNavigation;
delegateEvent = delegateEvent;
fetchPage = fetchPage;
awaitAnimations = awaitAnimations;
getAnchorElement = getAnchorElement;
use = use;
unuse = unuse;
findPlugin = findPlugin;
getCurrentUrl = getCurrentUrl;
createVisit = createVisit;
log: (message: string, context?: any) => void = () => {}; // here so it can be used by plugins
protected renderPage = renderPage;
replaceContent = replaceContent;
protected animatePageIn = animatePageIn;
protected animatePageOut = animatePageOut;
protected scrollToContent = scrollToContent;
/** Default options before merging user options */
defaults: Options = {
protected createVisit = createVisit;
resolveUrl = resolveUrl;
protected isSameResolvedUrl = isSameResolvedUrl;
readonly defaults: Options = {
animateHistoryBrowsing: false,

@@ -111,2 +161,8 @@ animationSelector: '[class*="transition-"]',

/** Index of the current history entry */
protected currentHistoryIndex = 1;
/** Delegated event subscription handle */
protected clickDelegate?: DelegateEventUnsubscribe;
constructor(options: Partial<Options> = {}) {

@@ -116,4 +172,4 @@ // Merge defaults and options

this.linkClickHandler = this.linkClickHandler.bind(this);
this.popStateHandler = this.popStateHandler.bind(this);
this.handleLinkClick = this.handleLinkClick.bind(this);
this.handlePopState = this.handlePopState.bind(this);

@@ -132,3 +188,3 @@ this.cache = new Cache(this);

checkRequirements() {
protected checkRequirements() {
if (typeof Promise === 'undefined') {

@@ -145,5 +201,5 @@ console.warn('Promise is not supported');

const { linkSelector } = this.options;
this.clickDelegate = this.delegateEvent(linkSelector, 'click', this.linkClickHandler);
this.clickDelegate = this.delegateEvent(linkSelector, 'click', this.handleLinkClick);
window.addEventListener('popstate', this.popStateHandler);
window.addEventListener('popstate', this.handlePopState);

@@ -178,3 +234,3 @@ // Initial save to cache

// remove popstate listener
window.removeEventListener('popstate', this.popStateHandler);
window.removeEventListener('popstate', this.handlePopState);

@@ -220,3 +276,3 @@ // empty cache

linkClickHandler(event: DelegateEvent<MouseEvent>) {
protected handleLinkClick(event: DelegateEvent<MouseEvent>) {
const el = event.delegateTarget as HTMLAnchorElement;

@@ -273,11 +329,3 @@ const { href, url, hash } = Location.fromElement(el);

/** Determine whether an element will open a new tab when clicking/activating. */
triggerWillOpenNewWindow(triggerEl: Element) {
if (triggerEl.matches('[download], [target="_blank"]')) {
return true;
}
return false;
}
popStateHandler(event: PopStateEvent) {
protected handlePopState(event: PopStateEvent) {
const href = event.state?.url ?? location.href;

@@ -332,33 +380,9 @@

/**
* Utility function to validate and run the global option 'resolveUrl'
* @param {string} url
* @returns {string} the resolved url
*/
resolveUrl(url: string) {
if (typeof this.options.resolveUrl !== 'function') {
console.warn(`[swup] options.resolveUrl expects a callback function.`);
return url;
/** Determine whether an element will open a new tab when clicking/activating. */
protected triggerWillOpenNewWindow(triggerEl: Element) {
if (triggerEl.matches('[download], [target="_blank"]')) {
return true;
}
const result = this.options.resolveUrl(url);
if (!result || typeof result !== 'string') {
console.warn(`[swup] options.resolveUrl needs to return a url`);
return url;
}
if (result.startsWith('//') || result.startsWith('http')) {
console.warn(`[swup] options.resolveUrl needs to return a relative url`);
return url;
}
return result;
return false;
}
/**
* Compares the resolved version of two paths and returns true if they are the same
* @param {string} url1
* @param {string} url2
* @returns {boolean}
*/
isSameResolvedUrl(url1: string, url2: string) {
return this.resolveUrl(url1) === this.resolveUrl(url2);
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc