aptechka 0.58.0 → 0.59.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.
- package/lib/morph/Morph.d.ts +3 -0
- package/lib/morph/index.cjs +1 -1
- package/lib/morph/index.js +239 -228
- package/package.json +1 -1
package/lib/morph/Morph.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ export interface MorphEvents {
|
|
|
44
44
|
}
|
|
45
45
|
export declare class Morph {
|
|
46
46
|
#private;
|
|
47
|
+
static instance: Morph;
|
|
47
48
|
preprocessor?: MorphPreprocessor;
|
|
48
49
|
pathnameModifier?: MorphPathnameModifier;
|
|
49
50
|
constructor(parameters?: Partial<MorphOptions>);
|
|
@@ -63,6 +64,8 @@ export declare class Morph {
|
|
|
63
64
|
addLink(element: HTMLAnchorElement): void;
|
|
64
65
|
addLinks(elements: Array<HTMLAnchorElement>): void;
|
|
65
66
|
removeLink(element: HTMLAnchorElement): void;
|
|
67
|
+
destroyOldLinks(morphElement: HTMLElement): void;
|
|
68
|
+
findNewLinks(morphElement: HTMLElement): void;
|
|
66
69
|
findLinks(): void;
|
|
67
70
|
}
|
|
68
71
|
declare global {
|
package/lib/morph/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var vt=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),St=n=>{throw TypeError(n)};var st=(n,e,s)=>e.has(n)||St("Cannot "+s);var t=(n,e,s)=>(st(n,e,"read from private field"),s?s.call(n):e.get(n)),o=(n,e,s)=>e.has(n)?St("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,s),a=(n,e,s,i)=>(st(n,e,"write to private field"),i?i.call(n,s):e.set(n,s),s),d=(n,e,s)=>(st(n,e,"access private method"),s);var x=(n,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(n,e)).next())});var yt=(n,e,s)=>(e=n[vt("asyncIterator")])?e.call(n):(n=n[vt("iterator")](),e={},s=(i,u)=>(u=n[i])&&(e[i]=f=>new Promise((M,H,p)=>(f=u.call(n,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 Pt=require("../index-Cqw2NKev.cjs"),U=require("../events-KVanG9sR.cjs"),Nt=require("../polyfills-Df4r-ETT.cjs"),Lt=require("../scroll-DAhSpkhR.cjs"),Z=require("../url-D1CgmwZ_.cjs"),Dt=require("../css-value-parser/index.cjs");class At 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)}}Pt.isBrowser&&!customElements.get("morph-announcer")&&customElements.define("morph-announcer",At);var w,c,N,K,V;class bt{constructor(e,s){o(this,w);o(this,c);o(this,N);o(this,K,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?Dt.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,K)),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,K)),t(this,c).removeEventListener("pointerenter",t(this,V)),t(this,c).classList.remove("current")}}w=new WeakMap,c=new WeakMap,N=new WeakMap,K=new WeakMap,V=new WeakMap;var k,B,E,D,q,C;class wt{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,$,T,m,Y,R,A,L,W,z,l,it,rt,nt,kt,ot,at,lt,ct,tt,_;class qt{constructor(e){o(this,l);o(this,P,null);o(this,O,null);o(this,g,[]);o(this,$,new DOMParser);o(this,T);o(this,m,null);o(this,Y);o(this,R,[]);o(this,A,!1);o(this,L,null);o(this,W,new Map);o(this,z,null);o(this,tt,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,_,()=>{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),U.dispatchEvent(document,"morphScroll",{detail:{left:s,top:e}})});if(Pt.isBrowser){a(this,P,{base:Z.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,nt).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 wt(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,tt)),Z.changeHistory({action:"replace",pathname:t(this,m),searchParameters:s.parameters||location.search,hash:s.hash}),a(this,z,new At),d(this,l,lt).call(this,document)}}get currentPathname(){return t(this,m)}get previousPathname(){return t(this,Y)}get links(){return t(this,g)}get scrollElement(){return t(this,L)}get isPopstateNavigation(){return t(this,A)}normalizePath(e){return Z.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,rt).call(this,s.pathname)})}navigate(H){return x(this,arguments,function*(e,{historyAction:s="push",centerScroll:i,offsetScroll:u,revalidate:f,keepSearchParameters:M}={}){var ht;if(t(this,R).length)return;const p=this.normalizePath(((ht=this.pathnameModifier)==null?void 0:ht.call(this,e))||e);let{pathname:h,hash:G,parameters:Ct,leaf:Tt}=p;if(t(this,T)===h||t(this,m)===h){t(this,A)||d(this,l,ct).call(this,G||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((r,b)=>{var v;(v=this.preprocessor)==null||v.call(this,{pathname:h,resolve:r,reject:b})})}catch(r){r?console.error(r):console.log("Route change canceled"),I=!1}if(!I||t(this,T)!==h){t(this,g).forEach(r=>{r.checkCurrent(t(this,m))});return}const ut=yield d(this,l,it).call(this,t(this,m)),S=yield d(this,l,it).call(this,h,f);if(t(this,T)!==h){t(this,g).forEach(r=>{r.checkCurrent(t(this,m))});return}ut.saveScrollState(),ut.saveDocumentState(),t(this,A)||(S.clearScrollState(),S.clearDocumentState()),S.cloneDocument(),t(this,z).textContent=S.title,document.body.appendChild(t(this,z));const dt={pathname:h};U.dispatchEvent(document,"morphStart",{detail:dt});const mt=Array.from(document.head.children),ft=Array.from(S.document.head.children),pt=d(this,l,kt).call(this,mt,ft),Mt=d(this,l,ot).call(this,mt,pt),J=d(this,l,ot).call(this,ft,pt);J.forEach((r,b)=>{if(r.tagName==="SCRIPT"&&r.getAttribute("src")){const v=document.createElement("script");v.type="module",v.src=r.getAttribute("src"),J[b]=v}}),J.forEach(r=>{document.head.appendChild(r)});const et=J.filter(r=>{if(r.hasAttribute("data-no-waiting"))return!1;if(d(this,l,at).call(this,r))return!0});t(this,P).waitForHeadToLoad&&et.length&&(yield new Promise(r=>x(this,null,function*(){let b=0;try{for(var v=yt(et),F,j,gt;F=!(j=yield v.next()).done;F=!1){const Q=j.value;Q.onload=()=>{b++,b===et.length&&r()}}}catch(j){gt=[j]}finally{try{F&&(j=v.return)&&(yield j.call(v))}finally{if(gt)throw gt[0]}}}))),yield Lt.wait(10);const Et=[];Mt.forEach(r=>{r.hasAttribute("data-permanent")||(d(this,l,at).call(this,r)?Et.push(r):r.remove())});const Ht=d(this,l,nt).call(this,S.document.body);t(this,P).morphInsideScrollContainer||d(this,l,lt).call(this,S.document),document.documentElement.setAttribute("data-current-pathname",h),document.documentElement.setAttribute("data-current-leaf",Tt),Z.changeHistory({action:s,pathname:h,searchParameters:Ct||(M?location.search:""),hash:G}),t(this,z).remove(),a(this,Y,t(this,m)),a(this,m,h),t(this,O).forEach((r,b)=>{const v=Ht[b],F=getComputedStyle(r).getPropertyValue("--morph-duration"),j=[...v.childNodes];if(F){const gt=[...r.childNodes];gt.forEach(y=>{y instanceof HTMLElement&&y.classList.add("old")}),j.forEach(y=>{y instanceof HTMLElement&&y.classList.add("new")}),r.prepend(...j),Nt.requestIdleCallback(()=>{j.forEach(y=>{y instanceof HTMLElement&&y.classList.add("in")})});const Q={morphElement:r,pathname:h};U.dispatchEvent(document,"morphNewChildrenAdded",{detail:Q});const xt=new Promise(y=>{setTimeout(()=>{gt.forEach(X=>X.remove()),j.forEach(X=>{X instanceof HTMLElement&&X.classList.remove("in","new")}),U.dispatchEvent(document,"morphOldChildrenRemoved",{detail:Q}),y()},(parseFloat(F)||0)*1e3+10)});t(this,R).push(xt)}else r.innerHTML="",r.append(...j)}),G?(S.clearScrollState(),d(this,l,ct).call(this,G,{centerScroll:i,offsetScroll:u})):t(this,A)?S.restoreScrollPosition():S.renewScrollPosition(),yield Promise.all(t(this,R)),Et.forEach(r=>r.remove()),a(this,R,[]),t(this,O).forEach(r=>{r.querySelectorAll("script").forEach(v=>{const F=document.createElement("script");F.type="module",F.src=v.getAttribute("src"),v.replaceWith(F)})}),this.findLinks(),U.dispatchEvent(document,"morphComplete",{detail:dt}),window.dispatchEvent(new Event("resize"))}catch(I){console.error(I)}a(this,T,void 0)})}addLink(e){t(this,g).push(new bt(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 bt(s,this)))}}P=new WeakMap,O=new WeakMap,g=new WeakMap,$=new WeakMap,T=new WeakMap,m=new WeakMap,Y=new WeakMap,R=new WeakMap,A=new WeakMap,L=new WeakMap,W=new WeakMap,z=new WeakMap,l=new WeakSet,it=function(e,s=!1){return x(this,null,function*(){let i=t(this,W).get(e);return(!i||s)&&(i=yield d(this,l,rt).call(this,e)),i})},rt=function(e){return x(this,null,function*(){const i=yield(yield fetch(e)).text(),u=t(this,$).parseFromString(i,"text/html"),f=new wt(this,e,u);return t(this,W).set(e,f),f})},nt=function(e){const s=[...e.querySelectorAll("[data-morph]")];return s.length?s:[e]},kt=function(e,s){return e.filter(i=>s.find(u=>u.outerHTML===i.outerHTML))},ot=function(e,s){return e.filter(i=>!s.find(u=>u.outerHTML===i.outerHTML))},at=function(e){return e.tagName==="SCRIPT"||e.tagName==="STYLE"||e.tagName==="LINK"&&e.getAttribute("rel")==="stylesheet"},lt=function(e){var s,i;(s=t(this,L))==null||s.removeEventListener("scroll",t(this,_)),a(this,L,e.querySelector(t(this,P).scrollSelector)||e.documentElement),(i=t(this,L))==null||i.addEventListener("scroll",t(this,_)),t(this,_).call(this)},ct=function(e,s){const i=typeof e=="string"?document.getElementById(e):e;(typeof i=="number"||i)&&Lt.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})},tt=new WeakMap,_=new WeakMap;exports.Morph=qt;
|
|
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;
|
package/lib/morph/index.js
CHANGED
|
@@ -1,376 +1,380 @@
|
|
|
1
|
-
var
|
|
1
|
+
var vt = (n, t) => (t = Symbol[n]) ? t : Symbol.for("Symbol." + n), wt = (n) => {
|
|
2
2
|
throw TypeError(n);
|
|
3
3
|
};
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
4
|
+
var it = (n, t, s) => t.has(n) || wt("Cannot " + s);
|
|
5
|
+
var e = (n, t, s) => (it(n, t, "read from private field"), s ? s.call(n) : t.get(n)), o = (n, t, s) => t.has(n) ? wt("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(n) : t.set(n, s), a = (n, t, s, i) => (it(n, t, "write to private field"), i ? i.call(n, s) : t.set(n, s), s), d = (n, t, s) => (it(n, t, "access private method"), s);
|
|
6
|
+
var N = (n, t, s) => new Promise((i, u) => {
|
|
7
|
+
var p = (E) => {
|
|
8
8
|
try {
|
|
9
|
-
|
|
9
|
+
M(s.next(E));
|
|
10
10
|
} catch (h) {
|
|
11
11
|
u(h);
|
|
12
12
|
}
|
|
13
|
-
},
|
|
13
|
+
}, H = (E) => {
|
|
14
14
|
try {
|
|
15
|
-
|
|
15
|
+
M(s.throw(E));
|
|
16
16
|
} catch (h) {
|
|
17
17
|
u(h);
|
|
18
18
|
}
|
|
19
|
-
},
|
|
20
|
-
|
|
19
|
+
}, M = (E) => E.done ? i(E.value) : Promise.resolve(E.value).then(p, H);
|
|
20
|
+
M((s = s.apply(n, t)).next());
|
|
21
21
|
});
|
|
22
|
-
var
|
|
23
|
-
import { i as
|
|
22
|
+
var yt = (n, t, s) => (t = n[vt("asyncIterator")]) ? t.call(n) : (n = n[vt("iterator")](), t = {}, s = (i, u) => (u = n[i]) && (t[i] = (p) => new Promise((H, M, E) => (p = u.call(n, p), E = p.done, Promise.resolve(p.value).then((h) => H({ value: h, done: E }), M)))), s("next"), s("return"), t);
|
|
23
|
+
import { i as At } from "../index-euf5anj6.js";
|
|
24
24
|
import { d as K } from "../events-CsVF98U6.js";
|
|
25
|
-
import { r as
|
|
26
|
-
import { w as
|
|
27
|
-
import { n as
|
|
28
|
-
import { cssValueParser as
|
|
29
|
-
class
|
|
25
|
+
import { r as Rt } from "../polyfills-DJrTJQky.js";
|
|
26
|
+
import { w as zt, s as It } from "../scroll-Benkuq-t.js";
|
|
27
|
+
import { n as qt, c as bt, s as Ot } from "../url-B6BNcw6_.js";
|
|
28
|
+
import { cssValueParser as Ft } from "../css-value-parser/index.js";
|
|
29
|
+
class Ct extends HTMLElement {
|
|
30
30
|
connectedCallback() {
|
|
31
|
-
const
|
|
31
|
+
const t = {
|
|
32
32
|
"aria-live": "assertive",
|
|
33
33
|
"aria-atomic": "true",
|
|
34
34
|
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"
|
|
35
35
|
};
|
|
36
|
-
for (const [s, i] of Object.entries(
|
|
36
|
+
for (const [s, i] of Object.entries(t))
|
|
37
37
|
this.setAttribute(s, i);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
var
|
|
42
|
-
class
|
|
43
|
-
constructor(
|
|
44
|
-
o(this,
|
|
40
|
+
At && !customElements.get("morph-announcer") && customElements.define("morph-announcer", Ct);
|
|
41
|
+
var b, c, x, G, F;
|
|
42
|
+
class rt {
|
|
43
|
+
constructor(t, s) {
|
|
44
|
+
o(this, b);
|
|
45
45
|
o(this, c);
|
|
46
|
-
o(this,
|
|
47
|
-
o(this,
|
|
48
|
-
if (
|
|
46
|
+
o(this, x);
|
|
47
|
+
o(this, G, (t) => {
|
|
48
|
+
if (t.preventDefault(), e(this, c).hasAttribute("data-back") && e(this, b).previousPathname)
|
|
49
49
|
history.back();
|
|
50
50
|
else {
|
|
51
|
-
const i =
|
|
51
|
+
const i = e(this, c).getAttribute(
|
|
52
52
|
"data-history-action"
|
|
53
|
-
) || "push", u =
|
|
53
|
+
) || "push", u = e(this, c).hasAttribute("data-center-scroll"), p = getComputedStyle(e(this, c)).getPropertyValue("--offset-scroll").trim(), H = p ? Ft.parse(p) : void 0, M = e(this, c).hasAttribute("data-revalidate"), E = e(this, c).hasAttribute(
|
|
54
54
|
"data-keep-search-parameters"
|
|
55
55
|
);
|
|
56
|
-
|
|
56
|
+
e(this, b).navigate(e(this, x), {
|
|
57
57
|
historyAction: i,
|
|
58
58
|
centerScroll: u,
|
|
59
|
-
offsetScroll:
|
|
60
|
-
revalidate:
|
|
61
|
-
keepSearchParameters:
|
|
59
|
+
offsetScroll: H,
|
|
60
|
+
revalidate: M,
|
|
61
|
+
keepSearchParameters: E
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
|
-
o(this,
|
|
66
|
-
|
|
65
|
+
o(this, F, () => {
|
|
66
|
+
e(this, b).prefetch(e(this, x)), e(this, c).removeEventListener("pointerenter", e(this, F));
|
|
67
67
|
});
|
|
68
|
-
a(this,
|
|
68
|
+
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));
|
|
69
69
|
}
|
|
70
70
|
get element() {
|
|
71
|
-
return
|
|
71
|
+
return e(this, c);
|
|
72
72
|
}
|
|
73
|
-
checkCurrent(
|
|
74
|
-
const s =
|
|
75
|
-
|
|
73
|
+
checkCurrent(t) {
|
|
74
|
+
const s = e(this, b).normalizePath(t), i = e(this, b).normalizePath(e(this, x));
|
|
75
|
+
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");
|
|
76
76
|
}
|
|
77
77
|
destroy() {
|
|
78
|
-
|
|
78
|
+
e(this, c).removeEventListener("click", e(this, G)), e(this, c).removeEventListener("pointerenter", e(this, F)), e(this, c).classList.remove("current");
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
|
|
82
|
-
var
|
|
83
|
-
class
|
|
84
|
-
constructor(
|
|
85
|
-
o(this,
|
|
86
|
-
o(this,
|
|
87
|
-
o(this,
|
|
81
|
+
b = new WeakMap(), c = new WeakMap(), x = new WeakMap(), G = new WeakMap(), F = new WeakMap();
|
|
82
|
+
var A, V, L, D, R, C;
|
|
83
|
+
class kt {
|
|
84
|
+
constructor(t, s, i) {
|
|
85
|
+
o(this, A);
|
|
86
|
+
o(this, V);
|
|
87
|
+
o(this, L, { x: 0, y: 0 });
|
|
88
88
|
o(this, D);
|
|
89
89
|
o(this, R, null);
|
|
90
90
|
o(this, C, null);
|
|
91
|
-
a(this,
|
|
91
|
+
a(this, A, t), a(this, V, s), a(this, D, i.cloneNode(!0));
|
|
92
92
|
}
|
|
93
93
|
get pathname() {
|
|
94
|
-
return
|
|
94
|
+
return e(this, V);
|
|
95
95
|
}
|
|
96
96
|
get scrollState() {
|
|
97
|
-
return
|
|
97
|
+
return e(this, L);
|
|
98
98
|
}
|
|
99
99
|
get document() {
|
|
100
|
-
return
|
|
100
|
+
return e(this, C);
|
|
101
101
|
}
|
|
102
102
|
cloneDocument() {
|
|
103
|
-
a(this, C, (
|
|
103
|
+
a(this, C, (e(this, R) || e(this, D)).cloneNode(!0));
|
|
104
104
|
}
|
|
105
105
|
get title() {
|
|
106
|
-
let
|
|
107
|
-
if (
|
|
108
|
-
|
|
106
|
+
let t = "";
|
|
107
|
+
if (e(this, C).title)
|
|
108
|
+
t = e(this, C).title;
|
|
109
109
|
else {
|
|
110
|
-
const s =
|
|
111
|
-
|
|
110
|
+
const s = e(this, C).querySelector("h1");
|
|
111
|
+
t = (s == null ? void 0 : s.innerText) || (s == null ? void 0 : s.textContent) || e(this, V);
|
|
112
112
|
}
|
|
113
|
-
return
|
|
113
|
+
return t;
|
|
114
114
|
}
|
|
115
115
|
clearScrollState() {
|
|
116
|
-
|
|
116
|
+
e(this, L).x = 0, e(this, L).y = 0;
|
|
117
117
|
}
|
|
118
118
|
clearDocumentState() {
|
|
119
119
|
a(this, R, null);
|
|
120
120
|
}
|
|
121
121
|
saveScrollState() {
|
|
122
|
-
|
|
122
|
+
e(this, D).documentElement.hasAttribute(
|
|
123
123
|
"data-no-scroll-restoration"
|
|
124
|
-
) ? (
|
|
124
|
+
) ? (e(this, L).x = 0, e(this, L).y = 0) : (e(this, L).x = e(this, A).scrollElement.scrollLeft, e(this, L).y = e(this, A).scrollElement.scrollTop);
|
|
125
125
|
}
|
|
126
126
|
saveDocumentState() {
|
|
127
|
-
|
|
127
|
+
e(this, D).documentElement.hasAttribute(
|
|
128
128
|
"data-no-page-restoration"
|
|
129
129
|
) ? a(this, R, null) : a(this, R, document.cloneNode(!0));
|
|
130
130
|
}
|
|
131
131
|
restoreScrollPosition() {
|
|
132
|
-
|
|
133
|
-
top:
|
|
134
|
-
left:
|
|
132
|
+
e(this, A).scrollElement.scroll({
|
|
133
|
+
top: e(this, L).y,
|
|
134
|
+
left: e(this, L).x
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
137
|
renewScrollPosition() {
|
|
138
|
-
|
|
138
|
+
e(this, A).scrollElement.scroll({
|
|
139
139
|
top: 0,
|
|
140
140
|
left: 0,
|
|
141
141
|
behavior: "instant"
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
-
|
|
146
|
-
var
|
|
147
|
-
class
|
|
148
|
-
constructor(
|
|
145
|
+
A = new WeakMap(), V = new WeakMap(), L = new WeakMap(), D = new WeakMap(), R = new WeakMap(), C = new WeakMap();
|
|
146
|
+
var k, W, m, tt, T, f, J, z, P, w, B, I, Q, l, nt, ot, at, Tt, lt, ct, ht, ut, et, U;
|
|
147
|
+
const Y = class Y {
|
|
148
|
+
constructor(t) {
|
|
149
149
|
o(this, l);
|
|
150
|
-
o(this,
|
|
151
|
-
o(this,
|
|
152
|
-
o(this,
|
|
153
|
-
o(this,
|
|
150
|
+
o(this, k, null);
|
|
151
|
+
o(this, W, null);
|
|
152
|
+
o(this, m, []);
|
|
153
|
+
o(this, tt, new DOMParser());
|
|
154
154
|
o(this, T);
|
|
155
|
-
o(this,
|
|
156
|
-
o(this,
|
|
155
|
+
o(this, f, null);
|
|
156
|
+
o(this, J);
|
|
157
157
|
o(this, z, []);
|
|
158
|
-
o(this,
|
|
158
|
+
o(this, P, !1);
|
|
159
159
|
o(this, w, null);
|
|
160
|
-
o(this,
|
|
160
|
+
o(this, B, /* @__PURE__ */ new Map());
|
|
161
161
|
o(this, I, null);
|
|
162
|
-
o(this,
|
|
162
|
+
o(this, Q, (t) => {
|
|
163
163
|
var s;
|
|
164
|
-
(s =
|
|
164
|
+
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";
|
|
165
|
+
});
|
|
166
|
+
o(this, et, (t) => N(this, null, function* () {
|
|
167
|
+
var s;
|
|
168
|
+
(s = t.state) != null && s.path && (t.preventDefault(), a(this, P, !0), yield this.navigate(t.state.path, { historyAction: "none" }), a(this, P, !1));
|
|
165
169
|
}));
|
|
166
170
|
o(this, U, () => {
|
|
167
|
-
const
|
|
168
|
-
document.documentElement.classList.toggle("top-scrolled",
|
|
171
|
+
const t = e(this, w).scrollTop, s = e(this, w).scrollLeft;
|
|
172
|
+
document.documentElement.classList.toggle("top-scrolled", t > 0), document.documentElement.classList.toggle("left-scrolled", s > 0), K(document, "morphScroll", {
|
|
169
173
|
detail: {
|
|
170
174
|
left: s,
|
|
171
|
-
top:
|
|
175
|
+
top: t
|
|
172
176
|
}
|
|
173
177
|
});
|
|
174
178
|
});
|
|
175
|
-
if (
|
|
176
|
-
a(this,
|
|
177
|
-
base:
|
|
178
|
-
waitForHeadToLoad: (
|
|
179
|
-
cachePages: (
|
|
180
|
-
trailingSlash: (
|
|
181
|
-
scrollSelector: (
|
|
182
|
-
morphInsideScrollContainer: (
|
|
183
|
-
}), a(this,
|
|
179
|
+
if (At && !Y.instance) {
|
|
180
|
+
Y.instance = this, a(this, k, {
|
|
181
|
+
base: qt(t == null ? void 0 : t.base),
|
|
182
|
+
waitForHeadToLoad: (t == null ? void 0 : t.waitForHeadToLoad) !== !1,
|
|
183
|
+
cachePages: (t == null ? void 0 : t.cachePages) !== !1,
|
|
184
|
+
trailingSlash: (t == null ? void 0 : t.trailingSlash) || !1,
|
|
185
|
+
scrollSelector: (t == null ? void 0 : t.scrollSelector) || "body",
|
|
186
|
+
morphInsideScrollContainer: (t == null ? void 0 : t.morphInsideScrollContainer) || !1
|
|
187
|
+
}), a(this, W, d(this, l, at).call(this, document.body));
|
|
184
188
|
const s = this.normalizePath(
|
|
185
189
|
location.pathname + location.hash
|
|
186
190
|
);
|
|
187
|
-
a(this,
|
|
188
|
-
|
|
189
|
-
new
|
|
191
|
+
a(this, f, s.pathname), e(this, B).set(
|
|
192
|
+
e(this, f),
|
|
193
|
+
new kt(this, e(this, f), document)
|
|
190
194
|
), document.documentElement.setAttribute(
|
|
191
195
|
"data-current-pathname",
|
|
192
|
-
|
|
196
|
+
e(this, f)
|
|
193
197
|
), document.documentElement.setAttribute(
|
|
194
198
|
"data-current-leaf",
|
|
195
199
|
s.leaf
|
|
196
|
-
), this.findLinks(), addEventListener("popstate",
|
|
200
|
+
), this.findLinks(), addEventListener("popstate", e(this, et)), bt({
|
|
197
201
|
action: "replace",
|
|
198
|
-
pathname:
|
|
202
|
+
pathname: e(this, f),
|
|
199
203
|
searchParameters: s.parameters || location.search,
|
|
200
204
|
hash: s.hash
|
|
201
|
-
}), a(this, I, new
|
|
205
|
+
}), a(this, I, new Ct()), d(this, l, ht).call(this, document);
|
|
202
206
|
}
|
|
203
207
|
}
|
|
204
208
|
get currentPathname() {
|
|
205
|
-
return
|
|
209
|
+
return e(this, f);
|
|
206
210
|
}
|
|
207
211
|
get previousPathname() {
|
|
208
|
-
return
|
|
212
|
+
return e(this, J);
|
|
209
213
|
}
|
|
210
214
|
get links() {
|
|
211
|
-
return
|
|
215
|
+
return e(this, m);
|
|
212
216
|
}
|
|
213
217
|
get scrollElement() {
|
|
214
|
-
return
|
|
218
|
+
return e(this, w);
|
|
215
219
|
}
|
|
216
220
|
get isPopstateNavigation() {
|
|
217
|
-
return
|
|
221
|
+
return e(this, P);
|
|
218
222
|
}
|
|
219
|
-
normalizePath(
|
|
220
|
-
return
|
|
221
|
-
base:
|
|
222
|
-
trailingSlash:
|
|
223
|
+
normalizePath(t) {
|
|
224
|
+
return Ot(t, {
|
|
225
|
+
base: e(this, k).base,
|
|
226
|
+
trailingSlash: e(this, k).trailingSlash
|
|
223
227
|
});
|
|
224
228
|
}
|
|
225
|
-
prefetch(
|
|
226
|
-
return
|
|
227
|
-
const s = this.normalizePath(
|
|
228
|
-
d(this, l,
|
|
229
|
+
prefetch(t) {
|
|
230
|
+
return N(this, null, function* () {
|
|
231
|
+
const s = this.normalizePath(t);
|
|
232
|
+
d(this, l, ot).call(this, s.pathname);
|
|
229
233
|
});
|
|
230
234
|
}
|
|
231
|
-
navigate(
|
|
232
|
-
return
|
|
235
|
+
navigate(M) {
|
|
236
|
+
return N(this, arguments, function* (t, {
|
|
233
237
|
historyAction: s = "push",
|
|
234
238
|
centerScroll: i,
|
|
235
239
|
offsetScroll: u,
|
|
236
|
-
revalidate:
|
|
237
|
-
keepSearchParameters:
|
|
240
|
+
revalidate: p,
|
|
241
|
+
keepSearchParameters: H
|
|
238
242
|
} = {}) {
|
|
239
|
-
var
|
|
240
|
-
if (
|
|
243
|
+
var dt;
|
|
244
|
+
if (e(this, z).length)
|
|
241
245
|
return;
|
|
242
|
-
const
|
|
243
|
-
let { pathname: h, hash:
|
|
244
|
-
if (
|
|
245
|
-
|
|
246
|
+
const E = this.normalizePath(((dt = this.pathnameModifier) == null ? void 0 : dt.call(this, t)) || t);
|
|
247
|
+
let { pathname: h, hash: X, parameters: Ht, leaf: Mt } = E;
|
|
248
|
+
if (e(this, T) === h || e(this, f) === h) {
|
|
249
|
+
e(this, P) || d(this, l, ut).call(this, X || 0, {
|
|
246
250
|
centerScroll: i,
|
|
247
251
|
offsetScroll: u,
|
|
248
252
|
behavior: "smooth"
|
|
249
253
|
});
|
|
250
254
|
return;
|
|
251
255
|
}
|
|
252
|
-
a(this, T, h),
|
|
256
|
+
a(this, T, h), e(this, m).forEach((q) => {
|
|
253
257
|
q.checkCurrent(h);
|
|
254
258
|
});
|
|
255
259
|
try {
|
|
256
260
|
let q = !0;
|
|
257
261
|
if (this.preprocessor)
|
|
258
262
|
try {
|
|
259
|
-
yield new Promise((r,
|
|
263
|
+
yield new Promise((r, y) => {
|
|
260
264
|
var S;
|
|
261
265
|
(S = this.preprocessor) == null || S.call(this, {
|
|
262
266
|
pathname: h,
|
|
263
267
|
resolve: r,
|
|
264
|
-
reject:
|
|
268
|
+
reject: y
|
|
265
269
|
});
|
|
266
270
|
});
|
|
267
271
|
} catch (r) {
|
|
268
272
|
r ? console.error(r) : console.log("Route change canceled"), q = !1;
|
|
269
273
|
}
|
|
270
|
-
if (!q ||
|
|
271
|
-
|
|
272
|
-
r.checkCurrent(
|
|
274
|
+
if (!q || e(this, T) !== h) {
|
|
275
|
+
e(this, m).forEach((r) => {
|
|
276
|
+
r.checkCurrent(e(this, f));
|
|
273
277
|
});
|
|
274
278
|
return;
|
|
275
279
|
}
|
|
276
|
-
const
|
|
277
|
-
if (
|
|
278
|
-
|
|
279
|
-
r.checkCurrent(
|
|
280
|
+
const mt = yield d(this, l, nt).call(this, e(this, f)), v = yield d(this, l, nt).call(this, h, p);
|
|
281
|
+
if (e(this, T) !== h) {
|
|
282
|
+
e(this, m).forEach((r) => {
|
|
283
|
+
r.checkCurrent(e(this, f));
|
|
280
284
|
});
|
|
281
285
|
return;
|
|
282
286
|
}
|
|
283
|
-
|
|
284
|
-
const
|
|
287
|
+
mt.saveScrollState(), mt.saveDocumentState(), e(this, P) || (v.clearScrollState(), v.clearDocumentState()), v.cloneDocument(), e(this, I).textContent = v.title, document.body.appendChild(e(this, I));
|
|
288
|
+
const ft = {
|
|
285
289
|
pathname: h
|
|
286
290
|
};
|
|
287
291
|
K(document, "morphStart", {
|
|
288
|
-
detail:
|
|
292
|
+
detail: ft
|
|
289
293
|
});
|
|
290
|
-
const
|
|
291
|
-
|
|
294
|
+
const pt = Array.from(document.head.children), Et = Array.from(v.document.head.children), gt = d(this, l, Tt).call(this, pt, Et), Nt = d(this, l, lt).call(this, pt, gt), Z = d(this, l, lt).call(this, Et, gt);
|
|
295
|
+
Z.forEach((r, y) => {
|
|
292
296
|
if (r.tagName === "SCRIPT" && r.getAttribute("src")) {
|
|
293
297
|
const S = document.createElement("script");
|
|
294
|
-
S.type = "module", S.src = r.getAttribute("src"),
|
|
298
|
+
S.type = "module", S.src = r.getAttribute("src"), Z[y] = S;
|
|
295
299
|
}
|
|
296
|
-
}),
|
|
300
|
+
}), Z.forEach((r) => {
|
|
297
301
|
document.head.appendChild(r);
|
|
298
302
|
});
|
|
299
|
-
const
|
|
303
|
+
const st = Z.filter((r) => {
|
|
300
304
|
if (r.hasAttribute("data-no-waiting"))
|
|
301
305
|
return !1;
|
|
302
|
-
if (d(this, l,
|
|
306
|
+
if (d(this, l, ct).call(this, r))
|
|
303
307
|
return !0;
|
|
304
308
|
});
|
|
305
|
-
|
|
306
|
-
let
|
|
309
|
+
e(this, k).waitForHeadToLoad && st.length && (yield new Promise((r) => N(this, null, function* () {
|
|
310
|
+
let y = 0;
|
|
307
311
|
try {
|
|
308
|
-
for (var S =
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
+
for (var S = yt(st), O, j, St; O = !(j = yield S.next()).done; O = !1) {
|
|
313
|
+
const $ = j.value;
|
|
314
|
+
$.onload = () => {
|
|
315
|
+
y++, y === st.length && r();
|
|
312
316
|
};
|
|
313
317
|
}
|
|
314
318
|
} catch (j) {
|
|
315
|
-
|
|
319
|
+
St = [j];
|
|
316
320
|
} finally {
|
|
317
321
|
try {
|
|
318
|
-
|
|
322
|
+
O && (j = S.return) && (yield j.call(S));
|
|
319
323
|
} finally {
|
|
320
|
-
if (
|
|
321
|
-
throw
|
|
324
|
+
if (St)
|
|
325
|
+
throw St[0];
|
|
322
326
|
}
|
|
323
327
|
}
|
|
324
|
-
}))), yield
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
r.hasAttribute("data-permanent") || (d(this, l,
|
|
328
|
+
}))), yield zt(10);
|
|
329
|
+
const Lt = [];
|
|
330
|
+
Nt.forEach((r) => {
|
|
331
|
+
r.hasAttribute("data-permanent") || (d(this, l, ct).call(this, r) ? Lt.push(r) : r.remove());
|
|
328
332
|
});
|
|
329
|
-
const
|
|
330
|
-
|
|
333
|
+
const xt = d(this, l, at).call(this, v.document.body);
|
|
334
|
+
e(this, k).morphInsideScrollContainer || d(this, l, ht).call(this, v.document), document.documentElement.setAttribute("data-current-pathname", h), document.documentElement.setAttribute("data-current-leaf", Mt), bt({
|
|
331
335
|
action: s,
|
|
332
336
|
pathname: h,
|
|
333
|
-
searchParameters:
|
|
334
|
-
hash:
|
|
335
|
-
}),
|
|
336
|
-
const S =
|
|
337
|
-
if (
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}), j.forEach((
|
|
342
|
-
|
|
343
|
-
}), r.prepend(...j),
|
|
344
|
-
j.forEach((
|
|
345
|
-
|
|
337
|
+
searchParameters: Ht || (H ? location.search : ""),
|
|
338
|
+
hash: X
|
|
339
|
+
}), e(this, I).remove(), a(this, J, e(this, f)), a(this, f, h), e(this, W).forEach((r, y) => {
|
|
340
|
+
const S = xt[y], O = getComputedStyle(r).getPropertyValue("--morph-duration"), j = [...S.childNodes];
|
|
341
|
+
if (O) {
|
|
342
|
+
const St = [...r.childNodes];
|
|
343
|
+
St.forEach((g) => {
|
|
344
|
+
g instanceof HTMLElement && (this.destroyOldLinks(g), g.classList.add("old"));
|
|
345
|
+
}), j.forEach((g) => {
|
|
346
|
+
g instanceof HTMLElement && (this.findNewLinks(g), g.classList.add("new"));
|
|
347
|
+
}), r.prepend(...j), Rt(() => {
|
|
348
|
+
j.forEach((g) => {
|
|
349
|
+
g instanceof HTMLElement && g.classList.add("in");
|
|
346
350
|
});
|
|
347
351
|
});
|
|
348
|
-
const
|
|
352
|
+
const $ = {
|
|
349
353
|
morphElement: r,
|
|
350
354
|
pathname: h
|
|
351
355
|
};
|
|
352
356
|
K(document, "morphNewChildrenAdded", {
|
|
353
|
-
detail:
|
|
357
|
+
detail: $
|
|
354
358
|
});
|
|
355
|
-
const
|
|
359
|
+
const Dt = new Promise((g) => {
|
|
356
360
|
setTimeout(() => {
|
|
357
|
-
|
|
358
|
-
|
|
361
|
+
St.forEach((_) => _.remove()), j.forEach((_) => {
|
|
362
|
+
_ instanceof HTMLElement && _.classList.remove("in", "new");
|
|
359
363
|
}), K(document, "morphOldChildrenRemoved", {
|
|
360
|
-
detail:
|
|
361
|
-
}),
|
|
362
|
-
}, (parseFloat(
|
|
364
|
+
detail: $
|
|
365
|
+
}), g();
|
|
366
|
+
}, (parseFloat(O) || 0) * 1e3 + 10);
|
|
363
367
|
});
|
|
364
|
-
|
|
368
|
+
e(this, z).push(Dt);
|
|
365
369
|
} else
|
|
366
|
-
r.innerHTML = "", r.append(...j);
|
|
367
|
-
}),
|
|
370
|
+
this.destroyOldLinks(r), r.innerHTML = "", r.append(...j), this.findNewLinks(r);
|
|
371
|
+
}), X ? (v.clearScrollState(), d(this, l, ut).call(this, X, { centerScroll: i, offsetScroll: u })) : e(this, P) ? v.restoreScrollPosition() : v.renewScrollPosition(), yield Promise.all(e(this, z)), Lt.forEach((r) => r.remove()), a(this, z, []), e(this, W).forEach((r) => {
|
|
368
372
|
r.querySelectorAll("script").forEach((S) => {
|
|
369
|
-
const
|
|
370
|
-
|
|
373
|
+
const O = document.createElement("script");
|
|
374
|
+
O.type = "module", O.src = S.getAttribute("src"), S.replaceWith(O);
|
|
371
375
|
});
|
|
372
|
-
}),
|
|
373
|
-
detail:
|
|
376
|
+
}), K(document, "morphComplete", {
|
|
377
|
+
detail: ft
|
|
374
378
|
}), window.dispatchEvent(new Event("resize"));
|
|
375
379
|
} catch (q) {
|
|
376
380
|
console.error(q);
|
|
@@ -378,71 +382,78 @@ class jt {
|
|
|
378
382
|
a(this, T, void 0);
|
|
379
383
|
});
|
|
380
384
|
}
|
|
381
|
-
addLink(
|
|
382
|
-
|
|
385
|
+
addLink(t) {
|
|
386
|
+
e(this, m).push(new rt(t, this));
|
|
383
387
|
}
|
|
384
|
-
addLinks(
|
|
385
|
-
|
|
388
|
+
addLinks(t) {
|
|
389
|
+
t.forEach((s) => {
|
|
386
390
|
this.addLink(s);
|
|
387
391
|
});
|
|
388
392
|
}
|
|
389
|
-
removeLink(
|
|
390
|
-
a(this,
|
|
393
|
+
removeLink(t) {
|
|
394
|
+
a(this, m, e(this, m).filter((s) => s.element === t ? (s.destroy(), !1) : !0));
|
|
395
|
+
}
|
|
396
|
+
destroyOldLinks(t) {
|
|
397
|
+
a(this, m, e(this, m).filter((s) => t.contains(s.element) ? (s.destroy(), !1) : !0));
|
|
398
|
+
}
|
|
399
|
+
findNewLinks(t) {
|
|
400
|
+
const s = [...t.querySelectorAll("a")].filter(
|
|
401
|
+
e(this, Q)
|
|
402
|
+
);
|
|
403
|
+
e(this, m).push(
|
|
404
|
+
...s.map((i) => new rt(i, this))
|
|
405
|
+
);
|
|
391
406
|
}
|
|
392
407
|
findLinks() {
|
|
393
|
-
const
|
|
408
|
+
const t = [
|
|
394
409
|
...document.documentElement.querySelectorAll("a")
|
|
395
|
-
].filter(
|
|
396
|
-
|
|
397
|
-
var i;
|
|
398
|
-
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";
|
|
399
|
-
}
|
|
400
|
-
);
|
|
401
|
-
t(this, g).forEach((s) => s.destroy()), a(this, g, e.map((s) => new wt(s, this)));
|
|
410
|
+
].filter(e(this, Q));
|
|
411
|
+
e(this, m).forEach((s) => s.destroy()), a(this, m, t.map((s) => new rt(s, this)));
|
|
402
412
|
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
return
|
|
406
|
-
let i =
|
|
407
|
-
return (!i || s) && (i = yield d(this, l,
|
|
413
|
+
};
|
|
414
|
+
k = new WeakMap(), W = new WeakMap(), m = new WeakMap(), tt = new WeakMap(), T = new WeakMap(), f = new WeakMap(), J = new WeakMap(), z = new WeakMap(), P = new WeakMap(), w = new WeakMap(), B = new WeakMap(), I = new WeakMap(), Q = new WeakMap(), l = new WeakSet(), nt = function(t, s = !1) {
|
|
415
|
+
return N(this, null, function* () {
|
|
416
|
+
let i = e(this, B).get(t);
|
|
417
|
+
return (!i || s) && (i = yield d(this, l, ot).call(this, t)), i;
|
|
408
418
|
});
|
|
409
|
-
},
|
|
410
|
-
return
|
|
411
|
-
const i = yield (yield fetch(
|
|
412
|
-
return
|
|
419
|
+
}, ot = function(t) {
|
|
420
|
+
return N(this, null, function* () {
|
|
421
|
+
const i = yield (yield fetch(t)).text(), u = e(this, tt).parseFromString(i, "text/html"), p = new kt(this, t, u);
|
|
422
|
+
return e(this, B).set(t, p), p;
|
|
413
423
|
});
|
|
414
|
-
},
|
|
415
|
-
const s = [...
|
|
416
|
-
return s.length ? s : [
|
|
417
|
-
},
|
|
418
|
-
return
|
|
424
|
+
}, at = function(t) {
|
|
425
|
+
const s = [...t.querySelectorAll("[data-morph]")];
|
|
426
|
+
return s.length ? s : [t];
|
|
427
|
+
}, Tt = function(t, s) {
|
|
428
|
+
return t.filter(
|
|
419
429
|
(i) => s.find(
|
|
420
430
|
(u) => u.outerHTML === i.outerHTML
|
|
421
431
|
)
|
|
422
432
|
);
|
|
423
|
-
},
|
|
424
|
-
return
|
|
433
|
+
}, lt = function(t, s) {
|
|
434
|
+
return t.filter(
|
|
425
435
|
(i) => !s.find(
|
|
426
436
|
(u) => u.outerHTML === i.outerHTML
|
|
427
437
|
)
|
|
428
438
|
);
|
|
429
|
-
},
|
|
430
|
-
return
|
|
431
|
-
},
|
|
439
|
+
}, ct = function(t) {
|
|
440
|
+
return t.tagName === "SCRIPT" || t.tagName === "STYLE" || t.tagName === "LINK" && t.getAttribute("rel") === "stylesheet";
|
|
441
|
+
}, ht = function(t) {
|
|
432
442
|
var s, i;
|
|
433
|
-
(s =
|
|
443
|
+
(s = e(this, w)) == null || s.removeEventListener(
|
|
434
444
|
"scroll",
|
|
435
|
-
|
|
436
|
-
), a(this, w,
|
|
437
|
-
},
|
|
438
|
-
const i = typeof
|
|
439
|
-
(typeof i == "number" || i) &&
|
|
440
|
-
scrollElement:
|
|
445
|
+
e(this, U)
|
|
446
|
+
), a(this, w, t.querySelector(e(this, k).scrollSelector) || t.documentElement), (i = e(this, w)) == null || i.addEventListener("scroll", e(this, U)), e(this, U).call(this);
|
|
447
|
+
}, ut = function(t, s) {
|
|
448
|
+
const i = typeof t == "string" ? document.getElementById(t) : t;
|
|
449
|
+
(typeof i == "number" || i) && It(i, {
|
|
450
|
+
scrollElement: e(this, w),
|
|
441
451
|
behavior: (s == null ? void 0 : s.behavior) || "instant",
|
|
442
452
|
center: s == null ? void 0 : s.centerScroll,
|
|
443
453
|
offset: s == null ? void 0 : s.offsetScroll
|
|
444
454
|
});
|
|
445
|
-
},
|
|
455
|
+
}, et = new WeakMap(), U = new WeakMap(), Y.instance = null;
|
|
456
|
+
let Pt = Y;
|
|
446
457
|
export {
|
|
447
|
-
|
|
458
|
+
Pt as Morph
|
|
448
459
|
};
|