aptechka 0.58.1 → 0.59.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/morph/Morph.d.ts +2 -0
- package/lib/morph/index.cjs +1 -1
- package/lib/morph/index.js +236 -226
- package/lib/popover/index.cjs +1 -1
- package/lib/popover/index.js +203 -195
- package/package.json +1 -1
package/lib/morph/Morph.d.ts
CHANGED
|
@@ -64,6 +64,8 @@ export declare class Morph {
|
|
|
64
64
|
addLink(element: HTMLAnchorElement): void;
|
|
65
65
|
addLinks(elements: Array<HTMLAnchorElement>): void;
|
|
66
66
|
removeLink(element: HTMLAnchorElement): void;
|
|
67
|
+
destroyOldLinks(morphElement: HTMLElement): void;
|
|
68
|
+
findNewLinks(morphElement: HTMLElement): void;
|
|
67
69
|
findLinks(): void;
|
|
68
70
|
}
|
|
69
71
|
declare global {
|
package/lib/morph/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var yt=(r,e)=>(e=Symbol[r])?e:Symbol.for("Symbol."+r),Lt=r=>{throw TypeError(r)};var it=(r,e,s)=>e.has(r)||Lt("Cannot "+s);var t=(r,e,s)=>(it(r,e,"read from private field"),s?s.call(r):e.get(r)),o=(r,e,s)=>e.has(r)?Lt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,s),a=(r,e,s,i)=>(it(r,e,"write to private field"),i?i.call(r,s):e.set(r,s),s),d=(r,e,s)=>(it(r,e,"access private method"),s);var x=(r,e,s)=>new Promise((i,u)=>{var f=p=>{try{H(s.next(p))}catch(h){u(h)}},M=p=>{try{H(s.throw(p))}catch(h){u(h)}},H=p=>p.done?i(p.value):Promise.resolve(p.value).then(f,M);H((s=s.apply(r,e)).next())});var bt=(r,e,s)=>(e=r[yt("asyncIterator")])?e.call(r):(r=r[yt("iterator")](),e={},s=(i,u)=>(u=r[i])&&(e[i]=f=>new Promise((M,H,p)=>(f=u.call(r,f),p=f.done,Promise.resolve(f.value).then(h=>M({value:h,done:p}),H)))),s("next"),s("return"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const kt=require("../index-Cqw2NKev.cjs"),K=require("../events-KVanG9sR.cjs"),qt=require("../polyfills-Df4r-ETT.cjs"),wt=require("../scroll-DAhSpkhR.cjs"),$=require("../url-D1CgmwZ_.cjs"),Rt=require("../css-value-parser/index.cjs");class Ct 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)}}kt.isBrowser&&!customElements.get("morph-announcer")&&customElements.define("morph-announcer",Ct);var w,c,N,G,V;class Pt{constructor(e,s){o(this,w);o(this,c);o(this,N);o(this,G,e=>{if(e.preventDefault(),t(this,c).hasAttribute("data-back")&&t(this,w).previousPathname)history.back();else{const i=t(this,c).getAttribute("data-history-action")||"push",u=t(this,c).hasAttribute("data-center-scroll"),f=getComputedStyle(t(this,c)).getPropertyValue("--offset-scroll").trim(),M=f?Rt.cssValueParser.parse(f):void 0,H=t(this,c).hasAttribute("data-revalidate"),p=t(this,c).hasAttribute("data-keep-search-parameters");t(this,w).navigate(t(this,N),{historyAction:i,centerScroll:u,offsetScroll:M,revalidate:H,keepSearchParameters:p})}});o(this,V,()=>{t(this,w).prefetch(t(this,N)),t(this,c).removeEventListener("pointerenter",t(this,V))});a(this,w,s),a(this,c,e),a(this,N,t(this,c).getAttribute("href")||"/"),t(this,c).addEventListener("click",t(this,G)),this.checkCurrent(location.pathname),t(this,c).hasAttribute("data-prefetch")&&t(this,c).addEventListener("pointerenter",t(this,V))}get element(){return t(this,c)}checkCurrent(e){const s=t(this,w).normalizePath(e),i=t(this,w).normalizePath(t(this,N));t(this,c).hasAttribute("data-include")&&s.pathname.includes(i.pathname)?t(this,c).classList.add("current"):i.pathname===s.pathname?t(this,c).classList.add("current"):t(this,c).classList.remove("current")}destroy(){t(this,c).removeEventListener("click",t(this,G)),t(this,c).removeEventListener("pointerenter",t(this,V)),t(this,c).classList.remove("current")}}w=new WeakMap,c=new WeakMap,N=new WeakMap,G=new WeakMap,V=new WeakMap;var k,B,E,D,q,C;class At{constructor(e,s,i){o(this,k);o(this,B);o(this,E,{x:0,y:0});o(this,D);o(this,q,null);o(this,C,null);a(this,k,e),a(this,B,s),a(this,D,i.cloneNode(!0))}get pathname(){return t(this,B)}get scrollState(){return t(this,E)}get document(){return t(this,C)}cloneDocument(){a(this,C,(t(this,q)||t(this,D)).cloneNode(!0))}get title(){let e="";if(t(this,C).title)e=t(this,C).title;else{const s=t(this,C).querySelector("h1");e=(s==null?void 0:s.innerText)||(s==null?void 0:s.textContent)||t(this,B)}return e}clearScrollState(){t(this,E).x=0,t(this,E).y=0}clearDocumentState(){a(this,q,null)}saveScrollState(){t(this,D).documentElement.hasAttribute("data-no-scroll-restoration")?(t(this,E).x=0,t(this,E).y=0):(t(this,E).x=t(this,k).scrollElement.scrollLeft,t(this,E).y=t(this,k).scrollElement.scrollTop)}saveDocumentState(){t(this,D).documentElement.hasAttribute("data-no-page-restoration")?a(this,q,null):a(this,q,document.cloneNode(!0))}restoreScrollPosition(){t(this,k).scrollElement.scroll({top:t(this,E).y,left:t(this,E).x})}renewScrollPosition(){t(this,k).scrollElement.scroll({top:0,left:0,behavior:"instant"})}}k=new WeakMap,B=new WeakMap,E=new WeakMap,D=new WeakMap,q=new WeakMap,C=new WeakMap;var P,O,g,tt,T,m,J,R,A,L,W,z,l,rt,ot,at,Tt,lt,ct,ht,ut,et,j;const Y=class Y{constructor(e){o(this,l);o(this,P,null);o(this,O,null);o(this,g,[]);o(this,tt,new DOMParser);o(this,T);o(this,m,null);o(this,J);o(this,R,[]);o(this,A,!1);o(this,L,null);o(this,W,new Map);o(this,z,null);o(this,et,e=>x(this,null,function*(){var s;(s=e.state)!=null&&s.path&&(e.preventDefault(),a(this,A,!0),yield this.navigate(e.state.path,{historyAction:"none"}),a(this,A,!1))}));o(this,j,()=>{const e=t(this,L).scrollTop,s=t(this,L).scrollLeft;document.documentElement.classList.toggle("top-scrolled",e>0),document.documentElement.classList.toggle("left-scrolled",s>0),K.dispatchEvent(document,"morphScroll",{detail:{left:s,top:e}})});if(kt.isBrowser&&!Y.instance){Y.instance=this,a(this,P,{base:$.normalizeBase(e==null?void 0:e.base),waitForHeadToLoad:(e==null?void 0:e.waitForHeadToLoad)!==!1,cachePages:(e==null?void 0:e.cachePages)!==!1,trailingSlash:(e==null?void 0:e.trailingSlash)||!1,scrollSelector:(e==null?void 0:e.scrollSelector)||"body",morphInsideScrollContainer:(e==null?void 0:e.morphInsideScrollContainer)||!1}),a(this,O,d(this,l,at).call(this,document.body));const s=this.normalizePath(location.pathname+location.hash);a(this,m,s.pathname),t(this,W).set(t(this,m),new At(this,t(this,m),document)),document.documentElement.setAttribute("data-current-pathname",t(this,m)),document.documentElement.setAttribute("data-current-leaf",s.leaf),this.findLinks(),addEventListener("popstate",t(this,et)),$.changeHistory({action:"replace",pathname:t(this,m),searchParameters:s.parameters||location.search,hash:s.hash}),a(this,z,new Ct),d(this,l,ht).call(this,document)}}get currentPathname(){return t(this,m)}get previousPathname(){return t(this,J)}get links(){return t(this,g)}get scrollElement(){return t(this,L)}get isPopstateNavigation(){return t(this,A)}normalizePath(e){return $.splitPath(e,{base:t(this,P).base,trailingSlash:t(this,P).trailingSlash})}prefetch(e){return x(this,null,function*(){const s=this.normalizePath(e);d(this,l,ot).call(this,s.pathname)})}navigate(H){return x(this,arguments,function*(e,{historyAction:s="push",centerScroll:i,offsetScroll:u,revalidate:f,keepSearchParameters:M}={}){var dt;if(t(this,R).length)return;const p=this.normalizePath(((dt=this.pathnameModifier)==null?void 0:dt.call(this,e))||e);let{pathname:h,hash:Q,parameters:Mt,leaf:Ht}=p;if(t(this,T)===h||t(this,m)===h){t(this,A)||d(this,l,ut).call(this,Q||0,{centerScroll:i,offsetScroll:u,behavior:"smooth"});return}a(this,T,h),t(this,g).forEach(I=>{I.checkCurrent(h)});try{let I=!0;if(this.preprocessor)try{yield new Promise((n,b)=>{var v;(v=this.preprocessor)==null||v.call(this,{pathname:h,resolve:n,reject:b})})}catch(n){n?console.error(n):console.log("Route change canceled"),I=!1}if(!I||t(this,T)!==h){t(this,g).forEach(n=>{n.checkCurrent(t(this,m))});return}const mt=yield d(this,l,rt).call(this,t(this,m)),S=yield d(this,l,rt).call(this,h,f);if(t(this,T)!==h){t(this,g).forEach(n=>{n.checkCurrent(t(this,m))});return}mt.saveScrollState(),mt.saveDocumentState(),t(this,A)||(S.clearScrollState(),S.clearDocumentState()),S.cloneDocument(),t(this,z).textContent=S.title,document.body.appendChild(t(this,z));const ft={pathname:h};K.dispatchEvent(document,"morphStart",{detail:ft});const pt=Array.from(document.head.children),Et=Array.from(S.document.head.children),gt=d(this,l,Tt).call(this,pt,Et),xt=d(this,l,lt).call(this,pt,gt),X=d(this,l,lt).call(this,Et,gt);X.forEach((n,b)=>{if(n.tagName==="SCRIPT"&&n.getAttribute("src")){const v=document.createElement("script");v.type="module",v.src=n.getAttribute("src"),X[b]=v}}),X.forEach(n=>{document.head.appendChild(n)});const st=X.filter(n=>{if(n.hasAttribute("data-no-waiting"))return!1;if(d(this,l,ct).call(this,n))return!0});t(this,P).waitForHeadToLoad&&st.length&&(yield new Promise(n=>x(this,null,function*(){let b=0;try{for(var v=bt(st),F,U,St;F=!(U=yield v.next()).done;F=!1){const Z=U.value;Z.onload=()=>{b++,b===st.length&&n()}}}catch(U){St=[U]}finally{try{F&&(U=v.return)&&(yield U.call(v))}finally{if(St)throw St[0]}}}))),yield wt.wait(10);const vt=[];xt.forEach(n=>{n.hasAttribute("data-permanent")||(d(this,l,ct).call(this,n)?vt.push(n):n.remove())});const Nt=d(this,l,at).call(this,S.document.body);t(this,P).morphInsideScrollContainer||d(this,l,ht).call(this,S.document),document.documentElement.setAttribute("data-current-pathname",h),document.documentElement.setAttribute("data-current-leaf",Ht),$.changeHistory({action:s,pathname:h,searchParameters:Mt||(M?location.search:""),hash:Q}),t(this,z).remove(),a(this,J,t(this,m)),a(this,m,h),t(this,O).forEach((n,b)=>{const v=Nt[b],F=getComputedStyle(n).getPropertyValue("--morph-duration"),U=[...v.childNodes];if(F){const St=[...n.childNodes];St.forEach(y=>{y instanceof HTMLElement&&y.classList.add("old")}),U.forEach(y=>{y instanceof HTMLElement&&y.classList.add("new")}),n.prepend(...U),qt.requestIdleCallback(()=>{U.forEach(y=>{y instanceof HTMLElement&&y.classList.add("in")})});const Z={morphElement:n,pathname:h};K.dispatchEvent(document,"morphNewChildrenAdded",{detail:Z});const Dt=new Promise(y=>{setTimeout(()=>{St.forEach(_=>_.remove()),U.forEach(_=>{_ instanceof HTMLElement&&_.classList.remove("in","new")}),K.dispatchEvent(document,"morphOldChildrenRemoved",{detail:Z}),y()},(parseFloat(F)||0)*1e3+10)});t(this,R).push(Dt)}else n.innerHTML="",n.append(...U)}),Q?(S.clearScrollState(),d(this,l,ut).call(this,Q,{centerScroll:i,offsetScroll:u})):t(this,A)?S.restoreScrollPosition():S.renewScrollPosition(),yield Promise.all(t(this,R)),vt.forEach(n=>n.remove()),a(this,R,[]),t(this,O).forEach(n=>{n.querySelectorAll("script").forEach(v=>{const F=document.createElement("script");F.type="module",F.src=v.getAttribute("src"),v.replaceWith(F)})}),this.findLinks(),K.dispatchEvent(document,"morphComplete",{detail:ft}),window.dispatchEvent(new Event("resize"))}catch(I){console.error(I)}a(this,T,void 0)})}addLink(e){t(this,g).push(new Pt(e,this))}addLinks(e){e.forEach(s=>{this.addLink(s)})}removeLink(e){a(this,g,t(this,g).filter(s=>s.element===e?(s.destroy(),!1):!0))}findLinks(){const e=[...document.documentElement.querySelectorAll("a")].filter(s=>{var i;return((i=s.getAttribute("href"))==null?void 0:i.startsWith("/"))&&!s.hasAttribute("download")&&!s.hasAttribute("data-morph-skip")&&!s.closest("[data-morph-skip]")&&s.getAttribute("target")!=="_blank"});t(this,g).forEach(s=>s.destroy()),a(this,g,e.map(s=>new Pt(s,this)))}};P=new WeakMap,O=new WeakMap,g=new WeakMap,tt=new WeakMap,T=new WeakMap,m=new WeakMap,J=new WeakMap,R=new WeakMap,A=new WeakMap,L=new WeakMap,W=new WeakMap,z=new WeakMap,l=new WeakSet,rt=function(e,s=!1){return x(this,null,function*(){let i=t(this,W).get(e);return(!i||s)&&(i=yield d(this,l,ot).call(this,e)),i})},ot=function(e){return x(this,null,function*(){const i=yield(yield fetch(e)).text(),u=t(this,tt).parseFromString(i,"text/html"),f=new At(this,e,u);return t(this,W).set(e,f),f})},at=function(e){const s=[...e.querySelectorAll("[data-morph]")];return s.length?s:[e]},Tt=function(e,s){return e.filter(i=>s.find(u=>u.outerHTML===i.outerHTML))},lt=function(e,s){return e.filter(i=>!s.find(u=>u.outerHTML===i.outerHTML))},ct=function(e){return e.tagName==="SCRIPT"||e.tagName==="STYLE"||e.tagName==="LINK"&&e.getAttribute("rel")==="stylesheet"},ht=function(e){var s,i;(s=t(this,L))==null||s.removeEventListener("scroll",t(this,j)),a(this,L,e.querySelector(t(this,P).scrollSelector)||e.documentElement),(i=t(this,L))==null||i.addEventListener("scroll",t(this,j)),t(this,j).call(this)},ut=function(e,s){const i=typeof e=="string"?document.getElementById(e):e;(typeof i=="number"||i)&&wt.scrollToElement(i,{scrollElement:t(this,L),behavior:(s==null?void 0:s.behavior)||"instant",center:s==null?void 0:s.centerScroll,offset:s==null?void 0:s.offsetScroll})},et=new WeakMap,j=new WeakMap,Y.instance=null;let nt=Y;exports.Morph=nt;
|
|
1
|
+
"use strict";var wt=(r,t)=>(t=Symbol[r])?t:Symbol.for("Symbol."+r),bt=r=>{throw TypeError(r)};var nt=(r,t,s)=>t.has(r)||bt("Cannot "+s);var e=(r,t,s)=>(nt(r,t,"read from private field"),s?s.call(r):t.get(r)),o=(r,t,s)=>t.has(r)?bt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,s),a=(r,t,s,i)=>(nt(r,t,"write to private field"),i?i.call(r,s):t.set(r,s),s),d=(r,t,s)=>(nt(r,t,"access private method"),s);var N=(r,t,s)=>new Promise((i,u)=>{var p=E=>{try{H(s.next(E))}catch(h){u(h)}},M=E=>{try{H(s.throw(E))}catch(h){u(h)}},H=E=>E.done?i(E.value):Promise.resolve(E.value).then(p,M);H((s=s.apply(r,t)).next())});var kt=(r,t,s)=>(t=r[wt("asyncIterator")])?t.call(r):(r=r[wt("iterator")](),t={},s=(i,u)=>(u=r[i])&&(t[i]=p=>new Promise((M,H,E)=>(p=u.call(r,p),E=p.done,Promise.resolve(p.value).then(h=>M({value:h,done:E}),H)))),s("next"),s("return"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ct=require("../index-Cqw2NKev.cjs"),K=require("../events-KVanG9sR.cjs"),Rt=require("../polyfills-Df4r-ETT.cjs"),Pt=require("../scroll-DAhSpkhR.cjs"),tt=require("../url-D1CgmwZ_.cjs"),zt=require("../css-value-parser/index.cjs");class Tt 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)}}Ct.isBrowser&&!customElements.get("morph-announcer")&&customElements.define("morph-announcer",Tt);var b,c,x,G,F;class rt{constructor(t,s){o(this,b);o(this,c);o(this,x);o(this,G,t=>{if(t.preventDefault(),e(this,c).hasAttribute("data-back")&&e(this,b).previousPathname)history.back();else{const i=e(this,c).getAttribute("data-history-action")||"push",u=e(this,c).hasAttribute("data-center-scroll"),p=getComputedStyle(e(this,c)).getPropertyValue("--offset-scroll").trim(),M=p?zt.cssValueParser.parse(p):void 0,H=e(this,c).hasAttribute("data-revalidate"),E=e(this,c).hasAttribute("data-keep-search-parameters");e(this,b).navigate(e(this,x),{historyAction:i,centerScroll:u,offsetScroll:M,revalidate:H,keepSearchParameters:E})}});o(this,F,()=>{e(this,b).prefetch(e(this,x)),e(this,c).removeEventListener("pointerenter",e(this,F))});a(this,b,s),a(this,c,t),a(this,x,e(this,c).getAttribute("href")||"/"),e(this,c).addEventListener("click",e(this,G)),this.checkCurrent(location.pathname),e(this,c).hasAttribute("data-prefetch")&&e(this,c).addEventListener("pointerenter",e(this,F))}get element(){return e(this,c)}checkCurrent(t){const s=e(this,b).normalizePath(t),i=e(this,b).normalizePath(e(this,x));e(this,c).hasAttribute("data-include")&&s.pathname.includes(i.pathname)?e(this,c).classList.add("current"):i.pathname===s.pathname?e(this,c).classList.add("current"):e(this,c).classList.remove("current")}destroy(){e(this,c).removeEventListener("click",e(this,G)),e(this,c).removeEventListener("pointerenter",e(this,F)),e(this,c).classList.remove("current")}}b=new WeakMap,c=new WeakMap,x=new WeakMap,G=new WeakMap,F=new WeakMap;var A,V,v,q,D,C;class At{constructor(t,s,i){o(this,A);o(this,V);o(this,v,{x:0,y:0});o(this,q);o(this,D,null);o(this,C,null);a(this,A,t),a(this,V,s),a(this,q,i.cloneNode(!0))}get pathname(){return e(this,V)}get scrollState(){return e(this,v)}get document(){return e(this,C)}cloneDocument(){a(this,C,(e(this,D)||e(this,q)).cloneNode(!0))}get title(){let t="";if(e(this,C).title)t=e(this,C).title;else{const s=e(this,C).querySelector("h1");t=(s==null?void 0:s.innerText)||(s==null?void 0:s.textContent)||e(this,V)}return t}clearScrollState(){e(this,v).x=0,e(this,v).y=0}clearDocumentState(){a(this,D,null)}saveScrollState(){e(this,q).documentElement.hasAttribute("data-no-scroll-restoration")?(e(this,v).x=0,e(this,v).y=0):(e(this,v).x=e(this,A).scrollElement.scrollLeft,e(this,v).y=e(this,A).scrollElement.scrollTop)}saveDocumentState(){e(this,q).documentElement.hasAttribute("data-no-page-restoration")?a(this,D,null):a(this,D,document.cloneNode(!0))}restoreScrollPosition(){e(this,A).scrollElement.scroll({top:e(this,v).y,left:e(this,v).x})}renewScrollPosition(){e(this,A).scrollElement.scroll({top:0,left:0,behavior:"instant"})}}A=new WeakMap,V=new WeakMap,v=new WeakMap,q=new WeakMap,D=new WeakMap,C=new WeakMap;var k,B,m,et,T,f,J,R,P,y,W,z,Q,l,at,lt,ct,Mt,ht,ut,dt,mt,st,j;const Y=class Y{constructor(t){o(this,l);o(this,k,null);o(this,B,null);o(this,m,[]);o(this,et,new DOMParser);o(this,T);o(this,f,null);o(this,J);o(this,R,[]);o(this,P,!1);o(this,y,null);o(this,W,new Map);o(this,z,null);o(this,Q,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,st,t=>N(this,null,function*(){var s;(s=t.state)!=null&&s.path&&(t.preventDefault(),a(this,P,!0),yield this.navigate(t.state.path,{historyAction:"none"}),a(this,P,!1))}));o(this,j,()=>{const t=e(this,y).scrollTop,s=e(this,y).scrollLeft;document.documentElement.classList.toggle("top-scrolled",t>0),document.documentElement.classList.toggle("left-scrolled",s>0),K.dispatchEvent(document,"morphScroll",{detail:{left:s,top:t}})});if(Ct.isBrowser&&!Y.instance){Y.instance=this,a(this,k,{base:tt.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)||"body",morphInsideScrollContainer:(t==null?void 0:t.morphInsideScrollContainer)||!1}),a(this,B,d(this,l,ct).call(this,document.body));const s=this.normalizePath(location.pathname+location.hash);a(this,f,s.pathname),e(this,W).set(e(this,f),new At(this,e(this,f),document)),document.documentElement.setAttribute("data-current-pathname",e(this,f)),document.documentElement.setAttribute("data-current-leaf",s.leaf),this.findLinks(),addEventListener("popstate",e(this,st)),tt.changeHistory({action:"replace",pathname:e(this,f),searchParameters:s.parameters||location.search,hash:s.hash}),a(this,z,new Tt),d(this,l,dt).call(this,document)}}get currentPathname(){return e(this,f)}get previousPathname(){return e(this,J)}get links(){return e(this,m)}get scrollElement(){return e(this,y)}get isPopstateNavigation(){return e(this,P)}normalizePath(t){return tt.splitPath(t,{base:e(this,k).base,trailingSlash:e(this,k).trailingSlash})}prefetch(t){return N(this,null,function*(){const s=this.normalizePath(t);d(this,l,lt).call(this,s.pathname)})}navigate(H){return N(this,arguments,function*(t,{historyAction:s="push",centerScroll:i,offsetScroll:u,revalidate:p,keepSearchParameters:M}={}){var ft;if(e(this,R).length)return;const E=this.normalizePath(((ft=this.pathnameModifier)==null?void 0:ft.call(this,t))||t);let{pathname:h,hash:X,parameters:Ht,leaf:Nt}=E;if(e(this,T)===h||e(this,f)===h){e(this,P)||d(this,l,mt).call(this,X||0,{centerScroll:i,offsetScroll:u,behavior:"smooth"});return}a(this,T,h),e(this,m).forEach(I=>{I.checkCurrent(h)});try{let I=!0;if(this.preprocessor)try{yield new Promise((n,w)=>{var S;(S=this.preprocessor)==null||S.call(this,{pathname:h,resolve:n,reject:w})})}catch(n){n?console.error(n):console.log("Route change canceled"),I=!1}if(!I||e(this,T)!==h){e(this,m).forEach(n=>{n.checkCurrent(e(this,f))});return}const pt=yield d(this,l,at).call(this,e(this,f)),L=yield d(this,l,at).call(this,h,p);if(e(this,T)!==h){e(this,m).forEach(n=>{n.checkCurrent(e(this,f))});return}pt.saveScrollState(),pt.saveDocumentState(),e(this,P)||(L.clearScrollState(),L.clearDocumentState()),L.cloneDocument(),e(this,z).textContent=L.title,document.body.appendChild(e(this,z));const Et={pathname:h};K.dispatchEvent(document,"morphStart",{detail:Et});const gt=Array.from(document.head.children),vt=Array.from(L.document.head.children),St=d(this,l,Mt).call(this,gt,vt),xt=d(this,l,ht).call(this,gt,St),Z=d(this,l,ht).call(this,vt,St);Z.forEach((n,w)=>{if(n.tagName==="SCRIPT"&&n.getAttribute("src")){const S=document.createElement("script");S.type="module",S.src=n.getAttribute("src"),Z[w]=S}}),Z.forEach(n=>{document.head.appendChild(n)});const it=Z.filter(n=>{if(n.hasAttribute("data-no-waiting"))return!1;if(d(this,l,ut).call(this,n))return!0});e(this,k).waitForHeadToLoad&&it.length&&(yield new Promise(n=>N(this,null,function*(){let w=0;try{for(var S=kt(it),O,U,yt;O=!(U=yield S.next()).done;O=!1){const _=U.value;_.onload=()=>{w++,w===it.length&&n()}}}catch(U){yt=[U]}finally{try{O&&(U=S.return)&&(yield U.call(S))}finally{if(yt)throw yt[0]}}}))),yield Pt.wait(10);const Lt=[];xt.forEach(n=>{n.hasAttribute("data-permanent")||(d(this,l,ut).call(this,n)?Lt.push(n):n.remove())});const qt=d(this,l,ct).call(this,L.document.body);e(this,k).morphInsideScrollContainer||d(this,l,dt).call(this,L.document),document.documentElement.setAttribute("data-current-pathname",h),document.documentElement.setAttribute("data-current-leaf",Nt),tt.changeHistory({action:s,pathname:h,searchParameters:Ht||(M?location.search:""),hash:X}),e(this,z).remove(),a(this,J,e(this,f)),a(this,f,h),e(this,B).forEach((n,w)=>{const S=qt[w],O=getComputedStyle(n).getPropertyValue("--morph-duration"),U=[...S.childNodes];if(O){const yt=[...n.childNodes];yt.forEach(g=>{g instanceof HTMLElement&&(this.destroyOldLinks(g),g.classList.add("old"))}),U.forEach(g=>{g instanceof HTMLElement&&(this.findNewLinks(g),g.classList.add("new"))}),n.prepend(...U),Rt.requestIdleCallback(()=>{U.forEach(g=>{g instanceof HTMLElement&&g.classList.add("in")})});const _={morphElement:n,pathname:h};K.dispatchEvent(document,"morphNewChildrenAdded",{detail:_});const Dt=new Promise(g=>{setTimeout(()=>{yt.forEach($=>$.remove()),U.forEach($=>{$ instanceof HTMLElement&&$.classList.remove("in","new")}),K.dispatchEvent(document,"morphOldChildrenRemoved",{detail:_}),g()},(parseFloat(O)||0)*1e3+10)});e(this,R).push(Dt)}else this.destroyOldLinks(n),n.innerHTML="",n.append(...U),this.findNewLinks(n)}),X?(L.clearScrollState(),d(this,l,mt).call(this,X,{centerScroll:i,offsetScroll:u})):e(this,P)?L.restoreScrollPosition():L.renewScrollPosition(),yield Promise.all(e(this,R)),Lt.forEach(n=>n.remove()),a(this,R,[]),e(this,B).forEach(n=>{n.querySelectorAll("script").forEach(S=>{const O=document.createElement("script");O.type="module",O.src=S.getAttribute("src"),S.replaceWith(O)})}),K.dispatchEvent(document,"morphComplete",{detail:Et}),window.dispatchEvent(new Event("resize"))}catch(I){console.error(I)}a(this,T,void 0)})}addLink(t){e(this,m).push(new rt(t,this))}addLinks(t){t.forEach(s=>{this.addLink(s)})}removeLink(t){a(this,m,e(this,m).filter(s=>s.element===t?(s.destroy(),!1):!0))}destroyOldLinks(t){a(this,m,e(this,m).filter(s=>t.contains(s.element)?(s.destroy(),!1):!0))}findNewLinks(t){const s=[...t.querySelectorAll("a")].filter(e(this,Q));e(this,m).push(...s.map(i=>new rt(i,this)))}findLinks(){const t=[...document.documentElement.querySelectorAll("a")].filter(e(this,Q));e(this,m).forEach(s=>s.destroy()),a(this,m,t.map(s=>new rt(s,this)))}};k=new WeakMap,B=new WeakMap,m=new WeakMap,et=new WeakMap,T=new WeakMap,f=new WeakMap,J=new WeakMap,R=new WeakMap,P=new WeakMap,y=new WeakMap,W=new WeakMap,z=new WeakMap,Q=new WeakMap,l=new WeakSet,at=function(t,s=!1){return N(this,null,function*(){let i=e(this,W).get(t);return(!i||s)&&(i=yield d(this,l,lt).call(this,t)),i})},lt=function(t){return N(this,null,function*(){const i=yield(yield fetch(t)).text(),u=e(this,et).parseFromString(i,"text/html"),p=new At(this,t,u);return e(this,W).set(t,p),p})},ct=function(t){const s=[...t.querySelectorAll("[data-morph]")];return s.length?s:[t]},Mt=function(t,s){return t.filter(i=>s.find(u=>u.outerHTML===i.outerHTML))},ht=function(t,s){return t.filter(i=>!s.find(u=>u.outerHTML===i.outerHTML))},ut=function(t){return t.tagName==="SCRIPT"||t.tagName==="STYLE"||t.tagName==="LINK"&&t.getAttribute("rel")==="stylesheet"},dt=function(t){var s,i;(s=e(this,y))==null||s.removeEventListener("scroll",e(this,j)),a(this,y,t.querySelector(e(this,k).scrollSelector)||t.documentElement),(i=e(this,y))==null||i.addEventListener("scroll",e(this,j)),e(this,j).call(this)},mt=function(t,s){const i=typeof t=="string"?document.getElementById(t):t;(typeof i=="number"||i)&&Pt.scrollToElement(i,{scrollElement:e(this,y),behavior:(s==null?void 0:s.behavior)||"instant",center:s==null?void 0:s.centerScroll,offset:s==null?void 0:s.offsetScroll})},st=new WeakMap,j=new WeakMap,Y.instance=null;let ot=Y;exports.Morph=ot;
|