2 lines
7.8 KiB
JavaScript
2 lines
7.8 KiB
JavaScript
"use strict";(self.webpackChunktelegram_t=self.webpackChunktelegram_t||[]).push([[3748],{3748:(t,e,i)=>{i.r(e),i.d(e,{default:()=>I});var s=i(57710),r=i(863),a=i(9933),n=i(3570),o=i(26926),h=i(76857);function d(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 m=Symbol("WAITING"),c=r.wZ||r.cj?.75:1,l=r.wZ?.5:.75,u=24,g=r.s$?2:4,p={},v=(0,h.Z)().map((t=>{let{connector:e}=t;return e})),f=new Map;let x=-1;class w{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=(0,o.Z)(p,!0),,h]=e;let d=f.get(r);return d?d.addView(n,s,h,a?.coords):(d=new w(...e),f.set(r,d)),d}constructor(t,e,i,s){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,m=arguments.length>8?arguments[8]:void 0;this.tgsUrl=t,this.container=e,this.renderId=i,this.params=s,this.customColor=a,this.onLoad=n,this.onEnded=h,this.onLoop=m,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,s.coords),this.initConfig(),this.initRenderer()}removeView(t){const{canvas:e,ctx:i,isSharedCanvas:s,coords:r}=this.views.get(t);s?i.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.frames=this.frames.map(((t,e)=>e===this.prevFrameIndex?t:void(t&&t!==m&&t.close())))))}playSegment(t){let[e,i]=t,s=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2?arguments[2]:void 0;r&&(this.views.get(r).isPaused=!1);const a=Math.round(this.approxFrameIndex);this.stopFrameIndex=Math.floor(i/this.reduceFactor),(a!==i||s)&&(this.approxFrameIndex=Math.floor(e/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.views.get(t),{canvas:r,ctx:a}=i;let[n,o]=[r.width,r.height];if(!r.dataset.isJustCleaned||"false"===r.dataset.isJustCleaned){const t=this.calcSizeFactor();[n,o]=F(r,t),a.clearRect(0,0,n,o),r.dataset.isJustCleaned="true",(0,s.i$)((()=>{r.dataset.isJustCleaned="false"}))}i.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!==m&&a.drawImage(h,i.coords.x,i.coords.y)}addView(t,e,i,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,s.WM)((()=>{const s=document.createElement("canvas"),a=s.getContext("2d");s.style.width=`${r}px`,s.style.height=`${r}px`,s.width=n,s.height=n,e.appendChild(s),this.views.set(t,{canvas:s,ctx:a,onLoad:i})}))}else{if(!e.isConnected)throw new Error("[RLottie] Shared canvas is not mounted");const s=e,o=s.getContext("2d");n=Math.round(this.params.size*a),this.imgSize||(this.imgSize=n,this.imageData=new ImageData(n,n));const[h,d]=F(s,a);this.views.set(t,{canvas:s,ctx:o,isSharedCanvas:!0,coords:{x:Math.round(r.x*h),y:Math.round(r.y*d)},onLoad:i})}this.isRendererInited&&this.doPlay()}calcSizeFactor(){const{size:t,isLowPriority:e,quality:i=(e&&(!t||t>u)?l:c)}=this.params;return Math.max(r.cL*i,1)}destroy(){this.isDestroyed=!0,this.pause(),this.clearCache(),this.destroyRenderer(),f.delete(this.renderId)}clearCache(){this.frames.forEach((t=>{t&&t!==m&&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,++x),v[this.workerIndex].request({name:"rlottie:init",args:[this.renderId,this.tgsUrl,this.imgSize,this.params.isLowPriority||!1,this.customColor,this.onRendererInit.bind(this)]})}destroyRenderer(){v[this.workerIndex].request({name:"rlottie:destroy",args:[this.renderId]})}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(),v[this.workerIndex].request({name:"rlottie:changeData",args:[this.renderId,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.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===m)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: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)}),s.WM)))}getFrame(t){return this.frames[t]}requestFrame(t){this.frames[t]=m,v[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]===m&&(this.frames[t]=e,this.isWaiting&&this.doPlay())}}function F(t,e){const i=Math.round(t.offsetWidth*e),r=Math.round(t.offsetHeight*e);return t.width===i&&t.height===r||(0,s.WM)((()=>{t.width=i,t.height=r})),[i,r]}const I=w}}]);
|
|
//# sourceMappingURL=3748.2a758785549adbc8bfb9.js.map
|