aptechka 0.67.3 → 0.68.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.
@@ -4,18 +4,17 @@ import { MorphRouteScrollState } from './MorphRoute';
4
4
  export interface MorphOptions {
5
5
  base: string;
6
6
  waitForHeadToLoad: boolean;
7
- cachePages: boolean;
8
7
  trailingSlash: boolean;
9
8
  scrollSelector: string | undefined;
10
9
  morphInsideScrollContainer: boolean;
11
10
  }
12
11
  export interface MorphNavigationEntry {
13
- pathname: string;
12
+ path: string;
14
13
  submorph?: Array<string>;
15
14
  }
16
15
  export interface MorphChildrenActionEntry {
17
16
  morphElement: HTMLElement;
18
- pathname: string;
17
+ path: string;
19
18
  }
20
19
  export interface MorphPreprocessorEntry extends MorphNavigationEntry {
21
20
  resolve: () => void;
@@ -55,7 +54,7 @@ export declare class Morph {
55
54
  preprocessor?: MorphPreprocessor;
56
55
  pathnameModifier?: MorphPathnameModifier;
57
56
  constructor(parameters?: Partial<MorphOptions>);
58
- get currentPathname(): string;
57
+ get currentPath(): string;
59
58
  get previousPathname(): string | undefined;
60
59
  get links(): MorphLink[];
61
60
  get scrollElement(): HTMLElement | Window;
@@ -71,6 +70,7 @@ export declare class Morph {
71
70
  pathname: string;
72
71
  parameters: string;
73
72
  hash: string;
73
+ path: string;
74
74
  };
75
75
  prefetch(path: string, revalidate?: boolean): Promise<void>;
76
76
  navigate(path: string, { historyAction, centerScroll, offsetScroll, revalidate, keepSearchParameters, submorph, clearState, }?: MorphNavigateOptions): Promise<void>;
@@ -3,6 +3,6 @@ export declare class MorphLink {
3
3
  #private;
4
4
  constructor(element: HTMLAnchorElement, morph: Morph);
5
5
  get element(): HTMLAnchorElement;
6
- checkCurrent(pathname: string): void;
6
+ checkCurrent(path: string): void;
7
7
  destroy(): void;
8
8
  }
@@ -10,14 +10,13 @@ export interface MorphRouteSaveState {
10
10
  export type MorpRouteSaveParametersArg = string | object | URLSearchParams;
11
11
  export declare class MorphRoute {
12
12
  #private;
13
- constructor(morph: Morph, pathname: string, searchParameters?: string);
14
- get pathname(): string;
15
- get searchParameters(): string | undefined;
13
+ constructor(morph: Morph, path: string);
14
+ get path(): string;
16
15
  get scrollState(): MorphRouteScrollState;
17
16
  get document(): Document;
18
17
  setInitialDocument(document: Document): void;
19
18
  abort(): void | undefined;
20
- fetch(revalidate?: boolean): Promise<void>;
19
+ fetch(revalidate?: boolean): Promise<void | null>;
21
20
  cloneDocument(): void;
22
21
  get title(): string;
23
22
  clearScrollState(): void;
@@ -1 +1 @@
1
- "use strict";var Ht=(a,t)=>(t=Symbol[a])?t:Symbol.for("Symbol."+a),Nt=a=>{throw TypeError(a)};var gt=(a,t,s)=>t.has(a)||Nt("Cannot "+s);var e=(a,t,s)=>(gt(a,t,"read from private field"),s?s.call(a):t.get(a)),o=(a,t,s)=>t.has(a)?Nt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(a):t.set(a,s),r=(a,t,s,i)=>(gt(a,t,"write to private field"),i?i.call(a,s):t.set(a,s),s),p=(a,t,s)=>(gt(a,t,"access private method"),s);var O=(a,t,s)=>new Promise((i,c)=>{var w=g=>{try{v(s.next(g))}catch(z){c(z)}},M=g=>{try{v(s.throw(g))}catch(z){c(z)}},v=g=>g.done?i(g.value):Promise.resolve(g.value).then(w,M);v((s=s.apply(a,t)).next())});var qt=(a,t,s)=>(t=a[Ht("asyncIterator")])?t.call(a):(a=a[Ht("iterator")](),t={},s=(i,c)=>(c=a[i])&&(t[i]=w=>new Promise((M,v,g)=>(w=c.call(a,w),g=w.done,Promise.resolve(w.value).then(z=>M({value:z,done:g}),v)))),s("next"),s("return"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Rt=require("../index-DekP7OZe.cjs"),F=require("../events-KVanG9sR.cjs"),Yt=require("../polyfills-Df4r-ETT.cjs"),Dt=require("../scroll-CIdNtj3G.cjs");require("construct-style-sheets-polyfill");const ht=require("../url-lnBE_6yf.cjs"),Xt=require("../css-value-parser/index.cjs");class Vt extends HTMLElement{connectedCallback(){const t={"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(t))this.setAttribute(s,i)}}Rt.isBrowser&&!customElements.get("morph-announcer")&&customElements.define("morph-announcer",Vt);var k,l,N,it,K;class St{constructor(t,s){o(this,k);o(this,l);o(this,N);o(this,it,t=>{var i;if(t.preventDefault(),e(this,l).hasAttribute("data-back")&&e(this,k).previousPathname)history.back();else{r(this,N,e(this,l).getAttribute("href")||"/");const c=e(this,l).getAttribute("data-history-action")||"push",w=e(this,l).hasAttribute("data-center-scroll"),M=getComputedStyle(e(this,l)).getPropertyValue("--offset-scroll").trim(),v=M?Xt.cssValueParser.parse(M):void 0,g=e(this,l).hasAttribute("data-revalidate"),z=e(this,l).hasAttribute("data-keep-search-parameters"),mt=(i=e(this,l).getAttribute("data-submorph"))==null?void 0:i.split(",").map($=>$.trim()),m=e(this,l).hasAttribute("data-clear-state");e(this,k).navigate(e(this,N),{historyAction:c,centerScroll:w,offsetScroll:v,revalidate:g,keepSearchParameters:z,submorph:mt,clearState:m})}});o(this,K,()=>{const t=e(this,l).hasAttribute("data-revalidate");e(this,k).prefetch(e(this,N),t),e(this,l).removeEventListener("pointerenter",e(this,K))});r(this,k,s),r(this,l,t),r(this,N,e(this,l).getAttribute("href")||"/"),e(this,l).addEventListener("click",e(this,it)),this.checkCurrent(location.pathname),e(this,l).hasAttribute("data-prefetch")&&e(this,l).addEventListener("pointerenter",e(this,K))}get element(){return e(this,l)}checkCurrent(t){const s=e(this,k).normalizePath(t),i=e(this,k).normalizePath(e(this,N));e(this,l).hasAttribute("data-include")&&s.pathname.includes(i.pathname)?e(this,l).classList.add("current"):i.pathname===s.pathname?e(this,l).classList.add("current"):e(this,l).classList.remove("current")}destroy(){e(this,l).removeEventListener("click",e(this,it)),e(this,l).removeEventListener("pointerenter",e(this,K)),e(this,l).classList.remove("current")}}k=new WeakMap,l=new WeakMap,N=new WeakMap,it=new WeakMap,K=new WeakMap;const $t=new DOMParser;var q,G,rt,b,C,W,D,J,Y,I;class It{constructor(t,s,i){o(this,q);o(this,G);o(this,rt);o(this,b,{x:0,y:0});o(this,C,null);o(this,W,null);o(this,D,null);o(this,J,null);o(this,Y,null);o(this,I,null);r(this,q,t),r(this,G,s),r(this,rt,i)}get pathname(){return e(this,G)}get searchParameters(){return e(this,rt)}get scrollState(){return e(this,b)}get document(){return e(this,D)}setInitialDocument(t){r(this,C,t.cloneNode(!0))}abort(){var t;return(t=e(this,Y))==null?void 0:t.abort(`[${this.pathname}] page loading cancelled`)}fetch(t){return O(this,null,function*(){if(!(e(this,C)&&!t&&!e(this,C).documentElement.hasAttribute("data-always-revalidate")))return e(this,I)?e(this,I):(r(this,I,new Promise(s=>O(this,null,function*(){try{r(this,Y,new AbortController);const c=yield(yield fetch(`${this.pathname}${this.searchParameters?"?"+this.searchParameters:""}`,{signal:e(this,Y).signal})).text(),w=$t.parseFromString(c,"text/html");this.setInitialDocument(w)}catch(i){console.warn(i)}finally{r(this,Y,null),r(this,I,null),s()}}))),e(this,I))})}cloneDocument(){r(this,D,(e(this,W)||e(this,C)).cloneNode(!0))}get title(){let t="";if(e(this,D).title)t=e(this,D).title;else{const s=e(this,D).querySelector("h1");t=(s==null?void 0:s.innerText)||(s==null?void 0:s.textContent)||e(this,G)}return t}clearScrollState(){e(this,b).x=0,e(this,b).y=0}clearDocumentState(){r(this,W,null)}saveScrollState(){e(this,C).documentElement.hasAttribute("data-no-scroll-restoration")?(e(this,b).x=0,e(this,b).y=0):(e(this,b).x=e(this,q).scrollValue.left,e(this,b).y=e(this,q).scrollValue.top)}restoreScrollPosition(){e(this,q).scrollElement.scroll({top:e(this,b).y,left:e(this,b).x,behavior:"instant"})}saveDocumentState(){e(this,C).documentElement.hasAttribute("data-no-page-restoration")?r(this,W,null):r(this,W,document.cloneNode(!0))}renewScrollPosition(){e(this,q).scrollElement.scroll({top:0,left:0,behavior:"instant"})}saveState(t){r(this,J,t)}clearState(){const t=e(this,J);return r(this,J,null),t}}q=new WeakMap,G=new WeakMap,rt=new WeakMap,b=new WeakMap,C=new WeakMap,W=new WeakMap,D=new WeakMap,J=new WeakMap,Y=new WeakMap,I=new WeakMap;var P,Q,E,R,d,nt,V,T,L,ot,x,X,Z,_,at,h,ut,wt,zt,yt,bt,Lt,Pt,dt,tt;const st=class st{constructor(t){o(this,h);o(this,P,null);o(this,Q,null);o(this,E,[]);o(this,R);o(this,d,null);o(this,nt);o(this,V,[]);o(this,T,!1);o(this,L,null);o(this,ot,!1);o(this,x,new Map);o(this,X,null);o(this,Z,0);o(this,_,0);o(this,at,t=>{var s;return((s=t.getAttribute("href"))==null?void 0:s.startsWith("/"))&&!t.hasAttribute("download")&&!t.hasAttribute("data-morph-skip")&&!t.closest("[data-morph-skip]")&&t.getAttribute("target")!=="_blank"});o(this,dt,t=>O(this,null,function*(){var s;(s=t.state)!=null&&s.path&&(t.preventDefault(),r(this,T,!0),yield this.navigate(t.state.path,{historyAction:"none"}),r(this,T,!1))}));o(this,tt,()=>{const{left:t,top:s}=this.scrollValue,i=s-e(this,_),c=t-e(this,Z);r(this,_,s),r(this,Z,t),document.documentElement.classList.toggle("scroll-y",s>0),document.documentElement.classList.toggle("scroll-x",t>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",c>0),document.documentElement.classList.toggle("scroll-x-backward",c<0),F.dispatchEvent(document,"morphScroll",{detail:{left:t,top:s}})});if(Rt.isBrowser&&!st.instance){st.instance=this,r(this,P,{base:ht.normalizeBase(t==null?void 0:t.base),waitForHeadToLoad:(t==null?void 0:t.waitForHeadToLoad)!==!1,cachePages:(t==null?void 0:t.cachePages)!==!1,trailingSlash:(t==null?void 0:t.trailingSlash)||!1,scrollSelector:t==null?void 0:t.scrollSelector,morphInsideScrollContainer:(t==null?void 0:t.morphInsideScrollContainer)||!1}),r(this,Q,p(this,h,wt).call(this,document.body));const s=this.normalizePath(location.pathname+location.hash);r(this,d,s.pathname);const i=new It(this,e(this,d));i.setInitialDocument(document),e(this,x).set(e(this,d),i),document.documentElement.setAttribute("data-current-pathname",e(this,d)),document.documentElement.setAttribute("data-current-leaf",s.leaf),this.findLinks(),history.scrollRestoration="manual",addEventListener("popstate",e(this,dt)),ht.changeHistory({action:"replace",pathname:e(this,d),searchParameters:s.parameters||location.search,hash:s.hash}),r(this,X,new Vt),p(this,h,Lt).call(this,document)}}get currentPathname(){return e(this,d)}get previousPathname(){return e(this,nt)}get links(){return e(this,E)}get scrollElement(){return e(this,L)}get isPopstateNavigation(){return e(this,T)}get scrollValue(){let t=0,s=0;return e(this,ot)?(t=window.scrollY,s=window.scrollX):(t=e(this,L).scrollTop,s=e(this,L).scrollLeft),{top:t,left:s}}saveState(t){const s=e(this,x).get(e(this,d));s&&s.saveState(t)}getState(){const t=e(this,x).get(e(this,d));return t==null?void 0:t.clearState()}normalizePath(t){return ht.splitPath(t,{base:e(this,P).base,trailingSlash:e(this,P).trailingSlash})}prefetch(t,s){return O(this,null,function*(){if(e(this,V).length)return;const i=this.normalizePath(t),c=p(this,h,ut).call(this,i.pathname,i.parameters);c==null||c.fetch(s)})}navigate(z){return O(this,arguments,function*(t,{historyAction:s="push",centerScroll:i,offsetScroll:c,revalidate:w,keepSearchParameters:M,submorph:v,clearState:g}={}){var kt;if(e(this,V).length)return;const mt=this.normalizePath(((kt=this.pathnameModifier)==null?void 0:kt.call(this,t))||t);let{pathname:m,hash:$,parameters:At,leaf:Bt}=mt;if(e(this,R)===m||e(this,d)===m){e(this,T)||p(this,h,Pt).call(this,$||0,{centerScroll:i,offsetScroll:c,behavior:"smooth"});return}r(this,R,m),e(this,E).forEach(j=>{j.checkCurrent(m)});try{let j=!0;if(this.preprocessor)try{yield new Promise((n,A)=>{var y;(y=this.preprocessor)==null||y.call(this,{pathname:m,resolve:n,reject:A,submorph:v})})}catch(n){n?console.error(n):console.log("Route change canceled"),j=!1}if(!j||e(this,R)!==m){e(this,E).forEach(n=>{n.checkCurrent(e(this,d))});return}const ft={pathname:m,submorph:v};F.dispatchEvent(document,"morphNavigation",{detail:ft});const pt=p(this,h,ut).call(this,e(this,d)),f=p(this,h,ut).call(this,m,At);if(e(this,x).forEach(n=>{n.pathname!==m&&n.abort()}),yield f==null?void 0:f.fetch(w),e(this,R)!==m){e(this,E).forEach(n=>{n.checkCurrent(e(this,d))});return}pt.clearState(),pt.saveScrollState(),pt.saveDocumentState(),e(this,T)||(f.clearScrollState(),f.clearDocumentState()),g&&f.clearState(),f.cloneDocument(),e(this,X).textContent=f.title,document.body.appendChild(e(this,X)),F.dispatchEvent(document,"morphStart",{detail:ft});const Ct=Array.from(document.head.children),Tt=Array.from(f.document.head.children),xt=p(this,h,zt).call(this,Ct,Tt),Ot=p(this,h,yt).call(this,Ct,xt),lt=p(this,h,yt).call(this,Tt,xt);lt.forEach((n,A)=>{if(n.tagName==="SCRIPT"&&n.getAttribute("src")){const y=document.createElement("script");y.type="module",y.src=n.getAttribute("src"),lt[A]=y}}),lt.forEach(n=>{document.head.appendChild(n)});const Et=lt.filter(n=>{if(n.hasAttribute("data-no-waiting"))return!1;if(p(this,h,bt).call(this,n))return!0});e(this,P).waitForHeadToLoad&&Et.length&&(yield new Promise(n=>O(this,null,function*(){let A=0;try{for(var y=qt(Et),et,B,U;et=!(B=yield y.next()).done;et=!1){const ct=B.value;ct.onload=()=>{A++,A===Et.length&&n()}}}catch(B){U=[B]}finally{try{et&&(B=y.return)&&(yield B.call(y))}finally{if(U)throw U[0]}}}))),yield Dt.wait(10);const Mt=[];Ot.forEach(n=>{n.hasAttribute("data-permanent")||(p(this,h,bt).call(this,n)?Mt.push(n):n.remove())});const Ft=p(this,h,wt).call(this,f.document.body);e(this,P).morphInsideScrollContainer||p(this,h,Lt).call(this,f.document),document.documentElement.setAttribute("data-current-pathname",m),document.documentElement.setAttribute("data-current-leaf",Bt),ht.changeHistory({action:s,pathname:m,searchParameters:At||(M?location.search:""),hash:$}),e(this,X).remove(),r(this,nt,e(this,d)),r(this,d,m),e(this,Q).forEach((n,A)=>{const y=Ft[A],et=getComputedStyle(n).getPropertyValue("--morph-duration");let B=[],U=[];v?v.forEach(u=>{const S=n.querySelector(u),H=y.querySelector(u);S&&H&&(U.push(S),B.push(H))}):(B.push(...y.childNodes),U.push(...n.childNodes)),U.forEach(u=>{u instanceof HTMLElement&&(this.destroyOldLinks(u),u.classList.add("old"))}),B.forEach(u=>{u instanceof HTMLElement&&(this.findNewLinks(u),u.classList.add("new"))}),v?B.forEach((u,S)=>{var H;(H=U[S].parentElement)==null||H.insertBefore(u,U[S])}):n.prepend(...B),Yt.requestIdleCallback(()=>{B.forEach(u=>{var S;u instanceof HTMLElement&&((S=u.parentElement)==null||S.style.setProperty("--new-content-height",u.offsetHeight+"px"),u.classList.add("in"))})});const ct={morphElement:n,pathname:m};F.dispatchEvent(document,"morphNewChildrenAdded",{detail:ct});const Wt=new Promise(u=>{setTimeout(()=>{U.forEach(S=>S.remove()),B.forEach(S=>{var H;S instanceof HTMLElement&&((H=S.parentElement)==null||H.style.removeProperty("--new-content-height"),S.classList.remove("in","new"))}),F.dispatchEvent(document,"morphOldChildrenRemoved",{detail:ct}),u()},(parseFloat(et)||0)*1e3+10)});e(this,V).push(Wt)}),this.isPopstateNavigation?document.documentElement.style.setProperty("--new-document-scroll-position",(this.scrollValue.top-f.scrollState.y)*1+"px"):document.documentElement.style.setProperty("--new-document-scroll-position",this.scrollValue.top+"px"),F.dispatchEvent(document,"morphBeforeNavigationScroll",{detail:f.scrollState}),$?(f.clearScrollState(),p(this,h,Pt).call(this,$,{centerScroll:i,offsetScroll:c})):e(this,T)?f.restoreScrollPosition():f.renewScrollPosition(),yield Promise.all(e(this,V)),Mt.forEach(n=>n.remove()),r(this,V,[]),e(this,Q).forEach(n=>{n.querySelectorAll("script").forEach(y=>{const et=document.createElement("script");et.type="module",et.src=y.getAttribute("src"),y.replaceWith(et)})}),F.dispatchEvent(document,"morphComplete",{detail:ft}),document.documentElement.style.removeProperty("--new-document-scroll-position"),window.dispatchEvent(new Event("resize"))}catch(j){console.error(j)}r(this,R,void 0)})}addLink(t){e(this,E).push(new St(t,this))}addLinks(t){t.forEach(s=>{this.addLink(s)})}removeLink(t){r(this,E,e(this,E).filter(s=>s.element===t?(s.destroy(),!1):!0))}destroyOldLinks(t){r(this,E,e(this,E).filter(s=>t.contains(s.element)?(s.destroy(),!1):!0))}findNewLinks(t){const s=[...t.querySelectorAll("a")].filter(e(this,at));e(this,E).push(...s.map(i=>new St(i,this)))}findLinks(){const t=[...document.documentElement.querySelectorAll("a")].filter(e(this,at));e(this,E).forEach(s=>s.destroy()),r(this,E,t.map(s=>new St(s,this)))}};P=new WeakMap,Q=new WeakMap,E=new WeakMap,R=new WeakMap,d=new WeakMap,nt=new WeakMap,V=new WeakMap,T=new WeakMap,L=new WeakMap,ot=new WeakMap,x=new WeakMap,X=new WeakMap,Z=new WeakMap,_=new WeakMap,at=new WeakMap,h=new WeakSet,ut=function(t,s){let i=e(this,x).get(t);return i||(i=new It(this,t,s),e(this,x).set(t,i)),i},wt=function(t){const s=[...t.querySelectorAll("[data-morph]")];return s.length?s:[t]},zt=function(t,s){return t.filter(i=>s.find(c=>c.outerHTML===i.outerHTML))},yt=function(t,s){return t.filter(i=>!s.find(c=>c.outerHTML===i.outerHTML))},bt=function(t){return t.tagName==="SCRIPT"||t.tagName==="STYLE"||t.tagName==="LINK"&&t.getAttribute("rel")==="stylesheet"},Lt=function(t){var s,i;(s=e(this,L))==null||s.removeEventListener("scroll",e(this,tt)),r(this,_,0),r(this,Z,0),r(this,L,e(this,P).scrollSelector&&t.querySelector(e(this,P).scrollSelector)||window),r(this,ot,e(this,L)===window),(i=e(this,L))==null||i.addEventListener("scroll",e(this,tt)),e(this,tt).call(this)},Pt=function(t,s){const i=typeof t=="string"?document.getElementById(t):t;(typeof i=="number"||i)&&Dt.scrollToElement(i,{scrollElement:e(this,L),behavior:(s==null?void 0:s.behavior)||"instant",center:s==null?void 0:s.centerScroll,offset:s==null?void 0:s.offsetScroll})},dt=new WeakMap,tt=new WeakMap,st.instance=null;let vt=st;exports.Morph=vt;
1
+ "use strict";var Ct=(a,t)=>(t=Symbol[a])?t:Symbol.for("Symbol."+a),Tt=a=>{throw TypeError(a)};var pt=(a,t,s)=>t.has(a)||Tt("Cannot "+s);var e=(a,t,s)=>(pt(a,t,"read from private field"),s?s.call(a):t.get(a)),o=(a,t,s)=>t.has(a)?Tt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(a):t.set(a,s),r=(a,t,s,i)=>(pt(a,t,"write to private field"),i?i.call(a,s):t.set(a,s),s),p=(a,t,s)=>(pt(a,t,"access private method"),s);var W=(a,t,s)=>new Promise((i,u)=>{var w=g=>{try{v(s.next(g))}catch(O){u(O)}},M=g=>{try{v(s.throw(g))}catch(O){u(O)}},v=g=>g.done?i(g.value):Promise.resolve(g.value).then(w,M);v((s=s.apply(a,t)).next())});var xt=(a,t,s)=>(t=a[Ct("asyncIterator")])?t.call(a):(a=a[Ct("iterator")](),t={},s=(i,u)=>(u=a[i])&&(t[i]=w=>new Promise((M,v,g)=>(w=u.call(a,w),g=w.done,Promise.resolve(w.value).then(O=>M({value:O,done:g}),v)))),s("next"),s("return"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Nt=require("../index-DekP7OZe.cjs"),Y=require("../events-KVanG9sR.cjs"),zt=require("../polyfills-Df4r-ETT.cjs"),Mt=require("../scroll-CIdNtj3G.cjs");require("construct-style-sheets-polyfill");const ct=require("../url-BT4fssbO.cjs"),Bt=require("../css-value-parser/index.cjs");class qt extends HTMLElement{connectedCallback(){const t={"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(t))this.setAttribute(s,i)}}Nt.isBrowser&&!customElements.get("morph-announcer")&&customElements.define("morph-announcer",qt);var k,l,q,st,$;class Et{constructor(t,s){o(this,k);o(this,l);o(this,q);o(this,st,t=>{var i;if(t.preventDefault(),e(this,l).hasAttribute("data-back")&&e(this,k).previousPathname)history.back();else{r(this,q,e(this,l).getAttribute("href")||"/");const u=e(this,l).getAttribute("data-history-action")||"push",w=e(this,l).hasAttribute("data-center-scroll"),M=getComputedStyle(e(this,l)).getPropertyValue("--offset-scroll").trim(),v=M?Bt.cssValueParser.parse(M):void 0,g=e(this,l).hasAttribute("data-revalidate"),O=e(this,l).hasAttribute("data-keep-search-parameters"),h=(i=e(this,l).getAttribute("data-submorph"))==null?void 0:i.split(",").map(H=>H.trim()),ot=e(this,l).hasAttribute("data-clear-state");e(this,k).navigate(e(this,q),{historyAction:u,centerScroll:w,offsetScroll:v,revalidate:g,keepSearchParameters:O,submorph:h,clearState:ot})}});o(this,$,()=>{const t=e(this,l).hasAttribute("data-revalidate");e(this,k).prefetch(e(this,q),t),e(this,l).removeEventListener("pointerenter",e(this,$))});r(this,k,s),r(this,l,t),r(this,q,e(this,l).getAttribute("href")||"/"),e(this,l).addEventListener("click",e(this,st)),this.checkCurrent(location.pathname),e(this,l).hasAttribute("data-prefetch")&&e(this,l).addEventListener("pointerenter",e(this,$))}get element(){return e(this,l)}checkCurrent(t){const s=e(this,k).normalizePath(t),i=e(this,k).normalizePath(e(this,q));e(this,l).hasAttribute("data-include")&&s.pathname.includes(i.pathname)?e(this,l).classList.add("current"):i.pathname===s.pathname?e(this,l).classList.add("current"):e(this,l).classList.remove("current")}destroy(){e(this,l).removeEventListener("click",e(this,st)),e(this,l).removeEventListener("pointerenter",e(this,$)),e(this,l).classList.remove("current")}}k=new WeakMap,l=new WeakMap,q=new WeakMap,st=new WeakMap,$=new WeakMap;const Ot=new DOMParser;var D,I,b,C,X,R,G,j,V;class Ht{constructor(t,s){o(this,D);o(this,I);o(this,b,{x:0,y:0});o(this,C,null);o(this,X,null);o(this,R,null);o(this,G,null);o(this,j,null);o(this,V,null);r(this,D,t),r(this,I,s)}get path(){return e(this,I)}get scrollState(){return e(this,b)}get document(){return e(this,R)}setInitialDocument(t){r(this,C,t.cloneNode(!0))}abort(){var t;return(t=e(this,j))==null?void 0:t.abort(`[${e(this,I)}] page loading cancelled`)}fetch(t){return W(this,null,function*(){return e(this,V)||e(this,C)&&e(this,C).documentElement.hasAttribute("data-cache")&&!t?e(this,V):(r(this,V,new Promise(s=>W(this,null,function*(){try{r(this,j,new AbortController);const u=yield(yield fetch(e(this,I),{signal:e(this,j).signal})).text(),w=Ot.parseFromString(u,"text/html");this.setInitialDocument(w)}catch(i){console.warn(i)}finally{r(this,j,null),r(this,V,null),s()}}))),e(this,V))})}cloneDocument(){r(this,R,(e(this,X)||e(this,C)).cloneNode(!0))}get title(){let t="";if(e(this,R).title)t=e(this,R).title;else{const s=e(this,R).querySelector("h1");t=(s==null?void 0:s.innerText)||(s==null?void 0:s.textContent)||e(this,I)}return t}clearScrollState(){e(this,b).x=0,e(this,b).y=0}clearDocumentState(){r(this,X,null)}saveScrollState(){e(this,C).documentElement.hasAttribute("data-no-scroll-restoration")?(e(this,b).x=0,e(this,b).y=0):(e(this,b).x=e(this,D).scrollValue.left,e(this,b).y=e(this,D).scrollValue.top)}restoreScrollPosition(){e(this,D).scrollElement.scroll({top:e(this,b).y,left:e(this,b).x,behavior:"instant"})}saveDocumentState(){e(this,C).documentElement.hasAttribute("data-no-page-restoration")?r(this,X,null):r(this,X,document.cloneNode(!0))}renewScrollPosition(){e(this,D).scrollElement.scroll({top:0,left:0,behavior:"instant"})}saveState(t){r(this,G,t)}clearState(){const t=e(this,G);return r(this,G,null),t}}D=new WeakMap,I=new WeakMap,b=new WeakMap,C=new WeakMap,X=new WeakMap,R=new WeakMap,G=new WeakMap,j=new WeakMap,V=new WeakMap;var P,J,E,z,m,it,B,T,L,rt,x,U,Q,Z,nt,c,ht,St,Dt,vt,wt,yt,bt,ut,_;const et=class et{constructor(t){o(this,c);o(this,P,null);o(this,J,null);o(this,E,[]);o(this,z);o(this,m,null);o(this,it);o(this,B,[]);o(this,T,!1);o(this,L,null);o(this,rt,!1);o(this,x,new Map);o(this,U,null);o(this,Q,0);o(this,Z,0);o(this,nt,t=>{var s;return((s=t.getAttribute("href"))==null?void 0:s.startsWith("/"))&&!t.hasAttribute("download")&&!t.hasAttribute("data-morph-skip")&&!t.closest("[data-morph-skip]")&&t.getAttribute("target")!=="_blank"});o(this,ut,t=>W(this,null,function*(){var s;(s=t.state)!=null&&s.path&&(t.preventDefault(),r(this,T,!0),yield this.navigate(t.state.path,{historyAction:"none"}),r(this,T,!1))}));o(this,_,()=>{const{left:t,top:s}=this.scrollValue,i=s-e(this,Z),u=t-e(this,Q);r(this,Z,s),r(this,Q,t),document.documentElement.classList.toggle("scroll-y",s>0),document.documentElement.classList.toggle("scroll-x",t>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",u>0),document.documentElement.classList.toggle("scroll-x-backward",u<0),Y.dispatchEvent(document,"morphScroll",{detail:{left:t,top:s}})});if(Nt.isBrowser&&!et.instance){et.instance=this,r(this,P,{base:ct.normalizeBase(t==null?void 0:t.base),waitForHeadToLoad:(t==null?void 0:t.waitForHeadToLoad)!==!1,trailingSlash:(t==null?void 0:t.trailingSlash)||!1,scrollSelector:t==null?void 0:t.scrollSelector,morphInsideScrollContainer:(t==null?void 0:t.morphInsideScrollContainer)||!1}),r(this,J,p(this,c,St).call(this,document.body));const s=this.normalizePath(location.pathname+location.hash);r(this,m,s.pathname);const i=new Ht(this,e(this,m));i.setInitialDocument(document),e(this,x).set(e(this,m),i),document.documentElement.setAttribute("data-current-pathname",e(this,m)),document.documentElement.setAttribute("data-current-leaf",s.leaf),this.findLinks(),history.scrollRestoration="manual",addEventListener("popstate",e(this,ut)),ct.changeHistory({action:"replace",pathname:e(this,m),searchParameters:s.parameters||location.search,hash:s.hash}),r(this,U,new qt),p(this,c,yt).call(this,document)}}get currentPath(){return e(this,m)}get previousPathname(){return e(this,it)}get links(){return e(this,E)}get scrollElement(){return e(this,L)}get isPopstateNavigation(){return e(this,T)}get scrollValue(){let t=0,s=0;return e(this,rt)?(t=window.scrollY,s=window.scrollX):(t=e(this,L).scrollTop,s=e(this,L).scrollLeft),{top:t,left:s}}saveState(t){const s=e(this,x).get(e(this,m));s&&s.saveState(t)}getState(){const t=e(this,x).get(e(this,m));return t==null?void 0:t.clearState()}normalizePath(t){return ct.splitPath(t,{base:e(this,P).base,trailingSlash:e(this,P).trailingSlash})}prefetch(t,s){return W(this,null,function*(){if(e(this,B).length)return;const i=p(this,c,ht).call(this,t);i==null||i.fetch(s)})}navigate(O){return W(this,arguments,function*(t,{historyAction:s="push",centerScroll:i,offsetScroll:u,revalidate:w,keepSearchParameters:M,submorph:v,clearState:g}={}){var ot;if(e(this,B).length)return;const h=this.normalizePath(((ot=this.pathnameModifier)==null?void 0:ot.call(this,t))||t);if(e(this,z)===h.path||e(this,m)===h.path){e(this,T)||p(this,c,bt).call(this,h.hash||0,{centerScroll:i,offsetScroll:u,behavior:"smooth"});return}r(this,z,h.path),e(this,E).forEach(H=>{H.checkCurrent(h.path)});try{let H=!0;if(this.preprocessor)try{yield new Promise((n,A)=>{var y;(y=this.preprocessor)==null||y.call(this,{path:t,resolve:n,reject:A,submorph:v})})}catch(n){n?console.error(n):console.log("Route change canceled"),H=!1}if(!H||e(this,z)!==h.path){e(this,E).forEach(n=>{n.checkCurrent(e(this,m))});return}const dt={path:h.path,submorph:v};Y.dispatchEvent(document,"morphNavigation",{detail:dt});const mt=p(this,c,ht).call(this,e(this,m)),f=p(this,c,ht).call(this,t);if(e(this,x).forEach(n=>{n.path!==h.path&&n.abort()}),yield f==null?void 0:f.fetch(w),e(this,z)!==h.path){e(this,E).forEach(n=>{n.checkCurrent(e(this,m))});return}mt.clearState(),mt.saveScrollState(),mt.saveDocumentState(),e(this,T)||(f.clearScrollState(),f.clearDocumentState()),g&&f.clearState(),f.cloneDocument(),e(this,U).textContent=f.title,document.body.appendChild(e(this,U)),Y.dispatchEvent(document,"morphStart",{detail:dt});const Lt=Array.from(document.head.children),Pt=Array.from(f.document.head.children),At=p(this,c,Dt).call(this,Lt,Pt),It=p(this,c,vt).call(this,Lt,At),at=p(this,c,vt).call(this,Pt,At);at.forEach((n,A)=>{if(n.tagName==="SCRIPT"&&n.getAttribute("src")){const y=document.createElement("script");y.type="module",y.src=n.getAttribute("src"),at[A]=y}}),at.forEach(n=>{document.head.appendChild(n)});const ft=at.filter(n=>{if(n.hasAttribute("data-no-waiting"))return!1;if(p(this,c,wt).call(this,n))return!0});e(this,P).waitForHeadToLoad&&ft.length&&(yield new Promise(n=>W(this,null,function*(){let A=0;try{for(var y=xt(ft),tt,F,K;tt=!(F=yield y.next()).done;tt=!1){const lt=F.value;lt.onload=()=>{A++,A===ft.length&&n()}}}catch(F){K=[F]}finally{try{tt&&(F=y.return)&&(yield F.call(y))}finally{if(K)throw K[0]}}}))),yield Mt.wait(10);const kt=[];It.forEach(n=>{n.hasAttribute("data-permanent")||(p(this,c,wt).call(this,n)?kt.push(n):n.remove())});const Rt=p(this,c,St).call(this,f.document.body);e(this,P).morphInsideScrollContainer||p(this,c,yt).call(this,f.document),document.documentElement.setAttribute("data-current-pathname",h.pathname),document.documentElement.setAttribute("data-current-leaf",h.leaf),ct.changeHistory({action:s,pathname:h.pathname,searchParameters:h.parameters||(M?location.search:""),hash:h.hash}),e(this,U).remove(),r(this,it,e(this,m)),r(this,m,h.path),e(this,J).forEach((n,A)=>{const y=Rt[A],tt=getComputedStyle(n).getPropertyValue("--morph-duration");let F=[],K=[];v?v.forEach(d=>{const S=n.querySelector(d),N=y.querySelector(d);S&&N&&(K.push(S),F.push(N))}):(F.push(...y.childNodes),K.push(...n.childNodes)),K.forEach(d=>{d instanceof HTMLElement&&(this.destroyOldLinks(d),d.classList.add("old"))}),F.forEach(d=>{d instanceof HTMLElement&&(this.findNewLinks(d),d.classList.add("new"))}),v?F.forEach((d,S)=>{var N;(N=K[S].parentElement)==null||N.insertBefore(d,K[S])}):n.prepend(...F),zt.requestIdleCallback(()=>{F.forEach(d=>{var S;d instanceof HTMLElement&&((S=d.parentElement)==null||S.style.setProperty("--new-content-height",d.offsetHeight+"px"),d.classList.add("in"))})});const lt={morphElement:n,path:h.path};Y.dispatchEvent(document,"morphNewChildrenAdded",{detail:lt});const Vt=new Promise(d=>{setTimeout(()=>{K.forEach(S=>S.remove()),F.forEach(S=>{var N;S instanceof HTMLElement&&((N=S.parentElement)==null||N.style.removeProperty("--new-content-height"),S.classList.remove("in","new"))}),Y.dispatchEvent(document,"morphOldChildrenRemoved",{detail:lt}),d()},(parseFloat(tt)||0)*1e3+10)});e(this,B).push(Vt)}),this.isPopstateNavigation?document.documentElement.style.setProperty("--new-document-scroll-position",(this.scrollValue.top-f.scrollState.y)*1+"px"):document.documentElement.style.setProperty("--new-document-scroll-position",this.scrollValue.top+"px"),Y.dispatchEvent(document,"morphBeforeNavigationScroll",{detail:f.scrollState}),h.hash?(f.clearScrollState(),p(this,c,bt).call(this,h.hash,{centerScroll:i,offsetScroll:u})):e(this,T)?f.restoreScrollPosition():f.renewScrollPosition(),yield Promise.all(e(this,B)),kt.forEach(n=>n.remove()),r(this,B,[]),e(this,J).forEach(n=>{n.querySelectorAll("script").forEach(y=>{const tt=document.createElement("script");tt.type="module",tt.src=y.getAttribute("src"),y.replaceWith(tt)})}),Y.dispatchEvent(document,"morphComplete",{detail:dt}),document.documentElement.style.removeProperty("--new-document-scroll-position"),window.dispatchEvent(new Event("resize"))}catch(H){console.error(H)}r(this,z,void 0)})}addLink(t){e(this,E).push(new Et(t,this))}addLinks(t){t.forEach(s=>{this.addLink(s)})}removeLink(t){r(this,E,e(this,E).filter(s=>s.element===t?(s.destroy(),!1):!0))}destroyOldLinks(t){r(this,E,e(this,E).filter(s=>t.contains(s.element)?(s.destroy(),!1):!0))}findNewLinks(t){const s=[...t.querySelectorAll("a")].filter(e(this,nt));e(this,E).push(...s.map(i=>new Et(i,this)))}findLinks(){const t=[...document.documentElement.querySelectorAll("a")].filter(e(this,nt));e(this,E).forEach(s=>s.destroy()),r(this,E,t.map(s=>new Et(s,this)))}};P=new WeakMap,J=new WeakMap,E=new WeakMap,z=new WeakMap,m=new WeakMap,it=new WeakMap,B=new WeakMap,T=new WeakMap,L=new WeakMap,rt=new WeakMap,x=new WeakMap,U=new WeakMap,Q=new WeakMap,Z=new WeakMap,nt=new WeakMap,c=new WeakSet,ht=function(t){let s=e(this,x).get(t);return s||(s=new Ht(this,t),e(this,x).set(t,s)),s},St=function(t){const s=[...t.querySelectorAll("[data-morph]")];return s.length?s:[t]},Dt=function(t,s){return t.filter(i=>s.find(u=>u.outerHTML===i.outerHTML))},vt=function(t,s){return t.filter(i=>!s.find(u=>u.outerHTML===i.outerHTML))},wt=function(t){return t.tagName==="SCRIPT"||t.tagName==="STYLE"||t.tagName==="LINK"&&t.getAttribute("rel")==="stylesheet"},yt=function(t){var s,i;(s=e(this,L))==null||s.removeEventListener("scroll",e(this,_)),r(this,Z,0),r(this,Q,0),r(this,L,e(this,P).scrollSelector&&t.querySelector(e(this,P).scrollSelector)||window),r(this,rt,e(this,L)===window),(i=e(this,L))==null||i.addEventListener("scroll",e(this,_)),e(this,_).call(this)},bt=function(t,s){const i=typeof t=="string"?document.getElementById(t):t;(typeof i=="number"||i)&&Mt.scrollToElement(i,{scrollElement:e(this,L),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,_=new WeakMap,et.instance=null;let gt=et;exports.Morph=gt;