TelegramPWA/dist/3748.f61e5faa4d7b4d3efc94.js
Alexander Zinchuk e952dc40d7 [Build]
2023-03-03 14:52:54 +01:00

2 lines
9.6 KiB
JavaScript

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