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 3.1.0 to 3.1.1

2

dist/Swup.modern.js

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

import t from"delegate-it";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},e.apply(this,arguments)}const n=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",i=({hash:t}={})=>location.pathname+location.search+(t?location.hash:""),s=(t,n={})=>{const s=e({url:t=t||i({hash:!0}),random:Math.random(),source:"swup"},n);history.pushState(s,"",t)},o=(t=null,n={})=>{t=t||i({hash:!0});const s=e({},history.state,{url:t,random:Math.random(),source:"swup"},n);history.replaceState(s,"",t)},r=(e,n,i,s)=>{const o=new AbortController;return t(e,n,i,s),{destroy:()=>o.abort()}},a=(t,e=document)=>e.querySelector(t),l=(t,e=document)=>Array.from(e.querySelectorAll(t)),c=t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})},u=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,h=t=>1e3*Number(t.slice(0,-1).replace(",",".")),d=(t,e)=>{var n,i;let s=document.createElement("html");s.innerHTML=t;let o=[];e.forEach(t=>{if(null==a(t,s))return console.warn(`[swup] Container ${t} not found on page.`),null;l(t).length!==l(t,s).length&&console.warn("[swup] Mismatched number of containers found on new page."),l(t).forEach((e,n)=>{l(t,s)[n].setAttribute("data-swup",String(o.length)),o.push(l(t,s)[n].outerHTML)})});const r=(null==(n=a("title",s))?void 0:n.innerText)||"",c=null==(i=a("body",s))?void 0:i.className;return s.innerHTML="",s=null,{title:r,pageClass:c,blocks:o,originalContent:t}},p=(t,n)=>{const i={url:window.location.pathname+window.location.search,method:"GET",data:null,headers:{}},{url:s,method:o,headers:r,data:a}=e({},i,t),l=new XMLHttpRequest;return l.onreadystatechange=function(){4===l.readyState&&n(l)},l.open(o,s,!0),Object.entries(r).forEach(([t,e])=>{l.setRequestHeader(t,e)}),l.send(a),l};class g 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 g(e)}static fromUrl(t){return new g(t)}}const m=(t,e)=>{let n=0;e.forEach(e=>{null==a(e,t)?console.warn(`[swup] Container ${e} not found on page.`):l(e).forEach((i,s)=>{l(e,t)[s].setAttribute("data-swup",String(n)),n++})})},f=t=>/^to-/.test(t)||["is-changing","is-rendering","is-popstate"].includes(t),v=()=>{const t=document.documentElement.className.split(" ").filter(f);document.documentElement.classList.remove(...t)};class w{constructor(t){this.pages={},this.last=null,this.swup=void 0,this.swup=t}getCacheUrl(t){return this.swup.resolveUrl(g.fromUrl(t).url)}cacheUrl(t){t.url=this.getCacheUrl(t.url),t.url in this.pages==0&&(this.pages[t.url]=t),t.responseURL=this.getCacheUrl(t.responseURL),this.last=this.pages[t.url],this.swup.log(`Cache (${Object.keys(this.pages).length})`,this.pages)}getPage(t){return t=this.getCacheUrl(t),this.pages[t]}getCurrentPage(){return this.getPage(i())}exists(t){return(t=this.getCacheUrl(t))in this.pages}empty(){this.pages={},this.last=null,this.swup.log("Cache cleared")}remove(t){delete this.pages[this.getCacheUrl(t)]}}const E=function({event:t,skipTransition:e}={}){if(e)return this.triggerEvent("transitionEnd",t),this.cleanupAnimationClasses(),[Promise.resolve()];c(()=>{this.triggerEvent("animationInStart"),document.documentElement.classList.remove("is-animating")});const n=this.getAnimationPromises("in");return Promise.all(n).then(()=>{this.triggerEvent("animationInDone"),this.triggerEvent("transitionEnd",t),this.cleanupAnimationClasses()}),n},P=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);return document.getElementById(t)||document.getElementById(e)||a(`a[name='${u(t)}']`)||a(`a[name='${u(e)}']`)};let S="transition",b="transitionend",y="animation",U="animationend";function k(t){const e=this.options.animationSelector;if(!1===e)return[Promise.resolve()];const n=l(e,document.body);if(!n.length)return console.warn(`[swup] No elements found matching animationSelector \`${e}\``),[Promise.resolve()];const i=n.map(t=>function(t){const{type:e,timeout:n,propCount:i}=function(t,e=null){const n=window.getComputedStyle(t),i=`${S}Duration`,s=`${y}Delay`,o=`${y}Duration`,r=n[`${S}Delay`].split(", "),a=(n[i]||"").split(", "),l=L(r,a),c=(n[s]||"").split(", "),u=(n[o]||"").split(", "),h=L(c,u);let d="",p=0,g=0;return"transition"===e?l>0&&(d="transition",p=l,g=a.length):"animation"===e?h>0&&(d="animation",p=h,g=u.length):(p=Math.max(l,h),d=p>0?l>h?"transition":"animation":null,g=d?"transition"===d?a.length:u.length:0),{type:d,timeout:p,propCount:g}}(t);if(e&&n)return new Promise(s=>{const o="transition"===e?b:U,r=performance.now();let a=0;const l=()=>{t.removeEventListener(o,c),s()},c=e=>{if(e.target===t){if(!(t=>[b,U].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()},n+1),t.addEventListener(o,c)})}(t)).filter(Boolean);return i.length?i:(console.warn(`[swup] No CSS animation duration defined on elements matching \`${e}\``),[Promise.resolve()])}function L(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>h(e)+h(t[n])))}void 0===window.ontransitionend&&void 0!==window.onwebkittransitionend&&(S="WebkitTransition",b="webkitTransitionEnd"),void 0===window.onanimationend&&void 0!==window.onwebkitanimationend&&(y="WebkitAnimation",U="webkitAnimationEnd");const C=function(t){const n=d(t.responseText,this.options.containers);return n?e({},n,{responseURL:t.responseURL||window.location.href}):(console.warn("[swup] Received page is invalid."),null)};function T(t){const n=this.options.requestHeaders,{url:i}=t;return this.cache.exists(i)?(this.triggerEvent("pageRetrievedFromCache"),Promise.resolve(this.cache.getPage(i))):new Promise((s,o)=>{p(e({},t,{headers:n}),t=>{if(500===t.status)return this.triggerEvent("serverError"),void o(i);const n=this.getPageData(t);if(!n||!n.blocks.length)return void o(i);const r=e({},n,{url:i});this.cache.cacheUrl(r),this.triggerEvent("pageLoaded"),s(r)})})}const H=function({event:t,skipTransition:e}={}){const n=t instanceof PopStateEvent;if(e)return this.triggerEvent("animationSkipped"),[Promise.resolve()];this.triggerEvent("animationOutStart"),document.documentElement.classList.add("is-changing","is-leaving","is-animating"),n&&document.documentElement.classList.add("is-popstate");const i=this.getAnimationPromises("out");return Promise.all(i).then(()=>{this.triggerEvent("animationOutDone")}),i};function R(t){const{url:e}=t;this.shouldIgnoreVisit(e)?window.location.href=e:this.performPageLoad(t)}function A(t){const{url:e,event:r,customTransition:a,history:l="push"}=null!=t?t:{},c=r instanceof PopStateEvent,u=this.shouldSkipTransition({url:e,event:r});this.triggerEvent("transitionStart",r),this.updateTransition(i(),e,a),null!=a&&document.documentElement.classList.add(`to-${n(a)}`);const h=this.leavePage({event:r,skipTransition:u}),d=this.fetchPage(t);if(!c){const t=e+(this.scrollToElement||"");"replace"===l?o(t):s(t)}this.currentPageUrl=i(),Promise.all([d,...h]).then(([t])=>{this.renderPage(t,{event:r,skipTransition:u})}).catch(t=>{void 0!==t&&(this.options.skipPopStateHandling=()=>(window.location=t,!0),history.go(-1))})}const $=function({blocks:t,title:e}){return t.forEach((t,e)=>{document.body.querySelector(`[data-swup="${e}"]`).outerHTML=t}),document.title=e,Promise.resolve()};function _(t,e){const n=this._handlers[t];n?n.push(e):console.warn(`Unsupported event ${t}.`)}function I(t,e){if(t&&e){const n=this._handlers[t];n.includes(e)?this._handlers[t]=n.filter(t=>t!==e):console.warn(`Handler for event '${t}' not found.`)}else t?this._handlers[t]=[]:Object.keys(this._handlers).forEach(t=>{this._handlers[t]=[]})}function x(t,e){this._handlers[t].forEach(t=>{try{t(e)}catch(t){console.error(t)}});const n=new CustomEvent(`swup:${t}`,{detail:t});document.dispatchEvent(n)}const O=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 q(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function D(t){return this.plugins.find(e=>e===t||e.name===t)}const M=function(t,{event:n,skipTransition:s}={}){if(document.documentElement.classList.remove("is-leaving"),!this.isSameResolvedUrl(i(),t.url))return;const{url:r}=g.fromUrl(t.responseURL);this.isSameResolvedUrl(i(),r)||(this.cache.cacheUrl(e({},t,{url:r})),this.currentPageUrl=i(),o(r)),s||document.documentElement.classList.add("is-rendering"),this.triggerEvent("willReplaceContent",n),this.replaceContent(t).then(()=>{this.triggerEvent("contentReplaced",n),this.triggerEvent("pageView",n),this.options.cache||this.cache.empty(),this.enterPage({event:n,skipTransition:s}),this.scrollToElement=null})};function N(t,e,n){this.transition={from:t,to:e,custom:n}}function W({event:t}){return!(!(t instanceof PopStateEvent)||this.options.animateHistoryBrowsing)}class V{constructor(t={}){this.version="3.1.0",this._handlers={animationInDone:[],animationInStart:[],animationOutDone:[],animationOutStart:[],animationSkipped:[],clickLink:[],contentReplaced:[],disabled:[],enabled:[],openPageInNewTab:[],pageLoaded:[],pageRetrievedFromCache:[],pageView:[],popState:[],samePage:[],samePageWithHash:[],serverError:[],transitionStart:[],transitionEnd:[],willReplaceContent:[]},this.scrollToElement=null,this.options=void 0,this.plugins=[],this.transition={},this.cache=void 0,this.currentPageUrl=i(),this.delegatedListeners={},this.boundPopStateHandler=void 0,this.loadPage=R,this.performPageLoad=A,this.leavePage=H,this.renderPage=M,this.replaceContent=$,this.enterPage=E,this.triggerEvent=x,this.delegateEvent=r,this.on=_,this.off=I,this.updateTransition=N,this.shouldSkipTransition=W,this.getAnimationPromises=k,this.getPageData=C,this.fetchPage=T,this.getAnchorElement=P,this.log=()=>{},this.use=O,this.unuse=q,this.findPlugin=D,this.getCurrentUrl=i,this.cleanupAnimationClasses=v,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',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=e({},this.defaults,t),this.boundPopStateHandler=this.popStateHandler.bind(this),this.cache=new w(this),this.enable()}enable(){"undefined"!=typeof Promise?(this.delegatedListeners.click=r(this.options.linkSelector,"click",this.linkClickHandler.bind(this)),window.addEventListener("popstate",this.boundPopStateHandler),m(document.documentElement,this.options.containers),this.options.plugins.forEach(t=>this.use(t)),o(),this.triggerEvent("enabled"),document.documentElement.classList.add("swup-enabled"),this.triggerEvent("pageView")):console.warn("Promise is not supported")}destroy(){this.delegatedListeners.click.destroy(),window.removeEventListener("popstate",this.boundPopStateHandler),this.cache.empty(),this.options.plugins.forEach(t=>{this.unuse(t)}),l("[data-swup]").forEach(t=>{t.removeAttribute("data-swup")}),this.off(),this.triggerEvent("disabled"),document.documentElement.classList.remove("swup-enabled")}shouldIgnoreVisit(t,{el:e,event:n}={}){const{origin:i,url:s,hash:o}=g.fromUrl(t);return i!==window.location.origin||!(!e||!this.triggerWillOpenNewWindow(e))||!!this.options.ignoreVisit(s+o,{el:e,event:n})}linkClickHandler(t){const e=t.delegateTarget,{href:n,url:s,hash:o}=g.fromElement(e);if(this.shouldIgnoreVisit(n,{el:e,event:t}))return;if(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return void this.triggerEvent("openPageInNewTab",t);if(0!==t.button)return;if(this.triggerEvent("clickLink",t),t.preventDefault(),!s||s===i())return void this.handleLinkToSamePage(s,o,t);if(this.isSameResolvedUrl(s,i()))return;this.scrollToElement=o||null;const r=e.getAttribute("data-swup-transition")||void 0;let a;const l=e.getAttribute("data-swup-history");l&&["push","replace"].includes(l)&&(a=l),this.performPageLoad({url:s,customTransition:r,history:a})}handleLinkToSamePage(t,e,n){if(e){if(this.triggerEvent("samePageWithHash",n),!P(e))return console.warn(`Element for offset not found (#${e})`);o(t+e)}else this.triggerEvent("samePage",n)}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}popStateHandler(t){var e,n;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(i(),this.currentPageUrl))return;const s=null!=(e=null==(n=t.state)?void 0:n.url)?e:location.href;if(this.shouldIgnoreVisit(s,{event:t}))return;const{url:o,hash:r}=g.fromUrl(s);r?this.scrollToElement=r:t.preventDefault(),this.triggerEvent("popState",t),this.options.animateHistoryBrowsing||(document.documentElement.classList.remove("is-animating"),v()),this.performPageLoad({url:o,event:t})}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{g as Location,n as classify,v as cleanupAnimationClasses,s as createHistoryRecord,V as default,r as delegateEvent,u as escapeCssIdentifier,p as fetch,i as getCurrentUrl,d as getDataFromHtml,m as markSwupElements,c as nextTick,a as query,l as queryAll,h as toMs,o as updateHistoryRecord};
import t from"delegate-it";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},e.apply(this,arguments)}const n=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",i=({hash:t}={})=>location.pathname+location.search+(t?location.hash:""),s=(t,n={})=>{const s=e({url:t=t||i({hash:!0}),random:Math.random(),source:"swup"},n);history.pushState(s,"",t)},o=(t=null,n={})=>{t=t||i({hash:!0});const s=e({},history.state,{url:t,random:Math.random(),source:"swup"},n);history.replaceState(s,"",t)},r=(e,n,i,s)=>{const o=new AbortController;return t(e,n,i,s),{destroy:()=>o.abort()}},a=(t,e=document)=>e.querySelector(t),l=(t,e=document)=>Array.from(e.querySelectorAll(t)),c=t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})},u=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,h=t=>1e3*Number(t.slice(0,-1).replace(",",".")),d=(t,e)=>{var n,i;let s=document.createElement("html");s.innerHTML=t;let o=[];e.forEach(t=>{if(null==a(t,s))return console.warn(`[swup] Container ${t} not found on page.`),null;l(t).length!==l(t,s).length&&console.warn("[swup] Mismatched number of containers found on new page."),l(t).forEach((e,n)=>{l(t,s)[n].setAttribute("data-swup",String(o.length)),o.push(l(t,s)[n].outerHTML)})});const r=(null==(n=a("title",s))?void 0:n.innerText)||"",c=null==(i=a("body",s))?void 0:i.className;return s.innerHTML="",s=null,{title:r,pageClass:c,blocks:o,originalContent:t}},p=(t,n)=>{const i={url:window.location.pathname+window.location.search,method:"GET",data:null,headers:{}},{url:s,method:o,headers:r,data:a}=e({},i,t),l=new XMLHttpRequest;return l.onreadystatechange=function(){4===l.readyState&&n(l)},l.open(o,s,!0),Object.entries(r).forEach(([t,e])=>{l.setRequestHeader(t,e)}),l.send(a),l};class g 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 g(e)}static fromUrl(t){return new g(t)}}const m=(t,e)=>{let n=0;e.forEach(e=>{null==a(e,t)?console.warn(`[swup] Container ${e} not found on page.`):l(e).forEach((i,s)=>{l(e,t)[s].setAttribute("data-swup",String(n)),n++})})},f=t=>/^to-/.test(t)||["is-changing","is-rendering","is-popstate"].includes(t),v=()=>{const t=document.documentElement.className.split(" ").filter(f);document.documentElement.classList.remove(...t)};class w{constructor(t){this.pages={},this.last=null,this.swup=void 0,this.swup=t}getCacheUrl(t){return this.swup.resolveUrl(g.fromUrl(t).url)}cacheUrl(t){t.url=this.getCacheUrl(t.url),t.url in this.pages==0&&(this.pages[t.url]=t),t.responseURL=this.getCacheUrl(t.responseURL),this.last=this.pages[t.url],this.swup.log(`Cache (${Object.keys(this.pages).length})`,this.pages)}getPage(t){return t=this.getCacheUrl(t),this.pages[t]}getCurrentPage(){return this.getPage(i())}exists(t){return(t=this.getCacheUrl(t))in this.pages}empty(){this.pages={},this.last=null,this.swup.log("Cache cleared")}remove(t){delete this.pages[this.getCacheUrl(t)]}}const E=function({event:t,skipTransition:e}={}){if(e)return this.triggerEvent("transitionEnd",t),this.cleanupAnimationClasses(),[Promise.resolve()];c(()=>{this.triggerEvent("animationInStart"),document.documentElement.classList.remove("is-animating")});const n=this.getAnimationPromises("in");return Promise.all(n).then(()=>{this.triggerEvent("animationInDone"),this.triggerEvent("transitionEnd",t),this.cleanupAnimationClasses()}),n},P=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)||a(`a[name='${u(t)}']`)||a(`a[name='${u(e)}']`);return n||"top"!==t||(n=document.body),n};let S="transition",b="transitionend",y="animation",U="animationend";function k(t){const e=this.options.animationSelector;if(!1===e)return[Promise.resolve()];const n=l(e,document.body);if(!n.length)return console.warn(`[swup] No elements found matching animationSelector \`${e}\``),[Promise.resolve()];const i=n.map(t=>function(t){const{type:e,timeout:n,propCount:i}=function(t,e=null){const n=window.getComputedStyle(t),i=`${S}Duration`,s=`${y}Delay`,o=`${y}Duration`,r=n[`${S}Delay`].split(", "),a=(n[i]||"").split(", "),l=L(r,a),c=(n[s]||"").split(", "),u=(n[o]||"").split(", "),h=L(c,u);let d="",p=0,g=0;return"transition"===e?l>0&&(d="transition",p=l,g=a.length):"animation"===e?h>0&&(d="animation",p=h,g=u.length):(p=Math.max(l,h),d=p>0?l>h?"transition":"animation":null,g=d?"transition"===d?a.length:u.length:0),{type:d,timeout:p,propCount:g}}(t);if(e&&n)return new Promise(s=>{const o="transition"===e?b:U,r=performance.now();let a=0;const l=()=>{t.removeEventListener(o,c),s()},c=e=>{if(e.target===t){if(!(t=>[b,U].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()},n+1),t.addEventListener(o,c)})}(t)).filter(Boolean);return i.length?i:(console.warn(`[swup] No CSS animation duration defined on elements matching \`${e}\``),[Promise.resolve()])}function L(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>h(e)+h(t[n])))}void 0===window.ontransitionend&&void 0!==window.onwebkittransitionend&&(S="WebkitTransition",b="webkitTransitionEnd"),void 0===window.onanimationend&&void 0!==window.onwebkitanimationend&&(y="WebkitAnimation",U="webkitAnimationEnd");const C=function(t){const n=d(t.responseText,this.options.containers);return n?e({},n,{responseURL:t.responseURL||window.location.href}):(console.warn("[swup] Received page is invalid."),null)};function T(t){const n=this.options.requestHeaders,{url:i}=t;return this.cache.exists(i)?(this.triggerEvent("pageRetrievedFromCache"),Promise.resolve(this.cache.getPage(i))):new Promise((s,o)=>{p(e({},t,{headers:n}),t=>{if(500===t.status)return this.triggerEvent("serverError"),void o(i);const n=this.getPageData(t);if(!n||!n.blocks.length)return void o(i);const r=e({},n,{url:i});this.cache.cacheUrl(r),this.triggerEvent("pageLoaded"),s(r)})})}const H=function({event:t,skipTransition:e}={}){const n=t instanceof PopStateEvent;if(e)return this.triggerEvent("animationSkipped"),[Promise.resolve()];this.triggerEvent("animationOutStart"),document.documentElement.classList.add("is-changing","is-leaving","is-animating"),n&&document.documentElement.classList.add("is-popstate");const i=this.getAnimationPromises("out");return Promise.all(i).then(()=>{this.triggerEvent("animationOutDone")}),i};function R(t){const{url:e}=t;this.shouldIgnoreVisit(e)?window.location.href=e:this.performPageLoad(t)}function A(t){const{url:e,event:r,customTransition:a,history:l="push"}=null!=t?t:{},c=r instanceof PopStateEvent,u=this.shouldSkipTransition({url:e,event:r});this.triggerEvent("transitionStart",r),this.updateTransition(i(),e,a),null!=a&&document.documentElement.classList.add(`to-${n(a)}`);const h=this.leavePage({event:r,skipTransition:u}),d=this.fetchPage(t);if(!c){const t=e+(this.scrollToElement||"");"replace"===l?o(t):s(t)}this.currentPageUrl=i(),Promise.all([d,...h]).then(([t])=>{this.renderPage(t,{event:r,skipTransition:u})}).catch(t=>{void 0!==t&&(this.options.skipPopStateHandling=()=>(window.location=t,!0),history.go(-1))})}const $=function({blocks:t,title:e}){return t.forEach((t,e)=>{document.body.querySelector(`[data-swup="${e}"]`).outerHTML=t}),document.title=e,Promise.resolve()};function _(t,e){const n=this._handlers[t];n?n.push(e):console.warn(`Unsupported event ${t}.`)}function I(t,e){if(t&&e){const n=this._handlers[t];n.includes(e)?this._handlers[t]=n.filter(t=>t!==e):console.warn(`Handler for event '${t}' not found.`)}else t?this._handlers[t]=[]:Object.keys(this._handlers).forEach(t=>{this._handlers[t]=[]})}function x(t,e){this._handlers[t].forEach(t=>{try{t(e)}catch(t){console.error(t)}});const n=new CustomEvent(`swup:${t}`,{detail:t});document.dispatchEvent(n)}const O=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 q(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function D(t){return this.plugins.find(e=>e===t||e.name===t)}const M=function(t,{event:n,skipTransition:s}={}){if(document.documentElement.classList.remove("is-leaving"),!this.isSameResolvedUrl(i(),t.url))return;const{url:r}=g.fromUrl(t.responseURL);this.isSameResolvedUrl(i(),r)||(this.cache.cacheUrl(e({},t,{url:r})),this.currentPageUrl=i(),o(r)),s||document.documentElement.classList.add("is-rendering"),this.triggerEvent("willReplaceContent",n),this.replaceContent(t).then(()=>{this.triggerEvent("contentReplaced",n),this.triggerEvent("pageView",n),this.options.cache||this.cache.empty(),this.enterPage({event:n,skipTransition:s}),this.scrollToElement=null})};function N(t,e,n){this.transition={from:t,to:e,custom:n}}function W({event:t}){return!(!(t instanceof PopStateEvent)||this.options.animateHistoryBrowsing)}class V{constructor(t={}){this.version="3.1.1",this._handlers={animationInDone:[],animationInStart:[],animationOutDone:[],animationOutStart:[],animationSkipped:[],clickLink:[],contentReplaced:[],disabled:[],enabled:[],openPageInNewTab:[],pageLoaded:[],pageRetrievedFromCache:[],pageView:[],popState:[],samePage:[],samePageWithHash:[],serverError:[],transitionStart:[],transitionEnd:[],willReplaceContent:[]},this.scrollToElement=null,this.options=void 0,this.plugins=[],this.transition={},this.cache=void 0,this.currentPageUrl=i(),this.delegatedListeners={},this.boundPopStateHandler=void 0,this.loadPage=R,this.performPageLoad=A,this.leavePage=H,this.renderPage=M,this.replaceContent=$,this.enterPage=E,this.triggerEvent=x,this.delegateEvent=r,this.on=_,this.off=I,this.updateTransition=N,this.shouldSkipTransition=W,this.getAnimationPromises=k,this.getPageData=C,this.fetchPage=T,this.getAnchorElement=P,this.log=()=>{},this.use=O,this.unuse=q,this.findPlugin=D,this.getCurrentUrl=i,this.cleanupAnimationClasses=v,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',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=e({},this.defaults,t),this.boundPopStateHandler=this.popStateHandler.bind(this),this.cache=new w(this),this.enable()}enable(){"undefined"!=typeof Promise?(this.delegatedListeners.click=r(this.options.linkSelector,"click",this.linkClickHandler.bind(this)),window.addEventListener("popstate",this.boundPopStateHandler),m(document.documentElement,this.options.containers),this.options.plugins.forEach(t=>this.use(t)),o(),this.triggerEvent("enabled"),document.documentElement.classList.add("swup-enabled"),this.triggerEvent("pageView")):console.warn("Promise is not supported")}destroy(){this.delegatedListeners.click.destroy(),window.removeEventListener("popstate",this.boundPopStateHandler),this.cache.empty(),this.options.plugins.forEach(t=>{this.unuse(t)}),l("[data-swup]").forEach(t=>{t.removeAttribute("data-swup")}),this.off(),this.triggerEvent("disabled"),document.documentElement.classList.remove("swup-enabled")}shouldIgnoreVisit(t,{el:e,event:n}={}){const{origin:i,url:s,hash:o}=g.fromUrl(t);return i!==window.location.origin||!(!e||!this.triggerWillOpenNewWindow(e))||!!this.options.ignoreVisit(s+o,{el:e,event:n})}linkClickHandler(t){const e=t.delegateTarget,{href:n,url:s,hash:o}=g.fromElement(e);if(this.shouldIgnoreVisit(n,{el:e,event:t}))return;if(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return void this.triggerEvent("openPageInNewTab",t);if(0!==t.button)return;if(this.triggerEvent("clickLink",t),t.preventDefault(),!s||s===i())return void this.handleLinkToSamePage(s,o,t);if(this.isSameResolvedUrl(s,i()))return;this.scrollToElement=o||null;const r=e.getAttribute("data-swup-transition")||void 0;let a;const l=e.getAttribute("data-swup-history");l&&["push","replace"].includes(l)&&(a=l),this.performPageLoad({url:s,customTransition:r,history:a})}handleLinkToSamePage(t,e,n){if(e){if(this.triggerEvent("samePageWithHash",n),!P(e))return console.warn(`Element for offset not found (#${e})`);o(t+e)}else this.triggerEvent("samePage",n)}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}popStateHandler(t){var e,n;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(i(),this.currentPageUrl))return;const s=null!=(e=null==(n=t.state)?void 0:n.url)?e:location.href;if(this.shouldIgnoreVisit(s,{event:t}))return;const{url:o,hash:r}=g.fromUrl(s);r?this.scrollToElement=r:t.preventDefault(),this.triggerEvent("popState",t),this.options.animateHistoryBrowsing||(document.documentElement.classList.remove("is-animating"),v()),this.performPageLoad({url:o,event:t})}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{g as Location,n as classify,v as cleanupAnimationClasses,s as createHistoryRecord,V as default,r as delegateEvent,u as escapeCssIdentifier,p as fetch,i as getCurrentUrl,d as getDataFromHtml,m as markSwupElements,c as nextTick,a as query,l as queryAll,h as toMs,o as updateHistoryRecord};
//# sourceMappingURL=Swup.modern.js.map

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

