2 lines
9.2 KiB
JavaScript
2 lines
9.2 KiB
JavaScript
"use strict";(self.webpackChunkmontana_messenger=self.webpackChunkmontana_messenger||[]).push([[6708],{66708(e,t,s){s.d(t,{default:()=>F});var i=s(19822),a=s(96454),r=s(67054),n=s(9705),o=s(14235),h=s(41074),d=s(66644);const c=Symbol("WAITING"),m=a.Ni||a.pz?.75:1,l=a.Ni?.5:.75,p=24,g=a.Yw?2:4,u=(0,h.Ay)().map(({connector:e})=>e),f=new Map,y=new WeakMap;let w=-1;class x{views=new Map;msPerFrame=1e3/60;reduceFactor=1;frames=[];isAnimating=!1;isWaiting=!0;isEnded=!1;isDestroyed=!1;isRendererInited=!1;approxFrameIndex=0;prevFrameIndex=-1;stopFrameIndex=0;speed=1;direction=1;requestedSeekToEnd=!1;static init(...e){const[,t,s,i,a=(0,o.A)(),,r,,,n]=e;let h=f.get(s);return h?h.addView(a,t,r,n,i?.coords):(h=new x(...e),f.set(s,h)),h}constructor(e,t,s,i,a=(0,o.A)(),r,n,h,d,c){this.tgsUrl=e,this.renderId=s,this.params=i,this.customColor=r,this.onEnded=h,this.onLoop=d,this.addView(a,t,n,c,i.coords),this.initConfig(),this.initRenderer()}removeView(e){const{canvas:t,ctx:s,isSharedCanvas:i,coords:a}=this.views.get(e);i?s.clearRect(a.x,a.y,this.imgSize,this.imgSize):t.remove(),this.views.delete(e),this.views.size||this.destroy()}isPlaying(){return this.isAnimating||this.isWaiting}play(e=!1,t){t&&(this.views.get(t).isPaused=!1),this.isEnded&&e&&(this.approxFrameIndex=Math.floor(0)),this.stopFrameIndex=void 0,this.direction=1,this.doPlay()}pause(e){this.lastRenderAt=void 0,(!e||(this.views.get(e).isPaused=!0,Array.from(this.views.values()).every(({isPaused:e})=>e)))&&(this.isWaiting?this.stopFrameIndex=this.approxFrameIndex:this.isAnimating=!1,this.params.isLowPriority||(this.frames=this.frames.map((e,t)=>t===this.prevFrameIndex?e:void(e&&e!==c&&e.close()))))}playSegment([e,t],s=!1,i){i&&(this.views.get(i).isPaused=!1);const a=Math.round(this.approxFrameIndex);this.stopFrameIndex=Math.floor(t/this.reduceFactor),(a!==t||s)&&(this.approxFrameIndex=Math.floor(e/this.reduceFactor)),this.direction=e<t?1:-1,this.doPlay()}seekToEnd(){this.requestedSeekToEnd=!0,this.doPlay()}setSpeed(e){this.speed=e}setNoLoop(e){this.params.noLoop=e}async setSharedCanvasCoords(e,t){const s=this.views.get(e),{canvas:i,ctx:a}=s,r=!i.dataset.isJustCleaned||"false"===i.dataset.isJustCleaned;r||await y.get(i);let[n,o]=[i.width,i.height];if(r){const e=this.calcSizeFactor();[n,o]=v(i,e),a.clearRect(0,0,n,o),i.dataset.isJustCleaned="true",(0,d.YS)(()=>{i.dataset.isJustCleaned="false"})}s.coords={x:Math.round((t?.x||0)*n),y:Math.round((t?.y||0)*o)};const h=this.getFrame(this.prevFrameIndex)||this.getFrame(Math.round(this.approxFrameIndex));h&&h!==c&&a.drawImage(h,s.coords.x,s.coords.y)}addView(e,t,s,i,a){const r=this.calcSizeFactor();let n;if(t instanceof HTMLDivElement){if(!(t.parentNode instanceof HTMLElement))throw new Error("[RLottie] Container is not mounted");const{size:a}=this.params;n=Math.round(a*r),this.imgSize||(this.imgSize=n,this.imageData=new ImageData(n,n)),(0,d.RK)(()=>{const r=document.createElement("canvas"),o=r.getContext("2d");r.classList.add("rlottie-canvas"),r.style.width=`${a}px`,r.style.height=`${a}px`,r.width=n,r.height=n,t.appendChild(r),this.views.set(e,{canvas:r,ctx:o,onLoad:s,onFrame:i})})}else{if(!t.isConnected)throw new Error("[RLottie] Shared canvas is not mounted");const i=t,o=i.getContext("2d");n=Math.round(this.params.size*r),this.imgSize||(this.imgSize=n,this.imageData=new ImageData(n,n));const[h,d]=v(i,r);this.views.set(e,{canvas:i,ctx:o,isSharedCanvas:!0,coords:{x:Math.round(a.x*h),y:Math.round(a.y*d)},onLoad:s})}this.isRendererInited&&this.doPlay()}calcSizeFactor(){const{size:e,isLowPriority:t,quality:s=(t&&(!e||e>p)?l:m)}=this.params;return Math.max(window.devicePixelRatio*s,1)}destroy(){this.isDestroyed=!0,this.pause(),this.clearCache(),this.destroyRenderer(),f.delete(this.renderId)}clearCache(){this.frames.forEach(e=>{e&&e!==c&&e.close()}),this.imageData=void 0,this.frames=[]}initConfig(){const{isLowPriority:e}=this.params;this.cacheModulo=e?0:g}setColor(e){this.customColor=e}initRenderer(){this.workerIndex=(0,r.A)(h.bP,++w),u[this.workerIndex].request({name:"rlottie:init",args:[this.renderId,this.tgsUrl,this.imgSize,this.params.isLowPriority||!1,this.customColor,this.onRendererInit.bind(this)]})}destroyRenderer(){u[this.workerIndex].request({name:"rlottie:destroy",args:[this.renderId]})}onRendererInit(e,t,s){this.isRendererInited=!0,this.reduceFactor=e,this.msPerFrame=t,this.framesCount=s,this.isWaiting&&this.doPlay()}changeData(e){this.pause(),this.tgsUrl=e,this.initConfig(),u[this.workerIndex].request({name:"rlottie:changeData",args:[this.renderId,this.tgsUrl,this.params.isLowPriority||!1,this.onChangeData.bind(this)]})}onChangeData(e,t,s){this.reduceFactor=e,this.msPerFrame=t,this.framesCount=s,this.isWaiting=!1,this.isAnimating=!1,this.doPlay()}doPlay(){this.framesCount&&(this.isDestroyed||(this.requestedSeekToEnd&&(this.approxFrameIndex=this.framesCount-1,this.stopFrameIndex=void 0,this.requestedSeekToEnd=!1),this.isAnimating||(this.isWaiting||(this.lastRenderAt=void 0),this.isEnded=!1,this.isAnimating=!0,this.isWaiting=!1,(0,i.i0)(()=>{if(this.isDestroyed)return!1;if(!this.isAnimating&&Array.from(this.views.values()).every(({isLoaded:e})=>e))return!1;const e=Math.round(this.approxFrameIndex),t=this.getFrame(e);if(!t||t===c)return t||this.requestFrame(e),this.isAnimating=!1,this.isWaiting=!0,!1;this.cacheModulo&&e%this.cacheModulo===0&&this.cleanupPrevFrame(e),e!==this.prevFrameIndex&&(this.views.forEach(s=>{const{ctx:i,isLoaded:a,isPaused:r,coords:{x:n,y:o}={},onLoad:h,onFrame:d}=s;a&&r||(i.clearRect(n||0,o||0,this.imgSize,this.imgSize),i.drawImage(t,n||0,o||0),d?.(e)),a||(s.isLoaded=!0,h?.())}),this.prevFrameIndex=e);const s=Date.now(),i=this.lastRenderAt?this.msPerFrame/(s-this.lastRenderAt):1,a=this.direction*this.speed/i,r=Math.round(this.approxFrameIndex+a);if(this.lastRenderAt=s,a>0&&(e===this.framesCount-1||r>this.framesCount-1)){if(this.params.noLoop)return this.isAnimating=!1,this.isEnded=!0,this.onEnded?.(),!1;this.onLoop?.(),this.approxFrameIndex=0}else if(a<0&&(0===e||r<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&&(e===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 n=Math.round(this.approxFrameIndex);return!!this.getFrame(n)||(this.requestFrame(n),this.isWaiting=!0,this.isAnimating=!1,!1)},d.RK))))}getFrame(e){return this.frames[e]}requestFrame(e){this.frames[e]=c,u[this.workerIndex].request({name:"rlottie:renderFrames",args:[this.renderId,e,this.onFrameLoad.bind(this)]})}cleanupPrevFrame(e){if(this.framesCount<3)return;const t=(0,r.A)(this.framesCount,e-1);this.frames[t]=void 0}onFrameLoad(e,t){this.frames[e]===c&&(this.frames[e]=t,this.isWaiting&&this.doPlay())}}function v(e,t){const s=Math.round(e.offsetWidth*t),i=Math.round(e.offsetHeight*t);if(e.width!==s||e.height!==i){const t=new n.A;y.set(e,t.promise),(0,d.RK)(()=>{e.width=s,e.height=i,t.resolve()})}return[s,i]}const F=x},5130(e,t,s){s.d(t,{U:()=>n});var i=s(14235),a=s(37836);class r{requestStates=new Map;requestStatesByCallback=new Map;pendingPayloads=[];pendingTransferables=[];constructor(e,t,s){this.target=e,this.onUpdate=t,this.channel=s}destroy(){}init(...e){this.postMessageOnTickEnd({type:"init",args:e})}request(e){const{requestStates:t,requestStatesByCallback:s}=this,{transferables:a,...r}=e,n=(0,i.A)(),o={type:"callMethod",messageId:n,...r},h={messageId:n},d=new Promise((e,t)=>{Object.assign(h,{resolve:e,reject:t})});if("function"==typeof o.args[o.args.length-1]){o.withCallback=!0;const e=o.args.pop();h.callback=e,s.set(e,h)}return t.set(n,h),d.catch(()=>{}).finally(()=>{t.delete(n),h.callback&&s.delete(h.callback)}),this.postMessageOnTickEnd(o,a),d}cancelCallback(e){e.isCanceled=!0;const{messageId:t}=this.requestStatesByCallback.get(e)||{};t&&this.postMessageOnTickEnd({type:"cancelProgress",messageId:t})}onMessage(e){const{requestStates:t,channel:s}=this;e.channel===s&&e.payloads.forEach(e=>{if("update"===e.type&&this.onUpdate&&this.onUpdate(e.update),"methodResponse"===e.type){const s=t.get(e.messageId);s&&(e.error?s.reject(e.error):s.resolve(e.response))}else if("methodCallback"===e.type){const s=t.get(e.messageId);s?.callback?.(...e.callbackArgs)}else if("unhandledError"===e.type)throw new Error(e.error?.message)})}postMessageOnTickEnd(e,t){this.pendingPayloads.push(e),t&&this.pendingTransferables.push(...t),this.postMessagesOnTickEnd()}postMessagesOnTickEnd=(0,a.Fe)(()=>{const{channel:e}=this,t=this.pendingPayloads,s=this.pendingTransferables;this.pendingPayloads=[],this.pendingTransferables=[],this.target.postMessage({channel:e,payloads:t},s)})}function n(e,t,s){const i=new r(e,t,s);function a({data:e}){i.onMessage(e)}return e.addEventListener("message",a),i.destroy=()=>{e.removeEventListener("message",a)},i}},67054(e,t,s){function i(e,t){return t-Math.floor(t/e)*e}s.d(t,{A:()=>i})},41074(e,t,s){s.d(t,{Ay:()=>o,M1:()=>h,bP:()=>r});var i=s(31481),a=s(5130);const r=Math.min(navigator.hardwareConcurrency||4,4);let n;function o(){return i.W75?[]:(n||(n=new Array(r).fill(void 0).map(()=>{const e=new Worker(new URL(s.p+s.u(6805),s.b));return{worker:e,connector:(0,a.U)(e,void 0,"media")}})),n)}function h(e,t){return o()[t].connector.request(e)}}}]);
|
|
//# sourceMappingURL=6708.bd8c12bd2ecfbe4af552.js.map
|