aptechka 0.51.15 → 0.51.16
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 +23 -23
- package/package.json +1 -1
package/lib/morph/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var gt=(n,t)=>(t=Symbol[n])?t:Symbol.for("Symbol."+n),vt=n=>{throw TypeError(n)};var tt=(n,t,s)=>t.has(n)||vt("Cannot "+s);var e=(n,t,s)=>(tt(n,t,"read from private field"),s?s.call(n):t.get(n)),o=(n,t,s)=>t.has(n)?vt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(n):t.set(n,s),a=(n,t,s,i)=>(tt(n,t,"write to private field"),i?i.call(n,s):t.set(n,s),s),d=(n,t,s)=>(tt(n,t,"access private method"),s);var T=(n,t,s)=>new Promise((i,u)=>{var f=c=>{try{M(s.next(c))}catch(g){u(g)}},O=c=>{try{M(s.throw(c))}catch(g){u(g)}},M=c=>c.done?i(c.value):Promise.resolve(c.value).then(f,O);M((s=s.apply(n,t)).next())});var Lt=(n,t,s)=>(t=n[gt("asyncIterator")])?t.call(n):(n=n[gt("iterator")](),t={},s=(i,u)=>(u=n[i])&&(t[i]=f=>new Promise((O,M,c)=>(f=u.call(n,f),c=f.done,Promise.resolve(f.value).then(g=>O({value:g,done:c}),M)))),s("next"),s("return"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const wt=require("../index-Cqw2NKev.cjs"),j=require("../events-KVanG9sR.cjs"),Ht=require("../polyfills-Df4r-ETT.cjs"),xt=require("../scroll-H9zqFeML.cjs"),Q=require("../url-CLvdjbII.cjs"),Nt=require("../css-value-parser/index.cjs");class bt 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)}}wt.isBrowser&&!customElements.get("morph-announcer")&&customElements.define("morph-announcer",bt);var b,h,H,U,F;class St{constructor(t,s){o(this,b);o(this,h);o(this,H);o(this,U,t=>{t.preventDefault();const s=e(this,h).getAttribute("data-history-action")||"push",i=e(this,h).hasAttribute("data-center-scroll"),u=getComputedStyle(e(this,h)).getPropertyValue("--offset-scroll").trim(),f=u?Nt.cssValueParser.parse(u):void 0,O=e(this,h).hasAttribute("data-revalidate");e(this,b).navigate(e(this,H),{historyAction:s,centerScroll:i,offsetScroll:f,revalidate:O})});o(this,F,()=>{e(this,b).prefetch(e(this,H)),e(this,h).removeEventListener("pointerenter",e(this,F))});a(this,b,s),a(this,h,t),a(this,H,e(this,h).getAttribute("href")||"/"),e(this,h).addEventListener("click",e(this,U)),this.checkCurrent(location.pathname),e(this,h).hasAttribute("data-prefetch")&&e(this,h).addEventListener("pointerenter",e(this,F))}get element(){return e(this,h)}checkCurrent(t){const s=e(this,b).normalizePath(t),i=e(this,b).normalizePath(e(this,H));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")}destroy(){e(this,h).removeEventListener("click",e(this,U)),e(this,h).removeEventListener("pointerenter",e(this,F)),e(this,h).classList.remove("current")}}b=new WeakMap,h=new WeakMap,H=new WeakMap,U=new WeakMap,F=new WeakMap;var x,I,p,N,D,P;class yt{constructor(t,s,i){o(this,x);o(this,I);o(this,p,{x:0,y:0});o(this,N);o(this,D,null);o(this,P,null);a(this,x,t),a(this,I,s),a(this,N,i.cloneNode(!0))}get pathname(){return e(this,I)}get scrollState(){return e(this,p)}get document(){return e(this,P)}cloneDocument(){a(this,P,(e(this,D)||e(this,N)).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,I)}return t}clearScrollState(){e(this,p).x=0,e(this,p).y=0}clearDocumentState(){a(this,D,null)}saveScrollState(){e(this,N).documentElement.hasAttribute("data-no-scroll-restoration")?(e(this,p).x=0,e(this,p).y=0):(e(this,p).x=e(this,x).scrollElement.scrollLeft,e(this,p).y=e(this,x).scrollElement.scrollTop)}saveDocumentState(){e(this,N).documentElement.hasAttribute("data-no-page-restoration")?a(this,D,null):a(this,D,document.cloneNode(!0))}restoreScrollPosition(){e(this,x).scrollElement.scroll({top:e(this,p).y,left:e(this,p).x})}}x=new WeakMap,I=new WeakMap,p=new WeakMap,N=new WeakMap,D=new WeakMap,P=new WeakMap;var A,_,E,X,C,m,K,R,k,L,V,q,l,et,st,it,Pt,nt,rt,ot,at,Z,B;class Dt{constructor(t){o(this,l);o(this,A,null);o(this,_,null);o(this,E,[]);o(this,X,new DOMParser);o(this,C);o(this,m,null);o(this,K);o(this,R,[]);o(this,k,!1);o(this,L,null);o(this,V,new Map);o(this,q,null);o(this,Z,t=>T(this,null,function*(){var s;(s=t.state)!=null&&s.path&&(t.preventDefault(),a(this,k,!0),yield this.navigate(t.state.path,{historyAction:"none"}),a(this,k,!1))}));o(this,B,()=>{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),j.dispatchEvent(document,"morphScroll",{detail:{left:s,top:t}})});if(wt.isBrowser){a(this,A,{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,_,d(this,l,it).call(this,document.body));const s=this.normalizePath(location.pathname+location.hash);a(this,m,s.pathname),e(this,V).set(e(this,m),new yt(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,Z)),Q.changeHistory({action:"replace",pathname:e(this,m),searchParameters:s.parameters,hash:s.hash}),a(this,q,new bt),d(this,l,ot).call(this,document)}}get currentPathname(){return e(this,m)}get previousPathname(){return e(this,K)}get links(){return e(this,E)}get scrollElement(){return e(this,L)}normalizePath(t){return Q.splitPath(t,{base:e(this,A).base,trailingSlash:e(this,A).trailingSlash})}prefetch(t){return T(this,null,function*(){const s=this.normalizePath(t);d(this,l,st).call(this,s.pathname)})}navigate(O){return T(this,arguments,function*(t,{historyAction:s="push",centerScroll:i,offsetScroll:u,revalidate:f}={}){var lt;if(e(this,R).length)return;const M=this.normalizePath(((lt=this.pathnameModifier)==null?void 0:lt.call(this,t))||t);let{pathname:c,hash:g,parameters:At,leaf:Ct}=M;if(e(this,C)===c||e(this,m)===c){e(this,k)||d(this,l,at).call(this,g||0,{centerScroll:i,offsetScroll:u,behavior:"smooth"});return}a(this,C,c),e(this,E).forEach(z=>{z.checkCurrent(c)});try{let z=!0;if(this.preprocessor)try{yield new Promise((r,y)=>{var w;(w=this.preprocessor)==null||w.call(this,{pathname:c,resolve:r,reject:y})})}catch(r){r?console.error(r):console.log("Route change canceled"),z=!1}if(!z||e(this,C)!==c){e(this,E).forEach(r=>{r.checkCurrent(e(this,m))});return}const ct=yield d(this,l,et).call(this,e(this,m)),S=yield d(this,l,et).call(this,c,f);if(e(this,C)!==c){e(this,E).forEach(r=>{r.checkCurrent(e(this,m))});return}ct.saveScrollState(),ct.saveDocumentState(),e(this,k)||(S.clearScrollState(),S.clearDocumentState()),S.cloneDocument(),e(this,q).textContent=S.title,document.body.appendChild(e(this,q));const ht={pathname:c};j.dispatchEvent(document,"morphStart",{detail:ht});const ut=Array.from(document.head.children),dt=Array.from(S.document.head.children),mt=d(this,l,Pt).call(this,ut,dt),kt=d(this,l,nt).call(this,ut,mt),Y=d(this,l,nt).call(this,dt,mt);Y.forEach((r,y)=>{if(r.tagName==="SCRIPT"&&r.getAttribute("src")){const w=document.createElement("script");w.type="module",w.src=r.getAttribute("src"),Y[y]=w}}),Y.forEach(r=>{document.head.appendChild(r)});const $=Y.filter(r=>{if(r.hasAttribute("data-no-waiting"))return!1;if(d(this,l,rt).call(this,r))return!0});e(this,A).waitForHeadToLoad&&$.length&&(yield new Promise(r=>T(this,null,function*(){let y=0;try{for(var w=Lt($),pt,W,Et;pt=!(W=yield w.next()).done;pt=!1){const G=W.value;G.onload=()=>{y++,y===$.length&&r()}}}catch(W){Et=[W]}finally{try{pt&&(W=w.return)&&(yield W.call(w))}finally{if(Et)throw Et[0]}}})));const ft=[];kt.forEach(r=>{r.hasAttribute("data-permanent")||(d(this,l,rt).call(this,r)?ft.push(r):r.remove())});const Mt=d(this,l,it).call(this,S.document.body);d(this,l,ot).call(this,S.document),document.documentElement.setAttribute("data-current-pathname",c),document.documentElement.setAttribute("data-current-leaf",Ct),Q.changeHistory({action:s,pathname:c,searchParameters:At,hash:g}),e(this,q).remove(),a(this,K,e(this,m)),a(this,m,c),e(this,_).forEach((r,y)=>{const w=Mt[y],pt=getComputedStyle(r).getPropertyValue("--morph-duration"),W=[...w.childNodes];if(pt){const Et=[...r.childNodes];Et.forEach(v=>{v instanceof HTMLElement&&v.classList.add("old")}),W.forEach(v=>{v instanceof HTMLElement&&v.classList.add("new")}),r.prepend(...W),Ht.requestIdleCallback(()=>{W.forEach(v=>{v instanceof HTMLElement&&v.classList.add("in")})});const G={morphElement:r,pathname:c};j.dispatchEvent(document,"morphNewChildrenAdded",{detail:G});const Tt=new Promise(v=>{setTimeout(()=>{Et.forEach(J=>J.remove()),W.forEach(J=>{J instanceof HTMLElement&&J.classList.remove("in","new")}),j.dispatchEvent(document,"morphOldChildrenRemoved",{detail:G}),v()},(parseFloat(pt)||0)*1e3+10)});e(this,R).push(Tt)}else r.innerHTML="",r.append(...W)}),g?(S.clearScrollState(),d(this,l,at).call(this,g,{centerScroll:i,offsetScroll:u})):e(this,k)&&S.restoreScrollPosition(),yield Promise.all(e(this,R)),ft.forEach(r=>r.remove()),a(this,R,[]),this.findLinks(),j.dispatchEvent(document,"morphComplete",{detail:ht}),window.dispatchEvent(new Event("resize"))}catch(z){console.error(z)}a(this,C,void 0)})}addLink(t){e(this,E).push(new St(t,this))}addLinks(t){t.forEach(s=>{this.addLink(s)})}removeLink(t){a(this,E,e(this,E).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]")});e(this,E).forEach(s=>s.destroy()),a(this,E,t.map(s=>new St(s,this)))}}A=new WeakMap,_=new WeakMap,E=new WeakMap,X=new WeakMap,C=new WeakMap,m=new WeakMap,K=new WeakMap,R=new WeakMap,k=new WeakMap,L=new WeakMap,V=new WeakMap,q=new WeakMap,l=new WeakSet,et=function(t,s=!1){return T(this,null,function*(){let i=e(this,V).get(t);return(!i||s)&&(i=yield d(this,l,st).call(this,t)),i})},st=function(t){return T(this,null,function*(){const i=yield(yield fetch(t)).text(),u=e(this,X).parseFromString(i,"text/html"),f=new yt(this,t,u);return e(this,V).set(t,f),f})},it=function(t){const s=[...t.querySelectorAll("[data-morph]")];return s.length?s:[t]},Pt=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))},rt=function(t){return t.tagName==="SCRIPT"||t.tagName==="STYLE"||t.tagName==="LINK"&&t.getAttribute("rel")==="stylesheet"},ot=function(t){var s,i;(s=e(this,L))==null||s.removeEventListener("scroll",e(this,B)),a(this,L,t.querySelector(e(this,A).scrollSelector)||t.documentElement),(i=e(this,L))==null||i.addEventListener("scroll",e(this,B)),e(this,B).call(this)},at=function(t,s){const i=typeof t=="string"?document.getElementById(t):t;(typeof i=="number"||i)&&xt.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})},Z=new WeakMap,B=new WeakMap;exports.Morph=Dt;
|
|
1
|
+
"use strict";var gt=(n,t)=>(t=Symbol[n])?t:Symbol.for("Symbol."+n),vt=n=>{throw TypeError(n)};var tt=(n,t,s)=>t.has(n)||vt("Cannot "+s);var e=(n,t,s)=>(tt(n,t,"read from private field"),s?s.call(n):t.get(n)),o=(n,t,s)=>t.has(n)?vt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(n):t.set(n,s),a=(n,t,s,i)=>(tt(n,t,"write to private field"),i?i.call(n,s):t.set(n,s),s),d=(n,t,s)=>(tt(n,t,"access private method"),s);var T=(n,t,s)=>new Promise((i,u)=>{var f=c=>{try{M(s.next(c))}catch(g){u(g)}},O=c=>{try{M(s.throw(c))}catch(g){u(g)}},M=c=>c.done?i(c.value):Promise.resolve(c.value).then(f,O);M((s=s.apply(n,t)).next())});var Lt=(n,t,s)=>(t=n[gt("asyncIterator")])?t.call(n):(n=n[gt("iterator")](),t={},s=(i,u)=>(u=n[i])&&(t[i]=f=>new Promise((O,M,c)=>(f=u.call(n,f),c=f.done,Promise.resolve(f.value).then(g=>O({value:g,done:c}),M)))),s("next"),s("return"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const wt=require("../index-Cqw2NKev.cjs"),_=require("../events-KVanG9sR.cjs"),Ht=require("../polyfills-Df4r-ETT.cjs"),xt=require("../scroll-H9zqFeML.cjs"),Q=require("../url-CLvdjbII.cjs"),Nt=require("../css-value-parser/index.cjs");class bt 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)}}wt.isBrowser&&!customElements.get("morph-announcer")&&customElements.define("morph-announcer",bt);var b,h,H,j,F;class St{constructor(t,s){o(this,b);o(this,h);o(this,H);o(this,j,t=>{t.preventDefault();const s=e(this,h).getAttribute("data-history-action")||"push",i=e(this,h).hasAttribute("data-center-scroll"),u=getComputedStyle(e(this,h)).getPropertyValue("--offset-scroll").trim(),f=u?Nt.cssValueParser.parse(u):void 0,O=e(this,h).hasAttribute("data-revalidate");e(this,b).navigate(e(this,H),{historyAction:s,centerScroll:i,offsetScroll:f,revalidate:O})});o(this,F,()=>{e(this,b).prefetch(e(this,H)),e(this,h).removeEventListener("pointerenter",e(this,F))});a(this,b,s),a(this,h,t),a(this,H,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,F))}get element(){return e(this,h)}checkCurrent(t){const s=e(this,b).normalizePath(t),i=e(this,b).normalizePath(e(this,H));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")}destroy(){e(this,h).removeEventListener("click",e(this,j)),e(this,h).removeEventListener("pointerenter",e(this,F)),e(this,h).classList.remove("current")}}b=new WeakMap,h=new WeakMap,H=new WeakMap,j=new WeakMap,F=new WeakMap;var x,I,p,N,D,P;class yt{constructor(t,s,i){o(this,x);o(this,I);o(this,p,{x:0,y:0});o(this,N);o(this,D,null);o(this,P,null);a(this,x,t),a(this,I,s),a(this,N,i.cloneNode(!0))}get pathname(){return e(this,I)}get scrollState(){return e(this,p)}get document(){return e(this,P)}cloneDocument(){a(this,P,(e(this,D)||e(this,N)).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,I)}return t}clearScrollState(){e(this,p).x=0,e(this,p).y=0}clearDocumentState(){a(this,D,null)}saveScrollState(){e(this,N).documentElement.hasAttribute("data-no-scroll-restoration")?(e(this,p).x=0,e(this,p).y=0):(e(this,p).x=e(this,x).scrollElement.scrollLeft,e(this,p).y=e(this,x).scrollElement.scrollTop)}saveDocumentState(){e(this,N).documentElement.hasAttribute("data-no-page-restoration")?a(this,D,null):a(this,D,document.cloneNode(!0))}restoreScrollPosition(){e(this,x).scrollElement.scroll({top:e(this,p).y,left:e(this,p).x})}}x=new WeakMap,I=new WeakMap,p=new WeakMap,N=new WeakMap,D=new WeakMap,P=new WeakMap;var A,U,E,X,C,m,K,R,k,L,V,q,l,et,st,it,Pt,nt,rt,ot,at,Z,B;class Dt{constructor(t){o(this,l);o(this,A,null);o(this,U,null);o(this,E,[]);o(this,X,new DOMParser);o(this,C);o(this,m,null);o(this,K);o(this,R,[]);o(this,k,!1);o(this,L,null);o(this,V,new Map);o(this,q,null);o(this,Z,t=>T(this,null,function*(){var s;(s=t.state)!=null&&s.path&&(t.preventDefault(),a(this,k,!0),yield this.navigate(t.state.path,{historyAction:"none"}),a(this,k,!1))}));o(this,B,()=>{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(wt.isBrowser){a(this,A,{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,U,d(this,l,it).call(this,document.body));const s=this.normalizePath(location.pathname+location.hash);a(this,m,s.pathname),e(this,V).set(e(this,m),new yt(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,Z)),Q.changeHistory({action:"replace",pathname:e(this,m),searchParameters:s.parameters,hash:s.hash}),a(this,q,new bt),d(this,l,ot).call(this,document)}}get currentPathname(){return e(this,m)}get previousPathname(){return e(this,K)}get links(){return e(this,E)}get scrollElement(){return e(this,L)}normalizePath(t){return Q.splitPath(t,{base:e(this,A).base,trailingSlash:e(this,A).trailingSlash})}prefetch(t){return T(this,null,function*(){const s=this.normalizePath(t);d(this,l,st).call(this,s.pathname)})}navigate(O){return T(this,arguments,function*(t,{historyAction:s="push",centerScroll:i,offsetScroll:u,revalidate:f}={}){var lt;if(e(this,R).length)return;const M=this.normalizePath(((lt=this.pathnameModifier)==null?void 0:lt.call(this,t))||t);let{pathname:c,hash:g,parameters:At,leaf:Ct}=M;if(e(this,C)===c||e(this,m)===c){e(this,k)||d(this,l,at).call(this,g||0,{centerScroll:i,offsetScroll:u,behavior:"smooth"});return}a(this,C,c),e(this,E).forEach(z=>{z.checkCurrent(c)});try{let z=!0;if(this.preprocessor)try{yield new Promise((r,y)=>{var w;(w=this.preprocessor)==null||w.call(this,{pathname:c,resolve:r,reject:y})})}catch(r){r?console.error(r):console.log("Route change canceled"),z=!1}if(!z||e(this,C)!==c){e(this,E).forEach(r=>{r.checkCurrent(e(this,m))});return}const ct=yield d(this,l,et).call(this,e(this,m)),S=yield d(this,l,et).call(this,c,f);if(e(this,C)!==c){e(this,E).forEach(r=>{r.checkCurrent(e(this,m))});return}ct.saveScrollState(),ct.saveDocumentState(),e(this,k)||(S.clearScrollState(),S.clearDocumentState()),S.cloneDocument(),e(this,q).textContent=S.title,document.body.appendChild(e(this,q));const ht={pathname:c};_.dispatchEvent(document,"morphStart",{detail:ht});const ut=Array.from(document.head.children),dt=Array.from(S.document.head.children),mt=d(this,l,Pt).call(this,ut,dt),kt=d(this,l,nt).call(this,ut,mt),Y=d(this,l,nt).call(this,dt,mt);Y.forEach((r,y)=>{if(r.tagName==="SCRIPT"&&r.getAttribute("src")){const w=document.createElement("script");w.type="module",w.src=r.getAttribute("src"),Y[y]=w}}),Y.forEach(r=>{document.head.appendChild(r)});const $=Y.filter(r=>{if(r.hasAttribute("data-no-waiting"))return!1;if(d(this,l,rt).call(this,r))return!0});e(this,A).waitForHeadToLoad&&$.length&&(yield new Promise(r=>T(this,null,function*(){let y=0;try{for(var w=Lt($),pt,W,Et;pt=!(W=yield w.next()).done;pt=!1){const G=W.value;G.onload=()=>{y++,y===$.length&&r()}}}catch(W){Et=[W]}finally{try{pt&&(W=w.return)&&(yield W.call(w))}finally{if(Et)throw Et[0]}}})));const ft=[];kt.forEach(r=>{r.hasAttribute("data-permanent")||(d(this,l,rt).call(this,r)?ft.push(r):r.remove())});const Mt=d(this,l,it).call(this,S.document.body);d(this,l,ot).call(this,S.document),document.documentElement.setAttribute("data-current-pathname",c),document.documentElement.setAttribute("data-current-leaf",Ct),Q.changeHistory({action:s,pathname:c,searchParameters:At,hash:g}),e(this,q).remove(),a(this,K,e(this,m)),a(this,m,c),e(this,U).forEach((r,y)=>{const w=Mt[y],pt=getComputedStyle(r).getPropertyValue("--morph-duration"),W=[...w.childNodes];if(pt){const Et=[...r.childNodes];Et.forEach(v=>{v instanceof HTMLElement&&v.classList.add("old")}),W.forEach(v=>{v instanceof HTMLElement&&v.classList.add("new")}),r.prepend(...W),Ht.requestIdleCallback(()=>{W.forEach(v=>{v instanceof HTMLElement&&v.classList.add("in")})});const G={morphElement:r,pathname:c};_.dispatchEvent(document,"morphNewChildrenAdded",{detail:G});const Tt=new Promise(v=>{setTimeout(()=>{Et.forEach(J=>J.remove()),W.forEach(J=>{J instanceof HTMLElement&&J.classList.remove("in","new")}),_.dispatchEvent(document,"morphOldChildrenRemoved",{detail:G}),v()},(parseFloat(pt)||0)*1e3+10)});e(this,R).push(Tt)}else r.innerHTML="",r.append(...W)}),g?(S.clearScrollState(),d(this,l,at).call(this,g,{centerScroll:i,offsetScroll:u})):e(this,k)&&S.restoreScrollPosition(),yield Promise.all(e(this,R)),ft.forEach(r=>r.remove()),a(this,R,[]),this.findLinks(),_.dispatchEvent(document,"morphComplete",{detail:ht}),window.dispatchEvent(new Event("resize"))}catch(z){console.error(z)}a(this,C,void 0)})}addLink(t){e(this,E).push(new St(t,this))}addLinks(t){t.forEach(s=>{this.addLink(s)})}removeLink(t){a(this,E,e(this,E).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,E).forEach(s=>s.destroy()),a(this,E,t.map(s=>new St(s,this)))}}A=new WeakMap,U=new WeakMap,E=new WeakMap,X=new WeakMap,C=new WeakMap,m=new WeakMap,K=new WeakMap,R=new WeakMap,k=new WeakMap,L=new WeakMap,V=new WeakMap,q=new WeakMap,l=new WeakSet,et=function(t,s=!1){return T(this,null,function*(){let i=e(this,V).get(t);return(!i||s)&&(i=yield d(this,l,st).call(this,t)),i})},st=function(t){return T(this,null,function*(){const i=yield(yield fetch(t)).text(),u=e(this,X).parseFromString(i,"text/html"),f=new yt(this,t,u);return e(this,V).set(t,f),f})},it=function(t){const s=[...t.querySelectorAll("[data-morph]")];return s.length?s:[t]},Pt=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))},rt=function(t){return t.tagName==="SCRIPT"||t.tagName==="STYLE"||t.tagName==="LINK"&&t.getAttribute("rel")==="stylesheet"},ot=function(t){var s,i;(s=e(this,L))==null||s.removeEventListener("scroll",e(this,B)),a(this,L,t.querySelector(e(this,A).scrollSelector)||t.documentElement),(i=e(this,L))==null||i.addEventListener("scroll",e(this,B)),e(this,B).call(this)},at=function(t,s){const i=typeof t=="string"?document.getElementById(t):t;(typeof i=="number"||i)&&xt.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})},Z=new WeakMap,B=new WeakMap;exports.Morph=Dt;
|
package/lib/morph/index.js
CHANGED
|
@@ -130,14 +130,14 @@ class yt {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
x = new WeakMap(), I = new WeakMap(), p = new WeakMap(), N = new WeakMap(), D = new WeakMap(), P = new WeakMap();
|
|
133
|
-
var A, K, E,
|
|
133
|
+
var A, K, E, Q, C, m, Y, R, k, L, V, z, l, tt, et, st, Pt, it, rt, nt, ot, X, B;
|
|
134
134
|
class Wt {
|
|
135
135
|
constructor(t) {
|
|
136
136
|
o(this, l);
|
|
137
137
|
o(this, A, null);
|
|
138
138
|
o(this, K, null);
|
|
139
139
|
o(this, E, []);
|
|
140
|
-
o(this,
|
|
140
|
+
o(this, Q, new DOMParser());
|
|
141
141
|
o(this, C);
|
|
142
142
|
o(this, m, null);
|
|
143
143
|
o(this, Y);
|
|
@@ -146,7 +146,7 @@ class Wt {
|
|
|
146
146
|
o(this, L, null);
|
|
147
147
|
o(this, V, /* @__PURE__ */ new Map());
|
|
148
148
|
o(this, z, null);
|
|
149
|
-
o(this,
|
|
149
|
+
o(this, X, (t) => M(this, null, function* () {
|
|
150
150
|
var s;
|
|
151
151
|
(s = t.state) != null && s.path && (t.preventDefault(), a(this, k, !0), yield this.navigate(t.state.path, { historyAction: "none" }), a(this, k, !1));
|
|
152
152
|
}));
|
|
@@ -179,7 +179,7 @@ class Wt {
|
|
|
179
179
|
), document.documentElement.setAttribute(
|
|
180
180
|
"data-current-leaf",
|
|
181
181
|
s.leaf
|
|
182
|
-
), this.findLinks(), addEventListener("popstate", e(this,
|
|
182
|
+
), this.findLinks(), addEventListener("popstate", e(this, X)), Lt({
|
|
183
183
|
action: "replace",
|
|
184
184
|
pathname: e(this, m),
|
|
185
185
|
searchParameters: s.parameters,
|
|
@@ -269,28 +269,28 @@ class Wt {
|
|
|
269
269
|
U(document, "morphStart", {
|
|
270
270
|
detail: ht
|
|
271
271
|
});
|
|
272
|
-
const ct = Array.from(document.head.children), ut = Array.from(S.document.head.children), dt = d(this, l, Pt).call(this, ct, ut), kt = d(this, l, it).call(this, ct, dt),
|
|
273
|
-
|
|
272
|
+
const ct = Array.from(document.head.children), ut = Array.from(S.document.head.children), dt = d(this, l, Pt).call(this, ct, ut), kt = d(this, l, it).call(this, ct, dt), _ = d(this, l, it).call(this, ut, dt);
|
|
273
|
+
_.forEach((n, y) => {
|
|
274
274
|
if (n.tagName === "SCRIPT" && n.getAttribute("src")) {
|
|
275
275
|
const w = document.createElement("script");
|
|
276
|
-
w.type = "module", w.src = n.getAttribute("src"),
|
|
276
|
+
w.type = "module", w.src = n.getAttribute("src"), _[y] = w;
|
|
277
277
|
}
|
|
278
|
-
}),
|
|
278
|
+
}), _.forEach((n) => {
|
|
279
279
|
document.head.appendChild(n);
|
|
280
280
|
});
|
|
281
|
-
const
|
|
281
|
+
const Z = _.filter((n) => {
|
|
282
282
|
if (n.hasAttribute("data-no-waiting"))
|
|
283
283
|
return !1;
|
|
284
284
|
if (d(this, l, rt).call(this, n))
|
|
285
285
|
return !0;
|
|
286
286
|
});
|
|
287
|
-
e(this, A).waitForHeadToLoad &&
|
|
287
|
+
e(this, A).waitForHeadToLoad && Z.length && (yield new Promise((n) => M(this, null, function* () {
|
|
288
288
|
let y = 0;
|
|
289
289
|
try {
|
|
290
|
-
for (var w = vt(
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
y++, y ===
|
|
290
|
+
for (var w = vt(Z), ft, W, pt; ft = !(W = yield w.next()).done; ft = !1) {
|
|
291
|
+
const G = W.value;
|
|
292
|
+
G.onload = () => {
|
|
293
|
+
y++, y === Z.length && n();
|
|
294
294
|
};
|
|
295
295
|
}
|
|
296
296
|
} catch (W) {
|
|
@@ -327,19 +327,19 @@ class Wt {
|
|
|
327
327
|
v instanceof HTMLElement && v.classList.add("in");
|
|
328
328
|
});
|
|
329
329
|
});
|
|
330
|
-
const
|
|
330
|
+
const G = {
|
|
331
331
|
morphElement: n,
|
|
332
332
|
pathname: h
|
|
333
333
|
};
|
|
334
334
|
U(document, "morphNewChildrenAdded", {
|
|
335
|
-
detail:
|
|
335
|
+
detail: G
|
|
336
336
|
});
|
|
337
337
|
const Mt = new Promise((v) => {
|
|
338
338
|
setTimeout(() => {
|
|
339
|
-
pt.forEach((
|
|
340
|
-
|
|
339
|
+
pt.forEach((J) => J.remove()), W.forEach((J) => {
|
|
340
|
+
J instanceof HTMLElement && J.classList.remove("in", "new");
|
|
341
341
|
}), U(document, "morphOldChildrenRemoved", {
|
|
342
|
-
detail:
|
|
342
|
+
detail: G
|
|
343
343
|
}), v();
|
|
344
344
|
}, (parseFloat(ft) || 0) * 1e3 + 10);
|
|
345
345
|
});
|
|
@@ -372,20 +372,20 @@ class Wt {
|
|
|
372
372
|
].filter(
|
|
373
373
|
(s) => {
|
|
374
374
|
var i;
|
|
375
|
-
return ((i = s.getAttribute("href")) == null ? void 0 : i.startsWith("/")) && !s.hasAttribute("download") && !s.hasAttribute("data-morph-skip") && !s.closest("[data-morph-skip]");
|
|
375
|
+
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";
|
|
376
376
|
}
|
|
377
377
|
);
|
|
378
378
|
e(this, E).forEach((s) => s.destroy()), a(this, E, t.map((s) => new St(s, this)));
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
|
-
A = new WeakMap(), K = new WeakMap(), E = new WeakMap(),
|
|
381
|
+
A = new WeakMap(), K = new WeakMap(), E = new WeakMap(), Q = new WeakMap(), C = new WeakMap(), m = new WeakMap(), Y = new WeakMap(), R = new WeakMap(), k = new WeakMap(), L = new WeakMap(), V = new WeakMap(), z = new WeakMap(), l = new WeakSet(), tt = function(t, s = !1) {
|
|
382
382
|
return M(this, null, function* () {
|
|
383
383
|
let i = e(this, V).get(t);
|
|
384
384
|
return (!i || s) && (i = yield d(this, l, et).call(this, t)), i;
|
|
385
385
|
});
|
|
386
386
|
}, et = function(t) {
|
|
387
387
|
return M(this, null, function* () {
|
|
388
|
-
const i = yield (yield fetch(t)).text(), u = e(this,
|
|
388
|
+
const i = yield (yield fetch(t)).text(), u = e(this, Q).parseFromString(i, "text/html"), f = new yt(this, t, u);
|
|
389
389
|
return e(this, V).set(t, f), f;
|
|
390
390
|
});
|
|
391
391
|
}, st = function(t) {
|
|
@@ -419,7 +419,7 @@ A = new WeakMap(), K = new WeakMap(), E = new WeakMap(), X = new WeakMap(), C =
|
|
|
419
419
|
center: s == null ? void 0 : s.centerScroll,
|
|
420
420
|
offset: s == null ? void 0 : s.offsetScroll
|
|
421
421
|
});
|
|
422
|
-
},
|
|
422
|
+
}, X = new WeakMap(), B = new WeakMap();
|
|
423
423
|
export {
|
|
424
424
|
Wt as Morph
|
|
425
425
|
};
|