TelegramPWA/dist/3748.0cbe1454538693e76a64.js
Alexander Zinchuk 2226feb98e [Build]
2023-04-27 01:48:35 +04:00

2 lines
10 KiB
JavaScript

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