mirror of
https://github.com/danog/telegram-tt.git
synced 2024-12-04 10:40:09 +01:00
2 lines
6.9 KiB
JavaScript
2 lines
6.9 KiB
JavaScript
"use strict";(self.webpackChunktelegram_t=self.webpackChunktelegram_t||[]).push([[941],{7941:(t,e,i)=>{i.r(e),i.d(e,{default:()=>g});var s=i(7361),n=i(6926);function r(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class a{constructor(t){this.worker=t,r(this,"requestStates",new Map),r(this,"requestStatesByCallback",new Map),this.subscribe()}request(t){const{worker:e,requestStates:i,requestStatesByCallback:s}=this,r=(0,n.Z)(i),a={type:"callMethod",messageId:r,...t},h={messageId:r},o=new Promise(((t,e)=>{Object.assign(h,{resolve:t,reject:e})}));if("function"==typeof a.args[a.args.length-1]){const t=a.args.pop();h.callback=t,s.set(t,h)}return i.set(r,h),o.catch((()=>{})).finally((()=>{i.delete(r),h.callback&&s.delete(h.callback)})),e.postMessage(a),o}cancelCallback(t){t.isCanceled=!0;const{messageId:e}=this.requestStatesByCallback.get(t)||{};e&&this.worker.postMessage({type:"cancelProgress",messageId:e})}subscribe(){const{worker:t,requestStates:e}=this;t.addEventListener("message",(({data:t})=>{if("methodResponse"===t.type){const i=e.get(t.messageId);i&&(t.error?i.reject(t.error):i.resolve(t.response))}else if("methodCallback"===t.type){const i=e.get(t.messageId);i&&i.callback&&i.callback(...t.callbackArgs)}else if("unhandledError"===t.type)throw t.error}))}}var h=i(9933),o=i(3570);function d(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const c=s.wB?.75:1,u=.75,m=s.s$?2:4,l=new Array(4).fill(void 0).map((()=>new a(new Worker(new URL(i.p+i.u(354),i.b)))));let p=-1;const g=class{constructor(t,e,i,s={},n){this.id=t,this.container=e,this.animationData=i,this.params=s,this.onLoad=n,d(this,"imgSize",void 0),d(this,"key",void 0),d(this,"msPerFrame",void 0),d(this,"reduceFactor",void 0),d(this,"cacheModulo",void 0),d(this,"chunkSize",void 0),d(this,"workerIndex",void 0),d(this,"chunks",[]),d(this,"framesCount",void 0),d(this,"chunksCount",void 0),d(this,"canvas",document.createElement("canvas")),d(this,"ctx",this.canvas.getContext("2d")),d(this,"isAnimating",!1),d(this,"isWaiting",!0),d(this,"isOnLoadFired",!1),d(this,"isDestroyed",!1),d(this,"approxFrameIndex",0),d(this,"prevFrameIndex",-1),d(this,"stopFrameIndex",0),d(this,"speed",1),d(this,"direction",1),d(this,"lastRenderAt",void 0),this.initContainer(),this.initConfig(),this.initRenderer()}isPlaying(){return this.isAnimating||this.isWaiting}play(){this.stopFrameIndex=void 0,this.direction=1,this.doPlay()}pause(){this.isWaiting?this.stopFrameIndex=this.approxFrameIndex:this.isAnimating=!1;const t=this.getChunkIndex(this.approxFrameIndex);this.chunks=this.chunks.map(((e,i)=>i===t?e:void 0))}goToAndPlay(t){this.approxFrameIndex=Math.floor(t/this.reduceFactor),this.stopFrameIndex=void 0,this.direction=1,this.doPlay()}goToAndStop(t){this.approxFrameIndex=Math.floor(t/this.reduceFactor),this.stopFrameIndex=Math.floor(t/this.reduceFactor),this.direction=1,this.doPlay()}playSegment([t,e]){this.approxFrameIndex=Math.floor(t/this.reduceFactor),this.stopFrameIndex=Math.floor(e/this.reduceFactor),this.direction=t<e?1:-1,this.doPlay()}setSpeed(t){this.speed=t}destroy(){this.isDestroyed=!0,this.pause(),this.destroyRenderer(),this.destroyContainer()}initContainer(){if(!(this.container.parentNode instanceof HTMLElement))throw new Error("[RLottie] Container is not mounted");let{size:t}=this.params;if(!t&&(t=this.container.offsetWidth||parseInt(this.container.style.width,10)||this.container.parentNode.offsetWidth,!t))throw new Error("[RLottie] Failed to detect width from container");this.canvas.style.width=`${t}px`,this.canvas.style.height=`${t}px`;const{isLowPriority:e,quality:i=(e?u:c)}=this.params,n=Math.round(t*Math.max(s.cL*i,1));this.canvas.width=n,this.canvas.height=n,this.container.appendChild(this.canvas),this.imgSize=n}initConfig(){this.key=`${this.id}_${this.imgSize}`;const{isLowPriority:t}=this.params,e=t?30:60,i=this.animationData.fr||e;this.reduceFactor=i%e==0?i/e:1,this.msPerFrame=1e3/(i/this.reduceFactor),this.cacheModulo=t?0:m,this.chunkSize=1}destroyContainer(){this.canvas.remove()}initRenderer(){this.workerIndex=(0,o.Z)(4,++p),l[this.workerIndex].request({name:"init",args:[this.key,this.animationData,this.imgSize,this.params.isLowPriority,this.reduceFactor,this.onRendererInit.bind(this)]})}destroyRenderer(){l[this.workerIndex].request({name:"destroy",args:[this.key]})}onRendererInit(t){this.framesCount=t,this.chunksCount=Math.ceil(t/this.chunkSize),this.isWaiting&&this.doPlay()}doPlay(){this.framesCount&&(this.isDestroyed||this.isAnimating||(this.isWaiting||(this.lastRenderAt=void 0),this.isAnimating=!0,this.isWaiting=!1,(0,h.j)((()=>{if(this.isDestroyed)return!1;if(!this.isAnimating&&this.isOnLoadFired)return!1;const t=Math.round(this.approxFrameIndex),e=this.getChunkIndex(t);if(!this.chunks[e])return this.requestChunk(e),this.isAnimating=!1,this.isWaiting=!0,!1;if(this.cacheModulo&&e%this.cacheModulo==0&&this.cleanupPrevChunk(e),this.requestNextChunk(e),t!==this.prevFrameIndex){const e=this.getFrame(t);if(!e)return this.isAnimating=!1,this.isWaiting=!0,!1;const i=new ImageData(new Uint8ClampedArray(e),this.imgSize,this.imgSize);this.ctx.putImageData(i,0,0),this.onLoad&&!this.isOnLoadFired&&(this.isOnLoadFired=!0,this.onLoad()),this.prevFrameIndex=t}const i=Date.now(),s=this.lastRenderAt?this.msPerFrame/(i-this.lastRenderAt):1,n=Math.min(1,this.direction*this.speed/s),r=Math.round(this.approxFrameIndex+n);if(this.lastRenderAt=i,n>0&&(t===this.framesCount-1||r>this.framesCount-1)){if(this.params.noLoop)return this.isAnimating=!1,!1;this.approxFrameIndex=0}else if(n<0&&(0===t||r<0)){if(this.params.noLoop)return this.isAnimating=!1,!1;this.approxFrameIndex=this.framesCount-1}else{if(void 0!==this.stopFrameIndex&&(t===this.stopFrameIndex||n>0&&r>this.stopFrameIndex||n<0&&r<this.stopFrameIndex))return this.stopFrameIndex=void 0,this.isAnimating=!1,!1;this.approxFrameIndex+=n}const a=Math.round(this.approxFrameIndex);return!!this.getFrame(a)||(this.requestChunk(this.getChunkIndex(a)),this.isWaiting=!0,this.isAnimating=!1,!1)}))))}getFrame(t){const e=this.getChunkIndex(t),i=this.getFrameIndexInChunk(t),s=this.chunks[e];if(s)return s[i]}getFrameIndexInChunk(t){return t-this.getChunkIndex(t)*this.chunkSize}getChunkIndex(t){return Math.floor(t/this.chunkSize)}requestChunk(t){if(this.chunks[t])return;this.chunks[t]=[];const e=t*this.chunkSize,i=Math.min(e+this.chunkSize-1,this.framesCount-1);l[this.workerIndex].request({name:"renderFrames",args:[this.key,e,i,this.onFrameLoad.bind(this)]})}cleanupPrevChunk(t){if(this.chunksCount<3)return;const e=(0,o.Z)(this.chunksCount,t-1);this.chunks[e]=void 0}requestNextChunk(t){if(1===this.chunksCount)return;const e=(0,o.Z)(this.chunksCount,t+1);this.chunks[e]||this.requestChunk(e)}onFrameLoad(t,e){const i=this.getChunkIndex(t),s=this.chunks[i];s&&(s[this.getFrameIndexInChunk(t)]=e,this.isWaiting&&this.doPlay())}}},3570:(t,e,i)=>{function s(t,e){return e-Math.floor(e/t)*t}i.d(e,{Z:()=>s})}}]);
|
|
//# sourceMappingURL=941.74ee93d332e344855ed7.js.map
|