aptechka 0.80.2 → 0.81.0

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.
@@ -24,6 +24,9 @@ export interface MorphURLParametersChangeEntry {
24
24
  previousURL: ReturnType<typeof splitPath>;
25
25
  detail: any;
26
26
  }
27
+ export interface MorphSamePathEntry {
28
+ detail: any;
29
+ }
27
30
  export interface MorphPreprocessorEntry extends MorphNavigationEntry {
28
31
  resolve: () => void;
29
32
  reject: () => void;
@@ -42,6 +45,7 @@ export interface MorphNavigateOptions {
42
45
  clearState?: boolean;
43
46
  keepScrollPosition?: boolean;
44
47
  mergeParams?: boolean;
48
+ removeParams?: string;
45
49
  detail?: any;
46
50
  }
47
51
  export interface MorphScrollDetail {
@@ -57,7 +61,7 @@ export interface MorphEvents {
57
61
  morphScroll: CustomEvent<MorphScrollDetail>;
58
62
  morphBeforeNavigationScroll: CustomEvent<MorphRouteScrollState>;
59
63
  morphURLParametersChange: CustomEvent<MorphURLParametersChangeEntry>;
60
- morphSamePath: CustomEvent;
64
+ morphSamePath: CustomEvent<MorphSamePathEntry>;
61
65
  }
62
66
  export interface MorphGetRouteOptions {
63
67
  searchParameters?: string;
@@ -81,12 +85,12 @@ export declare class Morph {
81
85
  get isNavigating(): boolean;
82
86
  saveState(state: any): void;
83
87
  getState(): any;
84
- normalizePath(path: string, options?: Pick<MorphNavigateOptions, 'mergeParams'>): import('../utils').SplitPathResult;
88
+ normalizePath(path: string, options?: Pick<MorphNavigateOptions, 'mergeParams' | 'removeParams'>): import('../utils').SplitPathResult;
85
89
  prefetch(path: string, revalidate?: boolean): Promise<void>;
86
90
  excludeHeadChild(child: Node): boolean;
87
91
  setHeaders(path: string): void;
88
92
  needRavalidation(path: string): void;
89
- navigate(path: string, { historyAction, centerScroll, offsetScroll, scrollBehaviour, revalidate, keepSearchParameters, submorph, submorphAppend, clearState, keepScrollPosition, mergeParams, detail, }?: MorphNavigateOptions): Promise<void>;
93
+ navigate(path: string, { historyAction, centerScroll, offsetScroll, scrollBehaviour, revalidate, keepSearchParameters, submorph, submorphAppend, clearState, keepScrollPosition, mergeParams, removeParams, detail, }?: MorphNavigateOptions): Promise<void>;
90
94
  addLink(element: HTMLAnchorElement): void;
91
95
  addLinks(elements: Array<HTMLAnchorElement>): void;
92
96
  removeLink(element: HTMLAnchorElement): void;
@@ -1 +1 @@
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;
1
+ "use strict";var Ee=Object.defineProperty,be=Object.defineProperties;var Le=Object.getOwnPropertyDescriptors;var ee=Object.getOwnPropertySymbols;var Se=Object.prototype.hasOwnProperty,ye=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))ye.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-CoUSEREU.cjs"),Pe=require("../css-value-parser/index.cjs"),le=require("../string-DUXXtU8v.cjs"),Ae=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 R,a,x,nt,Ut,de,Et,rt;class Wt{constructor(e,s){l(this,x);l(this,R);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,R).prefetch(t(this,x,nt),e),t(this,a).removeEventListener("pointerenter",t(this,rt))});o(this,R,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,Ut).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,R).normalizePath(e),i=t(this,R).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,Ut).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",Ae.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")}}R=new WeakMap,a=new WeakMap,x=new WeakSet,nt=function(){const e=new URL(t(this,a).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 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,R).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?Pe.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,Ct]=t(this,x,nt).split("?"),d=new URLSearchParams(Ct),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,Ut).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,R).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,R).links.forEach(w=>{w.updatePagination(L.currentPage-1,L.selector)}):t(this,a).hasAttribute("data-pagination-next-link")?t(this,R).links.forEach(w=>{w.updatePagination(L.currentPage+1,L.selector)}):t(this,a).hasAttribute("data-pagination-more-link")&&t(this,R).links.forEach(w=>{w.updatePagination(L.currentPage+1,L.selector)})),t(this,R).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,Vt,Lt;class ke{constructor(e){l(this,bt);l(this,T);l(this,ot,[]);l(this,Lt,()=>{g(this,bt,Vt).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,Vt).call(this)}destroy(){document.removeEventListener("morphURLParametersChange",t(this,Lt))}}T=new WeakMap,ot=new WeakMap,bt=new WeakSet,Vt=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 W,Q,U,V,Z,Y,ht,_,$,St,lt;class oe{constructor(e,s){l(this,W);l(this,Q);l(this,U,{x:0,y:0});l(this,V,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,W,e),o(this,Q,s)}get pathname(){return t(this,Q)}get scrollState(){return t(this,U)}get document(){return t(this,Y)}needRavalidation(){o(this,lt,!0)}setHeaders(e){o(this,St,e)}setInitialDocument(e){o(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,i){return J(this,null,function*(){var n;if(!i&&!t(this,lt)){const u=((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,$)||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-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,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,Q)}return e}clearScrollState(){t(this,U).x=0,t(this,U).y=0}clearDocumentState(){o(this,Z,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,Z,null):o(this,Z,document.cloneNode(!0))}renewScrollPosition(){t(this,W).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}}W=new WeakMap,Q=new WeakMap,U=new WeakMap,V=new WeakMap,Z=new WeakMap,Y=new WeakMap,ht=new WeakMap,_=new WeakMap,$=new WeakMap,St=new WeakMap,lt=new WeakMap;var D,ct,P,j,v,tt,O,G,N,yt,F,Pt,et,dt,ut,At,mt,kt,p,Ft,wt,gt,Bt,ue,Kt,Xt,Yt,$t,Mt,pt;const vt=class vt{constructor(e){l(this,p);l(this,D,null);l(this,ct,null);l(this,P,[]);l(this,j);l(this,v,null);l(this,tt);l(this,O,[]);l(this,G,!1);l(this,N,null);l(this,yt,!1);l(this,F,new Map);l(this,Pt,[]);l(this,et,null);l(this,dt,0);l(this,ut,0);l(this,At);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,Mt,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,At),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,Mt)),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,P)}get scrollElement(){return t(this,N)}get isPopstateNavigation(){return t(this,G)}get scrollValue(){let e=0,s=0;return t(this,yt)?(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,At,c),o(this,mt,f),o(this,kt,k);const Ct=((B=this.pathnameModifier)==null?void 0:B.call(this,e))||e,d=this.normalizePath(Ct,{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,P).forEach(K=>{K.checkCurrent(d.path)});return}else t(this,P).forEach(K=>{K.checkCurrent(d.path)});o(this,j,d);try{let K=!0;if(this.preprocessor)try{yield new Promise((r,A)=>{var M;(M=this.preprocessor)==null||M.call(this,{url:d,resolve:r,reject:A,submorph:c,detail:L})})}catch(r){r?console.error(r):console.log("Route change canceled"),K=!1}if(!K||t(this,j).pathname!==d.pathname){t(this,P).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(A=>{A.classList.add("out"),A.setAttribute("data-morph-out","")})}):t(this,ct).forEach(r=>{var A,M;(A=r.firstElementChild)==null||A.classList.add("out"),(M=r.firstElementChild)==null||M.setAttribute("data-morph-out","")}),I.dispatchEvent(document,"morphNavigation",{detail:Gt});const Nt=g(this,p,gt).call(this,t(this,v).pathname),y=g(this,p,gt).call(this,d.pathname);if(t(this,F).forEach(r=>{r.pathname!==d.pathname&&r.abort()}),yield y==null?void 0:y.fetch(Ct,t(this,v).path,f),t(this,j).pathname!==d.pathname){t(this,P).forEach(r=>{r.checkCurrent(t(this,v).path)});return}Nt.clearState(),Nt.saveScrollState(),Nt.saveDocumentState(),(!t(this,G)||f)&&(y.clearScrollState(),y.clearDocumentState()),st&&y.clearState(),y.cloneDocument(),t(this,et).textContent=y.title,document.body.appendChild(t(this,et));const Rt=zt(Tt({},Gt),{document:y.document});b||Rt.document.querySelectorAll("[data-morph-out]").forEach(r=>{r.classList.remove("out")}),I.dispatchEvent(document,"morphStart",{detail:Rt});const Jt=Array.from(document.head.children),Qt=Array.from(y.document.head.children),Zt=g(this,p,ue).call(this,Jt,Qt),me=g(this,p,Kt).call(this,Jt,Zt),xt=g(this,p,Kt).call(this,Qt,Zt).filter(r=>!this.excludeHeadChild(r));xt.forEach((r,A)=>{r.tagName==="SCRIPT"&&(xt[A]=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,D).waitForHeadToLoad&&qt.length&&(yield new Promise(r=>J(this,null,function*(){let A=0;try{for(var M=ne(qt),fe,X,q;fe=!(X=yield M.next()).done;fe=!1){const Ht=X.value;Ht.onload=()=>{A++,A===qt.length&&r()}}}catch(X){q=[X]}finally{try{fe&&(X=M.return)&&(yield X.call(M))}finally{if(q)throw q[0]}}}))),yield re.wait(10);const _t=[];b||me.forEach(r=>{r.hasAttribute("data-permanent")||(g(this,p,Xt).call(this,r)?_t.push(r):r.remove())});const pe=g(this,p,Bt).call(this,y.document.body);!t(this,D).morphInsideScrollContainer&&!c&&g(this,p,Yt).call(this,y.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,A)=>{const M=pe[A],fe=getComputedStyle(r).getPropertyValue("--morph-duration");let X=[],q=[];c?(c.forEach(m=>{const S=r.querySelector(m),C=M.querySelector(m);S&&C&&(q.push(S),X.push(C))}),q.forEach(m=>{m.parentElement&&Dt.push(m.parentElement)})):(X.push(...M.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(C=>{const ve=C.getAttribute("data-morph-transfer");Ht.push({element:C,selector:ve})}))}),X.forEach(m=>{m instanceof HTMLElement&&(Ht.forEach(S=>{const C=m.querySelector(S.selector);C&&C.replaceWith(y.document.importNode(S.element,!0))}),this.findNewLinks(m),m.classList.add("new"))}),c?b?X.forEach((m,S)=>{q[S]instanceof HTMLElement&&q[S].append(...m.childNodes)}):X.forEach((m,S)=>{var C;(C=q[S].parentElement)==null||C.insertBefore(m,q[S])}):r.prepend(...X),setTimeout(()=>{b||q.forEach(m=>{m instanceof HTMLElement&&m.classList.add("old-idle")}),X.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({},Rt),{morphElement:r});I.dispatchEvent(document,"morphNewChildrenAdded",{detail:te});const ge=new Promise(m=>{setTimeout(()=>{b||q.forEach(S=>{S.remove()}),X.forEach(S=>{var C;S instanceof HTMLElement&&((C=S.parentElement)==null||C.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-y.scrollState.y)*1+"px"):document.documentElement.style.setProperty("--new-document-scroll-position",this.scrollValue.top+"px"),I.dispatchEvent(document,"morphBeforeNavigationScroll",{detail:y.scrollState}),d.hash?(y.clearScrollState(),g(this,p,$t).call(this,d.hash,{centerScroll:i,offsetScroll:n,behavior:E})):t(this,G)?y.restoreScrollPosition():k||y.renewScrollPosition(),yield Promise.all(t(this,O)),b||_t.forEach(r=>r.remove()),o(this,O,[]),Dt.forEach(r=>{r.querySelectorAll("script").forEach(M=>{M.replaceWith(g(this,p,Ft).call(this,M))})}),t(this,P).forEach(r=>{r.checkCurrent(t(this,v).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,P).push(new Wt(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,wt));t(this,P).push(...s.map(i=>new Wt(i,this)))}findLinks(){const e=[...document.documentElement.querySelectorAll("a")].filter(t(this,wt));t(this,P).forEach(s=>s.destroy()),o(this,P,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 ke(s)))}};D=new WeakMap,ct=new WeakMap,P=new WeakMap,j=new WeakMap,v=new WeakMap,tt=new WeakMap,O=new WeakMap,G=new WeakMap,N=new WeakMap,yt=new WeakMap,F=new WeakMap,Pt=new WeakMap,et=new WeakMap,dt=new WeakMap,ut=new WeakMap,At=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))},Kt=function(e,s){return e.filter(i=>!s.find(n=>n.outerHTML===i.outerHTML))},Xt=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,yt,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})},Mt=new WeakMap,pt=new WeakMap,vt.instance=null;let Ot=vt;exports.Morph=Ot;