aptechka 0.52.0 → 0.52.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 +1 -0
- package/lib/morph/index.cjs +1 -1
- package/lib/morph/index.js +50 -47
- package/package.json +1 -1
package/lib/morph/Morph.d.ts
CHANGED
package/lib/morph/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var vt=(r,t)=>(t=Symbol[r])?t:Symbol.for("Symbol."+r),Lt=r=>{throw TypeError(r)};var et=(r,t,s)=>t.has(r)||Lt("Cannot "+s);var e=(r,t,s)=>(et(r,t,"read from private field"),s?s.call(r):t.get(r)),o=(r,t,s)=>t.has(r)?Lt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,s),a=(r,t,s,i)=>(et(r,t,"write to private field"),i?i.call(r,s):t.set(r,s),s),d=(r,t,s)=>(et(r,t,"access private method"),s);var H=(r,t,s)=>new Promise((i,u)=>{var f=p=>{try{T(s.next(p))}catch(h){u(h)}},M=p=>{try{T(s.throw(p))}catch(h){u(h)}},T=p=>p.done?i(p.value):Promise.resolve(p.value).then(f,M);T((s=s.apply(r,t)).next())});var St=(r,t,s)=>(t=r[vt("asyncIterator")])?t.call(r):(r=r[vt("iterator")](),t={},s=(i,u)=>(u=r[i])&&(t[i]=f=>new Promise((M,T,p)=>(f=u.call(r,f),p=f.done,Promise.resolve(f.value).then(h=>M({value:h,done:p}),T)))),s("next"),s("return"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const bt=require("../index-Cqw2NKev.cjs"),_=require("../events-KVanG9sR.cjs"),xt=require("../polyfills-Df4r-ETT.cjs"),Nt=require("../scroll-H9zqFeML.cjs"),X=require("../url-D1CgmwZ_.cjs"),Dt=require("../css-value-parser/index.cjs");class Pt 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)}}bt.isBrowser&&!customElements.get("morph-announcer")&&customElements.define("morph-announcer",Pt);var b,c,x,j,I;class yt{constructor(t,s){o(this,b);o(this,c);o(this,x);o(this,j,t=>{t.preventDefault();const s=e(this,c).getAttribute("data-history-action")||"push",i=e(this,c).hasAttribute("data-center-scroll"),u=getComputedStyle(e(this,c)).getPropertyValue("--offset-scroll").trim(),f=u?Dt.cssValueParser.parse(u):void 0,M=e(this,c).hasAttribute("data-revalidate"),T=e(this,c).hasAttribute("data-keep-search-parameters");e(this,b).navigate(e(this,x),{historyAction:s,centerScroll:i,offsetScroll:f,revalidate:M,keepSearchParameters:T})});o(this,I,()=>{e(this,b).prefetch(e(this,x)),e(this,c).removeEventListener("pointerenter",e(this,I))});a(this,b,s),a(this,c,t),a(this,x,e(this,c).getAttribute("href")||"/"),e(this,c).addEventListener("click",e(this,j)),this.checkCurrent(location.pathname),e(this,c).hasAttribute("data-prefetch")&&e(this,c).addEventListener("pointerenter",e(this,I))}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,j)),e(this,c).removeEventListener("pointerenter",e(this,I)),e(this,c).classList.remove("current")}}b=new WeakMap,c=new WeakMap,x=new WeakMap,j=new WeakMap,I=new WeakMap;var N,V,E,D,R,P;class wt{constructor(t,s,i){o(this,N);o(this,V);o(this,E,{x:0,y:0});o(this,D);o(this,R,null);o(this,P,null);a(this,N,t),a(this,V,s),a(this,D,i.cloneNode(!0))}get pathname(){return e(this,V)}get scrollState(){return e(this,E)}get document(){return e(this,P)}cloneDocument(){a(this,P,(e(this,R)||e(this,D)).cloneNode(!0))}get title(){let t="";if(e(this,P).title)t=e(this,P).title;else{const s=e(this,P).querySelector("h1");t=(s==null?void 0:s.innerText)||(s==null?void 0:s.textContent)||e(this,V)}return t}clearScrollState(){e(this,E).x=0,e(this,E).y=0}clearDocumentState(){a(this,R,null)}saveScrollState(){e(this,D).documentElement.hasAttribute("data-no-scroll-restoration")?(e(this,E).x=0,e(this,E).y=0):(e(this,E).x=e(this,N).scrollElement.scrollLeft,e(this,E).y=e(this,N).scrollElement.scrollTop)}saveDocumentState(){e(this,D).documentElement.hasAttribute("data-no-page-restoration")?a(this,R,null):a(this,R,document.cloneNode(!0))}restoreScrollPosition(){e(this,N).scrollElement.scroll({top:e(this,E).y,left:e(this,E).x})}}N=new WeakMap,V=new WeakMap,E=new WeakMap,D=new WeakMap,R=new WeakMap,P=new WeakMap;var A,U,g,Z,k,m,K,q,C,L,B,z,l,st,it,rt,At,nt,ot,at,lt,$,O;class Rt{constructor(t){o(this,l);o(this,A,null);o(this,U,null);o(this,g,[]);o(this,Z,new DOMParser);o(this,k);o(this,m,null);o(this,K);o(this,q,[]);o(this,C,!1);o(this,L,null);o(this,B,new Map);o(this,z,null);o(this,$,t=>H(this,null,function*(){var s;(s=t.state)!=null&&s.path&&(t.preventDefault(),a(this,C,!0),yield this.navigate(t.state.path,{historyAction:"none"}),a(this,C,!1))}));o(this,O,()=>{const t=e(this,L).scrollTop,s=e(this,L).scrollLeft;document.documentElement.classList.toggle("top-scrolled",t>0),document.documentElement.classList.toggle("left-scrolled",s>0),_.dispatchEvent(document,"morphScroll",{detail:{left:s,top:t}})});if(bt.isBrowser){a(this,A,{base:X.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,U,d(this,l,rt).call(this,document.body));const s=this.normalizePath(location.pathname+location.hash);a(this,m,s.pathname),e(this,B).set(e(this,m),new wt(this,e(this,m),document)),document.documentElement.setAttribute("data-current-pathname",e(this,m)),document.documentElement.setAttribute("data-current-leaf",s.leaf),this.findLinks(),addEventListener("popstate",e(this,$)),X.changeHistory({action:"replace",pathname:e(this,m),searchParameters:s.parameters||location.search,hash:s.hash}),a(this,z,new Pt),d(this,l,at).call(this,document)}}get currentPathname(){return e(this,m)}get previousPathname(){return e(this,K)}get links(){return e(this,g)}get scrollElement(){return e(this,L)}normalizePath(t){return X.splitPath(t,{base:e(this,A).base,trailingSlash:e(this,A).trailingSlash})}prefetch(t){return H(this,null,function*(){const s=this.normalizePath(t);d(this,l,it).call(this,s.pathname)})}navigate(T){return H(this,arguments,function*(t,{historyAction:s="push",centerScroll:i,offsetScroll:u,revalidate:f,keepSearchParameters:M}={}){var ct;if(e(this,q).length)return;const p=this.normalizePath(((ct=this.pathnameModifier)==null?void 0:ct.call(this,t))||t);let{pathname:h,hash:Y,parameters:kt,leaf:Ct}=p;if(e(this,k)===h||e(this,m)===h){e(this,C)||d(this,l,lt).call(this,Y||0,{centerScroll:i,offsetScroll:u,behavior:"smooth"});return}a(this,k,h),e(this,g).forEach(F=>{F.checkCurrent(h)});try{let F=!0;if(this.preprocessor)try{yield new Promise((n,y)=>{var w;(w=this.preprocessor)==null||w.call(this,{pathname:h,resolve:n,reject:y})})}catch(n){n?console.error(n):console.log("Route change canceled"),F=!1}if(!F||e(this,k)!==h){e(this,g).forEach(n=>{n.checkCurrent(e(this,m))});return}const ht=yield d(this,l,st).call(this,e(this,m)),S=yield d(this,l,st).call(this,h,f);if(e(this,k)!==h){e(this,g).forEach(n=>{n.checkCurrent(e(this,m))});return}ht.saveScrollState(),ht.saveDocumentState(),e(this,C)||(S.clearScrollState(),S.clearDocumentState()),S.cloneDocument(),e(this,z).textContent=S.title,document.body.appendChild(e(this,z));const ut={pathname:h};_.dispatchEvent(document,"morphStart",{detail:ut});const dt=Array.from(document.head.children),mt=Array.from(S.document.head.children),ft=d(this,l,At).call(this,dt,mt),Mt=d(this,l,nt).call(this,dt,ft),G=d(this,l,nt).call(this,mt,ft);G.forEach((n,y)=>{if(n.tagName==="SCRIPT"&&n.getAttribute("src")){const w=document.createElement("script");w.type="module",w.src=n.getAttribute("src"),G[y]=w}}),G.forEach(n=>{document.head.appendChild(n)});const tt=G.filter(n=>{if(n.hasAttribute("data-no-waiting"))return!1;if(d(this,l,ot).call(this,n))return!0});e(this,A).waitForHeadToLoad&&tt.length&&(yield new Promise(n=>H(this,null,function*(){let y=0;try{for(var w=St(tt),Et,W,gt;Et=!(W=yield w.next()).done;Et=!1){const J=W.value;J.onload=()=>{y++,y===tt.length&&n()}}}catch(W){gt=[W]}finally{try{Et&&(W=w.return)&&(yield W.call(w))}finally{if(gt)throw gt[0]}}})));const pt=[];Mt.forEach(n=>{n.hasAttribute("data-permanent")||(d(this,l,ot).call(this,n)?pt.push(n):n.remove())});const Tt=d(this,l,rt).call(this,S.document.body);d(this,l,at).call(this,S.document),document.documentElement.setAttribute("data-current-pathname",h),document.documentElement.setAttribute("data-current-leaf",Ct),X.changeHistory({action:s,pathname:h,searchParameters:kt||(M?location.search:""),hash:Y}),e(this,z).remove(),a(this,K,e(this,m)),a(this,m,h),e(this,U).forEach((n,y)=>{const w=Tt[y],Et=getComputedStyle(n).getPropertyValue("--morph-duration"),W=[...w.childNodes];if(Et){const gt=[...n.childNodes];gt.forEach(v=>{v instanceof HTMLElement&&v.classList.add("old")}),W.forEach(v=>{v instanceof HTMLElement&&v.classList.add("new")}),n.prepend(...W),xt.requestIdleCallback(()=>{W.forEach(v=>{v instanceof HTMLElement&&v.classList.add("in")})});const J={morphElement:n,pathname:h};_.dispatchEvent(document,"morphNewChildrenAdded",{detail:J});const Ht=new Promise(v=>{setTimeout(()=>{gt.forEach(Q=>Q.remove()),W.forEach(Q=>{Q instanceof HTMLElement&&Q.classList.remove("in","new")}),_.dispatchEvent(document,"morphOldChildrenRemoved",{detail:J}),v()},(parseFloat(Et)||0)*1e3+10)});e(this,q).push(Ht)}else n.innerHTML="",n.append(...W)}),Y?(S.clearScrollState(),d(this,l,lt).call(this,Y,{centerScroll:i,offsetScroll:u})):e(this,C)&&S.restoreScrollPosition(),yield Promise.all(e(this,q)),pt.forEach(n=>n.remove()),a(this,q,[]),this.findLinks(),_.dispatchEvent(document,"morphComplete",{detail:ut}),window.dispatchEvent(new Event("resize"))}catch(F){console.error(F)}a(this,k,void 0)})}addLink(t){e(this,g).push(new yt(t,this))}addLinks(t){t.forEach(s=>{this.addLink(s)})}removeLink(t){a(this,g,e(this,g).filter(s=>s.element===t?(s.destroy(),!1):!0))}findLinks(){const t=[...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"});e(this,g).forEach(s=>s.destroy()),a(this,g,t.map(s=>new yt(s,this)))}}A=new WeakMap,U=new WeakMap,g=new WeakMap,Z=new WeakMap,k=new WeakMap,m=new WeakMap,K=new WeakMap,q=new WeakMap,C=new WeakMap,L=new WeakMap,B=new WeakMap,z=new WeakMap,l=new WeakSet,st=function(t,s=!1){return H(this,null,function*(){let i=e(this,B).get(t);return(!i||s)&&(i=yield d(this,l,it).call(this,t)),i})},it=function(t){return H(this,null,function*(){const i=yield(yield fetch(t)).text(),u=e(this,Z).parseFromString(i,"text/html"),f=new wt(this,t,u);return e(this,B).set(t,f),f})},rt=function(t){const s=[...t.querySelectorAll("[data-morph]")];return s.length?s:[t]},At=function(t,s){return t.filter(i=>s.find(u=>u.outerHTML===i.outerHTML))},nt=function(t,s){return t.filter(i=>!s.find(u=>u.outerHTML===i.outerHTML))},ot=function(t){return t.tagName==="SCRIPT"||t.tagName==="STYLE"||t.tagName==="LINK"&&t.getAttribute("rel")==="stylesheet"},at=function(t){var s,i;(s=e(this,L))==null||s.removeEventListener("scroll",e(this,O)),a(this,L,t.querySelector(e(this,A).scrollSelector)||t.documentElement),(i=e(this,L))==null||i.addEventListener("scroll",e(this,O)),e(this,O).call(this)},lt=function(t,s){const i=typeof t=="string"?document.getElementById(t):t;(typeof i=="number"||i)&&Nt.scrollToElement(i,{scrollElement:e(this,L),behavior:(s==null?void 0:s.behavior)||"instant",center:s==null?void 0:s.centerScroll,offset:s==null?void 0:s.offsetScroll})},$=new WeakMap,O=new WeakMap;exports.Morph=Rt;
|
|
1
|
+
"use strict";var vt=(r,t)=>(t=Symbol[r])?t:Symbol.for("Symbol."+r),Lt=r=>{throw TypeError(r)};var et=(r,t,s)=>t.has(r)||Lt("Cannot "+s);var e=(r,t,s)=>(et(r,t,"read from private field"),s?s.call(r):t.get(r)),o=(r,t,s)=>t.has(r)?Lt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,s),a=(r,t,s,i)=>(et(r,t,"write to private field"),i?i.call(r,s):t.set(r,s),s),d=(r,t,s)=>(et(r,t,"access private method"),s);var H=(r,t,s)=>new Promise((i,u)=>{var f=p=>{try{T(s.next(p))}catch(h){u(h)}},M=p=>{try{T(s.throw(p))}catch(h){u(h)}},T=p=>p.done?i(p.value):Promise.resolve(p.value).then(f,M);T((s=s.apply(r,t)).next())});var St=(r,t,s)=>(t=r[vt("asyncIterator")])?t.call(r):(r=r[vt("iterator")](),t={},s=(i,u)=>(u=r[i])&&(t[i]=f=>new Promise((M,T,p)=>(f=u.call(r,f),p=f.done,Promise.resolve(f.value).then(h=>M({value:h,done:p}),T)))),s("next"),s("return"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const bt=require("../index-Cqw2NKev.cjs"),_=require("../events-KVanG9sR.cjs"),xt=require("../polyfills-Df4r-ETT.cjs"),Nt=require("../scroll-H9zqFeML.cjs"),X=require("../url-D1CgmwZ_.cjs"),Dt=require("../css-value-parser/index.cjs");class Pt 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)}}bt.isBrowser&&!customElements.get("morph-announcer")&&customElements.define("morph-announcer",Pt);var P,c,x,j,I;class yt{constructor(t,s){o(this,P);o(this,c);o(this,x);o(this,j,t=>{t.preventDefault();const s=e(this,c).getAttribute("data-history-action")||"push",i=e(this,c).hasAttribute("data-center-scroll"),u=getComputedStyle(e(this,c)).getPropertyValue("--offset-scroll").trim(),f=u?Dt.cssValueParser.parse(u):void 0,M=e(this,c).hasAttribute("data-revalidate"),T=e(this,c).hasAttribute("data-keep-search-parameters");e(this,P).navigate(e(this,x),{historyAction:s,centerScroll:i,offsetScroll:f,revalidate:M,keepSearchParameters:T})});o(this,I,()=>{e(this,P).prefetch(e(this,x)),e(this,c).removeEventListener("pointerenter",e(this,I))});a(this,P,s),a(this,c,t),a(this,x,e(this,c).getAttribute("href")||"/"),e(this,c).addEventListener("click",e(this,j)),this.checkCurrent(location.pathname),e(this,c).hasAttribute("data-prefetch")&&e(this,c).addEventListener("pointerenter",e(this,I))}get element(){return e(this,c)}checkCurrent(t){const s=e(this,P).normalizePath(t),i=e(this,P).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,j)),e(this,c).removeEventListener("pointerenter",e(this,I)),e(this,c).classList.remove("current")}}P=new WeakMap,c=new WeakMap,x=new WeakMap,j=new WeakMap,I=new WeakMap;var N,V,E,D,R,A;class wt{constructor(t,s,i){o(this,N);o(this,V);o(this,E,{x:0,y:0});o(this,D);o(this,R,null);o(this,A,null);a(this,N,t),a(this,V,s),a(this,D,i.cloneNode(!0))}get pathname(){return e(this,V)}get scrollState(){return e(this,E)}get document(){return e(this,A)}cloneDocument(){a(this,A,(e(this,R)||e(this,D)).cloneNode(!0))}get title(){let t="";if(e(this,A).title)t=e(this,A).title;else{const s=e(this,A).querySelector("h1");t=(s==null?void 0:s.innerText)||(s==null?void 0:s.textContent)||e(this,V)}return t}clearScrollState(){e(this,E).x=0,e(this,E).y=0}clearDocumentState(){a(this,R,null)}saveScrollState(){e(this,D).documentElement.hasAttribute("data-no-scroll-restoration")?(e(this,E).x=0,e(this,E).y=0):(e(this,E).x=e(this,N).scrollElement.scrollLeft,e(this,E).y=e(this,N).scrollElement.scrollTop)}saveDocumentState(){e(this,D).documentElement.hasAttribute("data-no-page-restoration")?a(this,R,null):a(this,R,document.cloneNode(!0))}restoreScrollPosition(){e(this,N).scrollElement.scroll({top:e(this,E).y,left:e(this,E).x})}}N=new WeakMap,V=new WeakMap,E=new WeakMap,D=new WeakMap,R=new WeakMap,A=new WeakMap;var k,U,g,Z,C,m,K,q,y,L,B,z,l,st,it,rt,At,nt,ot,at,lt,$,O;class Rt{constructor(t){o(this,l);o(this,k,null);o(this,U,null);o(this,g,[]);o(this,Z,new DOMParser);o(this,C);o(this,m,null);o(this,K);o(this,q,[]);o(this,y,!1);o(this,L,null);o(this,B,new Map);o(this,z,null);o(this,$,t=>H(this,null,function*(){var s;(s=t.state)!=null&&s.path&&(t.preventDefault(),a(this,y,!0),yield this.navigate(t.state.path,{historyAction:"none"}),a(this,y,!1))}));o(this,O,()=>{const t=e(this,L).scrollTop,s=e(this,L).scrollLeft;document.documentElement.classList.toggle("top-scrolled",t>0),document.documentElement.classList.toggle("left-scrolled",s>0),_.dispatchEvent(document,"morphScroll",{detail:{left:s,top:t}})});if(bt.isBrowser){a(this,k,{base:X.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,U,d(this,l,rt).call(this,document.body));const s=this.normalizePath(location.pathname+location.hash);a(this,m,s.pathname),e(this,B).set(e(this,m),new wt(this,e(this,m),document)),document.documentElement.setAttribute("data-current-pathname",e(this,m)),document.documentElement.setAttribute("data-current-leaf",s.leaf),this.findLinks(),addEventListener("popstate",e(this,$)),X.changeHistory({action:"replace",pathname:e(this,m),searchParameters:s.parameters||location.search,hash:s.hash}),a(this,z,new Pt),d(this,l,at).call(this,document)}}get currentPathname(){return e(this,m)}get previousPathname(){return e(this,K)}get links(){return e(this,g)}get scrollElement(){return e(this,L)}get isPopstateNavigation(){return e(this,y)}normalizePath(t){return X.splitPath(t,{base:e(this,k).base,trailingSlash:e(this,k).trailingSlash})}prefetch(t){return H(this,null,function*(){const s=this.normalizePath(t);d(this,l,it).call(this,s.pathname)})}navigate(T){return H(this,arguments,function*(t,{historyAction:s="push",centerScroll:i,offsetScroll:u,revalidate:f,keepSearchParameters:M}={}){var ct;if(e(this,q).length)return;const p=this.normalizePath(((ct=this.pathnameModifier)==null?void 0:ct.call(this,t))||t);let{pathname:h,hash:Y,parameters:kt,leaf:Ct}=p;if(e(this,C)===h||e(this,m)===h){e(this,y)||d(this,l,lt).call(this,Y||0,{centerScroll:i,offsetScroll:u,behavior:"smooth"});return}a(this,C,h),e(this,g).forEach(F=>{F.checkCurrent(h)});try{let F=!0;if(this.preprocessor)try{yield new Promise((n,w)=>{var b;(b=this.preprocessor)==null||b.call(this,{pathname:h,resolve:n,reject:w})})}catch(n){n?console.error(n):console.log("Route change canceled"),F=!1}if(!F||e(this,C)!==h){e(this,g).forEach(n=>{n.checkCurrent(e(this,m))});return}const ht=yield d(this,l,st).call(this,e(this,m)),S=yield d(this,l,st).call(this,h,f);if(e(this,C)!==h){e(this,g).forEach(n=>{n.checkCurrent(e(this,m))});return}ht.saveScrollState(),ht.saveDocumentState(),e(this,y)||(S.clearScrollState(),S.clearDocumentState()),S.cloneDocument(),e(this,z).textContent=S.title,document.body.appendChild(e(this,z));const ut={pathname:h};_.dispatchEvent(document,"morphStart",{detail:ut});const dt=Array.from(document.head.children),mt=Array.from(S.document.head.children),ft=d(this,l,At).call(this,dt,mt),Mt=d(this,l,nt).call(this,dt,ft),G=d(this,l,nt).call(this,mt,ft);G.forEach((n,w)=>{if(n.tagName==="SCRIPT"&&n.getAttribute("src")){const b=document.createElement("script");b.type="module",b.src=n.getAttribute("src"),G[w]=b}}),G.forEach(n=>{document.head.appendChild(n)});const tt=G.filter(n=>{if(n.hasAttribute("data-no-waiting"))return!1;if(d(this,l,ot).call(this,n))return!0});e(this,k).waitForHeadToLoad&&tt.length&&(yield new Promise(n=>H(this,null,function*(){let w=0;try{for(var b=St(tt),Et,W,gt;Et=!(W=yield b.next()).done;Et=!1){const J=W.value;J.onload=()=>{w++,w===tt.length&&n()}}}catch(W){gt=[W]}finally{try{Et&&(W=b.return)&&(yield W.call(b))}finally{if(gt)throw gt[0]}}})));const pt=[];Mt.forEach(n=>{n.hasAttribute("data-permanent")||(d(this,l,ot).call(this,n)?pt.push(n):n.remove())});const Tt=d(this,l,rt).call(this,S.document.body);d(this,l,at).call(this,S.document),document.documentElement.setAttribute("data-current-pathname",h),document.documentElement.setAttribute("data-current-leaf",Ct),X.changeHistory({action:s,pathname:h,searchParameters:kt||(M?location.search:""),hash:Y}),e(this,z).remove(),a(this,K,e(this,m)),a(this,m,h),e(this,U).forEach((n,w)=>{const b=Tt[w],Et=getComputedStyle(n).getPropertyValue("--morph-duration"),W=[...b.childNodes];if(Et){const gt=[...n.childNodes];gt.forEach(v=>{v instanceof HTMLElement&&v.classList.add("old")}),W.forEach(v=>{v instanceof HTMLElement&&v.classList.add("new")}),n.prepend(...W),xt.requestIdleCallback(()=>{W.forEach(v=>{v instanceof HTMLElement&&v.classList.add("in")})});const J={morphElement:n,pathname:h};_.dispatchEvent(document,"morphNewChildrenAdded",{detail:J});const Ht=new Promise(v=>{setTimeout(()=>{gt.forEach(Q=>Q.remove()),W.forEach(Q=>{Q instanceof HTMLElement&&Q.classList.remove("in","new")}),_.dispatchEvent(document,"morphOldChildrenRemoved",{detail:J}),v()},(parseFloat(Et)||0)*1e3+10)});e(this,q).push(Ht)}else n.innerHTML="",n.append(...W)}),Y?(S.clearScrollState(),d(this,l,lt).call(this,Y,{centerScroll:i,offsetScroll:u})):e(this,y)&&S.restoreScrollPosition(),yield Promise.all(e(this,q)),pt.forEach(n=>n.remove()),a(this,q,[]),this.findLinks(),_.dispatchEvent(document,"morphComplete",{detail:ut}),window.dispatchEvent(new Event("resize"))}catch(F){console.error(F)}a(this,C,void 0)})}addLink(t){e(this,g).push(new yt(t,this))}addLinks(t){t.forEach(s=>{this.addLink(s)})}removeLink(t){a(this,g,e(this,g).filter(s=>s.element===t?(s.destroy(),!1):!0))}findLinks(){const t=[...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"});e(this,g).forEach(s=>s.destroy()),a(this,g,t.map(s=>new yt(s,this)))}}k=new WeakMap,U=new WeakMap,g=new WeakMap,Z=new WeakMap,C=new WeakMap,m=new WeakMap,K=new WeakMap,q=new WeakMap,y=new WeakMap,L=new WeakMap,B=new WeakMap,z=new WeakMap,l=new WeakSet,st=function(t,s=!1){return H(this,null,function*(){let i=e(this,B).get(t);return(!i||s)&&(i=yield d(this,l,it).call(this,t)),i})},it=function(t){return H(this,null,function*(){const i=yield(yield fetch(t)).text(),u=e(this,Z).parseFromString(i,"text/html"),f=new wt(this,t,u);return e(this,B).set(t,f),f})},rt=function(t){const s=[...t.querySelectorAll("[data-morph]")];return s.length?s:[t]},At=function(t,s){return t.filter(i=>s.find(u=>u.outerHTML===i.outerHTML))},nt=function(t,s){return t.filter(i=>!s.find(u=>u.outerHTML===i.outerHTML))},ot=function(t){return t.tagName==="SCRIPT"||t.tagName==="STYLE"||t.tagName==="LINK"&&t.getAttribute("rel")==="stylesheet"},at=function(t){var s,i;(s=e(this,L))==null||s.removeEventListener("scroll",e(this,O)),a(this,L,t.querySelector(e(this,k).scrollSelector)||t.documentElement),(i=e(this,L))==null||i.addEventListener("scroll",e(this,O)),e(this,O).call(this)},lt=function(t,s){const i=typeof t=="string"?document.getElementById(t):t;(typeof i=="number"||i)&&Nt.scrollToElement(i,{scrollElement:e(this,L),behavior:(s==null?void 0:s.behavior)||"instant",center:s==null?void 0:s.centerScroll,offset:s==null?void 0:s.offsetScroll})},$=new WeakMap,O=new WeakMap;exports.Morph=Rt;
|
package/lib/morph/index.js
CHANGED
|
@@ -38,10 +38,10 @@ class Pt extends HTMLElement {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
bt && !customElements.get("morph-announcer") && customElements.define("morph-announcer", Pt);
|
|
41
|
-
var
|
|
41
|
+
var P, h, x, j, I;
|
|
42
42
|
class yt {
|
|
43
43
|
constructor(t, s) {
|
|
44
|
-
o(this,
|
|
44
|
+
o(this, P);
|
|
45
45
|
o(this, h);
|
|
46
46
|
o(this, x);
|
|
47
47
|
o(this, j, (t) => {
|
|
@@ -51,7 +51,7 @@ class yt {
|
|
|
51
51
|
) || "push", i = e(this, h).hasAttribute("data-center-scroll"), u = getComputedStyle(e(this, h)).getPropertyValue("--offset-scroll").trim(), f = u ? zt.parse(u) : void 0, T = e(this, h).hasAttribute("data-revalidate"), M = e(this, h).hasAttribute(
|
|
52
52
|
"data-keep-search-parameters"
|
|
53
53
|
);
|
|
54
|
-
e(this,
|
|
54
|
+
e(this, P).navigate(e(this, x), {
|
|
55
55
|
historyAction: s,
|
|
56
56
|
centerScroll: i,
|
|
57
57
|
offsetScroll: f,
|
|
@@ -60,23 +60,23 @@ class yt {
|
|
|
60
60
|
});
|
|
61
61
|
});
|
|
62
62
|
o(this, I, () => {
|
|
63
|
-
e(this,
|
|
63
|
+
e(this, P).prefetch(e(this, x)), e(this, h).removeEventListener("pointerenter", e(this, I));
|
|
64
64
|
});
|
|
65
|
-
a(this,
|
|
65
|
+
a(this, P, s), a(this, h, t), a(this, x, e(this, h).getAttribute("href") || "/"), e(this, h).addEventListener("click", e(this, j)), this.checkCurrent(location.pathname), e(this, h).hasAttribute("data-prefetch") && e(this, h).addEventListener("pointerenter", e(this, I));
|
|
66
66
|
}
|
|
67
67
|
get element() {
|
|
68
68
|
return e(this, h);
|
|
69
69
|
}
|
|
70
70
|
checkCurrent(t) {
|
|
71
|
-
const s = e(this,
|
|
71
|
+
const s = e(this, P).normalizePath(t), i = e(this, P).normalizePath(e(this, x));
|
|
72
72
|
e(this, h).hasAttribute("data-include") && s.pathname.includes(i.pathname) ? e(this, h).classList.add("current") : i.pathname === s.pathname ? e(this, h).classList.add("current") : e(this, h).classList.remove("current");
|
|
73
73
|
}
|
|
74
74
|
destroy() {
|
|
75
75
|
e(this, h).removeEventListener("click", e(this, j)), e(this, h).removeEventListener("pointerenter", e(this, I)), e(this, h).classList.remove("current");
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
var N, V, E, D, R,
|
|
78
|
+
P = new WeakMap(), h = new WeakMap(), x = new WeakMap(), j = new WeakMap(), I = new WeakMap();
|
|
79
|
+
var N, V, E, D, R, A;
|
|
80
80
|
class wt {
|
|
81
81
|
constructor(t, s, i) {
|
|
82
82
|
o(this, N);
|
|
@@ -84,7 +84,7 @@ class wt {
|
|
|
84
84
|
o(this, E, { x: 0, y: 0 });
|
|
85
85
|
o(this, D);
|
|
86
86
|
o(this, R, null);
|
|
87
|
-
o(this,
|
|
87
|
+
o(this, A, null);
|
|
88
88
|
a(this, N, t), a(this, V, s), a(this, D, i.cloneNode(!0));
|
|
89
89
|
}
|
|
90
90
|
get pathname() {
|
|
@@ -94,17 +94,17 @@ class wt {
|
|
|
94
94
|
return e(this, E);
|
|
95
95
|
}
|
|
96
96
|
get document() {
|
|
97
|
-
return e(this,
|
|
97
|
+
return e(this, A);
|
|
98
98
|
}
|
|
99
99
|
cloneDocument() {
|
|
100
|
-
a(this,
|
|
100
|
+
a(this, A, (e(this, R) || e(this, D)).cloneNode(!0));
|
|
101
101
|
}
|
|
102
102
|
get title() {
|
|
103
103
|
let t = "";
|
|
104
|
-
if (e(this,
|
|
105
|
-
t = e(this,
|
|
104
|
+
if (e(this, A).title)
|
|
105
|
+
t = e(this, A).title;
|
|
106
106
|
else {
|
|
107
|
-
const s = e(this,
|
|
107
|
+
const s = e(this, A).querySelector("h1");
|
|
108
108
|
t = (s == null ? void 0 : s.innerText) || (s == null ? void 0 : s.textContent) || e(this, V);
|
|
109
109
|
}
|
|
110
110
|
return t;
|
|
@@ -132,26 +132,26 @@ class wt {
|
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
-
N = new WeakMap(), V = new WeakMap(), E = new WeakMap(), D = new WeakMap(), R = new WeakMap(),
|
|
136
|
-
var
|
|
135
|
+
N = new WeakMap(), V = new WeakMap(), E = new WeakMap(), D = new WeakMap(), R = new WeakMap(), A = new WeakMap();
|
|
136
|
+
var k, K, g, X, C, m, Y, z, y, L, B, q, l, et, st, it, At, rt, nt, ot, at, Z, O;
|
|
137
137
|
class Ut {
|
|
138
138
|
constructor(t) {
|
|
139
139
|
o(this, l);
|
|
140
|
-
o(this,
|
|
140
|
+
o(this, k, null);
|
|
141
141
|
o(this, K, null);
|
|
142
142
|
o(this, g, []);
|
|
143
143
|
o(this, X, new DOMParser());
|
|
144
|
-
o(this,
|
|
144
|
+
o(this, C);
|
|
145
145
|
o(this, m, null);
|
|
146
146
|
o(this, Y);
|
|
147
147
|
o(this, z, []);
|
|
148
|
-
o(this,
|
|
148
|
+
o(this, y, !1);
|
|
149
149
|
o(this, L, null);
|
|
150
150
|
o(this, B, /* @__PURE__ */ new Map());
|
|
151
151
|
o(this, q, null);
|
|
152
152
|
o(this, Z, (t) => H(this, null, function* () {
|
|
153
153
|
var s;
|
|
154
|
-
(s = t.state) != null && s.path && (t.preventDefault(), a(this,
|
|
154
|
+
(s = t.state) != null && s.path && (t.preventDefault(), a(this, y, !0), yield this.navigate(t.state.path, { historyAction: "none" }), a(this, y, !1));
|
|
155
155
|
}));
|
|
156
156
|
o(this, O, () => {
|
|
157
157
|
const t = e(this, L).scrollTop, s = e(this, L).scrollLeft;
|
|
@@ -163,7 +163,7 @@ class Ut {
|
|
|
163
163
|
});
|
|
164
164
|
});
|
|
165
165
|
if (bt) {
|
|
166
|
-
a(this,
|
|
166
|
+
a(this, k, {
|
|
167
167
|
base: Dt(t == null ? void 0 : t.base),
|
|
168
168
|
waitForHeadToLoad: (t == null ? void 0 : t.waitForHeadToLoad) !== !1,
|
|
169
169
|
cachePages: (t == null ? void 0 : t.cachePages) !== !1,
|
|
@@ -202,10 +202,13 @@ class Ut {
|
|
|
202
202
|
get scrollElement() {
|
|
203
203
|
return e(this, L);
|
|
204
204
|
}
|
|
205
|
+
get isPopstateNavigation() {
|
|
206
|
+
return e(this, y);
|
|
207
|
+
}
|
|
205
208
|
normalizePath(t) {
|
|
206
209
|
return Rt(t, {
|
|
207
|
-
base: e(this,
|
|
208
|
-
trailingSlash: e(this,
|
|
210
|
+
base: e(this, k).base,
|
|
211
|
+
trailingSlash: e(this, k).trailingSlash
|
|
209
212
|
});
|
|
210
213
|
}
|
|
211
214
|
prefetch(t) {
|
|
@@ -227,46 +230,46 @@ class Ut {
|
|
|
227
230
|
return;
|
|
228
231
|
const p = this.normalizePath(((lt = this.pathnameModifier) == null ? void 0 : lt.call(this, t)) || t);
|
|
229
232
|
let { pathname: c, hash: _, parameters: kt, leaf: Ct } = p;
|
|
230
|
-
if (e(this,
|
|
231
|
-
e(this,
|
|
233
|
+
if (e(this, C) === c || e(this, m) === c) {
|
|
234
|
+
e(this, y) || d(this, l, at).call(this, _ || 0, {
|
|
232
235
|
centerScroll: i,
|
|
233
236
|
offsetScroll: u,
|
|
234
237
|
behavior: "smooth"
|
|
235
238
|
});
|
|
236
239
|
return;
|
|
237
240
|
}
|
|
238
|
-
a(this,
|
|
241
|
+
a(this, C, c), e(this, g).forEach((F) => {
|
|
239
242
|
F.checkCurrent(c);
|
|
240
243
|
});
|
|
241
244
|
try {
|
|
242
245
|
let F = !0;
|
|
243
246
|
if (this.preprocessor)
|
|
244
247
|
try {
|
|
245
|
-
yield new Promise((n,
|
|
246
|
-
var
|
|
247
|
-
(
|
|
248
|
+
yield new Promise((n, w) => {
|
|
249
|
+
var b;
|
|
250
|
+
(b = this.preprocessor) == null || b.call(this, {
|
|
248
251
|
pathname: c,
|
|
249
252
|
resolve: n,
|
|
250
|
-
reject:
|
|
253
|
+
reject: w
|
|
251
254
|
});
|
|
252
255
|
});
|
|
253
256
|
} catch (n) {
|
|
254
257
|
n ? console.error(n) : console.log("Route change canceled"), F = !1;
|
|
255
258
|
}
|
|
256
|
-
if (!F || e(this,
|
|
259
|
+
if (!F || e(this, C) !== c) {
|
|
257
260
|
e(this, g).forEach((n) => {
|
|
258
261
|
n.checkCurrent(e(this, m));
|
|
259
262
|
});
|
|
260
263
|
return;
|
|
261
264
|
}
|
|
262
265
|
const ht = yield d(this, l, et).call(this, e(this, m)), S = yield d(this, l, et).call(this, c, f);
|
|
263
|
-
if (e(this,
|
|
266
|
+
if (e(this, C) !== c) {
|
|
264
267
|
e(this, g).forEach((n) => {
|
|
265
268
|
n.checkCurrent(e(this, m));
|
|
266
269
|
});
|
|
267
270
|
return;
|
|
268
271
|
}
|
|
269
|
-
ht.saveScrollState(), ht.saveDocumentState(), e(this,
|
|
272
|
+
ht.saveScrollState(), ht.saveDocumentState(), e(this, y) || (S.clearScrollState(), S.clearDocumentState()), S.cloneDocument(), e(this, q).textContent = S.title, document.body.appendChild(e(this, q));
|
|
270
273
|
const ct = {
|
|
271
274
|
pathname: c
|
|
272
275
|
};
|
|
@@ -274,10 +277,10 @@ class Ut {
|
|
|
274
277
|
detail: ct
|
|
275
278
|
});
|
|
276
279
|
const ut = Array.from(document.head.children), dt = Array.from(S.document.head.children), mt = d(this, l, At).call(this, ut, dt), Tt = d(this, l, rt).call(this, ut, mt), G = d(this, l, rt).call(this, dt, mt);
|
|
277
|
-
G.forEach((n,
|
|
280
|
+
G.forEach((n, w) => {
|
|
278
281
|
if (n.tagName === "SCRIPT" && n.getAttribute("src")) {
|
|
279
|
-
const
|
|
280
|
-
|
|
282
|
+
const b = document.createElement("script");
|
|
283
|
+
b.type = "module", b.src = n.getAttribute("src"), G[w] = b;
|
|
281
284
|
}
|
|
282
285
|
}), G.forEach((n) => {
|
|
283
286
|
document.head.appendChild(n);
|
|
@@ -288,20 +291,20 @@ class Ut {
|
|
|
288
291
|
if (d(this, l, nt).call(this, n))
|
|
289
292
|
return !0;
|
|
290
293
|
});
|
|
291
|
-
e(this,
|
|
292
|
-
let
|
|
294
|
+
e(this, k).waitForHeadToLoad && $.length && (yield new Promise((n) => H(this, null, function* () {
|
|
295
|
+
let w = 0;
|
|
293
296
|
try {
|
|
294
|
-
for (var
|
|
297
|
+
for (var b = Lt($), pt, W, Et; pt = !(W = yield b.next()).done; pt = !1) {
|
|
295
298
|
const J = W.value;
|
|
296
299
|
J.onload = () => {
|
|
297
|
-
|
|
300
|
+
w++, w === $.length && n();
|
|
298
301
|
};
|
|
299
302
|
}
|
|
300
303
|
} catch (W) {
|
|
301
304
|
Et = [W];
|
|
302
305
|
} finally {
|
|
303
306
|
try {
|
|
304
|
-
pt && (W =
|
|
307
|
+
pt && (W = b.return) && (yield W.call(b));
|
|
305
308
|
} finally {
|
|
306
309
|
if (Et)
|
|
307
310
|
throw Et[0];
|
|
@@ -318,8 +321,8 @@ class Ut {
|
|
|
318
321
|
pathname: c,
|
|
319
322
|
searchParameters: kt || (T ? location.search : ""),
|
|
320
323
|
hash: _
|
|
321
|
-
}), e(this, q).remove(), a(this, Y, e(this, m)), a(this, m, c), e(this, K).forEach((n,
|
|
322
|
-
const
|
|
324
|
+
}), e(this, q).remove(), a(this, Y, e(this, m)), a(this, m, c), e(this, K).forEach((n, w) => {
|
|
325
|
+
const b = Mt[w], pt = getComputedStyle(n).getPropertyValue("--morph-duration"), W = [...b.childNodes];
|
|
323
326
|
if (pt) {
|
|
324
327
|
const Et = [...n.childNodes];
|
|
325
328
|
Et.forEach((v) => {
|
|
@@ -350,13 +353,13 @@ class Ut {
|
|
|
350
353
|
e(this, z).push(Ht);
|
|
351
354
|
} else
|
|
352
355
|
n.innerHTML = "", n.append(...W);
|
|
353
|
-
}), _ ? (S.clearScrollState(), d(this, l, at).call(this, _, { centerScroll: i, offsetScroll: u })) : e(this,
|
|
356
|
+
}), _ ? (S.clearScrollState(), d(this, l, at).call(this, _, { centerScroll: i, offsetScroll: u })) : e(this, y) && S.restoreScrollPosition(), yield Promise.all(e(this, z)), ft.forEach((n) => n.remove()), a(this, z, []), this.findLinks(), U(document, "morphComplete", {
|
|
354
357
|
detail: ct
|
|
355
358
|
}), window.dispatchEvent(new Event("resize"));
|
|
356
359
|
} catch (F) {
|
|
357
360
|
console.error(F);
|
|
358
361
|
}
|
|
359
|
-
a(this,
|
|
362
|
+
a(this, C, void 0);
|
|
360
363
|
});
|
|
361
364
|
}
|
|
362
365
|
addLink(t) {
|
|
@@ -382,7 +385,7 @@ class Ut {
|
|
|
382
385
|
e(this, g).forEach((s) => s.destroy()), a(this, g, t.map((s) => new yt(s, this)));
|
|
383
386
|
}
|
|
384
387
|
}
|
|
385
|
-
|
|
388
|
+
k = new WeakMap(), K = new WeakMap(), g = new WeakMap(), X = new WeakMap(), C = new WeakMap(), m = new WeakMap(), Y = new WeakMap(), z = new WeakMap(), y = new WeakMap(), L = new WeakMap(), B = new WeakMap(), q = new WeakMap(), l = new WeakSet(), et = function(t, s = !1) {
|
|
386
389
|
return H(this, null, function* () {
|
|
387
390
|
let i = e(this, B).get(t);
|
|
388
391
|
return (!i || s) && (i = yield d(this, l, st).call(this, t)), i;
|
|
@@ -414,7 +417,7 @@ A = new WeakMap(), K = new WeakMap(), g = new WeakMap(), X = new WeakMap(), k =
|
|
|
414
417
|
(s = e(this, L)) == null || s.removeEventListener(
|
|
415
418
|
"scroll",
|
|
416
419
|
e(this, O)
|
|
417
|
-
), a(this, L, t.querySelector(e(this,
|
|
420
|
+
), a(this, L, t.querySelector(e(this, k).scrollSelector) || t.documentElement), (i = e(this, L)) == null || i.addEventListener("scroll", e(this, O)), e(this, O).call(this);
|
|
418
421
|
}, at = function(t, s) {
|
|
419
422
|
const i = typeof t == "string" ? document.getElementById(t) : t;
|
|
420
423
|
(typeof i == "number" || i) && Nt(i, {
|