aptechka 0.82.0 → 0.82.1

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.
@@ -38,6 +38,7 @@ export interface MorphNavigateOptions {
38
38
  centerScroll?: boolean;
39
39
  offsetScroll?: number | ElementOrSelector<HTMLElement>;
40
40
  scrollBehaviour?: ScrollBehavior;
41
+ scrollTo?: string;
41
42
  revalidate?: boolean;
42
43
  keepSearchParameters?: boolean;
43
44
  submorph?: Array<string>;
@@ -90,7 +91,7 @@ export declare class Morph {
90
91
  excludeHeadChild(child: Node): boolean;
91
92
  setHeaders(path: string): void;
92
93
  needRavalidation(path: string): void;
93
- navigate(path: string, { historyAction, centerScroll, offsetScroll, scrollBehaviour, revalidate, keepSearchParameters, submorph, submorphAppend, clearState, keepScrollPosition, mergeParams, removeParams, detail, }?: MorphNavigateOptions): Promise<void>;
94
+ navigate(path: string, { historyAction, centerScroll, offsetScroll, scrollBehaviour, revalidate, keepSearchParameters, submorph, submorphAppend, clearState, keepScrollPosition, mergeParams, removeParams, detail, scrollTo, }?: MorphNavigateOptions): Promise<void>;
94
95
  addLink(element: HTMLAnchorElement): void;
95
96
  addLinks(elements: Array<HTMLAnchorElement>): void;
96
97
  removeLink(element: HTMLAnchorElement): void;
@@ -4,6 +4,5 @@ export declare class MorphLink {
4
4
  constructor(element: HTMLAnchorElement, morph: Morph);
5
5
  get element(): HTMLAnchorElement;
6
6
  checkCurrent(path: string): void;
7
- updatePagination(newPage: number, selector: string): void;
8
7
  destroy(): void;
9
8
  }
@@ -1 +1 @@
1
- "use strict";var Ee=Object.defineProperty,be=Object.defineProperties;var Le=Object.getOwnPropertyDescriptors;var ee=Object.getOwnPropertySymbols;var Se=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable;var se=(h,e)=>(e=Symbol[h])?e:Symbol.for("Symbol."+h),ie=h=>{throw TypeError(h)};var ae=(h,e,s)=>e in h?Ee(h,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):h[e]=s,Tt=(h,e)=>{for(var s in e||(e={}))Se.call(e,s)&&ae(h,s,e[s]);if(ee)for(var s of ee(e))Ae.call(e,s)&&ae(h,s,e[s]);return h},zt=(h,e)=>be(h,Le(e));var It=(h,e,s)=>e.has(h)||ie("Cannot "+s);var t=(h,e,s)=>(It(h,e,"read from private field"),s?s.call(h):e.get(h)),l=(h,e,s)=>e.has(h)?ie("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(h):e.set(h,s),o=(h,e,s,i)=>(It(h,e,"write to private field"),i?i.call(h,s):e.set(h,s),s),g=(h,e,s)=>(It(h,e,"access private method"),s);var J=(h,e,s)=>new Promise((i,n)=>{var E=c=>{try{u(s.next(c))}catch(b){n(b)}},f=c=>{try{u(s.throw(c))}catch(b){n(b)}},u=c=>c.done?i(c.value):Promise.resolve(c.value).then(E,f);u((s=s.apply(h,e)).next())});var ne=(h,e,s)=>(e=h[se("asyncIterator")])?e.call(h):(h=h[se("iterator")](),e={},s=(i,n)=>(n=h[i])&&(e[i]=E=>new Promise((f,u,c)=>(E=n.call(h,E),c=E.done,Promise.resolve(E.value).then(b=>f({value:b,done:c}),u)))),s("next"),s("return"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const he=require("../index-CKTweR3M.cjs"),I=require("../events-KVanG9sR.cjs"),re=require("../scroll-DxcPU0vk.cjs");require("construct-style-sheets-polyfill");const ft=require("../url-CPgw9bd5.cjs"),ye=require("../css-value-parser/index.cjs"),le=require("../string-DUXXtU8v.cjs"),Pe=require("../math-GDWEqu7y.cjs");class ce extends HTMLElement{connectedCallback(){const e={"aria-live":"assertive","aria-atomic":"true",style:"position: absolute; left: 0; top: 0; clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap; width: 1px; height: 1px"};for(const[s,i]of Object.entries(e))this.setAttribute(s,i)}}he.isBrowser&&!customElements.get("morph-announcer")&&customElements.define("morph-announcer",ce);var C,a,x,nt,Mt,de,Et,rt;class Vt{constructor(e,s){l(this,x);l(this,C);l(this,a);l(this,Et,e=>{e.preventDefault(),g(this,x,de).call(this)});l(this,rt,()=>{const e=t(this,a).hasAttribute("data-revalidate");t(this,C).prefetch(t(this,x,nt),e),t(this,a).removeEventListener("pointerenter",t(this,rt))});o(this,C,s),o(this,a,e),t(this,a).addEventListener("click",t(this,Et)),this.checkCurrent(location.href.replace(location.origin,""));const i=g(this,x,Mt).call(this,t(this,a).getAttribute("data-pagination-set-link")||t(this,a).getAttribute("data-pagination-more-link")||t(this,a).getAttribute("data-pagination-next-link")||t(this,a).getAttribute("data-pagination-prev-link"));i&&this.updatePagination(i.currentPage,i.selector),t(this,a).hasAttribute("data-prefetch")&&t(this,a).addEventListener("pointerenter",t(this,rt))}get element(){return t(this,a)}checkCurrent(e){var b,st;const s=t(this,C).normalizePath(e),i=t(this,C).normalizePath(t(this,x,nt));t(this,a).hasAttribute("data-include")&&s.pathname.includes(i.pathname)?t(this,a).classList.add("current"):i.pathname===s.pathname?t(this,a).classList.add("current"):(b=t(this,a).getAttribute("data-associated-paths"))!=null&&b.split(",").find(k=>s.pathname.includes(k))?t(this,a).classList.add("current"):t(this,a).classList.remove("current"),s.path===i.path?t(this,a).classList.add("exact"):t(this,a).classList.remove("exact");const[n,E]=(st=t(this,x,nt).split("#")[0])==null?void 0:st.split("?"),f=new URLSearchParams(E),u=new URLSearchParams(location.search);let c=0;for(const[k]of u)f.has(k)&&u.get(k)===f.get(k)&&c++;c?(t(this,a).classList.toggle("all-params-matched",u.size===c),t(this,a).classList.toggle("some-params-matched",u.size!==c)):!u.size&&t(this,a).hasAttribute("data-match-no-params")?t(this,a).classList.add("all-params-matched"):(t(this,a).classList.remove("all-params-matched"),t(this,a).classList.remove("some-params-matched"));for(const k in t(this,a).dataset){const at=le.camelToKebab(k);if(at.startsWith("match-param-")){const z=at.split("match-param-")[1],L=t(this,a).dataset[k],w=`param-${z}-matched`;u.has(z)&&u.get(z)===L||!u.has(z)&&(L===""||L==="*"||L==="all"||L==="any"||L==="vse")?t(this,a).classList.add(w):t(this,a).classList.remove(w)}}}updatePagination(e,s){const i=g(this,x,Mt).call(this,s);if(i)if(i.element.setAttribute("data-current-page",e.toString()),t(this,a).hasAttribute("data-pagination-more-link"))if(e<i.totalPages){t(this,a).style.display="";const n=t(this,a).querySelector("[data-pagination-more-link-counter]");n&&(n.textContent=(i.totalPages-e).toString());const E=t(this,a).getAttribute("href"),f=new URL(E,window.location.origin);f.searchParams.set("page",(e+1).toString());const u=f.href.replace(f.origin,"").toString();t(this,a).setAttribute("href",u),this.checkCurrent(u)}else t(this,a).style.display="none";else if(t(this,a).hasAttribute("data-pagination-prev-link")||t(this,a).hasAttribute("data-pagination-next-link")){const n=t(this,a).hasAttribute("data-pagination-prev-link"),E=t(this,a).getAttribute("href"),f=new URL(E,window.location.origin),u=e+(n?-1:1);f.searchParams.set("page",Pe.clamp(u,1,i.totalPages).toString());const c=f.href.replace(f.origin,"").toString();t(this,a).setAttribute("href",c),n?u<1?(t(this,a).classList.add("pagination-disabled"),t(this,a).setAttribute("tabindex","-1")):(t(this,a).classList.remove("pagination-disabled"),t(this,a).removeAttribute("tabindex")):u>i.totalPages?(t(this,a).classList.add("pagination-disabled"),t(this,a).setAttribute("tabindex","-1")):(t(this,a).classList.remove("pagination-disabled"),t(this,a).removeAttribute("tabindex"))}else t(this,a).hasAttribute("data-pagination-set-link")&&(t(this,a).getAttribute("data-value")===e.toString()?t(this,a).classList.add("pagination-current"):t(this,a).classList.remove("pagination-current"))}destroy(){t(this,a).removeEventListener("click",t(this,Et)),t(this,a).removeEventListener("pointerenter",t(this,rt)),t(this,a).classList.remove("current","exact","pagination-current")}}C=new WeakMap,a=new WeakMap,x=new WeakSet,nt=function(){const e=new URL(t(this,a).href);return t(this,C).normalizePath(e.pathname+e.search+e.hash).path},Mt=function(e){if(!e)return;const s=document.querySelector(e);if(s){const i=parseInt(s.getAttribute("data-current-page")||"1"),n=parseInt(s.getAttribute("data-total-pages")||"1");return{element:s,currentPage:i,totalPages:n,selector:e}}},de=function(){var s;if(document.documentElement.classList.contains("click-disabled"))return;if(t(this,a).hasAttribute("data-back")&&t(this,C).previousURL)history.back();else{const i=t(this,a).getAttribute("data-history-action")||"push",n=t(this,a).hasAttribute("data-center-scroll"),E=getComputedStyle(t(this,a)).getPropertyValue("--offset-scroll").trim(),f=E?ye.cssValueParser.parse(E):void 0,u=t(this,a).hasAttribute("data-revalidate")||t(this,a).hasAttribute("data-pagination-more-link")||t(this,a).hasAttribute("data-pagination-set-link")||t(this,a).hasAttribute("data-pagination-next-link")||t(this,a).hasAttribute("data-pagination-prev-link"),c=t(this,a).hasAttribute("data-keep-search-parameters"),b=t(this,a).hasAttribute("data-keep-scroll-position")||t(this,a).hasAttribute("data-pagination-more-link"),st=t(this,a).getAttribute("data-scroll-behaviour"),k=((s=t(this,a).getAttribute("data-submorph"))==null?void 0:s.split(",").map(w=>w.trim()))||t(this,a).hasAttribute("data-pagination-more-link")&&[t(this,a).getAttribute("data-pagination-more-link")]||t(this,a).hasAttribute("data-pagination-set-link")&&[t(this,a).getAttribute("data-pagination-set-link")]||t(this,a).hasAttribute("data-pagination-next-link")&&[t(this,a).getAttribute("data-pagination-next-link")]||t(this,a).hasAttribute("data-pagination-prev-link")&&[t(this,a).getAttribute("data-pagination-prev-link")]||void 0,at=t(this,a).hasAttribute("data-clear-state");let z=t(this,x,nt);if(t(this,a).hasAttribute("data-toggle-params")){const[w,Rt]=t(this,x,nt).split("?"),d=new URLSearchParams(Rt),B=new URLSearchParams(location.search),it=new URLSearchParams;for(const[H]of d)(!B.has(H)||B.has(H)&&B.get(H)!==d.get(H))&&it.append(H,d.get(H));if(t(this,a).hasAttribute("data-merge-params"))for(const[H]of B)d.has(H)||it.append(H,B.get(H));z=`${w}?${it.toString()}`}const L=g(this,x,Mt).call(this,t(this,a).getAttribute("data-pagination-set-link")||t(this,a).getAttribute("data-pagination-more-link")||t(this,a).getAttribute("data-pagination-next-link")||t(this,a).getAttribute("data-pagination-prev-link"));L&&(t(this,a).hasAttribute("data-pagination-set-link")?t(this,C).links.forEach(w=>{w.updatePagination(parseInt(t(this,a).getAttribute("data-value")||"1"),L.selector)}):t(this,a).hasAttribute("data-pagination-prev-link")?t(this,C).links.forEach(w=>{w.updatePagination(L.currentPage-1,L.selector)}):t(this,a).hasAttribute("data-pagination-next-link")?t(this,C).links.forEach(w=>{w.updatePagination(L.currentPage+1,L.selector)}):t(this,a).hasAttribute("data-pagination-more-link")&&t(this,C).links.forEach(w=>{w.updatePagination(L.currentPage+1,L.selector)})),t(this,C).navigate(z,{historyAction:i,centerScroll:n,offsetScroll:f,revalidate:u,keepSearchParameters:c,submorph:k,clearState:at,keepScrollPosition:b,scrollBehaviour:st,submorphAppend:t(this,a).hasAttribute("data-pagination-more-link"),mergeParams:!!L||t(this,a).hasAttribute("data-merge-params")&&!t(this,a).hasAttribute("data-toggle-params"),detail:t(this,a).getAttribute("data-detail"),removeParams:t(this,a).getAttribute("data-remove-params")||void 0})}},Et=new WeakMap,rt=new WeakMap;var T,ot,bt,Wt,Lt;class ke{constructor(e){l(this,bt);l(this,T);l(this,ot,[]);l(this,Lt,()=>{g(this,bt,Wt).call(this)});o(this,T,e);for(const s in t(this,T).dataset){const i=le.camelToKebab(s);if(i.startsWith("param-")){const n=i.split("param-")[1],E=t(this,T).dataset[s];t(this,ot).push({name:n,value:E})}}document.addEventListener("morphURLParametersChange",t(this,Lt)),g(this,bt,Wt).call(this)}destroy(){document.removeEventListener("morphURLParametersChange",t(this,Lt))}}T=new WeakMap,ot=new WeakMap,bt=new WeakSet,Wt=function(){const e=new URLSearchParams(location.search);let s=!!t(this,ot).find(n=>e.has(n.name)&&(e.get(n.name)===n.value||n.value==="*"||n.value==="all"||n.value==="any"||n.value==="vse"||e.get(n.name)==="*"||e.get(n.name)==="all"||e.get(n.name)==="any"||e.get(n.name)==="vse"));!s&&t(this,T).hasAttribute("data-match-no-params")&&(s=!t(this,ot).filter(n=>e.has(n.name)).length);const i=t(this,T).getAttribute("data-hide-class");s?i?t(this,T).classList.remove(i):t(this,T).style.display="":i?t(this,T).classList.add(i):t(this,T).style.display="none"},Lt=new WeakMap;const we=new DOMParser;var V,Q,M,W,Z,Y,ht,_,$,St,lt;class oe{constructor(e,s){l(this,V);l(this,Q);l(this,M,{x:0,y:0});l(this,W,null);l(this,Z,null);l(this,Y,null);l(this,ht,null);l(this,_,null);l(this,$,null);l(this,St);l(this,lt,!1);o(this,V,e),o(this,Q,s)}get pathname(){return t(this,Q)}get scrollState(){return t(this,M)}get document(){return t(this,Y)}needRavalidation(){o(this,lt,!0)}setHeaders(e){o(this,St,e)}setInitialDocument(e){o(this,W,e.cloneNode(!0))}abort(){var e;return(e=t(this,_))==null?void 0:e.abort(`[${t(this,Q)}] page loading cancelled`)}fetch(e,s,i){return J(this,null,function*(){var n;if(!i&&!t(this,lt)){const u=((n=t(this,W))==null?void 0:n.documentElement.getAttribute("data-cache"))&&s!==e,c=t(this,W)&&t(this,V).isPopstateNavigation;if(t(this,$)||u||c)return t(this,$)}return o(this,$,new Promise(E=>J(this,null,function*(){try{o(this,_,new AbortController);const u=yield(yield fetch(e,{signal:t(this,_).signal,headers:Tt({"X-MORPH":"true","X-MORPH-RAVALIDATE":i?"true":"false","X-MORPH-CURRENT-PATH":encodeURIComponent(s),"X-MORPH-NEW-PATH":encodeURIComponent(e)},t(this,St))})).text(),c=we.parseFromString(u,"text/html");this.setInitialDocument(c),o(this,lt,!1)}catch(f){console.warn(f)}finally{o(this,_,null),o(this,$,null),E()}}))),t(this,$)})}cloneDocument(){o(this,Y,(t(this,Z)||t(this,W)).cloneNode(!0))}get title(){let e="";if(t(this,Y).title)e=t(this,Y).title;else{const s=t(this,Y).querySelector("h1");e=(s==null?void 0:s.innerText)||(s==null?void 0:s.textContent)||t(this,Q)}return e}clearScrollState(){t(this,M).x=0,t(this,M).y=0}clearDocumentState(){o(this,Z,null)}saveScrollState(){t(this,W).documentElement.hasAttribute("data-no-scroll-restoration")?(t(this,M).x=0,t(this,M).y=0):(t(this,M).x=t(this,V).scrollValue.left,t(this,M).y=t(this,V).scrollValue.top)}restoreScrollPosition(){t(this,V).scrollElement.scroll({top:t(this,M).y,left:t(this,M).x,behavior:"instant"})}saveDocumentState(){t(this,W).documentElement.hasAttribute("data-no-page-restoration")?o(this,Z,null):o(this,Z,document.cloneNode(!0))}renewScrollPosition(){t(this,V).scrollElement.scroll({top:0,left:0,behavior:"instant"})}saveState(e){o(this,ht,e)}clearState(){const e=t(this,ht);return o(this,ht,null),e}}V=new WeakMap,Q=new WeakMap,M=new WeakMap,W=new WeakMap,Z=new WeakMap,Y=new WeakMap,ht=new WeakMap,_=new WeakMap,$=new WeakMap,St=new WeakMap,lt=new WeakMap;var D,ct,y,j,v,tt,O,G,N,At,F,yt,et,dt,ut,Pt,mt,kt,p,Ft,wt,gt,Bt,ue,Xt,Kt,Yt,$t,Ut,pt;const vt=class vt{constructor(e){l(this,p);l(this,D,null);l(this,ct,null);l(this,y,[]);l(this,j);l(this,v,null);l(this,tt);l(this,O,[]);l(this,G,!1);l(this,N,null);l(this,At,!1);l(this,F,new Map);l(this,yt,[]);l(this,et,null);l(this,dt,0);l(this,ut,0);l(this,Pt);l(this,mt);l(this,kt);l(this,wt,e=>{var s,i;return(((s=e.getAttribute("href"))==null?void 0:s.startsWith("/"))||((i=e.getAttribute("href"))==null?void 0:i.startsWith("?")))&&!e.hasAttribute("download")&&!e.hasAttribute("data-morph-skip")&&!e.closest("[data-morph-skip]")&&e.getAttribute("target")!=="_blank"});l(this,Ut,e=>J(this,null,function*(){e.preventDefault(),o(this,G,!0),yield this.navigate(location.href.replace(location.origin,""),{historyAction:"none",submorph:t(this,mt)?void 0:t(this,Pt),revalidate:t(this,mt),keepScrollPosition:t(this,kt)}),o(this,G,!1)}));l(this,pt,()=>{const{left:e,top:s}=this.scrollValue,i=s-t(this,ut),n=e-t(this,dt);o(this,ut,s),o(this,dt,e),document.documentElement.classList.toggle("scroll-y",s>0),document.documentElement.classList.toggle("scroll-x",e>0),document.documentElement.classList.toggle("scroll-y-forward",i>0),document.documentElement.classList.toggle("scroll-y-backward",i<0),document.documentElement.classList.toggle("scroll-x-forward",n>0),document.documentElement.classList.toggle("scroll-x-backward",n<0),I.dispatchEvent(document,"morphScroll",{detail:{left:e,top:s}})});if(he.isBrowser&&!vt.instance){vt.instance=this,o(this,D,{base:ft.normalizeBase(e==null?void 0:e.base),waitForHeadToLoad:(e==null?void 0:e.waitForHeadToLoad)!==!1,trailingSlash:(e==null?void 0:e.trailingSlash)||!1,scrollSelector:e==null?void 0:e.scrollSelector,morphInsideScrollContainer:(e==null?void 0:e.morphInsideScrollContainer)||!1}),o(this,ct,g(this,p,Bt).call(this,document.body));const s=this.normalizePath(location.pathname+location.search+location.hash);o(this,v,s);const i=new oe(this,t(this,v).pathname);i.setInitialDocument(document),t(this,F).set(t(this,v).pathname,i),document.documentElement.setAttribute("data-current-pathname",t(this,v).pathname),document.documentElement.setAttribute("data-current-leaf",s.leaf),this.findLinks(),this.findParamsDependent(),history.scrollRestoration="manual",addEventListener("popstate",t(this,Ut)),ft.changeHistory({action:"replace",pathname:s.pathname,searchParameters:s.parameters,hash:s.hash}),o(this,et,new ce),g(this,p,Yt).call(this,document)}}get currentURL(){return t(this,v)}get previousURL(){return t(this,tt)}get links(){return t(this,y)}get scrollElement(){return t(this,N)}get isPopstateNavigation(){return t(this,G)}get scrollValue(){let e=0,s=0;return t(this,At)?(e=window.scrollY,s=window.scrollX):(e=t(this,N).scrollTop,s=t(this,N).scrollLeft),{top:e,left:s}}get isNavigating(){return!!t(this,O).length}saveState(e){const s=t(this,F).get(t(this,v).path);s&&s.saveState(e)}getState(){const e=t(this,F).get(t(this,v).path);return e==null?void 0:e.clearState()}normalizePath(e,s){return ft.splitPath(e,{base:t(this,D).base,trailingSlash:t(this,D).trailingSlash,mergeParams:s!=null&&s.mergeParams?location.search:"",removeParams:s==null?void 0:s.removeParams})}prefetch(e,s){return J(this,null,function*(){var n;if(t(this,O).length)return;e=((n=this.pathnameModifier)==null?void 0:n.call(this,e))||e;const i=g(this,p,gt).call(this,e);i==null||i.fetch(e,t(this,v).path,s)})}excludeHeadChild(e){return!1}setHeaders(e){}needRavalidation(e){const s=this.normalizePath(e),i=g(this,p,gt).call(this,s.path);i==null||i.needRavalidation()}navigate(w){return J(this,arguments,function*(e,{historyAction:s="push",centerScroll:i,offsetScroll:n,scrollBehaviour:E,revalidate:f,keepSearchParameters:u,submorph:c,submorphAppend:b,clearState:st,keepScrollPosition:k,mergeParams:at,removeParams:z,detail:L}={}){var B,it,H,jt;if(t(this,O).length)return;o(this,Pt,c),o(this,mt,f),o(this,kt,k);const Rt=((B=this.pathnameModifier)==null?void 0:B.call(this,e))||e,d=this.normalizePath(Rt,{mergeParams:at,removeParams:z});if(!f&&(((it=t(this,j))==null?void 0:it.pathname)===d.pathname||t(this,v).pathname===d.pathname)){k||g(this,p,$t).call(this,d.hash||0,{centerScroll:i,offsetScroll:n,behavior:"smooth"}),I.dispatchEvent(document,"morphSamePath",{detail:{detail:L}}),((H=t(this,v))==null?void 0:H.parameters)!==d.parameters&&(o(this,tt,t(this,v)),o(this,v,d),ft.changeHistory({action:((jt=t(this,v))==null?void 0:jt.hash)!==d.hash?"replace":s,pathname:d.pathname,searchParameters:d.parameters,hash:d.hash}),I.dispatchEvent(document,"morphURLParametersChange",{detail:{newURL:t(this,v),previousURL:t(this,tt),detail:L}})),t(this,y).forEach(X=>{X.checkCurrent(d.path)});return}else t(this,y).forEach(X=>{X.checkCurrent(d.path)});o(this,j,d);try{let X=!0;if(this.preprocessor)try{yield new Promise((r,P)=>{var U;(U=this.preprocessor)==null||U.call(this,{url:d,resolve:r,reject:P,submorph:c,detail:L})})}catch(r){r?console.error(r):console.log("Route change canceled"),X=!1}if(!X||t(this,j).pathname!==d.pathname){t(this,y).forEach(r=>{r.checkCurrent(t(this,v).path)});return}const Gt={url:d,submorph:c,detail:L};c?b||c.forEach(r=>{document.querySelectorAll(r).forEach(P=>{P.classList.add("out"),P.setAttribute("data-morph-out","")})}):t(this,ct).forEach(r=>{var P,U;(P=r.firstElementChild)==null||P.classList.add("out"),(U=r.firstElementChild)==null||U.setAttribute("data-morph-out","")}),I.dispatchEvent(document,"morphNavigation",{detail:Gt});const Nt=g(this,p,gt).call(this,t(this,v).pathname),A=g(this,p,gt).call(this,d.pathname);if(t(this,F).forEach(r=>{r.pathname!==d.pathname&&r.abort()}),yield A==null?void 0:A.fetch(Rt,t(this,v).path,f),t(this,j).pathname!==d.pathname){t(this,y).forEach(r=>{r.checkCurrent(t(this,v).path)});return}Nt.clearState(),Nt.saveScrollState(),Nt.saveDocumentState(),(!t(this,G)||f)&&(A.clearScrollState(),A.clearDocumentState()),st&&A.clearState(),A.cloneDocument(),t(this,et).textContent=A.title,document.body.appendChild(t(this,et));const Ct=zt(Tt({},Gt),{document:A.document});b||Ct.document.querySelectorAll("[data-morph-out]").forEach(r=>{r.classList.remove("out")}),I.dispatchEvent(document,"morphStart",{detail:Ct});const Jt=Array.from(document.head.children),Qt=Array.from(A.document.head.children),Zt=g(this,p,ue).call(this,Jt,Qt),me=g(this,p,Xt).call(this,Jt,Zt),xt=g(this,p,Xt).call(this,Qt,Zt).filter(r=>!this.excludeHeadChild(r));xt.forEach((r,P)=>{r.tagName==="SCRIPT"&&(xt[P]=g(this,p,Ft).call(this,r))}),xt.forEach(r=>{document.head.appendChild(r)});const qt=xt.filter(r=>{if(r.hasAttribute("data-no-waiting"))return!1;if(g(this,p,Kt).call(this,r))return!0});t(this,D).waitForHeadToLoad&&qt.length&&(yield new Promise(r=>J(this,null,function*(){let P=0;try{for(var U=ne(qt),fe,K,q;fe=!(K=yield U.next()).done;fe=!1){const Ht=K.value;Ht.onload=()=>{P++,P===qt.length&&r()}}}catch(K){q=[K]}finally{try{fe&&(K=U.return)&&(yield K.call(U))}finally{if(q)throw q[0]}}}))),yield re.wait(10);const _t=[];b||me.forEach(r=>{r.hasAttribute("data-permanent")||(g(this,p,Kt).call(this,r)?_t.push(r):r.remove())});const pe=g(this,p,Bt).call(this,A.document.body);!t(this,D).morphInsideScrollContainer&&!c&&g(this,p,Yt).call(this,A.document),document.documentElement.setAttribute("data-current-pathname",d.pathname),document.documentElement.setAttribute("data-current-leaf",d.leaf),ft.changeHistory({action:s,pathname:d.pathname,searchParameters:d.parameters||(u?location.search:""),hash:d.hash}),t(this,et).remove(),o(this,tt,t(this,v)),o(this,v,d);const Dt=[];t(this,ct).forEach((r,P)=>{const U=pe[P],fe=getComputedStyle(r).getPropertyValue("--morph-duration");let K=[],q=[];c?(c.forEach(m=>{const S=r.querySelector(m),R=U.querySelector(m);S&&R&&(q.push(S),K.push(R))}),q.forEach(m=>{m.parentElement&&Dt.push(m.parentElement)})):(K.push(...U.childNodes),q.push(...r.childNodes),Dt.push(r));const Ht=[];b||q.forEach(m=>{m instanceof HTMLElement&&(this.destroyOldLinks(m),m.classList.add("old"),m.querySelectorAll("[data-morph-transfer]").forEach(R=>{const ve=R.getAttribute("data-morph-transfer");Ht.push({element:R,selector:ve})}))}),K.forEach(m=>{m instanceof HTMLElement&&(Ht.forEach(S=>{const R=m.querySelector(S.selector);R&&R.replaceWith(A.document.importNode(S.element,!0))}),this.findNewLinks(m),m.classList.add("new"))}),c?b?K.forEach((m,S)=>{q[S]instanceof HTMLElement&&q[S].append(...m.childNodes)}):K.forEach((m,S)=>{var R;(R=q[S].parentElement)==null||R.insertBefore(m,q[S])}):r.prepend(...K),setTimeout(()=>{b||q.forEach(m=>{m instanceof HTMLElement&&m.classList.add("old-idle")}),K.forEach(m=>{var S;m instanceof HTMLElement&&((S=m.parentElement)==null||S.style.setProperty("--new-content-height",m.offsetHeight+"px"),m.classList.add("new-idle"))})},0);const te=zt(Tt({},Ct),{morphElement:r});I.dispatchEvent(document,"morphNewChildrenAdded",{detail:te});const ge=new Promise(m=>{setTimeout(()=>{b||q.forEach(S=>{S.remove()}),K.forEach(S=>{var R;S instanceof HTMLElement&&((R=S.parentElement)==null||R.style.removeProperty("--new-content-height"),S.classList.remove("new-idle","new"))}),b||I.dispatchEvent(document,"morphOldChildrenRemoved",{detail:te}),m()},(parseFloat(fe)||0)*1e3+10)});t(this,O).push(ge)}),this.isPopstateNavigation?document.documentElement.style.setProperty("--new-document-scroll-position",(this.scrollValue.top-A.scrollState.y)*1+"px"):document.documentElement.style.setProperty("--new-document-scroll-position",this.scrollValue.top+"px"),I.dispatchEvent(document,"morphBeforeNavigationScroll",{detail:A.scrollState}),d.hash?(A.clearScrollState(),g(this,p,$t).call(this,d.hash,{centerScroll:i,offsetScroll:n,behavior:E})):t(this,G)?A.restoreScrollPosition():k||A.renewScrollPosition(),yield Promise.all(t(this,O)),b||_t.forEach(r=>r.remove()),o(this,O,[]),Dt.forEach(r=>{r.querySelectorAll("script").forEach(U=>{U.replaceWith(g(this,p,Ft).call(this,U))})}),t(this,y).forEach(r=>{r.checkCurrent(t(this,v).path)}),this.findParamsDependent(),I.dispatchEvent(document,"morphComplete",{detail:Ct}),document.documentElement.style.removeProperty("--new-document-scroll-position"),window.dispatchEvent(new Event("resize"))}catch(X){console.error(X)}o(this,j,void 0)})}addLink(e){t(this,y).push(new Vt(e,this))}addLinks(e){e.forEach(s=>{this.addLink(s)})}removeLink(e){o(this,y,t(this,y).filter(s=>s.element===e?(s.destroy(),!1):!0))}destroyOldLinks(e){o(this,y,t(this,y).filter(s=>e.contains(s.element)?(s.destroy(),!1):!0))}findNewLinks(e){const s=[...e.querySelectorAll("a")].filter(t(this,wt));t(this,y).push(...s.map(i=>new Vt(i,this)))}findLinks(){const e=[...document.documentElement.querySelectorAll("a")].filter(t(this,wt));t(this,y).forEach(s=>s.destroy()),o(this,y,e.map(s=>new Vt(s,this)))}findParamsDependent(){const e=[...document.documentElement.querySelectorAll("[data-morph-params-dependent]")];t(this,yt).forEach(s=>s.destroy()),o(this,yt,e.map(s=>new ke(s)))}};D=new WeakMap,ct=new WeakMap,y=new WeakMap,j=new WeakMap,v=new WeakMap,tt=new WeakMap,O=new WeakMap,G=new WeakMap,N=new WeakMap,At=new WeakMap,F=new WeakMap,yt=new WeakMap,et=new WeakMap,dt=new WeakMap,ut=new WeakMap,Pt=new WeakMap,mt=new WeakMap,kt=new WeakMap,p=new WeakSet,Ft=function(e){const s=document.createElement("script");for(let i=0;i<e.attributes.length;i++){const n=e.attributes[i];s.setAttribute(n.name,n.value)}return e.hasAttribute("src")||(s.innerHTML=e.innerHTML),s},wt=new WeakMap,gt=function(e){const s=this.normalizePath(e);let i=t(this,F).get(s.pathname);return i||(i=new oe(this,s.pathname),t(this,F).set(s.pathname,i)),i},Bt=function(e){const s=[...e.querySelectorAll("[data-morph]")];return s.length?s:[e]},ue=function(e,s){return e.filter(i=>s.find(n=>n.outerHTML===i.outerHTML))},Xt=function(e,s){return e.filter(i=>!s.find(n=>n.outerHTML===i.outerHTML))},Kt=function(e){return e.tagName==="SCRIPT"||e.tagName==="STYLE"||e.tagName==="LINK"&&e.getAttribute("rel")==="stylesheet"},Yt=function(e){var s,i;(s=t(this,N))==null||s.removeEventListener("scroll",t(this,pt)),o(this,ut,0),o(this,dt,0),o(this,N,t(this,D).scrollSelector&&e.querySelector(t(this,D).scrollSelector)||window),o(this,At,t(this,N)===window),(i=t(this,N))==null||i.addEventListener("scroll",t(this,pt)),t(this,pt).call(this)},$t=function(e,s){const i=typeof e=="string"?document.getElementById(e):e;(typeof i=="number"||i)&&re.scrollToElement(i,{scrollElement:t(this,N),behavior:(s==null?void 0:s.behavior)||"instant",center:s==null?void 0:s.centerScroll,offset:s==null?void 0:s.offsetScroll})},Ut=new WeakMap,pt=new WeakMap,vt.instance=null;let Ot=vt;exports.Morph=Ot;
1
+ "use strict";var ve=Object.defineProperty,Le=Object.defineProperties;var Se=Object.getOwnPropertyDescriptors;var ee=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,be=Object.prototype.propertyIsEnumerable;var se=(h,e)=>(e=Symbol[h])?e:Symbol.for("Symbol."+h),ie=h=>{throw TypeError(h)};var ae=(h,e,s)=>e in h?ve(h,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):h[e]=s,Tt=(h,e)=>{for(var s in e||(e={}))ye.call(e,s)&&ae(h,s,e[s]);if(ee)for(var s of ee(e))be.call(e,s)&&ae(h,s,e[s]);return h},qt=(h,e)=>Le(h,Se(e));var zt=(h,e,s)=>e.has(h)||ie("Cannot "+s);var t=(h,e,s)=>(zt(h,e,"read from private field"),s?s.call(h):e.get(h)),l=(h,e,s)=>e.has(h)?ie("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(h):e.set(h,s),n=(h,e,s,a)=>(zt(h,e,"write to private field"),a?a.call(h,s):e.set(h,s),s),g=(h,e,s)=>(zt(h,e,"access private method"),s);var J=(h,e,s)=>new Promise((a,o)=>{var L=c=>{try{p(s.next(c))}catch(E){o(E)}},y=c=>{try{p(s.throw(c))}catch(E){o(E)}},p=c=>c.done?a(c.value):Promise.resolve(c.value).then(L,y);p((s=s.apply(h,e)).next())});var re=(h,e,s)=>(e=h[se("asyncIterator")])?e.call(h):(h=h[se("iterator")](),e={},s=(a,o)=>(o=h[a])&&(e[a]=L=>new Promise((y,p,c)=>(L=o.call(h,L),c=L.done,Promise.resolve(L.value).then(E=>y({value:E,done:c}),p)))),s("next"),s("return"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const he=require("../index-CKTweR3M.cjs"),z=require("../events-KVanG9sR.cjs"),ne=require("../scroll-DxcPU0vk.cjs");require("construct-style-sheets-polyfill");const ft=require("../url-CPgw9bd5.cjs"),we=require("../css-value-parser/index.cjs"),le=require("../string-DUXXtU8v.cjs");class ce extends HTMLElement{connectedCallback(){const e={"aria-live":"assertive","aria-atomic":"true",style:"position: absolute; left: 0; top: 0; clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap; width: 1px; height: 1px"};for(const[s,a]of Object.entries(e))this.setAttribute(s,a)}}he.isBrowser&&!customElements.get("morph-announcer")&&customElements.define("morph-announcer",ce);var x,i,D,it,de,Et,rt;class It{constructor(e,s){l(this,D);l(this,x);l(this,i);l(this,Et,e=>{e.preventDefault(),g(this,D,de).call(this)});l(this,rt,()=>{const e=t(this,i).hasAttribute("data-revalidate");t(this,x).prefetch(t(this,D,it),e),t(this,i).removeEventListener("pointerenter",t(this,rt))});n(this,x,s),n(this,i,e),t(this,i).addEventListener("click",t(this,Et)),this.checkCurrent(location.href.replace(location.origin,"")),t(this,i).hasAttribute("data-prefetch")&&t(this,i).addEventListener("pointerenter",t(this,rt))}get element(){return t(this,i)}checkCurrent(e){var E,st;const s=t(this,x).normalizePath(e),a=t(this,x).normalizePath(t(this,D,it));t(this,i).hasAttribute("data-include")&&s.pathname.includes(a.pathname)?t(this,i).classList.add("current"):a.pathname===s.pathname?t(this,i).classList.add("current"):(E=t(this,i).getAttribute("data-associated-paths"))!=null&&E.split(",").find(A=>s.pathname.includes(A))?t(this,i).classList.add("current"):t(this,i).classList.remove("current"),s.path===a.path?t(this,i).classList.add("exact"):t(this,i).classList.remove("exact");const[o,L]=(st=t(this,D,it).split("#")[0])==null?void 0:st.split("?"),y=new URLSearchParams(L),p=new URLSearchParams(location.search);let c=0;for(const[A]of p)y.has(A)&&p.get(A)===y.get(A)&&c++;c?(t(this,i).classList.toggle("all-params-matched",p.size===c),t(this,i).classList.toggle("some-params-matched",p.size!==c)):!p.size&&t(this,i).hasAttribute("data-match-no-params")?t(this,i).classList.add("all-params-matched"):(t(this,i).classList.remove("all-params-matched"),t(this,i).classList.remove("some-params-matched"));for(const A in t(this,i).dataset){const at=le.camelToKebab(A);if(at.startsWith("match-param-")){const q=at.split("match-param-")[1],w=t(this,i).dataset[A],G=`param-${q}-matched`;p.has(q)&&p.get(q)===w||!p.has(q)&&(w===""||w==="*"||w==="all"||w==="any"||w==="vse")?t(this,i).classList.add(G):t(this,i).classList.remove(G)}}}destroy(){t(this,i).removeEventListener("click",t(this,Et)),t(this,i).removeEventListener("pointerenter",t(this,rt)),t(this,i).classList.remove("current","exact")}}x=new WeakMap,i=new WeakMap,D=new WeakSet,it=function(){const e=new URL(t(this,i).href);return t(this,x).normalizePath(e.pathname+e.search+e.hash).path},de=function(){var s;if(document.documentElement.classList.contains("click-disabled"))return;if(t(this,i).hasAttribute("data-back")&&t(this,x).previousURL)history.back();else{const a=t(this,i).getAttribute("data-history-action")||"push",o=t(this,i).hasAttribute("data-center-scroll"),L=getComputedStyle(t(this,i)).getPropertyValue("--offset-scroll").trim(),y=L?we.cssValueParser.parse(L):void 0,p=t(this,i).hasAttribute("data-revalidate")||t(this,i).hasAttribute("data-pagination-more-link")||t(this,i).hasAttribute("data-pagination-set-link")||t(this,i).hasAttribute("data-pagination-next-link")||t(this,i).hasAttribute("data-pagination-prev-link"),c=t(this,i).hasAttribute("data-keep-search-parameters"),E=t(this,i).hasAttribute("data-keep-scroll-position")||t(this,i).hasAttribute("data-pagination-more-link"),st=t(this,i).getAttribute("data-scroll-behaviour"),A=(s=t(this,i).getAttribute("data-submorph")||t(this,i).getAttribute("data-submorph-append"))==null?void 0:s.split(",").map(w=>w.trim()),at=t(this,i).hasAttribute("data-clear-state");let q=t(this,D,it);if(t(this,i).hasAttribute("data-toggle-params")){const[w,G]=t(this,D,it).split("?"),kt=new URLSearchParams(G),F=new URLSearchParams(location.search),d=new URLSearchParams;for(const[R]of kt)(!F.has(R)||F.has(R)&&F.get(R)!==kt.get(R))&&d.append(R,kt.get(R));if(t(this,i).hasAttribute("data-merge-params"))for(const[R]of F)kt.has(R)||d.append(R,F.get(R));q=`${w}?${d.toString()}`}t(this,x).navigate(q,{historyAction:a,centerScroll:o,offsetScroll:y,revalidate:p,keepSearchParameters:c,submorph:A,clearState:at,keepScrollPosition:E,scrollBehaviour:st,submorphAppend:t(this,i).hasAttribute("data-submorph-append"),mergeParams:t(this,i).hasAttribute("data-merge-params")&&!t(this,i).hasAttribute("data-toggle-params"),detail:t(this,i).getAttribute("data-detail"),removeParams:t(this,i).getAttribute("data-remove-params")||void 0,scrollTo:t(this,i).getAttribute("data-scroll-to")||void 0})}},Et=new WeakMap,rt=new WeakMap;var C,nt,vt,Vt,Lt;class Pe{constructor(e){l(this,vt);l(this,C);l(this,nt,[]);l(this,Lt,()=>{g(this,vt,Vt).call(this)});n(this,C,e);for(const s in t(this,C).dataset){const a=le.camelToKebab(s);if(a.startsWith("param-")){const o=a.split("param-")[1],L=t(this,C).dataset[s];t(this,nt).push({name:o,value:L})}}document.addEventListener("morphURLParametersChange",t(this,Lt)),g(this,vt,Vt).call(this)}destroy(){document.removeEventListener("morphURLParametersChange",t(this,Lt))}}C=new WeakMap,nt=new WeakMap,vt=new WeakSet,Vt=function(){const e=new URLSearchParams(location.search);let s=!!t(this,nt).find(o=>e.has(o.name)&&(e.get(o.name)===o.value||o.value==="*"||o.value==="all"||o.value==="any"||o.value==="vse"||e.get(o.name)==="*"||e.get(o.name)==="all"||e.get(o.name)==="any"||e.get(o.name)==="vse"));!s&&t(this,C).hasAttribute("data-match-no-params")&&(s=!t(this,nt).filter(o=>e.has(o.name)).length);const a=t(this,C).getAttribute("data-hide-class");s?a?t(this,C).classList.remove(a):t(this,C).style.display="":a?t(this,C).classList.add(a):t(this,C).style.display="none"},Lt=new WeakMap;const Ae=new DOMParser;var I,Q,H,V,Z,K,ot,_,Y,St,ht;class oe{constructor(e,s){l(this,I);l(this,Q);l(this,H,{x:0,y:0});l(this,V,null);l(this,Z,null);l(this,K,null);l(this,ot,null);l(this,_,null);l(this,Y,null);l(this,St);l(this,ht,!1);n(this,I,e),n(this,Q,s)}get pathname(){return t(this,Q)}get scrollState(){return t(this,H)}get document(){return t(this,K)}needRavalidation(){n(this,ht,!0)}setHeaders(e){n(this,St,e)}setInitialDocument(e){n(this,V,e.cloneNode(!0))}abort(){var e;return(e=t(this,_))==null?void 0:e.abort(`[${t(this,Q)}] page loading cancelled`)}fetch(e,s,a){return J(this,null,function*(){var o;if(!a&&!t(this,ht)){const p=((o=t(this,V))==null?void 0:o.documentElement.getAttribute("data-cache"))&&s!==e,c=t(this,V)&&t(this,I).isPopstateNavigation;if(t(this,Y)||p||c)return t(this,Y)}return n(this,Y,new Promise(L=>J(this,null,function*(){try{n(this,_,new AbortController);const p=yield(yield fetch(e,{signal:t(this,_).signal,headers:Tt({"X-MORPH":"true","X-MORPH-RAVALIDATE":a?"true":"false","X-MORPH-CURRENT-PATH":encodeURIComponent(s),"X-MORPH-NEW-PATH":encodeURIComponent(e)},t(this,St))})).text(),c=Ae.parseFromString(p,"text/html");this.setInitialDocument(c),n(this,ht,!1)}catch(y){console.warn(y)}finally{n(this,_,null),n(this,Y,null),L()}}))),t(this,Y)})}cloneDocument(){n(this,K,(t(this,Z)||t(this,V)).cloneNode(!0))}get title(){let e="";if(t(this,K).title)e=t(this,K).title;else{const s=t(this,K).querySelector("h1");e=(s==null?void 0:s.innerText)||(s==null?void 0:s.textContent)||t(this,Q)}return e}clearScrollState(){t(this,H).x=0,t(this,H).y=0}clearDocumentState(){n(this,Z,null)}saveScrollState(){t(this,V).documentElement.hasAttribute("data-no-scroll-restoration")?(t(this,H).x=0,t(this,H).y=0):(t(this,H).x=t(this,I).scrollValue.left,t(this,H).y=t(this,I).scrollValue.top)}restoreScrollPosition(){t(this,I).scrollElement.scroll({top:t(this,H).y,left:t(this,H).x,behavior:"instant"})}saveDocumentState(){t(this,V).documentElement.hasAttribute("data-no-page-restoration")?n(this,Z,null):n(this,Z,document.cloneNode(!0))}renewScrollPosition(){t(this,I).scrollElement.scroll({top:0,left:0,behavior:"instant"})}saveState(e){n(this,ot,e)}clearState(){const e=t(this,ot);return n(this,ot,null),e}}I=new WeakMap,Q=new WeakMap,H=new WeakMap,V=new WeakMap,Z=new WeakMap,K=new WeakMap,ot=new WeakMap,_=new WeakMap,Y=new WeakMap,St=new WeakMap,ht=new WeakMap;var N,lt,b,$,f,tt,W,j,M,yt,O,bt,et,ct,dt,wt,ut,Pt,m,Ot,At,pt,Ft,ue,Xt,Bt,Kt,Mt,Ut,mt;const gt=class gt{constructor(e){l(this,m);l(this,N,null);l(this,lt,null);l(this,b,[]);l(this,$);l(this,f,null);l(this,tt);l(this,W,[]);l(this,j,!1);l(this,M,null);l(this,yt,!1);l(this,O,new Map);l(this,bt,[]);l(this,et,null);l(this,ct,0);l(this,dt,0);l(this,wt);l(this,ut);l(this,Pt);l(this,At,e=>{var s,a;return(((s=e.getAttribute("href"))==null?void 0:s.startsWith("/"))||((a=e.getAttribute("href"))==null?void 0:a.startsWith("?")))&&!e.hasAttribute("download")&&!e.hasAttribute("data-morph-skip")&&!e.closest("[data-morph-skip]")&&e.getAttribute("target")!=="_blank"});l(this,Ut,e=>J(this,null,function*(){e.preventDefault(),n(this,j,!0),yield this.navigate(location.href.replace(location.origin,""),{historyAction:"none",submorph:t(this,ut)?void 0:t(this,wt),revalidate:t(this,ut),keepScrollPosition:t(this,Pt)}),n(this,j,!1)}));l(this,mt,()=>{const{left:e,top:s}=this.scrollValue,a=s-t(this,dt),o=e-t(this,ct);n(this,dt,s),n(this,ct,e),document.documentElement.classList.toggle("scroll-y",s>0),document.documentElement.classList.toggle("scroll-x",e>0),document.documentElement.classList.toggle("scroll-y-forward",a>0),document.documentElement.classList.toggle("scroll-y-backward",a<0),document.documentElement.classList.toggle("scroll-x-forward",o>0),document.documentElement.classList.toggle("scroll-x-backward",o<0),z.dispatchEvent(document,"morphScroll",{detail:{left:e,top:s}})});if(he.isBrowser&&!gt.instance){gt.instance=this,n(this,N,{base:ft.normalizeBase(e==null?void 0:e.base),waitForHeadToLoad:(e==null?void 0:e.waitForHeadToLoad)!==!1,trailingSlash:(e==null?void 0:e.trailingSlash)||!1,scrollSelector:e==null?void 0:e.scrollSelector,morphInsideScrollContainer:(e==null?void 0:e.morphInsideScrollContainer)||!1}),n(this,lt,g(this,m,Ft).call(this,document.body));const s=this.normalizePath(location.pathname+location.search+location.hash);n(this,f,s);const a=new oe(this,t(this,f).pathname);a.setInitialDocument(document),t(this,O).set(t(this,f).pathname,a),document.documentElement.setAttribute("data-current-pathname",t(this,f).pathname),document.documentElement.setAttribute("data-current-leaf",s.leaf),this.findLinks(),this.findParamsDependent(),history.scrollRestoration="manual",addEventListener("popstate",t(this,Ut)),ft.changeHistory({action:"replace",pathname:s.pathname,searchParameters:s.parameters,hash:s.hash}),n(this,et,new ce),g(this,m,Kt).call(this,document)}}get currentURL(){return t(this,f)}get previousURL(){return t(this,tt)}get links(){return t(this,b)}get scrollElement(){return t(this,M)}get isPopstateNavigation(){return t(this,j)}get scrollValue(){let e=0,s=0;return t(this,yt)?(e=window.scrollY,s=window.scrollX):(e=t(this,M).scrollTop,s=t(this,M).scrollLeft),{top:e,left:s}}get isNavigating(){return!!t(this,W).length}saveState(e){const s=t(this,O).get(t(this,f).path);s&&s.saveState(e)}getState(){const e=t(this,O).get(t(this,f).path);return e==null?void 0:e.clearState()}normalizePath(e,s){return ft.splitPath(e,{base:t(this,N).base,trailingSlash:t(this,N).trailingSlash,mergeParams:s!=null&&s.mergeParams?location.search:"",removeParams:s==null?void 0:s.removeParams})}prefetch(e,s){return J(this,null,function*(){var o;if(t(this,W).length)return;e=((o=this.pathnameModifier)==null?void 0:o.call(this,e))||e;const a=g(this,m,pt).call(this,e);a==null||a.fetch(e,t(this,f).path,s)})}excludeHeadChild(e){return!1}setHeaders(e){}needRavalidation(e){const s=this.normalizePath(e),a=g(this,m,pt).call(this,s.path);a==null||a.needRavalidation()}navigate(kt){return J(this,arguments,function*(e,{historyAction:s="push",centerScroll:a,offsetScroll:o,scrollBehaviour:L,revalidate:y,keepSearchParameters:p,submorph:c,submorphAppend:E,clearState:st,keepScrollPosition:A,mergeParams:at,removeParams:q,detail:w,scrollTo:G}={}){var R,Yt,$t,jt;if(t(this,W).length)return;n(this,wt,c),n(this,ut,y),n(this,Pt,A);const F=((R=this.pathnameModifier)==null?void 0:R.call(this,e))||e,d=this.normalizePath(F,{mergeParams:at,removeParams:q});if(!y&&(((Yt=t(this,$))==null?void 0:Yt.pathname)===d.pathname||t(this,f).pathname===d.pathname)){A||g(this,m,Mt).call(this,d.hash||0,{centerScroll:a,offsetScroll:o,behavior:"smooth"}),z.dispatchEvent(document,"morphSamePath",{detail:{detail:w}}),(($t=t(this,f))==null?void 0:$t.parameters)!==d.parameters&&(n(this,tt,t(this,f)),n(this,f,d),ft.changeHistory({action:((jt=t(this,f))==null?void 0:jt.hash)!==d.hash?"replace":s,pathname:d.pathname,searchParameters:d.parameters,hash:d.hash}),z.dispatchEvent(document,"morphURLParametersChange",{detail:{newURL:t(this,f),previousURL:t(this,tt),detail:w}})),t(this,b).forEach(X=>{X.checkCurrent(d.path)});return}else t(this,b).forEach(X=>{X.checkCurrent(d.path)});n(this,$,d);try{let X=!0;if(this.preprocessor)try{yield new Promise((r,P)=>{var T;(T=this.preprocessor)==null||T.call(this,{url:d,resolve:r,reject:P,submorph:c,detail:w})})}catch(r){r?console.error(r):console.log("Route change canceled"),X=!1}if(!X||t(this,$).pathname!==d.pathname){t(this,b).forEach(r=>{r.checkCurrent(t(this,f).path)});return}const Gt={url:d,submorph:c,detail:w};c?E||c.forEach(r=>{document.querySelectorAll(r).forEach(P=>{P.classList.add("out"),P.setAttribute("data-morph-out","")})}):t(this,lt).forEach(r=>{var P,T;(P=r.firstElementChild)==null||P.classList.add("out"),(T=r.firstElementChild)==null||T.setAttribute("data-morph-out","")}),z.dispatchEvent(document,"morphNavigation",{detail:Gt});const xt=g(this,m,pt).call(this,t(this,f).pathname),S=g(this,m,pt).call(this,d.pathname);if(t(this,O).forEach(r=>{r.pathname!==d.pathname&&r.abort()}),yield S==null?void 0:S.fetch(F,t(this,f).path,y),t(this,$).pathname!==d.pathname){t(this,b).forEach(r=>{r.checkCurrent(t(this,f).path)});return}xt.clearState(),xt.saveScrollState(),xt.saveDocumentState(),(!t(this,j)||y)&&(S.clearScrollState(),S.clearDocumentState()),st&&S.clearState(),S.cloneDocument(),t(this,et).textContent=S.title,document.body.appendChild(t(this,et));const Rt=qt(Tt({},Gt),{document:S.document});E||Rt.document.querySelectorAll("[data-morph-out]").forEach(r=>{r.classList.remove("out")}),z.dispatchEvent(document,"morphStart",{detail:Rt});const Jt=Array.from(document.head.children),Qt=Array.from(S.document.head.children),Zt=g(this,m,ue).call(this,Jt,Qt),me=g(this,m,Xt).call(this,Jt,Zt),Ct=g(this,m,Xt).call(this,Qt,Zt).filter(r=>!this.excludeHeadChild(r));Ct.forEach((r,P)=>{r.tagName==="SCRIPT"&&(Ct[P]=g(this,m,Ot).call(this,r))}),Ct.forEach(r=>{document.head.appendChild(r)});const Nt=Ct.filter(r=>{if(r.hasAttribute("data-no-waiting"))return!1;if(g(this,m,Bt).call(this,r))return!0});t(this,N).waitForHeadToLoad&&Nt.length&&(yield new Promise(r=>J(this,null,function*(){let P=0;try{for(var T=re(Nt),pe,B,U;pe=!(B=yield T.next()).done;pe=!1){const Ht=B.value;Ht.onload=()=>{P++,P===Nt.length&&r()}}}catch(B){U=[B]}finally{try{pe&&(B=T.return)&&(yield B.call(T))}finally{if(U)throw U[0]}}}))),yield ne.wait(10);const _t=[];E||me.forEach(r=>{r.hasAttribute("data-permanent")||(g(this,m,Bt).call(this,r)?_t.push(r):r.remove())});const fe=g(this,m,Ft).call(this,S.document.body);!t(this,N).morphInsideScrollContainer&&!c&&g(this,m,Kt).call(this,S.document),document.documentElement.setAttribute("data-current-pathname",d.pathname),document.documentElement.setAttribute("data-current-leaf",d.leaf),ft.changeHistory({action:s,pathname:d.pathname,searchParameters:d.parameters||(p?location.search:""),hash:d.hash}),t(this,et).remove(),n(this,tt,t(this,f)),n(this,f,d);const Dt=[];t(this,lt).forEach((r,P)=>{const T=fe[P],pe=getComputedStyle(r).getPropertyValue("--morph-duration");let B=[],U=[];c?(c.forEach(u=>{const v=r.querySelector(u),k=T.querySelector(u);v&&k&&(U.push(v),B.push(k))}),U.forEach(u=>{u.parentElement&&Dt.push(u.parentElement)})):(B.push(...T.childNodes),U.push(...r.childNodes),Dt.push(r));const Ht=[];E||U.forEach(u=>{u instanceof HTMLElement&&(this.destroyOldLinks(u),u.classList.add("old"),u.querySelectorAll("[data-morph-transfer]").forEach(k=>{const Ee=k.getAttribute("data-morph-transfer");Ht.push({element:k,selector:Ee})}))}),B.forEach(u=>{u instanceof HTMLElement&&(Ht.forEach(v=>{const k=u.querySelector(v.selector);k&&k.replaceWith(S.document.importNode(v.element,!0))}),this.findNewLinks(u),u.classList.add("new"))}),c?E?B.forEach((u,v)=>{U[v]instanceof HTMLElement&&U[v].append(...u.childNodes)}):B.forEach((u,v)=>{var k;(k=U[v].parentElement)==null||k.insertBefore(u,U[v])}):r.prepend(...B),setTimeout(()=>{E||U.forEach(u=>{u instanceof HTMLElement&&u.classList.add("old-idle")}),B.forEach(u=>{var v;u instanceof HTMLElement&&((v=u.parentElement)==null||v.style.setProperty("--new-content-height",u.offsetHeight+"px"),u.classList.add("new-idle"))})},0);const te=qt(Tt({},Rt),{morphElement:r});z.dispatchEvent(document,"morphNewChildrenAdded",{detail:te});const ge=new Promise(u=>{setTimeout(()=>{E||U.forEach(v=>{v.remove()}),B.forEach(v=>{var k;v instanceof HTMLElement&&((k=v.parentElement)==null||k.style.removeProperty("--new-content-height"),v.classList.remove("new-idle","new"))}),E||z.dispatchEvent(document,"morphOldChildrenRemoved",{detail:te}),u()},(parseFloat(pe)||0)*1e3+10)});t(this,W).push(ge)}),this.isPopstateNavigation?document.documentElement.style.setProperty("--new-document-scroll-position",(this.scrollValue.top-S.scrollState.y)*1+"px"):document.documentElement.style.setProperty("--new-document-scroll-position",this.scrollValue.top+"px"),z.dispatchEvent(document,"morphBeforeNavigationScroll",{detail:S.scrollState}),G?(S.clearScrollState(),g(this,m,Mt).call(this,G,{centerScroll:a,offsetScroll:o,behavior:L})):d.hash?(S.clearScrollState(),g(this,m,Mt).call(this,d.hash,{centerScroll:a,offsetScroll:o,behavior:L})):t(this,j)?S.restoreScrollPosition():A||S.renewScrollPosition(),yield Promise.all(t(this,W)),E||_t.forEach(r=>r.remove()),n(this,W,[]),Dt.forEach(r=>{r.querySelectorAll("script").forEach(T=>{T.replaceWith(g(this,m,Ot).call(this,T))})}),t(this,b).forEach(r=>{r.checkCurrent(t(this,f).path)}),this.findParamsDependent(),z.dispatchEvent(document,"morphComplete",{detail:Rt}),document.documentElement.style.removeProperty("--new-document-scroll-position"),window.dispatchEvent(new Event("resize"))}catch(X){console.error(X)}n(this,$,void 0)})}addLink(e){t(this,b).push(new It(e,this))}addLinks(e){e.forEach(s=>{this.addLink(s)})}removeLink(e){n(this,b,t(this,b).filter(s=>s.element===e?(s.destroy(),!1):!0))}destroyOldLinks(e){n(this,b,t(this,b).filter(s=>e.contains(s.element)?(s.destroy(),!1):!0))}findNewLinks(e){const s=[...e.querySelectorAll("a")].filter(t(this,At));t(this,b).push(...s.map(a=>new It(a,this)))}findLinks(){const e=[...document.documentElement.querySelectorAll("a")].filter(t(this,At));t(this,b).forEach(s=>s.destroy()),n(this,b,e.map(s=>new It(s,this)))}findParamsDependent(){const e=[...document.documentElement.querySelectorAll("[data-morph-params-dependent]")];t(this,bt).forEach(s=>s.destroy()),n(this,bt,e.map(s=>new Pe(s)))}};N=new WeakMap,lt=new WeakMap,b=new WeakMap,$=new WeakMap,f=new WeakMap,tt=new WeakMap,W=new WeakMap,j=new WeakMap,M=new WeakMap,yt=new WeakMap,O=new WeakMap,bt=new WeakMap,et=new WeakMap,ct=new WeakMap,dt=new WeakMap,wt=new WeakMap,ut=new WeakMap,Pt=new WeakMap,m=new WeakSet,Ot=function(e){const s=document.createElement("script");for(let a=0;a<e.attributes.length;a++){const o=e.attributes[a];s.setAttribute(o.name,o.value)}return e.hasAttribute("src")||(s.innerHTML=e.innerHTML),s},At=new WeakMap,pt=function(e){const s=this.normalizePath(e);let a=t(this,O).get(s.pathname);return a||(a=new oe(this,s.pathname),t(this,O).set(s.pathname,a)),a},Ft=function(e){const s=[...e.querySelectorAll("[data-morph]")];return s.length?s:[e]},ue=function(e,s){return e.filter(a=>s.find(o=>o.outerHTML===a.outerHTML))},Xt=function(e,s){return e.filter(a=>!s.find(o=>o.outerHTML===a.outerHTML))},Bt=function(e){return e.tagName==="SCRIPT"||e.tagName==="STYLE"||e.tagName==="LINK"&&e.getAttribute("rel")==="stylesheet"},Kt=function(e){var s,a;(s=t(this,M))==null||s.removeEventListener("scroll",t(this,mt)),n(this,dt,0),n(this,ct,0),n(this,M,t(this,N).scrollSelector&&e.querySelector(t(this,N).scrollSelector)||window),n(this,yt,t(this,M)===window),(a=t(this,M))==null||a.addEventListener("scroll",t(this,mt)),t(this,mt).call(this)},Mt=function(e,s){const a=typeof e=="string"?document.getElementById(e):e;(typeof a=="number"||a)&&ne.scrollToElement(a,{scrollElement:t(this,M),behavior:(s==null?void 0:s.behavior)||"instant",center:s==null?void 0:s.centerScroll,offset:s==null?void 0:s.offsetScroll})},Ut=new WeakMap,mt=new WeakMap,gt.instance=null;let Wt=gt;exports.Morph=Wt;