chatBackground-j-mSAtH4.js 15 KB

12
  1. import{p as ut,cd as mt,b8 as gt,R as ft,a2 as z,a5 as E,ax as N,U as y,fh as pt,ay as D,cv as _t,W as it,m as F,bQ as xt,aT as nt,di as st,aL as vt,bI as Pt,a8 as wt,dw as Ct,fi as Tt,f5 as yt,b4 as Et,fj as k,cM as St,bt as Q,dx as It,a4 as At,Y as L,$ as V,V as J,b6 as Lt,bf as bt,dU as Ut,X as Rt,cY as Nt}from"./index-D_EGaVbS.js";function ne(n,e){if(n.focus(),ut(n),e){const t=new KeyboardEvent(e.type,e);n.dispatchEvent(t)}}const Dt=z("<div>");function se(n){const[e,t]=mt(n,["amount","withTransition"]);return(()=>{const i=Dt();return gt(i,ft(t,{get style(){return{"padding-top":e.amount,transition:e.withTransition?".2s":void 0}}}),!1,!1),i})()}function Ft(n){return E(()=>{const e=n.name||"s";return{enterActive:(n.enterActiveClass||e+"-enter-active").split(" "),enter:(n.enterClass||e+"-enter").split(" "),enterTo:(n.enterToClass||e+"-enter-to").split(" "),exitActive:(n.exitActiveClass||e+"-exit-active").split(" "),exit:(n.exitClass||e+"-exit").split(" "),exitTo:(n.exitToClass||e+"-exit-to").split(" ")}})}function at(n){requestAnimationFrame(()=>requestAnimationFrame(n))}function Mt(n,e,t,i,s){const{onBeforeEnter:a,onEnter:l,onAfterEnter:m}=e;let h;a?.(t),t.classList.add(...n.enter),t.classList.add(...n.enterActive),queueMicrotask(()=>{if(!t.parentNode)return i?.();l?.(t,()=>o())}),at(()=>{t.classList.remove(...n.enter),t.classList.add(...n.enterTo),(!l||l.length<2)&&(t.addEventListener("transitionend",o),t.addEventListener("animationend",o),s!==void 0&&(h=window.setTimeout(()=>o(),s)))});function o(d){(!d||d.target===t)&&(clearTimeout(h),i?.(),t.removeEventListener("transitionend",o),t.removeEventListener("animationend",o),t.classList.remove(...n.enterActive),t.classList.remove(...n.enterTo),m?.(t))}}function Wt(n,e,t,i,s){const{onBeforeExit:a,onExit:l,onAfterExit:m}=e;if(!t.parentNode)return i?.();let h;a?.(t),t.classList.add(...n.exit),t.classList.add(...n.exitActive),l?.(t,()=>o()),at(()=>{t.classList.remove(...n.exit),t.classList.add(...n.exitTo),(!l||l.length<2)&&(t.addEventListener("transitionend",o),t.addEventListener("animationend",o),s!==void 0&&(h=window.setTimeout(()=>o(),s)))});function o(d){(!d||d.target===t)&&(clearTimeout(h),i?.(),t.removeEventListener("transitionend",o),t.removeEventListener("animationend",o),t.classList.remove(...n.exitActive),t.classList.remove(...n.exitTo),m?.(t))}}var Ot=()=>{},Z=(n,e)=>e();function $t(n,e){const t=N(n),i=t?[t]:[],{onEnter:s=Z,onExit:a=Z}=e,[l,m]=y(e.appear?[]:i),[h]=_t();let o,d=!1;function r(c,p){if(!c)return p&&p();d=!0,a(c,()=>{D(()=>{d=!1,m(f=>f.filter(w=>w!==c)),p&&p()})})}function g(c){const p=o;if(!p)return c&&c();o=void 0,m(f=>[p,...f]),s(p,c??Ot)}const u=e.mode==="out-in"?c=>d||r(c,g):e.mode==="in-out"?c=>g(()=>r(c)):c=>{r(c),g()};return pt(c=>{const p=n();return N(h)?(h(),c):(p!==c&&(o=p,D(()=>N(()=>u(c)))),p)},e.appear?void 0:t),l}var b=n=>n instanceof Element;function M(n,e){if(e(n))return n;if(typeof n=="function"&&!n.length)return M(n(),e);if(Array.isArray(n)){const t=[];for(const i of n){const s=M(i,e);s&&(Array.isArray(s)?t.push.apply(t,s):t.push(s))}return t.length?t:null}return null}function ae(n,e=b,t=b){const i=E(n),s=E(()=>M(i(),e));return s.toArray=()=>{const a=s();return Array.isArray(a)?a:a?[a]:[]},s}function W(n,e){if(e(n))return n;if(typeof n=="function"&&!n.length)return W(n(),e);if(Array.isArray(n))for(const t of n){const i=W(t,e);if(i)return i}return null}function zt(n,e=b,t=b){const i=E(n);return E(()=>W(i(),e))}const kt={inout:"in-out",outin:"out-in"},re=n=>{const e=Ft(n);return $t(zt(()=>n.children),{mode:kt[n.mode],appear:n.appear,onEnter(t,i){Mt(e(),n,t,i,n.duration)},onExit(t,i){Wt(e(),n,t,i,n.duration)}})};function Bt(n){return(e,t,i)=>{n.addEventListener(e,t,i),it(()=>{n.removeEventListener(e,t,i)})}}function oe(){const[n,e]=y(F.activeScreen);return Bt(F)("changeScreen",(t,i)=>e(i)),n}const Yt=!1,Gt=st&&Ct,I=class I{constructor(){this.canvases=new Set}static getInstance(e){let t=this.INSTANCES.find(i=>i.options.element===e.element&&xt(i.options,e,["element"]));return t||(t=new I,t.init(e),this.INSTANCES.push(t)),t}init(e){this.options=e}renderToCanvas(e){return this.renderImageFromUrl(this.options.url).then(()=>this.fillCanvas(e))}renderImageFromUrl(e){if(this.renderImageFromUrlPromise)return this.renderImageFromUrlPromise;const t=this.image=document.createElement("img");return t.crossOrigin="anonymous",this.renderImageFromUrlPromise=nt(t,e,!1).then(()=>!st||!Gt?t:createImageBitmap(t,{resizeWidth:1440,resizeHeight:2960}).then(i=>(this.imageBitmap=i,t)))}cleanup(e){this.canvases.delete(e),this.canvases.size||(vt(I.INSTANCES,this),this.imageBitmap?.close())}fillCanvas(e){const t=e.getContext("2d"),{width:i,height:s}=e,a=this.imageBitmap||this.image;let l=a.width,m=a.height;const h=(500+Pt.height/2.5)*e.dpr,o=h/m;l*=o,m=h,this.options.mask?(t.fillStyle="#000",t.fillRect(0,0,i,s),t.globalCompositeOperation="destination-out"):t.globalCompositeOperation="source-over";const d=u=>{for(let c=0;c<i;c+=l)t.drawImage(a,c,u,l,m)},r=(s-m)/2;if(d(r),r>0){let u=r;do d(u-=m);while(u>=0)}const g=s-1;for(let u=r+m;u<g;u+=m)d(u)}setCanvasDimensions(e){const t=Math.min(2,window.devicePixelRatio),i=this.options.width*t;let s=this.options.height*t;e.dpr=t,e.dataset.originalHeight=""+s,F.activeScreen===wt.large&&Yt&&(s*=1.5),e.width=i,e.height=s}createCanvas(){const e=document.createElement("canvas");return this.canvases.add(e),this.setCanvasDimensions(e),e}resize(e,t){this.init({...this.options,width:e,height:t});const i=[];for(const s of this.canvases)this.setCanvasDimensions(s),i.push(this.renderToCanvas(s));return Promise.all(i)}static resizeInstancesOf(e){const t=this.INSTANCES.filter(s=>s.options.element===e),i=e.getBoundingClientRect();return Promise.all(t.map(s=>s.resize(i.width,i.height)))}};I.INSTANCES=[];let U=I;const R=class R extends Tt{static getWallPaperStorageUrl(e,t){return`backgrounds/${e}${t?"?blur":""}`}static hasWallPaperStorageUrl(e,t){const i=this.getWallPaperStorageUrl(e,t);return this.cacheStorage.has(i)}static getBackground({slug:e,canDownload:t,blur:i,managers:s,appDownloadManager:a}){var h;const l=this.getWallPaperStorageUrl(e,i),m=t&&!!s&&!!a;return(h=this.backgroundPromises)[l]||(h[l]=this.cacheStorage.getFile(l).then(o=>this.backgroundPromises[l]=URL.createObjectURL(o),m?async o=>{if(o.type!=="NO_ENTRY_FOUND")throw o;const d=await s.appThemesManager.getWallPaperBySlug(e);let r=await a.downloadMediaURL({media:d.document});return i&&(r=await this.blurWallPaperImage(r)),this.saveWallPaperToCache(e,r,i),this.backgroundPromises[l]=r}:void 0))}static blurWallPaperImage(e){const{canvas:t,promise:i}=Et(e,12,4);return i.then(()=>t.toDataURL())}static saveWallPaperToCache(e,t,i){if(!(!e||e===k))return fetch(t).then(s=>this.cacheStorage.save(this.getWallPaperStorageUrl(e,i),s))}static setBackgroundUrlToCache({slug:e,url:t,blur:i}){this.backgroundPromises[this.getWallPaperStorageUrl(e,i)]=t}};R.cacheStorage=new yt("cachedBackgrounds"),R.backgroundPromises={};let O=R;const Ht="_Container_nve2r_1",Xt="_CanvasCommon_nve2r_11",qt="_blend_nve2r_22",T={Container:Ht,CanvasCommon:Xt,blend:qt};function jt(n,e){return-e*n*(n-2)}const $=50,tt=$;class B{constructor(){this._width=$,this._height=tt,this._tails=90,this._curve=[0,.25,.5,.75,1,1.5,2,2.5,3,3.5,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,18.3,18.6,18.9,19.2,19.5,19.8,20.1,20.4,20.7,21,21.3,21.6,21.9,22.2,22.5,22.8,23.1,23.4,23.7,24,24.3,24.6,24.9,25.2,25.5,25.8,26.1,26.3,26.4,26.5,26.6,26.7,26.8,26.9,27],this._positions=[{x:.8,y:.1},{x:.6,y:.2},{x:.35,y:.25},{x:.25,y:.6},{x:.2,y:.9},{x:.4,y:.8},{x:.65,y:.75},{x:.75,y:.4}],this._phases=this._positions.length,this.drawNextPositionAnimated=t=>{let i,s;if(t){const a=t();i=a>=1;const l=jt(a,1),m=this._nextPositionTail??0,o=(this._nextPositionTail=this._nextPositionTails*l)-m;o&&(this._nextPositionLeft-=o,this.changeTailAndDraw(-o))}else{const a=this._frames;s=a.shift(),i=!a.length}return s&&this.drawImageData(s),i&&(this._nextPositionLeft=void 0,this._nextPositionTails=void 0,this._nextPositionTail=void 0,this._animatingToNextPosition=void 0),!i};const e=this._tails/this._curve[this._curve.length-1];for(let t=0,i=this._curve.length;t<i;++t)this._curve[t]=this._curve[t]*e;this._incrementalCurve=this._curve.map((t,i,s)=>t-(s[i-1]??0))}hexToRgb(e){const t=St(e);return{r:t[0],g:t[1],b:t[2]}}getPositions(e){const t=this._positions.slice();t.push(...t.splice(0,e));const i=[];for(let s=0;s<t.length;s+=2)i.push(t[s]);return i}getNextPositions(e,t,i){const s=this.getPositions(e);if(!i[0]&&i.length===1)return[s];const l=this.getPositions(++e%this._phases).map((h,o)=>({x:(h.x-s[o].x)/t,y:(h.y-s[o].y)/t}));return i.map(h=>l.map((o,d)=>({x:s[d].x+o.x*h,y:s[d].y+o.y*h})))}curPosition(e,t){return this.getNextPositions(e,this._tails,[t])[0]}changeTail(e){for(this._tail+=e;this._tail>=this._tails;)this._tail-=this._tails,++this._phase>=this._phases&&(this._phase-=this._phases);for(;this._tail<0;)this._tail+=this._tails,--this._phase<0&&(this._phase+=this._phases)}changeTailAndDraw(e){this.changeTail(e);const t=this.curPosition(this._phase,this._tail);this.drawGradient(t)}getGradientImageData(e,t=this._phase,i=1-this._tail/this._tails){const s=this._hctx.createImageData(this._width,this._height),a=s.data,l=this._colors.length,m=g=>{const u=[];for(let c=0;c!=4;++c)u[c]={...this._positions[(g+c*2)%this._positions.length]},u[c].y=1-u[c].y;return u},h=(t+1)%this._positions.length,o=m(h),d=m(t);let r=0;for(let g=0;g<this._height;++g){const c=g/this._height-.5,p=c*c;for(let f=0;f<this._width;++f){const P=f/this._width-.5,S=.35*Math.sqrt(P*P+p),_=S*S*.8*8,x=Math.sin(_),G=Math.cos(_),ct=Math.max(0,Math.min(1,.5+P*G-c*x)),ht=Math.max(0,Math.min(1,.5+P*x+c*G));let A=0,H=0,X=0,q=0;for(let v=0;v<l;++v){const lt=o[v].x+(d[v].x-o[v].x)*i,dt=o[v].y+(d[v].y-o[v].y)*i,j=ct-lt,K=ht-dt;let C=Math.max(0,.9-Math.sqrt(j*j+K*K));C=C*C*C*C,A+=C,H+=C*this._colors[v].r,X+=C*this._colors[v].g,q+=C*this._colors[v].b}a[r++]=H/A,a[r++]=X/A,a[r++]=q/A,a[r++]=255}}return s}drawImageData(e){this._hctx.putImageData(e,0,0),this._ctx.drawImage(this._hc,0,0,this._width,this._height)}drawGradient(e){this.drawImageData(this.getGradientImageData(e))}init(e){this._frames=[],this._phase=0,this._tail=0;const t=e.getAttribute("data-colors").split(",");this._colors=t.map(i=>this.hexToRgb(i)),this._hc||(this._hc=document.createElement("canvas"),this._hc.width=this._width,this._hc.height=this._height,this._hctx=this._hc.getContext("2d",{alpha:!1})),this._canvas=e,this._ctx=this._canvas.getContext("2d",{alpha:!1}),this.update()}update(){if(this._colors.length<2){const t=this._colors[0];this._ctx.fillStyle=`rgb(${t.r}, ${t.g}, ${t.b})`,this._ctx.fillRect(0,0,this._width,this._height);return}const e=this.curPosition(this._phase,this._tail);this.drawGradient(e)}toNextPosition(e){if(this._colors.length<2)return;if(e){this._nextPositionLeft=this._tails+(this._nextPositionLeft??0),this._nextPositionTails=this._nextPositionLeft,this._nextPositionTail=void 0,this._animatingToNextPosition=!0,Q(this.drawNextPositionAnimated.bind(this,e),this);return}const t=this._tail,i=this._tails;let s;const a=[];for(let h=0,o=this._incrementalCurve.length;h<o;++h){const d=this._incrementalCurve[h];let r=(a[h-1]??t)+d;+r.toFixed(2)>i&&s===void 0&&(s=h,r%=i),a.push(r)}const l=a.slice(0,s),m=s!==void 0?a.slice(s):[];[l,m].forEach((h,o,d)=>{const r=h[h.length-1];if(r!==void 0&&r>i&&(h[h.length-1]=+r.toFixed(2)),this._tail=r??0,!h.length)return;const g=this.getNextPositions(this._phase,i,h);o!==d.length-1&&++this._phase>=this._phases&&(this._phase-=this._phases);const u=g.map(c=>this.getGradientImageData(c));this._frames.push(...u)}),this._animatingToNextPosition=!0,Q(this.drawNextPositionAnimated,this)}cleanup(){}static createCanvas(e){const t=document.createElement("canvas");return t.width=$,t.height=tt,e!==void 0&&(t.dataset.colors=e),t}static create(e){const t=this.createCanvas(e),i=new B;return i.init(t),{gradientRenderer:i,canvas:t}}}function Kt(...n){return n.filter(Boolean).join(" ")}function rt(n){const e=n.getContext("2d"),t=new Array(4).fill(0),i=e.getImageData(0,0,n.width,n.height).data,s=i.length/4;for(let l=0;l<i.length;l+=4)t[0]+=i[l],t[1]+=i[l+1],t[2]+=i[l+2],t[3]+=i[l+3];const a=new Uint8ClampedArray(4);return a[0]=t[0]/s,a[1]=t[1]/s,a[2]=t[2]/s,a[3]=t[3]/s,a}function Qt(n,e,t){const i=document.createElement("canvas"),s=e/t,a=50;return s===1?(i.width=a,i.height=i.width/s):s>1?(i.height=a,i.width=i.height/s):i.width=i.height=a,i.getContext("2d").drawImage(n,0,0,e,t,0,0,i.width,i.height),rt(i)}function ot(n){return Qt(n,n.naturalWidth,n.naturalHeight)}async function ce(n){const e=document.createElement("img");return await nt(e,n,!1),ot(e)}function Vt(n){let{h:e,s:t,l:i}=It(n[0],n[1],n[2]);return t>0&&(t=Math.min(100,t+5+.1*(100-t))),i=Math.max(0,i*.65),`hsla(${e}, ${t}%, ${i}%, .4)`}const Jt=z("<div>"),Zt=z("<img>");async function te(n){const{themeController:e,managers:t,peerId:i}=n;let s=e.getTheme(),a=e.getThemeSettings(s).wallpaper;if(i&&i.isUser()){const d=await t.appProfileManager.getCachedFullUser(i.toUserId());if(d?.wallpaper)a=d.wallpaper;else if(d?.theme_emoticon){const r=Nt.accountThemes.themes?.find(g=>g.emoticon===d.theme_emoticon);if(r){s=r;const g=r?.settings.find(u=>u.wallpaper)?.wallpaper;g&&(a=g)}}}let l;try{l=et(a.slug,a.settings?.pFlags.blur)}catch{l=et(k)}const m=!!a?.pFlags?.pattern,h=a.settings?.intensity&&a.settings.intensity/100,o=!!h&&h<0;return{theme:s,backgroundUrl:l,isPattern:m,isDarkPattern:o,intensity:h,wallPaper:a}}function et(n,e){return n===k?"assets/img/pattern.svg":O.getWallPaperStorageUrl(n,e)}async function ee(n){n.naturalWidth||await new Promise(e=>{n.addEventListener("load",e,{once:!0})})}function he(n){let e;const[t,i]=y(),[s,a]=y(),[l,m]=y(),[h,o]=y();async function d(){const{backgroundUrl:r,isPattern:g,isDarkPattern:u,intensity:c,wallPaper:p}=await te(n);o(r);let f,w,P,Y;if(r)if(g){const _=e.getBoundingClientRect(),x=U.getInstance({element:e,url:r,width:_.width,height:_.height,mask:u});w=x.createCanvas(),w.classList.add(T.CanvasCommon),u||w.classList.add(T.blend),x.renderToCanvas(w)}else f=document.createElement("img"),f.classList.add(T.CanvasCommon),bt(f,r);const S=Ut(p);if(S){const{canvas:_,gradientRenderer:x}=B.create(S);P=_,n.gradientRendererRef?.(x),P.classList.add(T.CanvasCommon)}else n.gradientRendererRef?.(void 0);if(c){let _;f?_=f:_=u?P:w;let x=Math.abs(c)*(u?.5:1);f?x=Math.max(.3,1-c):u&&(x=Math.max(.3,x)),_?.style.setProperty("--opacity-max",""+x)}if(D(()=>{i(w),a(P),m(f)}),n.onHighlightColor){let _;f?(await ee(f),_=ot(f)):_=rt(P);const x=Vt(Array.from(_));n.onHighlightColor(x)}return{patternRenderer:Y}}return At(()=>{const r=()=>{U.resizeInstancesOf(e)};window.addEventListener("resize",r);const g=d();it(()=>{window.removeEventListener("resize",r),g.then(({patternRenderer:u})=>{u?.cleanup(t())})})}),(()=>{const r=Jt(),g=e;return typeof g=="function"?Rt(g,r):e=r,L(r,s,null),L(r,t,null),L(r,l,null),L(r,(()=>{const u=E(()=>!!h());return()=>u()&&(()=>{const c=Zt();return V(c,T.CanvasCommon),c.style.setProperty("visibility","hidden"),J(()=>Lt(c,"src",h())),c})()})(),null),J(()=>V(r,Kt(T.Container,n.class))),r})()}export{he as C,se as S,re as T,zt as a,O as b,Kt as c,U as d,B as e,ne as f,ot as g,rt as h,Vt as i,W as j,ce as k,ae as r,Bt as s,oe as u};
  2. //# sourceMappingURL=chatBackground-j-mSAtH4.js.map