heic2any
Version:
Converting HEIC/HEIF to PNG/JPEG/GIF in the browser
21 lines • 1.36 MB
JavaScript
/*Copyrights for code authored by Yahoo Inc. is licensed under the following terms:
MIT License
Copyright 2017 Yahoo Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
!function(e,t,r,i){"use strict";function n(){return C.isValid()}function o(){return C.isValid()}function a(){var e={getUserMedia:!0};return C.isValid(e)}function s(e){var t=!1;if(w.isArray(e)&&e.length){if(w.each(e,function(e,r){w.isSupported.videoCodecs[r]&&(t=!0)}),!t){ return!1 }}else if(w.isString(e)&&e.length&&!w.isSupported.videoCodecs[e]){ return!1; }return C.isValid({getUserMedia:!0})}function d(){function e(e,t,r){var i,n;for(u=e,m=t,g=r,f=new Array(h),i=0;h>i;i++){ f[i]=new Array(4),n=f[i],n[0]=n[1]=n[2]=(i<<k+8)/h|0,D[i]=F/h|0,G[i]=0 }}function t(){for(var e=[],t=new Array(h),r=0;h>r;r++){ t[f[r][3]]=r; }for(var i=0,n=0;h>n;n++){var o=t[n];e[i++]=f[o][0],e[i++]=f[o][1],e[i++]=f[o][2]}return e}function r(){var e,t,r,i,n,o,a,s;for(a=0,s=0,e=0;h>e;e++){for(n=f[e],r=e,i=n[1],t=e+1;h>t;t++){ o=f[t],o[1]<i&&(r=t,i=o[1]); }if(o=f[r],e!=r&&(t=o[0],o[0]=n[0],n[0]=t,t=o[1],o[1]=n[1],n[1]=t,t=o[2],o[2]=n[2],n[2]=t,t=o[3],o[3]=n[3],n[3]=t),i!=a){for(P[a]=s+e>>1,t=a+1;i>t;t++){ P[t]=e; }a=i,s=e}}for(P[a]=s+C>>1,t=a+1;256>t;t++){ P[t]=C }}function i(){var e,t,r,i,n,o,a,f,h,C,x,F,W,O;for(y>m&&(g=1),l=30+(g-1)/3,F=u,W=0,O=m,x=m/(3*g),C=x/S|0,f=V,o=T,a=o>>U,1>=a&&(a=0),e=0;a>e;e++){ N[e]=f*((a*a-e*e)*z/(a*a)); }for(h=y>m?3:m%p!==0?3*p:m%v!==0?3*v:m%b!==0?3*b:3*w,e=0;x>e;){ if(r=(255&F[W+0])<<k,i=(255&F[W+1])<<k,n=(255&F[W+2])<<k,t=c(r,i,n),d(f,t,r,i,n),0!==a&&s(a,t,r,i,n),W+=h,W>=O&&(W-=m),e++,0===C&&(C=1),e%C===0){ for(f-=f/l,o-=o/I,a=o>>U,1>=a&&(a=0),t=0;a>t;t++){ N[t]=f*((a*a-t*t)*z/(a*a)) } } }}function n(e,t,r){var i,n,o,a,s,d,c;for(s=1e3,c=-1,i=P[t],n=i-1;h>i||n>=0;){ h>i&&(d=f[i],o=d[1]-t,o>=s?i=h:(i++,0>o&&(o=-o),a=d[0]-e,0>a&&(a=-a),o+=a,s>o&&(a=d[2]-r,0>a&&(a=-a),o+=a,s>o&&(s=o,c=d[3])))),n>=0&&(d=f[n],o=t-d[1],o>=s?n=-1:(n--,0>o&&(o=-o),a=d[0]-e,0>a&&(a=-a),o+=a,s>o&&(a=d[2]-r,0>a&&(a=-a),o+=a,s>o&&(s=o,c=d[3])))); }return c}function o(){return i(),a(),r(),t()}function a(){var e;for(e=0;h>e;e++){ f[e][0]>>=k,f[e][1]>>=k,f[e][2]>>=k,f[e][3]=e }}function s(e,t,r,i,n){var o,a,s,d,c,l,u;for(s=t-e,-1>s&&(s=-1),d=t+e,d>h&&(d=h),o=t+1,a=t-1,l=1;d>o||a>s;){if(c=N[l++],d>o){u=f[o++];try{u[0]-=c*(u[0]-r)/B|0,u[1]-=c*(u[1]-i)/B|0,u[2]-=c*(u[2]-n)/B|0}catch(m){}}if(a>s){u=f[a--];try{u[0]-=c*(u[0]-r)/B|0,u[1]-=c*(u[1]-i)/B|0,u[2]-=c*(u[2]-n)/B|0}catch(m$1){}}}}function d(e,t,r,i,n){var o=f[t],a=e/V;o[0]-=a*(o[0]-r)|0,o[1]-=a*(o[1]-i)|0,o[2]-=a*(o[2]-n)|0}function c(e,t,r){var i,n,o,a,s,d,c,l,u,m;for(l=~(1<<31),u=l,d=-1,c=d,i=0;h>i;i++){ m=f[i],n=m[0]-e,0>n&&(n=-n),o=m[1]-t,0>o&&(o=-o),n+=o,o=m[2]-r,0>o&&(o=-o),n+=o,l>n&&(l=n,d=i),a=n-(G[i]>>x-k),u>a&&(u=a,c=i),s=D[i]>>O,D[i]-=s,G[i]+=s<<W; }return D[d]+=E,G[d]-=M,c}var l,u,m,g,f,h=256,p=499,v=491,b=487,w=503,y=3*w,C=h-1,k=4,S=100,x=16,F=1<<x,W=10,O=10,E=F>>O,M=F<<W-O,A=h>>3,U=6,R=1<<U,T=A*R,I=30,j=10,V=1<<j,H=8,z=1<<H,L=j+H,B=1<<L,P=[],G=[],D=[],N=[];e.apply(this,arguments);var q={};return q.map=n,q.process=o,q}function c(){var e=this;try{e.onmessage=function(e){var t,i=e.data||{};i.gifshot&&(t=r.run(i),postMessage(t))}}catch(t){}var r={dataToRGB:function(e,t,r){for(var i=t*r*4,n=0,o=[];i>n;){ o.push(e[n++]),o.push(e[n++]),o.push(e[n++]),n++; }return o},componentizedPaletteToArray:function(e){e=e||[];for(var t=[],r=0;r<e.length;r+=3){var i=e[r],n=e[r+1],o=e[r+2];t.push(i<<16|n<<8|o)}return t},processFrameWithQuantizer:function(e,t,r,i){for(var n=this.dataToRGB(e,t,r),o=new d(n,n.length,i),a=o.process(),s=new Uint32Array(this.componentizedPaletteToArray(a)),c=t*r,l=new Uint8Array(c),u=0,m=0;c>m;m++){var g=n[u++],f=n[u++],h=n[u++];l[m]=o.map(g,f,h)}return{pixels:l,palette:s}},run:function(e){e=e||{};var t=e,r=t.height,i=(t.palette,t.sampleInterval),n=t.width,o=e.data;return this.processFrameWithQuantizer(o,n,r,i)}};return r}function l(e,t,r,n){function o(e){var t=e.length;if(2>t||t>256||t&t-1){ throw"Invalid code/color length, must be power of 2 and 2 .. 256."; }return t}function a(e,t,r,n){function o(r){for(;g>=r;){ e[t++]=255&f,f>>=8,g-=8,t===s+256&&(e[s]=255,s=t++) }}function a(e){f|=e<<g,g+=m,o(8)}e[t++]=r;var s=t++,d=1<<r,c=d-1,l=d+1,u=l+1,m=r+1,g=0,f=0,h=n[0]&c,p={};a(d);for(var v=1,b=n.length;b>v;++v){var w=n[v]&c,y=h<<8|w,C=p[y];if(C===i){for(f|=h<<g,g+=m;g>=8;){ e[t++]=255&f,f>>=8,g-=8,t===s+256&&(e[s]=255,s=t++); }4096===u?(a(d),u=l+1,m=r+1,p={}):(u>=1<<m&&++m,p[y]=u++),h=w}else { h=C }}return a(h),a(l),o(1),s+1===t?e[s]=0:(e[s]=t-s-1,e[t++]=0),t}var s=0;n=n===i?{}:n;var d=n.loop===i?null:n.loop,c=n.palette===i?null:n.palette;if(0>=t||0>=r||t>65535||r>65535){ throw"Width/Height invalid."; }e[s++]=71,e[s++]=73,e[s++]=70,e[s++]=56,e[s++]=57,e[s++]=97;var l=0,u=0;if(e[s++]=255&t,e[s++]=t>>8&255,e[s++]=255&r,e[s++]=r>>8&255,e[s++]=(null!==c?128:0)|l,e[s++]=u,e[s++]=0,null!==d){if(0>d||d>65535){ throw"Loop count invalid."; }e[s++]=33,e[s++]=255,e[s++]=11,e[s++]=78,e[s++]=69,e[s++]=84,e[s++]=83,e[s++]=67,e[s++]=65,e[s++]=80,e[s++]=69,e[s++]=50,e[s++]=46,e[s++]=48,e[s++]=3,e[s++]=1,e[s++]=255&d,e[s++]=d>>8&255,e[s++]=0}var m=!1;this.addFrame=function(t,r,n,d,l,u){if(m===!0&&(--s,m=!1),u=u===i?{}:u,0>t||0>r||t>65535||r>65535){ throw"x/y invalid."; }if(0>=n||0>=d||n>65535||d>65535){ throw"Width/Height invalid."; }if(l.length<n*d){ throw"Not enough pixels for the frame size."; }var g=!0,f=u.palette;if((f===i||null===f)&&(g=!1,f=c),f===i||null===f){ throw"Must supply either a local or global palette."; }for(var h=o(f),p=0;h>>=1;){ ++p; }h=1<<p;var v=u.delay===i?0:u.delay,b=u.disposal===i?0:u.disposal;if(0>b||b>3){ throw"Disposal out of range."; }var w=!1,y=0;if(u.transparent!==i&&null!==u.transparent&&(w=!0,y=u.transparent,0>y||y>=h)){ throw"Transparent color index."; }if((0!==b||w||0!==v)&&(e[s++]=33,e[s++]=249,e[s++]=4,e[s++]=b<<2|(w===!0?1:0),e[s++]=255&v,e[s++]=v>>8&255,e[s++]=y,e[s++]=0),e[s++]=44,e[s++]=255&t,e[s++]=t>>8&255,e[s++]=255&r,e[s++]=r>>8&255,e[s++]=255&n,e[s++]=n>>8&255,e[s++]=255&d,e[s++]=d>>8&255,e[s++]=g===!0?128|p-1:0,g===!0){ for(var C=0,k=f.length;k>C;++C){var S=f[C];e[s++]=S>>16&255,e[s++]=S>>8&255,e[s++]=255&S} }s=a(e,s,2>p?2:p,l)},this.end=function(){return m===!1&&(e[s++]=59,m=!0),s}}function u(e,t){e.getBase64GIF(function(e){t({error:!1,errorCode:"",errorMsg:"",image:e})})}function m(){function e(){w.each(l,function(e,t){t&&(t.text?f.addFrame(t.img,a,t.text):f.addFrame(t,a))}),u(f,n)}var r=arguments.length>0&&arguments[0]!==i?arguments[0]:{},n=r.callback,o=r.images,a=r.options,s=r.imagesLength,d={getUserMedia:!0,"window.URL":!0},c=C.validate(d),l=[],m=0,g=void 0,f=void 0;return c.error?n(c):(f=new O(a),w.each(o,function(r,i){var o=i;i.src&&(o=o.src),w.isElement(o)?(a.crossOrigin&&(o.crossOrigin=a.crossOrigin),l[r]=o,m+=1,m===s&&e()):w.isString(o)&&(g=new Image,a.crossOrigin&&(g.crossOrigin=a.crossOrigin),function(t){i.text&&(t.text=i.text),t.onerror=function(){var e=void 0;return--s,0===s?(e={},e.error="None of the requested images was capable of being retrieved",n(e)):void 0},t.onload=function(){l[r]=i.text?{img:t,text:t.text}:t,m+=1,m===s&&e(),w.removeElement(t)},t.src=o}(g),w.setCSSAttr(g,{position:"fixed",opacity:"0"}),t.body.appendChild(g))}),void 0)}function g(e){e=w.isObject(e)?e:{},A.stopVideoStreaming(e)}function f(e,r){var i=e.options||{},n=i.images,o=i.video,a=Number(i.gifWidth),s=Number(i.gifHeight),d=(Number(i.numFrames),e.cameraStream),c=e.videoElement,l=e.videoWidth,u=e.videoHeight,m=M.getCropDimensions({videoWidth:l,videoHeight:u,gifHeight:s,gifWidth:a}),f=r;i.crop=m,i.videoElement=c,i.videoWidth=l,i.videoHeight=u,i.cameraStream=d,w.isElement(c)&&(c.width=a+m.width,c.height=s+m.height,i.webcamVideoElement||(w.setCSSAttr(c,{position:"fixed",opacity:"0"}),t.body.appendChild(c)),c.play(),M.getGIF(i,function(e){n&&n.length||o&&o.length||g(e),f(e)}))}function h(){var e=arguments.length>0&&arguments[0]!==i?arguments[0]:{},t=e.callback,r=e.existingVideo,n=e.options,o={getUserMedia:!0,"window.URL":!0},a=C.validate(o),s=void 0,d=void 0;if(a.error){ return t(a); }if(w.isElement(r)&&r.src){if(d=r.src,s=w.getExtension(d),!w.isSupported.videoCodecs[s]){ return t(C.messages.videoCodecs) }}else { w.isArray(r)&&w.each(r,function(e,t){return s=t instanceof Blob?t.type.substr(t.type.lastIndexOf("/")+1,t.length):t.substr(t.lastIndexOf(".")+1,t.length),w.isSupported.videoCodecs[s]?(r=t,!1):void 0}); }A.startStreaming({completed:function(e){e.options=n||{},f(e,t)},existingVideo:r,crossOrigin:n.crossOrigin,options:n})}function p(){var e=arguments.length>0&&arguments[0]!==i?arguments[0]:{},t=e.callback,r=e.lastCameraStream,n=e.options,a=e.webcamVideoElement;return o()?n.savedRenderingContexts.length?(M.getGIF(n,function(e){t(e)}),void 0):(A.startVideoStreaming(function(){var e=arguments.length>0&&arguments[0]!==i?arguments[0]:{};e.options=n||{},f(e,t)},{lastCameraStream:r,callback:t,webcamVideoElement:a,crossOrigin:n.crossOrigin}),void 0):t(C.validate())}function v(e,t){if(t=w.isFunction(e)?e:t,e=w.isObject(e)?e:{},w.isFunction(t)){var r=w.mergeOptions(x,e)||{},i=e.cameraStream,n=r.images,o=n?n.length:0,a=r.video,s=r.webcamVideoElement;r=w.mergeOptions(r,{gifWidth:Math.floor(r.gifWidth),gifHeight:Math.floor(r.gifHeight)}),o?m({images:n,imagesLength:o,callback:t,options:r}):a?h({existingVideo:a,callback:t,options:r}):p({lastCameraStream:i,callback:t,webcamVideoElement:s,options:r})}}function b(e,t){if(t=w.isFunction(e)?e:t,e=w.isObject(e)?e:{},w.isFunction(t)){var r=w.mergeOptions(x,e),i=w.mergeOptions(r,{interval:.1,numFrames:1,gifWidth:Math.floor(r.gifWidth),gifHeight:Math.floor(r.gifHeight)});v(i,t)}}var w={URL:e.URL||e.webkitURL||e.mozURL||e.msURL,getUserMedia:function(){var e=r.getUserMedia||r.webkitGetUserMedia||r.mozGetUserMedia||r.msGetUserMedia;return e?e.bind(r):e}(),requestAnimFrame:e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame,requestTimeout:function(e,t){if(e=e||w.noop,t=t||0,!w.requestAnimFrame){ return setTimeout(e,t); }var r=(new Date).getTime(),i=new Object,n=w.requestAnimFrame,o=function a(){var o=(new Date).getTime(),s=o-r;s>=t?e.call():i.value=n(a)};return i.value=n(o),i},Blob:e.Blob||e.BlobBuilder||e.WebKitBlobBuilder||e.MozBlobBuilder||e.MSBlobBuilder,btoa:function(){var t=e.btoa||function(e){for(var t="",r=0,i=e.length,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=void 0,a=void 0,s=void 0,d=void 0,c=void 0,l=void 0,u=void 0;i>r;){ o=e.charCodeAt(r++),a=e.charCodeAt(r++),s=e.charCodeAt(r++),d=o>>2,c=(3&o)<<4|a>>4,l=(15&a)<<2|s>>6,u=63&s,isNaN(a)?l=u=64:isNaN(s)&&(u=64),t=t+n.charAt(d)+n.charAt(c)+n.charAt(l)+n.charAt(u); }return t};return t?t.bind(e):w.noop}(),isObject:function(e){return e&&"[object Object]"===Object.prototype.toString.call(e)},isEmptyObject:function(e){return w.isObject(e)&&!Object.keys(e).length},isArray:function(e){return e&&Array.isArray(e)},isFunction:function(e){return e&&"function"==typeof e},isElement:function(e){return e&&1===e.nodeType},isString:function(e){return"string"==typeof e||"[object String]"===Object.prototype.toString.call(e)},isSupported:{canvas:function(){var e=t.createElement("canvas");return e&&e.getContext&&e.getContext("2d")},webworkers:function(){return e.Worker},blob:function(){return w.Blob},Uint8Array:function(){return e.Uint8Array},Uint32Array:function(){return e.Uint32Array},videoCodecs:function(){var e=t.createElement("video"),r={mp4:!1,h264:!1,ogv:!1,ogg:!1,webm:!1};try{e&&e.canPlayType&&(r.mp4=""!==e.canPlayType('video/mp4; codecs="mp4v.20.8"'),r.h264=""!==(e.canPlayType('video/mp4; codecs="avc1.42E01E"')||e.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"')),r.ogv=""!==e.canPlayType('video/ogg; codecs="theora"'),r.ogg=""!==e.canPlayType('video/ogg; codecs="theora"'),r.webm=-1!==e.canPlayType('video/webm; codecs="vp8, vorbis"'))}catch(i){}return r}()},noop:function(){},each:function(e,t){var r=void 0,i=void 0;if(w.isArray(e)){ for(r=-1,i=e.length;++r<i&&t(r,e[r])!==!1;){ ; } }else if(w.isObject(e)){ for(r in e){ if(e.hasOwnProperty(r)&&t(r,e[r])===!1){ break } } }},mergeOptions:function(e,t){if(w.isObject(e)&&w.isObject(t)&&Object.keys){var r={};return w.each(e,function(t){r[t]=e[t]}),w.each(t,function(i){var n=t[i];r[i]=w.isObject(n)?e[i]?w.mergeOptions(e[i],n):n:n}),r}},setCSSAttr:function(e,t,r){w.isElement(e)&&(w.isString(t)&&w.isString(r)?e.style[t]=r:w.isObject(t)&&w.each(t,function(t,r){e.style[t]=r}))},removeElement:function(e){w.isElement(e)&&e.parentNode&&e.parentNode.removeChild(e)},createWebWorker:function(e){if(!w.isString(e)){ return{}; }try{var t=new w.Blob([e],{type:"text/javascript"}),r=w.URL.createObjectURL(t),i=new Worker(r);return{objectUrl:r,worker:i}}catch(n){return""+n}},getExtension:function(e){return e.substr(e.lastIndexOf(".")+1,e.length)},getFontSize:function(){var e=arguments.length>0&&arguments[0]!==i?arguments[0]:{};if(!t.body||e.resizeFont===!1){ return e.fontSize; }var r=e.text,n=e.gifWidth,o=parseInt(e.fontSize,10),a=parseInt(e.minFontSize,10),s=t.createElement("div"),d=t.createElement("span");for(s.setAttribute("width",n),s.appendChild(d),d.innerHTML=r,d.style.fontSize=o+"px",d.style.textIndent="-9999px",d.style.visibility="hidden",t.body.appendChild(d);d.offsetWidth>n&&o>=a;){ d.style.fontSize=--o+"px"; }return t.body.removeChild(d),o+"px"},webWorkerError:!1},y=Object.freeze({"default":w}),C={validate:function(e){e=w.isObject(e)?e:{};var t={};return w.each(C.validators,function(r,i){var n=i.errorCode;return e[n]||i.condition?void 0:(t=i,t.error=!0,!1)}),delete t.condition,t},isValid:function R(e){var t=C.validate(e),R=t.error!==!0?!0:!1;return R},validators:[{condition:w.isFunction(w.getUserMedia),errorCode:"getUserMedia",errorMsg:"The getUserMedia API is not supported in your browser"},{condition:w.isSupported.canvas(),errorCode:"canvas",errorMsg:"Canvas elements are not supported in your browser"},{condition:w.isSupported.webworkers(),errorCode:"webworkers",errorMsg:"The Web Workers API is not supported in your browser"},{condition:w.isFunction(w.URL),errorCode:"window.URL",errorMsg:"The window.URL API is not supported in your browser"},{condition:w.isSupported.blob(),errorCode:"window.Blob",errorMsg:"The window.Blob File API is not supported in your browser"},{condition:w.isSupported.Uint8Array(),errorCode:"window.Uint8Array",errorMsg:"The window.Uint8Array function constructor is not supported in your browser"},{condition:w.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"}}},k=Object.freeze({"default":C}),S=function(){},x={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:S,completeCallback:S,saveRenderingContexts:!1,savedRenderingContexts:[],showFrameText:!0,crossOrigin:"Anonymous",waterMark:null,waterMarkHeight:null,waterMarkWidth:null,waterMarkXCoordinate:1,waterMarkYCoordinate:1},F=Object.freeze({"default":x}),W=function(){},O=function(e){this.canvas=null,this.ctx=null,this.repeat=0,this.frames=[],this.numRenderedFrames=0,this.onRenderCompleteCallback=W,this.onRenderProgressCallback=W,this.workers=[],this.availableWorkers=[],this.generatingGIF=!1,this.options=e,this.initializeWebWorkers(e)};O.prototype={workerMethods:c(),initializeWebWorkers:function(e){var r=this,i=d.toString()+"("+c.toString()+"());",n=void 0,o=void 0,a=void 0,s=void 0,l=-1,u="";for(s=e.numWorkers;++l<s;){ n=w.createWebWorker(i),w.isObject(n)?(o=n.objectUrl,a=n.worker,r.workers.push({worker:a,objectUrl:o}),r.availableWorkers.push(a)):(u=n,w.webWorkerError=!!n); }this.workerError=u,this.canvas=t.createElement("canvas"),this.canvas.width=e.gifWidth,this.canvas.height=e.gifHeight,this.ctx=this.canvas.getContext("2d"),this.frames=[]},getWorker:function(){return this.availableWorkers.pop()},freeWorker:function(e){this.availableWorkers.push(e)},byteMap:function(){for(var e=[],t=0;256>t;t++){ e[t]=String.fromCharCode(t); }return e}(),bufferToString:function(e){for(var t=e.length,r="",i=-1;++i<t;){ r+=this.byteMap[e[i]]; }return r},onFrameFinished:function(e){var t=this,r=t.frames,i=t.options,n=!!(i.images||[]).length,o=r.every(function(e){return!e.beingProcessed&&e.done});t.numRenderedFrames++,n&&e(t.numRenderedFrames/r.length),t.onRenderProgressCallback(.75*t.numRenderedFrames/r.length),o?t.generatingGIF||t.generateGIF(r,t.onRenderCompleteCallback):w.requestTimeout(function(){t.processNextFrame()},1)},processFrame:function(e){var t=this,r=(this.options,this.options),n=r.progressCallback,o=r.sampleInterval,a=this.frames,s=void 0,d=void 0,c=function(){var e=arguments.length>0&&arguments[0]!==i?arguments[0]:{},r=e.data;delete s.data,s.pixels=Array.prototype.slice.call(r.pixels),s.palette=Array.prototype.slice.call(r.palette),s.done=!0,s.beingProcessed=!1,t.freeWorker(d),t.onFrameFinished(n)};return s=a[e],s.beingProcessed||s.done?(this.onFrameFinished(),void 0):(s.sampleInterval=o,s.beingProcessed=!0,s.gifshot=!0,d=this.getWorker(),d?(d.onmessage=c,d.postMessage(s)):c({data:t.workerMethods.run(s)}),void 0)},startRendering:function(e){this.onRenderCompleteCallback=e;for(var t=0;t<this.options.numWorkers&&t<this.frames.length;t++){ this.processFrame(t) }},processNextFrame:function(){for(var e=-1,t=0;t<this.frames.length;t++){var r=this.frames[t];if(!r.done&&!r.beingProcessed){e=t;break}}e>=0&&this.processFrame(e)},generateGIF:function(e,t){var r=[],i={loop:this.repeat},n=this.options,o=n.interval,a=n.frameDuration,s=n.images,d=!!s.length,c=n.gifHeight,u=n.gifWidth,m=new l(r,u,c,i),g=this.onRenderProgressCallback,f=d?100*o:0,h=void 0,p=void 0;this.generatingGIF=!0,w.each(e,function(t,r){var i=r.palette;g(.75+.25*r.position*1/e.length);for(var n=0;a>n;n++){ m.addFrame(0,0,u,c,r.pixels,{palette:i,delay:f}) }}),m.end(),g(1),this.frames=[],this.generatingGIF=!1,w.isFunction(t)&&(h=this.bufferToString(r),p="data:image/gif;base64,"+w.btoa(h),t(p))},setRepeat:function(e){this.repeat=e},addFrame:function(e,t,r){t=w.isObject(t)?t:{};var i=this,n=i.ctx,o=i.options,a=o.gifWidth,s=o.gifHeight,d=w.getFontSize(t),c=t,l=c.filter,u=c.fontColor,m=c.fontFamily,g=c.fontWeight,f=(c.gifHeight,c.gifWidth,c.text),h=c.textAlign,p=c.textBaseline,v=c.waterMark,b=c.waterMarkHeight,y=c.waterMarkWidth,C=c.waterMarkXCoordinate,k=c.waterMarkYCoordinate,S=t.textXCoordinate?t.textXCoordinate:"left"===h?1:"right"===h?a:a/2,x=t.textYCoordinate?t.textYCoordinate:"top"===p?1:"center"===p?s/2:s,F=g+" "+d+" "+m,W=r&&t.showFrameText?r:f,O=void 0;try{n.filter=l,n.drawImage(e,0,0,a,s),W&&(n.font=F,n.fillStyle=u,n.textAlign=h,n.textBaseline=p,n.fillText(W,S,x)),v&&n.drawImage(v,C,k,y,b),O=n.getImageData(0,0,a,s),i.addFrameImageData(O)}catch(E){return""+E}},addFrameImageData:function(){var e=arguments.length>0&&arguments[0]!==i?arguments[0]:{},t=this.frames,r=e.data;this.frames.push({data:r,width:e.width,height:e.height,palette:null,dithering:null,done:!1,beingProcessed:!1,position:t.length})},onRenderProgress:function(e){this.onRenderProgressCallback=e},isRendering:function(){return this.generatingGIF},getBase64GIF:function(e){var t=this,r=function(r){t.destroyWorkers(),w.requestTimeout(function(){e(r)},0)};t.startRendering(r)},destroyWorkers:function(){if(!this.workerError){var e=this.workers;w.each(e,function(e,t){var r=t.worker,i=t.objectUrl;r.terminate(),w.URL.revokeObjectURL(i)})}}};var E=function(){},M={getGIF:function(){var e=arguments.length>0&&arguments[0]!==i?arguments[0]:{},r=arguments[1];r=w.isFunction(r)?r:E;var n=t.createElement("canvas"),o=void 0,a=e.images,s=!!a.length,d=e.cameraStream,c=e.crop,l=e.filter,u=e.fontColor,m=e.fontFamily,g=e.fontWeight,f=e.keepCameraOn,h=(e.numWorkers,e.progressCallback),p=e.saveRenderingContexts,v=e.savedRenderingContexts,b=e.text,y=e.textAlign,C=e.textBaseline,k=e.videoElement,S=e.videoHeight,x=e.videoWidth,F=e.webcamVideoElement,W=e.waterMark,M=e.waterMarkHeight,A=e.waterMarkWidth,U=e.waterMarkXCoordinate,R=e.waterMarkYCoordinate,T=Number(e.gifWidth),I=Number(e.gifHeight),j=Number(e.interval),V=(Number(e.sampleInterval),s?0:1e3*j),H=[],z=v.length?v.length:e.numFrames,L=z,B=new O(e),P=w.getFontSize(e),G=e.textXCoordinate?e.textXCoordinate:"left"===y?1:"right"===y?T:T/2,D=e.textYCoordinate?e.textYCoordinate:"top"===C?1:"center"===C?I/2:I,N=g+" "+P+" "+m,q=c?Math.floor(c.scaledWidth/2):0,X=c?x-c.scaledWidth:0,Y=c?Math.floor(c.scaledHeight/2):0,Q=c?S-c.scaledHeight:0,_=function K(){function e(){try{X>x&&(X=x),Q>S&&(Q=S),0>q&&(q=0),0>Y&&(Y=0),o.filter=l,o.drawImage(k,q,Y,X,Q,0,0,T,I),t()}catch(r){if("NS_ERROR_NOT_AVAILABLE"!==r.name){ throw r; }w.requestTimeout(e,100)}}function t(){var e=void 0;p&&H.push(o.getImageData(0,0,T,I)),W&&o.drawImage(W,U,R,A,M),b&&(o.font=N,o.fillStyle=u,o.textAlign=y,o.textBaseline=C,o.fillText(b,G,D)),e=o.getImageData(0,0,T,I),B.addFrameImageData(e),L=i,h((z-L)/z),i>0&&w.requestTimeout(K,V),L||B.getBase64GIF(function(e){r({error:!1,errorCode:"",errorMsg:"",image:e,cameraStream:d,videoElement:k,webcamVideoElement:F,savedRenderingContexts:H,keepCameraOn:f})})}var i=L-1;v.length?(o.putImageData(v[z-L],0,0),t()):e()};z=z!==i?z:10,j=j!==i?j:.1,n.width=T,n.height=I,o=n.getContext("2d"),function J(){return v.length||0!==k.currentTime?(_(),void 0):(w.requestTimeout(J,100),void 0)}()},getCropDimensions:function(){var e=arguments.length>0&&arguments[0]!==i?arguments[0]:{},t=e.videoWidth,r=e.videoHeight,n=e.gifWidth,o=e.gifHeight,a={width:0,height:0,scaledWidth:0,scaledHeight:0};return t>r?(a.width=Math.round(t*(o/r))-n,a.scaledWidth=Math.round(a.width*(r/o))):(a.height=Math.round(r*(n/t))-o,a.scaledHeight=Math.round(a.height*(t/n))),a}},A={loadedData:!1,defaultVideoDimensions:{width:640,height:480},findVideoSize:function T(e){T.attempts=T.attempts||0;var t=e.cameraStream,r=e.completedCallback,i=e.videoElement;i&&(i.videoWidth>0&&i.videoHeight>0?(i.removeEventListener("loadeddata",A.findVideoSize),r({videoElement:i,cameraStream:t,videoWidth:i.videoWidth,videoHeight:i.videoHeight})):T.attempts<10?(T.attempts+=1,w.requestTimeout(function(){A.findVideoSize(e)},400)):r({videoElement:i,cameraStream:t,videoWidth:A.defaultVideoDimensions.width,videoHeight:A.defaultVideoDimensions.height}))},onStreamingTimeout:function(e){w.isFunction(e)&&e({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(e){var t=w.isArray(e.existingVideo)?e.existingVideo[0]:e.existingVideo,r=e.cameraStream,i=e.completedCallback,n=e.streamedCallback,o=e.videoElement;if(w.isFunction(n)&&n(),t){if(w.isString(t)){ o.src=t,o.innerHTML='<source src="'+t+'" type="video/'+w.getExtension(t)+'" />'; }else if(t instanceof Blob){try{o.src=w.URL.createObjectURL(t)}catch(a){}o.innerHTML='<source src="'+t+'" type="'+t.type+'" />'}}else if(o.mozSrcObject){ o.mozSrcObject=r; }else if(w.URL){ try{o.srcObject=r,o.src=w.URL.createObjectURL(r)}catch(a$1){o.srcObject=r} }o.play(),w.requestTimeout(function s(){s.count=s.count||0,A.loadedData===!0?(A.findVideoSize({videoElement:o,cameraStream:r,completedCallback:i}),A.loadedData=!1):(s.count+=1,s.count>10?A.findVideoSize({videoElement:o,cameraStream:r,completedCallback:i}):s())},0)},startStreaming:function(e){var r=w.isFunction(e.error)?e.error:w.noop,i=w.isFunction(e.streamed)?e.streamed:w.noop,n=w.isFunction(e.completed)?e.completed:w.noop,o=e.crossOrigin,a=e.existingVideo,s=e.lastCameraStream,d=e.options,c=e.webcamVideoElement,l=w.isElement(a)?a:c?c:t.createElement("video");o&&(l.crossOrigin=d.crossOrigin),l.autoplay=!0,l.loop=!0,l.muted=!0,l.addEventListener("loadeddata",function(){A.loadedData=!0,d.offset&&(l.currentTime=d.offset)}),a?A.stream({videoElement:l,existingVideo:a,completedCallback:n}):s?A.stream({videoElement:l,cameraStream:s,streamedCallback:i,completedCallback:n}):w.getUserMedia({video:!0},function(e){A.stream({videoElement:l,cameraStream:e,streamedCallback:i,completedCallback:n})},r)},startVideoStreaming:function(e){var t=arguments.length>1&&arguments[1]!==i?arguments[1]:{},r=t.timeout!==i?t.timeout:0,n=t.callback,o=t.webcamVideoElement,a=void 0;r>0&&(a=w.requestTimeout(function(){A.onStreamingTimeout(n)},1e4)),A.startStreaming({error:function(){n({error:!0,errorCode:"getUserMedia",errorMsg:"There was an issue with the getUserMedia API - the user probably denied permission",image:null,cameraStream:{}})},streamed:function(){clearTimeout(a)},completed:function(){var t=arguments.length>0&&arguments[0]!==i?arguments[0]:{},r=t.cameraStream,n=t.videoElement,o=t.videoHeight,a=t.videoWidth;e({cameraStream:r,videoElement:n,videoHeight:o,videoWidth:a})},lastCameraStream:t.lastCameraStream,webcamVideoElement:o,crossOrigin:t.crossOrigin,options:t})},stopVideoStreaming:function(e){e=w.isObject(e)?e:{};var t=e,r=t.keepCameraOn,i=t.videoElement,n=t.webcamVideoElement,o=e.cameraStream||{},a=o.getTracks?o.getTracks()||[]:[],s=!!a.length,d=a[0];!r&&s&&w.isFunction(d.stop)&&d.stop(),w.isElement(i)&&!n&&(i.pause(),w.isFunction(w.URL.revokeObjectURL)&&!w.webWorkerError&&i.src&&w.URL.revokeObjectURL(i.src),w.removeElement(i))}},U={utils:y,error:k,defaultOptions:F,createGIF:v,takeSnapShot:b,stopVideoStreaming:g,isSupported:n,isWebCamGIFSupported:o,isExistingVideoGIFSupported:s,isExistingImagesGIFSupported:a,VERSION:"0.4.5"};"function"==typeof define&&define.amd?define([],function(){return U}):"undefined"!=typeof exports?module.exports=U:e.gifshot=U}("undefined"!=typeof window?window:{},"undefined"!=typeof document?document:{createElement:function(){}},"undefined"!=typeof window?window.navigator:{});
(function (global, factory) {
if(typeof exports === 'object' && typeof module !== 'undefined') {
module.exports = factory();
module.exports.default = factory();
}
else if(typeof define === 'function' && define.amd) {
define(factory);
}
else {
(global = global || self, global.heic2any = factory())
}
}(this, function () { 'use strict';
var workerString = "\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.