aptechka 0.45.0 → 0.45.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/index.cjs +1 -1
- package/lib/morph/index.js +69 -65
- package/package.json +1 -1
package/lib/morph/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ft=(i,t)=>(t=Symbol[i])?t:Symbol.for("Symbol."+i),pt=i=>{throw TypeError(i)};var $=(i,t,s)=>t.has(i)||pt("Cannot "+s);var e=(i,t,s)=>($(i,t,"read from private field"),s?s.call(i):t.get(i)),r=(i,t,s)=>t.has(i)?pt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,s),a=(i,t,s,o)=>($(i,t,"write to private field"),o?o.call(i,s):t.set(i,s),s),d=(i,t,s)=>($(i,t,"access private method"),s);var M=(i,t,s)=>new Promise((o,u)=>{var m=l=>{try{A(s.next(l))}catch(g){u(g)}},V=l=>{try{A(s.throw(l))}catch(g){u(g)}},A=l=>l.done?o(l.value):Promise.resolve(l.value).then(m,V);A((s=s.apply(i,t)).next())});var Et=(i,t,s)=>(t=i[ft("asyncIterator")])?t.call(i):(i=i[ft("iterator")](),t={},s=(o,u)=>(u=i[o])&&(t[o]=m=>new Promise((V,A,l)=>(m=u.call(i,m),l=m.done,Promise.resolve(m.value).then(g=>V({value:g,done:l}),A)))),s("next"),s("return"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("../events-KVanG9sR.cjs"),Mt=require("../polyfills-Df4r-ETT.cjs"),Tt=require("../scroll-DPDSZypW.cjs");require("../index-Cqw2NKev.cjs");const Q=require("../url-CLvdjbII.cjs"),Ct=require("../css-value-parser/index.cjs");class St 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,o]of Object.entries(t))this.setAttribute(s,o)}}customElements.get("morph-announcer")||customElements.define("morph-announcer",St);var R,h,T,W,q;class gt{constructor(t,s){r(this,R);r(this,h);r(this,T);r(this,W,t=>{t.preventDefault();const s=e(this,h).getAttribute("data-history-action")||"push",o=e(this,h).hasAttribute("data-center-scroll"),u=getComputedStyle(e(this,h)).getPropertyValue("--offset-scroll").trim(),m=u?Ct.cssValueParser.parse(u):void 0,V=e(this,h).hasAttribute("data-revalidate");e(this,R).navigate(e(this,T),{historyAction:s,centerScroll:o,offsetScroll:m,revalidate:V})});r(this,q,()=>{e(this,R).prefetch(e(this,T)),e(this,h).removeEventListener("pointerenter",e(this,q))});a(this,R,s),a(this,h,t),a(this,T,e(this,h).getAttribute("href")||"/"),e(this,h).addEventListener("click",e(this,W));const o=s.normalizePath(e(this,T)),u=s.normalizePath(location.pathname);e(this,h).hasAttribute("data-include")&&u.pathname.includes(o.pathname)?e(this,h).classList.add("current"):o.pathname===u.pathname&&e(this,h).classList.add("current"),e(this,h).hasAttribute("data-prefetch")&&e(this,h).addEventListener("pointerenter",e(this,q))}get element(){return e(this,h)}destroy(){e(this,h).removeEventListener("click",e(this,W)),e(this,h).removeEventListener("pointerenter",e(this,q)),e(this,h).classList.remove("current")}}R=new WeakMap,h=new WeakMap,T=new WeakMap,W=new WeakMap,q=new WeakMap;var C,z,p,H,k,w;class vt{constructor(t,s,o){r(this,C);r(this,z);r(this,p,{x:0,y:0});r(this,H);r(this,k,null);r(this,w,null);a(this,C,t),a(this,z,s),a(this,H,o.cloneNode(!0))}get pathname(){return e(this,z)}get scrollState(){return e(this,p)}get document(){return e(this,w)}cloneDocument(){a(this,w,(e(this,k)||e(this,H)).cloneNode(!0))}get title(){let t="";if(e(this,w).title)t=e(this,w).title;else{const s=e(this,w).querySelector("h1");t=(s==null?void 0:s.innerText)||(s==null?void 0:s.textContent)||e(this,z)}return t}clearScrollState(){e(this,p).x=0,e(this,p).y=0}clearDocumentState(){a(this,k,null)}saveScrollState(){e(this,H).documentElement.hasAttribute("data-no-scroll-restoration")?(e(this,p).x=0,e(this,p).y=0):(e(this,p).x=e(this,C).scrollElement.scrollLeft,e(this,p).y=e(this,C).scrollElement.scrollTop)}saveDocumentState(){e(this,H).documentElement.hasAttribute("data-no-page-restoration")?a(this,k,null):a(this,k,document.cloneNode(!0))}restoreScrollPosition(){e(this,C).scrollElement.scroll({top:e(this,p).y,left:e(this,p).x})}}C=new WeakMap,z=new WeakMap,p=new WeakMap,H=new WeakMap,k=new WeakMap,w=new WeakMap;var b,j,v,U,P,f,B,x,N,F,I,D,c,tt,et,st,yt,it,nt,ot,X;class Ht{constructor(t){r(this,c);r(this,b);r(this,j,null);r(this,v,[]);r(this,U,new DOMParser);r(this,P);r(this,f,null);r(this,B);r(this,x,[]);r(this,N,!1);r(this,F,null);r(this,I,new Map);r(this,D,null);r(this,X,t=>M(this,null,function*(){var s;(s=t.state)!=null&&s.path&&(a(this,N,!0),yield this.navigate(t.state.path,{historyAction:"none"}),a(this,N,!1))}));a(this,b,{base:Q.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"}),a(this,j,d(this,c,st).call(this,document.body));const s=this.normalizePath(location.pathname+location.hash);a(this,f,s.pathname),e(this,I).set(e(this,f),new vt(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,X)),Q.changeHistory({action:"replace",pathname:e(this,f),searchParameters:s.parameters,hash:s.hash}),a(this,D,new St),d(this,c,ot).call(this)}get currentPathname(){return e(this,f)}get previousPathname(){return e(this,B)}get links(){return e(this,v)}get scrollElement(){return e(this,F)}normalizePath(t){return Q.splitPath(t,{base:e(this,b).base,trailingSlash:e(this,b).trailingSlash})}prefetch(t){return M(this,null,function*(){const s=this.normalizePath(t);d(this,c,et).call(this,s.pathname)})}navigate(V){return M(this,arguments,function*(t,{historyAction:s="push",centerScroll:o,offsetScroll:u,revalidate:m}={}){if(e(this,x).length)return;const A=this.normalizePath(t);let{pathname:l,hash:g,parameters:Lt,leaf:wt}=A;if(!(e(this,P)===l||e(this,f)===l)){a(this,P,l);try{let K=!0;if(this.preprocessor)try{yield new Promise((n,y)=>{var L;(L=this.preprocessor)==null||L.call(this,{pathname:l,resolve:n,reject:y})})}catch(n){n?console.error(n):console.log("Route change canceled"),K=!1}if(!K||e(this,P)!==l)return;const rt=yield d(this,c,tt).call(this,e(this,f)),S=yield d(this,c,tt).call(this,l,m);if(e(this,P)!==l)return;rt.saveScrollState(),rt.saveDocumentState(),e(this,N)||(S.clearScrollState(),S.clearDocumentState()),S.cloneDocument(),e(this,D).textContent=S.title,document.body.appendChild(e(this,D));const at={pathname:l};J.dispatchEvent(document,"morphStart",{detail:at});const lt=Array.from(document.head.children),ct=Array.from(S.document.head.children),ht=d(this,c,yt).call(this,lt,ct),bt=d(this,c,it).call(this,lt,ht),Y=d(this,c,it).call(this,ct,ht);Y.forEach((n,y)=>{if(n.tagName==="SCRIPT"&&n.getAttribute("src")){const L=document.createElement("script");L.type="module",L.src=n.getAttribute("src"),Y[y]=L}}),Y.forEach(n=>{document.head.appendChild(n)});const Z=Y.filter(n=>{if(n.hasAttribute("data-no-waiting"))return!1;if(d(this,c,nt).call(this,n))return!0});e(this,b).waitForHeadToLoad&&Z.length&&(yield new Promise(n=>M(this,null,function*(){let y=0;try{for(var L=Et(Z),dt,O,mt;dt=!(O=yield L.next()).done;dt=!1){const _=O.value;_.onload=()=>{y++,y===Z.length&&n()}}}catch(O){mt=[O]}finally{try{dt&&(O=L.return)&&(yield O.call(L))}finally{if(mt)throw mt[0]}}})));const ut=[];bt.forEach(n=>{n.hasAttribute("data-permanent")||(d(this,c,nt).call(this,n)?ut.push(n):n.remove())});const Pt=d(this,c,st).call(this,S.document.body);if(e(this,j).forEach((n,y)=>{const L=Pt[y],dt=getComputedStyle(n).getPropertyValue("--morph-duration"),O=[...L.childNodes];if(dt){const mt=[...n.childNodes];mt.forEach(E=>{E instanceof HTMLElement&&E.classList.add("old")}),O.forEach(E=>{E instanceof HTMLElement&&E.classList.add("new")}),n.prepend(...O),Mt.requestIdleCallback(()=>{O.forEach(E=>{E instanceof HTMLElement&&E.classList.add("in")})});const _={morphElement:n,pathname:l};J.dispatchEvent(document,"morphNewChildrenAdded",{detail:_});const At=new Promise(E=>{setTimeout(()=>{mt.forEach(G=>G.remove()),O.forEach(G=>{G instanceof HTMLElement&&G.classList.remove("in","new")}),J.dispatchEvent(document,"morphOldChildrenRemoved",{detail:_}),E()},(parseFloat(dt)||0)*1e3+10)});e(this,x).push(At)}else n.innerHTML="",n.append(...O)}),d(this,c,ot).call(this),g){S.clearScrollState();const n=document.getElementById(g);n instanceof HTMLElement&&Tt.scrollToElement(n,{scrollElement:e(this,F),behaviour:"instant",center:o,offset:u})}else e(this,N)&&S.restoreScrollPosition();yield Promise.all(e(this,x)),ut.forEach(n=>n.remove()),a(this,B,e(this,f)),a(this,f,l),a(this,x,[]),this.findLinks(),document.documentElement.setAttribute("data-current-pathname",l),document.documentElement.setAttribute("data-current-leaf",wt),e(this,D).remove(),Q.changeHistory({action:s,pathname:l,searchParameters:Lt,hash:g}),J.dispatchEvent(document,"morphComplete",{detail:at})}catch(K){console.error(K)}a(this,P,void 0)}})}addLink(t){e(this,v).push(new gt(t,this))}addLinks(t){t.forEach(s=>{this.addLink(s)})}removeLink(t){a(this,v,e(this,v).filter(s=>s.element===t?(s.destroy(),!1):!0))}findLinks(){const t=[...document.documentElement.querySelectorAll("a")].filter(s=>{var o;return((o=s.getAttribute("href"))==null?void 0:o.startsWith("/"))&&!s.hasAttribute("download")&&!s.hasAttribute("data-morph-skip")&&!s.closest("[data-morph-skip]")});e(this,v).forEach(s=>s.destroy()),a(this,v,t.map(s=>new gt(s,this)))}}b=new WeakMap,j=new WeakMap,v=new WeakMap,U=new WeakMap,P=new WeakMap,f=new WeakMap,B=new WeakMap,x=new WeakMap,N=new WeakMap,F=new WeakMap,I=new WeakMap,D=new WeakMap,c=new WeakSet,tt=function(t,s=!1){return M(this,null,function*(){let o=e(this,I).get(t);return(!o||s)&&(o=yield d(this,c,et).call(this,t)),o})},et=function(t){return M(this,null,function*(){const o=yield(yield fetch(t)).text(),u=e(this,U).parseFromString(o,"text/html"),m=new vt(this,t,u);return e(this,I).set(t,m),m})},st=function(t){const s=[...t.querySelectorAll("[data-morph]")];return s.length?s:[t]},yt=function(t,s){return t.filter(o=>s.find(u=>u.outerHTML===o.outerHTML))},it=function(t,s){return t.filter(o=>!s.find(u=>u.outerHTML===o.outerHTML))},nt=function(t){return t.tagName==="SCRIPT"||t.tagName==="STYLE"||t.tagName==="LINK"&&t.getAttribute("rel")==="stylesheet"},ot=function(){a(this,F,document.querySelector(e(this,b).scrollSelector)||document.documentElement)},X=new WeakMap;exports.Morph=Ht;
|
|
1
|
+
"use strict";var ft=(i,t)=>(t=Symbol[i])?t:Symbol.for("Symbol."+i),pt=i=>{throw TypeError(i)};var $=(i,t,s)=>t.has(i)||pt("Cannot "+s);var e=(i,t,s)=>($(i,t,"read from private field"),s?s.call(i):t.get(i)),o=(i,t,s)=>t.has(i)?pt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,s),a=(i,t,s,r)=>($(i,t,"write to private field"),r?r.call(i,s):t.set(i,s),s),d=(i,t,s)=>($(i,t,"access private method"),s);var M=(i,t,s)=>new Promise((r,u)=>{var m=l=>{try{A(s.next(l))}catch(g){u(g)}},V=l=>{try{A(s.throw(l))}catch(g){u(g)}},A=l=>l.done?r(l.value):Promise.resolve(l.value).then(m,V);A((s=s.apply(i,t)).next())});var Et=(i,t,s)=>(t=i[ft("asyncIterator")])?t.call(i):(i=i[ft("iterator")](),t={},s=(r,u)=>(u=i[r])&&(t[r]=m=>new Promise((V,A,l)=>(m=u.call(i,m),l=m.done,Promise.resolve(m.value).then(g=>V({value:g,done:l}),A)))),s("next"),s("return"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const St=require("../index-Cqw2NKev.cjs"),J=require("../events-KVanG9sR.cjs"),Tt=require("../polyfills-Df4r-ETT.cjs"),Ct=require("../scroll-DPDSZypW.cjs"),Q=require("../url-CLvdjbII.cjs"),Ht=require("../css-value-parser/index.cjs");class yt 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,r]of Object.entries(t))this.setAttribute(s,r)}}St.isBrowser&&!customElements.get("morph-announcer")&&customElements.define("morph-announcer",yt);var R,h,T,O,q;class gt{constructor(t,s){o(this,R);o(this,h);o(this,T);o(this,O,t=>{t.preventDefault();const s=e(this,h).getAttribute("data-history-action")||"push",r=e(this,h).hasAttribute("data-center-scroll"),u=getComputedStyle(e(this,h)).getPropertyValue("--offset-scroll").trim(),m=u?Ht.cssValueParser.parse(u):void 0,V=e(this,h).hasAttribute("data-revalidate");e(this,R).navigate(e(this,T),{historyAction:s,centerScroll:r,offsetScroll:m,revalidate:V})});o(this,q,()=>{e(this,R).prefetch(e(this,T)),e(this,h).removeEventListener("pointerenter",e(this,q))});a(this,R,s),a(this,h,t),a(this,T,e(this,h).getAttribute("href")||"/"),e(this,h).addEventListener("click",e(this,O));const r=s.normalizePath(e(this,T)),u=s.normalizePath(location.pathname);e(this,h).hasAttribute("data-include")&&u.pathname.includes(r.pathname)?e(this,h).classList.add("current"):r.pathname===u.pathname&&e(this,h).classList.add("current"),e(this,h).hasAttribute("data-prefetch")&&e(this,h).addEventListener("pointerenter",e(this,q))}get element(){return e(this,h)}destroy(){e(this,h).removeEventListener("click",e(this,O)),e(this,h).removeEventListener("pointerenter",e(this,q)),e(this,h).classList.remove("current")}}R=new WeakMap,h=new WeakMap,T=new WeakMap,O=new WeakMap,q=new WeakMap;var C,z,p,H,k,w;class vt{constructor(t,s,r){o(this,C);o(this,z);o(this,p,{x:0,y:0});o(this,H);o(this,k,null);o(this,w,null);a(this,C,t),a(this,z,s),a(this,H,r.cloneNode(!0))}get pathname(){return e(this,z)}get scrollState(){return e(this,p)}get document(){return e(this,w)}cloneDocument(){a(this,w,(e(this,k)||e(this,H)).cloneNode(!0))}get title(){let t="";if(e(this,w).title)t=e(this,w).title;else{const s=e(this,w).querySelector("h1");t=(s==null?void 0:s.innerText)||(s==null?void 0:s.textContent)||e(this,z)}return t}clearScrollState(){e(this,p).x=0,e(this,p).y=0}clearDocumentState(){a(this,k,null)}saveScrollState(){e(this,H).documentElement.hasAttribute("data-no-scroll-restoration")?(e(this,p).x=0,e(this,p).y=0):(e(this,p).x=e(this,C).scrollElement.scrollLeft,e(this,p).y=e(this,C).scrollElement.scrollTop)}saveDocumentState(){e(this,H).documentElement.hasAttribute("data-no-page-restoration")?a(this,k,null):a(this,k,document.cloneNode(!0))}restoreScrollPosition(){e(this,C).scrollElement.scroll({top:e(this,p).y,left:e(this,p).x})}}C=new WeakMap,z=new WeakMap,p=new WeakMap,H=new WeakMap,k=new WeakMap,w=new WeakMap;var b,W,v,U,P,f,j,x,N,F,I,D,c,tt,et,st,Lt,it,nt,rt,X;class kt{constructor(t){o(this,c);o(this,b,null);o(this,W,null);o(this,v,[]);o(this,U,new DOMParser);o(this,P);o(this,f,null);o(this,j);o(this,x,[]);o(this,N,!1);o(this,F,null);o(this,I,new Map);o(this,D,null);o(this,X,t=>M(this,null,function*(){var s;(s=t.state)!=null&&s.path&&(a(this,N,!0),yield this.navigate(t.state.path,{historyAction:"none"}),a(this,N,!1))}));if(St.isBrowser){a(this,b,{base:Q.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"}),a(this,W,d(this,c,st).call(this,document.body));const s=this.normalizePath(location.pathname+location.hash);a(this,f,s.pathname),e(this,I).set(e(this,f),new vt(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,X)),Q.changeHistory({action:"replace",pathname:e(this,f),searchParameters:s.parameters,hash:s.hash}),a(this,D,new yt),d(this,c,rt).call(this)}}get currentPathname(){return e(this,f)}get previousPathname(){return e(this,j)}get links(){return e(this,v)}get scrollElement(){return e(this,F)}normalizePath(t){return Q.splitPath(t,{base:e(this,b).base,trailingSlash:e(this,b).trailingSlash})}prefetch(t){return M(this,null,function*(){const s=this.normalizePath(t);d(this,c,et).call(this,s.pathname)})}navigate(V){return M(this,arguments,function*(t,{historyAction:s="push",centerScroll:r,offsetScroll:u,revalidate:m}={}){if(e(this,x).length)return;const A=this.normalizePath(t);let{pathname:l,hash:g,parameters:wt,leaf:bt}=A;if(!(e(this,P)===l||e(this,f)===l)){a(this,P,l);try{let _=!0;if(this.preprocessor)try{yield new Promise((n,y)=>{var L;(L=this.preprocessor)==null||L.call(this,{pathname:l,resolve:n,reject:y})})}catch(n){n?console.error(n):console.log("Route change canceled"),_=!1}if(!_||e(this,P)!==l)return;const ot=yield d(this,c,tt).call(this,e(this,f)),S=yield d(this,c,tt).call(this,l,m);if(e(this,P)!==l)return;ot.saveScrollState(),ot.saveDocumentState(),e(this,N)||(S.clearScrollState(),S.clearDocumentState()),S.cloneDocument(),e(this,D).textContent=S.title,document.body.appendChild(e(this,D));const at={pathname:l};J.dispatchEvent(document,"morphStart",{detail:at});const lt=Array.from(document.head.children),ct=Array.from(S.document.head.children),ht=d(this,c,Lt).call(this,lt,ct),Pt=d(this,c,it).call(this,lt,ht),K=d(this,c,it).call(this,ct,ht);K.forEach((n,y)=>{if(n.tagName==="SCRIPT"&&n.getAttribute("src")){const L=document.createElement("script");L.type="module",L.src=n.getAttribute("src"),K[y]=L}}),K.forEach(n=>{document.head.appendChild(n)});const Z=K.filter(n=>{if(n.hasAttribute("data-no-waiting"))return!1;if(d(this,c,nt).call(this,n))return!0});e(this,b).waitForHeadToLoad&&Z.length&&(yield new Promise(n=>M(this,null,function*(){let y=0;try{for(var L=Et(Z),dt,B,mt;dt=!(B=yield L.next()).done;dt=!1){const Y=B.value;Y.onload=()=>{y++,y===Z.length&&n()}}}catch(B){mt=[B]}finally{try{dt&&(B=L.return)&&(yield B.call(L))}finally{if(mt)throw mt[0]}}})));const ut=[];Pt.forEach(n=>{n.hasAttribute("data-permanent")||(d(this,c,nt).call(this,n)?ut.push(n):n.remove())});const At=d(this,c,st).call(this,S.document.body);if(e(this,W).forEach((n,y)=>{const L=At[y],dt=getComputedStyle(n).getPropertyValue("--morph-duration"),B=[...L.childNodes];if(dt){const mt=[...n.childNodes];mt.forEach(E=>{E instanceof HTMLElement&&E.classList.add("old")}),B.forEach(E=>{E instanceof HTMLElement&&E.classList.add("new")}),n.prepend(...B),Tt.requestIdleCallback(()=>{B.forEach(E=>{E instanceof HTMLElement&&E.classList.add("in")})});const Y={morphElement:n,pathname:l};J.dispatchEvent(document,"morphNewChildrenAdded",{detail:Y});const Mt=new Promise(E=>{setTimeout(()=>{mt.forEach(G=>G.remove()),B.forEach(G=>{G instanceof HTMLElement&&G.classList.remove("in","new")}),J.dispatchEvent(document,"morphOldChildrenRemoved",{detail:Y}),E()},(parseFloat(dt)||0)*1e3+10)});e(this,x).push(Mt)}else n.innerHTML="",n.append(...B)}),d(this,c,rt).call(this),g){S.clearScrollState();const n=document.getElementById(g);n instanceof HTMLElement&&Ct.scrollToElement(n,{scrollElement:e(this,F),behaviour:"instant",center:r,offset:u})}else e(this,N)&&S.restoreScrollPosition();yield Promise.all(e(this,x)),ut.forEach(n=>n.remove()),a(this,j,e(this,f)),a(this,f,l),a(this,x,[]),this.findLinks(),document.documentElement.setAttribute("data-current-pathname",l),document.documentElement.setAttribute("data-current-leaf",bt),e(this,D).remove(),Q.changeHistory({action:s,pathname:l,searchParameters:wt,hash:g}),J.dispatchEvent(document,"morphComplete",{detail:at})}catch(_){console.error(_)}a(this,P,void 0)}})}addLink(t){e(this,v).push(new gt(t,this))}addLinks(t){t.forEach(s=>{this.addLink(s)})}removeLink(t){a(this,v,e(this,v).filter(s=>s.element===t?(s.destroy(),!1):!0))}findLinks(){const t=[...document.documentElement.querySelectorAll("a")].filter(s=>{var r;return((r=s.getAttribute("href"))==null?void 0:r.startsWith("/"))&&!s.hasAttribute("download")&&!s.hasAttribute("data-morph-skip")&&!s.closest("[data-morph-skip]")});e(this,v).forEach(s=>s.destroy()),a(this,v,t.map(s=>new gt(s,this)))}}b=new WeakMap,W=new WeakMap,v=new WeakMap,U=new WeakMap,P=new WeakMap,f=new WeakMap,j=new WeakMap,x=new WeakMap,N=new WeakMap,F=new WeakMap,I=new WeakMap,D=new WeakMap,c=new WeakSet,tt=function(t,s=!1){return M(this,null,function*(){let r=e(this,I).get(t);return(!r||s)&&(r=yield d(this,c,et).call(this,t)),r})},et=function(t){return M(this,null,function*(){const r=yield(yield fetch(t)).text(),u=e(this,U).parseFromString(r,"text/html"),m=new vt(this,t,u);return e(this,I).set(t,m),m})},st=function(t){const s=[...t.querySelectorAll("[data-morph]")];return s.length?s:[t]},Lt=function(t,s){return t.filter(r=>s.find(u=>u.outerHTML===r.outerHTML))},it=function(t,s){return t.filter(r=>!s.find(u=>u.outerHTML===r.outerHTML))},nt=function(t){return t.tagName==="SCRIPT"||t.tagName==="STYLE"||t.tagName==="LINK"&&t.getAttribute("rel")==="stylesheet"},rt=function(){a(this,F,document.querySelector(e(this,b).scrollSelector)||document.documentElement)},X=new WeakMap;exports.Morph=kt;
|
package/lib/morph/index.js
CHANGED
|
@@ -20,13 +20,13 @@ var M = (i, t, s) => new Promise((o, u) => {
|
|
|
20
20
|
A((s = s.apply(i, t)).next());
|
|
21
21
|
});
|
|
22
22
|
var pt = (i, t, s) => (t = i[mt("asyncIterator")]) ? t.call(i) : (i = i[mt("iterator")](), t = {}, s = (o, u) => (u = i[o]) && (t[o] = (m) => new Promise((V, A, l) => (m = u.call(i, m), l = m.done, Promise.resolve(m.value).then((g) => V({ value: g, done: l }), A)))), s("next"), s("return"), t);
|
|
23
|
+
import { i as St } from "../index-euf5anj6.js";
|
|
23
24
|
import { d as Q } from "../events-CsVF98U6.js";
|
|
24
|
-
import { r as
|
|
25
|
-
import { s as
|
|
26
|
-
import "../
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
class St extends HTMLElement {
|
|
25
|
+
import { r as Tt } from "../polyfills-DJrTJQky.js";
|
|
26
|
+
import { s as Ct } from "../scroll-DNUlcfbO.js";
|
|
27
|
+
import { n as Ht, c as Et, s as kt } from "../url-CfcHdBT6.js";
|
|
28
|
+
import { cssValueParser as xt } from "../css-value-parser/index.js";
|
|
29
|
+
class vt extends HTMLElement {
|
|
30
30
|
connectedCallback() {
|
|
31
31
|
const t = {
|
|
32
32
|
"aria-live": "assertive",
|
|
@@ -37,18 +37,18 @@ class St extends HTMLElement {
|
|
|
37
37
|
this.setAttribute(s, o);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
customElements.get("morph-announcer")
|
|
41
|
-
var R, c, T,
|
|
40
|
+
St && !customElements.get("morph-announcer") && customElements.define("morph-announcer", vt);
|
|
41
|
+
var R, c, T, O, z;
|
|
42
42
|
class gt {
|
|
43
43
|
constructor(t, s) {
|
|
44
44
|
r(this, R);
|
|
45
45
|
r(this, c);
|
|
46
46
|
r(this, T);
|
|
47
|
-
r(this,
|
|
47
|
+
r(this, O, (t) => {
|
|
48
48
|
t.preventDefault();
|
|
49
49
|
const s = e(this, c).getAttribute(
|
|
50
50
|
"data-history-action"
|
|
51
|
-
) || "push", o = e(this, c).hasAttribute("data-center-scroll"), u = getComputedStyle(e(this, c)).getPropertyValue("--offset-scroll").trim(), m = u ?
|
|
51
|
+
) || "push", o = e(this, c).hasAttribute("data-center-scroll"), u = getComputedStyle(e(this, c)).getPropertyValue("--offset-scroll").trim(), m = u ? xt.parse(u) : void 0, V = e(this, c).hasAttribute("data-revalidate");
|
|
52
52
|
e(this, R).navigate(e(this, T), {
|
|
53
53
|
historyAction: s,
|
|
54
54
|
centerScroll: o,
|
|
@@ -59,7 +59,7 @@ class gt {
|
|
|
59
59
|
r(this, z, () => {
|
|
60
60
|
e(this, R).prefetch(e(this, T)), e(this, c).removeEventListener("pointerenter", e(this, z));
|
|
61
61
|
});
|
|
62
|
-
a(this, R, s), a(this, c, t), a(this, T, e(this, c).getAttribute("href") || "/"), e(this, c).addEventListener("click", e(this,
|
|
62
|
+
a(this, R, s), a(this, c, t), a(this, T, e(this, c).getAttribute("href") || "/"), e(this, c).addEventListener("click", e(this, O));
|
|
63
63
|
const o = s.normalizePath(e(this, T)), u = s.normalizePath(location.pathname);
|
|
64
64
|
e(this, c).hasAttribute("data-include") && u.pathname.includes(o.pathname) ? e(this, c).classList.add("current") : o.pathname === u.pathname && e(this, c).classList.add("current"), e(this, c).hasAttribute("data-prefetch") && e(this, c).addEventListener("pointerenter", e(this, z));
|
|
65
65
|
}
|
|
@@ -67,10 +67,10 @@ class gt {
|
|
|
67
67
|
return e(this, c);
|
|
68
68
|
}
|
|
69
69
|
destroy() {
|
|
70
|
-
e(this, c).removeEventListener("click", e(this,
|
|
70
|
+
e(this, c).removeEventListener("click", e(this, O)), e(this, c).removeEventListener("pointerenter", e(this, z)), e(this, c).classList.remove("current");
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
R = new WeakMap(), c = new WeakMap(), T = new WeakMap(),
|
|
73
|
+
R = new WeakMap(), c = new WeakMap(), T = new WeakMap(), O = new WeakMap(), z = new WeakMap();
|
|
74
74
|
var C, q, p, H, k, w;
|
|
75
75
|
class Lt {
|
|
76
76
|
constructor(t, s, o) {
|
|
@@ -128,12 +128,12 @@ class Lt {
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
C = new WeakMap(), q = new WeakMap(), p = new WeakMap(), H = new WeakMap(), k = new WeakMap(), w = new WeakMap();
|
|
131
|
-
var b,
|
|
132
|
-
class
|
|
131
|
+
var b, W, L, U, P, f, j, x, N, F, I, D, h, $, tt, et, yt, st, it, nt, X;
|
|
132
|
+
class Vt {
|
|
133
133
|
constructor(t) {
|
|
134
134
|
r(this, h);
|
|
135
|
-
r(this, b);
|
|
136
|
-
r(this,
|
|
135
|
+
r(this, b, null);
|
|
136
|
+
r(this, W, null);
|
|
137
137
|
r(this, L, []);
|
|
138
138
|
r(this, U, new DOMParser());
|
|
139
139
|
r(this, P);
|
|
@@ -148,29 +148,33 @@ class It {
|
|
|
148
148
|
var s;
|
|
149
149
|
(s = t.state) != null && s.path && (a(this, N, !0), yield this.navigate(t.state.path, { historyAction: "none" }), a(this, N, !1));
|
|
150
150
|
}));
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
151
|
+
if (St) {
|
|
152
|
+
a(this, b, {
|
|
153
|
+
base: Ht(t == null ? void 0 : t.base),
|
|
154
|
+
waitForHeadToLoad: (t == null ? void 0 : t.waitForHeadToLoad) !== !1,
|
|
155
|
+
cachePages: (t == null ? void 0 : t.cachePages) !== !1,
|
|
156
|
+
trailingSlash: (t == null ? void 0 : t.trailingSlash) || !1,
|
|
157
|
+
scrollSelector: (t == null ? void 0 : t.scrollSelector) || "body"
|
|
158
|
+
}), a(this, W, d(this, h, et).call(this, document.body));
|
|
159
|
+
const s = this.normalizePath(
|
|
160
|
+
location.pathname + location.hash
|
|
161
|
+
);
|
|
162
|
+
a(this, f, s.pathname), e(this, I).set(
|
|
163
|
+
e(this, f),
|
|
164
|
+
new Lt(this, e(this, f), document)
|
|
165
|
+
), document.documentElement.setAttribute(
|
|
166
|
+
"data-current-pathname",
|
|
167
|
+
e(this, f)
|
|
168
|
+
), document.documentElement.setAttribute(
|
|
169
|
+
"data-current-leaf",
|
|
170
|
+
s.leaf
|
|
171
|
+
), this.findLinks(), addEventListener("popstate", e(this, X)), Et({
|
|
172
|
+
action: "replace",
|
|
173
|
+
pathname: e(this, f),
|
|
174
|
+
searchParameters: s.parameters,
|
|
175
|
+
hash: s.hash
|
|
176
|
+
}), a(this, D, new vt()), d(this, h, nt).call(this);
|
|
177
|
+
}
|
|
174
178
|
}
|
|
175
179
|
get currentPathname() {
|
|
176
180
|
return e(this, f);
|
|
@@ -185,7 +189,7 @@ class It {
|
|
|
185
189
|
return e(this, F);
|
|
186
190
|
}
|
|
187
191
|
normalizePath(t) {
|
|
188
|
-
return
|
|
192
|
+
return kt(t, {
|
|
189
193
|
base: e(this, b).base,
|
|
190
194
|
trailingSlash: e(this, b).trailingSlash
|
|
191
195
|
});
|
|
@@ -206,7 +210,7 @@ class It {
|
|
|
206
210
|
if (e(this, x).length)
|
|
207
211
|
return;
|
|
208
212
|
const A = this.normalizePath(t);
|
|
209
|
-
let { pathname: l, hash: g, parameters:
|
|
213
|
+
let { pathname: l, hash: g, parameters: wt, leaf: bt } = A;
|
|
210
214
|
if (!(e(this, P) === l || e(this, f) === l)) {
|
|
211
215
|
a(this, P, l);
|
|
212
216
|
try {
|
|
@@ -236,7 +240,7 @@ class It {
|
|
|
236
240
|
Q(document, "morphStart", {
|
|
237
241
|
detail: rt
|
|
238
242
|
});
|
|
239
|
-
const at = Array.from(document.head.children), lt = Array.from(S.document.head.children), ht = d(this, h,
|
|
243
|
+
const at = Array.from(document.head.children), lt = Array.from(S.document.head.children), ht = d(this, h, yt).call(this, at, lt), Pt = d(this, h, st).call(this, at, ht), Y = d(this, h, st).call(this, lt, ht);
|
|
240
244
|
Y.forEach((n, v) => {
|
|
241
245
|
if (n.tagName === "SCRIPT" && n.getAttribute("src")) {
|
|
242
246
|
const y = document.createElement("script");
|
|
@@ -254,17 +258,17 @@ class It {
|
|
|
254
258
|
e(this, b).waitForHeadToLoad && Z.length && (yield new Promise((n) => M(this, null, function* () {
|
|
255
259
|
let v = 0;
|
|
256
260
|
try {
|
|
257
|
-
for (var y = pt(Z), ut,
|
|
258
|
-
const G =
|
|
261
|
+
for (var y = pt(Z), ut, B, dt; ut = !(B = yield y.next()).done; ut = !1) {
|
|
262
|
+
const G = B.value;
|
|
259
263
|
G.onload = () => {
|
|
260
264
|
v++, v === Z.length && n();
|
|
261
265
|
};
|
|
262
266
|
}
|
|
263
|
-
} catch (
|
|
264
|
-
dt = [
|
|
267
|
+
} catch (B) {
|
|
268
|
+
dt = [B];
|
|
265
269
|
} finally {
|
|
266
270
|
try {
|
|
267
|
-
ut && (
|
|
271
|
+
ut && (B = y.return) && (yield B.call(y));
|
|
268
272
|
} finally {
|
|
269
273
|
if (dt)
|
|
270
274
|
throw dt[0];
|
|
@@ -272,20 +276,20 @@ class It {
|
|
|
272
276
|
}
|
|
273
277
|
})));
|
|
274
278
|
const ct = [];
|
|
275
|
-
|
|
279
|
+
Pt.forEach((n) => {
|
|
276
280
|
n.hasAttribute("data-permanent") || (d(this, h, it).call(this, n) ? ct.push(n) : n.remove());
|
|
277
281
|
});
|
|
278
|
-
const
|
|
279
|
-
if (e(this,
|
|
280
|
-
const y =
|
|
282
|
+
const At = d(this, h, et).call(this, S.document.body);
|
|
283
|
+
if (e(this, W).forEach((n, v) => {
|
|
284
|
+
const y = At[v], ut = getComputedStyle(n).getPropertyValue("--morph-duration"), B = [...y.childNodes];
|
|
281
285
|
if (ut) {
|
|
282
286
|
const dt = [...n.childNodes];
|
|
283
287
|
dt.forEach((E) => {
|
|
284
288
|
E instanceof HTMLElement && E.classList.add("old");
|
|
285
|
-
}),
|
|
289
|
+
}), B.forEach((E) => {
|
|
286
290
|
E instanceof HTMLElement && E.classList.add("new");
|
|
287
|
-
}), n.prepend(...
|
|
288
|
-
|
|
291
|
+
}), n.prepend(...B), Tt(() => {
|
|
292
|
+
B.forEach((E) => {
|
|
289
293
|
E instanceof HTMLElement && E.classList.add("in");
|
|
290
294
|
});
|
|
291
295
|
});
|
|
@@ -296,32 +300,32 @@ class It {
|
|
|
296
300
|
Q(document, "morphNewChildrenAdded", {
|
|
297
301
|
detail: G
|
|
298
302
|
});
|
|
299
|
-
const
|
|
303
|
+
const Mt = new Promise((E) => {
|
|
300
304
|
setTimeout(() => {
|
|
301
|
-
dt.forEach((J) => J.remove()),
|
|
305
|
+
dt.forEach((J) => J.remove()), B.forEach((J) => {
|
|
302
306
|
J instanceof HTMLElement && J.classList.remove("in", "new");
|
|
303
307
|
}), Q(document, "morphOldChildrenRemoved", {
|
|
304
308
|
detail: G
|
|
305
309
|
}), E();
|
|
306
310
|
}, (parseFloat(ut) || 0) * 1e3 + 10);
|
|
307
311
|
});
|
|
308
|
-
e(this, x).push(
|
|
312
|
+
e(this, x).push(Mt);
|
|
309
313
|
} else
|
|
310
|
-
n.innerHTML = "", n.append(...
|
|
314
|
+
n.innerHTML = "", n.append(...B);
|
|
311
315
|
}), d(this, h, nt).call(this), g) {
|
|
312
316
|
S.clearScrollState();
|
|
313
317
|
const n = document.getElementById(g);
|
|
314
|
-
n instanceof HTMLElement &&
|
|
318
|
+
n instanceof HTMLElement && Ct(n, {
|
|
315
319
|
scrollElement: e(this, F),
|
|
316
320
|
behaviour: "instant",
|
|
317
321
|
center: o,
|
|
318
322
|
offset: u
|
|
319
323
|
});
|
|
320
324
|
} else e(this, N) && S.restoreScrollPosition();
|
|
321
|
-
yield Promise.all(e(this, x)), ct.forEach((n) => n.remove()), a(this, j, e(this, f)), a(this, f, l), a(this, x, []), this.findLinks(), document.documentElement.setAttribute("data-current-pathname", l), document.documentElement.setAttribute("data-current-leaf",
|
|
325
|
+
yield Promise.all(e(this, x)), ct.forEach((n) => n.remove()), a(this, j, e(this, f)), a(this, f, l), a(this, x, []), this.findLinks(), document.documentElement.setAttribute("data-current-pathname", l), document.documentElement.setAttribute("data-current-leaf", bt), e(this, D).remove(), Et({
|
|
322
326
|
action: s,
|
|
323
327
|
pathname: l,
|
|
324
|
-
searchParameters:
|
|
328
|
+
searchParameters: wt,
|
|
325
329
|
hash: g
|
|
326
330
|
}), Q(document, "morphComplete", {
|
|
327
331
|
detail: rt
|
|
@@ -356,7 +360,7 @@ class It {
|
|
|
356
360
|
e(this, L).forEach((s) => s.destroy()), a(this, L, t.map((s) => new gt(s, this)));
|
|
357
361
|
}
|
|
358
362
|
}
|
|
359
|
-
b = new WeakMap(),
|
|
363
|
+
b = new WeakMap(), W = new WeakMap(), L = new WeakMap(), U = new WeakMap(), P = new WeakMap(), f = new WeakMap(), j = new WeakMap(), x = new WeakMap(), N = new WeakMap(), F = new WeakMap(), I = new WeakMap(), D = new WeakMap(), h = new WeakSet(), $ = function(t, s = !1) {
|
|
360
364
|
return M(this, null, function* () {
|
|
361
365
|
let o = e(this, I).get(t);
|
|
362
366
|
return (!o || s) && (o = yield d(this, h, tt).call(this, t)), o;
|
|
@@ -369,7 +373,7 @@ b = new WeakMap(), B = new WeakMap(), L = new WeakMap(), U = new WeakMap(), P =
|
|
|
369
373
|
}, et = function(t) {
|
|
370
374
|
const s = [...t.querySelectorAll("[data-morph]")];
|
|
371
375
|
return s.length ? s : [t];
|
|
372
|
-
},
|
|
376
|
+
}, yt = function(t, s) {
|
|
373
377
|
return t.filter(
|
|
374
378
|
(o) => s.find(
|
|
375
379
|
(u) => u.outerHTML === o.outerHTML
|
|
@@ -387,5 +391,5 @@ b = new WeakMap(), B = new WeakMap(), L = new WeakMap(), U = new WeakMap(), P =
|
|
|
387
391
|
a(this, F, document.querySelector(e(this, b).scrollSelector) || document.documentElement);
|
|
388
392
|
}, X = new WeakMap();
|
|
389
393
|
export {
|
|
390
|
-
|
|
394
|
+
Vt as Morph
|
|
391
395
|
};
|