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