TelegramPWA/dist/7941.47f10f7fe9b15891eb31.js
Alexander Zinchuk 6929cccea1 [Build]
2022-11-13 17:07:57 +04:00

2 lines
8.6 KiB
JavaScript

"use strict";(self.webpackChunktelegram_t=self.webpackChunktelegram_t||[]).push([[7941],{67941:(t,e,s)=>{s.r(e),s.d(e,{default:()=>y});var i=s(77361),a=s(26926);function r(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}class n{constructor(t){this.worker=t,r(this,"requestStates",new Map),r(this,"requestStatesByCallback",new Map),this.subscribe()}request(t){const{worker:e,requestStates:s,requestStatesByCallback:i}=this,r=(0,a.Z)(s),n={type:"callMethod",messageId:r,...t},o={messageId:r},h=new Promise(((t,e)=>{Object.assign(o,{resolve:t,reject:e})}));if("function"==typeof n.args[n.args.length-1]){n.withCallback=!0;const t=n.args.pop();o.callback=t,i.set(t,o)}return s.set(r,o),h.catch((()=>{})).finally((()=>{s.delete(r),o.callback&&i.delete(o.callback)})),e.postMessage(n),h}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",(t=>{let{data:s}=t;if("methodResponse"===s.type){const t=e.get(s.messageId);t&&(s.error?t.reject(s.error):t.resolve(s.response))}else if("methodCallback"===s.type){var i;const t=e.get(s.messageId);null==t||null===(i=t.callback)||void 0===i||i.call(t,...s.callbackArgs)}else if("unhandledError"===s.type){var a;throw new Error(null===(a=s.error)||void 0===a?void 0:a.message)}}))}}var o=s(9933),h=s(3570),d=s(69118);function l(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}const c=Symbol("WAITING"),m=i.wB?.75:1,u=i.wZ?.5:.75,g=i.s$?2:4,p=new Map,f=new Array(4).fill(void 0).map((()=>new n(new Worker(new URL(s.p+s.u(2993),s.b)))));let v=-1;class x{static init(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];const[i,a,r,n,,o]=e;let h=p.get(n);return h?h.addContainer(i,a,r,null==o?void 0:o.coords):(h=new x(...e),p.set(n,h)),h}constructor(t,e,s,i,a,r={},n,o,h){this.id=i,this.tgsUrl=a,this.params=r,this.customColor=n,this.onEnded=o,this.onLoop=h,l(this,"containers",new Map),l(this,"imgSize",void 0),l(this,"imageData",void 0),l(this,"msPerFrame",1e3/60),l(this,"reduceFactor",1),l(this,"cacheModulo",void 0),l(this,"workerIndex",void 0),l(this,"frames",[]),l(this,"framesCount",void 0),l(this,"isAnimating",!1),l(this,"isWaiting",!0),l(this,"isEnded",!1),l(this,"isDestroyed",!1),l(this,"isRendererInited",!1),l(this,"approxFrameIndex",0),l(this,"prevFrameIndex",-1),l(this,"stopFrameIndex",0),l(this,"speed",1),l(this,"direction",1),l(this,"lastRenderAt",void 0),this.addContainer(t,e,s,r.coords),this.initConfig(),this.initRenderer()}removeContainer(t){const{canvas:e,ctx:s,isSharedCanvas:i,coords:a}=this.containers.get(t);i?s.clearRect(a.x,a.y,this.imgSize,this.imgSize):e.remove(),this.containers.delete(t),this.containers.size||this.destroy()}isPlaying(){return this.isAnimating||this.isWaiting}play(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=arguments.length>1?arguments[1]:void 0;e&&(this.containers.get(e).isPaused=!1),this.isEnded&&t&&(this.approxFrameIndex=Math.floor(0)),this.stopFrameIndex=void 0,this.direction=1,this.doPlay()}pause(t){t&&(this.containers.get(t).isPaused=!0,!Array.from(this.containers.values()).every((t=>{let{isPaused:e}=t;return e})))||(this.isWaiting?this.stopFrameIndex=this.approxFrameIndex:this.isAnimating=!1,this.params.isLowPriority||(this.frames=this.frames.map(((t,e)=>e===this.prevFrameIndex?t:void(t&&t!==c&&t.close())))))}playSegment(t){let[e,s]=t;this.approxFrameIndex=Math.floor(e/this.reduceFactor),this.stopFrameIndex=Math.floor(s/this.reduceFactor),this.direction=e<s?1:-1,this.doPlay()}setSpeed(t){this.speed=t}setNoLoop(t){this.params.noLoop=t}setSharedCanvasCoords(t,e){const s=this.containers.get(t),{canvas:a,ctx:r,isPaused:n,coords:o}=s;if(!a.dataset.isJustCleaned||"false"===a.dataset.isJustCleaned){const{isLowPriority:t,quality:e=(t?u:m)}=this.params,s=Math.max(i.cL*e,1);w(a,s),r.clearRect(0,0,a.width,a.height),a.dataset.isJustCleaned="true",(0,d.T2)((()=>{a.dataset.isJustCleaned="false"}))}if(s.coords={x:Math.round(((null==e?void 0:e.x)||0)*a.width),y:Math.round(((null==e?void 0:e.y)||0)*a.height)},n||!this.isPlaying()){const t=this.getFrame(this.prevFrameIndex)||this.getFrame(Math.round(this.approxFrameIndex));t&&t!==c&&r.drawImage(t,o.x,o.y)}}addContainer(t,e,s,a){const{isLowPriority:r,quality:n=(r?u:m)}=this.params;let o;const h=Math.max(i.cL*n,1);if(e instanceof HTMLDivElement){if(!(e.parentNode instanceof HTMLElement))throw new Error("[RLottie] Container is not mounted");let{size:i}=this.params;if(!i&&(i=e.offsetWidth||parseInt(e.style.width,10)||e.parentNode.offsetWidth,!i))throw new Error("[RLottie] Failed to detect width from container");const a=document.createElement("canvas"),r=a.getContext("2d");a.style.width=`${i}px`,a.style.height=`${i}px`,o=Math.round(i*h),a.width=o,a.height=o,e.appendChild(a),this.containers.set(t,{canvas:a,ctx:r,onLoad:s})}else{if(!e.offsetParent)throw new Error("[RLottie] Shared canvas is not mounted");const i=e,r=i.getContext("2d");w(i,h),o=Math.round(this.params.size*h),this.containers.set(t,{canvas:i,ctx:r,isSharedCanvas:!0,coords:{x:Math.round(((null==a?void 0:a.x)||0)*i.width),y:Math.round(((null==a?void 0:a.y)||0)*i.height)},onLoad:s})}this.imgSize||(this.imgSize=o,this.imageData=new ImageData(o,o)),this.isRendererInited&&this.doPlay()}destroy(){this.isDestroyed=!0,this.pause(),this.clearCache(),this.destroyRenderer(),p.delete(this.id)}clearCache(){this.frames.forEach((t=>{t&&t!==c&&t.close()})),this.imageData=void 0,this.frames=[]}initConfig(){const{isLowPriority:t}=this.params;this.cacheModulo=t?0:g}setColor(t){this.customColor=t}initRenderer(){this.workerIndex=(0,h.Z)(4,++v),f[this.workerIndex].request({name:"init",args:[this.id,this.tgsUrl,this.imgSize,this.params.isLowPriority,this.customColor,this.onRendererInit.bind(this)]})}destroyRenderer(){f[this.workerIndex].request({name:"destroy",args:[this.id]})}onRendererInit(t,e,s){this.isRendererInited=!0,this.reduceFactor=t,this.msPerFrame=e,this.framesCount=s,this.isWaiting&&this.doPlay()}changeData(t){this.pause(),this.tgsUrl=t,this.initConfig(),f[this.workerIndex].request({name:"changeData",args:[this.id,this.tgsUrl,this.params.isLowPriority,this.onChangeData.bind(this)]})}onChangeData(t,e,s){this.reduceFactor=t,this.msPerFrame=e,this.framesCount=s,this.isWaiting=!1,this.isAnimating=!1,this.doPlay()}doPlay(){this.framesCount&&(this.isDestroyed||this.isAnimating||(this.isWaiting||(this.lastRenderAt=void 0),this.isEnded=!1,this.isAnimating=!0,this.isWaiting=!1,(0,o.jt)((()=>{if(this.isDestroyed)return!1;if(!this.isAnimating)return!1;const t=Math.round(this.approxFrameIndex),e=this.getFrame(t);if(!e||e===c)return e||this.requestFrame(t),this.isAnimating=!1,this.isWaiting=!0,!1;this.cacheModulo&&t%this.cacheModulo==0&&this.cleanupPrevFrame(t),t!==this.prevFrameIndex&&(this.containers.forEach((t=>{const{ctx:s,isLoaded:i,isPaused:a,coords:{x:r,y:n}={},onLoad:o}=t;i&&a||(s.clearRect(r||0,n||0,this.imgSize,this.imgSize),s.drawImage(e,r||0,n||0)),i||(t.isLoaded=!0,null==o||o())})),this.prevFrameIndex=t);const s=Date.now(),i=this.lastRenderAt?this.msPerFrame/(s-this.lastRenderAt):1,a=Math.min(1,this.direction*this.speed/i),r=Math.round(this.approxFrameIndex+a);if(this.lastRenderAt=s,a>0&&(t===this.framesCount-1||r>this.framesCount-1)){var n,o;if(this.params.noLoop)return this.isAnimating=!1,this.isEnded=!0,null===(o=this.onEnded)||void 0===o||o.call(this),!1;null===(n=this.onLoop)||void 0===n||n.call(this),this.approxFrameIndex=0}else if(a<0&&(0===t||r<0)){var h,d;if(this.params.noLoop)return this.isAnimating=!1,this.isEnded=!0,null===(d=this.onEnded)||void 0===d||d.call(this),!1;null===(h=this.onLoop)||void 0===h||h.call(this),this.approxFrameIndex=this.framesCount-1}else{if(void 0!==this.stopFrameIndex&&(t===this.stopFrameIndex||a>0&&r>this.stopFrameIndex||a<0&&r<this.stopFrameIndex))return this.stopFrameIndex=void 0,this.isAnimating=!1,!1;this.approxFrameIndex+=a}const l=Math.round(this.approxFrameIndex);return!!this.getFrame(l)||(this.requestFrame(l),this.isWaiting=!0,this.isAnimating=!1,!1)}))))}getFrame(t){return this.frames[t]}requestFrame(t){this.frames[t]=c,f[this.workerIndex].request({name:"renderFrames",args:[this.id,t,this.onFrameLoad.bind(this)]})}cleanupPrevFrame(t){if(this.framesCount<3)return;const e=(0,h.Z)(this.framesCount,t-1);this.frames[e]=void 0}onFrameLoad(t,e){this.frames[t]===c&&(this.frames[t]=e,this.isWaiting&&this.doPlay())}}function w(t,e){const s=Math.round(t.offsetWidth*e),i=Math.round(t.offsetHeight*e);t.width===s&&t.height===i||(t.width=s,t.height=i)}const y=x},3570:(t,e,s)=>{function i(t,e){return e-Math.floor(e/t)*t}s.d(e,{Z:()=>i})}}]);
//# sourceMappingURL=7941.47f10f7fe9b15891eb31.js.map