swup 4.9.1 → 4.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Swup.cjs +1 -1
- package/dist/Swup.modern.js +1 -1
- package/dist/Swup.module.js +1 -1
- package/dist/Swup.umd.js +1 -1
- package/dist/types/Swup.d.ts.map +1 -0
- package/dist/types/config/version.d.ts.map +1 -0
- package/dist/types/helpers/Location.d.ts.map +1 -0
- package/dist/types/helpers/classify.d.ts.map +1 -0
- package/dist/types/helpers/delegateEvent.d.ts.map +1 -0
- package/dist/types/helpers/getCurrentUrl.d.ts.map +1 -0
- package/dist/types/helpers/history.d.ts.map +1 -0
- package/dist/types/helpers/matchPath.d.ts.map +1 -0
- package/dist/types/helpers.d.ts.map +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/modules/Cache.d.ts.map +1 -0
- package/dist/types/modules/Classes.d.ts.map +1 -0
- package/dist/types/modules/Hooks.d.ts.map +1 -0
- package/dist/types/modules/Visit.d.ts.map +1 -0
- package/dist/types/modules/animatePageIn.d.ts.map +1 -0
- package/dist/types/modules/animatePageOut.d.ts.map +1 -0
- package/dist/types/modules/awaitAnimations.d.ts.map +1 -0
- package/dist/types/modules/fetchPage.d.ts.map +1 -0
- package/dist/types/modules/getAnchorElement.d.ts.map +1 -0
- package/dist/types/modules/navigate.d.ts.map +1 -0
- package/dist/types/modules/plugins.d.ts.map +1 -0
- package/dist/types/modules/renderPage.d.ts.map +1 -0
- package/dist/types/modules/replaceContent.d.ts.map +1 -0
- package/dist/types/modules/resolveUrl.d.ts.map +1 -0
- package/dist/types/modules/scrollToContent.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +2 -2
- package/dist/types/src/Swup.d.ts.map +0 -1
- package/dist/types/src/config/version.d.ts.map +0 -1
- package/dist/types/src/helpers/Location.d.ts.map +0 -1
- package/dist/types/src/helpers/classify.d.ts.map +0 -1
- package/dist/types/src/helpers/delegateEvent.d.ts.map +0 -1
- package/dist/types/src/helpers/getCurrentUrl.d.ts.map +0 -1
- package/dist/types/src/helpers/history.d.ts.map +0 -1
- package/dist/types/src/helpers/matchPath.d.ts.map +0 -1
- package/dist/types/src/helpers.d.ts.map +0 -1
- package/dist/types/src/index.d.ts.map +0 -1
- package/dist/types/src/modules/Cache.d.ts.map +0 -1
- package/dist/types/src/modules/Classes.d.ts.map +0 -1
- package/dist/types/src/modules/Hooks.d.ts.map +0 -1
- package/dist/types/src/modules/Visit.d.ts.map +0 -1
- package/dist/types/src/modules/animatePageIn.d.ts.map +0 -1
- package/dist/types/src/modules/animatePageOut.d.ts.map +0 -1
- package/dist/types/src/modules/awaitAnimations.d.ts.map +0 -1
- package/dist/types/src/modules/fetchPage.d.ts.map +0 -1
- package/dist/types/src/modules/getAnchorElement.d.ts.map +0 -1
- package/dist/types/src/modules/navigate.d.ts.map +0 -1
- package/dist/types/src/modules/plugins.d.ts.map +0 -1
- package/dist/types/src/modules/renderPage.d.ts.map +0 -1
- package/dist/types/src/modules/replaceContent.d.ts.map +0 -1
- package/dist/types/src/modules/resolveUrl.d.ts.map +0 -1
- package/dist/types/src/modules/scrollToContent.d.ts.map +0 -1
- package/dist/types/src/utils/index.d.ts.map +0 -1
- package/dist/types/src/utils.d.ts.map +0 -1
- package/dist/types/tests/config/playwright.config.d.ts +0 -6
- package/dist/types/tests/config/playwright.config.d.ts.map +0 -1
- package/dist/types/tests/config/vitest.config.d.ts +0 -7
- package/dist/types/tests/config/vitest.config.d.ts.map +0 -1
- package/dist/types/tests/config/vitest.setup.d.ts +0 -2
- package/dist/types/tests/config/vitest.setup.d.ts.map +0 -1
- package/dist/types/tests/functional/alpinejs.spec.d.ts +0 -2
- package/dist/types/tests/functional/alpinejs.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/animation-classes.spec.d.ts +0 -2
- package/dist/types/tests/functional/animation-classes.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/animation-timing.spec.d.ts +0 -2
- package/dist/types/tests/functional/animation-timing.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/api-navigation.spec.d.ts +0 -2
- package/dist/types/tests/functional/api-navigation.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/cache.spec.d.ts +0 -2
- package/dist/types/tests/functional/cache.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/containers.spec.d.ts +0 -2
- package/dist/types/tests/functional/containers.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/events.spec.d.ts +0 -2
- package/dist/types/tests/functional/events.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/history.spec.d.ts +0 -2
- package/dist/types/tests/functional/history.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/ignore-visit.spec.d.ts +0 -2
- package/dist/types/tests/functional/ignore-visit.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/link-resolution.spec.d.ts +0 -2
- package/dist/types/tests/functional/link-resolution.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/link-selector.spec.d.ts +0 -2
- package/dist/types/tests/functional/link-selector.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/markup.spec.d.ts +0 -2
- package/dist/types/tests/functional/markup.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/native-mode.spec.d.ts +0 -2
- package/dist/types/tests/functional/native-mode.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/navigation.spec.d.ts +0 -2
- package/dist/types/tests/functional/navigation.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/page-load.spec.d.ts +0 -2
- package/dist/types/tests/functional/page-load.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/persisting.spec.d.ts +0 -2
- package/dist/types/tests/functional/persisting.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/plugins/body-class-plugin.spec.d.ts +0 -2
- package/dist/types/tests/functional/plugins/body-class-plugin.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/plugins/scroll-plugin.spec.d.ts +0 -2
- package/dist/types/tests/functional/plugins/scroll-plugin.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/redirects.spec.d.ts +0 -2
- package/dist/types/tests/functional/redirects.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/request.spec.d.ts +0 -2
- package/dist/types/tests/functional/request.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/scrolling.spec.d.ts +0 -2
- package/dist/types/tests/functional/scrolling.spec.d.ts.map +0 -1
- package/dist/types/tests/functional/visit-object.spec.d.ts +0 -2
- package/dist/types/tests/functional/visit-object.spec.d.ts.map +0 -1
- package/dist/types/tests/support/commands.d.ts +0 -21
- package/dist/types/tests/support/commands.d.ts.map +0 -1
- package/dist/types/tests/support/swup.d.ts +0 -20
- package/dist/types/tests/support/swup.d.ts.map +0 -1
- package/dist/types/tests/support/utils.d.ts +0 -5
- package/dist/types/tests/support/utils.d.ts.map +0 -1
- package/dist/types/tests/unit/awaitAnimations.test.d.ts +0 -2
- package/dist/types/tests/unit/awaitAnimations.test.d.ts.map +0 -1
- package/dist/types/tests/unit/cache.test.d.ts +0 -7
- package/dist/types/tests/unit/cache.test.d.ts.map +0 -1
- package/dist/types/tests/unit/delegateEvent.test.d.ts +0 -2
- package/dist/types/tests/unit/delegateEvent.test.d.ts.map +0 -1
- package/dist/types/tests/unit/exports.test.d.ts +0 -2
- package/dist/types/tests/unit/exports.test.d.ts.map +0 -1
- package/dist/types/tests/unit/hooks.test.d.ts +0 -2
- package/dist/types/tests/unit/hooks.test.d.ts.map +0 -1
- package/dist/types/tests/unit/ignoreVisit.test.d.ts +0 -2
- package/dist/types/tests/unit/ignoreVisit.test.d.ts.map +0 -1
- package/dist/types/tests/unit/location.test.d.ts +0 -2
- package/dist/types/tests/unit/location.test.d.ts.map +0 -1
- package/dist/types/tests/unit/matchPath.test.d.ts +0 -2
- package/dist/types/tests/unit/matchPath.test.d.ts.map +0 -1
- package/dist/types/tests/unit/plugins.test.d.ts +0 -2
- package/dist/types/tests/unit/plugins.test.d.ts.map +0 -1
- package/dist/types/tests/unit/replaceContent.test.d.ts +0 -2
- package/dist/types/tests/unit/replaceContent.test.d.ts.map +0 -1
- package/dist/types/tests/unit/swup.test.d.ts +0 -2
- package/dist/types/tests/unit/swup.test.d.ts.map +0 -1
- package/dist/types/tests/unit/utils.test.d.ts +0 -2
- package/dist/types/tests/unit/utils.test.d.ts.map +0 -1
- package/dist/types/tests/unit/visit.test.d.ts +0 -2
- package/dist/types/tests/unit/visit.test.d.ts.map +0 -1
- /package/dist/types/{src/Swup.d.ts → Swup.d.ts} +0 -0
- /package/dist/types/{src/config → config}/version.d.ts +0 -0
- /package/dist/types/{src/helpers → helpers}/Location.d.ts +0 -0
- /package/dist/types/{src/helpers → helpers}/classify.d.ts +0 -0
- /package/dist/types/{src/helpers → helpers}/delegateEvent.d.ts +0 -0
- /package/dist/types/{src/helpers → helpers}/getCurrentUrl.d.ts +0 -0
- /package/dist/types/{src/helpers → helpers}/history.d.ts +0 -0
- /package/dist/types/{src/helpers → helpers}/matchPath.d.ts +0 -0
- /package/dist/types/{src/helpers.d.ts → helpers.d.ts} +0 -0
- /package/dist/types/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/types/{src/modules → modules}/Cache.d.ts +0 -0
- /package/dist/types/{src/modules → modules}/Classes.d.ts +0 -0
- /package/dist/types/{src/modules → modules}/Hooks.d.ts +0 -0
- /package/dist/types/{src/modules → modules}/Visit.d.ts +0 -0
- /package/dist/types/{src/modules → modules}/animatePageIn.d.ts +0 -0
- /package/dist/types/{src/modules → modules}/animatePageOut.d.ts +0 -0
- /package/dist/types/{src/modules → modules}/awaitAnimations.d.ts +0 -0
- /package/dist/types/{src/modules → modules}/fetchPage.d.ts +0 -0
- /package/dist/types/{src/modules → modules}/getAnchorElement.d.ts +0 -0
- /package/dist/types/{src/modules → modules}/navigate.d.ts +0 -0
- /package/dist/types/{src/modules → modules}/plugins.d.ts +0 -0
- /package/dist/types/{src/modules → modules}/renderPage.d.ts +0 -0
- /package/dist/types/{src/modules → modules}/replaceContent.d.ts +0 -0
- /package/dist/types/{src/modules → modules}/resolveUrl.d.ts +0 -0
- /package/dist/types/{src/modules → modules}/scrollToContent.d.ts +0 -0
- /package/dist/types/{src/utils → utils}/index.d.ts +0 -0
- /package/dist/types/{src/utils.d.ts → utils.d.ts} +0 -0
package/dist/Swup.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t=require("delegate-it"),e=require("path-to-regexp");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=/*#__PURE__*/n(t);const r=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",i=({hash:t}={})=>window.location.pathname+window.location.search+(t?window.location.hash:""),s=(t,e={})=>{const n={url:t=t||i({hash:!0}),random:Math.random(),source:"swup",...e};window.history.pushState(n,"",t)},a=(t=null,e={})=>{t=t||i({hash:!0});const n={...window.history.state||{},url:t,random:Math.random(),source:"swup",...e};window.history.replaceState(n,"",t)},c=(t,e,n,r)=>{const i=new AbortController;return r={...r,signal:i.signal},o.default(t,e,n,r),{destroy:()=>i.abort()}};class l extends URL{constructor(t,e=document.baseURI){super(t.toString(),e),Object.setPrototypeOf(this,l.prototype)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new l(e)}static fromUrl(t){return new l(t)}}const h=function(t,e={}){try{const o=this;function n(n){const{status:i,url:s}=h;return Promise.resolve(h.text()).then(function(n){if(500===i)throw o.hooks.call("fetch:error",r,{status:i,response:h,url:s}),new u(`Server error: ${s}`,{status:i,url:s});if(!n)throw new u(`Empty response: ${s}`,{status:i,url:s});const{url:a}=l.fromUrl(s),c={url:a,html:n};return!r.cache.write||e.method&&"GET"!==e.method||t!==a||o.cache.set(c.url,c),c})}t=l.fromUrl(t).url;const{visit:r=o.visit}=e,i={...o.options.requestHeaders,...e.headers},s=e.timeout??o.options.timeout,a=new AbortController,{signal:c}=a;e={...e,headers:i,signal:c};let h,d=!1,f=null;s&&s>0&&(f=setTimeout(()=>{d=!0,a.abort("timeout")},s));const m=function(n,i){try{var s=Promise.resolve(o.hooks.call("fetch:request",r,{url:t,options:e},(t,{url:e,options:n})=>fetch(e,n))).then(function(t){h=t,f&&clearTimeout(f)})}catch(t){return i(t)}return s&&s.then?s.then(void 0,i):s}(0,function(e){if(d)throw o.hooks.call("fetch:timeout",r,{url:t}),new u(`Request timed out: ${t}`,{url:t,timedOut:d});if("AbortError"===e?.name||c.aborted)throw new u(`Request aborted: ${t}`,{url:t,aborted:!0});throw e});return Promise.resolve(m&&m.then?m.then(n):n())}catch(p){return Promise.reject(p)}};class u extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}class d{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,n)=>{t.set(n,{...e})}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?{...e}:e}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",void 0,{page:e})}update(t,e){t=this.resolve(t);const n={...this.get(t),...e,url:t};this.pages.set(t,n)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0,void 0)}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=l.fromUrl(t);return this.swup.resolveUrl(e)}}const f=(t,e=document)=>e.querySelector(t),m=(t,e=document)=>Array.from(e.querySelectorAll(t)),p=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function v(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function g(t,e=[]){return new Promise((n,o)=>{const r=t(...e);v(r)?r.then(n,o):n(r)})}function w(t,e){const n=t?.closest(`[${e}]`);return n?.hasAttribute(e)?n?.getAttribute(e)||!0:void 0}class y{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating","is-leaving"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?m(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}class k{constructor(t,e){this.id=void 0,this.state=void 0,this.from=void 0,this.to=void 0,this.containers=void 0,this.animation=void 0,this.trigger=void 0,this.cache=void 0,this.history=void 0,this.scroll=void 0,this.meta=void 0;const{to:n,from:o,hash:r,el:i,event:s}=e;this.id=Math.random(),this.state=1,this.from={url:o??t.location.url,hash:t.location.hash},this.to={url:n,hash:r},this.containers=t.options.containers,this.animation={animate:!0,wait:!1,name:void 0,native:t.options.native,scope:t.options.animationScope,selector:t.options.animationSelector},this.trigger={el:i,event:s},this.cache={read:t.options.cache,write:t.options.cache},this.history={action:"push",popstate:!1,direction:void 0},this.scroll={reset:!0,target:void 0},this.meta={}}advance(t){this.state<t&&(this.state=t)}abort(){this.state=8}ignore(){this.state=10}get done(){return this.state>=7}get ignored(){return 10===this.state}}function P(t){return new k(this,t)}const b="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function S(t,e,n){if(!t.s){if(n instanceof E){if(!n.s)return void(n.o=S.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(S.bind(null,t,e),S.bind(null,t,2));t.s=e,t.v=n;const o=t.o;o&&o(t)}}const E=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const o=new t,r=this.s;if(r){const t=1&r?e:n;if(t){try{S(o,1,t(this.v))}catch(t){S(o,2,t)}return o}return this}return this.o=function(t){try{const r=t.v;1&t.s?S(o,1,e?e(r):r):n?S(o,1,n(r)):S(o,2,r)}catch(t){S(o,2,t)}},o},t}();function x(t){return t instanceof E&&1&t.s}class C{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","visit:abort","visit:end"],this.nextHookId=0,this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n={}){const o=this.get(t);if(!o)return console.warn(`Hook '${t}' not found.`),()=>{};const r={...n,id:++this.nextHookId,hook:t,handler:e};return o.set(e,r),()=>this.off(t,e)}before(t,e,n={}){return this.on(t,e,{...n,before:!0})}replace(t,e,n={}){return this.on(t,e,{...n,replace:!0})}once(t,e,n={}){return this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n,o){try{const r=this,[i,s,a]=r.parseCallArgs(t,e,n,o),{before:c,handler:l,after:h}=r.getHandlers(t,a);return Promise.resolve(r.run(c,i,s)).then(function(){return Promise.resolve(r.run(l,i,s,!0)).then(function([e]){return Promise.resolve(r.run(h,i,s)).then(function(){return r.dispatchDomEvent(t,i,s),e})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n,o){const[r,i,s]=this.parseCallArgs(t,e,n,o),{before:a,handler:c,after:l}=this.getHandlers(t,s);this.runSync(a,r,i);const[h]=this.runSync(c,r,i,!0);return this.runSync(l,r,i),this.dispatchDomEvent(t,r,i),h}parseCallArgs(t,e,n,o){return e instanceof k||"object"!=typeof e&&"function"!=typeof n?[e,n,o]:[void 0,e,n]}run(t,e,n,o=!1){try{let r;const i=this;void 0===e&&(e=i.swup.visit);const s=[],a=function(t,e,n){if("function"==typeof t[b]){var o,r,i,s=t[b]();if(function t(a){try{for(;!((o=s.next()).done||n&&n());)if((a=e(o.value))&&a.then){if(!x(a))return void a.then(t,i||(i=S.bind(null,r=new E,2)));a=a.v}r?S(r,1,a):r=a}catch(t){S(r||(r=new E),2,t)}}(),s.return){var a=function(t){try{o.done||s.return()}catch(t){}return t};if(r&&r.then)return r.then(a,function(t){throw a(t)});a()}return r}if(!("length"in t))throw new TypeError("Object is not iterable");for(var c=[],l=0;l<t.length;l++)c.push(t[l]);return function(t,e,n){var o,r,i=-1;return function s(a){try{for(;++i<t.length&&(!n||!n());)if((a=e(i))&&a.then){if(!x(a))return void a.then(s,r||(r=S.bind(null,o=new E,2)));a=a.v}o?S(o,1,a):o=a}catch(t){S(o||(o=new E),2,t)}}(),o}(c,function(t){return e(c[t])},n)}(t,function({hook:t,handler:r,defaultHandler:a,once:c}){if(!e?.done)return c&&i.off(t,r),function(t,o){try{var i=Promise.resolve(g(r,[e,n,a])).then(function(t){s.push(t)})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(o)throw e;console.error(`Error in hook '${t}':`,e)})},function(){return r});return Promise.resolve(a&&a.then?a.then(function(t){return r?t:s}):r?a:s)}catch(t){return Promise.reject(t)}}runSync(t,e=this.swup.visit,n,o=!1){const r=[];for(const{hook:i,handler:s,defaultHandler:a,once:c}of t)if(!e?.done){c&&this.off(i,s);try{const t=s(e,n,a);r.push(t),v(t)&&console.warn(`Swup will not await Promises in handler for synchronous hook '${i}'.`)}catch(t){if(o)throw t;console.error(`Error in hook '${i}':`,t)}}return r}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const o=Array.from(n.values()),r=this.sortRegistrations,i=o.filter(({before:t,replace:e})=>t&&!e).sort(r),s=o.filter(({replace:t})=>t).filter(t=>!0).sort(r),a=o.filter(({before:t,replace:e})=>!t&&!e).sort(r),c=s.length>0;let l=[];if(e&&(l=[{id:0,hook:t,handler:e}],c)){const n=s.length-1,{handler:o,once:r}=s[n],i=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,i(t-1)):e};l=[{id:0,hook:t,once:r,handler:o,defaultHandler:i(n)}]}return{found:!0,before:i,handler:l,after:a,replaced:c}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e,n){if(e?.done)return;const o={hook:t,args:n,visit:e||this.swup.visit};document.dispatchEvent(new CustomEvent("swup:any",{detail:o,bubbles:!0})),document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:o,bubbles:!0}))}parseName(t){const[e,...n]=t.split(".");return[e,n.reduce((t,e)=>({...t,[e]:!0}),{})]}}const U=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||f(`a[name='${CSS.escape(t)}']`)||f(`a[name='${CSS.escape(e)}']`);return n||"top"!==t||(n=document.body),n},A=function({selector:t,elements:e}){try{if(!1===t&&!e)return Promise.resolve();let n=[];if(e)n=Array.from(e);else if(t&&(n=m(t,document.body),!n.length))return console.warn(`[swup] No elements found matching animationSelector \`${t}\``),Promise.resolve();const o=n.map(t=>function(t){const{type:e,timeout:n,propCount:o}=function(t){const e=window.getComputedStyle(t),n=j(e,`${$}Delay`),o=j(e,`${$}Duration`),r=q(n,o),i=j(e,`${H}Delay`),s=j(e,`${H}Duration`),a=q(i,s),c=Math.max(r,a),l=c>0?r>a?$:H:null;return{type:l,timeout:c,propCount:l?l===$?o.length:s.length:0}}(t);return!(!e||!n)&&new Promise(r=>{const i=`${e}end`,s=performance.now();let a=0;const c=()=>{t.removeEventListener(i,l),r()},l=e=>{e.target===t&&((performance.now()-s)/1e3<e.elapsedTime||++a>=o&&c())};setTimeout(()=>{a<o&&c()},n+1),t.addEventListener(i,l)})}(t)).filter(t=>!1!==t);return o.length?Promise.resolve(Promise.all(o)).then(function(){}):(t&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${t}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},$="transition",H="animation";function j(t,e){return(t[e]||"").split(", ")}function q(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>I(e)+I(t[n])))}function I(t){return 1e3*parseFloat(t)}const R=function(t,e={}){try{let o;const i=this;function n(n){if(o)return n;i.navigating=!0,i.visit=t;const{el:c}=t.trigger;e.referrer=e.referrer||i.location.url,!1===e.animate&&(t.animation.animate=!1),t.animation.animate||i.classes.clear();const h=e.history||w(c,"data-swup-history");"string"==typeof h&&["push","replace"].includes(h)&&(t.history.action=h);const u=e.animation||w(c,"data-swup-animation");return"string"==typeof u&&(t.animation.name=u),t.meta=e.meta||{},"object"==typeof e.cache?(t.cache.read=e.cache.read??t.cache.read,t.cache.write=e.cache.write??t.cache.write):void 0!==e.cache&&(t.cache={read:!!e.cache,write:!!e.cache}),delete e.cache,function(n,o){try{var c=function(n,o){try{var c=Promise.resolve(i.hooks.call("visit:start",t,void 0)).then(function(){function n(){if(t.ignored)throw new Error(`Visit to ${t.to.url} manually ignored`);if(!t.done)return Promise.resolve(i.hooks.call("visit:transition",t,void 0,function(){try{let n;function e(e){return n?e:(t.advance(4),Promise.resolve(i.animatePageOut(t)).then(function(){function e(){return Promise.resolve(i.animatePageIn(t)).then(function(){})}const n=function(){if(t.animation.native&&document.startViewTransition)return Promise.resolve(document.startViewTransition(function(){try{const e=i.renderPage;return Promise.resolve(o).then(function(n){return Promise.resolve(e.call(i,t,n))})}catch(t){return Promise.reject(t)}}).finished).then(function(){});{const e=i.renderPage;return Promise.resolve(o).then(function(n){return Promise.resolve(e.call(i,t,n)).then(function(){})})}}();return n&&n.then?n.then(e):e()}))}const r=function(){if(!t.animation.animate)return Promise.resolve(i.hooks.call("animation:skip",void 0)).then(function(){const e=i.renderPage;return Promise.resolve(o).then(function(o){return Promise.resolve(e.call(i,t,o)).then(function(){n=1})})})}();return Promise.resolve(r&&r.then?r.then(e):e(r))}catch(s){return Promise.reject(s)}})).then(function(){if(!t.done)return Promise.resolve(i.hooks.call("visit:end",t,void 0,()=>i.classes.clear())).then(function(){t.state=7,i.navigating=!1,i.onVisitEnd&&(i.onVisitEnd(),i.onVisitEnd=void 0)})})}t.state=3;const o=i.hooks.call("page:load",t,{options:e},function(t,e){try{function n(t){return e.page=t,e.cache=!!o,e.page}let o;return t.cache.read&&(o=i.cache.get(t.to.url)),Promise.resolve(o?n(o):Promise.resolve(i.fetchPage(t.to.url,e.options)).then(n))}catch(r){return Promise.reject(r)}});o.then(({html:e})=>{t.advance(5),t.to.html=e,t.to.document=(new DOMParser).parseFromString(e,"text/html")});const c=t.to.url+t.to.hash;t.history.popstate||("replace"===t.history.action||t.to.url===i.location.url?a(c):(i.currentHistoryIndex++,s(c,{index:i.currentHistoryIndex}))),i.location=l.fromUrl(c),t.history.popstate&&i.classes.add("is-popstate"),t.animation.name&&i.classes.add(`to-${r(t.animation.name)}`);const h=function(){if(t.animation.wait)return Promise.resolve(o).then(function(){})}();return h&&h.then?h.then(n):n()})}catch(t){return o(t)}return c&&c.then?c.then(void 0,o):c}(0,function(e){e&&!e?.aborted?(t.advance(9),console.error(e),i.options.skipPopStateHandling=()=>(window.location.assign(t.to.url+t.to.hash),!0),window.history.back()):t.advance(8)})}catch(t){return o(!0,t)}return c&&c.then?c.then(o.bind(null,!1),o.bind(null,!0)):o(!1,c)}(0,function(e,n){if(delete t.to.document,e)throw n;return n})}const c=function(){if(i.navigating)return function(){if(!(i.visit.state>=6))return Promise.resolve(i.hooks.call("visit:abort",i.visit,void 0)).then(function(){delete i.visit.to.document,i.visit.state=8});t.state=2,i.onVisitEnd=()=>i.performNavigation(t,e),o=1}()}();return Promise.resolve(c&&c.then?c.then(n):n(c))}catch(h){return Promise.reject(h)}};function V(t,e={},n={}){if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");if(this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void window.location.assign(t);const{url:o,hash:r}=l.fromUrl(t),i=this.createVisit({...n,to:o,hash:r});this.performNavigation(i,e)}const L=function(t){try{const e=this;return Promise.resolve(e.hooks.call("animation:out:start",t,void 0,()=>{e.classes.add("is-changing","is-animating","is-leaving")})).then(function(){return Promise.resolve(e.hooks.call("animation:out:await",t,{skip:!1},(t,{skip:n})=>{if(!n)return e.awaitAnimations({selector:t.animation.selector})})).then(function(){return Promise.resolve(e.hooks.call("animation:out:end",t,void 0)).then(function(){})})})}catch(t){return Promise.reject(t)}},T=function(t){const e=t.to.document;if(!e)return!1;const n=e.querySelector("title")?.innerText||"";document.title=n;const o=m('[data-swup-persist]:not([data-swup-persist=""])'),r=t.containers.map(t=>{const n=document.querySelector(t),o=e.querySelector(t);return n&&o?(n.replaceWith(o.cloneNode(!0)),!0):(n||console.warn(`[swup] Container missing in current document: ${t}`),o||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean);return o.forEach(t=>{const e=t.getAttribute("data-swup-persist"),n=f(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),r.length===t.containers.length},N=function(t){const e={behavior:"auto"},{target:n,reset:o}=t.scroll,r=n??t.to.hash;let i=!1;return r&&(i=this.hooks.callSync("scroll:anchor",t,{hash:r,options:e},(t,{hash:e,options:n})=>{const o=this.getAnchorElement(e);return o&&o.scrollIntoView(n),!!o})),o&&!i&&(i=this.hooks.callSync("scroll:top",t,{options:e},(t,{options:e})=>(window.scrollTo({top:0,left:0,...e}),!0))),i},D=function(t){try{const e=this;if(t.done)return Promise.resolve();const n=e.hooks.call("animation:in:await",t,{skip:!1},(t,{skip:n})=>{if(!n)return e.awaitAnimations({selector:t.animation.selector})});return Promise.resolve(p()).then(function(){return Promise.resolve(e.hooks.call("animation:in:start",t,void 0,()=>{e.classes.remove("is-animating")})).then(function(){return Promise.resolve(n).then(function(){return Promise.resolve(e.hooks.call("animation:in:end",t,void 0)).then(function(){})})})})}catch(t){return Promise.reject(t)}},O=function(t,e){try{const n=this;if(t.done)return Promise.resolve();t.advance(6);const{url:o}=e;return n.isSameResolvedUrl(i(),o)||(a(o),n.location=l.fromUrl(o),t.to.url=n.location.url,t.to.hash=n.location.hash),Promise.resolve(n.hooks.call("content:replace",t,{page:e},(t,{})=>{if(n.classes.remove("is-leaving"),t.animation.animate&&n.classes.add("is-rendering"),!n.replaceContent(t))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(n.classes.add("is-changing","is-animating","is-rendering"),t.animation.name&&n.classes.add(`to-${r(t.animation.name)}`))})).then(function(){return Promise.resolve(n.hooks.call("content:scroll",t,void 0,()=>n.scrollToContent(t))).then(function(){return Promise.resolve(n.hooks.call("page:view",t,{url:n.location.url,title:document.title})).then(function(){})})})}catch(t){return Promise.reject(t)}},M=function(t){var e;if(e=t,Boolean(e?.isSwupPlugin)){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function W(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function B(t){return this.plugins.find(e=>"string"==typeof t?[`Swup${t}`,t].includes(e.name):e===t)}function _(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function F(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}const K={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],hooks:{},ignoreVisit:(t,{el:e}={})=>!!e?.closest("[data-no-swup]"),linkSelector:"a[href]",linkToSelf:"scroll",native:!1,plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source,timeout:0};exports.Location=l,exports.classify=r,exports.createHistoryRecord=s,exports.default=class{get currentPageUrl(){return this.location.url}constructor(t={}){this.version="4.9.1",this.options=void 0,this.defaults=K,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.location=l.fromUrl(window.location.href),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.navigating=!1,this.onVisitEnd=void 0,this.use=M,this.unuse=W,this.findPlugin=B,this.log=()=>{},this.navigate=V,this.performNavigation=R,this.createVisit=P,this.delegateEvent=c,this.fetchPage=h,this.awaitAnimations=A,this.renderPage=O,this.replaceContent=T,this.animatePageIn=D,this.animatePageOut=L,this.scrollToContent=N,this.getAnchorElement=U,this.getCurrentUrl=i,this.resolveUrl=_,this.isSameResolvedUrl=F,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new d(this),this.classes=new y(this),this.hooks=new C(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=window.history.state?.index??1,this.enable()}enable(){try{const t=this,{linkSelector:e}=t.options;t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),t.options.native=t.options.native&&!!document.startViewTransition,t.options.plugins.forEach(e=>t.use(e));for(const[e,n]of Object.entries(t.options.hooks)){const[o,r]=t.hooks.parseName(e);t.hooks.on(o,n,r)}return"swup"!==window.history.state?.source&&a(null,{index:t.currentHistoryIndex}),Promise.resolve(p()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,void 0,()=>{const e=document.documentElement;e.classList.add("swup-enabled"),e.classList.toggle("swup-native",t.options.native)})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,void 0,()=>{const t=document.documentElement;t.classList.remove("swup-enabled"),t.classList.remove("swup-native")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,{el:e,event:n}={}){const{origin:o,url:r,hash:i}=l.fromUrl(t);return o!==window.location.origin||!(!e||!this.triggerWillOpenNewWindow(e))||!!this.options.ignoreVisit(r+i,{el:e,event:n})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:o,hash:r}=l.fromElement(e);if(this.shouldIgnoreVisit(n,{el:e,event:t}))return;if(this.navigating&&o===this.visit.to.url)return void t.preventDefault();const i=this.createVisit({to:o,hash:r,el:e,event:t});t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.callSync("link:newtab",i,{href:n}):0===t.button&&this.hooks.callSync("link:click",i,{el:e,event:t},()=>{const e=i.from.url??"";t.preventDefault(),o&&o!==e?this.isSameResolvedUrl(o,e)||this.performNavigation(i):r?this.hooks.callSync("link:anchor",i,{hash:r},()=>{a(o+r),this.scrollToContent(i)}):this.hooks.callSync("link:self",i,void 0,()=>{"navigate"===this.options.linkToSelf?this.performNavigation(i):(a(o),this.scrollToContent(i))})})}handlePopState(t){const e=t.state?.url??window.location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(i(),this.location.url))return;const{url:n,hash:o}=l.fromUrl(e),r=this.createVisit({to:n,hash:o,event:t});r.history.popstate=!0;const s=t.state?.index??0;s&&s!==this.currentHistoryIndex&&(r.history.direction=s-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=s),r.animation.animate=!1,r.scroll.reset=!1,r.scroll.target=!1,this.options.animateHistoryBrowsing&&(r.animation.animate=!0,r.scroll.reset=!0),this.hooks.callSync("history:popstate",r,{event:t},()=>{this.performNavigation(r)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}},exports.delegateEvent=c,exports.forceReflow=function(t){t=t||document.body,t?.getBoundingClientRect()},exports.getContextualAttr=w,exports.getCurrentUrl=i,exports.isPromise=v,exports.matchPath=(t,n)=>{Array.isArray(t)&&!t.length&&(t="");try{return e.match(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${String(t)}":\n${String(e)}`,{cause:e})}},exports.nextTick=p,exports.query=f,exports.queryAll=m,exports.runAsPromise=g,exports.updateHistoryRecord=a;
|
|
1
|
+
var t=require("delegate-it"),e=require("path-to-regexp");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=/*#__PURE__*/n(t);const r=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",i=({hash:t}={})=>window.location.pathname+window.location.search+(t?window.location.hash:""),s=(t,e={})=>{const n={url:t=t||i({hash:!0}),random:Math.random(),source:"swup",...e};window.history.pushState(n,"",t)},a=(t=null,e={})=>{t=t||i({hash:!0});const n={...window.history.state||{},url:t,random:Math.random(),source:"swup",...e};window.history.replaceState(n,"",t)},c=(t,e,n,r)=>{const i=new AbortController;return r={...r,signal:i.signal},o.default(t,e,n,r),{destroy:()=>i.abort()}};class l extends URL{constructor(t,e=document.baseURI){super(t.toString(),e),Object.setPrototypeOf(this,l.prototype)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new l(e)}static fromUrl(t){return new l(t)}}const h=function(t,e={}){try{const o=this;function n(n){const{status:i,url:s}=h;return Promise.resolve(h.text()).then(function(n){if(500===i)throw o.hooks.call("fetch:error",r,{status:i,response:h,url:s}),new u(`Server error: ${s}`,{status:i,url:s});if(!n)throw new u(`Empty response: ${s}`,{status:i,url:s});const{url:a}=l.fromUrl(s),c={url:a,html:n};return!r.cache.write||e.method&&"GET"!==e.method||t!==a||o.cache.set(c.url,c),c})}t=l.fromUrl(t).url;const{visit:r=o.visit}=e,i={...o.options.requestHeaders,...e.headers},s=e.timeout??o.options.timeout,a=new AbortController,{signal:c}=a;e={...e,headers:i,signal:c};let h,d=!1,f=null;s&&s>0&&(f=setTimeout(()=>{d=!0,a.abort("timeout")},s));const m=function(n,i){try{var s=Promise.resolve(o.hooks.call("fetch:request",r,{url:t,options:e},(t,{url:e,options:n})=>fetch(e,n))).then(function(t){h=t,f&&clearTimeout(f)})}catch(t){return i(t)}return s&&s.then?s.then(void 0,i):s}(0,function(e){if(d)throw o.hooks.call("fetch:timeout",r,{url:t}),new u(`Request timed out: ${t}`,{url:t,timedOut:d});if("AbortError"===e?.name||c.aborted)throw new u(`Request aborted: ${t}`,{url:t,aborted:!0});throw e});return Promise.resolve(m&&m.then?m.then(n):n())}catch(p){return Promise.reject(p)}};class u extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}class d{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,n)=>{t.set(n,{...e})}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?{...e}:e}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",void 0,{page:e})}update(t,e){t=this.resolve(t);const n={...this.get(t),...e,url:t};this.pages.set(t,n)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0,void 0)}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=l.fromUrl(t);return this.swup.resolveUrl(e)}}const f=(t,e=document)=>e.querySelector(t),m=(t,e=document)=>Array.from(e.querySelectorAll(t)),p=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function v(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function g(t,e=[]){return new Promise((n,o)=>{const r=t(...e);v(r)?r.then(n,o):n(r)})}function w(t,e){const n=t?.closest(`[${e}]`);return n?.hasAttribute(e)?n?.getAttribute(e)||!0:void 0}class y{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating","is-leaving"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?m(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}class k{constructor(t,e){this.id=void 0,this.state=void 0,this.from=void 0,this.to=void 0,this.containers=void 0,this.animation=void 0,this.trigger=void 0,this.cache=void 0,this.history=void 0,this.scroll=void 0,this.meta=void 0;const{to:n,from:o,hash:r,el:i,event:s}=e;this.id=Math.random(),this.state=1,this.from={url:o??t.location.url,hash:t.location.hash},this.to={url:n,hash:r},this.containers=t.options.containers,this.animation={animate:!0,wait:!1,name:void 0,native:t.options.native,scope:t.options.animationScope,selector:t.options.animationSelector},this.trigger={el:i,event:s},this.cache={read:t.options.cache,write:t.options.cache},this.history={action:"push",popstate:!1,direction:void 0},this.scroll={reset:!0,target:void 0},this.meta={}}advance(t){this.state<t&&(this.state=t)}abort(){this.state=8}ignore(){this.state=10}get done(){return this.state>=7}get ignored(){return 10===this.state}}function P(t){return new k(this,t)}const b="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function S(t,e,n){if(!t.s){if(n instanceof E){if(!n.s)return void(n.o=S.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(S.bind(null,t,e),S.bind(null,t,2));t.s=e,t.v=n;const o=t.o;o&&o(t)}}const E=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const o=new t,r=this.s;if(r){const t=1&r?e:n;if(t){try{S(o,1,t(this.v))}catch(t){S(o,2,t)}return o}return this}return this.o=function(t){try{const r=t.v;1&t.s?S(o,1,e?e(r):r):n?S(o,1,n(r)):S(o,2,r)}catch(t){S(o,2,t)}},o},t}();function x(t){return t instanceof E&&1&t.s}class C{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","visit:abort","visit:end"],this.nextHookId=0,this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n={}){const o=this.get(t);if(!o)return console.warn(`Hook '${t}' not found.`),()=>{};const r={...n,id:++this.nextHookId,hook:t,handler:e};return o.set(e,r),()=>this.off(t,e)}before(t,e,n={}){return this.on(t,e,{...n,before:!0})}replace(t,e,n={}){return this.on(t,e,{...n,replace:!0})}once(t,e,n={}){return this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n,o){try{const r=this,[i,s,a]=r.parseCallArgs(t,e,n,o),{before:c,handler:l,after:h}=r.getHandlers(t,a);return Promise.resolve(r.run(c,i,s)).then(function(){return Promise.resolve(r.run(l,i,s,!0)).then(function([e]){return Promise.resolve(r.run(h,i,s)).then(function(){return r.dispatchDomEvent(t,i,s),e})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n,o){const[r,i,s]=this.parseCallArgs(t,e,n,o),{before:a,handler:c,after:l}=this.getHandlers(t,s);this.runSync(a,r,i);const[h]=this.runSync(c,r,i,!0);return this.runSync(l,r,i),this.dispatchDomEvent(t,r,i),h}parseCallArgs(t,e,n,o){return e instanceof k||"object"!=typeof e&&"function"!=typeof n?[e,n,o]:[void 0,e,n]}run(t,e,n,o=!1){try{let r;const i=this;void 0===e&&(e=i.swup.visit);const s=[],a=function(t,e,n){if("function"==typeof t[b]){var o,r,i,s=t[b]();if(function t(a){try{for(;!((o=s.next()).done||n&&n());)if((a=e(o.value))&&a.then){if(!x(a))return void a.then(t,i||(i=S.bind(null,r=new E,2)));a=a.v}r?S(r,1,a):r=a}catch(t){S(r||(r=new E),2,t)}}(),s.return){var a=function(t){try{o.done||s.return()}catch(t){}return t};if(r&&r.then)return r.then(a,function(t){throw a(t)});a()}return r}if(!("length"in t))throw new TypeError("Object is not iterable");for(var c=[],l=0;l<t.length;l++)c.push(t[l]);return function(t,e,n){var o,r,i=-1;return function s(a){try{for(;++i<t.length&&(!n||!n());)if((a=e(i))&&a.then){if(!x(a))return void a.then(s,r||(r=S.bind(null,o=new E,2)));a=a.v}o?S(o,1,a):o=a}catch(t){S(o||(o=new E),2,t)}}(),o}(c,function(t){return e(c[t])},n)}(t,function({hook:t,handler:r,defaultHandler:a,once:c}){if(!e?.done)return c&&i.off(t,r),function(t,o){try{var i=Promise.resolve(g(r,[e,n,a])).then(function(t){s.push(t)})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(o)throw e;console.error(`Error in hook '${t}':`,e)})},function(){return r});return Promise.resolve(a&&a.then?a.then(function(t){return r?t:s}):r?a:s)}catch(t){return Promise.reject(t)}}runSync(t,e=this.swup.visit,n,o=!1){const r=[];for(const{hook:i,handler:s,defaultHandler:a,once:c}of t)if(!e?.done){c&&this.off(i,s);try{const t=s(e,n,a);r.push(t),v(t)&&console.warn(`Swup will not await Promises in handler for synchronous hook '${i}'.`)}catch(t){if(o)throw t;console.error(`Error in hook '${i}':`,t)}}return r}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const o=Array.from(n.values()),r=this.sortRegistrations,i=o.filter(({before:t,replace:e})=>t&&!e).sort(r),s=o.filter(({replace:t})=>t).filter(t=>!0).sort(r),a=o.filter(({before:t,replace:e})=>!t&&!e).sort(r),c=s.length>0;let l=[];if(e&&(l=[{id:0,hook:t,handler:e}],c)){const n=s.length-1,{handler:o,once:r}=s[n],i=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,i(t-1)):e};l=[{id:0,hook:t,once:r,handler:o,defaultHandler:i(n)}]}return{found:!0,before:i,handler:l,after:a,replaced:c}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e,n){if(e?.done)return;const o={hook:t,args:n,visit:e||this.swup.visit};document.dispatchEvent(new CustomEvent("swup:any",{detail:o,bubbles:!0})),document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:o,bubbles:!0}))}parseName(t){const[e,...n]=t.split(".");return[e,n.reduce((t,e)=>({...t,[e]:!0}),{})]}}const U=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||f(`a[name='${CSS.escape(t)}']`)||f(`a[name='${CSS.escape(e)}']`);return n||"top"!==t||(n=document.body),n},A=function({selector:t,elements:e}){try{if(!1===t&&!e)return Promise.resolve();let n=[];if(e)n=Array.from(e);else if(t&&(n=m(t,document.body),!n.length))return console.warn(`[swup] No elements found matching animationSelector \`${t}\``),Promise.resolve();const o=n.map(t=>function(t){const{type:e,timeout:n,propCount:o}=function(t){const e=window.getComputedStyle(t),n=j(e,`${$}Delay`),o=j(e,`${$}Duration`),r=q(n,o),i=j(e,`${H}Delay`),s=j(e,`${H}Duration`),a=q(i,s),c=Math.max(r,a),l=c>0?r>a?$:H:null;return{type:l,timeout:c,propCount:l?l===$?o.length:s.length:0}}(t);return!(!e||!n)&&new Promise(r=>{const i=`${e}end`,s=performance.now();let a=0;const c=()=>{t.removeEventListener(i,l),r()},l=e=>{e.target===t&&((performance.now()-s)/1e3<e.elapsedTime||++a>=o&&c())};setTimeout(()=>{a<o&&c()},n+1),t.addEventListener(i,l)})}(t)).filter(t=>!1!==t);return o.length?Promise.resolve(Promise.all(o)).then(function(){}):(t&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${t}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},$="transition",H="animation";function j(t,e){return(t[e]||"").split(", ")}function q(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>I(e)+I(t[n])))}function I(t){return 1e3*parseFloat(t)}const R=function(t,e={}){try{let o;const i=this;function n(n){if(o)return n;i.navigating=!0,i.visit=t;const{el:c}=t.trigger;e.referrer=e.referrer||i.location.url,!1===e.animate&&(t.animation.animate=!1),t.animation.animate||i.classes.clear();const h=e.history||w(c,"data-swup-history");"string"==typeof h&&["push","replace"].includes(h)&&(t.history.action=h);const u=e.animation||w(c,"data-swup-animation");return"string"==typeof u&&(t.animation.name=u),t.meta=e.meta||{},"object"==typeof e.cache?(t.cache.read=e.cache.read??t.cache.read,t.cache.write=e.cache.write??t.cache.write):void 0!==e.cache&&(t.cache={read:!!e.cache,write:!!e.cache}),delete e.cache,function(n,o){try{var c=function(n,o){try{var c=Promise.resolve(i.hooks.call("visit:start",t,void 0)).then(function(){function n(){if(t.ignored)throw new Error(`Visit to ${t.to.url} manually ignored`);if(!t.done)return Promise.resolve(i.hooks.call("visit:transition",t,void 0,function(){try{let n;function e(e){return n?e:(t.advance(4),Promise.resolve(i.animatePageOut(t)).then(function(){function e(){return Promise.resolve(i.animatePageIn(t)).then(function(){})}const n=function(){if(t.animation.native&&document.startViewTransition)return Promise.resolve(document.startViewTransition(function(){try{const e=i.renderPage;return Promise.resolve(o).then(function(n){return Promise.resolve(e.call(i,t,n))})}catch(t){return Promise.reject(t)}}).finished).then(function(){});{const e=i.renderPage;return Promise.resolve(o).then(function(n){return Promise.resolve(e.call(i,t,n)).then(function(){})})}}();return n&&n.then?n.then(e):e()}))}const r=function(){if(!t.animation.animate)return Promise.resolve(i.hooks.call("animation:skip",void 0)).then(function(){const e=i.renderPage;return Promise.resolve(o).then(function(o){return Promise.resolve(e.call(i,t,o)).then(function(){n=1})})})}();return Promise.resolve(r&&r.then?r.then(e):e(r))}catch(s){return Promise.reject(s)}})).then(function(){if(!t.done)return Promise.resolve(i.hooks.call("visit:end",t,void 0,()=>i.classes.clear())).then(function(){t.state=7,i.navigating=!1,i.onVisitEnd&&(i.onVisitEnd(),i.onVisitEnd=void 0)})})}t.state=3;const o=i.hooks.call("page:load",t,{options:e},function(t,e){try{function n(t){return e.page=t,e.cache=!!o,e.page}let o;return t.cache.read&&(o=i.cache.get(t.to.url)),Promise.resolve(o?n(o):Promise.resolve(i.fetchPage(t.to.url,e.options)).then(n))}catch(r){return Promise.reject(r)}});o.then(({html:e})=>{t.advance(5),t.to.html=e,t.to.document=(new DOMParser).parseFromString(e,"text/html")});const c=t.to.url+t.to.hash;t.history.popstate||("replace"===t.history.action||t.to.url===i.location.url?a(c):(i.currentHistoryIndex++,s(c,{index:i.currentHistoryIndex}))),i.location=l.fromUrl(c),t.history.popstate&&i.classes.add("is-popstate"),t.animation.name&&i.classes.add(`to-${r(t.animation.name)}`);const h=function(){if(t.animation.wait)return Promise.resolve(o).then(function(){})}();return h&&h.then?h.then(n):n()})}catch(t){return o(t)}return c&&c.then?c.then(void 0,o):c}(0,function(e){e&&!e?.aborted?(t.advance(9),console.error(e),i.options.skipPopStateHandling=()=>(window.location.assign(t.to.url+t.to.hash),!0),window.history.back()):t.advance(8)})}catch(t){return o(!0,t)}return c&&c.then?c.then(o.bind(null,!1),o.bind(null,!0)):o(!1,c)}(0,function(e,n){if(delete t.to.document,e)throw n;return n})}const c=function(){if(i.navigating)return function(){if(!(i.visit.state>=6))return Promise.resolve(i.hooks.call("visit:abort",i.visit,void 0)).then(function(){delete i.visit.to.document,i.visit.state=8});t.state=2,i.onVisitEnd=()=>i.performNavigation(t,e),o=1}()}();return Promise.resolve(c&&c.then?c.then(n):n(c))}catch(h){return Promise.reject(h)}};function V(t,e={},n={}){if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");if(this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void window.location.assign(t);const{url:o,hash:r}=l.fromUrl(t),i=this.createVisit({...n,to:o,hash:r});this.performNavigation(i,e)}const L=function(t){try{const e=this;return Promise.resolve(e.hooks.call("animation:out:start",t,void 0,()=>{e.classes.add("is-changing","is-animating","is-leaving")})).then(function(){return Promise.resolve(e.hooks.call("animation:out:await",t,{skip:!1},(t,{skip:n})=>{if(!n)return e.awaitAnimations({selector:t.animation.selector})})).then(function(){return Promise.resolve(e.hooks.call("animation:out:end",t,void 0)).then(function(){})})})}catch(t){return Promise.reject(t)}},T=function(t){const e=t.to.document;if(!e)return!1;const n=e.querySelector("title")?.innerText||"";document.title=n;const o=m('[data-swup-persist]:not([data-swup-persist=""])'),r=t.containers.map(t=>{const n=document.querySelector(t),o=e.querySelector(t);return n&&o?(n.replaceWith(o.cloneNode(!0)),!0):(n||console.warn(`[swup] Container missing in current document: ${t}`),o||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean);return o.forEach(t=>{const e=t.getAttribute("data-swup-persist"),n=f(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),r.length===t.containers.length},N=function(t){const e={behavior:"auto"},{target:n,reset:o}=t.scroll,r=n??t.to.hash;let i=!1;return r&&(i=this.hooks.callSync("scroll:anchor",t,{hash:r,options:e},(t,{hash:e,options:n})=>{const o=this.getAnchorElement(e);return o&&o.scrollIntoView(n),!!o})),o&&!i&&(i=this.hooks.callSync("scroll:top",t,{options:e},(t,{options:e})=>(window.scrollTo({top:0,left:0,...e}),!0))),i},D=function(t){try{const e=this;if(t.done)return Promise.resolve();const n=e.hooks.call("animation:in:await",t,{skip:!1},(t,{skip:n})=>{if(!n)return e.awaitAnimations({selector:t.animation.selector})});return Promise.resolve(p()).then(function(){return Promise.resolve(e.hooks.call("animation:in:start",t,void 0,()=>{e.classes.remove("is-animating")})).then(function(){return Promise.resolve(n).then(function(){return Promise.resolve(e.hooks.call("animation:in:end",t,void 0)).then(function(){})})})})}catch(t){return Promise.reject(t)}},O=function(t,e){try{const n=this;if(t.done)return Promise.resolve();t.advance(6);const{url:o}=e;return n.isSameResolvedUrl(i(),o)||(a(o),n.location=l.fromUrl(o),t.to.url=n.location.url,t.to.hash=n.location.hash),Promise.resolve(n.hooks.call("content:replace",t,{page:e},(t,{})=>{if(n.classes.remove("is-leaving"),t.animation.animate&&n.classes.add("is-rendering"),!n.replaceContent(t))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(n.classes.add("is-changing","is-animating","is-rendering"),t.animation.name&&n.classes.add(`to-${r(t.animation.name)}`))})).then(function(){return Promise.resolve(n.hooks.call("content:scroll",t,void 0,()=>n.scrollToContent(t))).then(function(){return Promise.resolve(n.hooks.call("page:view",t,{url:n.location.url,title:document.title})).then(function(){})})})}catch(t){return Promise.reject(t)}},M=function(t){var e;if(e=t,Boolean(e?.isSwupPlugin)){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function W(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function B(t){return this.plugins.find(e=>"string"==typeof t?[`Swup${t}`,t].includes(e.name):e===t)}function _(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function F(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}const K={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],hooks:{},ignoreVisit:(t,{el:e}={})=>!!e?.closest("[data-no-swup]"),linkSelector:"a[href]",linkToSelf:"scroll",native:!1,plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source,timeout:0};exports.Location=l,exports.classify=r,exports.createHistoryRecord=s,exports.default=class{get currentPageUrl(){return this.location.url}constructor(t={}){this.version="4.9.2",this.options=void 0,this.defaults=K,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.location=l.fromUrl(window.location.href),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.navigating=!1,this.onVisitEnd=void 0,this.use=M,this.unuse=W,this.findPlugin=B,this.log=()=>{},this.navigate=V,this.performNavigation=R,this.createVisit=P,this.delegateEvent=c,this.fetchPage=h,this.awaitAnimations=A,this.renderPage=O,this.replaceContent=T,this.animatePageIn=D,this.animatePageOut=L,this.scrollToContent=N,this.getAnchorElement=U,this.getCurrentUrl=i,this.resolveUrl=_,this.isSameResolvedUrl=F,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new d(this),this.classes=new y(this),this.hooks=new C(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=window.history.state?.index??1,this.enable()}enable(){try{const t=this,{linkSelector:e}=t.options;t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),t.options.native=t.options.native&&!!document.startViewTransition,t.options.plugins.forEach(e=>t.use(e));for(const[e,n]of Object.entries(t.options.hooks)){const[o,r]=t.hooks.parseName(e);t.hooks.on(o,n,r)}return"swup"!==window.history.state?.source&&a(null,{index:t.currentHistoryIndex}),Promise.resolve(p()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,void 0,()=>{const e=document.documentElement;e.classList.add("swup-enabled"),e.classList.toggle("swup-native",t.options.native)})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,void 0,()=>{const t=document.documentElement;t.classList.remove("swup-enabled"),t.classList.remove("swup-native")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,{el:e,event:n}={}){const{origin:o,url:r,hash:i}=l.fromUrl(t);return o!==window.location.origin||!(!e||!this.triggerWillOpenNewWindow(e))||!!this.options.ignoreVisit(r+i,{el:e,event:n})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:o,hash:r}=l.fromElement(e);if(this.shouldIgnoreVisit(n,{el:e,event:t}))return;if(this.navigating&&o===this.visit.to.url)return void t.preventDefault();const i=this.createVisit({to:o,hash:r,el:e,event:t});t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.callSync("link:newtab",i,{href:n}):0===t.button&&this.hooks.callSync("link:click",i,{el:e,event:t},()=>{const e=i.from.url??"";t.preventDefault(),o&&o!==e?this.isSameResolvedUrl(o,e)||this.performNavigation(i):r?this.hooks.callSync("link:anchor",i,{hash:r},()=>{a(o+r),this.scrollToContent(i)}):this.hooks.callSync("link:self",i,void 0,()=>{"navigate"===this.options.linkToSelf?this.performNavigation(i):(a(o),this.scrollToContent(i))})})}handlePopState(t){const e=t.state?.url??window.location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(i(),this.location.url))return;const{url:n,hash:o}=l.fromUrl(e),r=this.createVisit({to:n,hash:o,event:t});r.history.popstate=!0;const s=t.state?.index??0;s&&s!==this.currentHistoryIndex&&(r.history.direction=s-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=s),r.animation.animate=!1,r.scroll.reset=!1,r.scroll.target=!1,this.options.animateHistoryBrowsing&&(r.animation.animate=!0,r.scroll.reset=!0),this.hooks.callSync("history:popstate",r,{event:t},()=>{this.performNavigation(r)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}},exports.delegateEvent=c,exports.forceReflow=function(t){t=t||document.body,t?.getBoundingClientRect()},exports.getContextualAttr=w,exports.getCurrentUrl=i,exports.isPromise=v,exports.matchPath=(t,n)=>{Array.isArray(t)&&!t.length&&(t="");try{return e.match(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${String(t)}":\n${String(e)}`,{cause:e})}},exports.nextTick=p,exports.query=f,exports.queryAll=m,exports.runAsPromise=g,exports.updateHistoryRecord=a;
|
|
2
2
|
//# sourceMappingURL=Swup.cjs.map
|
package/dist/Swup.modern.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
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)({}).hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},i.apply(null,arguments)}const s=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",n=({hash:t}={})=>window.location.pathname+window.location.search+(t?window.location.hash:""),o=(t,e={})=>{const s=i({url:t=t||n({hash:!0}),random:Math.random(),source:"swup"},e);window.history.pushState(s,"",t)},r=(t=null,e={})=>{t=t||n({hash:!0});const s=i({},window.history.state||{},{url:t,random:Math.random(),source:"swup"},e);window.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),Object.setPrototypeOf(this,l.prototype)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new l(e)}static fromUrl(t){return new l(t)}}const h=(t,i)=>{Array.isArray(t)&&!t.length&&(t="");try{return e(t,i)}catch(e){throw new Error(`[swup] Error parsing path "${String(t)}":\n${String(e)}`,{cause:e})}};class c extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}async function u(t,e={}){var s;t=l.fromUrl(t).url;const{visit:n=this.visit}=e,o=i({},this.options.requestHeaders,e.headers),r=null!=(s=e.timeout)?s:this.options.timeout,a=new AbortController,{signal:h}=a;e=i({},e,{headers:o,signal:h});let u,d=!1,p=null;r&&r>0&&(p=setTimeout(()=>{d=!0,a.abort("timeout")},r));try{u=await this.hooks.call("fetch:request",n,{url:t,options:e},(t,{url:e,options:i})=>fetch(e,i)),p&&clearTimeout(p)}catch(e){if(d)throw this.hooks.call("fetch:timeout",n,{url:t}),new c(`Request timed out: ${t}`,{url:t,timedOut:d});if("AbortError"===(null==e?void 0:e.name)||h.aborted)throw new c(`Request aborted: ${t}`,{url:t,aborted:!0});throw e}const{status:m,url:g}=u,w=await u.text();if(500===m)throw this.hooks.call("fetch:error",n,{status:m,response:u,url:g}),new c(`Server error: ${g}`,{status:m,url:g});if(!w)throw new c(`Empty response: ${g}`,{status:m,url:g});const{url:f}=l.fromUrl(g),v={url:f,html:w};return!n.cache.write||e.method&&"GET"!==e.method||t!==f||this.cache.set(v.url,v),v}class d{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,s)=>{t.set(s,i({},e))}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?i({},e):e}set(t,e){e=i({},e,{url:t=this.resolve(t)}),this.pages.set(t,e),this.swup.hooks.callSync("cache:set",void 0,{page:e})}update(t,e){t=this.resolve(t);const s=i({},this.get(t),e,{url:t});this.pages.set(t,s)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0,void 0)}prune(t){this.pages.forEach((e,i)=>{t(i,e)&&this.delete(i)})}resolve(t){const{url:e}=l.fromUrl(t);return this.swup.resolveUrl(e)}}const p=(t,e=document)=>e.querySelector(t),m=(t,e=document)=>Array.from(e.querySelectorAll(t)),g=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function w(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function f(t,e=[]){return new Promise((i,s)=>{const n=t(...e);w(n)?n.then(i,s):i(n)})}function v(t){var e;null==(e=t=t||document.body)||e.getBoundingClientRect()}function y(t,e){const i=null==t?void 0:t.closest(`[${e}]`);return null!=i&&i.hasAttribute(e)?(null==i?void 0:i.getAttribute(e))||!0:void 0}class k{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating","is-leaving"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?m(this.selector):[]}add(...t){this.targets.forEach(e=>e.classList.add(...t))}remove(...t){this.targets.forEach(e=>e.classList.remove(...t))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}class b{constructor(t,e){this.id=void 0,this.state=void 0,this.from=void 0,this.to=void 0,this.containers=void 0,this.animation=void 0,this.trigger=void 0,this.cache=void 0,this.history=void 0,this.scroll=void 0,this.meta=void 0;const{to:i,from:s,hash:n,el:o,event:r}=e;this.id=Math.random(),this.state=1,this.from={url:null!=s?s:t.location.url,hash:t.location.hash},this.to={url:i,hash:n},this.containers=t.options.containers,this.animation={animate:!0,wait:!1,name:void 0,native:t.options.native,scope:t.options.animationScope,selector:t.options.animationSelector},this.trigger={el:o,event:r},this.cache={read:t.options.cache,write:t.options.cache},this.history={action:"push",popstate:!1,direction:void 0},this.scroll={reset:!0,target:void 0},this.meta={}}advance(t){this.state<t&&(this.state=t)}abort(){this.state=8}ignore(){this.state=10}get done(){return this.state>=7}get ignored(){return 10===this.state}}function S(t){return new b(this,t)}class E{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","visit:abort","visit:end"],this.nextHookId=0,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:++this.nextHookId,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,s){const[n,o,r]=this.parseCallArgs(t,e,i,s),{before:a,handler:l,after:h}=this.getHandlers(t,r);await this.run(a,n,o);const[c]=await this.run(l,n,o,!0);return await this.run(h,n,o),this.dispatchDomEvent(t,n,o),c}callSync(t,e,i,s){const[n,o,r]=this.parseCallArgs(t,e,i,s),{before:a,handler:l,after:h}=this.getHandlers(t,r);this.runSync(a,n,o);const[c]=this.runSync(l,n,o,!0);return this.runSync(h,n,o),this.dispatchDomEvent(t,n,o),c}parseCallArgs(t,e,i,s){return e instanceof b||"object"!=typeof e&&"function"!=typeof i?[e,i,s]:[void 0,e,i]}async run(t,e=this.swup.visit,i,s=!1){const n=[];for(const{hook:o,handler:r,defaultHandler:a,once:l}of t)if(null==e||!e.done){l&&this.off(o,r);try{const t=await f(r,[e,i,a]);n.push(t)}catch(t){if(s)throw t;console.error(`Error in hook '${o}':`,t)}}return n}runSync(t,e=this.swup.visit,i,s=!1){const n=[];for(const{hook:o,handler:r,defaultHandler:a,once:l}of t)if(null==e||!e.done){l&&this.off(o,r);try{const t=r(e,i,a);n.push(t),w(t)&&console.warn(`Swup will not await Promises in handler for synchronous hook '${o}'.`)}catch(t){if(s)throw t;console.error(`Error in hook '${o}':`,t)}}return n}getHandlers(t,e){const i=this.get(t);if(!i)return{found:!1,before:[],handler:[],after:[],replaced:!1};const s=Array.from(i.values()),n=this.sortRegistrations,o=s.filter(({before:t,replace:e})=>t&&!e).sort(n),r=s.filter(({replace:t})=>t).filter(t=>!0).sort(n),a=s.filter(({before:t,replace:e})=>!t&&!e).sort(n),l=r.length>0;let h=[];if(e&&(h=[{id:0,hook:t,handler:e}],l)){const i=r.length-1,{handler:s,once:n}=r[i],o=t=>{const i=r[t-1];return i?(e,s)=>i.handler(e,s,o(t-1)):e};h=[{id:0,hook:t,once:n,handler:s,defaultHandler:o(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,i){if(null!=e&&e.done)return;const s={hook:t,args:i,visit:e||this.swup.visit};document.dispatchEvent(new CustomEvent("swup:any",{detail:s,bubbles:!0})),document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:s,bubbles:!0}))}parseName(t){const[e,...s]=t.split(".");return[e,s.reduce((t,e)=>i({},t,{[e]:!0}),{})]}}const C=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let i=document.getElementById(t)||document.getElementById(e)||p(`a[name='${CSS.escape(t)}']`)||p(`a[name='${CSS.escape(e)}']`);return i||"top"!==t||(i=document.body),i},U="transition",$="animation";async function P({selector:t,elements:e}){if(!1===t&&!e)return;let i=[];if(e)i=Array.from(e);else if(t&&(i=m(t,document.body),!i.length))return void console.warn(`[swup] No elements found matching animationSelector \`${t}\``);const s=i.map(t=>function(t){const{type:e,timeout:i,propCount:s}=function(t){const e=window.getComputedStyle(t),i=x(e,`${U}Delay`),s=x(e,`${U}Duration`),n=A(i,s),o=x(e,`${$}Delay`),r=x(e,`${$}Duration`),a=A(o,r),l=Math.max(n,a),h=l>0?n>a?U:$:null;return{type:h,timeout:l,propCount:h?h===U?s.length:r.length:0}}(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=>{e.target===t&&((performance.now()-r)/1e3<e.elapsedTime||++a>=s&&l())};setTimeout(()=>{a<s&&l()},i+1),t.addEventListener(o,h)})}(t)).filter(t=>!1!==t);s.length?await Promise.all(s):t&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${t}\``)}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,i)=>H(e)+H(t[i])))}function H(t){return 1e3*parseFloat(t)}function I(t,e={},s={}){if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");if(this.shouldIgnoreVisit(t,{el:s.el,event:s.event}))return void window.location.assign(t);const{url:n,hash:o}=l.fromUrl(t),r=this.createVisit(i({},s,{to:n,hash:o}));this.performNavigation(r,e)}async function V(t,e={}){if(this.navigating){if(this.visit.state>=6)return t.state=2,void(this.onVisitEnd=()=>this.performNavigation(t,e));await this.hooks.call("visit:abort",this.visit,void 0),delete this.visit.to.document,this.visit.state=8}this.navigating=!0,this.visit=t;const{el:i}=t.trigger;e.referrer=e.referrer||this.location.url,!1===e.animate&&(t.animation.animate=!1),t.animation.animate||this.classes.clear();const n=e.history||y(i,"data-swup-history");"string"==typeof n&&["push","replace"].includes(n)&&(t.history.action=n);const a=e.animation||y(i,"data-swup-animation");var h,c;"string"==typeof a&&(t.animation.name=a),t.meta=e.meta||{},"object"==typeof e.cache?(t.cache.read=null!=(h=e.cache.read)?h:t.cache.read,t.cache.write=null!=(c=e.cache.write)?c:t.cache.write):void 0!==e.cache&&(t.cache={read:!!e.cache,write:!!e.cache}),delete e.cache;try{await this.hooks.call("visit:start",t,void 0),t.state=3;const i=this.hooks.call("page:load",t,{options:e},async(t,e)=>{let i;return t.cache.read&&(i=this.cache.get(t.to.url)),e.page=i||await this.fetchPage(t.to.url,e.options),e.cache=!!i,e.page});i.then(({html:e})=>{t.advance(5),t.to.html=e,t.to.document=(new DOMParser).parseFromString(e,"text/html")});const n=t.to.url+t.to.hash;if(t.history.popstate||("replace"===t.history.action||t.to.url===this.location.url?r(n):(this.currentHistoryIndex++,o(n,{index:this.currentHistoryIndex}))),this.location=l.fromUrl(n),t.history.popstate&&this.classes.add("is-popstate"),t.animation.name&&this.classes.add(`to-${s(t.animation.name)}`),t.animation.wait&&await i,t.ignored)throw new Error(`Visit to ${t.to.url} manually ignored`);if(t.done)return;if(await this.hooks.call("visit:transition",t,void 0,async()=>{if(!t.animation.animate)return await this.hooks.call("animation:skip",void 0),void await this.renderPage(t,await i);t.advance(4),await this.animatePageOut(t),t.animation.native&&document.startViewTransition?await document.startViewTransition(async()=>await this.renderPage(t,await i)).finished:await this.renderPage(t,await i),await this.animatePageIn(t)}),t.done)return;await this.hooks.call("visit:end",t,void 0,()=>this.classes.clear()),t.state=7,this.navigating=!1,this.onVisitEnd&&(this.onVisitEnd(),this.onVisitEnd=void 0)}catch(e){if(!e||null!=e&&e.aborted)return void t.advance(8);t.advance(9),console.error(e),this.options.skipPopStateHandling=()=>(window.location.assign(t.to.url+t.to.hash),!0),window.history.back()}finally{delete t.to.document}}const L=async function(t){await this.hooks.call("animation:out:start",t,void 0,()=>{this.classes.add("is-changing","is-animating","is-leaving")}),await this.hooks.call("animation:out:await",t,{skip:!1},(t,{skip:e})=>{if(!e)return this.awaitAnimations({selector:t.animation.selector})}),await this.hooks.call("animation:out:end",t,void 0)},q=function(t){var e;const i=t.to.document;if(!i)return!1;const s=(null==(e=i.querySelector("title"))?void 0:e.innerText)||"";document.title=s;const n=m('[data-swup-persist]:not([data-swup-persist=""])'),o=t.containers.map(t=>{const e=document.querySelector(t),s=i.querySelector(t);return e&&s?(e.replaceWith(s.cloneNode(!0)),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),s||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean);return n.forEach(t=>{const e=t.getAttribute("data-swup-persist"),i=p(`[data-swup-persist="${e}"]`);i&&i!==t&&i.replaceWith(t)}),o.length===t.containers.length},R=function(t){const e={behavior:"auto"},{target:s,reset:n}=t.scroll,o=null!=s?s:t.to.hash;let r=!1;return o&&(r=this.hooks.callSync("scroll:anchor",t,{hash:o,options:e},(t,{hash:e,options:i})=>{const s=this.getAnchorElement(e);return s&&s.scrollIntoView(i),!!s})),n&&!r&&(r=this.hooks.callSync("scroll:top",t,{options:e},(t,{options:e})=>(window.scrollTo(i({top:0,left:0},e)),!0))),r},T=async function(t){if(t.done)return;const e=this.hooks.call("animation:in:await",t,{skip:!1},(t,{skip:e})=>{if(!e)return this.awaitAnimations({selector:t.animation.selector})});await g(),await this.hooks.call("animation:in:start",t,void 0,()=>{this.classes.remove("is-animating")}),await e,await this.hooks.call("animation:in:end",t,void 0)},N=async function(t,e){if(t.done)return;t.advance(6);const{url:i}=e;this.isSameResolvedUrl(n(),i)||(r(i),this.location=l.fromUrl(i),t.to.url=this.location.url,t.to.hash=this.location.hash),await this.hooks.call("content:replace",t,{page:e},(t,{})=>{if(this.classes.remove("is-leaving"),t.animation.animate&&this.classes.add("is-rendering"),!this.replaceContent(t))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(this.classes.add("is-changing","is-animating","is-rendering"),t.animation.name&&this.classes.add(`to-${s(t.animation.name)}`))}),await this.hooks.call("content:scroll",t,void 0,()=>this.scrollToContent(t)),await this.hooks.call("page:view",t,{url:this.location.url,title:document.title})},O=function(t){var e;if(e=t,Boolean(null==e?void 0:e.isSwupPlugin)){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function D(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function M(t){return this.plugins.find(e=>"string"==typeof t?[`Swup${t}`,t].includes(e.name):e===t)}function W(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 j(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}const B={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],hooks:{},ignoreVisit:(t,{el:e}={})=>!(null==e||!e.closest("[data-no-swup]")),linkSelector:"a[href]",linkToSelf:"scroll",native:!1,plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>{var e;return"swup"!==(null==(e=t.state)?void 0:e.source)},timeout:0};class _{get currentPageUrl(){return this.location.url}constructor(t={}){var e,s;this.version="4.9.1",this.options=void 0,this.defaults=B,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.location=l.fromUrl(window.location.href),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.navigating=!1,this.onVisitEnd=void 0,this.use=O,this.unuse=D,this.findPlugin=M,this.log=()=>{},this.navigate=I,this.performNavigation=V,this.createVisit=S,this.delegateEvent=a,this.fetchPage=u,this.awaitAnimations=P,this.renderPage=N,this.replaceContent=q,this.animatePageIn=T,this.animatePageOut=L,this.scrollToContent=R,this.getAnchorElement=C,this.getCurrentUrl=n,this.resolveUrl=W,this.isSameResolvedUrl=j,this.options=i({},this.defaults,t),this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new d(this),this.classes=new k(this),this.hooks=new E(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=null!=(e=null==(s=window.history.state)?void 0:s.index)?e:1,this.enable()}async enable(){var t;const{linkSelector:e}=this.options;this.clickDelegate=this.delegateEvent(e,"click",this.handleLinkClick),window.addEventListener("popstate",this.handlePopState),this.options.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),this.options.native=this.options.native&&!!document.startViewTransition,this.options.plugins.forEach(t=>this.use(t));for(const[t,e]of Object.entries(this.options.hooks)){const[i,s]=this.hooks.parseName(t);this.hooks.on(i,e,s)}"swup"!==(null==(t=window.history.state)?void 0:t.source)&&r(null,{index:this.currentHistoryIndex}),await g(),await this.hooks.call("enable",void 0,void 0,()=>{const t=document.documentElement;t.classList.add("swup-enabled"),t.classList.toggle("swup-native",this.options.native)})}async destroy(){this.clickDelegate.destroy(),window.removeEventListener("popstate",this.handlePopState),this.cache.clear(),this.plugins.forEach(t=>this.unuse(t)),await this.hooks.call("disable",void 0,void 0,()=>{const t=document.documentElement;t.classList.remove("swup-enabled"),t.classList.remove("swup-native")}),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);if(this.shouldIgnoreVisit(i,{el:e,event:t}))return;if(this.navigating&&s===this.visit.to.url)return void t.preventDefault();const o=this.createVisit({to:s,hash:n,el:e,event:t});t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.callSync("link:newtab",o,{href:i}):0===t.button&&this.hooks.callSync("link:click",o,{el:e,event:t},()=>{var e;const i=null!=(e=o.from.url)?e:"";t.preventDefault(),s&&s!==i?this.isSameResolvedUrl(s,i)||this.performNavigation(o):n?this.hooks.callSync("link:anchor",o,{hash:n},()=>{r(s+n),this.scrollToContent(o)}):this.hooks.callSync("link:self",o,void 0,()=>{"navigate"===this.options.linkToSelf?this.performNavigation(o):(r(s),this.scrollToContent(o))})})}handlePopState(t){var e,i,s,o;const r=null!=(e=null==(i=t.state)?void 0:i.url)?e:window.location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(n(),this.location.url))return;const{url:a,hash:h}=l.fromUrl(r),c=this.createVisit({to:a,hash:h,event:t});c.history.popstate=!0;const u=null!=(s=null==(o=t.state)?void 0:o.index)?s:0;u&&u!==this.currentHistoryIndex&&(c.history.direction=u-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=u),c.animation.animate=!1,c.scroll.reset=!1,c.scroll.target=!1,this.options.animateHistoryBrowsing&&(c.animation.animate=!0,c.scroll.reset=!0),this.hooks.callSync("history:popstate",c,{event:t},()=>{this.performNavigation(c)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}export{l as Location,s as classify,o as createHistoryRecord,_ as default,a as delegateEvent,v as forceReflow,y as getContextualAttr,n as getCurrentUrl,w as isPromise,h as matchPath,g as nextTick,p as query,m as queryAll,f as runAsPromise,r as updateHistoryRecord};
|
|
1
|
+
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)({}).hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},i.apply(null,arguments)}const s=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",n=({hash:t}={})=>window.location.pathname+window.location.search+(t?window.location.hash:""),o=(t,e={})=>{const s=i({url:t=t||n({hash:!0}),random:Math.random(),source:"swup"},e);window.history.pushState(s,"",t)},r=(t=null,e={})=>{t=t||n({hash:!0});const s=i({},window.history.state||{},{url:t,random:Math.random(),source:"swup"},e);window.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),Object.setPrototypeOf(this,l.prototype)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new l(e)}static fromUrl(t){return new l(t)}}const h=(t,i)=>{Array.isArray(t)&&!t.length&&(t="");try{return e(t,i)}catch(e){throw new Error(`[swup] Error parsing path "${String(t)}":\n${String(e)}`,{cause:e})}};class c extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}async function u(t,e={}){var s;t=l.fromUrl(t).url;const{visit:n=this.visit}=e,o=i({},this.options.requestHeaders,e.headers),r=null!=(s=e.timeout)?s:this.options.timeout,a=new AbortController,{signal:h}=a;e=i({},e,{headers:o,signal:h});let u,d=!1,p=null;r&&r>0&&(p=setTimeout(()=>{d=!0,a.abort("timeout")},r));try{u=await this.hooks.call("fetch:request",n,{url:t,options:e},(t,{url:e,options:i})=>fetch(e,i)),p&&clearTimeout(p)}catch(e){if(d)throw this.hooks.call("fetch:timeout",n,{url:t}),new c(`Request timed out: ${t}`,{url:t,timedOut:d});if("AbortError"===(null==e?void 0:e.name)||h.aborted)throw new c(`Request aborted: ${t}`,{url:t,aborted:!0});throw e}const{status:m,url:g}=u,w=await u.text();if(500===m)throw this.hooks.call("fetch:error",n,{status:m,response:u,url:g}),new c(`Server error: ${g}`,{status:m,url:g});if(!w)throw new c(`Empty response: ${g}`,{status:m,url:g});const{url:f}=l.fromUrl(g),v={url:f,html:w};return!n.cache.write||e.method&&"GET"!==e.method||t!==f||this.cache.set(v.url,v),v}class d{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,s)=>{t.set(s,i({},e))}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?i({},e):e}set(t,e){e=i({},e,{url:t=this.resolve(t)}),this.pages.set(t,e),this.swup.hooks.callSync("cache:set",void 0,{page:e})}update(t,e){t=this.resolve(t);const s=i({},this.get(t),e,{url:t});this.pages.set(t,s)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0,void 0)}prune(t){this.pages.forEach((e,i)=>{t(i,e)&&this.delete(i)})}resolve(t){const{url:e}=l.fromUrl(t);return this.swup.resolveUrl(e)}}const p=(t,e=document)=>e.querySelector(t),m=(t,e=document)=>Array.from(e.querySelectorAll(t)),g=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function w(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function f(t,e=[]){return new Promise((i,s)=>{const n=t(...e);w(n)?n.then(i,s):i(n)})}function v(t){var e;null==(e=t=t||document.body)||e.getBoundingClientRect()}function y(t,e){const i=null==t?void 0:t.closest(`[${e}]`);return null!=i&&i.hasAttribute(e)?(null==i?void 0:i.getAttribute(e))||!0:void 0}class k{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating","is-leaving"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?m(this.selector):[]}add(...t){this.targets.forEach(e=>e.classList.add(...t))}remove(...t){this.targets.forEach(e=>e.classList.remove(...t))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}class b{constructor(t,e){this.id=void 0,this.state=void 0,this.from=void 0,this.to=void 0,this.containers=void 0,this.animation=void 0,this.trigger=void 0,this.cache=void 0,this.history=void 0,this.scroll=void 0,this.meta=void 0;const{to:i,from:s,hash:n,el:o,event:r}=e;this.id=Math.random(),this.state=1,this.from={url:null!=s?s:t.location.url,hash:t.location.hash},this.to={url:i,hash:n},this.containers=t.options.containers,this.animation={animate:!0,wait:!1,name:void 0,native:t.options.native,scope:t.options.animationScope,selector:t.options.animationSelector},this.trigger={el:o,event:r},this.cache={read:t.options.cache,write:t.options.cache},this.history={action:"push",popstate:!1,direction:void 0},this.scroll={reset:!0,target:void 0},this.meta={}}advance(t){this.state<t&&(this.state=t)}abort(){this.state=8}ignore(){this.state=10}get done(){return this.state>=7}get ignored(){return 10===this.state}}function S(t){return new b(this,t)}class E{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","visit:abort","visit:end"],this.nextHookId=0,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:++this.nextHookId,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,s){const[n,o,r]=this.parseCallArgs(t,e,i,s),{before:a,handler:l,after:h}=this.getHandlers(t,r);await this.run(a,n,o);const[c]=await this.run(l,n,o,!0);return await this.run(h,n,o),this.dispatchDomEvent(t,n,o),c}callSync(t,e,i,s){const[n,o,r]=this.parseCallArgs(t,e,i,s),{before:a,handler:l,after:h}=this.getHandlers(t,r);this.runSync(a,n,o);const[c]=this.runSync(l,n,o,!0);return this.runSync(h,n,o),this.dispatchDomEvent(t,n,o),c}parseCallArgs(t,e,i,s){return e instanceof b||"object"!=typeof e&&"function"!=typeof i?[e,i,s]:[void 0,e,i]}async run(t,e=this.swup.visit,i,s=!1){const n=[];for(const{hook:o,handler:r,defaultHandler:a,once:l}of t)if(null==e||!e.done){l&&this.off(o,r);try{const t=await f(r,[e,i,a]);n.push(t)}catch(t){if(s)throw t;console.error(`Error in hook '${o}':`,t)}}return n}runSync(t,e=this.swup.visit,i,s=!1){const n=[];for(const{hook:o,handler:r,defaultHandler:a,once:l}of t)if(null==e||!e.done){l&&this.off(o,r);try{const t=r(e,i,a);n.push(t),w(t)&&console.warn(`Swup will not await Promises in handler for synchronous hook '${o}'.`)}catch(t){if(s)throw t;console.error(`Error in hook '${o}':`,t)}}return n}getHandlers(t,e){const i=this.get(t);if(!i)return{found:!1,before:[],handler:[],after:[],replaced:!1};const s=Array.from(i.values()),n=this.sortRegistrations,o=s.filter(({before:t,replace:e})=>t&&!e).sort(n),r=s.filter(({replace:t})=>t).filter(t=>!0).sort(n),a=s.filter(({before:t,replace:e})=>!t&&!e).sort(n),l=r.length>0;let h=[];if(e&&(h=[{id:0,hook:t,handler:e}],l)){const i=r.length-1,{handler:s,once:n}=r[i],o=t=>{const i=r[t-1];return i?(e,s)=>i.handler(e,s,o(t-1)):e};h=[{id:0,hook:t,once:n,handler:s,defaultHandler:o(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,i){if(null!=e&&e.done)return;const s={hook:t,args:i,visit:e||this.swup.visit};document.dispatchEvent(new CustomEvent("swup:any",{detail:s,bubbles:!0})),document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:s,bubbles:!0}))}parseName(t){const[e,...s]=t.split(".");return[e,s.reduce((t,e)=>i({},t,{[e]:!0}),{})]}}const C=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let i=document.getElementById(t)||document.getElementById(e)||p(`a[name='${CSS.escape(t)}']`)||p(`a[name='${CSS.escape(e)}']`);return i||"top"!==t||(i=document.body),i},U="transition",$="animation";async function P({selector:t,elements:e}){if(!1===t&&!e)return;let i=[];if(e)i=Array.from(e);else if(t&&(i=m(t,document.body),!i.length))return void console.warn(`[swup] No elements found matching animationSelector \`${t}\``);const s=i.map(t=>function(t){const{type:e,timeout:i,propCount:s}=function(t){const e=window.getComputedStyle(t),i=x(e,`${U}Delay`),s=x(e,`${U}Duration`),n=A(i,s),o=x(e,`${$}Delay`),r=x(e,`${$}Duration`),a=A(o,r),l=Math.max(n,a),h=l>0?n>a?U:$:null;return{type:h,timeout:l,propCount:h?h===U?s.length:r.length:0}}(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=>{e.target===t&&((performance.now()-r)/1e3<e.elapsedTime||++a>=s&&l())};setTimeout(()=>{a<s&&l()},i+1),t.addEventListener(o,h)})}(t)).filter(t=>!1!==t);s.length?await Promise.all(s):t&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${t}\``)}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,i)=>H(e)+H(t[i])))}function H(t){return 1e3*parseFloat(t)}function I(t,e={},s={}){if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");if(this.shouldIgnoreVisit(t,{el:s.el,event:s.event}))return void window.location.assign(t);const{url:n,hash:o}=l.fromUrl(t),r=this.createVisit(i({},s,{to:n,hash:o}));this.performNavigation(r,e)}async function V(t,e={}){if(this.navigating){if(this.visit.state>=6)return t.state=2,void(this.onVisitEnd=()=>this.performNavigation(t,e));await this.hooks.call("visit:abort",this.visit,void 0),delete this.visit.to.document,this.visit.state=8}this.navigating=!0,this.visit=t;const{el:i}=t.trigger;e.referrer=e.referrer||this.location.url,!1===e.animate&&(t.animation.animate=!1),t.animation.animate||this.classes.clear();const n=e.history||y(i,"data-swup-history");"string"==typeof n&&["push","replace"].includes(n)&&(t.history.action=n);const a=e.animation||y(i,"data-swup-animation");var h,c;"string"==typeof a&&(t.animation.name=a),t.meta=e.meta||{},"object"==typeof e.cache?(t.cache.read=null!=(h=e.cache.read)?h:t.cache.read,t.cache.write=null!=(c=e.cache.write)?c:t.cache.write):void 0!==e.cache&&(t.cache={read:!!e.cache,write:!!e.cache}),delete e.cache;try{await this.hooks.call("visit:start",t,void 0),t.state=3;const i=this.hooks.call("page:load",t,{options:e},async(t,e)=>{let i;return t.cache.read&&(i=this.cache.get(t.to.url)),e.page=i||await this.fetchPage(t.to.url,e.options),e.cache=!!i,e.page});i.then(({html:e})=>{t.advance(5),t.to.html=e,t.to.document=(new DOMParser).parseFromString(e,"text/html")});const n=t.to.url+t.to.hash;if(t.history.popstate||("replace"===t.history.action||t.to.url===this.location.url?r(n):(this.currentHistoryIndex++,o(n,{index:this.currentHistoryIndex}))),this.location=l.fromUrl(n),t.history.popstate&&this.classes.add("is-popstate"),t.animation.name&&this.classes.add(`to-${s(t.animation.name)}`),t.animation.wait&&await i,t.ignored)throw new Error(`Visit to ${t.to.url} manually ignored`);if(t.done)return;if(await this.hooks.call("visit:transition",t,void 0,async()=>{if(!t.animation.animate)return await this.hooks.call("animation:skip",void 0),void await this.renderPage(t,await i);t.advance(4),await this.animatePageOut(t),t.animation.native&&document.startViewTransition?await document.startViewTransition(async()=>await this.renderPage(t,await i)).finished:await this.renderPage(t,await i),await this.animatePageIn(t)}),t.done)return;await this.hooks.call("visit:end",t,void 0,()=>this.classes.clear()),t.state=7,this.navigating=!1,this.onVisitEnd&&(this.onVisitEnd(),this.onVisitEnd=void 0)}catch(e){if(!e||null!=e&&e.aborted)return void t.advance(8);t.advance(9),console.error(e),this.options.skipPopStateHandling=()=>(window.location.assign(t.to.url+t.to.hash),!0),window.history.back()}finally{delete t.to.document}}const L=async function(t){await this.hooks.call("animation:out:start",t,void 0,()=>{this.classes.add("is-changing","is-animating","is-leaving")}),await this.hooks.call("animation:out:await",t,{skip:!1},(t,{skip:e})=>{if(!e)return this.awaitAnimations({selector:t.animation.selector})}),await this.hooks.call("animation:out:end",t,void 0)},q=function(t){var e;const i=t.to.document;if(!i)return!1;const s=(null==(e=i.querySelector("title"))?void 0:e.innerText)||"";document.title=s;const n=m('[data-swup-persist]:not([data-swup-persist=""])'),o=t.containers.map(t=>{const e=document.querySelector(t),s=i.querySelector(t);return e&&s?(e.replaceWith(s.cloneNode(!0)),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),s||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean);return n.forEach(t=>{const e=t.getAttribute("data-swup-persist"),i=p(`[data-swup-persist="${e}"]`);i&&i!==t&&i.replaceWith(t)}),o.length===t.containers.length},R=function(t){const e={behavior:"auto"},{target:s,reset:n}=t.scroll,o=null!=s?s:t.to.hash;let r=!1;return o&&(r=this.hooks.callSync("scroll:anchor",t,{hash:o,options:e},(t,{hash:e,options:i})=>{const s=this.getAnchorElement(e);return s&&s.scrollIntoView(i),!!s})),n&&!r&&(r=this.hooks.callSync("scroll:top",t,{options:e},(t,{options:e})=>(window.scrollTo(i({top:0,left:0},e)),!0))),r},T=async function(t){if(t.done)return;const e=this.hooks.call("animation:in:await",t,{skip:!1},(t,{skip:e})=>{if(!e)return this.awaitAnimations({selector:t.animation.selector})});await g(),await this.hooks.call("animation:in:start",t,void 0,()=>{this.classes.remove("is-animating")}),await e,await this.hooks.call("animation:in:end",t,void 0)},N=async function(t,e){if(t.done)return;t.advance(6);const{url:i}=e;this.isSameResolvedUrl(n(),i)||(r(i),this.location=l.fromUrl(i),t.to.url=this.location.url,t.to.hash=this.location.hash),await this.hooks.call("content:replace",t,{page:e},(t,{})=>{if(this.classes.remove("is-leaving"),t.animation.animate&&this.classes.add("is-rendering"),!this.replaceContent(t))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(this.classes.add("is-changing","is-animating","is-rendering"),t.animation.name&&this.classes.add(`to-${s(t.animation.name)}`))}),await this.hooks.call("content:scroll",t,void 0,()=>this.scrollToContent(t)),await this.hooks.call("page:view",t,{url:this.location.url,title:document.title})},O=function(t){var e;if(e=t,Boolean(null==e?void 0:e.isSwupPlugin)){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function D(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function M(t){return this.plugins.find(e=>"string"==typeof t?[`Swup${t}`,t].includes(e.name):e===t)}function W(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 j(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}const B={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],hooks:{},ignoreVisit:(t,{el:e}={})=>!(null==e||!e.closest("[data-no-swup]")),linkSelector:"a[href]",linkToSelf:"scroll",native:!1,plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>{var e;return"swup"!==(null==(e=t.state)?void 0:e.source)},timeout:0};class _{get currentPageUrl(){return this.location.url}constructor(t={}){var e,s;this.version="4.9.2",this.options=void 0,this.defaults=B,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.location=l.fromUrl(window.location.href),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.navigating=!1,this.onVisitEnd=void 0,this.use=O,this.unuse=D,this.findPlugin=M,this.log=()=>{},this.navigate=I,this.performNavigation=V,this.createVisit=S,this.delegateEvent=a,this.fetchPage=u,this.awaitAnimations=P,this.renderPage=N,this.replaceContent=q,this.animatePageIn=T,this.animatePageOut=L,this.scrollToContent=R,this.getAnchorElement=C,this.getCurrentUrl=n,this.resolveUrl=W,this.isSameResolvedUrl=j,this.options=i({},this.defaults,t),this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new d(this),this.classes=new k(this),this.hooks=new E(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=null!=(e=null==(s=window.history.state)?void 0:s.index)?e:1,this.enable()}async enable(){var t;const{linkSelector:e}=this.options;this.clickDelegate=this.delegateEvent(e,"click",this.handleLinkClick),window.addEventListener("popstate",this.handlePopState),this.options.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),this.options.native=this.options.native&&!!document.startViewTransition,this.options.plugins.forEach(t=>this.use(t));for(const[t,e]of Object.entries(this.options.hooks)){const[i,s]=this.hooks.parseName(t);this.hooks.on(i,e,s)}"swup"!==(null==(t=window.history.state)?void 0:t.source)&&r(null,{index:this.currentHistoryIndex}),await g(),await this.hooks.call("enable",void 0,void 0,()=>{const t=document.documentElement;t.classList.add("swup-enabled"),t.classList.toggle("swup-native",this.options.native)})}async destroy(){this.clickDelegate.destroy(),window.removeEventListener("popstate",this.handlePopState),this.cache.clear(),this.plugins.forEach(t=>this.unuse(t)),await this.hooks.call("disable",void 0,void 0,()=>{const t=document.documentElement;t.classList.remove("swup-enabled"),t.classList.remove("swup-native")}),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);if(this.shouldIgnoreVisit(i,{el:e,event:t}))return;if(this.navigating&&s===this.visit.to.url)return void t.preventDefault();const o=this.createVisit({to:s,hash:n,el:e,event:t});t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.callSync("link:newtab",o,{href:i}):0===t.button&&this.hooks.callSync("link:click",o,{el:e,event:t},()=>{var e;const i=null!=(e=o.from.url)?e:"";t.preventDefault(),s&&s!==i?this.isSameResolvedUrl(s,i)||this.performNavigation(o):n?this.hooks.callSync("link:anchor",o,{hash:n},()=>{r(s+n),this.scrollToContent(o)}):this.hooks.callSync("link:self",o,void 0,()=>{"navigate"===this.options.linkToSelf?this.performNavigation(o):(r(s),this.scrollToContent(o))})})}handlePopState(t){var e,i,s,o;const r=null!=(e=null==(i=t.state)?void 0:i.url)?e:window.location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(n(),this.location.url))return;const{url:a,hash:h}=l.fromUrl(r),c=this.createVisit({to:a,hash:h,event:t});c.history.popstate=!0;const u=null!=(s=null==(o=t.state)?void 0:o.index)?s:0;u&&u!==this.currentHistoryIndex&&(c.history.direction=u-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=u),c.animation.animate=!1,c.scroll.reset=!1,c.scroll.target=!1,this.options.animateHistoryBrowsing&&(c.animation.animate=!0,c.scroll.reset=!0),this.hooks.callSync("history:popstate",c,{event:t},()=>{this.performNavigation(c)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}export{l as Location,s as classify,o as createHistoryRecord,_ as default,a as delegateEvent,v as forceReflow,y as getContextualAttr,n as getCurrentUrl,w as isPromise,h as matchPath,g as nextTick,p as query,m as queryAll,f as runAsPromise,r as updateHistoryRecord};
|
|
2
2
|
//# sourceMappingURL=Swup.modern.js.map
|
package/dist/Swup.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
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||"",o=({hash:t}={})=>window.location.pathname+window.location.search+(t?window.location.hash:""),r=(t,e={})=>{const n={url:t=t||o({hash:!0}),random:Math.random(),source:"swup",...e};window.history.pushState(n,"",t)},i=(t=null,e={})=>{t=t||o({hash:!0});const n={...window.history.state||{},url:t,random:Math.random(),source:"swup",...e};window.history.replaceState(n,"",t)},s=(e,n,o,r)=>{const i=new AbortController;return r={...r,signal:i.signal},t(e,n,o,r),{destroy:()=>i.abort()}};class a extends URL{constructor(t,e=document.baseURI){super(t.toString(),e),Object.setPrototypeOf(this,a.prototype)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new a(e)}static fromUrl(t){return new a(t)}}const c=(t,n)=>{Array.isArray(t)&&!t.length&&(t="");try{return e(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${String(t)}":\n${String(e)}`,{cause:e})}},l=function(t,e={}){try{const o=this;function n(n){const{status:i,url:s}=u;return Promise.resolve(u.text()).then(function(n){if(500===i)throw o.hooks.call("fetch:error",r,{status:i,response:u,url:s}),new h(`Server error: ${s}`,{status:i,url:s});if(!n)throw new h(`Empty response: ${s}`,{status:i,url:s});const{url:c}=a.fromUrl(s),l={url:c,html:n};return!r.cache.write||e.method&&"GET"!==e.method||t!==c||o.cache.set(l.url,l),l})}t=a.fromUrl(t).url;const{visit:r=o.visit}=e,i={...o.options.requestHeaders,...e.headers},s=e.timeout??o.options.timeout,c=new AbortController,{signal:l}=c;e={...e,headers:i,signal:l};let u,d=!1,m=null;s&&s>0&&(m=setTimeout(()=>{d=!0,c.abort("timeout")},s));const f=function(n,i){try{var s=Promise.resolve(o.hooks.call("fetch:request",r,{url:t,options:e},(t,{url:e,options:n})=>fetch(e,n))).then(function(t){u=t,m&&clearTimeout(m)})}catch(t){return i(t)}return s&&s.then?s.then(void 0,i):s}(0,function(e){if(d)throw o.hooks.call("fetch:timeout",r,{url:t}),new h(`Request timed out: ${t}`,{url:t,timedOut:d});if("AbortError"===e?.name||l.aborted)throw new h(`Request aborted: ${t}`,{url:t,aborted:!0});throw e});return Promise.resolve(f&&f.then?f.then(n):n())}catch(p){return Promise.reject(p)}};class h extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}class u{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,n)=>{t.set(n,{...e})}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?{...e}:e}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",void 0,{page:e})}update(t,e){t=this.resolve(t);const n={...this.get(t),...e,url:t};this.pages.set(t,n)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0,void 0)}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=a.fromUrl(t);return this.swup.resolveUrl(e)}}const d=(t,e=document)=>e.querySelector(t),m=(t,e=document)=>Array.from(e.querySelectorAll(t)),f=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function p(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function v(t,e=[]){return new Promise((n,o)=>{const r=t(...e);p(r)?r.then(n,o):n(r)})}function g(t){t=t||document.body,t?.getBoundingClientRect()}function w(t,e){const n=t?.closest(`[${e}]`);return n?.hasAttribute(e)?n?.getAttribute(e)||!0:void 0}class y{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating","is-leaving"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?m(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}class k{constructor(t,e){this.id=void 0,this.state=void 0,this.from=void 0,this.to=void 0,this.containers=void 0,this.animation=void 0,this.trigger=void 0,this.cache=void 0,this.history=void 0,this.scroll=void 0,this.meta=void 0;const{to:n,from:o,hash:r,el:i,event:s}=e;this.id=Math.random(),this.state=1,this.from={url:o??t.location.url,hash:t.location.hash},this.to={url:n,hash:r},this.containers=t.options.containers,this.animation={animate:!0,wait:!1,name:void 0,native:t.options.native,scope:t.options.animationScope,selector:t.options.animationSelector},this.trigger={el:i,event:s},this.cache={read:t.options.cache,write:t.options.cache},this.history={action:"push",popstate:!1,direction:void 0},this.scroll={reset:!0,target:void 0},this.meta={}}advance(t){this.state<t&&(this.state=t)}abort(){this.state=8}ignore(){this.state=10}get done(){return this.state>=7}get ignored(){return 10===this.state}}function P(t){return new k(this,t)}const b="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function S(t,e,n){if(!t.s){if(n instanceof E){if(!n.s)return void(n.o=S.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(S.bind(null,t,e),S.bind(null,t,2));t.s=e,t.v=n;const o=t.o;o&&o(t)}}const E=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const o=new t,r=this.s;if(r){const t=1&r?e:n;if(t){try{S(o,1,t(this.v))}catch(t){S(o,2,t)}return o}return this}return this.o=function(t){try{const r=t.v;1&t.s?S(o,1,e?e(r):r):n?S(o,1,n(r)):S(o,2,r)}catch(t){S(o,2,t)}},o},t}();function C(t){return t instanceof E&&1&t.s}class U{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","visit:abort","visit:end"],this.nextHookId=0,this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n={}){const o=this.get(t);if(!o)return console.warn(`Hook '${t}' not found.`),()=>{};const r={...n,id:++this.nextHookId,hook:t,handler:e};return o.set(e,r),()=>this.off(t,e)}before(t,e,n={}){return this.on(t,e,{...n,before:!0})}replace(t,e,n={}){return this.on(t,e,{...n,replace:!0})}once(t,e,n={}){return this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n,o){try{const r=this,[i,s,a]=r.parseCallArgs(t,e,n,o),{before:c,handler:l,after:h}=r.getHandlers(t,a);return Promise.resolve(r.run(c,i,s)).then(function(){return Promise.resolve(r.run(l,i,s,!0)).then(function([e]){return Promise.resolve(r.run(h,i,s)).then(function(){return r.dispatchDomEvent(t,i,s),e})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n,o){const[r,i,s]=this.parseCallArgs(t,e,n,o),{before:a,handler:c,after:l}=this.getHandlers(t,s);this.runSync(a,r,i);const[h]=this.runSync(c,r,i,!0);return this.runSync(l,r,i),this.dispatchDomEvent(t,r,i),h}parseCallArgs(t,e,n,o){return e instanceof k||"object"!=typeof e&&"function"!=typeof n?[e,n,o]:[void 0,e,n]}run(t,e,n,o=!1){try{let r;const i=this;void 0===e&&(e=i.swup.visit);const s=[],a=function(t,e,n){if("function"==typeof t[b]){var o,r,i,s=t[b]();if(function t(a){try{for(;!((o=s.next()).done||n&&n());)if((a=e(o.value))&&a.then){if(!C(a))return void a.then(t,i||(i=S.bind(null,r=new E,2)));a=a.v}r?S(r,1,a):r=a}catch(t){S(r||(r=new E),2,t)}}(),s.return){var a=function(t){try{o.done||s.return()}catch(t){}return t};if(r&&r.then)return r.then(a,function(t){throw a(t)});a()}return r}if(!("length"in t))throw new TypeError("Object is not iterable");for(var c=[],l=0;l<t.length;l++)c.push(t[l]);return function(t,e,n){var o,r,i=-1;return function s(a){try{for(;++i<t.length&&(!n||!n());)if((a=e(i))&&a.then){if(!C(a))return void a.then(s,r||(r=S.bind(null,o=new E,2)));a=a.v}o?S(o,1,a):o=a}catch(t){S(o||(o=new E),2,t)}}(),o}(c,function(t){return e(c[t])},n)}(t,function({hook:t,handler:r,defaultHandler:a,once:c}){if(!e?.done)return c&&i.off(t,r),function(t,o){try{var i=Promise.resolve(v(r,[e,n,a])).then(function(t){s.push(t)})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(o)throw e;console.error(`Error in hook '${t}':`,e)})},function(){return r});return Promise.resolve(a&&a.then?a.then(function(t){return r?t:s}):r?a:s)}catch(t){return Promise.reject(t)}}runSync(t,e=this.swup.visit,n,o=!1){const r=[];for(const{hook:i,handler:s,defaultHandler:a,once:c}of t)if(!e?.done){c&&this.off(i,s);try{const t=s(e,n,a);r.push(t),p(t)&&console.warn(`Swup will not await Promises in handler for synchronous hook '${i}'.`)}catch(t){if(o)throw t;console.error(`Error in hook '${i}':`,t)}}return r}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const o=Array.from(n.values()),r=this.sortRegistrations,i=o.filter(({before:t,replace:e})=>t&&!e).sort(r),s=o.filter(({replace:t})=>t).filter(t=>!0).sort(r),a=o.filter(({before:t,replace:e})=>!t&&!e).sort(r),c=s.length>0;let l=[];if(e&&(l=[{id:0,hook:t,handler:e}],c)){const n=s.length-1,{handler:o,once:r}=s[n],i=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,i(t-1)):e};l=[{id:0,hook:t,once:r,handler:o,defaultHandler:i(n)}]}return{found:!0,before:i,handler:l,after:a,replaced:c}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e,n){if(e?.done)return;const o={hook:t,args:n,visit:e||this.swup.visit};document.dispatchEvent(new CustomEvent("swup:any",{detail:o,bubbles:!0})),document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:o,bubbles:!0}))}parseName(t){const[e,...n]=t.split(".");return[e,n.reduce((t,e)=>({...t,[e]:!0}),{})]}}const $=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||d(`a[name='${CSS.escape(t)}']`)||d(`a[name='${CSS.escape(e)}']`);return n||"top"!==t||(n=document.body),n},x=function({selector:t,elements:e}){try{if(!1===t&&!e)return Promise.resolve();let n=[];if(e)n=Array.from(e);else if(t&&(n=m(t,document.body),!n.length))return console.warn(`[swup] No elements found matching animationSelector \`${t}\``),Promise.resolve();const o=n.map(t=>function(t){const{type:e,timeout:n,propCount:o}=function(t){const e=window.getComputedStyle(t),n=j(e,`${A}Delay`),o=j(e,`${A}Duration`),r=I(n,o),i=j(e,`${H}Delay`),s=j(e,`${H}Duration`),a=I(i,s),c=Math.max(r,a),l=c>0?r>a?A:H:null;return{type:l,timeout:c,propCount:l?l===A?o.length:s.length:0}}(t);return!(!e||!n)&&new Promise(r=>{const i=`${e}end`,s=performance.now();let a=0;const c=()=>{t.removeEventListener(i,l),r()},l=e=>{e.target===t&&((performance.now()-s)/1e3<e.elapsedTime||++a>=o&&c())};setTimeout(()=>{a<o&&c()},n+1),t.addEventListener(i,l)})}(t)).filter(t=>!1!==t);return o.length?Promise.resolve(Promise.all(o)).then(function(){}):(t&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${t}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},A="transition",H="animation";function j(t,e){return(t[e]||"").split(", ")}function I(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>V(e)+V(t[n])))}function V(t){return 1e3*parseFloat(t)}const L=function(t,e={}){try{let s;const c=this;function o(o){if(s)return o;c.navigating=!0,c.visit=t;const{el:l}=t.trigger;e.referrer=e.referrer||c.location.url,!1===e.animate&&(t.animation.animate=!1),t.animation.animate||c.classes.clear();const h=e.history||w(l,"data-swup-history");"string"==typeof h&&["push","replace"].includes(h)&&(t.history.action=h);const u=e.animation||w(l,"data-swup-animation");return"string"==typeof u&&(t.animation.name=u),t.meta=e.meta||{},"object"==typeof e.cache?(t.cache.read=e.cache.read??t.cache.read,t.cache.write=e.cache.write??t.cache.write):void 0!==e.cache&&(t.cache={read:!!e.cache,write:!!e.cache}),delete e.cache,function(o,s){try{var l=function(o,s){try{var l=Promise.resolve(c.hooks.call("visit:start",t,void 0)).then(function(){function o(){if(t.ignored)throw new Error(`Visit to ${t.to.url} manually ignored`);if(!t.done)return Promise.resolve(c.hooks.call("visit:transition",t,void 0,function(){try{let n;function e(e){return n?e:(t.advance(4),Promise.resolve(c.animatePageOut(t)).then(function(){function e(){return Promise.resolve(c.animatePageIn(t)).then(function(){})}const n=function(){if(t.animation.native&&document.startViewTransition)return Promise.resolve(document.startViewTransition(function(){try{const e=c.renderPage;return Promise.resolve(s).then(function(n){return Promise.resolve(e.call(c,t,n))})}catch(t){return Promise.reject(t)}}).finished).then(function(){});{const e=c.renderPage;return Promise.resolve(s).then(function(n){return Promise.resolve(e.call(c,t,n)).then(function(){})})}}();return n&&n.then?n.then(e):e()}))}const o=function(){if(!t.animation.animate)return Promise.resolve(c.hooks.call("animation:skip",void 0)).then(function(){const e=c.renderPage;return Promise.resolve(s).then(function(o){return Promise.resolve(e.call(c,t,o)).then(function(){n=1})})})}();return Promise.resolve(o&&o.then?o.then(e):e(o))}catch(r){return Promise.reject(r)}})).then(function(){if(!t.done)return Promise.resolve(c.hooks.call("visit:end",t,void 0,()=>c.classes.clear())).then(function(){t.state=7,c.navigating=!1,c.onVisitEnd&&(c.onVisitEnd(),c.onVisitEnd=void 0)})})}t.state=3;const s=c.hooks.call("page:load",t,{options:e},function(t,e){try{function n(t){return e.page=t,e.cache=!!o,e.page}let o;return t.cache.read&&(o=c.cache.get(t.to.url)),Promise.resolve(o?n(o):Promise.resolve(c.fetchPage(t.to.url,e.options)).then(n))}catch(r){return Promise.reject(r)}});s.then(({html:e})=>{t.advance(5),t.to.html=e,t.to.document=(new DOMParser).parseFromString(e,"text/html")});const l=t.to.url+t.to.hash;t.history.popstate||("replace"===t.history.action||t.to.url===c.location.url?i(l):(c.currentHistoryIndex++,r(l,{index:c.currentHistoryIndex}))),c.location=a.fromUrl(l),t.history.popstate&&c.classes.add("is-popstate"),t.animation.name&&c.classes.add(`to-${n(t.animation.name)}`);const h=function(){if(t.animation.wait)return Promise.resolve(s).then(function(){})}();return h&&h.then?h.then(o):o()})}catch(t){return s(t)}return l&&l.then?l.then(void 0,s):l}(0,function(e){e&&!e?.aborted?(t.advance(9),console.error(e),c.options.skipPopStateHandling=()=>(window.location.assign(t.to.url+t.to.hash),!0),window.history.back()):t.advance(8)})}catch(t){return s(!0,t)}return l&&l.then?l.then(s.bind(null,!1),s.bind(null,!0)):s(!1,l)}(0,function(e,n){if(delete t.to.document,e)throw n;return n})}const l=function(){if(c.navigating)return function(){if(!(c.visit.state>=6))return Promise.resolve(c.hooks.call("visit:abort",c.visit,void 0)).then(function(){delete c.visit.to.document,c.visit.state=8});t.state=2,c.onVisitEnd=()=>c.performNavigation(t,e),s=1}()}();return Promise.resolve(l&&l.then?l.then(o):o(l))}catch(h){return Promise.reject(h)}};function T(t,e={},n={}){if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");if(this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void window.location.assign(t);const{url:o,hash:r}=a.fromUrl(t),i=this.createVisit({...n,to:o,hash:r});this.performNavigation(i,e)}const q=function(t){try{const e=this;return Promise.resolve(e.hooks.call("animation:out:start",t,void 0,()=>{e.classes.add("is-changing","is-animating","is-leaving")})).then(function(){return Promise.resolve(e.hooks.call("animation:out:await",t,{skip:!1},(t,{skip:n})=>{if(!n)return e.awaitAnimations({selector:t.animation.selector})})).then(function(){return Promise.resolve(e.hooks.call("animation:out:end",t,void 0)).then(function(){})})})}catch(t){return Promise.reject(t)}},R=function(t){const e=t.to.document;if(!e)return!1;const n=e.querySelector("title")?.innerText||"";document.title=n;const o=m('[data-swup-persist]:not([data-swup-persist=""])'),r=t.containers.map(t=>{const n=document.querySelector(t),o=e.querySelector(t);return n&&o?(n.replaceWith(o.cloneNode(!0)),!0):(n||console.warn(`[swup] Container missing in current document: ${t}`),o||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean);return o.forEach(t=>{const e=t.getAttribute("data-swup-persist"),n=d(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),r.length===t.containers.length},N=function(t){const e={behavior:"auto"},{target:n,reset:o}=t.scroll,r=n??t.to.hash;let i=!1;return r&&(i=this.hooks.callSync("scroll:anchor",t,{hash:r,options:e},(t,{hash:e,options:n})=>{const o=this.getAnchorElement(e);return o&&o.scrollIntoView(n),!!o})),o&&!i&&(i=this.hooks.callSync("scroll:top",t,{options:e},(t,{options:e})=>(window.scrollTo({top:0,left:0,...e}),!0))),i},D=function(t){try{const e=this;if(t.done)return Promise.resolve();const n=e.hooks.call("animation:in:await",t,{skip:!1},(t,{skip:n})=>{if(!n)return e.awaitAnimations({selector:t.animation.selector})});return Promise.resolve(f()).then(function(){return Promise.resolve(e.hooks.call("animation:in:start",t,void 0,()=>{e.classes.remove("is-animating")})).then(function(){return Promise.resolve(n).then(function(){return Promise.resolve(e.hooks.call("animation:in:end",t,void 0)).then(function(){})})})})}catch(t){return Promise.reject(t)}},O=function(t,e){try{const r=this;if(t.done)return Promise.resolve();t.advance(6);const{url:s}=e;return r.isSameResolvedUrl(o(),s)||(i(s),r.location=a.fromUrl(s),t.to.url=r.location.url,t.to.hash=r.location.hash),Promise.resolve(r.hooks.call("content:replace",t,{page:e},(t,{})=>{if(r.classes.remove("is-leaving"),t.animation.animate&&r.classes.add("is-rendering"),!r.replaceContent(t))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(r.classes.add("is-changing","is-animating","is-rendering"),t.animation.name&&r.classes.add(`to-${n(t.animation.name)}`))})).then(function(){return Promise.resolve(r.hooks.call("content:scroll",t,void 0,()=>r.scrollToContent(t))).then(function(){return Promise.resolve(r.hooks.call("page:view",t,{url:r.location.url,title:document.title})).then(function(){})})})}catch(t){return Promise.reject(t)}},M=function(t){var e;if(e=t,Boolean(e?.isSwupPlugin)){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function W(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function B(t){return this.plugins.find(e=>"string"==typeof t?[`Swup${t}`,t].includes(e.name):e===t)}function _(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function F(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}const K={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],hooks:{},ignoreVisit:(t,{el:e}={})=>!!e?.closest("[data-no-swup]"),linkSelector:"a[href]",linkToSelf:"scroll",native:!1,plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source,timeout:0};class z{get currentPageUrl(){return this.location.url}constructor(t={}){this.version="4.9.1",this.options=void 0,this.defaults=K,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.location=a.fromUrl(window.location.href),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.navigating=!1,this.onVisitEnd=void 0,this.use=M,this.unuse=W,this.findPlugin=B,this.log=()=>{},this.navigate=T,this.performNavigation=L,this.createVisit=P,this.delegateEvent=s,this.fetchPage=l,this.awaitAnimations=x,this.renderPage=O,this.replaceContent=R,this.animatePageIn=D,this.animatePageOut=q,this.scrollToContent=N,this.getAnchorElement=$,this.getCurrentUrl=o,this.resolveUrl=_,this.isSameResolvedUrl=F,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new u(this),this.classes=new y(this),this.hooks=new U(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=window.history.state?.index??1,this.enable()}enable(){try{const t=this,{linkSelector:e}=t.options;t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),t.options.native=t.options.native&&!!document.startViewTransition,t.options.plugins.forEach(e=>t.use(e));for(const[e,n]of Object.entries(t.options.hooks)){const[o,r]=t.hooks.parseName(e);t.hooks.on(o,n,r)}return"swup"!==window.history.state?.source&&i(null,{index:t.currentHistoryIndex}),Promise.resolve(f()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,void 0,()=>{const e=document.documentElement;e.classList.add("swup-enabled"),e.classList.toggle("swup-native",t.options.native)})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,void 0,()=>{const t=document.documentElement;t.classList.remove("swup-enabled"),t.classList.remove("swup-native")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,{el:e,event:n}={}){const{origin:o,url:r,hash:i}=a.fromUrl(t);return o!==window.location.origin||!(!e||!this.triggerWillOpenNewWindow(e))||!!this.options.ignoreVisit(r+i,{el:e,event:n})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:o,hash:r}=a.fromElement(e);if(this.shouldIgnoreVisit(n,{el:e,event:t}))return;if(this.navigating&&o===this.visit.to.url)return void t.preventDefault();const s=this.createVisit({to:o,hash:r,el:e,event:t});t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.callSync("link:newtab",s,{href:n}):0===t.button&&this.hooks.callSync("link:click",s,{el:e,event:t},()=>{const e=s.from.url??"";t.preventDefault(),o&&o!==e?this.isSameResolvedUrl(o,e)||this.performNavigation(s):r?this.hooks.callSync("link:anchor",s,{hash:r},()=>{i(o+r),this.scrollToContent(s)}):this.hooks.callSync("link:self",s,void 0,()=>{"navigate"===this.options.linkToSelf?this.performNavigation(s):(i(o),this.scrollToContent(s))})})}handlePopState(t){const e=t.state?.url??window.location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(o(),this.location.url))return;const{url:n,hash:r}=a.fromUrl(e),i=this.createVisit({to:n,hash:r,event:t});i.history.popstate=!0;const s=t.state?.index??0;s&&s!==this.currentHistoryIndex&&(i.history.direction=s-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=s),i.animation.animate=!1,i.scroll.reset=!1,i.scroll.target=!1,this.options.animateHistoryBrowsing&&(i.animation.animate=!0,i.scroll.reset=!0),this.hooks.callSync("history:popstate",i,{event:t},()=>{this.performNavigation(i)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}export{a as Location,n as classify,r as createHistoryRecord,z as default,s as delegateEvent,g as forceReflow,w as getContextualAttr,o as getCurrentUrl,p as isPromise,c as matchPath,f as nextTick,d as query,m as queryAll,v as runAsPromise,i as updateHistoryRecord};
|
|
1
|
+
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||"",o=({hash:t}={})=>window.location.pathname+window.location.search+(t?window.location.hash:""),r=(t,e={})=>{const n={url:t=t||o({hash:!0}),random:Math.random(),source:"swup",...e};window.history.pushState(n,"",t)},i=(t=null,e={})=>{t=t||o({hash:!0});const n={...window.history.state||{},url:t,random:Math.random(),source:"swup",...e};window.history.replaceState(n,"",t)},s=(e,n,o,r)=>{const i=new AbortController;return r={...r,signal:i.signal},t(e,n,o,r),{destroy:()=>i.abort()}};class a extends URL{constructor(t,e=document.baseURI){super(t.toString(),e),Object.setPrototypeOf(this,a.prototype)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new a(e)}static fromUrl(t){return new a(t)}}const c=(t,n)=>{Array.isArray(t)&&!t.length&&(t="");try{return e(t,n)}catch(e){throw new Error(`[swup] Error parsing path "${String(t)}":\n${String(e)}`,{cause:e})}},l=function(t,e={}){try{const o=this;function n(n){const{status:i,url:s}=u;return Promise.resolve(u.text()).then(function(n){if(500===i)throw o.hooks.call("fetch:error",r,{status:i,response:u,url:s}),new h(`Server error: ${s}`,{status:i,url:s});if(!n)throw new h(`Empty response: ${s}`,{status:i,url:s});const{url:c}=a.fromUrl(s),l={url:c,html:n};return!r.cache.write||e.method&&"GET"!==e.method||t!==c||o.cache.set(l.url,l),l})}t=a.fromUrl(t).url;const{visit:r=o.visit}=e,i={...o.options.requestHeaders,...e.headers},s=e.timeout??o.options.timeout,c=new AbortController,{signal:l}=c;e={...e,headers:i,signal:l};let u,d=!1,m=null;s&&s>0&&(m=setTimeout(()=>{d=!0,c.abort("timeout")},s));const f=function(n,i){try{var s=Promise.resolve(o.hooks.call("fetch:request",r,{url:t,options:e},(t,{url:e,options:n})=>fetch(e,n))).then(function(t){u=t,m&&clearTimeout(m)})}catch(t){return i(t)}return s&&s.then?s.then(void 0,i):s}(0,function(e){if(d)throw o.hooks.call("fetch:timeout",r,{url:t}),new h(`Request timed out: ${t}`,{url:t,timedOut:d});if("AbortError"===e?.name||l.aborted)throw new h(`Request aborted: ${t}`,{url:t,aborted:!0});throw e});return Promise.resolve(f&&f.then?f.then(n):n())}catch(p){return Promise.reject(p)}};class h extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}class u{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,n)=>{t.set(n,{...e})}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?{...e}:e}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",void 0,{page:e})}update(t,e){t=this.resolve(t);const n={...this.get(t),...e,url:t};this.pages.set(t,n)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0,void 0)}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=a.fromUrl(t);return this.swup.resolveUrl(e)}}const d=(t,e=document)=>e.querySelector(t),m=(t,e=document)=>Array.from(e.querySelectorAll(t)),f=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function p(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function v(t,e=[]){return new Promise((n,o)=>{const r=t(...e);p(r)?r.then(n,o):n(r)})}function g(t){t=t||document.body,t?.getBoundingClientRect()}function w(t,e){const n=t?.closest(`[${e}]`);return n?.hasAttribute(e)?n?.getAttribute(e)||!0:void 0}class y{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating","is-leaving"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?m(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}class k{constructor(t,e){this.id=void 0,this.state=void 0,this.from=void 0,this.to=void 0,this.containers=void 0,this.animation=void 0,this.trigger=void 0,this.cache=void 0,this.history=void 0,this.scroll=void 0,this.meta=void 0;const{to:n,from:o,hash:r,el:i,event:s}=e;this.id=Math.random(),this.state=1,this.from={url:o??t.location.url,hash:t.location.hash},this.to={url:n,hash:r},this.containers=t.options.containers,this.animation={animate:!0,wait:!1,name:void 0,native:t.options.native,scope:t.options.animationScope,selector:t.options.animationSelector},this.trigger={el:i,event:s},this.cache={read:t.options.cache,write:t.options.cache},this.history={action:"push",popstate:!1,direction:void 0},this.scroll={reset:!0,target:void 0},this.meta={}}advance(t){this.state<t&&(this.state=t)}abort(){this.state=8}ignore(){this.state=10}get done(){return this.state>=7}get ignored(){return 10===this.state}}function P(t){return new k(this,t)}const b="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function S(t,e,n){if(!t.s){if(n instanceof E){if(!n.s)return void(n.o=S.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(S.bind(null,t,e),S.bind(null,t,2));t.s=e,t.v=n;const o=t.o;o&&o(t)}}const E=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const o=new t,r=this.s;if(r){const t=1&r?e:n;if(t){try{S(o,1,t(this.v))}catch(t){S(o,2,t)}return o}return this}return this.o=function(t){try{const r=t.v;1&t.s?S(o,1,e?e(r):r):n?S(o,1,n(r)):S(o,2,r)}catch(t){S(o,2,t)}},o},t}();function C(t){return t instanceof E&&1&t.s}class U{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","visit:abort","visit:end"],this.nextHookId=0,this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n={}){const o=this.get(t);if(!o)return console.warn(`Hook '${t}' not found.`),()=>{};const r={...n,id:++this.nextHookId,hook:t,handler:e};return o.set(e,r),()=>this.off(t,e)}before(t,e,n={}){return this.on(t,e,{...n,before:!0})}replace(t,e,n={}){return this.on(t,e,{...n,replace:!0})}once(t,e,n={}){return this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n,o){try{const r=this,[i,s,a]=r.parseCallArgs(t,e,n,o),{before:c,handler:l,after:h}=r.getHandlers(t,a);return Promise.resolve(r.run(c,i,s)).then(function(){return Promise.resolve(r.run(l,i,s,!0)).then(function([e]){return Promise.resolve(r.run(h,i,s)).then(function(){return r.dispatchDomEvent(t,i,s),e})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n,o){const[r,i,s]=this.parseCallArgs(t,e,n,o),{before:a,handler:c,after:l}=this.getHandlers(t,s);this.runSync(a,r,i);const[h]=this.runSync(c,r,i,!0);return this.runSync(l,r,i),this.dispatchDomEvent(t,r,i),h}parseCallArgs(t,e,n,o){return e instanceof k||"object"!=typeof e&&"function"!=typeof n?[e,n,o]:[void 0,e,n]}run(t,e,n,o=!1){try{let r;const i=this;void 0===e&&(e=i.swup.visit);const s=[],a=function(t,e,n){if("function"==typeof t[b]){var o,r,i,s=t[b]();if(function t(a){try{for(;!((o=s.next()).done||n&&n());)if((a=e(o.value))&&a.then){if(!C(a))return void a.then(t,i||(i=S.bind(null,r=new E,2)));a=a.v}r?S(r,1,a):r=a}catch(t){S(r||(r=new E),2,t)}}(),s.return){var a=function(t){try{o.done||s.return()}catch(t){}return t};if(r&&r.then)return r.then(a,function(t){throw a(t)});a()}return r}if(!("length"in t))throw new TypeError("Object is not iterable");for(var c=[],l=0;l<t.length;l++)c.push(t[l]);return function(t,e,n){var o,r,i=-1;return function s(a){try{for(;++i<t.length&&(!n||!n());)if((a=e(i))&&a.then){if(!C(a))return void a.then(s,r||(r=S.bind(null,o=new E,2)));a=a.v}o?S(o,1,a):o=a}catch(t){S(o||(o=new E),2,t)}}(),o}(c,function(t){return e(c[t])},n)}(t,function({hook:t,handler:r,defaultHandler:a,once:c}){if(!e?.done)return c&&i.off(t,r),function(t,o){try{var i=Promise.resolve(v(r,[e,n,a])).then(function(t){s.push(t)})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(o)throw e;console.error(`Error in hook '${t}':`,e)})},function(){return r});return Promise.resolve(a&&a.then?a.then(function(t){return r?t:s}):r?a:s)}catch(t){return Promise.reject(t)}}runSync(t,e=this.swup.visit,n,o=!1){const r=[];for(const{hook:i,handler:s,defaultHandler:a,once:c}of t)if(!e?.done){c&&this.off(i,s);try{const t=s(e,n,a);r.push(t),p(t)&&console.warn(`Swup will not await Promises in handler for synchronous hook '${i}'.`)}catch(t){if(o)throw t;console.error(`Error in hook '${i}':`,t)}}return r}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const o=Array.from(n.values()),r=this.sortRegistrations,i=o.filter(({before:t,replace:e})=>t&&!e).sort(r),s=o.filter(({replace:t})=>t).filter(t=>!0).sort(r),a=o.filter(({before:t,replace:e})=>!t&&!e).sort(r),c=s.length>0;let l=[];if(e&&(l=[{id:0,hook:t,handler:e}],c)){const n=s.length-1,{handler:o,once:r}=s[n],i=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,i(t-1)):e};l=[{id:0,hook:t,once:r,handler:o,defaultHandler:i(n)}]}return{found:!0,before:i,handler:l,after:a,replaced:c}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e,n){if(e?.done)return;const o={hook:t,args:n,visit:e||this.swup.visit};document.dispatchEvent(new CustomEvent("swup:any",{detail:o,bubbles:!0})),document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:o,bubbles:!0}))}parseName(t){const[e,...n]=t.split(".");return[e,n.reduce((t,e)=>({...t,[e]:!0}),{})]}}const $=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||d(`a[name='${CSS.escape(t)}']`)||d(`a[name='${CSS.escape(e)}']`);return n||"top"!==t||(n=document.body),n},x=function({selector:t,elements:e}){try{if(!1===t&&!e)return Promise.resolve();let n=[];if(e)n=Array.from(e);else if(t&&(n=m(t,document.body),!n.length))return console.warn(`[swup] No elements found matching animationSelector \`${t}\``),Promise.resolve();const o=n.map(t=>function(t){const{type:e,timeout:n,propCount:o}=function(t){const e=window.getComputedStyle(t),n=j(e,`${A}Delay`),o=j(e,`${A}Duration`),r=I(n,o),i=j(e,`${H}Delay`),s=j(e,`${H}Duration`),a=I(i,s),c=Math.max(r,a),l=c>0?r>a?A:H:null;return{type:l,timeout:c,propCount:l?l===A?o.length:s.length:0}}(t);return!(!e||!n)&&new Promise(r=>{const i=`${e}end`,s=performance.now();let a=0;const c=()=>{t.removeEventListener(i,l),r()},l=e=>{e.target===t&&((performance.now()-s)/1e3<e.elapsedTime||++a>=o&&c())};setTimeout(()=>{a<o&&c()},n+1),t.addEventListener(i,l)})}(t)).filter(t=>!1!==t);return o.length?Promise.resolve(Promise.all(o)).then(function(){}):(t&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${t}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},A="transition",H="animation";function j(t,e){return(t[e]||"").split(", ")}function I(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>V(e)+V(t[n])))}function V(t){return 1e3*parseFloat(t)}const L=function(t,e={}){try{let s;const c=this;function o(o){if(s)return o;c.navigating=!0,c.visit=t;const{el:l}=t.trigger;e.referrer=e.referrer||c.location.url,!1===e.animate&&(t.animation.animate=!1),t.animation.animate||c.classes.clear();const h=e.history||w(l,"data-swup-history");"string"==typeof h&&["push","replace"].includes(h)&&(t.history.action=h);const u=e.animation||w(l,"data-swup-animation");return"string"==typeof u&&(t.animation.name=u),t.meta=e.meta||{},"object"==typeof e.cache?(t.cache.read=e.cache.read??t.cache.read,t.cache.write=e.cache.write??t.cache.write):void 0!==e.cache&&(t.cache={read:!!e.cache,write:!!e.cache}),delete e.cache,function(o,s){try{var l=function(o,s){try{var l=Promise.resolve(c.hooks.call("visit:start",t,void 0)).then(function(){function o(){if(t.ignored)throw new Error(`Visit to ${t.to.url} manually ignored`);if(!t.done)return Promise.resolve(c.hooks.call("visit:transition",t,void 0,function(){try{let n;function e(e){return n?e:(t.advance(4),Promise.resolve(c.animatePageOut(t)).then(function(){function e(){return Promise.resolve(c.animatePageIn(t)).then(function(){})}const n=function(){if(t.animation.native&&document.startViewTransition)return Promise.resolve(document.startViewTransition(function(){try{const e=c.renderPage;return Promise.resolve(s).then(function(n){return Promise.resolve(e.call(c,t,n))})}catch(t){return Promise.reject(t)}}).finished).then(function(){});{const e=c.renderPage;return Promise.resolve(s).then(function(n){return Promise.resolve(e.call(c,t,n)).then(function(){})})}}();return n&&n.then?n.then(e):e()}))}const o=function(){if(!t.animation.animate)return Promise.resolve(c.hooks.call("animation:skip",void 0)).then(function(){const e=c.renderPage;return Promise.resolve(s).then(function(o){return Promise.resolve(e.call(c,t,o)).then(function(){n=1})})})}();return Promise.resolve(o&&o.then?o.then(e):e(o))}catch(r){return Promise.reject(r)}})).then(function(){if(!t.done)return Promise.resolve(c.hooks.call("visit:end",t,void 0,()=>c.classes.clear())).then(function(){t.state=7,c.navigating=!1,c.onVisitEnd&&(c.onVisitEnd(),c.onVisitEnd=void 0)})})}t.state=3;const s=c.hooks.call("page:load",t,{options:e},function(t,e){try{function n(t){return e.page=t,e.cache=!!o,e.page}let o;return t.cache.read&&(o=c.cache.get(t.to.url)),Promise.resolve(o?n(o):Promise.resolve(c.fetchPage(t.to.url,e.options)).then(n))}catch(r){return Promise.reject(r)}});s.then(({html:e})=>{t.advance(5),t.to.html=e,t.to.document=(new DOMParser).parseFromString(e,"text/html")});const l=t.to.url+t.to.hash;t.history.popstate||("replace"===t.history.action||t.to.url===c.location.url?i(l):(c.currentHistoryIndex++,r(l,{index:c.currentHistoryIndex}))),c.location=a.fromUrl(l),t.history.popstate&&c.classes.add("is-popstate"),t.animation.name&&c.classes.add(`to-${n(t.animation.name)}`);const h=function(){if(t.animation.wait)return Promise.resolve(s).then(function(){})}();return h&&h.then?h.then(o):o()})}catch(t){return s(t)}return l&&l.then?l.then(void 0,s):l}(0,function(e){e&&!e?.aborted?(t.advance(9),console.error(e),c.options.skipPopStateHandling=()=>(window.location.assign(t.to.url+t.to.hash),!0),window.history.back()):t.advance(8)})}catch(t){return s(!0,t)}return l&&l.then?l.then(s.bind(null,!1),s.bind(null,!0)):s(!1,l)}(0,function(e,n){if(delete t.to.document,e)throw n;return n})}const l=function(){if(c.navigating)return function(){if(!(c.visit.state>=6))return Promise.resolve(c.hooks.call("visit:abort",c.visit,void 0)).then(function(){delete c.visit.to.document,c.visit.state=8});t.state=2,c.onVisitEnd=()=>c.performNavigation(t,e),s=1}()}();return Promise.resolve(l&&l.then?l.then(o):o(l))}catch(h){return Promise.reject(h)}};function T(t,e={},n={}){if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");if(this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void window.location.assign(t);const{url:o,hash:r}=a.fromUrl(t),i=this.createVisit({...n,to:o,hash:r});this.performNavigation(i,e)}const q=function(t){try{const e=this;return Promise.resolve(e.hooks.call("animation:out:start",t,void 0,()=>{e.classes.add("is-changing","is-animating","is-leaving")})).then(function(){return Promise.resolve(e.hooks.call("animation:out:await",t,{skip:!1},(t,{skip:n})=>{if(!n)return e.awaitAnimations({selector:t.animation.selector})})).then(function(){return Promise.resolve(e.hooks.call("animation:out:end",t,void 0)).then(function(){})})})}catch(t){return Promise.reject(t)}},R=function(t){const e=t.to.document;if(!e)return!1;const n=e.querySelector("title")?.innerText||"";document.title=n;const o=m('[data-swup-persist]:not([data-swup-persist=""])'),r=t.containers.map(t=>{const n=document.querySelector(t),o=e.querySelector(t);return n&&o?(n.replaceWith(o.cloneNode(!0)),!0):(n||console.warn(`[swup] Container missing in current document: ${t}`),o||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean);return o.forEach(t=>{const e=t.getAttribute("data-swup-persist"),n=d(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),r.length===t.containers.length},N=function(t){const e={behavior:"auto"},{target:n,reset:o}=t.scroll,r=n??t.to.hash;let i=!1;return r&&(i=this.hooks.callSync("scroll:anchor",t,{hash:r,options:e},(t,{hash:e,options:n})=>{const o=this.getAnchorElement(e);return o&&o.scrollIntoView(n),!!o})),o&&!i&&(i=this.hooks.callSync("scroll:top",t,{options:e},(t,{options:e})=>(window.scrollTo({top:0,left:0,...e}),!0))),i},D=function(t){try{const e=this;if(t.done)return Promise.resolve();const n=e.hooks.call("animation:in:await",t,{skip:!1},(t,{skip:n})=>{if(!n)return e.awaitAnimations({selector:t.animation.selector})});return Promise.resolve(f()).then(function(){return Promise.resolve(e.hooks.call("animation:in:start",t,void 0,()=>{e.classes.remove("is-animating")})).then(function(){return Promise.resolve(n).then(function(){return Promise.resolve(e.hooks.call("animation:in:end",t,void 0)).then(function(){})})})})}catch(t){return Promise.reject(t)}},O=function(t,e){try{const r=this;if(t.done)return Promise.resolve();t.advance(6);const{url:s}=e;return r.isSameResolvedUrl(o(),s)||(i(s),r.location=a.fromUrl(s),t.to.url=r.location.url,t.to.hash=r.location.hash),Promise.resolve(r.hooks.call("content:replace",t,{page:e},(t,{})=>{if(r.classes.remove("is-leaving"),t.animation.animate&&r.classes.add("is-rendering"),!r.replaceContent(t))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(r.classes.add("is-changing","is-animating","is-rendering"),t.animation.name&&r.classes.add(`to-${n(t.animation.name)}`))})).then(function(){return Promise.resolve(r.hooks.call("content:scroll",t,void 0,()=>r.scrollToContent(t))).then(function(){return Promise.resolve(r.hooks.call("page:view",t,{url:r.location.url,title:document.title})).then(function(){})})})}catch(t){return Promise.reject(t)}},M=function(t){var e;if(e=t,Boolean(e?.isSwupPlugin)){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function W(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function B(t){return this.plugins.find(e=>"string"==typeof t?[`Swup${t}`,t].includes(e.name):e===t)}function _(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function F(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}const K={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],hooks:{},ignoreVisit:(t,{el:e}={})=>!!e?.closest("[data-no-swup]"),linkSelector:"a[href]",linkToSelf:"scroll",native:!1,plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source,timeout:0};class z{get currentPageUrl(){return this.location.url}constructor(t={}){this.version="4.9.2",this.options=void 0,this.defaults=K,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.location=a.fromUrl(window.location.href),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.navigating=!1,this.onVisitEnd=void 0,this.use=M,this.unuse=W,this.findPlugin=B,this.log=()=>{},this.navigate=T,this.performNavigation=L,this.createVisit=P,this.delegateEvent=s,this.fetchPage=l,this.awaitAnimations=x,this.renderPage=O,this.replaceContent=R,this.animatePageIn=D,this.animatePageOut=q,this.scrollToContent=N,this.getAnchorElement=$,this.getCurrentUrl=o,this.resolveUrl=_,this.isSameResolvedUrl=F,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new u(this),this.classes=new y(this),this.hooks=new U(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=window.history.state?.index??1,this.enable()}enable(){try{const t=this,{linkSelector:e}=t.options;t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),t.options.native=t.options.native&&!!document.startViewTransition,t.options.plugins.forEach(e=>t.use(e));for(const[e,n]of Object.entries(t.options.hooks)){const[o,r]=t.hooks.parseName(e);t.hooks.on(o,n,r)}return"swup"!==window.history.state?.source&&i(null,{index:t.currentHistoryIndex}),Promise.resolve(f()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,void 0,()=>{const e=document.documentElement;e.classList.add("swup-enabled"),e.classList.toggle("swup-native",t.options.native)})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,void 0,()=>{const t=document.documentElement;t.classList.remove("swup-enabled"),t.classList.remove("swup-native")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,{el:e,event:n}={}){const{origin:o,url:r,hash:i}=a.fromUrl(t);return o!==window.location.origin||!(!e||!this.triggerWillOpenNewWindow(e))||!!this.options.ignoreVisit(r+i,{el:e,event:n})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:o,hash:r}=a.fromElement(e);if(this.shouldIgnoreVisit(n,{el:e,event:t}))return;if(this.navigating&&o===this.visit.to.url)return void t.preventDefault();const s=this.createVisit({to:o,hash:r,el:e,event:t});t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.callSync("link:newtab",s,{href:n}):0===t.button&&this.hooks.callSync("link:click",s,{el:e,event:t},()=>{const e=s.from.url??"";t.preventDefault(),o&&o!==e?this.isSameResolvedUrl(o,e)||this.performNavigation(s):r?this.hooks.callSync("link:anchor",s,{hash:r},()=>{i(o+r),this.scrollToContent(s)}):this.hooks.callSync("link:self",s,void 0,()=>{"navigate"===this.options.linkToSelf?this.performNavigation(s):(i(o),this.scrollToContent(s))})})}handlePopState(t){const e=t.state?.url??window.location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(o(),this.location.url))return;const{url:n,hash:r}=a.fromUrl(e),i=this.createVisit({to:n,hash:r,event:t});i.history.popstate=!0;const s=t.state?.index??0;s&&s!==this.currentHistoryIndex&&(i.history.direction=s-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=s),i.animation.animate=!1,i.scroll.reset=!1,i.scroll.target=!1,this.options.animateHistoryBrowsing&&(i.animation.animate=!0,i.scroll.reset=!0),this.hooks.callSync("history:popstate",i,{event:t},()=>{this.performNavigation(i)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}export{a as Location,n as classify,r as createHistoryRecord,z as default,s as delegateEvent,g as forceReflow,w as getContextualAttr,o as getCurrentUrl,p as isPromise,c as matchPath,f as nextTick,d as query,m as queryAll,v as runAsPromise,i as updateHistoryRecord};
|
|
2
2
|
//# sourceMappingURL=Swup.module.js.map
|
package/dist/Swup.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t||self).Swup=e()}(this,function(){const t=new WeakMap;function e(e,n,o,i){if(!e&&!t.has(n))return!1;const r=t.get(n)??new WeakMap;t.set(n,r);const s=r.get(o)??new Set;r.set(o,s);const a=s.has(i);return e?s.add(i):s.delete(i),a&&e}const n=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",o=({hash:t}={})=>window.location.pathname+window.location.search+(t?window.location.hash:""),i=(t=null,e={})=>{t=t||o({hash:!0});const n={...window.history.state||{},url:t,random:Math.random(),source:"swup",...e};window.history.replaceState(n,"",t)},r=(t,n,o,i)=>{const r=new AbortController;return function(t,n,o,i={}){const{signal:r,base:s=document}=i;if(r?.aborted)return;const{once:a,...c}=i,l=s instanceof Document?s.documentElement:s,h=Boolean("object"==typeof i?i.capture:i),u=i=>{const r=function(t,e){let n=t.target;if(n instanceof Text&&(n=n.parentElement),n instanceof Element&&t.currentTarget instanceof Node){const o=n.closest(e);if(o&&t.currentTarget.contains(o))return o}}(i,String(t));if(r){const t=Object.assign(i,{delegateTarget:r});o.call(l,t),a&&(l.removeEventListener(n,u,c),e(!1,l,o,d))}},d=JSON.stringify({selector:t,type:n,capture:h});e(!0,l,o,d)||l.addEventListener(n,u,c),r?.addEventListener("abort",()=>{e(!1,l,o,d)})}(t,n,o,i={...i,signal:r.signal}),{destroy:()=>r.abort()}};class s extends URL{constructor(t,e=document.baseURI){super(t.toString(),e),Object.setPrototypeOf(this,s.prototype)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new s(e)}static fromUrl(t){return new s(t)}}const a=function(t,e={}){try{const o=this;function n(n){const{status:r,url:a}=u;return Promise.resolve(u.text()).then(function(n){if(500===r)throw o.hooks.call("fetch:error",i,{status:r,response:u,url:a}),new c(`Server error: ${a}`,{status:r,url:a});if(!n)throw new c(`Empty response: ${a}`,{status:r,url:a});const{url:l}=s.fromUrl(a),h={url:l,html:n};return!i.cache.write||e.method&&"GET"!==e.method||t!==l||o.cache.set(h.url,h),h})}t=s.fromUrl(t).url;const{visit:i=o.visit}=e,r={...o.options.requestHeaders,...e.headers},a=e.timeout??o.options.timeout,l=new AbortController,{signal:h}=l;e={...e,headers:r,signal:h};let u,d=!1,f=null;a&&a>0&&(f=setTimeout(()=>{d=!0,l.abort("timeout")},a));const m=function(n,r){try{var s=Promise.resolve(o.hooks.call("fetch:request",i,{url:t,options:e},(t,{url:e,options:n})=>fetch(e,n))).then(function(t){u=t,f&&clearTimeout(f)})}catch(t){return r(t)}return s&&s.then?s.then(void 0,r):s}(0,function(e){if(d)throw o.hooks.call("fetch:timeout",i,{url:t}),new c(`Request timed out: ${t}`,{url:t,timedOut:d});if("AbortError"===e?.name||h.aborted)throw new c(`Request aborted: ${t}`,{url:t,aborted:!0});throw e});return Promise.resolve(m&&m.then?m.then(n):n())}catch(p){return Promise.reject(p)}};class c extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}class l{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,n)=>{t.set(n,{...e})}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?{...e}:e}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",void 0,{page:e})}update(t,e){t=this.resolve(t);const n={...this.get(t),...e,url:t};this.pages.set(t,n)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0,void 0)}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=s.fromUrl(t);return this.swup.resolveUrl(e)}}const h=(t,e=document)=>e.querySelector(t),u=(t,e=document)=>Array.from(e.querySelectorAll(t)),d=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function f(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function m(t,e){const n=t?.closest(`[${e}]`);return n?.hasAttribute(e)?n?.getAttribute(e)||!0:void 0}class p{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating","is-leaving"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?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))}}class v{constructor(t,e){this.id=void 0,this.state=void 0,this.from=void 0,this.to=void 0,this.containers=void 0,this.animation=void 0,this.trigger=void 0,this.cache=void 0,this.history=void 0,this.scroll=void 0,this.meta=void 0;const{to:n,from:o,hash:i,el:r,event:s}=e;this.id=Math.random(),this.state=1,this.from={url:o??t.location.url,hash:t.location.hash},this.to={url:n,hash:i},this.containers=t.options.containers,this.animation={animate:!0,wait:!1,name:void 0,native:t.options.native,scope:t.options.animationScope,selector:t.options.animationSelector},this.trigger={el:r,event:s},this.cache={read:t.options.cache,write:t.options.cache},this.history={action:"push",popstate:!1,direction:void 0},this.scroll={reset:!0,target:void 0},this.meta={}}advance(t){this.state<t&&(this.state=t)}abort(){this.state=8}ignore(){this.state=10}get done(){return this.state>=7}get ignored(){return 10===this.state}}function g(t){return new v(this,t)}const w="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function y(t,e,n){if(!t.s){if(n instanceof k){if(!n.s)return void(n.o=y.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(y.bind(null,t,e),y.bind(null,t,2));t.s=e,t.v=n;const o=t.o;o&&o(t)}}const k=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const o=new t,i=this.s;if(i){const t=1&i?e:n;if(t){try{y(o,1,t(this.v))}catch(t){y(o,2,t)}return o}return this}return this.o=function(t){try{const i=t.v;1&t.s?y(o,1,e?e(i):i):n?y(o,1,n(i)):y(o,2,i)}catch(t){y(o,2,t)}},o},t}();function P(t){return t instanceof k&&1&t.s}class b{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","visit:abort","visit:end"],this.nextHookId=0,this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n={}){const o=this.get(t);if(!o)return console.warn(`Hook '${t}' not found.`),()=>{};const i={...n,id:++this.nextHookId,hook:t,handler:e};return o.set(e,i),()=>this.off(t,e)}before(t,e,n={}){return this.on(t,e,{...n,before:!0})}replace(t,e,n={}){return this.on(t,e,{...n,replace:!0})}once(t,e,n={}){return this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n,o){try{const i=this,[r,s,a]=i.parseCallArgs(t,e,n,o),{before:c,handler:l,after:h}=i.getHandlers(t,a);return Promise.resolve(i.run(c,r,s)).then(function(){return Promise.resolve(i.run(l,r,s,!0)).then(function([e]){return Promise.resolve(i.run(h,r,s)).then(function(){return i.dispatchDomEvent(t,r,s),e})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n,o){const[i,r,s]=this.parseCallArgs(t,e,n,o),{before:a,handler:c,after:l}=this.getHandlers(t,s);this.runSync(a,i,r);const[h]=this.runSync(c,i,r,!0);return this.runSync(l,i,r),this.dispatchDomEvent(t,i,r),h}parseCallArgs(t,e,n,o){return e instanceof v||"object"!=typeof e&&"function"!=typeof n?[e,n,o]:[void 0,e,n]}run(t,e,n,o=!1){try{let i;const r=this;void 0===e&&(e=r.swup.visit);const s=[],a=function(t,e,n){if("function"==typeof t[w]){var o,i,r,s=t[w]();if(function t(a){try{for(;!((o=s.next()).done||n&&n());)if((a=e(o.value))&&a.then){if(!P(a))return void a.then(t,r||(r=y.bind(null,i=new k,2)));a=a.v}i?y(i,1,a):i=a}catch(t){y(i||(i=new k),2,t)}}(),s.return){var a=function(t){try{o.done||s.return()}catch(t){}return t};if(i&&i.then)return i.then(a,function(t){throw a(t)});a()}return i}if(!("length"in t))throw new TypeError("Object is not iterable");for(var c=[],l=0;l<t.length;l++)c.push(t[l]);return function(t,e,n){var o,i,r=-1;return function s(a){try{for(;++r<t.length&&(!n||!n());)if((a=e(r))&&a.then){if(!P(a))return void a.then(s,i||(i=y.bind(null,o=new k,2)));a=a.v}o?y(o,1,a):o=a}catch(t){y(o||(o=new k),2,t)}}(),o}(c,function(t){return e(c[t])},n)}(t,function({hook:t,handler:i,defaultHandler:a,once:c}){if(!e?.done)return c&&r.off(t,i),function(t,o){try{var r=Promise.resolve(function(t,e=[]){return new Promise((n,o)=>{const i=t(...e);f(i)?i.then(n,o):n(i)})}(i,[e,n,a])).then(function(t){s.push(t)})}catch(t){return o(t)}return r&&r.then?r.then(void 0,o):r}(0,function(e){if(o)throw e;console.error(`Error in hook '${t}':`,e)})},function(){return i});return Promise.resolve(a&&a.then?a.then(function(t){return i?t:s}):i?a:s)}catch(t){return Promise.reject(t)}}runSync(t,e=this.swup.visit,n,o=!1){const i=[];for(const{hook:r,handler:s,defaultHandler:a,once:c}of t)if(!e?.done){c&&this.off(r,s);try{const t=s(e,n,a);i.push(t),f(t)&&console.warn(`Swup will not await Promises in handler for synchronous hook '${r}'.`)}catch(t){if(o)throw t;console.error(`Error in hook '${r}':`,t)}}return i}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const o=Array.from(n.values()),i=this.sortRegistrations,r=o.filter(({before:t,replace:e})=>t&&!e).sort(i),s=o.filter(({replace:t})=>t).filter(t=>!0).sort(i),a=o.filter(({before:t,replace:e})=>!t&&!e).sort(i),c=s.length>0;let l=[];if(e&&(l=[{id:0,hook:t,handler:e}],c)){const n=s.length-1,{handler:o,once:i}=s[n],r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};l=[{id:0,hook:t,once:i,handler:o,defaultHandler:r(n)}]}return{found:!0,before:r,handler:l,after:a,replaced:c}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e,n){if(e?.done)return;const o={hook:t,args:n,visit:e||this.swup.visit};document.dispatchEvent(new CustomEvent("swup:any",{detail:o,bubbles:!0})),document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:o,bubbles:!0}))}parseName(t){const[e,...n]=t.split(".");return[e,n.reduce((t,e)=>({...t,[e]:!0}),{})]}}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)||h(`a[name='${CSS.escape(t)}']`)||h(`a[name='${CSS.escape(e)}']`);return n||"top"!==t||(n=document.body),n},E=function({selector:t,elements:e}){try{if(!1===t&&!e)return Promise.resolve();let n=[];if(e)n=Array.from(e);else if(t&&(n=u(t,document.body),!n.length))return console.warn(`[swup] No elements found matching animationSelector \`${t}\``),Promise.resolve();const o=n.map(t=>function(t){const{type:e,timeout:n,propCount:o}=function(t){const e=window.getComputedStyle(t),n=x(e,`${C}Delay`),o=x(e,`${C}Duration`),i=$(n,o),r=x(e,`${U}Delay`),s=x(e,`${U}Duration`),a=$(r,s),c=Math.max(i,a),l=c>0?i>a?C:U:null;return{type:l,timeout:c,propCount:l?l===C?o.length:s.length:0}}(t);return!(!e||!n)&&new Promise(i=>{const r=`${e}end`,s=performance.now();let a=0;const c=()=>{t.removeEventListener(r,l),i()},l=e=>{e.target===t&&((performance.now()-s)/1e3<e.elapsedTime||++a>=o&&c())};setTimeout(()=>{a<o&&c()},n+1),t.addEventListener(r,l)})}(t)).filter(t=>!1!==t);return o.length?Promise.resolve(Promise.all(o)).then(function(){}):(t&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${t}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},C="transition",U="animation";function x(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)=>A(e)+A(t[n])))}function A(t){return 1e3*parseFloat(t)}const H=function(t,e={}){try{let a;const c=this;function r(r){if(a)return r;c.navigating=!0,c.visit=t;const{el:l}=t.trigger;e.referrer=e.referrer||c.location.url,!1===e.animate&&(t.animation.animate=!1),t.animation.animate||c.classes.clear();const h=e.history||m(l,"data-swup-history");"string"==typeof h&&["push","replace"].includes(h)&&(t.history.action=h);const u=e.animation||m(l,"data-swup-animation");return"string"==typeof u&&(t.animation.name=u),t.meta=e.meta||{},"object"==typeof e.cache?(t.cache.read=e.cache.read??t.cache.read,t.cache.write=e.cache.write??t.cache.write):void 0!==e.cache&&(t.cache={read:!!e.cache,write:!!e.cache}),delete e.cache,function(r,a){try{var l=function(r,a){try{var l=Promise.resolve(c.hooks.call("visit:start",t,void 0)).then(function(){function r(){if(t.ignored)throw new Error(`Visit to ${t.to.url} manually ignored`);if(!t.done)return Promise.resolve(c.hooks.call("visit:transition",t,void 0,function(){try{let n;function e(e){return n?e:(t.advance(4),Promise.resolve(c.animatePageOut(t)).then(function(){function e(){return Promise.resolve(c.animatePageIn(t)).then(function(){})}const n=function(){if(t.animation.native&&document.startViewTransition)return Promise.resolve(document.startViewTransition(function(){try{const e=c.renderPage;return Promise.resolve(a).then(function(n){return Promise.resolve(e.call(c,t,n))})}catch(t){return Promise.reject(t)}}).finished).then(function(){});{const e=c.renderPage;return Promise.resolve(a).then(function(n){return Promise.resolve(e.call(c,t,n)).then(function(){})})}}();return n&&n.then?n.then(e):e()}))}const o=function(){if(!t.animation.animate)return Promise.resolve(c.hooks.call("animation:skip",void 0)).then(function(){const e=c.renderPage;return Promise.resolve(a).then(function(o){return Promise.resolve(e.call(c,t,o)).then(function(){n=1})})})}();return Promise.resolve(o&&o.then?o.then(e):e(o))}catch(i){return Promise.reject(i)}})).then(function(){if(!t.done)return Promise.resolve(c.hooks.call("visit:end",t,void 0,()=>c.classes.clear())).then(function(){t.state=7,c.navigating=!1,c.onVisitEnd&&(c.onVisitEnd(),c.onVisitEnd=void 0)})})}t.state=3;const a=c.hooks.call("page:load",t,{options:e},function(t,e){try{function n(t){return e.page=t,e.cache=!!o,e.page}let o;return t.cache.read&&(o=c.cache.get(t.to.url)),Promise.resolve(o?n(o):Promise.resolve(c.fetchPage(t.to.url,e.options)).then(n))}catch(i){return Promise.reject(i)}});a.then(({html:e})=>{t.advance(5),t.to.html=e,t.to.document=(new DOMParser).parseFromString(e,"text/html")});const l=t.to.url+t.to.hash;t.history.popstate||("replace"===t.history.action||t.to.url===c.location.url?i(l):(c.currentHistoryIndex++,((t,e={})=>{const n={url:t=t||o({hash:!0}),random:Math.random(),source:"swup",...e};window.history.pushState(n,"",t)})(l,{index:c.currentHistoryIndex}))),c.location=s.fromUrl(l),t.history.popstate&&c.classes.add("is-popstate"),t.animation.name&&c.classes.add(`to-${n(t.animation.name)}`);const h=function(){if(t.animation.wait)return Promise.resolve(a).then(function(){})}();return h&&h.then?h.then(r):r()})}catch(t){return a(t)}return l&&l.then?l.then(void 0,a):l}(0,function(e){e&&!e?.aborted?(t.advance(9),console.error(e),c.options.skipPopStateHandling=()=>(window.location.assign(t.to.url+t.to.hash),!0),window.history.back()):t.advance(8)})}catch(t){return a(!0,t)}return l&&l.then?l.then(a.bind(null,!1),a.bind(null,!0)):a(!1,l)}(0,function(e,n){if(delete t.to.document,e)throw n;return n})}const l=function(){if(c.navigating)return function(){if(!(c.visit.state>=6))return Promise.resolve(c.hooks.call("visit:abort",c.visit,void 0)).then(function(){delete c.visit.to.document,c.visit.state=8});t.state=2,c.onVisitEnd=()=>c.performNavigation(t,e),a=1}()}();return Promise.resolve(l&&l.then?l.then(r):r(l))}catch(h){return Promise.reject(h)}};function T(t,e={},n={}){if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");if(this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void window.location.assign(t);const{url:o,hash:i}=s.fromUrl(t),r=this.createVisit({...n,to:o,hash:i});this.performNavigation(r,e)}const j=function(t){try{const e=this;return Promise.resolve(e.hooks.call("animation:out:start",t,void 0,()=>{e.classes.add("is-changing","is-animating","is-leaving")})).then(function(){return Promise.resolve(e.hooks.call("animation:out:await",t,{skip:!1},(t,{skip:n})=>{if(!n)return e.awaitAnimations({selector:t.animation.selector})})).then(function(){return Promise.resolve(e.hooks.call("animation:out:end",t,void 0)).then(function(){})})})}catch(t){return Promise.reject(t)}},L=function(t){const e=t.to.document;if(!e)return!1;const n=e.querySelector("title")?.innerText||"";document.title=n;const o=u('[data-swup-persist]:not([data-swup-persist=""])'),i=t.containers.map(t=>{const n=document.querySelector(t),o=e.querySelector(t);return n&&o?(n.replaceWith(o.cloneNode(!0)),!0):(n||console.warn(`[swup] Container missing in current document: ${t}`),o||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean);return o.forEach(t=>{const e=t.getAttribute("data-swup-persist"),n=h(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),i.length===t.containers.length},I=function(t){const e={behavior:"auto"},{target:n,reset:o}=t.scroll,i=n??t.to.hash;let r=!1;return i&&(r=this.hooks.callSync("scroll:anchor",t,{hash:i,options:e},(t,{hash:e,options:n})=>{const o=this.getAnchorElement(e);return o&&o.scrollIntoView(n),!!o})),o&&!r&&(r=this.hooks.callSync("scroll:top",t,{options:e},(t,{options:e})=>(window.scrollTo({top:0,left:0,...e}),!0))),r},V=function(t){try{const e=this;if(t.done)return Promise.resolve();const n=e.hooks.call("animation:in:await",t,{skip:!1},(t,{skip:n})=>{if(!n)return e.awaitAnimations({selector:t.animation.selector})});return Promise.resolve(d()).then(function(){return Promise.resolve(e.hooks.call("animation:in:start",t,void 0,()=>{e.classes.remove("is-animating")})).then(function(){return Promise.resolve(n).then(function(){return Promise.resolve(e.hooks.call("animation:in:end",t,void 0)).then(function(){})})})})}catch(t){return Promise.reject(t)}},N=function(t,e){try{const r=this;if(t.done)return Promise.resolve();t.advance(6);const{url:a}=e;return r.isSameResolvedUrl(o(),a)||(i(a),r.location=s.fromUrl(a),t.to.url=r.location.url,t.to.hash=r.location.hash),Promise.resolve(r.hooks.call("content:replace",t,{page:e},(t,{})=>{if(r.classes.remove("is-leaving"),t.animation.animate&&r.classes.add("is-rendering"),!r.replaceContent(t))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(r.classes.add("is-changing","is-animating","is-rendering"),t.animation.name&&r.classes.add(`to-${n(t.animation.name)}`))})).then(function(){return Promise.resolve(r.hooks.call("content:scroll",t,void 0,()=>r.scrollToContent(t))).then(function(){return Promise.resolve(r.hooks.call("page:view",t,{url:r.location.url,title:document.title})).then(function(){})})})}catch(t){return Promise.reject(t)}},q=function(t){var e;if(e=t,Boolean(e?.isSwupPlugin)){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function R(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=>"string"==typeof t?[`Swup${t}`,t].includes(e.name):e===t)}function D(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 M(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}const W={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],hooks:{},ignoreVisit:(t,{el:e}={})=>!!e?.closest("[data-no-swup]"),linkSelector:"a[href]",linkToSelf:"scroll",native:!1,plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source,timeout:0};return class{get currentPageUrl(){return this.location.url}constructor(t={}){this.version="4.9.1",this.options=void 0,this.defaults=W,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.location=s.fromUrl(window.location.href),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.navigating=!1,this.onVisitEnd=void 0,this.use=q,this.unuse=R,this.findPlugin=O,this.log=()=>{},this.navigate=T,this.performNavigation=H,this.createVisit=g,this.delegateEvent=r,this.fetchPage=a,this.awaitAnimations=E,this.renderPage=N,this.replaceContent=L,this.animatePageIn=V,this.animatePageOut=j,this.scrollToContent=I,this.getAnchorElement=S,this.getCurrentUrl=o,this.resolveUrl=D,this.isSameResolvedUrl=M,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 b(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=window.history.state?.index??1,this.enable()}enable(){try{const t=this,{linkSelector:e}=t.options;t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),t.options.native=t.options.native&&!!document.startViewTransition,t.options.plugins.forEach(e=>t.use(e));for(const[e,n]of Object.entries(t.options.hooks)){const[o,i]=t.hooks.parseName(e);t.hooks.on(o,n,i)}return"swup"!==window.history.state?.source&&i(null,{index:t.currentHistoryIndex}),Promise.resolve(d()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,void 0,()=>{const e=document.documentElement;e.classList.add("swup-enabled"),e.classList.toggle("swup-native",t.options.native)})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,void 0,()=>{const t=document.documentElement;t.classList.remove("swup-enabled"),t.classList.remove("swup-native")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,{el:e,event:n}={}){const{origin:o,url:i,hash:r}=s.fromUrl(t);return o!==window.location.origin||!(!e||!this.triggerWillOpenNewWindow(e))||!!this.options.ignoreVisit(i+r,{el:e,event:n})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:o,hash:r}=s.fromElement(e);if(this.shouldIgnoreVisit(n,{el:e,event:t}))return;if(this.navigating&&o===this.visit.to.url)return void t.preventDefault();const a=this.createVisit({to:o,hash:r,el:e,event:t});t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.callSync("link:newtab",a,{href:n}):0===t.button&&this.hooks.callSync("link:click",a,{el:e,event:t},()=>{const e=a.from.url??"";t.preventDefault(),o&&o!==e?this.isSameResolvedUrl(o,e)||this.performNavigation(a):r?this.hooks.callSync("link:anchor",a,{hash:r},()=>{i(o+r),this.scrollToContent(a)}):this.hooks.callSync("link:self",a,void 0,()=>{"navigate"===this.options.linkToSelf?this.performNavigation(a):(i(o),this.scrollToContent(a))})})}handlePopState(t){const e=t.state?.url??window.location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(o(),this.location.url))return;const{url:n,hash:i}=s.fromUrl(e),r=this.createVisit({to:n,hash:i,event:t});r.history.popstate=!0;const a=t.state?.index??0;a&&a!==this.currentHistoryIndex&&(r.history.direction=a-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=a),r.animation.animate=!1,r.scroll.reset=!1,r.scroll.target=!1,this.options.animateHistoryBrowsing&&(r.animation.animate=!0,r.scroll.reset=!0),this.hooks.callSync("history:popstate",r,{event:t},()=>{this.performNavigation(r)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}});
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t||self).Swup=e()}(this,function(){const t=new WeakMap;function e(e,n,o,i){if(!e&&!t.has(n))return!1;const r=t.get(n)??new WeakMap;t.set(n,r);const s=r.get(o)??new Set;r.set(o,s);const a=s.has(i);return e?s.add(i):s.delete(i),a&&e}const n=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",o=({hash:t}={})=>window.location.pathname+window.location.search+(t?window.location.hash:""),i=(t=null,e={})=>{t=t||o({hash:!0});const n={...window.history.state||{},url:t,random:Math.random(),source:"swup",...e};window.history.replaceState(n,"",t)},r=(t,n,o,i)=>{const r=new AbortController;return function(t,n,o,i={}){const{signal:r,base:s=document}=i;if(r?.aborted)return;const{once:a,...c}=i,l=s instanceof Document?s.documentElement:s,h=Boolean("object"==typeof i?i.capture:i),u=i=>{const r=function(t,e){let n=t.target;if(n instanceof Text&&(n=n.parentElement),n instanceof Element&&t.currentTarget instanceof Node){const o=n.closest(e);if(o&&t.currentTarget.contains(o))return o}}(i,String(t));if(r){const t=Object.assign(i,{delegateTarget:r});o.call(l,t),a&&(l.removeEventListener(n,u,c),e(!1,l,o,d))}},d=JSON.stringify({selector:t,type:n,capture:h});e(!0,l,o,d)||l.addEventListener(n,u,c),r?.addEventListener("abort",()=>{e(!1,l,o,d)})}(t,n,o,i={...i,signal:r.signal}),{destroy:()=>r.abort()}};class s extends URL{constructor(t,e=document.baseURI){super(t.toString(),e),Object.setPrototypeOf(this,s.prototype)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new s(e)}static fromUrl(t){return new s(t)}}const a=function(t,e={}){try{const o=this;function n(n){const{status:r,url:a}=u;return Promise.resolve(u.text()).then(function(n){if(500===r)throw o.hooks.call("fetch:error",i,{status:r,response:u,url:a}),new c(`Server error: ${a}`,{status:r,url:a});if(!n)throw new c(`Empty response: ${a}`,{status:r,url:a});const{url:l}=s.fromUrl(a),h={url:l,html:n};return!i.cache.write||e.method&&"GET"!==e.method||t!==l||o.cache.set(h.url,h),h})}t=s.fromUrl(t).url;const{visit:i=o.visit}=e,r={...o.options.requestHeaders,...e.headers},a=e.timeout??o.options.timeout,l=new AbortController,{signal:h}=l;e={...e,headers:r,signal:h};let u,d=!1,f=null;a&&a>0&&(f=setTimeout(()=>{d=!0,l.abort("timeout")},a));const m=function(n,r){try{var s=Promise.resolve(o.hooks.call("fetch:request",i,{url:t,options:e},(t,{url:e,options:n})=>fetch(e,n))).then(function(t){u=t,f&&clearTimeout(f)})}catch(t){return r(t)}return s&&s.then?s.then(void 0,r):s}(0,function(e){if(d)throw o.hooks.call("fetch:timeout",i,{url:t}),new c(`Request timed out: ${t}`,{url:t,timedOut:d});if("AbortError"===e?.name||h.aborted)throw new c(`Request aborted: ${t}`,{url:t,aborted:!0});throw e});return Promise.resolve(m&&m.then?m.then(n):n())}catch(p){return Promise.reject(p)}};class c extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}class l{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,n)=>{t.set(n,{...e})}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?{...e}:e}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",void 0,{page:e})}update(t,e){t=this.resolve(t);const n={...this.get(t),...e,url:t};this.pages.set(t,n)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0,void 0)}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=s.fromUrl(t);return this.swup.resolveUrl(e)}}const h=(t,e=document)=>e.querySelector(t),u=(t,e=document)=>Array.from(e.querySelectorAll(t)),d=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function f(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function m(t,e){const n=t?.closest(`[${e}]`);return n?.hasAttribute(e)?n?.getAttribute(e)||!0:void 0}class p{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating","is-leaving"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?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))}}class v{constructor(t,e){this.id=void 0,this.state=void 0,this.from=void 0,this.to=void 0,this.containers=void 0,this.animation=void 0,this.trigger=void 0,this.cache=void 0,this.history=void 0,this.scroll=void 0,this.meta=void 0;const{to:n,from:o,hash:i,el:r,event:s}=e;this.id=Math.random(),this.state=1,this.from={url:o??t.location.url,hash:t.location.hash},this.to={url:n,hash:i},this.containers=t.options.containers,this.animation={animate:!0,wait:!1,name:void 0,native:t.options.native,scope:t.options.animationScope,selector:t.options.animationSelector},this.trigger={el:r,event:s},this.cache={read:t.options.cache,write:t.options.cache},this.history={action:"push",popstate:!1,direction:void 0},this.scroll={reset:!0,target:void 0},this.meta={}}advance(t){this.state<t&&(this.state=t)}abort(){this.state=8}ignore(){this.state=10}get done(){return this.state>=7}get ignored(){return 10===this.state}}function g(t){return new v(this,t)}const w="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function y(t,e,n){if(!t.s){if(n instanceof k){if(!n.s)return void(n.o=y.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(y.bind(null,t,e),y.bind(null,t,2));t.s=e,t.v=n;const o=t.o;o&&o(t)}}const k=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const o=new t,i=this.s;if(i){const t=1&i?e:n;if(t){try{y(o,1,t(this.v))}catch(t){y(o,2,t)}return o}return this}return this.o=function(t){try{const i=t.v;1&t.s?y(o,1,e?e(i):i):n?y(o,1,n(i)):y(o,2,i)}catch(t){y(o,2,t)}},o},t}();function P(t){return t instanceof k&&1&t.s}class b{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","visit:abort","visit:end"],this.nextHookId=0,this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n={}){const o=this.get(t);if(!o)return console.warn(`Hook '${t}' not found.`),()=>{};const i={...n,id:++this.nextHookId,hook:t,handler:e};return o.set(e,i),()=>this.off(t,e)}before(t,e,n={}){return this.on(t,e,{...n,before:!0})}replace(t,e,n={}){return this.on(t,e,{...n,replace:!0})}once(t,e,n={}){return this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n,o){try{const i=this,[r,s,a]=i.parseCallArgs(t,e,n,o),{before:c,handler:l,after:h}=i.getHandlers(t,a);return Promise.resolve(i.run(c,r,s)).then(function(){return Promise.resolve(i.run(l,r,s,!0)).then(function([e]){return Promise.resolve(i.run(h,r,s)).then(function(){return i.dispatchDomEvent(t,r,s),e})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n,o){const[i,r,s]=this.parseCallArgs(t,e,n,o),{before:a,handler:c,after:l}=this.getHandlers(t,s);this.runSync(a,i,r);const[h]=this.runSync(c,i,r,!0);return this.runSync(l,i,r),this.dispatchDomEvent(t,i,r),h}parseCallArgs(t,e,n,o){return e instanceof v||"object"!=typeof e&&"function"!=typeof n?[e,n,o]:[void 0,e,n]}run(t,e,n,o=!1){try{let i;const r=this;void 0===e&&(e=r.swup.visit);const s=[],a=function(t,e,n){if("function"==typeof t[w]){var o,i,r,s=t[w]();if(function t(a){try{for(;!((o=s.next()).done||n&&n());)if((a=e(o.value))&&a.then){if(!P(a))return void a.then(t,r||(r=y.bind(null,i=new k,2)));a=a.v}i?y(i,1,a):i=a}catch(t){y(i||(i=new k),2,t)}}(),s.return){var a=function(t){try{o.done||s.return()}catch(t){}return t};if(i&&i.then)return i.then(a,function(t){throw a(t)});a()}return i}if(!("length"in t))throw new TypeError("Object is not iterable");for(var c=[],l=0;l<t.length;l++)c.push(t[l]);return function(t,e,n){var o,i,r=-1;return function s(a){try{for(;++r<t.length&&(!n||!n());)if((a=e(r))&&a.then){if(!P(a))return void a.then(s,i||(i=y.bind(null,o=new k,2)));a=a.v}o?y(o,1,a):o=a}catch(t){y(o||(o=new k),2,t)}}(),o}(c,function(t){return e(c[t])},n)}(t,function({hook:t,handler:i,defaultHandler:a,once:c}){if(!e?.done)return c&&r.off(t,i),function(t,o){try{var r=Promise.resolve(function(t,e=[]){return new Promise((n,o)=>{const i=t(...e);f(i)?i.then(n,o):n(i)})}(i,[e,n,a])).then(function(t){s.push(t)})}catch(t){return o(t)}return r&&r.then?r.then(void 0,o):r}(0,function(e){if(o)throw e;console.error(`Error in hook '${t}':`,e)})},function(){return i});return Promise.resolve(a&&a.then?a.then(function(t){return i?t:s}):i?a:s)}catch(t){return Promise.reject(t)}}runSync(t,e=this.swup.visit,n,o=!1){const i=[];for(const{hook:r,handler:s,defaultHandler:a,once:c}of t)if(!e?.done){c&&this.off(r,s);try{const t=s(e,n,a);i.push(t),f(t)&&console.warn(`Swup will not await Promises in handler for synchronous hook '${r}'.`)}catch(t){if(o)throw t;console.error(`Error in hook '${r}':`,t)}}return i}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const o=Array.from(n.values()),i=this.sortRegistrations,r=o.filter(({before:t,replace:e})=>t&&!e).sort(i),s=o.filter(({replace:t})=>t).filter(t=>!0).sort(i),a=o.filter(({before:t,replace:e})=>!t&&!e).sort(i),c=s.length>0;let l=[];if(e&&(l=[{id:0,hook:t,handler:e}],c)){const n=s.length-1,{handler:o,once:i}=s[n],r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};l=[{id:0,hook:t,once:i,handler:o,defaultHandler:r(n)}]}return{found:!0,before:r,handler:l,after:a,replaced:c}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e,n){if(e?.done)return;const o={hook:t,args:n,visit:e||this.swup.visit};document.dispatchEvent(new CustomEvent("swup:any",{detail:o,bubbles:!0})),document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:o,bubbles:!0}))}parseName(t){const[e,...n]=t.split(".");return[e,n.reduce((t,e)=>({...t,[e]:!0}),{})]}}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)||h(`a[name='${CSS.escape(t)}']`)||h(`a[name='${CSS.escape(e)}']`);return n||"top"!==t||(n=document.body),n},E=function({selector:t,elements:e}){try{if(!1===t&&!e)return Promise.resolve();let n=[];if(e)n=Array.from(e);else if(t&&(n=u(t,document.body),!n.length))return console.warn(`[swup] No elements found matching animationSelector \`${t}\``),Promise.resolve();const o=n.map(t=>function(t){const{type:e,timeout:n,propCount:o}=function(t){const e=window.getComputedStyle(t),n=x(e,`${C}Delay`),o=x(e,`${C}Duration`),i=$(n,o),r=x(e,`${U}Delay`),s=x(e,`${U}Duration`),a=$(r,s),c=Math.max(i,a),l=c>0?i>a?C:U:null;return{type:l,timeout:c,propCount:l?l===C?o.length:s.length:0}}(t);return!(!e||!n)&&new Promise(i=>{const r=`${e}end`,s=performance.now();let a=0;const c=()=>{t.removeEventListener(r,l),i()},l=e=>{e.target===t&&((performance.now()-s)/1e3<e.elapsedTime||++a>=o&&c())};setTimeout(()=>{a<o&&c()},n+1),t.addEventListener(r,l)})}(t)).filter(t=>!1!==t);return o.length?Promise.resolve(Promise.all(o)).then(function(){}):(t&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${t}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},C="transition",U="animation";function x(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)=>A(e)+A(t[n])))}function A(t){return 1e3*parseFloat(t)}const H=function(t,e={}){try{let a;const c=this;function r(r){if(a)return r;c.navigating=!0,c.visit=t;const{el:l}=t.trigger;e.referrer=e.referrer||c.location.url,!1===e.animate&&(t.animation.animate=!1),t.animation.animate||c.classes.clear();const h=e.history||m(l,"data-swup-history");"string"==typeof h&&["push","replace"].includes(h)&&(t.history.action=h);const u=e.animation||m(l,"data-swup-animation");return"string"==typeof u&&(t.animation.name=u),t.meta=e.meta||{},"object"==typeof e.cache?(t.cache.read=e.cache.read??t.cache.read,t.cache.write=e.cache.write??t.cache.write):void 0!==e.cache&&(t.cache={read:!!e.cache,write:!!e.cache}),delete e.cache,function(r,a){try{var l=function(r,a){try{var l=Promise.resolve(c.hooks.call("visit:start",t,void 0)).then(function(){function r(){if(t.ignored)throw new Error(`Visit to ${t.to.url} manually ignored`);if(!t.done)return Promise.resolve(c.hooks.call("visit:transition",t,void 0,function(){try{let n;function e(e){return n?e:(t.advance(4),Promise.resolve(c.animatePageOut(t)).then(function(){function e(){return Promise.resolve(c.animatePageIn(t)).then(function(){})}const n=function(){if(t.animation.native&&document.startViewTransition)return Promise.resolve(document.startViewTransition(function(){try{const e=c.renderPage;return Promise.resolve(a).then(function(n){return Promise.resolve(e.call(c,t,n))})}catch(t){return Promise.reject(t)}}).finished).then(function(){});{const e=c.renderPage;return Promise.resolve(a).then(function(n){return Promise.resolve(e.call(c,t,n)).then(function(){})})}}();return n&&n.then?n.then(e):e()}))}const o=function(){if(!t.animation.animate)return Promise.resolve(c.hooks.call("animation:skip",void 0)).then(function(){const e=c.renderPage;return Promise.resolve(a).then(function(o){return Promise.resolve(e.call(c,t,o)).then(function(){n=1})})})}();return Promise.resolve(o&&o.then?o.then(e):e(o))}catch(i){return Promise.reject(i)}})).then(function(){if(!t.done)return Promise.resolve(c.hooks.call("visit:end",t,void 0,()=>c.classes.clear())).then(function(){t.state=7,c.navigating=!1,c.onVisitEnd&&(c.onVisitEnd(),c.onVisitEnd=void 0)})})}t.state=3;const a=c.hooks.call("page:load",t,{options:e},function(t,e){try{function n(t){return e.page=t,e.cache=!!o,e.page}let o;return t.cache.read&&(o=c.cache.get(t.to.url)),Promise.resolve(o?n(o):Promise.resolve(c.fetchPage(t.to.url,e.options)).then(n))}catch(i){return Promise.reject(i)}});a.then(({html:e})=>{t.advance(5),t.to.html=e,t.to.document=(new DOMParser).parseFromString(e,"text/html")});const l=t.to.url+t.to.hash;t.history.popstate||("replace"===t.history.action||t.to.url===c.location.url?i(l):(c.currentHistoryIndex++,((t,e={})=>{const n={url:t=t||o({hash:!0}),random:Math.random(),source:"swup",...e};window.history.pushState(n,"",t)})(l,{index:c.currentHistoryIndex}))),c.location=s.fromUrl(l),t.history.popstate&&c.classes.add("is-popstate"),t.animation.name&&c.classes.add(`to-${n(t.animation.name)}`);const h=function(){if(t.animation.wait)return Promise.resolve(a).then(function(){})}();return h&&h.then?h.then(r):r()})}catch(t){return a(t)}return l&&l.then?l.then(void 0,a):l}(0,function(e){e&&!e?.aborted?(t.advance(9),console.error(e),c.options.skipPopStateHandling=()=>(window.location.assign(t.to.url+t.to.hash),!0),window.history.back()):t.advance(8)})}catch(t){return a(!0,t)}return l&&l.then?l.then(a.bind(null,!1),a.bind(null,!0)):a(!1,l)}(0,function(e,n){if(delete t.to.document,e)throw n;return n})}const l=function(){if(c.navigating)return function(){if(!(c.visit.state>=6))return Promise.resolve(c.hooks.call("visit:abort",c.visit,void 0)).then(function(){delete c.visit.to.document,c.visit.state=8});t.state=2,c.onVisitEnd=()=>c.performNavigation(t,e),a=1}()}();return Promise.resolve(l&&l.then?l.then(r):r(l))}catch(h){return Promise.reject(h)}};function T(t,e={},n={}){if("string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");if(this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void window.location.assign(t);const{url:o,hash:i}=s.fromUrl(t),r=this.createVisit({...n,to:o,hash:i});this.performNavigation(r,e)}const j=function(t){try{const e=this;return Promise.resolve(e.hooks.call("animation:out:start",t,void 0,()=>{e.classes.add("is-changing","is-animating","is-leaving")})).then(function(){return Promise.resolve(e.hooks.call("animation:out:await",t,{skip:!1},(t,{skip:n})=>{if(!n)return e.awaitAnimations({selector:t.animation.selector})})).then(function(){return Promise.resolve(e.hooks.call("animation:out:end",t,void 0)).then(function(){})})})}catch(t){return Promise.reject(t)}},L=function(t){const e=t.to.document;if(!e)return!1;const n=e.querySelector("title")?.innerText||"";document.title=n;const o=u('[data-swup-persist]:not([data-swup-persist=""])'),i=t.containers.map(t=>{const n=document.querySelector(t),o=e.querySelector(t);return n&&o?(n.replaceWith(o.cloneNode(!0)),!0):(n||console.warn(`[swup] Container missing in current document: ${t}`),o||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean);return o.forEach(t=>{const e=t.getAttribute("data-swup-persist"),n=h(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),i.length===t.containers.length},I=function(t){const e={behavior:"auto"},{target:n,reset:o}=t.scroll,i=n??t.to.hash;let r=!1;return i&&(r=this.hooks.callSync("scroll:anchor",t,{hash:i,options:e},(t,{hash:e,options:n})=>{const o=this.getAnchorElement(e);return o&&o.scrollIntoView(n),!!o})),o&&!r&&(r=this.hooks.callSync("scroll:top",t,{options:e},(t,{options:e})=>(window.scrollTo({top:0,left:0,...e}),!0))),r},V=function(t){try{const e=this;if(t.done)return Promise.resolve();const n=e.hooks.call("animation:in:await",t,{skip:!1},(t,{skip:n})=>{if(!n)return e.awaitAnimations({selector:t.animation.selector})});return Promise.resolve(d()).then(function(){return Promise.resolve(e.hooks.call("animation:in:start",t,void 0,()=>{e.classes.remove("is-animating")})).then(function(){return Promise.resolve(n).then(function(){return Promise.resolve(e.hooks.call("animation:in:end",t,void 0)).then(function(){})})})})}catch(t){return Promise.reject(t)}},N=function(t,e){try{const r=this;if(t.done)return Promise.resolve();t.advance(6);const{url:a}=e;return r.isSameResolvedUrl(o(),a)||(i(a),r.location=s.fromUrl(a),t.to.url=r.location.url,t.to.hash=r.location.hash),Promise.resolve(r.hooks.call("content:replace",t,{page:e},(t,{})=>{if(r.classes.remove("is-leaving"),t.animation.animate&&r.classes.add("is-rendering"),!r.replaceContent(t))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(r.classes.add("is-changing","is-animating","is-rendering"),t.animation.name&&r.classes.add(`to-${n(t.animation.name)}`))})).then(function(){return Promise.resolve(r.hooks.call("content:scroll",t,void 0,()=>r.scrollToContent(t))).then(function(){return Promise.resolve(r.hooks.call("page:view",t,{url:r.location.url,title:document.title})).then(function(){})})})}catch(t){return Promise.reject(t)}},q=function(t){var e;if(e=t,Boolean(e?.isSwupPlugin)){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function R(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=>"string"==typeof t?[`Swup${t}`,t].includes(e.name):e===t)}function D(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 M(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}const W={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],hooks:{},ignoreVisit:(t,{el:e}={})=>!!e?.closest("[data-no-swup]"),linkSelector:"a[href]",linkToSelf:"scroll",native:!1,plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source,timeout:0};return class{get currentPageUrl(){return this.location.url}constructor(t={}){this.version="4.9.2",this.options=void 0,this.defaults=W,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.location=s.fromUrl(window.location.href),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.navigating=!1,this.onVisitEnd=void 0,this.use=q,this.unuse=R,this.findPlugin=O,this.log=()=>{},this.navigate=T,this.performNavigation=H,this.createVisit=g,this.delegateEvent=r,this.fetchPage=a,this.awaitAnimations=E,this.renderPage=N,this.replaceContent=L,this.animatePageIn=V,this.animatePageOut=j,this.scrollToContent=I,this.getAnchorElement=S,this.getCurrentUrl=o,this.resolveUrl=D,this.isSameResolvedUrl=M,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 b(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=window.history.state?.index??1,this.enable()}enable(){try{const t=this,{linkSelector:e}=t.options;t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),t.options.native=t.options.native&&!!document.startViewTransition,t.options.plugins.forEach(e=>t.use(e));for(const[e,n]of Object.entries(t.options.hooks)){const[o,i]=t.hooks.parseName(e);t.hooks.on(o,n,i)}return"swup"!==window.history.state?.source&&i(null,{index:t.currentHistoryIndex}),Promise.resolve(d()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,void 0,()=>{const e=document.documentElement;e.classList.add("swup-enabled"),e.classList.toggle("swup-native",t.options.native)})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,void 0,()=>{const t=document.documentElement;t.classList.remove("swup-enabled"),t.classList.remove("swup-native")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,{el:e,event:n}={}){const{origin:o,url:i,hash:r}=s.fromUrl(t);return o!==window.location.origin||!(!e||!this.triggerWillOpenNewWindow(e))||!!this.options.ignoreVisit(i+r,{el:e,event:n})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:o,hash:r}=s.fromElement(e);if(this.shouldIgnoreVisit(n,{el:e,event:t}))return;if(this.navigating&&o===this.visit.to.url)return void t.preventDefault();const a=this.createVisit({to:o,hash:r,el:e,event:t});t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.callSync("link:newtab",a,{href:n}):0===t.button&&this.hooks.callSync("link:click",a,{el:e,event:t},()=>{const e=a.from.url??"";t.preventDefault(),o&&o!==e?this.isSameResolvedUrl(o,e)||this.performNavigation(a):r?this.hooks.callSync("link:anchor",a,{hash:r},()=>{i(o+r),this.scrollToContent(a)}):this.hooks.callSync("link:self",a,void 0,()=>{"navigate"===this.options.linkToSelf?this.performNavigation(a):(i(o),this.scrollToContent(a))})})}handlePopState(t){const e=t.state?.url??window.location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(o(),this.location.url))return;const{url:n,hash:i}=s.fromUrl(e),r=this.createVisit({to:n,hash:i,event:t});r.history.popstate=!0;const a=t.state?.index??0;a&&a!==this.currentHistoryIndex&&(r.history.direction=a-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=a),r.animation.animate=!1,r.scroll.reset=!1,r.scroll.target=!1,this.options.animateHistoryBrowsing&&(r.animation.animate=!0,r.scroll.reset=!0),this.hooks.callSync("history:popstate",r,{event:t},()=>{this.performNavigation(r)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}});
|
|
2
2
|
//# sourceMappingURL=Swup.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Swup.d.ts","sourceRoot":"","sources":["../../src/Swup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD,OAAO,EAAgC,QAAQ,EAAuB,MAAM,cAAc,CAAC;AAC3F,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAE3E,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,KAAK,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAiB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAMnD,OAAO,EAAO,KAAK,EAAE,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAIxE,+CAA+C;AAC/C,MAAM,MAAM,OAAO,GAAG;IACrB,4DAA4D;IAC5D,sBAAsB,EAAE,OAAO,CAAC;IAChC,iFAAiF;IACjF,iBAAiB,EAAE,MAAM,GAAG,KAAK,CAAC;IAClC,0EAA0E;IAC1E,cAAc,EAAE,MAAM,GAAG,YAAY,CAAC;IACtC,mDAAmD;IACnD,KAAK,EAAE,OAAO,CAAC;IACf,6EAA6E;IAC7E,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,6FAA6F;IAC7F,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE;QAAE,EAAE,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE,KAAK,OAAO,CAAC;IACtF,mEAAmE;IACnE,YAAY,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,UAAU,EAAE,sBAAsB,CAAC;IACnC,+DAA+D;IAC/D,MAAM,EAAE,OAAO,CAAC;IAChB,iCAAiC;IACjC,KAAK,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAChC,sCAAsC;IACtC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,qDAAqD;IACrD,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,wCAAwC;IACxC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,oEAAoE;IACpE,oBAAoB,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC;IACxD,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;AAuBF,oCAAoC;AACpC,MAAM,CAAC,OAAO,OAAO,IAAI;IACxB,sBAAsB;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAW;IACnC,uCAAuC;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,kDAAkD;IAClD,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAY;IACtC,kCAAkC;IAClC,OAAO,EAAE,MAAM,EAAE,CAAM;IACvB,mCAAmC;IACnC,KAAK,EAAE,KAAK,CAAC;IACb,qBAAqB;IACrB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,oBAAoB;IACpB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,8BAA8B;IAC9B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,6CAA6C;IAC7C,QAAQ,EAAE,QAAQ,CAA0C;IAC5D,kFAAkF;IAClF,IAAI,cAAc,IAAI,MAAM,CAE3B;IACD,yCAAyC;IACzC,SAAS,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACtC,0CAA0C;IAC1C,SAAS,CAAC,aAAa,CAAC,EAAE,wBAAwB,CAAC;IACnD,wBAAwB;IACxB,SAAS,CAAC,UAAU,EAAE,OAAO,CAAS;IACtC,+BAA+B;IAC/B,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAE9C,uBAAuB;IACvB,GAAG,wDAAO;IACV,yBAAyB;IACzB,KAAK,eAAS;IACd,wCAAwC;IACxC,UAAU,oBAAc;IAExB,oEAAoE;IACpE,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAY;IAE7D,4BAA4B;IAC5B,QAAQ,kBAAY;IACpB,oCAAoC;IACpC,SAAS,CAAC,iBAAiB,2BAAqB;IAChD,0CAA0C;IAC1C,SAAS,CAAC,WAAW,qBAAe;IACpC,0CAA0C;IAC1C,aAAa,8aAAiB;IAC9B,mCAAmC;IACnC,SAAS,mBAAa;IACtB,iDAAiD;IACjD,eAAe,yBAAmB;IAClC,SAAS,CAAC,UAAU,+FAAc;IAClC,0CAA0C;IAC1C,cAAc,wCAAkB;IAChC,SAAS,CAAC,aAAa,8CAAiB;IACxC,SAAS,CAAC,cAAc,8CAAkB;IAC1C,SAAS,CAAC,eAAe,wCAAmB;IAC5C,+CAA+C;IAC/C,gBAAgB,oCAAoB;IAEpC,+BAA+B;IAC/B,aAAa;YA7IuB,CAAC;iBA6IP;IAC9B,0CAA0C;IAC1C,UAAU,oBAAc;IACxB,qDAAqD;IACrD,SAAS,CAAC,iBAAiB,2BAAqB;gBAEpC,OAAO,GAAE,OAAO,CAAC,OAAO,CAAM;IAiB1C,6DAA6D;IACvD,MAAM;IAgDZ,gEAAgE;IAC1D,OAAO;IAwBb,uFAAuF;IACvF,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,GAAE;QAAE,EAAE,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAO;IAsBnF,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC;IAiE1D,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,aAAa;IA4C7C,iFAAiF;IACjF,SAAS,CAAC,wBAAwB,CAAC,SAAS,EAAE,OAAO;CAMrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/config/version.ts"],"names":[],"mappings":"AAAA;;GAEG;;AASH,wBAA4B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Location.d.ts","sourceRoot":"","sources":["../../../src/helpers/Location.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,QAAS,SAAQ,GAAG;gBACpB,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,IAAI,GAAE,MAAyB;IAM9D;;OAEG;IACH,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED;;;;OAIG;IACH,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,OAAO,GAAG,QAAQ;IAKzC;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,QAAQ;CAG3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../../../src/helpers/classify.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,EAAE,WAAW,MAAM,KAAG,MAU1D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegateEvent.d.ts","sourceRoot":"","sources":["../../../src/helpers/delegateEvent.ts"],"names":[],"mappings":"AAAA,OAAiB,EAChB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAEpE,MAAM,MAAM,wBAAwB,GAAG;IACtC,OAAO,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC;AAEF,2CAA2C;AAC3C,eAAO,MAAM,aAAa,GACzB,QAAQ,SAAS,MAAM,EACvB,QAAQ,SAAS,OAAO,GAAG,aAAa,CAAC,QAAQ,EAAE,WAAW,CAAC,EAC/D,MAAM,SAAS,SAAS,GAAG,SAAS,EAEpC,UAAU,QAAQ,EAClB,MAAM,MAAM,EACZ,UAAU,oBAAoB,CAAC,2BAA2B,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,EAC7E,UAAU,eAAe,KACvB,wBAKF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCurrentUrl.d.ts","sourceRoot":"","sources":["../../../src/helpers/getCurrentUrl.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,eAAO,MAAM,aAAa,GAAI,WAAU;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAO,KAAG,MAEjE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../../src/helpers/history.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE3C,iEAAiE;AACjE,eAAO,MAAM,mBAAmB,GAAI,KAAK,MAAM,EAAE,OAAM,WAAgB,KAAG,IASzE,CAAC;AAEF,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,GAAI,MAAK,MAAM,GAAG,IAAW,EAAE,OAAM,WAAgB,KAAG,IAWvF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchPath.d.ts","sourceRoot":"","sources":["../../../src/helpers/matchPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC;AAErB,KAAK,MAAM,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AAEvC,oFAAoF;AACpF,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,MAAM,GAAG,MAAM,EAClD,MAAM,MAAM,CAAC,CAAC,CAAC,EACf,UAAU,MAAM,CAAC,CAAC,CAAC,KACjB,aAAa,CAAC,CAAC,CAYjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EACX,KAAK,EACL,SAAS,EACT,OAAO,EACP,cAAc,EACd,WAAW,EACX,YAAY,EACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EACX,QAAQ,EACR,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,SAAS,EACT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEnD,eAAe,IAAI,CAAC;AACpB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,YAAY,EACX,IAAI,EACJ,OAAO,EACP,MAAM,EACN,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,SAAS,EACT,OAAO,EACP,cAAc,EACd,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,WAAW,IAAI,OAAO,EAAE,0BAA0B;AAClD,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,SAAS,EACT,aAAa,EACb,oBAAoB,EACpB,wBAAwB,EACxB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cache.d.ts","sourceRoot":"","sources":["../../../src/modules/Cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI/C,MAAM,WAAW,SAAU,SAAQ,QAAQ;CAAG;AAE9C;;GAEG;AACH,qBAAa,KAAK;IACjB,0CAA0C;IAC1C,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC;IAErB,mCAAmC;IACnC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAa;gBAExC,IAAI,EAAE,IAAI;IAItB,wCAAwC;IACxC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,wBAAwB;IACxB,IAAI,GAAG,kBAMN;IAED,8CAA8C;IAC9C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIzB,oEAAoE;IACpE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAMvC,mDAAmD;IACnD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS;IAOhC,gEAAgE;IAChE,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAMnC,6BAA6B;IAC7B,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAIzB,uBAAuB;IACvB,KAAK,IAAI,IAAI;IAKb,iFAAiF;IACjF,KAAK,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,KAAK,OAAO,GAAG,IAAI;IAQjE,uEAAuE;IACvE,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;CAI/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Classes.d.ts","sourceRoot":"","sources":["../../../src/modules/Classes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAGnC,qBAAa,OAAO;IACnB,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC;IACrB,SAAS,CAAC,WAAW,WAOnB;gBAEU,IAAI,EAAE,IAAI;IAItB,SAAS,KAAK,SAAS,IAAI,MAAM,EAAE,CAMlC;IAED,SAAS,KAAK,QAAQ,IAAI,MAAM,CAE/B;IAED,SAAS,KAAK,OAAO,IAAI,WAAW,EAAE,CAGrC;IAED,GAAG,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAI/B,MAAM,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAIlC,KAAK,IAAI,IAAI;IAOb,SAAS,CAAC,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;CAGjD"}
|