2 lines
8.7 KiB
JavaScript
2 lines
8.7 KiB
JavaScript
"use strict";(self.webpackChunktelegram_t=self.webpackChunktelegram_t||[]).push([[7941],{67941:(t,e,s)=>{s.r(e),s.d(e,{default:()=>F});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=24,p=i.s$?2:4,f=new Map,v=new Array(4).fill(void 0).map((()=>new n(new Worker(new URL(s.p+s.u(2993),s.b)))));let x=-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,a,r,n,,o]=e;let h=f.get(n);return h?h.addContainer(i,a,r,null==o?void 0:o.coords):(h=new w(...e),f.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:i,ctx:a,isPaused:r,coords:n}=s;if(!i.dataset.isJustCleaned||"false"===i.dataset.isJustCleaned){const t=this.calcSizeFactor();y(i,t),a.clearRect(0,0,i.width,i.height),i.dataset.isJustCleaned="true",(0,d.T2)((()=>{i.dataset.isJustCleaned="false"}))}if(s.coords={x:Math.round(((null==e?void 0:e.x)||0)*i.width),y:Math.round(((null==e?void 0:e.y)||0)*i.height)},r||!this.isPlaying()){const t=this.getFrame(this.prevFrameIndex)||this.getFrame(Math.round(this.approxFrameIndex));t&&t!==c&&a.drawImage(t,n.x,n.y)}}addContainer(t,e,s,i){const a=this.calcSizeFactor();let r;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 n=document.createElement("canvas"),o=n.getContext("2d");n.style.width=`${i}px`,n.style.height=`${i}px`,r=Math.round(i*a),n.width=r,n.height=r,e.appendChild(n),this.containers.set(t,{canvas:n,ctx:o,onLoad:s})}else{if(!e.offsetParent)throw new Error("[RLottie] Shared canvas is not mounted");const n=e,o=n.getContext("2d");y(n,a),r=Math.round(this.params.size*a),this.containers.set(t,{canvas:n,ctx:o,isSharedCanvas:!0,coords:{x:Math.round(((null==i?void 0:i.x)||0)*n.width),y:Math.round(((null==i?void 0:i.y)||0)*n.height)},onLoad:s})}this.imgSize||(this.imgSize=r,this.imageData=new ImageData(r,r)),this.isRendererInited&&this.doPlay()}calcSizeFactor(){const{isLowPriority:t,size:e,quality:s=(t&&(!e||e>g)?u:m)}=this.params;return Math.max(i.cL*s,1)}destroy(){this.isDestroyed=!0,this.pause(),this.clearCache(),this.destroyRenderer(),f.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:p}setColor(t){this.customColor=t}initRenderer(){this.workerIndex=(0,h.Z)(4,++x),v[this.workerIndex].request({name:"init",args:[this.id,this.tgsUrl,this.imgSize,this.params.isLowPriority,this.customColor,this.onRendererInit.bind(this)]})}destroyRenderer(){v[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(),v[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,v[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 y(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 F=w},3570:(t,e,s)=>{function i(t,e){return e-Math.floor(e/t)*t}s.d(e,{Z:()=>i})}}]);
|
|
//# sourceMappingURL=7941.ae7dedc7950318e16ad9.js.map
|