@u1f992/pdfdiff 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.clang-format +3 -0
- package/.github/workflows/gh-pages.yml +6 -1
- package/LICENSE +68 -81
- package/dist/browser.js +1405 -3099
- package/dist/browser.js.map +1 -1
- package/dist/cli-png-worker.d.ts +13 -0
- package/dist/cli-png-worker.d.ts.map +1 -0
- package/dist/cli-png-worker.js +287 -0
- package/dist/cli-png-worker.js.map +1 -0
- package/dist/cli.js +401 -3110
- package/dist/cli.js.map +1 -1
- package/dist/core.wasm +0 -0
- package/dist/decode.d.ts +9 -0
- package/dist/decode.d.ts.map +1 -0
- package/dist/diff.d.ts +2 -1
- package/dist/diff.d.ts.map +1 -1
- package/dist/gs-wasm/gs.js +5821 -0
- package/dist/gs-wasm/gs.wasm +0 -0
- package/dist/gs-wasm/index.js +120 -0
- package/dist/gs-wasm/index.js.map +1 -0
- package/dist/gs-wasm/worker.js +764 -0
- package/dist/gs-wasm/worker.js.map +1 -0
- package/dist/image.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.html +6 -1
- package/dist/index.js +310 -3094
- package/dist/index.js.map +1 -1
- package/dist/iterable.d.ts.map +1 -1
- package/dist/jimp.d.ts +23 -1
- package/dist/jimp.d.ts.map +1 -1
- package/dist/pdf.d.ts +15 -4
- package/dist/pdf.d.ts.map +1 -1
- package/dist/perf.d.ts +16 -0
- package/dist/perf.d.ts.map +1 -0
- package/dist/rgba-color.d.ts.map +1 -1
- package/dist/squoosh_png_bg.wasm +0 -0
- package/dist/style.css +12 -0
- package/dist/transferable.d.ts +11 -0
- package/dist/transferable.d.ts.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/worker.d.ts +8 -8
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +144 -3210
- package/dist/worker.js.map +1 -1
- package/package.json +11 -4
- package/rollup.config.js +83 -5
- package/scripts/build-wasm.sh +32 -0
- package/src/browser.ts +122 -9
- package/src/cli-png-worker.ts +42 -0
- package/src/cli.ts +113 -34
- package/src/decode.ts +15 -0
- package/src/diff.ts +99 -51
- package/src/image.ts +4 -18
- package/src/index.html +6 -1
- package/src/index.test.ts +10 -18
- package/src/index.ts +176 -76
- package/src/iterable.test.ts +0 -17
- package/src/iterable.ts +0 -17
- package/src/jimp.ts +25 -7
- package/src/pdf.ts +99 -62
- package/src/perf.ts +77 -0
- package/src/rgba-color.test.ts +0 -17
- package/src/rgba-color.ts +0 -17
- package/src/style.css +12 -0
- package/src/transferable.ts +15 -0
- package/src/worker.ts +106 -100
- package/wasm/Makefile +34 -0
- package/wasm/bindings.cpp +76 -0
- package/wasm/core.c +176 -0
- package/wasm/core.h +69 -0
- package/dist/mupdf-wasm.wasm +0 -0
package/dist/worker.js
CHANGED
|
@@ -1,2981 +1,3 @@
|
|
|
1
|
-
var _$1=async function(_={}){var a,e,t=_,s=new Promise(((_,t)=>{a=_,e=t;})),n="object"==typeof window,i="undefined"!=typeof WorkerGlobalScope,m="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node&&"renderer"!=process.type;if(m){const{createRequire:_}=await import('module');var r=_(import.meta.url);}var o,p,d="./this.program",w=(_,a)=>{throw a},f=import.meta.url,l="";if(m){var c=r("fs"),g=r("path");f.startsWith("file:")&&(l=g.dirname(r("url").fileURLToPath(f))+"/"),p=_=>(_=U(_)?new URL(_):_,c.readFileSync(_)),o=async(_,a=true)=>(_=U(_)?new URL(_):_,c.readFileSync(_,a?void 0:"utf8")),process.argv.length>1&&(d=process.argv[1].replace(/\\/g,"/")),process.argv.slice(2),w=(_,a)=>{throw process.exitCode=_,a};}else if(n||i){try{l=new URL(".",f).href;}catch{}i&&(p=_=>{var a=new XMLHttpRequest;return a.open("GET",_,false),a.responseType="arraybuffer",a.send(null),new Uint8Array(a.response)}),o=async _=>{if(U(_))return new Promise(((a,e)=>{var t=new XMLHttpRequest;t.open("GET",_,true),t.responseType="arraybuffer",t.onload=()=>{200==t.status||0==t.status&&t.response?a(t.response):e(t.status);},t.onerror=e,t.send(null);}));var a=await fetch(_,{credentials:"same-origin"});if(a.ok)return a.arrayBuffer();throw new Error(a.status+" : "+a.url)};}var u,h,b,v,y,x,k,T=console.log.bind(console),j=console.error.bind(console),$=false,A=false,U=_=>_.startsWith("file://");function R(){var _=h.buffer;t.HEAPU8=b=new Uint8Array(_),t.HEAP32=v=new Int32Array(_),t.HEAPU32=y=new Uint32Array(_),t.HEAPF32=new Float32Array(_),k=new Float64Array(_),x=new BigInt64Array(_),new BigUint64Array(_);}var E,C=0,S=null;function M(){return t.locateFile?(_="mupdf-wasm.wasm",t.locateFile?t.locateFile(_,l):l+_):new URL("mupdf-wasm.wasm",import.meta.url).href;var _;}async function D(_){if(!u)try{var a=await o(_);return new Uint8Array(a)}catch{}return function(_){if(_==E&&u)return new Uint8Array(u);if(p)return p(_);throw "both async and sync fetching of the wasm failed"}(_)}async function F(_,a){try{var s=await D(_);return await WebAssembly.instantiate(s,a)}catch(_){j(`failed to asynchronously prepare wasm: ${_}`),function(_){t.onAbort?.(_),j(_="Aborted("+_+")"),$=true,_+=". Build with -sASSERTIONS for more info.",A&&r_();var a=new WebAssembly.RuntimeError(_);throw e(a),a}(_);}}class P{name="ExitStatus";constructor(_){this.message=`Program terminated with exit(${_})`,this.status=_;}}var I=_=>{for(;_.length>0;)_.shift()(t);},B=[],q=_=>B.push(_),L=[],W=_=>L.push(_),z=true,H=new TextDecoder,N=(_,a)=>{if(!_)return "";for(var e=_+a,t=_;!(t>=e)&&b[t];)++t;return H.decode(b.subarray(_,t))},G=_=>_<-9007199254740992||_>9007199254740992?NaN:Number(_),Y=(_,a,e)=>((_,a,e,t)=>{if(!(t>0))return 0;for(var s=e,n=e+t-1,i=0;i<_.length;++i){var m=_.charCodeAt(i);if(m>=55296&&m<=57343&&(m=65536+((1023&m)<<10)|1023&_.charCodeAt(++i)),m<=127){if(e>=n)break;a[e++]=m;}else if(m<=2047){if(e+1>=n)break;a[e++]=192|m>>6,a[e++]=128|63&m;}else if(m<=65535){if(e+2>=n)break;a[e++]=224|m>>12,a[e++]=128|m>>6&63,a[e++]=128|63&m;}else {if(e+3>=n)break;a[e++]=240|m>>18,a[e++]=128|m>>12&63,a[e++]=128|m>>6&63,a[e++]=128|63&m;}}return a[e]=0,e-s})(_,b,a,e),X=()=>Date.now(),J=[],K=(_,a,e)=>{var t=((_,a)=>{var e;for(J.length=0;e=b[_++];){var t=105!=e;a+=(t&=112!=e)&&a%8?4:0,J.push(112==e?y[a>>2]:106==e?x[a>>3]:105==e?v[a>>2]:k[a>>3]),a+=t?8:4;}return J})(a,e);return n_[_](...t)},Q=_=>{var a=(_-h.buffer.byteLength+65535)/65536|0;try{return h.grow(a),R(),1}catch(_){}},V={},Z=()=>{if(!Z.strings){var _={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:d||"./this.program"};for(var a in V) void 0===V[a]?delete _[a]:_[a]=V[a];var e=[];for(var a in _)e.push(`${a}=${_[a]}`);Z.strings=e;}return Z.strings},__=_=>{for(var a=0,e=0;e<_.length;++e){var t=_.charCodeAt(e);t<=127?a++:t<=2047?a+=2:t>=55296&&t<=57343?(a+=4,++e):a+=3;}return a},a_=_=>{z||(t.onExit?.(_),$=true),w(_,new P(_));},e_=(_,a)=>{a_(_);},t_=[null,[],[]],s_=(_,a)=>{var e=t_[_];0===a||10===a?((1===_?T:j)(((_,a=0,e=NaN)=>{for(var t=a+e,s=a;_[s]&&!(s>=t);)++s;return H.decode(_.buffer?_.subarray(a,s):new Uint8Array(_.slice(a,s)))})(e)),e.length=0):e.push(a);};t.noExitRuntime&&(z=t.noExitRuntime),t.print&&(T=t.print),t.printErr&&(j=t.printErr),t.wasmBinary&&(u=t.wasmBinary),t.arguments&&t.arguments,t.thisProgram&&(d=t.thisProgram),t.UTF8ToString=N,t.stringToUTF8=Y,t.lengthBytesUTF8=__;var n_={6015984:()=>{throw "TRYLATER"},6016006:()=>{throw "ABORT"},6016025:_=>{throw new Error(N(_))},6016064:()=>{throw new Error("Cannot create MuPDF context!")},6016117:(_,a,e,t,s,n,i)=>{globalThis.$libmupdf_text_walk.begin_span(_,a,e,t,s,n,i);},6016191:(_,a,e,t,s,n,i,m)=>{globalThis.$libmupdf_text_walk.show_glyph(_,a,e,t,s,n,i,m);},6016269:_=>{globalThis.$libmupdf_text_walk.end_span(_);},6016317:(_,a,e,t)=>globalThis.$libmupdf_load_font_file(_,a,e,t),6016380:(_,a,e,t)=>globalThis.$libmupdf_stm_read(_,a,e,t),6016438:_=>{globalThis.$libmupdf_stm_close(_);},6016478:(_,a,e,t)=>globalThis.$libmupdf_stm_seek(_,a,e,t),6016536:(_,a,e)=>{globalThis.$libmupdf_path_walk.moveto(_,a,e);},6016590:(_,a,e)=>{globalThis.$libmupdf_path_walk.lineto(_,a,e);},6016644:(_,a,e,t,s,n,i)=>{globalThis.$libmupdf_path_walk.curveto(_,a,e,t,s,n,i);},6016715:_=>{globalThis.$libmupdf_path_walk.closepath(_);},6016764:_=>{globalThis.$libmupdf_device.close_device(_);},6016813:_=>{globalThis.$libmupdf_device.drop_device(_);},6016861:(_,a,e,t,s,n,i,m)=>{globalThis.$libmupdf_device.fill_path(_,a,e,t,s,n,i,m);},6016935:(_,a,e,t,s,n,i,m)=>{globalThis.$libmupdf_device.stroke_path(_,a,e,t,s,n,i,m);},6017011:(_,a,e,t)=>{globalThis.$libmupdf_device.clip_path(_,a,e,t);},6017069:(_,a,e,t)=>{globalThis.$libmupdf_device.clip_stroke_path(_,a,e,t);},6017134:(_,a,e,t,s,n,i)=>{globalThis.$libmupdf_device.fill_text(_,a,e,t,s,n,i);},6017204:(_,a,e,t,s,n,i,m)=>{globalThis.$libmupdf_device.stroke_text(_,a,e,t,s,n,i,m);},6017280:(_,a,e)=>{globalThis.$libmupdf_device.clip_text(_,a,e);},6017334:(_,a,e,t)=>{globalThis.$libmupdf_device.clip_stroke_text(_,a,e,t);},6017399:(_,a,e)=>{globalThis.$libmupdf_device.ignore_text(_,a,e);},6017455:(_,a,e,t)=>{globalThis.$libmupdf_device.fill_shade(_,a,e,t);},6017514:(_,a,e,t)=>{globalThis.$libmupdf_device.fill_image(_,a,e,t);},6017573:(_,a,e,t,s,n,i)=>{globalThis.$libmupdf_device.fill_image_mask(_,a,e,t,s,n,i);},6017649:(_,a,e)=>{globalThis.$libmupdf_device.clip_image_mask(_,a,e);},6017709:_=>{globalThis.$libmupdf_device.pop_clip(_);},6017754:(_,a,e,t,s,n)=>{globalThis.$libmupdf_device.begin_mask(_,a,e,t,s,n);},6017821:(_,a)=>{globalThis.$libmupdf_device.end_mask(_,a);},6017870:(_,a,e,t,s,n,i)=>{globalThis.$libmupdf_device.begin_group(_,a,e,t,s,n,i);},6017942:_=>{globalThis.$libmupdf_device.end_group(_);},6017988:(_,a,e,t,s,n,i)=>globalThis.$libmupdf_device.begin_tile(_,a,e,t,s,n,i),6018066:_=>{globalThis.$libmupdf_device.end_tile(_);},6018111:(_,a)=>{globalThis.$libmupdf_device.begin_layer(_,a);},6018163:_=>{globalThis.$libmupdf_device.end_layer(_);}},i_={g:function(_,a,e){return 0},u:function(_,a){},t:function(_,a,e){return 0},f:function(_,a,e,t){},s:_=>{},e:(_,a,e)=>{},m:function(_,a){_=G(_);var e=new Date(1e3*_);v[a>>2]=e.getUTCSeconds(),v[a+4>>2]=e.getUTCMinutes(),v[a+8>>2]=e.getUTCHours(),v[a+12>>2]=e.getUTCDate(),v[a+16>>2]=e.getUTCMonth(),v[a+20>>2]=e.getUTCFullYear()-1900,v[a+24>>2]=e.getUTCDay();var t=Date.UTC(e.getUTCFullYear(),0,1,0,0,0,0),s=(e.getTime()-t)/864e5|0;v[a+28>>2]=s;},l:function(_){var a=(()=>{var a=Date.UTC(v[_+20>>2]+1900,v[_+16>>2],v[_+12>>2],v[_+8>>2],v[_+4>>2],v[_>>2],0),e=new Date(a);v[_+24>>2]=e.getUTCDay();var t=Date.UTC(e.getUTCFullYear(),0,1,0,0,0,0),s=(e.getTime()-t)/864e5|0;return v[_+28>>2]=s,e.getTime()/1e3})();return BigInt(a)},k:(_,a,e,t)=>{var s=(new Date).getFullYear(),n=new Date(s,0,1),i=new Date(s,6,1),m=n.getTimezoneOffset(),r=i.getTimezoneOffset(),o=Math.max(m,r);y[_>>2]=60*o,v[a>>2]=Number(m!=r);var p=_=>{var a=_>=0?"-":"+",e=Math.abs(_);return `UTC${a}${String(Math.floor(e/60)).padStart(2,"0")}${String(e%60).padStart(2,"0")}`},d=p(m),w=p(r);r<m?(Y(d,e,17),Y(w,t,17)):(Y(d,t,17),Y(w,e,17));},r:function(_,a,e){if(!((t=_)>=0&&t<=3))return 28;var t,s;s=0===_?X():performance.now();var n=Math.round(1e3*s*1e3);return x[e>>3]=BigInt(n),0},a:(_,a,e)=>K(_,a,e),j:(_,a,e)=>K(_,a,e),i:X,h:_=>{var a,e,t=b.length,s=2147483648;if((_>>>=0)>s)return false;for(var n=1;n<=4;n*=2){var i=t*(1+.2/n);i=Math.min(i,_+100663296);var m=Math.min(s,(a=Math.max(_,i),e=65536,Math.ceil(a/e)*e));if(Q(m))return true}return false},q:(_,a)=>{var e=0,t=0;for(var s of Z()){var n=a+e;y[_+t>>2]=n,e+=Y(s,n,1/0)+1,t+=4;}return 0},p:(_,a)=>{var e=Z();y[_>>2]=e.length;var t=0;for(var s of e)t+=__(s)+1;return y[a>>2]=t,0},b:e_,d:_=>52,o:(_,a,e,t)=>52,n:function(_,a,e,t){return 70},c:(_,a,e,t)=>{for(var s=0,n=0;n<e;n++){var i=y[a>>2],m=y[a+4>>2];a+=8;for(var r=0;r<m;r++)s_(_,b[i+r]);s+=m;}return y[t>>2]=s,0}},m_=await async function(){function _(_,a){return m_=_.exports,h=m_.v,R(),function(){if(C--,t.monitorRunDependencies?.(C),0==C&&S){var _=S;S=null,_();}}(),m_}C++,t.monitorRunDependencies?.(C);var a={a:i_};if(t.instantiateWasm)return new Promise(((e,s)=>{t.instantiateWasm(a,((a,t)=>{e(_(a));}));}));E??=M();try{var s=function(a){return _(a.instance)}(await async function(_,a,e){if(!_&&"function"==typeof WebAssembly.instantiateStreaming&&!U(a)&&!m)try{var t=fetch(a,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(t,e)}catch(_){j(`wasm streaming compile failed: ${_}`),j("falling back to ArrayBuffer instantiation");}return F(a,e)}(u,E,a));return s}catch(_){return e(_),Promise.reject(_)}}(),r_=(m_.w,t._wasm_init_context=m_.x,t._wasm_malloc=m_.y,t._wasm_free=m_.z,t._wasm_enable_icc=m_.A,t._wasm_disable_icc=m_.B,t._wasm_set_user_css=m_.C,t._wasm_Memento_checkAllMemory=m_.D,t._wasm_Memento_listBlocks=m_.E,t._wasm_keep_buffer=m_.F,t._wasm_drop_buffer=m_.G,t._wasm_keep_stream=m_.H,t._wasm_drop_stream=m_.I,t._wasm_keep_colorspace=m_.J,t._wasm_drop_colorspace=m_.K,t._wasm_keep_pixmap=m_.L,t._wasm_drop_pixmap=m_.M,t._wasm_keep_font=m_.N,t._wasm_drop_font=m_.O,t._wasm_keep_stroke_state=m_.P,t._wasm_drop_stroke_state=m_.Q,t._wasm_keep_image=m_.R,t._wasm_drop_image=m_.S,t._wasm_keep_shade=m_.T,t._wasm_drop_shade=m_.U,t._wasm_keep_path=m_.V,t._wasm_drop_path=m_.W,t._wasm_keep_text=m_.X,t._wasm_drop_text=m_.Y,t._wasm_keep_device=m_.Z,t._wasm_drop_device=m_._,t._wasm_keep_display_list=m_.$,t._wasm_drop_display_list=m_.aa,t._wasm_drop_stext_page=m_.ba,t._wasm_drop_document_writer=m_.ca,t._wasm_drop_outline_iterator=m_.da,t._wasm_keep_document=m_.ea,t._wasm_drop_document=m_.fa,t._wasm_keep_page=m_.ga,t._wasm_drop_page=m_.ha,t._wasm_keep_link=m_.ia,t._wasm_drop_link=m_.ja,t._wasm_keep_outline=m_.ka,t._wasm_drop_outline=m_.la,t._wasm_pdf_keep_annot=m_.ma,t._wasm_pdf_drop_annot=m_.na,t._wasm_pdf_keep_obj=m_.oa,t._wasm_pdf_drop_obj=m_.pa,t._wasm_pdf_keep_graft_map=m_.qa,t._wasm_pdf_drop_graft_map=m_.ra,t._wasm_buffer_get_data=m_.sa,t._wasm_buffer_get_len=m_.ta,t._wasm_colorspace_get_type=m_.ua,t._wasm_colorspace_get_n=m_.va,t._wasm_colorspace_get_name=m_.wa,t._wasm_pixmap_get_w=m_.xa,t._wasm_pixmap_get_h=m_.ya,t._wasm_pixmap_get_x=m_.za,t._wasm_pixmap_get_y=m_.Aa,t._wasm_pixmap_get_n=m_.Ba,t._wasm_pixmap_get_stride=m_.Ca,t._wasm_pixmap_get_alpha=m_.Da,t._wasm_pixmap_get_xres=m_.Ea,t._wasm_pixmap_get_yres=m_.Fa,t._wasm_pixmap_get_colorspace=m_.Ga,t._wasm_pixmap_get_samples=m_.Ha,t._wasm_pixmap_set_xres=m_.Ia,t._wasm_pixmap_set_yres=m_.Ja,t._wasm_font_get_name=m_.Ka,t._wasm_stroke_state_get_start_cap=m_.La,t._wasm_stroke_state_set_start_cap=m_.Ma,t._wasm_stroke_state_get_dash_cap=m_.Na,t._wasm_stroke_state_set_dash_cap=m_.Oa,t._wasm_stroke_state_get_end_cap=m_.Pa,t._wasm_stroke_state_set_end_cap=m_.Qa,t._wasm_stroke_state_get_linejoin=m_.Ra,t._wasm_stroke_state_set_linejoin=m_.Sa,t._wasm_stroke_state_get_linewidth=m_.Ta,t._wasm_stroke_state_set_linewidth=m_.Ua,t._wasm_stroke_state_get_miterlimit=m_.Va,t._wasm_stroke_state_set_miterlimit=m_.Wa,t._wasm_stroke_state_get_dash_phase=m_.Xa,t._wasm_stroke_state_set_dash_phase=m_.Ya,t._wasm_stroke_state_get_dash_len=m_.Za,t._wasm_image_get_w=m_._a,t._wasm_image_get_h=m_.$a,t._wasm_image_get_n=m_.ab,t._wasm_image_get_bpc=m_.bb,t._wasm_image_get_xres=m_.cb,t._wasm_image_get_yres=m_.db,t._wasm_image_get_imagemask=m_.eb,t._wasm_image_get_colorspace=m_.fb,t._wasm_image_get_mask=m_.gb,t._wasm_outline_get_title=m_.hb,t._wasm_outline_get_uri=m_.ib,t._wasm_outline_get_next=m_.jb,t._wasm_outline_get_down=m_.kb,t._wasm_outline_get_is_open=m_.lb,t._wasm_outline_item_get_title=m_.mb,t._wasm_outline_item_get_uri=m_.nb,t._wasm_outline_item_get_is_open=m_.ob,t._wasm_link_get_rect=m_.pb,t._wasm_link_get_uri=m_.qb,t._wasm_link_get_next=m_.rb,t._wasm_stext_page_get_mediabox=m_.sb,t._wasm_stext_page_get_first_block=m_.tb,t._wasm_stext_block_get_next=m_.ub,t._wasm_stext_block_get_type=m_.vb,t._wasm_stext_block_get_bbox=m_.wb,t._wasm_stext_block_get_first_line=m_.xb,t._wasm_stext_block_get_transform=m_.yb,t._wasm_stext_block_get_image=m_.zb,t._wasm_stext_line_get_next=m_.Ab,t._wasm_stext_line_get_wmode=m_.Bb,t._wasm_stext_line_get_dir=m_.Cb,t._wasm_stext_line_get_bbox=m_.Db,t._wasm_stext_line_get_first_char=m_.Eb,t._wasm_stext_char_get_next=m_.Fb,t._wasm_stext_char_get_c=m_.Gb,t._wasm_stext_char_get_origin=m_.Hb,t._wasm_stext_char_get_quad=m_.Ib,t._wasm_stext_char_get_size=m_.Jb,t._wasm_stext_char_get_font=m_.Kb,t._wasm_stext_char_get_argb=m_.Lb,t._wasm_link_dest_get_chapter=m_.Mb,t._wasm_link_dest_get_page=m_.Nb,t._wasm_link_dest_get_type=m_.Ob,t._wasm_link_dest_get_x=m_.Pb,t._wasm_link_dest_get_y=m_.Qb,t._wasm_link_dest_get_w=m_.Rb,t._wasm_link_dest_get_h=m_.Sb,t._wasm_link_dest_get_zoom=m_.Tb,t._wasm_pdf_filespec_params_get_filename=m_.Ub,t._wasm_pdf_filespec_params_get_mimetype=m_.Vb,t._wasm_pdf_filespec_params_get_size=m_.Wb,t._wasm_pdf_filespec_params_get_created=m_.Xb,t._wasm_pdf_filespec_params_get_modified=m_.Yb,t._wasm_pdf_page_get_obj=m_.Zb,t._wasm_new_buffer=m_._b,t._wasm_new_buffer_from_data=m_.$b,t._wasm_append_string=m_.ac,t._wasm_append_byte=m_.bc,t._wasm_append_buffer=m_.cc,t._wasm_slice_buffer=m_.dc,t._wasm_string_from_buffer=m_.ec,t._wasm_device_gray=m_.fc,t._wasm_device_rgb=m_.gc,t._wasm_device_bgr=m_.hc,t._wasm_device_cmyk=m_.ic,t._wasm_device_lab=m_.jc,t._wasm_new_icc_colorspace=m_.kc,t._wasm_new_stroke_state=m_.lc,t._wasm_stroke_state_get_dash_item=m_.mc,t._wasm_stroke_state_set_dash_item=m_.nc,t._wasm_new_base14_font=m_.oc,t._wasm_new_cjk_font=m_.pc,t._wasm_new_font_from_buffer=m_.qc,t._wasm_encode_character=m_.rc,t._wasm_advance_glyph=m_.sc,t._wasm_font_is_monospaced=m_.tc,t._wasm_font_is_serif=m_.uc,t._wasm_font_is_bold=m_.vc,t._wasm_font_is_italic=m_.wc,t._wasm_new_image_from_pixmap=m_.xc,t._wasm_new_image_from_buffer=m_.yc,t._wasm_get_pixmap_from_image=m_.zc,t._wasm_new_pixmap_from_page=m_.Ac,t._wasm_new_pixmap_from_page_contents=m_.Bc,t._wasm_pdf_new_pixmap_from_page_with_usage=m_.Cc,t._wasm_pdf_new_pixmap_from_page_contents_with_usage=m_.Dc,t._wasm_new_pixmap_with_bbox=m_.Ec,t._wasm_clear_pixmap=m_.Fc,t._wasm_clear_pixmap_with_value=m_.Gc,t._wasm_invert_pixmap=m_.Hc,t._wasm_invert_pixmap_luminance=m_.Ic,t._wasm_gamma_pixmap=m_.Jc,t._wasm_tint_pixmap=m_.Kc,t._wasm_new_buffer_from_pixmap_as_png=m_.Lc,t._wasm_new_buffer_from_pixmap_as_pam=m_.Mc,t._wasm_new_buffer_from_pixmap_as_psd=m_.Nc,t._wasm_new_buffer_from_pixmap_as_jpeg=m_.Oc,t._wasm_convert_pixmap=m_.Pc,t._wasm_warp_pixmap=m_.Qc,t._wasm_bound_shade=m_.Rc,t._wasm_new_display_list=m_.Sc,t._wasm_bound_display_list=m_.Tc,t._wasm_run_display_list=m_.Uc,t._wasm_new_pixmap_from_display_list=m_.Vc,t._wasm_new_stext_page_from_display_list=m_.Wc,t._wasm_search_display_list=m_.Xc,t._wasm_new_path=m_.Yc,t._wasm_moveto=m_.Zc,t._wasm_lineto=m_._c,t._wasm_curveto=m_.$c,t._wasm_curvetov=m_.ad,t._wasm_curvetoy=m_.bd,t._wasm_closepath=m_.cd,t._wasm_rectto=m_.dd,t._wasm_transform_path=m_.ed,t._wasm_bound_path=m_.fd,t._wasm_new_text=m_.gd,t._wasm_bound_text=m_.hd,t._wasm_show_glyph=m_.id,t._wasm_show_string=m_.jd,t._wasm_new_draw_device=m_.kd,t._wasm_new_display_list_device=m_.ld,t._wasm_close_device=m_.md,t._wasm_fill_path=m_.nd,t._wasm_stroke_path=m_.od,t._wasm_clip_path=m_.pd,t._wasm_clip_stroke_path=m_.qd,t._wasm_fill_text=m_.rd,t._wasm_stroke_text=m_.sd,t._wasm_clip_text=m_.td,t._wasm_clip_stroke_text=m_.ud,t._wasm_ignore_text=m_.vd,t._wasm_fill_shade=m_.wd,t._wasm_fill_image=m_.xd,t._wasm_fill_image_mask=m_.yd,t._wasm_clip_image_mask=m_.zd,t._wasm_pop_clip=m_.Ad,t._wasm_begin_mask=m_.Bd,t._wasm_end_mask=m_.Cd,t._wasm_begin_group=m_.Dd,t._wasm_end_group=m_.Ed,t._wasm_begin_tile=m_.Fd,t._wasm_end_tile=m_.Gd,t._wasm_begin_layer=m_.Hd,t._wasm_end_layer=m_.Id,t._wasm_new_document_writer_with_buffer=m_.Jd,t._wasm_begin_page=m_.Kd,t._wasm_end_page=m_.Ld,t._wasm_close_document_writer=m_.Md,t._wasm_print_stext_page_as_json=m_.Nd,t._wasm_search_stext_page=m_.Od,t._wasm_snap_selection=m_.Pd,t._wasm_copy_selection=m_.Qd,t._wasm_highlight_selection=m_.Rd,t._wasm_print_stext_page_as_html=m_.Sd,t._wasm_print_stext_page_as_text=m_.Td,t._wasm_open_document_with_buffer=m_.Ud,t._wasm_open_document_with_stream=m_.Vd,t._wasm_format_link_uri=m_.Wd,t._wasm_needs_password=m_.Xd,t._wasm_authenticate_password=m_.Yd,t._wasm_has_permission=m_.Zd,t._wasm_count_pages=m_._d,t._wasm_load_page=m_.$d,t._wasm_lookup_metadata=m_.ae,t._wasm_set_metadata=m_.be,t._wasm_resolve_link=m_.ce,t._wasm_resolve_link_dest=m_.de,t._wasm_load_outline=m_.ee,t._wasm_outline_get_page=m_.fe,t._wasm_layout_document=m_.ge,t._wasm_is_document_reflowable=m_.he,t._wasm_link_set_rect=m_.ie,t._wasm_link_set_uri=m_.je,t._wasm_bound_page=m_.ke,t._wasm_load_links=m_.le,t._wasm_create_link=m_.me,t._wasm_delete_link=m_.ne,t._wasm_run_page=m_.oe,t._wasm_run_page_contents=m_.pe,t._wasm_run_page_annots=m_.qe,t._wasm_run_page_widgets=m_.re,t._wasm_new_stext_page_from_page=m_.se,t._wasm_new_display_list_from_page=m_.te,t._wasm_new_display_list_from_page_contents=m_.ue,t._wasm_page_label=m_.ve,t._wasm_search_page=m_.we,t._wasm_new_outline_iterator=m_.xe,t._wasm_outline_iterator_next=m_.ye,t._wasm_outline_iterator_prev=m_.ze,t._wasm_outline_iterator_up=m_.Ae,t._wasm_outline_iterator_down=m_.Be,t._wasm_outline_iterator_delete=m_.Ce,t._wasm_outline_iterator_item=m_.De,t._wasm_outline_iterator_insert=m_.Ee,t._wasm_outline_iterator_update=m_.Fe,t._wasm_pdf_document_from_fz_document=m_.Ge,t._wasm_pdf_page_from_fz_page=m_.He,t._wasm_pdf_create_document=m_.Ie,t._wasm_pdf_version=m_.Je,t._wasm_pdf_was_repaired=m_.Ke,t._wasm_pdf_has_unsaved_changes=m_.Le,t._wasm_pdf_can_be_saved_incrementally=m_.Me,t._wasm_pdf_count_versions=m_.Ne,t._wasm_pdf_count_unsaved_versions=m_.Oe,t._wasm_pdf_validate_change_history=m_.Pe,t._wasm_pdf_enable_journal=m_.Qe,t._wasm_pdf_undoredo_state_position=m_.Re,t._wasm_pdf_undoredo_state_count=m_.Se,t._wasm_pdf_undoredo_step=m_.Te,t._wasm_pdf_begin_operation=m_.Ue,t._wasm_pdf_begin_implicit_operation=m_.Ve,t._wasm_pdf_end_operation=m_.We,t._wasm_pdf_abandon_operation=m_.Xe,t._wasm_pdf_undo=m_.Ye,t._wasm_pdf_redo=m_.Ze,t._wasm_pdf_can_undo=m_._e,t._wasm_pdf_can_redo=m_.$e,t._wasm_pdf_document_language=m_.af,t._wasm_pdf_set_document_language=m_.bf,t._wasm_pdf_trailer=m_.cf,t._wasm_pdf_xref_len=m_.df,t._wasm_pdf_lookup_page_obj=m_.ef,t._wasm_pdf_add_object=m_.ff,t._wasm_pdf_create_object=m_.gf,t._wasm_pdf_delete_object=m_.hf,t._wasm_pdf_add_stream=m_.jf,t._wasm_pdf_add_simple_font=m_.kf,t._wasm_pdf_add_cjk_font=m_.lf,t._wasm_pdf_add_cid_font=m_.mf,t._wasm_pdf_add_image=m_.nf,t._wasm_pdf_load_image=m_.of,t._wasm_pdf_add_page=m_.pf,t._wasm_pdf_insert_page=m_.qf,t._wasm_pdf_delete_page=m_.rf,t._wasm_pdf_set_page_labels=m_.sf,t._wasm_pdf_delete_page_labels=m_.tf,t._wasm_pdf_is_embedded_file=m_.uf,t._wasm_pdf_get_filespec_params=m_.vf,t._wasm_pdf_add_embedded_file=m_.wf,t._wasm_pdf_load_embedded_file_contents=m_.xf,t._wasm_pdf_write_document_buffer=m_.yf,t._wasm_pdf_js_supported=m_.zf,t._wasm_pdf_enable_js=m_.Af,t._wasm_pdf_disable_js=m_.Bf,t._wasm_pdf_rearrange_pages=m_.Cf,t._wasm_pdf_subset_fonts=m_.Df,t._wasm_pdf_bake_document=m_.Ef,t._wasm_pdf_count_layers=m_.Ff,t._wasm_pdf_layer_name=m_.Gf,t._wasm_pdf_layer_is_enabled=m_.Hf,t._wasm_pdf_enable_layer=m_.If,t._wasm_pdf_page_transform=m_.Jf,t._wasm_pdf_set_page_box=m_.Kf,t._wasm_pdf_first_annot=m_.Lf,t._wasm_pdf_next_annot=m_.Mf,t._wasm_pdf_first_widget=m_.Nf,t._wasm_pdf_next_widget=m_.Of,t._wasm_pdf_create_annot=m_.Pf,t._wasm_pdf_delete_annot=m_.Qf,t._wasm_pdf_update_page=m_.Rf,t._wasm_pdf_redact_page=m_.Sf,t._wasm_pdf_new_graft_map=m_.Tf,t._wasm_pdf_graft_mapped_object=m_.Uf,t._wasm_pdf_graft_object=m_.Vf,t._wasm_pdf_graft_mapped_page=m_.Wf,t._wasm_pdf_graft_page=m_.Xf,t._wasm_pdf_bound_annot=m_.Yf,t._wasm_pdf_run_annot=m_.Zf,t._wasm_pdf_new_pixmap_from_annot=m_._f,t._wasm_pdf_new_display_list_from_annot=m_.$f,t._wasm_pdf_update_annot=m_.ag,t._wasm_pdf_annot_obj=m_.bg,t._wasm_pdf_annot_type=m_.cg,t._wasm_pdf_annot_flags=m_.dg,t._wasm_pdf_set_annot_flags=m_.eg,t._wasm_pdf_annot_contents=m_.fg,t._wasm_pdf_set_annot_contents=m_.gg,t._wasm_pdf_annot_author=m_.hg,t._wasm_pdf_set_annot_author=m_.ig,t._wasm_pdf_annot_creation_date=m_.jg,t._wasm_pdf_set_annot_creation_date=m_.kg,t._wasm_pdf_annot_modification_date=m_.lg,t._wasm_pdf_set_annot_modification_date=m_.mg,t._wasm_pdf_annot_border_width=m_.ng,t._wasm_pdf_set_annot_border_width=m_.og,t._wasm_pdf_annot_border_style=m_.pg,t._wasm_pdf_set_annot_border_style=m_.qg,t._wasm_pdf_annot_border_effect=m_.rg,t._wasm_pdf_set_annot_border_effect=m_.sg,t._wasm_pdf_annot_border_effect_intensity=m_.tg,t._wasm_pdf_set_annot_border_effect_intensity=m_.ug,t._wasm_pdf_annot_opacity=m_.vg,t._wasm_pdf_set_annot_opacity=m_.wg,t._wasm_pdf_annot_filespec=m_.xg,t._wasm_pdf_set_annot_filespec=m_.yg,t._wasm_pdf_annot_quadding=m_.zg,t._wasm_pdf_set_annot_quadding=m_.Ag,t._wasm_pdf_annot_is_open=m_.Bg,t._wasm_pdf_set_annot_is_open=m_.Cg,t._wasm_pdf_annot_hidden_for_editing=m_.Dg,t._wasm_pdf_set_annot_hidden_for_editing=m_.Eg,t._wasm_pdf_annot_icon_name=m_.Fg,t._wasm_pdf_set_annot_icon_name=m_.Gg,t._wasm_pdf_annot_intent=m_.Hg,t._wasm_pdf_set_annot_intent=m_.Ig,t._wasm_pdf_annot_callout_style=m_.Jg,t._wasm_pdf_set_annot_callout_style=m_.Kg,t._wasm_pdf_annot_line_leader=m_.Lg,t._wasm_pdf_set_annot_line_leader=m_.Mg,t._wasm_pdf_annot_line_leader_extension=m_.Ng,t._wasm_pdf_set_annot_line_leader_extension=m_.Og,t._wasm_pdf_annot_line_leader_offset=m_.Pg,t._wasm_pdf_set_annot_line_leader_offset=m_.Qg,t._wasm_pdf_annot_line_caption=m_.Rg,t._wasm_pdf_set_annot_line_caption=m_.Sg,t._wasm_pdf_annot_rich_defaults=m_.Tg,t._wasm_pdf_set_annot_rich_defaults=m_.Ug,t._wasm_pdf_annot_callout_point=m_.Vg,t._wasm_pdf_annot_line_caption_offset=m_.Wg,t._wasm_pdf_annot_rect=m_.Xg,t._wasm_pdf_annot_popup=m_.Yg,t._wasm_pdf_annot_quad_point_count=m_.Zg,t._wasm_pdf_annot_quad_point=m_._g,t._wasm_pdf_annot_vertex_count=m_.$g,t._wasm_pdf_annot_vertex=m_.ah,t._wasm_pdf_annot_ink_list_count=m_.bh,t._wasm_pdf_annot_ink_list_stroke_count=m_.ch,t._wasm_pdf_annot_ink_list_stroke_vertex=m_.dh,t._wasm_pdf_annot_rich_contents=m_.eh,t._wasm_pdf_annot_border_dash_count=m_.fh,t._wasm_pdf_annot_border_dash_item=m_.gh,t._wasm_pdf_annot_has_rect=m_.hh,t._wasm_pdf_annot_has_ink_list=m_.ih,t._wasm_pdf_annot_has_quad_points=m_.jh,t._wasm_pdf_annot_has_vertices=m_.kh,t._wasm_pdf_annot_has_line=m_.lh,t._wasm_pdf_annot_has_interior_color=m_.mh,t._wasm_pdf_annot_has_line_ending_styles=m_.nh,t._wasm_pdf_annot_has_border=m_.oh,t._wasm_pdf_annot_has_border_effect=m_.ph,t._wasm_pdf_annot_has_icon_name=m_.qh,t._wasm_pdf_annot_has_open=m_.rh,t._wasm_pdf_annot_has_author=m_.sh,t._wasm_pdf_annot_has_filespec=m_.th,t._wasm_pdf_annot_has_callout=m_.uh,t._wasm_pdf_annot_has_rich_contents=m_.vh,t._wasm_pdf_annot_language=m_.wh,t._wasm_pdf_set_annot_language=m_.xh,t._wasm_pdf_set_annot_popup=m_.yh,t._wasm_pdf_set_annot_rect=m_.zh,t._wasm_pdf_clear_annot_quad_points=m_.Ah,t._wasm_pdf_clear_annot_vertices=m_.Bh,t._wasm_pdf_clear_annot_ink_list=m_.Ch,t._wasm_pdf_clear_annot_border_dash=m_.Dh,t._wasm_pdf_add_annot_quad_point=m_.Eh,t._wasm_pdf_add_annot_vertex=m_.Fh,t._wasm_pdf_add_annot_ink_list_stroke=m_.Gh,t._wasm_pdf_add_annot_ink_list_stroke_vertex=m_.Hh,t._wasm_pdf_add_annot_border_dash_item=m_.Ih,t._wasm_pdf_annot_line_ending_styles_start=m_.Jh,t._wasm_pdf_annot_line_1=m_.Kh,t._wasm_pdf_annot_line_2=m_.Lh,t._wasm_pdf_set_annot_line=m_.Mh,t._wasm_pdf_set_annot_callout_point=m_.Nh,t._wasm_pdf_annot_callout_line=m_.Oh,t._wasm_pdf_set_annot_callout_line=m_.Ph,t._wasm_pdf_set_annot_line_caption_offset=m_.Qh,t._wasm_pdf_annot_line_ending_styles_end=m_.Rh,t._wasm_pdf_set_annot_line_ending_styles=m_.Sh,t._wasm_pdf_annot_color=m_.Th,t._wasm_pdf_annot_interior_color=m_.Uh,t._wasm_pdf_set_annot_color=m_.Vh,t._wasm_pdf_set_annot_interior_color=m_.Wh,t._wasm_pdf_set_annot_default_appearance=m_.Xh,t._wasm_pdf_annot_default_appearance_font=m_.Yh,t._wasm_pdf_annot_default_appearance_size=m_.Zh,t._wasm_pdf_annot_default_appearance_color=m_._h,t._wasm_pdf_set_annot_rich_contents=m_.$h,t._wasm_pdf_set_annot_stamp_image=m_.ai,t._wasm_pdf_set_annot_appearance_from_display_list=m_.bi,t._wasm_pdf_set_annot_appearance=m_.ci,t._wasm_pdf_apply_redaction=m_.di,t._wasm_pdf_reset_form=m_.ei,t._wasm_pdf_annot_field_type=m_.fi,t._wasm_pdf_annot_field_flags=m_.gi,t._wasm_pdf_annot_field_label=m_.hi,t._wasm_pdf_annot_field_value=m_.ii,t._wasm_pdf_load_field_name=m_.ji,t._wasm_pdf_annot_text_widget_max_len=m_.ki,t._wasm_pdf_set_annot_text_field_value=m_.li,t._wasm_pdf_set_annot_choice_field_value=m_.mi,t._wasm_pdf_annot_choice_field_option_count=m_.ni,t._wasm_pdf_annot_choice_field_option=m_.oi,t._wasm_pdf_toggle_widget=m_.pi,t._wasm_pdf_is_indirect=m_.qi,t._wasm_pdf_is_bool=m_.ri,t._wasm_pdf_is_int=m_.si,t._wasm_pdf_is_real=m_.ti,t._wasm_pdf_is_number=m_.ui,t._wasm_pdf_is_name=m_.vi,t._wasm_pdf_is_string=m_.wi,t._wasm_pdf_is_array=m_.xi,t._wasm_pdf_is_dict=m_.yi,t._wasm_pdf_is_stream=m_.zi,t._wasm_pdf_to_num=m_.Ai,t._wasm_pdf_to_bool=m_.Bi,t._wasm_pdf_to_real=m_.Ci,t._wasm_pdf_to_name=m_.Di,t._wasm_pdf_to_text_string=m_.Ei,t._wasm_pdf_new_indirect=m_.Fi,t._wasm_pdf_new_array=m_.Gi,t._wasm_pdf_new_dict=m_.Hi,t._wasm_pdf_new_bool=m_.Ii,t._wasm_pdf_new_int=m_.Ji,t._wasm_pdf_new_real=m_.Ki,t._wasm_pdf_new_name=m_.Li,t._wasm_pdf_new_text_string=m_.Mi,t._wasm_pdf_new_string=m_.Ni,t._wasm_pdf_resolve_indirect=m_.Oi,t._wasm_pdf_array_len=m_.Pi,t._wasm_pdf_array_get=m_.Qi,t._wasm_pdf_dict_get=m_.Ri,t._wasm_pdf_dict_len=m_.Si,t._wasm_pdf_dict_get_key=m_.Ti,t._wasm_pdf_dict_get_val=m_.Ui,t._wasm_pdf_dict_get_inheritable=m_.Vi,t._wasm_pdf_dict_gets=m_.Wi,t._wasm_pdf_dict_gets_inheritable=m_.Xi,t._wasm_pdf_dict_put=m_.Yi,t._wasm_pdf_dict_puts=m_.Zi,t._wasm_pdf_dict_del=m_._i,t._wasm_pdf_dict_dels=m_.$i,t._wasm_pdf_array_put=m_.aj,t._wasm_pdf_array_push=m_.bj,t._wasm_pdf_array_delete=m_.cj,t._wasm_pdf_sprint_obj=m_.dj,t._wasm_pdf_load_stream=m_.ej,t._wasm_pdf_load_raw_stream=m_.fj,t._wasm_pdf_update_object=m_.gj,t._wasm_pdf_update_stream=m_.hj,t._wasm_pdf_to_string=m_.ij,t._wasm_new_stream=m_.jj,t._wasm_walk_path=m_.kj,t._wasm_walk_text=m_.lj,t._wasm_new_js_device=m_.mj,m_.nj);return function(){if(t.preInit)for("function"==typeof t.preInit&&(t.preInit=[t.preInit]);t.preInit.length>0;)t.preInit.shift()();}(),function _(){function e(){t.calledRun=true,$||(A=true,m_.w(),a(t),t.onRuntimeInitialized?.(),function(){if(t.postRun)for("function"==typeof t.postRun&&(t.postRun=[t.postRun]);t.postRun.length;)q(t.postRun.shift());I(B);}());}C>0?S=_:(function(){if(t.preRun)for("function"==typeof t.preRun&&(t.preRun=[t.preRun]);t.preRun.length;)W(t.preRun.shift());I(L);}(),C>0?S=_:t.setStatus?(t.setStatus("Running..."),setTimeout((()=>{setTimeout((()=>t.setStatus("")),1),e();}),1)):e());}(),s};
|
|
2
|
-
|
|
3
|
-
// Copyright (C) 2004-2025 Artifex Software, Inc.
|
|
4
|
-
//
|
|
5
|
-
// This file is part of MuPDF WASM Library.
|
|
6
|
-
//
|
|
7
|
-
// MuPDF is free software: you can redistribute it and/or modify it under the
|
|
8
|
-
// terms of the GNU Affero General Public License as published by the Free
|
|
9
|
-
// Software Foundation, either version 3 of the License, or (at your option)
|
|
10
|
-
// any later version.
|
|
11
|
-
//
|
|
12
|
-
// MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
13
|
-
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
14
|
-
// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
15
|
-
// details.
|
|
16
|
-
//
|
|
17
|
-
// You should have received a copy of the GNU Affero General Public License
|
|
18
|
-
// along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
|
|
19
|
-
//
|
|
20
|
-
// Alternative licensing terms are available from the licensor.
|
|
21
|
-
// For commercial licensing, see <https://www.artifex.com/> or contact
|
|
22
|
-
// Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
|
|
23
|
-
// CA 94129, USA, for further information.
|
|
24
|
-
var node_fs = null;
|
|
25
|
-
if (typeof process !== "undefined" && process.versions && process.versions.node)
|
|
26
|
-
node_fs = await import('node:fs');
|
|
27
|
-
const libmupdf = await _$1(globalThis["$libmupdf_wasm_Module"]);
|
|
28
|
-
libmupdf._wasm_init_context();
|
|
29
|
-
function Malloc(size) {
|
|
30
|
-
return libmupdf._wasm_malloc(size);
|
|
31
|
-
}
|
|
32
|
-
function Free(ptr) {
|
|
33
|
-
libmupdf._wasm_free(ptr);
|
|
34
|
-
}
|
|
35
|
-
/* -------------------------------------------------------------------------- */
|
|
36
|
-
// To pass Rect and Matrix as pointer arguments
|
|
37
|
-
const _wasm_int = Malloc(4);
|
|
38
|
-
const _wasm_point = Malloc(4 * 6) >> 2;
|
|
39
|
-
const _wasm_rect = Malloc(4 * 8) >> 2;
|
|
40
|
-
const _wasm_matrix = Malloc(4 * 6) >> 2;
|
|
41
|
-
const _wasm_color = Malloc(4 * 4) >> 2;
|
|
42
|
-
const _wasm_quad = Malloc(4 * 8) >> 2;
|
|
43
|
-
const _wasm_string = [0, 0];
|
|
44
|
-
function checkType(value, type) {
|
|
45
|
-
if (typeof type === "string" && typeof value !== type)
|
|
46
|
-
throw new TypeError("expected " + type);
|
|
47
|
-
if (typeof type === "function" && !(value instanceof type))
|
|
48
|
-
throw new TypeError("expected " + type.name);
|
|
49
|
-
}
|
|
50
|
-
function checkPoint(value) {
|
|
51
|
-
if (!Array.isArray(value) || value.length !== 2)
|
|
52
|
-
throw new TypeError("expected point");
|
|
53
|
-
}
|
|
54
|
-
function checkRect(value) {
|
|
55
|
-
if (!Array.isArray(value) || value.length !== 4)
|
|
56
|
-
throw new TypeError("expected rectangle");
|
|
57
|
-
}
|
|
58
|
-
function checkMatrix(value) {
|
|
59
|
-
if (!Array.isArray(value) || value.length !== 6)
|
|
60
|
-
throw new TypeError("expected matrix");
|
|
61
|
-
}
|
|
62
|
-
function checkQuad(value) {
|
|
63
|
-
if (!Array.isArray(value) || value.length !== 8)
|
|
64
|
-
throw new TypeError("expected quad");
|
|
65
|
-
}
|
|
66
|
-
function checkColor(value) {
|
|
67
|
-
if (!Array.isArray(value) || (value.length !== 1 && value.length !== 3 && value.length !== 4))
|
|
68
|
-
throw new TypeError("expected color array");
|
|
69
|
-
}
|
|
70
|
-
function checkAnnotColor(value) {
|
|
71
|
-
if (!Array.isArray(value) || (value.length !== 0 && value.length !== 1 && value.length !== 3 && value.length !== 4))
|
|
72
|
-
throw new TypeError("expected color array");
|
|
73
|
-
}
|
|
74
|
-
function BUFFER(input) {
|
|
75
|
-
if (input instanceof Buffer$1)
|
|
76
|
-
return input.pointer;
|
|
77
|
-
if (input instanceof ArrayBuffer || input instanceof Uint8Array)
|
|
78
|
-
return new Buffer$1(input).pointer;
|
|
79
|
-
if (typeof input === "string")
|
|
80
|
-
return new Buffer$1(input).pointer;
|
|
81
|
-
throw new TypeError("expected buffer");
|
|
82
|
-
}
|
|
83
|
-
function ENUM(value, list) {
|
|
84
|
-
if (typeof value === "number") {
|
|
85
|
-
if (value >= 0 && value < list.length)
|
|
86
|
-
return value;
|
|
87
|
-
}
|
|
88
|
-
if (typeof value === "string") {
|
|
89
|
-
let idx = list.indexOf(value);
|
|
90
|
-
if (idx >= 0)
|
|
91
|
-
return idx;
|
|
92
|
-
}
|
|
93
|
-
throw new TypeError(`invalid enum value ("${value}"; expected ${list.join(", ")})`);
|
|
94
|
-
}
|
|
95
|
-
function allocateUTF8(str) {
|
|
96
|
-
var size = libmupdf.lengthBytesUTF8(str) + 1;
|
|
97
|
-
var pointer = Malloc(size);
|
|
98
|
-
libmupdf.stringToUTF8(str, pointer, size);
|
|
99
|
-
return pointer;
|
|
100
|
-
}
|
|
101
|
-
function STRING_N(s, i) {
|
|
102
|
-
if (_wasm_string[i]) {
|
|
103
|
-
Free(_wasm_string[i]);
|
|
104
|
-
_wasm_string[i] = 0;
|
|
105
|
-
}
|
|
106
|
-
return _wasm_string[i] = allocateUTF8(s);
|
|
107
|
-
}
|
|
108
|
-
function STRING(s) {
|
|
109
|
-
return STRING_N(s, 0);
|
|
110
|
-
}
|
|
111
|
-
function STRING2(s) {
|
|
112
|
-
return STRING_N(s, 1);
|
|
113
|
-
}
|
|
114
|
-
function STRING_OPT(s) {
|
|
115
|
-
return typeof s === "string" ? STRING_N(s, 0) : 0;
|
|
116
|
-
}
|
|
117
|
-
function STRING2_OPT(s) {
|
|
118
|
-
return typeof s === "string" ? STRING_N(s, 1) : 0;
|
|
119
|
-
}
|
|
120
|
-
function POINT(p) {
|
|
121
|
-
libmupdf.HEAPF32[_wasm_point + 0] = p[0];
|
|
122
|
-
libmupdf.HEAPF32[_wasm_point + 1] = p[1];
|
|
123
|
-
return _wasm_point << 2;
|
|
124
|
-
}
|
|
125
|
-
function POINT2(p) {
|
|
126
|
-
libmupdf.HEAPF32[_wasm_point + 2] = p[0];
|
|
127
|
-
libmupdf.HEAPF32[_wasm_point + 3] = p[1];
|
|
128
|
-
return (_wasm_point + 2) << 2;
|
|
129
|
-
}
|
|
130
|
-
function POINT3(p) {
|
|
131
|
-
libmupdf.HEAPF32[_wasm_point + 4] = p[0];
|
|
132
|
-
libmupdf.HEAPF32[_wasm_point + 5] = p[1];
|
|
133
|
-
return (_wasm_point + 4) << 2;
|
|
134
|
-
}
|
|
135
|
-
function RECT(r) {
|
|
136
|
-
libmupdf.HEAPF32[_wasm_rect + 0] = r[0];
|
|
137
|
-
libmupdf.HEAPF32[_wasm_rect + 1] = r[1];
|
|
138
|
-
libmupdf.HEAPF32[_wasm_rect + 2] = r[2];
|
|
139
|
-
libmupdf.HEAPF32[_wasm_rect + 3] = r[3];
|
|
140
|
-
return _wasm_rect << 2;
|
|
141
|
-
}
|
|
142
|
-
function RECT2(r) {
|
|
143
|
-
libmupdf.HEAPF32[_wasm_rect + 4] = r[0];
|
|
144
|
-
libmupdf.HEAPF32[_wasm_rect + 5] = r[1];
|
|
145
|
-
libmupdf.HEAPF32[_wasm_rect + 6] = r[2];
|
|
146
|
-
libmupdf.HEAPF32[_wasm_rect + 7] = r[3];
|
|
147
|
-
return (_wasm_rect + 4) << 2;
|
|
148
|
-
}
|
|
149
|
-
function MATRIX(m) {
|
|
150
|
-
libmupdf.HEAPF32[_wasm_matrix + 0] = m[0];
|
|
151
|
-
libmupdf.HEAPF32[_wasm_matrix + 1] = m[1];
|
|
152
|
-
libmupdf.HEAPF32[_wasm_matrix + 2] = m[2];
|
|
153
|
-
libmupdf.HEAPF32[_wasm_matrix + 3] = m[3];
|
|
154
|
-
libmupdf.HEAPF32[_wasm_matrix + 4] = m[4];
|
|
155
|
-
libmupdf.HEAPF32[_wasm_matrix + 5] = m[5];
|
|
156
|
-
return _wasm_matrix << 2;
|
|
157
|
-
}
|
|
158
|
-
function QUAD(q) {
|
|
159
|
-
libmupdf.HEAPF32[_wasm_quad + 0] = q[0];
|
|
160
|
-
libmupdf.HEAPF32[_wasm_quad + 1] = q[1];
|
|
161
|
-
libmupdf.HEAPF32[_wasm_quad + 2] = q[2];
|
|
162
|
-
libmupdf.HEAPF32[_wasm_quad + 3] = q[3];
|
|
163
|
-
libmupdf.HEAPF32[_wasm_quad + 4] = q[4];
|
|
164
|
-
libmupdf.HEAPF32[_wasm_quad + 5] = q[5];
|
|
165
|
-
libmupdf.HEAPF32[_wasm_quad + 6] = q[6];
|
|
166
|
-
libmupdf.HEAPF32[_wasm_quad + 7] = q[7];
|
|
167
|
-
return _wasm_quad << 2;
|
|
168
|
-
}
|
|
169
|
-
function COLOR(c) {
|
|
170
|
-
if (typeof c !== "undefined") {
|
|
171
|
-
switch (c.length) {
|
|
172
|
-
case 0:
|
|
173
|
-
break;
|
|
174
|
-
case 1:
|
|
175
|
-
libmupdf.HEAPF32[_wasm_color + 0] = c[0];
|
|
176
|
-
break;
|
|
177
|
-
case 3:
|
|
178
|
-
libmupdf.HEAPF32[_wasm_color + 0] = c[0];
|
|
179
|
-
libmupdf.HEAPF32[_wasm_color + 1] = c[1];
|
|
180
|
-
libmupdf.HEAPF32[_wasm_color + 2] = c[2];
|
|
181
|
-
break;
|
|
182
|
-
case 4:
|
|
183
|
-
libmupdf.HEAPF32[_wasm_color + 0] = c[0];
|
|
184
|
-
libmupdf.HEAPF32[_wasm_color + 1] = c[1];
|
|
185
|
-
libmupdf.HEAPF32[_wasm_color + 2] = c[2];
|
|
186
|
-
libmupdf.HEAPF32[_wasm_color + 3] = c[3];
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return _wasm_color << 2;
|
|
191
|
-
}
|
|
192
|
-
/* -------------------------------------------------------------------------- */
|
|
193
|
-
function fromColor(n) {
|
|
194
|
-
if (n === 1)
|
|
195
|
-
return [
|
|
196
|
-
libmupdf.HEAPF32[_wasm_color]
|
|
197
|
-
];
|
|
198
|
-
if (n === 3)
|
|
199
|
-
return [
|
|
200
|
-
libmupdf.HEAPF32[_wasm_color + 0],
|
|
201
|
-
libmupdf.HEAPF32[_wasm_color + 1],
|
|
202
|
-
libmupdf.HEAPF32[_wasm_color + 2],
|
|
203
|
-
];
|
|
204
|
-
if (n === 4)
|
|
205
|
-
return [
|
|
206
|
-
libmupdf.HEAPF32[_wasm_color + 0],
|
|
207
|
-
libmupdf.HEAPF32[_wasm_color + 1],
|
|
208
|
-
libmupdf.HEAPF32[_wasm_color + 2],
|
|
209
|
-
libmupdf.HEAPF32[_wasm_color + 3],
|
|
210
|
-
];
|
|
211
|
-
throw new TypeError("invalid number of components for Color: " + n);
|
|
212
|
-
}
|
|
213
|
-
function fromAnnotColor(n) {
|
|
214
|
-
if (n === 0)
|
|
215
|
-
return [];
|
|
216
|
-
return fromColor(n);
|
|
217
|
-
}
|
|
218
|
-
function fromColorArray(n, ptr) {
|
|
219
|
-
let addr = ptr >> 2;
|
|
220
|
-
let color = [];
|
|
221
|
-
for (let i = 0; i < n; ++i)
|
|
222
|
-
color.push(libmupdf.HEAPF32[addr + i]);
|
|
223
|
-
return color;
|
|
224
|
-
}
|
|
225
|
-
function fromStringOrNull(ptr) {
|
|
226
|
-
if (ptr === 0)
|
|
227
|
-
return null;
|
|
228
|
-
return libmupdf.UTF8ToString(ptr);
|
|
229
|
-
}
|
|
230
|
-
function fromString$1(ptr) {
|
|
231
|
-
return libmupdf.UTF8ToString(ptr);
|
|
232
|
-
}
|
|
233
|
-
function fromStringFree(ptr) {
|
|
234
|
-
let str = libmupdf.UTF8ToString(ptr);
|
|
235
|
-
Free(ptr);
|
|
236
|
-
return str;
|
|
237
|
-
}
|
|
238
|
-
function fromPoint(ptr) {
|
|
239
|
-
let addr = ptr >> 2;
|
|
240
|
-
return [
|
|
241
|
-
libmupdf.HEAPF32[addr + 0],
|
|
242
|
-
libmupdf.HEAPF32[addr + 1],
|
|
243
|
-
];
|
|
244
|
-
}
|
|
245
|
-
function fromRect(ptr) {
|
|
246
|
-
let addr = ptr >> 2;
|
|
247
|
-
return [
|
|
248
|
-
libmupdf.HEAPF32[addr + 0],
|
|
249
|
-
libmupdf.HEAPF32[addr + 1],
|
|
250
|
-
libmupdf.HEAPF32[addr + 2],
|
|
251
|
-
libmupdf.HEAPF32[addr + 3],
|
|
252
|
-
];
|
|
253
|
-
}
|
|
254
|
-
function fromMatrix(ptr) {
|
|
255
|
-
let addr = ptr >> 2;
|
|
256
|
-
return [
|
|
257
|
-
libmupdf.HEAPF32[addr + 0],
|
|
258
|
-
libmupdf.HEAPF32[addr + 1],
|
|
259
|
-
libmupdf.HEAPF32[addr + 2],
|
|
260
|
-
libmupdf.HEAPF32[addr + 3],
|
|
261
|
-
libmupdf.HEAPF32[addr + 4],
|
|
262
|
-
libmupdf.HEAPF32[addr + 5],
|
|
263
|
-
];
|
|
264
|
-
}
|
|
265
|
-
function fromQuad(ptr) {
|
|
266
|
-
let addr = ptr >> 2;
|
|
267
|
-
return [
|
|
268
|
-
libmupdf.HEAPF32[addr + 0],
|
|
269
|
-
libmupdf.HEAPF32[addr + 1],
|
|
270
|
-
libmupdf.HEAPF32[addr + 2],
|
|
271
|
-
libmupdf.HEAPF32[addr + 3],
|
|
272
|
-
libmupdf.HEAPF32[addr + 4],
|
|
273
|
-
libmupdf.HEAPF32[addr + 5],
|
|
274
|
-
libmupdf.HEAPF32[addr + 6],
|
|
275
|
-
libmupdf.HEAPF32[addr + 7],
|
|
276
|
-
];
|
|
277
|
-
}
|
|
278
|
-
function fromBuffer$1(ptr) {
|
|
279
|
-
let data = libmupdf._wasm_buffer_get_data(ptr);
|
|
280
|
-
let size = libmupdf._wasm_buffer_get_len(ptr);
|
|
281
|
-
return libmupdf.HEAPU8.slice(data, data + size);
|
|
282
|
-
}
|
|
283
|
-
/* unused for now
|
|
284
|
-
function rgbFromColor(c?: Color): [number, number, number] {
|
|
285
|
-
var r = 0, g = 0, b = 0
|
|
286
|
-
if (typeof c !== "undefined") {
|
|
287
|
-
switch (c.length) {
|
|
288
|
-
case 1:
|
|
289
|
-
r = g = b = c[0]
|
|
290
|
-
break
|
|
291
|
-
case 3:
|
|
292
|
-
r = c[0]
|
|
293
|
-
g = c[1]
|
|
294
|
-
b = c[2]
|
|
295
|
-
break
|
|
296
|
-
case 4:
|
|
297
|
-
r = 1 - Math.min(1, c[0] + c[3])
|
|
298
|
-
g = 1 - Math.min(1, c[1] + c[3])
|
|
299
|
-
b = 1 - Math.min(1, c[2] + c[3])
|
|
300
|
-
break
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
return [ r, g, b ]
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
function numberFromColor(c?: Color): number {
|
|
307
|
-
var [ r, g, b ] = rgbFromColor(c)
|
|
308
|
-
return (255 << 24) | (r << 16) | (g << 8) | b
|
|
309
|
-
}
|
|
310
|
-
*/
|
|
311
|
-
function colorFromNumber(argb) {
|
|
312
|
-
var r = (argb >> 16) & 255;
|
|
313
|
-
var g = (argb >> 8) & 255;
|
|
314
|
-
var b = (argb) & 255;
|
|
315
|
-
return [r / 255, g / 255, b / 255];
|
|
316
|
-
}
|
|
317
|
-
function runSearch(searchFun, searchThis, needle, max_hits = 500) {
|
|
318
|
-
checkType(needle, "string");
|
|
319
|
-
let hits = 0;
|
|
320
|
-
let marks = 0;
|
|
321
|
-
try {
|
|
322
|
-
hits = Malloc(32 * max_hits);
|
|
323
|
-
marks = Malloc(4 * max_hits);
|
|
324
|
-
let n = searchFun(searchThis, STRING(needle), marks, hits, max_hits);
|
|
325
|
-
let outer = [];
|
|
326
|
-
if (n > 0) {
|
|
327
|
-
let inner = [];
|
|
328
|
-
for (let i = 0; i < n; ++i) {
|
|
329
|
-
let mark = libmupdf.HEAP32[(marks >> 2) + i];
|
|
330
|
-
let quad = fromQuad(hits + i * 32);
|
|
331
|
-
if (i > 0 && mark) {
|
|
332
|
-
outer.push(inner);
|
|
333
|
-
inner = [];
|
|
334
|
-
}
|
|
335
|
-
inner.push(quad);
|
|
336
|
-
}
|
|
337
|
-
outer.push(inner);
|
|
338
|
-
}
|
|
339
|
-
return outer;
|
|
340
|
-
}
|
|
341
|
-
finally {
|
|
342
|
-
Free(marks);
|
|
343
|
-
Free(hits);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
/* -------------------------------------------------------------------------- */
|
|
347
|
-
class Userdata {
|
|
348
|
-
constructor(pointer) {
|
|
349
|
-
if (typeof pointer !== "number")
|
|
350
|
-
throw new Error("invalid pointer: " + typeof pointer);
|
|
351
|
-
if (pointer !== 0) {
|
|
352
|
-
let ctor = this.constructor;
|
|
353
|
-
if (!ctor._finalizer)
|
|
354
|
-
ctor._finalizer = new FinalizationRegistry(ctor._drop);
|
|
355
|
-
ctor._finalizer.register(this, pointer, this);
|
|
356
|
-
}
|
|
357
|
-
this.pointer = pointer;
|
|
358
|
-
}
|
|
359
|
-
destroy() {
|
|
360
|
-
if (this.pointer !== 0) {
|
|
361
|
-
let ctor = this.constructor;
|
|
362
|
-
ctor._finalizer.unregister(this);
|
|
363
|
-
ctor._drop(this.pointer);
|
|
364
|
-
}
|
|
365
|
-
this.pointer = 0;
|
|
366
|
-
}
|
|
367
|
-
// Custom "console.log" formatting for Node
|
|
368
|
-
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
369
|
-
return this.toString();
|
|
370
|
-
}
|
|
371
|
-
toString() {
|
|
372
|
-
return `[${this.constructor.name} ${this.pointer}]`;
|
|
373
|
-
}
|
|
374
|
-
valueOf() {
|
|
375
|
-
throw new Error("cannot convert Userdata to Javascript value");
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
let Buffer$1 = class Buffer extends Userdata {
|
|
379
|
-
constructor(arg) {
|
|
380
|
-
if (typeof arg === "undefined")
|
|
381
|
-
super(libmupdf._wasm_new_buffer(1024));
|
|
382
|
-
else if (typeof arg === "number")
|
|
383
|
-
super(arg);
|
|
384
|
-
else if (typeof arg === "string") {
|
|
385
|
-
let data_len = libmupdf.lengthBytesUTF8(arg);
|
|
386
|
-
let data_ptr = Malloc(data_len + 1);
|
|
387
|
-
libmupdf.stringToUTF8(arg, data_ptr, data_len + 1);
|
|
388
|
-
super(libmupdf._wasm_new_buffer_from_data(data_ptr, data_len));
|
|
389
|
-
}
|
|
390
|
-
else if (arg instanceof ArrayBuffer || arg instanceof Uint8Array) {
|
|
391
|
-
let data_len = arg.byteLength;
|
|
392
|
-
let data_ptr = Malloc(data_len);
|
|
393
|
-
libmupdf.HEAPU8.set(new Uint8Array(arg), data_ptr);
|
|
394
|
-
super(libmupdf._wasm_new_buffer_from_data(data_ptr, data_len));
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
get length() {
|
|
398
|
-
return this.getLength();
|
|
399
|
-
}
|
|
400
|
-
set length(_) {
|
|
401
|
-
throw new TypeError("buffer length is read-only");
|
|
402
|
-
}
|
|
403
|
-
getLength() {
|
|
404
|
-
return libmupdf._wasm_buffer_get_len(this.pointer);
|
|
405
|
-
}
|
|
406
|
-
readByte(at) {
|
|
407
|
-
let data = libmupdf._wasm_buffer_get_data(this.pointer);
|
|
408
|
-
return libmupdf.HEAPU8[data + at];
|
|
409
|
-
}
|
|
410
|
-
write(s) {
|
|
411
|
-
libmupdf._wasm_append_string(this.pointer, STRING(s));
|
|
412
|
-
}
|
|
413
|
-
writeByte(b) {
|
|
414
|
-
libmupdf._wasm_append_byte(this.pointer, b);
|
|
415
|
-
}
|
|
416
|
-
writeLine(s) {
|
|
417
|
-
this.write(s);
|
|
418
|
-
this.writeByte(10);
|
|
419
|
-
}
|
|
420
|
-
writeBuffer(other) {
|
|
421
|
-
libmupdf._wasm_append_buffer(this.pointer, BUFFER(other));
|
|
422
|
-
}
|
|
423
|
-
asUint8Array() {
|
|
424
|
-
let data = libmupdf._wasm_buffer_get_data(this.pointer);
|
|
425
|
-
let size = libmupdf._wasm_buffer_get_len(this.pointer);
|
|
426
|
-
return libmupdf.HEAPU8.subarray(data, data + size);
|
|
427
|
-
}
|
|
428
|
-
slice(start, end) {
|
|
429
|
-
if (typeof end === "undefined")
|
|
430
|
-
end = this.getLength();
|
|
431
|
-
return new Buffer(libmupdf._wasm_slice_buffer(this.pointer, start, end));
|
|
432
|
-
}
|
|
433
|
-
asString() {
|
|
434
|
-
return fromString$1(libmupdf._wasm_string_from_buffer(this.pointer));
|
|
435
|
-
}
|
|
436
|
-
save(filename) {
|
|
437
|
-
if (node_fs)
|
|
438
|
-
node_fs.writeFileSync(filename, this.asUint8Array());
|
|
439
|
-
else
|
|
440
|
-
throw new Error("missing 'fs' module");
|
|
441
|
-
}
|
|
442
|
-
};
|
|
443
|
-
Buffer$1._drop = libmupdf._wasm_drop_buffer;
|
|
444
|
-
class ColorSpace extends Userdata {
|
|
445
|
-
constructor(from, name) {
|
|
446
|
-
if (typeof from === "number") {
|
|
447
|
-
super(from);
|
|
448
|
-
}
|
|
449
|
-
else {
|
|
450
|
-
if (typeof from === "string") {
|
|
451
|
-
if (node_fs)
|
|
452
|
-
from = node_fs.readFileSync(from);
|
|
453
|
-
else
|
|
454
|
-
throw new Error("missing 'fs' module");
|
|
455
|
-
}
|
|
456
|
-
super(libmupdf._wasm_new_icc_colorspace(STRING_OPT(name), BUFFER(from)));
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
getName() {
|
|
460
|
-
return fromString$1(libmupdf._wasm_colorspace_get_name(this.pointer));
|
|
461
|
-
}
|
|
462
|
-
getType() {
|
|
463
|
-
return ColorSpace.COLORSPACE_TYPES[libmupdf._wasm_colorspace_get_type(this.pointer)] || "None";
|
|
464
|
-
}
|
|
465
|
-
getNumberOfComponents() {
|
|
466
|
-
return libmupdf._wasm_colorspace_get_n(this.pointer);
|
|
467
|
-
}
|
|
468
|
-
isGray() { return this.getType() === "Gray"; }
|
|
469
|
-
isRGB() { return this.getType() === "RGB"; }
|
|
470
|
-
isCMYK() { return this.getType() === "CMYK"; }
|
|
471
|
-
isIndexed() { return this.getType() === "Indexed"; }
|
|
472
|
-
isLab() { return this.getType() === "Lab"; }
|
|
473
|
-
isDeviceN() { return this.getType() === "Separation"; }
|
|
474
|
-
isSubtractive() { return this.getType() === "CMYK" || this.getType() === "Separation"; }
|
|
475
|
-
toString() {
|
|
476
|
-
return "[ColorSpace " + this.getName() + "]";
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
ColorSpace._drop = libmupdf._wasm_drop_colorspace;
|
|
480
|
-
ColorSpace.COLORSPACE_TYPES = [
|
|
481
|
-
"None",
|
|
482
|
-
"Gray",
|
|
483
|
-
"RGB",
|
|
484
|
-
"BGR",
|
|
485
|
-
"CMYK",
|
|
486
|
-
"Lab",
|
|
487
|
-
"Indexed",
|
|
488
|
-
"Separation"
|
|
489
|
-
];
|
|
490
|
-
ColorSpace.DeviceGray = new ColorSpace(libmupdf._wasm_device_gray());
|
|
491
|
-
ColorSpace.DeviceRGB = new ColorSpace(libmupdf._wasm_device_rgb());
|
|
492
|
-
ColorSpace.DeviceBGR = new ColorSpace(libmupdf._wasm_device_bgr());
|
|
493
|
-
ColorSpace.DeviceCMYK = new ColorSpace(libmupdf._wasm_device_cmyk());
|
|
494
|
-
ColorSpace.Lab = new ColorSpace(libmupdf._wasm_device_lab());
|
|
495
|
-
class Font extends Userdata {
|
|
496
|
-
constructor(name_or_pointer, data, subfont = 0) {
|
|
497
|
-
let pointer = 0;
|
|
498
|
-
if (typeof name_or_pointer === "number") {
|
|
499
|
-
pointer = libmupdf._wasm_keep_font(name_or_pointer);
|
|
500
|
-
}
|
|
501
|
-
else {
|
|
502
|
-
if (typeof data === "string") {
|
|
503
|
-
if (node_fs)
|
|
504
|
-
data = node_fs.readFileSync(data);
|
|
505
|
-
else
|
|
506
|
-
throw new Error("missing 'fs' module");
|
|
507
|
-
}
|
|
508
|
-
if (data)
|
|
509
|
-
pointer = libmupdf._wasm_new_font_from_buffer(STRING(name_or_pointer), BUFFER(data), subfont);
|
|
510
|
-
else if (name_or_pointer === "zh-Hant")
|
|
511
|
-
pointer = libmupdf._wasm_new_cjk_font(Font.ADOBE_CNS);
|
|
512
|
-
else if (name_or_pointer === "zh-Hans")
|
|
513
|
-
pointer = libmupdf._wasm_new_cjk_font(Font.ADOBE_GB);
|
|
514
|
-
else if (name_or_pointer === "ja")
|
|
515
|
-
pointer = libmupdf._wasm_new_cjk_font(Font.ADOBE_JAPAN);
|
|
516
|
-
else if (name_or_pointer === "ko")
|
|
517
|
-
pointer = libmupdf._wasm_new_cjk_font(Font.ADOBE_KOREA);
|
|
518
|
-
else
|
|
519
|
-
pointer = libmupdf._wasm_new_base14_font(STRING(name_or_pointer));
|
|
520
|
-
}
|
|
521
|
-
super(pointer);
|
|
522
|
-
}
|
|
523
|
-
getName() {
|
|
524
|
-
return fromString$1(libmupdf._wasm_font_get_name(this.pointer));
|
|
525
|
-
}
|
|
526
|
-
encodeCharacter(uni) {
|
|
527
|
-
if (typeof uni === "string")
|
|
528
|
-
uni = uni.charCodeAt(0);
|
|
529
|
-
return libmupdf._wasm_encode_character(this.pointer, uni);
|
|
530
|
-
}
|
|
531
|
-
advanceGlyph(gid, wmode = 0) {
|
|
532
|
-
return libmupdf._wasm_advance_glyph(this.pointer, gid, wmode);
|
|
533
|
-
}
|
|
534
|
-
isMono() {
|
|
535
|
-
return !!libmupdf._wasm_font_is_monospaced(this.pointer);
|
|
536
|
-
}
|
|
537
|
-
isSerif() {
|
|
538
|
-
return !!libmupdf._wasm_font_is_serif(this.pointer);
|
|
539
|
-
}
|
|
540
|
-
isBold() {
|
|
541
|
-
return !!libmupdf._wasm_font_is_bold(this.pointer);
|
|
542
|
-
}
|
|
543
|
-
isItalic() {
|
|
544
|
-
return !!libmupdf._wasm_font_is_italic(this.pointer);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
Font._drop = libmupdf._wasm_drop_font;
|
|
548
|
-
Font.SIMPLE_ENCODING = [
|
|
549
|
-
"Latin",
|
|
550
|
-
"Greek",
|
|
551
|
-
"Cyrillic"
|
|
552
|
-
];
|
|
553
|
-
Font.ADOBE_CNS = 0;
|
|
554
|
-
Font.ADOBE_GB = 1;
|
|
555
|
-
Font.ADOBE_JAPAN = 2;
|
|
556
|
-
Font.ADOBE_KOREA = 3;
|
|
557
|
-
Font.CJK_ORDERING_BY_LANG = {
|
|
558
|
-
"Adobe-CNS1": 0,
|
|
559
|
-
"Adobe-GB1": 1,
|
|
560
|
-
"Adobe-Japan1": 2,
|
|
561
|
-
"Adobe-Korea1": 3,
|
|
562
|
-
"zh-Hant": 0,
|
|
563
|
-
"zh-TW": 0,
|
|
564
|
-
"zh-HK": 0,
|
|
565
|
-
"zh-Hans": 1,
|
|
566
|
-
"zh-CN": 1,
|
|
567
|
-
"ja": 2,
|
|
568
|
-
"ko": 3,
|
|
569
|
-
};
|
|
570
|
-
class Image extends Userdata {
|
|
571
|
-
constructor(data, mask) {
|
|
572
|
-
let pointer = 0;
|
|
573
|
-
if (typeof data === "number") {
|
|
574
|
-
pointer = libmupdf._wasm_keep_image(data);
|
|
575
|
-
}
|
|
576
|
-
else if (data instanceof Pixmap) {
|
|
577
|
-
pointer = libmupdf._wasm_new_image_from_pixmap(data.pointer, mask ? mask.pointer : 0);
|
|
578
|
-
}
|
|
579
|
-
else {
|
|
580
|
-
if (typeof data === "string") {
|
|
581
|
-
if (node_fs)
|
|
582
|
-
data = node_fs.readFileSync(data);
|
|
583
|
-
else
|
|
584
|
-
throw new Error("missing 'fs' module");
|
|
585
|
-
}
|
|
586
|
-
pointer = libmupdf._wasm_new_image_from_buffer(BUFFER(data));
|
|
587
|
-
}
|
|
588
|
-
super(pointer);
|
|
589
|
-
}
|
|
590
|
-
getWidth() {
|
|
591
|
-
return libmupdf._wasm_image_get_w(this.pointer);
|
|
592
|
-
}
|
|
593
|
-
getHeight() {
|
|
594
|
-
return libmupdf._wasm_image_get_h(this.pointer);
|
|
595
|
-
}
|
|
596
|
-
getNumberOfComponents() {
|
|
597
|
-
return libmupdf._wasm_image_get_n(this.pointer);
|
|
598
|
-
}
|
|
599
|
-
getBitsPerComponent() {
|
|
600
|
-
return libmupdf._wasm_image_get_bpc(this.pointer);
|
|
601
|
-
}
|
|
602
|
-
getXResolution() {
|
|
603
|
-
return libmupdf._wasm_image_get_xres(this.pointer);
|
|
604
|
-
}
|
|
605
|
-
getYResolution() {
|
|
606
|
-
return libmupdf._wasm_image_get_yres(this.pointer);
|
|
607
|
-
}
|
|
608
|
-
getImageMask() {
|
|
609
|
-
return !!libmupdf._wasm_image_get_imagemask(this.pointer);
|
|
610
|
-
}
|
|
611
|
-
getColorSpace() {
|
|
612
|
-
let cs = libmupdf._wasm_image_get_colorspace(this.pointer);
|
|
613
|
-
if (cs)
|
|
614
|
-
return new ColorSpace(libmupdf._wasm_keep_colorspace(cs));
|
|
615
|
-
return null;
|
|
616
|
-
}
|
|
617
|
-
getMask() {
|
|
618
|
-
let mask = libmupdf._wasm_image_get_mask(this.pointer);
|
|
619
|
-
if (mask)
|
|
620
|
-
return new Image(libmupdf._wasm_keep_image(mask));
|
|
621
|
-
return null;
|
|
622
|
-
}
|
|
623
|
-
toPixmap() {
|
|
624
|
-
return new Pixmap(libmupdf._wasm_get_pixmap_from_image(this.pointer));
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
Image._drop = libmupdf._wasm_drop_image;
|
|
628
|
-
class StrokeState extends Userdata {
|
|
629
|
-
constructor(data) {
|
|
630
|
-
if (typeof data === "number") {
|
|
631
|
-
super(data);
|
|
632
|
-
return this;
|
|
633
|
-
}
|
|
634
|
-
super(libmupdf._wasm_new_stroke_state(data?.dashes?.length ?? 0));
|
|
635
|
-
let lineCap = ENUM(data.lineCap, StrokeState.LINE_CAP);
|
|
636
|
-
let lineJoin = ENUM(data.lineJoin, StrokeState.LINE_JOIN);
|
|
637
|
-
libmupdf._wasm_stroke_state_set_start_cap(this.pointer, lineCap);
|
|
638
|
-
libmupdf._wasm_stroke_state_set_dash_cap(this.pointer, lineCap);
|
|
639
|
-
libmupdf._wasm_stroke_state_set_end_cap(this.pointer, lineCap);
|
|
640
|
-
libmupdf._wasm_stroke_state_set_linejoin(this.pointer, lineJoin);
|
|
641
|
-
libmupdf._wasm_stroke_state_set_linewidth(this.pointer, data.lineWidth);
|
|
642
|
-
libmupdf._wasm_stroke_state_set_miterlimit(this.pointer, data.miterLimit);
|
|
643
|
-
libmupdf._wasm_stroke_state_set_dash_phase(this.pointer, data.dashPhase ?? 0);
|
|
644
|
-
if (data.dashes) {
|
|
645
|
-
for (let i = 0; i < data.dashes.length; ++i)
|
|
646
|
-
libmupdf._wasm_stroke_state_set_dash_item(this.pointer, i, data.dashes[i] ?? 0);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
getLineCap() {
|
|
650
|
-
return libmupdf._wasm_stroke_state_get_start_cap(this.pointer);
|
|
651
|
-
}
|
|
652
|
-
getLineJoin() {
|
|
653
|
-
return libmupdf._wasm_stroke_state_get_linejoin(this.pointer);
|
|
654
|
-
}
|
|
655
|
-
getLineWidth() {
|
|
656
|
-
return libmupdf._wasm_stroke_state_get_linewidth(this.pointer);
|
|
657
|
-
}
|
|
658
|
-
getMiterLimit() {
|
|
659
|
-
return libmupdf._wasm_stroke_state_get_miterlimit(this.pointer);
|
|
660
|
-
}
|
|
661
|
-
getDashPhase() {
|
|
662
|
-
return libmupdf._wasm_stroke_state_get_dash_phase(this.pointer);
|
|
663
|
-
}
|
|
664
|
-
getDashes() {
|
|
665
|
-
var n = libmupdf._wasm_stroke_state_get_dash_len(this.pointer);
|
|
666
|
-
if (n > 0) {
|
|
667
|
-
var out = [];
|
|
668
|
-
for (let i = 0; i < n; ++i)
|
|
669
|
-
out[i] = libmupdf._wasm_stroke_state_get_dash_item(this.pointer, i);
|
|
670
|
-
return out;
|
|
671
|
-
}
|
|
672
|
-
return null;
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
StrokeState._drop = libmupdf._wasm_drop_stroke_state;
|
|
676
|
-
StrokeState.LINE_CAP = [
|
|
677
|
-
"Butt",
|
|
678
|
-
"Round",
|
|
679
|
-
"Square",
|
|
680
|
-
"Triangle"
|
|
681
|
-
];
|
|
682
|
-
StrokeState.LINE_JOIN = [
|
|
683
|
-
"Miter",
|
|
684
|
-
"Round",
|
|
685
|
-
"Bevel",
|
|
686
|
-
"MiterXPS"
|
|
687
|
-
];
|
|
688
|
-
class Path extends Userdata {
|
|
689
|
-
constructor(pointer) {
|
|
690
|
-
if (typeof pointer === "number")
|
|
691
|
-
super(pointer);
|
|
692
|
-
else
|
|
693
|
-
super(libmupdf._wasm_new_path());
|
|
694
|
-
}
|
|
695
|
-
getBounds(strokeState, transform) {
|
|
696
|
-
if (strokeState !== null)
|
|
697
|
-
checkType(strokeState, StrokeState);
|
|
698
|
-
checkMatrix(transform);
|
|
699
|
-
return fromRect(libmupdf._wasm_bound_path(this.pointer, strokeState?.pointer, MATRIX(transform)));
|
|
700
|
-
}
|
|
701
|
-
moveTo(x, y) {
|
|
702
|
-
checkType(x, "number");
|
|
703
|
-
checkType(y, "number");
|
|
704
|
-
libmupdf._wasm_moveto(this.pointer, x, y);
|
|
705
|
-
}
|
|
706
|
-
lineTo(x, y) {
|
|
707
|
-
checkType(x, "number");
|
|
708
|
-
checkType(y, "number");
|
|
709
|
-
libmupdf._wasm_lineto(this.pointer, x, y);
|
|
710
|
-
}
|
|
711
|
-
curveTo(x1, y1, x2, y2, x3, y3) {
|
|
712
|
-
checkType(x1, "number");
|
|
713
|
-
checkType(y1, "number");
|
|
714
|
-
checkType(x2, "number");
|
|
715
|
-
checkType(y2, "number");
|
|
716
|
-
checkType(x3, "number");
|
|
717
|
-
checkType(y3, "number");
|
|
718
|
-
libmupdf._wasm_curveto(this.pointer, x1, y1, x2, y2, x3, y3);
|
|
719
|
-
}
|
|
720
|
-
curveToV(cx, cy, ex, ey) {
|
|
721
|
-
checkType(cx, "number");
|
|
722
|
-
checkType(cy, "number");
|
|
723
|
-
checkType(ex, "number");
|
|
724
|
-
checkType(ey, "number");
|
|
725
|
-
libmupdf._wasm_curvetov(this.pointer, cx, cy, ex, ey);
|
|
726
|
-
}
|
|
727
|
-
curveToY(cx, cy, ex, ey) {
|
|
728
|
-
checkType(cx, "number");
|
|
729
|
-
checkType(cy, "number");
|
|
730
|
-
checkType(ex, "number");
|
|
731
|
-
checkType(ey, "number");
|
|
732
|
-
libmupdf._wasm_curvetoy(this.pointer, cx, cy, ex, ey);
|
|
733
|
-
}
|
|
734
|
-
closePath() {
|
|
735
|
-
libmupdf._wasm_closepath(this.pointer);
|
|
736
|
-
}
|
|
737
|
-
rect(x1, y1, x2, y2) {
|
|
738
|
-
checkType(x1, "number");
|
|
739
|
-
checkType(y1, "number");
|
|
740
|
-
checkType(x2, "number");
|
|
741
|
-
checkType(y2, "number");
|
|
742
|
-
libmupdf._wasm_rectto(this.pointer, x1, y1, x2, y2);
|
|
743
|
-
}
|
|
744
|
-
transform(matrix) {
|
|
745
|
-
checkMatrix(matrix);
|
|
746
|
-
libmupdf._wasm_transform_path(this.pointer, MATRIX(matrix));
|
|
747
|
-
}
|
|
748
|
-
walk(walker) {
|
|
749
|
-
let id = $libmupdf_path_id++;
|
|
750
|
-
$libmupdf_path_table.set(id, walker);
|
|
751
|
-
libmupdf._wasm_walk_path(this.pointer, id);
|
|
752
|
-
$libmupdf_path_table.delete(id);
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
Path._drop = libmupdf._wasm_drop_path;
|
|
756
|
-
class Text extends Userdata {
|
|
757
|
-
constructor(pointer) {
|
|
758
|
-
if (typeof pointer === "number")
|
|
759
|
-
super(pointer);
|
|
760
|
-
else
|
|
761
|
-
super(libmupdf._wasm_new_text());
|
|
762
|
-
}
|
|
763
|
-
getBounds(strokeState, transform) {
|
|
764
|
-
if (strokeState !== null)
|
|
765
|
-
checkType(strokeState, StrokeState);
|
|
766
|
-
checkMatrix(transform);
|
|
767
|
-
return fromRect(libmupdf._wasm_bound_text(this.pointer, strokeState?.pointer, MATRIX(transform)));
|
|
768
|
-
}
|
|
769
|
-
showGlyph(font, trm, gid, uni, wmode = 0) {
|
|
770
|
-
checkType(font, Font);
|
|
771
|
-
checkMatrix(trm);
|
|
772
|
-
checkType(gid, "number");
|
|
773
|
-
checkType(uni, "number");
|
|
774
|
-
libmupdf._wasm_show_glyph(this.pointer, font.pointer, MATRIX(trm), gid, uni, wmode);
|
|
775
|
-
}
|
|
776
|
-
showString(font, trm, str, wmode = 0) {
|
|
777
|
-
checkType(font, Font);
|
|
778
|
-
checkMatrix(trm);
|
|
779
|
-
checkType(str, "string");
|
|
780
|
-
return fromMatrix(libmupdf._wasm_show_string(this.pointer, font.pointer, MATRIX(trm), STRING(str), wmode));
|
|
781
|
-
}
|
|
782
|
-
walk(walker) {
|
|
783
|
-
let id = $libmupdf_text_id++;
|
|
784
|
-
$libmupdf_text_table.set(id, walker);
|
|
785
|
-
libmupdf._wasm_walk_text(this.pointer, id);
|
|
786
|
-
$libmupdf_text_table.delete(id);
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
Text._drop = libmupdf._wasm_drop_text;
|
|
790
|
-
class DisplayList extends Userdata {
|
|
791
|
-
constructor(arg1) {
|
|
792
|
-
let pointer = 0;
|
|
793
|
-
if (typeof arg1 === "number") {
|
|
794
|
-
pointer = arg1;
|
|
795
|
-
}
|
|
796
|
-
else {
|
|
797
|
-
checkRect(arg1);
|
|
798
|
-
pointer = libmupdf._wasm_new_display_list(RECT(arg1));
|
|
799
|
-
}
|
|
800
|
-
super(pointer);
|
|
801
|
-
}
|
|
802
|
-
getBounds() {
|
|
803
|
-
return fromRect(libmupdf._wasm_bound_display_list(this.pointer));
|
|
804
|
-
}
|
|
805
|
-
toPixmap(matrix, colorspace, alpha = false) {
|
|
806
|
-
checkMatrix(matrix);
|
|
807
|
-
checkType(colorspace, ColorSpace);
|
|
808
|
-
return new Pixmap(libmupdf._wasm_new_pixmap_from_display_list(this.pointer, MATRIX(matrix), colorspace.pointer, alpha));
|
|
809
|
-
}
|
|
810
|
-
toStructuredText(options = "") {
|
|
811
|
-
checkType(options, "string");
|
|
812
|
-
return new StructuredText(libmupdf._wasm_new_stext_page_from_display_list(this.pointer, STRING(options)));
|
|
813
|
-
}
|
|
814
|
-
run(device, matrix) {
|
|
815
|
-
checkType(device, Device);
|
|
816
|
-
checkMatrix(matrix);
|
|
817
|
-
libmupdf._wasm_run_display_list(this.pointer, device.pointer, MATRIX(matrix));
|
|
818
|
-
}
|
|
819
|
-
search(needle, max_hits = 500) {
|
|
820
|
-
return runSearch(libmupdf._wasm_search_display_list, this.pointer, needle, max_hits);
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
DisplayList._drop = libmupdf._wasm_drop_display_list;
|
|
824
|
-
class Pixmap extends Userdata {
|
|
825
|
-
constructor(arg1, bbox, alpha = false) {
|
|
826
|
-
if (typeof arg1 === "number") {
|
|
827
|
-
super(arg1);
|
|
828
|
-
}
|
|
829
|
-
if (arg1 instanceof ColorSpace) {
|
|
830
|
-
checkRect(bbox);
|
|
831
|
-
super(libmupdf._wasm_new_pixmap_with_bbox(arg1.pointer, RECT(bbox), alpha));
|
|
832
|
-
}
|
|
833
|
-
if (arg1 === null) {
|
|
834
|
-
checkRect(bbox);
|
|
835
|
-
super(libmupdf._wasm_new_pixmap_with_bbox(0, RECT(bbox), alpha));
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
getBounds() {
|
|
839
|
-
let x = libmupdf._wasm_pixmap_get_x(this.pointer);
|
|
840
|
-
let y = libmupdf._wasm_pixmap_get_y(this.pointer);
|
|
841
|
-
let w = libmupdf._wasm_pixmap_get_w(this.pointer);
|
|
842
|
-
let h = libmupdf._wasm_pixmap_get_h(this.pointer);
|
|
843
|
-
return [x, y, x + w, y + h];
|
|
844
|
-
}
|
|
845
|
-
clear(value) {
|
|
846
|
-
if (typeof value === "undefined")
|
|
847
|
-
libmupdf._wasm_clear_pixmap(this.pointer);
|
|
848
|
-
else
|
|
849
|
-
libmupdf._wasm_clear_pixmap_with_value(this.pointer, value);
|
|
850
|
-
}
|
|
851
|
-
getWidth() {
|
|
852
|
-
return libmupdf._wasm_pixmap_get_w(this.pointer);
|
|
853
|
-
}
|
|
854
|
-
getHeight() {
|
|
855
|
-
return libmupdf._wasm_pixmap_get_h(this.pointer);
|
|
856
|
-
}
|
|
857
|
-
getX() {
|
|
858
|
-
return libmupdf._wasm_pixmap_get_x(this.pointer);
|
|
859
|
-
}
|
|
860
|
-
getY() {
|
|
861
|
-
return libmupdf._wasm_pixmap_get_y(this.pointer);
|
|
862
|
-
}
|
|
863
|
-
getStride() {
|
|
864
|
-
return libmupdf._wasm_pixmap_get_stride(this.pointer);
|
|
865
|
-
}
|
|
866
|
-
getNumberOfComponents() {
|
|
867
|
-
return libmupdf._wasm_pixmap_get_n(this.pointer);
|
|
868
|
-
}
|
|
869
|
-
getAlpha() {
|
|
870
|
-
return libmupdf._wasm_pixmap_get_alpha(this.pointer);
|
|
871
|
-
}
|
|
872
|
-
getXResolution() {
|
|
873
|
-
return libmupdf._wasm_pixmap_get_xres(this.pointer);
|
|
874
|
-
}
|
|
875
|
-
getYResolution() {
|
|
876
|
-
return libmupdf._wasm_pixmap_get_yres(this.pointer);
|
|
877
|
-
}
|
|
878
|
-
setResolution(x, y) {
|
|
879
|
-
libmupdf._wasm_pixmap_set_xres(this.pointer, x);
|
|
880
|
-
libmupdf._wasm_pixmap_set_yres(this.pointer, y);
|
|
881
|
-
}
|
|
882
|
-
getColorSpace() {
|
|
883
|
-
let cs = libmupdf._wasm_pixmap_get_colorspace(this.pointer);
|
|
884
|
-
if (cs)
|
|
885
|
-
return new ColorSpace(libmupdf._wasm_keep_colorspace(cs));
|
|
886
|
-
return null;
|
|
887
|
-
}
|
|
888
|
-
getPixels() {
|
|
889
|
-
let s = libmupdf._wasm_pixmap_get_stride(this.pointer);
|
|
890
|
-
let h = libmupdf._wasm_pixmap_get_h(this.pointer);
|
|
891
|
-
let p = libmupdf._wasm_pixmap_get_samples(this.pointer);
|
|
892
|
-
return new Uint8ClampedArray(libmupdf.HEAPU8.buffer, p, s * h);
|
|
893
|
-
}
|
|
894
|
-
asPNG() {
|
|
895
|
-
let buf = libmupdf._wasm_new_buffer_from_pixmap_as_png(this.pointer);
|
|
896
|
-
try {
|
|
897
|
-
return fromBuffer$1(buf);
|
|
898
|
-
}
|
|
899
|
-
finally {
|
|
900
|
-
libmupdf._wasm_drop_buffer(buf);
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
asPSD() {
|
|
904
|
-
let buf = libmupdf._wasm_new_buffer_from_pixmap_as_psd(this.pointer);
|
|
905
|
-
try {
|
|
906
|
-
return fromBuffer$1(buf);
|
|
907
|
-
}
|
|
908
|
-
finally {
|
|
909
|
-
libmupdf._wasm_drop_buffer(buf);
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
asPAM() {
|
|
913
|
-
let buf = libmupdf._wasm_new_buffer_from_pixmap_as_pam(this.pointer);
|
|
914
|
-
try {
|
|
915
|
-
return fromBuffer$1(buf);
|
|
916
|
-
}
|
|
917
|
-
finally {
|
|
918
|
-
libmupdf._wasm_drop_buffer(buf);
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
asJPEG(quality, invert_cmyk = false) {
|
|
922
|
-
let buf = libmupdf._wasm_new_buffer_from_pixmap_as_jpeg(this.pointer, quality, invert_cmyk);
|
|
923
|
-
try {
|
|
924
|
-
return fromBuffer$1(buf);
|
|
925
|
-
}
|
|
926
|
-
finally {
|
|
927
|
-
libmupdf._wasm_drop_buffer(buf);
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
invert() {
|
|
931
|
-
libmupdf._wasm_invert_pixmap(this.pointer);
|
|
932
|
-
}
|
|
933
|
-
invertLuminance() {
|
|
934
|
-
libmupdf._wasm_invert_pixmap_luminance(this.pointer);
|
|
935
|
-
}
|
|
936
|
-
gamma(p) {
|
|
937
|
-
libmupdf._wasm_gamma_pixmap(this.pointer, p);
|
|
938
|
-
}
|
|
939
|
-
tint(black, white) {
|
|
940
|
-
let black_hex = 0x000000;
|
|
941
|
-
let white_hex = 0xffffff;
|
|
942
|
-
if (typeof black === "number")
|
|
943
|
-
black_hex = black;
|
|
944
|
-
else if (black instanceof Array && black.length === 3)
|
|
945
|
-
black_hex = (((black[0] * 255) << 16) | ((black[1] * 255) << 8) | ((black[2] * 255)));
|
|
946
|
-
if (typeof white === "number")
|
|
947
|
-
white_hex = white;
|
|
948
|
-
else if (white instanceof Array && white.length === 3)
|
|
949
|
-
white = (((white[0] * 255) << 16) | ((white[1] * 255) << 8) | ((white[2] * 255)));
|
|
950
|
-
libmupdf._wasm_tint_pixmap(this.pointer, black_hex, white_hex);
|
|
951
|
-
}
|
|
952
|
-
convertToColorSpace(colorspace, keepAlpha = false) {
|
|
953
|
-
checkType(colorspace, ColorSpace);
|
|
954
|
-
checkType(keepAlpha, "boolean");
|
|
955
|
-
return new Pixmap(libmupdf._wasm_convert_pixmap(this.pointer, colorspace.pointer, keepAlpha));
|
|
956
|
-
}
|
|
957
|
-
warp(points, width, height) {
|
|
958
|
-
let quad = points.flat();
|
|
959
|
-
checkQuad(quad);
|
|
960
|
-
checkType(width, "number");
|
|
961
|
-
checkType(height, "number");
|
|
962
|
-
return new Pixmap(libmupdf._wasm_warp_pixmap(this.pointer, QUAD(quad), width, height));
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
Pixmap._drop = libmupdf._wasm_drop_pixmap;
|
|
966
|
-
class Shade extends Userdata {
|
|
967
|
-
getBounds() {
|
|
968
|
-
return fromRect(libmupdf._wasm_bound_shade(this.pointer));
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
Shade._drop = libmupdf._wasm_drop_shade;
|
|
972
|
-
class StructuredText extends Userdata {
|
|
973
|
-
walk(walker) {
|
|
974
|
-
let block = libmupdf._wasm_stext_page_get_first_block(this.pointer);
|
|
975
|
-
while (block) {
|
|
976
|
-
let block_type = libmupdf._wasm_stext_block_get_type(block);
|
|
977
|
-
let block_bbox = fromRect(libmupdf._wasm_stext_block_get_bbox(block));
|
|
978
|
-
if (block_type === 1) {
|
|
979
|
-
if (walker.onImageBlock) {
|
|
980
|
-
let matrix = fromMatrix(libmupdf._wasm_stext_block_get_transform(block));
|
|
981
|
-
let image = new Image(libmupdf._wasm_stext_block_get_image(block));
|
|
982
|
-
walker.onImageBlock(block_bbox, matrix, image);
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
else {
|
|
986
|
-
if (walker.beginTextBlock)
|
|
987
|
-
walker.beginTextBlock(block_bbox);
|
|
988
|
-
let line = libmupdf._wasm_stext_block_get_first_line(block);
|
|
989
|
-
while (line) {
|
|
990
|
-
let line_bbox = fromRect(libmupdf._wasm_stext_line_get_bbox(line));
|
|
991
|
-
let line_wmode = libmupdf._wasm_stext_line_get_wmode(line);
|
|
992
|
-
let line_dir = fromPoint(libmupdf._wasm_stext_line_get_dir(line));
|
|
993
|
-
if (walker.beginLine)
|
|
994
|
-
walker.beginLine(line_bbox, line_wmode, line_dir);
|
|
995
|
-
if (walker.onChar) {
|
|
996
|
-
let ch = libmupdf._wasm_stext_line_get_first_char(line);
|
|
997
|
-
while (ch) {
|
|
998
|
-
let ch_rune = String.fromCharCode(libmupdf._wasm_stext_char_get_c(ch));
|
|
999
|
-
let ch_origin = fromPoint(libmupdf._wasm_stext_char_get_origin(ch));
|
|
1000
|
-
let ch_font = new Font(libmupdf._wasm_stext_char_get_font(ch));
|
|
1001
|
-
let ch_size = libmupdf._wasm_stext_char_get_size(ch);
|
|
1002
|
-
let ch_quad = fromQuad(libmupdf._wasm_stext_char_get_quad(ch));
|
|
1003
|
-
let ch_color = colorFromNumber(libmupdf._wasm_stext_char_get_argb(ch));
|
|
1004
|
-
walker.onChar(ch_rune, ch_origin, ch_font, ch_size, ch_quad, ch_color);
|
|
1005
|
-
ch = libmupdf._wasm_stext_char_get_next(ch);
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
if (walker.endLine)
|
|
1009
|
-
walker.endLine();
|
|
1010
|
-
line = libmupdf._wasm_stext_line_get_next(line);
|
|
1011
|
-
}
|
|
1012
|
-
if (walker.endTextBlock)
|
|
1013
|
-
walker.endTextBlock();
|
|
1014
|
-
}
|
|
1015
|
-
block = libmupdf._wasm_stext_block_get_next(block);
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
asJSON(scale = 1) {
|
|
1019
|
-
return fromStringFree(libmupdf._wasm_print_stext_page_as_json(this.pointer, scale));
|
|
1020
|
-
}
|
|
1021
|
-
asHTML(id) {
|
|
1022
|
-
return fromStringFree(libmupdf._wasm_print_stext_page_as_html(this.pointer, id));
|
|
1023
|
-
}
|
|
1024
|
-
asText() {
|
|
1025
|
-
return fromStringFree(libmupdf._wasm_print_stext_page_as_text(this.pointer));
|
|
1026
|
-
}
|
|
1027
|
-
snap(p, q, mode) {
|
|
1028
|
-
let mm = ENUM(mode, StructuredText.SELECT_MODE);
|
|
1029
|
-
return fromQuad(libmupdf._wasm_snap_selection(this.pointer, POINT(p), POINT2(q), mm));
|
|
1030
|
-
}
|
|
1031
|
-
copy(p, q) {
|
|
1032
|
-
return fromStringFree(libmupdf._wasm_copy_selection(this.pointer, POINT(p), POINT2(q)));
|
|
1033
|
-
}
|
|
1034
|
-
highlight(p, q, max_hits = 100) {
|
|
1035
|
-
let hits = 0;
|
|
1036
|
-
let result = [];
|
|
1037
|
-
try {
|
|
1038
|
-
hits = Malloc(32 * max_hits);
|
|
1039
|
-
let n = libmupdf._wasm_highlight_selection(this.pointer, POINT(p), POINT2(q), hits, max_hits);
|
|
1040
|
-
for (let i = 0; i < n; ++i)
|
|
1041
|
-
result.push(fromQuad(hits + i * 32));
|
|
1042
|
-
}
|
|
1043
|
-
finally {
|
|
1044
|
-
Free(hits);
|
|
1045
|
-
}
|
|
1046
|
-
return result;
|
|
1047
|
-
}
|
|
1048
|
-
search(needle, max_hits = 500) {
|
|
1049
|
-
return runSearch(libmupdf._wasm_search_stext_page, this.pointer, needle, max_hits);
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
StructuredText._drop = libmupdf._wasm_drop_stext_page;
|
|
1053
|
-
StructuredText.SELECT_MODE = [
|
|
1054
|
-
"chars",
|
|
1055
|
-
"words",
|
|
1056
|
-
"lines"
|
|
1057
|
-
];
|
|
1058
|
-
StructuredText.SELECT_CHARS = "chars";
|
|
1059
|
-
StructuredText.SELECT_WORDS = "words";
|
|
1060
|
-
StructuredText.SELECT_LINES = "lines";
|
|
1061
|
-
class Device extends Userdata {
|
|
1062
|
-
constructor(pointer_or_callbacks) {
|
|
1063
|
-
if (typeof pointer_or_callbacks === "number")
|
|
1064
|
-
super(pointer_or_callbacks);
|
|
1065
|
-
else {
|
|
1066
|
-
let id = $libmupdf_device_id++;
|
|
1067
|
-
$libmupdf_device_table.set(id, pointer_or_callbacks);
|
|
1068
|
-
super(libmupdf._wasm_new_js_device(id));
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
fillPath(path, evenOdd, ctm, colorspace, color, alpha) {
|
|
1072
|
-
checkType(path, Path);
|
|
1073
|
-
checkMatrix(ctm);
|
|
1074
|
-
checkType(colorspace, ColorSpace);
|
|
1075
|
-
checkColor(color);
|
|
1076
|
-
libmupdf._wasm_fill_path(this.pointer, path.pointer, evenOdd, MATRIX(ctm), colorspace.pointer, COLOR(color), alpha);
|
|
1077
|
-
}
|
|
1078
|
-
strokePath(path, stroke, ctm, colorspace, color, alpha) {
|
|
1079
|
-
checkType(path, Path);
|
|
1080
|
-
checkType(stroke, StrokeState);
|
|
1081
|
-
checkMatrix(ctm);
|
|
1082
|
-
checkType(colorspace, ColorSpace);
|
|
1083
|
-
checkColor(color);
|
|
1084
|
-
libmupdf._wasm_stroke_path(this.pointer, path.pointer, stroke.pointer, MATRIX(ctm), colorspace.pointer, COLOR(color), alpha);
|
|
1085
|
-
}
|
|
1086
|
-
clipPath(path, evenOdd, ctm) {
|
|
1087
|
-
checkType(path, Path);
|
|
1088
|
-
checkMatrix(ctm);
|
|
1089
|
-
libmupdf._wasm_clip_path(this.pointer, path.pointer, evenOdd, MATRIX(ctm));
|
|
1090
|
-
}
|
|
1091
|
-
clipStrokePath(path, stroke, ctm) {
|
|
1092
|
-
checkType(path, Path);
|
|
1093
|
-
checkType(stroke, StrokeState);
|
|
1094
|
-
checkMatrix(ctm);
|
|
1095
|
-
libmupdf._wasm_clip_stroke_path(this.pointer, path.pointer, stroke.pointer, MATRIX(ctm));
|
|
1096
|
-
}
|
|
1097
|
-
fillText(text, ctm, colorspace, color, alpha) {
|
|
1098
|
-
checkType(text, Text);
|
|
1099
|
-
checkMatrix(ctm);
|
|
1100
|
-
checkType(colorspace, ColorSpace);
|
|
1101
|
-
checkColor(color);
|
|
1102
|
-
libmupdf._wasm_fill_text(this.pointer, text.pointer, MATRIX(ctm), colorspace.pointer, COLOR(color), alpha);
|
|
1103
|
-
}
|
|
1104
|
-
strokeText(text, stroke, ctm, colorspace, color, alpha) {
|
|
1105
|
-
checkType(text, Text);
|
|
1106
|
-
checkType(stroke, StrokeState);
|
|
1107
|
-
checkMatrix(ctm);
|
|
1108
|
-
checkType(colorspace, ColorSpace);
|
|
1109
|
-
checkColor(color);
|
|
1110
|
-
libmupdf._wasm_stroke_text(this.pointer, text.pointer, stroke.pointer, MATRIX(ctm), colorspace.pointer, COLOR(color), alpha);
|
|
1111
|
-
}
|
|
1112
|
-
clipText(text, ctm) {
|
|
1113
|
-
checkType(text, Text);
|
|
1114
|
-
checkMatrix(ctm);
|
|
1115
|
-
libmupdf._wasm_clip_text(this.pointer, text.pointer, MATRIX(ctm));
|
|
1116
|
-
}
|
|
1117
|
-
clipStrokeText(text, stroke, ctm) {
|
|
1118
|
-
checkType(text, Text);
|
|
1119
|
-
checkType(stroke, StrokeState);
|
|
1120
|
-
checkMatrix(ctm);
|
|
1121
|
-
libmupdf._wasm_clip_stroke_text(this.pointer, text.pointer, stroke.pointer, MATRIX(ctm));
|
|
1122
|
-
}
|
|
1123
|
-
ignoreText(text, ctm) {
|
|
1124
|
-
checkType(text, Text);
|
|
1125
|
-
checkMatrix(ctm);
|
|
1126
|
-
libmupdf._wasm_ignore_text(this.pointer, text.pointer, MATRIX(ctm));
|
|
1127
|
-
}
|
|
1128
|
-
fillShade(shade, ctm, alpha) {
|
|
1129
|
-
checkType(shade, Shade);
|
|
1130
|
-
checkMatrix(ctm);
|
|
1131
|
-
libmupdf._wasm_fill_shade(this.pointer, shade.pointer, MATRIX(ctm), alpha);
|
|
1132
|
-
}
|
|
1133
|
-
fillImage(image, ctm, alpha) {
|
|
1134
|
-
checkType(image, Image);
|
|
1135
|
-
checkMatrix(ctm);
|
|
1136
|
-
libmupdf._wasm_fill_image(this.pointer, image.pointer, MATRIX(ctm), alpha);
|
|
1137
|
-
}
|
|
1138
|
-
fillImageMask(image, ctm, colorspace, color, alpha) {
|
|
1139
|
-
checkType(image, Image);
|
|
1140
|
-
checkMatrix(ctm);
|
|
1141
|
-
checkType(colorspace, ColorSpace);
|
|
1142
|
-
checkColor(color);
|
|
1143
|
-
libmupdf._wasm_fill_image_mask(this.pointer, image.pointer, MATRIX(ctm), colorspace.pointer, COLOR(color), alpha);
|
|
1144
|
-
}
|
|
1145
|
-
clipImageMask(image, ctm) {
|
|
1146
|
-
checkType(image, Image);
|
|
1147
|
-
checkMatrix(ctm);
|
|
1148
|
-
libmupdf._wasm_clip_image_mask(this.pointer, image.pointer, MATRIX(ctm));
|
|
1149
|
-
}
|
|
1150
|
-
popClip() {
|
|
1151
|
-
libmupdf._wasm_pop_clip(this.pointer);
|
|
1152
|
-
}
|
|
1153
|
-
beginMask(area, luminosity, colorspace, color) {
|
|
1154
|
-
checkRect(area);
|
|
1155
|
-
checkType(colorspace, ColorSpace);
|
|
1156
|
-
checkColor(color);
|
|
1157
|
-
libmupdf._wasm_begin_mask(this.pointer, RECT(area), luminosity, colorspace.pointer, COLOR(color));
|
|
1158
|
-
}
|
|
1159
|
-
endMask() {
|
|
1160
|
-
libmupdf._wasm_end_mask(this.pointer);
|
|
1161
|
-
}
|
|
1162
|
-
beginGroup(area, colorspace, isolated, knockout, blendmode, alpha) {
|
|
1163
|
-
checkRect(area);
|
|
1164
|
-
checkType(colorspace, ColorSpace);
|
|
1165
|
-
let blendmode_ix = ENUM(blendmode, Device.BLEND_MODES);
|
|
1166
|
-
libmupdf._wasm_begin_group(this.pointer, RECT(area), colorspace.pointer, isolated, knockout, blendmode_ix, alpha);
|
|
1167
|
-
}
|
|
1168
|
-
endGroup() {
|
|
1169
|
-
libmupdf._wasm_end_group(this.pointer);
|
|
1170
|
-
}
|
|
1171
|
-
beginTile(area, view, xstep, ystep, ctm, id) {
|
|
1172
|
-
checkRect(area);
|
|
1173
|
-
checkRect(view);
|
|
1174
|
-
checkMatrix(ctm);
|
|
1175
|
-
return libmupdf._wasm_begin_tile(this.pointer, RECT(area), RECT2(view), xstep, ystep, MATRIX(ctm), id);
|
|
1176
|
-
}
|
|
1177
|
-
endTile() {
|
|
1178
|
-
libmupdf._wasm_end_tile(this.pointer);
|
|
1179
|
-
}
|
|
1180
|
-
beginLayer(name) {
|
|
1181
|
-
libmupdf._wasm_begin_layer(this.pointer, STRING(name));
|
|
1182
|
-
}
|
|
1183
|
-
endLayer() {
|
|
1184
|
-
libmupdf._wasm_end_layer(this.pointer);
|
|
1185
|
-
}
|
|
1186
|
-
close() {
|
|
1187
|
-
libmupdf._wasm_close_device(this.pointer);
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
Device._drop = libmupdf._wasm_drop_device;
|
|
1191
|
-
Device.BLEND_MODES = [
|
|
1192
|
-
"Normal",
|
|
1193
|
-
"Multiply",
|
|
1194
|
-
"Screen",
|
|
1195
|
-
"Overlay",
|
|
1196
|
-
"Darken",
|
|
1197
|
-
"Lighten",
|
|
1198
|
-
"ColorDodge",
|
|
1199
|
-
"ColorBurn",
|
|
1200
|
-
"HardLight",
|
|
1201
|
-
"SoftLight",
|
|
1202
|
-
"Difference",
|
|
1203
|
-
"Exclusion",
|
|
1204
|
-
"Hue",
|
|
1205
|
-
"Saturation",
|
|
1206
|
-
"Color",
|
|
1207
|
-
"Luminosity",
|
|
1208
|
-
];
|
|
1209
|
-
class DocumentWriter extends Userdata {
|
|
1210
|
-
constructor(buffer, format, options) {
|
|
1211
|
-
super(libmupdf._wasm_new_document_writer_with_buffer(BUFFER(buffer), STRING(format), STRING2(options)));
|
|
1212
|
-
}
|
|
1213
|
-
beginPage(mediabox) {
|
|
1214
|
-
checkRect(mediabox);
|
|
1215
|
-
return new Device(libmupdf._wasm_begin_page(this.pointer, RECT(mediabox)));
|
|
1216
|
-
}
|
|
1217
|
-
endPage() {
|
|
1218
|
-
libmupdf._wasm_end_page(this.pointer);
|
|
1219
|
-
}
|
|
1220
|
-
close() {
|
|
1221
|
-
libmupdf._wasm_close_document_writer(this.pointer);
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
DocumentWriter._drop = libmupdf._wasm_drop_document_writer;
|
|
1225
|
-
class Document extends Userdata {
|
|
1226
|
-
static openDocument(from, magic) {
|
|
1227
|
-
let pointer = 0;
|
|
1228
|
-
if (typeof from === "string") {
|
|
1229
|
-
magic = from;
|
|
1230
|
-
if (node_fs)
|
|
1231
|
-
from = node_fs.readFileSync(from);
|
|
1232
|
-
else
|
|
1233
|
-
throw new Error("missing 'fs' module");
|
|
1234
|
-
}
|
|
1235
|
-
else {
|
|
1236
|
-
if (typeof magic === "undefined")
|
|
1237
|
-
magic = "application/pdf";
|
|
1238
|
-
}
|
|
1239
|
-
checkType(magic, "string");
|
|
1240
|
-
if (from instanceof ArrayBuffer || from instanceof Uint8Array)
|
|
1241
|
-
from = new Buffer$1(from);
|
|
1242
|
-
if (from instanceof Buffer$1)
|
|
1243
|
-
pointer = libmupdf._wasm_open_document_with_buffer(STRING(magic), from.pointer);
|
|
1244
|
-
else if (from instanceof Stream)
|
|
1245
|
-
pointer = libmupdf._wasm_open_document_with_stream(STRING(magic), from.pointer);
|
|
1246
|
-
else
|
|
1247
|
-
throw new Error("not a Buffer or Stream");
|
|
1248
|
-
let pdf = libmupdf._wasm_pdf_document_from_fz_document(pointer);
|
|
1249
|
-
if (pdf)
|
|
1250
|
-
return new PDFDocument(pdf);
|
|
1251
|
-
return new Document(pointer);
|
|
1252
|
-
}
|
|
1253
|
-
formatLinkURI(dest) {
|
|
1254
|
-
return fromStringFree(libmupdf._wasm_format_link_uri(this.pointer, dest.chapter | 0, dest.page | 0, ENUM(dest.type, Document.LINK_DEST), +dest.x, +dest.y, +dest.width, +dest.height, +dest.zoom));
|
|
1255
|
-
}
|
|
1256
|
-
asPDF() {
|
|
1257
|
-
if (this instanceof PDFDocument)
|
|
1258
|
-
return this;
|
|
1259
|
-
return null;
|
|
1260
|
-
}
|
|
1261
|
-
isPDF() {
|
|
1262
|
-
return this instanceof PDFDocument;
|
|
1263
|
-
}
|
|
1264
|
-
needsPassword() {
|
|
1265
|
-
return !!libmupdf._wasm_needs_password(this.pointer);
|
|
1266
|
-
}
|
|
1267
|
-
authenticatePassword(password) {
|
|
1268
|
-
return libmupdf._wasm_authenticate_password(this.pointer, STRING(password));
|
|
1269
|
-
}
|
|
1270
|
-
hasPermission(perm) {
|
|
1271
|
-
let perm_ix = Document.PERMISSION[perm];
|
|
1272
|
-
return !!libmupdf._wasm_has_permission(this.pointer, perm_ix);
|
|
1273
|
-
}
|
|
1274
|
-
getMetaData(key) {
|
|
1275
|
-
let value = libmupdf._wasm_lookup_metadata(this.pointer, STRING(key));
|
|
1276
|
-
if (value)
|
|
1277
|
-
return fromString$1(value);
|
|
1278
|
-
return undefined;
|
|
1279
|
-
}
|
|
1280
|
-
setMetaData(key, value) {
|
|
1281
|
-
libmupdf._wasm_set_metadata(this.pointer, STRING(key), STRING2(value));
|
|
1282
|
-
}
|
|
1283
|
-
countPages() {
|
|
1284
|
-
return libmupdf._wasm_count_pages(this.pointer);
|
|
1285
|
-
}
|
|
1286
|
-
isReflowable() {
|
|
1287
|
-
libmupdf._wasm_is_document_reflowable(this.pointer);
|
|
1288
|
-
}
|
|
1289
|
-
layout(w, h, em) {
|
|
1290
|
-
libmupdf._wasm_layout_document(this.pointer, w, h, em);
|
|
1291
|
-
}
|
|
1292
|
-
loadPage(index) {
|
|
1293
|
-
let fz_ptr = libmupdf._wasm_load_page(this.pointer, index);
|
|
1294
|
-
if (this instanceof PDFDocument) {
|
|
1295
|
-
let pdf_ptr = libmupdf._wasm_pdf_page_from_fz_page(fz_ptr);
|
|
1296
|
-
if (pdf_ptr)
|
|
1297
|
-
return new PDFPage(this, pdf_ptr);
|
|
1298
|
-
}
|
|
1299
|
-
return new Page(fz_ptr);
|
|
1300
|
-
}
|
|
1301
|
-
loadOutline() {
|
|
1302
|
-
let doc = this.pointer;
|
|
1303
|
-
function to_outline(outline) {
|
|
1304
|
-
let result = [];
|
|
1305
|
-
while (outline) {
|
|
1306
|
-
let title = libmupdf._wasm_outline_get_title(outline);
|
|
1307
|
-
let uri = libmupdf._wasm_outline_get_uri(outline);
|
|
1308
|
-
let open = libmupdf._wasm_outline_get_is_open(outline);
|
|
1309
|
-
let item = {
|
|
1310
|
-
title: title ? fromString$1(title) : undefined,
|
|
1311
|
-
uri: uri ? fromString$1(uri) : undefined,
|
|
1312
|
-
open: !!open,
|
|
1313
|
-
};
|
|
1314
|
-
let page = libmupdf._wasm_outline_get_page(doc, outline);
|
|
1315
|
-
if (page >= 0)
|
|
1316
|
-
item.page = page;
|
|
1317
|
-
let down = libmupdf._wasm_outline_get_down(outline);
|
|
1318
|
-
if (down)
|
|
1319
|
-
item.down = to_outline(down);
|
|
1320
|
-
result.push(item);
|
|
1321
|
-
outline = libmupdf._wasm_outline_get_next(outline);
|
|
1322
|
-
}
|
|
1323
|
-
return result;
|
|
1324
|
-
}
|
|
1325
|
-
let root = libmupdf._wasm_load_outline(doc);
|
|
1326
|
-
if (root)
|
|
1327
|
-
return to_outline(root);
|
|
1328
|
-
return null;
|
|
1329
|
-
}
|
|
1330
|
-
resolveLink(link) {
|
|
1331
|
-
if (link instanceof Link)
|
|
1332
|
-
return libmupdf._wasm_resolve_link(this.pointer, libmupdf._wasm_link_get_uri(link.pointer));
|
|
1333
|
-
return libmupdf._wasm_resolve_link(this.pointer, STRING(link));
|
|
1334
|
-
}
|
|
1335
|
-
resolveLinkDestination(link) {
|
|
1336
|
-
let dest;
|
|
1337
|
-
if (link instanceof Link)
|
|
1338
|
-
dest = libmupdf._wasm_resolve_link_dest(this.pointer, libmupdf._wasm_link_get_uri(link.pointer));
|
|
1339
|
-
else
|
|
1340
|
-
dest = libmupdf._wasm_resolve_link_dest(this.pointer, STRING(link));
|
|
1341
|
-
return {
|
|
1342
|
-
type: Document.LINK_DEST[libmupdf._wasm_link_dest_get_type(dest)],
|
|
1343
|
-
chapter: libmupdf._wasm_link_dest_get_chapter(dest),
|
|
1344
|
-
page: libmupdf._wasm_link_dest_get_page(dest),
|
|
1345
|
-
x: libmupdf._wasm_link_dest_get_x(dest),
|
|
1346
|
-
y: libmupdf._wasm_link_dest_get_y(dest),
|
|
1347
|
-
width: libmupdf._wasm_link_dest_get_w(dest),
|
|
1348
|
-
height: libmupdf._wasm_link_dest_get_h(dest),
|
|
1349
|
-
zoom: libmupdf._wasm_link_dest_get_zoom(dest),
|
|
1350
|
-
};
|
|
1351
|
-
}
|
|
1352
|
-
outlineIterator() {
|
|
1353
|
-
return new OutlineIterator(libmupdf._wasm_new_outline_iterator(this.pointer));
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
Document._drop = libmupdf._wasm_drop_document;
|
|
1357
|
-
Document.META_FORMAT = "format";
|
|
1358
|
-
Document.META_ENCRYPTION = "encryption";
|
|
1359
|
-
Document.META_INFO_AUTHOR = "info:Author";
|
|
1360
|
-
Document.META_INFO_TITLE = "info:Title";
|
|
1361
|
-
Document.META_INFO_SUBJECT = "info:Subject";
|
|
1362
|
-
Document.META_INFO_KEYWORDS = "info:Keywords";
|
|
1363
|
-
Document.META_INFO_CREATOR = "info:Creator";
|
|
1364
|
-
Document.META_INFO_PRODUCER = "info:Producer";
|
|
1365
|
-
Document.META_INFO_CREATIONDATE = "info:CreationDate";
|
|
1366
|
-
Document.META_INFO_MODIFICATIONDATE = "info:ModDate";
|
|
1367
|
-
Document.PERMISSION = {
|
|
1368
|
-
"print": "p".charCodeAt(0),
|
|
1369
|
-
"copy": "c".charCodeAt(0),
|
|
1370
|
-
"edit": "e".charCodeAt(0),
|
|
1371
|
-
"annotate": "n".charCodeAt(0),
|
|
1372
|
-
"form": "f".charCodeAt(0),
|
|
1373
|
-
"accessibility": "y".charCodeAt(0),
|
|
1374
|
-
"assemble": "a".charCodeAt(0),
|
|
1375
|
-
"print-hq": "h".charCodeAt(0),
|
|
1376
|
-
};
|
|
1377
|
-
Document.LINK_DEST = [
|
|
1378
|
-
"Fit",
|
|
1379
|
-
"FitB",
|
|
1380
|
-
"FitH",
|
|
1381
|
-
"FitBH",
|
|
1382
|
-
"FitV",
|
|
1383
|
-
"FitBV",
|
|
1384
|
-
"FitR",
|
|
1385
|
-
"XYZ",
|
|
1386
|
-
];
|
|
1387
|
-
class OutlineIterator extends Userdata {
|
|
1388
|
-
item() {
|
|
1389
|
-
let item = libmupdf._wasm_outline_iterator_item(this.pointer);
|
|
1390
|
-
if (item) {
|
|
1391
|
-
let title_ptr = libmupdf._wasm_outline_item_get_title(item);
|
|
1392
|
-
let uri_ptr = libmupdf._wasm_outline_item_get_uri(item);
|
|
1393
|
-
let is_open = libmupdf._wasm_outline_item_get_is_open(item);
|
|
1394
|
-
return {
|
|
1395
|
-
title: title_ptr ? fromString$1(title_ptr) : undefined,
|
|
1396
|
-
uri: uri_ptr ? fromString$1(uri_ptr) : undefined,
|
|
1397
|
-
open: !!is_open,
|
|
1398
|
-
};
|
|
1399
|
-
}
|
|
1400
|
-
return null;
|
|
1401
|
-
}
|
|
1402
|
-
next() {
|
|
1403
|
-
return libmupdf._wasm_outline_iterator_next(this.pointer);
|
|
1404
|
-
}
|
|
1405
|
-
prev() {
|
|
1406
|
-
return libmupdf._wasm_outline_iterator_prev(this.pointer);
|
|
1407
|
-
}
|
|
1408
|
-
up() {
|
|
1409
|
-
return libmupdf._wasm_outline_iterator_up(this.pointer);
|
|
1410
|
-
}
|
|
1411
|
-
down() {
|
|
1412
|
-
return libmupdf._wasm_outline_iterator_down(this.pointer);
|
|
1413
|
-
}
|
|
1414
|
-
delete() {
|
|
1415
|
-
return libmupdf._wasm_outline_iterator_delete(this.pointer);
|
|
1416
|
-
}
|
|
1417
|
-
insert(item) {
|
|
1418
|
-
return libmupdf._wasm_outline_iterator_insert(this.pointer, STRING_OPT(item.title), STRING2_OPT(item.uri), item.open);
|
|
1419
|
-
}
|
|
1420
|
-
update(item) {
|
|
1421
|
-
libmupdf._wasm_outline_iterator_update(this.pointer, STRING_OPT(item.title), STRING2_OPT(item.uri), item.open);
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
OutlineIterator._drop = libmupdf._wasm_drop_outline_iterator;
|
|
1425
|
-
OutlineIterator.RESULT_DID_NOT_MOVE = -1;
|
|
1426
|
-
OutlineIterator.RESULT_AT_ITEM = 0;
|
|
1427
|
-
OutlineIterator.RESULT_AT_EMPTY = 1;
|
|
1428
|
-
class Link extends Userdata {
|
|
1429
|
-
getBounds() {
|
|
1430
|
-
return fromRect(libmupdf._wasm_link_get_rect(this.pointer));
|
|
1431
|
-
}
|
|
1432
|
-
setBounds(rect) {
|
|
1433
|
-
checkRect(rect);
|
|
1434
|
-
libmupdf._wasm_link_set_rect(this.pointer, RECT(rect));
|
|
1435
|
-
}
|
|
1436
|
-
getURI() {
|
|
1437
|
-
return fromString$1(libmupdf._wasm_link_get_uri(this.pointer));
|
|
1438
|
-
}
|
|
1439
|
-
setURI(uri) {
|
|
1440
|
-
checkType(uri, "string");
|
|
1441
|
-
libmupdf._wasm_link_set_uri(this.pointer, STRING(uri));
|
|
1442
|
-
}
|
|
1443
|
-
isExternal() {
|
|
1444
|
-
return /^\w[\w+-.]*:/.test(this.getURI());
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
Link._drop = libmupdf._wasm_drop_link;
|
|
1448
|
-
class Page extends Userdata {
|
|
1449
|
-
isPDF() {
|
|
1450
|
-
return this instanceof PDFPage;
|
|
1451
|
-
}
|
|
1452
|
-
getBounds(box = "CropBox") {
|
|
1453
|
-
let box_ix = ENUM(box, Page.BOXES);
|
|
1454
|
-
return fromRect(libmupdf._wasm_bound_page(this.pointer, box_ix));
|
|
1455
|
-
}
|
|
1456
|
-
getLabel() {
|
|
1457
|
-
return fromString$1(libmupdf._wasm_page_label(this.pointer));
|
|
1458
|
-
}
|
|
1459
|
-
run(device, matrix) {
|
|
1460
|
-
checkType(device, Device);
|
|
1461
|
-
checkMatrix(matrix);
|
|
1462
|
-
libmupdf._wasm_run_page(this.pointer, device.pointer, MATRIX(matrix));
|
|
1463
|
-
}
|
|
1464
|
-
runPageContents(device, matrix) {
|
|
1465
|
-
checkType(device, Device);
|
|
1466
|
-
checkMatrix(matrix);
|
|
1467
|
-
libmupdf._wasm_run_page_contents(this.pointer, device.pointer, MATRIX(matrix));
|
|
1468
|
-
}
|
|
1469
|
-
runPageAnnots(device, matrix) {
|
|
1470
|
-
checkType(device, Device);
|
|
1471
|
-
checkMatrix(matrix);
|
|
1472
|
-
libmupdf._wasm_run_page_annots(this.pointer, device.pointer, MATRIX(matrix));
|
|
1473
|
-
}
|
|
1474
|
-
runPageWidgets(device, matrix) {
|
|
1475
|
-
checkType(device, Device);
|
|
1476
|
-
checkMatrix(matrix);
|
|
1477
|
-
libmupdf._wasm_run_page_widgets(this.pointer, device.pointer, MATRIX(matrix));
|
|
1478
|
-
}
|
|
1479
|
-
toPixmap(matrix, colorspace, alpha = false, showExtras = true) {
|
|
1480
|
-
checkType(colorspace, ColorSpace);
|
|
1481
|
-
checkMatrix(matrix);
|
|
1482
|
-
let result;
|
|
1483
|
-
if (showExtras)
|
|
1484
|
-
result = libmupdf._wasm_new_pixmap_from_page(this.pointer, MATRIX(matrix), colorspace.pointer, alpha);
|
|
1485
|
-
else
|
|
1486
|
-
result = libmupdf._wasm_new_pixmap_from_page_contents(this.pointer, MATRIX(matrix), colorspace.pointer, alpha);
|
|
1487
|
-
return new Pixmap(result);
|
|
1488
|
-
}
|
|
1489
|
-
toDisplayList(showExtras = true) {
|
|
1490
|
-
let result;
|
|
1491
|
-
if (showExtras)
|
|
1492
|
-
result = libmupdf._wasm_new_display_list_from_page(this.pointer);
|
|
1493
|
-
else
|
|
1494
|
-
result = libmupdf._wasm_new_display_list_from_page_contents(this.pointer);
|
|
1495
|
-
return new DisplayList(result);
|
|
1496
|
-
}
|
|
1497
|
-
toStructuredText(options = "") {
|
|
1498
|
-
checkType(options, "string");
|
|
1499
|
-
return new StructuredText(libmupdf._wasm_new_stext_page_from_page(this.pointer, STRING(options)));
|
|
1500
|
-
}
|
|
1501
|
-
getLinks() {
|
|
1502
|
-
let links = [];
|
|
1503
|
-
let link = libmupdf._wasm_load_links(this.pointer);
|
|
1504
|
-
while (link) {
|
|
1505
|
-
links.push(new Link(libmupdf._wasm_keep_link(link)));
|
|
1506
|
-
link = libmupdf._wasm_link_get_next(link);
|
|
1507
|
-
}
|
|
1508
|
-
return links;
|
|
1509
|
-
}
|
|
1510
|
-
createLink(bbox, uri) {
|
|
1511
|
-
checkRect(bbox);
|
|
1512
|
-
return new Link(libmupdf._wasm_create_link(this.pointer, RECT(bbox), STRING(uri)));
|
|
1513
|
-
}
|
|
1514
|
-
deleteLink(link) {
|
|
1515
|
-
checkType(link, Link);
|
|
1516
|
-
libmupdf._wasm_delete_link(this.pointer, link.pointer);
|
|
1517
|
-
}
|
|
1518
|
-
search(needle, max_hits = 500) {
|
|
1519
|
-
return runSearch(libmupdf._wasm_search_page, this.pointer, needle, max_hits);
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
Page._drop = libmupdf._wasm_drop_page;
|
|
1523
|
-
Page.BOXES = [
|
|
1524
|
-
"MediaBox",
|
|
1525
|
-
"CropBox",
|
|
1526
|
-
"BleedBox",
|
|
1527
|
-
"TrimBox",
|
|
1528
|
-
"ArtBox"
|
|
1529
|
-
];
|
|
1530
|
-
/* -------------------------------------------------------------------------- */
|
|
1531
|
-
class PDFDocument extends Document {
|
|
1532
|
-
constructor(arg1) {
|
|
1533
|
-
if (typeof arg1 === "undefined")
|
|
1534
|
-
super(libmupdf._wasm_pdf_create_document());
|
|
1535
|
-
else if (typeof arg1 === "number")
|
|
1536
|
-
super(arg1);
|
|
1537
|
-
else if (arg1 instanceof PDFDocument) {
|
|
1538
|
-
super(arg1.pointer);
|
|
1539
|
-
libmupdf._wasm_keep_document(this.pointer);
|
|
1540
|
-
}
|
|
1541
|
-
else {
|
|
1542
|
-
let doc = Document.openDocument(arg1, "application/pdf");
|
|
1543
|
-
if (doc instanceof PDFDocument)
|
|
1544
|
-
return doc;
|
|
1545
|
-
throw new Error("not a PDF document");
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
loadPage(index) {
|
|
1549
|
-
return super.loadPage(index);
|
|
1550
|
-
}
|
|
1551
|
-
// PDFObject instances are always bound to a document, so the WASM/JS value interface lives here.
|
|
1552
|
-
// Wrap a pdf_obj in a Userdata object. The pointer must be newly created or we already own it.
|
|
1553
|
-
_fromPDFObjectNew(ptr) {
|
|
1554
|
-
if (ptr === 0)
|
|
1555
|
-
return PDFObject.Null;
|
|
1556
|
-
return new PDFObject(this, ptr);
|
|
1557
|
-
}
|
|
1558
|
-
// Wrap a pdf_obj in a Userdata object. The pointer must be a borrowed pointer, so we have to take ownership.
|
|
1559
|
-
_fromPDFObjectKeep(ptr) {
|
|
1560
|
-
if (ptr === 0)
|
|
1561
|
-
return PDFObject.Null;
|
|
1562
|
-
return new PDFObject(this, libmupdf._wasm_pdf_keep_obj(ptr));
|
|
1563
|
-
}
|
|
1564
|
-
_toPDFObject(obj) {
|
|
1565
|
-
if (obj instanceof PDFObject)
|
|
1566
|
-
return obj;
|
|
1567
|
-
if (obj === null || obj === undefined)
|
|
1568
|
-
return this.newNull();
|
|
1569
|
-
if (typeof obj === "string") {
|
|
1570
|
-
// if a JS string is surrounded by parens, convert it to a PDF string
|
|
1571
|
-
if (obj.startsWith("(") && obj.endsWith(")"))
|
|
1572
|
-
return this.newString(obj.slice(1, -1));
|
|
1573
|
-
// otherwise treat it as a name
|
|
1574
|
-
return this.newName(obj);
|
|
1575
|
-
}
|
|
1576
|
-
if (typeof obj === "number") {
|
|
1577
|
-
if (obj === (obj | 0))
|
|
1578
|
-
return this.newInteger(obj);
|
|
1579
|
-
return this.newReal(obj);
|
|
1580
|
-
}
|
|
1581
|
-
if (typeof obj === "boolean")
|
|
1582
|
-
return this.newBoolean(obj);
|
|
1583
|
-
if (obj instanceof Array) {
|
|
1584
|
-
let result = this.newArray();
|
|
1585
|
-
for (let item of obj)
|
|
1586
|
-
result.push(item);
|
|
1587
|
-
return result;
|
|
1588
|
-
}
|
|
1589
|
-
if (obj instanceof Object) {
|
|
1590
|
-
let result = this.newDictionary();
|
|
1591
|
-
for (let key in obj)
|
|
1592
|
-
result.put(key, obj[key]);
|
|
1593
|
-
return result;
|
|
1594
|
-
}
|
|
1595
|
-
throw new TypeError("cannot convert value to PDFObject");
|
|
1596
|
-
}
|
|
1597
|
-
_PDFOBJ(obj) {
|
|
1598
|
-
// Note: We have to create a PDFObject instance for garbage collection.
|
|
1599
|
-
return this._toPDFObject(obj).pointer;
|
|
1600
|
-
}
|
|
1601
|
-
getVersion() {
|
|
1602
|
-
return libmupdf._wasm_pdf_version(this.pointer);
|
|
1603
|
-
}
|
|
1604
|
-
getLanguage() {
|
|
1605
|
-
return fromStringOrNull(libmupdf._wasm_pdf_document_language(this.pointer));
|
|
1606
|
-
}
|
|
1607
|
-
setLanguage(lang) {
|
|
1608
|
-
libmupdf._wasm_pdf_set_document_language(this.pointer, STRING(lang));
|
|
1609
|
-
}
|
|
1610
|
-
countObjects() {
|
|
1611
|
-
return libmupdf._wasm_pdf_xref_len(this.pointer);
|
|
1612
|
-
}
|
|
1613
|
-
getTrailer() {
|
|
1614
|
-
return new PDFObject(this, libmupdf._wasm_pdf_trailer(this.pointer));
|
|
1615
|
-
}
|
|
1616
|
-
createObject() {
|
|
1617
|
-
let num = libmupdf._wasm_pdf_create_object(this.pointer);
|
|
1618
|
-
return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_indirect(this.pointer, num));
|
|
1619
|
-
}
|
|
1620
|
-
newNull() { return PDFObject.Null; }
|
|
1621
|
-
newBoolean(v) { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_bool(v)); }
|
|
1622
|
-
newInteger(v) { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_int(v)); }
|
|
1623
|
-
newReal(v) { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_real(v)); }
|
|
1624
|
-
newName(v) { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_name(STRING(v))); }
|
|
1625
|
-
newString(v) { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_text_string(STRING(v))); }
|
|
1626
|
-
newByteString(v) {
|
|
1627
|
-
if (v instanceof Array)
|
|
1628
|
-
v = Uint8Array.from(v);
|
|
1629
|
-
checkType(v, Uint8Array);
|
|
1630
|
-
let len = v.byteLength;
|
|
1631
|
-
let ptr = Malloc(len);
|
|
1632
|
-
libmupdf.HEAPU8.set(v, ptr);
|
|
1633
|
-
try {
|
|
1634
|
-
return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_string(ptr, len));
|
|
1635
|
-
}
|
|
1636
|
-
finally {
|
|
1637
|
-
Free(ptr);
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
newIndirect(v) { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_indirect(this.pointer, v)); }
|
|
1641
|
-
newArray() { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_array(this.pointer)); }
|
|
1642
|
-
newDictionary() { return this._fromPDFObjectNew(libmupdf._wasm_pdf_new_dict(this.pointer)); }
|
|
1643
|
-
deleteObject(num) {
|
|
1644
|
-
if (num instanceof PDFObject)
|
|
1645
|
-
num = num.asIndirect();
|
|
1646
|
-
else
|
|
1647
|
-
checkType(num, "number");
|
|
1648
|
-
libmupdf._wasm_pdf_delete_object(this.pointer, num);
|
|
1649
|
-
}
|
|
1650
|
-
addObject(obj) {
|
|
1651
|
-
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_object(this.pointer, this._PDFOBJ(obj)));
|
|
1652
|
-
}
|
|
1653
|
-
addStream(buf, obj) {
|
|
1654
|
-
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_stream(this.pointer, BUFFER(buf), this._PDFOBJ(obj), 0));
|
|
1655
|
-
}
|
|
1656
|
-
addRawStream(buf, obj) {
|
|
1657
|
-
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_stream(this.pointer, BUFFER(buf), this._PDFOBJ(obj), 1));
|
|
1658
|
-
}
|
|
1659
|
-
newGraftMap() {
|
|
1660
|
-
return new PDFGraftMap(this, libmupdf._wasm_pdf_new_graft_map(this.pointer));
|
|
1661
|
-
}
|
|
1662
|
-
graftObject(obj) {
|
|
1663
|
-
checkType(obj, PDFObject);
|
|
1664
|
-
return this._fromPDFObjectNew(libmupdf._wasm_pdf_graft_object(this.pointer, obj.pointer));
|
|
1665
|
-
}
|
|
1666
|
-
graftPage(to, srcDoc, srcPage) {
|
|
1667
|
-
checkType(to, "number");
|
|
1668
|
-
checkType(srcDoc, PDFDocument);
|
|
1669
|
-
checkType(srcPage, "number");
|
|
1670
|
-
libmupdf._wasm_pdf_graft_page(this.pointer, to, srcDoc.pointer, srcPage);
|
|
1671
|
-
}
|
|
1672
|
-
addSimpleFont(font, encoding = "Latin") {
|
|
1673
|
-
checkType(font, Font);
|
|
1674
|
-
var encoding_ix = ENUM(encoding, Font.SIMPLE_ENCODING);
|
|
1675
|
-
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_simple_font(this.pointer, font.pointer, encoding_ix));
|
|
1676
|
-
}
|
|
1677
|
-
addCJKFont(font, lang, wmode = 0, serif = true) {
|
|
1678
|
-
checkType(font, Font);
|
|
1679
|
-
if (typeof lang === "string")
|
|
1680
|
-
lang = Font.CJK_ORDERING_BY_LANG[lang];
|
|
1681
|
-
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_cjk_font(this.pointer, font.pointer, lang, wmode, serif));
|
|
1682
|
-
}
|
|
1683
|
-
addFont(font) {
|
|
1684
|
-
checkType(font, Font);
|
|
1685
|
-
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_cid_font(this.pointer, font.pointer));
|
|
1686
|
-
}
|
|
1687
|
-
addImage(image) {
|
|
1688
|
-
checkType(image, Image);
|
|
1689
|
-
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_image(this.pointer, image.pointer));
|
|
1690
|
-
}
|
|
1691
|
-
loadImage(ref) {
|
|
1692
|
-
checkType(ref, PDFObject);
|
|
1693
|
-
return new Image(libmupdf._wasm_pdf_load_image(this.pointer, ref.pointer));
|
|
1694
|
-
}
|
|
1695
|
-
findPage(index) {
|
|
1696
|
-
checkType(index, "number");
|
|
1697
|
-
return this._fromPDFObjectKeep(libmupdf._wasm_pdf_lookup_page_obj(this.pointer, index));
|
|
1698
|
-
}
|
|
1699
|
-
addPage(mediabox, rotate, resources, contents) {
|
|
1700
|
-
checkRect(mediabox);
|
|
1701
|
-
checkType(rotate, "number");
|
|
1702
|
-
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_page(this.pointer, RECT(mediabox), rotate, this._PDFOBJ(resources), BUFFER(contents)));
|
|
1703
|
-
}
|
|
1704
|
-
insertPage(at, obj) {
|
|
1705
|
-
checkType(at, "number");
|
|
1706
|
-
libmupdf._wasm_pdf_insert_page(this.pointer, at, this._PDFOBJ(obj));
|
|
1707
|
-
}
|
|
1708
|
-
deletePage(at) {
|
|
1709
|
-
checkType(at, "number");
|
|
1710
|
-
libmupdf._wasm_pdf_delete_page(this.pointer, at);
|
|
1711
|
-
}
|
|
1712
|
-
isEmbeddedFile(ref) {
|
|
1713
|
-
checkType(ref, PDFObject);
|
|
1714
|
-
return !!libmupdf._wasm_pdf_is_embedded_file(ref.pointer);
|
|
1715
|
-
}
|
|
1716
|
-
addEmbeddedFile(filename, mimetype, contents, created, modified, checksum = false) {
|
|
1717
|
-
checkType(filename, "string");
|
|
1718
|
-
checkType(mimetype, "string");
|
|
1719
|
-
checkType(created, Date);
|
|
1720
|
-
checkType(modified, Date);
|
|
1721
|
-
checkType(checksum, "boolean");
|
|
1722
|
-
return this._fromPDFObjectNew(libmupdf._wasm_pdf_add_embedded_file(this.pointer, STRING(filename), STRING2(mimetype), BUFFER(contents), created.getTime() / 1000 | 0, modified.getTime() / 1000 | 0, checksum));
|
|
1723
|
-
}
|
|
1724
|
-
getFilespecParams(ref) {
|
|
1725
|
-
checkType(ref, PDFObject);
|
|
1726
|
-
let ptr = libmupdf._wasm_pdf_get_filespec_params(ref.pointer);
|
|
1727
|
-
return {
|
|
1728
|
-
filename: fromString$1(libmupdf._wasm_pdf_filespec_params_get_filename(ptr)),
|
|
1729
|
-
mimetype: fromString$1(libmupdf._wasm_pdf_filespec_params_get_mimetype(ptr)),
|
|
1730
|
-
size: libmupdf._wasm_pdf_filespec_params_get_filename(ptr),
|
|
1731
|
-
creationDate: new Date(libmupdf._wasm_pdf_filespec_params_get_created(ptr) * 1000),
|
|
1732
|
-
modificationDate: new Date(libmupdf._wasm_pdf_filespec_params_get_modified(ptr) * 1000),
|
|
1733
|
-
};
|
|
1734
|
-
}
|
|
1735
|
-
getEmbeddedFileContents(ref) {
|
|
1736
|
-
checkType(ref, PDFObject);
|
|
1737
|
-
let contents = libmupdf._wasm_pdf_load_embedded_file_contents(ref.pointer);
|
|
1738
|
-
if (contents)
|
|
1739
|
-
return new Buffer$1(contents);
|
|
1740
|
-
return null;
|
|
1741
|
-
}
|
|
1742
|
-
getEmbeddedFiles() {
|
|
1743
|
-
function _getEmbeddedFilesRec(result, N) {
|
|
1744
|
-
var i, n;
|
|
1745
|
-
if (N.isDictionary()) {
|
|
1746
|
-
var NN = N.get("Names");
|
|
1747
|
-
if (NN)
|
|
1748
|
-
for (i = 0, n = NN.length; i < n; i += 2)
|
|
1749
|
-
result[NN.get(i + 0).asString()] = NN.get(i + 1);
|
|
1750
|
-
var NK = N.get("Kids");
|
|
1751
|
-
if (NK)
|
|
1752
|
-
for (i = 0, n = NK.length; i < n; i += 1)
|
|
1753
|
-
_getEmbeddedFilesRec(result, NK.get(i));
|
|
1754
|
-
}
|
|
1755
|
-
return result;
|
|
1756
|
-
}
|
|
1757
|
-
return _getEmbeddedFilesRec({}, this.getTrailer().get("Root", "Names", "EmbeddedFiles"));
|
|
1758
|
-
}
|
|
1759
|
-
loadNameTree(treeName) {
|
|
1760
|
-
function _loadNameTreeRec(dict, node) {
|
|
1761
|
-
var kids = node.get("Kids");
|
|
1762
|
-
if (kids && kids.isArray())
|
|
1763
|
-
for (var i = 0; i < kids.length; i += 1)
|
|
1764
|
-
_loadNameTreeRec(dict, kids.get(i));
|
|
1765
|
-
var names = node.get("Names");
|
|
1766
|
-
if (names && names.isArray())
|
|
1767
|
-
for (var i = 0; i < names.length; i += 2)
|
|
1768
|
-
dict[names.get(i).asString()] = names.get(i + 1);
|
|
1769
|
-
}
|
|
1770
|
-
var node = this.getTrailer().get("Root").get("Names").get(treeName);
|
|
1771
|
-
var dict = {};
|
|
1772
|
-
if (node.isDictionary())
|
|
1773
|
-
_loadNameTreeRec(dict, node);
|
|
1774
|
-
return dict;
|
|
1775
|
-
}
|
|
1776
|
-
insertEmbeddedFile(filename, filespec) {
|
|
1777
|
-
var efs = this.getEmbeddedFiles();
|
|
1778
|
-
efs[filename] = filespec;
|
|
1779
|
-
this._rewriteEmbeddedFiles(efs);
|
|
1780
|
-
}
|
|
1781
|
-
deleteEmbeddedFile(filename) {
|
|
1782
|
-
var efs = this.getEmbeddedFiles();
|
|
1783
|
-
delete efs[filename];
|
|
1784
|
-
this._rewriteEmbeddedFiles(efs);
|
|
1785
|
-
}
|
|
1786
|
-
_rewriteEmbeddedFiles(efs) {
|
|
1787
|
-
var efs_keys = Object.keys(efs);
|
|
1788
|
-
efs_keys.sort();
|
|
1789
|
-
var root = this.getTrailer().get("Root");
|
|
1790
|
-
var root_names = root.get("Names");
|
|
1791
|
-
if (!root_names.isDictionary())
|
|
1792
|
-
root_names = root.put("Names", this.newDictionary());
|
|
1793
|
-
var root_names_efs = root_names.put("EmbeddedFiles", this.newDictionary());
|
|
1794
|
-
var root_names_efs_names = root_names_efs.put("Names", this.newArray());
|
|
1795
|
-
for (var key of efs_keys) {
|
|
1796
|
-
root_names_efs_names.push(this.newString(key));
|
|
1797
|
-
root_names_efs_names.push(efs[key]);
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
saveToBuffer(options = "") {
|
|
1801
|
-
var options_string;
|
|
1802
|
-
if (typeof options === "object") {
|
|
1803
|
-
options_string = Object.entries(options).map(kv => {
|
|
1804
|
-
var k = kv[0];
|
|
1805
|
-
var v = kv[1];
|
|
1806
|
-
if (v === true)
|
|
1807
|
-
return k + "=" + "yes";
|
|
1808
|
-
else if (v === false)
|
|
1809
|
-
return k + "=" + "no";
|
|
1810
|
-
else
|
|
1811
|
-
return k + "=" + String(v).replaceAll(",", ":");
|
|
1812
|
-
}).join(",");
|
|
1813
|
-
}
|
|
1814
|
-
else {
|
|
1815
|
-
options_string = options;
|
|
1816
|
-
}
|
|
1817
|
-
return new Buffer$1(libmupdf._wasm_pdf_write_document_buffer(this.pointer, STRING(options_string)));
|
|
1818
|
-
}
|
|
1819
|
-
save(filename, options = "") {
|
|
1820
|
-
if (node_fs)
|
|
1821
|
-
node_fs.writeFileSync(filename, this.saveToBuffer(options).asUint8Array());
|
|
1822
|
-
else
|
|
1823
|
-
throw new Error("missing 'fs' module");
|
|
1824
|
-
}
|
|
1825
|
-
setPageLabels(index, style = "D", prefix = "", start = 1) {
|
|
1826
|
-
libmupdf._wasm_pdf_set_page_labels(this.pointer, index, style.charCodeAt(0), STRING(prefix), start);
|
|
1827
|
-
}
|
|
1828
|
-
deletePageLabels(index) {
|
|
1829
|
-
libmupdf._wasm_pdf_delete_page_labels(this.pointer, index);
|
|
1830
|
-
}
|
|
1831
|
-
wasRepaired() {
|
|
1832
|
-
return !!libmupdf._wasm_pdf_was_repaired(this.pointer);
|
|
1833
|
-
}
|
|
1834
|
-
hasUnsavedChanges() {
|
|
1835
|
-
return !!libmupdf._wasm_pdf_has_unsaved_changes(this.pointer);
|
|
1836
|
-
}
|
|
1837
|
-
countVersions() {
|
|
1838
|
-
return libmupdf._wasm_pdf_count_versions(this.pointer);
|
|
1839
|
-
}
|
|
1840
|
-
countUnsavedVersions() {
|
|
1841
|
-
return libmupdf._wasm_pdf_count_unsaved_versions(this.pointer);
|
|
1842
|
-
}
|
|
1843
|
-
validateChangeHistory() {
|
|
1844
|
-
return libmupdf._wasm_pdf_validate_change_history(this.pointer);
|
|
1845
|
-
}
|
|
1846
|
-
canBeSavedIncrementally() {
|
|
1847
|
-
return !!libmupdf._wasm_pdf_can_be_saved_incrementally(this.pointer);
|
|
1848
|
-
}
|
|
1849
|
-
enableJournal() {
|
|
1850
|
-
libmupdf._wasm_pdf_enable_journal(this.pointer);
|
|
1851
|
-
}
|
|
1852
|
-
getJournal() {
|
|
1853
|
-
let position = libmupdf._wasm_pdf_undoredo_state_position(this.pointer);
|
|
1854
|
-
let n = libmupdf._wasm_pdf_undoredo_state_count(this.pointer);
|
|
1855
|
-
let steps = [];
|
|
1856
|
-
for (let i = 0; i < n; ++i)
|
|
1857
|
-
steps.push(fromString$1(libmupdf._wasm_pdf_undoredo_step(this.pointer, i)));
|
|
1858
|
-
return { position, steps };
|
|
1859
|
-
}
|
|
1860
|
-
beginOperation(op) {
|
|
1861
|
-
libmupdf._wasm_pdf_begin_operation(this.pointer, STRING(op));
|
|
1862
|
-
}
|
|
1863
|
-
beginImplicitOperation() {
|
|
1864
|
-
libmupdf._wasm_pdf_begin_implicit_operation(this.pointer);
|
|
1865
|
-
}
|
|
1866
|
-
endOperation() {
|
|
1867
|
-
libmupdf._wasm_pdf_end_operation(this.pointer);
|
|
1868
|
-
}
|
|
1869
|
-
abandonOperation() {
|
|
1870
|
-
libmupdf._wasm_pdf_abandon_operation(this.pointer);
|
|
1871
|
-
}
|
|
1872
|
-
canUndo() {
|
|
1873
|
-
return !!libmupdf._wasm_pdf_can_undo(this.pointer);
|
|
1874
|
-
}
|
|
1875
|
-
canRedo() {
|
|
1876
|
-
return !!libmupdf._wasm_pdf_can_redo(this.pointer);
|
|
1877
|
-
}
|
|
1878
|
-
undo() {
|
|
1879
|
-
libmupdf._wasm_pdf_undo(this.pointer);
|
|
1880
|
-
}
|
|
1881
|
-
redo() {
|
|
1882
|
-
libmupdf._wasm_pdf_redo(this.pointer);
|
|
1883
|
-
}
|
|
1884
|
-
isJSSupported() {
|
|
1885
|
-
return !!libmupdf._wasm_pdf_js_supported(this.pointer);
|
|
1886
|
-
}
|
|
1887
|
-
enableJS() {
|
|
1888
|
-
libmupdf._wasm_pdf_enable_js(this.pointer);
|
|
1889
|
-
}
|
|
1890
|
-
disableJS() {
|
|
1891
|
-
libmupdf._wasm_pdf_disable_js(this.pointer);
|
|
1892
|
-
}
|
|
1893
|
-
setJSEventListener(_listener) {
|
|
1894
|
-
throw "TODO";
|
|
1895
|
-
}
|
|
1896
|
-
rearrangePages(pages) {
|
|
1897
|
-
let n = pages.length;
|
|
1898
|
-
let ptr = Malloc(n << 2);
|
|
1899
|
-
for (let i = 0; i < n; ++i)
|
|
1900
|
-
libmupdf.HEAPU32[(ptr >> 2) + i] = pages[i] || 0;
|
|
1901
|
-
try {
|
|
1902
|
-
libmupdf._wasm_pdf_rearrange_pages(this.pointer, n, ptr);
|
|
1903
|
-
}
|
|
1904
|
-
finally {
|
|
1905
|
-
Free(ptr);
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
subsetFonts() {
|
|
1909
|
-
libmupdf._wasm_pdf_subset_fonts(this.pointer);
|
|
1910
|
-
}
|
|
1911
|
-
bake(bakeAnnots = true, bakeWidgets = true) {
|
|
1912
|
-
libmupdf._wasm_pdf_bake_document(this.pointer, bakeAnnots, bakeWidgets);
|
|
1913
|
-
}
|
|
1914
|
-
countLayers() {
|
|
1915
|
-
return libmupdf._wasm_pdf_count_layers(this.pointer);
|
|
1916
|
-
}
|
|
1917
|
-
isLayerVisible(layer) {
|
|
1918
|
-
return !!libmupdf._wasm_pdf_layer_is_enabled(this.pointer, layer);
|
|
1919
|
-
}
|
|
1920
|
-
setLayerVisible(layer, visible) {
|
|
1921
|
-
libmupdf._wasm_pdf_enable_layer(this.pointer, layer, Number(visible));
|
|
1922
|
-
}
|
|
1923
|
-
getLayerName(layer) {
|
|
1924
|
-
return fromString$1(libmupdf._wasm_pdf_layer_name(this.pointer, layer));
|
|
1925
|
-
}
|
|
1926
|
-
resetForm(fields, exclude) {
|
|
1927
|
-
libmupdf._wasm_pdf_reset_form(this.pointer, this._PDFOBJ(fields), Number(exclude));
|
|
1928
|
-
}
|
|
1929
|
-
}
|
|
1930
|
-
PDFDocument.PAGE_LABEL_NONE = "\0";
|
|
1931
|
-
PDFDocument.PAGE_LABEL_DECIMAL = "D";
|
|
1932
|
-
PDFDocument.PAGE_LABEL_ROMAN_UC = "R";
|
|
1933
|
-
PDFDocument.PAGE_LABEL_ROMAN_LC = "r";
|
|
1934
|
-
PDFDocument.PAGE_LABEL_ALPHA_UC = "A";
|
|
1935
|
-
PDFDocument.PAGE_LABEL_ALPHA_LC = "a";
|
|
1936
|
-
class PDFPage extends Page {
|
|
1937
|
-
// PRIVATE
|
|
1938
|
-
constructor(doc, pointer) {
|
|
1939
|
-
super(pointer);
|
|
1940
|
-
this._doc = doc;
|
|
1941
|
-
this._annots = null;
|
|
1942
|
-
this._widgets = null;
|
|
1943
|
-
}
|
|
1944
|
-
getObject() {
|
|
1945
|
-
return this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_page_get_obj(this.pointer));
|
|
1946
|
-
}
|
|
1947
|
-
getTransform() {
|
|
1948
|
-
return fromMatrix(libmupdf._wasm_pdf_page_transform(this.pointer));
|
|
1949
|
-
}
|
|
1950
|
-
setPageBox(box, rect) {
|
|
1951
|
-
let box_ix = ENUM(box, Page.BOXES);
|
|
1952
|
-
checkRect(rect);
|
|
1953
|
-
libmupdf._wasm_pdf_set_page_box(this.pointer, box_ix, RECT(rect));
|
|
1954
|
-
}
|
|
1955
|
-
toPixmap(matrix, colorspace, alpha = false, showExtras = true, usage = "View", box = "CropBox") {
|
|
1956
|
-
checkMatrix(matrix);
|
|
1957
|
-
checkType(colorspace, ColorSpace);
|
|
1958
|
-
let box_ix = ENUM(box, Page.BOXES);
|
|
1959
|
-
let result;
|
|
1960
|
-
if (showExtras)
|
|
1961
|
-
result = libmupdf._wasm_pdf_new_pixmap_from_page_with_usage(this.pointer, MATRIX(matrix), colorspace.pointer, alpha, STRING(usage), box_ix);
|
|
1962
|
-
else
|
|
1963
|
-
result = libmupdf._wasm_pdf_new_pixmap_from_page_contents_with_usage(this.pointer, MATRIX(matrix), colorspace.pointer, alpha, STRING(usage), box_ix);
|
|
1964
|
-
return new Pixmap(result);
|
|
1965
|
-
}
|
|
1966
|
-
getWidgets() {
|
|
1967
|
-
if (!this._widgets) {
|
|
1968
|
-
this._widgets = [];
|
|
1969
|
-
let widget = libmupdf._wasm_pdf_first_widget(this.pointer);
|
|
1970
|
-
while (widget) {
|
|
1971
|
-
this._widgets.push(new PDFWidget(this._doc, libmupdf._wasm_pdf_keep_annot(widget)));
|
|
1972
|
-
widget = libmupdf._wasm_pdf_next_widget(widget);
|
|
1973
|
-
}
|
|
1974
|
-
}
|
|
1975
|
-
return this._widgets;
|
|
1976
|
-
}
|
|
1977
|
-
getAnnotations() {
|
|
1978
|
-
if (!this._annots) {
|
|
1979
|
-
this._annots = [];
|
|
1980
|
-
let annot = libmupdf._wasm_pdf_first_annot(this.pointer);
|
|
1981
|
-
while (annot) {
|
|
1982
|
-
this._annots.push(new PDFAnnotation(this._doc, libmupdf._wasm_pdf_keep_annot(annot)));
|
|
1983
|
-
annot = libmupdf._wasm_pdf_next_annot(annot);
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
return this._annots;
|
|
1987
|
-
}
|
|
1988
|
-
createAnnotation(type) {
|
|
1989
|
-
let type_ix = ENUM(type, PDFAnnotation.ANNOT_TYPES);
|
|
1990
|
-
let annot = new PDFAnnotation(this._doc, libmupdf._wasm_pdf_create_annot(this.pointer, type_ix));
|
|
1991
|
-
if (this._annots)
|
|
1992
|
-
this._annots.push(annot);
|
|
1993
|
-
return annot;
|
|
1994
|
-
}
|
|
1995
|
-
deleteAnnotation(annot) {
|
|
1996
|
-
checkType(annot, PDFAnnotation);
|
|
1997
|
-
libmupdf._wasm_pdf_delete_annot(this.pointer, annot.pointer);
|
|
1998
|
-
if (this._annots) {
|
|
1999
|
-
let ix = this._annots.indexOf(annot);
|
|
2000
|
-
if (ix >= 0)
|
|
2001
|
-
this._annots.splice(ix, 1);
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
applyRedactions(black_boxes = true, image_method = 2, line_art_method = 1, text_method = 0) {
|
|
2005
|
-
libmupdf._wasm_pdf_redact_page(this.pointer, Number(black_boxes), image_method, line_art_method, text_method);
|
|
2006
|
-
}
|
|
2007
|
-
update() {
|
|
2008
|
-
return !!libmupdf._wasm_pdf_update_page(this.pointer);
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
|
-
PDFPage.REDACT_IMAGE_NONE = 0;
|
|
2012
|
-
PDFPage.REDACT_IMAGE_REMOVE = 1;
|
|
2013
|
-
PDFPage.REDACT_IMAGE_PIXELS = 2;
|
|
2014
|
-
PDFPage.REDACT_IMAGE_UNLESS_INVISIBLE = 3;
|
|
2015
|
-
PDFPage.REDACT_LINE_ART_NONE = 0;
|
|
2016
|
-
PDFPage.REDACT_LINE_ART_REMOVE_IF_COVERED = 1;
|
|
2017
|
-
PDFPage.REDACT_LINE_ART_REMOVE_IF_TOUCHED = 2;
|
|
2018
|
-
PDFPage.REDACT_TEXT_REMOVE = 0;
|
|
2019
|
-
PDFPage.REDACT_TEXT_NONE = 1;
|
|
2020
|
-
class PDFObject extends Userdata {
|
|
2021
|
-
// PRIVATE
|
|
2022
|
-
constructor(doc, pointer) {
|
|
2023
|
-
super(libmupdf._wasm_pdf_keep_obj(pointer));
|
|
2024
|
-
this._doc = doc;
|
|
2025
|
-
}
|
|
2026
|
-
isNull() { return this === PDFObject.Null; }
|
|
2027
|
-
isIndirect() { return !!libmupdf._wasm_pdf_is_indirect(this.pointer); }
|
|
2028
|
-
isBoolean() { return !!libmupdf._wasm_pdf_is_bool(this.pointer); }
|
|
2029
|
-
isInteger() { return !!libmupdf._wasm_pdf_is_int(this.pointer); }
|
|
2030
|
-
isReal() { return !!libmupdf._wasm_pdf_is_real(this.pointer); }
|
|
2031
|
-
isNumber() { return !!libmupdf._wasm_pdf_is_number(this.pointer); }
|
|
2032
|
-
isName() { return !!libmupdf._wasm_pdf_is_name(this.pointer); }
|
|
2033
|
-
isString() { return !!libmupdf._wasm_pdf_is_string(this.pointer); }
|
|
2034
|
-
isArray() { return !!libmupdf._wasm_pdf_is_array(this.pointer); }
|
|
2035
|
-
isDictionary() { return !!libmupdf._wasm_pdf_is_dict(this.pointer); }
|
|
2036
|
-
isStream() { return !!libmupdf._wasm_pdf_is_stream(this.pointer); }
|
|
2037
|
-
asIndirect() { return libmupdf._wasm_pdf_to_num(this.pointer); }
|
|
2038
|
-
asBoolean() { return !!libmupdf._wasm_pdf_to_bool(this.pointer); }
|
|
2039
|
-
asNumber() { return libmupdf._wasm_pdf_to_real(this.pointer); }
|
|
2040
|
-
asName() { return fromString$1(libmupdf._wasm_pdf_to_name(this.pointer)); }
|
|
2041
|
-
asString() { return fromString$1(libmupdf._wasm_pdf_to_text_string(this.pointer)); }
|
|
2042
|
-
asByteString() {
|
|
2043
|
-
let ptr = libmupdf._wasm_pdf_to_string(this.pointer, _wasm_int);
|
|
2044
|
-
let len = libmupdf.HEAPU32[_wasm_int >> 2];
|
|
2045
|
-
return libmupdf.HEAPU8.slice(ptr, ptr + len);
|
|
2046
|
-
}
|
|
2047
|
-
readStream() { return new Buffer$1(libmupdf._wasm_pdf_load_stream(this.pointer)); }
|
|
2048
|
-
readRawStream() { return new Buffer$1(libmupdf._wasm_pdf_load_raw_stream(this.pointer)); }
|
|
2049
|
-
writeObject(obj) {
|
|
2050
|
-
if (!this.isIndirect())
|
|
2051
|
-
throw new TypeError("can only call PDFObject.writeObject on an indirect reference");
|
|
2052
|
-
libmupdf._wasm_pdf_update_object(this._doc.pointer, this.asIndirect(), this._doc._PDFOBJ(obj));
|
|
2053
|
-
}
|
|
2054
|
-
writeStream(buf) {
|
|
2055
|
-
if (!this.isIndirect())
|
|
2056
|
-
throw new TypeError("can only call PDFObject.writeStream on an indirect reference");
|
|
2057
|
-
libmupdf._wasm_pdf_update_stream(this._doc.pointer, this.pointer, BUFFER(buf), 0);
|
|
2058
|
-
}
|
|
2059
|
-
writeRawStream(buf) {
|
|
2060
|
-
if (!this.isIndirect())
|
|
2061
|
-
throw new TypeError("can only call PDFObject.writeRawStream on an indirect reference");
|
|
2062
|
-
libmupdf._wasm_pdf_update_stream(this._doc.pointer, this.pointer, BUFFER(buf), 1);
|
|
2063
|
-
}
|
|
2064
|
-
resolve() {
|
|
2065
|
-
return this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_resolve_indirect(this.pointer));
|
|
2066
|
-
}
|
|
2067
|
-
get length() {
|
|
2068
|
-
return libmupdf._wasm_pdf_array_len(this.pointer);
|
|
2069
|
-
}
|
|
2070
|
-
set length(_) {
|
|
2071
|
-
throw new TypeError("object length is read-only");
|
|
2072
|
-
}
|
|
2073
|
-
_get(path) {
|
|
2074
|
-
let obj = this.pointer;
|
|
2075
|
-
for (let key of path) {
|
|
2076
|
-
if (typeof key === "number")
|
|
2077
|
-
obj = libmupdf._wasm_pdf_array_get(obj, key);
|
|
2078
|
-
else if (key instanceof PDFObject)
|
|
2079
|
-
obj = libmupdf._wasm_pdf_dict_get(obj, key.pointer);
|
|
2080
|
-
else
|
|
2081
|
-
obj = libmupdf._wasm_pdf_dict_gets(obj, STRING(key));
|
|
2082
|
-
if (obj === 0)
|
|
2083
|
-
break;
|
|
2084
|
-
}
|
|
2085
|
-
return obj;
|
|
2086
|
-
}
|
|
2087
|
-
get(...path) {
|
|
2088
|
-
return this._doc._fromPDFObjectKeep(this._get(path));
|
|
2089
|
-
}
|
|
2090
|
-
getInheritable(key) {
|
|
2091
|
-
if (key instanceof PDFObject)
|
|
2092
|
-
return this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_dict_get_inheritable(this.pointer, key.pointer));
|
|
2093
|
-
return this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_dict_gets_inheritable(this.pointer, STRING(key)));
|
|
2094
|
-
}
|
|
2095
|
-
put(key, value) {
|
|
2096
|
-
value = this._doc._toPDFObject(value);
|
|
2097
|
-
if (typeof key === "number")
|
|
2098
|
-
libmupdf._wasm_pdf_array_put(this.pointer, key, value.pointer);
|
|
2099
|
-
else if (key instanceof PDFObject)
|
|
2100
|
-
libmupdf._wasm_pdf_dict_put(this.pointer, key.pointer, value.pointer);
|
|
2101
|
-
else
|
|
2102
|
-
libmupdf._wasm_pdf_dict_puts(this.pointer, STRING(key), value.pointer);
|
|
2103
|
-
return value;
|
|
2104
|
-
}
|
|
2105
|
-
push(value) {
|
|
2106
|
-
value = this._doc._toPDFObject(value);
|
|
2107
|
-
libmupdf._wasm_pdf_array_push(this.pointer, value.pointer);
|
|
2108
|
-
return value;
|
|
2109
|
-
}
|
|
2110
|
-
delete(key) {
|
|
2111
|
-
if (typeof key === "number")
|
|
2112
|
-
libmupdf._wasm_pdf_array_delete(this.pointer, key);
|
|
2113
|
-
else if (key instanceof PDFObject)
|
|
2114
|
-
libmupdf._wasm_pdf_dict_del(this.pointer, key.pointer);
|
|
2115
|
-
else
|
|
2116
|
-
libmupdf._wasm_pdf_dict_dels(this.pointer, STRING(key));
|
|
2117
|
-
}
|
|
2118
|
-
valueOf() {
|
|
2119
|
-
if (this.isNull())
|
|
2120
|
-
return null;
|
|
2121
|
-
if (this.isBoolean())
|
|
2122
|
-
return this.asBoolean();
|
|
2123
|
-
if (this.isNumber())
|
|
2124
|
-
return this.asNumber();
|
|
2125
|
-
if (this.isName())
|
|
2126
|
-
return this.asName();
|
|
2127
|
-
if (this.isString())
|
|
2128
|
-
return this.asString();
|
|
2129
|
-
if (this.isIndirect())
|
|
2130
|
-
return `${this.asIndirect()} 0 R`;
|
|
2131
|
-
return this;
|
|
2132
|
-
}
|
|
2133
|
-
toString(tight = true, ascii = true) {
|
|
2134
|
-
return fromStringFree(libmupdf._wasm_pdf_sprint_obj(this.pointer, tight, ascii));
|
|
2135
|
-
}
|
|
2136
|
-
forEach(fn) {
|
|
2137
|
-
if (this.isArray()) {
|
|
2138
|
-
let n = this.length;
|
|
2139
|
-
for (let i = 0; i < n; ++i)
|
|
2140
|
-
fn(this.get(i), i, this);
|
|
2141
|
-
}
|
|
2142
|
-
else if (this.isDictionary()) {
|
|
2143
|
-
let n = libmupdf._wasm_pdf_dict_len(this.pointer);
|
|
2144
|
-
for (let i = 0; i < n; ++i) {
|
|
2145
|
-
let key = this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_dict_get_key(this.pointer, i));
|
|
2146
|
-
let val = this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_dict_get_val(this.pointer, i));
|
|
2147
|
-
fn(val, key.asName(), this);
|
|
2148
|
-
}
|
|
2149
|
-
}
|
|
2150
|
-
}
|
|
2151
|
-
// Convert to plain Javascript values, objects, and arrays.
|
|
2152
|
-
// If you want to resolve indirect references, pass an empty object or array as the first argument.
|
|
2153
|
-
// On exit, this object will contain all indirect objects encountered indexed by object number.
|
|
2154
|
-
// Note: This function will omit cyclic references.
|
|
2155
|
-
asJS(seen) {
|
|
2156
|
-
if (this.isIndirect()) {
|
|
2157
|
-
let ref = this.asIndirect();
|
|
2158
|
-
if (!seen)
|
|
2159
|
-
return `${ref} 0 R`;
|
|
2160
|
-
if (ref in seen)
|
|
2161
|
-
return seen[ref];
|
|
2162
|
-
seen[ref] = PDFObject.Null; // stop recursion!
|
|
2163
|
-
return seen[ref] = this.resolve().asJS(seen);
|
|
2164
|
-
}
|
|
2165
|
-
if (this.isArray()) {
|
|
2166
|
-
let result = [];
|
|
2167
|
-
this.forEach(val => {
|
|
2168
|
-
result.push(val.asJS(seen));
|
|
2169
|
-
});
|
|
2170
|
-
return result;
|
|
2171
|
-
}
|
|
2172
|
-
if (this.isDictionary()) {
|
|
2173
|
-
let result = {};
|
|
2174
|
-
this.forEach((val, key) => {
|
|
2175
|
-
result[key] = val.asJS(seen);
|
|
2176
|
-
});
|
|
2177
|
-
return result;
|
|
2178
|
-
}
|
|
2179
|
-
return this.valueOf();
|
|
2180
|
-
}
|
|
2181
|
-
}
|
|
2182
|
-
PDFObject._drop = libmupdf._wasm_pdf_drop_obj;
|
|
2183
|
-
PDFObject.Null = new PDFObject(null, 0);
|
|
2184
|
-
class PDFGraftMap extends Userdata {
|
|
2185
|
-
// PRIVATE
|
|
2186
|
-
constructor(doc, pointer) {
|
|
2187
|
-
super(pointer);
|
|
2188
|
-
this._doc = doc;
|
|
2189
|
-
}
|
|
2190
|
-
graftObject(obj) {
|
|
2191
|
-
checkType(obj, PDFObject);
|
|
2192
|
-
return this._doc._fromPDFObjectNew(libmupdf._wasm_pdf_graft_mapped_object(this.pointer, obj.pointer));
|
|
2193
|
-
}
|
|
2194
|
-
graftPage(to, srcDoc, srcPage) {
|
|
2195
|
-
checkType(to, "number");
|
|
2196
|
-
checkType(srcDoc, PDFDocument);
|
|
2197
|
-
checkType(srcPage, "number");
|
|
2198
|
-
libmupdf._wasm_pdf_graft_mapped_page(this.pointer, to, srcDoc.pointer, srcPage);
|
|
2199
|
-
}
|
|
2200
|
-
}
|
|
2201
|
-
PDFGraftMap._drop = libmupdf._wasm_pdf_drop_graft_map;
|
|
2202
|
-
class PDFAnnotation extends Userdata {
|
|
2203
|
-
// PRIVATE
|
|
2204
|
-
constructor(doc, pointer) {
|
|
2205
|
-
super(pointer);
|
|
2206
|
-
this._doc = doc;
|
|
2207
|
-
}
|
|
2208
|
-
getObject() {
|
|
2209
|
-
return this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_annot_obj(this.pointer));
|
|
2210
|
-
}
|
|
2211
|
-
getBounds() {
|
|
2212
|
-
return fromRect(libmupdf._wasm_pdf_bound_annot(this.pointer));
|
|
2213
|
-
}
|
|
2214
|
-
run(device, matrix) {
|
|
2215
|
-
checkType(device, Device);
|
|
2216
|
-
checkMatrix(matrix);
|
|
2217
|
-
libmupdf._wasm_pdf_run_annot(this.pointer, device.pointer, MATRIX(matrix));
|
|
2218
|
-
}
|
|
2219
|
-
toPixmap(matrix, colorspace, alpha = false) {
|
|
2220
|
-
checkMatrix(matrix);
|
|
2221
|
-
checkType(colorspace, ColorSpace);
|
|
2222
|
-
return new Pixmap(libmupdf._wasm_pdf_new_pixmap_from_annot(this.pointer, MATRIX(matrix), colorspace.pointer, alpha));
|
|
2223
|
-
}
|
|
2224
|
-
toDisplayList() {
|
|
2225
|
-
return new DisplayList(libmupdf._wasm_pdf_new_display_list_from_annot(this.pointer));
|
|
2226
|
-
}
|
|
2227
|
-
update() {
|
|
2228
|
-
return !!libmupdf._wasm_pdf_update_annot(this.pointer);
|
|
2229
|
-
}
|
|
2230
|
-
getType() {
|
|
2231
|
-
let type = libmupdf._wasm_pdf_annot_type(this.pointer);
|
|
2232
|
-
return PDFAnnotation.ANNOT_TYPES[type] || "Text";
|
|
2233
|
-
}
|
|
2234
|
-
getLanguage() {
|
|
2235
|
-
return fromStringOrNull(libmupdf._wasm_pdf_annot_language(this.pointer));
|
|
2236
|
-
}
|
|
2237
|
-
setLanguage(lang) {
|
|
2238
|
-
libmupdf._wasm_pdf_set_annot_language(this.pointer, STRING(lang));
|
|
2239
|
-
}
|
|
2240
|
-
getFlags() {
|
|
2241
|
-
return libmupdf._wasm_pdf_annot_flags(this.pointer);
|
|
2242
|
-
}
|
|
2243
|
-
setFlags(flags) {
|
|
2244
|
-
return libmupdf._wasm_pdf_set_annot_flags(this.pointer, flags);
|
|
2245
|
-
}
|
|
2246
|
-
getContents() {
|
|
2247
|
-
return fromString$1(libmupdf._wasm_pdf_annot_contents(this.pointer));
|
|
2248
|
-
}
|
|
2249
|
-
setContents(text) {
|
|
2250
|
-
libmupdf._wasm_pdf_set_annot_contents(this.pointer, STRING(text));
|
|
2251
|
-
}
|
|
2252
|
-
getAuthor() {
|
|
2253
|
-
return fromString$1(libmupdf._wasm_pdf_annot_author(this.pointer));
|
|
2254
|
-
}
|
|
2255
|
-
setAuthor(text) {
|
|
2256
|
-
libmupdf._wasm_pdf_set_annot_author(this.pointer, STRING(text));
|
|
2257
|
-
}
|
|
2258
|
-
getCreationDate() {
|
|
2259
|
-
return new Date(libmupdf._wasm_pdf_annot_creation_date(this.pointer) * 1000);
|
|
2260
|
-
}
|
|
2261
|
-
setCreationDate(date) {
|
|
2262
|
-
checkType(date, Date);
|
|
2263
|
-
libmupdf._wasm_pdf_set_annot_creation_date(this.pointer, date.getTime() / 1000);
|
|
2264
|
-
}
|
|
2265
|
-
getModificationDate() {
|
|
2266
|
-
return new Date(libmupdf._wasm_pdf_annot_modification_date(this.pointer) * 1000);
|
|
2267
|
-
}
|
|
2268
|
-
setModificationDate(date) {
|
|
2269
|
-
checkType(date, Date);
|
|
2270
|
-
libmupdf._wasm_pdf_set_annot_modification_date(this.pointer, date.getTime() / 1000);
|
|
2271
|
-
}
|
|
2272
|
-
hasRect() {
|
|
2273
|
-
return !!libmupdf._wasm_pdf_annot_has_rect(this.pointer);
|
|
2274
|
-
}
|
|
2275
|
-
hasInkList() {
|
|
2276
|
-
return !!libmupdf._wasm_pdf_annot_has_ink_list(this.pointer);
|
|
2277
|
-
}
|
|
2278
|
-
hasQuadPoints() {
|
|
2279
|
-
return !!libmupdf._wasm_pdf_annot_has_quad_points(this.pointer);
|
|
2280
|
-
}
|
|
2281
|
-
hasVertices() {
|
|
2282
|
-
return !!libmupdf._wasm_pdf_annot_has_vertices(this.pointer);
|
|
2283
|
-
}
|
|
2284
|
-
hasLine() {
|
|
2285
|
-
return !!libmupdf._wasm_pdf_annot_has_line(this.pointer);
|
|
2286
|
-
}
|
|
2287
|
-
hasInteriorColor() {
|
|
2288
|
-
return !!libmupdf._wasm_pdf_annot_has_interior_color(this.pointer);
|
|
2289
|
-
}
|
|
2290
|
-
hasLineEndingStyles() {
|
|
2291
|
-
return !!libmupdf._wasm_pdf_annot_has_line_ending_styles(this.pointer);
|
|
2292
|
-
}
|
|
2293
|
-
hasBorder() {
|
|
2294
|
-
return !!libmupdf._wasm_pdf_annot_has_border(this.pointer);
|
|
2295
|
-
}
|
|
2296
|
-
hasBorderEffect() {
|
|
2297
|
-
return !!libmupdf._wasm_pdf_annot_has_border_effect(this.pointer);
|
|
2298
|
-
}
|
|
2299
|
-
hasIcon() {
|
|
2300
|
-
return !!libmupdf._wasm_pdf_annot_has_icon_name(this.pointer);
|
|
2301
|
-
}
|
|
2302
|
-
hasOpen() {
|
|
2303
|
-
return !!libmupdf._wasm_pdf_annot_has_open(this.pointer);
|
|
2304
|
-
}
|
|
2305
|
-
hasAuthor() {
|
|
2306
|
-
return !!libmupdf._wasm_pdf_annot_has_author(this.pointer);
|
|
2307
|
-
}
|
|
2308
|
-
hasFilespec() {
|
|
2309
|
-
return !!libmupdf._wasm_pdf_annot_has_filespec(this.pointer);
|
|
2310
|
-
}
|
|
2311
|
-
hasCallout() {
|
|
2312
|
-
return !!libmupdf._wasm_pdf_annot_has_callout(this.pointer);
|
|
2313
|
-
}
|
|
2314
|
-
hasRichContents() {
|
|
2315
|
-
return !!libmupdf._wasm_pdf_annot_has_rich_contents(this.pointer);
|
|
2316
|
-
}
|
|
2317
|
-
getRect() {
|
|
2318
|
-
return fromRect(libmupdf._wasm_pdf_annot_rect(this.pointer));
|
|
2319
|
-
}
|
|
2320
|
-
setRect(rect) {
|
|
2321
|
-
checkRect(rect);
|
|
2322
|
-
libmupdf._wasm_pdf_set_annot_rect(this.pointer, RECT(rect));
|
|
2323
|
-
}
|
|
2324
|
-
getPopup() {
|
|
2325
|
-
return fromRect(libmupdf._wasm_pdf_annot_popup(this.pointer));
|
|
2326
|
-
}
|
|
2327
|
-
setPopup(rect) {
|
|
2328
|
-
checkRect(rect);
|
|
2329
|
-
libmupdf._wasm_pdf_set_annot_popup(this.pointer, RECT(rect));
|
|
2330
|
-
}
|
|
2331
|
-
getIsOpen() {
|
|
2332
|
-
return !!libmupdf._wasm_pdf_annot_is_open(this.pointer);
|
|
2333
|
-
}
|
|
2334
|
-
setIsOpen(isOpen) {
|
|
2335
|
-
checkType(isOpen, "boolean");
|
|
2336
|
-
libmupdf._wasm_pdf_set_annot_is_open(this.pointer, isOpen);
|
|
2337
|
-
}
|
|
2338
|
-
getHiddenForEditing() {
|
|
2339
|
-
return !!libmupdf._wasm_pdf_annot_hidden_for_editing(this.pointer);
|
|
2340
|
-
}
|
|
2341
|
-
setHiddenForEditing(isHidden) {
|
|
2342
|
-
checkType(isHidden, "boolean");
|
|
2343
|
-
libmupdf._wasm_pdf_set_annot_hidden_for_editing(this.pointer, isHidden);
|
|
2344
|
-
}
|
|
2345
|
-
getIcon() {
|
|
2346
|
-
return fromString$1(libmupdf._wasm_pdf_annot_icon_name(this.pointer));
|
|
2347
|
-
}
|
|
2348
|
-
setIcon(text) {
|
|
2349
|
-
checkType(text, "string");
|
|
2350
|
-
libmupdf._wasm_pdf_set_annot_icon_name(this.pointer, STRING(text));
|
|
2351
|
-
}
|
|
2352
|
-
getOpacity() {
|
|
2353
|
-
return libmupdf._wasm_pdf_annot_opacity(this.pointer);
|
|
2354
|
-
}
|
|
2355
|
-
setOpacity(opacity) {
|
|
2356
|
-
checkType(opacity, "number");
|
|
2357
|
-
libmupdf._wasm_pdf_set_annot_opacity(this.pointer, opacity);
|
|
2358
|
-
}
|
|
2359
|
-
getQuadding() {
|
|
2360
|
-
return libmupdf._wasm_pdf_annot_quadding(this.pointer);
|
|
2361
|
-
}
|
|
2362
|
-
setQuadding(quadding) {
|
|
2363
|
-
checkType(quadding, "number");
|
|
2364
|
-
libmupdf._wasm_pdf_set_annot_quadding(this.pointer, quadding);
|
|
2365
|
-
}
|
|
2366
|
-
getLine() {
|
|
2367
|
-
let a = fromPoint(libmupdf._wasm_pdf_annot_line_1(this.pointer));
|
|
2368
|
-
let b = fromPoint(libmupdf._wasm_pdf_annot_line_2(this.pointer));
|
|
2369
|
-
return [a, b];
|
|
2370
|
-
}
|
|
2371
|
-
setLine(a, b) {
|
|
2372
|
-
checkPoint(a);
|
|
2373
|
-
checkPoint(b);
|
|
2374
|
-
libmupdf._wasm_pdf_set_annot_line(this.pointer, POINT(a), POINT2(b));
|
|
2375
|
-
}
|
|
2376
|
-
getLineEndingStyles() {
|
|
2377
|
-
let a = libmupdf._wasm_pdf_annot_line_ending_styles_start(this.pointer);
|
|
2378
|
-
let b = libmupdf._wasm_pdf_annot_line_ending_styles_end(this.pointer);
|
|
2379
|
-
return {
|
|
2380
|
-
start: PDFAnnotation.LINE_ENDING[a] || "None",
|
|
2381
|
-
end: PDFAnnotation.LINE_ENDING[b] || "None",
|
|
2382
|
-
};
|
|
2383
|
-
}
|
|
2384
|
-
setLineEndingStyles(start, end) {
|
|
2385
|
-
let start_ix = ENUM(start, PDFAnnotation.LINE_ENDING);
|
|
2386
|
-
let end_ix = ENUM(end, PDFAnnotation.LINE_ENDING);
|
|
2387
|
-
libmupdf._wasm_pdf_set_annot_line_ending_styles(this.pointer, start_ix, end_ix);
|
|
2388
|
-
}
|
|
2389
|
-
getLineCaption() {
|
|
2390
|
-
return libmupdf._wasm_pdf_annot_line_caption(this.pointer);
|
|
2391
|
-
}
|
|
2392
|
-
setLineCaption(on) {
|
|
2393
|
-
return libmupdf._wasm_pdf_set_annot_line_caption(this.pointer, on);
|
|
2394
|
-
}
|
|
2395
|
-
getLineCaptionOffset() {
|
|
2396
|
-
return fromPoint(libmupdf._wasm_pdf_annot_line_caption_offset(this.pointer));
|
|
2397
|
-
}
|
|
2398
|
-
setLineCaptionOffset(p) {
|
|
2399
|
-
return libmupdf._wasm_pdf_set_annot_line_caption_offset(this.pointer, POINT(p));
|
|
2400
|
-
}
|
|
2401
|
-
getLineLeader() {
|
|
2402
|
-
return libmupdf._wasm_pdf_annot_line_leader(this.pointer);
|
|
2403
|
-
}
|
|
2404
|
-
getLineLeaderExtension() {
|
|
2405
|
-
return libmupdf._wasm_pdf_annot_line_leader_extension(this.pointer);
|
|
2406
|
-
}
|
|
2407
|
-
getLineLeaderOffset() {
|
|
2408
|
-
return libmupdf._wasm_pdf_annot_line_leader_offset(this.pointer);
|
|
2409
|
-
}
|
|
2410
|
-
setLineLeader(v) {
|
|
2411
|
-
return libmupdf._wasm_pdf_set_annot_line_leader(this.pointer, v);
|
|
2412
|
-
}
|
|
2413
|
-
setLineLeaderExtension(v) {
|
|
2414
|
-
return libmupdf._wasm_pdf_set_annot_line_leader_extension(this.pointer, v);
|
|
2415
|
-
}
|
|
2416
|
-
setLineLeaderOffset(v) {
|
|
2417
|
-
return libmupdf._wasm_pdf_set_annot_line_leader_offset(this.pointer, v);
|
|
2418
|
-
}
|
|
2419
|
-
getCalloutStyle() {
|
|
2420
|
-
let style = libmupdf._wasm_pdf_annot_callout_style(this.pointer);
|
|
2421
|
-
return PDFAnnotation.LINE_ENDING[style] || "None";
|
|
2422
|
-
}
|
|
2423
|
-
setCalloutStyle(style) {
|
|
2424
|
-
let style_ix = ENUM(style, PDFAnnotation.LINE_ENDING);
|
|
2425
|
-
libmupdf._wasm_pdf_set_annot_callout_style(this.pointer, style_ix);
|
|
2426
|
-
}
|
|
2427
|
-
getCalloutLine() {
|
|
2428
|
-
let n = libmupdf._wasm_pdf_annot_callout_line(this.pointer, (_wasm_point << 2));
|
|
2429
|
-
if (n == 3)
|
|
2430
|
-
return [
|
|
2431
|
-
fromPoint((_wasm_point + 0) << 2),
|
|
2432
|
-
fromPoint((_wasm_point + 1) << 2),
|
|
2433
|
-
fromPoint((_wasm_point + 2) << 2)
|
|
2434
|
-
];
|
|
2435
|
-
if (n == 2)
|
|
2436
|
-
return [
|
|
2437
|
-
fromPoint((_wasm_point + 0) << 2),
|
|
2438
|
-
fromPoint((_wasm_point + 1) << 2)
|
|
2439
|
-
];
|
|
2440
|
-
return null;
|
|
2441
|
-
}
|
|
2442
|
-
setCalloutLine(line) {
|
|
2443
|
-
let a = line[0] || [0, 0];
|
|
2444
|
-
let b = line[1] || [0, 0];
|
|
2445
|
-
let c = line[2] || [0, 0];
|
|
2446
|
-
libmupdf._wasm_pdf_set_annot_callout_line(this.pointer, line.length, POINT(a), POINT2(b), POINT3(c));
|
|
2447
|
-
}
|
|
2448
|
-
getCalloutPoint() {
|
|
2449
|
-
let line = this.getCalloutLine();
|
|
2450
|
-
if (line)
|
|
2451
|
-
return line[0];
|
|
2452
|
-
return undefined;
|
|
2453
|
-
}
|
|
2454
|
-
setCalloutPoint(p) {
|
|
2455
|
-
libmupdf._wasm_pdf_set_annot_callout_point(this.pointer, POINT(p));
|
|
2456
|
-
}
|
|
2457
|
-
getColor() {
|
|
2458
|
-
return fromAnnotColor(libmupdf._wasm_pdf_annot_color(this.pointer, COLOR()));
|
|
2459
|
-
}
|
|
2460
|
-
getInteriorColor() {
|
|
2461
|
-
return fromAnnotColor(libmupdf._wasm_pdf_annot_interior_color(this.pointer, COLOR()));
|
|
2462
|
-
}
|
|
2463
|
-
setColor(color) {
|
|
2464
|
-
checkAnnotColor(color);
|
|
2465
|
-
libmupdf._wasm_pdf_set_annot_color(this.pointer, color.length, COLOR(color));
|
|
2466
|
-
}
|
|
2467
|
-
setInteriorColor(color) {
|
|
2468
|
-
checkAnnotColor(color);
|
|
2469
|
-
libmupdf._wasm_pdf_set_annot_interior_color(this.pointer, color.length, COLOR(color));
|
|
2470
|
-
}
|
|
2471
|
-
getBorderWidth() {
|
|
2472
|
-
return libmupdf._wasm_pdf_annot_border_width(this.pointer);
|
|
2473
|
-
}
|
|
2474
|
-
setBorderWidth(value) {
|
|
2475
|
-
checkType(value, "number");
|
|
2476
|
-
return libmupdf._wasm_pdf_set_annot_border_width(this.pointer, value);
|
|
2477
|
-
}
|
|
2478
|
-
getBorderStyle() {
|
|
2479
|
-
return PDFAnnotation.BORDER_STYLE[libmupdf._wasm_pdf_annot_border_style(this.pointer)] || "Solid";
|
|
2480
|
-
}
|
|
2481
|
-
setBorderStyle(value) {
|
|
2482
|
-
let value_ix = ENUM(value, PDFAnnotation.BORDER_STYLE);
|
|
2483
|
-
return libmupdf._wasm_pdf_set_annot_border_style(this.pointer, value_ix);
|
|
2484
|
-
}
|
|
2485
|
-
getBorderEffect() {
|
|
2486
|
-
return PDFAnnotation.BORDER_EFFECT[libmupdf._wasm_pdf_annot_border_effect(this.pointer)] || "None";
|
|
2487
|
-
}
|
|
2488
|
-
setBorderEffect(value) {
|
|
2489
|
-
let value_ix = ENUM(value, PDFAnnotation.BORDER_EFFECT);
|
|
2490
|
-
return libmupdf._wasm_pdf_set_annot_border_effect(this.pointer, value_ix);
|
|
2491
|
-
}
|
|
2492
|
-
getBorderEffectIntensity() {
|
|
2493
|
-
return libmupdf._wasm_pdf_annot_border_effect_intensity(this.pointer);
|
|
2494
|
-
}
|
|
2495
|
-
setBorderEffectIntensity(value) {
|
|
2496
|
-
checkType(value, "number");
|
|
2497
|
-
return libmupdf._wasm_pdf_set_annot_border_effect_intensity(this.pointer, value);
|
|
2498
|
-
}
|
|
2499
|
-
getBorderDashCount() {
|
|
2500
|
-
return libmupdf._wasm_pdf_annot_border_dash_count(this.pointer);
|
|
2501
|
-
}
|
|
2502
|
-
getBorderDashItem(idx) {
|
|
2503
|
-
return libmupdf._wasm_pdf_annot_border_dash_item(this.pointer, idx);
|
|
2504
|
-
}
|
|
2505
|
-
clearBorderDash() {
|
|
2506
|
-
libmupdf._wasm_pdf_clear_annot_border_dash(this.pointer);
|
|
2507
|
-
}
|
|
2508
|
-
addBorderDashItem(v) {
|
|
2509
|
-
checkType(v, "number");
|
|
2510
|
-
return libmupdf._wasm_pdf_add_annot_border_dash_item(this.pointer, v);
|
|
2511
|
-
}
|
|
2512
|
-
getBorderDashPattern() {
|
|
2513
|
-
let n = this.getBorderDashCount();
|
|
2514
|
-
let result = new Array(n);
|
|
2515
|
-
for (let i = 0; i < n; ++i)
|
|
2516
|
-
result[i] = this.getBorderDashItem(i);
|
|
2517
|
-
return result;
|
|
2518
|
-
}
|
|
2519
|
-
setBorderDashPattern(list) {
|
|
2520
|
-
this.clearBorderDash();
|
|
2521
|
-
for (let v of list)
|
|
2522
|
-
this.addBorderDashItem(v);
|
|
2523
|
-
}
|
|
2524
|
-
getIntent() {
|
|
2525
|
-
return PDFAnnotation.INTENT[libmupdf._wasm_pdf_annot_intent(this.pointer)] || null;
|
|
2526
|
-
}
|
|
2527
|
-
setIntent(value) {
|
|
2528
|
-
let value_ix = ENUM(value, PDFAnnotation.INTENT);
|
|
2529
|
-
return libmupdf._wasm_pdf_set_annot_intent(this.pointer, value_ix);
|
|
2530
|
-
}
|
|
2531
|
-
setDefaultAppearance(fontName, size, color) {
|
|
2532
|
-
checkType(fontName, "string");
|
|
2533
|
-
checkType(size, "number");
|
|
2534
|
-
checkAnnotColor(color);
|
|
2535
|
-
libmupdf._wasm_pdf_set_annot_default_appearance(this.pointer, STRING(fontName), size, color.length, COLOR(color));
|
|
2536
|
-
}
|
|
2537
|
-
getDefaultAppearance() {
|
|
2538
|
-
let font = fromString$1(libmupdf._wasm_pdf_annot_default_appearance_font(this.pointer));
|
|
2539
|
-
let size = libmupdf._wasm_pdf_annot_default_appearance_size(this.pointer);
|
|
2540
|
-
let color = fromAnnotColor(libmupdf._wasm_pdf_annot_default_appearance_color(this.pointer, COLOR()));
|
|
2541
|
-
return { font, size, color };
|
|
2542
|
-
}
|
|
2543
|
-
getFileSpec() {
|
|
2544
|
-
return this._doc._fromPDFObjectKeep(libmupdf._wasm_pdf_annot_filespec(this.pointer));
|
|
2545
|
-
}
|
|
2546
|
-
setFileSpec(fs) {
|
|
2547
|
-
return libmupdf._wasm_pdf_set_annot_filespec(this.pointer, this._doc._PDFOBJ(fs));
|
|
2548
|
-
}
|
|
2549
|
-
getQuadPoints() {
|
|
2550
|
-
let n = libmupdf._wasm_pdf_annot_quad_point_count(this.pointer);
|
|
2551
|
-
let result = [];
|
|
2552
|
-
for (let i = 0; i < n; ++i)
|
|
2553
|
-
result.push(fromQuad(libmupdf._wasm_pdf_annot_quad_point(this.pointer, i)));
|
|
2554
|
-
return result;
|
|
2555
|
-
}
|
|
2556
|
-
clearQuadPoints() {
|
|
2557
|
-
libmupdf._wasm_pdf_clear_annot_quad_points(this.pointer);
|
|
2558
|
-
}
|
|
2559
|
-
addQuadPoint(quad) {
|
|
2560
|
-
checkQuad(quad);
|
|
2561
|
-
libmupdf._wasm_pdf_add_annot_quad_point(this.pointer, QUAD(quad));
|
|
2562
|
-
}
|
|
2563
|
-
setQuadPoints(quadlist) {
|
|
2564
|
-
this.clearQuadPoints();
|
|
2565
|
-
for (let quad of quadlist)
|
|
2566
|
-
this.addQuadPoint(quad);
|
|
2567
|
-
}
|
|
2568
|
-
getVertices() {
|
|
2569
|
-
let n = libmupdf._wasm_pdf_annot_vertex_count(this.pointer);
|
|
2570
|
-
let result = new Array(n);
|
|
2571
|
-
for (let i = 0; i < n; ++i)
|
|
2572
|
-
result[i] = fromPoint(libmupdf._wasm_pdf_annot_vertex(this.pointer, i));
|
|
2573
|
-
return result;
|
|
2574
|
-
}
|
|
2575
|
-
clearVertices() {
|
|
2576
|
-
libmupdf._wasm_pdf_clear_annot_vertices(this.pointer);
|
|
2577
|
-
}
|
|
2578
|
-
addVertex(vertex) {
|
|
2579
|
-
checkPoint(vertex);
|
|
2580
|
-
libmupdf._wasm_pdf_add_annot_vertex(this.pointer, POINT(vertex));
|
|
2581
|
-
}
|
|
2582
|
-
setVertices(vertexlist) {
|
|
2583
|
-
this.clearVertices();
|
|
2584
|
-
for (let vertex of vertexlist)
|
|
2585
|
-
this.addVertex(vertex);
|
|
2586
|
-
}
|
|
2587
|
-
getInkList() {
|
|
2588
|
-
let n = libmupdf._wasm_pdf_annot_ink_list_count(this.pointer);
|
|
2589
|
-
let outer = [];
|
|
2590
|
-
for (let i = 0; i < n; ++i) {
|
|
2591
|
-
let m = libmupdf._wasm_pdf_annot_ink_list_stroke_count(this.pointer, i);
|
|
2592
|
-
let inner = new Array(m);
|
|
2593
|
-
for (let k = 0; k < m; ++k)
|
|
2594
|
-
inner[k] = fromPoint(libmupdf._wasm_pdf_annot_ink_list_stroke_vertex(this.pointer, i, k));
|
|
2595
|
-
outer.push(inner);
|
|
2596
|
-
}
|
|
2597
|
-
return outer;
|
|
2598
|
-
}
|
|
2599
|
-
clearInkList() {
|
|
2600
|
-
libmupdf._wasm_pdf_clear_annot_ink_list(this.pointer);
|
|
2601
|
-
}
|
|
2602
|
-
addInkListStroke() {
|
|
2603
|
-
libmupdf._wasm_pdf_add_annot_ink_list_stroke(this.pointer);
|
|
2604
|
-
}
|
|
2605
|
-
addInkListStrokeVertex(v) {
|
|
2606
|
-
checkPoint(v);
|
|
2607
|
-
libmupdf._wasm_pdf_add_annot_ink_list_stroke_vertex(this.pointer, POINT(v));
|
|
2608
|
-
}
|
|
2609
|
-
setInkList(inklist) {
|
|
2610
|
-
this.clearInkList();
|
|
2611
|
-
for (let stroke of inklist) {
|
|
2612
|
-
this.addInkListStroke();
|
|
2613
|
-
for (let vertex of stroke)
|
|
2614
|
-
this.addInkListStrokeVertex(vertex);
|
|
2615
|
-
}
|
|
2616
|
-
}
|
|
2617
|
-
getRichContents() {
|
|
2618
|
-
return fromString$1(libmupdf._wasm_pdf_annot_rich_contents(this.pointer));
|
|
2619
|
-
}
|
|
2620
|
-
setRichContents(plain, html) {
|
|
2621
|
-
checkType(plain, "string");
|
|
2622
|
-
checkType(html, "string");
|
|
2623
|
-
libmupdf._wasm_pdf_set_annot_rich_contents(this.pointer, STRING(plain), STRING2(html));
|
|
2624
|
-
}
|
|
2625
|
-
getRichDefaults() {
|
|
2626
|
-
return fromString$1(libmupdf._wasm_pdf_annot_rich_defaults(this.pointer));
|
|
2627
|
-
}
|
|
2628
|
-
setRichDefaults(style) {
|
|
2629
|
-
checkType(style, "string");
|
|
2630
|
-
libmupdf._wasm_pdf_set_annot_rich_defaults(this.pointer, STRING(style));
|
|
2631
|
-
}
|
|
2632
|
-
setStampImage(image) {
|
|
2633
|
-
libmupdf._wasm_pdf_set_annot_stamp_image(this.pointer, image.pointer);
|
|
2634
|
-
}
|
|
2635
|
-
setAppearanceFromDisplayList(appearance, state, transform, list) {
|
|
2636
|
-
checkMatrix(transform);
|
|
2637
|
-
checkType(list, DisplayList);
|
|
2638
|
-
libmupdf._wasm_pdf_set_annot_appearance_from_display_list(this.pointer, STRING_OPT(appearance), STRING2_OPT(state), MATRIX(transform), list.pointer);
|
|
2639
|
-
}
|
|
2640
|
-
setAppearance(appearance, state, transform, bbox, resources, contents) {
|
|
2641
|
-
checkMatrix(transform);
|
|
2642
|
-
checkRect(bbox);
|
|
2643
|
-
libmupdf._wasm_pdf_set_annot_appearance(this.pointer, STRING_OPT(appearance), STRING2_OPT(state), MATRIX(transform), RECT(bbox), this._doc._PDFOBJ(resources), BUFFER(contents));
|
|
2644
|
-
}
|
|
2645
|
-
applyRedaction(black_boxes = 1, image_method = 2, line_art_method = 1, text_method = 0) {
|
|
2646
|
-
libmupdf._wasm_pdf_apply_redaction(this.pointer, black_boxes, image_method, line_art_method, text_method);
|
|
2647
|
-
}
|
|
2648
|
-
}
|
|
2649
|
-
PDFAnnotation._drop = libmupdf._wasm_pdf_drop_annot;
|
|
2650
|
-
/* IMPORTANT: Keep in sync with mupdf/pdf/annot.h and PDFAnnotation.java */
|
|
2651
|
-
PDFAnnotation.ANNOT_TYPES = [
|
|
2652
|
-
"Text",
|
|
2653
|
-
"Link",
|
|
2654
|
-
"FreeText",
|
|
2655
|
-
"Line",
|
|
2656
|
-
"Square",
|
|
2657
|
-
"Circle",
|
|
2658
|
-
"Polygon",
|
|
2659
|
-
"PolyLine",
|
|
2660
|
-
"Highlight",
|
|
2661
|
-
"Underline",
|
|
2662
|
-
"Squiggly",
|
|
2663
|
-
"StrikeOut",
|
|
2664
|
-
"Redact",
|
|
2665
|
-
"Stamp",
|
|
2666
|
-
"Caret",
|
|
2667
|
-
"Ink",
|
|
2668
|
-
"Popup",
|
|
2669
|
-
"FileAttachment",
|
|
2670
|
-
"Sound",
|
|
2671
|
-
"Movie",
|
|
2672
|
-
"RichMedia",
|
|
2673
|
-
"Widget",
|
|
2674
|
-
"Screen",
|
|
2675
|
-
"PrinterMark",
|
|
2676
|
-
"TrapNet",
|
|
2677
|
-
"Watermark",
|
|
2678
|
-
"3D",
|
|
2679
|
-
"Projection",
|
|
2680
|
-
];
|
|
2681
|
-
PDFAnnotation.LINE_ENDING = [
|
|
2682
|
-
"None",
|
|
2683
|
-
"Square",
|
|
2684
|
-
"Circle",
|
|
2685
|
-
"Diamond",
|
|
2686
|
-
"OpenArrow",
|
|
2687
|
-
"ClosedArrow",
|
|
2688
|
-
"Butt",
|
|
2689
|
-
"ROpenArrow",
|
|
2690
|
-
"RClosedArrow",
|
|
2691
|
-
"Slash",
|
|
2692
|
-
];
|
|
2693
|
-
PDFAnnotation.BORDER_STYLE = ["Solid", "Dashed", "Beveled", "Inset", "Underline"];
|
|
2694
|
-
PDFAnnotation.BORDER_EFFECT = ["None", "Cloudy"];
|
|
2695
|
-
PDFAnnotation.INTENT = [
|
|
2696
|
-
null,
|
|
2697
|
-
"FreeTextCallout",
|
|
2698
|
-
"FreeTextTypeWriter",
|
|
2699
|
-
"LineArrow",
|
|
2700
|
-
"LineDimension",
|
|
2701
|
-
"PloyLine",
|
|
2702
|
-
"PolygonCloud",
|
|
2703
|
-
"PolygonDimension",
|
|
2704
|
-
"StampImage",
|
|
2705
|
-
"StampSnapshot"
|
|
2706
|
-
];
|
|
2707
|
-
// Bit masks for getFlags and setFlags
|
|
2708
|
-
PDFAnnotation.IS_INVISIBLE = 1 << (1 - 1);
|
|
2709
|
-
PDFAnnotation.IS_HIDDEN = 1 << (2 - 1);
|
|
2710
|
-
PDFAnnotation.IS_PRINT = 1 << (3 - 1);
|
|
2711
|
-
PDFAnnotation.IS_NO_ZOOM = 1 << (4 - 1);
|
|
2712
|
-
PDFAnnotation.IS_NO_ROTATE = 1 << (5 - 1);
|
|
2713
|
-
PDFAnnotation.IS_NO_VIEW = 1 << (6 - 1);
|
|
2714
|
-
PDFAnnotation.IS_READ_ONLY = 1 << (7 - 1);
|
|
2715
|
-
PDFAnnotation.IS_LOCKED = 1 << (8 - 1);
|
|
2716
|
-
PDFAnnotation.IS_TOGGLE_NO_VIEW = 1 << (9 - 1);
|
|
2717
|
-
PDFAnnotation.IS_LOCKED_CONTENTS = 1 << (10 - 1);
|
|
2718
|
-
class PDFWidget extends PDFAnnotation {
|
|
2719
|
-
getFieldType() {
|
|
2720
|
-
return PDFWidget.WIDGET_TYPES[libmupdf._wasm_pdf_annot_field_type(this.pointer)] || "button";
|
|
2721
|
-
}
|
|
2722
|
-
isButton() {
|
|
2723
|
-
let type = this.getFieldType();
|
|
2724
|
-
return type === "button" || type === "checkbox" || type === "radiobutton";
|
|
2725
|
-
}
|
|
2726
|
-
isPushButton() {
|
|
2727
|
-
return this.getFieldType() === "button";
|
|
2728
|
-
}
|
|
2729
|
-
isCheckbox() {
|
|
2730
|
-
return this.getFieldType() === "checkbox";
|
|
2731
|
-
}
|
|
2732
|
-
isRadioButton() {
|
|
2733
|
-
return this.getFieldType() === "radiobutton";
|
|
2734
|
-
}
|
|
2735
|
-
isText() {
|
|
2736
|
-
return this.getFieldType() === "text";
|
|
2737
|
-
}
|
|
2738
|
-
isChoice() {
|
|
2739
|
-
let type = this.getFieldType();
|
|
2740
|
-
return type === "combobox" || type === "listbox";
|
|
2741
|
-
}
|
|
2742
|
-
isListBox() {
|
|
2743
|
-
return this.getFieldType() === "listbox";
|
|
2744
|
-
}
|
|
2745
|
-
isComboBox() {
|
|
2746
|
-
return this.getFieldType() === "combobox";
|
|
2747
|
-
}
|
|
2748
|
-
getFieldFlags() {
|
|
2749
|
-
return libmupdf._wasm_pdf_annot_field_flags(this.pointer);
|
|
2750
|
-
}
|
|
2751
|
-
isMultiline() {
|
|
2752
|
-
return (this.getFieldFlags() & PDFWidget.TX_FIELD_IS_MULTILINE) !== 0;
|
|
2753
|
-
}
|
|
2754
|
-
isPassword() {
|
|
2755
|
-
return (this.getFieldFlags() & PDFWidget.TX_FIELD_IS_PASSWORD) !== 0;
|
|
2756
|
-
}
|
|
2757
|
-
isComb() {
|
|
2758
|
-
return (this.getFieldFlags() & PDFWidget.TX_FIELD_IS_COMB) !== 0;
|
|
2759
|
-
}
|
|
2760
|
-
isReadOnly() {
|
|
2761
|
-
return (this.getFieldFlags() & PDFWidget.FIELD_IS_READ_ONLY) !== 0;
|
|
2762
|
-
}
|
|
2763
|
-
getLabel() {
|
|
2764
|
-
return fromString$1(libmupdf._wasm_pdf_annot_field_label(this.pointer));
|
|
2765
|
-
}
|
|
2766
|
-
getName() {
|
|
2767
|
-
return fromStringFree(libmupdf._wasm_pdf_load_field_name(this.pointer));
|
|
2768
|
-
}
|
|
2769
|
-
getValue() {
|
|
2770
|
-
return fromString$1(libmupdf._wasm_pdf_annot_field_value(this.pointer));
|
|
2771
|
-
}
|
|
2772
|
-
setTextValue(value) {
|
|
2773
|
-
return libmupdf._wasm_pdf_set_annot_text_field_value(this.pointer, STRING(value));
|
|
2774
|
-
}
|
|
2775
|
-
getMaxLen() {
|
|
2776
|
-
return libmupdf._wasm_pdf_annot_text_widget_max_len(this.pointer);
|
|
2777
|
-
}
|
|
2778
|
-
setChoiceValue(value) {
|
|
2779
|
-
return libmupdf._wasm_pdf_set_annot_choice_field_value(this.pointer, STRING(value));
|
|
2780
|
-
}
|
|
2781
|
-
getOptions(isExport = false) {
|
|
2782
|
-
let result = [];
|
|
2783
|
-
let n = libmupdf._wasm_pdf_annot_choice_field_option_count(this.pointer);
|
|
2784
|
-
for (let i = 0; i < n; ++i) {
|
|
2785
|
-
result.push(fromString$1(libmupdf._wasm_pdf_annot_choice_field_option(this.pointer, isExport, i)));
|
|
2786
|
-
}
|
|
2787
|
-
return result;
|
|
2788
|
-
}
|
|
2789
|
-
toggle() {
|
|
2790
|
-
return libmupdf._wasm_pdf_toggle_widget(this.pointer);
|
|
2791
|
-
}
|
|
2792
|
-
}
|
|
2793
|
-
/* IMPORTANT: Keep in sync with mupdf/pdf/widget.h and PDFWidget.java */
|
|
2794
|
-
PDFWidget.WIDGET_TYPES = [
|
|
2795
|
-
"widget", // unknown
|
|
2796
|
-
"button",
|
|
2797
|
-
"checkbox",
|
|
2798
|
-
"combobox",
|
|
2799
|
-
"listbox",
|
|
2800
|
-
"radiobutton",
|
|
2801
|
-
"signature",
|
|
2802
|
-
"text",
|
|
2803
|
-
];
|
|
2804
|
-
/* Field flags */
|
|
2805
|
-
PDFWidget.FIELD_IS_READ_ONLY = 1;
|
|
2806
|
-
PDFWidget.FIELD_IS_REQUIRED = 1 << 1;
|
|
2807
|
-
PDFWidget.FIELD_IS_NO_EXPORT = 1 << 2;
|
|
2808
|
-
/* Text fields */
|
|
2809
|
-
PDFWidget.TX_FIELD_IS_MULTILINE = 1 << 12;
|
|
2810
|
-
PDFWidget.TX_FIELD_IS_PASSWORD = 1 << 13;
|
|
2811
|
-
PDFWidget.TX_FIELD_IS_COMB = 1 << 24;
|
|
2812
|
-
/* Button fields */
|
|
2813
|
-
PDFWidget.BTN_FIELD_IS_NO_TOGGLE_TO_OFF = 1 << 14;
|
|
2814
|
-
PDFWidget.BTN_FIELD_IS_RADIO = 1 << 15;
|
|
2815
|
-
PDFWidget.BTN_FIELD_IS_PUSHBUTTON = 1 << 16;
|
|
2816
|
-
/* Choice fields */
|
|
2817
|
-
PDFWidget.CH_FIELD_IS_COMBO = 1 << 17;
|
|
2818
|
-
PDFWidget.CH_FIELD_IS_EDIT = 1 << 18;
|
|
2819
|
-
PDFWidget.CH_FIELD_IS_SORT = 1 << 19;
|
|
2820
|
-
PDFWidget.CH_FIELD_IS_MULTI_SELECT = 1 << 21;
|
|
2821
|
-
var $libmupdf_stm_id = 0;
|
|
2822
|
-
var $libmupdf_stm_table = new Map();
|
|
2823
|
-
globalThis.$libmupdf_stm_close = function (id) {
|
|
2824
|
-
let handle = $libmupdf_stm_table.get(id);
|
|
2825
|
-
if (handle) {
|
|
2826
|
-
handle.close();
|
|
2827
|
-
$libmupdf_stm_table.delete(id);
|
|
2828
|
-
return;
|
|
2829
|
-
}
|
|
2830
|
-
throw new Error("invalid file handle");
|
|
2831
|
-
};
|
|
2832
|
-
globalThis.$libmupdf_stm_seek = function (id, pos, offset, whence) {
|
|
2833
|
-
let handle = $libmupdf_stm_table.get(id);
|
|
2834
|
-
if (handle) {
|
|
2835
|
-
if (whence === 0)
|
|
2836
|
-
return offset;
|
|
2837
|
-
if (whence === 1)
|
|
2838
|
-
return pos + offset;
|
|
2839
|
-
if (whence === 2) {
|
|
2840
|
-
let size = handle.fileSize();
|
|
2841
|
-
if (size < 0)
|
|
2842
|
-
return -1;
|
|
2843
|
-
return size + offset;
|
|
2844
|
-
}
|
|
2845
|
-
throw new Error("invalid whence argument");
|
|
2846
|
-
}
|
|
2847
|
-
throw new Error("invalid file handle");
|
|
2848
|
-
};
|
|
2849
|
-
globalThis.$libmupdf_stm_read = function (id, pos, addr, size) {
|
|
2850
|
-
let handle = $libmupdf_stm_table.get(id);
|
|
2851
|
-
if (handle) {
|
|
2852
|
-
return handle.read(libmupdf.HEAPU8, addr, size, pos);
|
|
2853
|
-
}
|
|
2854
|
-
throw new Error("invalid file handle");
|
|
2855
|
-
};
|
|
2856
|
-
class Stream extends Userdata {
|
|
2857
|
-
constructor(handle) {
|
|
2858
|
-
let id = $libmupdf_stm_id++;
|
|
2859
|
-
$libmupdf_stm_table.set(id, handle);
|
|
2860
|
-
super(libmupdf._wasm_new_stream(id));
|
|
2861
|
-
}
|
|
2862
|
-
}
|
|
2863
|
-
Stream._drop = libmupdf._wasm_drop_stream;
|
|
2864
|
-
globalThis.$libmupdf_load_font_file = function (name, script, bold, italic) {
|
|
2865
|
-
return 0;
|
|
2866
|
-
};
|
|
2867
|
-
var $libmupdf_device_id = 0;
|
|
2868
|
-
var $libmupdf_device_table = new Map();
|
|
2869
|
-
var $libmupdf_path_id = 0;
|
|
2870
|
-
var $libmupdf_path_table = new Map();
|
|
2871
|
-
var $libmupdf_text_id = 0;
|
|
2872
|
-
var $libmupdf_text_table = new Map();
|
|
2873
|
-
globalThis.$libmupdf_path_walk = {
|
|
2874
|
-
moveto(id, x, y) {
|
|
2875
|
-
$libmupdf_path_table.get(id)?.moveTo?.(x, y);
|
|
2876
|
-
},
|
|
2877
|
-
lineto(id, x, y) {
|
|
2878
|
-
$libmupdf_path_table.get(id)?.lineTo?.(x, y);
|
|
2879
|
-
},
|
|
2880
|
-
curveto(id, x1, y1, x2, y2, x3, y3) {
|
|
2881
|
-
$libmupdf_path_table.get(id)?.curveTo?.(x1, y1, x2, y2, x3, y3);
|
|
2882
|
-
},
|
|
2883
|
-
closepath(id) {
|
|
2884
|
-
$libmupdf_path_table.get(id)?.closePath?.();
|
|
2885
|
-
},
|
|
2886
|
-
};
|
|
2887
|
-
var $libmupdf_text_font = null;
|
|
2888
|
-
globalThis.$libmupdf_text_walk = {
|
|
2889
|
-
begin_span(id, font, trm, wmode, bidi, dir, lang) {
|
|
2890
|
-
if (font !== $libmupdf_text_font?.pointer)
|
|
2891
|
-
$libmupdf_text_font = new Font(font);
|
|
2892
|
-
$libmupdf_text_table.get(id)?.beginSpan?.($libmupdf_text_font, fromMatrix(trm), wmode, bidi, dir, fromString$1(lang));
|
|
2893
|
-
},
|
|
2894
|
-
end_span(id) {
|
|
2895
|
-
$libmupdf_text_table.get(id)?.endSpan?.();
|
|
2896
|
-
},
|
|
2897
|
-
show_glyph(id, font, trm, glyph, unicode, wmode, bidi) {
|
|
2898
|
-
if (font !== $libmupdf_text_font?.pointer)
|
|
2899
|
-
$libmupdf_text_font = new Font(font);
|
|
2900
|
-
$libmupdf_text_table.get(id)?.showGlyph?.($libmupdf_text_font, fromMatrix(trm), glyph, unicode, wmode, bidi);
|
|
2901
|
-
},
|
|
2902
|
-
};
|
|
2903
|
-
globalThis.$libmupdf_device = {
|
|
2904
|
-
drop_device(id) {
|
|
2905
|
-
$libmupdf_device_table.get(id)?.drop?.();
|
|
2906
|
-
$libmupdf_device_table.delete(id);
|
|
2907
|
-
},
|
|
2908
|
-
close_device(id) {
|
|
2909
|
-
$libmupdf_device_table.get(id)?.close?.();
|
|
2910
|
-
},
|
|
2911
|
-
fill_path(id, path, even_odd, ctm, colorspace, color_n, color_arr, alpha) {
|
|
2912
|
-
$libmupdf_device_table.get(id)?.fillPath?.(new Path(path), !!even_odd, fromMatrix(ctm), new ColorSpace(colorspace), fromColorArray(color_n, color_arr), alpha);
|
|
2913
|
-
},
|
|
2914
|
-
clip_path(id, path, even_odd, ctm) {
|
|
2915
|
-
$libmupdf_device_table.get(id)?.clipPath?.(new Path(path), !!even_odd, fromMatrix(ctm));
|
|
2916
|
-
},
|
|
2917
|
-
stroke_path(id, path, stroke, ctm, colorspace, color_n, color_arr, alpha) {
|
|
2918
|
-
$libmupdf_device_table.get(id)?.strokePath?.(new Path(path), new StrokeState(stroke), fromMatrix(ctm), new ColorSpace(colorspace), fromColorArray(color_n, color_arr), alpha);
|
|
2919
|
-
},
|
|
2920
|
-
clip_stroke_path(id, path, stroke, ctm) {
|
|
2921
|
-
$libmupdf_device_table.get(id)?.clipStrokePath?.(new Path(path), new StrokeState(stroke), fromMatrix(ctm));
|
|
2922
|
-
},
|
|
2923
|
-
fill_text(id, text, ctm, colorspace, color_n, color_arr, alpha) {
|
|
2924
|
-
$libmupdf_device_table.get(id)?.fillText?.(new Text(text), fromMatrix(ctm), new ColorSpace(colorspace), fromColorArray(color_n, color_arr), alpha);
|
|
2925
|
-
},
|
|
2926
|
-
stroke_text(id, text, stroke, ctm, colorspace, color_n, color_arr, alpha) {
|
|
2927
|
-
$libmupdf_device_table.get(id)?.strokeText?.(new Text(text), new StrokeState(stroke), fromMatrix(ctm), new ColorSpace(colorspace), fromColorArray(color_n, color_arr), alpha);
|
|
2928
|
-
},
|
|
2929
|
-
clip_text(id, text, ctm) {
|
|
2930
|
-
$libmupdf_device_table.get(id)?.clipText?.(new Text(text), fromMatrix(ctm));
|
|
2931
|
-
},
|
|
2932
|
-
clip_stroke_text(id, text, stroke, ctm) {
|
|
2933
|
-
$libmupdf_device_table.get(id)?.clipStrokeText?.(new Text(text), new StrokeState(stroke), fromMatrix(ctm));
|
|
2934
|
-
},
|
|
2935
|
-
ignore_text(id, text, ctm) {
|
|
2936
|
-
$libmupdf_device_table.get(id)?.ignoreText?.(new Text(text), fromMatrix(ctm));
|
|
2937
|
-
},
|
|
2938
|
-
fill_shade(id, shade, ctm, alpha) {
|
|
2939
|
-
$libmupdf_device_table.get(id)?.fillShade?.(new Shade(shade), fromMatrix(ctm), alpha);
|
|
2940
|
-
},
|
|
2941
|
-
fill_image(id, image, ctm, alpha) {
|
|
2942
|
-
$libmupdf_device_table.get(id)?.fillImage?.(new Image(image), fromMatrix(ctm), alpha);
|
|
2943
|
-
},
|
|
2944
|
-
fill_image_mask(id, image, ctm, colorspace, color_n, color_arr, alpha) {
|
|
2945
|
-
$libmupdf_device_table.get(id)?.fillImageMask?.(new Image(image), fromMatrix(ctm), new ColorSpace(colorspace), fromColorArray(color_n, color_arr), alpha);
|
|
2946
|
-
},
|
|
2947
|
-
clip_image_mask(id, image, ctm) {
|
|
2948
|
-
$libmupdf_device_table.get(id)?.clipImageMask?.(new Image(image), fromMatrix(ctm));
|
|
2949
|
-
},
|
|
2950
|
-
pop_clip(id) {
|
|
2951
|
-
$libmupdf_device_table.get(id)?.popClip?.();
|
|
2952
|
-
},
|
|
2953
|
-
begin_mask(id, bbox, luminosity, colorspace, color_n, color_arr) {
|
|
2954
|
-
$libmupdf_device_table.get(id)?.beginMask?.(fromRect(bbox), !!luminosity, new ColorSpace(colorspace), fromColorArray(color_n, color_arr));
|
|
2955
|
-
},
|
|
2956
|
-
begin_group(id, bbox, colorspace, isolated, knockout, blendmode, alpha) {
|
|
2957
|
-
$libmupdf_device_table.get(id)?.beginGroup?.(fromRect(bbox), new ColorSpace(colorspace), !!isolated, !!knockout, Device.BLEND_MODES[blendmode], alpha);
|
|
2958
|
-
},
|
|
2959
|
-
begin_tile(id, area, view, xstep, ystep, ctm, tile_id) {
|
|
2960
|
-
return $libmupdf_device_table.get(id)?.beginTile?.(fromRect(area), fromRect(view), xstep, ystep, fromMatrix(ctm), tile_id) || 0;
|
|
2961
|
-
},
|
|
2962
|
-
begin_layer(id, name) {
|
|
2963
|
-
$libmupdf_device_table.get(id)?.beginLayer?.(fromString$1(name));
|
|
2964
|
-
},
|
|
2965
|
-
end_mask(id) {
|
|
2966
|
-
$libmupdf_device_table.get(id)?.endMask?.();
|
|
2967
|
-
},
|
|
2968
|
-
end_group(id) {
|
|
2969
|
-
$libmupdf_device_table.get(id)?.endGroup?.();
|
|
2970
|
-
},
|
|
2971
|
-
end_tile(id) {
|
|
2972
|
-
$libmupdf_device_table.get(id)?.endTile?.();
|
|
2973
|
-
},
|
|
2974
|
-
end_layer(id) {
|
|
2975
|
-
$libmupdf_device_table.get(id)?.endLayer?.();
|
|
2976
|
-
},
|
|
2977
|
-
};
|
|
2978
|
-
|
|
2979
1
|
var commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function getAugmentedNamespace(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype;}else i={};return Object.defineProperty(i,"__esModule",{value:true}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:true,get:function(){return e[t]}});})),i}"undefined"==typeof self&&"object"==typeof commonjsGlobal&&(commonjsGlobal.self=commonjsGlobal);var global$1="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},lookup=[],revLookup=[],Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,inited=false;function init(){inited=true;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)lookup[t]=e[t],revLookup[e.charCodeAt(t)]=t;revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;}function toByteArray(e){var t,i,r,n,a,o;inited||init();var s=e.length;if(s%4>0)throw new Error("Invalid string. Length must be a multiple of 4");a="="===e[s-2]?2:"="===e[s-1]?1:0,o=new Arr(3*s/4-a),r=a>0?s-4:s;var l=0;for(t=0,i=0;t<r;t+=4,i+=3)n=revLookup[e.charCodeAt(t)]<<18|revLookup[e.charCodeAt(t+1)]<<12|revLookup[e.charCodeAt(t+2)]<<6|revLookup[e.charCodeAt(t+3)],o[l++]=n>>16&255,o[l++]=n>>8&255,o[l++]=255&n;return 2===a?(n=revLookup[e.charCodeAt(t)]<<2|revLookup[e.charCodeAt(t+1)]>>4,o[l++]=255&n):1===a&&(n=revLookup[e.charCodeAt(t)]<<10|revLookup[e.charCodeAt(t+1)]<<4|revLookup[e.charCodeAt(t+2)]>>2,o[l++]=n>>8&255,o[l++]=255&n),o}function tripletToBase64(e){return lookup[e>>18&63]+lookup[e>>12&63]+lookup[e>>6&63]+lookup[63&e]}function encodeChunk(e,t,i){for(var r,n=[],a=t;a<i;a+=3)r=(e[a]<<16)+(e[a+1]<<8)+e[a+2],n.push(tripletToBase64(r));return n.join("")}function fromByteArray(e){var t;inited||init();for(var i=e.length,r=i%3,n="",a=[],o=16383,s=0,l=i-r;s<l;s+=o)a.push(encodeChunk(e,s,s+o>l?l:s+o));return 1===r?(t=e[i-1],n+=lookup[t>>2],n+=lookup[t<<4&63],n+="=="):2===r&&(t=(e[i-2]<<8)+e[i-1],n+=lookup[t>>10],n+=lookup[t>>4&63],n+=lookup[t<<2&63],n+="="),a.push(n),a.join("")}function read(e,t,i,r,n){var a,o,s=8*n-r-1,l=(1<<s)-1,u=l>>1,h=-7,c=i?n-1:0,f=i?-1:1,d=e[t+c];for(c+=f,a=d&(1<<-h)-1,d>>=-h,h+=s;h>0;a=256*a+e[t+c],c+=f,h-=8);for(o=a&(1<<-h)-1,a>>=-h,h+=r;h>0;o=256*o+e[t+c],c+=f,h-=8);if(0===a)a=1-u;else {if(a===l)return o?NaN:1/0*(d?-1:1);o+=Math.pow(2,r),a-=u;}return (d?-1:1)*o*Math.pow(2,a-r)}function write(e,t,i,r,n,a){var o,s,l,u=8*a-n-1,h=(1<<u)-1,c=h>>1,f=23===n?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:a-1,p=r?1:-1,m=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(s=isNaN(t)?1:0,o=h):(o=Math.floor(Math.log(t)/Math.LN2),t*(l=Math.pow(2,-o))<1&&(o--,l*=2),(t+=o+c>=1?f/l:f*Math.pow(2,1-c))*l>=2&&(o++,l/=2),o+c>=h?(s=0,o=h):o+c>=1?(s=(t*l-1)*Math.pow(2,n),o+=c):(s=t*Math.pow(2,c-1)*Math.pow(2,n),o=0));n>=8;e[i+d]=255&s,d+=p,s/=256,n-=8);for(o=o<<n|s,u+=n;u>0;e[i+d]=255&o,d+=p,o/=256,u-=8);e[i+d-p]|=128*m;}var toString={}.toString,isArray=Array.isArray||function(e){return "[object Array]"==toString.call(e)},INSPECT_MAX_BYTES=50;function kMaxLength(){return Buffer.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function createBuffer(e,t){if(kMaxLength()<t)throw new RangeError("Invalid typed array length");return Buffer.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=Buffer.prototype:(null===e&&(e=new Buffer(t)),e.length=t),e}function Buffer(e,t,i){if(!(Buffer.TYPED_ARRAY_SUPPORT||this instanceof Buffer))return new Buffer(e,t,i);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return allocUnsafe(this,e)}return from(this,e,t,i)}function from(e,t,i,r){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return "undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?fromArrayBuffer(e,t,i,r):"string"==typeof t?fromString(e,t,i):fromObject(e,t)}function assertSize(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function alloc(e,t,i,r){return assertSize(t),t<=0?createBuffer(e,t):void 0!==i?"string"==typeof r?createBuffer(e,t).fill(i,r):createBuffer(e,t).fill(i):createBuffer(e,t)}function allocUnsafe(e,t){if(assertSize(t),e=createBuffer(e,t<0?0:0|checked(t)),!Buffer.TYPED_ARRAY_SUPPORT)for(var i=0;i<t;++i)e[i]=0;return e}function fromString(e,t,i){if("string"==typeof i&&""!==i||(i="utf8"),!Buffer.isEncoding(i))throw new TypeError('"encoding" must be a valid string encoding');var r=0|byteLength(t,i),n=(e=createBuffer(e,r)).write(t,i);return n!==r&&(e=e.slice(0,n)),e}function fromArrayLike(e,t){var i=t.length<0?0:0|checked(t.length);e=createBuffer(e,i);for(var r=0;r<i;r+=1)e[r]=255&t[r];return e}function fromArrayBuffer(e,t,i,r){if(t.byteLength,i<0||t.byteLength<i)throw new RangeError("'offset' is out of bounds");if(t.byteLength<i+(r||0))throw new RangeError("'length' is out of bounds");return t=void 0===i&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,i):new Uint8Array(t,i,r),Buffer.TYPED_ARRAY_SUPPORT?(e=t).__proto__=Buffer.prototype:e=fromArrayLike(e,t),e}function fromObject(e,t){if(internalIsBuffer(t)){var i=0|checked(t.length);return 0===(e=createBuffer(e,i)).length||t.copy(e,0,0,i),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return "number"!=typeof t.length||isnan(t.length)?createBuffer(e,0):fromArrayLike(e,t);if("Buffer"===t.type&&isArray(t.data))return fromArrayLike(e,t.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function checked(e){if(e>=kMaxLength())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+kMaxLength().toString(16)+" bytes");return 0|e}function internalIsBuffer(e){return !(null==e||!e._isBuffer)}function byteLength(e,t){if(internalIsBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var i=e.length;if(0===i)return 0;for(var r=false;;)switch(t){case "ascii":case "latin1":case "binary":return i;case "utf8":case "utf-8":case void 0:return utf8ToBytes(e).length;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return 2*i;case "hex":return i>>>1;case "base64":return base64ToBytes(e).length;default:if(r)return utf8ToBytes(e).length;t=(""+t).toLowerCase(),r=true;}}function slowToString(e,t,i){var r=false;if((void 0===t||t<0)&&(t=0),t>this.length)return "";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return "";if((i>>>=0)<=(t>>>=0))return "";for(e||(e="utf8");;)switch(e){case "hex":return hexSlice(this,t,i);case "utf8":case "utf-8":return utf8Slice(this,t,i);case "ascii":return asciiSlice(this,t,i);case "latin1":case "binary":return latin1Slice(this,t,i);case "base64":return base64Slice(this,t,i);case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return utf16leSlice(this,t,i);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=true;}}function swap(e,t,i){var r=e[t];e[t]=e[i],e[i]=r;}function bidirectionalIndexOf(e,t,i,r,n){if(0===e.length)return -1;if("string"==typeof i?(r=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=n?0:e.length-1),i<0&&(i=e.length+i),i>=e.length){if(n)return -1;i=e.length-1;}else if(i<0){if(!n)return -1;i=0;}if("string"==typeof t&&(t=Buffer.from(t,r)),internalIsBuffer(t))return 0===t.length?-1:arrayIndexOf(e,t,i,r,n);if("number"==typeof t)return t&=255,Buffer.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?n?Uint8Array.prototype.indexOf.call(e,t,i):Uint8Array.prototype.lastIndexOf.call(e,t,i):arrayIndexOf(e,[t],i,r,n);throw new TypeError("val must be string, number or Buffer")}function arrayIndexOf(e,t,i,r,n){var a,o=1,s=e.length,l=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return -1;o=2,s/=2,l/=2,i/=2;}function u(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(n){var h=-1;for(a=i;a<s;a++)if(u(e,a)===u(t,-1===h?0:a-h)){if(-1===h&&(h=a),a-h+1===l)return h*o}else -1!==h&&(a-=a-h),h=-1;}else for(i+l>s&&(i=s-l),a=i;a>=0;a--){for(var c=true,f=0;f<l;f++)if(u(e,a+f)!==u(t,f)){c=false;break}if(c)return a}return -1}function hexWrite(e,t,i,r){i=Number(i)||0;var n=e.length-i;r?(r=Number(r))>n&&(r=n):r=n;var a=t.length;if(a%2!=0)throw new TypeError("Invalid hex string");r>a/2&&(r=a/2);for(var o=0;o<r;++o){var s=parseInt(t.substr(2*o,2),16);if(isNaN(s))return o;e[i+o]=s;}return o}function utf8Write(e,t,i,r){return blitBuffer(utf8ToBytes(t,e.length-i),e,i,r)}function asciiWrite(e,t,i,r){return blitBuffer(asciiToBytes(t),e,i,r)}function latin1Write(e,t,i,r){return asciiWrite(e,t,i,r)}function base64Write(e,t,i,r){return blitBuffer(base64ToBytes(t),e,i,r)}function ucs2Write(e,t,i,r){return blitBuffer(utf16leToBytes(t,e.length-i),e,i,r)}function base64Slice(e,t,i){return 0===t&&i===e.length?fromByteArray(e):fromByteArray(e.slice(t,i))}function utf8Slice(e,t,i){i=Math.min(e.length,i);for(var r=[],n=t;n<i;){var a,o,s,l,u=e[n],h=null,c=u>239?4:u>223?3:u>191?2:1;if(n+c<=i)switch(c){case 1:u<128&&(h=u);break;case 2:128==(192&(a=e[n+1]))&&(l=(31&u)<<6|63&a)>127&&(h=l);break;case 3:a=e[n+1],o=e[n+2],128==(192&a)&&128==(192&o)&&(l=(15&u)<<12|(63&a)<<6|63&o)>2047&&(l<55296||l>57343)&&(h=l);break;case 4:a=e[n+1],o=e[n+2],s=e[n+3],128==(192&a)&&128==(192&o)&&128==(192&s)&&(l=(15&u)<<18|(63&a)<<12|(63&o)<<6|63&s)>65535&&l<1114112&&(h=l);}null===h?(h=65533,c=1):h>65535&&(h-=65536,r.push(h>>>10&1023|55296),h=56320|1023&h),r.push(h),n+=c;}return decodeCodePointsArray(r)}Buffer.TYPED_ARRAY_SUPPORT=void 0===global$1.TYPED_ARRAY_SUPPORT||global$1.TYPED_ARRAY_SUPPORT,kMaxLength(),Buffer.poolSize=8192,Buffer._augment=function(e){return e.__proto__=Buffer.prototype,e},Buffer.from=function(e,t,i){return from(null,e,t,i)},Buffer.TYPED_ARRAY_SUPPORT&&(Buffer.prototype.__proto__=Uint8Array.prototype,Buffer.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&Buffer[Symbol.species]),Buffer.alloc=function(e,t,i){return alloc(null,e,t,i)},Buffer.allocUnsafe=function(e){return allocUnsafe(null,e)},Buffer.allocUnsafeSlow=function(e){return allocUnsafe(null,e)},Buffer.isBuffer=isBuffer,Buffer.compare=function(e,t){if(!internalIsBuffer(e)||!internalIsBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var i=e.length,r=t.length,n=0,a=Math.min(i,r);n<a;++n)if(e[n]!==t[n]){i=e[n],r=t[n];break}return i<r?-1:r<i?1:0},Buffer.isEncoding=function(e){switch(String(e).toLowerCase()){case "hex":case "utf8":case "utf-8":case "ascii":case "latin1":case "binary":case "base64":case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return true;default:return false}},Buffer.concat=function(e,t){if(!isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return Buffer.alloc(0);var i;if(void 0===t)for(t=0,i=0;i<e.length;++i)t+=e[i].length;var r=Buffer.allocUnsafe(t),n=0;for(i=0;i<e.length;++i){var a=e[i];if(!internalIsBuffer(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(r,n),n+=a.length;}return r},Buffer.byteLength=byteLength,Buffer.prototype._isBuffer=true,Buffer.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)swap(this,t,t+1);return this},Buffer.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)swap(this,t,t+3),swap(this,t+1,t+2);return this},Buffer.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)swap(this,t,t+7),swap(this,t+1,t+6),swap(this,t+2,t+5),swap(this,t+3,t+4);return this},Buffer.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?utf8Slice(this,0,e):slowToString.apply(this,arguments)},Buffer.prototype.equals=function(e){if(!internalIsBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===Buffer.compare(this,e)},Buffer.prototype.inspect=function(){var e="",t=INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,t).match(/.{2}/g).join(" "),this.length>t&&(e+=" ... ")),"<Buffer "+e+">"},Buffer.prototype.compare=function(e,t,i,r,n){if(!internalIsBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===i&&(i=e?e.length:0),void 0===r&&(r=0),void 0===n&&(n=this.length),t<0||i>e.length||r<0||n>this.length)throw new RangeError("out of range index");if(r>=n&&t>=i)return 0;if(r>=n)return -1;if(t>=i)return 1;if(this===e)return 0;for(var a=(n>>>=0)-(r>>>=0),o=(i>>>=0)-(t>>>=0),s=Math.min(a,o),l=this.slice(r,n),u=e.slice(t,i),h=0;h<s;++h)if(l[h]!==u[h]){a=l[h],o=u[h];break}return a<o?-1:o<a?1:0},Buffer.prototype.includes=function(e,t,i){return -1!==this.indexOf(e,t,i)},Buffer.prototype.indexOf=function(e,t,i){return bidirectionalIndexOf(this,e,t,i,true)},Buffer.prototype.lastIndexOf=function(e,t,i){return bidirectionalIndexOf(this,e,t,i,false)},Buffer.prototype.write=function(e,t,i,r){if(void 0===t)r="utf8",i=this.length,t=0;else if(void 0===i&&"string"==typeof t)r=t,i=this.length,t=0;else {if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(i)?(i|=0,void 0===r&&(r="utf8")):(r=i,i=void 0);}var n=this.length-t;if((void 0===i||i>n)&&(i=n),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var a=false;;)switch(r){case "hex":return hexWrite(this,e,t,i);case "utf8":case "utf-8":return utf8Write(this,e,t,i);case "ascii":return asciiWrite(this,e,t,i);case "latin1":case "binary":return latin1Write(this,e,t,i);case "base64":return base64Write(this,e,t,i);case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return ucs2Write(this,e,t,i);default:if(a)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),a=true;}},Buffer.prototype.toJSON=function(){return {type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var MAX_ARGUMENTS_LENGTH=4096;function decodeCodePointsArray(e){var t=e.length;if(t<=MAX_ARGUMENTS_LENGTH)return String.fromCharCode.apply(String,e);for(var i="",r=0;r<t;)i+=String.fromCharCode.apply(String,e.slice(r,r+=MAX_ARGUMENTS_LENGTH));return i}function asciiSlice(e,t,i){var r="";i=Math.min(e.length,i);for(var n=t;n<i;++n)r+=String.fromCharCode(127&e[n]);return r}function latin1Slice(e,t,i){var r="";i=Math.min(e.length,i);for(var n=t;n<i;++n)r+=String.fromCharCode(e[n]);return r}function hexSlice(e,t,i){var r=e.length;(!t||t<0)&&(t=0),(!i||i<0||i>r)&&(i=r);for(var n="",a=t;a<i;++a)n+=toHex(e[a]);return n}function utf16leSlice(e,t,i){for(var r=e.slice(t,i),n="",a=0;a<r.length;a+=2)n+=String.fromCharCode(r[a]+256*r[a+1]);return n}function checkOffset(e,t,i){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>i)throw new RangeError("Trying to access beyond buffer length")}function checkInt(e,t,i,r,n,a){if(!internalIsBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>n||t<a)throw new RangeError('"value" argument is out of bounds');if(i+r>e.length)throw new RangeError("Index out of range")}function objectWriteUInt16(e,t,i,r){t<0&&(t=65535+t+1);for(var n=0,a=Math.min(e.length-i,2);n<a;++n)e[i+n]=(t&255<<8*(r?n:1-n))>>>8*(r?n:1-n);}function objectWriteUInt32(e,t,i,r){t<0&&(t=4294967295+t+1);for(var n=0,a=Math.min(e.length-i,4);n<a;++n)e[i+n]=t>>>8*(r?n:3-n)&255;}function checkIEEE754(e,t,i,r,n,a){if(i+r>e.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function writeFloat(e,t,i,r,n){return n||checkIEEE754(e,t,i,4),write(e,t,i,r,23,4),i+4}function writeDouble(e,t,i,r,n){return n||checkIEEE754(e,t,i,8),write(e,t,i,r,52,8),i+8}Buffer.prototype.slice=function(e,t){var i,r=this.length;if((e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e),Buffer.TYPED_ARRAY_SUPPORT)(i=this.subarray(e,t)).__proto__=Buffer.prototype;else {var n=t-e;i=new Buffer(n,void 0);for(var a=0;a<n;++a)i[a]=this[a+e];}return i},Buffer.prototype.readUIntLE=function(e,t,i){e|=0,t|=0,i||checkOffset(e,t,this.length);for(var r=this[e],n=1,a=0;++a<t&&(n*=256);)r+=this[e+a]*n;return r},Buffer.prototype.readUIntBE=function(e,t,i){e|=0,t|=0,i||checkOffset(e,t,this.length);for(var r=this[e+--t],n=1;t>0&&(n*=256);)r+=this[e+--t]*n;return r},Buffer.prototype.readUInt8=function(e,t){return t||checkOffset(e,1,this.length),this[e]},Buffer.prototype.readUInt16LE=function(e,t){return t||checkOffset(e,2,this.length),this[e]|this[e+1]<<8},Buffer.prototype.readUInt16BE=function(e,t){return t||checkOffset(e,2,this.length),this[e]<<8|this[e+1]},Buffer.prototype.readUInt32LE=function(e,t){return t||checkOffset(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},Buffer.prototype.readUInt32BE=function(e,t){return t||checkOffset(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},Buffer.prototype.readIntLE=function(e,t,i){e|=0,t|=0,i||checkOffset(e,t,this.length);for(var r=this[e],n=1,a=0;++a<t&&(n*=256);)r+=this[e+a]*n;return r>=(n*=128)&&(r-=Math.pow(2,8*t)),r},Buffer.prototype.readIntBE=function(e,t,i){e|=0,t|=0,i||checkOffset(e,t,this.length);for(var r=t,n=1,a=this[e+--r];r>0&&(n*=256);)a+=this[e+--r]*n;return a>=(n*=128)&&(a-=Math.pow(2,8*t)),a},Buffer.prototype.readInt8=function(e,t){return t||checkOffset(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},Buffer.prototype.readInt16LE=function(e,t){t||checkOffset(e,2,this.length);var i=this[e]|this[e+1]<<8;return 32768&i?4294901760|i:i},Buffer.prototype.readInt16BE=function(e,t){t||checkOffset(e,2,this.length);var i=this[e+1]|this[e]<<8;return 32768&i?4294901760|i:i},Buffer.prototype.readInt32LE=function(e,t){return t||checkOffset(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},Buffer.prototype.readInt32BE=function(e,t){return t||checkOffset(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},Buffer.prototype.readFloatLE=function(e,t){return t||checkOffset(e,4,this.length),read(this,e,true,23,4)},Buffer.prototype.readFloatBE=function(e,t){return t||checkOffset(e,4,this.length),read(this,e,false,23,4)},Buffer.prototype.readDoubleLE=function(e,t){return t||checkOffset(e,8,this.length),read(this,e,true,52,8)},Buffer.prototype.readDoubleBE=function(e,t){return t||checkOffset(e,8,this.length),read(this,e,false,52,8)},Buffer.prototype.writeUIntLE=function(e,t,i,r){(e=+e,t|=0,i|=0,r)||checkInt(this,e,t,i,Math.pow(2,8*i)-1,0);var n=1,a=0;for(this[t]=255&e;++a<i&&(n*=256);)this[t+a]=e/n&255;return t+i},Buffer.prototype.writeUIntBE=function(e,t,i,r){(e=+e,t|=0,i|=0,r)||checkInt(this,e,t,i,Math.pow(2,8*i)-1,0);var n=i-1,a=1;for(this[t+n]=255&e;--n>=0&&(a*=256);)this[t+n]=e/a&255;return t+i},Buffer.prototype.writeUInt8=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,1,255,0),Buffer.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},Buffer.prototype.writeUInt16LE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,2,65535,0),Buffer.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):objectWriteUInt16(this,e,t,true),t+2},Buffer.prototype.writeUInt16BE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,2,65535,0),Buffer.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):objectWriteUInt16(this,e,t,false),t+2},Buffer.prototype.writeUInt32LE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,4,4294967295,0),Buffer.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):objectWriteUInt32(this,e,t,true),t+4},Buffer.prototype.writeUInt32BE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,4,4294967295,0),Buffer.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):objectWriteUInt32(this,e,t,false),t+4},Buffer.prototype.writeIntLE=function(e,t,i,r){if(e=+e,t|=0,!r){var n=Math.pow(2,8*i-1);checkInt(this,e,t,i,n-1,-n);}var a=0,o=1,s=0;for(this[t]=255&e;++a<i&&(o*=256);)e<0&&0===s&&0!==this[t+a-1]&&(s=1),this[t+a]=(e/o|0)-s&255;return t+i},Buffer.prototype.writeIntBE=function(e,t,i,r){if(e=+e,t|=0,!r){var n=Math.pow(2,8*i-1);checkInt(this,e,t,i,n-1,-n);}var a=i-1,o=1,s=0;for(this[t+a]=255&e;--a>=0&&(o*=256);)e<0&&0===s&&0!==this[t+a+1]&&(s=1),this[t+a]=(e/o|0)-s&255;return t+i},Buffer.prototype.writeInt8=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,1,127,-128),Buffer.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},Buffer.prototype.writeInt16LE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,2,32767,-32768),Buffer.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):objectWriteUInt16(this,e,t,true),t+2},Buffer.prototype.writeInt16BE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,2,32767,-32768),Buffer.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):objectWriteUInt16(this,e,t,false),t+2},Buffer.prototype.writeInt32LE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,4,2147483647,-2147483648),Buffer.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):objectWriteUInt32(this,e,t,true),t+4},Buffer.prototype.writeInt32BE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),Buffer.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):objectWriteUInt32(this,e,t,false),t+4},Buffer.prototype.writeFloatLE=function(e,t,i){return writeFloat(this,e,t,true,i)},Buffer.prototype.writeFloatBE=function(e,t,i){return writeFloat(this,e,t,false,i)},Buffer.prototype.writeDoubleLE=function(e,t,i){return writeDouble(this,e,t,true,i)},Buffer.prototype.writeDoubleBE=function(e,t,i){return writeDouble(this,e,t,false,i)},Buffer.prototype.copy=function(e,t,i,r){if(i||(i=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<i&&(r=i),r===i)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-i&&(r=e.length-t+i);var n,a=r-i;if(this===e&&i<t&&t<r)for(n=a-1;n>=0;--n)e[n+t]=this[n+i];else if(a<1e3||!Buffer.TYPED_ARRAY_SUPPORT)for(n=0;n<a;++n)e[n+t]=this[n+i];else Uint8Array.prototype.set.call(e,this.subarray(i,i+a),t);return a},Buffer.prototype.fill=function(e,t,i,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,i=this.length):"string"==typeof i&&(r=i,i=this.length),1===e.length){var n=e.charCodeAt(0);n<256&&(e=n);}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!Buffer.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else "number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;var a;if(t>>>=0,i=void 0===i?this.length:i>>>0,e||(e=0),"number"==typeof e)for(a=t;a<i;++a)this[a]=e;else {var o=internalIsBuffer(e)?e:utf8ToBytes(new Buffer(e,r).toString()),s=o.length;for(a=0;a<i-t;++a)this[a+t]=o[a%s];}return this};var INVALID_BASE64_RE=/[^+\/0-9A-Za-z-_]/g,HeaderTypes;function base64clean(e){if((e=stringtrim(e).replace(INVALID_BASE64_RE,"")).length<2)return "";for(;e.length%4!=0;)e+="=";return e}function stringtrim(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function toHex(e){return e<16?"0"+e.toString(16):e.toString(16)}function utf8ToBytes(e,t){var i;t=t||1/0;for(var r=e.length,n=null,a=[],o=0;o<r;++o){if((i=e.charCodeAt(o))>55295&&i<57344){if(!n){if(i>56319){(t-=3)>-1&&a.push(239,191,189);continue}if(o+1===r){(t-=3)>-1&&a.push(239,191,189);continue}n=i;continue}if(i<56320){(t-=3)>-1&&a.push(239,191,189),n=i;continue}i=65536+(n-55296<<10|i-56320);}else n&&(t-=3)>-1&&a.push(239,191,189);if(n=null,i<128){if((t-=1)<0)break;a.push(i);}else if(i<2048){if((t-=2)<0)break;a.push(i>>6|192,63&i|128);}else if(i<65536){if((t-=3)<0)break;a.push(i>>12|224,i>>6&63|128,63&i|128);}else {if(!(i<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;a.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128);}}return a}function asciiToBytes(e){for(var t=[],i=0;i<e.length;++i)t.push(255&e.charCodeAt(i));return t}function utf16leToBytes(e,t){for(var i,r,n,a=[],o=0;o<e.length&&!((t-=2)<0);++o)r=(i=e.charCodeAt(o))>>8,n=i%256,a.push(n),a.push(r);return a}function base64ToBytes(e){return toByteArray(base64clean(e))}function blitBuffer(e,t,i,r){for(var n=0;n<r&&!(n+i>=t.length||n>=e.length);++n)t[n+i]=e[n];return n}function isnan(e){return e!=e}function isBuffer(e){return null!=e&&(!!e._isBuffer||isFastBuffer(e)||isSlowBuffer(e))}function isFastBuffer(e){return !!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function isSlowBuffer(e){return "function"==typeof e.readFloatLE&&"function"==typeof e.slice&&isFastBuffer(e.slice(0,0))}!function(e){e[e.BITMAP_INFO_HEADER=40]="BITMAP_INFO_HEADER",e[e.BITMAP_V2_INFO_HEADER=52]="BITMAP_V2_INFO_HEADER",e[e.BITMAP_V3_INFO_HEADER=56]="BITMAP_V3_INFO_HEADER",e[e.BITMAP_V4_HEADER=108]="BITMAP_V4_HEADER",e[e.BITMAP_V5_HEADER=124]="BITMAP_V5_HEADER";}(HeaderTypes||(HeaderTypes={}));var HeaderTypes$1=HeaderTypes,BmpCompression;function maskColor(e,t,i,r){const n=1+~e&e,a=1+~t&t,o=1+~i&i,s=1+~r&r,l=e/n+1,u=t/a+1,h=i/o+1,c=r/s+1;return {shiftRed:t=>(t&e)/n*256/l,shiftGreen:e=>(e&t)/a*256/u,shiftBlue:e=>(e&i)/o*256/h,shiftAlpha:0!==r?e=>(e&r)/s*256/c:()=>255}}!function(e){e[e.NONE=0]="NONE",e[e.BI_RLE8=1]="BI_RLE8",e[e.BI_RLE4=2]="BI_RLE4",e[e.BI_BIT_FIELDS=3]="BI_BIT_FIELDS",e[e.BI_ALPHA_BIT_FIELDS=6]="BI_ALPHA_BIT_FIELDS";}(BmpCompression||(BmpCompression={}));class BmpDecoder{flag;fileSize;reserved1;reserved2;offset;headerSize;width;height;planes;bitPP;compression;rawSize;hr;vr;colors;importantColors;palette;data;maskRed;maskGreen;maskBlue;maskAlpha;toRGBA;pos;bottomUp;buffer;locRed;locGreen;locBlue;locAlpha;shiftRed;shiftGreen;shiftBlue;shiftAlpha;constructor(e,{toRGBA:t}={toRGBA:false}){if(this.buffer=e,this.toRGBA=!!t,this.pos=0,this.bottomUp=true,this.flag=this.buffer.toString("utf-8",0,this.pos+=2),"BM"!==this.flag)throw new Error("Invalid BMP File");this.locRed=this.toRGBA?0:3,this.locGreen=this.toRGBA?1:2,this.locBlue=this.toRGBA?2:1,this.locAlpha=this.toRGBA?3:0,this.parseHeader(),this.parseRGBA();}parseHeader(){if(this.fileSize=this.readUInt32LE(),this.reserved1=this.buffer.readUInt16LE(this.pos),this.pos+=2,this.reserved2=this.buffer.readUInt16LE(this.pos),this.pos+=2,this.offset=this.readUInt32LE(),this.headerSize=this.readUInt32LE(),!(this.headerSize in HeaderTypes$1))throw new Error(`Unsupported BMP header size ${this.headerSize}`);if(this.width=this.readUInt32LE(),this.height=this.readUInt32LE(),this.height=this.height>2147483647?this.height-4294967296:this.height,this.planes=this.buffer.readUInt16LE(this.pos),this.pos+=2,this.bitPP=this.buffer.readUInt16LE(this.pos),this.pos+=2,this.compression=this.readUInt32LE(),this.rawSize=this.readUInt32LE(),this.hr=this.readUInt32LE(),this.vr=this.readUInt32LE(),this.colors=this.readUInt32LE(),this.importantColors=this.readUInt32LE(),32===this.bitPP?(this.maskAlpha=0,this.maskRed=16711680,this.maskGreen=65280,this.maskBlue=255):16===this.bitPP&&(this.maskAlpha=0,this.maskRed=31744,this.maskGreen=992,this.maskBlue=31),(this.headerSize>HeaderTypes$1.BITMAP_INFO_HEADER||this.compression===BmpCompression.BI_BIT_FIELDS||this.compression===BmpCompression.BI_ALPHA_BIT_FIELDS)&&(this.maskRed=this.readUInt32LE(),this.maskGreen=this.readUInt32LE(),this.maskBlue=this.readUInt32LE()),(this.headerSize>HeaderTypes$1.BITMAP_V2_INFO_HEADER||this.compression===BmpCompression.BI_ALPHA_BIT_FIELDS)&&(this.maskAlpha=this.readUInt32LE()),this.headerSize>HeaderTypes$1.BITMAP_V3_INFO_HEADER&&(this.pos+=HeaderTypes$1.BITMAP_V4_HEADER-HeaderTypes$1.BITMAP_V3_INFO_HEADER),this.headerSize>HeaderTypes$1.BITMAP_V4_HEADER&&(this.pos+=HeaderTypes$1.BITMAP_V5_HEADER-HeaderTypes$1.BITMAP_V4_HEADER),this.bitPP<=8||this.colors>0){const e=0===this.colors?1<<this.bitPP:this.colors;this.palette=new Array(e);for(let t=0;t<e;t++){const e=this.buffer.readUInt8(this.pos++),i=this.buffer.readUInt8(this.pos++),r=this.buffer.readUInt8(this.pos++),n=this.buffer.readUInt8(this.pos++);this.palette[t]={red:r,green:i,blue:e,quad:n};}}this.height<0&&(this.height*=-1,this.bottomUp=false);const e=maskColor(this.maskRed,this.maskGreen,this.maskBlue,this.maskAlpha);this.shiftRed=e.shiftRed,this.shiftGreen=e.shiftGreen,this.shiftBlue=e.shiftBlue,this.shiftAlpha=e.shiftAlpha;}parseRGBA(){switch(this.data=Buffer.alloc(this.width*this.height*4),this.bitPP){case 1:this.bit1();break;case 4:this.bit4();break;case 8:this.bit8();break;case 16:this.bit16();break;case 24:this.bit24();break;default:this.bit32();}}bit1(){const e=Math.ceil(this.width/8),t=e%4,i=0!==t?4-t:0;this.scanImage(i,e,((e,t)=>{const i=this.buffer.readUInt8(this.pos++),r=t*this.width*4+8*e*4;for(let t=0;t<8&&8*e+t<this.width;t++){const e=this.palette[i>>7-t&1];this.data[r+t*this.locAlpha]=0,this.data[r+4*t+this.locBlue]=e.blue,this.data[r+4*t+this.locGreen]=e.green,this.data[r+4*t+this.locRed]=e.red;}}));}bit4(){if(this.compression===BmpCompression.BI_RLE4){this.data.fill(0);let e=false,t=this.bottomUp?this.height-1:0,i=0;for(;i<this.data.length;){const r=this.buffer.readUInt8(this.pos++),n=this.buffer.readUInt8(this.pos++);if(0===r){if(0===n){t+=this.bottomUp?-1:1,i=t*this.width*4,e=false;continue}if(1===n)break;if(2===n){const e=this.buffer.readUInt8(this.pos++),r=this.buffer.readUInt8(this.pos++);t+=this.bottomUp?-r:r,i+=r*this.width*4+4*e;}else {let t=this.buffer.readUInt8(this.pos++);for(let r=0;r<n;r++)i=this.setPixelData(i,e?15&t:(240&t)>>4),1&r&&r+1<n&&(t=this.buffer.readUInt8(this.pos++)),e=!e;1==(n+1>>1&1)&&this.pos++;}}else for(let t=0;t<r;t++)i=this.setPixelData(i,e?15&n:(240&n)>>4),e=!e;}}else {const e=Math.ceil(this.width/2),t=e%4,i=0!==t?4-t:0;this.scanImage(i,e,((e,t)=>{const i=this.buffer.readUInt8(this.pos++),r=t*this.width*4+2*e*4,n=i>>4;let a=this.palette[n];if(this.data[r]=0,this.data[r+1]=a.blue,this.data[r+2]=a.green,this.data[r+3]=a.red,2*e+1>=this.width)return false;const o=15&i;a=this.palette[o],this.data[r+4]=0,this.data[r+4+1]=a.blue,this.data[r+4+2]=a.green,this.data[r+4+3]=a.red;}));}}bit8(){if(this.compression===BmpCompression.BI_RLE8){this.data.fill(0);let e=this.bottomUp?this.height-1:0,t=0;for(;t<this.data.length;){const i=this.buffer.readUInt8(this.pos++),r=this.buffer.readUInt8(this.pos++);if(0===i){if(0===r){e+=this.bottomUp?-1:1,t=e*this.width*4;continue}if(1===r)break;if(2===r){const i=this.buffer.readUInt8(this.pos++),r=this.buffer.readUInt8(this.pos++);e+=this.bottomUp?-r:r,t+=r*this.width*4+4*i;}else {for(let e=0;e<r;e++){const e=this.buffer.readUInt8(this.pos++);t=this.setPixelData(t,e);} true&r&&this.pos++;}}else for(let e=0;e<i;e++)t=this.setPixelData(t,r);}}else {const e=this.width%4,t=0!==e?4-e:0;this.scanImage(t,this.width,((e,t)=>{const i=this.buffer.readUInt8(this.pos++),r=t*this.width*4+4*e;if(i<this.palette.length){const e=this.palette[i];this.data[r]=0,this.data[r+1]=e.blue,this.data[r+2]=e.green,this.data[r+3]=e.red;}else this.data[r]=0,this.data[r+1]=255,this.data[r+2]=255,this.data[r+3]=255;}));}}bit16(){const e=this.width%2*2;this.scanImage(e,this.width,((e,t)=>{const i=t*this.width*4+4*e,r=this.buffer.readUInt16LE(this.pos);this.pos+=2,this.data[i+this.locRed]=this.shiftRed(r),this.data[i+this.locGreen]=this.shiftGreen(r),this.data[i+this.locBlue]=this.shiftBlue(r),this.data[i+this.locAlpha]=this.shiftAlpha(r);}));}bit24(){const e=this.width%4;this.scanImage(e,this.width,((e,t)=>{const i=t*this.width*4+4*e,r=this.buffer.readUInt8(this.pos++),n=this.buffer.readUInt8(this.pos++),a=this.buffer.readUInt8(this.pos++);this.data[i+this.locRed]=a,this.data[i+this.locGreen]=n,this.data[i+this.locBlue]=r,this.data[i+this.locAlpha]=0;}));}bit32(){this.scanImage(0,this.width,((e,t)=>{const i=t*this.width*4+4*e,r=this.readUInt32LE();this.data[i+this.locRed]=this.shiftRed(r),this.data[i+this.locGreen]=this.shiftGreen(r),this.data[i+this.locBlue]=this.shiftBlue(r),this.data[i+this.locAlpha]=this.shiftAlpha(r);}));}scanImage(e=0,t=this.width,i){for(let r=this.height-1;r>=0;r--){const n=this.bottomUp?r:this.height-1-r;for(let e=0;e<t;e++){if(false===i.call(this,e,n))return}this.pos+=e;}}readUInt32LE(){const e=this.buffer.readUInt32LE(this.pos);return this.pos+=4,e}setPixelData(e,t){const{blue:i,green:r,red:n}=this.palette[t];return this.data[e+this.locAlpha]=0,this.data[e+1+this.locBlue]=i,this.data[e+2+this.locGreen]=r,this.data[e+3+this.locRed]=n,e+4}}function createInteger(e){return e.reduce(((e,t)=>e<<1|t),0)}function createColor(e){return e.quad<<24|e.red<<16|e.green<<8|e.blue}class BmpEncoder{fileSize;reserved1;reserved2;offset;width;flag;height;planes;bitPP;compress;hr;vr;colors;importantColors;rawSize;headerSize;data;palette;extraBytes;buffer;bytesInColor;pos;constructor(e){switch(this.buffer=e.data,this.width=e.width,this.height=e.height,this.headerSize=HeaderTypes$1.BITMAP_INFO_HEADER,this.flag="BM",this.bitPP=e.bitPP||24,this.offset=54,this.reserved1=e.reserved1||0,this.reserved2=e.reserved2||0,this.planes=1,this.compress=0,this.hr=e.hr||0,this.vr=e.vr||0,this.importantColors=e.importantColors||0,this.colors=Math.min(2**(this.bitPP-1||1),e.colors||1/0),this.palette=e.palette||[],this.colors&&this.bitPP<16?this.offset+=4*this.colors:this.colors=0,this.bitPP){case 32:this.bytesInColor=4;break;case 16:this.bytesInColor=2;break;case 8:this.bytesInColor=1;break;case 4:this.bytesInColor=.5;break;case 1:this.bytesInColor=1/8;break;default:this.bytesInColor=3,this.bitPP=24;}const t=this.width*this.bitPP/32,i=Math.ceil(t);this.extraBytes=4*(i-t),this.rawSize=this.height*i*4+2,this.fileSize=this.rawSize+this.offset,this.data=Buffer.alloc(this.fileSize,1),this.pos=0,this.encode();}encode(){switch(this.pos=0,this.writeHeader(),this.bitPP){case 32:this.bit32();break;case 16:this.bit16();break;case 8:this.bit8();break;case 4:this.bit4();break;case 1:this.bit1();break;default:this.bit24();}}writeHeader(){this.data.write(this.flag,this.pos,2),this.pos+=2,this.writeUInt32LE(this.fileSize),this.writeUInt32LE(this.reserved1<<16|this.reserved2),this.writeUInt32LE(this.offset),this.writeUInt32LE(this.headerSize),this.writeUInt32LE(this.width),this.writeUInt32LE(this.height),this.data.writeUInt16LE(this.planes,this.pos),this.pos+=2,this.data.writeUInt16LE(this.bitPP,this.pos),this.pos+=2,this.writeUInt32LE(this.compress),this.writeUInt32LE(this.rawSize),this.writeUInt32LE(this.hr),this.writeUInt32LE(this.vr),this.writeUInt32LE(this.colors),this.writeUInt32LE(this.importantColors);}bit1(){this.palette.length&&2===this.colors?this.initColors(1):(this.writeUInt32LE(16777215),this.writeUInt32LE(0)),this.pos+=1;let e=[];this.writeImage(((t,i,r)=>{let n=i;n++;const a=this.buffer[n++],o=this.buffer[n++],s=.2126*this.buffer[n++]+.7152*o+.0722*a;return e.push(s>127?0:1),(r+1)%8==0?(this.data[t-1]=createInteger(e),e=[]):r===this.width-1&&e.length>0&&(this.data[t-1]=createInteger(e)<<4,e=[]),n}));}bit4(){const e=this.initColors(4);let t=[];this.writeImage(((i,r,n)=>{let a=r;const o=createColor({quad:this.buffer[a++],blue:this.buffer[a++],green:this.buffer[a++],red:this.buffer[a++]}),s=e.findIndex((e=>e===o));return -1!==s?t.push(s):t.push(0),(n+1)%2==0&&(this.data[i]=t[0]<<4|t[1],t=[]),a}));}bit8(){const e=this.initColors(8);this.writeImage(((t,i)=>{let r=i;const n=createColor({quad:this.buffer[r++],blue:this.buffer[r++],green:this.buffer[r++],red:this.buffer[r++]}),a=e.findIndex((e=>e===n));return this.data[t]=-1!==a?a:0,r}));}bit16(){this.writeImage(((e,t)=>{let i=t+1;const r=this.buffer[i++]/8,n=this.buffer[i++]/8,a=this.buffer[i++]/8<<10|n<<5|r;return this.data[e]=255&a,this.data[e+1]=(65280&a)>>8,i}));}bit24(){this.writeImage(((e,t)=>{let i=t+1;return this.data[e]=this.buffer[i++],this.data[e+1]=this.buffer[i++],this.data[e+2]=this.buffer[i++],i}));}bit32(){this.writeImage(((e,t)=>{let i=t;return this.data[e+3]=this.buffer[i++],this.data[e]=this.buffer[i++],this.data[e+1]=this.buffer[i++],this.data[e+2]=this.buffer[i++],i}));}writeImage(e){const t=this.extraBytes+this.width*this.bytesInColor;let i=0;for(let r=0;r<this.height;r++)for(let n=0;n<this.width;n++){const a=Math.floor(this.pos+(this.height-1-r)*t+n*this.bytesInColor);i=e.call(this,a,i,n,r);}}initColors(e){const t=[];if(!this.palette.length)throw new Error(`To encode ${e}-bit BMPs a pallette is needed. Please choose up to ${this.colors} colors. Colors must be 32-bit integers.`);for(let e=0;e<this.colors;e++){const i=createColor(this.palette[e]);this.writeUInt32LE(i),t.push(i);}return t}writeUInt32LE(e){this.data.writeUInt32LE(e,this.pos),this.pos+=4;}}function decode$2(e,t){return new BmpDecoder(e,t)}function encode$2(e){return new BmpEncoder(e)}function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}var trimLeft=/^\s+/,trimRight=/\s+$/;function tinycolor(e,t){if(t=t||{},(e=e||"")instanceof tinycolor)return e;if(!(this instanceof tinycolor))return new tinycolor(e,t);var i=inputToRGB(e);this._originalInput=e,this._r=i.r,this._g=i.g,this._b=i.b,this._a=i.a,this._roundA=Math.round(100*this._a)/100,this._format=t.format||i.format,this._gradientType=t.gradientType,this._r<1&&(this._r=Math.round(this._r)),this._g<1&&(this._g=Math.round(this._g)),this._b<1&&(this._b=Math.round(this._b)),this._ok=i.ok;}function inputToRGB(e){var t={r:0,g:0,b:0},i=1,r=null,n=null,a=null,o=false,s=false;return "string"==typeof e&&(e=stringInputToObject(e)),"object"==_typeof(e)&&(isValidCSSUnit(e.r)&&isValidCSSUnit(e.g)&&isValidCSSUnit(e.b)?(t=rgbToRgb(e.r,e.g,e.b),o=true,s="%"===String(e.r).substr(-1)?"prgb":"rgb"):isValidCSSUnit(e.h)&&isValidCSSUnit(e.s)&&isValidCSSUnit(e.v)?(r=convertToPercentage(e.s),n=convertToPercentage(e.v),t=hsvToRgb(e.h,r,n),o=true,s="hsv"):isValidCSSUnit(e.h)&&isValidCSSUnit(e.s)&&isValidCSSUnit(e.l)&&(r=convertToPercentage(e.s),a=convertToPercentage(e.l),t=hslToRgb(e.h,r,a),o=true,s="hsl"),e.hasOwnProperty("a")&&(i=e.a)),i=boundAlpha(i),{ok:o,format:e.format||s,r:Math.min(255,Math.max(t.r,0)),g:Math.min(255,Math.max(t.g,0)),b:Math.min(255,Math.max(t.b,0)),a:i}}function rgbToRgb(e,t,i){return {r:255*bound01(e,255),g:255*bound01(t,255),b:255*bound01(i,255)}}function rgbToHsl(e,t,i){e=bound01(e,255),t=bound01(t,255),i=bound01(i,255);var r,n,a=Math.max(e,t,i),o=Math.min(e,t,i),s=(a+o)/2;if(a==o)r=n=0;else {var l=a-o;switch(n=s>.5?l/(2-a-o):l/(a+o),a){case e:r=(t-i)/l+(t<i?6:0);break;case t:r=(i-e)/l+2;break;case i:r=(e-t)/l+4;}r/=6;}return {h:r,s:n,l:s}}function hslToRgb(e,t,i){var r,n,a;function o(e,t,i){return i<0&&(i+=1),i>1&&(i-=1),i<1/6?e+6*(t-e)*i:i<.5?t:i<2/3?e+(t-e)*(2/3-i)*6:e}if(e=bound01(e,360),t=bound01(t,100),i=bound01(i,100),0===t)r=n=a=i;else {var s=i<.5?i*(1+t):i+t-i*t,l=2*i-s;r=o(l,s,e+1/3),n=o(l,s,e),a=o(l,s,e-1/3);}return {r:255*r,g:255*n,b:255*a}}function rgbToHsv(e,t,i){e=bound01(e,255),t=bound01(t,255),i=bound01(i,255);var r,n,a=Math.max(e,t,i),o=Math.min(e,t,i),s=a,l=a-o;if(n=0===a?0:l/a,a==o)r=0;else {switch(a){case e:r=(t-i)/l+(t<i?6:0);break;case t:r=(i-e)/l+2;break;case i:r=(e-t)/l+4;}r/=6;}return {h:r,s:n,v:s}}function hsvToRgb(e,t,i){e=6*bound01(e,360),t=bound01(t,100),i=bound01(i,100);var r=Math.floor(e),n=e-r,a=i*(1-t),o=i*(1-n*t),s=i*(1-(1-n)*t),l=r%6;return {r:255*[i,o,a,a,s,i][l],g:255*[s,i,i,o,a,a][l],b:255*[a,a,s,i,i,o][l]}}function rgbToHex(e,t,i,r){var n=[pad2(Math.round(e).toString(16)),pad2(Math.round(t).toString(16)),pad2(Math.round(i).toString(16))];return r&&n[0].charAt(0)==n[0].charAt(1)&&n[1].charAt(0)==n[1].charAt(1)&&n[2].charAt(0)==n[2].charAt(1)?n[0].charAt(0)+n[1].charAt(0)+n[2].charAt(0):n.join("")}function rgbaToHex(e,t,i,r,n){var a=[pad2(Math.round(e).toString(16)),pad2(Math.round(t).toString(16)),pad2(Math.round(i).toString(16)),pad2(convertDecimalToHex(r))];return n&&a[0].charAt(0)==a[0].charAt(1)&&a[1].charAt(0)==a[1].charAt(1)&&a[2].charAt(0)==a[2].charAt(1)&&a[3].charAt(0)==a[3].charAt(1)?a[0].charAt(0)+a[1].charAt(0)+a[2].charAt(0)+a[3].charAt(0):a.join("")}function rgbaToArgbHex(e,t,i,r){return [pad2(convertDecimalToHex(r)),pad2(Math.round(e).toString(16)),pad2(Math.round(t).toString(16)),pad2(Math.round(i).toString(16))].join("")}function _desaturate(e,t){t=0===t?0:t||10;var i=tinycolor(e).toHsl();return i.s-=t/100,i.s=clamp01(i.s),tinycolor(i)}function _saturate(e,t){t=0===t?0:t||10;var i=tinycolor(e).toHsl();return i.s+=t/100,i.s=clamp01(i.s),tinycolor(i)}function _greyscale(e){return tinycolor(e).desaturate(100)}function _lighten(e,t){t=0===t?0:t||10;var i=tinycolor(e).toHsl();return i.l+=t/100,i.l=clamp01(i.l),tinycolor(i)}function _brighten(e,t){t=0===t?0:t||10;var i=tinycolor(e).toRgb();return i.r=Math.max(0,Math.min(255,i.r-Math.round(-t/100*255))),i.g=Math.max(0,Math.min(255,i.g-Math.round(-t/100*255))),i.b=Math.max(0,Math.min(255,i.b-Math.round(-t/100*255))),tinycolor(i)}function _darken(e,t){t=0===t?0:t||10;var i=tinycolor(e).toHsl();return i.l-=t/100,i.l=clamp01(i.l),tinycolor(i)}function _spin(e,t){var i=tinycolor(e).toHsl(),r=(i.h+t)%360;return i.h=r<0?360+r:r,tinycolor(i)}function _complement(e){var t=tinycolor(e).toHsl();return t.h=(t.h+180)%360,tinycolor(t)}function polyad(e,t){if(isNaN(t)||t<=0)throw new Error("Argument to polyad must be a positive number");for(var i=tinycolor(e).toHsl(),r=[tinycolor(e)],n=360/t,a=1;a<t;a++)r.push(tinycolor({h:(i.h+a*n)%360,s:i.s,l:i.l}));return r}function _splitcomplement(e){var t=tinycolor(e).toHsl(),i=t.h;return [tinycolor(e),tinycolor({h:(i+72)%360,s:t.s,l:t.l}),tinycolor({h:(i+216)%360,s:t.s,l:t.l})]}function _analogous(e,t,i){t=t||6,i=i||30;var r=tinycolor(e).toHsl(),n=360/i,a=[tinycolor(e)];for(r.h=(r.h-(n*t>>1)+720)%360;--t;)r.h=(r.h+n)%360,a.push(tinycolor(r));return a}function _monochromatic(e,t){t=t||6;for(var i=tinycolor(e).toHsv(),r=i.h,n=i.s,a=i.v,o=[],s=1/t;t--;)o.push(tinycolor({h:r,s:n,v:a})),a=(a+s)%1;return o}tinycolor.prototype={isDark:function(){return this.getBrightness()<128},isLight:function(){return !this.isDark()},isValid:function(){return this._ok},getOriginalInput:function(){return this._originalInput},getFormat:function(){return this._format},getAlpha:function(){return this._a},getBrightness:function(){var e=this.toRgb();return (299*e.r+587*e.g+114*e.b)/1e3},getLuminance:function(){var e,t,i,r=this.toRgb();return e=r.r/255,t=r.g/255,i=r.b/255,.2126*(e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4))+.7152*(t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4))+.0722*(i<=.03928?i/12.92:Math.pow((i+.055)/1.055,2.4))},setAlpha:function(e){return this._a=boundAlpha(e),this._roundA=Math.round(100*this._a)/100,this},toHsv:function(){var e=rgbToHsv(this._r,this._g,this._b);return {h:360*e.h,s:e.s,v:e.v,a:this._a}},toHsvString:function(){var e=rgbToHsv(this._r,this._g,this._b),t=Math.round(360*e.h),i=Math.round(100*e.s),r=Math.round(100*e.v);return 1==this._a?"hsv("+t+", "+i+"%, "+r+"%)":"hsva("+t+", "+i+"%, "+r+"%, "+this._roundA+")"},toHsl:function(){var e=rgbToHsl(this._r,this._g,this._b);return {h:360*e.h,s:e.s,l:e.l,a:this._a}},toHslString:function(){var e=rgbToHsl(this._r,this._g,this._b),t=Math.round(360*e.h),i=Math.round(100*e.s),r=Math.round(100*e.l);return 1==this._a?"hsl("+t+", "+i+"%, "+r+"%)":"hsla("+t+", "+i+"%, "+r+"%, "+this._roundA+")"},toHex:function(e){return rgbToHex(this._r,this._g,this._b,e)},toHexString:function(e){return "#"+this.toHex(e)},toHex8:function(e){return rgbaToHex(this._r,this._g,this._b,this._a,e)},toHex8String:function(e){return "#"+this.toHex8(e)},toRgb:function(){return {r:Math.round(this._r),g:Math.round(this._g),b:Math.round(this._b),a:this._a}},toRgbString:function(){return 1==this._a?"rgb("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+")":"rgba("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+", "+this._roundA+")"},toPercentageRgb:function(){return {r:Math.round(100*bound01(this._r,255))+"%",g:Math.round(100*bound01(this._g,255))+"%",b:Math.round(100*bound01(this._b,255))+"%",a:this._a}},toPercentageRgbString:function(){return 1==this._a?"rgb("+Math.round(100*bound01(this._r,255))+"%, "+Math.round(100*bound01(this._g,255))+"%, "+Math.round(100*bound01(this._b,255))+"%)":"rgba("+Math.round(100*bound01(this._r,255))+"%, "+Math.round(100*bound01(this._g,255))+"%, "+Math.round(100*bound01(this._b,255))+"%, "+this._roundA+")"},toName:function(){return 0===this._a?"transparent":!(this._a<1)&&(hexNames[rgbToHex(this._r,this._g,this._b,true)]||false)},toFilter:function(e){var t="#"+rgbaToArgbHex(this._r,this._g,this._b,this._a),i=t,r=this._gradientType?"GradientType = 1, ":"";if(e){var n=tinycolor(e);i="#"+rgbaToArgbHex(n._r,n._g,n._b,n._a);}return "progid:DXImageTransform.Microsoft.gradient("+r+"startColorstr="+t+",endColorstr="+i+")"},toString:function(e){var t=!!e;e=e||this._format;var i=false,r=this._a<1&&this._a>=0;return t||!r||"hex"!==e&&"hex6"!==e&&"hex3"!==e&&"hex4"!==e&&"hex8"!==e&&"name"!==e?("rgb"===e&&(i=this.toRgbString()),"prgb"===e&&(i=this.toPercentageRgbString()),"hex"!==e&&"hex6"!==e||(i=this.toHexString()),"hex3"===e&&(i=this.toHexString(true)),"hex4"===e&&(i=this.toHex8String(true)),"hex8"===e&&(i=this.toHex8String()),"name"===e&&(i=this.toName()),"hsl"===e&&(i=this.toHslString()),"hsv"===e&&(i=this.toHsvString()),i||this.toHexString()):"name"===e&&0===this._a?this.toName():this.toRgbString()},clone:function(){return tinycolor(this.toString())},_applyModification:function(e,t){var i=e.apply(null,[this].concat([].slice.call(t)));return this._r=i._r,this._g=i._g,this._b=i._b,this.setAlpha(i._a),this},lighten:function(){return this._applyModification(_lighten,arguments)},brighten:function(){return this._applyModification(_brighten,arguments)},darken:function(){return this._applyModification(_darken,arguments)},desaturate:function(){return this._applyModification(_desaturate,arguments)},saturate:function(){return this._applyModification(_saturate,arguments)},greyscale:function(){return this._applyModification(_greyscale,arguments)},spin:function(){return this._applyModification(_spin,arguments)},_applyCombination:function(e,t){return e.apply(null,[this].concat([].slice.call(t)))},analogous:function(){return this._applyCombination(_analogous,arguments)},complement:function(){return this._applyCombination(_complement,arguments)},monochromatic:function(){return this._applyCombination(_monochromatic,arguments)},splitcomplement:function(){return this._applyCombination(_splitcomplement,arguments)},triad:function(){return this._applyCombination(polyad,[3])},tetrad:function(){return this._applyCombination(polyad,[4])}},tinycolor.fromRatio=function(e,t){if("object"==_typeof(e)){var i={};for(var r in e)e.hasOwnProperty(r)&&(i[r]="a"===r?e[r]:convertToPercentage(e[r]));e=i;}return tinycolor(e,t)},tinycolor.equals=function(e,t){return !(!e||!t)&&tinycolor(e).toRgbString()==tinycolor(t).toRgbString()},tinycolor.random=function(){return tinycolor.fromRatio({r:Math.random(),g:Math.random(),b:Math.random()})},tinycolor.mix=function(e,t,i){i=0===i?0:i||50;var r=tinycolor(e).toRgb(),n=tinycolor(t).toRgb(),a=i/100;return tinycolor({r:(n.r-r.r)*a+r.r,g:(n.g-r.g)*a+r.g,b:(n.b-r.b)*a+r.b,a:(n.a-r.a)*a+r.a})},tinycolor.readability=function(e,t){var i=tinycolor(e),r=tinycolor(t);return (Math.max(i.getLuminance(),r.getLuminance())+.05)/(Math.min(i.getLuminance(),r.getLuminance())+.05)},tinycolor.isReadable=function(e,t,i){var r,n,a=tinycolor.readability(e,t);switch(n=false,(r=validateWCAG2Parms(i)).level+r.size){case "AAsmall":case "AAAlarge":n=a>=4.5;break;case "AAlarge":n=a>=3;break;case "AAAsmall":n=a>=7;}return n},tinycolor.mostReadable=function(e,t,i){var r,n,a,o,s=null,l=0;n=(i=i||{}).includeFallbackColors,a=i.level,o=i.size;for(var u=0;u<t.length;u++)(r=tinycolor.readability(e,t[u]))>l&&(l=r,s=tinycolor(t[u]));return tinycolor.isReadable(e,s,{level:a,size:o})||!n?s:(i.includeFallbackColors=false,tinycolor.mostReadable(e,["#fff","#000"],i))};var names$1=tinycolor.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"663399",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},hexNames=tinycolor.hexNames=flip(names$1);function flip(e){var t={};for(var i in e)e.hasOwnProperty(i)&&(t[e[i]]=i);return t}function boundAlpha(e){return e=parseFloat(e),(isNaN(e)||e<0||e>1)&&(e=1),e}function bound01(e,t){isOnePointZero(e)&&(e="100%");var i=isPercentage(e);return e=Math.min(t,Math.max(0,parseFloat(e))),i&&(e=parseInt(e*t,10)/100),Math.abs(e-t)<1e-6?1:e%t/parseFloat(t)}function clamp01(e){return Math.min(1,Math.max(0,e))}function parseIntFromHex(e){return parseInt(e,16)}function isOnePointZero(e){return "string"==typeof e&&-1!=e.indexOf(".")&&1===parseFloat(e)}function isPercentage(e){return "string"==typeof e&&-1!=e.indexOf("%")}function pad2(e){return 1==e.length?"0"+e:""+e}function convertToPercentage(e){return e<=1&&(e=100*e+"%"),e}function convertDecimalToHex(e){return Math.round(255*parseFloat(e)).toString(16)}function convertHexToDecimal(e){return parseIntFromHex(e)/255}var matchers=(CSS_UNIT="(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)",PERMISSIVE_MATCH3="[\\s|\\(]+("+CSS_UNIT+")[,|\\s]+("+CSS_UNIT+")[,|\\s]+("+CSS_UNIT+")\\s*\\)?",PERMISSIVE_MATCH4="[\\s|\\(]+("+CSS_UNIT+")[,|\\s]+("+CSS_UNIT+")[,|\\s]+("+CSS_UNIT+")[,|\\s]+("+CSS_UNIT+")\\s*\\)?",{CSS_UNIT:new RegExp(CSS_UNIT),rgb:new RegExp("rgb"+PERMISSIVE_MATCH3),rgba:new RegExp("rgba"+PERMISSIVE_MATCH4),hsl:new RegExp("hsl"+PERMISSIVE_MATCH3),hsla:new RegExp("hsla"+PERMISSIVE_MATCH4),hsv:new RegExp("hsv"+PERMISSIVE_MATCH3),hsva:new RegExp("hsva"+PERMISSIVE_MATCH4),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/}),CSS_UNIT,PERMISSIVE_MATCH3,PERMISSIVE_MATCH4;function isValidCSSUnit(e){return !!matchers.CSS_UNIT.exec(e)}function stringInputToObject(e){e=e.replace(trimLeft,"").replace(trimRight,"").toLowerCase();var t,i=false;if(names$1[e])e=names$1[e],i=true;else if("transparent"==e)return {r:0,g:0,b:0,a:0,format:"name"};return (t=matchers.rgb.exec(e))?{r:t[1],g:t[2],b:t[3]}:(t=matchers.rgba.exec(e))?{r:t[1],g:t[2],b:t[3],a:t[4]}:(t=matchers.hsl.exec(e))?{h:t[1],s:t[2],l:t[3]}:(t=matchers.hsla.exec(e))?{h:t[1],s:t[2],l:t[3],a:t[4]}:(t=matchers.hsv.exec(e))?{h:t[1],s:t[2],v:t[3]}:(t=matchers.hsva.exec(e))?{h:t[1],s:t[2],v:t[3],a:t[4]}:(t=matchers.hex8.exec(e))?{r:parseIntFromHex(t[1]),g:parseIntFromHex(t[2]),b:parseIntFromHex(t[3]),a:convertHexToDecimal(t[4]),format:i?"name":"hex8"}:(t=matchers.hex6.exec(e))?{r:parseIntFromHex(t[1]),g:parseIntFromHex(t[2]),b:parseIntFromHex(t[3]),format:i?"name":"hex"}:(t=matchers.hex4.exec(e))?{r:parseIntFromHex(t[1]+""+t[1]),g:parseIntFromHex(t[2]+""+t[2]),b:parseIntFromHex(t[3]+""+t[3]),a:convertHexToDecimal(t[4]+""+t[4]),format:i?"name":"hex8"}:!!(t=matchers.hex3.exec(e))&&{r:parseIntFromHex(t[1]+""+t[1]),g:parseIntFromHex(t[2]+""+t[2]),b:parseIntFromHex(t[3]+""+t[3]),format:i?"name":"hex"}}function validateWCAG2Parms(e){var t,i;return "AA"!==(t=((e=e||{level:"AA",size:"small"}).level||"AA").toUpperCase())&&"AAA"!==t&&(t="AA"),"small"!==(i=(e.size||"small").toLowerCase())&&"large"!==i&&(i="small"),{level:t,size:i}}function clone(e){const t={width:e.bitmap.width,height:e.bitmap.height,data:Buffer.from(e.bitmap.data)};return new e.constructor(t)}function scan(e,t,i,r,n,a){let o,s,l,u,h;if("function"==typeof t)h=t,o=0,s=0,l=e.bitmap.width,u=e.bitmap.height;else {if(o=t,"number"!=typeof i)throw new Error("y must be a number");if(s=i,"number"!=typeof r)throw new Error("w must be a number");if(l=r,"number"!=typeof n)throw new Error("h must be a number");if(u=n,"function"!=typeof a)throw new Error("cb must be a function");h=a;}o=Math.round(o),s=Math.round(s),l=Math.round(l),u=Math.round(u);const c=h.bind(e);for(let t=s;t<s+u;t++)for(let i=o;i<o+l;i++){c(i,t,e.bitmap.width*t+i<<2);}return e}function*scanIterator(e,t,i,r,n){t=Math.round(t),i=Math.round(i),r=Math.round(r),n=Math.round(n);for(let a=i;a<i+n;a++)for(let i=t;i<t+r;i++){const t=e.bitmap.width*a+i<<2;yield {x:i,y:a,idx:t,image:e};}}function intToRGBA$1(e){if("number"!=typeof e)throw new Error("i must be a number");const t={r:0,g:0,b:0,a:0};return t.r=Math.floor(e/Math.pow(256,3)),t.g=Math.floor((e-t.r*Math.pow(256,3))/Math.pow(256,2)),t.b=Math.floor((e-t.r*Math.pow(256,3)-t.g*Math.pow(256,2))/Math.pow(256,1)),t.a=Math.floor((e-t.r*Math.pow(256,3)-t.g*Math.pow(256,2)-t.b*Math.pow(256,1))/Math.pow(256,0)),t}function rgbaToInt(e,t,i,r){let n=255&e;return n<<=8,n|=255&t,n<<=8,n|=255&i,n<<=8,n|=255&r,n>>>=0,n}function colorDiff(e,t){const i=e=>Math.pow(e,2),{max:r}=Math,n="a"in e?e.a:255,a="a"in t?t.a:255;return (r(i(e.r-t.r),i(e.r-t.r-n+a))+r(i(e.g-t.g),i(e.g-t.g-n+a))+r(i(e.b-t.b),i(e.b-t.b-n+a)))/195075}function limit255(e){return e=Math.max(e,0),e=Math.min(e,255)}function cssColorToHex(e){return "number"==typeof e?e:parseInt(tinycolor(e).toHex8(),16)}function encode$1(e,t={}){return scan({bitmap:e},0,0,e.width,e.height,(function(t,i,r){const n=e.data[r+0],a=e.data[r+1],o=e.data[r+2],s=e.data[r+3];e.data[r+0]=s,e.data[r+1]=o,e.data[r+2]=a,e.data[r+3]=n;})),encode$2({...e,...t}).data}function decode$1(e,t){const i=decode$2(e,t);return scan({bitmap:i},0,0,i.width,i.height,(function(e,t,r){const n=i.data[r+1],a=i.data[r+2],o=i.data[r+3];i.data[r+0]=o,i.data[r+1]=a,i.data[r+2]=n,i.data[r+3]=255;})),i}function msBmp(){return {mime:"image/x-ms-bmp",encode:encode$1,decode:decode$1}}function bmp(){return {mime:"image/bmp",encode:encode$1,decode:decode$1}}var omggif={},GifReader_1,GifWriter_1;function GifWriter(e,t,i,r){var n=0,a=void 0===(r=void 0===r?{}:r).loop?null:r.loop,o=void 0===r.palette?null:r.palette;if(t<=0||i<=0||t>65535||i>65535)throw new Error("Width/Height invalid.");function s(e){var t=e.length;if(t<2||t>256||t&t-1)throw new Error("Invalid code/color length, must be power of 2 and 2 .. 256.");return t}e[n++]=71,e[n++]=73,e[n++]=70,e[n++]=56,e[n++]=57,e[n++]=97;var l=0,u=0;if(null!==o){for(var h=s(o);h>>=1;)++l;if(h=1<<l,--l,void 0!==r.background){if((u=r.background)>=h)throw new Error("Background index out of range.");if(0===u)throw new Error("Background index explicitly passed as 0.")}}if(e[n++]=255&t,e[n++]=t>>8&255,e[n++]=255&i,e[n++]=i>>8&255,e[n++]=(null!==o?128:0)|l,e[n++]=u,e[n++]=0,null!==o)for(var c=0,f=o.length;c<f;++c){var d=o[c];e[n++]=d>>16&255,e[n++]=d>>8&255,e[n++]=255&d;}if(null!==a){if(a<0||a>65535)throw new Error("Loop count invalid.");e[n++]=33,e[n++]=255,e[n++]=11,e[n++]=78,e[n++]=69,e[n++]=84,e[n++]=83,e[n++]=67,e[n++]=65,e[n++]=80,e[n++]=69,e[n++]=50,e[n++]=46,e[n++]=48,e[n++]=3,e[n++]=1,e[n++]=255&a,e[n++]=a>>8&255,e[n++]=0;}var p=false;this.addFrame=function(t,i,r,a,l,u){if(true===p&&(--n,p=false),u=void 0===u?{}:u,t<0||i<0||t>65535||i>65535)throw new Error("x/y invalid.");if(r<=0||a<=0||r>65535||a>65535)throw new Error("Width/Height invalid.");if(l.length<r*a)throw new Error("Not enough pixels for the frame size.");var h=true,c=u.palette;if(null==c&&(h=false,c=o),null==c)throw new Error("Must supply either a local or global palette.");for(var f=s(c),d=0;f>>=1;)++d;f=1<<d;var m=void 0===u.delay?0:u.delay,_=void 0===u.disposal?0:u.disposal;if(_<0||_>3)throw new Error("Disposal out of range.");var g=false,b=0;if(void 0!==u.transparent&&null!==u.transparent&&(g=true,(b=u.transparent)<0||b>=f))throw new Error("Transparent color index.");if((0!==_||g||0!==m)&&(e[n++]=33,e[n++]=249,e[n++]=4,e[n++]=_<<2|(true===g?1:0),e[n++]=255&m,e[n++]=m>>8&255,e[n++]=b,e[n++]=0),e[n++]=44,e[n++]=255&t,e[n++]=t>>8&255,e[n++]=255&i,e[n++]=i>>8&255,e[n++]=255&r,e[n++]=r>>8&255,e[n++]=255&a,e[n++]=a>>8&255,e[n++]=true===h?128|d-1:0,true===h)for(var y=0,w=c.length;y<w;++y){var v=c[y];e[n++]=v>>16&255,e[n++]=v>>8&255,e[n++]=255&v;}return n=GifWriterOutputLZWCodeStream(e,n,d<2?2:d,l)},this.end=function(){return false===p&&(e[n++]=59,p=true),n},this.getOutputBuffer=function(){return e},this.setOutputBuffer=function(t){e=t;},this.getOutputBufferPosition=function(){return n},this.setOutputBufferPosition=function(e){n=e;};}function GifWriterOutputLZWCodeStream(e,t,i,r){e[t++]=i;var n=t++,a=1<<i,o=a-1,s=a+1,l=s+1,u=i+1,h=0,c=0;function f(i){for(;h>=i;)e[t++]=255&c,c>>=8,h-=8,t===n+256&&(e[n]=255,n=t++);}function d(e){c|=e<<h,h+=u,f(8);}var p=r[0]&o,m={};d(a);for(var _=1,g=r.length;_<g;++_){var b=r[_]&o,y=p<<8|b,w=m[y];if(void 0===w){for(c|=p<<h,h+=u;h>=8;)e[t++]=255&c,c>>=8,h-=8,t===n+256&&(e[n]=255,n=t++);4096===l?(d(a),l=s+1,u=i+1,m={}):(l>=1<<u&&++u,m[y]=l++),p=b;}else p=w;}return d(p),d(s),f(1),n+1===t?e[n]=0:(e[n]=t-n-1,e[t++]=0),t}function GifReader(e){var t=0;if(71!==e[t++]||73!==e[t++]||70!==e[t++]||56!==e[t++]||56!=(e[t++]+1&253)||97!==e[t++])throw new Error("Invalid GIF 87a/89a header.");var i=e[t++]|e[t++]<<8,r=e[t++]|e[t++]<<8,n=e[t++],a=n>>7,o=1<<(7&n)+1;e[t++],e[t++];var s=null,l=null;a&&(s=t,l=o,t+=3*o);var u=true,h=[],c=0,f=null,d=0,p=null;for(this.width=i,this.height=r;u&&t<e.length;)switch(e[t++]){case 33:switch(e[t++]){case 255:if(11!==e[t]||78==e[t+1]&&69==e[t+2]&&84==e[t+3]&&83==e[t+4]&&67==e[t+5]&&65==e[t+6]&&80==e[t+7]&&69==e[t+8]&&50==e[t+9]&&46==e[t+10]&&48==e[t+11]&&3==e[t+12]&&1==e[t+13]&&0==e[t+16])t+=14,p=e[t++]|e[t++]<<8,t++;else for(t+=12;;){if(!((I=e[t++])>=0))throw Error("Invalid block size");if(0===I)break;t+=I;}break;case 249:if(4!==e[t++]||0!==e[t+4])throw new Error("Invalid graphics extension block.");var m=e[t++];c=e[t++]|e[t++]<<8,f=e[t++],1&m||(f=null),d=m>>2&7,t++;break;case 254:for(;;){if(!((I=e[t++])>=0))throw Error("Invalid block size");if(0===I)break;t+=I;}break;default:throw new Error("Unknown graphic control label: 0x"+e[t-1].toString(16))}break;case 44:var _=e[t++]|e[t++]<<8,g=e[t++]|e[t++]<<8,b=e[t++]|e[t++]<<8,y=e[t++]|e[t++]<<8,w=e[t++],v=w>>6&1,x=1<<(7&w)+1,E=s,k=l,S=false;if(w>>7){S=true;E=t,k=x,t+=3*x;}var A=t;for(t++;;){var I;if(!((I=e[t++])>=0))throw Error("Invalid block size");if(0===I)break;t+=I;}h.push({x:_,y:g,width:b,height:y,has_local_palette:S,palette_offset:E,palette_size:k,data_offset:A,data_length:t-A,transparent_index:f,interlaced:!!v,delay:c,disposal:d});break;case 59:u=false;break;default:throw new Error("Unknown gif block: 0x"+e[t-1].toString(16))}this.numFrames=function(){return h.length},this.loopCount=function(){return p},this.frameInfo=function(e){if(e<0||e>=h.length)throw new Error("Frame index out of range.");return h[e]},this.decodeAndBlitFrameBGRA=function(t,r){var n=this.frameInfo(t),a=n.width*n.height,o=new Uint8Array(a);GifReaderLZWOutputIndexStream(e,n.data_offset,o,a);var s=n.palette_offset,l=n.transparent_index;null===l&&(l=256);var u=n.width,h=i-u,c=u,f=4*(n.y*i+n.x),d=4*((n.y+n.height)*i+n.x),p=f,m=4*h;true===n.interlaced&&(m+=4*i*7);for(var _=8,g=0,b=o.length;g<b;++g){var y=o[g];if(0===c&&(c=u,(p+=m)>=d&&(m=4*h+4*i*(_-1),p=f+(u+h)*(_<<1),_>>=1)),y===l)p+=4;else {var w=e[s+3*y],v=e[s+3*y+1],x=e[s+3*y+2];r[p++]=x,r[p++]=v,r[p++]=w,r[p++]=255;}--c;}},this.decodeAndBlitFrameRGBA=function(t,r){var n=this.frameInfo(t),a=n.width*n.height,o=new Uint8Array(a);GifReaderLZWOutputIndexStream(e,n.data_offset,o,a);var s=n.palette_offset,l=n.transparent_index;null===l&&(l=256);var u=n.width,h=i-u,c=u,f=4*(n.y*i+n.x),d=4*((n.y+n.height)*i+n.x),p=f,m=4*h;true===n.interlaced&&(m+=4*i*7);for(var _=8,g=0,b=o.length;g<b;++g){var y=o[g];if(0===c&&(c=u,(p+=m)>=d&&(m=4*h+4*i*(_-1),p=f+(u+h)*(_<<1),_>>=1)),y===l)p+=4;else {var w=e[s+3*y],v=e[s+3*y+1],x=e[s+3*y+2];r[p++]=w,r[p++]=v,r[p++]=x,r[p++]=255;}--c;}};}function GifReaderLZWOutputIndexStream(e,t,i,r){for(var n=e[t++],a=1<<n,o=a+1,s=o+1,l=n+1,u=(1<<l)-1,h=0,c=0,f=0,d=e[t++],p=new Int32Array(4096),m=null;;){for(;h<16&&0!==d;)c|=e[t++]<<h,h+=8,1===d?d=e[t++]:--d;if(h<l)break;var _=c&u;if(c>>=l,h-=l,_!==a){if(_===o)break;for(var g=_<s?_:m,b=0,y=g;y>a;)y=p[y]>>8,++b;var w=y;if(f+b+(g!==_?1:0)>r)return void console.log("Warning, gif stream longer than expected.");i[f++]=w;var v=f+=b;for(g!==_&&(i[f++]=w),y=g;b--;)y=p[y],i[--v]=255&y,y>>=8;null!==m&&s<4096&&(p[s++]=m<<8|w,s>=u+1&&l<12&&(++l,u=u<<1|1)),m=_;}else s=o+1,u=(1<<(l=n+1))-1,m=null;}return f!==r&&console.log("Warning, gif stream shorter than expected."),i}try{GifWriter_1=omggif.GifWriter=GifWriter,GifReader_1=omggif.GifReader=GifReader;}catch(e){}let BitmapImage$2=class e{constructor(...t){if(0===t.length)throw new Error("constructor requires parameters");const i=t[0];if(null!==i&&"object"==typeof i)if(i instanceof e){const e=i.bitmap;this.bitmap={width:e.width,height:e.height,data:new Buffer(e.width*e.height*4)},e.data.copy(this.bitmap.data);}else {if(!(i.width&&i.height&&i.data))throw new Error("unrecognized constructor parameters");this.bitmap=i;}else {if("number"!=typeof i||"number"!=typeof t[1])throw new Error("unrecognized constructor parameters");{const e=i,r=t[1],n=t[2];this.bitmap={width:e,height:r},Buffer.isBuffer(n)?this.bitmap.data=n:(this.bitmap.data=new Buffer(e*r*4),"number"==typeof n&&this.fillRGBA(n));}}}blit(e,t,i,r,n,a,o){if(r+a>this.bitmap.width)throw new Error("copy exceeds width of source bitmap");if(t+a>e.bitmap.width)throw new Error("copy exceeds width of target bitmap");if(n+o>this.bitmap.height)throw new Error("copy exceeds height of source bitmap");if(i+o>e.bitmap.height)throw new Erro("copy exceeds height of target bitmap");const s=this.bitmap.data,l=e.bitmap.data,u=4*this.bitmap.width,h=4*e.bitmap.width,c=4*a;let f=n*u+4*r,d=i*h+4*t;for(;--o>=0;)s.copy(l,d,f,f+c),f+=u,d+=h;return this}fillRGBA(e){const t=this.bitmap.data,i=4*this.bitmap.height;let r=0;for(;r<i;)t.writeUInt32BE(e,r),r+=4;for(;r<t.length;)t.copy(t,r,0,i),r+=i;return this}getRGBA(e,t){const i=4*(t*this.bitmap.width+e);return this.bitmap.data.readUInt32BE(i)}getRGBASet(){const e=new Set,t=this.bitmap.data;for(let i=0;i<t.length;i+=4)e.add(t.readUInt32BE(i,true));return e}greyscale(){const e=this.bitmap.data;return this.scan(0,0,this.bitmap.width,this.bitmap.height,((t,i,r)=>{const n=Math.round(.299*e[r]+.587*e[r+1]+.114*e[r+2]);e[r]=n,e[r+1]=n,e[r+2]=n;})),this}reframe(t,i,r,n,a){const o=t<0?0:t,s=i<0?0:i,l=r+o>this.bitmap.width?this.bitmap.width-o:r,u=n+s>this.bitmap.height?this.bitmap.height-s:n,h=t<0?-t:0,c=i<0?-i:0;let f;if(void 0===a){if(o!==t||s!=i||l!==r||u!==n)throw new GifError("fillRGBA required for this reframing");f=new e(r,n);}else f=new e(r,n,a);return this.blit(f,h,c,o,s,l,u),this.bitmap=f.bitmap,this}scale(e){if(1===e)return;if(!Number.isInteger(e)||e<1)throw new Error("the scale must be an integer >= 1");const t=this.bitmap.width,i=this.bitmap.height,r=t*e*4,n=this.bitmap.data,a=new Buffer(i*r*e);let o,s=0,l=0;for(let u=0;u<i;++u){o=l;for(let i=0;i<t;++i){const t=n.readUInt32BE(s,true);for(let i=0;i<e;++i)a.writeUInt32BE(t,l),l+=4;s+=4;}for(let t=1;t<e;++t)a.copy(a,l,o,l),l+=r,o+=r;}return this.bitmap={width:t*e,height:i*e,data:a},this}scanAllCoords(e){const t=this.bitmap.width,i=this.bitmap.data.length;let r=0,n=0;for(let a=0;a<i;a+=4)e(r,n,a),++r===t&&(r=0,++n);}scanAllIndexes(e){const t=this.bitmap.data.length;for(let i=0;i<t;i+=4)e(i);}};var bitmapimage=BitmapImage$2,gif$1={};let Gif$1=class{constructor(e,t,i){this.width=i.width,this.height=i.height,this.loops=i.loops,this.usesTransparency=i.usesTransparency,this.colorScope=i.colorScope,this.frames=t,this.buffer=e;}};Gif$1.GlobalColorsPreferred=0,Gif$1.GlobalColorsOnly=1,Gif$1.LocalColorsOnly=2;let GifError$2=class extends Error{constructor(e){super(e),e instanceof Error&&(this.stack="Gif"+e.stack);}};gif$1.Gif=Gif$1,gif$1.GifError=GifError$2;var gifcodec={},gifutil={},_polyfillNode_fs={},_polyfillNode_fs$1=Object.freeze({__proto__:null,default:_polyfillNode_fs}),require$$0=getAugmentedNamespace(_polyfillNode_fs$1),__defProp$3=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__defNormalProp$3=(e,t,i)=>t in e?__defProp$3(e,t,{enumerable:true,configurable:true,writable:true,value:i}):e[t]=i,__markAsModule=e=>__defProp$3(e,"__esModule",{value:true}),__export$1=(e,t)=>{for(var i in t)__defProp$3(e,i,{get:t[i],enumerable:true});},__reExport=(e,t,i,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of __getOwnPropNames(t))!__hasOwnProp.call(e,n)&&i&&__defProp$3(e,n,{get:()=>t[n],enumerable:!(r=__getOwnPropDesc(t,n))||r.enumerable});return e},__toCommonJS=(e=>(t,i)=>e&&e.get(t)||(i=__reExport(__markAsModule({}),t,1),e&&e.set(t,i),i))("undefined"!=typeof WeakMap?new WeakMap:0),__publicField$3=(e,t,i)=>(__defNormalProp$3(e,"symbol"!=typeof t?t+"":t,i),i),src_exports={};__export$1(src_exports,{applyPalette:()=>applyPalette,applyPaletteSync:()=>applyPaletteSync$1,buildPalette:()=>buildPalette,buildPaletteSync:()=>buildPaletteSync$1,constants:()=>constants_exports$1,conversion:()=>conversion_exports$1,distance:()=>distance_exports$1,image:()=>image_exports$1,palette:()=>palette_exports$1,quality:()=>quality_exports$1,utils:()=>utils_exports$1});var constants_exports$1={};__export$1(constants_exports$1,{bt709:()=>bt709_exports$1});var bt709_exports$1={};__export$1(bt709_exports$1,{Y:()=>Y$1,x:()=>x$2,y:()=>y$2});var Y$1=(e=>(e[e.RED=.2126]="RED",e[e.GREEN=.7152]="GREEN",e[e.BLUE=.0722]="BLUE",e[e.WHITE=1]="WHITE",e))(Y$1||{}),x$2=(e=>(e[e.RED=.64]="RED",e[e.GREEN=.3]="GREEN",e[e.BLUE=.15]="BLUE",e[e.WHITE=.3127]="WHITE",e))(x$2||{}),y$2=(e=>(e[e.RED=.33]="RED",e[e.GREEN=.6]="GREEN",e[e.BLUE=.06]="BLUE",e[e.WHITE=.329]="WHITE",e))(y$2||{}),conversion_exports$1={};function correctGamma$1(e){return e>.04045?((e+.055)/1.055)**2.4:e/12.92}function rgb2xyz$1(e,t,i){return {x:.4124*(e=correctGamma$1(e/255))+.3576*(t=correctGamma$1(t/255))+.1805*(i=correctGamma$1(i/255)),y:.2126*e+.7152*t+.0722*i,z:.0193*e+.1192*t+.9505*i}}__export$1(conversion_exports$1,{lab2rgb:()=>lab2rgb$1,lab2xyz:()=>lab2xyz$1,rgb2hsl:()=>rgb2hsl$1,rgb2lab:()=>rgb2lab$1,rgb2xyz:()=>rgb2xyz$1,xyz2lab:()=>xyz2lab$1,xyz2rgb:()=>xyz2rgb$1});var arithmetic_exports$1={};function degrees2radians$1(e){return e*(Math.PI/180)}function max3$1(e,t,i){let r=e;return r<t&&(r=t),r<i&&(r=i),r}function min3$1(e,t,i){let r=e;return r>t&&(r=t),r>i&&(r=i),r}function intInRange$1(e,t,i){return e>i&&(e=i),e<t&&(e=t),0|e}function inRange0to255Rounded$1(e){return (e=Math.round(e))>255?e=255:e<0&&(e=0),e}function inRange0to255$1(e){return e>255?e=255:e<0&&(e=0),e}function stableSort$1(e,t){const i=typeof e[0];let r;if("number"===i||"string"===i){const i=Object.create(null);for(let t=0,r=e.length;t<r;t++){const r=e[t];i[r]||0===i[r]||(i[r]=t);}r=e.sort(((e,r)=>t(e,r)||i[e]-i[r]));}else {const i=e.slice(0);r=e.sort(((e,r)=>t(e,r)||i.indexOf(e)-i.indexOf(r)));}return r}function rgb2hsl$1(e,t,i){const r=min3$1(e,t,i),n=max3$1(e,t,i),a=n-r,o=(r+n)/510;let s=0;o>0&&o<1&&(s=a/(o<.5?n+r:510-n-r));let l=0;return a>0&&(l=n===e?(t-i)/a:n===t?2+(i-e)/a:4+(e-t)/a,l*=60,l<0&&(l+=360)),{h:l,s:s,l:o}}__export$1(arithmetic_exports$1,{degrees2radians:()=>degrees2radians$1,inRange0to255:()=>inRange0to255$1,inRange0to255Rounded:()=>inRange0to255Rounded$1,intInRange:()=>intInRange$1,max3:()=>max3$1,min3:()=>min3$1,stableSort:()=>stableSort$1});var refX$1=.95047,refY$1=1,refZ$1=1.08883;function pivot$1(e){return e>.008856?e**(1/3):7.787*e+16/116}function xyz2lab$1(e,t,i){if(e=pivot$1(e/refX$1),t=pivot$1(t/refY$1),i=pivot$1(i/refZ$1),116*t-16<0)throw new Error("xxx");return {L:Math.max(0,116*t-16),a:500*(e-t),b:200*(t-i)}}function rgb2lab$1(e,t,i){const r=rgb2xyz$1(e,t,i);return xyz2lab$1(r.x,r.y,r.z)}var refX2$1=.95047,refY2$1=1,refZ2$1=1.08883;function pivot2$1(e){return e>.206893034?e**3:(e-16/116)/7.787}function lab2xyz$1(e,t,i){const r=(e+16)/116,n=r-i/200;return {x:refX2$1*pivot2$1(t/500+r),y:refY2$1*pivot2$1(r),z:refZ2$1*pivot2$1(n)}}function correctGamma2$1(e){return e>.0031308?1.055*e**(1/2.4)-.055:12.92*e}function xyz2rgb$1(e,t,i){const r=correctGamma2$1(3.2406*e+-1.5372*t+-0.4986*i),n=correctGamma2$1(-0.9689*e+1.8758*t+.0415*i),a=correctGamma2$1(.0557*e+-0.204*t+1.057*i);return {r:inRange0to255Rounded$1(255*r),g:inRange0to255Rounded$1(255*n),b:inRange0to255Rounded$1(255*a)}}function lab2rgb$1(e,t,i){const r=lab2xyz$1(e,t,i);return xyz2rgb$1(r.x,r.y,r.z)}var distance_exports$1={};__export$1(distance_exports$1,{AbstractDistanceCalculator:()=>AbstractDistanceCalculator$1,AbstractEuclidean:()=>AbstractEuclidean$1,AbstractManhattan:()=>AbstractManhattan$1,CIE94GraphicArts:()=>CIE94GraphicArts$1,CIE94Textiles:()=>CIE94Textiles$1,CIEDE2000:()=>CIEDE2000$1,CMetric:()=>CMetric$1,Euclidean:()=>Euclidean$1,EuclideanBT709:()=>EuclideanBT709$1,EuclideanBT709NoAlpha:()=>EuclideanBT709NoAlpha$1,Manhattan:()=>Manhattan$1,ManhattanBT709:()=>ManhattanBT709$1,ManhattanNommyde:()=>ManhattanNommyde$1,PNGQuant:()=>PNGQuant$1});var AbstractDistanceCalculator$1=class{constructor(){__publicField$3(this,"_maxDistance"),__publicField$3(this,"_whitePoint"),this._setDefaults(),this.setWhitePoint(255,255,255,255);}setWhitePoint(e,t,i,r){this._whitePoint={r:e>0?255/e:0,g:t>0?255/t:0,b:i>0?255/i:0,a:r>0?255/r:0},this._maxDistance=this.calculateRaw(e,t,i,r,0,0,0,0);}calculateNormalized(e,t){return this.calculateRaw(e.r,e.g,e.b,e.a,t.r,t.g,t.b,t.a)/this._maxDistance}},AbstractCIE94$1=class extends AbstractDistanceCalculator$1{calculateRaw(e,t,i,r,n,a,o,s){const l=rgb2lab$1(inRange0to255$1(e*this._whitePoint.r),inRange0to255$1(t*this._whitePoint.g),inRange0to255$1(i*this._whitePoint.b)),u=rgb2lab$1(inRange0to255$1(n*this._whitePoint.r),inRange0to255$1(a*this._whitePoint.g),inRange0to255$1(o*this._whitePoint.b)),h=l.L-u.L,c=l.a-u.a,f=l.b-u.b,d=Math.sqrt(l.a*l.a+l.b*l.b),p=d-Math.sqrt(u.a*u.a+u.b*u.b);let m=c*c+f*f-p*p;m=m<0?0:Math.sqrt(m);const _=(s-r)*this._whitePoint.a*this._kA;return Math.sqrt((h/this._Kl)**2+(p/(1+this._K1*d))**2+(m/(1+this._K2*d))**2+_**2)}},CIE94Textiles$1=class extends AbstractCIE94$1{_setDefaults(){this._Kl=2,this._K1=.048,this._K2=.014,this._kA=12.5/255;}},CIE94GraphicArts$1=class extends AbstractCIE94$1{_setDefaults(){this._Kl=1,this._K1=.045,this._K2=.015,this._kA=25/255;}},_CIEDE2000$1=class extends AbstractDistanceCalculator$1{_setDefaults(){}static _calculatehp(e,t){const i=Math.atan2(e,t);return i>=0?i:i+_CIEDE2000$1._deg360InRad}static _calculateRT(e,t){const i=t**7,r=2*Math.sqrt(i/(i+_CIEDE2000$1._pow25to7)),n=_CIEDE2000$1._deg30InRad*Math.exp(-(((e-_CIEDE2000$1._deg275InRad)/_CIEDE2000$1._deg25InRad)**2));return -Math.sin(2*n)*r}static _calculateT(e){return 1-.17*Math.cos(e-_CIEDE2000$1._deg30InRad)+.24*Math.cos(2*e)+.32*Math.cos(3*e+_CIEDE2000$1._deg6InRad)-.2*Math.cos(4*e-_CIEDE2000$1._deg63InRad)}static _calculate_ahp(e,t,i,r){const n=i+r;return 0===e?n:t<=_CIEDE2000$1._deg180InRad?n/2:n<_CIEDE2000$1._deg360InRad?(n+_CIEDE2000$1._deg360InRad)/2:(n-_CIEDE2000$1._deg360InRad)/2}static _calculate_dHp(e,t,i,r){let n;return n=0===e?0:t<=_CIEDE2000$1._deg180InRad?i-r:i<=r?i-r+_CIEDE2000$1._deg360InRad:i-r-_CIEDE2000$1._deg360InRad,2*Math.sqrt(e)*Math.sin(n/2)}calculateRaw(e,t,i,r,n,a,o,s){const l=rgb2lab$1(inRange0to255$1(e*this._whitePoint.r),inRange0to255$1(t*this._whitePoint.g),inRange0to255$1(i*this._whitePoint.b)),u=rgb2lab$1(inRange0to255$1(n*this._whitePoint.r),inRange0to255$1(a*this._whitePoint.g),inRange0to255$1(o*this._whitePoint.b)),h=(s-r)*this._whitePoint.a*_CIEDE2000$1._kA,c=this.calculateRawInLab(l,u);return Math.sqrt(c+h*h)}calculateRawInLab(e,t){const i=e.L,r=e.a,n=e.b,a=t.L,o=t.a,s=t.b,l=((Math.sqrt(r*r+n*n)+Math.sqrt(o*o+s*s))/2)**7,u=.5*(1-Math.sqrt(l/(l+_CIEDE2000$1._pow25to7))),h=(1+u)*r,c=(1+u)*o,f=Math.sqrt(h*h+n*n),d=Math.sqrt(c*c+s*s),p=f*d,m=_CIEDE2000$1._calculatehp(n,h),_=_CIEDE2000$1._calculatehp(s,c),g=Math.abs(m-_),b=a-i,y=d-f,w=_CIEDE2000$1._calculate_dHp(p,g,_,m),v=_CIEDE2000$1._calculate_ahp(p,g,m,_),x=(f+d)/2,E=((i+a)/2-50)**2,k=y/(1+.045*x),S=w/(1+.015*_CIEDE2000$1._calculateT(v)*x);return (b/(1+.015*E/Math.sqrt(20+E)))**2+k**2+S**2+_CIEDE2000$1._calculateRT(v,x)*k*S}},CIEDE2000$1=_CIEDE2000$1;__publicField$3(CIEDE2000$1,"_kA",25/255),__publicField$3(CIEDE2000$1,"_pow25to7",25**7),__publicField$3(CIEDE2000$1,"_deg360InRad",degrees2radians$1(360)),__publicField$3(CIEDE2000$1,"_deg180InRad",degrees2radians$1(180)),__publicField$3(CIEDE2000$1,"_deg30InRad",degrees2radians$1(30)),__publicField$3(CIEDE2000$1,"_deg6InRad",degrees2radians$1(6)),__publicField$3(CIEDE2000$1,"_deg63InRad",degrees2radians$1(63)),__publicField$3(CIEDE2000$1,"_deg275InRad",degrees2radians$1(275)),__publicField$3(CIEDE2000$1,"_deg25InRad",degrees2radians$1(25));var CMetric$1=class extends AbstractDistanceCalculator$1{calculateRaw(e,t,i,r,n,a,o,s){const l=(e+n)/2*this._whitePoint.r,u=(e-n)*this._whitePoint.r,h=(t-a)*this._whitePoint.g,c=(i-o)*this._whitePoint.b,f=((512+l)*u*u>>8)+4*h*h+((767-l)*c*c>>8),d=(s-r)*this._whitePoint.a;return Math.sqrt(f+d*d)}_setDefaults(){}},AbstractEuclidean$1=class extends AbstractDistanceCalculator$1{calculateRaw(e,t,i,r,n,a,o,s){const l=n-e,u=a-t,h=o-i,c=s-r;return Math.sqrt(this._kR*l*l+this._kG*u*u+this._kB*h*h+this._kA*c*c)}},Euclidean$1=class extends AbstractEuclidean$1{_setDefaults(){this._kR=1,this._kG=1,this._kB=1,this._kA=1;}},EuclideanBT709$1=class extends AbstractEuclidean$1{_setDefaults(){this._kR=.2126,this._kG=.7152,this._kB=.0722,this._kA=1;}},EuclideanBT709NoAlpha$1=class extends AbstractEuclidean$1{_setDefaults(){this._kR=.2126,this._kG=.7152,this._kB=.0722,this._kA=0;}},AbstractManhattan$1=class extends AbstractDistanceCalculator$1{calculateRaw(e,t,i,r,n,a,o,s){let l=n-e,u=a-t,h=o-i,c=s-r;return l<0&&(l=0-l),u<0&&(u=0-u),h<0&&(h=0-h),c<0&&(c=0-c),this._kR*l+this._kG*u+this._kB*h+this._kA*c}},Manhattan$1=class extends AbstractManhattan$1{_setDefaults(){this._kR=1,this._kG=1,this._kB=1,this._kA=1;}},ManhattanNommyde$1=class extends AbstractManhattan$1{_setDefaults(){this._kR=.4984,this._kG=.8625,this._kB=.2979,this._kA=1;}},ManhattanBT709$1=class extends AbstractManhattan$1{_setDefaults(){this._kR=.2126,this._kG=.7152,this._kB=.0722,this._kA=1;}},PNGQuant$1=class extends AbstractDistanceCalculator$1{calculateRaw(e,t,i,r,n,a,o,s){const l=(s-r)*this._whitePoint.a;return this._colordifferenceCh(e*this._whitePoint.r,n*this._whitePoint.r,l)+this._colordifferenceCh(t*this._whitePoint.g,a*this._whitePoint.g,l)+this._colordifferenceCh(i*this._whitePoint.b,o*this._whitePoint.b,l)}_colordifferenceCh(e,t,i){const r=e-t,n=r+i;return r*r+n*n}_setDefaults(){}},palette_exports$1={};__export$1(palette_exports$1,{AbstractPaletteQuantizer:()=>AbstractPaletteQuantizer$1,ColorHistogram:()=>ColorHistogram$1,NeuQuant:()=>NeuQuant$1,NeuQuantFloat:()=>NeuQuantFloat$1,RGBQuant:()=>RGBQuant$1,WuColorCube:()=>WuColorCube$1,WuQuant:()=>WuQuant$1});var AbstractPaletteQuantizer$1=class{quantizeSync(){for(const e of this.quantize())if(e.palette)return e.palette;throw new Error("unreachable")}},Point$1=class{constructor(){__publicField$3(this,"r"),__publicField$3(this,"g"),__publicField$3(this,"b"),__publicField$3(this,"a"),__publicField$3(this,"uint32"),__publicField$3(this,"rgba"),this.uint32=-1>>>0,this.r=this.g=this.b=this.a=0,this.rgba=new Array(4),this.rgba[0]=0,this.rgba[1]=0,this.rgba[2]=0,this.rgba[3]=0;}static createByQuadruplet(e){const t=new Point$1;return t.r=0|e[0],t.g=0|e[1],t.b=0|e[2],t.a=0|e[3],t._loadUINT32(),t._loadQuadruplet(),t}static createByRGBA(e,t,i,r){const n=new Point$1;return n.r=0|e,n.g=0|t,n.b=0|i,n.a=0|r,n._loadUINT32(),n._loadQuadruplet(),n}static createByUint32(e){const t=new Point$1;return t.uint32=e>>>0,t._loadRGBA(),t._loadQuadruplet(),t}from(e){this.r=e.r,this.g=e.g,this.b=e.b,this.a=e.a,this.uint32=e.uint32,this.rgba[0]=e.r,this.rgba[1]=e.g,this.rgba[2]=e.b,this.rgba[3]=e.a;}getLuminosity(e){let t=this.r,i=this.g,r=this.b;return e&&(t=Math.min(255,255-this.a+this.a*t/255),i=Math.min(255,255-this.a+this.a*i/255),r=Math.min(255,255-this.a+this.a*r/255)),.2126*t+.7152*i+.0722*r}_loadUINT32(){this.uint32=(this.a<<24|this.b<<16|this.g<<8|this.r)>>>0;}_loadRGBA(){this.r=255&this.uint32,this.g=this.uint32>>>8&255,this.b=this.uint32>>>16&255,this.a=this.uint32>>>24&255;}_loadQuadruplet(){this.rgba[0]=this.r,this.rgba[1]=this.g,this.rgba[2]=this.b,this.rgba[3]=this.a;}},PointContainer$1=class{constructor(){__publicField$3(this,"_pointArray"),__publicField$3(this,"_width"),__publicField$3(this,"_height"),this._width=0,this._height=0,this._pointArray=[];}getWidth(){return this._width}getHeight(){return this._height}setWidth(e){this._width=e;}setHeight(e){this._height=e;}getPointArray(){return this._pointArray}clone(){const e=new PointContainer$1;e._width=this._width,e._height=this._height;for(let t=0,i=this._pointArray.length;t<i;t++)e._pointArray[t]=Point$1.createByUint32(0|this._pointArray[t].uint32);return e}toUint32Array(){const e=this._pointArray.length,t=new Uint32Array(e);for(let i=0;i<e;i++)t[i]=this._pointArray[i].uint32;return t}toUint8Array(){return new Uint8Array(this.toUint32Array().buffer)}static fromHTMLImageElement(e){const t=e.naturalWidth,i=e.naturalHeight,r=document.createElement("canvas");r.width=t,r.height=i;return r.getContext("2d").drawImage(e,0,0,t,i,0,0,t,i),PointContainer$1.fromHTMLCanvasElement(r)}static fromHTMLCanvasElement(e){const t=e.width,i=e.height,r=e.getContext("2d").getImageData(0,0,t,i);return PointContainer$1.fromImageData(r)}static fromImageData(e){const t=e.width,i=e.height;return PointContainer$1.fromUint8Array(e.data,t,i)}static fromUint8Array(e,t,i){switch(Object.prototype.toString.call(e)){case "[object Uint8ClampedArray]":case "[object Uint8Array]":break;default:e=new Uint8Array(e);}const r=new Uint32Array(e.buffer);return PointContainer$1.fromUint32Array(r,t,i)}static fromUint32Array(e,t,i){const r=new PointContainer$1;r._width=t,r._height=i;for(let t=0,i=e.length;t<i;t++)r._pointArray[t]=Point$1.createByUint32(0|e[t]);return r}static fromBuffer(e,t,i){const r=new Uint32Array(e.buffer,e.byteOffset,e.byteLength/Uint32Array.BYTES_PER_ELEMENT);return PointContainer$1.fromUint32Array(r,t,i)}},hueGroups$1=10;function hueGroup$1(e,t){const i=360/t;for(let r=1,n=i-i/2;r<t;r++,n+=i)if(e>=n&&e<n+i)return r;return 0}var Palette$1=class{constructor(){__publicField$3(this,"_pointContainer"),__publicField$3(this,"_pointArray",[]),__publicField$3(this,"_i32idx",{}),this._pointContainer=new PointContainer$1,this._pointContainer.setHeight(1),this._pointArray=this._pointContainer.getPointArray();}add(e){this._pointArray.push(e),this._pointContainer.setWidth(this._pointArray.length);}has(e){for(let t=this._pointArray.length-1;t>=0;t--)if(e.uint32===this._pointArray[t].uint32)return true;return false}getNearestColor(e,t){return this._pointArray[0|this._getNearestIndex(e,t)]}getPointContainer(){return this._pointContainer}_nearestPointFromCache(e){return "number"==typeof this._i32idx[e]?this._i32idx[e]:-1}_getNearestIndex(e,t){let i=this._nearestPointFromCache(""+t.uint32);if(i>=0)return i;let r=Number.MAX_VALUE;i=0;for(let n=0,a=this._pointArray.length;n<a;n++){const a=this._pointArray[n],o=e.calculateRaw(t.r,t.g,t.b,t.a,a.r,a.g,a.b,a.a);o<r&&(r=o,i=n);}return this._i32idx[t.uint32]=i,i}sort(){this._i32idx={},this._pointArray.sort(((e,t)=>{const i=rgb2hsl$1(e.r,e.g,e.b),r=rgb2hsl$1(t.r,t.g,t.b),n=e.r===e.g&&e.g===e.b?0:1+hueGroup$1(i.h,hueGroups$1),a=(t.r===t.g&&t.g===t.b?0:1+hueGroup$1(r.h,hueGroups$1))-n;if(a)return -a;const o=e.getLuminosity(true),s=t.getLuminosity(true);if(s-o!=0)return s-o;const l=(100*r.s|0)-(100*i.s|0);return l?-l:0}));}},utils_exports$1={};__export$1(utils_exports$1,{HueStatistics:()=>HueStatistics$1,Palette:()=>Palette$1,Point:()=>Point$1,PointContainer:()=>PointContainer$1,ProgressTracker:()=>ProgressTracker$1,arithmetic:()=>arithmetic_exports$1});var HueGroup$1=class{constructor(){__publicField$3(this,"num",0),__publicField$3(this,"cols",[]);}},HueStatistics$1=class{constructor(e,t){__publicField$3(this,"_numGroups"),__publicField$3(this,"_minCols"),__publicField$3(this,"_stats"),__publicField$3(this,"_groupsFull"),this._numGroups=e,this._minCols=t,this._stats=[];for(let t=0;t<=e;t++)this._stats[t]=new HueGroup$1;this._groupsFull=0;}check(e){this._groupsFull===this._numGroups+1&&(this.check=()=>{});const t=255&e,i=e>>>8&255,r=e>>>16&255,n=t===i&&i===r?0:1+hueGroup$1(rgb2hsl$1(t,i,r).h,this._numGroups),a=this._stats[n],o=this._minCols;a.num++,a.num>o||(a.num===o&&this._groupsFull++,a.num<=o&&this._stats[n].cols.push(e));}injectIntoDictionary(e){for(let t=0;t<=this._numGroups;t++)this._stats[t].num<=this._minCols&&this._stats[t].cols.forEach((t=>{e[t]?e[t]++:e[t]=1;}));}injectIntoArray(e){for(let t=0;t<=this._numGroups;t++)this._stats[t].num<=this._minCols&&this._stats[t].cols.forEach((t=>{ -1===e.indexOf(t)&&e.push(t);}));}},_ProgressTracker$1=class{constructor(e,t){__publicField$3(this,"progress"),__publicField$3(this,"_step"),__publicField$3(this,"_range"),__publicField$3(this,"_last"),__publicField$3(this,"_progressRange"),this._range=e,this._progressRange=t,this._step=Math.max(1,this._range/(_ProgressTracker$1.steps+1)|0),this._last=-this._step,this.progress=0;}shouldNotify(e){return e-this._last>=this._step&&(this._last=e,this.progress=Math.min(this._progressRange*this._last/this._range,this._progressRange),true)}},ProgressTracker$1=_ProgressTracker$1;__publicField$3(ProgressTracker$1,"steps",100);var networkBiasShift$1=3,Neuron$1=class{constructor(e){__publicField$3(this,"r"),__publicField$3(this,"g"),__publicField$3(this,"b"),__publicField$3(this,"a"),this.r=this.g=this.b=this.a=e;}toPoint(){return Point$1.createByRGBA(this.r>>networkBiasShift$1,this.g>>networkBiasShift$1,this.b>>networkBiasShift$1,this.a>>networkBiasShift$1)}subtract(e,t,i,r){this.r-=0|e,this.g-=0|t,this.b-=0|i,this.a-=0|r;}},_NeuQuant$1=class extends AbstractPaletteQuantizer$1{constructor(e,t=256){super(),__publicField$3(this,"_pointArray"),__publicField$3(this,"_networkSize"),__publicField$3(this,"_network"),__publicField$3(this,"_sampleFactor"),__publicField$3(this,"_radPower"),__publicField$3(this,"_freq"),__publicField$3(this,"_bias"),__publicField$3(this,"_distance"),this._distance=e,this._pointArray=[],this._sampleFactor=1,this._networkSize=t,this._distance.setWhitePoint(255<<networkBiasShift$1,255<<networkBiasShift$1,255<<networkBiasShift$1,255<<networkBiasShift$1);}sample(e){this._pointArray=this._pointArray.concat(e.getPointArray());}*quantize(){this._init(),yield*this._learn(),yield {palette:this._buildPalette(),progress:100};}_init(){this._freq=[],this._bias=[],this._radPower=[],this._network=[];for(let e=0;e<this._networkSize;e++)this._network[e]=new Neuron$1((e<<networkBiasShift$1+8)/this._networkSize|0),this._freq[e]=_NeuQuant$1._initialBias/this._networkSize|0,this._bias[e]=0;}*_learn(){let e=this._sampleFactor;const t=this._pointArray.length;t<_NeuQuant$1._minpicturebytes&&(e=1);const i=30+(e-1)/3|0,r=t/e|0;let n,a=r/_NeuQuant$1._nCycles|0,o=_NeuQuant$1._initAlpha,s=(this._networkSize>>3)*_NeuQuant$1._radiusBias,l=s>>_NeuQuant$1._radiusBiasShift;l<=1&&(l=0);for(let e=0;e<l;e++)this._radPower[e]=o*((l*l-e*e)*_NeuQuant$1._radBias/(l*l))>>>0;n=t<_NeuQuant$1._minpicturebytes?1:t%_NeuQuant$1._prime1!=0?_NeuQuant$1._prime1:t%_NeuQuant$1._prime2!=0?_NeuQuant$1._prime2:t%_NeuQuant$1._prime3!=0?_NeuQuant$1._prime3:_NeuQuant$1._prime4;const u=new ProgressTracker$1(r,99);for(let e=0,h=0;e<r;){u.shouldNotify(e)&&(yield {progress:u.progress});const r=this._pointArray[h],c=r.b<<networkBiasShift$1,f=r.g<<networkBiasShift$1,d=r.r<<networkBiasShift$1,p=r.a<<networkBiasShift$1,m=this._contest(c,f,d,p);if(this._alterSingle(o,m,c,f,d,p),0!==l&&this._alterNeighbour(l,m,c,f,d,p),h+=n,h>=t&&(h-=t),e++,0===a&&(a=1),e%a==0){o-=o/i|0,s-=s/_NeuQuant$1._radiusDecrease|0,l=s>>_NeuQuant$1._radiusBiasShift,l<=1&&(l=0);for(let e=0;e<l;e++)this._radPower[e]=o*((l*l-e*e)*_NeuQuant$1._radBias/(l*l))>>>0;}}}_buildPalette(){const e=new Palette$1;return this._network.forEach((t=>{e.add(t.toPoint());})),e.sort(),e}_alterNeighbour(e,t,i,r,n,a){let o=t-e;o<-1&&(o=-1);let s=t+e;s>this._networkSize&&(s=this._networkSize);let l=t+1,u=t-1,h=1;for(;l<s||u>o;){const e=this._radPower[h++]/_NeuQuant$1._alphaRadBias;if(l<s){const t=this._network[l++];t.subtract(e*(t.r-n),e*(t.g-r),e*(t.b-i),e*(t.a-a));}if(u>o){const t=this._network[u--];t.subtract(e*(t.r-n),e*(t.g-r),e*(t.b-i),e*(t.a-a));}}}_alterSingle(e,t,i,r,n,a){e/=_NeuQuant$1._initAlpha;const o=this._network[t];o.subtract(e*(o.r-n),e*(o.g-r),e*(o.b-i),e*(o.a-a));}_contest(e,t,i,r){const n=1020<<networkBiasShift$1;let a=2147483647,o=a,s=-1,l=s;for(let u=0;u<this._networkSize;u++){const h=this._network[u],c=this._distance.calculateNormalized(h,{r:i,g:t,b:e,a:r})*n|0;c<a&&(a=c,s=u);const f=c-(this._bias[u]>>_NeuQuant$1._initialBiasShift-networkBiasShift$1);f<o&&(o=f,l=u);const d=this._freq[u]>>_NeuQuant$1._betaShift;this._freq[u]-=d,this._bias[u]+=d<<_NeuQuant$1._gammaShift;}return this._freq[s]+=_NeuQuant$1._beta,this._bias[s]-=_NeuQuant$1._betaGamma,l}},NeuQuant$1=_NeuQuant$1;__publicField$3(NeuQuant$1,"_prime1",499),__publicField$3(NeuQuant$1,"_prime2",491),__publicField$3(NeuQuant$1,"_prime3",487),__publicField$3(NeuQuant$1,"_prime4",503),__publicField$3(NeuQuant$1,"_minpicturebytes",_NeuQuant$1._prime4),__publicField$3(NeuQuant$1,"_nCycles",100),__publicField$3(NeuQuant$1,"_initialBiasShift",16),__publicField$3(NeuQuant$1,"_initialBias",1<<_NeuQuant$1._initialBiasShift),__publicField$3(NeuQuant$1,"_gammaShift",10),__publicField$3(NeuQuant$1,"_betaShift",10),__publicField$3(NeuQuant$1,"_beta",_NeuQuant$1._initialBias>>_NeuQuant$1._betaShift),__publicField$3(NeuQuant$1,"_betaGamma",_NeuQuant$1._initialBias<<_NeuQuant$1._gammaShift-_NeuQuant$1._betaShift),__publicField$3(NeuQuant$1,"_radiusBiasShift",6),__publicField$3(NeuQuant$1,"_radiusBias",1<<_NeuQuant$1._radiusBiasShift),__publicField$3(NeuQuant$1,"_radiusDecrease",30),__publicField$3(NeuQuant$1,"_alphaBiasShift",10),__publicField$3(NeuQuant$1,"_initAlpha",1<<_NeuQuant$1._alphaBiasShift),__publicField$3(NeuQuant$1,"_radBiasShift",8),__publicField$3(NeuQuant$1,"_radBias",1<<_NeuQuant$1._radBiasShift),__publicField$3(NeuQuant$1,"_alphaRadBiasShift",_NeuQuant$1._alphaBiasShift+_NeuQuant$1._radBiasShift),__publicField$3(NeuQuant$1,"_alphaRadBias",1<<_NeuQuant$1._alphaRadBiasShift);var networkBiasShift2$1=3,NeuronFloat$1=class{constructor(e){__publicField$3(this,"r"),__publicField$3(this,"g"),__publicField$3(this,"b"),__publicField$3(this,"a"),this.r=this.g=this.b=this.a=e;}toPoint(){return Point$1.createByRGBA(this.r>>networkBiasShift2$1,this.g>>networkBiasShift2$1,this.b>>networkBiasShift2$1,this.a>>networkBiasShift2$1)}subtract(e,t,i,r){this.r-=e,this.g-=t,this.b-=i,this.a-=r;}},_NeuQuantFloat$1=class extends AbstractPaletteQuantizer$1{constructor(e,t=256){super(),__publicField$3(this,"_pointArray"),__publicField$3(this,"_networkSize"),__publicField$3(this,"_network"),__publicField$3(this,"_sampleFactor"),__publicField$3(this,"_radPower"),__publicField$3(this,"_freq"),__publicField$3(this,"_bias"),__publicField$3(this,"_distance"),this._distance=e,this._pointArray=[],this._sampleFactor=1,this._networkSize=t,this._distance.setWhitePoint(255<<networkBiasShift2$1,255<<networkBiasShift2$1,255<<networkBiasShift2$1,255<<networkBiasShift2$1);}sample(e){this._pointArray=this._pointArray.concat(e.getPointArray());}*quantize(){this._init(),yield*this._learn(),yield {palette:this._buildPalette(),progress:100};}_init(){this._freq=[],this._bias=[],this._radPower=[],this._network=[];for(let e=0;e<this._networkSize;e++)this._network[e]=new NeuronFloat$1((e<<networkBiasShift2$1+8)/this._networkSize),this._freq[e]=_NeuQuantFloat$1._initialBias/this._networkSize,this._bias[e]=0;}*_learn(){let e=this._sampleFactor;const t=this._pointArray.length;t<_NeuQuantFloat$1._minpicturebytes&&(e=1);const i=30+(e-1)/3,r=t/e;let n,a=r/_NeuQuantFloat$1._nCycles|0,o=_NeuQuantFloat$1._initAlpha,s=(this._networkSize>>3)*_NeuQuantFloat$1._radiusBias,l=s>>_NeuQuantFloat$1._radiusBiasShift;l<=1&&(l=0);for(let e=0;e<l;e++)this._radPower[e]=o*((l*l-e*e)*_NeuQuantFloat$1._radBias/(l*l));n=t<_NeuQuantFloat$1._minpicturebytes?1:t%_NeuQuantFloat$1._prime1!=0?_NeuQuantFloat$1._prime1:t%_NeuQuantFloat$1._prime2!=0?_NeuQuantFloat$1._prime2:t%_NeuQuantFloat$1._prime3!=0?_NeuQuantFloat$1._prime3:_NeuQuantFloat$1._prime4;const u=new ProgressTracker$1(r,99);for(let e=0,h=0;e<r;){u.shouldNotify(e)&&(yield {progress:u.progress});const r=this._pointArray[h],c=r.b<<networkBiasShift2$1,f=r.g<<networkBiasShift2$1,d=r.r<<networkBiasShift2$1,p=r.a<<networkBiasShift2$1,m=this._contest(c,f,d,p);if(this._alterSingle(o,m,c,f,d,p),0!==l&&this._alterNeighbour(l,m,c,f,d,p),h+=n,h>=t&&(h-=t),e++,0===a&&(a=1),e%a==0){o-=o/i,s-=s/_NeuQuantFloat$1._radiusDecrease,l=s>>_NeuQuantFloat$1._radiusBiasShift,l<=1&&(l=0);for(let e=0;e<l;e++)this._radPower[e]=o*((l*l-e*e)*_NeuQuantFloat$1._radBias/(l*l));}}}_buildPalette(){const e=new Palette$1;return this._network.forEach((t=>{e.add(t.toPoint());})),e.sort(),e}_alterNeighbour(e,t,i,r,n,a){let o=t-e;o<-1&&(o=-1);let s=t+e;s>this._networkSize&&(s=this._networkSize);let l=t+1,u=t-1,h=1;for(;l<s||u>o;){const e=this._radPower[h++]/_NeuQuantFloat$1._alphaRadBias;if(l<s){const t=this._network[l++];t.subtract(e*(t.r-n),e*(t.g-r),e*(t.b-i),e*(t.a-a));}if(u>o){const t=this._network[u--];t.subtract(e*(t.r-n),e*(t.g-r),e*(t.b-i),e*(t.a-a));}}}_alterSingle(e,t,i,r,n,a){e/=_NeuQuantFloat$1._initAlpha;const o=this._network[t];o.subtract(e*(o.r-n),e*(o.g-r),e*(o.b-i),e*(o.a-a));}_contest(e,t,i,r){const n=1020<<networkBiasShift2$1;let a=2147483647,o=a,s=-1,l=s;for(let u=0;u<this._networkSize;u++){const h=this._network[u],c=this._distance.calculateNormalized(h,{r:i,g:t,b:e,a:r})*n;c<a&&(a=c,s=u);const f=c-(this._bias[u]>>_NeuQuantFloat$1._initialBiasShift-networkBiasShift2$1);f<o&&(o=f,l=u);const d=this._freq[u]>>_NeuQuantFloat$1._betaShift;this._freq[u]-=d,this._bias[u]+=d<<_NeuQuantFloat$1._gammaShift;}return this._freq[s]+=_NeuQuantFloat$1._beta,this._bias[s]-=_NeuQuantFloat$1._betaGamma,l}},NeuQuantFloat$1=_NeuQuantFloat$1;__publicField$3(NeuQuantFloat$1,"_prime1",499),__publicField$3(NeuQuantFloat$1,"_prime2",491),__publicField$3(NeuQuantFloat$1,"_prime3",487),__publicField$3(NeuQuantFloat$1,"_prime4",503),__publicField$3(NeuQuantFloat$1,"_minpicturebytes",_NeuQuantFloat$1._prime4),__publicField$3(NeuQuantFloat$1,"_nCycles",100),__publicField$3(NeuQuantFloat$1,"_initialBiasShift",16),__publicField$3(NeuQuantFloat$1,"_initialBias",1<<_NeuQuantFloat$1._initialBiasShift),__publicField$3(NeuQuantFloat$1,"_gammaShift",10),__publicField$3(NeuQuantFloat$1,"_betaShift",10),__publicField$3(NeuQuantFloat$1,"_beta",_NeuQuantFloat$1._initialBias>>_NeuQuantFloat$1._betaShift),__publicField$3(NeuQuantFloat$1,"_betaGamma",_NeuQuantFloat$1._initialBias<<_NeuQuantFloat$1._gammaShift-_NeuQuantFloat$1._betaShift),__publicField$3(NeuQuantFloat$1,"_radiusBiasShift",6),__publicField$3(NeuQuantFloat$1,"_radiusBias",1<<_NeuQuantFloat$1._radiusBiasShift),__publicField$3(NeuQuantFloat$1,"_radiusDecrease",30),__publicField$3(NeuQuantFloat$1,"_alphaBiasShift",10),__publicField$3(NeuQuantFloat$1,"_initAlpha",1<<_NeuQuantFloat$1._alphaBiasShift),__publicField$3(NeuQuantFloat$1,"_radBiasShift",8),__publicField$3(NeuQuantFloat$1,"_radBias",1<<_NeuQuantFloat$1._radBiasShift),__publicField$3(NeuQuantFloat$1,"_alphaRadBiasShift",_NeuQuantFloat$1._alphaBiasShift+_NeuQuantFloat$1._radBiasShift),__publicField$3(NeuQuantFloat$1,"_alphaRadBias",1<<_NeuQuantFloat$1._alphaRadBiasShift);var _ColorHistogram$1=class{constructor(e,t){__publicField$3(this,"_method"),__publicField$3(this,"_hueStats"),__publicField$3(this,"_histogram"),__publicField$3(this,"_initColors"),__publicField$3(this,"_minHueCols"),this._method=e,this._minHueCols=t<<2,this._initColors=t<<2,this._hueStats=new HueStatistics$1(_ColorHistogram$1._hueGroups,this._minHueCols),this._histogram=Object.create(null);}sample(e){switch(this._method){case 1:this._colorStats1D(e);break;case 2:this._colorStats2D(e);}}getImportanceSortedColorsIDXI32(){const e=stableSort$1(Object.keys(this._histogram),((e,t)=>this._histogram[t]-this._histogram[e]));if(0===e.length)return [];let t;switch(this._method){case 1:const i=Math.min(e.length,this._initColors),r=e[i-1],n=this._histogram[r];t=e.slice(0,i);let a=i;const o=e.length;for(;a<o&&this._histogram[e[a]]===n;)t.push(e[a++]);this._hueStats.injectIntoArray(t);break;case 2:t=e;break;default:throw new Error("Incorrect method")}return t.map((e=>+e))}_colorStats1D(e){const t=this._histogram,i=e.getPointArray(),r=i.length;for(let e=0;e<r;e++){const r=i[e].uint32;this._hueStats.check(r),r in t?t[r]++:t[r]=1;}}_colorStats2D(e){const t=e.getWidth(),i=e.getHeight(),r=e.getPointArray(),n=_ColorHistogram$1._boxSize[0],a=_ColorHistogram$1._boxSize[1],o=n*a,s=this._makeBoxes(t,i,n,a),l=this._histogram;s.forEach((e=>{let i=Math.round(e.w*e.h/o)*_ColorHistogram$1._boxPixels;i<2&&(i=2);const n={};this._iterateBox(e,t,(e=>{const t=r[e].uint32;this._hueStats.check(t),t in l?l[t]++:t in n?++n[t]>=i&&(l[t]=n[t]):n[t]=1;}));})),this._hueStats.injectIntoDictionary(l);}_iterateBox(e,t,i){const r=e,n=r.y*t+r.x,a=(r.y+r.h-1)*t+(r.x+r.w-1),o=t-r.w+1;let s=0,l=n;do{i.call(this,l),l+=++s%r.w==0?o:1;}while(l<=a)}_makeBoxes(e,t,i,r){const n=e%i,a=t%r,o=e-n,s=t-a,l=[];for(let u=0;u<t;u+=r)for(let t=0;t<e;t+=i)l.push({x:t,y:u,w:t===o?n:i,h:u===s?a:r});return l}},ColorHistogram$1=_ColorHistogram$1;__publicField$3(ColorHistogram$1,"_boxSize",[64,64]),__publicField$3(ColorHistogram$1,"_boxPixels",2),__publicField$3(ColorHistogram$1,"_hueGroups",10);var RemovedColor$1=class{constructor(e,t,i){__publicField$3(this,"index"),__publicField$3(this,"color"),__publicField$3(this,"distance"),this.index=e,this.color=t,this.distance=i;}},RGBQuant$1=class extends AbstractPaletteQuantizer$1{constructor(e,t=256,i=2){super(),__publicField$3(this,"_colors"),__publicField$3(this,"_initialDistance"),__publicField$3(this,"_distanceIncrement"),__publicField$3(this,"_histogram"),__publicField$3(this,"_distance"),this._distance=e,this._colors=t,this._histogram=new ColorHistogram$1(i,t),this._initialDistance=.01,this._distanceIncrement=.005;}sample(e){this._histogram.sample(e);}*quantize(){const e=this._histogram.getImportanceSortedColorsIDXI32();if(0===e.length)throw new Error("No colors in image");yield*this._buildPalette(e);}*_buildPalette(e){const t=new Palette$1,i=t.getPointContainer().getPointArray(),r=new Array(e.length);for(let t=0;t<e.length;t++)i.push(Point$1.createByUint32(e[t])),r[t]=1;const n=i.length,a=[];let o=n,s=this._initialDistance;const l=new ProgressTracker$1(o-this._colors,99);for(;o>this._colors;){a.length=0;for(let e=0;e<n;e++){if(l.shouldNotify(n-o)&&(yield {progress:l.progress}),0===r[e])continue;const t=i[e];for(let l=e+1;l<n;l++){if(0===r[l])continue;const e=i[l],n=this._distance.calculateNormalized(t,e);n<s&&(a.push(new RemovedColor$1(l,e,n)),r[l]=0,o--);}}s+=o>3*this._colors?this._initialDistance:this._distanceIncrement;}if(o<this._colors){stableSort$1(a,((e,t)=>t.distance-e.distance));let e=0;for(;o<this._colors&&e<a.length;){r[a[e].index]=1,o++,e++;}}let u=i.length;for(let e=u-1;e>=0;e--)0===r[e]&&(e!==u-1&&(i[e]=i[u-1]),--u);i.length=u,t.sort(),yield {palette:t,progress:100};}};function createArray1D$1(e){const t=[];for(let i=0;i<e;i++)t[i]=0;return t}function createArray4D$1(e,t,i,r){const n=new Array(e);for(let a=0;a<e;a++){n[a]=new Array(t);for(let e=0;e<t;e++){n[a][e]=new Array(i);for(let t=0;t<i;t++){n[a][e][t]=new Array(r);for(let i=0;i<r;i++)n[a][e][t][i]=0;}}}return n}function createArray3D$1(e,t,i){const r=new Array(e);for(let n=0;n<e;n++){r[n]=new Array(t);for(let e=0;e<t;e++){r[n][e]=new Array(i);for(let t=0;t<i;t++)r[n][e][t]=0;}}return r}function fillArray3D$1(e,t,i,r,n){for(let a=0;a<t;a++){e[a]=[];for(let t=0;t<i;t++){e[a][t]=[];for(let i=0;i<r;i++)e[a][t][i]=n;}}}function fillArray1D$1(e,t,i){for(let r=0;r<t;r++)e[r]=i;}var WuColorCube$1=class{constructor(){__publicField$3(this,"redMinimum"),__publicField$3(this,"redMaximum"),__publicField$3(this,"greenMinimum"),__publicField$3(this,"greenMaximum"),__publicField$3(this,"blueMinimum"),__publicField$3(this,"blueMaximum"),__publicField$3(this,"volume"),__publicField$3(this,"alphaMinimum"),__publicField$3(this,"alphaMaximum");}},_WuQuant$1=class extends AbstractPaletteQuantizer$1{constructor(e,t=256,i=5){super(),__publicField$3(this,"_reds"),__publicField$3(this,"_greens"),__publicField$3(this,"_blues"),__publicField$3(this,"_alphas"),__publicField$3(this,"_sums"),__publicField$3(this,"_weights"),__publicField$3(this,"_momentsRed"),__publicField$3(this,"_momentsGreen"),__publicField$3(this,"_momentsBlue"),__publicField$3(this,"_momentsAlpha"),__publicField$3(this,"_moments"),__publicField$3(this,"_table"),__publicField$3(this,"_pixels"),__publicField$3(this,"_cubes"),__publicField$3(this,"_colors"),__publicField$3(this,"_significantBitsPerChannel"),__publicField$3(this,"_maxSideIndex"),__publicField$3(this,"_alphaMaxSideIndex"),__publicField$3(this,"_sideSize"),__publicField$3(this,"_alphaSideSize"),__publicField$3(this,"_distance"),this._distance=e,this._setQuality(i),this._initialize(t);}sample(e){const t=e.getPointArray();for(let e=0,i=t.length;e<i;e++)this._addColor(t[e]);this._pixels=this._pixels.concat(t);}*quantize(){yield*this._preparePalette();const e=new Palette$1;for(let t=0;t<this._colors;t++)if(this._sums[t]>0){const i=this._sums[t],r=this._reds[t]/i,n=this._greens[t]/i,a=this._blues[t]/i,o=this._alphas[t]/i,s=Point$1.createByRGBA(0|r,0|n,0|a,0|o);e.add(s);}e.sort(),yield {palette:e,progress:100};}*_preparePalette(){yield*this._calculateMoments();let e=0;const t=createArray1D$1(this._colors);for(let i=1;i<this._colors;++i){this._cut(this._cubes[e],this._cubes[i])?(t[e]=this._cubes[e].volume>1?this._calculateVariance(this._cubes[e]):0,t[i]=this._cubes[i].volume>1?this._calculateVariance(this._cubes[i]):0):(t[e]=0,i--),e=0;let r=t[0];for(let n=1;n<=i;++n)t[n]>r&&(r=t[n],e=n);if(r<=0){this._colors=i+1;break}}const i=[],r=[],n=[],a=[];for(let e=0;e<this._colors;++e){const t=_WuQuant$1._volume(this._cubes[e],this._weights);t>0?(i[e]=_WuQuant$1._volume(this._cubes[e],this._momentsRed)/t|0,r[e]=_WuQuant$1._volume(this._cubes[e],this._momentsGreen)/t|0,n[e]=_WuQuant$1._volume(this._cubes[e],this._momentsBlue)/t|0,a[e]=_WuQuant$1._volume(this._cubes[e],this._momentsAlpha)/t|0):(i[e]=0,r[e]=0,n[e]=0,a[e]=0);}this._reds=createArray1D$1(this._colors+1),this._greens=createArray1D$1(this._colors+1),this._blues=createArray1D$1(this._colors+1),this._alphas=createArray1D$1(this._colors+1),this._sums=createArray1D$1(this._colors+1);for(let e=0,t=this._pixels.length;e<t;e++){const t=this._pixels[e];let o=-1,s=Number.MAX_VALUE;for(let e=0;e<this._colors;e++){const l=i[e],u=r[e],h=n[e],c=a[e],f=this._distance.calculateRaw(l,u,h,c,t.r,t.g,t.b,t.a);f<s&&(s=f,o=e);}this._reds[o]+=t.r,this._greens[o]+=t.g,this._blues[o]+=t.b,this._alphas[o]+=t.a,this._sums[o]++;}}_addColor(e){const t=8-this._significantBitsPerChannel,i=1+(e.r>>t),r=1+(e.g>>t),n=1+(e.b>>t),a=1+(e.a>>t);this._weights[a][i][r][n]++,this._momentsRed[a][i][r][n]+=e.r,this._momentsGreen[a][i][r][n]+=e.g,this._momentsBlue[a][i][r][n]+=e.b,this._momentsAlpha[a][i][r][n]+=e.a,this._moments[a][i][r][n]+=this._table[e.r]+this._table[e.g]+this._table[e.b]+this._table[e.a];}*_calculateMoments(){const e=[],t=[],i=[],r=[],n=[],a=[],o=createArray3D$1(this._sideSize,this._sideSize,this._sideSize),s=createArray3D$1(this._sideSize,this._sideSize,this._sideSize),l=createArray3D$1(this._sideSize,this._sideSize,this._sideSize),u=createArray3D$1(this._sideSize,this._sideSize,this._sideSize),h=createArray3D$1(this._sideSize,this._sideSize,this._sideSize),c=createArray3D$1(this._sideSize,this._sideSize,this._sideSize);let f=0;const d=new ProgressTracker$1(this._alphaMaxSideIndex*this._maxSideIndex,99);for(let p=1;p<=this._alphaMaxSideIndex;++p){fillArray3D$1(o,this._sideSize,this._sideSize,this._sideSize,0),fillArray3D$1(s,this._sideSize,this._sideSize,this._sideSize,0),fillArray3D$1(l,this._sideSize,this._sideSize,this._sideSize,0),fillArray3D$1(u,this._sideSize,this._sideSize,this._sideSize,0),fillArray3D$1(h,this._sideSize,this._sideSize,this._sideSize,0),fillArray3D$1(c,this._sideSize,this._sideSize,this._sideSize,0);for(let m=1;m<=this._maxSideIndex;++m,++f){d.shouldNotify(f)&&(yield {progress:d.progress}),fillArray1D$1(e,this._sideSize,0),fillArray1D$1(t,this._sideSize,0),fillArray1D$1(i,this._sideSize,0),fillArray1D$1(r,this._sideSize,0),fillArray1D$1(n,this._sideSize,0),fillArray1D$1(a,this._sideSize,0);for(let f=1;f<=this._maxSideIndex;++f){let d=0,_=0,g=0,b=0,y=0,w=0;for(let v=1;v<=this._maxSideIndex;++v)d+=this._weights[p][m][f][v],_+=this._momentsRed[p][m][f][v],g+=this._momentsGreen[p][m][f][v],b+=this._momentsBlue[p][m][f][v],y+=this._momentsAlpha[p][m][f][v],w+=this._moments[p][m][f][v],e[v]+=d,t[v]+=_,i[v]+=g,r[v]+=b,n[v]+=y,a[v]+=w,o[m][f][v]=o[m-1][f][v]+e[v],s[m][f][v]=s[m-1][f][v]+t[v],l[m][f][v]=l[m-1][f][v]+i[v],u[m][f][v]=u[m-1][f][v]+r[v],h[m][f][v]=h[m-1][f][v]+n[v],c[m][f][v]=c[m-1][f][v]+a[v],this._weights[p][m][f][v]=this._weights[p-1][m][f][v]+o[m][f][v],this._momentsRed[p][m][f][v]=this._momentsRed[p-1][m][f][v]+s[m][f][v],this._momentsGreen[p][m][f][v]=this._momentsGreen[p-1][m][f][v]+l[m][f][v],this._momentsBlue[p][m][f][v]=this._momentsBlue[p-1][m][f][v]+u[m][f][v],this._momentsAlpha[p][m][f][v]=this._momentsAlpha[p-1][m][f][v]+h[m][f][v],this._moments[p][m][f][v]=this._moments[p-1][m][f][v]+c[m][f][v];}}}}static _volumeFloat(e,t){return t[e.alphaMaximum][e.redMaximum][e.greenMaximum][e.blueMaximum]-t[e.alphaMaximum][e.redMaximum][e.greenMinimum][e.blueMaximum]-t[e.alphaMaximum][e.redMinimum][e.greenMaximum][e.blueMaximum]+t[e.alphaMaximum][e.redMinimum][e.greenMinimum][e.blueMaximum]-t[e.alphaMinimum][e.redMaximum][e.greenMaximum][e.blueMaximum]+t[e.alphaMinimum][e.redMaximum][e.greenMinimum][e.blueMaximum]+t[e.alphaMinimum][e.redMinimum][e.greenMaximum][e.blueMaximum]-t[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMaximum]-(t[e.alphaMaximum][e.redMaximum][e.greenMaximum][e.blueMinimum]-t[e.alphaMinimum][e.redMaximum][e.greenMaximum][e.blueMinimum]-t[e.alphaMaximum][e.redMaximum][e.greenMinimum][e.blueMinimum]+t[e.alphaMinimum][e.redMaximum][e.greenMinimum][e.blueMinimum]-t[e.alphaMaximum][e.redMinimum][e.greenMaximum][e.blueMinimum]+t[e.alphaMinimum][e.redMinimum][e.greenMaximum][e.blueMinimum]+t[e.alphaMaximum][e.redMinimum][e.greenMinimum][e.blueMinimum]-t[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMinimum])}static _volume(e,t){return 0|_WuQuant$1._volumeFloat(e,t)}static _top(e,t,i,r){let n;switch(t){case _WuQuant$1._alpha:n=r[i][e.redMaximum][e.greenMaximum][e.blueMaximum]-r[i][e.redMaximum][e.greenMinimum][e.blueMaximum]-r[i][e.redMinimum][e.greenMaximum][e.blueMaximum]+r[i][e.redMinimum][e.greenMinimum][e.blueMaximum]-(r[i][e.redMaximum][e.greenMaximum][e.blueMinimum]-r[i][e.redMaximum][e.greenMinimum][e.blueMinimum]-r[i][e.redMinimum][e.greenMaximum][e.blueMinimum]+r[i][e.redMinimum][e.greenMinimum][e.blueMinimum]);break;case _WuQuant$1._red:n=r[e.alphaMaximum][i][e.greenMaximum][e.blueMaximum]-r[e.alphaMaximum][i][e.greenMinimum][e.blueMaximum]-r[e.alphaMinimum][i][e.greenMaximum][e.blueMaximum]+r[e.alphaMinimum][i][e.greenMinimum][e.blueMaximum]-(r[e.alphaMaximum][i][e.greenMaximum][e.blueMinimum]-r[e.alphaMaximum][i][e.greenMinimum][e.blueMinimum]-r[e.alphaMinimum][i][e.greenMaximum][e.blueMinimum]+r[e.alphaMinimum][i][e.greenMinimum][e.blueMinimum]);break;case _WuQuant$1._green:n=r[e.alphaMaximum][e.redMaximum][i][e.blueMaximum]-r[e.alphaMaximum][e.redMinimum][i][e.blueMaximum]-r[e.alphaMinimum][e.redMaximum][i][e.blueMaximum]+r[e.alphaMinimum][e.redMinimum][i][e.blueMaximum]-(r[e.alphaMaximum][e.redMaximum][i][e.blueMinimum]-r[e.alphaMaximum][e.redMinimum][i][e.blueMinimum]-r[e.alphaMinimum][e.redMaximum][i][e.blueMinimum]+r[e.alphaMinimum][e.redMinimum][i][e.blueMinimum]);break;case _WuQuant$1._blue:n=r[e.alphaMaximum][e.redMaximum][e.greenMaximum][i]-r[e.alphaMaximum][e.redMaximum][e.greenMinimum][i]-r[e.alphaMaximum][e.redMinimum][e.greenMaximum][i]+r[e.alphaMaximum][e.redMinimum][e.greenMinimum][i]-(r[e.alphaMinimum][e.redMaximum][e.greenMaximum][i]-r[e.alphaMinimum][e.redMaximum][e.greenMinimum][i]-r[e.alphaMinimum][e.redMinimum][e.greenMaximum][i]+r[e.alphaMinimum][e.redMinimum][e.greenMinimum][i]);break;default:throw new Error("impossible")}return 0|n}static _bottom(e,t,i){switch(t){case _WuQuant$1._alpha:return -i[e.alphaMinimum][e.redMaximum][e.greenMaximum][e.blueMaximum]+i[e.alphaMinimum][e.redMaximum][e.greenMinimum][e.blueMaximum]+i[e.alphaMinimum][e.redMinimum][e.greenMaximum][e.blueMaximum]-i[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMaximum]-(-i[e.alphaMinimum][e.redMaximum][e.greenMaximum][e.blueMinimum]+i[e.alphaMinimum][e.redMaximum][e.greenMinimum][e.blueMinimum]+i[e.alphaMinimum][e.redMinimum][e.greenMaximum][e.blueMinimum]-i[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMinimum]);case _WuQuant$1._red:return -i[e.alphaMaximum][e.redMinimum][e.greenMaximum][e.blueMaximum]+i[e.alphaMaximum][e.redMinimum][e.greenMinimum][e.blueMaximum]+i[e.alphaMinimum][e.redMinimum][e.greenMaximum][e.blueMaximum]-i[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMaximum]-(-i[e.alphaMaximum][e.redMinimum][e.greenMaximum][e.blueMinimum]+i[e.alphaMaximum][e.redMinimum][e.greenMinimum][e.blueMinimum]+i[e.alphaMinimum][e.redMinimum][e.greenMaximum][e.blueMinimum]-i[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMinimum]);case _WuQuant$1._green:return -i[e.alphaMaximum][e.redMaximum][e.greenMinimum][e.blueMaximum]+i[e.alphaMaximum][e.redMinimum][e.greenMinimum][e.blueMaximum]+i[e.alphaMinimum][e.redMaximum][e.greenMinimum][e.blueMaximum]-i[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMaximum]-(-i[e.alphaMaximum][e.redMaximum][e.greenMinimum][e.blueMinimum]+i[e.alphaMaximum][e.redMinimum][e.greenMinimum][e.blueMinimum]+i[e.alphaMinimum][e.redMaximum][e.greenMinimum][e.blueMinimum]-i[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMinimum]);case _WuQuant$1._blue:return -i[e.alphaMaximum][e.redMaximum][e.greenMaximum][e.blueMinimum]+i[e.alphaMaximum][e.redMaximum][e.greenMinimum][e.blueMinimum]+i[e.alphaMaximum][e.redMinimum][e.greenMaximum][e.blueMinimum]-i[e.alphaMaximum][e.redMinimum][e.greenMinimum][e.blueMinimum]-(-i[e.alphaMinimum][e.redMaximum][e.greenMaximum][e.blueMinimum]+i[e.alphaMinimum][e.redMaximum][e.greenMinimum][e.blueMinimum]+i[e.alphaMinimum][e.redMinimum][e.greenMaximum][e.blueMinimum]-i[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMinimum]);default:return 0}}_calculateVariance(e){const t=_WuQuant$1._volume(e,this._momentsRed),i=_WuQuant$1._volume(e,this._momentsGreen),r=_WuQuant$1._volume(e,this._momentsBlue),n=_WuQuant$1._volume(e,this._momentsAlpha);return _WuQuant$1._volumeFloat(e,this._moments)-(t*t+i*i+r*r+n*n)/_WuQuant$1._volume(e,this._weights)}_maximize(e,t,i,r,n,a,o,s,l){const u=0|_WuQuant$1._bottom(e,t,this._momentsRed),h=0|_WuQuant$1._bottom(e,t,this._momentsGreen),c=0|_WuQuant$1._bottom(e,t,this._momentsBlue),f=0|_WuQuant$1._bottom(e,t,this._momentsAlpha),d=0|_WuQuant$1._bottom(e,t,this._weights);let p=0,m=-1;for(let _=i;_<r;++_){let i=u+_WuQuant$1._top(e,t,_,this._momentsRed),r=h+_WuQuant$1._top(e,t,_,this._momentsGreen),g=c+_WuQuant$1._top(e,t,_,this._momentsBlue),b=f+_WuQuant$1._top(e,t,_,this._momentsAlpha),y=d+_WuQuant$1._top(e,t,_,this._weights);if(0!==y){let e=i*i+r*r+g*g+b*b,t=e/y;i=n-i,r=a-r,g=o-g,b=s-b,y=l-y,0!==y&&(e=i*i+r*r+g*g+b*b,t+=e/y,t>p&&(p=t,m=_));}}return {max:p,position:m}}_cut(e,t){let i;const r=_WuQuant$1._volume(e,this._momentsRed),n=_WuQuant$1._volume(e,this._momentsGreen),a=_WuQuant$1._volume(e,this._momentsBlue),o=_WuQuant$1._volume(e,this._momentsAlpha),s=_WuQuant$1._volume(e,this._weights),l=this._maximize(e,_WuQuant$1._red,e.redMinimum+1,e.redMaximum,r,n,a,o,s),u=this._maximize(e,_WuQuant$1._green,e.greenMinimum+1,e.greenMaximum,r,n,a,o,s),h=this._maximize(e,_WuQuant$1._blue,e.blueMinimum+1,e.blueMaximum,r,n,a,o,s),c=this._maximize(e,_WuQuant$1._alpha,e.alphaMinimum+1,e.alphaMaximum,r,n,a,o,s);if(c.max>=l.max&&c.max>=u.max&&c.max>=h.max){if(i=_WuQuant$1._alpha,c.position<0)return false}else i=l.max>=c.max&&l.max>=u.max&&l.max>=h.max?_WuQuant$1._red:u.max>=c.max&&u.max>=l.max&&u.max>=h.max?_WuQuant$1._green:_WuQuant$1._blue;switch(t.redMaximum=e.redMaximum,t.greenMaximum=e.greenMaximum,t.blueMaximum=e.blueMaximum,t.alphaMaximum=e.alphaMaximum,i){case _WuQuant$1._red:t.redMinimum=e.redMaximum=l.position,t.greenMinimum=e.greenMinimum,t.blueMinimum=e.blueMinimum,t.alphaMinimum=e.alphaMinimum;break;case _WuQuant$1._green:t.greenMinimum=e.greenMaximum=u.position,t.redMinimum=e.redMinimum,t.blueMinimum=e.blueMinimum,t.alphaMinimum=e.alphaMinimum;break;case _WuQuant$1._blue:t.blueMinimum=e.blueMaximum=h.position,t.redMinimum=e.redMinimum,t.greenMinimum=e.greenMinimum,t.alphaMinimum=e.alphaMinimum;break;case _WuQuant$1._alpha:t.alphaMinimum=e.alphaMaximum=c.position,t.blueMinimum=e.blueMinimum,t.redMinimum=e.redMinimum,t.greenMinimum=e.greenMinimum;}return e.volume=(e.redMaximum-e.redMinimum)*(e.greenMaximum-e.greenMinimum)*(e.blueMaximum-e.blueMinimum)*(e.alphaMaximum-e.alphaMinimum),t.volume=(t.redMaximum-t.redMinimum)*(t.greenMaximum-t.greenMinimum)*(t.blueMaximum-t.blueMinimum)*(t.alphaMaximum-t.alphaMinimum),true}_initialize(e){this._colors=e,this._cubes=[];for(let t=0;t<e;t++)this._cubes[t]=new WuColorCube$1;this._cubes[0].redMinimum=0,this._cubes[0].greenMinimum=0,this._cubes[0].blueMinimum=0,this._cubes[0].alphaMinimum=0,this._cubes[0].redMaximum=this._maxSideIndex,this._cubes[0].greenMaximum=this._maxSideIndex,this._cubes[0].blueMaximum=this._maxSideIndex,this._cubes[0].alphaMaximum=this._alphaMaxSideIndex,this._weights=createArray4D$1(this._alphaSideSize,this._sideSize,this._sideSize,this._sideSize),this._momentsRed=createArray4D$1(this._alphaSideSize,this._sideSize,this._sideSize,this._sideSize),this._momentsGreen=createArray4D$1(this._alphaSideSize,this._sideSize,this._sideSize,this._sideSize),this._momentsBlue=createArray4D$1(this._alphaSideSize,this._sideSize,this._sideSize,this._sideSize),this._momentsAlpha=createArray4D$1(this._alphaSideSize,this._sideSize,this._sideSize,this._sideSize),this._moments=createArray4D$1(this._alphaSideSize,this._sideSize,this._sideSize,this._sideSize),this._table=[];for(let e=0;e<256;++e)this._table[e]=e*e;this._pixels=[];}_setQuality(e=5){this._significantBitsPerChannel=e,this._maxSideIndex=1<<this._significantBitsPerChannel,this._alphaMaxSideIndex=this._maxSideIndex,this._sideSize=this._maxSideIndex+1,this._alphaSideSize=this._alphaMaxSideIndex+1;}},WuQuant$1=_WuQuant$1;__publicField$3(WuQuant$1,"_alpha",3),__publicField$3(WuQuant$1,"_red",2),__publicField$3(WuQuant$1,"_green",1),__publicField$3(WuQuant$1,"_blue",0);var image_exports$1={};__export$1(image_exports$1,{AbstractImageQuantizer:()=>AbstractImageQuantizer$1,ErrorDiffusionArray:()=>ErrorDiffusionArray$1,ErrorDiffusionArrayKernel:()=>ErrorDiffusionArrayKernel$1,ErrorDiffusionRiemersma:()=>ErrorDiffusionRiemersma$1,NearestColor:()=>NearestColor$1});var AbstractImageQuantizer$1=class{quantizeSync(e,t){for(const i of this.quantize(e,t))if(i.pointContainer)return i.pointContainer;throw new Error("unreachable")}},NearestColor$1=class extends AbstractImageQuantizer$1{constructor(e){super(),__publicField$3(this,"_distance"),this._distance=e;}*quantize(e,t){const i=e.getPointArray(),r=e.getWidth(),n=e.getHeight(),a=new ProgressTracker$1(n,99);for(let e=0;e<n;e++){a.shouldNotify(e)&&(yield {progress:a.progress});for(let n=0,a=e*r;n<r;n++,a++){const e=i[a];e.from(t.getNearestColor(this._distance,e));}}yield {pointContainer:e,progress:100};}},ErrorDiffusionArrayKernel$1=(e=>(e[e.FloydSteinberg=0]="FloydSteinberg",e[e.FalseFloydSteinberg=1]="FalseFloydSteinberg",e[e.Stucki=2]="Stucki",e[e.Atkinson=3]="Atkinson",e[e.Jarvis=4]="Jarvis",e[e.Burkes=5]="Burkes",e[e.Sierra=6]="Sierra",e[e.TwoSierra=7]="TwoSierra",e[e.SierraLite=8]="SierraLite",e))(ErrorDiffusionArrayKernel$1||{}),ErrorDiffusionArray$1=class extends AbstractImageQuantizer$1{constructor(e,t,i=true,r=0,n=false){super(),__publicField$3(this,"_minColorDistance"),__publicField$3(this,"_serpentine"),__publicField$3(this,"_kernel"),__publicField$3(this,"_calculateErrorLikeGIMP"),__publicField$3(this,"_distance"),this._setKernel(t),this._distance=e,this._minColorDistance=r,this._serpentine=i,this._calculateErrorLikeGIMP=n;}*quantize(e,t){const i=e.getPointArray(),r=new Point$1,n=e.getWidth(),a=e.getHeight(),o=[];let s=1,l=1;for(const e of this._kernel){const t=e[2]+1;l<t&&(l=t);}for(let e=0;e<l;e++)this._fillErrorLine(o[e]=[],n);const u=new ProgressTracker$1(a,99);for(let e=0;e<a;e++){u.shouldNotify(e)&&(yield {progress:u.progress}),this._serpentine&&(s*=-1);const l=e*n,h=1===s?0:n-1,c=1===s?n:-1;this._fillErrorLine(o[0],n),o.push(o.shift());const f=o[0];for(let u=h,d=l+h;u!==c;u+=s,d+=s){const l=i[d],h=f[u];r.from(l);const c=Point$1.createByRGBA(inRange0to255Rounded$1(l.r+h[0]),inRange0to255Rounded$1(l.g+h[1]),inRange0to255Rounded$1(l.b+h[2]),inRange0to255Rounded$1(l.a+h[3])),p=t.getNearestColor(this._distance,c);if(l.from(p),this._minColorDistance){if(this._distance.calculateNormalized(r,p)<this._minColorDistance)continue}let m,_,g,b;this._calculateErrorLikeGIMP?(m=c.r-p.r,_=c.g-p.g,g=c.b-p.b,b=c.a-p.a):(m=r.r-p.r,_=r.g-p.g,g=r.b-p.b,b=r.a-p.a);const y=1===s?0:this._kernel.length-1,w=1===s?this._kernel.length:-1;for(let t=y;t!==w;t+=s){const i=this._kernel[t][1]*s,r=this._kernel[t][2];if(i+u>=0&&i+u<n&&r+e>=0&&r+e<a){const e=this._kernel[t][0],n=o[r][i+u];n[0]+=m*e,n[1]+=_*e,n[2]+=g*e,n[3]+=b*e;}}}}yield {pointContainer:e,progress:100};}_fillErrorLine(e,t){e.length>t&&(e.length=t);const i=e.length;for(let t=0;t<i;t++){const i=e[t];i[0]=i[1]=i[2]=i[3]=0;}for(let r=i;r<t;r++)e[r]=[0,0,0,0];}_setKernel(e){switch(e){case 0:this._kernel=[[7/16,1,0],[3/16,-1,1],[5/16,0,1],[1/16,1,1]];break;case 1:this._kernel=[[3/8,1,0],[3/8,0,1],[2/8,1,1]];break;case 2:this._kernel=[[8/42,1,0],[4/42,2,0],[2/42,-2,1],[4/42,-1,1],[8/42,0,1],[4/42,1,1],[2/42,2,1],[1/42,-2,2],[2/42,-1,2],[4/42,0,2],[2/42,1,2],[1/42,2,2]];break;case 3:this._kernel=[[1/8,1,0],[1/8,2,0],[1/8,-1,1],[1/8,0,1],[1/8,1,1],[1/8,0,2]];break;case 4:this._kernel=[[7/48,1,0],[5/48,2,0],[3/48,-2,1],[5/48,-1,1],[7/48,0,1],[5/48,1,1],[3/48,2,1],[1/48,-2,2],[3/48,-1,2],[5/48,0,2],[3/48,1,2],[1/48,2,2]];break;case 5:this._kernel=[[.25,1,0],[4/32,2,0],[2/32,-2,1],[4/32,-1,1],[.25,0,1],[4/32,1,1],[2/32,2,1]];break;case 6:this._kernel=[[5/32,1,0],[3/32,2,0],[2/32,-2,1],[4/32,-1,1],[5/32,0,1],[4/32,1,1],[2/32,2,1],[2/32,-1,2],[3/32,0,2],[2/32,1,2]];break;case 7:this._kernel=[[.25,1,0],[3/16,2,0],[1/16,-2,1],[2/16,-1,1],[3/16,0,1],[2/16,1,1],[1/16,2,1]];break;case 8:this._kernel=[[.5,1,0],[1/4,-1,1],[1/4,0,1]];break;default:throw new Error(`ErrorDiffusionArray: unknown kernel = ${e}`)}}};function*hilbertCurve$1(e,t,i){const r=Math.max(e,t),n={width:e,height:t,level:Math.floor(Math.log(r)/Math.log(2)+1),callback:i,tracker:new ProgressTracker$1(e*t,99),index:0,x:0,y:0};yield*walkHilbert$1(n,1),visit$1(n,0);}function*walkHilbert$1(e,t){if(!(e.level<1)){switch(e.tracker.shouldNotify(e.index)&&(yield {progress:e.tracker.progress}),e.level--,t){case 2:yield*walkHilbert$1(e,1),visit$1(e,3),yield*walkHilbert$1(e,2),visit$1(e,4),yield*walkHilbert$1(e,2),visit$1(e,2),yield*walkHilbert$1(e,4);break;case 3:yield*walkHilbert$1(e,4),visit$1(e,2),yield*walkHilbert$1(e,3),visit$1(e,1),yield*walkHilbert$1(e,3),visit$1(e,3),yield*walkHilbert$1(e,1);break;case 1:yield*walkHilbert$1(e,2),visit$1(e,4),yield*walkHilbert$1(e,1),visit$1(e,3),yield*walkHilbert$1(e,1),visit$1(e,1),yield*walkHilbert$1(e,3);break;case 4:yield*walkHilbert$1(e,3),visit$1(e,1),yield*walkHilbert$1(e,4),visit$1(e,2),yield*walkHilbert$1(e,4),visit$1(e,4),yield*walkHilbert$1(e,2);}e.level++;}}function visit$1(e,t){switch(e.x>=0&&e.x<e.width&&e.y>=0&&e.y<e.height&&(e.callback(e.x,e.y),e.index++),t){case 2:e.x--;break;case 3:e.x++;break;case 1:e.y--;break;case 4:e.y++;}}var ErrorDiffusionRiemersma$1=class extends AbstractImageQuantizer$1{constructor(e,t=16,i=1){super(),__publicField$3(this,"_distance"),__publicField$3(this,"_weights"),__publicField$3(this,"_errorQueueSize"),this._distance=e,this._errorQueueSize=t,this._weights=ErrorDiffusionRiemersma$1._createWeights(i,t);}*quantize(e,t){const i=e.getPointArray(),r=e.getWidth(),n=e.getHeight(),a=[];let o=0;for(let e=0;e<this._errorQueueSize;e++)a[e]={r:0,g:0,b:0,a:0};yield*hilbertCurve$1(r,n,((e,n)=>{const s=i[e+n*r];let{r:l,g:u,b:h,a:c}=s;for(let e=0;e<this._errorQueueSize;e++){const t=this._weights[e],i=a[(e+o)%this._errorQueueSize];l+=i.r*t,u+=i.g*t,h+=i.b*t,c+=i.a*t;}const f=Point$1.createByRGBA(inRange0to255Rounded$1(l),inRange0to255Rounded$1(u),inRange0to255Rounded$1(h),inRange0to255Rounded$1(c)),d=t.getNearestColor(this._distance,f);o=(o+1)%this._errorQueueSize;const p=(o+this._errorQueueSize-1)%this._errorQueueSize;a[p].r=s.r-d.r,a[p].g=s.g-d.g,a[p].b=s.b-d.b,a[p].a=s.a-d.a,s.from(d);})),yield {pointContainer:e,progress:100};}static _createWeights(e,t){const i=[],r=Math.exp(Math.log(t)/(t-1));for(let n=0,a=1;n<t;n++)i[n]=(a+.5|0)/t*e,a*=r;return i}},quality_exports$1={};__export$1(quality_exports$1,{ssim:()=>ssim$1});var K1$1=.01,K2$1=.03;function ssim$1(e,t){if(e.getHeight()!==t.getHeight()||e.getWidth()!==t.getWidth())throw new Error("Images have different sizes!");const i=(255*K1$1)**2,r=(255*K2$1)**2;let n=0,a=0;return iterate$1(e,t,((e,t,o,s)=>{let l=0,u=0,h=0;for(let i=0;i<e.length;i++)u+=(e[i]-o)**2,h+=(t[i]-s)**2,l+=(e[i]-o)*(t[i]-s);const c=e.length-1;u/=c,h/=c,l/=c;a+=(2*o*s+i)*(2*l+r)/((o**2+s**2+i)*(u+h+r)),n++;})),a/n}function iterate$1(e,t,i){const r=e.getWidth(),n=e.getHeight();for(let a=0;a<n;a+=8)for(let o=0;o<r;o+=8){const s=Math.min(8,r-o),l=Math.min(8,n-a),u=calculateLumaValuesForWindow$1(e,o,a,s,l),h=calculateLumaValuesForWindow$1(t,o,a,s,l);i(u,h,calculateAverageLuma$1(u),calculateAverageLuma$1(h));}}function calculateLumaValuesForWindow$1(e,t,i,r,n){const a=e.getPointArray(),o=[];let s=0;for(let l=i;l<i+n;l++){const i=l*e.getWidth();for(let e=t;e<t+r;e++){const t=a[i+e];o[s]=.2126*t.r+.7152*t.g+.0722*t.b,s++;}}return o}function calculateAverageLuma$1(e){let t=0;for(const i of e)t+=i;return t/e.length}var setImmediateImpl="function"==typeof setImmediate?setImmediate:"undefined"!=typeof process&&"function"==typeof(null==process?void 0:process.nextTick)?e=>process.nextTick(e):e=>setTimeout(e,0);function buildPaletteSync$1(e,{colorDistanceFormula:t,paletteQuantization:i,colors:r}={}){const n=paletteQuantizationToPaletteQuantizer$1(colorDistanceFormulaToColorDistance$1(t),i,r);return e.forEach((e=>n.sample(e))),n.quantizeSync()}async function buildPalette(e,{colorDistanceFormula:t,paletteQuantization:i,colors:r,onProgress:n}={}){return new Promise(((a,o)=>{const s=paletteQuantizationToPaletteQuantizer$1(colorDistanceFormulaToColorDistance$1(t),i,r);let l;e.forEach((e=>s.sample(e)));const u=s.quantize(),h=()=>{try{const e=u.next();e.done?a(l):(e.value.palette&&(l=e.value.palette),n&&n(e.value.progress),setImmediateImpl(h));}catch(e){o(e);}};setImmediateImpl(h);}))}function applyPaletteSync$1(e,t,{colorDistanceFormula:i,imageQuantization:r}={}){return imageQuantizationToImageQuantizer$1(colorDistanceFormulaToColorDistance$1(i),r).quantizeSync(e,t)}async function applyPalette(e,t,{colorDistanceFormula:i,imageQuantization:r,onProgress:n}={}){return new Promise(((a,o)=>{let s;const l=imageQuantizationToImageQuantizer$1(colorDistanceFormulaToColorDistance$1(i),r).quantize(e,t),u=()=>{try{const e=l.next();e.done?a(s):(e.value.pointContainer&&(s=e.value.pointContainer),n&&n(e.value.progress),setImmediateImpl(u));}catch(e){o(e);}};setImmediateImpl(u);}))}function colorDistanceFormulaToColorDistance$1(e="euclidean-bt709"){switch(e){case "cie94-graphic-arts":return new CIE94GraphicArts$1;case "cie94-textiles":return new CIE94Textiles$1;case "ciede2000":return new CIEDE2000$1;case "color-metric":return new CMetric$1;case "euclidean":return new Euclidean$1;case "euclidean-bt709":return new EuclideanBT709$1;case "euclidean-bt709-noalpha":return new EuclideanBT709NoAlpha$1;case "manhattan":return new Manhattan$1;case "manhattan-bt709":return new ManhattanBT709$1;case "manhattan-nommyde":return new ManhattanNommyde$1;case "pngquant":return new PNGQuant$1;default:throw new Error(`Unknown colorDistanceFormula ${e}`)}}function imageQuantizationToImageQuantizer$1(e,t="floyd-steinberg"){switch(t){case "nearest":return new NearestColor$1(e);case "riemersma":return new ErrorDiffusionRiemersma$1(e);case "floyd-steinberg":return new ErrorDiffusionArray$1(e,0);case "false-floyd-steinberg":return new ErrorDiffusionArray$1(e,1);case "stucki":return new ErrorDiffusionArray$1(e,2);case "atkinson":return new ErrorDiffusionArray$1(e,3);case "jarvis":return new ErrorDiffusionArray$1(e,4);case "burkes":return new ErrorDiffusionArray$1(e,5);case "sierra":return new ErrorDiffusionArray$1(e,6);case "two-sierra":return new ErrorDiffusionArray$1(e,7);case "sierra-lite":return new ErrorDiffusionArray$1(e,8);default:throw new Error(`Unknown imageQuantization ${t}`)}}function paletteQuantizationToPaletteQuantizer$1(e,t="wuquant",i=256){switch(t){case "neuquant":return new NeuQuant$1(e,i);case "rgbquant":return new RGBQuant$1(e,i);case "wuquant":return new WuQuant$1(e,i);case "neuquant-float":return new NeuQuantFloat$1(e,i);default:throw new Error(`Unknown paletteQuantization ${t}`)}}var imageQ=__toCommonJS(src_exports),gifframe={};const BitmapImage$1=bitmapimage;let GifFrame$1=class e extends BitmapImage$1{constructor(...t){if(super(...t),t[0]instanceof e){const e=t[0];this.xOffset=e.xOffset,this.yOffset=e.yOffset,this.disposalMethod=e.disposalMethod,this.delayCentisecs=e.delayCentisecs,this.interlaced=e.interlaced;}else {const i=t[t.length-1];let r={};"object"!=typeof i||i instanceof BitmapImage$1||(r=i),this.xOffset=r.xOffset||0,this.yOffset=r.yOffset||0,this.disposalMethod=void 0!==r.disposalMethod?r.disposalMethod:e.DisposeToBackgroundColor,this.delayCentisecs=r.delayCentisecs||8,this.interlaced=r.interlaced||false;}}getPalette(){const e=new Set,t=this.bitmap.data;let i=0,r=false;for(;i<t.length;){if(0===t[i+3])r=true;else {const r=t.readUInt32BE(i,true)>>8&16777215;e.add(r);}i+=4;}const n=new Array(e.size),a=e.values();for(i=0;i<n.length;++i)n[i]=a.next().value;n.sort(((e,t)=>e-t));let o=n.length;return r&&++o,{colors:n,usesTransparency:r,indexCount:o}}};var hasRequiredGifutil,hasRequiredGifcodec;function requireGifutil(){return hasRequiredGifutil||(hasRequiredGifutil=1,function(e){const t=require$$0,i=imageQ,r=bitmapimage,{GifFrame:n}=gifframe,{GifError:a}=gif$1,{GifCodec:o}=requireGifcodec(),s=[".jpg",".jpeg",".png",".bmp"],l=new o;function u(e,t,r,n,a){const o=Array.isArray(e)?e:[e];if(a){if(["FloydSteinberg","FalseFloydSteinberg","Stucki","Atkinson","Jarvis","Burkes","Sierra","TwoSierra","SierraLite"].indexOf(a.ditherAlgorithm)<0)throw new Error(`Invalid ditherAlgorithm '${a.ditherAlgorithm}'`);void 0===a.serpentine&&(a.serpentine=true),void 0===a.minimumColorDistanceToDither&&(a.minimumColorDistanceToDither=0),void 0===a.calculateErrorLikeGIMP&&(a.calculateErrorLikeGIMP=false);}const s=new i.distance.Euclidean,l=new i.palette[t](s,r,n);let u;u=a?new i.image.ErrorDiffusionArray(s,i.image.ErrorDiffusionArrayKernel[a.ditherAlgorithm],a.serpentine,a.minimumColorDistanceToDither,a.calculateErrorLikeGIMP):new i.image.NearestColor(s);const h=[];o.forEach((e=>{const t=e.bitmap.data,r=new ArrayBuffer(t.length),n=new Uint32Array(r);for(let e=0,i=0;e<t.length;e+=4,++i)n[i]=t.readUInt32LE(e,true);const a=i.utils.PointContainer.fromUint32Array(n,e.bitmap.width,e.bitmap.height);l.sample(a),h.push(a);}));const c=l.quantizeSync();for(let e=0;e<o.length;++e){const t=o[e].bitmap.data,i=u.quantizeSync(h[e],c).toUint32Array();for(let e=0,r=0;e<t.length;e+=4,++r)t.writeUInt32LE(i[r],e);}}e.cloneFrames=function(e){let t=[];return e.forEach((e=>{t.push(new n(e));})),t},e.getColorInfo=function(e,t){let i=false;const r=[];for(let t=0;t<e.length;++t){let n=e[t].getPalette();if(n.usesTransparency&&(i=true),n.indexCount>256)throw new a(`Frame ${t} uses more than 256 color indexes`);r.push(n);}if(0===t)return {usesTransparency:i,palettes:r};const n=new Set;r.forEach((e=>{e.colors.forEach((e=>{n.add(e);}));}));let o=n.size;if(i&&++o,t&&o>t)return {usesTransparency:i,palettes:r};const s=new Array(n.size),l=n.values();for(let e=0;e<s.length;++e)s[e]=l.next().value;return s.sort(((e,t)=>e-t)),{colors:s,indexCount:o,usesTransparency:i,palettes:r}},e.copyAsJimp=function(t,i){return e.shareAsJimp(t,new r(i))},e.getMaxDimensions=function(e){let t=0,i=0;return e.forEach((e=>{const r=e.xOffset+e.bitmap.width;r>t&&(t=r);const n=e.yOffset+e.bitmap.height;n>i&&(i=n);})),{maxWidth:t,maxHeight:i}},e.quantizeDekker=function(e,t,i){u(e,"NeuQuantFloat",t=t||256,0,i);},e.quantizeSorokin=function(e,t,i,r){let n;switch(t=t||256,i=i||"min-pop"){case "min-pop":n=2;break;case "top-pop":n=1;break;default:throw new Error(`Invalid quantizeSorokin histogram '${i}'`)}u(e,"RGBQuant",t,n,r);},e.quantizeWu=function(e,t,i,r){if(t=t||256,(i=i||5)<1||i>8)throw new Error("Invalid quantization quality");u(e,"WuQuant",t,i,r);},e.read=function(e,i){return i=i||l,Buffer.isBuffer(e)?i.decodeGif(e):function(e){return new Promise(((i,r)=>{t.readFile(e,((e,t)=>e?r(e):i(t)));}))}(e).then((e=>i.decodeGif(e)))},e.shareAsJimp=function(e,t){const i=new e(t.bitmap.width,t.bitmap.height,0);return i.bitmap.data=t.bitmap.data,i},e.write=function(e,i,r,n){n=n||l;const a=e.match(/\.[a-zA-Z]+$/);if(null!==a&&s.includes(a[0].toLowerCase()))throw new Error(`GIF '${e}' has an unexpected suffix`);return n.encodeGif(i,r).then((i=>function(e,i){return new Promise(((r,n)=>{t.writeFile(e,i,(e=>e?n(e):r()));}))}(e,i.buffer).then((()=>i))))};}(gifutil)),gifutil}function requireGifcodec(){if(hasRequiredGifcodec)return gifcodec;hasRequiredGifcodec=1;const e=omggif,{Gif:t,GifError:i}=gif$1;function r(){const e=requireGifutil();return r=function(){return e},e}const{GifFrame:n}=gifframe;function a(e,t){const i=e.indexOf(t);return -1===i?null:i}function o(e,t){for(var i,r=0,n=e.length-1;r<=n;)if(e[i=Math.floor((r+n)/2)]>t)n=i-1;else {if(!(e[i]<t))return i;r=i+1;}return null}function s(e){const t=e.colors;e.usesTransparency&&t.push(0);const i=t.length;let r=2;for(;i>r;)r<<=1;t.length=r,t.fill(0,i);}function l(e,t){let i=e.bitmap.width*e.bitmap.height;return i=Math.ceil(i*t/8),i+=Math.ceil(i/255),100+i+768}function u(e){let t=e.indexCount,i=0;for(--t;t;)++i,t>>=1;return i>0?i:1}function h(e,t,r,n,l){if(r.interlaced)throw new i("writing interlaced GIFs is not supported");const u=function(e,t,r){const n=r.colors,s=n.length<=8?a:o,l=t.bitmap.data,u=new Buffer(l.length/4);let h=n.length,c=0,f=0;for(;c<l.length;){if(0!==l[c+3]){const e=l.readUInt32BE(c,true)>>8&16777215;u[f]=s(n,e);}else u[f]=h;c+=4,++f;}if(r.usesTransparency){if(256===h)throw new i(`Frame ${e} already has 256 colorsand so can't use transparency`)}else h=null;return {buffer:u,transparentIndex:h}}(t,r,n),h={delay:r.delayCentisecs,disposal:r.disposalMethod,transparent:u.transparentIndex};l&&(s(n),h.palette=n.colors);try{let t,i=e.getOutputBuffer(),n=e.getOutputBufferPosition(),a=!0;for(;a;)if(t=e.addFrame(r.xOffset,r.yOffset,r.bitmap.width,r.bitmap.height,u.buffer,h),a=!1,t>=i.length-1){const t=new Buffer(1.5*i.length);i.copy(t),e.setOutputBuffer(t),e.setOutputBufferPosition(n),i=t,a=!0;}return i}catch(e){throw new i(e)}}return gifcodec.GifCodec=class{constructor(e={}){this._transparentRGB=null,"number"==typeof e.transparentRGB&&0!==e.transparentRGB&&(this._transparentRGBA=256*e.transparentRGB),this._testInitialBufferSize=0;}decodeGif(r){try{let n;try{n=new e.GifReader(r);}catch(e){throw new i(e)}const a=n.numFrames(),o=[],s={width:n.width,height:n.height,loops:n.loopCount(),usesTransparency:!1};for(let e=0;e<a;++e){const t=this._decodeFrame(n,e,s.usesTransparency);o.push(t.frame),t.usesTransparency&&(s.usesTransparency=!0);}return Promise.resolve(new t(r,o,s))}catch(e){return Promise.reject(e)}}encodeGif(e,n={}){try{if(null===e||0===e.length)throw new i("there are no frames");const a=r().getMaxDimensions(e);return (n=Object.assign({},n)).width=a.maxWidth,n.height=a.maxHeight,void 0===n.loops&&(n.loops=0),n.colorScope=n.colorScope||t.GlobalColorsPreferred,Promise.resolve(this._encodeGif(e,n))}catch(e){return Promise.reject(e)}}_decodeFrame(e,t,r){let a,o;try{if(a=e.frameInfo(t),o=new Buffer(e.width*e.height*4),e.decodeAndBlitFrameRGBA(t,o),a.width!==e.width||a.height!==e.height){if(a.y&&(o=o.slice(a.y*e.width*4)),e.width>a.width)for(let t=0;t<a.height;++t)o.copy(o,t*a.width*4,4*(a.x+t*e.width),4*(a.x+t*e.width)+4*a.width);o=o.slice(0,a.width*a.height*4);}}catch(e){throw new i(e)}let s=false;if(null===this._transparentRGBA){if(!r)for(let e=3;e<o.length;e+=4)0===o[e]&&(s=true,e=o.length);}else for(let e=3;e<o.length;e+=4)0===o[e]&&(o.writeUInt32BE(this._transparentRGBA,e-3),s=true);return {frame:new n(a.width,a.height,o,{xOffset:a.x,yOffset:a.y,disposalMethod:a.disposal,interlaced:a.interlaced,delayCentisecs:a.delay}),usesTransparency:s}}_encodeGif(n,a){let o;if(a.colorScope===t.LocalColorsOnly)o=r().getColorInfo(n,0);else if(o=r().getColorInfo(n,256),!o.colors){if(a.colorScope===t.GlobalColorsOnly)throw new i("Too many color indexes for global color table");a.colorScope=t.LocalColorsOnly;}a.usesTransparency=o.usesTransparency;const l=o.palettes;if(a.colorScope===t.LocalColorsOnly){return function(r,n,a,o){const s={loop:n.loops};let l,u=new Buffer(a);try{l=new e.GifWriter(u,n.width,n.height,s);}catch(e){throw new i(e)}for(let e=0;e<r.length;++e)u=h(l,e,r[e],o[e],true);return new t(u.slice(0,l.end()),r,n)}(n,a,2e3,l)}return function(r,n,a,o){const l={colors:o.colors.slice(),usesTransparency:o.usesTransparency};s(l);const u={palette:l.colors,loop:n.loops};let c,f=new Buffer(a);try{c=new e.GifWriter(f,n.width,n.height,u);}catch(e){throw new i(e)}for(let e=0;e<r.length;++e)f=h(c,e,r[e],o,false);return new t(f.slice(0,c.end()),r,n)}(n,a,2e3,o)}_getSizeEstimateGlobal(e,t){if(this._testInitialBufferSize>0)return this._testInitialBufferSize;let i=968;const r=u(e);return t.forEach((e=>{i+=l(e,r);})),i}_getSizeEstimateLocal(e,t){if(this._testInitialBufferSize>0)return this._testInitialBufferSize;let i=200;for(let r=0;r<t.length;++r){const n=u(e[r]);i+=l(t[r],n);}return i}},gifcodec}GifFrame$1.DisposeToAnything=0,GifFrame$1.DisposeNothing=1,GifFrame$1.DisposeToBackgroundColor=2,GifFrame$1.DisposeToPrevious=3,gifframe.GifFrame=GifFrame$1;const BitmapImage=bitmapimage,{GifCodec:GifCodec}=requireGifcodec(),{GifFrame:GifFrame}=gifframe,GifUtil=requireGifutil();var src={BitmapImage:BitmapImage,GifCodec:GifCodec,GifFrame:GifFrame,GifUtil:GifUtil};function gif(){return {mime:"image/gif",encode:async e=>{const t=new src.BitmapImage(e);src.GifUtil.quantizeDekker(t,256);const i=new src.GifFrame(e),r=new src.GifCodec;return (await r.encodeGif([i],{})).buffer},decode:e=>{const t=new omggif.GifReader(e),i=Buffer.alloc(t.width*t.height*4);return t.decodeAndBlitFrameRGBA(0,i),{data:i,width:t.width,height:t.height}}}}var encoder={exports:{}};!function(e){function t(e){var t,i,r,n,a,o=Math.floor,s=new Array(64),l=new Array(64),u=new Array(64),h=new Array(64),c=new Array(65535),f=new Array(65535),d=new Array(64),p=new Array(64),m=[],_=0,g=7,b=new Array(64),y=new Array(64),w=new Array(64),v=new Array(256),x=new Array(2048),E=[0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18,24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63],k=[0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0],S=[0,1,2,3,4,5,6,7,8,9,10,11],A=[0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,125],I=[1,2,3,0,4,17,5,18,33,49,65,6,19,81,97,7,34,113,20,50,129,145,161,8,35,66,177,193,21,82,209,240,36,51,98,114,130,9,10,22,23,24,25,26,37,38,39,40,41,42,52,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,225,226,227,228,229,230,231,232,233,234,241,242,243,244,245,246,247,248,249,250],M=[0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0],T=[0,1,2,3,4,5,6,7,8,9,10,11],P=[0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,119],B=[0,1,2,3,17,4,5,33,49,6,18,65,81,7,97,113,19,34,50,129,8,20,66,145,161,177,193,9,35,51,82,240,21,98,114,209,10,22,36,52,225,37,241,23,24,25,26,38,39,40,41,42,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,130,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,226,227,228,229,230,231,232,233,234,242,243,244,245,246,247,248,249,250];function C(e,t){for(var i=0,r=0,n=new Array,a=1;a<=16;a++){for(var o=1;o<=e[a];o++)n[t[r]]=[],n[t[r]][0]=i,n[t[r]][1]=a,r++,i++;i*=2;}return n}function R(e){for(var t=e[0],i=e[1]-1;i>=0;)t&1<<i&&(_|=1<<g),i--,--g<0&&(255==_?(z(255),z(0)):z(_),g=7,_=0);}function z(e){m.push(e);}function F(e){z(e>>8&255),z(255&e);}function N(e,t,i,r,n){for(var a,o=n[0],s=n[240],l=function(e,t){var i,r,n,a,o,s,l,u,h,c,f=0;for(h=0;h<8;++h){i=e[f],r=e[f+1],n=e[f+2],a=e[f+3],o=e[f+4],s=e[f+5],l=e[f+6];var p=i+(u=e[f+7]),m=i-u,_=r+l,g=r-l,b=n+s,y=n-s,w=a+o,v=a-o,x=p+w,E=p-w,k=_+b,S=_-b;e[f]=x+k,e[f+4]=x-k;var A=.707106781*(S+E);e[f+2]=E+A,e[f+6]=E-A;var I=.382683433*((x=v+y)-(S=g+m)),M=.5411961*x+I,T=1.306562965*S+I,P=.707106781*(k=y+g),B=m+P,C=m-P;e[f+5]=C+M,e[f+3]=C-M,e[f+1]=B+T,e[f+7]=B-T,f+=8;}for(f=0,h=0;h<8;++h){i=e[f],r=e[f+8],n=e[f+16],a=e[f+24],o=e[f+32],s=e[f+40],l=e[f+48];var R=i+(u=e[f+56]),z=i-u,F=r+l,N=r-l,O=n+s,D=n-s,$=a+o,L=a-o,U=R+$,Z=R-$,j=F+O,G=F-O;e[f]=U+j,e[f+32]=U-j;var H=.707106781*(G+Z);e[f+16]=Z+H,e[f+48]=Z-H;var Q=.382683433*((U=L+D)-(G=N+z)),W=.5411961*U+Q,q=1.306562965*G+Q,V=.707106781*(j=D+N),Y=z+V,K=z-V;e[f+40]=K+W,e[f+24]=K-W,e[f+8]=Y+q,e[f+56]=Y-q,f++;}for(h=0;h<64;++h)c=e[h]*t[h],d[h]=c>0?c+.5|0:c-.5|0;return d}(e,t),u=0;u<64;++u)p[E[u]]=l[u];var h=p[0]-i;i=p[0],0==h?R(r[0]):(R(r[f[a=32767+h]]),R(c[a]));for(var m=63;m>0&&0==p[m];m--);if(0==m)return R(o),i;for(var _,g=1;g<=m;){for(var b=g;0==p[g]&&g<=m;++g);var y=g-b;if(y>=16){_=y>>4;for(var w=1;w<=_;++w)R(s);y&=15;}a=32767+p[g],R(n[(y<<4)+f[a]]),R(c[a]),g++;}return 63!=m&&R(o),i}function O(e){if(e<=0&&(e=1),e>100&&(e=100),a!=e){((function(e){for(var t=[16,11,10,16,24,40,51,61,12,12,14,19,26,58,60,55,14,13,16,24,40,57,69,56,14,17,22,29,51,87,80,62,18,22,37,56,68,109,103,77,24,35,55,64,81,104,113,92,49,64,78,87,103,121,120,101,72,92,95,98,112,100,103,99],i=0;i<64;i++){var r=o((t[i]*e+50)/100);r<1?r=1:r>255&&(r=255),s[E[i]]=r;}for(var n=[17,18,24,47,99,99,99,99,18,21,26,66,99,99,99,99,24,26,56,99,99,99,99,99,47,66,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99],a=0;a<64;a++){var c=o((n[a]*e+50)/100);c<1?c=1:c>255&&(c=255),l[E[a]]=c;}for(var f=[1,1.387039845,1.306562965,1.175875602,1,.785694958,.5411961,.275899379],d=0,p=0;p<8;p++)for(var m=0;m<8;m++)u[d]=1/(s[E[d]]*f[p]*f[m]*8),h[d]=1/(l[E[d]]*f[p]*f[m]*8),d++;}))(e<50?Math.floor(5e3/e):Math.floor(200-2*e)),a=e;}}this.encode=function(e,a){var o;(new Date).getTime(),a&&O(a),m=new Array,_=0,g=7,F(65496),F(65504),F(16),z(74),z(70),z(73),z(70),z(0),z(1),z(1),z(0),F(1),F(1),z(0),z(0),void 0!==(o=e.comments)&&o.constructor===Array&&o.forEach((e=>{if("string"==typeof e){F(65534);var t,i=e.length;for(F(i+2),t=0;t<i;t++)z(e.charCodeAt(t));}})),function(e){if(e){F(65505),69===e[0]&&120===e[1]&&105===e[2]&&102===e[3]?F(e.length+2):(F(e.length+5+2),z(69),z(120),z(105),z(102),z(0));for(var t=0;t<e.length;t++)z(e[t]);}}(e.exifBuffer),function(){F(65499),F(132),z(0);for(var e=0;e<64;e++)z(s[e]);z(1);for(var t=0;t<64;t++)z(l[t]);}(),function(e,t){F(65472),F(17),z(8),F(t),F(e),z(3),z(1),z(17),z(0),z(2),z(17),z(1),z(3),z(17),z(1);}(e.width,e.height),function(){F(65476),F(418),z(0);for(var e=0;e<16;e++)z(k[e+1]);for(var t=0;t<=11;t++)z(S[t]);z(16);for(var i=0;i<16;i++)z(A[i+1]);for(var r=0;r<=161;r++)z(I[r]);z(1);for(var n=0;n<16;n++)z(M[n+1]);for(var a=0;a<=11;a++)z(T[a]);z(17);for(var o=0;o<16;o++)z(P[o+1]);for(var s=0;s<=161;s++)z(B[s]);}(),F(65498),F(12),z(3),z(1),z(0),z(2),z(17),z(3),z(17),z(0),z(63),z(0);var c=0,f=0,d=0;_=0,g=7,this.encode.displayName="_encode_";for(var p,v,E,C,D,$,L,U,Z,j=e.data,G=e.width,H=e.height,Q=4*G,W=0;W<H;){for(p=0;p<Q;){for($=D=Q*W+p,L=-1,U=0,Z=0;Z<64;Z++)$=D+(U=Z>>3)*Q+(L=4*(7&Z)),W+U>=H&&($-=Q*(W+1+U-H)),p+L>=Q&&($-=p+L-Q+4),v=j[$++],E=j[$++],C=j[$++],b[Z]=(x[v]+x[E+256|0]+x[C+512|0]>>16)-128,y[Z]=(x[v+768|0]+x[E+1024|0]+x[C+1280|0]>>16)-128,w[Z]=(x[v+1280|0]+x[E+1536|0]+x[C+1792|0]>>16)-128;c=N(b,u,c,t,r),f=N(y,h,f,i,n),d=N(w,h,d,i,n),p+=32;}W+=8;}if(g>=0){var q=[];q[1]=g+1,q[0]=(1<<g+1)-1,R(q);}return F(65497),Buffer.from(m)},(new Date).getTime(),e||(e=50),function(){for(var e=String.fromCharCode,t=0;t<256;t++)v[t]=e(t);}(),t=C(k,S),i=C(M,T),r=C(A,I),n=C(P,B),function(){for(var e=1,t=2,i=1;i<=15;i++){for(var r=e;r<t;r++)f[32767+r]=i,c[32767+r]=[],c[32767+r][1]=i,c[32767+r][0]=r;for(var n=-(t-1);n<=-e;n++)f[32767+n]=i,c[32767+n]=[],c[32767+n][1]=i,c[32767+n][0]=t-1+n;e<<=1,t<<=1;}}(),function(){for(var e=0;e<256;e++)x[e]=19595*e,x[e+256|0]=38470*e,x[e+512|0]=7471*e+32768,x[e+768|0]=-11059*e,x[e+1024|0]=-21709*e,x[e+1280|0]=32768*e+8421375,x[e+1536|0]=-27439*e,x[e+1792|0]=-5329*e;}(),O(e),(new Date).getTime();}encoder.exports=function(e,i){ void 0===i&&(i=50);var r=new t(i),n=r.encode(e,i);return {data:n,width:e.width,height:e.height}};}();var encoderExports=encoder.exports,decoder={exports:{}},module,JpegImage;module=decoder,JpegImage=function(){var e=new Int32Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]),t=4017,i=799,r=3406,n=2276,a=1567,o=3784,s=5793,l=2896;function u(){}function h(e,t){for(var i,r,n=0,a=[],o=16;o>0&&!e[o-1];)o--;a.push({children:[],index:0});var s,l=a[0];for(i=0;i<o;i++){for(r=0;r<e[i];r++){for((l=a.pop()).children[l.index]=t[n];l.index>0;){if(0===a.length)throw new Error("Could not recreate Huffman Table");l=a.pop();}for(l.index++,a.push(l);a.length<=i;)a.push(s={children:[],index:0}),l.children[l.index]=s.children,l=s;n++;}i+1<o&&(a.push(s={children:[],index:0}),l.children[l.index]=s.children,l=s);}return a[0].children}function c(t,i,r,n,a,o,s,l,u,h){r.precision,r.samplesPerLine,r.scanLines;var c=r.mcusPerLine,f=r.progressive;r.maxH,r.maxV;var d=i,p=0,m=0;function _(){if(m>0)return m--,p>>m&1;if(255==(p=t[i++])){var e=t[i++];if(e)throw new Error("unexpected marker: "+(p<<8|e).toString(16))}return m=7,p>>>7}function g(e){for(var t,i=e;null!==(t=_());){if("number"==typeof(i=i[t]))return i;if("object"!=typeof i)throw new Error("invalid huffman sequence")}return null}function b(e){for(var t=0;e>0;){var i=_();if(null===i)return;t=t<<1|i,e--;}return t}function y(e){var t=b(e);return t>=1<<e-1?t:t+(-1<<e)+1}var w,v=0,x=0;function E(e,t,i,r,n){var a=i%c,o=(i/c|0)*e.v+r,s=a*e.h+n;void 0===e.blocks[o]&&h.tolerantDecoding||t(e,e.blocks[o][s]);}function k(e,t,i){var r=i/e.blocksPerLine|0,n=i%e.blocksPerLine;void 0===e.blocks[r]&&h.tolerantDecoding||t(e,e.blocks[r][n]);}var S,A,I,M,T,P,B=n.length;P=f?0===o?0===l?function(e,t){var i=g(e.huffmanTableDC),r=0===i?0:y(i)<<u;t[0]=e.pred+=r;}:function(e,t){t[0]|=_()<<u;}:0===l?function(t,i){if(v>0)v--;else for(var r=o,n=s;r<=n;){var a=g(t.huffmanTableAC),l=15&a,h=a>>4;if(0!==l)i[e[r+=h]]=y(l)*(1<<u),r++;else {if(h<15){v=b(h)+(1<<h)-1;break}r+=16;}}}:function(t,i){for(var r=o,n=s,a=0;r<=n;){var l=e[r],h=i[l]<0?-1:1;switch(x){case 0:var c=g(t.huffmanTableAC),f=15&c;if(a=c>>4,0===f)a<15?(v=b(a)+(1<<a),x=4):(a=16,x=1);else {if(1!==f)throw new Error("invalid ACn encoding");w=y(f),x=a?2:3;}continue;case 1:case 2:i[l]?i[l]+=(_()<<u)*h:0==--a&&(x=2==x?3:0);break;case 3:i[l]?i[l]+=(_()<<u)*h:(i[l]=w<<u,x=0);break;case 4:i[l]&&(i[l]+=(_()<<u)*h);}r++;}4===x&&0==--v&&(x=0);}:function(t,i){var r=g(t.huffmanTableDC),n=0===r?0:y(r);i[0]=t.pred+=n;for(var a=1;a<64;){var o=g(t.huffmanTableAC),s=15&o,l=o>>4;if(0!==s)i[e[a+=l]]=y(s),a++;else {if(l<15)break;a+=16;}}};var C,R,z,F,N=0;for(R=1==B?n[0].blocksPerLine*n[0].blocksPerColumn:c*r.mcusPerColumn,a||(a=R);N<R;){for(A=0;A<B;A++)n[A].pred=0;if(v=0,1==B)for(S=n[0],T=0;T<a;T++)k(S,P,N),N++;else for(T=0;T<a;T++){for(A=0;A<B;A++)for(z=(S=n[A]).h,F=S.v,I=0;I<F;I++)for(M=0;M<z;M++)E(S,P,N,I,M);if(++N===R)break}if(N===R)do{if(255===t[i]&&0!==t[i+1])break;i+=1;}while(i<t.length-2);if(m=0,(C=t[i]<<8|t[i+1])<65280)throw new Error("marker was not found");if(!(C>=65488&&C<=65495))break;i+=2;}return i-d}function f(e,u){var h,c,f=[],d=u.blocksPerLine,p=u.blocksPerColumn,m=d<<3,g=new Int32Array(64),b=new Uint8Array(64);function y(e,h,c){var f,d,p,m,_,g,b,y,w,v,x=u.quantizationTable,E=c;for(v=0;v<64;v++)E[v]=e[v]*x[v];for(v=0;v<8;++v){var k=8*v;0!=E[1+k]||0!=E[2+k]||0!=E[3+k]||0!=E[4+k]||0!=E[5+k]||0!=E[6+k]||0!=E[7+k]?(f=s*E[0+k]+128>>8,d=s*E[4+k]+128>>8,p=E[2+k],m=E[6+k],_=l*(E[1+k]-E[7+k])+128>>8,y=l*(E[1+k]+E[7+k])+128>>8,g=E[3+k]<<4,b=E[5+k]<<4,w=f-d+1>>1,f=f+d+1>>1,d=w,w=p*o+m*a+128>>8,p=p*a-m*o+128>>8,m=w,w=_-b+1>>1,_=_+b+1>>1,b=w,w=y+g+1>>1,g=y-g+1>>1,y=w,w=f-m+1>>1,f=f+m+1>>1,m=w,w=d-p+1>>1,d=d+p+1>>1,p=w,w=_*n+y*r+2048>>12,_=_*r-y*n+2048>>12,y=w,w=g*i+b*t+2048>>12,g=g*t-b*i+2048>>12,b=w,E[0+k]=f+y,E[7+k]=f-y,E[1+k]=d+b,E[6+k]=d-b,E[2+k]=p+g,E[5+k]=p-g,E[3+k]=m+_,E[4+k]=m-_):(w=s*E[0+k]+512>>10,E[0+k]=w,E[1+k]=w,E[2+k]=w,E[3+k]=w,E[4+k]=w,E[5+k]=w,E[6+k]=w,E[7+k]=w);}for(v=0;v<8;++v){var S=v;0!=E[8+S]||0!=E[16+S]||0!=E[24+S]||0!=E[32+S]||0!=E[40+S]||0!=E[48+S]||0!=E[56+S]?(f=s*E[0+S]+2048>>12,d=s*E[32+S]+2048>>12,p=E[16+S],m=E[48+S],_=l*(E[8+S]-E[56+S])+2048>>12,y=l*(E[8+S]+E[56+S])+2048>>12,g=E[24+S],b=E[40+S],w=f-d+1>>1,f=f+d+1>>1,d=w,w=p*o+m*a+2048>>12,p=p*a-m*o+2048>>12,m=w,w=_-b+1>>1,_=_+b+1>>1,b=w,w=y+g+1>>1,g=y-g+1>>1,y=w,w=f-m+1>>1,f=f+m+1>>1,m=w,w=d-p+1>>1,d=d+p+1>>1,p=w,w=_*n+y*r+2048>>12,_=_*r-y*n+2048>>12,y=w,w=g*i+b*t+2048>>12,g=g*t-b*i+2048>>12,b=w,E[0+S]=f+y,E[56+S]=f-y,E[8+S]=d+b,E[48+S]=d-b,E[16+S]=p+g,E[40+S]=p-g,E[24+S]=m+_,E[32+S]=m-_):(w=s*c[v+0]+8192>>14,E[0+S]=w,E[8+S]=w,E[16+S]=w,E[24+S]=w,E[32+S]=w,E[40+S]=w,E[48+S]=w,E[56+S]=w);}for(v=0;v<64;++v){var A=128+(E[v]+8>>4);h[v]=A<0?0:A>255?255:A;}}_(m*p*8);for(var w=0;w<p;w++){var v=w<<3;for(h=0;h<8;h++)f.push(new Uint8Array(m));for(var x=0;x<d;x++){y(u.blocks[w][x],b,g);var E=0,k=x<<3;for(c=0;c<8;c++){var S=f[v+c];for(h=0;h<8;h++)S[k+h]=b[E++];}}}return f}function d(e){return e<0?0:e>255?255:e}u.prototype={load:function(e){var t=new XMLHttpRequest;t.open("GET",e,true),t.responseType="arraybuffer",t.onload=function(){var e=new Uint8Array(t.response||t.mozResponseArrayBuffer);this.parse(e),this.onload&&this.onload();}.bind(this),t.send(null);},parse:function(t){var i=1e3*this.opts.maxResolutionInMP*1e3,r=0;function n(){var e=t[r]<<8|t[r+1];return r+=2,e}function a(e){var t,i,r=1,n=1;for(i in e.components)e.components.hasOwnProperty(i)&&(r<(t=e.components[i]).h&&(r=t.h),n<t.v&&(n=t.v));var a=Math.ceil(e.samplesPerLine/8/r),o=Math.ceil(e.scanLines/8/n);for(i in e.components)if(e.components.hasOwnProperty(i)){t=e.components[i];var s=Math.ceil(Math.ceil(e.samplesPerLine/8)*t.h/r),l=Math.ceil(Math.ceil(e.scanLines/8)*t.v/n),u=a*t.h,h=o*t.v,c=[];_(h*u*256);for(var f=0;f<h;f++){for(var d=[],p=0;p<u;p++)d.push(new Int32Array(64));c.push(d);}t.blocksPerLine=s,t.blocksPerColumn=l,t.blocks=c;}e.maxH=r,e.maxV=n,e.mcusPerLine=a,e.mcusPerColumn=o;}t.length;var o,s,l,u,d=null,p=null,m=[],g=[],b=[],y=[],w=n(),v=-1;if(this.comments=[],65496!=w)throw new Error("SOI not found");for(w=n();65497!=w;){switch(w){case 65280:break;case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:case 65534:var x=(l=void 0,u=void 0,l=n(),u=t.subarray(r,r+l-2),r+=u.length,u);if(65534===w){var E=String.fromCharCode.apply(null,x);this.comments.push(E);}65504===w&&74===x[0]&&70===x[1]&&73===x[2]&&70===x[3]&&0===x[4]&&(d={version:{major:x[5],minor:x[6]},densityUnits:x[7],xDensity:x[8]<<8|x[9],yDensity:x[10]<<8|x[11],thumbWidth:x[12],thumbHeight:x[13],thumbData:x.subarray(14,14+3*x[12]*x[13])}),65505===w&&69===x[0]&&120===x[1]&&105===x[2]&&102===x[3]&&0===x[4]&&(this.exifBuffer=x.subarray(5,x.length)),65518===w&&65===x[0]&&100===x[1]&&111===x[2]&&98===x[3]&&101===x[4]&&0===x[5]&&(p={version:x[6],flags0:x[7]<<8|x[8],flags1:x[9]<<8|x[10],transformCode:x[11]});break;case 65499:for(var k=n()+r-2;r<k;){var S=t[r++];_(256);var A=new Int32Array(64);if(S>>4){if(S>>4!=1)throw new Error("DQT: invalid table spec");for(q=0;q<64;q++)A[e[q]]=n();}else for(q=0;q<64;q++)A[e[q]]=t[r++];m[15&S]=A;}break;case 65472:case 65473:case 65474:n(),(o={}).extended=65473===w,o.progressive=65474===w,o.precision=t[r++],o.scanLines=n(),o.samplesPerLine=n(),o.components={},o.componentsOrder=[];var I=o.scanLines*o.samplesPerLine;if(I>i){var M=Math.ceil((I-i)/1e6);throw new Error(`maxResolutionInMP limit exceeded by ${M}MP`)}var T,P=t[r++];for(Q=0;Q<P;Q++){T=t[r];var B=t[r+1]>>4,C=15&t[r+1],R=t[r+2];if(B<=0||C<=0)throw new Error("Invalid sampling factor, expected values above 0");o.componentsOrder.push(T),o.components[T]={h:B,v:C,quantizationIdx:R},r+=3;}a(o),g.push(o);break;case 65476:var z=n();for(Q=2;Q<z;){var F=t[r++],N=new Uint8Array(16),O=0;for(q=0;q<16;q++,r++)O+=N[q]=t[r];_(16+O);var D=new Uint8Array(O);for(q=0;q<O;q++,r++)D[q]=t[r];Q+=17+O,(F>>4?b:y)[15&F]=h(N,D);}break;case 65501:n(),s=n();break;case 65500:n(),n();break;case 65498:n();var $=t[r++],L=[];for(Q=0;Q<$;Q++){V=o.components[t[r++]];var U=t[r++];V.huffmanTableDC=y[U>>4],V.huffmanTableAC=b[15&U],L.push(V);}var Z=t[r++],j=t[r++],G=t[r++],H=c(t,r,o,L,s,Z,j,G>>4,15&G,this.opts);r+=H;break;case 65535:255!==t[r]&&r--;break;default:if(255==t[r-3]&&t[r-2]>=192&&t[r-2]<=254){r-=3;break}if(224===w||225==w){if(-1!==v)throw new Error(`first unknown JPEG marker at offset ${v.toString(16)}, second unknown JPEG marker ${w.toString(16)} at offset ${(r-1).toString(16)}`);v=r-1;const e=n();if(255===t[r+e-2]){r+=e-2;break}}throw new Error("unknown JPEG marker "+w.toString(16))}w=n();}if(1!=g.length)throw new Error("only single frame JPEGs supported");for(var Q=0;Q<g.length;Q++){var W=g[Q].components;for(var q in W)W[q].quantizationTable=m[W[q].quantizationIdx],delete W[q].quantizationIdx;}for(this.width=o.samplesPerLine,this.height=o.scanLines,this.jfif=d,this.adobe=p,this.components=[],Q=0;Q<o.componentsOrder.length;Q++){var V=o.components[o.componentsOrder[Q]];this.components.push({lines:f(0,V),scaleX:V.h/o.maxH,scaleY:V.v/o.maxV});}},getData:function(e,t){var i,r,n,a,o,s,l,u,h,c,f,p,m,g,b,y,w,v,x,E,k,S=this.width/e,A=this.height/t,I=0,M=e*t*this.components.length;_(M);var T=new Uint8Array(M);switch(this.components.length){case 1:for(i=this.components[0],c=0;c<t;c++)for(o=i.lines[0|c*i.scaleY*A],h=0;h<e;h++)f=o[0|h*i.scaleX*S],T[I++]=f;break;case 2:for(i=this.components[0],r=this.components[1],c=0;c<t;c++)for(o=i.lines[0|c*i.scaleY*A],s=r.lines[0|c*r.scaleY*A],h=0;h<e;h++)f=o[0|h*i.scaleX*S],T[I++]=f,f=s[0|h*r.scaleX*S],T[I++]=f;break;case 3:for(k=true,this.adobe&&this.adobe.transformCode?k=true:void 0!==this.opts.colorTransform&&(k=!!this.opts.colorTransform),i=this.components[0],r=this.components[1],n=this.components[2],c=0;c<t;c++)for(o=i.lines[0|c*i.scaleY*A],s=r.lines[0|c*r.scaleY*A],l=n.lines[0|c*n.scaleY*A],h=0;h<e;h++)k?(f=o[0|h*i.scaleX*S],p=s[0|h*r.scaleX*S],v=d(f+1.402*((m=l[0|h*n.scaleX*S])-128)),x=d(f-.3441363*(p-128)-.71413636*(m-128)),E=d(f+1.772*(p-128))):(v=o[0|h*i.scaleX*S],x=s[0|h*r.scaleX*S],E=l[0|h*n.scaleX*S]),T[I++]=v,T[I++]=x,T[I++]=E;break;case 4:if(!this.adobe)throw new Error("Unsupported color mode (4 components)");for(k=false,this.adobe&&this.adobe.transformCode?k=true:void 0!==this.opts.colorTransform&&(k=!!this.opts.colorTransform),i=this.components[0],r=this.components[1],n=this.components[2],a=this.components[3],c=0;c<t;c++)for(o=i.lines[0|c*i.scaleY*A],s=r.lines[0|c*r.scaleY*A],l=n.lines[0|c*n.scaleY*A],u=a.lines[0|c*a.scaleY*A],h=0;h<e;h++)k?(f=o[0|h*i.scaleX*S],p=s[0|h*r.scaleX*S],m=l[0|h*n.scaleX*S],g=u[0|h*a.scaleX*S],b=255-d(f+1.402*(m-128)),y=255-d(f-.3441363*(p-128)-.71413636*(m-128)),w=255-d(f+1.772*(p-128))):(b=o[0|h*i.scaleX*S],y=s[0|h*r.scaleX*S],w=l[0|h*n.scaleX*S],g=u[0|h*a.scaleX*S]),T[I++]=255-b,T[I++]=255-y,T[I++]=255-w,T[I++]=255-g;break;default:throw new Error("Unsupported color mode")}return T},copyToImageData:function(e,t){var i,r,n,a,o,s,l,u,h,c=e.width,f=e.height,p=e.data,m=this.getData(c,f),_=0,g=0;switch(this.components.length){case 1:for(r=0;r<f;r++)for(i=0;i<c;i++)n=m[_++],p[g++]=n,p[g++]=n,p[g++]=n,t&&(p[g++]=255);break;case 3:for(r=0;r<f;r++)for(i=0;i<c;i++)l=m[_++],u=m[_++],h=m[_++],p[g++]=l,p[g++]=u,p[g++]=h,t&&(p[g++]=255);break;case 4:for(r=0;r<f;r++)for(i=0;i<c;i++)o=m[_++],s=m[_++],n=m[_++],l=255-d(o*(1-(a=m[_++])/255)+a),u=255-d(s*(1-a/255)+a),h=255-d(n*(1-a/255)+a),p[g++]=l,p[g++]=u,p[g++]=h,t&&(p[g++]=255);break;default:throw new Error("Unsupported color mode")}}};var p=0,m=0;function _(e=0){var t=p+e;if(t>m){var i=Math.ceil((t-m)/1024/1024);throw new Error(`maxMemoryUsageInMB limit exceeded by at least ${i}MB`)}p=t;}return u.resetMaxMemoryUsage=function(e){p=0,m=e;},u.getBytesAllocated=function(){return p},u.requestMemoryAllocation=_,u}(),module.exports=function(e,t={}){var i={colorTransform:void 0,useTArray:false,formatAsRGBA:true,tolerantDecoding:true,maxResolutionInMP:100,maxMemoryUsageInMB:512,...t},r=new Uint8Array(e),n=new JpegImage;n.opts=i,JpegImage.resetMaxMemoryUsage(1024*i.maxMemoryUsageInMB*1024),n.parse(r);var a=i.formatAsRGBA?4:3,o=n.width*n.height*a;try{JpegImage.requestMemoryAllocation(o);var s={width:n.width,height:n.height,exifBuffer:n.exifBuffer,data:i.useTArray?new Uint8Array(o):Buffer.alloc(o)};n.comments.length>0&&(s.comments=n.comments);}catch(e){if(e instanceof RangeError)throw new Error("Could not allocate enough memory for the image. Required: "+o);if(e instanceof ReferenceError&&"Buffer is not defined"===e.message)throw new Error("Buffer is not globally defined in this environment. Consider setting useTArray to true");throw e}return n.copyToImageData(s,i.formatAsRGBA),s};var decoderExports=decoder.exports,encode=encoderExports,decode=decoderExports,jpegJs={encode:encode,decode:decode},JPEG=getDefaultExportFromCjs(jpegJs);function jpeg$2(){return {mime:"image/jpeg",encode:(e,{quality:t=100}={})=>JPEG.encode(e,t).data,decode:(e,t)=>JPEG.decode(e,t)}}function commonjsRequire(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var browser$1={exports:{}};browser$1.exports=function(){function e(t,i,r){function n(o,s){if(!i[o]){if(!t[o]){var l="function"==typeof commonjsRequire&&commonjsRequire;if(!s&&l)return l(o,true);if(a)return a(o,true);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var h=i[o]={exports:{}};t[o][0].call(h.exports,(function(e){return n(t[o][1][e]||e)}),h,h.exports,e,t,i,r);}return i[o].exports}for(var a="function"==typeof commonjsRequire&&commonjsRequire,o=0;o<r.length;o++)n(r[o]);return n}return e}()({1:[function(e,t,i){(function(t){(function(){let r=e("./interlace"),n=[function(){},function(e,t,i,r){if(r===t.length)throw new Error("Ran out of data");let n=t[r];e[i]=n,e[i+1]=n,e[i+2]=n,e[i+3]=255;},function(e,t,i,r){if(r+1>=t.length)throw new Error("Ran out of data");let n=t[r];e[i]=n,e[i+1]=n,e[i+2]=n,e[i+3]=t[r+1];},function(e,t,i,r){if(r+2>=t.length)throw new Error("Ran out of data");e[i]=t[r],e[i+1]=t[r+1],e[i+2]=t[r+2],e[i+3]=255;},function(e,t,i,r){if(r+3>=t.length)throw new Error("Ran out of data");e[i]=t[r],e[i+1]=t[r+1],e[i+2]=t[r+2],e[i+3]=t[r+3];}],a=[function(){},function(e,t,i,r){let n=t[0];e[i]=n,e[i+1]=n,e[i+2]=n,e[i+3]=r;},function(e,t,i){let r=t[0];e[i]=r,e[i+1]=r,e[i+2]=r,e[i+3]=t[1];},function(e,t,i,r){e[i]=t[0],e[i+1]=t[1],e[i+2]=t[2],e[i+3]=r;},function(e,t,i){e[i]=t[0],e[i+1]=t[1],e[i+2]=t[2],e[i+3]=t[3];}];function o(e,t){let i=[],r=0;function n(){if(r===e.length)throw new Error("Ran out of data");let n,a,o,s,l,u,h,c,f=e[r];switch(r++,t){default:throw new Error("unrecognised depth");case 16:h=e[r],r++,i.push((f<<8)+h);break;case 4:h=15&f,c=f>>4,i.push(c,h);break;case 2:l=3&f,u=f>>2&3,h=f>>4&3,c=f>>6&3,i.push(c,h,u,l);break;case 1:n=1&f,a=f>>1&1,o=f>>2&1,s=f>>3&1,l=f>>4&1,u=f>>5&1,h=f>>6&1,c=f>>7&1,i.push(c,h,u,l,s,o,a,n);}}return {get:function(e){for(;i.length<e;)n();let t=i.slice(0,e);return i=i.slice(e),t},resetAfterLine:function(){i.length=0;},end:function(){if(r!==e.length)throw new Error("extra data found")}}}function s(e,t,i,r,a,o){let s=e.width,l=e.height,u=e.index;for(let e=0;e<l;e++)for(let l=0;l<s;l++){let s=i(l,e,u);n[r](t,a,s,o),o+=r;}return o}function l(e,t,i,r,n,o){let s=e.width,l=e.height,u=e.index;for(let e=0;e<l;e++){for(let l=0;l<s;l++){let s=n.get(r),h=i(l,e,u);a[r](t,s,h,o);}n.resetAfterLine();}}i.dataToBitMap=function(e,i){let n,a,u=i.width,h=i.height,c=i.depth,f=i.bpp,d=i.interlace;8!==c&&(n=o(e,c)),a=c<=8?t.alloc(u*h*4):new Uint16Array(u*h*4);let p,m,_=Math.pow(2,c)-1,g=0;if(d)p=r.getImagePasses(u,h),m=r.getInterlaceIterator(u,h);else {let e=0;m=function(){let t=e;return e+=4,t},p=[{width:u,height:h}];}for(let t=0;t<p.length;t++)8===c?g=s(p[t],a,m,f,e,g):l(p[t],a,m,f,n,_);if(8===c){if(g!==e.length)throw new Error("extra data found")}else n.end();return a};}).call(this);}).call(this,e("buffer").Buffer);},{"./interlace":11,buffer:32}],2:[function(e,t,i){(function(i){(function(){let r=e("./constants");t.exports=function(e,t,n,a){let o=-1!==[r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(a.colorType);if(a.colorType===a.inputColorType){let t=function(){let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,true),256!==new Int16Array(e)[0]}();if(8===a.bitDepth||16===a.bitDepth&&t)return e}let s=16!==a.bitDepth?e:new Uint16Array(e.buffer),l=255,u=r.COLORTYPE_TO_BPP_MAP[a.inputColorType];4!==u||a.inputHasAlpha||(u=3);let h=r.COLORTYPE_TO_BPP_MAP[a.colorType];16===a.bitDepth&&(l=65535,h*=2);let c=i.alloc(t*n*h),f=0,d=0,p=a.bgColor||{};function m(){let e,t,i,n=l;switch(a.inputColorType){case r.COLORTYPE_COLOR_ALPHA:n=s[f+3],e=s[f],t=s[f+1],i=s[f+2];break;case r.COLORTYPE_COLOR:e=s[f],t=s[f+1],i=s[f+2];break;case r.COLORTYPE_ALPHA:n=s[f+1],e=s[f],t=e,i=e;break;case r.COLORTYPE_GRAYSCALE:e=s[f],t=e,i=e;break;default:throw new Error("input color type:"+a.inputColorType+" is not supported at present")}return a.inputHasAlpha&&(o||(n/=l,e=Math.min(Math.max(Math.round((1-n)*p.red+n*e),0),l),t=Math.min(Math.max(Math.round((1-n)*p.green+n*t),0),l),i=Math.min(Math.max(Math.round((1-n)*p.blue+n*i),0),l))),{red:e,green:t,blue:i,alpha:n}} void 0===p.red&&(p.red=l),void 0===p.green&&(p.green=l),void 0===p.blue&&(p.blue=l);for(let e=0;e<n;e++)for(let e=0;e<t;e++){let e=m();switch(a.colorType){case r.COLORTYPE_COLOR_ALPHA:case r.COLORTYPE_COLOR:8===a.bitDepth?(c[d]=e.red,c[d+1]=e.green,c[d+2]=e.blue,o&&(c[d+3]=e.alpha)):(c.writeUInt16BE(e.red,d),c.writeUInt16BE(e.green,d+2),c.writeUInt16BE(e.blue,d+4),o&&c.writeUInt16BE(e.alpha,d+6));break;case r.COLORTYPE_ALPHA:case r.COLORTYPE_GRAYSCALE:{let t=(e.red+e.green+e.blue)/3;8===a.bitDepth?(c[d]=t,o&&(c[d+1]=e.alpha)):(c.writeUInt16BE(t,d),o&&c.writeUInt16BE(e.alpha,d+2));break}default:throw new Error("unrecognised color Type "+a.colorType)}f+=u,d+=h;}return c};}).call(this);}).call(this,e("buffer").Buffer);},{"./constants":4,buffer:32}],3:[function(e,t,i){(function(i,r){(function(){let n=e("util"),a=e("stream"),o=t.exports=function(){a.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=false,this._encoding="utf8",this.writable=true;};n.inherits(o,a),o.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t}),i.nextTick(function(){this._process(),this._paused&&this._reads&&this._reads.length>0&&(this._paused=false,this.emit("drain"));}.bind(this));},o.prototype.write=function(e,t){if(!this.writable)return this.emit("error",new Error("Stream not writable")),false;let i;return i=r.isBuffer(e)?e:r.from(e,t||this._encoding),this._buffers.push(i),this._buffered+=i.length,this._process(),this._reads&&0===this._reads.length&&(this._paused=true),this.writable&&!this._paused},o.prototype.end=function(e,t){e&&this.write(e,t),this.writable=false,this._buffers&&(0===this._buffers.length?this._end():(this._buffers.push(null),this._process()));},o.prototype.destroySoon=o.prototype.end,o.prototype._end=function(){this._reads.length>0&&this.emit("error",new Error("Unexpected end of input")),this.destroy();},o.prototype.destroy=function(){this._buffers&&(this.writable=false,this._reads=null,this._buffers=null,this.emit("close"));},o.prototype._processReadAllowingLess=function(e){this._reads.shift();let t=this._buffers[0];t.length>e.length?(this._buffered-=e.length,this._buffers[0]=t.slice(e.length),e.func.call(this,t.slice(0,e.length))):(this._buffered-=t.length,this._buffers.shift(),e.func.call(this,t));},o.prototype._processRead=function(e){this._reads.shift();let t=0,i=0,n=r.alloc(e.length);for(;t<e.length;){let r=this._buffers[i++],a=Math.min(r.length,e.length-t);r.copy(n,t,0,a),t+=a,a!==r.length&&(this._buffers[--i]=r.slice(a));}i>0&&this._buffers.splice(0,i),this._buffered-=e.length,e.func.call(this,n);},o.prototype._process=function(){try{for(;this._buffered>0&&this._reads&&this._reads.length>0;){let e=this._reads[0];if(e.allowLess)this._processReadAllowingLess(e);else {if(!(this._buffered>=e.length))break;this._processRead(e);}}this._buffers&&!this.writable&&this._end();}catch(e){this.emit("error",e);}};}).call(this);}).call(this,e("_process"),e("buffer").Buffer);},{_process:63,buffer:32,stream:65,util:84}],4:[function(e,t,i){t.exports={PNG_SIGNATURE:[137,80,78,71,13,10,26,10],TYPE_IHDR:1229472850,TYPE_IEND:1229278788,TYPE_IDAT:1229209940,TYPE_PLTE:1347179589,TYPE_tRNS:1951551059,TYPE_gAMA:1732332865,COLORTYPE_GRAYSCALE:0,COLORTYPE_PALETTE:1,COLORTYPE_COLOR:2,COLORTYPE_ALPHA:4,COLORTYPE_PALETTE_COLOR:3,COLORTYPE_COLOR_ALPHA:6,COLORTYPE_TO_BPP_MAP:{0:1,2:3,3:1,4:2,6:4},GAMMA_DIVISION:1e5};},{}],5:[function(e,t,i){let r=[];!function(){for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)1&t?t=3988292384^t>>>1:t>>>=1;r[e]=t;}}();let n=t.exports=function(){this._crc=-1;};n.prototype.write=function(e){for(let t=0;t<e.length;t++)this._crc=r[255&(this._crc^e[t])]^this._crc>>>8;return true},n.prototype.crc32=function(){return ~this._crc},n.crc32=function(e){let t=-1;for(let i=0;i<e.length;i++)t=r[255&(t^e[i])]^t>>>8;return ~t};},{}],6:[function(e,t,i){(function(i){(function(){let r=e("./paeth-predictor");function n(e,t,i,r,n){for(let a=0;a<i;a++)r[n+a]=e[t+a];}function a(e,t,i){let r=0,n=t+i;for(let i=t;i<n;i++)r+=Math.abs(e[i]);return r}function o(e,t,i,r,n,a){for(let o=0;o<i;o++){let i=o>=a?e[t+o-a]:0,s=e[t+o]-i;r[n+o]=s;}}function s(e,t,i,r){let n=0;for(let a=0;a<i;a++){let i=a>=r?e[t+a-r]:0,o=e[t+a]-i;n+=Math.abs(o);}return n}function l(e,t,i,r,n){for(let a=0;a<i;a++){let o=t>0?e[t+a-i]:0,s=e[t+a]-o;r[n+a]=s;}}function u(e,t,i){let r=0,n=t+i;for(let a=t;a<n;a++){let n=t>0?e[a-i]:0,o=e[a]-n;r+=Math.abs(o);}return r}function h(e,t,i,r,n,a){for(let o=0;o<i;o++){let s=o>=a?e[t+o-a]:0,l=t>0?e[t+o-i]:0,u=e[t+o]-(s+l>>1);r[n+o]=u;}}function c(e,t,i,r){let n=0;for(let a=0;a<i;a++){let o=a>=r?e[t+a-r]:0,s=t>0?e[t+a-i]:0,l=e[t+a]-(o+s>>1);n+=Math.abs(l);}return n}function f(e,t,i,n,a,o){for(let s=0;s<i;s++){let l=s>=o?e[t+s-o]:0,u=t>0?e[t+s-i]:0,h=t>0&&s>=o?e[t+s-(i+o)]:0,c=e[t+s]-r(l,u,h);n[a+s]=c;}}function d(e,t,i,n){let a=0;for(let o=0;o<i;o++){let s=o>=n?e[t+o-n]:0,l=t>0?e[t+o-i]:0,u=t>0&&o>=n?e[t+o-(i+n)]:0,h=e[t+o]-r(s,l,u);a+=Math.abs(h);}return a}let p={0:n,1:o,2:l,3:h,4:f},m={0:a,1:s,2:u,3:c,4:d};t.exports=function(e,t,r,n,a){let o;if("filterType"in n&&-1!==n.filterType){if("number"!=typeof n.filterType)throw new Error("unrecognised filter types");o=[n.filterType];}else o=[0,1,2,3,4];16===n.bitDepth&&(a*=2);let s=t*a,l=0,u=0,h=i.alloc((s+1)*r),c=o[0];for(let t=0;t<r;t++){if(o.length>1){let t=1/0;for(let i=0;i<o.length;i++){let r=m[o[i]](e,u,s,a);r<t&&(c=o[i],t=r);}}h[l]=c,l++,p[c](e,u,s,h,l,a),l+=s,u+=s;}return h};}).call(this);}).call(this,e("buffer").Buffer);},{"./paeth-predictor":15,buffer:32}],7:[function(e,t,i){(function(i){(function(){let r=e("util"),n=e("./chunkstream"),a=e("./filter-parse"),o=t.exports=function(e){n.call(this);let t=[],r=this;this._filter=new a(e,{read:this.read.bind(this),write:function(e){t.push(e);},complete:function(){r.emit("complete",i.concat(t));}}),this._filter.start();};r.inherits(o,n);}).call(this);}).call(this,e("buffer").Buffer);},{"./chunkstream":3,"./filter-parse":9,buffer:32,util:84}],8:[function(e,t,i){(function(t){(function(){let r=e("./sync-reader"),n=e("./filter-parse");i.process=function(e,i){let a=[],o=new r(e);return new n(i,{read:o.read.bind(o),write:function(e){a.push(e);},complete:function(){}}).start(),o.process(),t.concat(a)};}).call(this);}).call(this,e("buffer").Buffer);},{"./filter-parse":9,"./sync-reader":22,buffer:32}],9:[function(e,t,i){(function(i){(function(){let r=e("./interlace"),n=e("./paeth-predictor");function a(e,t,i){let r=e*t;return 8!==i&&(r=Math.ceil(r/(8/i))),r}let o=t.exports=function(e,t){let i=e.width,n=e.height,o=e.interlace,s=e.bpp,l=e.depth;if(this.read=t.read,this.write=t.write,this.complete=t.complete,this._imageIndex=0,this._images=[],o){let e=r.getImagePasses(i,n);for(let t=0;t<e.length;t++)this._images.push({byteWidth:a(e[t].width,s,l),height:e[t].height,lineIndex:0});}else this._images.push({byteWidth:a(i,s,l),height:n,lineIndex:0});this._xComparison=8===l?s:16===l?2*s:1;};o.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this));},o.prototype._unFilterType1=function(e,t,i){let r=this._xComparison,n=r-1;for(let a=0;a<i;a++){let i=e[1+a],o=a>n?t[a-r]:0;t[a]=i+o;}},o.prototype._unFilterType2=function(e,t,i){let r=this._lastLine;for(let n=0;n<i;n++){let i=e[1+n],a=r?r[n]:0;t[n]=i+a;}},o.prototype._unFilterType3=function(e,t,i){let r=this._xComparison,n=r-1,a=this._lastLine;for(let o=0;o<i;o++){let i=e[1+o],s=a?a[o]:0,l=o>n?t[o-r]:0,u=Math.floor((l+s)/2);t[o]=i+u;}},o.prototype._unFilterType4=function(e,t,i){let r=this._xComparison,a=r-1,o=this._lastLine;for(let s=0;s<i;s++){let i=e[1+s],l=o?o[s]:0,u=s>a?t[s-r]:0,h=s>a&&o?o[s-r]:0,c=n(u,l,h);t[s]=i+c;}},o.prototype._reverseFilterLine=function(e){let t,r=e[0],n=this._images[this._imageIndex],a=n.byteWidth;if(0===r)t=e.slice(1,a+1);else switch(t=i.alloc(a),r){case 1:this._unFilterType1(e,t,a);break;case 2:this._unFilterType2(e,t,a);break;case 3:this._unFilterType3(e,t,a);break;case 4:this._unFilterType4(e,t,a);break;default:throw new Error("Unrecognised filter type - "+r)}this.write(t),n.lineIndex++,n.lineIndex>=n.height?(this._lastLine=null,this._imageIndex++,n=this._images[this._imageIndex]):this._lastLine=t,n?this.read(n.byteWidth+1,this._reverseFilterLine.bind(this)):(this._lastLine=null,this.complete());};}).call(this);}).call(this,e("buffer").Buffer);},{"./interlace":11,"./paeth-predictor":15,buffer:32}],10:[function(e,t,i){(function(e){(function(){function i(e,t,i,r,n){let a=0;for(let o=0;o<r;o++)for(let r=0;r<i;r++){let i=n[e[a]];if(!i)throw new Error("index "+e[a]+" not in palette");for(let e=0;e<4;e++)t[a+e]=i[e];a+=4;}}function r(e,t,i,r,n){let a=0;for(let o=0;o<r;o++)for(let r=0;r<i;r++){let i=false;if(1===n.length?n[0]===e[a]&&(i=true):n[0]===e[a]&&n[1]===e[a+1]&&n[2]===e[a+2]&&(i=true),i)for(let e=0;e<4;e++)t[a+e]=0;a+=4;}}function n(e,t,i,r,n){let a=255,o=Math.pow(2,n)-1,s=0;for(let n=0;n<r;n++)for(let r=0;r<i;r++){for(let i=0;i<4;i++)t[s+i]=Math.floor(e[s+i]*a/o+.5);s+=4;}}t.exports=function(t,a,o=false){let s=a.depth,l=a.width,u=a.height,h=a.colorType,c=a.transColor,f=a.palette,d=t;return 3===h?i(t,d,l,u,f):(c&&r(t,d,l,u,c),8===s||o||(16===s&&(d=e.alloc(l*u*4)),n(t,d,l,u,s))),d};}).call(this);}).call(this,e("buffer").Buffer);},{buffer:32}],11:[function(e,t,i){let r=[{x:[0],y:[0]},{x:[4],y:[0]},{x:[0,4],y:[4]},{x:[2,6],y:[0,4]},{x:[0,2,4,6],y:[2,6]},{x:[1,3,5,7],y:[0,2,4,6]},{x:[0,1,2,3,4,5,6,7],y:[1,3,5,7]}];i.getImagePasses=function(e,t){let i=[],n=e%8,a=t%8,o=(e-n)/8,s=(t-a)/8;for(let e=0;e<r.length;e++){let t=r[e],l=o*t.x.length,u=s*t.y.length;for(let e=0;e<t.x.length&&t.x[e]<n;e++)l++;for(let e=0;e<t.y.length&&t.y[e]<a;e++)u++;l>0&&u>0&&i.push({width:l,height:u,index:e});}return i},i.getInterlaceIterator=function(e){return function(t,i,n){let a=t%r[n].x.length,o=(t-a)/r[n].x.length*8+r[n].x[a],s=i%r[n].y.length;return 4*o+((i-s)/r[n].y.length*8+r[n].y[s])*e*4}};},{}],12:[function(e,t,i){(function(i){(function(){let r=e("util"),n=e("stream"),a=e("./constants"),o=e("./packer"),s=t.exports=function(e){n.call(this);let t=e||{};this._packer=new o(t),this._deflate=this._packer.createDeflate(),this.readable=true;};r.inherits(s,n),s.prototype.pack=function(e,t,r,n){this.emit("data",i.from(a.PNG_SIGNATURE)),this.emit("data",this._packer.packIHDR(t,r)),n&&this.emit("data",this._packer.packGAMA(n));let o=this._packer.filterData(e,t,r);this._deflate.on("error",this.emit.bind(this,"error")),this._deflate.on("data",function(e){this.emit("data",this._packer.packIDAT(e));}.bind(this)),this._deflate.on("end",function(){this.emit("data",this._packer.packIEND()),this.emit("end");}.bind(this)),this._deflate.end(o);};}).call(this);}).call(this,e("buffer").Buffer);},{"./constants":4,"./packer":14,buffer:32,stream:65,util:84}],13:[function(e,t,i){(function(i){(function(){let r=true,n=e("zlib");n.deflateSync||(r=false);let a=e("./constants"),o=e("./packer");t.exports=function(e,t){if(!r)throw new Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let s=new o(t||{}),l=[];l.push(i.from(a.PNG_SIGNATURE)),l.push(s.packIHDR(e.width,e.height)),e.gamma&&l.push(s.packGAMA(e.gamma));let u=s.filterData(e.data,e.width,e.height),h=n.deflateSync(u,s.getDeflateOptions());if(u=null,!h||!h.length)throw new Error("bad png - invalid compressed data response");return l.push(s.packIDAT(h)),l.push(s.packIEND()),i.concat(l)};}).call(this);}).call(this,e("buffer").Buffer);},{"./constants":4,"./packer":14,buffer:32,zlib:31}],14:[function(e,t,i){(function(i){(function(){let r=e("./constants"),n=e("./crc"),a=e("./bitpacker"),o=e("./filter-pack"),s=e("zlib"),l=t.exports=function(e){if(this._options=e,e.deflateChunkSize=e.deflateChunkSize||32768,e.deflateLevel=null!=e.deflateLevel?e.deflateLevel:9,e.deflateStrategy=null!=e.deflateStrategy?e.deflateStrategy:3,e.inputHasAlpha=null==e.inputHasAlpha||e.inputHasAlpha,e.deflateFactory=e.deflateFactory||s.createDeflate,e.bitDepth=e.bitDepth||8,e.colorType="number"==typeof e.colorType?e.colorType:r.COLORTYPE_COLOR_ALPHA,e.inputColorType="number"==typeof e.inputColorType?e.inputColorType:r.COLORTYPE_COLOR_ALPHA,-1===[r.COLORTYPE_GRAYSCALE,r.COLORTYPE_COLOR,r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(e.colorType))throw new Error("option color type:"+e.colorType+" is not supported at present");if(-1===[r.COLORTYPE_GRAYSCALE,r.COLORTYPE_COLOR,r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(e.inputColorType))throw new Error("option input color type:"+e.inputColorType+" is not supported at present");if(8!==e.bitDepth&&16!==e.bitDepth)throw new Error("option bit depth:"+e.bitDepth+" is not supported at present")};l.prototype.getDeflateOptions=function(){return {chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}},l.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())},l.prototype.filterData=function(e,t,i){let n=a(e,t,i,this._options),s=r.COLORTYPE_TO_BPP_MAP[this._options.colorType];return o(n,t,i,this._options,s)},l.prototype._packChunk=function(e,t){let r=t?t.length:0,a=i.alloc(r+12);return a.writeUInt32BE(r,0),a.writeUInt32BE(e,4),t&&t.copy(a,8),a.writeInt32BE(n.crc32(a.slice(4,a.length-4)),a.length-4),a},l.prototype.packGAMA=function(e){let t=i.alloc(4);return t.writeUInt32BE(Math.floor(e*r.GAMMA_DIVISION),0),this._packChunk(r.TYPE_gAMA,t)},l.prototype.packIHDR=function(e,t){let n=i.alloc(13);return n.writeUInt32BE(e,0),n.writeUInt32BE(t,4),n[8]=this._options.bitDepth,n[9]=this._options.colorType,n[10]=0,n[11]=0,n[12]=0,this._packChunk(r.TYPE_IHDR,n)},l.prototype.packIDAT=function(e){return this._packChunk(r.TYPE_IDAT,e)},l.prototype.packIEND=function(){return this._packChunk(r.TYPE_IEND,null)};}).call(this);}).call(this,e("buffer").Buffer);},{"./bitpacker":2,"./constants":4,"./crc":5,"./filter-pack":6,buffer:32,zlib:31}],15:[function(e,t,i){t.exports=function(e,t,i){let r=e+t-i,n=Math.abs(r-e),a=Math.abs(r-t),o=Math.abs(r-i);return n<=a&&n<=o?e:a<=o?t:i};},{}],16:[function(e,t,i){let r=e("util"),n=e("zlib"),a=e("./chunkstream"),o=e("./filter-parse-async"),s=e("./parser"),l=e("./bitmapper"),u=e("./format-normaliser"),h=t.exports=function(e){a.call(this),this._parser=new s(e,{read:this.read.bind(this),error:this._handleError.bind(this),metadata:this._handleMetaData.bind(this),gamma:this.emit.bind(this,"gamma"),palette:this._handlePalette.bind(this),transColor:this._handleTransColor.bind(this),finished:this._finished.bind(this),inflateData:this._inflateData.bind(this),simpleTransparency:this._simpleTransparency.bind(this),headersFinished:this._headersFinished.bind(this)}),this._options=e,this.writable=true,this._parser.start();};r.inherits(h,a),h.prototype._handleError=function(e){this.emit("error",e),this.writable=false,this.destroy(),this._inflate&&this._inflate.destroy&&this._inflate.destroy(),this._filter&&(this._filter.destroy(),this._filter.on("error",(function(){}))),this.errord=true;},h.prototype._inflateData=function(e){if(!this._inflate)if(this._bitmapInfo.interlace)this._inflate=n.createInflate(),this._inflate.on("error",this.emit.bind(this,"error")),this._filter.on("complete",this._complete.bind(this)),this._inflate.pipe(this._filter);else {let e=(1+(this._bitmapInfo.width*this._bitmapInfo.bpp*this._bitmapInfo.depth+7>>3))*this._bitmapInfo.height,t=Math.max(e,n.Z_MIN_CHUNK);this._inflate=n.createInflate({chunkSize:t});let i=e,r=this.emit.bind(this,"error");this._inflate.on("error",(function(e){i&&r(e);})),this._filter.on("complete",this._complete.bind(this));let a=this._filter.write.bind(this._filter);this._inflate.on("data",(function(e){i&&(e.length>i&&(e=e.slice(0,i)),i-=e.length,a(e));})),this._inflate.on("end",this._filter.end.bind(this._filter));}this._inflate.write(e);},h.prototype._handleMetaData=function(e){this._metaData=e,this._bitmapInfo=Object.create(e),this._filter=new o(this._bitmapInfo);},h.prototype._handleTransColor=function(e){this._bitmapInfo.transColor=e;},h.prototype._handlePalette=function(e){this._bitmapInfo.palette=e;},h.prototype._simpleTransparency=function(){this._metaData.alpha=true;},h.prototype._headersFinished=function(){this.emit("metadata",this._metaData);},h.prototype._finished=function(){this.errord||(this._inflate?this._inflate.end():this.emit("error","No Inflate block"));},h.prototype._complete=function(e){if(this.errord)return;let t;try{let i=l.dataToBitMap(e,this._bitmapInfo);t=u(i,this._bitmapInfo,this._options.skipRescale),i=null;}catch(e){return void this._handleError(e)}this.emit("parsed",t);};},{"./bitmapper":1,"./chunkstream":3,"./filter-parse-async":7,"./format-normaliser":10,"./parser":18,util:84,zlib:31}],17:[function(e,t,i){(function(i){(function(){let r=true,n=e("zlib"),a=e("./sync-inflate");n.deflateSync||(r=false);let o=e("./sync-reader"),s=e("./filter-parse-sync"),l=e("./parser"),u=e("./bitmapper"),h=e("./format-normaliser");t.exports=function(e,t){if(!r)throw new Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let c,f,d;function p(e){c=e;}function m(e){f=e;}function _(e){f.transColor=e;}function g(e){f.palette=e;}function b(){f.alpha=true;}function y(e){d=e;}let w=[];function v(e){w.push(e);}let x=new o(e);if(new l(t,{read:x.read.bind(x),error:p,metadata:m,gamma:y,palette:g,transColor:_,inflateData:v,simpleTransparency:b}).start(),x.process(),c)throw c;let E,k=i.concat(w);if(w.length=0,f.interlace)E=n.inflateSync(k);else {let e=(1+(f.width*f.bpp*f.depth+7>>3))*f.height;E=a(k,{chunkSize:e,maxLength:e});}if(k=null,!E||!E.length)throw new Error("bad png - invalid inflate data response");let S=s.process(E,f);k=null;let A=u.dataToBitMap(S,f);S=null;let I=h(A,f,t.skipRescale);return f.data=I,f.gamma=d||0,f};}).call(this);}).call(this,e("buffer").Buffer);},{"./bitmapper":1,"./filter-parse-sync":8,"./format-normaliser":10,"./parser":18,"./sync-inflate":21,"./sync-reader":22,buffer:32,zlib:31}],18:[function(e,t,i){(function(i){(function(){let r=e("./constants"),n=e("./crc"),a=t.exports=function(e,t){this._options=e,e.checkCRC=false!==e.checkCRC,this._hasIHDR=false,this._hasIEND=false,this._emittedHeadersFinished=false,this._palette=[],this._colorType=0,this._chunks={},this._chunks[r.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[r.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[r.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[r.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[r.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[r.TYPE_gAMA]=this._handleGAMA.bind(this),this.read=t.read,this.error=t.error,this.metadata=t.metadata,this.gamma=t.gamma,this.transColor=t.transColor,this.palette=t.palette,this.parsed=t.parsed,this.inflateData=t.inflateData,this.finished=t.finished,this.simpleTransparency=t.simpleTransparency,this.headersFinished=t.headersFinished||function(){};};a.prototype.start=function(){this.read(r.PNG_SIGNATURE.length,this._parseSignature.bind(this));},a.prototype._parseSignature=function(e){let t=r.PNG_SIGNATURE;for(let i=0;i<t.length;i++)if(e[i]!==t[i])return void this.error(new Error("Invalid file signature"));this.read(8,this._parseChunkBegin.bind(this));},a.prototype._parseChunkBegin=function(e){let t=e.readUInt32BE(0),a=e.readUInt32BE(4),o="";for(let t=4;t<8;t++)o+=String.fromCharCode(e[t]);let s=Boolean(32&e[4]);if(this._hasIHDR||a===r.TYPE_IHDR){if(this._crc=new n,this._crc.write(i.from(o)),this._chunks[a])return this._chunks[a](t);s?this.read(t+4,this._skipChunk.bind(this)):this.error(new Error("Unsupported critical chunk type "+o));}else this.error(new Error("Expected IHDR on beggining"));},a.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this));},a.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this));},a.prototype._parseChunkEnd=function(e){let t=e.readInt32BE(0),i=this._crc.crc32();this._options.checkCRC&&i!==t?this.error(new Error("Crc error - "+t+" - "+i)):this._hasIEND||this.read(8,this._parseChunkBegin.bind(this));},a.prototype._handleIHDR=function(e){this.read(e,this._parseIHDR.bind(this));},a.prototype._parseIHDR=function(e){this._crc.write(e);let t=e.readUInt32BE(0),i=e.readUInt32BE(4),n=e[8],a=e[9],o=e[10],s=e[11],l=e[12];if(8!==n&&4!==n&&2!==n&&1!==n&&16!==n)return void this.error(new Error("Unsupported bit depth "+n));if(!(a in r.COLORTYPE_TO_BPP_MAP))return void this.error(new Error("Unsupported color type"));if(0!==o)return void this.error(new Error("Unsupported compression method"));if(0!==s)return void this.error(new Error("Unsupported filter method"));if(0!==l&&1!==l)return void this.error(new Error("Unsupported interlace method"));this._colorType=a;let u=r.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=true,this.metadata({width:t,height:i,depth:n,interlace:Boolean(l),palette:Boolean(a&r.COLORTYPE_PALETTE),color:Boolean(a&r.COLORTYPE_COLOR),alpha:Boolean(a&r.COLORTYPE_ALPHA),bpp:u,colorType:a}),this._handleChunkEnd();},a.prototype._handlePLTE=function(e){this.read(e,this._parsePLTE.bind(this));},a.prototype._parsePLTE=function(e){this._crc.write(e);let t=Math.floor(e.length/3);for(let i=0;i<t;i++)this._palette.push([e[3*i],e[3*i+1],e[3*i+2],255]);this.palette(this._palette),this._handleChunkEnd();},a.prototype._handleTRNS=function(e){this.simpleTransparency(),this.read(e,this._parseTRNS.bind(this));},a.prototype._parseTRNS=function(e){if(this._crc.write(e),this._colorType===r.COLORTYPE_PALETTE_COLOR){if(0===this._palette.length)return void this.error(new Error("Transparency chunk must be after palette"));if(e.length>this._palette.length)return void this.error(new Error("More transparent colors than palette size"));for(let t=0;t<e.length;t++)this._palette[t][3]=e[t];this.palette(this._palette);}this._colorType===r.COLORTYPE_GRAYSCALE&&this.transColor([e.readUInt16BE(0)]),this._colorType===r.COLORTYPE_COLOR&&this.transColor([e.readUInt16BE(0),e.readUInt16BE(2),e.readUInt16BE(4)]),this._handleChunkEnd();},a.prototype._handleGAMA=function(e){this.read(e,this._parseGAMA.bind(this));},a.prototype._parseGAMA=function(e){this._crc.write(e),this.gamma(e.readUInt32BE(0)/r.GAMMA_DIVISION),this._handleChunkEnd();},a.prototype._handleIDAT=function(e){this._emittedHeadersFinished||(this._emittedHeadersFinished=true,this.headersFinished()),this.read(-e,this._parseIDAT.bind(this,e));},a.prototype._parseIDAT=function(e,t){if(this._crc.write(t),this._colorType===r.COLORTYPE_PALETTE_COLOR&&0===this._palette.length)throw new Error("Expected palette not found");this.inflateData(t);let i=e-t.length;i>0?this._handleIDAT(i):this._handleChunkEnd();},a.prototype._handleIEND=function(e){this.read(e,this._parseIEND.bind(this));},a.prototype._parseIEND=function(e){this._crc.write(e),this._hasIEND=true,this._handleChunkEnd(),this.finished&&this.finished();};}).call(this);}).call(this,e("buffer").Buffer);},{"./constants":4,"./crc":5,buffer:32}],19:[function(e,t,i){let r=e("./parser-sync"),n=e("./packer-sync");i.read=function(e,t){return r(e,t||{})},i.write=function(e,t){return n(e,t)};},{"./packer-sync":13,"./parser-sync":17}],20:[function(e,t,i){(function(t,r){(function(){let n=e("util"),a=e("stream"),o=e("./parser-async"),s=e("./packer-async"),l=e("./png-sync"),u=i.PNG=function(e){a.call(this),e=e||{},this.width=0|e.width,this.height=0|e.height,this.data=this.width>0&&this.height>0?r.alloc(4*this.width*this.height):null,e.fill&&this.data&&this.data.fill(0),this.gamma=0,this.readable=this.writable=true,this._parser=new o(e),this._parser.on("error",this.emit.bind(this,"error")),this._parser.on("close",this._handleClose.bind(this)),this._parser.on("metadata",this._metadata.bind(this)),this._parser.on("gamma",this._gamma.bind(this)),this._parser.on("parsed",function(e){this.data=e,this.emit("parsed",e);}.bind(this)),this._packer=new s(e),this._packer.on("data",this.emit.bind(this,"data")),this._packer.on("end",this.emit.bind(this,"end")),this._parser.on("close",this._handleClose.bind(this)),this._packer.on("error",this.emit.bind(this,"error"));};n.inherits(u,a),u.sync=l,u.prototype.pack=function(){return this.data&&this.data.length?(t.nextTick(function(){this._packer.pack(this.data,this.width,this.height,this.gamma);}.bind(this)),this):(this.emit("error","No data provided"),this)},u.prototype.parse=function(e,t){if(t){let e,i;e=function(e){this.removeListener("error",i),this.data=e,t(null,this);}.bind(this),i=function(i){this.removeListener("parsed",e),t(i,null);}.bind(this),this.once("parsed",e),this.once("error",i);}return this.end(e),this},u.prototype.write=function(e){return this._parser.write(e),true},u.prototype.end=function(e){this._parser.end(e);},u.prototype._metadata=function(e){this.width=e.width,this.height=e.height,this.emit("metadata",e);},u.prototype._gamma=function(e){this.gamma=e;},u.prototype._handleClose=function(){this._parser.writable||this._packer.readable||this.emit("close");},u.bitblt=function(e,t,i,r,n,a,o,s){if(r|=0,n|=0,a|=0,o|=0,s|=0,(i|=0)>e.width||r>e.height||i+n>e.width||r+a>e.height)throw new Error("bitblt reading outside image");if(o>t.width||s>t.height||o+n>t.width||s+a>t.height)throw new Error("bitblt writing outside image");for(let l=0;l<a;l++)e.data.copy(t.data,(s+l)*t.width+o<<2,(r+l)*e.width+i<<2,(r+l)*e.width+i+n<<2);},u.prototype.bitblt=function(e,t,i,r,n,a,o){return u.bitblt(this,e,t,i,r,n,a,o),this},u.adjustGamma=function(e){if(e.gamma){for(let t=0;t<e.height;t++)for(let i=0;i<e.width;i++){let r=e.width*t+i<<2;for(let t=0;t<3;t++){let i=e.data[r+t]/255;i=Math.pow(i,1/2.2/e.gamma),e.data[r+t]=Math.round(255*i);}}e.gamma=0;}},u.prototype.adjustGamma=function(){u.adjustGamma(this);};}).call(this);}).call(this,e("_process"),e("buffer").Buffer);},{"./packer-async":12,"./parser-async":16,"./png-sync":19,_process:63,buffer:32,stream:65,util:84}],21:[function(e,t,i){(function(r,n){(function(){let r=e("assert").ok,a=e("zlib"),o=e("util"),s=e("buffer").kMaxLength;function l(e){if(!(this instanceof l))return new l(e);e&&e.chunkSize<a.Z_MIN_CHUNK&&(e.chunkSize=a.Z_MIN_CHUNK),a.Inflate.call(this,e),this._offset=void 0===this._offset?this._outOffset:this._offset,this._buffer=this._buffer||this._outBuffer,e&&null!=e.maxLength&&(this._maxLength=e.maxLength);}function u(e){return new l(e)}function h(e,t){e._handle&&(e._handle.close(),e._handle=null);}function c(e,t){if("string"==typeof t&&(t=n.from(t)),!(t instanceof n))throw new TypeError("Not a string or buffer");let i=e._finishFlushFlag;return null==i&&(i=a.Z_FINISH),e._processChunk(t,i)}function f(e,t){return c(new l(t),e)}l.prototype._processChunk=function(e,t,i){if("function"==typeof i)return a.Inflate._processChunk.call(this,e,t,i);let o,l,u=this,c=e&&e.length,f=this._chunkSize-this._offset,d=this._maxLength,p=0,m=[],_=0;function g(e,t){if(u._hadError)return;let i=f-t;if(r(i>=0,"have should not go down"),i>0){let e=u._buffer.slice(u._offset,u._offset+i);if(u._offset+=i,e.length>d&&(e=e.slice(0,d)),m.push(e),_+=e.length,d-=e.length,0===d)return false}return (0===t||u._offset>=u._chunkSize)&&(f=u._chunkSize,u._offset=0,u._buffer=n.allocUnsafe(u._chunkSize)),0===t&&(p+=c-e,c=e,true)}this.on("error",(function(e){o=e;})),r(this._handle,"zlib binding closed");do{l=this._handle.writeSync(t,e,p,c,this._buffer,this._offset,f),l=l||this._writeState;}while(!this._hadError&&g(l[0],l[1]));if(this._hadError)throw o;if(_>=s)throw h(this),new RangeError("Cannot create final Buffer. It would be larger than 0x"+s.toString(16)+" bytes");let b=n.concat(m,_);return h(this),b},o.inherits(l,a.Inflate),t.exports=i=f,i.Inflate=l,i.createInflate=u,i.inflateSync=f;}).call(this);}).call(this,e("_process"),e("buffer").Buffer);},{_process:63,assert:23,buffer:32,util:84,zlib:31}],22:[function(e,t,i){let r=t.exports=function(e){this._buffer=e,this._reads=[];};r.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t});},r.prototype.process=function(){for(;this._reads.length>0&&this._buffer.length;){let e=this._reads[0];if(!this._buffer.length||!(this._buffer.length>=e.length||e.allowLess))break;{this._reads.shift();let t=this._buffer;this._buffer=t.slice(e.length),e.func.call(this,t.slice(0,e.length));}}if(this._reads.length>0)throw new Error("There are some read requests waitng on finished stream");if(this._buffer.length>0)throw new Error("unrecognised content at end of stream")};},{}],23:[function(e,t,i){(function(i){(function(){var r=e("object-assign");
|
|
2980
2
|
/*!
|
|
2981
3
|
* The buffer module from node.js, for the browser.
|
|
@@ -3212,22 +234,76 @@ read:function(e,t,i,r,n){var a,o,s=8*n-r-1,l=(1<<s)-1,u=l>>1,h=-7,c=i?n-1:0,f=i?
|
|
|
3212
234
|
* rgbquant.ts - part of Image Quantization Library
|
|
3213
235
|
*/"function"==typeof setImmediate?setImmediate:"undefined"!=typeof process&&(null==process||process.nextTick);const QuantizeOptionsSchema=z.object({colors:z.number().optional(),colorDistanceFormula:z.union([z.literal("cie94-textiles"),z.literal("cie94-graphic-arts"),z.literal("ciede2000"),z.literal("color-metric"),z.literal("euclidean"),z.literal("euclidean-bt709-noalpha"),z.literal("euclidean-bt709"),z.literal("manhattan"),z.literal("manhattan-bt709"),z.literal("manhattan-nommyde"),z.literal("pngquant")]).optional(),paletteQuantization:z.union([z.literal("neuquant"),z.literal("neuquant-float"),z.literal("rgbquant"),z.literal("wuquant")]).optional(),imageQuantization:z.union([z.literal("nearest"),z.literal("riemersma"),z.literal("floyd-steinberg"),z.literal("false-floyd-steinberg"),z.literal("stucki"),z.literal("atkinson"),z.literal("jarvis"),z.literal("burkes"),z.literal("sierra"),z.literal("two-sierra"),z.literal("sierra-lite")]).optional()}),methods={quantize(e,t){const{colors:i,colorDistanceFormula:r,paletteQuantization:n,imageQuantization:a}=QuantizeOptionsSchema.parse(t),o=utils_exports.PointContainer.fromUint8Array(e.bitmap.data,e.bitmap.width,e.bitmap.height),s=applyPaletteSync(o,buildPaletteSync([o],{colors:i,colorDistanceFormula:r,paletteQuantization:n}),{colorDistanceFormula:r,imageQuantization:a});return e.bitmap.data=Buffer.from(s.toUint8Array()),e}};var parseBmfontAscii=function(e){if(!e)throw new Error("no data provided");var t={pages:[],chars:[],kernings:[]},i=(e=e.toString().trim()).split(/\r\n?|\n/g);if(0===i.length)throw new Error("no data in BMFont file");for(var r=0;r<i.length;r++){var n=splitLine(i[r],r);if(n)if("page"===n.key){if("number"!=typeof n.data.id)throw new Error("malformed file at line "+r+" -- needs page id=N");if("string"!=typeof n.data.file)throw new Error("malformed file at line "+r+' -- needs page file="path"');t.pages[n.data.id]=n.data.file;}else "chars"===n.key||"kernings"===n.key||("char"===n.key?t.chars.push(n.data):"kerning"===n.key?t.kernings.push(n.data):t[n.key]=n.data);}return t};function splitLine(e,t){if(!(e=e.replace(/\t+/g," ").trim()))return null;var i=e.indexOf(" ");if(-1===i)throw new Error("no named row at line "+t);var r=e.substring(0,i);e=(e=(e=(e=e.substring(i+1)).replace(/letter=[\'\"]\S+[\'\"]/gi,"")).split("=")).map((function(e){return e.trim().match(/(".*?"|[^"\s]+)+(?=\s*|\s*$)/g)}));for(var n=[],a=0;a<e.length;a++){var o=e[a];0===a?n.push({key:o[0],data:""}):a===e.length-1?n[n.length-1].data=parseData(o[0]):(n[n.length-1].data=parseData(o[0]),n.push({key:o[1],data:""}));}var s={key:r,data:{}};return n.forEach((function(e){s.data[e.key]=e.data;})),s}function parseData(e){return e&&0!==e.length?0===e.indexOf('"')||0===e.indexOf("'")?e.substring(1,e.length-1):-1!==e.indexOf(",")?parseIntList$1(e):parseInt(e,10):""}function parseIntList$1(e){return e.split(",").map((function(e){return parseInt(e,10)}))}getDefaultExportFromCjs(parseBmfontAscii);var GLYPH_DESIGNER_ERROR="chasrset",parseAttribs=function(e){for(var t in e=Object.assign({},e),GLYPH_DESIGNER_ERROR in e&&(e.charset=e[GLYPH_DESIGNER_ERROR],delete e[GLYPH_DESIGNER_ERROR]),e)"face"!==t&&"charset"!==t&&(e[t]="padding"===t||"spacing"===t?parseIntList(e[t]):parseInt(e[t],10));return e};function parseIntList(e){return e.split(",").map((function(e){return parseInt(e,10)}))}var xmlParseFromString=void 0!==self.DOMParser?function(e){return (new self.DOMParser).parseFromString(e,"application/xml")}:void 0!==self.ActiveXObject&&new self.ActiveXObject("Microsoft.XMLDOM")?function(e){var t=new self.ActiveXObject("Microsoft.XMLDOM");return t.async="false",t.loadXML(e),t}:function(e){var t=document.createElement("div");return t.innerHTML=e,t},parseAttributes=parseAttribs,parseFromString=xmlParseFromString,NAME_MAP={scaleh:"scaleH",scalew:"scaleW",stretchh:"stretchH",lineheight:"lineHeight",alphachnl:"alphaChnl",redchnl:"redChnl",greenchnl:"greenChnl",bluechnl:"blueChnl"},browser=function(e){e=e.toString();var t=parseFromString(e),i={pages:[],chars:[],kernings:[]};["info","common"].forEach((function(e){var r=t.getElementsByTagName(e)[0];r&&(i[e]=parseAttributes(getAttribs(r)));}));var r=t.getElementsByTagName("pages")[0];if(!r)throw new Error("malformed file -- no <pages> element");for(var n=r.getElementsByTagName("page"),a=0;a<n.length;a++){var o=n[a],s=parseInt(o.getAttribute("id"),10),l=o.getAttribute("file");if(isNaN(s))throw new Error('malformed file -- page "id" attribute is NaN');if(!l)throw new Error('malformed file -- needs page "file" attribute');i.pages[parseInt(s,10)]=l;}return ["chars","kernings"].forEach((function(e){var r=t.getElementsByTagName(e)[0];if(r)for(var n=e.substring(0,e.length-1),a=r.getElementsByTagName(n),o=0;o<a.length;o++){var s=a[o];i[e].push(parseAttributes(getAttribs(s)));}})),i};function getAttribs(e){return getAttribList(e).reduce((function(e,t){return e[mapName(t.nodeName)]=t.nodeValue,e}),{})}function getAttribList(e){for(var t=[],i=0;i<e.attributes.length;i++)t.push(e.attributes[i]);return t}function mapName(e){return NAME_MAP[e.toLowerCase()]||e}getDefaultExportFromCjs(browser);var HEADER$1=[66,77,70],parseBmfontBinary=function(e){if(e.length<6)throw new Error("invalid buffer length for BMFont");var t=HEADER$1.every((function(t,i){return e.readUInt8(i)===t}));if(!t)throw new Error("BMFont missing BMF byte header");var i=3;if(e.readUInt8(i++)>3)throw new Error("Only supports BMFont Binary v3 (BMFont App v1.10)");for(var r={kernings:[],chars:[]},n=0;n<5;n++)i+=readBlock(r,e,i);return r};function readBlock(e,t,i){if(i>t.length-1)return 0;var r=t.readUInt8(i++),n=t.readInt32LE(i);switch(i+=4,r){case 1:e.info=readInfo(t,i);break;case 2:e.common=readCommon(t,i);break;case 3:e.pages=readPages(t,i,n);break;case 4:e.chars=readChars(t,i,n);break;case 5:e.kernings=readKernings(t,i,n);}return 5+n}function readInfo(e,t){var i={};i.size=e.readInt16LE(t);var r=e.readUInt8(t+2);return i.smooth=r>>7&1,i.unicode=r>>6&1,i.italic=r>>5&1,i.bold=r>>4&1,r>>3&1&&(i.fixedHeight=1),i.charset=e.readUInt8(t+3)||"",i.stretchH=e.readUInt16LE(t+4),i.aa=e.readUInt8(t+6),i.padding=[e.readInt8(t+7),e.readInt8(t+8),e.readInt8(t+9),e.readInt8(t+10)],i.spacing=[e.readInt8(t+11),e.readInt8(t+12)],i.outline=e.readUInt8(t+13),i.face=readStringNT(e,t+14),i}function readCommon(e,t){var i={};return i.lineHeight=e.readUInt16LE(t),i.base=e.readUInt16LE(t+2),i.scaleW=e.readUInt16LE(t+4),i.scaleH=e.readUInt16LE(t+6),i.pages=e.readUInt16LE(t+8),e.readUInt8(t+10),i.packed=0,i.alphaChnl=e.readUInt8(t+11),i.redChnl=e.readUInt8(t+12),i.greenChnl=e.readUInt8(t+13),i.blueChnl=e.readUInt8(t+14),i}function readPages(e,t,i){for(var r=[],n=readNameNT(e,t),a=n.length+1,o=i/a,s=0;s<o;s++)r[s]=e.slice(t,t+n.length).toString("utf8"),t+=a;return r}function readChars(e,t,i){for(var r=[],n=i/20,a=0;a<n;a++){var o={},s=20*a;o.id=e.readUInt32LE(t+0+s),o.x=e.readUInt16LE(t+4+s),o.y=e.readUInt16LE(t+6+s),o.width=e.readUInt16LE(t+8+s),o.height=e.readUInt16LE(t+10+s),o.xoffset=e.readInt16LE(t+12+s),o.yoffset=e.readInt16LE(t+14+s),o.xadvance=e.readInt16LE(t+16+s),o.page=e.readUInt8(t+18+s),o.chnl=e.readUInt8(t+19+s),r[a]=o;}return r}function readKernings(e,t,i){for(var r=[],n=i/10,a=0;a<n;a++){var o={},s=10*a;o.first=e.readUInt32LE(t+0+s),o.second=e.readUInt32LE(t+4+s),o.amount=e.readInt16LE(t+8+s),r[a]=o;}return r}function readNameNT(e,t){for(var i=t;i<e.length&&0!==e[i];i++);return e.slice(t,i)}function readStringNT(e,t){return readNameNT(e,t).toString("utf8")}getDefaultExportFromCjs(parseBmfontBinary);function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}const t=e=>{if(!e)return null;const i={};switch(e.type){case "ELEMENT":{let n={};const a=E(e.value.attributes),o=t(e.value.children);if(a&&(n=Object.assign(n,a)),o){const t=r(e.value.children);n=Object.assign(n,t);}i[e.value.type]=n;break}case "ATTRIBUTE":{const t=e.value;i[t.name]=t.value;break}case "CONTENT":return {content:e.value}}return i},r=e=>e&&Array.isArray(e)&&0!==e.length?n(e)?{content:e[0].value}:{children:e.map(t)}:null,n=e=>e&&Array.isArray(e)&&1===e.length&&"CONTENT"===e[0].type,E=e=>e&&Array.isArray(e)?e.map(t).reduce(((e,t)=>Object.assign(e,t)),{}):null;var s={convert:e=>t(e.value.children[0])},a={Token:(e,t)=>({type:e,value:t}),TOKEN_TYPE:{OPEN_BRACKET:"OPEN_BRACKET",ELEMENT_TYPE:"ELEMENT_TYPE",CLOSE_ELEMENT:"CLOSE_ELEMENT",ATTRIB_NAME:"ATTRIB_NAME",ATTRIB_VALUE:"ATTRIB_VALUE",ASSIGN:"ASSIGN",CLOSE_BRACKET:"CLOSE_BRACKET",CONTENT:"CONTENT",EOF:"EOF"}};const{Token:T,TOKEN_TYPE:u}=a,c=T("EOF"),l=e=>" "===e||"\n"===e||"\r"===e||"\t"===e,o=e=>e.replace(/'/g,'"');var N={createLexer:function(e){let t=null,i=(e=>{let t=0;for(;t<e.length&&l(e[t]);)t++;return ((e,t)=>{if(e.startsWith("<?xml",t)){const i=e.length;for(;t<i;)if("?"!==e[t])t++;else {if(">"===e[t+1])return t+2;t++;}}return t})(e,t)})(e),r=[];const n=()=>e[i],a=()=>t!==c&&i<e.length,s=e=>'"'===e||"'"===e,h=()=>{for(;a()&&l(e[i]);)i++;},f=t=>{if(a()){if("<"===e[i]){let t="<";return i++,a()&&"/"===e[i]?(i++,t="</"):a()&&"!"===e[i]&&"-"===e[i+1]&&"-"===e[i+2]&&(i++,i++,i++,t="\x3c!--"),t}if("/"===n()){let e="/";return i++,a()&&">"===n()&&(i++,e="/>"),e}if("="===e[i]||">"===e[i]){const t=e[i];return i++,t}}return d(!!t)},d=t=>{const r=t?/[^>=<]/u:/[a-zA-Z0-9_:-]/;let n=i;for(;a()&&e[i].match(r);)i++;return o(e.substring(n,i))},p=()=>{const l=i;h();const m=i-l;if(a())if(t&&t.type===u.OPEN_BRACKET){h();const e=f(false);t=T(u.ELEMENT_TYPE,e),r.push(e);}else if(t&&t.type===u.ASSIGN){a()&&s(n())&&i++;let r=i;for(;a()&&!s(n());)i++;const l=o(e.substring(r,i));i++,t=T(u.ATTRIB_VALUE,l);}else {h();let o=f(true);switch(o){case "=":t=t.type===u.ATTRIB_NAME?T(u.ASSIGN):T(u.CONTENT,o);break;case "</":{const n=i;for(;">"!==e[i];)i++;t=T(u.CLOSE_ELEMENT,e.substring(n,i)),i++,r.pop();break}case "/>":{const e=r.pop();t=T(u.CLOSE_ELEMENT,e);break}case "\x3c!--":{const t=["!","-","-"];for(;a()&&(">"!==t[2]||"-"!==t[1]||"-"!==t[0]);)t.shift(),t.push(e[i]),i++;return p()}case ">":t=T(u.CLOSE_BRACKET);break;case "<":t=T(u.OPEN_BRACKET);break;default:if(o&&o.length>0){if(t.type===u.CLOSE_BRACKET){let e="";"<"!==n()&&(e=d(true)),t=T(u.CONTENT,o+e);}else if(t.type!==u.ATTRIB_NAME&&t.type!==u.CONTENT)t.type===u.CLOSE_ELEMENT?(o=" ".repeat(m)+o,t=T(u.CONTENT,o)):t=T(u.ATTRIB_NAME,o);else {const e=" ".repeat(m)+o;t=T(u.CONTENT,e);}break}{const t='Unknown Syntax : "'+e[i]+'"';throw new Error(t)}}}else t=c;return t};return {peek:n,next:p,hasNext:a}}};const{createLexer:i}=N,{Token:p,TOKEN_TYPE:O}=a,[A,f,C,h]=["ROOT","ELEMENT","ATTRIBUTE","CONTENT"],_=(e,t)=>({type:e,value:t}),L=e=>_(h,e),y=(e,t,i)=>_(f,{type:e,attributes:t,children:i}),v=(e,t)=>_(C,{name:e,value:t}),S=(e,t)=>{const i=[];for(;e.hasNext();){const r=e.next();switch(r.type){case O.OPEN_BRACKET:{const t=e.next(),[r,n]=R(e);let a=[];n.type!==O.CLOSE_ELEMENT&&(a=S(e,t)),a&&a.length>0&&a[0].type===O.CONTENT&&(a=b(a)),i.push(y(t.value,r,a));break}case O.CLOSE_ELEMENT:if(r.value===t.value)return i;break;case O.CONTENT:i.push(L(r.value));break;case O.EOF:return i;default:throw new Error(`Unknown Lexem type: ${r.type} "${r.value}, scoping element: ${t.value}"`)}}return i},R=e=>{const t=[];let i=e.peek();if(!e.hasNext()||i&&i.type===O.CLOSE_BRACKET||i&&i.type===O.CLOSE_ELEMENT)return [t,i];for(i=e.next();e.hasNext()&&i&&i.type!==O.CLOSE_BRACKET&&i.type!==O.CLOSE_ELEMENT;){const r=i;e.next();const n=e.next(),a=v(r.value,n.value);t.push(a),i=e.next();}return [t,i]};function b(e){let t=[],i="";return e.forEach((e=>{e.type===O.CONTENT?i+=e.value:(i.length&&(t.push(L(i)),i=""),t.push(e));})),i.length&&t.push(L(i)),t}var B={transpile:function(e,t){const r=(e=>_(A,{children:S(e,p(A,"ROOT"))}))(i(e));return t?t.convert(r):r}};const M=s,{transpile:x}=B;var k=e({convertXML:function(e,t){return x(e,t||M)},createAST:function(e){return x(e)}}),simpleXmlToJson_min=k,xmlPackage=getDefaultExportFromCjs(simpleXmlToJson_min);const {convertXML:convertXML}=xmlPackage;createJimp({formats:[png]});Buffer.from([66,77,70,3]);var pixelmatch_1=pixelmatch;const defaultOptions={threshold:.1,includeAA:false,alpha:.1,aaColor:[255,255,0],diffColor:[255,0,0],diffColorAlt:null,diffMask:false};function pixelmatch(e,t,i,r,n,a){if(!isPixelData(e)||!isPixelData(t)||i&&!isPixelData(i))throw new Error("Image data: Uint8Array, Uint8ClampedArray or Buffer expected.");if(e.length!==t.length||i&&i.length!==e.length)throw new Error("Image sizes do not match.");if(e.length!==r*n*4)throw new Error("Image data size does not match width/height.");a=Object.assign({},defaultOptions,a);const o=r*n,s=new Uint32Array(e.buffer,e.byteOffset,o),l=new Uint32Array(t.buffer,t.byteOffset,o);let u=true;for(let e=0;e<o;e++)if(s[e]!==l[e]){u=false;break}if(u){if(i&&!a.diffMask)for(let t=0;t<o;t++)drawGrayPixel(e,4*t,a.alpha,i);return 0}const h=35215*a.threshold*a.threshold;let c=0;for(let o=0;o<n;o++)for(let s=0;s<r;s++){const l=4*(o*r+s),u=colorDelta(e,t,l,l);Math.abs(u)>h?a.includeAA||!antialiased(e,s,o,r,n,t)&&!antialiased(t,s,o,r,n,e)?(i&&drawPixel(i,l,...u<0&&a.diffColorAlt||a.diffColor),c++):i&&!a.diffMask&&drawPixel(i,l,...a.aaColor):i&&(a.diffMask||drawGrayPixel(e,l,a.alpha,i));}return c}function isPixelData(e){return ArrayBuffer.isView(e)&&1===e.constructor.BYTES_PER_ELEMENT}function antialiased(e,t,i,r,n,a){const o=Math.max(t-1,0),s=Math.max(i-1,0),l=Math.min(t+1,r-1),u=Math.min(i+1,n-1),h=4*(i*r+t);let c,f,d,p,m=t===o||t===l||i===s||i===u?1:0,_=0,g=0;for(let n=o;n<=l;n++)for(let a=s;a<=u;a++){if(n===t&&a===i)continue;const o=colorDelta(e,e,h,4*(a*r+n),true);if(0===o){if(m++,m>2)return false}else o<_?(_=o,c=n,f=a):o>g&&(g=o,d=n,p=a);}return 0!==_&&0!==g&&(hasManySiblings(e,c,f,r,n)&&hasManySiblings(a,c,f,r,n)||hasManySiblings(e,d,p,r,n)&&hasManySiblings(a,d,p,r,n))}function hasManySiblings(e,t,i,r,n){const a=Math.max(t-1,0),o=Math.max(i-1,0),s=Math.min(t+1,r-1),l=Math.min(i+1,n-1),u=4*(i*r+t);let h=t===a||t===s||i===o||i===l?1:0;for(let n=a;n<=s;n++)for(let a=o;a<=l;a++){if(n===t&&a===i)continue;const o=4*(a*r+n);if(e[u]===e[o]&&e[u+1]===e[o+1]&&e[u+2]===e[o+2]&&e[u+3]===e[o+3]&&h++,h>2)return true}return false}function colorDelta(e,t,i,r,n){let a=e[i+0],o=e[i+1],s=e[i+2],l=e[i+3],u=t[r+0],h=t[r+1],c=t[r+2],f=t[r+3];if(l===f&&a===u&&o===h&&s===c)return 0;l<255&&(l/=255,a=blend(a,l),o=blend(o,l),s=blend(s,l)),f<255&&(f/=255,u=blend(u,f),h=blend(h,f),c=blend(c,f));const d=rgb2y(a,o,s),p=rgb2y(u,h,c),m=d-p;if(n)return m;const _=rgb2i(a,o,s)-rgb2i(u,h,c),g=rgb2q(a,o,s)-rgb2q(u,h,c),b=.5053*m*m+.299*_*_+.1957*g*g;return d>p?-b:b}function rgb2y(e,t,i){return .29889531*e+.58662247*t+.11448223*i}function rgb2i(e,t,i){return .59597799*e-.2741761*t-.32180189*i}function rgb2q(e,t,i){return .21147017*e-.52261711*t+.31114694*i}function blend(e,t){return 255+(e-255)*t}function drawPixel(e,t,i,r,n){e[t+0]=i,e[t+1]=r,e[t+2]=n,e[t+3]=255;}function drawGrayPixel(e,t,i,r){const n=blend(rgb2y(e[t+0],e[t+1],e[t+2]),i*e[t+3]/255);drawPixel(r,t,n,n,n);}getDefaultExportFromCjs(pixelmatch_1);const defaultPlugins=[methods$h,methods$g,methods$f,methods$e,methods$c,methods$a,methods$b,methods$9,methods$8,methods$7,methods$6,methods$5,methods$4,methods$3,methods$d,methods$2,methods$1,methods],defaultFormats=[bmp,msBmp,gif,jpeg$2,png,tiff];({bmp:bmp().mime,gif:gif().mime,jpeg:jpeg$2().mime,png:png().mime,tiff:tiff().mime});const Jimp=createJimp({formats:defaultFormats,plugins:defaultPlugins});
|
|
3214
236
|
|
|
3215
|
-
|
|
3216
|
-
*
|
|
3217
|
-
*
|
|
3218
|
-
*
|
|
3219
|
-
*
|
|
3220
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
3221
|
-
* (at your option) any later version.
|
|
3222
|
-
*
|
|
3223
|
-
* This program is distributed in the hope that it will be useful,
|
|
3224
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
3225
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
3226
|
-
* GNU General Public License for more details.
|
|
3227
|
-
*
|
|
3228
|
-
* You should have received a copy of the GNU General Public License
|
|
3229
|
-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
237
|
+
/**
|
|
238
|
+
* Decode PNG bytes (as produced by {@link renderPageRangePng}) into an RGBA
|
|
239
|
+
* image.
|
|
240
|
+
* `jimp.fromBuffer` accepts an ArrayBuffer directly, which keeps this usable in
|
|
241
|
+
* the browser without relying on Node's `Buffer`.
|
|
3230
242
|
*/
|
|
243
|
+
async function decodePng(png) {
|
|
244
|
+
return (await Jimp.fromBuffer(png));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const _enabled = (() => {
|
|
248
|
+
try {
|
|
249
|
+
if (typeof process !== "undefined" &&
|
|
250
|
+
process.env &&
|
|
251
|
+
process.env.PDFDIFF_PROFILE === "1") {
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
// process not available (e.g. in some browser worker environments)
|
|
257
|
+
}
|
|
258
|
+
const g = globalThis;
|
|
259
|
+
return g.__PDFDIFF_PROFILE__ === true;
|
|
260
|
+
})();
|
|
261
|
+
const _counters = Object.create(null);
|
|
262
|
+
const _NOOP_SPAN = Object.freeze({ stop() { } });
|
|
263
|
+
const _noop = () => { };
|
|
264
|
+
const _emptyDump = () => Object.freeze({});
|
|
265
|
+
const _realPerf = {
|
|
266
|
+
enabled: true,
|
|
267
|
+
span(key) {
|
|
268
|
+
const t0 = performance.now();
|
|
269
|
+
return {
|
|
270
|
+
stop() {
|
|
271
|
+
_counters[key] = (_counters[key] ?? 0) + (performance.now() - t0);
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
},
|
|
275
|
+
incr(key, delta = 1) {
|
|
276
|
+
_counters[key] = (_counters[key] ?? 0) + delta;
|
|
277
|
+
},
|
|
278
|
+
setMax(key, value) {
|
|
279
|
+
const cur = _counters[key];
|
|
280
|
+
if (cur === undefined || value > cur)
|
|
281
|
+
_counters[key] = value;
|
|
282
|
+
},
|
|
283
|
+
merge(other) {
|
|
284
|
+
for (const k of Object.keys(other)) {
|
|
285
|
+
_counters[k] = (_counters[k] ?? 0) + other[k];
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
dump() {
|
|
289
|
+
return { ..._counters };
|
|
290
|
+
},
|
|
291
|
+
reset() {
|
|
292
|
+
for (const k of Object.keys(_counters))
|
|
293
|
+
delete _counters[k];
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
const _noopPerf = {
|
|
297
|
+
enabled: false,
|
|
298
|
+
span: () => _NOOP_SPAN,
|
|
299
|
+
incr: _noop,
|
|
300
|
+
setMax: _noop,
|
|
301
|
+
merge: _noop,
|
|
302
|
+
dump: _emptyDump,
|
|
303
|
+
reset: _noop,
|
|
304
|
+
};
|
|
305
|
+
const perf = _enabled ? _realPerf : _noopPerf;
|
|
306
|
+
|
|
3231
307
|
function createEmptyImage(width, height) {
|
|
3232
308
|
return new Jimp({
|
|
3233
309
|
width,
|
|
@@ -3265,251 +341,109 @@ function alignSize(images, align) {
|
|
|
3265
341
|
? img
|
|
3266
342
|
: alignImage(img, largerWidth, largerHeight, align));
|
|
3267
343
|
}
|
|
3268
|
-
function composeLayers(canvasWidth, canvasHeight, layers) {
|
|
3269
|
-
const canvas = createEmptyImage(canvasWidth, canvasHeight);
|
|
3270
|
-
const dData = canvas.bitmap.data;
|
|
3271
|
-
for (const [image, opacity] of layers) {
|
|
3272
|
-
const sData = image.bitmap.data;
|
|
3273
|
-
const srcWidth = image.width;
|
|
3274
|
-
const w = Math.min(canvasWidth, srcWidth);
|
|
3275
|
-
const h = Math.min(canvasHeight, image.height);
|
|
3276
|
-
for (let y = 0; y < h; y++) {
|
|
3277
|
-
for (let x = 0; x < w; x++) {
|
|
3278
|
-
const dIdx = (y * canvasWidth + x) * 4;
|
|
3279
|
-
const sIdx = (y * srcWidth + x) * 4;
|
|
3280
|
-
const sa = (sData[sIdx + 3] / 255) * opacity;
|
|
3281
|
-
if (sa === 0)
|
|
3282
|
-
continue;
|
|
3283
|
-
const da = dData[dIdx + 3] / 255;
|
|
3284
|
-
const oa = sa + da * (1 - sa);
|
|
3285
|
-
if (oa === 0)
|
|
3286
|
-
continue;
|
|
3287
|
-
const sw = sa / oa;
|
|
3288
|
-
const dw = (da * (1 - sa)) / oa;
|
|
3289
|
-
dData[dIdx] = Math.round(sData[sIdx] * sw + dData[dIdx] * dw);
|
|
3290
|
-
dData[dIdx + 1] = Math.round(sData[sIdx + 1] * sw + dData[dIdx + 1] * dw);
|
|
3291
|
-
dData[dIdx + 2] = Math.round(sData[sIdx + 2] * sw + dData[dIdx + 2] * dw);
|
|
3292
|
-
dData[dIdx + 3] = Math.round(oa * 255);
|
|
3293
|
-
}
|
|
3294
|
-
}
|
|
3295
|
-
}
|
|
3296
|
-
return canvas;
|
|
3297
|
-
}
|
|
3298
344
|
|
|
3299
|
-
|
|
3300
|
-
*
|
|
3301
|
-
*
|
|
3302
|
-
*
|
|
3303
|
-
* it under the terms of the GNU General Public License as published by
|
|
3304
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
3305
|
-
* (at your option) any later version.
|
|
3306
|
-
*
|
|
3307
|
-
* This program is distributed in the hope that it will be useful,
|
|
3308
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
3309
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
3310
|
-
* GNU General Public License for more details.
|
|
3311
|
-
*
|
|
3312
|
-
* You should have received a copy of the GNU General Public License
|
|
3313
|
-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
345
|
+
/**
|
|
346
|
+
* Slice an ArrayBufferView into a standalone backing buffer of the same kind
|
|
347
|
+
* (ArrayBuffer in, ArrayBuffer out; SharedArrayBuffer in, SharedArrayBuffer
|
|
348
|
+
* out). The buffer kind is preserved through the generic parameter.
|
|
3314
349
|
*/
|
|
3315
|
-
function
|
|
3316
|
-
|
|
3317
|
-
const width = aNew.width;
|
|
3318
|
-
const height = aNew.height;
|
|
3319
|
-
const aData = aNew.bitmap.data;
|
|
3320
|
-
const bData = bNew.bitmap.data;
|
|
3321
|
-
const mData = maskNew.bitmap.data;
|
|
3322
|
-
const diffImage = createEmptyImage(width, height);
|
|
3323
|
-
const dData = diffImage.bitmap.data;
|
|
3324
|
-
const addition = [];
|
|
3325
|
-
const deletion = [];
|
|
3326
|
-
const modification = [];
|
|
3327
|
-
for (let x = 0; x < width; x++) {
|
|
3328
|
-
for (let y = 0; y < height; y++) {
|
|
3329
|
-
const idx = (y * width + x) * 4;
|
|
3330
|
-
if (mData[idx + 3] !== 0)
|
|
3331
|
-
continue;
|
|
3332
|
-
const aAlpha = aData[idx + 3];
|
|
3333
|
-
const bAlpha = bData[idx + 3];
|
|
3334
|
-
if (aAlpha === bAlpha &&
|
|
3335
|
-
aData[idx] === bData[idx] &&
|
|
3336
|
-
aData[idx + 1] === bData[idx + 1] &&
|
|
3337
|
-
aData[idx + 2] === bData[idx + 2]) {
|
|
3338
|
-
continue;
|
|
3339
|
-
}
|
|
3340
|
-
if (aAlpha === 0 && bAlpha === 0)
|
|
3341
|
-
continue;
|
|
3342
|
-
let target;
|
|
3343
|
-
let color;
|
|
3344
|
-
if (aAlpha === 0) {
|
|
3345
|
-
target = addition;
|
|
3346
|
-
color = pallet.addition;
|
|
3347
|
-
}
|
|
3348
|
-
else if (bAlpha === 0) {
|
|
3349
|
-
target = deletion;
|
|
3350
|
-
color = pallet.deletion;
|
|
3351
|
-
}
|
|
3352
|
-
else {
|
|
3353
|
-
target = modification;
|
|
3354
|
-
color = pallet.modification;
|
|
3355
|
-
}
|
|
3356
|
-
target.push([x, y]);
|
|
3357
|
-
dData[idx] = color[0];
|
|
3358
|
-
dData[idx + 1] = color[1];
|
|
3359
|
-
dData[idx + 2] = color[2];
|
|
3360
|
-
dData[idx + 3] = color[3];
|
|
3361
|
-
}
|
|
3362
|
-
}
|
|
3363
|
-
return { diff: diffImage, addition, deletion, modification };
|
|
350
|
+
function sliceBackingBuffer(src) {
|
|
351
|
+
return src.buffer.slice(src.byteOffset, src.byteOffset + src.byteLength);
|
|
3364
352
|
}
|
|
3365
353
|
|
|
3366
|
-
/*
|
|
3367
|
-
|
|
3368
|
-
*
|
|
3369
|
-
* This program is free software: you can redistribute it and/or modify
|
|
3370
|
-
* it under the terms of the GNU General Public License as published by
|
|
3371
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
3372
|
-
* (at your option) any later version.
|
|
3373
|
-
*
|
|
3374
|
-
* This program is distributed in the hope that it will be useful,
|
|
3375
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
3376
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
3377
|
-
* GNU General Public License for more details.
|
|
3378
|
-
*
|
|
3379
|
-
* You should have received a copy of the GNU General Public License
|
|
3380
|
-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
3381
|
-
*/
|
|
3382
|
-
function pixmapToRGBA(pixmap) {
|
|
3383
|
-
const width = pixmap.getWidth();
|
|
3384
|
-
const height = pixmap.getHeight();
|
|
3385
|
-
const stride = pixmap.getStride();
|
|
3386
|
-
const hasAlpha = pixmap.getAlpha() !== 0;
|
|
3387
|
-
const samples = pixmap.getPixels();
|
|
3388
|
-
if (hasAlpha && stride === width * 4) {
|
|
3389
|
-
return new Uint8Array(samples);
|
|
3390
|
-
}
|
|
3391
|
-
const out = new Uint8Array(width * height * 4);
|
|
3392
|
-
const srcBpp = pixmap.getNumberOfComponents() + (hasAlpha ? 1 : 0);
|
|
3393
|
-
for (let y = 0; y < height; y++) {
|
|
3394
|
-
const srcRow = y * stride;
|
|
3395
|
-
const dstRow = y * width * 4;
|
|
3396
|
-
for (let x = 0; x < width; x++) {
|
|
3397
|
-
const s = srcRow + x * srcBpp;
|
|
3398
|
-
const d = dstRow + x * 4;
|
|
3399
|
-
out[d] = samples[s];
|
|
3400
|
-
out[d + 1] = samples[s + 1];
|
|
3401
|
-
out[d + 2] = samples[s + 2];
|
|
3402
|
-
out[d + 3] = hasAlpha ? samples[s + 3] : 255;
|
|
3403
|
-
}
|
|
3404
|
-
}
|
|
3405
|
-
return out;
|
|
3406
|
-
}
|
|
3407
|
-
async function pageToImage(page, dpi, alpha) {
|
|
3408
|
-
const zoom = dpi / 72;
|
|
3409
|
-
const pixmap = page.toPixmap([zoom, 0, 0, zoom, 0, 0], ColorSpace.DeviceRGB, alpha);
|
|
3410
|
-
const width = pixmap.getWidth();
|
|
3411
|
-
const height = pixmap.getHeight();
|
|
3412
|
-
const data = pixmapToRGBA(pixmap);
|
|
3413
|
-
pixmap.destroy();
|
|
3414
|
-
page.destroy();
|
|
3415
|
-
return Jimp.fromBitmap({ width, height, data });
|
|
3416
|
-
}
|
|
354
|
+
async function Module(moduleArg={}){var moduleRtn;var Module=moduleArg;var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(ENVIRONMENT_IS_NODE){const{createRequire}=await import('node:module');var require=createRequire(import.meta.url);}var _scriptName=import.meta.url;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("node:fs");if(_scriptName.startsWith("file:")){scriptDirectory=require("node:path").dirname(require("node:url").fileURLToPath(_scriptName))+"/";}readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){process.argv[1].replace(/\\/g,"/");}process.argv.slice(2);}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href;}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)};}readAsync=async url=>{if(isFileURI(url)){return new Promise((resolve,reject)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){resolve(xhr.response);return}reject(xhr.status);};xhr.onerror=reject;xhr.send(null);})}var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)};}}else;console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var isFileURI=filename=>filename.startsWith("file://");var readyPromiseResolve,readyPromiseReject;var runtimeInitialized=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b);}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift());}}callRuntimeCallbacks(onPreRuns);}function initRuntime(){runtimeInitialized=true;wasmExports["z"]();}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift());}}callRuntimeCallbacks(onPostRuns);}function abort(what){Module["onAbort"]?.(what);what=`Aborted(${what})`;err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject?.(e);throw e}var wasmBinaryFile;function findWasmBinary(){if(Module["locateFile"]){return locateFile("core.wasm")}return new URL("core.wasm",import.meta.url).href}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw "both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason);}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!isFileURI(binaryFile)&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation");}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();return wasmExports}function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(inst,mod)=>{resolve(receiveInstance(inst));});})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}var HEAP16;var HEAP32;var HEAP64;var HEAP8;var HEAPF32;var HEAPF64;var HEAPU16;var HEAPU32;var HEAPU64;var HEAPU8;var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module);}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.push(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.push(cb);class ExceptionInfo{constructor(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24;}set_type(type){HEAPU32[this.ptr+4>>2]=type;}get_type(){return HEAPU32[this.ptr+4>>2]}set_destructor(destructor){HEAPU32[this.ptr+8>>2]=destructor;}get_destructor(){return HEAPU32[this.ptr+8>>2]}set_caught(caught){caught=caught?1:0;HEAP8[this.ptr+12]=caught;}get_caught(){return HEAP8[this.ptr+12]!=0}set_rethrown(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13]=rethrown;}get_rethrown(){return HEAP8[this.ptr+13]!=0}init(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor);}set_adjusted_ptr(adjustedPtr){HEAPU32[this.ptr+16>>2]=adjustedPtr;}get_adjusted_ptr(){return HEAPU32[this.ptr+16>>2]}}var ___cxa_throw=(ptr,type,destructor)=>{var info=new ExceptionInfo(ptr);info.init(type,destructor);abort();};var __abort_js=()=>abort("");var AsciiToString=ptr=>{var str="";while(1){var ch=HEAPU8[ptr++];if(!ch)return str;str+=String.fromCharCode(ch);}};var awaitingDependencies={};var registeredTypes={};var typeDependencies={};var BindingError=class BindingError extends Error{constructor(message){super(message);this.name="BindingError";}};var throwBindingError=message=>{throw new BindingError(message)};function sharedRegisterType(rawType,registeredInstance,options={}){var name=registeredInstance.name;if(!rawType){throwBindingError(`type "${name}" must have a positive integer typeid pointer`);}if(registeredTypes.hasOwnProperty(rawType)){if(options.ignoreDuplicateRegistrations){return}else {throwBindingError(`Cannot register type '${name}' twice`);}}registeredTypes[rawType]=registeredInstance;delete typeDependencies[rawType];if(awaitingDependencies.hasOwnProperty(rawType)){var callbacks=awaitingDependencies[rawType];delete awaitingDependencies[rawType];callbacks.forEach(cb=>cb());}}function registerType(rawType,registeredInstance,options={}){return sharedRegisterType(rawType,registeredInstance,options)}var integerReadValueFromPointer=(name,width,signed)=>{switch(width){case 1:return signed?pointer=>HEAP8[pointer]:pointer=>HEAPU8[pointer];case 2:return signed?pointer=>HEAP16[pointer>>1]:pointer=>HEAPU16[pointer>>1];case 4:return signed?pointer=>HEAP32[pointer>>2]:pointer=>HEAPU32[pointer>>2];case 8:return signed?pointer=>HEAP64[pointer>>3]:pointer=>HEAPU64[pointer>>3];default:throw new TypeError(`invalid integer width (${width}): ${name}`)}};var __embind_register_bigint=(primitiveType,name,size,minRange,maxRange)=>{name=AsciiToString(name);const isUnsignedType=minRange===0n;let fromWireType=value=>value;if(isUnsignedType){const bitSize=size*8;fromWireType=value=>BigInt.asUintN(bitSize,value);maxRange=fromWireType(maxRange);}registerType(primitiveType,{name,fromWireType,toWireType:(destructors,value)=>{if(typeof value=="number"){value=BigInt(value);}return value},readValueFromPointer:integerReadValueFromPointer(name,size,!isUnsignedType),destructorFunction:null});};var __embind_register_bool=(rawType,name,trueValue,falseValue)=>{name=AsciiToString(name);registerType(rawType,{name,fromWireType:function(wt){return !!wt},toWireType:function(destructors,o){return o?trueValue:falseValue},readValueFromPointer:function(pointer){return this.fromWireType(HEAPU8[pointer])},destructorFunction:null});};var emval_freelist=[];var emval_handles=[0,1,,1,null,1,true,1,false,1];var __emval_decref=handle=>{if(handle>9&&0===--emval_handles[handle+1]){emval_handles[handle]=undefined;emval_freelist.push(handle);}};var Emval={toValue:handle=>{if(!handle){throwBindingError(`Cannot use deleted val. handle = ${handle}`);}return emval_handles[handle]},toHandle:value=>{switch(value){case undefined:return 2;case null:return 4;case true:return 6;case false:return 8;default:{const handle=emval_freelist.pop()||emval_handles.length;emval_handles[handle]=value;emval_handles[handle+1]=1;return handle}}}};function readPointer(pointer){return this.fromWireType(HEAPU32[pointer>>2])}var EmValType={name:"emscripten::val",fromWireType:handle=>{var rv=Emval.toValue(handle);__emval_decref(handle);return rv},toWireType:(destructors,value)=>Emval.toHandle(value),readValueFromPointer:readPointer,destructorFunction:null};var __embind_register_emval=rawType=>registerType(rawType,EmValType);var floatReadValueFromPointer=(name,width)=>{switch(width){case 4:return function(pointer){return this.fromWireType(HEAPF32[pointer>>2])};case 8:return function(pointer){return this.fromWireType(HEAPF64[pointer>>3])};default:throw new TypeError(`invalid float width (${width}): ${name}`)}};var __embind_register_float=(rawType,name,size)=>{name=AsciiToString(name);registerType(rawType,{name,fromWireType:value=>value,toWireType:(destructors,value)=>value,readValueFromPointer:floatReadValueFromPointer(name,size),destructorFunction:null});};var createNamedFunction=(name,func)=>Object.defineProperty(func,"name",{value:name});var runDestructors=destructors=>{while(destructors.length){var ptr=destructors.pop();var del=destructors.pop();del(ptr);}};function usesDestructorStack(argTypes){for(var i=1;i<argTypes.length;++i){if(argTypes[i]!==null&&argTypes[i].destructorFunction===undefined){return true}}return false}function createJsInvoker(argTypes,isClassMethodFunc,returns,isAsync){var needsDestructorStack=usesDestructorStack(argTypes);var argCount=argTypes.length-2;var argsList=[];var argsListWired=["fn"];for(var i=0;i<argCount;++i){argsList.push(`arg${i}`);argsListWired.push(`arg${i}Wired`);}argsList=argsList.join(",");argsListWired=argsListWired.join(",");var invokerFnBody=`return function (${argsList}) {\n`;if(needsDestructorStack){invokerFnBody+="var destructors = [];\n";}var dtorStack=needsDestructorStack?"destructors":"null";var args1=["humanName","throwBindingError","invoker","fn","runDestructors","fromRetWire","toClassParamWire"];for(var i=0;i<argCount;++i){var argName=`toArg${i}Wire`;invokerFnBody+=`var arg${i}Wired = ${argName}(${dtorStack}, arg${i});\n`;args1.push(argName);}invokerFnBody+=(returns||isAsync?"var rv = ":"")+`invoker(${argsListWired});\n`;if(needsDestructorStack){invokerFnBody+="runDestructors(destructors);\n";}else {for(var i=2;i<argTypes.length;++i){var paramName=i===1?"thisWired":"arg"+(i-2)+"Wired";if(argTypes[i].destructorFunction!==null){invokerFnBody+=`${paramName}_dtor(${paramName});\n`;args1.push(`${paramName}_dtor`);}}}if(returns){invokerFnBody+="var ret = fromRetWire(rv);\n"+"return ret;\n";}invokerFnBody+="}\n";return new Function(args1,invokerFnBody)}function craftInvokerFunction(humanName,argTypes,classType,cppInvokerFunc,cppTargetFunc,isAsync){var argCount=argTypes.length;if(argCount<2){throwBindingError("argTypes array size mismatch! Must at least get return value and 'this' types!");}var isClassMethodFunc=argTypes[1]!==null&&classType!==null;var needsDestructorStack=usesDestructorStack(argTypes);var returns=!argTypes[0].isVoid;var retType=argTypes[0];var instType=argTypes[1];var closureArgs=[humanName,throwBindingError,cppInvokerFunc,cppTargetFunc,runDestructors,retType.fromWireType.bind(retType),instType?.toWireType.bind(instType)];for(var i=2;i<argCount;++i){var argType=argTypes[i];closureArgs.push(argType.toWireType.bind(argType));}if(!needsDestructorStack){for(var i=2;i<argTypes.length;++i){if(argTypes[i].destructorFunction!==null){closureArgs.push(argTypes[i].destructorFunction);}}}let invokerFactory=createJsInvoker(argTypes,isClassMethodFunc,returns,isAsync);var invokerFn=invokerFactory(...closureArgs);return createNamedFunction(humanName,invokerFn)}var ensureOverloadTable=(proto,methodName,humanName)=>{if(undefined===proto[methodName].overloadTable){var prevFunc=proto[methodName];proto[methodName]=function(...args){if(!proto[methodName].overloadTable.hasOwnProperty(args.length)){throwBindingError(`Function '${humanName}' called with an invalid number of arguments (${args.length}) - expects one of (${proto[methodName].overloadTable})!`);}return proto[methodName].overloadTable[args.length].apply(this,args)};proto[methodName].overloadTable=[];proto[methodName].overloadTable[prevFunc.argCount]=prevFunc;}};var exposePublicSymbol=(name,value,numArguments)=>{if(Module.hasOwnProperty(name)){if(undefined===numArguments||undefined!==Module[name].overloadTable&&undefined!==Module[name].overloadTable[numArguments]){throwBindingError(`Cannot register public name '${name}' twice`);}ensureOverloadTable(Module,name,name);if(Module[name].overloadTable.hasOwnProperty(numArguments)){throwBindingError(`Cannot register multiple overloads of a function with the same number of arguments (${numArguments})!`);}Module[name].overloadTable[numArguments]=value;}else {Module[name]=value;Module[name].argCount=numArguments;}};var heap32VectorToArray=(count,firstElement)=>{var array=[];for(var i=0;i<count;i++){array.push(HEAPU32[firstElement+i*4>>2]);}return array};var InternalError=class InternalError extends Error{constructor(message){super(message);this.name="InternalError";}};var throwInternalError=message=>{throw new InternalError(message)};var replacePublicSymbol=(name,value,numArguments)=>{if(!Module.hasOwnProperty(name)){throwInternalError("Replacing nonexistent public symbol");}if(undefined!==Module[name].overloadTable&&undefined!==numArguments){Module[name].overloadTable[numArguments]=value;}else {Module[name]=value;Module[name].argCount=numArguments;}};var wasmTableMirror=[];var getWasmTableEntry=funcPtr=>{var func=wasmTableMirror[funcPtr];if(!func){wasmTableMirror[funcPtr]=func=wasmTable.get(funcPtr);}return func};var embind__requireFunction=(signature,rawFunction,isAsync=false)=>{signature=AsciiToString(signature);function makeDynCaller(){var rtn=getWasmTableEntry(rawFunction);return rtn}var fp=makeDynCaller();if(typeof fp!="function"){throwBindingError(`unknown function pointer with signature ${signature}: ${rawFunction}`);}return fp};class UnboundTypeError extends Error{}var getTypeName=type=>{var ptr=___getTypeName(type);var rv=AsciiToString(ptr);_free(ptr);return rv};var throwUnboundTypeError=(message,types)=>{var unboundTypes=[];var seen={};function visit(type){if(seen[type]){return}if(registeredTypes[type]){return}if(typeDependencies[type]){typeDependencies[type].forEach(visit);return}unboundTypes.push(type);seen[type]=true;}types.forEach(visit);throw new UnboundTypeError(`${message}: `+unboundTypes.map(getTypeName).join([", "]))};var whenDependentTypesAreResolved=(myTypes,dependentTypes,getTypeConverters)=>{myTypes.forEach(type=>typeDependencies[type]=dependentTypes);function onComplete(typeConverters){var myTypeConverters=getTypeConverters(typeConverters);if(myTypeConverters.length!==myTypes.length){throwInternalError("Mismatched type converter count");}for(var i=0;i<myTypes.length;++i){registerType(myTypes[i],myTypeConverters[i]);}}var typeConverters=new Array(dependentTypes.length);var unregisteredTypes=[];var registered=0;for(let[i,dt]of dependentTypes.entries()){if(registeredTypes.hasOwnProperty(dt)){typeConverters[i]=registeredTypes[dt];}else {unregisteredTypes.push(dt);if(!awaitingDependencies.hasOwnProperty(dt)){awaitingDependencies[dt]=[];}awaitingDependencies[dt].push(()=>{typeConverters[i]=registeredTypes[dt];++registered;if(registered===unregisteredTypes.length){onComplete(typeConverters);}});}}if(0===unregisteredTypes.length){onComplete(typeConverters);}};var getFunctionName=signature=>{signature=signature.trim();const argsIndex=signature.indexOf("(");if(argsIndex===-1)return signature;return signature.slice(0,argsIndex)};var __embind_register_function=(name,argCount,rawArgTypesAddr,signature,rawInvoker,fn,isAsync,isNonnullReturn)=>{var argTypes=heap32VectorToArray(argCount,rawArgTypesAddr);name=AsciiToString(name);name=getFunctionName(name);rawInvoker=embind__requireFunction(signature,rawInvoker,isAsync);exposePublicSymbol(name,function(){throwUnboundTypeError(`Cannot call ${name} due to unbound types`,argTypes);},argCount-1);whenDependentTypesAreResolved([],argTypes,argTypes=>{var invokerArgsArray=[argTypes[0],null].concat(argTypes.slice(1));replacePublicSymbol(name,craftInvokerFunction(name,invokerArgsArray,null,rawInvoker,fn,isAsync),argCount-1);return []});};var __embind_register_integer=(primitiveType,name,size,minRange,maxRange)=>{name=AsciiToString(name);const isUnsignedType=minRange===0;let fromWireType=value=>value;if(isUnsignedType){var bitshift=32-8*size;fromWireType=value=>value<<bitshift>>>bitshift;maxRange=fromWireType(maxRange);}registerType(primitiveType,{name,fromWireType,toWireType:(destructors,value)=>value,readValueFromPointer:integerReadValueFromPointer(name,size,minRange!==0),destructorFunction:null});};var __embind_register_memory_view=(rawType,dataTypeIndex,name)=>{var typeMapping=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array];var TA=typeMapping[dataTypeIndex];function decodeMemoryView(handle){var size=HEAPU32[handle>>2];var data=HEAPU32[handle+4>>2];return new TA(HEAP8.buffer,data,size)}name=AsciiToString(name);registerType(rawType,{name,fromWireType:decodeMemoryView,readValueFromPointer:decodeMemoryView},{ignoreDuplicateRegistrations:true});};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.codePointAt(i);if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u;}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63;}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63;}else {if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63;i++;}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++;}else if(c<=2047){len+=2;}else if(c>=55296&&c<=57343){len+=4;++i;}else {len+=3;}}return len};var UTF8Decoder=globalThis.TextDecoder&&new TextDecoder;var findStringEnd=(heapOrArray,idx,maxBytesToRead,ignoreNul)=>{var maxIdx=idx+maxBytesToRead;if(ignoreNul)return maxIdx;while(heapOrArray[idx]&&!(idx>=maxIdx))++idx;return idx};var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead,ignoreNul)=>{var endPtr=findStringEnd(heapOrArray,idx,maxBytesToRead,ignoreNul);if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2;}else {u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63;}if(u0<65536){str+=String.fromCharCode(u0);}else {var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023);}}return str};var UTF8ToString=(ptr,maxBytesToRead,ignoreNul)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead,ignoreNul):"";var __embind_register_std_string=(rawType,name)=>{name=AsciiToString(name);registerType(rawType,{name,fromWireType(value){var length=HEAPU32[value>>2];var payload=value+4;var str;{str=UTF8ToString(payload,length,true);}_free(value);return str},toWireType(destructors,value){if(value instanceof ArrayBuffer){value=new Uint8Array(value);}var length;var valueIsOfTypeString=typeof value=="string";if(!(valueIsOfTypeString||ArrayBuffer.isView(value)&&value.BYTES_PER_ELEMENT==1)){throwBindingError("Cannot pass non-string to std::string");}if(valueIsOfTypeString){length=lengthBytesUTF8(value);}else {length=value.length;}var base=_malloc(4+length+1);var ptr=base+4;HEAPU32[base>>2]=length;if(valueIsOfTypeString){{stringToUTF8(value,ptr,length+1);}}else {HEAPU8.set(value,ptr);}if(destructors!==null){destructors.push(_free,base);}return base},readValueFromPointer:readPointer,destructorFunction(ptr){_free(ptr);}});};var UTF16Decoder=globalThis.TextDecoder?new TextDecoder("utf-16le"):undefined;var UTF16ToString=(ptr,maxBytesToRead,ignoreNul)=>{var idx=ptr>>1;var endIdx=findStringEnd(HEAPU16,idx,maxBytesToRead/2,ignoreNul);if(endIdx-idx>16&&UTF16Decoder)return UTF16Decoder.decode(HEAPU16.subarray(idx,endIdx));var str="";for(var i=idx;i<endIdx;++i){var codeUnit=HEAPU16[i];str+=String.fromCharCode(codeUnit);}return str};var stringToUTF16=(str,outPtr,maxBytesToWrite)=>{maxBytesToWrite??=2147483647;if(maxBytesToWrite<2)return 0;maxBytesToWrite-=2;var startPtr=outPtr;var numCharsToWrite=maxBytesToWrite<str.length*2?maxBytesToWrite/2:str.length;for(var i=0;i<numCharsToWrite;++i){var codeUnit=str.charCodeAt(i);HEAP16[outPtr>>1]=codeUnit;outPtr+=2;}HEAP16[outPtr>>1]=0;return outPtr-startPtr};var lengthBytesUTF16=str=>str.length*2;var UTF32ToString=(ptr,maxBytesToRead,ignoreNul)=>{var str="";var startIdx=ptr>>2;for(var i=0;!(i>=maxBytesToRead/4);i++){var utf32=HEAPU32[startIdx+i];if(!utf32&&!ignoreNul)break;str+=String.fromCodePoint(utf32);}return str};var stringToUTF32=(str,outPtr,maxBytesToWrite)=>{maxBytesToWrite??=2147483647;if(maxBytesToWrite<4)return 0;var startPtr=outPtr;var endPtr=startPtr+maxBytesToWrite-4;for(var i=0;i<str.length;++i){var codePoint=str.codePointAt(i);if(codePoint>65535){i++;}HEAP32[outPtr>>2]=codePoint;outPtr+=4;if(outPtr+4>endPtr)break}HEAP32[outPtr>>2]=0;return outPtr-startPtr};var lengthBytesUTF32=str=>{var len=0;for(var i=0;i<str.length;++i){var codePoint=str.codePointAt(i);if(codePoint>65535){i++;}len+=4;}return len};var __embind_register_std_wstring=(rawType,charSize,name)=>{name=AsciiToString(name);var decodeString,encodeString,lengthBytesUTF;if(charSize===2){decodeString=UTF16ToString;encodeString=stringToUTF16;lengthBytesUTF=lengthBytesUTF16;}else {decodeString=UTF32ToString;encodeString=stringToUTF32;lengthBytesUTF=lengthBytesUTF32;}registerType(rawType,{name,fromWireType:value=>{var length=HEAPU32[value>>2];var str=decodeString(value+4,length*charSize,true);_free(value);return str},toWireType:(destructors,value)=>{if(!(typeof value=="string")){throwBindingError(`Cannot pass non-string to C++ string type ${name}`);}var length=lengthBytesUTF(value);var ptr=_malloc(4+length+charSize);HEAPU32[ptr>>2]=length/charSize;encodeString(value,ptr+4,length+charSize);if(destructors!==null){destructors.push(_free,ptr);}return ptr},readValueFromPointer:readPointer,destructorFunction(ptr){_free(ptr);}});};var __embind_register_void=(rawType,name)=>{name=AsciiToString(name);registerType(rawType,{isVoid:true,name,fromWireType:()=>undefined,toWireType:(destructors,o)=>undefined});};var __emval_array_to_memory_view=(dst,src)=>{dst=Emval.toValue(dst);src=Emval.toValue(src);dst.set(src);};var emval_methodCallers=[];var emval_addMethodCaller=caller=>{var id=emval_methodCallers.length;emval_methodCallers.push(caller);return id};var requireRegisteredType=(rawType,humanName)=>{var impl=registeredTypes[rawType];if(undefined===impl){throwBindingError(`${humanName} has unknown type ${getTypeName(rawType)}`);}return impl};var emval_lookupTypes=(argCount,argTypes)=>{var a=new Array(argCount);for(var i=0;i<argCount;++i){a[i]=requireRegisteredType(HEAPU32[argTypes+i*4>>2],`parameter ${i}`);}return a};var emval_returnValue=(toReturnWire,destructorsRef,handle)=>{var destructors=[];var result=toReturnWire(destructors,handle);if(destructors.length){HEAPU32[destructorsRef>>2]=Emval.toHandle(destructors);}return result};var emval_symbols={};var getStringOrSymbol=address=>{var symbol=emval_symbols[address];if(symbol===undefined){return AsciiToString(address)}return symbol};var __emval_create_invoker=(argCount,argTypesPtr,kind)=>{var GenericWireTypeSize=8;var[retType,...argTypes]=emval_lookupTypes(argCount,argTypesPtr);var toReturnWire=retType.toWireType.bind(retType);var argFromPtr=argTypes.map(type=>type.readValueFromPointer.bind(type));argCount--;var captures={toValue:Emval.toValue};var args=argFromPtr.map((argFromPtr,i)=>{var captureName=`argFromPtr${i}`;captures[captureName]=argFromPtr;return `${captureName}(args${i?"+"+i*GenericWireTypeSize:""})`});var functionBody;switch(kind){case 0:functionBody="toValue(handle)";break;case 2:functionBody="new (toValue(handle))";break;case 3:functionBody="";break;case 1:captures["getStringOrSymbol"]=getStringOrSymbol;functionBody="toValue(handle)[getStringOrSymbol(methodName)]";break}functionBody+=`(${args})`;if(!retType.isVoid){captures["toReturnWire"]=toReturnWire;captures["emval_returnValue"]=emval_returnValue;functionBody=`return emval_returnValue(toReturnWire, destructorsRef, ${functionBody})`;}functionBody=`return function (handle, methodName, destructorsRef, args) {\n${functionBody}\n}`;var invokerFunction=new Function(Object.keys(captures),functionBody)(...Object.values(captures));var functionName=`methodCaller<(${argTypes.map(t=>t.name)}) => ${retType.name}>`;return emval_addMethodCaller(createNamedFunction(functionName,invokerFunction))};var __emval_get_global=name=>{if(!name){return Emval.toHandle(globalThis)}name=getStringOrSymbol(name);return Emval.toHandle(globalThis[name])};var __emval_get_property=(handle,key)=>{handle=Emval.toValue(handle);key=Emval.toValue(key);return Emval.toHandle(handle[key])};var __emval_incref=handle=>{if(handle>9){emval_handles[handle+1]+=1;}};var __emval_invoke=(caller,handle,methodName,destructorsRef,args)=>emval_methodCallers[caller](handle,methodName,destructorsRef,args);var __emval_new_cstring=v=>Emval.toHandle(getStringOrSymbol(v));var __emval_new_object=()=>Emval.toHandle({});var __emval_run_destructors=handle=>{var destructors=Emval.toValue(handle);runDestructors(destructors);__emval_decref(handle);};var __emval_set_property=(handle,key,value)=>{handle=Emval.toValue(handle);key=Emval.toValue(key);value=Emval.toValue(value);handle[key]=value;};var getHeapMax=()=>2147483648;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};{if(Module["noExitRuntime"])Module["noExitRuntime"];if(Module["print"])Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(Module["arguments"])Module["arguments"];if(Module["thisProgram"])Module["thisProgram"];if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].shift()();}}}var _free,_malloc,___getTypeName,wasmMemory,wasmTable;function assignWasmExports(wasmExports){_free=wasmExports["A"];_malloc=wasmExports["B"];___getTypeName=wasmExports["D"];wasmMemory=wasmExports["y"];wasmTable=wasmExports["C"];}var wasmImports={w:___cxa_throw,q:__abort_js,m:__embind_register_bigint,u:__embind_register_bool,s:__embind_register_emval,l:__embind_register_float,n:__embind_register_function,f:__embind_register_integer,a:__embind_register_memory_view,t:__embind_register_std_string,i:__embind_register_std_wstring,v:__embind_register_void,x:__emval_array_to_memory_view,e:__emval_create_invoker,b:__emval_decref,k:__emval_get_global,o:__emval_get_property,h:__emval_incref,d:__emval_invoke,g:__emval_new_cstring,p:__emval_new_object,c:__emval_run_destructors,j:__emval_set_property,r:_emscripten_resize_heap};function run(){preRun();function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve?.(Module);Module["onRuntimeInitialized"]?.();postRun();}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun();},1);}else {doRun();}}var wasmExports;wasmExports=await (createWasm());run();if(runtimeInitialized){moduleRtn=Module;}else {moduleRtn=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject;});}
|
|
355
|
+
return moduleRtn}
|
|
3417
356
|
|
|
3418
|
-
/*
|
|
3419
|
-
* Copyright (C) 2025 Koutaro Mukai
|
|
3420
|
-
*
|
|
3421
|
-
* This program is free software: you can redistribute it and/or modify
|
|
3422
|
-
* it under the terms of the GNU General Public License as published by
|
|
3423
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
3424
|
-
* (at your option) any later version.
|
|
3425
|
-
*
|
|
3426
|
-
* This program is distributed in the hope that it will be useful,
|
|
3427
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
3428
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
3429
|
-
* GNU General Public License for more details.
|
|
3430
|
-
*
|
|
3431
|
-
* You should have received a copy of the GNU General Public License
|
|
3432
|
-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
3433
|
-
*/
|
|
3434
|
-
let pdfA;
|
|
3435
|
-
let pdfB;
|
|
3436
|
-
let pdfMask;
|
|
3437
357
|
let opts;
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
index < pdfMask.countPages()
|
|
3455
|
-
? pageToImage(pdfMask.loadPage(index), opts.dpi, opts.alpha)
|
|
3456
|
-
: createEmptyImage(1, 1),
|
|
358
|
+
let wasm = null;
|
|
359
|
+
async function getWasm() {
|
|
360
|
+
if (!wasm)
|
|
361
|
+
wasm = await Module();
|
|
362
|
+
return wasm;
|
|
363
|
+
}
|
|
364
|
+
function packColor([r, g, b, a]) {
|
|
365
|
+
return ((r << 24) | (g << 16) | (b << 8) | a) >>> 0;
|
|
366
|
+
}
|
|
367
|
+
async function processPage(msg) {
|
|
368
|
+
const index = msg.index;
|
|
369
|
+
const sLoad = perf.span("worker.decodeAll_ms");
|
|
370
|
+
const [pageA, pageB, pageMaskOrNull] = (await Promise.all([
|
|
371
|
+
msg.a !== null ? decodePng(msg.a) : createEmptyImage(1, 1),
|
|
372
|
+
msg.b !== null ? decodePng(msg.b) : createEmptyImage(1, 1),
|
|
373
|
+
msg.mask !== null ? decodePng(msg.mask) : Promise.resolve(null),
|
|
3457
374
|
]));
|
|
3458
|
-
|
|
3459
|
-
const
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
375
|
+
sLoad.stop();
|
|
376
|
+
const sAlign = perf.span("worker.alignSize_ms");
|
|
377
|
+
let aAligned;
|
|
378
|
+
let bAligned;
|
|
379
|
+
let maskAligned;
|
|
380
|
+
if (pageMaskOrNull !== null) {
|
|
381
|
+
[aAligned, bAligned, maskAligned] = alignSize([pageA, pageB, pageMaskOrNull], opts.align);
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
[aAligned, bAligned] = alignSize([pageA, pageB], opts.align);
|
|
385
|
+
maskAligned = null;
|
|
386
|
+
}
|
|
387
|
+
sAlign.stop();
|
|
388
|
+
const width = aAligned.width;
|
|
389
|
+
const height = aAligned.height;
|
|
390
|
+
const aData = aAligned.bitmap.data;
|
|
391
|
+
const bData = bAligned.bitmap.data;
|
|
392
|
+
const maskData = maskAligned !== null ? maskAligned.bitmap.data : null;
|
|
393
|
+
const sProcess = perf.span("worker.processPage_ms");
|
|
394
|
+
const wasmModule = await getWasm();
|
|
395
|
+
const result = wasmModule.processPage(aData, bData, maskData, width, height, packColor(opts.pallet.addition), packColor(opts.pallet.deletion), packColor(opts.pallet.modification));
|
|
396
|
+
if (typeof result === "number") {
|
|
397
|
+
throw new Error(`wasm processPage failed: ${result}`);
|
|
398
|
+
}
|
|
399
|
+
sProcess.stop();
|
|
400
|
+
const sXfer = perf.span("worker.toTransferable_ms");
|
|
401
|
+
const aBuf = sliceBackingBuffer(aData);
|
|
402
|
+
const bBuf = sliceBackingBuffer(bData);
|
|
403
|
+
const dBuf = sliceBackingBuffer(result.overlay);
|
|
404
|
+
const addBuf = sliceBackingBuffer(result.addition);
|
|
405
|
+
const delBuf = sliceBackingBuffer(result.deletion);
|
|
406
|
+
const modBuf = sliceBackingBuffer(result.modification);
|
|
407
|
+
sXfer.stop();
|
|
408
|
+
perf.incr("worker.pages");
|
|
409
|
+
let pagePerf;
|
|
410
|
+
if (perf.enabled) {
|
|
411
|
+
pagePerf = perf.dump();
|
|
412
|
+
perf.reset();
|
|
413
|
+
}
|
|
3464
414
|
return {
|
|
3465
415
|
type: "pageResult",
|
|
3466
416
|
index,
|
|
3467
|
-
a: {
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
height: pageB.height,
|
|
3475
|
-
data: toTransferable(pageB.bitmap.data),
|
|
3476
|
-
},
|
|
3477
|
-
diff: {
|
|
3478
|
-
width: diff.width,
|
|
3479
|
-
height: diff.height,
|
|
3480
|
-
data: toTransferable(diff.bitmap.data),
|
|
3481
|
-
},
|
|
3482
|
-
addition,
|
|
3483
|
-
deletion,
|
|
3484
|
-
modification,
|
|
417
|
+
a: { width, height, data: aBuf },
|
|
418
|
+
b: { width, height, data: bBuf },
|
|
419
|
+
diff: { width, height, data: dBuf },
|
|
420
|
+
addition: addBuf,
|
|
421
|
+
deletion: delBuf,
|
|
422
|
+
modification: modBuf,
|
|
423
|
+
perf: pagePerf,
|
|
3485
424
|
};
|
|
3486
425
|
}
|
|
3487
426
|
self.addEventListener("message", async (e) => {
|
|
3488
427
|
try {
|
|
3489
428
|
const msg = e.data;
|
|
3490
429
|
if (msg.type === "init") {
|
|
3491
|
-
pdfA = PDFDocument.openDocument(msg.aBytes, "application/pdf");
|
|
3492
|
-
pdfB = PDFDocument.openDocument(msg.bBytes, "application/pdf");
|
|
3493
|
-
pdfMask = msg.maskBytes
|
|
3494
|
-
? PDFDocument.openDocument(msg.maskBytes, "application/pdf")
|
|
3495
|
-
: new PDFDocument();
|
|
3496
430
|
opts = {
|
|
3497
|
-
dpi: msg.dpi,
|
|
3498
|
-
alpha: msg.alpha,
|
|
3499
431
|
pallet: msg.pallet,
|
|
3500
432
|
align: msg.align,
|
|
3501
433
|
};
|
|
3502
|
-
|
|
3503
|
-
pdfA.loadPage(0).destroy();
|
|
434
|
+
await getWasm();
|
|
3504
435
|
const ready = { type: "ready" };
|
|
3505
436
|
self.postMessage(ready);
|
|
3506
437
|
}
|
|
3507
438
|
else if (msg.type === "page") {
|
|
3508
|
-
const result = await processPage(msg
|
|
439
|
+
const result = await processPage(msg);
|
|
3509
440
|
self.postMessage(result, [
|
|
3510
441
|
result.a.data,
|
|
3511
442
|
result.b.data,
|
|
3512
443
|
result.diff.data,
|
|
444
|
+
result.addition,
|
|
445
|
+
result.deletion,
|
|
446
|
+
result.modification,
|
|
3513
447
|
]);
|
|
3514
448
|
}
|
|
3515
449
|
}
|