import t from"delegate-it";const e=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",n=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},i=function(t,e){void 0===e&&(e={});const i={url:t=t||n({hash:!0}),random:Math.random(),source:"swup",...e};history.pushState(i,"",t)},s=function(t,e){void 0===t&&(t=null),void 0===e&&(e={}),t=t||n({hash:!0});const i={...history.state,url:t,random:Math.random(),source:"swup",...e};history.replaceState(i,"",t)},o=(e,n,i,s)=>{const o=new AbortController;return t(e,n,i,s),{destroy:()=>o.abort()}},r=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},a=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},l=t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})},c=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,u=t=>1e3*Number(t.slice(0,-1).replace(",",".")),h=(t,e)=>{let n=document.createElement("html");n.innerHTML=t;let i=[];e.forEach(t=>{if(null==r(t,n))return console.warn(`[swup] Container ${t} not found on page.`),null;a(t).length!==a(t,n).length&&console.warn("[swup] Mismatched number of containers found on new page."),a(t).forEach((e,s)=>{a(t,n)[s].setAttribute("data-swup",String(i.length)),i.push(a(t,n)[s].outerHTML)})});const s=r("title",n)?.innerText||"",o=r("body",n)?.className;return n.innerHTML="",n=null,{title:s,pageClass:o,blocks:i,originalContent:t}},d=(t,e)=>{const n={url:window.location.pathname+window.location.search,method:"GET",data:null,headers:{}},{url:i,method:s,headers:o,data:r}={...n,...t},a=new XMLHttpRequest;return a.onreadystatechange=function(){4===a.readyState&&e(a)},a.open(s,i,!0),Object.entries(o).forEach(t=>{let[e,n]=t;a.setRequestHeader(e,n)}),a.send(r),a};class p 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 p(e)}static fromUrl(t){return new p(t)}}const g=(t,e)=>{let n=0;e.forEach(e=>{null==r(e,t)?console.warn(`[swup] Container ${e} not found on page.`):a(e).forEach((i,s)=>{a(e,t)[s].setAttribute("data-swup",String(n)),n++})})},m=t=>/^to-/.test(t)||["is-changing","is-rendering","is-popstate"].includes(t),f=()=>{const t=document.documentElement.className.split(" ").filter(m);document.documentElement.classList.remove(...t)};class v{constructor(t){this.pages={},this.last=null,this.swup=void 0,this.swup=t}getCacheUrl(t){return this.swup.resolveUrl(p.fromUrl(t).url)}cacheUrl(t){t.url=this.getCacheUrl(t.url),t.url in this.pages==0&&(this.pages[t.url]=t),t.responseURL=this.getCacheUrl(t.responseURL),this.last=this.pages[t.url],this.swup.log(`Cache (${Object.keys(this.pages).length})`,this.pages)}getPage(t){return t=this.getCacheUrl(t),this.pages[t]}getCurrentPage(){return this.getPage(n())}exists(t){return(t=this.getCacheUrl(t))in this.pages}empty(){this.pages={},this.last=null,this.swup.log("Cache cleared")}remove(t){delete this.pages[this.getCacheUrl(t)]}}const w=function(t){let{event:e,skipTransition:n}=void 0===t?{}:t;if(n)return this.triggerEvent("transitionEnd",e),this.cleanupAnimationClasses(),[Promise.resolve()];l(()=>{this.triggerEvent("animationInStart"),document.documentElement.classList.remove("is-animating")});const i=this.getAnimationPromises("in");return Promise.all(i).then(()=>{this.triggerEvent("animationInDone"),this.triggerEvent("transitionEnd",e),this.cleanupAnimationClasses()}),i},E=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);return document.getElementById(t)||document.getElementById(e)||r(`a[name='${c(t)}']`)||r(`a[name='${c(e)}']`)};let P="transition",S="transitionend",b="animation",U="animationend";function k(t){const e=this.options.animationSelector;if(!1===e)return[Promise.resolve()];const n=a(e,document.body);if(!n.length)return console.warn(`[swup] No elements found matching animationSelector \`${e}\``),[Promise.resolve()];const i=n.map(t=>function(t){const{type:e,timeout:n,propCount:i}=function(t,e){void 0===e&&(e=null);const n=window.getComputedStyle(t),i=`${P}Duration`,s=`${b}Delay`,o=`${b}Duration`,r=n[`${P}Delay`].split(", "),a=(n[i]||"").split(", "),l=y(r,a),c=(n[s]||"").split(", "),u=(n[o]||"").split(", "),h=y(c,u);let d="",p=0,g=0;return"transition"===e?l>0&&(d="transition",p=l,g=a.length):"animation"===e?h>0&&(d="animation",p=h,g=u.length):(p=Math.max(l,h),d=p>0?l>h?"transition":"animation":null,g=d?"transition"===d?a.length:u.length:0),{type:d,timeout:p,propCount:g}}(t);if(e&&n)return new Promise(s=>{const o="transition"===e?S:U,r=performance.now();let a=0;const l=()=>{t.removeEventListener(o,c),s()},c=e=>{if(e.target===t){if(!(t=>[S,U].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()},n+1),t.addEventListener(o,c)})}(t)).filter(Boolean);return i.length?i:(console.warn(`[swup] No CSS animation duration defined on elements matching \`${e}\``),[Promise.resolve()])}function y(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>u(e)+u(t[n])))}void 0===window.ontransitionend&&void 0!==window.onwebkittransitionend&&(P="WebkitTransition",S="webkitTransitionEnd"),void 0===window.onanimationend&&void 0!==window.onwebkitanimationend&&(b="WebkitAnimation",U="webkitAnimationEnd");const L=function(t){const e=h(t.responseText,this.options.containers);return e?{...e,responseURL:t.responseURL||window.location.href}:(console.warn("[swup] Received page is invalid."),null)};function C(t){const e=this.options.requestHeaders,{url:n}=t;return this.cache.exists(n)?(this.triggerEvent("pageRetrievedFromCache"),Promise.resolve(this.cache.getPage(n))):new Promise((i,s)=>{d({...t,headers:e},t=>{if(500===t.status)return this.triggerEvent("serverError"),void s(n);const e=this.getPageData(t);if(!e||!e.blocks.length)return void s(n);const o={...e,url:n};this.cache.cacheUrl(o),this.triggerEvent("pageLoaded"),i(o)})})}const T=function(t){let{event:e,skipTransition:n}=void 0===t?{}:t;const i=e instanceof PopStateEvent;if(n)return this.triggerEvent("animationSkipped"),[Promise.resolve()];this.triggerEvent("animationOutStart"),document.documentElement.classList.add("is-changing","is-leaving","is-animating"),i&&document.documentElement.classList.add("is-popstate");const s=this.getAnimationPromises("out");return Promise.all(s).then(()=>{this.triggerEvent("animationOutDone")}),s};function H(t){const{url:e}=t;this.shouldIgnoreVisit(e)?window.location.href=e:this.performPageLoad(t)}function R(t){const{url:o,event:r,customTransition:a,history:l="push"}=t??{},c=r instanceof PopStateEvent,u=this.shouldSkipTransition({url:o,event:r});this.triggerEvent("transitionStart",r),this.updateTransition(n(),o,a),null!=a&&document.documentElement.classList.add(`to-${e(a)}`);const h=this.leavePage({event:r,skipTransition:u}),d=this.fetchPage(t);if(!c){const t=o+(this.scrollToElement||"");"replace"===l?s(t):i(t)}this.currentPageUrl=n(),Promise.all([d,...h]).then(t=>{let[e]=t;this.renderPage(e,{event:r,skipTransition:u})}).catch(t=>{void 0!==t&&(this.options.skipPopStateHandling=()=>(window.location=t,!0),history.go(-1))})}const A=function(t){let{blocks:e,title:n}=t;return e.forEach((t,e)=>{document.body.querySelector(`[data-swup="${e}"]`).outerHTML=t}),document.title=n,Promise.resolve()};function $(t,e){const n=this._handlers[t];n?n.push(e):console.warn(`Unsupported event ${t}.`)}function _(t,e){if(t&&e){const n=this._handlers[t];n.includes(e)?this._handlers[t]=n.filter(t=>t!==e):console.warn(`Handler for event '${t}' not found.`)}else t?this._handlers[t]=[]:Object.keys(this._handlers).forEach(t=>{this._handlers[t]=[]})}function I(t,e){this._handlers[t].forEach(t=>{try{t(e)}catch(t){console.error(t)}});const n=new CustomEvent(`swup:${t}`,{detail:t});document.dispatchEvent(n)}const x=function(t){if(t?.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 q(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function D(t){return this.plugins.find(e=>e===t||e.name===t)}const M=function(t,e){let{event:i,skipTransition:o}=void 0===e?{}:e;if(document.documentElement.classList.remove("is-leaving"),!this.isSameResolvedUrl(n(),t.url))return;const{url:r}=p.fromUrl(t.responseURL);this.isSameResolvedUrl(n(),r)||(this.cache.cacheUrl({...t,url:r}),this.currentPageUrl=n(),s(r)),o||document.documentElement.classList.add("is-rendering"),this.triggerEvent("willReplaceContent",i),this.replaceContent(t).then(()=>{this.triggerEvent("contentReplaced",i),this.triggerEvent("pageView",i),this.options.cache||this.cache.empty(),this.enterPage({event:i,skipTransition:o}),this.scrollToElement=null})};function N(t,e,n){this.transition={from:t,to:e,custom:n}}function W(t){let{event:e}=t;return!(!(e instanceof PopStateEvent)||this.options.animateHistoryBrowsing)}class O{constructor(t){void 0===t&&(t={}),this.version="3.1.0",this._handlers={animationInDone:[],animationInStart:[],animationOutDone:[],animationOutStart:[],animationSkipped:[],clickLink:[],contentReplaced:[],disabled:[],enabled:[],openPageInNewTab:[],pageLoaded:[],pageRetrievedFromCache:[],pageView:[],popState:[],samePage:[],samePageWithHash:[],serverError:[],transitionStart:[],transitionEnd:[],willReplaceContent:[]},this.scrollToElement=null,this.options=void 0,this.plugins=[],this.transition={},this.cache=void 0,this.currentPageUrl=n(),this.delegatedListeners={},this.boundPopStateHandler=void 0,this.loadPage=H,this.performPageLoad=R,this.leavePage=T,this.renderPage=M,this.replaceContent=A,this.enterPage=w,this.triggerEvent=I,this.delegateEvent=o,this.on=$,this.off=_,this.updateTransition=N,this.shouldSkipTransition=W,this.getAnimationPromises=k,this.getPageData=L,this.fetchPage=C,this.getAnchorElement=E,this.log=()=>{},this.use=x,this.unuse=q,this.findPlugin=D,this.getCurrentUrl=n,this.cleanupAnimationClasses=f,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',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.options={...this.defaults,...t},this.boundPopStateHandler=this.popStateHandler.bind(this),this.cache=new v(this),this.enable()}enable(){"undefined"!=typeof Promise?(this.delegatedListeners.click=o(this.options.linkSelector,"click",this.linkClickHandler.bind(this)),window.addEventListener("popstate",this.boundPopStateHandler),g(document.documentElement,this.options.containers),this.options.plugins.forEach(t=>this.use(t)),s(),this.triggerEvent("enabled"),document.documentElement.classList.add("swup-enabled"),this.triggerEvent("pageView")):console.warn("Promise is not supported")}destroy(){this.delegatedListeners.click.destroy(),window.removeEventListener("popstate",this.boundPopStateHandler),this.cache.empty(),this.options.plugins.forEach(t=>{this.unuse(t)}),a("[data-swup]").forEach(t=>{t.removeAttribute("data-swup")}),this.off(),this.triggerEvent("disabled"),document.documentElement.classList.remove("swup-enabled")}shouldIgnoreVisit(t,e){let{el:n,event:i}=void 0===e?{}:e;const{origin:s,url:o,hash:r}=p.fromUrl(t);return s!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(o+r,{el:n,event:i})}linkClickHandler(t){const e=t.delegateTarget,{href:i,url:s,hash:o}=p.fromElement(e);if(this.shouldIgnoreVisit(i,{el:e,event:t}))return;if(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return void this.triggerEvent("openPageInNewTab",t);if(0!==t.button)return;if(this.triggerEvent("clickLink",t),t.preventDefault(),!s||s===n())return void this.handleLinkToSamePage(s,o,t);if(this.isSameResolvedUrl(s,n()))return;this.scrollToElement=o||null;const r=e.getAttribute("data-swup-transition")||void 0;let a;const l=e.getAttribute("data-swup-history");l&&["push","replace"].includes(l)&&(a=l),this.performPageLoad({url:s,customTransition:r,history:a})}handleLinkToSamePage(t,e,n){if(e){if(this.triggerEvent("samePageWithHash",n),!E(e))return console.warn(`Element for offset not found (#${e})`);s(t+e)}else this.triggerEvent("samePage",n)}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}popStateHandler(t){if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(n(),this.currentPageUrl))return;const e=t.state?.url??location.href;if(this.shouldIgnoreVisit(e,{event:t}))return;const{url:i,hash:s}=p.fromUrl(e);s?this.scrollToElement=s:t.preventDefault(),this.triggerEvent("popState",t),this.options.animateHistoryBrowsing||(document.documentElement.classList.remove("is-animating"),f()),this.performPageLoad({url:i,event:t})}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{p as Location,e as classify,f as cleanupAnimationClasses,i as createHistoryRecord,O as default,o as delegateEvent,c as escapeCssIdentifier,d as fetch,n as getCurrentUrl,h as getDataFromHtml,g as markSwupElements,l as nextTick,r as query,a as queryAll,u as toMs,s as updateHistoryRecord};
import t from"delegate-it";const e=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",n=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},i=function(t,e){void 0===e&&(e={});const i={url:t=t||n({hash:!0}),random:Math.random(),source:"swup",...e};history.pushState(i,"",t)},s=function(t,e){void 0===t&&(t=null),void 0===e&&(e={}),t=t||n({hash:!0});const i={...history.state,url:t,random:Math.random(),source:"swup",...e};history.replaceState(i,"",t)},o=(e,n,i,s)=>{const o=new AbortController;return t(e,n,i,s),{destroy:()=>o.abort()}},r=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},a=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},l=t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})},c=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,u=t=>1e3*Number(t.slice(0,-1).replace(",",".")),h=(t,e)=>{let n=document.createElement("html");n.innerHTML=t;let i=[];e.forEach(t=>{if(null==r(t,n))return console.warn(`[swup] Container ${t} not found on page.`),null;a(t).length!==a(t,n).length&&console.warn("[swup] Mismatched number of containers found on new page."),a(t).forEach((e,s)=>{a(t,n)[s].setAttribute("data-swup",String(i.length)),i.push(a(t,n)[s].outerHTML)})});const s=r("title",n)?.innerText||"",o=r("body",n)?.className;return n.innerHTML="",n=null,{title:s,pageClass:o,blocks:i,originalContent:t}},d=(t,e)=>{const n={url:window.location.pathname+window.location.search,method:"GET",data:null,headers:{}},{url:i,method:s,headers:o,data:r}={...n,...t},a=new XMLHttpRequest;return a.onreadystatechange=function(){4===a.readyState&&e(a)},a.open(s,i,!0),Object.entries(o).forEach(t=>{let[e,n]=t;a.setRequestHeader(e,n)}),a.send(r),a};class p 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 p(e)}static fromUrl(t){return new p(t)}}const g=(t,e)=>{let n=0;e.forEach(e=>{null==r(e,t)?console.warn(`[swup] Container ${e} not found on page.`):a(e).forEach((i,s)=>{a(e,t)[s].setAttribute("data-swup",String(n)),n++})})},m=t=>/^to-/.test(t)||["is-changing","is-rendering","is-popstate"].includes(t),f=()=>{const t=document.documentElement.className.split(" ").filter(m);document.documentElement.classList.remove(...t)};class v{constructor(t){this.pages={},this.last=null,this.swup=void 0,this.swup=t}getCacheUrl(t){return this.swup.resolveUrl(p.fromUrl(t).url)}cacheUrl(t){t.url=this.getCacheUrl(t.url),t.url in this.pages==0&&(this.pages[t.url]=t),t.responseURL=this.getCacheUrl(t.responseURL),this.last=this.pages[t.url],this.swup.log(`Cache (${Object.keys(this.pages).length})`,this.pages)}getPage(t){return t=this.getCacheUrl(t),this.pages[t]}getCurrentPage(){return this.getPage(n())}exists(t){return(t=this.getCacheUrl(t))in this.pages}empty(){this.pages={},this.last=null,this.swup.log("Cache cleared")}remove(t){delete this.pages[this.getCacheUrl(t)]}}const w=function(t){let{event:e,skipTransition:n}=void 0===t?{}:t;if(n)return this.triggerEvent("transitionEnd",e),this.cleanupAnimationClasses(),[Promise.resolve()];l(()=>{this.triggerEvent("animationInStart"),document.documentElement.classList.remove("is-animating")});const i=this.getAnimationPromises("in");return Promise.all(i).then(()=>{this.triggerEvent("animationInDone"),this.triggerEvent("transitionEnd",e),this.cleanupAnimationClasses()}),i},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)||r(`a[name='${c(t)}']`)||r(`a[name='${c(e)}']`);return n||"top"!==t||(n=document.body),n};let P="transition",S="transitionend",b="animation",U="animationend";function k(t){const e=this.options.animationSelector;if(!1===e)return[Promise.resolve()];const n=a(e,document.body);if(!n.length)return console.warn(`[swup] No elements found matching animationSelector \`${e}\``),[Promise.resolve()];const i=n.map(t=>function(t){const{type:e,timeout:n,propCount:i}=function(t,e){void 0===e&&(e=null);const n=window.getComputedStyle(t),i=`${P}Duration`,s=`${b}Delay`,o=`${b}Duration`,r=n[`${P}Delay`].split(", "),a=(n[i]||"").split(", "),l=y(r,a),c=(n[s]||"").split(", "),u=(n[o]||"").split(", "),h=y(c,u);let d="",p=0,g=0;return"transition"===e?l>0&&(d="transition",p=l,g=a.length):"animation"===e?h>0&&(d="animation",p=h,g=u.length):(p=Math.max(l,h),d=p>0?l>h?"transition":"animation":null,g=d?"transition"===d?a.length:u.length:0),{type:d,timeout:p,propCount:g}}(t);if(e&&n)return new Promise(s=>{const o="transition"===e?S:U,r=performance.now();let a=0;const l=()=>{t.removeEventListener(o,c),s()},c=e=>{if(e.target===t){if(!(t=>[S,U].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()},n+1),t.addEventListener(o,c)})}(t)).filter(Boolean);return i.length?i:(console.warn(`[swup] No CSS animation duration defined on elements matching \`${e}\``),[Promise.resolve()])}function y(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>u(e)+u(t[n])))}void 0===window.ontransitionend&&void 0!==window.onwebkittransitionend&&(P="WebkitTransition",S="webkitTransitionEnd"),void 0===window.onanimationend&&void 0!==window.onwebkitanimationend&&(b="WebkitAnimation",U="webkitAnimationEnd");const L=function(t){const e=h(t.responseText,this.options.containers);return e?{...e,responseURL:t.responseURL||window.location.href}:(console.warn("[swup] Received page is invalid."),null)};function C(t){const e=this.options.requestHeaders,{url:n}=t;return this.cache.exists(n)?(this.triggerEvent("pageRetrievedFromCache"),Promise.resolve(this.cache.getPage(n))):new Promise((i,s)=>{d({...t,headers:e},t=>{if(500===t.status)return this.triggerEvent("serverError"),void s(n);const e=this.getPageData(t);if(!e||!e.blocks.length)return void s(n);const o={...e,url:n};this.cache.cacheUrl(o),this.triggerEvent("pageLoaded"),i(o)})})}const T=function(t){let{event:e,skipTransition:n}=void 0===t?{}:t;const i=e instanceof PopStateEvent;if(n)return this.triggerEvent("animationSkipped"),[Promise.resolve()];this.triggerEvent("animationOutStart"),document.documentElement.classList.add("is-changing","is-leaving","is-animating"),i&&document.documentElement.classList.add("is-popstate");const s=this.getAnimationPromises("out");return Promise.all(s).then(()=>{this.triggerEvent("animationOutDone")}),s};function H(t){const{url:e}=t;this.shouldIgnoreVisit(e)?window.location.href=e:this.performPageLoad(t)}function R(t){const{url:o,event:r,customTransition:a,history:l="push"}=t??{},c=r instanceof PopStateEvent,u=this.shouldSkipTransition({url:o,event:r});this.triggerEvent("transitionStart",r),this.updateTransition(n(),o,a),null!=a&&document.documentElement.classList.add(`to-${e(a)}`);const h=this.leavePage({event:r,skipTransition:u}),d=this.fetchPage(t);if(!c){const t=o+(this.scrollToElement||"");"replace"===l?s(t):i(t)}this.currentPageUrl=n(),Promise.all([d,...h]).then(t=>{let[e]=t;this.renderPage(e,{event:r,skipTransition:u})}).catch(t=>{void 0!==t&&(this.options.skipPopStateHandling=()=>(window.location=t,!0),history.go(-1))})}const A=function(t){let{blocks:e,title:n}=t;return e.forEach((t,e)=>{document.body.querySelector(`[data-swup="${e}"]`).outerHTML=t}),document.title=n,Promise.resolve()};function $(t,e){const n=this._handlers[t];n?n.push(e):console.warn(`Unsupported event ${t}.`)}function _(t,e){if(t&&e){const n=this._handlers[t];n.includes(e)?this._handlers[t]=n.filter(t=>t!==e):console.warn(`Handler for event '${t}' not found.`)}else t?this._handlers[t]=[]:Object.keys(this._handlers).forEach(t=>{this._handlers[t]=[]})}function I(t,e){this._handlers[t].forEach(t=>{try{t(e)}catch(t){console.error(t)}});const n=new CustomEvent(`swup:${t}`,{detail:t});document.dispatchEvent(n)}const x=function(t){if(t?.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 q(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function D(t){return this.plugins.find(e=>e===t||e.name===t)}const M=function(t,e){let{event:i,skipTransition:o}=void 0===e?{}:e;if(document.documentElement.classList.remove("is-leaving"),!this.isSameResolvedUrl(n(),t.url))return;const{url:r}=p.fromUrl(t.responseURL);this.isSameResolvedUrl(n(),r)||(this.cache.cacheUrl({...t,url:r}),this.currentPageUrl=n(),s(r)),o||document.documentElement.classList.add("is-rendering"),this.triggerEvent("willReplaceContent",i),this.replaceContent(t).then(()=>{this.triggerEvent("contentReplaced",i),this.triggerEvent("pageView",i),this.options.cache||this.cache.empty(),this.enterPage({event:i,skipTransition:o}),this.scrollToElement=null})};function N(t,e,n){this.transition={from:t,to:e,custom:n}}function W(t){let{event:e}=t;return!(!(e instanceof PopStateEvent)||this.options.animateHistoryBrowsing)}class O{constructor(t){void 0===t&&(t={}),this.version="3.1.1",this._handlers={animationInDone:[],animationInStart:[],animationOutDone:[],animationOutStart:[],animationSkipped:[],clickLink:[],contentReplaced:[],disabled:[],enabled:[],openPageInNewTab:[],pageLoaded:[],pageRetrievedFromCache:[],pageView:[],popState:[],samePage:[],samePageWithHash:[],serverError:[],transitionStart:[],transitionEnd:[],willReplaceContent:[]},this.scrollToElement=null,this.options=void 0,this.plugins=[],this.transition={},this.cache=void 0,this.currentPageUrl=n(),this.delegatedListeners={},this.boundPopStateHandler=void 0,this.loadPage=H,this.performPageLoad=R,this.leavePage=T,this.renderPage=M,this.replaceContent=A,this.enterPage=w,this.triggerEvent=I,this.delegateEvent=o,this.on=$,this.off=_,this.updateTransition=N,this.shouldSkipTransition=W,this.getAnimationPromises=k,this.getPageData=L,this.fetchPage=C,this.getAnchorElement=E,this.log=()=>{},this.use=x,this.unuse=q,this.findPlugin=D,this.getCurrentUrl=n,this.cleanupAnimationClasses=f,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',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.options={...this.defaults,...t},this.boundPopStateHandler=this.popStateHandler.bind(this),this.cache=new v(this),this.enable()}enable(){"undefined"!=typeof Promise?(this.delegatedListeners.click=o(this.options.linkSelector,"click",this.linkClickHandler.bind(this)),window.addEventListener("popstate",this.boundPopStateHandler),g(document.documentElement,this.options.containers),this.options.plugins.forEach(t=>this.use(t)),s(),this.triggerEvent("enabled"),document.documentElement.classList.add("swup-enabled"),this.triggerEvent("pageView")):console.warn("Promise is not supported")}destroy(){this.delegatedListeners.click.destroy(),window.removeEventListener("popstate",this.boundPopStateHandler),this.cache.empty(),this.options.plugins.forEach(t=>{this.unuse(t)}),a("[data-swup]").forEach(t=>{t.removeAttribute("data-swup")}),this.off(),this.triggerEvent("disabled"),document.documentElement.classList.remove("swup-enabled")}shouldIgnoreVisit(t,e){let{el:n,event:i}=void 0===e?{}:e;const{origin:s,url:o,hash:r}=p.fromUrl(t);return s!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(o+r,{el:n,event:i})}linkClickHandler(t){const e=t.delegateTarget,{href:i,url:s,hash:o}=p.fromElement(e);if(this.shouldIgnoreVisit(i,{el:e,event:t}))return;if(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return void this.triggerEvent("openPageInNewTab",t);if(0!==t.button)return;if(this.triggerEvent("clickLink",t),t.preventDefault(),!s||s===n())return void this.handleLinkToSamePage(s,o,t);if(this.isSameResolvedUrl(s,n()))return;this.scrollToElement=o||null;const r=e.getAttribute("data-swup-transition")||void 0;let a;const l=e.getAttribute("data-swup-history");l&&["push","replace"].includes(l)&&(a=l),this.performPageLoad({url:s,customTransition:r,history:a})}handleLinkToSamePage(t,e,n){if(e){if(this.triggerEvent("samePageWithHash",n),!E(e))return console.warn(`Element for offset not found (#${e})`);s(t+e)}else this.triggerEvent("samePage",n)}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}popStateHandler(t){if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(n(),this.currentPageUrl))return;const e=t.state?.url??location.href;if(this.shouldIgnoreVisit(e,{event:t}))return;const{url:i,hash:s}=p.fromUrl(e);s?this.scrollToElement=s:t.preventDefault(),this.triggerEvent("popState",t),this.options.animateHistoryBrowsing||(document.documentElement.classList.remove("is-animating"),f()),this.performPageLoad({url:i,event:t})}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{p as Location,e as classify,f as cleanupAnimationClasses,i as createHistoryRecord,O as default,o as delegateEvent,c as escapeCssIdentifier,d as fetch,n as getCurrentUrl,h as getDataFromHtml,g as markSwupElements,l as nextTick,r as query,a as queryAll,u as toMs,s 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=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},e=function(e,n){void 0===e&&(e=null),void 0===n&&(n={}),e=e||t({hash:!0});const i={...history.state,url:e,random:Math.random(),source:"swup",...n};history.replaceState(i,"",e)},n=new WeakMap;function i(t,e,i,s){if(!t&&!n.has(e))return!1;const o=n.get(e)??new WeakMap;n.set(e,o);const r=o.get(i)??new Set;o.set(i,r);const a=r.has(s);return t?r.add(s):r.delete(s),a&&t}const s=(t,e,n,s)=>{const o=new AbortController;return function(t,e,n,s={}){const{signal:o,base:r=document}=s;if(o?.aborted)return;const{once:a,...l}=s,c=r instanceof Document?r.documentElement:r,u=Boolean("object"==typeof s?s.capture:s),h=s=>{const o=function(t,e){let n=t.target;if(n instanceof Text&&(n=n.parentElement),n instanceof Element&&t.currentTarget instanceof Element){const i=n.closest(e);if(i&&t.currentTarget.contains(i))return i}}(s,t);if(o){const t=Object.assign(s,{delegateTarget:o});n.call(c,t),a&&(c.removeEventListener(e,h,l),i(!1,c,n,d))}},d=JSON.stringify({selector:t,type:e,capture:u});i(!0,c,n,d)||c.addEventListener(e,h,l),o?.addEventListener("abort",()=>{i(!1,c,n,d)})}(t,e,n,s),{destroy:()=>o.abort()}},o=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},r=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},a=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,l=t=>1e3*Number(t.slice(0,-1).replace(",","."));class c extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href");return new c(e)}static fromUrl(t){return new c(t)}}const u=t=>/^to-/.test(t)||["is-changing","is-rendering","is-popstate"].includes(t),h=()=>{const t=document.documentElement.className.split(" ").filter(u);document.documentElement.classList.remove(...t)};class d{constructor(t){this.pages={},this.last=null,this.swup=void 0,this.swup=t}getCacheUrl(t){return this.swup.resolveUrl(c.fromUrl(t).url)}cacheUrl(t){t.url=this.getCacheUrl(t.url),t.url in this.pages==0&&(this.pages[t.url]=t),t.responseURL=this.getCacheUrl(t.responseURL),this.last=this.pages[t.url],this.swup.log(`Cache (${Object.keys(this.pages).length})`,this.pages)}getPage(t){return t=this.getCacheUrl(t),this.pages[t]}getCurrentPage(){return this.getPage(t())}exists(t){return(t=this.getCacheUrl(t))in this.pages}empty(){this.pages={},this.last=null,this.swup.log("Cache cleared")}remove(t){delete this.pages[this.getCacheUrl(t)]}}const p=function(t){let{event:e,skipTransition:n}=void 0===t?{}:t;if(n)return this.triggerEvent("transitionEnd",e),this.cleanupAnimationClasses(),[Promise.resolve()];var i;i=()=>{this.triggerEvent("animationInStart"),document.documentElement.classList.remove("is-animating")},requestAnimationFrame(()=>{requestAnimationFrame(()=>{i()})});const s=this.getAnimationPromises("in");return Promise.all(s).then(()=>{this.triggerEvent("animationInDone"),this.triggerEvent("transitionEnd",e),this.cleanupAnimationClasses()}),s},g=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);return document.getElementById(t)||document.getElementById(e)||o(`a[name='${a(t)}']`)||o(`a[name='${a(e)}']`)};let m="transition",f="transitionend",v="animation",w="animationend";function E(t){const e=this.options.animationSelector;if(!1===e)return[Promise.resolve()];const n=r(e,document.body);if(!n.length)return console.warn(`[swup] No elements found matching animationSelector \`${e}\``),[Promise.resolve()];const i=n.map(t=>function(t){const{type:e,timeout:n,propCount:i}=function(t,e){void 0===e&&(e=null);const n=window.getComputedStyle(t),i=`${m}Duration`,s=`${v}Delay`,o=`${v}Duration`,r=n[`${m}Delay`].split(", "),a=(n[i]||"").split(", "),l=P(r,a),c=(n[s]||"").split(", "),u=(n[o]||"").split(", "),h=P(c,u);let d="",p=0,g=0;return"transition"===e?l>0&&(d="transition",p=l,g=a.length):"animation"===e?h>0&&(d="animation",p=h,g=u.length):(p=Math.max(l,h),d=p>0?l>h?"transition":"animation":null,g=d?"transition"===d?a.length:u.length:0),{type:d,timeout:p,propCount:g}}(t);if(e&&n)return new Promise(s=>{const o="transition"===e?f:w,r=performance.now();let a=0;const l=()=>{t.removeEventListener(o,c),s()},c=e=>{if(e.target===t){if(!(t=>[f,w].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()},n+1),t.addEventListener(o,c)})}(t)).filter(Boolean);return i.length?i:(console.warn(`[swup] No CSS animation duration defined on elements matching \`${e}\``),[Promise.resolve()])}function P(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>l(e)+l(t[n])))}void 0===window.ontransitionend&&void 0!==window.onwebkittransitionend&&(m="WebkitTransition",f="webkitTransitionEnd"),void 0===window.onanimationend&&void 0!==window.onwebkitanimationend&&(v="WebkitAnimation",w="webkitAnimationEnd");const S=function(t){const e=((t,e)=>{let n=document.createElement("html");n.innerHTML=t;let i=[];e.forEach(t=>{if(null==o(t,n))return console.warn(`[swup] Container ${t} not found on page.`),null;r(t).length!==r(t,n).length&&console.warn("[swup] Mismatched number of containers found on new page."),r(t).forEach((e,s)=>{r(t,n)[s].setAttribute("data-swup",String(i.length)),i.push(r(t,n)[s].outerHTML)})});const s=o("title",n)?.innerText||"",a=o("body",n)?.className;return n.innerHTML="",n=null,{title:s,pageClass:a,blocks:i,originalContent:t}})(t.responseText,this.options.containers);return e?{...e,responseURL:t.responseURL||window.location.href}:(console.warn("[swup] Received page is invalid."),null)};function b(t){const e=this.options.requestHeaders,{url:n}=t;return this.cache.exists(n)?(this.triggerEvent("pageRetrievedFromCache"),Promise.resolve(this.cache.getPage(n))):new Promise((i,s)=>{((t,e)=>{const n={url:window.location.pathname+window.location.search,method:"GET",data:null,headers:{}},{url:i,method:s,headers:o,data:r}={...n,...t},a=new XMLHttpRequest;a.onreadystatechange=function(){4===a.readyState&&e(a)},a.open(s,i,!0),Object.entries(o).forEach(t=>{let[e,n]=t;a.setRequestHeader(e,n)}),a.send(r)})({...t,headers:e},t=>{if(500===t.status)return this.triggerEvent("serverError"),void s(n);const e=this.getPageData(t);if(!e||!e.blocks.length)return void s(n);const o={...e,url:n};this.cache.cacheUrl(o),this.triggerEvent("pageLoaded"),i(o)})})}const y=function(t){let{event:e,skipTransition:n}=void 0===t?{}:t;const i=e instanceof PopStateEvent;if(n)return this.triggerEvent("animationSkipped"),[Promise.resolve()];this.triggerEvent("animationOutStart"),document.documentElement.classList.add("is-changing","is-leaving","is-animating"),i&&document.documentElement.classList.add("is-popstate");const s=this.getAnimationPromises("out");return Promise.all(s).then(()=>{this.triggerEvent("animationOutDone")}),s};function k(t){const{url:e}=t;this.shouldIgnoreVisit(e)?window.location.href=e:this.performPageLoad(t)}function U(n){const{url:i,event:s,customTransition:o,history:r="push"}=n??{},a=s instanceof PopStateEvent,l=this.shouldSkipTransition({url:i,event:s});var c;this.triggerEvent("transitionStart",s),this.updateTransition(t(),i,o),null!=o&&document.documentElement.classList.add(`to-${c=o,String(c).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||""}`);const u=this.leavePage({event:s,skipTransition:l}),h=this.fetchPage(n);if(!a){const n=i+(this.scrollToElement||"");"replace"===r?e(n):function(e,n){void 0===n&&(n={});const i={url:e=e||t({hash:!0}),random:Math.random(),source:"swup",...n};history.pushState(i,"",e)}(n)}this.currentPageUrl=t(),Promise.all([h,...u]).then(t=>{let[e]=t;this.renderPage(e,{event:s,skipTransition:l})}).catch(t=>{void 0!==t&&(this.options.skipPopStateHandling=()=>(window.location=t,!0),history.go(-1))})}const L=function(t){let{blocks:e,title:n}=t;return e.forEach((t,e)=>{document.body.querySelector(`[data-swup="${e}"]`).outerHTML=t}),document.title=n,Promise.resolve()};function T(t,e){const n=this._handlers[t];n?n.push(e):console.warn(`Unsupported event ${t}.`)}function C(t,e){if(t&&e){const n=this._handlers[t];n.includes(e)?this._handlers[t]=n.filter(t=>t!==e):console.warn(`Handler for event '${t}' not found.`)}else t?this._handlers[t]=[]:Object.keys(this._handlers).forEach(t=>{this._handlers[t]=[]})}function H(t,e){this._handlers[t].forEach(t=>{try{t(e)}catch(t){console.error(t)}});const n=new CustomEvent(`swup:${t}`,{detail:t});document.dispatchEvent(n)}const R=function(t){if(t?.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 A(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)}const _=function(n,i){let{event:s,skipTransition:o}=void 0===i?{}:i;if(document.documentElement.classList.remove("is-leaving"),!this.isSameResolvedUrl(t(),n.url))return;const{url:r}=c.fromUrl(n.responseURL);this.isSameResolvedUrl(t(),r)||(this.cache.cacheUrl({...n,url:r}),this.currentPageUrl=t(),e(r)),o||document.documentElement.classList.add("is-rendering"),this.triggerEvent("willReplaceContent",s),this.replaceContent(n).then(()=>{this.triggerEvent("contentReplaced",s),this.triggerEvent("pageView",s),this.options.cache||this.cache.empty(),this.enterPage({event:s,skipTransition:o}),this.scrollToElement=null})};function x(t,e,n){this.transition={from:t,to:e,custom:n}}function I(t){let{event:e}=t;return!(!(e instanceof PopStateEvent)||this.options.animateHistoryBrowsing)}return class{constructor(e){void 0===e&&(e={}),this.version="3.1.0",this._handlers={animationInDone:[],animationInStart:[],animationOutDone:[],animationOutStart:[],animationSkipped:[],clickLink:[],contentReplaced:[],disabled:[],enabled:[],openPageInNewTab:[],pageLoaded:[],pageRetrievedFromCache:[],pageView:[],popState:[],samePage:[],samePageWithHash:[],serverError:[],transitionStart:[],transitionEnd:[],willReplaceContent:[]},this.scrollToElement=null,this.options=void 0,this.plugins=[],this.transition={},this.cache=void 0,this.currentPageUrl=t(),this.delegatedListeners={},this.boundPopStateHandler=void 0,this.loadPage=k,this.performPageLoad=U,this.leavePage=y,this.renderPage=_,this.replaceContent=L,this.enterPage=p,this.triggerEvent=H,this.delegateEvent=s,this.on=T,this.off=C,this.updateTransition=x,this.shouldSkipTransition=I,this.getAnimationPromises=E,this.getPageData=S,this.fetchPage=b,this.getAnchorElement=g,this.log=()=>{},this.use=R,this.unuse=A,this.findPlugin=$,this.getCurrentUrl=t,this.cleanupAnimationClasses=h,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',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.options={...this.defaults,...e},this.boundPopStateHandler=this.popStateHandler.bind(this),this.cache=new d(this),this.enable()}enable(){"undefined"!=typeof Promise?(this.delegatedListeners.click=s(this.options.linkSelector,"click",this.linkClickHandler.bind(this)),window.addEventListener("popstate",this.boundPopStateHandler),((t,e)=>{let n=0;this.options.containers.forEach(e=>{null==o(e,t)?console.warn(`[swup] Container ${e} not found on page.`):r(e).forEach((i,s)=>{r(e,t)[s].setAttribute("data-swup",String(n)),n++})})})(document.documentElement),this.options.plugins.forEach(t=>this.use(t)),e(),this.triggerEvent("enabled"),document.documentElement.classList.add("swup-enabled"),this.triggerEvent("pageView")):console.warn("Promise is not supported")}destroy(){this.delegatedListeners.click.destroy(),window.removeEventListener("popstate",this.boundPopStateHandler),this.cache.empty(),this.options.plugins.forEach(t=>{this.unuse(t)}),r("[data-swup]").forEach(t=>{t.removeAttribute("data-swup")}),this.off(),this.triggerEvent("disabled"),document.documentElement.classList.remove("swup-enabled")}shouldIgnoreVisit(t,e){let{el:n,event:i}=void 0===e?{}:e;const{origin:s,url:o,hash:r}=c.fromUrl(t);return s!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(o+r,{el:n,event:i})}linkClickHandler(e){const n=e.delegateTarget,{href:i,url:s,hash:o}=c.fromElement(n);if(this.shouldIgnoreVisit(i,{el:n,event:e}))return;if(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return void this.triggerEvent("openPageInNewTab",e);if(0!==e.button)return;if(this.triggerEvent("clickLink",e),e.preventDefault(),!s||s===t())return void this.handleLinkToSamePage(s,o,e);if(this.isSameResolvedUrl(s,t()))return;this.scrollToElement=o||null;const r=n.getAttribute("data-swup-transition")||void 0;let a;const l=n.getAttribute("data-swup-history");l&&["push","replace"].includes(l)&&(a=l),this.performPageLoad({url:s,customTransition:r,history:a})}handleLinkToSamePage(t,n,i){if(n){if(this.triggerEvent("samePageWithHash",i),!g(n))return console.warn(`Element for offset not found (#${n})`);e(t+n)}else this.triggerEvent("samePage",i)}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}popStateHandler(e){if(this.options.skipPopStateHandling(e))return;if(this.isSameResolvedUrl(t(),this.currentPageUrl))return;const n=e.state?.url??location.href;if(this.shouldIgnoreVisit(n,{event:e}))return;const{url:i,hash:s}=c.fromUrl(n);s?this.scrollToElement=s:e.preventDefault(),this.triggerEvent("popState",e),this.options.animateHistoryBrowsing||(document.documentElement.classList.remove("is-animating"),h()),this.performPageLoad({url:i,event:e})}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=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},e=function(e,n){void 0===e&&(e=null),void 0===n&&(n={}),e=e||t({hash:!0});const i={...history.state,url:e,random:Math.random(),source:"swup",...n};history.replaceState(i,"",e)},n=new WeakMap;function i(t,e,i,s){if(!t&&!n.has(e))return!1;const o=n.get(e)??new WeakMap;n.set(e,o);const r=o.get(i)??new Set;o.set(i,r);const a=r.has(s);return t?r.add(s):r.delete(s),a&&t}const s=(t,e,n,s)=>{const o=new AbortController;return function(t,e,n,s={}){const{signal:o,base:r=document}=s;if(o?.aborted)return;const{once:a,...l}=s,c=r instanceof Document?r.documentElement:r,u=Boolean("object"==typeof s?s.capture:s),h=s=>{const o=function(t,e){let n=t.target;if(n instanceof Text&&(n=n.parentElement),n instanceof Element&&t.currentTarget instanceof Element){const i=n.closest(e);if(i&&t.currentTarget.contains(i))return i}}(s,t);if(o){const t=Object.assign(s,{delegateTarget:o});n.call(c,t),a&&(c.removeEventListener(e,h,l),i(!1,c,n,d))}},d=JSON.stringify({selector:t,type:e,capture:u});i(!0,c,n,d)||c.addEventListener(e,h,l),o?.addEventListener("abort",()=>{i(!1,c,n,d)})}(t,e,n,s),{destroy:()=>o.abort()}},o=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},r=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},a=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,l=t=>1e3*Number(t.slice(0,-1).replace(",","."));class c extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href");return new c(e)}static fromUrl(t){return new c(t)}}const u=t=>/^to-/.test(t)||["is-changing","is-rendering","is-popstate"].includes(t),h=()=>{const t=document.documentElement.className.split(" ").filter(u);document.documentElement.classList.remove(...t)};class d{constructor(t){this.pages={},this.last=null,this.swup=void 0,this.swup=t}getCacheUrl(t){return this.swup.resolveUrl(c.fromUrl(t).url)}cacheUrl(t){t.url=this.getCacheUrl(t.url),t.url in this.pages==0&&(this.pages[t.url]=t),t.responseURL=this.getCacheUrl(t.responseURL),this.last=this.pages[t.url],this.swup.log(`Cache (${Object.keys(this.pages).length})`,this.pages)}getPage(t){return t=this.getCacheUrl(t),this.pages[t]}getCurrentPage(){return this.getPage(t())}exists(t){return(t=this.getCacheUrl(t))in this.pages}empty(){this.pages={},this.last=null,this.swup.log("Cache cleared")}remove(t){delete this.pages[this.getCacheUrl(t)]}}const p=function(t){let{event:e,skipTransition:n}=void 0===t?{}:t;if(n)return this.triggerEvent("transitionEnd",e),this.cleanupAnimationClasses(),[Promise.resolve()];var i;i=()=>{this.triggerEvent("animationInStart"),document.documentElement.classList.remove("is-animating")},requestAnimationFrame(()=>{requestAnimationFrame(()=>{i()})});const s=this.getAnimationPromises("in");return Promise.all(s).then(()=>{this.triggerEvent("animationInDone"),this.triggerEvent("transitionEnd",e),this.cleanupAnimationClasses()}),s},g=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)||o(`a[name='${a(t)}']`)||o(`a[name='${a(e)}']`);return n||"top"!==t||(n=document.body),n};let m="transition",f="transitionend",v="animation",w="animationend";function E(t){const e=this.options.animationSelector;if(!1===e)return[Promise.resolve()];const n=r(e,document.body);if(!n.length)return console.warn(`[swup] No elements found matching animationSelector \`${e}\``),[Promise.resolve()];const i=n.map(t=>function(t){const{type:e,timeout:n,propCount:i}=function(t,e){void 0===e&&(e=null);const n=window.getComputedStyle(t),i=`${m}Duration`,s=`${v}Delay`,o=`${v}Duration`,r=n[`${m}Delay`].split(", "),a=(n[i]||"").split(", "),l=P(r,a),c=(n[s]||"").split(", "),u=(n[o]||"").split(", "),h=P(c,u);let d="",p=0,g=0;return"transition"===e?l>0&&(d="transition",p=l,g=a.length):"animation"===e?h>0&&(d="animation",p=h,g=u.length):(p=Math.max(l,h),d=p>0?l>h?"transition":"animation":null,g=d?"transition"===d?a.length:u.length:0),{type:d,timeout:p,propCount:g}}(t);if(e&&n)return new Promise(s=>{const o="transition"===e?f:w,r=performance.now();let a=0;const l=()=>{t.removeEventListener(o,c),s()},c=e=>{if(e.target===t){if(!(t=>[f,w].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()},n+1),t.addEventListener(o,c)})}(t)).filter(Boolean);return i.length?i:(console.warn(`[swup] No CSS animation duration defined on elements matching \`${e}\``),[Promise.resolve()])}function P(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>l(e)+l(t[n])))}void 0===window.ontransitionend&&void 0!==window.onwebkittransitionend&&(m="WebkitTransition",f="webkitTransitionEnd"),void 0===window.onanimationend&&void 0!==window.onwebkitanimationend&&(v="WebkitAnimation",w="webkitAnimationEnd");const S=function(t){const e=((t,e)=>{let n=document.createElement("html");n.innerHTML=t;let i=[];e.forEach(t=>{if(null==o(t,n))return console.warn(`[swup] Container ${t} not found on page.`),null;r(t).length!==r(t,n).length&&console.warn("[swup] Mismatched number of containers found on new page."),r(t).forEach((e,s)=>{r(t,n)[s].setAttribute("data-swup",String(i.length)),i.push(r(t,n)[s].outerHTML)})});const s=o("title",n)?.innerText||"",a=o("body",n)?.className;return n.innerHTML="",n=null,{title:s,pageClass:a,blocks:i,originalContent:t}})(t.responseText,this.options.containers);return e?{...e,responseURL:t.responseURL||window.location.href}:(console.warn("[swup] Received page is invalid."),null)};function b(t){const e=this.options.requestHeaders,{url:n}=t;return this.cache.exists(n)?(this.triggerEvent("pageRetrievedFromCache"),Promise.resolve(this.cache.getPage(n))):new Promise((i,s)=>{((t,e)=>{const n={url:window.location.pathname+window.location.search,method:"GET",data:null,headers:{}},{url:i,method:s,headers:o,data:r}={...n,...t},a=new XMLHttpRequest;a.onreadystatechange=function(){4===a.readyState&&e(a)},a.open(s,i,!0),Object.entries(o).forEach(t=>{let[e,n]=t;a.setRequestHeader(e,n)}),a.send(r)})({...t,headers:e},t=>{if(500===t.status)return this.triggerEvent("serverError"),void s(n);const e=this.getPageData(t);if(!e||!e.blocks.length)return void s(n);const o={...e,url:n};this.cache.cacheUrl(o),this.triggerEvent("pageLoaded"),i(o)})})}const y=function(t){let{event:e,skipTransition:n}=void 0===t?{}:t;const i=e instanceof PopStateEvent;if(n)return this.triggerEvent("animationSkipped"),[Promise.resolve()];this.triggerEvent("animationOutStart"),document.documentElement.classList.add("is-changing","is-leaving","is-animating"),i&&document.documentElement.classList.add("is-popstate");const s=this.getAnimationPromises("out");return Promise.all(s).then(()=>{this.triggerEvent("animationOutDone")}),s};function k(t){const{url:e}=t;this.shouldIgnoreVisit(e)?window.location.href=e:this.performPageLoad(t)}function U(n){const{url:i,event:s,customTransition:o,history:r="push"}=n??{},a=s instanceof PopStateEvent,l=this.shouldSkipTransition({url:i,event:s});var c;this.triggerEvent("transitionStart",s),this.updateTransition(t(),i,o),null!=o&&document.documentElement.classList.add(`to-${c=o,String(c).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||""}`);const u=this.leavePage({event:s,skipTransition:l}),h=this.fetchPage(n);if(!a){const n=i+(this.scrollToElement||"");"replace"===r?e(n):function(e,n){void 0===n&&(n={});const i={url:e=e||t({hash:!0}),random:Math.random(),source:"swup",...n};history.pushState(i,"",e)}(n)}this.currentPageUrl=t(),Promise.all([h,...u]).then(t=>{let[e]=t;this.renderPage(e,{event:s,skipTransition:l})}).catch(t=>{void 0!==t&&(this.options.skipPopStateHandling=()=>(window.location=t,!0),history.go(-1))})}const L=function(t){let{blocks:e,title:n}=t;return e.forEach((t,e)=>{document.body.querySelector(`[data-swup="${e}"]`).outerHTML=t}),document.title=n,Promise.resolve()};function T(t,e){const n=this._handlers[t];n?n.push(e):console.warn(`Unsupported event ${t}.`)}function C(t,e){if(t&&e){const n=this._handlers[t];n.includes(e)?this._handlers[t]=n.filter(t=>t!==e):console.warn(`Handler for event '${t}' not found.`)}else t?this._handlers[t]=[]:Object.keys(this._handlers).forEach(t=>{this._handlers[t]=[]})}function H(t,e){this._handlers[t].forEach(t=>{try{t(e)}catch(t){console.error(t)}});const n=new CustomEvent(`swup:${t}`,{detail:t});document.dispatchEvent(n)}const R=function(t){if(t?.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 A(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)}const _=function(n,i){let{event:s,skipTransition:o}=void 0===i?{}:i;if(document.documentElement.classList.remove("is-leaving"),!this.isSameResolvedUrl(t(),n.url))return;const{url:r}=c.fromUrl(n.responseURL);this.isSameResolvedUrl(t(),r)||(this.cache.cacheUrl({...n,url:r}),this.currentPageUrl=t(),e(r)),o||document.documentElement.classList.add("is-rendering"),this.triggerEvent("willReplaceContent",s),this.replaceContent(n).then(()=>{this.triggerEvent("contentReplaced",s),this.triggerEvent("pageView",s),this.options.cache||this.cache.empty(),this.enterPage({event:s,skipTransition:o}),this.scrollToElement=null})};function x(t,e,n){this.transition={from:t,to:e,custom:n}}function I(t){let{event:e}=t;return!(!(e instanceof PopStateEvent)||this.options.animateHistoryBrowsing)}return class{constructor(e){void 0===e&&(e={}),this.version="3.1.1",this._handlers={animationInDone:[],animationInStart:[],animationOutDone:[],animationOutStart:[],animationSkipped:[],clickLink:[],contentReplaced:[],disabled:[],enabled:[],openPageInNewTab:[],pageLoaded:[],pageRetrievedFromCache:[],pageView:[],popState:[],samePage:[],samePageWithHash:[],serverError:[],transitionStart:[],transitionEnd:[],willReplaceContent:[]},this.scrollToElement=null,this.options=void 0,this.plugins=[],this.transition={},this.cache=void 0,this.currentPageUrl=t(),this.delegatedListeners={},this.boundPopStateHandler=void 0,this.loadPage=k,this.performPageLoad=U,this.leavePage=y,this.renderPage=_,this.replaceContent=L,this.enterPage=p,this.triggerEvent=H,this.delegateEvent=s,this.on=T,this.off=C,this.updateTransition=x,this.shouldSkipTransition=I,this.getAnimationPromises=E,this.getPageData=S,this.fetchPage=b,this.getAnchorElement=g,this.log=()=>{},this.use=R,this.unuse=A,this.findPlugin=$,this.getCurrentUrl=t,this.cleanupAnimationClasses=h,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',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.options={...this.defaults,...e},this.boundPopStateHandler=this.popStateHandler.bind(this),this.cache=new d(this),this.enable()}enable(){"undefined"!=typeof Promise?(this.delegatedListeners.click=s(this.options.linkSelector,"click",this.linkClickHandler.bind(this)),window.addEventListener("popstate",this.boundPopStateHandler),((t,e)=>{let n=0;this.options.containers.forEach(e=>{null==o(e,t)?console.warn(`[swup] Container ${e} not found on page.`):r(e).forEach((i,s)=>{r(e,t)[s].setAttribute("data-swup",String(n)),n++})})})(document.documentElement),this.options.plugins.forEach(t=>this.use(t)),e(),this.triggerEvent("enabled"),document.documentElement.classList.add("swup-enabled"),this.triggerEvent("pageView")):console.warn("Promise is not supported")}destroy(){this.delegatedListeners.click.destroy(),window.removeEventListener("popstate",this.boundPopStateHandler),this.cache.empty(),this.options.plugins.forEach(t=>{this.unuse(t)}),r("[data-swup]").forEach(t=>{t.removeAttribute("data-swup")}),this.off(),this.triggerEvent("disabled"),document.documentElement.classList.remove("swup-enabled")}shouldIgnoreVisit(t,e){let{el:n,event:i}=void 0===e?{}:e;const{origin:s,url:o,hash:r}=c.fromUrl(t);return s!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(o+r,{el:n,event:i})}linkClickHandler(e){const n=e.delegateTarget,{href:i,url:s,hash:o}=c.fromElement(n);if(this.shouldIgnoreVisit(i,{el:n,event:e}))return;if(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return void this.triggerEvent("openPageInNewTab",e);if(0!==e.button)return;if(this.triggerEvent("clickLink",e),e.preventDefault(),!s||s===t())return void this.handleLinkToSamePage(s,o,e);if(this.isSameResolvedUrl(s,t()))return;this.scrollToElement=o||null;const r=n.getAttribute("data-swup-transition")||void 0;let a;const l=n.getAttribute("data-swup-history");l&&["push","replace"].includes(l)&&(a=l),this.performPageLoad({url:s,customTransition:r,history:a})}handleLinkToSamePage(t,n,i){if(n){if(this.triggerEvent("samePageWithHash",i),!g(n))return console.warn(`Element for offset not found (#${n})`);e(t+n)}else this.triggerEvent("samePage",i)}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}popStateHandler(e){if(this.options.skipPopStateHandling(e))return;if(this.isSameResolvedUrl(t(),this.currentPageUrl))return;const n=e.state?.url??location.href;if(this.shouldIgnoreVisit(n,{event:e}))return;const{url:i,hash:s}=c.fromUrl(n);s?this.scrollToElement=s:e.preventDefault(),this.triggerEvent("popState",e),this.options.animateHistoryBrowsing||(document.documentElement.classList.remove("is-animating"),h()),this.performPageLoad({url:i,event:e})}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)}}});
//# sourceMappingURL=Swup.umd.js.map
{
"name": "swup",
"amdName": "Swup",
"version": "3.1.0",
"version": "3.1.1",
"description": "Complete, flexible, extensible, and easy-to-use page transition library for your server-side rendered website.",

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

@@ -20,9 +20,13 @@ import { escapeCssIdentifier as escape, query } from '../utils.js';

const decoded = decodeURIComponent(hash);
return (
let element =
document.getElementById(hash) ||
document.getElementById(decoded) ||
query(`a[name='${escape(hash)}']`) ||
query(`a[name='${escape(decoded)}']`)
);
query(`a[name='${escape(decoded)}']`);
if (!element && hash === 'top') {
element = document.body;
}
return element;
};

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