1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
const q=()=>{document.querySelectorAll(`a[href='${location.pathname}']`).forEach(t=>t.classList.add("active"))};document.addEventListener("astro:page-load",q,{once:!0});document.addEventListener("astro:after-swap",q);document.querySelectorAll(".off-canvas-toggle").forEach(e=>e.addEventListener("click",t=>{const{target:n}=e.dataset;n&&document.querySelector(n)?.classList.toggle("active")}));const Q="astro:before-preparation",Z="astro:after-preparation",ee="astro:before-swap",te="astro:after-swap",ne=e=>document.dispatchEvent(new Event(e));class F extends Event{from;to;direction;navigationType;sourceElement;info;newDocument;constructor(t,n,r,o,a,l,h,s,d){super(t,n),this.from=r,this.to=o,this.direction=a,this.navigationType=l,this.sourceElement=h,this.info=s,this.newDocument=d,Object.defineProperties(this,{from:{enumerable:!0},to:{enumerable:!0,writable:!0},direction:{enumerable:!0,writable:!0},navigationType:{enumerable:!0},sourceElement:{enumerable:!0},info:{enumerable:!0},newDocument:{enumerable:!0,writable:!0}})}}class re extends F{formData;loader;constructor(t,n,r,o,a,l,h,s,d){super(Q,{cancelable:!0},t,n,r,o,a,l,h),this.formData=s,this.loader=d.bind(this,this),Object.defineProperties(this,{formData:{enumerable:!0},loader:{enumerable:!0,writable:!0}})}}class oe extends F{direction;viewTransition;swap;constructor(t,n,r){super(ee,void 0,t.from,t.to,t.direction,t.navigationType,t.sourceElement,t.info,t.newDocument),this.direction=t.direction,this.viewTransition=n,this.swap=r.bind(this,this),Object.defineProperties(this,{direction:{enumerable:!0},viewTransition:{enumerable:!0},swap:{enumerable:!0,writable:!0}})}}async function ie(e,t,n,r,o,a,l,h){const s=new re(e,t,n,r,o,a,window.document,l,h);return document.dispatchEvent(s)&&(await s.loader(),s.defaultPrevented||(ne(Z),s.navigationType!=="traverse"&&k({scrollX,scrollY}))),s}async function se(e,t,n){const r=new oe(e,t,n);return document.dispatchEvent(r),r.swap(),r}const ae=history.pushState.bind(history),D=history.replaceState.bind(history),k=e=>{history.state&&(history.scrollRestoration="manual",D({...history.state,...e},""))},R=!!document.startViewTransition,x=()=>!!document.querySelector('[name="astro-view-transitions-enabled"]'),_=(e,t)=>e.pathname===t.pathname&&e.search===t.search;let A,y,b=!1,C;const U=e=>document.dispatchEvent(new Event(e)),V=()=>U("astro:page-load"),ce=()=>{let e=document.createElement("div");e.setAttribute("aria-live","assertive"),e.setAttribute("aria-atomic","true"),e.className="astro-route-announcer",document.body.append(e),setTimeout(()=>{let t=document.title||document.querySelector("h1")?.textContent||location.pathname;e.textContent=t},60)},w="data-astro-transition-persist",W="data-astro-transition",X="data-astro-transition-fallback";let I,v=0;history.state?(v=history.state.index,scrollTo({left:history.state.scrollX,top:history.state.scrollY})):x()&&(D({index:v,scrollX,scrollY},""),history.scrollRestoration="manual");const le=(e,t)=>{let n=!1,r=!1;return(...o)=>{if(n){r=!0;return}e(...o),n=!0,setTimeout(()=>{r&&(r=!1,e(...o)),n=!1},t)}};async function ue(e,t){try{const n=await fetch(e,t),r=n.headers.get("content-type")?.replace(/;.*$/,"");return r!=="text/html"&&r!=="application/xhtml+xml"?null:{html:await n.text(),redirected:n.redirected?n.url:void 0,mediaType:r}}catch{return null}}function Y(){const e=document.querySelector('[name="astro-view-transitions-fallback"]');return e?e.getAttribute("content"):"animate"}function fe(){let e=Promise.resolve();for(const t of Array.from(document.scripts)){if(t.dataset.astroExec==="")continue;const n=document.createElement("script");n.innerHTML=t.innerHTML;for(const r of t.attributes){if(r.name==="src"){const o=new Promise(a=>{n.onload=a});e=e.then(()=>o)}n.setAttribute(r.name,r.value)}n.dataset.astroExec="",t.replaceWith(n)}return e}const B=(e,t,n,r)=>{const o=_(t,e);let a=!1;if(e.href!==location.href&&!r)if(n.history==="replace"){const l=history.state;D({...n.state,index:l.index,scrollX:l.scrollX,scrollY:l.scrollY},"",e.href)}else ae({...n.state,index:++v,scrollX:0,scrollY:0},"",e.href);A=e,o||(scrollTo({left:0,top:0,behavior:"instant"}),a=!0),r?scrollTo(r.scrollX,r.scrollY):(e.hash?(history.scrollRestoration="auto",location.href=e.href):a||scrollTo({left:0,top:0,behavior:"instant"}),history.scrollRestoration="manual")};function de(e){const t=[];for(const n of e.querySelectorAll("head link[rel=stylesheet]"))if(!document.querySelector(`[${w}="${n.getAttribute(w)}"], link[rel=stylesheet][href="${n.getAttribute("href")}"]`)){const r=document.createElement("link");r.setAttribute("rel","preload"),r.setAttribute("as","style"),r.setAttribute("href",n.getAttribute("href")),t.push(new Promise(o=>{["load","error"].forEach(a=>r.addEventListener(a,o)),document.head.append(r)}))}return t}async function O(e,t,n,r){const o=(i,u)=>{const m=i.getAttribute(w),p=m&&u.head.querySelector(`[${w}="${m}"]`);if(p)return p;if(i.matches("link[rel=stylesheet]")){const g=i.getAttribute("href");return u.head.querySelector(`link[rel=stylesheet][href="${g}"]`)}return null},a=()=>{const i=document.activeElement;if(i?.closest(`[${w}]`)){if(i instanceof HTMLInputElement||i instanceof HTMLTextAreaElement){const u=i.selectionStart,m=i.selectionEnd;return{activeElement:i,start:u,end:m}}return{activeElement:i}}else return{activeElement:null}},l=({activeElement:i,start:u,end:m})=>{i&&(i.focus(),(i instanceof HTMLInputElement||i instanceof HTMLTextAreaElement)&&(i.selectionStart=u,i.selectionEnd=m))},h=i=>{const u=document.documentElement,m=[...u.attributes].filter(({name:c})=>(u.removeAttribute(c),c.startsWith("data-astro-")));[...i.newDocument.documentElement.attributes,...m].forEach(({name:c,value:f})=>u.setAttribute(c,f));for(const c of document.scripts)for(const f of i.newDocument.scripts)if(!c.src&&c.textContent===f.textContent||c.src&&c.type===f.type&&c.src===f.src){f.dataset.astroExec="";break}for(const c of Array.from(document.head.children)){const f=o(c,i.newDocument);f?f.remove():c.remove()}document.head.append(...i.newDocument.head.children);const p=document.body,g=a();document.body.replaceWith(i.newDocument.body);for(const c of p.querySelectorAll(`[${w}]`)){const f=c.getAttribute(w),S=document.querySelector(`[${w}="${f}"]`);S&&S.replaceWith(c)}l(g)};async function s(i){function u(c){const f=c.effect;return!f||!(f instanceof KeyframeEffect)||!f.target?!1:window.getComputedStyle(f.target,f.pseudoElement).animationIterationCount==="infinite"}const m=document.getAnimations();document.documentElement.setAttribute(X,i);const g=document.getAnimations().filter(c=>!m.includes(c)&&!u(c));return Promise.all(g.map(c=>c.finished))}if(!b)document.documentElement.setAttribute(W,e.direction),r==="animate"&&await s("old");else throw new DOMException("Transition was skipped");const d=await se(e,y,h);B(d.to,d.from,t,n),U(te),r==="animate"&&!b&&s("new").then(()=>C())}async function K(e,t,n,r,o){if(!x()||location.origin!==n.origin){location.href=n.href;return}const a=o?"traverse":r.history==="replace"?"replace":"push";if(a!=="traverse"&&k({scrollX,scrollY}),_(t,n)&&n.hash){B(n,t,r,o);return}const l=await ie(t,n,e,a,r.sourceElement,r.info,r.formData,h);if(l.defaultPrevented){location.href=n.href;return}async function h(s){const d=s.to.href,i={};s.formData&&(i.method="POST",i.body=s.formData);const u=await ue(d,i);if(u===null){s.preventDefault();return}if(u.redirected&&(s.to=new URL(u.redirected)),I??=new DOMParser,s.newDocument=I.parseFromString(u.html,u.mediaType),s.newDocument.querySelectorAll("noscript").forEach(p=>p.remove()),!s.newDocument.querySelector('[name="astro-view-transitions-enabled"]')&&!s.formData){s.preventDefault();return}const m=de(s.newDocument);m.length&&await Promise.all(m)}if(b=!1,R)y=document.startViewTransition(async()=>await O(l,r,o));else{const s=(async()=>{await new Promise(d=>setTimeout(d)),await O(l,r,o,Y())})();y={updateCallbackDone:s,ready:s,finished:new Promise(d=>C=d),skipTransition:()=>{b=!0}}}y.ready.then(async()=>{await fe(),V(),ce()}),y.finished.then(()=>{document.documentElement.removeAttribute(W),document.documentElement.removeAttribute(X)}),await y.ready}async function M(e,t){await K("forward",A,new URL(e,location.href),t??{})}function me(e){if(!x()&&e.state){location.reload();return}if(e.state===null)return;const t=history.state,n=t.index,r=n>v?"forward":"back";v=n,K(r,A,new URL(location.href),{},t)}const H=()=>{k({scrollX,scrollY})};{(R||Y()!=="none")&&(A=new URL(location.href),addEventListener("popstate",me),addEventListener("load",V),"onscrollend"in window?addEventListener("scrollend",H):addEventListener("scroll",le(H,350),{passive:!0}));for(const e of document.scripts)e.dataset.astroExec=""}const j=new Set,T=new WeakSet;let L,G,N=!1;function he(e){N||(N=!0,L??=e?.prefetchAll??!1,G??=e?.defaultStrategy??"hover",we(),pe(),ye())}function we(){for(const e of["touchstart","mousedown"])document.body.addEventListener(e,t=>{E(t.target,"tap")&&P(t.target.href,{with:"fetch",ignoreSlowConnection:!0})},{passive:!0})}function pe(){let e;document.body.addEventListener("focusin",r=>{E(r.target,"hover")&&t(r)},{passive:!0}),document.body.addEventListener("focusout",n,{passive:!0}),J(()=>{for(const r of document.getElementsByTagName("a"))T.has(r)||E(r,"hover")&&(T.add(r),r.addEventListener("mouseenter",t,{passive:!0}),r.addEventListener("mouseleave",n,{passive:!0}))});function t(r){const o=r.target.href;e&&clearTimeout(e),e=setTimeout(()=>{P(o,{with:"fetch"})},80)}function n(){e&&(clearTimeout(e),e=0)}}function ye(){let e;J(()=>{for(const t of document.getElementsByTagName("a"))T.has(t)||E(t,"viewport")&&(T.add(t),e??=ge(),e.observe(t))})}function ge(){const e=new WeakMap;return new IntersectionObserver((t,n)=>{for(const r of t){const o=r.target,a=e.get(o);r.isIntersecting?(a&&clearTimeout(a),e.set(o,setTimeout(()=>{n.unobserve(o),e.delete(o),P(o.href,{with:"link"})},300))):a&&(clearTimeout(a),e.delete(o))}})}function P(e,t){const n=t?.ignoreSlowConnection??!1;if(!ve(e,n))return;if(j.add(e),(t?.with??"link")==="link"){const o=document.createElement("link");o.rel="prefetch",o.setAttribute("href",e),document.head.append(o)}else fetch(e).catch(o=>{console.log(`[astro] Failed to prefetch ${e}`),console.error(o)})}function ve(e,t){if(!navigator.onLine||!t&&z())return!1;try{const n=new URL(e,location.href);return location.origin===n.origin&&(location.pathname!==n.pathname||location.search!==n.search)&&!j.has(e)}catch{}return!1}function E(e,t){if(e?.tagName!=="A")return!1;const n=e.dataset.astroPrefetch;return n==="false"?!1:t==="tap"&&(n!=null||L)&&z()?!0:n==null&&L||n===""?t===G:n===t}function z(){if("connection"in navigator){const e=navigator.connection;return e.saveData||/(2|3)g/.test(e.effectiveType)}return!1}function J(e){e();let t=!1;document.addEventListener("astro:page-load",()=>{if(!t){t=!0;return}e()})}function be(){const e=document.querySelector('[name="astro-view-transitions-fallback"]');return e?e.getAttribute("content"):"animate"}function $(e){return e.dataset.astroReload!==void 0}(R||be()!=="none")&&(document.addEventListener("click",e=>{let t=e.target;if(t instanceof Element&&(t=t.closest("a, area")),!(t instanceof HTMLAnchorElement)&&!(t instanceof SVGAElement)&&!(t instanceof HTMLAreaElement))return;const n=t instanceof HTMLElement?t.target:t.target.baseVal,r=t instanceof HTMLElement?t.href:t.href.baseVal,o=new URL(r,location.href).origin;$(t)||t.hasAttribute("download")||!t.href||n&&n!=="_self"||o!==location.origin||e.button!==0||e.metaKey||e.ctrlKey||e.altKey||e.shiftKey||e.defaultPrevented||(e.preventDefault(),M(r,{history:t.dataset.astroHistory==="replace"?"replace":"auto",sourceElement:t}))}),document.addEventListener("submit",e=>{let t=e.target;if(t.tagName!=="FORM"||$(t))return;const n=t,r=e.submitter,o=new FormData(n,r);let a=r?.getAttribute("formaction")??n.action??location.pathname;const l=r?.getAttribute("formmethod")??n.method;if(l==="dialog")return;const h={sourceElement:r??n};if(l==="get"){const s=new URLSearchParams(o),d=new URL(a);d.search=s.toString(),a=d.toString()}else h.formData=o;e.preventDefault(),M(a,h)}),he({prefetchAll:!0}));
|