heic2any
Version:
Converting HEIC/HEIF to PNG/JPEG/GIF in the browser
1 lines • 1.35 MB
JavaScript
!function(r,H,a,U){"use strict";function o(){return b.isValid()}function k(){function m(r,a,A,e,i){var t,f,n,o,u,l,c;for((n=a-r)<-1&&(n=-1),s<(o=a+r)&&(o=s),t=a+1,f=a-1,l=1;t<o||n<f;){if(u=M[l++],t<o){c=W[t++];try{c[0]-=u*(c[0]-A)/b|0,c[1]-=u*(c[1]-e)/b|0,c[2]-=u*(c[2]-i)/b|0}catch(r){}}if(n<f){c=W[f--];try{c[0]-=u*(c[0]-A)/b|0,c[1]-=u*(c[1]-e)/b|0,c[2]-=u*(c[2]-i)/b|0}catch(r){}}}}function y(r,a,A){var e,i,t,f,n,o,u,l,c,b;for(c=l=~(1<<31),u=o=-1,e=0;e<s;e++)(i=(b=W[e])[0]-r)<0&&(i=-i),(t=b[1]-a)<0&&(t=-t),i+=t,(t=b[2]-A)<0&&(t=-t),(i+=t)<l&&(l=i,o=e),(f=i-(g[e]>>d-F))<c&&(c=f,u=e),n=J[e]>>h,J[e]-=n,g[e]+=n<<k;return J[o]+=v,g[o]-=w,u}var Z,p,E,B,W,s=256,X=499,G=491,I=487,V=503,C=3*V,o=s-1,F=4,R=100,d=16,t=1<<d,k=10,h=10,v=t>>h,w=t<<k-h,_=6,N=(s>>3)*(1<<_),Y=30,D=1024,Q=256,b=1<<18,l=[],g=[],J=[],M=[];(function(r,a,A){var e,i;for(p=r,E=a,B=A,W=new Array(s),e=0;e<s;e++)W[e]=new Array(4),(i=W[e])[0]=i[1]=i[2]=(e<<F+8)/s|0,J[e]=t/s|0,g[e]=0}).apply(this,arguments);var r={map:function(r,a,A){var e,i,t,f,n,o,u;for(n=1e3,u=-1,i=(e=l[a])-1;e<s||0<=i;)e<s&&(n<=(t=(o=W[e])[1]-a)?e=s:(e++,t<0&&(t=-t),(f=o[0]-r)<0&&(f=-f),(t+=f)<n&&((f=o[2]-A)<0&&(f=-f),(t+=f)<n&&(n=t,u=o[3])))),0<=i&&(n<=(t=a-(o=W[i])[1])?i=-1:(i--,t<0&&(t=-t),(f=o[0]-r)<0&&(f=-f),(t+=f)<n&&((f=o[2]-A)<0&&(f=-f),(t+=f)<n&&(n=t,u=o[3]))));return u}};return r.process=function(){return function(){var r,a,A,e,i,t,f,n,o,u,l,c,b,s,d,k,h,v,w,g;for(E<C&&(B=1),Z=30+(B-1)/3,c=p,u=(l=(s=E)/(3*B))/R|(b=0),n=D,(f=(t=N)>>_)<=1&&(f=0),r=0;r<f;r++)M[r]=n*((f*f-r*r)*Q/(f*f));for(o=E<C?3:E%X!=0?3*X:E%G!=0?3*G:E%I!=0?3*I:3*V,r=0;r<l;)if(a=y(A=(255&c[b+0])<<F,e=(255&c[b+1])<<F,i=(255&c[b+2])<<F),d=n,k=A,h=e,v=i,w=void 0,w=W[a],g=d/D,w[0]-=g*(w[0]-k)|0,w[1]-=g*(w[1]-h)|0,w[2]-=g*(w[2]-v)|0,0!==f&&m(f,a,A,e,i),s<=(b+=o)&&(b-=E),0===u&&(u=1),++r%u==0)for(n-=n/Z,(f=(t-=t/Y)>>_)<=1&&(f=0),a=0;a<f;a++)M[a]=n*((f*f-a*a)*Q/(f*f))}(),function(){var r;for(r=0;r<s;r++)W[r][0]>>=F,W[r][1]>>=F,W[r][2]>>=F,W[r][3]=r}(),function(){var r,a,A,e,i,t,f,n;for(r=n=f=0;r<s;r++){for(e=(i=W[A=r])[1],a=r+1;a<s;a++)(t=W[a])[1]<e&&(A=a,e=t[1]);if(t=W[A],r!=A&&(a=t[0],t[0]=i[0],i[0]=a,a=t[1],t[1]=i[1],i[1]=a,a=t[2],t[2]=i[2],i[2]=a,a=t[3],t[3]=i[3],i[3]=a),e!=f){for(l[f]=n+r>>1,a=f+1;a<e;a++)l[a]=r;f=e,n=r}}for(l[f]=n+o>>1,a=f+1;a<256;a++)l[a]=o}(),function(){for(var r=[],a=new Array(s),A=0;A<s;A++)a[W[A][3]]=A;for(var e=0,i=0;i<s;i++){var t=a[i];r[e++]=W[t][0],r[e++]=W[t][1],r[e++]=W[t][2]}return r}()},r}function u(){try{this.onmessage=function(r){var a,A=r.data||{};A.gifshot&&(a=e.run(A),postMessage(a))}}catch(r){}var e={dataToRGB:function(r,a,A){for(var e=a*A*4,i=0,t=[];i<e;)t.push(r[i++]),t.push(r[i++]),t.push(r[i++]),i++;return t},componentizedPaletteToArray:function(r){r=r||[];for(var a=[],A=0;A<r.length;A+=3){var e=r[A],i=r[A+1],t=r[A+2];a.push(e<<16|i<<8|t)}return a},processFrameWithQuantizer:function(r,a,A,e){for(var i=this.dataToRGB(r,a,A),t=new k(i,i.length,e),f=t.process(),n=new Uint32Array(this.componentizedPaletteToArray(f)),o=a*A,u=new Uint8Array(o),l=0,c=0;c<o;c++){var b=i[l++],s=i[l++],d=i[l++];u[c]=t.map(b,s,d)}return{pixels:u,palette:n}},run:function(r){r=r||{};var a=r.height,A=(r.palette,r.sampleInterval),e=r.width,i=r.data;return this.processFrameWithQuantizer(i,e,a,A)}};return e}function d(v,r,a,A){var w=0,e=(A=A===U?{}:A).loop===U?null:A.loop,g=A.palette===U?null:A.palette;if(r<=0||a<=0||65535<r||65535<a)throw"Width/Height invalid.";v[w++]=71,v[w++]=73,v[w++]=70,v[w++]=56,v[w++]=57,v[w++]=97;if(v[w++]=255&r,v[w++]=r>>8&255,v[w++]=255&a,v[w++]=a>>8&255,v[w++]=0|(null!==g?128:0),v[w++]=0,v[w++]=0,null!==e){if(e<0||65535<e)throw"Loop count invalid.";v[w++]=33,v[w++]=255,v[w++]=11,v[w++]=78,v[w++]=69,v[w++]=84,v[w++]=83,v[w++]=67,v[w++]=65,v[w++]=80,v[w++]=69,v[w++]=50,v[w++]=46,v[w++]=48,v[w++]=3,v[w++]=1,v[w++]=255&e,v[w++]=e>>8&255,v[w++]=0}var m=!1;this.addFrame=function(r,a,A,e,i,t){if(!0===m&&(--w,m=!1),t=t===U?{}:t,r<0||a<0||65535<r||65535<a)throw"x/y invalid.";if(A<=0||e<=0||65535<A||65535<e)throw"Width/Height invalid.";if(i.length<A*e)throw"Not enough pixels for the frame size.";var f=!0,n=t.palette;if(n!==U&&null!==n||(f=!1,n=g),n===U||null===n)throw"Must supply either a local or global palette.";for(var o=function(r){var a=r.length;if(a<2||256<a||a&a-1)throw"Invalid code/color length, must be power of 2 and 2 .. 256.";return a}(n),u=0;o>>=1;)++u;o=1<<u;var l=t.delay===U?0:t.delay,c=t.disposal===U?0:t.disposal;if(c<0||3<c)throw"Disposal out of range.";var b=!1,s=0;if(t.transparent!==U&&null!==t.transparent&&(b=!0,(s=t.transparent)<0||o<=s))throw"Transparent color index.";if(0===c&&!b&&0===l||(v[w++]=33,v[w++]=249,v[w++]=4,v[w++]=c<<2|(!0===b?1:0),v[w++]=255&l,v[w++]=l>>8&255,v[w++]=s,v[w++]=0),v[w++]=44,v[w++]=255&r,v[w++]=r>>8&255,v[w++]=255&a,v[w++]=a>>8&255,v[w++]=255&A,v[w++]=A>>8&255,v[w++]=255&e,v[w++]=e>>8&255,v[w++]=!0===f?128|u-1:0,!0===f)for(var d=0,k=n.length;d<k;++d){var h=n[d];v[w++]=h>>16&255,v[w++]=h>>8&255,v[w++]=255&h}w=function(a,A,r,e){function i(r){for(;r<=b;)a[A++]=255&s,s>>=8,b-=8,A===f+256&&(a[f]=255,f=A++)}function t(r){s|=r<<b,b+=c,i(8)}a[A++]=r;var f=A++,n=1<<r,o=n-1,u=1+n,l=1+u,c=r+1,b=0,s=0,d=e[0]&o,k={};t(n);for(var h=1,v=e.length;h<v;++h){var w=e[h]&o,g=d<<8|w,m=k[g];if(m===U){for(s|=d<<b,b+=c;8<=b;)a[A++]=255&s,s>>=8,b-=8,A===f+256&&(a[f]=255,f=A++);4096===l?(t(n),l=1+u,c=r+1,k={}):(1<<c<=l&&++c,k[g]=l++),d=w}else d=m}return t(d),t(u),i(1),f+1===A?a[f]=0:(a[f]=A-f-1,a[A++]=0),A}(v,w,u<2?2:u,i)},this.end=function(){return!1===m&&(v[w++]=59,m=!0),w}}function l(r){function i(){var a;S.each(o,function(r,a){a&&(a.text?c.addFrame(a.img,f,a.text):c.addFrame(a,f))}),a=t,c.getBase64GIF(function(r){a({error:!1,errorCode:"",errorMsg:"",image:r})})}var a=0<arguments.length&&r!==U?r:{},t=a.callback,A=a.images,f=a.options,n=a.imagesLength,e=b.validate({getUserMedia:!0,"window.URL":!0}),o=[],u=0,l=void 0,c=void 0;return e.error?t(e):(c=new P(f),void S.each(A,function(r,a){var A,e=a;a.src&&(e=e.src),S.isElement(e)?(f.crossOrigin&&(e.crossOrigin=f.crossOrigin),o[r]=e,(u+=1)===n&&i()):S.isString(e)&&(l=new Image,f.crossOrigin&&(l.crossOrigin=f.crossOrigin),A=l,a.text&&(A.text=a.text),A.onerror=function(){var r=void 0;return 0===--n?((r={}).error="None of the requested images was capable of being retrieved",t(r)):void 0},A.onload=function(){o[r]=a.text?{img:A,text:A.text}:A,(u+=1)===n&&i(),S.removeElement(A)},A.src=e,S.setCSSAttr(l,{position:"fixed",opacity:"0"}),H.body.appendChild(l))}))}function s(r){r=S.isObject(r)?r:{},m.stopVideoStreaming(r)}function c(r,a){var A=r.options||{},e=A.images,i=A.video,t=Number(A.gifWidth),f=Number(A.gifHeight),n=(Number(A.numFrames),r.cameraStream),o=r.videoElement,u=r.videoWidth,l=r.videoHeight,c=g.getCropDimensions({videoWidth:u,videoHeight:l,gifHeight:f,gifWidth:t}),b=a;A.crop=c,A.videoElement=o,A.videoWidth=u,A.videoHeight=l,A.cameraStream=n,S.isElement(o)&&(o.width=t+c.width,o.height=f+c.height,A.webcamVideoElement||(S.setCSSAttr(o,{position:"fixed",opacity:"0"}),H.body.appendChild(o)),o.play(),g.getGIF(A,function(r){e&&e.length||i&&i.length||s(r),b(r)}))}function e(r,a){if(a=S.isFunction(r)?r:a,r=S.isObject(r)?r:{},S.isFunction(a)){var A=S.mergeOptions(v,r)||{},e=r.cameraStream,i=A.images,t=i?i.length:0,f=A.video,n=A.webcamVideoElement;A=S.mergeOptions(A,{gifWidth:Math.floor(A.gifWidth),gifHeight:Math.floor(A.gifHeight)}),t?l({images:i,imagesLength:t,callback:a,options:A}):f?function(r){var a=0<arguments.length&&r!==U?r:{},A=a.callback,e=a.existingVideo,i=a.options,t=b.validate({getUserMedia:!0,"window.URL":!0}),f=void 0,n=void 0;if(t.error)return A(t);if(S.isElement(e)&&e.src){if(n=e.src,f=S.getExtension(n),!S.isSupported.videoCodecs[f])return A(b.messages.videoCodecs)}else S.isArray(e)&&S.each(e,function(r,a){return f=a instanceof Blob?a.type.substr(a.type.lastIndexOf("/")+1,a.length):a.substr(a.lastIndexOf(".")+1,a.length),S.isSupported.videoCodecs[f]?(e=a,!1):void 0});m.startStreaming({completed:function(r){r.options=i||{},c(r,A)},existingVideo:e,crossOrigin:i.crossOrigin,options:i})}({existingVideo:f,callback:a,options:A}):function(r){var a=0<arguments.length&&r!==U?r:{},A=a.callback,e=a.lastCameraStream,i=a.options,t=a.webcamVideoElement;o()?i.savedRenderingContexts.length?g.getGIF(i,function(r){A(r)}):m.startVideoStreaming(function(){var r=0<arguments.length&&arguments[0]!==U?arguments[0]:{};r.options=i||{},c(r,A)},{lastCameraStream:e,callback:A,webcamVideoElement:t,crossOrigin:i.crossOrigin}):A(b.validate())}({lastCameraStream:e,callback:a,webcamVideoElement:n,options:A})}}function A(){}function i(){}var t,f,S={URL:r.URL||r.webkitURL||r.mozURL||r.msURL,getUserMedia:(f=a.getUserMedia||a.webkitGetUserMedia||a.mozGetUserMedia||a.msGetUserMedia)?f.bind(a):f,requestAnimFrame:r.requestAnimationFrame||r.webkitRequestAnimationFrame||r.mozRequestAnimationFrame||r.oRequestAnimationFrame||r.msRequestAnimationFrame,requestTimeout:function(A,e){if(A=A||S.noop,e=e||0,!S.requestAnimFrame)return setTimeout(A,e);var i=(new Date).getTime(),t=new Object,f=S.requestAnimFrame;return t.value=f(function r(){var a=(new Date).getTime();e<=a-i?A.call():t.value=f(r)}),t},Blob:r.Blob||r.BlobBuilder||r.WebKitBlobBuilder||r.MozBlobBuilder||r.MSBlobBuilder,btoa:(t=r.btoa||function(r){for(var a="",A=0,e=r.length,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",t=void 0,f=void 0,n=void 0,o=void 0,u=void 0,l=void 0,c=void 0;A<e;)o=(t=r.charCodeAt(A++))>>2,u=(3&t)<<4|(f=r.charCodeAt(A++))>>4,l=(15&f)<<2|(n=r.charCodeAt(A++))>>6,c=63&n,isNaN(f)?l=c=64:isNaN(n)&&(c=64),a=a+i.charAt(o)+i.charAt(u)+i.charAt(l)+i.charAt(c);return a})?t.bind(r):S.noop,isObject:function(r){return r&&"[object Object]"===Object.prototype.toString.call(r)},isEmptyObject:function(r){return S.isObject(r)&&!Object.keys(r).length},isArray:function(r){return r&&Array.isArray(r)},isFunction:function(r){return r&&"function"==typeof r},isElement:function(r){return r&&1===r.nodeType},isString:function(r){return"string"==typeof r||"[object String]"===Object.prototype.toString.call(r)},isSupported:{canvas:function(){var r=H.createElement("canvas");return r&&r.getContext&&r.getContext("2d")},webworkers:function(){return r.Worker},blob:function(){return S.Blob},Uint8Array:function(){return r.Uint8Array},Uint32Array:function(){return r.Uint32Array},videoCodecs:function(){var r=H.createElement("video"),a={mp4:!1,h264:!1,ogv:!1,ogg:!1,webm:!1};try{r&&r.canPlayType&&(a.mp4=""!==r.canPlayType('video/mp4; codecs="mp4v.20.8"'),a.h264=""!==(r.canPlayType('video/mp4; codecs="avc1.42E01E"')||r.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"')),a.ogv=""!==r.canPlayType('video/ogg; codecs="theora"'),a.ogg=""!==r.canPlayType('video/ogg; codecs="theora"'),a.webm=-1!==r.canPlayType('video/webm; codecs="vp8, vorbis"'))}catch(r){}return a}()},noop:function(){},each:function(r,a){var A=void 0,e=void 0;if(S.isArray(r))for(A=-1,e=r.length;++A<e&&!1!==a(A,r[A]););else if(S.isObject(r))for(A in r)if(r.hasOwnProperty(A)&&!1===a(A,r[A]))break},mergeOptions:function(A,e){if(S.isObject(A)&&S.isObject(e)&&Object.keys){var i={};return S.each(A,function(r){i[r]=A[r]}),S.each(e,function(r){var a=e[r];i[r]=S.isObject(a)&&A[r]?S.mergeOptions(A[r],a):a}),i}},setCSSAttr:function(A,r,a){S.isElement(A)&&(S.isString(r)&&S.isString(a)?A.style[r]=a:S.isObject(r)&&S.each(r,function(r,a){A.style[r]=a}))},removeElement:function(r){S.isElement(r)&&r.parentNode&&r.parentNode.removeChild(r)},createWebWorker:function(r){if(!S.isString(r))return{};try{var a=new S.Blob([r],{type:"text/javascript"}),A=S.URL.createObjectURL(a);return{objectUrl:A,worker:new Worker(A)}}catch(r){return""+r}},getExtension:function(r){return r.substr(r.lastIndexOf(".")+1,r.length)},getFontSize:function(){var r=0<arguments.length&&arguments[0]!==U?arguments[0]:{};if(!H.body||!1===r.resizeFont)return r.fontSize;var a=r.text,A=r.gifWidth,e=parseInt(r.fontSize,10),i=parseInt(r.minFontSize,10),t=H.createElement("div"),f=H.createElement("span");for(t.setAttribute("width",A),t.appendChild(f),f.innerHTML=a,f.style.fontSize=e+"px",f.style.textIndent="-9999px",f.style.visibility="hidden",H.body.appendChild(f);f.offsetWidth>A&&i<=e;)f.style.fontSize=--e+"px";return H.body.removeChild(f),e+"px"},webWorkerError:!1},n=Object.freeze({default:S}),b={validate:function(e){e=S.isObject(e)?e:{};var i={};return S.each(b.validators,function(r,a){var A=a.errorCode;return e[A]||a.condition?void 0:!((i=a).error=!0)}),delete i.condition,i},isValid:function(r){var a=!0!==b.validate(r).error;return a},validators:[{condition:S.isFunction(S.getUserMedia),errorCode:"getUserMedia",errorMsg:"The getUserMedia API is not supported in your browser"},{condition:S.isSupported.canvas(),errorCode:"canvas",errorMsg:"Canvas elements are not supported in your browser"},{condition:S.isSupported.webworkers(),errorCode:"webworkers",errorMsg:"The Web Workers API is not supported in your browser"},{condition:S.isFunction(S.URL),errorCode:"window.URL",errorMsg:"The window.URL API is not supported in your browser"},{condition:S.isSupported.blob(),errorCode:"window.Blob",errorMsg:"The window.Blob File API is not supported in your browser"},{condition:S.isSupported.Uint8Array(),errorCode:"window.Uint8Array",errorMsg:"The window.Uint8Array function constructor is not supported in your browser"},{condition:S.isSupported.Uint32Array(),errorCode:"window.Uint32Array",errorMsg:"The window.Uint32Array function constructor is not supported in your browser"}],messages:{videoCodecs:{errorCode:"videocodec",errorMsg:"The video codec you are trying to use is not supported in your browser"}}},h=Object.freeze({default:b}),v={sampleInterval:10,numWorkers:2,filter:"",gifWidth:200,gifHeight:200,interval:.1,numFrames:10,frameDuration:1,keepCameraOn:!1,images:[],video:null,webcamVideoElement:null,cameraStream:null,text:"",fontWeight:"normal",fontSize:"16px",minFontSize:"10px",resizeFont:!1,fontFamily:"sans-serif",fontColor:"#ffffff",textAlign:"center",textBaseline:"bottom",textXCoordinate:null,textYCoordinate:null,progressCallback:A,completeCallback:A,saveRenderingContexts:!1,savedRenderingContexts:[],showFrameText:!0,crossOrigin:"Anonymous",waterMark:null,waterMarkHeight:null,waterMarkWidth:null,waterMarkXCoordinate:1,waterMarkYCoordinate:1},w=Object.freeze({default:v}),P=function(r){this.canvas=null,this.ctx=null,this.repeat=0,this.frames=[],this.numRenderedFrames=0,this.onRenderCompleteCallback=i,this.onRenderProgressCallback=i,this.workers=[],this.availableWorkers=[],this.generatingGIF=!1,this.options=r,this.initializeWebWorkers(r)};P.prototype={workerMethods:u(),initializeWebWorkers:function(r){var a,A=k.toString()+"("+u.toString()+"());",e=void 0,i=void 0,t=void 0,f=-1,n="";for(a=r.numWorkers;++f<a;)e=S.createWebWorker(A),S.isObject(e)?(i=e.objectUrl,t=e.worker,this.workers.push({worker:t,objectUrl:i}),this.availableWorkers.push(t)):(n=e,S.webWorkerError=!!e);this.workerError=n,this.canvas=H.createElement("canvas"),this.canvas.width=r.gifWidth,this.canvas.height=r.gifHeight,this.ctx=this.canvas.getContext("2d"),this.frames=[]},getWorker:function(){return this.availableWorkers.pop()},freeWorker:function(r){this.availableWorkers.push(r)},byteMap:function(){for(var r=[],a=0;a<256;a++)r[a]=String.fromCharCode(a);return r}(),bufferToString:function(r){for(var a=r.length,A="",e=-1;++e<a;)A+=this.byteMap[r[e]];return A},onFrameFinished:function(r){var a=this,A=a.frames,e=!!(a.options.images||[]).length,i=A.every(function(r){return!r.beingProcessed&&r.done});a.numRenderedFrames++,e&&r(a.numRenderedFrames/A.length),a.onRenderProgressCallback(.75*a.numRenderedFrames/A.length),i?a.generatingGIF||a.generateGIF(A,a.onRenderCompleteCallback):S.requestTimeout(function(){a.processNextFrame()},1)},processFrame:function(r){function a(){var r=(0<arguments.length&&arguments[0]!==U?arguments[0]:{}).data;delete n.data,n.pixels=Array.prototype.slice.call(r.pixels),n.palette=Array.prototype.slice.call(r.palette),n.done=!0,n.beingProcessed=!1,A.freeWorker(o),A.onFrameFinished(i)}var A=this,e=(this.options,this.options),i=e.progressCallback,t=e.sampleInterval,f=this.frames,n=void 0,o=void 0;return(n=f[r]).beingProcessed||n.done?void this.onFrameFinished():(n.sampleInterval=t,n.beingProcessed=!0,n.gifshot=!0,void((o=this.getWorker())?(o.onmessage=a,o.postMessage(n)):a({data:A.workerMethods.run(n)})))},startRendering:function(r){this.onRenderCompleteCallback=r;for(var a=0;a<this.options.numWorkers&&a<this.frames.length;a++)this.processFrame(a)},processNextFrame:function(){for(var r=-1,a=0;a<this.frames.length;a++){var A=this.frames[a];if(!A.done&&!A.beingProcessed){r=a;break}}0<=r&&this.processFrame(r)},generateGIF:function(i,r){var a=[],A={loop:this.repeat},e=this.options,t=e.interval,f=e.frameDuration,n=!!e.images.length,o=e.gifHeight,u=e.gifWidth,l=new d(a,u,o,A),c=this.onRenderProgressCallback,b=n?100*t:0,s=void 0;this.generatingGIF=!0,S.each(i,function(r,a){var A=a.palette;c(.75+.25*a.position*1/i.length);for(var e=0;e<f;e++)l.addFrame(0,0,u,o,a.pixels,{palette:A,delay:b})}),l.end(),c(1),this.frames=[],this.generatingGIF=!1,S.isFunction(r)&&(s=this.bufferToString(a),r("data:image/gif;base64,"+S.btoa(s)))},setRepeat:function(r){this.repeat=r},addFrame:function(r,a,A){a=S.isObject(a)?a:{};var e=this.ctx,i=this.options,t=i.gifWidth,f=i.gifHeight,n=S.getFontSize(a),o=a.filter,u=a.fontColor,l=a.fontFamily,c=a.fontWeight,b=(a.gifHeight,a.gifWidth,a.text),s=a.textAlign,d=a.textBaseline,k=a.waterMark,h=a.waterMarkHeight,v=a.waterMarkWidth,w=a.waterMarkXCoordinate,g=a.waterMarkYCoordinate,m=a.textXCoordinate?a.textXCoordinate:"left"===s?1:"right"===s?t:t/2,y=a.textYCoordinate?a.textYCoordinate:"top"===d?1:"center"===d?f/2:f,Z=c+" "+n+" "+l,p=A&&a.showFrameText?A:b,E=void 0;try{e.filter=o,e.drawImage(r,0,0,t,f),p&&(e.font=Z,e.fillStyle=u,e.textAlign=s,e.textBaseline=d,e.fillText(p,m,y)),k&&e.drawImage(k,w,g,v,h),E=e.getImageData(0,0,t,f),this.addFrameImageData(E)}catch(r){return""+r}},addFrameImageData:function(){var r=0<arguments.length&&arguments[0]!==U?arguments[0]:{},a=this.frames,A=r.data;this.frames.push({data:A,width:r.width,height:r.height,palette:null,dithering:null,done:!1,beingProcessed:!1,position:a.length})},onRenderProgress:function(r){this.onRenderProgressCallback=r},isRendering:function(){return this.generatingGIF},getBase64GIF:function(a){var A=this;A.startRendering(function(r){A.destroyWorkers(),S.requestTimeout(function(){a(r)},0)})},destroyWorkers:function(){if(!this.workerError){var r=this.workers;S.each(r,function(r,a){var A=a.worker,e=a.objectUrl;A.terminate(),S.URL.revokeObjectURL(e)})}}};function x(){}var g={getGIF:function(){var r=0<arguments.length&&arguments[0]!==U?arguments[0]:{},e=arguments[1];e=S.isFunction(e)?e:x;var a=H.createElement("canvas"),i=void 0,A=!!r.images.length,t=r.cameraStream,f=r.crop,n=r.filter,o=r.fontColor,u=r.fontFamily,l=r.fontWeight,c=r.keepCameraOn,b=(r.numWorkers,r.progressCallback),s=r.saveRenderingContexts,d=r.savedRenderingContexts,k=r.text,h=r.textAlign,v=r.textBaseline,w=r.videoElement,g=r.videoHeight,m=r.videoWidth,y=r.webcamVideoElement,Z=r.waterMark,p=r.waterMarkHeight,E=r.waterMarkWidth,B=r.waterMarkXCoordinate,W=r.waterMarkYCoordinate,X=Number(r.gifWidth),G=Number(r.gifHeight),I=Number(r.interval),V=(Number(r.sampleInterval),A?0:1e3*I),C=[],F=d.length?d.length:r.numFrames,R=F,_=new P(r),N=S.getFontSize(r),Y=r.textXCoordinate?r.textXCoordinate:"left"===h?1:"right"===h?X:X/2,D=r.textYCoordinate?r.textYCoordinate:"top"===v?1:"center"===v?G/2:G,Q=l+" "+N+" "+u,J=f?Math.floor(f.scaledWidth/2):0,M=f?m-f.scaledWidth:0,j=f?Math.floor(f.scaledHeight/2):0,T=f?g-f.scaledHeight:0;F=F!==U?F:10,I=I!==U?I:.1,a.width=X,a.height=G,i=a.getContext("2d"),function r(){return d.length||0!==w.currentTime?void function a(){function r(){var r;s&&C.push(i.getImageData(0,0,X,G)),Z&&i.drawImage(Z,B,W,E,p),k&&(i.font=Q,i.fillStyle=o,i.textAlign=h,i.textBaseline=v,i.fillText(k,Y,D)),r=i.getImageData(0,0,X,G),_.addFrameImageData(r),b((F-(R=A))/F),0<A&&S.requestTimeout(a,V),R||_.getBase64GIF(function(r){e({error:!1,errorCode:"",errorMsg:"",image:r,cameraStream:t,videoElement:w,webcamVideoElement:y,savedRenderingContexts:C,keepCameraOn:c})})}var A=R-1;d.length?(i.putImageData(d[F-R],0,0),r()):function a(){try{m<M&&(M=m),g<T&&(T=g),J<0&&(J=0),j<0&&(j=0),i.filter=n,i.drawImage(w,J,j,M,T,0,0,X,G),r()}catch(r){if("NS_ERROR_NOT_AVAILABLE"!==r.name)throw r;S.requestTimeout(a,100)}}()}():void S.requestTimeout(r,100)}()},getCropDimensions:function(){var r=0<arguments.length&&arguments[0]!==U?arguments[0]:{},a=r.videoWidth,A=r.videoHeight,e=r.gifWidth,i=r.gifHeight,t={width:0,height:0,scaledWidth:0,scaledHeight:0};return A<a?(t.width=Math.round(a*(i/A))-e,t.scaledWidth=Math.round(t.width*(A/i))):(t.height=Math.round(A*(e/a))-i,t.scaledHeight=Math.round(t.height*(a/e))),t}},m={loadedData:!1,defaultVideoDimensions:{width:640,height:480},findVideoSize:function r(a){r.attempts=r.attempts||0;var A=a.cameraStream,e=a.completedCallback,i=a.videoElement;i&&(0<i.videoWidth&&0<i.videoHeight?(i.removeEventListener("loadeddata",m.findVideoSize),e({videoElement:i,cameraStream:A,videoWidth:i.videoWidth,videoHeight:i.videoHeight})):r.attempts<10?(r.attempts+=1,S.requestTimeout(function(){m.findVideoSize(a)},400)):e({videoElement:i,cameraStream:A,videoWidth:m.defaultVideoDimensions.width,videoHeight:m.defaultVideoDimensions.height}))},onStreamingTimeout:function(r){S.isFunction(r)&&r({error:!0,errorCode:"getUserMedia",errorMsg:"There was an issue with the getUserMedia API - Timed out while trying to start streaming",image:null,cameraStream:{}})},stream:function(r){var a=S.isArray(r.existingVideo)?r.existingVideo[0]:r.existingVideo,A=r.cameraStream,e=r.completedCallback,i=r.streamedCallback,t=r.videoElement;if(S.isFunction(i)&&i(),a){if(S.isString(a))t.src=a,t.innerHTML='<source src="'+a+'" type="video/'+S.getExtension(a)+'" />';else if(a instanceof Blob){try{t.src=S.URL.createObjectURL(a)}catch(r){}t.innerHTML='<source src="'+a+'" type="'+a.type+'" />'}}else if(t.mozSrcObject)t.mozSrcObject=A;else if(S.URL)try{t.srcObject=A,t.src=S.URL.createObjectURL(A)}catch(r){t.srcObject=A}t.play(),S.requestTimeout(function r(){r.count=r.count||0,!0===m.loadedData?(m.findVideoSize({videoElement:t,cameraStream:A,completedCallback:e}),m.loadedData=!1):10<(r.count+=1)?m.findVideoSize({videoElement:t,cameraStream:A,completedCallback:e}):r()},0)},startStreaming:function(r){var a=S.isFunction(r.error)?r.error:S.noop,A=S.isFunction(r.streamed)?r.streamed:S.noop,e=S.isFunction(r.completed)?r.completed:S.noop,i=r.crossOrigin,t=r.existingVideo,f=r.lastCameraStream,n=r.options,o=r.webcamVideoElement,u=S.isElement(t)?t:o||H.createElement("video");i&&(u.crossOrigin=n.crossOrigin),u.autoplay=!0,u.loop=!0,u.muted=!0,u.addEventListener("loadeddata",function(){m.loadedData=!0,n.offset&&(u.currentTime=n.offset)}),t?m.stream({videoElement:u,existingVideo:t,completedCallback:e}):f?m.stream({videoElement:u,cameraStream:f,streamedCallback:A,completedCallback:e}):S.getUserMedia({video:!0},function(r){m.stream({videoElement:u,cameraStream:r,streamedCallback:A,completedCallback:e})},a)},startVideoStreaming:function(t){var r=1<arguments.length&&arguments[1]!==U?arguments[1]:{},a=r.timeout!==U?r.timeout:0,A=r.callback,e=r.webcamVideoElement,i=void 0;0<a&&(i=S.requestTimeout(function(){m.onStreamingTimeout(A)},1e4)),m.startStreaming({error:function(){A({error:!0,errorCode:"getUserMedia",errorMsg:"There was an issue with the getUserMedia API - the user probably denied permission",image:null,cameraStream:{}})},streamed:function(){clearTimeout(i)},completed:function(){var r=0<arguments.length&&arguments[0]!==U?arguments[0]:{},a=r.cameraStream,A=r.videoElement,e=r.videoHeight,i=r.videoWidth;t({cameraStream:a,videoElement:A,videoHeight:e,videoWidth:i})},lastCameraStream:r.lastCameraStream,webcamVideoElement:e,crossOrigin:r.crossOrigin,options:r})},stopVideoStreaming:function(r){r=S.isObject(r)?r:{};var a=r.keepCameraOn,A=r.videoElement,e=r.webcamVideoElement,i=r.cameraStream||{},t=i.getTracks&&i.getTracks()||[],f=t[0];!a&&t.length&&S.isFunction(f.stop)&&f.stop(),S.isElement(A)&&!e&&(A.pause(),S.isFunction(S.URL.revokeObjectURL)&&!S.webWorkerError&&A.src&&S.URL.revokeObjectURL(A.src),S.removeElement(A))}},y={utils:n,error:h,defaultOptions:w,createGIF:e,takeSnapShot:function(r,a){if(a=S.isFunction(r)?r:a,r=S.isObject(r)?r:{},S.isFunction(a)){var A=S.mergeOptions(v,r);e(S.mergeOptions(A,{interval:.1,numFrames:1,gifWidth:Math.floor(A.gifWidth),gifHeight:Math.floor(A.gifHeight)}),a)}},stopVideoStreaming:s,isSupported:function(){return b.isValid()},isWebCamGIFSupported:o,isExistingVideoGIFSupported:function(r){var A=!1;if(S.isArray(r)&&r.length){if(S.each(r,function(r,a){S.isSupported.videoCodecs[a]&&(A=!0)}),!A)return!1}else if(S.isString(r)&&r.length&&!S.isSupported.videoCodecs[r])return!1;return b.isValid({getUserMedia:!0})},isExistingImagesGIFSupported:function(){return b.isValid({getUserMedia:!0})},VERSION:"0.4.5"};"function"==typeof define&&define.amd?define([],function(){return y}):"undefined"!=typeof exports?module.exports=y:r.gifshot=y}("undefined"!=typeof window?window:{},"undefined"!=typeof document?document:{createElement:function(){}},"undefined"!=typeof window?window.navigator:{}),function(r,a){"object"==typeof exports&&"undefined"!=typeof module?(module.exports=a(),module.exports.default=a()):"function"==typeof define&&define.amd?define(a):(r=r||self).heic2any=a()}(this,function(){"use strict";var r=new Blob(['\nvar Module=void 0!==Module?Module:{};(function(){var d={print:function(A){A=Array.prototype.slice.call(arguments).join(" "),console.log(A)},printErr:function(A){A=Array.prototype.slice.call(arguments).join(" "),console.error(A)},canvas:{},noInitialRun:!0},A={};for(Sr in d)d.hasOwnProperty(Sr)&&(A[Sr]=d[Sr]);var i,f,e=!1,l=!1,o=!1,r=!1;if(d.ENVIRONMENT)if("WEB"===d.ENVIRONMENT)e=!0;else if("WORKER"===d.ENVIRONMENT)l=!0;else if("NODE"===d.ENVIRONMENT)o=!0;else{if("SHELL"!==d.ENVIRONMENT)throw new Error("The provided Module[\'ENVIRONMENT\'] value is not valid. It must be one of: WEB|WORKER|NODE|SHELL.");r=!0}else e="object"==typeof window,l="function"==typeof importScripts,o="object"==typeof process&&"function"==typeof require&&!e&&!l,r=!e&&!o&&!l;if(o)d.print||(d.print=console.log),d.printErr||(d.printErr=console.warn),d.read=function(A,e){var r;return(r=vr(A))||(i=i||require("fs"),A=(f=f||require("path")).normalize(A),r=i.readFileSync(A)),e?r:r.toString()},d.readBinary=function(A){var e=d.read(A,!0);return e.buffer||(e=new Uint8Array(e)),h(e.buffer),e},d.thisProgram||(1<process.argv.length?d.thisProgram=process.argv[1].replace(/\\\\/g,"/"):d.thisProgram="unknown-program"),d.arguments=process.argv.slice(2),"undefined"!=typeof module&&(module.exports=d),process.on("uncaughtException",function(A){if(!(A instanceof Yr))throw A}),process.on("unhandledRejection",function(A,e){process.exit(1)}),d.inspect=function(){return"[Emscripten Module object]"};else if(r)d.print||(d.print=print),"undefined"!=typeof printErr&&(d.printErr=printErr),"undefined"!=typeof read?d.read=function(A){var e=vr(A);return e?kr(e):read(A)}:d.read=function(){throw"no read() available"},d.readBinary=function(A){var e;return(e=vr(A))?e:"function"==typeof readbuffer?new Uint8Array(readbuffer(A)):(h("object"==typeof(e=read(A,"binary"))),e)},"undefined"!=typeof scriptArgs?d.arguments=scriptArgs:void 0!==arguments&&(d.arguments=arguments),"function"==typeof quit&&(d.quit=function(A,e){quit(A)});else{if(!e&&!l)throw new Error("Unknown runtime environment. Where are we?");if(d.read=function(e){try{var A=new XMLHttpRequest;return A.open("GET",e,!1),A.send(null),A.responseText}catch(A){var r=vr(e);if(r)return kr(r);throw A}},l&&(d.readBinary=function(e){try{var A=new XMLHttpRequest;return A.open("GET",e,!1),A.responseType="arraybuffer",A.send(null),new Uint8Array(A.response)}catch(A){var r=vr(e);if(r)return r;throw A}}),d.readAsync=function(e,r,i){var f=new XMLHttpRequest;f.open("GET",e,!0),f.responseType="arraybuffer",f.onload=function(){if(200==f.status||0==f.status&&f.response)r(f.response);else{var A=vr(e);A?r(A.buffer):i()}},f.onerror=i,f.send(null)},void 0!==arguments&&(d.arguments=arguments),"undefined"!=typeof console)d.print||(d.print=function(A){console.log(A)}),d.printErr||(d.printErr=function(A){console.warn(A)});else{d.print||(d.print=function(A){})}void 0===d.setWindowTitle&&(d.setWindowTitle=function(A){document.title=A})}for(Sr in d.print||(d.print=function(){}),d.printErr||(d.printErr=d.print),d.arguments||(d.arguments=[]),d.thisProgram||(d.thisProgram="./this.program"),d.quit||(d.quit=function(A,e){throw e}),d.print=d.print,d.printErr=d.printErr,d.preRun=[],d.postRun=[],A)A.hasOwnProperty(Sr)&&(d[Sr]=A[Sr]);A=void 0;var k={setTempRet0:function(A){return tempRet0=A},getTempRet0:function(){return tempRet0},stackSave:function(){return _},stackRestore:function(A){_=A},getNativeTypeSize:function(A){switch(A){case"i1":case"i8":return 1;case"i16":return 2;case"i32":return 4;case"i64":return 8;case"float":return 4;case"double":return 8;default:if("*"===A[A.length-1])return k.QUANTUM_SIZE;if("i"!==A[0])return 0;var e=parseInt(A.substr(1));return h(e%8==0),e/8}},getNativeFieldSize:function(A){return Math.max(k.getNativeTypeSize(A),k.QUANTUM_SIZE)},STACK_ALIGN:16,prepVararg:function(A,e){return"double"===e||"i64"===e?7&A&&(h(4==(7&A)),A+=4):h(0==(3&A)),A},getAlignSize:function(A,e,r){return r||"i64"!=A&&"double"!=A?A?Math.min(e||(A?k.getNativeFieldSize(A):0),k.QUANTUM_SIZE):Math.min(e,8):8},dynCall:function(A,e,r){return r&&r.length?d["dynCall_"+A].apply(null,[e].concat(r)):d["dynCall_"+A].call(null,e)},functionPointers:[],addFunction:function(A){for(var e=0;e<k.functionPointers.length;e++)if(!k.functionPointers[e])return k.functionPointers[e]=A,2*(1+e);throw"Finished up all reserved function pointers. Use a higher value for RESERVED_FUNCTION_POINTERS."},removeFunction:function(A){k.functionPointers[(A-2)/2]=null},warnOnce:function(A){k.warnOnce.shown||(k.warnOnce.shown={}),k.warnOnce.shown[A]||(k.warnOnce.shown[A]=1,d.printErr(A))},funcWrappers:{},getFuncWrapper:function(e,r){if(e){h(r),k.funcWrappers[r]||(k.funcWrappers[r]={});var A=k.funcWrappers[r];return A[e]||(1===r.length?A[e]=function(){return k.dynCall(r,e)}:2===r.length?A[e]=function(A){return k.dynCall(r,e,[A])}:A[e]=function(){return k.dynCall(r,e,Array.prototype.slice.call(arguments))}),A[e]}},getCompilerSetting:function(A){throw"You must build with -s RETAIN_COMPILER_SETTINGS=1 for Runtime.getCompilerSetting or emscripten_get_compiler_setting to work"},stackAlloc:function(A){var e=_;return _=(_=_+A|0)+15&-16,e},staticAlloc:function(A){var e=R;return R=(R=R+A|0)+15&-16,e},dynamicAlloc:function(A){var e=I[D>>2],r=-16&(e+A+15|0);if((I[D>>2]=r,H<=r)&&!z())return I[D>>2]=e,0;return e},alignMemory:function(A,e){return A=Math.ceil(A/(e||16))*(e||16)},makeBigInt:function(A,e,r){return r?+(A>>>0)+4294967296*(e>>>0):+(A>>>0)+4294967296*(0|e)},GLOBAL_BASE:8,QUANTUM_SIZE:4,__dummy__:0};d.Runtime=k;var n=0;function h(A,e){A||Mr("Assertion failed: "+e)}function w(A,e,r){switch("*"===(r=r||"i8").charAt(r.length-1)&&(r="i32"),r){case"i1":case"i8":B[A>>0]=e;break;case"i16":X[A>>1]=e;break;case"i32":I[A>>2]=e;break;case"i64":tempI64=[e>>>0,(tempDouble=e,1<=+iA(tempDouble)?0<tempDouble?(0|tA(+nA(tempDouble/4294967296),4294967295))>>>0:~~+fA((tempDouble-(~~tempDouble>>>0))/4294967296)>>>0:0)],I[A>>2]=tempI64[0],I[A+4>>2]=tempI64[1];break;case"float":G[A>>2]=e;break;case"double":V[A>>3]=e;break;default:Mr("invalid type for setValue: "+r)}}var t=0,v=2,m=4;function a(A,e,r,i){var f,n;n="number"==typeof A?(f=!0,A):(f=!1,A.length);var t,o="string"==typeof e?e:null;if(t=r==m?i:["function"==typeof Gr?Gr:k.staticAlloc,k.stackAlloc,k.staticAlloc,k.dynamicAlloc][void 0===r?v:r](Math.max(n,o?1:e.length)),f){var a;for(h(0==(3&(i=t))),a=t+(-4&n);i<a;i+=4)I[i>>2]=0;for(a=t+n;i<a;)B[i++>>0]=0;return t}if("i8"===o)return A.subarray||A.slice?E.set(A,t):E.set(new Uint8Array(A),t),t;for(var c,l,u,b=0;b<n;){var s=A[b];"function"==typeof s&&(s=k.getFunctionIndex(s)),0!==(c=o||e[b])?("i64"==c&&(c="i32"),w(t+b,s,c),u!==c&&(l=k.getNativeTypeSize(c),u=c),b+=l):b++}return t}function g(A,e){if(0===e||!A)return"";for(var r,i=0,f=0;i|=r=E[A+f>>0],(0!=r||e)&&(f++,!e||f!=e););e=e||f;var n="";if(i<128){for(var t;0<e;)t=String.fromCharCode.apply(String,E.subarray(A,A+Math.min(e,1024))),n=n?n+t:t,A+=1024,e-=1024;return n}return c(E,A)}d.ALLOC_NORMAL=t,d.ALLOC_STACK=1,d.ALLOC_STATIC=v,d.ALLOC_DYNAMIC=3,d.ALLOC_NONE=m,d.getMemory=function(A){return N?AA?Gr(A):k.dynamicAlloc(A):k.staticAlloc(A)};var u="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function c(A,e){for(var r=e;A[r];)++r;if(16<r-e&&A.subarray&&u)return u.decode(A.subarray(e,r));for(var i,f,n,t,o,a="";;){if(!(i=A[e++]))return a;if(128&i)if(f=63&A[e++],192!=(224&i))if(n=63&A[e++],(i=224==(240&i)?(15&i)<<12|f<<6|n:(t=63&A[e++],240==(248&i)?(7&i)<<18|f<<12|n<<6|t:(o=63&A[e++],248==(252&i)?(3&i)<<24|f<<18|n<<12|t<<6|o:(1&i)<<30|f<<24|n<<18|t<<12|o<<6|63&A[e++])))<65536)a+=String.fromCharCode(i);else{var c=i-65536;a+=String.fromCharCode(55296|c>>10,56320|1023&c)}else a+=String.fromCharCode((31&i)<<6|f);else a+=String.fromCharCode(i)}}function b(A,e,r,i){if(!(0<i))return 0;for(var f=r,n=r+i-1,t=0;t<A.length;++t){var o=A.charCodeAt(t);if(55296<=o&&o<=57343&&(o=65536+((1023&o)<<10)|1023&A.charCodeAt(++t)),o<=127){if(n<=r)break;e[r++]=o}else if(o<=2047){if(n<=r+1)break;e[r++]=192|o>>6,e[r++]=128|63&o}else if(o<=65535){if(n<=r+2)break;e[r++]=224|o>>12,e[r++]=128|o>>6&63,e[r++]=128|63&o}else if(o<=2097151){if(n<=r+3)break;e[r++]=240|o>>18,e[r++]=128|o>>12&63,e[r++]=128|o>>6&63,e[r++]=128|63&o}else if(o<=67108863){if(n<=r+4)break;e[r++]=248|o>>24,e[r++]=128|o>>18&63,e[r++]=128|o>>12&63,e[r++]=128|o>>6&63,e[r++]=128|63&o}else{if(n<=r+5)break;e[r++]=252|o>>30,e[r++]=128|o>>24&63,e[r++]=128|o>>18&63,e[r++]=128|o>>12&63,e[r++]=128|o>>6&63,e[r++]=128|63&o}}return e[r]=0,r-f}function s(A,e,r){return b(A,E,e,r)}function Z(A){for(var e=0,r=0;r<A.length;++r){var i=A.charCodeAt(r);55296<=i&&i<=57343&&(i=65536+((1023&i)<<10)|1023&A.charCodeAt(++r)),i<=127?++e:e+=i<=2047?2:i<=65535?3:i<=2097151?4:i<=67108863?5:6}return e}"undefined"!=typeof TextDecoder&&new TextDecoder("utf-16le");function p(){var A=function(){var e=new Error;if(!e.stack){try{throw new Error(0)}catch(A){e=A}if(!e.stack)return"(no stack trace available)"}return e.stack.toString()}();return d.extraStackTrace&&(A+="\\n"+d.extraStackTrace()),A.replace(/__Z[\\w\\d_]+/g,function(A){var e=A;return A===e?A:A+" ["+e+"]"})}var y,B,E,X,W,I,C,G,V,F,R,N,_,Y,Q,D,J,M=65536,T=16777216,U=16777216;function S(A,e){return 0<A%e&&(A+=e-A%e),A}function O(){d.HEAP8=B=new Int8Array(y),d.HEAP16=X=new Int16Array(y),d.HEAP32=I=new Int32Array(y),d.HEAPU8=E=new Uint8Array(y),d.HEAPU16=W=new Uint16Array(y),d.HEAPU32=C=new Uint32Array(y),d.HEAPF32=G=new Float32Array(y),d.HEAPF64=V=new Float64Array(y)}function z(){var A=d.usingWasm?M:T,e=2147483648-A;if(I[D>>2]>e)return!1;var r=H;for(H=Math.max(H,U);H<I[D>>2];)H=H<=536870912?S(2*H,A):Math.min(S((3*H+2147483648)/4,A),e);var i,f=d.reallocBuffer(H);return f&&f.byteLength==H?(i=f,d.buffer=y=i,O(),!0):(H=r,!1)}R=_=D=0,N=!1,d.reallocBuffer||(d.reallocBuffer=function(A){var e;try{if(ArrayBuffer.transfer)e=ArrayBuffer.transfer(y,A);else{var r=B;e=new ArrayBuffer(A),new Int8Array(e).set(r)}}catch(A){return!1}return!!Ir(e)&&e});try{(J=Function.prototype.call.bind(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype,"byteLength").get))(new ArrayBuffer(4))}catch(Or){J=function(A){return A.byteLength}}var j=d.TOTAL_STACK||5242880,H=d.TOTAL_MEMORY||16777216;if(H<j&&d.printErr("TOTAL_MEMORY should be larger than TOTAL_STACK, was "+H+"! (TOTAL_STACK="+j+")"),y=d.buffer?d.buffer:new ArrayBuffer(H),O(),I[0]=1668509029,X[1]=25459,115!==E[2]||99!==E[3])throw"Runtime error: expected the system to be little-endian!";function x(A){for(;0<A.length;){var e=A.shift();if("function"!=typeof e){var r=e.func;"number"==typeof r?void 0===e.arg?d.dynCall_v(r):d.dynCall_vi(r,e.arg):r(void 0===e.arg?null:e.arg)}else e()}}d.HEAP=void 0,d.buffer=y,d.HEAP8=B,d.HEAP16=X,d.HEAP32=I,d.HEAPU8=E,d.HEAPU16=W,d.HEAPU32=C,d.HEAPF32=G,d.HEAPF64=V;var P=[],L=[],K=[],q=[],$=[],AA=!1;function eA(A,e){B.set(A,e)}function rA(A,e,r){for(var i=0;i<A.length;++i)B[e++>>0]=A.charCodeAt(i);r||(B[e>>0]=0)}Math.imul&&-5===Math.imul(4294967295,5)||(Math.imul=function(A,e){var r=65535&A,i=65535&e;return r*i+((A>>>16)*i+r*(e>>>16)<<16)|0}),Math.imul=Math.imul,Math.clz32||(Math.clz32=function(A){A>>>=0;for(var e=0;e<32;e++)if(A&1<<31-e)return e;return 32}),Math.clz32=Math.clz32,Math.trunc||(Math.trunc=function(A){return A<0?Math.ceil(A):Math.floor(A)}),Math.trunc=Math.trunc;var iA=Math.abs,fA=(Math.cos,Math.sin,Math.tan,Math.acos,Math.asin,Math.atan,Math.atan2,Math.exp,Math.log,Math.sqrt,Math.ceil),nA=Math.floor,tA=(Math.pow,Math.imul,Math.fround,Math.round,Math.min),oA=(Math.clz32,Math.trunc,0),aA=null,cA=null;function lA(A){oA++,d.monitorRunDependencies&&d.monitorRunDependencies(oA)}function uA(A){if(oA--,d.monitorRunDependencies&&d.monitorRunDependencies(oA),0==oA&&(null!==aA&&(clearInterval(aA),aA=null),cA)){var e=cA;cA=null,e()}}d.addRunDependency=lA,d.removeRunDependency=uA,d.preloadedImages={},d.preloadedAudios={};var bA=null;F=k.GLOBAL_BASE,R=F+79664,L.push({func:function(){Zr()}},{func:function(){yr()}},{func:function(){Br()}},{func:function(){Er()}},{func:function(){pr()}},{func:function(){Xr()}});var sA=R;function dA(){return!!dA.uncaught_exception}R+=16;var kA={last:0,caught:[],infos:{},deAdjust:function(A){if(!A||kA.infos[A])return A;for(var e in kA.infos){if(kA.infos[e].adjusted===A)return e}return A},addRef:function(A){A&&kA.infos[A].refcount++},decRef:function(A){if(A){var e=kA.infos[A];h(0<e.refcount),e.refcount--,0!==e.refcount||e.rethrown||(e.destructor&&d.dynCall_vi(e.destructor,A),delete kA.infos[A],___cxa_free_exception(A))}},clearRef:function(A){A&&(kA.infos[A].refcount=0)}};var hA={EPERM:1,ENOENT:2,ESRCH:3,EINTR:4,EIO:5,ENXIO:6,E2BIG:7,ENOEXEC:8,EBADF:9,ECHILD:10,EAGAIN:11,EWOULDBLOCK:11,ENOMEM:12,EACCES:13,EFAULT:14,ENOTBLK:15,EBUSY:16,EEXIST:17,EXDEV:18,ENODEV:19,ENOTDIR:20,EISDIR:21,EINVAL:22,ENFILE:23,EMFILE:24,ENOTTY:25,ETXTBSY:26,EFBIG:27,ENOSPC:28,ESPIPE:29,EROFS:30,EMLINK:31,EPIPE:32,EDOM:33,ERANGE:34,ENOMSG:42,EIDRM:43,ECHRNG:44,EL2NSYNC:45,EL3HLT:46,EL3RST:47,ELNRNG:48,EUNATCH:49,ENOCSI:50,EL2HLT:51,EDEADLK:35,ENOLCK:37,EBADE:52,EBADR:53,EXFULL:54,ENOANO:55,EBADRQC:56,EBADSLT:57,EDEADLOCK:35,EBFONT:59,ENOSTR:60,ENODATA:61,ETIME:62,ENOSR:63,ENONET:64,ENOPKG:65,EREMOTE:66,ENOLINK:67,EADV:68,ESRMNT:69,ECOMM:70,EPROTO:71,EMULTIHOP:72,EDOTDOT:73,EBADMSG:74,ENOTUNIQ:76,EBADFD:77,EREMCHG:78,ELIBACC:79,ELIBBAD:80,ELIBSCN:81,ELIBMAX:82,ELIBEXEC:83,ENOSYS:38,ENOTEMPTY:39,ENAMETOOLONG:36,ELOOP:40,EOPNOTSUPP:95,EPFNOSUPPORT:96,ECONNRESET:104,ENOBUFS:105,EAFNOSUPPORT:97,EPROTOTYPE:91,ENOTSOCK:88,ENOPROTOOPT:92,ESHUTDOWN:108,ECONNREFUSED:111,EADDRINUSE:98,ECONNABORTED:103,ENETUNREACH:101,ENETDOWN:100,ETIMEDOUT:110,EHOSTDOWN:112,EHOSTUNREACH:113,EINPROGRESS:115,EALREADY:114,EDESTADDRREQ:89,EMSGSIZE:90,EPROTONOSUPPORT:93,ESOCKTNOSUPPORT:94,EADDRNOTAVAIL:99,ENETRESET:102,EISCONN:106,ENOTCONN:107,ETOOMANYREFS:109,EUSERS:87,EDQUOT:122,ESTALE:116,ENOTSUP:95,ENOMEDIUM:123,EILSEQ:84,EOVERFLOW:75,ECANCELED:125,ENOTRECOVERABLE:131,EOWNERDEAD:130,ESTRPIPE:86};function wA(A){return d.___errno_location&&(I[d.___errno_location()>>2]=A),A}var vA={0:"Success",1:"Not super-user",2:"No such file or directory",3:"No such process",4:"Interrupted system call",5:"I/O error",6:"No such device or address",7:"Arg list too long",8:"Exec format error",9:"Bad file number",10:"No children",11:"No more processes",12:"Not enough core",13:"Permission denied",14:"Bad address",15:"Block device required",16:"Mount device busy",17:"File exists",18:"Cross-device link",19:"No such device",20:"Not a directory",21:"Is a directory",22:"Invalid argument",23:"Too many open files in system",24:"Too many open files",25:"Not a typewriter",26:"Text file busy",27:"File too large",28:"No space left on device",29:"Illegal seek",30:"Read only file system",31:"Too many links",32:"Broken pipe",33:"Math arg out of domain of func",34:"Math result not representable",35:"File locking deadlock error",36:"File or path name too long",37:"No record locks available",38:"Function not implemented",39:"Directory not empty",40:"Too many symbolic links",42:"No message of desired type",43:"Identifier removed",44:"Channel number out of range",45:"Level 2 not synchronized",46:"Level 3 halted",47:"Level 3 reset",48:"Link number out of range",49:"Protocol driver not attached",50:"No CSI structure available",51:"Level 2 halted",52:"Invalid exchange",53:"Invalid request descriptor",54:"Exchange full",55:"No anode",56:"Invalid request code",57:"Invalid slot",59:"Bad font file fmt",60:"Device not a stream",61:"No data (for no delay io)",62:"Timer expired",63:"Out of streams resources",64:"Machine is not on the network",65:"Package not installed",66:"The object is remote",67:"The link has been severed",68:"Advertise error",69:"Srmount error",70:"Communication error on send",71:"Protocol error",72:"Multihop attempted",73:"Cross mount point (not really error)",74:"Trying to read unreadable message",75:"Value too large for defined data type",76:"Given log. name not unique",77:"f.d. invalid for this operation",78:"Remote address changed",79:"Can access a needed shared lib",80:"Accessing a corrupted shared lib",81:".lib section in a.out corrupted",82:"Attempting to link in too many libs",83:"Attempting to exec a shared library",84:"Illegal byte sequence",86:"Streams pipe error",87:"Too many users",88:"Socket operation on non-socket",89:"Destination address required",90:"Message too long",91:"Protocol wrong type for socket",92:"Protocol not available",93:"Unknown protocol",94:"Socket type not supported",95:"Not supported",96:"Protocol family not supported",97:"Address family not supported by protocol family",98:"Address already in use",99:"Address not available",100:"Network interface is not configured",101:"Network is unreachable",102:"Connection reset by network",103:"Connection aborted",104:"Connection reset by peer",105:"No buffer space available",106:"Socket is already connected",107:"Socket is not connected",108:"Can\'t send after socket shutdown",109:"Too many references",110:"Connection timed out",111:"Connection refused",112:"Host is down",113:"Host is unreachable",114:"Socket already connected",115:"Connection already in progress",116:"Stale file handle",122:"Quota exceeded",123:"No medium (in tape drive)",125:"Operation canceled",130:"Previous owner died",131:"State not recoverable"},mA={splitPath:function(A){return/^(\\/?|)([\\s\\S]*?)((?:\\.{1,2}|[^\\/]+?|)(\\.[^.\\/]*|))(?:[\\/]*)$/.exec(A).slice(1)},normalizeArray:function(A,e){for(var r=0,i=A.length-1;0<=i;i--){var f=A[i];"."===f?A.splice(i,1):".."===f?(A.splice(i,1),r++):r&&(A.splice(i,1),r--)}if(e)for(;r;r--)A.unshift("..");return A},normalize:function(A){var e="/"===A.charAt(0),r="/"===A.substr(-1);return(A=mA.normalizeArray(A.split("/").filter(function(A){return!!A}),!e).join("/"))||e||(A="."),A&&r&&(A+="/"),(e?"/":"")+A},dirname:function(A){var e=mA.splitPath(A),r=e[0],i=e[1];return r||i?r+(i=i&&i.substr(0,i.length-1)):"."},basename:function(A){if("/"===A)return"/";var e=A.lastIndexOf("/");return-1===e?A:A.substr(e+1)},extname:function(A){return mA.splitPath(A)[3]},join:function(){var A=Array.prototype.slice.call(arguments,0);return mA.normalize(A.join("/"))},join2:function(A,e){return mA.normalize(A+"/"+e)},resolve:function(){for(var A="",e=!1,r=arguments.length-1;-1<=r&&!e;r--){var i=0<=r?arguments[r]:EA.cwd();if("string"!=typeof i)throw new TypeError("Arguments to path.resolve must be strings");if(!i)return"";A=i+"/"+A,e="/"===i.charAt(0)}return(e?"/":"")+(A=mA.normalizeArray(A.split("/").filter(function(A){return!!A}),!e).join("/"))||"."},relative:function(A,e){function r(A){for(var e=0;e<A.length&&""===A[e];e++);for(var r=A.length-1;0<=r&&""===A[r];r--);return r<e?[]:A.slice(e,r-e+1)}A=mA.resolve(A).substr(1),e=mA.resolve(e).substr(1);for(var i=r(A.split("/")),f=r(e.split("/")),n=Math.min(i.length,f.length),t=n,o=0;o<n;o++)if(i[o]!==f[o]){t=o;break}var a=[];for(o=t;o<i.length;o++)a.push("..");return(a=a.concat(f.slice(t))).join("/")}},gA={ttys:[],init:function(){},shutdown:function(){},register:function(A,e){gA.ttys[A]={input:[],output:[],ops:e},EA.registerDevice(A,gA.stream_ops)},stream_ops:{open:function(A){var e=gA.ttys[A.node.rdev];if(!e)throw new EA.ErrnoError(hA.ENODEV);A.tty=e,A.seekable=!1},close:function(A){A.tty.ops.flush(A.tty)},flush:function(A){A.tty.ops.flush(A.tty)},read:function(A,e,r,i,f){if(!A.tty||!A.tty.ops.get_char)throw new EA.ErrnoError(hA.ENXIO);for(var n=0,t=0;t<i;t++){var o;try{o=A.tty.ops.get_char(A.tty)}catch(A){throw new EA.ErrnoError(hA.EIO)}if(void 0===o&&0===n)throw new EA.ErrnoError(hA.EAGAIN);if(null==o)break;n++,e[r+t]=o}return n&&(A.node.timestamp=Date.now()),n},write:function(A,e,r,i,f){if(!A.tty||!A.tty.ops.put_char)throw new EA.ErrnoError(hA.ENXIO);for(var n=0;n<i;n++)try{A.tty.ops.put_char(A.tty,e[r+n])}catch(A){throw new EA.ErrnoError(hA.EIO)}return i&&(A.node.timestamp=Date.now()),n}},default_tty_ops:{get_char:function(A){if(!A.input.length){var e=null;if(o){var r=new Buffer(256),i=0,f="win32"!=process.platform,n=process.stdin.fd;if(f){var t=!1;try{n=ur.openSync("/dev/stdin","r"),t=!0}catch(A){}}try{i=ur.readSync(n,r,0,256,null)}catch(A){if(-1==A.toString().indexOf("EOF"))throw A;i=0}t&&ur.closeSync(n),e=0<i?r.slice(0,i).toString("utf-8"):null}else"undefined"!=typeof window&&"function"==typeof window.prompt?null!==(e=window.prompt("Input: "))&&(e+="\\n"):"function"==typeof readline&&null!==(e=readline())&&(e+="\\n");if(!e)return null;A.input=dr(e,!0)}return A.input.shift()},put_char:function(A,e){null===e||10===e?(d.print(c(A.output,0)),A.output=[]):0!=e&&A.output.push(e)},flush:function(A){A.output&&0<A.output.length&&(d.print(c(A.output,0)),A.output=[])}},default_tty1_ops:{put_char:function(A,e){null===e||10===e?(d.printErr(c(A.output,0)),A.output=[]):0!=e&&A.output.push(e)},flush:function(A){A.output&&0<A.output.length&&(d.printErr(c(A.output,0)),A.output=[])}}},ZA={ops_table:null,mount:function(A){return ZA.createNode(null,"/",16895,0)},createNode:function(A,e,r,i){if(EA.isBlkdev(r)||EA.isFIFO(r))throw new EA.ErrnoError(hA.EPERM);ZA.ops_table||(ZA.ops_table={dir:{node:{getattr:ZA.node_ops.getattr,setattr:ZA.node_ops.setattr,lookup:ZA.node_ops.lookup,mknod:ZA.node_ops.mknod,rename:ZA.node_ops.rename,unlink:ZA.node_ops.unlink,rmdir:ZA.node_ops.rmdir,readdir:ZA.node_ops.readdir,symlink:ZA.node_ops.symlink},stream:{llseek:ZA.stream_ops.llseek}},file:{node:{getattr:ZA.node_ops.getattr,setattr:ZA.node_ops.setattr},stream:{llseek:ZA.stream_ops.llseek,read:ZA.stream_ops.read,write:ZA.stream_ops.write,allocate:ZA.stream_ops.allocate,mmap:ZA.stream_ops.mmap,msync:ZA.stream_ops.msync}},link:{node:{getattr:ZA.node_ops.getattr,setattr:ZA.node_ops.setattr,readlink:ZA.node_ops.readlink},stream:{}},chrdev:{node:{getattr:ZA.node_ops.getattr,setattr:ZA.node_ops.setattr},stream:EA.chrdev_stream_ops}});var f=EA.createNode(A,e,r,i);return EA.isDir(f.mode)?(f.node_ops=ZA.ops_table.dir.node,f.stream_ops=ZA.ops_table.dir.stream,f.contents={}):EA.isFile(f.mode)?(f.node_ops=ZA.ops_table.file.node,f.stream_ops=ZA.ops_table.file.stream,f.usedBytes=0,f.contents=null):EA.isLink(f.mode)?(f.node_ops=ZA.ops_table.link.node,f.stream_ops=ZA.ops_table.link.stream):EA.isChrdev(f.mode)&&(f.node_ops=ZA.ops_table.chrdev.node,f.stream_ops=ZA.ops_table.chrdev.stream),f.timestamp=Date.now(),A&&(A.contents[e]=f),f},getFileDataAsRegularArray:function(A){if(A.contents&&A.contents.subarray){for(var e=[],r=0;r<A.usedBytes;++r)e.push(A.contents[r]);return e}return A.contents},getFileDataAsTypedArray:function(A){return A.contents?A.contents.subarray?A.contents.subarray(0,A.usedBytes):new Uint8Array(A.contents):new Uint8Array},expandFileStorage:function(A,e){if(A.contents&&A.contents.subarray&&e>A.contents.length&&(A.contents=ZA.getFileDataAsRegularArray(A),A.usedBytes=A.contents.length),!A.contents||A.contents.subarray){var r=A.contents?A.contents.length:0;if(e<=r)return;e=Math.max(e,r*(r<1048576?2:1.125)|0),0!=r&&(e=Math.max(e,256));var i=A.contents;return A.contents=new Uint8Array(e),void(0<A.usedBytes&&A.contents.set(i.subarray(0,A.usedBytes),0))}for(!A.contents&&0<e&&(A.contents=[]);A.contents.length<e;)A.contents.push(0)},resizeFileStorage:function(A,e){if(A.usedBytes!=e){if(0==e)return A.contents=null,void(A.usedBytes=0);if(!A.contents||A.contents.subarray){var r=A.contents;return A.contents=new Uint8Array(new ArrayBuffer(e)),r&&A.contents.set(r.subarray(0,Math.min(e,A.usedBytes))),void(A.usedBytes=e)}if(A.contents||(A.contents=[]),A.contents.length>e)A.contents.length=e;else for(;A.contents.length<e;)A.contents.push(0);A.usedBytes=e}},node_ops:{getattr:function(A){var e={};return e.dev=EA.isChrdev(A.mode)?A.id:1,e.ino=A.id,e.mode=A.mode,e.nlink=1,e.uid=0,e.gid=0,e.rdev=A.rdev,EA.isDir(A.mode)?e.size=4096:EA.isFile(A.mode)?e.size=A.usedBytes:EA.isLink(A.mode)?e.size=A.link.length:e.size=0,e.atime=new Date(A.timestamp),e.mtime=new Date(A.timestamp),e.ctime=new Date(A.timestamp),e.blksize=4096,e.blocks=Math.ceil(e.size/e.blksize),e},setattr:function(A,e){void 0!==e.mode&&(A.mode=e.mode),void 0!==e.timestamp&&(A.timestamp=e.timestamp),void 0!==e.size&&ZA.resizeFileStorage(A,e.size)},lookup:function(A,e){throw EA.genericErrors[hA.ENOENT]},mknod:function(A,e,r,i){return ZA.createNode(A,e,r,i)},rename:function(A,e,r){if(EA.isDir(A.mode)){var i;try{i=EA.lookupNode(e,r)}catch(A){}if(i)for(var f in i.contents)throw new EA.ErrnoError(hA.ENOTEMPTY)}delete A.parent.contents[A.name],A.name=r,(e.contents[r]=A).parent=e},unlink:function(A,e){delete A.contents[e]},rmdir:function(A,e){var r=EA.lookupNode(A,e);for(var i in r.contents)throw new EA.ErrnoError(hA.ENOTEMPTY);delete A.contents[e]},readdir:function(A){